@tbox.cn/dsh-acp-bridge-core 0.1.0-rc.5 → 0.1.0-rc.7
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/lib/index.js +1 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{isAbsolute as e,resolve as t}from"node:path";const n={"user/message":`project`,"assistant/message":`project`,"tool/call":`project`,"tool/result":`project`,"todo/write":`project`,"session/title":`project`,"command/run":`project`,"command/done":`project`,"subagent/catalog":`project`,"turn/start":`project`,"turn/end":`project`,"step/start":`skip`,"step/end":`skip`,"developer/message":`skip`,"system/message":`skip`,"assistant/attempt":`skip`,"request/header":`skip`,"request/context":`skip`,"session/end-seed":`skip`,"agent/inbox/spliced":`skip`,"tool/ptc-dispatch-start":`skip`,"tool/ptc-dispatch":`skip`,"subagent/descriptor":`skip`,"approval/asked":`skip`,"approval/decided":`skip`,"approval/policy":`skip`,"permission/preset":`skip`,"sandbox/mode":`skip`,"model/selection":`skip`,"goal/change":`skip`};function r(e){return n[e]??`unknown`}function i(e){return e.ignorable===!0}const a={read:`read`,read_image:`read`,write:`edit`,edit:`edit`,str_replace_editor:`edit`,bash:`execute`,pwsh:`execute`,glob:`search`,grep:`search`,web_search:`search`,web_fetch:`fetch`,webfetch:`fetch`,todo_write:`think`,plan:`think`,skill:`other`},o=new Set([`edit`,`write`,`scratch_write`,`scratch_edit`,`str_replace_editor`]);function s(e){return a[e]||(e.startsWith(`scratch_`)?a[e.slice(8)]??`other`:(e.startsWith(`subagent_`),`other`))}const c=e=>typeof e==`string`?e:void 0,l=e=>c(e.file_path)??c(e.filePath)??c(e.path),u=e=>c(e.old_string)??c(e.oldString)??c(e.old_str),d=e=>c(e.new_string)??c(e.newString)??c(e.new_str);function f(n,r){if(n!==void 0){if(e(n)||r===void 0)return n;try{return t(r,n)}catch{return n}}}const p=new Set([`scratch_write`,`scratch_edit`]);function m(t,n,r){if(!o.has(t))return[];let i=n??{},a=l(i);if(!a||p.has(t)&&!e(a))return[];let s=typeof i.line==`number`?i.line:typeof i.lineNumber==`number`?i.lineNumber:typeof i.offset==`number`?i.offset:null;return[{path:f(a,r)??a,line:s}]}function h(e,t,n,r){if(!o.has(e))return[];let i=c(n?.path);if(i!==void 0){let e=t??{};return[{path:i,line:typeof e.line==`number`?e.line:typeof e.lineNumber==`number`?e.lineNumber:typeof e.offset==`number`?e.offset:null}]}return m(e,t,r)}const ee=e=>{let t=typeof e.offset==`number`?e.offset:void 0,n=typeof e.limit==`number`?e.limit:void 0;return n!==void 0&&n>0?` (${t??1} - ${(t??1)+n-1})`:t===void 0?``:` (from line ${t})`},te={create:`Create`,str_replace:`Replace`,insert:`Insert`,view:`View`},g={bash:e=>{let t=c(e.command),n=c(e.description);return n?`${n} (${t?.slice(0,60)??``})`:t?`Execute ${t.slice(0,120)}${t.length>120?`…`:``}`:`Execute`},pwsh:e=>{let t=c(e.command);return t?`Execute ${t.slice(0,120)}${t.length>120?`…`:``}`:`Execute`},read:e=>`Read ${l(e)??`file`}${ee(e)}`,read_image:e=>`Read image ${l(e)??`file`}`,write:e=>`Write ${l(e)??`file`}`,edit:e=>`Edit ${l(e)??`file`}`,scratch_bash:e=>{let t=c(e.description);if(t)return`Scratch: ${t}`;let n=c(e.command);return n?`Execute ${n.slice(0,120)}${n.length>120?`…`:``}`:`Execute`},scratch_write:e=>`Write scratch file ${l(e)??`file`}`,scratch_edit:e=>`Edit scratch file ${l(e)??`file`}`,subagent:e=>{let t=c(e.description)??c(e.prompt);return t?`Delegate: ${t}`:`Delegate`},str_replace_editor:e=>{let t=te[c(e.command)??``]??`str_replace_editor`,n=l(e);return n?`${t} ${n}`:t},grep:e=>{let t=c(e.pattern),n=c(e.path);return`Grep${t?` "${t}"`:``}${n?` in ${n}`:``}`},glob:e=>`Glob ${c(e.pattern)??``}`,web_fetch:e=>`Fetch ${c(e.url)??`URL`}`,web_search:e=>{let t=c(e.query);return`Search${t?` "${t}"`:``}`},webfetch:e=>{let t=c(e.url),n=c(e.format);return`Fetch ${t??`URL`}${n&&n!==`markdown`?` (${n})`:``}`},todo_write:e=>{let t=e.todos,n=Array.isArray(t)?t:[],r=n.filter(e=>e.status===`completed`).length;return`Update TODOs${n.length?` (${r}/${n.length})`:``}`},ask_user_question:()=>`Ask the user`,skill:e=>`Load skill: ${c(e.name)??``}`};function _(e,t){return(g[e]??(()=>e))(t??{})}function v(e,t,n){let r=_(e,t),i=n??{};if(e===`write`||e===`scratch_write`)return i.operation===`create`?`${r} (created)`:i.operation===`update`?`${r} (updated)`:r;if(e===`edit`||e===`scratch_edit`){let e=i.diffs;return Array.isArray(e)&&e.length>0?`${r} (${e.length} changes)`:r}return r}function y(e,t,n){return`[${t??`subagent:${n.slice(-8)}`}] ${e}`}function b(e){if(e!==void 0)try{let t=JSON.parse(e);return typeof t==`object`&&t?t:void 0}catch{return}}const x={methodNotFound:-32601,invalidParams:-32602,conflict:-32600,internal:-32603,sessionNotFound:-32002},S=e=>typeof e==`string`?e:void 0;function ne(e){let t=e.message,n=e.data&&typeof e.data==`object`?e.data:{};switch(e.code){case`session-not-found`:{let e=S(n.sessionId);return{code:x.sessionNotFound,message:t??`session not found`,data:e===void 0?void 0:{uri:`session:${e}`}}}case`session/writer-held`:return{code:x.conflict,message:t??`session is owned by another writer`,data:{reason:S(n.reason)??`writer-held`,retryable:!0}};case`turn-error`:return{code:x.internal,message:t??`turn failed`,data:{sessionId:S(n.sessionId),kind:S(n.kind)??`turn-error`,retryable:n.retryable===!0,code:S(n.code),partialOutput:n.partialOutput===!0}};case`llm-auth`:return{code:x.internal,message:t??`llm credential missing`,data:{kind:`auth`,retryable:!1}};case`retry-after-turn`:return{code:x.internal,message:t??`reload in progress`,data:{retryable:!0,reason:`skill_reload_in_progress`}};case`method-not-found`:return{code:x.methodNotFound,message:t??`method not found`};case`invalid-params`:return{code:x.invalidParams,message:t??`invalid params`,data:n.errors===void 0?void 0:{errors:n.errors}};default:return{code:x.internal,message:t??`dsh error`,data:{kind:`unknown-dsh-error`,...e.code===void 0?{}:{code:e.code},...Object.keys(n).length>0?{detail:n}:{}}}}}function C(e){let t=e?.kind;switch(t){case`completed`:case`aborted`:case`blocked`:return{stopReason:`end_turn`};case`interrupted`:return{stopReason:`cancelled`};case`max-tokens`:return{stopReason:`max_tokens`};case`error`:return{error:!0};case`forked`:default:return{stopReason:`end_turn`,warn:`unknown turn end reason: ${String(t)}`}}}const w=[1],T=w[w.length-1]??1;function re(e){return e===void 0?{version:T}:w.includes(e)?{version:e}:{version:T,warn:`client protocol version ${e} not in supported set`}}function ie(e){return{capabilities:{loadSession:!0,promptCapabilities:{}},meta:{openacpagent:{usage:{},image:{}},tboxcode:{protocolVersion:e}}}}var ae=class{#e=new Map;record(e,t,n){this.#e.set(e,{name:t,input:b(n)})}lookup(e){return this.#e.get(e)}},oe=class{byChild=new Map;#e=new Map;#t=new Map;#n=new Map;accept(e){this.byChild.set(e.childId,{mode:e.mode,...e.label===void 0?{}:{label:e.label}});let t=this.#e.size>1;for(let[n,r]of this.#e)this.#t.set(n,{childId:e.childId,toolName:r,...e.label===void 0?{}:{label:e.label},ambiguous:t});this.#e.size===1&&this.#n.set(e.childId,[...this.#e.keys()][0]),this.#e.clear()}trackDelegation(e,t){this.#e.set(e,t)}tracks(e){return this.byChild.has(e)}parentCallIdOf(e){return this.#n.get(e)}labelOfChild(e){return this.byChild.get(e)?.label}metaFor(e,t){let n=this.#t.get(e),r=n?.toolName??t,i=r===`subagent`?`general`:r.startsWith(`subagent_`)?r.slice(9):r;return n===void 0||n.ambiguous?{runId:e,agentType:i}:{runId:n.childId,agentType:i,...n.label===void 0?{}:{name:n.label}}}};const E=e=>typeof e==`string`?e:void 0,D=e=>e.data??{},O=new Set([`write`,`scratch_write`]),k=new Set([`edit`,`scratch_edit`]),se=e=>typeof e==`object`&&!!e&&typeof e.path==`string`&&(e.oldText===null||typeof e.oldText==`string`)&&typeof e.newText==`string`;function A(e,t,n,r){let i=n??{},a=i.diffs;if(Array.isArray(a)&&a.length>0)return a.every(se)?a:[];let o=E(i.path),s=t??{};if(o!==void 0)return O.has(e)?[{path:o,oldText:i.operation===`create`?null:E(i.before)??null,newText:E(i.after)??E(s.content)??``}]:k.has(e)?[{path:o,oldText:E(i.before)??u(s)??null,newText:E(i.after)??d(s)??``}]:[];let c=f(l(s),r);return c===void 0?[]:O.has(e)?[{path:c,oldText:null,newText:E(s.content)??``}]:k.has(e)?[{path:c,oldText:u(s)??null,newText:d(s)??``}]:e===`str_replace_editor`?s.command===`create`?[{path:c,oldText:null,newText:E(s.file_text)??``}]:s.command===`str_replace`?[{path:c,oldText:E(s.old_str)??null,newText:E(s.new_str)??``}]:[]:[]}function j(e,t){return{sessionUpdate:`user_message_chunk`,content:{type:`text`,text:e},...t?{messageId:t}:{}}}function M(e,t){return{sessionUpdate:`agent_message_chunk`,content:{type:`text`,text:e},...t?{messageId:t}:{}}}function N(e,t){return{sessionUpdate:`agent_thought_chunk`,content:{type:`text`,text:e},...t?{messageId:t}:{}}}function ce(e,t,n,r){return{sessionUpdate:`usage_update`,used:e,size:t,_meta:{openacpagent:{usage:{cacheReadTokens:n,cacheWriteTokens:r}}}}}function le(e,t){if(e.source?.kind!==`user`)return[];let n=e,r=typeof n.id==`string`?n.id:null,i=n.content??[];if(i.length===0)return[j(``,r)];let a=[];for(let e of i)e.type===`text`?a.push(j(E(e.text)??``,r)):a.push(j(`[${String(e.type)}]`,r));return a}function ue(e,t){let n=e.message,r=[],i=typeof n?.id==`string`?n.id:null,a=t.seen,o=n?.content??[],s=typeof e.turn==`number`?e.turn:void 0,c=typeof e.step==`number`?e.step:void 0,l=t.live&&a!==void 0&&t.attempts!==void 0&&s!==void 0&&c!==void 0?t.attempts.resolve(s,c,e=>de(e,o)):void 0,u=l?.attemptId??i;if(a&&l!==void 0){let e=a.get(l.attemptId);a.set(l.attemptId,{text:Math.max(e?.text??0,l.text.length),reasoning:Math.max(e?.reasoning??0,l.reasoning.length)})}let d=0,f=0;for(let e of o){let t=e.type;if(t!==`text`&&t!==`reasoning`)continue;let n=E(e.text)??``,i=t===`reasoning`?`reasoning`:`text`,o=i===`reasoning`?f:d;if(a){let e=u??``,t=a.get(e)??{text:0,reasoning:0},s=Math.min(n.length,Math.max(0,t[i]-o)),c=n.slice(s);c&&r.push(i===`reasoning`?N(c,u):M(c,u)),t[i]=Math.max(t[i],o+n.length),a.set(e,t)}else r.push(i===`reasoning`?N(n,u):M(n,u));i===`reasoning`?f+=n.length:d+=n.length}if(a&&l!==void 0&&i!==null&&i!==l.attemptId){let e=a.get(l.attemptId);e!==void 0&&a.set(i,{...e})}let p=e.usage;if(p){let e=(typeof p.totalTokens==`number`?p.totalTokens:void 0)??(typeof p.inputTokens==`number`?p.inputTokens:0)+(typeof p.outputTokens==`number`?p.outputTokens:0);r.push(ce(e,2e5,typeof p.cacheReadTokens==`number`?p.cacheReadTokens:0,typeof p.cacheWriteTokens==`number`?p.cacheWriteTokens:0))}return r}function de(e,t){let n=``,r=``;for(let e of t)e.type===`text`?n+=E(e.text)??``:e.type===`reasoning`&&(r+=E(e.text)??``);return P(e.text,n)&&P(e.reasoning,r)}function P(e,t){return t.startsWith(e)||e.startsWith(t)}function fe(e,t){let n=E(e.callId)??``,r=E(e.name)??`unknown`,i=E(e.arguments);t.journal?.record(n,r,i);let a=b(i);t.subagents!==void 0&&(r===`subagent`||r.startsWith(`subagent_`))&&t.subagents.trackDelegation(n,r);let o=r===`bash`&&t.supportsTerminalOutput===!0;return[{sessionUpdate:`tool_call`,toolCallId:n,name:r,title:_(r,a),kind:s(r),status:`pending`,locations:m(r,a,t.cwd),rawInput:a??{},...o?{content:[{type:`terminal`,terminalId:n}]}:{}}]}function pe(e,t){let n=e.message,r=E(n?.toolCallId)??``,i=t.journal?.lookup(r),a=i?.name??`unknown`,o=i?.input,c=n?.isError===!0||e.error!==void 0?`failed`:`completed`,l=e.meta,u=v(a,o,l),d=(n?.content??[]).filter(e=>e.type===`text`).map(e=>E(e.text)??``).join(``),f=[];if(c===`completed`)for(let e of A(a,o,l,t.cwd))f.push({type:`diff`,...e});let p=a===`bash`;p&&t.supportsTerminalOutput===!0?f.push({type:`terminal`,terminalId:r}):d.trimEnd()&&f.push({type:`content`,content:{type:`text`,text:d}});let m={};return l!=null&&(m.openacpagent={toolMeta:l}),t.subagents!==void 0&&(a===`subagent`||a.startsWith(`subagent_`))&&(m.openacpagent={...m.openacpagent,subagent:t.subagents.metaFor(r,a)}),p&&t.supportsTerminalOutput===!0?[{sessionUpdate:`tool_call_update`,toolCallId:r,_meta:{terminal_output:{terminal_id:r,data:d}}},{sessionUpdate:`tool_call_update`,toolCallId:r,name:a,status:c,title:u,kind:s(a),locations:h(a,o,l,t.cwd),rawInput:o??{},rawOutput:{content:n?.content??[],meta:l,error:e.error},...f.length>0?{content:f}:{},_meta:{...m,terminal_exit:{terminal_id:r,exit_code:c===`completed`?0:1,signal:null}}}]:[{sessionUpdate:`tool_call_update`,toolCallId:r,name:a,status:c,title:u,kind:s(a),locations:h(a,o,l,t.cwd),rawInput:o??{},rawOutput:{content:n?.content??[],meta:l,error:e.error},...f.length>0?{content:f}:{},...Object.keys(m).length>0?{_meta:m}:{}}]}function me(e,t,n,r){let i=t.type,a=D(t),o=n.parentCallIdOf(e)??e;if(i===`tool/call`){let t=E(a.callId)??``,i=E(a.name)??`unknown`,c=E(a.arguments);r.journal.record(t,i,c);let l=b(c),u=i===`bash`&&r.supportsTerminalOutput===!0;return[{sessionUpdate:`tool_call`,toolCallId:`${o}:${t}`,name:i,title:y(_(i,l),n.labelOfChild(e),e),kind:s(i),status:`pending`,locations:m(i,l,r.cwd),rawInput:l??{},...u?{content:[{type:`terminal`,terminalId:`${o}:${t}`}]}:{}}]}if(i===`tool/result`){let t=a.message,i=E(t?.toolCallId)??``,c=r.journal.lookup(i),l=c?.name??`unknown`,u=c?.input,d=t?.isError===!0||a.error!==void 0?`failed`:`completed`,f=a.meta,p=(t?.content??[]).filter(e=>e.type===`text`).map(e=>E(e.text)??``).join(``),m=[];if(d===`completed`)for(let e of A(l,u,f,r.cwd))m.push({type:`diff`,...e});return[{sessionUpdate:`tool_call_update`,toolCallId:`${o}:${i}`,name:l,status:d,title:y(v(l,u,f),n.labelOfChild(e),e),kind:s(l),locations:h(l,u,f,r.cwd),rawInput:u??{},rawOutput:{content:t?.content??[],...f==null?{}:{meta:f},error:a.error},...p.trimEnd()?{content:[...m,{type:`content`,content:{type:`text`,text:p}}]}:m.length>0?{content:m}:{},_meta:{openacpagent:{...f==null?{}:{toolMeta:f},subagent:n.metaFor(o,l)}}}]}return[]}function he(e){return[{sessionUpdate:`plan`,entries:(e.todos??[]).map(e=>({content:E(e.content)??``,status:e.status===`in_progress`?`in_progress`:e.status===`completed`?`completed`:`pending`}))}]}function ge(e,t){let n=t.source;return[{sessionUpdate:`session_info_update`,title:E(t.title)??null,updatedAt:new Date(e.time).toISOString(),_meta:n?.kind===void 0?{}:{openacpagent:{titleSource:n.kind}}}]}function _e(e){let t=E(e.name)??``,n=E(e.args);return[j(`/${t}${n?` ${n}`:``}`,E(e.commandId))]}function F(e){let t=e.kind===`success`?`success`:`error`,n=M(E(e.text)??(t===`success`?`Command completed`:`Command failed`),E(e.commandId));return typeof e.sourceEventSeq==`number`&&(n._meta={openacpagent:{sourceEventSeq:e.sourceEventSeq}}),[n]}function I(e,t,n){let a=r(e.type);if(a===`skip`)return[];if(a===`unknown`)return n?.(e.type,i(e)?`debug`:`warn`),[];let o=D(e);switch(e.type){case`user/message`:return le(o,t);case`assistant/message`:return ue(o,t);case`tool/call`:return fe(o,t);case`tool/result`:return pe(o,t);case`todo/write`:return he(o);case`session/title`:return ge(e,o);case`command/run`:return _e(o);case`command/done`:return F(o);case`subagent/catalog`:{let n=E(o.childId);if(n!==void 0){let r=o;t.subagents?.accept({childId:n,childCreatedAt:typeof r.childCreatedAt==`number`?r.childCreatedAt:e.time,mode:E(r.mode)??`unknown`,label:E(r.label)}),t.onSubagentCatalog?.({childId:n,childCreatedAt:typeof r.childCreatedAt==`number`?r.childCreatedAt:e.time,mode:E(r.mode)??`unknown`,label:E(r.label)})}return[]}case`turn/start`:case`turn/end`:return[];default:return[]}}function ve(e,t,n){return I(e,{...t,live:!1},n)}function ye(e,t){if(!t.live)return[];if(e.type===`start`)return typeof e.turn==`number`&&typeof e.step==`number`&&t.attempts?.begin(e.attemptId,e.turn,e.step),[];if(e.type!==`chunk`)return[];let n=e.chunk?.type,r=E(e.chunk?.text)??``;return n===`text-delta`?(t.attempts?.record(e.attemptId,`text`,r),[M(r,e.attemptId)]):n===`reasoning-delta`?(t.attempts?.record(e.attemptId,`reasoning`,r),[N(r,e.attemptId)]):[]}var be=class{#e=[];constructor(e){this.onDerived=e}accept(e){let t=e.data??{};if(e.type===`turn/start`&&typeof t.turn==`number`)this.#e.push({turn:t.turn,tools:new Map});else if(e.type===`tool/call`&&typeof t.callId==`string`)this.#e[this.#e.length-1]?.tools.set(t.callId,{resolved:!1});else if(e.type===`tool/result`){let e=t.message,n=E(e?.toolCallId),r=this.#e[this.#e.length-1];if(n!==void 0&&r!==void 0){let e=r.tools.get(n);e&&(e.resolved=!0)}}else if(e.type===`turn/end`){let e=this.#e[this.#e.length-1];if(e){for(let[t,n]of e.tools)n.resolved||this.onDerived({sessionUpdate:`tool_call_update`,toolCallId:t,status:`failed`,_meta:{derived:!0}});this.#e.pop()}}}},xe=class{#e=new Map;begin(e,t,n){if(!(e===``||!Number.isInteger(t)||!Number.isInteger(n))){for(let[e,r]of this.#e)r.turn===t&&r.step===n&&this.#e.delete(e);for(;this.#e.size>=8;){let e=this.#e.keys().next().value;if(e===void 0)break;this.#e.delete(e)}this.#e.set(e,{attemptId:e,turn:t,step:n,text:``,reasoning:``})}}record(e,t,n){let r=this.#e.get(e);r!==void 0&&(r[t]+=n)}resolve(e,t,n){let r=this.#t(e,t);if(r!==void 0)return this.#e.delete(r.attemptId),n(r)?r:void 0}clear(){this.#e.clear()}#t(e,t){for(let n of this.#e.values())if(n.turn===e&&n.step===t)return n}};let Se=0;const L=(e,t,n={})=>({type:e,seq:++Se,time:17e11,data:t,...n}),R={id:`msg-u1`,role:`user`,content:[{type:`text`,text:`hello`}],source:{kind:`user`}},Ce={id:`msg-cat1`,role:`user`,content:[{type:`text`,text:`<skill catalog>`}],source:{kind:`skill-catalog`,form:`catalog`,entries:[]}},we={id:`msg-rc1`,role:`user`,content:[{type:`text`,text:`<runtime context>`}],source:{kind:`runtime-context`}},Te={id:`msg-a1`,role:`assistant`,content:[{type:`text`,text:`world`}],source:{kind:`model`,provider:`echo`,model:`echo`}},Ee={id:`msg-a2`,role:`assistant`,content:[{type:`reasoning`,text:`thinking…`},{type:`text`,text:`answer`}],source:{kind:`model`,provider:`echo`,model:`echo`}},De=[{name:`echo-whitelist`,events:[L(`user/message`,Ce),L(`user/message`,we),L(`user/message`,R)],expectedLive:[z(`hello`,`msg-u1`)]},{name:`user-last-subagent-task`,events:[L(`user/message`,{...R,id:`msg-task`,content:[{type:`text`,text:`delegate task`}]})],expectedLive:[z(`delegate task`,`msg-task`)]},{name:`assistant-durable-mixed`,events:[L(`assistant/message`,{turn:1,step:1,message:Ee,stream:[],usage:{inputTokens:10,outputTokens:5,totalTokens:15,cacheReadTokens:3,cacheWriteTokens:2}})],expectedLive:[V(`thinking…`,`msg-a2`),B(`answer`,`msg-a2`),H(15,3,2)]},{name:`assistant-durable-no-usage`,events:[L(`assistant/message`,{turn:1,step:2,message:Te,stream:[]})],expectedLive:[B(`world`,`msg-a1`)]},{name:`tool-lifecycle-bash`,events:[L(`turn/start`,{turn:1}),L(`tool/call`,{turn:1,step:1,callId:`c1`,name:`bash`,arguments:`{"command":"ls -la"}`}),L(`tool/result`,{turn:1,step:1,message:{toolCallId:`c1`,role:`tool`,content:[{type:`text`,text:`file.txt`}]}}),L(`turn/end`,{turn:1,reason:{kind:`completed`}})],expectedLive:[U(`c1`,`Execute ls -la`,`execute`,{command:`ls -la`},[],`bash`),W(`c1`,`completed`,`Execute ls -la`,`execute`,[],{command:`ls -la`},{name:`bash`,content:[{type:`text`,text:`file.txt`}],contentFrames:[{type:`content`,content:{type:`text`,text:`file.txt`}}]})],expectedDerived:[]},{name:`tool-derived-failed`,events:[L(`turn/start`,{turn:1}),L(`tool/call`,{turn:1,step:1,callId:`c2`,name:`read`,arguments:`{"file_path":"a.ts"}`}),L(`turn/end`,{turn:1,reason:{kind:`error`}})],expectedLive:[U(`c2`,`Read a.ts`,`read`,{file_path:`a.ts`},[],`read`)],expectedDerived:[{sessionUpdate:`tool_call_update`,toolCallId:`c2`,status:`failed`,_meta:{derived:!0}}]},{name:`edit-diff-locations`,cwd:`/w`,events:[L(`tool/call`,{turn:1,step:1,callId:`c3`,name:`edit`,arguments:`{"file_path":"src/a.ts","old_string":"a","new_string":"b"}`}),L(`tool/result`,{turn:1,step:1,message:{toolCallId:`c3`,role:`tool`,content:[{type:`text`,text:`ok`}]}})],expectedLive:[U(`c3`,`Edit src/a.ts`,`edit`,{file_path:`src/a.ts`,old_string:`a`,new_string:`b`},[{path:`/w/src/a.ts`,line:null}],`edit`),W(`c3`,`completed`,`Edit src/a.ts`,`edit`,[{path:`/w/src/a.ts`,line:null}],{file_path:`src/a.ts`,old_string:`a`,new_string:`b`},{name:`edit`,content:[{type:`text`,text:`ok`}],contentFrames:[{type:`diff`,path:`/w/src/a.ts`,oldText:`a`,newText:`b`},{type:`content`,content:{type:`text`,text:`ok`}}]})]},{name:`write-create-diff`,cwd:`/w`,events:[L(`tool/call`,{turn:1,step:1,callId:`w1`,name:`write`,arguments:`{"file_path":"src/new.ts","content":"line1\\nline2\\n"}`}),L(`tool/result`,{turn:1,step:1,message:{toolCallId:`w1`,role:`tool`,content:[{type:`text`,text:`<path>/w/src/new.ts</path>
|
|
1
|
+
import{isAbsolute as e,resolve as t}from"node:path";const n={"user/message":`project`,"assistant/message":`project`,"tool/call":`project`,"tool/result":`project`,"todo/write":`project`,"session/title":`project`,"command/run":`project`,"command/done":`project`,"subagent/catalog":`project`,"turn/start":`project`,"turn/end":`project`,"step/start":`skip`,"step/end":`skip`,"developer/message":`skip`,"system/message":`skip`,"assistant/attempt":`skip`,"request/header":`skip`,"request/context":`skip`,"session/end-seed":`skip`,"agent/inbox/spliced":`skip`,"tool/ptc-dispatch-start":`skip`,"tool/ptc-dispatch":`skip`,"subagent/descriptor":`skip`,"approval/asked":`skip`,"approval/decided":`skip`,"approval/policy":`skip`,"permission/preset":`skip`,"sandbox/mode":`skip`,"model/selection":`skip`,"goal/change":`skip`};function r(e){return n[e]??`unknown`}function i(e){return e.ignorable===!0}const a={read:`read`,read_image:`read`,write:`edit`,edit:`edit`,str_replace_editor:`edit`,bash:`execute`,pwsh:`execute`,glob:`search`,grep:`search`,web_search:`search`,web_fetch:`fetch`,webfetch:`fetch`,todo_write:`think`,plan:`think`,skill:`other`},o=new Set([`edit`,`write`,`scratch_write`,`scratch_edit`,`str_replace_editor`]);function s(e){return a[e]||(e.startsWith(`scratch_`)?a[e.slice(8)]??`other`:(e.startsWith(`subagent_`),`other`))}const c=e=>typeof e==`string`?e:void 0,l=e=>c(e.file_path)??c(e.filePath)??c(e.path),u=e=>c(e.old_string)??c(e.oldString)??c(e.old_str),d=e=>c(e.new_string)??c(e.newString)??c(e.new_str);function f(n,r){if(n!==void 0){if(e(n)||r===void 0)return n;try{return t(r,n)}catch{return n}}}const p=new Set([`scratch_write`,`scratch_edit`]);function m(t,n,r){if(!o.has(t))return[];let i=n??{},a=l(i);if(!a||p.has(t)&&!e(a))return[];let s=typeof i.line==`number`?i.line:typeof i.lineNumber==`number`?i.lineNumber:typeof i.offset==`number`?i.offset:null;return[{path:f(a,r)??a,line:s}]}function h(e,t,n,r){if(!o.has(e))return[];let i=c(n?.path);if(i!==void 0){let e=t??{};return[{path:i,line:typeof e.line==`number`?e.line:typeof e.lineNumber==`number`?e.lineNumber:typeof e.offset==`number`?e.offset:null}]}return m(e,t,r)}const ee=e=>{let t=typeof e.offset==`number`?e.offset:void 0,n=typeof e.limit==`number`?e.limit:void 0;return n!==void 0&&n>0?` (${t??1} - ${(t??1)+n-1})`:t===void 0?``:` (from line ${t})`},te={create:`Create`,str_replace:`Replace`,insert:`Insert`,view:`View`},g={bash:e=>{let t=c(e.command),n=c(e.description);return n?`${n} (${t?.slice(0,60)??``})`:t?`Execute ${t.slice(0,120)}${t.length>120?`…`:``}`:`Execute`},pwsh:e=>{let t=c(e.command);return t?`Execute ${t.slice(0,120)}${t.length>120?`…`:``}`:`Execute`},read:e=>`Read ${l(e)??`file`}${ee(e)}`,read_image:e=>`Read image ${l(e)??`file`}`,write:e=>`Write ${l(e)??`file`}`,edit:e=>`Edit ${l(e)??`file`}`,scratch_bash:e=>{let t=c(e.description);if(t)return`Scratch: ${t}`;let n=c(e.command);return n?`Execute ${n.slice(0,120)}${n.length>120?`…`:``}`:`Execute`},scratch_write:e=>`Write scratch file ${l(e)??`file`}`,scratch_edit:e=>`Edit scratch file ${l(e)??`file`}`,subagent:e=>{let t=c(e.description)??c(e.prompt);return t?`Delegate: ${t}`:`Delegate`},str_replace_editor:e=>{let t=te[c(e.command)??``]??`str_replace_editor`,n=l(e);return n?`${t} ${n}`:t},grep:e=>{let t=c(e.pattern),n=c(e.path);return`Grep${t?` "${t}"`:``}${n?` in ${n}`:``}`},glob:e=>`Glob ${c(e.pattern)??``}`,web_fetch:e=>`Fetch ${c(e.url)??`URL`}`,web_search:e=>{let t=c(e.query);return`Search${t?` "${t}"`:``}`},webfetch:e=>{let t=c(e.url),n=c(e.format);return`Fetch ${t??`URL`}${n&&n!==`markdown`?` (${n})`:``}`},todo_write:e=>{let t=e.todos,n=Array.isArray(t)?t:[],r=n.filter(e=>e.status===`completed`).length;return`Update TODOs${n.length?` (${r}/${n.length})`:``}`},ask_user_question:()=>`Ask the user`,skill:e=>`Load skill: ${c(e.name)??``}`};function _(e,t){return(g[e]??(()=>e))(t??{})}function v(e,t,n){let r=_(e,t),i=n??{};if(e===`write`||e===`scratch_write`)return i.operation===`create`?`${r} (created)`:i.operation===`update`?`${r} (updated)`:r;if(e===`edit`||e===`scratch_edit`){let e=i.diffs;return Array.isArray(e)&&e.length>0?`${r} (${e.length} changes)`:r}return r}function y(e,t,n){return`[${t??`subagent:${n.slice(-8)}`}] ${e}`}function b(e){if(e!==void 0)try{let t=JSON.parse(e);return typeof t==`object`&&t?t:void 0}catch{return}}const x={methodNotFound:-32601,invalidParams:-32602,conflict:-32600,internal:-32603,sessionNotFound:-32002},S=e=>typeof e==`string`?e:void 0;function ne(e){let t=e.message,n=e.data&&typeof e.data==`object`?e.data:{};switch(e.code){case`session-not-found`:{let e=S(n.sessionId);return{code:x.sessionNotFound,message:t??`session not found`,data:e===void 0?void 0:{uri:`session:${e}`}}}case`session/writer-held`:return{code:x.conflict,message:t??`session is owned by another writer`,data:{reason:S(n.reason)??`writer-held`,retryable:!0}};case`turn-error`:return{code:x.internal,message:t??`turn failed`,data:{sessionId:S(n.sessionId),kind:S(n.kind)??`turn-error`,retryable:n.retryable===!0,code:S(n.code),partialOutput:n.partialOutput===!0}};case`llm-auth`:return{code:x.internal,message:t??`llm credential missing`,data:{kind:`auth`,retryable:!1}};case`retry-after-turn`:return{code:x.internal,message:t??`reload in progress`,data:{retryable:!0,reason:`skill_reload_in_progress`}};case`method-not-found`:return{code:x.methodNotFound,message:t??`method not found`};case`invalid-params`:return{code:x.invalidParams,message:t??`invalid params`,data:n.errors===void 0?void 0:{errors:n.errors}};default:return{code:x.internal,message:t??`dsh error`,data:{kind:`unknown-dsh-error`,...e.code===void 0?{}:{code:e.code},...Object.keys(n).length>0?{detail:n}:{}}}}}function C(e){let t=e?.kind;switch(t){case`completed`:case`aborted`:case`blocked`:return{stopReason:`end_turn`};case`interrupted`:return{stopReason:`cancelled`};case`max-tokens`:return{stopReason:`max_tokens`};case`error`:return{error:!0};case`forked`:default:return{stopReason:`end_turn`,warn:`unknown turn end reason: ${String(t)}`}}}const w=[1],T=w[w.length-1]??1;function re(e){return e===void 0?{version:T}:w.includes(e)?{version:e}:{version:T,warn:`client protocol version ${e} not in supported set`}}function ie(e){return{capabilities:{loadSession:!0,promptCapabilities:{image:!0,embeddedContext:!0}},meta:{openacpagent:{usage:{},image:{}},tboxcode:{protocolVersion:e}}}}var ae=class{#e=new Map;record(e,t,n){this.#e.set(e,{name:t,input:b(n)})}lookup(e){return this.#e.get(e)}},oe=class{byChild=new Map;#e=new Map;#t=new Map;#n=new Map;accept(e){this.byChild.set(e.childId,{mode:e.mode,...e.label===void 0?{}:{label:e.label}});let t=this.#e.size>1;for(let[n,r]of this.#e)this.#t.set(n,{childId:e.childId,toolName:r,...e.label===void 0?{}:{label:e.label},ambiguous:t});this.#e.size===1&&this.#n.set(e.childId,[...this.#e.keys()][0]),this.#e.clear()}trackDelegation(e,t){this.#e.set(e,t)}tracks(e){return this.byChild.has(e)}parentCallIdOf(e){return this.#n.get(e)}labelOfChild(e){return this.byChild.get(e)?.label}metaFor(e,t){let n=this.#t.get(e),r=n?.toolName??t,i=r===`subagent`?`general`:r.startsWith(`subagent_`)?r.slice(9):r;return n===void 0||n.ambiguous?{runId:e,agentType:i}:{runId:n.childId,agentType:i,...n.label===void 0?{}:{name:n.label}}}};const E=e=>typeof e==`string`?e:void 0,D=e=>e.data??{},O=new Set([`write`,`scratch_write`]),k=new Set([`edit`,`scratch_edit`]),se=e=>typeof e==`object`&&!!e&&typeof e.path==`string`&&(e.oldText===null||typeof e.oldText==`string`)&&typeof e.newText==`string`;function A(e,t,n,r){let i=n??{},a=i.diffs;if(Array.isArray(a)&&a.length>0)return a.every(se)?a:[];let o=E(i.path),s=t??{};if(o!==void 0)return O.has(e)?[{path:o,oldText:i.operation===`create`?null:E(i.before)??null,newText:E(i.after)??E(s.content)??``}]:k.has(e)?[{path:o,oldText:E(i.before)??u(s)??null,newText:E(i.after)??d(s)??``}]:[];let c=f(l(s),r);return c===void 0?[]:O.has(e)?[{path:c,oldText:null,newText:E(s.content)??``}]:k.has(e)?[{path:c,oldText:u(s)??null,newText:d(s)??``}]:e===`str_replace_editor`?s.command===`create`?[{path:c,oldText:null,newText:E(s.file_text)??``}]:s.command===`str_replace`?[{path:c,oldText:E(s.old_str)??null,newText:E(s.new_str)??``}]:[]:[]}function j(e,t){return{sessionUpdate:`user_message_chunk`,content:{type:`text`,text:e},...t?{messageId:t}:{}}}function M(e,t){return{sessionUpdate:`agent_message_chunk`,content:{type:`text`,text:e},...t?{messageId:t}:{}}}function N(e,t){return{sessionUpdate:`agent_thought_chunk`,content:{type:`text`,text:e},...t?{messageId:t}:{}}}function ce(e,t,n,r){return{sessionUpdate:`usage_update`,used:e,size:t,_meta:{openacpagent:{usage:{cacheReadTokens:n,cacheWriteTokens:r}}}}}function le(e,t){if(e.source?.kind!==`user`)return[];let n=e,r=typeof n.id==`string`?n.id:null,i=n.content??[];if(i.length===0)return[j(``,r)];let a=[];for(let e of i)e.type===`text`?a.push(j(E(e.text)??``,r)):a.push(j(`[${String(e.type)}]`,r));return a}function ue(e,t){let n=e.message,r=[],i=typeof n?.id==`string`?n.id:null,a=t.seen,o=n?.content??[],s=typeof e.turn==`number`?e.turn:void 0,c=typeof e.step==`number`?e.step:void 0,l=t.live&&a!==void 0&&t.attempts!==void 0&&s!==void 0&&c!==void 0?t.attempts.resolve(s,c,e=>de(e,o)):void 0,u=l?.attemptId??i;if(a&&l!==void 0){let e=a.get(l.attemptId);a.set(l.attemptId,{text:Math.max(e?.text??0,l.text.length),reasoning:Math.max(e?.reasoning??0,l.reasoning.length)})}let d=0,f=0;for(let e of o){let t=e.type;if(t!==`text`&&t!==`reasoning`)continue;let n=E(e.text)??``,i=t===`reasoning`?`reasoning`:`text`,o=i===`reasoning`?f:d;if(a){let e=u??``,t=a.get(e)??{text:0,reasoning:0},s=Math.min(n.length,Math.max(0,t[i]-o)),c=n.slice(s);c&&r.push(i===`reasoning`?N(c,u):M(c,u)),t[i]=Math.max(t[i],o+n.length),a.set(e,t)}else r.push(i===`reasoning`?N(n,u):M(n,u));i===`reasoning`?f+=n.length:d+=n.length}if(a&&l!==void 0&&i!==null&&i!==l.attemptId){let e=a.get(l.attemptId);e!==void 0&&a.set(i,{...e})}let p=e.usage;if(p){let e=(typeof p.totalTokens==`number`?p.totalTokens:void 0)??(typeof p.inputTokens==`number`?p.inputTokens:0)+(typeof p.outputTokens==`number`?p.outputTokens:0);r.push(ce(e,2e5,typeof p.cacheReadTokens==`number`?p.cacheReadTokens:0,typeof p.cacheWriteTokens==`number`?p.cacheWriteTokens:0))}return r}function de(e,t){let n=``,r=``;for(let e of t)e.type===`text`?n+=E(e.text)??``:e.type===`reasoning`&&(r+=E(e.text)??``);return P(e.text,n)&&P(e.reasoning,r)}function P(e,t){return t.startsWith(e)||e.startsWith(t)}function fe(e,t){let n=E(e.callId)??``,r=E(e.name)??`unknown`,i=E(e.arguments);t.journal?.record(n,r,i);let a=b(i);t.subagents!==void 0&&(r===`subagent`||r.startsWith(`subagent_`))&&t.subagents.trackDelegation(n,r);let o=r===`bash`&&t.supportsTerminalOutput===!0;return[{sessionUpdate:`tool_call`,toolCallId:n,name:r,title:_(r,a),kind:s(r),status:`pending`,locations:m(r,a,t.cwd),rawInput:a??{},...o?{content:[{type:`terminal`,terminalId:n}]}:{}}]}function pe(e,t){let n=e.message,r=E(n?.toolCallId)??``,i=t.journal?.lookup(r),a=i?.name??`unknown`,o=i?.input,c=n?.isError===!0||e.error!==void 0?`failed`:`completed`,l=e.meta,u=v(a,o,l),d=(n?.content??[]).filter(e=>e.type===`text`).map(e=>E(e.text)??``).join(``),f=[];if(c===`completed`)for(let e of A(a,o,l,t.cwd))f.push({type:`diff`,...e});let p=a===`bash`;p&&t.supportsTerminalOutput===!0?f.push({type:`terminal`,terminalId:r}):d.trimEnd()&&f.push({type:`content`,content:{type:`text`,text:d}});let m={};return l!=null&&(m.openacpagent={toolMeta:l}),t.subagents!==void 0&&(a===`subagent`||a.startsWith(`subagent_`))&&(m.openacpagent={...m.openacpagent,subagent:t.subagents.metaFor(r,a)}),p&&t.supportsTerminalOutput===!0?[{sessionUpdate:`tool_call_update`,toolCallId:r,_meta:{terminal_output:{terminal_id:r,data:d}}},{sessionUpdate:`tool_call_update`,toolCallId:r,name:a,status:c,title:u,kind:s(a),locations:h(a,o,l,t.cwd),rawInput:o??{},rawOutput:{content:n?.content??[],meta:l,error:e.error},...f.length>0?{content:f}:{},_meta:{...m,terminal_exit:{terminal_id:r,exit_code:c===`completed`?0:1,signal:null}}}]:[{sessionUpdate:`tool_call_update`,toolCallId:r,name:a,status:c,title:u,kind:s(a),locations:h(a,o,l,t.cwd),rawInput:o??{},rawOutput:{content:n?.content??[],meta:l,error:e.error},...f.length>0?{content:f}:{},...Object.keys(m).length>0?{_meta:m}:{}}]}function me(e,t,n,r){let i=t.type,a=D(t),o=n.parentCallIdOf(e)??e;if(i===`tool/call`){let t=E(a.callId)??``,i=E(a.name)??`unknown`,c=E(a.arguments);r.journal.record(t,i,c);let l=b(c),u=i===`bash`&&r.supportsTerminalOutput===!0;return[{sessionUpdate:`tool_call`,toolCallId:`${o}:${t}`,name:i,title:y(_(i,l),n.labelOfChild(e),e),kind:s(i),status:`pending`,locations:m(i,l,r.cwd),rawInput:l??{},...u?{content:[{type:`terminal`,terminalId:`${o}:${t}`}]}:{}}]}if(i===`tool/result`){let t=a.message,i=E(t?.toolCallId)??``,c=r.journal.lookup(i),l=c?.name??`unknown`,u=c?.input,d=t?.isError===!0||a.error!==void 0?`failed`:`completed`,f=a.meta,p=(t?.content??[]).filter(e=>e.type===`text`).map(e=>E(e.text)??``).join(``),m=[];if(d===`completed`)for(let e of A(l,u,f,r.cwd))m.push({type:`diff`,...e});return[{sessionUpdate:`tool_call_update`,toolCallId:`${o}:${i}`,name:l,status:d,title:y(v(l,u,f),n.labelOfChild(e),e),kind:s(l),locations:h(l,u,f,r.cwd),rawInput:u??{},rawOutput:{content:t?.content??[],...f==null?{}:{meta:f},error:a.error},...p.trimEnd()?{content:[...m,{type:`content`,content:{type:`text`,text:p}}]}:m.length>0?{content:m}:{},_meta:{openacpagent:{...f==null?{}:{toolMeta:f},subagent:n.metaFor(o,l)}}}]}return[]}function he(e){return[{sessionUpdate:`plan`,entries:(e.todos??[]).map(e=>({content:E(e.content)??``,status:e.status===`in_progress`?`in_progress`:e.status===`completed`?`completed`:`pending`}))}]}function ge(e,t){let n=t.source;return[{sessionUpdate:`session_info_update`,title:E(t.title)??null,updatedAt:new Date(e.time).toISOString(),_meta:n?.kind===void 0?{}:{openacpagent:{titleSource:n.kind}}}]}function _e(e){let t=E(e.name)??``,n=E(e.args);return[j(`/${t}${n?` ${n}`:``}`,E(e.commandId))]}function F(e){let t=e.kind===`success`?`success`:`error`,n=M(E(e.text)??(t===`success`?`Command completed`:`Command failed`),E(e.commandId));return typeof e.sourceEventSeq==`number`&&(n._meta={openacpagent:{sourceEventSeq:e.sourceEventSeq}}),[n]}function I(e,t,n){let a=r(e.type);if(a===`skip`)return[];if(a===`unknown`)return n?.(e.type,i(e)?`debug`:`warn`),[];let o=D(e);switch(e.type){case`user/message`:return le(o,t);case`assistant/message`:return ue(o,t);case`tool/call`:return fe(o,t);case`tool/result`:return pe(o,t);case`todo/write`:return he(o);case`session/title`:return ge(e,o);case`command/run`:return _e(o);case`command/done`:return F(o);case`subagent/catalog`:{let n=E(o.childId);if(n!==void 0){let r=o;t.subagents?.accept({childId:n,childCreatedAt:typeof r.childCreatedAt==`number`?r.childCreatedAt:e.time,mode:E(r.mode)??`unknown`,label:E(r.label)}),t.onSubagentCatalog?.({childId:n,childCreatedAt:typeof r.childCreatedAt==`number`?r.childCreatedAt:e.time,mode:E(r.mode)??`unknown`,label:E(r.label)})}return[]}case`turn/start`:case`turn/end`:return[];default:return[]}}function ve(e,t,n){return I(e,{...t,live:!1},n)}function ye(e,t){if(!t.live)return[];if(e.type===`start`)return typeof e.turn==`number`&&typeof e.step==`number`&&t.attempts?.begin(e.attemptId,e.turn,e.step),[];if(e.type!==`chunk`)return[];let n=e.chunk?.type,r=E(e.chunk?.text)??``;return n===`text-delta`?(t.attempts?.record(e.attemptId,`text`,r),[M(r,e.attemptId)]):n===`reasoning-delta`?(t.attempts?.record(e.attemptId,`reasoning`,r),[N(r,e.attemptId)]):[]}var be=class{#e=[];constructor(e){this.onDerived=e}accept(e){let t=e.data??{};if(e.type===`turn/start`&&typeof t.turn==`number`)this.#e.push({turn:t.turn,tools:new Map});else if(e.type===`tool/call`&&typeof t.callId==`string`)this.#e[this.#e.length-1]?.tools.set(t.callId,{resolved:!1});else if(e.type===`tool/result`){let e=t.message,n=E(e?.toolCallId),r=this.#e[this.#e.length-1];if(n!==void 0&&r!==void 0){let e=r.tools.get(n);e&&(e.resolved=!0)}}else if(e.type===`turn/end`){let e=this.#e[this.#e.length-1];if(e){for(let[t,n]of e.tools)n.resolved||this.onDerived({sessionUpdate:`tool_call_update`,toolCallId:t,status:`failed`,_meta:{derived:!0}});this.#e.pop()}}}},xe=class{#e=new Map;begin(e,t,n){if(!(e===``||!Number.isInteger(t)||!Number.isInteger(n))){for(let[e,r]of this.#e)r.turn===t&&r.step===n&&this.#e.delete(e);for(;this.#e.size>=8;){let e=this.#e.keys().next().value;if(e===void 0)break;this.#e.delete(e)}this.#e.set(e,{attemptId:e,turn:t,step:n,text:``,reasoning:``})}}record(e,t,n){let r=this.#e.get(e);r!==void 0&&(r[t]+=n)}resolve(e,t,n){let r=this.#t(e,t);if(r!==void 0)return this.#e.delete(r.attemptId),n(r)?r:void 0}clear(){this.#e.clear()}#t(e,t){for(let n of this.#e.values())if(n.turn===e&&n.step===t)return n}};let Se=0;const L=(e,t,n={})=>({type:e,seq:++Se,time:17e11,data:t,...n}),R={id:`msg-u1`,role:`user`,content:[{type:`text`,text:`hello`}],source:{kind:`user`}},Ce={id:`msg-cat1`,role:`user`,content:[{type:`text`,text:`<skill catalog>`}],source:{kind:`skill-catalog`,form:`catalog`,entries:[]}},we={id:`msg-rc1`,role:`user`,content:[{type:`text`,text:`<runtime context>`}],source:{kind:`runtime-context`}},Te={id:`msg-a1`,role:`assistant`,content:[{type:`text`,text:`world`}],source:{kind:`model`,provider:`echo`,model:`echo`}},Ee={id:`msg-a2`,role:`assistant`,content:[{type:`reasoning`,text:`thinking…`},{type:`text`,text:`answer`}],source:{kind:`model`,provider:`echo`,model:`echo`}},De=[{name:`echo-whitelist`,events:[L(`user/message`,Ce),L(`user/message`,we),L(`user/message`,R)],expectedLive:[z(`hello`,`msg-u1`)]},{name:`user-last-subagent-task`,events:[L(`user/message`,{...R,id:`msg-task`,content:[{type:`text`,text:`delegate task`}]})],expectedLive:[z(`delegate task`,`msg-task`)]},{name:`assistant-durable-mixed`,events:[L(`assistant/message`,{turn:1,step:1,message:Ee,stream:[],usage:{inputTokens:10,outputTokens:5,totalTokens:15,cacheReadTokens:3,cacheWriteTokens:2}})],expectedLive:[V(`thinking…`,`msg-a2`),B(`answer`,`msg-a2`),H(15,3,2)]},{name:`assistant-durable-no-usage`,events:[L(`assistant/message`,{turn:1,step:2,message:Te,stream:[]})],expectedLive:[B(`world`,`msg-a1`)]},{name:`tool-lifecycle-bash`,events:[L(`turn/start`,{turn:1}),L(`tool/call`,{turn:1,step:1,callId:`c1`,name:`bash`,arguments:`{"command":"ls -la"}`}),L(`tool/result`,{turn:1,step:1,message:{toolCallId:`c1`,role:`tool`,content:[{type:`text`,text:`file.txt`}]}}),L(`turn/end`,{turn:1,reason:{kind:`completed`}})],expectedLive:[U(`c1`,`Execute ls -la`,`execute`,{command:`ls -la`},[],`bash`),W(`c1`,`completed`,`Execute ls -la`,`execute`,[],{command:`ls -la`},{name:`bash`,content:[{type:`text`,text:`file.txt`}],contentFrames:[{type:`content`,content:{type:`text`,text:`file.txt`}}]})],expectedDerived:[]},{name:`tool-derived-failed`,events:[L(`turn/start`,{turn:1}),L(`tool/call`,{turn:1,step:1,callId:`c2`,name:`read`,arguments:`{"file_path":"a.ts"}`}),L(`turn/end`,{turn:1,reason:{kind:`error`}})],expectedLive:[U(`c2`,`Read a.ts`,`read`,{file_path:`a.ts`},[],`read`)],expectedDerived:[{sessionUpdate:`tool_call_update`,toolCallId:`c2`,status:`failed`,_meta:{derived:!0}}]},{name:`edit-diff-locations`,cwd:`/w`,events:[L(`tool/call`,{turn:1,step:1,callId:`c3`,name:`edit`,arguments:`{"file_path":"src/a.ts","old_string":"a","new_string":"b"}`}),L(`tool/result`,{turn:1,step:1,message:{toolCallId:`c3`,role:`tool`,content:[{type:`text`,text:`ok`}]}})],expectedLive:[U(`c3`,`Edit src/a.ts`,`edit`,{file_path:`src/a.ts`,old_string:`a`,new_string:`b`},[{path:`/w/src/a.ts`,line:null}],`edit`),W(`c3`,`completed`,`Edit src/a.ts`,`edit`,[{path:`/w/src/a.ts`,line:null}],{file_path:`src/a.ts`,old_string:`a`,new_string:`b`},{name:`edit`,content:[{type:`text`,text:`ok`}],contentFrames:[{type:`diff`,path:`/w/src/a.ts`,oldText:`a`,newText:`b`},{type:`content`,content:{type:`text`,text:`ok`}}]})]},{name:`write-create-diff`,cwd:`/w`,events:[L(`tool/call`,{turn:1,step:1,callId:`w1`,name:`write`,arguments:`{"file_path":"src/new.ts","content":"line1\\nline2\\n"}`}),L(`tool/result`,{turn:1,step:1,message:{toolCallId:`w1`,role:`tool`,content:[{type:`text`,text:`<path>/w/src/new.ts</path>
|
|
2
2
|
Created file`}]},meta:{operation:`create`,path:`/w/src/new.ts`,diffs:[]}})],expectedLive:[U(`w1`,`Write src/new.ts`,`edit`,{file_path:`src/new.ts`,content:`line1
|
|
3
3
|
line2
|
|
4
4
|
`},[{path:`/w/src/new.ts`,line:null}],`write`),W(`w1`,`completed`,`Write src/new.ts (created)`,`edit`,[{path:`/w/src/new.ts`,line:null}],{file_path:`src/new.ts`,content:`line1
|