blade-code 0.10.10 → 0.10.11

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 (49) hide show
  1. package/dist/blade.js +2 -2
  2. package/dist/{chunk-d600wn06.js → chunk-1qz9qfzc.js} +1 -1
  3. package/dist/{chunk-mhne9y2k.js → chunk-230xac12.js} +1 -1
  4. package/dist/{chunk-gvc0qqk4.js → chunk-3wms95qc.js} +1 -1
  5. package/dist/chunk-4hawehmd.js +114 -0
  6. package/dist/{chunk-j42jswx0.js → chunk-4vjx9ft1.js} +1 -1
  7. package/dist/{chunk-ttncpgr6.js → chunk-5b7xhvd1.js} +1 -1
  8. package/dist/{chunk-hfv5gcqj.js → chunk-5df4x6ec.js} +1 -1
  9. package/dist/{chunk-nmmj1x0c.js → chunk-7ysw82r9.js} +1 -1
  10. package/dist/{chunk-zf183j2y.js → chunk-82tsyr4f.js} +1 -1
  11. package/dist/{chunk-6kwv8ph0.js → chunk-93pn0vhs.js} +1 -1
  12. package/dist/{chunk-hetayg68.js → chunk-ajg3q7e4.js} +1 -1
  13. package/dist/{chunk-egmwj6xg.js → chunk-amx33f28.js} +1 -1
  14. package/dist/{chunk-jw8gb53m.js → chunk-b692dgxx.js} +1 -1
  15. package/dist/{chunk-zyf1r2j3.js → chunk-brwths02.js} +1 -1
  16. package/dist/{chunk-rhw2zkq8.js → chunk-bzwa0td4.js} +1 -1
  17. package/dist/{chunk-hveqdgt6.js → chunk-cskpqe1m.js} +1 -1
  18. package/dist/chunk-efqa79kw.js +1 -0
  19. package/dist/{chunk-7mhkm3x7.js → chunk-fm913p7k.js} +1 -1
  20. package/dist/{chunk-y56s2qww.js → chunk-gqrrheb3.js} +1 -1
  21. package/dist/{chunk-b6gknm33.js → chunk-h6w3ggx9.js} +1 -1
  22. package/dist/{chunk-g1qpzyt3.js → chunk-h9k52syw.js} +1 -1
  23. package/dist/{chunk-wnqybbry.js → chunk-jvfzm6gn.js} +1 -1
  24. package/dist/{chunk-t9aggrv8.js → chunk-k1my44xn.js} +1 -1
  25. package/dist/chunk-kqgtrnm6.js +4 -0
  26. package/dist/{chunk-c7201g75.js → chunk-qdf7sb0k.js} +1 -1
  27. package/dist/{chunk-9e5z64ap.js → chunk-s6v7kg40.js} +1 -1
  28. package/dist/{chunk-7hjjjkj0.js → chunk-sa572750.js} +1 -1
  29. package/dist/{chunk-3n4m3pcy.js → chunk-sxcm8ryt.js} +1 -1
  30. package/dist/{chunk-3v0ay0sf.js → chunk-tgtj3bj1.js} +1 -1
  31. package/dist/{chunk-ggq4y248.js → chunk-wpjb7918.js} +35 -35
  32. package/dist/{chunk-cfwnbrrd.js → chunk-xe0z59h2.js} +1 -1
  33. package/dist/{chunk-fvy56ajf.js → chunk-xm9katxj.js} +1 -1
  34. package/dist/{chunk-bxp1w7sh.js → chunk-yg2bd4w2.js} +41 -41
  35. package/dist/{chunk-epek6vr2.js → chunk-z18bbtg9.js} +1 -1
  36. package/dist/{chunk-vdj00rsv.js → chunk-ze1hqsbs.js} +1 -1
  37. package/dist/web/assets/{ChatView-DdX4BvAo.js → ChatView-DG6MMrFK.js} +2 -2
  38. package/dist/web/assets/{CodeBlockHighlighter-DBw81YZa.js → CodeBlockHighlighter-Cf3DBUGk.js} +1 -1
  39. package/dist/web/assets/{FilePreview-Di-mSDMs.js → FilePreview-LvuYnyjv.js} +1 -1
  40. package/dist/web/assets/{MarkdownRenderer-CxSfwebU.js → MarkdownRenderer-CkSbe36j.js} +3 -3
  41. package/dist/web/assets/{SettingsModal-CoBMb8of.js → SettingsModal-DBsb7E9J.js} +1 -1
  42. package/dist/web/assets/{TaskSwitcher-BmS-DA4i.js → TaskSwitcher-Z0KWY8g9.js} +1 -1
  43. package/dist/web/assets/{TerminalPanel-BPruynbV.js → TerminalPanel-DVWTlxtd.js} +1 -1
  44. package/dist/web/assets/{index-Bx7HzeXs.js → index-DWtXGF3o.js} +26 -26
  45. package/dist/web/index.html +1 -1
  46. package/package.json +1 -1
  47. package/dist/chunk-576pdgtm.js +0 -114
  48. package/dist/chunk-tkqrhxqr.js +0 -1
  49. package/dist/chunk-zepqp80m.js +0 -4
@@ -5,7 +5,7 @@
5
5
  <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
7
  <title>BladeCode</title>
8
- <script type="module" crossorigin src="/assets/index-Bx7HzeXs.js"></script>
8
+ <script type="module" crossorigin src="/assets/index-DWtXGF3o.js"></script>
9
9
  <link rel="modulepreload" crossorigin href="/assets/vendor-react-DG5dkZ_t.js">
10
10
  <link rel="modulepreload" crossorigin href="/assets/vendor-radix-DXRuAJHH.js">
11
11
  <link rel="modulepreload" crossorigin href="/assets/vendor-icons-ICv1v-tf.js">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blade-code",
3
- "version": "0.10.10",
3
+ "version": "0.10.11",
4
4
  "private": false,
5
5
  "description": "🗡️ Blade Code - 智能代码助手命令行工具",
6
6
  "type": "module",
@@ -1,114 +0,0 @@
1
- import{ee as n}from"./chunk-4dq9y7zn.js";import{Cf as l,Ef as C,Gf as L,Kf as u,Lf as o}from"./chunk-363pgv1e.js";import{Mf as J}from"./chunk-g11hq0e5.js";import{stat as i}from"node:fs/promises";import A from"node:path";import*as M from"node:path";var a=50,s=100,t=/^[A-Za-z0-9_-]+$/,e=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?(?:Z|[+-]\d{2}:\d{2})$/;function EE(_){return typeof _==="string"&&e.test(_)&&Number.isFinite(Date.parse(_))}function P(_){return typeof _==="string"&&M.isAbsolute(_)}function _E(_){return Buffer.from(JSON.stringify(_),"utf8").toString("base64url")}function RE(_){try{if(!t.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||P(R.cwd))||!EE(R.lastMessageTime)||!P(R.projectPath)||!C(R.sessionId))throw Error("invalid");return{version:1,cwd:R.cwd===null?null:M.resolve(R.cwd),includeSubagents:R.includeSubagents,archived:R.archived??!1,lastMessageTime:R.lastMessageTime,projectPath:M.resolve(R.projectPath),sessionId:R.sessionId}}catch{throw Error("Invalid session cursor")}}function f(_){let E="";for(let R=0;R<_.length;R+=1)E+=_.charCodeAt(R).toString(16).padStart(4,"0");return E}function WE(_){if(!_.cursor)return;let E=RE(_.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 wE(_={}){let{cwd:E,cursor:R,limit:W,includeSubagents:$=!1,archived:k=!1}=_;if(E!==void 0&&!M.isAbsolute(E))throw Error("Session catalog cwd must be absolute");let H=W===void 0?a:W;if(!Number.isInteger(H)||H<1||H>s)throw Error("Session catalog limit must be an integer from 1 to 100");return{cwd:E===void 0?null:M.resolve(E),cursor:R??void 0,limit:H,includeSubagents:$,archived:k}}function $E(_,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 xE(_,E){let R=[..._],W=WE(E);if(W)R=R.filter((H)=>$E(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 k=$[$.length-1];return{sessions:$,nextCursor:_E({version:1,cwd:E.cwd,includeSubagents:E.includeSubagents,archived:E.archived,lastMessageTime:k.lastMessageTime,projectPath:k.projectPath,sessionId:k.sessionId})}}function kE(_){return _.type==="message_created"||_.type==="part_created"||_.type==="part_updated"||_.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:p(_,E),createdAt:R.data.createdAt}}function p(_,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 S(_,E){N(_,E);let R=_.findIndex((W)=>W.type==="message_created"&&W.data.messageId===E);return _.filter((W,$)=>$<R||!kE(W))}function z(_){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=S(E,R.data.targetMessageId)}return E}function qE(_){let E=z(_);return E.filter(O).map((R)=>({messageId:R.data.messageId,preview:p(E,R.data.messageId),createdAt:R.data.createdAt})).reverse()}function fE(_,E){let R=z(_),W=N(R,E),$=R.findIndex((H)=>H.type==="message_created"&&H.data.messageId===E),k=R.slice($);return{checkpoint:W,projectedEntries:S(R,E),removedTurns:k.filter(O).length,snapshotMessageIds:k.flatMap((H)=>H.type==="part_created"&&H.data.partType==="tool_call"?[H.data.partId]:[])}}import*as x from"node:fs";import{createReadStream as HE}from"node:fs";import*as Y from"node:fs/promises";import*as I from"node:path";import{createInterface as QE}from"node:readline";var c=65536;function VE(_,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 w(_,E="session transcript"){let R=_.split(`
2
- `),W=!_.endsWith(`
3
- `),$=[];for(let[k,H]of R.entries())try{let Q=VE(H,k+1,E);if(Q){if(typeof Q.seq!=="number")Q.seq=$.length+1;$.push(Q)}}catch(Q){if(W&&k===R.length-1)break;throw Q}return $}class Z{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 Z.stampSeqFrom(_,Z.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 Y.mkdir(I.dirname(this.filePath),{recursive:!0,mode:493});let E=await Y.open(this.filePath,"a+",384);try{let R=await this.repairIncompleteTail(E),W=await this.readTailSeq(E),$=Z.stampSeqFrom(_,W),k=`${$.map((H)=>JSON.stringify(H)).join(`
4
- `)}
5
- `;return await E.appendFile(R+k,"utf8"),await E.sync(),$}finally{await E.close()}})}async createExclusive(_){if(_.length===0)throw Error("Cannot create an empty session transcript");await Y.mkdir(I.dirname(this.filePath),{recursive:!0,mode:493});let E;try{E=await Y.open(this.filePath,"wx",384);let W=`${Z.stampSeq(_,[]).map(($)=>JSON.stringify($)).join(`
6
- `)}
7
- `;await E.writeFile(W,"utf-8"),await E.sync()}catch(R){if(E)await E.close(),E=void 0,await Y.unlink(this.filePath).catch(()=>{return});throw R}finally{await E?.close()}}async readAll(){if(!x.existsSync(this.filePath))return[];let _=await Y.readFile(this.filePath,"utf-8");return w(_,this.filePath)}async readStream(_){return new Promise((E,R)=>{if(!x.existsSync(this.filePath)){E();return}let W=HE(this.filePath,"utf-8"),$=QE({input:W,crlfDelay:Number.POSITIVE_INFINITY}),k=0;$.on("line",async(H)=>{let Q=H.trim();if(Q.length===0)return;try{let X=JSON.parse(Q);if(k+=1,typeof X.seq!=="number")X.seq=k;await _(X)}catch(X){console.warn(`[JSONLStore] 解析 JSON 行失败: ${Q}`,X)}}),$.on("close",()=>E()),$.on("error",R),W.on("error",R)})}async filter(_){let E=[];return await this.readStream((R)=>{if(_(R))E.push(R)}),E}async readLast(_){return(await this.readAll()).slice(-_)}async readFromSeq(_){return(await this.readAll()).filter((R)=>(R.seq??0)>=_)}async getStats(){try{if(!x.existsSync(this.filePath))return{exists:!1,size:0,lineCount:0};let _=await Y.stat(this.filePath),R=(await Y.readFile(this.filePath,"utf-8")).split(`
8
- `).filter((W)=>W.trim().length>0).length;return{exists:!0,size:_.size,lineCount:R}}catch(_){return console.error(`[JSONLStore] 获取统计信息失败: ${this.filePath}`,_),{exists:!1,size:0,lineCount:0}}}async exists(){try{return await Y.access(this.filePath),!0}catch{return!1}}async delete(){try{return await this.enqueue(async()=>{try{return await Y.unlink(this.filePath),!0}catch(_){if(_.code==="ENOENT")return!1;throw _}})}catch(_){throw console.error(`[JSONLStore] 删除文件失败: ${this.filePath}`,_),_}}async deleteValidated(_){return this.enqueue(async()=>{let E;try{E=await Y.open(this.filePath,"r")}catch(W){if(W.code==="ENOENT")return!1;throw W}let R;try{R=w(await E.readFile("utf8"),"session transcript")}finally{await E.close()}if(!_(R))return!1;try{return await Y.unlink(this.filePath),!0}catch(W){if(W.code==="ENOENT")return!1;throw W}})}async appendValidated(_){return this.appendValidatedAsync(async(E)=>_(E))}async appendValidatedAsync(_){return this.enqueue(async()=>{let E=await Y.open(this.filePath,"r+");try{let{entries:R,separator:W,size:$}=await this.readCommittedState(E,"session transcript"),k=await _(R),[H]=Z.stampSeq([k],R),Q=`${W}${JSON.stringify(H)}
9
- `;return await E.write(Q,$,"utf8"),await E.sync(),H}finally{await E.close()}})}getFilePath(){return this.filePath}async enqueue(_){let R=(Z.appendQueues.get(this.filePath)??Promise.resolve()).catch(()=>{return}).then(_),W=R.then(()=>{return},()=>{return});Z.appendQueues.set(this.filePath,W);try{return await R}finally{if(Z.appendQueues.get(this.filePath)===W)Z.appendQueues.delete(this.filePath)}}async readCommittedState(_,E=this.filePath){let R=await this.repairIncompleteTail(_),W=await _.readFile("utf8"),$=w(W,E),{size:k}=await _.stat();return{entries:$,separator:R,size:k}}async readTailSeq(_){let{size:E}=await _.stat();if(E===0)return 0;let R=Math.max(0,E-c),W=Buffer.allocUnsafe(E-R);await _.read(W,0,W.length,R);let $=W.toString("utf8").split(`
10
- `);for(let H=$.length-1;H>=0;H--){let Q=$[H].trim();if(!Q)continue;if(H===0&&R>0)break;try{let X=JSON.parse(Q).seq;if(typeof X==="number")return X}catch{}break}let k=await _.readFile("utf8");return Z.maxSeq(w(k,this.filePath))}async repairIncompleteTail(_){let{size:E}=await _.stat();if(E===0)return"";let R=Buffer.allocUnsafe(1);if(await _.read(R,0,1,E-1),R[0]===10)return"";let W=await this.findTailStart(_,E),$=Buffer.allocUnsafe(E-W);await _.read($,0,$.length,W);try{return JSON.parse($.toString("utf8").trim()),`
11
- `}catch{return await _.truncate(W),""}}async findTailStart(_,E){let R=E;while(R>0){let W=Math.max(0,R-c),$=Buffer.allocUnsafe(R-W);await _.read($,0,$.length,W);let k=$.lastIndexOf(10);if(k>=0)return W+k+1;R=W}return 0}}function XE(){return typeof globalThis.Bun<"u"}function YE(_){return{exec:(E)=>_.exec(E),prepare:(E)=>{let R=_.prepare(E);return{run:(...W)=>{R.run(...W)},get:(...W)=>R.get(...W),all:(...W)=>R.all(...W)}},transaction:(E)=>_.transaction(E)(),pragma:(E)=>_.pragma(E,{simple:!0}),close:()=>_.close()}}function GE(_){return{exec:(E)=>_.exec(E),prepare:(E)=>{let R=_.query(E);return{run:(...W)=>{R.run(...W)},get:(...W)=>R.get(...W),all:(...W)=>R.all(...W)}},transaction:(E)=>_.transaction(E)(),pragma:(E)=>{let R=_.query(`PRAGMA ${E}`).get();if(!R)return;let W=Object.values(R);return W.length===1?W[0]:R},close:()=>_.close()}}var ZE=["PRAGMA journal_mode=WAL;","PRAGMA busy_timeout=5000;","PRAGMA synchronous=NORMAL;","PRAGMA foreign_keys=ON;"].join(`
12
- `);async function m(_){try{let E;if(XE()){let{Database:W}=await import("bun:sqlite");E=GE(new W(_))}else{let $=(await import("better-sqlite3")).default;E=YE(new $(_))}return E.exec(ZE),E}catch{return null}}function h(_){let E=Number(_.pragma("user_version")??0);if(E===3)return;if(E>0&&E!==3)_.exec(`
13
- DROP TABLE IF EXISTS parts_fts;
14
- DROP TABLE IF EXISTS parts;
15
- DROP TABLE IF EXISTS sessions;
16
- DROP TABLE IF EXISTS projection_state;
17
- `);_.exec(`
18
- CREATE TABLE IF NOT EXISTS projection_state (
19
- project_path TEXT NOT NULL,
20
- session_id TEXT NOT NULL,
21
- last_seq INTEGER NOT NULL DEFAULT 0,
22
- file_size INTEGER NOT NULL DEFAULT 0,
23
- mtime_ms INTEGER NOT NULL DEFAULT 0,
24
- PRIMARY KEY (project_path, session_id)
25
- );
26
-
27
- CREATE TABLE IF NOT EXISTS sessions (
28
- project_path TEXT NOT NULL,
29
- session_id TEXT NOT NULL,
30
- root_id TEXT,
31
- parent_id TEXT,
32
- relation_type TEXT,
33
- title TEXT,
34
- agent_type TEXT,
35
- model TEXT,
36
- task_status TEXT,
37
- archived_at TEXT,
38
- last_message_time TEXT,
39
- project_sort_key TEXT NOT NULL,
40
- session_sort_key TEXT NOT NULL,
41
- first_message_time TEXT,
42
- message_count INTEGER NOT NULL DEFAULT 0,
43
- has_errors INTEGER NOT NULL DEFAULT 0,
44
- is_subagent INTEGER NOT NULL DEFAULT 0,
45
- -- 完整 StoredSessionMetadata JSON,读回时直接反序列化,保证与 JSONL 路径一致。
46
- metadata_json TEXT NOT NULL,
47
- PRIMARY KEY (project_path, session_id)
48
- );
49
- CREATE INDEX IF NOT EXISTS idx_sessions_catalog ON sessions(
50
- last_message_time DESC,
51
- project_sort_key ASC,
52
- session_sort_key ASC
53
- );
54
- CREATE INDEX IF NOT EXISTS idx_sessions_archived ON sessions(
55
- archived_at,
56
- project_path,
57
- parent_id
58
- );
59
-
60
- CREATE TABLE IF NOT EXISTS parts (
61
- project_path TEXT NOT NULL,
62
- session_id TEXT NOT NULL,
63
- part_id TEXT NOT NULL,
64
- message_id TEXT,
65
- part_type TEXT,
66
- role TEXT,
67
- seq INTEGER,
68
- timestamp TEXT,
69
- text TEXT,
70
- PRIMARY KEY (project_path, session_id, part_id)
71
- );
72
- CREATE INDEX IF NOT EXISTS idx_parts_session ON parts(project_path, session_id);
73
-
74
- CREATE VIRTUAL TABLE IF NOT EXISTS parts_fts USING fts5(
75
- text,
76
- project_path UNINDEXED,
77
- session_id UNINDEXED,
78
- part_id UNINDEXED,
79
- role UNINDEXED,
80
- timestamp UNINDEXED,
81
- seq UNINDEXED,
82
- tokenize = 'unicode61'
83
- );
84
- `),_.exec("PRAGMA user_version=3;")}var KE=n("Service"),B;function d(){return A.join(u(),"index.db")}async function TE(){let _=d();if(B&&B.path===_)return B.db;let E=(async()=>{let R=await m(_);if(!R)return null;try{return h(R),R}catch{return null}})();return B={path:_,db:E},E}function UE(){B=void 0}function ME(_){if(_&&typeof _==="object"){let E=_.text;if(typeof E==="string")return E}return null}function FE(_,E,R,W){_.prepare("DELETE FROM parts WHERE project_path=? AND session_id=?").run(E,R),_.prepare("DELETE FROM parts_fts WHERE project_path=? AND session_id=?").run(E,R);let $=new Map;for(let Q of W)if(Q.type==="message_created")$.set(Q.data.messageId,Q.data.role);let k=_.prepare(`INSERT OR REPLACE INTO parts
85
- (project_path, session_id, part_id, message_id, part_type, role, seq, timestamp, text)
86
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`),H=_.prepare(`INSERT INTO parts_fts (text, project_path, session_id, part_id, role, timestamp, seq)
87
- VALUES (?, ?, ?, ?, ?, ?, ?)`);for(let Q of W){if(Q.type!=="part_created"&&Q.type!=="part_updated")continue;if(Q.data.partType!=="text")continue;let X=ME(Q.data.payload);if(X===null)continue;let G=$.get(Q.data.messageId)??"assistant",F=Q.seq??0;if(k.run(E,R,Q.data.partId,Q.data.messageId,Q.data.partType,G,F,Q.timestamp,X),G==="user"||G==="assistant")H.run(X,E,R,Q.data.partId,G,Q.timestamp,F)}}function DE(_,E){_.prepare(`INSERT INTO sessions
88
- (project_path, session_id, root_id, parent_id, relation_type, title,
89
- agent_type, model, task_status, archived_at, last_message_time, project_sort_key,
90
- session_sort_key, first_message_time, message_count, has_errors,
91
- is_subagent, metadata_json)
92
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
93
- ON CONFLICT(project_path, session_id) DO UPDATE SET
94
- root_id=excluded.root_id, parent_id=excluded.parent_id,
95
- relation_type=excluded.relation_type, title=excluded.title,
96
- agent_type=excluded.agent_type, model=excluded.model,
97
- task_status=excluded.task_status, archived_at=excluded.archived_at,
98
- last_message_time=excluded.last_message_time,
99
- project_sort_key=excluded.project_sort_key,
100
- session_sort_key=excluded.session_sort_key,
101
- first_message_time=excluded.first_message_time, message_count=excluded.message_count,
102
- has_errors=excluded.has_errors, is_subagent=excluded.is_subagent,
103
- metadata_json=excluded.metadata_json`).run(E.projectPath,E.sessionId,E.rootId,E.parentId??null,E.relationType??null,E.title??null,E.agentType??null,E.model??null,E.taskStatus,E.archivedAt??null,E.lastMessageTime,f(E.projectPath),f(E.sessionId),E.firstMessageTime,E.messageCount,E.hasErrors?1:0,E.relationType==="subagent"?1:0,JSON.stringify(E))}function r(_,E,R){for(let W of["sessions","parts","parts_fts"])_.prepare(`DELETE FROM ${W} WHERE project_path=? AND session_id=?`).run(E,R)}function v(_,E,R){r(_,E,R),_.prepare("DELETE FROM projection_state WHERE project_path=? AND session_id=?").run(E,R)}function y(_,E,R,W,$,k){_.prepare(`INSERT INTO projection_state
104
- (project_path, session_id, last_seq, file_size, mtime_ms)
105
- VALUES (?, ?, ?, ?, ?)
106
- ON CONFLICT(project_path, session_id) DO UPDATE SET
107
- last_seq=excluded.last_seq, file_size=excluded.file_size,
108
- mtime_ms=excluded.mtime_ms`).run(E,R,W,$,k)}async function BE(_,E,R,W,$=L(R,E)){let k;try{let V=await i($);k={size:V.size,mtimeMs:V.mtimeMs}}catch{return _.transaction(()=>v(_,R,E)),!0}let H=_.prepare("SELECT last_seq, file_size, mtime_ms FROM projection_state WHERE project_path=? AND session_id=?").get(R,E);if(H&&H.file_size===k.size&&H.mtime_ms===Math.floor(k.mtimeMs))return!1;let X=await new Z($).readAll(),G=X.reduce((V,T)=>typeof T.seq==="number"&&T.seq>V?T.seq:V,0),F=z(X),K=W(X,E,R);if(X.length===0||!K)return _.transaction(()=>{r(_,R,E),y(_,R,E,G,k.size,Math.floor(k.mtimeMs))}),!0;let D=_.prepare("SELECT last_message_time FROM sessions WHERE project_path=? AND session_id=?").get(K.projectPath,K.sessionId),g=A.resolve($)===A.resolve(L(K.projectPath,K.sessionId));if(D&&!g&&typeof D.last_message_time==="string"&&D.last_message_time>K.lastMessageTime)return y(_,R,E,G,k.size,Math.floor(k.mtimeMs)),!0;return _.transaction(()=>{DE(_,K),FE(_,K.projectPath,K.sessionId,F),y(_,R,E,G,k.size,Math.floor(k.mtimeMs))}),!0}var b=new WeakMap;async function AE(_,E,R=0){let W=b.get(_)??{};if(b.set(_,W),W.inFlight)return W.inFlight;if(R>0&&W.lastCompletedAt!==void 0&&Date.now()-W.lastCompletedAt<=R)return;let $=gE(_,E);W.inFlight=$;try{await $,W.lastCompletedAt=Date.now()}finally{if(W.inFlight===$)W.inFlight=void 0}}async function gE(_,E){let{readdir:R}=await import("node:fs/promises"),W=await o(),$=new Set,H=(await Promise.all(W.map(async(V)=>{let T=l(V),U=A.join(u(),"projects",V);try{return(await R(U)).flatMap((q)=>{if(!q.endsWith(".jsonl"))return[];let j=q.slice(0,-6);if(!C(j))return[];return[{filePath:A.join(U,q),projectPath:T,sessionId:j}]})}catch{return[]}}))).flat();for(let V of H)$.add(`${V.projectPath}\x00${V.sessionId}`);let Q=_.prepare(`SELECT project_path, session_id, last_seq, file_size, mtime_ms
109
- FROM projection_state`).all(),X=new Map(Q.map((V)=>[`${V.project_path}\x00${V.session_id}`,V])),G=[],F=Math.min(128,H.length),K=0;await Promise.all(Array.from({length:F},async()=>{while(K<H.length){let V=H[K++];if(!V)continue;try{let T=await i(V.filePath),U=X.get(`${V.projectPath}\x00${V.sessionId}`);if(U&&U.file_size===T.size&&U.mtime_ms===Math.floor(T.mtimeMs))continue}catch{}G.push(V)}}));let D=Math.min(32,G.length),g=0;await Promise.all(Array.from({length:D},async()=>{while(g<G.length){let V=G[g++];if(!V)continue;try{await BE(_,V.sessionId,V.projectPath,E,V.filePath)}catch(T){if(T.code!=="ENOENT")KE.warn(`[SessionService] Skipping invalid session transcript: ${V.sessionId}`)}}}));for(let V of Q)if(!$.has(`${V.project_path}\x00${V.session_id}`))_.transaction(()=>v(_,V.project_path,V.session_id))}function oE(_,E,R){_.transaction(()=>v(_,R,E))}async function nE(_){let{rm:E}=await import("node:fs/promises");UE();let R=d();for(let k of["","-wal","-shm"])await E(`${R}${k}`,{force:!0}).catch(()=>{return});let W=await TE();if(!W)return null;return await AE(W,_),W.prepare("SELECT COUNT(*) c FROM sessions").get()?.c??0}function iE(_,E,R,W){let $=E.replace(/["*]/g," ").trim().split(/\s+/)[0];if(!$)return[];let k=`"${$}"*`,H=R?`SELECT session_id, role, timestamp, text FROM parts_fts
110
- WHERE parts_fts MATCH ? AND project_path = ?
111
- ORDER BY timestamp DESC LIMIT ?`:`SELECT session_id, role, timestamp, text FROM parts_fts
112
- WHERE parts_fts MATCH ?
113
- ORDER BY timestamp DESC LIMIT ?`,Q=_.prepare(H);return R?Q.all(k,R,W):Q.all(k,W)}
114
- export{z as ac,qE as bc,fE as cc,w as dc,Z as ec,f as fc,WE as gc,wE as hc,$E as ic,xE as jc,d as kc,TE as lc,UE as mc,BE as nc,AE as oc,oE as pc,nE as qc,iE as rc};
@@ -1 +0,0 @@
1
- import{sc as a,tc as b}from"./chunk-gvc0qqk4.js";import"./chunk-wnqybbry.js";import"./chunk-g11hq0e5.js";export{a as globalOptions,b as cliConfig};
@@ -1,4 +0,0 @@
1
- import"./chunk-vmq248m7.js";import"./chunk-4dq9y7zn.js";import{Se as J}from"./chunk-d600wn06.js";import"./chunk-3aqdjrtm.js";import"./chunk-kvx3sb3z.js";import"./chunk-f4z3gkbs.js";import{if as H}from"./chunk-5s123nbs.js";import"./chunk-s5666ta0.js";import"./chunk-dsj62dcg.js";import"./chunk-wnqybbry.js";import"./chunk-gav4hxcv.js";import"./chunk-afkhzdfc.js";import"./chunk-363pgv1e.js";import{Mf as B}from"./chunk-g11hq0e5.js";var O={command:"doctor",describe:"Check the health of your Blade installation",builder:(D)=>D.option("rebuild-index",{type:"boolean",default:!1,describe:"Rebuild the SQLite session index from JSONL transcripts"}),handler:async(D)=>{if(D.rebuildIndex){console.log(`Rebuilding session index from JSONL transcripts...
2
- `);try{let{rebuildProjectionIndex:z}=await import("./chunk-b6gknm33.js"),{SessionService:F}=await import("./chunk-ttncpgr6.js"),G=await z(F.projectionDeriverForSearch());if(G===null)console.log("[WARN] Session index unavailable (SQLite driver missing); reads fall back to JSONL scan.");else console.log(`[OK] Session index rebuilt: ${G} session(s) indexed.`)}catch(z){console.log("[FAIL] Session index rebuild failed"),console.log(` Error: ${z instanceof Error?z.message:"未知错误"}`),process.exit(1)}return}console.log(`Running Blade health check...
3
- `);let A=0;try{await J.getInstance().initialize(),console.log("[OK] Configuration: OK")}catch(z){console.log("[FAIL] Configuration: FAILED"),console.log(` Error: ${z instanceof Error?z.message:"未知错误"}`),A++}let E=process.version;if(parseInt(E.slice(1).split(".")[0])>=18)console.log(`[OK] Node.js version: ${E}`);else console.log(`[WARN] Node.js version: ${E} (recommended: v18+)`),A++;try{let z=await import("fs/promises"),F=H();await z.access(F,(await import("fs")).constants.R_OK|(await import("fs")).constants.W_OK),console.log("[OK] File system permissions: OK")}catch(z){console.log("[FAIL] File system permissions: FAILED"),console.log(" Error: Cannot read/write in current directory"),A++}try{await import("ink"),console.log("[OK] Dependencies: OK")}catch(z){console.log("[FAIL] Dependencies: FAILED"),console.log(" Error: Missing required dependencies"),A++}if(console.log(`
4
- Health Check Summary:`),A===0)console.log("All checks passed! Blade is ready to use.");else console.log(`Warning: Found ${A} issue(s). Please resolve them for optimal performance.`),process.exit(1)}};export{O as doctorCommands};