blade-code 0.5.12 → 0.5.14
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/dist/blade.js +2 -2
- package/dist/{chunk-jbgnyvq5.js → chunk-188szde1.js} +1 -1
- package/dist/{chunk-v7t5d690.js → chunk-2mg2f5ye.js} +1 -1
- package/dist/{chunk-45wmm5j8.js → chunk-3e49zxqs.js} +1 -1
- package/dist/{chunk-rjk18y5r.js → chunk-4fr2426x.js} +2 -2
- package/dist/{chunk-2w8npk23.js → chunk-4ydppdj9.js} +1 -1
- package/dist/chunk-5m2115cc.js +1 -0
- package/dist/{chunk-zt7hzp5v.js → chunk-7199c8y4.js} +193 -187
- package/dist/{chunk-gyha7gsz.js → chunk-9a0xfrad.js} +1 -1
- package/dist/{chunk-4nqwtxst.js → chunk-a8e5kaxt.js} +1 -1
- package/dist/{chunk-rnqx8daf.js → chunk-e41c8gcw.js} +1 -1
- package/dist/{chunk-pp156ttb.js → chunk-eanf7ve1.js} +1 -1
- package/dist/{chunk-xkkrvg68.js → chunk-fw4yyv5m.js} +1 -1
- package/dist/{chunk-cfn3456j.js → chunk-j6z6fn0y.js} +1 -1
- package/dist/{chunk-vz8v6y2d.js → chunk-yjg1xvq9.js} +1 -1
- package/dist/{chunk-jjctnvbz.js → chunk-yvw8k73m.js} +1 -1
- package/package.json +1 -1
- package/dist/chunk-8qqpttys.js +0 -1
package/dist/blade.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{n as B}from"./chunk-pfsft4nd.js";import{$ as F,_ as D}from"./chunk-mxrre2n3.js";import"./chunk-x9zj0r7s.js";import"./chunk-mz6n4w13.js";import"./chunk-yk91w5p2.js";import{vb as E,xb as q}from"./chunk-7ycmx7c2.js";import{Ab as H}from"./chunk-set7v1rf.js";import{Db as J}from"./chunk-j2ag7hh6.js";var X=process.argv.slice(2),$=v(X),w=$!==null;if($!==null)H.setGlobalDebug($);function v(Q){for(let W=0;W<Q.length;W+=1){let T=Q[W];if(T==="--debug"||T==="-d"){let N=Q[W+1];return N&&!N.startsWith("-")?N:!0}if(T.startsWith("--debug="))return T.slice(8)||!0}return null}function C(Q){return Q.length===1&&(Q[0]==="--version"||Q[0]==="-V")}function z(Q,...W){return Q.some((T)=>W.some((N)=>T===N||T.startsWith(`${N}=`)))}async function f(){if(C(X)){let{getVersion:K}=await import("./chunk-
|
|
2
|
+
import{n as B}from"./chunk-pfsft4nd.js";import{$ as F,_ as D}from"./chunk-mxrre2n3.js";import"./chunk-x9zj0r7s.js";import"./chunk-mz6n4w13.js";import"./chunk-yk91w5p2.js";import{vb as E,xb as q}from"./chunk-7ycmx7c2.js";import{Ab as H}from"./chunk-set7v1rf.js";import{Db as J}from"./chunk-j2ag7hh6.js";var X=process.argv.slice(2),$=v(X),w=$!==null;if($!==null)H.setGlobalDebug($);function v(Q){for(let W=0;W<Q.length;W+=1){let T=Q[W];if(T==="--debug"||T==="-d"){let N=Q[W+1];return N&&!N.startsWith("-")?N:!0}if(T.startsWith("--debug="))return T.slice(8)||!0}return null}function C(Q){return Q.length===1&&(Q[0]==="--version"||Q[0]==="-V")}function z(Q,...W){return Q.some((T)=>W.some((N)=>T===N||T.startsWith(`${N}=`)))}async function f(){if(C(X)){let{getVersion:K}=await import("./chunk-yvw8k73m.js");console.log(K());return}let Q=D(process.cwd());if(F(Q),E(q()),process.getuid&&process.getuid()===0){let K=!!process.env.SUDO_USER,U=!!process.env.BLADE_ALLOW_ROOT;if(K&&!U)console.error(""),console.error("Error: 请不要使用 sudo 运行 blade"),console.error(""),console.error("原因:"),console.error(" 使用 sudo 会创建属于 root 的配置文件,"),console.error(" 导致普通用户无法访问。"),console.error(""),console.error("正确用法:"),console.error(" blade # 直接运行,不要加 sudo"),console.error(""),console.error("如果遇到权限错误,请运行:"),console.error(" sudo chown -R $USER:$USER ~/.blade/"),console.error(""),console.error("如果你确实需要以 root 运行(容器/CI),设置环境变量:"),console.error(" BLADE_ALLOW_ROOT=1 blade"),console.error(""),process.exit(1)}if(B(),z(X,"--headless")){let{handleHeadlessMode:K}=await import("./chunk-fw4yyv5m.js");if(await K())return}if(z(X,"--print","-p")){let{handlePrintMode:K}=await import("./chunk-a8e5kaxt.js");if(await K())return}if(X.includes("--acp")){let{runAcpIntegration:K}=await import("./chunk-eanf7ve1.js");await K();return}let[{default:W},{hideBin:T},{cliConfig:N,globalOptions:G},{loadConfiguration:I,validateOutput:L,validatePermissions:M},{doctorCommands:_},{installCommands:y},{mcpCommands:R},{serveCommand:S},{updateCommands:k},{webCommand:O}]=await Promise.all([import("yargs"),import("yargs/helpers"),import("./chunk-5m2115cc.js"),import("./chunk-fe7g701v.js"),import("./chunk-k65n39by.js"),import("./chunk-g5pasj7t.js"),import("./chunk-9a0xfrad.js"),import("./chunk-3e49zxqs.js"),import("./chunk-bhjw4b73.js"),import("./chunk-4ydppdj9.js")]),x=W(T(process.argv)).scriptName(N.scriptName).usage(N.usage).version(N.version).locale(N.locale).showHelpOnFail(N.showHelpOnFail).demandCommand(0,"").recommendCommands().strict(N.strict).parserConfiguration({"populate--":!0}).options(G).middleware([M,I,L]).command(R).command(_).command(k).command(y).command(O).command(S).completion("completion",!1).help("help","Show help").alias("help","h").alias("version","V").fail((K,U,Z)=>{if(U){if(console.error("An error occurred:"),console.error(U.message),w&&U.stack)console.error(`
|
|
3
3
|
Stack trace:`),console.error(U.stack);else console.error(`
|
|
4
4
|
Run with --debug to show the stack trace.`);process.exit(1)}if(K)console.error("Error: Invalid arguments:"),console.error(K),console.error(`
|
|
5
|
-
Hint: Did you mean:`),Z.showHelp(),process.exit(1)}).command("$0",!1,()=>{},async(K)=>{let U=K._.slice(1),Z=U.length>0?U.join(" "):void 0,V=import("./chunk-th432d0b.js").then(({checkVersionOnStartup:A})=>A()),[{render:b},{createElement:P},{AppWrapper:h}]=await Promise.all([import("ink"),import("react"),import("./chunk-
|
|
5
|
+
Hint: Did you mean:`),Z.showHelp(),process.exit(1)}).command("$0",!1,()=>{},async(K)=>{let U=K._.slice(1),Z=U.length>0?U.join(" "):void 0,V=import("./chunk-th432d0b.js").then(({checkVersionOnStartup:A})=>A()),[{render:b},{createElement:P},{AppWrapper:h}]=await Promise.all([import("ink"),import("react"),import("./chunk-4fr2426x.js")]),Y={...K,initialMessage:Z,debug:K.debug,print:Boolean(K.print),versionCheckPromise:V};delete Y._,delete Y.$0,delete Y.message,b(P(h,Y),{patchConsole:!0,exitOnCtrlC:!1,alternateBuffer:!1})});try{await x.parse()}catch(K){console.error("Error: Parse error:",K),process.exit(1)}}if(J.main==J.module)f().catch(console.error);export{f as main};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{ba as S,ca as h}from"./chunk-
|
|
1
|
+
import{ba as S,ca as h}from"./chunk-2mg2f5ye.js";import{kb as M}from"./chunk-yddnm9n2.js";import{Db as c}from"./chunk-j2ag7hh6.js";import{EventEmitter as r}from"events";import{z as L}from"zod";import{isPlainObject as v}from"lodash-es";function b(B){if(B===void 0)return"undefined";if(typeof B==="string")return B;try{let G=JSON.stringify(B);return G===void 0?String(B):G}catch{return String(B)}}class R extends Error{issues;type;constructor(B,G,Q="validation_error"){super(B);this.issues=G;this.type=Q;this.name="ToolValidationError"}}function g(B){let{code:G}=B,Q=B,X=Q.received;switch(G){case"invalid_type":{let Y=Q.expected;return`类型错误:期望 ${b(Y)},实际收到 ${b(X)}`}case"too_small":{let{minimum:Y,inclusive:$}=Q,W=typeof Q.type==="string"?Q.type:void 0;if(W==="string"&&typeof Y==="number")return`长度不能少于 ${Y} 个字符`;if(W==="number"&&typeof Y==="number")return`不能小于${$?"等于":""} ${Y}`;if(W==="array"&&typeof Y==="number")return`数组长度不能少于 ${Y}`;return"值太小"}case"too_big":{let{maximum:Y,inclusive:$}=Q,W=typeof Q.type==="string"?Q.type:void 0;if(W==="string"&&typeof Y==="number")return`长度不能超过 ${Y} 个字符`;if(W==="number"&&typeof Y==="number")return`不能大于${$?"等于":""} ${Y}`;if(W==="array"&&typeof Y==="number")return`数组长度不能超过 ${Y}`;return"值太大"}case"invalid_string":{let Y=Q.validation;if(Y==="email")return"必须是有效的电子邮件地址";if(Y==="url")return"必须是有效的 URL";if(Y==="uuid")return"必须是有效的 UUID";if(v(Y)){let $=Y;if(typeof $.includes==="string")return`必须包含 "${$.includes}"`;if(typeof $.startsWith==="string")return`必须以 "${$.startsWith}" 开头`;if(typeof $.endsWith==="string")return`必须以 "${$.endsWith}" 结尾`}return"字符串格式不正确"}case"invalid_enum_value":{let Y=Q.options;if(Array.isArray(Y))return`必须是以下值之一:${Y.map(($)=>b($)).join(", ")}`;return"必须是枚举允许的值之一"}case"invalid_literal":{let Y=Q.expected;return`必须是字面量值:${b(Y)}`}case"unrecognized_keys":{let Y=Q.keys;if(Array.isArray(Y))return`包含未知的参数:${Y.map(($)=>b($)).join(", ")}`;return"包含未知的参数"}case"invalid_union":return"不符合任何有效的类型定义";case"invalid_date":return"必须是有效的日期";case"custom":return B.message||"自定义验证失败";default:return B.message||"验证失败"}}function u(B){let G=B.issues.map((X)=>{let Y=X.path.join("."),$=g(X),W=X.received;return{field:Y||"root",message:$,value:W}}),Q=G.length===1?`参数验证失败 [${G[0].field}]: ${G[0].message}`:`参数验证失败 (${G.length} 个错误):
|
|
2
2
|
${G.map((X)=>` - ${X.field}: ${X.message}`).join(`
|
|
3
3
|
`)}`;return new R(Q,G)}function y(B,G){let Q=B.safeParse(G);if(!Q.success)throw u(Q.error);return Q.data}import{zodToJsonSchema as l}from"zod-to-json-schema";function H(B){let G=l(B,{target:"jsonSchema7",$refStrategy:"none"});if(G.type==="object"&&G.properties&&!Array.isArray(G.required))G.required=[];return G}class w{toolName;params;executeFn;descriptionFn;affectedPathsFn;constructor(B,G,Q,X,Y){this.toolName=B;this.params=G;this.executeFn=Q;this.descriptionFn=X;this.affectedPathsFn=Y}getDescription(){if(this.descriptionFn)return this.descriptionFn(this.params);return`执行工具: ${this.toolName}`}getAffectedPaths(){if(this.affectedPathsFn)return this.affectedPathsFn(this.params);return[]}async execute(B,G,Q){let X={signal:B,updateOutput:G,...Q};return this.executeFn(this.params,X)}}function k(B){return{name:B.name,displayName:B.displayName,kind:B.kind,isReadOnly:B.isReadOnly??M(B.kind),isConcurrencySafe:B.isConcurrencySafe??!1,strict:B.strict??!1,description:B.description,version:B.version||"1.0.0",category:B.category,tags:B.tags||[],getFunctionDeclaration(){let G=H(B.schema),Q=B.description.short;if(B.description.long)Q+=`
|
|
4
4
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e={name:"blade-code",version:"0.5.
|
|
1
|
+
var e={name:"blade-code",version:"0.5.14",private:!1,description:"🗡️ Blade Code - 智能代码助手命令行工具",type:"module",bin:{blade:"dist/blade.js"},files:["dist","vendor/ripgrep/**","README.md"],scripts:{dev:"node scripts/run-bun.js --watch src/blade.tsx","dev:serve":"node scripts/run-bun.js --watch src/blade.tsx serve --port 4097",build:"rm -rf dist && node scripts/run-bun.js run scripts/build.ts",start:"node scripts/run-bun.js run dist/blade.js",test:"node scripts/test.js","test:all":"vitest run --config vitest.config.ts","test:unit":"node scripts/test.js unit","test:integration":"node scripts/test.js integration","test:cli":"node scripts/test.js cli","test:headless-core":"node scripts/test.js headlessCore","test:e2e":"node scripts/test.js e2e","test:performance":"node scripts/test.js performance","test:snapshot":"node scripts/test.js snapshot","test:security":"node scripts/test.js security","test:coverage":"node scripts/test.js all --coverage","test:watch":"vitest --watch --config vitest.config.ts","benchmark:repo":"node scripts/run-bun.js run scripts/run-real-repo-benchmark.ts","test:update-snapshots":"node scripts/test.js snapshot --update",lint:"biome lint src tests","lint:fix":"biome lint --write src tests","type-check":"tsc --noEmit","format:check":"biome format src tests",ready:"node scripts/run-bun.js run scripts/ready.ts","detect-unused":"node scripts/run-bun.js run scripts/detect-unused.ts",release:"node scripts/release.js","release:dry":"node scripts/release.js --dry-run","release:major":"node scripts/release.js --major","release:minor":"node scripts/release.js --minor","release:patch":"node scripts/release.js --patch"},keywords:["cli","blade","ai","assistant","agent","llm"],author:"echoVic",license:"MIT",engines:{node:">=20.0.0"},optionalDependencies:{"@vscode/ripgrep":"^1.17.0","bun-pty":"^0.4.8","node-pty":"1.0.0"},dependencies:{"@agentclientprotocol/sdk":"^0.12.0","@ai-sdk/anthropic":"^3.0.7","@ai-sdk/azure":"^3.0.5","@ai-sdk/deepseek":"^2.0.4","@ai-sdk/google":"^3.0.4","@ai-sdk/openai":"^3.0.26","@ai-sdk/openai-compatible":"^2.0.4","@inkjs/ui":"^2.0.0","@modelcontextprotocol/sdk":"^1.17.4",ahooks:"^3.9.6",ai:"^6.0.39","ansi-escapes":"^7.2.0","async-mutex":"^0.5.0",axios:"^1.12.2",chalk:"^5.4.1",diff:"^8.0.2","fast-glob":"^3.3.3","fuse.js":"^7.1.0","gray-matter":"^4.0.3",hono:"^4.7.10",ink:"npm:@jrichman/ink@6.4.10","ink-big-text":"^2.0.0","ink-gradient":"^3.0.0","ink-select-input":"^6.2.0","ink-spinner":"^5.0.0","ink-text-input":"^6.0.0","js-tiktoken":"^1.0.21","lodash-es":"^4.17.21",lowlight:"^3.3.0","lru-cache":"^11.2.4",nanoid:"^5.1.6",open:"^10.1.2",openai:"^6.2.0",picomatch:"^4.0.3",react:"^19.1.1","react-dom":"^19.1.1",semver:"^7.7.3","string-width":"^8.1.0",undici:"^7.16.0","write-file-atomic":"^7.0.0",ws:"^8.18.0",yaml:"^2.8.1",yargs:"^18.0.0",zod:"^3.24.2","zod-to-json-schema":"^3.24.6",zustand:"^5.0.9"},devDependencies:{"@biomejs/biome":"^2.2.4","@types/bun":"^1.3.4","@types/json-schema":"^7.0.15","@types/lodash-es":"^4.17.12","@types/node":"^22.15.24","@types/picomatch":"^4.0.2","@types/react":"^19.1.1","@types/react-dom":"^19.1.1","@types/semver":"^7.7.1","@types/write-file-atomic":"^4.0.3","@types/ws":"^8.5.12","@types/yargs":"^17.0.33","@vitest/coverage-v8":"^3.0.0",jsdom:"^26.0.0",typescript:"^5.9.2",vitest:"^3.0.0"}};function r(){return{name:e.name,version:e.version,description:e.description}}function n(){return e.version}function o(){return e.name}function c(){return e.description}function d(){return`v${e.version}`}function a(){return`v${e.version} © 2025 Blade Code`}
|
|
2
2
|
export{r as aa,n as ba,o as ca,c as da,d as ea,a as fa};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as y,b as A,c as C,d as D}from"./chunk-
|
|
1
|
+
import{a as y,b as A,c as C,d as D}from"./chunk-j6z6fn0y.js";import"./chunk-q5yn875m.js";import"./chunk-7199c8y4.js";import"./chunk-188szde1.js";import"./chunk-mxrre2n3.js";import"./chunk-2mg2f5ye.js";import"./chunk-68ctb04g.js";import{Aa as q}from"./chunk-x9zj0r7s.js";import"./chunk-mz6n4w13.js";import"./chunk-158qedny.js";import"./chunk-yddnm9n2.js";import"./chunk-yk91w5p2.js";import"./chunk-37rethcy.js";import"./chunk-7ycmx7c2.js";import"./chunk-set7v1rf.js";import"./chunk-j2ag7hh6.js";import H from"chalk";var R={command:"serve",describe:"Start a headless Blade server (no browser)",builder:y,handler:async(E)=>{let f=A(E);if(await q(),!process.env.BLADE_SERVER_PASSWORD)console.log(H.yellow("Warning: BLADE_SERVER_PASSWORD is not set; server is unsecured."));let b=await D.listenAsync(f);if(console.log(`Blade server listening on http://${b.hostname}:${b.port}`),f.hostname==="0.0.0.0"){let F=C();for(let G of F)console.log(` Network: http://${G}:${b.port}`)}await new Promise(()=>{}),await b.stop()}};export{R as serveCommand};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{e as E2,f as h2}from"./chunk-q5yn875m.js";import{h as A4,i as v4,j as R4}from"./chunk-qwfywxs2.js";import{l as D$,m as k4,o as o1}from"./chunk-pfsft4nd.js";import{B as r8,C as e6,D as f4,E as X8,F as e1,G as h6,I as f6,J as D6,M as f$,N as M8,O as D4,P as _1,Q as wJ,R as bJ,S as M6,T as V4,U as C6,W as KJ,y as UJ}from"./chunk-
|
|
1
|
+
import{e as E2,f as h2}from"./chunk-q5yn875m.js";import{h as A4,i as v4,j as R4}from"./chunk-qwfywxs2.js";import{l as D$,m as k4,o as o1}from"./chunk-pfsft4nd.js";import{B as r8,C as e6,D as f4,E as X8,F as e1,G as h6,I as f6,J as D6,M as f$,N as M8,O as D4,P as _1,Q as wJ,R as bJ,S as M6,T as V4,U as C6,W as KJ,y as UJ}from"./chunk-7199c8y4.js";import{Y as S4}from"./chunk-188szde1.js";import"./chunk-mxrre2n3.js";import{fa as I2}from"./chunk-2mg2f5ye.js";import{ga as S8}from"./chunk-68ctb04g.js";import{Aa as x6,Ga as p0,ha as O$,ia as m0,ja as E1,ka as vQ,la as i1,ma as T$,na as iJ,oa as mQ,pa as D2,qa as nJ,sa as K4,ua as iQ,va as H1,wa as C4,xa as w1,ya as b4}from"./chunk-x9zj0r7s.js";import{Ha as I4,Ja as M4}from"./chunk-mz6n4w13.js";import{Na as G4,Oa as T4,Sa as d6}from"./chunk-158qedny.js";import"./chunk-yddnm9n2.js";import{mb as yQ,nb as L1}from"./chunk-yk91w5p2.js";import{qb as o2}from"./chunk-37rethcy.js";import{ub as AJ,xb as A0}from"./chunk-7ycmx7c2.js";import{Bb as j1,yb as P4}from"./chunk-set7v1rf.js";import{Db as s$}from"./chunk-j2ag7hh6.js";import{useMemoizedFn as dQ}from"ahooks";import{useEffect as c5,useState as lQ}from"react";import{useMemoizedFn as r0}from"ahooks";import{Box as l1}from"ink";import{useEffect as r1,useRef as T8}from"react";import{useShallow as nQ}from"zustand/react/shallow";import{useStore as c4}from"zustand";function Q0($){return c4(iQ,$)}var u4=[],tQ=()=>Q0(($)=>$.session.sessionId),sQ=()=>Q0(($)=>$.session.messages),eQ=()=>Q0(($)=>$.session.clearCount),$6=()=>Q0(($)=>$.session.isCompacting),Q6=()=>Q0(($)=>$.session.tokenUsage.estimatedCostUsd),f1=()=>Q0(($)=>$.session.actions),J6=()=>Q0(($)=>{let{inputTokens:Q,maxContextTokens:J}=$.session.tokenUsage;if(J<=0)return 100;let Y=Math.max(0,100-Q/J*100);return Math.round(Y)}),Y6=()=>Q0(($)=>$.app.initializationStatus),Z6=()=>Q0(($)=>$.app.initializationError),a$=()=>Q0(($)=>$.app.activeModal),X6=()=>Q0(($)=>$.app.tasks),q6=()=>Q0(($)=>$.app.modelEditorTarget),G6=()=>Q0(($)=>$.app.sessionSelectorData),U6=()=>Q0(($)=>$.app.awaitingSecondCtrlC),D1=()=>Q0(($)=>$.app.actions),o$=()=>Q0(($)=>$.app.initializationStatus==="ready"),K6=()=>Q0(($)=>$.app.tasks.length>0),_$=()=>Q0(($)=>$.config.config?.permissionMode||"default"),O6=()=>Q0(($)=>$.config.config?.models??u4),i$=()=>Q0(($)=>{let Q=$.config.config;if(!Q)return;let J=Q.currentModelId;return Q.models.find((Z)=>Z.id===J)??Q.models[0]}),z6=()=>Q0(($)=>$.config.config?.currentModelId),_0=()=>Q0(($)=>{return m0.getTheme()}),_6=()=>Q0(($)=>$.config.config?.theme??"default"),i0=()=>Q0(($)=>$.focus.currentFocus),N6=()=>Q0(($)=>$.focus.actions),V1=()=>Q0(($)=>$.command.isProcessing),F6=()=>Q0(($)=>$.command.actions),W6=()=>Q0(($)=>$.command.pendingCommands),n$=()=>Q0(($)=>$.app.thinkingModeEnabled),H6=()=>Q0(($)=>$.session.currentThinkingContent),L6=()=>Q0(($)=>$.session.thinkingExpanded),w6=()=>Q0(($)=>$.session.currentStreamingMessageId),b6=()=>Q0(nQ(($)=>({lines:$.session.currentStreamingLines,tail:$.session.currentStreamingTail,lineCount:$.session.currentStreamingLineCount,version:$.session.currentStreamingVersion}))),B6=()=>Q0(($)=>$.session.finalizingStreamingMessageId),A6=()=>Q0(($)=>$.session.historyExpanded),v6=()=>Q0(($)=>$.session.expandedMessageCount),R6=()=>Q0(nQ(($)=>{let Q=$.spec.currentSpec;if(!Q)return{phase:null,completed:0,total:0};let J=Q.tasks??[],Y=J.filter((Z)=>Z.status==="completed").length;return{phase:Q.phase,completed:Y,total:J.length}}));import{useMemoizedFn as u8}from"ahooks";import{useEffect as c6,useRef as Y9}from"react";function x4($){if(!($ instanceof Error))return"未知错误";let Y=$.lastError??$;if(Y.responseBody)try{let X=JSON.parse(Y.responseBody)?.error?.message;if(X){let G=Y.statusCode?` (HTTP ${Y.statusCode})`:"";return`${X}${G}`}}catch{}let Z=$.message.match(/Last error:\s*(.+)$/);if(Z)return Z[1];return $.message}function d4($){if(!($ instanceof Error))return!1;return $.name==="AbortError"||$.message.includes("aborted")}function l4($){if(!($ instanceof Error))return!1;let Q=$.message;return Q.includes("can only concatenate str")||Q.includes("image_url")||Q.includes("multimodal")||Q.includes("vision")||Q.includes("does not support images")}function m8($){let Q=d4($),J=l4($),Y;if(J)Y="当前模型不支持图片理解功能。请切换到支持视觉能力的模型(如 Claude 4.5、GPT-5.2、Gemini 3 Pro、Qwen3-VL-Plus 等)后重试。";else Y=x4($);return{displayMessage:Y,isAbort:Q,isVisionNotSupported:J}}function y6($){let{text:Q,images:J,parts:Y}=$;if(J.length===0)return Q;let Z=[];for(let q of Y)if(q.type==="text")Z.push({type:"text",text:q.text});else Z.push({type:"image_url",image_url:{url:`data:${q.mimeType};base64,${q.base64}`}});return Z}function P6($){return{role:$.role,content:$.content}}function I6($){if(!$.restoredContextMessages||$.restoredVisibleMessageCount<=0)return $.messages.map(P6);let Q=$.messages.slice($.restoredVisibleMessageCount).map(P6);return[...$.restoredContextMessages,...Q]}function r4($){return typeof $==="object"&&$!==null&&$.action==="invoke_skill"&&typeof $.skillName==="string"}function a4($){return typeof $==="object"&&$!==null&&$.action==="invoke_custom_command"&&typeof $.commandName==="string"&&typeof $.processedContent==="string"}function o4($){return typeof $==="object"&&$!==null&&$.action==="invoke_plugin_command"&&typeof $.commandName==="string"&&typeof $.processedContent==="string"}function i4($){return typeof $==="object"&&$!==null&&$.action==="invoke_once_model"&&typeof $.modelId==="string"&&typeof $.prompt==="string"}function n4($,Q,J,Y){switch($){case"show_theme_selector":return J.setActiveModal("themeSelector"),!0;case"show_model_selector":return J.setActiveModal("modelSelector"),!0;case"show_model_add_wizard":return J.setActiveModal("modelAddWizard"),!0;case"show_permissions_manager":return J.setActiveModal("permissionsManager"),!0;case"show_agents_manager":return J.setActiveModal("agentsManager"),!0;case"show_skills_manager":return J.setActiveModal("skillsManager"),!0;case"show_hooks_manager":return J.setActiveModal("hooksManager"),!0;case"show_plugins_manager":return J.setActiveModal("pluginsManager"),!0;case"show_agent_creation_wizard":return J.setActiveModal("agentCreationWizard"),!0;case"show_session_selector":{let Z=Q?.sessions;return J.showSessionSelector(Z),!0}case"clear_screen":return Y.clearMessages(),Y.setError(null),Y.resetTokenUsage(),J.setTasks([]),!0;case"compact_completed":case"compact_fallback":return Y.resetTokenUsage(),!0;case"exit_application":return o1(0),!0;default:return!1}}async function k6($,Q,J,Y){let{text:Z}=$;if(!M6(Z))return{type:"not_slash"};let q={cwd:A0(),signal:Y},X=await C6(Z,q);if(X.message){if(n4(X.message,X.data,Q,J))return{type:"handled",commandResult:{success:!0}}}if(r4(X.data)){let{skillName:K,skillArgs:U}=X.data,F=U?`Please use the "${K}" skill to help me with: ${U}`:`Please use the "${K}" skill.`;return J.addUserMessage(F),{type:"continue_as_agent",result:{userDisplayMessage:F,agentInput:{displayText:F,text:F,images:[],parts:[{type:"text",text:F}]},userMessageAlreadyAdded:!0}}}if(a4(X.data)){let{commandName:K,processedContent:U}=X.data;J.addUserMessage(Z);let F=`# Custom Command: /${K}
|
|
2
2
|
|
|
3
3
|
The user has invoked the custom command "/${K}". Follow the instructions below to complete the task.
|
|
4
4
|
|
|
@@ -126,7 +126,7 @@ ${V}
|
|
|
126
126
|
`);while(Z.length>0&&Z[0].trim()==="")Z.shift();while(Z.length>0&&Z[Z.length-1].trim()==="")Z.pop();let q=Z.length>50,X=q?Z.slice(0,50):Z,G=X.join(`
|
|
127
127
|
`),K=G.includes("<<<DIFF>>>"),U=G.includes("```");if(K){let F=G.match(/<<<DIFF>>>\s*({[\s\S]*?})\s*<<<\/DIFF>>>/);if(F)try{let O=JSON.parse(F[1]);return f(X0,{flexDirection:"column",children:[f(ZQ,{patch:O.patch,startLine:O.startLine,matchLine:O.matchLine,terminalWidth:Q},void 0,!1,void 0,this),q&&f(X0,{marginTop:1,children:f(N0,{dimColor:!0,color:J.colors.text.muted,children:["... 省略 ",Z.length-50," 行 ..."]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}catch{}}if(U){let F=G.match(/```(\w+)?\s*\n([\s\S]*?)\n```/);if(F){let O=F[1]||"text",N=F[2];return f(X0,{flexDirection:"column",children:[f(_8,{content:N,language:O,showLineNumbers:!1,terminalWidth:Q},void 0,!1,void 0,this),q&&f(X0,{marginTop:1,children:f(N0,{dimColor:!0,color:J.colors.text.muted,children:["... 省略 ",Z.length-50," 行 ..."]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}}return f(X0,{flexDirection:"column",children:[X.map((F,O)=>f(N0,{color:J.colors.text.primary,children:F},O,!1,void 0,this)),q&&f(X0,{marginTop:1,children:f(N0,{dimColor:!0,color:J.colors.text.muted,children:["... 省略 ",Z.length-50," 行 ..."]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)});function k3($,Q,J,Y=80){if(!J||Q===void 0||Q<=0)return{content:$,isTruncated:!1,hiddenLines:0};let q=Math.max(1,Q-8),X=Math.max(40,Y*0.8),G=q*X;if($.length<=G)return{content:$,isTruncated:!1,hiddenLines:0};let K=Math.floor(G*0.9),U=$.length-K,F=U,O=$.indexOf(`
|
|
128
128
|
`,U);if(O!==-1&&O-U<X)F=O+1;let N=$.slice(F),_=($.slice(0,F).match(/\n/g)||[]).length+1;return{content:N,isTruncated:!0,hiddenLines:_}}var h1=J$.memo(({content:$,role:Q,terminalWidth:J,metadata:Y,isPending:Z=!1,availableTerminalHeight:q,hidePrefix:X=!1,noMargin:G=!1,renderPlainTextOnly:K=!1,streamingLines:U,streamingHiddenLines:F,messageId:O,blocksOverride:N,currentLineOverride:z,streamingMode:_="text",renderCodeBlocksAsPlainText:W=!1})=>{let w=_0(),L=N!==void 0,H=Q$(()=>v3(Q,w.colors,Y),[Q,w.colors,Y]),{color:R,prefix:I}=H,v=I.length+1,B=Q$(()=>{if(!Y||typeof Y!=="object")return null;if(!("subtaskRef"in Y))return null;let P=Y.subtaskRef;if(!P||typeof P!=="object")return null;return P},[Y]),A=Q==="tool"&&Y?.phase==="start",b=!G&&!A,k=Q$(()=>{if(!K)return[];return $.split(/\r?\n/)},[$,K]);if(!L&&Z){let P=U??$.split(/\r?\n/),r=F??0,T=!1,h=!1,S=!1;if(_!=="text")T=_==="code",h=_==="diff",S=_==="table";return f(X0,{flexDirection:"column",marginBottom:b?1:0,flexShrink:0,children:[r>0&&f(X0,{flexDirection:"row",flexShrink:0,children:[f(X0,{width:v,flexShrink:0},void 0,!1,void 0,this),f(N0,{color:w.colors.text.muted,dimColor:!0,children:["^ ",r," lines above (streaming...)"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),P.map((i,D0)=>{if(_==="text"){if(i.match(E1.codeBlock))T=!T;else if(i.match(E1.diffStart))h=!0;else if(i.match(E1.diffEnd))h=!1;else if(i.match(E1.table))S=!0;else if(S&&!i.match(E1.table))S=!1}let B0=_==="text"&&!T&&!h&&!S,o0=B0?i.match(E1.ulItem):null,S0=B0?i.match(E1.olItem):null,J1=o0??S0;return f(X0,{flexDirection:"row",flexShrink:0,children:[D0===0&&!X?f(X0,{marginRight:1,flexShrink:0,children:f(N0,{color:R,bold:!0,children:I},void 0,!1,void 0,this)},void 0,!1,void 0,this):f(X0,{width:v,flexShrink:0},void 0,!1,void 0,this),f(X0,{flexGrow:1,flexShrink:0,children:J1?f(wQ,{type:o0?"ul":"ol",marker:J1[2],itemText:J1[3],leadingWhitespace:J1[1]},void 0,!1,void 0,this):f(N0,{wrap:"wrap",children:i===""?" ":i},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},D0,!0,void 0,this)})]},void 0,!0,void 0,this)}if(!L&&K)return f(X0,{flexDirection:"column",marginBottom:b?1:0,flexShrink:0,children:k.map((P,r)=>f(X0,{flexDirection:"row",flexShrink:0,children:[r===0&&!X?f(X0,{marginRight:1,flexShrink:0,children:f(N0,{color:R,bold:!0,children:I},void 0,!1,void 0,this)},void 0,!1,void 0,this):f(X0,{width:v,flexShrink:0},void 0,!1,void 0,this),f(X0,{flexGrow:1,flexShrink:0,children:f(N0,{wrap:"wrap",children:P===""?" ":P},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},r,!0,void 0,this))},void 0,!1,void 0,this);let V=oJ(null);AQ(()=>{V.current=null},[O]);let p=Q$(()=>{if(L)return null;if(!O)return null;return iJ(O)},[O,L]);AQ(()=>{if(L)return;if(!p||!O)return;V.current={messageId:O,blocks:p}},[p,O,L]),AQ(()=>{if(L)return;if(!p||!O)return;nJ(O)},[p,O,L]);let d=Q$(()=>L?{content:$,isTruncated:!1,hiddenLines:0}:k3($,q,Z,J),[$,q,Z,J,L]),{content:l,isTruncated:s,hiddenLines:D}=d;if(!L&&Q==="tool"&&Y&&"detail"in Y){let P=Y;if(P.detail)return f(X0,{flexDirection:"column",marginBottom:G?0:1,children:[f(X0,{flexDirection:"row",children:[f(X0,{marginRight:1,children:f(N0,{color:R,bold:!0,children:I},void 0,!1,void 0,this)},void 0,!1,void 0,this),f(N0,{color:R,children:$},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f(X0,{marginLeft:I.length+1,children:f(C3,{detail:P.detail,terminalWidth:J-(I.length+1)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}let{completedContent:C,currentLine:y}=Q$(()=>{if(L)return{completedContent:"",currentLine:z??""};if(!Z)return{completedContent:l,currentLine:""};let P=l.lastIndexOf(`
|
|
129
|
-
`);if(P===-1)return{completedContent:"",currentLine:l};return{completedContent:l.slice(0,P+1),currentLine:l.slice(P+1)}},[l,Z,L,z]),a=oJ({content:"",blocks:[]}),u=Q$(()=>{if(L)return N??[];if(p)return p;if(V.current&&V.current.messageId===O)return V.current.blocks;let P=a.current;if(!Z||!C.startsWith(P.content)){let S=vQ(C);return a.current={content:C,blocks:S},S}if(C===P.content)return P.blocks;let r=C.slice(P.content.length),T=vQ(r),h=[...P.blocks,...T];return a.current={content:C,blocks:h},h},[C,Z,L,N]);return f(X0,{flexDirection:"column",marginBottom:b?1:0,flexShrink:0,children:[s&&f(X0,{flexDirection:"row",flexShrink:0,children:[f(X0,{width:v,flexShrink:0},void 0,!1,void 0,this),f(N0,{color:w.colors.text.muted,dimColor:!0,children:["^ ",D," lines above (streaming...)"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),u.map((P,r)=>{if(P.type==="empty")return f(X0,{height:1,flexShrink:0},r,!1,void 0,this);return f(X0,{flexDirection:"row",flexShrink:0,children:[r===0&&!X&&f(X0,{marginRight:1,flexShrink:0,children:f(N0,{color:R,bold:!0,children:I},void 0,!1,void 0,this)},void 0,!1,void 0,this),(r>0||X)&&f(X0,{width:v,flexShrink:0},void 0,!1,void 0,this),f(X0,{flexGrow:1,flexShrink:0,children:P.type==="code"?W?f(N0,{wrap:"wrap",children:P.content},void 0,!1,void 0,this):f(R3,{content:P.content,language:P.language,terminalWidth:J-v,isPending:Z,availableHeight:q},void 0,!1,void 0,this):P.type==="table"&&P.tableData?f(aJ,{headers:P.tableData.headers,rows:P.tableData.rows,terminalWidth:J-v},void 0,!1,void 0,this):P.type==="heading"?f(y3,{content:P.content,level:P.level||1},void 0,!1,void 0,this):P.type==="list"?f(wQ,{type:P.listType||"ul",marker:P.marker||"-",itemText:P.content,leadingWhitespace:" ".repeat(P.indentation||0)},void 0,!1,void 0,this):P.type==="hr"?f(P3,{terminalWidth:J-v},void 0,!1,void 0,this):P.type==="diff"&&P.diffData?f(ZQ,{patch:P.diffData.patch,startLine:P.diffData.startLine,matchLine:P.diffData.matchLine,terminalWidth:J-v},void 0,!1,void 0,this):P.type==="command-message"?f(M3,{content:P.content},void 0,!1,void 0,this):P.type==="blockquote"&&P.blockquoteLines?f(xJ,{lines:P.blockquoteLines,level:P.blockquoteLevel||1},void 0,!1,void 0,this):f(I3,{content:P.content},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},r,!0,void 0,this)}),y&&f(X0,{flexDirection:"row",flexShrink:0,children:[u.length===0&&!X?f(X0,{marginRight:1,flexShrink:0,children:f(N0,{color:R,bold:!0,children:I},void 0,!1,void 0,this)},void 0,!1,void 0,this):f(X0,{width:v,flexShrink:0},void 0,!1,void 0,this),f(X0,{flexGrow:1,flexShrink:0,children:f(N0,{wrap:"wrap",children:y},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),B&&f(X0,{flexDirection:"row",flexShrink:0,children:[f(X0,{width:v,flexShrink:0},void 0,!1,void 0,this),f(X0,{flexDirection:"column",flexGrow:1,flexShrink:0,children:[f(N0,{color:w.colors.text.muted,children:["Subtask ",typeof B.agentType==="string"?`@${B.agentType}`:"",typeof B.status==="string"?` · ${B.status}`:""]},void 0,!0,void 0,this),typeof B.summary==="string"&&B.summary.trim()!==""&&f(N0,{wrap:"wrap",children:B.summary},void 0,!1,void 0,this),typeof B.childSessionId==="string"&&f(N0,{color:w.colors.text.muted,children:["Session ",B.childSessionId]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},($,Q)=>{return $.content===Q.content&&$.role===Q.role&&$.terminalWidth===Q.terminalWidth&&$.isPending===Q.isPending&&$.availableTerminalHeight===Q.availableTerminalHeight&&$.hidePrefix===Q.hidePrefix&&$.noMargin===Q.noMargin&&$.renderPlainTextOnly===Q.renderPlainTextOnly&&$.streamingHiddenLines===Q.streamingHiddenLines&&$.streamingLines===Q.streamingLines&&$.messageId===Q.messageId&&$.metadata===Q.metadata&&$.blocksOverride===Q.blocksOverride&&$.currentLineOverride===Q.currentLineOverride&&$.streamingMode===Q.streamingMode&&$.renderCodeBlocksAsPlainText===Q.renderCodeBlocksAsPlainText});import{jsxDEV as w0,Fragment as E3}from"react/jsx-dev-runtime";var D3=RQ.memo(({label:$,isSelected:Q})=>w0(N1,{color:Q?"yellow":void 0,children:$},void 0,!1,void 0,this)),V3=RQ.memo(({details:$,headerColor:Q,isPlanModeExit:J,isPlanModeEnter:Y,terminalWidth:Z})=>w0(E3,{children:[w0(Z1,{marginBottom:1,children:w0(N1,{children:$.message},void 0,!1,void 0,this)},void 0,!1,void 0,this),$.planContent&&w0(Z1,{flexDirection:"column",marginBottom:1,borderStyle:"single",borderColor:Q,padding:1,children:[w0(N1,{bold:!0,color:Q,children:"实施方案"},void 0,!1,void 0,this),w0(Z1,{marginTop:1,children:w0(h1,{content:$.planContent,role:"assistant",terminalWidth:Z-4},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!$.planContent&&$.details&&w0(Z1,{flexDirection:"column",marginBottom:1,children:w0(h1,{content:$.details,role:"assistant",terminalWidth:Z},void 0,!1,void 0,this)},void 0,!1,void 0,this),$.risks&&$.risks.length>0&&w0(Z1,{flexDirection:"column",marginBottom:1,children:[w0(N1,{color:"red",bold:!0,children:"风险提示:"},void 0,!1,void 0,this),$.risks.map((q,X)=>w0(Z1,{marginLeft:2,children:w0(N1,{color:"red",children:["• ",q]},void 0,!0,void 0,this)},X,!1,void 0,this))]},void 0,!0,void 0,this),$.affectedFiles&&$.affectedFiles.length>0&&w0(Z1,{flexDirection:"column",marginBottom:1,children:[w0(N1,{color:"yellow",children:"影响的文件:"},void 0,!1,void 0,this),$.affectedFiles.slice(0,3).map((q,X)=>w0(Z1,{marginLeft:2,children:w0(N1,{children:["• ",q]},void 0,!0,void 0,this)},X,!1,void 0,this)),$.affectedFiles.length>3&&w0(Z1,{marginLeft:2,children:w0(N1,{color:"gray",children:["...还有 ",$.affectedFiles.length-3," 个文件"]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this));function j3($,Q){return`使用 ↑↓ 选择,回车确认 · ${$||Q?"Y/N":"Y/S/N"} 快捷键 · Esc 取消`}var sJ=RQ.memo(({details:$,onResponse:Q})=>{let{stdout:J}=T3(),Y=J.columns||80,q=i0()==="confirmation-prompt",X=P0(!1),G=$.type==="exitPlanMode",K=$.type==="enterPlanMode",U=$.type==="maxTurnsExceeded";S3((N,z)=>{if(z.ctrl&&N==="c"||z.meta&&N==="c"){X();return}if(z.escape){Q({approved:!1,reason:"用户取消"});return}let _=N.toLowerCase();if(G){if(_==="y"){Q({approved:!0,targetMode:"autoEdit"});return}if(_==="s"){Q({approved:!0,targetMode:"default"});return}if(_==="n"){Q({approved:!1,reason:"方案需要改进"});return}}else if(K){if(_==="y"){Q({approved:!0});return}if(_==="n"){Q({approved:!1,reason:"用户拒绝进入 Plan 模式"});return}}else if(U){if(_==="y"){Q({approved:!0});return}if(_==="n"){Q({approved:!1,reason:"用户选择停止"});return}}else{if(_==="y"){Q({approved:!0,scope:"once"});return}if(_==="s"){Q({approved:!0,scope:"session"});return}if(_==="n"){Q({approved:!1,reason:"用户拒绝"});return}}},{isActive:q});let F=tJ(()=>{if(G)return[{key:"approve-auto",label:"[Y] 批准,自动执行",value:{approved:!0,targetMode:"autoEdit"}},{key:"approve-default",label:"[S] 批准,逐步确认",value:{approved:!0,targetMode:"default"}},{key:"reject",label:"[N] 继续优化方案",value:{approved:!1,reason:"方案需要改进"}}];if(K)return[{key:"approve",label:"[Y] 进入规划模式",value:{approved:!0}},{key:"reject",label:"[N] 直接执行",value:{approved:!1,reason:"用户拒绝进入 Plan 模式"}}];if(U)return[{key:"continue",label:"[Y] 继续执行",value:{approved:!0}},{key:"stop",label:"[N] 停止",value:{approved:!1,reason:"用户选择停止"}}];return[{key:"approve-once",label:"[Y] 允许(仅本次)",value:{approved:!0,scope:"once"}},{key:"approve-session",label:"[S] 允许(记住本项目)",value:{approved:!0,scope:"session"}},{key:"reject",label:"[N] 拒绝",value:{approved:!1,reason:"用户拒绝"}}]},[G,K,U]),O=tJ(()=>{if(G)return{color:"cyan",title:"方案审核"};if(K)return{color:"magenta",title:"进入规划模式"};if(U)return{color:"yellow",title:"已达最大轮次"};return{color:"yellow",title:$.title||"操作确认"}},[G,K,U,$.title]);return w0(Z1,{flexDirection:"column",borderStyle:"round",borderColor:q?O.color:"gray",padding:1,children:[w0(Z1,{marginBottom:1,children:w0(N1,{bold:!0,color:O.color,children:O.title},void 0,!1,void 0,this)},void 0,!1,void 0,this),w0(V3,{details:$,headerColor:O.color,isPlanModeExit:G,isPlanModeEnter:K,terminalWidth:Y},void 0,!1,void 0,this),w0(Z1,{flexDirection:"column",children:[w0(N1,{color:"gray",children:j3(K,U)},void 0,!1,void 0,this),w0(f3,{items:F,isFocused:q,itemComponent:D3,onSelect:(N)=>{Q(N.value)}},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)});import{Box as K0,Text as $0,useInput as h3}from"ink";import eJ from"ink-text-input";import{useState as v1}from"react";import{jsxDEV as j}from"react/jsx-dev-runtime";var g$=[{action:"add",description:"Add a new hook"},{action:"status",description:"Show hooks status"},{action:"list",description:"List all configured hooks"}],H8=[{location:"local",name:"Project settings (local)",description:"Saved in .blade/settings.local.json"},{location:"project",name:"Project settings",description:"Checked in at .blade/settings.json"},{location:"user",name:"User settings",description:"Saved in at ~/.blade/settings.json"}],L8=[{event:"PreToolUse",description:"Before tool execution"},{event:"PostToolUse",description:"After tool execution"},{event:"PostToolUseFailure",description:"After tool execution fails"},{event:"PermissionRequest",description:"When permission is requested"},{event:"UserPromptSubmit",description:"Before processing user prompt"},{event:"Stop",description:"When Claude stops responding"},{event:"SubagentStop",description:"When subagent stops"},{event:"SessionStart",description:"When session starts"},{event:"SessionEnd",description:"When session ends"},{event:"Notification",description:"When notification is sent"},{event:"Compaction",description:"Before context compaction"}],m3=[`jq -r '.tool_input.file_path | select(endswith(".go"))' | xargs -r gofmt -w`,`jq -r '"\\(.tool_input.command) - \\(.tool_input.description // "No description")"' >> ~/.blade/bash-command-log.txt`,"/usr/local/bin/security_check.sh","python3 ~/hooks/validate_changes.py"],$2=({onClose:$,onSave:Q})=>{let J=m0.getTheme(),[Y,Z]=v1("action"),[q,X]=v1(0),[G,K]=v1(0),[U,F]=v1(0),[O,N]=v1(""),[z,_]=v1(""),[W,w]=v1(null),[L,H]=v1(!1),[R,I]=v1(null),v=g$[q],B=L8[G],A=H8[U],b=()=>{if(R){I(null);return}switch(Y){case"action":$();break;case"event":Z("action");break;case"matcher":Z("event");break;case"command":Z("matcher");break;case"location":Z("command");break;case"confirm":Z("location");break}};h3((D,C)=>{if(C.escape){b();return}if(Y==="action"){if(C.upArrow)X((y)=>y>0?y-1:g$.length-1);else if(C.downArrow)X((y)=>y<g$.length-1?y+1:0);else if(C.return)k()}else if(Y==="event"){if(C.upArrow)K((y)=>y>0?y-1:L8.length-1);else if(C.downArrow)K((y)=>y<L8.length-1?y+1:0);else if(C.return)Z("matcher")}else if(Y==="location"){if(C.upArrow)F((y)=>y>0?y-1:H8.length-1);else if(C.downArrow)F((y)=>y<H8.length-1?y+1:0);else if(C.return)Z("confirm")}else if(Y==="confirm"){if(C.return)s()}});let k=()=>{let D=g$[q].action;if(D==="add")Z("event");else if(D==="status")V();else if(D==="list")p()},V=()=>{let D=L1.getInstance(),C=D.isEnabled(),y=D.getConfig(),a={};for(let P of Object.values(yQ)){let r=y[P];if(r&&Array.isArray(r)){let T=r.reduce((h,S)=>h+(S.hooks?.length||0),0);if(T>0)a[P]=T}}let u=[`Status: ${C?"Enabled":"Disabled"}`,""];if(Object.keys(a).length>0){u.push("Configured hooks:");for(let[P,r]of Object.entries(a))u.push(` ${P}: ${r} hook(s)`)}else u.push("No hooks configured");I(u.join(`
|
|
129
|
+
`);if(P===-1)return{completedContent:"",currentLine:l};return{completedContent:l.slice(0,P+1),currentLine:l.slice(P+1)}},[l,Z,L,z]),a=oJ({content:"",blocks:[]}),u=Q$(()=>{if(L)return N??[];if(p)return p;if(V.current&&V.current.messageId===O)return V.current.blocks;let P=a.current;if(!Z||!C.startsWith(P.content)){let S=vQ(C);return a.current={content:C,blocks:S},S}if(C===P.content)return P.blocks;let r=C.slice(P.content.length),T=vQ(r),h=[...P.blocks,...T];return a.current={content:C,blocks:h},h},[C,Z,L,N]);return f(X0,{flexDirection:"column",marginBottom:b?1:0,flexShrink:0,children:[s&&f(X0,{flexDirection:"row",flexShrink:0,children:[f(X0,{width:v,flexShrink:0},void 0,!1,void 0,this),f(N0,{color:w.colors.text.muted,dimColor:!0,children:["^ ",D," lines above (streaming...)"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),u.map((P,r)=>{if(P.type==="empty")return f(X0,{height:1,flexShrink:0},r,!1,void 0,this);return f(X0,{flexDirection:"row",flexShrink:0,children:[r===0&&!X&&f(X0,{marginRight:1,flexShrink:0,children:f(N0,{color:R,bold:!0,children:I},void 0,!1,void 0,this)},void 0,!1,void 0,this),(r>0||X)&&f(X0,{width:v,flexShrink:0},void 0,!1,void 0,this),f(X0,{flexGrow:1,flexShrink:0,children:P.type==="code"?W?f(N0,{wrap:"wrap",children:P.content},void 0,!1,void 0,this):f(R3,{content:P.content,language:P.language,terminalWidth:J-v,isPending:Z,availableHeight:q},void 0,!1,void 0,this):P.type==="table"&&P.tableData?f(aJ,{headers:P.tableData.headers,rows:P.tableData.rows,terminalWidth:J-v},void 0,!1,void 0,this):P.type==="heading"?f(y3,{content:P.content,level:P.level||1},void 0,!1,void 0,this):P.type==="list"?f(wQ,{type:P.listType||"ul",marker:P.marker||"-",itemText:P.content,leadingWhitespace:" ".repeat(P.indentation||0)},void 0,!1,void 0,this):P.type==="hr"?f(P3,{terminalWidth:J-v},void 0,!1,void 0,this):P.type==="diff"&&P.diffData?f(ZQ,{patch:P.diffData.patch,startLine:P.diffData.startLine,matchLine:P.diffData.matchLine,terminalWidth:J-v},void 0,!1,void 0,this):P.type==="command-message"?f(M3,{content:P.content},void 0,!1,void 0,this):P.type==="blockquote"&&P.blockquoteLines?f(xJ,{lines:P.blockquoteLines,level:P.blockquoteLevel||1},void 0,!1,void 0,this):f(I3,{content:P.content},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},r,!0,void 0,this)}),y&&f(X0,{flexDirection:"row",flexShrink:0,children:[u.length===0&&!X?f(X0,{marginRight:1,flexShrink:0,children:f(N0,{color:R,bold:!0,children:I},void 0,!1,void 0,this)},void 0,!1,void 0,this):f(X0,{width:v,flexShrink:0},void 0,!1,void 0,this),f(X0,{flexGrow:1,flexShrink:0,children:f(N0,{wrap:"wrap",children:y},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),B&&f(X0,{flexDirection:"row",flexShrink:0,children:[f(X0,{width:v,flexShrink:0},void 0,!1,void 0,this),f(X0,{flexDirection:"column",flexGrow:1,flexShrink:0,children:[f(N0,{color:w.colors.text.muted,children:["Subtask"," ",typeof B.agentType==="string"?`@${B.agentType}`:"",typeof B.status==="string"?` · ${B.status}`:""]},void 0,!0,void 0,this),typeof B.summary==="string"&&B.summary.trim()!==""&&f(N0,{wrap:"wrap",children:B.summary},void 0,!1,void 0,this),typeof B.childSessionId==="string"&&f(N0,{color:w.colors.text.muted,children:["Session ",B.childSessionId]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},($,Q)=>{return $.content===Q.content&&$.role===Q.role&&$.terminalWidth===Q.terminalWidth&&$.isPending===Q.isPending&&$.availableTerminalHeight===Q.availableTerminalHeight&&$.hidePrefix===Q.hidePrefix&&$.noMargin===Q.noMargin&&$.renderPlainTextOnly===Q.renderPlainTextOnly&&$.streamingHiddenLines===Q.streamingHiddenLines&&$.streamingLines===Q.streamingLines&&$.messageId===Q.messageId&&$.metadata===Q.metadata&&$.blocksOverride===Q.blocksOverride&&$.currentLineOverride===Q.currentLineOverride&&$.streamingMode===Q.streamingMode&&$.renderCodeBlocksAsPlainText===Q.renderCodeBlocksAsPlainText});import{jsxDEV as w0,Fragment as E3}from"react/jsx-dev-runtime";var D3=RQ.memo(({label:$,isSelected:Q})=>w0(N1,{color:Q?"yellow":void 0,children:$},void 0,!1,void 0,this)),V3=RQ.memo(({details:$,headerColor:Q,isPlanModeExit:J,isPlanModeEnter:Y,terminalWidth:Z})=>w0(E3,{children:[w0(Z1,{marginBottom:1,children:w0(N1,{children:$.message},void 0,!1,void 0,this)},void 0,!1,void 0,this),$.planContent&&w0(Z1,{flexDirection:"column",marginBottom:1,borderStyle:"single",borderColor:Q,padding:1,children:[w0(N1,{bold:!0,color:Q,children:"实施方案"},void 0,!1,void 0,this),w0(Z1,{marginTop:1,children:w0(h1,{content:$.planContent,role:"assistant",terminalWidth:Z-4},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!$.planContent&&$.details&&w0(Z1,{flexDirection:"column",marginBottom:1,children:w0(h1,{content:$.details,role:"assistant",terminalWidth:Z},void 0,!1,void 0,this)},void 0,!1,void 0,this),$.risks&&$.risks.length>0&&w0(Z1,{flexDirection:"column",marginBottom:1,children:[w0(N1,{color:"red",bold:!0,children:"风险提示:"},void 0,!1,void 0,this),$.risks.map((q,X)=>w0(Z1,{marginLeft:2,children:w0(N1,{color:"red",children:["• ",q]},void 0,!0,void 0,this)},X,!1,void 0,this))]},void 0,!0,void 0,this),$.affectedFiles&&$.affectedFiles.length>0&&w0(Z1,{flexDirection:"column",marginBottom:1,children:[w0(N1,{color:"yellow",children:"影响的文件:"},void 0,!1,void 0,this),$.affectedFiles.slice(0,3).map((q,X)=>w0(Z1,{marginLeft:2,children:w0(N1,{children:["• ",q]},void 0,!0,void 0,this)},X,!1,void 0,this)),$.affectedFiles.length>3&&w0(Z1,{marginLeft:2,children:w0(N1,{color:"gray",children:["...还有 ",$.affectedFiles.length-3," 个文件"]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this));function j3($,Q){return`使用 ↑↓ 选择,回车确认 · ${$||Q?"Y/N":"Y/S/N"} 快捷键 · Esc 取消`}var sJ=RQ.memo(({details:$,onResponse:Q})=>{let{stdout:J}=T3(),Y=J.columns||80,q=i0()==="confirmation-prompt",X=P0(!1),G=$.type==="exitPlanMode",K=$.type==="enterPlanMode",U=$.type==="maxTurnsExceeded";S3((N,z)=>{if(z.ctrl&&N==="c"||z.meta&&N==="c"){X();return}if(z.escape){Q({approved:!1,reason:"用户取消"});return}let _=N.toLowerCase();if(G){if(_==="y"){Q({approved:!0,targetMode:"autoEdit"});return}if(_==="s"){Q({approved:!0,targetMode:"default"});return}if(_==="n"){Q({approved:!1,reason:"方案需要改进"});return}}else if(K){if(_==="y"){Q({approved:!0});return}if(_==="n"){Q({approved:!1,reason:"用户拒绝进入 Plan 模式"});return}}else if(U){if(_==="y"){Q({approved:!0});return}if(_==="n"){Q({approved:!1,reason:"用户选择停止"});return}}else{if(_==="y"){Q({approved:!0,scope:"once"});return}if(_==="s"){Q({approved:!0,scope:"session"});return}if(_==="n"){Q({approved:!1,reason:"用户拒绝"});return}}},{isActive:q});let F=tJ(()=>{if(G)return[{key:"approve-auto",label:"[Y] 批准,自动执行",value:{approved:!0,targetMode:"autoEdit"}},{key:"approve-default",label:"[S] 批准,逐步确认",value:{approved:!0,targetMode:"default"}},{key:"reject",label:"[N] 继续优化方案",value:{approved:!1,reason:"方案需要改进"}}];if(K)return[{key:"approve",label:"[Y] 进入规划模式",value:{approved:!0}},{key:"reject",label:"[N] 直接执行",value:{approved:!1,reason:"用户拒绝进入 Plan 模式"}}];if(U)return[{key:"continue",label:"[Y] 继续执行",value:{approved:!0}},{key:"stop",label:"[N] 停止",value:{approved:!1,reason:"用户选择停止"}}];return[{key:"approve-once",label:"[Y] 允许(仅本次)",value:{approved:!0,scope:"once"}},{key:"approve-session",label:"[S] 允许(记住本项目)",value:{approved:!0,scope:"session"}},{key:"reject",label:"[N] 拒绝",value:{approved:!1,reason:"用户拒绝"}}]},[G,K,U]),O=tJ(()=>{if(G)return{color:"cyan",title:"方案审核"};if(K)return{color:"magenta",title:"进入规划模式"};if(U)return{color:"yellow",title:"已达最大轮次"};return{color:"yellow",title:$.title||"操作确认"}},[G,K,U,$.title]);return w0(Z1,{flexDirection:"column",borderStyle:"round",borderColor:q?O.color:"gray",padding:1,children:[w0(Z1,{marginBottom:1,children:w0(N1,{bold:!0,color:O.color,children:O.title},void 0,!1,void 0,this)},void 0,!1,void 0,this),w0(V3,{details:$,headerColor:O.color,isPlanModeExit:G,isPlanModeEnter:K,terminalWidth:Y},void 0,!1,void 0,this),w0(Z1,{flexDirection:"column",children:[w0(N1,{color:"gray",children:j3(K,U)},void 0,!1,void 0,this),w0(f3,{items:F,isFocused:q,itemComponent:D3,onSelect:(N)=>{Q(N.value)}},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)});import{Box as K0,Text as $0,useInput as h3}from"ink";import eJ from"ink-text-input";import{useState as v1}from"react";import{jsxDEV as j}from"react/jsx-dev-runtime";var g$=[{action:"add",description:"Add a new hook"},{action:"status",description:"Show hooks status"},{action:"list",description:"List all configured hooks"}],H8=[{location:"local",name:"Project settings (local)",description:"Saved in .blade/settings.local.json"},{location:"project",name:"Project settings",description:"Checked in at .blade/settings.json"},{location:"user",name:"User settings",description:"Saved in at ~/.blade/settings.json"}],L8=[{event:"PreToolUse",description:"Before tool execution"},{event:"PostToolUse",description:"After tool execution"},{event:"PostToolUseFailure",description:"After tool execution fails"},{event:"PermissionRequest",description:"When permission is requested"},{event:"UserPromptSubmit",description:"Before processing user prompt"},{event:"Stop",description:"When Claude stops responding"},{event:"SubagentStop",description:"When subagent stops"},{event:"SessionStart",description:"When session starts"},{event:"SessionEnd",description:"When session ends"},{event:"Notification",description:"When notification is sent"},{event:"Compaction",description:"Before context compaction"}],m3=[`jq -r '.tool_input.file_path | select(endswith(".go"))' | xargs -r gofmt -w`,`jq -r '"\\(.tool_input.command) - \\(.tool_input.description // "No description")"' >> ~/.blade/bash-command-log.txt`,"/usr/local/bin/security_check.sh","python3 ~/hooks/validate_changes.py"],$2=({onClose:$,onSave:Q})=>{let J=m0.getTheme(),[Y,Z]=v1("action"),[q,X]=v1(0),[G,K]=v1(0),[U,F]=v1(0),[O,N]=v1(""),[z,_]=v1(""),[W,w]=v1(null),[L,H]=v1(!1),[R,I]=v1(null),v=g$[q],B=L8[G],A=H8[U],b=()=>{if(R){I(null);return}switch(Y){case"action":$();break;case"event":Z("action");break;case"matcher":Z("event");break;case"command":Z("matcher");break;case"location":Z("command");break;case"confirm":Z("location");break}};h3((D,C)=>{if(C.escape){b();return}if(Y==="action"){if(C.upArrow)X((y)=>y>0?y-1:g$.length-1);else if(C.downArrow)X((y)=>y<g$.length-1?y+1:0);else if(C.return)k()}else if(Y==="event"){if(C.upArrow)K((y)=>y>0?y-1:L8.length-1);else if(C.downArrow)K((y)=>y<L8.length-1?y+1:0);else if(C.return)Z("matcher")}else if(Y==="location"){if(C.upArrow)F((y)=>y>0?y-1:H8.length-1);else if(C.downArrow)F((y)=>y<H8.length-1?y+1:0);else if(C.return)Z("confirm")}else if(Y==="confirm"){if(C.return)s()}});let k=()=>{let D=g$[q].action;if(D==="add")Z("event");else if(D==="status")V();else if(D==="list")p()},V=()=>{let D=L1.getInstance(),C=D.isEnabled(),y=D.getConfig(),a={};for(let P of Object.values(yQ)){let r=y[P];if(r&&Array.isArray(r)){let T=r.reduce((h,S)=>h+(S.hooks?.length||0),0);if(T>0)a[P]=T}}let u=[`Status: ${C?"Enabled":"Disabled"}`,""];if(Object.keys(a).length>0){u.push("Configured hooks:");for(let[P,r]of Object.entries(a))u.push(` ${P}: ${r} hook(s)`)}else u.push("No hooks configured");I(u.join(`
|
|
130
130
|
`))},p=()=>{let C=L1.getInstance().getConfig(),y=[],a=!1;for(let u of Object.values(yQ)){let P=C[u];if(!P||!Array.isArray(P)||P.length===0)continue;a=!0,y.push(`${u}:`);for(let r of P){let T=r.matcher,h="all";if(T?.tools)h=`tools: ${Array.isArray(T.tools)?T.tools.join(", "):T.tools}`;y.push(` [${h}]`);for(let S of r.hooks||[])if(S.type==="command")y.push(` -> ${S.command}`)}y.push("")}if(!a)y.push("No hooks configured"),y.push(""),y.push("Configure hooks in .blade/settings.local.json");I(y.join(`
|
|
131
131
|
`))},d=()=>{Z("command")},l=()=>{if(!z.trim()){w("Command cannot be empty");return}w(null),Z("location")},s=async()=>{H(!0),w(null);try{let D=L1.getInstance(),C=await import("node:fs/promises"),y=await import("node:path"),a=await import("node:os"),u={matcher:O.trim()?{tools:O.trim()}:{},hooks:[{type:"command",command:z.trim()}]},P;switch(A.location){case"local":P=y.join(A0(),".blade","settings.local.json");break;case"project":P=y.join(A0(),".blade","settings.json");break;case"user":P=y.join(a.homedir(),".blade","settings.json");break}await C.mkdir(y.dirname(P),{recursive:!0});let r={};try{let i=await C.readFile(P,"utf-8");r=JSON.parse(i)}catch{}let T=r.hooks||{},h=T[B.event]||[],S={...T,enabled:!0,[B.event]:[...h,u]};if(r.hooks=S,await C.writeFile(P,JSON.stringify(r,null,2),"utf-8"),await D.reloadConfig(),Q)Q({event:B.event,matcher:O.trim(),command:z.trim()});$()}catch(D){w(`Failed to save hook: ${D instanceof Error?D.message:"Unknown error"}`),H(!1)}};return j(K0,{flexDirection:"column",padding:1,children:[j(K0,{marginBottom:1,children:j($0,{bold:!0,color:J.colors.success,children:"Hooks Manager"},void 0,!1,void 0,this)},void 0,!1,void 0,this),j(K0,{marginBottom:1,children:j($0,{color:J.colors.warning,children:"[WARN] Hooks execute shell commands with your full user permissions. Only use hooks from trusted sources."},void 0,!1,void 0,this)},void 0,!1,void 0,this),R&&j(K0,{flexDirection:"column",marginBottom:1,children:[j($0,{children:R},void 0,!1,void 0,this),j(K0,{marginTop:1,children:j($0,{color:J.colors.muted,children:"Esc to go back"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Y==="action"&&!R&&j(K0,{flexDirection:"column",children:[j(K0,{flexDirection:"column",marginTop:1,children:g$.map((D,C)=>j(K0,{children:[j($0,{color:C===q?J.colors.primary:void 0,bold:C===q,children:[C===q?"> ":" ",D.action]},void 0,!0,void 0,this),j($0,{color:J.colors.muted,children:[" - ",D.description]},void 0,!0,void 0,this)]},D.action,!0,void 0,this))},void 0,!1,void 0,this),j(K0,{marginTop:1,children:j($0,{color:J.colors.muted,children:"Up/Down to select · Enter to continue · Esc to close"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Y==="event"&&j(K0,{flexDirection:"column",children:[j($0,{bold:!0,children:"Select Event:"},void 0,!1,void 0,this),j(K0,{flexDirection:"column",marginTop:1,children:L8.map((D,C)=>j(K0,{children:[j($0,{color:C===G?J.colors.primary:void 0,bold:C===G,children:[C===G?"> ":" ",D.event]},void 0,!0,void 0,this),j($0,{color:J.colors.muted,children:[" - ",D.description]},void 0,!0,void 0,this)]},D.event,!0,void 0,this))},void 0,!1,void 0,this),j(K0,{marginTop:1,children:j($0,{color:J.colors.muted,children:"Up/Down to select · Enter to continue · Esc to go back"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Y!=="event"&&j(K0,{marginBottom:1,children:j($0,{children:["Event:"," ",j($0,{bold:!0,color:J.colors.primary,children:B.event},void 0,!1,void 0,this),j($0,{color:J.colors.muted,children:[" - ",B.description]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),(Y==="matcher"||Y==="command"||Y==="confirm")&&j(K0,{flexDirection:"column",marginBottom:1,children:[j($0,{color:J.colors.muted,children:"Input to command is JSON of tool call arguments."},void 0,!1,void 0,this),j($0,{color:J.colors.muted,children:"Exit code 0 - stdout/stderr not shown"},void 0,!1,void 0,this),j($0,{color:J.colors.muted,children:"Exit code 2 - show stderr to model and block tool call"},void 0,!1,void 0,this),j($0,{color:J.colors.muted,children:"Other exit codes - show stderr to user only but continue with tool call"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Y==="matcher"&&j(K0,{flexDirection:"column",children:[j(K0,{children:[j($0,{bold:!0,children:"Matcher: "},void 0,!1,void 0,this),j(eJ,{value:O,onChange:N,onSubmit:d,placeholder:"e.g., Read, Bash, Edit|Write (empty = all tools)"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),j(K0,{marginTop:1,children:j($0,{color:J.colors.muted,children:"Tool name pattern (supports | for multiple). Leave empty to match all."},void 0,!1,void 0,this)},void 0,!1,void 0,this),j(K0,{marginTop:1,children:j($0,{color:J.colors.muted,children:"Enter to continue · Esc to go back"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),(Y==="command"||Y==="confirm")&&j(K0,{marginBottom:1,children:j($0,{children:["Matcher: ",j($0,{bold:!0,children:O||"(all tools)"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),Y==="command"&&j(K0,{flexDirection:"column",children:[j(K0,{children:j($0,{bold:!0,children:"Command: "},void 0,!1,void 0,this)},void 0,!1,void 0,this),j(K0,{borderStyle:"single",borderColor:J.colors.border.light,paddingX:1,marginTop:1,children:j(eJ,{value:z,onChange:_,onSubmit:l,placeholder:"Enter shell command..."},void 0,!1,void 0,this)},void 0,!1,void 0,this),j(K0,{flexDirection:"column",marginTop:1,children:[j($0,{bold:!0,children:"Examples:"},void 0,!1,void 0,this),m3.map((D,C)=>j($0,{color:J.colors.muted,children:["• ",D]},C,!0,void 0,this))]},void 0,!0,void 0,this),j(K0,{marginTop:1,children:j($0,{color:J.colors.muted,children:"Enter to continue · Esc to go back"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Y==="location"&&j(K0,{flexDirection:"column",children:[j(K0,{flexDirection:"column",borderStyle:"round",borderColor:J.colors.border.light,paddingX:2,paddingY:1,marginBottom:1,children:[j($0,{bold:!0,color:J.colors.primary,children:"Save hook configuration"},void 0,!1,void 0,this),j($0,{children:" "},void 0,!1,void 0,this),j($0,{children:[" ","Event: ",B.event," - ",B.description]},void 0,!0,void 0,this),j($0,{children:[" Matcher: ",O||"(all)"]},void 0,!0,void 0,this),j($0,{children:[" Command: ",z]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),j($0,{bold:!0,children:"Where should this hook be saved?"},void 0,!1,void 0,this),j(K0,{flexDirection:"column",marginTop:1,children:H8.map((D,C)=>j(K0,{children:[j($0,{color:C===U?J.colors.primary:void 0,bold:C===U,children:[C===U?"> ":" ",C+1,". ",D.name]},void 0,!0,void 0,this),j($0,{color:J.colors.muted,children:[" ",D.description]},void 0,!0,void 0,this)]},D.location,!0,void 0,this))},void 0,!1,void 0,this),j(K0,{marginTop:1,children:j($0,{color:J.colors.muted,children:"Enter to confirm · Esc to go back"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Y==="confirm"&&j(K0,{flexDirection:"column",children:[j(K0,{flexDirection:"column",borderStyle:"round",borderColor:J.colors.success,paddingX:2,paddingY:1,children:[j($0,{bold:!0,children:["Saving hook to ",A.description,"..."]},void 0,!0,void 0,this),j($0,{children:" "},void 0,!1,void 0,this),j($0,{children:["Event: ",B.event]},void 0,!0,void 0,this),j($0,{children:["Matcher: ",O||"(all tools)"]},void 0,!0,void 0,this),j($0,{children:["Command: ",z]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),j(K0,{marginTop:1,children:j($0,{color:J.colors.muted,children:L?"Saving...":"Enter to confirm · Esc to go back"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),W&&j(K0,{marginTop:1,children:j($0,{color:J.colors.error,children:W},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};import{useMemoizedFn as O2}from"ahooks";import{Box as i3,Text as n3}from"ink";import t3 from"react";import{useMemoizedFn as x3}from"ahooks";import Y$ from"chalk";import{Text as d3,useInput as l3}from"ink";import{useEffect as MQ,useRef as CQ}from"react";var R1={TIMEOUT_MS:100,RAPID_INPUT_THRESHOLD_MS:150,LARGE_INPUT_THRESHOLD:300,MEDIUM_SIZE_MULTI_CHUNK_THRESHOLD:200};import{execSync as R$}from"node:child_process";import{existsSync as g3,readFileSync as PQ}from"node:fs";import{basename as Q2,isAbsolute as p3}from"node:path";function J2($){try{let Q=Buffer.from($,"base64");if(Q.length<4)return"image/png";if(Q[0]===137&&Q[1]===80&&Q[2]===78&&Q[3]===71)return"image/png";if(Q[0]===255&&Q[1]===216&&Q[2]===255)return"image/jpeg";if(Q[0]===71&&Q[1]===73&&Q[2]===70)return"image/gif";if(Q[0]===82&&Q[1]===73&&Q[2]===70&&Q[3]===70){if(Q.length>=12&&Q[8]===87&&Q[9]===69&&Q[10]===66&&Q[11]===80)return"image/webp"}return"image/png"}catch{return"image/png"}}function Y2(){let $=process.platform,Q={darwin:"/tmp/blade_cli_latest_screenshot.png",linux:"/tmp/blade_cli_latest_screenshot.png",win32:process.env.TEMP?`${process.env.TEMP}\\blade_cli_latest_screenshot.png`:"C:\\Temp\\blade_cli_latest_screenshot.png"},J={darwin:{checkImage:"osascript -e 'the clipboard as «class PNGf»'",saveImage:(Y)=>`osascript -e 'set png_data to (the clipboard as «class PNGf»)' -e 'set fp to open for access POSIX file "${Y}" with write permission' -e 'write png_data to fp' -e 'close access fp'`,getPath:"osascript -e 'get POSIX path of (the clipboard as «class furl»)'",deleteFile:(Y)=>`rm -f "${Y}"`},linux:{checkImage:'xclip -selection clipboard -t TARGETS -o | grep -E "image/(png|jpeg|jpg|gif|webp)"',saveImage:(Y)=>`xclip -selection clipboard -t image/png -o > "${Y}" || wl-paste --type image/png > "${Y}"`,getPath:"xclip -selection clipboard -t text/plain -o",deleteFile:(Y)=>`rm -f "${Y}"`},win32:{checkImage:'powershell -Command "(Get-Clipboard -Format Image) -ne $null"',saveImage:(Y)=>`powershell -Command "$img = Get-Clipboard -Format Image; if ($img) { $img.Save('${Y.replace(/\\/g,"\\\\")}', [System.Drawing.Imaging.ImageFormat]::Png) }"`,getPath:'powershell -Command "Get-Clipboard"',deleteFile:(Y)=>`del /f "${Y}"`}};return{commands:J[$]||J.linux,screenshotPath:Q[$]||Q.linux}}function c3(){let{commands:$}=Y2();try{return R$($.getPath,{encoding:"utf-8"}).trim()}catch(Q){return console.error("Failed to get clipboard path:",Q),null}}function Z2($){if($.startsWith('"')&&$.endsWith('"')||$.startsWith("'")&&$.endsWith("'"))return $.slice(1,-1);return $}function X2($){if(process.platform==="win32")return $;let Q="__DOUBLE_BACKSLASH__";return $.replace(/\\\\/g,Q).replace(/\\(.)/g,"$1").replace(new RegExp(Q,"g"),"\\")}function IQ($){let Q=Z2($.trim()),J=X2(Q);return/\.(png|jpe?g|gif|webp)$/i.test(J)}function u3($){let Q=Z2($.trim()),J=X2(Q);if(IQ(J))return J;return null}async function q2($){let Q=u3($);if(!Q)return null;let J;try{if(p3(Q))J=PQ(Q);else{let X=c3();if(X&&Q===Q2(X))J=PQ(X);else return null}}catch(X){return console.error("Failed to read image file:",X),null}let Y=J.toString("base64"),Z=J2(Y),q=Q2(Q);return{path:Q,base64:Y,mediaType:Z,filename:q}}async function G2(){let $=process.platform,Q={darwin:"pbpaste",linux:"xclip -selection clipboard -o || wl-paste",win32:'powershell -Command "Get-Clipboard"'},J=Q[$]||Q.linux;try{return R$(J,{encoding:"utf-8"})||null}catch{return null}}async function U2(){let{commands:$,screenshotPath:Q}=Y2();try{if(R$($.checkImage,{stdio:"ignore"}),R$($.saveImage(Q),{stdio:"ignore"}),!g3(Q))return null;let Y=PQ(Q).toString("base64"),Z=J2(Y);return R$($.deleteFile(Q),{stdio:"ignore"}),{base64:Y,mediaType:Z}}catch(J){try{R$($.deleteFile(Q),{stdio:"ignore"})}catch{}return null}}import{jsxDEV as o3}from"react/jsx-dev-runtime";var r3=/\r\n/g,a3=/\r/g;function Z$($){if(!$.includes("\r"))return $;return $.replace(r3,`
|
|
132
132
|
`).replace(a3,`
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as Q,b as R,c as T,d as W}from"./chunk-
|
|
1
|
+
import{a as Q,b as R,c as T,d as W}from"./chunk-j6z6fn0y.js";import"./chunk-q5yn875m.js";import"./chunk-7199c8y4.js";import"./chunk-188szde1.js";import"./chunk-mxrre2n3.js";import{ba as M}from"./chunk-2mg2f5ye.js";import"./chunk-68ctb04g.js";import{Aa as J}from"./chunk-x9zj0r7s.js";import"./chunk-mz6n4w13.js";import"./chunk-158qedny.js";import"./chunk-yddnm9n2.js";import"./chunk-yk91w5p2.js";import"./chunk-37rethcy.js";import"./chunk-7ycmx7c2.js";import"./chunk-set7v1rf.js";import"./chunk-j2ag7hh6.js";import b from"chalk";import H from"open";var $=`
|
|
2
2
|
____ _ _
|
|
3
3
|
| __ )| | __ _ __| | ___
|
|
4
4
|
| _ \\| |/ _\` |/ _\` |/ _ \\
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as a,u as b}from"./chunk-e41c8gcw.js";import"./chunk-2mg2f5ye.js";import"./chunk-j2ag7hh6.js";export{a as globalOptions,b as cliConfig};
|