aws-runtime-bridge 1.9.168 → 1.9.170

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 (82) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/dist/adapter/AcodeSdkAdapter.d.ts +46 -0
  3. package/dist/adapter/AcodeSdkAdapter.js +4 -4
  4. package/dist/adapter/ClaudeSdkAdapter.js +2 -2
  5. package/dist/adapter/types.d.ts +7 -0
  6. package/dist/config.d.ts +6 -0
  7. package/dist/config.js +2 -2
  8. package/dist/index.js +1 -1
  9. package/dist/routes/agent-state.d.ts +2 -0
  10. package/dist/routes/agent-state.js +2 -0
  11. package/dist/routes/capabilities.js +1 -1
  12. package/dist/routes/debug-mount.d.ts +2 -0
  13. package/dist/routes/debug-mount.js +2 -0
  14. package/dist/routes/mcp.js +1 -1
  15. package/dist/routes/plugins.js +1 -1
  16. package/dist/routes/skills.js +1 -1
  17. package/dist/routes/terminal.js +28 -32
  18. package/dist/services/acode-bg-manager.d.ts +2 -0
  19. package/dist/services/agent-capability-sync.js +1 -1
  20. package/dist/services/debug-mount.d.ts +122 -0
  21. package/dist/services/debug-mount.js +2 -0
  22. package/dist/services/desktop-mcp-manager.js +1 -1
  23. package/dist/services/instance-ai-config-service.js +1 -1
  24. package/dist/services/instance-features.d.ts +4 -0
  25. package/dist/services/instance-features.js +1 -1
  26. package/dist/services/instance-init-service.js +1 -1
  27. package/dist/services/mcp-deploy.d.ts +31 -0
  28. package/dist/services/mcp-deploy.js +4 -3
  29. package/dist/services/mcp-env-injector.d.ts +24 -0
  30. package/dist/services/mcp-env-injector.js +1 -1
  31. package/dist/services/mcp-package.d.ts +35 -0
  32. package/dist/services/mcp-package.js +2 -0
  33. package/dist/services/mcp-probe-client.d.ts +25 -0
  34. package/dist/services/mcp-probe-client.js +2 -0
  35. package/dist/services/panel-env.d.ts +5 -0
  36. package/dist/services/panel-env.js +1 -1
  37. package/dist/services/plugin-deployment.d.ts +36 -0
  38. package/dist/services/plugin-deployment.js +3 -0
  39. package/dist/services/plugin-event-buffer.js +2 -1
  40. package/dist/services/plugin-fs.d.ts +5 -0
  41. package/dist/services/plugin-fs.js +2 -0
  42. package/dist/services/plugin-handler-adapter.d.ts +7 -0
  43. package/dist/services/plugin-handler-adapter.js +3 -0
  44. package/dist/services/plugin-listener-runner.d.ts +18 -0
  45. package/dist/services/plugin-listener-runner.js +8 -0
  46. package/dist/services/plugin-loader.d.ts +32 -0
  47. package/dist/services/plugin-loader.js +2 -0
  48. package/dist/services/plugin-manager.d.ts +17 -136
  49. package/dist/services/plugin-manager.js +4 -15
  50. package/dist/services/plugin-manifest.d.ts +83 -0
  51. package/dist/services/plugin-manifest.js +2 -0
  52. package/dist/services/plugin-runtime.d.ts +67 -0
  53. package/dist/services/plugin-runtime.js +1 -0
  54. package/dist/services/skill-manager.d.ts +15 -0
  55. package/dist/services/skill-manager.js +3 -2
  56. package/dist/types.d.ts +6 -0
  57. package/dist/utils/mcp-utils.js +1 -1
  58. package/package/acode/dist/compaction.d.ts +35 -1
  59. package/package/acode/dist/compaction.js +6 -6
  60. package/package/acode/dist/plugin-types.d.ts +6 -27
  61. package/package/acode/dist/runtime.d.ts +37 -0
  62. package/package/acode/dist/runtime.js +31 -30
  63. package/package/acode/dist/tool-group-manager.d.ts +10 -0
  64. package/package/acode/dist/tool-group-manager.js +5 -10
  65. package/package/acode/dist/types.d.ts +2 -0
  66. package/package/aws-client-agent-mcp/dist/ability-market-tools.d.ts +18 -0
  67. package/package/aws-client-agent-mcp/dist/ability-market-tools.js +2 -0
  68. package/package/aws-client-agent-mcp/dist/agent-client.d.ts +15 -4
  69. package/package/aws-client-agent-mcp/dist/agent-client.js +1 -1
  70. package/package/aws-client-agent-mcp/dist/http-client.d.ts +2 -0
  71. package/package/aws-client-agent-mcp/dist/http-client.js +1 -1
  72. package/package/aws-client-agent-mcp/dist/mcp-server.d.ts +0 -7
  73. package/package/aws-client-agent-mcp/dist/mcp-server.js +12 -12
  74. package/package/aws-client-agent-mcp/dist/mcp-tools.d.ts +3 -0
  75. package/package/aws-client-agent-mcp/dist/mcp-tools.js +20 -20
  76. package/package/aws-client-agent-mcp/dist/memory-store.d.ts +1 -1
  77. package/package/aws-client-agent-mcp/dist/memory-store.js +2 -2
  78. package/package/aws-client-agent-mcp/dist/memory-tools.js +7 -7
  79. package/package/aws-client-agent-mcp/dist/tool-groups.js +2 -2
  80. package/package/aws-client-agent-mcp/dist/types.d.ts +2 -21
  81. package/package.json +3 -2
  82. package/dist/services/builtin-commands/create-plugin.md +0 -44
@@ -1,3 +1,4 @@
1
- import{promises as g,cpSync as S,existsSync as f,mkdirSync as v,readFileSync as j,readdirSync as E,rmSync as m,writeFileSync as I}from"node:fs";import i from"node:path";import{getBridgeTemplateSkillsDir as b}from"../config.js";import{extractSkillZip as x,resolveSkillSourceDirFromExtractRoot as A}from"../utils/file-utils.js";import{createLogger as L}from"../utils/logger.js";import{getSkillFarmRoot as N,syncAgentSkillFarm as _}from"./agent-capability-sync.js";import{setDeployedDefaultsProvider as K,reconcileDefaultsFromDeployed as z}from"./capability-config.js";import{getAgentInitRoot as $}from"./instance-state.js";const h=L("skill-manager");function F(l){return typeof l=="string"&&l.length>0&&l.length<=128&&/^[a-zA-Z0-9_.-]+$/.test(l)}const O=1;class p{static getInstance(){return this._instance||(this._instance=new p(i.join(b(),"deployed"))),this._instance}constructor(r){this.rootDir=r}manifestFile(){return i.join(this.rootDir,"manifest.json")}skillDir(r){const t=i.join(this.rootDir,r),e=i.resolve(this.rootDir);if(i.resolve(t)!==i.join(e,r))throw new Error(`\u6280\u80FD\u76EE\u5F55\u8D8A\u51FA\u90E8\u7F72\u533A: ${r}`);return t}isHealthy(r){return f(i.join(this.skillDir(r),"SKILL.md"))}readManifest(){try{const r=JSON.parse(j(this.manifestFile(),"utf8"));return Array.isArray(r.skills)?r.skills.filter(t=>t&&t.skillName):[]}catch{return[]}}writeManifest(r){v(this.rootDir,{recursive:!0}),I(this.manifestFile(),`${JSON.stringify({version:O,skills:r},null,2)}
2
- `,"utf8")}async saveSharedSkill(r,t,e=!0,o,D){if(!r||r.length===0)return{ok:!1,error:"zip \u5305\u5185\u5BB9\u4E3A\u7A7A"};const y=i.join($("_tmp"),`skill-deploy-${Date.now()}-${Math.random().toString(36).slice(2,8)}`);try{await R(r,y);const n=await A(y),a=i.basename(i.resolve(n)),M=String(t||"").replace(/\.zip$/i,"").trim(),s=D&&D.trim()||(a&&!a.startsWith("skill-deploy-")?a:"")||M;if(!F(s))return{ok:!1,error:`\u6280\u80FD\u540D\u975E\u6CD5: ${JSON.stringify(s)}`};if(!f(i.join(n,"SKILL.md")))return{ok:!1,error:`\u6280\u80FD\u5305\u7F3A\u5C11 SKILL.md: ${t}`};const k=this.readManifest().find(d=>d.skillName===s);if(k&&k.sha256===o&&this.isHealthy(s))return{ok:!0,skillName:s};v(this.rootDir,{recursive:!0});const c=this.skillDir(s),u=i.join(this.rootDir,`.old-${s}-${Date.now()}-${Math.random().toString(36).slice(2,8)}`);if(f(c))try{S(c,u,{recursive:!0})}catch{m(c,{recursive:!0,force:!0})}try{S(n,c,{recursive:!0})}catch(d){throw f(u)&&(m(c,{recursive:!0,force:!0}),S(u,c,{recursive:!0})),d}f(u)&&m(u,{recursive:!0,force:!0});const w=this.readManifest().filter(d=>d.skillName!==s);return w.push({skillName:s,zipFile:k?.zipFile??`${s}.zip`,fileName:t,defaultEnabled:e,sha256:o}),this.writeManifest(w),h.info("[shared] \u6280\u80FD\u5DF2\u90E8\u7F72\u5230 bridge: %s\uFF08\u6765\u6E90 %s%s\uFF09",s,t,o?`, sha256=${o.slice(0,12)}\u2026`:""),this.applyToKnownAgents(),{ok:!0,skillName:s}}catch(n){const a=n instanceof Error?n.message:String(n);return h.warn("[shared] \u6280\u80FD\u90E8\u7F72\u5931\u8D25\uFF08%s\uFF09: %s",t,a),{ok:!1,error:`\u6280\u80FD\u90E8\u7F72\u5931\u8D25: ${a}`}}finally{try{m(y,{recursive:!0,force:!0})}catch{}}}async removeDeployedSkill(r){if(!F(r))return{ok:!1,error:"skillName \u975E\u6CD5"};const t=this.readManifest().filter(e=>e.skillName!==r);this.writeManifest(t);try{m(this.skillDir(r),{recursive:!0,force:!0})}catch(e){return{ok:!1,error:`\u90E8\u7F72\u76EE\u5F55\u6E05\u7406\u5931\u8D25: ${e instanceof Error?e.message:String(e)}`}}return this.applyToKnownAgents(),h.info("[shared] \u6280\u80FD\u5DF2\u4ECE bridge \u79FB\u9664\u90E8\u7F72: %s",r),{ok:!0}}listDeployed(){return this.readManifest().filter(r=>!/^skill-deploy-/.test(r.skillName)).map(r=>({...r,deployed:this.isHealthy(r.skillName)}))}deployedDefaultEnabled(){const r={};for(const t of this.readManifest())/^skill-deploy-/.test(t.skillName)||(r[t.skillName]=t.defaultEnabled);return r}applyToKnownAgents(){const r=new Set,t=N();try{if(f(t))for(const e of E(t))e.startsWith(".")||r.add(e)}catch{}for(const e of r)try{_(e)}catch(o){h.warn("[shared] \u540C\u6B65\u6280\u80FD\u519C\u573A\u5931\u8D25 agent=%s: %s",e,o instanceof Error?o.message:String(o))}}}p._instance=null;async function R(l,r){const t=i.join($("_tmp"),`skill-${Date.now()}-${Math.random().toString(36).slice(2,8)}.zip`);await g.mkdir(i.dirname(t),{recursive:!0}),await g.writeFile(t,l);try{await x(t,r)}finally{await g.rm(t,{force:!0}).catch(()=>{})}}const T=p.getInstance();K("skills",()=>T.deployedDefaultEnabled());const G=()=>z("skills");export{p as SkillManager,F as isValidSkillName,G as reconcileSkillsDefaultsFromDeployed,T as skillManager};
1
+ import{promises as F,cpSync as S,existsSync as l,mkdirSync as D,readFileSync as E,readdirSync as x,rmSync as f,writeFileSync as P}from"node:fs";import i from"node:path";import{getBridgeInstancePrivateSkillsDir as b,getBridgeInstancePrivateSkillsManifest as O,getBridgeTemplateSkillsDir as _}from"../config.js";import{extractSkillZip as z,resolveSkillSourceDirFromExtractRoot as N}from"../utils/file-utils.js";import{createLogger as J}from"../utils/logger.js";import{getSkillFarmRoot as R,syncAgentSkillFarm as j}from"./agent-capability-sync.js";import{setDeployedDefaultsProvider as T,reconcileDefaultsFromDeployed as H}from"./capability-config.js";import{getAgentInitRoot as L}from"./instance-state.js";const d=J("skill-manager");function w(v){return typeof v=="string"&&v.length>0&&v.length<=128&&/^[a-zA-Z0-9_.-]+$/.test(v)}const A=1;class ${static getInstance(){return this._instance||(this._instance=new $(i.join(_(),"deployed"))),this._instance}constructor(r){this.rootDir=r}manifestFile(){return i.join(this.rootDir,"manifest.json")}skillDir(r){const e=i.join(this.rootDir,r),t=i.resolve(this.rootDir);if(i.resolve(e)!==i.join(t,r))throw new Error(`\u6280\u80FD\u76EE\u5F55\u8D8A\u51FA\u90E8\u7F72\u533A: ${r}`);return e}isHealthy(r){return l(i.join(this.skillDir(r),"SKILL.md"))}readManifest(){try{const r=JSON.parse(E(this.manifestFile(),"utf8"));return Array.isArray(r.skills)?r.skills.filter(e=>e&&e.skillName):[]}catch{return[]}}writeManifest(r){D(this.rootDir,{recursive:!0}),P(this.manifestFile(),`${JSON.stringify({version:A,skills:r},null,2)}
2
+ `,"utf8")}async saveSharedSkill(r,e,t=!0,o,g){if(!r||r.length===0)return{ok:!1,error:"zip \u5305\u5185\u5BB9\u4E3A\u7A7A"};const y=i.join(L("_tmp"),`skill-deploy-${Date.now()}-${Math.random().toString(36).slice(2,8)}`);try{await K(r,y);const n=await N(y),a=i.basename(i.resolve(n)),M=String(e||"").replace(/\.zip$/i,"").trim(),s=g&&g.trim()||(a&&!a.startsWith("skill-deploy-")?a:"")||M;if(!w(s))return{ok:!1,error:`\u6280\u80FD\u540D\u975E\u6CD5: ${JSON.stringify(s)}`};if(!l(i.join(n,"SKILL.md")))return{ok:!1,error:`\u6280\u80FD\u5305\u7F3A\u5C11 SKILL.md: ${e}`};const c=this.readManifest().find(m=>m.skillName===s);if(c&&c.sha256===o&&this.isHealthy(s))return{ok:!0,skillName:s};D(this.rootDir,{recursive:!0});const u=this.skillDir(s),h=i.join(this.rootDir,`.old-${s}-${Date.now()}-${Math.random().toString(36).slice(2,8)}`);if(l(u))try{S(u,h,{recursive:!0})}catch{f(u,{recursive:!0,force:!0})}try{S(n,u,{recursive:!0})}catch(m){throw l(h)&&(f(u,{recursive:!0,force:!0}),S(h,u,{recursive:!0})),m}l(h)&&f(h,{recursive:!0,force:!0});const k=this.readManifest().filter(m=>m.skillName!==s);return k.push({skillName:s,zipFile:c?.zipFile??`${s}.zip`,fileName:e,defaultEnabled:t,sha256:o}),this.writeManifest(k),d.info("[shared] \u6280\u80FD\u5DF2\u90E8\u7F72\u5230 bridge: %s\uFF08\u6765\u6E90 %s%s\uFF09",s,e,o?`, sha256=${o.slice(0,12)}\u2026`:""),this.applyToKnownAgents(),{ok:!0,skillName:s}}catch(n){const a=n instanceof Error?n.message:String(n);return d.warn("[shared] \u6280\u80FD\u90E8\u7F72\u5931\u8D25\uFF08%s\uFF09: %s",e,a),{ok:!1,error:`\u6280\u80FD\u90E8\u7F72\u5931\u8D25: ${a}`}}finally{try{f(y,{recursive:!0,force:!0})}catch{}}}async removeDeployedSkill(r){if(!w(r))return{ok:!1,error:"skillName \u975E\u6CD5"};const e=this.readManifest().filter(t=>t.skillName!==r);this.writeManifest(e);try{f(this.skillDir(r),{recursive:!0,force:!0})}catch(t){return{ok:!1,error:`\u90E8\u7F72\u76EE\u5F55\u6E05\u7406\u5931\u8D25: ${t instanceof Error?t.message:String(t)}`}}return this.applyToKnownAgents(),d.info("[shared] \u6280\u80FD\u5DF2\u4ECE bridge \u79FB\u9664\u90E8\u7F72: %s",r),{ok:!0}}listDeployed(){return this.readManifest().filter(r=>!/^skill-deploy-/.test(r.skillName)).map(r=>({...r,deployed:this.isHealthy(r.skillName)}))}privateManifestFile(r){return O(r)}privateSkillDir(r,e){const t=i.resolve(b(r)),o=i.join(t,e);if(i.resolve(o)!==i.join(t,e))throw new Error(`\u79C1\u6709\u6280\u80FD\u76EE\u5F55\u8D8A\u51FA\u5B9E\u4F8B\u79C1\u6709\u533A: ${e}`);return o}readPrivateManifest(r){try{const e=JSON.parse(E(this.privateManifestFile(r),"utf8"));return Array.isArray(e.skills)?e.skills.filter(t=>t&&t.skillName):[]}catch{return[]}}writePrivateManifest(r,e){const t=this.privateManifestFile(r);D(i.dirname(t),{recursive:!0}),P(t,`${JSON.stringify({version:A,skills:e},null,2)}
3
+ `,"utf8")}async savePrivateSkill(r,e,t,o,g){if(!r)return{ok:!1,error:"agentId is required"};if(!e||e.length===0)return{ok:!1,error:"zip \u5305\u5185\u5BB9\u4E3A\u7A7A"};const y=i.join(L("_tmp"),`skill-private-${Date.now()}-${Math.random().toString(36).slice(2,8)}`);try{await K(e,y);const n=await N(y),a=i.basename(i.resolve(n)),M=String(t||"").replace(/\.zip$/i,"").trim(),s=g&&g.trim()||(a&&!a.startsWith("skill-private-")?a:"")||M;if(!w(s))return{ok:!1,error:`\u6280\u80FD\u540D\u975E\u6CD5: ${JSON.stringify(s)}`};if(!l(i.join(n,"SKILL.md")))return{ok:!1,error:`\u6280\u80FD\u5305\u7F3A\u5C11 SKILL.md: ${t}`};const c=this.privateSkillDir(r,s),u=b(r);D(u,{recursive:!0});const h=this.readPrivateManifest(r).find(p=>p.skillName===s);if(h&&h.sha256===o&&l(i.join(c,"SKILL.md")))return{ok:!0,skillName:s};const k=i.join(u,`.old-${s}-${Date.now()}-${Math.random().toString(36).slice(2,8)}`);if(l(c))try{S(c,k,{recursive:!0})}catch{f(c,{recursive:!0,force:!0})}try{S(n,c,{recursive:!0})}catch(p){throw l(k)&&(f(c,{recursive:!0,force:!0}),S(k,c,{recursive:!0})),p}l(k)&&f(k,{recursive:!0,force:!0});const m=this.readPrivateManifest(r).filter(p=>p.skillName!==s);m.push({skillName:s,zipFile:h?.zipFile??`${s}.zip`,fileName:t,defaultEnabled:!0,sha256:o}),this.writePrivateManifest(r,m),d.info("[private] agent=%s \u79C1\u6709\u6280\u80FD\u5DF2\u5B89\u88C5: %s\uFF08\u6765\u6E90 %s%s\uFF09",r,s,t,o?`, sha256=${o.slice(0,12)}\u2026`:"");try{j(r)}catch(p){d.warn("[private] agent=%s \u79C1\u6709\u6280\u80FD\u5B89\u88C5\u540E\u540C\u6B65\u519C\u573A\u5931\u8D25: %s",r,p instanceof Error?p.message:String(p))}return{ok:!0,skillName:s}}catch(n){const a=n instanceof Error?n.message:String(n);return d.warn("[private] \u79C1\u6709\u6280\u80FD\u5B89\u88C5\u5931\u8D25\uFF08%s\uFF09: %s",t,a),{ok:!1,error:`\u79C1\u6709\u6280\u80FD\u5B89\u88C5\u5931\u8D25: ${a}`}}finally{try{f(y,{recursive:!0,force:!0})}catch{}}}async removePrivateSkill(r,e){if(!r)return{ok:!1,error:"agentId is required"};if(!w(e))return{ok:!1,error:"skillName \u975E\u6CD5"};const t=this.readPrivateManifest(r).filter(o=>o.skillName!==e);this.writePrivateManifest(r,t);try{f(this.privateSkillDir(r,e),{recursive:!0,force:!0})}catch(o){return{ok:!1,error:`\u79C1\u6709\u6280\u80FD\u76EE\u5F55\u6E05\u7406\u5931\u8D25: ${o instanceof Error?o.message:String(o)}`}}try{j(r)}catch{}return d.info("[private] agent=%s \u79C1\u6709\u6280\u80FD\u5DF2\u79FB\u9664: %s",r,e),{ok:!0}}listPrivateSkills(r){return r?this.readPrivateManifest(r).filter(e=>!/^skill-private-/.test(e.skillName)).map(e=>({...e,deployed:l(i.join(this.privateSkillDir(r,e.skillName),"SKILL.md"))})):[]}deployedDefaultEnabled(){const r={};for(const e of this.readManifest())/^skill-deploy-/.test(e.skillName)||(r[e.skillName]=e.defaultEnabled);return r}applyToKnownAgents(){const r=new Set,e=R();try{if(l(e))for(const t of x(e))t.startsWith(".")||r.add(t)}catch{}for(const t of r)try{j(t)}catch(o){d.warn("[shared] \u540C\u6B65\u6280\u80FD\u519C\u573A\u5931\u8D25 agent=%s: %s",t,o instanceof Error?o.message:String(o))}}}$._instance=null;async function K(v,r){const e=i.join(L("_tmp"),`skill-${Date.now()}-${Math.random().toString(36).slice(2,8)}.zip`);await F.mkdir(i.dirname(e),{recursive:!0}),await F.writeFile(e,v);try{await z(e,r)}finally{await F.rm(e,{force:!0}).catch(()=>{})}}const I=$.getInstance();T("skills",()=>I.deployedDefaultEnabled());const U=()=>H("skills");export{$ as SkillManager,w as isValidSkillName,U as reconcileSkillsDefaultsFromDeployed,I as skillManager};
3
4
 
package/dist/types.d.ts CHANGED
@@ -42,11 +42,17 @@ export interface McpPayload {
42
42
  url?: string;
43
43
  args?: string[];
44
44
  env?: Record<string, string>;
45
+
46
+ headers?: Record<string, string>;
45
47
  enabled?: boolean;
46
48
 
47
49
  collapsed?: boolean;
48
50
 
49
51
  description?: string;
52
+
53
+ packageUrl?: string;
54
+
55
+ packageSha256?: string;
50
56
  installedAt?: string;
51
57
  }
52
58
  export interface McpServerConfig {
@@ -1,2 +1,2 @@
1
- import{randomUUID as i}from"node:crypto";import{parseBoolean as o}from"./validation.js";function d(r){if(!r||typeof r!="object")return null;const n=r,t=String(n.name||"").trim();return t?{id:String(n.id||i()),name:t,transport:String(n.transport||"stdio").trim().toLowerCase(),command:n.command===null||n.command===void 0?"":String(n.command),url:n.url===null||n.url===void 0?"":String(n.url),args:Array.isArray(n.args)?n.args.map(e=>String(e)):[],env:n.env&&typeof n.env=="object"?n.env:{},enabled:o(n.enabled,!0),collapsed:n.collapsed===!0,description:String(n.description||"").trim()||void 0,installedAt:n.installedAt||new Date().toISOString()}:null}export{d as normalizeMcpPayload};
1
+ import{randomUUID as a}from"node:crypto";import{parseBoolean as i}from"./validation.js";function l(r){if(!r||typeof r!="object")return null;const e=r,n=String(e.name||"").trim();return n?{id:String(e.id||a()),name:n,transport:String(e.transport||"stdio").trim().toLowerCase(),command:e.command===null||e.command===void 0?"":String(e.command),url:e.url===null||e.url===void 0?"":String(e.url),args:Array.isArray(e.args)?e.args.map(t=>String(t)):[],env:e.env&&typeof e.env=="object"?e.env:{},headers:e.headers&&typeof e.headers=="object"?e.headers:{},enabled:i(e.enabled,!0),collapsed:e.collapsed===!0,description:String(e.description||"").trim()||void 0,packageUrl:String(e.packageUrl||"").trim()||void 0,packageSha256:String(e.packageSha256||"").trim()||void 0,installedAt:e.installedAt||new Date().toISOString()}:null}export{l as normalizeMcpPayload};
2
2
 
@@ -10,6 +10,33 @@ export declare const PRUNE_PROTECT = 40000;
10
10
 
11
11
  export declare const PRUNE_MINIMUM = 20000;
12
12
 
13
+ export type CompactionPruneCategory = "fileReads" | "fileEdits" | "otherTools" | "commands" | "browser";
14
+
15
+ export declare const COMPACTION_PRUNE_CATEGORIES: readonly CompactionPruneCategory[];
16
+
17
+ export interface CompactionPlan {
18
+
19
+ pruneCategories?: CompactionPruneCategory[];
20
+
21
+ summarize?: boolean;
22
+ }
23
+
24
+ export declare function pruneCategoryOf(toolName: string): CompactionPruneCategory;
25
+
26
+ export interface CompactionPreview {
27
+
28
+ categories: Record<CompactionPruneCategory, {
29
+ messages: number;
30
+ tokens: number;
31
+ }>;
32
+
33
+ summarizableMessages: number;
34
+
35
+ totalTokens: number;
36
+ }
37
+
38
+ export declare function previewCompaction(messages: readonly ChatMessageLike[]): CompactionPreview;
39
+
13
40
  export declare const RUNTIME_RESOURCES_PREFIX = "ACode runtime resources:";
14
41
 
15
42
  export declare const COMPACTION_LLM_PROMPT_TEMPLATE: string;
@@ -89,7 +116,10 @@ export declare function isOverflow(messages: readonly ChatMessageLike[], context
89
116
 
90
117
  export declare function isOverflowByActualUsage(accumulatedInput: number, accumulatedOutput: number, contextLimit: number): boolean;
91
118
 
92
- export declare function pruneToolOutputs(messages: ChatMessageLike[], contextLimit?: number): {
119
+ export declare function pruneToolOutputs(messages: ChatMessageLike[], contextLimit?: number, options?: {
120
+ categories?: readonly CompactionPruneCategory[];
121
+ manual?: boolean;
122
+ }): {
93
123
  prunedCount: number;
94
124
  freedTokens: number;
95
125
  };
@@ -110,5 +140,9 @@ export declare function performCompaction(messages: ChatMessageLike[], contextLi
110
140
  onPhase?: (event: CompactionPhaseEvent) => void;
111
141
 
112
142
  actualUsedTokens?: number;
143
+
144
+ force?: boolean;
145
+
146
+ plan?: CompactionPlan;
113
147
  }): Promise<CompactionResult>;
114
148
  export {};
@@ -1,7 +1,7 @@
1
- const st=2e4,lt=.55,B=[[32e3,.7],[128e3,.75],[512e3,.8],[Number.POSITIVE_INFINITY,.85]];function T(t){if(t<=0)return .55;for(const[e,o]of B)if(t<e)return o;return .85}const j=4e4,F=2e4,G=.5,K=.1,W=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},k=2;function D(t){if(!t)return k;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]]:k}const M=128e3,C=8192,$=8,X=6e3,b=500,L="ACode context compaction summary:",J="ACode runtime resources:",ct=["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
- `),H=1.5,R=4,q=1.15,V=2e3,Y=8;function at(t,e,o){const n=Math.floor(t*T(t)),s=o??t,l=Math.min(2e4,e),i=s-l;return Math.min(n,i)}function ut(t,e){const o=e&&e>0?e:t;return o>0?o:t}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 ft(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(s=>o.startsWith(s)).sort((s,l)=>l.length-s.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/H+o/R)}function A(t){return t?Math.ceil(Q(t)*q):0}function Z(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"?V:Math.ceil(JSON.stringify(t).length/R)}return typeof t=="string"?A(t):0}function I(t){return Buffer.byteLength(t,"utf8")}function N(t){let e=16;if(typeof t.content=="string")e+=I(t.content);else if(Array.isArray(t.content))for(const o of t.content)typeof o=="object"&&o!==null&&(e+=I(JSON.stringify(o)));return t.tool_calls&&(e+=I(JSON.stringify(t.tool_calls))),t.tool_call_id&&(e+=I(t.tool_call_id)),e}function _t(t){let e=0;for(const o of t)e+=N(o);return 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+=Z(n);o.tool_calls&&(e+=Y+Math.ceil(JSON.stringify(o.tool_calls).length/R))}return e}function v(t){let e=0;for(const o of t)e+=N(o);return Math.round(e/1024*10)/10}function mt(t,e,o){if(e<=0)return!1;const n=x(t),s=Math.floor(e*T(e));return n>=s}function pt(t,e,o){if(o<=0)return!1;const n=t+e,s=Math.floor(o*T(o));return n>=s}function tt(t){return t.role==="tool"}function et(t,e,o){if(!(t.role!=="tool"||!t.tool_call_id))for(let n=o-1;n>=0;n--){const s=e[n];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 i=l.function;return i?String(i.name??""):void 0}}}}function ot(t,e=M){if(t.length===0)return{prunedCount:0,freedTokens:0};const o=Math.min(j,Math.floor(e*G)),n=Math.min(F,Math.floor(e*K));let s=0;const l=[],i=[];let a=0;for(let r=t.length-1;r>=0;r--){const c=t[r];if(c.role==="user"&&a++,a<2||!tt(c))continue;const _=et(c,t,r);if(_&&W.has(_))continue;const u=typeof c.content=="string"?c.content:"",p=A(u);if(s+=p,s>o){const h=_?D(_):k,d={msg:c,tokens:p,name:_??""};h<=1?i.push(d):l.push(d)}}l.sort((r,c)=>c.tokens-r.tokens),i.sort((r,c)=>r.tokens-c.tokens);const f=[];let m=0;for(const r of l){if(m>=n)break;m+=r.tokens,f.push(r.msg)}if(m<n){for(const r of i)if(m+=r.tokens,f.push(r.msg),m>=n)break}if(m<n)return{prunedCount:0,freedTokens:0};for(const r of f)r.content="[Old tool result content cleared]";return{prunedCount:f.length,freedTokens:m}}function z(t){return t.role==="system"&&typeof t.content=="string"&&t.content.startsWith(L)}function nt(t){return t.role==="system"&&typeof t.content=="string"&&t.content.startsWith(J)}function U(t,e){const o=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(" "):"",n=o.length>b?`${o.slice(0,b)}\u2026`:o,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(i=>{if(typeof i=="object"&&i!==null){const a=i.function;return a?String(a.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}`),n&&s.push(`content=${n}`),s.join(" | ")}async function rt(t,e){const o=t.filter(r=>r.role==="system"&&!z(r)&&!nt(r)),n=t.filter(r=>r.role!=="system"||z(r)),s=Math.max(0,n.length-$);if(s===0)return 0;const l=n.slice(0,s);let i=n.slice(s);const a=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"&&a.add(c.id);i=i.filter(r=>{if(r.role==="tool"){const c=typeof r.tool_call_id=="string"?r.tool_call_id.trim():"";return c!==""&&a.has(c)}return!0});let f=!0;for(;f;){f=!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 c=new Set;for(const u of i)u.role==="tool"&&u.tool_call_id&&c.add(u.tool_call_id);const _=i.filter(u=>{if(u.role==="tool"){const p=typeof u.tool_call_id=="string"?u.tool_call_id.trim():"";return p!==""&&r.has(p)}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(!c.has(d)){h=!1;break}return h}return!0});_.length!==i.length&&(f=!0,i=_)}if(i.length===0)return 0;let m=null;if(e?.llmSummarizer)try{const r=l.map((c,_)=>U(c,_)).join(`
3
- `);m=await e.llmSummarizer({conversationText:r,messageCount:s,contextLimit:e.contextLimit??M})}catch{m=null}if(t.length=0,t.push(...o),m!==null)t.push({role:"system",content:[L,`${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.","",m].join(`
4
- `)});else{const c=l.map((_,u)=>U(_,u)).join(`
5
- `).slice(0,X);t.push({role:"system",content:[L,`${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.","",c].join(`
6
- `)})}return t.push(...i),s}function it(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 a=t[i];if(a.role==="assistant"&&Array.isArray(a.tool_calls))for(const f of a.tool_calls)typeof f=="object"&&f!==null&&typeof f.id=="string"&&n.add(f.id)}const s=o-e;t.splice(e,s);let l=0;for(let i=t.length-1;i>=e;i--){const a=t[i];if(a.role!=="tool")continue;const f=typeof a.tool_call_id=="string"?a.tool_call_id.trim():"";(f===""||n.has(f))&&(t.splice(i,1),l++)}return s+l}async function dt(t,e,o=C,n){const s=v(t),l=t.length,i=x(t);let a="none",f=0,m=0,r=0,c=!1;n?.onPhase&&n.onPhase({phase:"prune_start",messageCount:t.length});const _=ot(t,e);_.prunedCount>0&&(a="prune",f=_.prunedCount,r+=_.freedTokens),n?.onPhase&&n.onPhase({phase:"prune_end",prunedCount:_.prunedCount,freedTokens:_.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 w=await rt(t,{llmSummarizer:n?.llmSummarizer,contextLimit:e});if(w>0){a=a==="prune"?"prune+summarize":"summarize",m=w;const O=x(t);r=Math.max(r,i-O),c=!!t.find(E=>E.role==="system"&&typeof E.content=="string"&&E.content.includes("summarized by LLM"))}else{const O=it(t);if(O>0){a=a==="prune"?"prune+summarize":"summarize",m=O;const P=x(t);r=Math.max(r,i-P)}}n?.onPhase&&n.onPhase({phase:"summarize_end",summarizedCount:m,usedLLM:c})}const h=v(t),d=t.length,S=x(t);return a==="none"?{strategy:"none",freedTokens:0,sizeBeforeKB:s,sizeAfterKB:s,tokensBefore:i,tokensAfter:S,messageCountBefore:l,messageCountAfter:d,prunedToolMessages:0,summarizedMessages:0}:{strategy:a,freedTokens:r,sizeBeforeKB:s,sizeAfterKB:h,tokensBefore:i,tokensAfter:S,messageCountBefore:l,messageCountAfter:d,prunedToolMessages:f,summarizedMessages:m}}export{st as COMPACTION_BUFFER,ct as COMPACTION_LLM_PROMPT_TEMPLATE,lt as COMPACTION_TRIGGER_RATIO,F as PRUNE_MINIMUM,j as PRUNE_PROTECT,J as RUNTIME_RESOURCES_PREFIX,at as calculateCompactionThreshold,_t as conversationSizeBytes,v as conversationSizeKB,x as estimateConversationTokens,Q as estimateTextTokens,A as estimateTokens,T as getCompactionTriggerRatio,z as isCompactionSummaryMessage,mt as isOverflow,pt as isOverflowByActualUsage,nt as isRuntimeResourcesMessage,ft as lookupModelLimits,dt as performCompaction,ot as pruneToolOutputs,ut as resolveReplayWindow,it as snipOldestMessageGroup,rt as summarizeConversation};
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};
7
7
 
@@ -8,31 +8,14 @@ export declare function splitQualifiedToolName(qualifiedName: string): {
8
8
 
9
9
  export type PluginStatus = "enabled" | "disabled" | "error";
10
10
 
11
- export interface PluginCatalogTool {
12
-
13
- name: string;
14
- description: string;
15
-
16
- requiredParams?: string[];
17
- }
18
-
19
- export interface PluginCatalogEntry {
20
- plugin: string;
21
- version?: string;
22
- description?: string;
23
- status: PluginStatus;
24
- tools: PluginCatalogTool[];
25
- }
26
-
27
- export interface PluginCatalogSnapshot {
28
- revision: number;
29
- plugins: PluginCatalogEntry[];
30
- }
11
+ export type PluginListenerState = "pending" | "running" | "stopped";
31
12
 
32
13
  export interface PluginListenerSummary {
33
14
  event: string;
34
15
  delivery: "poll" | "force" | "wake";
35
16
  running: boolean;
17
+
18
+ state: PluginListenerState;
36
19
  error?: string;
37
20
  }
38
21
 
@@ -55,9 +38,9 @@ export interface PluginSummary {
55
38
 
56
39
  running?: boolean;
57
40
 
58
- error?: string;
41
+ listenerState?: PluginListenerState;
59
42
 
60
- builtin?: boolean;
43
+ error?: string;
61
44
  }
62
45
 
63
46
  export type PluginManageAction = "install" | "uninstall" | "reload" | "enable" | "disable" | "list";
@@ -112,15 +95,11 @@ export interface ACodePluginBridge {
112
95
 
113
96
  listPlugins(): Promise<PluginSummary[]>;
114
97
 
115
- getCatalog(): Promise<PluginCatalogSnapshot>;
116
-
117
- getToolSchema(qualifiedName: string): Promise<PluginToolSchema | null>;
98
+ getPluginTools(plugin: string): Promise<PluginToolSchema[]>;
118
99
 
119
100
  invokeTool(plugin: string, tool: string, params: JsonObject, ctx?: PluginInvokeContext): Promise<PluginToolInvocationResult>;
120
101
 
121
102
  manage(request: PluginManageRequest): Promise<PluginManageResult>;
122
103
 
123
104
  getCommandDirs?(): Promise<string[]>;
124
-
125
- exposePlugin?(plugin: string): void;
126
105
  }
@@ -2,6 +2,7 @@ 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";
5
6
  import type { ACodeMcpServerSpec, ACodeRuntimeConfig } from "./types.js";
6
7
  export interface ACodeMcpConnection {
7
8
  serverName: string;
@@ -71,6 +72,8 @@ export declare class ACodeRuntime extends EventEmitter {
71
72
  private readonly config;
72
73
  private readonly hookBus;
73
74
  private initialConversation;
75
+
76
+ private readonly mcpStderrBuffers;
74
77
  private state;
75
78
  private abortController;
76
79
 
@@ -85,6 +88,8 @@ export declare class ACodeRuntime extends EventEmitter {
85
88
  private readonly memoryDelegateCooldownUntil;
86
89
 
87
90
  private toolGroupManager;
91
+
92
+ private pluginGroupStates;
88
93
  private submitQueue;
89
94
 
90
95
  private activeTurnToken;
@@ -102,6 +107,8 @@ export declare class ACodeRuntime extends EventEmitter {
102
107
 
103
108
  private forceMessagePending;
104
109
 
110
+ private compactRequested;
111
+
105
112
  private turnPromptPushed;
106
113
  private abortRequested;
107
114
 
@@ -146,6 +153,14 @@ export declare class ACodeRuntime extends EventEmitter {
146
153
 
147
154
  private handleCompactionPhase;
148
155
 
156
+ private runCompactionPass;
157
+
158
+ compactContext(plan?: CompactionPlan): {
159
+ requested: boolean;
160
+ };
161
+
162
+ getCompactionPreview(): CompactionPreview;
163
+
149
164
  start(): Promise<void>;
150
165
 
151
166
  private loadAllSkills;
@@ -180,8 +195,26 @@ export declare class ACodeRuntime extends EventEmitter {
180
195
 
181
196
  removeBuiltInToolsByPrefix(prefix: string): number;
182
197
 
198
+ addMcpServer(name: string, spec: ACodeMcpServerSpec): Promise<{
199
+ ok: boolean;
200
+ tools: number;
201
+ toolNames?: string[];
202
+ error?: string;
203
+ }>;
204
+
205
+ removeMcpServer(name: string): Promise<{
206
+ ok: boolean;
207
+ removed: boolean;
208
+ }>;
209
+
183
210
  addPluginCommands(commands: import("./types.js").ACodeCommandSpec[]): void;
184
211
 
212
+ private applyPluginGroups;
213
+
214
+ syncPluginGroups(): Promise<void>;
215
+
216
+ private injectPluginChangeNotice;
217
+
185
218
  private emitExposedToolsStatus;
186
219
 
187
220
  private injectForceMessage;
@@ -325,6 +358,10 @@ export declare class ACodeRuntime extends EventEmitter {
325
358
  private refreshMcpConnectionTools;
326
359
  private createMcpTransport;
327
360
 
361
+ private ensureMcpStderrBuffer;
362
+
363
+ getMcpServerStderr(serverName: string, tail?: number): string[];
364
+
328
365
  private fetchProfilePrompt;
329
366
 
330
367
  private extractProfileFromToolResult;