aws-runtime-bridge 1.9.96 → 1.9.100

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 (123) hide show
  1. package/dist/adapter/AcodeSdkAdapter.d.ts +7 -1
  2. package/dist/adapter/AcodeSdkAdapter.js +5 -5
  3. package/dist/adapter/ClaudeSdkAdapter.d.ts +4 -0
  4. package/dist/adapter/ClaudeSdkAdapter.js +2 -2
  5. package/dist/adapter/CodexSdkAdapter.d.ts +2 -0
  6. package/dist/adapter/CodexSdkAdapter.js +3 -3
  7. package/dist/adapter/OpencodeSdkAdapter.d.ts +2 -0
  8. package/dist/adapter/OpencodeSdkAdapter.js +2 -2
  9. package/dist/adapter/idle-poll-loop.d.ts +4 -1
  10. package/dist/adapter/idle-poll-loop.js +1 -1
  11. package/dist/adapter/types.d.ts +4 -2
  12. package/dist/browser/browser-pool.d.ts +73 -0
  13. package/dist/browser/browser-pool.js +2 -0
  14. package/dist/browser/browser-profile-store.d.ts +28 -0
  15. package/dist/browser/browser-profile-store.js +2 -0
  16. package/dist/browser/built-in-browser-tools.d.ts +27 -0
  17. package/dist/browser/built-in-browser-tools.js +2 -0
  18. package/dist/browser/element-locator.d.ts +24 -0
  19. package/dist/browser/element-locator.js +2 -0
  20. package/dist/browser/element-picker.d.ts +17 -0
  21. package/dist/browser/element-picker.js +2 -0
  22. package/dist/browser/input-dispatcher.d.ts +34 -0
  23. package/dist/browser/input-dispatcher.js +2 -0
  24. package/dist/browser/listener-store.d.ts +32 -0
  25. package/dist/browser/listener-store.js +2 -0
  26. package/dist/browser/page-listener-manager.d.ts +106 -0
  27. package/dist/browser/page-listener-manager.js +307 -0
  28. package/dist/browser/page-listener-types.d.ts +90 -0
  29. package/dist/browser/page-listener-types.js +1 -0
  30. package/dist/browser/screencast-manager.d.ts +42 -0
  31. package/dist/browser/screencast-manager.js +2 -0
  32. package/dist/browser/snapshot-serializer.d.ts +15 -0
  33. package/dist/browser/snapshot-serializer.js +5 -0
  34. package/dist/browser/ssrf-guard.d.ts +15 -0
  35. package/dist/browser/ssrf-guard.js +2 -0
  36. package/dist/browser/stealth.d.ts +7 -0
  37. package/dist/browser/stealth.js +173 -0
  38. package/dist/browser/step-archive.d.ts +52 -0
  39. package/dist/browser/step-archive.js +2 -0
  40. package/dist/browser/types.d.ts +192 -0
  41. package/dist/browser/types.js +2 -0
  42. package/dist/browser/ws-server.d.ts +67 -0
  43. package/dist/browser/ws-server.js +2 -0
  44. package/dist/config.d.ts +1 -1
  45. package/dist/index.js +1 -1
  46. package/dist/middleware/auth.d.ts +2 -0
  47. package/dist/middleware/auth.js +1 -1
  48. package/dist/remote-desktop/computer-control.d.ts +30 -0
  49. package/dist/remote-desktop/computer-control.js +2 -0
  50. package/dist/remote-desktop/coords.d.ts +13 -0
  51. package/dist/remote-desktop/coords.js +2 -0
  52. package/dist/remote-desktop/frame-backpressure.d.ts +7 -0
  53. package/dist/remote-desktop/frame-backpressure.js +2 -0
  54. package/dist/remote-desktop/index.d.ts +7 -0
  55. package/dist/remote-desktop/index.js +4 -0
  56. package/dist/remote-desktop/input-backends/interface.d.ts +17 -0
  57. package/dist/remote-desktop/input-backends/interface.js +1 -0
  58. package/dist/remote-desktop/input-backends/key-map.d.ts +2 -0
  59. package/dist/remote-desktop/input-backends/key-map.js +2 -0
  60. package/dist/remote-desktop/input-dispatcher.d.ts +11 -0
  61. package/dist/remote-desktop/input-dispatcher.js +2 -0
  62. package/dist/remote-desktop/permission-manager.d.ts +7 -0
  63. package/dist/remote-desktop/permission-manager.js +2 -0
  64. package/dist/remote-desktop/screen-capture.d.ts +27 -0
  65. package/dist/remote-desktop/screen-capture.js +2 -0
  66. package/dist/remote-desktop/session-manager.d.ts +59 -0
  67. package/dist/remote-desktop/session-manager.js +2 -0
  68. package/dist/remote-desktop/system-backend.d.ts +65 -0
  69. package/dist/remote-desktop/system-backend.js +5 -0
  70. package/dist/remote-desktop/types.d.ts +68 -0
  71. package/dist/remote-desktop/types.js +1 -0
  72. package/dist/remote-desktop/ui-automation.d.ts +48 -0
  73. package/dist/remote-desktop/ui-automation.js +31 -0
  74. package/dist/remote-desktop/win32-api.d.ts +29 -0
  75. package/dist/remote-desktop/win32-api.js +2 -0
  76. package/dist/routes/background-tasks.d.ts +2 -0
  77. package/dist/routes/background-tasks.js +2 -0
  78. package/dist/routes/browser-listeners.d.ts +2 -0
  79. package/dist/routes/browser-listeners.js +2 -0
  80. package/dist/routes/browser-sessions.d.ts +2 -0
  81. package/dist/routes/browser-sessions.js +2 -0
  82. package/dist/routes/instance.js +2 -2
  83. package/dist/routes/pty.js +3 -3
  84. package/dist/routes/terminal.js +30 -30
  85. package/dist/services/agent-pty-manager.d.ts +22 -0
  86. package/dist/services/agent-pty-manager.js +5 -0
  87. package/dist/services/browser-session-manager.d.ts +55 -0
  88. package/dist/services/browser-session-manager.js +12 -0
  89. package/dist/services/cli-commands.d.ts +4 -0
  90. package/dist/services/cli-commands.js +5 -5
  91. package/dist/services/workspace-files.js +1 -1
  92. package/package/acode/dist/await-complete-tool.d.ts +17 -0
  93. package/package/acode/dist/await-complete-tool.js +21 -0
  94. package/package/acode/dist/background-command-manager.d.ts +148 -0
  95. package/package/acode/dist/background-command-manager.js +8 -0
  96. package/package/acode/dist/background-command-store.d.ts +46 -0
  97. package/package/acode/dist/background-command-store.js +2 -0
  98. package/package/acode/dist/background-command-tools.d.ts +5 -0
  99. package/package/acode/dist/background-command-tools.js +18 -0
  100. package/package/acode/dist/background-output-ringbuffer.d.ts +23 -0
  101. package/package/acode/dist/background-output-ringbuffer.js +3 -0
  102. package/package/acode/dist/built-in-file-tools.d.ts +8 -1
  103. package/package/acode/dist/built-in-file-tools.js +2 -2
  104. package/package/acode/dist/compaction.js +6 -6
  105. package/package/acode/dist/index.d.ts +1 -0
  106. package/package/acode/dist/index.js +1 -1
  107. package/package/acode/dist/runtime.d.ts +6 -0
  108. package/package/acode/dist/runtime.js +27 -27
  109. package/package/acode/dist/sub-agent-tools.d.ts +0 -1
  110. package/package/acode/dist/sub-agent-tools.js +11 -28
  111. package/package/acode/dist/terminal-tool.d.ts +7 -0
  112. package/package/acode/dist/terminal-tool.js +2 -0
  113. package/package/acode/dist/terminal-types.d.ts +38 -0
  114. package/package/acode/dist/terminal-types.js +1 -0
  115. package/package/acode/dist/types.d.ts +10 -1
  116. package/package/aws-client-agent-mcp/dist/agent-client.d.ts +3 -1
  117. package/package/aws-client-agent-mcp/dist/agent-client.js +1 -1
  118. package/package/aws-client-agent-mcp/dist/logger.d.ts +2 -0
  119. package/package/aws-client-agent-mcp/dist/logger.js +1 -1
  120. package/package/aws-client-agent-mcp/dist/mcp-server.d.ts +8 -0
  121. package/package/aws-client-agent-mcp/dist/mcp-server.js +30 -19
  122. package/package/aws-client-agent-mcp/dist/types.d.ts +25 -0
  123. package/package.json +6 -2
@@ -1,4 +1,4 @@
1
- import{randomUUID as Y}from"node:crypto";import{promises as u,createReadStream as C}from"node:fs";import f from"node:path";import D from"node:readline";import{runShellCommand as K}from"./builtins/shellCommandRunner.js";import{symbolsTool as V}from"./built-in-symbols-tool.js";const H=2e3,v=2e3,Z=50*1024,U=4096,J=.3,Q=new Set([".png",".jpg",".jpeg",".gif",".bmp",".ico",".webp",".tiff",".tif",".zip",".gz",".tar",".rar",".7z",".bz2",".xz",".lz",".exe",".dll",".so",".dylib",".bin",".o",".a",".pdf",".doc",".docx",".xls",".xlsx",".ppt",".pptx",".mp3",".mp4",".avi",".mov",".wav",".flv",".mkv",".ogg",".woff",".woff2",".ttf",".otf",".eot",".class",".jar",".war",".ear",".pyc",".pyo",".node",".sqlite",".db",".mdb",".wasm"]),tt=1e3,et=1024*1024,nt=256*1024,ot=1e3,it=new Set([".git","node_modules","dist","build",".next",".nuxt",".cache",".turbo",".output","coverage",".nyc_output"]);function y(o){return o.replace(/\\/g,"/")}async function q(o){try{return await u.access(o),!0}catch{return!1}}function rt(o,n){if(!n)return 0;let t=0,e=o.indexOf(n);for(;e>=0;)t+=1,e=o.indexOf(n,e+n.length);return t}function _(o,n,t){for(const e of n){const i=o[e];if(typeof i=="string")return i}throw new Error(`${t} is required`)}function O(o,n){for(const t of n){const e=o[t];if(typeof e=="string"&&e.trim())return e}}function A(o,n,t){for(const e of n){const i=o[e],r=typeof i=="number"?i:typeof i=="string"?Number(i):NaN;if(Number.isFinite(r)&&r>0)return Math.floor(r)}return t}async function W(o){const n=f.extname(o).toLowerCase();if(Q.has(n))return!0;const t=await u.open(o,"r");try{const e=Buffer.alloc(U),{bytesRead:i}=await t.read(e,0,U,0);if(i===0)return!1;const r=e.subarray(0,i);if(r.includes(0))return!0;let c=0;for(let s=0;s<i;s++){const a=r[s];(a<9||a>13&&a<32)&&c++}return c/i>J}finally{await t.close()}}function E(o,n){const t=f.resolve(n),e=f.relative(o,t);if(e.startsWith("..")||f.isAbsolute(e))throw new Error(`Target path is outside workspace: ${t}`);return t}async function at(o,n){const t=f.resolve(String(o||"").trim()),e=await u.realpath(t);if(!(await u.stat(e)).isDirectory())throw new Error(`Workspace path is not a directory: ${t}`);if(!n?.trim())return{workspaceRoot:e,cwd:e};const r=n.trim(),c=f.isAbsolute(r)?f.resolve(r):f.resolve(t,r),s=f.relative(t,c);if(s.startsWith("..")||f.isAbsolute(s))throw new Error(`Command cwd is outside workspace: ${c}`);const a=E(e,await u.realpath(c));if(!(await u.stat(a)).isDirectory())throw new Error(`Command cwd is not a directory: ${a}`);return{workspaceRoot:e,cwd:a}}async function st(o,n){const t=await u.realpath(f.dirname(n));E(o,t);try{if((await u.lstat(n)).isSymbolicLink())throw new Error(`Refusing to write through symbolic link: ${n}`)}catch(e){if((typeof e=="object"&&e!==null?Reflect.get(e,"code"):void 0)!=="ENOENT")throw e}}async function R(o,n){const t=f.resolve(String(o||"").trim()),e=await u.realpath(t);if(!(await u.stat(e)).isDirectory())throw new Error(`Workspace path is not a directory: ${t}`);const r=n.trim();if(!r)throw new Error("file_path is required");const c=f.isAbsolute(r)?f.resolve(r):f.resolve(t,r),s=f.relative(t,c);if(s.startsWith("..")||f.isAbsolute(s))throw new Error(`Target path is outside workspace: ${c}`);return{workspaceRoot:e,requestedPath:c,targetPath:E(e,f.join(e,s))}}async function j(o,n,t){const e=await R(o,n),i=f.dirname(e.targetPath),r=!await q(i);await u.mkdir(i,{recursive:!0}),await st(e.workspaceRoot,e.targetPath);const c=f.join(i,`.${f.basename(e.targetPath)}.${process.pid}.${Y()}.tmp`);try{await u.writeFile(c,t,"utf-8"),await u.rename(c,e.targetPath)}catch(s){throw await u.rm(c,{force:!0}),s}return{workspaceRoot:e.workspaceRoot,targetPath:e.targetPath,bytes:Buffer.byteLength(t,"utf-8"),createdParentDirectory:r}}async function ct(o,n){const t=await R(o,n),e=E(t.workspaceRoot,await u.realpath(t.targetPath));if(!(await u.stat(e)).isFile())throw new Error(`Path is not a file: ${e}`);return{workspaceRoot:t.workspaceRoot,targetPath:e,content:await u.readFile(e,"utf-8")}}async function lt(o,n,t,e){const i=await R(o,n),r=E(i.workspaceRoot,await u.realpath(i.targetPath));if(!(await u.stat(r)).isFile())throw new Error(`Path is not a file: ${r}`);if(await W(r))return{workspaceRoot:i.workspaceRoot,targetPath:r,content:"[Binary file, content skipped]",isBinary:!0,truncated:!1,totalLines:0,shownFromLine:0,shownToLine:0};const s=C(r,{encoding:"utf-8"}),a=D.createInterface({input:s,crlfDelay:1/0});try{const d=[];let p=0,l=0,I=0,m=!1,w=!1;const S=t-1;for await(const L of a){if(l++,p<S){p++;continue}if(d.length>=e){m=!0,p++;continue}let x=L;x.length>v&&(x=x.slice(0,v)+`... (line truncated to ${v} chars)`);const k=`${p+1}: ${x}`,T=Buffer.byteLength(k,"utf-8")+1;if(I+T>Z){w=!0;break}d.push(k),I+=T,p++}if(l>0&&d.length===0&&!m&&!w&&S>=l)throw new Error(`offset ${t} exceeds total line count ${l} in file: ${r}`);const P=d.length>0?t:0,h=d.length>0?t+d.length-1:0;let b;w?b=`Output capped at 50 KB. Showing lines ${P}-${h}. Use offset=${h+1} to continue.`:m?b=`Showing lines ${P}-${h} of ${l}. Use offset=${h+1} to continue.`:b=`End of file - total ${l} lines`;const M=d.length>0?d.join(`
1
+ import{randomUUID as Y}from"node:crypto";import{promises as d,createReadStream as N}from"node:fs";import f from"node:path";import D from"node:readline";import{runShellCommand as K}from"./builtins/shellCommandRunner.js";import{symbolsTool as H}from"./built-in-symbols-tool.js";import{createListBackgroundCommandsTool as V,createKillBackgroundCommandTool as Z,createReadBackgroundOutputTool as J}from"./background-command-tools.js";const Q=2e3,E=2e3,tt=50*1024,U=4096,et=.3,ot=new Set([".png",".jpg",".jpeg",".gif",".bmp",".ico",".webp",".tiff",".tif",".zip",".gz",".tar",".rar",".7z",".bz2",".xz",".lz",".exe",".dll",".so",".dylib",".bin",".o",".a",".pdf",".doc",".docx",".xls",".xlsx",".ppt",".pptx",".mp3",".mp4",".avi",".mov",".wav",".flv",".mkv",".ogg",".woff",".woff2",".ttf",".otf",".eot",".class",".jar",".war",".ear",".pyc",".pyo",".node",".sqlite",".db",".mdb",".wasm"]),nt=1e3,it=1024*1024,rt=256*1024,at=1e3,st=new Set([".git","node_modules","dist","build",".next",".nuxt",".cache",".turbo",".output","coverage",".nyc_output"]);function _(i){return i.replace(/\\/g,"/")}async function q(i){try{return await d.access(i),!0}catch{return!1}}function ct(i,o){if(!o)return 0;let e=0,t=i.indexOf(o);for(;t>=0;)e+=1,t=i.indexOf(o,t+o.length);return e}function k(i,o,e){for(const t of o){const r=i[t];if(typeof r=="string")return r}throw new Error(`${e} is required`)}function A(i,o){for(const e of o){const t=i[e];if(typeof t=="string"&&t.trim())return t}}function O(i,o,e){for(const t of o){const r=i[t],n=typeof r=="number"?r:typeof r=="string"?Number(r):NaN;if(Number.isFinite(n)&&n>0)return Math.floor(n)}return e}async function W(i){const o=f.extname(i).toLowerCase();if(ot.has(o))return!0;const e=await d.open(i,"r");try{const t=Buffer.alloc(U),{bytesRead:r}=await e.read(t,0,U,0);if(r===0)return!1;const n=t.subarray(0,r);if(n.includes(0))return!0;let c=0;for(let s=0;s<r;s++){const a=n[s];(a<9||a>13&&a<32)&&c++}return c/r>et}finally{await e.close()}}function R(i,o){const e=f.resolve(o),t=f.relative(i,e);if(t.startsWith("..")||f.isAbsolute(t))throw new Error(`Target path is outside workspace: ${e}`);return e}async function lt(i,o){const e=f.resolve(String(i||"").trim()),t=await d.realpath(e);if(!(await d.stat(t)).isDirectory())throw new Error(`Workspace path is not a directory: ${e}`);if(!o?.trim())return{workspaceRoot:t,cwd:t};const n=o.trim(),c=f.isAbsolute(n)?f.resolve(n):f.resolve(e,n),s=f.relative(e,c);if(s.startsWith("..")||f.isAbsolute(s))throw new Error(`Command cwd is outside workspace: ${c}`);const a=R(t,await d.realpath(c));if(!(await d.stat(a)).isDirectory())throw new Error(`Command cwd is not a directory: ${a}`);return{workspaceRoot:t,cwd:a}}async function ut(i,o){const e=await d.realpath(f.dirname(o));R(i,e);try{if((await d.lstat(o)).isSymbolicLink())throw new Error(`Refusing to write through symbolic link: ${o}`)}catch(t){if((typeof t=="object"&&t!==null?Reflect.get(t,"code"):void 0)!=="ENOENT")throw t}}async function S(i,o){const e=f.resolve(String(i||"").trim()),t=await d.realpath(e);if(!(await d.stat(t)).isDirectory())throw new Error(`Workspace path is not a directory: ${e}`);const n=o.trim();if(!n)throw new Error("file_path is required");const c=f.isAbsolute(n)?f.resolve(n):f.resolve(e,n),s=f.relative(e,c);if(s.startsWith("..")||f.isAbsolute(s))throw new Error(`Target path is outside workspace: ${c}`);return{workspaceRoot:t,requestedPath:c,targetPath:R(t,f.join(t,s))}}async function j(i,o,e){const t=await S(i,o),r=f.dirname(t.targetPath),n=!await q(r);await d.mkdir(r,{recursive:!0}),await ut(t.workspaceRoot,t.targetPath);const c=f.join(r,`.${f.basename(t.targetPath)}.${process.pid}.${Y()}.tmp`);try{await d.writeFile(c,e,"utf-8"),await d.rename(c,t.targetPath)}catch(s){throw await d.rm(c,{force:!0}),s}return{workspaceRoot:t.workspaceRoot,targetPath:t.targetPath,bytes:Buffer.byteLength(e,"utf-8"),createdParentDirectory:n}}async function dt(i,o){const e=await S(i,o),t=R(e.workspaceRoot,await d.realpath(e.targetPath));if(!(await d.stat(t)).isFile())throw new Error(`Path is not a file: ${t}`);return{workspaceRoot:e.workspaceRoot,targetPath:t,content:await d.readFile(t,"utf-8")}}async function ft(i,o,e,t){const r=await S(i,o),n=R(r.workspaceRoot,await d.realpath(r.targetPath));if(!(await d.stat(n)).isFile())throw new Error(`Path is not a file: ${n}`);if(await W(n))return{workspaceRoot:r.workspaceRoot,targetPath:n,content:"[Binary file, content skipped]",isBinary:!0,truncated:!1,totalLines:0,shownFromLine:0,shownToLine:0};const s=N(n,{encoding:"utf-8"}),a=D.createInterface({input:s,crlfDelay:1/0});try{const u=[];let m=0,p=0,g=0,h=!1,l=!1;const M=e-1;for await(const L of a){if(p++,m<M){m++;continue}if(u.length>=t){h=!0,m++;continue}let T=L;T.length>E&&(T=T.slice(0,E)+`... (line truncated to ${E} chars)`);const x=`${m+1}: ${T}`,v=Buffer.byteLength(x,"utf-8")+1;if(g+v>tt){l=!0;break}u.push(x),g+=v,m++}if(p>0&&u.length===0&&!h&&!l&&M>=p)throw new Error(`offset ${e} exceeds total line count ${p} in file: ${n}`);const b=u.length>0?e:0,w=u.length>0?e+u.length-1:0;let P;l?P=`Output capped at 50 KB. Showing lines ${b}-${w}. Use offset=${w+1} to continue.`:h?P=`Showing lines ${b}-${w} of ${p}. Use offset=${w+1} to continue.`:P=`End of file - total ${p} lines`;const B=u.length>0?u.join(`
2
2
  `)+`
3
- `+b:b;return{workspaceRoot:i.workspaceRoot,targetPath:r,content:M,isBinary:!1,truncated:m||w,totalLines:w?-1:l,shownFromLine:P,shownToLine:h}}finally{a.close(),s.destroy()}}function G(o){let n="",t=0;for(;t<o.length;){const e=o[t];if(e==="*")n+="[^/]*";else if(e==="?")n+="[^/]";else if(e==="{"){const i=o.indexOf("}",t);if(i>=0){const r=o.slice(t+1,i);n+=`(${r.split(",").join("|")})`,t=i}else n+="\\{"}else if(e==="["){const i=o.indexOf("]",t);i>=0?(n+=o.slice(t,i+1),t=i):n+="\\["}else"+^$.()|\\".includes(e)?n+="\\"+e:n+=e;t++}return new RegExp(`^${n}$`)}async function ut(o,n,t,e){const i=[];async function r(c){if(i.length>=e)return;const s=await u.readdir(c,{withFileTypes:!0});for(const a of s){if(i.length>=e)return;if(a.name.startsWith(".")&&a.isDirectory())continue;const d=f.join(c,a.name);if(a.isDirectory()){if(it.has(a.name))continue;await r(d)}else if(a.isFile()){if(n&&!n.test(a.name)||t&&t.test(a.name))continue;i.push(d)}}}return await r(o),i}async function dt(o,n,t){if((await u.stat(o)).size>et)return{matches:[],count:0};if(await W(o))return{matches:[],count:0};const i=f.relative(n,o).replace(/\\/g,"/"),r=[];let c=0;const s=C(o,{encoding:"utf-8"}),a=D.createInterface({input:s,crlfDelay:1/0});try{let d=0;for await(const p of a)if(d++,t.regex.test(p)){if(c++,t.collectContent){let l=p;if(l.length>v&&(l=l.slice(0,v)+`... (line truncated to ${v} chars)`),r.push({file:i,line:d,content:l}),r.length>=t.maxResults)break}if(t.stopOnFirstMatch)break}}finally{a.close(),s.destroy()}return{matches:r,count:c}}const X=10*6e4,ft=X,pt=6e4,ht=10*6e4;function mt(o,n){return{kind:"builtin",toolName:"write_file",exposedName:"write_file",description:"Create or overwrite a UTF-8 text file inside the current workspace. Parent directories are created automatically.",inputSchema:{type:"object",properties:{file_path:{type:"string",description:"Workspace-relative file path to write."},content:{type:"string",description:"Complete UTF-8 file content."}},required:["file_path","content"],additionalProperties:!1},async execute(t){const e=_(t,["file_path","filePath"],"file_path"),i=_(t,["content"],"content"),r=await R(o,e),c=await q(r.targetPath),s=c?await u.readFile(r.targetPath,"utf-8").catch(()=>null):null,a=await j(o,e,i);if(n){const d=f.relative(a.workspaceRoot,a.targetPath).replace(/\\/g,"/");await n({filePath:d,operation:c?"UPDATE":"CREATE",beforeContent:s,afterContent:i})}return{ok:!0,tool:"write_file",workspacePath:y(a.workspaceRoot),filePath:y(a.targetPath),bytes:a.bytes,createdParentDirectory:a.createdParentDirectory}}}}function wt(o,n){return{kind:"builtin",toolName:"edit_file",exposedName:"edit_file",description:"Replace exactly one occurrence of old_string with new_string in a UTF-8 workspace text file.",inputSchema:{type:"object",properties:{file_path:{type:"string",description:"Workspace-relative file path to edit."},old_string:{type:"string",description:"Existing text to replace. Must occur exactly once."},new_string:{type:"string",description:"Replacement text."}},required:["file_path","old_string","new_string"],additionalProperties:!1},async execute(t){const e=_(t,["file_path","filePath"],"file_path"),i=_(t,["old_string","oldString"],"old_string"),r=_(t,["new_string","newString"],"new_string");if(!i)throw new Error("old_string must not be empty");const c=await ct(o,e),s=rt(c.content,i);if(s===0)throw new Error("old_string was not found in file");if(s>1)throw new Error(`old_string occurs ${s} times; provide a unique match`);const a=c.content.replace(i,r),d=await j(o,e,a);if(n){const p=f.relative(d.workspaceRoot,d.targetPath).replace(/\\/g,"/");await n({filePath:p,operation:"UPDATE",beforeContent:c.content,afterContent:a})}return{ok:!0,tool:"edit_file",workspacePath:y(d.workspaceRoot),filePath:y(d.targetPath),replacements:1,bytes:d.bytes}}}}function gt(o,n){return{kind:"builtin",toolName:"delete_file",exposedName:"delete_file",description:"Delete a file inside the current workspace. Returns an error if the file does not exist.",inputSchema:{type:"object",properties:{file_path:{type:"string",description:"Workspace-relative file path to delete."}},required:["file_path"],additionalProperties:!1},async execute(t){const e=_(t,["file_path","filePath"],"file_path"),i=await R(o,e),r=E(i.workspaceRoot,await u.realpath(i.targetPath).catch(()=>i.targetPath)),c=await u.stat(r).catch(()=>null);if(!c)throw new Error(`File does not exist: ${r}`);if(!c.isFile())throw new Error(`Path is not a file: ${r}`);const s=await u.readFile(r,"utf-8").catch(()=>null);if(await u.rm(r,{force:!0}),n){const a=f.relative(i.workspaceRoot,r).replace(/\\/g,"/");await n({filePath:a,operation:"DELETE",beforeContent:s,afterContent:null})}return{ok:!0,tool:"delete_file",workspacePath:y(i.workspaceRoot),filePath:y(r),deleted:!0}}}}function yt(o){return{kind:"builtin",toolName:"read_file",exposedName:"read_file",description:"Read a UTF-8 text file inside the current workspace. Returns content with line numbers in the format '<line>: <content>'. Supports offset (1-indexed line number to start from) and limit (max lines to return, default 2000). Output is capped at 2000 lines or 50 KB, whichever is reached first. Individual lines longer than 2000 characters are truncated. Avoid tiny repeated slices (e.g. 30-line chunks); read a larger window if more context is needed.",inputSchema:{type:"object",properties:{file_path:{type:"string",description:"Workspace-relative file path to read."},offset:{type:"number",description:"Line number to start reading from (1-indexed). Defaults to 1."},limit:{type:"number",description:"Maximum number of lines to return. Defaults to 2000."}},required:["file_path"],additionalProperties:!1},async execute(n){const t=_(n,["file_path","filePath"],"file_path"),e=A(n,["offset"],1),i=A(n,["limit"],H),r=await lt(o,t,e,i);return{ok:!0,tool:"read_file",workspacePath:y(r.workspaceRoot),filePath:y(r.targetPath),content:r.content,isBinary:r.isBinary,truncated:r.truncated,totalLines:r.totalLines,shownFromLine:r.shownFromLine,shownToLine:r.shownToLine}}}}function _t(o,n){return{kind:"builtin",toolName:"Bash",exposedName:"Bash",description:"Execute a shell command in the current workspace. Use for local diagnostics, builds, tests, and OS commands. The command runs with a bounded timeout and returns stdout, stderr, and exit code.",inputSchema:{type:"object",properties:{command:{type:"string",description:"Shell command to execute."},cwd:{type:"string",description:"Optional workspace-relative working directory. Defaults to the workspace root."},timeout_ms:{type:"number",description:"Optional timeout in milliseconds. Defaults to 600000 and is capped at 600000."},inactivity_timeout_ms:{type:"number",description:"Optional no-output timeout in milliseconds. Defaults to 60000 and is capped at 600000."},description:{type:"string",description:"Optional short reason for running the command."}},required:["command"],additionalProperties:!1},async execute(t,e){const i=_(t,["command"],"command").trim();if(!i)throw new Error("command must not be empty");const r=A(t,["timeout_ms","timeoutMs"],ft),c=Math.min(r,X),s=A(t,["inactivity_timeout_ms","inactivityTimeoutMs"],pt),a=Math.min(s,ht),d=O(t,["cwd"]),p=await at(o,d),l=await K({commandText:i,agentId:n,workspaceRoot:p.workspaceRoot,cwd:p.cwd,timeoutMs:c,inactivityTimeoutMs:a,onOutput:e?.onOutput});return{ok:l.exitCode===0&&!l.timedOut,tool:"Bash",command:i,cwd:y(p.cwd),exitCode:l.exitCode,signal:l.signal,timedOut:l.timedOut,inactivityTimedOut:l.inactivityTimedOut,timeoutMs:c,inactivityTimeoutMs:a,durationMs:l.durationMs,outputSpilled:l.outputSpilled,outputFilePath:l.outputFilePath,outputLineCount:l.outputLineCount,commandFilePath:l.commandFilePath,commandLineCount:l.commandLineCount,stdout:l.stdout,stderr:l.stderr}}}}function Pt(o){return{kind:"builtin",toolName:"grep",exposedName:"grep",description:"Search file contents using regular expressions within the workspace. Returns matched lines with file paths and line numbers. Supports include/exclude glob patterns, case-insensitive matching, and three output modes (content, files_with_matches, count). Searches recursively through directories, skipping binary files, hidden directories, and common build/dependency directories (node_modules, .git, dist, etc.).",inputSchema:{type:"object",properties:{pattern:{type:"string",description:"Regular expression pattern to search for in file contents."},path:{type:"string",description:"Workspace-relative file or directory path to search in. Defaults to the workspace root."},include:{type:"string",description:"Glob pattern to filter files by name (e.g. '*.ts', '*.{js,ts}'). Only matching files are searched."},exclude:{type:"string",description:"Glob pattern to exclude files by name (e.g. '*.test.ts'). Matching files are skipped."},case_insensitive:{type:"boolean",description:"Case-insensitive matching. Default false."},output_mode:{type:"string",enum:["content","files_with_matches","count"],description:"Output format: 'content' returns matched lines with line numbers (default), 'files_with_matches' returns only file paths with matches, 'count' returns match counts per file."},max_results:{type:"number",description:"Maximum number of matched lines to return (content mode). Default 1000."}},required:["pattern"],additionalProperties:!1},async execute(n){const t=_(n,["pattern"],"pattern"),e=O(n,["path"])||".",i=O(n,["include"]),r=O(n,["exclude"]),c=n.case_insensitive===!0,s=(()=>{const g=n.output_mode;return g==="files_with_matches"||g==="count"?g:"content"})(),a=A(n,["max_results"],ot),d=c?"i":"";let p;try{p=new RegExp(t,d)}catch(g){throw new Error(`Invalid regex pattern: ${g instanceof Error?g.message:String(g)}`)}const l=i?G(i):null,I=r?G(r):null,m=await R(o,e),w=E(m.workspaceRoot,await u.realpath(m.targetPath)),S=await u.stat(w);let P;if(S.isFile())P=[w];else if(S.isDirectory())P=await ut(w,l,I,tt);else throw new Error(`Path is neither a file nor a directory: ${w}`);const h=[],b=[],M=[];let L=0,x=0,k=!1;for(const g of P){if(s==="content"&&h.length>=a){k=!0;break}const z={regex:p,maxResults:s==="content"?a-h.length:Number.MAX_SAFE_INTEGER,collectContent:s==="content",stopOnFirstMatch:s==="files_with_matches"},F=await dt(g,m.workspaceRoot,z);if(F.count>0){const N=f.relative(m.workspaceRoot,g).replace(/\\/g,"/");if(M.push(N),L+=F.count,s==="content"){for(const $ of F.matches){const B=Buffer.byteLength($.content,"utf-8")+64;if(x+B>nt){k=!0;break}x+=B,h.push($)}if(k)break;if(h.length>=a){k=!0;break}}else s==="count"&&b.push({file:N,count:F.count})}}const T={ok:!0,tool:"grep",pattern:t,searchPath:y(m.targetPath),outputMode:s,filesSearched:P.length,filesMatched:M.length,totalMatches:L,truncated:k};return s==="content"?T.matches=h:s==="files_with_matches"?T.matches=M:T.matches=b,T}}}function Rt(o,n,t){const e=n||"unknown";return[yt(o),mt(o,t),wt(o,t),gt(o,t),Pt(o),_t(o,e),V(o)]}export{Rt as createBuiltInFileTools,E as ensureInsideWorkspace,R as resolveWorkspaceTarget};
3
+ `+P:P;return{workspaceRoot:r.workspaceRoot,targetPath:n,content:B,isBinary:!1,truncated:h||l,totalLines:l?-1:p,shownFromLine:b,shownToLine:w}}finally{a.close(),s.destroy()}}function G(i){let o="",e=0;for(;e<i.length;){const t=i[e];if(t==="*")o+="[^/]*";else if(t==="?")o+="[^/]";else if(t==="{"){const r=i.indexOf("}",e);if(r>=0){const n=i.slice(e+1,r);o+=`(${n.split(",").join("|")})`,e=r}else o+="\\{"}else if(t==="["){const r=i.indexOf("]",e);r>=0?(o+=i.slice(e,r+1),e=r):o+="\\["}else"+^$.()|\\".includes(t)?o+="\\"+t:o+=t;e++}return new RegExp(`^${o}$`)}async function pt(i,o,e,t){const r=[];async function n(c){if(r.length>=t)return;const s=await d.readdir(c,{withFileTypes:!0});for(const a of s){if(r.length>=t)return;if(a.name.startsWith(".")&&a.isDirectory())continue;const u=f.join(c,a.name);if(a.isDirectory()){if(st.has(a.name))continue;await n(u)}else if(a.isFile()){if(o&&!o.test(a.name)||e&&e.test(a.name))continue;r.push(u)}}}return await n(i),r}async function mt(i,o,e){if((await d.stat(i)).size>it)return{matches:[],count:0};if(await W(i))return{matches:[],count:0};const r=f.relative(o,i).replace(/\\/g,"/"),n=[];let c=0;const s=N(i,{encoding:"utf-8"}),a=D.createInterface({input:s,crlfDelay:1/0});try{let u=0;for await(const m of a)if(u++,e.regex.test(m)){if(c++,e.collectContent){let p=m;if(p.length>E&&(p=p.slice(0,E)+`... (line truncated to ${E} chars)`),n.push({file:r,line:u,content:p}),n.length>=e.maxResults)break}if(e.stopOnFirstMatch)break}}finally{a.close(),s.destroy()}return{matches:n,count:c}}const X=10*6e4,ht=X,wt=6e4,gt=10*6e4;function yt(i,o){return{kind:"builtin",toolName:"write_file",exposedName:"write_file",description:"Create or overwrite a UTF-8 text file inside the current workspace. Parent directories are created automatically.",inputSchema:{type:"object",properties:{file_path:{type:"string",description:"Workspace-relative file path to write."},content:{type:"string",description:"Complete UTF-8 file content."}},required:["file_path","content"],additionalProperties:!1},async execute(e){const t=k(e,["file_path","filePath"],"file_path"),r=k(e,["content"],"content"),n=await S(i,t),c=await q(n.targetPath),s=c?await d.readFile(n.targetPath,"utf-8").catch(()=>null):null,a=await j(i,t,r);if(o){const u=f.relative(a.workspaceRoot,a.targetPath).replace(/\\/g,"/");await o({filePath:u,operation:c?"UPDATE":"CREATE",beforeContent:s,afterContent:r})}return{ok:!0,tool:"write_file",workspacePath:_(a.workspaceRoot),filePath:_(a.targetPath),bytes:a.bytes,createdParentDirectory:a.createdParentDirectory}}}}function _t(i,o){return{kind:"builtin",toolName:"edit_file",exposedName:"edit_file",description:"Replace exactly one occurrence of old_string with new_string in a UTF-8 workspace text file.",inputSchema:{type:"object",properties:{file_path:{type:"string",description:"Workspace-relative file path to edit."},old_string:{type:"string",description:"Existing text to replace. Must occur exactly once."},new_string:{type:"string",description:"Replacement text."}},required:["file_path","old_string","new_string"],additionalProperties:!1},async execute(e){const t=k(e,["file_path","filePath"],"file_path"),r=k(e,["old_string","oldString"],"old_string"),n=k(e,["new_string","newString"],"new_string");if(!r)throw new Error("old_string must not be empty");const c=await dt(i,t),s=ct(c.content,r);if(s===0)throw new Error("old_string was not found in file");if(s>1)throw new Error(`old_string occurs ${s} times; provide a unique match`);const a=c.content.replace(r,n),u=await j(i,t,a);if(o){const m=f.relative(u.workspaceRoot,u.targetPath).replace(/\\/g,"/");await o({filePath:m,operation:"UPDATE",beforeContent:c.content,afterContent:a})}return{ok:!0,tool:"edit_file",workspacePath:_(u.workspaceRoot),filePath:_(u.targetPath),replacements:1,bytes:u.bytes}}}}function kt(i,o){return{kind:"builtin",toolName:"delete_file",exposedName:"delete_file",description:"Delete a file inside the current workspace. Returns an error if the file does not exist.",inputSchema:{type:"object",properties:{file_path:{type:"string",description:"Workspace-relative file path to delete."}},required:["file_path"],additionalProperties:!1},async execute(e){const t=k(e,["file_path","filePath"],"file_path"),r=await S(i,t),n=R(r.workspaceRoot,await d.realpath(r.targetPath).catch(()=>r.targetPath)),c=await d.stat(n).catch(()=>null);if(!c)throw new Error(`File does not exist: ${n}`);if(!c.isFile())throw new Error(`Path is not a file: ${n}`);const s=await d.readFile(n,"utf-8").catch(()=>null);if(await d.rm(n,{force:!0}),o){const a=f.relative(r.workspaceRoot,n).replace(/\\/g,"/");await o({filePath:a,operation:"DELETE",beforeContent:s,afterContent:null})}return{ok:!0,tool:"delete_file",workspacePath:_(r.workspaceRoot),filePath:_(n),deleted:!0}}}}function bt(i){return{kind:"builtin",toolName:"read_file",exposedName:"read_file",description:"Read a UTF-8 text file inside the current workspace. Returns content with line numbers in the format '<line>: <content>'. Supports offset (1-indexed line number to start from) and limit (max lines to return, default 2000). Output is capped at 2000 lines or 50 KB, whichever is reached first. Individual lines longer than 2000 characters are truncated. Avoid tiny repeated slices (e.g. 30-line chunks); read a larger window if more context is needed.",inputSchema:{type:"object",properties:{file_path:{type:"string",description:"Workspace-relative file path to read."},offset:{type:"number",description:"Line number to start reading from (1-indexed). Defaults to 1."},limit:{type:"number",description:"Maximum number of lines to return. Defaults to 2000."}},required:["file_path"],additionalProperties:!1},async execute(o){const e=k(o,["file_path","filePath"],"file_path"),t=O(o,["offset"],1),r=O(o,["limit"],Q),n=await ft(i,e,t,r);return{ok:!0,tool:"read_file",workspacePath:_(n.workspaceRoot),filePath:_(n.targetPath),content:n.content,isBinary:n.isBinary,truncated:n.truncated,totalLines:n.totalLines,shownFromLine:n.shownFromLine,shownToLine:n.shownToLine}}}}function Pt(i,o,e){return{kind:"builtin",toolName:"Bash",exposedName:"Bash",description:"Execute a shell command in the current workspace. Use for local diagnostics, builds, tests, and OS commands. The command runs with a bounded timeout and returns stdout, stderr, and exit code. Set wait_seconds to 0 or n>0 to move long-running commands to the background and return a task_id immediately (or after n seconds); then use ListBackgroundCommands / ReadBackgroundOutput / KillBackgroundCommand to manage them.",inputSchema:{type:"object",properties:{command:{type:"string",description:"Shell command to execute."},cwd:{type:"string",description:"Optional workspace-relative working directory. Defaults to the workspace root."},timeout_ms:{type:"number",description:"Optional timeout in milliseconds. Defaults to 600000 and is capped at 600000."},inactivity_timeout_ms:{type:"number",description:"Optional no-output timeout in milliseconds. Defaults to 60000 and is capped at 600000. Only applies to foreground (wait_seconds=-1); ignored once a command moves to background."},wait_seconds:{type:"number",description:"How long to block waiting for the command to finish. -1 (default): block until completion (current behavior, capped at timeout_ms). 0: spawn and immediately move to background, return task_id. n>0: wait up to n seconds; if still running, move to background and return task_id. Background commands remain subject to timeout_ms (total upper bound); inactivity_timeout_ms is ignored once backgrounded.",default:-1,minimum:-1},description:{type:"string",description:"Optional short reason for running the command."}},required:["command"],additionalProperties:!1},async execute(t,r){const n=k(t,["command"],"command").trim();if(!n)throw new Error("command must not be empty");const c=O(t,["timeout_ms","timeoutMs"],ht),s=Math.min(c,X),a=O(t,["inactivity_timeout_ms","inactivityTimeoutMs"],wt),u=Math.min(a,gt),m=A(t,["cwd"]),p=await lt(i,m),g=t.wait_seconds,h=typeof g=="number"&&Number.isFinite(g)?g:-1;if(h!==-1&&e)return await xt({deps:e,command:n,agentId:o,workspaceRoot:p.workspaceRoot,cwd:p.cwd,timeoutMs:s,waitSeconds:h});const l=await K({commandText:n,agentId:o,workspaceRoot:p.workspaceRoot,cwd:p.cwd,timeoutMs:s,inactivityTimeoutMs:u,onOutput:r?.onOutput});return{ok:l.exitCode===0&&!l.timedOut,tool:"Bash",command:n,cwd:_(p.cwd),exitCode:l.exitCode,signal:l.signal,timedOut:l.timedOut,inactivityTimedOut:l.inactivityTimedOut,timeoutMs:s,inactivityTimeoutMs:u,durationMs:l.durationMs,outputSpilled:l.outputSpilled,outputFilePath:l.outputFilePath,outputLineCount:l.outputLineCount,commandFilePath:l.commandFilePath,commandLineCount:l.commandLineCount,stdout:l.stdout,stderr:l.stderr}}}}async function xt(i){const{deps:o,command:e,agentId:t,workspaceRoot:r,cwd:n,timeoutMs:c,waitSeconds:s}=i;try{const{taskId:a,completion:u}=o.manager.startCommand({commandText:e,agentId:t,workspaceRoot:r,cwd:n,timeoutMs:c,onCompleted:o.emitCompleted});if(s===0)return{ok:!0,tool:"Bash",command:e,backgrounded:!0,taskId:a,status:"backgrounded",reason:"immediate",message:`Command moved to background. Use ListBackgroundCommands to view, ReadBackgroundOutput(task_id="${a}", mode="tail") to read output, KillBackgroundCommand(task_id="${a}") to stop.`};const m=Math.max(0,Math.floor(s*1e3));let p;const g=new Promise(h=>{p=setTimeout(()=>h("__timeout__"),m),p.unref?.()});try{const h=await Promise.race([u,g]);if(h==="__timeout__")return{ok:!0,tool:"Bash",command:e,backgrounded:!0,taskId:a,status:"backgrounded",reason:"timeout",waitedMs:m,message:`Command still running after ${s}s; moved to background. Use ListBackgroundCommands / ReadBackgroundOutput(task_id="${a}", mode="tail") to inspect.`};const l=h;return{ok:l.exitCode===0&&!l.timedOut,tool:"Bash",command:e,backgrounded:!1,taskId:a,exitCode:l.exitCode,signal:l.signal,timedOut:l.timedOut,durationMs:l.durationMs,stdout:l.stdout,stderr:l.stderr}}finally{p&&clearTimeout(p)}}catch(a){if(a?.code==="too_many_tasks"||a?.code==="global_limit_reached")return{ok:!1,tool:"Bash",command:e,backgrounded:!1,error:a.code,message:a.message};throw a}}function Tt(i){return{kind:"builtin",toolName:"grep",exposedName:"grep",description:"Search file contents using regular expressions within the workspace. Returns matched lines with file paths and line numbers. Supports include/exclude glob patterns, case-insensitive matching, and three output modes (content, files_with_matches, count). Searches recursively through directories, skipping binary files, hidden directories, and common build/dependency directories (node_modules, .git, dist, etc.).",inputSchema:{type:"object",properties:{pattern:{type:"string",description:"Regular expression pattern to search for in file contents."},path:{type:"string",description:"Workspace-relative file or directory path to search in. Defaults to the workspace root."},include:{type:"string",description:"Glob pattern to filter files by name (e.g. '*.ts', '*.{js,ts}'). Only matching files are searched."},exclude:{type:"string",description:"Glob pattern to exclude files by name (e.g. '*.test.ts'). Matching files are skipped."},case_insensitive:{type:"boolean",description:"Case-insensitive matching. Default false."},output_mode:{type:"string",enum:["content","files_with_matches","count"],description:"Output format: 'content' returns matched lines with line numbers (default), 'files_with_matches' returns only file paths with matches, 'count' returns match counts per file."},max_results:{type:"number",description:"Maximum number of matched lines to return (content mode). Default 1000."}},required:["pattern"],additionalProperties:!1},async execute(o){const e=k(o,["pattern"],"pattern"),t=A(o,["path"])||".",r=A(o,["include"]),n=A(o,["exclude"]),c=o.case_insensitive===!0,s=(()=>{const y=o.output_mode;return y==="files_with_matches"||y==="count"?y:"content"})(),a=O(o,["max_results"],at),u=c?"i":"";let m;try{m=new RegExp(e,u)}catch(y){throw new Error(`Invalid regex pattern: ${y instanceof Error?y.message:String(y)}`)}const p=r?G(r):null,g=n?G(n):null,h=await S(i,t),l=R(h.workspaceRoot,await d.realpath(h.targetPath)),M=await d.stat(l);let b;if(M.isFile())b=[l];else if(M.isDirectory())b=await pt(l,p,g,nt);else throw new Error(`Path is neither a file nor a directory: ${l}`);const w=[],P=[],B=[];let L=0,T=0,x=!1;for(const y of b){if(s==="content"&&w.length>=a){x=!0;break}const z={regex:m,maxResults:s==="content"?a-w.length:Number.MAX_SAFE_INTEGER,collectContent:s==="content",stopOnFirstMatch:s==="files_with_matches"},C=await mt(y,h.workspaceRoot,z);if(C.count>0){const I=f.relative(h.workspaceRoot,y).replace(/\\/g,"/");if(B.push(I),L+=C.count,s==="content"){for(const $ of C.matches){const F=Buffer.byteLength($.content,"utf-8")+64;if(T+F>rt){x=!0;break}T+=F,w.push($)}if(x)break;if(w.length>=a){x=!0;break}}else s==="count"&&P.push({file:I,count:C.count})}}const v={ok:!0,tool:"grep",pattern:e,searchPath:_(h.targetPath),outputMode:s,filesSearched:b.length,filesMatched:B.length,totalMatches:L,truncated:x};return s==="content"?v.matches=w:s==="files_with_matches"?v.matches=B:v.matches=P,v}}}function Lt(i,o,e,t){const r=o||"unknown",n=[bt(i),yt(i,e),_t(i,e),kt(i,e),Tt(i),Pt(i,r,t),H(i)];return t&&n.push(V(r,t),Z(r,t),J(r,t)),n}export{Lt as createBuiltInFileTools,R as ensureInsideWorkspace,S as resolveWorkspaceTarget};
4
4
 
@@ -1,7 +1,7 @@
1
- const nt=2e4,rt=.55,z=[[32e3,.7],[128e3,.75],[512e3,.8],[Number.POSITIVE_INFINITY,.85]];function T(t){if(t<=0)return .55;for(const[e,o]of z)if(t<e)return o;return .85}const U=4e4,j=2e4,B=.5,F=.1,G=new Set(["skill","todo_write","todo_read"]),y={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},L=2;function K(t){if(!t)return L;if(y[t]!==void 0)return y[t];const e=Object.keys(y).filter(o=>t.startsWith(o)).sort((o,n)=>n.length-o.length);return e.length>0?y[e[0]]:L}const M=128e3,C=8192,D=8,$=6e3,b=500,E="ACode context compaction summary:",it=["Please summarize the conversation above using the following structured format.","Keep each section concise but preserve all actionable details.","","## Goal","The user's primary objective in this conversation.","","## Instructions","Standing instructions, constraints, or preferences the user has stated.","","## Discoveries","Key findings, decisions, tool results, file paths, and errors encountered.","","## Accomplished","Tasks that have been completed (do not redo these).","","## Files","Files read, modified, or created with brief context.","","Output only the summary, no preamble."].join(`
2
- `),W=1.5,S=4,J=1.15,X=2e3,H=8;function lt(t,e,o){const n=Math.floor(t*T(t)),l=o??t,s=Math.min(2e4,e),i=l-s;return Math.min(n,i)}const A={"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 st(t,e){if(e?.contextLimit&&e.contextLimit>0)return{contextLimit:e.contextLimit,maxOutput:e.maxOutput??C};if(!t)return{contextLimit:M,maxOutput:C};const o=t.toLowerCase().trim();if(A[o])return A[o];const n=Object.keys(A).filter(l=>o.startsWith(l)).sort((l,s)=>s.length-l.length);return n.length>0?A[n[0]]:{contextLimit:M,maxOutput:C}}function q(t){if(!t)return 0;let e=0,o=0;for(const n of t)n>"\xFF"?e++:o++;return Math.ceil(e/W+o/S)}function g(t){return t?Math.ceil(q(t)*J):0}function V(t){if(typeof t=="object"&&t!==null){const e=t;return e.type==="text"&&typeof e.text=="string"?g(e.text):e.type==="image_url"||e.type==="document"?X:Math.ceil(JSON.stringify(t).length/S)}return typeof t=="string"?g(t):0}function Y(t){let e=16;if(typeof t.content=="string")e+=t.content.length*2;else if(Array.isArray(t.content))for(const o of t.content)typeof o=="object"&&o!==null&&(e+=JSON.stringify(o).length);return t.tool_calls&&(e+=JSON.stringify(t.tool_calls).length),t.tool_call_id&&(e+=t.tool_call_id.length),e}function x(t){let e=0;for(const o of t){if(typeof o.content=="string")e+=g(o.content);else if(Array.isArray(o.content))for(const n of o.content)e+=V(n);o.tool_calls&&(e+=H+Math.ceil(JSON.stringify(o.tool_calls).length/S))}return e}function N(t){let e=0;for(const o of t)e+=Y(o);return Math.round(e/1024*10)/10}function ct(t,e,o){if(e<=0)return!1;const n=x(t),l=Math.floor(e*T(e));return n>=l}function ut(t,e,o){if(o<=0)return!1;const n=t+e,l=Math.floor(o*T(o));return n>=l}function Q(t){return t.role==="tool"}function Z(t,e,o){if(!(t.role!=="tool"||!t.tool_call_id))for(let n=o-1;n>=0;n--){const l=e[n];if(l&&l.role==="assistant"&&Array.isArray(l.tool_calls)){for(const s of l.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 tt(t,e=M){if(t.length===0)return{prunedCount:0,freedTokens:0};const o=Math.min(U,Math.floor(e*B)),n=Math.min(j,Math.floor(e*F));let l=0;const s=[],i=[];let u=0;for(let r=t.length-1;r>=0;r--){const c=t[r];if(c.role==="user"&&u++,u<2||!Q(c))continue;const f=Z(c,t,r);if(f&&G.has(f))continue;const a=typeof c.content=="string"?c.content:"",p=g(a);if(l+=p,l>o){const h=f?K(f):L,d={msg:c,tokens:p,name:f??""};h<=1?i.push(d):s.push(d)}}s.sort((r,c)=>c.tokens-r.tokens),i.sort((r,c)=>r.tokens-c.tokens);const m=[];let _=0;for(const r of s){if(_>=n)break;_+=r.tokens,m.push(r.msg)}if(_<n){for(const r of i)if(_+=r.tokens,m.push(r.msg),_>=n)break}if(_<n)return{prunedCount:0,freedTokens:0};for(const r of m)r.content="[Old tool result content cleared]";return{prunedCount:m.length,freedTokens:_}}function w(t){return t.role==="system"&&typeof t.content=="string"&&t.content.startsWith(E)}function v(t,e){const o=typeof t.content=="string"?t.content:Array.isArray(t.content)?t.content.map(s=>typeof s=="object"&&s!==null?JSON.stringify(s):String(s)).join(" "):"",n=o.length>b?`${o.slice(0,b)}\u2026`:o,l=[`${e+1}. ${t.role}`];if(t.tool_calls&&Array.isArray(t.tool_calls)&&t.tool_calls.length>0){const s=t.tool_calls.map(i=>{if(typeof i=="object"&&i!==null){const u=i.function;return u?String(u.name??""):""}return""}).filter(Boolean).join(", ");s&&l.push(`tool_calls=${s}`)}return t.tool_call_id&&l.push(`tool_call_id=${t.tool_call_id}`),n&&l.push(`content=${n}`),l.join(" | ")}async function et(t,e){const o=t.filter(r=>r.role==="system"&&!w(r)),n=t.filter(r=>r.role!=="system"||w(r)),l=Math.max(0,n.length-D);if(l===0)return 0;const s=n.slice(0,l);let i=n.slice(l);const u=new Set;for(const r of i)if(r.role==="assistant"&&r.tool_calls?.length)for(const c of r.tool_calls)typeof c=="object"&&c!==null&&typeof c.id=="string"&&u.add(c.id);i=i.filter(r=>r.role==="tool"&&r.tool_call_id?u.has(r.tool_call_id):!0);let m=!0;for(;m;){m=!1;const r=new Set;for(const a of i)if(a.role==="assistant"&&a.tool_calls?.length)for(const p of a.tool_calls)typeof p=="object"&&p!==null&&typeof p.id=="string"&&r.add(p.id);const c=new Set;for(const a of i)a.role==="tool"&&a.tool_call_id&&c.add(a.tool_call_id);const f=i.filter(a=>{if(a.role==="tool"&&a.tool_call_id)return r.has(a.tool_call_id);if(a.role==="assistant"&&a.tool_calls?.length){const p=new Set;for(const d of a.tool_calls)typeof d=="object"&&d!==null&&typeof d.id=="string"&&p.add(d.id);if(p.size===0)return!0;let h=!0;for(const d of p)if(!c.has(d)){h=!1;break}return h}return!0});f.length!==i.length&&(m=!0,i=f)}if(i.length===0)return 0;let _=null;if(e?.llmSummarizer)try{const r=s.map((c,f)=>v(c,f)).join(`
3
- `);_=await e.llmSummarizer({conversationText:r,messageCount:l,contextLimit:e.contextLimit??M})}catch{_=null}if(t.length=0,t.push(...o),_!==null)t.push({role:"system",content:[E,`${l} earlier conversation messages were summarized by LLM to free context space.`,"Preserve the user's goal, decisions, tool results, file paths, errors, and unresolved tasks from this summary.","Recent messages below remain authoritative.","",_].join(`
4
- `)});else{const c=s.map((f,a)=>v(f,a)).join(`
5
- `).slice(0,$);t.push({role:"system",content:[E,`${l} earlier conversation messages were summarized to free context space.`,"Preserve the user's goal, decisions, tool results, file paths, errors, and unresolved tasks from this summary.","Recent messages below remain authoritative.","",c].join(`
6
- `)})}return t.push(...i),l}function ot(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 o=t.length;for(let i=e+1;i<t.length;i++)if(t[i].role==="user"){o=i;break}if(o>=t.length)return 0;const n=new Set;for(let i=e;i<o;i++){const u=t[i];if(u.role==="assistant"&&Array.isArray(u.tool_calls))for(const m of u.tool_calls)typeof m=="object"&&m!==null&&typeof m.id=="string"&&n.add(m.id)}const l=o-e;t.splice(e,l);let s=0;if(n.size>0)for(let i=t.length-1;i>=e;i--){const u=t[i];u.role==="tool"&&u.tool_call_id&&n.has(u.tool_call_id)&&(t.splice(i,1),s++)}return l+s}async function at(t,e,o=C,n){const l=N(t),s=t.length,i=x(t);let u="none",m=0,_=0,r=0,c=!1;n?.onPhase&&n.onPhase({phase:"prune_start",messageCount:t.length});const f=tt(t,e);f.prunedCount>0&&(u="prune",m=f.prunedCount,r+=f.freedTokens),n?.onPhase&&n.onPhase({phase:"prune_end",prunedCount:f.prunedCount,freedTokens:f.freedTokens});const a=x(t);if((n?.actualUsedTokens?Math.max(a,Math.max(n.actualUsedTokens,i)-r):a)>=Math.floor(e*T(e))){n?.onPhase&&n.onPhase({phase:"summarize_start",messageCount:t.length});const R=await et(t,{llmSummarizer:n?.llmSummarizer,contextLimit:e});if(R>0){u=u==="prune"?"prune+summarize":"summarize",_=R;const O=x(t);r=Math.max(r,i-O),c=!!t.find(I=>I.role==="system"&&typeof I.content=="string"&&I.content.includes("summarized by LLM"))}else{const O=ot(t);if(O>0){u=u==="prune"?"prune+summarize":"summarize",_=O;const k=x(t);r=Math.max(r,i-k)}}n?.onPhase&&n.onPhase({phase:"summarize_end",summarizedCount:_,usedLLM:c})}const h=N(t),d=t.length,P=x(t);return u==="none"?{strategy:"none",freedTokens:0,sizeBeforeKB:l,sizeAfterKB:l,tokensBefore:i,tokensAfter:P,messageCountBefore:s,messageCountAfter:d,prunedToolMessages:0,summarizedMessages:0}:{strategy:u,freedTokens:r,sizeBeforeKB:l,sizeAfterKB:h,tokensBefore:i,tokensAfter:P,messageCountBefore:s,messageCountAfter:d,prunedToolMessages:m,summarizedMessages:_}}export{nt as COMPACTION_BUFFER,it as COMPACTION_LLM_PROMPT_TEMPLATE,rt as COMPACTION_TRIGGER_RATIO,j as PRUNE_MINIMUM,U as PRUNE_PROTECT,lt as calculateCompactionThreshold,N as conversationSizeKB,x as estimateConversationTokens,q as estimateTextTokens,g as estimateTokens,T as getCompactionTriggerRatio,ct as isOverflow,ut as isOverflowByActualUsage,st as lookupModelLimits,at as performCompaction,tt as pruneToolOutputs,ot as snipOldestMessageGroup,et as summarizeConversation};
1
+ const nt=2e4,rt=.55,z=[[32e3,.7],[128e3,.75],[512e3,.8],[Number.POSITIVE_INFINITY,.85]];function T(t){if(t<=0)return .55;for(const[e,o]of z)if(t<e)return o;return .85}const U=4e4,j=2e4,B=.5,F=.1,G=new Set(["skill","todo_write","todo_read"]),y={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},L=2;function K(t){if(!t)return L;if(y[t]!==void 0)return y[t];const e=Object.keys(y).filter(o=>t.startsWith(o)).sort((o,n)=>n.length-o.length);return e.length>0?y[e[0]]:L}const M=128e3,C=8192,D=8,W=6e3,R=500,k="ACode context compaction summary:",it=["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
+ `),$=1.5,E=4,J=1.15,X=2e3,H=8;function lt(t,e,o){const n=Math.floor(t*T(t)),l=o??t,s=Math.min(2e4,e),i=l-s;return Math.min(n,i)}const g={"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 st(t,e){if(e?.contextLimit&&e.contextLimit>0)return{contextLimit:e.contextLimit,maxOutput:e.maxOutput??C};if(!t)return{contextLimit:M,maxOutput:C};const o=t.toLowerCase().trim();if(g[o])return g[o];const n=Object.keys(g).filter(l=>o.startsWith(l)).sort((l,s)=>s.length-l.length);return n.length>0?g[n[0]]:{contextLimit:M,maxOutput:C}}function q(t){if(!t)return 0;let e=0,o=0;for(const n of t)n>"\xFF"?e++:o++;return Math.ceil(e/$+o/E)}function A(t){return t?Math.ceil(q(t)*J):0}function V(t){if(typeof t=="object"&&t!==null){const e=t;return e.type==="text"&&typeof e.text=="string"?A(e.text):e.type==="image_url"||e.type==="document"?X:Math.ceil(JSON.stringify(t).length/E)}return typeof t=="string"?A(t):0}function Y(t){let e=16;if(typeof t.content=="string")e+=t.content.length*2;else if(Array.isArray(t.content))for(const o of t.content)typeof o=="object"&&o!==null&&(e+=JSON.stringify(o).length);return t.tool_calls&&(e+=JSON.stringify(t.tool_calls).length),t.tool_call_id&&(e+=t.tool_call_id.length),e}function x(t){let e=0;for(const o of t){if(typeof o.content=="string")e+=A(o.content);else if(Array.isArray(o.content))for(const n of o.content)e+=V(n);o.tool_calls&&(e+=H+Math.ceil(JSON.stringify(o.tool_calls).length/E))}return e}function b(t){let e=0;for(const o of t)e+=Y(o);return Math.round(e/1024*10)/10}function at(t,e,o){if(e<=0)return!1;const n=x(t),l=Math.floor(e*T(e));return n>=l}function ct(t,e,o){if(o<=0)return!1;const n=t+e,l=Math.floor(o*T(o));return n>=l}function Q(t){return t.role==="tool"}function Z(t,e,o){if(!(t.role!=="tool"||!t.tool_call_id))for(let n=o-1;n>=0;n--){const l=e[n];if(l&&l.role==="assistant"&&Array.isArray(l.tool_calls)){for(const s of l.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 tt(t,e=M){if(t.length===0)return{prunedCount:0,freedTokens:0};const o=Math.min(U,Math.floor(e*B)),n=Math.min(j,Math.floor(e*F));let l=0;const s=[],i=[];let c=0;for(let r=t.length-1;r>=0;r--){const a=t[r];if(a.role==="user"&&c++,c<2||!Q(a))continue;const f=Z(a,t,r);if(f&&G.has(f))continue;const u=typeof a.content=="string"?a.content:"",p=A(u);if(l+=p,l>o){const h=f?K(f):L,d={msg:a,tokens:p,name:f??""};h<=1?i.push(d):s.push(d)}}s.sort((r,a)=>a.tokens-r.tokens),i.sort((r,a)=>r.tokens-a.tokens);const m=[];let _=0;for(const r of s){if(_>=n)break;_+=r.tokens,m.push(r.msg)}if(_<n){for(const r of i)if(_+=r.tokens,m.push(r.msg),_>=n)break}if(_<n)return{prunedCount:0,freedTokens:0};for(const r of m)r.content="[Old tool result content cleared]";return{prunedCount:m.length,freedTokens:_}}function N(t){return t.role==="system"&&typeof t.content=="string"&&t.content.startsWith(k)}function v(t,e){const o=typeof t.content=="string"?t.content:Array.isArray(t.content)?t.content.map(s=>typeof s=="object"&&s!==null?JSON.stringify(s):String(s)).join(" "):"",n=o.length>R?`${o.slice(0,R)}\u2026`:o,l=[`${e+1}. ${t.role}`];if(t.tool_calls&&Array.isArray(t.tool_calls)&&t.tool_calls.length>0){const s=t.tool_calls.map(i=>{if(typeof i=="object"&&i!==null){const c=i.function;return c?String(c.name??""):""}return""}).filter(Boolean).join(", ");s&&l.push(`tool_calls=${s}`)}return t.tool_call_id&&l.push(`tool_call_id=${t.tool_call_id}`),n&&l.push(`content=${n}`),l.join(" | ")}async function et(t,e){const o=t.filter(r=>r.role==="system"&&!N(r)),n=t.filter(r=>r.role!=="system"||N(r)),l=Math.max(0,n.length-D);if(l===0)return 0;const s=n.slice(0,l);let i=n.slice(l);const c=new Set;for(const r of i)if(r.role==="assistant"&&r.tool_calls?.length)for(const a of r.tool_calls)typeof a=="object"&&a!==null&&typeof a.id=="string"&&c.add(a.id);i=i.filter(r=>r.role==="tool"&&r.tool_call_id?c.has(r.tool_call_id):!0);let m=!0;for(;m;){m=!1;const r=new Set;for(const u of i)if(u.role==="assistant"&&u.tool_calls?.length)for(const p of u.tool_calls)typeof p=="object"&&p!==null&&typeof p.id=="string"&&r.add(p.id);const a=new Set;for(const u of i)u.role==="tool"&&u.tool_call_id&&a.add(u.tool_call_id);const f=i.filter(u=>{if(u.role==="tool"&&u.tool_call_id)return r.has(u.tool_call_id);if(u.role==="assistant"&&u.tool_calls?.length){const p=new Set;for(const d of u.tool_calls)typeof d=="object"&&d!==null&&typeof d.id=="string"&&p.add(d.id);if(p.size===0)return!0;let h=!0;for(const d of p)if(!a.has(d)){h=!1;break}return h}return!0});f.length!==i.length&&(m=!0,i=f)}if(i.length===0)return 0;let _=null;if(e?.llmSummarizer)try{const r=s.map((a,f)=>v(a,f)).join(`
3
+ `);_=await e.llmSummarizer({conversationText:r,messageCount:l,contextLimit:e.contextLimit??M})}catch{_=null}if(t.length=0,t.push(...o),_!==null)t.push({role:"system",content:[k,`${l} 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.","",_].join(`
4
+ `)});else{const a=s.map((f,u)=>v(f,u)).join(`
5
+ `).slice(0,W);t.push({role:"system",content:[k,`${l} 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.","",a].join(`
6
+ `)})}return t.push(...i),l}function ot(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 o=t.length;for(let i=e+1;i<t.length;i++)if(t[i].role==="user"){o=i;break}if(o>=t.length)return 0;const n=new Set;for(let i=e;i<o;i++){const c=t[i];if(c.role==="assistant"&&Array.isArray(c.tool_calls))for(const m of c.tool_calls)typeof m=="object"&&m!==null&&typeof m.id=="string"&&n.add(m.id)}const l=o-e;t.splice(e,l);let s=0;if(n.size>0)for(let i=t.length-1;i>=e;i--){const c=t[i];c.role==="tool"&&c.tool_call_id&&n.has(c.tool_call_id)&&(t.splice(i,1),s++)}return l+s}async function ut(t,e,o=C,n){const l=b(t),s=t.length,i=x(t);let c="none",m=0,_=0,r=0,a=!1;n?.onPhase&&n.onPhase({phase:"prune_start",messageCount:t.length});const f=tt(t,e);f.prunedCount>0&&(c="prune",m=f.prunedCount,r+=f.freedTokens),n?.onPhase&&n.onPhase({phase:"prune_end",prunedCount:f.prunedCount,freedTokens:f.freedTokens});const u=x(t);if((n?.actualUsedTokens?Math.max(u,Math.max(n.actualUsedTokens,i)-r):u)>=Math.floor(e*T(e))){n?.onPhase&&n.onPhase({phase:"summarize_start",messageCount:t.length});const S=await et(t,{llmSummarizer:n?.llmSummarizer,contextLimit:e});if(S>0){c=c==="prune"?"prune+summarize":"summarize",_=S;const O=x(t);r=Math.max(r,i-O),a=!!t.find(I=>I.role==="system"&&typeof I.content=="string"&&I.content.includes("summarized by LLM"))}else{const O=ot(t);if(O>0){c=c==="prune"?"prune+summarize":"summarize",_=O;const P=x(t);r=Math.max(r,i-P)}}n?.onPhase&&n.onPhase({phase:"summarize_end",summarizedCount:_,usedLLM:a})}const h=b(t),d=t.length,w=x(t);return c==="none"?{strategy:"none",freedTokens:0,sizeBeforeKB:l,sizeAfterKB:l,tokensBefore:i,tokensAfter:w,messageCountBefore:s,messageCountAfter:d,prunedToolMessages:0,summarizedMessages:0}:{strategy:c,freedTokens:r,sizeBeforeKB:l,sizeAfterKB:h,tokensBefore:i,tokensAfter:w,messageCountBefore:s,messageCountAfter:d,prunedToolMessages:m,summarizedMessages:_}}export{nt as COMPACTION_BUFFER,it as COMPACTION_LLM_PROMPT_TEMPLATE,rt as COMPACTION_TRIGGER_RATIO,j as PRUNE_MINIMUM,U as PRUNE_PROTECT,lt as calculateCompactionThreshold,b as conversationSizeKB,x as estimateConversationTokens,q as estimateTextTokens,A as estimateTokens,T as getCompactionTriggerRatio,at as isOverflow,ct as isOverflowByActualUsage,st as lookupModelLimits,ut as performCompaction,tt as pruneToolOutputs,ot as snipOldestMessageGroup,et as summarizeConversation};
7
7
 
@@ -9,6 +9,7 @@ export * from './sub-agent-types.js';
9
9
  export * from './sub-agent-store.js';
10
10
  export * from './sub-agent-manager.js';
11
11
  export * from './sub-agent-tools.js';
12
+ export * from './terminal-types.js';
12
13
  export * from './parsers/types.js';
13
14
  export * from './parsers/tree-sitter-loader.js';
14
15
  export * from './parsers/ast-cache.js';
@@ -1,2 +1,2 @@
1
- export*from"./commands/commandRegistry.js";export*from"./commands/commandLoader.js";export*from"./commands/commandParser.js";export*from"./config.js";export*from"./hooks/hookBus.js";export*from"./runtime.js";export*from"./types.js";export*from"./sub-agent-types.js";export*from"./sub-agent-store.js";export*from"./sub-agent-manager.js";export*from"./sub-agent-tools.js";export*from"./parsers/types.js";export*from"./parsers/tree-sitter-loader.js";export*from"./parsers/ast-cache.js";export*from"./parsers/language-detector.js";export*from"./parsers/language-queries.js";export*from"./parsers/symbol-extractor.js";export*from"./built-in-symbols-tool.js";
1
+ export*from"./commands/commandRegistry.js";export*from"./commands/commandLoader.js";export*from"./commands/commandParser.js";export*from"./config.js";export*from"./hooks/hookBus.js";export*from"./runtime.js";export*from"./types.js";export*from"./sub-agent-types.js";export*from"./sub-agent-store.js";export*from"./sub-agent-manager.js";export*from"./sub-agent-tools.js";export*from"./terminal-types.js";export*from"./parsers/types.js";export*from"./parsers/tree-sitter-loader.js";export*from"./parsers/ast-cache.js";export*from"./parsers/language-detector.js";export*from"./parsers/language-queries.js";export*from"./parsers/symbol-extractor.js";export*from"./built-in-symbols-tool.js";
2
2
 
@@ -32,6 +32,8 @@ export declare class ACodeRuntime extends EventEmitter {
32
32
  private abortRequested;
33
33
 
34
34
  private pendingAwaitedSubIds;
35
+
36
+ private pendingAwaitedBgTaskIds;
35
37
  private sessionCompleteEmitted;
36
38
  private contextVersion;
37
39
  private readonly stopWaiters;
@@ -84,12 +86,16 @@ export declare class ACodeRuntime extends EventEmitter {
84
86
 
85
87
  private buildSubAgentToolDeps;
86
88
 
89
+ private buildAwaitCompleteDeps;
90
+
87
91
  submitQuestionAnswer(toolCallId: string, answers: Record<string, string>): boolean;
88
92
 
89
93
  private rejectAllQuestionWaiters;
90
94
 
91
95
  private cancelPendingAwaitedSubAgents;
92
96
 
97
+ private cancelPendingAwaitedBgTasks;
98
+
93
99
  stop(): Promise<void>;
94
100
  private resolveCommandDirs;
95
101
  private runModelTurn;