@tbox.cn/dsh-acp-bridge-core 0.1.0-rc.13 → 0.1.0-rc.14

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.d.ts CHANGED
@@ -8,9 +8,11 @@ type Classification = 'project' | 'skip';
8
8
  /**
9
9
  * 事件分类表。
10
10
  *
11
- * project(11):user/message · assistant/message · tool/call · tool/result ·
11
+ * project(13):user/message · assistant/message · tool/call · tool/result ·
12
12
  * todo/write · session/title · command/run · command/done · subagent/catalog ·
13
- * turn/start · turn/end(来源:[acp-projection-contract] 投影基准表)。
13
+ * turn/start · turn/end · tool/ptc-dispatch-start · tool/ptc-dispatch
14
+ * (来源:[acp-projection-contract] 投影基准表;PTC 两事件为 log-only 子调用
15
+ * 生命周期,投影为独立标准工具帧,父关联经 `_meta.tboxcode.ptc`)。
14
16
  *
15
17
  * skip 防自产回声显式项:sandbox/mode / permission/preset(桥动作引发)·
16
18
  * model/selection(set_config_option 经 api selectModel 自产)。
@@ -30,6 +32,8 @@ declare const CLASSIFICATION: {
30
32
  'subagent/catalog': "project";
31
33
  'turn/start': "project";
32
34
  'turn/end': "project";
35
+ 'tool/ptc-dispatch-start': "project";
36
+ 'tool/ptc-dispatch': "project";
33
37
  'step/start': "skip";
34
38
  'step/end': "skip";
35
39
  'developer/message': "skip";
@@ -39,8 +43,6 @@ declare const CLASSIFICATION: {
39
43
  'request/context': "skip";
40
44
  'session/end-seed': "skip";
41
45
  'agent/inbox/spliced': "skip";
42
- 'tool/ptc-dispatch-start': "skip";
43
- 'tool/ptc-dispatch': "skip";
44
46
  'subagent/descriptor': "skip";
45
47
  'approval/asked': "skip";
46
48
  'approval/decided': "skip";
@@ -48,6 +50,7 @@ declare const CLASSIFICATION: {
48
50
  'permission/preset': "skip";
49
51
  'sandbox/mode': "skip";
50
52
  'model/selection': "skip";
53
+ 'agent-preset/selected': "skip";
51
54
  'goal/change': "skip";
52
55
  };
53
56
  type ClassifiedEventType = keyof typeof CLASSIFICATION;
package/lib/index.js CHANGED
@@ -1,11 +1,16 @@
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
- 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
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`,"tool/ptc-dispatch-start":`project`,"tool/ptc-dispatch":`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`,"subagent/descriptor":`skip`,"approval/asked":`skip`,"approval/decided":`skip`,"approval/policy":`skip`,"permission/preset":`skip`,"sandbox/mode":`skip`,"model/selection":`skip`,"agent-preset/selected":`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`,run_code:`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})`:``}`},run_code:e=>{let t=c(e.description)?.replace(/\s+/g,` `).trim();return t===void 0||t.length===0?`Run code`:t.length>120?`${t.slice(0,120)}\u2026`:t},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 re(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 C=[1],w=C[C.length-1]??1;function ie(e){return e===void 0?{version:w}:C.includes(e)?{version:e}:{version:w,warn:`client protocol version ${e} not in supported set`}}function ae(e){return{capabilities:{loadSession:!0,promptCapabilities:{image:!0,embeddedContext:!0}},meta:{openacpagent:{usage:{},image:{}},tboxcode:{protocolVersion:e}}}}var oe=class{#e=new Map;record(e,t,n){this.#e.set(e,{name:t,input:b(n)})}lookup(e){return this.#e.get(e)}},se=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 T=e=>typeof e==`string`?e:void 0,ce=e=>e.data??{},le=new Set([`write`,`scratch_write`]),E=new Set([`edit`,`scratch_edit`]),ue=e=>typeof e==`object`&&!!e&&typeof e.path==`string`&&(e.oldText===null||typeof e.oldText==`string`)&&typeof e.newText==`string`;function de(e,t,n,r){let i=n??{},a=i.diffs;if(Array.isArray(a)&&a.length>0)return a.every(ue)?a:[];let o=T(i.path),s=t??{};if(o!==void 0)return le.has(e)?[{path:o,oldText:i.operation===`create`?null:T(i.before)??null,newText:T(i.after)??T(s.content)??``}]:E.has(e)?[{path:o,oldText:T(i.before)??u(s)??null,newText:T(i.after)??d(s)??``}]:[];let c=f(l(s),r);return c===void 0?[]:le.has(e)?[{path:c,oldText:null,newText:T(s.content)??``}]:E.has(e)?[{path:c,oldText:u(s)??null,newText:d(s)??``}]:e===`str_replace_editor`?s.command===`create`?[{path:c,oldText:null,newText:T(s.file_text)??``}]:s.command===`str_replace`?[{path:c,oldText:T(s.old_str)??null,newText:T(s.new_str)??``}]:[]:[]}function D(e,t){return{sessionUpdate:`user_message_chunk`,content:{type:`text`,text:e},...t?{messageId:t}:{}}}function O(e,t){return{sessionUpdate:`agent_message_chunk`,content:{type:`text`,text:e},...t?{messageId:t}:{}}}function k(e,t){return{sessionUpdate:`agent_thought_chunk`,content:{type:`text`,text:e},...t?{messageId:t}:{}}}function fe(e,t,n,r){return{sessionUpdate:`usage_update`,used:e,size:t,_meta:{openacpagent:{usage:{cacheReadTokens:n,cacheWriteTokens:r}}}}}const A=e=>e===`subagent`||e.startsWith(`subagent_`),j=e=>typeof e==`object`&&!!e&&!Array.isArray(e),M=(e,t)=>e.idPrefix===void 0?t:`${e.idPrefix}:${t}`;function N(e){return typeof e==`string`?b(e):j(e)?e:void 0}function P(...e){let t;for(let n of e)if(n!==void 0){t??={};for(let[e,r]of Object.entries(n)){let n=t[e];t[e]=j(n)&&j(r)?{...n,...r}:r}}return t}const F=e=>P(e.presentationMeta!==void 0&&e.presentationMeta!==null?{openacpagent:{toolMeta:e.presentationMeta}}:void 0,e.frameMeta);function I(e){let t=M(e,e.callId),n=e.name===`bash`&&e.supportsTerminalOutput===!0,r=_(e.name,e.input),i=F(e);return{sessionUpdate:`tool_call`,toolCallId:t,name:e.name,title:e.decorateTitle===void 0?r:e.decorateTitle(r),kind:s(e.name),status:`pending`,locations:m(e.name,e.input,e.cwd),rawInput:e.rawInput??e.input??{},...n?{content:[{type:`terminal`,terminalId:t}]}:{},...i===void 0?{}:{_meta:i}}}function L(e){let t=M(e,e.callId),n=v(e.name,e.input,e.presentationMeta),r=e.content.filter(e=>e.type===`text`).map(e=>T(e.text)??``).join(``),i=[];if(e.status===`completed`)for(let t of de(e.name,e.input,e.presentationMeta,e.cwd))i.push({type:`diff`,...t});let a=e.name===`bash`&&e.supportsTerminalOutput===!0;a?i.push({type:`terminal`,terminalId:t}):r.trimEnd()&&i.push({type:`content`,content:{type:`text`,text:r}});let o=F(e),c={sessionUpdate:`tool_call_update`,toolCallId:t,name:e.name,status:e.status,title:e.decorateTitle===void 0?n:e.decorateTitle(n),kind:s(e.name),locations:h(e.name,e.input,e.presentationMeta,e.cwd),rawInput:e.rawInput??e.input??{},rawOutput:{content:e.content,meta:e.presentationMeta,error:e.error},...i.length>0?{content:i}:{}};return a?[{sessionUpdate:`tool_call_update`,toolCallId:t,_meta:{terminal_output:{terminal_id:t,data:r}}},{...c,_meta:{...o??{},terminal_exit:{terminal_id:t,exit_code:e.status===`completed`?0:1,signal:null}}}]:[o===void 0?c:{...c,_meta:o}]}function pe(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[D(``,r)];let a=[];for(let e of i)e.type===`text`?a.push(D(T(e.text)??``,r)):a.push(D(`[${String(e.type)}]`,r));return a}function me(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=>he(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=T(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`?k(c,u):O(c,u)),t[i]=Math.max(t[i],o+n.length),a.set(e,t)}else r.push(i===`reasoning`?k(n,u):O(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(fe(e,2e5,typeof p.cacheReadTokens==`number`?p.cacheReadTokens:0,typeof p.cacheWriteTokens==`number`?p.cacheWriteTokens:0))}return r}function he(e,t){let n=``,r=``;for(let e of t)e.type===`text`?n+=T(e.text)??``:e.type===`reasoning`&&(r+=T(e.text)??``);return R(e.text,n)&&R(e.reasoning,r)}function R(e,t){return t.startsWith(e)||e.startsWith(t)}function ge(e,t){let n=T(e.callId)??``,r=T(e.name)??`unknown`,i=T(e.arguments);t.journal?.record(n,r,i);let a=b(i);return t.subagents!==void 0&&A(r)&&t.subagents.trackDelegation(n,r),[I({callId:n,name:r,input:a,cwd:t.cwd,supportsTerminalOutput:t.supportsTerminalOutput})]}function _e(e,t){let n=e.message,r=T(n?.toolCallId)??``,i=t.journal?.lookup(r),a=i?.name??`unknown`,o=i?.input,s=n?.isError===!0||e.error!==void 0?`failed`:`completed`,c=t.subagents!==void 0&&A(a)?{openacpagent:{subagent:t.subagents.metaFor(r,a)}}:void 0;return L({callId:r,name:a,input:o,cwd:t.cwd,supportsTerminalOutput:t.supportsTerminalOutput,status:s,content:n?.content??[],presentationMeta:e.meta,error:e.error,frameMeta:c})}function z(e,t){let n=T(t);return P(e.frameMeta,n===void 0||n===``?void 0:{tboxcode:{ptc:{parentToolCallId:M(e,n)}}})}function ve(e,t){let n=T(e.subCallId),r=T(e.name);return n===void 0||n===``||r===void 0||r.trim()===``?[]:[I({callId:n,name:r,input:N(e.arguments),rawInput:e.arguments??{},cwd:t.cwd,supportsTerminalOutput:t.supportsTerminalOutput,idPrefix:t.idPrefix,decorateTitle:t.decorateTitle,frameMeta:z(t,e.parentCallId)})]}function B(e,t){let n=T(e.subCallId),r=T(e.name);if(n===void 0||n===``||r===void 0||r.trim()===``)return[];let i=e.isError===!0||e.error!==void 0?`failed`:`completed`;return L({callId:n,name:r,input:N(e.arguments),rawInput:e.arguments??{},cwd:t.cwd,supportsTerminalOutput:t.supportsTerminalOutput,idPrefix:t.idPrefix,decorateTitle:t.decorateTitle,status:i,content:Array.isArray(e.content)?e.content:[],presentationMeta:e.meta,error:e.error,frameMeta:z(t,e.parentCallId)})}function ye(e,t,n,r){let i=t.type,a=ce(t),o=n.parentCallIdOf(e)??e,s={cwd:r.cwd,supportsTerminalOutput:r.supportsTerminalOutput,idPrefix:o,decorateTitle:t=>y(t,n.labelOfChild(e),e)};if(i===`tool/call`){let e=T(a.callId)??``,t=T(a.name)??`unknown`,n=T(a.arguments);return r.journal.record(e,t,n),[I({callId:e,name:t,input:b(n),...s})]}if(i===`tool/result`){let e=a.message,t=T(e?.toolCallId)??``,i=r.journal.lookup(t),c=i?.name??`unknown`,l=i?.input,u=e?.isError===!0||a.error!==void 0?`failed`:`completed`;return L({callId:t,name:c,input:l,...s,status:u,content:e?.content??[],presentationMeta:a.meta,error:a.error,frameMeta:{openacpagent:{subagent:n.metaFor(o,c)}}})}if(i===`tool/ptc-dispatch-start`||i===`tool/ptc-dispatch`){let e=T(a.name),t=i===`tool/ptc-dispatch`?{openacpagent:{subagent:n.metaFor(o,e??`unknown`)}}:void 0,r={...s,frameMeta:t};return i===`tool/ptc-dispatch-start`?ve(a,r):B(a,r)}return[]}function be(e){return[{sessionUpdate:`plan`,entries:(e.todos??[]).map(e=>({content:T(e.content)??``,status:e.status===`in_progress`?`in_progress`:e.status===`completed`?`completed`:`pending`}))}]}function xe(e,t){let n=t.source;return[{sessionUpdate:`session_info_update`,title:T(t.title)??null,updatedAt:new Date(e.time).toISOString(),_meta:n?.kind===void 0?{}:{openacpagent:{titleSource:n.kind}}}]}function Se(e){let t=T(e.name)??``,n=T(e.args);return[D(`/${t}${n?` ${n}`:``}`,T(e.commandId))]}function Ce(e){let t=e.kind===`success`?`success`:`error`,n=O(T(e.text)??(t===`success`?`Command completed`:`Command failed`),T(e.commandId));return typeof e.sourceEventSeq==`number`&&(n._meta={openacpagent:{sourceEventSeq:e.sourceEventSeq}}),[n]}function we(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=ce(e);switch(e.type){case`user/message`:return pe(o,t);case`assistant/message`:return me(o,t);case`tool/call`:return ge(o,t);case`tool/result`:return _e(o,t);case`tool/ptc-dispatch-start`:{let e=T(o.subCallId),n=T(o.name);return e!==void 0&&e!==``&&n!==void 0&&A(n)&&t.subagents?.trackDelegation(e,n),ve(o,{cwd:t.cwd,supportsTerminalOutput:t.supportsTerminalOutput})}case`tool/ptc-dispatch`:{let e=T(o.subCallId),n=T(o.name),r=t.subagents!==void 0&&e!==void 0&&e!==``&&n!==void 0&&A(n)?{openacpagent:{subagent:t.subagents.metaFor(e,n)}}:void 0;return B(o,{cwd:t.cwd,supportsTerminalOutput:t.supportsTerminalOutput,frameMeta:r})}case`todo/write`:return be(o);case`session/title`:return xe(e,o);case`command/run`:return Se(o);case`command/done`:return Ce(o);case`subagent/catalog`:{let n=T(o.childId);if(n!==void 0){let r=o;t.subagents?.accept({childId:n,childCreatedAt:typeof r.childCreatedAt==`number`?r.childCreatedAt:e.time,mode:T(r.mode)??`unknown`,label:T(r.label)}),t.onSubagentCatalog?.({childId:n,childCreatedAt:typeof r.childCreatedAt==`number`?r.childCreatedAt:e.time,mode:T(r.mode)??`unknown`,label:T(r.label)})}return[]}case`turn/start`:case`turn/end`:return[];default:return[]}}function Te(e,t,n){return we(e,{...t,live:!1},n)}function Ee(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=T(e.chunk?.text)??``;return n===`text-delta`?(t.attempts?.record(e.attemptId,`text`,r),[O(r,e.attemptId)]):n===`reasoning-delta`?(t.attempts?.record(e.attemptId,`reasoning`,r),[k(r,e.attemptId)]):[]}var De=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=T(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===`tool/ptc-dispatch-start`&&typeof t.subCallId==`string`)this.#e[this.#e.length-1]?.tools.set(t.subCallId,{resolved:!1});else if(e.type===`tool/ptc-dispatch`){let e=typeof t.subCallId==`string`?t.subCallId:void 0,n=this.#e[this.#e.length-1];if(e!==void 0&&n!==void 0){let t=n.tools.get(e);t&&(t.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()}}}},Oe=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 ke=0;const V=(e,t,n={})=>({type:e,seq:++ke,time:17e11,data:t,...n}),H={id:`msg-u1`,role:`user`,content:[{type:`text`,text:`hello`}],source:{kind:`user`}},Ae={id:`msg-cat1`,role:`user`,content:[{type:`text`,text:`<skill catalog>`}],source:{kind:`skill-catalog`,form:`catalog`,entries:[]}},je={id:`msg-rc1`,role:`user`,content:[{type:`text`,text:`<runtime context>`}],source:{kind:`runtime-context`}},Me={id:`msg-a1`,role:`assistant`,content:[{type:`text`,text:`world`}],source:{kind:`model`,provider:`echo`,model:`echo`}},Ne={id:`msg-a2`,role:`assistant`,content:[{type:`reasoning`,text:`thinking…`},{type:`text`,text:`answer`}],source:{kind:`model`,provider:`echo`,model:`echo`}},Pe=[{name:`echo-whitelist`,events:[V(`user/message`,Ae),V(`user/message`,je),V(`user/message`,H)],expectedLive:[U(`hello`,`msg-u1`)]},{name:`user-last-subagent-task`,events:[V(`user/message`,{...H,id:`msg-task`,content:[{type:`text`,text:`delegate task`}]})],expectedLive:[U(`delegate task`,`msg-task`)]},{name:`assistant-durable-mixed`,events:[V(`assistant/message`,{turn:1,step:1,message:Ne,stream:[],usage:{inputTokens:10,outputTokens:5,totalTokens:15,cacheReadTokens:3,cacheWriteTokens:2}})],expectedLive:[G(`thinking…`,`msg-a2`),W(`answer`,`msg-a2`),K(15,3,2)]},{name:`assistant-durable-no-usage`,events:[V(`assistant/message`,{turn:1,step:2,message:Me,stream:[]})],expectedLive:[W(`world`,`msg-a1`)]},{name:`tool-lifecycle-bash`,events:[V(`turn/start`,{turn:1}),V(`tool/call`,{turn:1,step:1,callId:`c1`,name:`bash`,arguments:`{"command":"ls -la"}`}),V(`tool/result`,{turn:1,step:1,message:{toolCallId:`c1`,role:`tool`,content:[{type:`text`,text:`file.txt`}]}}),V(`turn/end`,{turn:1,reason:{kind:`completed`}})],expectedLive:[J(`c1`,`Execute ls -la`,`execute`,{command:`ls -la`},[],`bash`),Y(`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:[V(`turn/start`,{turn:1}),V(`tool/call`,{turn:1,step:1,callId:`c2`,name:`read`,arguments:`{"file_path":"a.ts"}`}),V(`turn/end`,{turn:1,reason:{kind:`error`}})],expectedLive:[J(`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:[V(`tool/call`,{turn:1,step:1,callId:`c3`,name:`edit`,arguments:`{"file_path":"src/a.ts","old_string":"a","new_string":"b"}`}),V(`tool/result`,{turn:1,step:1,message:{toolCallId:`c3`,role:`tool`,content:[{type:`text`,text:`ok`}]}})],expectedLive:[J(`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`),Y(`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:[V(`tool/call`,{turn:1,step:1,callId:`w1`,name:`write`,arguments:`{"file_path":"src/new.ts","content":"line1\\nline2\\n"}`}),V(`tool/result`,{turn:1,step:1,message:{toolCallId:`w1`,role:`tool`,content:[{type:`text`,text:`<path>/w/src/new.ts</path>
2
+ Created file`}]},meta:{operation:`create`,path:`/w/src/new.ts`,diffs:[]}})],expectedLive:[J(`w1`,`Write src/new.ts`,`edit`,{file_path:`src/new.ts`,content:`line1
3
3
  line2
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
4
+ `},[{path:`/w/src/new.ts`,line:null}],`write`),Y(`w1`,`completed`,`Write src/new.ts (created)`,`edit`,[{path:`/w/src/new.ts`,line:null}],{file_path:`src/new.ts`,content:`line1
5
5
  line2
6
6
  `},{name:`write`,meta:{operation:`create`,path:`/w/src/new.ts`,diffs:[]},content:[{type:`text`,text:`<path>/w/src/new.ts</path>
7
7
  Created file`}],contentFrames:[{type:`diff`,path:`/w/src/new.ts`,oldText:null,newText:`line1
8
8
  line2
9
9
  `},{type:`content`,content:{type:`text`,text:`<path>/w/src/new.ts</path>
10
- Created file`}}]})]},{name:`write-update-diff`,cwd:`/w`,events:[L(`tool/call`,{turn:1,step:1,callId:`w2`,name:`write`,arguments:`{"file_path":"src/a.ts","content":"new"}`}),L(`tool/result`,{turn:1,step:1,message:{toolCallId:`w2`,role:`tool`,content:[{type:`text`,text:`Updated file`}]},meta:{operation:`update`,path:`/w/src/a.ts`,diffs:[{path:`/w/src/a.ts`,oldText:`old`,newText:`new`}]}})],expectedLive:[U(`w2`,`Write src/a.ts`,`edit`,{file_path:`src/a.ts`,content:`new`},[{path:`/w/src/a.ts`,line:null}],`write`),W(`w2`,`completed`,`Write src/a.ts (updated)`,`edit`,[{path:`/w/src/a.ts`,line:null}],{file_path:`src/a.ts`,content:`new`},{name:`write`,meta:{operation:`update`,path:`/w/src/a.ts`,diffs:[{path:`/w/src/a.ts`,oldText:`old`,newText:`new`}]},content:[{type:`text`,text:`Updated file`}],contentFrames:[{type:`diff`,path:`/w/src/a.ts`,oldText:`old`,newText:`new`},{type:`content`,content:{type:`text`,text:`Updated file`}}]})]},{name:`edit-snake-diff`,cwd:`/w`,events:[L(`tool/call`,{turn:1,step:1,callId:`e1`,name:`edit`,arguments:`{"file_path":"src/a.ts","old_string":"a","new_string":"b"}`}),L(`tool/result`,{turn:1,step:1,message:{toolCallId:`e1`,role:`tool`,content:[{type:`text`,text:`ok`}]},meta:{path:`/w/src/a.ts`,diffs:[{path:`/w/src/a.ts`,oldText:`a`,newText:`b`}]}})],expectedLive:[U(`e1`,`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(`e1`,`completed`,`Edit src/a.ts (1 changes)`,`edit`,[{path:`/w/src/a.ts`,line:null}],{file_path:`src/a.ts`,old_string:`a`,new_string:`b`},{name:`edit`,meta:{path:`/w/src/a.ts`,diffs:[{path:`/w/src/a.ts`,oldText:`a`,newText:`b`}]},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:`scratch-write-diff`,cwd:`/w`,events:[L(`tool/call`,{turn:1,step:1,callId:`sw1`,name:`scratch_write`,arguments:`{"filePath":"x.py","content":"print(1)"}`}),L(`tool/result`,{turn:1,step:1,message:{toolCallId:`sw1`,role:`tool`,content:[{type:`text`,text:`written: /tmp/tboxcode-scratch/s1/x.py`}]},meta:{path:`/tmp/tboxcode-scratch/s1/x.py`,operation:`create`,diffs:[{path:`/tmp/tboxcode-scratch/s1/x.py`,oldText:null,newText:`print(1)`}]}})],expectedLive:[U(`sw1`,`Write scratch file x.py`,`edit`,{filePath:`x.py`,content:`print(1)`},[],`scratch_write`),W(`sw1`,`completed`,`Write scratch file x.py (created)`,`edit`,[{path:`/tmp/tboxcode-scratch/s1/x.py`,line:null}],{filePath:`x.py`,content:`print(1)`},{name:`scratch_write`,meta:{path:`/tmp/tboxcode-scratch/s1/x.py`,operation:`create`,diffs:[{path:`/tmp/tboxcode-scratch/s1/x.py`,oldText:null,newText:`print(1)`}]},content:[{type:`text`,text:`written: /tmp/tboxcode-scratch/s1/x.py`}],contentFrames:[{type:`diff`,path:`/tmp/tboxcode-scratch/s1/x.py`,oldText:null,newText:`print(1)`},{type:`content`,content:{type:`text`,text:`written: /tmp/tboxcode-scratch/s1/x.py`}}]})]},{name:`write-failed-no-diff`,cwd:`/w`,events:[L(`tool/call`,{turn:1,step:1,callId:`wf1`,name:`write`,arguments:`{"file_path":"src/a.ts","content":"x"}`}),L(`tool/result`,{turn:1,step:1,message:{toolCallId:`wf1`,role:`tool`,isError:!0,content:[{type:`text`,text:`denied`}]},meta:{path:`/w/src/a.ts`,diffs:[{path:`/w/src/a.ts`,oldText:`old`,newText:`x`}]},error:{name:`FsError`,message:`denied`}})],expectedLive:[U(`wf1`,`Write src/a.ts`,`edit`,{file_path:`src/a.ts`,content:`x`},[{path:`/w/src/a.ts`,line:null}],`write`),W(`wf1`,`failed`,`Write src/a.ts`,`edit`,[{path:`/w/src/a.ts`,line:null}],{file_path:`src/a.ts`,content:`x`},{name:`write`,meta:{path:`/w/src/a.ts`,diffs:[{path:`/w/src/a.ts`,oldText:`old`,newText:`x`}]},content:[{type:`text`,text:`denied`}],contentFrames:[{type:`content`,content:{type:`text`,text:`denied`}}],error:{name:`FsError`,message:`denied`}})]},{name:`str-replace-editor-create`,cwd:`/w`,events:[L(`tool/call`,{turn:1,step:1,callId:`sre1`,name:`str_replace_editor`,arguments:`{"command":"create","path":"src/b.ts","file_text":"x"}`}),L(`tool/result`,{turn:1,step:1,message:{toolCallId:`sre1`,role:`tool`,content:[{type:`text`,text:`created`}]}})],expectedLive:[U(`sre1`,`Create src/b.ts`,`edit`,{command:`create`,path:`src/b.ts`,file_text:`x`},[{path:`/w/src/b.ts`,line:null}],`str_replace_editor`),W(`sre1`,`completed`,`Create src/b.ts`,`edit`,[{path:`/w/src/b.ts`,line:null}],{command:`create`,path:`src/b.ts`,file_text:`x`},{name:`str_replace_editor`,content:[{type:`text`,text:`created`}],contentFrames:[{type:`diff`,path:`/w/src/b.ts`,oldText:null,newText:`x`},{type:`content`,content:{type:`text`,text:`created`}}]})]},{name:`locations-gated-read`,events:[L(`tool/call`,{turn:1,step:1,callId:`c4`,name:`read`,arguments:`{"file_path":"a.ts"}`}),L(`tool/result`,{turn:1,step:1,message:{toolCallId:`c4`,role:`tool`,content:[{type:`text`,text:`x`}]}})],expectedLive:[U(`c4`,`Read a.ts`,`read`,{file_path:`a.ts`},[],`read`),W(`c4`,`completed`,`Read a.ts`,`read`,[],{file_path:`a.ts`},{name:`read`,content:[{type:`text`,text:`x`}],contentFrames:[{type:`content`,content:{type:`text`,text:`x`}}]})]},{name:`journal-missing-degraded`,events:[L(`tool/result`,{turn:1,step:1,message:{toolCallId:`ghost`,role:`tool`,content:[{type:`text`,text:`late`}]}})],expectedLive:[W(`ghost`,`completed`,`unknown`,`other`,[],{},{name:`unknown`,content:[{type:`text`,text:`late`}],contentFrames:[{type:`content`,content:{type:`text`,text:`late`}}]})]},{name:`plan-todo-write`,events:[L(`todo/write`,{todos:[{content:`a`,status:`completed`},{content:`b`,status:`in_progress`},{content:`c`,status:`pending`}]})],expectedLive:[{sessionUpdate:`plan`,entries:[{content:`a`,status:`completed`},{content:`b`,status:`in_progress`},{content:`c`,status:`pending`}]}]},{name:`session-info-title`,events:[L(`session/title`,{title:`Fix bug`,messageSeqs:[1],source:{kind:`provider`,provider:`p`}})],expectedLive:[{sessionUpdate:`session_info_update`,title:`Fix bug`,updatedAt:new Date(17e11).toISOString(),_meta:{openacpagent:{titleSource:`provider`}}}]},{name:`command-projection`,events:[L(`command/run`,{commandId:`cmd1`,name:`compact`,source:{kind:`user`}}),L(`command/done`,{commandId:`cmd1`,kind:`success`,text:`compacted`,sourceEventSeq:9})],expectedLive:[z(`/compact`,`cmd1`),Oe(B(`compacted`,`cmd1`),{openacpagent:{sourceEventSeq:9}})]},{name:`command-echo-record-input-false`,events:[L(`command/run`,{commandId:`cmd2`,name:`feedback`,source:{kind:`user`}})],expectedLive:[z(`/feedback`,`cmd2`)]},{name:`stream-frame-boundaries`,events:[],streamFrames:[{type:`start`,attemptId:`att1`},{type:`chunk`,attemptId:`att1`,chunk:{type:`text-delta`,text:`he`}},{type:`chunk`,attemptId:`att1`,chunk:{type:`reasoning-delta`,text:`think`}},{type:`chunk`,attemptId:`att1`,chunk:{type:`tool-call-delta`}},{type:`end`,attemptId:`att1`,index:2,outcome:{kind:`committed`,eventType:`assistant/message`,seq:5}}],expectedLive:[B(`he`,`att1`),V(`think`,`att1`)],expectedReplay:[]},{name:`stream-durable-merged`,events:[L(`assistant/message`,{turn:1,step:1,message:{id:`msg-merged`,role:`assistant`,content:[{type:`reasoning`,text:`think`},{type:`text`,text:`Hello`}],source:{kind:`model`,provider:`echo`,model:`echo`}},stream:[],usage:{inputTokens:1,outputTokens:1}})],streamFrames:[{type:`start`,attemptId:`att-merged`,revision:1,turn:1,step:1},{type:`chunk`,attemptId:`att-merged`,revision:2,index:0,time:0,chunk:{type:`reasoning-delta`,text:`thi`}},{type:`chunk`,attemptId:`att-merged`,revision:3,index:1,time:1,chunk:{type:`text-delta`,text:`Hel`}}],expectedLive:[V(`thi`,`att-merged`),B(`Hel`,`att-merged`),V(`nk`,`att-merged`),B(`lo`,`att-merged`),H(2,0,0)],expectedReplay:[V(`think`,`msg-merged`),B(`Hello`,`msg-merged`),H(2,0,0)]},{name:`surface-replace-folded`,events:[L(`user/message`,{...R,id:`msg-ck`,content:[{type:`text`,text:`compacted summary`}]},{surfaceOp:{op:`replace`,startSeq:1,endSeq:3}})],expectedLive:[z(`compacted summary`,`msg-ck`)]},{name:`unknown-fallback-graded`,events:[L(`llm/retry`,{attempt:1},{ignorable:!0}),L(`brand-new-event`,{x:1})],expectedLive:[],expectedUnknown:[[`llm/retry`,`debug`],[`brand-new-event`,`warn`]]},{name:`skip-classified-silent`,events:[L(`sandbox/mode`,{mode:`read-only`}),L(`permission/preset`,{preset:`auto`}),L(`model/selection`,{provider:`p`,model:`m`}),L(`subagent/descriptor`,{childId:`c`}),L(`goal/change`,{kind:`goal/change`,version:1,operation:`create`})],expectedLive:[],expectedUnknown:[]}];function z(e,t){return{sessionUpdate:`user_message_chunk`,content:{type:`text`,text:e},messageId:t}}function B(e,t){return{sessionUpdate:`agent_message_chunk`,content:{type:`text`,text:e},messageId:t}}function V(e,t){return{sessionUpdate:`agent_thought_chunk`,content:{type:`text`,text:e},messageId:t}}function H(e,t,n){return{sessionUpdate:`usage_update`,used:e,size:2e5,_meta:{openacpagent:{usage:{cacheReadTokens:t,cacheWriteTokens:n}}}}}function Oe(e,t){return{...e,_meta:t}}function U(e,t,n,r,i=[],a){return{sessionUpdate:`tool_call`,toolCallId:e,...a===void 0?{}:{name:a},title:t,kind:n,status:`pending`,locations:i,rawInput:r}}function W(e,t,n,r,i,a,o){return{sessionUpdate:`tool_call_update`,toolCallId:e,...o.name===void 0?{}:{name:o.name},status:t,title:n,kind:r,locations:i,rawInput:a,rawOutput:{content:o.content??[],meta:o.meta,error:o.error},...o.contentFrames&&o.contentFrames.length>0?{content:o.contentFrames}:{},...o.meta!==void 0&&o.meta!==null?{_meta:{openacpagent:{toolMeta:o.meta}}}:{}}}const G=/^\/([a-z][a-z0-9_-]*)(?=$|[\s])/u,K=new Set([`plan`,`permission`,`export`]),ke={plan:`mode 单一真源 = configOption 通道(死防御——组合挂回 plan-mode 插件时已正确)`,permission:`权限档单一真源 = configOption 通道(dsh /permission 是会话中切档唯一写路径,投影制造第二写入口)`,export:`产物走 web 认证 GET 路由,ACP 客户端不可达`};function Ae(e){let t=e?.trim()??``,n=G.exec(t);if(n===null)return{hit:!1,name:``,shadow:!1};let r=n[1]??``;return{hit:!0,name:r,shadow:K.has(r)}}function je(e){return e.kind===`aborted`?{stopReason:`cancelled`}:{stopReason:`end_turn`,usage:{totalTokens:0,inputTokens:0,outputTokens:0}}}function Me(e,t){let n=new Map;for(let t of e){if(K.has(t.name))continue;let e=t.input?.hint;n.set(t.name,{name:t.name,description:t.description,...e===void 0?{}:{input:{hint:e}}})}for(let e of t)!e.invocation.userInvocable||n.has(e.name)||n.set(e.name,{name:e.name,description:e.description});return[...n.values()].sort((e,t)=>e.name<t.name?-1:e.name>t.name?1:0)}function q(e){let t=e.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``);return t===``?`question`:t}function J(e){let t=new Set;return e.map(e=>{let n=q(e.header??e.question),r=n,i=2;for(;t.has(r);)r=`${n}-${i}`,i+=1;return t.add(r),r})}function Ne(e){let t=e.options??[],n=e=>({const:e.label,title:e.description===void 0?e.label:`${e.label} — ${e.description}`}),r=e.intent===void 0?void 0:t.find(t=>t.label===e.intent?.approve),i=r===void 0?t:t.filter(e=>e!==r);return[...r===void 0?[]:[n(r)],...i.map(n),{const:`__custom__`,title:`Other — type your own answer below`}]}function Pe(e){let t=J(e),n={},r=[];return e.forEach((e,i)=>{let a=t[i]??`question-${i}`,o=e.detail===void 0?e.question:`${e.question}\n\n${e.detail}`;if(e.options!==void 0&&e.options.length>0){let t=Ne(e);n[a]=e.multiSelect===!0?{type:`array`,title:e.header??e.question,description:o,minItems:1,items:{anyOf:t}}:{type:`string`,title:e.header??e.question,description:o,oneOf:t}}else n[a]={type:`string`,title:e.header??e.question,description:o};n[`${a}_customText`]={type:`string`,title:`Custom answer`},r.push(a)}),{type:`object`,properties:n,required:r}}function Y(e,t){return t.has(e)}function Fe(e,t){let n=J(e);return{answers:e.map((e,r)=>{let i=n[r]??`question-${r}`,a=t[i];if(a===void 0)throw Error(`elicitation content missing property: ${i}`);let o=new Set((e.options??[]).map(e=>e.label));if(e.options!==void 0&&e.options.length>0&&e.multiSelect===!0){if(!Array.isArray(a)||a.some(e=>typeof e!=`string`))throw Error(`elicitation content property is not a string array: ${i}`);let t=a.filter(e=>Y(e,o)),n=a.filter(e=>!Y(e,o));return{id:e.id,selected:t,...n.length===0?{}:{custom:n.join(`
11
- `)}}}if(typeof a!=`string`)throw Error(`elicitation content property is not a string: ${i}`);return e.options===void 0||e.options.length===0?{id:e.id,selected:[],...a===``?{}:{custom:a}}:Y(a,o)?{id:e.id,selected:[a]}:{id:e.id,selected:[],custom:a}})}}const X=`mode`,Ie=`model`,Le=`reasoning_effort`,Re=``,Z={build:{sandbox:`danger-full-access`,approval:`never`},plan:{sandbox:`read-only`,approval:`ask`}},Q={build:`build`,plan:`plan`},ze=[`build`,`plan`];function $(e){return e in Z}function Be(e){return $(e)?Z[e]:void 0}function Ve(e){return e===`read-only`?`plan`:`build`}function He(e){return{id:X,name:`Mode`,category:`mode`,type:`select`,currentValue:e,options:ze.map(e=>({value:e,name:Q[e]}))}}function Ue(e,t){return JSON.stringify([e,t])}export{G as COMMAND_GATE_PATTERN,T as LATEST_PROTOCOL_VERSION,o as LOCATIONS_ALLOWED,Ie as MODEL_CONFIG_ID,X as MODE_CONFIG_ID,Z as MODE_TABLE,w as PROTOCOL_VERSIONS,Re as PROVIDER_DEFAULT_REASONING_VALUE,Le as REASONING_CONFIG_ID,x as RpcErrorCode,K as SHADOW_COMMANDS,ke as SHADOW_COMMANDS_RATIONALE,xe as StreamAttemptState,oe as SubagentCatalogState,g as TOOL_TITLE_BUILDERS,ae as ToolJournal,be as TurnFoldTracker,De as WIRE_FIXTURES,f as absolutize,ie as agentCapabilities,Pe as buildElicitationSchema,v as buildToolResultTitle,_ as buildToolTitle,r as classify,Ae as commandGate,Me as commandsProjection,$ as isAcpSessionMode,i as isIgnorable,h as locationsForResult,ne as mapRpcError,He as modeConfigOption,Ve as modeFromSandbox,re as negotiateProtocolVersion,Fe as parseElicitationContent,b as parseToolArguments,d as pickNew,u as pickOld,l as pickPath,I as projectEvent,ve as projectRecord,ye as projectStreamFrame,me as projectSubagentChildEvent,Ue as resolveModelValue,je as settleToResponse,q as slugifyQuestion,C as stopReasonFromTurnEnd,m as toLocations,s as toolKind,Be as translateMode,y as withSubagentPrefix};
10
+ Created file`}}]})]},{name:`write-update-diff`,cwd:`/w`,events:[V(`tool/call`,{turn:1,step:1,callId:`w2`,name:`write`,arguments:`{"file_path":"src/a.ts","content":"new"}`}),V(`tool/result`,{turn:1,step:1,message:{toolCallId:`w2`,role:`tool`,content:[{type:`text`,text:`Updated file`}]},meta:{operation:`update`,path:`/w/src/a.ts`,diffs:[{path:`/w/src/a.ts`,oldText:`old`,newText:`new`}]}})],expectedLive:[J(`w2`,`Write src/a.ts`,`edit`,{file_path:`src/a.ts`,content:`new`},[{path:`/w/src/a.ts`,line:null}],`write`),Y(`w2`,`completed`,`Write src/a.ts (updated)`,`edit`,[{path:`/w/src/a.ts`,line:null}],{file_path:`src/a.ts`,content:`new`},{name:`write`,meta:{operation:`update`,path:`/w/src/a.ts`,diffs:[{path:`/w/src/a.ts`,oldText:`old`,newText:`new`}]},content:[{type:`text`,text:`Updated file`}],contentFrames:[{type:`diff`,path:`/w/src/a.ts`,oldText:`old`,newText:`new`},{type:`content`,content:{type:`text`,text:`Updated file`}}]})]},{name:`edit-snake-diff`,cwd:`/w`,events:[V(`tool/call`,{turn:1,step:1,callId:`e1`,name:`edit`,arguments:`{"file_path":"src/a.ts","old_string":"a","new_string":"b"}`}),V(`tool/result`,{turn:1,step:1,message:{toolCallId:`e1`,role:`tool`,content:[{type:`text`,text:`ok`}]},meta:{path:`/w/src/a.ts`,diffs:[{path:`/w/src/a.ts`,oldText:`a`,newText:`b`}]}})],expectedLive:[J(`e1`,`Edit src/a.ts`,`edit`,{file_path:`src/a.ts`,old_string:`a`,new_string:`b`},[{path:`/w/src/a.ts`,line:null}],`edit`),Y(`e1`,`completed`,`Edit src/a.ts (1 changes)`,`edit`,[{path:`/w/src/a.ts`,line:null}],{file_path:`src/a.ts`,old_string:`a`,new_string:`b`},{name:`edit`,meta:{path:`/w/src/a.ts`,diffs:[{path:`/w/src/a.ts`,oldText:`a`,newText:`b`}]},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:`scratch-write-diff`,cwd:`/w`,events:[V(`tool/call`,{turn:1,step:1,callId:`sw1`,name:`scratch_write`,arguments:`{"filePath":"x.py","content":"print(1)"}`}),V(`tool/result`,{turn:1,step:1,message:{toolCallId:`sw1`,role:`tool`,content:[{type:`text`,text:`written: /tmp/tboxcode-scratch/s1/x.py`}]},meta:{path:`/tmp/tboxcode-scratch/s1/x.py`,operation:`create`,diffs:[{path:`/tmp/tboxcode-scratch/s1/x.py`,oldText:null,newText:`print(1)`}]}})],expectedLive:[J(`sw1`,`Write scratch file x.py`,`edit`,{filePath:`x.py`,content:`print(1)`},[],`scratch_write`),Y(`sw1`,`completed`,`Write scratch file x.py (created)`,`edit`,[{path:`/tmp/tboxcode-scratch/s1/x.py`,line:null}],{filePath:`x.py`,content:`print(1)`},{name:`scratch_write`,meta:{path:`/tmp/tboxcode-scratch/s1/x.py`,operation:`create`,diffs:[{path:`/tmp/tboxcode-scratch/s1/x.py`,oldText:null,newText:`print(1)`}]},content:[{type:`text`,text:`written: /tmp/tboxcode-scratch/s1/x.py`}],contentFrames:[{type:`diff`,path:`/tmp/tboxcode-scratch/s1/x.py`,oldText:null,newText:`print(1)`},{type:`content`,content:{type:`text`,text:`written: /tmp/tboxcode-scratch/s1/x.py`}}]})]},{name:`write-failed-no-diff`,cwd:`/w`,events:[V(`tool/call`,{turn:1,step:1,callId:`wf1`,name:`write`,arguments:`{"file_path":"src/a.ts","content":"x"}`}),V(`tool/result`,{turn:1,step:1,message:{toolCallId:`wf1`,role:`tool`,isError:!0,content:[{type:`text`,text:`denied`}]},meta:{path:`/w/src/a.ts`,diffs:[{path:`/w/src/a.ts`,oldText:`old`,newText:`x`}]},error:{name:`FsError`,message:`denied`}})],expectedLive:[J(`wf1`,`Write src/a.ts`,`edit`,{file_path:`src/a.ts`,content:`x`},[{path:`/w/src/a.ts`,line:null}],`write`),Y(`wf1`,`failed`,`Write src/a.ts`,`edit`,[{path:`/w/src/a.ts`,line:null}],{file_path:`src/a.ts`,content:`x`},{name:`write`,meta:{path:`/w/src/a.ts`,diffs:[{path:`/w/src/a.ts`,oldText:`old`,newText:`x`}]},content:[{type:`text`,text:`denied`}],contentFrames:[{type:`content`,content:{type:`text`,text:`denied`}}],error:{name:`FsError`,message:`denied`}})]},{name:`str-replace-editor-create`,cwd:`/w`,events:[V(`tool/call`,{turn:1,step:1,callId:`sre1`,name:`str_replace_editor`,arguments:`{"command":"create","path":"src/b.ts","file_text":"x"}`}),V(`tool/result`,{turn:1,step:1,message:{toolCallId:`sre1`,role:`tool`,content:[{type:`text`,text:`created`}]}})],expectedLive:[J(`sre1`,`Create src/b.ts`,`edit`,{command:`create`,path:`src/b.ts`,file_text:`x`},[{path:`/w/src/b.ts`,line:null}],`str_replace_editor`),Y(`sre1`,`completed`,`Create src/b.ts`,`edit`,[{path:`/w/src/b.ts`,line:null}],{command:`create`,path:`src/b.ts`,file_text:`x`},{name:`str_replace_editor`,content:[{type:`text`,text:`created`}],contentFrames:[{type:`diff`,path:`/w/src/b.ts`,oldText:null,newText:`x`},{type:`content`,content:{type:`text`,text:`created`}}]})]},{name:`locations-gated-read`,events:[V(`tool/call`,{turn:1,step:1,callId:`c4`,name:`read`,arguments:`{"file_path":"a.ts"}`}),V(`tool/result`,{turn:1,step:1,message:{toolCallId:`c4`,role:`tool`,content:[{type:`text`,text:`x`}]}})],expectedLive:[J(`c4`,`Read a.ts`,`read`,{file_path:`a.ts`},[],`read`),Y(`c4`,`completed`,`Read a.ts`,`read`,[],{file_path:`a.ts`},{name:`read`,content:[{type:`text`,text:`x`}],contentFrames:[{type:`content`,content:{type:`text`,text:`x`}}]})]},{name:`journal-missing-degraded`,events:[V(`tool/result`,{turn:1,step:1,message:{toolCallId:`ghost`,role:`tool`,content:[{type:`text`,text:`late`}]}})],expectedLive:[Y(`ghost`,`completed`,`unknown`,`other`,[],{},{name:`unknown`,content:[{type:`text`,text:`late`}],contentFrames:[{type:`content`,content:{type:`text`,text:`late`}}]})]},{name:`ptc-run-code-lifecycle`,events:[V(`turn/start`,{turn:1}),V(`tool/call`,{turn:1,step:1,callId:`rc1`,name:`run_code`,arguments:`{"code":"return await tools.read({ file_path: 'a.ts' })","description":"Scan repo\\nfor TODOs"}`}),V(`tool/ptc-dispatch-start`,{turn:1,step:1,rootCallId:`rc1`,parentCallId:`rc1`,subCallId:`rc1:ptc:1`,name:`read`,arguments:{file_path:`a.ts`}}),V(`tool/ptc-dispatch`,{turn:1,step:1,rootCallId:`rc1`,parentCallId:`rc1`,subCallId:`rc1:ptc:1`,name:`read`,arguments:{file_path:`a.ts`},isError:!1,content:[{type:`text`,text:`export {}
11
+ `}]}),V(`tool/result`,{turn:1,step:1,message:{toolCallId:`rc1`,role:`tool`,content:[{type:`text`,text:`done`}]}}),V(`turn/end`,{turn:1,reason:{kind:`completed`}})],expectedLive:[J(`rc1`,`Scan repo for TODOs`,`other`,{code:`return await tools.read({ file_path: 'a.ts' })`,description:`Scan repo
12
+ for TODOs`},[],`run_code`),q(J(`rc1:ptc:1`,`Read a.ts`,`read`,{file_path:`a.ts`},[],`read`),`rc1`),q(Y(`rc1:ptc:1`,`completed`,`Read a.ts`,`read`,[],{file_path:`a.ts`},{name:`read`,content:[{type:`text`,text:`export {}
13
+ `}],contentFrames:[{type:`content`,content:{type:`text`,text:`export {}
14
+ `}}]}),`rc1`),Y(`rc1`,`completed`,`Scan repo for TODOs`,`other`,[],{code:`return await tools.read({ file_path: 'a.ts' })`,description:`Scan repo
15
+ for TODOs`},{name:`run_code`,content:[{type:`text`,text:`done`}],contentFrames:[{type:`content`,content:{type:`text`,text:`done`}}]})],expectedDerived:[]},{name:`ptc-dispatch-failed`,events:[V(`tool/ptc-dispatch-start`,{parentCallId:`rc2`,rootCallId:`rc2`,subCallId:`rc2:ptc:1`,name:`read`,arguments:{file_path:`a.ts`}}),V(`tool/ptc-dispatch`,{parentCallId:`rc2`,rootCallId:`rc2`,subCallId:`rc2:ptc:1`,name:`read`,arguments:{file_path:`a.ts`},isError:!0,content:[{type:`text`,text:`missing`}],error:{name:`ReadError`,code:`ENOENT`}})],expectedLive:[q(J(`rc2:ptc:1`,`Read a.ts`,`read`,{file_path:`a.ts`},[],`read`),`rc2`),q(Y(`rc2:ptc:1`,`failed`,`Read a.ts`,`read`,[],{file_path:`a.ts`},{name:`read`,content:[{type:`text`,text:`missing`}],contentFrames:[{type:`content`,content:{type:`text`,text:`missing`}}],error:{name:`ReadError`,code:`ENOENT`}}),`rc2`)]},{name:`ptc-dispatch-diff`,cwd:`/w`,events:[V(`tool/ptc-dispatch-start`,{parentCallId:`rc3`,rootCallId:`rc3`,subCallId:`rc3:ptc:1`,name:`write`,arguments:{file_path:`src/x.ts`,content:`x`}}),V(`tool/ptc-dispatch`,{parentCallId:`rc3`,rootCallId:`rc3`,subCallId:`rc3:ptc:1`,name:`write`,arguments:{file_path:`src/x.ts`,content:`x`},isError:!1,content:[{type:`text`,text:`Created file`}],meta:{operation:`create`,path:`/w/src/x.ts`,diffs:[]}})],expectedLive:[q(J(`rc3:ptc:1`,`Write src/x.ts`,`edit`,{file_path:`src/x.ts`,content:`x`},[{path:`/w/src/x.ts`,line:null}],`write`),`rc3`),q(Y(`rc3:ptc:1`,`completed`,`Write src/x.ts (created)`,`edit`,[{path:`/w/src/x.ts`,line:null}],{file_path:`src/x.ts`,content:`x`},{name:`write`,meta:{operation:`create`,path:`/w/src/x.ts`,diffs:[]},content:[{type:`text`,text:`Created file`}],contentFrames:[{type:`diff`,path:`/w/src/x.ts`,oldText:null,newText:`x`},{type:`content`,content:{type:`text`,text:`Created file`}}]}),`rc3`)]},{name:`ptc-dispatch-no-start`,events:[V(`tool/ptc-dispatch`,{parentCallId:`rc4`,rootCallId:`rc4`,subCallId:`rc4:ptc:9`,name:`grep`,arguments:{pattern:`x`},isError:!1,content:[{type:`text`,text:`ok`}]})],expectedLive:[q(Y(`rc4:ptc:9`,`completed`,`Grep "x"`,`search`,[],{pattern:`x`},{name:`grep`,content:[{type:`text`,text:`ok`}],contentFrames:[{type:`content`,content:{type:`text`,text:`ok`}}]}),`rc4`)]},{name:`ptc-dispatch-derived-failed`,events:[V(`turn/start`,{turn:1}),V(`tool/ptc-dispatch-start`,{parentCallId:`rc5`,rootCallId:`rc5`,subCallId:`rc5:ptc:1`,name:`read`,arguments:{file_path:`a.ts`}}),V(`turn/end`,{turn:1,reason:{kind:`error`}})],expectedLive:[q(J(`rc5:ptc:1`,`Read a.ts`,`read`,{file_path:`a.ts`},[],`read`),`rc5`)],expectedDerived:[{sessionUpdate:`tool_call_update`,toolCallId:`rc5:ptc:1`,status:`failed`,_meta:{derived:!0}}]},{name:`plan-todo-write`,events:[V(`todo/write`,{todos:[{content:`a`,status:`completed`},{content:`b`,status:`in_progress`},{content:`c`,status:`pending`}]})],expectedLive:[{sessionUpdate:`plan`,entries:[{content:`a`,status:`completed`},{content:`b`,status:`in_progress`},{content:`c`,status:`pending`}]}]},{name:`session-info-title`,events:[V(`session/title`,{title:`Fix bug`,messageSeqs:[1],source:{kind:`provider`,provider:`p`}})],expectedLive:[{sessionUpdate:`session_info_update`,title:`Fix bug`,updatedAt:new Date(17e11).toISOString(),_meta:{openacpagent:{titleSource:`provider`}}}]},{name:`command-projection`,events:[V(`command/run`,{commandId:`cmd1`,name:`compact`,source:{kind:`user`}}),V(`command/done`,{commandId:`cmd1`,kind:`success`,text:`compacted`,sourceEventSeq:9})],expectedLive:[U(`/compact`,`cmd1`),Fe(W(`compacted`,`cmd1`),{openacpagent:{sourceEventSeq:9}})]},{name:`command-echo-record-input-false`,events:[V(`command/run`,{commandId:`cmd2`,name:`feedback`,source:{kind:`user`}})],expectedLive:[U(`/feedback`,`cmd2`)]},{name:`stream-frame-boundaries`,events:[],streamFrames:[{type:`start`,attemptId:`att1`},{type:`chunk`,attemptId:`att1`,chunk:{type:`text-delta`,text:`he`}},{type:`chunk`,attemptId:`att1`,chunk:{type:`reasoning-delta`,text:`think`}},{type:`chunk`,attemptId:`att1`,chunk:{type:`tool-call-delta`}},{type:`end`,attemptId:`att1`,index:2,outcome:{kind:`committed`,eventType:`assistant/message`,seq:5}}],expectedLive:[W(`he`,`att1`),G(`think`,`att1`)],expectedReplay:[]},{name:`stream-durable-merged`,events:[V(`assistant/message`,{turn:1,step:1,message:{id:`msg-merged`,role:`assistant`,content:[{type:`reasoning`,text:`think`},{type:`text`,text:`Hello`}],source:{kind:`model`,provider:`echo`,model:`echo`}},stream:[],usage:{inputTokens:1,outputTokens:1}})],streamFrames:[{type:`start`,attemptId:`att-merged`,revision:1,turn:1,step:1},{type:`chunk`,attemptId:`att-merged`,revision:2,index:0,time:0,chunk:{type:`reasoning-delta`,text:`thi`}},{type:`chunk`,attemptId:`att-merged`,revision:3,index:1,time:1,chunk:{type:`text-delta`,text:`Hel`}}],expectedLive:[G(`thi`,`att-merged`),W(`Hel`,`att-merged`),G(`nk`,`att-merged`),W(`lo`,`att-merged`),K(2,0,0)],expectedReplay:[G(`think`,`msg-merged`),W(`Hello`,`msg-merged`),K(2,0,0)]},{name:`surface-replace-folded`,events:[V(`user/message`,{...H,id:`msg-ck`,content:[{type:`text`,text:`compacted summary`}]},{surfaceOp:{op:`replace`,startSeq:1,endSeq:3}})],expectedLive:[U(`compacted summary`,`msg-ck`)]},{name:`unknown-fallback-graded`,events:[V(`llm/retry`,{attempt:1},{ignorable:!0}),V(`brand-new-event`,{x:1})],expectedLive:[],expectedUnknown:[[`llm/retry`,`debug`],[`brand-new-event`,`warn`]]},{name:`skip-classified-silent`,events:[V(`sandbox/mode`,{mode:`read-only`}),V(`permission/preset`,{preset:`auto`}),V(`model/selection`,{provider:`p`,model:`m`}),V(`subagent/descriptor`,{childId:`c`}),V(`goal/change`,{kind:`goal/change`,version:1,operation:`create`})],expectedLive:[],expectedUnknown:[]}];function U(e,t){return{sessionUpdate:`user_message_chunk`,content:{type:`text`,text:e},messageId:t}}function W(e,t){return{sessionUpdate:`agent_message_chunk`,content:{type:`text`,text:e},messageId:t}}function G(e,t){return{sessionUpdate:`agent_thought_chunk`,content:{type:`text`,text:e},messageId:t}}function K(e,t,n){return{sessionUpdate:`usage_update`,used:e,size:2e5,_meta:{openacpagent:{usage:{cacheReadTokens:t,cacheWriteTokens:n}}}}}function Fe(e,t){return{...e,_meta:t}}function Ie(e){return{tboxcode:{ptc:{parentToolCallId:e}}}}function q(e,t){return{...e,_meta:{...e._meta??{},...Ie(t)}}}function J(e,t,n,r,i=[],a){return{sessionUpdate:`tool_call`,toolCallId:e,...a===void 0?{}:{name:a},title:t,kind:n,status:`pending`,locations:i,rawInput:r}}function Y(e,t,n,r,i,a,o){return{sessionUpdate:`tool_call_update`,toolCallId:e,...o.name===void 0?{}:{name:o.name},status:t,title:n,kind:r,locations:i,rawInput:a,rawOutput:{content:o.content??[],meta:o.meta,error:o.error},...o.contentFrames&&o.contentFrames.length>0?{content:o.contentFrames}:{},...o.meta!==void 0&&o.meta!==null?{_meta:{openacpagent:{toolMeta:o.meta}}}:{}}}const X=/^\/([a-z][a-z0-9_-]*)(?=$|[\s])/u,Z=new Set([`plan`,`permission`,`export`]),Le={plan:`mode 单一真源 = configOption 通道(死防御——组合挂回 plan-mode 插件时已正确)`,permission:`权限档单一真源 = configOption 通道(dsh /permission 是会话中切档唯一写路径,投影制造第二写入口)`,export:`产物走 web 认证 GET 路由,ACP 客户端不可达`};function Re(e){let t=e?.trim()??``,n=X.exec(t);if(n===null)return{hit:!1,name:``,shadow:!1};let r=n[1]??``;return{hit:!0,name:r,shadow:Z.has(r)}}function ze(e){return e.kind===`aborted`?{stopReason:`cancelled`}:{stopReason:`end_turn`,usage:{totalTokens:0,inputTokens:0,outputTokens:0}}}function Be(e,t){let n=new Map;for(let t of e){if(Z.has(t.name))continue;let e=t.input?.hint;n.set(t.name,{name:t.name,description:t.description,...e===void 0?{}:{input:{hint:e}}})}for(let e of t)!e.invocation.userInvocable||n.has(e.name)||n.set(e.name,{name:e.name,description:e.description});return[...n.values()].sort((e,t)=>e.name<t.name?-1:e.name>t.name?1:0)}function Ve(e){let t=e.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``);return t===``?`question`:t}function He(e){let t=new Set;return e.map(e=>{let n=Ve(e.header??e.question),r=n,i=2;for(;t.has(r);)r=`${n}-${i}`,i+=1;return t.add(r),r})}function Ue(e){let t=e.options??[],n=e=>({const:e.label,title:e.description===void 0?e.label:`${e.label} — ${e.description}`}),r=e.intent===void 0?void 0:t.find(t=>t.label===e.intent?.approve),i=r===void 0?t:t.filter(e=>e!==r);return[...r===void 0?[]:[n(r)],...i.map(n),{const:`__custom__`,title:`Other — type your own answer below`}]}function We(e){let t=He(e),n={},r=[];return e.forEach((e,i)=>{let a=t[i]??`question-${i}`,o=e.detail===void 0?e.question:`${e.question}\n\n${e.detail}`;if(e.options!==void 0&&e.options.length>0){let t=Ue(e);n[a]=e.multiSelect===!0?{type:`array`,title:e.header??e.question,description:o,minItems:1,items:{anyOf:t}}:{type:`string`,title:e.header??e.question,description:o,oneOf:t}}else n[a]={type:`string`,title:e.header??e.question,description:o};n[`${a}_customText`]={type:`string`,title:`Custom answer`},r.push(a)}),{type:`object`,properties:n,required:r}}function Q(e,t){return t.has(e)}function Ge(e,t){let n=He(e);return{answers:e.map((e,r)=>{let i=n[r]??`question-${r}`,a=t[i];if(a===void 0)throw Error(`elicitation content missing property: ${i}`);let o=new Set((e.options??[]).map(e=>e.label));if(e.options!==void 0&&e.options.length>0&&e.multiSelect===!0){if(!Array.isArray(a)||a.some(e=>typeof e!=`string`))throw Error(`elicitation content property is not a string array: ${i}`);let t=a.filter(e=>Q(e,o)),n=a.filter(e=>!Q(e,o));return{id:e.id,selected:t,...n.length===0?{}:{custom:n.join(`
16
+ `)}}}if(typeof a!=`string`)throw Error(`elicitation content property is not a string: ${i}`);return e.options===void 0||e.options.length===0?{id:e.id,selected:[],...a===``?{}:{custom:a}}:Q(a,o)?{id:e.id,selected:[a]}:{id:e.id,selected:[],custom:a}})}}const Ke=`mode`,qe=`model`,Je=`reasoning_effort`,Ye=``,$={build:{sandbox:`danger-full-access`,approval:`never`},plan:{sandbox:`read-only`,approval:`ask`}},Xe={build:`build`,plan:`plan`},Ze=[`build`,`plan`];function Qe(e){return e in $}function $e(e){return Qe(e)?$[e]:void 0}function et(e){return e===`read-only`?`plan`:`build`}function tt(e){return{id:Ke,name:`Mode`,category:`mode`,type:`select`,currentValue:e,options:Ze.map(e=>({value:e,name:Xe[e]}))}}function nt(e,t){return JSON.stringify([e,t])}export{X as COMMAND_GATE_PATTERN,w as LATEST_PROTOCOL_VERSION,o as LOCATIONS_ALLOWED,qe as MODEL_CONFIG_ID,Ke as MODE_CONFIG_ID,$ as MODE_TABLE,C as PROTOCOL_VERSIONS,Ye as PROVIDER_DEFAULT_REASONING_VALUE,Je as REASONING_CONFIG_ID,x as RpcErrorCode,Z as SHADOW_COMMANDS,Le as SHADOW_COMMANDS_RATIONALE,Oe as StreamAttemptState,se as SubagentCatalogState,g as TOOL_TITLE_BUILDERS,oe as ToolJournal,De as TurnFoldTracker,Pe as WIRE_FIXTURES,f as absolutize,ae as agentCapabilities,We as buildElicitationSchema,v as buildToolResultTitle,_ as buildToolTitle,r as classify,Re as commandGate,Be as commandsProjection,Qe as isAcpSessionMode,i as isIgnorable,h as locationsForResult,ne as mapRpcError,tt as modeConfigOption,et as modeFromSandbox,ie as negotiateProtocolVersion,Ge as parseElicitationContent,b as parseToolArguments,d as pickNew,u as pickOld,l as pickPath,we as projectEvent,Te as projectRecord,Ee as projectStreamFrame,ye as projectSubagentChildEvent,nt as resolveModelValue,ze as settleToResponse,Ve as slugifyQuestion,re as stopReasonFromTurnEnd,m as toLocations,s as toolKind,$e as translateMode,y as withSubagentPrefix};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tbox.cn/dsh-acp-bridge-core",
3
- "version": "0.1.0-rc.13",
3
+ "version": "0.1.0-rc.14",
4
4
  "type": "module",
5
5
  "description": "纯函数翻译核心:dsh 事件 → ACP update 投影、错误码映射、模式表、命令判定(运行时零依赖)",
6
6
  "main": "./lib/index.js",
@@ -10,20 +10,22 @@
10
10
  ],
11
11
  "devDependencies": {
12
12
  "@agentclientprotocol/sdk": "1.8.0",
13
- "@deepseek-ai/dsh-api-session-controller": "0.2.1-rc.2",
14
- "@deepseek-ai/dsh-commands": "0.2.1-rc.2",
15
- "@deepseek-ai/dsh-goal": "0.2.1-rc.2",
16
- "@deepseek-ai/dsh-llm": "0.2.1-rc.2",
17
- "@deepseek-ai/dsh-permission-presets": "0.2.1-rc.2",
18
- "@deepseek-ai/dsh-sandbox": "0.2.1-rc.2",
19
- "@deepseek-ai/dsh-session": "0.2.1-rc.2",
20
- "@deepseek-ai/dsh-session-title": "0.2.1-rc.2",
21
- "@deepseek-ai/dsh-subagent": "0.2.1-rc.2",
22
- "@deepseek-ai/dsh-tool-todo": "0.2.1-rc.2",
23
- "@deepseek-ai/dsh-user-approval": "0.2.1-rc.2",
24
- "@deepseek-ai/dsh-user-questions": "0.2.1-rc.2",
13
+ "@deepseek-ai/dsh-agent-preset-registry": "0.2.2-rc.1",
14
+ "@deepseek-ai/dsh-api-session-controller": "0.2.2-rc.1",
15
+ "@deepseek-ai/dsh-commands": "0.2.2-rc.1",
16
+ "@deepseek-ai/dsh-goal": "0.2.2-rc.1",
17
+ "@deepseek-ai/dsh-llm": "0.2.2-rc.1",
18
+ "@deepseek-ai/dsh-permission-presets": "0.2.2-rc.1",
19
+ "@deepseek-ai/dsh-sandbox": "0.2.2-rc.1",
20
+ "@deepseek-ai/dsh-session": "0.2.2-rc.1",
21
+ "@deepseek-ai/dsh-session-title": "0.2.2-rc.1",
22
+ "@deepseek-ai/dsh-subagent": "0.2.2-rc.1",
23
+ "@deepseek-ai/dsh-tool-todo": "0.2.2-rc.1",
24
+ "@deepseek-ai/dsh-user-approval": "0.2.2-rc.1",
25
+ "@deepseek-ai/dsh-user-questions": "0.2.2-rc.1",
25
26
  "zod": "4.6.7",
26
- "@deepseek-ai/dsh-sandbox-policy": "0.2.1-rc.2"
27
+ "@deepseek-ai/dsh-sandbox-policy": "0.2.2-rc.1",
28
+ "@deepseek-ai/dsh-tool-executor-ptc": "0.2.2-rc.1"
27
29
  },
28
30
  "scripts": {
29
31
  "build": "tsdown",