blade-code 0.10.102 → 0.10.104
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-050537sc.js +10 -0
- package/dist/{chunk-9sx3vsyj.js → chunk-0hr050ck.js} +1 -1
- package/dist/{chunk-9n5ystr6.js → chunk-0tbdbnyp.js} +3 -3
- package/dist/{chunk-kwkkcs4y.js → chunk-181ef74x.js} +1 -1
- package/dist/{chunk-enwtex3j.js → chunk-31aeh672.js} +2 -2
- package/dist/{chunk-ffp2rn7f.js → chunk-32yfgw9s.js} +1 -1
- package/dist/{chunk-19xfer55.js → chunk-3rpmd93p.js} +2 -2
- package/dist/{chunk-c6tq09mt.js → chunk-41cg66y0.js} +1 -1
- package/dist/{chunk-p0rvgzpx.js → chunk-41ympwz1.js} +1 -1
- package/dist/{chunk-39qzk9nm.js → chunk-47e6tdbb.js} +1 -1
- package/dist/chunk-496d1ag5.js +1 -0
- package/dist/{chunk-9b0896bm.js → chunk-4m38k0rp.js} +1 -1
- package/dist/{chunk-a5jv8pn9.js → chunk-6nc7mcxx.js} +1 -1
- package/dist/{chunk-4fmtv329.js → chunk-6wsvgk20.js} +1 -1
- package/dist/{chunk-j00px1es.js → chunk-7fz3w4rk.js} +1 -1
- package/dist/chunk-8886s1qa.js +1 -0
- package/dist/{chunk-ykkqywtq.js → chunk-946wkbmw.js} +1 -1
- package/dist/{chunk-k7vv9vne.js → chunk-9p20hhs0.js} +1 -1
- package/dist/{chunk-0zhdjaen.js → chunk-abd57h72.js} +1 -1
- package/dist/{chunk-na3jmz7f.js → chunk-b69xvpah.js} +1 -1
- package/dist/{chunk-qjeadpj2.js → chunk-bt18xsc6.js} +1 -1
- package/dist/chunk-c475tfqf.js +2 -0
- package/dist/chunk-cj0c0ffd.js +1 -0
- package/dist/{chunk-zxhv8xfp.js → chunk-e40ntkjm.js} +1 -1
- package/dist/{chunk-fn9cse83.js → chunk-epdzdv4e.js} +1 -1
- package/dist/{chunk-czcxx8tb.js → chunk-f3426b1c.js} +1 -1
- package/dist/{chunk-w9xfks7f.js → chunk-fhfzdyba.js} +1 -1
- package/dist/{chunk-qcy79mva.js → chunk-fva7jnjy.js} +1 -1
- package/dist/{chunk-10taec1j.js → chunk-j2dyprdy.js} +1 -1
- package/dist/{chunk-hexj26gw.js → chunk-jk209m4h.js} +1 -1
- package/dist/{chunk-6kb69vkx.js → chunk-jntgg3zj.js} +3 -3
- package/dist/chunk-kdjtxpxw.js +1 -0
- package/dist/chunk-kf7whgr7.js +2 -0
- package/dist/{chunk-fpx3462x.js → chunk-kfcbaj44.js} +1 -1
- package/dist/chunk-kfgw21tq.js +1 -0
- package/dist/chunk-knmvaxsb.js +1 -0
- package/dist/{chunk-qw57eqns.js → chunk-m5zx8enh.js} +2 -2
- package/dist/{chunk-kt5jqaxp.js → chunk-mm762w5r.js} +1 -1
- package/dist/{chunk-b8n5mx53.js → chunk-mxjsttbc.js} +1 -1
- package/dist/{chunk-d8wzc602.js → chunk-n7mzxa8h.js} +2 -2
- package/dist/{chunk-cpk84yrx.js → chunk-pkack2dw.js} +1 -1
- package/dist/{chunk-70hwyc2w.js → chunk-q69fzq4y.js} +1 -1
- package/dist/chunk-r9p130v6.js +1 -0
- package/dist/{chunk-3awjdsef.js → chunk-rchz6j90.js} +1 -1
- package/dist/chunk-rnz5zxdw.js +1 -0
- package/dist/{chunk-2va6ex5v.js → chunk-rvk9r2cm.js} +1 -1
- package/dist/{chunk-6yezrqe7.js → chunk-rx2eax1g.js} +1 -1
- package/dist/{chunk-425p4nwx.js → chunk-s10pmnrd.js} +2 -2
- package/dist/{chunk-vw328ehw.js → chunk-scq56220.js} +1 -1
- package/dist/{chunk-f9asjkfz.js → chunk-sdbbyagy.js} +1 -1
- package/dist/chunk-sg795gzk.js +1 -0
- package/dist/chunk-stmmw8m8.js +6 -0
- package/dist/{chunk-v6hffjwc.js → chunk-sv9apfmy.js} +2 -2
- package/dist/{chunk-9hsbjy6a.js → chunk-szxajr6e.js} +1 -1
- package/dist/{chunk-rkk39efr.js → chunk-t55d9bjv.js} +1 -1
- package/dist/{chunk-6r6yzw44.js → chunk-terw7qdx.js} +267 -265
- package/dist/{chunk-q3vza5gt.js → chunk-tgdhsm5t.js} +2 -2
- package/dist/chunk-v4w5b2cq.js +1 -0
- package/dist/chunk-vk4xbek0.js +1 -0
- package/dist/{chunk-pdqczfn3.js → chunk-vtq52np4.js} +1 -1
- package/dist/{chunk-53xtssbf.js → chunk-w7hy5wh1.js} +1 -1
- package/dist/chunk-w7vhgbhr.js +1 -0
- package/dist/{chunk-cp7xsjj2.js → chunk-wyhyw9rq.js} +2 -2
- package/dist/{chunk-m4wnqx0e.js → chunk-x2wsb8w2.js} +2 -2
- package/dist/{chunk-hpjnk87v.js → chunk-x3cxmwnz.js} +1 -1
- package/dist/{chunk-1wgese5c.js → chunk-x6m0h59v.js} +1 -1
- package/dist/chunk-xm8nyj5z.js +2 -0
- package/dist/chunk-z8ddwve9.js +1 -0
- package/dist/{chunk-rej5bbbs.js → chunk-z9gd9spf.js} +1 -1
- package/dist/{chunk-anez8ekm.js → chunk-zc7snr6f.js} +2 -2
- package/dist/web/assets/{ChatView-C5kVDWL0.js → ChatView-_4ut_-Jh.js} +16 -16
- package/dist/web/assets/{CodeBlockHighlighter-BxJu15oF.js → CodeBlockHighlighter-DkDr6wE9.js} +1 -1
- package/dist/web/assets/{FilePreview-BDNq89O6.js → FilePreview-DCI-oqhJ.js} +1 -1
- package/dist/web/assets/{KanbanBoard-CCn0j1Ow.js → KanbanBoard-CB5C4tJC.js} +1 -1
- package/dist/web/assets/{MarkdownRenderer-15FrKNPV.js → MarkdownRenderer-ychfmIQK.js} +3 -3
- package/dist/web/assets/{SettingsModal-DCL04xT_.js → SettingsModal-SSdk0Bjr.js} +1 -1
- package/dist/web/assets/{TaskSwitcher-Gyn_K98p.js → TaskSwitcher-EnaUhn3o.js} +1 -1
- package/dist/web/assets/{TerminalPanel-Cbh0NmHM.js → TerminalPanel-BcWxLSV3.js} +1 -1
- package/dist/web/assets/{arrow-left-wfNAFD9Y.js → arrow-left-Ob5r20g7.js} +1 -1
- package/dist/web/assets/{calendar-clock-BbbqqtLj.js → calendar-clock-eOALT8DB.js} +1 -1
- package/dist/web/assets/{chevrons-up-down-uCUY_a67.js → chevrons-up-down-BkZBwmbt.js} +1 -1
- package/dist/web/assets/{clock-3-DfiIeEEf.js → clock-3-DQp9SzYc.js} +1 -1
- package/dist/web/assets/{external-link-CilEshFB.js → external-link-BuGUowPD.js} +1 -1
- package/dist/web/assets/{folder-D9K0ykgI.js → folder-c92kw1oI.js} +1 -1
- package/dist/web/assets/{index-BKBXGV6s.js → index-CS8jtO_A.js} +16 -16
- package/dist/web/assets/{pause-D4a4_iHl.js → pause-DP_CXoH7.js} +1 -1
- package/dist/web/assets/{play-D9guMjPv.js → play-DcRwtohz.js} +1 -1
- package/dist/web/assets/{session-events-DelJesUm.js → session-events-CrAgnaj2.js} +1 -1
- package/dist/web/assets/{teamService-CAVeS_dL.js → teamService-JyVbGQhi.js} +1 -1
- package/dist/web/index.html +2 -2
- package/package.json +1 -1
- package/dist/chunk-00rps629.js +0 -2
- package/dist/chunk-4t3h306m.js +0 -6
- package/dist/chunk-9018357g.js +0 -1
- package/dist/chunk-a8mgzsh7.js +0 -1
- package/dist/chunk-c3zcqqb7.js +0 -1
- package/dist/chunk-cwnaydst.js +0 -1
- package/dist/chunk-d7rg6t0n.js +0 -1
- package/dist/chunk-gdp02sqp.js +0 -1
- package/dist/chunk-kfmh3t1r.js +0 -1
- package/dist/chunk-kvdk0pfk.js +0 -1
- package/dist/chunk-maebpz1j.js +0 -2
- package/dist/chunk-n4cw6vt1.js +0 -1
- package/dist/chunk-p7t010gq.js +0 -1
- package/dist/chunk-ryemn19e.js +0 -10
- package/dist/chunk-xy5fmskp.js +0 -1
- package/dist/chunk-y3anmree.js +0 -1
- package/dist/chunk-yx4802a0.js +0 -2
- package/dist/chunk-zy6vm5jm.js +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{pi as r}from"./chunk-n7mzxa8h.js";import{Ni as d,Pi as x,Ri as j,Vi as u,Wi as i}from"./chunk-tgdhsm5t.js";import{Xi as I}from"./chunk-fhfzdyba.js";import{stat as a}from"node:fs/promises";import B from"node:path";import*as U from"node:path";var e=50,__=100,E_=new Set(["queued","running","completed","failed","cancelled","interrupted"]),R_=new Set(["high","medium","low"]),W_=/^[A-Za-z0-9_-]+$/,$_=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?(?:Z|[+-]\d{2}:\d{2})$/;function H_(_){return typeof _==="string"&&$_.test(_)&&Number.isFinite(Date.parse(_))}function v(_){return typeof _==="string"&&U.isAbsolute(_)}function M_(_){return Buffer.from(JSON.stringify(_),"utf8").toString("base64url")}function Q_(_){try{if(!W_.test(_))throw Error("invalid");let E=Buffer.from(_,"base64url").toString("utf8");if(Buffer.from(E,"utf8").toString("base64url")!==_)throw Error("invalid");let R=JSON.parse(E);if(R.version!==1||typeof R.includeSubagents!=="boolean"||R.archived!==void 0&&typeof R.archived!=="boolean"||!(R.cwd===null||v(R.cwd))||!H_(R.lastMessageTime)||!v(R.projectPath)||!x(R.sessionId))throw Error("invalid");return{version:1,cwd:R.cwd===null?null:U.resolve(R.cwd),includeSubagents:R.includeSubagents,archived:R.archived??!1,lastMessageTime:R.lastMessageTime,projectPath:U.resolve(R.projectPath),sessionId:R.sessionId}}catch{throw Error("Invalid session cursor")}}function J(_){let E="";for(let R=0;R<_.length;R+=1)E+=_.charCodeAt(R).toString(16).padStart(4,"0");return E}function V_(_){if(!_.cursor)return;let E=Q_(_.cursor);if(E.cwd!==_.cwd||E.includeSubagents!==_.includeSubagents||(E.archived??!1)!==_.archived)throw Error("Session cursor scope does not match this query");return E}function O_(_={}){let{cwd:E,cursor:R,limit:W,includeSubagents:$=!1,archived:M=!1}=_;if(E!==void 0&&!U.isAbsolute(E))throw Error("Session catalog cwd must be absolute");let H=W===void 0?e:W;if(!Number.isInteger(H)||H<1||H>__)throw Error("Session catalog limit must be an integer from 1 to 100");return{cwd:E===void 0?null:U.resolve(E),cursor:R??void 0,limit:H,includeSubagents:$,archived:M}}function N_(_={}){let E=c(_.taskStatus,E_,"task status"),R=c(_.taskPriority,R_,"task priority"),W=S(_.taskDueAfter,"taskDueAfter"),$=S(_.taskDueBefore,"taskDueBefore");return X_(W,$),{...E?{taskStatuses:E}:{},...R?{taskPriorities:R}:{},...W?{taskDueAfter:W}:{},...$?{taskDueBefore:$}:{}}}function c(_,E,R){if(_===void 0)return;let W=Array.isArray(_)?_:[_];if(W.length===0)return;let $=new Set;for(let M of W){if(typeof M!=="string"||!E.has(M))throw Error(`Invalid session ${R} filter`);$.add(M)}return[...$].sort()}function S(_,E){if(_===void 0)return;if(typeof _!=="string"||!Number.isFinite(Date.parse(_)))throw Error(`Invalid session ${E} filter`);return new Date(_).toISOString()}function X_(_,E){if(_!==void 0&&E!==void 0&&_>E)throw Error("Session task due range is inverted")}function Y_(_,E){if(_.lastMessageTime>E.lastMessageTime)return-1;if(_.lastMessageTime<E.lastMessageTime)return 1;if(_.projectPath<E.projectPath)return-1;if(_.projectPath>E.projectPath)return 1;if(_.sessionId<E.sessionId)return-1;if(_.sessionId>E.sessionId)return 1;return 0}function f_(_,E){let R=[..._],W=V_(E);if(W)R=R.filter((H)=>Y_(H,{sessionId:W.sessionId,projectPath:W.projectPath,lastMessageTime:W.lastMessageTime})>0);let $=R.slice(0,E.limit);if($.length===0||R.length<=$.length)return{sessions:$};let M=$[$.length-1];return{sessions:$,nextCursor:M_({version:1,cwd:E.cwd,includeSubagents:E.includeSubagents,archived:E.archived,lastMessageTime:M.lastMessageTime,projectPath:M.projectPath,sessionId:M.sessionId})}}function G_(_){return _.type==="message_created"||_.type==="token_budget_handoff_recorded"||_.type==="part_created"||_.type==="part_updated"||_.type==="turn_started"||_.type==="turn_completed"||_.type==="turn_aborted"||_.type==="turn_recovery_acknowledged"||_.type==="interaction_requested"||_.type==="interaction_responded"||_.type==="interaction_recovered"||_.type==="review_started"||_.type==="review_completed"}function O(_){return _.type==="message_created"&&_.data.role==="user"&&(_.data.inboxMessageId!==void 0||_.data.parentMessageId===void 0)}function N(_,E){let R=_.find((W)=>O(W)&&W.data.messageId===E);if(!R)throw Error(`Rewind checkpoint not found: ${E}`);return{messageId:E,preview:m(_,E),createdAt:R.data.createdAt}}function m(_,E){let R=_.flatMap((W)=>{if(W.type!=="part_created"||W.data.messageId!==E)return[];if(W.data.partType==="text"){let $=W.data.payload;return typeof $.text==="string"?[$.text]:[]}if(W.data.partType==="image")return["[Image]"];return[]}).join("").trim();if(R.length<=160)return R;return`${R.slice(0,160)}...`}function h(_,E){N(_,E);let R=_.findIndex((H)=>H.type==="message_created"&&H.data.messageId===E),W=_[R],$=W?.type==="message_created"?W.data.inboxMessageId:void 0,M=new Set(_.flatMap((H)=>H.type==="turn_started"&&$&&H.data.inputMessageIds?.includes($)?[H.data.turnId]:[]));return _.filter((H,Q)=>{if((H.type==="turn_started"||H.type==="turn_completed"||H.type==="turn_aborted"||H.type==="turn_recovery_acknowledged")&&M.has(H.data.turnId))return!1;return Q<R||!G_(H)})}function w(_){let E=[];for(let R of _){if(R.type!=="session_rewound"){E.push(R);continue}if(N(E,R.data.targetMessageId),R.data.mode!=="code")E=h(E,R.data.targetMessageId)}return E}function j_(_){let E=w(_);return E.filter(O).map((R)=>({messageId:R.data.messageId,preview:m(E,R.data.messageId),createdAt:R.data.createdAt})).reverse()}function u_(_,E){let R=w(_),W=N(R,E),$=R.findIndex((H)=>H.type==="message_created"&&H.data.messageId===E),M=R.slice($);return{checkpoint:W,projectedEntries:h(R,E),removedTurns:M.filter(O).length,snapshotMessageIds:M.flatMap((H)=>H.type==="part_created"&&H.data.partType==="tool_call"?[H.data.partId]:[])}}import*as z from"node:fs";import{createReadStream as g_}from"node:fs";import*as X from"node:fs/promises";import*as f from"node:path";import{createInterface as T_}from"node:readline";var b=65536;function D(_){let E=_.data;if(E===null||typeof E!=="object"||Array.isArray(E))throw Error("Session event data must be a JSON object");return JSON.stringify(_)}function Z_(_,E,R){let W=_.trim();if(!W)return;try{return JSON.parse(W)}catch($){throw Error(`Invalid session JSONL in ${R} at line ${E}`,{cause:$})}}function y(_,E="session transcript"){let R=_.split(`
|
|
2
2
|
`),W=!_.endsWith(`
|
|
3
3
|
`),$=[];for(let[M,H]of R.entries())try{let Q=Z_(H,M+1,E);if(Q){if(typeof Q.seq!=="number")Q.seq=$.length+1;$.push(Q)}}catch(Q){if(W&&M===R.length-1)break;throw Q}return $}class G{static appendQueues=new Map;filePath;constructor(_){this.filePath=_}static maxSeq(_){let E=0;for(let R of _)if(typeof R.seq==="number"&&R.seq>E)E=R.seq;return E}static stampSeqFrom(_,E){let R=E;return _.map((W)=>{if(typeof W.seq==="number"){if(W.seq>R)R=W.seq;return W}return R+=1,{...W,seq:R}})}static stampSeq(_,E){return G.stampSeqFrom(_,G.maxSeq(E))}async append(_){try{let[E]=await this.appendEntries([_]);return E}catch(E){throw console.error(`[JSONLStore] 追加写入失败: ${this.filePath}`,E),E}}async appendBatch(_){try{return await this.appendEntries(_)}catch(E){throw console.error(`[JSONLStore] 批量追加写入失败: ${this.filePath}`,E),E}}async appendEntries(_){if(_.length===0)return[];return this.enqueue(async()=>{await X.mkdir(f.dirname(this.filePath),{recursive:!0,mode:493});let E=await X.open(this.filePath,"a+",384);try{let R=await this.repairIncompleteTail(E),W=await this.readTailSeq(E),$=G.stampSeqFrom(_,W),M=`${$.map(D).join(`
|
|
4
4
|
`)}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{P as I}from"./chunk-
|
|
1
|
+
import{P as I}from"./chunk-terw7qdx.js";import{Qd as M}from"./chunk-rx2eax1g.js";import P from"node:path";function w(s){let a=s.replace(/\s+/g," ").trim();return a.length<=72?a:`${a.slice(0,69)}...`}function W(s){let a=s.replace(/\s+/g," ").trim();return a.length<=500?a:`${a.slice(0,497)}...`}function A(s){return`task/${s.replace(/[^a-zA-Z0-9_-]/g,"-").slice(0,40)}`}class C{static async createSessionTask(s){if(!s.prompt.trim())throw Error("Task prompt must not be blank");if(!P.isAbsolute(s.sourceProjectPath))throw Error("Task source project path must be absolute");let a=P.resolve(s.sourceProjectPath),t;try{return t=s.isolation==="worktree"?await I.enter({sessionId:s.sessionId,workspaceRoot:a,name:A(s.sessionId)}):void 0,{metadata:await M.createSessionMetadata(s.sessionId,t?.workspaceRoot??a,{title:s.title?.trim()||w(s.prompt),taskPromptSummary:W(s.prompt),taskPriority:s.taskPriority,taskKind:s.taskKind,taskDueAt:s.taskDueAt,taskDispatch:s.dispatch,taskModelId:s.dispatch?.modelId,selectedModelId:s.dispatch?.modelId,permissionMode:s.dispatch?.permissionMode,reasoningEffort:s.dispatch?.reasoningEffort,serviceTier:s.dispatch?.serviceTier,responseVerbosity:s.dispatch?.responseVerbosity,communicationStyle:s.dispatch?.communicationStyle,communicationStyleDigest:s.dispatch?.communicationStyleDigest,projectInstructionsDigest:s.dispatch?.projectInstructionsDigest,taskRetriedFrom:s.retriedFrom,taskIsolation:s.isolation,taskSourceProjectPath:a,taskWorktree:t}),taskWorktree:t}}catch(k){if(t)await I.exit({sessionId:s.sessionId,action:"remove",discardChanges:!0}).catch(()=>{return});throw k}}}var $=256,V=8388608,x=30000;class i extends Error{kind;pendingItems;pendingBytes;constructor(s,a,t){super(a,t);this.kind=s;this.name="BoundedSerialEgressError",this.pendingItems=t?.pendingItems,this.pendingBytes=t?.pendingBytes}}function T(s){s.catch(()=>{return})}class K{options;pending=[];flushWaiters=[];pendingBytes=0;nextSequence=0;completedSequence=0;draining=!1;closed=!1;failure;activeWriteAbort;activeWriteStop;activeWriteTimeout;constructor(s){this.options=s;if(this.assertPositiveInteger(s.maxPendingItems,"maxPendingItems"),this.assertPositiveInteger(s.maxPendingBytes,"maxPendingBytes"),this.assertPositiveInteger(s.writeTimeoutMs,"writeTimeoutMs"),s.signal?.addEventListener("abort",this.handleAbort,{once:!0}),s.signal?.aborted)this.handleAbort()}offer(s){if(this.closed)return{accepted:!1,error:this.failure??new i("closed","Egress is already closed")};let a;try{a=this.options.sizeOf(s)}catch(h){return this.rejectAdmission(new i("invalid_size","Egress size calculation failed",{cause:h}))}if(!Number.isSafeInteger(a)||a<0)return this.rejectAdmission(new i("invalid_size","Egress size must be a non-negative safe integer"));if(a>this.options.maxPendingBytes)return this.rejectAdmission(new i("oversized",`Egress value requires ${a} bytes; limit is ${this.options.maxPendingBytes}`));if(this.pending.length>=this.options.maxPendingItems||this.pendingBytes+a>this.options.maxPendingBytes)return this.rejectAdmission(new i("overflow",`Egress pending limit exceeded (${this.pending.length} items, ${this.pendingBytes} bytes)`));let t,k,c=new Promise((h,m)=>{t=h,k=m});return T(c),this.nextSequence+=1,this.pending.push({value:s,bytes:a,sequence:this.nextSequence,resolve:t,reject:k,completion:c}),this.pendingBytes+=a,this.startDrain(),{accepted:!0,completion:c}}flush(){if(this.failure){let c=Promise.reject(this.failure);return T(c),c}let s=this.nextSequence;if(s<=this.completedSequence)return Promise.resolve();let a,t,k=new Promise((c,h)=>{a=c,t=h});return T(k),this.flushWaiters.push({targetSequence:s,resolve:a,reject:t}),k}close(s){let a=s instanceof i?s:new i("closed","Egress was closed",{cause:s});this.fail(a)}stats(){return{closed:this.closed,pendingItems:this.pending.length,pendingBytes:this.pendingBytes}}handleAbort=()=>{this.fail(new i("aborted","Egress was aborted",{cause:this.options.signal?.reason}))};rejectAdmission(s){return this.fail(s),{accepted:!1,error:s}}startDrain(){if(this.draining||this.closed)return;this.draining=!0;let s=this.drain();T(s)}async drain(){try{while(!this.closed){let s=this.pending[0];if(!s)return;try{await this.writeOne(s.value)}catch(a){this.fail(this.normalizeWriteError(a));return}if(this.closed||this.pending[0]!==s)return;this.pending.shift(),this.pendingBytes-=s.bytes,this.completedSequence=s.sequence,s.resolve(),this.settleFlushWaiters()}}finally{if(this.draining=!1,!this.closed&&this.pending.length>0)this.startDrain()}}async writeOne(s){let a=new AbortController;this.activeWriteAbort=a;let t,k,c=new Promise((S,f)=>{k=f});T(c),this.activeWriteStop=k;let h=Promise.resolve().then(()=>this.options.write(s,a.signal));T(h);let m=new Promise((S,f)=>{t=setTimeout(()=>{let D=new i("write_timeout",`Egress write timed out after ${this.options.writeTimeoutMs}ms`);a.abort(D),f(D)},this.options.writeTimeoutMs),this.activeWriteTimeout=t});T(m);try{await Promise.race([h,m,c])}finally{if(t!==void 0)clearTimeout(t);if(this.activeWriteTimeout===t)this.activeWriteTimeout=void 0;if(this.activeWriteAbort===a)this.activeWriteAbort=void 0;if(this.activeWriteStop===k)this.activeWriteStop=void 0}}normalizeWriteError(s){if(s instanceof i)return s;return new i("write_failed","Egress write failed",{cause:s})}fail(s){if(this.closed)return;if(s.pendingItems??=this.pending.length,s.pendingBytes??=this.pendingBytes,this.closed=!0,this.failure=s,this.options.signal?.removeEventListener("abort",this.handleAbort),this.activeWriteTimeout!==void 0)clearTimeout(this.activeWriteTimeout),this.activeWriteTimeout=void 0;this.activeWriteAbort?.abort(s),this.activeWriteStop?.(s),this.activeWriteAbort=void 0,this.activeWriteStop=void 0;let a=this.pending.splice(0);this.pendingBytes=0;for(let t of a)t.reject(s);for(let t of this.flushWaiters.splice(0))t.reject(s);try{this.options.onFailure?.(s)}catch{}}settleFlushWaiters(){for(let s=0;s<this.flushWaiters.length;){let a=this.flushWaiters[s];if(a.targetSequence>this.completedSequence){s+=1;continue}this.flushWaiters.splice(s,1),a.resolve()}}assertPositiveInteger(s,a){if(!Number.isSafeInteger(s)||s<=0)throw RangeError(`${a} must be a positive safe integer`)}}
|
|
2
2
|
export{C as v,$ as w,V as x,x as y,i as z,K as A};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{Dh as Q,Eh as X,Fh as U,Gh as Z}from"./chunk-f3426b1c.js";import{Hh as N,Ih as h,Kh as d}from"./chunk-c475tfqf.js";import{pi as a}from"./chunk-n7mzxa8h.js";import{Vi as i}from"./chunk-tgdhsm5t.js";var b=[{min:0,max:59},{min:0,max:23},{min:1,max:31},{min:1,max:12},{min:0,max:7}],T={Sun:0,Mon:1,Tue:2,Wed:3,Thu:4,Fri:5,Sat:6},E=new Map;function D($,J,K){let B=new Set;for(let W of $.split(",")){let[Y,O]=W.split("/"),V=O?Number.parseInt(O,10):1;if(!Number.isInteger(V)||V<1)throw Error(`Invalid cron step in "${$}"`);let j=J,H=K;if(Y!=="*"&&Y!=="")if(Y.includes("-")){let[k,r]=Y.split("-");j=Number.parseInt(k,10),H=Number.parseInt(r,10)}else j=Number.parseInt(Y,10),H=j;if(!Number.isInteger(j)||!Number.isInteger(H)||j<J||H>K||j>H)throw Error(`Invalid cron range "${Y}" in field "${$}"`);for(let k=j;k<=H;k+=V)B.add(k)}return B}function R($){let J=$.trim().split(/\s+/);if(J.length!==5)throw Error(`Cron expression must have 5 fields (min hour dom mon dow), got ${J.length}`);let[K,B,W,Y,O]=J,V=D(O,b[4].min,b[4].max),j=new Set([...V].map((H)=>H===7?0:H));return{minutes:D(K,b[0].min,b[0].max),hours:D(B,b[1].min,b[1].max),daysOfMonth:D(W,b[2].min,b[2].max),months:D(Y,b[3].min,b[3].max),daysOfWeek:j,domRestricted:W.trim()!=="*",dowRestricted:O.trim()!=="*"}}function y($,J){if(!J)return{minute:$.getMinutes(),hour:$.getHours(),dayOfMonth:$.getDate(),month:$.getMonth()+1,dayOfWeek:$.getDay()};let K=E.get(J);if(!K)K=new Intl.DateTimeFormat("en-US",{timeZone:J,month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",weekday:"short",hourCycle:"h23"}),E.set(J,K);let B=Object.fromEntries(K.formatToParts($).filter((W)=>W.type!=="literal").map((W)=>[W.type,W.value]));return{minute:Number(B.minute),hour:Number(B.hour),dayOfMonth:Number(B.day),month:Number(B.month),dayOfWeek:T[B.weekday]??-1}}function p($,J,K){let B=y(J,K);if(!$.minutes.has(B.minute))return!1;if(!$.hours.has(B.hour))return!1;if(!$.months.has(B.month))return!1;let W=$.daysOfMonth.has(B.dayOfMonth),Y=$.daysOfWeek.has(B.dayOfWeek);if($.domRestricted&&$.dowRestricted)return W||Y;if($.domRestricted)return W;if($.dowRestricted)return Y;return!0}function e($,J,K){let B=R($),W=new Date(J.getTime());W.setSeconds(0,0),W.setMinutes(W.getMinutes()+1);let Y=new Date(J.getTime());Y.setFullYear(Y.getFullYear()+4);while(W.getTime()<=Y.getTime()){if(p(B,W,K))return new Date(W.getTime());W.setMinutes(W.getMinutes()+1)}return null}var S={s:1000,m:60000,h:3600000,d:86400000};function F1($){let K=$.trim().toLowerCase().match(/^(\d+)\s*([smhd]?)$/);if(!K)return null;let B=Number.parseInt(K[1],10);if(!Number.isInteger(B)||B<=0)return null;let W=K[2]||"m";return B*S[W]}function Q1($){for(let J of["d","h","m","s"]){let K=S[J];if($%K===0)return`${$/K}${J}`}return`${Math.round($/1000)}s`}function F($,J,K){switch($.kind){case"cron":{if(!$.cron)return null;try{return e($.cron,J,$.timezone)}catch{return null}}case"interval":{if(!$.intervalMs||$.intervalMs<=0)return null;let W=new Date((K??J).getTime()+$.intervalMs);return W.getTime()<=J.getTime()?new Date(J.getTime()+1000):W}case"once":{if(!$.runAt)return null;let B=new Date($.runAt);if(Number.isNaN(B.getTime()))return null;return B.getTime()>J.getTime()?B:null}default:return null}}function z($){switch($.kind){case"cron":if(!$.cron)return"cron trigger requires a cron expression";try{if(R($.cron),$.timezone)new Intl.DateTimeFormat("en-US",{timeZone:$.timezone}).format();return null}catch(J){return J instanceof Error?J.message:"invalid cron expression"}case"interval":if(!$.intervalMs||$.intervalMs<60000)return"interval trigger requires intervalMs >= 60000 (1 minute)";return null;case"once":{if(!$.runAt)return"once trigger requires runAt timestamp";let J=new Date($.runAt);if(Number.isNaN(J.getTime()))return"once trigger runAt is not a valid date";return null}default:return"unknown trigger kind"}}function z1($){switch($.kind){case"cron":return`cron: ${$.cron??"?"}`;case"interval":return`every ${$.intervalMs?Q1($.intervalMs):"?"}`;case"once":return`once at ${$.runAt??"?"}`;default:return"unknown"}}import{mkdir as P1,readFile as I1}from"node:fs/promises";import t from"node:path";import{nanoid as L1}from"nanoid";import D1 from"write-file-atomic";var l=16384;function v1($){let J=/^\s*\/btw(?:\s+([\s\S]*))?\s*$/iu.exec($);if(!J)return;return{question:(J[1]??"").trim()}}var w=X(Z(["default","autoEdit","yolo","plan"]));var v=X(Z(["user","assistant","system","tool"])),$1=X(Q.Union([Q.Object({type:Q.Literal("text"),text:Q.String()}),Q.Object({type:Q.Literal("image_url"),image_url:Q.Object({url:Q.String()})})])),m=Q.Union([Q.String(),Q.Array($1)]),R1=X(Q.Object({id:Q.String(),role:v,content:m,timestamp:Q.Number(),metadata:Q.Optional(Q.Record(Q.String(),Q.Unknown())),thinkingContent:Q.Optional(Q.String()),tool_call_id:Q.Optional(Q.String()),name:Q.Optional(Q.String()),tool_calls:Q.Optional(Q.Unknown())})),J1=X(Z(["queued","running","completed","failed","cancelled","interrupted"])),A=X(Z(["local","worktree"])),x=X(Z(["high","medium","low"])),C=X(Z(["feature","bug","maintenance","research"])),X1=X(Z(["applied","discarded","conflicted"])),Z1=X(Q.Object({status:X1,updatedAt:Q.String(),sourceCommit:Q.Optional(Q.String()),changedFiles:Q.Optional(Q.Integer({minimum:0})),message:Q.Optional(Q.String())})),B1=X(Q.Object({changedFiles:Q.Integer({minimum:0}),additions:Q.Integer({minimum:0}),deletions:Q.Integer({minimum:0}),commits:Q.Integer({minimum:0})})),K1=X(Q.Object({path:Q.String({minLength:1}),patch:Q.String({maxLength:2097152}),additions:Q.Integer({minimum:0}),deletions:Q.Integer({minimum:0}),binary:Q.Boolean(),truncated:Q.Boolean()})),S1=X(Q.Object({sessionId:Q.String(),projectPath:Q.String(),baseCommit:Q.String(),files:Q.Array(K1,{maxItems:100}),truncated:Q.Boolean()})),W1=Q.Union([Q.String(),Q.Number(),Q.Boolean(),Q.Array(Q.String())]),Y1=X(Q.Object({name:Q.String(),type:Z(["string","number","integer","boolean","select","multi-select"]),title:Q.String(),description:Q.Optional(Q.String()),required:Q.Boolean(),defaultValue:Q.Optional(W1),options:Q.Optional(Q.Array(Q.Object({value:Q.String(),label:Q.String()}))),format:Q.Optional(Z(["date","uri","email","date-time"])),minimum:Q.Optional(Q.Number()),maximum:Q.Optional(Q.Number()),minLength:Q.Optional(Q.Number()),maxLength:Q.Optional(Q.Number()),minItems:Q.Optional(Q.Number()),maxItems:Q.Optional(Q.Number())})),l1=X(Q.Object({serverName:Q.String(),mode:Z(["form","url"]),message:Q.String(),fields:Q.Optional(Q.Array(Y1)),requestedSchema:Q.Optional(Q.Record(Q.String(),Q.Unknown())),url:Q.Optional(Q.String()),domain:Q.Optional(Q.String()),elicitationId:Q.Optional(Q.String())})),H1=X(Q.Object({type:Z(["permission","question","elicitation"]),requestId:Q.String()})),j1=X(Q.Object({code:Z(["authentication","permission","rate_limit","timeout","network","model_unavailable","context_limit","unsupported_input","workspace_unavailable","capacity","runtime"]),message:Q.String({minLength:1,maxLength:500}),retryable:Q.Boolean(),resource:Q.Optional(Z(["pending_count","pending_bytes","resident_runtimes"]))})),M=X(Z(["auto","off","minimal","low","medium","high","xhigh","max"])),P=X(Z(["auto","standard","fast","flex"])),I=X(Z(["auto","low","medium","high"])),G=X(Q.Union([Z(["auto","pragmatic","friendly","explanatory"]),Q.String({minLength:7,maxLength:300,pattern:"^(?:(?:user|project):[a-z0-9][a-z0-9._-]{0,63}(?::[a-z0-9][a-z0-9._-]{0,63}){0,3}|plugin:[a-z0-9][a-z0-9._-]{0,63}:[a-z0-9][a-z0-9._-]{0,63}(?::[a-z0-9][a-z0-9._-]{0,63}){0,3})$"})])),_=X(Q.Object({sessionId:Q.String(),projectPath:Q.String(),title:Q.Optional(Q.String()),gitBranch:Q.Optional(Q.String()),rootId:Q.String(),parentId:Q.Optional(Q.String()),relationType:Q.Optional(Z(["subagent","fork"])),resumedFrom:Q.Optional(Q.String()),rootAgentId:Q.Optional(Q.String()),resumeDepth:Q.Optional(Q.Integer({minimum:0})),taskStatus:U(J1,"completed"),taskStatusReason:Q.Optional(Q.String()),taskFailure:Q.Optional(j1),taskStartedAt:Q.Optional(Q.String()),taskCompletedAt:Q.Optional(Q.String()),taskPromptSummary:Q.Optional(Q.String()),taskPriority:Q.Optional(x),taskKind:Q.Optional(C),taskDueAt:Q.Optional(Q.String()),taskModelId:Q.Optional(Q.String()),selectedModelId:Q.Optional(Q.String()),permissionMode:Q.Optional(w),reasoningEffort:Q.Optional(M),serviceTier:Q.Optional(P),responseVerbosity:Q.Optional(I),communicationStyle:Q.Optional(G),communicationStyleDigest:Q.Optional(Q.String({pattern:"^[a-f0-9]{64}$"})),projectInstructionsDigest:Q.Optional(Q.String({pattern:"^[a-f0-9]{64}$"})),taskRetryAvailable:Q.Optional(Q.Boolean()),taskRetriedFrom:Q.Optional(Q.Object({sessionId:Q.String(),projectPath:Q.String()})),taskDelivery:Q.Optional(Z1),taskIsolation:Q.Optional(A),taskSourceProjectPath:Q.Optional(Q.String()),taskWorktreePath:Q.Optional(Q.String()),taskWorktreeBranch:Q.Optional(Q.String()),taskBaseCommit:Q.Optional(Q.String()),taskDiffStat:Q.Optional(B1),taskQueuePosition:Q.Optional(Q.Integer({minimum:1})),taskQueueDepth:Q.Optional(Q.Integer({minimum:0})),taskConcurrencyLimit:Q.Optional(Q.Integer({minimum:1})),archivedAt:Q.Optional(Q.String()),archivedBySessionId:Q.Optional(Q.String()),pendingInteraction:Q.Optional(H1),messageCount:Q.Number(),firstMessageTime:Q.String(),lastMessageTime:Q.String(),hasErrors:Q.Boolean()})),u1=X(Q.Object({sessions:Q.Array(_),nextCursor:Q.Optional(Q.String())})),h1=X(Q.Object({session:_,archivedSessionIds:Q.Array(Q.String())})),d1=X(Q.Object({session:_,restoredSessionIds:Q.Array(Q.String())})),m1=X(Q.Object({version:Q.Union([Q.Literal(1),Q.Literal(2)]),sessionId:Q.String(),goalId:Q.String(),objective:Q.String(),status:Z(["active","verifying","paused","blocked","usage_limited","budget_limited","complete"]),tokenBudget:Q.Optional(Q.Number()),tokensUsed:Q.Number(),timeUsedSeconds:Q.Number(),continuationCount:Q.Number(),statusReason:Q.Optional(Q.String()),completionVerification:Q.Optional(Q.Object({attempt:Q.Integer({minimum:1}),status:Z(["pending","pass","fail","partial"]),requestedAt:Q.String(),completedAt:Q.Optional(Q.String()),verifierSessionId:Q.Optional(Q.String()),summary:Q.Optional(Q.String()),evidenceSha256:Q.Optional(Q.String({pattern:"^[a-f0-9]{64}$"}))})),prematureStop:Q.Optional(Q.Object({pattern:Q.Unsafe({type:"string"}),consecutiveCount:Q.Integer({minimum:1}),detectedAt:Q.String()})),verificationStall:Q.Optional(Q.Unsafe({type:"object"})),executionFrontier:Q.Optional(Q.Object({taskListId:Q.String({minLength:1,maxLength:256}),total:Q.Integer({minimum:0}),completed:Q.Integer({minimum:0}),inProgress:Q.Integer({minimum:0}),pending:Q.Integer({minimum:0}),blocked:Q.Integer({minimum:0}),nextTask:Q.Optional(Q.Object({id:Q.String({minLength:1}),subject:Q.String({minLength:1,maxLength:512}),priority:Z(["high","medium","low"])})),digestSha256:Q.String({pattern:"^[a-f0-9]{64}$"}),observedAt:Q.String()})),frontierStall:Q.Optional(Q.Object({category:Z(["waiting_dependency","same_task_no_effect","repeated_deferral"]),consecutiveCount:Q.Integer({minimum:1,maximum:3}),digestSha256:Q.String({pattern:"^[a-f0-9]{64}$"}),detectedAt:Q.String()})),createdAt:Q.String(),updatedAt:Q.String()})),c=X(Q.Object({role:v,content:m,metadata:Q.Optional(Q.Unknown()),reasoningContent:Q.Optional(Q.String()),thinkingContent:Q.Optional(Q.String()),tool_call_id:Q.Optional(Q.String()),name:Q.Optional(Q.String()),tool_calls:Q.Optional(Q.Unknown())})),c1=X(Q.Object({session:_,messages:Q.Array(c)})),n=X(Z(["conversation","code","both"])),U1=X(Q.Object({messageId:Q.String(),preview:Q.String(),createdAt:Q.String(),fileCount:Q.Integer({minimum:0})})),n1=X(Q.Object({targetMessageId:Q.String({minLength:1}),mode:U(n,"conversation")})),g1=X(Q.Object({checkpoint:U1,mode:n,removedTurns:Q.Integer({minimum:1}),restoredFiles:Q.Array(Q.String()),messages:Q.Array(c)})),k1=Z(["running","completed","failed","cancelled"]),u=X(Q.Object({id:Q.String(),subagentType:Q.String(),description:Q.String(),status:k1,background:Q.Boolean(),rootAgentId:Q.String(),resumedFrom:Q.Optional(Q.String()),resumeDepth:Q.Integer({minimum:0}),createdAt:Q.Number(),lastActiveAt:Q.Number(),completedAt:Q.Optional(Q.Number()),restartRecovery:Q.Optional(Q.Object({outcome:Z(["completed","interrupted","failed"]),recoveredAt:Q.Number()})),result:Q.Optional(Q.Object({success:Q.Boolean(),message:Q.String(),error:Q.Optional(Q.String()),verificationCommands:Q.Optional(Q.Array(Q.String())),verificationVerdict:Q.Optional(Z(["pass","fail","partial"])),modifiedFiles:Q.Optional(Q.Array(Q.String()))})),stats:Q.Optional(Q.Object({tokens:Q.Optional(Q.Number()),toolCalls:Q.Optional(Q.Number()),duration:Q.Optional(Q.Number())}))})),o1=X(Q.Object({prompt:Q.String({minLength:1,maxLength:32000,pattern:"\\S"})})),s1=X(Q.Object({source:u,session:u})),i1=X(Q.Object({sessionId:Q.String(),projectPath:Q.String()})),a1=X(Q.Object({path:Q.String(),name:Q.String(),gitBranch:Q.Optional(Q.String()),available:Q.Boolean(),isCurrent:Q.Boolean(),boundAt:Q.String()})),t1=X(Q.Union([Q.Object({cancelled:Q.Literal(!0)}),Q.Object({cancelled:Q.Literal(!1),path:Q.String({minLength:1})})])),r1=X(Q.Object({type:Q.String(),seq:Q.Optional(Q.Number()),properties:Q.Record(Q.String(),Q.Unknown())})),g=Q.Object({type:Z(["file","image","url"]),path:Q.Optional(Q.String()),url:Q.Optional(Q.String()),content:Q.Optional(Q.String({maxLength:h})),mimeType:Q.Optional(Q.String()),name:Q.Optional(Q.String())}),o=Q.Record(Q.String(),Q.Unknown()),T1=X(Q.Object({prompt:Q.String({minLength:1,maxLength:32000,pattern:"\\S"}),title:Q.Optional(Q.String({minLength:1,maxLength:200})),taskPriority:U(x,"medium"),taskKind:U(C,"feature"),taskDueAt:Q.Optional(Q.String({minLength:1,maxLength:64})),projectPath:Q.Optional(Q.String()),modelId:Q.Optional(Q.String({minLength:1,maxLength:500})),reasoningEffort:Q.Optional(M),serviceTier:Q.Optional(P),responseVerbosity:Q.Optional(I),communicationStyle:Q.Optional(G),isolation:U(A,"worktree"),permissionMode:U(w,"default"),attachments:Q.Optional(Q.Array(g,{maxItems:N})),outputSchema:Q.Optional(o)})),y1=X(Q.Object({title:Q.Optional(Q.String({minLength:1,maxLength:200})),taskPriority:Q.Optional(x),taskKind:Q.Optional(C),taskDueAt:Q.Optional(Q.Union([Q.String({minLength:1,maxLength:64}),Q.Null()]))})),p1=X(Q.Object({session:_,runId:Q.String(),messageId:Q.String(),status:Z(["queued","running"]),queuePosition:Q.Optional(Q.Integer({minimum:1})),queueDepth:Q.Optional(Q.Integer({minimum:0})),maxConcurrentTasks:Q.Optional(Q.Integer({minimum:1}))})),e1=X(Q.Object({action:Z(["apply","discard"])})),q=X(Q.Object({kind:Z(["cron","interval","once"]),cron:Q.Optional(Q.String({minLength:1,maxLength:120})),intervalMs:Q.Optional(Q.Integer({minimum:60000})),runAt:Q.Optional(Q.String({minLength:1,maxLength:40})),timezone:Q.Optional(Q.String({minLength:1,maxLength:80}))})),O1=X(Q.Object({modelId:Q.Optional(Q.String({minLength:1,maxLength:500})),reasoningEffort:Q.Optional(M),serviceTier:Q.Optional(P),responseVerbosity:Q.Optional(I),communicationStyle:Q.Optional(G),isolation:U(A,"worktree"),permissionMode:U(w,"default")})),f=X(Q.Object({id:Q.String(),title:Q.Optional(Q.String({minLength:1,maxLength:200})),prompt:Q.String({minLength:1,maxLength:32000,pattern:"\\S"}),projectPath:Q.String({minLength:1}),trigger:q,dispatch:O1,enabled:Q.Boolean(),createdAt:Q.String(),updatedAt:Q.String(),nextRunAt:Q.Union([Q.String(),Q.Null()]),expiresAt:Q.Union([Q.String(),Q.Null()]),lastRunAt:Q.Optional(Q.String()),lastRunSessionId:Q.Optional(Q.String()),lastStatus:Q.Optional(Z(["queued","running","completed","failed","cancelled","interrupted","error"])),lastError:Q.Optional(Q.String()),runCount:Q.Integer({minimum:0})})),QQ=X(Q.Object({title:Q.Optional(Q.String({minLength:1,maxLength:200})),prompt:Q.String({minLength:1,maxLength:32000,pattern:"\\S"}),projectPath:Q.String({minLength:1}),trigger:q,modelId:Q.Optional(Q.String({minLength:1,maxLength:500})),reasoningEffort:Q.Optional(M),serviceTier:Q.Optional(P),responseVerbosity:Q.Optional(I),communicationStyle:Q.Optional(G),isolation:U(A,"worktree"),permissionMode:U(w,"default"),enabled:U(Q.Boolean(),!0)})),$Q=X(Q.Object({title:Q.Optional(Q.String({minLength:1,maxLength:200})),prompt:Q.Optional(Q.String({minLength:1,maxLength:32000,pattern:"\\S"})),trigger:Q.Optional(q),modelId:Q.Optional(Q.String({minLength:1,maxLength:500})),reasoningEffort:Q.Optional(M),serviceTier:Q.Optional(P),responseVerbosity:Q.Optional(I),communicationStyle:Q.Optional(G),isolation:Q.Optional(A),permissionMode:Q.Optional(w),enabled:Q.Optional(Q.Boolean())})),JQ=X(Q.Object({schedules:Q.Array(f)})),XQ=X(Q.Object({content:Q.String({maxLength:d}),projectPath:Q.Optional(Q.String()),modelId:Q.Optional(Q.String({minLength:1,maxLength:500})),reasoningEffort:Q.Optional(M),serviceTier:Q.Optional(P),responseVerbosity:Q.Optional(I),communicationStyle:Q.Optional(G),permissionMode:Q.Optional(w),attachments:Q.Optional(Q.Array(g,{maxItems:N})),outputSchema:Q.Optional(o)})),V1=Z(["completed","failed","aborted","timed_out","spawn_error"]),b1=X(Q.Object({version:Q.Literal(1),command:Q.String(),status:V1,exitCode:Q.Union([Q.Integer(),Q.Null()]),durationMs:Q.Number({minimum:0}),stdout:Q.String(),stderr:Q.String(),stdoutOmittedBytes:Q.Integer({minimum:0}),stderrOmittedBytes:Q.Integer({minimum:0}),binaryOutput:Q.Boolean(),truncated:Q.Boolean()})),ZQ=X(Q.Object({command:Q.String({minLength:1,maxLength:32768,pattern:"^(?![\\s\\S]*\\u0000)(?=[\\s\\S]*\\S)[\\s\\S]*$"}),projectPath:Q.Optional(Q.String())})),BQ=X(Q.Object({executionId:Q.String(),messageId:Q.String(),record:b1,auxiliary:Q.Boolean(),delivery:Q.Optional(Z(["current_turn","next_turn"])),queued:Q.Optional(Q.Integer({minimum:0}))})),KQ=X(Q.Object({question:Q.String({minLength:1,maxLength:l,pattern:"^(?![\\s\\S]*\\x00)(?=[\\s\\S]*\\S)[\\s\\S]*$"}),projectPath:Q.Optional(Q.String())})),WQ=X(Q.Object({response:Q.String({minLength:1}),durationMs:Q.Number({minimum:0}),modelId:Q.Optional(Q.String()),usage:Q.Optional(Q.Object({promptTokens:Q.Number({minimum:0}),completionTokens:Q.Number({minimum:0}),totalTokens:Q.Number({minimum:0}),reasoningTokens:Q.Optional(Q.Number({minimum:0})),cacheCreationInputTokens:Q.Optional(Q.Number({minimum:0})),cacheReadInputTokens:Q.Optional(Q.Number({minimum:0})),costUsd:Q.Optional(Q.Number({minimum:0}))}))})),YQ=X(Q.Object({projectPath:Q.String(),kind:Z(["uncommitted","base","commit"]),ref:Q.Optional(Q.String({maxLength:200})),instructions:Q.Optional(Q.String({maxLength:4000})),modelId:Q.Optional(Q.String({minLength:1,maxLength:200}))})),HQ=X(Q.Object({reviewId:Q.String(),status:Q.Literal("running")})),jQ=X(Q.Object({messageId:Q.String(),role:v,content:Q.String(),timestamp:Q.String()})),UQ=X(Q.Object({approved:Q.Boolean(),remember:Q.Optional(Q.Boolean()),scope:Q.Optional(Z(["once","session","project"])),targetMode:Q.Optional(w),feedback:Q.Optional(Q.String()),answers:Q.Optional(Q.Record(Q.String(),Q.Union([Q.String(),Q.Array(Q.String())]))),elicitation:Q.Optional(Q.Object({action:Z(["accept","decline","cancel"]),content:Q.Optional(Q.Record(Q.String(),Q.Union([Q.String({maxLength:4000}),Q.Number(),Q.Boolean(),Q.Array(Q.String({maxLength:1000}),{maxItems:100})]),{maxProperties:32}))}))})),G1=X(Q.Object({id:G,name:Q.String({minLength:1,maxLength:80}),description:Q.String({minLength:1,maxLength:256}),source:Z(["built-in","user","project","plugin"]),contentSha256:Q.Optional(Q.String({pattern:"^[a-f0-9]{64}$"}))})),kQ=X(Q.Object({id:Q.String(),displayName:Q.Optional(Q.String()),provider:Q.String(),model:Q.String(),contextWindow:Q.Optional(Q.Number()),maxTokens:Q.Optional(Q.Number()),reasoning:Q.Optional(Q.Boolean()),supportedReasoningEfforts:Q.Optional(Q.Array(Z(["off","minimal","low","medium","high","xhigh","max"]))),supportedServiceTiers:Q.Optional(Q.Array(Z(["standard","fast","flex"]))),supportedResponseVerbosities:Q.Optional(Q.Array(Z(["low","medium","high"]))),communicationStyles:Q.Optional(Q.Array(G1,{maxItems:36})),input:Q.Optional(Q.Array(Z(["text","image"]))),overrides:Q.Optional(Q.Object({baseUrl:Q.Optional(Q.String()),temperature:Q.Optional(Q.Number()),maxOutputTokens:Q.Optional(Q.Number()),timeout:Q.Optional(Q.Number()),streamIdleTimeout:Q.Optional(Q.Number({minimum:1000}))}))})),OQ=X(Z(["vs-dark","vs-light","hc-black"])),w1=X(Z(["light","dark","system"])),M1=X(Q.Object({language:Q.String(),codeTheme:Q.String(),uiTheme:w1,autoSaveSessions:Q.Boolean(),notifyBuild:Q.Boolean(),notifyErrors:Q.Boolean(),notifySounds:Q.Boolean(),privacyTelemetry:Q.Boolean(),privacyCrash:Q.Boolean(),agentTeamsEnabled:Q.Boolean(),communicationStyle:Q.Optional(G)})),VQ=X(Q.Partial(M1));var s=a("Service"),A1=1;function _1(){return t.join(i(),"schedules.json")}class L{filePath;static instance;static getInstance(){if(!L.instance)L.instance=new L;return L.instance}writeChain=Promise.resolve();constructor($=_1()){this.filePath=$}async readFile(){try{let $=await I1(this.filePath,"utf-8"),J=JSON.parse($);if(!J||!Array.isArray(J.schedules))return[];let K=[],B=0;for(let W of J.schedules){let Y=f.safeParse(W);if(Y.success)K.push(Y.data);else B+=1}if(B>0)s.warn(`[ScheduleStore] Ignored ${B} invalid persisted schedule(s)`);return K}catch($){let J=$;if(J.code!=="ENOENT")s.warn("[ScheduleStore] Failed to read schedules; treating as empty:",J);return[]}}async writeFile($){await P1(t.dirname(this.filePath),{recursive:!0,mode:493});let J={version:A1,schedules:$};await D1(this.filePath,JSON.stringify(J,null,2),{mode:384})}serializeWrite($){let J=this.writeChain.then($,$);return this.writeChain=J.then(()=>{return},()=>{return}),J}async list(){return this.readFile()}async get($){return(await this.readFile()).find((K)=>K.id===$)}async create($){return this.serializeWrite(async()=>{let J=$.trigger.kind==="cron"&&!$.trigger.timezone?{...$.trigger,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone}:$.trigger,K=z(J);if(K)throw Error(K);let B=new Date;if(J.kind==="once"&&new Date(J.runAt).getTime()<=B.getTime())throw Error("once trigger runAt must be in the future");let W=B.toISOString(),Y=F(J,B),O={id:L1(10),title:$.title,prompt:$.prompt,projectPath:$.projectPath,trigger:J,dispatch:{modelId:$.modelId,reasoningEffort:$.reasoningEffort,serviceTier:$.serviceTier,responseVerbosity:$.responseVerbosity,communicationStyle:$.communicationStyle,isolation:$.isolation??"worktree",permissionMode:$.permissionMode??"default"},enabled:$.enabled??!0,createdAt:W,updatedAt:W,nextRunAt:Y?Y.toISOString():null,expiresAt:null,runCount:0},V=await this.readFile();return V.push(O),await this.writeFile(V),O})}async update($,J){return this.serializeWrite(async()=>{let K=await this.readFile(),B=K.findIndex((H)=>H.id===$);if(B===-1)return;let W=K[B];if(J.trigger){let H=J.trigger.kind==="cron"&&!J.trigger.timezone?{...J.trigger,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone}:J.trigger,k=z(H);if(k)throw Error(k);if(H.kind==="once"&&new Date(H.runAt).getTime()<=Date.now())throw Error("once trigger runAt must be in the future");J={...J,trigger:H}}let Y={...W,...J,dispatch:J.dispatch?{...W.dispatch,...J.dispatch}:W.dispatch,updatedAt:new Date().toISOString()},O=!W.enabled,V=Y.enabled,j=J.trigger!==void 0;if((j||O&&V)&&J.nextRunAt===void 0){let H=new Date,k=F(Y.trigger,H);if(Y.nextRunAt=k?k.toISOString():null,j)Y.expiresAt=null}return K[B]=Y,await this.writeFile(K),Y})}async remove($){return this.serializeWrite(async()=>{let J=await this.readFile(),K=J.filter((B)=>B.id!==$);if(K.length===J.length)return!1;return await this.writeFile(K),!0})}async setEnabled($,J){return this.update($,{enabled:J})}}var NQ=L.getInstance();
|
|
2
|
+
export{l as Ia,v1 as Ja,F1 as Ka,F as La,z as Ma,z1 as Na,S1 as Oa,_ as Pa,n1 as Qa,o1 as Ra,T1 as Sa,y1 as Ta,p1 as Ua,e1 as Va,f as Wa,QQ as Xa,$Q as Ya,JQ as Za,XQ as _a,ZQ as $a,KQ as ab,YQ as bb,L as cb,NQ as db};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{oe as a,pe as b}from"./chunk-scq56220.js";import"./chunk-m5zx8enh.js";import"./chunk-fhfzdyba.js";export{a as globalOptions,b as cliConfig};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{Mh as L,Ph as _}from"./chunk-0hr050ck.js";import{execSync as F}from"child_process";import{existsSync as Q,readFileSync as O,realpathSync as b}from"fs";import*as V from"os";import*as H from"path";import{basename as J,isAbsolute as j,resolve as R}from"path";function G(z=_()){let q=z,M=f(q);return{workingDirectory:q,projectRoot:M,platform:`${V.platform()} (${V.arch()})`,nodeVersion:process.version,currentDate:new Date().toISOString().split("T")[0],homeDirectory:V.homedir()}}function Y(z,q){try{return F(q,{cwd:z,encoding:"utf8",stdio:["pipe","pipe","ignore"]}).trim()}catch{return null}}function v(z={}){let{includeGitSnapshot:q=!0,includeDirectoryListing:M=!0,workingDirectory:W}=z,B=G(W),$=Q(H.join(B.projectRoot,".git")),T=J(process.env.SHELL||"unknown"),A=["package.json","tsconfig.json","BLADE.md",".env.example"].filter((K)=>Q(H.join(B.projectRoot,K))).map((K)=>`- \`${H.join(B.projectRoot,K)}\``),N=`# Environment
|
|
2
2
|
You have been invoked in the following environment:
|
|
3
3
|
- Primary working directory: ${B.workingDirectory}
|
|
4
4
|
- Is a git repository: ${$?"true":"false"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{e as G3,f as U3}from"./chunk-
|
|
1
|
+
import{e as G3,f as U3}from"./chunk-7fz3w4rk.js";import{i as qZ,j as zZ,k as OZ}from"./chunk-32yfgw9s.js";import{u as P2}from"./chunk-epdzdv4e.js";import{C as N6,G as MZ,I as h4,J as f4,K as X6,Q as l9,R as r9,V as E$,X as M9,Y as y9,_ as a9,aa as v8,ba as y3,ca as R3,fa as T3,ga as C3,ka as dJ,la as D6,na as k6,oa as f6,pa as yZ,qa as V9,sa as j9,ua as H6}from"./chunk-terw7qdx.js";import"./chunk-abd57h72.js";import{Ca as cY,Da as dY,Ea as lY,Ha as PZ}from"./chunk-kfcbaj44.js";import{Ja as d9}from"./chunk-xm8nyj5z.js";import{Db as c9,Mb as R4,qb as x9,rb as u9}from"./chunk-0tbdbnyp.js";import{Xb as E8}from"./chunk-8hprmrd5.js";import{Bd as C9,Cd as y4,Dd as I9,Fd as W2,Nd as f8,Qd as f0,ad as E9,pd as b9,ud as P9}from"./chunk-rx2eax1g.js";import"./chunk-s0tq8gyx.js";import"./chunk-x3cxmwnz.js";import{te as GZ}from"./chunk-j2dyprdy.js";import{ue as h8,ve as M2,xe as n$}from"./chunk-vtq52np4.js";import"./chunk-z9gd9spf.js";import{$e as a0,Be as t1,Ce as K$,De as R1,Ee as UJ,Fe as H2,Ge as B9,He as OY,Ie as CJ,Je as eY,Ke as _Y,Le as J8,Me as Y$,Ne as AZ,Oe as G$,Pe as KZ,Qe as Z4,Re as V8,Ue as v9}from"./chunk-mxjsttbc.js";import"./chunk-v508x7cg.js";import"./chunk-dg0d3303.js";import"./chunk-rchz6j90.js";import{pf as IJ}from"./chunk-w7hy5wh1.js";import"./chunk-2hb222re.js";import"./chunk-pkack2dw.js";import{Bf as T2,Ef as m3,Jf as M3,Sf as bZ}from"./chunk-mm762w5r.js";import"./chunk-kf7whgr7.js";import"./chunk-fva7jnjy.js";import"./chunk-41ympwz1.js";import{og as OJ,qg as y$}from"./chunk-jntgg3zj.js";import"./chunk-41cg66y0.js";import{sh as wZ,xh as P3,yh as BZ}from"./chunk-3rpmd93p.js";import"./chunk-sdbbyagy.js";import"./chunk-f3426b1c.js";import{Hh as K8,Ih as L2,Kh as _J}from"./chunk-c475tfqf.js";import{Ph as Z$}from"./chunk-0hr050ck.js";import"./chunk-q69fzq4y.js";import{mi as LZ,pi as y1}from"./chunk-n7mzxa8h.js";import{ri as X3,si as Q3,vi as Q1}from"./chunk-s10pmnrd.js";import"./chunk-9p20hhs0.js";import{Hi as iY}from"./chunk-m5zx8enh.js";import{Ki as cJ}from"./chunk-wyhyw9rq.js";import"./chunk-rvk9r2cm.js";import{Vi as M4}from"./chunk-tgdhsm5t.js";import{Xi as zJ}from"./chunk-fhfzdyba.js";import{useMemoizedFn as H4}from"ahooks";import{useEffect as yK,useState as F4}from"react";import{useMemoizedFn as t0}from"ahooks";import QZ from"ansi-escapes";import{Box as W1,useStdout as LK}from"ink";import{useEffect as L1,useMemo as wK,useRef as n8,useState as BK}from"react";import{useShallow as TZ}from"zustand/react/shallow";import{useStore as RZ}from"zustand";function Z0($){return RZ(J8,$)}var CZ=[],Y8=()=>Z0(($)=>$.session.sessionId),o$=()=>Z0(($)=>$.session.workspaceRoot),$2=()=>Z0(($)=>$.session.messages),lJ=()=>Z0(($)=>$.session.clearCount),rJ=()=>Z0(($)=>$.session.isCompacting),aJ=()=>Z0(($)=>$.session.tokenUsage.estimatedCostUsd),iJ=()=>Z0(($)=>{let{totalInputTokens:J,cacheReadTokens:Z,cacheWriteTokens:Y}=$.session.tokenUsage;return dJ({totalInputTokens:J,cacheReadTokens:Z,cacheWriteTokens:Y}).hitRate}),oJ=()=>Z0(($)=>$.session.providerCircuit),nJ=()=>Z0(($)=>$.session.providerAdmission),tJ=()=>Z0(($)=>$.session.providerRetry),sJ=()=>Z0(($)=>$.session.providerStall),eJ=()=>Z0(($)=>$.session.actionStationarity),P1=()=>Z0(($)=>$.session.actions),$9=()=>Z0(($)=>{let{totalTokens:J,maxContextTokens:Z}=$.session.tokenUsage;if(Z<=0)return 100;let Y=Math.max(0,100-J/Z*100);return Math.round(Y)}),J9=()=>Z0(($)=>$.app.initializationStatus),Y9=()=>Z0(($)=>$.app.initializationError),J2=()=>Z0(($)=>$.app.activeModal),Z9=()=>Z0(($)=>$.app.tasks),X9=()=>Z0(($)=>$.app.modelEditorTarget),Q9=()=>Z0(($)=>$.app.sessionSelectorData),K9=()=>Z0(($)=>$.app.awaitingSecondCtrlC),M1=()=>Z0(($)=>$.app.actions),Y2=()=>Z0(($)=>$.app.sideConversation),G9=()=>Z0(($)=>$.app.teams),Z2=()=>Z0(($)=>$.app.initializationStatus==="ready"),U9=()=>Z0(($)=>$.app.tasks.length>0),Z8=()=>Z0(($)=>$.config.config?.permissionMode||"default"),q9=()=>Z0(($)=>$.config.config?.models??CZ),X2=()=>Z0(($)=>{let J=$.config.config;if(!J)return;let Z=J.currentModelId;return J.models.find((X)=>X.id===Z)??J.models[0]}),Q2=()=>Z0(($)=>$.config.config?.currentModelId),z9=()=>Z0(($)=>$.config.config?.agentTeamsEnabled===!0),P0=()=>Z0(($)=>{return K$.getTheme()}),O9=()=>Z0(($)=>$.config.config?.codeTheme??"default"),r0=()=>Z0(($)=>$.focus.currentFocus),_9=()=>Z0(($)=>$.focus.actions),X8=()=>Z0(($)=>$.command.isProcessing),N9=()=>Z0(($)=>$.command.actions),Q8=()=>Z0(($)=>$.command.pendingCommands),H9=()=>Z0(($)=>$.command.recoveredSteeringCount),K2=()=>Z0(($)=>$.app.reasoningEffort!=="off"),G2=()=>Z0(($)=>$.app.reasoningEffort),U2=()=>Z0(($)=>$.app.serviceTier),q2=()=>Z0(($)=>$.app.responseVerbosity),z2=()=>Z0(($)=>$.app.communicationStyle),O2=()=>Z0(($)=>$.session.currentThinkingContent),F9=()=>Z0(($)=>$.session.thinkingExpanded),_2=()=>Z0(($)=>$.session.currentStreamingMessageId),N2=()=>Z0(TZ(($)=>({lines:$.session.currentStreamingLines,tail:$.session.currentStreamingTail,lineCount:$.session.currentStreamingLineCount,version:$.session.currentStreamingVersion}))),W9=()=>Z0(($)=>$.session.finalizingStreamingMessageId),L9=()=>Z0(($)=>$.session.historyExpanded),w9=()=>Z0(($)=>$.session.expandedMessageCount);import{useMemoizedFn as X1}from"ahooks";import{useEffect as g1,useMemo as oZ,useRef as R2}from"react";class W4{options;requested=!1;scheduled=!1;inFlight=!1;disposed=!1;generation=0;activeRunController=null;scheduleCallback;constructor($){this.options=$;this.scheduleCallback=$.schedule??queueMicrotask}request(){if(this.disposed)return;this.requested=!0,this.scheduleIfRunnable()}notifyIdle(){this.scheduleIfRunnable()}dispose(){this.disposed=!0,this.requested=!1,this.scheduled=!1,this.generation++,this.activeRunController?.abort("pending-resume-coordinator-disposed"),this.activeRunController=null}scheduleIfRunnable(){if(this.disposed||!this.requested||this.scheduled||this.inFlight||!this.options.canRun())return;this.scheduled=!0;let $=this.generation;this.scheduleCallback(()=>{if(this.disposed||$!==this.generation)return;this.scheduled=!1,this.flush()})}async flush(){if(this.disposed||this.inFlight||!this.requested||!this.options.canRun())return;this.requested=!1,this.inFlight=!0;let $=new AbortController;this.activeRunController=$;let J="completed";try{J=await this.options.run($.signal)}finally{if(this.activeRunController===$)this.activeRunController=null;if(this.inFlight=!1,J==="deferred")this.requested=!0;this.scheduleIfRunnable()}}}class S8{options;finalized=!1;constructor($){this.options=$}get isFinalized(){return this.finalized}acceptsDeltas(){return!this.finalized&&!this.options.signal.aborted}startTurn(){this.finalized=!1}finalize(){if(!this.acceptsDeltas())return!1;return this.finalized=!0,this.commit(this.options.streamingBuffer.drainPendingBuffers()),!0}abortAndFinalize($){if(this.finalized)return $(),!1;this.finalized=!0;let J=this.options.streamingBuffer.drainPendingBuffers();return $(),this.commit(J),!0}discard(){this.finalized=!0,this.options.streamingBuffer.resetStreamingBuffers(),this.options.discardStreamingMessage(),this.options.clearThinking()}commit($){let J=this.options.getStreamingMessageId();if(J){if($.extraContent)H2(J,$.extraContent);B9(J)}this.options.finalizeStreamingMessage($.extraContent,$.extraThinking)}}function IZ($){if(!($ instanceof Error))return"未知错误";let Y=$.lastError??$;if(Y.responseBody)try{let K=JSON.parse(Y.responseBody)?.error?.message;if(K){let G=Y.statusCode?` (HTTP ${Y.statusCode})`:"";return`${K}${G}`}}catch{}let X=$.message.match(/Last error:\s*(.+)$/);if(X)return X[1];return $.message}function SZ($){if(!($ instanceof Error))return!1;return $.name==="AbortError"||$.message.includes("aborted")}function kZ($){if(!($ instanceof Error))return!1;let J=$.message;return J.includes("can only concatenate str")||J.includes("image_url")||J.includes("multimodal")||J.includes("vision")||J.includes("does not support images")}function F2($){let J=SZ($),Z=kZ($),Y;if(Z)Y="当前模型不支持图片理解功能。请切换到支持视觉能力的模型(如 Claude 4.5、GPT-5.2、Gemini 3 Pro、Qwen3-VL-Plus 等)后重试。";else Y=IZ($);return{displayMessage:Y,isAbort:J,isVisionNotSupported:Z}}import{appendFileSync as fZ,mkdirSync as vZ,writeFileSync as DZ}from"node:fs";import VZ from"node:os";import L4 from"node:path";var A9=null;function jZ(){let $=process.env.BLADE_STORAGE_ROOT||L4.join(VZ.homedir(),".blade");return L4.join($,"logs","stream-debug.log")}function EZ($){if(A9===$)return;let J=L4.dirname($);vZ(J,{recursive:!0,mode:493}),DZ($,`=== Stream Debug Log Started: ${new Date().toISOString()} ===
|
|
2
2
|
`),A9=$}function w4($,J,Z){try{let Y=jZ();EZ(Y);let X=new Date().toISOString(),Q=Z?` | ${JSON.stringify(Z)}`:"",K=`[${X}] [${$}] ${J}${Q}
|
|
3
3
|
`;fZ(Y,K)}catch{}}var k8=y1("UI");function A4($,J){if(J.state==="requires_attention"){let Z=J.reason==="interrupted_tool_call";$.addToolMessage("Turn recovery requires attention",{toolName:"Runtime Recovery",phase:"complete",summary:Z?"An interrupted tool may have partially completed":"A completed tool may already have changed external state",detail:`${J.turnId} · inspect workspace, processes, and external state before retrying`});return}$.addToolMessage(J.state==="completed"?"Recovered completed turn":"Resuming interrupted turn",{toolName:"Runtime Recovery",phase:"complete",summary:J.state==="completed"?"The durable final response was recovered":"No tool execution was recorded before interruption",detail:J.turnId})}function R9($,J){let Z=$.streamSession??new S8({signal:$.signal,streamingBuffer:$.streamingBuffer,getStreamingMessageId:$.getStreamingMessageId,finalizeStreamingMessage:$.sessionActions.finalizeStreamingMessage,discardStreamingMessage:$.sessionActions.discardStreamingMessage,clearThinking:()=>$.sessionActions.setCurrentThinkingContent(null)});return(Y)=>{switch(Y.kind){case"content_delta":if(!Z.acceptsDeltas())break;J.contentDeltaCount++,J.contentDeltaTotalLen+=Y.delta.length,w4("loopEventHandler","onContentDelta",{callCount:J.contentDeltaCount,deltaLen:Y.delta.length,totalLen:J.contentDeltaTotalLen}),$.streamingBuffer.batchAppendContent(Y.delta);break;case"thinking_delta":if(!Z.acceptsDeltas())break;if($.thinkingModeEnabled)$.streamingBuffer.batchAppendThinking(Y.delta);break;case"stream_end":{$.sessionActions.setProviderCircuit(null),$.sessionActions.setProviderRetry(null),$.sessionActions.setProviderStall(null),k8.debug("[loopEventHandler] stream_end",{contentDeltaCount:J.contentDeltaCount,contentDeltaTotalLen:J.contentDeltaTotalLen,streamFinalized:Z.isFinalized,signalAborted:$.signal.aborted}),w4("loopEventHandler","onStreamEnd",{contentDeltaCallCount:J.contentDeltaCount,contentDeltaTotalLen:J.contentDeltaTotalLen,streamFinalized:Z.isFinalized,signalAborted:$.signal.aborted}),Z.finalize();break}case"model_fallback":$.sessionActions.setProviderAdmission(null),$.sessionActions.setProviderCircuit(null),$.sessionActions.setProviderRetry(null),$.sessionActions.setProviderStall(null),Z.discard();break;case"provider_admission":{let{kind:X,...Q}=Y;$.sessionActions.setProviderAdmission(Y.phase==="queued"?Q:null);break}case"provider_circuit":{let{kind:X,...Q}=Y;$.sessionActions.setProviderCircuit(Y.phase==="closed"?null:Q);break}case"provider_retry":{let{kind:X,...Q}=Y;$.sessionActions.setProviderRetry(Y.phase==="recovered"?null:Q);break}case"provider_stall":{let{kind:X,...Q}=Y;$.sessionActions.setProviderStall(Y.phase==="detected"?Q:null);break}case"action_stationarity":{let{kind:X,...Q}=Y;$.sessionActions.setActionStationarity(Y.phase==="recovered"?null:Q);break}case"turn_recovery":{A4($.sessionActions,Y.assessment);break}case"tool_start":{let X=Y.toolCall;if(!("function"in X))break;if(X.function.name===W2)break;if(k8.debug("[loopEventHandler] tool_start",{toolName:X.function.name,toolKind:Y.toolKind}),["TaskCreate","TaskUpdate","TaskList"].includes(X.function.name))break;try{let Q=JSON.parse(X.function.arguments),K=M9(X.function.name,Q);$.sessionActions.addToolMessage(K,{toolCallId:X.id,toolName:X.function.name,phase:"start",summary:K,params:Q})}catch(Q){k8.error("[loopEventHandler] onToolStart error:",Q)}break}case"tool_progress":{let X=Y.toolCall;if(!("function"in X))break;if(X.function.name===W2)break;let Q=Y.update.total!==void 0?` ${Math.max(0,Math.min(100,Math.round((Y.update.progress??0)/Y.update.total*100)))}%`:"",K=`${X.function.name}${Q}: ${Y.update.message}`;$.sessionActions.addToolMessage(K,{toolCallId:X.id,toolName:X.function.name,phase:"progress",summary:K,...Y.update.admission?{admission:Y.update.admission}:{}});break}case"tool_result":{let X=Y.toolCall;if(!("function"in X))break;if(X.function.name===W2)break;k8.debug("[loopEventHandler] tool_result",{toolName:X.function.name,success:Y.result.success});let Q=P9(y9(X.function.name,Y.result),b9);$.sessionActions.addToolMessage(Q.summary,{toolCallId:X.id,toolName:X.function.name,phase:"complete",summary:Q.summary,detail:Q.detail});break}case"structured_output":$.sessionActions.replaceLastAssistantMessage(JSON.stringify(Y.output,null,2));break;case"token_usage":$.sessionActions.updateTokenUsage(Y.usage);break;case"compaction":if($.sessionActions.setCompacting(Y.phase==="start"),Y.phase==="end"){if($.sessionActions.resetContextUsage(),Y.outcome!=="failed")J.compactionCount=(J.compactionCount??0)+1}break;case"turn_start":k8.debug("[loopEventHandler] turn_start",{turn:Y.turn,maxTurns:Y.maxTurns}),$.sessionActions.updateTokenUsage({turnCount:Y.turn}),$.sessionActions.setProviderCircuit(null),$.sessionActions.setProviderRetry(null),$.sessionActions.setProviderStall(null),Z.startTurn();break;case"task_update":$.appActions.setTasks(Y.tasks);break;case"goal_frontier_updated":$.appActions.setTasks(Y.tasks);break;case"mcp_catalog_changed":{let X=`MCP catalog r${Y.revision}: +${Y.added.length} -${Y.removed.length} ~${Y.updated.length}`;$.sessionActions.addToolMessage(X,{toolName:"MCP Catalog",phase:"complete",summary:X,detail:[Y.added.length>0?`Added: ${Y.added.join(", ")}`:"",Y.removed.length>0?`Removed: ${Y.removed.join(", ")}`:"",Y.updated.length>0?`Updated: ${Y.updated.join(", ")}`:""].filter(Boolean).join(`
|
|
4
4
|
`)});break}case"mcp_content_changed":{let X=`MCP ${Y.contentKind} r${Y.revision}: +${Y.added.length} -${Y.removed.length} ~${Y.updated.length}`;$.sessionActions.addToolMessage(X,{toolName:"MCP Content",phase:"complete",summary:X,detail:[Y.added.length>0?`Added: ${Y.added.join(", ")}`:"",Y.removed.length>0?`Removed: ${Y.removed.join(", ")}`:"",Y.updated.length>0?`Updated: ${Y.updated.join(", ")}`:""].filter(Boolean).join(`
|
|
@@ -118,7 +118,7 @@ ${h}`}]}}let $$=b4(e),g=await k($$);if(!g.accepted){let h=g.reason==="queue_full
|
|
|
118
118
|
|
|
119
119
|
**重要**:请直接返回 JSON,不要添加任何额外的解释或文字。`,G)).trim(),k=T.match(/```(?:json)?\s*\n([\s\S]*?)\n```/);if(k)T=k[1];let y=JSON.parse(T);if(!y.name||!y.description||!y.systemPrompt)throw Error("Missing required fields: name, description, or systemPrompt");if(!/^[a-z0-9]+(-[a-z0-9]+)*$/.test(y.name))throw Error("Invalid name format. Must be kebab-case (lowercase, numbers, hyphens only)");K({name:y.name,description:y.description,tools:Array.isArray(y.tools)?y.tools:[],color:y.color||"blue",location:"project",systemPrompt:y.systemPrompt}),X("confirm")}catch(P){_(P instanceof Error?P.message:String(P))}finally{O(!1)}});T6(()=>{if(Y==="aiGenerating"&&!q&&!z)B()},[Y,q,z,B]);let w=j2(async()=>{try{let P=Q.location==="project"?V4.join(Z$(),".blade","agents"):V4.join(v5.homedir(),".blade","agents");await R6.promises.mkdir(P,{recursive:!0});let b=["---",`name: ${Q.name}`,`description: ${Q.description}`];if(Q.tools.length>0&&!Q.tools.includes("all")){b.push("tools:");for(let k of Q.tools)b.push(` - ${k}`)}if(Q.color)b.push(`color: ${Q.color}`);b.push("---");let v=[b.join(`
|
|
120
120
|
`),"",`# ${Q.name} Subagent`,"",Q.systemPrompt||"你是一个专门的代理,负责执行特定任务。",""].join(`
|
|
121
|
-
`),T=V4.join(P,`${Q.name}.md`);await R6.promises.writeFile(T,v,"utf-8"),$()}catch(P){console.error("保存配置失败:",P)}}),M=h0(!1,J);if(q0((P,b)=>{if(b.escape)S();else if(b.ctrl&&P==="c"||b.meta&&P==="c")M()},{isActive:Y!=="tools"}),Y==="mode")return E(N0,{flexDirection:"column",paddingY:1,children:[E(N0,{marginBottom:1,children:E(G0,{bold:!0,color:"cyan",children:"选择创建方式"},void 0,!1,void 0,this)},void 0,!1,void 0,this),E(N0,{marginBottom:1,children:E(G0,{dimColor:!0,children:"你可以手动配置每个细节,或让 AI 根据你的描述自动生成配置"},void 0,!1,void 0,this)},void 0,!1,void 0,this),E(E2,{items:[{label:"AI 智能生成 - 根据描述自动生成完整配置",value:"ai"},{label:"手动配置 - 逐步配置每个选项",value:"manual"}],onSelect:(P)=>{if(P.value==="ai")L("ai"),X("aiPrompt");else L("manual"),X("name")}},void 0,!1,void 0,this),E(N0,{marginTop:1,children:E(G0,{dimColor:!0,children:"使用方向键选择 | Enter 确认 | ESC 取消"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(Y==="aiPrompt")return E(N0,{flexDirection:"column",paddingY:1,children:[E(N0,{marginBottom:1,children:E(G0,{bold:!0,color:"cyan",children:"AI 智能生成"},void 0,!1,void 0,this)},void 0,!1,void 0,this),E(N0,{marginBottom:1,children:E(G0,{dimColor:!0,children:'描述你想要创建的 Agent(例如:"一个专门用于代码审查的 agent,能够分析代码质量和潜在bug")'},void 0,!1,void 0,this)},void 0,!1,void 0,this),E(N0,{marginBottom:1,children:[E(G0,{color:"green",children:"描述: "},void 0,!1,void 0,this),E(g8,{value:G,onChange:U,onSubmit:(P)=>{if(!P.trim())return;X("aiGenerating")}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E(N0,{children:E(G0,{dimColor:!0,children:"按 Enter 开始生成 | ESC 返回"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(Y==="aiGenerating"){if(z)return E(N0,{flexDirection:"column",paddingY:1,children:[E(N0,{marginBottom:1,children:E(G0,{bold:!0,color:"red",children:"AI 生成失败"},void 0,!1,void 0,this)},void 0,!1,void 0,this),E(N0,{marginBottom:1,children:E(G0,{color:"red",children:z},void 0,!1,void 0,this)},void 0,!1,void 0,this),E(N0,{marginBottom:1,children:E(G0,{dimColor:!0,children:"按 ESC 返回修改描述"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return E(N0,{flexDirection:"column",paddingY:1,children:[E(N0,{marginBottom:1,children:E(G0,{bold:!0,color:"yellow",children:[E(E5,{type:"dots"},void 0,!1,void 0,this)," AI 正在生成配置..."]},void 0,!0,void 0,this)},void 0,!1,void 0,this),E(N0,{marginBottom:1,children:E(G0,{dimColor:!0,children:['根据你的描述:"',G,'"']},void 0,!0,void 0,this)},void 0,!1,void 0,this),E(N0,{marginBottom:1,children:E(G0,{color:"gray",children:"正在调用 LLM 生成 agent 配置,请稍候..."},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}if(Y==="name"){let P=W==="edit";return E(N0,{flexDirection:"column",paddingY:1,children:[E(N0,{marginBottom:1,children:E(G0,{bold:!0,color:"cyan",children:["Step 1/7: ",P?"Agent 名称(不可修改)":"输入 Agent 名称"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),E(N0,{marginBottom:1,children:E(G0,{dimColor:!0,children:P?"编辑模式下名称不可修改(修改名称相当于创建新 Agent)":"名称只能包含小写字母、数字和连字符(例如:code-reviewer)"},void 0,!1,void 0,this)},void 0,!1,void 0,this),E(N0,{marginBottom:1,children:[E(G0,{color:"green",children:"名称: "},void 0,!1,void 0,this),P?E(G0,{children:Q.name},void 0,!1,void 0,this):E(g8,{value:Q.name,onChange:(b)=>K({...Q,name:b}),onSubmit:(b)=>{if(m5(b))return;H()}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E(N0,{children:E(G0,{dimColor:!0,children:P?"按 Enter 继续 | ESC 返回":"按 Enter 继续 | ESC 返回"},void 0,!1,void 0,this)},void 0,!1,void 0,this),P&&E(g8,{value:"",onChange:()=>{},onSubmit:H,showCursor:!1},"edit-mode-dummy-input",!1,void 0,this)]},void 0,!0,void 0,this)}if(Y==="description")return E(N0,{flexDirection:"column",paddingY:1,children:[E(N0,{marginBottom:1,children:E(G0,{bold:!0,color:"cyan",children:"Step 2/7: 输入描述信息"},void 0,!1,void 0,this)},void 0,!1,void 0,this),E(N0,{marginBottom:1,children:E(G0,{dimColor:!0,children:"简短描述这个 Agent 的用途和使用场景(这将帮助主 Agent 决定何时使用它)"},void 0,!1,void 0,this)},void 0,!1,void 0,this),E(N0,{marginBottom:1,children:[E(G0,{color:"green",children:"描述: "},void 0,!1,void 0,this),E(g8,{value:Q.description,onChange:(P)=>K({...Q,description:P}),onSubmit:(P)=>{if(!P.trim())return;H()}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E(N0,{children:E(G0,{dimColor:!0,children:"按 Enter 继续 | ESC 返回"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(Y==="tools")return E(p5,{config:Q,setConfig:K,onNext:H,onPrev:S},void 0,!1,void 0,this);if(Y==="color")return E(N0,{flexDirection:"column",paddingY:1,children:[E(N0,{marginBottom:1,children:E(G0,{bold:!0,color:"cyan",children:"Step 4/7: 选择背景颜色"},void 0,!1,void 0,this)},void 0,!1,void 0,this),E(N0,{marginBottom:1,children:E(G0,{dimColor:!0,children:"为 Agent 选择一个颜色标识(用于在 UI 中区分不同的 Agents)"},void 0,!1,void 0,this)},void 0,!1,void 0,this),E(E2,{items:g5,onSelect:(P)=>{let b=P.value==="none"?void 0:P.value;K({...Q,color:b}),H()}},void 0,!1,void 0,this),E(N0,{marginTop:1,children:E(G0,{dimColor:!0,children:"使用方向键选择 | Enter 确认 | ESC 返回"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(Y==="location")return E(N0,{flexDirection:"column",paddingY:1,children:[E(N0,{marginBottom:1,children:E(G0,{bold:!0,color:"cyan",children:"Step 5/7: 选择保存位置"},void 0,!1,void 0,this)},void 0,!1,void 0,this),E(N0,{marginBottom:1,children:E(G0,{dimColor:!0,children:"项目级配置仅在当前项目生效,用户级配置全局可用"},void 0,!1,void 0,this)},void 0,!1,void 0,this),E(E2,{items:[{label:"项目级 (.blade/agents/) - 仅当前项目",value:"project"},{label:"用户级 (~/.blade/agents/) - 全局可用",value:"user"}],onSelect:(P)=>{K({...Q,location:P.value}),H()}},void 0,!1,void 0,this),E(N0,{marginTop:1,children:E(G0,{dimColor:!0,children:"使用方向键选择 | Enter 确认 | ESC 返回"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(Y==="systemPrompt")return E(N0,{flexDirection:"column",paddingY:1,children:[E(N0,{marginBottom:1,children:E(G0,{bold:!0,color:"cyan",children:"Step 6/7: 输入系统提示词"},void 0,!1,void 0,this)},void 0,!1,void 0,this),E(N0,{marginBottom:1,children:E(G0,{dimColor:!0,children:"定义 Agent 的行为和职责(可选,留空将使用默认提示)"},void 0,!1,void 0,this)},void 0,!1,void 0,this),E(N0,{marginBottom:1,children:[E(G0,{color:"green",children:"提示词: "},void 0,!1,void 0,this),E(g8,{value:Q.systemPrompt,onChange:(P)=>K({...Q,systemPrompt:P}),onSubmit:()=>H()},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E(N0,{children:E(G0,{dimColor:!0,children:"按 Enter 继续 | ESC 返回"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(Y==="confirm")return E(N0,{flexDirection:"column",paddingY:1,children:[E(N0,{marginBottom:1,children:E(G0,{bold:!0,color:"cyan",children:"Step 7/7: 确认配置"},void 0,!1,void 0,this)},void 0,!1,void 0,this),E(N0,{flexDirection:"column",paddingLeft:2,marginBottom:1,children:[E(G0,{children:[E(G0,{bold:!0,color:"green",children:["名称:"," "]},void 0,!0,void 0,this),E(G0,{children:Q.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E(G0,{children:[E(G0,{bold:!0,color:"green",children:["描述:"," "]},void 0,!0,void 0,this),E(G0,{children:Q.description},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E(G0,{children:[E(G0,{bold:!0,color:"green",children:["工具:"," "]},void 0,!0,void 0,this),E(G0,{children:Q.tools.includes("all")?"所有工具":Q.tools.join(", ")||"所有工具"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E(G0,{children:[E(G0,{bold:!0,color:"green",children:["颜色:"," "]},void 0,!0,void 0,this),E(G0,{children:Q.color||"默认"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E(G0,{children:[E(G0,{bold:!0,color:"green",children:["位置:"," "]},void 0,!0,void 0,this),E(G0,{children:Q.location==="project"?"项目级":"用户级"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E(G0,{children:[E(G0,{bold:!0,color:"green",children:["提示词:"," "]},void 0,!0,void 0,this),E(G0,{children:Q.systemPrompt||"(使用默认)"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),E(E2,{items:[{label:"确认并保存",value:"save"},{label:"返回上一步",value:"back"},{label:"取消",value:"cancel"}],onSelect:(P)=>{if(P.value==="save")w();else if(P.value==="back")S();else J()}},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return null}function p5({config:$,setConfig:J,onNext:Z,onPrev:Y}){let{isFocused:X}=V5({id:"step-tools"});q0((K,G)=>{if(G.escape)Y()},{isActive:X});let Q=(K)=>{if(K.includes("all"))J({...$,tools:["all"]});else J({...$,tools:K});Z()};return E(N0,{flexDirection:"column",paddingY:1,children:[E(N0,{marginBottom:1,children:E(G0,{bold:!0,color:"cyan",children:"Step 3/7: 选择可用工具"},void 0,!1,void 0,this)},void 0,!1,void 0,this),E(N0,{marginBottom:1,children:E(G0,{dimColor:!0,children:"方向键导航,空格切换勾选,Enter 确认进入下一步 | ESC 返回上一步"},void 0,!1,void 0,this)},void 0,!1,void 0,this),E(D5,{options:h5,defaultValue:$.tools,onSubmit:Q},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import x5 from"node:fs";import{useMemoizedFn as x1}from"ahooks";import{Box as v0,Text as g0}from"ink";import j4 from"ink-select-input";import{useEffect as u5,useMemo as C6,useState as h2}from"react";import{jsxDEV as Y0}from"react/jsx-dev-runtime";var E4=10;function I6({workspaceRoot:$,initialMode:J="menu",onComplete:Z,onCancel:Y}){let X=T2($),[Q,K]=h2(J),[G,U]=h2(null),[q,O]=h2(0),[z,_]=h2(0),W=x1(()=>{X.clear(),X.loadFromStandardLocations(),O((T)=>T+1)}),L=C6(()=>{return X.getAllSubagents()},[q]),N=Math.ceil(L.length/E4)||1,A=C6(()=>{let T=z*E4;return L.slice(T,T+E4)},[L,z]);u5(()=>{let T=Math.max(0,N-1);if(z>T)_(T)},[N,z]);let I=x1(()=>{if(z<N-1)_((T)=>T+1)}),H=x1(()=>{if(z>0)_((T)=>T-1)}),S=[{key:"list",label:"查看所有 Agents",value:"list"},{key:"create",label:"创建新 Agent",value:"create"},{key:"edit",label:"编辑 Agent",value:"edit"},{key:"delete",label:"删除 Agent",value:"delete"},{key:"cancel",label:"取消",value:"cancel"}],B=x1((T)=>{if(T.value==="cancel"){Y?.();return}K(T.value)}),w=x1((T)=>{if(U(T.value),Q==="edit")K("editWizard");else if(Q==="delete")K("deleteConfirm")}),M=x1(async()=>{if(!G?.configPath)return;try{await x5.promises.unlink(G.configPath),W(),P()}catch(T){console.error("删除失败:",T)}}),P=x1(()=>{K("menu"),U(null)}),b=h0(!1,Y);if(q0((T,k)=>{if(k.escape){if(Q==="menu")Y?.();else if(Q==="list"||Q==="edit"||Q==="delete")_(0),P();else if(Q==="deleteConfirm")P()}else if(k.ctrl&&T==="c"||k.meta&&T==="c")b();else if(Q==="list"){if(k.leftArrow||T==="h")H();else if(k.rightArrow||T==="l")I()}},{isActive:Q!=="create"&&Q!=="editWizard"}),Q==="menu")return Y0(v0,{flexDirection:"column",paddingY:1,children:[Y0(v0,{marginBottom:1,children:Y0(g0,{bold:!0,color:"cyan",children:"Agents 管理"},void 0,!1,void 0,this)},void 0,!1,void 0,this),Y0(j4,{items:S,onSelect:B},void 0,!1,void 0,this),Y0(v0,{marginTop:1,children:Y0(g0,{dimColor:!0,children:"使用方向键选择 | Enter 确认 | ESC 退出"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(Q==="list"){if(L.length===0)return Y0(v0,{flexDirection:"column",paddingY:1,children:[Y0(v0,{marginBottom:1,children:Y0(g0,{bold:!0,color:"cyan",children:"所有 Agents"},void 0,!1,void 0,this)},void 0,!1,void 0,this),Y0(v0,{paddingLeft:2,children:Y0(g0,{color:"gray",children:"没有找到任何 agent 配置"},void 0,!1,void 0,this)},void 0,!1,void 0,this),Y0(v0,{marginTop:1,paddingLeft:2,children:Y0(g0,{color:"gray",children:"配置文件位置: .blade/agents/ 或 ~/.blade/agents/"},void 0,!1,void 0,this)},void 0,!1,void 0,this),Y0(v0,{marginTop:1,paddingLeft:2,children:Y0(g0,{dimColor:!0,children:"按 ESC 返回菜单"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return Y0(v0,{flexDirection:"column",paddingY:1,children:[Y0(v0,{marginBottom:1,children:[Y0(g0,{bold:!0,color:"cyan",children:"所有 Agents"},void 0,!1,void 0,this),Y0(g0,{color:"gray",children:[" (共 ",L.length," 个)"]},void 0,!0,void 0,this),N>1&&Y0(g0,{color:"yellow",children:[" ","第 ",z+1,"/",N," 页"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),A.map((T)=>Y0(v0,{flexDirection:"column",paddingLeft:2,children:[Y0(v0,{children:Y0(g0,{children:[Y0(g0,{bold:!0,color:T.color||"white",children:["• ",T.name]},void 0,!0,void 0,this),Y0(g0,{color:"gray",children:[" - ",T.description]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),T.tools&&T.tools.length>0&&Y0(v0,{paddingLeft:2,children:Y0(g0,{color:"gray",children:["工具: ",T.tools.join(", ")]},void 0,!0,void 0,this)},void 0,!1,void 0,this),T.configPath&&Y0(v0,{paddingLeft:2,children:Y0(g0,{color:"gray",dimColor:!0,children:T.configPath},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},T.name,!0,void 0,this)),Y0(v0,{marginTop:1,paddingLeft:2,children:N>1?Y0(g0,{dimColor:!0,children:"Left/Right to page | ESC 返回菜单"},void 0,!1,void 0,this):Y0(g0,{dimColor:!0,children:"按 ESC 返回菜单"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}let v=(T)=>{if(L.length===0)return Y0(v0,{flexDirection:"column",paddingY:1,children:[Y0(v0,{marginBottom:1,children:Y0(g0,{bold:!0,color:"cyan",children:T},void 0,!1,void 0,this)},void 0,!1,void 0,this),Y0(v0,{paddingLeft:2,children:Y0(g0,{color:"gray",children:"没有找到任何 agent 配置"},void 0,!1,void 0,this)},void 0,!1,void 0,this),Y0(v0,{marginTop:1,paddingLeft:2,children:Y0(g0,{dimColor:!0,children:"按 ESC 返回菜单"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this);let k=L.map((y)=>({key:y.name,label:`${y.name} - ${y.description}`,value:y}));return Y0(v0,{flexDirection:"column",paddingY:1,children:[Y0(v0,{marginBottom:1,children:Y0(g0,{bold:!0,color:"cyan",children:T},void 0,!1,void 0,this)},void 0,!1,void 0,this),Y0(j4,{items:k,onSelect:w},void 0,!1,void 0,this),Y0(v0,{marginTop:1,children:Y0(g0,{dimColor:!0,children:"使用方向键选择 | Enter 确认 | ESC 返回"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};if(Q==="create")return Y0(m8,{onComplete:()=>{W(),P()},onCancel:P},void 0,!1,void 0,this);if(Q==="edit")return v("编辑 Agent");if(Q==="editWizard"&&G){let T={name:G.name,description:G.description,tools:G.tools||[],color:G.color,location:G.configPath?.includes(".blade/agents")?"project":"user",systemPrompt:G.systemPrompt||""};return Y0(m8,{initialConfig:T,onComplete:()=>{W(),P()},onCancel:P},void 0,!1,void 0,this)}if(Q==="delete")return v("删除 Agent");if(Q==="deleteConfirm"&&G)return Y0(v0,{flexDirection:"column",paddingY:1,children:[Y0(v0,{marginBottom:1,children:Y0(g0,{bold:!0,color:"red",children:"确认删除"},void 0,!1,void 0,this)},void 0,!1,void 0,this),Y0(v0,{marginBottom:1,paddingLeft:2,children:Y0(g0,{children:["你确定要删除 Agent"," ",Y0(g0,{bold:!0,color:"yellow",children:G.name},void 0,!1,void 0,this)," ","吗?"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),Y0(v0,{marginBottom:1,paddingLeft:2,children:Y0(g0,{dimColor:!0,children:["文件路径: ",G.configPath]},void 0,!0,void 0,this)},void 0,!1,void 0,this),Y0(v0,{marginBottom:1,paddingLeft:2,children:Y0(g0,{color:"red",children:"此操作无法撤销!"},void 0,!1,void 0,this)},void 0,!1,void 0,this),Y0(j4,{items:[{label:"确认删除",value:"confirm"},{label:"取消",value:"cancel"}],onSelect:(T)=>{if(T.value==="confirm")M();else P()}},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return null}import{Box as O8,Text as W0}from"ink";import d5,{useEffect as l5,useState as r5}from"react";import{useEffect as c5,useState as S6}from"react";function v6($=Z$(),J=5000){let[Z,Y]=S6(null),[X,Q]=S6(!0);return c5(()=>{let K=!0,G=async()=>{try{let q=await k6($);if(!K)return;if(!q){Y(null),Q(!1);return}let O=await f6($);if(!K)return;Y(O)}catch{if(K)Y(null)}finally{if(K)Q(!1)}};G();let U=null;if(J>0)U=setInterval(G,J);return()=>{if(K=!1,U)clearInterval(U)}},[$,J]),{branch:Z,loading:X}}import{jsxDEV as X0,Fragment as m$}from"react/jsx-dev-runtime";var V6=d5.memo(()=>{let $=Z2(),J=Z8(),Y=J2()==="shortcuts",X=K9(),Q=o$(),{branch:K}=v6(Q),G=X2(),U=$9(),q=rJ(),O=K2(),z=G2(),_=U2(),W=q2(),L=z2(),N=aJ(),A=iJ(),I=Q8(),H=H9(),S=Y8(),[B,w]=r5(null);l5(()=>{let k=!1;new h4(Q,S).get().then((o)=>{if(!k)w(o)}).catch(()=>{if(!k)w(null)});let j=h4.subscribe((o)=>{if(!k&&o.sessionId===S&&o.workspaceRoot===Q)w(o.goal)});return()=>{k=!0,j()}},[S,Q]);let M=G?S2(G):!1,b=(()=>{if(J==="default")return null;if(J==="autoEdit")return X0(W0,{color:"magenta",children:[">> ","auto edit on ",X0(W0,{color:"gray",children:"(shift+tab to cycle)"},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(J==="plan")return X0(W0,{color:"cyan",children:["‖ plan mode on ",X0(W0,{color:"gray",children:"(shift+tab to cycle)"},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(J==="yolo")return X0(W0,{color:"red",children:["yolo mode on ",X0(W0,{color:"gray",children:"(all tools auto-approved)"},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return null})(),v=b!==null,T=[["Enter:发送","Shift+Enter:换行","Esc:中止"],["Shift+Tab:切换模式","Up/Down:历史","Tab:补全"],["Ctrl+A:行首","Ctrl+E:行尾","Ctrl+K:删到尾"],["Ctrl+U:删到首","Ctrl+W:删单词","Ctrl+C:退出"],["Ctrl+O:浏览记录","PgUp/PgDn:翻页","g/G:首尾"]];return X0(O8,{flexDirection:"row",justifyContent:"space-between",paddingX:2,paddingY:0,children:[Y?X0(O8,{flexDirection:"column",gap:0,children:T.map((k,y)=>X0(O8,{flexDirection:"row",children:[k.map((j,o)=>{let[t,a]=j.split(":");return X0(O8,{flexDirection:"row",width:20,children:[X0(W0,{color:"yellow",children:t},void 0,!1,void 0,this),X0(W0,{color:"gray",children:":"},void 0,!1,void 0,this),X0(W0,{color:"white",children:a},void 0,!1,void 0,this)]},o,!0,void 0,this)}),y===T.length-1&&X0(W0,{color:"cyan",children:" ? 关闭"},void 0,!1,void 0,this)]},y,!0,void 0,this))},void 0,!1,void 0,this):X0(O8,{flexDirection:"row",gap:1,children:[K&&X0(m$,{children:[X0(W0,{color:"gray",children:[" ",K]},void 0,!0,void 0,this),X0(W0,{color:"gray",children:"·"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),b,v&&X0(W0,{color:"gray",children:"·"},void 0,!1,void 0,this),B&&X0(m$,{children:[X0(W0,{color:B.status==="active"?"green":B.status==="verifying"?"cyan":B.status==="blocked"||B.status==="budget_limited"?"yellow":"gray",children:["goal:",B.status," ",B.objective.slice(0,32),B.prematureStop?` recovery:${B.prematureStop.consecutiveCount}`:"",B.verificationStall?` verify-gap:${B.verificationStall.consecutiveCount}`:""]},void 0,!0,void 0,this),X0(W0,{color:"gray",children:"·"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),X0(W0,{color:"gray",children:"? for shortcuts"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),X0(O8,{flexDirection:"row",gap:1,children:!$?X0(W0,{color:"red",children:"[WARN] API 密钥未配置"},void 0,!1,void 0,this):X0(m$,{children:[M&&X0(m$,{children:[O?X0(W0,{color:"cyan",children:["Effort ",z]},void 0,!0,void 0,this):X0(W0,{color:"gray",children:"Tab:Effort"},void 0,!1,void 0,this),X0(W0,{color:"gray",children:"·"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),_!=="auto"&&X0(m$,{children:[X0(W0,{color:_==="fast"?"yellow":"gray",children:["Speed ",_]},void 0,!0,void 0,this),X0(W0,{color:"gray",children:"·"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),W!=="auto"&&X0(m$,{children:[X0(W0,{color:"gray",children:["Output ",W]},void 0,!0,void 0,this),X0(W0,{color:"gray",children:"·"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),L!=="auto"&&X0(m$,{children:[X0(W0,{color:"gray",children:["Style ",L]},void 0,!0,void 0,this),X0(W0,{color:"gray",children:"·"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),G&&X0(W0,{color:"gray",children:G.model},void 0,!1,void 0,this),X0(W0,{color:"gray",children:"·"},void 0,!1,void 0,this),q?X0(W0,{color:"yellow",children:"压缩中..."},void 0,!1,void 0,this):X0(W0,{color:U<20?"red":U<50?"yellow":"gray",children:[U,"%"]},void 0,!0,void 0,this),X0(W0,{color:"gray",children:"·"},void 0,!1,void 0,this),X0(W0,{color:A===void 0?"gray":"cyan",children:["Cache ",D6(A)]},void 0,!0,void 0,this),N>0.001&&X0(m$,{children:[X0(W0,{color:"gray",children:"·"},void 0,!1,void 0,this),X0(W0,{color:"green",children:["$",N<0.01?N.toFixed(4):N.toFixed(3)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),I.length>0&&X0(m$,{children:[X0(W0,{color:"gray",children:"·"},void 0,!1,void 0,this),X0(W0,{color:"yellow",children:["已排队 ",I.length]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),H>0&&X0(m$,{children:[X0(W0,{color:"gray",children:"·"},void 0,!1,void 0,this),X0(W0,{color:"cyan",children:["已恢复 ",H," 条指令"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),X&&X0(m$,{children:[X0(W0,{color:"gray",children:"·"},void 0,!1,void 0,this),X0(W0,{color:"yellow",children:"再按一次 Ctrl+C 退出"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)});import{Box as g4,Text as m4}from"ink";import a5 from"react";import{jsxDEV as _8}from"react/jsx-dev-runtime";var j6=a5.memo(({suggestions:$,selectedIndex:J,visible:Z,maxDisplay:Y=8})=>{if(!Z||$.length===0)return null;let X=0,Q=Math.min(Y,$.length),K=J>=$.length;if(J>=Y&&!K)X=J-Y+1,Q=J+1;let G=$.slice(X,Q),U=$.length>Y;return _8(g4,{flexDirection:"column",paddingX:2,paddingY:0,children:[G.map((q,O)=>{let _=X+O===J;return _8(g4,{flexDirection:"row",paddingX:1,gap:2,children:[_8(m4,{color:_?"cyan":"white",bold:_,children:q.command},void 0,!1,void 0,this),_8(m4,{color:_?"cyan":"gray",dimColor:!_,children:["- ",q.description]},void 0,!0,void 0,this)]},q.command,!0,void 0,this)}),U&&_8(g4,{paddingX:1,children:_8(m4,{color:K?"cyan":"gray",bold:K,dimColor:!K,children:["... and ",$.length-Y," more"]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)});import{Box as v$,Text as s$,useStdout as rX}from"ink";import aX from"ink-select-input";import qJ,{useMemo as NY}from"react";import{Box as L0,Text as k0}from"ink";import c1,{useEffect as GJ,useMemo as u1,useRef as zY}from"react";import{Box as t4,Text as a6}from"ink";import GX from"react";import{Text as p$}from"ink";import XX from"react";import d6 from"string-width";import p8 from"string-width";function p4({onlyFirst:$=!1}={}){return new RegExp("(?:\\u001B\\][\\s\\S]*?(?:\\u0007|\\u001B\\u005C|\\u009C))|[\\u001B\\u009B][[\\]()#;?]*(?:\\d{1,4}(?:[;:]\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]",$?void 0:"g")}var i5=p4();function x4($){if(typeof $!=="string")throw TypeError(`Expected a \`string\`, got \`${typeof $}\``);if(!$.includes("\x1B")&&!$.includes(""))return $;return $.replace(i5,"")}var E6=($=0)=>(J)=>`\x1B[${J+$}m`,h6=($=0)=>(J)=>`\x1B[${38+$};5;${J}m`,g6=($=0)=>(J,Z,Y)=>`\x1B[${38+$};2;${J};${Z};${Y}m`,c0={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}},sq=Object.keys(c0.modifier),o5=Object.keys(c0.color),n5=Object.keys(c0.bgColor),eq=[...o5,...n5];function t5(){let $=new Map;for(let[J,Z]of Object.entries(c0)){for(let[Y,X]of Object.entries(Z))c0[Y]={open:`\x1B[${X[0]}m`,close:`\x1B[${X[1]}m`},Z[Y]=c0[Y],$.set(X[0],X[1]);Object.defineProperty(c0,J,{value:Z,enumerable:!1})}return Object.defineProperty(c0,"codes",{value:$,enumerable:!1}),c0.color.close="\x1B[39m",c0.bgColor.close="\x1B[49m",c0.color.ansi=E6(),c0.color.ansi256=h6(),c0.color.ansi16m=g6(),c0.bgColor.ansi=E6(10),c0.bgColor.ansi256=h6(10),c0.bgColor.ansi16m=g6(10),Object.defineProperties(c0,{rgbToAnsi256:{value(J,Z,Y){if(J===Z&&Z===Y){if(J<8)return 16;if(J>248)return 231;return Math.round((J-8)/247*24)+232}return 16+36*Math.round(J/255*5)+6*Math.round(Z/255*5)+Math.round(Y/255*5)},enumerable:!1},hexToRgb:{value(J){let Z=/[a-f\d]{6}|[a-f\d]{3}/i.exec(J.toString(16));if(!Z)return[0,0,0];let[Y]=Z;if(Y.length===3)Y=[...Y].map((Q)=>Q+Q).join("");let X=Number.parseInt(Y,16);return[X>>16&255,X>>8&255,X&255]},enumerable:!1},hexToAnsi256:{value:(J)=>c0.rgbToAnsi256(...c0.hexToRgb(J)),enumerable:!1},ansi256ToAnsi:{value(J){if(J<8)return 30+J;if(J<16)return 90+(J-8);let Z,Y,X;if(J>=232)Z=((J-232)*10+8)/255,Y=Z,X=Z;else{J-=16;let G=J%36;Z=Math.floor(J/36)/5,Y=Math.floor(G/6)/5,X=G%6/5}let Q=Math.max(Z,Y,X)*2;if(Q===0)return 30;let K=30+(Math.round(X)<<2|Math.round(Y)<<1|Math.round(Z));if(Q===2)K+=60;return K},enumerable:!1},rgbToAnsi:{value:(J,Z,Y)=>c0.ansi256ToAnsi(c0.rgbToAnsi256(J,Z,Y)),enumerable:!1},hexToAnsi:{value:(J)=>c0.ansi256ToAnsi(c0.hexToAnsi256(J)),enumerable:!1}}),c0}var s5=t5(),m6=s5;var m2=new Set(["\x1B",""]),e5=39,c4="\x07",u6="[",$X="]",c6="m",g2=`${$X}8;;`,p6=($)=>`${m2.values().next().value}${u6}${$}${c6}`,x6=($)=>`${m2.values().next().value}${g2}${$}${c4}`,JX=($)=>$.split(" ").map((J)=>p8(J)),u4=($,J,Z)=>{let Y=[...J],X=!1,Q=!1,K=p8(x4($.at(-1)));for(let[G,U]of Y.entries()){let q=p8(U);if(K+q<=Z)$[$.length-1]+=U;else $.push(U),K=0;if(m2.has(U))X=!0,Q=Y.slice(G+1,G+1+g2.length).join("")===g2;if(X){if(Q){if(U===c4)X=!1,Q=!1}else if(U===c6)X=!1;continue}if(K+=q,K===Z&&G<Y.length-1)$.push(""),K=0}if(!K&&$.at(-1).length>0&&$.length>1)$[$.length-2]+=$.pop()},YX=($)=>{let J=$.split(" "),Z=J.length;while(Z>0){if(p8(J[Z-1])>0)break;Z--}if(Z===J.length)return $;return J.slice(0,Z).join(" ")+J.slice(Z).join("")},ZX=($,J,Z={})=>{if(Z.trim!==!1&&$.trim()==="")return"";let Y="",X,Q,K=JX($),G=[""];for(let[z,_]of $.split(" ").entries()){if(Z.trim!==!1)G[G.length-1]=G.at(-1).trimStart();let W=p8(G.at(-1));if(z!==0){if(W>=J&&(Z.wordWrap===!1||Z.trim===!1))G.push(""),W=0;if(W>0||Z.trim===!1)G[G.length-1]+=" ",W++}if(Z.hard&&K[z]>J){let L=J-W,N=1+Math.floor((K[z]-L-1)/J);if(Math.floor((K[z]-1)/J)<N)G.push("");u4(G,_,J);continue}if(W+K[z]>J&&W>0&&K[z]>0){if(Z.wordWrap===!1&&W<J){u4(G,_,J);continue}G.push("")}if(W+K[z]>J&&Z.wordWrap===!1){u4(G,_,J);continue}G[G.length-1]+=_}if(Z.trim!==!1)G=G.map((z)=>YX(z));let U=G.join(`
|
|
121
|
+
`),T=V4.join(P,`${Q.name}.md`);await R6.promises.writeFile(T,v,"utf-8"),$()}catch(P){console.error("保存配置失败:",P)}}),M=h0(!1,J);if(q0((P,b)=>{if(b.escape)S();else if(b.ctrl&&P==="c"||b.meta&&P==="c")M()},{isActive:Y!=="tools"}),Y==="mode")return E(N0,{flexDirection:"column",paddingY:1,children:[E(N0,{marginBottom:1,children:E(G0,{bold:!0,color:"cyan",children:"选择创建方式"},void 0,!1,void 0,this)},void 0,!1,void 0,this),E(N0,{marginBottom:1,children:E(G0,{dimColor:!0,children:"你可以手动配置每个细节,或让 AI 根据你的描述自动生成配置"},void 0,!1,void 0,this)},void 0,!1,void 0,this),E(E2,{items:[{label:"AI 智能生成 - 根据描述自动生成完整配置",value:"ai"},{label:"手动配置 - 逐步配置每个选项",value:"manual"}],onSelect:(P)=>{if(P.value==="ai")L("ai"),X("aiPrompt");else L("manual"),X("name")}},void 0,!1,void 0,this),E(N0,{marginTop:1,children:E(G0,{dimColor:!0,children:"使用方向键选择 | Enter 确认 | ESC 取消"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(Y==="aiPrompt")return E(N0,{flexDirection:"column",paddingY:1,children:[E(N0,{marginBottom:1,children:E(G0,{bold:!0,color:"cyan",children:"AI 智能生成"},void 0,!1,void 0,this)},void 0,!1,void 0,this),E(N0,{marginBottom:1,children:E(G0,{dimColor:!0,children:'描述你想要创建的 Agent(例如:"一个专门用于代码审查的 agent,能够分析代码质量和潜在bug")'},void 0,!1,void 0,this)},void 0,!1,void 0,this),E(N0,{marginBottom:1,children:[E(G0,{color:"green",children:"描述: "},void 0,!1,void 0,this),E(g8,{value:G,onChange:U,onSubmit:(P)=>{if(!P.trim())return;X("aiGenerating")}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E(N0,{children:E(G0,{dimColor:!0,children:"按 Enter 开始生成 | ESC 返回"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(Y==="aiGenerating"){if(z)return E(N0,{flexDirection:"column",paddingY:1,children:[E(N0,{marginBottom:1,children:E(G0,{bold:!0,color:"red",children:"AI 生成失败"},void 0,!1,void 0,this)},void 0,!1,void 0,this),E(N0,{marginBottom:1,children:E(G0,{color:"red",children:z},void 0,!1,void 0,this)},void 0,!1,void 0,this),E(N0,{marginBottom:1,children:E(G0,{dimColor:!0,children:"按 ESC 返回修改描述"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return E(N0,{flexDirection:"column",paddingY:1,children:[E(N0,{marginBottom:1,children:E(G0,{bold:!0,color:"yellow",children:[E(E5,{type:"dots"},void 0,!1,void 0,this)," AI 正在生成配置..."]},void 0,!0,void 0,this)},void 0,!1,void 0,this),E(N0,{marginBottom:1,children:E(G0,{dimColor:!0,children:['根据你的描述:"',G,'"']},void 0,!0,void 0,this)},void 0,!1,void 0,this),E(N0,{marginBottom:1,children:E(G0,{color:"gray",children:"正在调用 LLM 生成 agent 配置,请稍候..."},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}if(Y==="name"){let P=W==="edit";return E(N0,{flexDirection:"column",paddingY:1,children:[E(N0,{marginBottom:1,children:E(G0,{bold:!0,color:"cyan",children:["Step 1/7: ",P?"Agent 名称(不可修改)":"输入 Agent 名称"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),E(N0,{marginBottom:1,children:E(G0,{dimColor:!0,children:P?"编辑模式下名称不可修改(修改名称相当于创建新 Agent)":"名称只能包含小写字母、数字和连字符(例如:code-reviewer)"},void 0,!1,void 0,this)},void 0,!1,void 0,this),E(N0,{marginBottom:1,children:[E(G0,{color:"green",children:"名称: "},void 0,!1,void 0,this),P?E(G0,{children:Q.name},void 0,!1,void 0,this):E(g8,{value:Q.name,onChange:(b)=>K({...Q,name:b}),onSubmit:(b)=>{if(m5(b))return;H()}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E(N0,{children:E(G0,{dimColor:!0,children:P?"按 Enter 继续 | ESC 返回":"按 Enter 继续 | ESC 返回"},void 0,!1,void 0,this)},void 0,!1,void 0,this),P&&E(g8,{value:"",onChange:()=>{},onSubmit:H,showCursor:!1},"edit-mode-dummy-input",!1,void 0,this)]},void 0,!0,void 0,this)}if(Y==="description")return E(N0,{flexDirection:"column",paddingY:1,children:[E(N0,{marginBottom:1,children:E(G0,{bold:!0,color:"cyan",children:"Step 2/7: 输入描述信息"},void 0,!1,void 0,this)},void 0,!1,void 0,this),E(N0,{marginBottom:1,children:E(G0,{dimColor:!0,children:"简短描述这个 Agent 的用途和使用场景(这将帮助主 Agent 决定何时使用它)"},void 0,!1,void 0,this)},void 0,!1,void 0,this),E(N0,{marginBottom:1,children:[E(G0,{color:"green",children:"描述: "},void 0,!1,void 0,this),E(g8,{value:Q.description,onChange:(P)=>K({...Q,description:P}),onSubmit:(P)=>{if(!P.trim())return;H()}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E(N0,{children:E(G0,{dimColor:!0,children:"按 Enter 继续 | ESC 返回"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(Y==="tools")return E(p5,{config:Q,setConfig:K,onNext:H,onPrev:S},void 0,!1,void 0,this);if(Y==="color")return E(N0,{flexDirection:"column",paddingY:1,children:[E(N0,{marginBottom:1,children:E(G0,{bold:!0,color:"cyan",children:"Step 4/7: 选择背景颜色"},void 0,!1,void 0,this)},void 0,!1,void 0,this),E(N0,{marginBottom:1,children:E(G0,{dimColor:!0,children:"为 Agent 选择一个颜色标识(用于在 UI 中区分不同的 Agents)"},void 0,!1,void 0,this)},void 0,!1,void 0,this),E(E2,{items:g5,onSelect:(P)=>{let b=P.value==="none"?void 0:P.value;K({...Q,color:b}),H()}},void 0,!1,void 0,this),E(N0,{marginTop:1,children:E(G0,{dimColor:!0,children:"使用方向键选择 | Enter 确认 | ESC 返回"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(Y==="location")return E(N0,{flexDirection:"column",paddingY:1,children:[E(N0,{marginBottom:1,children:E(G0,{bold:!0,color:"cyan",children:"Step 5/7: 选择保存位置"},void 0,!1,void 0,this)},void 0,!1,void 0,this),E(N0,{marginBottom:1,children:E(G0,{dimColor:!0,children:"项目级配置仅在当前项目生效,用户级配置全局可用"},void 0,!1,void 0,this)},void 0,!1,void 0,this),E(E2,{items:[{label:"项目级 (.blade/agents/) - 仅当前项目",value:"project"},{label:"用户级 (~/.blade/agents/) - 全局可用",value:"user"}],onSelect:(P)=>{K({...Q,location:P.value}),H()}},void 0,!1,void 0,this),E(N0,{marginTop:1,children:E(G0,{dimColor:!0,children:"使用方向键选择 | Enter 确认 | ESC 返回"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(Y==="systemPrompt")return E(N0,{flexDirection:"column",paddingY:1,children:[E(N0,{marginBottom:1,children:E(G0,{bold:!0,color:"cyan",children:"Step 6/7: 输入系统提示词"},void 0,!1,void 0,this)},void 0,!1,void 0,this),E(N0,{marginBottom:1,children:E(G0,{dimColor:!0,children:"定义 Agent 的行为和职责(可选,留空将使用默认提示)"},void 0,!1,void 0,this)},void 0,!1,void 0,this),E(N0,{marginBottom:1,children:[E(G0,{color:"green",children:"提示词: "},void 0,!1,void 0,this),E(g8,{value:Q.systemPrompt,onChange:(P)=>K({...Q,systemPrompt:P}),onSubmit:()=>H()},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E(N0,{children:E(G0,{dimColor:!0,children:"按 Enter 继续 | ESC 返回"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(Y==="confirm")return E(N0,{flexDirection:"column",paddingY:1,children:[E(N0,{marginBottom:1,children:E(G0,{bold:!0,color:"cyan",children:"Step 7/7: 确认配置"},void 0,!1,void 0,this)},void 0,!1,void 0,this),E(N0,{flexDirection:"column",paddingLeft:2,marginBottom:1,children:[E(G0,{children:[E(G0,{bold:!0,color:"green",children:["名称:"," "]},void 0,!0,void 0,this),E(G0,{children:Q.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E(G0,{children:[E(G0,{bold:!0,color:"green",children:["描述:"," "]},void 0,!0,void 0,this),E(G0,{children:Q.description},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E(G0,{children:[E(G0,{bold:!0,color:"green",children:["工具:"," "]},void 0,!0,void 0,this),E(G0,{children:Q.tools.includes("all")?"所有工具":Q.tools.join(", ")||"所有工具"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E(G0,{children:[E(G0,{bold:!0,color:"green",children:["颜色:"," "]},void 0,!0,void 0,this),E(G0,{children:Q.color||"默认"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E(G0,{children:[E(G0,{bold:!0,color:"green",children:["位置:"," "]},void 0,!0,void 0,this),E(G0,{children:Q.location==="project"?"项目级":"用户级"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E(G0,{children:[E(G0,{bold:!0,color:"green",children:["提示词:"," "]},void 0,!0,void 0,this),E(G0,{children:Q.systemPrompt||"(使用默认)"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),E(E2,{items:[{label:"确认并保存",value:"save"},{label:"返回上一步",value:"back"},{label:"取消",value:"cancel"}],onSelect:(P)=>{if(P.value==="save")w();else if(P.value==="back")S();else J()}},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return null}function p5({config:$,setConfig:J,onNext:Z,onPrev:Y}){let{isFocused:X}=V5({id:"step-tools"});q0((K,G)=>{if(G.escape)Y()},{isActive:X});let Q=(K)=>{if(K.includes("all"))J({...$,tools:["all"]});else J({...$,tools:K});Z()};return E(N0,{flexDirection:"column",paddingY:1,children:[E(N0,{marginBottom:1,children:E(G0,{bold:!0,color:"cyan",children:"Step 3/7: 选择可用工具"},void 0,!1,void 0,this)},void 0,!1,void 0,this),E(N0,{marginBottom:1,children:E(G0,{dimColor:!0,children:"方向键导航,空格切换勾选,Enter 确认进入下一步 | ESC 返回上一步"},void 0,!1,void 0,this)},void 0,!1,void 0,this),E(D5,{options:h5,defaultValue:$.tools,onSubmit:Q},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import x5 from"node:fs";import{useMemoizedFn as x1}from"ahooks";import{Box as v0,Text as g0}from"ink";import j4 from"ink-select-input";import{useEffect as u5,useMemo as C6,useState as h2}from"react";import{jsxDEV as Y0}from"react/jsx-dev-runtime";var E4=10;function I6({workspaceRoot:$,initialMode:J="menu",onComplete:Z,onCancel:Y}){let X=T2($),[Q,K]=h2(J),[G,U]=h2(null),[q,O]=h2(0),[z,_]=h2(0),W=x1(()=>{X.clear(),X.loadFromStandardLocations(),O((T)=>T+1)}),L=C6(()=>{return X.getAllSubagents()},[q]),N=Math.ceil(L.length/E4)||1,A=C6(()=>{let T=z*E4;return L.slice(T,T+E4)},[L,z]);u5(()=>{let T=Math.max(0,N-1);if(z>T)_(T)},[N,z]);let I=x1(()=>{if(z<N-1)_((T)=>T+1)}),H=x1(()=>{if(z>0)_((T)=>T-1)}),S=[{key:"list",label:"查看所有 Agents",value:"list"},{key:"create",label:"创建新 Agent",value:"create"},{key:"edit",label:"编辑 Agent",value:"edit"},{key:"delete",label:"删除 Agent",value:"delete"},{key:"cancel",label:"取消",value:"cancel"}],B=x1((T)=>{if(T.value==="cancel"){Y?.();return}K(T.value)}),w=x1((T)=>{if(U(T.value),Q==="edit")K("editWizard");else if(Q==="delete")K("deleteConfirm")}),M=x1(async()=>{if(!G?.configPath)return;try{await x5.promises.unlink(G.configPath),W(),P()}catch(T){console.error("删除失败:",T)}}),P=x1(()=>{K("menu"),U(null)}),b=h0(!1,Y);if(q0((T,k)=>{if(k.escape){if(Q==="menu")Y?.();else if(Q==="list"||Q==="edit"||Q==="delete")_(0),P();else if(Q==="deleteConfirm")P()}else if(k.ctrl&&T==="c"||k.meta&&T==="c")b();else if(Q==="list"){if(k.leftArrow||T==="h")H();else if(k.rightArrow||T==="l")I()}},{isActive:Q!=="create"&&Q!=="editWizard"}),Q==="menu")return Y0(v0,{flexDirection:"column",paddingY:1,children:[Y0(v0,{marginBottom:1,children:Y0(g0,{bold:!0,color:"cyan",children:"Agents 管理"},void 0,!1,void 0,this)},void 0,!1,void 0,this),Y0(j4,{items:S,onSelect:B},void 0,!1,void 0,this),Y0(v0,{marginTop:1,children:Y0(g0,{dimColor:!0,children:"使用方向键选择 | Enter 确认 | ESC 退出"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(Q==="list"){if(L.length===0)return Y0(v0,{flexDirection:"column",paddingY:1,children:[Y0(v0,{marginBottom:1,children:Y0(g0,{bold:!0,color:"cyan",children:"所有 Agents"},void 0,!1,void 0,this)},void 0,!1,void 0,this),Y0(v0,{paddingLeft:2,children:Y0(g0,{color:"gray",children:"没有找到任何 agent 配置"},void 0,!1,void 0,this)},void 0,!1,void 0,this),Y0(v0,{marginTop:1,paddingLeft:2,children:Y0(g0,{color:"gray",children:"配置文件位置: .blade/agents/ 或 ~/.blade/agents/"},void 0,!1,void 0,this)},void 0,!1,void 0,this),Y0(v0,{marginTop:1,paddingLeft:2,children:Y0(g0,{dimColor:!0,children:"按 ESC 返回菜单"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return Y0(v0,{flexDirection:"column",paddingY:1,children:[Y0(v0,{marginBottom:1,children:[Y0(g0,{bold:!0,color:"cyan",children:"所有 Agents"},void 0,!1,void 0,this),Y0(g0,{color:"gray",children:[" (共 ",L.length," 个)"]},void 0,!0,void 0,this),N>1&&Y0(g0,{color:"yellow",children:[" ","第 ",z+1,"/",N," 页"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),A.map((T)=>Y0(v0,{flexDirection:"column",paddingLeft:2,children:[Y0(v0,{children:Y0(g0,{children:[Y0(g0,{bold:!0,color:T.color||"white",children:["• ",T.name]},void 0,!0,void 0,this),Y0(g0,{color:"gray",children:[" - ",T.description]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),T.tools&&T.tools.length>0&&Y0(v0,{paddingLeft:2,children:Y0(g0,{color:"gray",children:["工具: ",T.tools.join(", ")]},void 0,!0,void 0,this)},void 0,!1,void 0,this),T.configPath&&Y0(v0,{paddingLeft:2,children:Y0(g0,{color:"gray",dimColor:!0,children:T.configPath},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},T.name,!0,void 0,this)),Y0(v0,{marginTop:1,paddingLeft:2,children:N>1?Y0(g0,{dimColor:!0,children:"Left/Right to page | ESC 返回菜单"},void 0,!1,void 0,this):Y0(g0,{dimColor:!0,children:"按 ESC 返回菜单"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}let v=(T)=>{if(L.length===0)return Y0(v0,{flexDirection:"column",paddingY:1,children:[Y0(v0,{marginBottom:1,children:Y0(g0,{bold:!0,color:"cyan",children:T},void 0,!1,void 0,this)},void 0,!1,void 0,this),Y0(v0,{paddingLeft:2,children:Y0(g0,{color:"gray",children:"没有找到任何 agent 配置"},void 0,!1,void 0,this)},void 0,!1,void 0,this),Y0(v0,{marginTop:1,paddingLeft:2,children:Y0(g0,{dimColor:!0,children:"按 ESC 返回菜单"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this);let k=L.map((y)=>({key:y.name,label:`${y.name} - ${y.description}`,value:y}));return Y0(v0,{flexDirection:"column",paddingY:1,children:[Y0(v0,{marginBottom:1,children:Y0(g0,{bold:!0,color:"cyan",children:T},void 0,!1,void 0,this)},void 0,!1,void 0,this),Y0(j4,{items:k,onSelect:w},void 0,!1,void 0,this),Y0(v0,{marginTop:1,children:Y0(g0,{dimColor:!0,children:"使用方向键选择 | Enter 确认 | ESC 返回"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};if(Q==="create")return Y0(m8,{onComplete:()=>{W(),P()},onCancel:P},void 0,!1,void 0,this);if(Q==="edit")return v("编辑 Agent");if(Q==="editWizard"&&G){let T={name:G.name,description:G.description,tools:G.tools||[],color:G.color,location:G.configPath?.includes(".blade/agents")?"project":"user",systemPrompt:G.systemPrompt||""};return Y0(m8,{initialConfig:T,onComplete:()=>{W(),P()},onCancel:P},void 0,!1,void 0,this)}if(Q==="delete")return v("删除 Agent");if(Q==="deleteConfirm"&&G)return Y0(v0,{flexDirection:"column",paddingY:1,children:[Y0(v0,{marginBottom:1,children:Y0(g0,{bold:!0,color:"red",children:"确认删除"},void 0,!1,void 0,this)},void 0,!1,void 0,this),Y0(v0,{marginBottom:1,paddingLeft:2,children:Y0(g0,{children:["你确定要删除 Agent"," ",Y0(g0,{bold:!0,color:"yellow",children:G.name},void 0,!1,void 0,this)," ","吗?"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),Y0(v0,{marginBottom:1,paddingLeft:2,children:Y0(g0,{dimColor:!0,children:["文件路径: ",G.configPath]},void 0,!0,void 0,this)},void 0,!1,void 0,this),Y0(v0,{marginBottom:1,paddingLeft:2,children:Y0(g0,{color:"red",children:"此操作无法撤销!"},void 0,!1,void 0,this)},void 0,!1,void 0,this),Y0(j4,{items:[{label:"确认删除",value:"confirm"},{label:"取消",value:"cancel"}],onSelect:(T)=>{if(T.value==="confirm")M();else P()}},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return null}import{Box as O8,Text as W0}from"ink";import d5,{useEffect as l5,useState as r5}from"react";import{useEffect as c5,useState as S6}from"react";function v6($=Z$(),J=5000){let[Z,Y]=S6(null),[X,Q]=S6(!0);return c5(()=>{let K=!0,G=async()=>{try{let q=await k6($);if(!K)return;if(!q){Y(null),Q(!1);return}let O=await f6($);if(!K)return;Y(O)}catch{if(K)Y(null)}finally{if(K)Q(!1)}};G();let U=null;if(J>0)U=setInterval(G,J);return()=>{if(K=!1,U)clearInterval(U)}},[$,J]),{branch:Z,loading:X}}import{jsxDEV as X0,Fragment as m$}from"react/jsx-dev-runtime";var V6=d5.memo(()=>{let $=Z2(),J=Z8(),Y=J2()==="shortcuts",X=K9(),Q=o$(),{branch:K}=v6(Q),G=X2(),U=$9(),q=rJ(),O=K2(),z=G2(),_=U2(),W=q2(),L=z2(),N=aJ(),A=iJ(),I=Q8(),H=H9(),S=Y8(),[B,w]=r5(null);l5(()=>{let k=!1;new h4(Q,S).get().then((o)=>{if(!k)w(o)}).catch(()=>{if(!k)w(null)});let j=h4.subscribe((o)=>{if(!k&&o.sessionId===S&&o.workspaceRoot===Q)w(o.goal)});return()=>{k=!0,j()}},[S,Q]);let M=G?S2(G):!1,b=(()=>{if(J==="default")return null;if(J==="autoEdit")return X0(W0,{color:"magenta",children:[">> ","auto edit on ",X0(W0,{color:"gray",children:"(shift+tab to cycle)"},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(J==="plan")return X0(W0,{color:"cyan",children:["‖ plan mode on ",X0(W0,{color:"gray",children:"(shift+tab to cycle)"},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(J==="yolo")return X0(W0,{color:"red",children:["yolo mode on ",X0(W0,{color:"gray",children:"(all tools auto-approved)"},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return null})(),v=b!==null,T=[["Enter:发送","Shift+Enter:换行","Esc:中止"],["Shift+Tab:切换模式","Up/Down:历史","Tab:补全"],["Ctrl+A:行首","Ctrl+E:行尾","Ctrl+K:删到尾"],["Ctrl+U:删到首","Ctrl+W:删单词","Ctrl+C:退出"],["Ctrl+O:浏览记录","PgUp/PgDn:翻页","g/G:首尾"]];return X0(O8,{flexDirection:"row",justifyContent:"space-between",paddingX:2,paddingY:0,children:[Y?X0(O8,{flexDirection:"column",gap:0,children:T.map((k,y)=>X0(O8,{flexDirection:"row",children:[k.map((j,o)=>{let[t,a]=j.split(":");return X0(O8,{flexDirection:"row",width:20,children:[X0(W0,{color:"yellow",children:t},void 0,!1,void 0,this),X0(W0,{color:"gray",children:":"},void 0,!1,void 0,this),X0(W0,{color:"white",children:a},void 0,!1,void 0,this)]},o,!0,void 0,this)}),y===T.length-1&&X0(W0,{color:"cyan",children:" ? 关闭"},void 0,!1,void 0,this)]},y,!0,void 0,this))},void 0,!1,void 0,this):X0(O8,{flexDirection:"row",gap:1,children:[K&&X0(m$,{children:[X0(W0,{color:"gray",children:[" ",K]},void 0,!0,void 0,this),X0(W0,{color:"gray",children:"·"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),b,v&&X0(W0,{color:"gray",children:"·"},void 0,!1,void 0,this),B&&X0(m$,{children:[X0(W0,{color:B.status==="active"?"green":B.status==="verifying"?"cyan":B.status==="blocked"||B.status==="budget_limited"?"yellow":"gray",children:["goal:",B.status," ",B.objective.slice(0,32),B.prematureStop?` recovery:${B.prematureStop.consecutiveCount}`:"",B.verificationStall?` verify-gap:${B.verificationStall.consecutiveCount}`:"",B.frontierStall?` frontier:${B.frontierStall.category}:${B.frontierStall.consecutiveCount}`:""]},void 0,!0,void 0,this),X0(W0,{color:"gray",children:"·"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),X0(W0,{color:"gray",children:"? for shortcuts"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),X0(O8,{flexDirection:"row",gap:1,children:!$?X0(W0,{color:"red",children:"[WARN] API 密钥未配置"},void 0,!1,void 0,this):X0(m$,{children:[M&&X0(m$,{children:[O?X0(W0,{color:"cyan",children:["Effort ",z]},void 0,!0,void 0,this):X0(W0,{color:"gray",children:"Tab:Effort"},void 0,!1,void 0,this),X0(W0,{color:"gray",children:"·"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),_!=="auto"&&X0(m$,{children:[X0(W0,{color:_==="fast"?"yellow":"gray",children:["Speed ",_]},void 0,!0,void 0,this),X0(W0,{color:"gray",children:"·"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),W!=="auto"&&X0(m$,{children:[X0(W0,{color:"gray",children:["Output ",W]},void 0,!0,void 0,this),X0(W0,{color:"gray",children:"·"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),L!=="auto"&&X0(m$,{children:[X0(W0,{color:"gray",children:["Style ",L]},void 0,!0,void 0,this),X0(W0,{color:"gray",children:"·"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),G&&X0(W0,{color:"gray",children:G.model},void 0,!1,void 0,this),X0(W0,{color:"gray",children:"·"},void 0,!1,void 0,this),q?X0(W0,{color:"yellow",children:"压缩中..."},void 0,!1,void 0,this):X0(W0,{color:U<20?"red":U<50?"yellow":"gray",children:[U,"%"]},void 0,!0,void 0,this),X0(W0,{color:"gray",children:"·"},void 0,!1,void 0,this),X0(W0,{color:A===void 0?"gray":"cyan",children:["Cache ",D6(A)]},void 0,!0,void 0,this),N>0.001&&X0(m$,{children:[X0(W0,{color:"gray",children:"·"},void 0,!1,void 0,this),X0(W0,{color:"green",children:["$",N<0.01?N.toFixed(4):N.toFixed(3)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),I.length>0&&X0(m$,{children:[X0(W0,{color:"gray",children:"·"},void 0,!1,void 0,this),X0(W0,{color:"yellow",children:["已排队 ",I.length]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),H>0&&X0(m$,{children:[X0(W0,{color:"gray",children:"·"},void 0,!1,void 0,this),X0(W0,{color:"cyan",children:["已恢复 ",H," 条指令"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),X&&X0(m$,{children:[X0(W0,{color:"gray",children:"·"},void 0,!1,void 0,this),X0(W0,{color:"yellow",children:"再按一次 Ctrl+C 退出"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)});import{Box as g4,Text as m4}from"ink";import a5 from"react";import{jsxDEV as _8}from"react/jsx-dev-runtime";var j6=a5.memo(({suggestions:$,selectedIndex:J,visible:Z,maxDisplay:Y=8})=>{if(!Z||$.length===0)return null;let X=0,Q=Math.min(Y,$.length),K=J>=$.length;if(J>=Y&&!K)X=J-Y+1,Q=J+1;let G=$.slice(X,Q),U=$.length>Y;return _8(g4,{flexDirection:"column",paddingX:2,paddingY:0,children:[G.map((q,O)=>{let _=X+O===J;return _8(g4,{flexDirection:"row",paddingX:1,gap:2,children:[_8(m4,{color:_?"cyan":"white",bold:_,children:q.command},void 0,!1,void 0,this),_8(m4,{color:_?"cyan":"gray",dimColor:!_,children:["- ",q.description]},void 0,!0,void 0,this)]},q.command,!0,void 0,this)}),U&&_8(g4,{paddingX:1,children:_8(m4,{color:K?"cyan":"gray",bold:K,dimColor:!K,children:["... and ",$.length-Y," more"]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)});import{Box as v$,Text as s$,useStdout as rX}from"ink";import aX from"ink-select-input";import qJ,{useMemo as NY}from"react";import{Box as L0,Text as k0}from"ink";import c1,{useEffect as GJ,useMemo as u1,useRef as zY}from"react";import{Box as t4,Text as a6}from"ink";import GX from"react";import{Text as p$}from"ink";import XX from"react";import d6 from"string-width";import p8 from"string-width";function p4({onlyFirst:$=!1}={}){return new RegExp("(?:\\u001B\\][\\s\\S]*?(?:\\u0007|\\u001B\\u005C|\\u009C))|[\\u001B\\u009B][[\\]()#;?]*(?:\\d{1,4}(?:[;:]\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]",$?void 0:"g")}var i5=p4();function x4($){if(typeof $!=="string")throw TypeError(`Expected a \`string\`, got \`${typeof $}\``);if(!$.includes("\x1B")&&!$.includes(""))return $;return $.replace(i5,"")}var E6=($=0)=>(J)=>`\x1B[${J+$}m`,h6=($=0)=>(J)=>`\x1B[${38+$};5;${J}m`,g6=($=0)=>(J,Z,Y)=>`\x1B[${38+$};2;${J};${Z};${Y}m`,c0={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}},sq=Object.keys(c0.modifier),o5=Object.keys(c0.color),n5=Object.keys(c0.bgColor),eq=[...o5,...n5];function t5(){let $=new Map;for(let[J,Z]of Object.entries(c0)){for(let[Y,X]of Object.entries(Z))c0[Y]={open:`\x1B[${X[0]}m`,close:`\x1B[${X[1]}m`},Z[Y]=c0[Y],$.set(X[0],X[1]);Object.defineProperty(c0,J,{value:Z,enumerable:!1})}return Object.defineProperty(c0,"codes",{value:$,enumerable:!1}),c0.color.close="\x1B[39m",c0.bgColor.close="\x1B[49m",c0.color.ansi=E6(),c0.color.ansi256=h6(),c0.color.ansi16m=g6(),c0.bgColor.ansi=E6(10),c0.bgColor.ansi256=h6(10),c0.bgColor.ansi16m=g6(10),Object.defineProperties(c0,{rgbToAnsi256:{value(J,Z,Y){if(J===Z&&Z===Y){if(J<8)return 16;if(J>248)return 231;return Math.round((J-8)/247*24)+232}return 16+36*Math.round(J/255*5)+6*Math.round(Z/255*5)+Math.round(Y/255*5)},enumerable:!1},hexToRgb:{value(J){let Z=/[a-f\d]{6}|[a-f\d]{3}/i.exec(J.toString(16));if(!Z)return[0,0,0];let[Y]=Z;if(Y.length===3)Y=[...Y].map((Q)=>Q+Q).join("");let X=Number.parseInt(Y,16);return[X>>16&255,X>>8&255,X&255]},enumerable:!1},hexToAnsi256:{value:(J)=>c0.rgbToAnsi256(...c0.hexToRgb(J)),enumerable:!1},ansi256ToAnsi:{value(J){if(J<8)return 30+J;if(J<16)return 90+(J-8);let Z,Y,X;if(J>=232)Z=((J-232)*10+8)/255,Y=Z,X=Z;else{J-=16;let G=J%36;Z=Math.floor(J/36)/5,Y=Math.floor(G/6)/5,X=G%6/5}let Q=Math.max(Z,Y,X)*2;if(Q===0)return 30;let K=30+(Math.round(X)<<2|Math.round(Y)<<1|Math.round(Z));if(Q===2)K+=60;return K},enumerable:!1},rgbToAnsi:{value:(J,Z,Y)=>c0.ansi256ToAnsi(c0.rgbToAnsi256(J,Z,Y)),enumerable:!1},hexToAnsi:{value:(J)=>c0.ansi256ToAnsi(c0.hexToAnsi256(J)),enumerable:!1}}),c0}var s5=t5(),m6=s5;var m2=new Set(["\x1B",""]),e5=39,c4="\x07",u6="[",$X="]",c6="m",g2=`${$X}8;;`,p6=($)=>`${m2.values().next().value}${u6}${$}${c6}`,x6=($)=>`${m2.values().next().value}${g2}${$}${c4}`,JX=($)=>$.split(" ").map((J)=>p8(J)),u4=($,J,Z)=>{let Y=[...J],X=!1,Q=!1,K=p8(x4($.at(-1)));for(let[G,U]of Y.entries()){let q=p8(U);if(K+q<=Z)$[$.length-1]+=U;else $.push(U),K=0;if(m2.has(U))X=!0,Q=Y.slice(G+1,G+1+g2.length).join("")===g2;if(X){if(Q){if(U===c4)X=!1,Q=!1}else if(U===c6)X=!1;continue}if(K+=q,K===Z&&G<Y.length-1)$.push(""),K=0}if(!K&&$.at(-1).length>0&&$.length>1)$[$.length-2]+=$.pop()},YX=($)=>{let J=$.split(" "),Z=J.length;while(Z>0){if(p8(J[Z-1])>0)break;Z--}if(Z===J.length)return $;return J.slice(0,Z).join(" ")+J.slice(Z).join("")},ZX=($,J,Z={})=>{if(Z.trim!==!1&&$.trim()==="")return"";let Y="",X,Q,K=JX($),G=[""];for(let[z,_]of $.split(" ").entries()){if(Z.trim!==!1)G[G.length-1]=G.at(-1).trimStart();let W=p8(G.at(-1));if(z!==0){if(W>=J&&(Z.wordWrap===!1||Z.trim===!1))G.push(""),W=0;if(W>0||Z.trim===!1)G[G.length-1]+=" ",W++}if(Z.hard&&K[z]>J){let L=J-W,N=1+Math.floor((K[z]-L-1)/J);if(Math.floor((K[z]-1)/J)<N)G.push("");u4(G,_,J);continue}if(W+K[z]>J&&W>0&&K[z]>0){if(Z.wordWrap===!1&&W<J){u4(G,_,J);continue}G.push("")}if(W+K[z]>J&&Z.wordWrap===!1){u4(G,_,J);continue}G[G.length-1]+=_}if(Z.trim!==!1)G=G.map((z)=>YX(z));let U=G.join(`
|
|
122
122
|
`),q=[...U],O=0;for(let[z,_]of q.entries()){if(Y+=_,m2.has(_)){let{groups:L}=new RegExp(`(?:\\${u6}(?<code>\\d+)m|\\${g2}(?<uri>.*)${c4})`).exec(U.slice(O))||{groups:{}};if(L.code!==void 0){let N=Number.parseFloat(L.code);X=N===e5?void 0:N}else if(L.uri!==void 0)Q=L.uri.length===0?void 0:L.uri}let W=m6.codes.get(Number(X));if(q[z+1]===`
|
|
123
123
|
`){if(Q)Y+=x6("");if(X&&W)Y+=p6(W)}else if(_===`
|
|
124
124
|
`){if(X&&W)Y+=p6(X);if(Q)Y+=x6(Q)}O+=_.length}return Y};function d4($,J,Z){return String($).normalize().replaceAll(`\r
|