aws-runtime-bridge 1.9.170 → 1.9.172

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/CHANGELOG.md +83 -0
  2. package/dist/adapter/AcodeSdkAdapter.d.ts +6 -12
  3. package/dist/adapter/AcodeSdkAdapter.js +3 -3
  4. package/dist/adapter/ClaudeSdkAdapter.d.ts +2 -0
  5. package/dist/adapter/ClaudeSdkAdapter.js +3 -3
  6. package/dist/adapter/types.d.ts +4 -7
  7. package/dist/index.js +1 -1
  8. package/dist/routes/terminal.d.ts +8 -0
  9. package/dist/routes/terminal.js +27 -33
  10. package/dist/services/agent-startup-memory.d.ts +11 -0
  11. package/dist/services/agent-startup-memory.js +8 -0
  12. package/dist/services/log-retention.d.ts +37 -0
  13. package/dist/services/log-retention.js +2 -0
  14. package/dist/services/request-invalid-dump.d.ts +21 -0
  15. package/dist/services/request-invalid-dump.js +2 -0
  16. package/dist/services/session-output.d.ts +2 -0
  17. package/dist/services/session-output.js +2 -2
  18. package/dist/utils/lifecycle-log.d.ts +2 -0
  19. package/dist/utils/lifecycle-log.js +2 -2
  20. package/package/acode/dist/ask-user-question-tool.d.ts +11 -1
  21. package/package/acode/dist/ask-user-question-tool.js +3 -3
  22. package/package/acode/dist/built-in-file-tools.js +2 -2
  23. package/package/acode/dist/compaction.d.ts +143 -31
  24. package/package/acode/dist/compaction.js +20 -6
  25. package/package/acode/dist/image-utils.js +1 -1
  26. package/package/acode/dist/runtime-environment.js +1 -1
  27. package/package/acode/dist/runtime.d.ts +13 -4
  28. package/package/acode/dist/runtime.js +31 -28
  29. package/package/acode/dist/types.d.ts +1 -1
  30. package/package/aws-client-agent-mcp/dist/agent-client.d.ts +2 -0
  31. package/package/aws-client-agent-mcp/dist/agent-client.js +1 -1
  32. package/package/aws-client-agent-mcp/dist/mcp-server.js +1 -1
  33. package/package/aws-client-agent-mcp/dist/mcp-tools.d.ts +4 -0
  34. package/package/aws-client-agent-mcp/dist/mcp-tools.js +32 -18
  35. package/package/aws-client-agent-mcp/dist/status-reporter.js +1 -1
  36. package/package/aws-client-agent-mcp/dist/tool-groups.js +2 -2
  37. package/package/aws-client-agent-mcp/dist/types.d.ts +15 -1
  38. package/package.json +1 -1
@@ -1,7 +1,21 @@
1
- const dt=2e4,pt=.55,q=[[32e3,.7],[128e3,.75],[512e3,.8],[Number.POSITIVE_INFINITY,.85]];function C(t){if(t<=0)return .55;for(const[e,n]of q)if(t<e)return n;return .85}const V=4e4,Y=2e4,Q=.5,Z=.1,w=new Set(["skill","todo_write","todo_read"]),tt=["fileReads","fileEdits","otherTools","commands","browser"];function L(t){const e=b(t);return e<=0?"fileReads":e===1?"fileEdits":e===3?"commands":e>=4?"browser":"otherTools"}function ht(t){const e=Object.fromEntries(tt.map(o=>[o,{messages:0,tokens:0}]));for(let o=0;o<t.length;o++){const s=t[o];if(!z(s))continue;const l=v(s,t,o);if(l&&w.has(l))continue;const r=typeof s.content=="string"?s.content:"";if(r==="[Old tool result content cleared]")continue;const u=e[L(l??"")];u.messages+=1,u.tokens+=y(r)}const n=t.filter(o=>o.role!=="system").length;return{categories:e,summarizableMessages:Math.max(0,n-G),totalTokens:O(t)}}const g={read_file:0,Read:0,grep:0,Grep:0,glob:0,Glob:0,"contextweaver_codebase-retrieval":0,Edit:1,edit:1,Write:1,write:1,write_file:1,webfetch:2,WebFetch:2,WebSearch:2,websearch_web_search_exa:2,bash:3,Bash:3,run_terminal_command:3,playwright_browser_:4},A=2;function b(t){if(!t)return A;if(g[t]!==void 0)return g[t];const e=Object.keys(g).filter(n=>t.startsWith(n)).sort((n,o)=>o.length-n.length);return e.length>0?g[e[0]]:A}const I=128e3,k=8192,G=8,et=6e3,K=500,P="ACode context compaction summary:",nt="ACode runtime resources:",xt=["Please summarize the conversation above using the following structured format.","Keep each section concise but preserve all actionable details.","Omit any section that has no relevant content.","","## Goal","The user's primary objective in this conversation (1-2 sentences).","","## Known Facts","Key facts already established: decisions, findings, errors, constraints, and user-stated preferences.","","## Done","Tasks that have been completed (do not redo these).","","## In Progress","What is currently being worked on but not yet finished: which step it stopped at and any partial results.","","## Next Steps","The immediate next actions to take to continue the work.","","## Files","Files read, modified, or created with brief context.","","Output only the summary, no preamble."].join(`
2
- `),ot=1.5,N=4,rt=1.15,it=2e3,st=8;function Ot(t,e,n){const o=Math.floor(t*C(t)),s=n??t,l=Math.min(2e4,e),r=s-l;return Math.min(o,r)}function Tt(t,e){const n=e&&e>0?e:t;return n>0?n:t}const E={"claude-4":{contextLimit:2e5,maxOutput:8192},"claude-sonnet-4":{contextLimit:2e5,maxOutput:8192},"claude-3-5-sonnet":{contextLimit:2e5,maxOutput:8192},"claude-3-opus":{contextLimit:2e5,maxOutput:8192},"claude-3-haiku":{contextLimit:2e5,maxOutput:8192},"claude-2":{contextLimit:1e5,maxOutput:4096},"gpt-4o":{contextLimit:128e3,maxOutput:16384},"gpt-4-turbo":{contextLimit:128e3,maxOutput:4096},"gpt-4":{contextLimit:8192,maxOutput:4096},"gpt-3.5-turbo":{contextLimit:16384,maxOutput:4096},o1:{contextLimit:2e5,maxOutput:1e5},"o3-mini":{contextLimit:2e5,maxOutput:1e5},"gemini-2.0-flash":{contextLimit:1048576,maxOutput:8192},"gemini-2.5-pro":{contextLimit:1048576,maxOutput:8192},"gemini-1.5-pro":{contextLimit:2097152,maxOutput:8192},"gemini-1.5-flash":{contextLimit:1048576,maxOutput:8192},deepseek:{contextLimit:64e3,maxOutput:8192},"deepseek-chat":{contextLimit:64e3,maxOutput:8192},"deepseek-reasoner":{contextLimit:64e3,maxOutput:8192},"qwen-max":{contextLimit:32e3,maxOutput:8192},"qwen-plus":{contextLimit:128e3,maxOutput:8192},"qwen-turbo":{contextLimit:1e6,maxOutput:8192},"glm-4":{contextLimit:128e3,maxOutput:4096},"yi-":{contextLimit:2e5,maxOutput:4096},"llama-3":{contextLimit:8192,maxOutput:4096},"llama-2":{contextLimit:4096,maxOutput:4096},mistral:{contextLimit:32e3,maxOutput:4096},mixtral:{contextLimit:32e3,maxOutput:4096},codestral:{contextLimit:256e3,maxOutput:8192},grok:{contextLimit:131072,maxOutput:4096},"nova-":{contextLimit:2e5,maxOutput:8192}};function yt(t,e){if(e?.contextLimit&&e.contextLimit>0)return{contextLimit:e.contextLimit,maxOutput:e.maxOutput??k};if(!t)return{contextLimit:I,maxOutput:k};const n=t.toLowerCase().trim();if(E[n])return E[n];const o=Object.keys(E).filter(s=>n.startsWith(s)).sort((s,l)=>l.length-s.length);return o.length>0?E[o[0]]:{contextLimit:I,maxOutput:k}}function lt(t){if(!t)return 0;let e=0,n=0;for(const o of t)o>"\xFF"?e++:n++;return Math.ceil(e/ot+n/N)}function y(t){return t?Math.ceil(lt(t)*rt):0}function ct(t){if(typeof t=="object"&&t!==null){const e=t;return e.type==="text"&&typeof e.text=="string"?y(e.text):e.type==="image_url"||e.type==="document"?it:Math.ceil(JSON.stringify(t).length/N)}return typeof t=="string"?y(t):0}function S(t){return Buffer.byteLength(t,"utf8")}function W(t){let e=16;if(typeof t.content=="string")e+=S(t.content);else if(Array.isArray(t.content))for(const n of t.content)typeof n=="object"&&n!==null&&(e+=S(JSON.stringify(n)));return t.tool_calls&&(e+=S(JSON.stringify(t.tool_calls))),t.tool_call_id&&(e+=S(t.tool_call_id)),e}function Mt(t){let e=0;for(const n of t)e+=W(n);return e}function O(t){let e=0;for(const n of t){if(typeof n.content=="string")e+=y(n.content);else if(Array.isArray(n.content))for(const o of n.content)e+=ct(o);n.tool_calls&&(e+=st+Math.ceil(JSON.stringify(n.tool_calls).length/N))}return e}function D(t){let e=0;for(const n of t)e+=W(n);return Math.round(e/1024*10)/10}function Ct(t,e,n){if(e<=0)return!1;const o=O(t),s=Math.floor(e*C(e));return o>=s}function gt(t,e,n){if(n<=0)return!1;const o=t+e,s=Math.floor(n*C(n));return o>=s}function z(t){return t.role==="tool"}function v(t,e,n){if(!(t.role!=="tool"||!t.tool_call_id))for(let o=n-1;o>=0;o--){const s=e[o];if(s&&s.role==="assistant"&&Array.isArray(s.tool_calls)){for(const l of s.tool_calls)if(typeof l=="object"&&l!==null&&"id"in l&&l.id===t.tool_call_id){const r=l.function;return r?String(r.name??""):void 0}}}}function at(t,e=I,n){if(t.length===0)return{prunedCount:0,freedTokens:0};const o=n?.categories===void 0?null:new Set(n.categories);if(o&&o.size===0)return{prunedCount:0,freedTokens:0};const s=Math.min(V,Math.floor(e*Q)),l=Math.min(Y,Math.floor(e*Z));let r=0;const u=[],_=[];let h=0;for(let f=t.length-1;f>=0;f--){const i=t[f];if(i.role==="user"&&h++,h<2||!z(i))continue;const a=v(i,t,f);if(a&&w.has(a)||o&&!o.has(L(a??"")))continue;const p=typeof i.content=="string"?i.content:"",d=y(p);if(r+=d,r>s){const x=a?b(a):A,T={msg:i,tokens:d,name:a??""};x<=1?_.push(T):u.push(T)}}if(u.sort((f,i)=>i.tokens-f.tokens),_.sort((f,i)=>f.tokens-i.tokens),n?.manual){const f=new Set([...u.map(i=>i.msg),..._.map(i=>i.msg)]);for(let i=t.length-1;i>=0;i--){const a=t[i];if(!z(a)||f.has(a))continue;const p=v(a,t,i);if(p&&w.has(p)||o&&!o.has(L(p??"")))continue;const d=typeof a.content=="string"?a.content:"";if(d==="[Old tool result content cleared]")continue;const x={msg:a,tokens:y(d),name:p??""};(p?b(p):A)<=1?_.push(x):u.push(x)}_.sort((i,a)=>i.tokens-a.tokens)}const c=[];let m=0;for(const f of u){if(!n?.manual&&m>=l)break;m+=f.tokens,c.push(f.msg)}if(n?.manual||m<l){for(const f of _)if(m+=f.tokens,c.push(f.msg),!n?.manual&&m>=l)break}if(!n?.manual&&m<l)return{prunedCount:0,freedTokens:0};for(const f of c)f.content="[Old tool result content cleared]";return{prunedCount:c.length,freedTokens:m}}function $(t){return t.role==="system"&&typeof t.content=="string"&&t.content.startsWith(P)}function ut(t){return t.role==="system"&&typeof t.content=="string"&&t.content.startsWith(nt)}function X(t,e){const n=typeof t.content=="string"?t.content:Array.isArray(t.content)?t.content.map(l=>typeof l=="object"&&l!==null?JSON.stringify(l):String(l)).join(" "):"",o=n.length>K?`${n.slice(0,K)}\u2026`:n,s=[`${e+1}. ${t.role}`];if(t.tool_calls&&Array.isArray(t.tool_calls)&&t.tool_calls.length>0){const l=t.tool_calls.map(r=>{if(typeof r=="object"&&r!==null){const u=r.function;return u?String(u.name??""):""}return""}).filter(Boolean).join(", ");l&&s.push(`tool_calls=${l}`)}return t.tool_call_id&&s.push(`tool_call_id=${t.tool_call_id}`),o&&s.push(`content=${o}`),s.join(" | ")}async function ft(t,e){const n=t.filter(c=>c.role==="system"&&!$(c)&&!ut(c)),o=t.filter(c=>c.role!=="system"||$(c)),s=Math.max(0,o.length-G);if(s===0)return 0;const l=o.slice(0,s);let r=o.slice(s);const u=new Set;for(const c of r)if(c.role==="assistant"&&c.tool_calls?.length)for(const m of c.tool_calls)typeof m=="object"&&m!==null&&typeof m.id=="string"&&u.add(m.id);r=r.filter(c=>{if(c.role==="tool"){const m=typeof c.tool_call_id=="string"?c.tool_call_id.trim():"";return m!==""&&u.has(m)}return!0});let _=!0;for(;_;){_=!1;const c=new Set;for(const i of r)if(i.role==="assistant"&&i.tool_calls?.length)for(const a of i.tool_calls)typeof a=="object"&&a!==null&&typeof a.id=="string"&&c.add(a.id);const m=new Set;for(const i of r)i.role==="tool"&&i.tool_call_id&&m.add(i.tool_call_id);const f=r.filter(i=>{if(i.role==="tool"){const a=typeof i.tool_call_id=="string"?i.tool_call_id.trim():"";return a!==""&&c.has(a)}if(i.role==="assistant"&&i.tool_calls?.length){const a=new Set;for(const d of i.tool_calls)typeof d=="object"&&d!==null&&typeof d.id=="string"&&a.add(d.id);if(a.size===0)return!0;let p=!0;for(const d of a)if(!m.has(d)){p=!1;break}return p}return!0});f.length!==r.length&&(_=!0,r=f)}if(r.length===0)return 0;let h=null;if(e?.llmSummarizer)try{const c=l.map((m,f)=>X(m,f)).join(`
3
- `);h=await e.llmSummarizer({conversationText:c,messageCount:s,contextLimit:e.contextLimit??I})}catch{h=null}if(t.length=0,t.push(...n),h!==null)t.push({role:"system",content:[P,`${s} earlier conversation messages were summarized by LLM to free context space.`,"Preserve the user's goal, known facts, completed work, in-progress work, next steps, file paths, and errors from this summary.","Continue from where the work left off \u2014 do not redo completed tasks.","Recent messages below remain authoritative.","",h].join(`
4
- `)});else{const m=l.map((f,i)=>X(f,i)).join(`
5
- `).slice(0,et);t.push({role:"system",content:[P,`${s} earlier conversation messages were summarized to free context space.`,"Preserve the user's goal, known facts, completed work, in-progress work, next steps, file paths, and errors from this summary.","Continue from where the work left off \u2014 do not redo completed tasks.","Recent messages below remain authoritative.","",m].join(`
6
- `)})}return t.push(...r),s}function mt(t){if(t.length<=1)return 0;let e=0;for(;e<t.length&&t[e].role==="system";)e++;if(e>=t.length)return 0;let n=t.length;for(let r=e+1;r<t.length;r++)if(t[r].role==="user"){n=r;break}if(n>=t.length)return 0;const o=new Set;for(let r=e;r<n;r++){const u=t[r];if(u.role==="assistant"&&Array.isArray(u.tool_calls))for(const _ of u.tool_calls)typeof _=="object"&&_!==null&&typeof _.id=="string"&&o.add(_.id)}const s=n-e;t.splice(e,s);let l=0;for(let r=t.length-1;r>=e;r--){const u=t[r];if(u.role!=="tool")continue;const _=typeof u.tool_call_id=="string"?u.tool_call_id.trim():"";(_===""||o.has(_))&&(t.splice(r,1),l++)}return s+l}async function At(t,e,n=k,o){const s=D(t),l=t.length,r=O(t);let u="none",_=0,h=0,c=0,m=!1;const f=o?.plan,i=f!==void 0,a=f?.pruneCategories,p=!i||a!==void 0&&a.length>0,d=!i||f?.summarize===!0;o?.onPhase&&o.onPhase({phase:"prune_start",messageCount:t.length});const x=p?at(t,e,{categories:a,manual:i}):{prunedCount:0,freedTokens:0};x.prunedCount>0&&(u="prune",_=x.prunedCount,c+=x.freedTokens),o?.onPhase&&o.onPhase({phase:"prune_end",prunedCount:x.prunedCount,freedTokens:x.freedTokens});const T=O(t),J=o?.actualUsedTokens?Math.max(T,Math.max(o.actualUsedTokens,r)-c):T;if(d&&(o?.force===!0||J>=Math.floor(e*C(e)))){o?.onPhase&&o.onPhase({phase:"summarize_start",messageCount:t.length});const B=await ft(t,{llmSummarizer:o?.llmSummarizer,contextLimit:e});if(B>0){u=u==="prune"?"prune+summarize":"summarize",h=B;const M=O(t);c=Math.max(c,r-M),m=!!t.find(R=>R.role==="system"&&typeof R.content=="string"&&R.content.includes("summarized by LLM"))}else{const M=mt(t);if(M>0){u=u==="prune"?"prune+summarize":"summarize",h=M;const F=O(t);c=Math.max(c,r-F)}}o?.onPhase&&o.onPhase({phase:"summarize_end",summarizedCount:h,usedLLM:m})}const H=D(t),U=t.length,j=O(t);return u==="none"?{strategy:"none",freedTokens:0,sizeBeforeKB:s,sizeAfterKB:s,tokensBefore:r,tokensAfter:j,messageCountBefore:l,messageCountAfter:U,prunedToolMessages:0,summarizedMessages:0}:{strategy:u,freedTokens:c,sizeBeforeKB:s,sizeAfterKB:H,tokensBefore:r,tokensAfter:j,messageCountBefore:l,messageCountAfter:U,prunedToolMessages:_,summarizedMessages:h}}export{dt as COMPACTION_BUFFER,xt as COMPACTION_LLM_PROMPT_TEMPLATE,tt as COMPACTION_PRUNE_CATEGORIES,pt as COMPACTION_TRIGGER_RATIO,Y as PRUNE_MINIMUM,V as PRUNE_PROTECT,nt as RUNTIME_RESOURCES_PREFIX,Ot as calculateCompactionThreshold,Mt as conversationSizeBytes,D as conversationSizeKB,O as estimateConversationTokens,lt as estimateTextTokens,y as estimateTokens,C as getCompactionTriggerRatio,$ as isCompactionSummaryMessage,Ct as isOverflow,gt as isOverflowByActualUsage,ut as isRuntimeResourcesMessage,yt as lookupModelLimits,At as performCompaction,ht as previewCompaction,L as pruneCategoryOf,at as pruneToolOutputs,Tt as resolveReplayWindow,mt as snipOldestMessageGroup,ft as summarizeConversation};
1
+ const ge=2e4,ye=.55,_t=[[32e3,.7],[128e3,.75],[512e3,.8],[Number.POSITIVE_INFINITY,.85]];function D(t){if(t<=0)return .55;for(const[e,n]of _t)if(t<e)return n;return .85}const gt=4e4,yt=2e4,Mt=.5,Tt=.1,ot=new Set(["skill","todo_write","todo_read"]),B={read_file:0,Read:0,grep:0,Grep:0,glob:0,Glob:0,"contextweaver_codebase-retrieval":0,Edit:1,edit:1,Write:1,write:1,write_file:1,webfetch:2,WebFetch:2,WebSearch:2,websearch_web_search_exa:2,bash:3,Bash:3,run_terminal_command:3,playwright_browser_:4},$=2;function rt(t){if(!t)return $;if(B[t]!==void 0)return B[t];const e=Object.keys(B).filter(n=>t.startsWith(n)).sort((n,o)=>o.length-n.length);return e.length>0?B[e[0]]:$}const K=128e3,L=8192,xt=8,At=6e3,Me=500,N="ACode context compaction summary:",St="ACode runtime resources:",wt="[Runtime Instructions]",Te=["Please summarize the conversation above using the following structured format.","Keep each section concise but preserve all actionable details.","Omit any section that has no relevant content.","","## Goal","The user's primary objective in this conversation (1-2 sentences).","","## Known Facts","Key facts already established: decisions, findings, errors, constraints, and user-stated preferences.","","## Done","Tasks that have been completed (do not redo these).","","## In Progress","What is currently being worked on but not yet finished: which step it stopped at and any partial results.","","## Next Steps","The immediate next actions to take to continue the work.","","## Files","Files read, modified, or created with brief context.","","Output only the summary, no preamble."].join(`
2
+ `),Ot=1.5,X=4,Ct=1.15,kt=2e3,Et=8,bt=6e4,Rt=.45,It=.8,Pt=2e3,Lt=.08,Nt=8192,Y=[Number.POSITIVE_INFINITY,32e3,8e3,2e3],st=8,it=2,vt=.85,zt=!1,Ut=.6,v=800,Ft=100,jt=8e3,Dt=1e3,Bt=8e3,$t=1e3,Kt=32e3;class z extends Error{constructor(e){super(`ACode summary input overflow: ${e}`),this.marker=e,this.kind="overflow",this.name="SummaryOverflowError"}}class U extends Error{constructor(e,n){super(`ACode summary unavailable after ${e} attempt(s): ${n.message}`),this.attempts=e,this.lastError=n,this.kind="unavailable",this.name="SummaryUnavailableError"}}function Yt(t,e,n){const o=Math.floor(t*D(t)),r=n??t,s=Math.min(2e4,e),i=r-s;return Math.min(o,i)}function at(t){const{contextLimit:e,maxOutput:n}=t,o=t.inputLimit&&t.inputLimit>0?t.inputLimit:e,r=Math.max(1,o-n),s=Math.max(0,Math.floor(t.toolsTokens??0)),i=t.threshold??Yt(e,n,t.inputLimit),l=Math.max(0,Math.min(bt,Math.floor(r*Rt))),a=Math.max(Pt,Math.floor(r*It)-s),h=Math.max(0,Math.min(Nt,Math.floor(r*Lt))),f=Math.max(0,Math.floor(i*vt));return{contextLimit:e,maxOutput:n,...t.inputLimit&&t.inputLimit>0?{inputLimit:t.inputLimit}:{},usableTokens:r,toolsTokens:s,keepRecentTokens:l,summaryInputBudget:a,summaryMaxTokens:h,targetTokens:f}}function I(t,e){const n=E(t)+e.toolsTokens;return e.targetTokens<=0?!0:n<=e.targetTokens}function xe(t,e){return E(t)+e.toolsTokens<=e.usableTokens}const Ht=[{key:"filePaths",pattern:/(?:[A-Za-z]:[\\/]|\.{1,2}[\\/]|\/)?(?:[\w.@-]{1,120}[\\/]){1,16}[\w.@-]{1,120}\.[A-Za-z0-9]{1,8}\b/g},{key:"commands",pattern:/\b(?:npm|npx|yarn|pnpm|git|docker|kubectl|mvn|gradle|python|python3|node|deno|bun|cargo|go|make|pytest|vitest|tsc)\s+[^\n"'`]{2,120}/g},{key:"errors",pattern:/\b(?:[A-Z][A-Za-z]*(?:Error|Exception)|E[A-Z]{3,})\b[^\n]{0,120}/g},{key:"identifiers",pattern:/\b(?:[A-Z][A-Z0-9_]{2,31}|[a-z][a-z0-9]{0,30}(?:_[a-z0-9]{1,20})+|[a-z][a-z0-9]{0,30}[A-Z][A-Za-z0-9]{0,30})\b/g},{key:"numbers",pattern:/\b\d{2,}(?:\.\d+){0,3}\b/g}],Z=2e4,Wt={filePaths:5,commands:6,errors:8,identifiers:4,numbers:2};function Gt(t){const e={filePaths:new Set,commands:new Set,errors:new Set,identifiers:new Set,numbers:new Set},n=[];for(const o of t)if(o.role!=="system"){if(typeof o.content=="string")n.push(o.content);else if(Array.isArray(o.content)){for(const r of o.content)if(typeof r=="string")n.push(r);else if(r&&typeof r=="object"){const s=r.text;typeof s=="string"&&n.push(s)}}if(o.tool_calls?.length)try{n.push(JSON.stringify(o.tool_calls))}catch{}}for(const o of n){const r=o.length<=Z?o:`${o.slice(0,Z/2)}
3
+ ${o.slice(-Z/2)}`;for(const{key:s,pattern:i}of Ht){i.lastIndex=0;let l;for(;(l=i.exec(r))!==null;){const a=l[0].trim();if(!(a.length<Wt[s])){if(e[s].size>=Ft)break;e[s].add(a)}}i.lastIndex=0}}return{filePaths:[...e.filePaths],commands:[...e.commands],errors:[...e.errors],identifiers:[...e.identifiers],numbers:[...e.numbers]}}function lt(t){return t.filePaths.length===0&&t.commands.length===0&&t.errors.length===0&&t.identifiers.length===0&&t.numbers.length===0}function Ae(t){const e=["The following facts MUST appear verbatim in your summary (exact spelling,","no paraphrasing, no rounding, no path shortening). Include each one that is","relevant to the conversation:"],n=[["File paths",t.filePaths],["Commands",t.commands],["Errors",t.errors],["Identifiers",t.identifiers],["Numbers",t.numbers]];for(const[o,r]of n)if(r.length!==0){e.push("",`${o}:`);for(const s of r)e.push(`- ${s}`)}return e.join(`
4
+ `)}function Xt(t,e){const n={filePaths:[],commands:[],errors:[],identifiers:[],numbers:[]};for(const o of Object.keys(n))for(const r of e[o])t.includes(r)||n[o].push(r);return n}function Zt(t,e){if(lt(e))return t;const n=[t.trimEnd(),"","## Verbatim Anchors","(Facts below were present in the raw conversation and are reproduced verbatim.)"],o=[["File paths",e.filePaths],["Commands",e.commands],["Errors",e.errors],["Identifiers",e.identifiers],["Numbers",e.numbers]];for(const[r,s]of o)if(s.length!==0){n.push("",`${r}:`);for(const i of s)n.push(`- ${i}`)}return n.join(`
5
+ `)}function Jt(t,e,n=!0){return t.map((o,r)=>Q(o,r,e,n)).join(`
6
+ `)}function Vt(t,e,n,o=!0){const r=[];let s=[],i=0;for(let l=0;l<t.length;l++){const a=Q(t[l],l,e,o),h=k(a);s.length>0&&i+h>n&&(r.push(s.join(`
7
+ `)),s=[],i=0),s.push(a),i+=h}return s.length>0&&r.push(s.join(`
8
+ `)),r}function qt(t,e,n=!0){const o=Math.max(1,e.summaryInputBudget),r=["S1","S2","S3","S4"];for(let a=0;a<Y.length;a++){const h=Y[a],f=Jt(t,h,n);if(k(f)<=o)return{step:r[a]??"S4",cap:h,chunks:[f],singleShot:!0}}const s=Y[Y.length-1]??2e3,i=Vt(t,s,Math.floor(o*.9),n),l=i.length<=st?i:Qt(i,st);return{step:"S5",cap:s,chunks:l,singleShot:!1}}function Qt(t,e){const n=Math.max(1,Math.min(e,t.length)),o=[];for(let r=0;r<n;r++){const s=Math.floor(r*t.length/n),i=Math.floor((r+1)*t.length/n);o.push(t.slice(s,Math.max(s+1,i)).join(`
9
+ `))}return o}function te(t){return new Promise(e=>setTimeout(e,t))}function F(t){if(!(t instanceof Error))return!1;if(t.name==="AbortError")return!0;const e=t.message.toLowerCase();return e.includes("aborted by user")||e.includes("summarization aborted")}function ee(t){if(!(t instanceof Error))return!1;const e=t.message.toLowerCase();return/\b(408|429|5\d\d)\b/.test(e)||e.includes("fetch failed")||e.includes("timed out")||e.includes("timeout")||e.includes("econnreset")||e.includes("econnrefused")||e.includes("etimedout")||e.includes("enotfound")||e.includes("socket hang up")||e.includes("network error")||e.includes("empty content")||e.includes("stream response has no body")}async function J(t,e){const n=Math.max(1,Math.floor(e?.maxAttempts??1)),o=e?.baseDelayMs??Dt,r=e?.maxDelayMs??Bt,s=e?.jitterMs??$t;let i=new Error("summarizer was never invoked");for(let l=1;l<=n;l++)try{const a=await t();if(typeof a!="string"||a.trim().length===0)throw new Error("summarizer returned empty content");return{summary:a,attempts:l}}catch(a){if(i=a instanceof Error?a:new Error(String(a)),a instanceof z||F(a))throw i;if(!ee(a)||l>=n)throw new U(l,i);const f=Math.min(r,o*Math.pow(2,l-1));await te(f+Math.random()*s)}throw new U(n,i)}async function ne(t){const{removed:e,budget:n,llmSummarizer:o,anchors:r,previousSummary:s,retryPolicy:i,includeReasoning:l=!0}=t,a=qt(e,n,l),h=lt(r)?void 0:r,f=n.summaryMaxTokens>0?n.summaryMaxTokens:void 0;let p=0;if(a.singleShot){const d=await J(()=>o({conversationText:a.chunks[0],messageCount:e.length,contextLimit:n.contextLimit,...s?{previousSummary:s}:{},...h?{anchors:h}:{},...f?{maxTokens:f}:{}}),i);return{summary:d.summary,step:a.step,chunks:1,attempts:d.attempts}}const m=new Array(a.chunks.length).fill(null);for(let d=0;d<a.chunks.length;d++){if(m[d]!==null)continue;const w=a.chunks[d],c=await J(()=>o({conversationText:w,messageCount:e.length,contextLimit:n.contextLimit,...h?{anchors:h}:{},...f?{maxTokens:f}:{}}),i);m[d]=c.summary,p+=c.attempts}let u=m,_=0;for(;u.length>1&&_<it;){const d=[],c=_===it-1?u.length:Math.max(2,Math.ceil(u.length/4));for(let g=0;g<u.length;g+=c){const b=u.slice(g,g+c),y=b.map((R,C)=>`### Part ${g+C+1}
10
+ ${R}`).join(`
11
+
12
+ `),M=await J(()=>o({conversationText:y,messageCount:b.length,contextLimit:n.contextLimit,...s?{previousSummary:s}:{},...f?{maxTokens:f}:{}}),i);d.push(M.summary),p+=M.attempts}u=d,_+=1}return{summary:u.length===1?u[0]:u.map((d,w)=>`### Part ${w+1}
13
+ ${d}`).join(`
14
+
15
+ `),step:a.step,chunks:a.chunks.length,attempts:p}}function ct(t,e){if(!t||t.length<=e)return t;const n=Math.max(v,Math.floor(e));if(t.length<=n)return t;const o=Math.floor(n*Ut),r=Math.max(0,n-o),s=t.length-o-r;return t.slice(0,o)+`
16
+ \u2026[truncated ${s} chars]\u2026
17
+ `+(r>0?t.slice(-r):"")}function oe(t){return t.role!=="tool"||typeof t.content!="string"||t.content==="[Old tool result content cleared]"?!1:t.content.length>v}function re(t,e){let n=0,o=0;if(e<=0||t.length===0)return{downsampleCount:n,droppedMessages:o};let r=E(t);if(r<=e)return{downsampleCount:n,droppedMessages:o};for(;r>e;){let s=-1,i=0;for(let f=0;f<t.length;f++){const p=t[f];if(!oe(p))continue;const m=p.content.length;m>i&&(i=m,s=f)}if(s<0)break;const l=t[s],a=k(l.content),h=Math.max(v,Math.floor(i/2));l.content=ct(l.content,h),r-=a-k(l.content),n+=1}for(;r>e;){const s=se(t);if(s<=0||t.length-s<1)break;const i=t.slice(0,s);r-=E(i),t.splice(0,s),o+=s}for(;r>e;){let s=-1,i=0;for(let f=0;f<t.length;f++){const p=t[f];typeof p.content=="string"&&(p.content.length<=v||p.content!=="[Old tool result content cleared]"&&p.content.length>i&&(i=p.content.length,s=f))}if(s<0)break;const l=t[s],a=k(l.content),h=Math.max(v,Math.floor(i/2));l.content=ct(l.content,h),r-=a-k(l.content),n+=1}return{downsampleCount:n,droppedMessages:o}}function se(t){if(t.length<=1)return 0;let e=0;for(;e<t.length&&t[e].role==="system";)e+=1;if(e>=t.length)return 0;for(let n=e+1;n<t.length;n++)if(t[n].role==="user")return n-e;return 0}function Se(t,e){const n=e&&e>0?e:t;return n>0?n:t}const H={"claude-4":{contextLimit:2e5,maxOutput:8192},"claude-sonnet-4":{contextLimit:2e5,maxOutput:8192},"claude-3-5-sonnet":{contextLimit:2e5,maxOutput:8192},"claude-3-opus":{contextLimit:2e5,maxOutput:8192},"claude-3-haiku":{contextLimit:2e5,maxOutput:8192},"claude-2":{contextLimit:1e5,maxOutput:4096},"gpt-4o":{contextLimit:128e3,maxOutput:16384},"gpt-4-turbo":{contextLimit:128e3,maxOutput:4096},"gpt-4":{contextLimit:8192,maxOutput:4096},"gpt-3.5-turbo":{contextLimit:16384,maxOutput:4096},o1:{contextLimit:2e5,maxOutput:1e5},"o3-mini":{contextLimit:2e5,maxOutput:1e5},"gemini-2.0-flash":{contextLimit:1048576,maxOutput:8192},"gemini-2.5-pro":{contextLimit:1048576,maxOutput:8192},"gemini-1.5-pro":{contextLimit:2097152,maxOutput:8192},"gemini-1.5-flash":{contextLimit:1048576,maxOutput:8192},deepseek:{contextLimit:64e3,maxOutput:8192},"deepseek-chat":{contextLimit:64e3,maxOutput:8192},"deepseek-reasoner":{contextLimit:64e3,maxOutput:8192},"qwen-max":{contextLimit:32e3,maxOutput:8192},"qwen-plus":{contextLimit:128e3,maxOutput:8192},"qwen-turbo":{contextLimit:1e6,maxOutput:8192},"glm-4":{contextLimit:128e3,maxOutput:4096},"yi-":{contextLimit:2e5,maxOutput:4096},"llama-3":{contextLimit:8192,maxOutput:4096},"llama-2":{contextLimit:4096,maxOutput:4096},mistral:{contextLimit:32e3,maxOutput:4096},mixtral:{contextLimit:32e3,maxOutput:4096},codestral:{contextLimit:256e3,maxOutput:8192},grok:{contextLimit:131072,maxOutput:4096},"nova-":{contextLimit:2e5,maxOutput:8192}};function we(t,e){if(e?.contextLimit&&e.contextLimit>0)return{contextLimit:e.contextLimit,maxOutput:e.maxOutput??L};if(!t)return{contextLimit:K,maxOutput:L};const n=t.toLowerCase().trim();if(H[n])return H[n];const o=Object.keys(H).filter(r=>n.startsWith(r)).sort((r,s)=>s.length-r.length);return o.length>0?H[o[0]]:{contextLimit:K,maxOutput:L}}function ie(t){if(!t)return 0;let e=0,n=0;for(const o of t)o>"\xFF"?e++:n++;return Math.ceil(e/Ot+n/X)}function k(t){return t?Math.ceil(ie(t)*Ct):0}function ae(t){if(typeof t=="object"&&t!==null){const e=t;return e.type==="text"&&typeof e.text=="string"?k(e.text):e.type==="image_url"||e.type==="document"?kt:Math.ceil(JSON.stringify(t).length/X)}return typeof t=="string"?k(t):0}function W(t){return Buffer.byteLength(t,"utf8")}function ut(t){let e=16;if(typeof t.content=="string")e+=W(t.content);else if(Array.isArray(t.content))for(const n of t.content)typeof n=="object"&&n!==null&&(e+=W(JSON.stringify(n)));return t.tool_calls&&(e+=W(JSON.stringify(t.tool_calls))),t.tool_call_id&&(e+=W(t.tool_call_id)),e}function Oe(t){let e=0;for(const n of t)e+=ut(n);return e}function E(t){let e=0;for(const n of t){if(typeof n.content=="string")e+=k(n.content);else if(Array.isArray(n.content))for(const o of n.content)e+=ae(o);n.tool_calls&&(e+=Et+Math.ceil(JSON.stringify(n.tool_calls).length/X))}return e}function V(t){let e=0;for(const n of t)e+=ut(n);return Math.round(e/1024*10)/10}function Ce(t,e,n){if(e<=0)return!1;const o=E(t),r=Math.floor(e*D(e));return o>=r}function ke(t,e,n){if(n<=0)return!1;const o=t+e,r=Math.floor(n*D(n));return o>=r}function ft(t){return t.role==="tool"}function mt(t,e,n){if(!(t.role!=="tool"||!t.tool_call_id))for(let o=n-1;o>=0;o--){const r=e[o];if(r&&r.role==="assistant"&&Array.isArray(r.tool_calls)){for(const s of r.tool_calls)if(typeof s=="object"&&s!==null&&"id"in s&&s.id===t.tool_call_id){const i=s.function;return i?String(i.name??""):void 0}}}}function le(t,e=K,n){if(t.length===0)return{prunedCount:0,freedTokens:0};const o=Math.min(gt,Math.floor(e*Mt)),r=Math.min(yt,Math.floor(e*Tt)),s=n?.ignoreMinimumGain===!0;let i=0;const l=[],a=[];let h=0;for(let m=t.length-1;m>=0;m--){const u=t[m];if(u.role==="user"&&h++,h<2||!ft(u))continue;const _=mt(u,t,m);if(_&&ot.has(_))continue;const x=typeof u.content=="string"?u.content:"";if(x==="[Old tool result content cleared]")continue;const d=k(x);if(i+=d,i>o){const w=_?rt(_):$,c={msg:u,tokens:d,name:_??""};w<=1?a.push(c):l.push(c)}}if(l.sort((m,u)=>u.tokens-m.tokens),a.sort((m,u)=>m.tokens-u.tokens),s){const m=new Set([...l.map(u=>u.msg),...a.map(u=>u.msg)]);for(let u=t.length-1;u>=0;u--){const _=t[u];if(!ft(_)||m.has(_))continue;const x=mt(_,t,u);if(x&&ot.has(x))continue;const d=typeof _.content=="string"?_.content:"";if(d==="[Old tool result content cleared]")continue;const w={msg:_,tokens:k(d),name:x??""};(x?rt(x):$)<=1?a.push(w):l.push(w)}a.sort((u,_)=>u.tokens-_.tokens)}const f=[];let p=0;for(const m of l){if(!s&&p>=r)break;p+=m.tokens,f.push(m.msg)}if(s||p<r){for(const m of a)if(p+=m.tokens,f.push(m.msg),!s&&p>=r)break}if(!s&&p<r)return{prunedCount:0,freedTokens:0};for(const m of f)m.content="[Old tool result content cleared]";return{prunedCount:f.length,freedTokens:p}}function q(t){return t.role==="system"&&typeof t.content=="string"&&t.content.startsWith(N)}function ce(t){return t.role==="system"&&typeof t.content=="string"&&t.content.startsWith(St)}function ue(t){return t.role==="system"&&typeof t.content=="string"&&t.content.startsWith(wt)}function Q(t,e,n=Number.POSITIVE_INFINITY,o=!0){const r=typeof t.content=="string"?t.content:Array.isArray(t.content)?t.content.map(l=>typeof l=="object"&&l!==null?JSON.stringify(l):String(l)).join(" "):"",s=Number.isFinite(n)&&r.length>n?`${r.slice(0,n)}\u2026[truncated ${r.length-n} chars]`:r,i=[`${e+1}. ${t.role}`];if(t.tool_calls&&Array.isArray(t.tool_calls)&&t.tool_calls.length>0){const l=t.tool_calls.map(a=>{if(typeof a=="object"&&a!==null){const h=a.function;return h?String(h.name??""):""}return""}).filter(Boolean).join(", ");l&&i.push(`tool_calls=${l}`)}if(t.tool_call_id&&i.push(`tool_call_id=${t.tool_call_id}`),o&&t.reasoning){const l=t.reasoning.slice(0,jt);i.push(`thinking=${l}`)}return s&&i.push(`content=${s}`),i.join(" | ")}async function ht(t,e){const n=e?.includeReasoning!==!1,o=e?.budget??at({contextLimit:e?.contextLimit??K,maxOutput:L}),r=t.filter(c=>c.role==="system"&&!q(c)&&!ce(c)&&!ue(c)),s=t.filter(c=>c.role!=="system"||q(c)),i=Math.max(0,s.length-xt);if(i===0)return 0;const l=s.slice(0,i);let a=s.slice(i);const h=new Set;for(const c of a)if(c.role==="assistant"&&c.tool_calls?.length)for(const g of c.tool_calls)typeof g=="object"&&g!==null&&typeof g.id=="string"&&h.add(g.id);a=a.filter(c=>{if(c.role==="tool"){const g=typeof c.tool_call_id=="string"?c.tool_call_id.trim():"";return g!==""&&h.has(g)}return!0});let f=!0;for(;f;){f=!1;const c=new Set;for(const y of a)if(y.role==="assistant"&&y.tool_calls?.length)for(const M of y.tool_calls)typeof M=="object"&&M!==null&&typeof M.id=="string"&&c.add(M.id);const g=new Set;for(const y of a)y.role==="tool"&&y.tool_call_id&&g.add(y.tool_call_id);const b=a.filter(y=>{if(y.role==="tool"){const M=typeof y.tool_call_id=="string"?y.tool_call_id.trim():"";return M!==""&&c.has(M)}if(y.role==="assistant"&&y.tool_calls?.length){const M=new Set;for(const C of y.tool_calls)typeof C=="object"&&C!==null&&typeof C.id=="string"&&M.add(C.id);if(M.size===0)return!0;let R=!0;for(const C of M)if(!g.has(C)){R=!1;break}return R}return!0});b.length!==a.length&&(f=!0,a=b)}if(a.length===0)return 0;const p=re(a,o.keepRecentTokens);e?.stats&&(e.stats.downsampleCount+=p.downsampleCount,e.stats.droppedMessages+=p.droppedMessages);const m=Gt(l);let u=null,_,x,d=0;const w=e?.allowRuleFallback!==!1;if(e?.llmSummarizer)try{const c=await ne({removed:l,budget:o,llmSummarizer:e.llmSummarizer,anchors:m,includeReasoning:n,...e.previousSummary?{previousSummary:e.previousSummary}:{},...e.retryPolicy?{retryPolicy:e.retryPolicy}:{}}),g=Xt(c.summary,m);u=Zt(c.summary,g),_=c.step,x=c.chunks,d=c.attempts}catch(c){if(c instanceof z||F(c)||!w||!(c instanceof U))throw c;u=null}if(t.length=0,t.push(...r),u!==null)t.push({role:"system",content:[N,`${i} earlier conversation messages were summarized by LLM to free context space.`,"Preserve the user's goal, known facts, completed work, in-progress work, next steps, file paths, and errors from this summary.","Continue from where the work left off \u2014 do not redo completed tasks.","Recent messages below remain authoritative.","",u].join(`
18
+ `)});else{const g=l.map((b,y)=>Q(b,y)).join(`
19
+ `).slice(0,At);t.push({role:"system",content:[N,`${i} earlier conversation messages were summarized to free context space.`,"Preserve the user's goal, known facts, completed work, in-progress work, next steps, file paths, and errors from this summary.","Continue from where the work left off \u2014 do not redo completed tasks.","Recent messages below remain authoritative.","",g].join(`
20
+ `)})}return t.push(...a),i}function dt(t){if(t.length<=1)return 0;let e=0;for(;e<t.length&&t[e].role==="system";)e++;if(e>=t.length)return 0;let n=t.length;for(let i=e+1;i<t.length;i++)if(t[i].role==="user"){n=i;break}if(n>=t.length)return 0;const o=new Set;for(let i=e;i<n;i++){const l=t[i];if(l.role==="assistant"&&Array.isArray(l.tool_calls))for(const a of l.tool_calls)typeof a=="object"&&a!==null&&typeof a.id=="string"&&o.add(a.id)}const r=n-e;t.splice(e,r);let s=0;for(let i=t.length-1;i>=e;i--){const l=t[i];if(l.role!=="tool")continue;const a=typeof l.tool_call_id=="string"?l.tool_call_id.trim():"";(a===""||o.has(a))&&(t.splice(i,1),s++)}return r+s}function fe(t){for(let e=t.length-1;e>=0;e--){const n=t[e];if(!q(n))continue;const o=typeof n.content=="string"?n.content:"";return(o.startsWith(N)?o.slice(N.length).trim():o).slice(0,Kt)}}function me(t){let e=0;for(const n of t){if(n.role!=="tool")continue;const o=typeof n.content=="string"?n.content:"";o&&(o.startsWith("[tool output omitted")||(n.content=`[tool output omitted: ${o.length} chars]`,e+=1))}return e}function he(t){let e=0;for(const n of t)n.reasoning&&(delete n.reasoning,e+=1);return e}async function Ee(t,e,n=L,o){const r=V(t),s=t.length,i=E(t);let l="none",a=0,h=0,f=0,p=!1,m=1,u,_=!1;const x={downsampleCount:0,droppedMessages:0},d=o?.budget??at({contextLimit:e,maxOutput:n,...o?.inputLimit?{inputLimit:o.inputLimit}:{},...o?.toolsTokens?{toolsTokens:o.toolsTokens}:{}}),w=Math.floor(e*D(e)),c=E(t),g=o?.actualUsedTokens?Math.max(c,o.actualUsedTokens):c;if(!(o?.force===!0||g>=w))return{strategy:"none",freedTokens:0,sizeBeforeKB:r,sizeAfterKB:r,tokensBefore:i,tokensAfter:i,messageCountBefore:s,messageCountAfter:s,prunedToolMessages:0,summarizedMessages:0,level:1,downsampleCount:x.downsampleCount,noSummary:!0,reachedTarget:I(t,d)};if(!o?.llmSummarizer){o?.onPhase&&o.onPhase({phase:"prune_start",messageCount:t.length});const T=le(t,e);o?.onPhase&&o.onPhase({phase:"prune_end",prunedCount:T.prunedCount,freedTokens:T.freedTokens});let O=0;(o?.force===!0||g>=w)&&(o?.onPhase&&o.onPhase({phase:"summarize_start",messageCount:t.length}),O=await ht(t,{contextLimit:e,budget:d}),O===0&&(O=dt(t)),o?.onPhase&&o.onPhase({phase:"summarize_end",summarizedCount:O,usedLLM:!1,level:2}));const S=E(t),A=V(t),P=I(t,d);return{strategy:T.prunedCount>0?O>0?"prune+summarize":"prune":O>0?"summarize":"none",freedTokens:Math.max(0,i-S),sizeBeforeKB:r,sizeAfterKB:A,tokensBefore:i,tokensAfter:S,messageCountBefore:s,messageCountAfter:t.length,prunedToolMessages:T.prunedCount,summarizedMessages:O,level:2,downsampleCount:x.downsampleCount,noSummary:!0,reachedTarget:P}}const y=fe(t);let M;const R=async(T,O,S)=>{if(!o?.llmSummarizer)return"empty";o?.onPhase&&o.onPhase({phase:"summarize_start",messageCount:t.length});const A=await ht(t,{llmSummarizer:o.llmSummarizer,contextLimit:e,budget:d,includeReasoning:S,allowRuleFallback:o.allowRuleFallback,...o.retryPolicy?{retryPolicy:o.retryPolicy}:{},...y?{previousSummary:y}:{},stats:x});return A<=0?"empty":(m=T,u=O,l="summarize",h+=A,p=!!t.find(j=>j.role==="system"&&typeof j.content=="string"&&j.content.includes("summarized by LLM")),o?.onPhase&&o.onPhase({phase:"summarize_end",summarizedCount:h,usedLLM:p,level:m}),"ok")};let C=!1,tt=!1;try{await R(1,"LLM \u6458\u8981\uFF08\u9AD8\u4FDD\u771F\uFF09",!0)==="empty"&&(tt=!0)}catch(T){if(F(T)||!(T instanceof z))throw T;M=T,C=!0,o?.onPhase&&o.onPhase({phase:"degrade",level:2,reason:T instanceof Error?T.message:String(T)})}if(tt)return{strategy:"none",freedTokens:0,sizeBeforeKB:r,sizeAfterKB:r,tokensBefore:i,tokensAfter:i,messageCountBefore:s,messageCountAfter:s,prunedToolMessages:0,summarizedMessages:0,level:1,downsampleCount:x.downsampleCount,noSummary:!0,reachedTarget:I(t,d)};if(C)if(zt&&I(t,d))_=!0;else{const T=me(t);T>0&&(a+=T,l=h>0?"prune+summarize":"prune");let O=!1;try{if(await R(2,"\u53BB\u9664\u5DE5\u5177\u8F93\u51FA\u540E\u6458\u8981",!0)!=="ok")throw new U(1,new Error("summarize produced nothing"))}catch(S){if(F(S)||!(S instanceof z))throw S;M=S,O=!0,o?.onPhase&&o.onPhase({phase:"degrade",level:3,reason:S instanceof Error?S.message:String(S)})}if(O){he(t);let S=!1;try{if(await R(3,"\u4EC5\u660E\u9762\u6587\u672C\u6458\u8981",!1)!=="ok")throw new U(1,new Error("summarize produced nothing"))}catch(A){if(F(A)||!(A instanceof z))throw A;M=A,S=!0,o?.onPhase&&o.onPhase({phase:"degrade",level:4,reason:A instanceof Error?A.message:String(A)})}if(S){let A=0;for(;!I(t,d);){const P=dt(t);if(P<=0)break;A+=P}if(A>0)m=4,u="\u9010\u8F6E\u622A\u65AD\uFF08\u515C\u5E95\uFF09",l="summarize",h+=A,_=!0;else if(M&&h===0)throw M}}}const pt=V(t),et=t.length,G=E(t);f=Math.max(f,Math.max(0,i-G));const nt=I(t,d);return l==="none"?{strategy:"none",freedTokens:0,sizeBeforeKB:r,sizeAfterKB:r,tokensBefore:i,tokensAfter:G,messageCountBefore:s,messageCountAfter:et,prunedToolMessages:0,summarizedMessages:0,level:m,downsampleCount:x.downsampleCount,noSummary:!0,reachedTarget:nt}:{strategy:l,freedTokens:f,sizeBeforeKB:r,sizeAfterKB:pt,tokensBefore:i,tokensAfter:G,messageCountBefore:s,messageCountAfter:et,prunedToolMessages:a,summarizedMessages:h,level:m,...u?{levelLabel:u}:{},downsampleCount:x.downsampleCount,noSummary:_,reachedTarget:nt}}export{ge as COMPACTION_BUFFER,Te as COMPACTION_LLM_PROMPT_TEMPLATE,ye as COMPACTION_TRIGGER_RATIO,yt as PRUNE_MINIMUM,gt as PRUNE_PROTECT,wt as RUNTIME_INSTRUCTIONS_PREFIX,St as RUNTIME_RESOURCES_PREFIX,z as SummaryOverflowError,U as SummaryUnavailableError,Zt as appendMissingAnchors,at as calculateCompactionBudget,Yt as calculateCompactionThreshold,Oe as conversationSizeBytes,V as conversationSizeKB,ct as downsampleToolContent,E as estimateConversationTokens,ie as estimateTextTokens,k as estimateTokens,Gt as extractFidelityAnchors,Xt as findMissingAnchors,xe as fitsHardWindow,D as getCompactionTriggerRatio,I as hasReachedTarget,q as isCompactionSummaryMessage,lt as isEmptyAnchors,Ce as isOverflow,ke as isOverflowByActualUsage,ue as isRuntimeInstructionsMessage,ce as isRuntimeResourcesMessage,we as lookupModelLimits,Ee as performCompaction,le as pruneToolOutputs,Ae as renderAnchorsForPrompt,Se as resolveReplayWindow,re as shrinkRetainedWindow,dt as snipOldestMessageGroup,ht as summarizeConversation};
7
21
 
@@ -1,2 +1,2 @@
1
- function q(e){return`image/${e}`}function W(e){return e>=1024*1024?`${(e/(1024*1024)).toFixed(2)} MB`:e>=1024?`${(e/1024).toFixed(1)} KB`:`${e} B`}function S(e){return e.length<12?null:e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71?"png":e[0]===255&&e[1]===216&&e[2]===255?"jpeg":e[0]===71&&e[1]===73&&e[2]===70?"gif":e[0]===82&&e[1]===73&&e[2]===70&&e[3]===70&&e[8]===87&&e[9]===69&&e[10]===66&&e[11]===80?"webp":null}function D(e){if(!(e.length<24||e.toString("hex",0,8)!=="89504e470d0a1a0a"))return{width:e.readUInt32BE(16),height:e.readUInt32BE(20)}}function F(e){if(!(e.length<10||e.toString("ascii",0,6)!=="GIF87a"&&e.toString("ascii",0,6)!=="GIF89a"))return{width:e.readUInt16LE(6),height:e.readUInt16LE(8)}}function v(e){if(e.length<4||e[0]!==255||e[1]!==216)return;let i=2;for(;i+9<e.length;){if(e[i]!==255){i+=1;continue}const r=e[i+1],l=e.readUInt16BE(i+2);if(l<2)return;if(r>=192&&r<=207&&![196,200,204].includes(r)&&i+8<e.length)return{height:e.readUInt16BE(i+5),width:e.readUInt16BE(i+7)};i+=2+l}}function z(e){if(e.length<30||e.toString("ascii",0,4)!=="RIFF"||e.toString("ascii",8,12)!=="WEBP")return;const i=e.toString("ascii",12,16);if(i==="VP8X")return{width:1+e.readUIntLE(24,3),height:1+e.readUIntLE(27,3)};if(i==="VP8 ")return{width:e.readUInt16LE(26)&16383,height:e.readUInt16LE(28)&16383};if(i==="VP8L"&&e.length>=25){const r=e.readUInt32LE(21);return{width:(r&16383)+1,height:(r>>14&16383)+1}}}function B(e){const i=S(e);if(!i)return null;const l=(i==="png"?D:i==="gif"?F:i==="jpeg"?v:z)(e);return!l||!l.width||!l.height?null:l}let x;async function M(){return x===void 0&&(x=import("sharp").then(i=>{const r=i,l=typeof r=="function"?r:r.default;return typeof l=="function"?l:null}).catch(()=>null)),x}function R(){x=void 0}function H(e){x=Promise.resolve(e)}async function O(e,i,r){const l=await M();if(!l)return null;try{const p=await l(e).metadata();let g=p.width??0,c=p.height??0;if(!g||!c){const d=B(e);g=d?.width??0,c=d?.height??0}const a=g>0&&c>0,h=a&&g<=r.maxWidth&&c<=r.maxHeight;if(h&&e.length<=r.maxBytes)return{buffer:e,mediaType:i,width:g,height:c,changed:!1};if(h){if(i==="png"){const d=await l(e).png({compressionLevel:9,palette:!0}).toBuffer();if(d.length<=r.maxBytes)return{buffer:d,mediaType:"png",width:g,height:c,changed:!0}}for(const d of[80,60,40,20]){const m=await l(e).jpeg({quality:d}).toBuffer();if(m.length<=r.maxBytes)return{buffer:m,mediaType:"jpeg",width:g,height:c,changed:!0}}}let n=a?g:r.maxWidth,t=a?c:r.maxHeight;n>r.maxWidth&&(t=Math.round(t*r.maxWidth/n),n=r.maxWidth),t>r.maxHeight&&(n=Math.round(n*r.maxHeight/t),t=r.maxHeight),n=Math.max(1,n),t=Math.max(1,t);const s={fit:"inside",withoutEnlargement:!0};if(i==="png"){const d=await l(e).resize(n,t,s).png({compressionLevel:9,palette:!0}).toBuffer();if(d.length<=r.maxBytes)return{buffer:d,mediaType:"png",width:n,height:t,changed:!0}}for(const d of[80,60,40,20]){const m=await l(e).resize(n,t,s).jpeg({quality:d}).toBuffer();if(m.length<=r.maxBytes)return{buffer:m,mediaType:"jpeg",width:n,height:t,changed:!0}}const o=Math.min(n,1e3),u=Math.max(1,Math.round(t*o/Math.max(n,1)));return{buffer:await l(e).resize(o,u,s).jpeg({quality:20}).toBuffer(),mediaType:"jpeg",width:o,height:u,changed:!0}}catch{return null}}const U=2e3,j=1e3;async function I(e){try{const i=await e();return i.length>0?i:null}catch{return null}}async function P(e,i,r){const l=await M();if(!l)return null;try{if(i==="gif")return c(null);const a=await p(l,e,i);if(a!==null&&a.buffer.length<=r.normalMaxBytes)return c({...a,level:"lossy"});const h=a!==null?{buffer:a.buffer,mediaType:a.mediaType}:{buffer:e,mediaType:i},n=await g(l,h.buffer,h.mediaType,{maxBytes:r.normalMaxBytes,targetDimension:U,qualityBias:"high"});if(n!==null&&n.buffer.length<=r.clearMaxBytes)return c({...n,level:"normal"});const t=n!==null?{buffer:n.buffer,mediaType:n.mediaType}:{buffer:h.buffer,mediaType:h.mediaType},s=await g(l,t.buffer,t.mediaType,{maxBytes:r.clearMaxBytes,targetDimension:j,qualityBias:"low"});return c(s!==null?{...s,level:"clear"}:n!==null?{...n,level:"normal"}:a!==null?{...a,level:"lossy"}:null)}catch{return null}async function p(a,h,n){const t=[];n==="png"?(t.push({mediaType:"png",encode:()=>a(h).png({compressionLevel:9}).toBuffer()}),t.push({mediaType:"webp",encode:()=>a(h).webp({lossless:!0}).toBuffer()})):n==="webp"&&t.push({mediaType:"webp",encode:()=>a(h).webp({lossless:!0}).toBuffer()});let s=null;for(const o of t){const u=await I(o.encode);u&&u.length<h.length&&(!s||u.length<s.buffer.length)&&(s={buffer:u,mediaType:o.mediaType})}return s}async function g(a,h,n,t){let s=B(h)?.width??0,o=B(h)?.height??0;s>t.targetDimension&&(o=Math.round(o*t.targetDimension/s),s=t.targetDimension),o>t.targetDimension&&(s=Math.round(s*t.targetDimension/o),o=t.targetDimension),s=Math.max(1,s),o=Math.max(1,o);const u={fit:"inside",withoutEnlargement:!0},T=n==="gif"?"png":n,d=[],m=t.qualityBias==="high"?[90,80,70]:[60,50,40],E=t.qualityBias==="high"?[80,70,60]:[50,40,30],L=t.qualityBias==="high"?[80,70,60]:[50,40,30];if(T==="png")for(const f of m)d.push({mediaType:"png",encode:()=>a(h).resize(s,o,u).png({compressionLevel:9,palette:!0,quality:f}).toBuffer()});for(const f of E)d.push({mediaType:"webp",encode:()=>a(h).resize(s,o,u).webp({quality:f}).toBuffer()});if(T!=="webp")for(const f of L)d.push({mediaType:"jpeg",encode:()=>a(h).resize(s,o,u).jpeg({quality:f}).toBuffer()});let y=null;for(const f of d){const w=await I(f.encode);if(w&&w.length<h.length&&((!y||w.length<y.buffer.length)&&(y={buffer:w,mediaType:f.mediaType}),y.buffer.length<=t.maxBytes))break}return y}function c(a){const h=B(e),n=a!==null,t=n?a.buffer:e,s=n?Math.max(0,Math.round((1-t.length/e.length)*100)):0;return{buffer:t,mediaType:n?a.mediaType:i,width:h?.width??0,height:h?.height??0,compressed:n,level:n?a.level:null,originalSize:e.length,compressedSize:t.length,savedPercent:s}}}export{S as detectImageFormatFromBuffer,W as formatBytes,q as imageMediaType,B as readImageDimensions,R as resetSharpCacheForTest,H as setSharpFactoryForTest,P as tryCompressImageWithSharp,O as tryResizeWithSharp};
1
+ function q(e){return`image/${e}`}function W(e){return e>=1024*1024?`${(e/(1024*1024)).toFixed(2)} MB`:e>=1024?`${(e/1024).toFixed(1)} KB`:`${e} B`}function S(e){return e.length<12?null:e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71?"png":e[0]===255&&e[1]===216&&e[2]===255?"jpeg":e[0]===71&&e[1]===73&&e[2]===70?"gif":e[0]===82&&e[1]===73&&e[2]===70&&e[3]===70&&e[8]===87&&e[9]===69&&e[10]===66&&e[11]===80?"webp":null}function D(e){if(!(e.length<24||e.toString("hex",0,8)!=="89504e470d0a1a0a"))return{width:e.readUInt32BE(16),height:e.readUInt32BE(20)}}function F(e){if(!(e.length<10||e.toString("ascii",0,6)!=="GIF87a"&&e.toString("ascii",0,6)!=="GIF89a"))return{width:e.readUInt16LE(6),height:e.readUInt16LE(8)}}function v(e){if(e.length<4||e[0]!==255||e[1]!==216)return;let i=2;for(;i+9<e.length;){if(e[i]!==255){i+=1;continue}const r=e[i+1],h=e.readUInt16BE(i+2);if(h<2)return;if(r>=192&&r<=207&&![196,200,204].includes(r)&&i+8<e.length)return{height:e.readUInt16BE(i+5),width:e.readUInt16BE(i+7)};i+=2+h}}function z(e){if(e.length<30||e.toString("ascii",0,4)!=="RIFF"||e.toString("ascii",8,12)!=="WEBP")return;const i=e.toString("ascii",12,16);if(i==="VP8X")return{width:1+e.readUIntLE(24,3),height:1+e.readUIntLE(27,3)};if(i==="VP8 ")return{width:e.readUInt16LE(26)&16383,height:e.readUInt16LE(28)&16383};if(i==="VP8L"&&e.length>=25){const r=e.readUInt32LE(21);return{width:(r&16383)+1,height:(r>>14&16383)+1}}}function B(e){const i=S(e);if(!i)return null;const h=(i==="png"?D:i==="gif"?F:i==="jpeg"?v:z)(e);return!h||!h.width||!h.height?null:h}let x;async function M(){return x===void 0&&(x=import("sharp").then(i=>{const r=i,h=typeof r=="function"?r:r.default;return typeof h=="function"?h:null}).catch(()=>null)),x}function R(){x=void 0}function H(e){x=Promise.resolve(e)}async function O(e,i,r){const h=await M();if(!h)return null;try{const p=await h(e).metadata();let g=p.width??0,c=p.height??0;if(!g||!c){const d=B(e);g=d?.width??0,c=d?.height??0}const a=g>0&&c>0,s=a&&g<=r.maxWidth&&c<=r.maxHeight;if(s&&e.length<=r.maxBytes)return{buffer:e,mediaType:i,width:g,height:c,changed:!1};if(s){if(i==="png"){const d=await h(e).png({compressionLevel:9,palette:!0}).toBuffer();if(d.length<=r.maxBytes)return{buffer:d,mediaType:"png",width:g,height:c,changed:!0}}for(const d of[80,60,40,20]){const m=await h(e).jpeg({quality:d}).toBuffer();if(m.length<=r.maxBytes)return{buffer:m,mediaType:"jpeg",width:g,height:c,changed:!0}}}let n=a?g:r.maxWidth,t=a?c:r.maxHeight;n>r.maxWidth&&(t=Math.round(t*r.maxWidth/n),n=r.maxWidth),t>r.maxHeight&&(n=Math.round(n*r.maxHeight/t),t=r.maxHeight),n=Math.max(1,n),t=Math.max(1,t);const l={fit:"inside",withoutEnlargement:!0};if(i==="png"){const d=await h(e).resize(n,t,l).png({compressionLevel:9,palette:!0}).toBuffer();if(d.length<=r.maxBytes)return{buffer:d,mediaType:"png",width:n,height:t,changed:!0}}for(const d of[80,60,40,20]){const m=await h(e).resize(n,t,l).jpeg({quality:d}).toBuffer();if(m.length<=r.maxBytes)return{buffer:m,mediaType:"jpeg",width:n,height:t,changed:!0}}const o=Math.min(n,1e3),u=Math.max(1,Math.round(t*o/Math.max(n,1)));return{buffer:await h(e).resize(o,u,l).jpeg({quality:20}).toBuffer(),mediaType:"jpeg",width:o,height:u,changed:!0}}catch{return null}}const U=2e3,j=1e3;async function I(e){try{const i=await e();return i.length>0?i:null}catch{return null}}async function P(e,i,r){const h=await M();if(!h)return null;try{if(i==="gif")return c(null);const a=await p(h,e,i);if(a!==null&&a.buffer.length<=r.normalMaxBytes)return c({...a,level:"lossy"});const s=a!==null?{buffer:a.buffer,mediaType:a.mediaType}:{buffer:e,mediaType:i},n=await g(h,s.buffer,s.mediaType,{maxBytes:r.normalMaxBytes,targetDimension:U,qualityBias:"high"});if(n!==null&&n.buffer.length<=r.clearMaxBytes)return c({...n,level:"normal"});const t=n!==null?{buffer:n.buffer,mediaType:n.mediaType}:{buffer:s.buffer,mediaType:s.mediaType},l=await g(h,t.buffer,t.mediaType,{maxBytes:r.clearMaxBytes,targetDimension:j,qualityBias:"low"});return c(l!==null?{...l,level:"clear"}:n!==null?{...n,level:"normal"}:a!==null?{...a,level:"lossy"}:null)}catch{return null}async function p(a,s,n){const t=[];n==="png"?(t.push({mediaType:"png",encode:()=>a(s).png({compressionLevel:9}).toBuffer()}),t.push({mediaType:"webp",encode:()=>a(s).webp({lossless:!0}).toBuffer()})):n==="webp"&&t.push({mediaType:"webp",encode:()=>a(s).webp({lossless:!0}).toBuffer()});let l=null;for(const o of t){const u=await I(o.encode);u&&u.length<s.length&&(!l||u.length<l.buffer.length)&&(l={buffer:u,mediaType:o.mediaType})}return l}async function g(a,s,n,t){let l=B(s)?.width??0,o=B(s)?.height??0;l>t.targetDimension&&(o=Math.round(o*t.targetDimension/l),l=t.targetDimension),o>t.targetDimension&&(l=Math.round(l*t.targetDimension/o),o=t.targetDimension),l=Math.max(1,l),o=Math.max(1,o);const u={fit:"inside",withoutEnlargement:!0},T=n==="gif"?"png":n,d=[],m=t.qualityBias==="high"?[90,80,70]:[60,50,40],E=t.qualityBias==="high"?[80,70,60]:[50,40,30],L=t.qualityBias==="high"?[80,70,60]:[50,40,30];if(T==="png")for(const f of m)d.push({mediaType:"png",encode:()=>a(s).resize(l,o,u).png({compressionLevel:9,palette:!0,quality:f}).toBuffer()});for(const f of E)d.push({mediaType:"webp",encode:()=>a(s).resize(l,o,u).webp({quality:f}).toBuffer()});if(T!=="webp")for(const f of L)d.push({mediaType:"jpeg",encode:()=>a(s).resize(l,o,u).jpeg({quality:f}).toBuffer()});let y=null;for(const f of d){const w=await I(f.encode);if(w&&w.length<s.length&&((!y||w.length<y.buffer.length)&&(y={buffer:w,mediaType:f.mediaType}),y.buffer.length<=t.maxBytes))break}return y}function c(a){const s=a!==null,n=s?a.buffer:e,t=B(n),l=s?Math.max(0,Math.round((1-n.length/e.length)*100)):0;return{buffer:n,mediaType:s?a.mediaType:i,width:t?.width??0,height:t?.height??0,compressed:s,level:s?a.level:null,originalSize:e.length,compressedSize:n.length,savedPercent:l}}}export{S as detectImageFormatFromBuffer,W as formatBytes,q as imageMediaType,B as readImageDimensions,R as resetSharpCacheForTest,H as setSharpFactoryForTest,P as tryCompressImageWithSharp,O as tryResizeWithSharp};
2
2
 
@@ -1,4 +1,4 @@
1
- import l from"node:os";import r from"node:path";import{shellExecutable as m}from"./builtins/shellCommandPreparation.js";function c(e=process.platform,n=l.release(),i=m()){const s=e==="win32"?"Windows":e==="darwin"?"macOS":e==="linux"?"Linux":e,o=r.basename(i.command).toLowerCase(),t=e==="win32"?`Shell: ${o} (Windows) \u2014 commands run in a Windows shell, not a POSIX shell; Unix-only commands (rm, grep, sed, ...) may be unavailable, prefer Windows equivalents (rd, findstr, ...) or the built-in file tools.`:`Shell: ${o} \u2014 commands run in a POSIX shell.`;return["[Runtime Environment]",`Platform: ${s} (${e}, release ${n})`,t].join(`
1
+ import r from"node:os";import l from"node:path";import{shellExecutable as a}from"./builtins/shellCommandPreparation.js";function c(e=process.platform,n=r.release(),t=a()){const o=e==="win32"?"Windows":e==="darwin"?"macOS":e==="linux"?"Linux":e,i=l.basename(t.command).toLowerCase(),s=e==="win32"?`Shell: ${i} (Windows) \u2014 commands run in a Windows shell, not a POSIX shell; Unix-only commands (rm, grep, sed, ...) may be unavailable, prefer Windows equivalents (rd, findstr, ...) or the built-in file tools.`:`Shell: ${i} \u2014 commands run in a POSIX shell.`;return["[Runtime Environment]",`Platform: ${o} (${e}, release ${n})`,s,"Images: if an image is already at an http(s) URL (including signed URLs with query strings), call read_file with that URL directly \u2014 it is fetched in memory and never written to disk. Do NOT download it with Bash/curl/wget first."].join(`
2
2
  `)}function h(e){const n=e.trim();return n?["[Resume Context]","\u4EE5\u4E0B\u5185\u5BB9\u53D6\u81EA\u4F60\u4E0A\u4E00\u6B21\u8FD0\u884C\u5230\u8BE5\u5B9E\u4F8B\u4F11\u7720\u4E3A\u6B62\u7684\u8FDB\u5EA6\u5FEB\u7167\uFF08\u7531\u7CFB\u7EDF\u5728\u4F11\u7720\u65F6\u81EA\u52A8\u4FDD\u5B58\uFF09\u3002","\u5B83\u4E0D\u662F\u65B0\u7684\u7528\u6237\u6D88\u606F\uFF0C\u4E5F\u4E0D\u662F\u65B0\u7684\u4EFB\u52A1\u6307\u4EE4\uFF0C\u800C\u662F\u4F60\u81EA\u5DF1\u7684\u8BB0\u5FC6\u63A5\u7EED\u70B9\u3002","","\u63A5\u7EED\u89C4\u5219\uFF1A","1. \u4E0A\u8FF0\u5FEB\u7167\u91CC\u5DF2\u7ECF\u5B8C\u6210\u7684\u5DE5\u4F5C\u4E0D\u8981\u91CD\u505A\uFF0C\u5DF2\u786E\u8BA4\u7684\u7ED3\u8BBA\u76F4\u63A5\u6CBF\u7528\u3002","2. \u5FEB\u7167\u4E2D\u6807\u6CE8\u4E3A\u5F85\u5904\u7406/\u8FDB\u884C\u4E2D\u7684\u4E8B\u9879\uFF0C\u662F\u4F60\u8981\u7EE7\u7EED\u63A8\u8FDB\u7684\u76EE\u6807\u3002","3. \u82E5\u5FEB\u7167\u4FE1\u606F\u4E0D\u8DB3\u4EE5\u5224\u65AD\u4E0B\u4E00\u6B65\uFF0C\u5148\u8BFB\u53D6\u76F8\u5173\u6587\u4EF6\u6216\u8C03\u7528 poll_message \u83B7\u53D6\u6700\u65B0\u6D88\u606F\uFF0C\u518D\u884C\u52A8\u3002","","--- \u8FDB\u5EA6\u5FEB\u7167\u5F00\u59CB ---",n,"--- \u8FDB\u5EA6\u5FEB\u7167\u7ED3\u675F ---"].join(`
3
3
  `):""}export{h as buildResumeContextBlock,c as buildRuntimeEnvironmentPrompt};
4
4
 
@@ -2,7 +2,6 @@ import { EventEmitter } from "node:events";
2
2
  import { Client } from "@modelcontextprotocol/sdk/client/index.js";
3
3
  import type { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
4
4
  import { type ACodeBuiltInTool, type EditFailureSnapshot, type JsonObject, type ToolPermissionPolicy } from "./built-in-file-tools.js";
5
- import { type CompactionPlan, type CompactionPreview } from "./compaction.js";
6
5
  import type { ACodeMcpServerSpec, ACodeRuntimeConfig } from "./types.js";
7
6
  export interface ACodeMcpConnection {
8
7
  serverName: string;
@@ -39,6 +38,8 @@ interface ChatMessage {
39
38
  content: string | ChatContentPart[] | null;
40
39
  tool_call_id?: string;
41
40
  tool_calls?: ChatToolCall[];
41
+
42
+ reasoning?: string;
42
43
  }
43
44
  interface ChatToolCall {
44
45
  id: string;
@@ -109,6 +110,8 @@ export declare class ACodeRuntime extends EventEmitter {
109
110
 
110
111
  private compactRequested;
111
112
 
113
+ private instructionsDirty;
114
+
112
115
  private turnPromptPushed;
113
116
  private abortRequested;
114
117
 
@@ -155,12 +158,10 @@ export declare class ACodeRuntime extends EventEmitter {
155
158
 
156
159
  private runCompactionPass;
157
160
 
158
- compactContext(plan?: CompactionPlan): {
161
+ compactContext(): {
159
162
  requested: boolean;
160
163
  };
161
164
 
162
- getCompactionPreview(): CompactionPreview;
163
-
164
165
  start(): Promise<void>;
165
166
 
166
167
  private loadAllSkills;
@@ -235,6 +236,10 @@ export declare class ACodeRuntime extends EventEmitter {
235
236
 
236
237
  submitQuestionAnswer(toolCallId: string, answers: Record<string, string>): boolean;
237
238
 
239
+ cancelQuestionAnswer(toolCallId: string, reason?: string): boolean;
240
+
241
+ private settleQuestionWaiter;
242
+
238
243
  private rejectAllQuestionWaiters;
239
244
 
240
245
  private readonly permissionWaiters;
@@ -273,6 +278,10 @@ export declare class ACodeRuntime extends EventEmitter {
273
278
  private compactForContextOverflow;
274
279
 
275
280
  private rebuildRuntimeResourcesMessage;
281
+
282
+ private rebuildRuntimeInstructionsMessage;
283
+
284
+ private buildRuntimeInstructionsContent;
276
285
  private readChatCompletionStream;
277
286
  private handleToolCalls;
278
287