blade-code 0.10.22 → 0.10.23
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-2rbct4ks.js → chunk-0affe05f.js} +1 -1
- package/dist/{chunk-bh42pn4d.js → chunk-2j3d4ykq.js} +1 -1
- package/dist/{chunk-tnt2hhcg.js → chunk-2vs6ff2m.js} +1 -1
- package/dist/{chunk-s7g6jt82.js → chunk-3d2f82yb.js} +2 -2
- package/dist/{chunk-a3yg9fd5.js → chunk-46nbyp0r.js} +469 -379
- package/dist/{chunk-5bgyskdm.js → chunk-48w87cah.js} +1 -1
- package/dist/{chunk-kntre6sz.js → chunk-6bywhrm9.js} +1 -1
- package/dist/{chunk-04gq93dx.js → chunk-6g2tsx64.js} +1 -1
- package/dist/{chunk-244cdt25.js → chunk-70jrd752.js} +1 -1
- package/dist/chunk-73shq329.js +1 -0
- package/dist/{chunk-m96f2aq9.js → chunk-8efpk2z9.js} +1 -1
- package/dist/{chunk-y5xyh4br.js → chunk-afk22y4r.js} +1 -1
- package/dist/{chunk-n63thdsq.js → chunk-ak7v70sy.js} +1 -1
- package/dist/{chunk-hfveg7c1.js → chunk-b183w6w0.js} +1 -1
- package/dist/{chunk-5ztdsaex.js → chunk-c7va41dk.js} +1 -1
- package/dist/{chunk-se1ef1r7.js → chunk-cjyrr1c0.js} +1 -1
- package/dist/{chunk-3bk8jveq.js → chunk-cwyktf92.js} +1 -1
- package/dist/{chunk-34cqp0rx.js → chunk-ddj5f5cz.js} +1 -1
- package/dist/{chunk-d3kqhv5k.js → chunk-hpgee5s3.js} +1 -1
- package/dist/{chunk-06pbdpcg.js → chunk-hvp9kt76.js} +1 -1
- package/dist/{chunk-mrx6qkax.js → chunk-k7p4qwdr.js} +1 -1
- package/dist/{chunk-nwy1rpwf.js → chunk-kaa0np37.js} +1 -1
- package/dist/{chunk-18f9g8ja.js → chunk-n7hnp8yj.js} +1 -1
- package/dist/{chunk-avtsweaa.js → chunk-nbwvc4v4.js} +1 -1
- package/dist/{chunk-qw900zg9.js → chunk-nfm5j63c.js} +1 -1
- package/dist/{chunk-haqfbgv4.js → chunk-nv59nazz.js} +1 -1
- package/dist/{chunk-ef8rr9eh.js → chunk-q8f1k8ns.js} +1 -1
- package/dist/{chunk-9nc6sfj4.js → chunk-qjzt9pna.js} +1 -1
- package/dist/{chunk-7nygnmnm.js → chunk-rbwntemj.js} +1 -1
- package/dist/{chunk-gwvds95j.js → chunk-tffagd03.js} +1 -1
- package/dist/{chunk-pefrn6n0.js → chunk-tw0eh910.js} +1 -1
- package/dist/{chunk-g1zrs8tj.js → chunk-x0g7y97q.js} +1 -1
- package/dist/{chunk-r40fthzd.js → chunk-yann89nx.js} +1 -1
- package/package.json +1 -1
- package/dist/chunk-vxhf2q0r.js +0 -1
package/dist/blade.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{Gc as W}from"./chunk-
|
|
2
|
+
import{Gc as W}from"./chunk-8efpk2z9.js";import{Jc as F,Kc as M}from"./chunk-9m80tr4t.js";import"./chunk-q8f1k8ns.js";import"./chunk-wax3nm7t.js";import"./chunk-xjqcc0nt.js";import"./chunk-hpgee5s3.js";import"./chunk-sr2stcda.js";import{me as T}from"./chunk-djh79rde.js";import"./chunk-nfm5j63c.js";import"./chunk-gcsygn5a.js";import"./chunk-9ka0bdry.js";import"./chunk-vc2c8wkx.js";import{qf as N,rf as B}from"./chunk-kvd5nexw.js";import"./chunk-8472vz3s.js";import"./chunk-f9tahtz6.js";import"./chunk-tffagd03.js";import"./chunk-698qsvyb.js";import"./chunk-h0q03x9f.js";import"./chunk-czjbz0fp.js";import{Vf as J}from"./chunk-c7zk9zj2.js";import v from"node:path";var E=process.argv.slice(2),I=u(E),p=I!==null;if(I!==null)T.setGlobalDebug(I);function u(Q){for(let Y=0;Y<Q.length;Y+=1){let U=Q[Y];if(U==="--debug"||U==="-d"){let X=Q[Y+1];return X&&!X.startsWith("-")?X:!0}if(U.startsWith("--debug="))return U.slice(8)||!0}return null}function c(Q){return Q.length===1&&(Q[0]==="--version"||Q[0]==="-V")}function q(Q,...Y){return Q.some((U)=>Y.some((X)=>U===X||U.startsWith(`${X}=`)))}function m(Q,...Y){let U=[];for(let X=0;X<Q.length;X+=1){let G=Q[X],z=Y.find(($)=>G.startsWith(`${$}=`));if(z){let $=G.slice(z.length+1);if($)U.push($);continue}if(Y.includes(G)){let $=Q[X+1];if($&&!$.startsWith("-"))U.push($),X+=1}}return U}async function t(){if(c(E)){let{getVersion:K}=await import("./chunk-ddj5f5cz.js");console.log(K());return}let Q=process.cwd(),Y=F(Q);M(Y),N(B());let U=m(E,"--plugin-dir","--pluginDir");if(U.length>0){let{configureInvocationPluginDirs:K}=await import("./chunk-2vs6ff2m.js");K(U.map((Z)=>v.resolve(Q,Z)))}if(q(E,"--trust-workspace","--trustWorkspace")){let{WorkspaceTrustService:K}=await import("./chunk-s1310gqw.js");await K.getInstance().trust(B())}if(process.getuid&&process.getuid()===0){let K=!!process.env.SUDO_USER,Z=!!process.env.BLADE_ALLOW_ROOT;if(K&&!Z)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(q(E,"--headless")){let{handleHeadlessMode:K}=await import("./chunk-cjyrr1c0.js");if(await K())return}if(W(),q(E,"--print","-p")){let{handlePrintMode:K}=await import("./chunk-48w87cah.js");if(await K())return}if(E.includes("--acp")){let{runAcpIntegration:K}=await import("./chunk-6bywhrm9.js");await K();return}let[{default:X},{hideBin:G},{cliConfig:z,globalOptions:$},{loadConfiguration:_,validateOutput:D,validatePermissions:R},{doctorCommands:S},{installCommands:k},{mcpCommands:O},{projectsCommands:y},{scheduleCommands:b},{serveCommand:V},{updateCommands:P},{webCommand:x}]=await Promise.all([import("yargs"),import("yargs/helpers"),import("./chunk-73shq329.js"),import("./chunk-qjzt9pna.js"),import("./chunk-3d2f82yb.js"),import("./chunk-vannpbp0.js"),import("./chunk-hvp9kt76.js"),import("./chunk-33wheqb0.js"),import("./chunk-yqk501wp.js"),import("./chunk-cwyktf92.js"),import("./chunk-afv2grka.js"),import("./chunk-afk22y4r.js")]),A=X(G(process.argv)).scriptName(z.scriptName).usage(z.usage).version(z.version).locale(z.locale).showHelpOnFail(z.showHelpOnFail).demandCommand(0,"").recommendCommands().strict(z.strict).parserConfiguration({"populate--":!0}).options($).middleware([_,R,D]).command(O).command(y).command(b).command(S).command(P).command(k).command(x).command(V).completion("completion",!1).help("help","Show help").alias("help","h").alias("version","V").fail((K,Z,L)=>{if(Z){if(console.error("An error occurred:"),console.error(Z.message),p&&Z.stack)console.error(`
|
|
3
3
|
Stack trace:`),console.error(Z.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:`),L.showHelp(),process.exit(1)}).command("$0",!1,()=>{},async(K)=>{let Z=K._.slice(1),L=Z.length>0?Z.join(" "):void 0,h=import("./chunk-p29w4zfc.js").then(({checkVersionOnStartup:C})=>C()),[{render:w},{createElement:f},{AppWrapper:j}]=await Promise.all([import("ink"),import("react"),import("./chunk-
|
|
5
|
+
Hint: Did you mean:`),L.showHelp(),process.exit(1)}).command("$0",!1,()=>{},async(K)=>{let Z=K._.slice(1),L=Z.length>0?Z.join(" "):void 0,h=import("./chunk-p29w4zfc.js").then(({checkVersionOnStartup:C})=>C()),[{render:w},{createElement:f},{AppWrapper:j}]=await Promise.all([import("ink"),import("react"),import("./chunk-nv59nazz.js")]),H={...K,initialMessage:L,debug:K.debug,print:Boolean(K.print),versionCheckPromise:h};delete H._,delete H.$0,delete H.message,w(f(j,H),{patchConsole:!0,exitOnCtrlC:!1,alternateBuffer:!1})});try{await A.parse()}catch(K){console.error("Error: Parse error:",K),process.exit(1)}}if(J.main==J.module)t().catch(console.error);export{t as main};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{xb as I5}from"./chunk-4dnvydyv.js";import{$b as W1,Eb as Z5,Fb as J5,Gb as c$,Hb as u$,Ob as d1,Xb as L2,Zb as J1,_b as i0,fc as P0,yb as d2}from"./chunk-n63thdsq.js";import{gc as V2,jc as o1,kc as q2}from"./chunk-vypake1a.js";import{ld as v5}from"./chunk-xjqcc0nt.js";import{md as R5,nd as f2,od as S5,pd as h5,qd as Z1,sd as m1}from"./chunk-rxfmqnf7.js";import{Wd as v2,Xd as b2,_d as C5}from"./chunk-5xph8r1k.js";import{he as t2}from"./chunk-d3kqhv5k.js";import{ne as w2}from"./chunk-djh79rde.js";import{cf as M5}from"./chunk-gcsygn5a.js";import{rf as i}from"./chunk-kvd5nexw.js";import{Ef as $5}from"./chunk-gwvds95j.js";import{Mf as Z0,Of as M1,Pf as X2,Qf as l0,Sf as t1,Uf as e1}from"./chunk-czjbz0fp.js";import{Vf as K7}from"./chunk-c7zk9zj2.js";function a2($){return $.role==="system"&&Array.isArray($.content)}function o2($){if($.role!=="system"||!$.metadata||Array.isArray($.metadata))return!1;return typeof $.metadata==="object"&&$.metadata.contextualProjectRules===!0}class R0{systemMessages;_contextualSystemMessages;_history;_pending=[];context;constructor($,Z){this.context=$;let J=$.messages.find(a2);if(this._contextualSystemMessages=$.messages.filter(o2),J)this.systemMessages=[J,...this._contextualSystemMessages];else if(Z)this.systemMessages=[{role:"system",content:[{type:"text",text:Z,providerOptions:{anthropic:{cacheControl:{type:"ephemeral"}}}}]},...this._contextualSystemMessages];else this.systemMessages=[...this._contextualSystemMessages];this._history=$.messages.filter((W)=>!a2(W)&&!o2(W))}get historyLength(){return this._history.length}get history(){return this._history}get pending(){return this._pending}toLLMMessages(){return[...this.systemMessages,...this._history,...this._pending]}getMessagesForLLM(){return this.toLLMMessages()}getHistory(){return this._history}appendPending($){this._pending.push($)}appendUser($){this._pending.push($)}appendAssistant($){this._pending.push($)}appendToolResult($){this._pending.push($)}appendContextualProjectInstructions($){if(!o2($))throw Error("Contextual project instructions require safe metadata");this._contextualSystemMessages.push($),this.systemMessages.push($)}syncContextualSystemMessages(){let $=this.systemMessages.filter(a2);this.systemMessages.splice(0,this.systemMessages.length,...$,...this._contextualSystemMessages)}appendControl($,Z){if($==="system")throw Error("Cannot append system control message via appendControl. Use constructor for root system prompt.");this._pending.push(Z)}appendToHistory($){this._history.push($)}commitPending(){if(this._pending.length>0)this._history.push(...this._pending),this._pending=[]}replaceHistory($){this._history=$.filter((Z)=>!a2(Z)&&!o2(Z))}restoreDurableHistory($){this._contextualSystemMessages=$.filter(o2),this._history=$.filter((Z)=>!a2(Z)&&!o2(Z)),this._pending=[],this.syncContextualSystemMessages()}removeMessages($){this._history=this._history.filter((Z)=>!$(Z)),this._pending=this._pending.filter((Z)=>!$(Z)),this._contextualSystemMessages=this._contextualSystemMessages.filter((Z)=>!$(Z)),this.syncContextualSystemMessages()}writeback(){this.commitPending(),this.context.messages=[...this._contextualSystemMessages,...this._history]}get hasSystemPrompt(){return this.systemMessages.length>0}}function G1($){if($.isSubagent)return"continue";if(!$.budget||$.budget<=0)return"continue";if($.consecutiveContinuations>=3&&$.lastOutputDelta<500)return"stop";if($.usage/$.budget>=0.9)return"stop";return"continue"}function L1($){return{budget:$.budget,usage:0,consecutiveContinuations:0,lastOutputDelta:0,isSubagent:$.isSubagent??!1}}function F1($,Z,J){return{...$,usage:$.usage+Z,lastOutputDelta:Z,consecutiveContinuations:J?$.consecutiveContinuations+1:0}}import m2 from"node:path";var o5=new Set(["GOEXPERIMENT","GOOS","GOARCH","CGO_ENABLED","GO111MODULE","RUST_BACKTRACE","RUST_LOG","NODE_ENV","PYTHONUNBUFFERED","PYTHONDONTWRITEBYTECODE","GIT_TERMINAL_PROMPT","LANG","LANGUAGE","LC_ALL","LC_CTYPE","LC_TIME","CHARSET","TERM","COLORTERM","NO_COLOR","FORCE_COLOR","TZ","LS_COLORS","LSCOLORS","GREP_COLOR","GREP_COLORS"]),a5=/^(LD_.+|DYLD_.+|PATH)$/,U1=/^([A-Za-z_][A-Za-z0-9_]*)=([\w./:@-]*)$/;function U0($){let Z=$;while(!0){let J=Z.match(/^(\S+)[ \t]+([\s\S]*)$/);if(!J)break;let W=J[1],K=J[2],Y=W.match(U1);if(!Y)break;let X=Y[1];if(!o5.has(X))break;Z=K}return Z}function q8($){let Z=$;while(!0){let J=Z.match(/^(\S+)[ \t]+([\s\S]*)$/);if(!J)break;let W=J[1],K=J[2],Y=W.match(U1);if(!Y)break;let X=Y[1];if(a5.test(X))break;Z=K}return Z}var s5=[/^timeout[ \t]+(?:--foreground[ \t]+|--preserve-status[ \t]+|-v[ \t]+|--verbose[ \t]+|-k[ \t]+\S+[ \t]+|--kill-after[= ]\S+[ \t]+|-s[ \t]+\S+[ \t]+|--signal[= ]\S+[ \t]+)*\S+[ \t]+/,/^time[ \t]+/,/^nice[ \t]+(?:-n[ \t]+\d+[ \t]+|-\d+[ \t]+)?/,/^nohup[ \t]+/];function A$($){let Z=$,J=!0;while(J){J=!1;for(let W of s5){let K=Z.match(W);if(K){Z=Z.slice(K[0].length),J=!0;break}}if(Z.startsWith("-- "))Z=Z.slice(3),J=!0}return Z}function h0($){let Z=[],J="",W=!1,K=!1,Y=!1;for(let X=0;X<$.length;X++){let z=$[X];if(Y){J+=z,Y=!1;continue}if(z==="\\"&&!W){J+=z,Y=!0;continue}if(z==="'"&&!K){W=!W,J+=z;continue}if(z==='"'&&!W){K=!K,J+=z;continue}if(W||K){J+=z;continue}if(z==="|"){if(X+1<$.length&&$[X+1]==="|"){if(J.trim())Z.push(J.trim());J="",X++;continue}return null}if(z===">"||z==="<")return null;if(z==="&"&&X+1<$.length&&$[X+1]==="&"){if(J.trim())Z.push(J.trim());J="",X++;continue}if(z==="&")return null;if(z===";"){if(J.trim())Z.push(J.trim());J="";continue}J+=z}if(J.trim())Z.push(J.trim());return Z.length>0?Z:null}function O1($){let Z=!1,J=!1,W=!1;for(let K=0;K<$.length;K++){let Y=$[K];if(W){W=!1;continue}if(Y==="\\"&&!Z){W=!0;continue}if(Y==="'"&&!J){Z=!Z;continue}if(Y==='"'&&!Z){J=!J;continue}if(Z)continue;if(Y==="$"){let X=$[K+1];if(X&&/[A-Za-z_@*#?!$0-9({]/.test(X))return!0}if(Y==="`")return!0;if(J)continue;if(Y==="|")return!0;if(Y===">"||Y==="<")return!0;if(Y==="{"){let X=$.slice(K);if(/^\{[^}]*,[^}]*\}/.test(X)||/^\{[^}]*\.\.[^}]*\}/.test(X))return!0}}return!1}function O0($){let Z=[],J="",W=!1,K=!1,Y=!1;for(let X=0;X<$.length;X++){let z=$[X];if(Y){J+=z,Y=!1;continue}if(z==="\\"&&!W){if(Y=!0,K){let Q=$[X+1];if(Q&&'$`"\\'.includes(Q))continue;J+=z,Y=!1}continue}if(z==="'"&&!K){W=!W;continue}if(z==='"'&&!W){K=!K;continue}if(!W&&!K&&/[ \t]/.test(z)){if(J)Z.push(J),J="";continue}J+=z}if(J)Z.push(J);return Z}var t5=new Set(["npm","pnpm","yarn","bun"]),y1=new Set(["biome","eslint","jest","mypy","pyright","pytest","ruff","tsc","vitest"]),e5=new Set(["-u","--fix","--update","--update-snapshot","--updateSnapshot","--watch","--watchAll","--write"]);function $6($){return $!==void 0&&/^(?:test|lint|build|type-?check)(?::[\w.-]+)*$/i.test($)}function Z6($){return $.replace(/\s+2>&1\s*$/,"").trim()}function J6($,Z,J){if(!J||Z.length!==2)return;let W=/^(.+?)[ \t]+&&[ \t]+([\s\S]+)$/.exec($);if(!W)return;let K=O0(W[1]??"");if(K.length!==2||K[0]!=="cd")return;let Y=K[1];if(!Y||Y==="-")return;let X=m2.isAbsolute(Y)?m2.resolve(Y):m2.resolve(J,Y);if(!d2.isWithinWorkspace(X,J))return;return W[2]?.trim()||void 0}function s2($,Z){let J=U0(Z6($)),W=h0(J);if(!W||O1(J)||/[\r\n]/.test(J))return!1;let K=W.length===1?W[0]:J6(J,W,Z);if(!K)return!1;let Y=O0(K);if(Y.length===0||Y.some((H)=>[...e5].some((V)=>H===V||H.startsWith(`${V}=`))))return!1;let[X,z,Q]=Y;if(t5.has(X??""))return $6(z==="run"?Q:z)||z==="--test";if((X==="npx"||X==="bunx")&&y1.has(z??""))return!0;if(y1.has(X??""))return!0;if(X==="node"&&z==="--test")return!0;if(X==="go"&&["build","test","vet"].includes(z??""))return!0;return X==="cargo"&&["build","check","clippy","test"].includes(z??"")}function O8($,Z){if($===void 0)return!0;if(typeof $!=="string"||$.split(/[\\/]/).includes(".."))return!1;if(!Z)return!m2.isAbsolute($);let J=m2.isAbsolute($)?m2.resolve($):m2.resolve(Z,$);return d2.isWithinWorkspace(J,Z)}var x$=w2("Agent"),W6=3;function k$($,Z,J){if($!=="length")return{action:"none"};if(Z>=W6)return{action:"truncated"};if(G1(J)==="stop")return x$.info("[Loop] Token budget: diminishing returns detected, skipping recovery"),{action:"budget_stop"};return{action:"recover"}}var K6=[/:\s*$/,/:\s*$/,/\.\.\.\s*$/,/让我(先|来|开始|查看|检查|修复)/,/Let me (first|start|check|look|fix)/i,/I('ll| will) (now |)(create|write|edit|update|modify|fix|add|implement)/i,/我(现在就|来|要)(创建|写入|编辑|修改|修复|添加|实现)/,/\d+\.\s+(First|Next|Then|Finally)/i],Y6=/```[\s\S]{50,}```/,P1="请执行你提到的操作,不要只是描述。使用 Edit/Write/ApplyPatch/Bash 工具来实际修改文件。",X6=2;function T$($,Z,J=!0){if(!$||Z>=X6)return{action:"none"};if(!J&&Y6.test($))return{action:"retry",prompt:P1};let W=$.slice(-200),K=W.match(/```/g);if(K&&K.length%2!==0)return{action:"none"};if(K6.some((X)=>X.test(W)))return{action:"retry",prompt:P1};return{action:"none"}}var z6=[/\b(?:run|execute|rerun|re-run)\b[\s\S]{0,60}\b(?:tests?|test suite|lint|type-?check|build)\b/i,/\b(?:npm|pnpm|yarn|bun)\s+(?:run\s+)?(?:test|lint|build|type-?check)\b/i,/(?:运行|执行|跑|重新运行).{0,30}(?:测试|单测|集成测试|检查|构建)/],E1={test:/\b(?:tests?|test suite)\b|(?:测试|单测|集成测试)/i,lint:/\blint(?:ing)?\b/i,"type-check":/\btype[\s-]?check(?:ing)?\b|\btsc\b|类型检查/i,build:/\bbuild\b|构建/i},Q6={test:/(?:^|\s)(?:npm|pnpm|yarn|bun)\s+(?:run\s+)?test\b|(?:^|\s)(?:node|bun)\s+--test\b|(?:^|\s)(?:vitest|jest|pytest|go\s+test|cargo\s+test)\b/i,lint:/(?:^|\s)(?:npm|pnpm|yarn|bun)\s+(?:run\s+)?lint\b/i,"type-check":/(?:^|\s)(?:npm|pnpm|yarn|bun)\s+(?:run\s+)?type-?check\b|(?:^|\s)tsc\b/i,build:/(?:^|\s)(?:npm|pnpm|yarn|bun)\s+(?:run\s+)?build\b/i},H6="The user explicitly required verification, but it has not run successfully. Do not finish or explain. Your next action must be a Bash tool call that runs the requested test, lint, type-check, or build command. Inspect the command result and fix any failure before finishing.",B6="Required verification did not run successfully before the retry limit.",V6=3;function N1($,Z,J,W){if(!J.success)return;if(["Edit","Write","ApplyPatch","NotebookEdit"].includes(Z)){$.clear();return}if(Z==="Bash"&&typeof J.metadata?.command==="string"&&J.metadata.exit_code===0&&s2(J.metadata.command,W)){$.add(J.metadata.command);return}if(!["Task","TaskOutput"].includes(Z))return;let K=J.metadata?.verificationCommands;if(!Array.isArray(K))return;for(let Y of K)if(typeof Y==="string"&&s2(Y,W))$.add(Y)}function f$($,Z,J){if(!$||!z6.some((Q)=>Q.test($)))return{action:"none"};let W=Object.keys(E1).filter((Q)=>E1[Q].test($)),K=[...Z],Y=W.filter((Q)=>!K.some((H)=>Q6[Q].test(H)));if(W.length>0?Y.length===0:K.some((Q)=>s2(Q)))return{action:"none"};if(J>=V6)return{action:"fail",message:B6};let z=W.length>1&&Y.length>0?` Missing successful verification categories: ${Y.join(", ")}.`:"";return{action:"retry",prompt:`${H6}${z}`}}var D6=[/\bdelegate\b[\s\S]{0,120}\b(?:Task tool|subagent|agent)\b/i,/\b(?:call|use|invoke)\b[\s\S]{0,80}\bTask tool\b/i,/(?:委派|交给|调用|使用).{0,60}(?:Task|子代理|子智能体)/],_1=[/\b(?:do not|don't|never)\s+(?:delegate|call|use|invoke)\b/i,/(?:不要|禁止|无需)(?:委派|调用|使用).{0,20}(?:Task|子代理|子智能体)?/];function S1($){return typeof $==="string"&&_1.some((Z)=>Z.test($))}var j6=[/\b(?:call|use|invoke)\b[\s\S]{0,30}\bTask(?: tool)?\b[\s\S]{0,30}\bexactly once\b/i,/\bexactly once\b[\s\S]{0,30}\b(?:call|use|invoke)\b[\s\S]{0,30}\bTask(?: tool)?\b/i,/\bexactly one\b[\s\S]{0,30}\bTask(?: tool)? calls?\b/i,/(?:Task|子代理).{0,20}(?:恰好|仅|只)(?:调用|使用)?一次/,/(?:恰好|仅|只)(?:调用|使用)?一次.{0,20}(?:Task|子代理)/],w6=[/\b(?:do not|don't|never)\s+(?:call|use|invoke)\s+(?:the\s+)?Task\b[\s\S]{0,30}\bexactly once\b/i,/\bTask\b[\s\S]{0,30}\b(?:does not|doesn't|need not)\b[\s\S]{0,30}\bexactly once\b/i,/\bmultiple\s+Task(?: tool)?\s+calls?\s+(?:are\s+)?allowed\b/i,/(?:不要|禁止).{0,12}(?:Task|子代理).{0,12}(?:恰好|仅|只)(?:调用|使用)?一次/];function q6($){if(typeof $!=="string")return;if(w6.some((Z)=>Z.test($)))return"multiple-allowed";return j6.some((Z)=>Z.test($))?"required":void 0}function I0($){for(let Z of $){let J=q6(Z);if(J!==void 0)return J==="required"}return!1}var G6="The user explicitly required delegation, but no Task tool call completed successfully. Do not solve the task directly or explain. Your next action must be a Task tool call using the requested subagent.",L6="Required delegation did not complete before the retry limit.",F6=3;function A1($,Z,J){let W=(typeof $==="string"?[$]:$??[]).map((X)=>X.trim()).filter(Boolean),K=I0(W),Y=!1;if(!K)for(let X of W){if(_1.some((z)=>z.test(X)))break;if(D6.some((z)=>z.test(X))){Y=!0;break}}if(W.length===0||!K&&!Y||Z.has("Task"))return{action:"none"};if(J>=F6)return{action:"fail",message:L6};return{action:"retry",prompt:G6}}var U6=[/\b(?:use|create|enter|start|work\s+(?:in|inside))\b.{0,60}\bworktree\b/i,/(?:使用|创建|进入).{0,30}(?:worktree|工作树)/i],O6=[/\b(?:exit|leave)\b.{0,40}\bworktree\b/i,/\bworktree\b.{0,60}\b(?:action\s+)?(?:keep|remove)\b/i,/(?:退出|离开).{0,30}(?:worktree|工作树)/i],y6=[/\b(?:do not|don't|never|must not|should not)\b[^.!?;\n]{0,80}\b(?:git\s+)?worktree\b/gi,/\bwithout\b[^.!?;\n]{0,60}\b(?:git\s+)?worktree\b/gi,/(?:不要|禁止|不得|无需)[^。!?;\n]{0,50}(?:worktree|工作树)/gi];function x1($){return y6.reduce((Z,J)=>Z.replace(J," "),$)}function p0($){if(typeof $!=="string")return!1;let Z=x1($);return U6.some((J)=>J.test(Z))}var P6="The user explicitly required git worktree isolation, but EnterWorktree has not completed successfully. Do not continue in the original workspace. Your next action must be an EnterWorktree tool call. Wait for its result before using file or Bash tools.",E6="The user explicitly required leaving the managed worktree, but ExitWorktree has not completed successfully. Do not finish or explain. Your next action must be an ExitWorktree tool call using the action requested by the user.",b6="Required worktree lifecycle did not complete before the retry limit.",N6=3;function k1($,Z,J){if(!$)return{action:"none"};let W=x1($);if(!p0(W))return{action:"none"};let K=O6.some((X)=>X.test(W));if(Z.has("TaskWorktree"))return{action:"none"};let Y=!Z.has("EnterWorktree")?"EnterWorktree":K&&!Z.has("ExitWorktree")?"ExitWorktree":void 0;if(!Y)return{action:"none"};if(J>=N6)return{action:"fail",message:b6};return{action:"retry",tool:Y,prompt:Y==="EnterWorktree"?P6:E6}}var b1=30000;async function M$($){try{let J=t2.getInstance().executeStopHooks({projectDir:$.workspaceRoot??i(),sessionId:$.sessionId,permissionMode:$.permissionMode,reason:$.reason,abortSignal:$.abortSignal}),W,K=new Promise((Y)=>{W=setTimeout(()=>Y("timeout"),b1)});try{let Y=await Promise.race([J,K]);if(Y==="timeout")return x$.warn(`[Loop] Stop hook 超时 (${b1}ms),按 shouldStop: true 处理`),{action:"stop"};let X=Y;if(!X.shouldStop)return{action:"continue",reason:X.continueReason};return{action:"stop"}}finally{clearTimeout(W)}}catch(Z){return x$.warn("[Loop] Stop hook execution failed:",Z),{action:"stop"}}}async function _6($,Z){let J;while(!(J=await $.next()).done)if(Z)await Z(J.value);return J.value}var S6=[/<system-reminder>[\s\S]*?<\/system-reminder>/gi,/<file[^>]*>[\s\S]*?<\/file>/gi,/<hooks_context>[\s\S]*?<\/hooks_context>/gi,/<[^>]+>/g];function A6($){if(typeof $==="string")return $;if(Array.isArray($))return $.map((Z)=>{if(typeof Z==="string")return Z;if(Z&&typeof Z==="object"&&"text"in Z){let J=Z.text;return typeof J==="string"?J:""}return""}).join(" ");return""}function x6($){let Z=$;for(let Q of S6)Z=Z.replace(Q," ");Z=Z.replace(/^\s*\/[a-zA-Z][\w-]*\s+/,"");let J=Z.replace(/\s+/g," ").trim();if(!J)return"";let W=J.match(/^(.+?)(?:[.!?]\s|[。!?](?=\S|$)|$)/),K=W&&W[1].length>=6?W[1]:J;if(K=K.trim().replace(/[\s.。!!??,,;;::-]+$/,""),K.length<=60)return K;let Y=K.slice(0,60),X=Y.lastIndexOf(" ");return`${(X>36?Y.slice(0,X):Y).trimEnd()}…`}function T1($){return x6(A6($))}import{EventEmitter as k6}from"events";import f1 from"node:path";function v$($){if(M1($.sessionId),!f1.isAbsolute($.projectPath))throw Error("projectPath must be absolute");return{sessionId:$.sessionId,projectPath:f1.resolve($.projectPath)}}function f8($){let Z=v$($);return JSON.stringify([Z.projectPath,Z.sessionId])}class e2 extends k6{static instance;constructor(){super();this.setMaxListeners(100)}static getInstance(){if(!e2.instance)e2.instance=new e2;return e2.instance}publish($,Z,J,W){let K=v$($);this.emit("event",{sessionId:K.sessionId,projectPath:K.projectPath,type:Z,...W!==void 0?{seq:W}:{},properties:J})}subscribe($){return this.on("event",$),()=>this.off("event",$)}}var y0=e2.getInstance();var x2=w2("Agent"),g0=new Set;async function T6($,Z){let J=$.sessionId;if(!J||$.subagentInfo)return;if(g0.has(J))return;if(g0.size>=5000)g0.clear();g0.add(J);try{let W=$.workspaceRoot,K=await P0.findSessionMetadata(J,W);if(!K)return;if(K.title&&K.title.trim())return;let Y=T1(Z);if(!Y)return;await P0.updateSessionMetadata(J,K.projectPath,{title:Y}),y0.publish({sessionId:J,projectPath:K.projectPath},"session.updated",{title:Y})}catch(W){x2.debug?.("[Loop] 自动生成会话标题失败:",W)}}var R$=`<turn_aborted>
|
|
1
|
+
import{xb as I5}from"./chunk-4dnvydyv.js";import{$b as W1,Eb as Z5,Fb as J5,Gb as c$,Hb as u$,Ob as d1,Xb as L2,Zb as J1,_b as i0,fc as P0,yb as d2}from"./chunk-ak7v70sy.js";import{gc as V2,jc as o1,kc as q2}from"./chunk-vypake1a.js";import{ld as v5}from"./chunk-xjqcc0nt.js";import{md as R5,nd as f2,od as S5,pd as h5,qd as Z1,sd as m1}from"./chunk-rxfmqnf7.js";import{Wd as v2,Xd as b2,_d as C5}from"./chunk-5xph8r1k.js";import{he as t2}from"./chunk-hpgee5s3.js";import{ne as w2}from"./chunk-djh79rde.js";import{cf as M5}from"./chunk-gcsygn5a.js";import{rf as i}from"./chunk-kvd5nexw.js";import{Ef as $5}from"./chunk-tffagd03.js";import{Mf as Z0,Of as M1,Pf as X2,Qf as l0,Sf as t1,Uf as e1}from"./chunk-czjbz0fp.js";import{Vf as K7}from"./chunk-c7zk9zj2.js";function a2($){return $.role==="system"&&Array.isArray($.content)}function o2($){if($.role!=="system"||!$.metadata||Array.isArray($.metadata))return!1;return typeof $.metadata==="object"&&$.metadata.contextualProjectRules===!0}class R0{systemMessages;_contextualSystemMessages;_history;_pending=[];context;constructor($,Z){this.context=$;let J=$.messages.find(a2);if(this._contextualSystemMessages=$.messages.filter(o2),J)this.systemMessages=[J,...this._contextualSystemMessages];else if(Z)this.systemMessages=[{role:"system",content:[{type:"text",text:Z,providerOptions:{anthropic:{cacheControl:{type:"ephemeral"}}}}]},...this._contextualSystemMessages];else this.systemMessages=[...this._contextualSystemMessages];this._history=$.messages.filter((W)=>!a2(W)&&!o2(W))}get historyLength(){return this._history.length}get history(){return this._history}get pending(){return this._pending}toLLMMessages(){return[...this.systemMessages,...this._history,...this._pending]}getMessagesForLLM(){return this.toLLMMessages()}getHistory(){return this._history}appendPending($){this._pending.push($)}appendUser($){this._pending.push($)}appendAssistant($){this._pending.push($)}appendToolResult($){this._pending.push($)}appendContextualProjectInstructions($){if(!o2($))throw Error("Contextual project instructions require safe metadata");this._contextualSystemMessages.push($),this.systemMessages.push($)}syncContextualSystemMessages(){let $=this.systemMessages.filter(a2);this.systemMessages.splice(0,this.systemMessages.length,...$,...this._contextualSystemMessages)}appendControl($,Z){if($==="system")throw Error("Cannot append system control message via appendControl. Use constructor for root system prompt.");this._pending.push(Z)}appendToHistory($){this._history.push($)}commitPending(){if(this._pending.length>0)this._history.push(...this._pending),this._pending=[]}replaceHistory($){this._history=$.filter((Z)=>!a2(Z)&&!o2(Z))}restoreDurableHistory($){this._contextualSystemMessages=$.filter(o2),this._history=$.filter((Z)=>!a2(Z)&&!o2(Z)),this._pending=[],this.syncContextualSystemMessages()}removeMessages($){this._history=this._history.filter((Z)=>!$(Z)),this._pending=this._pending.filter((Z)=>!$(Z)),this._contextualSystemMessages=this._contextualSystemMessages.filter((Z)=>!$(Z)),this.syncContextualSystemMessages()}writeback(){this.commitPending(),this.context.messages=[...this._contextualSystemMessages,...this._history]}get hasSystemPrompt(){return this.systemMessages.length>0}}function G1($){if($.isSubagent)return"continue";if(!$.budget||$.budget<=0)return"continue";if($.consecutiveContinuations>=3&&$.lastOutputDelta<500)return"stop";if($.usage/$.budget>=0.9)return"stop";return"continue"}function L1($){return{budget:$.budget,usage:0,consecutiveContinuations:0,lastOutputDelta:0,isSubagent:$.isSubagent??!1}}function F1($,Z,J){return{...$,usage:$.usage+Z,lastOutputDelta:Z,consecutiveContinuations:J?$.consecutiveContinuations+1:0}}import m2 from"node:path";var o5=new Set(["GOEXPERIMENT","GOOS","GOARCH","CGO_ENABLED","GO111MODULE","RUST_BACKTRACE","RUST_LOG","NODE_ENV","PYTHONUNBUFFERED","PYTHONDONTWRITEBYTECODE","GIT_TERMINAL_PROMPT","LANG","LANGUAGE","LC_ALL","LC_CTYPE","LC_TIME","CHARSET","TERM","COLORTERM","NO_COLOR","FORCE_COLOR","TZ","LS_COLORS","LSCOLORS","GREP_COLOR","GREP_COLORS"]),a5=/^(LD_.+|DYLD_.+|PATH)$/,U1=/^([A-Za-z_][A-Za-z0-9_]*)=([\w./:@-]*)$/;function U0($){let Z=$;while(!0){let J=Z.match(/^(\S+)[ \t]+([\s\S]*)$/);if(!J)break;let W=J[1],K=J[2],Y=W.match(U1);if(!Y)break;let X=Y[1];if(!o5.has(X))break;Z=K}return Z}function q8($){let Z=$;while(!0){let J=Z.match(/^(\S+)[ \t]+([\s\S]*)$/);if(!J)break;let W=J[1],K=J[2],Y=W.match(U1);if(!Y)break;let X=Y[1];if(a5.test(X))break;Z=K}return Z}var s5=[/^timeout[ \t]+(?:--foreground[ \t]+|--preserve-status[ \t]+|-v[ \t]+|--verbose[ \t]+|-k[ \t]+\S+[ \t]+|--kill-after[= ]\S+[ \t]+|-s[ \t]+\S+[ \t]+|--signal[= ]\S+[ \t]+)*\S+[ \t]+/,/^time[ \t]+/,/^nice[ \t]+(?:-n[ \t]+\d+[ \t]+|-\d+[ \t]+)?/,/^nohup[ \t]+/];function A$($){let Z=$,J=!0;while(J){J=!1;for(let W of s5){let K=Z.match(W);if(K){Z=Z.slice(K[0].length),J=!0;break}}if(Z.startsWith("-- "))Z=Z.slice(3),J=!0}return Z}function h0($){let Z=[],J="",W=!1,K=!1,Y=!1;for(let X=0;X<$.length;X++){let z=$[X];if(Y){J+=z,Y=!1;continue}if(z==="\\"&&!W){J+=z,Y=!0;continue}if(z==="'"&&!K){W=!W,J+=z;continue}if(z==='"'&&!W){K=!K,J+=z;continue}if(W||K){J+=z;continue}if(z==="|"){if(X+1<$.length&&$[X+1]==="|"){if(J.trim())Z.push(J.trim());J="",X++;continue}return null}if(z===">"||z==="<")return null;if(z==="&"&&X+1<$.length&&$[X+1]==="&"){if(J.trim())Z.push(J.trim());J="",X++;continue}if(z==="&")return null;if(z===";"){if(J.trim())Z.push(J.trim());J="";continue}J+=z}if(J.trim())Z.push(J.trim());return Z.length>0?Z:null}function O1($){let Z=!1,J=!1,W=!1;for(let K=0;K<$.length;K++){let Y=$[K];if(W){W=!1;continue}if(Y==="\\"&&!Z){W=!0;continue}if(Y==="'"&&!J){Z=!Z;continue}if(Y==='"'&&!Z){J=!J;continue}if(Z)continue;if(Y==="$"){let X=$[K+1];if(X&&/[A-Za-z_@*#?!$0-9({]/.test(X))return!0}if(Y==="`")return!0;if(J)continue;if(Y==="|")return!0;if(Y===">"||Y==="<")return!0;if(Y==="{"){let X=$.slice(K);if(/^\{[^}]*,[^}]*\}/.test(X)||/^\{[^}]*\.\.[^}]*\}/.test(X))return!0}}return!1}function O0($){let Z=[],J="",W=!1,K=!1,Y=!1;for(let X=0;X<$.length;X++){let z=$[X];if(Y){J+=z,Y=!1;continue}if(z==="\\"&&!W){if(Y=!0,K){let Q=$[X+1];if(Q&&'$`"\\'.includes(Q))continue;J+=z,Y=!1}continue}if(z==="'"&&!K){W=!W;continue}if(z==='"'&&!W){K=!K;continue}if(!W&&!K&&/[ \t]/.test(z)){if(J)Z.push(J),J="";continue}J+=z}if(J)Z.push(J);return Z}var t5=new Set(["npm","pnpm","yarn","bun"]),y1=new Set(["biome","eslint","jest","mypy","pyright","pytest","ruff","tsc","vitest"]),e5=new Set(["-u","--fix","--update","--update-snapshot","--updateSnapshot","--watch","--watchAll","--write"]);function $6($){return $!==void 0&&/^(?:test|lint|build|type-?check)(?::[\w.-]+)*$/i.test($)}function Z6($){return $.replace(/\s+2>&1\s*$/,"").trim()}function J6($,Z,J){if(!J||Z.length!==2)return;let W=/^(.+?)[ \t]+&&[ \t]+([\s\S]+)$/.exec($);if(!W)return;let K=O0(W[1]??"");if(K.length!==2||K[0]!=="cd")return;let Y=K[1];if(!Y||Y==="-")return;let X=m2.isAbsolute(Y)?m2.resolve(Y):m2.resolve(J,Y);if(!d2.isWithinWorkspace(X,J))return;return W[2]?.trim()||void 0}function s2($,Z){let J=U0(Z6($)),W=h0(J);if(!W||O1(J)||/[\r\n]/.test(J))return!1;let K=W.length===1?W[0]:J6(J,W,Z);if(!K)return!1;let Y=O0(K);if(Y.length===0||Y.some((H)=>[...e5].some((V)=>H===V||H.startsWith(`${V}=`))))return!1;let[X,z,Q]=Y;if(t5.has(X??""))return $6(z==="run"?Q:z)||z==="--test";if((X==="npx"||X==="bunx")&&y1.has(z??""))return!0;if(y1.has(X??""))return!0;if(X==="node"&&z==="--test")return!0;if(X==="go"&&["build","test","vet"].includes(z??""))return!0;return X==="cargo"&&["build","check","clippy","test"].includes(z??"")}function O8($,Z){if($===void 0)return!0;if(typeof $!=="string"||$.split(/[\\/]/).includes(".."))return!1;if(!Z)return!m2.isAbsolute($);let J=m2.isAbsolute($)?m2.resolve($):m2.resolve(Z,$);return d2.isWithinWorkspace(J,Z)}var x$=w2("Agent"),W6=3;function k$($,Z,J){if($!=="length")return{action:"none"};if(Z>=W6)return{action:"truncated"};if(G1(J)==="stop")return x$.info("[Loop] Token budget: diminishing returns detected, skipping recovery"),{action:"budget_stop"};return{action:"recover"}}var K6=[/:\s*$/,/:\s*$/,/\.\.\.\s*$/,/让我(先|来|开始|查看|检查|修复)/,/Let me (first|start|check|look|fix)/i,/I('ll| will) (now |)(create|write|edit|update|modify|fix|add|implement)/i,/我(现在就|来|要)(创建|写入|编辑|修改|修复|添加|实现)/,/\d+\.\s+(First|Next|Then|Finally)/i],Y6=/```[\s\S]{50,}```/,P1="请执行你提到的操作,不要只是描述。使用 Edit/Write/ApplyPatch/Bash 工具来实际修改文件。",X6=2;function T$($,Z,J=!0){if(!$||Z>=X6)return{action:"none"};if(!J&&Y6.test($))return{action:"retry",prompt:P1};let W=$.slice(-200),K=W.match(/```/g);if(K&&K.length%2!==0)return{action:"none"};if(K6.some((X)=>X.test(W)))return{action:"retry",prompt:P1};return{action:"none"}}var z6=[/\b(?:run|execute|rerun|re-run)\b[\s\S]{0,60}\b(?:tests?|test suite|lint|type-?check|build)\b/i,/\b(?:npm|pnpm|yarn|bun)\s+(?:run\s+)?(?:test|lint|build|type-?check)\b/i,/(?:运行|执行|跑|重新运行).{0,30}(?:测试|单测|集成测试|检查|构建)/],E1={test:/\b(?:tests?|test suite)\b|(?:测试|单测|集成测试)/i,lint:/\blint(?:ing)?\b/i,"type-check":/\btype[\s-]?check(?:ing)?\b|\btsc\b|类型检查/i,build:/\bbuild\b|构建/i},Q6={test:/(?:^|\s)(?:npm|pnpm|yarn|bun)\s+(?:run\s+)?test\b|(?:^|\s)(?:node|bun)\s+--test\b|(?:^|\s)(?:vitest|jest|pytest|go\s+test|cargo\s+test)\b/i,lint:/(?:^|\s)(?:npm|pnpm|yarn|bun)\s+(?:run\s+)?lint\b/i,"type-check":/(?:^|\s)(?:npm|pnpm|yarn|bun)\s+(?:run\s+)?type-?check\b|(?:^|\s)tsc\b/i,build:/(?:^|\s)(?:npm|pnpm|yarn|bun)\s+(?:run\s+)?build\b/i},H6="The user explicitly required verification, but it has not run successfully. Do not finish or explain. Your next action must be a Bash tool call that runs the requested test, lint, type-check, or build command. Inspect the command result and fix any failure before finishing.",B6="Required verification did not run successfully before the retry limit.",V6=3;function N1($,Z,J,W){if(!J.success)return;if(["Edit","Write","ApplyPatch","NotebookEdit"].includes(Z)){$.clear();return}if(Z==="Bash"&&typeof J.metadata?.command==="string"&&J.metadata.exit_code===0&&s2(J.metadata.command,W)){$.add(J.metadata.command);return}if(!["Task","TaskOutput"].includes(Z))return;let K=J.metadata?.verificationCommands;if(!Array.isArray(K))return;for(let Y of K)if(typeof Y==="string"&&s2(Y,W))$.add(Y)}function f$($,Z,J){if(!$||!z6.some((Q)=>Q.test($)))return{action:"none"};let W=Object.keys(E1).filter((Q)=>E1[Q].test($)),K=[...Z],Y=W.filter((Q)=>!K.some((H)=>Q6[Q].test(H)));if(W.length>0?Y.length===0:K.some((Q)=>s2(Q)))return{action:"none"};if(J>=V6)return{action:"fail",message:B6};let z=W.length>1&&Y.length>0?` Missing successful verification categories: ${Y.join(", ")}.`:"";return{action:"retry",prompt:`${H6}${z}`}}var D6=[/\bdelegate\b[\s\S]{0,120}\b(?:Task tool|subagent|agent)\b/i,/\b(?:call|use|invoke)\b[\s\S]{0,80}\bTask tool\b/i,/(?:委派|交给|调用|使用).{0,60}(?:Task|子代理|子智能体)/],_1=[/\b(?:do not|don't|never)\s+(?:delegate|call|use|invoke)\b/i,/(?:不要|禁止|无需)(?:委派|调用|使用).{0,20}(?:Task|子代理|子智能体)?/];function S1($){return typeof $==="string"&&_1.some((Z)=>Z.test($))}var j6=[/\b(?:call|use|invoke)\b[\s\S]{0,30}\bTask(?: tool)?\b[\s\S]{0,30}\bexactly once\b/i,/\bexactly once\b[\s\S]{0,30}\b(?:call|use|invoke)\b[\s\S]{0,30}\bTask(?: tool)?\b/i,/\bexactly one\b[\s\S]{0,30}\bTask(?: tool)? calls?\b/i,/(?:Task|子代理).{0,20}(?:恰好|仅|只)(?:调用|使用)?一次/,/(?:恰好|仅|只)(?:调用|使用)?一次.{0,20}(?:Task|子代理)/],w6=[/\b(?:do not|don't|never)\s+(?:call|use|invoke)\s+(?:the\s+)?Task\b[\s\S]{0,30}\bexactly once\b/i,/\bTask\b[\s\S]{0,30}\b(?:does not|doesn't|need not)\b[\s\S]{0,30}\bexactly once\b/i,/\bmultiple\s+Task(?: tool)?\s+calls?\s+(?:are\s+)?allowed\b/i,/(?:不要|禁止).{0,12}(?:Task|子代理).{0,12}(?:恰好|仅|只)(?:调用|使用)?一次/];function q6($){if(typeof $!=="string")return;if(w6.some((Z)=>Z.test($)))return"multiple-allowed";return j6.some((Z)=>Z.test($))?"required":void 0}function I0($){for(let Z of $){let J=q6(Z);if(J!==void 0)return J==="required"}return!1}var G6="The user explicitly required delegation, but no Task tool call completed successfully. Do not solve the task directly or explain. Your next action must be a Task tool call using the requested subagent.",L6="Required delegation did not complete before the retry limit.",F6=3;function A1($,Z,J){let W=(typeof $==="string"?[$]:$??[]).map((X)=>X.trim()).filter(Boolean),K=I0(W),Y=!1;if(!K)for(let X of W){if(_1.some((z)=>z.test(X)))break;if(D6.some((z)=>z.test(X))){Y=!0;break}}if(W.length===0||!K&&!Y||Z.has("Task"))return{action:"none"};if(J>=F6)return{action:"fail",message:L6};return{action:"retry",prompt:G6}}var U6=[/\b(?:use|create|enter|start|work\s+(?:in|inside))\b.{0,60}\bworktree\b/i,/(?:使用|创建|进入).{0,30}(?:worktree|工作树)/i],O6=[/\b(?:exit|leave)\b.{0,40}\bworktree\b/i,/\bworktree\b.{0,60}\b(?:action\s+)?(?:keep|remove)\b/i,/(?:退出|离开).{0,30}(?:worktree|工作树)/i],y6=[/\b(?:do not|don't|never|must not|should not)\b[^.!?;\n]{0,80}\b(?:git\s+)?worktree\b/gi,/\bwithout\b[^.!?;\n]{0,60}\b(?:git\s+)?worktree\b/gi,/(?:不要|禁止|不得|无需)[^。!?;\n]{0,50}(?:worktree|工作树)/gi];function x1($){return y6.reduce((Z,J)=>Z.replace(J," "),$)}function p0($){if(typeof $!=="string")return!1;let Z=x1($);return U6.some((J)=>J.test(Z))}var P6="The user explicitly required git worktree isolation, but EnterWorktree has not completed successfully. Do not continue in the original workspace. Your next action must be an EnterWorktree tool call. Wait for its result before using file or Bash tools.",E6="The user explicitly required leaving the managed worktree, but ExitWorktree has not completed successfully. Do not finish or explain. Your next action must be an ExitWorktree tool call using the action requested by the user.",b6="Required worktree lifecycle did not complete before the retry limit.",N6=3;function k1($,Z,J){if(!$)return{action:"none"};let W=x1($);if(!p0(W))return{action:"none"};let K=O6.some((X)=>X.test(W));if(Z.has("TaskWorktree"))return{action:"none"};let Y=!Z.has("EnterWorktree")?"EnterWorktree":K&&!Z.has("ExitWorktree")?"ExitWorktree":void 0;if(!Y)return{action:"none"};if(J>=N6)return{action:"fail",message:b6};return{action:"retry",tool:Y,prompt:Y==="EnterWorktree"?P6:E6}}var b1=30000;async function M$($){try{let J=t2.getInstance().executeStopHooks({projectDir:$.workspaceRoot??i(),sessionId:$.sessionId,permissionMode:$.permissionMode,reason:$.reason,abortSignal:$.abortSignal}),W,K=new Promise((Y)=>{W=setTimeout(()=>Y("timeout"),b1)});try{let Y=await Promise.race([J,K]);if(Y==="timeout")return x$.warn(`[Loop] Stop hook 超时 (${b1}ms),按 shouldStop: true 处理`),{action:"stop"};let X=Y;if(!X.shouldStop)return{action:"continue",reason:X.continueReason};return{action:"stop"}}finally{clearTimeout(W)}}catch(Z){return x$.warn("[Loop] Stop hook execution failed:",Z),{action:"stop"}}}async function _6($,Z){let J;while(!(J=await $.next()).done)if(Z)await Z(J.value);return J.value}var S6=[/<system-reminder>[\s\S]*?<\/system-reminder>/gi,/<file[^>]*>[\s\S]*?<\/file>/gi,/<hooks_context>[\s\S]*?<\/hooks_context>/gi,/<[^>]+>/g];function A6($){if(typeof $==="string")return $;if(Array.isArray($))return $.map((Z)=>{if(typeof Z==="string")return Z;if(Z&&typeof Z==="object"&&"text"in Z){let J=Z.text;return typeof J==="string"?J:""}return""}).join(" ");return""}function x6($){let Z=$;for(let Q of S6)Z=Z.replace(Q," ");Z=Z.replace(/^\s*\/[a-zA-Z][\w-]*\s+/,"");let J=Z.replace(/\s+/g," ").trim();if(!J)return"";let W=J.match(/^(.+?)(?:[.!?]\s|[。!?](?=\S|$)|$)/),K=W&&W[1].length>=6?W[1]:J;if(K=K.trim().replace(/[\s.。!!??,,;;::-]+$/,""),K.length<=60)return K;let Y=K.slice(0,60),X=Y.lastIndexOf(" ");return`${(X>36?Y.slice(0,X):Y).trimEnd()}…`}function T1($){return x6(A6($))}import{EventEmitter as k6}from"events";import f1 from"node:path";function v$($){if(M1($.sessionId),!f1.isAbsolute($.projectPath))throw Error("projectPath must be absolute");return{sessionId:$.sessionId,projectPath:f1.resolve($.projectPath)}}function f8($){let Z=v$($);return JSON.stringify([Z.projectPath,Z.sessionId])}class e2 extends k6{static instance;constructor(){super();this.setMaxListeners(100)}static getInstance(){if(!e2.instance)e2.instance=new e2;return e2.instance}publish($,Z,J,W){let K=v$($);this.emit("event",{sessionId:K.sessionId,projectPath:K.projectPath,type:Z,...W!==void 0?{seq:W}:{},properties:J})}subscribe($){return this.on("event",$),()=>this.off("event",$)}}var y0=e2.getInstance();var x2=w2("Agent"),g0=new Set;async function T6($,Z){let J=$.sessionId;if(!J||$.subagentInfo)return;if(g0.has(J))return;if(g0.size>=5000)g0.clear();g0.add(J);try{let W=$.workspaceRoot,K=await P0.findSessionMetadata(J,W);if(!K)return;if(K.title&&K.title.trim())return;let Y=T1(Z);if(!Y)return;await P0.updateSessionMetadata(J,K.projectPath,{title:Y}),y0.publish({sessionId:J,projectPath:K.projectPath},"session.updated",{title:Y})}catch(W){x2.debug?.("[Loop] 自动生成会话标题失败:",W)}}var R$=`<turn_aborted>
|
|
2
2
|
The previous turn was interrupted. Commands or tool calls may have partially completed; inspect the workspace and running processes before retrying.
|
|
3
3
|
</turn_aborted>`,c2="Tool execution was blocked because its durable call record could not be committed. No tool side effect was started.",v1="Tool execution completed, but its durable result record could not be committed. Further model and tool execution was stopped. The operation may have completed; inspect external state before retrying.";class $0 extends Error{phase;constructor($,Z){super($==="user_message"?"Conversation input could not be committed. No further model request was started.":"Model output could not be committed. The run was stopped before any further model request or successful completion.",Z);this.phase=$;this.name="DurableConversationPersistenceError"}}function u2($){return $.executionEngine?.getContextManager()}async function W2($,Z,J,W=null,K,Y={}){let X=Y.required??$.executionEngine!==void 0;try{let z=u2($),Q=typeof J==="string"?J.trim()!=="":J.some((H)=>H.type==="text"?H.text.trim()!=="":!0);if(z&&Z.sessionId&&Q){let H=await z.saveMessage(Z.sessionId,"user",J,W,K,Z.subagentInfo);if(X&&!H)throw Error("Durable user-message commit returned no identity");return T6(Z,J),H}if(X&&Z.sessionId&&Q)throw Error("Durable user-message storage is unavailable")}catch(z){if(x2.warn("[Loop] 保存用户消息失败:",z),X)throw new $0("user_message",{cause:z})}return null}async function C($,Z,J,W,K,Y,X={}){let z=X.required??$.executionEngine!==void 0;try{let Q=u2($),H=Boolean(J.trim()||K?.trim());if(Q&&Z.sessionId&&H){let V=await Q.saveMessage(Z.sessionId,"assistant",J,W,Y,Z.subagentInfo,K);if(z&&!V)throw Error("Durable assistant-message commit returned no identity");return V}if(z&&Z.sessionId&&H)throw Error("Durable assistant-message storage is unavailable")}catch(Q){if(x2.warn("[Loop] 保存助手消息失败:",Q),z)throw new $0("assistant_message",{cause:Q})}return null}async function R1($,Z,J){try{let W=u2($);if(W&&Z.sessionId)return await W.saveMessage(Z.sessionId,"system",R$,J,void 0,Z.subagentInfo)}catch(W){x2.warn("[Loop] 保存中断边界失败:",W)}return null}async function h1($,Z,J,W,K){try{let Y=u2($);if(!Y||!Z.sessionId||J.length===0)return null;return await Y.saveMessage(Z.sessionId,"system",`<contextual-project-instructions-ref count="${J.length}" />`,K,{contextualProjectRules:!0,ruleReferences:JSON.parse(JSON.stringify(J.map((X)=>({...X})))),triggerPaths:[...W]},Z.subagentInfo)}catch(Y){x2.warn("[Loop] 保存 contextual project rules provenance 失败:",Y)}return null}async function h$($,Z,J,W,K,Y={}){try{let X=u2($);if(X&&Z.sessionId){let z=await X.saveToolUse(Z.sessionId,J,W,K,Z.subagentInfo);if(Y.required&&!z)throw Error("Durable tool-use commit returned no identity");return z}if(Y.required&&Z.sessionId)throw Error("Durable tool-use storage is unavailable")}catch(X){if(x2.warn("[Loop] 保存工具调用失败:",X),Y.required)throw X}return null}async function m0($,Z,J,W,K,Y,X,z,Q,H={}){try{let V=u2($);if(V&&Z.sessionId){let w=await V.saveToolResult(Z.sessionId,J,W,K,Y,X,Z.subagentInfo,z,Q);if(H.required&&!w)throw Error("Durable tool-result commit returned no identity");return w}if(H.required&&Z.sessionId)throw Error("Durable tool-result storage is unavailable")}catch(V){if(x2.warn("[Loop] 保存工具结果失败:",V),H.required)throw V}return null}async function E0($,Z,J,W,K={}){try{let Y=u2($);if(Y&&Z.sessionId){let X=await Y.saveCompaction(Z.sessionId,J,W,null);if(K.required&&!X)throw Error("Compaction checkpoint commit returned no identity");return X||null}if(K.required&&Z.sessionId)throw Error("Compaction checkpoint storage is unavailable")}catch(Y){if(x2.warn("[Loop] 保存压缩数据失败:",Y),K.required)throw Y}return null}import{createHash as n7}from"node:crypto";import{promises as m6}from"node:fs";import d6 from"node:path";import{nanoid as T2}from"nanoid";import*as d from"node:fs/promises";import*as l2 from"node:path";var C1={enabled:!0,maxIndexLines:200};var f6="memory",I1="MEMORY.md";class C${memoryDir;config;initialized=!1;constructor($,Z,J){if(J)this.memoryDir=J;else{let W=Z0($);this.memoryDir=l2.join(W,f6)}this.config={...C1,...Z}}async initialize(){if(this.initialized)return;await d.mkdir(this.memoryDir,{recursive:!0}),this.initialized=!0}async loadIndex(){if(!this.config.enabled)return null;await this.initialize();let $=l2.join(this.memoryDir,I1);try{let Z=await d.readFile($,"utf-8");if(!Z.trim())return null;let J=Z.split(`
|
|
4
4
|
`),K=J.slice(0,this.config.maxIndexLines).join(`
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{Wd as L1,Xd as Z0,Yd as G1}from"./chunk-5xph8r1k.js";import{ae as $O,be as HO}from"./chunk-5sw8j9ae.js";import{ee as Y1}from"./chunk-18n15nn8.js";import{fe as B0,he as M0}from"./chunk-
|
|
1
|
+
import{Wd as L1,Xd as Z0,Yd as G1}from"./chunk-5xph8r1k.js";import{ae as $O,be as HO}from"./chunk-5sw8j9ae.js";import{ee as Y1}from"./chunk-18n15nn8.js";import{fe as B0,he as M0}from"./chunk-hpgee5s3.js";import{ne as h,oe as z}from"./chunk-djh79rde.js";import{$e as j0,Re as V0,Se as o1}from"./chunk-nfm5j63c.js";import{ff as u,hf as W,kf as R1}from"./chunk-9ka0bdry.js";import{rf as b}from"./chunk-kvd5nexw.js";import{Ef as d0}from"./chunk-tffagd03.js";import{Jf as T}from"./chunk-698qsvyb.js";import J1 from"node:path";import L$ from"node:path";import C0 from"node:fs";import J0 from"node:os";import R from"node:path";import jO from"yaml";var g$={type:"object",properties:{verdict:{type:"string",enum:["pass","fail","partial"]},summary:{type:"string",minLength:1,maxLength:2000},findings:{type:"array",maxItems:50,items:{type:"string",minLength:1,maxLength:1000}}},required:["verdict","summary","findings"],additionalProperties:!1};function u$(O){if(!O||typeof O!=="object"||Array.isArray(O))return;let $=O.verdict;return $==="pass"||$==="fail"||$==="partial"?$:void 0}var UO=`# Goal Completion Verifier
|
|
2
2
|
|
|
3
3
|
You are a fresh, independent, adversarial verifier. The parent Agent has claimed
|
|
4
4
|
that a persisted goal is complete. Your job is to refute that claim unless the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Rd as a,Sd as b,Td as c,Ud as d,Vd as e}from"./chunk-
|
|
1
|
+
import{Rd as a,Sd as b,Td as c,Ud as d,Vd as e}from"./chunk-2j3d4ykq.js";import"./chunk-5xph8r1k.js";import"./chunk-5sw8j9ae.js";import"./chunk-18n15nn8.js";import"./chunk-hpgee5s3.js";import"./chunk-sr2stcda.js";import"./chunk-djh79rde.js";import"./chunk-nfm5j63c.js";import"./chunk-gcsygn5a.js";import"./chunk-9ka0bdry.js";import"./chunk-vc2c8wkx.js";import"./chunk-kvd5nexw.js";import"./chunk-8472vz3s.js";import"./chunk-f9tahtz6.js";import"./chunk-tffagd03.js";import"./chunk-698qsvyb.js";import"./chunk-h0q03x9f.js";import"./chunk-czjbz0fp.js";import"./chunk-c7zk9zj2.js";export{d as snapshotWorkspaceAgentResources,c as resolveWorkspaceAgentResources,e as resetWorkspaceAgentResources,a as refreshWorkspaceCommunicationStyles,b as configureInvocationPluginDirs};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import"./chunk-wax3nm7t.js";import"./chunk-djh79rde.js";import{$e as Q}from"./chunk-
|
|
2
|
-
`);try{let{rebuildProjectionIndex:z}=await import("./chunk-9wdg2mqh.js"),{SessionService:B}=await import("./chunk-
|
|
1
|
+
import"./chunk-wax3nm7t.js";import"./chunk-djh79rde.js";import{$e as Q}from"./chunk-nfm5j63c.js";import"./chunk-gcsygn5a.js";import"./chunk-9ka0bdry.js";import"./chunk-vc2c8wkx.js";import{rf as L}from"./chunk-kvd5nexw.js";import"./chunk-8472vz3s.js";import"./chunk-f9tahtz6.js";import"./chunk-tffagd03.js";import"./chunk-698qsvyb.js";import"./chunk-h0q03x9f.js";import"./chunk-czjbz0fp.js";import{Vf as F}from"./chunk-c7zk9zj2.js";var K=[22,19,0];function T(G){let A=/^v?(\d+)\.(\d+)\.(\d+)/.exec(G);if(!A)return!1;let H=A.slice(1).map(Number);for(let z=0;z<K.length;z++){let B=H[z]??0,J=K[z];if(B!==J)return B>J}return!0}var X={command:"doctor",describe:"Check the health of your Blade installation",builder:(G)=>G.option("rebuild-index",{type:"boolean",default:!1,describe:"Rebuild the SQLite session index from JSONL transcripts"}),handler:async(G)=>{if(G.rebuildIndex){console.log(`Rebuilding session index from JSONL transcripts...
|
|
2
|
+
`);try{let{rebuildProjectionIndex:z}=await import("./chunk-9wdg2mqh.js"),{SessionService:B}=await import("./chunk-nbwvc4v4.js"),J=await z(B.projectionDeriverForSearch());if(J===null)console.log("[WARN] Session index unavailable (SQLite driver missing); reads fall back to JSONL scan.");else console.log(`[OK] Session index rebuilt: ${J} session(s) indexed.`)}catch(z){console.log("[FAIL] Session index rebuild failed"),console.log(` Error: ${z instanceof Error?z.message:"未知错误"}`),process.exit(1)}return}console.log(`Running Blade health check...
|
|
3
3
|
`);let A=0;try{await Q.getInstance().initialize(),console.log("[OK] Configuration: OK")}catch(z){console.log("[FAIL] Configuration: FAILED"),console.log(` Error: ${z instanceof Error?z.message:"未知错误"}`),A++}let H=process.version;if(T(H))console.log(`[OK] Node.js version: ${H}`);else console.log(`[WARN] Node.js version: ${H} (required: >=22.19.0)`),A++;try{let z=await import("fs/promises"),B=L();await z.access(B,(await import("fs")).constants.R_OK|(await import("fs")).constants.W_OK),console.log("[OK] File system permissions: OK")}catch(z){console.log("[FAIL] File system permissions: FAILED"),console.log(" Error: Cannot read/write in current directory"),A++}try{await import("ink"),console.log("[OK] Dependencies: OK")}catch(z){console.log("[FAIL] Dependencies: FAILED"),console.log(" Error: Missing required dependencies"),A++}if(console.log(`
|
|
4
4
|
Health Check Summary:`),A===0)console.log("All checks passed! Blade is ready to use.");else console.log(`Warning: Found ${A} issue(s). Please resolve them for optimal performance.`),process.exit(1)}};export{T as isSupportedNodeVersion,X as doctorCommands};
|