blade-code 0.10.205 → 0.11.1

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.
Files changed (184) hide show
  1. package/dist/blade.js +2 -2
  2. package/dist/{chunk-7ajvrtb3.js → chunk-06hkf59s.js} +1 -1
  3. package/dist/{chunk-p0wyhp5a.js → chunk-0b83mt1c.js} +2 -2
  4. package/dist/{chunk-qtwgm95z.js → chunk-0wcnkxe8.js} +3 -3
  5. package/dist/{chunk-b8ast0cp.js → chunk-1beqtjsw.js} +1 -1
  6. package/dist/chunk-1kxpnt9q.js +1 -0
  7. package/dist/chunk-25s0c8km.js +1726 -0
  8. package/dist/{chunk-ak5xvsxr.js → chunk-27bjk35b.js} +1 -1
  9. package/dist/{chunk-515yj7mt.js → chunk-2ftyzk83.js} +1 -1
  10. package/dist/chunk-2g3v9qpz.js +1 -0
  11. package/dist/{chunk-5zmp7p0n.js → chunk-2vrsfb8p.js} +59 -59
  12. package/dist/{chunk-17d4m89n.js → chunk-30p7aff1.js} +2 -2
  13. package/dist/{chunk-kehgewqh.js → chunk-3kszepm6.js} +1 -1
  14. package/dist/{chunk-ys8gysg8.js → chunk-3y2x6fb6.js} +1 -1
  15. package/dist/chunk-43gg1wdc.js +1 -0
  16. package/dist/{chunk-xbs91jd8.js → chunk-447ps2te.js} +2 -2
  17. package/dist/{chunk-0eajnhrj.js → chunk-4cdk4mds.js} +1 -1
  18. package/dist/{chunk-8pd1hp4r.js → chunk-5034apfz.js} +2 -2
  19. package/dist/{chunk-ynd1v33f.js → chunk-5bc4hwt9.js} +1 -1
  20. package/dist/chunk-72wn385d.js +1 -0
  21. package/dist/chunk-7eset766.js +25 -0
  22. package/dist/chunk-7vzz3rsx.js +332 -0
  23. package/dist/{chunk-xxbxc31z.js → chunk-80946c9a.js} +1 -1
  24. package/dist/chunk-8emp6ysb.js +1 -0
  25. package/dist/chunk-8evyh5t0.js +1 -0
  26. package/dist/chunk-8hdtssvs.js +1 -0
  27. package/dist/chunk-8n3jythp.js +733 -0
  28. package/dist/{chunk-zj1g4nbq.js → chunk-8sth12hd.js} +1 -1
  29. package/dist/{chunk-fdr4fcrf.js → chunk-9qxch6sy.js} +1 -1
  30. package/dist/chunk-9ydrwcpy.js +3 -0
  31. package/dist/chunk-9yn01a90.js +12 -0
  32. package/dist/chunk-a1tt14a2.js +2 -0
  33. package/dist/{chunk-egss0m1x.js → chunk-a731hdwa.js} +1 -1
  34. package/dist/{chunk-gn9er641.js → chunk-a74ynw4t.js} +1 -1
  35. package/dist/chunk-b36egepz.js +1 -0
  36. package/dist/chunk-dxq7462e.js +352 -0
  37. package/dist/{chunk-eg3ms291.js → chunk-f552hzcx.js} +1 -1
  38. package/dist/{chunk-g01mth5d.js → chunk-f6hc7t65.js} +2 -2
  39. package/dist/{chunk-qq5y7b2r.js → chunk-fqxzzsgr.js} +1 -1
  40. package/dist/{chunk-xyypxrad.js → chunk-g0hhqxpg.js} +1 -1
  41. package/dist/{chunk-4wx5sya5.js → chunk-gzbb747a.js} +1 -1
  42. package/dist/{chunk-w42j9p3t.js → chunk-h8w3ahnk.js} +1 -1
  43. package/dist/chunk-hmw99nm1.js +94 -0
  44. package/dist/chunk-hrtf7dba.js +2 -0
  45. package/dist/chunk-j7dx054r.js +1 -0
  46. package/dist/chunk-j9ppeg6v.js +1 -0
  47. package/dist/chunk-jemb0vwa.js +1 -0
  48. package/dist/{chunk-qdbbke8f.js → chunk-m30qwpe9.js} +1 -1
  49. package/dist/{chunk-kvp523gt.js → chunk-m70cnaeg.js} +1 -1
  50. package/dist/{chunk-rtwd35gd.js → chunk-m8te4s8f.js} +2 -2
  51. package/dist/chunk-ms0wve9g.js +14 -0
  52. package/dist/{chunk-wezr6wfq.js → chunk-n8qg68y2.js} +1 -1
  53. package/dist/chunk-pm5ssr7m.js +25 -0
  54. package/dist/chunk-r9m3b170.js +1 -0
  55. package/dist/chunk-rt3f4xjz.js +23 -0
  56. package/dist/{chunk-430b319j.js → chunk-s1cch8tt.js} +1 -1
  57. package/dist/chunk-sa9fxss4.js +2 -0
  58. package/dist/{chunk-xmymx75h.js → chunk-ta99scbr.js} +1 -1
  59. package/dist/chunk-tf1qz4q6.js +1 -0
  60. package/dist/{chunk-efjjkha8.js → chunk-tqt5c2f5.js} +2 -2
  61. package/dist/{chunk-9jz1q7bk.js → chunk-ts5xzefm.js} +2 -2
  62. package/dist/chunk-v17q4bsd.js +6 -0
  63. package/dist/{chunk-qp2qc4p2.js → chunk-v1k6nvth.js} +2 -2
  64. package/dist/{chunk-1cy4ab77.js → chunk-vbjgcn49.js} +1 -1
  65. package/dist/{chunk-kkzznz4w.js → chunk-wcps5gjm.js} +1 -1
  66. package/dist/{chunk-vz88tqtd.js → chunk-xcj23spc.js} +2 -2
  67. package/dist/chunk-xcy45yxx.js +8 -0
  68. package/dist/chunk-xseh3f4m.js +2 -0
  69. package/dist/chunk-xz7dddaj.js +4 -0
  70. package/dist/{chunk-c51wwnh2.js → chunk-xzva8y4e.js} +5 -6
  71. package/dist/chunk-y0wc0hef.js +10 -0
  72. package/dist/chunk-yrr9mdjn.js +44 -0
  73. package/dist/{chunk-f8kjdxz7.js → chunk-zjezws85.js} +2 -2
  74. package/dist/web/assets/ChatView-BA3kB_z1.js +17 -0
  75. package/dist/web/assets/CodeBlockHighlighter-B5kcdVCA.js +8 -0
  76. package/dist/web/assets/FilePreview-BQid6G2-.js +8 -0
  77. package/dist/web/assets/KanbanBoard-CTR7bMLa.js +1 -0
  78. package/dist/web/assets/MarkdownRenderer-d7DdyYdx.js +30 -0
  79. package/dist/web/assets/ScrollArea-D1tPWHKZ.js +1 -0
  80. package/dist/web/assets/SessionHistorySurface-Cv_jRoJr.js +1 -0
  81. package/dist/web/assets/SettingsModal-CFa2uCzI.js +5 -0
  82. package/dist/web/assets/Sidebar-DrRNJOgU.js +1 -0
  83. package/dist/web/assets/TaskSwitcher-C9AKJrl-.js +1 -0
  84. package/dist/web/assets/TerminalPanel-BxBGcuB9.js +1 -0
  85. package/dist/web/assets/archive-DNa9b1YE.js +1 -0
  86. package/dist/web/assets/arrow-left-BQh8jlfT.js +1 -0
  87. package/dist/web/assets/calendar-clock-CC7FeYTg.js +1 -0
  88. package/dist/web/assets/chevron-right-6ZTOJE0p.js +1 -0
  89. package/dist/web/assets/clock-3-P2q6i6vm.js +1 -0
  90. package/dist/web/assets/copy-C-KvzjCC.js +1 -0
  91. package/dist/web/assets/dist-DiQNoDMg.js +11 -0
  92. package/dist/web/assets/download-CJHn20x1.js +1 -0
  93. package/dist/web/assets/folder-DmyFehXD.js +1 -0
  94. package/dist/web/assets/index-BVEiHNFk.css +1 -0
  95. package/dist/web/assets/index-D-oma3Je.js +11 -0
  96. package/dist/web/assets/message-square-plus-CKu9bFq3.js +1 -0
  97. package/dist/web/assets/pause-D2FxNG-w.js +1 -0
  98. package/dist/web/assets/pencil-D6HI7KC8.js +1 -0
  99. package/dist/web/assets/play-4jKCDYR-.js +1 -0
  100. package/dist/web/assets/plus-C4p8E1Nk.js +1 -0
  101. package/dist/web/assets/preload-helper-BC9Zf9qO.js +1 -0
  102. package/dist/web/assets/rolldown-runtime-hePW80VL.js +1 -0
  103. package/dist/web/assets/session-events-CvFfHkFA.js +23 -0
  104. package/dist/web/assets/settings-fWlqCZ-U.js +1 -0
  105. package/dist/web/assets/team-qGS2kixH.js +1 -0
  106. package/dist/web/assets/teamService-DfIvlI2_.js +1 -0
  107. package/dist/web/assets/terminal-DZkEoiSb.js +1 -0
  108. package/dist/web/assets/triangle-alert-Detl9fRQ.js +1 -0
  109. package/dist/web/assets/vendor-radix-CHeA_3Pt.js +41 -0
  110. package/dist/web/assets/vendor-react-hNfZDUf2.js +9 -0
  111. package/dist/web/assets/vendor-xterm-CANZO_wP.js +16 -0
  112. package/dist/web/assets/vendor-xterm-CHOd7Rch.css +1 -0
  113. package/dist/web/index.html +6 -4
  114. package/package.json +11 -10
  115. package/dist/chunk-18swytk4.js +0 -25
  116. package/dist/chunk-3297ghav.js +0 -1
  117. package/dist/chunk-33ck9ryb.js +0 -1
  118. package/dist/chunk-4fa11h6f.js +0 -94
  119. package/dist/chunk-535s1mm8.js +0 -1
  120. package/dist/chunk-57939tb3.js +0 -8
  121. package/dist/chunk-6169xxb4.js +0 -2
  122. package/dist/chunk-6v0cdqkw.js +0 -1
  123. package/dist/chunk-8kwj6px8.js +0 -1
  124. package/dist/chunk-a8z11yd2.js +0 -3
  125. package/dist/chunk-aatfjx15.js +0 -2
  126. package/dist/chunk-b2ek44t5.js +0 -12
  127. package/dist/chunk-b9d0ex8n.js +0 -4
  128. package/dist/chunk-bwe49m6n.js +0 -1719
  129. package/dist/chunk-ccgtbzrz.js +0 -14
  130. package/dist/chunk-jgxfhk9k.js +0 -733
  131. package/dist/chunk-jhpwwwjt.js +0 -1
  132. package/dist/chunk-jjj86dej.js +0 -1
  133. package/dist/chunk-kejvty9z.js +0 -23
  134. package/dist/chunk-kf9gj2gn.js +0 -2
  135. package/dist/chunk-mhe1zppc.js +0 -1
  136. package/dist/chunk-pb1q26gw.js +0 -181
  137. package/dist/chunk-pc5f77qh.js +0 -1
  138. package/dist/chunk-pkx6kfy6.js +0 -1
  139. package/dist/chunk-qjptyj18.js +0 -1
  140. package/dist/chunk-shgxzmdw.js +0 -1
  141. package/dist/chunk-thytjs86.js +0 -44
  142. package/dist/chunk-tm3789m3.js +0 -2
  143. package/dist/chunk-tnmcrvk2.js +0 -25
  144. package/dist/chunk-wejthch2.js +0 -1
  145. package/dist/chunk-xv6ejk2z.js +0 -353
  146. package/dist/chunk-yvgef7rp.js +0 -10
  147. package/dist/chunk-zj48897e.js +0 -6
  148. package/dist/web/assets/ChatView-BF6HUrBw.js +0 -70
  149. package/dist/web/assets/CodeBlockHighlighter-C4CgCiRf.js +0 -8
  150. package/dist/web/assets/FilePreview-BS4PgFKb.js +0 -55
  151. package/dist/web/assets/KanbanBoard-DDXB-yq1.js +0 -16
  152. package/dist/web/assets/MarkdownRenderer-DS7RznBE.js +0 -30
  153. package/dist/web/assets/ScrollArea-BM9NzGZM.js +0 -1
  154. package/dist/web/assets/SessionHistorySurface-DnRySeLE.js +0 -6
  155. package/dist/web/assets/SettingsModal-D5YLUtIo.js +0 -20
  156. package/dist/web/assets/Sidebar-BZC6OkDJ.js +0 -31
  157. package/dist/web/assets/TaskSwitcher-WewOkw5m.js +0 -26
  158. package/dist/web/assets/TerminalPanel-C5SGdRNr.js +0 -6
  159. package/dist/web/assets/archive-DkczUU08.js +0 -6
  160. package/dist/web/assets/arrow-left-9pBiQwu7.js +0 -6
  161. package/dist/web/assets/calendar-clock-BFnUlxrU.js +0 -6
  162. package/dist/web/assets/chevron-right-yCVkAEcj.js +0 -6
  163. package/dist/web/assets/clock-3-CcoWoRQs.js +0 -6
  164. package/dist/web/assets/copy-HJF0oQBS.js +0 -6
  165. package/dist/web/assets/download-DSBCIqk3.js +0 -6
  166. package/dist/web/assets/external-link-zIgEO0KB.js +0 -11
  167. package/dist/web/assets/folder-BdRo64o3.js +0 -11
  168. package/dist/web/assets/index-B5mUEr6D.js +0 -11
  169. package/dist/web/assets/index-BVDkKudh.js +0 -211
  170. package/dist/web/assets/index-CaCifsSK.css +0 -1
  171. package/dist/web/assets/message-square-plus-3klTXO0S.js +0 -21
  172. package/dist/web/assets/pause-B9Q5JWvH.js +0 -6
  173. package/dist/web/assets/pencil-CbYIz1b1.js +0 -6
  174. package/dist/web/assets/play-CZMTj43e.js +0 -6
  175. package/dist/web/assets/plus-Cc7I8fhb.js +0 -6
  176. package/dist/web/assets/session-events-NEjosinC.js +0 -31
  177. package/dist/web/assets/settings-DSF3exX2.js +0 -6
  178. package/dist/web/assets/team-qfeJHL9s.js +0 -6
  179. package/dist/web/assets/teamService-Bs9qBKI8.js +0 -1
  180. package/dist/web/assets/terminal-DQLqe-Ed.js +0 -6
  181. package/dist/web/assets/vendor-radix-D6QrtXqd.js +0 -45
  182. package/dist/web/assets/vendor-react-DofNRwfy.js +0 -49
  183. package/dist/web/assets/vendor-xterm-9CEnUXvW.css +0 -32
  184. package/dist/web/assets/vendor-xterm-DuYZoU4T.js +0 -49
@@ -1,3 +0,0 @@
1
- import{fk as K}from"./chunk-4wx5sya5.js";import{appendFileSync as Y,existsSync as Z,mkdirSync as _,readdirSync as f,statSync as M,unlinkSync as p}from"node:fs";import x from"node:path";var E;((T)=>{T[T.DEBUG=0]="DEBUG";T[T.INFO=1]="INFO";T[T.WARN=2]="WARN";T[T.ERROR=3]="ERROR"})(E||={});var t=null,G=null,H=!1;function S(n){if(t!==n)t=n}async function b(){}function z(){if(H)return G;H=!0;try{let n=x.join(K(),"logs");if(!Z(n))_(n,{recursive:!0,mode:493});if(M(n).uid===0&&process.getuid&&process.getuid()!==0)return console.error(""),console.error("[FAIL] 权限错误:~/.blade/logs 目录属于 root 用户"),console.error(""),console.error("这通常是因为您曾经使用 sudo 运行过 blade。"),console.error(""),console.error("解决方法:"),console.error(" sudo chown -R $USER:$USER ~/.blade/"),console.error(""),console.error("然后重新运行 blade(不要使用 sudo)"),console.error(""),null;return B(n,30),G=n,n}catch(n){return console.error("[Logger] 无法创建日志目录:",n),null}}function B(n,u){try{let c=f(n),w=Date.now(),T=u*24*60*60*1000;for(let $ of c){if(!$.startsWith("blade-")||!$.endsWith(".log")&&!$.endsWith(".jsonl"))continue;let m=x.join(n,$);try{let q=M(m);if(w-q.mtimeMs>T)p(m)}catch(q){}}}catch(c){}}function J(){let n=z();if(!n)return null;let u=t||"default";return x.join(n,`blade-${u}.jsonl`)}function U(n,u,c){let w=J();if(!w)return;try{let T={timestamp:new Date().toISOString(),level:E[u],category:n,message:c};Y(w,JSON.stringify(T)+`
2
- `)}catch(T){}}class k{static globalDebugConfig=null;enabled;minLevel;category;constructor(n={}){if(n.enabled!==void 0)this.enabled=n.enabled;else if(k.globalDebugConfig!==null)this.enabled=Boolean(k.globalDebugConfig);else this.enabled=!1;this.minLevel=n.minLevel??0,this.category=n.category??"General"}static setGlobalDebug(n){k.globalDebugConfig=n}static clearGlobalDebug(){k.globalDebugConfig=null}setEnabled(n){this.enabled=n}parseDebugFilter(n){if(!n)return{enabled:!1};if(n===!0||n==="true"||n==="1")return{enabled:!0};let u=String(n).trim();if(!u)return{enabled:!0};if(u.startsWith("!"))return{enabled:!0,filter:{mode:"exclude",categories:u.split(",").map((T)=>T.trim().replace(/^!/,"")).filter(Boolean)}};return{enabled:!0,filter:{mode:"include",categories:u.split(",").map((w)=>w.trim()).filter(Boolean)}}}shouldLogCategory(n){if(!n)return!0;let u=this.category.toLowerCase();if(n.mode==="include")return n.categories.some((c)=>u.includes(c.toLowerCase()));return!n.categories.some((c)=>u.includes(c.toLowerCase()))}shouldLogToConsole(n){if(k.globalDebugConfig!==null){let{enabled:u,filter:c}=this.parseDebugFilter(k.globalDebugConfig);if(!u)return!1;if(n<this.minLevel)return!1;return this.shouldLogCategory(c)}return this.enabled&&n>=this.minLevel}log(n,...u){let c=u.map((w)=>typeof w==="object"?JSON.stringify(w):String(w)).join(" ");if(U(this.category,n,c),this.shouldLogToConsole(n)){let w=E[n],T=`[${this.category}] [${w}]`;console.error(T,...u)}}debug(...n){this.log(0,...n)}info(...n){this.log(1,...n)}warn(...n){this.log(2,...n)}error(...n){this.log(3,...n)}}function h(n,u){return new k({...u,category:n})}var s=new k({category:"General"});import F from"typebox/schema";import R from"typebox/value";class A extends Error{issues;constructor(n){super(n.map((u)=>{return`${u.path.length>0?u.path.join("."):"root"}: ${u.message}`}).join("; "));this.issues=n;this.name="SchemaValidationError"}}function O(n){if(!n)return[];return n.split("/").slice(1).map((u)=>u.replace(/~1/g,"/").replace(/~0/g,"~")).map((u)=>/^(0|[1-9]\d*)$/.test(u)?Number(u):u)}function P(n,u){let c=n;for(let w of u){if(c===null||typeof c!=="object")return;c=c[w]}return c}function Q(n,u){let[,c]=F.Errors(n,u);return c.map((w)=>{let T=O(w.instancePath);return{code:w.keyword,path:T,message:w.message,value:P(u,T)}})}function j(n,u){let c=R.Default(n,R.Clone(u)),w=Q(n,c);if(w.length>0)return{success:!1,error:new A(w)};let T=R.Clean(n,c),$=Q(n,T);if($.length>0)return{success:!1,error:new A($)};return{success:!0,data:T}}function W(n,u){let c=j(n,u);if(!c.success)throw c.error;return c.data}import X from"typebox";function i(n){return Object.defineProperties(n,{parse:{value:(u)=>W(n,u),enumerable:!1},safeParse:{value:(u)=>j(n,u),enumerable:!1}}),n}function a(n,u){return X.Optional({...n,default:u})}function L(n,u={}){return X.Unsafe({type:"string",enum:[...n],...u})}
3
- export{S as Bj,b as Cj,k as Dj,h as Ej,s as Fj,j as Gj,W as Hj,X as Ij,i as Jj,a as Kj,L as Lj};
@@ -1,2 +0,0 @@
1
- import{Di as H,Ei as I}from"./chunk-thytjs86.js";import{Mutex as J}from"async-mutex";class B extends Error{limit;resource="resident_runtimes";retryable=!0;constructor(b){super("Session runtime capacity is full");this.limit=b;this.name="SessionRuntimeCapacityError"}}class D extends Error{constructor(){super("Session runtime residency is closed");this.name="SessionRuntimeResidencyClosedError"}}class A extends Error{constructor(b){super(`Session runtime residency already owns key: ${b}`);this.name="SessionRuntimeResidencyConflictError"}}class K{maxResident;idleMs;now;residents=new Map;reservations=new Map;operations=new J;nextGeneration=1;closed=!1;constructor(b){if(!H(b.maxResident))throw Error("Invalid max resident Session Runtime limit");if(!I(b.idleMs))throw Error("Invalid Session Runtime idle timeout");this.maxResident=b.maxResident,this.idleMs=b.idleMs,this.now=b.now??Date.now}acquire(b){let j=this.residents.get(b);if(!j||j.poisoned)return;return j.pins++,j.lastUsedAt=this.now(),this.createLease(j)}owns(b,j){let q=this.residents.get(b);return Boolean(q&&(j===void 0||q.value===j))}async reserve(b,j){if(!b.trim())throw Error("Session runtime residency key must not be blank");return this.operations.runExclusive(async()=>{if(this.closed)throw new D;if(this.residents.has(b)||this.reservations.has(b))throw new A(b);while(this.retainedCount()>=this.maxResident){if(!j.allowEviction)throw new B(this.maxResident);let z=this.oldestEvictableWebResident();if(!z)throw new B(this.maxResident);await this.disposeResident(z,!0)}let q={generation:this.allocateGeneration(),surface:j.surface};return this.reservations.set(b,q),this.createReservation(b,q)})}async remove(b,j){return this.operations.runExclusive(async()=>{let q=this.residents.get(b);if(!q||j!==void 0&&q.value!==j)return!1;if(q.pins>0)return!1;return await this.disposeResident(q,!0),!0})}async forget(b,j){return this.operations.runExclusive(async()=>{let q=this.residents.get(b);if(!q||j!==void 0&&q.value!==j||q.pins>0)return!1;return this.residents.delete(b),!0})}async sweepIdle(){return this.operations.runExclusive(async()=>{if(this.closed)return 0;let b=0;while(!0){let j=this.oldestIdleWebResident();if(!j)return b;await this.disposeResident(j,!0),b++}})}async disposeAll(){await this.operations.runExclusive(async()=>{this.closed=!0,this.reservations.clear();let b;for(let j of[...this.residents.values()])try{await this.disposeResident(j,!1)}catch(q){b??=q}if(this.residents.clear(),b!==void 0)throw b})}getStats(){let b=0;for(let j of this.residents.values())if(j.pins>0)b++;return{resident:this.residents.size,reserved:this.reservations.size,pinned:b,maxResident:this.maxResident}}retainedCount(){return this.residents.size+this.reservations.size}allocateGeneration(){let b=this.nextGeneration;return this.nextGeneration=this.nextGeneration===Number.MAX_SAFE_INTEGER?1:this.nextGeneration+1,b}createReservation(b,j){let q=!1;return{commit:(z)=>{if(q)throw new A(b);if(z.key!==b||z.surface!==j.surface||this.reservations.get(b)!==j||this.closed)throw this.reservations.delete(b),q=!0,this.closed?new D:new A(b);this.reservations.delete(b);let G={...z,generation:j.generation,pins:1,lastUsedAt:this.now(),poisoned:!1};return this.residents.set(b,G),q=!0,this.createLease(G)},cancel:()=>{if(q)return;if(this.reservations.get(b)===j)this.reservations.delete(b);q=!0}}}createLease(b){let j=!1;return{value:b.value,release:()=>{if(j)return;j=!0;let q=this.residents.get(b.key);if(q!==b||q.generation!==b.generation)return;q.pins=Math.max(0,q.pins-1),q.lastUsedAt=this.now()}}}oldestEvictableWebResident(){return this.sortedWebResidents().find((b)=>this.canEvict(b))}oldestIdleWebResident(){let b=this.now();return this.sortedWebResidents().find((j)=>b-j.lastUsedAt>=this.idleMs&&this.canEvict(j))}sortedWebResidents(){return[...this.residents.values()].filter((b)=>b.surface==="web").sort((b,j)=>b.lastUsedAt-j.lastUsedAt||b.generation-j.generation)}canEvict(b){if(b.pins>0||b.poisoned)return!1;try{return b.canEvict()}catch{return!1}}async disposeResident(b,j){if(this.residents.get(b.key)!==b)return;this.residents.delete(b.key);try{await b.dispose()}catch(q){if(j&&!this.closed&&!this.residents.has(b.key))b.lastUsedAt=this.now(),b.poisoned=!0,this.residents.set(b.key,b);throw q}}}
2
- export{B as v,K as w};
@@ -1,12 +0,0 @@
1
- import{p as c,q as v,r as d,s as m,t as l,u as a}from"./chunk-b9d0ex8n.js";import{da as O,ka as S}from"./chunk-bwe49m6n.js";import"./chunk-g01mth5d.js";import"./chunk-tnmcrvk2.js";import"./chunk-kf9gj2gn.js";import{Zb as M,ic as E}from"./chunk-pb1q26gw.js";import"./chunk-fdr4fcrf.js";import{ie as f}from"./chunk-4fa11h6f.js";import"./chunk-egss0m1x.js";import{Ne as h}from"./chunk-xv6ejk2z.js";import"./chunk-efjjkha8.js";import{sf as I}from"./chunk-9jz1q7bk.js";import{uf as y,vf as R,wf as g}from"./chunk-rtwd35gd.js";import{xf as C}from"./chunk-8pd1hp4r.js";import"./chunk-p0wyhp5a.js";import{Uf as w}from"./chunk-18swytk4.js";import"./chunk-5yyp6njq.js";import"./chunk-v508x7cg.js";import"./chunk-57939tb3.js";import"./chunk-ynd1v33f.js";import"./chunk-w42j9p3t.js";import"./chunk-zfxcef0z.js";import"./chunk-xyypxrad.js";import"./chunk-jgxfhk9k.js";import"./chunk-kehgewqh.js";import"./chunk-kkzznz4w.js";import"./chunk-1cy4ab77.js";import"./chunk-7ajvrtb3.js";import"./chunk-c51wwnh2.js";import"./chunk-ys8gysg8.js";import{Fh as A}from"./chunk-thytjs86.js";import"./chunk-tm3789m3.js";import{cj as P}from"./chunk-qdbbke8f.js";import"./chunk-wezr6wfq.js";import"./chunk-a8z11yd2.js";import"./chunk-qtwgm95z.js";import"./chunk-0eajnhrj.js";import"./chunk-6169xxb4.js";import"./chunk-f8kjdxz7.js";import"./chunk-4wx5sya5.js";import"./chunk-eg3ms291.js";import s from"yargs";import{hideBin as e}from"yargs/helpers";var i=new Set(Object.values(A));function t(j){if(j&&i.has(j))return j;return}function z(j){if(j.options.outputFormat==="json")j.io.stdout.write(`${JSON.stringify({response:j.response,...j.structuredOutput?{structured_output:j.structuredOutput,output_schema_digest:j.structuredOutputSchemaDigest}:{},input:j.requestInput,model:j.options.model,timestamp:new Date().toISOString()},null,2)}
2
- `);else if(j.options.outputFormat==="stream-json")j.io.stdout.write(`${JSON.stringify(j.structuredOutput?{type:"structured_output",output:j.structuredOutput,schema_digest:j.structuredOutputSchemaDigest}:{type:"response",content:j.response})}
3
- `);else j.io.stdout.write(`${j.response}
4
- `)}function n(j){return j.command("* [message]","Print response and exit (useful for pipes)",(B)=>B.positional("message",{describe:"Message to process",type:"string"}).option("p",{alias:"print",describe:"Print response and exit (useful for pipes)",type:"boolean"}).option("output-format",{describe:'Output format: "text", "json", "stream-json"',type:"string",default:"text"}).option("include-partial-messages",{describe:"Include partial message chunks as they arrive",type:"boolean"}).option("input-format",{describe:'Input format: "text", "stream-json"',type:"string",default:"text"}).option("json-schema",{alias:["jsonSchema"],describe:"Inline JSON Schema for the structured final response",type:"string"}).option("output-schema",{alias:["outputSchema"],describe:"Path to a JSON Schema file for the structured final response",type:"string"}).option("model",{describe:"Model for the current session",type:"string"}).option("append-system-prompt",{describe:"Append a system prompt to the default system prompt",type:"string"}).option("system-prompt",{describe:"Replace the default system prompt",type:"string"}).option("max-turns",{alias:["maxTurns"],describe:"Maximum conversation turns (-1: unlimited, N>0: limit to N turns)",type:"number"}),async(B)=>{if(!B.p)return;let q=await o(B);process.exit(q)})}async function o(j,B=process){let q;try{await c();let D=j.forkSession!==!0&&(j.continue===!0||typeof j.resume==="string"&&j.resume.length>0)?await d({message:j.message,_:j._}):await v({message:j.message,_:j._,defaultMessage:"Hello"}),K=D===void 0,T=K?{mode:"agent",content:""}:await m(D);if(T.mode==="output"){if(T.content)B.stdout.write(`${T.content}
5
- `);return T.exitCode??0}let Q=T.content,W=await l(j),X=Q.trimStart().startsWith("!")?Q.trimStart().slice(1).trim():void 0;if(X!==void 0&&W)throw Error("Output schemas cannot be combined with user shell commands");let{sessionId:J,messages:r,metadata:G}=await a({sessionId:j.sessionId,continue:j.continue,resume:j.resume,forkSession:j.forkSession,fallbackSessionPrefix:"print"}),Y=G?.projectPath??P(),b=t(j.permissionMode)??G?.permissionMode??w()?.permissionMode??"default";await f.setSessionPermissionMode(J,Y,b);let N=await E.cancelPendingNonInteractive(Y,J)?await f.loadSessionModelContext(J,Y):r;q=await O.create({sessionId:J,workspaceRoot:Y,modelId:j.model,permissionMode:b,mcpConfig:j.mcpConfig,strictMcpConfig:j.strictMcpConfig,agents:j.agents?C(j.agents):void 0,...N.length>0?{sessionStart:{isResume:!0,resumeSessionId:J}}:{}});let Z=K&&q.getPendingSteeringCount()>0,k=K&&!Z?await q.getGoal():null,L=k?.status==="active"||k?.status==="verifying",U=q.getTurnRecoveryAssessment?.()??{state:"none"};if(K&&!Z&&!L&&U.state==="requires_attention")throw B.stderr.write(`[turn-recovery:${U.state}] ${U.turnId}
6
- `),Error("Turn recovery requires explicit user attention before continuation");let _=K&&!Z&&!L?await q.getRecoveredFinalResponse():void 0;if(K&&!Z&&!L){if(!_)throw Error("No unfinished turn or active goal to resume");let H=U;if(H.state!=="none")B.stderr.write(`[turn-recovery:${H.state}] ${H.turnId}
7
- `);return z({io:B,options:j,response:_.content,requestInput:Q,structuredOutput:_.structuredOutput,structuredOutputSchemaDigest:_.structuredOutputSchemaDigest}),0}if(X!==void 0){let H=await q.executeUserShellCommand(X);if(j.outputFormat==="json")B.stdout.write(`${JSON.stringify(H,null,2)}
8
- `);else if(j.outputFormat==="stream-json")B.stdout.write(`${JSON.stringify({type:"user_shell_completed",executionId:H.executionId,record:H.record})}
9
- `);else B.stdout.write(`${h(H.record)}
10
- `);return H.record.status==="completed"?0:H.record.status==="aborted"?130:H.record.exitCode??1}let x=await S.createWithRuntime(q,{sessionId:J,systemPrompt:j.systemPrompt,appendSystemPrompt:j.appendSystemPrompt,maxTurns:j.maxTurns,modelId:j.model,permissionMode:b,toolWhitelist:j.allowedTools,toolBlacklist:j.disallowedTools,mcpConfig:j.mcpConfig,strictMcpConfig:j.strictMcpConfig}),F={messages:[...N],userId:"cli-user",sessionId:J,workspaceRoot:Y,permissionMode:b},V=await M(W||K?x.chatStream(Q,F,{...W?{outputSchema:W}:{},pendingInputOnly:Z,goalContinuationOnly:L}):x.chatStream(Q,F),(H)=>{if(H.kind!=="turn_recovery")return;B.stderr.write(`[turn-recovery:${H.assessment.state}] ${H.assessment.turnId}
11
- `)});if(V.metadata?.recoveryAttention)throw Error("Turn recovery requires explicit user attention before continuation");if(!V.success)throw Error(V.error?.message??"Agent execution failed");let u=V.finalMessage||"",p=V.metadata?.structuredOutput;return z({io:B,options:j,response:u,requestInput:Q,structuredOutput:p,structuredOutputSchemaDigest:V.metadata?.structuredOutputSchemaDigest}),0}catch($){return B.stderr.write(`Error: ${$ instanceof Error?$.message:"未知错误"}
12
- `),1}finally{await q?.dispose()}}async function fj(){if(process.argv.slice(2).findIndex((q)=>q==="--print"||q==="-p")===-1)return!1;try{let{print:q,"output-format":$,"include-partial-messages":D,"input-format":K,"system-prompt":T,"append-system-prompt":Q,"max-turns":W,...X}=I,J=s(e(process.argv)).scriptName("blade").strict(!1).options(X).middleware([R,y,g]);return n(J),await J.parse(),!0}catch(q){console.error(`Print mode error: ${q instanceof Error?q.message:"未知错误"}`),process.exit(1)}}export{o as runPrint,fj as handlePrintMode};
@@ -1,4 +0,0 @@
1
- import{Aa as F,Ca as L}from"./chunk-bwe49m6n.js";import{_d as $,ae as B,ie as Q}from"./chunk-4fa11h6f.js";import{Yg as y}from"./chunk-jgxfhk9k.js";import{cj as V}from"./chunk-qdbbke8f.js";async function j(){await y(V())}async function I(b){let q=b.message||b._?.[0];if(typeof q==="string"&&q.trim())return q;let z=b.stdin??process.stdin;if(!z.isTTY){let G=[];for await(let K of z)G.push(K);return Buffer.concat(G).toString("utf-8").trim()}if(b.defaultMessage!==void 0)return b.defaultMessage;throw Error("No input provided")}async function M(b){let q=b.message||b._?.[0];if(typeof q==="string"&&q.trim())return q;let z=b.stdin??process.stdin;if(z.isTTY)return;let G=[];for await(let Z of z)G.push(Buffer.isBuffer(Z)?Z:Buffer.from(Z));return Buffer.concat(G).toString("utf-8").trim()||void 0}async function R(b){if(!F(b))return{mode:"agent",content:b};let q=await L(b,{cwd:V(),surface:"headless",workspaceRoot:V()});if(!q.success)return{mode:"output",content:`Error: ${q.error||"未知错误"}`,exitCode:1};let z=q.data;if(z?.action==="invoke_skill"){let{skillName:G,skillArgs:K}=z;return{mode:"agent",content:K?`Please use the "${G}" skill to help me with: ${K}`:`Please use the "${G}" skill.`}}if(z?.action==="invoke_custom_command"||z?.action==="invoke_plugin_command"){let G=z.processedContent;return{mode:"agent",content:`# Custom Command: /${z.commandName}
2
-
3
- ${G}`}}return{mode:"output",content:q.content||q.message||"",exitCode:0}}import{readFile as D,stat as H}from"node:fs/promises";import J from"node:path";function x(b,q){let z;try{z=JSON.parse(b)}catch(G){throw Error(`Invalid JSON output schema from ${q}`,{cause:G})}return B(z).schema}async function _(b){if(b.jsonSchema!==void 0&&b.outputSchema!==void 0)throw Error("--json-schema cannot be combined with --output-schema");if(b.jsonSchema!==void 0)return x(b.jsonSchema,"--json-schema");if(b.outputSchema===void 0)return;let q=J.resolve(b.outputSchema),z=await H(q);if(!z.isFile())throw Error(`Output schema path is not a regular file: ${q}`);if(z.size>$)throw Error(`Output schema exceeds ${$} bytes: ${q}`);return x(await D(q,"utf8"),q)}function N(b){if(!(b instanceof Error))return!1;return b.message.includes("未找到会话")||b.message.includes("ENOENT")||b.message.includes("no such file")}async function W(b){try{return await Q.loadSessionModelContext(b,V())}catch(q){if(N(q))return null;throw q}}async function C(b){if(b.resume===!0||b.resume==="true")throw Error("--resume without a session ID is only supported in interactive UI mode");if(typeof b.resume==="string"&&b.resume.length>0){if(b.forkSession){let G=V(),K=await Q.forkSession(b.resume,{newSessionId:b.sessionId,sourceProjectPath:G,targetProjectPath:G});return{...K,messages:await Q.loadSessionModelContext(K.sessionId,G)}}let[q,z]=await Promise.all([Q.loadSessionModelContext(b.resume),Q.findSessionMetadata(b.resume)]);return{sessionId:b.resume,messages:q,metadata:z}}if(b.continue){let q=b.forkSession?await Q.listSessions({cwd:V()}):await Q.listSessions();if(q.length>0){let z=q[0].sessionId;if(b.forkSession){let G=V(),K=await Q.forkSession(z,{newSessionId:b.sessionId,sourceProjectPath:G,targetProjectPath:G});return{...K,messages:await Q.loadSessionModelContext(K.sessionId,G)}}return{sessionId:z,messages:await Q.loadSessionModelContext(z),metadata:q[0]}}if(b.forkSession)throw Error("Cannot fork: no sessions are available to continue")}if(b.sessionId){let q=await W(b.sessionId);return{sessionId:b.sessionId,messages:q??[],...q?{metadata:await Q.findSessionMetadata(b.sessionId,V())}:{}}}return{sessionId:`${b.fallbackSessionPrefix}-${Date.now()}`,messages:[]}}
4
- export{j as p,I as q,M as r,R as s,_ as t,C as u};