flavor-code 1.4.0-beta.3 → 1.4.0-beta.5

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 (37) hide show
  1. package/dist/agent/loop.d.ts +4 -2
  2. package/dist/{app-H7RYDMD3.js → app-SXNJDSI2.js} +3 -3
  3. package/dist/{chunk-NIKCPCJG.js → chunk-J7TLT6LR.js} +1098 -366
  4. package/dist/{chunk-3BHKW5A7.js → chunk-JZVC4477.js} +8 -2
  5. package/dist/{chunk-KBHWS7M6.js → chunk-KQMKY7C5.js} +4 -0
  6. package/dist/chunk-N5MXHJKD.js +107 -0
  7. package/dist/cli-main.js +20 -13
  8. package/dist/cli.js +51 -10
  9. package/dist/config/schema.d.ts +4 -0
  10. package/dist/context/manager.d.ts +9 -0
  11. package/dist/desktop/main.js +1442 -625
  12. package/dist/desktop-renderer/assets/index-nR67Z0XT.js +154 -0
  13. package/dist/desktop-renderer/assets/{interactive-terminal-j52Ty3QO.js → interactive-terminal-D2J4feTJ.js} +1 -1
  14. package/dist/desktop-renderer/index.html +1 -1
  15. package/dist/goal/classifier.d.ts +2 -0
  16. package/dist/goal/orchestrator.d.ts +23 -2
  17. package/dist/goal/planner.d.ts +2 -0
  18. package/dist/goal/store.d.ts +2 -0
  19. package/dist/goal/types.d.ts +14 -0
  20. package/dist/harness/journal.d.ts +2 -0
  21. package/dist/jobs/registry.d.ts +6 -0
  22. package/dist/{load-SLSL3IWR.js → load-F4AYLCF6.js} +1 -1
  23. package/dist/loop/orchestrator.d.ts +20 -0
  24. package/dist/loop/types.d.ts +7 -0
  25. package/dist/loop/verifier.d.ts +2 -0
  26. package/dist/production.d.ts +17 -0
  27. package/dist/sdk/index.js +4 -4
  28. package/dist/session/tree.d.ts +2 -0
  29. package/dist/ui/session.d.ts +11 -0
  30. package/dist/ui/transcript.d.ts +9 -0
  31. package/dist/utils/abort.d.ts +16 -0
  32. package/dist/utils/heap.d.ts +58 -0
  33. package/dist/utils/memory-restart.d.ts +42 -3
  34. package/dist/utils/rotation-census.d.ts +36 -0
  35. package/package.json +1 -1
  36. package/dist/chunk-CIVPKHF4.js +0 -53
  37. package/dist/desktop-renderer/assets/index-CYd5JkTR.js +0 -154
@@ -1,4 +1,4 @@
1
- import{i as e,n as t,r as n,t as r}from"./index-CYd5JkTR.js";var i=e(n(),1),a=2,o=1,s=class{activate(e){this._terminal=e}dispose(){}fit(){let e=this.proposeDimensions();if(!e||!this._terminal||isNaN(e.cols)||isNaN(e.rows))return;let t=this._terminal._core;(this._terminal.rows!==e.rows||this._terminal.cols!==e.cols)&&(t._renderService.clear(),this._terminal.resize(e.cols,e.rows))}proposeDimensions(){if(!this._terminal||!this._terminal.element||!this._terminal.element.parentElement)return;let e=this._terminal._core._renderService.dimensions;if(e.css.cell.width===0||e.css.cell.height===0)return;let t=this._terminal.options.scrollback===0?0:this._terminal.options.overviewRuler?.width||14,n=window.getComputedStyle(this._terminal.element.parentElement),r=parseInt(n.getPropertyValue(`height`)),i=Math.max(0,parseInt(n.getPropertyValue(`width`))),s=window.getComputedStyle(this._terminal.element),c={top:parseInt(s.getPropertyValue(`padding-top`)),bottom:parseInt(s.getPropertyValue(`padding-bottom`)),right:parseInt(s.getPropertyValue(`padding-right`)),left:parseInt(s.getPropertyValue(`padding-left`))},l=c.top+c.bottom,u=c.right+c.left,d=r-l,f=i-u-t;return{cols:Math.max(a,Math.floor(f/e.css.cell.width)),rows:Math.max(o,Math.floor(d/e.css.cell.height))}}},c=Object.defineProperty,l=Object.getOwnPropertyDescriptor,u=(e,t)=>{for(var n in t)c(e,n,{get:t[n],enumerable:!0})},d=(e,t,n,r)=>{for(var i=r>1?void 0:r?l(t,n):t,a=e.length-1,o;a>=0;a--)(o=e[a])&&(i=(r?o(t,n,i):o(i))||i);return r&&i&&c(t,n,i),i},f=(e,t)=>(n,r)=>t(n,r,e),p=`Terminal input`,m={get:()=>p,set:e=>p=e},h=`Too much output to announce, navigate to rows manually to read`,g={get:()=>h,set:e=>h=e};function _(e){return e.replace(/\r?\n/g,`\r`)}function ee(e,t){return t?`\x1B[200~`+e+`\x1B[201~`:e}function te(e,t){e.clipboardData&&e.clipboardData.setData(`text/plain`,t.selectionText),e.preventDefault()}function ne(e,t,n,r){e.stopPropagation(),e.clipboardData&&re(e.clipboardData.getData(`text/plain`),t,n,r)}function re(e,t,n,r){e=_(e),e=ee(e,n.decPrivateModes.bracketedPasteMode&&r.rawOptions.ignoreBracketedPasteMode!==!0),n.triggerDataEvent(e,!0),t.value=``}function ie(e,t,n){let r=n.getBoundingClientRect(),i=e.clientX-r.left-10,a=e.clientY-r.top-10;t.style.width=`20px`,t.style.height=`20px`,t.style.left=`${i}px`,t.style.top=`${a}px`,t.style.zIndex=`1000`,t.focus()}function ae(e,t,n,r,i){ie(e,t,n),i&&r.rightClickSelect(e),t.value=r.selectionText,t.select()}function v(e){return e>65535?(e-=65536,String.fromCharCode((e>>10)+55296)+String.fromCharCode(e%1024+56320)):String.fromCharCode(e)}function oe(e,t=0,n=e.length){let r=``;for(let i=t;i<n;++i){let t=e[i];t>65535?(t-=65536,r+=String.fromCharCode((t>>10)+55296)+String.fromCharCode(t%1024+56320)):r+=String.fromCharCode(t)}return r}var se=class{constructor(){this._interim=0}clear(){this._interim=0}decode(e,t){let n=e.length;if(!n)return 0;let r=0,i=0;if(this._interim){let n=e.charCodeAt(i++);56320<=n&&n<=57343?t[r++]=(this._interim-55296)*1024+n-56320+65536:(t[r++]=this._interim,t[r++]=n),this._interim=0}for(let a=i;a<n;++a){let i=e.charCodeAt(a);if(55296<=i&&i<=56319){if(++a>=n)return this._interim=i,r;let o=e.charCodeAt(a);56320<=o&&o<=57343?t[r++]=(i-55296)*1024+o-56320+65536:(t[r++]=i,t[r++]=o);continue}i!==65279&&(t[r++]=i)}return r}},y=class{constructor(){this.interim=new Uint8Array(3)}clear(){this.interim.fill(0)}decode(e,t){let n=e.length;if(!n)return 0;let r=0,i,a,o,s,c=0,l=0;if(this.interim[0]){let i=!1,a=this.interim[0];a&=(a&224)==192?31:(a&240)==224?15:7;let o=0,s;for(;(s=this.interim[++o]&63)&&o<4;)a<<=6,a|=s;let c=(this.interim[0]&224)==192?2:(this.interim[0]&240)==224?3:4,u=c-o;for(;l<u;){if(l>=n)return 0;if(s=e[l++],(s&192)!=128){l--,i=!0;break}else this.interim[o++]=s,a<<=6,a|=s&63}i||(c===2?a<128?l--:t[r++]=a:c===3?a<2048||a>=55296&&a<=57343||a===65279||(t[r++]=a):a<65536||a>1114111||(t[r++]=a)),this.interim.fill(0)}let u=n-4,d=l;for(;d<n;){for(;d<u&&!((i=e[d])&128)&&!((a=e[d+1])&128)&&!((o=e[d+2])&128)&&!((s=e[d+3])&128);)t[r++]=i,t[r++]=a,t[r++]=o,t[r++]=s,d+=4;if(i=e[d++],i<128)t[r++]=i;else if((i&224)==192){if(d>=n)return this.interim[0]=i,r;if(a=e[d++],(a&192)!=128){d--;continue}if(c=(i&31)<<6|a&63,c<128){d--;continue}t[r++]=c}else if((i&240)==224){if(d>=n)return this.interim[0]=i,r;if(a=e[d++],(a&192)!=128){d--;continue}if(d>=n)return this.interim[0]=i,this.interim[1]=a,r;if(o=e[d++],(o&192)!=128){d--;continue}if(c=(i&15)<<12|(a&63)<<6|o&63,c<2048||c>=55296&&c<=57343||c===65279)continue;t[r++]=c}else if((i&248)==240){if(d>=n)return this.interim[0]=i,r;if(a=e[d++],(a&192)!=128){d--;continue}if(d>=n)return this.interim[0]=i,this.interim[1]=a,r;if(o=e[d++],(o&192)!=128){d--;continue}if(d>=n)return this.interim[0]=i,this.interim[1]=a,this.interim[2]=o,r;if(s=e[d++],(s&192)!=128){d--;continue}if(c=(i&7)<<18|(a&63)<<12|(o&63)<<6|s&63,c<65536||c>1114111)continue;t[r++]=c}}return r}},ce=``,le=` `,ue=class e{constructor(){this.fg=0,this.bg=0,this.extended=new b}static toColorRGB(e){return[e>>>16&255,e>>>8&255,e&255]}static fromColorRGB(e){return(e[0]&255)<<16|(e[1]&255)<<8|e[2]&255}clone(){let t=new e;return t.fg=this.fg,t.bg=this.bg,t.extended=this.extended.clone(),t}isInverse(){return this.fg&67108864}isBold(){return this.fg&134217728}isUnderline(){return this.hasExtendedAttrs()&&this.extended.underlineStyle!==0?1:this.fg&268435456}isBlink(){return this.fg&536870912}isInvisible(){return this.fg&1073741824}isItalic(){return this.bg&67108864}isDim(){return this.bg&134217728}isStrikethrough(){return this.fg&2147483648}isProtected(){return this.bg&536870912}isOverline(){return this.bg&1073741824}getFgColorMode(){return this.fg&50331648}getBgColorMode(){return this.bg&50331648}isFgRGB(){return(this.fg&50331648)==50331648}isBgRGB(){return(this.bg&50331648)==50331648}isFgPalette(){return(this.fg&50331648)==16777216||(this.fg&50331648)==33554432}isBgPalette(){return(this.bg&50331648)==16777216||(this.bg&50331648)==33554432}isFgDefault(){return(this.fg&50331648)==0}isBgDefault(){return(this.bg&50331648)==0}isAttributeDefault(){return this.fg===0&&this.bg===0}getFgColor(){switch(this.fg&50331648){case 16777216:case 33554432:return this.fg&255;case 50331648:return this.fg&16777215;default:return-1}}getBgColor(){switch(this.bg&50331648){case 16777216:case 33554432:return this.bg&255;case 50331648:return this.bg&16777215;default:return-1}}hasExtendedAttrs(){return this.bg&268435456}updateExtended(){this.extended.isEmpty()?this.bg&=-268435457:this.bg|=268435456}getUnderlineColor(){if(this.bg&268435456&&~this.extended.underlineColor)switch(this.extended.underlineColor&50331648){case 16777216:case 33554432:return this.extended.underlineColor&255;case 50331648:return this.extended.underlineColor&16777215;default:return this.getFgColor()}return this.getFgColor()}getUnderlineColorMode(){return this.bg&268435456&&~this.extended.underlineColor?this.extended.underlineColor&50331648:this.getFgColorMode()}isUnderlineColorRGB(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)==50331648:this.isFgRGB()}isUnderlineColorPalette(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)==16777216||(this.extended.underlineColor&50331648)==33554432:this.isFgPalette()}isUnderlineColorDefault(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)==0:this.isFgDefault()}getUnderlineStyle(){return this.fg&268435456?this.bg&268435456?this.extended.underlineStyle:1:0}getUnderlineVariantOffset(){return this.extended.underlineVariantOffset}},b=class e{constructor(e=0,t=0){this._ext=0,this._urlId=0,this._ext=e,this._urlId=t}get ext(){return this._urlId?this._ext&-469762049|this.underlineStyle<<26:this._ext}set ext(e){this._ext=e}get underlineStyle(){return this._urlId?5:(this._ext&469762048)>>26}set underlineStyle(e){this._ext&=-469762049,this._ext|=e<<26&469762048}get underlineColor(){return this._ext&67108863}set underlineColor(e){this._ext&=-67108864,this._ext|=e&67108863}get urlId(){return this._urlId}set urlId(e){this._urlId=e}get underlineVariantOffset(){let e=(this._ext&3758096384)>>29;return e<0?e^4294967288:e}set underlineVariantOffset(e){this._ext&=536870911,this._ext|=e<<29&3758096384}clone(){return new e(this._ext,this._urlId)}isEmpty(){return this.underlineStyle===0&&this._urlId===0}},x=class e extends ue{constructor(){super(...arguments),this.content=0,this.fg=0,this.bg=0,this.extended=new b,this.combinedData=``}static fromCharData(t){let n=new e;return n.setFromCharData(t),n}isCombined(){return this.content&2097152}getWidth(){return this.content>>22}getChars(){return this.content&2097152?this.combinedData:this.content&2097151?v(this.content&2097151):``}getCode(){return this.isCombined()?this.combinedData.charCodeAt(this.combinedData.length-1):this.content&2097151}setFromCharData(e){this.fg=e[0],this.bg=0;let t=!1;if(e[1].length>2)t=!0;else if(e[1].length===2){let n=e[1].charCodeAt(0);if(55296<=n&&n<=56319){let r=e[1].charCodeAt(1);56320<=r&&r<=57343?this.content=(n-55296)*1024+r-56320+65536|e[2]<<22:t=!0}else t=!0}else this.content=e[1].charCodeAt(0)|e[2]<<22;t&&(this.combinedData=e[1],this.content=2097152|e[2]<<22)}getAsCharData(){return[this.fg,this.getChars(),this.getWidth(),this.getCode()]}},de=`di$target`,fe=`di$dependencies`,S=new Map;function pe(e){return e[fe]||[]}function C(e){if(S.has(e))return S.get(e);let t=function(e,n,r){if(arguments.length!==3)throw Error(`@IServiceName-decorator can only be used to decorate a parameter`);me(t,e,r)};return t._id=e,S.set(e,t),t}function me(e,t,n){t[de]===t?t[fe].push({id:e,index:n}):(t[fe]=[{id:e,index:n}],t[de]=t)}var w=C(`BufferService`),he=C(`CoreMouseService`),T=C(`CoreService`),ge=C(`CharsetService`),E=C(`InstantiationService`),_e=C(`LogService`),D=C(`OptionsService`),ve=C(`OscLinkService`),ye=C(`UnicodeService`),be=C(`DecorationService`),xe=class{constructor(e,t,n){this._bufferService=e,this._optionsService=t,this._oscLinkService=n}provideLinks(e,t){let n=this._bufferService.buffer.lines.get(e-1);if(!n){t(void 0);return}let r=[],i=this._optionsService.rawOptions.linkHandler,a=new x,o=n.getTrimmedLength(),s=-1,c=-1,l=!1;for(let t=0;t<o;t++)if(!(c===-1&&!n.hasContent(t))){if(n.loadCell(t,a),a.hasExtendedAttrs()&&a.extended.urlId)if(c===-1){c=t,s=a.extended.urlId;continue}else l=a.extended.urlId!==s;else c!==-1&&(l=!0);if(l||c!==-1&&t===o-1){let n=this._oscLinkService.getLinkData(s)?.uri;if(n){let a={start:{x:c+1,y:e},end:{x:t+ +(!l&&t===o-1),y:e}},s=!1;if(!i?.allowNonHttpProtocols)try{let e=new URL(n);[`http:`,`https:`].includes(e.protocol)||(s=!0)}catch{s=!0}s||r.push({text:n,range:a,activate:(e,t)=>i?i.activate(e,t,a):Se(e,t),hover:(e,t)=>i?.hover?.(e,t,a),leave:(e,t)=>i?.leave?.(e,t,a)})}l=!1,a.hasExtendedAttrs()&&a.extended.urlId?(c=t,s=a.extended.urlId):(c=-1,s=-1)}}t(r)}};xe=d([f(0,w),f(1,D),f(2,ve)],xe);function Se(e,t){if(confirm(`Do you want to navigate to ${t}?
1
+ import{i as e,n as t,r as n,t as r}from"./index-nR67Z0XT.js";var i=e(n(),1),a=2,o=1,s=class{activate(e){this._terminal=e}dispose(){}fit(){let e=this.proposeDimensions();if(!e||!this._terminal||isNaN(e.cols)||isNaN(e.rows))return;let t=this._terminal._core;(this._terminal.rows!==e.rows||this._terminal.cols!==e.cols)&&(t._renderService.clear(),this._terminal.resize(e.cols,e.rows))}proposeDimensions(){if(!this._terminal||!this._terminal.element||!this._terminal.element.parentElement)return;let e=this._terminal._core._renderService.dimensions;if(e.css.cell.width===0||e.css.cell.height===0)return;let t=this._terminal.options.scrollback===0?0:this._terminal.options.overviewRuler?.width||14,n=window.getComputedStyle(this._terminal.element.parentElement),r=parseInt(n.getPropertyValue(`height`)),i=Math.max(0,parseInt(n.getPropertyValue(`width`))),s=window.getComputedStyle(this._terminal.element),c={top:parseInt(s.getPropertyValue(`padding-top`)),bottom:parseInt(s.getPropertyValue(`padding-bottom`)),right:parseInt(s.getPropertyValue(`padding-right`)),left:parseInt(s.getPropertyValue(`padding-left`))},l=c.top+c.bottom,u=c.right+c.left,d=r-l,f=i-u-t;return{cols:Math.max(a,Math.floor(f/e.css.cell.width)),rows:Math.max(o,Math.floor(d/e.css.cell.height))}}},c=Object.defineProperty,l=Object.getOwnPropertyDescriptor,u=(e,t)=>{for(var n in t)c(e,n,{get:t[n],enumerable:!0})},d=(e,t,n,r)=>{for(var i=r>1?void 0:r?l(t,n):t,a=e.length-1,o;a>=0;a--)(o=e[a])&&(i=(r?o(t,n,i):o(i))||i);return r&&i&&c(t,n,i),i},f=(e,t)=>(n,r)=>t(n,r,e),p=`Terminal input`,m={get:()=>p,set:e=>p=e},h=`Too much output to announce, navigate to rows manually to read`,g={get:()=>h,set:e=>h=e};function _(e){return e.replace(/\r?\n/g,`\r`)}function ee(e,t){return t?`\x1B[200~`+e+`\x1B[201~`:e}function te(e,t){e.clipboardData&&e.clipboardData.setData(`text/plain`,t.selectionText),e.preventDefault()}function ne(e,t,n,r){e.stopPropagation(),e.clipboardData&&re(e.clipboardData.getData(`text/plain`),t,n,r)}function re(e,t,n,r){e=_(e),e=ee(e,n.decPrivateModes.bracketedPasteMode&&r.rawOptions.ignoreBracketedPasteMode!==!0),n.triggerDataEvent(e,!0),t.value=``}function ie(e,t,n){let r=n.getBoundingClientRect(),i=e.clientX-r.left-10,a=e.clientY-r.top-10;t.style.width=`20px`,t.style.height=`20px`,t.style.left=`${i}px`,t.style.top=`${a}px`,t.style.zIndex=`1000`,t.focus()}function ae(e,t,n,r,i){ie(e,t,n),i&&r.rightClickSelect(e),t.value=r.selectionText,t.select()}function v(e){return e>65535?(e-=65536,String.fromCharCode((e>>10)+55296)+String.fromCharCode(e%1024+56320)):String.fromCharCode(e)}function oe(e,t=0,n=e.length){let r=``;for(let i=t;i<n;++i){let t=e[i];t>65535?(t-=65536,r+=String.fromCharCode((t>>10)+55296)+String.fromCharCode(t%1024+56320)):r+=String.fromCharCode(t)}return r}var se=class{constructor(){this._interim=0}clear(){this._interim=0}decode(e,t){let n=e.length;if(!n)return 0;let r=0,i=0;if(this._interim){let n=e.charCodeAt(i++);56320<=n&&n<=57343?t[r++]=(this._interim-55296)*1024+n-56320+65536:(t[r++]=this._interim,t[r++]=n),this._interim=0}for(let a=i;a<n;++a){let i=e.charCodeAt(a);if(55296<=i&&i<=56319){if(++a>=n)return this._interim=i,r;let o=e.charCodeAt(a);56320<=o&&o<=57343?t[r++]=(i-55296)*1024+o-56320+65536:(t[r++]=i,t[r++]=o);continue}i!==65279&&(t[r++]=i)}return r}},y=class{constructor(){this.interim=new Uint8Array(3)}clear(){this.interim.fill(0)}decode(e,t){let n=e.length;if(!n)return 0;let r=0,i,a,o,s,c=0,l=0;if(this.interim[0]){let i=!1,a=this.interim[0];a&=(a&224)==192?31:(a&240)==224?15:7;let o=0,s;for(;(s=this.interim[++o]&63)&&o<4;)a<<=6,a|=s;let c=(this.interim[0]&224)==192?2:(this.interim[0]&240)==224?3:4,u=c-o;for(;l<u;){if(l>=n)return 0;if(s=e[l++],(s&192)!=128){l--,i=!0;break}else this.interim[o++]=s,a<<=6,a|=s&63}i||(c===2?a<128?l--:t[r++]=a:c===3?a<2048||a>=55296&&a<=57343||a===65279||(t[r++]=a):a<65536||a>1114111||(t[r++]=a)),this.interim.fill(0)}let u=n-4,d=l;for(;d<n;){for(;d<u&&!((i=e[d])&128)&&!((a=e[d+1])&128)&&!((o=e[d+2])&128)&&!((s=e[d+3])&128);)t[r++]=i,t[r++]=a,t[r++]=o,t[r++]=s,d+=4;if(i=e[d++],i<128)t[r++]=i;else if((i&224)==192){if(d>=n)return this.interim[0]=i,r;if(a=e[d++],(a&192)!=128){d--;continue}if(c=(i&31)<<6|a&63,c<128){d--;continue}t[r++]=c}else if((i&240)==224){if(d>=n)return this.interim[0]=i,r;if(a=e[d++],(a&192)!=128){d--;continue}if(d>=n)return this.interim[0]=i,this.interim[1]=a,r;if(o=e[d++],(o&192)!=128){d--;continue}if(c=(i&15)<<12|(a&63)<<6|o&63,c<2048||c>=55296&&c<=57343||c===65279)continue;t[r++]=c}else if((i&248)==240){if(d>=n)return this.interim[0]=i,r;if(a=e[d++],(a&192)!=128){d--;continue}if(d>=n)return this.interim[0]=i,this.interim[1]=a,r;if(o=e[d++],(o&192)!=128){d--;continue}if(d>=n)return this.interim[0]=i,this.interim[1]=a,this.interim[2]=o,r;if(s=e[d++],(s&192)!=128){d--;continue}if(c=(i&7)<<18|(a&63)<<12|(o&63)<<6|s&63,c<65536||c>1114111)continue;t[r++]=c}}return r}},ce=``,le=` `,ue=class e{constructor(){this.fg=0,this.bg=0,this.extended=new b}static toColorRGB(e){return[e>>>16&255,e>>>8&255,e&255]}static fromColorRGB(e){return(e[0]&255)<<16|(e[1]&255)<<8|e[2]&255}clone(){let t=new e;return t.fg=this.fg,t.bg=this.bg,t.extended=this.extended.clone(),t}isInverse(){return this.fg&67108864}isBold(){return this.fg&134217728}isUnderline(){return this.hasExtendedAttrs()&&this.extended.underlineStyle!==0?1:this.fg&268435456}isBlink(){return this.fg&536870912}isInvisible(){return this.fg&1073741824}isItalic(){return this.bg&67108864}isDim(){return this.bg&134217728}isStrikethrough(){return this.fg&2147483648}isProtected(){return this.bg&536870912}isOverline(){return this.bg&1073741824}getFgColorMode(){return this.fg&50331648}getBgColorMode(){return this.bg&50331648}isFgRGB(){return(this.fg&50331648)==50331648}isBgRGB(){return(this.bg&50331648)==50331648}isFgPalette(){return(this.fg&50331648)==16777216||(this.fg&50331648)==33554432}isBgPalette(){return(this.bg&50331648)==16777216||(this.bg&50331648)==33554432}isFgDefault(){return(this.fg&50331648)==0}isBgDefault(){return(this.bg&50331648)==0}isAttributeDefault(){return this.fg===0&&this.bg===0}getFgColor(){switch(this.fg&50331648){case 16777216:case 33554432:return this.fg&255;case 50331648:return this.fg&16777215;default:return-1}}getBgColor(){switch(this.bg&50331648){case 16777216:case 33554432:return this.bg&255;case 50331648:return this.bg&16777215;default:return-1}}hasExtendedAttrs(){return this.bg&268435456}updateExtended(){this.extended.isEmpty()?this.bg&=-268435457:this.bg|=268435456}getUnderlineColor(){if(this.bg&268435456&&~this.extended.underlineColor)switch(this.extended.underlineColor&50331648){case 16777216:case 33554432:return this.extended.underlineColor&255;case 50331648:return this.extended.underlineColor&16777215;default:return this.getFgColor()}return this.getFgColor()}getUnderlineColorMode(){return this.bg&268435456&&~this.extended.underlineColor?this.extended.underlineColor&50331648:this.getFgColorMode()}isUnderlineColorRGB(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)==50331648:this.isFgRGB()}isUnderlineColorPalette(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)==16777216||(this.extended.underlineColor&50331648)==33554432:this.isFgPalette()}isUnderlineColorDefault(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)==0:this.isFgDefault()}getUnderlineStyle(){return this.fg&268435456?this.bg&268435456?this.extended.underlineStyle:1:0}getUnderlineVariantOffset(){return this.extended.underlineVariantOffset}},b=class e{constructor(e=0,t=0){this._ext=0,this._urlId=0,this._ext=e,this._urlId=t}get ext(){return this._urlId?this._ext&-469762049|this.underlineStyle<<26:this._ext}set ext(e){this._ext=e}get underlineStyle(){return this._urlId?5:(this._ext&469762048)>>26}set underlineStyle(e){this._ext&=-469762049,this._ext|=e<<26&469762048}get underlineColor(){return this._ext&67108863}set underlineColor(e){this._ext&=-67108864,this._ext|=e&67108863}get urlId(){return this._urlId}set urlId(e){this._urlId=e}get underlineVariantOffset(){let e=(this._ext&3758096384)>>29;return e<0?e^4294967288:e}set underlineVariantOffset(e){this._ext&=536870911,this._ext|=e<<29&3758096384}clone(){return new e(this._ext,this._urlId)}isEmpty(){return this.underlineStyle===0&&this._urlId===0}},x=class e extends ue{constructor(){super(...arguments),this.content=0,this.fg=0,this.bg=0,this.extended=new b,this.combinedData=``}static fromCharData(t){let n=new e;return n.setFromCharData(t),n}isCombined(){return this.content&2097152}getWidth(){return this.content>>22}getChars(){return this.content&2097152?this.combinedData:this.content&2097151?v(this.content&2097151):``}getCode(){return this.isCombined()?this.combinedData.charCodeAt(this.combinedData.length-1):this.content&2097151}setFromCharData(e){this.fg=e[0],this.bg=0;let t=!1;if(e[1].length>2)t=!0;else if(e[1].length===2){let n=e[1].charCodeAt(0);if(55296<=n&&n<=56319){let r=e[1].charCodeAt(1);56320<=r&&r<=57343?this.content=(n-55296)*1024+r-56320+65536|e[2]<<22:t=!0}else t=!0}else this.content=e[1].charCodeAt(0)|e[2]<<22;t&&(this.combinedData=e[1],this.content=2097152|e[2]<<22)}getAsCharData(){return[this.fg,this.getChars(),this.getWidth(),this.getCode()]}},de=`di$target`,fe=`di$dependencies`,S=new Map;function pe(e){return e[fe]||[]}function C(e){if(S.has(e))return S.get(e);let t=function(e,n,r){if(arguments.length!==3)throw Error(`@IServiceName-decorator can only be used to decorate a parameter`);me(t,e,r)};return t._id=e,S.set(e,t),t}function me(e,t,n){t[de]===t?t[fe].push({id:e,index:n}):(t[fe]=[{id:e,index:n}],t[de]=t)}var w=C(`BufferService`),he=C(`CoreMouseService`),T=C(`CoreService`),ge=C(`CharsetService`),E=C(`InstantiationService`),_e=C(`LogService`),D=C(`OptionsService`),ve=C(`OscLinkService`),ye=C(`UnicodeService`),be=C(`DecorationService`),xe=class{constructor(e,t,n){this._bufferService=e,this._optionsService=t,this._oscLinkService=n}provideLinks(e,t){let n=this._bufferService.buffer.lines.get(e-1);if(!n){t(void 0);return}let r=[],i=this._optionsService.rawOptions.linkHandler,a=new x,o=n.getTrimmedLength(),s=-1,c=-1,l=!1;for(let t=0;t<o;t++)if(!(c===-1&&!n.hasContent(t))){if(n.loadCell(t,a),a.hasExtendedAttrs()&&a.extended.urlId)if(c===-1){c=t,s=a.extended.urlId;continue}else l=a.extended.urlId!==s;else c!==-1&&(l=!0);if(l||c!==-1&&t===o-1){let n=this._oscLinkService.getLinkData(s)?.uri;if(n){let a={start:{x:c+1,y:e},end:{x:t+ +(!l&&t===o-1),y:e}},s=!1;if(!i?.allowNonHttpProtocols)try{let e=new URL(n);[`http:`,`https:`].includes(e.protocol)||(s=!0)}catch{s=!0}s||r.push({text:n,range:a,activate:(e,t)=>i?i.activate(e,t,a):Se(e,t),hover:(e,t)=>i?.hover?.(e,t,a),leave:(e,t)=>i?.leave?.(e,t,a)})}l=!1,a.hasExtendedAttrs()&&a.extended.urlId?(c=t,s=a.extended.urlId):(c=-1,s=-1)}}t(r)}};xe=d([f(0,w),f(1,D),f(2,ve)],xe);function Se(e,t){if(confirm(`Do you want to navigate to ${t}?
2
2
 
3
3
  WARNING: This link could potentially be dangerous`)){let e=window.open();if(e){try{e.opener=null}catch{}e.location.href=t}else console.warn(`Opening link blocked as opener could not be cleared`)}}var Ce=C(`CharSizeService`),we=C(`CoreBrowserService`),Te=C(`MouseService`),Ee=C(`RenderService`),De=C(`SelectionService`),Oe=C(`CharacterJoinerService`),ke=C(`ThemeService`),Ae=C(`LinkProviderService`),je=new class{constructor(){this.listeners=[],this.unexpectedErrorHandler=function(e){setTimeout(()=>{throw e.stack?Le.isErrorNoTelemetry(e)?new Le(e.message+`
4
4
 
@@ -6,7 +6,7 @@
6
6
  <meta name="color-scheme" content="light" />
7
7
  <meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; connect-src 'self' http://127.0.0.1:* http://localhost:* http://[::1]:* ws://127.0.0.1:* ws://localhost:* ws://[::1]:*; frame-src http://127.0.0.1:* http://localhost:* http://[::1]:*" />
8
8
  <title>Flavor Code</title>
9
- <script type="module" crossorigin src="./assets/index-CYd5JkTR.js"></script>
9
+ <script type="module" crossorigin src="./assets/index-nR67Z0XT.js"></script>
10
10
  <link rel="stylesheet" crossorigin href="./assets/index-Bk6FYhyh.css">
11
11
  </head>
12
12
  <body>
@@ -6,6 +6,8 @@ export interface ClassifierOptions {
6
6
  skepticCount: number;
7
7
  workspace: string;
8
8
  signal?: AbortSignal;
9
+ /** Safe-point hook used by long-running hosts to rotate before OOM. */
10
+ onProgress?(): void | Promise<void>;
9
11
  }
10
12
  export declare function runClassifier(evidence: EvidencePacket, plan: Plan, options: ClassifierOptions): Promise<AggregatedOutcome>;
11
13
  export declare function computeFingerprint(gaps: Gap[]): string;
@@ -7,8 +7,11 @@ export interface GoalOrchestratorOptions {
7
7
  plannerModelId: string;
8
8
  classifierModelId: string;
9
9
  skepticCount: number;
10
- maxRounds: number;
11
- maxStallStreak: number;
10
+ /** Optional finite policies for embedded/test hosts. Production leaves these unset. */
11
+ maxRounds?: number;
12
+ maxStallStreak?: number;
13
+ /** Retry delay override for deterministic tests or an embedding host. */
14
+ stageRetryDelayMs?(attempt: number): number;
12
15
  runWorker(input: {
13
16
  goal: string;
14
17
  round: number;
@@ -21,7 +24,17 @@ export interface GoalOrchestratorOptions {
21
24
  idFactory?(): string;
22
25
  persistence?: {
23
26
  save(state: GoalState): Promise<void>;
27
+ /** Present when the store can reload a goal for resume after heap rotation. */
28
+ load?(goalId: string): Promise<GoalState>;
24
29
  };
30
+ /**
31
+ * Called at every round boundary (state persisted). Production uses it to
32
+ * rotate onto a fresh heap between rounds so multi-day goals never die on
33
+ * a grown heap; the relaunched process resumes the goal from its state.
34
+ */
35
+ onRoundBoundary?(goalId: string): void | Promise<void>;
36
+ /** Also sampled inside planner/classifier streams and around host verification. */
37
+ onMemoryCheckpoint?(goalId: string): void | Promise<void>;
25
38
  verifyHost?(signal: AbortSignal): Promise<HostVerificationEvidence>;
26
39
  }
27
40
  export declare class GoalOrchestrator {
@@ -32,4 +45,12 @@ export declare class GoalOrchestrator {
32
45
  goal: string;
33
46
  signal: AbortSignal;
34
47
  }): AsyncIterable<GoalRuntimeEvent>;
48
+ /**
49
+ * Continue a goal whose process rotated onto a fresh heap. The persisted
50
+ * state decides where to pick up; an interrupted round simply runs again.
51
+ */
52
+ resume(request: {
53
+ goalId: string;
54
+ signal: AbortSignal;
55
+ }): AsyncIterable<GoalRuntimeEvent>;
35
56
  }
@@ -5,5 +5,7 @@ export interface PlannerOptions {
5
5
  modelId: string;
6
6
  objective: string;
7
7
  signal?: AbortSignal;
8
+ /** Safe-point hook used by long-running hosts to rotate before OOM. */
9
+ onProgress?(): void | Promise<void>;
8
10
  }
9
11
  export declare function runPlanner(options: PlannerOptions): Promise<Plan>;
@@ -6,4 +6,6 @@ export declare class GoalStore {
6
6
  maxBytes?: number;
7
7
  });
8
8
  save(input: GoalState): Promise<void>;
9
+ /** Reload a persisted goal so a rotated process can resume it. */
10
+ load(goalId: string): Promise<GoalState>;
9
11
  }
@@ -146,6 +146,10 @@ export declare const GoalStateSchema: z.ZodObject<{
146
146
  planPath: z.ZodNullable<z.ZodString>;
147
147
  verifyRounds: z.ZodNumber;
148
148
  workerRounds: z.ZodNumber;
149
+ pendingVerification: z.ZodOptional<z.ZodNullable<z.ZodObject<{
150
+ round: z.ZodNumber;
151
+ finalResponse: z.ZodString;
152
+ }, z.core.$strict>>>;
149
153
  lastGaps: z.ZodArray<z.ZodObject<{
150
154
  criterion: z.ZodString;
151
155
  description: z.ZodString;
@@ -179,6 +183,16 @@ export declare const GoalStateSchema: z.ZodObject<{
179
183
  }, z.core.$strict>;
180
184
  export type GoalState = z.infer<typeof GoalStateSchema>;
181
185
  export type GoalRuntimeEvent = {
186
+ type: "goal-resumed";
187
+ goalId: string;
188
+ round: number;
189
+ } | {
190
+ type: "goal-stage-retry";
191
+ stage: "planning" | "classification";
192
+ attempt: number;
193
+ reason: string;
194
+ delayMs: number;
195
+ } | {
182
196
  type: "goal-plan-created";
183
197
  plan: Plan;
184
198
  planPath: string;
@@ -83,6 +83,8 @@ export declare class HarnessJournal {
83
83
  constructor(options: HarnessJournalOptions);
84
84
  get path(): string;
85
85
  get records(): readonly HarnessJournalRecord[];
86
+ /** Retained record count for the rotation census. */
87
+ get recordCount(): number;
86
88
  admitQueue<T>(kind: "steer" | "followUp", payload: T): string;
87
89
  claimQueue(id: string): void;
88
90
  ackQueue(id: string): void;
@@ -42,6 +42,12 @@ export declare class JobRegistry {
42
42
  create(input: CreateJobInput): JobHandle;
43
43
  list(owner?: string): readonly JobSnapshot[];
44
44
  read(id: string, owner: string, cursor?: number): JobReadResult;
45
+ /** Retained sizes for the rotation census. */
46
+ census(): {
47
+ jobs: number;
48
+ running: number;
49
+ windowChars: number;
50
+ };
45
51
  wait(id: string, owner: string, signal?: AbortSignal): Promise<JobSnapshot>;
46
52
  kill(id: string, owner: string): void | Promise<void>;
47
53
  subscribe(listener: (jobs: readonly JobSnapshot[]) => void): () => void;
@@ -7,7 +7,7 @@ import {
7
7
  setProjectMcpServerDisabled,
8
8
  setProjectProviderConfig,
9
9
  setProjectSkillDisabled
10
- } from "./chunk-KBHWS7M6.js";
10
+ } from "./chunk-KQMKY7C5.js";
11
11
  import "./chunk-S32JRDZK.js";
12
12
  export {
13
13
  loadConfig,
@@ -8,6 +8,8 @@ export interface LoopPersistence {
8
8
  create(state: LoopState): Promise<void>;
9
9
  save(state: LoopState): Promise<void>;
10
10
  append(event: LoopEvent): Promise<void>;
11
+ /** Present when the store can reload a loop for resume after heap rotation. */
12
+ load?(loopId: string): Promise<LoopState>;
11
13
  }
12
14
  export type LoopConfirmation = "approved" | "rejected" | "unavailable";
13
15
  export type LoopRuntimeEvent = {
@@ -67,8 +69,18 @@ export interface LoopOrchestratorOptions {
67
69
  runVerifier(plan: VerificationPlan, workspace: string, signal: AbortSignal): Promise<LoopVerificationEvidence>;
68
70
  confirmBudget(state: LoopState, dimensions: readonly BudgetDimension[], signal: AbortSignal): Promise<LoopConfirmation>;
69
71
  fingerprint(workspace: string): Promise<string>;
72
+ /**
73
+ * Called at every cycle boundary (state persisted). Production uses it to
74
+ * rotate onto a fresh heap between cycles so multi-day loops never die on
75
+ * a grown heap; the relaunched process resumes the loop from its state.
76
+ */
77
+ onCycleBoundary?(loopId: string): void | Promise<void>;
78
+ /** Also sampled around verification and confidence checks. */
79
+ onMemoryCheckpoint?(loopId: string): void | Promise<void>;
70
80
  /** Optional hallucination guard for confidence checks and retry monitoring. */
71
81
  hallucinationGuard?: HallucinationGuard;
82
+ /** Optional safety policy for hosts that want a finite no-progress stop. */
83
+ maxNoProgressCycles?: number | undefined;
72
84
  now?(): string;
73
85
  idFactory?(): string;
74
86
  }
@@ -79,4 +91,12 @@ export declare class LoopOrchestrator {
79
91
  goal: string;
80
92
  signal: AbortSignal;
81
93
  }): AsyncIterable<LoopRuntimeEvent>;
94
+ /**
95
+ * Continue a loop whose process rotated onto a fresh heap. The persisted
96
+ * state decides where to pick up; an interrupted cycle simply runs again.
97
+ */
98
+ resume(request: {
99
+ loopId: string;
100
+ signal: AbortSignal;
101
+ }): AsyncIterable<LoopRuntimeEvent>;
82
102
  }
@@ -118,6 +118,13 @@ export declare const LoopStateSchema: z.ZodObject<{
118
118
  summary: z.ZodString;
119
119
  }, z.core.$strict>;
120
120
  }, z.core.$strict>>;
121
+ pendingCycle: z.ZodOptional<z.ZodNullable<z.ZodObject<{
122
+ cycle: z.ZodNumber;
123
+ startedAt: z.ZodString;
124
+ inputTokens: z.ZodNumber;
125
+ outputTokens: z.ZodNumber;
126
+ workerText: z.ZodString;
127
+ }, z.core.$strict>>>;
121
128
  terminalReason: z.ZodOptional<z.ZodString>;
122
129
  }, z.core.$strict>;
123
130
  export declare const LoopEventSchema: z.ZodObject<{
@@ -9,5 +9,7 @@ export interface VerificationPlan {
9
9
  commands: VerificationCommand[];
10
10
  needsHumanReason?: string;
11
11
  }
12
+ /** Verification state is retained across dozens of rounds; keep each stream evidential, not archival. */
13
+ export declare const MAX_PERSISTED_VERIFICATION_STREAM_BYTES = 1024;
12
14
  export declare function inferVerificationPlan(workspace: string): Promise<VerificationPlan>;
13
15
  export declare function runVerificationPlan(plan: VerificationPlan, workspace: string, signal: AbortSignal, executionEnvironment?: ExecutionEnvironment): Promise<LoopVerificationEvidence>;
@@ -4,6 +4,9 @@ import { type McpClientFactory } from "./mcp/client.js";
4
4
  import type { PermissionProfile, PermissionRequest } from "./permissions/engine.js";
5
5
  import { type PromptEnvironment } from "./prompts/system.js";
6
6
  import type { ApprovalDecision } from "./tools/runtime.js";
7
+ import { type MemoryRestartContinuation } from "./utils/memory-restart.js";
8
+ import { type HeapReading } from "./utils/heap.js";
9
+ import { type RotationCensusHolder } from "./utils/rotation-census.js";
7
10
  import { type FileWriteProposal } from "./tools/files.js";
8
11
  import type { ToolDefinition } from "./tools/types.js";
9
12
  import { FlavorSession, type SessionOutput, type SessionServices } from "./ui/session.js";
@@ -22,6 +25,11 @@ export interface ProductionRuntimeOptions {
22
25
  home?: string;
23
26
  environment?: NodeJS.ProcessEnv;
24
27
  output(event: SessionOutput): void;
28
+ /**
29
+ * Embedder-owned restart hook. CLI callers omit it and exit with code 75;
30
+ * desktop callers dispose and recreate the runtime around the saved session.
31
+ */
32
+ onMemoryRestartRequested?(sessionId: string): void;
25
33
  onApprovalChange?(): void;
26
34
  /** Called whenever the active registerTool-managed command set changes. */
27
35
  onToolsChange?(): void;
@@ -102,4 +110,13 @@ export declare class ApprovalBridge {
102
110
  resolve(decision: ApprovalDecision): void;
103
111
  }
104
112
  export declare function createProductionRuntime(options: ProductionRuntimeOptions): Promise<ProductionRuntime>;
113
+ export interface MemoryRestartRotation {
114
+ /** Set when a /loop or /goal must be resumed by the relaunched process. */
115
+ continuation?: MemoryRestartContinuation;
116
+ /** Heap reading captured at the decision point; drives census + snapshot. */
117
+ reading?: HeapReading;
118
+ /** Retention census holders reported by the major in-memory owners. */
119
+ holders?: Record<string, RotationCensusHolder>;
120
+ }
105
121
  export declare function runGoalSession(orchestrator: GoalOrchestrator, goal: string, signal: AbortSignal): AsyncIterable<AgentEvent>;
122
+ export declare function runResumeGoalSession(orchestrator: GoalOrchestrator, goalId: string, signal: AbortSignal): AsyncIterable<AgentEvent>;
package/dist/sdk/index.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  FlavorRpcServer,
5
5
  TraceRecordSchema,
6
6
  TraceRecorder
7
- } from "../chunk-3BHKW5A7.js";
7
+ } from "../chunk-JZVC4477.js";
8
8
  import {
9
9
  AgentMessageQueue,
10
10
  DockerExecutionEnvironment,
@@ -13,9 +13,9 @@ import {
13
13
  WorkspaceCheckpointStore,
14
14
  buildDockerInvocation,
15
15
  createProductionRuntime
16
- } from "../chunk-NIKCPCJG.js";
17
- import "../chunk-CIVPKHF4.js";
18
- import "../chunk-KBHWS7M6.js";
16
+ } from "../chunk-J7TLT6LR.js";
17
+ import "../chunk-N5MXHJKD.js";
18
+ import "../chunk-KQMKY7C5.js";
19
19
  import "../chunk-ZJCAQXA7.js";
20
20
  import "../chunk-S32JRDZK.js";
21
21
 
@@ -20,6 +20,8 @@ export declare class SessionHistory {
20
20
  private constructor();
21
21
  static open(options: SessionHistoryOptions): Promise<SessionHistory>;
22
22
  get leafId(): string | null;
23
+ /** Cheap retained-node count for the rotation census (no cloning). */
24
+ get nodeCount(): number;
23
25
  tree(): readonly SessionTreeNode[];
24
26
  append(input: {
25
27
  prompt: string;
@@ -4,6 +4,7 @@ import type { PermissionMode } from "../permissions/engine.js";
4
4
  import type { SkillMetadata } from "../skills/registry.js";
5
5
  import { type McpSlashCommand, type ModelRole } from "./commands.js";
6
6
  import type { QuestionBridge } from "../tools/ask-user-question.js";
7
+ import type { MemoryRestartContinuation } from "../utils/memory-restart.js";
7
8
  import type { MemoryType } from "../memory/types.js";
8
9
  import { type AgentQueueSnapshot } from "../agent/message-queue.js";
9
10
  import type { SessionTreeNode } from "../session/tree.js";
@@ -113,6 +114,14 @@ export interface SessionServices {
113
114
  runSkill(skill: string, prompt: string, signal: AbortSignal): AsyncIterable<AgentEvent>;
114
115
  runLoop(goal: string, signal: AbortSignal): AsyncIterable<AgentEvent>;
115
116
  runGoal(goal: string, signal: AbortSignal): AsyncIterable<AgentEvent>;
117
+ /** Resume a /loop interrupted by a heap rotation, keyed by its persisted id. */
118
+ resumeLoop?(loopId: string, signal: AbortSignal): AsyncIterable<AgentEvent>;
119
+ /** Resume a /goal interrupted by a heap rotation, keyed by its persisted id. */
120
+ resumeGoal?(goalId: string, signal: AbortSignal): AsyncIterable<AgentEvent>;
121
+ /** The loop/goal a relaunched process should resume after a rotation, consumed once. */
122
+ continuation?(): MemoryRestartContinuation | undefined;
123
+ /** True after the runtime has committed to replacing the current heap. */
124
+ rotationPending?(): boolean;
116
125
  mcp(command: McpSlashCommand, signal: AbortSignal): Promise<string>;
117
126
  ide?(): Promise<string>;
118
127
  ideContext?(): Promise<IdeEditorContext | undefined>;
@@ -186,6 +195,8 @@ export declare class FlavorSession {
186
195
  constructor(services: SessionServices);
187
196
  get active(): boolean;
188
197
  queueSnapshot(): AgentQueueSnapshot;
198
+ /** True when start() admitted a persisted /loop or /goal continuation. */
199
+ get rotationContinuationResumed(): boolean;
189
200
  clearQueue(): AgentQueueSnapshot;
190
201
  whenIdle(): Promise<void>;
191
202
  steer(input: string): void;
@@ -77,6 +77,9 @@ export interface TranscriptState {
77
77
  */
78
78
  export declare const MAX_TRANSCRIPT_TURNS = 200;
79
79
  export declare const MAX_TRANSCRIPT_CHARS = 2000000;
80
+ /** A /loop or /goal is one presentation turn and can run for days. */
81
+ export declare const MAX_ACTIVE_TRANSCRIPT_BLOCKS = 160;
82
+ export declare const MAX_ACTIVE_ASSISTANT_CHARS = 64000;
80
83
  export type TranscriptAction = {
81
84
  type: "hydrate";
82
85
  messages: readonly TranscriptHistoryMessage[];
@@ -102,3 +105,9 @@ export declare function createTranscriptState(): TranscriptState;
102
105
  export declare function transcriptReducer(state: TranscriptState, action: TranscriptAction): TranscriptState;
103
106
  export declare function transcriptFromLegacyConversation(messages: readonly TranscriptHistoryMessage[], compact?: TranscriptCompactBoundary): TranscriptState;
104
107
  export declare function restoreTranscriptState(state: TranscriptState): TranscriptState;
108
+ /** Rotation-only diagnostic; callers invoke it at most once per restart. */
109
+ export declare function transcriptCensus(state: TranscriptState): {
110
+ turns: number;
111
+ blocks: number;
112
+ chars: number;
113
+ };
@@ -2,3 +2,19 @@
2
2
  * The operation must still receive the signal when it supports cancellation.
3
3
  */
4
4
  export declare function waitWithSignal<T>(operation: Promise<T>, signal?: AbortSignal): Promise<T>;
5
+ export interface ScopedAbortSignal {
6
+ readonly signal: AbortSignal;
7
+ dispose(): void;
8
+ }
9
+ /**
10
+ * Give one provider request its own short-lived signal while preserving
11
+ * cancellation from the enclosing turn.
12
+ *
13
+ * Some HTTP SDKs attach a once-only listener to the caller's signal and do
14
+ * not remove it after a successful request. Reusing a turn signal for
15
+ * hundreds of agent iterations then retains every request controller until
16
+ * the entire turn ends. Disposing this scope unlinks the turn and aborts the
17
+ * derived signal so SDK listeners and any unfinished response body release
18
+ * their references immediately.
19
+ */
20
+ export declare function createScopedAbortSignal(parent?: AbortSignal): ScopedAbortSignal;
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Heap watermarks for the controlled rotation protocol.
3
+ *
4
+ * Long-running sessions (interactive turns, /loop cycles, /goal rounds) rotate
5
+ * onto a fresh heap instead of growing until V8 dies. Two watermarks:
6
+ *
7
+ * - MEMORY_PRESSURE_HEAP_RATIO: hard guard checked before every model call.
8
+ * Tripping it stops the current turn; the session is persisted first.
9
+ * - MEMORY_ROTATION_HEAP_RATIO: soft guard checked only at turn/cycle/round
10
+ * boundaries. Tripping it rotates between units of work, so multi-day runs
11
+ * keep going on a fresh heap without losing the loop or goal in flight.
12
+ *
13
+ * Both readings are GC-verified when --expose-gc is available (the launcher
14
+ * injects it): heapUsed includes uncollected garbage, and declaring pressure
15
+ * on garbage alone would rotate or stop turns for no reason. A full GC before
16
+ * judging keeps the decision about the live set only.
17
+ */
18
+ export declare const MEMORY_PRESSURE_HEAP_RATIO = 0.8;
19
+ export declare const MEMORY_ROTATION_HEAP_RATIO = 0.6;
20
+ export declare const MEMORY_PRESSURE_RSS_RATIO = 0.75;
21
+ export declare const MEMORY_ROTATION_RSS_RATIO = 0.6;
22
+ export interface HeapReading {
23
+ heapUsed: number;
24
+ heapLimit: number;
25
+ ratio: number;
26
+ /** Ratio measured after a forced full GC; undefined when gc is not exposed. */
27
+ verifiedRatio?: number;
28
+ gcVerified: boolean;
29
+ rss?: number;
30
+ memoryLimit?: number;
31
+ rssRatio?: number;
32
+ external?: number;
33
+ arrayBuffers?: number;
34
+ }
35
+ export declare function readHeap(): {
36
+ heapUsed: number;
37
+ heapLimit: number;
38
+ ratio: number;
39
+ };
40
+ /**
41
+ * Hard-guard reading. Returns undefined below the threshold; when the raw
42
+ * reading crosses it, a full GC (if exposed) decides whether the live set
43
+ * really is that large. Without --expose-gc the raw reading stands.
44
+ */
45
+ export declare function verifiedHeapPressure(threshold: number): HeapReading | undefined;
46
+ /**
47
+ * Boundary rotation decision. Cheap below the precheck ratio; above it the
48
+ * live set is measured with a full GC and compared against the soft
49
+ * watermark. Without --expose-gc only a raw reading at the hard watermark
50
+ * rotates, so an uninstrumented process degrades to the old behaviour.
51
+ */
52
+ export declare function heapRotationNeeded(): HeapReading | undefined;
53
+ /**
54
+ * Explicit opt-in only. The launcher already asks V8 for one near-limit
55
+ * snapshot; synchronously taking another in the recovery path can exhaust the
56
+ * very heap/RSS headroom needed to persist and exit cleanly.
57
+ */
58
+ export declare function heapSnapshotWarranted(_reading: HeapReading): boolean;
@@ -7,23 +7,62 @@
7
7
  * relaunches the CLI with `--resume <sessionId>`, so memory pressure restores
8
8
  * the saved session instead of ending in a fatal V8 OOM crash. The interrupted
9
9
  * turn is intentionally not replayed because it may contain non-idempotent tools.
10
+ *
11
+ * Boundary rotations (between turns, /loop cycles, /goal rounds) carry a
12
+ * `continuation` in the marker: the relaunched process picks the interrupted
13
+ * loop or goal back up from its persisted state, so multi-day autonomous runs
14
+ * survive heap rotation without losing the long-running task.
10
15
  */
11
16
  export declare const MEMORY_RESTART_EXIT_CODE = 75;
12
17
  export declare const MEMORY_RESTART_MARKER_FILE = "memory-restart.json";
13
- export declare const MEMORY_RESTART_MAX_ATTEMPTS = 3;
18
+ /**
19
+ * Rotations are seamless (the session and any loop/goal resume automatically),
20
+ * so the budget only exists to stop a pathological spin: 24 rotations inside
21
+ * one hour still covers a multi-day run rotating every few hours.
22
+ */
23
+ export declare const MEMORY_RESTART_MAX_ATTEMPTS = 24;
14
24
  export declare const MEMORY_RESTART_WINDOW_MS: number;
25
+ /** Two rotations closer together than this mean the fresh heap is born heavy; stop rotating and let the hard guard decide. */
26
+ export declare const MEMORY_RESTART_MIN_GAP_MS: number;
27
+ /**
28
+ * Leave enough time for a slow launcher, host reboot, or unattended machine
29
+ * wake-up to recover a persisted long task. Session/id validation still keeps
30
+ * an unrelated stale marker from resuming in the wrong process.
31
+ */
32
+ export declare const MEMORY_RESTART_CONTINUATION_TTL_MS: number;
33
+ export interface MemoryRestartContinuation {
34
+ kind: "loop" | "goal";
35
+ id: string;
36
+ }
15
37
  export interface MemoryRestartMarker {
16
38
  sessionId: string;
39
+ /** Start of the fixed accounting window; unlike requestedAt this does not slide. */
40
+ windowStartedAt?: string;
17
41
  requestedAt: string;
18
42
  attempts: number;
43
+ continuation?: MemoryRestartContinuation;
19
44
  }
45
+ /** Recorded when a rotation is requested; orchestrators skip terminal bookkeeping on the way out. */
46
+ export declare function markMemoryRotation(): void;
47
+ export declare function memoryRotationActive(): boolean;
48
+ /** In-process hosts clear this only after the old runtime has been fully disposed. */
49
+ export declare function clearMemoryRotation(): void;
20
50
  export declare function memoryRestartMarkerPath(workspace: string): string;
21
51
  /**
22
- * Count restarts per session inside a rolling window. A marker for a
52
+ * Count restarts per session inside a fixed window. A marker for a
23
53
  * different session or an expired window starts counting from one again, so
24
54
  * a healthy long-lived session never exhausts the budget.
25
55
  */
26
- export declare function nextMemoryRestartMarker(previous: MemoryRestartMarker | undefined, sessionId: string, now: Date): MemoryRestartMarker;
56
+ export declare function nextMemoryRestartMarker(previous: MemoryRestartMarker | undefined, sessionId: string, now: Date, continuation?: MemoryRestartContinuation): MemoryRestartMarker;
57
+ /**
58
+ * Remove a consumed continuation without turning marker consumption into a
59
+ * second restart attempt or extending the accounting/cooldown windows.
60
+ */
61
+ export declare function consumedMemoryRestartMarker(marker: MemoryRestartMarker): MemoryRestartMarker;
62
+ /** True when the previous rotation for this session is too recent for another seamless one. */
63
+ export declare function rotationCooldownActive(marker: MemoryRestartMarker | undefined, sessionId: string, now: Date): boolean;
64
+ /** The continuation a relaunched process should pick up, if still fresh. */
65
+ export declare function pendingContinuation(marker: MemoryRestartMarker | undefined, sessionId: string, now: Date): MemoryRestartContinuation | undefined;
27
66
  export declare function shouldRelaunchForMemoryRestart(marker: MemoryRestartMarker | undefined): boolean;
28
67
  /**
29
68
  * Rebuild the CLI arguments for the relaunched process: drop any existing
@@ -0,0 +1,36 @@
1
+ import type { HeapReading } from "./heap.js";
2
+ /**
3
+ * Rotation forensics. Every heap rotation leaves a retention census: each
4
+ * major in-memory holder reports its retained size, so the next recurrence
5
+ * names its own grower instead of restarting with zero evidence. A full
6
+ * .heapsnapshot accompanies rotations whose verified live set is near the
7
+ * hard limit (or every rotation under FLAVOR_HEAP_SNAPSHOT_ON_ROTATE=1).
8
+ */
9
+ export interface RotationCensusHolder {
10
+ entries?: number;
11
+ chars?: number;
12
+ bytes?: number;
13
+ }
14
+ export interface RotationCensus {
15
+ at: string;
16
+ reason: string;
17
+ sessionId: string;
18
+ heap: {
19
+ heapUsedMb: number;
20
+ heapLimitMb: number;
21
+ rawRatio: number;
22
+ verifiedRatio?: number;
23
+ gcVerified: boolean;
24
+ rssMb: number;
25
+ externalMb: number;
26
+ arrayBuffersMb: number;
27
+ memoryLimitMb?: number;
28
+ rssRatio?: number;
29
+ };
30
+ holders: Record<string, RotationCensusHolder>;
31
+ }
32
+ export declare function censusHeapBlock(reading: HeapReading): RotationCensus["heap"];
33
+ /** Best-effort: a failed census must never block the rotation itself. */
34
+ export declare function writeRotationCensus(workspace: string, census: RotationCensus): string | undefined;
35
+ /** Best-effort heap snapshot; synchronous and slow on large heaps by nature. */
36
+ export declare function writeRotationHeapSnapshot(workspace: string): string | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flavor-code",
3
- "version": "1.4.0-beta.3",
3
+ "version": "1.4.0-beta.5",
4
4
  "author": "YachuanWzh",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -1,53 +0,0 @@
1
- #!/usr/bin/env node
2
- import { createRequire } from "node:module"; const require = createRequire(import.meta.url);
3
-
4
- // src/utils/memory-restart.ts
5
- import { join } from "path";
6
- var MEMORY_RESTART_EXIT_CODE = 75;
7
- var MEMORY_RESTART_MARKER_FILE = "memory-restart.json";
8
- var MEMORY_RESTART_MAX_ATTEMPTS = 3;
9
- var MEMORY_RESTART_WINDOW_MS = 30 * 60 * 1e3;
10
- var SESSION_ID_PATTERN = /^session-[A-Za-z0-9_-]+$/u;
11
- function memoryRestartMarkerPath(workspace) {
12
- return join(workspace, ".flavor", "tmp", MEMORY_RESTART_MARKER_FILE);
13
- }
14
- function nextMemoryRestartMarker(previous, sessionId, now) {
15
- const reusable = previous !== void 0 && previous.sessionId === sessionId && now.getTime() - Date.parse(previous.requestedAt) < MEMORY_RESTART_WINDOW_MS && Number.isInteger(previous.attempts) && previous.attempts > 0;
16
- return { sessionId, requestedAt: now.toISOString(), attempts: reusable ? previous.attempts + 1 : 1 };
17
- }
18
- function shouldRelaunchForMemoryRestart(marker) {
19
- return marker !== void 0 && SESSION_ID_PATTERN.test(marker.sessionId) && Number.isInteger(marker.attempts) && marker.attempts >= 1 && marker.attempts <= MEMORY_RESTART_MAX_ATTEMPTS;
20
- }
21
- function memoryRestartArgs(argv, marker) {
22
- if (!shouldRelaunchForMemoryRestart(marker)) return void 0;
23
- const stripped = [];
24
- for (let index = 0; index < argv.length; index += 1) {
25
- const argument = argv[index];
26
- if (argument === "--resume") {
27
- if (index + 1 < argv.length && !argv[index + 1].startsWith("-")) index += 1;
28
- continue;
29
- }
30
- if (argument.startsWith("--resume=")) continue;
31
- stripped.push(argument);
32
- }
33
- return [...stripped, "--resume", marker.sessionId];
34
- }
35
- function parseMemoryRestartMarker(json) {
36
- try {
37
- const value = JSON.parse(json);
38
- if (typeof value.sessionId !== "string" || typeof value.requestedAt !== "string" || typeof value.attempts !== "number") {
39
- return void 0;
40
- }
41
- return { sessionId: value.sessionId, requestedAt: value.requestedAt, attempts: value.attempts };
42
- } catch {
43
- return void 0;
44
- }
45
- }
46
-
47
- export {
48
- MEMORY_RESTART_EXIT_CODE,
49
- memoryRestartMarkerPath,
50
- nextMemoryRestartMarker,
51
- memoryRestartArgs,
52
- parseMemoryRestartMarker
53
- };