blade-code 0.10.128 → 0.10.129
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-0z9nqbd0.js +2 -0
- package/dist/{chunk-yqqeh12b.js → chunk-1c11sbk3.js} +2 -2
- package/dist/{chunk-fa0pyv9k.js → chunk-1q6sasj0.js} +2 -2
- package/dist/chunk-1y8x5q68.js +1 -0
- package/dist/chunk-2bnpn8be.js +1 -0
- package/dist/{chunk-xzfc1s6k.js → chunk-2y1qngw7.js} +1 -1
- package/dist/{chunk-p2rxrxct.js → chunk-440v1nhy.js} +3 -3
- package/dist/{chunk-ted1hyvb.js → chunk-44jtpg8y.js} +1 -1
- package/dist/{chunk-z3hpstky.js → chunk-53h87fmt.js} +1 -1
- package/dist/chunk-54yagjc7.js +2 -0
- package/dist/chunk-606343xt.js +1 -0
- package/dist/{chunk-85jv1sr7.js → chunk-651cnx1s.js} +2 -2
- package/dist/{chunk-n8w1jxsh.js → chunk-67qdrjyy.js} +1 -1
- package/dist/chunk-6czf04er.js +1 -0
- package/dist/{chunk-pq6g92cz.js → chunk-6p6ts4kv.js} +2 -2
- package/dist/{chunk-sca5q3tt.js → chunk-77efqpdc.js} +1 -1
- package/dist/{chunk-10w2pj3r.js → chunk-93x9xbew.js} +1 -1
- package/dist/chunk-9gs4eqt8.js +1 -0
- package/dist/{chunk-jy0vfp8a.js → chunk-9kt66etm.js} +1 -1
- package/dist/chunk-9pzfv6nb.js +1 -0
- package/dist/{chunk-p7349xay.js → chunk-9rj01jd1.js} +2 -2
- package/dist/chunk-9s8saznq.js +1 -0
- package/dist/{chunk-1aw643j2.js → chunk-9snmrjg8.js} +2 -2
- package/dist/{chunk-yqpej45c.js → chunk-a60cmnmz.js} +2 -2
- package/dist/{chunk-8hd4vd20.js → chunk-aaxc81jc.js} +1 -1
- package/dist/{chunk-c47db31j.js → chunk-ajsw4te2.js} +2 -2
- package/dist/{chunk-xejvs1fk.js → chunk-amc5d34g.js} +1 -1
- package/dist/{chunk-r04vwtej.js → chunk-ar5np5h5.js} +2 -2
- package/dist/{chunk-mkvvyq49.js → chunk-bamj4e6v.js} +2 -2
- package/dist/{chunk-atema2rc.js → chunk-dfjmvj3d.js} +2 -2
- package/dist/{chunk-9n90djh7.js → chunk-dg54m1y3.js} +2 -2
- package/dist/{chunk-s7axaw78.js → chunk-edtxcqxa.js} +1 -1
- package/dist/chunk-f8gb685p.js +2 -0
- package/dist/chunk-fhafrrvs.js +1 -0
- package/dist/{chunk-zfyg3888.js → chunk-g4xny949.js} +1 -1
- package/dist/chunk-gfbkrk60.js +338 -0
- package/dist/{chunk-12hdakw4.js → chunk-gmqpfm52.js} +2 -2
- package/dist/{chunk-skv2gb99.js → chunk-grhsv55v.js} +2 -2
- package/dist/{chunk-nx8xb7dm.js → chunk-jkfkyedn.js} +1 -1
- package/dist/{chunk-v4nqv1pr.js → chunk-jxh9wf3c.js} +356 -356
- package/dist/{chunk-b408cqg1.js → chunk-kbxqsf93.js} +2 -2
- package/dist/chunk-kd3k1q9z.js +1 -0
- package/dist/{chunk-a7gghhvn.js → chunk-m5vpmvrs.js} +18 -18
- package/dist/chunk-m9mw8ppy.js +1 -0
- package/dist/{chunk-y93nqyqd.js → chunk-mawx6fa5.js} +2 -2
- package/dist/{chunk-xshrj2nd.js → chunk-mdew58v9.js} +1 -1
- package/dist/{chunk-60he05xs.js → chunk-mkzze9aq.js} +2 -2
- package/dist/{chunk-n4q6fvqe.js → chunk-mvm1rzc4.js} +2 -2
- package/dist/chunk-nz8wbcf1.js +1 -0
- package/dist/{chunk-qm632an7.js → chunk-p00f53yq.js} +1 -1
- package/dist/{chunk-9hnfz9bx.js → chunk-pa636c8e.js} +1 -1
- package/dist/chunk-pd1b8jrv.js +1 -0
- package/dist/chunk-pj69j4zp.js +2 -0
- package/dist/{chunk-41byj2h8.js → chunk-q6xsfm60.js} +2 -2
- package/dist/{chunk-6m4sqwj0.js → chunk-qcvxff27.js} +2 -2
- package/dist/chunk-r1b4pnce.js +94 -0
- package/dist/{chunk-jxc67ydz.js → chunk-rnmt44jm.js} +2 -2
- package/dist/chunk-s51h6n70.js +23 -0
- package/dist/chunk-s6158tg7.js +170 -0
- package/dist/{chunk-fgbqm2jh.js → chunk-sfe4810k.js} +1 -1
- package/dist/{chunk-96w8ay2h.js → chunk-sj1dzeta.js} +1 -1
- package/dist/{chunk-ektgnqmh.js → chunk-sx77dpxw.js} +1 -1
- package/dist/chunk-t6bg5b37.js +1 -0
- package/dist/{chunk-gxwkwkhp.js → chunk-tkydv9k8.js} +1 -1
- package/dist/{chunk-q3y3s16v.js → chunk-v52wc8yg.js} +2 -2
- package/dist/chunk-wzcwxhhz.js +1 -0
- package/dist/{chunk-yysqw1cq.js → chunk-xcmadwjv.js} +2 -2
- package/dist/chunk-xdphpfrg.js +14 -0
- package/dist/chunk-xsjtjrt9.js +10 -0
- package/dist/{chunk-6v2hhgka.js → chunk-y4f99y85.js} +2 -2
- package/dist/{chunk-mvgmsjwq.js → chunk-z03dtyh6.js} +1 -1
- package/dist/{chunk-rz2wc93t.js → chunk-za8gyypy.js} +4 -4
- package/dist/{chunk-mm05y2c5.js → chunk-zkzhm39s.js} +1 -1
- package/dist/{chunk-1xg7qx35.js → chunk-zwjrensv.js} +1 -1
- package/dist/chunk-zzgxy86p.js +1 -0
- package/dist/web/assets/ChatView-Bg36FUaj.js +53 -0
- package/dist/web/assets/{CodeBlockHighlighter-0VOa5Mes.js → CodeBlockHighlighter-D5rB73Eo.js} +2 -2
- package/dist/web/assets/FilePreview-BxaBSmap.js +65 -0
- package/dist/web/assets/KanbanBoard-B4gx3JMo.js +16 -0
- package/dist/web/assets/{MarkdownRenderer-3g4TPTeI.js → MarkdownRenderer-BRH7LHhN.js} +3 -3
- package/dist/web/assets/ScrollArea-DikU3QeQ.js +1 -0
- package/dist/web/assets/SessionHistorySurface-DG80d6-F.js +6 -0
- package/dist/web/assets/{SettingsModal-3GMy6V-E.js → SettingsModal-Bxqkok81.js} +3 -3
- package/dist/web/assets/Sidebar-DGaHGcHx.js +31 -0
- package/dist/web/assets/TaskSwitcher-DOnLPurk.js +26 -0
- package/dist/web/assets/TerminalPanel-BzhCF9vw.js +6 -0
- package/dist/web/assets/archive-BiDGrqry.js +6 -0
- package/dist/web/assets/{arrow-left-03GxbYI7.js → arrow-left-BY-esOAP.js} +1 -1
- package/dist/web/assets/{calendar-clock-8W4ostX1.js → calendar-clock-BCyxvfVt.js} +1 -1
- package/dist/web/assets/chevron-right-Bg-10yuN.js +6 -0
- package/dist/web/assets/{chevrons-up-down-BboZzEAk.js → chevrons-up-down-M5SAJq7T.js} +1 -1
- package/dist/web/assets/{clock-3-aXgeptZP.js → clock-3-v-nHTA0A.js} +1 -1
- package/dist/web/assets/copy-p1zc_rjZ.js +6 -0
- package/dist/web/assets/download-D_-kbJXR.js +6 -0
- package/dist/web/assets/{external-link-UkIIC2ds.js → external-link-wSGTIqe3.js} +1 -1
- package/dist/web/assets/{folder-BOCc5dv2.js → folder-Ltm9jCS5.js} +1 -1
- package/dist/web/assets/index-B4186fIT.css +1 -0
- package/dist/web/assets/index-_xnlrekR.js +210 -0
- package/dist/web/assets/{pause-DVIT6IIr.js → pause-_LvCZkxM.js} +1 -1
- package/dist/web/assets/pencil-DB6ICr_h.js +6 -0
- package/dist/web/assets/{play-DsdF5dji.js → play-BRXP1rHJ.js} +1 -1
- package/dist/web/assets/plus-BqvjEpLw.js +6 -0
- package/dist/web/assets/session-events-AGMXvPey.js +22 -0
- package/dist/web/assets/settings-LfQbDvBA.js +6 -0
- package/dist/web/assets/teamService-B5FnUcet.js +1 -0
- package/dist/web/assets/terminal-By4sO9Gw.js +6 -0
- package/dist/web/assets/vendor-radix-D6QrtXqd.js +45 -0
- package/dist/web/index.html +3 -3
- package/package.json +1 -1
- package/dist/chunk-0ktte40x.js +0 -185
- package/dist/chunk-1acb8fwq.js +0 -120
- package/dist/chunk-3pwqqk7w.js +0 -1
- package/dist/chunk-3q7g9206.js +0 -1
- package/dist/chunk-562w5zc6.js +0 -2
- package/dist/chunk-5x56nka1.js +0 -1
- package/dist/chunk-7hajkvde.js +0 -1
- package/dist/chunk-9wptwfmg.js +0 -1
- package/dist/chunk-ap01rwg0.js +0 -169
- package/dist/chunk-cm8fy1jn.js +0 -1
- package/dist/chunk-dp4r5bay.js +0 -1
- package/dist/chunk-dtxza4zh.js +0 -1
- package/dist/chunk-hd7bxzvy.js +0 -1
- package/dist/chunk-hks48s9k.js +0 -1
- package/dist/chunk-hmncnf7p.js +0 -1
- package/dist/chunk-j6fj679p.js +0 -10
- package/dist/chunk-m8czdpyg.js +0 -1
- package/dist/chunk-p5awnndq.js +0 -8
- package/dist/chunk-s7peh6kf.js +0 -2
- package/dist/chunk-ws6gtw33.js +0 -1
- package/dist/chunk-wtmhqy5s.js +0 -1
- package/dist/chunk-xnstybjm.js +0 -2
- package/dist/chunk-xpdtg9h9.js +0 -23
- package/dist/chunk-z2jwm4s8.js +0 -1
- package/dist/web/assets/ChatView-DCHnicTP.js +0 -58
- package/dist/web/assets/FilePreview-C_3KHzzj.js +0 -65
- package/dist/web/assets/KanbanBoard-D_NTkUnD.js +0 -16
- package/dist/web/assets/TaskSwitcher-eCdxu5Eo.js +0 -26
- package/dist/web/assets/TerminalPanel-9q9Trmv9.js +0 -6
- package/dist/web/assets/index-DGf6Z2kM.css +0 -1
- package/dist/web/assets/index-DaiT-mmo.js +0 -275
- package/dist/web/assets/session-events-CWzF04l4.js +0 -22
- package/dist/web/assets/teamService-BliaDj1Z.js +0 -1
- package/dist/web/assets/vendor-radix-Bc1_Q9tz.js +0 -45
package/dist/chunk-0ktte40x.js
DELETED
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import{Ui as Z_}from"./chunk-r04vwtej.js";import{Aj as P,Bj as G_,Dj as v,Ej as c,Gj as T_,Hj as U_,Kj as D,Mj as i,Nj as L,Vj as F_,qj as Y_,yj as q}from"./chunk-xnstybjm.js";import{Wj as b}from"./chunk-mm05y2c5.js";import{readdir as l,stat as C_}from"node:fs/promises";import f from"node:path";import*as k from"node:path";var __=50,E_=100,I_=new Set(["queued","running","completed","failed","cancelled","interrupted"]),k_=new Set(["high","medium","low"]),M_=/^[A-Za-z0-9_-]+$/,D_=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?(?:Z|[+-]\d{2}:\d{2})$/,q_=/^acp-remote-exact-path:[a-f0-9]{64}$/;function g_(_){return typeof _==="string"&&D_.test(_)&&Number.isFinite(Date.parse(_))}function s(_){return typeof _==="string"&&k.isAbsolute(_)}function r(_){return typeof _==="string"&&q_.test(_)}function z_(_){return Buffer.from(JSON.stringify(_),"utf8").toString("base64url")}function J_(_){return Buffer.from(JSON.stringify(_),"utf8").toString("base64url")}function w_(_){try{if(!M_.test(_))throw Error("invalid");let E=Buffer.from(_,"base64url").toString("utf8");if(Buffer.from(E,"utf8").toString("base64url")!==_)throw Error("invalid");let M=JSON.parse(E);if(M.version!==1||M.kind!==void 0&&M.kind!=="local"||typeof M.includeSubagents!=="boolean"||M.archived!==void 0&&typeof M.archived!=="boolean"||!(M.cwd===null||s(M.cwd))||!g_(M.lastMessageTime)||!s(M.projectPath)||!D(M.sessionId))throw Error("invalid");return{version:1,kind:"local",cwd:M.cwd===null?null:k.resolve(M.cwd),includeSubagents:M.includeSubagents,archived:M.archived??!1,lastMessageTime:M.lastMessageTime,projectPath:k.resolve(M.projectPath),sessionId:M.sessionId}}catch{throw Error("Invalid session cursor")}}function O_(_){try{if(!M_.test(_))throw Error("invalid");let E=Buffer.from(_,"base64url").toString("utf8");if(Buffer.from(E,"utf8").toString("base64url")!==_)throw Error("invalid");let M=JSON.parse(E),g=Object.keys(M),W=new Set(["version","kind","exactIdentity","includeSubagents","archived","lastMessageTime","workspaceIdentity","sessionId"]);if(g.some(($)=>!W.has($))||M.version!==1||M.kind!=="remote"||typeof M.includeSubagents!=="boolean"||typeof M.archived!=="boolean"||!(M.exactIdentity===null||r(M.exactIdentity))||!g_(M.lastMessageTime)||!r(M.workspaceIdentity)||!D(M.sessionId))throw Error("invalid");return{version:1,kind:"remote",exactIdentity:M.exactIdentity??null,includeSubagents:M.includeSubagents,archived:M.archived,lastMessageTime:M.lastMessageTime,workspaceIdentity:M.workspaceIdentity,sessionId:M.sessionId}}catch{throw Error("Invalid remote session cursor")}}function S(_){let E="";for(let M=0;M<_.length;M+=1)E+=_.charCodeAt(M).toString(16).padStart(4,"0");return E}function N_(_){if(!_.cursor)return;let E=w_(_.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 L_(_){if(!_.cursor)return;let E=O_(_.cursor);if(E.exactIdentity!==_.exactIdentity||_.exactIdentity!==null&&E.workspaceIdentity!==_.exactIdentity||E.includeSubagents!==_.includeSubagents||(E.archived??!1)!==_.archived)throw Error("Remote session cursor scope does not match this query");return E}function _E(_={}){let{cwd:E,cursor:M,limit:g,includeSubagents:W=!1,archived:$=!1}=_;if(E!==void 0&&!k.isAbsolute(E))throw Error("Session catalog cwd must be absolute");let V=g===void 0?__:g;if(!Number.isInteger(V)||V<1||V>E_)throw Error("Session catalog limit must be an integer from 1 to 100");return{cwd:E===void 0?null:k.resolve(E),cursor:M??void 0,limit:V,includeSubagents:W,archived:$}}function EE(_={}){let{descriptor:E,cursor:M,limit:g,includeSubagents:W=!1,archived:$=!1}=_,V=g===void 0?__:g;if(!Number.isInteger(V)||V<1||V>E_)throw Error("Session catalog limit must be an integer from 1 to 100");return{descriptor:E,exactIdentity:E?.exactIdentity??null,cursor:M??void 0,limit:V,includeSubagents:W,archived:$}}function ME(_={}){let E=t(_.taskStatus,I_,"task status"),M=t(_.taskPriority,k_,"task priority"),g=e(_.taskDueAfter,"taskDueAfter"),W=e(_.taskDueBefore,"taskDueBefore");return j_(g,W),{...E?{taskStatuses:E}:{},...M?{taskPriorities:M}:{},...g?{taskDueAfter:g}:{},...W?{taskDueBefore:W}:{}}}function t(_,E,M){if(_===void 0)return;let g=Array.isArray(_)?_:[_];if(g.length===0)return;let W=new Set;for(let $ of g){if(typeof $!=="string"||!E.has($))throw Error(`Invalid session ${M} filter`);W.add($)}return[...W].sort()}function e(_,E){if(_===void 0)return;if(typeof _!=="string"||!Number.isFinite(Date.parse(_)))throw Error(`Invalid session ${E} filter`);return new Date(_).toISOString()}function j_(_,E){if(_!==void 0&&E!==void 0&&_>E)throw Error("Session task due range is inverted")}function K_(_,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 P_(_,E){if(_.lastMessageTime>E.lastMessageTime)return-1;if(_.lastMessageTime<E.lastMessageTime)return 1;if(_.workspaceIdentity<E.workspaceIdentity)return-1;if(_.workspaceIdentity>E.workspaceIdentity)return 1;if(_.sessionId<E.sessionId)return-1;if(_.sessionId>E.sessionId)return 1;return 0}function gE(_,E){let M=[..._],g=N_(E);if(g)M=M.filter((V)=>K_(V,{sessionId:g.sessionId,projectPath:g.projectPath,lastMessageTime:g.lastMessageTime})>0);let W=M.slice(0,E.limit);if(W.length===0||M.length<=W.length)return{sessions:W};let $=W[W.length-1];return{sessions:W,nextCursor:z_({version:1,kind:"local",cwd:E.cwd,includeSubagents:E.includeSubagents,archived:E.archived,lastMessageTime:$.lastMessageTime,projectPath:$.projectPath,sessionId:$.sessionId})}}function WE(_,E){let M=[..._],g=L_(E);if(g)M=M.filter((V)=>P_(V,{sessionId:g.sessionId,projectPath:V.projectPath,lastMessageTime:g.lastMessageTime,workspaceIdentity:g.workspaceIdentity})>0);let W=M.slice(0,E.limit);if(W.length===0||M.length<=W.length)return{sessions:W};let $=W[W.length-1];return{sessions:W,nextCursor:J_({version:1,kind:"remote",exactIdentity:E.exactIdentity,includeSubagents:E.includeSubagents,archived:E.archived,lastMessageTime:$.lastMessageTime,workspaceIdentity:$.workspaceIdentity,sessionId:$.sessionId})}}function f_(_){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 m(_){return _.type==="message_created"&&_.data.role==="user"&&(_.data.inboxMessageId!==void 0||_.data.parentMessageId===void 0)}function u(_,E){let M=_.find((g)=>m(g)&&g.data.messageId===E);if(!M)throw Error(`Rewind checkpoint not found: ${E}`);return{messageId:E,preview:W_(_,E),createdAt:M.data.createdAt}}function W_(_,E){let M=_.flatMap((g)=>{if(g.type!=="part_created"||g.data.messageId!==E)return[];if(g.data.partType==="text"){let W=g.data.payload;return typeof W.text==="string"?[W.text]:[]}if(g.data.partType==="image")return["[Image]"];return[]}).join("").trim();if(M.length<=160)return M;return`${M.slice(0,160)}...`}function $_(_,E){u(_,E);let M=_.findIndex((V)=>V.type==="message_created"&&V.data.messageId===E),g=_[M],W=g?.type==="message_created"?g.data.inboxMessageId:void 0,$=new Set(_.flatMap((V)=>V.type==="turn_started"&&W&&V.data.inputMessageIds?.includes(W)?[V.data.turnId]:[]));return _.filter((V,Q)=>{if((V.type==="turn_started"||V.type==="turn_completed"||V.type==="turn_aborted"||V.type==="turn_recovery_acknowledged")&&$.has(V.data.turnId))return!1;return Q<M||!f_(V)})}function j(_){let E=[];for(let M of _){if(M.type!=="session_rewound"){E.push(M);continue}if(u(E,M.data.targetMessageId),M.data.mode!=="code")E=$_(E,M.data.targetMessageId)}return E}function VE(_){let E=j(_);return E.filter(m).map((M)=>({messageId:M.data.messageId,preview:W_(E,M.data.messageId),createdAt:M.data.createdAt})).reverse()}function HE(_,E){let M=j(_),g=u(M,E),W=M.findIndex((V)=>V.type==="message_created"&&V.data.messageId===E),$=M.slice(W);return{checkpoint:g,projectedEntries:$_(M,E),removedTurns:$.filter(m).length,snapshotMessageIds:$.flatMap((V)=>V.type==="part_created"&&V.data.partType==="tool_call"?[V.data.partId]:[])}}import*as C from"node:fs";import{createReadStream as v_}from"node:fs";import*as G from"node:fs/promises";import*as h from"node:path";import{createInterface as S_}from"node:readline";var V_=65536;function K(_){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 m_(_,E,M){let g=_.trim();if(!g)return;try{return JSON.parse(g)}catch(W){throw Error(`Invalid session JSONL in ${M} at line ${E}`,{cause:W})}}function w(_,E="session transcript"){let M=_.split(`
|
|
2
|
-
`),g=!_.endsWith(`
|
|
3
|
-
`),W=[];for(let[$,V]of M.entries())try{let Q=m_(V,$+1,E);if(Q){if(typeof Q.seq!=="number")Q.seq=W.length+1;W.push(Q)}}catch(Q){if(g&&$===M.length-1)break;throw Q}return W}class Z{static appendQueues=new Map;filePath;constructor(_){this.filePath=_}static maxSeq(_){let E=0;for(let M of _)if(typeof M.seq==="number"&&M.seq>E)E=M.seq;return E}static stampSeqFrom(_,E){let M=E;return _.map((g)=>{if(typeof g.seq==="number"){if(g.seq>M)M=g.seq;return g}return M+=1,{...g,seq:M}})}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 G.mkdir(h.dirname(this.filePath),{recursive:!0,mode:493});let E=await G.open(this.filePath,"a+",384);try{let M=await this.repairIncompleteTail(E),g=await this.readTailSeq(E),W=Z.stampSeqFrom(_,g),$=`${W.map(K).join(`
|
|
4
|
-
`)}
|
|
5
|
-
`;return await E.appendFile(M+$,"utf8"),await E.sync(),W}finally{await E.close()}})}async createExclusive(_){if(_.length===0)throw Error("Cannot create an empty session transcript");await G.mkdir(h.dirname(this.filePath),{recursive:!0,mode:493});let E;try{E=await G.open(this.filePath,"wx",384);let g=`${Z.stampSeq(_,[]).map(K).join(`
|
|
6
|
-
`)}
|
|
7
|
-
`;await E.writeFile(g,"utf-8"),await E.sync()}catch(M){if(E)await E.close(),E=void 0,await G.unlink(this.filePath).catch(()=>{return});throw M}finally{await E?.close()}}async readAll(){if(!C.existsSync(this.filePath))return[];let _=await G.readFile(this.filePath,"utf-8");return w(_,this.filePath)}async readStream(_){return new Promise((E,M)=>{if(!C.existsSync(this.filePath)){E();return}let g=v_(this.filePath,"utf-8"),W=S_({input:g,crlfDelay:Number.POSITIVE_INFINITY}),$=0;W.on("line",async(V)=>{let Q=V.trim();if(Q.length===0)return;try{let H=JSON.parse(Q);if($+=1,typeof H.seq!=="number")H.seq=$;await _(H)}catch(H){console.warn(`[JSONLStore] 解析 JSON 行失败: ${Q}`,H)}}),W.on("close",()=>E()),W.on("error",M),g.on("error",M)})}async filter(_){let E=[];return await this.readStream((M)=>{if(_(M))E.push(M)}),E}async readLast(_){return(await this.readAll()).slice(-_)}async readFromSeq(_){return(await this.readAll()).filter((M)=>(M.seq??0)>=_)}async getStats(){try{if(!C.existsSync(this.filePath))return{exists:!1,size:0,lineCount:0};let _=await G.stat(this.filePath),M=(await G.readFile(this.filePath,"utf-8")).split(`
|
|
8
|
-
`).filter((g)=>g.trim().length>0).length;return{exists:!0,size:_.size,lineCount:M}}catch(_){return console.error(`[JSONLStore] 获取统计信息失败: ${this.filePath}`,_),{exists:!1,size:0,lineCount:0}}}async exists(){try{return await G.access(this.filePath),!0}catch{return!1}}async delete(){try{return await this.enqueue(async()=>{try{return await G.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 G.open(this.filePath,"r")}catch(g){if(g.code==="ENOENT")return!1;throw g}let M;try{M=w(await E.readFile("utf8"),"session transcript")}finally{await E.close()}if(!_(M))return!1;try{return await G.unlink(this.filePath),!0}catch(g){if(g.code==="ENOENT")return!1;throw g}})}async appendValidated(_,E={}){return this.appendValidatedAsync(async(M)=>_(M),E)}async appendValidatedBatch(_,E={}){return this.appendValidatedBatchAsync(async(M)=>_(M),E)}async appendValidatedBatchAsync(_,E={}){return this.enqueue(async()=>{let M=E.noFollow?C.constants.O_RDWR|(C.constants.O_NOFOLLOW??0):"r+",g=await G.open(this.filePath,M);try{await E.validateHandle?.(g);let{entries:W,separator:$,size:V}=await this.readCommittedState(g,"session transcript"),Q=await _(W);if(Q.length===0)return[];let H=Z.stampSeq(Q,W),U=`${H.map(K).join(`
|
|
9
|
-
`)}
|
|
10
|
-
`;return await g.write($+U,V,"utf8"),await g.sync(),await E.validateHandle?.(g),H}finally{await g.close()}})}async appendValidatedAsync(_,E={}){return this.enqueue(async()=>{let M=E.noFollow?C.constants.O_RDWR|(C.constants.O_NOFOLLOW??0):"r+",g=await G.open(this.filePath,M);try{await E.validateHandle?.(g);let{entries:W,separator:$,size:V}=await this.readCommittedState(g,"session transcript"),Q=await _(W),[H]=Z.stampSeq([Q],W),U=`${$}${K(H)}
|
|
11
|
-
`;return await g.write(U,V,"utf8"),await g.sync(),await E.validateHandle?.(g),H}finally{await g.close()}})}async readAllValidated(_={}){let E=_.noFollow?C.constants.O_RDONLY|(C.constants.O_NOFOLLOW??0):"r",M;try{M=await G.open(this.filePath,E)}catch(g){if(g.code==="ENOENT")return[];throw g}try{await _.validateHandle?.(M);let g=w(await M.readFile("utf8"),"session transcript");return await _.validateHandle?.(M),g}finally{await M.close()}}getFilePath(){return this.filePath}async enqueue(_){let M=(Z.appendQueues.get(this.filePath)??Promise.resolve()).catch(()=>{return}).then(_),g=M.then(()=>{return},()=>{return});Z.appendQueues.set(this.filePath,g);try{return await M}finally{if(Z.appendQueues.get(this.filePath)===g)Z.appendQueues.delete(this.filePath)}}async readCommittedState(_,E=this.filePath){let M=await this.repairIncompleteTail(_),g=await _.readFile("utf8"),W=w(g,E),{size:$}=await _.stat();return{entries:W,separator:M,size:$}}async readTailSeq(_){let{size:E}=await _.stat();if(E===0)return 0;let M=Math.max(0,E-V_),g=Buffer.allocUnsafe(E-M);await _.read(g,0,g.length,M);let W=g.toString("utf8").split(`
|
|
12
|
-
`);for(let V=W.length-1;V>=0;V--){let Q=W[V].trim();if(!Q)continue;if(V===0&&M>0)break;try{let H=JSON.parse(Q).seq;if(typeof H==="number")return H}catch{}break}let $=await _.readFile("utf8");return Z.maxSeq(w($,this.filePath))}async repairIncompleteTail(_){let{size:E}=await _.stat();if(E===0)return"";let M=Buffer.allocUnsafe(1);if(await _.read(M,0,1,E-1),M[0]===10)return"";let g=await this.findTailStart(_,E),W=Buffer.allocUnsafe(E-g);await _.read(W,0,W.length,g);try{return JSON.parse(W.toString("utf8").trim()),`
|
|
13
|
-
`}catch{return await _.truncate(g),""}}async findTailStart(_,E){let M=E;while(M>0){let g=Math.max(0,M-V_),W=Buffer.allocUnsafe(M-g);await _.read(W,0,W.length,g);let $=W.lastIndexOf(10);if($>=0)return g+$+1;M=g}return 0}}function u_(){return typeof globalThis.Bun<"u"}function h_(_){return{exec:(E)=>_.exec(E),prepare:(E)=>{let M=_.prepare(E);return{run:(...g)=>{M.run(...g)},get:(...g)=>M.get(...g),all:(...g)=>M.all(...g)}},transaction:(E)=>_.transaction(E)(),pragma:(E)=>_.pragma(E,{simple:!0}),close:()=>_.close()}}function b_(_){return{exec:(E)=>_.exec(E),prepare:(E)=>{let M=_.query(E);return{run:(...g)=>{M.run(...g)},get:(...g)=>M.get(...g),all:(...g)=>M.all(...g)}},transaction:(E)=>_.transaction(E)(),pragma:(E)=>{let M=_.query(`PRAGMA ${E}`).get();if(!M)return;let g=Object.values(M);return g.length===1?g[0]:M},close:()=>_.close()}}var p_=["PRAGMA journal_mode=WAL;","PRAGMA busy_timeout=5000;","PRAGMA synchronous=NORMAL;","PRAGMA foreign_keys=ON;"].join(`
|
|
14
|
-
`);async function H_(_){try{let E;if(u_()){let{Database:g}=await import("bun:sqlite");E=b_(new g(_))}else{let W=(await import("better-sqlite3")).default;E=h_(new W(_))}return E.exec(p_),E}catch{return null}}function Q_(_){let E=Number(_.pragma("user_version")??0);if(E===6)return;if(E>0&&E!==6)_.exec(`
|
|
15
|
-
DROP TABLE IF EXISTS parts_fts;
|
|
16
|
-
DROP TABLE IF EXISTS parts;
|
|
17
|
-
DROP TABLE IF EXISTS sessions;
|
|
18
|
-
DROP TABLE IF EXISTS projection_state;
|
|
19
|
-
`);_.exec(`
|
|
20
|
-
CREATE TABLE IF NOT EXISTS projection_state (
|
|
21
|
-
source_kind TEXT NOT NULL CHECK(source_kind IN ('local', 'acp-remote')),
|
|
22
|
-
project_path TEXT NOT NULL,
|
|
23
|
-
session_id TEXT NOT NULL,
|
|
24
|
-
last_seq INTEGER NOT NULL DEFAULT 0,
|
|
25
|
-
file_size INTEGER NOT NULL DEFAULT 0,
|
|
26
|
-
mtime_ms INTEGER NOT NULL DEFAULT 0,
|
|
27
|
-
stat_fingerprint TEXT NOT NULL DEFAULT '',
|
|
28
|
-
PRIMARY KEY (source_kind, project_path, session_id)
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
CREATE TABLE IF NOT EXISTS sessions (
|
|
32
|
-
source_kind TEXT NOT NULL CHECK(source_kind IN ('local', 'acp-remote')),
|
|
33
|
-
project_path TEXT NOT NULL,
|
|
34
|
-
session_id TEXT NOT NULL,
|
|
35
|
-
root_id TEXT,
|
|
36
|
-
parent_id TEXT,
|
|
37
|
-
relation_type TEXT,
|
|
38
|
-
title TEXT,
|
|
39
|
-
agent_type TEXT,
|
|
40
|
-
model TEXT,
|
|
41
|
-
task_status TEXT,
|
|
42
|
-
task_priority TEXT,
|
|
43
|
-
task_kind TEXT,
|
|
44
|
-
task_due_at TEXT,
|
|
45
|
-
archived_at TEXT,
|
|
46
|
-
last_message_time TEXT,
|
|
47
|
-
project_sort_key TEXT NOT NULL,
|
|
48
|
-
session_sort_key TEXT NOT NULL,
|
|
49
|
-
first_message_time TEXT,
|
|
50
|
-
message_count INTEGER NOT NULL DEFAULT 0,
|
|
51
|
-
has_errors INTEGER NOT NULL DEFAULT 0,
|
|
52
|
-
is_subagent INTEGER NOT NULL DEFAULT 0,
|
|
53
|
-
-- 完整 StoredSessionMetadata JSON,读回时直接反序列化,保证与 JSONL 路径一致。
|
|
54
|
-
metadata_json TEXT NOT NULL,
|
|
55
|
-
PRIMARY KEY (source_kind, project_path, session_id)
|
|
56
|
-
);
|
|
57
|
-
CREATE INDEX IF NOT EXISTS idx_sessions_catalog ON sessions(
|
|
58
|
-
source_kind,
|
|
59
|
-
last_message_time DESC,
|
|
60
|
-
project_sort_key ASC,
|
|
61
|
-
session_sort_key ASC
|
|
62
|
-
);
|
|
63
|
-
CREATE INDEX IF NOT EXISTS idx_sessions_archived ON sessions(
|
|
64
|
-
source_kind,
|
|
65
|
-
archived_at,
|
|
66
|
-
project_path,
|
|
67
|
-
parent_id
|
|
68
|
-
);
|
|
69
|
-
-- 任务看板过滤/排序:按项目锁定后再按状态、优先级、截止时间收敛。
|
|
70
|
-
CREATE INDEX IF NOT EXISTS idx_sessions_task_board ON sessions(
|
|
71
|
-
project_path,
|
|
72
|
-
task_status,
|
|
73
|
-
task_priority,
|
|
74
|
-
task_due_at,
|
|
75
|
-
source_kind
|
|
76
|
-
);
|
|
77
|
-
CREATE INDEX IF NOT EXISTS idx_sessions_task_status ON sessions(
|
|
78
|
-
task_status,
|
|
79
|
-
project_path,
|
|
80
|
-
source_kind
|
|
81
|
-
);
|
|
82
|
-
CREATE INDEX IF NOT EXISTS idx_sessions_task_priority ON sessions(
|
|
83
|
-
task_priority,
|
|
84
|
-
task_due_at,
|
|
85
|
-
source_kind
|
|
86
|
-
) WHERE task_priority IS NOT NULL;
|
|
87
|
-
CREATE INDEX IF NOT EXISTS idx_sessions_task_due_at ON sessions(
|
|
88
|
-
task_due_at,
|
|
89
|
-
source_kind
|
|
90
|
-
) WHERE task_due_at IS NOT NULL;
|
|
91
|
-
|
|
92
|
-
CREATE TABLE IF NOT EXISTS parts (
|
|
93
|
-
source_kind TEXT NOT NULL CHECK(source_kind IN ('local', 'acp-remote')),
|
|
94
|
-
project_path TEXT NOT NULL,
|
|
95
|
-
session_id TEXT NOT NULL,
|
|
96
|
-
part_id TEXT NOT NULL,
|
|
97
|
-
message_id TEXT,
|
|
98
|
-
part_type TEXT,
|
|
99
|
-
role TEXT,
|
|
100
|
-
seq INTEGER,
|
|
101
|
-
timestamp TEXT,
|
|
102
|
-
text TEXT,
|
|
103
|
-
PRIMARY KEY (source_kind, project_path, session_id, part_id)
|
|
104
|
-
);
|
|
105
|
-
CREATE INDEX IF NOT EXISTS idx_parts_session ON parts(
|
|
106
|
-
source_kind, project_path, session_id
|
|
107
|
-
);
|
|
108
|
-
|
|
109
|
-
CREATE VIRTUAL TABLE IF NOT EXISTS parts_fts USING fts5(
|
|
110
|
-
text,
|
|
111
|
-
source_kind UNINDEXED,
|
|
112
|
-
project_path UNINDEXED,
|
|
113
|
-
session_id UNINDEXED,
|
|
114
|
-
part_id UNINDEXED,
|
|
115
|
-
role UNINDEXED,
|
|
116
|
-
timestamp UNINDEXED,
|
|
117
|
-
seq UNINDEXED,
|
|
118
|
-
tokenize = 'unicode61'
|
|
119
|
-
);
|
|
120
|
-
`),_.exec("PRAGMA user_version=6;")}var c_=Z_("Service"),B_={readSession(_){return _.readAll()}},d=B_;function qE(_){d=_}function zE(){d=B_}var O;function A_(){return f.join(Y_(),"index.db")}async function l_(){let _=A_();if(O&&O.path===_)return O.db;let E=(async()=>{let M=await H_(_);if(!M)return null;try{return Q_(M),M}catch{return null}})();return O={path:_,db:E},E}function n_(){O=void 0}function a_(_){if(_&&typeof _==="object"){let E=_.text;if(typeof E==="string")return E}return null}function i_(_,E,M,g,W){_.prepare("DELETE FROM parts WHERE source_kind=? AND project_path=? AND session_id=?").run(E,M,g),_.prepare("DELETE FROM parts_fts WHERE source_kind=? AND project_path=? AND session_id=?").run(E,M,g);let $=new Map;for(let H of W)if(H.type==="message_created")$.set(H.data.messageId,H.data.role);let V=_.prepare(`INSERT OR REPLACE INTO parts
|
|
121
|
-
(source_kind, project_path, session_id, part_id, message_id, part_type, role,
|
|
122
|
-
seq, timestamp, text)
|
|
123
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`),Q=_.prepare(`INSERT INTO parts_fts
|
|
124
|
-
(text, source_kind, project_path, session_id, part_id, role, timestamp, seq)
|
|
125
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`);for(let H of W){if(H.type!=="part_created"&&H.type!=="part_updated")continue;if(H.data.partType!=="text")continue;let U=a_(H.data.payload);if(U===null)continue;let T=$.get(H.data.messageId)??"assistant",A=H.seq??0;if(V.run(E,M,g,H.data.partId,H.data.messageId,H.data.partType,T,A,H.timestamp,U),T==="user"||T==="assistant")Q.run(U,E,M,g,H.data.partId,T,H.timestamp,A)}}function d_(_,E,M){_.prepare(`INSERT INTO sessions
|
|
126
|
-
(source_kind, project_path, session_id, root_id, parent_id, relation_type, title,
|
|
127
|
-
agent_type, model, task_status, task_priority, task_kind, task_due_at,
|
|
128
|
-
archived_at, last_message_time, project_sort_key,
|
|
129
|
-
session_sort_key, first_message_time, message_count, has_errors,
|
|
130
|
-
is_subagent, metadata_json)
|
|
131
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
132
|
-
ON CONFLICT(source_kind, project_path, session_id) DO UPDATE SET
|
|
133
|
-
root_id=excluded.root_id, parent_id=excluded.parent_id,
|
|
134
|
-
relation_type=excluded.relation_type, title=excluded.title,
|
|
135
|
-
agent_type=excluded.agent_type, model=excluded.model,
|
|
136
|
-
task_status=excluded.task_status, task_priority=excluded.task_priority,
|
|
137
|
-
task_kind=excluded.task_kind, task_due_at=excluded.task_due_at,
|
|
138
|
-
archived_at=excluded.archived_at,
|
|
139
|
-
last_message_time=excluded.last_message_time,
|
|
140
|
-
project_sort_key=excluded.project_sort_key,
|
|
141
|
-
session_sort_key=excluded.session_sort_key,
|
|
142
|
-
first_message_time=excluded.first_message_time, message_count=excluded.message_count,
|
|
143
|
-
has_errors=excluded.has_errors, is_subagent=excluded.is_subagent,
|
|
144
|
-
metadata_json=excluded.metadata_json`).run(E,M.projectPath,M.sessionId,M.rootId,M.parentId??null,M.relationType??null,M.title??null,M.agentType??null,M.model??null,M.taskStatus,M.taskPriority??null,M.taskKind??null,M.taskDueAt??null,M.archivedAt??null,M.lastMessageTime,S(M.projectPath),S(M.sessionId),M.firstMessageTime,M.messageCount,M.hasErrors?1:0,M.relationType==="subagent"?1:0,JSON.stringify(M))}function o(_,E,M,g){for(let W of["sessions","parts","parts_fts"])_.prepare(`DELETE FROM ${W} WHERE source_kind=? AND project_path=? AND session_id=?`).run(E,M,g)}function x(_,E,M,g){o(_,E,M,g),_.prepare("DELETE FROM projection_state WHERE source_kind=? AND project_path=? AND session_id=?").run(E,M,g)}function o_(_,E,M){let g=_.prepare(`SELECT project_path, session_id FROM sessions
|
|
145
|
-
WHERE source_kind=? AND json_extract(metadata_json, '$.filePath')=?`).all(E,M);for(let W of g)o(_,E,W.project_path,W.session_id)}function p(_,E,M,g,W,$,V,Q){_.prepare(`INSERT INTO projection_state
|
|
146
|
-
(source_kind, project_path, session_id, last_seq, file_size, mtime_ms,
|
|
147
|
-
stat_fingerprint)
|
|
148
|
-
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
149
|
-
ON CONFLICT(source_kind, project_path, session_id) DO UPDATE SET
|
|
150
|
-
last_seq=excluded.last_seq, file_size=excluded.file_size,
|
|
151
|
-
mtime_ms=excluded.mtime_ms, stat_fingerprint=excluded.stat_fingerprint`).run(E,M,g,W,$,V,Q)}function N(_){return[_.dev,_.ino,_.size,_.mtimeNs,_.ctimeNs].join(":")}async function R_(_,E,M,g,W,$="local"){if($==="acp-remote")return v(M,async(V)=>{let Q=L(V,E),H=W??Q;if(H!==Q)throw new q("remote-session-file-path");return n(_,E,M,g,H,$,V)});return n(_,E,M,g,W??i(M,E),$)}async function n(_,E,M,g,W,$,V){if($==="acp-remote"){if(!V)throw new q("remote-session-scope");try{await c(V,W)}catch(Y){if(Y.code!=="ENOENT")throw Y;return _.transaction(()=>x(_,$,M,E)),!0}}let Q;try{Q=await C_(W,{bigint:!0})}catch(Y){let J=Y.code;if($==="acp-remote"&&J!=="ENOENT")throw Y;return _.transaction(()=>x(_,$,M,E)),!0}let H=_.prepare(`SELECT last_seq, file_size, mtime_ms, stat_fingerprint FROM projection_state
|
|
152
|
-
WHERE source_kind=? AND project_path=? AND session_id=?`).get($,M,E);if($==="local"&&H&&H.stat_fingerprint===N(Q))return!1;let U=new Z(W),T;try{T=await d.readSession(U)}catch(Y){if($!=="acp-remote"||Y.code!=="ENOENT")throw Y;return _.transaction(()=>x(_,$,M,E)),!0}if($==="acp-remote"&&T.length===0){try{await c(V,W)}catch(Y){if(Y.code==="ENOENT")return _.transaction(()=>x(_,$,M,E)),!0;throw Y}throw new q("remote-session-empty")}let A=$==="local"?T.find((Y)=>Y.type==="session_created"):void 0,z=$==="local"&&A!==void 0&&Object.hasOwn(A.data,"remoteWorkspace"),y=null;if($==="acp-remote"){let Y=T_(T,E,M);y=P(Y.data.remoteWorkspace)}else if(z)P(A.data.remoteWorkspace);let R=T.reduce((Y,J)=>typeof J.seq==="number"&&J.seq>Y?J.seq:Y,0),F=j(T),X=z?null:g(T,E,M,$,W),B=X?.remoteWorkspace;if($==="acp-remote"){if(!X||X.sessionId!==E||X.projectPath!==M||B===void 0)throw new q("remote-session-metadata");let Y=P(B);if(!y||Y.style!==y.style||Y.wirePath!==y.wirePath||Y.exactIdentity!==y.exactIdentity||Y.collisionIdentity!==y.collisionIdentity)throw new q("remote-session-descriptor");if(G_(Y.collisionIdentity)!==M)throw new q("remote-session-project-path")}if(T.length===0||!X||$==="local"&&B!==void 0)return _.transaction(()=>{if(z)o_(_,$,W),x(_,$,M,E);else o(_,$,M,E),p(_,$,M,E,R,Number(Q.size),Number(Q.mtimeMs),N(Q))}),!0;let I=_.prepare(`SELECT last_message_time FROM sessions
|
|
153
|
-
WHERE source_kind=? AND project_path=? AND session_id=?`).get($,X.projectPath,X.sessionId),y_=$==="acp-remote"&&V?L(V,X.sessionId):i(X.projectPath,X.sessionId),x_=f.resolve(W)===f.resolve(y_);if(I&&!x_&&typeof I.last_message_time==="string"&&I.last_message_time>X.lastMessageTime)return p(_,$,M,E,R,Number(Q.size),Number(Q.mtimeMs),N(Q)),!0;return _.transaction(()=>{d_(_,$,X),i_(_,$,X.projectPath,X.sessionId,F),p(_,$,M,E,R,Number(Q.size),Number(Q.mtimeMs),N(Q))}),!0}var X_=new WeakMap;function a(_,E,M,g){let W=_.prepare(`SELECT session_id FROM projection_state
|
|
154
|
-
WHERE source_kind=? AND project_path=?
|
|
155
|
-
UNION
|
|
156
|
-
SELECT session_id FROM sessions
|
|
157
|
-
WHERE source_kind=? AND project_path=?
|
|
158
|
-
UNION
|
|
159
|
-
SELECT session_id FROM parts
|
|
160
|
-
WHERE source_kind=? AND project_path=?
|
|
161
|
-
UNION
|
|
162
|
-
SELECT session_id FROM parts_fts
|
|
163
|
-
WHERE source_kind=? AND project_path=?`).all(E,M,E,M,E,M,E,M);for(let $ of W)if(!g.has($.session_id))x(_,E,M,$.session_id)}async function s_(_,E,M){try{await v(M,async(g)=>{let W=(await l(String(g))).flatMap((H)=>{if(!H.endsWith(".jsonl"))return[];let U=H.slice(0,-6);if(!D(U))return[];return[{filePath:L(g,U),sessionId:U}]}),$=new Set(W.map((H)=>H.sessionId)),V=Math.min(32,W.length),Q=0;await Promise.all(Array.from({length:V},async()=>{while(Q<W.length){let H=W[Q++];if(!H)continue;await n(_,H.sessionId,M,E,H.filePath,"acp-remote",g)}})),_.transaction(()=>{a(_,"acp-remote",M,$)})})}catch(g){if(g.code!=="ENOENT")throw g;_.transaction(()=>{a(_,"acp-remote",M,new Set)})}}async function JE(_,E){let M=await U_();for(let $ of M)await s_(_,E,String($));let g=new Set(M.map(String)),W=_.prepare(`SELECT project_path FROM projection_state WHERE source_kind='acp-remote'
|
|
164
|
-
UNION
|
|
165
|
-
SELECT project_path FROM sessions WHERE source_kind='acp-remote'
|
|
166
|
-
UNION
|
|
167
|
-
SELECT project_path FROM parts WHERE source_kind='acp-remote'
|
|
168
|
-
UNION
|
|
169
|
-
SELECT project_path FROM parts_fts WHERE source_kind='acp-remote'`).all();for(let $ of W)if(!g.has($.project_path))_.transaction(()=>{a(_,"acp-remote",$.project_path,new Set)})}async function r_(_,E,M=0){let g=X_.get(_)??{};if(X_.set(_,g),g.inFlight)return g.inFlight;if(M>0&&g.lastCompletedAt!==void 0&&Date.now()-g.lastCompletedAt<=M)return;let W=t_(_,E);g.inFlight=W;try{await W,g.lastCompletedAt=Date.now()}finally{if(g.inFlight===W)g.inFlight=void 0}}async function t_(_,E){let M=new Set,g=await F_(),$=(await Promise.all(g.map(async(R)=>{if(R.kind==="local")try{return(await l(R.storagePath)).flatMap((X)=>{if(!X.endsWith(".jsonl"))return[];let B=X.slice(0,-6);if(!D(B))return[];return[{kind:"local",filePath:f.join(R.storagePath,X),projectPath:R.projectPath,sessionId:B}]})}catch{return[]}return v(R.storagePath,async(F)=>{return(await l(String(F))).flatMap((B)=>{if(!B.endsWith(".jsonl"))return[];let I=B.slice(0,-6);if(!D(I))return[];return[{kind:"acp-remote",filePath:L(F,I),projectPath:R.projectPath,sessionId:I}]})})}))).flat();for(let R of $)M.add(`${R.kind}\x00${R.projectPath}\x00${R.sessionId}`);let V=_.prepare(`SELECT source_kind, project_path, session_id, last_seq, file_size, mtime_ms,
|
|
170
|
-
stat_fingerprint
|
|
171
|
-
FROM projection_state`).all(),Q=new Map(V.map((R)=>[`${R.source_kind}\x00${R.project_path}\x00${R.session_id}`,R])),H=[],U=Math.min(128,$.length),T=0;await Promise.all(Array.from({length:U},async()=>{while(T<$.length){let R=$[T++];if(!R)continue;if(R.kind==="acp-remote"){H.push(R);continue}try{let F=await C_(R.filePath,{bigint:!0}),X=Q.get(`${R.kind}\x00${R.projectPath}\x00${R.sessionId}`);if(X&&X.stat_fingerprint===N(F))continue}catch(F){if(F.code!=="ENOENT")throw F}H.push(R)}}));let A=Math.min(32,H.length),z=0;await Promise.all(Array.from({length:A},async()=>{while(z<H.length){let R=H[z++];if(!R)continue;try{if(R.kind==="acp-remote")await R_(_,R.sessionId,R.projectPath,E,R.filePath,"acp-remote");else await R_(_,R.sessionId,R.projectPath,E,R.filePath,"local")}catch(F){let X=F.code;if(R.kind==="acp-remote"){if(X==="ENOENT")continue;throw F}if(X==="acp_remote_workspace_state_invalid")throw F;if(X!=="ENOENT")c_.warn(`[SessionService] Skipping invalid session transcript: ${R.sessionId}`)}}}));let y=_.prepare(`SELECT source_kind, project_path, session_id FROM projection_state
|
|
172
|
-
UNION
|
|
173
|
-
SELECT source_kind, project_path, session_id FROM sessions
|
|
174
|
-
WHERE source_kind='acp-remote'
|
|
175
|
-
UNION
|
|
176
|
-
SELECT source_kind, project_path, session_id FROM parts
|
|
177
|
-
WHERE source_kind='acp-remote'
|
|
178
|
-
UNION
|
|
179
|
-
SELECT source_kind, project_path, session_id FROM parts_fts
|
|
180
|
-
WHERE source_kind='acp-remote'`).all();for(let R of y)if(!M.has(`${R.source_kind}\x00${R.project_path}\x00${R.session_id}`))_.transaction(()=>x(_,R.source_kind,R.project_path,R.session_id))}function wE(_,E,M,g="local"){_.transaction(()=>x(_,g,M,E))}async function OE(_){let{rm:E}=await import("node:fs/promises");n_();let M=A_();for(let $ of["","-wal","-shm"])await E(`${M}${$}`,{force:!0}).catch(()=>{return});let g=await l_();if(!g)return null;return await r_(g,_),g.prepare("SELECT COUNT(*) c FROM sessions").get()?.c??0}function NE(_,E,M,g){let W=E.replace(/["*]/g," ").trim().split(/\s+/)[0];if(!W)return[];let $=`"${W}"*`,V=M?`SELECT session_id, role, timestamp, text FROM parts_fts
|
|
181
|
-
WHERE parts_fts MATCH ? AND source_kind = 'local' AND project_path = ?
|
|
182
|
-
ORDER BY timestamp DESC LIMIT ?`:`SELECT session_id, role, timestamp, text FROM parts_fts
|
|
183
|
-
WHERE parts_fts MATCH ? AND source_kind = 'local'
|
|
184
|
-
ORDER BY timestamp DESC LIMIT ?`,Q=_.prepare(V);return M?Q.all($,M,g):Q.all($,g)}
|
|
185
|
-
export{j as fe,VE as ge,HE as he,w as ie,Z as je,S as ke,N_ as le,L_ as me,_E as ne,EE as oe,ME as pe,K_ as qe,P_ as re,gE as se,WE as te,qE as ue,zE as ve,A_ as we,l_ as xe,n_ as ye,R_ as ze,s_ as Ae,JE as Be,r_ as Ce,wE as De,OE as Ee,NE as Fe};
|