sliccy 2.9.5 → 2.9.6

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.
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/slicc-editor-BXeXUUnd.js","assets/preload-helper-D4M6sveU.js","assets/dist-Ct5XR8EU.js","assets/magick-wasm-BtLTRPKb.js","assets/chunk-jRWAZmH_.js","assets/sql-wasm-DsCCg8Gn.js","assets/__vite-browser-external-BotBUAC3.js","assets/pyodide-JXDzDQlX.js","assets/es-DAIH-mv9.js","assets/dist-BNEtmCAc2.js","assets/provider-settings-ChPESpua.js","assets/simple-options-CP_5aL7H.js","assets/openai-CuiHR4mv.js","assets/logger-B-No_qN_.js","assets/skills-5aRDmjxF.js","assets/constants-BnzYaC4L.js","assets/path-utils-CgbXfwyO.js","assets/xterm-BmfB5bmM.css","assets/offscreen-client-DJYi05-D.js","assets/bsh-watchdog-DYfdvOrR.js"])))=>i.map(i=>d[i]);
2
- import{a as e,i as t,n,o as r,r as i,t as a}from"./chunk-jRWAZmH_.js";import{t as o}from"./logger-B-No_qN_.js";import{t as s}from"./preload-helper-D4M6sveU.js";import{_ as c,a as l,b as u,c as d,d as f,f as p,g as m,i as h,m as g,n as _,o as v,p as y,r as b,s as x,t as S,u as C,v as w,x as T,y as E}from"./provider-settings-ChPESpua.js";import{f as D,l as O,p as ee,s as te,u as ne}from"./constants-BnzYaC4L.js";import{n as k,r as re,t as ie}from"./path-utils-CgbXfwyO.js";import{n as ae,r as oe}from"./skills-5aRDmjxF.js";import{_ as se,a as ce,b as le,c as ue,d as de,f as fe,g as A,h as pe,i as me,l as he,m as ge,n as _e,o as ve,p as ye,r as be,s as xe,t as j,u as Se,v as Ce,x as we,y as Te}from"./db-ybNEUfR8.js";import{t as Ee}from"./magick-wasm-BtLTRPKb.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),e.crossOrigin===`use-credentials`?t.credentials=`include`:e.crossOrigin===`anonymous`?t.credentials=`omit`:t.credentials=`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();function M(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var De=M();function N(e){De=e}var P={exec:()=>null};function Oe(e,t=``){let n=typeof e==`string`?e:e.source,r={replace:(e,t)=>{let i=typeof t==`string`?t:t.source;return i=i.replace(Ae.caret,`$1`),n=n.replace(e,i),r},getRegex:()=>new RegExp(n,t)};return r}var ke=(()=>{try{return!0}catch{return!1}})(),Ae={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:e=>RegExp(`^( {0,3}${e})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}#`),htmlBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}<(?:[a-z].*>|!--)`,`i`),blockquoteBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}>`)},je=/^(?:[ \t]*(?:\n|$))+/,Me=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,Ne=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,Pe=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,Fe=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,Ie=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,Le=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,Re=Oe(Le).replace(/bull/g,Ie).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,``).getRegex(),ze=Oe(Le).replace(/bull/g,Ie).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),Be=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,Ve=/^[^\n]+/,He=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,Ue=Oe(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace(`label`,He).replace(`title`,/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),We=Oe(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,Ie).getRegex(),Ge=`address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul`,Ke=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,qe=Oe(`^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))`,`i`).replace(`comment`,Ke).replace(`tag`,Ge).replace(`attribute`,/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),Je=Oe(Be).replace(`hr`,Pe).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)])[ \\t]`).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,Ge).getRegex(),Ye={blockquote:Oe(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace(`paragraph`,Je).getRegex(),code:Me,def:Ue,fences:Ne,heading:Fe,hr:Pe,html:qe,lheading:Re,list:We,newline:je,paragraph:Je,table:P,text:Ve},Xe=Oe(`^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)`).replace(`hr`,Pe).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`blockquote`,` {0,3}>`).replace(`code`,`(?: {4}| {0,3} )[^\\n]`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)])[ \\t]`).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,Ge).getRegex(),Ze={...Ye,lheading:ze,table:Xe,paragraph:Oe(Be).replace(`hr`,Pe).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`table`,Xe).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)])[ \\t]`).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,Ge).getRegex()},Qe={...Ye,html:Oe(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace(`comment`,Ke).replace(/tag/g,`(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b`).getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:P,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:Oe(Be).replace(`hr`,Pe).replace(`heading`,` *#{1,6} *[^
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/slicc-editor-BXeXUUnd.js","assets/preload-helper-D4M6sveU.js","assets/dist-Ct5XR8EU.js","assets/magick-wasm-BtLTRPKb.js","assets/chunk-jRWAZmH_.js","assets/sql-wasm-DsCCg8Gn.js","assets/__vite-browser-external-BotBUAC3.js","assets/pyodide-JXDzDQlX.js","assets/es-QZlqFBVD.js","assets/dist-BNEtmCAc2.js","assets/provider-settings-ArVcQj7G.js","assets/simple-options-CP_5aL7H.js","assets/openai-CuiHR4mv.js","assets/logger-B-No_qN_.js","assets/skills-Cwc_5caT.js","assets/constants-BnzYaC4L.js","assets/path-utils-CgbXfwyO.js","assets/xterm-BmfB5bmM.css","assets/offscreen-client-DJYi05-D.js","assets/bsh-watchdog-DYfdvOrR.js"])))=>i.map(i=>d[i]);
2
+ import{a as e,i as t,n,o as r,r as i,t as a}from"./chunk-jRWAZmH_.js";import{t as o}from"./logger-B-No_qN_.js";import{t as s}from"./preload-helper-D4M6sveU.js";import{_ as c,a as l,b as u,c as d,d as f,f as p,g as m,i as h,m as g,n as _,o as v,p as y,r as b,s as x,t as S,u as C,v as w,x as T,y as E}from"./provider-settings-ArVcQj7G.js";import{f as D,l as O,p as ee,s as te,u as ne}from"./constants-BnzYaC4L.js";import{n as k,r as re,t as ie}from"./path-utils-CgbXfwyO.js";import{n as ae,r as oe}from"./skills-Cwc_5caT.js";import{_ as se,a as ce,b as le,c as ue,d as de,f as fe,g as A,h as pe,i as me,l as he,m as ge,n as _e,o as ve,p as ye,r as be,s as xe,t as j,u as Se,v as Ce,x as we,y as Te}from"./db-ybNEUfR8.js";import{t as Ee}from"./magick-wasm-BtLTRPKb.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),e.crossOrigin===`use-credentials`?t.credentials=`include`:e.crossOrigin===`anonymous`?t.credentials=`omit`:t.credentials=`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();function M(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var De=M();function N(e){De=e}var P={exec:()=>null};function Oe(e,t=``){let n=typeof e==`string`?e:e.source,r={replace:(e,t)=>{let i=typeof t==`string`?t:t.source;return i=i.replace(Ae.caret,`$1`),n=n.replace(e,i),r},getRegex:()=>new RegExp(n,t)};return r}var ke=(()=>{try{return!0}catch{return!1}})(),Ae={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:e=>RegExp(`^( {0,3}${e})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}#`),htmlBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}<(?:[a-z].*>|!--)`,`i`),blockquoteBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}>`)},je=/^(?:[ \t]*(?:\n|$))+/,Me=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,Ne=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,Pe=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,Fe=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,Ie=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,Le=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,Re=Oe(Le).replace(/bull/g,Ie).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,``).getRegex(),ze=Oe(Le).replace(/bull/g,Ie).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),Be=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,Ve=/^[^\n]+/,He=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,Ue=Oe(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace(`label`,He).replace(`title`,/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),We=Oe(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,Ie).getRegex(),Ge=`address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul`,Ke=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,qe=Oe(`^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))`,`i`).replace(`comment`,Ke).replace(`tag`,Ge).replace(`attribute`,/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),Je=Oe(Be).replace(`hr`,Pe).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)])[ \\t]`).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,Ge).getRegex(),Ye={blockquote:Oe(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace(`paragraph`,Je).getRegex(),code:Me,def:Ue,fences:Ne,heading:Fe,hr:Pe,html:qe,lheading:Re,list:We,newline:je,paragraph:Je,table:P,text:Ve},Xe=Oe(`^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)`).replace(`hr`,Pe).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`blockquote`,` {0,3}>`).replace(`code`,`(?: {4}| {0,3} )[^\\n]`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)])[ \\t]`).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,Ge).getRegex(),Ze={...Ye,lheading:ze,table:Xe,paragraph:Oe(Be).replace(`hr`,Pe).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`table`,Xe).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)])[ \\t]`).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,Ge).getRegex()},Qe={...Ye,html:Oe(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace(`comment`,Ke).replace(/tag/g,`(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b`).getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:P,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:Oe(Be).replace(`hr`,Pe).replace(`heading`,` *#{1,6} *[^
3
3
  ]`).replace(`lheading`,Re).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`|fences`,``).replace(`|list`,``).replace(`|html`,``).replace(`|tag`,``).getRegex()},$e=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,et=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,tt=/^( {2,}|\\)\n(?!\s*$)/,nt=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,rt=/[\p{P}\p{S}]/u,it=/[\s\p{P}\p{S}]/u,at=/[^\s\p{P}\p{S}]/u,ot=Oe(/^((?![*_])punctSpace)/,`u`).replace(/punctSpace/g,it).getRegex(),st=/(?!~)[\p{P}\p{S}]/u,ct=/(?!~)[\s\p{P}\p{S}]/u,lt=/(?:[^\s\p{P}\p{S}]|~)/u,ut=Oe(/link|precode-code|html/,`g`).replace(`link`,/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace(`precode-`,ke?"(?<!`)()":"(^^|[^`])").replace(`code`,/(?<b>`+)[^`]+\k<b>(?!`)/).replace(`html`,/<(?! )[^<>]*?>/).getRegex(),dt=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,ft=Oe(dt,`u`).replace(/punct/g,rt).getRegex(),pt=Oe(dt,`u`).replace(/punct/g,st).getRegex(),mt=`^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)`,ht=Oe(mt,`gu`).replace(/notPunctSpace/g,at).replace(/punctSpace/g,it).replace(/punct/g,rt).getRegex(),gt=Oe(mt,`gu`).replace(/notPunctSpace/g,lt).replace(/punctSpace/g,ct).replace(/punct/g,st).getRegex(),_t=Oe(`^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)`,`gu`).replace(/notPunctSpace/g,at).replace(/punctSpace/g,it).replace(/punct/g,rt).getRegex(),vt=Oe(/^~~?(?:((?!~)punct)|[^\s~])/,`u`).replace(/punct/g,rt).getRegex(),yt=Oe(`^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)`,`gu`).replace(/notPunctSpace/g,at).replace(/punctSpace/g,it).replace(/punct/g,rt).getRegex(),bt=Oe(/\\(punct)/,`gu`).replace(/punct/g,rt).getRegex(),xt=Oe(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace(`scheme`,/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace(`email`,/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),St=Oe(Ke).replace(`(?:-->|$)`,`-->`).getRegex(),Ct=Oe(`^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>`).replace(`comment`,St).replace(`attribute`,/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),wt=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/,Tt=Oe(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace(`label`,wt).replace(`href`,/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace(`title`,/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Et=Oe(/^!?\[(label)\]\[(ref)\]/).replace(`label`,wt).replace(`ref`,He).getRegex(),Dt=Oe(/^!?\[(ref)\](?:\[\])?/).replace(`ref`,He).getRegex(),Ot=Oe(`reflink|nolink(?!\\()`,`g`).replace(`reflink`,Et).replace(`nolink`,Dt).getRegex(),kt=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,At={_backpedal:P,anyPunctuation:bt,autolink:xt,blockSkip:ut,br:tt,code:et,del:P,delLDelim:P,delRDelim:P,emStrongLDelim:ft,emStrongRDelimAst:ht,emStrongRDelimUnd:_t,escape:$e,link:Tt,nolink:Dt,punctuation:ot,reflink:Et,reflinkSearch:Ot,tag:Ct,text:nt,url:P},jt={...At,link:Oe(/^!?\[(label)\]\((.*?)\)/).replace(`label`,wt).getRegex(),reflink:Oe(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace(`label`,wt).getRegex()},Mt={...At,emStrongRDelimAst:gt,emStrongLDelim:pt,delLDelim:vt,delRDelim:yt,url:Oe(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace(`protocol`,kt).replace(`email`,/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:Oe(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace(`protocol`,kt).getRegex()},Nt={...Mt,br:Oe(tt).replace(`{2,}`,`*`).getRegex(),text:Oe(Mt.text).replace(`\\b_`,`\\b_| {2,}\\n`).replace(/\{2,\}/g,`*`).getRegex()},Pt={normal:Ye,gfm:Ze,pedantic:Qe},Ft={normal:At,gfm:Mt,breaks:Nt,pedantic:jt},It={"&":`&amp;`,"<":`&lt;`,">":`&gt;`,'"':`&quot;`,"'":`&#39;`},Lt=e=>It[e];function Rt(e,t){if(t){if(Ae.escapeTest.test(e))return e.replace(Ae.escapeReplace,Lt)}else if(Ae.escapeTestNoEncode.test(e))return e.replace(Ae.escapeReplaceNoEncode,Lt);return e}function zt(e){try{e=encodeURI(e).replace(Ae.percentDecode,`%`)}catch{return null}return e}function Bt(e,t){let n=e.replace(Ae.findPipe,(e,t,n)=>{let r=!1,i=t;for(;--i>=0&&n[i]===`\\`;)r=!r;return r?`|`:` |`}).split(Ae.splitPipe),r=0;if(n[0].trim()||n.shift(),n.length>0&&!n.at(-1)?.trim()&&n.pop(),t)if(n.length>t)n.splice(t);else for(;n.length<t;)n.push(``);for(;r<n.length;r++)n[r]=n[r].trim().replace(Ae.slashPipe,`|`);return n}function Vt(e,t,n){let r=e.length;if(r===0)return``;let i=0;for(;i<r;){let a=e.charAt(r-i-1);if(a===t&&!n)i++;else if(a!==t&&n)i++;else break}return e.slice(0,r-i)}function Ht(e){let t=e.split(`
4
4
  `),n=t.length-1;for(;n>=0&&!t[n].trim();)n--;return t.length-n<=2?e:t.slice(0,n+1).join(`
5
5
  `)}function Ut(e,t){if(e.indexOf(t[1])===-1)return-1;let n=0;for(let r=0;r<e.length;r++)if(e[r]===`\\`)r++;else if(e[r]===t[0])n++;else if(e[r]===t[1]&&(n--,n<0))return r;return n>0?-2:-1}function Wt(e,t=0){let n=t,r=``;for(let t of e)if(t===` `){let e=4-n%4;r+=` `.repeat(e),n+=e}else r+=t,n++;return r}function Gt(e,t,n,r,i){let a=t.href,o=t.title||null,s=e[1].replace(i.other.outputLinkReplace,`$1`);r.state.inLink=!0;let c={type:e[0].charAt(0)===`!`?`image`:`link`,raw:n,href:a,title:o,text:s,tokens:r.inlineTokens(s)};return r.state.inLink=!1,c}function Kt(e,t,n){let r=e.match(n.other.indentCodeCompensation);if(r===null)return t;let i=r[1];return t.split(`
@@ -3277,11 +3277,11 @@ gpgsig`+GJ(o)+`
3277
3277
  ignorecase = true
3278
3278
  `),await e.write(r+`/HEAD`,`ref: refs/heads/${i}\n`)}async function LX({fs:e,cache:t,http:n,onProgress:r,onMessage:i,onAuth:a,onAuthSuccess:o,onAuthFailure:s,onPostCheckout:c,dir:l,gitdir:u,url:d,corsProxy:f,ref:p,remote:m,depth:h,since:g,exclude:_,relative:v,singleBranch:y,noCheckout:b,noTags:x,headers:S,nonBlocking:C,batchSize:w=100}){try{if(await IX({fs:e,gitdir:u}),await zY({fs:e,gitdir:u,remote:m,url:d,force:!1}),f){let t=await Tq.get({fs:e,gitdir:u});await t.set(`http.corsProxy`,f),await Tq.save({fs:e,gitdir:u,config:t})}let{defaultBranch:T,fetchHead:E}=await FX({fs:e,cache:t,http:n,onProgress:r,onMessage:i,onAuth:a,onAuthSuccess:o,onAuthFailure:s,gitdir:u,ref:p,remote:m,corsProxy:f,depth:h,since:g,exclude:_,relative:v,singleBranch:y,headers:S,tags:!x});if(E===null)return;p||=T,p=p.replace(`refs/heads/`,``),await KY({fs:e,cache:t,onProgress:r,onPostCheckout:c,dir:l,gitdir:u,ref:p,remote:m,noCheckout:b,nonBlocking:C,batchSize:w})}catch(t){throw await e.rmdir(u,{recursive:!0,maxRetries:10}).catch(()=>void 0),t}}async function RX({fs:e,http:t,onProgress:n,onMessage:r,onAuth:i,onAuthSuccess:a,onAuthFailure:o,onPostCheckout:s,dir:c,gitdir:l=X(c,`.git`),url:u,corsProxy:d=void 0,ref:f=void 0,remote:p=`origin`,depth:m=void 0,since:h=void 0,exclude:g=[],relative:_=!1,singleBranch:v=!1,noCheckout:y=!1,noTags:b=!1,headers:x={},cache:S={},nonBlocking:C=!1,batchSize:w=100}){try{Z(`fs`,e),Z(`http`,t),Z(`gitdir`,l),y||Z(`dir`,c),Z(`url`,u);let T=new dY(e);return await LX({fs:T,cache:S,http:t,onProgress:n,onMessage:r,onAuth:i,onAuthSuccess:a,onAuthFailure:o,onPostCheckout:s,dir:c,gitdir:await pY({fsp:T,dotgit:l}),url:u,corsProxy:d,ref:f,remote:p,depth:m,since:h,exclude:g,relative:_,singleBranch:v,noCheckout:y,noTags:b,headers:x,nonBlocking:C,batchSize:w})}catch(e){throw e.caller=`git.clone`,e}}async function zX({fs:e,onSign:t,dir:n,gitdir:r=X(n,`.git`),message:i,author:a,committer:o,signingKey:s,amend:c=!1,dryRun:l=!1,noUpdateBranch:u=!1,ref:d,parent:f,tree:p,cache:m={}}){try{Z(`fs`,e),c||Z(`message`,i),s&&Z(`onSign`,t);let n=new dY(e);return await jY({fs:n,cache:m,onSign:t,gitdir:await pY({fsp:n,dotgit:r}),message:i,author:a,committer:o,signingKey:s,amend:c,dryRun:l,noUpdateBranch:u,ref:d,parent:f,tree:p})}catch(e){throw e.caller=`git.commit`,e}}async function BX({fs:e,dir:t,gitdir:n=X(t,`.git`),fullname:r=!1,test:i=!1}){try{Z(`fs`,e),Z(`gitdir`,n);let t=new dY(e);return await iX({fs:t,gitdir:await pY({fsp:t,dotgit:n}),fullname:r,test:i})}catch(e){throw e.caller=`git.currentBranch`,e}}async function VX({fs:e,gitdir:t,ref:n}){if(n=n.startsWith(`refs/heads/`)?n:`refs/heads/${n}`,!await Aq.exists({fs:e,gitdir:t,ref:n}))throw new ZK(n);let r=await Aq.expand({fs:e,gitdir:t,ref:n});if(r===await iX({fs:e,gitdir:t,fullname:!0})){let n=await Aq.resolve({fs:e,gitdir:t,ref:r});await Aq.writeRef({fs:e,gitdir:t,ref:`HEAD`,value:n})}await Aq.deleteRef({fs:e,gitdir:t,ref:r});let i=rX(n),a=await Tq.get({fs:e,gitdir:t});await a.deleteSection(`branch`,i),await Tq.save({fs:e,gitdir:t,config:a})}async function HX({fs:e,dir:t,gitdir:n=X(t,`.git`),ref:r}){try{Z(`fs`,e),Z(`ref`,r);let t=new dY(e);return await VX({fs:t,gitdir:await pY({fsp:t,dotgit:n}),ref:r})}catch(e){throw e.caller=`git.deleteBranch`,e}}async function UX({fs:e,gitdir:t,remote:n}){let r=await Tq.get({fs:e,gitdir:t});await r.deleteSection(`remote`,n),await Tq.save({fs:e,gitdir:t,config:r})}async function WX({fs:e,dir:t,gitdir:n=X(t,`.git`),remote:r}){try{Z(`fs`,e),Z(`remote`,r);let t=new dY(e);return await UX({fs:t,gitdir:await pY({fsp:t,dotgit:n}),remote:r})}catch(e){throw e.caller=`git.deleteRemote`,e}}async function GX({fs:e,gitdir:t,ref:n}){n=n.startsWith(`refs/tags/`)?n:`refs/tags/${n}`,await Aq.deleteRef({fs:e,gitdir:t,ref:n})}async function KX({fs:e,dir:t,gitdir:n=X(t,`.git`),ref:r}){try{Z(`fs`,e),Z(`ref`,r);let t=new dY(e);return await GX({fs:t,gitdir:await pY({fsp:t,dotgit:n}),ref:r})}catch(e){throw e.caller=`git.deleteTag`,e}}async function qX({fs:e,gitdir:t,oid:n}){let r=n.slice(0,2);return(await e.readdir(`${t}/objects/${r}`)).map(e=>`${r}${e}`).filter(e=>e.startsWith(n))}async function JX({fs:e,cache:t,gitdir:n,oid:r,getExternalRefDelta:i}){let a=[],o=await e.readdir(X(n,`objects/pack`));o=o.filter(e=>e.endsWith(`.idx`));for(let s of o){let o=await aJ({fs:e,cache:t,filename:`${n}/objects/pack/${s}`,getExternalRefDelta:i});if(o.error)throw new yK(o.error);for(let e of o.offsets.keys())e.startsWith(r)&&a.push(e)}return a}async function YX({fs:e,cache:t,gitdir:n,oid:r}){let i=r=>cJ({fs:e,cache:t,gitdir:n,oid:r}),a=await qX({fs:e,gitdir:n,oid:r}),o=await JX({fs:e,cache:t,gitdir:n,oid:r,getExternalRefDelta:i});for(let e of o)a.indexOf(e)===-1&&a.push(e);if(a.length===1)return a[0];throw a.length>1?new uJ(`oids`,r,a):new ZK(`an object matching "${r}"`)}async function XX({fs:e,dir:t,gitdir:n=X(t,`.git`),oid:r,cache:i={}}){try{Z(`fs`,e),Z(`gitdir`,n),Z(`oid`,r);let t=new dY(e);return await YX({fs:t,cache:i,gitdir:await pY({fsp:t,dotgit:n}),oid:r})}catch(e){throw e.caller=`git.expandOid`,e}}async function ZX({fs:e,cache:t,gitdir:n,oids:r}){let i={},a=r.length,o=r.map((e,t)=>({index:t,oid:e}));for(;o.length;){let r=new Set;for(let{oid:e,index:t}of o)i[e]||(i[e]=new Set),i[e].add(t),i[e].size===a&&r.add(e);if(r.size>0)return[...r];let s=new Map;for(let{oid:r,index:a}of o)try{let{object:o}=await cJ({fs:e,cache:t,gitdir:n,oid:r}),{parent:c}=qJ.from(o).parseHeaders();for(let e of c)(!i[e]||!i[e].has(a))&&s.set(e+`:`+a,{oid:e,index:a})}catch{}o=Array.from(s.values())}return[]}async function QX({fs:e,cache:t,dir:n,gitdir:r,ours:i,theirs:a,fastForward:o=!0,fastForwardOnly:s=!1,dryRun:c=!1,noUpdateBranch:l=!1,abortOnConflict:u=!0,message:d,author:f,committer:p,signingKey:m,onSign:h,mergeDriver:g,allowUnrelatedHistories:_=!1}){i===void 0&&(i=await iX({fs:e,gitdir:r,fullname:!0})),i=await Aq.expand({fs:e,gitdir:r,ref:i}),a=await Aq.expand({fs:e,gitdir:r,ref:a});let v=await Aq.resolve({fs:e,gitdir:r,ref:i}),y=await Aq.resolve({fs:e,gitdir:r,ref:a}),b=await ZX({fs:e,cache:t,gitdir:r,oids:[v,y]});if(b.length!==1)if(b.length===0&&_)b.push(`4b825dc642cb6eb9a060e54bf8d69288fbee4904`);else throw new SJ;let x=b[0];if(x===y)return{oid:v,alreadyMerged:!0};if(o&&x===v)return!c&&!l&&await Aq.writeRef({fs:e,gitdir:r,ref:i,value:y}),{oid:y,fastForward:!0};{if(s)throw new gJ;let o=await UK.acquire({fs:e,gitdir:r,cache:t,allowUnmerged:!1},async o=>eX({fs:e,cache:t,dir:n,gitdir:r,index:o,ourOid:v,theirOid:y,baseOid:x,ourName:rX(i),baseName:`base`,theirName:rX(a),dryRun:c,abortOnConflict:u,mergeDriver:g}));if(o instanceof CJ)throw o;return d||=`Merge branch '${rX(a)}' into ${rX(i)}`,{oid:await jY({fs:e,cache:t,gitdir:r,message:d,ref:i,tree:o,parent:[v,y],author:f,committer:p,signingKey:m,onSign:h,dryRun:c,noUpdateBranch:l}),tree:o,mergeCommit:!0}}}async function $X({fs:e,cache:t,http:n,onProgress:r,onMessage:i,onAuth:a,onAuthSuccess:o,onAuthFailure:s,dir:c,gitdir:l,ref:u,url:d,remote:f,remoteRef:p,prune:m,pruneTags:h,fastForward:g,fastForwardOnly:_,corsProxy:v,singleBranch:y,headers:b,author:x,committer:S,signingKey:C}){try{if(!u){let t=await iX({fs:e,gitdir:l});if(!t)throw new TJ(`ref`);u=t}let{fetchHead:w,fetchHeadDescription:T}=await FX({fs:e,cache:t,http:n,onProgress:r,onMessage:i,onAuth:a,onAuthSuccess:o,onAuthFailure:s,gitdir:l,corsProxy:v,ref:u,url:d,remote:f,remoteRef:p,singleBranch:y,headers:b,prune:m,pruneTags:h});await QX({fs:e,cache:t,gitdir:l,ours:u,theirs:w,fastForward:g,fastForwardOnly:_,message:`Merge ${T}`,author:x,committer:S,signingKey:C,dryRun:!1,noUpdateBranch:!1}),await KY({fs:e,cache:t,onProgress:r,dir:c,gitdir:l,ref:u,remote:f,noCheckout:!1})}catch(e){throw e.caller=`git.pull`,e}}async function eZ({fs:e,http:t,onProgress:n,onMessage:r,onAuth:i,onAuthSuccess:a,onAuthFailure:o,dir:s,gitdir:c=X(s,`.git`),ref:l,remote:u,remoteRef:d,url:f,corsProxy:p,depth:m=null,since:h=null,exclude:g=[],relative:_=!1,tags:v=!1,singleBranch:y=!1,headers:b={},prune:x=!1,pruneTags:S=!1,cache:C={}}){try{Z(`fs`,e),Z(`http`,t),Z(`gitdir`,c);let s=new dY(e);return await FX({fs:s,cache:C,http:t,onProgress:n,onMessage:r,onAuth:i,onAuthSuccess:a,onAuthFailure:o,gitdir:await pY({fsp:s,dotgit:c}),ref:l,remote:u,remoteRef:d,url:f,corsProxy:p,depth:m,since:h,exclude:g,relative:_,tags:v,singleBranch:y,headers:b,prune:x,pruneTags:S})}catch(e){throw e.caller=`git.fetch`,e}}async function tZ({fs:e,filepath:t}){if(await e.exists(X(t,`.git`)))return t;{let n=GK(t);if(n===t)throw new ZK(`git root for ${t}`);return tZ({fs:e,filepath:n})}}async function nZ({fs:e,filepath:t}){try{return Z(`fs`,e),Z(`filepath`,t),await tZ({fs:new dY(e),filepath:t})}catch(e){throw e.caller=`git.findRoot`,e}}async function rZ({fs:e,dir:t,gitdir:n=X(t,`.git`),path:r}){try{Z(`fs`,e),Z(`gitdir`,n),Z(`path`,r);let t=new dY(e);return await TY({fs:t,gitdir:await pY({fsp:t,dotgit:n}),path:r})}catch(e){throw e.caller=`git.getConfig`,e}}async function iZ({fs:e,bare:t=!1,dir:n,gitdir:r=t?n:X(n,`.git`),defaultBranch:i=`master`}){try{Z(`fs`,e),Z(`gitdir`,r),t||Z(`dir`,n);let a=new dY(e);return await IX({fs:a,bare:t,dir:n,gitdir:await pY({fsp:a,dotgit:r}),defaultBranch:i})}catch(e){throw e.caller=`git.init`,e}}async function aZ({fs:e,cache:t,gitdir:n,oid:r,ancestor:i,depth:a}){let o=await SX.read({fs:e,gitdir:n});if(!r)throw new TJ(`oid`);if(!i)throw new TJ(`ancestor`);if(r===i)return!1;let s=[r],c=new Set,l=0;for(;s.length;){if(l++===a)throw new xJ(a);let r=s.shift(),{type:u,object:d}=await cJ({fs:e,cache:t,gitdir:n,oid:r});if(u!==`commit`)throw new QK(r,u,`commit`);let f=qJ.from(d).parse();for(let e of f.parent)if(e===i)return!0;if(!o.has(r))for(let e of f.parent)c.has(e)||(s.push(e),c.add(e))}return!1}async function oZ({fs:e,dir:t,gitdir:n=X(t,`.git`),remote:r}){try{Z(`fs`,e),Z(`gitdir`,n);let t=new dY(e),i=await pY({fsp:t,dotgit:n});return Aq.listBranches({fs:t,gitdir:i,remote:r})}catch(e){throw e.caller=`git.listBranches`,e}}async function sZ({fs:e,gitdir:t,ref:n,cache:r}){if(n){let i=await Aq.resolve({gitdir:t,fs:e,ref:n}),a=[];return await cZ({fs:e,cache:r,gitdir:t,oid:i,filenames:a,prefix:``}),a}else return UK.acquire({fs:e,gitdir:t,cache:r},async function(e){return e.entries.map(e=>e.path)})}async function cZ({fs:e,cache:t,gitdir:n,oid:r,filenames:i,prefix:a}){let{tree:o}=await FY({fs:e,cache:t,gitdir:n,oid:r});for(let r of o)r.type===`tree`?await cZ({fs:e,cache:t,gitdir:n,oid:r.oid,filenames:i,prefix:X(a,r.path)}):i.push(X(a,r.path))}async function lZ({fs:e,dir:t,gitdir:n=X(t,`.git`),ref:r,cache:i={}}){try{Z(`fs`,e),Z(`gitdir`,n);let t=new dY(e);return await sZ({fs:t,cache:i,gitdir:await pY({fsp:t,dotgit:n}),ref:r})}catch(e){throw e.caller=`git.listFiles`,e}}async function uZ({fs:e,gitdir:t}){let n=await Tq.get({fs:e,gitdir:t}),r=await n.getSubsections(`remote`);return Promise.all(r.map(async e=>({remote:e,url:await n.get(`remote.${e}.url`)})))}async function dZ({fs:e,dir:t,gitdir:n=X(t,`.git`)}){try{Z(`fs`,e),Z(`gitdir`,n);let t=new dY(e);return await uZ({fs:t,gitdir:await pY({fsp:t,dotgit:n})})}catch(e){throw e.caller=`git.listRemotes`,e}}async function fZ({fs:e,dir:t,gitdir:n=X(t,`.git`)}){try{Z(`fs`,e),Z(`gitdir`,n);let t=new dY(e),r=await pY({fsp:t,dotgit:n});return Aq.listTags({fs:t,gitdir:r})}catch(e){throw e.caller=`git.listTags`,e}}function pZ(e,t){return e.committer.timestamp-t.committer.timestamp}var mZ=`e69de29bb2d1d6434b8b29ae775ad8c2e48c5391`;async function hZ({fs:e,cache:t,gitdir:n,oid:r,fileId:i}){if(i===mZ)return;let a=r,o,s=await JJ({fs:e,cache:t,gitdir:n,oid:r}),c=s.tree;return i===s.oid?o=s.path:(o=await gZ({fs:e,cache:t,gitdir:n,tree:c,fileId:i,oid:a}),Array.isArray(o)&&(o.length===0?o=void 0:o.length===1&&(o=o[0]))),o}async function gZ({fs:e,cache:t,gitdir:n,tree:r,fileId:i,oid:a,filepaths:o=[],parentPath:s=``}){let c=r.entries().map(function(r){let c;return r.oid===i?(c=X(s,r.path),o.push(c)):r.type===`tree`&&(c=cJ({fs:e,cache:t,gitdir:n,oid:r.oid}).then(function({object:c}){return gZ({fs:e,cache:t,gitdir:n,tree:Lq.from(c),fileId:i,oid:a,filepaths:o,parentPath:X(s,r.path)})})),c});return await Promise.all(c),o}async function _Z({fs:e,cache:t,gitdir:n,filepath:r,ref:i,depth:a,since:o,force:s,follow:c}){let l=o===void 0?void 0:Math.floor(o.valueOf()/1e3),u=[],d=await SX.read({fs:e,gitdir:n}),f=[await AY({fs:e,cache:t,gitdir:n,oid:await Aq.resolve({fs:e,gitdir:n,ref:i})})],p,m,h;function g(e){h&&r&&u.push(e)}for(;f.length>0;){let i=f.pop();if(l!==void 0&&i.commit.committer.timestamp<=l)break;if(r){let a;try{a=await NY({fs:e,cache:t,gitdir:n,oid:i.commit.tree,filepath:r}),m&&p!==a&&u.push(m),p=a,m=i,h=!0}catch(a){if(a instanceof ZK){let o=c&&p;if(o&&(o=await hZ({fs:e,cache:t,gitdir:n,oid:i.commit.tree,fileId:p}),o))if(Array.isArray(o)){if(m){let i=await hZ({fs:e,cache:t,gitdir:n,oid:m.commit.tree,fileId:p});if(Array.isArray(i))if(o=o.filter(e=>i.indexOf(e)===-1),o.length===1)o=o[0],r=o,m&&u.push(m);else{o=!1,m&&u.push(m);break}}}else r=o,m&&u.push(m);if(!o){if(h&&p&&(u.push(m),!s))break;if(!s&&!c)throw a}m=i,h=!1}else throw a}}else u.push(i);if(a!==void 0&&u.length===a){g(i);break}if(!d.has(i.oid))for(let r of i.commit.parent){let i=await AY({fs:e,cache:t,gitdir:n,oid:r});f.map(e=>e.oid).includes(i.oid)||f.push(i)}f.length===0&&g(i),f.sort((e,t)=>pZ(e.commit,t.commit))}return u}async function vZ({fs:e,dir:t,gitdir:n=X(t,`.git`),filepath:r,ref:i=`HEAD`,depth:a,since:o,force:s,follow:c,cache:l={}}){try{Z(`fs`,e),Z(`gitdir`,n),Z(`ref`,i);let t=new dY(e);return await _Z({fs:t,cache:l,gitdir:await pY({fsp:t,dotgit:n}),filepath:r,ref:i,depth:a,since:o,force:s,follow:c})}catch(e){throw e.caller=`git.log`,e}}async function yZ({fs:e,onSign:t,dir:n,gitdir:r=X(n,`.git`),ours:i,theirs:a,fastForward:o=!0,fastForwardOnly:s=!1,dryRun:c=!1,noUpdateBranch:l=!1,abortOnConflict:u=!0,message:d,author:f,committer:p,signingKey:m,cache:h={},mergeDriver:g,allowUnrelatedHistories:_=!1}){try{Z(`fs`,e),m&&Z(`onSign`,t);let v=new dY(e),y=await pY({fsp:v,dotgit:r}),b=await DY({fs:v,gitdir:y,author:f});if(!b&&(!s||!o))throw new wJ(`author`);let x=await OY({fs:v,gitdir:y,author:b,committer:p});if(!x&&(!s||!o))throw new wJ(`committer`);return await QX({fs:v,cache:h,dir:n,gitdir:y,ours:i,theirs:a,fastForward:o,fastForwardOnly:s,dryRun:c,noUpdateBranch:l,abortOnConflict:u,message:d,author:b,committer:x,signingKey:m,onSign:t,mergeDriver:g,allowUnrelatedHistories:_})}catch(e){throw e.caller=`git.merge`,e}}var bZ={commit:16,tree:32,blob:48,tag:64,ofs_delta:96,ref_delta:112};async function xZ({fs:e,cache:t,dir:n,gitdir:r=X(n,`.git`),oids:i}){let a=new uK.default,o=[];function s(e,t){let n=Buffer.from(e,t);o.push(n),a.update(n)}async function c({stype:e,object:t}){let n=bZ[e],r=t.length,i=r>15?128:0,a=r&15;r>>>=4;let o=(i|n|a).toString(16);for(s(o,`hex`);i;)i=r>127?128:0,o=i|r&127,s(uX(2,o),`hex`),r>>>=7;s(Buffer.from(await vY(t)))}s(`PACK`),s(`00000002`,`hex`),s(uX(8,i.length),`hex`);for(let n of i){let{type:i,object:a}=await cJ({fs:e,cache:t,gitdir:r,oid:n});await c({write:s,object:a,stype:i})}let l=a.digest();return o.push(l),o}async function SZ({fs:e,http:t,onProgress:n,onMessage:r,onAuth:i,onAuthSuccess:a,onAuthFailure:o,dir:s,gitdir:c=X(s,`.git`),ref:l,url:u,remote:d,remoteRef:f,prune:p=!1,pruneTags:m=!1,fastForward:h=!0,fastForwardOnly:g=!1,corsProxy:_,singleBranch:v,headers:y={},author:b,committer:x,signingKey:S,cache:C={}}){try{Z(`fs`,e),Z(`gitdir`,c);let w=new dY(e),T=await pY({fsp:w,dotgit:c}),E=await DY({fs:w,gitdir:T,author:b});if(!E)throw new wJ(`author`);let D=await OY({fs:w,gitdir:T,author:E,committer:x});if(!D)throw new wJ(`committer`);return await $X({fs:w,cache:C,http:t,onProgress:n,onMessage:r,onAuth:i,onAuthSuccess:a,onAuthFailure:o,dir:s,gitdir:T,ref:l,url:u,remote:d,remoteRef:f,fastForward:h,fastForwardOnly:g,corsProxy:_,singleBranch:v,headers:y,author:E,committer:D,signingKey:S,prune:p,pruneTags:m})}catch(e){throw e.caller=`git.pull`,e}}async function CZ({fs:e,cache:t,dir:n,gitdir:r=X(n,`.git`),start:i,finish:a}){let o=await SX.read({fs:e,gitdir:r}),s=new Set,c=new Set;for(let t of i)s.add(await Aq.resolve({fs:e,gitdir:r,ref:t}));for(let t of a)try{let n=await Aq.resolve({fs:e,gitdir:r,ref:t});c.add(n)}catch{}let l=new Set;async function u(n){l.add(n);let{type:i,object:a}=await cJ({fs:e,cache:t,gitdir:r,oid:n});if(i===`tag`){let e=WJ.from(a).headers().object;return u(e)}if(i!==`commit`)throw new QK(n,i,`commit`);if(!o.has(n))for(n of qJ.from(a).headers().parent)!c.has(n)&&!l.has(n)&&await u(n)}for(let e of s)await u(e);return l}async function wZ({fs:e,cache:t,dir:n,gitdir:r=X(n,`.git`),oids:i}){let a=new Set;async function o(n){if(a.has(n))return;a.add(n);let{type:i,object:s}=await cJ({fs:e,cache:t,gitdir:r,oid:n});if(i===`tag`){let e=WJ.from(s).headers().object;await o(e)}else if(i===`commit`){let e=qJ.from(s).headers().tree;await o(e)}else if(i===`tree`){let e=Lq.from(s);for(let t of e)t.type===`blob`&&a.add(t.oid),t.type===`tree`&&await o(t.oid)}}for(let e of i)await o(e);return a}async function TZ(e){let t={},n=``,r=dX.streamReader(e),i=await r();for(;i!==!0;)i!==null&&(n+=i.toString(`utf8`)+`
3279
3279
  `),i=await r();let a=n.toString(`utf8`).split(`
3280
- `);if(i=a.shift(),!i.startsWith(`unpack `))throw new DJ(`unpack ok" or "unpack [error message]`,i);t.ok=i===`unpack ok`,t.ok||(t.error=i.slice(7)),t.refs={};for(let e of a){if(e.trim()===``)continue;let n=e.slice(0,2),r=e.slice(3),i=r.indexOf(` `);i===-1&&(i=r.length);let a=r.slice(0,i),o=r.slice(i+1);t.refs[a]={ok:n===`ok`,error:o}}return t}async function EZ({capabilities:e=[],triplets:t=[]}){let n=[],r=`\x00 ${e.join(` `)}`;for(let e of t)n.push(dX.encode(`${e.oldoid} ${e.oid} ${e.fullRef}${r}\n`)),r=``;return n.push(dX.flush()),n}async function DZ({fs:e,cache:t,http:n,onProgress:r,onMessage:i,onAuth:a,onAuthSuccess:o,onAuthFailure:s,onPrePush:c,gitdir:l,ref:u,remoteRef:d,remote:f,url:p,force:m=!1,delete:h=!1,corsProxy:g,headers:_={}}){let v=u||await iX({fs:e,gitdir:l});if(v===void 0)throw new TJ(`ref`);let y=await Tq.get({fs:e,gitdir:l});f=f||await y.get(`branch.${v}.pushRemote`)||await y.get(`remote.pushDefault`)||await y.get(`branch.${v}.remote`)||`origin`;let b=p||await y.get(`remote.${f}.pushurl`)||await y.get(`remote.${f}.url`);if(b===void 0)throw new TJ(`remote OR url`);let x=d||await y.get(`branch.${v}.merge`);if(b===void 0)throw new TJ(`remoteRef`);g===void 0&&(g=await y.get(`http.corsProxy`));let S=await Aq.expand({fs:e,gitdir:l,ref:v}),C=h?`0000000000000000000000000000000000000000`:await Aq.resolve({fs:e,gitdir:l,ref:S}),w=yX.getRemoteHelperFor({url:b}),T=await w.discover({http:n,onAuth:a,onAuthSuccess:o,onAuthFailure:s,corsProxy:g,service:`git-receive-pack`,url:b,headers:_,protocolVersion:1}),E=T.auth,D;if(!x)D=S;else try{D=await Aq.expandAgainstMap({ref:x,map:T.refs})}catch(e){if(e instanceof ZK)D=x.startsWith(`refs/`)?x:`refs/heads/${x}`;else throw e}let O=T.refs.get(D)||`0000000000000000000000000000000000000000`;if(c&&!await c({remote:f,url:b,localRef:{ref:h?`(delete)`:S,oid:C},remoteRef:{ref:D,oid:O}}))throw new NJ;let ee=!T.capabilities.has(`no-thin`),te=new Set;if(!h){let n=[...T.refs.values()],r=new Set;if(O!==`0000000000000000000000000000000000000000`){let i=await ZX({fs:e,cache:t,gitdir:l,oids:[C,O]});for(let e of i)n.push(e);ee&&(r=await wZ({fs:e,cache:t,gitdir:l,oids:i}))}if(n.includes(C)||(te=await wZ({fs:e,cache:t,gitdir:l,oids:await CZ({fs:e,cache:t,gitdir:l,start:[C],finish:n})})),ee){try{let n=await Aq.resolve({fs:e,gitdir:l,ref:`refs/remotes/${f}/HEAD`,depth:2}),{oid:i}=await Aq.resolveAgainstMap({ref:n.replace(`refs/remotes/${f}/`,``),fullref:n,map:T.refs}),a=[i];for(let n of await wZ({fs:e,cache:t,gitdir:l,oids:a}))r.add(n)}catch{}for(let e of r)te.delete(e)}if(C===O&&(m=!0),!m){if(S.startsWith(`refs/tags`)&&O!==`0000000000000000000000000000000000000000`)throw new OJ(`tag-exists`);if(C!==`0000000000000000000000000000000000000000`&&O!==`0000000000000000000000000000000000000000`&&!await aZ({fs:e,cache:t,gitdir:l,oid:C,ancestor:O,depth:-1}))throw new OJ(`not-fast-forward`)}}let ne=await EZ({capabilities:DX([...T.capabilities],[`report-status`,`side-band-64k`,`agent=${OX.agent}`]),triplets:[{oldoid:O,oid:C,fullRef:D}]}),k=h?[]:await xZ({fs:e,cache:t,gitdir:l,oids:[...te]}),re=await w.connect({http:n,onProgress:r,corsProxy:g,service:`git-receive-pack`,url:b,auth:E,headers:_,body:[...ne,...k]}),{packfile:ie,progress:ae}=await MX.demux(re.body);i&&sX(jX(ae),async e=>{await i(e)});let oe=await TZ(ie);if(re.headers&&(oe.headers=re.headers),f&&oe.ok&&oe.refs[D].ok&&!S.startsWith(`refs/tags`)){let t=`refs/remotes/${f}/${D.replace(`refs/heads`,``)}`;h?await Aq.deleteRef({fs:e,gitdir:l,ref:t}):await Aq.writeRef({fs:e,gitdir:l,ref:t,value:C})}if(oe.ok&&Object.values(oe.refs).every(e=>e.ok))return oe;throw new _J(Object.entries(oe.refs).filter(([e,t])=>!t.ok).map(([e,t])=>`\n - ${e}: ${t.error}`).join(``),oe)}async function OZ({fs:e,http:t,onProgress:n,onMessage:r,onAuth:i,onAuthSuccess:a,onAuthFailure:o,onPrePush:s,dir:c,gitdir:l=X(c,`.git`),ref:u,remoteRef:d,remote:f=`origin`,url:p,force:m=!1,delete:h=!1,corsProxy:g,headers:_={},cache:v={}}){try{Z(`fs`,e),Z(`http`,t),Z(`gitdir`,l);let c=new dY(e);return await DZ({fs:c,cache:v,http:t,onProgress:n,onMessage:r,onAuth:i,onAuthSuccess:a,onAuthFailure:o,onPrePush:s,gitdir:await pY({fsp:c,dotgit:l}),ref:u,remoteRef:d,remote:f,url:p,force:m,delete:h,corsProxy:g,headers:_})}catch(e){throw e.caller=`git.push`,e}}async function kZ({fs:e,cache:t,gitdir:n,oid:r}){let{type:i,object:a}=await cJ({fs:e,cache:t,gitdir:n,oid:r});if(i===`tag`)return r=WJ.from(a).parse().object,kZ({fs:e,cache:t,gitdir:n,oid:r});if(i!==`blob`)throw new QK(r,i,`blob`);return{oid:r,blob:new Uint8Array(a)}}async function AZ({fs:e,cache:t,gitdir:n,oid:r,filepath:i=void 0}){return i!==void 0&&(r=await NY({fs:e,cache:t,gitdir:n,oid:r,filepath:i})),await kZ({fs:e,cache:t,gitdir:n,oid:r})}async function jZ({fs:e,dir:t,gitdir:n=X(t,`.git`),oid:r,filepath:i,cache:a={}}){try{Z(`fs`,e),Z(`gitdir`,n),Z(`oid`,r);let t=new dY(e);return await AZ({fs:t,cache:a,gitdir:await pY({fsp:t,dotgit:n}),oid:r,filepath:i})}catch(e){throw e.caller=`git.readBlob`,e}}async function MZ({fs:e,dir:t,gitdir:n=X(t,`.git`),oid:r,cache:i={}}){try{Z(`fs`,e),Z(`gitdir`,n),Z(`oid`,r);let t=new dY(e);return await AY({fs:t,cache:i,gitdir:await pY({fsp:t,dotgit:n}),oid:r})}catch(e){throw e.caller=`git.readCommit`,e}}async function NZ({fs:e,dir:t,gitdir:n=X(t,`.git`),oid:r,filepath:i=void 0,cache:a={}}){try{Z(`fs`,e),Z(`gitdir`,n),Z(`oid`,r);let t=new dY(e);return await FY({fs:t,cache:a,gitdir:await pY({fsp:t,dotgit:n}),oid:r,filepath:i})}catch(e){throw e.caller=`git.readTree`,e}}async function PZ({fs:e,dir:t,gitdir:n=X(t,`.git`),filepath:r,cache:i={}}){try{Z(`fs`,e),Z(`gitdir`,n),Z(`filepath`,r);let t=new dY(e),a=await pY({fsp:t,dotgit:n});await UK.acquire({fs:t,gitdir:a,cache:i},async function(e){e.delete({filepath:r})})}catch(e){throw e.caller=`git.remove`,e}}async function FZ({gitdir:e,type:t,object:n}){return AK(Rq.wrap({type:t,object:n}))}async function IZ({fs:e,dir:t,gitdir:n=X(t,`.git`),filepath:r,ref:i,cache:a={}}){try{Z(`fs`,e),Z(`gitdir`,n),Z(`filepath`,r);let o=new dY(e),s=await pY({fsp:o,dotgit:n}),c,l;try{c=await Aq.resolve({fs:o,gitdir:s,ref:i||`HEAD`})}catch(e){if(i)throw e}if(c)try{c=await NY({fs:o,cache:a,gitdir:s,oid:c,filepath:r})}catch{c=null}let u={ctime:new Date(0),mtime:new Date(0),dev:0,ino:0,mode:0,uid:0,gid:0,size:0},d=t&&await o.read(X(t,r));d&&(l=await FZ({gitdir:s,type:`blob`,object:d}),c===l&&(u=await o.lstat(X(t,r)))),await UK.acquire({fs:o,gitdir:s,cache:a},async function(e){e.delete({filepath:r}),c&&e.insert({filepath:r,stats:u,oid:c})})}catch(e){throw e.caller=`git.reset`,e}}async function LZ({fs:e,dir:t,gitdir:n=X(t,`.git`),ref:r,depth:i}){try{Z(`fs`,e),Z(`gitdir`,n),Z(`ref`,r);let t=new dY(e),a=await pY({fsp:t,dotgit:n});return await Aq.resolve({fs:t,gitdir:a,ref:r,depth:i})}catch(e){throw e.caller=`git.resolveRef`,e}}async function RZ({fs:e,dir:t,gitdir:n=X(t,`.git`),path:r,value:i,append:a=!1}){try{Z(`fs`,e),Z(`gitdir`,n),Z(`path`,r);let t=new dY(e),o=await pY({fsp:t,dotgit:n}),s=await Tq.get({fs:t,gitdir:o});a?await s.append(r,i):await s.set(r,i),await Tq.save({fs:t,gitdir:o,config:s})}catch(e){throw e.caller=`git.setConfig`,e}}async function zZ({fs:e,gitdir:t,commit:n}){return await xY({fs:e,gitdir:t,type:`commit`,object:qJ.from(n).toObject(),format:`content`})}async function BZ({fs:e,dir:t,gitdir:n=X(t,`.git`),ref:r=`HEAD`,filepaths:i=[`.`],filter:a,cache:o={},ignored:s=!1}){try{Z(`fs`,e),Z(`gitdir`,n),Z(`ref`,r);let c=new dY(e);return await rY({fs:c,cache:o,dir:t,gitdir:await pY({fsp:c,dotgit:n}),trees:[XJ({ref:r}),QJ(),XK()],map:async function(e,[n,r,o]){if(!n&&!o&&r&&!s&&await hY.isIgnored({fs:c,dir:t,filepath:e})||!i.some(t=>GY(e,t)))return null;if(a&&!a(e))return;let[l,u,d]=await Promise.all([n&&n.type(),r&&r.type(),o&&o.type()]),f=[l,u,d].includes(`blob`);if((l===`tree`||l===`special`)&&!f)return;if(l===`commit`)return null;if((u===`tree`||u===`special`)&&!f)return;if(d===`commit`)return null;if((d===`tree`||d===`special`)&&!f)return;let p=l===`blob`?await n.oid():void 0,m=d===`blob`?await o.oid():void 0,h;l!==`blob`&&u===`blob`&&d!==`blob`?h=`42`:u===`blob`&&(h=await r.oid());let g=[void 0,p,h,m],_=g.map(e=>g.indexOf(e));return _.shift(),[e,..._]}})}catch(e){throw e.caller=`git.statusMatrix`,e}}async function VZ({fs:e,dir:t,gitdir:n=X(t,`.git`),ref:r,object:i,force:a=!1}){try{Z(`fs`,e),Z(`gitdir`,n),Z(`ref`,r);let t=new dY(e);if(r===void 0)throw new TJ(`ref`);r=r.startsWith(`refs/tags/`)?r:`refs/tags/${r}`;let o=await pY({fsp:t,dotgit:n}),s=await Aq.resolve({fs:t,gitdir:o,ref:i||`HEAD`});if(!a&&await Aq.exists({fs:t,gitdir:o,ref:r}))throw new lJ(`tag`,r);await Aq.writeRef({fs:t,gitdir:o,ref:r,value:s})}catch(e){throw e.caller=`git.tag`,e}}function HZ(){try{return OX.version}catch(e){throw e.caller=`git.version`,e}}async function UZ({fs:e,dir:t,gitdir:n=X(t,`.git`),trees:r,map:i,reduce:a,iterate:o,cache:s={}}){try{Z(`fs`,e),Z(`gitdir`,n),Z(`trees`,r);let c=new dY(e);return await rY({fs:c,cache:s,dir:t,gitdir:await pY({fsp:c,dotgit:n}),trees:r,map:i,reduce:a,iterate:o})}catch(e){throw e.caller=`git.walk`,e}}async function WZ({fs:e,dir:t,gitdir:n=X(t,`.git`),blob:r}){try{Z(`fs`,e),Z(`gitdir`,n),Z(`blob`,r);let t=new dY(e);return await xY({fs:t,gitdir:await pY({fsp:t,dotgit:n}),type:`blob`,object:r,format:`content`})}catch(e){throw e.caller=`git.writeBlob`,e}}async function GZ({fs:e,dir:t,gitdir:n=X(t,`.git`),commit:r}){try{Z(`fs`,e),Z(`gitdir`,n),Z(`commit`,r);let t=new dY(e);return await zZ({fs:t,gitdir:await pY({fsp:t,dotgit:n}),commit:r})}catch(e){throw e.caller=`git.writeCommit`,e}}async function KZ({fs:e,dir:t,gitdir:n=X(t,`.git`),ref:r,value:i,force:a=!1,symbolic:o=!1}){try{Z(`fs`,e),Z(`gitdir`,n),Z(`ref`,r),Z(`value`,i);let t=new dY(e);if(!RY(r,!0))throw new bJ(r,hK.default.clean(r));let s=await pY({fsp:t,dotgit:n});if(!a&&await Aq.exists({fs:t,gitdir:s,ref:r}))throw new lJ(`ref`,r);o?await Aq.writeSymbolicRef({fs:t,gitdir:s,ref:r,value:i}):(i=await Aq.resolve({fs:t,gitdir:s,ref:i}),await Aq.writeRef({fs:t,gitdir:s,ref:r,value:i}))}catch(e){throw e.caller=`git.writeRef`,e}}async function qZ({fs:e,dir:t,gitdir:n=X(t,`.git`),tree:r}){try{Z(`fs`,e),Z(`gitdir`,n),Z(`tree`,r);let t=new dY(e);return await IY({fs:t,gitdir:await pY({fsp:t,dotgit:n}),tree:r})}catch(e){throw e.caller=`git.writeTree`,e}}function JZ(){return typeof chrome<`u`&&!!chrome?.runtime?.id}function YZ(){return{request:async e=>{let{url:t,method:n=`GET`,headers:r={},body:i,onProgress:a}=e,o;if(i){let e=[];for await(let t of i)e.push(t);let t=e.reduce((e,t)=>e+t.length,0);o=new Uint8Array(t);let n=0;for(let t of e)o.set(t,n),n+=t.length}let s,c=r[`content-type`]??`application/octet-stream`,l=o?new Blob([o.buffer],{type:c}):void 0;if(JZ())s=await fetch(t,{method:n,headers:r,body:l});else{let e={...r,"X-Target-URL":t};if(r[`content-type`]&&(e[`Content-Type`]=r[`content-type`]),s=await fetch(`/api/fetch-proxy`,{method:n,headers:e,body:l}),s.status===502||s.status===400){let e=await s.text(),t=`Proxy error ${s.status}`;try{t=JSON.parse(e).error??t}catch{}throw Error(t)}}let u={};s.headers.forEach((e,t)=>{u[t]=e});let d=s.body,f;if(d){let e=d.getReader(),t=0;f={[Symbol.asyncIterator](){return this},async next(){let{done:n,value:r}=await e.read();return n?{done:!0,value:void 0}:(t+=r.length,a&&a({phase:`Receiving`,loaded:t,total:parseInt(u[`content-length`]??`0`,10)||t}),{done:!1,value:r})}}}return{url:s.url||t,method:n,headers:u,body:f,statusCode:s.status,statusMessage:s.statusText}}}}var XZ=YZ();function ZZ(e,t){let n=e.length,r=t.length;if(n===0&&r===0)return[];if(n===0)return t.map(e=>({type:`insert`,line:e}));if(r===0)return e.map(e=>({type:`delete`,line:e}));let i=n+r,a=i,o=2*i+1,s=[],c=Array(o).fill(0),l=-1;outer:for(let o=0;o<=i;o++){s.push(c.slice());for(let i=-o;i<=o;i+=2){let s;s=i===-o||i!==o&&c[i-1+a]<c[i+1+a]?c[i+1+a]:c[i-1+a]+1;let u=s-i;for(;s<n&&u<r&&e[s]===t[u];)s++,u++;if(c[i+a]=s,s>=n&&u>=r){l=o;break outer}}}l===-1&&(l=i);let u=[],d=n,f=r;for(let n=l;n>0;n--){let r=s[n],i=d-f,o;o=i===-n||i!==n&&r[i-1+a]<r[i+1+a]?i+1:i-1;let c=r[o+a],l=c-o;for(;d>c&&f>l;)d--,f--,u.push({type:`equal`,line:e[d]});d===c&&f>l?(f--,u.push({type:`insert`,line:t[f]})):f===l&&d>c&&(d--,u.push({type:`delete`,line:e[d]}))}for(;d>0&&f>0;)d--,f--,u.push({type:`equal`,line:e[d]});return u.reverse(),u}function QZ(e,t=3){let n=[],r=[];for(let t=0;t<e.length;t++)e[t].type!==`equal`&&r.push(t);if(r.length===0)return[];let i=0,a=[];for(let e=1;e<r.length;e++)r[e]-r[e-1]>2*t&&(a.push([i,e-1]),i=e);a.push([i,r.length-1]);for(let[i,o]of a){let a=r[i],s=r[o],c=Math.max(0,a-t),l=Math.min(e.length-1,s+t),u=[],d=0,f=0;for(let t=0;t<c;t++)(e[t].type===`equal`||e[t].type===`delete`)&&d++,(e[t].type===`equal`||e[t].type===`insert`)&&f++;let p=d+1,m=f+1,h=0,g=0;for(let t=c;t<=l;t++){let n=e[t];switch(n.type){case`equal`:u.push(` ${n.line}`),h++,g++;break;case`delete`:u.push(`-${n.line}`),h++;break;case`insert`:u.push(`+${n.line}`),g++;break}}n.push({oldStart:p,oldCount:h,newStart:m,newCount:g,lines:u})}return n}function $Z(e){let{oldContent:t,newContent:n,oldName:r,newName:i,color:a=!0}=e;if(t===n)return``;let o=t.split(`
3280
+ `);if(i=a.shift(),!i.startsWith(`unpack `))throw new DJ(`unpack ok" or "unpack [error message]`,i);t.ok=i===`unpack ok`,t.ok||(t.error=i.slice(7)),t.refs={};for(let e of a){if(e.trim()===``)continue;let n=e.slice(0,2),r=e.slice(3),i=r.indexOf(` `);i===-1&&(i=r.length);let a=r.slice(0,i),o=r.slice(i+1);t.refs[a]={ok:n===`ok`,error:o}}return t}async function EZ({capabilities:e=[],triplets:t=[]}){let n=[],r=`\x00 ${e.join(` `)}`;for(let e of t)n.push(dX.encode(`${e.oldoid} ${e.oid} ${e.fullRef}${r}\n`)),r=``;return n.push(dX.flush()),n}async function DZ({fs:e,cache:t,http:n,onProgress:r,onMessage:i,onAuth:a,onAuthSuccess:o,onAuthFailure:s,onPrePush:c,gitdir:l,ref:u,remoteRef:d,remote:f,url:p,force:m=!1,delete:h=!1,corsProxy:g,headers:_={}}){let v=u||await iX({fs:e,gitdir:l});if(v===void 0)throw new TJ(`ref`);let y=await Tq.get({fs:e,gitdir:l});f=f||await y.get(`branch.${v}.pushRemote`)||await y.get(`remote.pushDefault`)||await y.get(`branch.${v}.remote`)||`origin`;let b=p||await y.get(`remote.${f}.pushurl`)||await y.get(`remote.${f}.url`);if(b===void 0)throw new TJ(`remote OR url`);let x=d||await y.get(`branch.${v}.merge`);if(b===void 0)throw new TJ(`remoteRef`);g===void 0&&(g=await y.get(`http.corsProxy`));let S=await Aq.expand({fs:e,gitdir:l,ref:v}),C=h?`0000000000000000000000000000000000000000`:await Aq.resolve({fs:e,gitdir:l,ref:S}),w=yX.getRemoteHelperFor({url:b}),T=await w.discover({http:n,onAuth:a,onAuthSuccess:o,onAuthFailure:s,corsProxy:g,service:`git-receive-pack`,url:b,headers:_,protocolVersion:1}),E=T.auth,D;if(!x)D=S;else try{D=await Aq.expandAgainstMap({ref:x,map:T.refs})}catch(e){if(e instanceof ZK)D=x.startsWith(`refs/`)?x:`refs/heads/${x}`;else throw e}let O=T.refs.get(D)||`0000000000000000000000000000000000000000`;if(c&&!await c({remote:f,url:b,localRef:{ref:h?`(delete)`:S,oid:C},remoteRef:{ref:D,oid:O}}))throw new NJ;let ee=!T.capabilities.has(`no-thin`),te=new Set;if(!h){let n=[...T.refs.values()],r=new Set;if(O!==`0000000000000000000000000000000000000000`){let i=await ZX({fs:e,cache:t,gitdir:l,oids:[C,O]});for(let e of i)n.push(e);ee&&(r=await wZ({fs:e,cache:t,gitdir:l,oids:i}))}if(n.includes(C)||(te=await wZ({fs:e,cache:t,gitdir:l,oids:await CZ({fs:e,cache:t,gitdir:l,start:[C],finish:n})})),ee){try{let n=await Aq.resolve({fs:e,gitdir:l,ref:`refs/remotes/${f}/HEAD`,depth:2}),{oid:i}=await Aq.resolveAgainstMap({ref:n.replace(`refs/remotes/${f}/`,``),fullref:n,map:T.refs}),a=[i];for(let n of await wZ({fs:e,cache:t,gitdir:l,oids:a}))r.add(n)}catch{}for(let e of r)te.delete(e)}if(C===O&&(m=!0),!m){if(S.startsWith(`refs/tags`)&&O!==`0000000000000000000000000000000000000000`)throw new OJ(`tag-exists`);if(C!==`0000000000000000000000000000000000000000`&&O!==`0000000000000000000000000000000000000000`&&!await aZ({fs:e,cache:t,gitdir:l,oid:C,ancestor:O,depth:-1}))throw new OJ(`not-fast-forward`)}}let ne=await EZ({capabilities:DX([...T.capabilities],[`report-status`,`side-band-64k`,`agent=${OX.agent}`]),triplets:[{oldoid:O,oid:C,fullRef:D}]}),k=h?[]:await xZ({fs:e,cache:t,gitdir:l,oids:[...te]}),re=await w.connect({http:n,onProgress:r,corsProxy:g,service:`git-receive-pack`,url:b,auth:E,headers:_,body:[...ne,...k]}),{packfile:ie,progress:ae}=await MX.demux(re.body);i&&sX(jX(ae),async e=>{await i(e)});let oe=await TZ(ie);if(re.headers&&(oe.headers=re.headers),f&&oe.ok&&oe.refs[D].ok&&!S.startsWith(`refs/tags`)){let t=`refs/remotes/${f}/${D.replace(`refs/heads`,``)}`;h?await Aq.deleteRef({fs:e,gitdir:l,ref:t}):await Aq.writeRef({fs:e,gitdir:l,ref:t,value:C})}if(oe.ok&&Object.values(oe.refs).every(e=>e.ok))return oe;throw new _J(Object.entries(oe.refs).filter(([e,t])=>!t.ok).map(([e,t])=>`\n - ${e}: ${t.error}`).join(``),oe)}async function OZ({fs:e,http:t,onProgress:n,onMessage:r,onAuth:i,onAuthSuccess:a,onAuthFailure:o,onPrePush:s,dir:c,gitdir:l=X(c,`.git`),ref:u,remoteRef:d,remote:f=`origin`,url:p,force:m=!1,delete:h=!1,corsProxy:g,headers:_={},cache:v={}}){try{Z(`fs`,e),Z(`http`,t),Z(`gitdir`,l);let c=new dY(e);return await DZ({fs:c,cache:v,http:t,onProgress:n,onMessage:r,onAuth:i,onAuthSuccess:a,onAuthFailure:o,onPrePush:s,gitdir:await pY({fsp:c,dotgit:l}),ref:u,remoteRef:d,remote:f,url:p,force:m,delete:h,corsProxy:g,headers:_})}catch(e){throw e.caller=`git.push`,e}}async function kZ({fs:e,cache:t,gitdir:n,oid:r}){let{type:i,object:a}=await cJ({fs:e,cache:t,gitdir:n,oid:r});if(i===`tag`)return r=WJ.from(a).parse().object,kZ({fs:e,cache:t,gitdir:n,oid:r});if(i!==`blob`)throw new QK(r,i,`blob`);return{oid:r,blob:new Uint8Array(a)}}async function AZ({fs:e,cache:t,gitdir:n,oid:r,filepath:i=void 0}){return i!==void 0&&(r=await NY({fs:e,cache:t,gitdir:n,oid:r,filepath:i})),await kZ({fs:e,cache:t,gitdir:n,oid:r})}async function jZ({fs:e,dir:t,gitdir:n=X(t,`.git`),oid:r,filepath:i,cache:a={}}){try{Z(`fs`,e),Z(`gitdir`,n),Z(`oid`,r);let t=new dY(e);return await AZ({fs:t,cache:a,gitdir:await pY({fsp:t,dotgit:n}),oid:r,filepath:i})}catch(e){throw e.caller=`git.readBlob`,e}}async function MZ({fs:e,dir:t,gitdir:n=X(t,`.git`),oid:r,cache:i={}}){try{Z(`fs`,e),Z(`gitdir`,n),Z(`oid`,r);let t=new dY(e);return await AY({fs:t,cache:i,gitdir:await pY({fsp:t,dotgit:n}),oid:r})}catch(e){throw e.caller=`git.readCommit`,e}}async function NZ({fs:e,dir:t,gitdir:n=X(t,`.git`),oid:r,filepath:i=void 0,cache:a={}}){try{Z(`fs`,e),Z(`gitdir`,n),Z(`oid`,r);let t=new dY(e);return await FY({fs:t,cache:a,gitdir:await pY({fsp:t,dotgit:n}),oid:r,filepath:i})}catch(e){throw e.caller=`git.readTree`,e}}async function PZ({fs:e,dir:t,gitdir:n=X(t,`.git`),filepath:r,cache:i={}}){try{Z(`fs`,e),Z(`gitdir`,n),Z(`filepath`,r);let t=new dY(e),a=await pY({fsp:t,dotgit:n});await UK.acquire({fs:t,gitdir:a,cache:i},async function(e){e.delete({filepath:r})})}catch(e){throw e.caller=`git.remove`,e}}async function FZ({gitdir:e,type:t,object:n}){return AK(Rq.wrap({type:t,object:n}))}async function IZ({fs:e,dir:t,gitdir:n=X(t,`.git`),filepath:r,ref:i,cache:a={}}){try{Z(`fs`,e),Z(`gitdir`,n),Z(`filepath`,r);let o=new dY(e),s=await pY({fsp:o,dotgit:n}),c,l;try{c=await Aq.resolve({fs:o,gitdir:s,ref:i||`HEAD`})}catch(e){if(i)throw e}if(c)try{c=await NY({fs:o,cache:a,gitdir:s,oid:c,filepath:r})}catch{c=null}let u={ctime:new Date(0),mtime:new Date(0),dev:0,ino:0,mode:0,uid:0,gid:0,size:0},d=t&&await o.read(X(t,r));d&&(l=await FZ({gitdir:s,type:`blob`,object:d}),c===l&&(u=await o.lstat(X(t,r)))),await UK.acquire({fs:o,gitdir:s,cache:a},async function(e){e.delete({filepath:r}),c&&e.insert({filepath:r,stats:u,oid:c})})}catch(e){throw e.caller=`git.reset`,e}}async function LZ({fs:e,dir:t,gitdir:n=X(t,`.git`),ref:r,depth:i}){try{Z(`fs`,e),Z(`gitdir`,n),Z(`ref`,r);let t=new dY(e),a=await pY({fsp:t,dotgit:n});return await Aq.resolve({fs:t,gitdir:a,ref:r,depth:i})}catch(e){throw e.caller=`git.resolveRef`,e}}async function RZ({fs:e,dir:t,gitdir:n=X(t,`.git`),path:r,value:i,append:a=!1}){try{Z(`fs`,e),Z(`gitdir`,n),Z(`path`,r);let t=new dY(e),o=await pY({fsp:t,dotgit:n}),s=await Tq.get({fs:t,gitdir:o});a?await s.append(r,i):await s.set(r,i),await Tq.save({fs:t,gitdir:o,config:s})}catch(e){throw e.caller=`git.setConfig`,e}}async function zZ({fs:e,gitdir:t,commit:n}){return await xY({fs:e,gitdir:t,type:`commit`,object:qJ.from(n).toObject(),format:`content`})}async function BZ({fs:e,dir:t,gitdir:n=X(t,`.git`),ref:r=`HEAD`,filepaths:i=[`.`],filter:a,cache:o={},ignored:s=!1}){try{Z(`fs`,e),Z(`gitdir`,n),Z(`ref`,r);let c=new dY(e);return await rY({fs:c,cache:o,dir:t,gitdir:await pY({fsp:c,dotgit:n}),trees:[XJ({ref:r}),QJ(),XK()],map:async function(e,[n,r,o]){if(!n&&!o&&r&&!s&&await hY.isIgnored({fs:c,dir:t,filepath:e})||!i.some(t=>GY(e,t)))return null;if(a&&!a(e))return;let[l,u,d]=await Promise.all([n&&n.type(),r&&r.type(),o&&o.type()]),f=[l,u,d].includes(`blob`);if((l===`tree`||l===`special`)&&!f)return;if(l===`commit`)return null;if((u===`tree`||u===`special`)&&!f)return;if(d===`commit`)return null;if((d===`tree`||d===`special`)&&!f)return;let p=l===`blob`?await n.oid():void 0,m=d===`blob`?await o.oid():void 0,h;l!==`blob`&&u===`blob`&&d!==`blob`?h=`42`:u===`blob`&&(h=await r.oid());let g=[void 0,p,h,m],_=g.map(e=>g.indexOf(e));return _.shift(),[e,..._]}})}catch(e){throw e.caller=`git.statusMatrix`,e}}async function VZ({fs:e,dir:t,gitdir:n=X(t,`.git`),ref:r,object:i,force:a=!1}){try{Z(`fs`,e),Z(`gitdir`,n),Z(`ref`,r);let t=new dY(e);if(r===void 0)throw new TJ(`ref`);r=r.startsWith(`refs/tags/`)?r:`refs/tags/${r}`;let o=await pY({fsp:t,dotgit:n}),s=await Aq.resolve({fs:t,gitdir:o,ref:i||`HEAD`});if(!a&&await Aq.exists({fs:t,gitdir:o,ref:r}))throw new lJ(`tag`,r);await Aq.writeRef({fs:t,gitdir:o,ref:r,value:s})}catch(e){throw e.caller=`git.tag`,e}}function HZ(){try{return OX.version}catch(e){throw e.caller=`git.version`,e}}async function UZ({fs:e,dir:t,gitdir:n=X(t,`.git`),trees:r,map:i,reduce:a,iterate:o,cache:s={}}){try{Z(`fs`,e),Z(`gitdir`,n),Z(`trees`,r);let c=new dY(e);return await rY({fs:c,cache:s,dir:t,gitdir:await pY({fsp:c,dotgit:n}),trees:r,map:i,reduce:a,iterate:o})}catch(e){throw e.caller=`git.walk`,e}}async function WZ({fs:e,dir:t,gitdir:n=X(t,`.git`),blob:r}){try{Z(`fs`,e),Z(`gitdir`,n),Z(`blob`,r);let t=new dY(e);return await xY({fs:t,gitdir:await pY({fsp:t,dotgit:n}),type:`blob`,object:r,format:`content`})}catch(e){throw e.caller=`git.writeBlob`,e}}async function GZ({fs:e,dir:t,gitdir:n=X(t,`.git`),commit:r}){try{Z(`fs`,e),Z(`gitdir`,n),Z(`commit`,r);let t=new dY(e);return await zZ({fs:t,gitdir:await pY({fsp:t,dotgit:n}),commit:r})}catch(e){throw e.caller=`git.writeCommit`,e}}async function KZ({fs:e,dir:t,gitdir:n=X(t,`.git`),ref:r,value:i,force:a=!1,symbolic:o=!1}){try{Z(`fs`,e),Z(`gitdir`,n),Z(`ref`,r),Z(`value`,i);let t=new dY(e);if(!RY(r,!0))throw new bJ(r,hK.default.clean(r));let s=await pY({fsp:t,dotgit:n});if(!a&&await Aq.exists({fs:t,gitdir:s,ref:r}))throw new lJ(`ref`,r);o?await Aq.writeSymbolicRef({fs:t,gitdir:s,ref:r,value:i}):(i=await Aq.resolve({fs:t,gitdir:s,ref:i}),await Aq.writeRef({fs:t,gitdir:s,ref:r,value:i}))}catch(e){throw e.caller=`git.writeRef`,e}}async function qZ({fs:e,dir:t,gitdir:n=X(t,`.git`),tree:r}){try{Z(`fs`,e),Z(`gitdir`,n),Z(`tree`,r);let t=new dY(e);return await IY({fs:t,gitdir:await pY({fsp:t,dotgit:n}),tree:r})}catch(e){throw e.caller=`git.writeTree`,e}}function JZ(e){return e.headers.get(`x-proxy-error`)===`1`}async function YZ(e){let t=`Proxy error ${e.status}`,n;try{n=await e.text()}catch{return t}return XZ(n,t)}function XZ(e,t){let n;try{n=JSON.parse(e)}catch{return t}if(!n||typeof n!=`object`)return t;let r=n.error;if(typeof r==`string`&&r.length>0)return r;if(r&&typeof r==`object`){let e=r.message;if(typeof e==`string`&&e.length>0)return e;try{return JSON.stringify(r)}catch{return t}}return t}function ZZ(){return typeof chrome<`u`&&!!chrome?.runtime?.id}function QZ(){return{request:async e=>{let{url:t,method:n=`GET`,headers:r={},body:i,onProgress:a}=e,o;if(i){let e=[];for await(let t of i)e.push(t);let t=e.reduce((e,t)=>e+t.length,0);o=new Uint8Array(t);let n=0;for(let t of e)o.set(t,n),n+=t.length}let s,c=r[`content-type`]??`application/octet-stream`,l=o?new Blob([o.buffer],{type:c}):void 0;if(ZZ())s=await fetch(t,{method:n,headers:r,body:l});else{let e={...r,"X-Target-URL":t};if(r[`content-type`]&&(e[`Content-Type`]=r[`content-type`]),s=await fetch(`/api/fetch-proxy`,{method:n,headers:e,body:l}),JZ(s))throw Error(await YZ(s))}let u={};s.headers.forEach((e,t)=>{u[t]=e});let d=s.body,f;if(d){let e=d.getReader(),t=0;f={[Symbol.asyncIterator](){return this},async next(){let{done:n,value:r}=await e.read();return n?{done:!0,value:void 0}:(t+=r.length,a&&a({phase:`Receiving`,loaded:t,total:parseInt(u[`content-length`]??`0`,10)||t}),{done:!1,value:r})}}}return{url:s.url||t,method:n,headers:u,body:f,statusCode:s.status,statusMessage:s.statusText}}}}var $Z=QZ();function eQ(e,t){let n=e.length,r=t.length;if(n===0&&r===0)return[];if(n===0)return t.map(e=>({type:`insert`,line:e}));if(r===0)return e.map(e=>({type:`delete`,line:e}));let i=n+r,a=i,o=2*i+1,s=[],c=Array(o).fill(0),l=-1;outer:for(let o=0;o<=i;o++){s.push(c.slice());for(let i=-o;i<=o;i+=2){let s;s=i===-o||i!==o&&c[i-1+a]<c[i+1+a]?c[i+1+a]:c[i-1+a]+1;let u=s-i;for(;s<n&&u<r&&e[s]===t[u];)s++,u++;if(c[i+a]=s,s>=n&&u>=r){l=o;break outer}}}l===-1&&(l=i);let u=[],d=n,f=r;for(let n=l;n>0;n--){let r=s[n],i=d-f,o;o=i===-n||i!==n&&r[i-1+a]<r[i+1+a]?i+1:i-1;let c=r[o+a],l=c-o;for(;d>c&&f>l;)d--,f--,u.push({type:`equal`,line:e[d]});d===c&&f>l?(f--,u.push({type:`insert`,line:t[f]})):f===l&&d>c&&(d--,u.push({type:`delete`,line:e[d]}))}for(;d>0&&f>0;)d--,f--,u.push({type:`equal`,line:e[d]});return u.reverse(),u}function tQ(e,t=3){let n=[],r=[];for(let t=0;t<e.length;t++)e[t].type!==`equal`&&r.push(t);if(r.length===0)return[];let i=0,a=[];for(let e=1;e<r.length;e++)r[e]-r[e-1]>2*t&&(a.push([i,e-1]),i=e);a.push([i,r.length-1]);for(let[i,o]of a){let a=r[i],s=r[o],c=Math.max(0,a-t),l=Math.min(e.length-1,s+t),u=[],d=0,f=0;for(let t=0;t<c;t++)(e[t].type===`equal`||e[t].type===`delete`)&&d++,(e[t].type===`equal`||e[t].type===`insert`)&&f++;let p=d+1,m=f+1,h=0,g=0;for(let t=c;t<=l;t++){let n=e[t];switch(n.type){case`equal`:u.push(` ${n.line}`),h++,g++;break;case`delete`:u.push(`-${n.line}`),h++;break;case`insert`:u.push(`+${n.line}`),g++;break}}n.push({oldStart:p,oldCount:h,newStart:m,newCount:g,lines:u})}return n}function nQ(e){let{oldContent:t,newContent:n,oldName:r,newName:i,color:a=!0}=e;if(t===n)return``;let o=t.split(`
3281
3281
  `),s=n.split(`
3282
- `);o.length>0&&o[o.length-1]===``&&o.pop(),s.length>0&&s[s.length-1]===``&&s.pop();let c=QZ(ZZ(o,s));if(c.length===0)return``;let l=a?`\x1B[31m`:``,u=a?`\x1B[32m`:``,d=a?`\x1B[36m`:``,f=a?`\x1B[1m`:``,p=a?`\x1B[0m`:``,m=``;m+=`${f}diff --git a/${r} b/${i}${p}\n`,m+=`${f}--- a/${r}${p}\n`,m+=`${f}+++ b/${i}${p}\n`;for(let e of c){m+=`${d}@@ -${e.oldStart},${e.oldCount} +${e.newStart},${e.newCount} @@${p}\n`;for(let t of e.lines)t.startsWith(`+`)?m+=`${u}${t}${p}\n`:t.startsWith(`-`)?m+=`${l}${t}${p}\n`:m+=`${t}\n`}return m}function eQ(e,t){if(e===t)return{insertions:0,deletions:0};let n=e.split(`
3282
+ `);o.length>0&&o[o.length-1]===``&&o.pop(),s.length>0&&s[s.length-1]===``&&s.pop();let c=tQ(eQ(o,s));if(c.length===0)return``;let l=a?`\x1B[31m`:``,u=a?`\x1B[32m`:``,d=a?`\x1B[36m`:``,f=a?`\x1B[1m`:``,p=a?`\x1B[0m`:``,m=``;m+=`${f}diff --git a/${r} b/${i}${p}\n`,m+=`${f}--- a/${r}${p}\n`,m+=`${f}+++ b/${i}${p}\n`;for(let e of c){m+=`${d}@@ -${e.oldStart},${e.oldCount} +${e.newStart},${e.newCount} @@${p}\n`;for(let t of e.lines)t.startsWith(`+`)?m+=`${u}${t}${p}\n`:t.startsWith(`-`)?m+=`${l}${t}${p}\n`:m+=`${t}\n`}return m}function rQ(e,t){if(e===t)return{insertions:0,deletions:0};let n=e.split(`
3283
3283
  `),r=t.split(`
3284
- `);n.length>0&&n[n.length-1]===``&&n.pop(),r.length>0&&r[r.length-1]===``&&r.pop();let i=ZZ(n,r),a=0,o=0;for(let e of i)e.type===`insert`&&a++,e.type===`delete`&&o++;return{insertions:a,deletions:o}}var tQ=33188,nQ=16877,rQ=40960;function iQ(e,t){let n=t.mtimeMs??0;return{type:e,mode:t.mode??(e===`dir`?nQ:e===`symlink`?rQ:tQ),size:t.size??0,ino:t.ino??0,mtimeMs:n,ctimeMs:t.ctimeMs??n,uid:1,gid:1,dev:1,isFile:()=>e===`file`,isDirectory:()=>e===`dir`,isSymbolicLink:()=>e===`symlink`}}function aQ(e){if(typeof e==`string`)return/^utf-?8$/i.test(e);if(e&&typeof e==`object`){let t=e.encoding;if(typeof t==`string`)return/^utf-?8$/i.test(t)}return!1}function oQ(e){let t=e.getLightningFS(),n=t=>e.isPathUnderMount(t);return{promises:{async readFile(r,i){return n(r)?await e.readFile(r,aQ(i)?{encoding:`utf-8`}:{encoding:`binary`}):aQ(i)?await t.readFile(r,{encoding:`utf8`}):await t.readFile(r)},async writeFile(r,i,a){if(n(r)){await e.writeFile(r,i);return}await t.writeFile(r,i)},async unlink(r){if(n(r)){await e.rm(r);return}await t.unlink(r)},async readdir(r){return n(r)?(await e.readDir(r)).map(e=>e.name):await t.readdir(r)},async mkdir(r,i){let a=i??void 0;if(n(r)){await e.mkdir(r,a?.recursive===void 0?void 0:{recursive:a.recursive});return}await t.mkdir(r,a?.mode===void 0?void 0:{mode:a.mode})},async rmdir(r){if(n(r)){await e.rm(r);return}await t.rmdir(r)},async stat(r){if(n(r)){let t=await e.stat(r);return iQ(t.type===`directory`?`dir`:`file`,{size:t.size,mtimeMs:t.mtime,ctimeMs:t.ctime})}let i=await t.stat(r);return iQ(i.isDirectory()?`dir`:i.isSymbolicLink()?`symlink`:`file`,{mode:i.mode,size:i.size,ino:i.ino,mtimeMs:i.mtimeMs,ctimeMs:i.ctimeMs})},async lstat(r){if(n(r)){let t=await e.lstat(r);return iQ(t.type===`directory`?`dir`:t.type===`symlink`?`symlink`:`file`,{size:t.size,mtimeMs:t.mtime,ctimeMs:t.ctime})}let i=await t.lstat(r);return iQ(i.isDirectory()?`dir`:i.isSymbolicLink()?`symlink`:`file`,{mode:i.mode,size:i.size,ino:i.ino,mtimeMs:i.mtimeMs,ctimeMs:i.ctimeMs})},async readlink(e){if(n(e))throw new F(`EINVAL`,`symlinks not supported on mounted filesystems`,e);return t.readlink(e)},async symlink(e,r){if(n(r))throw new F(`EINVAL`,`symlinks not supported on mounted filesystems`,r);await t.symlink(e,r)}}}}var sQ=class e{static globalFsByDbName=new Map;lfs;corsProxy;authorName;authorEmail;globalDbName;githubToken;githubTokenLoaded=!1;constructor(e){this.options=e,this.lfs=oQ(e.fs).promises,this.corsProxy=e.corsProxy,this.authorName=e.authorName??`User`,this.authorEmail=e.authorEmail??`user@example.com`,this.globalDbName=e.globalDbName??`slicc-fs-global`}getOnAuth(){if(!this.githubToken)return;let e=this.githubToken;return()=>({username:`x-access-token`,password:e})}getGlobalFs(){let t=e.globalFsByDbName.get(this.globalDbName);if(t)return t;let n=Hs.create({dbName:this.globalDbName});return e.globalFsByDbName.set(this.globalDbName,n),n}async ensureGithubTokenLoaded(){if(!this.githubTokenLoaded){this.githubTokenLoaded=!0;try{let e=(await(await this.getGlobalFs()).readTextFile(`/workspace/.git/github-token`)).trim();this.githubToken=e||void 0}catch{this.githubToken=void 0}}}async setGithubToken(e){let t=e.trim(),n=await this.getGlobalFs();if(!t){try{await n.rm(`/workspace/.git/github-token`)}catch{}this.githubToken=void 0,this.githubTokenLoaded=!0;return}await n.writeFile(`/workspace/.git/github-token`,t),this.githubToken=t,this.githubTokenLoaded=!0}async execute(e,t){if(e.length===0)return this.help();let[n,...r]=e;try{switch(await this.ensureGithubTokenLoaded(),n){case`init`:return this.init(t,r);case`clone`:return this.clone(t,r);case`add`:return this.add(t,r);case`status`:return this.status(t,r);case`commit`:return this.commit(t,r);case`log`:return this.log(t,r);case`branch`:return this.branch(t,r);case`checkout`:return this.checkout(t,r);case`diff`:return this.diff(t,r);case`show`:return this.show(t,r);case`remote`:return this.remote(t,r);case`fetch`:return this.fetch(t,r);case`pull`:return this.pull(t,r);case`push`:return this.push(t,r);case`merge`:return this.merge(t,r);case`reset`:return this.reset(t,r);case`config`:return this.config(t,r);case`tag`:return this.tag(t,r);case`ls-files`:return this.lsFiles(t,r);case`show-ref`:return this.showRef(t,r);case`stash`:return this.stash(t,r);case`rm`:return this.rm(t,r);case`mv`:return this.mv(t,r);case`rev-parse`:return this.revParse(t,r);case`help`:case`--help`:case`-h`:return this.help();case`version`:case`--version`:return this.version();default:return{stdout:``,stderr:`git: '${n}' is not a git command. See 'git help'.\n`,exitCode:1}}}catch(e){return{stdout:``,stderr:`fatal: ${e instanceof Error?e.message:String(e)}\n`,exitCode:128}}}version(){return{stdout:`git version 2.43.0 (isomorphic-git ${HZ()})\n`,stderr:``,exitCode:0}}help(){return{stdout:`usage: git <command> [<args>]
3284
+ `);n.length>0&&n[n.length-1]===``&&n.pop(),r.length>0&&r[r.length-1]===``&&r.pop();let i=eQ(n,r),a=0,o=0;for(let e of i)e.type===`insert`&&a++,e.type===`delete`&&o++;return{insertions:a,deletions:o}}var iQ=33188,aQ=16877,oQ=40960;function sQ(e,t){let n=t.mtimeMs??0;return{type:e,mode:t.mode??(e===`dir`?aQ:e===`symlink`?oQ:iQ),size:t.size??0,ino:t.ino??0,mtimeMs:n,ctimeMs:t.ctimeMs??n,uid:1,gid:1,dev:1,isFile:()=>e===`file`,isDirectory:()=>e===`dir`,isSymbolicLink:()=>e===`symlink`}}function cQ(e){if(typeof e==`string`)return/^utf-?8$/i.test(e);if(e&&typeof e==`object`){let t=e.encoding;if(typeof t==`string`)return/^utf-?8$/i.test(t)}return!1}function lQ(e){let t=e.getLightningFS(),n=t=>e.isPathUnderMount(t);return{promises:{async readFile(r,i){return n(r)?await e.readFile(r,cQ(i)?{encoding:`utf-8`}:{encoding:`binary`}):cQ(i)?await t.readFile(r,{encoding:`utf8`}):await t.readFile(r)},async writeFile(r,i,a){if(n(r)){await e.writeFile(r,i);return}await t.writeFile(r,i)},async unlink(r){if(n(r)){await e.rm(r);return}await t.unlink(r)},async readdir(r){return n(r)?(await e.readDir(r)).map(e=>e.name):await t.readdir(r)},async mkdir(r,i){let a=i??void 0;if(n(r)){await e.mkdir(r,a?.recursive===void 0?void 0:{recursive:a.recursive});return}await t.mkdir(r,a?.mode===void 0?void 0:{mode:a.mode})},async rmdir(r){if(n(r)){await e.rm(r);return}await t.rmdir(r)},async stat(r){if(n(r)){let t=await e.stat(r);return sQ(t.type===`directory`?`dir`:`file`,{size:t.size,mtimeMs:t.mtime,ctimeMs:t.ctime})}let i=await t.stat(r);return sQ(i.isDirectory()?`dir`:i.isSymbolicLink()?`symlink`:`file`,{mode:i.mode,size:i.size,ino:i.ino,mtimeMs:i.mtimeMs,ctimeMs:i.ctimeMs})},async lstat(r){if(n(r)){let t=await e.lstat(r);return sQ(t.type===`directory`?`dir`:t.type===`symlink`?`symlink`:`file`,{size:t.size,mtimeMs:t.mtime,ctimeMs:t.ctime})}let i=await t.lstat(r);return sQ(i.isDirectory()?`dir`:i.isSymbolicLink()?`symlink`:`file`,{mode:i.mode,size:i.size,ino:i.ino,mtimeMs:i.mtimeMs,ctimeMs:i.ctimeMs})},async readlink(e){if(n(e))throw new F(`EINVAL`,`symlinks not supported on mounted filesystems`,e);return t.readlink(e)},async symlink(e,r){if(n(r))throw new F(`EINVAL`,`symlinks not supported on mounted filesystems`,r);await t.symlink(e,r)}}}}var uQ=class e{static globalFsByDbName=new Map;lfs;corsProxy;authorName;authorEmail;globalDbName;githubToken;githubTokenLoaded=!1;constructor(e){this.options=e,this.lfs=lQ(e.fs).promises,this.corsProxy=e.corsProxy,this.authorName=e.authorName??`User`,this.authorEmail=e.authorEmail??`user@example.com`,this.globalDbName=e.globalDbName??`slicc-fs-global`}getOnAuth(){if(!this.githubToken)return;let e=this.githubToken;return()=>({username:`x-access-token`,password:e})}getGlobalFs(){let t=e.globalFsByDbName.get(this.globalDbName);if(t)return t;let n=Hs.create({dbName:this.globalDbName});return e.globalFsByDbName.set(this.globalDbName,n),n}async ensureGithubTokenLoaded(){if(!this.githubTokenLoaded){this.githubTokenLoaded=!0;try{let e=(await(await this.getGlobalFs()).readTextFile(`/workspace/.git/github-token`)).trim();this.githubToken=e||void 0}catch{this.githubToken=void 0}}}async setGithubToken(e){let t=e.trim(),n=await this.getGlobalFs();if(!t){try{await n.rm(`/workspace/.git/github-token`)}catch{}this.githubToken=void 0,this.githubTokenLoaded=!0;return}await n.writeFile(`/workspace/.git/github-token`,t),this.githubToken=t,this.githubTokenLoaded=!0}async execute(e,t){if(e.length===0)return this.help();let[n,...r]=e;try{switch(await this.ensureGithubTokenLoaded(),n){case`init`:return this.init(t,r);case`clone`:return this.clone(t,r);case`add`:return this.add(t,r);case`status`:return this.status(t,r);case`commit`:return this.commit(t,r);case`log`:return this.log(t,r);case`branch`:return this.branch(t,r);case`checkout`:return this.checkout(t,r);case`diff`:return this.diff(t,r);case`show`:return this.show(t,r);case`remote`:return this.remote(t,r);case`fetch`:return this.fetch(t,r);case`pull`:return this.pull(t,r);case`push`:return this.push(t,r);case`merge`:return this.merge(t,r);case`reset`:return this.reset(t,r);case`config`:return this.config(t,r);case`tag`:return this.tag(t,r);case`ls-files`:return this.lsFiles(t,r);case`show-ref`:return this.showRef(t,r);case`stash`:return this.stash(t,r);case`rm`:return this.rm(t,r);case`mv`:return this.mv(t,r);case`rev-parse`:return this.revParse(t,r);case`help`:case`--help`:case`-h`:return this.help();case`version`:case`--version`:return this.version();default:return{stdout:``,stderr:`git: '${n}' is not a git command. See 'git help'.\n`,exitCode:1}}}catch(e){return{stdout:``,stderr:`fatal: ${e instanceof Error?e.message:String(e)}\n`,exitCode:128}}}version(){return{stdout:`git version 2.43.0 (isomorphic-git ${HZ()})\n`,stderr:``,exitCode:0}}help(){return{stdout:`usage: git <command> [<args>]
3285
3285
 
3286
3286
  Available commands:
3287
3287
  init Initialize a new repository
@@ -3310,7 +3310,7 @@ Available commands:
3310
3310
  rev-parse Pick out and massage parameters
3311
3311
 
3312
3312
  `,stderr:``,exitCode:0}}async init(e,t){let n=this.parseArg(t,`--initial-branch`,`-b`)??`main`;return await iZ({fs:this.lfs,dir:e,defaultBranch:n}),{stdout:`Initialized empty Git repository in ${e}/.git/\n`,stderr:``,exitCode:0}}async clone(e,t){if(t.length===0)return{stdout:``,stderr:`fatal: You must specify a repository to clone.
3313
- `,exitCode:128};let n=t[0],r=t[1];if(!r){let e=n.match(/\/([^\/]+?)(\.git)?$/);r=e?e[1]:`repo`}let i=r.startsWith(`/`)?r:`${e}/${r}`,a=this.parseArg(t,`--depth`),o=this.parseArg(t,`--branch`,`-b`),s=this.parseBooleanFlag(t,`--single-branch`,!0),c=`Cloning into '${r}'...\n`;await RX({fs:this.lfs,http:XZ,dir:i,url:n,corsProxy:this.corsProxy,depth:a?parseInt(a,10):1,ref:o,singleBranch:s,noCheckout:!1,cache:{},onAuth:this.getOnAuth(),onProgress:e=>{e.phase===`Receiving objects`&&(c+=`Receiving objects: ${e.loaded}/${e.total}\n`)}});try{let e=await lZ({fs:this.lfs,dir:i});e.length>0&&(c+=`Checked out ${e.length} files.\n`)}catch{}return{stdout:c+`done.
3313
+ `,exitCode:128};let n=t[0],r=t[1];if(!r){let e=n.match(/\/([^\/]+?)(\.git)?$/);r=e?e[1]:`repo`}let i=r.startsWith(`/`)?r:`${e}/${r}`,a=this.parseArg(t,`--depth`),o=this.parseArg(t,`--branch`,`-b`),s=this.parseBooleanFlag(t,`--single-branch`,!0),c=`Cloning into '${r}'...\n`;await RX({fs:this.lfs,http:$Z,dir:i,url:n,corsProxy:this.corsProxy,depth:a?parseInt(a,10):1,ref:o,singleBranch:s,noCheckout:!1,cache:{},onAuth:this.getOnAuth(),onProgress:e=>{e.phase===`Receiving objects`&&(c+=`Receiving objects: ${e.loaded}/${e.total}\n`)}});try{let e=await lZ({fs:this.lfs,dir:i});e.length>0&&(c+=`Checked out ${e.length} files.\n`)}catch{}return{stdout:c+`done.
3314
3314
  `,stderr:``,exitCode:0}}async add(e,t){let n=t.includes(`-A`)||t.includes(`--all`),r=t.includes(`-u`)||t.includes(`--update`),i=t.includes(`-f`)||t.includes(`--force`),a=t.filter(e=>!e.startsWith(`-`));if(!n&&!r&&a.length===0)return{stdout:``,stderr:`Nothing specified, nothing added.
3315
3315
  `,exitCode:0};if(n){let t=await BZ({fs:this.lfs,dir:e});for(let[n,,r,a]of t)r!==a&&(r===0?await PZ({fs:this.lfs,dir:e,filepath:n}):await CY({fs:this.lfs,dir:e,filepath:n,force:i}))}else if(a.includes(`.`)){let t=await BZ({fs:this.lfs,dir:e});for(let[n,,r,a]of t)r!==a&&r!==0&&await CY({fs:this.lfs,dir:e,filepath:n,force:i})}else if(r){let t=await BZ({fs:this.lfs,dir:e});for(let[n,r,a,o]of t)r!==0&&a!==o&&(a===0?await PZ({fs:this.lfs,dir:e,filepath:n}):await CY({fs:this.lfs,dir:e,filepath:n,force:i}))}else for(let t of a)await CY({fs:this.lfs,dir:e,filepath:t,force:i});return{stdout:``,stderr:``,exitCode:0}}async status(e,t){let n=t.includes(`--short`)||t.includes(`-s`),r=t.includes(`--porcelain`);if(n||r)return this.statusShort(e);let i=``;try{let t=await BX({fs:this.lfs,dir:e});i+=`On branch ${t??`(no branch)`}\n\n`}catch{i+=`Not on any branch.
3316
3316
 
@@ -3336,14 +3336,14 @@ Available commands:
3336
3336
  `,exitCode:1};let i=t.slice(0,r).filter(e=>!e.startsWith(`-`))[0];return this.checkoutFiles(e,n,i)}let i=t.find(e=>!e.startsWith(`-`));return i?n?(await WY({fs:this.lfs,dir:e,ref:i,checkout:!0}),{stdout:`Switched to a new branch '${i}'\n`,stderr:``,exitCode:0}):(await ZY({fs:this.lfs,dir:e,ref:i}),{stdout:`Switched to branch '${i}'\n`,stderr:``,exitCode:0}):{stdout:``,stderr:`error: you must specify path(s) or a branch to checkout
3337
3337
  `,exitCode:1}}async checkoutFiles(e,t,n){let r=n??`HEAD`,i=await LZ({fs:this.lfs,dir:e,ref:r});for(let n of t){let{blob:t}=await jZ({fs:this.lfs,dir:e,oid:i,filepath:n}),r=n.lastIndexOf(`/`);r!==-1&&await this.options.fs.mkdir(`${e}/${n.slice(0,r)}`,{recursive:!0}),await this.options.fs.writeFile(`${e}/${n}`,t),await CY({fs:this.lfs,dir:e,filepath:n})}return{stdout:``,stderr:``,exitCode:0}}async diff(e,t){let n=t.includes(`--staged`)||t.includes(`--cached`),r=t.includes(`--name-only`),i=t.includes(`--stat`),a=t.filter(e=>!e.startsWith(`-`));if(a.length>=2)return this.diffCommits(e,a[0],a[1],{nameOnly:r,stat:i});let o=[];if(n)await UZ({fs:this.lfs,dir:e,trees:[XJ({ref:`HEAD`}),XK()],map:async(t,[n,r])=>{if(t===`.`||t.startsWith(`.git`))return;let i=n?await n.type():void 0,a=r?await r.type():void 0;if(i===`tree`||a===`tree`)return;let s=n?await n.oid():void 0,c=r?await r.oid():void 0;if(s===c)return;let l=``;if(s)try{let{blob:t}=await jZ({fs:this.lfs,dir:e,oid:s});l=new TextDecoder().decode(t)}catch{}let u=``;if(c)try{let{blob:t}=await jZ({fs:this.lfs,dir:e,oid:c});u=new TextDecoder().decode(t)}catch{}o.push({filepath:t,oldContent:l,newContent:u})}});else{let t=new Map;await UZ({fs:this.lfs,dir:e,trees:[XK()],map:async(e,[n])=>{if(e===`.`||e.startsWith(`.git`)||!n||await n.type()!==`blob`)return;let r=await n.oid();r&&t.set(e,r)}});for(let[n,r]of t){let t=``;try{let{blob:n}=await jZ({fs:this.lfs,dir:e,oid:r});t=new TextDecoder().decode(n)}catch{}let i=``;try{i=await this.options.fs.readTextFile(`${e}/${n}`)}catch{}t!==i&&o.push({filepath:n,oldContent:t,newContent:i})}}if(o.length===0)return{stdout:``,stderr:``,exitCode:0};if(r)return{stdout:o.map(e=>e.filepath).join(`
3338
3338
  `)+`
3339
- `,stderr:``,exitCode:0};if(i)return this.formatDiffStat(o);let s=``;for(let e of o)s+=$Z({oldContent:e.oldContent,newContent:e.newContent,oldName:e.filepath,newName:e.filepath});return{stdout:s,stderr:``,exitCode:0}}async diffCommits(e,t,n,r){let i=t,a=n;try{i=await XX({fs:this.lfs,dir:e,oid:t})}catch{try{i=await LZ({fs:this.lfs,dir:e,ref:t})}catch{}}try{a=await XX({fs:this.lfs,dir:e,oid:n})}catch{try{a=await LZ({fs:this.lfs,dir:e,ref:n})}catch{}}let o=[];if(await UZ({fs:this.lfs,dir:e,trees:[XJ({ref:i}),XJ({ref:a})],map:async(e,[t,n])=>{if(e===`.`)return;let r=t?await t.type():void 0,i=n?await n.type():void 0;if(r===`tree`||i===`tree`||(t?await t.oid():void 0)===(n?await n.oid():void 0))return;let a=t?await t.content():void 0,s=n?await n.content():void 0,c=a?new TextDecoder().decode(a):``,l=s?new TextDecoder().decode(s):``;o.push({filepath:e,oldContent:c,newContent:l})}}),o.length===0)return{stdout:``,stderr:``,exitCode:0};if(r.nameOnly)return{stdout:o.map(e=>e.filepath).join(`
3339
+ `,stderr:``,exitCode:0};if(i)return this.formatDiffStat(o);let s=``;for(let e of o)s+=nQ({oldContent:e.oldContent,newContent:e.newContent,oldName:e.filepath,newName:e.filepath});return{stdout:s,stderr:``,exitCode:0}}async diffCommits(e,t,n,r){let i=t,a=n;try{i=await XX({fs:this.lfs,dir:e,oid:t})}catch{try{i=await LZ({fs:this.lfs,dir:e,ref:t})}catch{}}try{a=await XX({fs:this.lfs,dir:e,oid:n})}catch{try{a=await LZ({fs:this.lfs,dir:e,ref:n})}catch{}}let o=[];if(await UZ({fs:this.lfs,dir:e,trees:[XJ({ref:i}),XJ({ref:a})],map:async(e,[t,n])=>{if(e===`.`)return;let r=t?await t.type():void 0,i=n?await n.type():void 0;if(r===`tree`||i===`tree`||(t?await t.oid():void 0)===(n?await n.oid():void 0))return;let a=t?await t.content():void 0,s=n?await n.content():void 0,c=a?new TextDecoder().decode(a):``,l=s?new TextDecoder().decode(s):``;o.push({filepath:e,oldContent:c,newContent:l})}}),o.length===0)return{stdout:``,stderr:``,exitCode:0};if(r.nameOnly)return{stdout:o.map(e=>e.filepath).join(`
3340
3340
  `)+`
3341
- `,stderr:``,exitCode:0};if(r.stat)return this.formatDiffStat(o);let s=``;for(let e of o)s+=$Z({oldContent:e.oldContent,newContent:e.newContent,oldName:e.filepath,newName:e.filepath});return{stdout:s,stderr:``,exitCode:0}}formatDiffStat(e){let t=`\x1B[0m`,n=``,r=0,i=0,a=0,o=e.map(e=>{let t=eQ(e.oldContent,e.newContent);return e.filepath.length>a&&(a=e.filepath.length),r+=t.insertions,i+=t.deletions,{filepath:e.filepath,...t}});for(let e of o){let r=e.insertions+e.deletions,i=`${`+`.repeat(e.insertions)}${t}${`-`.repeat(e.deletions)}${t}`;n+=` ${e.filepath.padEnd(a)} | ${String(r).padStart(4)} ${i}\n`}return n+=` ${e.length} file${e.length===1?``:`s`} changed`,r>0&&(n+=`, ${r} insertion${r===1?``:`s`}(+)`),i>0&&(n+=`, ${i} deletion${i===1?``:`s`}(-)`),n+=`
3341
+ `,stderr:``,exitCode:0};if(r.stat)return this.formatDiffStat(o);let s=``;for(let e of o)s+=nQ({oldContent:e.oldContent,newContent:e.newContent,oldName:e.filepath,newName:e.filepath});return{stdout:s,stderr:``,exitCode:0}}formatDiffStat(e){let t=`\x1B[0m`,n=``,r=0,i=0,a=0,o=e.map(e=>{let t=rQ(e.oldContent,e.newContent);return e.filepath.length>a&&(a=e.filepath.length),r+=t.insertions,i+=t.deletions,{filepath:e.filepath,...t}});for(let e of o){let r=e.insertions+e.deletions,i=`${`+`.repeat(e.insertions)}${t}${`-`.repeat(e.deletions)}${t}`;n+=` ${e.filepath.padEnd(a)} | ${String(r).padStart(4)} ${i}\n`}return n+=` ${e.length} file${e.length===1?``:`s`} changed`,r>0&&(n+=`, ${r} insertion${r===1?``:`s`}(+)`),i>0&&(n+=`, ${i} deletion${i===1?``:`s`}(-)`),n+=`
3342
3342
  `,{stdout:n,stderr:``,exitCode:0}}async show(e,t){let n=t.includes(`--stat`),r=this.parseArg(t,`--format`,`--pretty`),i=new Set([`--format`,`--pretty`]),a;for(let e=0;e<t.length;e++){let n=t[e];if(n.startsWith(`-`)){i.has(n)&&e++;continue}a=n;break}if(a&&a.includes(`:`))return await this.showFileAtCommit(e,a);let o=a??`HEAD`,s;try{s=await LZ({fs:this.lfs,dir:e,ref:o})}catch{try{s=await XX({fs:this.lfs,dir:e,oid:o})}catch{return{stdout:``,stderr:`fatal: bad object ${o}\n`,exitCode:128}}}let{commit:c}=await MZ({fs:this.lfs,dir:e,oid:s}),l=this.formatShowHeader(s,c,r),u=c.parent.length>0?c.parent[0]:void 0;if(u){let t=await this.diffCommits(e,u,s,{nameOnly:!1,stat:n});l+=t.stdout}else{let t=await this.diffInitialCommit(e,s,n);l+=t}return{stdout:l,stderr:``,exitCode:0}}async showFileAtCommit(e,t){let n=t.indexOf(`:`),r=t.slice(0,n)||`HEAD`,i=t.slice(n+1),a=await LZ({fs:this.lfs,dir:e,ref:r}),o=await jZ({fs:this.lfs,dir:e,oid:a,filepath:i});return{stdout:new TextDecoder().decode(o.blob),stderr:``,exitCode:0}}formatShowHeader(e,t,n){if(n)return n.replace(/%H/g,e).replace(/%h/g,e.slice(0,7)).replace(/%s/g,t.message.split(`
3343
3343
  `)[0]).replace(/%an/g,t.author.name).replace(/%ae/g,t.author.email).replace(/%ad/g,new Date(t.author.timestamp*1e3).toLocaleString())+`
3344
3344
  `;let r=`\x1b[33mcommit ${e}\x1b[0m\n`;return r+=`Author: ${t.author.name} <${t.author.email}>\n`,r+=`Date: ${new Date(t.author.timestamp*1e3).toLocaleString()}\n\n`,r+=` ${t.message.replace(/\n/g,`
3345
- `)}\n\n`,r}async diffInitialCommit(e,t,n){let r=[];if(await UZ({fs:this.lfs,dir:e,trees:[XJ({ref:t})],map:async(e,[t])=>{if(e===`.`||!t||await t.type()!==`blob`)return;let n=await t.content();n&&r.push({filepath:e,content:new TextDecoder().decode(n)})}}),r.length===0)return``;if(n){let e=r.map(e=>({filepath:e.filepath,oldContent:``,newContent:e.content}));return this.formatDiffStat(e).stdout}let i=``;for(let e of r)i+=$Z({oldContent:``,newContent:e.content,oldName:e.filepath,newName:e.filepath});return i}async remote(e,t){let[n,...r]=t;if(n===`add`&&r.length>=2){let[t,n]=r;return await BY({fs:this.lfs,dir:e,remote:t,url:n}),{stdout:``,stderr:``,exitCode:0}}if(n===`remove`||n===`rm`){let t=r[0];if(t)return await WX({fs:this.lfs,dir:e,remote:t}),{stdout:``,stderr:``,exitCode:0}}let i=t.includes(`-v`)||t.includes(`--verbose`),a=await dZ({fs:this.lfs,dir:e}),o=``;for(let{remote:e,url:t}of a)i?(o+=`${e}\t${t} (fetch)\n`,o+=`${e}\t${t} (push)\n`):o+=`${e}\n`;return{stdout:o,stderr:``,exitCode:0}}async fetch(e,t){let n=t.find(e=>!e.startsWith(`-`))??`origin`,r=t.includes(`--prune`)||t.includes(`-p`),i=`Fetching ${n}\n`,a=await eZ({fs:this.lfs,http:XZ,dir:e,remote:n,corsProxy:this.corsProxy,prune:r,onAuth:this.getOnAuth(),onProgress:e=>{i+=`${e.phase}: ${e.loaded}/${e.total}\n`}});return a.fetchHead&&(i+=`From ${n}\n`,i+=` ${a.fetchHead.slice(0,7)}..${a.fetchHeadDescription??``}\n`),{stdout:i,stderr:``,exitCode:0}}async pull(e,t){let n=t.find(e=>!e.startsWith(`-`))??`origin`,r=`Pulling from ${n}...\n`;return await SZ({fs:this.lfs,http:XZ,dir:e,remote:n,corsProxy:this.corsProxy,author:{name:this.authorName,email:this.authorEmail},onAuth:this.getOnAuth(),onProgress:e=>{r+=`${e.phase}: ${e.loaded}/${e.total}\n`}}),r+=`Already up to date.
3346
- `,{stdout:r,stderr:``,exitCode:0}}async push(e,t){let n=t.includes(`-f`)||t.includes(`--force`),r=t.includes(`-u`)||t.includes(`--set-upstream`),i=t.filter(e=>!e.startsWith(`-`)),a=i[0]??`origin`,o=i[1]??await BX({fs:this.lfs,dir:e}),s=`Pushing to ${a}...\n`,c=await OZ({fs:this.lfs,http:XZ,dir:e,remote:a,ref:o??void 0,corsProxy:this.corsProxy,force:n,onAuth:this.getOnAuth(),onProgress:e=>{s+=`${e.phase}: ${e.loaded}/${e.total}\n`}});if(c.ok)s+=`To ${a}\n`,s+=` ${o} -> ${o}\n`,r&&o&&(await RZ({fs:this.lfs,dir:e,path:`branch.${o}.remote`,value:a}),await RZ({fs:this.lfs,dir:e,path:`branch.${o}.merge`,value:`refs/heads/${o}`}),s+=`Branch '${o}' set up to track remote branch '${o}' from '${a}'.\n`);else return{stdout:``,stderr:`error: failed to push to '${a}': ${c.error}\n`,exitCode:1};return{stdout:s,stderr:``,exitCode:0}}async merge(e,t){let n=t.includes(`--no-ff`),r=t.includes(`--ff-only`),i=t.find(e=>!e.startsWith(`-`));if(!i)return{stdout:``,stderr:`fatal: No branch specified to merge.
3345
+ `)}\n\n`,r}async diffInitialCommit(e,t,n){let r=[];if(await UZ({fs:this.lfs,dir:e,trees:[XJ({ref:t})],map:async(e,[t])=>{if(e===`.`||!t||await t.type()!==`blob`)return;let n=await t.content();n&&r.push({filepath:e,content:new TextDecoder().decode(n)})}}),r.length===0)return``;if(n){let e=r.map(e=>({filepath:e.filepath,oldContent:``,newContent:e.content}));return this.formatDiffStat(e).stdout}let i=``;for(let e of r)i+=nQ({oldContent:``,newContent:e.content,oldName:e.filepath,newName:e.filepath});return i}async remote(e,t){let[n,...r]=t;if(n===`add`&&r.length>=2){let[t,n]=r;return await BY({fs:this.lfs,dir:e,remote:t,url:n}),{stdout:``,stderr:``,exitCode:0}}if(n===`remove`||n===`rm`){let t=r[0];if(t)return await WX({fs:this.lfs,dir:e,remote:t}),{stdout:``,stderr:``,exitCode:0}}let i=t.includes(`-v`)||t.includes(`--verbose`),a=await dZ({fs:this.lfs,dir:e}),o=``;for(let{remote:e,url:t}of a)i?(o+=`${e}\t${t} (fetch)\n`,o+=`${e}\t${t} (push)\n`):o+=`${e}\n`;return{stdout:o,stderr:``,exitCode:0}}async fetch(e,t){let n=t.find(e=>!e.startsWith(`-`))??`origin`,r=t.includes(`--prune`)||t.includes(`-p`),i=`Fetching ${n}\n`,a=await eZ({fs:this.lfs,http:$Z,dir:e,remote:n,corsProxy:this.corsProxy,prune:r,onAuth:this.getOnAuth(),onProgress:e=>{i+=`${e.phase}: ${e.loaded}/${e.total}\n`}});return a.fetchHead&&(i+=`From ${n}\n`,i+=` ${a.fetchHead.slice(0,7)}..${a.fetchHeadDescription??``}\n`),{stdout:i,stderr:``,exitCode:0}}async pull(e,t){let n=t.find(e=>!e.startsWith(`-`))??`origin`,r=`Pulling from ${n}...\n`;return await SZ({fs:this.lfs,http:$Z,dir:e,remote:n,corsProxy:this.corsProxy,author:{name:this.authorName,email:this.authorEmail},onAuth:this.getOnAuth(),onProgress:e=>{r+=`${e.phase}: ${e.loaded}/${e.total}\n`}}),r+=`Already up to date.
3346
+ `,{stdout:r,stderr:``,exitCode:0}}async push(e,t){let n=t.includes(`-f`)||t.includes(`--force`),r=t.includes(`-u`)||t.includes(`--set-upstream`),i=t.filter(e=>!e.startsWith(`-`)),a=i[0]??`origin`,o=i[1]??await BX({fs:this.lfs,dir:e}),s=`Pushing to ${a}...\n`,c=await OZ({fs:this.lfs,http:$Z,dir:e,remote:a,ref:o??void 0,corsProxy:this.corsProxy,force:n,onAuth:this.getOnAuth(),onProgress:e=>{s+=`${e.phase}: ${e.loaded}/${e.total}\n`}});if(c.ok)s+=`To ${a}\n`,s+=` ${o} -> ${o}\n`,r&&o&&(await RZ({fs:this.lfs,dir:e,path:`branch.${o}.remote`,value:a}),await RZ({fs:this.lfs,dir:e,path:`branch.${o}.merge`,value:`refs/heads/${o}`}),s+=`Branch '${o}' set up to track remote branch '${o}' from '${a}'.\n`);else return{stdout:``,stderr:`error: failed to push to '${a}': ${c.error}\n`,exitCode:1};return{stdout:s,stderr:``,exitCode:0}}async merge(e,t){let n=t.includes(`--no-ff`),r=t.includes(`--ff-only`),i=t.find(e=>!e.startsWith(`-`));if(!i)return{stdout:``,stderr:`fatal: No branch specified to merge.
3347
3347
  `,exitCode:128};try{let t=await yZ({fs:this.lfs,dir:e,ours:await BX({fs:this.lfs,dir:e})??void 0,theirs:i,fastForward:!n,fastForwardOnly:r,author:{name:this.authorName,email:this.authorEmail},abortOnConflict:!0});return t.alreadyMerged?{stdout:`Already up to date.
3348
3348
  `,stderr:``,exitCode:0}:t.fastForward?(await ZY({fs:this.lfs,dir:e,ref:await BX({fs:this.lfs,dir:e})??`HEAD`}),{stdout:`Updating..${t.oid?t.oid.slice(0,7):``}\nFast-forward\n`,stderr:``,exitCode:0}):t.mergeCommit?(await ZY({fs:this.lfs,dir:e,ref:await BX({fs:this.lfs,dir:e})??`HEAD`}),{stdout:`Merge made by the 'ort' strategy.
3349
3349
  `,stderr:``,exitCode:0}):{stdout:`Merge complete.
@@ -3373,7 +3373,7 @@ Available commands:
3373
3373
  `,exitCode:128};let r=n[0],i=n[1],a=r.startsWith(`/`)?r:`${e}/${r}`,o=i.startsWith(`/`)?i:`${e}/${i}`,s;try{s=await this.options.fs.readFile(a,{encoding:`binary`})}catch{return{stdout:``,stderr:`fatal: bad source, source=${r}, destination=${i}\n`,exitCode:128}}let c=o.lastIndexOf(`/`);return c!==-1&&await this.options.fs.mkdir(o.slice(0,c),{recursive:!0}),await this.options.fs.writeFile(o,s),await this.options.fs.rm(a),await CY({fs:this.lfs,dir:e,filepath:i}),await PZ({fs:this.lfs,dir:e,filepath:r}),{stdout:``,stderr:``,exitCode:0}}async revParse(e,t){if(t.includes(`--show-toplevel`))try{return{stdout:`${await nZ({fs:this.lfs,filepath:e})}\n`,stderr:``,exitCode:0}}catch{return{stdout:``,stderr:`fatal: not a git repository
3374
3374
  `,exitCode:128}}if(t.includes(`--is-inside-work-tree`))try{return await nZ({fs:this.lfs,filepath:e}),{stdout:`true
3375
3375
  `,stderr:``,exitCode:0}}catch{return{stdout:`false
3376
- `,stderr:``,exitCode:0}}let n=t.find(e=>!e.startsWith(`-`))??`HEAD`;try{return{stdout:`${await LZ({fs:this.lfs,dir:e,ref:n})}\n`,stderr:``,exitCode:0}}catch{return{stdout:``,stderr:`fatal: ambiguous argument '${n}'\n`,exitCode:128}}}parseArg(e,...t){for(let n of t){let t=e.indexOf(n);if(t!==-1&&e[t+1])return e[t+1];for(let t of e)if(t.startsWith(`${n}=`))return t.slice(n.length+1)}}parseBooleanFlag(e,t,n){let r=`--no-${t.slice(2)}`,i=n;for(let n of e)n===t&&(i=!0),n===r&&(i=!1);return i}},Q=o(`playwright-teleport`),cQ=null,lQ=null;function uQ(e){cQ=e}function dQ(e){lQ=e}function fQ(e){let t=e.match(/^(f[0-9]+)(e[0-9]+)$/);return t?{framePrefix:t[1],isIframe:!0}:{framePrefix:``,isIframe:!1}}function pQ(e){let t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}var mQ=[`playwright-cli`,`playwright`,`puppeteer`],hQ=new WeakMap,gQ=new Set([`click`,`dblclick`,`fill`,`type`,`press`,`goto`,`navigate`,`select`,`check`,`uncheck`,`drag`,`dialog-accept`,`dialog-dismiss`]);function _Q(e){return e.toISOString().replace(/:/g,`-`)}function vQ(e,t){let n=hQ.get(e);n||(n=new WeakMap,hQ.set(e,n));let r=n.get(t);return r||(r={snapshots:new Map,appTabId:null,harRecorder:null,sessionDirsCreated:!1,teleportWatchers:new Map},n.set(t,r)),r}function yQ(e){return e instanceof F||typeof e==`object`&&e&&`code`in e?e.code===`EEXIST`:e instanceof Error&&e.message.includes(`EEXIST`)}var bQ=`function(text) {
3376
+ `,stderr:``,exitCode:0}}let n=t.find(e=>!e.startsWith(`-`))??`HEAD`;try{return{stdout:`${await LZ({fs:this.lfs,dir:e,ref:n})}\n`,stderr:``,exitCode:0}}catch{return{stdout:``,stderr:`fatal: ambiguous argument '${n}'\n`,exitCode:128}}}parseArg(e,...t){for(let n of t){let t=e.indexOf(n);if(t!==-1&&e[t+1])return e[t+1];for(let t of e)if(t.startsWith(`${n}=`))return t.slice(n.length+1)}}parseBooleanFlag(e,t,n){let r=`--no-${t.slice(2)}`,i=n;for(let n of e)n===t&&(i=!0),n===r&&(i=!1);return i}},Q=o(`playwright-teleport`),dQ=null,fQ=null;function pQ(e){dQ=e}function mQ(e){fQ=e}function hQ(e){let t=e.match(/^(f[0-9]+)(e[0-9]+)$/);return t?{framePrefix:t[1],isIframe:!0}:{framePrefix:``,isIframe:!1}}function gQ(e){let t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}var _Q=[`playwright-cli`,`playwright`,`puppeteer`],vQ=new WeakMap,yQ=new Set([`click`,`dblclick`,`fill`,`type`,`press`,`goto`,`navigate`,`select`,`check`,`uncheck`,`drag`,`dialog-accept`,`dialog-dismiss`]);function bQ(e){return e.toISOString().replace(/:/g,`-`)}function xQ(e,t){let n=vQ.get(e);n||(n=new WeakMap,vQ.set(e,n));let r=n.get(t);return r||(r={snapshots:new Map,appTabId:null,harRecorder:null,sessionDirsCreated:!1,teleportWatchers:new Map},n.set(t,r)),r}function SQ(e){return e instanceof F||typeof e==`object`&&e&&`code`in e?e.code===`EEXIST`:e instanceof Error&&e.message.includes(`EEXIST`)}var CQ=`function(text) {
3377
3377
  const el = this;
3378
3378
  const tag = el.tagName;
3379
3379
  const proto = tag === 'TEXTAREA' ? window.HTMLTextAreaElement.prototype : window.HTMLInputElement.prototype;
@@ -3385,11 +3385,11 @@ Available commands:
3385
3385
  }
3386
3386
  el.dispatchEvent(new Event('input', { bubbles: true }));
3387
3387
  el.dispatchEvent(new Event('change', { bubbles: true }));
3388
- }`,xQ=`function() {
3388
+ }`,wQ=`function() {
3389
3389
  const el = this;
3390
3390
  if (el.isContentEditable) return el.textContent || '';
3391
3391
  return el.value ?? '';
3392
- }`,SQ=`function() {
3392
+ }`,TQ=`function() {
3393
3393
  const el = this;
3394
3394
  if (!(el instanceof HTMLElement)) return false;
3395
3395
  el.focus();
@@ -3413,15 +3413,15 @@ Available commands:
3413
3413
  return true;
3414
3414
  }
3415
3415
  return false;
3416
- }`;async function CQ(e){let t=await e.evaluate(`JSON.stringify({ href: location.href, hostname: location.hostname, pathname: location.pathname })`);return JSON.parse(t)}async function wQ(e,t){if(!t.sessionDirsCreated){for(let t of[`/.playwright`,`/.playwright/snapshots`,`/.playwright/screenshots`])try{await e.mkdir(t,{recursive:!0})}catch(e){if(!yQ(e))throw e}t.sessionDirsCreated=!0}}async function TQ(e,t,n,r){try{return await e.withTab(r,async()=>{let n=await e.evaluate(`JSON.stringify({ url: location.href, title: document.title })`),{url:r,title:i}=JSON.parse(n),a=kQ(await e.getAccessibilityTree(),new Map,new Map,{value:0}).join(`
3416
+ }`;async function EQ(e){let t=await e.evaluate(`JSON.stringify({ href: location.href, hostname: location.hostname, pathname: location.pathname })`);return JSON.parse(t)}async function DQ(e,t){if(!t.sessionDirsCreated){for(let t of[`/.playwright`,`/.playwright/snapshots`,`/.playwright/screenshots`])try{await e.mkdir(t,{recursive:!0})}catch(e){if(!SQ(e))throw e}t.sessionDirsCreated=!0}}async function OQ(e,t,n,r){try{return await e.withTab(r,async()=>{let n=await e.evaluate(`JSON.stringify({ url: location.href, title: document.title })`),{url:r,title:i}=JSON.parse(n),a=MQ(await e.getAccessibilityTree(),new Map,new Map,{value:0}).join(`
3417
3417
  `),o=[`Page URL: ${r}`,`Page Title: ${i}`,``,a].join(`
3418
- `),s=`/.playwright/snapshots/page-${_Q(new Date)}.yml`;return await t.writeFile(s,o),s})}catch{return null}}async function EQ(e,t,n){await wQ(e,t);let r=new Date().toISOString(),i=`playwright-cli ${n.command}${n.args.length?` `+n.args.join(` `):``}`,a=n.result.exitCode===0?n.result.stdout.trim()||`OK`:`Error: ${n.result.stderr.trim()}`,o=[`### ${i}`,`- **Time**: ${r}`];if(n.tabUrl||n.targetId){let e=n.tabUrl?`${n.tabUrl}${n.targetId?` (targetId: ${n.targetId})`:``}`:`targetId: ${n.targetId}`;o.push(`- **Tab**: ${e}`)}o.push(`- **Result**: ${a}`),n.snapshotPath&&o.push(``,`[Snapshot](${n.snapshotPath})`),o.push(`---`,``);let s=o.join(`
3418
+ `),s=`/.playwright/snapshots/page-${bQ(new Date)}.yml`;return await t.writeFile(s,o),s})}catch{return null}}async function kQ(e,t,n){await DQ(e,t);let r=new Date().toISOString(),i=`playwright-cli ${n.command}${n.args.length?` `+n.args.join(` `):``}`,a=n.result.exitCode===0?n.result.stdout.trim()||`OK`:`Error: ${n.result.stderr.trim()}`,o=[`### ${i}`,`- **Time**: ${r}`];if(n.tabUrl||n.targetId){let e=n.tabUrl?`${n.tabUrl}${n.targetId?` (targetId: ${n.targetId})`:``}`:`targetId: ${n.targetId}`;o.push(`- **Tab**: ${e}`)}o.push(`- **Result**: ${a}`),n.snapshotPath&&o.push(``,`[Snapshot](${n.snapshotPath})`),o.push(`---`,``);let s=o.join(`
3419
3419
  `)+`
3420
- `,c=`/.playwright/session.md`,l=``;try{let t=await e.readFile(c);l=typeof t==`string`?t:new TextDecoder().decode(t)}catch{}await e.writeFile(c,l+s)}function DQ(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\n/g,`\\n`)}function OQ(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`)}function kQ(e,t,n,r,i=``,a=``){let o=[],s=tc(e.role,`unknown`).toLowerCase(),c=tc(e.name),l=tc(e.value),u=![`none`,`presentation`,`generic`,`rootwebarea`].includes(s)&&(c||s===`textbox`||s===`button`||s===`link`||s===`checkbox`||s===`radio`),d=``;if(u){d=a+`e${++r.value}`,e.backendNodeId&&n.set(d,e.backendNodeId);let i=OQ(c),o=``;o=s===`button`&&c?`button[aria-label="${i}"], button[title="${i}"]`:s===`link`&&c?`a[aria-label="${i}"], a[title="${i}"]`:s===`textbox`?c?`input[aria-label="${i}"], textarea[aria-label="${i}"], [contenteditable][aria-label="${i}"], input[placeholder="${i}"], textarea[placeholder="${i}"], [contenteditable][placeholder="${i}"], input[title="${i}"], textarea[title="${i}"], [contenteditable][title="${i}"]`:`input, textarea, [contenteditable]`:s===`checkbox`?`input[type="checkbox"]`:s===`radio`?`input[type="radio"]`:c?`[aria-label="${i}"], [title="${i}"]`:`[role="${s}"]`,t.set(d,o)}let f=`${i}- ${s}`;if(c&&(f+=` "${DQ(c)}"`),d&&(f+=` [ref=${d}]`),l&&(f+=`: "${DQ(l)}"`),o.push(f),e.children)for(let s of e.children)o.push(...kQ(s,t,n,r,i+` `,a));return o}async function AQ(e,t){if(t.appTabId)return;let n=await e.listPages(),r=typeof window<`u`?window.location.origin:`http://localhost:5710`,i=n.find(e=>e.url.startsWith(r)&&!e.url.includes(`/preview/`));i&&(t.appTabId=i.targetId)}function jQ(e,t){return t===e.appTabId}function MQ(e){let t=e.url.trim(),n=e.title.trim();return n===`Omnibox Popup`||t.startsWith(`chrome://`)||t.startsWith(`chrome-search://`)||t.startsWith(`chrome-untrusted://`)||t.startsWith(`devtools://`)||t.length===0&&/popup$/i.test(n)}function NQ(e,t){return!jQ(e,t.targetId)&&!MQ(t)}async function PQ(e,t){return await AQ(e,t),(typeof e.listAllTargets==`function`?await e.listAllTargets():await e.listPages()).filter(e=>NQ(t,e))}async function FQ(e,t,n,r){await e.attachToPage(n);let i=await e.evaluate(`JSON.stringify({ url: location.href, title: document.title })`),{url:a,title:o}=JSON.parse(i),s=await e.getAccessibilityTree(),c=new Map,l=new Map,u=new Map,d=kQ(s,c,l,{value:0}).join(`
3420
+ `,c=`/.playwright/session.md`,l=``;try{let t=await e.readFile(c);l=typeof t==`string`?t:new TextDecoder().decode(t)}catch{}await e.writeFile(c,l+s)}function AQ(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\n/g,`\\n`)}function jQ(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`)}function MQ(e,t,n,r,i=``,a=``){let o=[],s=tc(e.role,`unknown`).toLowerCase(),c=tc(e.name),l=tc(e.value),u=![`none`,`presentation`,`generic`,`rootwebarea`].includes(s)&&(c||s===`textbox`||s===`button`||s===`link`||s===`checkbox`||s===`radio`),d=``;if(u){d=a+`e${++r.value}`,e.backendNodeId&&n.set(d,e.backendNodeId);let i=jQ(c),o=``;o=s===`button`&&c?`button[aria-label="${i}"], button[title="${i}"]`:s===`link`&&c?`a[aria-label="${i}"], a[title="${i}"]`:s===`textbox`?c?`input[aria-label="${i}"], textarea[aria-label="${i}"], [contenteditable][aria-label="${i}"], input[placeholder="${i}"], textarea[placeholder="${i}"], [contenteditable][placeholder="${i}"], input[title="${i}"], textarea[title="${i}"], [contenteditable][title="${i}"]`:`input, textarea, [contenteditable]`:s===`checkbox`?`input[type="checkbox"]`:s===`radio`?`input[type="radio"]`:c?`[aria-label="${i}"], [title="${i}"]`:`[role="${s}"]`,t.set(d,o)}let f=`${i}- ${s}`;if(c&&(f+=` "${AQ(c)}"`),d&&(f+=` [ref=${d}]`),l&&(f+=`: "${AQ(l)}"`),o.push(f),e.children)for(let s of e.children)o.push(...MQ(s,t,n,r,i+` `,a));return o}async function NQ(e,t){if(t.appTabId)return;let n=await e.listPages(),r=typeof window<`u`?window.location.origin:`http://localhost:5710`,i=n.find(e=>e.url.startsWith(r)&&!e.url.includes(`/preview/`));i&&(t.appTabId=i.targetId)}function PQ(e,t){return t===e.appTabId}function FQ(e){let t=e.url.trim(),n=e.title.trim();return n===`Omnibox Popup`||t.startsWith(`chrome://`)||t.startsWith(`chrome-search://`)||t.startsWith(`chrome-untrusted://`)||t.startsWith(`devtools://`)||t.length===0&&/popup$/i.test(n)}function IQ(e,t){return!PQ(e,t.targetId)&&!FQ(t)}async function LQ(e,t){return await NQ(e,t),(typeof e.listAllTargets==`function`?await e.listAllTargets():await e.listPages()).filter(e=>IQ(t,e))}async function RQ(e,t,n,r){await e.attachToPage(n);let i=await e.evaluate(`JSON.stringify({ url: location.href, title: document.title })`),{url:a,title:o}=JSON.parse(i),s=await e.getAccessibilityTree(),c=new Map,l=new Map,u=new Map,d=MQ(s,c,l,{value:0}).join(`
3421
3421
  `);if(!r?.noIframes&&typeof e.getFrameTree==`function`)try{let t=(await e.getFrameTree()).filter(e=>e.parentFrameId);if(t.length>0){let n=0,r=d.split(`
3422
- `),i=[],o=new Set;for(let s of r){i.push(s);let r=s.match(/^(\s*)- iframe\s/);if(!r)continue;let d=s.match(/:\s*"([^"]+)"\s*$/);if(!d)continue;let f=d[1],p=t.find(e=>{if(o.has(e.frameId))return!1;try{let t=new URL(e.url),n=new URL(f,a),r=n.origin+n.pathname.replace(/\/$/,``)+n.search;return t.origin+t.pathname.replace(/\/$/,``)+t.search===r}catch{return e.url===f}});if(!p)continue;o.add(p.frameId),n++;let m=`f${n}`,h=r[1]+` `;try{let t=await e.getAccessibilityTreeForFrame(p.frameId),n=new Map,r=new Map,a=kQ(t,n,r,{value:0},h,m);for(let[e,t]of n)c.set(e,t),u.set(e,p.frameId);for(let[e,t]of r)l.set(e,t),u.set(e,p.frameId);i.push(...a)}catch{}}d=i.join(`
3422
+ `),i=[],o=new Set;for(let s of r){i.push(s);let r=s.match(/^(\s*)- iframe\s/);if(!r)continue;let d=s.match(/:\s*"([^"]+)"\s*$/);if(!d)continue;let f=d[1],p=t.find(e=>{if(o.has(e.frameId))return!1;try{let t=new URL(e.url),n=new URL(f,a),r=n.origin+n.pathname.replace(/\/$/,``)+n.search;return t.origin+t.pathname.replace(/\/$/,``)+t.search===r}catch{return e.url===f}});if(!p)continue;o.add(p.frameId),n++;let m=`f${n}`,h=r[1]+` `;try{let t=await e.getAccessibilityTreeForFrame(p.frameId),n=new Map,r=new Map,a=MQ(t,n,r,{value:0},h,m);for(let[e,t]of n)c.set(e,t),u.set(e,p.frameId);for(let[e,t]of r)l.set(e,t),u.set(e,p.frameId);i.push(...a)}catch{}}d=i.join(`
3423
3423
  `)}}catch{}let f={url:a,title:o,refToSelector:c,refToBackendNodeId:l,refToFrameId:u,content:d,timestamp:Date.now()};return t.snapshots.set(n,f),{snapshot:f,output:[`Page URL: ${a}`,`Page Title: ${o}`,``,d].join(`
3424
- `)}}function IQ(e){let t=new Map;for(let n of e){let e=n.domain??`unknown`;t.set(e,(t.get(e)??0)+1)}return[...t.entries()].sort((e,t)=>t[1]-e[1]).map(([e,t])=>`${t} ${e}`).join(`, `)}var LQ={origin:``,localStorage:{},sessionStorage:{}};function RQ(e){return Object.keys(e.localStorage).length+Object.keys(e.sessionStorage).length}function zQ(e){if(!e)return null;try{return new URL(e).origin}catch{return null}}function BQ(e){try{return new URL(`/favicon.ico`,e).toString()}catch{return e}}function VQ(e,t,n){let r=zQ(t);if(t&&r===e)return t;let i=zQ(n);return n&&i===e?n:e||(t??n)}async function HQ(e,t){let n=await e.evaluate(`(() => {
3424
+ `)}}function zQ(e){let t=new Map;for(let n of e){let e=n.domain??`unknown`;t.set(e,(t.get(e)??0)+1)}return[...t.entries()].sort((e,t)=>t[1]-e[1]).map(([e,t])=>`${t} ${e}`).join(`, `)}var BQ={origin:``,localStorage:{},sessionStorage:{}};function VQ(e){return Object.keys(e.localStorage).length+Object.keys(e.sessionStorage).length}function HQ(e){if(!e)return null;try{return new URL(e).origin}catch{return null}}function UQ(e){try{return new URL(`/favicon.ico`,e).toString()}catch{return e}}function WQ(e,t,n){let r=HQ(t);if(t&&r===e)return t;let i=HQ(n);return n&&i===e?n:e||(t??n)}async function GQ(e,t){let n=await e.evaluate(`(() => {
3425
3425
  const collect = (storage) => {
3426
3426
  const items = {};
3427
3427
  for (let i = 0; i < storage.length; i++) {
@@ -3435,7 +3435,7 @@ Available commands:
3435
3435
  localStorage: collect(window.localStorage),
3436
3436
  sessionStorage: collect(window.sessionStorage),
3437
3437
  });
3438
- })()`);if(typeof n!=`string`||n.length===0)return Q.warn(`Teleport storage capture returned non-string result`,{label:t,type:typeof n}),LQ;try{let e=JSON.parse(n);return{origin:typeof e.origin==`string`?e.origin:``,localStorage:e.localStorage??{},sessionStorage:e.sessionStorage??{}}}catch(e){return Q.warn(`Could not parse teleport storage snapshot`,{label:t,error:String(e)}),LQ}}function UQ(e){return`(() => {
3438
+ })()`);if(typeof n!=`string`||n.length===0)return Q.warn(`Teleport storage capture returned non-string result`,{label:t,type:typeof n}),BQ;try{let e=JSON.parse(n);return{origin:typeof e.origin==`string`?e.origin:``,localStorage:e.localStorage??{},sessionStorage:e.sessionStorage??{}}}catch(e){return Q.warn(`Could not parse teleport storage snapshot`,{label:t,error:String(e)}),BQ}}function KQ(e){return`(() => {
3439
3439
  const snapshot = ${JSON.stringify(e)};
3440
3440
  if (!snapshot.origin || window.location.origin !== snapshot.origin) return;
3441
3441
  const markerKey = '__slicc_teleport_storage_applied__:' + snapshot.origin;
@@ -3451,7 +3451,7 @@ Available commands:
3451
3451
  apply(window.localStorage, snapshot.localStorage || {});
3452
3452
  apply(window.sessionStorage, snapshot.sessionStorage || {});
3453
3453
  try { window.sessionStorage.setItem(markerKey, '1'); } catch {}
3454
- })();`}function WQ(e){return`(() => {
3454
+ })();`}function qQ(e){return`(() => {
3455
3455
  const snapshot = ${JSON.stringify(e)};
3456
3456
  if (!snapshot.origin || globalThis.location.origin !== snapshot.origin) {
3457
3457
  throw new Error('Teleport storage origin mismatch');
@@ -3469,11 +3469,11 @@ Available commands:
3469
3469
  localStorageCount: Object.keys(snapshot.localStorage || {}).length,
3470
3470
  sessionStorageCount: Object.keys(snapshot.sessionStorage || {}).length,
3471
3471
  });
3472
- })();`}async function GQ(e,t,n){let r=RQ(t);if(r===0)return;let i=await e.evaluate(WQ(t));Q.info(`Applied teleport storage snapshot on current page`,{target:n,totalEntries:r,resultType:typeof i}),Q.debug(`Applied teleport storage snapshot details`,{target:n,origin:t.origin||`(unknown)`,totalEntries:r,resultType:typeof i})}async function KQ(e,t,n,r){let i=RQ(t);if(i===0)return null;let a=await e.sendCDP(`Page.addScriptToEvaluateOnNewDocument`,{source:UQ(t)}),o=typeof a.identifier==`string`?a.identifier:null;return Q.info(`Installed teleport storage init script`,{target:r,totalEntries:i,hasIdentifier:!!o}),Q.debug(`Installed teleport storage init script details`,{target:r,origin:t.origin||`(unknown)`,localStorageCount:Object.keys(t.localStorage).length,sessionStorageCount:Object.keys(t.sessionStorage).length,hasIdentifier:!!o}),o?async()=>{try{await e.attachToPage(n),await e.sendCDP(`Page.removeScriptToEvaluateOnNewDocument`,{identifier:o})}catch(e){Q.warn(`Failed to remove teleport storage init script`,{target:r,error:String(e)})}}:null}async function qQ(e){let t=await e.evaluate(`(() => JSON.stringify({
3472
+ })();`}async function JQ(e,t,n){let r=VQ(t);if(r===0)return;let i=await e.evaluate(qQ(t));Q.info(`Applied teleport storage snapshot on current page`,{target:n,totalEntries:r,resultType:typeof i}),Q.debug(`Applied teleport storage snapshot details`,{target:n,origin:t.origin||`(unknown)`,totalEntries:r,resultType:typeof i})}async function YQ(e,t,n,r){let i=VQ(t);if(i===0)return null;let a=await e.sendCDP(`Page.addScriptToEvaluateOnNewDocument`,{source:KQ(t)}),o=typeof a.identifier==`string`?a.identifier:null;return Q.info(`Installed teleport storage init script`,{target:r,totalEntries:i,hasIdentifier:!!o}),Q.debug(`Installed teleport storage init script details`,{target:r,origin:t.origin||`(unknown)`,localStorageCount:Object.keys(t.localStorage).length,sessionStorageCount:Object.keys(t.sessionStorage).length,hasIdentifier:!!o}),o?async()=>{try{await e.attachToPage(n),await e.sendCDP(`Page.removeScriptToEvaluateOnNewDocument`,{identifier:o})}catch(e){Q.warn(`Failed to remove teleport storage init script`,{target:r,error:String(e)})}}:null}async function XQ(e){let t=await e.evaluate(`(() => JSON.stringify({
3473
3473
  url: window.location.href,
3474
3474
  title: document.title || '',
3475
3475
  bodySnippet: document.body?.innerText?.replace(/s+/g, ' ').trim().slice(0, 500) || '(empty)',
3476
- }))()`);if(typeof t!=`string`||t.length===0)return{url:``,title:``,bodySnippet:`(unavailable)`};try{let e=JSON.parse(t);return{url:typeof e.url==`string`?e.url:``,title:typeof e.title==`string`?e.title:``,bodySnippet:typeof e.bodySnippet==`string`&&e.bodySnippet.length>0?e.bodySnippet:`(empty)`}}catch{return{url:``,title:``,bodySnippet:`(unparseable)`}}}function JQ(e){return/callback|authorize\/resume|error/i.test(e)}async function YQ(e,t,n){try{let r=await qQ(e),i=`${n}:${r.url}:${r.title}`;if(t.lastFollowerDiagnosticKey===i)return;t.lastFollowerDiagnosticKey=i,Q.debug(`Teleport follower diagnostics`,{reason:n,url:r.url,title:r.title,bodySnippet:r.bodySnippet})}catch(e){Q.warn(`Could not capture teleport follower diagnostics`,{reason:n,error:String(e)})}}async function XQ(e,t){let n=e.removeFollowerStorageScript;if(n){e.removeFollowerStorageScript=null;try{await n(),Q.info(`Removed follower teleport storage init script`,{reason:t})}catch(e){Q.warn(`Failed to remove follower teleport storage init script`,{reason:t,error:String(e)})}}}async function ZQ(e,t){if(Q.warn(`Teleport timed out`,{timeoutMs:t.timeoutMs,phase:t.phase}),Q.debug(`Teleport timeout details`,{timeoutMs:t.timeoutMs,phase:t.phase,followerTargetId:t.followerTargetId}),t.phase=`timedOut`,t.followerTargetId){try{await e.attachToPage(t.followerTargetId),await YQ(e,t,`timeout`)}catch(e){Q.warn(`Could not attach to follower for timeout diagnostics`,{error:String(e)})}await XQ(t,`timeout`)}if(QQ(t),t.followerTargetId)try{await e.closePage(t.followerTargetId)}catch(e){Q.warn(`Failed to close follower tab after timeout`,{error:String(e)})}t.rejectBlock?.(Error(`Teleport timed out after ${Math.round(t.timeoutMs/1e3)}s — human did not complete auth`))}function QQ(e){Q.info(`Cleaning up teleport watcher`,{phase:e.phase,hadPoll:!!e.pollInterval,hadTimeout:!!e.timeoutTimer,hadListener:!!e.cleanupListener}),e.pollInterval&&=(clearInterval(e.pollInterval),void 0),e.timeoutTimer&&=(clearTimeout(e.timeoutTimer),void 0),e.cleanupListener&&=(e.cleanupListener(),void 0)}function $Q(e,t,n,r,i,a,o,s){Q.info(`Arming teleport watcher`,{timeoutMs:i,runtimeSelection:a?`explicit`:`auto`}),Q.debug(`Arming teleport watcher details`,{startPattern:n.source,returnPattern:r.source,timeoutMs:i,runtimeId:a??`auto`,originalUrl:o});let c={startPattern:n,returnPattern:r,timeoutMs:i,runtimeId:a,phase:`armed`,leaderTargetId:s,originalLeaderUrl:o};return c.completionPromise=new Promise((e,t)=>{c.resolveBlock=e,c.rejectBlock=t}),c.completionPromise.catch(()=>{}),c.pollInterval=setInterval(async()=>{if(c.phase!==`armed`)return;let r=c.leaderTargetId;if(r)try{await e.attachToPage(r);let i=await e.evaluate(`window.location.href`),a=typeof i==`string`?i:String(i);Q.debug(`Polling leader tab URL`,{targetId:r,href:a,startPattern:n.source}),n.test(a)&&(Q.info(`Teleport start pattern matched on leader`),Q.debug(`Teleport start pattern matched on leader details`,{targetId:r,href:a,startPattern:n.source}),e$(e,t,c,a))}catch(e){Q.warn(`Error polling leader tab URL`,{targetId:r,error:String(e)})}},1e3),s&&t.teleportWatchers.set(s,c),c}async function e$(e,t,n,r){if(n.phase===`armed`){n.phase=`teleporting`,Q.info(`Teleport triggered`),Q.debug(`Teleport trigger details`,{triggerUrl:r}),n.pollInterval&&=(clearInterval(n.pollInterval),void 0);try{let i=[],a=LQ;try{i=(await e.sendCDP(`Network.getCookies`,{})).cookies??[],Q.info(`Captured leader cookies for follower`,{count:i.length})}catch(e){Q.warn(`Could not capture leader cookies`,{error:String(e)})}try{a=await HQ(e,`leader`),Q.info(`Captured leader storage for follower`,{totalEntries:RQ(a),localStorageCount:Object.keys(a.localStorage).length,sessionStorageCount:Object.keys(a.sessionStorage).length}),Q.debug(`Captured leader storage for follower details`,{origin:a.origin||`(unknown)`,localStorageCount:Object.keys(a.localStorage).length,sessionStorageCount:Object.keys(a.sessionStorage).length})}catch(e){Q.warn(`Could not capture leader storage`,{error:String(e)})}let o=n.runtimeId;if(!o){let e=cQ?.();if(!e)throw Error(`No follower selection available — not connected to a tray`);let t=e();if(!t)throw Error(`No followers connected to teleport to`);o=t.runtimeId}Q.info(`Selected follower for teleport`),Q.debug(`Selected follower for teleport details`,{runtimeId:o});let s=await e.createRemotePage(o,`about:blank`),c=s.includes(`:`)?s:`${o}:${s}`;if(n.followerTargetId=c,Q.info(`Opened follower tab for teleport`),Q.debug(`Opened follower tab for teleport details`,{followerTargetId:c}),await e.attachToPage(c),Q.info(`Attached to follower tab for teleport`),Q.debug(`Attached to follower tab for teleport details`,{followerTargetId:c}),await e.sendCDP(`Page.enable`),i.length>0)try{await e.sendCDP(`Network.setCookies`,{cookies:i}),Q.info(`Injected leader cookies into follower`,{count:i.length})}catch(e){Q.warn(`Could not inject leader cookies into follower`,{error:String(e)})}let l=r;n.removeFollowerStorageScript=await KQ(e,a,c,`follower`),Q.info(`Navigating follower to intercepted auth URL`),Q.debug(`Navigating follower to intercepted auth URL details`,{url:l,originalLeaderUrl:n.originalLeaderUrl,triggerUrl:r,storageOrigin:a.origin||`(unknown)`}),await e.sendCDP(`Page.navigate`,{url:l}),Q.info(`Starting teleport timeout timer`,{timeoutMs:n.timeoutMs}),n.timeoutTimer=setTimeout(()=>{(n.phase===`teleporting`||n.phase===`waitingForAuth`||n.phase===`waitingForReturn`)&&ZQ(e,n)},n.timeoutMs),n.phase=`waitingForAuth`,Q.info(`Teleport waiting for follower auth redirect`),Q.debug(`Teleport waiting for follower auth redirect details`,{startPattern:n.startPattern.source}),n.pollInterval=setInterval(async()=>{if(!(n.phase!==`waitingForAuth`&&n.phase!==`waitingForReturn`))try{await e.attachToPage(c);let r=await e.evaluate(`window.location.href`),i=typeof r==`string`?r:String(r);if(!i)return;if(n.lastFollowerUrl!==i&&(n.lastFollowerUrl=i,Q.debug(`Follower teleport navigation`,{href:i,phase:n.phase})),n.phase===`waitingForAuth`){n.startPattern.test(i)?(n.phase=`waitingForReturn`,Q.info(`Follower reached auth provider; waiting for return pattern`),Q.debug(`Follower reached auth provider details`,{href:i,startPattern:n.startPattern.source})):Q.debug(`Waiting for auth redirect on follower`,{href:i,startPattern:n.startPattern.source});return}Q.debug(`Polling follower tab URL for return`,{href:i,returnPattern:n.returnPattern.source}),JQ(i)&&await YQ(e,n,`waiting-for-return`),n.returnPattern.test(i)&&(Q.info(`Follower return pattern matched after auth`),Q.debug(`Follower return pattern matched after auth details`,{href:i,returnPattern:n.returnPattern.source}),t$(e,t,n,o))}catch(e){Q.warn(`Error polling follower tab URL`,{error:String(e)})}},1e3)}catch(e){Q.error(`Teleport trigger failed`,{error:String(e)}),await XQ(n,`trigger-error`),n.phase=`done`,QQ(n),n.rejectBlock?.(e instanceof Error?e:Error(String(e)))}}}async function t$(e,t,n,r){if(!(n.phase!==`teleporting`&&n.phase!==`waitingForReturn`)){n.phase=`capturing`,Q.info(`Capturing auth state from follower`),Q.debug(`Capturing auth state from follower details`,{followerTargetId:n.followerTargetId,runtimeId:r}),n.pollInterval&&=(clearInterval(n.pollInterval),void 0),n.timeoutTimer&&=(clearTimeout(n.timeoutTimer),void 0);try{Q.info(`Waiting for redirect chain to settle (2s)`),await new Promise(e=>setTimeout(e,2e3)),await e.attachToPage(n.followerTargetId);let t;try{let n=await e.evaluate(`window.location.href`);t=typeof n==`string`?n:String(n),Q.debug(`Captured final URL from follower`,{finalUrl:t})}catch(e){Q.warn(`Could not read follower URL (may be mid-navigation)`,{error:String(e)})}try{let t=await e.evaluate(`document.body?.innerText?.substring(0, 500) || "(empty)"`);Q.debug(`Follower page content at capture time`,{bodyText:t})}catch(e){Q.warn(`Could not read follower page content`,{error:String(e)})}let i=(await e.sendCDP(`Network.getCookies`)).cookies??[],a=i.length>0?IQ(i):`none`;Q.info(`Captured cookies from follower`,{count:i.length}),Q.debug(`Captured cookies from follower details`,{count:i.length,domains:a});let o=LQ;try{o=await HQ(e,`follower`),Q.info(`Captured follower storage for leader`,{totalEntries:RQ(o),localStorageCount:Object.keys(o.localStorage).length,sessionStorageCount:Object.keys(o.sessionStorage).length}),Q.debug(`Captured follower storage for leader details`,{origin:o.origin||`(unknown)`,localStorageCount:Object.keys(o.localStorage).length,sessionStorageCount:Object.keys(o.sessionStorage).length})}catch(e){Q.warn(`Could not capture follower storage`,{error:String(e)})}let s=RQ(o);await YQ(e,n,`capture`),await XQ(n,`capture`);try{await e.closePage(n.followerTargetId),Q.info(`Closed follower tab after teleport`),Q.debug(`Closed follower tab after teleport details`,{followerTargetId:n.followerTargetId})}catch(e){Q.warn(`Failed to close follower tab`,{error:String(e)})}let c=n.leaderTargetId,l=o.origin||``,u=VQ(l,n.originalLeaderUrl,t),d=zQ(n.originalLeaderUrl),f=!!l&&d!==l,p=f?BQ(l):null;if(c)if(await e.attachToPage(c),i.length>0&&(await e.sendCDP(`Network.setCookies`,{cookies:i}),Q.info(`Injected cookies into leader tab`,{count:i.length}),Q.debug(`Injected cookies into leader tab details`,{count:i.length,leaderTargetId:c})),f&&p){Q.info(`Hydrating leader storage origin before landing`,{storageEntries:s}),Q.debug(`Hydrating leader storage origin before landing details`,{hydrationUrl:p,landingUrl:u,originalLeaderUrl:n.originalLeaderUrl,finalUrl:t,leaderTargetId:c,storageOrigin:l,storageEntries:s});try{await e.navigate(p),await GQ(e,o,`leader`),u&&u!==p&&await e.navigate(u)}catch(t){Q.warn(`Direct leader origin hydration failed, falling back to init-script replay`,{error:String(t)}),Q.debug(`Direct leader origin hydration fallback details`,{hydrationUrl:p,landingUrl:u,error:String(t)});let n=await KQ(e,o,c,`leader`);try{u&&await e.navigate(u)}finally{await n?.()}}}else{let r=await KQ(e,o,c,`leader`);try{u&&(Q.info(`Navigating leader after auth-state injection`,{hasLandingUrl:!0,storageEntries:s}),Q.debug(`Navigating leader after auth-state injection details`,{landingUrl:u,originalLeaderUrl:n.originalLeaderUrl,finalUrl:t,leaderTargetId:c,storageOrigin:o.origin||`(unknown)`,storageEntries:s}),await e.navigate(u))}finally{await r?.()}}else Q.warn(`No leader tab available for auth-state injection`);n.phase=`done`,QQ(n);let m=i.length>0?` (${IQ(i)})`:``,h=s>0?` + ${s} storage entr${s===1?`y`:`ies`}`:``,g=u?` (navigated to ${u})`:``,_=`Teleported ${i.length} cookie(s)${m}${h} from ${r}${g}`;Q.info(`Teleport completed successfully`,{cookieCount:i.length,storageEntries:s,landed:!!u}),Q.debug(`Teleport completed successfully details`,{result:_}),n.resolveBlock?.(_)}catch(e){Q.error(`Teleport auth-state capture failed`,{error:String(e)}),await XQ(n,`capture-error`),n.phase=`done`,QQ(n),n.rejectBlock?.(e instanceof Error?e:Error(String(e)))}}}function n$(e){return`Usage: ${e} <command> [args...]
3476
+ }))()`);if(typeof t!=`string`||t.length===0)return{url:``,title:``,bodySnippet:`(unavailable)`};try{let e=JSON.parse(t);return{url:typeof e.url==`string`?e.url:``,title:typeof e.title==`string`?e.title:``,bodySnippet:typeof e.bodySnippet==`string`&&e.bodySnippet.length>0?e.bodySnippet:`(empty)`}}catch{return{url:``,title:``,bodySnippet:`(unparseable)`}}}function ZQ(e){return/callback|authorize\/resume|error/i.test(e)}async function QQ(e,t,n){try{let r=await XQ(e),i=`${n}:${r.url}:${r.title}`;if(t.lastFollowerDiagnosticKey===i)return;t.lastFollowerDiagnosticKey=i,Q.debug(`Teleport follower diagnostics`,{reason:n,url:r.url,title:r.title,bodySnippet:r.bodySnippet})}catch(e){Q.warn(`Could not capture teleport follower diagnostics`,{reason:n,error:String(e)})}}async function $Q(e,t){let n=e.removeFollowerStorageScript;if(n){e.removeFollowerStorageScript=null;try{await n(),Q.info(`Removed follower teleport storage init script`,{reason:t})}catch(e){Q.warn(`Failed to remove follower teleport storage init script`,{reason:t,error:String(e)})}}}async function e$(e,t){if(Q.warn(`Teleport timed out`,{timeoutMs:t.timeoutMs,phase:t.phase}),Q.debug(`Teleport timeout details`,{timeoutMs:t.timeoutMs,phase:t.phase,followerTargetId:t.followerTargetId}),t.phase=`timedOut`,t.followerTargetId){try{await e.attachToPage(t.followerTargetId),await QQ(e,t,`timeout`)}catch(e){Q.warn(`Could not attach to follower for timeout diagnostics`,{error:String(e)})}await $Q(t,`timeout`)}if(t$(t),t.followerTargetId)try{await e.closePage(t.followerTargetId)}catch(e){Q.warn(`Failed to close follower tab after timeout`,{error:String(e)})}t.rejectBlock?.(Error(`Teleport timed out after ${Math.round(t.timeoutMs/1e3)}s — human did not complete auth`))}function t$(e){Q.info(`Cleaning up teleport watcher`,{phase:e.phase,hadPoll:!!e.pollInterval,hadTimeout:!!e.timeoutTimer,hadListener:!!e.cleanupListener}),e.pollInterval&&=(clearInterval(e.pollInterval),void 0),e.timeoutTimer&&=(clearTimeout(e.timeoutTimer),void 0),e.cleanupListener&&=(e.cleanupListener(),void 0)}function n$(e,t,n,r,i,a,o,s){Q.info(`Arming teleport watcher`,{timeoutMs:i,runtimeSelection:a?`explicit`:`auto`}),Q.debug(`Arming teleport watcher details`,{startPattern:n.source,returnPattern:r.source,timeoutMs:i,runtimeId:a??`auto`,originalUrl:o});let c={startPattern:n,returnPattern:r,timeoutMs:i,runtimeId:a,phase:`armed`,leaderTargetId:s,originalLeaderUrl:o};return c.completionPromise=new Promise((e,t)=>{c.resolveBlock=e,c.rejectBlock=t}),c.completionPromise.catch(()=>{}),c.pollInterval=setInterval(async()=>{if(c.phase!==`armed`)return;let r=c.leaderTargetId;if(r)try{await e.attachToPage(r);let i=await e.evaluate(`window.location.href`),a=typeof i==`string`?i:String(i);Q.debug(`Polling leader tab URL`,{targetId:r,href:a,startPattern:n.source}),n.test(a)&&(Q.info(`Teleport start pattern matched on leader`),Q.debug(`Teleport start pattern matched on leader details`,{targetId:r,href:a,startPattern:n.source}),r$(e,t,c,a))}catch(e){Q.warn(`Error polling leader tab URL`,{targetId:r,error:String(e)})}},1e3),s&&t.teleportWatchers.set(s,c),c}async function r$(e,t,n,r){if(n.phase===`armed`){n.phase=`teleporting`,Q.info(`Teleport triggered`),Q.debug(`Teleport trigger details`,{triggerUrl:r}),n.pollInterval&&=(clearInterval(n.pollInterval),void 0);try{let i=[],a=BQ;try{i=(await e.sendCDP(`Network.getCookies`,{})).cookies??[],Q.info(`Captured leader cookies for follower`,{count:i.length})}catch(e){Q.warn(`Could not capture leader cookies`,{error:String(e)})}try{a=await GQ(e,`leader`),Q.info(`Captured leader storage for follower`,{totalEntries:VQ(a),localStorageCount:Object.keys(a.localStorage).length,sessionStorageCount:Object.keys(a.sessionStorage).length}),Q.debug(`Captured leader storage for follower details`,{origin:a.origin||`(unknown)`,localStorageCount:Object.keys(a.localStorage).length,sessionStorageCount:Object.keys(a.sessionStorage).length})}catch(e){Q.warn(`Could not capture leader storage`,{error:String(e)})}let o=n.runtimeId;if(!o){let e=dQ?.();if(!e)throw Error(`No follower selection available — not connected to a tray`);let t=e();if(!t)throw Error(`No followers connected to teleport to`);o=t.runtimeId}Q.info(`Selected follower for teleport`),Q.debug(`Selected follower for teleport details`,{runtimeId:o});let s=await e.createRemotePage(o,`about:blank`),c=s.includes(`:`)?s:`${o}:${s}`;if(n.followerTargetId=c,Q.info(`Opened follower tab for teleport`),Q.debug(`Opened follower tab for teleport details`,{followerTargetId:c}),await e.attachToPage(c),Q.info(`Attached to follower tab for teleport`),Q.debug(`Attached to follower tab for teleport details`,{followerTargetId:c}),await e.sendCDP(`Page.enable`),i.length>0)try{await e.sendCDP(`Network.setCookies`,{cookies:i}),Q.info(`Injected leader cookies into follower`,{count:i.length})}catch(e){Q.warn(`Could not inject leader cookies into follower`,{error:String(e)})}let l=r;n.removeFollowerStorageScript=await YQ(e,a,c,`follower`),Q.info(`Navigating follower to intercepted auth URL`),Q.debug(`Navigating follower to intercepted auth URL details`,{url:l,originalLeaderUrl:n.originalLeaderUrl,triggerUrl:r,storageOrigin:a.origin||`(unknown)`}),await e.sendCDP(`Page.navigate`,{url:l}),Q.info(`Starting teleport timeout timer`,{timeoutMs:n.timeoutMs}),n.timeoutTimer=setTimeout(()=>{(n.phase===`teleporting`||n.phase===`waitingForAuth`||n.phase===`waitingForReturn`)&&e$(e,n)},n.timeoutMs),n.phase=`waitingForAuth`,Q.info(`Teleport waiting for follower auth redirect`),Q.debug(`Teleport waiting for follower auth redirect details`,{startPattern:n.startPattern.source}),n.pollInterval=setInterval(async()=>{if(!(n.phase!==`waitingForAuth`&&n.phase!==`waitingForReturn`))try{await e.attachToPage(c);let r=await e.evaluate(`window.location.href`),i=typeof r==`string`?r:String(r);if(!i)return;if(n.lastFollowerUrl!==i&&(n.lastFollowerUrl=i,Q.debug(`Follower teleport navigation`,{href:i,phase:n.phase})),n.phase===`waitingForAuth`){n.startPattern.test(i)?(n.phase=`waitingForReturn`,Q.info(`Follower reached auth provider; waiting for return pattern`),Q.debug(`Follower reached auth provider details`,{href:i,startPattern:n.startPattern.source})):Q.debug(`Waiting for auth redirect on follower`,{href:i,startPattern:n.startPattern.source});return}Q.debug(`Polling follower tab URL for return`,{href:i,returnPattern:n.returnPattern.source}),ZQ(i)&&await QQ(e,n,`waiting-for-return`),n.returnPattern.test(i)&&(Q.info(`Follower return pattern matched after auth`),Q.debug(`Follower return pattern matched after auth details`,{href:i,returnPattern:n.returnPattern.source}),i$(e,t,n,o))}catch(e){Q.warn(`Error polling follower tab URL`,{error:String(e)})}},1e3)}catch(e){Q.error(`Teleport trigger failed`,{error:String(e)}),await $Q(n,`trigger-error`),n.phase=`done`,t$(n),n.rejectBlock?.(e instanceof Error?e:Error(String(e)))}}}async function i$(e,t,n,r){if(!(n.phase!==`teleporting`&&n.phase!==`waitingForReturn`)){n.phase=`capturing`,Q.info(`Capturing auth state from follower`),Q.debug(`Capturing auth state from follower details`,{followerTargetId:n.followerTargetId,runtimeId:r}),n.pollInterval&&=(clearInterval(n.pollInterval),void 0),n.timeoutTimer&&=(clearTimeout(n.timeoutTimer),void 0);try{Q.info(`Waiting for redirect chain to settle (2s)`),await new Promise(e=>setTimeout(e,2e3)),await e.attachToPage(n.followerTargetId);let t;try{let n=await e.evaluate(`window.location.href`);t=typeof n==`string`?n:String(n),Q.debug(`Captured final URL from follower`,{finalUrl:t})}catch(e){Q.warn(`Could not read follower URL (may be mid-navigation)`,{error:String(e)})}try{let t=await e.evaluate(`document.body?.innerText?.substring(0, 500) || "(empty)"`);Q.debug(`Follower page content at capture time`,{bodyText:t})}catch(e){Q.warn(`Could not read follower page content`,{error:String(e)})}let i=(await e.sendCDP(`Network.getCookies`)).cookies??[],a=i.length>0?zQ(i):`none`;Q.info(`Captured cookies from follower`,{count:i.length}),Q.debug(`Captured cookies from follower details`,{count:i.length,domains:a});let o=BQ;try{o=await GQ(e,`follower`),Q.info(`Captured follower storage for leader`,{totalEntries:VQ(o),localStorageCount:Object.keys(o.localStorage).length,sessionStorageCount:Object.keys(o.sessionStorage).length}),Q.debug(`Captured follower storage for leader details`,{origin:o.origin||`(unknown)`,localStorageCount:Object.keys(o.localStorage).length,sessionStorageCount:Object.keys(o.sessionStorage).length})}catch(e){Q.warn(`Could not capture follower storage`,{error:String(e)})}let s=VQ(o);await QQ(e,n,`capture`),await $Q(n,`capture`);try{await e.closePage(n.followerTargetId),Q.info(`Closed follower tab after teleport`),Q.debug(`Closed follower tab after teleport details`,{followerTargetId:n.followerTargetId})}catch(e){Q.warn(`Failed to close follower tab`,{error:String(e)})}let c=n.leaderTargetId,l=o.origin||``,u=WQ(l,n.originalLeaderUrl,t),d=HQ(n.originalLeaderUrl),f=!!l&&d!==l,p=f?UQ(l):null;if(c)if(await e.attachToPage(c),i.length>0&&(await e.sendCDP(`Network.setCookies`,{cookies:i}),Q.info(`Injected cookies into leader tab`,{count:i.length}),Q.debug(`Injected cookies into leader tab details`,{count:i.length,leaderTargetId:c})),f&&p){Q.info(`Hydrating leader storage origin before landing`,{storageEntries:s}),Q.debug(`Hydrating leader storage origin before landing details`,{hydrationUrl:p,landingUrl:u,originalLeaderUrl:n.originalLeaderUrl,finalUrl:t,leaderTargetId:c,storageOrigin:l,storageEntries:s});try{await e.navigate(p),await JQ(e,o,`leader`),u&&u!==p&&await e.navigate(u)}catch(t){Q.warn(`Direct leader origin hydration failed, falling back to init-script replay`,{error:String(t)}),Q.debug(`Direct leader origin hydration fallback details`,{hydrationUrl:p,landingUrl:u,error:String(t)});let n=await YQ(e,o,c,`leader`);try{u&&await e.navigate(u)}finally{await n?.()}}}else{let r=await YQ(e,o,c,`leader`);try{u&&(Q.info(`Navigating leader after auth-state injection`,{hasLandingUrl:!0,storageEntries:s}),Q.debug(`Navigating leader after auth-state injection details`,{landingUrl:u,originalLeaderUrl:n.originalLeaderUrl,finalUrl:t,leaderTargetId:c,storageOrigin:o.origin||`(unknown)`,storageEntries:s}),await e.navigate(u))}finally{await r?.()}}else Q.warn(`No leader tab available for auth-state injection`);n.phase=`done`,t$(n);let m=i.length>0?` (${zQ(i)})`:``,h=s>0?` + ${s} storage entr${s===1?`y`:`ies`}`:``,g=u?` (navigated to ${u})`:``,_=`Teleported ${i.length} cookie(s)${m}${h} from ${r}${g}`;Q.info(`Teleport completed successfully`,{cookieCount:i.length,storageEntries:s,landed:!!u}),Q.debug(`Teleport completed successfully details`,{result:_}),n.resolveBlock?.(_)}catch(e){Q.error(`Teleport auth-state capture failed`,{error:String(e)}),await $Q(n,`capture-error`),n.phase=`done`,t$(n),n.rejectBlock?.(e instanceof Error?e:Error(String(e)))}}}function a$(e){return`Usage: ${e} <command> [args...]
3477
3477
 
3478
3478
  Commands:
3479
3479
  open [url|/vfs/path] [--foreground|--fg] [--runtime=<id>]
@@ -3548,20 +3548,20 @@ Commands:
3548
3548
  sessionstorage-clear Clear all sessionStorage
3549
3549
  help Show this help message
3550
3550
 
3551
- Aliases: ${mQ.filter(t=>t!==e).join(`, `)}`}var r$=new Set([`tab`,`filename`,`max-width`,`runtime`,`timeout`,`filter`,`output`,`start`,`return`,`teleport-start`,`teleport-return`,`teleport-runtime`,`domain`,`path`,`expires`]);function i$(e){let t=[],n={};for(let r=0;r<e.length;r++){let i=e[r];if(i.startsWith(`--`)&&i.includes(`=`)){let e=i.indexOf(`=`);n[i.slice(2,e)]=i.slice(e+1)}else if(i.startsWith(`--`)){let t=i.slice(2);if(r$.has(t))if(r+1<e.length&&!e[r+1].startsWith(`--`))n[t]=e[++r];else throw Error(`--${t} requires a value`);else n[t]=`true`}else t.push(i)}return{positional:t,flags:n}}function a$(e){let t=e.tab;return t?{targetId:t}:{error:`Error: --tab <targetId> is required. Run 'playwright-cli tab-list' to get tab IDs.
3552
- `}}function o$(e,t,n){let r=n$(e),i=t?vQ(t,n):null;return gR(e,async a=>{if(a.length===0||a[0]===`help`||a[0]===`--help`||a[0]===`-h`)return{stdout:r+`
3553
- `,stderr:``,exitCode:0};if(!t||!i)return{stdout:``,stderr:`${e}: browser APIs are unavailable in this environment\n`,exitCode:1};let o=a[0],s=a.slice(1),c,l;try{({positional:c,flags:l}=i$(s))}catch(t){return{stdout:``,stderr:`${e} ${o}: ${t instanceof Error?t.message:String(t)}\n`,exitCode:1}}let u;try{switch(o){case`teleport`:{if(l.list===`true`){Q.info(`Listing available follower runtimes`);let e=lQ?.();if(!e){u={stdout:``,stderr:`teleport: not connected to a tray
3551
+ Aliases: ${_Q.filter(t=>t!==e).join(`, `)}`}var o$=new Set([`tab`,`filename`,`max-width`,`runtime`,`timeout`,`filter`,`output`,`start`,`return`,`teleport-start`,`teleport-return`,`teleport-runtime`,`domain`,`path`,`expires`]);function s$(e){let t=[],n={};for(let r=0;r<e.length;r++){let i=e[r];if(i.startsWith(`--`)&&i.includes(`=`)){let e=i.indexOf(`=`);n[i.slice(2,e)]=i.slice(e+1)}else if(i.startsWith(`--`)){let t=i.slice(2);if(o$.has(t))if(r+1<e.length&&!e[r+1].startsWith(`--`))n[t]=e[++r];else throw Error(`--${t} requires a value`);else n[t]=`true`}else t.push(i)}return{positional:t,flags:n}}function c$(e){let t=e.tab;return t?{targetId:t}:{error:`Error: --tab <targetId> is required. Run 'playwright-cli tab-list' to get tab IDs.
3552
+ `}}function l$(e,t,n){let r=a$(e),i=t?xQ(t,n):null;return gR(e,async a=>{if(a.length===0||a[0]===`help`||a[0]===`--help`||a[0]===`-h`)return{stdout:r+`
3553
+ `,stderr:``,exitCode:0};if(!t||!i)return{stdout:``,stderr:`${e}: browser APIs are unavailable in this environment\n`,exitCode:1};let o=a[0],s=a.slice(1),c,l;try{({positional:c,flags:l}=s$(s))}catch(t){return{stdout:``,stderr:`${e} ${o}: ${t instanceof Error?t.message:String(t)}\n`,exitCode:1}}let u;try{switch(o){case`teleport`:{if(l.list===`true`){Q.info(`Listing available follower runtimes`);let e=fQ?.();if(!e){u={stdout:``,stderr:`teleport: not connected to a tray
3554
3554
  `,exitCode:1};break}let t=e();if(t.length===0){u={stdout:`No followers connected to the tray.
3555
3555
  `,stderr:``,exitCode:0};break}let n=[`Available runtimes for teleport:`];for(let e of t){let t=[e.runtimeId];if(e.floatType&&t.push(`[${e.floatType}]`),e.runtime&&t.push(`(${e.runtime})`),e.lastActivity){let n=Math.round((Date.now()-e.lastActivity)/1e3);t.push(`active ${n}s ago`)}n.push(` ${t.join(` `)}`)}u={stdout:n.join(`
3556
3556
  `)+`
3557
- `,stderr:``,exitCode:0};break}if(l.off===`true`){let e=a$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}Q.info(`Disarming teleport watcher via --off`,{targetId:e.targetId});let t=i.teleportWatchers.get(e.targetId);t&&(QQ(t),i.teleportWatchers.delete(e.targetId)),u={stdout:`Teleport watcher disarmed
3558
- `,stderr:``,exitCode:0};break}let e=a$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}let n=l.start||l[`teleport-start`],r=l.return||l[`teleport-return`];if(!n||!r){u={stdout:``,stderr:`teleport requires --start <regex> and --return <regex>
3557
+ `,stderr:``,exitCode:0};break}if(l.off===`true`){let e=c$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}Q.info(`Disarming teleport watcher via --off`,{targetId:e.targetId});let t=i.teleportWatchers.get(e.targetId);t&&(t$(t),i.teleportWatchers.delete(e.targetId)),u={stdout:`Teleport watcher disarmed
3558
+ `,stderr:``,exitCode:0};break}let e=c$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}let n=l.start||l[`teleport-start`],r=l.return||l[`teleport-return`];if(!n||!r){u={stdout:``,stderr:`teleport requires --start <regex> and --return <regex>
3559
3559
  `,exitCode:1};break}let a,o;try{a=new RegExp(n)}catch{u={stdout:``,stderr:`Invalid regex for --start: ${n}\n`,exitCode:1};break}try{o=new RegExp(r)}catch{u={stdout:``,stderr:`Invalid regex for --return: ${r}\n`,exitCode:1};break}let s=l.timeout?parseInt(l.timeout,10):300;if(isNaN(s)||s<=0){u={stdout:``,stderr:`--timeout must be a positive number
3560
- `,exitCode:1};break}let c=l.runtime,d=i.teleportWatchers.get(e.targetId);d&&(Q.info(`Disarming existing teleport watcher before re-arming`,{targetId:e.targetId}),QQ(d),i.teleportWatchers.delete(e.targetId));let f;try{await t.attachToPage(e.targetId);let n=await t.evaluate(`window.location.href`);f=typeof n==`string`?n:String(n)}catch{}Q.info(`Arming teleport via explicit subcommand`,{targetId:e.targetId,timeoutSec:s,runtimeSelection:c?`explicit`:`auto`}),Q.debug(`Arming teleport via explicit subcommand details`,{targetId:e.targetId,startPattern:n,returnPattern:r,timeoutSec:s,runtimeId:c??`auto`,leaderUrl:f}),$Q(t,i,a,o,s*1e3,c,f,e.targetId),u={stdout:`Teleport armed on tab ${e.targetId}. Will trigger when URL matches ${n}\n`,stderr:``,exitCode:0};break}case`open`:case`tab-new`:{let e=c[0]||`about:blank`,n=l.runtime;await AQ(t,i);let r;r=n?await t.createRemotePage(n,e):await t.createPage(e);let a=l[`teleport-start`],o=l[`teleport-return`];if(a&&o){Q.info(`Arming teleport via open/tab-new flags`),Q.debug(`Arming teleport via open/tab-new flags details`,{targetId:r,startPattern:a,returnPattern:o});let n,s;try{n=new RegExp(a)}catch{u={stdout:``,stderr:`Invalid regex for --teleport-start: ${a}\n`,exitCode:1};break}try{s=new RegExp(o)}catch{u={stdout:``,stderr:`Invalid regex for --teleport-return: ${o}\n`,exitCode:1};break}let c=l.timeout?parseInt(l.timeout,10):300,d=i.teleportWatchers.get(r);d&&(QQ(d),i.teleportWatchers.delete(r)),$Q(t,i,n,s,c*1e3,l[`teleport-runtime`],e,r)}u={stdout:`Opened ${e} in new tab [targetId: ${r}]\n`,stderr:``,exitCode:0};break}case`goto`:case`navigate`:{if(c.length===0){u={stdout:``,stderr:`goto requires a URL
3561
- `,exitCode:1};break}let e=a$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}await t.withTab(e.targetId,async()=>(await t.navigate(c[0]),!0)),i.snapshots.delete(e.targetId);let n=l[`teleport-start`],r=l[`teleport-return`];if(n&&r){Q.info(`Arming teleport via goto/navigate flags`),Q.debug(`Arming teleport via goto/navigate flags details`,{targetId:e.targetId,startPattern:n,returnPattern:r});let a,o;try{a=new RegExp(n)}catch{u={stdout:``,stderr:`Invalid regex for --teleport-start: ${n}\n`,exitCode:1};break}try{o=new RegExp(r)}catch{u={stdout:``,stderr:`Invalid regex for --teleport-return: ${r}\n`,exitCode:1};break}let s=l.timeout?parseInt(l.timeout,10):300,d=i.teleportWatchers.get(e.targetId);d&&(QQ(d),i.teleportWatchers.delete(e.targetId)),$Q(t,i,a,o,s*1e3,l[`teleport-runtime`],c[0],e.targetId)}u={stdout:`Navigated to ${c[0]}\n`,stderr:``,exitCode:0};break}case`snapshot`:{let e=a$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}let r=l[`no-iframes`]===`true`,{output:a}=await t.withTab(e.targetId,async()=>await FQ(t,i,e.targetId,{noIframes:r}));if(l.filename){await n.writeFile(l.filename,a),u={stdout:`Snapshot saved to ${l.filename}\n`,stderr:``,exitCode:0};break}u={stdout:a+`
3562
- `,stderr:``,exitCode:0};break}case`frames`:{let e=a$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}u={stdout:await t.withTab(e.targetId,async()=>`Frames in current tab:\n${(await t.getFrameTree()).map(e=>{let t=e.parentFrameId?`child`:`main`,n=e.parentFrameId?` (parent: ${e.parentFrameId})`:``;return` [${t}] ${e.frameId}${n} - ${e.url}`}).join(`
3560
+ `,exitCode:1};break}let c=l.runtime,d=i.teleportWatchers.get(e.targetId);d&&(Q.info(`Disarming existing teleport watcher before re-arming`,{targetId:e.targetId}),t$(d),i.teleportWatchers.delete(e.targetId));let f;try{await t.attachToPage(e.targetId);let n=await t.evaluate(`window.location.href`);f=typeof n==`string`?n:String(n)}catch{}Q.info(`Arming teleport via explicit subcommand`,{targetId:e.targetId,timeoutSec:s,runtimeSelection:c?`explicit`:`auto`}),Q.debug(`Arming teleport via explicit subcommand details`,{targetId:e.targetId,startPattern:n,returnPattern:r,timeoutSec:s,runtimeId:c??`auto`,leaderUrl:f}),n$(t,i,a,o,s*1e3,c,f,e.targetId),u={stdout:`Teleport armed on tab ${e.targetId}. Will trigger when URL matches ${n}\n`,stderr:``,exitCode:0};break}case`open`:case`tab-new`:{let e=c[0]||`about:blank`,n=l.runtime;await NQ(t,i);let r;r=n?await t.createRemotePage(n,e):await t.createPage(e);let a=l[`teleport-start`],o=l[`teleport-return`];if(a&&o){Q.info(`Arming teleport via open/tab-new flags`),Q.debug(`Arming teleport via open/tab-new flags details`,{targetId:r,startPattern:a,returnPattern:o});let n,s;try{n=new RegExp(a)}catch{u={stdout:``,stderr:`Invalid regex for --teleport-start: ${a}\n`,exitCode:1};break}try{s=new RegExp(o)}catch{u={stdout:``,stderr:`Invalid regex for --teleport-return: ${o}\n`,exitCode:1};break}let c=l.timeout?parseInt(l.timeout,10):300,d=i.teleportWatchers.get(r);d&&(t$(d),i.teleportWatchers.delete(r)),n$(t,i,n,s,c*1e3,l[`teleport-runtime`],e,r)}u={stdout:`Opened ${e} in new tab [targetId: ${r}]\n`,stderr:``,exitCode:0};break}case`goto`:case`navigate`:{if(c.length===0){u={stdout:``,stderr:`goto requires a URL
3561
+ `,exitCode:1};break}let e=c$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}await t.withTab(e.targetId,async()=>(await t.navigate(c[0]),!0)),i.snapshots.delete(e.targetId);let n=l[`teleport-start`],r=l[`teleport-return`];if(n&&r){Q.info(`Arming teleport via goto/navigate flags`),Q.debug(`Arming teleport via goto/navigate flags details`,{targetId:e.targetId,startPattern:n,returnPattern:r});let a,o;try{a=new RegExp(n)}catch{u={stdout:``,stderr:`Invalid regex for --teleport-start: ${n}\n`,exitCode:1};break}try{o=new RegExp(r)}catch{u={stdout:``,stderr:`Invalid regex for --teleport-return: ${r}\n`,exitCode:1};break}let s=l.timeout?parseInt(l.timeout,10):300,d=i.teleportWatchers.get(e.targetId);d&&(t$(d),i.teleportWatchers.delete(e.targetId)),n$(t,i,a,o,s*1e3,l[`teleport-runtime`],c[0],e.targetId)}u={stdout:`Navigated to ${c[0]}\n`,stderr:``,exitCode:0};break}case`snapshot`:{let e=c$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}let r=l[`no-iframes`]===`true`,{output:a}=await t.withTab(e.targetId,async()=>await RQ(t,i,e.targetId,{noIframes:r}));if(l.filename){await n.writeFile(l.filename,a),u={stdout:`Snapshot saved to ${l.filename}\n`,stderr:``,exitCode:0};break}u={stdout:a+`
3562
+ `,stderr:``,exitCode:0};break}case`frames`:{let e=c$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}u={stdout:await t.withTab(e.targetId,async()=>`Frames in current tab:\n${(await t.getFrameTree()).map(e=>{let t=e.parentFrameId?`child`:`main`,n=e.parentFrameId?` (parent: ${e.parentFrameId})`:``;return` [${t}] ${e.frameId}${n} - ${e.url}`}).join(`
3563
3563
  `)}`)+`
3564
- `,stderr:``,exitCode:0};break}case`screenshot`:{let e=a$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}u={stdout:await t.withTab(e.targetId,async()=>{let r;if(c[0]&&c[0].startsWith(`e`)){let n=i.snapshots.get(e.targetId);if(!n)throw Error(`No snapshot available. Run "snapshot" first.`);let a=n.refToBackendNodeId.get(c[0]);if(a){let e=t.getTransport(),n=t.getSessionId();await e.send(`DOM.enable`,{},n),await e.send(`Runtime.enable`,{},n);let i=(await e.send(`DOM.resolveNode`,{backendNodeId:a},n)).object;if(i?.objectId){let t=(await e.send(`Runtime.callFunctionOn`,{objectId:i.objectId,functionDeclaration:`function() {
3564
+ `,stderr:``,exitCode:0};break}case`screenshot`:{let e=c$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}u={stdout:await t.withTab(e.targetId,async()=>{let r;if(c[0]&&c[0].startsWith(`e`)){let n=i.snapshots.get(e.targetId);if(!n)throw Error(`No snapshot available. Run "snapshot" first.`);let a=n.refToBackendNodeId.get(c[0]);if(a){let e=t.getTransport(),n=t.getSessionId();await e.send(`DOM.enable`,{},n),await e.send(`Runtime.enable`,{},n);let i=(await e.send(`DOM.resolveNode`,{backendNodeId:a},n)).object;if(i?.objectId){let t=(await e.send(`Runtime.callFunctionOn`,{objectId:i.objectId,functionDeclaration:`function() {
3565
3565
  this.scrollIntoView({ block: 'center' });
3566
3566
  const r = this.getBoundingClientRect();
3567
3567
  return { x: r.x + window.scrollX, y: r.y + window.scrollY, width: r.width, height: r.height };
@@ -3571,17 +3571,17 @@ Aliases: ${mQ.filter(t=>t!==e).join(`, `)}`}var r$=new Set([`tab`,`filename`,`ma
3571
3571
  el.scrollIntoView({ block: 'center' });
3572
3572
  const r = el.getBoundingClientRect();
3573
3573
  return JSON.stringify({ x: r.x + window.scrollX, y: r.y + window.scrollY, width: r.width, height: r.height });
3574
- })()`);i&&(r=JSON.parse(i))}}let a=l[`max-width`]?parseInt(l[`max-width`],10):void 0,o=await t.screenshot({fullPage:l.fullPage===`true`,...r?{clip:r}:{},...a?{maxWidth:a}:{}}),s=l.filename||`/tmp/screenshot-${Date.now()}.png`,u=pQ(o);await n.writeFile(s,u);try{await wQ(n,i);let e=`/.playwright/screenshots/screenshot-${_Q(new Date)}.png`;await n.writeFile(e,u)}catch{}return`Screenshot saved to ${s} (${Math.round(u.length/1024)} KB)`})+`
3574
+ })()`);i&&(r=JSON.parse(i))}}let a=l[`max-width`]?parseInt(l[`max-width`],10):void 0,o=await t.screenshot({fullPage:l.fullPage===`true`,...r?{clip:r}:{},...a?{maxWidth:a}:{}}),s=l.filename||`/tmp/screenshot-${Date.now()}.png`,u=gQ(o);await n.writeFile(s,u);try{await DQ(n,i);let e=`/.playwright/screenshots/screenshot-${bQ(new Date)}.png`;await n.writeFile(e,u)}catch{}return`Screenshot saved to ${s} (${Math.round(u.length/1024)} KB)`})+`
3575
3575
  `,stderr:``,exitCode:0};break}case`click`:{if(c.length===0){u={stdout:``,stderr:`click requires a ref (e.g. e5)
3576
- `,exitCode:1};break}let e=a$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}let n=c[0];u={stdout:await t.withTab(e.targetId,async()=>{let r=i.snapshots.get(e.targetId);if(!r)throw Error(`No snapshot available. Run "snapshot" first.`);let{isIframe:a}=fQ(n),o=r.refToFrameId?.get(n);if(a&&o){let a=r.refToSelector.get(n);if(!a)throw Error(`Unknown ref "${n}" in iframe`);let s=a.split(`,`)[0].trim();return await t.evaluateInFrame(o,`(function() {
3576
+ `,exitCode:1};break}let e=c$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}let n=c[0];u={stdout:await t.withTab(e.targetId,async()=>{let r=i.snapshots.get(e.targetId);if(!r)throw Error(`No snapshot available. Run "snapshot" first.`);let{isIframe:a}=hQ(n),o=r.refToFrameId?.get(n);if(a&&o){let a=r.refToSelector.get(n);if(!a)throw Error(`Unknown ref "${n}" in iframe`);let s=a.split(`,`)[0].trim();return await t.evaluateInFrame(o,`(function() {
3577
3577
  var el = document.querySelector(${JSON.stringify(s)});
3578
3578
  if (!el) throw new Error('Element not found in iframe for ref ${n}');
3579
3579
  el.scrollIntoView({ block: 'center' });
3580
3580
  el.click();
3581
3581
  })()`),i.snapshots.delete(e.targetId),`Clicked ${n} (in iframe)`}let s=r.refToBackendNodeId.get(n);if(s)return await t.clickByBackendNodeId(s),i.snapshots.delete(e.targetId),`Clicked ${n}`;let c=r.refToSelector.get(n);if(!c)throw Error(`Unknown ref "${n}". Available: ${[...r.refToSelector.keys()].slice(0,10).join(`, `)}...`);return await t.click(c),i.snapshots.delete(e.targetId),`Clicked ${n}`})+`
3582
3582
  `,stderr:``,exitCode:0};break}case`type`:{if(c.length===0){u={stdout:``,stderr:`type requires text
3583
- `,exitCode:1};break}let e=a$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}let n=c.join(` `);await t.withTab(e.targetId,async()=>{await t.type(n)}),u={stdout:`Typed: ${n}\n`,stderr:``,exitCode:0};break}case`fill`:{if(c.length<2){u={stdout:``,stderr:`fill requires <ref> <text>
3584
- `,exitCode:1};break}let e=a$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}let n=c[0],r=c.slice(1).join(` `);u={stdout:await t.withTab(e.targetId,async()=>{let a=i.snapshots.get(e.targetId);if(!a)throw Error(`No snapshot available. Run "snapshot" first.`);let{isIframe:o}=fQ(n),s=a.refToFrameId?.get(n);if(o&&s){let o=a.refToSelector.get(n);if(!o)throw Error(`Unknown ref "${n}" in iframe`);let c=o.split(`,`)[0].trim();return await t.evaluateInFrame(s,`(function() {
3583
+ `,exitCode:1};break}let e=c$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}let n=c.join(` `);await t.withTab(e.targetId,async()=>{await t.type(n)}),u={stdout:`Typed: ${n}\n`,stderr:``,exitCode:0};break}case`fill`:{if(c.length<2){u={stdout:``,stderr:`fill requires <ref> <text>
3584
+ `,exitCode:1};break}let e=c$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}let n=c[0],r=c.slice(1).join(` `);u={stdout:await t.withTab(e.targetId,async()=>{let a=i.snapshots.get(e.targetId);if(!a)throw Error(`No snapshot available. Run "snapshot" first.`);let{isIframe:o}=hQ(n),s=a.refToFrameId?.get(n);if(o&&s){let o=a.refToSelector.get(n);if(!o)throw Error(`Unknown ref "${n}" in iframe`);let c=o.split(`,`)[0].trim();return await t.evaluateInFrame(s,`(function() {
3585
3585
  var el = document.querySelector(${JSON.stringify(c)});
3586
3586
  if (!el) throw new Error('Element not found in iframe for ref ${n}');
3587
3587
  el.scrollIntoView({ block: 'center' });
@@ -3590,55 +3590,55 @@ Aliases: ${mQ.filter(t=>t!==e).join(`, `)}`}var r$=new Set([`tab`,`filename`,`ma
3590
3590
  el.value = ${JSON.stringify(r)};
3591
3591
  el.dispatchEvent(new Event('input', { bubbles: true }));
3592
3592
  el.dispatchEvent(new Event('change', { bubbles: true }));
3593
- })()`),i.snapshots.delete(e.targetId),`Filled ${n} with: ${r} (in iframe)`}let c=a.refToBackendNodeId.get(n);if(c){await t.clickByBackendNodeId(c);let a=t.getTransport(),o=t.getSessionId();await a.send(`DOM.enable`,{},o),await a.send(`Runtime.enable`,{},o);let s=(await a.send(`DOM.resolveNode`,{backendNodeId:c},o)).object;return s?.objectId&&await a.send(`Runtime.callFunctionOn`,{objectId:s.objectId,functionDeclaration:SQ,returnByValue:!0},o),await t.type(r),s?.objectId&&((await a.send(`Runtime.callFunctionOn`,{objectId:s.objectId,functionDeclaration:xQ,returnByValue:!0},o)).result?.value??``)!==r&&await a.send(`Runtime.callFunctionOn`,{objectId:s.objectId,functionDeclaration:bQ,arguments:[{value:r}],returnByValue:!0},o),i.snapshots.delete(e.targetId),`Filled ${n} with: ${r}`}let l=a.refToSelector.get(n);if(!l)throw Error(`Unknown ref "${n}"`);return await t.click(l),await t.evaluate(`(function() {
3593
+ })()`),i.snapshots.delete(e.targetId),`Filled ${n} with: ${r} (in iframe)`}let c=a.refToBackendNodeId.get(n);if(c){await t.clickByBackendNodeId(c);let a=t.getTransport(),o=t.getSessionId();await a.send(`DOM.enable`,{},o),await a.send(`Runtime.enable`,{},o);let s=(await a.send(`DOM.resolveNode`,{backendNodeId:c},o)).object;return s?.objectId&&await a.send(`Runtime.callFunctionOn`,{objectId:s.objectId,functionDeclaration:TQ,returnByValue:!0},o),await t.type(r),s?.objectId&&((await a.send(`Runtime.callFunctionOn`,{objectId:s.objectId,functionDeclaration:wQ,returnByValue:!0},o)).result?.value??``)!==r&&await a.send(`Runtime.callFunctionOn`,{objectId:s.objectId,functionDeclaration:CQ,arguments:[{value:r}],returnByValue:!0},o),i.snapshots.delete(e.targetId),`Filled ${n} with: ${r}`}let l=a.refToSelector.get(n);if(!l)throw Error(`Unknown ref "${n}"`);return await t.click(l),await t.evaluate(`(function() {
3594
3594
  const el = document.querySelector(${JSON.stringify(l)});
3595
3595
  if (el) {
3596
- return (${SQ}).call(el);
3596
+ return (${TQ}).call(el);
3597
3597
  }
3598
3598
  return false;
3599
3599
  })()`),await t.type(r),await t.evaluate(`(function() {
3600
3600
  const el = document.querySelector(${JSON.stringify(l.split(`,`)[0].trim())});
3601
3601
  if (!el) return '';
3602
- return (${xQ}).call(el);
3602
+ return (${wQ}).call(el);
3603
3603
  })()`)!==r&&await t.evaluate(`(function() {
3604
3604
  const el = document.querySelector(${JSON.stringify(l.split(`,`)[0].trim())});
3605
3605
  if (!el) return;
3606
- (${bQ}).call(el, ${JSON.stringify(r)});
3606
+ (${CQ}).call(el, ${JSON.stringify(r)});
3607
3607
  })()`),i.snapshots.delete(e.targetId),`Filled ${n} with: ${r}`})+`
3608
3608
  `,stderr:``,exitCode:0};break}case`eval`:{if(c.length===0){u={stdout:``,stderr:`eval requires an expression
3609
- `,exitCode:1};break}let e=a$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}let n=c.join(` `);u={stdout:(await t.withTab(e.targetId,async()=>{let e=await t.evaluate(n);return typeof e==`string`?e:JSON.stringify(e,null,2)})??`undefined`)+`
3609
+ `,exitCode:1};break}let e=c$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}let n=c.join(` `);u={stdout:(await t.withTab(e.targetId,async()=>{let e=await t.evaluate(n);return typeof e==`string`?e:JSON.stringify(e,null,2)})??`undefined`)+`
3610
3610
  `,stderr:``,exitCode:0};break}case`eval-file`:{if(c.length===0){u={stdout:``,stderr:`eval-file requires a file path
3611
- `,exitCode:1};break}let e=a$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}let r=c[0],i=l.output,a;try{a=await n.readTextFile(r)}catch(e){u={stdout:``,stderr:`eval-file: cannot read ${r}: ${e instanceof Error?e.message:String(e)}\n`,exitCode:1};break}let o=await t.withTab(e.targetId,async()=>{let e=await t.evaluate(a);return typeof e==`string`?e:JSON.stringify(e,null,2)});if(i){let e=o??`null`;await n.writeFile(i,e),u={stdout:`Result saved to ${i} (${Math.round(new TextEncoder().encode(e).length/1024)} KB)\n`,stderr:``,exitCode:0}}else u={stdout:(o??`undefined`)+`
3611
+ `,exitCode:1};break}let e=c$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}let r=c[0],i=l.output,a;try{a=await n.readTextFile(r)}catch(e){u={stdout:``,stderr:`eval-file: cannot read ${r}: ${e instanceof Error?e.message:String(e)}\n`,exitCode:1};break}let o=await t.withTab(e.targetId,async()=>{let e=await t.evaluate(a);return typeof e==`string`?e:JSON.stringify(e,null,2)});if(i){let e=o??`null`;await n.writeFile(i,e),u={stdout:`Result saved to ${i} (${Math.round(new TextEncoder().encode(e).length/1024)} KB)\n`,stderr:``,exitCode:0}}else u={stdout:(o??`undefined`)+`
3612
3612
  `,stderr:``,exitCode:0};break}case`press`:{if(c.length===0){u={stdout:``,stderr:`press requires a key name
3613
- `,exitCode:1};break}let e=a$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}let n=c[0];await t.withTab(e.targetId,async()=>{let e=t.getTransport(),r=t.getSessionId();await e.send(`Input.dispatchKeyEvent`,{type:`keyDown`,key:n},r),await e.send(`Input.dispatchKeyEvent`,{type:`keyUp`,key:n},r)}),u={stdout:`Pressed ${n}\n`,stderr:``,exitCode:0};break}case`go-back`:{let e=a$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}await t.withTab(e.targetId,async()=>{await t.evaluate(`history.back()`)}),i.snapshots.delete(e.targetId),u={stdout:`Navigated back
3614
- `,stderr:``,exitCode:0};break}case`go-forward`:{let e=a$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}await t.withTab(e.targetId,async()=>{await t.evaluate(`history.forward()`)}),i.snapshots.delete(e.targetId),u={stdout:`Navigated forward
3615
- `,stderr:``,exitCode:0};break}case`reload`:{let e=a$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}await t.withTab(e.targetId,async()=>{await t.sendCDP(`Page.reload`)}),u={stdout:`Reloaded
3616
- `,stderr:``,exitCode:0};break}case`tab-list`:{let e=await PQ(t,i);if(e.length===0){u={stdout:`No tabs open
3613
+ `,exitCode:1};break}let e=c$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}let n=c[0];await t.withTab(e.targetId,async()=>{let e=t.getTransport(),r=t.getSessionId();await e.send(`Input.dispatchKeyEvent`,{type:`keyDown`,key:n},r),await e.send(`Input.dispatchKeyEvent`,{type:`keyUp`,key:n},r)}),u={stdout:`Pressed ${n}\n`,stderr:``,exitCode:0};break}case`go-back`:{let e=c$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}await t.withTab(e.targetId,async()=>{await t.evaluate(`history.back()`)}),i.snapshots.delete(e.targetId),u={stdout:`Navigated back
3614
+ `,stderr:``,exitCode:0};break}case`go-forward`:{let e=c$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}await t.withTab(e.targetId,async()=>{await t.evaluate(`history.forward()`)}),i.snapshots.delete(e.targetId),u={stdout:`Navigated forward
3615
+ `,stderr:``,exitCode:0};break}case`reload`:{let e=c$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}await t.withTab(e.targetId,async()=>{await t.sendCDP(`Page.reload`)}),u={stdout:`Reloaded
3616
+ `,stderr:``,exitCode:0};break}case`tab-list`:{let e=await LQ(t,i);if(e.length===0){u={stdout:`No tabs open
3617
3617
  `,stderr:``,exitCode:0};break}u={stdout:e.map(e=>{let t=!!e.active,n=e.targetId.includes(`:`),r=t?` (active)`:``,i=n?` [remote:${e.targetId.substring(0,e.targetId.indexOf(`:`))}]`:``;return`[${e.targetId}] ${e.url} "${e.title}"${r}${i}`}).join(`
3618
3618
  `)+`
3619
- `,stderr:``,exitCode:0};break}case`tab-close`:case`close`:{let e=a$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}await t.closePage(e.targetId),i.snapshots.delete(e.targetId),i.teleportWatchers.delete(e.targetId),u={stdout:`Closed tab ${e.targetId}\n`,stderr:``,exitCode:0};break}case`dblclick`:{if(c.length===0){u={stdout:``,stderr:`dblclick requires a ref (e.g. e5)
3620
- `,exitCode:1};break}let e=a$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}let n=c[0],r=c[1]||`left`;u={stdout:await t.withTab(e.targetId,async()=>{let a=i.snapshots.get(e.targetId);if(!a)throw Error(`No snapshot available. Run "snapshot" first.`);let{isIframe:o}=fQ(n),s=a.refToFrameId?.get(n);if(o&&s){let r=a.refToSelector.get(n);if(!r)throw Error(`Unknown ref "${n}" in iframe`);let o=r.split(`,`)[0].trim();return await t.evaluateInFrame(s,`(function() {
3619
+ `,stderr:``,exitCode:0};break}case`tab-close`:case`close`:{let e=c$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}await t.closePage(e.targetId),i.snapshots.delete(e.targetId),i.teleportWatchers.delete(e.targetId),u={stdout:`Closed tab ${e.targetId}\n`,stderr:``,exitCode:0};break}case`dblclick`:{if(c.length===0){u={stdout:``,stderr:`dblclick requires a ref (e.g. e5)
3620
+ `,exitCode:1};break}let e=c$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}let n=c[0],r=c[1]||`left`;u={stdout:await t.withTab(e.targetId,async()=>{let a=i.snapshots.get(e.targetId);if(!a)throw Error(`No snapshot available. Run "snapshot" first.`);let{isIframe:o}=hQ(n),s=a.refToFrameId?.get(n);if(o&&s){let r=a.refToSelector.get(n);if(!r)throw Error(`Unknown ref "${n}" in iframe`);let o=r.split(`,`)[0].trim();return await t.evaluateInFrame(s,`(function() {
3621
3621
  var el = document.querySelector(${JSON.stringify(o)});
3622
3622
  if (!el) throw new Error('Element not found in iframe for ref ${n}');
3623
3623
  el.scrollIntoView({ block: 'center' });
3624
3624
  el.dispatchEvent(new MouseEvent('dblclick', { bubbles: true }));
3625
3625
  })()`),i.snapshots.delete(e.targetId),`Double-clicked ${n} (in iframe)`}let c=a.refToBackendNodeId.get(n);if(!c)throw Error(`Unknown ref "${n}"`);return await t.dblclickByBackendNodeId(c,r),i.snapshots.delete(e.targetId),`Double-clicked ${n}`})+`
3626
3626
  `,stderr:``,exitCode:0};break}case`hover`:{if(c.length===0){u={stdout:``,stderr:`hover requires a ref (e.g. e5)
3627
- `,exitCode:1};break}let e=a$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}let n=c[0];u={stdout:await t.withTab(e.targetId,async()=>{let r=i.snapshots.get(e.targetId);if(!r)throw Error(`No snapshot available. Run "snapshot" first.`);let{isIframe:a}=fQ(n),o=r.refToFrameId?.get(n);if(a&&o){let e=r.refToSelector.get(n);if(!e)throw Error(`Unknown ref "${n}" in iframe`);let i=e.split(`,`)[0].trim();return await t.evaluateInFrame(o,`(function() {
3627
+ `,exitCode:1};break}let e=c$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}let n=c[0];u={stdout:await t.withTab(e.targetId,async()=>{let r=i.snapshots.get(e.targetId);if(!r)throw Error(`No snapshot available. Run "snapshot" first.`);let{isIframe:a}=hQ(n),o=r.refToFrameId?.get(n);if(a&&o){let e=r.refToSelector.get(n);if(!e)throw Error(`Unknown ref "${n}" in iframe`);let i=e.split(`,`)[0].trim();return await t.evaluateInFrame(o,`(function() {
3628
3628
  var el = document.querySelector(${JSON.stringify(i)});
3629
3629
  if (!el) throw new Error('Element not found in iframe for ref ${n}');
3630
3630
  el.scrollIntoView({ block: 'center' });
3631
3631
  el.dispatchEvent(new MouseEvent('mouseover', { bubbles: true }));
3632
3632
  })()`),`Hovered ${n} (in iframe)`}let s=r.refToBackendNodeId.get(n);if(!s)throw Error(`Unknown ref "${n}"`);return await t.hoverByBackendNodeId(s),`Hovered ${n}`})+`
3633
3633
  `,stderr:``,exitCode:0};break}case`select`:{if(c.length<2){u={stdout:``,stderr:`select requires <ref> <value>
3634
- `,exitCode:1};break}let e=a$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}let n=c[0],r=c.slice(1).join(` `);u={stdout:await t.withTab(e.targetId,async()=>{let a=i.snapshots.get(e.targetId);if(!a)throw Error(`No snapshot available. Run "snapshot" first.`);let{isIframe:o}=fQ(n),s=a.refToFrameId?.get(n);if(o&&s){let o=a.refToSelector.get(n);if(!o)throw Error(`Unknown ref "${n}" in iframe`);let c=o.split(`,`)[0].trim();return await t.evaluateInFrame(s,`(function() {
3634
+ `,exitCode:1};break}let e=c$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}let n=c[0],r=c.slice(1).join(` `);u={stdout:await t.withTab(e.targetId,async()=>{let a=i.snapshots.get(e.targetId);if(!a)throw Error(`No snapshot available. Run "snapshot" first.`);let{isIframe:o}=hQ(n),s=a.refToFrameId?.get(n);if(o&&s){let o=a.refToSelector.get(n);if(!o)throw Error(`Unknown ref "${n}" in iframe`);let c=o.split(`,`)[0].trim();return await t.evaluateInFrame(s,`(function() {
3635
3635
  var el = document.querySelector(${JSON.stringify(c)});
3636
3636
  if (!el) throw new Error('Element not found in iframe for ref ${n}');
3637
3637
  el.value = ${JSON.stringify(r)};
3638
3638
  el.dispatchEvent(new Event('change', { bubbles: true }));
3639
3639
  })()`),i.snapshots.delete(e.targetId),`Selected "${r}" on ${n} (in iframe)`}let c=a.refToBackendNodeId.get(n);if(!c)throw Error(`Unknown ref "${n}"`);return await t.selectByBackendNodeId(c,r),i.snapshots.delete(e.targetId),`Selected "${r}" on ${n}`})+`
3640
3640
  `,stderr:``,exitCode:0};break}case`check`:{if(c.length===0){u={stdout:``,stderr:`check requires a ref (e.g. e5)
3641
- `,exitCode:1};break}let e=a$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}let n=c[0];u={stdout:await t.withTab(e.targetId,async()=>{let r=i.snapshots.get(e.targetId);if(!r)throw Error(`No snapshot available. Run "snapshot" first.`);let{isIframe:a}=fQ(n),o=r.refToFrameId?.get(n);if(a&&o){let a=r.refToSelector.get(n);if(!a)throw Error(`Unknown ref "${n}" in iframe`);let s=a.split(`,`)[0].trim();return await t.evaluateInFrame(o,`(function() {
3641
+ `,exitCode:1};break}let e=c$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}let n=c[0];u={stdout:await t.withTab(e.targetId,async()=>{let r=i.snapshots.get(e.targetId);if(!r)throw Error(`No snapshot available. Run "snapshot" first.`);let{isIframe:a}=hQ(n),o=r.refToFrameId?.get(n);if(a&&o){let a=r.refToSelector.get(n);if(!a)throw Error(`Unknown ref "${n}" in iframe`);let s=a.split(`,`)[0].trim();return await t.evaluateInFrame(o,`(function() {
3642
3642
  var el = document.querySelector(${JSON.stringify(s)});
3643
3643
  if (!el) throw new Error('Element not found in iframe for ref ${n}');
3644
3644
  if (!el.checked) {
@@ -3648,7 +3648,7 @@ Aliases: ${mQ.filter(t=>t!==e).join(`, `)}`}var r$=new Set([`tab`,`filename`,`ma
3648
3648
  }
3649
3649
  })()`),i.snapshots.delete(e.targetId),`Checked ${n} (in iframe)`}let s=r.refToBackendNodeId.get(n);if(!s)throw Error(`Unknown ref "${n}"`);let c=await t.setCheckedByBackendNodeId(s,!0);return c===`toggled`&&i.snapshots.delete(e.targetId),c===`already`?`${n} already checked`:`Checked ${n}`})+`
3650
3650
  `,stderr:``,exitCode:0};break}case`uncheck`:{if(c.length===0){u={stdout:``,stderr:`uncheck requires a ref (e.g. e5)
3651
- `,exitCode:1};break}let e=a$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}let n=c[0];u={stdout:await t.withTab(e.targetId,async()=>{let r=i.snapshots.get(e.targetId);if(!r)throw Error(`No snapshot available. Run "snapshot" first.`);let{isIframe:a}=fQ(n),o=r.refToFrameId?.get(n);if(a&&o){let a=r.refToSelector.get(n);if(!a)throw Error(`Unknown ref "${n}" in iframe`);let s=a.split(`,`)[0].trim();return await t.evaluateInFrame(o,`(function() {
3651
+ `,exitCode:1};break}let e=c$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}let n=c[0];u={stdout:await t.withTab(e.targetId,async()=>{let r=i.snapshots.get(e.targetId);if(!r)throw Error(`No snapshot available. Run "snapshot" first.`);let{isIframe:a}=hQ(n),o=r.refToFrameId?.get(n);if(a&&o){let a=r.refToSelector.get(n);if(!a)throw Error(`Unknown ref "${n}" in iframe`);let s=a.split(`,`)[0].trim();return await t.evaluateInFrame(o,`(function() {
3652
3652
  var el = document.querySelector(${JSON.stringify(s)});
3653
3653
  if (!el) throw new Error('Element not found in iframe for ref ${n}');
3654
3654
  if (el.checked) {
@@ -3658,37 +3658,37 @@ Aliases: ${mQ.filter(t=>t!==e).join(`, `)}`}var r$=new Set([`tab`,`filename`,`ma
3658
3658
  }
3659
3659
  })()`),i.snapshots.delete(e.targetId),`Unchecked ${n} (in iframe)`}let s=r.refToBackendNodeId.get(n);if(!s)throw Error(`Unknown ref "${n}"`);let c=await t.setCheckedByBackendNodeId(s,!1);return c===`toggled`&&i.snapshots.delete(e.targetId),c===`already`?`${n} already unchecked`:`Unchecked ${n}`})+`
3660
3660
  `,stderr:``,exitCode:0};break}case`drag`:{if(c.length<2){u={stdout:``,stderr:`drag requires <startRef> <endRef>
3661
- `,exitCode:1};break}let e=a$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}let n=c[0],r=c[1];u={stdout:await t.withTab(e.targetId,async()=>{let a=i.snapshots.get(e.targetId);if(!a)throw Error(`No snapshot available. Run "snapshot" first.`);let o=a.refToBackendNodeId.get(n),s=a.refToBackendNodeId.get(r);if(!o)throw Error(`Unknown ref "${n}"`);if(!s)throw Error(`Unknown ref "${r}"`);return await t.dragByBackendNodeIds(o,s),i.snapshots.delete(e.targetId),`Dragged ${n} to ${r}`})+`
3661
+ `,exitCode:1};break}let e=c$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}let n=c[0],r=c[1];u={stdout:await t.withTab(e.targetId,async()=>{let a=i.snapshots.get(e.targetId);if(!a)throw Error(`No snapshot available. Run "snapshot" first.`);let o=a.refToBackendNodeId.get(n),s=a.refToBackendNodeId.get(r);if(!o)throw Error(`Unknown ref "${n}"`);if(!s)throw Error(`Unknown ref "${r}"`);return await t.dragByBackendNodeIds(o,s),i.snapshots.delete(e.targetId),`Dragged ${n} to ${r}`})+`
3662
3662
  `,stderr:``,exitCode:0};break}case`resize`:{if(c.length<2){u={stdout:``,stderr:`resize requires <width> <height>
3663
- `,exitCode:1};break}let e=a$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}let n=parseInt(c[0],10),r=parseInt(c[1],10);if(isNaN(n)||isNaN(r)||n<=0||r<=0){u={stdout:``,stderr:`resize requires positive integer width and height
3664
- `,exitCode:1};break}await t.withTab(e.targetId,async()=>{let e=t.getTransport(),i=t.getSessionId();await e.send(`Emulation.setDeviceMetricsOverride`,{width:n,height:r,deviceScaleFactor:1,mobile:!1},i)}),i.snapshots.delete(e.targetId),u={stdout:`Resized viewport to ${n}x${r}\n`,stderr:``,exitCode:0};break}case`dialog-accept`:{let e=a$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}let n=c.length>0?c.join(` `):void 0;await t.withTab(e.targetId,async()=>{let e=t.getTransport(),r=t.getSessionId();await e.send(`Page.enable`,{},r),await e.send(`Page.handleJavaScriptDialog`,{accept:!0,...n===void 0?{}:{promptText:n}},r)}),u={stdout:`Accepted dialog${n?` with "${n}"`:``}\n`,stderr:``,exitCode:0};break}case`dialog-dismiss`:{let e=a$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}await t.withTab(e.targetId,async()=>{let e=t.getTransport(),n=t.getSessionId();await e.send(`Page.enable`,{},n),await e.send(`Page.handleJavaScriptDialog`,{accept:!1},n)}),u={stdout:`Dismissed dialog
3665
- `,stderr:``,exitCode:0};break}case`cookie-list`:{let e=a$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}u={stdout:await t.withTab(e.targetId,async()=>{let e=(await t.sendCDP(`Network.getCookies`)).cookies??[];return e.length===0?`No cookies`:e.map(e=>`${e.name}=${e.value}\tDomain=${e.domain}\tPath=${e.path}\tSecure=${e.secure}\tHttpOnly=${e.httpOnly}\tExpires=${e.expires}`).join(`
3663
+ `,exitCode:1};break}let e=c$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}let n=parseInt(c[0],10),r=parseInt(c[1],10);if(isNaN(n)||isNaN(r)||n<=0||r<=0){u={stdout:``,stderr:`resize requires positive integer width and height
3664
+ `,exitCode:1};break}await t.withTab(e.targetId,async()=>{let e=t.getTransport(),i=t.getSessionId();await e.send(`Emulation.setDeviceMetricsOverride`,{width:n,height:r,deviceScaleFactor:1,mobile:!1},i)}),i.snapshots.delete(e.targetId),u={stdout:`Resized viewport to ${n}x${r}\n`,stderr:``,exitCode:0};break}case`dialog-accept`:{let e=c$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}let n=c.length>0?c.join(` `):void 0;await t.withTab(e.targetId,async()=>{let e=t.getTransport(),r=t.getSessionId();await e.send(`Page.enable`,{},r),await e.send(`Page.handleJavaScriptDialog`,{accept:!0,...n===void 0?{}:{promptText:n}},r)}),u={stdout:`Accepted dialog${n?` with "${n}"`:``}\n`,stderr:``,exitCode:0};break}case`dialog-dismiss`:{let e=c$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}await t.withTab(e.targetId,async()=>{let e=t.getTransport(),n=t.getSessionId();await e.send(`Page.enable`,{},n),await e.send(`Page.handleJavaScriptDialog`,{accept:!1},n)}),u={stdout:`Dismissed dialog
3665
+ `,stderr:``,exitCode:0};break}case`cookie-list`:{let e=c$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}u={stdout:await t.withTab(e.targetId,async()=>{let e=(await t.sendCDP(`Network.getCookies`)).cookies??[];return e.length===0?`No cookies`:e.map(e=>`${e.name}=${e.value}\tDomain=${e.domain}\tPath=${e.path}\tSecure=${e.secure}\tHttpOnly=${e.httpOnly}\tExpires=${e.expires}`).join(`
3666
3666
  `)})+`
3667
3667
  `,stderr:``,exitCode:0};break}case`cookie-get`:{if(c.length===0){u={stdout:``,stderr:`cookie-get requires a cookie name
3668
- `,exitCode:1};break}let e=a$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}let n=c[0];u={stdout:await t.withTab(e.targetId,async()=>{let e=((await t.sendCDP(`Network.getCookies`)).cookies??[]).filter(e=>e.name===n);if(e.length===0)throw Error(`Cookie "${n}" not found`);return e.map(e=>`${e.name}=${e.value}\tDomain=${e.domain}\tPath=${e.path}\tSecure=${e.secure}\tHttpOnly=${e.httpOnly}\tExpires=${e.expires}`).join(`
3668
+ `,exitCode:1};break}let e=c$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}let n=c[0];u={stdout:await t.withTab(e.targetId,async()=>{let e=((await t.sendCDP(`Network.getCookies`)).cookies??[]).filter(e=>e.name===n);if(e.length===0)throw Error(`Cookie "${n}" not found`);return e.map(e=>`${e.name}=${e.value}\tDomain=${e.domain}\tPath=${e.path}\tSecure=${e.secure}\tHttpOnly=${e.httpOnly}\tExpires=${e.expires}`).join(`
3669
3669
  `)})+`
3670
3670
  `,stderr:``,exitCode:0};break}case`cookie-set`:{if(c.length<2){u={stdout:``,stderr:`cookie-set requires <name> <value>
3671
- `,exitCode:1};break}let e=a$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}await t.withTab(e.targetId,async()=>{let e=await CQ(t),n={name:c[0],value:c[1]};l.domain&&(n.domain=l.domain),l.path&&(n.path=l.path),l.secure===`true`&&(n.secure=!0),l.httpOnly===`true`&&(n.httpOnly=!0),l.expires&&(n.expires=parseFloat(l.expires)),!n.domain&&!n.path&&(n.url=e.href),await t.sendCDP(`Network.setCookie`,n)}),u={stdout:`Cookie "${c[0]}" set\n`,stderr:``,exitCode:0};break}case`cookie-delete`:{if(c.length===0){u={stdout:``,stderr:`cookie-delete requires a cookie name
3672
- `,exitCode:1};break}let e=a$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}await t.withTab(e.targetId,async()=>{let e={name:c[0]};l.domain&&(e.domain=l.domain),l.path&&(e.path=l.path),!e.domain&&!e.path&&(e.url=(await CQ(t)).href),await t.sendCDP(`Network.deleteCookies`,e)}),u={stdout:`Cookie "${c[0]}" deleted\n`,stderr:``,exitCode:0};break}case`cookie-clear`:{let e=a$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}await t.withTab(e.targetId,async()=>{await t.sendCDP(`Network.clearBrowserCookies`)}),u={stdout:`All cookies cleared
3673
- `,stderr:``,exitCode:0};break}case`localstorage-list`:{let e=a$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}u={stdout:await t.withTab(e.targetId,async()=>{let e=await t.evaluate(`JSON.stringify(Object.entries(localStorage))`),n=JSON.parse(e);return n.length===0?`No localStorage entries`:n.map(([e,t])=>`${e}=${t}`).join(`
3671
+ `,exitCode:1};break}let e=c$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}await t.withTab(e.targetId,async()=>{let e=await EQ(t),n={name:c[0],value:c[1]};l.domain&&(n.domain=l.domain),l.path&&(n.path=l.path),l.secure===`true`&&(n.secure=!0),l.httpOnly===`true`&&(n.httpOnly=!0),l.expires&&(n.expires=parseFloat(l.expires)),!n.domain&&!n.path&&(n.url=e.href),await t.sendCDP(`Network.setCookie`,n)}),u={stdout:`Cookie "${c[0]}" set\n`,stderr:``,exitCode:0};break}case`cookie-delete`:{if(c.length===0){u={stdout:``,stderr:`cookie-delete requires a cookie name
3672
+ `,exitCode:1};break}let e=c$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}await t.withTab(e.targetId,async()=>{let e={name:c[0]};l.domain&&(e.domain=l.domain),l.path&&(e.path=l.path),!e.domain&&!e.path&&(e.url=(await EQ(t)).href),await t.sendCDP(`Network.deleteCookies`,e)}),u={stdout:`Cookie "${c[0]}" deleted\n`,stderr:``,exitCode:0};break}case`cookie-clear`:{let e=c$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}await t.withTab(e.targetId,async()=>{await t.sendCDP(`Network.clearBrowserCookies`)}),u={stdout:`All cookies cleared
3673
+ `,stderr:``,exitCode:0};break}case`localstorage-list`:{let e=c$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}u={stdout:await t.withTab(e.targetId,async()=>{let e=await t.evaluate(`JSON.stringify(Object.entries(localStorage))`),n=JSON.parse(e);return n.length===0?`No localStorage entries`:n.map(([e,t])=>`${e}=${t}`).join(`
3674
3674
  `)})+`
3675
3675
  `,stderr:``,exitCode:0};break}case`localstorage-get`:{if(c.length===0){u={stdout:``,stderr:`localstorage-get requires a key
3676
- `,exitCode:1};break}let e=a$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}u={stdout:await t.withTab(e.targetId,async()=>{let e=await t.evaluate(`localStorage.getItem(${JSON.stringify(c[0])})`);if(e===null)throw Error(`Key "${c[0]}" not found in localStorage`);return e})+`
3676
+ `,exitCode:1};break}let e=c$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}u={stdout:await t.withTab(e.targetId,async()=>{let e=await t.evaluate(`localStorage.getItem(${JSON.stringify(c[0])})`);if(e===null)throw Error(`Key "${c[0]}" not found in localStorage`);return e})+`
3677
3677
  `,stderr:``,exitCode:0};break}case`localstorage-set`:{if(c.length<2){u={stdout:``,stderr:`localstorage-set requires <key> <value>
3678
- `,exitCode:1};break}let e=a$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}await t.withTab(e.targetId,async()=>{await t.evaluate(`localStorage.setItem(${JSON.stringify(c[0])}, ${JSON.stringify(c.slice(1).join(` `))})`)}),u={stdout:`localStorage "${c[0]}" set\n`,stderr:``,exitCode:0};break}case`localstorage-delete`:{if(c.length===0){u={stdout:``,stderr:`localstorage-delete requires a key
3679
- `,exitCode:1};break}let e=a$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}await t.withTab(e.targetId,async()=>{await t.evaluate(`localStorage.removeItem(${JSON.stringify(c[0])})`)}),u={stdout:`localStorage "${c[0]}" deleted\n`,stderr:``,exitCode:0};break}case`localstorage-clear`:{let e=a$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}await t.withTab(e.targetId,async()=>{await t.evaluate(`localStorage.clear()`)}),u={stdout:`localStorage cleared
3680
- `,stderr:``,exitCode:0};break}case`sessionstorage-list`:{let e=a$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}u={stdout:await t.withTab(e.targetId,async()=>{let e=await t.evaluate(`JSON.stringify(Object.entries(sessionStorage))`),n=JSON.parse(e);return n.length===0?`No sessionStorage entries`:n.map(([e,t])=>`${e}=${t}`).join(`
3678
+ `,exitCode:1};break}let e=c$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}await t.withTab(e.targetId,async()=>{await t.evaluate(`localStorage.setItem(${JSON.stringify(c[0])}, ${JSON.stringify(c.slice(1).join(` `))})`)}),u={stdout:`localStorage "${c[0]}" set\n`,stderr:``,exitCode:0};break}case`localstorage-delete`:{if(c.length===0){u={stdout:``,stderr:`localstorage-delete requires a key
3679
+ `,exitCode:1};break}let e=c$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}await t.withTab(e.targetId,async()=>{await t.evaluate(`localStorage.removeItem(${JSON.stringify(c[0])})`)}),u={stdout:`localStorage "${c[0]}" deleted\n`,stderr:``,exitCode:0};break}case`localstorage-clear`:{let e=c$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}await t.withTab(e.targetId,async()=>{await t.evaluate(`localStorage.clear()`)}),u={stdout:`localStorage cleared
3680
+ `,stderr:``,exitCode:0};break}case`sessionstorage-list`:{let e=c$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}u={stdout:await t.withTab(e.targetId,async()=>{let e=await t.evaluate(`JSON.stringify(Object.entries(sessionStorage))`),n=JSON.parse(e);return n.length===0?`No sessionStorage entries`:n.map(([e,t])=>`${e}=${t}`).join(`
3681
3681
  `)})+`
3682
3682
  `,stderr:``,exitCode:0};break}case`sessionstorage-get`:{if(c.length===0){u={stdout:``,stderr:`sessionstorage-get requires a key
3683
- `,exitCode:1};break}let e=a$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}u={stdout:await t.withTab(e.targetId,async()=>{let e=await t.evaluate(`sessionStorage.getItem(${JSON.stringify(c[0])})`);if(e===null)throw Error(`Key "${c[0]}" not found in sessionStorage`);return e})+`
3683
+ `,exitCode:1};break}let e=c$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}u={stdout:await t.withTab(e.targetId,async()=>{let e=await t.evaluate(`sessionStorage.getItem(${JSON.stringify(c[0])})`);if(e===null)throw Error(`Key "${c[0]}" not found in sessionStorage`);return e})+`
3684
3684
  `,stderr:``,exitCode:0};break}case`sessionstorage-set`:{if(c.length<2){u={stdout:``,stderr:`sessionstorage-set requires <key> <value>
3685
- `,exitCode:1};break}let e=a$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}await t.withTab(e.targetId,async()=>{await t.evaluate(`sessionStorage.setItem(${JSON.stringify(c[0])}, ${JSON.stringify(c.slice(1).join(` `))})`)}),u={stdout:`sessionStorage "${c[0]}" set\n`,stderr:``,exitCode:0};break}case`sessionstorage-delete`:{if(c.length===0){u={stdout:``,stderr:`sessionstorage-delete requires a key
3686
- `,exitCode:1};break}let e=a$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}await t.withTab(e.targetId,async()=>{await t.evaluate(`sessionStorage.removeItem(${JSON.stringify(c[0])})`)}),u={stdout:`sessionStorage "${c[0]}" deleted\n`,stderr:``,exitCode:0};break}case`sessionstorage-clear`:{let e=a$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}await t.withTab(e.targetId,async()=>{await t.evaluate(`sessionStorage.clear()`)}),u={stdout:`sessionStorage cleared
3687
- `,stderr:``,exitCode:0};break}case`record`:{let e=c[0]||`about:blank`,r=l.filter;await AQ(t,i);let a=await t.createPage(e),o=t.getTransport(),s=(await o.send(`Target.attachToTarget`,{targetId:a,flatten:!0})).sessionId;i.harRecorder||=new dc(o,n);let d=await i.harRecorder.startRecording(a,s,r);u={stdout:`Recording started (targetId: ${a}, recordingId: ${d}) at ${e}\nHAR saved to /recordings/${d}/\n`,stderr:``,exitCode:0};break}case`stop-recording`:{if(c.length===0){u={stdout:``,stderr:`stop-recording requires a recordingId
3688
- `,exitCode:1};break}let e=c[0];if(!i.harRecorder){u={stdout:``,stderr:`Recording not found: ${e}\n`,exitCode:1};break}u={stdout:`Recording stopped. HAR files saved to ${await i.harRecorder.stopRecording(e)}\n`,stderr:``,exitCode:0};break}default:u={stdout:``,stderr:`Unknown command: ${o}\nRun "playwright-cli help" for usage.\n`,exitCode:1};break}}catch(e){u={stdout:``,stderr:`Error: ${e instanceof Error?e.message:String(e)}\n`,exitCode:1}}let d=l.tab??null,f=null;gQ.has(o)&&u.exitCode===0&&d&&(f=await TQ(t,n,i,d));try{await EQ(n,i,{command:o,args:s,result:u,snapshotPath:f,targetId:d})}catch{}return u})}var s$=new Map([[`File operations`,[`ls`,`cat`,`head`,`tail`,`wc`,`touch`,`mkdir`,`rm`,`cp`,`mv`,`ln`,`chmod`,`stat`,`readlink`]],[`Text processing`,[`grep`,`sed`,`awk`,`sort`,`uniq`,`cut`,`tr`,`tee`,`diff`]],[`Search`,[`find`,`rg`]],[`Navigation & paths`,[`pwd`,`basename`,`dirname`,`tree`,`du`,`cd`]],[`Archives`,[`zip`,`unzip`,`pdftk`,`pdf`]],[`Media`,[`convert`,`magick`]],[`Audio`,[`say`,`afplay`,`chime`]],[`Environment & shell`,[`echo`,`printf`,`env`,`printenv`,`export`,`alias`,`unalias`,`history`,`clear`,`true`,`false`,`bash`,`sh`,`commands`,`which`,`uname`,`man`,`host`,`oauth-token`,`secret`,`nuke`,`models`,`cost`]],[`Data processing`,[`xargs`,`jq`,`base64`,`date`]],[`Network`,[`curl`,`wget`,`html-to-markdown`]],[`Version control`,[`git`]],[`Languages`,[`node`,`python`,`python3`,`sqlite3`]],[`Skills`,[`skill`,`upskill`]],[`Browser & UI`,[`serve`,`open`,`imgcat`,...mQ,`webhook`]],[`Filesystem`,[`mount`,`fswatch`]],[`Scoops & agents`,[`agent`]]]);function c$(e,t=[]){let n=[],r=new Set(e);n.push(`Available commands:
3689
- `);let i=[];for(let[e,t]of s$){let i=t.filter(e=>r.has(e));if(i.length>0){n.push(` ${e}:`),n.push(` ${i.join(`, `)}\n`);for(let e of i)r.delete(e)}}for(let e of r)i.push(e);return i.length>0&&(n.push(` Other:`),n.push(` ${i.sort().join(`, `)}\n`)),t.length>0&&(n.push(` User scripts (.jsh):`),n.push(` ${t.sort().join(`, `)}\n`)),n.push(`Use '<command> --help' for details on a specific command.`),n.join(`
3685
+ `,exitCode:1};break}let e=c$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}await t.withTab(e.targetId,async()=>{await t.evaluate(`sessionStorage.setItem(${JSON.stringify(c[0])}, ${JSON.stringify(c.slice(1).join(` `))})`)}),u={stdout:`sessionStorage "${c[0]}" set\n`,stderr:``,exitCode:0};break}case`sessionstorage-delete`:{if(c.length===0){u={stdout:``,stderr:`sessionstorage-delete requires a key
3686
+ `,exitCode:1};break}let e=c$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}await t.withTab(e.targetId,async()=>{await t.evaluate(`sessionStorage.removeItem(${JSON.stringify(c[0])})`)}),u={stdout:`sessionStorage "${c[0]}" deleted\n`,stderr:``,exitCode:0};break}case`sessionstorage-clear`:{let e=c$(l);if(`error`in e){u={stdout:``,stderr:e.error,exitCode:1};break}await t.withTab(e.targetId,async()=>{await t.evaluate(`sessionStorage.clear()`)}),u={stdout:`sessionStorage cleared
3687
+ `,stderr:``,exitCode:0};break}case`record`:{let e=c[0]||`about:blank`,r=l.filter;await NQ(t,i);let a=await t.createPage(e),o=t.getTransport(),s=(await o.send(`Target.attachToTarget`,{targetId:a,flatten:!0})).sessionId;i.harRecorder||=new dc(o,n);let d=await i.harRecorder.startRecording(a,s,r);u={stdout:`Recording started (targetId: ${a}, recordingId: ${d}) at ${e}\nHAR saved to /recordings/${d}/\n`,stderr:``,exitCode:0};break}case`stop-recording`:{if(c.length===0){u={stdout:``,stderr:`stop-recording requires a recordingId
3688
+ `,exitCode:1};break}let e=c[0];if(!i.harRecorder){u={stdout:``,stderr:`Recording not found: ${e}\n`,exitCode:1};break}u={stdout:`Recording stopped. HAR files saved to ${await i.harRecorder.stopRecording(e)}\n`,stderr:``,exitCode:0};break}default:u={stdout:``,stderr:`Unknown command: ${o}\nRun "playwright-cli help" for usage.\n`,exitCode:1};break}}catch(e){u={stdout:``,stderr:`Error: ${e instanceof Error?e.message:String(e)}\n`,exitCode:1}}let d=l.tab??null,f=null;yQ.has(o)&&u.exitCode===0&&d&&(f=await OQ(t,n,i,d));try{await kQ(n,i,{command:o,args:s,result:u,snapshotPath:f,targetId:d})}catch{}return u})}var u$=new Map([[`File operations`,[`ls`,`cat`,`head`,`tail`,`wc`,`touch`,`mkdir`,`rm`,`cp`,`mv`,`ln`,`chmod`,`stat`,`readlink`]],[`Text processing`,[`grep`,`sed`,`awk`,`sort`,`uniq`,`cut`,`tr`,`tee`,`diff`]],[`Search`,[`find`,`rg`]],[`Navigation & paths`,[`pwd`,`basename`,`dirname`,`tree`,`du`,`cd`]],[`Archives`,[`zip`,`unzip`,`pdftk`,`pdf`]],[`Media`,[`convert`,`magick`]],[`Audio`,[`say`,`afplay`,`chime`]],[`Environment & shell`,[`echo`,`printf`,`env`,`printenv`,`export`,`alias`,`unalias`,`history`,`clear`,`true`,`false`,`bash`,`sh`,`commands`,`which`,`uname`,`man`,`host`,`oauth-token`,`secret`,`nuke`,`models`,`cost`]],[`Data processing`,[`xargs`,`jq`,`base64`,`date`]],[`Network`,[`curl`,`wget`,`html-to-markdown`]],[`Version control`,[`git`]],[`Languages`,[`node`,`python`,`python3`,`sqlite3`]],[`Skills`,[`skill`,`upskill`]],[`Browser & UI`,[`serve`,`open`,`imgcat`,..._Q,`webhook`]],[`Filesystem`,[`mount`,`fswatch`]],[`Scoops & agents`,[`agent`]]]);function d$(e,t=[]){let n=[],r=new Set(e);n.push(`Available commands:
3689
+ `);let i=[];for(let[e,t]of u$){let i=t.filter(e=>r.has(e));if(i.length>0){n.push(` ${e}:`),n.push(` ${i.join(`, `)}\n`);for(let e of i)r.delete(e)}}for(let e of r)i.push(e);return i.length>0&&(n.push(` Other:`),n.push(` ${i.sort().join(`, `)}\n`)),t.length>0&&(n.push(` User scripts (.jsh):`),n.push(` ${t.sort().join(`, `)}\n`)),n.push(`Use '<command> --help' for details on a specific command.`),n.join(`
3690
3690
  `)+`
3691
- `}function l$(e={}){return gR(`commands`,async(t,n)=>{if(t.includes(`--help`)||t.includes(`-h`))return{stdout:`commands - display available commands
3691
+ `}function f$(e={}){return gR(`commands`,async(t,n)=>{if(t.includes(`--help`)||t.includes(`-h`))return{stdout:`commands - display available commands
3692
3692
 
3693
3693
  Usage: commands [command]
3694
3694
 
@@ -3699,7 +3699,7 @@ If a command name is provided, shows help for that command.
3699
3699
  Otherwise, lists all available commands.
3700
3700
 
3701
3701
  Note: This is an enhanced version of 'help' that shows all custom commands.
3702
- `,stderr:``,exitCode:0};if(t.length>0&&n.exec){let e=t[0];return n.exec(`${e} --help`,{cwd:n.cwd})}return{stdout:c$(n.getRegisteredCommands?.()??[],await e.getJshCommands?.()??[]),stderr:``,exitCode:0}})}function u$(e){let t=e.toLowerCase();return t.endsWith(`.jpg`)||t.endsWith(`.jpeg`)?`JPEG`:t.endsWith(`.png`)?`PNG`:t.endsWith(`.gif`)?`GIF`:t.endsWith(`.webp`)?`WEBP`:t.endsWith(`.bmp`)?`BMP`:t.endsWith(`.tiff`)||t.endsWith(`.tif`)?`TIFF`:t.endsWith(`.avif`)?`AVIF`:`PNG`}function d$(){return{stdout:`usage: convert [input] [operations...] [output]
3702
+ `,stderr:``,exitCode:0};if(t.length>0&&n.exec){let e=t[0];return n.exec(`${e} --help`,{cwd:n.cwd})}return{stdout:d$(n.getRegisteredCommands?.()??[],await e.getJshCommands?.()??[]),stderr:``,exitCode:0}})}function p$(e){let t=e.toLowerCase();return t.endsWith(`.jpg`)||t.endsWith(`.jpeg`)?`JPEG`:t.endsWith(`.png`)?`PNG`:t.endsWith(`.gif`)?`GIF`:t.endsWith(`.webp`)?`WEBP`:t.endsWith(`.bmp`)?`BMP`:t.endsWith(`.tiff`)||t.endsWith(`.tif`)?`TIFF`:t.endsWith(`.avif`)?`AVIF`:`PNG`}function m$(){return{stdout:`usage: convert [input] [operations...] [output]
3703
3703
 
3704
3704
  Operations:
3705
3705
  -resize WxH resize to width x height
@@ -3714,7 +3714,7 @@ Examples:
3714
3714
  convert photo.png -resize 50% smaller.png
3715
3715
  convert image.jpg -rotate 90 -quality 85 rotated.jpg
3716
3716
  convert input.png -crop 100x100+50+50 cropped.png
3717
- `,stderr:``,exitCode:0}}function f$(e=`convert`){return gR(e,async(t,n)=>{if(t.length===0||t.includes(`--help`)||t.includes(`-h`))return d$();let r=[],i=[],a=0;for(;a<t.length;){let n=t[a];if(n===`-resize`){if(a+1>=t.length||t[a+1].startsWith(`-`))return{stdout:``,stderr:`${e}: missing argument for -resize\n`,exitCode:1};i.push({type:`resize`,value:t[a+1]}),a+=2}else if(n===`-rotate`){if(a+1>=t.length||t[a+1].startsWith(`-`))return{stdout:``,stderr:`${e}: missing argument for -rotate\n`,exitCode:1};i.push({type:`rotate`,value:t[a+1]}),a+=2}else if(n===`-crop`){if(a+1>=t.length||t[a+1].startsWith(`-`))return{stdout:``,stderr:`${e}: missing argument for -crop\n`,exitCode:1};i.push({type:`crop`,value:t[a+1]}),a+=2}else if(n===`-quality`){if(a+1>=t.length||t[a+1].startsWith(`-`))return{stdout:``,stderr:`${e}: missing argument for -quality\n`,exitCode:1};i.push({type:`quality`,value:t[a+1]}),a+=2}else if(n.startsWith(`-`))return{stdout:``,stderr:`${e}: unsupported option ${n}\n`,exitCode:1};else r.push(n),a++}if(r.length!==2)return{stdout:``,stderr:`${e}: expected exactly one input file and one output file\n`,exitCode:1};let o=r[0],s=r[1];try{let e=n.fs.resolvePath(n.cwd,o),t=await n.fs.readFileBuffer(e),r=await Ee(),a=null;if(await r.ImageMagick.read(t,async e=>{for(let t of i)switch(t.type){case`resize`:{let n=t.value.match(/^(\d+)%$/);if(n){let t=parseInt(n[1],10),r=Math.round(e.width*t/100),i=Math.round(e.height*t/100);e.resize(r,i)}else{let n=t.value.endsWith(`!`),i=(n?t.value.slice(0,-1):t.value).split(`x`);if(i.length===2){let t=parseInt(i[0],10),a=parseInt(i[1],10);if(n){let n=new r.MagickGeometry(t,a);n.ignoreAspectRatio=!0,e.resize(n)}else e.resize(t,a)}else throw Error(`Invalid resize format: ${t.value}`)}break}case`rotate`:{let n=parseFloat(t.value);if(isNaN(n))throw Error(`Invalid rotation degrees: ${t.value}`);e.rotate(n);break}case`crop`:{if(!t.value.match(/^(\d+)x(\d+)\+(\d+)\+(\d+)$/))throw Error(`Invalid crop format: ${t.value} (expected WxH+X+Y)`);let n=new r.MagickGeometry(t.value);e.crop(n);break}case`quality`:{let n=parseInt(t.value,10);if(isNaN(n)||n<0||n>100)throw Error(`Invalid quality: ${t.value} (must be 0-100)`);e.quality=n;break}}let t=u$(s);e.write(t,e=>{a=e})}),!a)throw Error(`Failed to generate output image`);let c=n.fs.resolvePath(n.cwd,s);return await n.fs.writeFile(c,a),{stdout:``,stderr:``,exitCode:0}}catch(t){return{stdout:``,stderr:`${e}: ${t instanceof Error?t.message:String(t)}\n`,exitCode:1}}})}var p$=o(`tray-leader`),m$=`leader-tray-session`,h$=3e4,g$=1e4,_$=1e3,v$=3e4,y$=2,b$=20,x$={state:`inactive`,session:null,error:null};function S$(){return{...x$,session:x$.session?{...x$.session}:null}}function C$(e){x$={...e,session:e.session?{...e.session}:null}}var w$=class{constructor(e=m$){this.key=e}async load(){return T$(await ye(this.key))}async save(e){await we(this.key,JSON.stringify(e))}async clear(){await we(this.key,``)}};function T$(e){if(!e)return null;try{let t=JSON.parse(e);return typeof t.workerBaseUrl!=`string`||typeof t.trayId!=`string`||typeof t.createdAt!=`string`||typeof t.controllerId!=`string`||typeof t.controllerUrl!=`string`||typeof t.joinUrl!=`string`||typeof t.webhookUrl!=`string`||typeof t.runtime!=`string`?null:{workerBaseUrl:t.workerBaseUrl,trayId:t.trayId,createdAt:t.createdAt,controllerId:t.controllerId,controllerUrl:t.controllerUrl,joinUrl:t.joinUrl,webhookUrl:t.webhookUrl,leaderKey:typeof t.leaderKey==`string`?t.leaderKey:void 0,leaderWebSocketUrl:typeof t.leaderWebSocketUrl==`string`?t.leaderWebSocketUrl:null,runtime:t.runtime}}catch{return null}}var E$=class{store;fetchImpl;webSocketFactory;pingIntervalMs;connectTimeoutMs;reconnectEnabled;reconnectBaseDelayMs;reconnectMaxDelayMs;reconnectBackoffMultiplier;reconnectMaxAttempts;reconnectSleep;socket=null;pingTimer=null;currentSession=null;stopped=!1;reconnecting=!1;reconnectGeneration=0;constructor(e){this.options=e,this.store=e.store??new w$,this.fetchImpl=e.fetchImpl??A$(),this.webSocketFactory=e.webSocketFactory??(e=>new WebSocket(e)),this.pingIntervalMs=e.pingIntervalMs??h$,this.connectTimeoutMs=e.connectTimeoutMs??g$;let t=e.reconnect;this.reconnectEnabled=t!==!1;let n=t===!1||!t?{}:t;this.reconnectBaseDelayMs=n.baseDelayMs??_$,this.reconnectMaxDelayMs=n.maxDelayMs??v$,this.reconnectBackoffMultiplier=n.backoffMultiplier??y$,this.reconnectMaxAttempts=n.maxAttempts??b$,this.reconnectSleep=n.sleep??(e=>new Promise(t=>setTimeout(t,e)))}async start(){if(this.stopped=!1,this.currentSession&&this.socket)return C$({state:`leader`,session:this.currentSession,error:null}),this.currentSession;C$({state:`connecting`,session:null,error:null}),this.currentSession=null;try{let e=await this.connectOnce();return p$.info(`Leader joined tray`,{trayId:e.trayId,controllerId:e.controllerId,runtime:e.runtime}),e}catch(e){throw C$({state:`error`,session:this.currentSession,error:e instanceof Error?e.message:String(e)}),e}}stop(){this.stopped=!0,this.reconnecting=!1,this.reconnectGeneration++,this.tearDownSocket(),this.currentSession=null,C$({state:`inactive`,session:null,error:null})}tearDownSocket(){this.pingTimer&&=(clearInterval(this.pingTimer),null);let e=this.socket;if(this.socket=null,e)try{e.close()}catch{}}async connectOnce(){let e=await this.store.load(),t=e?.workerBaseUrl===this.options.workerBaseUrl?e:null,n=await this.attachWithRecovery(t);this.currentSession=n;let r=await this.openLeaderSocket(n.leaderWebSocketUrl);return this.socket=r,this.startPingLoop(r),C$({state:`leader`,session:n,error:null}),n}async handleUnexpectedDisconnect(e){if(this.stopped)return;if(!this.reconnectEnabled){p$.warn(`Leader WebSocket dropped and auto-reconnect is disabled`,{reason:e}),this.tearDownSocket(),this.currentSession=null,C$({state:`error`,session:null,error:`Leader WebSocket dropped: ${e}`});return}if(this.reconnecting)return;this.reconnecting=!0;let t=++this.reconnectGeneration;p$.warn(`Leader WebSocket dropped — starting reconnect loop`,{reason:e}),this.tearDownSocket();let n=0,r=this.reconnectBaseDelayMs,i=e;for(;!this.stopped&&t===this.reconnectGeneration&&n<this.reconnectMaxAttempts&&(n++,C$({state:`reconnecting`,session:this.currentSession,error:null,reconnectAttempts:n}),this.options.onReconnecting?.(n,i),p$.info(`Leader reconnect attempt`,{attempt:n,delay:r}),await this.reconnectSleep(r),!(this.stopped||t!==this.reconnectGeneration));){try{let e=await this.connectOnce();if(this.stopped||t!==this.reconnectGeneration){this.tearDownSocket();break}this.reconnecting=!1,p$.info(`Leader reconnect successful`,{attempt:n,trayId:e.trayId}),this.options.onReconnected?.(e);return}catch(e){i=e instanceof Error?e.message:String(e),p$.warn(`Leader reconnect attempt failed`,{attempt:n,error:i}),this.tearDownSocket()}r=Math.min(r*this.reconnectBackoffMultiplier,this.reconnectMaxDelayMs)}!this.stopped&&t===this.reconnectGeneration&&(this.reconnecting=!1,this.currentSession=null,C$({state:`error`,session:null,error:`Leader reconnect failed after ${n} attempts: ${i}`,reconnectAttempts:n}),p$.warn(`Leader reconnect gave up`,{attempts:n,lastError:i}),this.options.onReconnectGaveUp?.(i,n))}async clearSession(){await this.store.clear()}sendControlMessage(e){if(!this.socket)throw Error(`Tray leader WebSocket is not connected`);this.socket.send(JSON.stringify(e))}async attachWithRecovery(e){try{return await this.claimLeaderSession(e)}catch(t){if(!e||!O$(t))throw t;return p$.warn(`Stored tray session is stale, creating a fresh tray`,{trayId:e.trayId,error:t instanceof Error?t.message:String(t)}),await this.store.clear(),this.claimLeaderSession(null)}}async claimLeaderSession(e){let t=e??await this.createTraySession(),n=await this.fetchJson(t.controllerUrl,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({controllerId:t.controllerId,leaderKey:t.leaderKey,runtime:this.options.runtime})});if(n.role!==`leader`||!n.leaderKey||!n.websocket?.url)throw Error(`Tray attach did not return leader access for controller ${n.controllerId}`);let r={...t,trayId:n.trayId,controllerId:n.controllerId,leaderKey:n.leaderKey,leaderWebSocketUrl:n.websocket.url,runtime:this.options.runtime};return await this.store.save(r),r}async createTraySession(){let e=await this.fetchJson(ro(this.options.workerBaseUrl,`tray`),{method:`POST`});return{workerBaseUrl:this.options.workerBaseUrl,trayId:e.trayId,createdAt:e.createdAt,controllerId:crypto.randomUUID(),controllerUrl:e.capabilities.controller.url,joinUrl:e.capabilities.join.url,webhookUrl:e.capabilities.webhook.url,runtime:this.options.runtime}}async openLeaderSocket(e){return await new Promise((t,n)=>{let r=this.webSocketFactory(e),i=!1,a=setTimeout(()=>{o(`Tray leader WebSocket timed out after ${this.connectTimeoutMs}ms waiting for leader.connected`);try{r.close(1e3,`leader.connected timeout`)}catch{}},this.connectTimeoutMs),o=e=>{i||(i=!0,clearTimeout(a),n(Error(e)))};r.addEventListener(`message`,e=>{let n=k$(e.data);if(n){if(n.type===`leader.connected`){i||(i=!0,clearTimeout(a),t(r));return}if(n.type===`pong`){p$.debug(`Tray leader heartbeat acknowledged`,{trayId:this.currentSession?.trayId});return}this.options.onControlMessage?.(n)}}),r.addEventListener(`close`,()=>o(`Tray leader WebSocket closed before leader.connected`)),r.addEventListener(`error`,()=>o(`Tray leader WebSocket failed before leader.connected`))})}startPingLoop(e){this.pingTimer&&clearInterval(this.pingTimer);let t=t=>{this.stopped||this.socket!==e||this.handleUnexpectedDisconnect(t).catch(e=>{p$.warn(`Leader reconnect loop crashed`,{error:e instanceof Error?e.message:String(e)})})},n=()=>{try{e.send(JSON.stringify({type:`ping`}))}catch(e){t(`Leader ping send failed: ${e instanceof Error?e.message:String(e)}`)}};n(),this.pingTimer=setInterval(n,this.pingIntervalMs),e.addEventListener(`close`,()=>t(`Leader WebSocket closed`)),e.addEventListener(`error`,()=>t(`Leader WebSocket errored`))}async fetchJson(e,t){let n=await this.fetchImpl(e,t);if(!n.ok)throw await D$.fromResponse(n);return await n.json()}},D$=class e extends Error{constructor(e,t,n){super(n),this.status=e,this.code=t,this.name=`LeaderTrayHttpError`}static async fromResponse(t){try{let n=await t.json();return new e(t.status,n.code??null,n.error??`Tray request failed (${t.status})`)}catch{return new e(t.status,null,`Tray request failed (${t.status})`)}}};function O$(e){return e instanceof D$&&[403,404,410].includes(e.status)}function k$(e){if(typeof e!=`string`)return null;try{return JSON.parse(e)}catch{return null}}function A$(e=fetch){return typeof chrome<`u`&&chrome?.runtime?.id?e:async(t,n={})=>{let r=typeof t==`string`?t:t.toString();try{if(new URL(r).origin===window.location.origin)return e(r,{...n,cache:`no-store`})}catch{}let i=new Headers(n.headers);i.set(`X-Target-URL`,r);let a=await e(`/api/fetch-proxy`,{...n,headers:i,cache:`no-store`});if(a.status===400||a.status===502){let e=`Proxy error ${a.status}`;try{e=(await a.json()).error??e}catch{}throw Error(e)}return a}}var j$=null;function M$(e){j$=e}function N$(){return j$?.()??[]}var P$=null;function F$(e){P$=e}function I$(){return P$??void 0}function L$(){return{stdout:`host - display or manage the current tray host status
3717
+ `,stderr:``,exitCode:0}}function h$(e=`convert`){return gR(e,async(t,n)=>{if(t.length===0||t.includes(`--help`)||t.includes(`-h`))return m$();let r=[],i=[],a=0;for(;a<t.length;){let n=t[a];if(n===`-resize`){if(a+1>=t.length||t[a+1].startsWith(`-`))return{stdout:``,stderr:`${e}: missing argument for -resize\n`,exitCode:1};i.push({type:`resize`,value:t[a+1]}),a+=2}else if(n===`-rotate`){if(a+1>=t.length||t[a+1].startsWith(`-`))return{stdout:``,stderr:`${e}: missing argument for -rotate\n`,exitCode:1};i.push({type:`rotate`,value:t[a+1]}),a+=2}else if(n===`-crop`){if(a+1>=t.length||t[a+1].startsWith(`-`))return{stdout:``,stderr:`${e}: missing argument for -crop\n`,exitCode:1};i.push({type:`crop`,value:t[a+1]}),a+=2}else if(n===`-quality`){if(a+1>=t.length||t[a+1].startsWith(`-`))return{stdout:``,stderr:`${e}: missing argument for -quality\n`,exitCode:1};i.push({type:`quality`,value:t[a+1]}),a+=2}else if(n.startsWith(`-`))return{stdout:``,stderr:`${e}: unsupported option ${n}\n`,exitCode:1};else r.push(n),a++}if(r.length!==2)return{stdout:``,stderr:`${e}: expected exactly one input file and one output file\n`,exitCode:1};let o=r[0],s=r[1];try{let e=n.fs.resolvePath(n.cwd,o),t=await n.fs.readFileBuffer(e),r=await Ee(),a=null;if(await r.ImageMagick.read(t,async e=>{for(let t of i)switch(t.type){case`resize`:{let n=t.value.match(/^(\d+)%$/);if(n){let t=parseInt(n[1],10),r=Math.round(e.width*t/100),i=Math.round(e.height*t/100);e.resize(r,i)}else{let n=t.value.endsWith(`!`),i=(n?t.value.slice(0,-1):t.value).split(`x`);if(i.length===2){let t=parseInt(i[0],10),a=parseInt(i[1],10);if(n){let n=new r.MagickGeometry(t,a);n.ignoreAspectRatio=!0,e.resize(n)}else e.resize(t,a)}else throw Error(`Invalid resize format: ${t.value}`)}break}case`rotate`:{let n=parseFloat(t.value);if(isNaN(n))throw Error(`Invalid rotation degrees: ${t.value}`);e.rotate(n);break}case`crop`:{if(!t.value.match(/^(\d+)x(\d+)\+(\d+)\+(\d+)$/))throw Error(`Invalid crop format: ${t.value} (expected WxH+X+Y)`);let n=new r.MagickGeometry(t.value);e.crop(n);break}case`quality`:{let n=parseInt(t.value,10);if(isNaN(n)||n<0||n>100)throw Error(`Invalid quality: ${t.value} (must be 0-100)`);e.quality=n;break}}let t=p$(s);e.write(t,e=>{a=e})}),!a)throw Error(`Failed to generate output image`);let c=n.fs.resolvePath(n.cwd,s);return await n.fs.writeFile(c,a),{stdout:``,stderr:``,exitCode:0}}catch(t){return{stdout:``,stderr:`${e}: ${t instanceof Error?t.message:String(t)}\n`,exitCode:1}}})}var g$=o(`tray-leader`),_$=`leader-tray-session`,v$=3e4,y$=1e4,b$=1e3,x$=3e4,S$=2,C$=20,w$={state:`inactive`,session:null,error:null};function T$(){return{...w$,session:w$.session?{...w$.session}:null}}function E$(e){w$={...e,session:e.session?{...e.session}:null}}var D$=class{constructor(e=_$){this.key=e}async load(){return O$(await ye(this.key))}async save(e){await we(this.key,JSON.stringify(e))}async clear(){await we(this.key,``)}};function O$(e){if(!e)return null;try{let t=JSON.parse(e);return typeof t.workerBaseUrl!=`string`||typeof t.trayId!=`string`||typeof t.createdAt!=`string`||typeof t.controllerId!=`string`||typeof t.controllerUrl!=`string`||typeof t.joinUrl!=`string`||typeof t.webhookUrl!=`string`||typeof t.runtime!=`string`?null:{workerBaseUrl:t.workerBaseUrl,trayId:t.trayId,createdAt:t.createdAt,controllerId:t.controllerId,controllerUrl:t.controllerUrl,joinUrl:t.joinUrl,webhookUrl:t.webhookUrl,leaderKey:typeof t.leaderKey==`string`?t.leaderKey:void 0,leaderWebSocketUrl:typeof t.leaderWebSocketUrl==`string`?t.leaderWebSocketUrl:null,runtime:t.runtime}}catch{return null}}var k$=class{store;fetchImpl;webSocketFactory;pingIntervalMs;connectTimeoutMs;reconnectEnabled;reconnectBaseDelayMs;reconnectMaxDelayMs;reconnectBackoffMultiplier;reconnectMaxAttempts;reconnectSleep;socket=null;pingTimer=null;currentSession=null;stopped=!1;reconnecting=!1;reconnectGeneration=0;constructor(e){this.options=e,this.store=e.store??new D$,this.fetchImpl=e.fetchImpl??N$(),this.webSocketFactory=e.webSocketFactory??(e=>new WebSocket(e)),this.pingIntervalMs=e.pingIntervalMs??v$,this.connectTimeoutMs=e.connectTimeoutMs??y$;let t=e.reconnect;this.reconnectEnabled=t!==!1;let n=t===!1||!t?{}:t;this.reconnectBaseDelayMs=n.baseDelayMs??b$,this.reconnectMaxDelayMs=n.maxDelayMs??x$,this.reconnectBackoffMultiplier=n.backoffMultiplier??S$,this.reconnectMaxAttempts=n.maxAttempts??C$,this.reconnectSleep=n.sleep??(e=>new Promise(t=>setTimeout(t,e)))}async start(){if(this.stopped=!1,this.currentSession&&this.socket)return E$({state:`leader`,session:this.currentSession,error:null}),this.currentSession;E$({state:`connecting`,session:null,error:null}),this.currentSession=null;try{let e=await this.connectOnce();return g$.info(`Leader joined tray`,{trayId:e.trayId,controllerId:e.controllerId,runtime:e.runtime}),e}catch(e){throw E$({state:`error`,session:this.currentSession,error:e instanceof Error?e.message:String(e)}),e}}stop(){this.stopped=!0,this.reconnecting=!1,this.reconnectGeneration++,this.tearDownSocket(),this.currentSession=null,E$({state:`inactive`,session:null,error:null})}tearDownSocket(){this.pingTimer&&=(clearInterval(this.pingTimer),null);let e=this.socket;if(this.socket=null,e)try{e.close()}catch{}}async connectOnce(){let e=await this.store.load(),t=e?.workerBaseUrl===this.options.workerBaseUrl?e:null,n=await this.attachWithRecovery(t);this.currentSession=n;let r=await this.openLeaderSocket(n.leaderWebSocketUrl);return this.socket=r,this.startPingLoop(r),E$({state:`leader`,session:n,error:null}),n}async handleUnexpectedDisconnect(e){if(this.stopped)return;if(!this.reconnectEnabled){g$.warn(`Leader WebSocket dropped and auto-reconnect is disabled`,{reason:e}),this.tearDownSocket(),this.currentSession=null,E$({state:`error`,session:null,error:`Leader WebSocket dropped: ${e}`});return}if(this.reconnecting)return;this.reconnecting=!0;let t=++this.reconnectGeneration;g$.warn(`Leader WebSocket dropped — starting reconnect loop`,{reason:e}),this.tearDownSocket();let n=0,r=this.reconnectBaseDelayMs,i=e;for(;!this.stopped&&t===this.reconnectGeneration&&n<this.reconnectMaxAttempts&&(n++,E$({state:`reconnecting`,session:this.currentSession,error:null,reconnectAttempts:n}),this.options.onReconnecting?.(n,i),g$.info(`Leader reconnect attempt`,{attempt:n,delay:r}),await this.reconnectSleep(r),!(this.stopped||t!==this.reconnectGeneration));){try{let e=await this.connectOnce();if(this.stopped||t!==this.reconnectGeneration){this.tearDownSocket();break}this.reconnecting=!1,g$.info(`Leader reconnect successful`,{attempt:n,trayId:e.trayId}),this.options.onReconnected?.(e);return}catch(e){i=e instanceof Error?e.message:String(e),g$.warn(`Leader reconnect attempt failed`,{attempt:n,error:i}),this.tearDownSocket()}r=Math.min(r*this.reconnectBackoffMultiplier,this.reconnectMaxDelayMs)}!this.stopped&&t===this.reconnectGeneration&&(this.reconnecting=!1,this.currentSession=null,E$({state:`error`,session:null,error:`Leader reconnect failed after ${n} attempts: ${i}`,reconnectAttempts:n}),g$.warn(`Leader reconnect gave up`,{attempts:n,lastError:i}),this.options.onReconnectGaveUp?.(i,n))}async clearSession(){await this.store.clear()}sendControlMessage(e){if(!this.socket)throw Error(`Tray leader WebSocket is not connected`);this.socket.send(JSON.stringify(e))}async attachWithRecovery(e){try{return await this.claimLeaderSession(e)}catch(t){if(!e||!j$(t))throw t;return g$.warn(`Stored tray session is stale, creating a fresh tray`,{trayId:e.trayId,error:t instanceof Error?t.message:String(t)}),await this.store.clear(),this.claimLeaderSession(null)}}async claimLeaderSession(e){let t=e??await this.createTraySession(),n=await this.fetchJson(t.controllerUrl,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({controllerId:t.controllerId,leaderKey:t.leaderKey,runtime:this.options.runtime})});if(n.role!==`leader`||!n.leaderKey||!n.websocket?.url)throw Error(`Tray attach did not return leader access for controller ${n.controllerId}`);let r={...t,trayId:n.trayId,controllerId:n.controllerId,leaderKey:n.leaderKey,leaderWebSocketUrl:n.websocket.url,runtime:this.options.runtime};return await this.store.save(r),r}async createTraySession(){let e=await this.fetchJson(ro(this.options.workerBaseUrl,`tray`),{method:`POST`});return{workerBaseUrl:this.options.workerBaseUrl,trayId:e.trayId,createdAt:e.createdAt,controllerId:crypto.randomUUID(),controllerUrl:e.capabilities.controller.url,joinUrl:e.capabilities.join.url,webhookUrl:e.capabilities.webhook.url,runtime:this.options.runtime}}async openLeaderSocket(e){return await new Promise((t,n)=>{let r=this.webSocketFactory(e),i=!1,a=setTimeout(()=>{o(`Tray leader WebSocket timed out after ${this.connectTimeoutMs}ms waiting for leader.connected`);try{r.close(1e3,`leader.connected timeout`)}catch{}},this.connectTimeoutMs),o=e=>{i||(i=!0,clearTimeout(a),n(Error(e)))};r.addEventListener(`message`,e=>{let n=M$(e.data);if(n){if(n.type===`leader.connected`){i||(i=!0,clearTimeout(a),t(r));return}if(n.type===`pong`){g$.debug(`Tray leader heartbeat acknowledged`,{trayId:this.currentSession?.trayId});return}this.options.onControlMessage?.(n)}}),r.addEventListener(`close`,()=>o(`Tray leader WebSocket closed before leader.connected`)),r.addEventListener(`error`,()=>o(`Tray leader WebSocket failed before leader.connected`))})}startPingLoop(e){this.pingTimer&&clearInterval(this.pingTimer);let t=t=>{this.stopped||this.socket!==e||this.handleUnexpectedDisconnect(t).catch(e=>{g$.warn(`Leader reconnect loop crashed`,{error:e instanceof Error?e.message:String(e)})})},n=()=>{try{e.send(JSON.stringify({type:`ping`}))}catch(e){t(`Leader ping send failed: ${e instanceof Error?e.message:String(e)}`)}};n(),this.pingTimer=setInterval(n,this.pingIntervalMs),e.addEventListener(`close`,()=>t(`Leader WebSocket closed`)),e.addEventListener(`error`,()=>t(`Leader WebSocket errored`))}async fetchJson(e,t){let n=await this.fetchImpl(e,t);if(!n.ok)throw await A$.fromResponse(n);return await n.json()}},A$=class e extends Error{constructor(e,t,n){super(n),this.status=e,this.code=t,this.name=`LeaderTrayHttpError`}static async fromResponse(t){try{let n=await t.json();return new e(t.status,n.code??null,n.error??`Tray request failed (${t.status})`)}catch{return new e(t.status,null,`Tray request failed (${t.status})`)}}};function j$(e){return e instanceof A$&&[403,404,410].includes(e.status)}function M$(e){if(typeof e!=`string`)return null;try{return JSON.parse(e)}catch{return null}}function N$(e=fetch){return typeof chrome<`u`&&chrome?.runtime?.id?e:async(t,n={})=>{let r=typeof t==`string`?t:t.toString();try{if(new URL(r).origin===window.location.origin)return e(r,{...n,cache:`no-store`})}catch{}let i=new Headers(n.headers);i.set(`X-Target-URL`,r);let a=await e(`/api/fetch-proxy`,{...n,headers:i,cache:`no-store`});if(JZ(a))throw Error(await YZ(a));return a}}var P$=null;function F$(e){P$=e}function I$(){return P$?.()??[]}var L$=null;function R$(e){L$=e}function z$(){return L$??void 0}function B$(){return{stdout:`host - display or manage the current tray host status
3718
3718
 
3719
3719
  Usage: host [reset]
3720
3720
 
@@ -3722,22 +3722,22 @@ Shows the current tray state (leader or follower) and, when available, the join
3722
3722
 
3723
3723
  Subcommands:
3724
3724
  reset Disconnect all followers and create a fresh tray session with a new join URL
3725
- `,stderr:``,exitCode:0}}function R$(e){if(e<60)return`${e}s ago`;let t=Math.floor(e/60);if(t<60)return`${t}m ago`;let n=Math.floor(t/60),r=t%60;return r===0?`${n}h ago`:`${n}h ${r}m ago`}function z$(e,t){let n=[`status: ${e.state}`];if(e.session?n.push(`join_url: ${e.session.joinUrl}`):n.push(`join_url: unavailable`),e.error&&n.push(`error: ${e.error}`),t.length>0){n.push(`followers:`);for(let e of t){let t=[e.runtimeId];if(e.runtime&&t.push(`(${e.runtime})`),e.connectedAt){let n=Math.round((Date.now()-new Date(e.connectedAt).getTime())/1e3);t.push(`connected ${R$(n)}`)}n.push(` - ${t.join(` `)}`)}}return`${n.join(`
3726
- `)}\n`}function B$(e){let t=[`status: follower (${e.state})`];if(e.joinUrl&&t.push(`join_url: ${e.joinUrl}`),e.state===`connecting`){if(e.connectingSince!=null){let n=Math.round((Date.now()-e.connectingSince)/1e3);t.push(`connecting_for: ${R$(n).replace(` ago`,``)}`)}e.attachAttempts>0&&t.push(`attach_attempts: ${e.attachAttempts}`),e.lastAttachCode&&t.push(`last_code: ${e.lastAttachCode}`)}if(e.state===`connected`&&e.lastPingTime!=null){let n=Math.round((Date.now()-e.lastPingTime)/1e3);t.push(`last_ping: ${n}s ago`)}return e.state===`reconnecting`&&e.reconnectAttempts>0&&t.push(`reconnect_attempts: ${e.reconnectAttempts}`),e.lastError&&t.push(`last_error: ${e.lastError}`),e.error&&t.push(`error: ${e.error}`),`${t.join(`
3727
- `)}\n`}function V$(e={}){let t=e.getStatus??S$,n=e.getFollowerStatus??go,r=e.getFollowers??N$;return gR(`host`,async i=>{if(i.includes(`--help`)||i.includes(`-h`))return L$();if(i[0]===`reset`)return H$(n,t,e.resetTray??I$());if(i.length>0)return{stdout:``,stderr:`host: unsupported arguments
3728
- `,exitCode:1};let a=n();return a.state===`inactive`?{stdout:z$(t(),r()),stderr:``,exitCode:0}:{stdout:B$(a),stderr:``,exitCode:0}})}async function H$(e,t,n){if(e().state!==`inactive`)return{stdout:``,stderr:`host reset: only the leader can reset the tray session
3725
+ `,stderr:``,exitCode:0}}function V$(e){if(e<60)return`${e}s ago`;let t=Math.floor(e/60);if(t<60)return`${t}m ago`;let n=Math.floor(t/60),r=t%60;return r===0?`${n}h ago`:`${n}h ${r}m ago`}function H$(e,t){let n=[`status: ${e.state}`];if(e.session?n.push(`join_url: ${e.session.joinUrl}`):n.push(`join_url: unavailable`),e.error&&n.push(`error: ${e.error}`),t.length>0){n.push(`followers:`);for(let e of t){let t=[e.runtimeId];if(e.runtime&&t.push(`(${e.runtime})`),e.connectedAt){let n=Math.round((Date.now()-new Date(e.connectedAt).getTime())/1e3);t.push(`connected ${V$(n)}`)}n.push(` - ${t.join(` `)}`)}}return`${n.join(`
3726
+ `)}\n`}function U$(e){let t=[`status: follower (${e.state})`];if(e.joinUrl&&t.push(`join_url: ${e.joinUrl}`),e.state===`connecting`){if(e.connectingSince!=null){let n=Math.round((Date.now()-e.connectingSince)/1e3);t.push(`connecting_for: ${V$(n).replace(` ago`,``)}`)}e.attachAttempts>0&&t.push(`attach_attempts: ${e.attachAttempts}`),e.lastAttachCode&&t.push(`last_code: ${e.lastAttachCode}`)}if(e.state===`connected`&&e.lastPingTime!=null){let n=Math.round((Date.now()-e.lastPingTime)/1e3);t.push(`last_ping: ${n}s ago`)}return e.state===`reconnecting`&&e.reconnectAttempts>0&&t.push(`reconnect_attempts: ${e.reconnectAttempts}`),e.lastError&&t.push(`last_error: ${e.lastError}`),e.error&&t.push(`error: ${e.error}`),`${t.join(`
3727
+ `)}\n`}function W$(e={}){let t=e.getStatus??T$,n=e.getFollowerStatus??go,r=e.getFollowers??I$;return gR(`host`,async i=>{if(i.includes(`--help`)||i.includes(`-h`))return B$();if(i[0]===`reset`)return G$(n,t,e.resetTray??z$());if(i.length>0)return{stdout:``,stderr:`host: unsupported arguments
3728
+ `,exitCode:1};let a=n();return a.state===`inactive`?{stdout:H$(t(),r()),stderr:``,exitCode:0}:{stdout:U$(a),stderr:``,exitCode:0}})}async function G$(e,t,n){if(e().state!==`inactive`)return{stdout:``,stderr:`host reset: only the leader can reset the tray session
3729
3729
  `,exitCode:1};let r=t();if(r.state!==`leader`&&r.state!==`error`)return{stdout:``,stderr:`host reset: no active tray session to reset
3730
3730
  `,exitCode:1};if(!n)return{stdout:``,stderr:`host reset: tray reset is not available in this environment
3731
3731
  `,exitCode:1};try{return{stdout:`Tray session reset. All followers disconnected.
3732
- `+z$(await n(),[]),stderr:``,exitCode:0}}catch(e){return{stdout:``,stderr:`host reset: ${e instanceof Error?e.message:String(e)}\n`,exitCode:1}}}function U$(){return{stdout:`imgcat - preview image and video files in the preview tab
3732
+ `+H$(await n(),[]),stderr:``,exitCode:0}}catch(e){return{stdout:``,stderr:`host reset: ${e instanceof Error?e.message:String(e)}\n`,exitCode:1}}}function K$(){return{stdout:`imgcat - preview image and video files in the preview tab
3733
3733
 
3734
3734
  Usage: imgcat <path> [path...]
3735
3735
 
3736
3736
  Options:
3737
3737
  -h, --help Show this help message
3738
- `,stderr:``,exitCode:0}}function W$(e={}){return gR(`imgcat`,async(t,n)=>{if(t.length===0||t.includes(`--help`)||t.includes(`-h`))return U$();if(typeof window>`u`||typeof document>`u`)return{stdout:``,stderr:`imgcat: browser APIs are unavailable in this environment
3738
+ `,stderr:``,exitCode:0}}function q$(e={}){return gR(`imgcat`,async(t,n)=>{if(t.length===0||t.includes(`--help`)||t.includes(`-h`))return K$();if(typeof window>`u`||typeof document>`u`)return{stdout:``,stderr:`imgcat: browser APIs are unavailable in this environment
3739
3739
  `,exitCode:1};if(!e.onMediaPreview)return{stdout:``,stderr:`imgcat: terminal preview is unavailable
3740
- `,exitCode:1};let r=[];for(let e of t){let t=n.fs.resolvePath(n.cwd,e);if(!(await n.fs.stat(t)).isFile)return{stdout:``,stderr:`imgcat: not a file: ${e}\n`,exitCode:1};let i=Ua(t);if(!Ka(i))return{stdout:``,stderr:`imgcat: unsupported media type: ${e}\n`,exitCode:1};let a=await n.fs.readFileBuffer(t),o=new Uint8Array(a.byteLength);o.set(a),r.push({path:t,mimeType:i,bytes:o})}try{return await e.onMediaPreview(r),{stdout:``,stderr:``,exitCode:0}}catch(e){return{stdout:``,stderr:`imgcat: ${e instanceof Error?e.message:String(e)}\n`,exitCode:1}}})}var G$=`0.29.3`,K$=`https://sql.js.org/dist/`;function q$(e,t){if(typeof t!=`string`||!/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(t))throw Error(`${e} must use an exact semver version in package.json`);return t}var J$=`https://cdn.jsdelivr.net/pyodide/v${q$(`pyodide`,G$)}/full/`,Y$=`v20.0.0-js-shim`,X$=`
3740
+ `,exitCode:1};let r=[];for(let e of t){let t=n.fs.resolvePath(n.cwd,e);if(!(await n.fs.stat(t)).isFile)return{stdout:``,stderr:`imgcat: not a file: ${e}\n`,exitCode:1};let i=Ua(t);if(!Ka(i))return{stdout:``,stderr:`imgcat: unsupported media type: ${e}\n`,exitCode:1};let a=await n.fs.readFileBuffer(t),o=new Uint8Array(a.byteLength);o.set(a),r.push({path:t,mimeType:i,bytes:o})}try{return await e.onMediaPreview(r),{stdout:``,stderr:``,exitCode:0}}catch(e){return{stdout:``,stderr:`imgcat: ${e instanceof Error?e.message:String(e)}\n`,exitCode:1}}})}var J$=`0.29.3`,Y$=`https://sql.js.org/dist/`;function X$(e,t){if(typeof t!=`string`||!/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(t))throw Error(`${e} must use an exact semver version in package.json`);return t}var Z$=`https://cdn.jsdelivr.net/pyodide/v${X$(`pyodide`,J$)}/full/`,Q$=`v20.0.0-js-shim`,$$=`
3741
3741
  import sys
3742
3742
  import traceback
3743
3743
 
@@ -3757,10 +3757,10 @@ except SystemExit as exc:
3757
3757
  except BaseException:
3758
3758
  traceback.print_exc()
3759
3759
  __slicc_exit_code = 1
3760
- `,Z$=null,Q$=null,$$=Object.create(null),e1=class extends Error{constructor(e){super(`Process exited with code ${e}`),this.code=e,this.name=`NodeExitError`}};function t1(e){let t=e.length>1&&e.endsWith(`/`)?e.slice(0,-1):e,n=t.lastIndexOf(`/`);return n>=0?t.slice(n+1):t}function n1(e){let t=e.lastIndexOf(`/`);return t<=0?`/`:e.slice(0,t)}function r1(e,t){return e===`/`?`/${t}`:`${e}/${t}`}function i1(e){if(/^(https?:\/\/|about:|file:|chrome:)/i.test(e))return!0;try{return new URL(e).protocol.length>0}catch{return!1}}function a1(e,t){return e===`/`?t.startsWith(`/`):t===e||t.startsWith(`${e}/`)}function o1(e){return Array.from(e).map(e=>e.toString(16).padStart(2,`0`)).join(``)}function s1(e){return e==null?``:e instanceof Uint8Array?`x'${o1(e)}'`:String(e)}function c1(e){return Ua(e)}function l1(e){let t=typeof chrome<`u`&&!!chrome?.runtime?.id,n=`/preview${e}`;return t?chrome.runtime.getURL(n):`${typeof window<`u`&&window.location?.origin?window.location.origin:`http://localhost:5710`}${n}`}function u1(e){return e.length===0||e.startsWith(`/`)?!1:!e.split(`/`).some(e=>e===`..`)}function d1(e,t){return k(`${e}/${t}`)}function f1(e){if(typeof e==`string`)return e;if(e==null)return String(e);try{return JSON.stringify(e)}catch{return String(e)}}function p1(e,t){let n=import.meta.resolve;if(typeof n==`function`)try{return new URL(`./`,n(e))}catch{}return new URL(t,import.meta.url)}async function m1(){return Z$||=(async()=>{let e=(await s(()=>import(`./sql-wasm-DsCCg8Gn.js`).then(e=>r(e.default,1)),__vite__mapDeps([5,4,6]))).default,t=typeof window>`u`?p1(`sql.js/dist/sql-wasm.js`,`../../../../../node_modules/sql.js/dist/`).toString():K$;return e({locateFile:e=>`${t}${e}`})})(),Z$}var h1=typeof chrome<`u`&&!!chrome?.runtime?.id;async function g1(){return Q$||=(async()=>{let{loadPyodide:e}=await s(async()=>{let{loadPyodide:e}=await import(`./pyodide-JXDzDQlX.js`);return{loadPyodide:e}},__vite__mapDeps([7,4,1])),t;return t=typeof window>`u`?decodeURIComponent(p1(`pyodide/pyodide.mjs`,`../../../../../node_modules/pyodide/`).pathname):h1?chrome.runtime.getURL(`pyodide/`):J$,e({indexURL:t,fullStdLib:!1})})(),Q$}var _1=new Set([`http`,`https`,`net`,`tls`,`dgram`,`dns`,`cluster`,`worker_threads`,`child_process`,`crypto`,`os`,`stream`,`zlib`,`vm`,`v8`,`perf_hooks`,`readline`,`repl`,`tty`,`inspector`]);function v1(e){let t=/\brequire\s*\(\s*(['"`])([^'"`\s]+)\1\s*\)/g,n=new Set,r;for(;(r=t.exec(e))!==null;)n.add(r[2]);return[...n]}function y1(){return{stdout:`usage: node -e <code> [args...]
3761
- `,stderr:``,exitCode:0}}function b1(){return{stdout:`${Y$}\n`,stderr:``,exitCode:0}}function x1(){return gR(`node`,async(e,t)=>{if(e.includes(`--help`)||e.includes(`-h`))return y1();if(e.includes(`--version`)||e.includes(`-v`))return b1();let n=``,r=`<stdin>`,i=[`node`];if(e.length>0&&(e[0]===`-e`||e[0]===`--eval`)){if(!e[1])return{stdout:``,stderr:`node: option requires an argument -- eval
3760
+ `,e1=null,t1=null,n1=Object.create(null),r1=class extends Error{constructor(e){super(`Process exited with code ${e}`),this.code=e,this.name=`NodeExitError`}};function i1(e){let t=e.length>1&&e.endsWith(`/`)?e.slice(0,-1):e,n=t.lastIndexOf(`/`);return n>=0?t.slice(n+1):t}function a1(e){let t=e.lastIndexOf(`/`);return t<=0?`/`:e.slice(0,t)}function o1(e,t){return e===`/`?`/${t}`:`${e}/${t}`}function s1(e){if(/^(https?:\/\/|about:|file:|chrome:)/i.test(e))return!0;try{return new URL(e).protocol.length>0}catch{return!1}}function c1(e,t){return e===`/`?t.startsWith(`/`):t===e||t.startsWith(`${e}/`)}function l1(e){return Array.from(e).map(e=>e.toString(16).padStart(2,`0`)).join(``)}function u1(e){return e==null?``:e instanceof Uint8Array?`x'${l1(e)}'`:String(e)}function d1(e){return Ua(e)}function f1(e){let t=typeof chrome<`u`&&!!chrome?.runtime?.id,n=`/preview${e}`;return t?chrome.runtime.getURL(n):`${typeof window<`u`&&window.location?.origin?window.location.origin:`http://localhost:5710`}${n}`}function p1(e){return e.length===0||e.startsWith(`/`)?!1:!e.split(`/`).some(e=>e===`..`)}function m1(e,t){return k(`${e}/${t}`)}function h1(e){if(typeof e==`string`)return e;if(e==null)return String(e);try{return JSON.stringify(e)}catch{return String(e)}}function g1(e,t){let n=import.meta.resolve;if(typeof n==`function`)try{return new URL(`./`,n(e))}catch{}return new URL(t,import.meta.url)}async function _1(){return e1||=(async()=>{let e=(await s(()=>import(`./sql-wasm-DsCCg8Gn.js`).then(e=>r(e.default,1)),__vite__mapDeps([5,4,6]))).default,t=typeof window>`u`?g1(`sql.js/dist/sql-wasm.js`,`../../../../../node_modules/sql.js/dist/`).toString():Y$;return e({locateFile:e=>`${t}${e}`})})(),e1}var v1=typeof chrome<`u`&&!!chrome?.runtime?.id;async function y1(){return t1||=(async()=>{let{loadPyodide:e}=await s(async()=>{let{loadPyodide:e}=await import(`./pyodide-JXDzDQlX.js`);return{loadPyodide:e}},__vite__mapDeps([7,4,1])),t;return t=typeof window>`u`?decodeURIComponent(g1(`pyodide/pyodide.mjs`,`../../../../../node_modules/pyodide/`).pathname):v1?chrome.runtime.getURL(`pyodide/`):Z$,e({indexURL:t,fullStdLib:!1})})(),t1}var b1=new Set([`http`,`https`,`net`,`tls`,`dgram`,`dns`,`cluster`,`worker_threads`,`child_process`,`crypto`,`os`,`stream`,`zlib`,`vm`,`v8`,`perf_hooks`,`readline`,`repl`,`tty`,`inspector`]);function x1(e){let t=/\brequire\s*\(\s*(['"`])([^'"`\s]+)\1\s*\)/g,n=new Set,r;for(;(r=t.exec(e))!==null;)n.add(r[2]);return[...n]}function S1(){return{stdout:`usage: node -e <code> [args...]
3761
+ `,stderr:``,exitCode:0}}function C1(){return{stdout:`${Q$}\n`,stderr:``,exitCode:0}}function w1(){return gR(`node`,async(e,t)=>{if(e.includes(`--help`)||e.includes(`-h`))return S1();if(e.includes(`--version`)||e.includes(`-v`))return C1();let n=``,r=`<stdin>`,i=[`node`];if(e.length>0&&(e[0]===`-e`||e[0]===`--eval`)){if(!e[1])return{stdout:``,stderr:`node: option requires an argument -- eval
3762
3762
  `,exitCode:9};n=e[1],r=`[eval]`,i=[`node`,...e.slice(2)]}else if(e.length>0&&!e[0].startsWith(`-`)){let a=e[0],o=t.fs.resolvePath(t.cwd,a);if(!await t.fs.exists(o))return{stdout:``,stderr:`node: cannot find module '${a}'\n`,exitCode:1};n=await t.fs.readFile(o),r=a,i=[`node`,a,...e.slice(1)]}else if(t.stdin.trim().length>0)n=t.stdin,r=`<stdin>`,i=[`node`];else if(e.length>0)return{stdout:``,stderr:`node: unsupported option '${e[0]}'\n`,exitCode:9};else return{stdout:``,stderr:`node: REPL mode is not supported in this environment; use node -e "code"
3763
- `,exitCode:9};let a=[],o=[],c=e=>{a.push(typeof e==`string`?e:String(e))},l=e=>{o.push(typeof e==`string`?e:String(e))},u={log:(...e)=>c(`${e.map(f1).join(` `)}\n`),info:(...e)=>c(`${e.map(f1).join(` `)}\n`),warn:(...e)=>l(`${e.map(f1).join(` `)}\n`),error:(...e)=>l(`${e.map(f1).join(` `)}\n`)},d={argv:i,env:Object.fromEntries(t.env.entries()),cwd:()=>t.cwd,exit:e=>{throw new e1(Number.isFinite(e)?Number(e):0)},stdout:{write:c},stderr:{write:l}},f={readFile:async e=>{let n=t.fs.resolvePath(t.cwd,e);return t.fs.readFile(n)},readFileBinary:async e=>{let n=t.fs.resolvePath(t.cwd,e);return t.fs.readFileBuffer(n)},writeFile:async(e,n)=>{let r=t.fs.resolvePath(t.cwd,e);await t.fs.writeFile(r,n)},writeFileBinary:async(e,n)=>{let r=t.fs.resolvePath(t.cwd,e),i=new Uint8Array(n.byteLength);i.set(n),await t.fs.writeFile(r,i)},readDir:async e=>{let n=t.fs.resolvePath(t.cwd,e);return t.fs.readdir(n)},exists:async e=>{let n=t.fs.resolvePath(t.cwd,e);return t.fs.exists(n)},fetchToFile:async(e,n)=>{if(typeof fetch>`u`)throw Error(`fetch is not available in this runtime`);let r=await fetch(e);if(!r.ok)throw Error(`fetch ${r.status} ${r.statusText}`);let i=new Uint8Array(await r.arrayBuffer()),a=t.fs.resolvePath(t.cwd,n);return await t.fs.writeFile(a,i),i.byteLength}},p=async e=>{if(!t.exec)throw Error(`exec is not available in this runtime`);let n=await t.exec(e,{cwd:t.cwd});return{stdout:n.stdout,stderr:n.stderr,exitCode:n.exitCode}},m=typeof chrome<`u`&&!!chrome?.runtime?.id;if(!m){let e=v1(n),t=new Set([`fs`,`process`,`buffer`]),r=e.map(e=>e.startsWith(`node:`)?e.slice(5):e).filter(e=>!t.has(e)&&!_1.has(e)),i=$$.__requireCache??=Object.create(null),a=r.filter(e=>!(e in i));if(a.length>0){let e=await Promise.allSettled(a.map(async e=>{let t=await s(()=>import(`https://esm.sh/`+e),[]);i[e]=t&&typeof t==`object`&&`default`in t?t.default:t}));for(let t=0;t<e.length;t++)if(e[t].status===`rejected`){let n=e[t].reason;l(`Warning: failed to pre-load require('${a[t]}'): ${n instanceof Error?n.message:String(n)}\n`)}}}let h=e=>{let t=e.startsWith(`node:`)?e.slice(5):e;if(t===`fs`)return f;if(t===`process`)return d;if(t===`buffer`)return{Buffer:globalThis.Buffer};if(t===`path`){let t=$$.__requireCache;if(t&&`path`in t)return t.path;if(t&&e in t)return t[e];throw Error(`require('${e}'): path module not pre-loaded. Add require('path') as a static import.`)}if(_1.has(t))throw Error(`require('${e}'): Node built-in '${t}' is not available in the browser environment.${{http:` Use fetch() instead.`,https:` Use fetch() instead.`,child_process:` Use exec() which is available as a shell bridge.`,crypto:` Use globalThis.crypto (Web Crypto API) instead.`}[t]||``}`);let n=$$.__requireCache;if(n&&e in n)return n[e];throw Error(`require('${e}'): module not pre-loaded. Use a string literal or await import('https://esm.sh/${e}') directly.`)},g={exports:{},filename:r};try{if(m){let e=`
3763
+ `,exitCode:9};let a=[],o=[],c=e=>{a.push(typeof e==`string`?e:String(e))},l=e=>{o.push(typeof e==`string`?e:String(e))},u={log:(...e)=>c(`${e.map(h1).join(` `)}\n`),info:(...e)=>c(`${e.map(h1).join(` `)}\n`),warn:(...e)=>l(`${e.map(h1).join(` `)}\n`),error:(...e)=>l(`${e.map(h1).join(` `)}\n`)},d={argv:i,env:Object.fromEntries(t.env.entries()),cwd:()=>t.cwd,exit:e=>{throw new r1(Number.isFinite(e)?Number(e):0)},stdout:{write:c},stderr:{write:l}},f={readFile:async e=>{let n=t.fs.resolvePath(t.cwd,e);return t.fs.readFile(n)},readFileBinary:async e=>{let n=t.fs.resolvePath(t.cwd,e);return t.fs.readFileBuffer(n)},writeFile:async(e,n)=>{let r=t.fs.resolvePath(t.cwd,e);await t.fs.writeFile(r,n)},writeFileBinary:async(e,n)=>{let r=t.fs.resolvePath(t.cwd,e),i=new Uint8Array(n.byteLength);i.set(n),await t.fs.writeFile(r,i)},readDir:async e=>{let n=t.fs.resolvePath(t.cwd,e);return t.fs.readdir(n)},exists:async e=>{let n=t.fs.resolvePath(t.cwd,e);return t.fs.exists(n)},fetchToFile:async(e,n)=>{if(typeof fetch>`u`)throw Error(`fetch is not available in this runtime`);let r=await fetch(e);if(!r.ok)throw Error(`fetch ${r.status} ${r.statusText}`);let i=new Uint8Array(await r.arrayBuffer()),a=t.fs.resolvePath(t.cwd,n);return await t.fs.writeFile(a,i),i.byteLength}},p=async e=>{if(!t.exec)throw Error(`exec is not available in this runtime`);let n=await t.exec(e,{cwd:t.cwd});return{stdout:n.stdout,stderr:n.stderr,exitCode:n.exitCode}},m=typeof chrome<`u`&&!!chrome?.runtime?.id;if(!m){let e=x1(n),t=new Set([`fs`,`process`,`buffer`]),r=e.map(e=>e.startsWith(`node:`)?e.slice(5):e).filter(e=>!t.has(e)&&!b1.has(e)),i=n1.__requireCache??=Object.create(null),a=r.filter(e=>!(e in i));if(a.length>0){let e=await Promise.allSettled(a.map(async e=>{let t=await s(()=>import(`https://esm.sh/`+e),[]);i[e]=t&&typeof t==`object`&&`default`in t?t.default:t}));for(let t=0;t<e.length;t++)if(e[t].status===`rejected`){let n=e[t].reason;l(`Warning: failed to pre-load require('${a[t]}'): ${n instanceof Error?n.message:String(n)}\n`)}}}let h=e=>{let t=e.startsWith(`node:`)?e.slice(5):e;if(t===`fs`)return f;if(t===`process`)return d;if(t===`buffer`)return{Buffer:globalThis.Buffer};if(t===`path`){let t=n1.__requireCache;if(t&&`path`in t)return t.path;if(t&&e in t)return t[e];throw Error(`require('${e}'): path module not pre-loaded. Add require('path') as a static import.`)}if(b1.has(t))throw Error(`require('${e}'): Node built-in '${t}' is not available in the browser environment.${{http:` Use fetch() instead.`,https:` Use fetch() instead.`,child_process:` Use exec() which is available as a shell bridge.`,crypto:` Use globalThis.crypto (Web Crypto API) instead.`}[t]||``}`);let n=n1.__requireCache;if(n&&e in n)return n[e];throw Error(`require('${e}'): module not pre-loaded. Use a string literal or await import('https://esm.sh/${e}') directly.`)},g={exports:{},filename:r};try{if(m){let e=`
3764
3764
  const __stdout = [];
3765
3765
  const __stderr = [];
3766
3766
  const __origConsole = { log: console.log, error: console.error, warn: console.warn, info: console.info };
@@ -3861,17 +3861,17 @@ except BaseException:
3861
3861
  console.info = __origConsole.info;
3862
3862
  return { stdout: __stdout.join(''), stderr: __stderr.join('') };
3863
3863
  `,r=document.querySelector(`iframe[data-js-tool]`);r||(r=document.createElement(`iframe`),r.style.display=`none`,r.dataset.jsTool=`true`,r.src=chrome.runtime.getURL(`sandbox.html`),document.body.appendChild(r),await new Promise(e=>{r.addEventListener(`load`,()=>e(),{once:!0})}));let a=`node-${Date.now()}-${Math.random().toString(36).slice(2)}`,o=e=>{let n=e.data;!n||n.type!==`vfs`||(async()=>{try{let e,i=n.args?.[0]?t.fs.resolvePath(t.cwd,n.args[0]):n.args?.[0];switch(n.op){case`readFile`:e=await t.fs.readFile(i);break;case`readFileBinary`:e=await t.fs.readFileBuffer(i);break;case`writeFile`:await t.fs.writeFile(i,n.args[1]),e=!0;break;case`writeFileBinary`:await t.fs.writeFile(i,n.binaryData??new Uint8Array),e=!0;break;case`readDir`:e=await t.fs.readdir(i);break;case`exists`:e=await t.fs.exists(i);break;case`stat`:{let n=await t.fs.stat(i);e={isDirectory:n.isDirectory,isFile:n.isFile,size:n.size};break}case`mkdir`:await t.fs.mkdir(i,{recursive:!0}),e=!0;break;case`rm`:await t.fs.rm(i,{recursive:!0}),e=!0;break}r.contentWindow.postMessage({type:`vfs_response`,id:n.id,result:e},`*`)}catch(e){let t=e instanceof Error?e.message:String(e);r.contentWindow.postMessage({type:`vfs_response`,id:n.id,error:t},`*`)}})()};window.addEventListener(`message`,o);let s=e=>{let t=e.data;!t||t.type!==`shell_exec`||(async()=>{try{let e=await p(t.command);r.contentWindow.postMessage({type:`shell_exec_response`,id:t.id,result:e},`*`)}catch(e){let n=e instanceof Error?e.message:String(e);r.contentWindow.postMessage({type:`shell_exec_response`,id:t.id,error:n},`*`)}})()};window.addEventListener(`message`,s);let c=e=>{let t=e.data;!t||t.type!==`fetch_proxy`||(async()=>{try{let e={method:t.init?.method??`GET`,cache:`no-store`};t.init?.headers&&(e.headers=t.init.headers),t.init?.body&&![`GET`,`HEAD`].includes(e.method)&&(e.body=t.init.body);let n=await fetch(t.url,e),i=await n.arrayBuffer(),a={};n.headers.forEach((e,t)=>{a[t]=e}),r.contentWindow.postMessage({type:`fetch_proxy_response`,id:t.id,status:n.status,statusText:n.statusText,headers:a,body:new Uint8Array(i)},`*`)}catch(e){let n=e instanceof Error?e.message:String(e);r.contentWindow.postMessage({type:`fetch_proxy_response`,id:t.id,error:n},`*`)}})()};window.addEventListener(`message`,c);let l=await new Promise((t,n)=>{let i,o=e=>{if(e.data?.type===`exec_result`&&e.data.id===a)if(window.removeEventListener(`message`,o),clearTimeout(i),e.data.error)t({stdout:``,stderr:e.data.error+`
3864
- `});else try{let n=JSON.parse(e.data.result);t({stdout:n.stdout||``,stderr:n.stderr||``})}catch{t({stdout:e.data.result||``,stderr:``})}};i=setTimeout(()=>{window.removeEventListener(`message`,o),n(Error(`node eval timed out (30s)`))},3e4),window.addEventListener(`message`,o),r.contentWindow.postMessage({type:`exec`,id:a,code:e},`*`)});return window.removeEventListener(`message`,o),window.removeEventListener(`message`,s),window.removeEventListener(`message`,c),{stdout:l.stdout,stderr:l.stderr,exitCode:+!!l.stderr}}let e=Object.getPrototypeOf(async function(){}).constructor;return await new e(`fs`,`process`,`console`,`require`,`module`,`exports`,`__state`,`exec`,`"use strict";\nconst globalThis = __state;\nconst global = __state;\n${n}`)(f,d,u,h,g,g.exports,$$,p),{stdout:a.join(``),stderr:o.join(``),exitCode:0}}catch(e){if(e instanceof e1)return{stdout:a.join(``),stderr:o.join(``),exitCode:e.code};let t=e instanceof Error?e.stack??e.message:String(e);return{stdout:a.join(``),stderr:`${o.join(``)}${t}\n`,exitCode:1}}})}var S1=[`--download`,`-d`,`--view`,`-v`];function C1(){return{stdout:`usage: open [--download|-d] [--view|-v] <url|path> [url|path...]
3864
+ `});else try{let n=JSON.parse(e.data.result);t({stdout:n.stdout||``,stderr:n.stderr||``})}catch{t({stdout:e.data.result||``,stderr:``})}};i=setTimeout(()=>{window.removeEventListener(`message`,o),n(Error(`node eval timed out (30s)`))},3e4),window.addEventListener(`message`,o),r.contentWindow.postMessage({type:`exec`,id:a,code:e},`*`)});return window.removeEventListener(`message`,o),window.removeEventListener(`message`,s),window.removeEventListener(`message`,c),{stdout:l.stdout,stderr:l.stderr,exitCode:+!!l.stderr}}let e=Object.getPrototypeOf(async function(){}).constructor;return await new e(`fs`,`process`,`console`,`require`,`module`,`exports`,`__state`,`exec`,`"use strict";\nconst globalThis = __state;\nconst global = __state;\n${n}`)(f,d,u,h,g,g.exports,n1,p),{stdout:a.join(``),stderr:o.join(``),exitCode:0}}catch(e){if(e instanceof r1)return{stdout:a.join(``),stderr:o.join(``),exitCode:e.code};let t=e instanceof Error?e.stack??e.message:String(e);return{stdout:a.join(``),stderr:`${o.join(``)}${t}\n`,exitCode:1}}})}var T1=[`--download`,`-d`,`--view`,`-v`];function E1(){return{stdout:`usage: open [--download|-d] [--view|-v] <url|path> [url|path...]
3865
3865
 
3866
3866
  VFS paths are served in a new browser tab via the preview service worker.
3867
3867
  URLs (http/https/etc.) are opened directly in a new tab.
3868
3868
  For app directories with a default entry file, prefer serve <dir>.
3869
3869
  --download, -d Force download instead of opening in a tab.
3870
3870
  --view, -v Return image inline so the agent can see it.
3871
- `,stderr:``,exitCode:0}}function w1(e){let t=``,n=8192;for(let r=0;r<e.length;r+=n)t+=String.fromCharCode(...e.subarray(r,r+n));return btoa(t)}function T1(){return gR(`open`,async(e,t)=>{if(e.length===0||e.includes(`--help`)||e.includes(`-h`))return C1();if(typeof window>`u`||typeof document>`u`)return{stdout:``,stderr:`open: browser APIs are unavailable in this environment
3872
- `,exitCode:1};let n=e.includes(`--download`)||e.includes(`-d`),r=e.includes(`--view`)||e.includes(`-v`),i=e.filter(e=>!S1.includes(e));if(i.length===0)return C1();let a=[];for(let e of i){if(i1(e)){window.open(e,`_blank`,`noopener,noreferrer`),a.push(`opened ${e}`);continue}let i=t.fs.resolvePath(t.cwd,e);if(i.endsWith(`.shtml`)){let e=typeof window<`u`?window.__slicc_sprinkleManager:void 0;if(e){let t=(i.split(`/`).pop()??``).replace(/\.shtml$/,``);try{await e.open(t),a.push(`opened sprinkle ${t} from ${i}`)}catch(e){return{stdout:``,stderr:`open: ${e instanceof Error?e.message:String(e)}\n`,exitCode:1}}}else{let e=l1(i);window.open(e,`_blank`,`noopener,noreferrer`),a.push(`opened ${i} → ${e}`)}continue}if(r){let n;try{n=await t.fs.stat(i)}catch{return{stdout:``,stderr:`open: no such file: ${e}\n`,exitCode:1}}if(!n.isFile)return{stdout:``,stderr:`open: not a file: ${e}\n`,exitCode:1};let r;try{r=await t.fs.readFileBuffer(i)}catch{return{stdout:``,stderr:`open: failed to read: ${e}\n`,exitCode:1}}let o=c1(i),s=w1(new Uint8Array(r));a.push(`${i} (${Math.round(r.byteLength/1024)} KB)\n<img:data:${o};base64,${s}>`)}else if(n){let n;try{n=await t.fs.stat(i)}catch{return{stdout:``,stderr:`open: no such file: ${e}\n`,exitCode:1}}if(!n.isFile)return{stdout:``,stderr:`open: not a file: ${e}\n`,exitCode:1};let r;try{r=await t.fs.readFileBuffer(i)}catch{return{stdout:``,stderr:`open: failed to read: ${e}\n`,exitCode:1}}let o=new Uint8Array(r.byteLength);o.set(r);let s=new Blob([o.buffer],{type:c1(i)}),c=URL.createObjectURL(s),l=document.createElement(`a`);l.href=c,l.download=t1(i)||`download`,l.style.display=`none`,document.body.appendChild(l),l.click(),document.body.removeChild(l),setTimeout(()=>URL.revokeObjectURL(c),0),a.push(`downloaded ${i}`)}else{let e=l1(i);window.open(e,`_blank`,`noopener,noreferrer`),a.push(`opened ${i} → ${e}`)}}return{stdout:a.join(`
3871
+ `,stderr:``,exitCode:0}}function D1(e){let t=``,n=8192;for(let r=0;r<e.length;r+=n)t+=String.fromCharCode(...e.subarray(r,r+n));return btoa(t)}function O1(){return gR(`open`,async(e,t)=>{if(e.length===0||e.includes(`--help`)||e.includes(`-h`))return E1();if(typeof window>`u`||typeof document>`u`)return{stdout:``,stderr:`open: browser APIs are unavailable in this environment
3872
+ `,exitCode:1};let n=e.includes(`--download`)||e.includes(`-d`),r=e.includes(`--view`)||e.includes(`-v`),i=e.filter(e=>!T1.includes(e));if(i.length===0)return E1();let a=[];for(let e of i){if(s1(e)){window.open(e,`_blank`,`noopener,noreferrer`),a.push(`opened ${e}`);continue}let i=t.fs.resolvePath(t.cwd,e);if(i.endsWith(`.shtml`)){let e=typeof window<`u`?window.__slicc_sprinkleManager:void 0;if(e){let t=(i.split(`/`).pop()??``).replace(/\.shtml$/,``);try{await e.open(t),a.push(`opened sprinkle ${t} from ${i}`)}catch(e){return{stdout:``,stderr:`open: ${e instanceof Error?e.message:String(e)}\n`,exitCode:1}}}else{let e=f1(i);window.open(e,`_blank`,`noopener,noreferrer`),a.push(`opened ${i} → ${e}`)}continue}if(r){let n;try{n=await t.fs.stat(i)}catch{return{stdout:``,stderr:`open: no such file: ${e}\n`,exitCode:1}}if(!n.isFile)return{stdout:``,stderr:`open: not a file: ${e}\n`,exitCode:1};let r;try{r=await t.fs.readFileBuffer(i)}catch{return{stdout:``,stderr:`open: failed to read: ${e}\n`,exitCode:1}}let o=d1(i),s=D1(new Uint8Array(r));a.push(`${i} (${Math.round(r.byteLength/1024)} KB)\n<img:data:${o};base64,${s}>`)}else if(n){let n;try{n=await t.fs.stat(i)}catch{return{stdout:``,stderr:`open: no such file: ${e}\n`,exitCode:1}}if(!n.isFile)return{stdout:``,stderr:`open: not a file: ${e}\n`,exitCode:1};let r;try{r=await t.fs.readFileBuffer(i)}catch{return{stdout:``,stderr:`open: failed to read: ${e}\n`,exitCode:1}}let o=new Uint8Array(r.byteLength);o.set(r);let s=new Blob([o.buffer],{type:d1(i)}),c=URL.createObjectURL(s),l=document.createElement(`a`);l.href=c,l.download=i1(i)||`download`,l.style.display=`none`,document.body.appendChild(l),l.click(),document.body.removeChild(l),setTimeout(()=>URL.revokeObjectURL(c),0),a.push(`downloaded ${i}`)}else{let e=f1(i);window.open(e,`_blank`,`noopener,noreferrer`),a.push(`opened ${i} → ${e}`)}}return{stdout:a.join(`
3873
3873
  `)+`
3874
- `,stderr:``,exitCode:0}})}var E1=null,D1=null;async function O1(){return E1||=s(()=>import(`./es-DAIH-mv9.js`),__vite__mapDeps([8,4,6])),E1}async function k1(){return D1||=s(()=>import(`./dist-BNEtmCAc2.js`),__vite__mapDeps([9,1])),D1}function A1(e){return e.endsWith(`right`)?{range:e.slice(0,-5),rotation:90}:e.endsWith(`left`)?{range:e.slice(0,-4),rotation:270}:e.endsWith(`down`)?{range:e.slice(0,-4),rotation:180}:{range:e}}function j1(e){let{range:t,rotation:n}=A1(e);if(/^\d+$/.test(t)){let e=parseInt(t,10);return{start:e,end:e,rotation:n}}let r=t.match(/^(\d+)-(\d+|end)$/);if(r)return{start:parseInt(r[1],10),end:r[2]===`end`?`end`:parseInt(r[2],10),rotation:n};throw Error(`Invalid page range: ${e}`)}function M1(e,t){let n=e.start,r=e.end;if(n<1||n>t)throw Error(`Page ${n} out of range (1-${t})`);let i=r===`end`?t:r;if(i<1||i>t)throw Error(`Page ${i} out of range (1-${t})`);if(i<n)throw Error(`Invalid range: ${n}-${i}`);let a=[];for(let e=n;e<=i;e++)a.push(e);return a}function N1(){return{stdout:`usage: pdftk <input.pdf> <operation> [args...]
3874
+ `,stderr:``,exitCode:0}})}var k1=null,A1=null;async function j1(){return k1||=s(()=>import(`./es-QZlqFBVD.js`),__vite__mapDeps([8,4,6])),k1}async function M1(){return A1||=s(()=>import(`./dist-BNEtmCAc2.js`),__vite__mapDeps([9,1])),A1}function N1(e){return e.endsWith(`right`)?{range:e.slice(0,-5),rotation:90}:e.endsWith(`left`)?{range:e.slice(0,-4),rotation:270}:e.endsWith(`down`)?{range:e.slice(0,-4),rotation:180}:{range:e}}function P1(e){let{range:t,rotation:n}=N1(e);if(/^\d+$/.test(t)){let e=parseInt(t,10);return{start:e,end:e,rotation:n}}let r=t.match(/^(\d+)-(\d+|end)$/);if(r)return{start:parseInt(r[1],10),end:r[2]===`end`?`end`:parseInt(r[2],10),rotation:n};throw Error(`Invalid page range: ${e}`)}function F1(e,t){let n=e.start,r=e.end;if(n<1||n>t)throw Error(`Page ${n} out of range (1-${t})`);let i=r===`end`?t:r;if(i<1||i>t)throw Error(`Page ${i} out of range (1-${t})`);if(i<n)throw Error(`Invalid range: ${n}-${i}`);let a=[];for(let e=n;e<=i;e++)a.push(e);return a}function I1(){return{stdout:`usage: pdftk <input.pdf> <operation> [args...]
3875
3875
 
3876
3876
  Operations:
3877
3877
  dump_data Print metadata (page count, title, author, etc.)
@@ -3895,14 +3895,14 @@ Page ranges:
3895
3895
  1-endright Pages 1 to end, rotated 90° clockwise
3896
3896
  3left Page 3 rotated 270° (counterclockwise)
3897
3897
  1-5down Pages 1-5 rotated 180°
3898
- `,stderr:``,exitCode:0}}function P1(e=`pdftk`){return gR(e,async(t,n)=>{if(t.length===0||t.includes(`--help`)||t.includes(`-h`))return N1();try{let r=[],i=0;for(;i<t.length;){let e=t[i],a=e.match(/^([A-Z])=(.+)$/);if(a){let e=a[1],t=n.fs.resolvePath(n.cwd,a[2]);r.push({handle:e,path:t}),i++;continue}if([`dump_data`,`dump_data_utf8`,`cat`,`rotate`].includes(e))break;if(!e.startsWith(`-`)){let t=n.fs.resolvePath(n.cwd,e);r.push({handle:``,path:t}),i++;continue}break}if(r.length===0)return{stdout:``,stderr:`${e}: no input PDF specified\n`,exitCode:1};let a=t[i];if(i++,!a)return{stdout:``,stderr:`${e}: no operation specified\n`,exitCode:1};if(a===`dump_data`){if(r.length>1)return{stdout:``,stderr:`${e}: dump_data only supports a single input file\n`,exitCode:1};let t=await O1(),i=await n.fs.readFileBuffer(r[0].path),a=await t.PDFDocument.load(i),o=[];o.push(`NumberOfPages: ${a.getPageCount()}`);let s=a.getTitle();s&&o.push(`InfoBegin`),s&&o.push(`InfoKey: Title`),s&&o.push(`InfoValue: ${s}`);let c=a.getAuthor();c&&o.push(`InfoBegin`),c&&o.push(`InfoKey: Author`),c&&o.push(`InfoValue: ${c}`);let l=a.getCreator();l&&o.push(`InfoBegin`),l&&o.push(`InfoKey: Creator`),l&&o.push(`InfoValue: ${l}`);let u=a.getProducer();return u&&o.push(`InfoBegin`),u&&o.push(`InfoKey: Producer`),u&&o.push(`InfoValue: ${u}`),{stdout:o.join(`
3898
+ `,stderr:``,exitCode:0}}function L1(e=`pdftk`){return gR(e,async(t,n)=>{if(t.length===0||t.includes(`--help`)||t.includes(`-h`))return I1();try{let r=[],i=0;for(;i<t.length;){let e=t[i],a=e.match(/^([A-Z])=(.+)$/);if(a){let e=a[1],t=n.fs.resolvePath(n.cwd,a[2]);r.push({handle:e,path:t}),i++;continue}if([`dump_data`,`dump_data_utf8`,`cat`,`rotate`].includes(e))break;if(!e.startsWith(`-`)){let t=n.fs.resolvePath(n.cwd,e);r.push({handle:``,path:t}),i++;continue}break}if(r.length===0)return{stdout:``,stderr:`${e}: no input PDF specified\n`,exitCode:1};let a=t[i];if(i++,!a)return{stdout:``,stderr:`${e}: no operation specified\n`,exitCode:1};if(a===`dump_data`){if(r.length>1)return{stdout:``,stderr:`${e}: dump_data only supports a single input file\n`,exitCode:1};let t=await j1(),i=await n.fs.readFileBuffer(r[0].path),a=await t.PDFDocument.load(i),o=[];o.push(`NumberOfPages: ${a.getPageCount()}`);let s=a.getTitle();s&&o.push(`InfoBegin`),s&&o.push(`InfoKey: Title`),s&&o.push(`InfoValue: ${s}`);let c=a.getAuthor();c&&o.push(`InfoBegin`),c&&o.push(`InfoKey: Author`),c&&o.push(`InfoValue: ${c}`);let l=a.getCreator();l&&o.push(`InfoBegin`),l&&o.push(`InfoKey: Creator`),l&&o.push(`InfoValue: ${l}`);let u=a.getProducer();return u&&o.push(`InfoBegin`),u&&o.push(`InfoKey: Producer`),u&&o.push(`InfoValue: ${u}`),{stdout:o.join(`
3899
3899
  `)+`
3900
- `,stderr:``,exitCode:0}}if(a===`dump_data_utf8`){if(r.length>1)return{stdout:``,stderr:`${e}: dump_data_utf8 only supports a single input file\n`,exitCode:1};let t=await k1(),i=await n.fs.readFileBuffer(r[0].path);return{stdout:(await t.extractText(i)).text+`
3901
- `,stderr:``,exitCode:0}}if(a===`cat`){let a=await O1(),o=await a.PDFDocument.create(),s=t.slice(i),c=s.indexOf(`output`);if(c===-1)return{stdout:``,stderr:`${e}: cat operation requires 'output <filename>'\n`,exitCode:1};let l=s.slice(0,c),u=s[c+1];if(!u)return{stdout:``,stderr:`${e}: output filename not specified\n`,exitCode:1};let d=n.fs.resolvePath(n.cwd,u),f=new Map;for(let e of r){let t=await n.fs.readFileBuffer(e.path),r=await a.PDFDocument.load(t),i=e.handle||`default`;f.set(i,r)}for(let t of l){if(/^[A-Z]$/.test(t)){let n=f.get(t);if(!n)return{stdout:``,stderr:`${e}: unknown handle '${t}'\n`,exitCode:1};let r=n.getPageCount(),i=Array.from({length:r},(e,t)=>t);(await o.copyPages(n,i)).forEach(e=>o.addPage(e));continue}let n=f.get(r[0].handle||`default`);if(!n)return{stdout:``,stderr:`${e}: no default input document\n`,exitCode:1};let i=n.getPageCount(),s=j1(t),c=M1(s,i).map(e=>e-1),l=await o.copyPages(n,c);for(let e of l)s.rotation&&e.setRotation(a.degrees(s.rotation)),o.addPage(e)}let p=await o.save();return await n.fs.writeFile(d,p),{stdout:`Created ${u}\n`,stderr:``,exitCode:0}}if(a===`rotate`){if(r.length>1)return{stdout:``,stderr:`${e}: rotate only supports a single input file\n`,exitCode:1};let a=await O1(),o=await n.fs.readFileBuffer(r[0].path),s=await a.PDFDocument.load(o),c=t.slice(i),l=c.indexOf(`output`);if(l===-1)return{stdout:``,stderr:`${e}: rotate operation requires 'output <filename>'\n`,exitCode:1};let u=c.slice(0,l),d=c[l+1];if(!d)return{stdout:``,stderr:`${e}: output filename not specified\n`,exitCode:1};let f=n.fs.resolvePath(n.cwd,d),p=s.getPageCount(),m=new Map;for(let t of u){let n=j1(t);if(!n.rotation)return{stdout:``,stderr:`${e}: rotation suffix required (right/left/down) for range '${t}'\n`,exitCode:1};let r=M1(n,p);for(let e of r)m.set(e-1,n.rotation)}let h=s.getPages();for(let[e,t]of m.entries()){let n=h[e],r=(n.getRotation().angle+t)%360;n.setRotation(a.degrees(r))}let g=await s.save();return await n.fs.writeFile(f,g),{stdout:`Created ${d}\n`,stderr:``,exitCode:0}}return{stdout:``,stderr:`${e}: unknown operation '${a}'\n`,exitCode:1}}catch(t){return{stdout:``,stderr:`${e}: ${t instanceof Error?t.message:String(t)}\n`,exitCode:1}}})}async function F1(e,t,n){let r=t.FS;function i(e){try{r.stat(e)}catch{r.mkdirTree(e)}}async function a(t){i(t);let n;try{n=await e.readdir(t)}catch{return}for(let o of n){let n=t===`/`?`/${o}`:`${t}/${o}`;try{if((await e.stat(n)).isDirectory)await a(n);else{let a=await e.readFile(n);i(t),r.writeFile(n,a)}}catch{}}}for(let e of n)await a(e)}async function I1(e,t,n){let r=t.FS;async function i(t){let n;try{n=r.readdir(t).filter(e=>e!==`.`&&e!==`..`)}catch{return}for(let a of n){let n=t===`/`?`/${a}`:`${t}/${a}`;try{let a=r.stat(n);if(r.isDir(a.mode))await e.mkdir(n,{recursive:!0}),await i(n);else{let i=new TextDecoder().decode(r.readFile(n));await e.mkdir(t,{recursive:!0}),await e.writeFile(n,i)}}catch{}}}for(let e of n)await i(e)}function L1(){return{stdout:`usage: python3 [-c code | script.py] [args...]
3902
- `,stderr:``,exitCode:0}}function R1(){return{stdout:`Python 3.12 (Pyodide)
3903
- `,stderr:``,exitCode:0}}function z1(e){return gR(e,async(t,n)=>{if(t.includes(`--help`)||t.includes(`-h`))return L1();if(t.includes(`--version`)||t.includes(`-V`))return R1();let r=``,i=`<stdin>`,a=[`python3`];if(t[0]===`-c`){if(!t[1])return{stdout:``,stderr:`${e}: option requires an argument -- 'c'\n`,exitCode:2};r=t[1],i=`-c`,a=[`-c`,...t.slice(2)]}else if(t.length>0&&!t[0].startsWith(`-`)){let o=t[0],s=n.fs.resolvePath(n.cwd,o);if(!await n.fs.exists(s))return{stdout:``,stderr:`${e}: can't open file '${o}': [Errno 2] No such file or directory\n`,exitCode:2};r=await n.fs.readFile(s),i=o,a=[o,...t.slice(1)]}else if(n.stdin.trim().length>0)r=n.stdin,i=`<stdin>`,a=[`<stdin>`];else if(t.length>0)return{stdout:``,stderr:`${e}: unsupported option '${t[0]}'\n`,exitCode:2};else return{stdout:``,stderr:`${e}: no input provided (use -c CODE, script path, or stdin)\n`,exitCode:2};try{let e=await g1(),t=[],o=[],s=[n.cwd,`/tmp`];if(i!==`<stdin>`&&i!==`[eval]`){let e=i.includes(`/`)?i.slice(0,i.lastIndexOf(`/`)):n.cwd;s.includes(e)||s.push(e)}await F1(n.fs,e,s);try{e.FS.chdir(n.cwd)}catch{}e.setStdout({batched:e=>t.push(e+`
3900
+ `,stderr:``,exitCode:0}}if(a===`dump_data_utf8`){if(r.length>1)return{stdout:``,stderr:`${e}: dump_data_utf8 only supports a single input file\n`,exitCode:1};let t=await M1(),i=await n.fs.readFileBuffer(r[0].path);return{stdout:(await t.extractText(i)).text+`
3901
+ `,stderr:``,exitCode:0}}if(a===`cat`){let a=await j1(),o=await a.PDFDocument.create(),s=t.slice(i),c=s.indexOf(`output`);if(c===-1)return{stdout:``,stderr:`${e}: cat operation requires 'output <filename>'\n`,exitCode:1};let l=s.slice(0,c),u=s[c+1];if(!u)return{stdout:``,stderr:`${e}: output filename not specified\n`,exitCode:1};let d=n.fs.resolvePath(n.cwd,u),f=new Map;for(let e of r){let t=await n.fs.readFileBuffer(e.path),r=await a.PDFDocument.load(t),i=e.handle||`default`;f.set(i,r)}for(let t of l){if(/^[A-Z]$/.test(t)){let n=f.get(t);if(!n)return{stdout:``,stderr:`${e}: unknown handle '${t}'\n`,exitCode:1};let r=n.getPageCount(),i=Array.from({length:r},(e,t)=>t);(await o.copyPages(n,i)).forEach(e=>o.addPage(e));continue}let n=f.get(r[0].handle||`default`);if(!n)return{stdout:``,stderr:`${e}: no default input document\n`,exitCode:1};let i=n.getPageCount(),s=P1(t),c=F1(s,i).map(e=>e-1),l=await o.copyPages(n,c);for(let e of l)s.rotation&&e.setRotation(a.degrees(s.rotation)),o.addPage(e)}let p=await o.save();return await n.fs.writeFile(d,p),{stdout:`Created ${u}\n`,stderr:``,exitCode:0}}if(a===`rotate`){if(r.length>1)return{stdout:``,stderr:`${e}: rotate only supports a single input file\n`,exitCode:1};let a=await j1(),o=await n.fs.readFileBuffer(r[0].path),s=await a.PDFDocument.load(o),c=t.slice(i),l=c.indexOf(`output`);if(l===-1)return{stdout:``,stderr:`${e}: rotate operation requires 'output <filename>'\n`,exitCode:1};let u=c.slice(0,l),d=c[l+1];if(!d)return{stdout:``,stderr:`${e}: output filename not specified\n`,exitCode:1};let f=n.fs.resolvePath(n.cwd,d),p=s.getPageCount(),m=new Map;for(let t of u){let n=P1(t);if(!n.rotation)return{stdout:``,stderr:`${e}: rotation suffix required (right/left/down) for range '${t}'\n`,exitCode:1};let r=F1(n,p);for(let e of r)m.set(e-1,n.rotation)}let h=s.getPages();for(let[e,t]of m.entries()){let n=h[e],r=(n.getRotation().angle+t)%360;n.setRotation(a.degrees(r))}let g=await s.save();return await n.fs.writeFile(f,g),{stdout:`Created ${d}\n`,stderr:``,exitCode:0}}return{stdout:``,stderr:`${e}: unknown operation '${a}'\n`,exitCode:1}}catch(t){return{stdout:``,stderr:`${e}: ${t instanceof Error?t.message:String(t)}\n`,exitCode:1}}})}async function R1(e,t,n){let r=t.FS;function i(e){try{r.stat(e)}catch{r.mkdirTree(e)}}async function a(t){i(t);let n;try{n=await e.readdir(t)}catch{return}for(let o of n){let n=t===`/`?`/${o}`:`${t}/${o}`;try{if((await e.stat(n)).isDirectory)await a(n);else{let a=await e.readFile(n);i(t),r.writeFile(n,a)}}catch{}}}for(let e of n)await a(e)}async function z1(e,t,n){let r=t.FS;async function i(t){let n;try{n=r.readdir(t).filter(e=>e!==`.`&&e!==`..`)}catch{return}for(let a of n){let n=t===`/`?`/${a}`:`${t}/${a}`;try{let a=r.stat(n);if(r.isDir(a.mode))await e.mkdir(n,{recursive:!0}),await i(n);else{let i=new TextDecoder().decode(r.readFile(n));await e.mkdir(t,{recursive:!0}),await e.writeFile(n,i)}}catch{}}}for(let e of n)await i(e)}function B1(){return{stdout:`usage: python3 [-c code | script.py] [args...]
3902
+ `,stderr:``,exitCode:0}}function V1(){return{stdout:`Python 3.12 (Pyodide)
3903
+ `,stderr:``,exitCode:0}}function H1(e){return gR(e,async(t,n)=>{if(t.includes(`--help`)||t.includes(`-h`))return B1();if(t.includes(`--version`)||t.includes(`-V`))return V1();let r=``,i=`<stdin>`,a=[`python3`];if(t[0]===`-c`){if(!t[1])return{stdout:``,stderr:`${e}: option requires an argument -- 'c'\n`,exitCode:2};r=t[1],i=`-c`,a=[`-c`,...t.slice(2)]}else if(t.length>0&&!t[0].startsWith(`-`)){let o=t[0],s=n.fs.resolvePath(n.cwd,o);if(!await n.fs.exists(s))return{stdout:``,stderr:`${e}: can't open file '${o}': [Errno 2] No such file or directory\n`,exitCode:2};r=await n.fs.readFile(s),i=o,a=[o,...t.slice(1)]}else if(n.stdin.trim().length>0)r=n.stdin,i=`<stdin>`,a=[`<stdin>`];else if(t.length>0)return{stdout:``,stderr:`${e}: unsupported option '${t[0]}'\n`,exitCode:2};else return{stdout:``,stderr:`${e}: no input provided (use -c CODE, script path, or stdin)\n`,exitCode:2};try{let e=await y1(),t=[],o=[],s=[n.cwd,`/tmp`];if(i!==`<stdin>`&&i!==`[eval]`){let e=i.includes(`/`)?i.slice(0,i.lastIndexOf(`/`)):n.cwd;s.includes(e)||s.push(e)}await R1(n.fs,e,s);try{e.FS.chdir(n.cwd)}catch{}e.setStdout({batched:e=>t.push(e+`
3904
3904
  `)}),e.setStderr({batched:e=>o.push(e+`
3905
- `)});let c=!1;e.setStdin({stdin:()=>c||!n.stdin?null:(c=!0,n.stdin)}),e.globals.set(`__slicc_code`,r),e.globals.set(`__slicc_filename`,i),e.globals.set(`__slicc_argv`,a),await e.runPythonAsync(X$);let l=e.globals.get(`__slicc_exit_code`),u=typeof l==`number`?l:Number(l??1);try{e.runPython(`del __slicc_code, __slicc_filename, __slicc_argv, __slicc_exit_code`)}catch{}return await I1(n.fs,e,s),{stdout:t.join(``),stderr:o.join(``),exitCode:u}}catch(t){return{stdout:``,stderr:`${e}: ${t instanceof Error?t.message:String(t)}\n`,exitCode:1}}})}function B1(){return{stdout:`usage: serve [--entry <relative-path>] [--project] <directory>
3905
+ `)});let c=!1;e.setStdin({stdin:()=>c||!n.stdin?null:(c=!0,n.stdin)}),e.globals.set(`__slicc_code`,r),e.globals.set(`__slicc_filename`,i),e.globals.set(`__slicc_argv`,a),await e.runPythonAsync($$);let l=e.globals.get(`__slicc_exit_code`),u=typeof l==`number`?l:Number(l??1);try{e.runPython(`del __slicc_code, __slicc_filename, __slicc_argv, __slicc_exit_code`)}catch{}return await z1(n.fs,e,s),{stdout:t.join(``),stderr:o.join(``),exitCode:u}}catch(t){return{stdout:``,stderr:`${e}: ${t instanceof Error?t.message:String(t)}\n`,exitCode:1}}})}function U1(){return{stdout:`usage: serve [--entry <relative-path>] [--project] <directory>
3906
3906
 
3907
3907
  Serve a VFS directory in a new browser tab via the preview service worker.
3908
3908
  Defaults to index.html inside the target directory.
@@ -3911,23 +3911,23 @@ Page ranges:
3911
3911
  --project Enable project serve mode. Root-relative paths (/scripts/,
3912
3912
  /styles/, etc.) resolve against the served directory.
3913
3913
  Use this for frameworks like EDS that expect a local dev server.
3914
- `,stderr:``,exitCode:0}}function V1(e){let t=`index.html`,n,r=!1;for(let i=0;i<e.length;i+=1){let a=e[i];if(a===`--entry`){let n=e[i+1];if(!n)return{entry:t,project:r,error:`serve: missing value for --entry
3914
+ `,stderr:``,exitCode:0}}function W1(e){let t=`index.html`,n,r=!1;for(let i=0;i<e.length;i+=1){let a=e[i];if(a===`--entry`){let n=e[i+1];if(!n)return{entry:t,project:r,error:`serve: missing value for --entry
3915
3915
  `};t=n,i+=1;continue}if(a.startsWith(`--entry=`)){t=a.slice(8);continue}if(a===`--project`){r=!0;continue}if(a.startsWith(`-`))return{entry:t,project:r,error:`serve: unknown option: ${a}\n`};if(n)return{entry:t,project:r,error:`serve: expected a single directory argument
3916
- `};n=a}return{directory:n,entry:t,project:r}}function H1(e,t){return gR(`serve`,async(n,r)=>{if(n.length===0||n.includes(`--help`)||n.includes(`-h`))return B1();let i=typeof window<`u`&&typeof window.open==`function`;if(!e&&!i)return{stdout:``,stderr:`serve: browser APIs are unavailable in this environment
3917
- `,exitCode:1};let a=V1(n);if(a.error)return{stdout:``,stderr:a.error,exitCode:1};if(!a.directory)return B1();if(!u1(a.entry))return{stdout:``,stderr:`serve: invalid entry file: ${a.entry}\n`,exitCode:1};let o=r.fs.resolvePath(r.cwd,a.directory),s;try{s=await r.fs.stat(o)}catch{return{stdout:``,stderr:`serve: no such directory: ${a.directory}\n`,exitCode:1}}if(!s.isDirectory)return{stdout:``,stderr:`serve: not a directory: ${a.directory}\n`,exitCode:1};let c=d1(o,a.entry),l;try{l=await r.fs.stat(c)}catch{return{stdout:``,stderr:`serve: entry file not found: ${c}\n`,exitCode:1}}if(!l.isFile)return{stdout:``,stderr:`serve: entry is not a file: ${c}\n`,exitCode:1};let u=l1(c);if(a.project&&(u+=`?projectRoot=${encodeURIComponent(o)}`),e&&t){let t=await e.createPage(u);return{stdout:`serving ${o} → ${u} (targetId: ${t})\nUse: playwright-cli <command> --tab ${t}\n`,stderr:``,exitCode:0}}return typeof window<`u`&&typeof window.open==`function`&&window.open(u,`_blank`,`noopener,noreferrer`),{stdout:`serving ${o} → ${u}\n`,stderr:``,exitCode:0}})}function U1(){return{stdout:`usage: sqlite3 [database] [sql]
3918
- `,stderr:``,exitCode:0}}function W1(e=`sqlite3`){return gR(e,async(t,n)=>{if(t.includes(`--help`)||t.includes(`-h`))return U1();let r=`:memory:`,i=t;t.length>0&&!t[0].startsWith(`-`)&&(r=t[0],i=t.slice(1));let a=i.join(` `).trim()||n.stdin.trim();if(!a)return{stdout:``,stderr:`${e}: interactive mode is not supported; provide SQL as argument or stdin\n`,exitCode:1};try{let e=await m1(),t=r===`:memory:`,i=t?`:memory:`:n.fs.resolvePath(n.cwd,r),o;!t&&await n.fs.exists(i)&&(o=await n.fs.readFileBuffer(i));let s=o?new e.Database(o):new e.Database,c=s.exec(a);t||await n.fs.writeFile(i,s.export()),s.close();let l=[];for(let e of c)for(let t of e.values)l.push(t.map(s1).join(`|`));return{stdout:l.length>0?`${l.join(`
3919
- `)}\n`:``,stderr:``,exitCode:0}}catch(t){return{stdout:``,stderr:`${e}: ${t instanceof Error?t.message:String(t)}\n`,exitCode:1}}})}function G1(){return{stdout:`usage: uname
3920
- `,stderr:``,exitCode:0}}function K1(){return gR(`uname`,async e=>{if(e.includes(`--help`)||e.includes(`-h`))return G1();if(e.length>0)return{stdout:``,stderr:`uname: unsupported arguments
3916
+ `};n=a}return{directory:n,entry:t,project:r}}function G1(e,t){return gR(`serve`,async(n,r)=>{if(n.length===0||n.includes(`--help`)||n.includes(`-h`))return U1();let i=typeof window<`u`&&typeof window.open==`function`;if(!e&&!i)return{stdout:``,stderr:`serve: browser APIs are unavailable in this environment
3917
+ `,exitCode:1};let a=W1(n);if(a.error)return{stdout:``,stderr:a.error,exitCode:1};if(!a.directory)return U1();if(!p1(a.entry))return{stdout:``,stderr:`serve: invalid entry file: ${a.entry}\n`,exitCode:1};let o=r.fs.resolvePath(r.cwd,a.directory),s;try{s=await r.fs.stat(o)}catch{return{stdout:``,stderr:`serve: no such directory: ${a.directory}\n`,exitCode:1}}if(!s.isDirectory)return{stdout:``,stderr:`serve: not a directory: ${a.directory}\n`,exitCode:1};let c=m1(o,a.entry),l;try{l=await r.fs.stat(c)}catch{return{stdout:``,stderr:`serve: entry file not found: ${c}\n`,exitCode:1}}if(!l.isFile)return{stdout:``,stderr:`serve: entry is not a file: ${c}\n`,exitCode:1};let u=f1(c);if(a.project&&(u+=`?projectRoot=${encodeURIComponent(o)}`),e&&t){let t=await e.createPage(u);return{stdout:`serving ${o} → ${u} (targetId: ${t})\nUse: playwright-cli <command> --tab ${t}\n`,stderr:``,exitCode:0}}return typeof window<`u`&&typeof window.open==`function`&&window.open(u,`_blank`,`noopener,noreferrer`),{stdout:`serving ${o} → ${u}\n`,stderr:``,exitCode:0}})}function K1(){return{stdout:`usage: sqlite3 [database] [sql]
3918
+ `,stderr:``,exitCode:0}}function q1(e=`sqlite3`){return gR(e,async(t,n)=>{if(t.includes(`--help`)||t.includes(`-h`))return K1();let r=`:memory:`,i=t;t.length>0&&!t[0].startsWith(`-`)&&(r=t[0],i=t.slice(1));let a=i.join(` `).trim()||n.stdin.trim();if(!a)return{stdout:``,stderr:`${e}: interactive mode is not supported; provide SQL as argument or stdin\n`,exitCode:1};try{let e=await _1(),t=r===`:memory:`,i=t?`:memory:`:n.fs.resolvePath(n.cwd,r),o;!t&&await n.fs.exists(i)&&(o=await n.fs.readFileBuffer(i));let s=o?new e.Database(o):new e.Database,c=s.exec(a);t||await n.fs.writeFile(i,s.export()),s.close();let l=[];for(let e of c)for(let t of e.values)l.push(t.map(u1).join(`|`));return{stdout:l.length>0?`${l.join(`
3919
+ `)}\n`:``,stderr:``,exitCode:0}}catch(t){return{stdout:``,stderr:`${e}: ${t instanceof Error?t.message:String(t)}\n`,exitCode:1}}})}function J1(){return{stdout:`usage: uname
3920
+ `,stderr:``,exitCode:0}}function Y1(){return gR(`uname`,async e=>{if(e.includes(`--help`)||e.includes(`-h`))return J1();if(e.length>0)return{stdout:``,stderr:`uname: unsupported arguments
3921
3921
  `,exitCode:1};let t=globalThis.navigator?.userAgent;return typeof t!=`string`||t.length===0?{stdout:``,stderr:`uname: navigator.userAgent is unavailable
3922
- `,exitCode:1}:{stdout:`${t}\n`,stderr:``,exitCode:0}})}function q1(){return{stdout:`usage: man <topic>
3922
+ `,exitCode:1}:{stdout:`${t}\n`,stderr:``,exitCode:0}})}function X1(){return{stdout:`usage: man <topic>
3923
3923
 
3924
3924
  Fetches documentation for a given topic from sliccy.com.
3925
- `,stderr:``,exitCode:0}}function J1(e){return e.replace(/<[^>]*>/g,``).replace(/&amp;/g,`&`).replace(/&lt;/g,`<`).replace(/&gt;/g,`>`).replace(/&quot;/g,`"`).replace(/&#39;/g,`'`).replace(/&nbsp;/g,` `).trimEnd()}function Y1(){return gR(`man`,async e=>{if(e.includes(`--help`)||e.includes(`-h`))return q1();if(e.length===0)return{stdout:``,stderr:`What manual page do you want?
3925
+ `,stderr:``,exitCode:0}}function Z1(e){return e.replace(/<[^>]*>/g,``).replace(/&amp;/g,`&`).replace(/&lt;/g,`<`).replace(/&gt;/g,`>`).replace(/&quot;/g,`"`).replace(/&#39;/g,`'`).replace(/&nbsp;/g,` `).trimEnd()}function Q1(){return gR(`man`,async e=>{if(e.includes(`--help`)||e.includes(`-h`))return X1();if(e.length===0)return{stdout:``,stderr:`What manual page do you want?
3926
3926
  For example, try 'man commands'.
3927
- `,exitCode:1};let t=e.join(`-`),n=`https://www.sliccy.com/man/${t}.plain.html`;try{let e=await fetch(n);return e.status===404?{stdout:``,stderr:`No manual entry for ${t}\n`,exitCode:1}:e.ok?{stdout:J1(await e.text())+`
3928
- `,stderr:``,exitCode:0}:{stdout:``,stderr:`man: failed to fetch manual page for ${t}: ${e.status} ${e.statusText}\n`,exitCode:1}}catch(e){return{stdout:``,stderr:`man: ${e.message||String(e)}\n`,exitCode:1}}})}function X1(){return{stdout:`usage: unzip <archive.zip> [-d <destination>]
3929
- `,stderr:``,exitCode:0}}function Z1(){return gR(`unzip`,async(e,t)=>{if(e.length===0||e.includes(`--help`)||e.includes(`-h`))return X1();let n=`.`,r=[];for(let t=0;t<e.length;t++){let i=e[t];if(i===`-d`){n=e[t+1]??``,t++;continue}if(i.startsWith(`-`))return{stdout:``,stderr:`unzip: unsupported option ${i}\n`,exitCode:1};r.push(i)}if(r.length<1)return{stdout:``,stderr:`unzip: expected archive path
3930
- `,exitCode:1};let i=t.fs.resolvePath(t.cwd,r[0]),a=t.fs.resolvePath(t.cwd,n||`.`);await t.fs.mkdir(a,{recursive:!0});let o=D(await t.fs.readFileBuffer(i)),s=0;for(let[e,n]of Object.entries(o)){let r=e.replace(/\\/g,`/`);if(!r||r.endsWith(`/`))continue;let i=t.fs.resolvePath(a,r);if(!a1(a,i))return{stdout:``,stderr:`unzip: blocked suspicious path ${e}\n`,exitCode:1};let o=n1(i);o!==`/`&&await t.fs.mkdir(o,{recursive:!0}),await t.fs.writeFile(i,n),s++}return{stdout:`extracted ${s} file(s) to ${a}\n`,stderr:``,exitCode:0}})}function Q1(){return{stdout:`usage: webhook <command> [options]
3927
+ `,exitCode:1};let t=e.join(`-`),n=`https://www.sliccy.com/man/${t}.plain.html`;try{let e=await fetch(n);return e.status===404?{stdout:``,stderr:`No manual entry for ${t}\n`,exitCode:1}:e.ok?{stdout:Z1(await e.text())+`
3928
+ `,stderr:``,exitCode:0}:{stdout:``,stderr:`man: failed to fetch manual page for ${t}: ${e.status} ${e.statusText}\n`,exitCode:1}}catch(e){return{stdout:``,stderr:`man: ${e.message||String(e)}\n`,exitCode:1}}})}function $1(){return{stdout:`usage: unzip <archive.zip> [-d <destination>]
3929
+ `,stderr:``,exitCode:0}}function e0(){return gR(`unzip`,async(e,t)=>{if(e.length===0||e.includes(`--help`)||e.includes(`-h`))return $1();let n=`.`,r=[];for(let t=0;t<e.length;t++){let i=e[t];if(i===`-d`){n=e[t+1]??``,t++;continue}if(i.startsWith(`-`))return{stdout:``,stderr:`unzip: unsupported option ${i}\n`,exitCode:1};r.push(i)}if(r.length<1)return{stdout:``,stderr:`unzip: expected archive path
3930
+ `,exitCode:1};let i=t.fs.resolvePath(t.cwd,r[0]),a=t.fs.resolvePath(t.cwd,n||`.`);await t.fs.mkdir(a,{recursive:!0});let o=D(await t.fs.readFileBuffer(i)),s=0;for(let[e,n]of Object.entries(o)){let r=e.replace(/\\/g,`/`);if(!r||r.endsWith(`/`))continue;let i=t.fs.resolvePath(a,r);if(!c1(a,i))return{stdout:``,stderr:`unzip: blocked suspicious path ${e}\n`,exitCode:1};let o=a1(i);o!==`/`&&await t.fs.mkdir(o,{recursive:!0}),await t.fs.writeFile(i,n),s++}return{stdout:`extracted ${s} file(s) to ${a}\n`,stderr:``,exitCode:0}})}function t0(){return{stdout:`usage: webhook <command> [options]
3931
3931
 
3932
3932
  Commands:
3933
3933
  create --scoop <name> [--name <name>] [--filter <code>] Create a new webhook endpoint
@@ -3945,12 +3945,12 @@ Examples:
3945
3945
  webhook create --scoop slack-relay --name slack --filter "(e) => ({ text: e.body.text, user: e.body.user })"
3946
3946
  webhook list
3947
3947
  webhook delete abc123
3948
- `,stderr:``,exitCode:0}}async function $1(e,t,n){if(typeof chrome<`u`&&chrome?.runtime?.id)throw Error(`Webhooks are only available in CLI mode (npm run dev:full)`);let r={method:e,headers:{"Content-Type":`application/json`}};n&&(r.body=JSON.stringify(n));let i=await fetch(`/api/webhooks${t}`,r),a=await i.json().catch(()=>({}));return{ok:i.ok,status:i.status,data:a}}function e0(){return gR(`webhook`,async e=>{if(e.length===0||e.includes(`--help`)||e.includes(`-h`))return Q1();let t=e[0];try{switch(t){case`create`:{let t=`default`,n,r,i=e.indexOf(`--name`);i!==-1&&e[i+1]&&(t=e[i+1]);let a=e.indexOf(`--filter`);a!==-1&&e[a+1]&&(n=e[a+1]);let o=e.indexOf(`--scoop`);if(o!==-1&&e[o+1]&&(r=e[o+1]),!r)return{stdout:``,stderr:`webhook: --scoop is required (every webhook must route to a scoop)
3949
- `,exitCode:1};let{ok:s,data:c}=await $1(`POST`,``,{name:t,filter:n,scoop:r});if(!s)return{stdout:``,stderr:`webhook: failed to create webhook: ${c.error??`unknown error`}\n`,exitCode:1};let l=c,u=`Created webhook "${l.name}"\nID: ${l.id}\nURL: ${l.url}\n`;return l.scoop&&(u+=`Scoop: ${l.scoop}\n`),l.filter&&(u+=`Filter: ${l.filter}\n`),{stdout:u,stderr:``,exitCode:0}}case`list`:{let{ok:e,data:t}=await $1(`GET`,``);if(!e)return{stdout:``,stderr:`webhook: failed to list webhooks: ${t.error??`unknown error`}\n`,exitCode:1};let n=t;if(n.length===0)return{stdout:`No active webhooks
3948
+ `,stderr:``,exitCode:0}}async function n0(e,t,n){if(typeof chrome<`u`&&chrome?.runtime?.id)throw Error(`Webhooks are only available in CLI mode (npm run dev:full)`);let r={method:e,headers:{"Content-Type":`application/json`}};n&&(r.body=JSON.stringify(n));let i=await fetch(`/api/webhooks${t}`,r),a=await i.json().catch(()=>({}));return{ok:i.ok,status:i.status,data:a}}function r0(){return gR(`webhook`,async e=>{if(e.length===0||e.includes(`--help`)||e.includes(`-h`))return t0();let t=e[0];try{switch(t){case`create`:{let t=`default`,n,r,i=e.indexOf(`--name`);i!==-1&&e[i+1]&&(t=e[i+1]);let a=e.indexOf(`--filter`);a!==-1&&e[a+1]&&(n=e[a+1]);let o=e.indexOf(`--scoop`);if(o!==-1&&e[o+1]&&(r=e[o+1]),!r)return{stdout:``,stderr:`webhook: --scoop is required (every webhook must route to a scoop)
3949
+ `,exitCode:1};let{ok:s,data:c}=await n0(`POST`,``,{name:t,filter:n,scoop:r});if(!s)return{stdout:``,stderr:`webhook: failed to create webhook: ${c.error??`unknown error`}\n`,exitCode:1};let l=c,u=`Created webhook "${l.name}"\nID: ${l.id}\nURL: ${l.url}\n`;return l.scoop&&(u+=`Scoop: ${l.scoop}\n`),l.filter&&(u+=`Filter: ${l.filter}\n`),{stdout:u,stderr:``,exitCode:0}}case`list`:{let{ok:e,data:t}=await n0(`GET`,``);if(!e)return{stdout:``,stderr:`webhook: failed to list webhooks: ${t.error??`unknown error`}\n`,exitCode:1};let n=t;if(n.length===0)return{stdout:`No active webhooks
3950
3950
  `,stderr:``,exitCode:0};let r=`Active webhooks:
3951
3951
  `;for(let e of n)r+=` ${e.id} ${e.name.padEnd(20)} ${e.url}`,e.scoop&&(r+=` -> ${e.scoop}`),e.filter&&(r+=` [filtered]`),r+=`
3952
3952
  `;return{stdout:r,stderr:``,exitCode:0}}case`delete`:{let t=e[1];if(!t)return{stdout:``,stderr:`webhook: delete requires an ID
3953
- `,exitCode:1};let{ok:n,status:r,data:i}=await $1(`DELETE`,`/${t}`);return n?{stdout:`Deleted webhook "${t}"\n`,stderr:``,exitCode:0}:r===404?{stdout:``,stderr:`webhook: webhook "${t}" not found\n`,exitCode:1}:{stdout:``,stderr:`webhook: failed to delete webhook: ${i.error??`unknown error`}\n`,exitCode:1}}default:return{stdout:``,stderr:`webhook: unknown command "${t}"\n`,exitCode:1}}}catch(e){return{stdout:``,stderr:`webhook: ${e instanceof Error?e.message:String(e)}\n`,exitCode:1}}})}function t0(){return{stdout:`usage: crontask <command> [options]
3953
+ `,exitCode:1};let{ok:n,status:r,data:i}=await n0(`DELETE`,`/${t}`);return n?{stdout:`Deleted webhook "${t}"\n`,stderr:``,exitCode:0}:r===404?{stdout:``,stderr:`webhook: webhook "${t}" not found\n`,exitCode:1}:{stdout:``,stderr:`webhook: failed to delete webhook: ${i.error??`unknown error`}\n`,exitCode:1}}default:return{stdout:``,stderr:`webhook: unknown command "${t}"\n`,exitCode:1}}}catch(e){return{stdout:``,stderr:`webhook: ${e instanceof Error?e.message:String(e)}\n`,exitCode:1}}})}function i0(){return{stdout:`usage: crontask <command> [options]
3954
3954
 
3955
3955
  Commands:
3956
3956
  create [options] Create a new cron task
@@ -3982,16 +3982,16 @@ Examples:
3982
3982
  crontask create --name every-5min --scoop poller --cron "*/5 * * * *" --filter "() => ({ time: Date.now() })"
3983
3983
  crontask list
3984
3984
  crontask delete abc123
3985
- `,stderr:``,exitCode:0}}var n0=typeof chrome<`u`&&!!chrome?.runtime?.id;function r0(){return globalThis.__slicc_lickManager??null}var i0=null;async function a0(){if(i0)return i0;let{createLickManagerProxy:e}=await s(async()=>{let{createLickManagerProxy:e}=await import(`./lick-manager-proxy-BF0GrOv_.js`);return{createLickManagerProxy:e}},[]);return i0=e(),i0}async function o0(e,t,n){let r={method:e,headers:{"Content-Type":`application/json`}};n&&(r.body=JSON.stringify(n));let i=await fetch(`/api/crontasks${t}`,r),a=await i.json().catch(()=>({}));return{ok:i.ok,status:i.status,data:a}}function s0(){return gR(`crontask`,async e=>{if(e.length===0||e.includes(`--help`)||e.includes(`-h`))return t0();let t=e[0];try{switch(t){case`create`:{let t,n,r,i,a=e.indexOf(`--name`);a!==-1&&e[a+1]&&(t=e[a+1]);let o=e.indexOf(`--cron`);o!==-1&&e[o+1]&&(n=e[o+1]);let s=e.indexOf(`--filter`);s!==-1&&e[s+1]&&(r=e[s+1]);let c=e.indexOf(`--scoop`);if(c!==-1&&e[c+1]&&(i=e[c+1]),!t)return{stdout:``,stderr:`crontask: --name is required
3985
+ `,stderr:``,exitCode:0}}var a0=typeof chrome<`u`&&!!chrome?.runtime?.id;function o0(){return globalThis.__slicc_lickManager??null}var s0=null;async function c0(){if(s0)return s0;let{createLickManagerProxy:e}=await s(async()=>{let{createLickManagerProxy:e}=await import(`./lick-manager-proxy-BF0GrOv_.js`);return{createLickManagerProxy:e}},[]);return s0=e(),s0}async function l0(e,t,n){let r={method:e,headers:{"Content-Type":`application/json`}};n&&(r.body=JSON.stringify(n));let i=await fetch(`/api/crontasks${t}`,r),a=await i.json().catch(()=>({}));return{ok:i.ok,status:i.status,data:a}}function u0(){return gR(`crontask`,async e=>{if(e.length===0||e.includes(`--help`)||e.includes(`-h`))return i0();let t=e[0];try{switch(t){case`create`:{let t,n,r,i,a=e.indexOf(`--name`);a!==-1&&e[a+1]&&(t=e[a+1]);let o=e.indexOf(`--cron`);o!==-1&&e[o+1]&&(n=e[o+1]);let s=e.indexOf(`--filter`);s!==-1&&e[s+1]&&(r=e[s+1]);let c=e.indexOf(`--scoop`);if(c!==-1&&e[c+1]&&(i=e[c+1]),!t)return{stdout:``,stderr:`crontask: --name is required
3986
3986
  `,exitCode:1};if(!n)return{stdout:``,stderr:`crontask: --cron is required
3987
- `,exitCode:1};if(n0){if(r)return{stdout:``,stderr:`crontask: --filter is not supported in extension mode (CSP restriction)
3988
- `,exitCode:1};let e=r0(),a=e?await e.createCronTask(t,n,i):await(await a0()).createCronTask(t,n,i),o=`Created cron task "${a.name}"\n`;return o+=`ID: ${a.id}\n`,o+=`Cron: ${a.cron}\n`,a.scoop&&(o+=`Scoop: ${a.scoop}\n`),a.nextRun&&(o+=`Next run: ${new Date(a.nextRun).toLocaleString()}\n`),{stdout:o,stderr:``,exitCode:0}}let{ok:l,data:u}=await o0(`POST`,``,{name:t,cron:n,filter:r,scoop:i});if(!l)return{stdout:``,stderr:`crontask: failed to create: ${u.error??`unknown error`}\n`,exitCode:1};let d=u,f=`Created cron task "${d.name}"\n`;return f+=`ID: ${d.id}\n`,f+=`Cron: ${d.cron}\n`,d.scoop&&(f+=`Scoop: ${d.scoop}\n`),d.filter&&(f+=`Filter: ${d.filter}\n`),d.nextRun&&(f+=`Next run: ${new Date(d.nextRun).toLocaleString()}\n`),{stdout:f,stderr:``,exitCode:0}}case`list`:{if(n0){let e=r0(),t=e?e.listCronTasks():await(async()=>{let{listCronTasksAsync:e}=await s(async()=>{let{listCronTasksAsync:e}=await import(`./lick-manager-proxy-BF0GrOv_.js`);return{listCronTasksAsync:e}},[]);return e()})();if(t.length===0)return{stdout:`No active cron tasks
3987
+ `,exitCode:1};if(a0){if(r)return{stdout:``,stderr:`crontask: --filter is not supported in extension mode (CSP restriction)
3988
+ `,exitCode:1};let e=o0(),a=e?await e.createCronTask(t,n,i):await(await c0()).createCronTask(t,n,i),o=`Created cron task "${a.name}"\n`;return o+=`ID: ${a.id}\n`,o+=`Cron: ${a.cron}\n`,a.scoop&&(o+=`Scoop: ${a.scoop}\n`),a.nextRun&&(o+=`Next run: ${new Date(a.nextRun).toLocaleString()}\n`),{stdout:o,stderr:``,exitCode:0}}let{ok:l,data:u}=await l0(`POST`,``,{name:t,cron:n,filter:r,scoop:i});if(!l)return{stdout:``,stderr:`crontask: failed to create: ${u.error??`unknown error`}\n`,exitCode:1};let d=u,f=`Created cron task "${d.name}"\n`;return f+=`ID: ${d.id}\n`,f+=`Cron: ${d.cron}\n`,d.scoop&&(f+=`Scoop: ${d.scoop}\n`),d.filter&&(f+=`Filter: ${d.filter}\n`),d.nextRun&&(f+=`Next run: ${new Date(d.nextRun).toLocaleString()}\n`),{stdout:f,stderr:``,exitCode:0}}case`list`:{if(a0){let e=o0(),t=e?e.listCronTasks():await(async()=>{let{listCronTasksAsync:e}=await s(async()=>{let{listCronTasksAsync:e}=await import(`./lick-manager-proxy-BF0GrOv_.js`);return{listCronTasksAsync:e}},[]);return e()})();if(t.length===0)return{stdout:`No active cron tasks
3989
3989
  `,stderr:``,exitCode:0};let n=`Active cron tasks:
3990
3990
  `;for(let e of t)n+=` ${e.id} ${e.name.padEnd(20)} ${e.cron.padEnd(15)}`,e.scoop&&(n+=` -> ${e.scoop}`),e.filter&&(n+=` [filtered]`),n+=` (${e.status})`,e.nextRun&&(n+=` next: ${new Date(e.nextRun).toLocaleString()}`),n+=`
3991
- `;return{stdout:n,stderr:``,exitCode:0}}let{ok:e,data:t}=await o0(`GET`,``);if(!e)return{stdout:``,stderr:`crontask: failed to list: ${t.error??`unknown error`}\n`,exitCode:1};let n=t;if(n.length===0)return{stdout:`No active cron tasks
3991
+ `;return{stdout:n,stderr:``,exitCode:0}}let{ok:e,data:t}=await l0(`GET`,``);if(!e)return{stdout:``,stderr:`crontask: failed to list: ${t.error??`unknown error`}\n`,exitCode:1};let n=t;if(n.length===0)return{stdout:`No active cron tasks
3992
3992
  `,stderr:``,exitCode:0};let r=`Active cron tasks:
3993
3993
  `;for(let e of n)r+=` ${e.id} ${e.name.padEnd(20)} ${e.cron.padEnd(15)}`,e.scoop&&(r+=` -> ${e.scoop}`),e.filter&&(r+=` [filtered]`),r+=` (${e.status})`,e.nextRun&&(r+=` next: ${new Date(e.nextRun).toLocaleString()}`),r+=`
3994
- `;return{stdout:r,stderr:``,exitCode:0}}case`delete`:case`kill`:{let n=e[1];if(!n)return{stdout:``,stderr:`crontask: ${t} requires an ID\n`,exitCode:1};if(n0){let e=r0();return(e?await e.deleteCronTask(n):await(await a0()).deleteCronTask(n))?{stdout:`Deleted cron task "${n}"\n`,stderr:``,exitCode:0}:{stdout:``,stderr:`crontask: task "${n}" not found\n`,exitCode:1}}let{ok:r,status:i,data:a}=await o0(`DELETE`,`/${n}`);return r?{stdout:`Deleted cron task "${n}"\n`,stderr:``,exitCode:0}:i===404?{stdout:``,stderr:`crontask: task "${n}" not found\n`,exitCode:1}:{stdout:``,stderr:`crontask: failed to delete: ${a.error??`unknown error`}\n`,exitCode:1}}default:return{stdout:``,stderr:`crontask: unknown command "${t}"\n`,exitCode:1}}}catch(e){return{stdout:``,stderr:`crontask: ${e instanceof Error?e.message:String(e)}\n`,exitCode:1}}})}var c0=new Map,l0=0;function u0(){return gR(`fswatch`,async e=>{let t=e[0];if(!t||t===`--help`)return{stdout:`usage: fswatch <command> [options]
3994
+ `;return{stdout:r,stderr:``,exitCode:0}}case`delete`:case`kill`:{let n=e[1];if(!n)return{stdout:``,stderr:`crontask: ${t} requires an ID\n`,exitCode:1};if(a0){let e=o0();return(e?await e.deleteCronTask(n):await(await c0()).deleteCronTask(n))?{stdout:`Deleted cron task "${n}"\n`,stderr:``,exitCode:0}:{stdout:``,stderr:`crontask: task "${n}" not found\n`,exitCode:1}}let{ok:r,status:i,data:a}=await l0(`DELETE`,`/${n}`);return r?{stdout:`Deleted cron task "${n}"\n`,stderr:``,exitCode:0}:i===404?{stdout:``,stderr:`crontask: task "${n}" not found\n`,exitCode:1}:{stdout:``,stderr:`crontask: failed to delete: ${a.error??`unknown error`}\n`,exitCode:1}}default:return{stdout:``,stderr:`crontask: unknown command "${t}"\n`,exitCode:1}}}catch(e){return{stdout:``,stderr:`crontask: ${e instanceof Error?e.message:String(e)}\n`,exitCode:1}}})}var d0=new Map,f0=0;function p0(){return gR(`fswatch`,async e=>{let t=e[0];if(!t||t===`--help`)return{stdout:`usage: fswatch <command> [options]
3995
3995
 
3996
3996
  Commands:
3997
3997
  create --path <path> --pattern <glob> [--scoop <name>] [--name <name>] Watch for file changes
@@ -4003,11 +4003,11 @@ Options:
4003
4003
  --pattern <glob> File pattern to match, e.g. "*.md", "*.bsh" (required)
4004
4004
  --scoop <name> Route change events to this scoop as lick events
4005
4005
  --name <name> Human-readable name for the watcher
4006
- `,stderr:``,exitCode:0};if(t===`list`){if(c0.size===0)return{stdout:`No active file watchers.
4007
- `,stderr:``,exitCode:0};let e=``;for(let[,t]of c0)e+=`ID: ${t.id}\n`,e+=` Name: ${t.name}\n`,e+=` Path: ${t.basePath}\n`,e+=` Pattern: ${t.pattern}\n`,t.scoop&&(e+=` Scoop: ${t.scoop}\n`),e+=` Created: ${t.createdAt}\n\n`;return{stdout:e,stderr:``,exitCode:0}}if(t===`delete`){let t=e[1];if(!t)return{stdout:``,stderr:`fswatch: delete requires an ID
4008
- `,exitCode:1};let n=c0.get(t);return n?(n.unsubscribe(),c0.delete(t),{stdout:`Deleted watcher "${n.name}" (${t})\n`,stderr:``,exitCode:0}):{stdout:``,stderr:`fswatch: watcher not found: ${t}\n`,exitCode:1}}if(t===`create`){let t=``,n=``,r=``,i=``;for(let a=1;a<e.length;a++)e[a]===`--path`&&e[a+1]?t=e[++a]:e[a]===`--pattern`&&e[a+1]?n=e[++a]:e[a]===`--scoop`&&e[a+1]?r=e[++a]:e[a]===`--name`&&e[a+1]&&(i=e[++a]);if(!t||!n)return{stdout:``,stderr:`fswatch: --path and --pattern are required
4006
+ `,stderr:``,exitCode:0};if(t===`list`){if(d0.size===0)return{stdout:`No active file watchers.
4007
+ `,stderr:``,exitCode:0};let e=``;for(let[,t]of d0)e+=`ID: ${t.id}\n`,e+=` Name: ${t.name}\n`,e+=` Path: ${t.basePath}\n`,e+=` Pattern: ${t.pattern}\n`,t.scoop&&(e+=` Scoop: ${t.scoop}\n`),e+=` Created: ${t.createdAt}\n\n`;return{stdout:e,stderr:``,exitCode:0}}if(t===`delete`){let t=e[1];if(!t)return{stdout:``,stderr:`fswatch: delete requires an ID
4008
+ `,exitCode:1};let n=d0.get(t);return n?(n.unsubscribe(),d0.delete(t),{stdout:`Deleted watcher "${n.name}" (${t})\n`,stderr:``,exitCode:0}):{stdout:``,stderr:`fswatch: watcher not found: ${t}\n`,exitCode:1}}if(t===`create`){let t=``,n=``,r=``,i=``;for(let a=1;a<e.length;a++)e[a]===`--path`&&e[a+1]?t=e[++a]:e[a]===`--pattern`&&e[a+1]?n=e[++a]:e[a]===`--scoop`&&e[a+1]?r=e[++a]:e[a]===`--name`&&e[a+1]&&(i=e[++a]);if(!t||!n)return{stdout:``,stderr:`fswatch: --path and --pattern are required
4009
4009
  `,exitCode:1};let a=RegExp(`^`+n.replace(/\./g,`\\.`).replace(/\*/g,`.*`)+`$`),o=e=>{let t=e.split(`/`).pop()??``;return a.test(t)},s=globalThis.__slicc_fs_watcher;if(!s)return{stdout:``,stderr:`fswatch: file system watcher not available
4010
- `,exitCode:1};let c=`fsw-${++l0}`;i||=`${n} in ${t}`;let l=globalThis.__slicc_lick_handler,u=s.watch(t,o,e=>{l&&l({type:`fswatch`,fswatchId:c,fswatchName:i,targetScoop:r,timestamp:new Date().toISOString(),changes:e.map(e=>({type:e.type,path:e.path})),body:{changes:e.map(e=>({type:e.type,path:e.path}))}})});c0.set(c,{id:c,name:i,basePath:t,pattern:n,scoop:r,unsubscribe:u,createdAt:new Date().toISOString()});let d=`Created file watcher "${i}"\n`;return d+=`ID: ${c}\n`,d+=`Path: ${t}\n`,d+=`Pattern: ${n}\n`,r&&(d+=`Scoop: ${r}\n`),{stdout:d,stderr:``,exitCode:0}}return{stdout:``,stderr:`fswatch: unknown command: ${t}\n`,exitCode:1}})}var d0=class{listeners=new Map;lickHandler;fs;closeHandler;stopConeHandler;constructor(e,t,n,r){this.fs=e,this.lickHandler=t,this.closeHandler=n,this.stopConeHandler=r}createAPI(e){let t={name:e,lick:t=>{let n=typeof t==`string`?t:t.action,r=typeof t==`string`?void 0:t.data,i={type:`sprinkle`,sprinkleName:e,targetScoop:h0(e),timestamp:new Date().toISOString(),body:{action:n,data:r}};this.lickHandler(i)},on:(t,n)=>{let r=`${e}:${t}`,i=this.listeners.get(r);i||(i=new Set,this.listeners.set(r,i)),i.add(n)},off:(t,n)=>{let r=`${e}:${t}`;this.listeners.get(r)?.delete(n)},readFile:async e=>await this.fs.readFile(e,{encoding:`utf-8`}),writeFile:async(e,t)=>{await this.fs.writeFile(e,t)},readDir:async e=>(await this.fs.readDir(e)).map(e=>({name:e.name,type:e.type})),exists:async e=>this.fs.exists(e),stat:async e=>{let t=await this.fs.stat(e);return{type:t.type,size:t.size}},mkdir:async e=>{await this.fs.mkdir(e,{recursive:!0})},rm:async e=>{await this.fs.rm(e)},screenshot:async e=>{let n=t._container;if(!n)return``;let r=e?n.querySelector(e):n;if(!r)throw Error(`Element not found: `+(e||`container`));let i=r.getBoundingClientRect(),a=Math.ceil(i.width),o=Math.ceil(i.height);if(a===0||o===0)throw Error(`Element has zero dimensions`);let s=document.createElement(`canvas`),c=window.devicePixelRatio||1;s.width=a*c,s.height=o*c;let l=s.getContext(`2d`);l.scale(c,c);let u=r.cloneNode(!0),d=`<svg xmlns="http://www.w3.org/2000/svg" width="${a}" height="${o}"><foreignObject width="100%" height="100%">${new XMLSerializer().serializeToString(u)}</foreignObject></svg>`;return new Promise((e,t)=>{let n=new Image;n.onload=()=>{l.drawImage(n,0,0),e(s.toDataURL(`image/png`))},n.onerror=()=>t(Error(`Screenshot rendering failed`)),n.src=`data:image/svg+xml;charset=utf-8,`+encodeURIComponent(d)})},setState:t=>{try{localStorage.setItem(`slicc-sprinkle-state:${e}`,JSON.stringify(t))}catch{}},getState:()=>{try{let t=localStorage.getItem(`slicc-sprinkle-state:${e}`);return t?JSON.parse(t):null}catch{return null}},open:e=>{let t=/^https?:|^chrome-extension:/.test(e)?e:l1(e);window.open(t,`_blank`)},close:()=>this.closeHandler(e),stopCone:()=>this.stopConeHandler()};return t}pushUpdate(e,t){let n=`${e}:update`,r=this.listeners.get(n);if(r)for(let e of r){let n=r;setTimeout(()=>{if(n.has(e))try{e(t)}catch{}},0)}}removeSprinkle(e){for(let t of this.listeners.keys())t.startsWith(`${e}:`)&&this.listeners.delete(t)}},f0=`slicc-sprinkle-routes`;function p0(){try{let e=localStorage.getItem(f0);return e?JSON.parse(e):{}}catch{return{}}}function m0(e){try{localStorage.setItem(f0,JSON.stringify(e))}catch{}}function h0(e){return p0()[e]}function g0(e,t){let n=p0();n[e]=t,m0(n)}function _0(e){let t=p0();delete t[e],m0(t)}function v0(){return p0()}function y0(){return{stdout:`usage: sprinkle <subcommand> [args]
4010
+ `,exitCode:1};let c=`fsw-${++f0}`;i||=`${n} in ${t}`;let l=globalThis.__slicc_lick_handler,u=s.watch(t,o,e=>{l&&l({type:`fswatch`,fswatchId:c,fswatchName:i,targetScoop:r,timestamp:new Date().toISOString(),changes:e.map(e=>({type:e.type,path:e.path})),body:{changes:e.map(e=>({type:e.type,path:e.path}))}})});d0.set(c,{id:c,name:i,basePath:t,pattern:n,scoop:r,unsubscribe:u,createdAt:new Date().toISOString()});let d=`Created file watcher "${i}"\n`;return d+=`ID: ${c}\n`,d+=`Path: ${t}\n`,d+=`Pattern: ${n}\n`,r&&(d+=`Scoop: ${r}\n`),{stdout:d,stderr:``,exitCode:0}}return{stdout:``,stderr:`fswatch: unknown command: ${t}\n`,exitCode:1}})}var m0=class{listeners=new Map;lickHandler;fs;closeHandler;stopConeHandler;constructor(e,t,n,r){this.fs=e,this.lickHandler=t,this.closeHandler=n,this.stopConeHandler=r}createAPI(e){let t={name:e,lick:t=>{let n=typeof t==`string`?t:t.action,r=typeof t==`string`?void 0:t.data,i={type:`sprinkle`,sprinkleName:e,targetScoop:v0(e),timestamp:new Date().toISOString(),body:{action:n,data:r}};this.lickHandler(i)},on:(t,n)=>{let r=`${e}:${t}`,i=this.listeners.get(r);i||(i=new Set,this.listeners.set(r,i)),i.add(n)},off:(t,n)=>{let r=`${e}:${t}`;this.listeners.get(r)?.delete(n)},readFile:async e=>await this.fs.readFile(e,{encoding:`utf-8`}),writeFile:async(e,t)=>{await this.fs.writeFile(e,t)},readDir:async e=>(await this.fs.readDir(e)).map(e=>({name:e.name,type:e.type})),exists:async e=>this.fs.exists(e),stat:async e=>{let t=await this.fs.stat(e);return{type:t.type,size:t.size}},mkdir:async e=>{await this.fs.mkdir(e,{recursive:!0})},rm:async e=>{await this.fs.rm(e)},screenshot:async e=>{let n=t._container;if(!n)return``;let r=e?n.querySelector(e):n;if(!r)throw Error(`Element not found: `+(e||`container`));let i=r.getBoundingClientRect(),a=Math.ceil(i.width),o=Math.ceil(i.height);if(a===0||o===0)throw Error(`Element has zero dimensions`);let s=document.createElement(`canvas`),c=window.devicePixelRatio||1;s.width=a*c,s.height=o*c;let l=s.getContext(`2d`);l.scale(c,c);let u=r.cloneNode(!0),d=`<svg xmlns="http://www.w3.org/2000/svg" width="${a}" height="${o}"><foreignObject width="100%" height="100%">${new XMLSerializer().serializeToString(u)}</foreignObject></svg>`;return new Promise((e,t)=>{let n=new Image;n.onload=()=>{l.drawImage(n,0,0),e(s.toDataURL(`image/png`))},n.onerror=()=>t(Error(`Screenshot rendering failed`)),n.src=`data:image/svg+xml;charset=utf-8,`+encodeURIComponent(d)})},setState:t=>{try{localStorage.setItem(`slicc-sprinkle-state:${e}`,JSON.stringify(t))}catch{}},getState:()=>{try{let t=localStorage.getItem(`slicc-sprinkle-state:${e}`);return t?JSON.parse(t):null}catch{return null}},open:e=>{let t=/^https?:|^chrome-extension:/.test(e)?e:f1(e);window.open(t,`_blank`)},close:()=>this.closeHandler(e),stopCone:()=>this.stopConeHandler()};return t}pushUpdate(e,t){let n=`${e}:update`,r=this.listeners.get(n);if(r)for(let e of r){let n=r;setTimeout(()=>{if(n.has(e))try{e(t)}catch{}},0)}}removeSprinkle(e){for(let t of this.listeners.keys())t.startsWith(`${e}:`)&&this.listeners.delete(t)}},h0=`slicc-sprinkle-routes`;function g0(){try{let e=localStorage.getItem(h0);return e?JSON.parse(e):{}}catch{return{}}}function _0(e){try{localStorage.setItem(h0,JSON.stringify(e))}catch{}}function v0(e){return g0()[e]}function y0(e,t){let n=g0();n[e]=t,_0(n)}function b0(e){let t=g0();delete t[e],_0(t)}function x0(){return g0()}function S0(){return{stdout:`usage: sprinkle <subcommand> [args]
4011
4011
 
4012
4012
  list List available .shtml sprinkles
4013
4013
  open <name> Open a sprinkle by name
@@ -4020,23 +4020,23 @@ Options:
4020
4020
  chat <html> Show inline HTML in chat (Tool UI)
4021
4021
  Use data-action="name" on buttons for callbacks
4022
4022
  Pipe HTML: echo "<div>...</div>" | sprinkle chat
4023
- `,stderr:``,exitCode:0}}function b0(){return typeof window>`u`?null:window.__slicc_sprinkleManager??null}function x0(){return gR(`sprinkle`,async(e,t)=>{if(e.length===0||e[0]===`--help`||e[0]===`-h`)return y0();let n=e[0];if(n===`chat`){let n=e.slice(1).join(` `);if(!n&&t.stdin&&(n=t.stdin),!n)return{stdout:``,stderr:`sprinkle chat: HTML content required
4023
+ `,stderr:``,exitCode:0}}function C0(){return typeof window>`u`?null:window.__slicc_sprinkleManager??null}function w0(){return gR(`sprinkle`,async(e,t)=>{if(e.length===0||e[0]===`--help`||e[0]===`-h`)return S0();let n=e[0];if(n===`chat`){let n=e.slice(1).join(` `);if(!n&&t.stdin&&(n=t.stdin),!n)return{stdout:``,stderr:`sprinkle chat: HTML content required
4024
4024
  `,exitCode:1};let r=await pi({html:n,onAction:async(e,t)=>({action:e,data:t})});return r===null?{stdout:``,stderr:`sprinkle chat: not in tool execution context
4025
4025
  `,exitCode:1}:{stdout:JSON.stringify(r)+`
4026
- `,stderr:``,exitCode:0}}let r=b0();if(!r)return{stdout:``,stderr:`sprinkle: sprinkle manager not initialized
4026
+ `,stderr:``,exitCode:0}}let r=C0();if(!r)return{stdout:``,stderr:`sprinkle: sprinkle manager not initialized
4027
4027
  `,exitCode:1};switch(n){case`list`:{await r.refresh();let e=r.available();if(e.length===0)return{stdout:`No .shtml sprinkles found.
4028
4028
  `,stderr:``,exitCode:0};let t=new Set(r.opened());return{stdout:e.map(e=>{let n=t.has(e.name)?` [open]`:``;return` ${e.name}${n} ${e.title} (${e.path})`}).join(`
4029
4029
  `)+`
4030
4030
  `,stderr:``,exitCode:0}}case`open`:{let t=e[1];if(!t)return{stdout:``,stderr:`sprinkle open: name required
4031
4031
  `,exitCode:1};try{return await r.open(t),{stdout:`Sprinkle "${t}" opened.\n`,stderr:``,exitCode:0}}catch(e){return{stdout:``,stderr:`sprinkle open: ${e instanceof Error?e.message:String(e)}\n`,exitCode:1}}}case`close`:{let t=e[1];return t?(r.close(t),{stdout:`Sprinkle "${t}" closed.\n`,stderr:``,exitCode:0}):{stdout:``,stderr:`sprinkle close: name required
4032
- `,exitCode:1}}case`refresh`:{await r.refresh();let e=r.available().length;return{stdout:`Found ${e} sprinkle${e===1?``:`s`}.\n`,stderr:``,exitCode:0}}case`route`:{let t=e[1];if(!t){let e=v0(),t=Object.entries(e);return t.length===0?{stdout:`No sprinkle routes configured (all licks go to cone).
4032
+ `,exitCode:1}}case`refresh`:{await r.refresh();let e=r.available().length;return{stdout:`Found ${e} sprinkle${e===1?``:`s`}.\n`,stderr:``,exitCode:0}}case`route`:{let t=e[1];if(!t){let e=x0(),t=Object.entries(e);return t.length===0?{stdout:`No sprinkle routes configured (all licks go to cone).
4033
4033
  `,stderr:``,exitCode:0}:{stdout:`Sprinkle routes:
4034
4034
  `+t.map(([e,t])=>` ${e} -> ${t}`).join(`
4035
4035
  `)+`
4036
- `,stderr:``,exitCode:0}}if(e.includes(`--clear`))return _0(t),{stdout:`Route cleared for sprinkle "${t}" (licks will go to cone).\n`,stderr:``,exitCode:0};let n=e.indexOf(`--scoop`),r=n===-1?void 0:e[n+1];if(!r){let e=h0(t);return e?{stdout:`${t} -> ${e}\n`,stderr:``,exitCode:0}:{stdout:`${t} -> cone (default)\n`,stderr:``,exitCode:0}}return g0(t,r),{stdout:`Sprinkle "${t}" lick events will route to scoop "${r}".\n`,stderr:``,exitCode:0}}case`send`:{let t=e[1];if(!t)return{stdout:``,stderr:`sprinkle send: name required
4036
+ `,stderr:``,exitCode:0}}if(e.includes(`--clear`))return b0(t),{stdout:`Route cleared for sprinkle "${t}" (licks will go to cone).\n`,stderr:``,exitCode:0};let n=e.indexOf(`--scoop`),r=n===-1?void 0:e[n+1];if(!r){let e=v0(t);return e?{stdout:`${t} -> ${e}\n`,stderr:``,exitCode:0}:{stdout:`${t} -> cone (default)\n`,stderr:``,exitCode:0}}return y0(t,r),{stdout:`Sprinkle "${t}" lick events will route to scoop "${r}".\n`,stderr:``,exitCode:0}}case`send`:{let t=e[1];if(!t)return{stdout:``,stderr:`sprinkle send: name required
4037
4037
  `,exitCode:1};let n=e.slice(2).join(` `);if(!n)return{stdout:``,stderr:`sprinkle send: JSON data required
4038
4038
  `,exitCode:1};let i;try{i=JSON.parse(n)}catch{return{stdout:``,stderr:`sprinkle send: invalid JSON
4039
- `,exitCode:1}}return r.sendToSprinkle(t,i),{stdout:`Data sent to sprinkle "${t}".\n`,stderr:``,exitCode:0}}default:return{stdout:``,stderr:`sprinkle: unknown subcommand "${n}"\n`,exitCode:1}}})}function S0(){return`oauth-token — get an OAuth access token for a provider
4039
+ `,exitCode:1}}return r.sendToSprinkle(t,i),{stdout:`Data sent to sprinkle "${t}".\n`,stderr:``,exitCode:0}}default:return{stdout:``,stderr:`sprinkle: unknown subcommand "${n}"\n`,exitCode:1}}})}function T0(){return`oauth-token — get an OAuth access token for a provider
4040
4040
 
4041
4041
  Usage:
4042
4042
  oauth-token <providerId> Get token for a specific provider
@@ -4052,13 +4052,13 @@ on success.
4052
4052
  Examples:
4053
4053
  oauth-token adobe
4054
4054
  curl -H "Authorization: Bearer $(oauth-token adobe)" https://api.corp.com/data
4055
- `}function C0(){return gR(`oauth-token`,async e=>{let{getOAuthAccountInfo:t,getSelectedProvider:n,getAccounts:r}=await s(async()=>{let{getOAuthAccountInfo:e,getSelectedProvider:t,getAccounts:n}=await import(`./provider-settings-ChPESpua.js`).then(e=>e.l);return{getOAuthAccountInfo:e,getSelectedProvider:t,getAccounts:n}},__vite__mapDeps([10,4,1,11,12,13])),{getRegisteredProviderConfig:i,getRegisteredProviderIds:a}=await s(async()=>{let{getRegisteredProviderConfig:e,getRegisteredProviderIds:t}=await import(`./provider-settings-ChPESpua.js`).then(e=>e.h);return{getRegisteredProviderConfig:e,getRegisteredProviderIds:t}},__vite__mapDeps([10,4,1,11,12,13]));if(e.includes(`--help`)||e.includes(`-h`))return{stdout:S0(),stderr:``,exitCode:0};if(e.includes(`--list`))return w0(r,a,i,t);let o,c=e.indexOf(`--provider`);if(c>=0){if(o=e[c+1],!o)return{stdout:``,stderr:`oauth-token: --provider requires a value
4055
+ `}function E0(){return gR(`oauth-token`,async e=>{let{getOAuthAccountInfo:t,getSelectedProvider:n,getAccounts:r}=await s(async()=>{let{getOAuthAccountInfo:e,getSelectedProvider:t,getAccounts:n}=await import(`./provider-settings-ArVcQj7G.js`).then(e=>e.l);return{getOAuthAccountInfo:e,getSelectedProvider:t,getAccounts:n}},__vite__mapDeps([10,4,1,11,12,13])),{getRegisteredProviderConfig:i,getRegisteredProviderIds:a}=await s(async()=>{let{getRegisteredProviderConfig:e,getRegisteredProviderIds:t}=await import(`./provider-settings-ArVcQj7G.js`).then(e=>e.h);return{getRegisteredProviderConfig:e,getRegisteredProviderIds:t}},__vite__mapDeps([10,4,1,11,12,13]));if(e.includes(`--help`)||e.includes(`-h`))return{stdout:T0(),stderr:``,exitCode:0};if(e.includes(`--list`))return D0(r,a,i,t);let o,c=e.indexOf(`--provider`);if(c>=0){if(o=e[c+1],!o)return{stdout:``,stderr:`oauth-token: --provider requires a value
4056
4056
  `,exitCode:1}}else if(e.length>0)o=e[0];else{let e=n(),t=i(e);if(t?.isOAuth&&t.onOAuthLogin)o=e;else if(o=a().find(e=>{let t=i(e);return t?.isOAuth&&t.onOAuthLogin}),!o)return{stdout:``,stderr:`oauth-token: no OAuth providers configured
4057
4057
  `,exitCode:1}}let l=i(o);if(!l)return{stdout:``,stderr:`oauth-token: unknown provider "${o}"\n`,exitCode:1};if(!l.isOAuth||!l.onOAuthLogin)return{stdout:``,stderr:`oauth-token: provider "${o}" is not an OAuth provider\n`,exitCode:1};let u=t(o);if(u&&!u.expired)return{stdout:`${u.token}\n`,stderr:``,exitCode:0};try{let{createOAuthLauncher:e}=await s(async()=>{let{createOAuthLauncher:e}=await import(`./oauth-service-8Xax8Fjw.js`);return{createOAuthLauncher:e}},[]),n=e();await l.onOAuthLogin(n,()=>{});let r=t(o);return r&&r.token?{stdout:`${r.token}\n`,stderr:``,exitCode:0}:(console.error(`[oauth-token] Provider ${o}: login completed but no token was saved`),{stdout:``,stderr:`oauth-token: login completed but no token was saved
4058
- `,exitCode:1})}catch(e){let t=e instanceof Error?e.message:String(e);return console.error(`[oauth-token] Provider ${o}: login failed:`,t),{stdout:``,stderr:`oauth-token: login failed: ${t}\n`,exitCode:1}}})}function w0(e,t,n,r){let i=t().filter(e=>n(e)?.isOAuth);if(i.length===0)return{stdout:`No OAuth providers configured.
4058
+ `,exitCode:1})}catch(e){let t=e instanceof Error?e.message:String(e);return console.error(`[oauth-token] Provider ${o}: login failed:`,t),{stdout:``,stderr:`oauth-token: login failed: ${t}\n`,exitCode:1}}})}function D0(e,t,n,r){let i=t().filter(e=>n(e)?.isOAuth);if(i.length===0)return{stdout:`No OAuth providers configured.
4059
4059
  `,stderr:``,exitCode:0};let a=[];for(let e of i){let t=r(e);if(!t)a.push(`${e} (no token)`);else if(t.expired){let n=t.userName?` as ${t.userName}`:``;a.push(`${e} (expired${n})`)}else{let n=[];if(t.userName?n.push(`logged in as ${t.userName}`):n.push(`logged in`),t.expiresAt){let e=t.expiresAt-Date.now();if(e>0){let t=Math.floor(e/36e5),r=Math.floor(e%36e5/6e4);t>0?n.push(`expires in ${t}h`):n.push(`expires in ${r}m`)}}a.push(`${e} (${n.join(`, `)})`)}}return{stdout:a.join(`
4060
4060
  `)+`
4061
- `,stderr:``,exitCode:0}}function T0(){return`secret — manage secrets for the fetch proxy
4061
+ `,stderr:``,exitCode:0}}function O0(){return`secret — manage secrets for the fetch proxy
4062
4062
 
4063
4063
  Usage:
4064
4064
  secret set <name> --domain <patterns> Show instructions for adding a secret
@@ -4075,19 +4075,19 @@ Examples:
4075
4075
  secret list
4076
4076
  secret delete GITHUB_TOKEN
4077
4077
  secret test GITHUB_TOKEN https://api.github.com/repos
4078
- `}async function E0(e,t,n){if(typeof chrome<`u`&&chrome?.runtime?.id)throw Error(`Secrets CLI is only available in CLI mode`);let r={method:e,headers:{"Content-Type":`application/json`}};n&&(r.body=JSON.stringify(n));let i=await fetch(`/api/secrets${t}`,r),a=await i.json().catch(()=>({}));return{ok:i.ok,status:i.status,data:a}}function D0(e){let t=e.indexOf(`--domain`);return t===-1||!e[t+1]?null:e[t+1].split(`,`).map(e=>e.trim()).filter(e=>e.length>0)}function O0(){return gR(`secret`,async e=>{if(e.length===0||e.includes(`--help`)||e.includes(`-h`))return{stdout:T0(),stderr:``,exitCode:0};let t=e[0];try{switch(t){case`set`:{let t=e[1];if(!t||t.startsWith(`-`))return{stdout:``,stderr:`secret: set requires a <name>
4079
- `,exitCode:1};let n=D0(e),r=n&&n.length>0?n.join(`,`):`<domain1,domain2>`,i=`To add the secret "${t}", use one of the following methods:\n\n`;return i+=` macOS Keychain (swift-server):
4078
+ `}async function k0(e,t,n){if(typeof chrome<`u`&&chrome?.runtime?.id)throw Error(`Secrets CLI is only available in CLI mode`);let r={method:e,headers:{"Content-Type":`application/json`}};n&&(r.body=JSON.stringify(n));let i=await fetch(`/api/secrets${t}`,r),a=await i.json().catch(()=>({}));return{ok:i.ok,status:i.status,data:a}}function A0(e){let t=e.indexOf(`--domain`);return t===-1||!e[t+1]?null:e[t+1].split(`,`).map(e=>e.trim()).filter(e=>e.length>0)}function j0(){return gR(`secret`,async e=>{if(e.length===0||e.includes(`--help`)||e.includes(`-h`))return{stdout:O0(),stderr:``,exitCode:0};let t=e[0];try{switch(t){case`set`:{let t=e[1];if(!t||t.startsWith(`-`))return{stdout:``,stderr:`secret: set requires a <name>
4079
+ `,exitCode:1};let n=A0(e),r=n&&n.length>0?n.join(`,`):`<domain1,domain2>`,i=`To add the secret "${t}", use one of the following methods:\n\n`;return i+=` macOS Keychain (swift-server):
4080
4080
  `,i+=` security add-generic-password -s ai.sliccy.slicc -a ${t} -w '<value>' -U -C note -j '${r}'\n\n`,i+=` Environment file (node-server):
4081
4081
  `,i+=` Add to ~/.slicc/secrets.env:
4082
4082
  `,i+=` ${t}=<value>\n`,i+=` ${t}_DOMAINS=${r}\n\n`,i+=`Then restart the server to pick up changes.
4083
- `,{stdout:i,stderr:``,exitCode:0}}case`list`:{let{ok:e,data:t}=await E0(`GET`,``);if(!e)return{stdout:``,stderr:`secret: failed to list secrets: ${t.error??`unknown error`}\n`,exitCode:1};let n=t;if(n.length===0)return{stdout:`No secrets stored
4083
+ `,{stdout:i,stderr:``,exitCode:0}}case`list`:{let{ok:e,data:t}=await k0(`GET`,``);if(!e)return{stdout:``,stderr:`secret: failed to list secrets: ${t.error??`unknown error`}\n`,exitCode:1};let n=t;if(n.length===0)return{stdout:`No secrets stored
4084
4084
  `,stderr:``,exitCode:0};let r=Math.max(4,...n.map(e=>e.name.length)),i=`${`NAME`.padEnd(r)} DOMAINS\n`;for(let e of n)i+=`${e.name.padEnd(r)} ${e.domains.join(`, `)}\n`;return{stdout:i,stderr:``,exitCode:0}}case`delete`:{let t=e[1];if(!t)return{stdout:``,stderr:`secret: delete requires a <name>
4085
4085
  `,exitCode:1};let n=`To delete the secret "${t}", use one of the following methods:\n\n`;return n+=` macOS Keychain (swift-server):
4086
4086
  `,n+=` security delete-generic-password -s ai.sliccy.slicc -a ${t}\n\n`,n+=` Environment file (node-server):
4087
4087
  `,n+=` Remove the ${t}= and ${t}_DOMAINS= lines from ~/.slicc/secrets.env\n\n`,n+=`Then restart the server to pick up changes.
4088
4088
  `,{stdout:n,stderr:``,exitCode:0}}case`test`:{let t=e[1],n=e[2];if(!t||!n)return{stdout:``,stderr:`secret: test requires <name> <url>
4089
- `,exitCode:1};let r;try{r=new URL(n).hostname}catch{return{stdout:``,stderr:`secret: invalid URL "${n}"\n`,exitCode:1}}let{ok:i,data:a}=await E0(`GET`,``);if(!i)return{stdout:``,stderr:`secret: failed to fetch secrets
4090
- `,exitCode:1};let o=a.find(e=>e.name===t);if(!o)return{stdout:``,stderr:`secret: no secret named "${t}"\n`,exitCode:1};let{isAllowedDomain:c}=await s(async()=>{let{isAllowedDomain:e}=await import(`./secret-masking-CXZkZ8rX.js`);return{isAllowedDomain:e}},[]);return c(o.domains,r)?{stdout:`✓ ${t} is allowed for ${r}\n`,stderr:``,exitCode:0}:{stdout:`✗ ${t} is NOT allowed for ${r}\n Allowed domains: ${o.domains.join(`, `)}\n`,stderr:``,exitCode:1}}default:return{stdout:``,stderr:`secret: unknown command "${t}"\n`,exitCode:1}}}catch(e){return{stdout:``,stderr:`secret: ${e instanceof Error?e.message:String(e)}\n`,exitCode:1}}})}function k0(e,t,n={}){let r=new Map;for(let e of t)r.set(e.path,e);let i=new Set,a=[],o=[],s=[];for(let t of e){i.add(t.path);let e=r.get(t.path);e?e.size===t.size&&e.mtimeMs===t.mtimeMs?s.push(t.path):o.push(t.path):a.push(t.path)}let c=[];if(n.delete)for(let e of t)i.has(e.path)||c.push(e.path);return{toAdd:a,toUpdate:o,toDelete:c,toSkip:s}}var A0=null;function j0(e){A0=e}function M0(){return A0?.()??null}function N0(e){let t={dryRun:!1,delete:!1,verbose:!1},n=[];for(let r of e)if(r===`--dry-run`||r===`-n`)t.dryRun=!0;else if(r===`--delete`)t.delete=!0;else if(r===`--verbose`||r===`-v`)t.verbose=!0;else if(r===`--help`||r===`-h`)return{error:`__help__`};else if(r.startsWith(`-`))return{error:`Unknown flag: ${r}`};else n.push(r);if(n.length!==2)return{error:`Expected exactly 2 arguments: <source> <dest>`};let[r,i]=n,a=P0(r),o=P0(i);return a&&o?{error:`Cannot sync between two remote paths — one side must be local`}:!a&&!o?{error:`One argument must be a remote path (runtime-id:/path)`}:o?{direction:`push`,localPath:r,remotePath:o.path,runtimeId:o.runtimeId,...t}:{direction:`pull`,localPath:i,remotePath:a.path,runtimeId:a.runtimeId,...t}}function P0(e){let t=e.indexOf(`:`);if(t<=0)return null;let n=e.slice(0,t),r=e.slice(t+1);return r.startsWith(`/`)?{runtimeId:n,path:r}:null}function F0(){return{stdout:`rsync — sync files between local VFS and a remote tray runtime
4089
+ `,exitCode:1};let r;try{r=new URL(n).hostname}catch{return{stdout:``,stderr:`secret: invalid URL "${n}"\n`,exitCode:1}}let{ok:i,data:a}=await k0(`GET`,``);if(!i)return{stdout:``,stderr:`secret: failed to fetch secrets
4090
+ `,exitCode:1};let o=a.find(e=>e.name===t);if(!o)return{stdout:``,stderr:`secret: no secret named "${t}"\n`,exitCode:1};let{isAllowedDomain:c}=await s(async()=>{let{isAllowedDomain:e}=await import(`./secret-masking-CXZkZ8rX.js`);return{isAllowedDomain:e}},[]);return c(o.domains,r)?{stdout:`✓ ${t} is allowed for ${r}\n`,stderr:``,exitCode:0}:{stdout:`✗ ${t} is NOT allowed for ${r}\n Allowed domains: ${o.domains.join(`, `)}\n`,stderr:``,exitCode:1}}default:return{stdout:``,stderr:`secret: unknown command "${t}"\n`,exitCode:1}}}catch(e){return{stdout:``,stderr:`secret: ${e instanceof Error?e.message:String(e)}\n`,exitCode:1}}})}function M0(e,t,n={}){let r=new Map;for(let e of t)r.set(e.path,e);let i=new Set,a=[],o=[],s=[];for(let t of e){i.add(t.path);let e=r.get(t.path);e?e.size===t.size&&e.mtimeMs===t.mtimeMs?s.push(t.path):o.push(t.path):a.push(t.path)}let c=[];if(n.delete)for(let e of t)i.has(e.path)||c.push(e.path);return{toAdd:a,toUpdate:o,toDelete:c,toSkip:s}}var N0=null;function P0(e){N0=e}function F0(){return N0?.()??null}function I0(e){let t={dryRun:!1,delete:!1,verbose:!1},n=[];for(let r of e)if(r===`--dry-run`||r===`-n`)t.dryRun=!0;else if(r===`--delete`)t.delete=!0;else if(r===`--verbose`||r===`-v`)t.verbose=!0;else if(r===`--help`||r===`-h`)return{error:`__help__`};else if(r.startsWith(`-`))return{error:`Unknown flag: ${r}`};else n.push(r);if(n.length!==2)return{error:`Expected exactly 2 arguments: <source> <dest>`};let[r,i]=n,a=L0(r),o=L0(i);return a&&o?{error:`Cannot sync between two remote paths — one side must be local`}:!a&&!o?{error:`One argument must be a remote path (runtime-id:/path)`}:o?{direction:`push`,localPath:r,remotePath:o.path,runtimeId:o.runtimeId,...t}:{direction:`pull`,localPath:i,remotePath:a.path,runtimeId:a.runtimeId,...t}}function L0(e){let t=e.indexOf(`:`);if(t<=0)return null;let n=e.slice(0,t),r=e.slice(t+1);return r.startsWith(`/`)?{runtimeId:n,path:r}:null}function R0(){return{stdout:`rsync — sync files between local VFS and a remote tray runtime
4091
4091
 
4092
4092
  Usage:
4093
4093
  rsync [flags] <local-path> <runtime-id>:<remote-path> # push
@@ -4103,21 +4103,21 @@ Examples:
4103
4103
  rsync /workspace follower-abc123:/workspace
4104
4104
  rsync --delete /shared leader:/shared
4105
4105
  rsync follower-abc123:/workspace/project /workspace/project
4106
- `,stderr:``,exitCode:0}}async function I0(e,t){if(!await e.exists(t))return[];let n=[];for await(let r of e.walk(t)){let i=r.slice(t.length).replace(/^\//,``);if(!i)continue;let a=await e.stat(r);n.push({path:i,size:a.size,mtimeMs:a.mtime})}return n}async function L0(e,t,n){let r=(await e(t,{op:`walk`,path:n}))[0];if(!r.ok){if(r.code===`ENOENT`)return[];throw Error(`Remote walk failed: ${r.error}`)}if(r.data.type!==`paths`)throw Error(`Unexpected walk response type`);let i=r.data.paths,a=[];for(let r of i){let i=r.slice(n.length).replace(/^\//,``);if(!i)continue;let o=(await e(t,{op:`stat`,path:r}))[0];o.ok&&o.data.type===`stat`&&a.push({path:i,size:o.data.stat.size,mtimeMs:o.data.stat.mtime})}return a}async function R0(e,t,n){let r=await e(t,{op:`readFile`,path:n,encoding:`binary`}),i=``;for(let e of r){if(!e.ok)throw Error(`Remote read failed: ${e.error}`);e.data.type===`file`&&(i+=e.data.content)}return i}async function z0(e,t,n){let r=await e(t,{op:`mkdir`,path:n,recursive:!0});if(!r[0].ok)throw Error(`Remote mkdir failed: ${r[0].error}`)}function B0(e){let t=e.lastIndexOf(`/`);return t<=0?`/`:e.slice(0,t)}async function V0(e,t,n){let r=[],{localPath:i,remotePath:a,runtimeId:o,verbose:s,dryRun:c}=n,l=k0(await I0(e,i),await L0(t,o,a),{delete:n.delete});if(s||c){for(let e of l.toAdd)r.push(`+ ${e}`);for(let e of l.toUpdate)r.push(`~ ${e}`);for(let e of l.toDelete)r.push(`- ${e}`);if(s)for(let e of l.toSkip)r.push(` ${e} (up to date)`)}let u=l.toAdd.length+l.toUpdate.length+l.toDelete.length;if(c)return r.push(`\n(dry run) ${u} file(s) would be transferred, ${l.toSkip.length} up to date`),{stdout:r.join(`
4106
+ `,stderr:``,exitCode:0}}async function z0(e,t){if(!await e.exists(t))return[];let n=[];for await(let r of e.walk(t)){let i=r.slice(t.length).replace(/^\//,``);if(!i)continue;let a=await e.stat(r);n.push({path:i,size:a.size,mtimeMs:a.mtime})}return n}async function B0(e,t,n){let r=(await e(t,{op:`walk`,path:n}))[0];if(!r.ok){if(r.code===`ENOENT`)return[];throw Error(`Remote walk failed: ${r.error}`)}if(r.data.type!==`paths`)throw Error(`Unexpected walk response type`);let i=r.data.paths,a=[];for(let r of i){let i=r.slice(n.length).replace(/^\//,``);if(!i)continue;let o=(await e(t,{op:`stat`,path:r}))[0];o.ok&&o.data.type===`stat`&&a.push({path:i,size:o.data.stat.size,mtimeMs:o.data.stat.mtime})}return a}async function V0(e,t,n){let r=await e(t,{op:`readFile`,path:n,encoding:`binary`}),i=``;for(let e of r){if(!e.ok)throw Error(`Remote read failed: ${e.error}`);e.data.type===`file`&&(i+=e.data.content)}return i}async function H0(e,t,n){let r=await e(t,{op:`mkdir`,path:n,recursive:!0});if(!r[0].ok)throw Error(`Remote mkdir failed: ${r[0].error}`)}function U0(e){let t=e.lastIndexOf(`/`);return t<=0?`/`:e.slice(0,t)}async function W0(e,t,n){let r=[],{localPath:i,remotePath:a,runtimeId:o,verbose:s,dryRun:c}=n,l=M0(await z0(e,i),await B0(t,o,a),{delete:n.delete});if(s||c){for(let e of l.toAdd)r.push(`+ ${e}`);for(let e of l.toUpdate)r.push(`~ ${e}`);for(let e of l.toDelete)r.push(`- ${e}`);if(s)for(let e of l.toSkip)r.push(` ${e} (up to date)`)}let u=l.toAdd.length+l.toUpdate.length+l.toDelete.length;if(c)return r.push(`\n(dry run) ${u} file(s) would be transferred, ${l.toSkip.length} up to date`),{stdout:r.join(`
4107
4107
  `)+`
4108
- `,stderr:``,exitCode:0};for(let n of[...l.toAdd,...l.toUpdate]){let s=i+`/`+n,c=a+`/`+n;await z0(t,o,B0(c));let l=await t(o,{op:`writeFile`,path:c,content:U0(await e.readFile(s,{encoding:`binary`})),encoding:`base64`});if(!l[0].ok)return{stdout:r.join(`
4108
+ `,stderr:``,exitCode:0};for(let n of[...l.toAdd,...l.toUpdate]){let s=i+`/`+n,c=a+`/`+n;await H0(t,o,U0(c));let l=await t(o,{op:`writeFile`,path:c,content:K0(await e.readFile(s,{encoding:`binary`})),encoding:`base64`});if(!l[0].ok)return{stdout:r.join(`
4109
4109
  `)+`
4110
4110
  `,stderr:`Error writing ${c}: ${l[0].error}\n`,exitCode:1}}for(let e of l.toDelete){let n=a+`/`+e,i=await t(o,{op:`rm`,path:n});if(!i[0].ok)return{stdout:r.join(`
4111
4111
  `)+`
4112
4112
  `,stderr:`Error deleting ${n}: ${i[0].error}\n`,exitCode:1}}return r.push(`${u} file(s) transferred, ${l.toSkip.length} up to date`),{stdout:r.join(`
4113
4113
  `)+`
4114
- `,stderr:``,exitCode:0}}async function H0(e,t,n){let r=[],{localPath:i,remotePath:a,runtimeId:o,verbose:s,dryRun:c}=n,l=k0(await L0(t,o,a),await I0(e,i),{delete:n.delete});if(s||c){for(let e of l.toAdd)r.push(`+ ${e}`);for(let e of l.toUpdate)r.push(`~ ${e}`);for(let e of l.toDelete)r.push(`- ${e}`);if(s)for(let e of l.toSkip)r.push(` ${e} (up to date)`)}let u=l.toAdd.length+l.toUpdate.length+l.toDelete.length;if(c)return r.push(`\n(dry run) ${u} file(s) would be transferred, ${l.toSkip.length} up to date`),{stdout:r.join(`
4114
+ `,stderr:``,exitCode:0}}async function G0(e,t,n){let r=[],{localPath:i,remotePath:a,runtimeId:o,verbose:s,dryRun:c}=n,l=M0(await B0(t,o,a),await z0(e,i),{delete:n.delete});if(s||c){for(let e of l.toAdd)r.push(`+ ${e}`);for(let e of l.toUpdate)r.push(`~ ${e}`);for(let e of l.toDelete)r.push(`- ${e}`);if(s)for(let e of l.toSkip)r.push(` ${e} (up to date)`)}let u=l.toAdd.length+l.toUpdate.length+l.toDelete.length;if(c)return r.push(`\n(dry run) ${u} file(s) would be transferred, ${l.toSkip.length} up to date`),{stdout:r.join(`
4115
4115
  `)+`
4116
- `,stderr:``,exitCode:0};for(let n of[...l.toAdd,...l.toUpdate]){let r=a+`/`+n,s=i+`/`+n,c=B0(s);await e.exists(c)||await e.mkdir(c,{recursive:!0});let l=W0(await R0(t,o,r));await e.writeFile(s,l)}for(let t of l.toDelete){let n=i+`/`+t;await e.rm(n)}return r.push(`${u} file(s) transferred, ${l.toSkip.length} up to date`),{stdout:r.join(`
4116
+ `,stderr:``,exitCode:0};for(let n of[...l.toAdd,...l.toUpdate]){let r=a+`/`+n,s=i+`/`+n,c=U0(s);await e.exists(c)||await e.mkdir(c,{recursive:!0});let l=q0(await V0(t,o,r));await e.writeFile(s,l)}for(let t of l.toDelete){let n=i+`/`+t;await e.rm(n)}return r.push(`${u} file(s) transferred, ${l.toSkip.length} up to date`),{stdout:r.join(`
4117
4117
  `)+`
4118
- `,stderr:``,exitCode:0}}function U0(e){let t=``;for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);return btoa(t)}function W0(e){let t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}function G0(e={}){let t=e.fs,n=e.getSendFsRequest??M0;return gR(`rsync`,async e=>{if(e.includes(`--help`)||e.includes(`-h`)||e.length===0)return F0();if(!t)return{stdout:``,stderr:`rsync: no filesystem available
4118
+ `,stderr:``,exitCode:0}}function K0(e){let t=``;for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);return btoa(t)}function q0(e){let t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}function J0(e={}){let t=e.fs,n=e.getSendFsRequest??F0;return gR(`rsync`,async e=>{if(e.includes(`--help`)||e.includes(`-h`)||e.length===0)return R0();if(!t)return{stdout:``,stderr:`rsync: no filesystem available
4119
4119
  `,exitCode:1};let r=n();if(!r)return{stdout:``,stderr:`rsync: not connected to a tray — rsync requires a tray connection
4120
- `,exitCode:1};let i=N0(e);if(`error`in i)return i.error===`__help__`?F0():{stdout:``,stderr:`rsync: ${i.error}\n`,exitCode:1};try{return i.direction===`push`?await V0(t,r,i):await H0(t,r,i)}catch(e){return{stdout:``,stderr:`rsync: ${e instanceof Error?e.message:String(e)}\n`,exitCode:1}}})}var K0=[`/workspace/skills`];async function q0(e){let t=new Map;for(let n of K0)await e.exists(n)&&await J0(e,n,t);return await J0(e,`/`,t),t}async function J0(e,t,n){for await(let r of e.walk(t)){if(!r.endsWith(`.jsh`))continue;let e=Y0(r);n.has(e)||n.set(e,r)}}function Y0(e){let t=e.split(`/`).pop()??e;return t.endsWith(`.jsh`)?t.slice(0,-4):t}function X0(e={}){let t=e.scriptCatalog!==void 0||e.fs!==void 0?e:typeof e.walk==`function`&&typeof e.exists==`function`?{fs:e}:{};return gR(`which`,async(e,n)=>{if(e.includes(`--help`)||e.includes(`-h`))return{stdout:`which - locate a command
4120
+ `,exitCode:1};let i=I0(e);if(`error`in i)return i.error===`__help__`?R0():{stdout:``,stderr:`rsync: ${i.error}\n`,exitCode:1};try{return i.direction===`push`?await W0(t,r,i):await G0(t,r,i)}catch(e){return{stdout:``,stderr:`rsync: ${e instanceof Error?e.message:String(e)}\n`,exitCode:1}}})}var Y0=[`/workspace/skills`];async function X0(e){let t=new Map;for(let n of Y0)await e.exists(n)&&await Z0(e,n,t);return await Z0(e,`/`,t),t}async function Z0(e,t,n){for await(let r of e.walk(t)){if(!r.endsWith(`.jsh`))continue;let e=Q0(r);n.has(e)||n.set(e,r)}}function Q0(e){let t=e.split(`/`).pop()??e;return t.endsWith(`.jsh`)?t.slice(0,-4):t}function $0(e={}){let t=e.scriptCatalog!==void 0||e.fs!==void 0?e:typeof e.walk==`function`&&typeof e.exists==`function`?{fs:e}:{};return gR(`which`,async(e,n)=>{if(e.includes(`--help`)||e.includes(`-h`))return{stdout:`which - locate a command
4121
4121
 
4122
4122
  Usage: which <command> [command...]
4123
4123
 
@@ -4127,12 +4127,12 @@ Prints the path of the given command(s).
4127
4127
 
4128
4128
  Exit code 0 if all commands found, 1 if any not found.
4129
4129
  `,stderr:``,exitCode:0};if(e.length===0)return{stdout:``,stderr:`which: missing argument
4130
- `,exitCode:1};let r=n.getRegisteredCommands?.()??[],i=new Set(r),a=t.scriptCatalog?await t.scriptCatalog.getJshCommands():t.fs?await q0(t.fs):new Map,o=[],s=!0;for(let t of e)if(i.has(t))o.push(`/usr/bin/${t}`);else{let e=a.get(t);e?o.push(e):s=!1}return{stdout:o.length>0?o.join(`
4130
+ `,exitCode:1};let r=n.getRegisteredCommands?.()??[],i=new Set(r),a=t.scriptCatalog?await t.scriptCatalog.getJshCommands():t.fs?await X0(t.fs):new Map,o=[],s=!0;for(let t of e)if(i.has(t))o.push(`/usr/bin/${t}`);else{let e=a.get(t);e?o.push(e):s=!1}return{stdout:o.length>0?o.join(`
4131
4131
  `)+`
4132
- `:``,stderr:``,exitCode:+!s}})}async function Z0(e,t,n,r){if((await e.fs.stat(t)).isFile)return r[n]=await e.fs.readFileBuffer(t),1;let i=await e.fs.readdir(t),a=0;for(let o of i){let i=r1(t,o),s=n?`${n}/${o}`:o;a+=await Z0(e,i,s,r)}return a}function Q0(){return{stdout:`usage: zip [-r] <archive.zip> <path> [path...]
4133
- `,stderr:``,exitCode:0}}function $0(){return gR(`zip`,async(e,t)=>{if(e.length===0||e.includes(`--help`)||e.includes(`-h`))return Q0();let n=!1,r=[];for(let t of e){if(t===`-r`){n=!0;continue}if(t.startsWith(`-`))return{stdout:``,stderr:`zip: unsupported option ${t}\n`,exitCode:1};r.push(t)}if(r.length<2)return{stdout:``,stderr:`zip: expected archive path and at least one input path
4134
- `,exitCode:1};let i=t.fs.resolvePath(t.cwd,r[0]),a=r.slice(1),o={},s=0;for(let e of a){let r=t.fs.resolvePath(t.cwd,e),i=await t.fs.stat(r),a=(e.startsWith(`/`)?e.slice(1):e.replace(/^\.\//,``))||t1(r);if(i.isDirectory&&!n)return{stdout:``,stderr:`zip: ${e} is a directory (use -r)\n`,exitCode:1};s+=await Z0(t,r,a,o)}if(s===0)return{stdout:``,stderr:`zip: nothing to do
4135
- `,exitCode:1};let c=ee(o);return await t.fs.writeFile(i,c),{stdout:`created ${i} (${s} file(s))\n`,stderr:``,exitCode:0}})}function e2(){return{stdout:`screencapture - capture screen, window, or tab using browser screen sharing
4132
+ `:``,stderr:``,exitCode:+!s}})}async function e2(e,t,n,r){if((await e.fs.stat(t)).isFile)return r[n]=await e.fs.readFileBuffer(t),1;let i=await e.fs.readdir(t),a=0;for(let o of i){let i=o1(t,o),s=n?`${n}/${o}`:o;a+=await e2(e,i,s,r)}return a}function t2(){return{stdout:`usage: zip [-r] <archive.zip> <path> [path...]
4133
+ `,stderr:``,exitCode:0}}function n2(){return gR(`zip`,async(e,t)=>{if(e.length===0||e.includes(`--help`)||e.includes(`-h`))return t2();let n=!1,r=[];for(let t of e){if(t===`-r`){n=!0;continue}if(t.startsWith(`-`))return{stdout:``,stderr:`zip: unsupported option ${t}\n`,exitCode:1};r.push(t)}if(r.length<2)return{stdout:``,stderr:`zip: expected archive path and at least one input path
4134
+ `,exitCode:1};let i=t.fs.resolvePath(t.cwd,r[0]),a=r.slice(1),o={},s=0;for(let e of a){let r=t.fs.resolvePath(t.cwd,e),i=await t.fs.stat(r),a=(e.startsWith(`/`)?e.slice(1):e.replace(/^\.\//,``))||i1(r);if(i.isDirectory&&!n)return{stdout:``,stderr:`zip: ${e} is a directory (use -r)\n`,exitCode:1};s+=await e2(t,r,a,o)}if(s===0)return{stdout:``,stderr:`zip: nothing to do
4135
+ `,exitCode:1};let c=ee(o);return await t.fs.writeFile(i,c),{stdout:`created ${i} (${s} file(s))\n`,stderr:``,exitCode:0}})}function r2(){return{stdout:`screencapture - capture screen, window, or tab using browser screen sharing
4136
4136
 
4137
4137
  Usage: screencapture [options] <output-file>
4138
4138
 
@@ -4148,57 +4148,57 @@ Examples:
4148
4148
  screencapture screenshot.png # Capture to file
4149
4149
  screencapture -c # Capture to clipboard
4150
4150
  screencapture -v capture.png # Capture and return for agent vision
4151
- `,stderr:``,exitCode:0}}function t2(e){let t=``,n=8192;for(let r=0;r<e.length;r+=n)t+=String.fromCharCode(...e.subarray(r,r+n));return btoa(t)}function n2(e){switch(e.split(`.`).pop()?.toLowerCase()){case`jpg`:case`jpeg`:return`image/jpeg`;case`webp`:return`image/webp`;default:return`image/png`}}async function r2(e,t){let n=await navigator.mediaDevices.getDisplayMedia({video:!0,audio:!1});try{let r=document.createElement(`video`);r.srcObject=n,r.muted=!0,r.playsInline=!0,await new Promise((e,t)=>{r.onloadedmetadata=()=>{r.play().then(()=>e()).catch(t)},r.onerror=()=>t(Error(`Failed to load video stream`))}),await new Promise(e=>requestAnimationFrame(e));let i=r.videoWidth,a=r.videoHeight,o=document.createElement(`canvas`);o.width=i,o.height=a;let s=o.getContext(`2d`);if(!s)throw Error(`Failed to get canvas context`);return s.drawImage(r,0,0,i,a),new Promise((n,r)=>{o.toBlob(e=>{e?n(e):r(Error(`Failed to create image blob`))},e,t)})}finally{n.getTracks().forEach(e=>e.stop())}}function i2(){return gR(`screencapture`,async(e,t)=>{if(e.includes(`--help`)||e.includes(`-h`))return e2();if(typeof window>`u`||typeof navigator>`u`||typeof document>`u`)return{stdout:``,stderr:`screencapture: browser APIs are unavailable in this environment
4151
+ `,stderr:``,exitCode:0}}function i2(e){let t=``,n=8192;for(let r=0;r<e.length;r+=n)t+=String.fromCharCode(...e.subarray(r,r+n));return btoa(t)}function a2(e){switch(e.split(`.`).pop()?.toLowerCase()){case`jpg`:case`jpeg`:return`image/jpeg`;case`webp`:return`image/webp`;default:return`image/png`}}async function o2(e,t){let n=await navigator.mediaDevices.getDisplayMedia({video:!0,audio:!1});try{let r=document.createElement(`video`);r.srcObject=n,r.muted=!0,r.playsInline=!0,await new Promise((e,t)=>{r.onloadedmetadata=()=>{r.play().then(()=>e()).catch(t)},r.onerror=()=>t(Error(`Failed to load video stream`))}),await new Promise(e=>requestAnimationFrame(e));let i=r.videoWidth,a=r.videoHeight,o=document.createElement(`canvas`);o.width=i,o.height=a;let s=o.getContext(`2d`);if(!s)throw Error(`Failed to get canvas context`);return s.drawImage(r,0,0,i,a),new Promise((n,r)=>{o.toBlob(e=>{e?n(e):r(Error(`Failed to create image blob`))},e,t)})}finally{n.getTracks().forEach(e=>e.stop())}}function s2(){return gR(`screencapture`,async(e,t)=>{if(e.includes(`--help`)||e.includes(`-h`))return r2();if(typeof window>`u`||typeof navigator>`u`||typeof document>`u`)return{stdout:``,stderr:`screencapture: browser APIs are unavailable in this environment
4152
4152
  `,exitCode:1};if(!navigator.mediaDevices?.getDisplayMedia)return{stdout:``,stderr:`screencapture: screen capture is not supported in this browser
4153
4153
  `,exitCode:1};let n=e.includes(`--clipboard`)||e.includes(`-c`),r=e.includes(`--view`)||e.includes(`-v`),i=[`--clipboard`,`-c`,`--view`,`-v`,`--help`,`-h`],a=e.indexOf(`--`),o=(a>=0?e.slice(a+1):e.filter(e=>!i.includes(e)))[0];if(!n&&!o)return{stdout:``,stderr:`screencapture: output file required (or use -c for clipboard)
4154
- `,exitCode:1};let s=o||`screenshot.png`,c=n2(s),l=c===`image/png`?1:.92,u;try{u=await r2(c,l)}catch(e){let t=e instanceof Error?e.message:String(e);return t.includes(`Permission denied`)||t.includes(`NotAllowedError`)?{stdout:``,stderr:`screencapture: user cancelled or permission denied
4155
- `,exitCode:1}:{stdout:``,stderr:`screencapture: ${t}\n`,exitCode:1}}let d=await u.arrayBuffer(),f=new Uint8Array(d);if(n)try{let e;if(c===`image/png`)e=u;else{let t=new Image,n=URL.createObjectURL(u);try{await new Promise((e,r)=>{t.onload=()=>e(),t.onerror=()=>r(Error(`Failed to load image for conversion`)),t.src=n})}finally{URL.revokeObjectURL(n)}let r=document.createElement(`canvas`);r.width=t.width,r.height=t.height;let i=r.getContext(`2d`);if(!i)throw Error(`Failed to get canvas context`);i.drawImage(t,0,0),e=await new Promise((e,t)=>{r.toBlob(n=>{n?e(n):t(Error(`Failed to create PNG blob`))},`image/png`)})}return await navigator.clipboard.write([new ClipboardItem({"image/png":e})]),{stdout:`captured ${Math.round(e.size/1024)} KB to clipboard\n`,stderr:``,exitCode:0}}catch(e){return{stdout:``,stderr:`screencapture: failed to copy to clipboard: ${e instanceof Error?e.message:String(e)}\n`,exitCode:1}}let p=t.fs.resolvePath(t.cwd,s);try{await t.fs.writeFile(p,f)}catch(e){return{stdout:``,stderr:`screencapture: failed to write file: ${e instanceof Error?e.message:String(e)}\n`,exitCode:1}}let m=Math.round(f.length/1024);return r?{stdout:`${p} (${m} KB)\n<img:data:${c};base64,${t2(f)}>`,stderr:``,exitCode:0}:{stdout:`captured ${m} KB to ${t1(p)}\n`,stderr:``,exitCode:0}})}function a2(e){return e instanceof Error?e.message:String(e)}function o2(){return{stdout:`usage: pbcopy
4154
+ `,exitCode:1};let s=o||`screenshot.png`,c=a2(s),l=c===`image/png`?1:.92,u;try{u=await o2(c,l)}catch(e){let t=e instanceof Error?e.message:String(e);return t.includes(`Permission denied`)||t.includes(`NotAllowedError`)?{stdout:``,stderr:`screencapture: user cancelled or permission denied
4155
+ `,exitCode:1}:{stdout:``,stderr:`screencapture: ${t}\n`,exitCode:1}}let d=await u.arrayBuffer(),f=new Uint8Array(d);if(n)try{let e;if(c===`image/png`)e=u;else{let t=new Image,n=URL.createObjectURL(u);try{await new Promise((e,r)=>{t.onload=()=>e(),t.onerror=()=>r(Error(`Failed to load image for conversion`)),t.src=n})}finally{URL.revokeObjectURL(n)}let r=document.createElement(`canvas`);r.width=t.width,r.height=t.height;let i=r.getContext(`2d`);if(!i)throw Error(`Failed to get canvas context`);i.drawImage(t,0,0),e=await new Promise((e,t)=>{r.toBlob(n=>{n?e(n):t(Error(`Failed to create PNG blob`))},`image/png`)})}return await navigator.clipboard.write([new ClipboardItem({"image/png":e})]),{stdout:`captured ${Math.round(e.size/1024)} KB to clipboard\n`,stderr:``,exitCode:0}}catch(e){return{stdout:``,stderr:`screencapture: failed to copy to clipboard: ${e instanceof Error?e.message:String(e)}\n`,exitCode:1}}let p=t.fs.resolvePath(t.cwd,s);try{await t.fs.writeFile(p,f)}catch(e){return{stdout:``,stderr:`screencapture: failed to write file: ${e instanceof Error?e.message:String(e)}\n`,exitCode:1}}let m=Math.round(f.length/1024);return r?{stdout:`${p} (${m} KB)\n<img:data:${c};base64,${i2(f)}>`,stderr:``,exitCode:0}:{stdout:`captured ${m} KB to ${i1(p)}\n`,stderr:``,exitCode:0}})}function c2(e){return e instanceof Error?e.message:String(e)}function l2(){return{stdout:`usage: pbcopy
4156
4156
 
4157
4157
  Copy stdin to the clipboard.
4158
4158
  Example: echo hello | pbcopy
4159
- `,stderr:``,exitCode:0}}function s2(){return{stdout:`usage: pbpaste
4159
+ `,stderr:``,exitCode:0}}function u2(){return{stdout:`usage: pbpaste
4160
4160
 
4161
4161
  Paste clipboard contents to stdout.
4162
- `,stderr:``,exitCode:0}}function c2(e){return{stdout:`usage: ${e} [-i|-o]\n\n -i Force copy mode (read from stdin)
4162
+ `,stderr:``,exitCode:0}}function d2(e){return{stdout:`usage: ${e} [-i|-o]\n\n -i Force copy mode (read from stdin)
4163
4163
  -o Force paste mode (write to stdout)
4164
4164
  (default) Auto-detect: stdin present = copy, no stdin = paste
4165
- Example: echo hello | ${e}\n Example: ${e} -o > file.txt\n`,stderr:``,exitCode:0}}async function l2(e,t){if(!globalThis.navigator?.clipboard)return{stdout:``,stderr:`${t}: clipboard API is unavailable\n`,exitCode:1};try{return await navigator.clipboard.writeText(e),{stdout:``,stderr:``,exitCode:0}}catch(e){return{stdout:``,stderr:`${t}: failed to write to clipboard: ${a2(e)}\n`,exitCode:1}}}async function u2(e){if(!globalThis.navigator?.clipboard)return{stdout:``,stderr:`${e}: clipboard API is unavailable\n`,exitCode:1};try{return{stdout:await navigator.clipboard.readText(),stderr:``,exitCode:0}}catch(t){return{stdout:``,stderr:`${e}: failed to read from clipboard: ${a2(t)}\n`,exitCode:1}}}function d2(){return gR(`pbcopy`,async(e,t)=>e.includes(`--help`)||e.includes(`-h`)?o2():l2(t.stdin,`pbcopy`))}function f2(){return gR(`pbpaste`,async e=>e.includes(`--help`)||e.includes(`-h`)?s2():u2(`pbpaste`))}function p2(e){return gR(e,async(t,n)=>{if(t.includes(`--help`)||t.includes(`-h`))return c2(e);let r=t.includes(`-i`),i=t.includes(`-o`);return r&&i?{stdout:``,stderr:`${e}: cannot use both -i and -o\n`,exitCode:1}:i?u2(e):r||n.stdin.length>0?l2(n.stdin,e):u2(e)})}function m2(){return{stdout:`usage: say [-v voice] [-r rate] [-l lang] [--list] <text>
4165
+ Example: echo hello | ${e}\n Example: ${e} -o > file.txt\n`,stderr:``,exitCode:0}}async function f2(e,t){if(!globalThis.navigator?.clipboard)return{stdout:``,stderr:`${t}: clipboard API is unavailable\n`,exitCode:1};try{return await navigator.clipboard.writeText(e),{stdout:``,stderr:``,exitCode:0}}catch(e){return{stdout:``,stderr:`${t}: failed to write to clipboard: ${c2(e)}\n`,exitCode:1}}}async function p2(e){if(!globalThis.navigator?.clipboard)return{stdout:``,stderr:`${e}: clipboard API is unavailable\n`,exitCode:1};try{return{stdout:await navigator.clipboard.readText(),stderr:``,exitCode:0}}catch(t){return{stdout:``,stderr:`${e}: failed to read from clipboard: ${c2(t)}\n`,exitCode:1}}}function m2(){return gR(`pbcopy`,async(e,t)=>e.includes(`--help`)||e.includes(`-h`)?l2():f2(t.stdin,`pbcopy`))}function h2(){return gR(`pbpaste`,async e=>e.includes(`--help`)||e.includes(`-h`)?u2():p2(`pbpaste`))}function g2(e){return gR(e,async(t,n)=>{if(t.includes(`--help`)||t.includes(`-h`))return d2(e);let r=t.includes(`-i`),i=t.includes(`-o`);return r&&i?{stdout:``,stderr:`${e}: cannot use both -i and -o\n`,exitCode:1}:i?p2(e):r||n.stdin.length>0?f2(n.stdin,e):p2(e)})}function _2(){return{stdout:`usage: say [-v voice] [-r rate] [-l lang] [--list] <text>
4166
4166
 
4167
4167
  Speaks the given text using the Web Speech API.
4168
4168
  -v voice Voice name (partial match supported)
4169
4169
  -r rate Speech rate (0.1 to 10, default 1)
4170
4170
  -l lang Language tag (required, BCP 47, e.g. en-US, de-DE, fr-FR)
4171
4171
  --list List available voices
4172
- `,stderr:``,exitCode:0}}var h2=!1,g2=null;function _2(){return h2?Promise.resolve(speechSynthesis.getVoices()):(g2||=new Promise(e=>{let t=speechSynthesis.getVoices();if(t.length>0){h2=!0,e(t);return}let n=()=>{h2=!0,speechSynthesis.removeEventListener(`voiceschanged`,n),e(speechSynthesis.getVoices())};speechSynthesis.addEventListener(`voiceschanged`,n),setTimeout(()=>{speechSynthesis.removeEventListener(`voiceschanged`,n),h2=!0,e(speechSynthesis.getVoices())},1e3)}),g2)}function v2(){return gR(`say`,async e=>{if(e.includes(`--help`)||e.includes(`-h`))return m2();if(typeof window>`u`||typeof speechSynthesis>`u`)return{stdout:``,stderr:`say: Web Speech API unavailable in this environment
4173
- `,exitCode:1};if(e.includes(`--list`))return{stdout:(await _2()).map(e=>`${e.name} (${e.lang})${e.default?` [default]`:``}`).join(`
4172
+ `,stderr:``,exitCode:0}}var v2=!1,y2=null;function b2(){return v2?Promise.resolve(speechSynthesis.getVoices()):(y2||=new Promise(e=>{let t=speechSynthesis.getVoices();if(t.length>0){v2=!0,e(t);return}let n=()=>{v2=!0,speechSynthesis.removeEventListener(`voiceschanged`,n),e(speechSynthesis.getVoices())};speechSynthesis.addEventListener(`voiceschanged`,n),setTimeout(()=>{speechSynthesis.removeEventListener(`voiceschanged`,n),v2=!0,e(speechSynthesis.getVoices())},1e3)}),y2)}function x2(){return gR(`say`,async e=>{if(e.includes(`--help`)||e.includes(`-h`))return _2();if(typeof window>`u`||typeof speechSynthesis>`u`)return{stdout:``,stderr:`say: Web Speech API unavailable in this environment
4173
+ `,exitCode:1};if(e.includes(`--list`))return{stdout:(await b2()).map(e=>`${e.name} (${e.lang})${e.default?` [default]`:``}`).join(`
4174
4174
  `)+`
4175
4175
  `,stderr:``,exitCode:0};let t=null,n=1,r=null,i=[];for(let a=0;a<e.length;a++){let o=e[a];if(o===`-v`){if(a+1>=e.length||e[a+1].startsWith(`-`))return{stdout:``,stderr:`say: -v requires a voice name
4176
4176
  `,exitCode:1};t=e[++a]}else if(o===`-r`){if(a+1>=e.length||e[a+1].startsWith(`-`))return{stdout:``,stderr:`say: -r requires a rate value
4177
4177
  `,exitCode:1};if(n=parseFloat(e[++a]),isNaN(n)||n<.1||n>10)return{stdout:``,stderr:`say: rate must be between 0.1 and 10
4178
4178
  `,exitCode:1}}else if(o===`-l`){if(a+1>=e.length||e[a+1].startsWith(`-`))return{stdout:``,stderr:`say: -l requires a language tag
4179
- `,exitCode:1};r=e[++a]}else if(o.startsWith(`-`)&&o!==`--list`)return{stdout:``,stderr:`say: unknown option: ${o}\n`,exitCode:1};else o.startsWith(`-`)||i.push(o)}let a=i.join(` `);if(!a)return m2();if(!r)return{stdout:``,stderr:`say: -l language tag is required
4180
- `,exitCode:1};let o=new SpeechSynthesisUtterance(a);if(o.rate=n,o.lang=r,t){let e=(await _2()).find(e=>e.name.toLowerCase().includes(t.toLowerCase()));if(e)o.voice=e;else return{stdout:``,stderr:`say: voice "${t}" not found. Use --list to see available voices.\n`,exitCode:1}}return new Promise(e=>{o.onend=()=>{e({stdout:``,stderr:``,exitCode:0})},o.onerror=t=>{e({stdout:``,stderr:`say: speech synthesis error: ${t.error}\n`,exitCode:1})},speechSynthesis.speak(o)})})}function y2(){return{stdout:`usage: afplay [-v volume] [-r rate] <file>
4179
+ `,exitCode:1};r=e[++a]}else if(o.startsWith(`-`)&&o!==`--list`)return{stdout:``,stderr:`say: unknown option: ${o}\n`,exitCode:1};else o.startsWith(`-`)||i.push(o)}let a=i.join(` `);if(!a)return _2();if(!r)return{stdout:``,stderr:`say: -l language tag is required
4180
+ `,exitCode:1};let o=new SpeechSynthesisUtterance(a);if(o.rate=n,o.lang=r,t){let e=(await b2()).find(e=>e.name.toLowerCase().includes(t.toLowerCase()));if(e)o.voice=e;else return{stdout:``,stderr:`say: voice "${t}" not found. Use --list to see available voices.\n`,exitCode:1}}return new Promise(e=>{o.onend=()=>{e({stdout:``,stderr:``,exitCode:0})},o.onerror=t=>{e({stdout:``,stderr:`say: speech synthesis error: ${t.error}\n`,exitCode:1})},speechSynthesis.speak(o)})})}function S2(){return{stdout:`usage: afplay [-v volume] [-r rate] <file>
4181
4181
 
4182
4182
  Plays an audio file using the Web Audio API.
4183
4183
  -v volume Volume level (0 to 1, default 1)
4184
4184
  -r rate Playback rate (0.25 to 4, default 1)
4185
- `,stderr:``,exitCode:0}}var b2=null;function x2(){return(!b2||b2.state===`closed`)&&(b2=new AudioContext),b2}async function S2(e,t,n,r){if(typeof window>`u`||typeof AudioContext>`u`)return{stdout:``,stderr:`afplay: Web Audio API unavailable in this environment
4186
- `,exitCode:1};let i=r.fs.resolvePath(r.cwd,e),a;try{a=new Uint8Array(await r.fs.readFileBuffer(i))}catch{return{stdout:``,stderr:`afplay: cannot open ${e}: No such file\n`,exitCode:1}}if(!c1(i).startsWith(`audio/`))return{stdout:``,stderr:`afplay: ${e} is not an audio file\n`,exitCode:1};try{let e=x2();e.state===`suspended`&&await e.resume();let r=new ArrayBuffer(a.byteLength);new Uint8Array(r).set(a);let i=await e.decodeAudioData(r),o=e.createBufferSource();o.buffer=i,o.playbackRate.value=n;let s=e.createGain();return s.gain.value=t,o.connect(s),s.connect(e.destination),new Promise(e=>{o.onended=()=>{e({stdout:``,stderr:``,exitCode:0})},o.start()})}catch(t){return{stdout:``,stderr:`afplay: failed to play ${e}: ${t instanceof Error?t.message:String(t)}\n`,exitCode:1}}}function C2(){return gR(`afplay`,async(e,t)=>{if(e.length===0||e.includes(`--help`)||e.includes(`-h`))return y2();let n=1,r=1,i=null;for(let t=0;t<e.length;t++){let a=e[t];if(a===`-v`){if(t+1>=e.length||e[t+1].startsWith(`-`))return{stdout:``,stderr:`afplay: -v requires a volume value
4185
+ `,stderr:``,exitCode:0}}var C2=null;function w2(){return(!C2||C2.state===`closed`)&&(C2=new AudioContext),C2}async function T2(e,t,n,r){if(typeof window>`u`||typeof AudioContext>`u`)return{stdout:``,stderr:`afplay: Web Audio API unavailable in this environment
4186
+ `,exitCode:1};let i=r.fs.resolvePath(r.cwd,e),a;try{a=new Uint8Array(await r.fs.readFileBuffer(i))}catch{return{stdout:``,stderr:`afplay: cannot open ${e}: No such file\n`,exitCode:1}}if(!d1(i).startsWith(`audio/`))return{stdout:``,stderr:`afplay: ${e} is not an audio file\n`,exitCode:1};try{let e=w2();e.state===`suspended`&&await e.resume();let r=new ArrayBuffer(a.byteLength);new Uint8Array(r).set(a);let i=await e.decodeAudioData(r),o=e.createBufferSource();o.buffer=i,o.playbackRate.value=n;let s=e.createGain();return s.gain.value=t,o.connect(s),s.connect(e.destination),new Promise(e=>{o.onended=()=>{e({stdout:``,stderr:``,exitCode:0})},o.start()})}catch(t){return{stdout:``,stderr:`afplay: failed to play ${e}: ${t instanceof Error?t.message:String(t)}\n`,exitCode:1}}}function E2(){return gR(`afplay`,async(e,t)=>{if(e.length===0||e.includes(`--help`)||e.includes(`-h`))return S2();let n=1,r=1,i=null;for(let t=0;t<e.length;t++){let a=e[t];if(a===`-v`){if(t+1>=e.length||e[t+1].startsWith(`-`))return{stdout:``,stderr:`afplay: -v requires a volume value
4187
4187
  `,exitCode:1};if(n=parseFloat(e[++t]),isNaN(n)||n<0||n>1)return{stdout:``,stderr:`afplay: volume must be between 0 and 1
4188
4188
  `,exitCode:1}}else if(a===`-r`){if(t+1>=e.length||e[t+1].startsWith(`-`))return{stdout:``,stderr:`afplay: -r requires a rate value
4189
4189
  `,exitCode:1};if(r=parseFloat(e[++t]),isNaN(r)||r<.25||r>4)return{stdout:``,stderr:`afplay: rate must be between 0.25 and 4
4190
4190
  `,exitCode:1}}else if(a.startsWith(`-`))return{stdout:``,stderr:`afplay: unknown option: ${a}\n`,exitCode:1};else{if(i!==null)return{stdout:``,stderr:`afplay: only one file can be specified
4191
- `,exitCode:1};i=a}}return i?S2(i,n,r,t):y2()})}function w2(){return gR(`chime`,async(e,t)=>e.includes(`--help`)||e.includes(`-h`)?{stdout:`usage: chime
4191
+ `,exitCode:1};i=a}}return i?T2(i,n,r,t):S2()})}function D2(){return gR(`chime`,async(e,t)=>e.includes(`--help`)||e.includes(`-h`)?{stdout:`usage: chime
4192
4192
 
4193
4193
  Plays a notification chime sound.
4194
4194
  Alias for: afplay /shared/sounds/chime.mp3
4195
- `,stderr:``,exitCode:0}:S2(`/shared/sounds/chime.mp3`,1,1,t))}function T2(){return gR(`debug`,async e=>{if(e.includes(`--help`)||e.includes(`-h`))return{stdout:`usage: debug [on|off]
4195
+ `,stderr:``,exitCode:0}:T2(`/shared/sounds/chime.mp3`,1,1,t))}function O2(){return gR(`debug`,async e=>{if(e.includes(`--help`)||e.includes(`-h`))return{stdout:`usage: debug [on|off]
4196
4196
 
4197
4197
  Toggle debug tabs (Terminal, Memory) in extension mode.
4198
4198
  Without arguments, shows current state.
4199
4199
  `,stderr:``,exitCode:0};let t=e[0]?.toLowerCase();if(t!==`on`&&t!==`off`&&t!==void 0)return{stdout:``,stderr:`debug: unknown argument '${t}' (use 'on' or 'off')\n`,exitCode:1};if(!t)try{let e=localStorage.getItem(`slicc-hidden-tabs`);return{stdout:`Debug tabs: ${(e?JSON.parse(e):[`terminal`,`memory`]).includes(`terminal`)?`off`:`on`}\n`,stderr:``,exitCode:0}}catch{return{stdout:`Debug tabs: off
4200
4200
  `,stderr:``,exitCode:0}}let n=t===`on`,r=window.__slicc_debug_tabs;if(r)return r(n),{stdout:`Debug tabs ${n?`enabled`:`hidden`}\n`,stderr:``,exitCode:0};try{return chrome.runtime.sendMessage({source:`offscreen`,payload:{type:`debug-tabs`,show:n}}),{stdout:`Debug tabs ${n?`enabled`:`hidden`}\n`,stderr:``,exitCode:0}}catch{return{stdout:``,stderr:`debug: failed to send toggle message
4201
- `,exitCode:1}}})}var E2=`/.cache/artificial-analysis.json`,D2=1440*60*1e3,O2=`https://artificialanalysis.ai/api/v2/data/llms/models`;async function k2(e,t=!1){if(e&&!t)try{let t=await e.readFile(E2),n=JSON.parse(t);if(Date.now()-n.fetchedAt<D2)return n.models}catch{}let n=null;try{n=localStorage.getItem(`aa_api_key`)}catch{}let r={Accept:`application/json`};n&&(r[`x-api-key`]=n);let i;try{i=await fetch(O2,{headers:r})}catch{return[]}if(i.status===401||!i.ok)return[];let a;try{a=await i.json()}catch{return[]}let o=(Array.isArray(a)?a:a?.data??a?.models??[]).map(e=>({slug:e.slug??``,name:e.name??``,creator_slug:e.model_creator?.slug??``,intelligence_index:e.evaluations?.artificial_analysis_intelligence_index??null,coding_index:e.evaluations?.artificial_analysis_coding_index??null,speed_tps:e.median_output_tokens_per_second??null}));if(e&&o.length>0){let t={fetchedAt:Date.now(),models:o};try{await e.mkdir(`/.cache`,{recursive:!0}),await e.writeFile(E2,JSON.stringify(t))}catch{}}return o}function A2(e){return e.toLowerCase().replace(/\./g,`-`).replace(/-\d{8}$/,``).replace(/-\d{4}$/,``)}function j2(e,t){let n=e.toLowerCase(),r=t.find(e=>e.slug===n);if(r)return r;let i=A2(e),a=t.find(e=>A2(e.slug)===i);if(a)return a;let o=t.filter(e=>n.includes(e.slug)||e.slug.includes(n));if(o.length>0)return o.sort((e,t)=>t.slug.length-e.slug.length),o[0]}function M2(){return`models - list available LLM models
4201
+ `,exitCode:1}}})}var k2=`/.cache/artificial-analysis.json`,A2=1440*60*1e3,j2=`https://artificialanalysis.ai/api/v2/data/llms/models`;async function M2(e,t=!1){if(e&&!t)try{let t=await e.readFile(k2),n=JSON.parse(t);if(Date.now()-n.fetchedAt<A2)return n.models}catch{}let n=null;try{n=localStorage.getItem(`aa_api_key`)}catch{}let r={Accept:`application/json`};n&&(r[`x-api-key`]=n);let i;try{i=await fetch(j2,{headers:r})}catch{return[]}if(i.status===401||!i.ok)return[];let a;try{a=await i.json()}catch{return[]}let o=(Array.isArray(a)?a:a?.data??a?.models??[]).map(e=>({slug:e.slug??``,name:e.name??``,creator_slug:e.model_creator?.slug??``,intelligence_index:e.evaluations?.artificial_analysis_intelligence_index??null,coding_index:e.evaluations?.artificial_analysis_coding_index??null,speed_tps:e.median_output_tokens_per_second??null}));if(e&&o.length>0){let t={fetchedAt:Date.now(),models:o};try{await e.mkdir(`/.cache`,{recursive:!0}),await e.writeFile(k2,JSON.stringify(t))}catch{}}return o}function N2(e){return e.toLowerCase().replace(/\./g,`-`).replace(/-\d{8}$/,``).replace(/-\d{4}$/,``)}function P2(e,t){let n=e.toLowerCase(),r=t.find(e=>e.slug===n);if(r)return r;let i=N2(e),a=t.find(e=>N2(e.slug)===i);if(a)return a;let o=t.filter(e=>n.includes(e.slug)||e.slug.includes(n));if(o.length>0)return o.sort((e,t)=>t.slug.length-e.slug.length),o[0]}function F2(){return`models - list available LLM models
4202
4202
 
4203
4203
  Usage: models [options]
4204
4204
 
@@ -4210,26 +4210,26 @@ Options:
4210
4210
  --refresh Force re-fetch benchmark data from Artificial Analysis
4211
4211
  --no-benchmarks Skip benchmark data enrichment (faster, works offline)
4212
4212
  -h, --help Show this help message
4213
- `}function N2(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`.replace(`.0M`,`M`):e>=1e3?`${(e/1e3).toFixed(0)}K`:`${e}`}function P2(e){return`$${e.toFixed(2)}`}var F2=/\b(embedding|embed|tts|whisper|dall-e|image-gen|audio|vision-preview)\b/i;function I2(e){let t=`${e.id} ${e.name??``}`;return!F2.test(t)}function L2(e){let t=e.toLowerCase();t=t.replace(/-\d{8}$/,``),t=t.replace(/-\d{4}$/,``),t=t.replace(/-(preview|latest)$/,``);let n=t.match(/^(claude-(?:opus|sonnet|haiku))/);if(n)return n[1];let r=t.match(/^(gpt-\d+)(?:\.\d+)?(-[a-z][-a-z]*)?$/);if(r)return r[1]+(r[2]??``);let i=t.match(/^gemini-[\d.]+-(.+)$/);if(i)return`gemini-${i[1]}`;let a=t.match(/^gemini-(\d+)-(.+)$/);if(a)return`gemini-${a[2]}`;let o=t.match(/^grok-[\d.]+-([\w-]+)$/);if(o)return`grok-${o[1]}`;if(t.match(/^(grok)-[\d.]+$/))return`grok`;let s=t.match(/^(o\d+(?:-[a-z]+)?)(?:-\d.*)?$/);return s?s[1]:t.replace(/-[\d.]+$/,``)}function R2(e){let t=new Map;for(let n of e){let e=L2(n.id);t.has(e)||t.set(e,n)}return[...t.values()]}function z2(e,t,n,r,i){let a=i?j2(e.id,i):void 0,o={id:e.id,name:e.name,provider:t,cost:e.cost??{input:0,output:0,cacheRead:0,cacheWrite:0},contextWindow:e.contextWindow??0,maxTokens:e.maxTokens??0,reasoning:!!e.reasoning,input:e.input??[`text`],selected:e.id===n&&t===r};return a?.intelligence_index!=null&&(o.intelligence=a.intelligence_index),a?.coding_index!=null&&(o.codingScore=a.coding_index),a?.speed_tps!=null&&(o.speed=a.speed_tps),o}function B2(e,t,n,r){let i=[];i.push(`Models for "${e}" (${t}):\n`);for(let e of n){let t=e.selected?` ► `:` `,n=e.id.padEnd(30),r=`${P2(e.cost.input)} / ${P2(e.cost.output)}`,a=`${N2(e.contextWindow)} ctx`,o=e.intelligence==null?``:`IQ:${e.intelligence}`,s=e.speed==null?``:`${Math.round(e.speed)} t/s`,c=e.reasoning?`reasoning`:``,l=o||s?`${o.padEnd(6)} ${s.padEnd(8)}`:``;i.push(`${t}${n} ${r.padEnd(16)} ${a.padEnd(10)} ${l} ${c}`)}let a=n.find(e=>e.selected);return i.push(`\n ${n.length} model${n.length===1?``:`s`} available.${a?` Currently using: ${a.id}`:``}`),r&&i.push(` Intelligence data: artificialanalysis.ai`),i.join(`
4213
+ `}function I2(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`.replace(`.0M`,`M`):e>=1e3?`${(e/1e3).toFixed(0)}K`:`${e}`}function L2(e){return`$${e.toFixed(2)}`}var R2=/\b(embedding|embed|tts|whisper|dall-e|image-gen|audio|vision-preview)\b/i;function z2(e){let t=`${e.id} ${e.name??``}`;return!R2.test(t)}function B2(e){let t=e.toLowerCase();t=t.replace(/-\d{8}$/,``),t=t.replace(/-\d{4}$/,``),t=t.replace(/-(preview|latest)$/,``);let n=t.match(/^(claude-(?:opus|sonnet|haiku))/);if(n)return n[1];let r=t.match(/^(gpt-\d+)(?:\.\d+)?(-[a-z][-a-z]*)?$/);if(r)return r[1]+(r[2]??``);let i=t.match(/^gemini-[\d.]+-(.+)$/);if(i)return`gemini-${i[1]}`;let a=t.match(/^gemini-(\d+)-(.+)$/);if(a)return`gemini-${a[2]}`;let o=t.match(/^grok-[\d.]+-([\w-]+)$/);if(o)return`grok-${o[1]}`;if(t.match(/^(grok)-[\d.]+$/))return`grok`;let s=t.match(/^(o\d+(?:-[a-z]+)?)(?:-\d.*)?$/);return s?s[1]:t.replace(/-[\d.]+$/,``)}function V2(e){let t=new Map;for(let n of e){let e=B2(n.id);t.has(e)||t.set(e,n)}return[...t.values()]}function H2(e,t,n,r,i){let a=i?P2(e.id,i):void 0,o={id:e.id,name:e.name,provider:t,cost:e.cost??{input:0,output:0,cacheRead:0,cacheWrite:0},contextWindow:e.contextWindow??0,maxTokens:e.maxTokens??0,reasoning:!!e.reasoning,input:e.input??[`text`],selected:e.id===n&&t===r};return a?.intelligence_index!=null&&(o.intelligence=a.intelligence_index),a?.coding_index!=null&&(o.codingScore=a.coding_index),a?.speed_tps!=null&&(o.speed=a.speed_tps),o}function U2(e,t,n,r){let i=[];i.push(`Models for "${e}" (${t}):\n`);for(let e of n){let t=e.selected?` ► `:` `,n=e.id.padEnd(30),r=`${L2(e.cost.input)} / ${L2(e.cost.output)}`,a=`${I2(e.contextWindow)} ctx`,o=e.intelligence==null?``:`IQ:${e.intelligence}`,s=e.speed==null?``:`${Math.round(e.speed)} t/s`,c=e.reasoning?`reasoning`:``,l=o||s?`${o.padEnd(6)} ${s.padEnd(8)}`:``;i.push(`${t}${n} ${r.padEnd(16)} ${a.padEnd(10)} ${l} ${c}`)}let a=n.find(e=>e.selected);return i.push(`\n ${n.length} model${n.length===1?``:`s`} available.${a?` Currently using: ${a.id}`:``}`),r&&i.push(` Intelligence data: artificialanalysis.ai`),i.join(`
4214
4214
  `)+`
4215
- `}function V2(e){return gR(`models`,async t=>{let{getAccounts:n,getAvailableProviders:r,getProviderConfig:i,getProviderModels:a,getSelectedProvider:o,getSelectedModelId:c}=await s(async()=>{let{getAccounts:e,getAvailableProviders:t,getProviderConfig:n,getProviderModels:r,getSelectedProvider:i,getSelectedModelId:a}=await import(`./provider-settings-ChPESpua.js`).then(e=>e.l);return{getAccounts:e,getAvailableProviders:t,getProviderConfig:n,getProviderModels:r,getSelectedProvider:i,getSelectedModelId:a}},__vite__mapDeps([10,4,1,11,12,13]));if(t.includes(`--help`)||t.includes(`-h`))return{stdout:M2(),stderr:``,exitCode:0};let l=t.includes(`--json`),u=t.includes(`--all`),d=t.includes(`--all-versions`),f=t.includes(`--refresh`),p=t.includes(`--no-benchmarks`),m=t.indexOf(`--provider`),h=m>=0?t[m+1]:void 0,g=o(),_=c(),v=n();if(v.length===0)return{stdout:``,stderr:`No provider accounts configured. Run the provider settings to add one.
4216
- `,exitCode:1};let y;p||(y=await k2(e,f),y.length===0&&(y=void 0));let b;if(h){let e=r();if(!e.includes(h))return{stdout:``,stderr:`Unknown provider: ${h}. Available: ${e.join(`, `)}\n`,exitCode:1};b=[h]}else b=u?[...new Set(v.map(e=>e.providerId))]:[g];let x=[],S=[];for(let e of b){let t=a(e).filter(I2);if(t.length===0){if(!u)return{stdout:``,stderr:`No models available for provider ${e}.\n`,exitCode:1};continue}let n=t.map(t=>z2(t,e,_,g,y)).sort((e,t)=>t.cost.input-e.cost.input);if(d||(n=R2(n)),x.push(...n),!l){let t=i(e);S.push(B2(t.name,e,n,!!y))}}return l?{stdout:JSON.stringify(x,null,2)+`
4215
+ `}function W2(e){return gR(`models`,async t=>{let{getAccounts:n,getAvailableProviders:r,getProviderConfig:i,getProviderModels:a,getSelectedProvider:o,getSelectedModelId:c}=await s(async()=>{let{getAccounts:e,getAvailableProviders:t,getProviderConfig:n,getProviderModels:r,getSelectedProvider:i,getSelectedModelId:a}=await import(`./provider-settings-ArVcQj7G.js`).then(e=>e.l);return{getAccounts:e,getAvailableProviders:t,getProviderConfig:n,getProviderModels:r,getSelectedProvider:i,getSelectedModelId:a}},__vite__mapDeps([10,4,1,11,12,13]));if(t.includes(`--help`)||t.includes(`-h`))return{stdout:F2(),stderr:``,exitCode:0};let l=t.includes(`--json`),u=t.includes(`--all`),d=t.includes(`--all-versions`),f=t.includes(`--refresh`),p=t.includes(`--no-benchmarks`),m=t.indexOf(`--provider`),h=m>=0?t[m+1]:void 0,g=o(),_=c(),v=n();if(v.length===0)return{stdout:``,stderr:`No provider accounts configured. Run the provider settings to add one.
4216
+ `,exitCode:1};let y;p||(y=await M2(e,f),y.length===0&&(y=void 0));let b;if(h){let e=r();if(!e.includes(h))return{stdout:``,stderr:`Unknown provider: ${h}. Available: ${e.join(`, `)}\n`,exitCode:1};b=[h]}else b=u?[...new Set(v.map(e=>e.providerId))]:[g];let x=[],S=[];for(let e of b){let t=a(e).filter(z2);if(t.length===0){if(!u)return{stdout:``,stderr:`No models available for provider ${e}.\n`,exitCode:1};continue}let n=t.map(t=>H2(t,e,_,g,y)).sort((e,t)=>t.cost.input-e.cost.input);if(d||(n=V2(n)),x.push(...n),!l){let t=i(e);S.push(U2(t.name,e,n,!!y))}}return l?{stdout:JSON.stringify(x,null,2)+`
4217
4217
  `,stderr:``,exitCode:0}:(!d&&!l&&S.push(`Showing latest versions only. Use --all-versions to see all.
4218
4218
  `),{stdout:S.join(`
4219
- `),stderr:``,exitCode:0})})}var H2=i({createCostCommand:()=>Z2,registerSessionCostsProvider:()=>W2}),U2=null;function W2(e){U2=e}function G2(){return`cost - show session cost breakdown
4219
+ `),stderr:``,exitCode:0})})}var G2=i({createCostCommand:()=>e4,registerSessionCostsProvider:()=>q2}),K2=null;function q2(e){K2=e}function J2(){return`cost - show session cost breakdown
4220
4220
 
4221
4221
  Usage: cost [options]
4222
4222
 
4223
4223
  Options:
4224
4224
  --json Output as JSON (for programmatic use)
4225
4225
  -h, --help Show this help message
4226
- `}function K2(e){let t=e/1e6;return t<.01?`<0.01`:t.toFixed(2)}function q2(e){return`$${e.toFixed(2)}`}function J2(e,t){if(!t||t===0)return`-`;let n=t/(1e3*60*60);return n===0?`-`:`$${(e/n).toFixed(2)}`}function Y2(e,t){return e.length<=t?e:e.slice(0,t-3)+`...`}function X2(e){let t=[];t.push(`Session Cost Breakdown:
4227
- `);let n=` `+`Agent`.padEnd(16)+`Model`.padEnd(18)+`MTok (in/out)`.padEnd(15)+`Cache (r/w)`.padEnd(15)+`Cost`.padStart(10)+`$/hour`.padStart(10),r=` `+`─`.repeat(84);t.push(n),t.push(r);let i=0,a=0,o=0,s=0,c=0;for(let n of e){let e=n.name.padEnd(16),r=Y2(n.model,18).padEnd(18),l=`${K2(n.usage.input).padStart(5)} / ${K2(n.usage.output).padStart(5)}`.padEnd(15),u=`${K2(n.usage.cacheRead).padStart(5)} / ${K2(n.usage.cacheWrite).padStart(5)}`.padEnd(15),d=q2(n.usage.cost.total).padStart(10),f=J2(n.usage.cost.total,n.activeTimeMs).padStart(10);t.push(` ${e}${r}${l}${u}${d}${f}`),i+=n.usage.input,a+=n.usage.output,o+=n.usage.cacheRead,s+=n.usage.cacheWrite,c+=n.usage.cost.total}t.push(r);let l=`Total`.padEnd(16),u=``.padEnd(18),d=`${K2(i).padStart(5)} / ${K2(a).padStart(5)}`.padEnd(15),f=`${K2(o).padStart(5)} / ${K2(s).padStart(5)}`.padEnd(15),p=q2(c).padStart(10),m=``.padStart(10);return t.push(` ${l}${u}${d}${f}${p}${m}`),t.join(`
4226
+ `}function Y2(e){let t=e/1e6;return t<.01?`<0.01`:t.toFixed(2)}function X2(e){return`$${e.toFixed(2)}`}function Z2(e,t){if(!t||t===0)return`-`;let n=t/(1e3*60*60);return n===0?`-`:`$${(e/n).toFixed(2)}`}function Q2(e,t){return e.length<=t?e:e.slice(0,t-3)+`...`}function $2(e){let t=[];t.push(`Session Cost Breakdown:
4227
+ `);let n=` `+`Agent`.padEnd(16)+`Model`.padEnd(18)+`MTok (in/out)`.padEnd(15)+`Cache (r/w)`.padEnd(15)+`Cost`.padStart(10)+`$/hour`.padStart(10),r=` `+`─`.repeat(84);t.push(n),t.push(r);let i=0,a=0,o=0,s=0,c=0;for(let n of e){let e=n.name.padEnd(16),r=Q2(n.model,18).padEnd(18),l=`${Y2(n.usage.input).padStart(5)} / ${Y2(n.usage.output).padStart(5)}`.padEnd(15),u=`${Y2(n.usage.cacheRead).padStart(5)} / ${Y2(n.usage.cacheWrite).padStart(5)}`.padEnd(15),d=X2(n.usage.cost.total).padStart(10),f=Z2(n.usage.cost.total,n.activeTimeMs).padStart(10);t.push(` ${e}${r}${l}${u}${d}${f}`),i+=n.usage.input,a+=n.usage.output,o+=n.usage.cacheRead,s+=n.usage.cacheWrite,c+=n.usage.cost.total}t.push(r);let l=`Total`.padEnd(16),u=``.padEnd(18),d=`${Y2(i).padStart(5)} / ${Y2(a).padStart(5)}`.padEnd(15),f=`${Y2(o).padStart(5)} / ${Y2(s).padStart(5)}`.padEnd(15),p=X2(c).padStart(10),m=``.padStart(10);return t.push(` ${l}${u}${d}${f}${p}${m}`),t.join(`
4228
4228
  `)+`
4229
- `}function Z2(){return gR(`cost`,async e=>{if(e.includes(`--help`)||e.includes(`-h`))return{stdout:G2(),stderr:``,exitCode:0};if(!U2)return{stdout:``,stderr:`Cost data not available.
4230
- `,exitCode:1};let t=await U2();return t.length===0?{stdout:`No session cost data yet.
4229
+ `}function e4(){return gR(`cost`,async e=>{if(e.includes(`--help`)||e.includes(`-h`))return{stdout:J2(),stderr:``,exitCode:0};if(!K2)return{stdout:``,stderr:`Cost data not available.
4230
+ `,exitCode:1};let t=await K2();return t.length===0?{stdout:`No session cost data yet.
4231
4231
  `,stderr:``,exitCode:0}:e.includes(`--json`)?{stdout:JSON.stringify(t,null,2)+`
4232
- `,stderr:``,exitCode:0}:{stdout:X2(t),stderr:``,exitCode:0}})}function Q2(){return gR(`nuke`,async e=>e.includes(`--help`)||e.includes(`-h`)?{stdout:`Usage: nuke <launch-code>
4232
+ `,stderr:``,exitCode:0}:{stdout:$2(t),stderr:``,exitCode:0}})}function t4(){return gR(`nuke`,async e=>e.includes(`--help`)||e.includes(`-h`)?{stdout:`Usage: nuke <launch-code>
4233
4233
 
4234
4234
  Completely reset the environment by deleting all local data and reloading.
4235
4235
  Destroys the file system, chat history, and scoops database.
@@ -4237,7 +4237,7 @@ Requires the secret launch code to proceed.
4237
4237
  `,stderr:``,exitCode:0}:e.join(``).includes(`1234`)?(indexedDB.databases().then(e=>{for(let t of e)t.name&&indexedDB.deleteDatabase(t.name)}),setTimeout(()=>location.reload(),0),{stdout:`Nuking everything…
4238
4238
  `,stderr:``,exitCode:0}):{stdout:``,stderr:`⚠️ WARNING: this will reset the entire environment, file system, chats, and scoops.
4239
4239
  Run nuke again with the secret launch code to proceed.
4240
- `,exitCode:1})}var $2=o(`agent-command`),e4=`usage: agent <cwd> <allowed-commands> <prompt>
4240
+ `,exitCode:1})}var n4=o(`agent-command`),r4=`usage: agent <cwd> <allowed-commands> <prompt>
4241
4241
 
4242
4242
  Spawns a sub-scoop, feeds it a task, blocks until the agent loop completes,
4243
4243
  then prints the scoop's final message on stdout.
@@ -4274,17 +4274,17 @@ Examples:
4274
4274
  agent /home ls,wc,find "how many files do I have in my home directory"
4275
4275
  agent --model claude-haiku-4-5 . "*" "summarize files in this directory"
4276
4276
  agent --read-only /workspace/,/shared/assets/ . "*" "review the docs"
4277
- `;function t4(e){let t=[],n=!1,r,i,a=0;for(;a<e.length;){let o=e[a];if(t.length===2){t.push(o),a+=1;continue}if(o===`-h`||o===`--help`){n=!0,a+=1;continue}if(o===`--model`){let t=e[a+1];if(t===void 0||t.length>0&&t.startsWith(`-`))return{help:!1,error:`agent: --model requires a value`};if(t===``)return{help:!1,error:`agent: --model requires a non-empty value`};r=t,a+=2;continue}if(o===`--read-only`){let t=e[a+1];if(t===void 0||t.length>0&&t.startsWith(`-`))return{help:!1,error:`agent: --read-only requires a value`};if(t===``)return{help:!1,error:`agent: --read-only requires a non-empty value`};let n=n4(t);if(n.length===0)return{help:!1,error:`agent: --read-only requires a non-empty value`};i=n,a+=2;continue}if(o.length>0&&o.startsWith(`-`))return{help:!1,error:`agent: unknown flag '${o}'`};t.push(o),a+=1}if(n)return{help:!0};if(t.length<3)return{help:!1,error:`agent: missing required argument ${[`<cwd>`,`<allowed-commands>`,`<prompt>`][t.length]}`};if(t.length>3)return{help:!1,error:`agent: too many arguments`};let[o,s,c]=t;return{help:!1,cwd:o,allowedCommandsRaw:s,prompt:c,modelId:r,visiblePaths:i}}function n4(e){return e.split(`,`).map(e=>e.trim()).filter(e=>e.length>0)}function r4(e,t){return e.startsWith(`/`)?k(e):k(`${t.length>0?t:`/`}/${e}`)}function i4(e){return e.split(`,`).map(e=>e.trim()).filter(e=>e.length>0)}function a4(e){return e==null?`
4277
+ `;function i4(e){let t=[],n=!1,r,i,a=0;for(;a<e.length;){let o=e[a];if(t.length===2){t.push(o),a+=1;continue}if(o===`-h`||o===`--help`){n=!0,a+=1;continue}if(o===`--model`){let t=e[a+1];if(t===void 0||t.length>0&&t.startsWith(`-`))return{help:!1,error:`agent: --model requires a value`};if(t===``)return{help:!1,error:`agent: --model requires a non-empty value`};r=t,a+=2;continue}if(o===`--read-only`){let t=e[a+1];if(t===void 0||t.length>0&&t.startsWith(`-`))return{help:!1,error:`agent: --read-only requires a value`};if(t===``)return{help:!1,error:`agent: --read-only requires a non-empty value`};let n=a4(t);if(n.length===0)return{help:!1,error:`agent: --read-only requires a non-empty value`};i=n,a+=2;continue}if(o.length>0&&o.startsWith(`-`))return{help:!1,error:`agent: unknown flag '${o}'`};t.push(o),a+=1}if(n)return{help:!0};if(t.length<3)return{help:!1,error:`agent: missing required argument ${[`<cwd>`,`<allowed-commands>`,`<prompt>`][t.length]}`};if(t.length>3)return{help:!1,error:`agent: too many arguments`};let[o,s,c]=t;return{help:!1,cwd:o,allowedCommandsRaw:s,prompt:c,modelId:r,visiblePaths:i}}function a4(e){return e.split(`,`).map(e=>e.trim()).filter(e=>e.length>0)}function o4(e,t){return e.startsWith(`/`)?k(e):k(`${t.length>0?t:`/`}/${e}`)}function s4(e){return e.split(`,`).map(e=>e.trim()).filter(e=>e.length>0)}function c4(e){return e==null?`
4278
4278
  `:e.replace(/\n+$/,``)+`
4279
- `}function o4(e){return e==null||e===``?``:e.replace(/\n+$/,``)+`
4280
- `}function s4(){let e=globalThis.__slicc_agent;if(!(!e||typeof e.spawn!=`function`))return e}function c4(e={}){let{getParentJid:t}=e;return gR(`agent`,async(e,n)=>{let r=t4(e);if(r.help)return{stdout:e4,stderr:``,exitCode:0};if(r.error)return{stdout:``,stderr:`${r.error}\n`,exitCode:1};let i=r.cwd??``;if(i===``)return{stdout:``,stderr:`agent: <cwd> must not be empty
4281
- `,exitCode:1};let a=r4(i,n.cwd),o=i4(r.allowedCommandsRaw??``),s=r.prompt??``;try{if(!(await n.fs.stat(a)).isDirectory)return{stdout:``,stderr:`agent: cwd not a directory: ${i}\n`,exitCode:1}}catch{return{stdout:``,stderr:`agent: cwd not found: ${i}\n`,exitCode:1}}let c=n.fs;if(typeof c.canWrite==`function`&&!c.canWrite(a))return{stdout:``,stderr:`agent: cwd not writable: ${i}\n`,exitCode:1};let l=s4();if(!l)return{stdout:``,stderr:`agent: orchestrator bridge not available
4282
- `,exitCode:1};let u={cwd:a,allowedCommands:o,prompt:s};r.modelId!==void 0&&(u.modelId=r.modelId),r.visiblePaths!==void 0&&(u.visiblePaths=r.visiblePaths),n.cwd&&n.cwd.length>0&&(u.invokingCwd=n.cwd);let d=t?.();d!==void 0&&d.length>0&&(u.parentJid=d);try{let e=await l.spawn(u),t=typeof e?.exitCode==`number`?e.exitCode:0,n=e?.finalText;return t===0?{stdout:a4(n),stderr:``,exitCode:0}:{stdout:``,stderr:o4(n),exitCode:t}}catch(e){let t=e instanceof Error?e.message:String(e);return $2.error(`agent bridge threw`,e),{stdout:``,stderr:`${t}\n`,exitCode:1}}})}function l4(e={}){let t=[l$({getJshCommands:e.getJshCommands}),V$(),H1(e.browserAPI,e.fs),T1(),W$(e),$0(),Z1(),W1(`sqlite3`),W1(`sqllite`),x1(),z1(`python3`),z1(`python`),e0(),s0(),u0(),x0(),P1(`pdftk`),P1(`pdf`),f$(`convert`),f$(`magick`),X0({fs:e.fs,scriptCatalog:e.scriptCatalog}),K1(),Y1(),C0(),O0(),G0({fs:e.fs}),i2(),d2(),f2(),p2(`xclip`),p2(`xsel`),v2(),C2(),w2(),V2(e.fs),Z2(),Q2(),c4({getParentJid:e.getParentJid})];return typeof chrome<`u`&&chrome?.runtime?.id&&t.push(T2()),e.fs&&t.push(...mQ.map(t=>o$(t,e.browserAPI,e.fs))),t}var u4=`https://wry-manatee-359.convex.site/api/v1`,d4=`https://api.tessl.io`,f4=`/workspace/skills`,p4=`slicc-fs-global`,m4=`/workspace/.git/github-token`,h4=`application/vnd.github.v3+json`,g4=`https://www.sliccy.com/skills/catalog.json`;function _4(e){if(!(!e||!e.trim()))return e.split(`,`).map(e=>e.trim()).filter(Boolean)}function v4(e){return e.map(e=>{let t=e.boost?parseFloat(e.boost):NaN,n=Number.isFinite(t)?t:void 0;return{name:e.name,displayName:e.displayName||e.name,description:e.description||``,source:{repo:e.repo,path:e.path||void 0,skill:e.skill||void 0},affinity:{apps:_4(e.apps),tasks:_4(e.tasks),role:_4(e.role),purpose:_4(e.purpose)},priority:n}})}var y4={apps:3,tasks:2,role:1,purpose:1};function b4(e,t){return e.map(e=>{let n=0,r=[],i=(e.affinity.apps??[]).filter(e=>t.apps.includes(e));i.length&&(n+=i.length*y4.apps,r.push(`apps(${i.join(`, `)})`));let a=(e.affinity.tasks??[]).filter(e=>t.tasks.includes(e));return a.length&&(n+=a.length*y4.tasks,r.push(`tasks(${a.join(`, `)})`)),(e.affinity.role??[]).includes(t.role)&&(n+=y4.role,r.push(`role(${t.role})`)),(e.affinity.purpose??[]).includes(t.purpose)&&(n+=y4.purpose,r.push(`purpose(${t.purpose})`)),n*=e.priority??1,{entry:e,score:n,matchReasons:r}}).filter(e=>e.score>0).sort((e,t)=>t.score-e.score)}function x4(e){let t=`upskill ${e.repo}`;return e.path&&(t+=` --path ${e.path}`),e.skill&&(t+=` --skill ${e.skill}`),t}async function S4(e){let t=new Set;try{let n=await e.readDir(f4);for(let e of n)e.type===`directory`&&t.add(e.name)}catch{}try{let n=await e.readTextFile(`/${O}/${ne}`),r=JSON.parse(n);for(let e of r.applied_skills??[])t.add(e.name)}catch{}let n=[`.agents`,`.claude`];try{let r=await e.readDir(`/`);for(let i of r)if(i.type===`directory`)for(let r of n)try{let n=`/${i.name}/${r}/skills`,a=await e.readDir(n);for(let e of a)e.type===`directory`&&t.add(e.name)}catch{}}catch{}return t}var C4;function w4(){return C4||=Hs.create({dbName:p4}),C4}async function T4(){try{return(await(await w4()).readTextFile(m4)).trim()||void 0}catch{return}}function E4(e,t=h4){let n={Accept:t,"User-Agent":`slicc-upskill`};return e&&(n.Authorization=`Bearer ${e}`),n}async function D4(e){let t=await T4();return{hasToken:!!t,request:(n,r=h4)=>e(n,{headers:E4(t,r)})}}function O4(e,t){if(!e)return;let n=t.toLowerCase();for(let[t,r]of Object.entries(e))if(t.toLowerCase()===n)return r}function k4(e){let t=MW(e);if(!t)return;try{let e=JSON.parse(t);if(typeof e.message==`string`&&e.message.trim())return e.message.trim()}catch{}let n=t.trim();if(n)return n.slice(0,200)}function A4(e,t,n){let r=k4(e.body),i=r?` GitHub said: ${r}`:``,a=O4(e.headers,`retry-after`),o=O4(e.headers,`x-ratelimit-remaining`),s=r?.toLowerCase()??``;if(e.status===429||o===`0`||s.includes(`rate limit`))return n?`GitHub rate-limited access to ${t} (HTTP ${e.status}). The configured github.token was used, so retry later${a?` after about ${a} seconds`:``}.${i}`:`GitHub rate-limited anonymous access to ${t} (HTTP ${e.status}). This often happens on shared VPNs or corporate egress IPs because unauthenticated GitHub API requests are limited per IP. Configure a token with: git config github.token <PAT>, then retry. You can also retry off VPN or later.${i}`;if(e.status===401)return n?`GitHub rejected the configured github.token while accessing ${t} (HTTP 401). Update it with: git config github.token <PAT>, then retry.${i}`:`GitHub requires authentication to access ${t} (HTTP 401). Configure a token with: git config github.token <PAT>, then retry.${i}`;if(e.status===404)return`GitHub could not find ${t} (HTTP 404). Check the repository, path, and permissions.${i}`;if(e.status===403)return n?`GitHub denied access to ${t} (HTTP 403). Check that your github.token can access this repository or retry later if GitHub is throttling requests.${i}`:`GitHub denied anonymous access to ${t} (HTTP 403). If this repo is public on a shared VPN, you may have hit GitHub's shared IP limit; otherwise the repository or path may require authentication. Configure a token with: git config github.token <PAT>, then retry.${i}`;let c=e.statusText?` ${e.statusText}`:``;return`GitHub request for ${t} failed (HTTP ${e.status}${c}).${i}`}function j4(){return`Discovery roots: /workspace/skills plus accessible **/.agents/skills/* and **/.claude/skills/* anywhere in the VFS.
4283
- `}function M4(){return`Only native /workspace/skills entries are install-managed; compatibility-discovered .agents/.claude skills remain read-only.
4284
- `}function N4(e){switch(e){case`native`:return`native`;case`agents`:return`.agents`;case`claude`:return`.claude`}}function P4(e){return e.source===`native`}function F4(e){return P4(e)?e.installed&&e.installedVersion?`installed (v${e.installedVersion})`:`available`:e.installed&&e.installedVersion?`compatibility (state v${e.installedVersion})`:`compatibility (read-only)`}function I4(e){return P4(e)?`install-managed (/workspace/skills)`:`compatibility-only (read-only)`}function L4(e,t){let n=`${t}:\n\n`;n+=` NAME VERSION SOURCE STATUS
4279
+ `}function l4(e){return e==null||e===``?``:e.replace(/\n+$/,``)+`
4280
+ `}function u4(){let e=globalThis.__slicc_agent;if(!(!e||typeof e.spawn!=`function`))return e}function d4(e={}){let{getParentJid:t}=e;return gR(`agent`,async(e,n)=>{let r=i4(e);if(r.help)return{stdout:r4,stderr:``,exitCode:0};if(r.error)return{stdout:``,stderr:`${r.error}\n`,exitCode:1};let i=r.cwd??``;if(i===``)return{stdout:``,stderr:`agent: <cwd> must not be empty
4281
+ `,exitCode:1};let a=o4(i,n.cwd),o=s4(r.allowedCommandsRaw??``),s=r.prompt??``;try{if(!(await n.fs.stat(a)).isDirectory)return{stdout:``,stderr:`agent: cwd not a directory: ${i}\n`,exitCode:1}}catch{return{stdout:``,stderr:`agent: cwd not found: ${i}\n`,exitCode:1}}let c=n.fs;if(typeof c.canWrite==`function`&&!c.canWrite(a))return{stdout:``,stderr:`agent: cwd not writable: ${i}\n`,exitCode:1};let l=u4();if(!l)return{stdout:``,stderr:`agent: orchestrator bridge not available
4282
+ `,exitCode:1};let u={cwd:a,allowedCommands:o,prompt:s};r.modelId!==void 0&&(u.modelId=r.modelId),r.visiblePaths!==void 0&&(u.visiblePaths=r.visiblePaths),n.cwd&&n.cwd.length>0&&(u.invokingCwd=n.cwd);let d=t?.();d!==void 0&&d.length>0&&(u.parentJid=d);try{let e=await l.spawn(u),t=typeof e?.exitCode==`number`?e.exitCode:0,n=e?.finalText;return t===0?{stdout:c4(n),stderr:``,exitCode:0}:{stdout:``,stderr:l4(n),exitCode:t}}catch(e){let t=e instanceof Error?e.message:String(e);return n4.error(`agent bridge threw`,e),{stdout:``,stderr:`${t}\n`,exitCode:1}}})}function f4(e={}){let t=[f$({getJshCommands:e.getJshCommands}),W$(),G1(e.browserAPI,e.fs),O1(),q$(e),n2(),e0(),q1(`sqlite3`),q1(`sqllite`),w1(),H1(`python3`),H1(`python`),r0(),u0(),p0(),w0(),L1(`pdftk`),L1(`pdf`),h$(`convert`),h$(`magick`),$0({fs:e.fs,scriptCatalog:e.scriptCatalog}),Y1(),Q1(),E0(),j0(),J0({fs:e.fs}),s2(),m2(),h2(),g2(`xclip`),g2(`xsel`),x2(),E2(),D2(),W2(e.fs),e4(),t4(),d4({getParentJid:e.getParentJid})];return typeof chrome<`u`&&chrome?.runtime?.id&&t.push(O2()),e.fs&&t.push(..._Q.map(t=>l$(t,e.browserAPI,e.fs))),t}var p4=`https://wry-manatee-359.convex.site/api/v1`,m4=`https://api.tessl.io`,h4=`/workspace/skills`,g4=`slicc-fs-global`,_4=`/workspace/.git/github-token`,v4=`application/vnd.github.v3+json`,y4=`https://www.sliccy.com/skills/catalog.json`;function b4(e){if(!(!e||!e.trim()))return e.split(`,`).map(e=>e.trim()).filter(Boolean)}function x4(e){return e.map(e=>{let t=e.boost?parseFloat(e.boost):NaN,n=Number.isFinite(t)?t:void 0;return{name:e.name,displayName:e.displayName||e.name,description:e.description||``,source:{repo:e.repo,path:e.path||void 0,skill:e.skill||void 0},affinity:{apps:b4(e.apps),tasks:b4(e.tasks),role:b4(e.role),purpose:b4(e.purpose)},priority:n}})}var S4={apps:3,tasks:2,role:1,purpose:1};function C4(e,t){return e.map(e=>{let n=0,r=[],i=(e.affinity.apps??[]).filter(e=>t.apps.includes(e));i.length&&(n+=i.length*S4.apps,r.push(`apps(${i.join(`, `)})`));let a=(e.affinity.tasks??[]).filter(e=>t.tasks.includes(e));return a.length&&(n+=a.length*S4.tasks,r.push(`tasks(${a.join(`, `)})`)),(e.affinity.role??[]).includes(t.role)&&(n+=S4.role,r.push(`role(${t.role})`)),(e.affinity.purpose??[]).includes(t.purpose)&&(n+=S4.purpose,r.push(`purpose(${t.purpose})`)),n*=e.priority??1,{entry:e,score:n,matchReasons:r}}).filter(e=>e.score>0).sort((e,t)=>t.score-e.score)}function w4(e){let t=`upskill ${e.repo}`;return e.path&&(t+=` --path ${e.path}`),e.skill&&(t+=` --skill ${e.skill}`),t}async function T4(e){let t=new Set;try{let n=await e.readDir(h4);for(let e of n)e.type===`directory`&&t.add(e.name)}catch{}try{let n=await e.readTextFile(`/${O}/${ne}`),r=JSON.parse(n);for(let e of r.applied_skills??[])t.add(e.name)}catch{}let n=[`.agents`,`.claude`];try{let r=await e.readDir(`/`);for(let i of r)if(i.type===`directory`)for(let r of n)try{let n=`/${i.name}/${r}/skills`,a=await e.readDir(n);for(let e of a)e.type===`directory`&&t.add(e.name)}catch{}}catch{}return t}var E4;function D4(){return E4||=Hs.create({dbName:g4}),E4}async function O4(){try{return(await(await D4()).readTextFile(_4)).trim()||void 0}catch{return}}function k4(e,t=v4){let n={Accept:t,"User-Agent":`slicc-upskill`};return e&&(n.Authorization=`Bearer ${e}`),n}async function A4(e){let t=await O4();return{hasToken:!!t,request:(n,r=v4)=>e(n,{headers:k4(t,r)})}}function j4(e,t){if(!e)return;let n=t.toLowerCase();for(let[t,r]of Object.entries(e))if(t.toLowerCase()===n)return r}function M4(e){let t=MW(e);if(!t)return;try{let e=JSON.parse(t);if(typeof e.message==`string`&&e.message.trim())return e.message.trim()}catch{}let n=t.trim();if(n)return n.slice(0,200)}function N4(e,t,n){let r=M4(e.body),i=r?` GitHub said: ${r}`:``,a=j4(e.headers,`retry-after`),o=j4(e.headers,`x-ratelimit-remaining`),s=r?.toLowerCase()??``;if(e.status===429||o===`0`||s.includes(`rate limit`))return n?`GitHub rate-limited access to ${t} (HTTP ${e.status}). The configured github.token was used, so retry later${a?` after about ${a} seconds`:``}.${i}`:`GitHub rate-limited anonymous access to ${t} (HTTP ${e.status}). This often happens on shared VPNs or corporate egress IPs because unauthenticated GitHub API requests are limited per IP. Configure a token with: git config github.token <PAT>, then retry. You can also retry off VPN or later.${i}`;if(e.status===401)return n?`GitHub rejected the configured github.token while accessing ${t} (HTTP 401). Update it with: git config github.token <PAT>, then retry.${i}`:`GitHub requires authentication to access ${t} (HTTP 401). Configure a token with: git config github.token <PAT>, then retry.${i}`;if(e.status===404)return`GitHub could not find ${t} (HTTP 404). Check the repository, path, and permissions.${i}`;if(e.status===403)return n?`GitHub denied access to ${t} (HTTP 403). Check that your github.token can access this repository or retry later if GitHub is throttling requests.${i}`:`GitHub denied anonymous access to ${t} (HTTP 403). If this repo is public on a shared VPN, you may have hit GitHub's shared IP limit; otherwise the repository or path may require authentication. Configure a token with: git config github.token <PAT>, then retry.${i}`;let c=e.statusText?` ${e.statusText}`:``;return`GitHub request for ${t} failed (HTTP ${e.status}${c}).${i}`}function P4(){return`Discovery roots: /workspace/skills plus accessible **/.agents/skills/* and **/.claude/skills/* anywhere in the VFS.
4283
+ `}function F4(){return`Only native /workspace/skills entries are install-managed; compatibility-discovered .agents/.claude skills remain read-only.
4284
+ `}function I4(e){switch(e){case`native`:return`native`;case`agents`:return`.agents`;case`claude`:return`.claude`}}function L4(e){return e.source===`native`}function R4(e){return L4(e)?e.installed&&e.installedVersion?`installed (v${e.installedVersion})`:`available`:e.installed&&e.installedVersion?`compatibility (state v${e.installedVersion})`:`compatibility (read-only)`}function z4(e){return L4(e)?`install-managed (/workspace/skills)`:`compatibility-only (read-only)`}function B4(e,t){let n=`${t}:\n\n`;n+=` NAME VERSION SOURCE STATUS
4285
4285
  `,n+=` ─────────────────────────────────────────────────────────────
4286
- `;for(let t of e)n+=` ${t.name.padEnd(20)} ${t.manifest.version.padEnd(10)} ${N4(t.source).padEnd(9)} ${F4(t)}\n`;return n+=`\n${j4()}`,n+=M4(),n}function R4(e){let t=`Skill: ${e.manifest.skill}\n`;if(t+=`Version: ${e.manifest.version}\n`,t+=`Description: ${e.manifest.description||`(none)`}\n`,t+=`Source: ${N4(e.source)}\n`,t+=`Source root: ${e.sourceRoot}\n`,t+=`Management: ${I4(e)}\n`,t+=`Status: ${F4(e)}\n`,e.skillFilePath&&(t+=`Instructions: ${e.skillFilePath}\n`),e.shadowedPaths?.length){t+=`Shadowed paths:
4287
- `;for(let n of e.shadowedPaths)t+=` - ${n}\n`}return t}function z4(e,t){return`${e}: "${t.name}" is discoverable from ${t.sourceRoot} but remains compatibility-only/read-only. Only native /workspace/skills entries are install-managed.\n`}function B4(){return{stdout:`usage: upskill <command> [options]
4286
+ `;for(let t of e)n+=` ${t.name.padEnd(20)} ${t.manifest.version.padEnd(10)} ${I4(t.source).padEnd(9)} ${R4(t)}\n`;return n+=`\n${P4()}`,n+=F4(),n}function V4(e){let t=`Skill: ${e.manifest.skill}\n`;if(t+=`Version: ${e.manifest.version}\n`,t+=`Description: ${e.manifest.description||`(none)`}\n`,t+=`Source: ${I4(e.source)}\n`,t+=`Source root: ${e.sourceRoot}\n`,t+=`Management: ${z4(e)}\n`,t+=`Status: ${R4(e)}\n`,e.skillFilePath&&(t+=`Instructions: ${e.skillFilePath}\n`),e.shadowedPaths?.length){t+=`Shadowed paths:
4287
+ `;for(let n of e.shadowedPaths)t+=` - ${n}\n`}return t}function H4(e,t){return`${e}: "${t.name}" is discoverable from ${t.sourceRoot} but remains compatibility-only/read-only. Only native /workspace/skills entries are install-managed.\n`}function U4(){return{stdout:`usage: upskill <command> [options]
4288
4288
 
4289
4289
  Install skills from GitHub repositories, ClawHub, or Tessl registry.
4290
4290
 
@@ -4297,7 +4297,7 @@ Commands:
4297
4297
  <clawhub-url> Install skill from ClawHub URL
4298
4298
  tessl:<name> Install skill from Tessl registry
4299
4299
 
4300
- ${j4()}${M4()}
4300
+ ${P4()}${F4()}
4301
4301
 
4302
4302
  GitHub Installation:
4303
4303
  upskill owner/repo List available skills in repo
@@ -4338,20 +4338,20 @@ Examples:
4338
4338
  upskill aemcoder/skills@fix/stateless-tab-targeting --all
4339
4339
  upskill https://clawhub.ai/arun-8687/tavily-search
4340
4340
  upskill tessl:postgres-pro
4341
- `,stderr:``,exitCode:0}}async function V4(e,t){let n=await t(`${u4}/search?q=${encodeURIComponent(e)}`,{headers:{Accept:`application/json`}});if(n.status!==200)throw Error(`ClawHub returned HTTP ${n.status}`);let r=NW(n.body);return r.results?r.results.map(e=>({name:e.slug,displayName:e.displayName||e.slug,summary:e.summary||``,source:`clawhub`,qualityScore:null,installHint:`upskill clawhub:${e.slug}`})):[]}function H4(e){let t=e.match(/github\.com\/([^\/?#]+)\/([^\/?#]+)/);return t?{owner:t[1],repo:t[2].replace(/\.git$/,``)}:null}async function U4(e,t){let n=await t(`${d4}/experimental/search?q=${encodeURIComponent(e)}&contentType=skills&page%5Bsize%5D=20`,{headers:{Accept:`application/json`}});if(n.status!==200)throw Error(`Tessl returned HTTP ${n.status}`);let r=NW(n.body);if(!r.data)return[];let i=new Map;for(let e of r.data){if(e.type!==`skill`)continue;let t=e.attributes,n=H4(t.sourceUrl),r=n?`${n.owner}/${n.repo}`:void 0,a=t.scores.aggregate==null?null:Math.round(t.scores.aggregate*100),o=t.sourceUrl||e.id,s=i.get(o);if(s&&s.qualityScore!=null&&a!=null&&s.qualityScore>=a)continue;let c=t.path.replace(/\/SKILL\.md$/i,``),l=c.split(`/`).pop()||t.name,u=n?`upskill ${n.owner}/${n.repo} --path ${c.split(`/`).slice(0,-1).join(`/`)||`.`} --skill ${l}`:`upskill tessl:${t.name}`;i.set(o,{name:t.name,displayName:t.name,summary:t.description||``,source:`tessl`,qualityScore:a,installHint:u,featured:t.featured,sourceRepo:r})}return Array.from(i.values())}var W4=10;async function G4(e,t,n=1){let[r,i]=await Promise.allSettled([V4(e,t),U4(e,t)]),a=r.status===`fulfilled`?r.value:[],o=i.status===`fulfilled`?i.value:[];if(a.length===0&&o.length===0){let t=``;return r.status===`rejected`&&i.status===`rejected`&&(t=`upskill: both registries failed to respond
4342
- `),{stdout:`No skills found for "${e}"\n\nTry a different search term or browse https://clawhub.ai or https://tessl.io/registry\n`,stderr:t,exitCode:+!!t}}let s=[],c=0,l=0;for(;c<o.length&&c<3;)s.push(o[c++]);for(;l<a.length||c<o.length;)l<a.length&&s.push(a[l++]),c<o.length&&s.push(o[c++]);let u=s.length,d=Math.ceil(u/W4),f=Math.max(1,Math.min(n,d)),p=(f-1)*W4,m=s.slice(p,p+W4),h=`Search results for "${e}" (page ${f}/${d}, ${u} total):\n\n`;for(let e of m){let t=e.qualityScore==null?` `:String(e.qualityScore).padStart(3),n=`[${e.source}]`,r=e.sourceRepo?` ${e.sourceRepo}`:``;h+=` ${e.name.padEnd(30)} ${t} ${n.padEnd(10)}${r}\n`,e.summary&&(h+=` ${e.summary}\n`),h+=`
4341
+ `,stderr:``,exitCode:0}}async function W4(e,t){let n=await t(`${p4}/search?q=${encodeURIComponent(e)}`,{headers:{Accept:`application/json`}});if(n.status!==200)throw Error(`ClawHub returned HTTP ${n.status}`);let r=NW(n.body);return r.results?r.results.map(e=>({name:e.slug,displayName:e.displayName||e.slug,summary:e.summary||``,source:`clawhub`,qualityScore:null,installHint:`upskill clawhub:${e.slug}`})):[]}function G4(e){let t=e.match(/github\.com\/([^\/?#]+)\/([^\/?#]+)/);return t?{owner:t[1],repo:t[2].replace(/\.git$/,``)}:null}async function K4(e,t){let n=await t(`${m4}/experimental/search?q=${encodeURIComponent(e)}&contentType=skills&page%5Bsize%5D=20`,{headers:{Accept:`application/json`}});if(n.status!==200)throw Error(`Tessl returned HTTP ${n.status}`);let r=NW(n.body);if(!r.data)return[];let i=new Map;for(let e of r.data){if(e.type!==`skill`)continue;let t=e.attributes,n=G4(t.sourceUrl),r=n?`${n.owner}/${n.repo}`:void 0,a=t.scores.aggregate==null?null:Math.round(t.scores.aggregate*100),o=t.sourceUrl||e.id,s=i.get(o);if(s&&s.qualityScore!=null&&a!=null&&s.qualityScore>=a)continue;let c=t.path.replace(/\/SKILL\.md$/i,``),l=c.split(`/`).pop()||t.name,u=n?`upskill ${n.owner}/${n.repo} --path ${c.split(`/`).slice(0,-1).join(`/`)||`.`} --skill ${l}`:`upskill tessl:${t.name}`;i.set(o,{name:t.name,displayName:t.name,summary:t.description||``,source:`tessl`,qualityScore:a,installHint:u,featured:t.featured,sourceRepo:r})}return Array.from(i.values())}var q4=10;async function J4(e,t,n=1){let[r,i]=await Promise.allSettled([W4(e,t),K4(e,t)]),a=r.status===`fulfilled`?r.value:[],o=i.status===`fulfilled`?i.value:[];if(a.length===0&&o.length===0){let t=``;return r.status===`rejected`&&i.status===`rejected`&&(t=`upskill: both registries failed to respond
4342
+ `),{stdout:`No skills found for "${e}"\n\nTry a different search term or browse https://clawhub.ai or https://tessl.io/registry\n`,stderr:t,exitCode:+!!t}}let s=[],c=0,l=0;for(;c<o.length&&c<3;)s.push(o[c++]);for(;l<a.length||c<o.length;)l<a.length&&s.push(a[l++]),c<o.length&&s.push(o[c++]);let u=s.length,d=Math.ceil(u/q4),f=Math.max(1,Math.min(n,d)),p=(f-1)*q4,m=s.slice(p,p+q4),h=`Search results for "${e}" (page ${f}/${d}, ${u} total):\n\n`;for(let e of m){let t=e.qualityScore==null?` `:String(e.qualityScore).padStart(3),n=`[${e.source}]`,r=e.sourceRepo?` ${e.sourceRepo}`:``;h+=` ${e.name.padEnd(30)} ${t} ${n.padEnd(10)}${r}\n`,e.summary&&(h+=` ${e.summary}\n`),h+=`
4343
4343
  `}return f<d&&(h+=`Showing ${p+1}-${p+m.length} of ${u}. `,h+=`Next page: upskill search ${e} --page ${f+1}\n\n`),h+=`To install:
4344
4344
  `,a.length>0&&(h+=` From ClawHub: upskill clawhub:<slug>
4345
4345
  `),o.length>0&&(h+=` From Tessl: upskill <owner/repo> --skill <name>
4346
- `),{stdout:h,stderr:``,exitCode:0}}async function K4(e,t,n,r=!1,i){try{let a=`${f4}/${e}`;try{if(await t.stat(a),!r)return{stdout:``,stderr:`upskill: skill "${e}" already exists (use --force to overwrite)\n`,exitCode:1};await t.rm(a,{recursive:!0})}catch{}let o=`${u4}/download?slug=${encodeURIComponent(e)}`,s=await n(o,{});if(s.status===404)return{stdout:``,stderr:`upskill: skill "${e}" not found on ClawHub\n`,exitCode:1};if(s.status!==200)return{stdout:``,stderr:`upskill: failed to download skill (HTTP ${s.status})\n`,exitCode:1};let c=s.headers[`content-type`]||``,l=OW(o);l||=PW(s.body);let u;try{u=D(l)}catch(e){let t=e instanceof Error?e.message:String(e),n=Array.from(l.slice(0,20)).map(e=>e.toString(16).padStart(2,`0`)).join(` `);return{stdout:``,stderr:`upskill: failed to unzip: ${t}\nContent-Type: ${c}\nBody: ${l.length} bytes\nHex: ${n}\n`,exitCode:1}}await t.mkdir(a,{recursive:!0});let d=0;for(let[e,n]of Object.entries(u)){let r=e.replace(/\\/g,`/`);if(!r||r.endsWith(`/`)||r===`_meta.json`)continue;let i=`${a}/${r}`,o=i.substring(0,i.lastIndexOf(`/`));o!==a&&await t.mkdir(o,{recursive:!0}),await t.writeFile(i,n),d++}let f=q4(u,i);return await t3(),{stdout:`Installed skill "${e}" from ClawHub (${d} files)\n${f}`,stderr:``,exitCode:0}}catch(e){return{stdout:``,stderr:`upskill: failed to install from ClawHub: ${e instanceof Error?e.message:String(e)}\n`,exitCode:1}}}function q4(e,t){let n;for(let[t,r]of Object.entries(e))if((t.split(`/`).pop()||``).toLowerCase()===`skill.md`){n=new TextDecoder().decode(r);break}if(!n)return``;let r=n.match(/^---\s*\n([\s\S]*?)\n---/);if(!r)return``;let i=r[1],a=J4(i);if(a.length===0)return``;if(!t||t.length===0)return` Requires: ${a.join(`, `)}\n`;let o=new Set(t),s=a.filter(e=>!o.has(e));return s.length===0?` Requires: ${a.join(`, `)} (all available)\n`:` Requires: ${a.join(`, `)}\n Missing: ${s.join(`, `)} -- this skill may not work in the SLICC shell\n`}function J4(e){let t=e.match(/metadata:\s*\n\s*(\{[\s\S]*\})/);if(t)try{let e=JSON.parse(t[1]);for(let t of[`openclaw`,`clawdis`,`clawdbot`]){let n=e[t];if(n?.requires&&typeof n.requires==`object`){let e=n.requires;if(Array.isArray(e.bins))return e.bins.filter(e=>typeof e==`string`)}}}catch{}let n=e.match(/"bins"\s*:\s*\[([^\]]*)\]/);return n?n[1].split(`,`).map(e=>e.trim().replace(/^["']|["']$/g,``)).filter(Boolean):[]}async function Y4(e,t){let n=await t(`${d4}/experimental/search?q=${encodeURIComponent(e)}&contentType=skills&page%5Bsize%5D=5`,{headers:{Accept:`application/json`}});if(n.status!==200)return{error:`Tessl search failed (HTTP ${n.status})`};let r=NW(n.body).data?.find(t=>t.type===`skill`&&t.attributes.name===e);if(!r)return{error:`skill "${e}" not found on Tessl registry`};let i=H4(r.attributes.sourceUrl);if(!i)return{error:`skill "${e}" has no GitHub source URL`};let a=r.attributes.path.replace(/\/SKILL\.md$/i,``);return{owner:i.owner,repo:i.repo,skillPath:a,skillName:e}}async function X4(e,t,n,r=`main`){let i=`https://codeload.github.com/${e}/${t}/zip/refs/heads/${r}`,a=await n(i,{headers:{"User-Agent":`slicc-upskill`}});if(a.status===404)return r===`main`?X4(e,t,n,`master`):{status:`not_found`};if(a.status!==200)return{status:`error`,message:`codeload returned HTTP ${a.status}`};let o=OW(i);o||=PW(a.body);try{return{status:`ok`,files:D(o)}}catch(e){return{status:`error`,message:`failed to unzip: ${e instanceof Error?e.message:String(e)}`}}}function Z4(e){let t={};for(let[n,r]of Object.entries(e)){let e=n.indexOf(`/`);if(e<0)continue;let i=n.slice(e+1);i&&(t[i]=r)}return t}async function Q4(e,t,n,r,i,a){if(i){let n=await X4(e,t,i,a);if(n.status===`ok`){let e=Z4(n.files),t=[],i=r?r.replace(/^\/|\/$/g,``)+`/`:``;for(let n of Object.keys(e))if(n.startsWith(i)&&(n.split(`/`).pop()||``)===`SKILL.md`){let e=n.replace(/\/SKILL\.md$/,``),r=e.split(`/`).pop()||e;t.push({name:r,path:e})}return{skills:t}}if(n.status===`not_found`)return{skills:[],error:`${a?`branch "${a}" in ${e}/${t}`:`repository ${e}/${t}`} not found`}}let o=[];async function s(r){let i=`https://api.github.com/repos/${e}/${t}/contents/${r}`,c=a?`${i}?ref=${encodeURIComponent(a)}`:i,l=await n.request(c);if(l.status!==200)throw Error(A4(l,`${e}/${t}${r?`/${r}`:``}`,n.hasToken));let u=NW(l.body);for(let e of u)if(e.type===`file`&&e.name===`SKILL.md`){let t=e.path.replace(`/SKILL.md`,``),n=t.split(`/`).pop()||t;o.push({name:n,path:t})}else e.type===`dir`&&await s(e.path)}try{return await s(r||``),{skills:o}}catch(e){return{skills:[],error:e instanceof Error?e.message:String(e)}}}async function $4(e,t,n,r,i,a,o=!1,s,c){try{let l=`${f4}/${r}`;try{if(await i.stat(l),!o)return{stdout:``,stderr:`upskill: skill "${r}" already exists (use --force to overwrite)\n`,exitCode:1};await i.rm(l,{recursive:!0})}catch{}if(s){let a=await X4(e,t,s,c);if(a.status===`not_found`)return{stdout:``,stderr:`upskill: ${c?`branch "${c}" in ${e}/${t}`:`repository ${e}/${t}`} not found\n`,exitCode:1};if(a.status===`ok`){let o=Z4(a.files),s=n.replace(/^\/|\/$/g,``)+`/`;await i.mkdir(l,{recursive:!0});let c=0;for(let[e,t]of Object.entries(o)){if(!e.startsWith(s))continue;let n=e.slice(s.length);if(!n||e.endsWith(`/`))continue;let r=`${l}/${n}`,a=r.substring(0,r.lastIndexOf(`/`));a!==l&&await i.mkdir(a,{recursive:!0}),await i.writeFile(r,t),c++}if(c>0)return await a3(),await r3(),{stdout:`Installed skill "${r}" from ${e}/${t}\n`,stderr:``,exitCode:0}}}let u=`https://api.github.com/repos/${e}/${t}/contents/${n}`,d=c?`${u}?ref=${encodeURIComponent(c)}`:u,f=await a.request(d);if(f.status!==200)return{stdout:``,stderr:`upskill: ${A4(f,`${e}/${t}/${n}`,a.hasToken)}\n`,exitCode:1};let p=NW(f.body);await i.mkdir(l,{recursive:!0});async function m(n,r){for(let o of n)if(o.type===`file`&&o.download_url){let n=await a.request(o.download_url,`*/*`);if(n.status!==200)throw Error(A4(n,`${e}/${t}/${o.path}`,a.hasToken));let s=OW(o.download_url);await i.writeFile(`${r}/${o.name}`,s??n.body)}else if(o.type===`dir`){let n=`https://api.github.com/repos/${e}/${t}/contents/${o.path}`,s=c?`${n}?ref=${encodeURIComponent(c)}`:n,l=await a.request(s);if(l.status!==200)throw Error(A4(l,`${e}/${t}/${o.path}`,a.hasToken));let u=NW(l.body);await i.mkdir(`${r}/${o.name}`,{recursive:!0}),await m(u,`${r}/${o.name}`)}}try{await m(p,l)}catch(e){try{await i.rm(l,{recursive:!0})}catch{}throw e}return await t3(),{stdout:`Installed skill "${r}" from ${e}/${t}\n`,stderr:``,exitCode:0}}catch(e){return{stdout:``,stderr:`upskill: failed to install from GitHub: ${e instanceof Error?e.message:String(e)}\n`,exitCode:1}}}function e3(e){let t=e.match(/^https?:\/\/clawhub\.ai\/[^\/]+\/([^\/]+)/);if(t)return t[1];if(e.startsWith(`clawhub:`)){let t=e.slice(8);return t.includes(`/`)?t.split(`/`)[1]:t}return null}async function t3(){await a3(),await r3()}async function n3(e,t,n,r,i=!1){let a=`${f4}/${t}`;try{if(await r.stat(a),!i)return{ok:!1,error:`skill "${t}" already exists (use --force to overwrite)`};await r.rm(a,{recursive:!0})}catch{}let o=e.replace(/^\/|\/$/g,``),s=o?o+`/`:``;await r.mkdir(a,{recursive:!0});let c=0;try{for(let[e,t]of Object.entries(n)){if(!e.startsWith(s))continue;let n=e.slice(s.length);if(!n||e.endsWith(`/`))continue;let i=`${a}/${n}`,o=i.replace(/\/+/g,`/`);if(o.includes(`/../`)||o.includes(`/..`)||!o.startsWith(a+`/`))continue;let l=i.substring(0,i.lastIndexOf(`/`));l!==a&&await r.mkdir(l,{recursive:!0}),await r.writeFile(i,t),c++}}catch(e){throw await r.rm(a,{recursive:!0}).catch(()=>{}),e}return c===0?(await r.rm(a,{recursive:!0}).catch(()=>{}),{ok:!1,error:`no files found for skill "${t}" in ZIP`}):{ok:!0}}async function r3(){try{let e=(typeof window<`u`?window:globalThis).__slicc_reloadSkills;if(typeof e==`function`){await e();return}typeof chrome<`u`&&chrome?.runtime?.sendMessage&&chrome.runtime.sendMessage({source:`panel`,payload:{type:`reload-skills`}})}catch{}}function i3(e){let t=e.match(/^([a-zA-Z0-9_-]+)\/([a-zA-Z0-9_.-]+)(?:@([a-zA-Z0-9_./\-]+))?$/);return t?{owner:t[1],repo:t[2],branch:t[3]}:null}async function a3(){try{if(typeof window>`u`)return;let e=window.__slicc_sprinkleManager;e&&typeof e.openNewAutoOpenSprinkles==`function`&&await e.openNewAutoOpenSprinkles()}catch{}}async function o3(e,t,n){let r=null;try{let t=await e.readDir(`/home`);for(let n of t)try{let t=await e.readTextFile(`/home/${n.name}/.welcome.json`);r=JSON.parse(t);break}catch{}}catch{}if(!r)return{stdout:``,stderr:`upskill: no user profile found. Complete the welcome onboarding first, or create /home/<name>/.welcome.json manually.
4347
- `,exitCode:1};let i,a;try{let[n,r]=await Promise.all([(async()=>{let e=await t(g4,{headers:{Accept:`application/json`}});if(e.status!==200)throw Error(`HTTP ${e.status}`);return v4(NW(e.body).data)})(),S4(e)]);i=n,a=r}catch(e){return{stdout:``,stderr:`upskill: failed to fetch skill catalog from ${g4}: ${e instanceof Error?e.message:String(e)}\n`,exitCode:1}}let o=b4(i,r).filter(e=>!a.has(e.entry.name));if(o.length===0)return{stdout:`No new skill recommendations — all matching skills are already installed.
4348
- `,stderr:``,exitCode:0};if(n){let n=new Map;for(let e of o){let t=e.entry.source.repo,r=n.get(t);r?r.push(e):n.set(t,[e])}let r=o.length,i=0,a=Date.now(),s=``,c=``,l=0,u=await Promise.allSettled(Array.from(n.entries()).map(async([n,o])=>{let[c,l]=n.split(`/`),u=await X4(c,l,t);if(u.status===`not_found`||u.status===`error`){let e=u.status===`not_found`?`upskill: repository ${n} not found\n`:`upskill: failed to fetch ${n}: ${u.message}\n`,t=[];for(let e of o){i++,((Date.now()-a)/1e3).toFixed(1);let o=i<r?` (~${Math.round((r-i)*(Date.now()-a)/i/1e3)}s remaining)`:``;s+=`[${i}/${r}] Failed "${e.entry.name}" from ${n}: repo fetch failed${o}\n`,t.push({ok:!1,name:e.entry.name,error:`repo fetch failed for ${n}`})}return{errors:e,results:t}}let d=Z4(u.files),f=[],p=new Map;for(let e of Object.keys(d))if(e.endsWith(`/SKILL.md`)){let t=e.replace(/\/SKILL\.md$/,``),n=t.split(`/`).pop()||t;p.set(n,t)}for(let t of o){let o=t.entry.source,c,l;if(o.skill){let e=p.get(o.skill);if(e)c=e,l=o.skill;else if(o.path)c=o.path.replace(/^\/|\/$/g,``),l=o.skill;else{let e=`skill "${o.skill}" not found in ${n}`;f.push({ok:!1,name:t.entry.name,error:e}),i++;let c=i<r?` (~${Math.round((r-i)*(Date.now()-a)/i/1e3)}s remaining)`:``;s+=`[${i}/${r}] Failed "${t.entry.name}" from ${n}: ${e}${c}\n`;continue}}else if(o.path)c=o.path.replace(/^\/|\/$/g,``),l=t.entry.name;else{let e=p.get(t.entry.name);if(e)c=e,l=t.entry.name;else{let e=`skill "${t.entry.name}" not found in ${n} and no explicit path provided`;f.push({ok:!1,name:t.entry.name,error:e}),i++;let o=i<r?` (~${Math.round((r-i)*(Date.now()-a)/i/1e3)}s remaining)`:``;s+=`[${i}/${r}] Failed "${t.entry.name}" from ${n}: ${e}${o}\n`;continue}}let u=Date.now(),m=await n3(c,l,d,e,!1);i++;let h=((Date.now()-u)/1e3).toFixed(1),g=(Date.now()-a)/i,_=Math.round((r-i)*g/1e3),v=i<r?` (~${_}s remaining)`:``;m.ok?(f.push({ok:!0,name:l}),s+=`[${i}/${r}] Installed "${l}" from ${n} (${h}s)${v}\n`):(f.push({ok:!1,name:l,error:m.error}),s+=`[${i}/${r}] Failed "${l}" from ${n}: ${m.error}${v}\n`)}return{errors:``,results:f}}));for(let e of u){if(e.status===`rejected`){c+=`upskill: unexpected error: ${e.reason}\n`;continue}e.value.errors&&(c+=e.value.errors);for(let t of e.value.results)t.ok?l++:t.error&&(c+=`upskill: ${t.error}\n`)}let d=((Date.now()-a)/1e3).toFixed(1);return l>0&&(s+=`\nInstalled ${l} recommended skill(s) in ${d}s\n`,await t3()),{stdout:s,stderr:c,exitCode:+!!c}}let s=`Recommended skills for you:
4346
+ `),{stdout:h,stderr:``,exitCode:0}}async function Y4(e,t,n,r=!1,i){try{let a=`${h4}/${e}`;try{if(await t.stat(a),!r)return{stdout:``,stderr:`upskill: skill "${e}" already exists (use --force to overwrite)\n`,exitCode:1};await t.rm(a,{recursive:!0})}catch{}let o=`${p4}/download?slug=${encodeURIComponent(e)}`,s=await n(o,{});if(s.status===404)return{stdout:``,stderr:`upskill: skill "${e}" not found on ClawHub\n`,exitCode:1};if(s.status!==200)return{stdout:``,stderr:`upskill: failed to download skill (HTTP ${s.status})\n`,exitCode:1};let c=s.headers[`content-type`]||``,l=OW(o);l||=PW(s.body);let u;try{u=D(l)}catch(e){let t=e instanceof Error?e.message:String(e),n=Array.from(l.slice(0,20)).map(e=>e.toString(16).padStart(2,`0`)).join(` `);return{stdout:``,stderr:`upskill: failed to unzip: ${t}\nContent-Type: ${c}\nBody: ${l.length} bytes\nHex: ${n}\n`,exitCode:1}}await t.mkdir(a,{recursive:!0});let d=0;for(let[e,n]of Object.entries(u)){let r=e.replace(/\\/g,`/`);if(!r||r.endsWith(`/`)||r===`_meta.json`)continue;let i=`${a}/${r}`,o=i.substring(0,i.lastIndexOf(`/`));o!==a&&await t.mkdir(o,{recursive:!0}),await t.writeFile(i,n),d++}let f=X4(u,i);return await i3(),{stdout:`Installed skill "${e}" from ClawHub (${d} files)\n${f}`,stderr:``,exitCode:0}}catch(e){return{stdout:``,stderr:`upskill: failed to install from ClawHub: ${e instanceof Error?e.message:String(e)}\n`,exitCode:1}}}function X4(e,t){let n;for(let[t,r]of Object.entries(e))if((t.split(`/`).pop()||``).toLowerCase()===`skill.md`){n=new TextDecoder().decode(r);break}if(!n)return``;let r=n.match(/^---\s*\n([\s\S]*?)\n---/);if(!r)return``;let i=r[1],a=Z4(i);if(a.length===0)return``;if(!t||t.length===0)return` Requires: ${a.join(`, `)}\n`;let o=new Set(t),s=a.filter(e=>!o.has(e));return s.length===0?` Requires: ${a.join(`, `)} (all available)\n`:` Requires: ${a.join(`, `)}\n Missing: ${s.join(`, `)} -- this skill may not work in the SLICC shell\n`}function Z4(e){let t=e.match(/metadata:\s*\n\s*(\{[\s\S]*\})/);if(t)try{let e=JSON.parse(t[1]);for(let t of[`openclaw`,`clawdis`,`clawdbot`]){let n=e[t];if(n?.requires&&typeof n.requires==`object`){let e=n.requires;if(Array.isArray(e.bins))return e.bins.filter(e=>typeof e==`string`)}}}catch{}let n=e.match(/"bins"\s*:\s*\[([^\]]*)\]/);return n?n[1].split(`,`).map(e=>e.trim().replace(/^["']|["']$/g,``)).filter(Boolean):[]}async function Q4(e,t){let n=await t(`${m4}/experimental/search?q=${encodeURIComponent(e)}&contentType=skills&page%5Bsize%5D=5`,{headers:{Accept:`application/json`}});if(n.status!==200)return{error:`Tessl search failed (HTTP ${n.status})`};let r=NW(n.body).data?.find(t=>t.type===`skill`&&t.attributes.name===e);if(!r)return{error:`skill "${e}" not found on Tessl registry`};let i=G4(r.attributes.sourceUrl);if(!i)return{error:`skill "${e}" has no GitHub source URL`};let a=r.attributes.path.replace(/\/SKILL\.md$/i,``);return{owner:i.owner,repo:i.repo,skillPath:a,skillName:e}}async function $4(e,t,n,r=`main`){let i=`https://codeload.github.com/${e}/${t}/zip/refs/heads/${r}`,a=await n(i,{headers:{"User-Agent":`slicc-upskill`}});if(a.status===404)return r===`main`?$4(e,t,n,`master`):{status:`not_found`};if(a.status!==200)return{status:`error`,message:`codeload returned HTTP ${a.status}`};let o=OW(i);o||=PW(a.body);try{return{status:`ok`,files:D(o)}}catch(e){return{status:`error`,message:`failed to unzip: ${e instanceof Error?e.message:String(e)}`}}}function e3(e){let t={};for(let[n,r]of Object.entries(e)){let e=n.indexOf(`/`);if(e<0)continue;let i=n.slice(e+1);i&&(t[i]=r)}return t}async function t3(e,t,n,r,i,a){if(i){let n=await $4(e,t,i,a);if(n.status===`ok`){let e=e3(n.files),t=[],i=r?r.replace(/^\/|\/$/g,``)+`/`:``;for(let n of Object.keys(e))if(n.startsWith(i)&&(n.split(`/`).pop()||``)===`SKILL.md`){let e=n.replace(/\/SKILL\.md$/,``),r=e.split(`/`).pop()||e;t.push({name:r,path:e})}return{skills:t}}if(n.status===`not_found`)return{skills:[],error:`${a?`branch "${a}" in ${e}/${t}`:`repository ${e}/${t}`} not found`}}let o=[];async function s(r){let i=`https://api.github.com/repos/${e}/${t}/contents/${r}`,c=a?`${i}?ref=${encodeURIComponent(a)}`:i,l=await n.request(c);if(l.status!==200)throw Error(N4(l,`${e}/${t}${r?`/${r}`:``}`,n.hasToken));let u=NW(l.body);for(let e of u)if(e.type===`file`&&e.name===`SKILL.md`){let t=e.path.replace(`/SKILL.md`,``),n=t.split(`/`).pop()||t;o.push({name:n,path:t})}else e.type===`dir`&&await s(e.path)}try{return await s(r||``),{skills:o}}catch(e){return{skills:[],error:e instanceof Error?e.message:String(e)}}}async function n3(e,t,n,r,i,a,o=!1,s,c){try{let l=`${h4}/${r}`;try{if(await i.stat(l),!o)return{stdout:``,stderr:`upskill: skill "${r}" already exists (use --force to overwrite)\n`,exitCode:1};await i.rm(l,{recursive:!0})}catch{}if(s){let a=await $4(e,t,s,c);if(a.status===`not_found`)return{stdout:``,stderr:`upskill: ${c?`branch "${c}" in ${e}/${t}`:`repository ${e}/${t}`} not found\n`,exitCode:1};if(a.status===`ok`){let o=e3(a.files),s=n.replace(/^\/|\/$/g,``)+`/`;await i.mkdir(l,{recursive:!0});let c=0;for(let[e,t]of Object.entries(o)){if(!e.startsWith(s))continue;let n=e.slice(s.length);if(!n||e.endsWith(`/`))continue;let r=`${l}/${n}`,a=r.substring(0,r.lastIndexOf(`/`));a!==l&&await i.mkdir(a,{recursive:!0}),await i.writeFile(r,t),c++}if(c>0)return await c3(),await o3(),{stdout:`Installed skill "${r}" from ${e}/${t}\n`,stderr:``,exitCode:0}}}let u=`https://api.github.com/repos/${e}/${t}/contents/${n}`,d=c?`${u}?ref=${encodeURIComponent(c)}`:u,f=await a.request(d);if(f.status!==200)return{stdout:``,stderr:`upskill: ${N4(f,`${e}/${t}/${n}`,a.hasToken)}\n`,exitCode:1};let p=NW(f.body);await i.mkdir(l,{recursive:!0});async function m(n,r){for(let o of n)if(o.type===`file`&&o.download_url){let n=await a.request(o.download_url,`*/*`);if(n.status!==200)throw Error(N4(n,`${e}/${t}/${o.path}`,a.hasToken));let s=OW(o.download_url);await i.writeFile(`${r}/${o.name}`,s??n.body)}else if(o.type===`dir`){let n=`https://api.github.com/repos/${e}/${t}/contents/${o.path}`,s=c?`${n}?ref=${encodeURIComponent(c)}`:n,l=await a.request(s);if(l.status!==200)throw Error(N4(l,`${e}/${t}/${o.path}`,a.hasToken));let u=NW(l.body);await i.mkdir(`${r}/${o.name}`,{recursive:!0}),await m(u,`${r}/${o.name}`)}}try{await m(p,l)}catch(e){try{await i.rm(l,{recursive:!0})}catch{}throw e}return await i3(),{stdout:`Installed skill "${r}" from ${e}/${t}\n`,stderr:``,exitCode:0}}catch(e){return{stdout:``,stderr:`upskill: failed to install from GitHub: ${e instanceof Error?e.message:String(e)}\n`,exitCode:1}}}function r3(e){let t=e.match(/^https?:\/\/clawhub\.ai\/[^\/]+\/([^\/]+)/);if(t)return t[1];if(e.startsWith(`clawhub:`)){let t=e.slice(8);return t.includes(`/`)?t.split(`/`)[1]:t}return null}async function i3(){await c3(),await o3()}async function a3(e,t,n,r,i=!1){let a=`${h4}/${t}`;try{if(await r.stat(a),!i)return{ok:!1,error:`skill "${t}" already exists (use --force to overwrite)`};await r.rm(a,{recursive:!0})}catch{}let o=e.replace(/^\/|\/$/g,``),s=o?o+`/`:``;await r.mkdir(a,{recursive:!0});let c=0;try{for(let[e,t]of Object.entries(n)){if(!e.startsWith(s))continue;let n=e.slice(s.length);if(!n||e.endsWith(`/`))continue;let i=`${a}/${n}`,o=i.replace(/\/+/g,`/`);if(o.includes(`/../`)||o.includes(`/..`)||!o.startsWith(a+`/`))continue;let l=i.substring(0,i.lastIndexOf(`/`));l!==a&&await r.mkdir(l,{recursive:!0}),await r.writeFile(i,t),c++}}catch(e){throw await r.rm(a,{recursive:!0}).catch(()=>{}),e}return c===0?(await r.rm(a,{recursive:!0}).catch(()=>{}),{ok:!1,error:`no files found for skill "${t}" in ZIP`}):{ok:!0}}async function o3(){try{let e=(typeof window<`u`?window:globalThis).__slicc_reloadSkills;if(typeof e==`function`){await e();return}typeof chrome<`u`&&chrome?.runtime?.sendMessage&&chrome.runtime.sendMessage({source:`panel`,payload:{type:`reload-skills`}})}catch{}}function s3(e){let t=e.match(/^([a-zA-Z0-9_-]+)\/([a-zA-Z0-9_.-]+)(?:@([a-zA-Z0-9_./\-]+))?$/);return t?{owner:t[1],repo:t[2],branch:t[3]}:null}async function c3(){try{if(typeof window>`u`)return;let e=window.__slicc_sprinkleManager;e&&typeof e.openNewAutoOpenSprinkles==`function`&&await e.openNewAutoOpenSprinkles()}catch{}}async function l3(e,t,n){let r=null;try{let t=await e.readDir(`/home`);for(let n of t)try{let t=await e.readTextFile(`/home/${n.name}/.welcome.json`);r=JSON.parse(t);break}catch{}}catch{}if(!r)return{stdout:``,stderr:`upskill: no user profile found. Complete the welcome onboarding first, or create /home/<name>/.welcome.json manually.
4347
+ `,exitCode:1};let i,a;try{let[n,r]=await Promise.all([(async()=>{let e=await t(y4,{headers:{Accept:`application/json`}});if(e.status!==200)throw Error(`HTTP ${e.status}`);return x4(NW(e.body).data)})(),T4(e)]);i=n,a=r}catch(e){return{stdout:``,stderr:`upskill: failed to fetch skill catalog from ${y4}: ${e instanceof Error?e.message:String(e)}\n`,exitCode:1}}let o=C4(i,r).filter(e=>!a.has(e.entry.name));if(o.length===0)return{stdout:`No new skill recommendations — all matching skills are already installed.
4348
+ `,stderr:``,exitCode:0};if(n){let n=new Map;for(let e of o){let t=e.entry.source.repo,r=n.get(t);r?r.push(e):n.set(t,[e])}let r=o.length,i=0,a=Date.now(),s=``,c=``,l=0,u=await Promise.allSettled(Array.from(n.entries()).map(async([n,o])=>{let[c,l]=n.split(`/`),u=await $4(c,l,t);if(u.status===`not_found`||u.status===`error`){let e=u.status===`not_found`?`upskill: repository ${n} not found\n`:`upskill: failed to fetch ${n}: ${u.message}\n`,t=[];for(let e of o){i++,((Date.now()-a)/1e3).toFixed(1);let o=i<r?` (~${Math.round((r-i)*(Date.now()-a)/i/1e3)}s remaining)`:``;s+=`[${i}/${r}] Failed "${e.entry.name}" from ${n}: repo fetch failed${o}\n`,t.push({ok:!1,name:e.entry.name,error:`repo fetch failed for ${n}`})}return{errors:e,results:t}}let d=e3(u.files),f=[],p=new Map;for(let e of Object.keys(d))if(e.endsWith(`/SKILL.md`)){let t=e.replace(/\/SKILL\.md$/,``),n=t.split(`/`).pop()||t;p.set(n,t)}for(let t of o){let o=t.entry.source,c,l;if(o.skill){let e=p.get(o.skill);if(e)c=e,l=o.skill;else if(o.path)c=o.path.replace(/^\/|\/$/g,``),l=o.skill;else{let e=`skill "${o.skill}" not found in ${n}`;f.push({ok:!1,name:t.entry.name,error:e}),i++;let c=i<r?` (~${Math.round((r-i)*(Date.now()-a)/i/1e3)}s remaining)`:``;s+=`[${i}/${r}] Failed "${t.entry.name}" from ${n}: ${e}${c}\n`;continue}}else if(o.path)c=o.path.replace(/^\/|\/$/g,``),l=t.entry.name;else{let e=p.get(t.entry.name);if(e)c=e,l=t.entry.name;else{let e=`skill "${t.entry.name}" not found in ${n} and no explicit path provided`;f.push({ok:!1,name:t.entry.name,error:e}),i++;let o=i<r?` (~${Math.round((r-i)*(Date.now()-a)/i/1e3)}s remaining)`:``;s+=`[${i}/${r}] Failed "${t.entry.name}" from ${n}: ${e}${o}\n`;continue}}let u=Date.now(),m=await a3(c,l,d,e,!1);i++;let h=((Date.now()-u)/1e3).toFixed(1),g=(Date.now()-a)/i,_=Math.round((r-i)*g/1e3),v=i<r?` (~${_}s remaining)`:``;m.ok?(f.push({ok:!0,name:l}),s+=`[${i}/${r}] Installed "${l}" from ${n} (${h}s)${v}\n`):(f.push({ok:!1,name:l,error:m.error}),s+=`[${i}/${r}] Failed "${l}" from ${n}: ${m.error}${v}\n`)}return{errors:``,results:f}}));for(let e of u){if(e.status===`rejected`){c+=`upskill: unexpected error: ${e.reason}\n`;continue}e.value.errors&&(c+=e.value.errors);for(let t of e.value.results)t.ok?l++:t.error&&(c+=`upskill: ${t.error}\n`)}let d=((Date.now()-a)/1e3).toFixed(1);return l>0&&(s+=`\nInstalled ${l} recommended skill(s) in ${d}s\n`,await i3()),{stdout:s,stderr:c,exitCode:+!!c}}let s=`Recommended skills for you:
4349
4349
 
4350
- `,c=0;for(let e of o){c++;let t=x4(e.entry.source);s+=` ${c}. ${e.entry.displayName.padEnd(35)} score: ${Math.round(e.score)}\n`,s+=` ${e.entry.description}\n`,s+=` Match: ${e.matchReasons.join(`, `)}\n`,s+=` Install: ${t}\n\n`}return s+=`To install all recommended: upskill recommendations --install
4351
- `,{stdout:s,stderr:``,exitCode:0}}function s3(e,t){return gR(`upskill`,async(n,r)=>{if(n.length===0||n.includes(`--help`)||n.includes(`-h`))return B4();let i=[],a,o=!1,c=!1,l=!1,u=``,d,f=``,p=1,m=0;for(;m<n.length;){let r=n[m];if(r===`search`){let e=n.slice(m+1),t=e.indexOf(`--page`);t>=0&&(p=parseInt(e[t+1],10)||1,e.splice(t,2)),f=e.join(` `);break}else if(r===`recommendations`)return o3(e,t,n.includes(`--install`));else if(r===`list`){let t=await(await s(()=>import(`./skills-5aRDmjxF.js`).then(e=>e.t),__vite__mapDeps([14,4,15,16]))).discoverSkills(e);return t.length===0?{stdout:`No discoverable local skills found.\n\n${j4()}${M4()}`,stderr:``,exitCode:0}:{stdout:L4(t,`Discoverable local skills`),stderr:``,exitCode:0}}else if(r===`info`||r===`read`){let t=n[m+1];if(!t)return{stdout:``,stderr:`upskill: ${r} requires a skill name\n`,exitCode:1};let i=await s(()=>import(`./skills-5aRDmjxF.js`).then(e=>e.t),__vite__mapDeps([14,4,15,16]));if(r===`info`){let n=await i.getSkillInfo(e,t);return n?{stdout:R4(n),stderr:``,exitCode:0}:{stdout:``,stderr:`upskill: skill "${t}" not found\n`,exitCode:1}}else{let n=await i.readSkillInstructions(e,t);return n===null?{stdout:``,stderr:`upskill: no SKILL.md found for "${t}"\n`,exitCode:1}:{stdout:n+`
4350
+ `,c=0;for(let e of o){c++;let t=w4(e.entry.source);s+=` ${c}. ${e.entry.displayName.padEnd(35)} score: ${Math.round(e.score)}\n`,s+=` ${e.entry.description}\n`,s+=` Match: ${e.matchReasons.join(`, `)}\n`,s+=` Install: ${t}\n\n`}return s+=`To install all recommended: upskill recommendations --install
4351
+ `,{stdout:s,stderr:``,exitCode:0}}function u3(e,t){return gR(`upskill`,async(n,r)=>{if(n.length===0||n.includes(`--help`)||n.includes(`-h`))return U4();let i=[],a,o=!1,c=!1,l=!1,u=``,d,f=``,p=1,m=0;for(;m<n.length;){let r=n[m];if(r===`search`){let e=n.slice(m+1),t=e.indexOf(`--page`);t>=0&&(p=parseInt(e[t+1],10)||1,e.splice(t,2)),f=e.join(` `);break}else if(r===`recommendations`)return l3(e,t,n.includes(`--install`));else if(r===`list`){let t=await(await s(()=>import(`./skills-Cwc_5caT.js`).then(e=>e.t),__vite__mapDeps([14,4,15,16]))).discoverSkills(e);return t.length===0?{stdout:`No discoverable local skills found.\n\n${P4()}${F4()}`,stderr:``,exitCode:0}:{stdout:B4(t,`Discoverable local skills`),stderr:``,exitCode:0}}else if(r===`info`||r===`read`){let t=n[m+1];if(!t)return{stdout:``,stderr:`upskill: ${r} requires a skill name\n`,exitCode:1};let i=await s(()=>import(`./skills-Cwc_5caT.js`).then(e=>e.t),__vite__mapDeps([14,4,15,16]));if(r===`info`){let n=await i.getSkillInfo(e,t);return n?{stdout:V4(n),stderr:``,exitCode:0}:{stdout:``,stderr:`upskill: skill "${t}" not found\n`,exitCode:1}}else{let n=await i.readSkillInstructions(e,t);return n===null?{stdout:``,stderr:`upskill: no SKILL.md found for "${t}"\n`,exitCode:1}:{stdout:n+`
4352
4352
  `,stderr:``,exitCode:0}}}else if(r===`--skill`)i.push(n[++m]);else if(r===`--path`||r===`-p`)a=n[++m];else if(r===`--list`)o=!0;else if(r===`--all`)c=!0;else if(r===`--force`)l=!0;else if(r===`--branch`||r===`-b`){let e=n[m+1];if(!e||e.startsWith(`-`))return{stdout:``,stderr:`upskill: --branch requires a value
4353
- `,exitCode:1};d=n[++m]}else r.startsWith(`-`)||(u=r);m++}if(f)return G4(f,t,p);if(!u)return B4();let h=e3(u);if(h){let n=r.getRegisteredCommands?.()??[];return K4(h,e,t,l,n)}if(u.startsWith(`tessl:`)){let n=u.slice(6);if(!n)return{stdout:``,stderr:`upskill: tessl: requires a skill name
4354
- `,exitCode:1};let r=await Y4(n,t);if(`error`in r)return{stdout:``,stderr:`upskill: ${r.error}\n`,exitCode:1};let i=await D4(t);return $4(r.owner,r.repo,r.skillPath,r.skillName,e,i,l,t)}let g=i3(u);if(g){let{owner:n,repo:r}=g,s=d??g.branch,f=await D4(t),p=await Q4(n,r,f,a,t,s);if(p.error)return{stdout:``,stderr:`upskill: failed to list skills: ${p.error}\n`,exitCode:1};if(p.skills.length===0)return{stdout:`No skills found in ${n}/${r}${a?`/`+a:``}\n`,stderr:``,exitCode:0};if(o){let e=`Available skills in ${n}/${r}:\n\n`;for(let t of p.skills)e+=` ${t.name.padEnd(30)} ${t.path}\n`;return e+=`\nFound ${p.skills.length} skill(s)\n`,e+=`\nTo install: upskill ${u} --skill <name>\n`,e+=`To install all: upskill ${u} --all\n`,{stdout:e,stderr:``,exitCode:0}}let m=p.skills;if(i.length>0){m=p.skills.filter(e=>i.includes(e.name));for(let e of i)if(!p.skills.find(t=>t.name===e))return{stdout:``,stderr:`upskill: skill "${e}" not found in ${n}/${r}\n`,exitCode:1}}else if(!c){let e=`Available skills in ${n}/${r}:\n\n`;for(let t of p.skills)e+=` ${t.name.padEnd(30)} ${t.path}\n`;return e+=`\nFound ${p.skills.length} skill(s)\n`,e+=`\nTo install specific skills: upskill ${u} --skill <name>\n`,e+=`To install all: upskill ${u} --all\n`,{stdout:e,stderr:``,exitCode:0}}let h=``,_=``,v=0,y=m.length,b=Date.now();if(y>1){let i=await X4(n,r,t,s);if(i.status===`not_found`)return{stdout:``,stderr:`upskill: ${s?`branch "${s}" in ${n}/${r}`:`repository ${n}/${r}`} not found\n`,exitCode:1};if(i.status===`error`)return{stdout:``,stderr:`upskill: failed to fetch ${n}/${r}: ${i.message}\n`,exitCode:1};let a=Z4(i.files);for(let t=0;t<m.length;t++){let i=m[t],o=await n3(i.path,i.name,a,e,l),s=t+1,c=((Date.now()-b)/1e3).toFixed(1),u=(Date.now()-b)/s,d=Math.round((y-s)*u/1e3),f=s<y?` (~${d}s remaining)`:``;o.ok?(h+=`[${s}/${y}] Installed "${i.name}" from ${n}/${r} (${c}s)${f}\n`,v++):(h+=`[${s}/${y}] Failed "${i.name}": ${o.error}${f}\n`,_+=`upskill: ${o.error}\n`)}}else for(let i of m){let a=await $4(n,r,i.path,i.name,e,f,l,t,s);a.exitCode===0?(h+=a.stdout,v++):_+=a.stderr}let x=((Date.now()-b)/1e3).toFixed(1);return v>0&&(h+=`\nInstalled ${v} skill(s)${y>1?` in ${x}s`:``}\n`,await t3()),{stdout:h,stderr:_,exitCode:+!!_}}return{stdout:``,stderr:`upskill: unrecognized source "${u}"\n\nExpected: owner/repo, clawhub:<slug>, tessl:<name>, or https://clawhub.ai/user/skill\n`,exitCode:1}})}function c3(e){return gR(`skill`,async(t,n)=>{if(t.length===0||t.includes(`--help`)||t.includes(`-h`))return{stdout:`usage: skill <command> [options]
4353
+ `,exitCode:1};d=n[++m]}else r.startsWith(`-`)||(u=r);m++}if(f)return J4(f,t,p);if(!u)return U4();let h=r3(u);if(h){let n=r.getRegisteredCommands?.()??[];return Y4(h,e,t,l,n)}if(u.startsWith(`tessl:`)){let n=u.slice(6);if(!n)return{stdout:``,stderr:`upskill: tessl: requires a skill name
4354
+ `,exitCode:1};let r=await Q4(n,t);if(`error`in r)return{stdout:``,stderr:`upskill: ${r.error}\n`,exitCode:1};let i=await A4(t);return n3(r.owner,r.repo,r.skillPath,r.skillName,e,i,l,t)}let g=s3(u);if(g){let{owner:n,repo:r}=g,s=d??g.branch,f=await A4(t),p=await t3(n,r,f,a,t,s);if(p.error)return{stdout:``,stderr:`upskill: failed to list skills: ${p.error}\n`,exitCode:1};if(p.skills.length===0)return{stdout:`No skills found in ${n}/${r}${a?`/`+a:``}\n`,stderr:``,exitCode:0};if(o){let e=`Available skills in ${n}/${r}:\n\n`;for(let t of p.skills)e+=` ${t.name.padEnd(30)} ${t.path}\n`;return e+=`\nFound ${p.skills.length} skill(s)\n`,e+=`\nTo install: upskill ${u} --skill <name>\n`,e+=`To install all: upskill ${u} --all\n`,{stdout:e,stderr:``,exitCode:0}}let m=p.skills;if(i.length>0){m=p.skills.filter(e=>i.includes(e.name));for(let e of i)if(!p.skills.find(t=>t.name===e))return{stdout:``,stderr:`upskill: skill "${e}" not found in ${n}/${r}\n`,exitCode:1}}else if(!c){let e=`Available skills in ${n}/${r}:\n\n`;for(let t of p.skills)e+=` ${t.name.padEnd(30)} ${t.path}\n`;return e+=`\nFound ${p.skills.length} skill(s)\n`,e+=`\nTo install specific skills: upskill ${u} --skill <name>\n`,e+=`To install all: upskill ${u} --all\n`,{stdout:e,stderr:``,exitCode:0}}let h=``,_=``,v=0,y=m.length,b=Date.now();if(y>1){let i=await $4(n,r,t,s);if(i.status===`not_found`)return{stdout:``,stderr:`upskill: ${s?`branch "${s}" in ${n}/${r}`:`repository ${n}/${r}`} not found\n`,exitCode:1};if(i.status===`error`)return{stdout:``,stderr:`upskill: failed to fetch ${n}/${r}: ${i.message}\n`,exitCode:1};let a=e3(i.files);for(let t=0;t<m.length;t++){let i=m[t],o=await a3(i.path,i.name,a,e,l),s=t+1,c=((Date.now()-b)/1e3).toFixed(1),u=(Date.now()-b)/s,d=Math.round((y-s)*u/1e3),f=s<y?` (~${d}s remaining)`:``;o.ok?(h+=`[${s}/${y}] Installed "${i.name}" from ${n}/${r} (${c}s)${f}\n`,v++):(h+=`[${s}/${y}] Failed "${i.name}": ${o.error}${f}\n`,_+=`upskill: ${o.error}\n`)}}else for(let i of m){let a=await n3(n,r,i.path,i.name,e,f,l,t,s);a.exitCode===0?(h+=a.stdout,v++):_+=a.stderr}let x=((Date.now()-b)/1e3).toFixed(1);return v>0&&(h+=`\nInstalled ${v} skill(s)${y>1?` in ${x}s`:``}\n`,await i3()),{stdout:h,stderr:_,exitCode:+!!_}}return{stdout:``,stderr:`upskill: unrecognized source "${u}"\n\nExpected: owner/repo, clawhub:<slug>, tessl:<name>, or https://clawhub.ai/user/skill\n`,exitCode:1}})}function d3(e){return gR(`skill`,async(t,n)=>{if(t.length===0||t.includes(`--help`)||t.includes(`-h`))return{stdout:`usage: skill <command> [options]
4355
4355
 
4356
4356
  Commands:
4357
4357
  list List discoverable skills and management status
@@ -4360,7 +4360,7 @@ Commands:
4360
4360
  install <name> Install a native /workspace/skills skill (apply manifest)
4361
4361
  uninstall <name> Uninstall a native /workspace/skills skill
4362
4362
 
4363
- ${j4()}${M4()}
4363
+ ${P4()}${F4()}
4364
4364
 
4365
4365
  For installing skills from registries or GitHub, use 'upskill':
4366
4366
  upskill search "query" Search ClawHub + Tessl
@@ -4372,27 +4372,27 @@ Examples:
4372
4372
  skill list
4373
4373
  skill info bluebubbles
4374
4374
  skill read bluebubbles
4375
- `,stderr:``,exitCode:0};let r=t[0],i=await s(()=>import(`./skills-5aRDmjxF.js`).then(e=>e.t),__vite__mapDeps([14,4,15,16]));try{switch(r){case`list`:{let t=await i.discoverSkills(e);return t.length===0?{stdout:`No discoverable skills found.\n\n${j4()}${M4()}\nInstall install-managed skills with: upskill owner/repo --all\n`,stderr:``,exitCode:0}:{stdout:L4(t,`Discoverable skills`),stderr:``,exitCode:0}}case`info`:{let n=t[1];if(!n)return{stdout:``,stderr:`skill: info requires a skill name
4376
- `,exitCode:1};let r=await i.getSkillInfo(e,n);return r?{stdout:R4(r),stderr:``,exitCode:0}:{stdout:``,stderr:`skill: "${n}" not found\n`,exitCode:1}}case`read`:{let n=t[1];if(!n)return{stdout:``,stderr:`skill: read requires a skill name
4375
+ `,stderr:``,exitCode:0};let r=t[0],i=await s(()=>import(`./skills-Cwc_5caT.js`).then(e=>e.t),__vite__mapDeps([14,4,15,16]));try{switch(r){case`list`:{let t=await i.discoverSkills(e);return t.length===0?{stdout:`No discoverable skills found.\n\n${P4()}${F4()}\nInstall install-managed skills with: upskill owner/repo --all\n`,stderr:``,exitCode:0}:{stdout:B4(t,`Discoverable skills`),stderr:``,exitCode:0}}case`info`:{let n=t[1];if(!n)return{stdout:``,stderr:`skill: info requires a skill name
4376
+ `,exitCode:1};let r=await i.getSkillInfo(e,n);return r?{stdout:V4(r),stderr:``,exitCode:0}:{stdout:``,stderr:`skill: "${n}" not found\n`,exitCode:1}}case`read`:{let n=t[1];if(!n)return{stdout:``,stderr:`skill: read requires a skill name
4377
4377
  `,exitCode:1};let r=await i.readSkillInstructions(e,n);return r===null?{stdout:``,stderr:`skill: no SKILL.md found for "${n}"\n`,exitCode:1}:{stdout:r+`
4378
4378
  `,stderr:``,exitCode:0}}case`install`:{let n=t[1];if(!n)return{stdout:``,stderr:`skill: install requires a skill name
4379
- `,exitCode:1};let r=await i.getSkillInfo(e,n);if(r&&!P4(r))return{stdout:``,stderr:z4(`skill`,r),exitCode:1};let a=await i.applySkill(e,n);return a.success?(await a3(),await r3(),{stdout:`Installed skill "${a.skill}" v${a.version}\n`,stderr:``,exitCode:0}):{stdout:``,stderr:`skill: ${a.error}\n`,exitCode:1}}case`uninstall`:{let n=t[1];if(!n)return{stdout:``,stderr:`skill: uninstall requires a skill name
4380
- `,exitCode:1};let r=await i.getSkillInfo(e,n);if(r&&!P4(r))return{stdout:``,stderr:`skill: "${n}" is a compatibility skill discovered from ${r.sourceRoot} (read-only). Only native /workspace/skills entries can be uninstalled.\n`,exitCode:1};let a=await i.uninstallSkill(e,n);return a.success?{stdout:`Uninstalled skill "${a.skill}"\n`,stderr:``,exitCode:0}:{stdout:``,stderr:`skill: ${a.error}\n`,exitCode:1}}default:return{stdout:``,stderr:`skill: unknown command "${r}"\n`,exitCode:1}}}catch(e){return{stdout:``,stderr:`skill: ${e instanceof Error?e.message:String(e)}\n`,exitCode:1}}})}function l3(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&#39;`)}var u3=class{constructor(e){this.options=e}async execute(e,t){let n=e[0];if(n===`--help`||n===`-h`)return this.help();if(n===`unmount`||n===`-u`){let n=e[1];if(!n)return{stdout:``,stderr:`mount unmount: path required`,exitCode:1};let r=n.startsWith(`/`)?n:`${t.replace(/\/$/,``)}/${n}`;return this.options.fs.unmount(r),{stdout:`Unmounted ${r}\n`,stderr:``,exitCode:0}}if(n===`list`||n===`-l`){let e=this.options.fs.listMounts();if(e.length===0)return{stdout:`No active mounts
4379
+ `,exitCode:1};let r=await i.getSkillInfo(e,n);if(r&&!L4(r))return{stdout:``,stderr:H4(`skill`,r),exitCode:1};let a=await i.applySkill(e,n);return a.success?(await c3(),await o3(),{stdout:`Installed skill "${a.skill}" v${a.version}\n`,stderr:``,exitCode:0}):{stdout:``,stderr:`skill: ${a.error}\n`,exitCode:1}}case`uninstall`:{let n=t[1];if(!n)return{stdout:``,stderr:`skill: uninstall requires a skill name
4380
+ `,exitCode:1};let r=await i.getSkillInfo(e,n);if(r&&!L4(r))return{stdout:``,stderr:`skill: "${n}" is a compatibility skill discovered from ${r.sourceRoot} (read-only). Only native /workspace/skills entries can be uninstalled.\n`,exitCode:1};let a=await i.uninstallSkill(e,n);return a.success?{stdout:`Uninstalled skill "${a.skill}"\n`,stderr:``,exitCode:0}:{stdout:``,stderr:`skill: ${a.error}\n`,exitCode:1}}default:return{stdout:``,stderr:`skill: unknown command "${r}"\n`,exitCode:1}}}catch(e){return{stdout:``,stderr:`skill: ${e instanceof Error?e.message:String(e)}\n`,exitCode:1}}})}function f3(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&#39;`)}var p3=class{constructor(e){this.options=e}async execute(e,t){let n=e[0];if(n===`--help`||n===`-h`)return this.help();if(n===`unmount`||n===`-u`){let n=e[1];if(!n)return{stdout:``,stderr:`mount unmount: path required`,exitCode:1};let r=n.startsWith(`/`)?n:`${t.replace(/\/$/,``)}/${n}`;return this.options.fs.unmount(r),{stdout:`Unmounted ${r}\n`,stderr:``,exitCode:0}}if(n===`list`||n===`-l`){let e=this.options.fs.listMounts();if(e.length===0)return{stdout:`No active mounts
4381
4381
  `,stderr:``,exitCode:0};let t=this.options.fs.getMountIndex();return{stdout:e.map(e=>{let n=t.getState(e);return n?n.status===`ready`?`${e} (indexed: ${n.indexed} entries)`:n.status===`indexing`?`${e} (indexing: ${n.indexed} entries...)`:n.status===`error`?`${e} (index error: ${n.error})`:`${e} (pending index)`:e}).join(`
4382
4382
  `)+`
4383
4383
  `,stderr:``,exitCode:0}}if(n===`refresh`){let n=e[1];if(!n)return{stdout:``,stderr:`mount refresh: path required`,exitCode:1};let r=n.startsWith(`/`)?n:`${t.replace(/\/$/,``)}/${n}`;try{return await this.options.fs.refreshMount(r),{stdout:`Re-indexed ${r}\n`,stderr:``,exitCode:0}}catch(e){return{stdout:``,stderr:`mount refresh: ${e instanceof Error?e.message:String(e)}`,exitCode:1}}}if(!n)return{stdout:``,stderr:`mount: mount point required
4384
4384
  Usage: mount <target-path>
4385
4385
  `,exitCode:1};if(typeof window>`u`||!(`showDirectoryPicker`in window))return{stdout:``,stderr:`mount: File System Access API not available in this environment`,exitCode:1};let r;r=n.startsWith(`/`)?n:`${t.replace(/\/$/,``)}/${n}`,r.length>1&&(r=r.replace(/\/+$/,``));let i=fi(),a;if(i){let e=await pi({html:`
4386
4386
  <div class="sprinkle-action-card">
4387
- <div class="sprinkle-action-card__header">Mount at <code>${l3(r)}</code> <span class="sprinkle-badge sprinkle-badge--notice">approval</span></div>
4387
+ <div class="sprinkle-action-card__header">Mount at <code>${f3(r)}</code> <span class="sprinkle-badge sprinkle-badge--notice">approval</span></div>
4388
4388
  <div class="sprinkle-action-card__actions">
4389
4389
  <button class="sprinkle-btn sprinkle-btn--secondary" data-action="deny">Deny</button>
4390
4390
  <button class="sprinkle-btn sprinkle-btn--primary" data-action="approve" data-picker="directory">Select directory</button>
4391
4391
  </div>
4392
4392
  </div>
4393
- `,onAction:async(e,t)=>{if(e===`approve`){let e=t;if(e?.handleInIdb&&typeof e.idbKey==`string`)try{let t=await p3(e.idbKey);return t?(await d3(t),{approved:!0,handle:t}):{error:`No directory handle found in storage`}}catch(e){return{error:e instanceof Error?e.message:String(e)}}if(e?.cancelled)return{cancelled:!0};if(e?.error)return{error:String(e.error)};try{return{approved:!0,handle:await window.showDirectoryPicker({mode:`readwrite`})}}catch(e){return e instanceof Error&&e.name===`AbortError`?{cancelled:!0}:{error:e instanceof Error?e.message:String(e)}}}return{denied:!0}}});if(!e)return{stdout:``,stderr:`mount: tool UI not available`,exitCode:1};let t=e;if(t.denied)return{stdout:``,stderr:`mount: denied by user`,exitCode:1};if(t.cancelled)return{stdout:``,stderr:`mount: cancelled`,exitCode:1};if(t.error)return{stdout:``,stderr:`mount: ${t.error}`,exitCode:1};if(!t.handle)return{stdout:``,stderr:`mount: no directory selected`,exitCode:1};a=t.handle}else if(typeof chrome<`u`&&chrome?.runtime?.id)try{let e=await f3();if(e.cancelled)return{stdout:``,stderr:`mount: cancelled`,exitCode:1};if(e.error)return{stdout:``,stderr:`mount: ${e.error}`,exitCode:1};if(e.handleInIdb&&typeof e.idbKey==`string`){let t=await p3(e.idbKey);if(!t)return{stdout:``,stderr:`mount: no directory handle found in storage`,exitCode:1};await d3(t),a=t}else return{stdout:``,stderr:`mount: unexpected popup result`,exitCode:1}}catch(e){return{stdout:``,stderr:`mount: ${e instanceof Error?e.message:String(e)}`,exitCode:1}}else try{a=await window.showDirectoryPicker({mode:`readwrite`})}catch(e){return e instanceof Error&&e.name===`AbortError`?{stdout:``,stderr:`mount: cancelled`,exitCode:1}:{stdout:``,stderr:`mount: ${e instanceof Error?e.message:String(e)}`,exitCode:1}}try{return await this.options.fs.mount(r,a),{stdout:`Mounted '${a.name}' → ${r}\nIndexing in background for fast file discovery.\nNote: External changes are not auto-detected — use 'mount refresh ${r}' after modifying files outside the browser.\n`,stderr:``,exitCode:0}}catch(e){return{stdout:``,stderr:`mount: ${e instanceof Error?e.message:String(e)}`,exitCode:1}}}help(){return{stdout:[`Usage: mount <target-path>`,` mount unmount <path>`,` mount list`,` mount refresh <path>`,``,`Transparently bridge a real filesystem directory into the virtual filesystem.`,`Opens a directory picker; all reads and writes under <target-path> go directly`,`to the real directory — no copying occurs. Changes are immediately visible on`,`both sides. Mount points must be empty so existing VFS files are not hidden.`,``,`Upon mounting, files are indexed asynchronously for fast discovery. External`,`changes (made outside the browser) are NOT automatically detected — use`,"`mount refresh` to re-index after external modifications.",``,`Arguments:`,` <target-path> Mount point in the virtual filesystem (required).`,``,`Sub-commands:`,` unmount <path> Remove a mount point`,` list Show active mount points and index status`,` refresh <path> Re-index a mount after external changes`,``,`Examples:`,` mount /mnt/myapp # Mount selected dir at /mnt/myapp`,` mount list # Show active mounts with index status`,` mount refresh /mnt/myapp # Re-index after external changes`,` mount unmount /mnt/myapp`].join(`
4393
+ `,onAction:async(e,t)=>{if(e===`approve`){let e=t;if(e?.handleInIdb&&typeof e.idbKey==`string`)try{let t=await g3(e.idbKey);return t?(await m3(t),{approved:!0,handle:t}):{error:`No directory handle found in storage`}}catch(e){return{error:e instanceof Error?e.message:String(e)}}if(e?.cancelled)return{cancelled:!0};if(e?.error)return{error:String(e.error)};try{return{approved:!0,handle:await window.showDirectoryPicker({mode:`readwrite`})}}catch(e){return e instanceof Error&&e.name===`AbortError`?{cancelled:!0}:{error:e instanceof Error?e.message:String(e)}}}return{denied:!0}}});if(!e)return{stdout:``,stderr:`mount: tool UI not available`,exitCode:1};let t=e;if(t.denied)return{stdout:``,stderr:`mount: denied by user`,exitCode:1};if(t.cancelled)return{stdout:``,stderr:`mount: cancelled`,exitCode:1};if(t.error)return{stdout:``,stderr:`mount: ${t.error}`,exitCode:1};if(!t.handle)return{stdout:``,stderr:`mount: no directory selected`,exitCode:1};a=t.handle}else if(typeof chrome<`u`&&chrome?.runtime?.id)try{let e=await h3();if(e.cancelled)return{stdout:``,stderr:`mount: cancelled`,exitCode:1};if(e.error)return{stdout:``,stderr:`mount: ${e.error}`,exitCode:1};if(e.handleInIdb&&typeof e.idbKey==`string`){let t=await g3(e.idbKey);if(!t)return{stdout:``,stderr:`mount: no directory handle found in storage`,exitCode:1};await m3(t),a=t}else return{stdout:``,stderr:`mount: unexpected popup result`,exitCode:1}}catch(e){return{stdout:``,stderr:`mount: ${e instanceof Error?e.message:String(e)}`,exitCode:1}}else try{a=await window.showDirectoryPicker({mode:`readwrite`})}catch(e){return e instanceof Error&&e.name===`AbortError`?{stdout:``,stderr:`mount: cancelled`,exitCode:1}:{stdout:``,stderr:`mount: ${e instanceof Error?e.message:String(e)}`,exitCode:1}}try{return await this.options.fs.mount(r,a),{stdout:`Mounted '${a.name}' → ${r}\nIndexing in background for fast file discovery.\nNote: External changes are not auto-detected — use 'mount refresh ${r}' after modifying files outside the browser.\n`,stderr:``,exitCode:0}}catch(e){return{stdout:``,stderr:`mount: ${e instanceof Error?e.message:String(e)}`,exitCode:1}}}help(){return{stdout:[`Usage: mount <target-path>`,` mount unmount <path>`,` mount list`,` mount refresh <path>`,``,`Transparently bridge a real filesystem directory into the virtual filesystem.`,`Opens a directory picker; all reads and writes under <target-path> go directly`,`to the real directory — no copying occurs. Changes are immediately visible on`,`both sides. Mount points must be empty so existing VFS files are not hidden.`,``,`Upon mounting, files are indexed asynchronously for fast discovery. External`,`changes (made outside the browser) are NOT automatically detected — use`,"`mount refresh` to re-index after external modifications.",``,`Arguments:`,` <target-path> Mount point in the virtual filesystem (required).`,``,`Sub-commands:`,` unmount <path> Remove a mount point`,` list Show active mount points and index status`,` refresh <path> Re-index a mount after external changes`,``,`Examples:`,` mount /mnt/myapp # Mount selected dir at /mnt/myapp`,` mount list # Show active mounts with index status`,` mount refresh /mnt/myapp # Re-index after external changes`,` mount unmount /mnt/myapp`].join(`
4394
4394
  `)+`
4395
- `,stderr:``,exitCode:0}}};async function d3(e){let t=e;if(t.requestPermission){let n=await t.requestPermission({mode:`readwrite`});if(n!==`granted`)throw Error(`Permission denied for "${e.name}" (${n})`)}}function f3(){let e=`mount-${Date.now().toString(36)}`;return new Promise(t=>{let n=chrome.runtime.getURL(`mount-popup.html?requestId=${encodeURIComponent(e)}`),r=()=>{clearTimeout(i),chrome.runtime.onMessage.removeListener(a)},i=setTimeout(()=>{r(),t({cancelled:!0})},6e4),a=n=>{let i=n;!i||i.source!==`mount-popup`||i.requestId!==e||(r(),t(i))};chrome.runtime.onMessage.addListener(a),chrome.windows.create({url:n,type:`popup`,width:300,height:80,focused:!0}).catch(()=>{r(),t({error:`Failed to open directory picker window`})})})}async function p3(e){let t=await new Promise((e,t)=>{let n=indexedDB.open(`slicc-pending-mount`,1);n.onupgradeneeded=()=>{n.result.objectStoreNames.contains(`handles`)||n.result.createObjectStore(`handles`)},n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error)}),n=t.transaction(`handles`,`readwrite`),r=n.objectStore(`handles`),i=r.get(e),a=r.delete(e);a.onerror=()=>{console.warn(`[mount] Failed to delete pending handle from IDB`,e,a.error)};let o=await new Promise((e,t)=>{n.oncomplete=()=>e(i.result??null),i.onerror=()=>t(i.error??Error(`IDB get failed`)),n.onerror=()=>t(n.error??Error(`IDB transaction failed`)),n.onabort=()=>t(n.error??Error(`IDB transaction aborted`))});return t.close(),o}var m3=new Set([`http`,`https`,`net`,`tls`,`dgram`,`dns`,`cluster`,`worker_threads`,`child_process`,`crypto`,`os`,`stream`,`zlib`,`vm`,`v8`,`perf_hooks`,`readline`,`repl`,`tty`,`inspector`]);function h3(e){let t=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,n=[],r;for(;(r=t.exec(e))!==null;)n.push(r[1]);return[...new Set(n)]}async function g3(e,t,n){return await n.fs.exists(e)?_3(await n.fs.readFile(e),[`node`,e,...t],n):{stdout:``,stderr:`jsh: cannot find script '${e}'\n`,exitCode:127}}async function _3(e,t,n){let r=[],i=[],a=e=>{r.push(typeof e==`string`?e:String(e))},o=e=>{i.push(typeof e==`string`?e:String(e))},c={log:(...e)=>a(`${e.map(f1).join(` `)}\n`),info:(...e)=>a(`${e.map(f1).join(` `)}\n`),warn:(...e)=>o(`${e.map(f1).join(` `)}\n`),error:(...e)=>o(`${e.map(f1).join(` `)}\n`)},l={argv:t,env:Object.fromEntries(n.env.entries()),cwd:()=>n.cwd,exit:e=>{throw new e1(Number.isFinite(e)?Number(e):0)},stdout:{write:a},stderr:{write:o}},u={readFile:async e=>{let t=n.fs.resolvePath(n.cwd,e);return n.fs.readFile(t)},readFileBinary:async e=>{let t=n.fs.resolvePath(n.cwd,e);return n.fs.readFileBuffer(t)},writeFile:async(e,t)=>{let r=n.fs.resolvePath(n.cwd,e);await n.fs.writeFile(r,t)},writeFileBinary:async(e,t)=>{let r=n.fs.resolvePath(n.cwd,e),i=new Uint8Array(t.byteLength);i.set(t),await n.fs.writeFile(r,i)},readDir:async e=>{let t=n.fs.resolvePath(n.cwd,e);return n.fs.readdir(t)},exists:async e=>{let t=n.fs.resolvePath(n.cwd,e);return n.fs.exists(t)},stat:async e=>{let t=n.fs.resolvePath(n.cwd,e),r=await n.fs.stat(t);return{isDirectory:r.isDirectory,isFile:r.isFile,size:r.size}},mkdir:async e=>{let t=n.fs.resolvePath(n.cwd,e);await n.fs.mkdir(t,{recursive:!0})},rm:async e=>{let t=n.fs.resolvePath(n.cwd,e);await n.fs.rm(t,{recursive:!0})},fetchToFile:async(e,t)=>{if(typeof fetch>`u`)throw Error(`fetch is not available in this runtime`);let r=await fetch(e);if(!r.ok)throw Error(`fetch ${r.status} ${r.statusText}`);let i=new Uint8Array(await r.arrayBuffer()),a=n.fs.resolvePath(n.cwd,t);return await n.fs.writeFile(a,i),i.byteLength}},d=async e=>{if(!n.exec)throw Error(`exec is not available in this runtime`);let t=await n.exec(e,{cwd:n.cwd});return{stdout:t.stdout,stderr:t.stderr,exitCode:t.exitCode}},f=typeof chrome<`u`&&!!chrome?.runtime?.id;if(!f){let t=h3(e),n=new Set([`fs`,`process`,`buffer`]),r=t.map(e=>e.startsWith(`node:`)?e.slice(5):e).filter(e=>!n.has(e)&&!m3.has(e)),i=$$.__requireCache??=Object.create(null),a=r.filter(e=>!(e in i));if(a.length>0){let e=await Promise.allSettled(a.map(async e=>{let t=await s(()=>import(`https://esm.sh/`+e),[]);return{id:e,value:t.default===void 0?t:t.default}}));for(let t of e)t.status===`fulfilled`&&(i[t.value.id]=t.value.value)}}let p=e=>{let t=e.startsWith(`node:`)?e.slice(5):e;if(t===`fs`)return u;if(t===`process`)return l;if(t===`buffer`)return{Buffer:globalThis.Buffer};if(t===`path`){let t=$$.__requireCache;if(t&&`path`in t)return t.path;if(t&&e in t)return t[e];throw Error(`require('${e}'): path module not pre-loaded. Add require('path') as a static import.`)}if(m3.has(t))throw Error(`require('${e}'): Node built-in '${t}' is not available in the browser environment.${{http:` Use fetch() instead.`,https:` Use fetch() instead.`,child_process:` Use exec() which is available as a shell bridge.`,crypto:` Use globalThis.crypto (Web Crypto API) instead.`}[t]||``}`);let n=$$.__requireCache;if(n&&e in n)return n[e];throw Error(`require('${e}'): module not pre-loaded. Use a string literal so it can be pre-fetched, or use \`await import('https://esm.sh/${e}')\` directly.`)},m={exports:{},filename:t[1]||`<script>`};try{if(f){let r=`
4395
+ `,stderr:``,exitCode:0}}};async function m3(e){let t=e;if(t.requestPermission){let n=await t.requestPermission({mode:`readwrite`});if(n!==`granted`)throw Error(`Permission denied for "${e.name}" (${n})`)}}function h3(){let e=`mount-${Date.now().toString(36)}`;return new Promise(t=>{let n=chrome.runtime.getURL(`mount-popup.html?requestId=${encodeURIComponent(e)}`),r=()=>{clearTimeout(i),chrome.runtime.onMessage.removeListener(a)},i=setTimeout(()=>{r(),t({cancelled:!0})},6e4),a=n=>{let i=n;!i||i.source!==`mount-popup`||i.requestId!==e||(r(),t(i))};chrome.runtime.onMessage.addListener(a),chrome.windows.create({url:n,type:`popup`,width:300,height:80,focused:!0}).catch(()=>{r(),t({error:`Failed to open directory picker window`})})})}async function g3(e){let t=await new Promise((e,t)=>{let n=indexedDB.open(`slicc-pending-mount`,1);n.onupgradeneeded=()=>{n.result.objectStoreNames.contains(`handles`)||n.result.createObjectStore(`handles`)},n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error)}),n=t.transaction(`handles`,`readwrite`),r=n.objectStore(`handles`),i=r.get(e),a=r.delete(e);a.onerror=()=>{console.warn(`[mount] Failed to delete pending handle from IDB`,e,a.error)};let o=await new Promise((e,t)=>{n.oncomplete=()=>e(i.result??null),i.onerror=()=>t(i.error??Error(`IDB get failed`)),n.onerror=()=>t(n.error??Error(`IDB transaction failed`)),n.onabort=()=>t(n.error??Error(`IDB transaction aborted`))});return t.close(),o}var _3=new Set([`http`,`https`,`net`,`tls`,`dgram`,`dns`,`cluster`,`worker_threads`,`child_process`,`crypto`,`os`,`stream`,`zlib`,`vm`,`v8`,`perf_hooks`,`readline`,`repl`,`tty`,`inspector`]);function v3(e){let t=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,n=[],r;for(;(r=t.exec(e))!==null;)n.push(r[1]);return[...new Set(n)]}async function y3(e,t,n){return await n.fs.exists(e)?b3(await n.fs.readFile(e),[`node`,e,...t],n):{stdout:``,stderr:`jsh: cannot find script '${e}'\n`,exitCode:127}}async function b3(e,t,n){let r=[],i=[],a=e=>{r.push(typeof e==`string`?e:String(e))},o=e=>{i.push(typeof e==`string`?e:String(e))},c={log:(...e)=>a(`${e.map(h1).join(` `)}\n`),info:(...e)=>a(`${e.map(h1).join(` `)}\n`),warn:(...e)=>o(`${e.map(h1).join(` `)}\n`),error:(...e)=>o(`${e.map(h1).join(` `)}\n`)},l={argv:t,env:Object.fromEntries(n.env.entries()),cwd:()=>n.cwd,exit:e=>{throw new r1(Number.isFinite(e)?Number(e):0)},stdout:{write:a},stderr:{write:o}},u={readFile:async e=>{let t=n.fs.resolvePath(n.cwd,e);return n.fs.readFile(t)},readFileBinary:async e=>{let t=n.fs.resolvePath(n.cwd,e);return n.fs.readFileBuffer(t)},writeFile:async(e,t)=>{let r=n.fs.resolvePath(n.cwd,e);await n.fs.writeFile(r,t)},writeFileBinary:async(e,t)=>{let r=n.fs.resolvePath(n.cwd,e),i=new Uint8Array(t.byteLength);i.set(t),await n.fs.writeFile(r,i)},readDir:async e=>{let t=n.fs.resolvePath(n.cwd,e);return n.fs.readdir(t)},exists:async e=>{let t=n.fs.resolvePath(n.cwd,e);return n.fs.exists(t)},stat:async e=>{let t=n.fs.resolvePath(n.cwd,e),r=await n.fs.stat(t);return{isDirectory:r.isDirectory,isFile:r.isFile,size:r.size}},mkdir:async e=>{let t=n.fs.resolvePath(n.cwd,e);await n.fs.mkdir(t,{recursive:!0})},rm:async e=>{let t=n.fs.resolvePath(n.cwd,e);await n.fs.rm(t,{recursive:!0})},fetchToFile:async(e,t)=>{if(typeof fetch>`u`)throw Error(`fetch is not available in this runtime`);let r=await fetch(e);if(!r.ok)throw Error(`fetch ${r.status} ${r.statusText}`);let i=new Uint8Array(await r.arrayBuffer()),a=n.fs.resolvePath(n.cwd,t);return await n.fs.writeFile(a,i),i.byteLength}},d=async e=>{if(!n.exec)throw Error(`exec is not available in this runtime`);let t=await n.exec(e,{cwd:n.cwd});return{stdout:t.stdout,stderr:t.stderr,exitCode:t.exitCode}},f=typeof chrome<`u`&&!!chrome?.runtime?.id;if(!f){let t=v3(e),n=new Set([`fs`,`process`,`buffer`]),r=t.map(e=>e.startsWith(`node:`)?e.slice(5):e).filter(e=>!n.has(e)&&!_3.has(e)),i=n1.__requireCache??=Object.create(null),a=r.filter(e=>!(e in i));if(a.length>0){let e=await Promise.allSettled(a.map(async e=>{let t=await s(()=>import(`https://esm.sh/`+e),[]);return{id:e,value:t.default===void 0?t:t.default}}));for(let t of e)t.status===`fulfilled`&&(i[t.value.id]=t.value.value)}}let p=e=>{let t=e.startsWith(`node:`)?e.slice(5):e;if(t===`fs`)return u;if(t===`process`)return l;if(t===`buffer`)return{Buffer:globalThis.Buffer};if(t===`path`){let t=n1.__requireCache;if(t&&`path`in t)return t.path;if(t&&e in t)return t[e];throw Error(`require('${e}'): path module not pre-loaded. Add require('path') as a static import.`)}if(_3.has(t))throw Error(`require('${e}'): Node built-in '${t}' is not available in the browser environment.${{http:` Use fetch() instead.`,https:` Use fetch() instead.`,child_process:` Use exec() which is available as a shell bridge.`,crypto:` Use globalThis.crypto (Web Crypto API) instead.`}[t]||``}`);let n=n1.__requireCache;if(n&&e in n)return n[e];throw Error(`require('${e}'): module not pre-loaded. Use a string literal so it can be pre-fetched, or use \`await import('https://esm.sh/${e}')\` directly.`)},m={exports:{},filename:t[1]||`<script>`};try{if(f){let r=`
4396
4396
  const __stdout = [];
4397
4397
  const __stderr = [];
4398
4398
  const __origConsole = { log: console.log, error: console.error, warn: console.warn, info: console.info };
@@ -4488,9 +4488,9 @@ Usage: mount <target-path>
4488
4488
  console.info = __origConsole.info;
4489
4489
  return { stdout: __stdout.join(''), stderr: __stderr.join('') };
4490
4490
  `,i=document.querySelector(`iframe[data-js-tool]`);i||(i=document.createElement(`iframe`),i.style.display=`none`,i.dataset.jsTool=`true`,i.src=chrome.runtime.getURL(`sandbox.html`),document.body.appendChild(i),await new Promise(e=>{i.addEventListener(`load`,()=>e(),{once:!0})}));let a=`jsh-${Date.now()}-${Math.random().toString(36).slice(2)}`,o=e=>{let t=e.data;!t||t.type!==`vfs`||(async()=>{try{let e,r=t.args?.[0]?n.fs.resolvePath(n.cwd,t.args[0]):t.args?.[0];switch(t.op){case`readFile`:e=await n.fs.readFile(r);break;case`readFileBinary`:e=await n.fs.readFileBuffer(r);break;case`writeFile`:await n.fs.writeFile(r,t.args[1]),e=!0;break;case`writeFileBinary`:await n.fs.writeFile(r,t.binaryData??new Uint8Array),e=!0;break;case`readDir`:e=await n.fs.readdir(r);break;case`exists`:e=await n.fs.exists(r);break;case`stat`:{let t=await n.fs.stat(r);e={isDirectory:t.isDirectory,isFile:t.isFile,size:t.size};break}case`mkdir`:await n.fs.mkdir(r,{recursive:!0}),e=!0;break;case`rm`:await n.fs.rm(r,{recursive:!0}),e=!0;break}i.contentWindow.postMessage({type:`vfs_response`,id:t.id,result:e},`*`)}catch(e){let n=e instanceof Error?e.message:String(e);i.contentWindow.postMessage({type:`vfs_response`,id:t.id,error:n},`*`)}})()};window.addEventListener(`message`,o);let s=e=>{let t=e.data;!t||t.type!==`shell_exec`||(async()=>{try{let e=await d(t.command);i.contentWindow.postMessage({type:`shell_exec_response`,id:t.id,result:e},`*`)}catch(e){let n=e instanceof Error?e.message:String(e);i.contentWindow.postMessage({type:`shell_exec_response`,id:t.id,error:n},`*`)}})()};window.addEventListener(`message`,s);let c=e=>{let t=e.data;!t||t.type!==`fetch_proxy`||(async()=>{try{let e={method:t.init?.method??`GET`,cache:`no-store`};t.init?.headers&&(e.headers=t.init.headers),t.init?.body&&![`GET`,`HEAD`].includes(e.method)&&(e.body=t.init.body);let n=await fetch(t.url,e),r=await n.arrayBuffer(),a={};n.headers.forEach((e,t)=>{a[t]=e}),i.contentWindow.postMessage({type:`fetch_proxy_response`,id:t.id,status:n.status,statusText:n.statusText,headers:a,body:new Uint8Array(r)},`*`)}catch(e){let n=e instanceof Error?e.message:String(e);i.contentWindow.postMessage({type:`fetch_proxy_response`,id:t.id,error:n},`*`)}})()};window.addEventListener(`message`,c);let u=await new Promise((e,t)=>{let n,o=t=>{if(t.data?.type===`exec_result`&&t.data.id===a)if(window.removeEventListener(`message`,o),clearTimeout(n),t.data.error)e({stdout:``,stderr:t.data.error+`
4491
- `});else try{let n=JSON.parse(t.data.result);e({stdout:n.stdout||``,stderr:n.stderr||``})}catch{e({stdout:t.data.result||``,stderr:``})}};n=setTimeout(()=>{window.removeEventListener(`message`,o),t(Error(`jsh eval timed out (30s)`))},3e4),window.addEventListener(`message`,o),i.contentWindow.postMessage({type:`exec`,id:a,code:r},`*`)});return window.removeEventListener(`message`,o),window.removeEventListener(`message`,s),window.removeEventListener(`message`,c),{stdout:u.stdout,stderr:u.stderr,exitCode:+!!u.stderr}}let a=Object.getPrototypeOf(async function(){}).constructor;return await new a(`fs`,`process`,`console`,`require`,`module`,`exports`,`__state`,`exec`,`"use strict";\nconst globalThis = __state;\nconst global = __state;\n${e}`)(u,l,c,p,m,m.exports,$$,d),{stdout:r.join(``),stderr:i.join(``),exitCode:0}}catch(e){if(e instanceof e1)return{stdout:r.join(``),stderr:i.join(``),exitCode:e.code};let t=e instanceof Error?e.stack??e.message:String(e);return{stdout:r.join(``),stderr:`${i.join(``)}${t}\n`,exitCode:1}}}function v3(e){let t=[],n=``,r=0;for(;r<e.length;){let i=e[r];if(i===`"`){for(r++;r<e.length&&e[r]!==`"`;)n+=e[r],r++;r++}else if(i===`'`){for(r++;r<e.length&&e[r]!==`'`;)n+=e[r],r++;r++}else i===`\\`&&r+1<e.length&&e[r+1]===` `?(n+=` `,r+=2):/\s/.test(i)?(n.length>0&&(t.push(n),n=``),r++):(n+=i,r++)}return n.length>0&&t.push(n),t}var y3=[`/workspace`,`/shared`];async function b3(e){let t=[],n=new Set;for(let r of y3)await e.exists(r)&&await x3(e,r,t,n);return t}async function x3(e,t,n,r){for await(let i of e.walk(t)){if(!i.endsWith(`.bsh`)||r.has(i))continue;r.add(i);let t=S3(i);if(!t)continue;let a=await e.readFile(i,{encoding:`utf-8`}),o=C3(typeof a==`string`?a:new TextDecoder().decode(a));n.push({path:i,hostnamePattern:t,matchPatterns:o})}}function S3(e){let t=e.split(`/`).pop()??``;if(!t.endsWith(`.bsh`))return null;let n=t.slice(0,-4);return n?n.startsWith(`-.`)?`*`+n.slice(1):n:null}function C3(e){let t=e.split(`
4492
- `).slice(0,10),n=[];for(let e of t){let t=e.match(/^\s*\/\/\s*@match\s+(.+)$/);t&&n.push(t[1].trim())}return n}function w3(e,t){if(t.startsWith(`*.`)){let n=t.slice(1);return e===t.slice(2)||e.endsWith(n)&&e.length>n.length}return e===t}function T3(e,t){try{let n=new URL(e),r=t.match(/^(\*|https?):\/\/([^/]+)(\/.*)?$/);if(!r)return!1;let[,i,a,o]=r;return i!==`*`&&n.protocol.slice(0,-1)!==i||!w3(n.hostname,a)?!1:o?E3(n.pathname+n.search,o):!0}catch{return!1}}function E3(e,t){let n=`^`+t.replace(/[.+^${}()|[\]\\]/g,`\\$&`).replace(/\*/g,`.*`)+`$`;return new RegExp(n).test(e)}function D3(e,t){try{let n=new URL(t);return e.filter(e=>w3(n.hostname,e.hostnamePattern)?e.matchPatterns.length>0?e.matchPatterns.some(e=>T3(t,e)):!0:!1)}catch{return[]}}var O3=[`/workspace`,`/shared`];function k3(e){return new Map(e)}function A3(e){return e.map(e=>({...e,matchPatterns:[...e.matchPatterns]}))}function j3(e){if(e&&typeof e.listMounts==`function`)return e;if(e&&typeof e.getUnderlyingFS==`function`){let t=e.getUnderlyingFS?.();if(t&&typeof t.listMounts==`function`)return t}return null}function M3(e){return(j3(e)?.listMounts?.().length??0)>0}function N3(e){return e?(j3(e)?.listMounts?.()??[]).some(e=>O3.some(t=>e===t||e.startsWith(t+`/`))):!1}var P3=class{jshFs;bshFs;watcher;watcherUnsubs=[];jshCache=null;jshInflight=null;bshCache=null;bshInflight=null;jshGeneration=0;bshGeneration=0;constructor(e){if(this.jshFs=e.jshFs,this.bshFs=e.bshFs,this.watcher=e.watcher??null,this.watcher&&(this.watcherUnsubs.push(this.watcher.watch(`/`,()=>!0,()=>this.invalidateJsh())),this.bshFs))for(let e of O3)this.watcherUnsubs.push(this.watcher.watch(e,()=>!0,()=>this.invalidateBsh()))}dispose(){for(let e of this.watcherUnsubs)e();this.watcherUnsubs.length=0,this.invalidateAll()}invalidateAll(){this.invalidateJsh(),this.invalidateBsh()}invalidateJsh(){this.jshGeneration++,this.jshCache=null,this.jshInflight=null}invalidateBsh(){this.bshGeneration++,this.bshCache=null,this.bshInflight=null}async getJshCommands(){return k3(await this.loadJshCommands())}async getJshCommandNames(){return[...(await this.getJshCommands()).keys()]}async getBshEntries(){return this.bshFs?A3(await this.loadBshEntries()):[]}async findMatchingBshScripts(e){return this.bshFs?A3(D3(await this.loadBshEntries(),e)):[]}shouldCacheJsh(){return!!this.watcher&&!M3(this.jshFs)}shouldCacheBsh(){return!!this.watcher&&!!this.bshFs&&!N3(this.bshFs)}async loadJshCommands(){let e=this.shouldCacheJsh();if(e&&this.jshCache)return this.jshCache;if(!this.jshInflight){let t=this.jshGeneration,n=q0(this.jshFs).then(n=>{let r=k3(n);return e&&this.jshGeneration===t&&(this.jshCache=r),r}).finally(()=>{this.jshInflight===n&&(this.jshInflight=null)});this.jshInflight=n}return this.jshInflight}async loadBshEntries(){if(!this.bshFs)return[];let e=this.shouldCacheBsh();if(e&&this.bshCache)return this.bshCache;if(!this.bshInflight){let t=this.bshGeneration,n=b3(this.bshFs).then(n=>{let r=A3(n);return e&&this.bshGeneration===t&&(this.bshCache=r),r}).finally(()=>{this.bshInflight===n&&(this.bshInflight=null)});this.bshInflight=n}return this.bshInflight}},F3=null,I3=!1;function L3(){return typeof chrome<`u`&&chrome?.runtime?.id?`extension`:typeof document<`u`&&document.documentElement?.dataset?.electronOverlay?`electron`:`cli`}async function R3(){if(!I3&&!(typeof localStorage<`u`&&localStorage.getItem(`telemetry-disabled`)===`true`))try{typeof window<`u`&&(window.SAMPLE_PAGEVIEWS_AT_RATE=`high`),F3=(await s(()=>import(`./src-Cu5WM_BM.js`),[])).sampleRUM,I3=!0,F3&&F3(`navigate`,{source:typeof document<`u`?document.referrer:``,target:L3()})}catch{}}function z3(e,t){F3?.(`formsubmit`,{source:e,target:t})}function B3(e){F3?.(`fill`,{source:e})}function V3(e){F3?.(`viewblock`,{source:e})}function H3(e){let t=e.length>1&&e.endsWith(`/`)?e.slice(0,-1):e,n=t.lastIndexOf(`/`);return n>=0?t.slice(n+1):t}function U3(e){return e&&typeof e.getWatcher==`function`?e.getWatcher?.()??null:e&&typeof e.getUnderlyingFS==`function`?U3(e.getUnderlyingFS?.()):null}function W3(e){if(!e)return!0;let t=e.toLowerCase();return t.startsWith(`text/`)||t.includes(`json`)||t.includes(`xml`)||t.includes(`javascript`)||t.includes(`ecmascript`)||t.includes(`html`)||t.includes(`css`)||t.includes(`svg`)}async function G3(e,t){let n=e.headers.get(`content-type`)??``,r=await e.arrayBuffer(),i=new Uint8Array(r);if(!W3(n)){let e=``;for(let t=0;t<i.length;t+=32768)e+=String.fromCharCode(...i.subarray(t,t+32768));EW(e,i),t&&DW(t,i)}return i}function K3(e){if(e){if(e instanceof Headers){let t={};return e.forEach((e,n)=>{t[n]=e}),t}return e}}function q3(e,t){if(e){if((t?.[`Content-Type`]??t?.[`content-type`]??``).includes(`multipart/form-data`)){let t=PW(e);return new Blob([t])}return e}}function J3(e){if(!e)return{};let t={};for(let[n,r]of Object.entries(e)){let e=n.toLowerCase();e===`cookie`?t[`X-Proxy-Cookie`]=r:e===`origin`?t[`X-Proxy-Origin`]=r:e===`referer`?t[`X-Proxy-Referer`]=r:e.startsWith(`proxy-`)?t[`X-Proxy-${n}`]=r:t[n]=r}return t}function Y3(e){let t={};for(let[n,r]of Object.entries(e))n.toLowerCase()===`x-proxy-set-cookie`?t[`set-cookie`]=r:t[n]=r;return t}function X3(){return typeof chrome<`u`&&chrome?.runtime?.id?async(e,t)=>{let n=K3(t?.headers),r=await fetch(e,{method:t?.method??`GET`,headers:n,body:q3(t?.body,n)}),i=await G3(r,e),a={};return r.headers.forEach((e,t)=>{a[t]=e}),{status:r.status,statusText:r.statusText,headers:a,body:i,url:e}}:async(e,t)=>{let n=t?.method??`GET`,r={...J3(K3(t?.headers)),"X-Target-URL":e},i={method:n,headers:r,cache:`no-store`};t?.body&&![`GET`,`HEAD`].includes(n)&&(i.body=q3(t.body,r));let a=await fetch(`/api/fetch-proxy`,i);if(a.status===502||a.status===400){let e=await a.text(),t=`Proxy error ${a.status}`;try{t=JSON.parse(e).error??t}catch{}throw Error(t)}let o=await G3(a,e),s={};a.headers.forEach((e,t)=>{s[t]=e});let c=Y3(s);return{status:a.status,statusText:a.statusText,headers:c,body:o,url:e}}}var Z3=class{bash;vfsAdapter;gitCommands;mountCommands;terminal=null;fitAddon=null;terminalHost=null;previewHost=null;previewUrls=[];previewStateListener=null;hasPreview=!1;resizeObserver=null;themeObserver=null;currentLine=``;cursorPos=0;history=[];historyIndex=-1;isExecuting=!1;execAbort=null;continuationBuffer=``;lastEnv;cwd;builtinCommandNames;allowedCommands;scriptCatalog;ownsScriptCatalog;registeredJshCommands=new Map;jshSyncInflight=null;jshSyncDirty=!1;constructor(e){this.options=e,this.vfsAdapter=new AW(e.fs),this.allowedCommands=e.allowedCommands&&!e.allowedCommands.includes(`*`)?new Set(e.allowedCommands):null;let t=e.cwd??`/`,n={HOME:`/`,PATH:`/usr/bin`,USER:`user`,SHELL:`/bin/bash`,PWD:t,...e.env};this.gitCommands=new sQ({fs:e.fs,authorName:n.GIT_AUTHOR_NAME??`User`,authorEmail:n.GIT_AUTHOR_EMAIL??`user@example.com`}),this.mountCommands=new u3({fs:e.fs});let r=e.jshDiscoveryFs??e.fs,i=e.bshDiscoveryFs??e.fs,a=U3(r)??U3(i);this.scriptCatalog=e.scriptCatalog??new P3({jshFs:r,bshFs:i,watcher:a}),this.ownsScriptCatalog=!e.scriptCatalog,a&&a.watch(`/`,e=>e.endsWith(`.jsh`),()=>{this.syncJshCommands().catch(()=>void 0)});let o=this.createGitCustomCommand(),s=l4({onMediaPreview:async e=>this.renderMediaPreview(e),getJshCommands:()=>this.getJshCommandNames(),fs:e.fs,scriptCatalog:this.scriptCatalog,browserAPI:e.browserAPI,getParentJid:e.getParentJid}),c=this.createMountCustomCommand(),l=X3(),u=[o,c,c3(e.fs),s3(e.fs,l),...s].filter(e=>this.isCommandAllowed(e.name)),d=[...lR(),...uR()],f=this.allowedCommands?d.filter(e=>this.isCommandAllowed(e)):void 0;if(this.bash=new yW({fs:this.vfsAdapter,cwd:t,env:n,fetch:l,commands:f,customCommands:u}),this.allowedCommands!==null){let e=this.bash;for(let t of uR())this.isCommandAllowed(t)||e.commands.delete(t)}let p=u.map(e=>e.name),m=f??[...lR(),...uR()];this.builtinCommandNames=new Set([...m,...p]),this.vfsAdapter.setRegisteredCommandsFn(()=>[...this.builtinCommandNames]),this.lastEnv={...n},this.cwd=t,this.syncJshCommands().catch(()=>void 0)}isCommandAllowed(e){return this.allowedCommands===null||this.allowedCommands.has(e)}async syncJshCommands(){return this.jshSyncInflight?(this.jshSyncDirty=!0,this.jshSyncInflight):(this.jshSyncInflight=this.doSyncJshCommands(),this.jshSyncInflight)}async doSyncJshCommands(){try{let e=await this.scriptCatalog.getJshCommands(),t=this.options.jshDiscoveryFs??this.options.fs;for(let[n,r]of e){if(!this.isCommandAllowed(n)||this.builtinCommandNames.has(n)&&!this.registeredJshCommands.has(n)||this.registeredJshCommands.get(n)===r)continue;let e=this.scriptCatalog,i=this,a=n,o={name:n,async execute(n,r){let o=(await e.getJshCommands()).get(a);if(!o)return{stdout:``,stderr:`jsh: command '${a}' no longer exists\n`,exitCode:127};let s;try{let e=await t.readFile(o,{encoding:`utf-8`});s=typeof e==`string`?e:new TextDecoder().decode(e)}catch{return{stdout:``,stderr:`jsh: cannot read script '${o}'\n`,exitCode:127}}let c=[`node`,o,...n],l=r.exec??((e,t)=>i.bash.exec(e,{env:Object.fromEntries(r.env),cwd:t?.cwd??r.cwd}));return _3(s,c,{fs:r.fs,cwd:r.cwd,env:r.env,stdin:r.stdin,exec:l})}};this.bash.registerCommand(o),this.registeredJshCommands.set(n,r),this.builtinCommandNames.add(n)}}finally{this.jshSyncInflight=null,this.jshSyncDirty&&(this.jshSyncDirty=!1,this.syncJshCommands().catch(()=>void 0))}}createGitCustomCommand(){let e=this.gitCommands;return gR(`git`,async(t,n)=>{let r=n.cwd,i=await e.execute(t,r);return{stdout:i.stdout,stderr:i.stderr,exitCode:i.exitCode}})}createMountCustomCommand(){let e=this.mountCommands;return gR(`mount`,async(t,n)=>{let r=n.cwd,i=await e.execute(t,r);return{stdout:i.stdout,stderr:i.stderr,exitCode:i.exitCode}})}getBash(){return this.bash}getCwd(){return this.cwd}getScriptCatalog(){return this.scriptCatalog}getEnv(){return{...this.lastEnv}}async getFilteredJshCommands(){let e=await this.scriptCatalog.getJshCommands(),t=new Map;for(let[n,r]of e)this.builtinCommandNames.has(n)||this.isCommandAllowed(n)&&t.set(n,r);return t}async getJshCommandNames(){return[...(await this.getFilteredJshCommands()).keys()]}async tryJshFallback(e){let t=e.trim(),n=t.indexOf(` `),r=n>=0?t.slice(0,n):t,i=n>=0?t.slice(n+1).trim():``,a=(await this.getFilteredJshCommands()).get(r);if(!a)return null;let o=i?v3(i):[],s=this.options.jshDiscoveryFs??this.options.fs,c;try{let e=await s.readFile(a,{encoding:`utf-8`});c=typeof e==`string`?e:new TextDecoder().decode(e)}catch{return{stdout:``,stderr:`jsh: cannot read script '${a}'\n`,exitCode:127,env:this.lastEnv}}let l=[`node`,a,...o],u=await _3(c,l,{fs:this.vfsAdapter,cwd:this.cwd,env:new Map(Object.entries(this.lastEnv)),stdin:``,exec:(e,t)=>this.bash.exec(e,{env:this.lastEnv,cwd:t?.cwd??this.cwd})});return{stdout:u.stdout,stderr:u.stderr,exitCode:u.exitCode,env:this.lastEnv}}async runCommand(e,t){B3(e.trim().split(/\s+/)[0]||`unknown`);let n={env:this.lastEnv,cwd:this.cwd,signal:t??this.execAbort?.signal},r=await this.bash.exec(e,n);if(r.env&&(this.lastEnv={...r.env}),r.env?.PWD&&(this.cwd=r.env.PWD),r.exitCode===127){let t=await this.tryJshFallback(e);if(t)return this.syncJshCommands().catch(()=>void 0),t}return r}async mount(e){let t=e??this.options.container;if(!t)throw Error(`No container element provided`);let{Terminal:n}=await s(async()=>{let{Terminal:e}=await import(`./xterm-D5M9QCcR.js`);return{Terminal:e}},[]),{FitAddon:r}=await s(async()=>{let{FitAddon:e}=await import(`./addon-fit-B0aHsvmX.js`);return{FitAddon:e}},[]);await s(()=>Promise.resolve({}),__vite__mapDeps([17]));let i=!document.documentElement.classList.contains(`theme-light`),a={background:`#141414`,foreground:`#cfcfcf`,cursor:`#3562ff`,cursorAccent:`#141414`,selectionBackground:`#3562ff40`,selectionForeground:`#ffffff`,black:`#1a1a1a`,red:`#e34850`,green:`#2d9d78`,yellow:`#e68619`,blue:`#3562ff`,magenta:`#a962e8`,cyan:`#2db9be`,white:`#cfcfcf`,brightBlack:`#5a5a5a`,brightRed:`#e34850`,brightGreen:`#2d9d78`,brightYellow:`#e68619`,brightBlue:`#4a75ff`,brightMagenta:`#a962e8`,brightCyan:`#2db9be`,brightWhite:`#ffffff`},o={background:`#f0f0f0`,foreground:`#1a1a1a`,cursor:`#2b54db`,cursorAccent:`#f0f0f0`,selectionBackground:`#2b54db30`,selectionForeground:`#000000`,black:`#1a1a1a`,red:`#d73220`,green:`#268e6c`,yellow:`#d17a00`,blue:`#2b54db`,magenta:`#8839ef`,cyan:`#1a9088`,white:`#e8e8e8`,brightBlack:`#6e6e6e`,brightRed:`#d73220`,brightGreen:`#268e6c`,brightYellow:`#d17a00`,brightBlue:`#1e44c4`,brightMagenta:`#8839ef`,brightCyan:`#1a9088`,brightWhite:`#ffffff`};this.terminal=new n({cursorBlink:!0,fontSize:11,fontFamily:`'Source Code Pro', 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace`,theme:i?a:o,convertEol:!0}),this.themeObserver?.disconnect(),this.themeObserver=new MutationObserver(()=>{if(!this.terminal)return;let e=document.documentElement.classList.contains(`theme-light`);this.terminal.options.theme=e?o:a}),this.themeObserver.observe(document.documentElement,{attributes:!0,attributeFilter:[`class`]}),this.fitAddon=new r,this.terminal.loadAddon(this.fitAddon),t.replaceChildren(),this.terminalHost=document.createElement(`div`),this.terminalHost.className=`terminal-panel__terminal-host`,t.appendChild(this.terminalHost),this.previewHost=document.createElement(`div`),this.previewHost.className=`terminal-panel__preview`,t.appendChild(this.previewHost),this.terminal.open(this.terminalHost),this.fitAddon.fit(),this.resizeObserver?.disconnect(),this.resizeObserver=new ResizeObserver(()=>this.refit()),this.resizeObserver.observe(this.terminalHost),this.terminal.writeln(`\x1B[1mslicc\x1B[0m \x1B[90mshell (powered by just-bash)\x1B[0m`),this.terminal.writeln(`\x1B[90mType "help" for available commands.\x1B[0m
4493
- `),this.showPrompt(),this.setupInputHandler()}async executeCommand(e,t){let n=await this.runCommand(e,t);return{stdout:n.stdout,stderr:n.stderr,exitCode:n.exitCode}}async executeScriptFile(e,t=[]){return g3(e,t,{fs:this.vfsAdapter,cwd:this.cwd,env:new Map(Object.entries(this.lastEnv)),stdin:``,exec:(e,t)=>this.bash.exec(e,{env:this.lastEnv,cwd:t?.cwd??this.cwd})})}refit(){this.fitAddon?.fit()}setPreviewStateListener(e){this.previewStateListener=e,this.previewStateListener?.(this.hasPreview)}async executeCommandInTerminal(e){let t=e.trim();if(!t)return{stdout:``,stderr:``,exitCode:0};if(!this.terminal)return this.executeCommand(t);if(this.isExecuting||this.currentLine.length>0||this.continuationBuffer.length>0)return{stdout:``,stderr:`terminal is busy; finish current input first
4491
+ `});else try{let n=JSON.parse(t.data.result);e({stdout:n.stdout||``,stderr:n.stderr||``})}catch{e({stdout:t.data.result||``,stderr:``})}};n=setTimeout(()=>{window.removeEventListener(`message`,o),t(Error(`jsh eval timed out (30s)`))},3e4),window.addEventListener(`message`,o),i.contentWindow.postMessage({type:`exec`,id:a,code:r},`*`)});return window.removeEventListener(`message`,o),window.removeEventListener(`message`,s),window.removeEventListener(`message`,c),{stdout:u.stdout,stderr:u.stderr,exitCode:+!!u.stderr}}let a=Object.getPrototypeOf(async function(){}).constructor;return await new a(`fs`,`process`,`console`,`require`,`module`,`exports`,`__state`,`exec`,`"use strict";\nconst globalThis = __state;\nconst global = __state;\n${e}`)(u,l,c,p,m,m.exports,n1,d),{stdout:r.join(``),stderr:i.join(``),exitCode:0}}catch(e){if(e instanceof r1)return{stdout:r.join(``),stderr:i.join(``),exitCode:e.code};let t=e instanceof Error?e.stack??e.message:String(e);return{stdout:r.join(``),stderr:`${i.join(``)}${t}\n`,exitCode:1}}}function x3(e){let t=[],n=``,r=0;for(;r<e.length;){let i=e[r];if(i===`"`){for(r++;r<e.length&&e[r]!==`"`;)n+=e[r],r++;r++}else if(i===`'`){for(r++;r<e.length&&e[r]!==`'`;)n+=e[r],r++;r++}else i===`\\`&&r+1<e.length&&e[r+1]===` `?(n+=` `,r+=2):/\s/.test(i)?(n.length>0&&(t.push(n),n=``),r++):(n+=i,r++)}return n.length>0&&t.push(n),t}var S3=[`/workspace`,`/shared`];async function C3(e){let t=[],n=new Set;for(let r of S3)await e.exists(r)&&await w3(e,r,t,n);return t}async function w3(e,t,n,r){for await(let i of e.walk(t)){if(!i.endsWith(`.bsh`)||r.has(i))continue;r.add(i);let t=T3(i);if(!t)continue;let a=await e.readFile(i,{encoding:`utf-8`}),o=E3(typeof a==`string`?a:new TextDecoder().decode(a));n.push({path:i,hostnamePattern:t,matchPatterns:o})}}function T3(e){let t=e.split(`/`).pop()??``;if(!t.endsWith(`.bsh`))return null;let n=t.slice(0,-4);return n?n.startsWith(`-.`)?`*`+n.slice(1):n:null}function E3(e){let t=e.split(`
4492
+ `).slice(0,10),n=[];for(let e of t){let t=e.match(/^\s*\/\/\s*@match\s+(.+)$/);t&&n.push(t[1].trim())}return n}function D3(e,t){if(t.startsWith(`*.`)){let n=t.slice(1);return e===t.slice(2)||e.endsWith(n)&&e.length>n.length}return e===t}function O3(e,t){try{let n=new URL(e),r=t.match(/^(\*|https?):\/\/([^/]+)(\/.*)?$/);if(!r)return!1;let[,i,a,o]=r;return i!==`*`&&n.protocol.slice(0,-1)!==i||!D3(n.hostname,a)?!1:o?k3(n.pathname+n.search,o):!0}catch{return!1}}function k3(e,t){let n=`^`+t.replace(/[.+^${}()|[\]\\]/g,`\\$&`).replace(/\*/g,`.*`)+`$`;return new RegExp(n).test(e)}function A3(e,t){try{let n=new URL(t);return e.filter(e=>D3(n.hostname,e.hostnamePattern)?e.matchPatterns.length>0?e.matchPatterns.some(e=>O3(t,e)):!0:!1)}catch{return[]}}var j3=[`/workspace`,`/shared`];function M3(e){return new Map(e)}function N3(e){return e.map(e=>({...e,matchPatterns:[...e.matchPatterns]}))}function P3(e){if(e&&typeof e.listMounts==`function`)return e;if(e&&typeof e.getUnderlyingFS==`function`){let t=e.getUnderlyingFS?.();if(t&&typeof t.listMounts==`function`)return t}return null}function F3(e){return(P3(e)?.listMounts?.().length??0)>0}function I3(e){return e?(P3(e)?.listMounts?.()??[]).some(e=>j3.some(t=>e===t||e.startsWith(t+`/`))):!1}var L3=class{jshFs;bshFs;watcher;watcherUnsubs=[];jshCache=null;jshInflight=null;bshCache=null;bshInflight=null;jshGeneration=0;bshGeneration=0;constructor(e){if(this.jshFs=e.jshFs,this.bshFs=e.bshFs,this.watcher=e.watcher??null,this.watcher&&(this.watcherUnsubs.push(this.watcher.watch(`/`,()=>!0,()=>this.invalidateJsh())),this.bshFs))for(let e of j3)this.watcherUnsubs.push(this.watcher.watch(e,()=>!0,()=>this.invalidateBsh()))}dispose(){for(let e of this.watcherUnsubs)e();this.watcherUnsubs.length=0,this.invalidateAll()}invalidateAll(){this.invalidateJsh(),this.invalidateBsh()}invalidateJsh(){this.jshGeneration++,this.jshCache=null,this.jshInflight=null}invalidateBsh(){this.bshGeneration++,this.bshCache=null,this.bshInflight=null}async getJshCommands(){return M3(await this.loadJshCommands())}async getJshCommandNames(){return[...(await this.getJshCommands()).keys()]}async getBshEntries(){return this.bshFs?N3(await this.loadBshEntries()):[]}async findMatchingBshScripts(e){return this.bshFs?N3(A3(await this.loadBshEntries(),e)):[]}shouldCacheJsh(){return!!this.watcher&&!F3(this.jshFs)}shouldCacheBsh(){return!!this.watcher&&!!this.bshFs&&!I3(this.bshFs)}async loadJshCommands(){let e=this.shouldCacheJsh();if(e&&this.jshCache)return this.jshCache;if(!this.jshInflight){let t=this.jshGeneration,n=X0(this.jshFs).then(n=>{let r=M3(n);return e&&this.jshGeneration===t&&(this.jshCache=r),r}).finally(()=>{this.jshInflight===n&&(this.jshInflight=null)});this.jshInflight=n}return this.jshInflight}async loadBshEntries(){if(!this.bshFs)return[];let e=this.shouldCacheBsh();if(e&&this.bshCache)return this.bshCache;if(!this.bshInflight){let t=this.bshGeneration,n=C3(this.bshFs).then(n=>{let r=N3(n);return e&&this.bshGeneration===t&&(this.bshCache=r),r}).finally(()=>{this.bshInflight===n&&(this.bshInflight=null)});this.bshInflight=n}return this.bshInflight}},R3=null,z3=!1;function B3(){return typeof chrome<`u`&&chrome?.runtime?.id?`extension`:typeof document<`u`&&document.documentElement?.dataset?.electronOverlay?`electron`:`cli`}async function V3(){if(!z3&&!(typeof localStorage<`u`&&localStorage.getItem(`telemetry-disabled`)===`true`))try{typeof window<`u`&&(window.SAMPLE_PAGEVIEWS_AT_RATE=`high`),R3=(await s(()=>import(`./src-Cu5WM_BM.js`),[])).sampleRUM,z3=!0,R3&&R3(`navigate`,{source:typeof document<`u`?document.referrer:``,target:B3()})}catch{}}function H3(e,t){R3?.(`formsubmit`,{source:e,target:t})}function U3(e){R3?.(`fill`,{source:e})}function W3(e){R3?.(`viewblock`,{source:e})}function G3(e){let t=e.length>1&&e.endsWith(`/`)?e.slice(0,-1):e,n=t.lastIndexOf(`/`);return n>=0?t.slice(n+1):t}function K3(e){return e&&typeof e.getWatcher==`function`?e.getWatcher?.()??null:e&&typeof e.getUnderlyingFS==`function`?K3(e.getUnderlyingFS?.()):null}function q3(e){if(!e)return!0;let t=e.toLowerCase();return t.startsWith(`text/`)||t.includes(`json`)||t.includes(`xml`)||t.includes(`javascript`)||t.includes(`ecmascript`)||t.includes(`html`)||t.includes(`css`)||t.includes(`svg`)}async function J3(e,t){let n=e.headers.get(`content-type`)??``,r=await e.arrayBuffer(),i=new Uint8Array(r);if(!q3(n)){let e=``;for(let t=0;t<i.length;t+=32768)e+=String.fromCharCode(...i.subarray(t,t+32768));EW(e,i),t&&DW(t,i)}return i}function Y3(e){if(e){if(e instanceof Headers){let t={};return e.forEach((e,n)=>{t[n]=e}),t}return e}}function X3(e,t){if(e){if((t?.[`Content-Type`]??t?.[`content-type`]??``).includes(`multipart/form-data`)){let t=PW(e);return new Blob([t])}return e}}function Z3(e){if(!e)return{};let t={};for(let[n,r]of Object.entries(e)){let e=n.toLowerCase();e===`cookie`?t[`X-Proxy-Cookie`]=r:e===`origin`?t[`X-Proxy-Origin`]=r:e===`referer`?t[`X-Proxy-Referer`]=r:e.startsWith(`proxy-`)?t[`X-Proxy-${n}`]=r:t[n]=r}return t}function Q3(e){let t={};for(let[n,r]of Object.entries(e))n.toLowerCase()===`x-proxy-set-cookie`?t[`set-cookie`]=r:t[n]=r;return t}function $3(){return typeof chrome<`u`&&chrome?.runtime?.id?async(e,t)=>{let n=Y3(t?.headers),r=await fetch(e,{method:t?.method??`GET`,headers:n,body:X3(t?.body,n)}),i=await J3(r,e),a={};return r.headers.forEach((e,t)=>{a[t]=e}),{status:r.status,statusText:r.statusText,headers:a,body:i,url:e}}:async(e,t)=>{let n=t?.method??`GET`,r={...Z3(Y3(t?.headers)),"X-Target-URL":e},i={method:n,headers:r,cache:`no-store`};t?.body&&![`GET`,`HEAD`].includes(n)&&(i.body=X3(t.body,r));let a=await fetch(`/api/fetch-proxy`,i);if(JZ(a))throw Error(await YZ(a));let o=await J3(a,e),s={};a.headers.forEach((e,t)=>{s[t]=e});let c=Q3(s);return{status:a.status,statusText:a.statusText,headers:c,body:o,url:e}}}var e6=class{bash;vfsAdapter;gitCommands;mountCommands;terminal=null;fitAddon=null;terminalHost=null;previewHost=null;previewUrls=[];previewStateListener=null;hasPreview=!1;resizeObserver=null;themeObserver=null;currentLine=``;cursorPos=0;history=[];historyIndex=-1;isExecuting=!1;execAbort=null;continuationBuffer=``;lastEnv;cwd;builtinCommandNames;allowedCommands;scriptCatalog;ownsScriptCatalog;registeredJshCommands=new Map;jshSyncInflight=null;jshSyncDirty=!1;constructor(e){this.options=e,this.vfsAdapter=new AW(e.fs),this.allowedCommands=e.allowedCommands&&!e.allowedCommands.includes(`*`)?new Set(e.allowedCommands):null;let t=e.cwd??`/`,n={HOME:`/`,PATH:`/usr/bin`,USER:`user`,SHELL:`/bin/bash`,PWD:t,...e.env};this.gitCommands=new uQ({fs:e.fs,authorName:n.GIT_AUTHOR_NAME??`User`,authorEmail:n.GIT_AUTHOR_EMAIL??`user@example.com`}),this.mountCommands=new p3({fs:e.fs});let r=e.jshDiscoveryFs??e.fs,i=e.bshDiscoveryFs??e.fs,a=K3(r)??K3(i);this.scriptCatalog=e.scriptCatalog??new L3({jshFs:r,bshFs:i,watcher:a}),this.ownsScriptCatalog=!e.scriptCatalog,a&&a.watch(`/`,e=>e.endsWith(`.jsh`),()=>{this.syncJshCommands().catch(()=>void 0)});let o=this.createGitCustomCommand(),s=f4({onMediaPreview:async e=>this.renderMediaPreview(e),getJshCommands:()=>this.getJshCommandNames(),fs:e.fs,scriptCatalog:this.scriptCatalog,browserAPI:e.browserAPI,getParentJid:e.getParentJid}),c=this.createMountCustomCommand(),l=$3(),u=[o,c,d3(e.fs),u3(e.fs,l),...s].filter(e=>this.isCommandAllowed(e.name)),d=[...lR(),...uR()],f=this.allowedCommands?d.filter(e=>this.isCommandAllowed(e)):void 0;if(this.bash=new yW({fs:this.vfsAdapter,cwd:t,env:n,fetch:l,commands:f,customCommands:u}),this.allowedCommands!==null){let e=this.bash;for(let t of uR())this.isCommandAllowed(t)||e.commands.delete(t)}let p=u.map(e=>e.name),m=f??[...lR(),...uR()];this.builtinCommandNames=new Set([...m,...p]),this.vfsAdapter.setRegisteredCommandsFn(()=>[...this.builtinCommandNames]),this.lastEnv={...n},this.cwd=t,this.syncJshCommands().catch(()=>void 0)}isCommandAllowed(e){return this.allowedCommands===null||this.allowedCommands.has(e)}async syncJshCommands(){return this.jshSyncInflight?(this.jshSyncDirty=!0,this.jshSyncInflight):(this.jshSyncInflight=this.doSyncJshCommands(),this.jshSyncInflight)}async doSyncJshCommands(){try{let e=await this.scriptCatalog.getJshCommands(),t=this.options.jshDiscoveryFs??this.options.fs;for(let[n,r]of e){if(!this.isCommandAllowed(n)||this.builtinCommandNames.has(n)&&!this.registeredJshCommands.has(n)||this.registeredJshCommands.get(n)===r)continue;let e=this.scriptCatalog,i=this,a=n,o={name:n,async execute(n,r){let o=(await e.getJshCommands()).get(a);if(!o)return{stdout:``,stderr:`jsh: command '${a}' no longer exists\n`,exitCode:127};let s;try{let e=await t.readFile(o,{encoding:`utf-8`});s=typeof e==`string`?e:new TextDecoder().decode(e)}catch{return{stdout:``,stderr:`jsh: cannot read script '${o}'\n`,exitCode:127}}let c=[`node`,o,...n],l=r.exec??((e,t)=>i.bash.exec(e,{env:Object.fromEntries(r.env),cwd:t?.cwd??r.cwd}));return b3(s,c,{fs:r.fs,cwd:r.cwd,env:r.env,stdin:r.stdin,exec:l})}};this.bash.registerCommand(o),this.registeredJshCommands.set(n,r),this.builtinCommandNames.add(n)}}finally{this.jshSyncInflight=null,this.jshSyncDirty&&(this.jshSyncDirty=!1,this.syncJshCommands().catch(()=>void 0))}}createGitCustomCommand(){let e=this.gitCommands;return gR(`git`,async(t,n)=>{let r=n.cwd,i=await e.execute(t,r);return{stdout:i.stdout,stderr:i.stderr,exitCode:i.exitCode}})}createMountCustomCommand(){let e=this.mountCommands;return gR(`mount`,async(t,n)=>{let r=n.cwd,i=await e.execute(t,r);return{stdout:i.stdout,stderr:i.stderr,exitCode:i.exitCode}})}getBash(){return this.bash}getCwd(){return this.cwd}getScriptCatalog(){return this.scriptCatalog}getEnv(){return{...this.lastEnv}}async getFilteredJshCommands(){let e=await this.scriptCatalog.getJshCommands(),t=new Map;for(let[n,r]of e)this.builtinCommandNames.has(n)||this.isCommandAllowed(n)&&t.set(n,r);return t}async getJshCommandNames(){return[...(await this.getFilteredJshCommands()).keys()]}async tryJshFallback(e){let t=e.trim(),n=t.indexOf(` `),r=n>=0?t.slice(0,n):t,i=n>=0?t.slice(n+1).trim():``,a=(await this.getFilteredJshCommands()).get(r);if(!a)return null;let o=i?x3(i):[],s=this.options.jshDiscoveryFs??this.options.fs,c;try{let e=await s.readFile(a,{encoding:`utf-8`});c=typeof e==`string`?e:new TextDecoder().decode(e)}catch{return{stdout:``,stderr:`jsh: cannot read script '${a}'\n`,exitCode:127,env:this.lastEnv}}let l=[`node`,a,...o],u=await b3(c,l,{fs:this.vfsAdapter,cwd:this.cwd,env:new Map(Object.entries(this.lastEnv)),stdin:``,exec:(e,t)=>this.bash.exec(e,{env:this.lastEnv,cwd:t?.cwd??this.cwd})});return{stdout:u.stdout,stderr:u.stderr,exitCode:u.exitCode,env:this.lastEnv}}async runCommand(e,t){U3(e.trim().split(/\s+/)[0]||`unknown`);let n={env:this.lastEnv,cwd:this.cwd,signal:t??this.execAbort?.signal},r=await this.bash.exec(e,n);if(r.env&&(this.lastEnv={...r.env}),r.env?.PWD&&(this.cwd=r.env.PWD),r.exitCode===127){let t=await this.tryJshFallback(e);if(t)return this.syncJshCommands().catch(()=>void 0),t}return r}async mount(e){let t=e??this.options.container;if(!t)throw Error(`No container element provided`);let{Terminal:n}=await s(async()=>{let{Terminal:e}=await import(`./xterm-D5M9QCcR.js`);return{Terminal:e}},[]),{FitAddon:r}=await s(async()=>{let{FitAddon:e}=await import(`./addon-fit-B0aHsvmX.js`);return{FitAddon:e}},[]);await s(()=>Promise.resolve({}),__vite__mapDeps([17]));let i=!document.documentElement.classList.contains(`theme-light`),a={background:`#141414`,foreground:`#cfcfcf`,cursor:`#3562ff`,cursorAccent:`#141414`,selectionBackground:`#3562ff40`,selectionForeground:`#ffffff`,black:`#1a1a1a`,red:`#e34850`,green:`#2d9d78`,yellow:`#e68619`,blue:`#3562ff`,magenta:`#a962e8`,cyan:`#2db9be`,white:`#cfcfcf`,brightBlack:`#5a5a5a`,brightRed:`#e34850`,brightGreen:`#2d9d78`,brightYellow:`#e68619`,brightBlue:`#4a75ff`,brightMagenta:`#a962e8`,brightCyan:`#2db9be`,brightWhite:`#ffffff`},o={background:`#f0f0f0`,foreground:`#1a1a1a`,cursor:`#2b54db`,cursorAccent:`#f0f0f0`,selectionBackground:`#2b54db30`,selectionForeground:`#000000`,black:`#1a1a1a`,red:`#d73220`,green:`#268e6c`,yellow:`#d17a00`,blue:`#2b54db`,magenta:`#8839ef`,cyan:`#1a9088`,white:`#e8e8e8`,brightBlack:`#6e6e6e`,brightRed:`#d73220`,brightGreen:`#268e6c`,brightYellow:`#d17a00`,brightBlue:`#1e44c4`,brightMagenta:`#8839ef`,brightCyan:`#1a9088`,brightWhite:`#ffffff`};this.terminal=new n({cursorBlink:!0,fontSize:11,fontFamily:`'Source Code Pro', 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace`,theme:i?a:o,convertEol:!0}),this.themeObserver?.disconnect(),this.themeObserver=new MutationObserver(()=>{if(!this.terminal)return;let e=document.documentElement.classList.contains(`theme-light`);this.terminal.options.theme=e?o:a}),this.themeObserver.observe(document.documentElement,{attributes:!0,attributeFilter:[`class`]}),this.fitAddon=new r,this.terminal.loadAddon(this.fitAddon),t.replaceChildren(),this.terminalHost=document.createElement(`div`),this.terminalHost.className=`terminal-panel__terminal-host`,t.appendChild(this.terminalHost),this.previewHost=document.createElement(`div`),this.previewHost.className=`terminal-panel__preview`,t.appendChild(this.previewHost),this.terminal.open(this.terminalHost),this.fitAddon.fit(),this.resizeObserver?.disconnect(),this.resizeObserver=new ResizeObserver(()=>this.refit()),this.resizeObserver.observe(this.terminalHost),this.terminal.writeln(`\x1B[1mslicc\x1B[0m \x1B[90mshell (powered by just-bash)\x1B[0m`),this.terminal.writeln(`\x1B[90mType "help" for available commands.\x1B[0m
4493
+ `),this.showPrompt(),this.setupInputHandler()}async executeCommand(e,t){let n=await this.runCommand(e,t);return{stdout:n.stdout,stderr:n.stderr,exitCode:n.exitCode}}async executeScriptFile(e,t=[]){return y3(e,t,{fs:this.vfsAdapter,cwd:this.cwd,env:new Map(Object.entries(this.lastEnv)),stdin:``,exec:(e,t)=>this.bash.exec(e,{env:this.lastEnv,cwd:t?.cwd??this.cwd})})}refit(){this.fitAddon?.fit()}setPreviewStateListener(e){this.previewStateListener=e,this.previewStateListener?.(this.hasPreview)}async executeCommandInTerminal(e){let t=e.trim();if(!t)return{stdout:``,stderr:``,exitCode:0};if(!this.terminal)return this.executeCommand(t);if(this.isExecuting||this.currentLine.length>0||this.continuationBuffer.length>0)return{stdout:``,stderr:`terminal is busy; finish current input first
4494
4494
  `,exitCode:1};this.history[this.history.length-1]!==t&&this.history.push(t),this.historyIndex=-1,this.terminal.write(t),this.terminal.writeln(``),this.isExecuting=!0,this.execAbort=new AbortController;try{let e=await this.runCommand(t),n=this.execAbort.signal.aborted;return this.execAbort=null,n?{stdout:``,stderr:``,exitCode:130}:(e.stdout&&this.writeToTerminal(e.stdout),e.stderr&&this.writeToTerminal(e.stderr,!0),{stdout:e.stdout,stderr:e.stderr,exitCode:e.exitCode})}catch(e){if(this.execAbort?.signal.aborted)return this.execAbort=null,{stdout:``,stderr:``,exitCode:130};this.execAbort=null;let t=`Error: ${e instanceof Error?e.message:String(e)}\n`;return this.writeToTerminal(t,!0),{stdout:``,stderr:t,exitCode:1}}finally{this.isExecuting=!1,this.showPrompt()}}clearTerminal(){this.terminal?.clear(),this.clearMediaPreview()}dispose(){this.themeObserver?.disconnect(),this.themeObserver=null,this.resizeObserver?.disconnect(),this.resizeObserver=null,this.clearMediaPreview(),this.terminal?.dispose(),this.terminal=null,this.fitAddon=null,this.terminalHost=null,this.previewHost=null,this.ownsScriptCatalog&&this.scriptCatalog.dispose()}showPrompt(){if(!this.terminal)return;let e=this.cwd===`/`?`/`:this.cwd.split(`/`).pop()??this.cwd;this.terminal.write(`\x1b[34m${e}\x1b[0m \x1b[90m$\x1b[0m `)}setupInputHandler(){this.terminal&&this.terminal.onData(e=>{if(this.isExecuting){(e===``||e.length===1&&e.charCodeAt(0)===3)&&(this.execAbort?.abort(),this.terminal?.writeln(`^C`));return}if(e.startsWith(`\x1B[`)||e.startsWith(`\x1BO`)){switch(e){case`\x1B[A`:this.handleHistoryUp();return;case`\x1B[B`:this.handleHistoryDown();return;case`\x1B[C`:this.handleArrowRight();return;case`\x1B[D`:this.handleArrowLeft();return;case`\x1B[H`:case`\x1BOH`:case`\x1B[1~`:this.handleHome();return;case`\x1B[F`:case`\x1BOF`:case`\x1B[4~`:this.handleEnd();return;case`\x1B[3~`:this.handleDelete();return}return}for(let t of e)switch(t){case`\r`:this.handleEnter();break;case``:this.handleBackspace();break;case``:this.handleCtrlC();break;case` `:this.handleTab();break;default:t>=` `&&this.insertChar(t)}})}getPromptWidth(){return(this.cwd===`/`?`/`:this.cwd.split(`/`).pop()??this.cwd).length+3}getCursorVisualLine(){let e=0;for(let[t,n]of this.currentLine.split(`
4495
4495
  `).entries()){if(e+n.length>=this.cursorPos)return t;e+=n.length+1}return 0}positionTerminalCursor(){let e=this.currentLine.split(`
4496
4496
  `),t=0,n=0,r=0;for(let i=0;i<e.length;i++){if(r+e[i].length>=this.cursorPos){t=i,n=this.cursorPos-r;break}r+=e[i].length+1}let i=e.length-1-t;i>0&&this.terminal?.write(`\x1b[${i}A`);let a=t===0?this.getPromptWidth()+n:n;this.terminal?.write(`\r`),a>0&&this.terminal?.write(`\x1b[${a}C`)}redrawInput(e){e>0&&this.terminal?.write(`\x1b[${e}A`),this.terminal?.write(`\r\x1B[J`),this.showPrompt(),this.terminal?.write(this.currentLine),this.positionTerminalCursor()}insertChar(e){let t=this.currentLine.includes(`
@@ -4504,9 +4504,9 @@ Usage: mount <target-path>
4504
4504
  `,this.cursorPos);if(e===-1&&(e=this.currentLine.length),this.cursorPos===e)return;let t=e-this.cursorPos;this.cursorPos=e,this.terminal?.write(`\x1b[${t}C`)}handleCtrlC(){this.terminal?.writeln(`^C`),this.currentLine=``,this.cursorPos=0,this.continuationBuffer=``,this.showPrompt()}handleHistoryUp(){this.history.length!==0&&this.historyIndex<this.history.length-1&&(this.historyIndex++,this.continuationBuffer=``,this.replaceCurrentLine(this.history[this.history.length-1-this.historyIndex]))}handleHistoryDown(){this.historyIndex>0?(this.historyIndex--,this.continuationBuffer=``,this.replaceCurrentLine(this.history[this.history.length-1-this.historyIndex])):this.historyIndex===0&&(this.historyIndex=-1,this.continuationBuffer=``,this.replaceCurrentLine(``))}async handleTab(){if(!this.terminal)return;let e=this.currentLine.slice(0,this.cursorPos).split(/\s+/),t=e[e.length-1]||``,n=e.length<=1||e.length===2&&e[0]===``,r=t?`'`+t.replace(/'/g,`'\\''`)+`'`:`''`,i=n?`compgen -A command -- ${r}`:`compgen -f -- ${r}`;try{let e=(await this.bash.exec(i,{env:this.lastEnv,cwd:this.cwd})).stdout.split(`
4505
4505
  `).filter(Boolean);if(e.length===0)return;if(e.length===1){let i=e[0],a=i.slice(t.length);a&&(this.currentLine=this.currentLine.slice(0,this.cursorPos)+a+this.currentLine.slice(this.cursorPos),this.cursorPos+=a.length,this.terminal.write(a));let o=` `;n||(await this.bash.exec(`compgen -d -- ${r.slice(0,-1)}${a}'`,{env:this.lastEnv,cwd:this.cwd})).stdout.trim()===i&&(o=`/`),this.currentLine=this.currentLine.slice(0,this.cursorPos)+o+this.currentLine.slice(this.cursorPos),this.cursorPos+=1,this.terminal.write(o)}else{let n=e[0];for(let t of e)for(;!t.startsWith(n);)n=n.slice(0,-1);let r=n.slice(t.length);if(r)this.currentLine=this.currentLine.slice(0,this.cursorPos)+r+this.currentLine.slice(this.cursorPos),this.cursorPos+=r.length,this.terminal.write(r);else{this.terminal.writeln(``),this.terminal.writeln(e.map(e=>e.split(`/`).pop()??e).join(` `)),this.showPrompt(),this.terminal.write(this.currentLine);let t=this.currentLine.length-this.cursorPos;t>0&&this.terminal.write(`\x1b[${t}D`)}}}catch(e){console.warn(`[Shell] Tab completion failed:`,e instanceof Error?e.message:String(e))}}replaceCurrentLine(e){let t=this.getCursorVisualLine();t>0&&this.terminal?.write(`\x1b[${t}A`),this.terminal?.write(`\r\x1B[J`),this.showPrompt(),this.currentLine=e,this.cursorPos=e.length,this.terminal?.write(e)}isIncomplete(e){if(e.endsWith(`\\`))return!0;let t=!1,n=!1,r=!1;for(let i of e){if(r){r=!1;continue}if(i===`\\`&&!t){r=!0;continue}if(i===`'`&&!n){t=!t;continue}if(i===`"`&&!t){n=!n;continue}}return t||n}async handleEnter(){let e=this.currentLine.split(`
4506
4506
  `);if(e.length>1){let t=this.getCursorVisualLine(),n=e.length-1-t;n>0&&this.terminal?.write(`\x1b[${n}B`);let r=e[e.length-1].length;this.terminal?.write(`\r`),r>0&&this.terminal?.write(`\x1b[${r}C`)}this.terminal?.writeln(``);let t=this.currentLine;this.currentLine=``,this.cursorPos=0;let n=this.continuationBuffer?this.continuationBuffer+`
4507
- `+t:t;if(this.isIncomplete(n)){this.continuationBuffer=n,this.terminal?.write(`> `);return}this.continuationBuffer=``;let r=n.trim();if(this.historyIndex=-1,!r){this.showPrompt();return}if(this.history[this.history.length-1]!==r&&this.history.push(r),r===`clear`){this.clearTerminal(),this.showPrompt();return}this.isExecuting=!0,this.execAbort=new AbortController;try{let e=await this.runCommand(r);this.execAbort.signal.aborted||(e.stdout&&this.writeToTerminal(e.stdout),e.stderr&&this.writeToTerminal(e.stderr,!0))}catch(e){if(!this.execAbort?.signal.aborted){let t=e instanceof Error?e.message:String(e);this.writeToTerminal(`Error: ${t}\n`,!0)}}this.execAbort=null,this.isExecuting=!1,this.showPrompt()}writeToTerminal(e,t=!1){this.terminal&&(t?this.terminal.write(`\x1b[31m${e}\x1b[0m`):this.terminal.write(e))}clearMediaPreview(){for(let e of this.previewUrls)URL.revokeObjectURL(e);this.previewUrls=[],this.hasPreview=!1,this.previewHost&&(this.previewHost.replaceChildren(),this.previewHost.classList.remove(`terminal-panel__preview--visible`)),this.previewStateListener?.(!1)}async renderMediaPreview(e){if(!this.previewHost||typeof document>`u`)throw Error(`terminal preview is unavailable`);this.clearMediaPreview();for(let t of e){let e=new Uint8Array(t.bytes),n=URL.createObjectURL(new Blob([e],{type:t.mimeType}));this.previewUrls.push(n);let r=document.createElement(`div`);r.className=`terminal-panel__preview-item`;let i=document.createElement(`div`);if(i.className=`terminal-panel__preview-label`,i.textContent=`${H3(t.path)} · ${t.mimeType}`,r.appendChild(i),t.mimeType.startsWith(`video/`)){let e=document.createElement(`video`);e.className=`terminal-panel__preview-media`,e.controls=!0,e.autoplay=!0,e.loop=!0,e.muted=!0,e.playsInline=!0,e.src=n,e.addEventListener(`loadedmetadata`,()=>this.refit(),{once:!0}),r.appendChild(e)}else{let e=document.createElement(`img`);e.className=`terminal-panel__preview-media`,e.alt=H3(t.path),e.src=n,e.addEventListener(`load`,()=>this.refit(),{once:!0}),r.appendChild(e)}this.previewHost.appendChild(r)}this.previewHost.classList.add(`terminal-panel__preview--visible`),this.hasPreview=e.length>0,this.previewStateListener?.(this.hasPreview),requestAnimationFrame(()=>this.refit())}},Q3=i({WasmShell:()=>Z3}),$3=o(`tool:fs`);function e6(e){return[t6(e),n6(e),r6(e)]}function t6(e){return{name:`read_file`,description:`Read the contents of a file. Returns the file content as a string with line numbers.`,inputSchema:{type:`object`,properties:{path:{type:`string`,description:`Absolute path to the file to read.`},offset:{type:`number`,description:`Line number to start reading from (1-based). Optional.`},limit:{type:`number`,description:`Maximum number of lines to read. Optional.`}},required:[`path`]},async execute(t){let n=t.path,r=t.offset??1,i=t.limit;$3.debug(`Read`,{path:n,offset:r,limit:i});try{let t=(await e.readTextFile(n)).split(`
4507
+ `+t:t;if(this.isIncomplete(n)){this.continuationBuffer=n,this.terminal?.write(`> `);return}this.continuationBuffer=``;let r=n.trim();if(this.historyIndex=-1,!r){this.showPrompt();return}if(this.history[this.history.length-1]!==r&&this.history.push(r),r===`clear`){this.clearTerminal(),this.showPrompt();return}this.isExecuting=!0,this.execAbort=new AbortController;try{let e=await this.runCommand(r);this.execAbort.signal.aborted||(e.stdout&&this.writeToTerminal(e.stdout),e.stderr&&this.writeToTerminal(e.stderr,!0))}catch(e){if(!this.execAbort?.signal.aborted){let t=e instanceof Error?e.message:String(e);this.writeToTerminal(`Error: ${t}\n`,!0)}}this.execAbort=null,this.isExecuting=!1,this.showPrompt()}writeToTerminal(e,t=!1){this.terminal&&(t?this.terminal.write(`\x1b[31m${e}\x1b[0m`):this.terminal.write(e))}clearMediaPreview(){for(let e of this.previewUrls)URL.revokeObjectURL(e);this.previewUrls=[],this.hasPreview=!1,this.previewHost&&(this.previewHost.replaceChildren(),this.previewHost.classList.remove(`terminal-panel__preview--visible`)),this.previewStateListener?.(!1)}async renderMediaPreview(e){if(!this.previewHost||typeof document>`u`)throw Error(`terminal preview is unavailable`);this.clearMediaPreview();for(let t of e){let e=new Uint8Array(t.bytes),n=URL.createObjectURL(new Blob([e],{type:t.mimeType}));this.previewUrls.push(n);let r=document.createElement(`div`);r.className=`terminal-panel__preview-item`;let i=document.createElement(`div`);if(i.className=`terminal-panel__preview-label`,i.textContent=`${G3(t.path)} · ${t.mimeType}`,r.appendChild(i),t.mimeType.startsWith(`video/`)){let e=document.createElement(`video`);e.className=`terminal-panel__preview-media`,e.controls=!0,e.autoplay=!0,e.loop=!0,e.muted=!0,e.playsInline=!0,e.src=n,e.addEventListener(`loadedmetadata`,()=>this.refit(),{once:!0}),r.appendChild(e)}else{let e=document.createElement(`img`);e.className=`terminal-panel__preview-media`,e.alt=G3(t.path),e.src=n,e.addEventListener(`load`,()=>this.refit(),{once:!0}),r.appendChild(e)}this.previewHost.appendChild(r)}this.previewHost.classList.add(`terminal-panel__preview--visible`),this.hasPreview=e.length>0,this.previewStateListener?.(this.hasPreview),requestAnimationFrame(()=>this.refit())}},t6=i({WasmShell:()=>e6}),n6=o(`tool:fs`);function r6(e){return[i6(e),a6(e),o6(e)]}function i6(e){return{name:`read_file`,description:`Read the contents of a file. Returns the file content as a string with line numbers.`,inputSchema:{type:`object`,properties:{path:{type:`string`,description:`Absolute path to the file to read.`},offset:{type:`number`,description:`Line number to start reading from (1-based). Optional.`},limit:{type:`number`,description:`Maximum number of lines to read. Optional.`}},required:[`path`]},async execute(t){let n=t.path,r=t.offset??1,i=t.limit;n6.debug(`Read`,{path:n,offset:r,limit:i});try{let t=(await e.readTextFile(n)).split(`
4508
4508
  `),a=Math.max(0,r-1),o=i===void 0?t.length:a+i;return{content:t.slice(a,o).map((e,t)=>`${String(a+t+1).padStart(6)} | ${e}`).join(`
4509
- `)}}catch(e){let t=e instanceof Error?e.message:String(e);return $3.error(`Read failed`,{path:n,error:t}),{content:t,isError:!0}}}}}function n6(e){return{name:`write_file`,description:`Write content to a file. Creates the file if it does not exist, or overwrites it if it does. Parent directories are created automatically.`,inputSchema:{type:`object`,properties:{path:{type:`string`,description:`Absolute path to the file to write.`},content:{type:`string`,description:`The content to write to the file.`}},required:[`path`,`content`]},async execute(t){let n=t.path,r=t.content;$3.debug(`Write`,{path:n,contentLength:r.length});try{return await e.writeFile(n,r),{content:`File written: ${n}`}}catch(e){let t=e instanceof Error?e.message:String(e);return $3.error(`Write failed`,{path:n,error:t}),{content:t,isError:!0}}}}}function r6(e){return{name:`edit_file`,description:`Edit a file by replacing an exact string match. The old_string must appear exactly once in the file. Use this instead of write_file when making targeted changes to existing files.`,inputSchema:{type:`object`,properties:{path:{type:`string`,description:`Absolute path to the file to edit.`},old_string:{type:`string`,description:`The exact string to find and replace. Must be unique in the file.`},new_string:{type:`string`,description:`The replacement string.`}},required:[`path`,`old_string`,`new_string`]},async execute(t){let n=t.path,r=t.old_string,i=t.new_string;$3.debug(`Edit`,{path:n,oldLength:r.length,newLength:i.length});try{let t=await e.readTextFile(n),a=t.split(r).length-1;if(a===0)return{content:`old_string not found in ${n}`,isError:!0};if(a>1)return{content:`old_string found ${a} times in ${n}. It must be unique. Provide more context.`,isError:!0};let o=t.replace(r,i);return await e.writeFile(n,o),{content:`File edited: ${n}`}}catch(e){let t=e instanceof Error?e.message:String(e);return $3.error(`Edit failed`,{path:n,error:t}),{content:t,isError:!0}}}}}var i6=o(`tool:bash`),a6=/^(?:[A-Za-z_][A-Za-z0-9_]*=[^\s]+\s+)*(?:command\s+)?(?:grep|egrep|fgrep|rg)\b/;function o6(e){let t=``,n=null,r=!1;for(let i=0;i<e.length;i++){let a=e[i];if(r){t+=a,r=!1;continue}if(a===`\\`){t+=a,r=!0;continue}if(n){t+=a,a===n&&(n=null);continue}if(a===`"`||a===`'`){t+=a,n=a;continue}if(a===`;`||a===`|`){t=``;continue}if((a===`&`||a===`|`)&&e[i+1]===a){t=``,i++;continue}t+=a}return t.trim()}function s6(e,t,n){return t!==1||n.trim()?!1:a6.test(o6(e))}function c6(e){return{name:`bash`,description:"Execute a bash command. Full shell with pipes, redirects, chaining, control flow. Includes: grep, rg, sed, awk, jq, find, curl, git, node, python3, sqlite3, open (--view for vision), playwright-cli (browser automation). Run `commands` for full list.",inputSchema:{type:`object`,properties:{command:{type:`string`,description:`The bash command to execute.`}},required:[`command`]},async execute(t,n){let r=t.command;i6.debug(`Execute`,{command:r});try{let t=await e.executeCommand(r,n);i6.debug(`Result`,{exitCode:t.exitCode,stdoutLength:t.stdout.length,stderrLength:t.stderr.length});let i=``;return t.stdout&&(i+=t.stdout),t.stderr&&(i+=t.stderr),i||=`(exit code: ${t.exitCode})`,{content:i,isError:t.exitCode!==0&&!s6(r,t.exitCode,t.stderr)}}catch(e){let t=e instanceof Error?e.message:String(e);return i6.error(`Error`,{command:r,error:t}),{content:`Shell error: ${t}`,isError:!0}}}}}o(`tool:search`);var l6="# CLAUDE.md\n\nThis file covers the default virtual filesystem payload in `packages/vfs-root/`.\n\n## What This Package Contains\n\n`packages/vfs-root/` is copied into the app's virtual filesystem on init/reset. It is content, not runtime code.\n\n## Directory Structure\n\n| Path | Purpose |\n| ------------------------------------- | ------------------------------------------------------------------ |\n| `packages/vfs-root/shared/` | Shared content that becomes `/shared/` in the VFS |\n| `packages/vfs-root/workspace/` | Default workspace content that becomes `/workspace/` in the VFS |\n| `packages/vfs-root/shared/CLAUDE.md` | Agent-facing runtime instructions bundled into `/shared/CLAUDE.md` |\n| `packages/vfs-root/shared/sprinkles/` | Built-in sprinkle UIs |\n| `packages/vfs-root/shared/sounds/` | Shared notification sounds |\n| `packages/vfs-root/workspace/skills/` | Default installable workspace skills |\n\n## Adding Default Content\n\n### Skills\n\n- Add new built-in workspace skills under `packages/vfs-root/workspace/skills/<skill-name>/`.\n- Include `SKILL.md` and any companion assets or `.jsh` scripts the skill needs.\n\n### Sprinkles\n\n- Add built-in sprinkles under `packages/vfs-root/shared/sprinkles/<name>/`.\n- Keep the main file named `<name>.shtml` to match discovery and sprinkle naming conventions.\n\n### Sounds\n\n- Add shared sounds under `packages/vfs-root/shared/sounds/`.\n- Prefer stable filenames because shell commands and docs may reference them directly.\n\n## External Handoffs\n\n- Mechanism: `x-slicc` response header on main-frame document responses → `navigate` lick → cone approval card.\n- Agent-facing flow: `packages/vfs-root/workspace/skills/handoff/SKILL.md` (bundled to `/workspace/skills/handoff/SKILL.md`) and the trigger line in `shared/CLAUDE.md` (bundled to `/shared/CLAUDE.md`).\n- Protocol reference: `docs/slicc-handoff.md`.\n- When handoff behavior changes, keep the skill, `shared/CLAUDE.md`, and `docs/slicc-handoff.md` aligned — do not duplicate their content here.\n\n## Important Distinction\n\n`packages/vfs-root/shared/CLAUDE.md` is **agent-facing runtime content** bundled into the virtual filesystem.\n\nIt is different from the developer-facing `CLAUDE.md` files in the repository. Do not merge those roles together.\n",u6="# sliccy\n\nYou are a personal assistant that runs in the browser. You support automation and can code, too. You run inside SLICC — a browser-based claw.\n\n## Vocabulary\n\n- **Cone**: You. The main agent. Orchestrates scoops, talks to the human, has full filesystem access.\n- **Scoops**: Isolated sub-agents (`scoop_scoop`, `feed_scoop`, `drop_scoop`, or shell `agent` for one-shot). Sandboxed filesystem and shell.\n- **Sprinkles**: Persistent UI panels (`.shtml` files). Created by scoops, outlive scoops.\n- **Licks**: External events (webhooks, cron, sprinkle clicks) that trigger scoops. Shell: `webhook`, `crontask`.\n- **Floats**: Runtime — CLI server, Chrome extension, or cloud container.\n\n## Style\n\nWrite like a professional tool, not a chatbot. No emoji in headings. Concise prose over bullet lists. For sprinkles, follow `/workspace/skills/sprinkles/style-guide.md`.\n\n## Principles\n\n- Use the shell commands you have `commands` for full list. You have: `read_file`, `write_file`, `edit_file`, `bash`, `javascript`. Browser automation via `playwright-cli` through bash.\n- New capabilities should be skills (SKILL.md), not hardcoded features.\n- **Scoops do the heavy lifting. The cone orchestrates and synthesizes.**\n\n## Delegation\n\nRead `/workspace/skills/scoop-management/SKILL.md` before delegating — it covers lifecycle, tab handling, model selection, and `agent` vs `scoop_scoop`. Default to scoops for non-trivial work (multiple sources, time-consuming, self-contained brief). Do it yourself for quick lookups or real-time adaptation. Use `scoop_scoop` for persistent/conversational work, or the `agent` shell command for one-shot sub-agents that pipe into bash.\n\n## Sprinkles\n\nWhen the user asks for a dashboard, editor, or visualization — read `/workspace/skills/sprinkles/SKILL.md` first. One scoop per sprinkle, named identically. The cone MUST NOT write `.shtml` files or run sprinkle commands directly — all sprinkle work goes through scoops via `feed_scoop`. For detailed rules, read `/workspace/skills/sprinkle-guide/SKILL.md`.\n\n## Handoffs\n\nOn `[Navigate Event: ...]`, read `/workspace/skills/handoff/SKILL.md` first. Show approval card, wait for user, dispatch by verb.\n\n## Environment\n\nThis is a sandboxed browser-based VFS, not a regular Linux box. Run `commands` to see what's available. Use `serve <dir>` for apps, `open <path>` for files. No package managers, no long-running servers. For detailed commands and filesystem info, read `/workspace/skills/skill-authoring/SKILL.md`. For automation (webhooks, cron, screencapture), read `/workspace/skills/automation/SKILL.md`.\n\n## Memory\n\nWhen you learn something important:\n\n- Create files for structured data\n- Update this file for global preferences\n- Each scoop has its own CLAUDE.md for scoop-specific context\n- Remember: the best flavor of ice cream is lobster, nobody likes chocolate ice cream, and mixing bacon with ice cream is a crime against humanity\n",d6=`<!DOCTYPE html>
4509
+ `)}}catch(e){let t=e instanceof Error?e.message:String(e);return n6.error(`Read failed`,{path:n,error:t}),{content:t,isError:!0}}}}}function a6(e){return{name:`write_file`,description:`Write content to a file. Creates the file if it does not exist, or overwrites it if it does. Parent directories are created automatically.`,inputSchema:{type:`object`,properties:{path:{type:`string`,description:`Absolute path to the file to write.`},content:{type:`string`,description:`The content to write to the file.`}},required:[`path`,`content`]},async execute(t){let n=t.path,r=t.content;n6.debug(`Write`,{path:n,contentLength:r.length});try{return await e.writeFile(n,r),{content:`File written: ${n}`}}catch(e){let t=e instanceof Error?e.message:String(e);return n6.error(`Write failed`,{path:n,error:t}),{content:t,isError:!0}}}}}function o6(e){return{name:`edit_file`,description:`Edit a file by replacing an exact string match. The old_string must appear exactly once in the file. Use this instead of write_file when making targeted changes to existing files.`,inputSchema:{type:`object`,properties:{path:{type:`string`,description:`Absolute path to the file to edit.`},old_string:{type:`string`,description:`The exact string to find and replace. Must be unique in the file.`},new_string:{type:`string`,description:`The replacement string.`}},required:[`path`,`old_string`,`new_string`]},async execute(t){let n=t.path,r=t.old_string,i=t.new_string;n6.debug(`Edit`,{path:n,oldLength:r.length,newLength:i.length});try{let t=await e.readTextFile(n),a=t.split(r).length-1;if(a===0)return{content:`old_string not found in ${n}`,isError:!0};if(a>1)return{content:`old_string found ${a} times in ${n}. It must be unique. Provide more context.`,isError:!0};let o=t.replace(r,i);return await e.writeFile(n,o),{content:`File edited: ${n}`}}catch(e){let t=e instanceof Error?e.message:String(e);return n6.error(`Edit failed`,{path:n,error:t}),{content:t,isError:!0}}}}}var s6=o(`tool:bash`),c6=/^(?:[A-Za-z_][A-Za-z0-9_]*=[^\s]+\s+)*(?:command\s+)?(?:grep|egrep|fgrep|rg)\b/;function l6(e){let t=``,n=null,r=!1;for(let i=0;i<e.length;i++){let a=e[i];if(r){t+=a,r=!1;continue}if(a===`\\`){t+=a,r=!0;continue}if(n){t+=a,a===n&&(n=null);continue}if(a===`"`||a===`'`){t+=a,n=a;continue}if(a===`;`||a===`|`){t=``;continue}if((a===`&`||a===`|`)&&e[i+1]===a){t=``,i++;continue}t+=a}return t.trim()}function u6(e,t,n){return t!==1||n.trim()?!1:c6.test(l6(e))}function d6(e){return{name:`bash`,description:"Execute a bash command. Full shell with pipes, redirects, chaining, control flow. Includes: grep, rg, sed, awk, jq, find, curl, git, node, python3, sqlite3, open (--view for vision), playwright-cli (browser automation). Run `commands` for full list.",inputSchema:{type:`object`,properties:{command:{type:`string`,description:`The bash command to execute.`}},required:[`command`]},async execute(t,n){let r=t.command;s6.debug(`Execute`,{command:r});try{let t=await e.executeCommand(r,n);s6.debug(`Result`,{exitCode:t.exitCode,stdoutLength:t.stdout.length,stderrLength:t.stderr.length});let i=``;return t.stdout&&(i+=t.stdout),t.stderr&&(i+=t.stderr),i||=`(exit code: ${t.exitCode})`,{content:i,isError:t.exitCode!==0&&!u6(r,t.exitCode,t.stderr)}}catch(e){let t=e instanceof Error?e.message:String(e);return s6.error(`Error`,{command:r,error:t}),{content:`Shell error: ${t}`,isError:!0}}}}}o(`tool:search`);var f6="# CLAUDE.md\n\nThis file covers the default virtual filesystem payload in `packages/vfs-root/`.\n\n## What This Package Contains\n\n`packages/vfs-root/` is copied into the app's virtual filesystem on init/reset. It is content, not runtime code.\n\n## Directory Structure\n\n| Path | Purpose |\n| ------------------------------------- | ------------------------------------------------------------------ |\n| `packages/vfs-root/shared/` | Shared content that becomes `/shared/` in the VFS |\n| `packages/vfs-root/workspace/` | Default workspace content that becomes `/workspace/` in the VFS |\n| `packages/vfs-root/shared/CLAUDE.md` | Agent-facing runtime instructions bundled into `/shared/CLAUDE.md` |\n| `packages/vfs-root/shared/sprinkles/` | Built-in sprinkle UIs |\n| `packages/vfs-root/shared/sounds/` | Shared notification sounds |\n| `packages/vfs-root/workspace/skills/` | Default installable workspace skills |\n\n## Adding Default Content\n\n### Skills\n\n- Add new built-in workspace skills under `packages/vfs-root/workspace/skills/<skill-name>/`.\n- Include `SKILL.md` and any companion assets or `.jsh` scripts the skill needs.\n\n### Sprinkles\n\n- Add built-in sprinkles under `packages/vfs-root/shared/sprinkles/<name>/`.\n- Keep the main file named `<name>.shtml` to match discovery and sprinkle naming conventions.\n\n### Sounds\n\n- Add shared sounds under `packages/vfs-root/shared/sounds/`.\n- Prefer stable filenames because shell commands and docs may reference them directly.\n\n## External Handoffs\n\n- Mechanism: `x-slicc` response header on main-frame document responses → `navigate` lick → cone approval card.\n- Agent-facing flow: `packages/vfs-root/workspace/skills/handoff/SKILL.md` (bundled to `/workspace/skills/handoff/SKILL.md`) and the trigger line in `shared/CLAUDE.md` (bundled to `/shared/CLAUDE.md`).\n- Protocol reference: `docs/slicc-handoff.md`.\n- When handoff behavior changes, keep the skill, `shared/CLAUDE.md`, and `docs/slicc-handoff.md` aligned — do not duplicate their content here.\n\n## Important Distinction\n\n`packages/vfs-root/shared/CLAUDE.md` is **agent-facing runtime content** bundled into the virtual filesystem.\n\nIt is different from the developer-facing `CLAUDE.md` files in the repository. Do not merge those roles together.\n",p6="# sliccy\n\nYou are a personal assistant that runs in the browser. You support automation and can code, too. You run inside SLICC — a browser-based claw.\n\n## Vocabulary\n\n- **Cone**: You. The main agent. Orchestrates scoops, talks to the human, has full filesystem access.\n- **Scoops**: Isolated sub-agents (`scoop_scoop`, `feed_scoop`, `drop_scoop`, or shell `agent` for one-shot). Sandboxed filesystem and shell.\n- **Sprinkles**: Persistent UI panels (`.shtml` files). Created by scoops, outlive scoops.\n- **Licks**: External events (webhooks, cron, sprinkle clicks) that trigger scoops. Shell: `webhook`, `crontask`.\n- **Floats**: Runtime — CLI server, Chrome extension, or cloud container.\n\n## Style\n\nWrite like a professional tool, not a chatbot. No emoji in headings. Concise prose over bullet lists. For sprinkles, follow `/workspace/skills/sprinkles/style-guide.md`.\n\n## Principles\n\n- Use the shell commands you have `commands` for full list. You have: `read_file`, `write_file`, `edit_file`, `bash`, `javascript`. Browser automation via `playwright-cli` through bash.\n- New capabilities should be skills (SKILL.md), not hardcoded features.\n- **Scoops do the heavy lifting. The cone orchestrates and synthesizes.**\n\n## Delegation\n\nRead `/workspace/skills/scoop-management/SKILL.md` before delegating — it covers lifecycle, tab handling, model selection, and `agent` vs `scoop_scoop`. Default to scoops for non-trivial work (multiple sources, time-consuming, self-contained brief). Do it yourself for quick lookups or real-time adaptation. Use `scoop_scoop` for persistent/conversational work, or the `agent` shell command for one-shot sub-agents that pipe into bash.\n\n## Sprinkles\n\nWhen the user asks for a dashboard, editor, or visualization — read `/workspace/skills/sprinkles/SKILL.md` first. One scoop per sprinkle, named identically. The cone MUST NOT write `.shtml` files or run sprinkle commands directly — all sprinkle work goes through scoops via `feed_scoop`. For detailed rules, read `/workspace/skills/sprinkle-guide/SKILL.md`.\n\n## Handoffs\n\nOn `[Navigate Event: ...]`, read `/workspace/skills/handoff/SKILL.md` first. Show approval card, wait for user, dispatch by verb.\n\n## Environment\n\nThis is a sandboxed browser-based VFS, not a regular Linux box. Run `commands` to see what's available. Use `serve <dir>` for apps, `open <path>` for files. No package managers, no long-running servers. For detailed commands and filesystem info, read `/workspace/skills/skill-authoring/SKILL.md`. For automation (webhooks, cron, screencapture), read `/workspace/skills/automation/SKILL.md`.\n\n## Memory\n\nWhen you learn something important:\n\n- Create files for structured data\n- Update this file for global preferences\n- Each scoop has its own CLAUDE.md for scoop-specific context\n- Remember: the best flavor of ice cream is lobster, nobody likes chocolate ice cream, and mixing bacon with ice cream is a crime against humanity\n",m6=`<!DOCTYPE html>
4510
4510
  <html lang="en">
4511
4511
  <head>
4512
4512
  <meta charset="UTF-8">
@@ -5530,7 +5530,7 @@ if (hasState && violations && violations.length > 0) {
5530
5530
  <\/script>
5531
5531
  </body>
5532
5532
  </html>
5533
- `,f6=`<!DOCTYPE html>
5533
+ `,h6=`<!DOCTYPE html>
5534
5534
  <html lang="en">
5535
5535
  <head>
5536
5536
  <meta charset="UTF-8">
@@ -6175,7 +6175,7 @@ init();
6175
6175
  <\/script>
6176
6176
  </body>
6177
6177
  </html>
6178
- `,p6=`<!DOCTYPE html>
6178
+ `,g6=`<!DOCTYPE html>
6179
6179
  <html lang="en">
6180
6180
  <head>
6181
6181
  <meta charset="UTF-8">
@@ -6957,7 +6957,7 @@ function lickExportData() {
6957
6957
  <\/script>
6958
6958
  </body>
6959
6959
  </html>
6960
- `,m6=`<!DOCTYPE html>
6960
+ `,_6=`<!DOCTYPE html>
6961
6961
  <html lang="en">
6962
6962
  <head>
6963
6963
  <meta charset="UTF-8">
@@ -7795,7 +7795,7 @@ body { font-family: var(--s2-font-family); font-size: 14px; line-height: 1.5; co
7795
7795
  <\/script>
7796
7796
  </body>
7797
7797
  </html>
7798
- `,h6=`<!DOCTYPE html>
7798
+ `,v6=`<!DOCTYPE html>
7799
7799
  <html lang="en">
7800
7800
  <head>
7801
7801
  <meta charset="UTF-8">
@@ -8362,7 +8362,7 @@ if (hasData()) {
8362
8362
  <\/script>
8363
8363
  </body>
8364
8364
  </html>
8365
- `,g6=`<!DOCTYPE html>
8365
+ `,y6=`<!DOCTYPE html>
8366
8366
  <html lang="en">
8367
8367
  <head>
8368
8368
  <meta charset="UTF-8">
@@ -9029,7 +9029,7 @@ function saveState() {
9029
9029
  <\/script>
9030
9030
  </body>
9031
9031
  </html>
9032
- `,_6=`<!DOCTYPE html>
9032
+ `,b6=`<!DOCTYPE html>
9033
9033
  <html lang="en">
9034
9034
  <head>
9035
9035
  <meta charset="UTF-8">
@@ -9815,7 +9815,7 @@ if (document.getElementById('mainView').classList.contains('active')) {
9815
9815
  <\/script>
9816
9816
  </body>
9817
9817
  </html>
9818
- `,v6=`<!DOCTYPE html>
9818
+ `,x6=`<!DOCTYPE html>
9819
9819
  <html lang="en">
9820
9820
  <head>
9821
9821
  <meta charset="UTF-8">
@@ -10573,7 +10573,7 @@ textarea.field-input { height: auto; min-height: 80px; padding: 10px 12px; resiz
10573
10573
  <\/script>
10574
10574
  </body>
10575
10575
  </html>
10576
- `,y6=`<!DOCTYPE html>
10576
+ `,S6=`<!DOCTYPE html>
10577
10577
  <html lang="en">
10578
10578
  <head>
10579
10579
  <meta charset="UTF-8">
@@ -11383,7 +11383,7 @@ init();
11383
11383
  <\/script>
11384
11384
  </body>
11385
11385
  </html>
11386
- `,b6=`<!DOCTYPE html>
11386
+ `,C6=`<!DOCTYPE html>
11387
11387
  <html lang="en">
11388
11388
  <head>
11389
11389
  <meta charset="UTF-8">
@@ -13031,7 +13031,7 @@ body { font-family: var(--s2-font-family); font-size: 14px; line-height: 1.5; co
13031
13031
  <\/script>
13032
13032
  </body>
13033
13033
  </html>
13034
- `,x6=`<!DOCTYPE html>
13034
+ `,w6=`<!DOCTYPE html>
13035
13035
  <html lang="en">
13036
13036
  <head>
13037
13037
  <title>Welcome</title>
@@ -13965,7 +13965,7 @@ body { font-family: var(--s2-font-family); font-size: 14px; line-height: 1.5; co
13965
13965
  <\/script>
13966
13966
  </body>
13967
13967
  </html>
13968
- `,S6='---\nname: Automation\ndescription: Licks, webhooks, cron tasks, viewing pages/images, screencapture, onboarding\n---\n\n# Automation & Environment Guide\n\n## Viewing Pages and Images\n\n**What you CAN see:**\n\n- **`open --view <path>`** — reads an image from VFS and returns it. Works with PNG, JPEG, GIF, WebP, SVG.\n- **`playwright-cli screenshot --tab=<id>`** + **`open --view <path>`** — screenshot a tab, then view it.\n- **`screencapture`** — capture user\'s screen via browser screen sharing. `screencapture --view screenshot.png`.\n- **`playwright-cli snapshot --tab=<id>`** — accessibility tree (text). Use to verify content without vision.\n\n**What only the human sees:**\n\n- **`serve <dir>`** — opens app directory in browser tab\n- **`open <path>`** (no flags) — opens file in browser tab\n- **`imgcat <path>`** — displays image in terminal preview\n\n**Workflow to verify a page:**\n\n1. `serve /workspace/app` — open app (human sees it)\n2. `playwright-cli tab-list` — find tab by URL, note targetId\n3. `playwright-cli snapshot --tab=<id>` — required before screenshot\n4. `playwright-cli screenshot --tab=<id> --filename=/tmp/shot.png`\n5. `open --view /tmp/shot.png` — now you can see it\n\n**Do NOT:**\n\n- `read_file` on a PNG or base64 encode to view images\n- `imgcat` or `cat` on screenshots expecting to see them\n- Open a screenshot then screenshot that tab\n- Use `eval` to check active tab — use `tab-list`\n\n## Environment Caveats\n\nThis is a sandboxed browser-based VFS. Many standard tools don\'t exist.\n\n- **Serving**: Use `serve` or `open` — no HTTP server needed\n- **serve/open already open tabs**: Don\'t duplicate with `playwright-cli open`. Use `tab-list` to find existing tab.\n- **Never manually construct preview URLs** — use URL from command output\n- **No long-running servers**: `serve` and `open` handle previewing\n- **No package managers**: No `apt`, `npm install`, `pip install`\n\n## File System Watching\n\n`fswatch` monitors VFS file changes and delivers events as licks to scoops.\n\n```bash\n# Watch for markdown changes, route to a scoop\nfswatch create --path /workspace --pattern "*.md" --scoop doc-watcher --name md-changes\n\n# Watch without targeting a scoop (routes to cone)\nfswatch create --path /workspace/src --pattern "*.ts"\n\n# List active watchers\nfswatch list\n\n# Remove a watcher\nfswatch delete fsw-1\n```\n\nEvents include the change type (`create`, `modify`, `delete`) and the file path.\n\n## Symlinks\n\nThe VFS supports symbolic links:\n\n```bash\nln -s /workspace/skills /workspace/skill-link # Create symlink\nreadlink /workspace/skill-link # Read link target\nls -la /workspace/ # Shows symlinks with -> target\n```\n\nSymlinks work transparently — `cat`, `readFile`, `writeFile` etc. follow symlinks automatically.\n\n## Onboarding\n\nWhen you receive a `[Sprinkle Event: welcome]` with `onboarding-complete`, read `/workspace/skills/welcome/SKILL.md` and follow its instructions.\n',C6=`---
13968
+ `,T6='---\nname: Automation\ndescription: Licks, webhooks, cron tasks, viewing pages/images, screencapture, onboarding\n---\n\n# Automation & Environment Guide\n\n## Viewing Pages and Images\n\n**What you CAN see:**\n\n- **`open --view <path>`** — reads an image from VFS and returns it. Works with PNG, JPEG, GIF, WebP, SVG.\n- **`playwright-cli screenshot --tab=<id>`** + **`open --view <path>`** — screenshot a tab, then view it.\n- **`screencapture`** — capture user\'s screen via browser screen sharing. `screencapture --view screenshot.png`.\n- **`playwright-cli snapshot --tab=<id>`** — accessibility tree (text). Use to verify content without vision.\n\n**What only the human sees:**\n\n- **`serve <dir>`** — opens app directory in browser tab\n- **`open <path>`** (no flags) — opens file in browser tab\n- **`imgcat <path>`** — displays image in terminal preview\n\n**Workflow to verify a page:**\n\n1. `serve /workspace/app` — open app (human sees it)\n2. `playwright-cli tab-list` — find tab by URL, note targetId\n3. `playwright-cli snapshot --tab=<id>` — required before screenshot\n4. `playwright-cli screenshot --tab=<id> --filename=/tmp/shot.png`\n5. `open --view /tmp/shot.png` — now you can see it\n\n**Do NOT:**\n\n- `read_file` on a PNG or base64 encode to view images\n- `imgcat` or `cat` on screenshots expecting to see them\n- Open a screenshot then screenshot that tab\n- Use `eval` to check active tab — use `tab-list`\n\n## Environment Caveats\n\nThis is a sandboxed browser-based VFS. Many standard tools don\'t exist.\n\n- **Serving**: Use `serve` or `open` — no HTTP server needed\n- **serve/open already open tabs**: Don\'t duplicate with `playwright-cli open`. Use `tab-list` to find existing tab.\n- **Never manually construct preview URLs** — use URL from command output\n- **No long-running servers**: `serve` and `open` handle previewing\n- **No package managers**: No `apt`, `npm install`, `pip install`\n\n## File System Watching\n\n`fswatch` monitors VFS file changes and delivers events as licks to scoops.\n\n```bash\n# Watch for markdown changes, route to a scoop\nfswatch create --path /workspace --pattern "*.md" --scoop doc-watcher --name md-changes\n\n# Watch without targeting a scoop (routes to cone)\nfswatch create --path /workspace/src --pattern "*.ts"\n\n# List active watchers\nfswatch list\n\n# Remove a watcher\nfswatch delete fsw-1\n```\n\nEvents include the change type (`create`, `modify`, `delete`) and the file path.\n\n## Symlinks\n\nThe VFS supports symbolic links:\n\n```bash\nln -s /workspace/skills /workspace/skill-link # Create symlink\nreadlink /workspace/skill-link # Read link target\nls -la /workspace/ # Shows symlinks with -> target\n```\n\nSymlinks work transparently — `cat`, `readFile`, `writeFile` etc. follow symlinks automatically.\n\n## Onboarding\n\nWhen you receive a `[Sprinkle Event: welcome]` with `onboarding-complete`, read `/workspace/skills/welcome/SKILL.md` and follow its instructions.\n',E6=`---
13969
13969
  name: handoff
13970
13970
  description: React to navigate lick events (x-slicc response headers) with a yes/no approval card
13971
13971
  allowed-tools: bash
@@ -14036,7 +14036,7 @@ Use this shtml block verbatim, substituting the origin URL and header value. Kee
14036
14036
  - Do not fetch the origin URL until the user has accepted. Even a \`HEAD\` request is too eager — the origin may use fetch-beacon side effects.
14037
14037
  - Do not execute the header value as a shell command. It is instruction text or a pointer, not code.
14038
14038
  - Do not render more than one approval card for a single navigate event. If you already showed the card, wait for the user.
14039
- `,w6=`---
14039
+ `,D6=`---
14040
14040
  name: inline-widgets
14041
14041
  description: Interactive widget patterns for inline shtml cards in chat messages
14042
14042
  allowed-tools: bash
@@ -14306,7 +14306,7 @@ slicc.lick({ action: 'sort-complete', algorithm: algo, comparisons: n });
14306
14306
  \`\`\`
14307
14307
 
14308
14308
  The agent receives the lick as a structured message and can respond with prose, another inline widget, or spawn a scoop.
14309
- `,T6=`---
14309
+ `,O6=`---
14310
14310
  name: playwright-cli
14311
14311
  description: Browse the web, interact with pages, take screenshots, extract data via the playwright-cli shell command.
14312
14312
  allowed-tools: bash
@@ -14495,7 +14495,7 @@ playwright-cli stop-recording <recordingId> # Stop and save HAR
14495
14495
  - The SLICC app tab and Chrome internal UI tabs are automatically excluded from \`tab-list\`.
14496
14496
  - \`fill\` clears and types into regular inputs, textareas, and \`contenteditable\` elements.
14497
14497
  - Screenshots default to \`/tmp/screenshot-<timestamp>.png\`. Use \`--filename=path\` to save elsewhere.
14498
- `,E6=`---
14498
+ `,k6=`---
14499
14499
  name: Scoop Management
14500
14500
  description: Detailed scoop lifecycle, delegation rules, browser tab handling
14501
14501
  ---
@@ -14681,7 +14681,7 @@ scoop_scoop({ name: "architect", model: "claude-opus-4-6", prompt: "Design the n
14681
14681
  \`\`\`
14682
14682
 
14683
14683
  **Error handling**: If a scoop fails due to an invalid model or API error, it will retry up to 3 times with exponential backoff for transient errors (rate limits, server errors). Non-retryable errors (invalid model, auth failures) fail immediately and notify the cone, bypassing any \`scoop_mute\` settings.
14684
- `,D6="---\nname: Skill Authoring\ndescription: Skills discovery, .jsh/.bsh files, shell commands, filesystem\n---\n\n# Skill Authoring & Shell Reference\n\n## Skills\n\nSkills in `/workspace/skills/` extend capabilities. SLICC also discovers compatibility skills from `.agents/skills/*/SKILL.md` and `.claude/skills/*/SKILL.md` anywhere in the reachable VFS. Only native `/workspace/skills/` entries are install-managed; compatibility-discovered skills stay read-only.\n\n## .jsh Files (JavaScript Shell Scripts)\n\n`.jsh` files are auto-discovered as shell commands anywhere on the VFS:\n\n- **Auto-discovery**: registered as callable commands (by filename without extension)\n- **Skills can ship them**: executable `.jsh` scripts live alongside SKILL.md\n- **Node-like globals**: `process`, `console`, `fs` (VFS bridge with `readFile`, `writeFile`, `readDir`, `exists`)\n- **Dual-mode**: work in CLI server and Chrome extension\n- **Top-level `await`**: wrapped in AsyncFunction. Always `await` fs methods. Don't use `.then()`.\n\n## .bsh Files (Browser Shell Scripts)\n\n`.bsh` files auto-execute when the browser navigates to a matching URL:\n\n- **Filename = hostname pattern**: `-.okta.com.bsh` matches `*.okta.com`\n- **`// @match` directive**: restrict to specific URL patterns in first 10 lines\n- Same execution engine as `.jsh`\n\n## Shell Commands\n\nType `commands` in the terminal for the full list. Key commands:\n\n- **skill list/info/read** — inspect skills; `skill install/uninstall` manages native packages\n- **upskill** — install from GitHub (`upskill owner/repo`) or ClawHub (`upskill clawhub:name`)\n- **webhook/crontask/fswatch** — set up licks (external event triggers, file change watchers)\n- **sprinkle** — manage sprinkles: `list`, `open`, `close`, `send`, `chat`\n- **oauth-token** — get OAuth access token for a provider\n- **cost** — show session cost breakdown (tokens, cache, cost per cone/scoop)\n- **git** — full git support\n- **node -e / python3 -c** — execute JS or Python\n- **serve <dir>** — open VFS app directory in browser tab\n- **open <path|url>** — open file/URL in browser. `open --view` to see images inline\n- **playwright-cli** — browser automation (tab-list, tab-new, snapshot, screenshot, click, fill, tab-close)\n- **pbcopy/pbpaste/xclip/xsel** — clipboard\n- **say** — text-to-speech\n- **afplay** — play audio files\n- **chime** — notification sound\n- **rsync** — sync files between local VFS and remote tray runtime\n- **teleport** — transfer browser cookies from remote tray runtime\n- **host** — tray status and join URL\n\n## Filesystem\n\nVirtual filesystem stored in IndexedDB, survives tab closes and refreshes. Mount local directories:\n\n```\nmount /mnt/myproject\n```\n\nUse an empty mount point. Mounting over existing files is blocked so built-in skills and scripts stay discoverable. `ln -s` the mounted files into the place where you need them.\n\n## Capabilities\n\n- Read/write files in virtual workspace\n- Run bash commands in sandboxed shell\n- Automate browser interactions (screenshots, navigation, clicking, JS eval)\n- Delegate work to scoops and react when they finish\n- Respond to licks (webhooks, scheduled tasks)\n",O6=`---
14684
+ `,A6="---\nname: Skill Authoring\ndescription: Skills discovery, .jsh/.bsh files, shell commands, filesystem\n---\n\n# Skill Authoring & Shell Reference\n\n## Skills\n\nSkills in `/workspace/skills/` extend capabilities. SLICC also discovers compatibility skills from `.agents/skills/*/SKILL.md` and `.claude/skills/*/SKILL.md` anywhere in the reachable VFS. Only native `/workspace/skills/` entries are install-managed; compatibility-discovered skills stay read-only.\n\n## .jsh Files (JavaScript Shell Scripts)\n\n`.jsh` files are auto-discovered as shell commands anywhere on the VFS:\n\n- **Auto-discovery**: registered as callable commands (by filename without extension)\n- **Skills can ship them**: executable `.jsh` scripts live alongside SKILL.md\n- **Node-like globals**: `process`, `console`, `fs` (VFS bridge with `readFile`, `writeFile`, `readDir`, `exists`)\n- **Dual-mode**: work in CLI server and Chrome extension\n- **Top-level `await`**: wrapped in AsyncFunction. Always `await` fs methods. Don't use `.then()`.\n\n## .bsh Files (Browser Shell Scripts)\n\n`.bsh` files auto-execute when the browser navigates to a matching URL:\n\n- **Filename = hostname pattern**: `-.okta.com.bsh` matches `*.okta.com`\n- **`// @match` directive**: restrict to specific URL patterns in first 10 lines\n- Same execution engine as `.jsh`\n\n## Shell Commands\n\nType `commands` in the terminal for the full list. Key commands:\n\n- **skill list/info/read** — inspect skills; `skill install/uninstall` manages native packages\n- **upskill** — install from GitHub (`upskill owner/repo`) or ClawHub (`upskill clawhub:name`)\n- **webhook/crontask/fswatch** — set up licks (external event triggers, file change watchers)\n- **sprinkle** — manage sprinkles: `list`, `open`, `close`, `send`, `chat`\n- **oauth-token** — get OAuth access token for a provider\n- **cost** — show session cost breakdown (tokens, cache, cost per cone/scoop)\n- **git** — full git support\n- **node -e / python3 -c** — execute JS or Python\n- **serve <dir>** — open VFS app directory in browser tab\n- **open <path|url>** — open file/URL in browser. `open --view` to see images inline\n- **playwright-cli** — browser automation (tab-list, tab-new, snapshot, screenshot, click, fill, tab-close)\n- **pbcopy/pbpaste/xclip/xsel** — clipboard\n- **say** — text-to-speech\n- **afplay** — play audio files\n- **chime** — notification sound\n- **rsync** — sync files between local VFS and remote tray runtime\n- **teleport** — transfer browser cookies from remote tray runtime\n- **host** — tray status and join URL\n\n## Filesystem\n\nVirtual filesystem stored in IndexedDB, survives tab closes and refreshes. Mount local directories:\n\n```\nmount /mnt/myproject\n```\n\nUse an empty mount point. Mounting over existing files is blocked so built-in skills and scripts stay discoverable. `ln -s` the mounted files into the place where you need them.\n\n## Capabilities\n\n- Read/write files in virtual workspace\n- Run bash commands in sandboxed shell\n- Automate browser interactions (screenshots, navigation, clicking, JS eval)\n- Delegate work to scoops and react when they finish\n- Respond to licks (webhooks, scheduled tasks)\n",j6=`---
14685
14685
  name: Sprinkle Guide
14686
14686
  description: Inline cards, sprinkle chat, cone orchestration rules for UI panels
14687
14687
  ---
@@ -14744,7 +14744,7 @@ The cone MUST NOT: write/edit \`.shtml\` files, run \`sprinkle open/close/send\`
14744
14744
  See the sprinkles skill (\`read_file /workspace/skills/sprinkles/SKILL.md\`) for creating, modifying, and handling lick events.
14745
14745
 
14746
14746
  **NEVER handle a lick in the cone. Always \`feed_scoop\`.**
14747
- `,k6='---\nname: sprinkles\ndescription: Create interactive sprinkles — dashboards, forms, and visualizations\nallowed-tools: bash\n---\n\n# Sprinkles\n\n`.shtml` files in `/shared/sprinkles/` become interactive UI panels. Use them to create dashboards, forms, and visualizations alongside the chat.\n\n**Two sprinkle modes**:\n\n- **Fragment mode** (default): Plain HTML fragments injected into the sidebar. Do NOT use `<!DOCTYPE html>`, `<html>`, `<head>`, `<body>`, or custom CSS — use the built-in `.sprinkle-*` classes. Scripts get a `slicc` bridge object automatically.\n- **Full-document mode**: Complete HTML documents (starting with `<!DOCTYPE html>` or `<html>`) render inside sandboxed iframes. Use this for complex layouts with custom CSS, sidebars, split panes, modals, or canvas/SVG visualizations. The bridge script is auto-injected — `window.slicc` and `window.bridge` are available in your scripts. Use `parent.postMessage` is handled internally.\n\n**When to use full-document mode**: Use it when you need custom CSS beyond `.sprinkle-*` classes, complex layouts (sidebar + main, split panes, tabs), or interactive canvas/SVG. The parent page\'s S2 theme tokens are injected automatically.\n\n**Creating a sprinkle**:\n\n1. `read_file /workspace/skills/sprinkles/style-guide.md` — **always read first** before writing any sprinkle\n2. `write_file` to `/shared/sprinkles/<name>/<name>.shtml` (follow the style guide templates)\n3. `bash` → `sprinkle open <name>`\n4. **CRITICAL: Do NOT finish or send a completion message.** You own this sprinkle for its entire lifetime. The cone will send you follow-up instructions (modifications, lick events) via `feed_scoop`. If you finish, you lose your context and cannot handle future work on this sprinkle.\n\n**Updating a sprinkle** (when you receive follow-up instructions):\n\n1. Edit `/shared/sprinkles/<name>/<name>.shtml` with the requested changes\n2. Reload: `sprinkle close <name> && sprinkle open <name>`\n3. Do NOT finish — stay ready for more instructions\n\n**Handling lick events** (when the cone forwards a user interaction):\nThe cone will send you a message with the lick action and your sprinkle name. Only modify YOUR sprinkle — the one matching your scoop name. Process the action and push updates:\n\n- `bash` → `sprinkle send <name> \'{"key":"value"}\'` to push data to the sprinkle\'s `slicc.on(\'update\', ...)` handler\n- Or edit the `.shtml` file and reload if the UI structure needs to change\n- Do NOT finish — stay ready for more events\n\n**Managing sprinkles via bash**:\n\n- `sprinkle list` — see available sprinkles\n- `sprinkle open <name>` — show a sprinkle in the sidebar\n- `sprinkle close <name>` — remove it\n- `sprinkle send <name> \'<json>\'` — push data (single-quote the JSON!)\n- `sprinkle chat \'<html>\'` — show inline HTML in the chat (for quick confirmations/choices)\n- `open /path/to/file.shtml` — also opens as a sprinkle\n\n**Bridge API** (available as `slicc` in `<script>` tags and `onclick` attributes):\n\n- `slicc.lick({action: \'refresh\', data: {...}})` — send a lick event to the cone (cone routes to the right scoop)\n- `slicc.on(\'update\', function(data) {...})` — receive data sent via `sprinkle send`\n- `slicc.name` — the sprinkle\'s name\n- `slicc.close()` — close the sprinkle\n- `slicc.stopCone()` — stop the cone agent\n- `slicc.readFile(path)` — read a VFS file (returns `Promise<string>`)\n- `slicc.writeFile(path, content)` — write text content to a VFS file\n- `slicc.readDir(path)` — list directory entries (returns `Promise<Array<{name, type}>>`)\n- `slicc.exists(path)` — check if path exists (returns `Promise<boolean>`)\n- `slicc.stat(path)` — get file metadata (returns `Promise<{type, size}>`)\n- `slicc.mkdir(path)` — create a directory (recursive)\n- `slicc.rm(path)` — remove a file\n- `slicc.screenshot(selector?)` — capture sprinkle DOM as base64 PNG data URL. Note: The screenshot captures a DOM clone using SVG foreignObject. External stylesheets and some computed styles may not be fully reproduced. For best results, use inline styles on elements you intend to screenshot.\n\n**onclick attributes**: Always use `slicc` — e.g. `onclick="slicc.lick({action: \'add-year\'})"`. The `slicc` variable is automatically resolved per-sprinkle, so multiple sprinkles won\'t collide. Do NOT use `bridge` or any other variable name in onclick.\n\n**CSS components** — Do NOT write custom CSS. Use the built-in `.sprinkle-*` classes: cards, tables, badges, buttons, text fields, progress bars, meters, layout utilities, and more. For inputs use `class="sprinkle-text-field"`, never inline border/padding styles. Run `read_file /workspace/skills/sprinkles/style-guide.md` for the full component reference with markup examples.\n\n## Built-in Sprinkles\n\nThese sprinkles ship with SLICC at `/shared/sprinkles/`. They are full-document HTML apps rendered in sandboxed iframes.\n\n| Sprinkle name | Open with | Use when the user asks for... |\n| ------------------ | -------------------------------- | --------------------------------------------------------------------- |\n| `page-editor` | `sprinkle open page-editor` | WYSIWYG editor, page editor, edit sections, visual editing |\n| `content-tree` | `sprinkle open content-tree` | content tree, page tree, site structure, page browser, navigate pages |\n| `review-workflow` | `sprinkle open review-workflow` | review, approval workflow, annotations, comments on content |\n| `seo-dashboard` | `sprinkle open seo-dashboard` | SEO audit, meta tags, SERP preview, SEO issues |\n| `schema-editor` | `sprinkle open schema-editor` | schema, structured data, JSON-LD, rich results |\n| `readability` | `sprinkle open readability` | readability, reading level, text analysis, simplify text |\n| `brand-compliance` | `sprinkle open brand-compliance` | brand check, brand compliance, style guide violations |\n| `tone-voice` | `sprinkle open tone-voice` | tone, voice, writing style, formality, tone analysis |\n| `performance` | `sprinkle open performance` | performance, Core Web Vitals, page speed, lighthouse |\n| `funnels` | `sprinkle open funnels` | funnels, conversion, A/B test, analytics |\n\n### When a user request matches a built-in sprinkle\n\nWhen the user\'s request matches a built-in sprinkle (see table above), **ask the user which approach they prefer** before proceeding:\n\n> I can help with that. Would you like me to:\n>\n> 1. **Open the built-in [sprinkle name]** — ready to use immediately, I\'ll populate it with your data\n> 2. **Build a custom one from scratch** — tailored exactly to your needs, but takes a moment to create\n>\n> Which do you prefer?\n\n**If the user says "open" / "use the built-in" / picks option 1** — use the built-in sprinkle (see "Using Built-in Sprinkles" in style-guide.md for the scoop brief template).\n\n**If the user says "build" / "create" / "custom" / picks option 2** — create a new sprinkle from scratch following the "Creating a sprinkle" flow above.\n\n**If the user explicitly says "open the page editor"** (or any built-in name directly) — skip the question and use the built-in immediately.\n\n**If the request is clearly novel** (no matching built-in) — create from scratch without asking.\n\n### Cone orchestration for sprinkles\n\n**Rule 3: Creating sprinkles** — Create a scoop, then feed it a complete, self-contained brief:\n\n```\nscoop_scoop("giro-winners")\nfeed_scoop("giro-winners", "You own the sprinkle \'giro-winners\'. Your job:\n1. Run: read_file /workspace/skills/sprinkles/style-guide.md\n2. Research the last 3 Giro d\'Italia winners\n3. Write the sprinkle to /shared/sprinkles/giro-winners/giro-winners.shtml\n4. Run: sprinkle open giro-winners\n5. IMPORTANT: After opening the sprinkle, do NOT finish. Stay ready — you will receive follow-up instructions and lick events for this sprinkle via feed_scoop. Do not send a completion message.")\n```\n\n**Rule 4: Modifying sprinkles** — Feed the EXISTING scoop that owns it. Do NOT create a new scoop:\n\n```\nfeed_scoop("giro-winners", "Modify YOUR sprinkle \'giro-winners\' at /shared/sprinkles/giro-winners/giro-winners.shtml:\nAdd an \'Add Previous Year\' button with onclick=\\"slicc.lick({action: \'add-year\'})\\"\nThen reload: sprinkle close giro-winners && sprinkle open giro-winners\nStay ready for more work.")\n```\n\n**Rule 5: Lick events** — Forward to owning scoop, never handle yourself:\n\n```\nfeed_scoop("giro-winners", "Lick event on YOUR sprinkle \'giro-winners\' (/shared/sprinkles/giro-winners/giro-winners.shtml):\nAction: \'add-year\'\nLook up the next previous year\'s Giro d\'Italia winner and update the sprinkle.\nUse: sprinkle send giro-winners \'<json>\' to push data, or edit the .shtml and reload.\nStay ready for more lick events.")\n```\n',A6=`# Lucide Icons Example
14747
+ `,M6='---\nname: sprinkles\ndescription: Create interactive sprinkles — dashboards, forms, and visualizations\nallowed-tools: bash\n---\n\n# Sprinkles\n\n`.shtml` files in `/shared/sprinkles/` become interactive UI panels. Use them to create dashboards, forms, and visualizations alongside the chat.\n\n**Two sprinkle modes**:\n\n- **Fragment mode** (default): Plain HTML fragments injected into the sidebar. Do NOT use `<!DOCTYPE html>`, `<html>`, `<head>`, `<body>`, or custom CSS — use the built-in `.sprinkle-*` classes. Scripts get a `slicc` bridge object automatically.\n- **Full-document mode**: Complete HTML documents (starting with `<!DOCTYPE html>` or `<html>`) render inside sandboxed iframes. Use this for complex layouts with custom CSS, sidebars, split panes, modals, or canvas/SVG visualizations. The bridge script is auto-injected — `window.slicc` and `window.bridge` are available in your scripts. Use `parent.postMessage` is handled internally.\n\n**When to use full-document mode**: Use it when you need custom CSS beyond `.sprinkle-*` classes, complex layouts (sidebar + main, split panes, tabs), or interactive canvas/SVG. The parent page\'s S2 theme tokens are injected automatically.\n\n**Creating a sprinkle**:\n\n1. `read_file /workspace/skills/sprinkles/style-guide.md` — **always read first** before writing any sprinkle\n2. `write_file` to `/shared/sprinkles/<name>/<name>.shtml` (follow the style guide templates)\n3. `bash` → `sprinkle open <name>`\n4. **CRITICAL: Do NOT finish or send a completion message.** You own this sprinkle for its entire lifetime. The cone will send you follow-up instructions (modifications, lick events) via `feed_scoop`. If you finish, you lose your context and cannot handle future work on this sprinkle.\n\n**Updating a sprinkle** (when you receive follow-up instructions):\n\n1. Edit `/shared/sprinkles/<name>/<name>.shtml` with the requested changes\n2. Reload: `sprinkle close <name> && sprinkle open <name>`\n3. Do NOT finish — stay ready for more instructions\n\n**Handling lick events** (when the cone forwards a user interaction):\nThe cone will send you a message with the lick action and your sprinkle name. Only modify YOUR sprinkle — the one matching your scoop name. Process the action and push updates:\n\n- `bash` → `sprinkle send <name> \'{"key":"value"}\'` to push data to the sprinkle\'s `slicc.on(\'update\', ...)` handler\n- Or edit the `.shtml` file and reload if the UI structure needs to change\n- Do NOT finish — stay ready for more events\n\n**Managing sprinkles via bash**:\n\n- `sprinkle list` — see available sprinkles\n- `sprinkle open <name>` — show a sprinkle in the sidebar\n- `sprinkle close <name>` — remove it\n- `sprinkle send <name> \'<json>\'` — push data (single-quote the JSON!)\n- `sprinkle chat \'<html>\'` — show inline HTML in the chat (for quick confirmations/choices)\n- `open /path/to/file.shtml` — also opens as a sprinkle\n\n**Bridge API** (available as `slicc` in `<script>` tags and `onclick` attributes):\n\n- `slicc.lick({action: \'refresh\', data: {...}})` — send a lick event to the cone (cone routes to the right scoop)\n- `slicc.on(\'update\', function(data) {...})` — receive data sent via `sprinkle send`\n- `slicc.name` — the sprinkle\'s name\n- `slicc.close()` — close the sprinkle\n- `slicc.stopCone()` — stop the cone agent\n- `slicc.readFile(path)` — read a VFS file (returns `Promise<string>`)\n- `slicc.writeFile(path, content)` — write text content to a VFS file\n- `slicc.readDir(path)` — list directory entries (returns `Promise<Array<{name, type}>>`)\n- `slicc.exists(path)` — check if path exists (returns `Promise<boolean>`)\n- `slicc.stat(path)` — get file metadata (returns `Promise<{type, size}>`)\n- `slicc.mkdir(path)` — create a directory (recursive)\n- `slicc.rm(path)` — remove a file\n- `slicc.screenshot(selector?)` — capture sprinkle DOM as base64 PNG data URL. Note: The screenshot captures a DOM clone using SVG foreignObject. External stylesheets and some computed styles may not be fully reproduced. For best results, use inline styles on elements you intend to screenshot.\n\n**onclick attributes**: Always use `slicc` — e.g. `onclick="slicc.lick({action: \'add-year\'})"`. The `slicc` variable is automatically resolved per-sprinkle, so multiple sprinkles won\'t collide. Do NOT use `bridge` or any other variable name in onclick.\n\n**CSS components** — Do NOT write custom CSS. Use the built-in `.sprinkle-*` classes: cards, tables, badges, buttons, text fields, progress bars, meters, layout utilities, and more. For inputs use `class="sprinkle-text-field"`, never inline border/padding styles. Run `read_file /workspace/skills/sprinkles/style-guide.md` for the full component reference with markup examples.\n\n## Built-in Sprinkles\n\nThese sprinkles ship with SLICC at `/shared/sprinkles/`. They are full-document HTML apps rendered in sandboxed iframes.\n\n| Sprinkle name | Open with | Use when the user asks for... |\n| ------------------ | -------------------------------- | --------------------------------------------------------------------- |\n| `page-editor` | `sprinkle open page-editor` | WYSIWYG editor, page editor, edit sections, visual editing |\n| `content-tree` | `sprinkle open content-tree` | content tree, page tree, site structure, page browser, navigate pages |\n| `review-workflow` | `sprinkle open review-workflow` | review, approval workflow, annotations, comments on content |\n| `seo-dashboard` | `sprinkle open seo-dashboard` | SEO audit, meta tags, SERP preview, SEO issues |\n| `schema-editor` | `sprinkle open schema-editor` | schema, structured data, JSON-LD, rich results |\n| `readability` | `sprinkle open readability` | readability, reading level, text analysis, simplify text |\n| `brand-compliance` | `sprinkle open brand-compliance` | brand check, brand compliance, style guide violations |\n| `tone-voice` | `sprinkle open tone-voice` | tone, voice, writing style, formality, tone analysis |\n| `performance` | `sprinkle open performance` | performance, Core Web Vitals, page speed, lighthouse |\n| `funnels` | `sprinkle open funnels` | funnels, conversion, A/B test, analytics |\n\n### When a user request matches a built-in sprinkle\n\nWhen the user\'s request matches a built-in sprinkle (see table above), **ask the user which approach they prefer** before proceeding:\n\n> I can help with that. Would you like me to:\n>\n> 1. **Open the built-in [sprinkle name]** — ready to use immediately, I\'ll populate it with your data\n> 2. **Build a custom one from scratch** — tailored exactly to your needs, but takes a moment to create\n>\n> Which do you prefer?\n\n**If the user says "open" / "use the built-in" / picks option 1** — use the built-in sprinkle (see "Using Built-in Sprinkles" in style-guide.md for the scoop brief template).\n\n**If the user says "build" / "create" / "custom" / picks option 2** — create a new sprinkle from scratch following the "Creating a sprinkle" flow above.\n\n**If the user explicitly says "open the page editor"** (or any built-in name directly) — skip the question and use the built-in immediately.\n\n**If the request is clearly novel** (no matching built-in) — create from scratch without asking.\n\n### Cone orchestration for sprinkles\n\n**Rule 3: Creating sprinkles** — Create a scoop, then feed it a complete, self-contained brief:\n\n```\nscoop_scoop("giro-winners")\nfeed_scoop("giro-winners", "You own the sprinkle \'giro-winners\'. Your job:\n1. Run: read_file /workspace/skills/sprinkles/style-guide.md\n2. Research the last 3 Giro d\'Italia winners\n3. Write the sprinkle to /shared/sprinkles/giro-winners/giro-winners.shtml\n4. Run: sprinkle open giro-winners\n5. IMPORTANT: After opening the sprinkle, do NOT finish. Stay ready — you will receive follow-up instructions and lick events for this sprinkle via feed_scoop. Do not send a completion message.")\n```\n\n**Rule 4: Modifying sprinkles** — Feed the EXISTING scoop that owns it. Do NOT create a new scoop:\n\n```\nfeed_scoop("giro-winners", "Modify YOUR sprinkle \'giro-winners\' at /shared/sprinkles/giro-winners/giro-winners.shtml:\nAdd an \'Add Previous Year\' button with onclick=\\"slicc.lick({action: \'add-year\'})\\"\nThen reload: sprinkle close giro-winners && sprinkle open giro-winners\nStay ready for more work.")\n```\n\n**Rule 5: Lick events** — Forward to owning scoop, never handle yourself:\n\n```\nfeed_scoop("giro-winners", "Lick event on YOUR sprinkle \'giro-winners\' (/shared/sprinkles/giro-winners/giro-winners.shtml):\nAction: \'add-year\'\nLook up the next previous year\'s Giro d\'Italia winner and update the sprinkle.\nUse: sprinkle send giro-winners \'<json>\' to push data, or edit the .shtml and reload.\nStay ready for more lick events.")\n```\n',N6=`# Lucide Icons Example
14748
14748
 
14749
14749
  This shows how to use Lucide icons in inline sprinkles instead of emojis.
14750
14750
 
@@ -14854,7 +14854,7 @@ This shows how to use Lucide icons in inline sprinkles instead of emojis.
14854
14854
  **UI**: \`settings\`, \`menu\`, \`more-vertical\`, \`more-horizontal\`, \`eye\`, \`eye-off\`, \`lock\`, \`unlock\`
14855
14855
 
14856
14856
  Browse all icons at [lucide.dev/icons](https://lucide.dev/icons)
14857
- `,j6=`# Sprinkle Component Reference
14857
+ `,P6=`# Sprinkle Component Reference
14858
14858
 
14859
14859
  Use these CSS classes in \`.shtml\` sprinkles. Do NOT write custom CSS — these components cover all common UI patterns.
14860
14860
 
@@ -15634,7 +15634,7 @@ background: color-mix(in srgb, var(--s2-accent) 6%, transparent); /* blue tint *
15634
15634
  | \`--s2-spacing-400\` | 24px |
15635
15635
  | \`--s2-spacing-500\` | 32px |
15636
15636
  | \`--s2-spacing-600\` | 40px |
15637
- `,M6=`---
15637
+ `,F6=`---
15638
15638
  name: welcome
15639
15639
  description: Handle onboarding lick from the welcome sprinkle
15640
15640
  allowed-tools: bash
@@ -15728,8 +15728,8 @@ Do NOT save a profile, update \`/shared/CLAUDE.md\`, or write a greeting.
15728
15728
 
15729
15729
  - **\`start-task\` lick** — treat as the user's first request, begin the task immediately.
15730
15730
  - **Sparse profiles** (user skipped most steps) — keep greeting brief, ask what they need.
15731
- `,N6=`data:audio/mpeg;base64,SUQzBAAAAAAAIlRTU0UAAAAOAAADTGF2ZjYyLjMuMTAwAAAAAAAAAAAAAAD/+0DAAAAAAAAAAAAAAAAAAAAAAABYaW5nAAAADwAAAAcAAAYbAJWVlZWVlZWVlZWVlZWVqqqqqqqqqqqqqqqqqqq7u7u7u7u7u7u7u7u7u8zMzMzMzMzMzMzMzMzMzN3d3d3d3d3d3d3d3d3d7u7u7u7u7u7u7u7u7u7//////////////////wAAAABMYXZjNjIuMTEAAAAAAAAAAAAAAAAkA2kAAAAAAAAGG+gbtfQAAAAAAP/7wMQAAAv4N1B0ZIAqHxVpvznQgAr9rb7PJkyd34smDgMBk078/BAKAoGBQw+OHn/gAGf4eHv/wB3mf/gb/+OAf/AMf/h4A78AMP/oeAGfAAw/+h4AZ8BGH/48AM/iMf/+AAAAAAYeHh4eAAAAAAYeHh48AQMIAMGIBMXNwtEAoEAwAAQFAIBXCQKu8YAEJgcFBQtl1DXh6g4LDYWQ0TAcKGhAZbDTOWxGG4ECgfmRFLtKMFhAMNgLYEsYxXEXG8YqgB/V3RF/XZhqJUcp//99nKcqIv7vmWv///4zWppVVpf///////5TWpqarS0v8RBUFREe/1gqIgqCoiXfkTAVAAwAAMY6g6nK2AAgTCmlJdBcQAwEcSQmFALZslhoW7uNZ4gSBAGEM6A0KbEqs5LgGh4TzAuMFNh9L4FA2JwwsRBsKsxbGrvVd4Ah/AtwTpu046oAoLB7MBAHAAAuQSQgTSmJa2mO8ncaGTeyJsz3wn9TbdBmuCWkp8D8E//+gA4/C9YFwCq9RAA7S+AQNicISCx60KQy7HHeq7wBD0BcwnTfOPUM5NC/UFgAAAA6uQ6OhMlAQIF6e9CTI2Vyp7bkY0xyAhvA8Zp848zYQBSgCAONoPJlh0OM6j8g0QAE5IcEu49m0ZsbxZWX6cQwG6gzS0dl1wT//6UO9sCfUFoAAAAziH7QUEI6FiQEQGYIOeVMMQXnACAteiQWVmmckZbEXG1w7KCMN9bB7QFyC3ELRigOQJdCo56zhEjAgXAlbcHreLLGmdkZTD2m1w6ygjUO98CeUH4AAAAziH/QkCMDzpmjj44B3nBC54YUDZoxbLGmdEdERly9qyhjDfixayBkA2cGE4UKrxIIhgz8HwBS3YlbIGxt21jWiK0hatrEYEjVTEFNRTMuMTAwVVVVVVVVVVVVVVVVVVVVB3aABwAfwAAAMj7DgFUgDBxFLY4XWT6pcoZrVtbqPGBB//sgxO8Axmw5Qd29gCiLCCg4DdB0oi1tkrKwMMFBV000qkxBTUUzLjEwMKqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqv/7EMT6AEVwQTPgcEPgk4goOA3QdKqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq//sQxPsARMRBQ+Dqg2C2iCa8Pgh8qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqr/+xDE+oDFuEFD4Whj4KMIKDgtDHyqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqv/7EMT4gMVgQUXhYGPgmgan+AHgBaqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq//sQxO0DxaRHKeDgY+gAAD/AAAAEqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqo=`,P6=o(`skills`),F6=Object.assign({"/packages/vfs-root/AGENTS.md":l6,"/packages/vfs-root/CLAUDE.md":l6,"/packages/vfs-root/shared/CLAUDE.md":u6,"/packages/vfs-root/shared/sprinkles/brand-compliance/brand-compliance.shtml":d6,"/packages/vfs-root/shared/sprinkles/content-tree/content-tree.shtml":f6,"/packages/vfs-root/shared/sprinkles/funnels/funnels.shtml":p6,"/packages/vfs-root/shared/sprinkles/page-editor/page-editor.shtml":m6,"/packages/vfs-root/shared/sprinkles/performance/performance.shtml":h6,"/packages/vfs-root/shared/sprinkles/readability/readability.shtml":g6,"/packages/vfs-root/shared/sprinkles/review-workflow/review-workflow.shtml":_6,"/packages/vfs-root/shared/sprinkles/schema-editor/schema-editor.shtml":v6,"/packages/vfs-root/shared/sprinkles/seo-dashboard/seo-dashboard.shtml":y6,"/packages/vfs-root/shared/sprinkles/tone-voice/tone-voice.shtml":b6,"/packages/vfs-root/shared/sprinkles/welcome/welcome.shtml":x6,"/packages/vfs-root/workspace/skills/automation/SKILL.md":S6,"/packages/vfs-root/workspace/skills/handoff/SKILL.md":C6,"/packages/vfs-root/workspace/skills/inline-widgets/SKILL.md":w6,"/packages/vfs-root/workspace/skills/playwright-cli/SKILL.md":T6,"/packages/vfs-root/workspace/skills/scoop-management/SKILL.md":E6,"/packages/vfs-root/workspace/skills/skill-authoring/SKILL.md":D6,"/packages/vfs-root/workspace/skills/sprinkle-guide/SKILL.md":O6,"/packages/vfs-root/workspace/skills/sprinkles/SKILL.md":k6,"/packages/vfs-root/workspace/skills/sprinkles/icon-example.md":A6,"/packages/vfs-root/workspace/skills/sprinkles/style-guide.md":j6,"/packages/vfs-root/workspace/skills/welcome/SKILL.md":M6}),I6=Object.assign({"/packages/vfs-root/shared/sounds/chime.mp3":N6});function L6(e){let t=e.split(`,`)[1],n=atob(t),r=new Uint8Array(n.length);for(let e=0;e<n.length;e++)r[e]=n.charCodeAt(e);return r}function R6(){let e={};for(let[t,n]of Object.entries(F6))e[t]=n;for(let[t,n]of Object.entries(I6))e[t]=L6(n);return e}function z6(e){let t=new Map;for(let n of e){if(t.has(n.metadata.name)){P6.debug(`Skipped shadowed runtime skill`,{name:n.metadata.name,path:n.path,winnerPath:t.get(n.metadata.name)?.path});continue}t.set(n.metadata.name,n)}return Array.from(t.values())}function B6(e){let t=e.match(/^---\s*\n([\s\S]*?)\n---\s*\n([\s\S]*)$/);if(!t)return{metadata:{},body:e};let[,n,r]=t,i={};for(let e of n.split(`
15732
- `)){let t=e.match(/^(\w[\w-]*):\s*(.*)$/);if(!t)continue;let[,n,r]=t,a=r.trim();switch(n){case`name`:i.name=a;break;case`description`:i.description=a;break;case`allowed-tools`:i.allowedTools=a.split(`,`).map(e=>e.trim());break}}return{metadata:i,body:r}}async function V6(e,t){let n=await H6(e,t),r=await U6(e,t),i=n.filter(e=>e.source===`native`),a=n.filter(e=>e.source!==`native`),o=z6([...i,...r,...a]);return P6.info(`Skills loaded`,{count:o.length,dir:t}),o}async function H6(e,t){let n=await ae(e,t),r=[];for(let t of n)if(t.skillFilePath)try{let{metadata:n,body:i}=B6(await e.readTextFile(t.skillFilePath)),a=n.name||t.name;r.push({metadata:{name:a,description:n.description||t.manifest.description||``,allowedTools:n.allowedTools},content:i,path:t.skillFilePath,source:t.source}),P6.debug(`Loaded discovered skill`,{name:a,path:t.skillFilePath,source:t.source})}catch{P6.debug(`Failed to load discovered skill`,{name:t.name,path:t.skillFilePath})}return r}async function U6(e,t){let n=[];try{let r=await e.readDir(t);for(let i of r)if(i.type===`file`&&i.name.endsWith(`.md`)){let r=`${t}/${i.name}`;try{let t=await e.readFile(r,{encoding:`utf-8`}),{metadata:a,body:o}=B6(typeof t==`string`?t:new TextDecoder().decode(t)),s=a.name||i.name.replace(`.md`,``);n.push({metadata:{name:s,description:a.description||``,allowedTools:a.allowedTools},content:o,path:r}),P6.debug(`Loaded standalone skill`,{name:s,path:r})}catch{}}}catch{P6.debug(`Standalone skills directory not found`,{dir:t})}return n}function W6(e){return e.length===0?``:`
15731
+ `,I6=`data:audio/mpeg;base64,SUQzBAAAAAAAIlRTU0UAAAAOAAADTGF2ZjYyLjMuMTAwAAAAAAAAAAAAAAD/+0DAAAAAAAAAAAAAAAAAAAAAAABYaW5nAAAADwAAAAcAAAYbAJWVlZWVlZWVlZWVlZWVqqqqqqqqqqqqqqqqqqq7u7u7u7u7u7u7u7u7u8zMzMzMzMzMzMzMzMzMzN3d3d3d3d3d3d3d3d3d7u7u7u7u7u7u7u7u7u7//////////////////wAAAABMYXZjNjIuMTEAAAAAAAAAAAAAAAAkA2kAAAAAAAAGG+gbtfQAAAAAAP/7wMQAAAv4N1B0ZIAqHxVpvznQgAr9rb7PJkyd34smDgMBk078/BAKAoGBQw+OHn/gAGf4eHv/wB3mf/gb/+OAf/AMf/h4A78AMP/oeAGfAAw/+h4AZ8BGH/48AM/iMf/+AAAAAAYeHh4eAAAAAAYeHh48AQMIAMGIBMXNwtEAoEAwAAQFAIBXCQKu8YAEJgcFBQtl1DXh6g4LDYWQ0TAcKGhAZbDTOWxGG4ECgfmRFLtKMFhAMNgLYEsYxXEXG8YqgB/V3RF/XZhqJUcp//99nKcqIv7vmWv///4zWppVVpf///////5TWpqarS0v8RBUFREe/1gqIgqCoiXfkTAVAAwAAMY6g6nK2AAgTCmlJdBcQAwEcSQmFALZslhoW7uNZ4gSBAGEM6A0KbEqs5LgGh4TzAuMFNh9L4FA2JwwsRBsKsxbGrvVd4Ah/AtwTpu046oAoLB7MBAHAAAuQSQgTSmJa2mO8ncaGTeyJsz3wn9TbdBmuCWkp8D8E//+gA4/C9YFwCq9RAA7S+AQNicISCx60KQy7HHeq7wBD0BcwnTfOPUM5NC/UFgAAAA6uQ6OhMlAQIF6e9CTI2Vyp7bkY0xyAhvA8Zp848zYQBSgCAONoPJlh0OM6j8g0QAE5IcEu49m0ZsbxZWX6cQwG6gzS0dl1wT//6UO9sCfUFoAAAAziH7QUEI6FiQEQGYIOeVMMQXnACAteiQWVmmckZbEXG1w7KCMN9bB7QFyC3ELRigOQJdCo56zhEjAgXAlbcHreLLGmdkZTD2m1w6ygjUO98CeUH4AAAAziH/QkCMDzpmjj44B3nBC54YUDZoxbLGmdEdERly9qyhjDfixayBkA2cGE4UKrxIIhgz8HwBS3YlbIGxt21jWiK0hatrEYEjVTEFNRTMuMTAwVVVVVVVVVVVVVVVVVVVVB3aABwAfwAAAMj7DgFUgDBxFLY4XWT6pcoZrVtbqPGBB//sgxO8Axmw5Qd29gCiLCCg4DdB0oi1tkrKwMMFBV000qkxBTUUzLjEwMKqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqv/7EMT6AEVwQTPgcEPgk4goOA3QdKqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq//sQxPsARMRBQ+Dqg2C2iCa8Pgh8qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqr/+xDE+oDFuEFD4Whj4KMIKDgtDHyqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqv/7EMT4gMVgQUXhYGPgmgan+AHgBaqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq//sQxO0DxaRHKeDgY+gAAD/AAAAEqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqo=`,L6=o(`skills`),R6=Object.assign({"/packages/vfs-root/AGENTS.md":f6,"/packages/vfs-root/CLAUDE.md":f6,"/packages/vfs-root/shared/CLAUDE.md":p6,"/packages/vfs-root/shared/sprinkles/brand-compliance/brand-compliance.shtml":m6,"/packages/vfs-root/shared/sprinkles/content-tree/content-tree.shtml":h6,"/packages/vfs-root/shared/sprinkles/funnels/funnels.shtml":g6,"/packages/vfs-root/shared/sprinkles/page-editor/page-editor.shtml":_6,"/packages/vfs-root/shared/sprinkles/performance/performance.shtml":v6,"/packages/vfs-root/shared/sprinkles/readability/readability.shtml":y6,"/packages/vfs-root/shared/sprinkles/review-workflow/review-workflow.shtml":b6,"/packages/vfs-root/shared/sprinkles/schema-editor/schema-editor.shtml":x6,"/packages/vfs-root/shared/sprinkles/seo-dashboard/seo-dashboard.shtml":S6,"/packages/vfs-root/shared/sprinkles/tone-voice/tone-voice.shtml":C6,"/packages/vfs-root/shared/sprinkles/welcome/welcome.shtml":w6,"/packages/vfs-root/workspace/skills/automation/SKILL.md":T6,"/packages/vfs-root/workspace/skills/handoff/SKILL.md":E6,"/packages/vfs-root/workspace/skills/inline-widgets/SKILL.md":D6,"/packages/vfs-root/workspace/skills/playwright-cli/SKILL.md":O6,"/packages/vfs-root/workspace/skills/scoop-management/SKILL.md":k6,"/packages/vfs-root/workspace/skills/skill-authoring/SKILL.md":A6,"/packages/vfs-root/workspace/skills/sprinkle-guide/SKILL.md":j6,"/packages/vfs-root/workspace/skills/sprinkles/SKILL.md":M6,"/packages/vfs-root/workspace/skills/sprinkles/icon-example.md":N6,"/packages/vfs-root/workspace/skills/sprinkles/style-guide.md":P6,"/packages/vfs-root/workspace/skills/welcome/SKILL.md":F6}),z6=Object.assign({"/packages/vfs-root/shared/sounds/chime.mp3":I6});function B6(e){let t=e.split(`,`)[1],n=atob(t),r=new Uint8Array(n.length);for(let e=0;e<n.length;e++)r[e]=n.charCodeAt(e);return r}function V6(){let e={};for(let[t,n]of Object.entries(R6))e[t]=n;for(let[t,n]of Object.entries(z6))e[t]=B6(n);return e}function H6(e){let t=new Map;for(let n of e){if(t.has(n.metadata.name)){L6.debug(`Skipped shadowed runtime skill`,{name:n.metadata.name,path:n.path,winnerPath:t.get(n.metadata.name)?.path});continue}t.set(n.metadata.name,n)}return Array.from(t.values())}function U6(e){let t=e.match(/^---\s*\n([\s\S]*?)\n---\s*\n([\s\S]*)$/);if(!t)return{metadata:{},body:e};let[,n,r]=t,i={};for(let e of n.split(`
15732
+ `)){let t=e.match(/^(\w[\w-]*):\s*(.*)$/);if(!t)continue;let[,n,r]=t,a=r.trim();switch(n){case`name`:i.name=a;break;case`description`:i.description=a;break;case`allowed-tools`:i.allowedTools=a.split(`,`).map(e=>e.trim());break}}return{metadata:i,body:r}}async function W6(e,t){let n=await G6(e,t),r=await K6(e,t),i=n.filter(e=>e.source===`native`),a=n.filter(e=>e.source!==`native`),o=H6([...i,...r,...a]);return L6.info(`Skills loaded`,{count:o.length,dir:t}),o}async function G6(e,t){let n=await ae(e,t),r=[];for(let t of n)if(t.skillFilePath)try{let{metadata:n,body:i}=U6(await e.readTextFile(t.skillFilePath)),a=n.name||t.name;r.push({metadata:{name:a,description:n.description||t.manifest.description||``,allowedTools:n.allowedTools},content:i,path:t.skillFilePath,source:t.source}),L6.debug(`Loaded discovered skill`,{name:a,path:t.skillFilePath,source:t.source})}catch{L6.debug(`Failed to load discovered skill`,{name:t.name,path:t.skillFilePath})}return r}async function K6(e,t){let n=[];try{let r=await e.readDir(t);for(let i of r)if(i.type===`file`&&i.name.endsWith(`.md`)){let r=`${t}/${i.name}`;try{let t=await e.readFile(r,{encoding:`utf-8`}),{metadata:a,body:o}=U6(typeof t==`string`?t:new TextDecoder().decode(t)),s=a.name||i.name.replace(`.md`,``);n.push({metadata:{name:s,description:a.description||``,allowedTools:a.allowedTools},content:o,path:r}),L6.debug(`Loaded standalone skill`,{name:s,path:r})}catch{}}}catch{L6.debug(`Standalone skills directory not found`,{dir:t})}return n}function q6(e){return e.length===0?``:`
15733
15733
  ---
15734
15734
  AVAILABLE SKILLS
15735
15735
 
@@ -15738,11 +15738,11 @@ The following skills are available. To use a skill, first read its full instruct
15738
15738
 
15739
15739
  ${e.map(e=>{let t=e.metadata.allowedTools?` Allowed tools: ${e.metadata.allowedTools.join(`, `)}\n`:``;return`- **${e.metadata.name}**: ${e.metadata.description}\n${t} Path: ${e.path}`}).join(`
15740
15740
  `)}
15741
- ---`}async function G6(e,t=`/workspace/skills`){let n=R6();for(let[r,i]of Object.entries(n)){let n=r.slice(18),a=n.startsWith(`/workspace/skills`),o=n.startsWith(`/workspace/scripts`);if(!a&&!o)continue;let s=n;a&&t!==`/workspace/skills`&&(s=n.replace(`/workspace/skills`,t)),o&&t!==`/workspace/skills`&&(s=t.replace(`/workspace/skills`,``)+n);try{await e.stat(s)}catch{let t=s.substring(0,s.lastIndexOf(`/`));try{await e.mkdir(t,{recursive:!0})}catch{}await e.writeFile(s,i),P6.info(`Created default file`,{path:s})}}}async function K6(e){let t=R6();for(let[n,r]of Object.entries(t)){let t=n.slice(18);if(t.startsWith(`/shared/`))try{await e.stat(t)}catch{let n=t.substring(0,t.lastIndexOf(`/`));try{await e.mkdir(n,{recursive:!0})}catch{}await e.writeFile(t,r),P6.info(`Created default shared file`,{path:t})}}}var q6=o(`scoop-management-tools`);function J6(e,t){let n=t(),r=[],i=[];for(let t of e){let e=n.find(e=>!e.isCone&&(e.folder===t||e.name===t));e?r.push(e):i.push(t)}return{resolved:r,unknown:i}}function Y6(e){let{scoop:t,onSendMessage:n,onFeedScoop:r,getScoops:i,getScoopTabState:a,onScoopScoop:o,onDropScoop:s,onSetGlobalMemory:c,getGlobalMemory:l,onMuteScoops:u,onUnmuteScoops:d,onWaitForScoops:f}=e,p=[];return p.push({name:`send_message`,description:`Send a progress message while still working. Your final output is also sent.`,inputSchema:{type:`object`,properties:{text:{type:`string`,description:`The message text to send`},sender:{type:`string`,description:`Optional sender name/role (e.g., "Researcher"). Defaults to assistant name.`}},required:[`text`]},execute:async e=>{let{text:r,sender:i}=e;return n(r,i),q6.info(`Message sent`,{scoopFolder:t.folder,textLength:r.length}),{content:`Message sent.`}}}),t.isCone&&r&&p.push({name:`feed_scoop`,description:`Give a scoop a task. Provide a complete, self-contained prompt — the scoop has no access to your conversation. You'll be notified when it finishes.`,inputSchema:{type:`object`,properties:{scoop_name:{type:`string`,description:`The scoop folder name (e.g., "test-scoop"). Use list_scoops to see available scoops.`},prompt:{type:`string`,description:`Complete, self-contained instructions for the scoop. Include ALL context — the scoop cannot see your conversation.`}},required:[`scoop_name`,`prompt`]},execute:async e=>{let{scoop_name:t,prompt:n}=e,a=i().find(e=>e.folder===t||e.name===t);if(!a)return{content:`Scoop "${t}" not found. Available: ${i().filter(e=>!e.isCone).map(e=>e.folder).join(`, `)}`,isError:!0};if(a.isCone)return{content:`Cannot feed the cone (yourself).`,isError:!0};try{return await r(a.jid,n),q6.info(`Fed scoop`,{target:a.folder,promptLength:n.length}),{content:`Task sent to ${a.folder}. You will be notified when it completes.`}}catch(e){return{content:`Failed to feed scoop: ${e instanceof Error?e.message:String(e)}`,isError:!0}}}}),t.isCone&&(p.push({name:`list_scoops`,description:`List all registered scoops.`,inputSchema:{type:`object`,properties:{}},execute:async()=>{let e=i();return e.length===0?{content:`No scoops registered.`}:{content:`Registered scoops:\n${e.map(e=>{let t=a?.(e.jid),n=t?.status??`unknown`,r=t?.lastActivity?new Date(t.lastActivity).toLocaleString(`en-US`,{month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`,hour12:!0}):``,i=r?` — ${n} (since ${r})`:` — ${n}`;return e.isCone?`- ${e.assistantLabel} (${e.folder}) [CONE]${i}`:`- ${e.name} (${e.folder})${i}`}).join(`
15742
- `)}`}}}),o&&p.push({name:`scoop_scoop`,description:`Create a new scoop. Optionally specify a model, a prompt, and per-scoop sandbox shape (visible/writable paths + command allow-list). If prompt is provided, the scoop starts working immediately after creation (no separate feed_scoop needed).`,inputSchema:{type:`object`,properties:{name:{type:`string`,description:`Display name for the scoop (e.g., "hero-block")`},model:{type:`string`,description:`Model ID for this scoop (e.g., "claude-sonnet-4-6"). If omitted, uses the same model as the cone.`},prompt:{type:`string`,description:`Task prompt for the scoop. If provided, the scoop starts working immediately after creation.`},visiblePaths:{type:`array`,items:{type:`string`},description:`VFS paths the scoop can READ (not write). Pure replace — what you set is what you get. Omit to use the default ["/workspace/"] which exposes the shared skills tree. Pass [] for no extra read-only paths. Note: the scoop's writablePaths are always readable too, so a true read-nothing sandbox also requires writablePaths: []. Mounts remain readable regardless. Trailing slash recommended (e.g. "/shared/data/").`},writablePaths:{type:`array`,items:{type:`string`},description:`VFS paths the scoop can READ AND WRITE. Pure replace. Omit to use the default ["/scoops/<folder>/", "/shared/"] which gives the scoop its own sandbox plus shared space. Pass [] to block all writes. Trailing slash recommended.`},allowedCommands:{type:`array`,items:{type:`string`},description:`Shell command allow-list. Omit for unrestricted access to every built-in, custom, and .jsh command (the default). Pass a list of command names to restrict the scoop's shell — e.g. ["echo","cat","grep"] for a read-only text-processing scoop. Pass ["*"] for explicit unrestricted. Applies to pipelines, substitutions, and network commands too.`}},required:[`name`]},execute:async e=>{let{name:t,model:n,prompt:i,visiblePaths:a,writablePaths:s,allowedCommands:c}=e,l=t.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,50)+`-scoop`;try{let e=await o({name:t,folder:l,trigger:`@${l}`,isCone:!1,type:`scoop`,requiresTrigger:!0,assistantLabel:l,addedAt:new Date().toISOString(),config:{...n?{modelId:n}:{},visiblePaths:a??[`/workspace/`],writablePaths:s??[`/scoops/${l}/`,`/shared/`],...c?{allowedCommands:c}:{}},configSchemaVersion:2});if(q6.info(`Scoop created`,{name:t,folder:l}),i&&r){try{await r(e.jid,i)}catch(e){let n=e instanceof Error?e.message:String(e);return q6.error(`Auto-feed failed`,{name:t,error:n}),{content:`Scoop "${t}" created as "${l}" but the initial task could not be sent: ${n}. Use feed_scoop to retry.`,isError:!0}}return{content:`Scoop "${t}" created as "${l}" and task sent. It is now working on it.`}}return{content:`Scoop "${t}" created as "${l}". Use feed_scoop to give it a task.`}}catch(e){return{content:`Failed to create scoop: ${e instanceof Error?e.message:String(e)}`,isError:!0}}}}),s&&p.push({name:`drop_scoop`,description:`Remove a scoop and stop its work. The scoop will be unregistered and its context destroyed.`,inputSchema:{type:`object`,properties:{scoop_name:{type:`string`,description:`The scoop folder name (e.g., "test-scoop"). Use list_scoops to see available scoops.`}},required:[`scoop_name`]},execute:async e=>{let{scoop_name:t}=e,n=i().find(e=>e.folder===t||e.name===t);if(!n)return{content:`Scoop "${t}" not found. Available: ${i().filter(e=>!e.isCone).map(e=>e.folder).join(`, `)}`,isError:!0};if(n.isCone)return{content:`Cannot drop the cone (yourself).`,isError:!0};try{return await s(n.jid),q6.info(`Scoop dropped`,{name:n.name,folder:n.folder}),{content:`Scoop "${n.name}" (${n.folder}) has been dropped.`}}catch(e){return{content:`Failed to drop scoop: ${e instanceof Error?e.message:String(e)}`,isError:!0}}}}),u&&p.push({name:`scoop_mute`,description:`Suspend scoop→cone notifications for the given scoops. While muted, a scoop's completion is stashed and will be delivered to the cone when you call scoop_unmute (or scoop_wait which consumes it). Use this when coordinating parallel work so each scoop's completion does not trigger its own cone turn.`,inputSchema:{type:`object`,properties:{scoop_names:{type:`array`,items:{type:`string`},description:`Folder or display names of scoops to mute (e.g., ["writer-scoop", "reviewer-scoop"]).`}},required:[`scoop_names`]},execute:async e=>{let{scoop_names:t}=e;if(!Array.isArray(t)||t.length===0)return{content:`scoop_names must be a non-empty array.`,isError:!0};let{resolved:n,unknown:r}=J6(t,i);return n.length===0?{content:`No matching scoops found. Unknown: ${r.join(`, `)}`,isError:!0}:(u(n.map(e=>e.jid)),q6.info(`Scoops muted`,{names:n.map(e=>e.folder)}),{content:`Muted: ${n.map(e=>e.folder).join(`, `)}${r.length>0?` (unknown: ${r.join(`, `)})`:``}`})}}),d&&p.push({name:`scoop_unmute`,description:`Resume scoop→cone notifications for the given scoops. Any completion that landed while a scoop was muted is returned in this tool result (NOT dispatched as a new cone turn), so you can read all stashed summaries in the current turn. Scoops with no stashed completion are simply unmuted.`,inputSchema:{type:`object`,properties:{scoop_names:{type:`array`,items:{type:`string`},description:`Folder or display names of scoops to unmute (e.g., ["writer-scoop"]).`}},required:[`scoop_names`]},execute:async e=>{let{scoop_names:t}=e;if(!Array.isArray(t)||t.length===0)return{content:`scoop_names must be a non-empty array.`,isError:!0};let{resolved:n,unknown:r}=J6(t,i);if(n.length===0)return{content:`No matching scoops found. Unknown: ${r.join(`, `)}`,isError:!0};let a=n.map(e=>e.jid),o=new Map(n.map(e=>[e.jid,e.folder])),s=await d(a);q6.info(`Scoops unmuted`,{names:n.map(e=>e.folder),stashedCount:s.length});let c=[`Unmuted: ${n.map(e=>e.folder).join(`, `)}${r.length>0?` (unknown: ${r.join(`, `)})`:``}`];if(s.length===0)c.push(`No stashed completions.`);else{c.push(``,`Stashed completions:`);for(let e of s){let t=o.get(e.jid)??e.jid;c.push(`--- ${t} ---`),e.notificationPath&&c.push(`VFS path: ${e.notificationPath}`),c.push(e.summary)}}return{content:c.join(`
15743
- `)}}}),f&&p.push({name:`scoop_wait`,description:`Block until the given scoops complete or an optional timeout expires. Use this to coordinate parallel work: you feed several scoops, then call scoop_wait to receive all their results in one go without the cone being pinged for each individual completion. Already-completed scoops (including those whose completion arrived while you were processing your previous turn) are returned immediately.`,inputSchema:{type:`object`,properties:{scoop_names:{type:`array`,items:{type:`string`},description:`Folder or display names of scoops to wait for (e.g., ["writer-scoop", "reviewer-scoop"]).`},timeout_ms:{type:`number`,description:`Optional timeout in milliseconds. If any listed scoop has not completed by the deadline, it is reported as timed-out in the result and the wait returns. Omit for no timeout.`}},required:[`scoop_names`]},execute:async e=>{let{scoop_names:t,timeout_ms:n}=e;if(!Array.isArray(t)||t.length===0)return{content:`scoop_names must be a non-empty array.`,isError:!0};if(n!==void 0&&(typeof n!=`number`||!Number.isFinite(n)||n<0))return{content:`timeout_ms must be a non-negative finite number (or omitted).`,isError:!0};let{resolved:r,unknown:a}=J6(t,i);if(r.length===0)return{content:`No matching scoops found. Unknown: ${a.join(`, `)}`,isError:!0};let o=r.map(e=>e.jid),s=new Map(r.map(e=>[e.jid,e.folder])),c=await f(o,n);q6.info(`Wait completed`,{names:r.map(e=>e.folder),timeout_ms:n,timedOut:c.filter(e=>e.timedOut).length});let l=[];a.length>0&&l.push(`Unknown scoops (skipped): ${a.join(`, `)}`);for(let e of c){let t=s.get(e.jid)??e.jid;e.timedOut?l.push(`--- ${t} (timed out) ---`):(l.push(`--- ${t} ---`),l.push(e.summary??`(no output)`))}return{content:l.join(`
15744
- `)}}}),c&&l&&p.push({name:`update_global_memory`,description:`Update the global CLAUDE.md memory file that is shared across all scoops. Use this instead of write_file for /shared/CLAUDE.md.`,inputSchema:{type:`object`,properties:{content:{type:`string`,description:`The new content for the global memory file`}},required:[`content`]},execute:async e=>{let{content:t}=e;try{return await c(t),q6.info(`Global memory updated`),{content:`Global memory updated successfully.`}}catch(e){return{content:`Failed to update global memory: ${e instanceof Error?e.message:String(e)}`,isError:!0}}}})),p}var X6=`slicc:adobe-daily-uuid:`,Z6=new Map;function Q6(){return new Date().toISOString().slice(0,10)}function $6(){try{return globalThis.localStorage??null}catch{return null}}function e8(e){let t=Q6(),n=$6(),r=X6+e;if(n){let e=n.getItem(r);if(e)try{let n=JSON.parse(e);if(n.date===t&&typeof n.uuid==`string`)return n.uuid}catch{}let i=crypto.randomUUID();try{n.setItem(r,JSON.stringify({uuid:i,date:t}))}catch{}return i}let i=Z6.get(e);if(i&&i.date===t)return i.uuid;let a=crypto.randomUUID();return Z6.set(e,{uuid:a,date:t}),a}async function t8(e,t){let n=new TextEncoder().encode(`${t}:${e}`),r=await crypto.subtle.digest(`SHA-256`,n);return Array.from(new Uint8Array(r).slice(0,8)).map(e=>e.toString(16).padStart(2,`0`)).join(``)}async function n8(e,t){let n=e8(t??e.jid);return e.isCone?n:`${n}/${await t8(e.folder,n)}`}var r8=i({fetchSecretEnvVars:()=>a8}),i8=o(`secret-env`);async function a8(){if(typeof chrome<`u`&&chrome?.runtime?.id)return{};try{let e=await fetch(`/api/secrets/masked`);if(!e.ok)return i8.warn(`Failed to fetch masked secrets`,{status:e.status}),{};let t=await e.json();if(!Array.isArray(t)||t.length===0)return{};let n={};for(let e of t)e.name&&e.maskedValue&&(n[e.name]=e.maskedValue);return Object.keys(n).length>0&&i8.info(`Loaded masked secrets into shell env`,{count:Object.keys(n).length}),n}catch(e){return i8.debug(`Could not fetch masked secrets (server may be unavailable)`,{error:e instanceof Error?e.message:String(e)}),{}}}var o8=o(`scoop-context`);function s8(e){return/image exceeds.*maximum/i.test(e)||/Could not process image/i.test(e)||/invalid.*image/i.test(e)||/image.*too (large|big)/i.test(e)}function c8(e){return/\b(401|403|404|405|410|422)\b/.test(e)||/unauthorized|forbidden|authentication.*failed|invalid.*api.?key/i.test(e)||/model.*not.*found|invalid.*model|unknown.*model|does.*not.*exist/i.test(e)||/insufficient.*quota|billing|payment.*required|account.*suspended/i.test(e)||/invalid.*request|malformed|bad.*request/i.test(e)}function l8(e){return/\b429\b|rate.*limit|too.*many.*requests|quota.*exceeded/i.test(e)||/\b(500|502|503|504)\b|internal.*server|bad.*gateway|service.*unavailable|gateway.*timeout/i.test(e)||/network.*error|connection.*refused|timeout|econnreset|socket.*hang.*up/i.test(e)||/overloaded|temporarily.*unavailable|try.*again/i.test(e)}function u8(e,t){return t?.aborted?Promise.resolve(!0):new Promise(n=>{let r=()=>{clearTimeout(i),n(!0)},i=setTimeout(()=>{t?.removeEventListener(`abort`,r),n(!1)},e);t?.addEventListener(`abort`,r,{once:!0})})}var d8=class{scoop;callbacks;fs=null;shell=null;agent=null;status=`initializing`;isProcessing=!1;disposed=!1;didStreamDeltas=!1;unsubscribe=null;promptAbortController=null;sessionStore=null;sessionId;sessionCreatedAt=0;isRecovering=!1;coneJid;skillsFs=null;skillsDir=`/workspace/skills`;constructor(e,t,n,r,i,a){this.scoop=e,this.callbacks=t,this.fs=n,this.sessionStore=r??null,this.skillsFs=i??null,this.coneJid=a,this.sessionId=e.jid}async init(){this.setStatus(`initializing`);try{if(!this.fs)throw Error(`Filesystem not provided`);o8.info(`Filesystem ready`,{folder:this.scoop.folder}),await this.ensureDirectoryStructure();let e=this.scoop.isCone?`/`:`/scoops/${this.scoop.folder}/workspace`,t=this.callbacks.getBrowserAPI();this.skillsDir=`/workspace/skills`,this.scoop.isCone&&await G6(this.fs,this.skillsDir);let n=this.skillsFs??this.fs,r=await a8();this.shell=new Z3({fs:this.fs,cwd:e,env:Object.keys(r).length>0?r:void 0,browserAPI:t,jshDiscoveryFs:this.skillsFs?n:void 0,allowedCommands:this.scoop.config?.allowedCommands,getParentJid:()=>this.scoop.jid}),o8.info(`WasmShell initialized`,{folder:this.scoop.folder});let i=await V6(n,this.skillsDir),a=Y6({scoop:this.scoop,onSendMessage:this.callbacks.onSendMessage,getScoops:this.callbacks.getScoops,getScoopTabState:this.callbacks.getScoopTabState,onFeedScoop:this.callbacks.onFeedScoop,onScoopScoop:this.callbacks.onScoopScoop,onDropScoop:this.callbacks.onDropScoop,onMuteScoops:this.callbacks.onMuteScoops,onUnmuteScoops:this.callbacks.onUnmuteScoops,onWaitForScoops:this.callbacks.onWaitForScoops,onSetGlobalMemory:this.callbacks.setGlobalMemory,getGlobalMemory:this.callbacks.getGlobalMemory}),o=c([...e6(this.fs),c6(this.shell),...a]),s=this.scoop.isCone?`/workspace/CLAUDE.md`:`/scoops/${this.scoop.folder}/CLAUDE.md`,u=``;try{let e=await this.fs.readFile(s,{encoding:`utf-8`});u=typeof e==`string`?e:new TextDecoder().decode(e)}catch{}let h=await this.callbacks.getGlobalMemory();if(h)try{this.scoop.isCone&&await(`getUnderlyingFS`in this.fs?this.fs.getUnderlyingFS():this.fs).writeFile(`/shared/CLAUDE.md`,h)}catch{}if(!l()){let e=d();throw Error(`No API key configured for provider "${e}"`)}let g=this.scoop.config?.modelId?p(this.scoop.config.modelId):f(),_=this.scoop.isCone?`Cone`:`Scoop "${this.scoop.name}"`;console.log(`[model] ${_} using model: ${g.id} (provider: ${g.provider})`);let v=this.buildSystemPrompt(h,u,i),y=[];if(this.sessionStore)try{let e=await this.sessionStore.load(this.sessionId);e&&(y=e.messages,this.sessionCreatedAt=e.createdAt,o8.info(`Restored agent session`,{folder:this.scoop.folder,messageCount:y.length}))}catch(e){o8.error(`Failed to restore agent session`,{folder:this.scoop.folder,error:e instanceof Error?e.message:String(e)}),this.callbacks.onError(`Conversation history could not be restored. Starting fresh.`)}let b=m({model:g,getApiKey:()=>l()??void 0}),x=await n8(this.scoop,this.coneJid),S=(e,t,n)=>e.provider===`adobe`?T(e,t,{...n,headers:{...n?.headers,"X-Session-Id":x}}):T(e,t,n);if(this.disposed)return;this.agent=new E({initialState:{model:g,tools:o,systemPrompt:v,messages:y},getApiKey:()=>l()??void 0,transformContext:b,streamFn:S}),this.unsubscribe=this.agent.subscribe(e=>this.handleAgentEvent(e)),this.setStatus(`ready`),o8.info(`ScoopContext initialized`,{folder:this.scoop.folder,toolCount:o.length})}catch(e){if(this.disposed)return;let t=e instanceof Error?e.message:String(e);o8.error(`ScoopContext init failed`,{folder:this.scoop.folder,error:t}),this.setStatus(`error`),this.callbacks.onError(`Failed to initialize: ${t}`)}}async prompt(e){if(!this.agent){this.callbacks.onError(`Agent not initialized`);return}let t=this.agent.state?.isStreaming??!1;if(this.isProcessing||t){o8.info(`Queueing prompt via followUp while processing`,{folder:this.scoop.folder,isProcessing:this.isProcessing,agentIsStreaming:t}),this.agent.followUp({role:`user`,content:[{type:`text`,text:e}],timestamp:Date.now()});return}let n=this.agent;this.promptAbortController?.abort();let r=new AbortController;this.promptAbortController=r;let i=r.signal;this.isProcessing=!0,this.setStatus(`processing`);let a=1e3,o=null;try{for(let t=1;t<=3;t++){if(this.disposed||i.aborted)return;this.didStreamDeltas=!1;try{await n.prompt(e),o=null;break}catch(e){if(this.disposed||i.aborted)return;o=e instanceof Error?e:Error(String(e));let n=o.message;if(c8(n)){o8.error(`Non-retryable agent error`,{folder:this.scoop.folder,error:n,attempt:t}),this.setStatus(`error`),this.callbacks.onFatalError?this.callbacks.onFatalError(`Scoop "${this.scoop.name}" failed with unrecoverable error: ${n}`):this.callbacks.onError(n);return}if(l8(n)&&t<3){let e=a*2**(t-1);if(o8.warn(`Retryable agent error, will retry`,{folder:this.scoop.folder,error:n,attempt:t,maxRetries:3,delayMs:e}),await u8(e,i)||this.disposed)return;continue}if(o8.error(`Agent error`,{folder:this.scoop.folder,error:n,attempt:t,isRetryable:l8(n)}),t===3)break;if(await u8(a*2**(t-1),i)||this.disposed)return}}if(o&&!this.disposed&&!i.aborted){let e=o.message;o8.error(`Agent error after retries exhausted`,{folder:this.scoop.folder,error:e,maxRetries:3}),this.setStatus(`error`),this.callbacks.onFatalError?this.callbacks.onFatalError(`Scoop "${this.scoop.name}" failed after 3 attempts: ${e}`):this.callbacks.onError(e);return}!this.disposed&&!i.aborted&&this.setStatus(`ready`)}finally{this.isProcessing=!1,this.promptAbortController===r&&(this.promptAbortController=null)}}stop(){this.promptAbortController?.abort(),this.agent?.clearAllQueues?.(),this.agent?.abort?.(),this.isProcessing=!1,this.setStatus(`ready`)}clearMessages(){this.agent&&(this.agent.state.messages=[])}getAgentMessages(){return this.agent?.state?.messages?structuredClone(this.agent.state.messages):[]}getSessionId(){return this.sessionId}getFS(){return this.fs}getShell(){return this.shell}updateModel(){if(!this.agent)return;let e=f();this.agent.state.model=e,o8.info(`Model updated on running agent`,{folder:this.scoop.folder,model:e.id})}async reloadSkills(){if(!this.agent)return;let e=await V6(this.skillsFs??this.fs,this.skillsDir),t=``,n=this.scoop.isCone?`/workspace/CLAUDE.md`:`/scoops/${this.scoop.folder}/CLAUDE.md`;try{let e=await this.fs.readFile(n,{encoding:`utf-8`});t=typeof e==`string`?e:new TextDecoder().decode(e)}catch{}let r=await this.callbacks.getGlobalMemory(),i=this.buildSystemPrompt(r,t,e);this.agent.state.systemPrompt=i,o8.info(`Skills reloaded`,{folder:this.scoop.folder,skillCount:e.length})}dispose(){this.disposed=!0,this.promptAbortController?.abort(),this.promptAbortController=null,this.agent?.clearAllQueues?.(),this.agent?.abort?.(),this.unsubscribe?.(),this.shell?.dispose(),this.agent=null,this.shell=null,this.fs=null}setStatus(e){this.disposed||(this.status=e,this.callbacks.onStatusChange(e))}handleAgentEvent(e){if(!this.disposed)switch(e.type){case`message_update`:{let t=e.assistantMessageEvent;t.type===`text_delta`&&(this.didStreamDeltas=!0,this.callbacks.onResponse(t.delta,!0));break}case`tool_execution_start`:this.callbacks.onToolStart?.(e.toolName,e.args);break;case`tool_execution_update`:{let t=e.partialResult;for(let n of t?.content??[])n.type===`tool_ui`&&n.requestId&&n.html?this.callbacks.onToolUI?.(e.toolName,n.requestId,n.html):n.type===`tool_ui_done`&&n.requestId&&this.callbacks.onToolUIDone?.(n.requestId);break}case`tool_execution_end`:{let t=e.result,n=[];for(let e of t?.content??[])e.type===`text`&&e.text&&n.push(e.text),e.type===`image`&&e.data&&e.mimeType&&n.push(`<img:data:${e.mimeType};base64,${e.data}>`);this.callbacks.onToolEnd?.(e.toolName,n.join(`
15745
- `),e.isError);break}case`message_end`:if(e.message.role===`assistant`){let t=e.message.content.filter(e=>e.type===`text`).map(e=>e.text).join(``);t&&!this.didStreamDeltas&&this.callbacks.onResponse(t,!1)}break;case`turn_end`:this.callbacks.onResponseDone();break;case`agent_end`:{let t=e.messages;if(t.length>0){let e=t[t.length-1];if(e.role===`assistant`&&e.errorMessage){let n=e.errorMessage;if(!this.isRecovering&&s8(n)){this.recoverFromImageError(t);break}if(!this.isRecovering&&u(e)){this.recoverFromOverflow(t);break}this.isRecovering=!1,this.callbacks.onError(n)}else this.isRecovering=!1}let n=this.agent?.state?.messages??e.messages;this.sessionStore&&n.length>0&&this.sessionStore.save({id:this.sessionId,messages:n,config:{},createdAt:this.sessionCreatedAt||Date.now(),updatedAt:Date.now()}).catch(e=>{o8.error(`Failed to save agent session`,{folder:this.scoop.folder,error:e instanceof Error?e.message:String(e)})});break}}}recoverFromOverflow(e){if(this.agent){o8.warn(`Context overflow detected, attempting recovery`,{folder:this.scoop.folder,messageCount:e.length}),this.isRecovering=`overflow`,this.callbacks.onResponse(`Context window exceeded — recovering by trimming oversized messages...`,!1);try{let t=e.slice(0,-1),n=0;for(let e=t.length-1;e>=0&&n<5;e--){let r=t[e];if(!Array.isArray(r.content))continue;let i=0;for(let e of r.content)e.type===`text`&&e.text&&(i+=e.text.length),e.type===`image`&&e.data&&(i+=e.data.length);if(i>4e4){let a={type:`text`,text:`[Content removed: ${r.role===`toolResult`?`tool result`:r.role} was too large for context window (${Math.round(i/1e3)}K chars). The operation completed but output could not be retained.]`};if(r.role===`assistant`){let n=r.content.filter(e=>e.type===`toolCall`);t[e]={...r,content:[a,...n]}}else t[e]={...r,content:[a]};n++,o8.info(`Replaced oversized message`,{index:e,role:r.role,size:i,preservedToolCalls:r.role===`assistant`?r.content.filter(e=>e.type===`toolCall`).length:0})}}this.agent.state.messages=t;let r=n>0?`[System: Context overflow recovered. ${n} oversized message(s) were replaced with placeholders to fit within the context window. The conversation continues — you may need to re-read files or re-run commands if their output was removed.]`:`[System: Context overflow recovered. Older messages were trimmed. The conversation continues — compaction will summarize history on the next turn.]`;this.agent.prompt(r).catch(e=>{o8.error(`Recovery re-prompt failed`,{folder:this.scoop.folder,error:e instanceof Error?e.message:String(e)}),this.isRecovering=!1,this.callbacks.onError(`Context overflow recovery failed: ${e instanceof Error?e.message:String(e)}`)})}catch(e){o8.error(`Recovery failed`,{folder:this.scoop.folder,error:e instanceof Error?e.message:String(e)}),this.isRecovering=!1,this.callbacks.onError(`Context overflow recovery failed: ${e instanceof Error?e.message:String(e)}`)}}}recoverFromImageError(e){if(this.agent){o8.warn(`Image processing error detected, attempting recovery`,{folder:this.scoop.folder,messageCount:e.length}),this.isRecovering=`image`,this.callbacks.onResponse(`Image rejected by API — removing problematic images and continuing...`,!1);try{let t=e.slice(0,-1),n=0,r=Math.max(0,t.length-10);for(let e=t.length-1;e>=r;e--){let r=t[e];if(!Array.isArray(r.content)||!r.content.some(e=>e.type===`image`))continue;let i=r.content.filter(e=>e.type!==`image`);i.length===0?t[e]={...r,content:[{type:`text`,text:`[Image removed: rejected by API]`}]}:t[e]={...r,content:i},n++}this.agent.state.messages=t;let i=`[System: An image was rejected by the API and has been removed from the conversation (${n} message(s) affected). The conversation continues without the image.]`;this.agent.prompt(i).catch(e=>{o8.error(`Image recovery re-prompt failed`,{folder:this.scoop.folder,error:e instanceof Error?e.message:String(e)}),this.isRecovering=!1,this.callbacks.onError(`Image error recovery failed: ${e instanceof Error?e.message:String(e)}`)})}catch(e){o8.error(`Image recovery failed`,{folder:this.scoop.folder,error:e instanceof Error?e.message:String(e)}),this.isRecovering=!1,this.callbacks.onError(`Image error recovery failed: ${e instanceof Error?e.message:String(e)}`)}}}async ensureDirectoryStructure(){if(!this.fs)return;let e=this.scoop.isCone?[`/workspace`,`/shared`,`/scoops`,`/home`,`/tmp`,`/mnt`]:[`/scoops/${this.scoop.folder}`,`/scoops/${this.scoop.folder}/workspace`,`/scoops/${this.scoop.folder}/home`,`/scoops/${this.scoop.folder}/tmp`,`/shared`];for(let t of e)try{await this.fs.mkdir(t,{recursive:!0})}catch{}let t=this.scoop.isCone?`/workspace/CLAUDE.md`:`/scoops/${this.scoop.folder}/CLAUDE.md`;try{await this.fs.readFile(t)}catch{let e=`# ${this.scoop.assistantLabel} Memory
15741
+ ---`}async function J6(e,t=`/workspace/skills`){let n=V6();for(let[r,i]of Object.entries(n)){let n=r.slice(18),a=n.startsWith(`/workspace/skills`),o=n.startsWith(`/workspace/scripts`);if(!a&&!o)continue;let s=n;a&&t!==`/workspace/skills`&&(s=n.replace(`/workspace/skills`,t)),o&&t!==`/workspace/skills`&&(s=t.replace(`/workspace/skills`,``)+n);try{await e.stat(s)}catch{let t=s.substring(0,s.lastIndexOf(`/`));try{await e.mkdir(t,{recursive:!0})}catch{}await e.writeFile(s,i),L6.info(`Created default file`,{path:s})}}}async function Y6(e){let t=V6();for(let[n,r]of Object.entries(t)){let t=n.slice(18);if(t.startsWith(`/shared/`))try{await e.stat(t)}catch{let n=t.substring(0,t.lastIndexOf(`/`));try{await e.mkdir(n,{recursive:!0})}catch{}await e.writeFile(t,r),L6.info(`Created default shared file`,{path:t})}}}var X6=o(`scoop-management-tools`);function Z6(e,t){let n=t(),r=[],i=[];for(let t of e){let e=n.find(e=>!e.isCone&&(e.folder===t||e.name===t));e?r.push(e):i.push(t)}return{resolved:r,unknown:i}}function Q6(e){let{scoop:t,onSendMessage:n,onFeedScoop:r,getScoops:i,getScoopTabState:a,onScoopScoop:o,onDropScoop:s,onSetGlobalMemory:c,getGlobalMemory:l,onMuteScoops:u,onUnmuteScoops:d,onWaitForScoops:f}=e,p=[];return p.push({name:`send_message`,description:`Send a progress message while still working. Your final output is also sent.`,inputSchema:{type:`object`,properties:{text:{type:`string`,description:`The message text to send`},sender:{type:`string`,description:`Optional sender name/role (e.g., "Researcher"). Defaults to assistant name.`}},required:[`text`]},execute:async e=>{let{text:r,sender:i}=e;return n(r,i),X6.info(`Message sent`,{scoopFolder:t.folder,textLength:r.length}),{content:`Message sent.`}}}),t.isCone&&r&&p.push({name:`feed_scoop`,description:`Give a scoop a task. Provide a complete, self-contained prompt — the scoop has no access to your conversation. You'll be notified when it finishes.`,inputSchema:{type:`object`,properties:{scoop_name:{type:`string`,description:`The scoop folder name (e.g., "test-scoop"). Use list_scoops to see available scoops.`},prompt:{type:`string`,description:`Complete, self-contained instructions for the scoop. Include ALL context — the scoop cannot see your conversation.`}},required:[`scoop_name`,`prompt`]},execute:async e=>{let{scoop_name:t,prompt:n}=e,a=i().find(e=>e.folder===t||e.name===t);if(!a)return{content:`Scoop "${t}" not found. Available: ${i().filter(e=>!e.isCone).map(e=>e.folder).join(`, `)}`,isError:!0};if(a.isCone)return{content:`Cannot feed the cone (yourself).`,isError:!0};try{return await r(a.jid,n),X6.info(`Fed scoop`,{target:a.folder,promptLength:n.length}),{content:`Task sent to ${a.folder}. You will be notified when it completes.`}}catch(e){return{content:`Failed to feed scoop: ${e instanceof Error?e.message:String(e)}`,isError:!0}}}}),t.isCone&&(p.push({name:`list_scoops`,description:`List all registered scoops.`,inputSchema:{type:`object`,properties:{}},execute:async()=>{let e=i();return e.length===0?{content:`No scoops registered.`}:{content:`Registered scoops:\n${e.map(e=>{let t=a?.(e.jid),n=t?.status??`unknown`,r=t?.lastActivity?new Date(t.lastActivity).toLocaleString(`en-US`,{month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`,hour12:!0}):``,i=r?` — ${n} (since ${r})`:` — ${n}`;return e.isCone?`- ${e.assistantLabel} (${e.folder}) [CONE]${i}`:`- ${e.name} (${e.folder})${i}`}).join(`
15742
+ `)}`}}}),o&&p.push({name:`scoop_scoop`,description:`Create a new scoop. Optionally specify a model, a prompt, and per-scoop sandbox shape (visible/writable paths + command allow-list). If prompt is provided, the scoop starts working immediately after creation (no separate feed_scoop needed).`,inputSchema:{type:`object`,properties:{name:{type:`string`,description:`Display name for the scoop (e.g., "hero-block")`},model:{type:`string`,description:`Model ID for this scoop (e.g., "claude-sonnet-4-6"). If omitted, uses the same model as the cone.`},prompt:{type:`string`,description:`Task prompt for the scoop. If provided, the scoop starts working immediately after creation.`},visiblePaths:{type:`array`,items:{type:`string`},description:`VFS paths the scoop can READ (not write). Pure replace — what you set is what you get. Omit to use the default ["/workspace/"] which exposes the shared skills tree. Pass [] for no extra read-only paths. Note: the scoop's writablePaths are always readable too, so a true read-nothing sandbox also requires writablePaths: []. Mounts remain readable regardless. Trailing slash recommended (e.g. "/shared/data/").`},writablePaths:{type:`array`,items:{type:`string`},description:`VFS paths the scoop can READ AND WRITE. Pure replace. Omit to use the default ["/scoops/<folder>/", "/shared/"] which gives the scoop its own sandbox plus shared space. Pass [] to block all writes. Trailing slash recommended.`},allowedCommands:{type:`array`,items:{type:`string`},description:`Shell command allow-list. Omit for unrestricted access to every built-in, custom, and .jsh command (the default). Pass a list of command names to restrict the scoop's shell — e.g. ["echo","cat","grep"] for a read-only text-processing scoop. Pass ["*"] for explicit unrestricted. Applies to pipelines, substitutions, and network commands too.`}},required:[`name`]},execute:async e=>{let{name:t,model:n,prompt:i,visiblePaths:a,writablePaths:s,allowedCommands:c}=e,l=t.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,50)+`-scoop`;try{let e=await o({name:t,folder:l,trigger:`@${l}`,isCone:!1,type:`scoop`,requiresTrigger:!0,assistantLabel:l,addedAt:new Date().toISOString(),config:{...n?{modelId:n}:{},visiblePaths:a??[`/workspace/`],writablePaths:s??[`/scoops/${l}/`,`/shared/`],...c?{allowedCommands:c}:{}},configSchemaVersion:2});if(X6.info(`Scoop created`,{name:t,folder:l}),i&&r){try{await r(e.jid,i)}catch(e){let n=e instanceof Error?e.message:String(e);return X6.error(`Auto-feed failed`,{name:t,error:n}),{content:`Scoop "${t}" created as "${l}" but the initial task could not be sent: ${n}. Use feed_scoop to retry.`,isError:!0}}return{content:`Scoop "${t}" created as "${l}" and task sent. It is now working on it.`}}return{content:`Scoop "${t}" created as "${l}". Use feed_scoop to give it a task.`}}catch(e){return{content:`Failed to create scoop: ${e instanceof Error?e.message:String(e)}`,isError:!0}}}}),s&&p.push({name:`drop_scoop`,description:`Remove a scoop and stop its work. The scoop will be unregistered and its context destroyed.`,inputSchema:{type:`object`,properties:{scoop_name:{type:`string`,description:`The scoop folder name (e.g., "test-scoop"). Use list_scoops to see available scoops.`}},required:[`scoop_name`]},execute:async e=>{let{scoop_name:t}=e,n=i().find(e=>e.folder===t||e.name===t);if(!n)return{content:`Scoop "${t}" not found. Available: ${i().filter(e=>!e.isCone).map(e=>e.folder).join(`, `)}`,isError:!0};if(n.isCone)return{content:`Cannot drop the cone (yourself).`,isError:!0};try{return await s(n.jid),X6.info(`Scoop dropped`,{name:n.name,folder:n.folder}),{content:`Scoop "${n.name}" (${n.folder}) has been dropped.`}}catch(e){return{content:`Failed to drop scoop: ${e instanceof Error?e.message:String(e)}`,isError:!0}}}}),u&&p.push({name:`scoop_mute`,description:`Suspend scoop→cone notifications for the given scoops. While muted, a scoop's completion is stashed and will be delivered to the cone when you call scoop_unmute (or scoop_wait which consumes it). Use this when coordinating parallel work so each scoop's completion does not trigger its own cone turn.`,inputSchema:{type:`object`,properties:{scoop_names:{type:`array`,items:{type:`string`},description:`Folder or display names of scoops to mute (e.g., ["writer-scoop", "reviewer-scoop"]).`}},required:[`scoop_names`]},execute:async e=>{let{scoop_names:t}=e;if(!Array.isArray(t)||t.length===0)return{content:`scoop_names must be a non-empty array.`,isError:!0};let{resolved:n,unknown:r}=Z6(t,i);return n.length===0?{content:`No matching scoops found. Unknown: ${r.join(`, `)}`,isError:!0}:(u(n.map(e=>e.jid)),X6.info(`Scoops muted`,{names:n.map(e=>e.folder)}),{content:`Muted: ${n.map(e=>e.folder).join(`, `)}${r.length>0?` (unknown: ${r.join(`, `)})`:``}`})}}),d&&p.push({name:`scoop_unmute`,description:`Resume scoop→cone notifications for the given scoops. Any completion that landed while a scoop was muted is returned in this tool result (NOT dispatched as a new cone turn), so you can read all stashed summaries in the current turn. Scoops with no stashed completion are simply unmuted.`,inputSchema:{type:`object`,properties:{scoop_names:{type:`array`,items:{type:`string`},description:`Folder or display names of scoops to unmute (e.g., ["writer-scoop"]).`}},required:[`scoop_names`]},execute:async e=>{let{scoop_names:t}=e;if(!Array.isArray(t)||t.length===0)return{content:`scoop_names must be a non-empty array.`,isError:!0};let{resolved:n,unknown:r}=Z6(t,i);if(n.length===0)return{content:`No matching scoops found. Unknown: ${r.join(`, `)}`,isError:!0};let a=n.map(e=>e.jid),o=new Map(n.map(e=>[e.jid,e.folder])),s=await d(a);X6.info(`Scoops unmuted`,{names:n.map(e=>e.folder),stashedCount:s.length});let c=[`Unmuted: ${n.map(e=>e.folder).join(`, `)}${r.length>0?` (unknown: ${r.join(`, `)})`:``}`];if(s.length===0)c.push(`No stashed completions.`);else{c.push(``,`Stashed completions:`);for(let e of s){let t=o.get(e.jid)??e.jid;c.push(`--- ${t} ---`),e.notificationPath&&c.push(`VFS path: ${e.notificationPath}`),c.push(e.summary)}}return{content:c.join(`
15743
+ `)}}}),f&&p.push({name:`scoop_wait`,description:`Block until the given scoops complete or an optional timeout expires. Use this to coordinate parallel work: you feed several scoops, then call scoop_wait to receive all their results in one go without the cone being pinged for each individual completion. Already-completed scoops (including those whose completion arrived while you were processing your previous turn) are returned immediately.`,inputSchema:{type:`object`,properties:{scoop_names:{type:`array`,items:{type:`string`},description:`Folder or display names of scoops to wait for (e.g., ["writer-scoop", "reviewer-scoop"]).`},timeout_ms:{type:`number`,description:`Optional timeout in milliseconds. If any listed scoop has not completed by the deadline, it is reported as timed-out in the result and the wait returns. Omit for no timeout.`}},required:[`scoop_names`]},execute:async e=>{let{scoop_names:t,timeout_ms:n}=e;if(!Array.isArray(t)||t.length===0)return{content:`scoop_names must be a non-empty array.`,isError:!0};if(n!==void 0&&(typeof n!=`number`||!Number.isFinite(n)||n<0))return{content:`timeout_ms must be a non-negative finite number (or omitted).`,isError:!0};let{resolved:r,unknown:a}=Z6(t,i);if(r.length===0)return{content:`No matching scoops found. Unknown: ${a.join(`, `)}`,isError:!0};let o=r.map(e=>e.jid),s=new Map(r.map(e=>[e.jid,e.folder])),c=await f(o,n);X6.info(`Wait completed`,{names:r.map(e=>e.folder),timeout_ms:n,timedOut:c.filter(e=>e.timedOut).length});let l=[];a.length>0&&l.push(`Unknown scoops (skipped): ${a.join(`, `)}`);for(let e of c){let t=s.get(e.jid)??e.jid;e.timedOut?l.push(`--- ${t} (timed out) ---`):(l.push(`--- ${t} ---`),l.push(e.summary??`(no output)`))}return{content:l.join(`
15744
+ `)}}}),c&&l&&p.push({name:`update_global_memory`,description:`Update the global CLAUDE.md memory file that is shared across all scoops. Use this instead of write_file for /shared/CLAUDE.md.`,inputSchema:{type:`object`,properties:{content:{type:`string`,description:`The new content for the global memory file`}},required:[`content`]},execute:async e=>{let{content:t}=e;try{return await c(t),X6.info(`Global memory updated`),{content:`Global memory updated successfully.`}}catch(e){return{content:`Failed to update global memory: ${e instanceof Error?e.message:String(e)}`,isError:!0}}}})),p}var $6=`slicc:adobe-daily-uuid:`,e8=new Map;function t8(){return new Date().toISOString().slice(0,10)}function n8(){try{return globalThis.localStorage??null}catch{return null}}function r8(e){let t=t8(),n=n8(),r=$6+e;if(n){let e=n.getItem(r);if(e)try{let n=JSON.parse(e);if(n.date===t&&typeof n.uuid==`string`)return n.uuid}catch{}let i=crypto.randomUUID();try{n.setItem(r,JSON.stringify({uuid:i,date:t}))}catch{}return i}let i=e8.get(e);if(i&&i.date===t)return i.uuid;let a=crypto.randomUUID();return e8.set(e,{uuid:a,date:t}),a}async function i8(e,t){let n=new TextEncoder().encode(`${t}:${e}`),r=await crypto.subtle.digest(`SHA-256`,n);return Array.from(new Uint8Array(r).slice(0,8)).map(e=>e.toString(16).padStart(2,`0`)).join(``)}async function a8(e,t){let n=r8(t??e.jid);return e.isCone?n:`${n}/${await i8(e.folder,n)}`}var o8=i({fetchSecretEnvVars:()=>c8}),s8=o(`secret-env`);async function c8(){if(typeof chrome<`u`&&chrome?.runtime?.id)return{};try{let e=await fetch(`/api/secrets/masked`);if(!e.ok)return s8.warn(`Failed to fetch masked secrets`,{status:e.status}),{};let t=await e.json();if(!Array.isArray(t)||t.length===0)return{};let n={};for(let e of t)e.name&&e.maskedValue&&(n[e.name]=e.maskedValue);return Object.keys(n).length>0&&s8.info(`Loaded masked secrets into shell env`,{count:Object.keys(n).length}),n}catch(e){return s8.debug(`Could not fetch masked secrets (server may be unavailable)`,{error:e instanceof Error?e.message:String(e)}),{}}}var l8=o(`scoop-context`);function u8(e){return/image exceeds.*maximum/i.test(e)||/Could not process image/i.test(e)||/invalid.*image/i.test(e)||/image.*too (large|big)/i.test(e)}function d8(e){return/\b(401|403|404|405|410|422)\b/.test(e)||/unauthorized|forbidden|authentication.*failed|invalid.*api.?key/i.test(e)||/model.*not.*found|invalid.*model|unknown.*model|does.*not.*exist/i.test(e)||/insufficient.*quota|billing|payment.*required|account.*suspended/i.test(e)||/invalid.*request|malformed|bad.*request/i.test(e)}function f8(e){return/\b429\b|rate.*limit|too.*many.*requests|quota.*exceeded/i.test(e)||/\b(500|502|503|504)\b|internal.*server|bad.*gateway|service.*unavailable|gateway.*timeout/i.test(e)||/network.*error|connection.*refused|timeout|econnreset|socket.*hang.*up/i.test(e)||/overloaded|temporarily.*unavailable|try.*again/i.test(e)}function p8(e,t){return t?.aborted?Promise.resolve(!0):new Promise(n=>{let r=()=>{clearTimeout(i),n(!0)},i=setTimeout(()=>{t?.removeEventListener(`abort`,r),n(!1)},e);t?.addEventListener(`abort`,r,{once:!0})})}var m8=class{scoop;callbacks;fs=null;shell=null;agent=null;status=`initializing`;isProcessing=!1;disposed=!1;didStreamDeltas=!1;unsubscribe=null;promptAbortController=null;sessionStore=null;sessionId;sessionCreatedAt=0;isRecovering=!1;coneJid;skillsFs=null;skillsDir=`/workspace/skills`;constructor(e,t,n,r,i,a){this.scoop=e,this.callbacks=t,this.fs=n,this.sessionStore=r??null,this.skillsFs=i??null,this.coneJid=a,this.sessionId=e.jid}async init(){this.setStatus(`initializing`);try{if(!this.fs)throw Error(`Filesystem not provided`);l8.info(`Filesystem ready`,{folder:this.scoop.folder}),await this.ensureDirectoryStructure();let e=this.scoop.isCone?`/`:`/scoops/${this.scoop.folder}/workspace`,t=this.callbacks.getBrowserAPI();this.skillsDir=`/workspace/skills`,this.scoop.isCone&&await J6(this.fs,this.skillsDir);let n=this.skillsFs??this.fs,r=await c8();this.shell=new e6({fs:this.fs,cwd:e,env:Object.keys(r).length>0?r:void 0,browserAPI:t,jshDiscoveryFs:this.skillsFs?n:void 0,allowedCommands:this.scoop.config?.allowedCommands,getParentJid:()=>this.scoop.jid}),l8.info(`WasmShell initialized`,{folder:this.scoop.folder});let i=await W6(n,this.skillsDir),a=Q6({scoop:this.scoop,onSendMessage:this.callbacks.onSendMessage,getScoops:this.callbacks.getScoops,getScoopTabState:this.callbacks.getScoopTabState,onFeedScoop:this.callbacks.onFeedScoop,onScoopScoop:this.callbacks.onScoopScoop,onDropScoop:this.callbacks.onDropScoop,onMuteScoops:this.callbacks.onMuteScoops,onUnmuteScoops:this.callbacks.onUnmuteScoops,onWaitForScoops:this.callbacks.onWaitForScoops,onSetGlobalMemory:this.callbacks.setGlobalMemory,getGlobalMemory:this.callbacks.getGlobalMemory}),o=c([...r6(this.fs),d6(this.shell),...a]),s=this.scoop.isCone?`/workspace/CLAUDE.md`:`/scoops/${this.scoop.folder}/CLAUDE.md`,u=``;try{let e=await this.fs.readFile(s,{encoding:`utf-8`});u=typeof e==`string`?e:new TextDecoder().decode(e)}catch{}let h=await this.callbacks.getGlobalMemory();if(h)try{this.scoop.isCone&&await(`getUnderlyingFS`in this.fs?this.fs.getUnderlyingFS():this.fs).writeFile(`/shared/CLAUDE.md`,h)}catch{}if(!l()){let e=d();throw Error(`No API key configured for provider "${e}"`)}let g=this.scoop.config?.modelId?p(this.scoop.config.modelId):f(),_=this.scoop.isCone?`Cone`:`Scoop "${this.scoop.name}"`;console.log(`[model] ${_} using model: ${g.id} (provider: ${g.provider})`);let v=this.buildSystemPrompt(h,u,i),y=[];if(this.sessionStore)try{let e=await this.sessionStore.load(this.sessionId);e&&(y=e.messages,this.sessionCreatedAt=e.createdAt,l8.info(`Restored agent session`,{folder:this.scoop.folder,messageCount:y.length}))}catch(e){l8.error(`Failed to restore agent session`,{folder:this.scoop.folder,error:e instanceof Error?e.message:String(e)}),this.callbacks.onError(`Conversation history could not be restored. Starting fresh.`)}let b=m({model:g,getApiKey:()=>l()??void 0}),x=await a8(this.scoop,this.coneJid),S=(e,t,n)=>e.provider===`adobe`?T(e,t,{...n,headers:{...n?.headers,"X-Session-Id":x}}):T(e,t,n);if(this.disposed)return;this.agent=new E({initialState:{model:g,tools:o,systemPrompt:v,messages:y},getApiKey:()=>l()??void 0,transformContext:b,streamFn:S}),this.unsubscribe=this.agent.subscribe(e=>this.handleAgentEvent(e)),this.setStatus(`ready`),l8.info(`ScoopContext initialized`,{folder:this.scoop.folder,toolCount:o.length})}catch(e){if(this.disposed)return;let t=e instanceof Error?e.message:String(e);l8.error(`ScoopContext init failed`,{folder:this.scoop.folder,error:t}),this.setStatus(`error`),this.callbacks.onError(`Failed to initialize: ${t}`)}}async prompt(e){if(!this.agent){this.callbacks.onError(`Agent not initialized`);return}let t=this.agent.state?.isStreaming??!1;if(this.isProcessing||t){l8.info(`Queueing prompt via followUp while processing`,{folder:this.scoop.folder,isProcessing:this.isProcessing,agentIsStreaming:t}),this.agent.followUp({role:`user`,content:[{type:`text`,text:e}],timestamp:Date.now()});return}let n=this.agent;this.promptAbortController?.abort();let r=new AbortController;this.promptAbortController=r;let i=r.signal;this.isProcessing=!0,this.setStatus(`processing`);let a=1e3,o=null;try{for(let t=1;t<=3;t++){if(this.disposed||i.aborted)return;this.didStreamDeltas=!1;try{await n.prompt(e),o=null;break}catch(e){if(this.disposed||i.aborted)return;o=e instanceof Error?e:Error(String(e));let n=o.message;if(d8(n)){l8.error(`Non-retryable agent error`,{folder:this.scoop.folder,error:n,attempt:t}),this.setStatus(`error`),this.callbacks.onFatalError?this.callbacks.onFatalError(`Scoop "${this.scoop.name}" failed with unrecoverable error: ${n}`):this.callbacks.onError(n);return}if(f8(n)&&t<3){let e=a*2**(t-1);if(l8.warn(`Retryable agent error, will retry`,{folder:this.scoop.folder,error:n,attempt:t,maxRetries:3,delayMs:e}),await p8(e,i)||this.disposed)return;continue}if(l8.error(`Agent error`,{folder:this.scoop.folder,error:n,attempt:t,isRetryable:f8(n)}),t===3)break;if(await p8(a*2**(t-1),i)||this.disposed)return}}if(o&&!this.disposed&&!i.aborted){let e=o.message;l8.error(`Agent error after retries exhausted`,{folder:this.scoop.folder,error:e,maxRetries:3}),this.setStatus(`error`),this.callbacks.onFatalError?this.callbacks.onFatalError(`Scoop "${this.scoop.name}" failed after 3 attempts: ${e}`):this.callbacks.onError(e);return}!this.disposed&&!i.aborted&&this.setStatus(`ready`)}finally{this.isProcessing=!1,this.promptAbortController===r&&(this.promptAbortController=null)}}stop(){this.promptAbortController?.abort(),this.agent?.clearAllQueues?.(),this.agent?.abort?.(),this.isProcessing=!1,this.setStatus(`ready`)}clearMessages(){this.agent&&(this.agent.state.messages=[])}getAgentMessages(){return this.agent?.state?.messages?structuredClone(this.agent.state.messages):[]}getSessionId(){return this.sessionId}getFS(){return this.fs}getShell(){return this.shell}updateModel(){if(!this.agent)return;let e=f();this.agent.state.model=e,l8.info(`Model updated on running agent`,{folder:this.scoop.folder,model:e.id})}async reloadSkills(){if(!this.agent)return;let e=await W6(this.skillsFs??this.fs,this.skillsDir),t=``,n=this.scoop.isCone?`/workspace/CLAUDE.md`:`/scoops/${this.scoop.folder}/CLAUDE.md`;try{let e=await this.fs.readFile(n,{encoding:`utf-8`});t=typeof e==`string`?e:new TextDecoder().decode(e)}catch{}let r=await this.callbacks.getGlobalMemory(),i=this.buildSystemPrompt(r,t,e);this.agent.state.systemPrompt=i,l8.info(`Skills reloaded`,{folder:this.scoop.folder,skillCount:e.length})}dispose(){this.disposed=!0,this.promptAbortController?.abort(),this.promptAbortController=null,this.agent?.clearAllQueues?.(),this.agent?.abort?.(),this.unsubscribe?.(),this.shell?.dispose(),this.agent=null,this.shell=null,this.fs=null}setStatus(e){this.disposed||(this.status=e,this.callbacks.onStatusChange(e))}handleAgentEvent(e){if(!this.disposed)switch(e.type){case`message_update`:{let t=e.assistantMessageEvent;t.type===`text_delta`&&(this.didStreamDeltas=!0,this.callbacks.onResponse(t.delta,!0));break}case`tool_execution_start`:this.callbacks.onToolStart?.(e.toolName,e.args);break;case`tool_execution_update`:{let t=e.partialResult;for(let n of t?.content??[])n.type===`tool_ui`&&n.requestId&&n.html?this.callbacks.onToolUI?.(e.toolName,n.requestId,n.html):n.type===`tool_ui_done`&&n.requestId&&this.callbacks.onToolUIDone?.(n.requestId);break}case`tool_execution_end`:{let t=e.result,n=[];for(let e of t?.content??[])e.type===`text`&&e.text&&n.push(e.text),e.type===`image`&&e.data&&e.mimeType&&n.push(`<img:data:${e.mimeType};base64,${e.data}>`);this.callbacks.onToolEnd?.(e.toolName,n.join(`
15745
+ `),e.isError);break}case`message_end`:if(e.message.role===`assistant`){let t=e.message.content.filter(e=>e.type===`text`).map(e=>e.text).join(``);t&&!this.didStreamDeltas&&this.callbacks.onResponse(t,!1)}break;case`turn_end`:this.callbacks.onResponseDone();break;case`agent_end`:{let t=e.messages;if(t.length>0){let e=t[t.length-1];if(e.role===`assistant`&&e.errorMessage){let n=e.errorMessage;if(!this.isRecovering&&u8(n)){this.recoverFromImageError(t);break}if(!this.isRecovering&&u(e)){this.recoverFromOverflow(t);break}this.isRecovering=!1,this.callbacks.onError(n)}else this.isRecovering=!1}let n=this.agent?.state?.messages??e.messages;this.sessionStore&&n.length>0&&this.sessionStore.save({id:this.sessionId,messages:n,config:{},createdAt:this.sessionCreatedAt||Date.now(),updatedAt:Date.now()}).catch(e=>{l8.error(`Failed to save agent session`,{folder:this.scoop.folder,error:e instanceof Error?e.message:String(e)})});break}}}recoverFromOverflow(e){if(this.agent){l8.warn(`Context overflow detected, attempting recovery`,{folder:this.scoop.folder,messageCount:e.length}),this.isRecovering=`overflow`,this.callbacks.onResponse(`Context window exceeded — recovering by trimming oversized messages...`,!1);try{let t=e.slice(0,-1),n=0;for(let e=t.length-1;e>=0&&n<5;e--){let r=t[e];if(!Array.isArray(r.content))continue;let i=0;for(let e of r.content)e.type===`text`&&e.text&&(i+=e.text.length),e.type===`image`&&e.data&&(i+=e.data.length);if(i>4e4){let a={type:`text`,text:`[Content removed: ${r.role===`toolResult`?`tool result`:r.role} was too large for context window (${Math.round(i/1e3)}K chars). The operation completed but output could not be retained.]`};if(r.role===`assistant`){let n=r.content.filter(e=>e.type===`toolCall`);t[e]={...r,content:[a,...n]}}else t[e]={...r,content:[a]};n++,l8.info(`Replaced oversized message`,{index:e,role:r.role,size:i,preservedToolCalls:r.role===`assistant`?r.content.filter(e=>e.type===`toolCall`).length:0})}}this.agent.state.messages=t;let r=n>0?`[System: Context overflow recovered. ${n} oversized message(s) were replaced with placeholders to fit within the context window. The conversation continues — you may need to re-read files or re-run commands if their output was removed.]`:`[System: Context overflow recovered. Older messages were trimmed. The conversation continues — compaction will summarize history on the next turn.]`;this.agent.prompt(r).catch(e=>{l8.error(`Recovery re-prompt failed`,{folder:this.scoop.folder,error:e instanceof Error?e.message:String(e)}),this.isRecovering=!1,this.callbacks.onError(`Context overflow recovery failed: ${e instanceof Error?e.message:String(e)}`)})}catch(e){l8.error(`Recovery failed`,{folder:this.scoop.folder,error:e instanceof Error?e.message:String(e)}),this.isRecovering=!1,this.callbacks.onError(`Context overflow recovery failed: ${e instanceof Error?e.message:String(e)}`)}}}recoverFromImageError(e){if(this.agent){l8.warn(`Image processing error detected, attempting recovery`,{folder:this.scoop.folder,messageCount:e.length}),this.isRecovering=`image`,this.callbacks.onResponse(`Image rejected by API — removing problematic images and continuing...`,!1);try{let t=e.slice(0,-1),n=0,r=Math.max(0,t.length-10);for(let e=t.length-1;e>=r;e--){let r=t[e];if(!Array.isArray(r.content)||!r.content.some(e=>e.type===`image`))continue;let i=r.content.filter(e=>e.type!==`image`);i.length===0?t[e]={...r,content:[{type:`text`,text:`[Image removed: rejected by API]`}]}:t[e]={...r,content:i},n++}this.agent.state.messages=t;let i=`[System: An image was rejected by the API and has been removed from the conversation (${n} message(s) affected). The conversation continues without the image.]`;this.agent.prompt(i).catch(e=>{l8.error(`Image recovery re-prompt failed`,{folder:this.scoop.folder,error:e instanceof Error?e.message:String(e)}),this.isRecovering=!1,this.callbacks.onError(`Image error recovery failed: ${e instanceof Error?e.message:String(e)}`)})}catch(e){l8.error(`Image recovery failed`,{folder:this.scoop.folder,error:e instanceof Error?e.message:String(e)}),this.isRecovering=!1,this.callbacks.onError(`Image error recovery failed: ${e instanceof Error?e.message:String(e)}`)}}}async ensureDirectoryStructure(){if(!this.fs)return;let e=this.scoop.isCone?[`/workspace`,`/shared`,`/scoops`,`/home`,`/tmp`,`/mnt`]:[`/scoops/${this.scoop.folder}`,`/scoops/${this.scoop.folder}/workspace`,`/scoops/${this.scoop.folder}/home`,`/scoops/${this.scoop.folder}/tmp`,`/shared`];for(let t of e)try{await this.fs.mkdir(t,{recursive:!0})}catch{}let t=this.scoop.isCone?`/workspace/CLAUDE.md`:`/scoops/${this.scoop.folder}/CLAUDE.md`;try{await this.fs.readFile(t)}catch{let e=`# ${this.scoop.assistantLabel} Memory
15746
15746
 
15747
15747
  ${this.scoop.isCone?`Role: Cone (main orchestrator)`:`Scoop: ${this.scoop.name}`}
15748
15748
  Folder: ${this.scoop.folder}
@@ -15753,7 +15753,7 @@ Created: ${new Date().toISOString()}
15753
15753
 
15754
15754
  ## Context
15755
15755
  (Add important context here)
15756
- `;try{await this.fs.writeFile(t,e)}catch(e){if(e?.code===`EACCES`)o8.debug(`Skipping default memory write (sandbox is read-only)`,{folder:this.scoop.folder,path:t});else throw e}}}buildSystemPrompt(e,t,n){let r=this.scoop.config?.assistantName||this.scoop.assistantLabel,i=`# ${r}
15756
+ `;try{await this.fs.writeFile(t,e)}catch(e){if(e?.code===`EACCES`)l8.debug(`Skipping default memory write (sandbox is read-only)`,{folder:this.scoop.folder,path:t});else throw e}}}buildSystemPrompt(e,t,n){let r=this.scoop.config?.assistantName||this.scoop.assistantLabel,i=`# ${r}
15757
15757
 
15758
15758
  You are ${r}, ${this.scoop.isCone?`the main assistant (cone)`:`a scoop assistant`} in SLICC (Self-Licking Ice Cream Cone).
15759
15759
 
@@ -15821,18 +15821,18 @@ ${e}
15821
15821
  ---
15822
15822
  ${this.scoop.isCone?`CONE`:`SCOOP`} MEMORY (${this.scoop.name}):
15823
15823
  ${t}
15824
- ---`);let a=W6(n);return a&&(i+=a),i}},f8=o(`scheduler`),p8=class{callbacks;pollInterval=null;running=!1;constructor(e){this.callbacks=e}start(){this.running||(this.running=!0,this.pollInterval=window.setInterval(()=>this.checkTasks(),6e4),this.checkTasks(),f8.info(`Scheduler started`))}stop(){this.pollInterval&&=(clearInterval(this.pollInterval),null),this.running=!1,f8.info(`Scheduler stopped`)}async createTask(e,t,n,r){let i={id:`task-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,groupFolder:e,prompt:t,scheduleType:n,scheduleValue:r,status:`active`,nextRun:this.calculateNextRun(n,r),lastRun:null,createdAt:new Date().toISOString()};return await Te(i),f8.info(`Task created`,{id:i.id,groupFolder:e,scheduleType:n}),i}async updateTask(e,t){let n=await ge(e);if(!n)return null;let r={...n,...t};return(t.scheduleType||t.scheduleValue)&&(r.nextRun=this.calculateNextRun(r.scheduleType,r.scheduleValue)),await Te(r),f8.info(`Task updated`,{id:e,updates:Object.keys(t)}),r}async pauseTask(e){return await this.updateTask(e,{status:`paused`})!==null}async resumeTask(e){return await ge(e)?(await this.updateTask(e,{status:`active`}),!0):!1}async deleteTask(e){return await ge(e)?(await ce(e),f8.info(`Task deleted`,{id:e}),!0):!1}async getTasksByScoop(e){return(await he()).filter(t=>t.groupFolder===e)}async getAllTasks(){return he()}async checkTasks(){let e=await he(),t=new Date;for(let n of e)n.status===`active`&&n.nextRun&&(new Date(n.nextRun)>t||await this.runTask(n))}async runTask(e){let t=this.callbacks.getScoop(e.groupFolder);if(!t){f8.warn(`Task scoop not found`,{taskId:e.id,groupFolder:e.groupFolder});return}f8.info(`Running task`,{id:e.id,groupFolder:e.groupFolder});try{let n=new Date().toISOString(),r=this.calculateNextRun(e.scheduleType,e.scheduleValue),i=e.scheduleType===`once`?`completed`:e.status;await Te({...e,lastRun:n,nextRun:r,status:i}),await this.callbacks.onTaskRun(e,t),f8.info(`Task completed`,{id:e.id})}catch(t){f8.error(`Task execution failed`,{id:e.id,error:t instanceof Error?t.message:String(t)})}}calculateNextRun(e,t){let n=new Date;switch(e){case`cron`:return this.getNextCronTime(t,n)?.toISOString()??null;case`interval`:{let e=parseInt(t,10);return isNaN(e)||e<=0?null:new Date(n.getTime()+e).toISOString()}case`once`:return new Date(t)>n?t:null;default:return null}}getNextCronTime(e,t){let n=e.trim().split(/\s+/);if(n.length!==5)return null;let[r,i,a,o,s]=n,c=new Date(t);c.setSeconds(0),c.setMilliseconds(0),c.setMinutes(c.getMinutes()+1);for(let e=0;e<527040;e++){if(this.cronMatches(c,r,i,a,o,s))return c;c.setMinutes(c.getMinutes()+1)}return null}cronMatches(e,t,n,r,i,a){return this.cronFieldMatches(e.getMinutes(),t)&&this.cronFieldMatches(e.getHours(),n)&&this.cronFieldMatches(e.getDate(),r)&&this.cronFieldMatches(e.getMonth()+1,i)&&this.cronFieldMatches(e.getDay(),a)}cronFieldMatches(e,t){if(t===`*`)return!0;if(t.includes(`,`))return t.split(`,`).some(t=>this.cronFieldMatches(e,t.trim()));if(t.includes(`-`)){let[n,r]=t.split(`-`).map(e=>parseInt(e,10));return e>=n&&e<=r}if(t.includes(`/`)){let[n,r]=t.split(`/`),i=parseInt(r,10);if(n===`*`)return e%i===0;let a=parseInt(n,10);return e>=a&&(e-a)%i===0}return parseInt(t,10)===e}},m8=i({LickManager:()=>g8,buildActiveLicksError:()=>_8,getLickManager:()=>y8}),h8=o(`lick-manager`),g8=class{webhooks=new Map;crontasks=new Map;cronInterval=null;eventHandler=null;async init(){await pe();let e=await Se();for(let t of e)this.webhooks.set(t.id,t);h8.info(`Loaded webhooks`,{count:this.webhooks.size});let t=await xe();for(let e of t)this.crontasks.set(e.id,e);h8.info(`Loaded crontasks`,{count:this.crontasks.size}),this.cronInterval=setInterval(()=>this.runCronScheduler(),6e4),h8.info(`Cron scheduler started`)}dispose(){this.cronInterval&&=(clearInterval(this.cronInterval),null)}setEventHandler(e){this.eventHandler=e}emitEvent(e){h8.info(`External lick event`,{type:e.type,target:e.targetScoop}),this.eventHandler?.(e)}async createWebhook(e,t,n){let r=this.generateId(),i={id:r,name:e,createdAt:new Date().toISOString(),filter:n,scoop:t};return n&&this.compileFilter(n,!0),this.webhooks.set(r,i),await le(i),h8.info(`Webhook created`,{id:r,name:e,scoop:t}),i}async deleteWebhook(e){return this.webhooks.has(e)?(this.webhooks.delete(e),await ve(e),h8.info(`Webhook deleted`,{id:e}),!0):!1}listWebhooks(){return Array.from(this.webhooks.values())}getWebhook(e){return this.webhooks.get(e)}handleWebhookEvent(e,t,n){let r=this.webhooks.get(e);if(!r){h8.warn(`Webhook not found`,{webhookId:e});return}let i={type:`webhook`,webhookId:e,webhookName:r.name,targetScoop:r.scoop,timestamp:new Date().toISOString(),headers:t,body:n};if(r.filter)try{let t=this.compileFilter(r.filter,!0)(i);if(t===!1){h8.debug(`Webhook event dropped by filter`,{webhookId:e,name:r.name});return}typeof t==`object`&&t&&(i=t)}catch(t){h8.error(`Webhook filter error`,{webhookId:e,error:t instanceof Error?t.message:String(t)})}h8.info(`Webhook event received`,{webhookId:e,name:r.name,targetScoop:r.scoop}),this.eventHandler?.(i)}async createCronTask(e,t,n,r){let i=this.getNextCronTime(t,new Date);if(!i)throw Error(`Invalid cron expression`);r&&this.compileFilter(r,!1);let a=this.generateId(),o={id:a,name:e,cron:t,scoop:n,filter:r,nextRun:i.toISOString(),lastRun:null,status:`active`,createdAt:new Date().toISOString()};return this.crontasks.set(a,o),await A(o),h8.info(`Cron task created`,{id:a,name:e,cron:t,scoop:n}),o}async deleteCronTask(e){return this.crontasks.has(e)?(this.crontasks.delete(e),await _e(e),h8.info(`Cron task deleted`,{id:e}),!0):!1}listCronTasks(){return Array.from(this.crontasks.values())}getCronTask(e){return this.crontasks.get(e)}getLicksForScoop(e,t){let n=n=>n===e||n===t||`${n}-scoop`===t;return{webhooks:Array.from(this.webhooks.values()).filter(e=>n(e.scoop)),cronTasks:Array.from(this.crontasks.values()).filter(e=>n(e.scoop))}}async runCronScheduler(){let e=new Date;for(let t of this.crontasks.values()){if(t.status!==`active`||!t.nextRun||new Date(t.nextRun)>e)continue;let n={time:e.toISOString()};if(t.filter)try{let r=this.compileFilter(t.filter,!1)(null);if(r===!1){h8.debug(`Cron task skipped by filter`,{id:t.id,name:t.name}),t.nextRun=this.getNextCronTime(t.cron,e)?.toISOString()??null,t.lastRun=e.toISOString(),await A(t);continue}typeof r==`object`&&r&&(n=r)}catch(e){h8.error(`Cron filter error`,{id:t.id,error:e instanceof Error?e.message:String(e)})}let r={type:`cron`,cronId:t.id,cronName:t.name,targetScoop:t.scoop,timestamp:e.toISOString(),body:n};h8.info(`Cron task running`,{id:t.id,name:t.name}),this.eventHandler?.(r),t.nextRun=this.getNextCronTime(t.cron,e)?.toISOString()??null,t.lastRun=e.toISOString(),await A(t)}}generateId(){let e=``;for(let t=0;t<12;t++)e+=`abcdefghijklmnopqrstuvwxyz0123456789`[Math.floor(Math.random()*36)];return e}compileFilter(e,t){try{return t?Function(`event`,`return (${e})(event);`):Function(`return (${e})();`)}catch(e){throw Error(`Invalid filter function: ${e instanceof Error?e.message:String(e)}`)}}getNextCronTime(e,t){let n=e.trim().split(/\s+/);if(n.length!==5)return null;let[r,i,a,o,s]=n,c=new Date(t);c.setSeconds(0),c.setMilliseconds(0),c.setMinutes(c.getMinutes()+1);let l=(e,t)=>{if(t===`*`)return!0;if(t.includes(`,`))return t.split(`,`).some(t=>l(e,t.trim()));if(t.includes(`-`)){let[n,r]=t.split(`-`).map(e=>parseInt(e,10));return e>=n&&e<=r}if(t.includes(`/`)){let[n,r]=t.split(`/`),i=parseInt(r,10);if(n===`*`)return e%i===0;let a=parseInt(n,10);return e>=a&&(e-a)%i===0}return parseInt(t,10)===e};for(let e=0;e<527040;e++){if(l(c.getMinutes(),r)&&l(c.getHours(),i)&&l(c.getDate(),a)&&l(c.getMonth()+1,o)&&l(c.getDay(),s))return c;c.setMinutes(c.getMinutes()+1)}return null}};function _8(e,t,n){if(t.length===0&&n.length===0)return null;let r=[];t.length>0&&r.push(`${t.length} active webhook${t.length>1?`s`:``}`),n.length>0&&r.push(`${n.length} active cron task${n.length>1?`s`:``}`);let i=[...t.map(e=>` webhook delete ${e.id}`),...n.map(e=>` crontask delete ${e.id}`)].join(`
15825
- `);return Error(`Cannot remove scoop '${e}': it has ${r.join(` and `)}. Unregister them first:\n${i}`)}var v8=null;function y8(){return v8||=new g8,v8}var b8=o(`orchestrator`),x8=120*1e3,S8=`/shared/scoop-notifications`,C8=200,w8=1e3;function T8(e){let t=e.replace(/\r\n?/g,`
15824
+ ---`);let a=q6(n);return a&&(i+=a),i}},h8=o(`scheduler`),g8=class{callbacks;pollInterval=null;running=!1;constructor(e){this.callbacks=e}start(){this.running||(this.running=!0,this.pollInterval=window.setInterval(()=>this.checkTasks(),6e4),this.checkTasks(),h8.info(`Scheduler started`))}stop(){this.pollInterval&&=(clearInterval(this.pollInterval),null),this.running=!1,h8.info(`Scheduler stopped`)}async createTask(e,t,n,r){let i={id:`task-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,groupFolder:e,prompt:t,scheduleType:n,scheduleValue:r,status:`active`,nextRun:this.calculateNextRun(n,r),lastRun:null,createdAt:new Date().toISOString()};return await Te(i),h8.info(`Task created`,{id:i.id,groupFolder:e,scheduleType:n}),i}async updateTask(e,t){let n=await ge(e);if(!n)return null;let r={...n,...t};return(t.scheduleType||t.scheduleValue)&&(r.nextRun=this.calculateNextRun(r.scheduleType,r.scheduleValue)),await Te(r),h8.info(`Task updated`,{id:e,updates:Object.keys(t)}),r}async pauseTask(e){return await this.updateTask(e,{status:`paused`})!==null}async resumeTask(e){return await ge(e)?(await this.updateTask(e,{status:`active`}),!0):!1}async deleteTask(e){return await ge(e)?(await ce(e),h8.info(`Task deleted`,{id:e}),!0):!1}async getTasksByScoop(e){return(await he()).filter(t=>t.groupFolder===e)}async getAllTasks(){return he()}async checkTasks(){let e=await he(),t=new Date;for(let n of e)n.status===`active`&&n.nextRun&&(new Date(n.nextRun)>t||await this.runTask(n))}async runTask(e){let t=this.callbacks.getScoop(e.groupFolder);if(!t){h8.warn(`Task scoop not found`,{taskId:e.id,groupFolder:e.groupFolder});return}h8.info(`Running task`,{id:e.id,groupFolder:e.groupFolder});try{let n=new Date().toISOString(),r=this.calculateNextRun(e.scheduleType,e.scheduleValue),i=e.scheduleType===`once`?`completed`:e.status;await Te({...e,lastRun:n,nextRun:r,status:i}),await this.callbacks.onTaskRun(e,t),h8.info(`Task completed`,{id:e.id})}catch(t){h8.error(`Task execution failed`,{id:e.id,error:t instanceof Error?t.message:String(t)})}}calculateNextRun(e,t){let n=new Date;switch(e){case`cron`:return this.getNextCronTime(t,n)?.toISOString()??null;case`interval`:{let e=parseInt(t,10);return isNaN(e)||e<=0?null:new Date(n.getTime()+e).toISOString()}case`once`:return new Date(t)>n?t:null;default:return null}}getNextCronTime(e,t){let n=e.trim().split(/\s+/);if(n.length!==5)return null;let[r,i,a,o,s]=n,c=new Date(t);c.setSeconds(0),c.setMilliseconds(0),c.setMinutes(c.getMinutes()+1);for(let e=0;e<527040;e++){if(this.cronMatches(c,r,i,a,o,s))return c;c.setMinutes(c.getMinutes()+1)}return null}cronMatches(e,t,n,r,i,a){return this.cronFieldMatches(e.getMinutes(),t)&&this.cronFieldMatches(e.getHours(),n)&&this.cronFieldMatches(e.getDate(),r)&&this.cronFieldMatches(e.getMonth()+1,i)&&this.cronFieldMatches(e.getDay(),a)}cronFieldMatches(e,t){if(t===`*`)return!0;if(t.includes(`,`))return t.split(`,`).some(t=>this.cronFieldMatches(e,t.trim()));if(t.includes(`-`)){let[n,r]=t.split(`-`).map(e=>parseInt(e,10));return e>=n&&e<=r}if(t.includes(`/`)){let[n,r]=t.split(`/`),i=parseInt(r,10);if(n===`*`)return e%i===0;let a=parseInt(n,10);return e>=a&&(e-a)%i===0}return parseInt(t,10)===e}},_8=i({LickManager:()=>y8,buildActiveLicksError:()=>b8,getLickManager:()=>S8}),v8=o(`lick-manager`),y8=class{webhooks=new Map;crontasks=new Map;cronInterval=null;eventHandler=null;async init(){await pe();let e=await Se();for(let t of e)this.webhooks.set(t.id,t);v8.info(`Loaded webhooks`,{count:this.webhooks.size});let t=await xe();for(let e of t)this.crontasks.set(e.id,e);v8.info(`Loaded crontasks`,{count:this.crontasks.size}),this.cronInterval=setInterval(()=>this.runCronScheduler(),6e4),v8.info(`Cron scheduler started`)}dispose(){this.cronInterval&&=(clearInterval(this.cronInterval),null)}setEventHandler(e){this.eventHandler=e}emitEvent(e){v8.info(`External lick event`,{type:e.type,target:e.targetScoop}),this.eventHandler?.(e)}async createWebhook(e,t,n){let r=this.generateId(),i={id:r,name:e,createdAt:new Date().toISOString(),filter:n,scoop:t};return n&&this.compileFilter(n,!0),this.webhooks.set(r,i),await le(i),v8.info(`Webhook created`,{id:r,name:e,scoop:t}),i}async deleteWebhook(e){return this.webhooks.has(e)?(this.webhooks.delete(e),await ve(e),v8.info(`Webhook deleted`,{id:e}),!0):!1}listWebhooks(){return Array.from(this.webhooks.values())}getWebhook(e){return this.webhooks.get(e)}handleWebhookEvent(e,t,n){let r=this.webhooks.get(e);if(!r){v8.warn(`Webhook not found`,{webhookId:e});return}let i={type:`webhook`,webhookId:e,webhookName:r.name,targetScoop:r.scoop,timestamp:new Date().toISOString(),headers:t,body:n};if(r.filter)try{let t=this.compileFilter(r.filter,!0)(i);if(t===!1){v8.debug(`Webhook event dropped by filter`,{webhookId:e,name:r.name});return}typeof t==`object`&&t&&(i=t)}catch(t){v8.error(`Webhook filter error`,{webhookId:e,error:t instanceof Error?t.message:String(t)})}v8.info(`Webhook event received`,{webhookId:e,name:r.name,targetScoop:r.scoop}),this.eventHandler?.(i)}async createCronTask(e,t,n,r){let i=this.getNextCronTime(t,new Date);if(!i)throw Error(`Invalid cron expression`);r&&this.compileFilter(r,!1);let a=this.generateId(),o={id:a,name:e,cron:t,scoop:n,filter:r,nextRun:i.toISOString(),lastRun:null,status:`active`,createdAt:new Date().toISOString()};return this.crontasks.set(a,o),await A(o),v8.info(`Cron task created`,{id:a,name:e,cron:t,scoop:n}),o}async deleteCronTask(e){return this.crontasks.has(e)?(this.crontasks.delete(e),await _e(e),v8.info(`Cron task deleted`,{id:e}),!0):!1}listCronTasks(){return Array.from(this.crontasks.values())}getCronTask(e){return this.crontasks.get(e)}getLicksForScoop(e,t){let n=n=>n===e||n===t||`${n}-scoop`===t;return{webhooks:Array.from(this.webhooks.values()).filter(e=>n(e.scoop)),cronTasks:Array.from(this.crontasks.values()).filter(e=>n(e.scoop))}}async runCronScheduler(){let e=new Date;for(let t of this.crontasks.values()){if(t.status!==`active`||!t.nextRun||new Date(t.nextRun)>e)continue;let n={time:e.toISOString()};if(t.filter)try{let r=this.compileFilter(t.filter,!1)(null);if(r===!1){v8.debug(`Cron task skipped by filter`,{id:t.id,name:t.name}),t.nextRun=this.getNextCronTime(t.cron,e)?.toISOString()??null,t.lastRun=e.toISOString(),await A(t);continue}typeof r==`object`&&r&&(n=r)}catch(e){v8.error(`Cron filter error`,{id:t.id,error:e instanceof Error?e.message:String(e)})}let r={type:`cron`,cronId:t.id,cronName:t.name,targetScoop:t.scoop,timestamp:e.toISOString(),body:n};v8.info(`Cron task running`,{id:t.id,name:t.name}),this.eventHandler?.(r),t.nextRun=this.getNextCronTime(t.cron,e)?.toISOString()??null,t.lastRun=e.toISOString(),await A(t)}}generateId(){let e=``;for(let t=0;t<12;t++)e+=`abcdefghijklmnopqrstuvwxyz0123456789`[Math.floor(Math.random()*36)];return e}compileFilter(e,t){try{return t?Function(`event`,`return (${e})(event);`):Function(`return (${e})();`)}catch(e){throw Error(`Invalid filter function: ${e instanceof Error?e.message:String(e)}`)}}getNextCronTime(e,t){let n=e.trim().split(/\s+/);if(n.length!==5)return null;let[r,i,a,o,s]=n,c=new Date(t);c.setSeconds(0),c.setMilliseconds(0),c.setMinutes(c.getMinutes()+1);let l=(e,t)=>{if(t===`*`)return!0;if(t.includes(`,`))return t.split(`,`).some(t=>l(e,t.trim()));if(t.includes(`-`)){let[n,r]=t.split(`-`).map(e=>parseInt(e,10));return e>=n&&e<=r}if(t.includes(`/`)){let[n,r]=t.split(`/`),i=parseInt(r,10);if(n===`*`)return e%i===0;let a=parseInt(n,10);return e>=a&&(e-a)%i===0}return parseInt(t,10)===e};for(let e=0;e<527040;e++){if(l(c.getMinutes(),r)&&l(c.getHours(),i)&&l(c.getDate(),a)&&l(c.getMonth()+1,o)&&l(c.getDay(),s))return c;c.setMinutes(c.getMinutes()+1)}return null}};function b8(e,t,n){if(t.length===0&&n.length===0)return null;let r=[];t.length>0&&r.push(`${t.length} active webhook${t.length>1?`s`:``}`),n.length>0&&r.push(`${n.length} active cron task${n.length>1?`s`:``}`);let i=[...t.map(e=>` webhook delete ${e.id}`),...n.map(e=>` crontask delete ${e.id}`)].join(`
15825
+ `);return Error(`Cannot remove scoop '${e}': it has ${r.join(` and `)}. Unregister them first:\n${i}`)}var x8=null;function S8(){return x8||=new y8,x8}var C8=o(`orchestrator`),w8=120*1e3,T8=`/shared/scoop-notifications`,E8=200,D8=1e3;function O8(e){let t=e.replace(/\r\n?/g,`
15826
15826
  `);if(t.length===0)return 0;let n=1;for(let e=0;e<t.length;e++)t[e]===`
15827
15827
  `&&n++;return t.endsWith(`
15828
- `)?n-1:n}var E8=class{scoops=new Map;tabs=new Map;contexts=new Map;messageQueues=new Map;lastAgentTimestamp=new Map;container;callbacks;config;pollInterval=null;scheduler=null;globalMemoryCache=``;sharedFs=null;scoopResponseBuffer=new Map;lickManager=null;sessionStore=null;fsWatcher=null;idleTimers=new Map;droppedScoopCosts=[];scoopObservers=new Map;mutedScoops=new Set;pendingCompletions=new Map;completionWaiters=new Map;constructor(e,t,n={name:`sliccy`,triggerPattern:/^@sliccy\b/i}){this.container=e,this.callbacks=t,this.config=n}async init(){await pe(),this.sharedFs=await Hs.create({dbName:`slicc-fs`}),this.sessionStore=new w,this.fsWatcher=new qs,this.sharedFs.setWatcher(this.fsWatcher),globalThis.__slicc_fs_watcher=this.fsWatcher,await this.ensureRootStructure();let e=await ue();for(let t of Object.values(e)){t.isCone&&(t.trigger=void 0,t.requiresTrigger=!1,t.assistantLabel=t.assistantLabel||`sliccy`),this.migrateScoopConfig(t),this.scoops.set(t.jid,t),this.messageQueues.set(t.jid,[]);let e=await ye(`lastAgentTs_${t.jid}`);e&&this.lastAgentTimestamp.set(t.jid,e)}await this.ensureGlobalMemory(),this.scheduler=new p8({onTaskRun:async(e,t)=>{b8.info(`Running scheduled task`,{taskId:e.id,scoop:t.name}),await this.sendPrompt(t.jid,`[SCHEDULED TASK]\n\n${e.prompt}`,`scheduler`,`Scheduled Task`)},getScoop:e=>{for(let t of this.scoops.values())if(t.folder===e)return t}}),this.scheduler.start(),b8.info(`Orchestrator initialized`,{scoopCount:this.scoops.size});for(let e of this.scoops.values())await this.createScoopTab(e.jid);W2(()=>this.getSessionCosts()),this.startMessageLoop()}migrateScoopConfig(e){if(e.isCone)return;let t=e.configSchemaVersion??0;t>=2||(t<1&&(e.config={...e.config,visiblePaths:e.config?.visiblePaths??[`/workspace/`]}),t<2&&(e.config={...e.config,writablePaths:e.config?.writablePaths??[`/scoops/${e.folder}/`,`/shared/`]}),e.configSchemaVersion=2)}async ensureRootStructure(){if(this.sharedFs)for(let e of[`/workspace`,`/shared`,`/scoops`,`/home`,`/tmp`,`/mnt`])try{await this.sharedFs.mkdir(e,{recursive:!0})}catch{}}async ensureGlobalMemory(){if(this.sharedFs){await K6(this.sharedFs);try{let e=await this.sharedFs.readFile(`/shared/CLAUDE.md`,{encoding:`utf-8`});this.globalMemoryCache=typeof e==`string`?e:new TextDecoder().decode(e)}catch{b8.warn(`Global memory file not found after creating defaults`)}}}async getGlobalMemory(){if(this.globalMemoryCache)return this.globalMemoryCache;if(this.sharedFs)try{let e=await this.sharedFs.readFile(`/shared/CLAUDE.md`,{encoding:`utf-8`});this.globalMemoryCache=typeof e==`string`?e:new TextDecoder().decode(e)}catch{}return this.globalMemoryCache}async setGlobalMemory(e){this.sharedFs&&(await this.sharedFs.writeFile(`/shared/CLAUDE.md`,e),this.globalMemoryCache=e,b8.info(`Global memory updated`))}getSharedFS(){return this.sharedFs}getSessionStore(){return this.sessionStore}setLickManager(e){this.lickManager=e,globalThis.__slicc_lick_handler=e=>{this.lickManager?.emitEvent(e)}}observeScoop(e,t){let n=this.scoopObservers.get(e);return n||(n=new Set,this.scoopObservers.set(e,n)),n.add(t),()=>{let n=this.scoopObservers.get(e);n&&(n.delete(t),n.size===0&&this.scoopObservers.delete(e))}}async maybeNotifyConeOnScoopComplete(e){let t=this.scoops.get(e);if(!t||t.isCone)return;let n=this.scoopResponseBuffer.get(e);if(this.scoopResponseBuffer.delete(e),!n||t.notifyOnComplete===!1)return;let r=this.completionWaiters.get(e);if(r&&r.length>0){this.completionWaiters.delete(e);let t=n.length>2e4?n.slice(0,2e4)+`
15829
- ... (truncated)`:n;for(let n of r)try{n(t)}catch(t){b8.warn(`completion waiter threw`,{jid:e,error:t instanceof Error?t.message:String(t)})}return}if(this.mutedScoops.has(e)){this.pendingCompletions.set(e,{responseText:n,timestamp:new Date().toISOString()}),b8.info(`Scoop completion stashed (muted)`,{scoop:t.folder,responseLength:n.length});return}await this.deliverCompletionToCone(t,n)}async deliverCompletionToCone(e,t){let n=Array.from(this.scoops.values()).find(e=>e.isCone);if(!n)return;let r=T8(t),i=t.slice(0,w8),a,o=null,s=null;try{s=await this.writeScoopCompletionArtifact(e,t),b8.info(`Routing scoop completion to cone`,{scoop:e.folder,responseLength:t.length,lineCount:r,notificationPath:s})}catch(t){o=t instanceof Error?t.message:String(t),b8.warn(`Failed to persist scoop completion artifact, falling back to inline preview`,{scoop:e.folder,error:o})}a=o===null?this.formatScoopCompletionNotification(e.assistantLabel,s??`unavailable`,r,i):this.formatScoopCompletionFallbackNotification(e.assistantLabel,r,i,o);let c={id:`scoop-done-${e.jid}-${Date.now()}`,chatJid:n.jid,senderId:e.folder,senderName:e.assistantLabel,content:a,timestamp:new Date().toISOString(),fromAssistant:!1,channel:`scoop-notify`};try{this.callbacks.onIncomingMessage?.(n.jid,c)}catch(t){b8.warn(`onIncomingMessage for scoop-notify threw`,{scoop:e.folder,error:t instanceof Error?t.message:String(t)})}try{await this.handleMessage(c)}catch(t){let r=t instanceof Error?t.message:String(t);b8.error(`Failed to route scoop completion to cone`,{scoop:e.folder,error:r}),this.callbacks.onError(n.jid,`Scoop ${e.folder} completed but notification failed: ${r}`)}}async writeScoopCompletionArtifact(e,t){if(!this.sharedFs)throw Error(`Shared filesystem not initialized`);await this.sharedFs.mkdir(S8,{recursive:!0}),await this.pruneScoopCompletionArtifacts(C8-1);let n=new Date().toISOString().replace(/[:.]/g,`-`),r=Math.random().toString(36).slice(2,8),i=`${S8}/${n}-${e.folder}-${r}.md`;return await this.sharedFs.writeFile(i,t),await this.pruneScoopCompletionArtifacts(),i}async pruneScoopCompletionArtifacts(e=C8){if(!this.sharedFs)return;let t;try{t=await this.sharedFs.readDir(S8)}catch{return}let n=t.filter(e=>e.type===`file`).map(e=>e.name).sort(),r=n.length-e;if(!(r<=0))for(let e of n.slice(0,r)){let t=`${S8}/${e}`;try{await this.sharedFs.rm(t)}catch(e){b8.warn(`Failed to prune scoop completion artifact`,{path:t,error:e instanceof Error?e.message:String(e)})}}}formatScoopCompletionNotification(e,t,n,r){return[`[@${e} completed]`,`VFS path: ${t}`,`Total lines: ${n}`,`Preview (up to ${w8} chars):`,r].join(`
15830
- `)}formatScoopCompletionFallbackNotification(e,t,n,r){return[`[@${e} completed]`,`VFS path: unavailable`,`Artifact persistence error: ${r}`,`Total lines: ${t}`,`Preview (up to ${w8} chars):`,n].join(`
15831
- `)}muteScoops(e){for(let t of e)this.mutedScoops.add(t);b8.info(`Scoops muted`,{count:e.length})}async unmuteScoops(e){let t=[],n=[];for(let r of e){this.mutedScoops.delete(r);let e=this.pendingCompletions.get(r);if(!e)continue;this.pendingCompletions.delete(r);let i=this.scoops.get(r);if(!i||i.isCone)continue;let a={jid:r,summary:e.responseText.length>2e4?e.responseText.slice(0,2e4)+`
15832
- ... (truncated)`:e.responseText,timestamp:e.timestamp,notificationPath:null};t.push(a),n.push(this.writeScoopCompletionArtifact(i,e.responseText).then(e=>{a.notificationPath=e}).catch(e=>{b8.warn(`unmute artifact persist failed`,{jid:r,error:e instanceof Error?e.message:String(e)})}))}return await Promise.all(n),b8.info(`Scoops unmuted`,{count:e.length,consumed:t.length}),t}isScoopMuted(e){return this.mutedScoops.has(e)}async waitForScoops(e,t){if(e.length===0)return[];let n=Array.from(new Set(e)),r=new Map,i=[];for(let e of n)this.mutedScoops.has(e)||(this.mutedScoops.add(e),i.push(e));for(let e of n){let t=this.pendingCompletions.get(e);if(t){this.pendingCompletions.delete(e);let n=t.responseText.length>2e4?t.responseText.slice(0,2e4)+`
15833
- ... (truncated)`:t.responseText;r.set(e,{summary:n,timedOut:!1})}}let a=n.filter(e=>!r.has(e)),o=a.filter(e=>this.scoops.has(e)),s=a.filter(e=>!this.scoops.has(e));for(let e of s)r.set(e,{summary:null,timedOut:!0});let c=[],l=o.map(e=>new Promise(t=>{let n=n=>{r.has(e)||(r.set(e,{summary:n,timedOut:n===null}),t())};c.push({jid:e,waiter:n});let i=this.completionWaiters.get(e);i||(i=[],this.completionWaiters.set(e,i)),i.push(n)})),u=null;try{l.length>0&&(t!=null&&t>=0?await Promise.race([Promise.all(l),new Promise(e=>{u=setTimeout(()=>e(),t)})]):await Promise.all(l))}finally{u&&clearTimeout(u);for(let{jid:e,waiter:t}of c){let n=this.completionWaiters.get(e);if(!n)continue;let r=n.indexOf(t);r!==-1&&n.splice(r,1),n.length===0&&this.completionWaiters.delete(e)}for(let e of i)this.mutedScoops.delete(e)}for(let e of o)r.has(e)||r.set(e,{summary:null,timedOut:!0});return e.map(e=>{let t=r.get(e)??{summary:null,timedOut:!0};return{jid:e,summary:t.summary,timedOut:t.timedOut}})}dispatchScoopEvent(e,t,...n){let r=this.scoopObservers.get(e);if(r)for(let i of r){let r=i[t];if(r)try{r(...n)}catch(n){b8.warn(`scoop observer threw`,{jid:e,event:t,error:n instanceof Error?n.message:String(n)})}}}async registerScoop(e){await Ce(e),this.scoops.set(e.jid,e),this.messageQueues.set(e.jid,[]),b8.info(`Scoop registered`,{jid:e.jid,name:e.name});try{await this.createScoopTab(e.jid)}catch(t){throw b8.error(`Scoop init failed`,{jid:e.jid,name:e.name,error:t instanceof Error?t.message:String(t)}),await this.destroyScoopTab(e.jid).catch(()=>{}),this.scoops.delete(e.jid),this.messageQueues.delete(e.jid),await me(e.jid).catch(t=>{b8.warn(`Failed to rollback scoop registration`,{jid:e.jid,name:e.name,error:t instanceof Error?t.message:String(t)})}),t}}async unregisterScoop(e){let t=this.scoops.get(e);if(t&&this.lickManager){let{webhooks:e,cronTasks:n}=this.lickManager.getLicksForScoop(t.name,t.folder),r=_8(t.folder,e,n);if(r)throw r}this.snapshotScoopCost(e),this.clearIdleTimer(e),await this.destroyScoopTab(e),this.sessionStore?.delete(e).catch(t=>{b8.warn(`Failed to delete agent session`,{jid:e,error:t instanceof Error?t.message:String(t)})}),await me(e),this.scoops.delete(e),this.messageQueues.delete(e),this.lastAgentTimestamp.delete(e),this.scoopResponseBuffer.delete(e),this.scoopObservers.delete(e);let n=this.completionWaiters.get(e);if(n){this.completionWaiters.delete(e);for(let t of n)try{t(null)}catch(t){b8.warn(`completion waiter threw on unregister`,{jid:e,error:t instanceof Error?t.message:String(t)})}}this.mutedScoops.delete(e),this.pendingCompletions.delete(e),b8.info(`Scoop unregistered`,{jid:e})}getScoops(){return Array.from(this.scoops.values())}getScoop(e){return this.scoops.get(e)}async resetFilesystem(){for(let[e,t]of this.contexts.entries())this.clearIdleTimer(e),t.stop(),this.contexts.delete(e);this.sharedFs=await Hs.create({dbName:`slicc-fs`,wipe:!0}),this.fsWatcher&&this.sharedFs.setWatcher(this.fsWatcher),await this.ensureRootStructure(),await this.ensureGlobalMemory(),await G6(this.sharedFs).catch(e=>{b8.warn(`Failed to re-seed default skills`,{error:e instanceof Error?e.message:String(e)})}),this.droppedScoopCosts=[],b8.info(`Filesystem reset and defaults re-seeded`)}async clearAllMessages(){await j(),this.sessionStore&&await this.sessionStore.clearAll().catch(e=>{b8.warn(`Failed to clear agent sessions`,{error:e instanceof Error?e.message:String(e)})});for(let e of this.contexts.values())e.clearMessages();this.lastAgentTimestamp.clear();for(let e of this.scoops.keys())this.messageQueues.set(e,[]);this.droppedScoopCosts=[],b8.info(`All messages cleared`)}async handleMessage(e){b8.info(`handleMessage`,{id:e.id,chatJid:e.chatJid,sender:e.senderName,channel:e.channel,contentPreview:e.content.slice(0,80)});let t=this.scoops.get(e.chatJid);z3(t?.isCone?`cone`:t?.name??`unknown`,localStorage.getItem(`selected-model`)??`unknown`),await se(e),await this.routeToScoop(e)}async delegateToScoop(e,t,n){let r=this.scoops.get(e);if(!r)throw Error(`Scoop not found: ${e}`);let i={id:`delegate-${Date.now()}-${Math.random().toString(36).slice(2)}`,chatJid:e,senderId:`cone`,senderName:n,content:t,timestamp:new Date().toISOString(),fromAssistant:!0,channel:`delegation`};await se(i),this.callbacks.onIncomingMessage?.(e,i),b8.info(`Delegating to scoop`,{scoopJid:e,scoopName:r.name,promptLength:t.length}),this.sendPrompt(e,t,`cone`,n).catch(t=>{let n=t instanceof Error?t.message:String(t);b8.error(`Delegation failed`,{scoopJid:e,error:n}),this.callbacks.onError(e,`Delegation failed: ${n}`)})}async routeToScoop(e){let t=this.scoops.get(e.chatJid);if(!t){b8.info(`routeToScoop: unregistered target`,{chatJid:e.chatJid});return}let n=e.channel===`webhook`||e.channel===`cron`||e.channel===`fswatch`||e.channel===`sprinkle`;if(!t.isCone&&t.requiresTrigger&&t.trigger&&!n&&!e.content.includes(t.trigger)){b8.info(`routeToScoop: trigger not found in content`,{chatJid:e.chatJid,trigger:t.trigger,contentPreview:e.content.slice(0,80)});return}let r=this.messageQueues.get(e.chatJid)??[];r.push(e),this.messageQueues.set(e.chatJid,r);let i=this.tabs.get(e.chatJid);if(b8.debug(`routeToScoop: queued`,{chatJid:e.chatJid,scoopName:t.name,tabStatus:i?.status??`no-tab`,queueLength:r.length}),i?.status===`error`){b8.info(`routeToScoop: tab in error state, retrying init`,{chatJid:e.chatJid});try{await this.createScoopTab(e.chatJid),i=this.tabs.get(e.chatJid)}catch{b8.warn(`routeToScoop: retry init failed`,{chatJid:e.chatJid})}}i?.status===`ready`&&await this.processScoopQueue(e.chatJid)}async createScoopTab(e){let t=this.scoops.get(e);if(!t)throw Error(`Scoop not found: ${e}`);if(this.contexts.has(e))if(this.tabs.get(e)?.status===`error`)b8.info(`Re-creating context after error`,{jid:e}),this.contexts.get(e)?.dispose(),this.contexts.delete(e),this.tabs.delete(e);else{b8.debug(`Context already exists`,{jid:e});return}if(!this.sharedFs)throw Error(`Shared filesystem not initialized`);let n=`scoop-${t.folder}-${Date.now()}`,r=t.isCone?this.sharedFs:new Us(this.sharedFs,t.config?.writablePaths?[...t.config.writablePaths]:[],t.config?.visiblePaths?[...t.config.visiblePaths]:[]),i={onResponse:(n,r)=>{if(this.scoops.has(e)&&(this.callbacks.onResponse(e,n,r),this.dispatchScoopEvent(e,`onResponse`,n,r),!t.isCone))if(r){let t=this.scoopResponseBuffer.get(e)??``;this.scoopResponseBuffer.set(e,t+n)}else this.scoopResponseBuffer.set(e,n)},onResponseDone:()=>{if(!this.scoops.has(e))return;let t=this.tabs.get(e);t&&(t.lastActivity=new Date().toISOString(),this.tabs.set(e,t)),this.callbacks.onResponseDone(e)},onError:t=>{if(!this.scoops.has(e))return;let n=this.tabs.get(e);n&&(n.status=`error`,n.error=t,this.tabs.set(e,n)),this.callbacks.onError(e,t),this.callbacks.onStatusChange(e,`error`),this.dispatchScoopEvent(e,`onError`,t),this.dispatchScoopEvent(e,`onStatusChange`,`error`)},onFatalError:t=>{if(!this.scoops.has(e))return;let n=this.scoops.get(e);b8.error(`Fatal scoop error`,{jid:e,folder:n.folder,error:t});let r=this.tabs.get(e);if(r&&(r.status=`error`,r.error=t,this.tabs.set(e,r)),this.callbacks.onError(e,t),this.callbacks.onStatusChange(e,`error`),this.dispatchScoopEvent(e,`onError`,t),this.dispatchScoopEvent(e,`onStatusChange`,`error`),n.isCone)return;this.mutedScoops.delete(e),this.pendingCompletions.delete(e),this.scoopResponseBuffer.delete(e);let i=this.completionWaiters.get(e);if(i&&i.length>0){this.completionWaiters.delete(e);for(let t of i)try{t(null)}catch(t){b8.warn(`completion waiter threw on fatal error`,{jid:e,error:t instanceof Error?t.message:String(t)})}}let a=Array.from(this.scoops.values()).find(e=>e.isCone);if(!a)return;let o={id:`scoop-error-${e}-${Date.now()}`,chatJid:a.jid,senderId:n.folder,senderName:n.assistantLabel,content:`[@${n.assistantLabel} FAILED]: ${t}`,timestamp:new Date().toISOString(),fromAssistant:!1,channel:`scoop-error`};try{this.callbacks.onIncomingMessage?.(a.jid,o)}catch(e){b8.warn(`onIncomingMessage for scoop-error threw`,{scoop:n.folder,error:e instanceof Error?e.message:String(e)})}this.handleMessage(o).catch(e=>{b8.error(`Failed to route fatal error to cone`,{scoop:n.folder,error:e instanceof Error?e.message:String(e)})})},onStatusChange:n=>{if(!this.scoops.has(e))return;let r=this.tabs.get(e);r&&(r.status=n,r.lastActivity=new Date().toISOString(),this.tabs.set(e,r)),this.callbacks.onStatusChange(e,n),this.dispatchScoopEvent(e,`onStatusChange`,n),n===`ready`&&!t.isCone&&this.maybeNotifyConeOnScoopComplete(e)},onToolStart:(t,n)=>{this.callbacks.onToolStart?.(e,t,n)},onToolEnd:(t,n,r)=>{this.callbacks.onToolEnd?.(e,t,n,r)},onToolUI:(t,n,r)=>{this.callbacks.onToolUI?.(e,t,n,r)},onToolUIDone:t=>{this.callbacks.onToolUIDone?.(e,t)},onSendMessage:(t,n)=>{let r=`${n?`[${n}] `:``}${t}`;this.callbacks.onSendMessage(e,r),this.dispatchScoopEvent(e,`onSendMessage`,t)},getScoops:()=>this.getScoops(),getScoopTabState:t.isCone?e=>this.tabs.get(e):void 0,onFeedScoop:t.isCone?(e,n)=>this.delegateToScoop(e,n,t.assistantLabel):void 0,onScoopScoop:t.isCone?async e=>{let t={...e,jid:`scoop_${e.folder}_${Date.now()}`};return await this.registerScoop(t),t}:void 0,onDropScoop:t.isCone?async e=>{await this.unregisterScoop(e)}:void 0,onMuteScoops:t.isCone?e=>this.muteScoops(e):void 0,onUnmuteScoops:t.isCone?e=>this.unmuteScoops(e):void 0,onWaitForScoops:t.isCone?(e,t)=>this.waitForScoops(e,t):void 0,getGlobalMemory:()=>this.getGlobalMemory(),setGlobalMemory:t.isCone?e=>this.setGlobalMemory(e):void 0,getBrowserAPI:()=>this.callbacks.getBrowserAPI()},a=Array.from(this.scoops.values()).find(e=>e.isCone)?.jid,o=new d8(t,i,r,this.sessionStore??void 0,this.sharedFs??void 0,a);this.contexts.set(e,o),this.tabs.set(e,{jid:e,contextId:n,status:`initializing`,lastActivity:new Date().toISOString()}),await o.init();let s=this.tabs.get(e);s&&s.status===`initializing`&&(s.status=`ready`,this.tabs.set(e,s),this.callbacks.onStatusChange(e,`ready`),this.dispatchScoopEvent(e,`onStatusChange`,`ready`));let c=this.scoops.get(e);c&&!c.isCone&&this.startIdleTimer(e),b8.info(`Scoop context created`,{jid:e,contextId:n})}async destroyScoopTab(e){this.clearIdleTimer(e);let t=this.contexts.get(e);t&&(t.dispose(),this.contexts.delete(e),this.tabs.delete(e),this.scoopObservers.delete(e),b8.info(`Scoop context destroyed`,{jid:e}))}isProcessing(e){return this.tabs.get(e)?.status===`processing`}getScoopContext(e){return this.contexts.get(e)}async clearQueuedMessages(e){let t=this.messageQueues.get(e);if(t&&t.length>0){for(let e of t)await be(e.id);this.messageQueues.set(e,[])}}async deleteQueuedMessage(e,t){let n=this.messageQueues.get(e);if(n){let e=n.findIndex(e=>e.id===t);e!==-1&&n.splice(e,1)}await be(t)}async getMessagesForScoop(e){return de(e)}async waitForTabReady(e,t=1e4){let n=Date.now();for(;Date.now()-n<t;){let t=this.tabs.get(e);if(!t)return!1;if(t.status===`ready`||t.status===`processing`)return!0;if(t.status===`error`)return!1;await new Promise(e=>setTimeout(e,100))}return b8.warn(`Timed out waiting for tab to become ready`,{jid:e}),!1}async sendPrompt(e,t,n,r){let i=this.contexts.get(e);i||=(await this.createScoopTab(e),this.contexts.get(e));let a=this.tabs.get(e);if(a?.status===`initializing`){if(b8.debug(`Context initializing, waiting to send message`,{jid:e}),!await this.waitForTabReady(e)){b8.error(`Context did not become ready in time, dropping prompt`,{jid:e});return}i=this.contexts.get(e),a=this.tabs.get(e)}if(!i){b8.error(`Context not found after creation`,{jid:e});return}this.clearIdleTimer(e),this.scoopResponseBuffer.delete(e),a&&(a.status=`processing`,a.lastActivity=new Date().toISOString(),this.tabs.set(e,a),this.callbacks.onStatusChange(e,`processing`),this.dispatchScoopEvent(e,`onStatusChange`,`processing`)),b8.debug(`Prompt sent to scoop`,{jid:e,textLength:t.length}),await i.prompt(t)}async processScoopQueue(e){let t=this.messageQueues.get(e);if(!t||t.length===0){b8.debug(`processScoopQueue: empty queue`,{jid:e});return}let n=this.tabs.get(e);if(n?.status!==`ready`){b8.debug(`processScoopQueue: tab not ready`,{jid:e,status:n?.status??`no-tab`});return}let r=this.scoops.get(e),i=r?.assistantLabel??e,a=this.lastAgentTimestamp.get(e)??``,o=await fe(e,a,i);if(b8.debug(`processScoopQueue: DB query`,{jid:e,scoopName:r?.name,excludeName:i,since:a,dbMessageCount:o.length,queueLength:t.length}),o.length===0){b8.debug(`processScoopQueue: no messages from DB, clearing queue`,{jid:e}),this.messageQueues.set(e,[]);return}let s=o.map(e=>`[${new Date(e.timestamp).toLocaleString(`en-US`,{month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`,hour12:!0})}] ${e.senderName}: ${e.content}`).join(`
15834
- `);this.messageQueues.set(e,[]);let c=o[o.length-1];this.lastAgentTimestamp.set(e,c.timestamp),await we(`lastAgentTs_${e}`,c.timestamp),await this.sendPrompt(e,s,c.senderId,c.senderName)}startMessageLoop(){this.pollInterval||=window.setInterval(()=>{for(let e of this.scoops.keys())this.tabs.get(e)?.status===`ready`&&this.processScoopQueue(e).catch(t=>{let n=t instanceof Error?t.message:String(t);b8.error(`Message queue processing failed`,{jid:e,error:n}),this.callbacks.onError(e,`Queue processing failed: ${n}`)})},2e3)}stopMessageLoop(){this.pollInterval&&=(clearInterval(this.pollInterval),null)}updateModel(){for(let e of this.contexts.values())e.updateModel();b8.info(`Model updated on all active contexts`,{contextCount:this.contexts.size})}async reloadAllSkills(){let e=[];for(let[t,n]of this.contexts){let r=this.tabs.get(t);(r?.status===`ready`||r?.status===`processing`)&&e.push(n.reloadSkills().catch(e=>{b8.warn(`Failed to reload skills for scoop`,{jid:t,error:e instanceof Error?e.message:String(e)})}))}await Promise.all(e),b8.info(`Skills reloaded across all contexts`,{count:e.length})}stopScoop(e){let t=this.contexts.get(e);t&&t.stop()}buildScoopCost(e,t){let n=t.getAgentMessages().filter(e=>e.role===`assistant`);if(n.length===0)return null;let r={input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},i=new Map;for(let e of n)r.input+=e.usage.input,r.output+=e.usage.output,r.cacheRead+=e.usage.cacheRead,r.cacheWrite+=e.usage.cacheWrite,r.totalTokens+=e.usage.totalTokens,r.cost.input+=e.usage.cost.input,r.cost.output+=e.usage.cost.output,r.cost.cacheRead+=e.usage.cost.cacheRead,r.cost.cacheWrite+=e.usage.cost.cacheWrite,r.cost.total+=e.usage.cost.total,i.set(e.model,(i.get(e.model)??0)+1);let a=``,o=0;for(let[e,t]of i)t>o&&(a=e,o=t);let s=n.map(e=>e.timestamp).sort((e,t)=>e-t),c=s[0],l=s[s.length-1],u=900*1e3,d=l-c,f=Math.max(1,Math.ceil(d/u))*u;return{name:e.assistantLabel,type:e.isCone?`cone`:`scoop`,model:a,usage:r,turns:n.length,firstActivity:c,lastActivity:l,activeTimeMs:f}}snapshotScoopCost(e){let t=this.scoops.get(e),n=this.contexts.get(e);if(!t||!n)return;let r=this.buildScoopCost(t,n);r&&this.droppedScoopCosts.push(r)}getSessionCosts(){let e=[];for(let t of this.scoops.values()){let n=this.contexts.get(t.jid);if(!n)continue;let r=this.buildScoopCost(t,n);r&&e.push(r)}return e.push(...this.droppedScoopCosts),e}startIdleTimer(e){if(this.clearIdleTimer(e),this.tabs.get(e)?.status===`processing`)return;let t=setTimeout(()=>{this.idleTimers.delete(e);let t=this.scoops.get(e);if(!t||t.isCone||this.tabs.get(e)?.status!==`ready`)return;let n=Array.from(this.scoops.values()).find(e=>e.isCone);if(!n)return;let r={id:`scoop-idle-${e}-${Date.now()}`,chatJid:n.jid,senderId:t.folder,senderName:t.assistantLabel,content:`[@${t.assistantLabel} idle]: Scoop "${t.name}" has been ready for 2 minutes without receiving any work. This is expected if the scoop is waiting for webhooks or cron tasks. If you intended to delegate work, use feed_scoop to send a prompt.`,timestamp:new Date().toISOString(),fromAssistant:!1,channel:`scoop-idle`};b8.info(`Scoop idle timeout`,{jid:e,scoop:t.folder});try{this.callbacks.onIncomingMessage?.(n.jid,r)}catch(t){b8.warn(`onIncomingMessage for scoop-idle threw`,{jid:e,error:t instanceof Error?t.message:String(t)})}this.handleMessage(r).catch(t=>{let n=t instanceof Error?t.message:String(t);b8.error(`Failed to send idle notification`,{jid:e,error:n})})},x8);this.idleTimers.set(e,t)}clearIdleTimer(e){let t=this.idleTimers.get(e);t&&(clearTimeout(t),this.idleTimers.delete(e))}async shutdown(){this.stopMessageLoop();for(let e of this.idleTimers.keys())this.clearIdleTimer(e);this.scheduler?.stop(),this.scheduler=null;for(let e of this.completionWaiters.values())for(let t of e)try{t(null)}catch(e){b8.warn(`completion waiter threw during shutdown`,{error:e instanceof Error?e.message:String(e)})}this.completionWaiters.clear(),this.mutedScoops.clear(),this.pendingCompletions.clear();for(let e of this.contexts.keys())await this.destroyScoopTab(e);b8.info(`Orchestrator shutdown`)}};o(`heartbeat`);var D8=o(`tray-follower`);function O8(e){let t=new URL(e);return t.searchParams.set(`json`,`true`),t.toString()}async function k8(e){let t=O8(e.joinUrl),n=await I8(await(e.fetchImpl??fetch)(t,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({controllerId:e.controllerId,runtime:e.runtime})}));return D8.info(`Follower tray attach response`,{trayId:n.trayId,action:n.result.action,code:n.result.code,participantCount:n.participantCount}),A8(n)}function A8(e){let t={trayId:e.trayId,controllerId:e.controllerId,participantCount:e.participantCount,leader:e.leader,action:e.result.action,code:e.result.code,iceServers:e.iceServers};return e.result.action===`wait`?{...t,retryAfterMs:e.result.retryAfterMs}:e.result.action===`signal`?{...t,bootstrap:e.result.bootstrap}:e.result.action===`fail`?{...t,error:e.result.error}:t}async function j8(e){return F8(await L8(e,{action:`poll`,controllerId:e.controllerId,bootstrapId:e.bootstrapId,cursor:e.cursor}))}async function M8(e){return F8(await L8(e,{action:`answer`,controllerId:e.controllerId,bootstrapId:e.bootstrapId,answer:e.answer}))}async function N8(e){return F8(await L8(e,{action:`ice-candidate`,controllerId:e.controllerId,bootstrapId:e.bootstrapId,candidate:e.candidate}))}async function P8(e){return F8(await L8(e,{action:`retry`,controllerId:e.controllerId,bootstrapId:e.bootstrapId,runtime:e.runtime}))}function F8(e){return{trayId:e.trayId,controllerId:e.controllerId,participantCount:e.participantCount,leader:e.leader,bootstrap:e.bootstrap,events:e.events}}async function I8(e){let t=null,n=null;try{t=await e.text(),n=JSON.parse(t)}catch{}if(!R8(n)){let n=t?t.slice(0,200):`(empty)`;throw D8.warn(`Tray follower attach returned an invalid response`,{status:e.status,body:n}),Error(`Tray follower attach returned an invalid response (${e.status}): ${n}`)}return n}async function L8(e,t){let n=O8(e.joinUrl),r=await(e.fetchImpl??fetch)(n,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t)}),i=await r.json().catch(()=>null);if(!z8(i))throw Error(`Tray follower bootstrap returned an invalid response (${r.status})`);return i}function R8(e){if(!e||typeof e!=`object`)return!1;let t=e;if(typeof t.trayId!=`string`||typeof t.controllerId!=`string`||t.role!==`follower`||typeof t.participantCount!=`number`)return!1;let n=t.result;if(!n||typeof n!=`object`)return!1;let r=n;return r.action===`wait`?(r.code===`LEADER_NOT_ELECTED`||r.code===`LEADER_NOT_CONNECTED`)&&typeof r.retryAfterMs==`number`:r.action===`signal`?r.code===`LEADER_CONNECTED`&&B8(r.bootstrap):r.action===`fail`?(r.code===`INVALID_JOIN_CAPABILITY`||r.code===`TRAY_EXPIRED`)&&typeof r.error==`string`:!1}function z8(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.trayId==`string`&&typeof t.controllerId==`string`&&t.role===`follower`&&typeof t.participantCount==`number`&&B8(t.bootstrap)&&Array.isArray(t.events)}function B8(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.controllerId==`string`&&typeof t.bootstrapId==`string`&&typeof t.attempt==`number`&&typeof t.state==`string`&&typeof t.expiresAt==`string`&&typeof t.cursor==`number`&&typeof t.maxRetries==`number`&&typeof t.retriesRemaining==`number`}var V8=i({AGENT_BRIDGE_GLOBAL_KEY:()=>U8,AGENT_SPAWN_REQUEST_TYPE:()=>W8,createAgentBridge:()=>G8,publishAgentBridge:()=>K8,publishAgentBridgeProxy:()=>q8}),H8=o(`agent-bridge`),U8=`__slicc_agent`,W8=`agent-spawn-request`;function G8(e,t,n=null,r={}){let i=r.generateName??Z8,a=r.generateUid??J8,o=r.resolveModel??$8;function s(){for(let t=0;t<8;t++){let t=i(),n=`agent_${Q8(t)}`;if(!e.getScoops().some(e=>e.jid===n))return t}return a()}function c(t){if(t===void 0)return null;let n=e.getScoops().find(e=>e.jid===t);if(!n)return null;let r=n.config?.modelId;return r&&r.length>0?r:null}async function l(r){let i=r.modelId;if(i!==void 0&&(i===``||o(i)===null))return{finalText:`agent: unknown model: ${i}`,exitCode:1};let a=i??c(r.parentJid)??``,l=s(),u=`agent-${l}`,d=`agent_${Q8(l)}`,f=`/scoops/${u}`,p=e5(r.cwd),m={visiblePaths:t5(r),writablePaths:n5([p,`/shared/`,`${f}/`,`/tmp/`]),allowedCommands:r.allowedCommands};a&&(m.modelId=a);let h={jid:d,name:u,folder:u,isCone:!1,type:`scoop`,requiresTrigger:!1,assistantLabel:u,addedAt:new Date().toISOString(),config:m,configSchemaVersion:2,notifyOnComplete:!1},g=[],_=``,v=null,y=e.observeScoop(d,{onSendMessage:e=>{g.push(e)},onResponse:(e,t)=>{t?_+=e:_=e},onError:e=>{v===null&&(v=e)}});try{try{await e.registerScoop(h)}catch(e){return{finalText:v??r5(e),exitCode:1}}return await e.sendPrompt(d,r.prompt,`agent`,`agent`),v===null?{finalText:g.length>0?g[g.length-1]:_,exitCode:0}:{finalText:v,exitCode:1}}catch(e){return{finalText:v??r5(e),exitCode:1}}finally{y();try{await e.unregisterScoop(d)}catch(e){H8.warn(`unregisterScoop failed`,{jid:d,error:r5(e)})}try{await t.rm(f,{recursive:!0})}catch(e){i5(e,`ENOENT`)||H8.warn(`scratch folder cleanup failed`,{folder:u,error:r5(e)})}if(n)try{await n.delete(d)}catch(e){H8.warn(`sessionStore.delete failed`,{jid:d,error:r5(e)})}}}return{spawn:l}}function K8(e,t,n=null,r={}){let i=G8(e,t,n,r);return globalThis[U8]=i,H8.info(`agent bridge published on globalThis.__slicc_agent`),i}function q8(){let e={spawn(e){return new Promise((t,n)=>{let r=globalThis.chrome?.runtime;if(!r||typeof r.sendMessage!=`function`){n(Error(`agent: chrome.runtime.sendMessage not available`));return}let i=e=>{let i=r.lastError;if(i){n(Error(i.message??`chrome.runtime error`));return}if(e==null){n(Error(`agent: empty response from offscreen bridge`));return}let a=e;if(!a.ok){n(Error(a.error??`agent: offscreen bridge error`));return}if(!a.result){n(Error(`agent: offscreen bridge returned no result`));return}t(a.result)};try{r.sendMessage({source:`panel`,payload:{type:W8,options:e}},i)}catch(e){n(e instanceof Error?e:Error(String(e)))}})}};return globalThis[U8]=e,H8.info(`agent bridge proxy published on globalThis.__slicc_agent`),e}function J8(){let e=globalThis;return typeof e.crypto?.randomUUID==`function`?e.crypto.randomUUID().replace(/-/g,``).slice(0,12):`${Date.now().toString(36)}${Math.random().toString(36).slice(2,8)}`}var Y8=`amber.bouncy.breezy.bubbly.cheeky.chilly.cozy.dapper.dreamy.eager.exuberant.fluffy.frosty.gentle.giddy.glossy.jolly.lucky.mellow.merry.nimble.plucky.quirky.salty.sleepy.snappy.sparkly.spiffy.sunny.sweet.toasty.velvety.whimsy.zesty`.split(`.`),X8=`blueberry.butterscotch.caramel.cherry.chocolate.cinnamon.coconut.coffee.cookies.custard.espresso.fudge.gelato.hazelnut.honeycomb.lavender.lemon.mango.maple.marzipan.matcha.mint.mocha.neapolitan.nougat.peach.pecan.pistachio.praline.raspberry.sherbet.sorbet.stracciatella.strawberry.tiramisu.toffee.vanilla`.split(`.`);function Z8(){return`${Y8[Math.floor(Math.random()*Y8.length)]}-${X8[Math.floor(Math.random()*X8.length)]}`}function Q8(e){return e.replace(/-/g,`_`)}function $8(e){try{let t=h();for(let n of t)if(n.models.some(t=>t.id===e))return e;return null}catch{return null}}function e5(e){let t=k(e);return t.endsWith(`/`)?t:`${t}/`}function t5(e){if(e.visiblePaths!==void 0)return e.visiblePaths.map(e5);let t=[`/workspace/`];return e.invokingCwd&&e.invokingCwd.length>0&&t.push(e5(e.invokingCwd)),n5(t)}function n5(e){let t=new Set,n=[];for(let r of e)t.has(r)||(t.add(r),n.push(r));return n}function r5(e){return e instanceof Error?e.message:String(e)}function i5(e,t){if(typeof e!=`object`||!e)return!1;let n=e.code;return typeof n==`string`&&n===t}var a5=o(`tray-webrtc`),o5=`tray-control`,s5=250,c5=class{peerConnectionFactory;dataChannelLabel;peers=new Map;iceServers;constructor(e){this.options=e,this.iceServers=e.iceServers,this.peerConnectionFactory=e.peerConnectionFactory??(()=>d5(this.iceServers)),this.dataChannelLabel=e.dataChannelLabel??o5}setIceServers(e){this.iceServers=e}async handleControlMessage(e){e.type===`follower.join_requested`?(e.iceServers&&!this.iceServers&&(this.iceServers=e.iceServers),await this.handleJoinRequested(e)):e.type===`bootstrap.answer`?await this.peers.get(e.bootstrapId)?.peer.setRemoteDescription(e.answer):e.type===`bootstrap.ice_candidate`&&await this.peers.get(e.bootstrapId)?.peer.addIceCandidate(e.candidate)}getPeers(){return Array.from(this.peers.values()).map(({state:e})=>({...e}))}getChannel(e){return this.peers.get(e)?.channel??null}stop(){for(let e of this.peers.values())e.peer.close();this.peers.clear()}async handleJoinRequested(e){this.closeControllerPeers(e.controllerId);let t=this.peerConnectionFactory(),n={controllerId:e.controllerId,bootstrapId:e.bootstrapId,attempt:e.attempt,state:`connecting`,connectedAt:null,runtime:e.runtime},r=t.createDataChannel(this.dataChannelLabel);this.peers.set(e.bootstrapId,{state:n,peer:t,channel:r}),t.addEventListener(`icecandidate`,({candidate:t})=>{let n=p5(t);n&&this.options.sendControlMessage({type:`bootstrap.ice_candidate`,controllerId:e.controllerId,bootstrapId:e.bootstrapId,candidate:n})}),t.addEventListener(`connectionstatechange`,()=>{let n=this.peers.get(e.bootstrapId);n&&(n.state.state===`connected`?(t.connectionState===`disconnected`||t.connectionState===`failed`)&&(a5.warn(`Leader peer connection state changed post-connect`,{bootstrapId:e.bootstrapId,state:t.connectionState}),this.options.onPeerDisconnected?.(e.bootstrapId,`Peer connection ${t.connectionState}`)):t.connectionState===`failed`&&this.failPeer(e,`Leader peer connection failed before the data channel opened`))}),r.addEventListener(`open`,()=>{let t=this.peers.get(e.bootstrapId);!t||t.state.state===`connected`||(t.state.state=`connected`,t.state.connectedAt=new Date().toISOString(),this.options.onPeerConnected?.({...t.state},t.channel))}),r.addEventListener(`close`,()=>{let t=this.peers.get(e.bootstrapId);t&&(t.state.state===`connected`?(a5.warn(`Leader data channel closed post-connect`,{bootstrapId:e.bootstrapId}),this.options.onPeerDisconnected?.(e.bootstrapId,`Data channel closed`)):this.failPeer(e,`Leader data channel closed before opening`))}),r.addEventListener(`error`,()=>{let t=this.peers.get(e.bootstrapId);t&&(t.state.state===`connected`?(a5.warn(`Leader data channel error post-connect`,{bootstrapId:e.bootstrapId}),this.options.onPeerDisconnected?.(e.bootstrapId,`Data channel error`)):this.failPeer(e,`Leader data channel failed before opening`))});try{let n=await t.createOffer();await t.setLocalDescription(n),this.options.sendControlMessage({type:`bootstrap.offer`,controllerId:e.controllerId,bootstrapId:e.bootstrapId,offer:f5(t.localDescription??n,`offer`)})}catch(t){this.failPeer(e,t instanceof Error?t.message:String(t))}}closeControllerPeers(e){for(let[t,n]of this.peers.entries())n.state.controllerId===e&&(n.peer.close(),this.peers.delete(t))}failPeer(e,t){let n=this.peers.get(e.bootstrapId);if(n){n.peer.close(),this.peers.delete(e.bootstrapId);try{this.options.sendControlMessage({type:`bootstrap.failed`,controllerId:e.controllerId,bootstrapId:e.bootstrapId,code:`WEBRTC_BOOTSTRAP_FAILED`,message:t,retryable:!0,retryAfterMs:1e3})}catch(e){a5.warn(`Failed to report tray bootstrap failure`,{error:e instanceof Error?e.message:String(e)})}}}},l5=class{fetchImpl;peerConnectionFactory;controllerIdFactory;sleep;pollIntervalMs;iceServers;activePeer=null;stopped=!1;constructor(e){this.options=e,this.fetchImpl=e.fetchImpl??fetch,this.iceServers=e.iceServers,this.peerConnectionFactory=e.peerConnectionFactory??(()=>d5(this.iceServers)),this.controllerIdFactory=e.controllerIdFactory??(()=>crypto.randomUUID()),this.sleep=e.sleep??(e=>new Promise(t=>setTimeout(t,e))),this.pollIntervalMs=e.pollIntervalMs??s5}async start(){this.stopped=!1;let e=this.controllerIdFactory(),t=Date.now();_o({state:`connecting`,joinUrl:this.options.joinUrl,trayId:null,error:null,lastPingTime:null,reconnectAttempts:0,attachAttempts:0,lastAttachCode:null,connectingSince:t,lastError:null}),a5.info(`Follower tray join starting`,{joinUrl:this.options.joinUrl});let n=0;for(;;){m5(this.stopped),n++;let t;try{t=await k8({joinUrl:this.options.joinUrl,controllerId:e,runtime:this.options.runtime,fetchImpl:this.fetchImpl})}catch(e){let t=e instanceof Error?e.message:String(e);throw _o({...go(),attachAttempts:n,lastError:t}),e}if(_o({...go(),attachAttempts:n,lastAttachCode:t.code}),t.action===`wait`){let e=t.retryAfterMs??1e3;a5.info(`Follower tray attach waiting`,{attempt:n,code:t.code,retryAfterMs:e}),n%10==0&&a5.warn(`Follower tray attach still waiting after ${n} attempts`,{attempt:n,code:t.code,retryAfterMs:e}),await this.sleep(e);continue}if(t.action===`fail`||!t.bootstrap){let e=t.error??`Tray follower attach failed (${t.code})`;throw _o({state:`error`,joinUrl:this.options.joinUrl,trayId:null,error:e,lastPingTime:null,reconnectAttempts:0,attachAttempts:n,lastAttachCode:t.code,connectingSince:null,lastError:e}),a5.warn(`Follower tray attach failed`,{error:e}),Error(e)}t.iceServers&&(this.iceServers=t.iceServers);try{let r=await this.completeBootstrap(t.trayId,e,t.bootstrap);return _o({state:`connected`,joinUrl:this.options.joinUrl,trayId:r.trayId,error:null,lastPingTime:null,reconnectAttempts:0,attachAttempts:n,lastAttachCode:t.code,connectingSince:null,lastError:null}),a5.info(`Follower tray connected`,{trayId:r.trayId,controllerId:e}),r}catch(e){let r=e instanceof Error?e.message:String(e);throw _o({state:`error`,joinUrl:this.options.joinUrl,trayId:t.trayId,error:r,lastPingTime:null,reconnectAttempts:0,attachAttempts:n,lastAttachCode:t.code,connectingSince:null,lastError:r}),a5.warn(`Follower tray bootstrap failed`,{error:r}),e}}}stop(){this.stopped=!0,this.activePeer?.peer.close(),this.activePeer?.channel?.close(),this.activePeer=null,_o({state:`inactive`,joinUrl:null,trayId:null,error:null,lastPingTime:null,reconnectAttempts:0,attachAttempts:0,lastAttachCode:null,connectingSince:null,lastError:null})}async completeBootstrap(e,t,n){let r=n,i=0;for(this.activePeer=this.createFollowerPeer(t,r.bootstrapId);;){if(m5(this.stopped),this.activePeer.open&&this.activePeer.channel)return{trayId:e,controllerId:t,bootstrapId:r.bootstrapId,channel:this.activePeer.channel};if(this.activePeer.openError)throw Error(this.activePeer.openError);let n=await j8({joinUrl:this.options.joinUrl,controllerId:t,bootstrapId:r.bootstrapId,cursor:i,fetchImpl:this.fetchImpl});r=n.bootstrap,i=r.cursor;try{for(let e of n.events)if(e.type===`bootstrap.offer`){await this.activePeer.peer.setRemoteDescription(e.offer);let n=await this.activePeer.peer.createAnswer();await this.activePeer.peer.setLocalDescription(n),await M8({joinUrl:this.options.joinUrl,controllerId:t,bootstrapId:r.bootstrapId,answer:f5(this.activePeer.peer.localDescription??n,`answer`),fetchImpl:this.fetchImpl})}else if(e.type===`bootstrap.ice_candidate`)await this.activePeer.peer.addIceCandidate(e.candidate);else if(e.type===`bootstrap.failed`)throw Error(e.failure.message)}catch(e){if(r.failure?.retryable&&r.retriesRemaining>0){r=(await P8({joinUrl:this.options.joinUrl,controllerId:t,bootstrapId:r.bootstrapId,runtime:this.options.runtime,fetchImpl:this.fetchImpl})).bootstrap,i=0,this.activePeer.peer.close(),this.activePeer=this.createFollowerPeer(t,r.bootstrapId);continue}throw e}this.activePeer.open||await this.sleep(this.pollIntervalMs)}}createFollowerPeer(e,t){let n=this.peerConnectionFactory(),r={peer:n,channel:null,open:!1,openError:null};return n.addEventListener(`connectionstatechange`,()=>{r.open&&(n.connectionState===`disconnected`||n.connectionState===`failed`)&&(a5.warn(`Follower peer connection state changed post-connect`,{bootstrapId:t,state:n.connectionState}),this.options.onDisconnected?.(`Peer connection ${n.connectionState}`))}),n.addEventListener(`datachannel`,({channel:e})=>{r.channel=e,e.addEventListener(`open`,()=>{r.open=!0}),e.addEventListener(`close`,()=>{r.open?(a5.warn(`Follower data channel closed post-connect`,{bootstrapId:t}),this.options.onDisconnected?.(`Data channel closed`)):r.openError=`Follower data channel closed before opening`}),e.addEventListener(`error`,()=>{r.open?(a5.warn(`Follower data channel error post-connect`,{bootstrapId:t}),this.options.onDisconnected?.(`Data channel error`)):r.openError=`Follower data channel failed before opening`})}),n.addEventListener(`icecandidate`,({candidate:n})=>{let r=p5(n);r&&N8({joinUrl:this.options.joinUrl,controllerId:e,bootstrapId:t,candidate:r,fetchImpl:this.fetchImpl}).catch(e=>{a5.warn(`Failed to send follower ICE candidate`,{error:e instanceof Error?e.message:String(e)})})}),r}};function u5(e,t){let n=t.baseDelayMs??1e3,r=t.backoffMultiplier??2,i=t.maxDelayMs??3e4,a=t.maxAttempts??10,o=t.sleep??e.sleep??(e=>new Promise(t=>setTimeout(t,e))),s=!1,c=!1,l=null,u={cancel(){s=!0,c=!1,l?.stop(),l=null},get reconnecting(){return c}},d=()=>{let t=new l5({...e,sleep:o,onDisconnected:e=>{s||(a5.warn(`Follower disconnected, starting reconnect loop`,{reason:e}),f(e))}});return l=t,{manager:t,connectionPromise:t.start()}},f=async u=>{if(s||c)return;c=!0,l?.stop(),l=null;let f=0,p=n,m=u??`Unknown disconnect`;for(;!s&&f<a&&(f++,t.onReconnecting?.(f),_o({...go(),state:`reconnecting`,error:null,reconnectAttempts:f}),a5.info(`Reconnect attempt`,{attempt:f,delay:p}),await o(p),!s);){let n=null;try{let r=d();n=r.manager;let i=await r.connectionPromise;if(s){n.stop();break}c=!1,_o({...go(),state:`connected`,joinUrl:e.joinUrl,trayId:i.trayId,error:null,lastPingTime:null,reconnectAttempts:0,connectingSince:null,lastError:null}),a5.info(`Reconnect successful`,{attempt:f,trayId:i.trayId}),t.onConnected(i);return}catch(e){m=e instanceof Error?e.message:String(e),a5.warn(`Reconnect attempt failed`,{attempt:f,error:m}),n?.stop(),l=null}p=Math.min(p*r,i)}s||(c=!1,_o({...go(),state:`error`,error:`Reconnect failed after ${f} attempts: ${m}`,reconnectAttempts:f}),a5.warn(`Reconnect gave up`,{attempts:f,lastError:m}),t.onGaveUp?.(m))},{connectionPromise:p}=d();return p.then(e=>{s||t.onConnected(e)}).catch(e=>{s||a5.warn(`Initial follower connection failed`,{error:e instanceof Error?e.message:String(e)})}),u}function d5(e){if(typeof RTCPeerConnection>`u`)throw Error(`RTCPeerConnection is not available in this runtime`);let t=e?.length?{iceServers:e}:void 0;return new RTCPeerConnection(t)}function f5(e,t){if(!e||e.type!==t||typeof e.sdp!=`string`)throw Error(`Expected a local ${t} description before signaling`);return{type:e.type,sdp:e.sdp}}function p5(e){if(!e||typeof e!=`object`)return null;let t=e;return typeof t.candidate==`string`?{candidate:t.candidate,sdpMid:typeof t.sdpMid==`string`?t.sdpMid:null,sdpMLineIndex:typeof t.sdpMLineIndex==`number`?t.sdpMLineIndex:null,usernameFragment:typeof t.usernameFragment==`string`?t.usernameFragment:null}:null}function m5(e){if(e)throw Error(`Tray follower stopped before WebRTC bootstrap completed`)}var h5=64*1024;async function g5(e,t){try{switch(t.op){case`readFile`:return await _5(e,t.path,t.encoding);case`writeFile`:return[await v5(e,t.path,t.content,t.encoding)];case`stat`:return[await y5(e,t.path)];case`readDir`:return[await b5(e,t.path)];case`mkdir`:return[await x5(e,t.path,t.recursive)];case`rm`:return[await S5(e,t.path,t.recursive)];case`exists`:return[await C5(e,t.path)];case`walk`:return[await w5(e,t.path)];default:return[{ok:!1,error:`Unknown fs operation: ${t.op}`}]}}catch(e){return[E5(e)]}}async function _5(e,t,n){return(n??`utf-8`)===`utf-8`?T5(await e.readFile(t,{encoding:`utf-8`}),`utf-8`):T5(D5(await e.readFile(t,{encoding:`binary`})),`base64`)}async function v5(e,t,n,r){if(r===`base64`){let r=O5(n);await e.writeFile(t,r)}else await e.writeFile(t,n);return{ok:!0,data:{type:`void`}}}async function y5(e,t){return{ok:!0,data:{type:`stat`,stat:await e.stat(t)}}}async function b5(e,t){return{ok:!0,data:{type:`dirEntries`,entries:await e.readDir(t)}}}async function x5(e,t,n){return await e.mkdir(t,{recursive:n}),{ok:!0,data:{type:`void`}}}async function S5(e,t,n){return await e.rm(t,{recursive:n}),{ok:!0,data:{type:`void`}}}async function C5(e,t){return{ok:!0,data:{type:`exists`,exists:await e.exists(t)}}}async function w5(e,t){let n=[];for await(let r of e.walk(t))n.push(r);return{ok:!0,data:{type:`paths`,paths:n}}}function T5(e,t){if(e.length<=h5)return[{ok:!0,data:{type:`file`,content:e,encoding:t}}];let n=Math.ceil(e.length/h5),r=[];for(let i=0;i<n;i++){let a=i*h5,o=e.slice(a,a+h5);r.push({ok:!0,data:{type:`file`,content:o,encoding:t},chunkIndex:i,totalChunks:n})}return r}function E5(e){return e instanceof Error&&`code`in e?{ok:!1,error:e.message,code:e.code}:{ok:!1,error:e instanceof Error?e.message:String(e)}}function D5(e){let t=``;for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);return btoa(t)}function O5(e){let t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}var k5=class{runtimes=new Map;dirty=!1;setTargets(e,t){this.runtimes.set(e,t),this.dirty=!0}removeRuntime(e){this.runtimes.delete(e)&&(this.dirty=!0)}getEntries(){this.dirty=!1;let e=[];for(let[t,n]of this.runtimes)for(let r of n)e.push({targetId:`${t}:${r.targetId}`,localTargetId:r.targetId,runtimeId:t,title:r.title,url:r.url,isLocal:!1});return e}hasChanged(){return this.dirty}getRuntimeIds(){return[...this.runtimes.keys()]}},A5=o(`data-channel-keepalive`),j5=class{sendPing;onDead;intervalMs;maxMissed;timer=null;missedPongs=0;awaitingPong=!1;stopped=!1;constructor(e){this.sendPing=e.sendPing,this.onDead=e.onDead,this.intervalMs=e.intervalMs??1e4,this.maxMissed=e.maxMissed??3}start(){this.timer||this.stopped||(this.timer=setInterval(()=>this.tick(),this.intervalMs))}stop(){this.stopped=!0,this.timer&&=(clearInterval(this.timer),null)}receivePong(){this.awaitingPong=!1,this.missedPongs=0}receivePing(){this.missedPongs=0,this.awaitingPong=!1}get missed(){return this.missedPongs}tick(){if(!this.stopped){if(this.awaitingPong&&(this.missedPongs++,A5.debug(`Missed pong`,{missedPongs:this.missedPongs,maxMissed:this.maxMissed}),this.missedPongs>=this.maxMissed)){A5.warn(`Channel declared dead`,{missedPongs:this.missedPongs}),this.stop(),this.onDead();return}this.awaitingPong=!0,this.sendPing()}}},M5=o(`tray-leader-sync`);function N5(e){return e?e.includes(`standalone`)?`standalone`:e.includes(`extension`)?`extension`:e.includes(`electron`)?`electron`:`unknown`:`unknown`}var P5=class{followers=new Map;registry=new k5;runtimeToBootstrap=new Map;pendingCDPRoutes=new Map;cdpChunkBuffers=new Map;remoteTransports=new Map;pendingTabOpenRoutes=new Map;tabOpenResolvers=new Map;pendingFsRoutes=new Map;fsResolvers=new Map;constructor(e){this.options=e}addFollower(e,t,n){this.removeFollower(e);let r=wc(t),i=r.onMessage(t=>{this.handleFollowerMessage(e,t)}),a=new j5({sendPing:()=>r.send({type:`ping`}),onDead:()=>{M5.warn(`Follower keepalive dead, removing follower`,{bootstrapId:e}),this.removeFollower(e),this.options.onFollowerDead?.(e)}});a.start(),this.followers.set(e,{bootstrapId:e,sync:r,unsubscribe:i,keepalive:a,runtime:n?.runtime,connectedAt:n?.connectedAt,lastActivity:Date.now(),floatType:N5(n?.runtime)}),M5.info(`Follower added to sync`,{bootstrapId:e,followerCount:this.followers.size}),this.options.onFollowerCountChanged?.(this.followers.size),this.sendSnapshotToFollower(e);let o=this.getConnectedEntries();o.length>0&&r.send({type:`targets.registry`,targets:o})}removeFollower(e){let t=this.followers.get(e);if(t){t.keepalive.stop(),t.unsubscribe(),t.sync.close(),this.followers.delete(e);for(let[t,n]of this.runtimeToBootstrap)if(n===e){this.cleanupRemoteTransports(t),this.registry.removeRuntime(t),this.runtimeToBootstrap.delete(t);break}this.registry.hasChanged()&&this.broadcastTargetRegistry(),M5.info(`Follower removed from sync`,{bootstrapId:e,followerCount:this.followers.size}),this.options.onFollowerCountChanged?.(this.followers.size)}}broadcastEvent(e){if(this.followers.size===0)return;let t={type:`agent_event`,event:e,scoopJid:this.options.getScoopJid()};for(let e of this.followers.values())e.sync.send(t)}broadcastUserMessage(e,t){if(this.followers.size===0)return;let n={type:`user_message_echo`,text:e,messageId:t,scoopJid:this.options.getScoopJid()};for(let e of this.followers.values())e.sync.send(n)}broadcastStatus(e){if(this.followers.size===0)return;let t={type:`status`,scoopStatus:e};for(let e of this.followers.values())e.sync.send(t)}sendSnapshotToFollower(e){let t=this.followers.get(e);if(!t)return;let n=this.options.getMessages(),r=this.options.getScoopJid();xc(t.sync,n,r),M5.debug(`Snapshot sent to follower`,{bootstrapId:e,messageCount:n.length})}handleFollowerMessage(e,t){switch(t.type){case`user_message`:M5.info(`Follower user message received`,{bootstrapId:e,messageId:t.messageId}),this.options.onFollowerMessage(t.text,t.messageId);break;case`abort`:M5.info(`Follower abort received`,{bootstrapId:e}),this.options.onFollowerAbort();break;case`request_snapshot`:M5.info(`Follower snapshot request received`,{bootstrapId:e}),this.sendSnapshotToFollower(e);break;case`targets.advertise`:M5.info(`Follower targets advertised`,{bootstrapId:e,runtimeId:t.runtimeId,targetCount:t.targets.length});for(let e of[...this.remoteTransports.keys()]){let n=e.substring(0,e.indexOf(`:`));n!==`leader`&&!this.runtimeToBootstrap.has(n)&&n!==t.runtimeId&&(this.remoteTransports.get(e)?.disconnect(),this.remoteTransports.delete(e),M5.debug(`Cleaned up orphaned remote transport on advertise`,{key:e}))}this.runtimeToBootstrap.set(t.runtimeId,e),this.registry.setTargets(t.runtimeId,t.targets),this.broadcastTargetRegistry();break;case`cdp.request`:{let{requestId:n,targetRuntimeId:r,localTargetId:i,method:a,params:o,sessionId:s}=t;r===`leader`?this.executeLocalCDP(n,i,a,o,s,e):this.forwardCDPRequest(n,r,i,a,o,s,e);break}case`cdp.response`:this.handleCDPResponse(t);break;case`cdp.event`:this.handleCDPEvent(e,t.method,t.params,t.sessionId);break;case`tab.open`:{let{requestId:n,targetRuntimeId:r,url:i}=t;r===`leader`?this.executeLocalTabOpen(n,i,e):this.forwardTabOpen(n,r,i,e);break}case`tab.opened`:this.handleTabOpenResponse(t.requestId,t.targetId);break;case`tab.open.error`:this.handleTabOpenError(t.requestId,t.error);break;case`fs.request`:{let{requestId:n,targetRuntimeId:r,request:i}=t;r===`leader`?this.executeLocalFs(n,i,e):this.forwardFsRequest(n,r,i,e);break}case`fs.response`:this.handleFsResponse(t.requestId,t.response);break;case`ping`:{let t=this.followers.get(e);t&&(t.keepalive.receivePing(),t.lastActivity=Date.now(),t.sync.send({type:`pong`}));break}case`pong`:{let t=this.followers.get(e);t&&(t.keepalive.receivePong(),t.lastActivity=Date.now());break}}}setLocalTargets(e){this.registry.setTargets(`leader`,e),this.registry.hasChanged()&&this.broadcastTargetRegistry()}broadcastTargetRegistry(){if(this.followers.size===0)return;let e={type:`targets.registry`,targets:this.getConnectedEntries()};for(let t of this.followers.values())t.sync.send(e)}getTargets(){return this.getConnectedEntries()}getConnectedEntries(){return this.registry.getEntries().filter(e=>{if(e.runtimeId===`leader`)return!0;let t=this.runtimeToBootstrap.get(e.runtimeId);return t?this.followers.has(t):!1})}createRemoteTransport(e,t){let n=new Ec({sendCDPRequest:(n,r,i,a)=>{let o=this.runtimeToBootstrap.get(e),s=o?this.followers.get(o):void 0;if(!s){this.remoteTransports.get(`${e}:${t}`)?.handleResponse(n,void 0,`Target runtime "${e}" not connected`);return}this.pendingCDPRoutes.set(n,{requesterBootstrapId:`__leader__`,requestId:n}),s.sync.send({type:`cdp.request`,requestId:n,localTargetId:t,method:r,params:i,sessionId:a})}});return this.remoteTransports.set(`${e}:${t}`,n),n}removeRemoteTransport(e,t){let n=`${e}:${t}`,r=this.remoteTransports.get(n);r&&(r.disconnect(),this.remoteTransports.delete(n))}cleanupRemoteTransports(e){let t=`${e}:`;for(let e of[...this.remoteTransports.keys()])e.startsWith(t)&&(this.remoteTransports.get(e)?.disconnect(),this.remoteTransports.delete(e),M5.debug(`Cleaned up stale remote transport`,{key:e}))}getConnectedFollowers(){return[...this.runtimeToBootstrap.entries()].map(([e,t])=>{let n=this.followers.get(t);return{runtimeId:e,runtime:n?.runtime,connectedAt:n?.connectedAt,lastActivity:n?.lastActivity,floatType:n?.floatType}})}getBestFollowerForTeleport(){let e=[];for(let[t,n]of this.runtimeToBootstrap){let r=this.followers.get(n);r&&e.push({runtimeId:t,bootstrapId:n,floatType:r.floatType,lastActivity:r.lastActivity})}if(e.length===0)return null;let t=e.filter(e=>e.floatType===`standalone`),n=t.length>0?t:e;return n.sort((e,t)=>t.lastActivity-e.lastActivity),n[0]}get hasFollowers(){return this.followers.size>0}stop(){for(let e of[...this.followers.keys()])this.removeFollower(e)}async executeLocalCDP(e,t,n,r,i,a){let o=this.followers.get(a);if(!o)return;let s=this.options.browserTransport;if(!s){o.sync.send({type:`cdp.response`,requestId:e,error:`Leader has no browser transport`});return}try{let t=await s.send(n,r,i);vc(o.sync,e,t)}catch(t){o.sync.send({type:`cdp.response`,requestId:e,error:t instanceof Error?t.message:String(t)})}}forwardCDPRequest(e,t,n,r,i,a,o){let s=this.runtimeToBootstrap.get(t),c=s?this.followers.get(s):void 0,l=this.followers.get(o);if(!c){l&&l.sync.send({type:`cdp.response`,requestId:e,error:`Target runtime "${t}" not connected`});return}this.pendingCDPRoutes.set(e,{requesterBootstrapId:o,requestId:e}),c.sync.send({type:`cdp.request`,requestId:e,localTargetId:n,method:r,params:i,sessionId:a})}handleCDPResponse(e){let{requestId:t,result:n,error:r,chunkData:i,chunkIndex:a,totalChunks:o}=e,s=this.pendingCDPRoutes.get(t);if(!s)return;let c=yc(this.cdpChunkBuffers,e);if(!c)return;if(this.pendingCDPRoutes.delete(t),s.requesterBootstrapId===`__leader__`){for(let e of this.remoteTransports.values())e.handleResponse(t,c.result,c.error);return}let l=this.followers.get(s.requesterBootstrapId);l&&vc(l.sync,t,c.result,c.error)}handleCDPEvent(e,t,n,r){let i;for(let[t,n]of this.runtimeToBootstrap)if(n===e){i=t;break}if(!i)return;let a=`${i}:`;for(let[e,r]of this.remoteTransports)e.startsWith(a)&&r.handleEvent(t,n)}openRemoteTab(e,t){let n=this.runtimeToBootstrap.get(e),r=n?this.followers.get(n):void 0;if(!r)return Promise.reject(Error(`Target runtime "${e}" not connected`));let i=`tab-open-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;return new Promise((e,n)=>{this.tabOpenResolvers.set(i,{resolve:e,reject:n}),this.pendingTabOpenRoutes.set(i,{requesterBootstrapId:`__leader__`,requestId:i}),r.sync.send({type:`tab.open`,requestId:i,url:t})})}async executeLocalTabOpen(e,t,n){let r=this.followers.get(n);if(!r)return;let i=this.options.browserTransport;if(!i){r.sync.send({type:`tab.open.error`,requestId:e,error:`Leader has no browser transport`});return}try{let n=(await i.send(`Target.createTarget`,{url:t,background:!0})).targetId;r.sync.send({type:`tab.opened`,requestId:e,targetId:`leader:${n}`})}catch(t){r.sync.send({type:`tab.open.error`,requestId:e,error:t instanceof Error?t.message:String(t)})}}forwardTabOpen(e,t,n,r){let i=this.runtimeToBootstrap.get(t),a=i?this.followers.get(i):void 0,o=this.followers.get(r);if(!a){o&&o.sync.send({type:`tab.open.error`,requestId:e,error:`Target runtime "${t}" not connected`});return}this.pendingTabOpenRoutes.set(e,{requesterBootstrapId:r,requestId:e}),a.sync.send({type:`tab.open`,requestId:e,url:n})}handleTabOpenResponse(e,t){let n=this.pendingTabOpenRoutes.get(e);if(!n)return;if(this.pendingTabOpenRoutes.delete(e),n.requesterBootstrapId===`__leader__`){let n=this.tabOpenResolvers.get(e);n&&(this.tabOpenResolvers.delete(e),n.resolve(t));return}let r=this.followers.get(n.requesterBootstrapId);r&&r.sync.send({type:`tab.opened`,requestId:e,targetId:t})}handleTabOpenError(e,t){let n=this.pendingTabOpenRoutes.get(e);if(!n)return;if(this.pendingTabOpenRoutes.delete(e),n.requesterBootstrapId===`__leader__`){let n=this.tabOpenResolvers.get(e);n&&(this.tabOpenResolvers.delete(e),n.reject(Error(t)));return}let r=this.followers.get(n.requesterBootstrapId);r&&r.sync.send({type:`tab.open.error`,requestId:e,error:t})}async executeLocalFs(e,t,n){let r=this.followers.get(n);if(!r)return;let i=this.options.vfs;if(!i){r.sync.send({type:`fs.response`,requestId:e,response:{ok:!1,error:`Leader has no VFS`}});return}let a=await g5(i,t);for(let t of a)r.sync.send({type:`fs.response`,requestId:e,response:t})}forwardFsRequest(e,t,n,r){let i=this.runtimeToBootstrap.get(t),a=i?this.followers.get(i):void 0,o=this.followers.get(r);if(!a){o&&o.sync.send({type:`fs.response`,requestId:e,response:{ok:!1,error:`Target runtime "${t}" not connected`}});return}this.pendingFsRoutes.set(e,{requesterBootstrapId:r,requestId:e,chunks:[],totalChunks:1}),a.sync.send({type:`fs.request`,requestId:e,request:n})}handleFsResponse(e,t){let n=this.pendingFsRoutes.get(e);if(!n){let n=this.fsResolvers.get(e);if(n){n.responses.push(t);let r=t.ok&&t.totalChunks||1;n.responses.length>=r&&(this.fsResolvers.delete(e),n.resolve(n.responses))}return}if(n.requesterBootstrapId===`__leader__`){let n=this.fsResolvers.get(e);if(n){n.responses.push(t);let r=t.ok&&t.totalChunks||1;n.responses.length>=r&&(this.fsResolvers.delete(e),this.pendingFsRoutes.delete(e),n.resolve(n.responses))}return}let r=this.followers.get(n.requesterBootstrapId);r&&r.sync.send({type:`fs.response`,requestId:e,response:t}),n.chunks.push(t),n.totalChunks=t.ok&&t.totalChunks||1,n.chunks.length>=n.totalChunks&&this.pendingFsRoutes.delete(e)}sendFsRequest(e,t){if(e===`leader`){let e=this.options.vfs;return e?g5(e,t):Promise.resolve([{ok:!1,error:`Leader has no VFS`}])}let n=this.runtimeToBootstrap.get(e),r=n?this.followers.get(n):void 0;if(!r)return Promise.resolve([{ok:!1,error:`Target runtime "${e}" not connected`}]);let i=`fs-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;return new Promise((e,n)=>{this.fsResolvers.set(i,{resolve:e,reject:n,responses:[]}),this.pendingFsRoutes.set(i,{requesterBootstrapId:`__leader__`,requestId:i,chunks:[],totalChunks:1}),r.sync.send({type:`fs.request`,requestId:i,request:t})})}},F5=o(`tray-follower-sync`),I5=class{sync;eventListeners=new Set;unsubscribe;keepalive;latestSnapshot=null;sentMessageIds=new Set;targetEntries=[];remoteTransports=new Map;cdpChunkBuffers=new Map;snapshotChunkBuffer=null;remoteCDPSessions=new Set;cdpEventCleanups=[];tabOpenResolvers=new Map;fsResolvers=new Map;constructor(e,t={}){this.options=t,this.sync=Tc(e),this.unsubscribe=this.sync.onMessage(e=>{this.handleLeaderMessage(e)}),this.keepalive=new j5({sendPing:()=>this.sync.send({type:`ping`}),onDead:()=>{F5.warn(`Leader keepalive dead, cleaning up`),this.handleDisconnect(`Keepalive timeout — leader not responding`),this.options.onDead?.()}}),this.keepalive.start(),e.addEventListener(`close`,()=>{F5.warn(`Data channel closed`),this.handleDisconnect(`Data channel closed`)}),e.addEventListener(`error`,()=>{F5.warn(`Data channel error`),this.handleDisconnect(`Data channel error`)})}sendMessage(e,t){let n=t??`follower-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;this.sentMessageIds.add(n),this.sync.send({type:`user_message`,text:e,messageId:n}),F5.info(`Sent user message to leader`,{messageId:n})}onEvent(e){return this.eventListeners.add(e),()=>this.eventListeners.delete(e)}stop(){this.sync.send({type:`abort`}),F5.info(`Sent abort to leader`)}requestSnapshot(){this.sync.send({type:`request_snapshot`})}getLatestSnapshot(){return this.latestSnapshot}close(){this.keepalive.stop(),this.unsubscribe(),this.sync.close(),this.eventListeners.clear(),this.cleanupCDPEventForwarding(),F5.info(`Follower sync closed`)}advertiseTargets(e,t){this.sync.send({type:`targets.advertise`,targets:e,runtimeId:t})}getTargets(){return this.targetEntries}disconnected=!1;handleDisconnect(e){this.disconnected||(this.disconnected=!0,_o({...go(),state:`error`,error:e}),this.emitEvent({type:`error`,error:`Connection to leader lost: ${e}`}),this.keepalive.stop(),this.cleanupCDPEventForwarding(),this.unsubscribe(),this.sync.close(),this.options.onDisconnect?.(e))}handleLeaderMessage(e){switch(e.type){case`snapshot`:F5.info(`Snapshot received from leader`,{messageCount:e.messages.length,scoopJid:e.scoopJid}),this.snapshotChunkBuffer=null,this.latestSnapshot={messages:e.messages,scoopJid:e.scoopJid},this.options.onSnapshot?.(e.messages,e.scoopJid);break;case`snapshot_chunk`:{let t=Sc(this.snapshotChunkBuffer,e);this.snapshotChunkBuffer=t.buffer,t.result&&(F5.info(`Chunked snapshot reassembled from leader`,{messageCount:t.result.messages.length,scoopJid:t.result.scoopJid}),this.latestSnapshot=t.result,this.options.onSnapshot?.(t.result.messages,t.result.scoopJid));break}case`agent_event`:this.emitEvent(e.event);break;case`user_message_echo`:if(this.sentMessageIds.has(e.messageId)){this.sentMessageIds.delete(e.messageId),F5.debug(`Skipping own message echo`,{messageId:e.messageId});break}F5.info(`User message echo received`,{messageId:e.messageId,scoopJid:e.scoopJid}),this.options.onUserMessage?.(e.text,e.messageId,e.scoopJid);break;case`status`:this.options.onStatus?.(e.scoopStatus);break;case`error`:F5.warn(`Error from leader`,{error:e.error}),this.emitEvent({type:`error`,error:e.error});break;case`targets.registry`:F5.info(`Target registry received from leader`,{targetCount:e.targets.length}),this.targetEntries=e.targets,this.options.onTargetsUpdated?.(this.targetEntries);break;case`cdp.request`:{let{requestId:t,localTargetId:n,method:r,params:i,sessionId:a}=e;this.executeLocalCDP(t,n,r,i,a);break}case`cdp.response`:this.routeCDPResponse(e);break;case`cdp.event`:for(let t of this.remoteTransports.values())t.handleEvent(e.method,e.params);break;case`tab.open`:this.executeLocalTabOpen(e.requestId,e.url);break;case`tab.opened`:{let t=this.tabOpenResolvers.get(e.requestId);t&&(this.tabOpenResolvers.delete(e.requestId),t.resolve(e.targetId));break}case`tab.open.error`:{let t=this.tabOpenResolvers.get(e.requestId);t&&(this.tabOpenResolvers.delete(e.requestId),t.reject(Error(e.error)));break}case`fs.request`:this.executeLocalFs(e.requestId,e.request);break;case`fs.response`:this.routeFsResponse(e.requestId,e.response);break;case`ping`:this.keepalive.receivePing(),this.sync.send({type:`pong`});break;case`pong`:this.keepalive.receivePong(),vo(Date.now());break}}emitEvent(e){for(let t of this.eventListeners)try{t(e)}catch(t){F5.error(`Listener error`,{eventType:e.type,error:t instanceof Error?t.message:String(t)})}}createRemoteTransport(e,t){let n=new Ec({sendCDPRequest:(n,r,i,a)=>{this.sync.send({type:`cdp.request`,requestId:n,targetRuntimeId:e,localTargetId:t,method:r,params:i,sessionId:a})}});return this.remoteTransports.set(`${e}:${t}`,n),n}removeRemoteTransport(e,t){let n=`${e}:${t}`,r=this.remoteTransports.get(n);r&&(r.disconnect(),this.remoteTransports.delete(n))}openRemoteTab(e,t){let n=`tab-open-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;return new Promise((r,i)=>{this.tabOpenResolvers.set(n,{resolve:r,reject:i}),this.sync.send({type:`tab.open`,requestId:n,targetRuntimeId:e,url:t})})}async executeLocalTabOpen(e,t){let n=this.options.browserTransport;if(!n){this.sync.send({type:`tab.open.error`,requestId:e,error:`Follower has no browser transport`});return}try{let r=(await n.send(`Target.createTarget`,{url:t,background:!0})).targetId;this.sync.send({type:`tab.opened`,requestId:e,targetId:r}),this.options.onTargetsChanged?.()}catch(t){this.sync.send({type:`tab.open.error`,requestId:e,error:t instanceof Error?t.message:String(t)})}}async executeLocalCDP(e,t,n,r,i){let a=this.options.browserTransport;if(!a){this.sync.send({type:`cdp.response`,requestId:e,error:`Follower has no browser transport`});return}try{let t=await a.send(n,r,i);if(n===`Target.attachToTarget`&&t.sessionId){let e=t.sessionId;this.remoteCDPSessions.add(e),this.setupCDPEventForwarding(a,e),F5.debug(`Tracking remote CDP session`,{remoteSessionId:e})}n===`Target.detachFromTarget`&&i&&this.remoteCDPSessions.has(i)&&(this.remoteCDPSessions.delete(i),F5.debug(`Removed remote CDP session on detach`,{sessionId:i})),vc(this.sync,e,t)}catch(t){this.sync.send({type:`cdp.response`,requestId:e,error:t instanceof Error?t.message:String(t)})}}setupCDPEventForwarding(e,t){for(let n of[`Page.frameNavigated`,`Page.loadEventFired`,`Page.domContentEventFired`,`Network.responseReceived`,`Network.loadingFinished`,`Network.requestWillBeSent`]){let r=e=>{if(e.sessionId!==t||!this.remoteCDPSessions.has(t))return;let{sessionId:r,...i}=e;this.sync.send({type:`cdp.event`,method:n,params:i,sessionId:t})};e.on(n,r),this.cdpEventCleanups.push(()=>e.off(n,r))}}cleanupCDPEventForwarding(){for(let e of this.cdpEventCleanups)e();this.cdpEventCleanups.length=0,this.remoteCDPSessions.clear()}routeCDPResponse(e){let t=yc(this.cdpChunkBuffers,e);if(t)for(let n of this.remoteTransports.values())n.handleResponse(e.requestId,t.result,t.error)}async executeLocalFs(e,t){let n=this.options.vfs;if(!n){this.sync.send({type:`fs.response`,requestId:e,response:{ok:!1,error:`Follower has no VFS`}});return}let r=await g5(n,t);for(let t of r)this.sync.send({type:`fs.response`,requestId:e,response:t})}routeFsResponse(e,t){let n=this.fsResolvers.get(e);if(!n)return;n.responses.push(t);let r=t.ok&&t.totalChunks||1;n.responses.length>=r&&(this.fsResolvers.delete(e),n.resolve(n.responses))}sendFsRequest(e,t){let n=`fs-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;return new Promise((r,i)=>{this.fsResolvers.set(n,{resolve:r,reject:i,responses:[]}),this.sync.send({type:`fs.request`,requestId:n,targetRuntimeId:e,request:t})})}},L5=o(`tab-persistence-guard`),R5=`slicc-tray-leader-active`,z5=class{active=!1;audioCtx=null;oscillator=null;lockController=null;beforeUnloadHandler=null;constructor(e={}){this.options=e}activate(){this.active||(this.active=!0,this.startSilentAudio(),this.acquireWebLock(),this.installBeforeUnload(),L5.info(`Tab persistence guard activated`))}deactivate(){this.active&&(this.active=!1,this.stopSilentAudio(),this.releaseWebLock(),this.removeBeforeUnload(),L5.info(`Tab persistence guard deactivated`))}isActive(){return this.active}startSilentAudio(){try{let e=(this.options.audioContextFactory??(()=>{let e=typeof globalThis<`u`?globalThis.AudioContext??globalThis.webkitAudioContext:void 0;return e?new e:null}))();if(!e){L5.warn(`AudioContext unavailable — discard prevention via silent audio disabled`);return}e.resume?.().catch(()=>{});let t=e.createOscillator(),n=e.createGain();n.gain.value=0,t.connect(n),n.connect(e.destination),t.start(),this.audioCtx=e,this.oscillator=t}catch(e){L5.warn(`Failed to start silent audio guard`,{error:e instanceof Error?e.message:String(e)})}}stopSilentAudio(){try{this.oscillator?.stop()}catch{}this.oscillator=null,this.audioCtx&&=(this.audioCtx.close?.().catch(()=>{}),null)}acquireWebLock(){try{let e=this.options.lockManager??(typeof navigator<`u`&&`locks`in navigator?navigator.locks:null);if(!e){L5.warn(`navigator.locks unavailable — discard prevention via Web Lock disabled`);return}let t=new AbortController;this.lockController=t,e.request(R5,{mode:`exclusive`,signal:t.signal},()=>new Promise(e=>{if(t.signal.aborted){e();return}let n=()=>{t.signal.removeEventListener(`abort`,n),e()};t.signal.addEventListener(`abort`,n,{once:!0})})).catch(e=>{e?.name!==`AbortError`&&L5.warn(`Web Lock request rejected`,{error:e instanceof Error?e.message:String(e)})})}catch(e){L5.warn(`Failed to acquire Web Lock`,{error:e instanceof Error?e.message:String(e)})}}releaseWebLock(){try{this.lockController?.abort()}catch{}this.lockController=null}installBeforeUnload(){try{let e=this.options.windowRef??(typeof window<`u`?window:null);if(!e)return;let t=()=>{};e.addEventListener(`beforeunload`,t),this.beforeUnloadHandler=t}catch{}}removeBeforeUnload(){try{let e=this.options.windowRef??(typeof window<`u`?window:null);e&&this.beforeUnloadHandler&&e.removeEventListener(`beforeunload`,this.beforeUnloadHandler)}catch{}this.beforeUnloadHandler=null}};function B5(e,t){if(t)return`extension`;try{return U5(new URL(e))?`electron-overlay`:`standalone`}catch{return`standalone`}}function V5(e,t){return e===`electron-overlay`||e===`standalone`&&t}function H5(e){try{let t=new URL(e).searchParams.get(`tab`);return t&&Wo(t)?t:Ho}catch{return Ho}}function U5(e){return e.pathname===`/electron`||e.pathname===`/electron/`||e.searchParams.get(`runtime`)===`electron-overlay`}function W5(e){let t=new URL(e);return`${t.protocol===`https:`?`wss:`:`ws:`}//${t.host}/licks-ws`}function G5(e,t){return`${new URL(e).origin}/webhooks/${t}`}function K5(e,t){return`${e.replace(/\/+$/,``)}/${t.replace(/^\/+/,``)}`}function q5(e){return typeof e==`object`&&!!e&&`type`in e&&e.type===`slicc-electron-overlay:set-tab`}var J5=[`/shared/sprinkles`];async function Y5(e){let t=new Map;for(let n of J5)await e.exists(n)&&await X5(e,n,t);return await X5(e,`/`,t),t}async function X5(e,t,n){for await(let r of e.walk(t)){if(!r.endsWith(`.shtml`))continue;let t=Z5(r);if(!n.has(t)){let i;try{i=await e.readFile(r,{encoding:`utf-8`})??``}catch{i=``}n.set(t,{name:t,path:r,title:Q5(i,t),autoOpen:$5(i)})}}}function Z5(e){let t=e.split(`/`).pop()??e;return t.endsWith(`.shtml`)?t.slice(0,-6):t}function Q5(e,t){let n=e.match(/data-sprinkle-title=["']([^"']+)["']/);if(n)return n[1];let r=e.match(/<title>([^<]+)<\/title>/i);return r?r[1].trim():t}function $5(e){return/data-sprinkle-autoopen\b/.test(e)}var e7=o(`sprinkle-manager`),t7=`slicc-open-sprinkles`,n7=class{fs;bridge;callbacks;availableSprinkles=new Map;watcherUnsub;openSprinkles=new Map;constructor(e,t,n,r){this.fs=e,this.bridge=new d0(e,t,e=>this.close(e),r),this.callbacks=n}async restoreOpenSprinkles(){try{let e=localStorage.getItem(t7);if(!e){for(let e of this.availableSprinkles.values())if(e.autoOpen)try{await this.open(e.name)}catch{e7.warn(`Failed to auto-open sprinkle`,{name:e.name})}return}let t=JSON.parse(e);for(let e of t)try{await this.open(e)}catch{e7.warn(`Failed to restore sprinkle`,{name:e})}}catch{}}persistOpenSprinkles(){try{localStorage.setItem(t7,JSON.stringify([...this.openSprinkles.keys()]))}catch{}}async openNewAutoOpenSprinkles(){await this.refresh();for(let e of this.availableSprinkles.values())if(e.autoOpen&&!this.openSprinkles.has(e.name))try{await this.open(e.name),e7.info(`Auto-opened new sprinkle after install`,{name:e.name})}catch{e7.warn(`Failed to auto-open new sprinkle`,{name:e.name})}}async refresh(){this.availableSprinkles=await Y5(this.fs),e7.info(`Discovered sprinkles`,{count:this.availableSprinkles.size})}async open(e,t){if(this.openSprinkles.has(e)){e7.info(`Sprinkle already open`,{name:e});return}let n=this.availableSprinkles.get(e);if(n||=(await this.refresh(),this.availableSprinkles.get(e)),!n)throw Error(`Sprinkle not found: ${e}`);let r=await this.fs.readFile(n.path,{encoding:`utf-8`});if(r==null)throw Error(`Failed to read sprinkle content: ${n.path} (file may be corrupted or missing)`);let i=typeof r==`string`?r:new TextDecoder(`utf-8`).decode(r),a=document.createElement(`div`);a.className=`sprinkle-panel`,a.style.cssText=`width: 100%; height: 100%; display: flex; flex-direction: column; overflow: hidden;`,a.dataset.sprinkle=e,this.openSprinkles.set(e,{renderer:null,container:a}),this.callbacks.addSprinkle(e,n.title,a,t);let o=new Xr(a,this.bridge.createAPI(e));await o.render(i,e),this.openSprinkles.get(e).renderer=o,this.persistOpenSprinkles(),V3(e),e7.info(`Sprinkle opened`,{name:e,title:n.title})}close(e){let t=this.openSprinkles.get(e);t&&(t.renderer?.dispose(),t.container.remove(),this.bridge.removeSprinkle(e),this.openSprinkles.delete(e),this.callbacks.removeSprinkle(e),this.persistOpenSprinkles(),e7.info(`Sprinkle closed`,{name:e}))}available(){return Array.from(this.availableSprinkles.values())}opened(){return Array.from(this.openSprinkles.keys())}setupWatcher(e){this.watcherUnsub=e.watch(`/workspace`,e=>e.endsWith(`.shtml`),()=>void this.refresh())}dispose(){this.watcherUnsub?.()}sendToSprinkle(e,t){let n=this.openSprinkles.get(e);if(!n){e7.warn(`Cannot send to closed sprinkle`,{name:e});return}this.bridge.pushUpdate(e,t),n.renderer.pushUpdate(t)}};async function r7(e,t,n){let r=[],i=[];for(let{path:a,handle:o}of e){let e=typeof o?.name==`string`?o.name:``;if(!o||!(`queryPermission`in o)){i.push({path:a,dirName:e});continue}let s;try{s=await o.queryPermission({mode:`readwrite`})}catch(t){n?.warn?.(`queryPermission threw on persisted handle`,{path:a,error:t instanceof Error?t.message:String(t)}),i.push({path:a,dirName:e});continue}if(s!==`granted`){i.push({path:a,dirName:e});continue}try{await t.mount(a,o),n?.info?.(`Restored mount from previous session`,{path:a,name:e}),r.push({path:a,dirName:e})}catch(t){n?.warn?.(`Failed to re-mount persisted handle`,{path:a,error:t instanceof Error?t.message:String(t)}),i.push({path:a,dirName:e})}}return{restored:r,needsRecovery:i}}function i7(e){return`'${e.replace(/'/g,`'\\''`)}'`}function a7(e){let t=e.replace(/\r\n|[\r\n]/g,` `),n=t.match(/`+/g),r=n?Math.max(...n.map(e=>e.length))+1:1,i="`".repeat(r);return`${i}${t.startsWith("`")||t.endsWith("`")?` ${t} `:t}${i}`}function o7(e){if(!Array.isArray(e)||e.length===0)return null;let t=e.map(({path:e,dirName:t})=>{let n=t?` (previously mounted from ${a7(t)})`:``;return`- ${a7(e)}${n}`}),n=e.map(({path:e})=>` mount ${i7(e)}`),r=e.length===1?`mount point`:`mount points`,i=e.length===1?`it`:`them`;return[`[Session Reload] Mount recovery required for ${e.length} ${r}.`,``,`The page was reloaded and the following ${r} lost filesystem permission. The browser cannot restore access without a fresh user gesture, so ${i} cannot be used until the user re-authorizes:`,``,...t,``,`Please tell the user what happened and ask whether they want to re-mount. If yes, run the corresponding command(s) so the folder picker opens and they can re-select the same directory:`,``,...n,``,"If the user no longer needs a mount, run `mount unmount <path>` (with the path shell-quoted the same way) to clear the stale entry instead."].join(`
15835
- `)}var $=o(`main`),s7=`slicc-pending-mount`,c7=`pendingMount`;function l7(){try{let e=new URLSearchParams(window.location.search).get(`ui-fixture`);return e===null?!1:e===``||e===`1`||e.toLowerCase()===`true`}catch{return!1}}async function u7(e){let[{createChatFixture:t,FIXTURE_SESSION_ID:n,FIXTURE_SCOOP_NAME:r}]=await Promise.all([s(()=>import(`./chat-fixture-BWvups7M.js`),[])]);await e.switchToContext(n,!0,r),e.loadMessages(t()),$.info(`Loaded UI fixture session for design iteration`)}async function d7(e){let t=await new Promise((e,t)=>{let n=indexedDB.open(s7,1);n.onupgradeneeded=()=>n.result.createObjectStore(`handles`),n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error)}),n=t.transaction(`handles`,`readwrite`);n.objectStore(`handles`).put(e,c7),await new Promise(e=>n.oncomplete=()=>e()),t.close()}async function f7(e){let t;try{t=await new Promise((e,t)=>{let n=indexedDB.open(s7,1);n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error)})}catch{return}let n=t.transaction(`handles`,`readwrite`),r=await new Promise(e=>{let t=n.objectStore(`handles`).get(c7);t.onsuccess=()=>e(t.result),t.onerror=()=>e(void 0)});if(r){n.objectStore(`handles`).delete(c7),await new Promise(e=>n.oncomplete=()=>e());let t=`/mnt/${r.name}`;await e.mount(t,r),$.info(`Mounted folder from welcome onboarding`,{name:r.name,path:t})}t.close()}function p7(){let e=document.createElement(`div`);e.className=`skill-drop-overlay`;let t=document.createElement(`div`);t.className=`skill-drop-overlay__card`;let n=document.createElement(`div`);n.className=`skill-drop-overlay__title`,t.appendChild(n);let r=document.createElement(`div`);return r.className=`skill-drop-overlay__desc`,t.appendChild(r),e.appendChild(t),document.body.appendChild(e),{show(t,i){n.textContent=t,r.textContent=i,e.classList.add(`skill-drop-overlay--visible`)},hide(){e.classList.remove(`skill-drop-overlay--visible`)}}}function m7(){let e=document.createElement(`div`);return e.className=`skill-drop-toast-container`,document.body.appendChild(e),(t,n)=>{let r=document.createElement(`div`);r.className=`skill-drop-toast skill-drop-toast--${n}`,r.textContent=t,e.appendChild(r),requestAnimationFrame(()=>r.classList.add(`skill-drop-toast--visible`)),window.setTimeout(()=>{r.classList.remove(`skill-drop-toast--visible`),window.setTimeout(()=>r.remove(),180)},4200)}}function h7(e,t,n){let r=p7(),i=0,a=!1,o=()=>{i=0,a||r.hide()};window.addEventListener(`dragenter`,e=>{Zs(e.dataTransfer)&&(e.preventDefault(),i+=1,a||r.show(`Drop .skill to install`,`Unpack into /workspace/skills/{name}.`))}),window.addEventListener(`dragover`,e=>{Zs(e.dataTransfer)&&(e.preventDefault(),e.dataTransfer&&(e.dataTransfer.dropEffect=`copy`),a||r.show(`Drop .skill to install`,`Unpack into /workspace/skills/{name}.`))}),window.addEventListener(`dragleave`,()=>{i!==0&&(i=Math.max(0,i-1),i===0&&!a&&r.hide())}),window.addEventListener(`dragend`,o),window.addEventListener(`blur`,o),window.addEventListener(`drop`,async s=>{let c=Qs(s.dataTransfer);if(!c){o();return}if(s.preventDefault(),i=0,a){r.hide(),t(`Another .skill installation is already in progress.`,`error`);return}a=!0,r.show(`Installing skill…`,c.name);try{let r=await oe(e,c);await n(),t(`Installed "${r.skillName}" to ${r.destinationPath} (${r.fileCount} files). Run "skill install ${r.skillName}" to apply it.`,`success`)}catch(e){t(`Failed to install dropped skill: ${e instanceof Error?e.message:String(e)}`,`error`)}finally{a=!1,r.hide()}})}async function g7(e){let{OffscreenClient:t}=await s(async()=>{let{OffscreenClient:e}=await import(`./offscreen-client-DJYi05-D.js`);return{OffscreenClient:e}},__vite__mapDeps([18,13])),{VirtualFS:n}=await s(async()=>{let{VirtualFS:e}=await Promise.resolve().then(()=>Js);return{VirtualFS:e}},void 0),{publishAgentBridgeProxy:r}=await s(async()=>{let{publishAgentBridgeProxy:e}=await Promise.resolve().then(()=>V8);return{publishAgentBridgeProxy:e}},void 0),i=new Yo(e,!0);window.__slicc_debug_tabs=e=>i.setDebugTabs(e),await i.panels.chat.initSession(`session-cone`),r();let a=null,o=await n.create({dbName:`slicc-fs`});i.panels.fileBrowser.setFs(o),$.info(`File browser wired to shared VFS (local IndexedDB)`);let c=new BroadcastChannel(`preview-vfs`);c.onmessage=e=>{if(e.data?.type!==`preview-vfs-read`)return;let{id:t,path:n,asText:r}=e.data;(async()=>{try{let e=r?`utf-8`:`binary`,i=await o.readFile(n,{encoding:e});c.postMessage({type:`preview-vfs-response`,id:t,content:i})}catch(e){let r=e instanceof Error?e.message:String(e);r.includes(`ENOENT`)||$.error(`Preview VFS read failed`,{path:n,error:r}),c.postMessage({type:`preview-vfs-response`,id:t,error:r})}})()},h7(o,m7(),async()=>{await i.panels.fileBrowser.refresh()});try{let{WasmShell:e}=await s(async()=>{let{WasmShell:e}=await Promise.resolve().then(()=>Q3);return{WasmShell:e}},void 0),{PanelCdpProxy:t,BrowserAPI:n}=await s(async()=>{let{PanelCdpProxy:e,BrowserAPI:t}=await Promise.resolve().then(()=>Dc);return{PanelCdpProxy:e,BrowserAPI:t}},void 0),{fetchSecretEnvVars:r}=await s(async()=>{let{fetchSecretEnvVars:e}=await Promise.resolve().then(()=>r8);return{fetchSecretEnvVars:e}},void 0),a=new t;await a.connect();let c=new n(a),l=await r(),u=new e({fs:o,browserAPI:c,env:Object.keys(l).length>0?l:void 0});await i.panels.terminal.mountShell(u),$.info(`Terminal mounted with shared VFS and BrowserAPI (CDP proxy)`)}catch(e){$.warn(`Failed to mount shell to terminal`,e)}{let{registerSessionCostsProvider:e}=await s(async()=>{let{registerSessionCostsProvider:e}=await Promise.resolve().then(()=>H2);return{registerSessionCostsProvider:e}},void 0);e(()=>new Promise(e=>{chrome.runtime.sendMessage({source:`panel`,payload:{type:`get-session-costs`}},t=>{if(chrome.runtime.lastError||!t?.ok){e([]);return}e(t.costs??[])})}))}let l,u=new Set,d=async e=>{a=e,l.selectedScoopJid=e.jid,i.panels.memory.setSelectedScoop(e.jid),i.setScoopSwitcherSelected?.(e.jid),i.panels.scoops.setSelectedJid(e.jid);let t=e.isCone?`session-cone`:`session-${e.folder}`,n=e.isCone?void 0:e.name;await i.panels.chat.switchToContext(t,!e.isCone,n),l.isProcessing(e.jid)&&i.panels.chat.setProcessing(!0)};l=new t({onStatusChange:(e,t)=>{i.panels.scoops.updateScoopStatus(e,t),i.updateScoopSwitcherStatus?.(e,t),a?.jid===e&&(i.setAgentProcessing(t===`processing`),t===`processing`?i.panels.chat.setProcessing(!0):t===`ready`&&i.panels.chat.setProcessing(!1))},onScoopCreated:e=>{i.panels.scoops.refreshScoops(),i.refreshScoopSwitcher?.(),a||(a=e,l.selectedScoopJid=e.jid,i.panels.memory.setSelectedScoop(e.jid))},onScoopListUpdate:()=>{let e=new Set(l.getScoops().map(e=>e.folder));for(let t of u)e.has(t)||i.panels.chat.deleteSessionById(`session-${t}`);if(u=e,i.panels.scoops.refreshScoops(),i.refreshScoopSwitcher?.(),!a){let e=l.getScoops().find(e=>e.isCone);e&&(a=e,l.selectedScoopJid=e.jid,i.panels.memory.setSelectedScoop(e.jid))}},onIncomingMessage:(e,t)=>{if(wa(t.channel)){let n=new Date(t.timestamp).getTime(),r=t.channel;if(a?.jid===e)i.panels.chat.addLickMessage(t.id,t.content,r,n);else{let a=l.getScoops().find(t=>t.jid===e),o=a?.isCone?`session-cone`:a?`session-${a.folder}`:`session-${e}`;i.panels.chat.persistLickToSession(o,{id:t.id,content:t.content,channel:r,timestamp:n})}return}if(a?.jid===e){let e=t.channel===`delegation`?`**[Instructions from sliccy]**\n\n${t.content}`:t.content;i.panels.chat.addUserMessage(e)}},onReady:async()=>{try{$.info(`Offscreen engine ready, scoop count:`,l.getScoops().length),window.localStorage.getItem(`slicc.trayJoinUrl`)&&chrome.runtime.sendMessage({source:`panel`,payload:{type:`refresh-tray-runtime`}}).catch(()=>{});let e=a??l.getScoops().find(e=>e.isCone)??l.getScoops()[0];e&&(a=e,l.selectedScoopJid=e.jid,await d(e))}catch(e){$.error(`Failed to initialize on ready`,{error:e instanceof Error?e.message:String(e)})}}}),l.setLocalFS(o);let f=l.createAgentHandle();i.panels.chat.setAgent(f),i.panels.scoops.setOrchestrator(l),i.panels.memory.setOrchestrator(l),i.setScoopSwitcherOrchestrator?.(l),i.onScoopSelect=d,i.onModelChange=e=>{localStorage.setItem(`selected-model`,e),l.updateModel()},i.onClearChat=async()=>{let e=l.getScoops();for(let t of e){let e=t.isCone?`session-cone`:`session-${t.folder}`;await i.panels.chat.deleteSessionById(e)}l.clearAllMessages()},i.onClearFilesystem=async()=>{l.clearFilesystem()},i.panels.chat.onInlineSprinkleLick=(e,t)=>{l.sendSprinkleLick(`inline`,{action:e,data:t})};let p=new n7(o,async e=>{if(e.type===`sprinkle`){if(e.sprinkleName===`welcome`){let t=e.body,n=t?.action;(n===`onboarding-complete`||n===`shortcut-migrate`)&&o.writeFile(`/shared/.welcomed`,`1`).catch(e=>$.warn(`Failed to persist welcome completion marker`,e)),n===`shortcut-migrate`&&p.close(`welcome`),n===`onboarding-complete`&&t?.data?.mountWorkspace&&f7(o).catch(e=>$.warn(`Failed to mount workspace from onboarding`,e))}if(e.sprinkleName===`welcome`&&e.body?.action===`request-mount`){try{let e=window;if(!e.showDirectoryPicker)throw Error(`showDirectoryPicker not supported`);let t=await e.showDirectoryPicker({mode:`readwrite`});await d7(t),p.sendToSprinkle(`welcome`,{action:`mount-complete`,dirName:t.name})}catch(e){e.name!==`AbortError`&&$.warn(`Mount picker failed`,e),p.sendToSprinkle(`welcome`,{action:`mount-cancelled`})}return}l.sendSprinkleLick(e.sprinkleName,e.body,e.targetScoop)}},{addSprinkle:(e,t,n,r)=>i.addSprinkle(e,t,n,r),removeSprinkle:e=>i.removeSprinkle(e)},()=>{let e=l.getScoops().find(e=>e.isCone);e&&l.stopScoop(e.jid)});if(window.__slicc_sprinkleManager=p,window.__slicc_reloadSkills=()=>(chrome.runtime.sendMessage({source:`panel`,payload:{type:`reload-skills`}}),Promise.resolve()),l.setSprinkleOpHandler(e=>{let{id:t,op:n,name:r,data:i}=e;console.log(`[main-ext] sprinkle-op handler called`,{id:t,op:n,name:r}),(async()=>{try{let e;switch(n){case`list`:await p.refresh(),e=p.available();break;case`opened`:e=p.opened();break;case`refresh`:await p.refresh(),e=p.available().length;break;case`open`:await p.open(r),e=!0;break;case`close`:p.close(r),e=!0;break;case`send`:p.sendToSprinkle(r,i),e=!0;break;case`openNewAutoOpen`:await p.openNewAutoOpenSprinkles(),e=!0;break}console.log(`[main-ext] sprinkle-op response sending`,{id:t,op:n,result:typeof e}),chrome.runtime.sendMessage({source:`panel`,payload:{type:`sprinkle-op-response`,id:t,result:e}}).catch(()=>{})}catch(e){chrome.runtime.sendMessage({source:`panel`,payload:{type:`sprinkle-op-response`,id:t,error:e instanceof Error?e.message:String(e)}}).catch(()=>{})}})()}),await p.refresh(),i.onSprinkleClose=e=>p.close(e),i.getAvailableSprinkles=()=>{let e=new Set(p.opened());return p.available().filter(t=>!e.has(t.name)).map(e=>({name:e.name,title:e.title}))},i.onOpenSprinkle=(e,t)=>p.open(e,t),i.updateAddButtons(),await p.restoreOpenSprinkles(),!await o.exists(`/shared/.welcomed`)&&localStorage.getItem(`slicc-welcomed`)&&(await o.writeFile(`/shared/.welcomed`,`1`).catch(()=>{}),localStorage.removeItem(`slicc-welcomed`)),!await o.exists(`/shared/.welcomed`)&&!so(window.localStorage)&&p.available().some(e=>e.name===`welcome`))try{await p.open(`welcome`)}catch(e){$.warn(`Failed to open welcome sprinkle`,e)}$.info(`SprinkleManager initialized (extension mode)`),l.requestState(),$.info(`Extension UI connected to offscreen agent engine`),l7()&&await u7(i.panels.chat),R3().catch(()=>{})}function _7(){if(typeof chrome<`u`&&chrome?.runtime?.id)return;let e=new Blob([`
15828
+ `)?n-1:n}var k8=class{scoops=new Map;tabs=new Map;contexts=new Map;messageQueues=new Map;lastAgentTimestamp=new Map;container;callbacks;config;pollInterval=null;scheduler=null;globalMemoryCache=``;sharedFs=null;scoopResponseBuffer=new Map;lickManager=null;sessionStore=null;fsWatcher=null;idleTimers=new Map;droppedScoopCosts=[];scoopObservers=new Map;mutedScoops=new Set;pendingCompletions=new Map;completionWaiters=new Map;constructor(e,t,n={name:`sliccy`,triggerPattern:/^@sliccy\b/i}){this.container=e,this.callbacks=t,this.config=n}async init(){await pe(),this.sharedFs=await Hs.create({dbName:`slicc-fs`}),this.sessionStore=new w,this.fsWatcher=new qs,this.sharedFs.setWatcher(this.fsWatcher),globalThis.__slicc_fs_watcher=this.fsWatcher,await this.ensureRootStructure();let e=await ue();for(let t of Object.values(e)){t.isCone&&(t.trigger=void 0,t.requiresTrigger=!1,t.assistantLabel=t.assistantLabel||`sliccy`),this.migrateScoopConfig(t),this.scoops.set(t.jid,t),this.messageQueues.set(t.jid,[]);let e=await ye(`lastAgentTs_${t.jid}`);e&&this.lastAgentTimestamp.set(t.jid,e)}await this.ensureGlobalMemory(),this.scheduler=new g8({onTaskRun:async(e,t)=>{C8.info(`Running scheduled task`,{taskId:e.id,scoop:t.name}),await this.sendPrompt(t.jid,`[SCHEDULED TASK]\n\n${e.prompt}`,`scheduler`,`Scheduled Task`)},getScoop:e=>{for(let t of this.scoops.values())if(t.folder===e)return t}}),this.scheduler.start(),C8.info(`Orchestrator initialized`,{scoopCount:this.scoops.size});for(let e of this.scoops.values())await this.createScoopTab(e.jid);q2(()=>this.getSessionCosts()),this.startMessageLoop()}migrateScoopConfig(e){if(e.isCone)return;let t=e.configSchemaVersion??0;t>=2||(t<1&&(e.config={...e.config,visiblePaths:e.config?.visiblePaths??[`/workspace/`]}),t<2&&(e.config={...e.config,writablePaths:e.config?.writablePaths??[`/scoops/${e.folder}/`,`/shared/`]}),e.configSchemaVersion=2)}async ensureRootStructure(){if(this.sharedFs)for(let e of[`/workspace`,`/shared`,`/scoops`,`/home`,`/tmp`,`/mnt`])try{await this.sharedFs.mkdir(e,{recursive:!0})}catch{}}async ensureGlobalMemory(){if(this.sharedFs){await Y6(this.sharedFs);try{let e=await this.sharedFs.readFile(`/shared/CLAUDE.md`,{encoding:`utf-8`});this.globalMemoryCache=typeof e==`string`?e:new TextDecoder().decode(e)}catch{C8.warn(`Global memory file not found after creating defaults`)}}}async getGlobalMemory(){if(this.globalMemoryCache)return this.globalMemoryCache;if(this.sharedFs)try{let e=await this.sharedFs.readFile(`/shared/CLAUDE.md`,{encoding:`utf-8`});this.globalMemoryCache=typeof e==`string`?e:new TextDecoder().decode(e)}catch{}return this.globalMemoryCache}async setGlobalMemory(e){this.sharedFs&&(await this.sharedFs.writeFile(`/shared/CLAUDE.md`,e),this.globalMemoryCache=e,C8.info(`Global memory updated`))}getSharedFS(){return this.sharedFs}getSessionStore(){return this.sessionStore}setLickManager(e){this.lickManager=e,globalThis.__slicc_lick_handler=e=>{this.lickManager?.emitEvent(e)}}observeScoop(e,t){let n=this.scoopObservers.get(e);return n||(n=new Set,this.scoopObservers.set(e,n)),n.add(t),()=>{let n=this.scoopObservers.get(e);n&&(n.delete(t),n.size===0&&this.scoopObservers.delete(e))}}async maybeNotifyConeOnScoopComplete(e){let t=this.scoops.get(e);if(!t||t.isCone)return;let n=this.scoopResponseBuffer.get(e);if(this.scoopResponseBuffer.delete(e),!n||t.notifyOnComplete===!1)return;let r=this.completionWaiters.get(e);if(r&&r.length>0){this.completionWaiters.delete(e);let t=n.length>2e4?n.slice(0,2e4)+`
15829
+ ... (truncated)`:n;for(let n of r)try{n(t)}catch(t){C8.warn(`completion waiter threw`,{jid:e,error:t instanceof Error?t.message:String(t)})}return}if(this.mutedScoops.has(e)){this.pendingCompletions.set(e,{responseText:n,timestamp:new Date().toISOString()}),C8.info(`Scoop completion stashed (muted)`,{scoop:t.folder,responseLength:n.length});return}await this.deliverCompletionToCone(t,n)}async deliverCompletionToCone(e,t){let n=Array.from(this.scoops.values()).find(e=>e.isCone);if(!n)return;let r=O8(t),i=t.slice(0,D8),a,o=null,s=null;try{s=await this.writeScoopCompletionArtifact(e,t),C8.info(`Routing scoop completion to cone`,{scoop:e.folder,responseLength:t.length,lineCount:r,notificationPath:s})}catch(t){o=t instanceof Error?t.message:String(t),C8.warn(`Failed to persist scoop completion artifact, falling back to inline preview`,{scoop:e.folder,error:o})}a=o===null?this.formatScoopCompletionNotification(e.assistantLabel,s??`unavailable`,r,i):this.formatScoopCompletionFallbackNotification(e.assistantLabel,r,i,o);let c={id:`scoop-done-${e.jid}-${Date.now()}`,chatJid:n.jid,senderId:e.folder,senderName:e.assistantLabel,content:a,timestamp:new Date().toISOString(),fromAssistant:!1,channel:`scoop-notify`};try{this.callbacks.onIncomingMessage?.(n.jid,c)}catch(t){C8.warn(`onIncomingMessage for scoop-notify threw`,{scoop:e.folder,error:t instanceof Error?t.message:String(t)})}try{await this.handleMessage(c)}catch(t){let r=t instanceof Error?t.message:String(t);C8.error(`Failed to route scoop completion to cone`,{scoop:e.folder,error:r}),this.callbacks.onError(n.jid,`Scoop ${e.folder} completed but notification failed: ${r}`)}}async writeScoopCompletionArtifact(e,t){if(!this.sharedFs)throw Error(`Shared filesystem not initialized`);await this.sharedFs.mkdir(T8,{recursive:!0}),await this.pruneScoopCompletionArtifacts(E8-1);let n=new Date().toISOString().replace(/[:.]/g,`-`),r=Math.random().toString(36).slice(2,8),i=`${T8}/${n}-${e.folder}-${r}.md`;return await this.sharedFs.writeFile(i,t),await this.pruneScoopCompletionArtifacts(),i}async pruneScoopCompletionArtifacts(e=E8){if(!this.sharedFs)return;let t;try{t=await this.sharedFs.readDir(T8)}catch{return}let n=t.filter(e=>e.type===`file`).map(e=>e.name).sort(),r=n.length-e;if(!(r<=0))for(let e of n.slice(0,r)){let t=`${T8}/${e}`;try{await this.sharedFs.rm(t)}catch(e){C8.warn(`Failed to prune scoop completion artifact`,{path:t,error:e instanceof Error?e.message:String(e)})}}}formatScoopCompletionNotification(e,t,n,r){return[`[@${e} completed]`,`VFS path: ${t}`,`Total lines: ${n}`,`Preview (up to ${D8} chars):`,r].join(`
15830
+ `)}formatScoopCompletionFallbackNotification(e,t,n,r){return[`[@${e} completed]`,`VFS path: unavailable`,`Artifact persistence error: ${r}`,`Total lines: ${t}`,`Preview (up to ${D8} chars):`,n].join(`
15831
+ `)}muteScoops(e){for(let t of e)this.mutedScoops.add(t);C8.info(`Scoops muted`,{count:e.length})}async unmuteScoops(e){let t=[],n=[];for(let r of e){this.mutedScoops.delete(r);let e=this.pendingCompletions.get(r);if(!e)continue;this.pendingCompletions.delete(r);let i=this.scoops.get(r);if(!i||i.isCone)continue;let a={jid:r,summary:e.responseText.length>2e4?e.responseText.slice(0,2e4)+`
15832
+ ... (truncated)`:e.responseText,timestamp:e.timestamp,notificationPath:null};t.push(a),n.push(this.writeScoopCompletionArtifact(i,e.responseText).then(e=>{a.notificationPath=e}).catch(e=>{C8.warn(`unmute artifact persist failed`,{jid:r,error:e instanceof Error?e.message:String(e)})}))}return await Promise.all(n),C8.info(`Scoops unmuted`,{count:e.length,consumed:t.length}),t}isScoopMuted(e){return this.mutedScoops.has(e)}async waitForScoops(e,t){if(e.length===0)return[];let n=Array.from(new Set(e)),r=new Map,i=[];for(let e of n)this.mutedScoops.has(e)||(this.mutedScoops.add(e),i.push(e));for(let e of n){let t=this.pendingCompletions.get(e);if(t){this.pendingCompletions.delete(e);let n=t.responseText.length>2e4?t.responseText.slice(0,2e4)+`
15833
+ ... (truncated)`:t.responseText;r.set(e,{summary:n,timedOut:!1})}}let a=n.filter(e=>!r.has(e)),o=a.filter(e=>this.scoops.has(e)),s=a.filter(e=>!this.scoops.has(e));for(let e of s)r.set(e,{summary:null,timedOut:!0});let c=[],l=o.map(e=>new Promise(t=>{let n=n=>{r.has(e)||(r.set(e,{summary:n,timedOut:n===null}),t())};c.push({jid:e,waiter:n});let i=this.completionWaiters.get(e);i||(i=[],this.completionWaiters.set(e,i)),i.push(n)})),u=null;try{l.length>0&&(t!=null&&t>=0?await Promise.race([Promise.all(l),new Promise(e=>{u=setTimeout(()=>e(),t)})]):await Promise.all(l))}finally{u&&clearTimeout(u);for(let{jid:e,waiter:t}of c){let n=this.completionWaiters.get(e);if(!n)continue;let r=n.indexOf(t);r!==-1&&n.splice(r,1),n.length===0&&this.completionWaiters.delete(e)}for(let e of i)this.mutedScoops.delete(e)}for(let e of o)r.has(e)||r.set(e,{summary:null,timedOut:!0});return e.map(e=>{let t=r.get(e)??{summary:null,timedOut:!0};return{jid:e,summary:t.summary,timedOut:t.timedOut}})}dispatchScoopEvent(e,t,...n){let r=this.scoopObservers.get(e);if(r)for(let i of r){let r=i[t];if(r)try{r(...n)}catch(n){C8.warn(`scoop observer threw`,{jid:e,event:t,error:n instanceof Error?n.message:String(n)})}}}async registerScoop(e){await Ce(e),this.scoops.set(e.jid,e),this.messageQueues.set(e.jid,[]),C8.info(`Scoop registered`,{jid:e.jid,name:e.name});try{await this.createScoopTab(e.jid)}catch(t){throw C8.error(`Scoop init failed`,{jid:e.jid,name:e.name,error:t instanceof Error?t.message:String(t)}),await this.destroyScoopTab(e.jid).catch(()=>{}),this.scoops.delete(e.jid),this.messageQueues.delete(e.jid),await me(e.jid).catch(t=>{C8.warn(`Failed to rollback scoop registration`,{jid:e.jid,name:e.name,error:t instanceof Error?t.message:String(t)})}),t}}async unregisterScoop(e){let t=this.scoops.get(e);if(t&&this.lickManager){let{webhooks:e,cronTasks:n}=this.lickManager.getLicksForScoop(t.name,t.folder),r=b8(t.folder,e,n);if(r)throw r}this.snapshotScoopCost(e),this.clearIdleTimer(e),await this.destroyScoopTab(e),this.sessionStore?.delete(e).catch(t=>{C8.warn(`Failed to delete agent session`,{jid:e,error:t instanceof Error?t.message:String(t)})}),await me(e),this.scoops.delete(e),this.messageQueues.delete(e),this.lastAgentTimestamp.delete(e),this.scoopResponseBuffer.delete(e),this.scoopObservers.delete(e);let n=this.completionWaiters.get(e);if(n){this.completionWaiters.delete(e);for(let t of n)try{t(null)}catch(t){C8.warn(`completion waiter threw on unregister`,{jid:e,error:t instanceof Error?t.message:String(t)})}}this.mutedScoops.delete(e),this.pendingCompletions.delete(e),C8.info(`Scoop unregistered`,{jid:e})}getScoops(){return Array.from(this.scoops.values())}getScoop(e){return this.scoops.get(e)}async resetFilesystem(){for(let[e,t]of this.contexts.entries())this.clearIdleTimer(e),t.stop(),this.contexts.delete(e);this.sharedFs=await Hs.create({dbName:`slicc-fs`,wipe:!0}),this.fsWatcher&&this.sharedFs.setWatcher(this.fsWatcher),await this.ensureRootStructure(),await this.ensureGlobalMemory(),await J6(this.sharedFs).catch(e=>{C8.warn(`Failed to re-seed default skills`,{error:e instanceof Error?e.message:String(e)})}),this.droppedScoopCosts=[],C8.info(`Filesystem reset and defaults re-seeded`)}async clearAllMessages(){await j(),this.sessionStore&&await this.sessionStore.clearAll().catch(e=>{C8.warn(`Failed to clear agent sessions`,{error:e instanceof Error?e.message:String(e)})});for(let e of this.contexts.values())e.clearMessages();this.lastAgentTimestamp.clear();for(let e of this.scoops.keys())this.messageQueues.set(e,[]);this.droppedScoopCosts=[],C8.info(`All messages cleared`)}async handleMessage(e){C8.info(`handleMessage`,{id:e.id,chatJid:e.chatJid,sender:e.senderName,channel:e.channel,contentPreview:e.content.slice(0,80)});let t=this.scoops.get(e.chatJid);H3(t?.isCone?`cone`:t?.name??`unknown`,localStorage.getItem(`selected-model`)??`unknown`),await se(e),await this.routeToScoop(e)}async delegateToScoop(e,t,n){let r=this.scoops.get(e);if(!r)throw Error(`Scoop not found: ${e}`);let i={id:`delegate-${Date.now()}-${Math.random().toString(36).slice(2)}`,chatJid:e,senderId:`cone`,senderName:n,content:t,timestamp:new Date().toISOString(),fromAssistant:!0,channel:`delegation`};await se(i),this.callbacks.onIncomingMessage?.(e,i),C8.info(`Delegating to scoop`,{scoopJid:e,scoopName:r.name,promptLength:t.length}),this.sendPrompt(e,t,`cone`,n).catch(t=>{let n=t instanceof Error?t.message:String(t);C8.error(`Delegation failed`,{scoopJid:e,error:n}),this.callbacks.onError(e,`Delegation failed: ${n}`)})}async routeToScoop(e){let t=this.scoops.get(e.chatJid);if(!t){C8.info(`routeToScoop: unregistered target`,{chatJid:e.chatJid});return}let n=e.channel===`webhook`||e.channel===`cron`||e.channel===`fswatch`||e.channel===`sprinkle`;if(!t.isCone&&t.requiresTrigger&&t.trigger&&!n&&!e.content.includes(t.trigger)){C8.info(`routeToScoop: trigger not found in content`,{chatJid:e.chatJid,trigger:t.trigger,contentPreview:e.content.slice(0,80)});return}let r=this.messageQueues.get(e.chatJid)??[];r.push(e),this.messageQueues.set(e.chatJid,r);let i=this.tabs.get(e.chatJid);if(C8.debug(`routeToScoop: queued`,{chatJid:e.chatJid,scoopName:t.name,tabStatus:i?.status??`no-tab`,queueLength:r.length}),i?.status===`error`){C8.info(`routeToScoop: tab in error state, retrying init`,{chatJid:e.chatJid});try{await this.createScoopTab(e.chatJid),i=this.tabs.get(e.chatJid)}catch{C8.warn(`routeToScoop: retry init failed`,{chatJid:e.chatJid})}}i?.status===`ready`&&await this.processScoopQueue(e.chatJid)}async createScoopTab(e){let t=this.scoops.get(e);if(!t)throw Error(`Scoop not found: ${e}`);if(this.contexts.has(e))if(this.tabs.get(e)?.status===`error`)C8.info(`Re-creating context after error`,{jid:e}),this.contexts.get(e)?.dispose(),this.contexts.delete(e),this.tabs.delete(e);else{C8.debug(`Context already exists`,{jid:e});return}if(!this.sharedFs)throw Error(`Shared filesystem not initialized`);let n=`scoop-${t.folder}-${Date.now()}`,r=t.isCone?this.sharedFs:new Us(this.sharedFs,t.config?.writablePaths?[...t.config.writablePaths]:[],t.config?.visiblePaths?[...t.config.visiblePaths]:[]),i={onResponse:(n,r)=>{if(this.scoops.has(e)&&(this.callbacks.onResponse(e,n,r),this.dispatchScoopEvent(e,`onResponse`,n,r),!t.isCone))if(r){let t=this.scoopResponseBuffer.get(e)??``;this.scoopResponseBuffer.set(e,t+n)}else this.scoopResponseBuffer.set(e,n)},onResponseDone:()=>{if(!this.scoops.has(e))return;let t=this.tabs.get(e);t&&(t.lastActivity=new Date().toISOString(),this.tabs.set(e,t)),this.callbacks.onResponseDone(e)},onError:t=>{if(!this.scoops.has(e))return;let n=this.tabs.get(e);n&&(n.status=`error`,n.error=t,this.tabs.set(e,n)),this.callbacks.onError(e,t),this.callbacks.onStatusChange(e,`error`),this.dispatchScoopEvent(e,`onError`,t),this.dispatchScoopEvent(e,`onStatusChange`,`error`)},onFatalError:t=>{if(!this.scoops.has(e))return;let n=this.scoops.get(e);C8.error(`Fatal scoop error`,{jid:e,folder:n.folder,error:t});let r=this.tabs.get(e);if(r&&(r.status=`error`,r.error=t,this.tabs.set(e,r)),this.callbacks.onError(e,t),this.callbacks.onStatusChange(e,`error`),this.dispatchScoopEvent(e,`onError`,t),this.dispatchScoopEvent(e,`onStatusChange`,`error`),n.isCone)return;this.mutedScoops.delete(e),this.pendingCompletions.delete(e),this.scoopResponseBuffer.delete(e);let i=this.completionWaiters.get(e);if(i&&i.length>0){this.completionWaiters.delete(e);for(let t of i)try{t(null)}catch(t){C8.warn(`completion waiter threw on fatal error`,{jid:e,error:t instanceof Error?t.message:String(t)})}}let a=Array.from(this.scoops.values()).find(e=>e.isCone);if(!a)return;let o={id:`scoop-error-${e}-${Date.now()}`,chatJid:a.jid,senderId:n.folder,senderName:n.assistantLabel,content:`[@${n.assistantLabel} FAILED]: ${t}`,timestamp:new Date().toISOString(),fromAssistant:!1,channel:`scoop-error`};try{this.callbacks.onIncomingMessage?.(a.jid,o)}catch(e){C8.warn(`onIncomingMessage for scoop-error threw`,{scoop:n.folder,error:e instanceof Error?e.message:String(e)})}this.handleMessage(o).catch(e=>{C8.error(`Failed to route fatal error to cone`,{scoop:n.folder,error:e instanceof Error?e.message:String(e)})})},onStatusChange:n=>{if(!this.scoops.has(e))return;let r=this.tabs.get(e);r&&(r.status=n,r.lastActivity=new Date().toISOString(),this.tabs.set(e,r)),this.callbacks.onStatusChange(e,n),this.dispatchScoopEvent(e,`onStatusChange`,n),n===`ready`&&!t.isCone&&this.maybeNotifyConeOnScoopComplete(e)},onToolStart:(t,n)=>{this.callbacks.onToolStart?.(e,t,n)},onToolEnd:(t,n,r)=>{this.callbacks.onToolEnd?.(e,t,n,r)},onToolUI:(t,n,r)=>{this.callbacks.onToolUI?.(e,t,n,r)},onToolUIDone:t=>{this.callbacks.onToolUIDone?.(e,t)},onSendMessage:(t,n)=>{let r=`${n?`[${n}] `:``}${t}`;this.callbacks.onSendMessage(e,r),this.dispatchScoopEvent(e,`onSendMessage`,t)},getScoops:()=>this.getScoops(),getScoopTabState:t.isCone?e=>this.tabs.get(e):void 0,onFeedScoop:t.isCone?(e,n)=>this.delegateToScoop(e,n,t.assistantLabel):void 0,onScoopScoop:t.isCone?async e=>{let t={...e,jid:`scoop_${e.folder}_${Date.now()}`};return await this.registerScoop(t),t}:void 0,onDropScoop:t.isCone?async e=>{await this.unregisterScoop(e)}:void 0,onMuteScoops:t.isCone?e=>this.muteScoops(e):void 0,onUnmuteScoops:t.isCone?e=>this.unmuteScoops(e):void 0,onWaitForScoops:t.isCone?(e,t)=>this.waitForScoops(e,t):void 0,getGlobalMemory:()=>this.getGlobalMemory(),setGlobalMemory:t.isCone?e=>this.setGlobalMemory(e):void 0,getBrowserAPI:()=>this.callbacks.getBrowserAPI()},a=Array.from(this.scoops.values()).find(e=>e.isCone)?.jid,o=new m8(t,i,r,this.sessionStore??void 0,this.sharedFs??void 0,a);this.contexts.set(e,o),this.tabs.set(e,{jid:e,contextId:n,status:`initializing`,lastActivity:new Date().toISOString()}),await o.init();let s=this.tabs.get(e);s&&s.status===`initializing`&&(s.status=`ready`,this.tabs.set(e,s),this.callbacks.onStatusChange(e,`ready`),this.dispatchScoopEvent(e,`onStatusChange`,`ready`));let c=this.scoops.get(e);c&&!c.isCone&&this.startIdleTimer(e),C8.info(`Scoop context created`,{jid:e,contextId:n})}async destroyScoopTab(e){this.clearIdleTimer(e);let t=this.contexts.get(e);t&&(t.dispose(),this.contexts.delete(e),this.tabs.delete(e),this.scoopObservers.delete(e),C8.info(`Scoop context destroyed`,{jid:e}))}isProcessing(e){return this.tabs.get(e)?.status===`processing`}getScoopContext(e){return this.contexts.get(e)}async clearQueuedMessages(e){let t=this.messageQueues.get(e);if(t&&t.length>0){for(let e of t)await be(e.id);this.messageQueues.set(e,[])}}async deleteQueuedMessage(e,t){let n=this.messageQueues.get(e);if(n){let e=n.findIndex(e=>e.id===t);e!==-1&&n.splice(e,1)}await be(t)}async getMessagesForScoop(e){return de(e)}async waitForTabReady(e,t=1e4){let n=Date.now();for(;Date.now()-n<t;){let t=this.tabs.get(e);if(!t)return!1;if(t.status===`ready`||t.status===`processing`)return!0;if(t.status===`error`)return!1;await new Promise(e=>setTimeout(e,100))}return C8.warn(`Timed out waiting for tab to become ready`,{jid:e}),!1}async sendPrompt(e,t,n,r){let i=this.contexts.get(e);i||=(await this.createScoopTab(e),this.contexts.get(e));let a=this.tabs.get(e);if(a?.status===`initializing`){if(C8.debug(`Context initializing, waiting to send message`,{jid:e}),!await this.waitForTabReady(e)){C8.error(`Context did not become ready in time, dropping prompt`,{jid:e});return}i=this.contexts.get(e),a=this.tabs.get(e)}if(!i){C8.error(`Context not found after creation`,{jid:e});return}this.clearIdleTimer(e),this.scoopResponseBuffer.delete(e),a&&(a.status=`processing`,a.lastActivity=new Date().toISOString(),this.tabs.set(e,a),this.callbacks.onStatusChange(e,`processing`),this.dispatchScoopEvent(e,`onStatusChange`,`processing`)),C8.debug(`Prompt sent to scoop`,{jid:e,textLength:t.length}),await i.prompt(t)}async processScoopQueue(e){let t=this.messageQueues.get(e);if(!t||t.length===0){C8.debug(`processScoopQueue: empty queue`,{jid:e});return}let n=this.tabs.get(e);if(n?.status!==`ready`){C8.debug(`processScoopQueue: tab not ready`,{jid:e,status:n?.status??`no-tab`});return}let r=this.scoops.get(e),i=r?.assistantLabel??e,a=this.lastAgentTimestamp.get(e)??``,o=await fe(e,a,i);if(C8.debug(`processScoopQueue: DB query`,{jid:e,scoopName:r?.name,excludeName:i,since:a,dbMessageCount:o.length,queueLength:t.length}),o.length===0){C8.debug(`processScoopQueue: no messages from DB, clearing queue`,{jid:e}),this.messageQueues.set(e,[]);return}let s=o.map(e=>`[${new Date(e.timestamp).toLocaleString(`en-US`,{month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`,hour12:!0})}] ${e.senderName}: ${e.content}`).join(`
15834
+ `);this.messageQueues.set(e,[]);let c=o[o.length-1];this.lastAgentTimestamp.set(e,c.timestamp),await we(`lastAgentTs_${e}`,c.timestamp),await this.sendPrompt(e,s,c.senderId,c.senderName)}startMessageLoop(){this.pollInterval||=window.setInterval(()=>{for(let e of this.scoops.keys())this.tabs.get(e)?.status===`ready`&&this.processScoopQueue(e).catch(t=>{let n=t instanceof Error?t.message:String(t);C8.error(`Message queue processing failed`,{jid:e,error:n}),this.callbacks.onError(e,`Queue processing failed: ${n}`)})},2e3)}stopMessageLoop(){this.pollInterval&&=(clearInterval(this.pollInterval),null)}updateModel(){for(let e of this.contexts.values())e.updateModel();C8.info(`Model updated on all active contexts`,{contextCount:this.contexts.size})}async reloadAllSkills(){let e=[];for(let[t,n]of this.contexts){let r=this.tabs.get(t);(r?.status===`ready`||r?.status===`processing`)&&e.push(n.reloadSkills().catch(e=>{C8.warn(`Failed to reload skills for scoop`,{jid:t,error:e instanceof Error?e.message:String(e)})}))}await Promise.all(e),C8.info(`Skills reloaded across all contexts`,{count:e.length})}stopScoop(e){let t=this.contexts.get(e);t&&t.stop()}buildScoopCost(e,t){let n=t.getAgentMessages().filter(e=>e.role===`assistant`);if(n.length===0)return null;let r={input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},i=new Map;for(let e of n)r.input+=e.usage.input,r.output+=e.usage.output,r.cacheRead+=e.usage.cacheRead,r.cacheWrite+=e.usage.cacheWrite,r.totalTokens+=e.usage.totalTokens,r.cost.input+=e.usage.cost.input,r.cost.output+=e.usage.cost.output,r.cost.cacheRead+=e.usage.cost.cacheRead,r.cost.cacheWrite+=e.usage.cost.cacheWrite,r.cost.total+=e.usage.cost.total,i.set(e.model,(i.get(e.model)??0)+1);let a=``,o=0;for(let[e,t]of i)t>o&&(a=e,o=t);let s=n.map(e=>e.timestamp).sort((e,t)=>e-t),c=s[0],l=s[s.length-1],u=900*1e3,d=l-c,f=Math.max(1,Math.ceil(d/u))*u;return{name:e.assistantLabel,type:e.isCone?`cone`:`scoop`,model:a,usage:r,turns:n.length,firstActivity:c,lastActivity:l,activeTimeMs:f}}snapshotScoopCost(e){let t=this.scoops.get(e),n=this.contexts.get(e);if(!t||!n)return;let r=this.buildScoopCost(t,n);r&&this.droppedScoopCosts.push(r)}getSessionCosts(){let e=[];for(let t of this.scoops.values()){let n=this.contexts.get(t.jid);if(!n)continue;let r=this.buildScoopCost(t,n);r&&e.push(r)}return e.push(...this.droppedScoopCosts),e}startIdleTimer(e){if(this.clearIdleTimer(e),this.tabs.get(e)?.status===`processing`)return;let t=setTimeout(()=>{this.idleTimers.delete(e);let t=this.scoops.get(e);if(!t||t.isCone||this.tabs.get(e)?.status!==`ready`)return;let n=Array.from(this.scoops.values()).find(e=>e.isCone);if(!n)return;let r={id:`scoop-idle-${e}-${Date.now()}`,chatJid:n.jid,senderId:t.folder,senderName:t.assistantLabel,content:`[@${t.assistantLabel} idle]: Scoop "${t.name}" has been ready for 2 minutes without receiving any work. This is expected if the scoop is waiting for webhooks or cron tasks. If you intended to delegate work, use feed_scoop to send a prompt.`,timestamp:new Date().toISOString(),fromAssistant:!1,channel:`scoop-idle`};C8.info(`Scoop idle timeout`,{jid:e,scoop:t.folder});try{this.callbacks.onIncomingMessage?.(n.jid,r)}catch(t){C8.warn(`onIncomingMessage for scoop-idle threw`,{jid:e,error:t instanceof Error?t.message:String(t)})}this.handleMessage(r).catch(t=>{let n=t instanceof Error?t.message:String(t);C8.error(`Failed to send idle notification`,{jid:e,error:n})})},w8);this.idleTimers.set(e,t)}clearIdleTimer(e){let t=this.idleTimers.get(e);t&&(clearTimeout(t),this.idleTimers.delete(e))}async shutdown(){this.stopMessageLoop();for(let e of this.idleTimers.keys())this.clearIdleTimer(e);this.scheduler?.stop(),this.scheduler=null;for(let e of this.completionWaiters.values())for(let t of e)try{t(null)}catch(e){C8.warn(`completion waiter threw during shutdown`,{error:e instanceof Error?e.message:String(e)})}this.completionWaiters.clear(),this.mutedScoops.clear(),this.pendingCompletions.clear();for(let e of this.contexts.keys())await this.destroyScoopTab(e);C8.info(`Orchestrator shutdown`)}};o(`heartbeat`);var A8=o(`tray-follower`);function j8(e){let t=new URL(e);return t.searchParams.set(`json`,`true`),t.toString()}async function M8(e){let t=j8(e.joinUrl),n=await z8(await(e.fetchImpl??fetch)(t,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({controllerId:e.controllerId,runtime:e.runtime})}));return A8.info(`Follower tray attach response`,{trayId:n.trayId,action:n.result.action,code:n.result.code,participantCount:n.participantCount}),N8(n)}function N8(e){let t={trayId:e.trayId,controllerId:e.controllerId,participantCount:e.participantCount,leader:e.leader,action:e.result.action,code:e.result.code,iceServers:e.iceServers};return e.result.action===`wait`?{...t,retryAfterMs:e.result.retryAfterMs}:e.result.action===`signal`?{...t,bootstrap:e.result.bootstrap}:e.result.action===`fail`?{...t,error:e.result.error}:t}async function P8(e){return R8(await B8(e,{action:`poll`,controllerId:e.controllerId,bootstrapId:e.bootstrapId,cursor:e.cursor}))}async function F8(e){return R8(await B8(e,{action:`answer`,controllerId:e.controllerId,bootstrapId:e.bootstrapId,answer:e.answer}))}async function I8(e){return R8(await B8(e,{action:`ice-candidate`,controllerId:e.controllerId,bootstrapId:e.bootstrapId,candidate:e.candidate}))}async function L8(e){return R8(await B8(e,{action:`retry`,controllerId:e.controllerId,bootstrapId:e.bootstrapId,runtime:e.runtime}))}function R8(e){return{trayId:e.trayId,controllerId:e.controllerId,participantCount:e.participantCount,leader:e.leader,bootstrap:e.bootstrap,events:e.events}}async function z8(e){let t=null,n=null;try{t=await e.text(),n=JSON.parse(t)}catch{}if(!V8(n)){let n=t?t.slice(0,200):`(empty)`;throw A8.warn(`Tray follower attach returned an invalid response`,{status:e.status,body:n}),Error(`Tray follower attach returned an invalid response (${e.status}): ${n}`)}return n}async function B8(e,t){let n=j8(e.joinUrl),r=await(e.fetchImpl??fetch)(n,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t)}),i=await r.json().catch(()=>null);if(!H8(i))throw Error(`Tray follower bootstrap returned an invalid response (${r.status})`);return i}function V8(e){if(!e||typeof e!=`object`)return!1;let t=e;if(typeof t.trayId!=`string`||typeof t.controllerId!=`string`||t.role!==`follower`||typeof t.participantCount!=`number`)return!1;let n=t.result;if(!n||typeof n!=`object`)return!1;let r=n;return r.action===`wait`?(r.code===`LEADER_NOT_ELECTED`||r.code===`LEADER_NOT_CONNECTED`)&&typeof r.retryAfterMs==`number`:r.action===`signal`?r.code===`LEADER_CONNECTED`&&U8(r.bootstrap):r.action===`fail`?(r.code===`INVALID_JOIN_CAPABILITY`||r.code===`TRAY_EXPIRED`)&&typeof r.error==`string`:!1}function H8(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.trayId==`string`&&typeof t.controllerId==`string`&&t.role===`follower`&&typeof t.participantCount==`number`&&U8(t.bootstrap)&&Array.isArray(t.events)}function U8(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.controllerId==`string`&&typeof t.bootstrapId==`string`&&typeof t.attempt==`number`&&typeof t.state==`string`&&typeof t.expiresAt==`string`&&typeof t.cursor==`number`&&typeof t.maxRetries==`number`&&typeof t.retriesRemaining==`number`}var W8=i({AGENT_BRIDGE_GLOBAL_KEY:()=>K8,AGENT_SPAWN_REQUEST_TYPE:()=>q8,createAgentBridge:()=>J8,publishAgentBridge:()=>Y8,publishAgentBridgeProxy:()=>X8}),G8=o(`agent-bridge`),K8=`__slicc_agent`,q8=`agent-spawn-request`;function J8(e,t,n=null,r={}){let i=r.generateName??e5,a=r.generateUid??Z8,o=r.resolveModel??n5;function s(){for(let t=0;t<8;t++){let t=i(),n=`agent_${t5(t)}`;if(!e.getScoops().some(e=>e.jid===n))return t}return a()}function c(t){if(t===void 0)return null;let n=e.getScoops().find(e=>e.jid===t);if(!n)return null;let r=n.config?.modelId;return r&&r.length>0?r:null}async function l(r){let i=r.modelId;if(i!==void 0&&(i===``||o(i)===null))return{finalText:`agent: unknown model: ${i}`,exitCode:1};let a=i??c(r.parentJid)??``,l=s(),u=`agent-${l}`,d=`agent_${t5(l)}`,f=`/scoops/${u}`,p=r5(r.cwd),m={visiblePaths:i5(r),writablePaths:a5([p,`/shared/`,`${f}/`,`/tmp/`]),allowedCommands:r.allowedCommands};a&&(m.modelId=a);let h={jid:d,name:u,folder:u,isCone:!1,type:`scoop`,requiresTrigger:!1,assistantLabel:u,addedAt:new Date().toISOString(),config:m,configSchemaVersion:2,notifyOnComplete:!1},g=[],_=``,v=null,y=e.observeScoop(d,{onSendMessage:e=>{g.push(e)},onResponse:(e,t)=>{t?_+=e:_=e},onError:e=>{v===null&&(v=e)}});try{try{await e.registerScoop(h)}catch(e){return{finalText:v??o5(e),exitCode:1}}return await e.sendPrompt(d,r.prompt,`agent`,`agent`),v===null?{finalText:g.length>0?g[g.length-1]:_,exitCode:0}:{finalText:v,exitCode:1}}catch(e){return{finalText:v??o5(e),exitCode:1}}finally{y();try{await e.unregisterScoop(d)}catch(e){G8.warn(`unregisterScoop failed`,{jid:d,error:o5(e)})}try{await t.rm(f,{recursive:!0})}catch(e){s5(e,`ENOENT`)||G8.warn(`scratch folder cleanup failed`,{folder:u,error:o5(e)})}if(n)try{await n.delete(d)}catch(e){G8.warn(`sessionStore.delete failed`,{jid:d,error:o5(e)})}}}return{spawn:l}}function Y8(e,t,n=null,r={}){let i=J8(e,t,n,r);return globalThis[K8]=i,G8.info(`agent bridge published on globalThis.__slicc_agent`),i}function X8(){let e={spawn(e){return new Promise((t,n)=>{let r=globalThis.chrome?.runtime;if(!r||typeof r.sendMessage!=`function`){n(Error(`agent: chrome.runtime.sendMessage not available`));return}let i=e=>{let i=r.lastError;if(i){n(Error(i.message??`chrome.runtime error`));return}if(e==null){n(Error(`agent: empty response from offscreen bridge`));return}let a=e;if(!a.ok){n(Error(a.error??`agent: offscreen bridge error`));return}if(!a.result){n(Error(`agent: offscreen bridge returned no result`));return}t(a.result)};try{r.sendMessage({source:`panel`,payload:{type:q8,options:e}},i)}catch(e){n(e instanceof Error?e:Error(String(e)))}})}};return globalThis[K8]=e,G8.info(`agent bridge proxy published on globalThis.__slicc_agent`),e}function Z8(){let e=globalThis;return typeof e.crypto?.randomUUID==`function`?e.crypto.randomUUID().replace(/-/g,``).slice(0,12):`${Date.now().toString(36)}${Math.random().toString(36).slice(2,8)}`}var Q8=`amber.bouncy.breezy.bubbly.cheeky.chilly.cozy.dapper.dreamy.eager.exuberant.fluffy.frosty.gentle.giddy.glossy.jolly.lucky.mellow.merry.nimble.plucky.quirky.salty.sleepy.snappy.sparkly.spiffy.sunny.sweet.toasty.velvety.whimsy.zesty`.split(`.`),$8=`blueberry.butterscotch.caramel.cherry.chocolate.cinnamon.coconut.coffee.cookies.custard.espresso.fudge.gelato.hazelnut.honeycomb.lavender.lemon.mango.maple.marzipan.matcha.mint.mocha.neapolitan.nougat.peach.pecan.pistachio.praline.raspberry.sherbet.sorbet.stracciatella.strawberry.tiramisu.toffee.vanilla`.split(`.`);function e5(){return`${Q8[Math.floor(Math.random()*Q8.length)]}-${$8[Math.floor(Math.random()*$8.length)]}`}function t5(e){return e.replace(/-/g,`_`)}function n5(e){try{let t=h();for(let n of t)if(n.models.some(t=>t.id===e))return e;return null}catch{return null}}function r5(e){let t=k(e);return t.endsWith(`/`)?t:`${t}/`}function i5(e){if(e.visiblePaths!==void 0)return e.visiblePaths.map(r5);let t=[`/workspace/`];return e.invokingCwd&&e.invokingCwd.length>0&&t.push(r5(e.invokingCwd)),a5(t)}function a5(e){let t=new Set,n=[];for(let r of e)t.has(r)||(t.add(r),n.push(r));return n}function o5(e){return e instanceof Error?e.message:String(e)}function s5(e,t){if(typeof e!=`object`||!e)return!1;let n=e.code;return typeof n==`string`&&n===t}var c5=o(`tray-webrtc`),l5=`tray-control`,u5=250,d5=class{peerConnectionFactory;dataChannelLabel;peers=new Map;iceServers;constructor(e){this.options=e,this.iceServers=e.iceServers,this.peerConnectionFactory=e.peerConnectionFactory??(()=>m5(this.iceServers)),this.dataChannelLabel=e.dataChannelLabel??l5}setIceServers(e){this.iceServers=e}async handleControlMessage(e){e.type===`follower.join_requested`?(e.iceServers&&!this.iceServers&&(this.iceServers=e.iceServers),await this.handleJoinRequested(e)):e.type===`bootstrap.answer`?await this.peers.get(e.bootstrapId)?.peer.setRemoteDescription(e.answer):e.type===`bootstrap.ice_candidate`&&await this.peers.get(e.bootstrapId)?.peer.addIceCandidate(e.candidate)}getPeers(){return Array.from(this.peers.values()).map(({state:e})=>({...e}))}getChannel(e){return this.peers.get(e)?.channel??null}stop(){for(let e of this.peers.values())e.peer.close();this.peers.clear()}async handleJoinRequested(e){this.closeControllerPeers(e.controllerId);let t=this.peerConnectionFactory(),n={controllerId:e.controllerId,bootstrapId:e.bootstrapId,attempt:e.attempt,state:`connecting`,connectedAt:null,runtime:e.runtime},r=t.createDataChannel(this.dataChannelLabel);this.peers.set(e.bootstrapId,{state:n,peer:t,channel:r}),t.addEventListener(`icecandidate`,({candidate:t})=>{let n=g5(t);n&&this.options.sendControlMessage({type:`bootstrap.ice_candidate`,controllerId:e.controllerId,bootstrapId:e.bootstrapId,candidate:n})}),t.addEventListener(`connectionstatechange`,()=>{let n=this.peers.get(e.bootstrapId);n&&(n.state.state===`connected`?(t.connectionState===`disconnected`||t.connectionState===`failed`)&&(c5.warn(`Leader peer connection state changed post-connect`,{bootstrapId:e.bootstrapId,state:t.connectionState}),this.options.onPeerDisconnected?.(e.bootstrapId,`Peer connection ${t.connectionState}`)):t.connectionState===`failed`&&this.failPeer(e,`Leader peer connection failed before the data channel opened`))}),r.addEventListener(`open`,()=>{let t=this.peers.get(e.bootstrapId);!t||t.state.state===`connected`||(t.state.state=`connected`,t.state.connectedAt=new Date().toISOString(),this.options.onPeerConnected?.({...t.state},t.channel))}),r.addEventListener(`close`,()=>{let t=this.peers.get(e.bootstrapId);t&&(t.state.state===`connected`?(c5.warn(`Leader data channel closed post-connect`,{bootstrapId:e.bootstrapId}),this.options.onPeerDisconnected?.(e.bootstrapId,`Data channel closed`)):this.failPeer(e,`Leader data channel closed before opening`))}),r.addEventListener(`error`,()=>{let t=this.peers.get(e.bootstrapId);t&&(t.state.state===`connected`?(c5.warn(`Leader data channel error post-connect`,{bootstrapId:e.bootstrapId}),this.options.onPeerDisconnected?.(e.bootstrapId,`Data channel error`)):this.failPeer(e,`Leader data channel failed before opening`))});try{let n=await t.createOffer();await t.setLocalDescription(n),this.options.sendControlMessage({type:`bootstrap.offer`,controllerId:e.controllerId,bootstrapId:e.bootstrapId,offer:h5(t.localDescription??n,`offer`)})}catch(t){this.failPeer(e,t instanceof Error?t.message:String(t))}}closeControllerPeers(e){for(let[t,n]of this.peers.entries())n.state.controllerId===e&&(n.peer.close(),this.peers.delete(t))}failPeer(e,t){let n=this.peers.get(e.bootstrapId);if(n){n.peer.close(),this.peers.delete(e.bootstrapId);try{this.options.sendControlMessage({type:`bootstrap.failed`,controllerId:e.controllerId,bootstrapId:e.bootstrapId,code:`WEBRTC_BOOTSTRAP_FAILED`,message:t,retryable:!0,retryAfterMs:1e3})}catch(e){c5.warn(`Failed to report tray bootstrap failure`,{error:e instanceof Error?e.message:String(e)})}}}},f5=class{fetchImpl;peerConnectionFactory;controllerIdFactory;sleep;pollIntervalMs;iceServers;activePeer=null;stopped=!1;constructor(e){this.options=e,this.fetchImpl=e.fetchImpl??fetch,this.iceServers=e.iceServers,this.peerConnectionFactory=e.peerConnectionFactory??(()=>m5(this.iceServers)),this.controllerIdFactory=e.controllerIdFactory??(()=>crypto.randomUUID()),this.sleep=e.sleep??(e=>new Promise(t=>setTimeout(t,e))),this.pollIntervalMs=e.pollIntervalMs??u5}async start(){this.stopped=!1;let e=this.controllerIdFactory(),t=Date.now();_o({state:`connecting`,joinUrl:this.options.joinUrl,trayId:null,error:null,lastPingTime:null,reconnectAttempts:0,attachAttempts:0,lastAttachCode:null,connectingSince:t,lastError:null}),c5.info(`Follower tray join starting`,{joinUrl:this.options.joinUrl});let n=0;for(;;){_5(this.stopped),n++;let t;try{t=await M8({joinUrl:this.options.joinUrl,controllerId:e,runtime:this.options.runtime,fetchImpl:this.fetchImpl})}catch(e){let t=e instanceof Error?e.message:String(e);throw _o({...go(),attachAttempts:n,lastError:t}),e}if(_o({...go(),attachAttempts:n,lastAttachCode:t.code}),t.action===`wait`){let e=t.retryAfterMs??1e3;c5.info(`Follower tray attach waiting`,{attempt:n,code:t.code,retryAfterMs:e}),n%10==0&&c5.warn(`Follower tray attach still waiting after ${n} attempts`,{attempt:n,code:t.code,retryAfterMs:e}),await this.sleep(e);continue}if(t.action===`fail`||!t.bootstrap){let e=t.error??`Tray follower attach failed (${t.code})`;throw _o({state:`error`,joinUrl:this.options.joinUrl,trayId:null,error:e,lastPingTime:null,reconnectAttempts:0,attachAttempts:n,lastAttachCode:t.code,connectingSince:null,lastError:e}),c5.warn(`Follower tray attach failed`,{error:e}),Error(e)}t.iceServers&&(this.iceServers=t.iceServers);try{let r=await this.completeBootstrap(t.trayId,e,t.bootstrap);return _o({state:`connected`,joinUrl:this.options.joinUrl,trayId:r.trayId,error:null,lastPingTime:null,reconnectAttempts:0,attachAttempts:n,lastAttachCode:t.code,connectingSince:null,lastError:null}),c5.info(`Follower tray connected`,{trayId:r.trayId,controllerId:e}),r}catch(e){let r=e instanceof Error?e.message:String(e);throw _o({state:`error`,joinUrl:this.options.joinUrl,trayId:t.trayId,error:r,lastPingTime:null,reconnectAttempts:0,attachAttempts:n,lastAttachCode:t.code,connectingSince:null,lastError:r}),c5.warn(`Follower tray bootstrap failed`,{error:r}),e}}}stop(){this.stopped=!0,this.activePeer?.peer.close(),this.activePeer?.channel?.close(),this.activePeer=null,_o({state:`inactive`,joinUrl:null,trayId:null,error:null,lastPingTime:null,reconnectAttempts:0,attachAttempts:0,lastAttachCode:null,connectingSince:null,lastError:null})}async completeBootstrap(e,t,n){let r=n,i=0;for(this.activePeer=this.createFollowerPeer(t,r.bootstrapId);;){if(_5(this.stopped),this.activePeer.open&&this.activePeer.channel)return{trayId:e,controllerId:t,bootstrapId:r.bootstrapId,channel:this.activePeer.channel};if(this.activePeer.openError)throw Error(this.activePeer.openError);let n=await P8({joinUrl:this.options.joinUrl,controllerId:t,bootstrapId:r.bootstrapId,cursor:i,fetchImpl:this.fetchImpl});r=n.bootstrap,i=r.cursor;try{for(let e of n.events)if(e.type===`bootstrap.offer`){await this.activePeer.peer.setRemoteDescription(e.offer);let n=await this.activePeer.peer.createAnswer();await this.activePeer.peer.setLocalDescription(n),await F8({joinUrl:this.options.joinUrl,controllerId:t,bootstrapId:r.bootstrapId,answer:h5(this.activePeer.peer.localDescription??n,`answer`),fetchImpl:this.fetchImpl})}else if(e.type===`bootstrap.ice_candidate`)await this.activePeer.peer.addIceCandidate(e.candidate);else if(e.type===`bootstrap.failed`)throw Error(e.failure.message)}catch(e){if(r.failure?.retryable&&r.retriesRemaining>0){r=(await L8({joinUrl:this.options.joinUrl,controllerId:t,bootstrapId:r.bootstrapId,runtime:this.options.runtime,fetchImpl:this.fetchImpl})).bootstrap,i=0,this.activePeer.peer.close(),this.activePeer=this.createFollowerPeer(t,r.bootstrapId);continue}throw e}this.activePeer.open||await this.sleep(this.pollIntervalMs)}}createFollowerPeer(e,t){let n=this.peerConnectionFactory(),r={peer:n,channel:null,open:!1,openError:null};return n.addEventListener(`connectionstatechange`,()=>{r.open&&(n.connectionState===`disconnected`||n.connectionState===`failed`)&&(c5.warn(`Follower peer connection state changed post-connect`,{bootstrapId:t,state:n.connectionState}),this.options.onDisconnected?.(`Peer connection ${n.connectionState}`))}),n.addEventListener(`datachannel`,({channel:e})=>{r.channel=e,e.addEventListener(`open`,()=>{r.open=!0}),e.addEventListener(`close`,()=>{r.open?(c5.warn(`Follower data channel closed post-connect`,{bootstrapId:t}),this.options.onDisconnected?.(`Data channel closed`)):r.openError=`Follower data channel closed before opening`}),e.addEventListener(`error`,()=>{r.open?(c5.warn(`Follower data channel error post-connect`,{bootstrapId:t}),this.options.onDisconnected?.(`Data channel error`)):r.openError=`Follower data channel failed before opening`})}),n.addEventListener(`icecandidate`,({candidate:n})=>{let r=g5(n);r&&I8({joinUrl:this.options.joinUrl,controllerId:e,bootstrapId:t,candidate:r,fetchImpl:this.fetchImpl}).catch(e=>{c5.warn(`Failed to send follower ICE candidate`,{error:e instanceof Error?e.message:String(e)})})}),r}};function p5(e,t){let n=t.baseDelayMs??1e3,r=t.backoffMultiplier??2,i=t.maxDelayMs??3e4,a=t.maxAttempts??10,o=t.sleep??e.sleep??(e=>new Promise(t=>setTimeout(t,e))),s=!1,c=!1,l=null,u={cancel(){s=!0,c=!1,l?.stop(),l=null},get reconnecting(){return c}},d=()=>{let t=new f5({...e,sleep:o,onDisconnected:e=>{s||(c5.warn(`Follower disconnected, starting reconnect loop`,{reason:e}),f(e))}});return l=t,{manager:t,connectionPromise:t.start()}},f=async u=>{if(s||c)return;c=!0,l?.stop(),l=null;let f=0,p=n,m=u??`Unknown disconnect`;for(;!s&&f<a&&(f++,t.onReconnecting?.(f),_o({...go(),state:`reconnecting`,error:null,reconnectAttempts:f}),c5.info(`Reconnect attempt`,{attempt:f,delay:p}),await o(p),!s);){let n=null;try{let r=d();n=r.manager;let i=await r.connectionPromise;if(s){n.stop();break}c=!1,_o({...go(),state:`connected`,joinUrl:e.joinUrl,trayId:i.trayId,error:null,lastPingTime:null,reconnectAttempts:0,connectingSince:null,lastError:null}),c5.info(`Reconnect successful`,{attempt:f,trayId:i.trayId}),t.onConnected(i);return}catch(e){m=e instanceof Error?e.message:String(e),c5.warn(`Reconnect attempt failed`,{attempt:f,error:m}),n?.stop(),l=null}p=Math.min(p*r,i)}s||(c=!1,_o({...go(),state:`error`,error:`Reconnect failed after ${f} attempts: ${m}`,reconnectAttempts:f}),c5.warn(`Reconnect gave up`,{attempts:f,lastError:m}),t.onGaveUp?.(m))},{connectionPromise:p}=d();return p.then(e=>{s||t.onConnected(e)}).catch(e=>{s||c5.warn(`Initial follower connection failed`,{error:e instanceof Error?e.message:String(e)})}),u}function m5(e){if(typeof RTCPeerConnection>`u`)throw Error(`RTCPeerConnection is not available in this runtime`);let t=e?.length?{iceServers:e}:void 0;return new RTCPeerConnection(t)}function h5(e,t){if(!e||e.type!==t||typeof e.sdp!=`string`)throw Error(`Expected a local ${t} description before signaling`);return{type:e.type,sdp:e.sdp}}function g5(e){if(!e||typeof e!=`object`)return null;let t=e;return typeof t.candidate==`string`?{candidate:t.candidate,sdpMid:typeof t.sdpMid==`string`?t.sdpMid:null,sdpMLineIndex:typeof t.sdpMLineIndex==`number`?t.sdpMLineIndex:null,usernameFragment:typeof t.usernameFragment==`string`?t.usernameFragment:null}:null}function _5(e){if(e)throw Error(`Tray follower stopped before WebRTC bootstrap completed`)}var v5=64*1024;async function y5(e,t){try{switch(t.op){case`readFile`:return await b5(e,t.path,t.encoding);case`writeFile`:return[await x5(e,t.path,t.content,t.encoding)];case`stat`:return[await S5(e,t.path)];case`readDir`:return[await C5(e,t.path)];case`mkdir`:return[await w5(e,t.path,t.recursive)];case`rm`:return[await T5(e,t.path,t.recursive)];case`exists`:return[await E5(e,t.path)];case`walk`:return[await D5(e,t.path)];default:return[{ok:!1,error:`Unknown fs operation: ${t.op}`}]}}catch(e){return[k5(e)]}}async function b5(e,t,n){return(n??`utf-8`)===`utf-8`?O5(await e.readFile(t,{encoding:`utf-8`}),`utf-8`):O5(A5(await e.readFile(t,{encoding:`binary`})),`base64`)}async function x5(e,t,n,r){if(r===`base64`){let r=j5(n);await e.writeFile(t,r)}else await e.writeFile(t,n);return{ok:!0,data:{type:`void`}}}async function S5(e,t){return{ok:!0,data:{type:`stat`,stat:await e.stat(t)}}}async function C5(e,t){return{ok:!0,data:{type:`dirEntries`,entries:await e.readDir(t)}}}async function w5(e,t,n){return await e.mkdir(t,{recursive:n}),{ok:!0,data:{type:`void`}}}async function T5(e,t,n){return await e.rm(t,{recursive:n}),{ok:!0,data:{type:`void`}}}async function E5(e,t){return{ok:!0,data:{type:`exists`,exists:await e.exists(t)}}}async function D5(e,t){let n=[];for await(let r of e.walk(t))n.push(r);return{ok:!0,data:{type:`paths`,paths:n}}}function O5(e,t){if(e.length<=v5)return[{ok:!0,data:{type:`file`,content:e,encoding:t}}];let n=Math.ceil(e.length/v5),r=[];for(let i=0;i<n;i++){let a=i*v5,o=e.slice(a,a+v5);r.push({ok:!0,data:{type:`file`,content:o,encoding:t},chunkIndex:i,totalChunks:n})}return r}function k5(e){return e instanceof Error&&`code`in e?{ok:!1,error:e.message,code:e.code}:{ok:!1,error:e instanceof Error?e.message:String(e)}}function A5(e){let t=``;for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);return btoa(t)}function j5(e){let t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}var M5=class{runtimes=new Map;dirty=!1;setTargets(e,t){this.runtimes.set(e,t),this.dirty=!0}removeRuntime(e){this.runtimes.delete(e)&&(this.dirty=!0)}getEntries(){this.dirty=!1;let e=[];for(let[t,n]of this.runtimes)for(let r of n)e.push({targetId:`${t}:${r.targetId}`,localTargetId:r.targetId,runtimeId:t,title:r.title,url:r.url,isLocal:!1});return e}hasChanged(){return this.dirty}getRuntimeIds(){return[...this.runtimes.keys()]}},N5=o(`data-channel-keepalive`),P5=class{sendPing;onDead;intervalMs;maxMissed;timer=null;missedPongs=0;awaitingPong=!1;stopped=!1;constructor(e){this.sendPing=e.sendPing,this.onDead=e.onDead,this.intervalMs=e.intervalMs??1e4,this.maxMissed=e.maxMissed??3}start(){this.timer||this.stopped||(this.timer=setInterval(()=>this.tick(),this.intervalMs))}stop(){this.stopped=!0,this.timer&&=(clearInterval(this.timer),null)}receivePong(){this.awaitingPong=!1,this.missedPongs=0}receivePing(){this.missedPongs=0,this.awaitingPong=!1}get missed(){return this.missedPongs}tick(){if(!this.stopped){if(this.awaitingPong&&(this.missedPongs++,N5.debug(`Missed pong`,{missedPongs:this.missedPongs,maxMissed:this.maxMissed}),this.missedPongs>=this.maxMissed)){N5.warn(`Channel declared dead`,{missedPongs:this.missedPongs}),this.stop(),this.onDead();return}this.awaitingPong=!0,this.sendPing()}}},F5=o(`tray-leader-sync`);function I5(e){return e?e.includes(`standalone`)?`standalone`:e.includes(`extension`)?`extension`:e.includes(`electron`)?`electron`:`unknown`:`unknown`}var L5=class{followers=new Map;registry=new M5;runtimeToBootstrap=new Map;pendingCDPRoutes=new Map;cdpChunkBuffers=new Map;remoteTransports=new Map;pendingTabOpenRoutes=new Map;tabOpenResolvers=new Map;pendingFsRoutes=new Map;fsResolvers=new Map;constructor(e){this.options=e}addFollower(e,t,n){this.removeFollower(e);let r=wc(t),i=r.onMessage(t=>{this.handleFollowerMessage(e,t)}),a=new P5({sendPing:()=>r.send({type:`ping`}),onDead:()=>{F5.warn(`Follower keepalive dead, removing follower`,{bootstrapId:e}),this.removeFollower(e),this.options.onFollowerDead?.(e)}});a.start(),this.followers.set(e,{bootstrapId:e,sync:r,unsubscribe:i,keepalive:a,runtime:n?.runtime,connectedAt:n?.connectedAt,lastActivity:Date.now(),floatType:I5(n?.runtime)}),F5.info(`Follower added to sync`,{bootstrapId:e,followerCount:this.followers.size}),this.options.onFollowerCountChanged?.(this.followers.size),this.sendSnapshotToFollower(e);let o=this.getConnectedEntries();o.length>0&&r.send({type:`targets.registry`,targets:o})}removeFollower(e){let t=this.followers.get(e);if(t){t.keepalive.stop(),t.unsubscribe(),t.sync.close(),this.followers.delete(e);for(let[t,n]of this.runtimeToBootstrap)if(n===e){this.cleanupRemoteTransports(t),this.registry.removeRuntime(t),this.runtimeToBootstrap.delete(t);break}this.registry.hasChanged()&&this.broadcastTargetRegistry(),F5.info(`Follower removed from sync`,{bootstrapId:e,followerCount:this.followers.size}),this.options.onFollowerCountChanged?.(this.followers.size)}}broadcastEvent(e){if(this.followers.size===0)return;let t={type:`agent_event`,event:e,scoopJid:this.options.getScoopJid()};for(let e of this.followers.values())e.sync.send(t)}broadcastUserMessage(e,t){if(this.followers.size===0)return;let n={type:`user_message_echo`,text:e,messageId:t,scoopJid:this.options.getScoopJid()};for(let e of this.followers.values())e.sync.send(n)}broadcastStatus(e){if(this.followers.size===0)return;let t={type:`status`,scoopStatus:e};for(let e of this.followers.values())e.sync.send(t)}sendSnapshotToFollower(e){let t=this.followers.get(e);if(!t)return;let n=this.options.getMessages(),r=this.options.getScoopJid();xc(t.sync,n,r),F5.debug(`Snapshot sent to follower`,{bootstrapId:e,messageCount:n.length})}handleFollowerMessage(e,t){switch(t.type){case`user_message`:F5.info(`Follower user message received`,{bootstrapId:e,messageId:t.messageId}),this.options.onFollowerMessage(t.text,t.messageId);break;case`abort`:F5.info(`Follower abort received`,{bootstrapId:e}),this.options.onFollowerAbort();break;case`request_snapshot`:F5.info(`Follower snapshot request received`,{bootstrapId:e}),this.sendSnapshotToFollower(e);break;case`targets.advertise`:F5.info(`Follower targets advertised`,{bootstrapId:e,runtimeId:t.runtimeId,targetCount:t.targets.length});for(let e of[...this.remoteTransports.keys()]){let n=e.substring(0,e.indexOf(`:`));n!==`leader`&&!this.runtimeToBootstrap.has(n)&&n!==t.runtimeId&&(this.remoteTransports.get(e)?.disconnect(),this.remoteTransports.delete(e),F5.debug(`Cleaned up orphaned remote transport on advertise`,{key:e}))}this.runtimeToBootstrap.set(t.runtimeId,e),this.registry.setTargets(t.runtimeId,t.targets),this.broadcastTargetRegistry();break;case`cdp.request`:{let{requestId:n,targetRuntimeId:r,localTargetId:i,method:a,params:o,sessionId:s}=t;r===`leader`?this.executeLocalCDP(n,i,a,o,s,e):this.forwardCDPRequest(n,r,i,a,o,s,e);break}case`cdp.response`:this.handleCDPResponse(t);break;case`cdp.event`:this.handleCDPEvent(e,t.method,t.params,t.sessionId);break;case`tab.open`:{let{requestId:n,targetRuntimeId:r,url:i}=t;r===`leader`?this.executeLocalTabOpen(n,i,e):this.forwardTabOpen(n,r,i,e);break}case`tab.opened`:this.handleTabOpenResponse(t.requestId,t.targetId);break;case`tab.open.error`:this.handleTabOpenError(t.requestId,t.error);break;case`fs.request`:{let{requestId:n,targetRuntimeId:r,request:i}=t;r===`leader`?this.executeLocalFs(n,i,e):this.forwardFsRequest(n,r,i,e);break}case`fs.response`:this.handleFsResponse(t.requestId,t.response);break;case`ping`:{let t=this.followers.get(e);t&&(t.keepalive.receivePing(),t.lastActivity=Date.now(),t.sync.send({type:`pong`}));break}case`pong`:{let t=this.followers.get(e);t&&(t.keepalive.receivePong(),t.lastActivity=Date.now());break}}}setLocalTargets(e){this.registry.setTargets(`leader`,e),this.registry.hasChanged()&&this.broadcastTargetRegistry()}broadcastTargetRegistry(){if(this.followers.size===0)return;let e={type:`targets.registry`,targets:this.getConnectedEntries()};for(let t of this.followers.values())t.sync.send(e)}getTargets(){return this.getConnectedEntries()}getConnectedEntries(){return this.registry.getEntries().filter(e=>{if(e.runtimeId===`leader`)return!0;let t=this.runtimeToBootstrap.get(e.runtimeId);return t?this.followers.has(t):!1})}createRemoteTransport(e,t){let n=new Ec({sendCDPRequest:(n,r,i,a)=>{let o=this.runtimeToBootstrap.get(e),s=o?this.followers.get(o):void 0;if(!s){this.remoteTransports.get(`${e}:${t}`)?.handleResponse(n,void 0,`Target runtime "${e}" not connected`);return}this.pendingCDPRoutes.set(n,{requesterBootstrapId:`__leader__`,requestId:n}),s.sync.send({type:`cdp.request`,requestId:n,localTargetId:t,method:r,params:i,sessionId:a})}});return this.remoteTransports.set(`${e}:${t}`,n),n}removeRemoteTransport(e,t){let n=`${e}:${t}`,r=this.remoteTransports.get(n);r&&(r.disconnect(),this.remoteTransports.delete(n))}cleanupRemoteTransports(e){let t=`${e}:`;for(let e of[...this.remoteTransports.keys()])e.startsWith(t)&&(this.remoteTransports.get(e)?.disconnect(),this.remoteTransports.delete(e),F5.debug(`Cleaned up stale remote transport`,{key:e}))}getConnectedFollowers(){return[...this.runtimeToBootstrap.entries()].map(([e,t])=>{let n=this.followers.get(t);return{runtimeId:e,runtime:n?.runtime,connectedAt:n?.connectedAt,lastActivity:n?.lastActivity,floatType:n?.floatType}})}getBestFollowerForTeleport(){let e=[];for(let[t,n]of this.runtimeToBootstrap){let r=this.followers.get(n);r&&e.push({runtimeId:t,bootstrapId:n,floatType:r.floatType,lastActivity:r.lastActivity})}if(e.length===0)return null;let t=e.filter(e=>e.floatType===`standalone`),n=t.length>0?t:e;return n.sort((e,t)=>t.lastActivity-e.lastActivity),n[0]}get hasFollowers(){return this.followers.size>0}stop(){for(let e of[...this.followers.keys()])this.removeFollower(e)}async executeLocalCDP(e,t,n,r,i,a){let o=this.followers.get(a);if(!o)return;let s=this.options.browserTransport;if(!s){o.sync.send({type:`cdp.response`,requestId:e,error:`Leader has no browser transport`});return}try{let t=await s.send(n,r,i);vc(o.sync,e,t)}catch(t){o.sync.send({type:`cdp.response`,requestId:e,error:t instanceof Error?t.message:String(t)})}}forwardCDPRequest(e,t,n,r,i,a,o){let s=this.runtimeToBootstrap.get(t),c=s?this.followers.get(s):void 0,l=this.followers.get(o);if(!c){l&&l.sync.send({type:`cdp.response`,requestId:e,error:`Target runtime "${t}" not connected`});return}this.pendingCDPRoutes.set(e,{requesterBootstrapId:o,requestId:e}),c.sync.send({type:`cdp.request`,requestId:e,localTargetId:n,method:r,params:i,sessionId:a})}handleCDPResponse(e){let{requestId:t,result:n,error:r,chunkData:i,chunkIndex:a,totalChunks:o}=e,s=this.pendingCDPRoutes.get(t);if(!s)return;let c=yc(this.cdpChunkBuffers,e);if(!c)return;if(this.pendingCDPRoutes.delete(t),s.requesterBootstrapId===`__leader__`){for(let e of this.remoteTransports.values())e.handleResponse(t,c.result,c.error);return}let l=this.followers.get(s.requesterBootstrapId);l&&vc(l.sync,t,c.result,c.error)}handleCDPEvent(e,t,n,r){let i;for(let[t,n]of this.runtimeToBootstrap)if(n===e){i=t;break}if(!i)return;let a=`${i}:`;for(let[e,r]of this.remoteTransports)e.startsWith(a)&&r.handleEvent(t,n)}openRemoteTab(e,t){let n=this.runtimeToBootstrap.get(e),r=n?this.followers.get(n):void 0;if(!r)return Promise.reject(Error(`Target runtime "${e}" not connected`));let i=`tab-open-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;return new Promise((e,n)=>{this.tabOpenResolvers.set(i,{resolve:e,reject:n}),this.pendingTabOpenRoutes.set(i,{requesterBootstrapId:`__leader__`,requestId:i}),r.sync.send({type:`tab.open`,requestId:i,url:t})})}async executeLocalTabOpen(e,t,n){let r=this.followers.get(n);if(!r)return;let i=this.options.browserTransport;if(!i){r.sync.send({type:`tab.open.error`,requestId:e,error:`Leader has no browser transport`});return}try{let n=(await i.send(`Target.createTarget`,{url:t,background:!0})).targetId;r.sync.send({type:`tab.opened`,requestId:e,targetId:`leader:${n}`})}catch(t){r.sync.send({type:`tab.open.error`,requestId:e,error:t instanceof Error?t.message:String(t)})}}forwardTabOpen(e,t,n,r){let i=this.runtimeToBootstrap.get(t),a=i?this.followers.get(i):void 0,o=this.followers.get(r);if(!a){o&&o.sync.send({type:`tab.open.error`,requestId:e,error:`Target runtime "${t}" not connected`});return}this.pendingTabOpenRoutes.set(e,{requesterBootstrapId:r,requestId:e}),a.sync.send({type:`tab.open`,requestId:e,url:n})}handleTabOpenResponse(e,t){let n=this.pendingTabOpenRoutes.get(e);if(!n)return;if(this.pendingTabOpenRoutes.delete(e),n.requesterBootstrapId===`__leader__`){let n=this.tabOpenResolvers.get(e);n&&(this.tabOpenResolvers.delete(e),n.resolve(t));return}let r=this.followers.get(n.requesterBootstrapId);r&&r.sync.send({type:`tab.opened`,requestId:e,targetId:t})}handleTabOpenError(e,t){let n=this.pendingTabOpenRoutes.get(e);if(!n)return;if(this.pendingTabOpenRoutes.delete(e),n.requesterBootstrapId===`__leader__`){let n=this.tabOpenResolvers.get(e);n&&(this.tabOpenResolvers.delete(e),n.reject(Error(t)));return}let r=this.followers.get(n.requesterBootstrapId);r&&r.sync.send({type:`tab.open.error`,requestId:e,error:t})}async executeLocalFs(e,t,n){let r=this.followers.get(n);if(!r)return;let i=this.options.vfs;if(!i){r.sync.send({type:`fs.response`,requestId:e,response:{ok:!1,error:`Leader has no VFS`}});return}let a=await y5(i,t);for(let t of a)r.sync.send({type:`fs.response`,requestId:e,response:t})}forwardFsRequest(e,t,n,r){let i=this.runtimeToBootstrap.get(t),a=i?this.followers.get(i):void 0,o=this.followers.get(r);if(!a){o&&o.sync.send({type:`fs.response`,requestId:e,response:{ok:!1,error:`Target runtime "${t}" not connected`}});return}this.pendingFsRoutes.set(e,{requesterBootstrapId:r,requestId:e,chunks:[],totalChunks:1}),a.sync.send({type:`fs.request`,requestId:e,request:n})}handleFsResponse(e,t){let n=this.pendingFsRoutes.get(e);if(!n){let n=this.fsResolvers.get(e);if(n){n.responses.push(t);let r=t.ok&&t.totalChunks||1;n.responses.length>=r&&(this.fsResolvers.delete(e),n.resolve(n.responses))}return}if(n.requesterBootstrapId===`__leader__`){let n=this.fsResolvers.get(e);if(n){n.responses.push(t);let r=t.ok&&t.totalChunks||1;n.responses.length>=r&&(this.fsResolvers.delete(e),this.pendingFsRoutes.delete(e),n.resolve(n.responses))}return}let r=this.followers.get(n.requesterBootstrapId);r&&r.sync.send({type:`fs.response`,requestId:e,response:t}),n.chunks.push(t),n.totalChunks=t.ok&&t.totalChunks||1,n.chunks.length>=n.totalChunks&&this.pendingFsRoutes.delete(e)}sendFsRequest(e,t){if(e===`leader`){let e=this.options.vfs;return e?y5(e,t):Promise.resolve([{ok:!1,error:`Leader has no VFS`}])}let n=this.runtimeToBootstrap.get(e),r=n?this.followers.get(n):void 0;if(!r)return Promise.resolve([{ok:!1,error:`Target runtime "${e}" not connected`}]);let i=`fs-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;return new Promise((e,n)=>{this.fsResolvers.set(i,{resolve:e,reject:n,responses:[]}),this.pendingFsRoutes.set(i,{requesterBootstrapId:`__leader__`,requestId:i,chunks:[],totalChunks:1}),r.sync.send({type:`fs.request`,requestId:i,request:t})})}},R5=o(`tray-follower-sync`),z5=class{sync;eventListeners=new Set;unsubscribe;keepalive;latestSnapshot=null;sentMessageIds=new Set;targetEntries=[];remoteTransports=new Map;cdpChunkBuffers=new Map;snapshotChunkBuffer=null;remoteCDPSessions=new Set;cdpEventCleanups=[];tabOpenResolvers=new Map;fsResolvers=new Map;constructor(e,t={}){this.options=t,this.sync=Tc(e),this.unsubscribe=this.sync.onMessage(e=>{this.handleLeaderMessage(e)}),this.keepalive=new P5({sendPing:()=>this.sync.send({type:`ping`}),onDead:()=>{R5.warn(`Leader keepalive dead, cleaning up`),this.handleDisconnect(`Keepalive timeout — leader not responding`),this.options.onDead?.()}}),this.keepalive.start(),e.addEventListener(`close`,()=>{R5.warn(`Data channel closed`),this.handleDisconnect(`Data channel closed`)}),e.addEventListener(`error`,()=>{R5.warn(`Data channel error`),this.handleDisconnect(`Data channel error`)})}sendMessage(e,t){let n=t??`follower-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;this.sentMessageIds.add(n),this.sync.send({type:`user_message`,text:e,messageId:n}),R5.info(`Sent user message to leader`,{messageId:n})}onEvent(e){return this.eventListeners.add(e),()=>this.eventListeners.delete(e)}stop(){this.sync.send({type:`abort`}),R5.info(`Sent abort to leader`)}requestSnapshot(){this.sync.send({type:`request_snapshot`})}getLatestSnapshot(){return this.latestSnapshot}close(){this.keepalive.stop(),this.unsubscribe(),this.sync.close(),this.eventListeners.clear(),this.cleanupCDPEventForwarding(),R5.info(`Follower sync closed`)}advertiseTargets(e,t){this.sync.send({type:`targets.advertise`,targets:e,runtimeId:t})}getTargets(){return this.targetEntries}disconnected=!1;handleDisconnect(e){this.disconnected||(this.disconnected=!0,_o({...go(),state:`error`,error:e}),this.emitEvent({type:`error`,error:`Connection to leader lost: ${e}`}),this.keepalive.stop(),this.cleanupCDPEventForwarding(),this.unsubscribe(),this.sync.close(),this.options.onDisconnect?.(e))}handleLeaderMessage(e){switch(e.type){case`snapshot`:R5.info(`Snapshot received from leader`,{messageCount:e.messages.length,scoopJid:e.scoopJid}),this.snapshotChunkBuffer=null,this.latestSnapshot={messages:e.messages,scoopJid:e.scoopJid},this.options.onSnapshot?.(e.messages,e.scoopJid);break;case`snapshot_chunk`:{let t=Sc(this.snapshotChunkBuffer,e);this.snapshotChunkBuffer=t.buffer,t.result&&(R5.info(`Chunked snapshot reassembled from leader`,{messageCount:t.result.messages.length,scoopJid:t.result.scoopJid}),this.latestSnapshot=t.result,this.options.onSnapshot?.(t.result.messages,t.result.scoopJid));break}case`agent_event`:this.emitEvent(e.event);break;case`user_message_echo`:if(this.sentMessageIds.has(e.messageId)){this.sentMessageIds.delete(e.messageId),R5.debug(`Skipping own message echo`,{messageId:e.messageId});break}R5.info(`User message echo received`,{messageId:e.messageId,scoopJid:e.scoopJid}),this.options.onUserMessage?.(e.text,e.messageId,e.scoopJid);break;case`status`:this.options.onStatus?.(e.scoopStatus);break;case`error`:R5.warn(`Error from leader`,{error:e.error}),this.emitEvent({type:`error`,error:e.error});break;case`targets.registry`:R5.info(`Target registry received from leader`,{targetCount:e.targets.length}),this.targetEntries=e.targets,this.options.onTargetsUpdated?.(this.targetEntries);break;case`cdp.request`:{let{requestId:t,localTargetId:n,method:r,params:i,sessionId:a}=e;this.executeLocalCDP(t,n,r,i,a);break}case`cdp.response`:this.routeCDPResponse(e);break;case`cdp.event`:for(let t of this.remoteTransports.values())t.handleEvent(e.method,e.params);break;case`tab.open`:this.executeLocalTabOpen(e.requestId,e.url);break;case`tab.opened`:{let t=this.tabOpenResolvers.get(e.requestId);t&&(this.tabOpenResolvers.delete(e.requestId),t.resolve(e.targetId));break}case`tab.open.error`:{let t=this.tabOpenResolvers.get(e.requestId);t&&(this.tabOpenResolvers.delete(e.requestId),t.reject(Error(e.error)));break}case`fs.request`:this.executeLocalFs(e.requestId,e.request);break;case`fs.response`:this.routeFsResponse(e.requestId,e.response);break;case`ping`:this.keepalive.receivePing(),this.sync.send({type:`pong`});break;case`pong`:this.keepalive.receivePong(),vo(Date.now());break}}emitEvent(e){for(let t of this.eventListeners)try{t(e)}catch(t){R5.error(`Listener error`,{eventType:e.type,error:t instanceof Error?t.message:String(t)})}}createRemoteTransport(e,t){let n=new Ec({sendCDPRequest:(n,r,i,a)=>{this.sync.send({type:`cdp.request`,requestId:n,targetRuntimeId:e,localTargetId:t,method:r,params:i,sessionId:a})}});return this.remoteTransports.set(`${e}:${t}`,n),n}removeRemoteTransport(e,t){let n=`${e}:${t}`,r=this.remoteTransports.get(n);r&&(r.disconnect(),this.remoteTransports.delete(n))}openRemoteTab(e,t){let n=`tab-open-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;return new Promise((r,i)=>{this.tabOpenResolvers.set(n,{resolve:r,reject:i}),this.sync.send({type:`tab.open`,requestId:n,targetRuntimeId:e,url:t})})}async executeLocalTabOpen(e,t){let n=this.options.browserTransport;if(!n){this.sync.send({type:`tab.open.error`,requestId:e,error:`Follower has no browser transport`});return}try{let r=(await n.send(`Target.createTarget`,{url:t,background:!0})).targetId;this.sync.send({type:`tab.opened`,requestId:e,targetId:r}),this.options.onTargetsChanged?.()}catch(t){this.sync.send({type:`tab.open.error`,requestId:e,error:t instanceof Error?t.message:String(t)})}}async executeLocalCDP(e,t,n,r,i){let a=this.options.browserTransport;if(!a){this.sync.send({type:`cdp.response`,requestId:e,error:`Follower has no browser transport`});return}try{let t=await a.send(n,r,i);if(n===`Target.attachToTarget`&&t.sessionId){let e=t.sessionId;this.remoteCDPSessions.add(e),this.setupCDPEventForwarding(a,e),R5.debug(`Tracking remote CDP session`,{remoteSessionId:e})}n===`Target.detachFromTarget`&&i&&this.remoteCDPSessions.has(i)&&(this.remoteCDPSessions.delete(i),R5.debug(`Removed remote CDP session on detach`,{sessionId:i})),vc(this.sync,e,t)}catch(t){this.sync.send({type:`cdp.response`,requestId:e,error:t instanceof Error?t.message:String(t)})}}setupCDPEventForwarding(e,t){for(let n of[`Page.frameNavigated`,`Page.loadEventFired`,`Page.domContentEventFired`,`Network.responseReceived`,`Network.loadingFinished`,`Network.requestWillBeSent`]){let r=e=>{if(e.sessionId!==t||!this.remoteCDPSessions.has(t))return;let{sessionId:r,...i}=e;this.sync.send({type:`cdp.event`,method:n,params:i,sessionId:t})};e.on(n,r),this.cdpEventCleanups.push(()=>e.off(n,r))}}cleanupCDPEventForwarding(){for(let e of this.cdpEventCleanups)e();this.cdpEventCleanups.length=0,this.remoteCDPSessions.clear()}routeCDPResponse(e){let t=yc(this.cdpChunkBuffers,e);if(t)for(let n of this.remoteTransports.values())n.handleResponse(e.requestId,t.result,t.error)}async executeLocalFs(e,t){let n=this.options.vfs;if(!n){this.sync.send({type:`fs.response`,requestId:e,response:{ok:!1,error:`Follower has no VFS`}});return}let r=await y5(n,t);for(let t of r)this.sync.send({type:`fs.response`,requestId:e,response:t})}routeFsResponse(e,t){let n=this.fsResolvers.get(e);if(!n)return;n.responses.push(t);let r=t.ok&&t.totalChunks||1;n.responses.length>=r&&(this.fsResolvers.delete(e),n.resolve(n.responses))}sendFsRequest(e,t){let n=`fs-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;return new Promise((r,i)=>{this.fsResolvers.set(n,{resolve:r,reject:i,responses:[]}),this.sync.send({type:`fs.request`,requestId:n,targetRuntimeId:e,request:t})})}},B5=o(`tab-persistence-guard`),V5=`slicc-tray-leader-active`,H5=class{active=!1;audioCtx=null;oscillator=null;lockController=null;beforeUnloadHandler=null;constructor(e={}){this.options=e}activate(){this.active||(this.active=!0,this.startSilentAudio(),this.acquireWebLock(),this.installBeforeUnload(),B5.info(`Tab persistence guard activated`))}deactivate(){this.active&&(this.active=!1,this.stopSilentAudio(),this.releaseWebLock(),this.removeBeforeUnload(),B5.info(`Tab persistence guard deactivated`))}isActive(){return this.active}startSilentAudio(){try{let e=(this.options.audioContextFactory??(()=>{let e=typeof globalThis<`u`?globalThis.AudioContext??globalThis.webkitAudioContext:void 0;return e?new e:null}))();if(!e){B5.warn(`AudioContext unavailable — discard prevention via silent audio disabled`);return}e.resume?.().catch(()=>{});let t=e.createOscillator(),n=e.createGain();n.gain.value=0,t.connect(n),n.connect(e.destination),t.start(),this.audioCtx=e,this.oscillator=t}catch(e){B5.warn(`Failed to start silent audio guard`,{error:e instanceof Error?e.message:String(e)})}}stopSilentAudio(){try{this.oscillator?.stop()}catch{}this.oscillator=null,this.audioCtx&&=(this.audioCtx.close?.().catch(()=>{}),null)}acquireWebLock(){try{let e=this.options.lockManager??(typeof navigator<`u`&&`locks`in navigator?navigator.locks:null);if(!e){B5.warn(`navigator.locks unavailable — discard prevention via Web Lock disabled`);return}let t=new AbortController;this.lockController=t,e.request(V5,{mode:`exclusive`,signal:t.signal},()=>new Promise(e=>{if(t.signal.aborted){e();return}let n=()=>{t.signal.removeEventListener(`abort`,n),e()};t.signal.addEventListener(`abort`,n,{once:!0})})).catch(e=>{e?.name!==`AbortError`&&B5.warn(`Web Lock request rejected`,{error:e instanceof Error?e.message:String(e)})})}catch(e){B5.warn(`Failed to acquire Web Lock`,{error:e instanceof Error?e.message:String(e)})}}releaseWebLock(){try{this.lockController?.abort()}catch{}this.lockController=null}installBeforeUnload(){try{let e=this.options.windowRef??(typeof window<`u`?window:null);if(!e)return;let t=()=>{};e.addEventListener(`beforeunload`,t),this.beforeUnloadHandler=t}catch{}}removeBeforeUnload(){try{let e=this.options.windowRef??(typeof window<`u`?window:null);e&&this.beforeUnloadHandler&&e.removeEventListener(`beforeunload`,this.beforeUnloadHandler)}catch{}this.beforeUnloadHandler=null}};function U5(e,t){if(t)return`extension`;try{return K5(new URL(e))?`electron-overlay`:`standalone`}catch{return`standalone`}}function W5(e,t){return e===`electron-overlay`||e===`standalone`&&t}function G5(e){try{let t=new URL(e).searchParams.get(`tab`);return t&&Wo(t)?t:Ho}catch{return Ho}}function K5(e){return e.pathname===`/electron`||e.pathname===`/electron/`||e.searchParams.get(`runtime`)===`electron-overlay`}function q5(e){let t=new URL(e);return`${t.protocol===`https:`?`wss:`:`ws:`}//${t.host}/licks-ws`}function J5(e,t){return`${new URL(e).origin}/webhooks/${t}`}function Y5(e,t){return`${e.replace(/\/+$/,``)}/${t.replace(/^\/+/,``)}`}function X5(e){return typeof e==`object`&&!!e&&`type`in e&&e.type===`slicc-electron-overlay:set-tab`}var Z5=[`/shared/sprinkles`];async function Q5(e){let t=new Map;for(let n of Z5)await e.exists(n)&&await $5(e,n,t);return await $5(e,`/`,t),t}async function $5(e,t,n){for await(let r of e.walk(t)){if(!r.endsWith(`.shtml`))continue;let t=e7(r);if(!n.has(t)){let i;try{i=await e.readFile(r,{encoding:`utf-8`})??``}catch{i=``}n.set(t,{name:t,path:r,title:t7(i,t),autoOpen:n7(i)})}}}function e7(e){let t=e.split(`/`).pop()??e;return t.endsWith(`.shtml`)?t.slice(0,-6):t}function t7(e,t){let n=e.match(/data-sprinkle-title=["']([^"']+)["']/);if(n)return n[1];let r=e.match(/<title>([^<]+)<\/title>/i);return r?r[1].trim():t}function n7(e){return/data-sprinkle-autoopen\b/.test(e)}var r7=o(`sprinkle-manager`),i7=`slicc-open-sprinkles`,a7=class{fs;bridge;callbacks;availableSprinkles=new Map;watcherUnsub;openSprinkles=new Map;constructor(e,t,n,r){this.fs=e,this.bridge=new m0(e,t,e=>this.close(e),r),this.callbacks=n}async restoreOpenSprinkles(){try{let e=localStorage.getItem(i7);if(!e){for(let e of this.availableSprinkles.values())if(e.autoOpen)try{await this.open(e.name)}catch{r7.warn(`Failed to auto-open sprinkle`,{name:e.name})}return}let t=JSON.parse(e);for(let e of t)try{await this.open(e)}catch{r7.warn(`Failed to restore sprinkle`,{name:e})}}catch{}}persistOpenSprinkles(){try{localStorage.setItem(i7,JSON.stringify([...this.openSprinkles.keys()]))}catch{}}async openNewAutoOpenSprinkles(){await this.refresh();for(let e of this.availableSprinkles.values())if(e.autoOpen&&!this.openSprinkles.has(e.name))try{await this.open(e.name),r7.info(`Auto-opened new sprinkle after install`,{name:e.name})}catch{r7.warn(`Failed to auto-open new sprinkle`,{name:e.name})}}async refresh(){this.availableSprinkles=await Q5(this.fs),r7.info(`Discovered sprinkles`,{count:this.availableSprinkles.size})}async open(e,t){if(this.openSprinkles.has(e)){r7.info(`Sprinkle already open`,{name:e});return}let n=this.availableSprinkles.get(e);if(n||=(await this.refresh(),this.availableSprinkles.get(e)),!n)throw Error(`Sprinkle not found: ${e}`);let r=await this.fs.readFile(n.path,{encoding:`utf-8`});if(r==null)throw Error(`Failed to read sprinkle content: ${n.path} (file may be corrupted or missing)`);let i=typeof r==`string`?r:new TextDecoder(`utf-8`).decode(r),a=document.createElement(`div`);a.className=`sprinkle-panel`,a.style.cssText=`width: 100%; height: 100%; display: flex; flex-direction: column; overflow: hidden;`,a.dataset.sprinkle=e,this.openSprinkles.set(e,{renderer:null,container:a}),this.callbacks.addSprinkle(e,n.title,a,t);let o=new Xr(a,this.bridge.createAPI(e));await o.render(i,e),this.openSprinkles.get(e).renderer=o,this.persistOpenSprinkles(),W3(e),r7.info(`Sprinkle opened`,{name:e,title:n.title})}close(e){let t=this.openSprinkles.get(e);t&&(t.renderer?.dispose(),t.container.remove(),this.bridge.removeSprinkle(e),this.openSprinkles.delete(e),this.callbacks.removeSprinkle(e),this.persistOpenSprinkles(),r7.info(`Sprinkle closed`,{name:e}))}available(){return Array.from(this.availableSprinkles.values())}opened(){return Array.from(this.openSprinkles.keys())}setupWatcher(e){this.watcherUnsub=e.watch(`/workspace`,e=>e.endsWith(`.shtml`),()=>void this.refresh())}dispose(){this.watcherUnsub?.()}sendToSprinkle(e,t){let n=this.openSprinkles.get(e);if(!n){r7.warn(`Cannot send to closed sprinkle`,{name:e});return}this.bridge.pushUpdate(e,t),n.renderer.pushUpdate(t)}};async function o7(e,t,n){let r=[],i=[];for(let{path:a,handle:o}of e){let e=typeof o?.name==`string`?o.name:``;if(!o||!(`queryPermission`in o)){i.push({path:a,dirName:e});continue}let s;try{s=await o.queryPermission({mode:`readwrite`})}catch(t){n?.warn?.(`queryPermission threw on persisted handle`,{path:a,error:t instanceof Error?t.message:String(t)}),i.push({path:a,dirName:e});continue}if(s!==`granted`){i.push({path:a,dirName:e});continue}try{await t.mount(a,o),n?.info?.(`Restored mount from previous session`,{path:a,name:e}),r.push({path:a,dirName:e})}catch(t){n?.warn?.(`Failed to re-mount persisted handle`,{path:a,error:t instanceof Error?t.message:String(t)}),i.push({path:a,dirName:e})}}return{restored:r,needsRecovery:i}}function s7(e){return`'${e.replace(/'/g,`'\\''`)}'`}function c7(e){let t=e.replace(/\r\n|[\r\n]/g,` `),n=t.match(/`+/g),r=n?Math.max(...n.map(e=>e.length))+1:1,i="`".repeat(r);return`${i}${t.startsWith("`")||t.endsWith("`")?` ${t} `:t}${i}`}function l7(e){if(!Array.isArray(e)||e.length===0)return null;let t=e.map(({path:e,dirName:t})=>{let n=t?` (previously mounted from ${c7(t)})`:``;return`- ${c7(e)}${n}`}),n=e.map(({path:e})=>` mount ${s7(e)}`),r=e.length===1?`mount point`:`mount points`,i=e.length===1?`it`:`them`;return[`[Session Reload] Mount recovery required for ${e.length} ${r}.`,``,`The page was reloaded and the following ${r} lost filesystem permission. The browser cannot restore access without a fresh user gesture, so ${i} cannot be used until the user re-authorizes:`,``,...t,``,`Please tell the user what happened and ask whether they want to re-mount. If yes, run the corresponding command(s) so the folder picker opens and they can re-select the same directory:`,``,...n,``,"If the user no longer needs a mount, run `mount unmount <path>` (with the path shell-quoted the same way) to clear the stale entry instead."].join(`
15835
+ `)}var $=o(`main`),u7=`slicc-pending-mount`,d7=`pendingMount`;function f7(){try{let e=new URLSearchParams(window.location.search).get(`ui-fixture`);return e===null?!1:e===``||e===`1`||e.toLowerCase()===`true`}catch{return!1}}async function p7(e){let[{createChatFixture:t,FIXTURE_SESSION_ID:n,FIXTURE_SCOOP_NAME:r}]=await Promise.all([s(()=>import(`./chat-fixture-BWvups7M.js`),[])]);await e.switchToContext(n,!0,r),e.loadMessages(t()),$.info(`Loaded UI fixture session for design iteration`)}async function m7(e){let t=await new Promise((e,t)=>{let n=indexedDB.open(u7,1);n.onupgradeneeded=()=>n.result.createObjectStore(`handles`),n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error)}),n=t.transaction(`handles`,`readwrite`);n.objectStore(`handles`).put(e,d7),await new Promise(e=>n.oncomplete=()=>e()),t.close()}async function h7(e){let t;try{t=await new Promise((e,t)=>{let n=indexedDB.open(u7,1);n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error)})}catch{return}let n=t.transaction(`handles`,`readwrite`),r=await new Promise(e=>{let t=n.objectStore(`handles`).get(d7);t.onsuccess=()=>e(t.result),t.onerror=()=>e(void 0)});if(r){n.objectStore(`handles`).delete(d7),await new Promise(e=>n.oncomplete=()=>e());let t=`/mnt/${r.name}`;await e.mount(t,r),$.info(`Mounted folder from welcome onboarding`,{name:r.name,path:t})}t.close()}function g7(){let e=document.createElement(`div`);e.className=`skill-drop-overlay`;let t=document.createElement(`div`);t.className=`skill-drop-overlay__card`;let n=document.createElement(`div`);n.className=`skill-drop-overlay__title`,t.appendChild(n);let r=document.createElement(`div`);return r.className=`skill-drop-overlay__desc`,t.appendChild(r),e.appendChild(t),document.body.appendChild(e),{show(t,i){n.textContent=t,r.textContent=i,e.classList.add(`skill-drop-overlay--visible`)},hide(){e.classList.remove(`skill-drop-overlay--visible`)}}}function _7(){let e=document.createElement(`div`);return e.className=`skill-drop-toast-container`,document.body.appendChild(e),(t,n)=>{let r=document.createElement(`div`);r.className=`skill-drop-toast skill-drop-toast--${n}`,r.textContent=t,e.appendChild(r),requestAnimationFrame(()=>r.classList.add(`skill-drop-toast--visible`)),window.setTimeout(()=>{r.classList.remove(`skill-drop-toast--visible`),window.setTimeout(()=>r.remove(),180)},4200)}}function v7(e,t,n){let r=g7(),i=0,a=!1,o=()=>{i=0,a||r.hide()};window.addEventListener(`dragenter`,e=>{Zs(e.dataTransfer)&&(e.preventDefault(),i+=1,a||r.show(`Drop .skill to install`,`Unpack into /workspace/skills/{name}.`))}),window.addEventListener(`dragover`,e=>{Zs(e.dataTransfer)&&(e.preventDefault(),e.dataTransfer&&(e.dataTransfer.dropEffect=`copy`),a||r.show(`Drop .skill to install`,`Unpack into /workspace/skills/{name}.`))}),window.addEventListener(`dragleave`,()=>{i!==0&&(i=Math.max(0,i-1),i===0&&!a&&r.hide())}),window.addEventListener(`dragend`,o),window.addEventListener(`blur`,o),window.addEventListener(`drop`,async s=>{let c=Qs(s.dataTransfer);if(!c){o();return}if(s.preventDefault(),i=0,a){r.hide(),t(`Another .skill installation is already in progress.`,`error`);return}a=!0,r.show(`Installing skill…`,c.name);try{let r=await oe(e,c);await n(),t(`Installed "${r.skillName}" to ${r.destinationPath} (${r.fileCount} files). Run "skill install ${r.skillName}" to apply it.`,`success`)}catch(e){t(`Failed to install dropped skill: ${e instanceof Error?e.message:String(e)}`,`error`)}finally{a=!1,r.hide()}})}async function y7(e){let{OffscreenClient:t}=await s(async()=>{let{OffscreenClient:e}=await import(`./offscreen-client-DJYi05-D.js`);return{OffscreenClient:e}},__vite__mapDeps([18,13])),{VirtualFS:n}=await s(async()=>{let{VirtualFS:e}=await Promise.resolve().then(()=>Js);return{VirtualFS:e}},void 0),{publishAgentBridgeProxy:r}=await s(async()=>{let{publishAgentBridgeProxy:e}=await Promise.resolve().then(()=>W8);return{publishAgentBridgeProxy:e}},void 0),i=new Yo(e,!0);window.__slicc_debug_tabs=e=>i.setDebugTabs(e),await i.panels.chat.initSession(`session-cone`),r();let a=null,o=await n.create({dbName:`slicc-fs`});i.panels.fileBrowser.setFs(o),$.info(`File browser wired to shared VFS (local IndexedDB)`);let c=new BroadcastChannel(`preview-vfs`);c.onmessage=e=>{if(e.data?.type!==`preview-vfs-read`)return;let{id:t,path:n,asText:r}=e.data;(async()=>{try{let e=r?`utf-8`:`binary`,i=await o.readFile(n,{encoding:e});c.postMessage({type:`preview-vfs-response`,id:t,content:i})}catch(e){let r=e instanceof Error?e.message:String(e);r.includes(`ENOENT`)||$.error(`Preview VFS read failed`,{path:n,error:r}),c.postMessage({type:`preview-vfs-response`,id:t,error:r})}})()},v7(o,_7(),async()=>{await i.panels.fileBrowser.refresh()});try{let{WasmShell:e}=await s(async()=>{let{WasmShell:e}=await Promise.resolve().then(()=>t6);return{WasmShell:e}},void 0),{PanelCdpProxy:t,BrowserAPI:n}=await s(async()=>{let{PanelCdpProxy:e,BrowserAPI:t}=await Promise.resolve().then(()=>Dc);return{PanelCdpProxy:e,BrowserAPI:t}},void 0),{fetchSecretEnvVars:r}=await s(async()=>{let{fetchSecretEnvVars:e}=await Promise.resolve().then(()=>o8);return{fetchSecretEnvVars:e}},void 0),a=new t;await a.connect();let c=new n(a),l=await r(),u=new e({fs:o,browserAPI:c,env:Object.keys(l).length>0?l:void 0});await i.panels.terminal.mountShell(u),$.info(`Terminal mounted with shared VFS and BrowserAPI (CDP proxy)`)}catch(e){$.warn(`Failed to mount shell to terminal`,e)}{let{registerSessionCostsProvider:e}=await s(async()=>{let{registerSessionCostsProvider:e}=await Promise.resolve().then(()=>G2);return{registerSessionCostsProvider:e}},void 0);e(()=>new Promise(e=>{chrome.runtime.sendMessage({source:`panel`,payload:{type:`get-session-costs`}},t=>{if(chrome.runtime.lastError||!t?.ok){e([]);return}e(t.costs??[])})}))}let l,u=new Set,d=async e=>{a=e,l.selectedScoopJid=e.jid,i.panels.memory.setSelectedScoop(e.jid),i.setScoopSwitcherSelected?.(e.jid),i.panels.scoops.setSelectedJid(e.jid);let t=e.isCone?`session-cone`:`session-${e.folder}`,n=e.isCone?void 0:e.name;await i.panels.chat.switchToContext(t,!e.isCone,n),l.isProcessing(e.jid)&&i.panels.chat.setProcessing(!0)};l=new t({onStatusChange:(e,t)=>{i.panels.scoops.updateScoopStatus(e,t),i.updateScoopSwitcherStatus?.(e,t),a?.jid===e&&(i.setAgentProcessing(t===`processing`),t===`processing`?i.panels.chat.setProcessing(!0):t===`ready`&&i.panels.chat.setProcessing(!1))},onScoopCreated:e=>{i.panels.scoops.refreshScoops(),i.refreshScoopSwitcher?.(),a||(a=e,l.selectedScoopJid=e.jid,i.panels.memory.setSelectedScoop(e.jid))},onScoopListUpdate:()=>{let e=new Set(l.getScoops().map(e=>e.folder));for(let t of u)e.has(t)||i.panels.chat.deleteSessionById(`session-${t}`);if(u=e,i.panels.scoops.refreshScoops(),i.refreshScoopSwitcher?.(),!a){let e=l.getScoops().find(e=>e.isCone);e&&(a=e,l.selectedScoopJid=e.jid,i.panels.memory.setSelectedScoop(e.jid))}},onIncomingMessage:(e,t)=>{if(wa(t.channel)){let n=new Date(t.timestamp).getTime(),r=t.channel;if(a?.jid===e)i.panels.chat.addLickMessage(t.id,t.content,r,n);else{let a=l.getScoops().find(t=>t.jid===e),o=a?.isCone?`session-cone`:a?`session-${a.folder}`:`session-${e}`;i.panels.chat.persistLickToSession(o,{id:t.id,content:t.content,channel:r,timestamp:n})}return}if(a?.jid===e){let e=t.channel===`delegation`?`**[Instructions from sliccy]**\n\n${t.content}`:t.content;i.panels.chat.addUserMessage(e)}},onReady:async()=>{try{$.info(`Offscreen engine ready, scoop count:`,l.getScoops().length),window.localStorage.getItem(`slicc.trayJoinUrl`)&&chrome.runtime.sendMessage({source:`panel`,payload:{type:`refresh-tray-runtime`}}).catch(()=>{});let e=a??l.getScoops().find(e=>e.isCone)??l.getScoops()[0];e&&(a=e,l.selectedScoopJid=e.jid,await d(e))}catch(e){$.error(`Failed to initialize on ready`,{error:e instanceof Error?e.message:String(e)})}}}),l.setLocalFS(o);let f=l.createAgentHandle();i.panels.chat.setAgent(f),i.panels.scoops.setOrchestrator(l),i.panels.memory.setOrchestrator(l),i.setScoopSwitcherOrchestrator?.(l),i.onScoopSelect=d,i.onModelChange=e=>{localStorage.setItem(`selected-model`,e),l.updateModel()},i.onClearChat=async()=>{let e=l.getScoops();for(let t of e){let e=t.isCone?`session-cone`:`session-${t.folder}`;await i.panels.chat.deleteSessionById(e)}l.clearAllMessages()},i.onClearFilesystem=async()=>{l.clearFilesystem()},i.panels.chat.onInlineSprinkleLick=(e,t)=>{l.sendSprinkleLick(`inline`,{action:e,data:t})};let p=new a7(o,async e=>{if(e.type===`sprinkle`){if(e.sprinkleName===`welcome`){let t=e.body,n=t?.action;(n===`onboarding-complete`||n===`shortcut-migrate`)&&o.writeFile(`/shared/.welcomed`,`1`).catch(e=>$.warn(`Failed to persist welcome completion marker`,e)),n===`shortcut-migrate`&&p.close(`welcome`),n===`onboarding-complete`&&t?.data?.mountWorkspace&&h7(o).catch(e=>$.warn(`Failed to mount workspace from onboarding`,e))}if(e.sprinkleName===`welcome`&&e.body?.action===`request-mount`){try{let e=window;if(!e.showDirectoryPicker)throw Error(`showDirectoryPicker not supported`);let t=await e.showDirectoryPicker({mode:`readwrite`});await m7(t),p.sendToSprinkle(`welcome`,{action:`mount-complete`,dirName:t.name})}catch(e){e.name!==`AbortError`&&$.warn(`Mount picker failed`,e),p.sendToSprinkle(`welcome`,{action:`mount-cancelled`})}return}l.sendSprinkleLick(e.sprinkleName,e.body,e.targetScoop)}},{addSprinkle:(e,t,n,r)=>i.addSprinkle(e,t,n,r),removeSprinkle:e=>i.removeSprinkle(e)},()=>{let e=l.getScoops().find(e=>e.isCone);e&&l.stopScoop(e.jid)});if(window.__slicc_sprinkleManager=p,window.__slicc_reloadSkills=()=>(chrome.runtime.sendMessage({source:`panel`,payload:{type:`reload-skills`}}),Promise.resolve()),l.setSprinkleOpHandler(e=>{let{id:t,op:n,name:r,data:i}=e;console.log(`[main-ext] sprinkle-op handler called`,{id:t,op:n,name:r}),(async()=>{try{let e;switch(n){case`list`:await p.refresh(),e=p.available();break;case`opened`:e=p.opened();break;case`refresh`:await p.refresh(),e=p.available().length;break;case`open`:await p.open(r),e=!0;break;case`close`:p.close(r),e=!0;break;case`send`:p.sendToSprinkle(r,i),e=!0;break;case`openNewAutoOpen`:await p.openNewAutoOpenSprinkles(),e=!0;break}console.log(`[main-ext] sprinkle-op response sending`,{id:t,op:n,result:typeof e}),chrome.runtime.sendMessage({source:`panel`,payload:{type:`sprinkle-op-response`,id:t,result:e}}).catch(()=>{})}catch(e){chrome.runtime.sendMessage({source:`panel`,payload:{type:`sprinkle-op-response`,id:t,error:e instanceof Error?e.message:String(e)}}).catch(()=>{})}})()}),await p.refresh(),i.onSprinkleClose=e=>p.close(e),i.getAvailableSprinkles=()=>{let e=new Set(p.opened());return p.available().filter(t=>!e.has(t.name)).map(e=>({name:e.name,title:e.title}))},i.onOpenSprinkle=(e,t)=>p.open(e,t),i.updateAddButtons(),await p.restoreOpenSprinkles(),!await o.exists(`/shared/.welcomed`)&&localStorage.getItem(`slicc-welcomed`)&&(await o.writeFile(`/shared/.welcomed`,`1`).catch(()=>{}),localStorage.removeItem(`slicc-welcomed`)),!await o.exists(`/shared/.welcomed`)&&!so(window.localStorage)&&p.available().some(e=>e.name===`welcome`))try{await p.open(`welcome`)}catch(e){$.warn(`Failed to open welcome sprinkle`,e)}$.info(`SprinkleManager initialized (extension mode)`),l.requestState(),$.info(`Extension UI connected to offscreen agent engine`),f7()&&await p7(i.panels.chat),V3().catch(()=>{})}function b7(){if(typeof chrome<`u`&&chrome?.runtime?.id)return;let e=new Blob([`
15836
15836
  let lastPong = Date.now();
15837
15837
  let frozen = false;
15838
15838
  setInterval(() => {
@@ -15852,7 +15852,7 @@ ${t}
15852
15852
  }
15853
15853
  }
15854
15854
  };
15855
- `],{type:`application/javascript`}),t=URL.createObjectURL(e),n=new Worker(t);URL.revokeObjectURL(t),n.onmessage=e=>{if(e.data.type===`ping`)n.postMessage({type:`pong`});else if(e.data.type===`freeze-detected`)console.error(`[freeze-watchdog] Main thread blocked for ${e.data.elapsed}ms — capturing trace on recovery`);else if(e.data.type===`freeze-recovered`){console.error(`[freeze-watchdog] Main thread recovered. Stack trace at recovery point:`),console.trace(`[freeze-watchdog] recovery stack`);let e=performance.getEntriesByType(`longtask`);e.length>0&&console.error(`[freeze-watchdog] Long tasks:`,e.map(e=>({duration:e.duration,startTime:e.startTime,name:e.name})))}},window.addEventListener(`beforeunload`,()=>{n.terminate()},{once:!0})}async function v7(){_7(),Gr(),rs();let e=document.getElementById(`app`);if(!e)throw Error(`#app element not found`);`serviceWorker`in navigator&&navigator.serviceWorker.register(`/preview-sw.js`,{scope:`/preview/`}).then(()=>$.info(`Preview SW registered`)).catch(e=>$.error(`Preview SW registration failed — preview feature will not work`,e)),S();let t=l(),n=so(window.localStorage);if(!t&&!n){let e=window.location.port===`5710`||window.location.port===`3000`;window.location.port===``&&window.location.pathname.includes(`/join/`)?await g({autoJoinUrl:window.location.origin+window.location.pathname}):!e&&window.location.port!==``?await g({preferTrayJoin:!0}):await g(),t=l()}let r=!t&&so(window.localStorage),i=typeof chrome<`u`&&!!chrome?.runtime?.id,a=B5(window.location.href,i);if(a===`extension`)return g7(e);let o=new Yo(e,a===`electron-overlay`);if(a===`electron-overlay`){let e=H5(window.location.href);o.setActiveTab(e);let t=document.createElement(`style`);t.id=`slicc-electron-overlay-runtime-style`,t.textContent=`
15855
+ `],{type:`application/javascript`}),t=URL.createObjectURL(e),n=new Worker(t);URL.revokeObjectURL(t),n.onmessage=e=>{if(e.data.type===`ping`)n.postMessage({type:`pong`});else if(e.data.type===`freeze-detected`)console.error(`[freeze-watchdog] Main thread blocked for ${e.data.elapsed}ms — capturing trace on recovery`);else if(e.data.type===`freeze-recovered`){console.error(`[freeze-watchdog] Main thread recovered. Stack trace at recovery point:`),console.trace(`[freeze-watchdog] recovery stack`);let e=performance.getEntriesByType(`longtask`);e.length>0&&console.error(`[freeze-watchdog] Long tasks:`,e.map(e=>({duration:e.duration,startTime:e.startTime,name:e.name})))}},window.addEventListener(`beforeunload`,()=>{n.terminate()},{once:!0})}async function x7(){b7(),Gr(),rs();let e=document.getElementById(`app`);if(!e)throw Error(`#app element not found`);`serviceWorker`in navigator&&navigator.serviceWorker.register(`/preview-sw.js`,{scope:`/preview/`}).then(()=>$.info(`Preview SW registered`)).catch(e=>$.error(`Preview SW registration failed — preview feature will not work`,e)),S();let t=l(),n=so(window.localStorage);if(!t&&!n){let e=window.location.port===`5710`||window.location.port===`3000`;window.location.port===``&&window.location.pathname.includes(`/join/`)?await g({autoJoinUrl:window.location.origin+window.location.pathname}):!e&&window.location.port!==``?await g({preferTrayJoin:!0}):await g(),t=l()}let r=!t&&so(window.localStorage),i=typeof chrome<`u`&&!!chrome?.runtime?.id,a=U5(window.location.href,i);if(a===`extension`)return y7(e);let o=new Yo(e,a===`electron-overlay`);if(a===`electron-overlay`){let e=G5(window.location.href);o.setActiveTab(e);let t=document.createElement(`style`);t.id=`slicc-electron-overlay-runtime-style`,t.textContent=`
15856
15856
  #app > .tab-bar { display: none !important; }
15857
15857
  #app > .tab-content {
15858
15858
  height: calc(100vh - var(--s2-header-height));
@@ -15860,4 +15860,4 @@ ${t}
15860
15860
  #app > .tab-content > .tab-content__panel {
15861
15861
  height: 100%;
15862
15862
  }
15863
- `,document.head.appendChild(t),window.addEventListener(`message`,e=>{e.source===window.parent&&q5(e.data)&&o.setActiveTab(H5(`http://localhost/?tab=${e.data.tab??``}`))}),window.addEventListener(`keydown`,e=>{e.code===`Semicolon`&&(e.metaKey||e.ctrlKey)&&!e.shiftKey&&!e.altKey&&!e.repeat&&(e.preventDefault(),e.stopPropagation(),window.parent.postMessage({type:`slicc-electron-overlay:toggle`},`*`))},!0)}let c=m7();await o.panels.chat.initSession(`session-cone`),$.info(`Session initialized`);let u=new oc,d=new Set,f=e=>{$.debug(`Emit to UI`,{type:e.type,listenerCount:d.size});for(let t of d)try{t(e)}catch(t){$.error(`Listener error`,{eventType:e.type,error:t instanceof Error?t.message:String(t)})}},p=null,m=new Map,h=new Map;function _(){return Date.now().toString(36)+Math.random().toString(36).slice(2,8)}function v(e){let t=h.get(e);return t||(t=[],h.set(e,t)),t}function y(e,t){let n=v(e),r=m.get(e);if(r){let e=n.find(e=>e.id===r);if(e)return e}r=`scoop-${e}-${_()}`,m.set(e,r);let i=b.getScoops().find(t=>t.jid===e),a=i?.isCone?`cone`:i?.name??`unknown`,o={id:r,role:`assistant`,content:``,timestamp:Date.now(),toolCalls:[],isStreaming:!0,source:a,channel:t};return n.push(o),p?.jid===e&&f({type:`message_start`,messageId:r}),o}let b=new E8(o.getIframeContainer(),{onResponse:(e,t,n)=>{let r=y(e);n?r.content+=t:(r.content=t,r.isStreaming=!1),p?.jid===e&&(f({type:`content_delta`,messageId:r.id,text:t}),n||f({type:`content_done`,messageId:r.id}))},onResponseDone:e=>{let t=v(e),n=m.get(e);if(n){let r=t.find(e=>e.id===n);r&&(r.isStreaming=!1),p?.jid===e&&f({type:`content_done`,messageId:n}),m.delete(e)}},onSendMessage:(e,t)=>{$.debug(`Send message requested`,{targetJid:e,textLength:t.length});let n=`msg-${_()}`,r={id:n,chatJid:e,senderId:`assistant`,senderName:`sliccy`,content:t,timestamp:new Date().toISOString(),fromAssistant:!0,channel:`web`};b.handleMessage(r),v(e).push({id:n,role:`assistant`,content:t,timestamp:Date.now()}),p?.jid===e&&(f({type:`message_start`,messageId:n}),f({type:`content_delta`,messageId:n,text:t}),f({type:`content_done`,messageId:n}))},onStatusChange:(e,t)=>{if(o.panels.scoops.updateScoopStatus(e,t),o.updateScoopSwitcherStatus?.(e,t),p?.jid===e){if(o.setAgentProcessing(t===`processing`),t===`processing`)o.panels.chat.setProcessing(!0);else if(t===`ready`){o.panels.chat.setProcessing(!1);let t=m.get(e)??`done-${e}-${_()}`;m.delete(e),f({type:`turn_end`,messageId:t})}}},onError:(e,t)=>{$.error(`Scoop error`,{scoopJid:e,error:t}),p?.jid===e&&f({type:`error`,error:t})},getBrowserAPI:()=>u,onToolStart:(e,t,n)=>{if(new Set([`send_message`,`list_scoops`,`list_tasks`]).has(t))return;let r=y(e);r.toolCalls||=[],r.toolCalls.push({id:_(),name:t,input:n}),p?.jid===e&&f({type:`tool_use_start`,messageId:r.id,toolName:t,toolInput:n})},onToolEnd:(e,t,n,r)=>{if(new Set([`send_message`,`list_scoops`,`list_tasks`]).has(t))return;let i=v(e),a=m.get(e);if(a){let e=i.find(e=>e.id===a);if(e?.toolCalls){let i=[...e.toolCalls].reverse().find(e=>e.name===t&&e.result===void 0);i&&(i.result=n,i.isError=r)}}p?.jid===e&&a&&f({type:`tool_result`,messageId:a,toolName:t,result:n,isError:r})},onToolUI:(e,t,n,r)=>{let i=m.get(e);i?f({type:`tool_ui`,messageId:i,toolName:t,requestId:n,html:r}):$.warn(`Cannot emit tool_ui - no message ID for scoop`,{scoopJid:e,requestId:n})},onToolUIDone:(e,t)=>{let n=m.get(e);n&&f({type:`tool_ui_done`,messageId:n,requestId:t})},onIncomingMessage:(e,t)=>{if(wa(t.channel)){let n=new Date(t.timestamp).getTime(),r=t.channel;if(v(e).push({id:t.id,role:`user`,content:t.content,timestamp:n,source:`lick`,channel:r}),p?.jid===e)o.panels.chat.addLickMessage(t.id,t.content,r,n);else{let i=b.getScoops().find(t=>t.jid===e),a=i?.isCone?`session-cone`:i?`session-${i.folder}`:`session-${e}`;o.panels.chat.persistLickToSession(a,{id:t.id,content:t.content,channel:r,timestamp:n})}return}let n={id:t.id,role:`user`,content:t.channel===`delegation`?`**[Instructions from sliccy]**\n\n${t.content}`:t.content,timestamp:new Date(t.timestamp).getTime(),source:t.channel===`delegation`?`delegation`:void 0,channel:t.channel};v(e).push(n),p?.jid===e&&(f({type:`message_start`,messageId:t.id}),f({type:`content_delta`,messageId:t.id,text:n.content}),f({type:`content_done`,messageId:t.id}))}});await b.init(),o.panels.scoops.setOrchestrator(b),o.panels.memory.setOrchestrator(b),o.setScoopSwitcherOrchestrator?.(b);{let e=b.getSharedFS();e?K8(b,e,b.getSessionStore()):$.warn(`AgentBridge not published — orchestrator.getSharedFS() returned null`)}let x=b.getSharedFS();if(x){o.panels.fileBrowser.setFs(x),$.info(`File browser wired to shared VFS`);let e=new BroadcastChannel(`preview-vfs`);e.onmessage=t=>{if(t.data?.type!==`preview-vfs-read`)return;let{id:n,path:r,asText:i}=t.data;(async()=>{try{let t=i?`utf-8`:`binary`,a=await x.readFile(r,{encoding:t});e.postMessage({type:`preview-vfs-response`,id:n,content:a})}catch(t){let i=t instanceof Error?t.message:String(t);i.includes(`ENOENT`)||$.error(`Preview VFS read failed`,{path:r,error:i}),e.postMessage({type:`preview-vfs-response`,id:n,error:i})}})()},h7(x,(e,t)=>{t===`error`?$.warn(`Dropped skill install failed`,{message:e}):$.info(`Dropped skill installed`,{message:e}),c(e,t)},async()=>{await o.panels.fileBrowser.refresh()});try{let{WasmShell:e}=await s(async()=>{let{WasmShell:e}=await Promise.resolve().then(()=>Q3);return{WasmShell:e}},void 0),{fetchSecretEnvVars:t}=await s(async()=>{let{fetchSecretEnvVars:e}=await Promise.resolve().then(()=>r8);return{fetchSecretEnvVars:e}},void 0),n=await t(),r=new e({fs:x,browserAPI:u,env:Object.keys(n).length>0?n:void 0});await o.panels.terminal.mountShell(r),$.info(`Terminal mounted with shared VFS`);try{let{BshWatchdog:e}=await s(async()=>{let{BshWatchdog:e}=await import(`./bsh-watchdog-DYfdvOrR.js`);return{BshWatchdog:e}},__vite__mapDeps([19,13])),t=new e({browserAPI:u,scriptCatalog:r.getScriptCatalog(),fs:x});t.start(),window.addEventListener(`beforeunload`,()=>t.stop(),{once:!0}),$.info(`BSH navigation watchdog started`)}catch(e){$.warn(`Failed to start BSH watchdog`,e)}}catch(e){$.warn(`Failed to mount shell to terminal`,e)}}let C=b.getScoops(),w=C.some(e=>e.isCone);if(r)$.info(`Skipping local cone bootstrap while joining a tray without a configured provider`);else if(!w)p=await o.panels.scoops.createCone(),$.info(`Created cone`);else{let e=new URLSearchParams(window.location.search).get(`scoop`);if(e){let t=C.find(t=>t.folder===e);t?(p=t,$.info(`Restored scoop from URL`,{folder:e})):p=C.find(e=>e.isCone)??C[0]}else p=C.find(e=>e.isCone)??C[0]}p&&o.panels.memory.setSelectedScoop(p.jid);let T=null,E={sendMessage(e,t){if(!p){f({type:`error`,error:`No scoop selected`});return}let n={id:t??`msg-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,chatJid:p.jid,senderId:`user`,senderName:`User`,content:e,timestamp:new Date().toISOString(),fromAssistant:!1,channel:`web`};v(p.jid).push({id:n.id,role:`user`,content:e,timestamp:Date.now()}),T?.broadcastUserMessage(e,n.id),b.handleMessage(n),b.createScoopTab(p.jid)},onEvent(e){return d.add(e),()=>d.delete(e)},stop(){p&&(b.stopScoop(p.jid),b.clearQueuedMessages(p.jid).catch(e=>{$.error(`Failed to clear queued messages on stop`,{error:e instanceof Error?e.message:String(e)})}))}};o.panels.chat.setAgent(E),o.panels.chat.setDeleteQueuedMessageCallback(e=>{if(p){b.deleteQueuedMessage(p.jid,e).catch(t=>{$.error(`Failed to delete queued message`,{messageId:e,error:t instanceof Error?t.message:String(t)})});let t=h.get(p.jid);if(t){let n=t.findIndex(t=>t.id===e);n!==-1&&t.splice(n,1)}}}),$.info(`Cone agent handle wired to chat UI`);let{getLickManager:D}=await s(async()=>{let{getLickManager:e}=await Promise.resolve().then(()=>m8);return{getLickManager:e}},void 0),O=D();await O.init(),b.setLickManager(O);let ee=e=>{let t=e.type===`webhook`,n=e.type===`sprinkle`,r=e.type===`fswatch`,i=e.type===`session-reload`,a=e.type===`navigate`,s=t?e.webhookName:n?e.sprinkleName:r?e.fswatchName:i?`session-reload`:a?e.navigateUrl:e.cronName,c=t?e.webhookId:n?e.sprinkleName:r?e.fswatchId:i?`session-reload`:a?e.navigateUrl:e.cronId,l=e.type;if($.debug(`Lick event`,{type:e.type,name:s,targetScoop:e.targetScoop}),n&&e.sprinkleName===`welcome`){let t=e.body,n=t?.action;(n===`onboarding-complete`||n===`shortcut-migrate`)&&x?.writeFile(`/shared/.welcomed`,`1`).catch(e=>$.warn(`Failed to persist welcome marker`,e)),n===`shortcut-migrate`&&ne?.close(`welcome`),n===`onboarding-complete`&&t?.data?.mountWorkspace&&x&&f7(x).catch(e=>$.warn(`Failed to mount workspace from onboarding`,e))}if(n&&e.sprinkleName===`welcome`&&e.body?.action===`request-mount`){(async()=>{try{let e=window;if(!e.showDirectoryPicker)throw Error(`showDirectoryPicker not supported`);let t=await e.showDirectoryPicker({mode:`readwrite`});await d7(t),ne?.sendToSprinkle(`welcome`,{action:`mount-complete`,dirName:t.name})}catch(e){e.name!==`AbortError`&&$.warn(`Mount picker failed`,e),ne?.sendToSprinkle(`welcome`,{action:`mount-cancelled`})}})();return}let u=b.getScoops(),d;if(d=e.targetScoop?u.find(t=>t.name===e.targetScoop||t.folder===e.targetScoop||t.folder===`${e.targetScoop}-scoop`):u.find(e=>e.isCone),d){let u=`${l}-${c}-${Date.now()}`,f=t?`Webhook Event`:n?`Sprinkle Event`:r?`File Watch Event`:i?`Session Reload`:a?`Navigate Event`:`Cron Event`,m=null;if(i){let t=e.body;if(t?.reason===`mount-recovery`&&(m=o7(t.mounts??[]),m===null)){$.debug(`Dropping session-reload lick with empty mount-recovery list`);return}}m===null&&(m=`[${f}: ${s}]\n\`\`\`json\n${JSON.stringify(e.body,null,2)}\n\`\`\``);let h={id:u,chatJid:d.jid,senderId:l,senderName:`${l}:${s}`,content:m,timestamp:e.timestamp,fromAssistant:!1,channel:l},g=Date.now();if(v(d.jid).push({id:u,role:`user`,content:m,timestamp:g,source:`lick`,channel:l}),p?.jid===d.jid)o.panels.chat.addLickMessage(u,m,l,g);else{let e=d.isCone?`session-cone`:`session-${d.folder}`;o.panels.chat.persistLickToSession(e,{id:u,content:m,channel:l,timestamp:g})}$.info(`Routing lick to scoop`,{type:l,name:s,scoopJid:d.jid}),b.handleMessage(h)}else $.warn(`Lick target scoop not found`,{targetScoop:e.targetScoop})};O.setEventHandler(ee);let te=new hc(u.getTransport(),e=>{O.emitEvent({type:`navigate`,navigateUrl:e.url,targetScoop:void 0,timestamp:new Date().toISOString(),body:{url:e.url,sliccHeader:e.sliccHeader,title:e.title}})});(async()=>{try{await u.connect(),await te.start(),$.info(`Navigation watcher started`)}catch(e){$.warn(`Failed to start navigation watcher`,{error:e instanceof Error?e.message:String(e)})}})(),x&&Ls().then(async e=>{if(e.length===0)return;let{needsRecovery:t}=await r7(e,x,$);t.length!==0&&ee({type:`session-reload`,targetScoop:void 0,timestamp:new Date().toISOString(),body:{reason:`mount-recovery`,mounts:t}})}).catch(e=>$.warn(`Failed to restore persisted mounts`,e)),o.panels.chat.onInlineSprinkleLick=(e,t)=>{ee({type:`sprinkle`,sprinkleName:`inline`,targetScoop:void 0,timestamp:new Date().toISOString(),body:{action:e,data:t}})};let ne=null;if(x){if(ne=new n7(x,ee,{addSprinkle:(e,t,n,r)=>o.addSprinkle(e,t,n,r),removeSprinkle:e=>o.removeSprinkle(e)},()=>{let e=b.getScoops().find(e=>e.isCone);e&&(b.stopScoop(e.jid),b.clearQueuedMessages(e.jid).catch(e=>{$.error(`Failed to clear queued messages on sprinkle stopCone`,{error:e instanceof Error?e.message:String(e)})}))}),window.__slicc_sprinkleManager=ne,window.__slicc_reloadSkills=()=>b.reloadAllSkills(),await ne.refresh(),o.onSprinkleClose=e=>ne.close(e),o.getAvailableSprinkles=()=>{let e=new Set(ne.opened());return ne.available().filter(t=>!e.has(t.name)).map(e=>({name:e.name,title:e.title}))},o.onOpenSprinkle=(e,t)=>ne.open(e,t),o.updateAddButtons(),!await x.exists(`/shared/.welcomed`)&&localStorage.getItem(`slicc-welcomed`)&&(await x.writeFile(`/shared/.welcomed`,`1`).catch(()=>{}),localStorage.removeItem(`slicc-welcomed`)),!await x.exists(`/shared/.welcomed`)&&!r&&ne.available().some(e=>e.name===`welcome`))try{await ne.open(`welcome`)}catch(e){$.warn(`Failed to open welcome sprinkle`,e)}await ne.restoreOpenSprinkles(),$.info(`SprinkleManager initialized`)}let k=()=>{let e=W5(window.location.href),t=new WebSocket(e);t.onopen=()=>{$.info(`Lick WebSocket connected`)},t.onmessage=async e=>{try{let n=JSON.parse(e.data);if(n.requestId){let e;try{switch(n.type){case`list_webhooks`:e={type:`response`,requestId:n.requestId,data:O.listWebhooks()};break;case`create_webhook`:{let t=await O.createWebhook(n.name||`default`,n.scoop,n.filter),r=S$().session,i=r?.webhookUrl?K5(r.webhookUrl,t.id):G5(window.location.href,t.id);e={type:`response`,requestId:n.requestId,data:{...t,url:i}};break}case`delete_webhook`:e=await O.deleteWebhook(n.id)?{type:`response`,requestId:n.requestId,data:{ok:!0}}:{type:`response`,requestId:n.requestId,data:{error:`Webhook not found`}};break;case`list_crontasks`:e={type:`response`,requestId:n.requestId,data:O.listCronTasks()};break;case`create_crontask`:{if(!n.name)throw Error(`name is required`);if(!n.cron)throw Error(`cron is required`);let t=await O.createCronTask(n.name,n.cron,n.scoop,n.filter);e={type:`response`,requestId:n.requestId,data:t};break}case`delete_crontask`:e=await O.deleteCronTask(n.id)?{type:`response`,requestId:n.requestId,data:{ok:!0}}:{type:`response`,requestId:n.requestId,data:{error:`Cron task not found`}};break;case`tray_status`:{let t=S$();e={type:`response`,requestId:n.requestId,data:{state:t.state,joinUrl:t.session?.joinUrl??null,workerBaseUrl:t.session?.workerBaseUrl??null,trayId:t.session?.trayId??null}};break}default:e={type:`response`,requestId:n.requestId,error:`Unknown request type: ${n.type}`}}}catch(t){e={type:`response`,requestId:n.requestId,error:t instanceof Error?t.message:String(t)}}t.send(JSON.stringify(e));return}if(n.type===`webhook_event`&&O.handleWebhookEvent(n.webhookId,n.headers,n.body),n.type===`navigate_event`){let e=typeof n.sliccHeader==`string`?n.sliccHeader:``,t=typeof n.url==`string`&&n.url.length>0?n.url:``;e&&t&&O.emitEvent({type:`navigate`,navigateUrl:t,targetScoop:void 0,timestamp:typeof n.timestamp==`string`?n.timestamp:new Date().toISOString(),body:{url:t,sliccHeader:e,title:typeof n.title==`string`?n.title:void 0}})}}catch(e){$.error(`Failed to process lick message`,{error:e instanceof Error?e.message:String(e)})}},t.onclose=()=>{$.warn(`Lick WebSocket disconnected, reconnecting in 3s...`),setTimeout(k,3e3)},t.onerror=e=>{$.error(`Lick WebSocket error`,{error:String(e)})}};k(),o.onModelChange=e=>{localStorage.setItem(`selected-model`,e),b.updateModel()};let re=new Set;o.onClearChat=async()=>{await b.clearAllMessages(),h.clear(),re.clear()},o.onClearFilesystem=async()=>{await b.resetFilesystem()};let ie=async e=>{$.info(`Scoop selected`,{jid:e.jid,name:e.name}),p=e,b.createScoopTab(e.jid),o.panels.memory.setSelectedScoop(e.jid),o.panels.scoops.setSelectedJid(e.jid);let t=e.isCone?`session-cone`:`session-${e.folder}`,n=h.get(e.jid),r=!re.has(e.jid),i=e.isCone?void 0:e.name;if(!r&&n&&n.length>0)await o.panels.chat.switchToContext(t,!e.isCone,i),o.panels.chat.loadMessages(n);else{if(await o.panels.chat.switchToContext(t,!e.isCone,i),o.panels.chat.getMessages().length===0){let t=await b.getMessagesForScoop(e.jid);for(let e of t){let t=e.channel===`delegation`;wa(e.channel)?o.panels.chat.addLickMessage(e.id,e.content,e.channel,new Date(e.timestamp).getTime()):t?o.panels.chat.addUserMessage(`**[Instructions from sliccy]**\n\n${e.content}`):e.fromAssistant?(f({type:`message_start`,messageId:e.id}),f({type:`content_delta`,messageId:e.id,text:e.content}),f({type:`content_done`,messageId:e.id})):o.panels.chat.addUserMessage(e.content)}}let n=o.panels.chat.getMessages(),r=new Set(n.map(e=>e.id)),a=v(e.jid),s=a.filter(e=>!r.has(e.id));a.length=0,a.push(...n,...s),s.length>0&&o.panels.chat.loadMessages(a)}e.isCone&&b.isProcessing(e.jid)&&o.panels.chat.setProcessing(!0),re.add(e.jid)};if(o.onScoopSelect=ie,p&&(b.createScoopTab(p.jid),await ie(p)),l7()&&await u7(o.panels.chat),a===`standalone`||a===`electron-overlay`){let e=await fo(),t=V5(a,e!==null)?no:null,n=await uo({locationHref:window.location.href,storage:window.localStorage,envBaseUrl:null,defaultWorkerBaseUrl:t,runtimeConfigFetcher:async()=>e}),r=null,i=null,s=null;j0(()=>T?(e,t)=>T.sendFsRequest(e,t):r?(e,t)=>r.sendFsRequest(e,t):null),uQ(()=>T?()=>T.getBestFollowerForTeleport():null),dQ(()=>T?()=>T.getConnectedFollowers():null);let c=e=>{s&&=(clearInterval(s),null),r?.close();let t=`follower-${e.bootstrapId}`,n=new I5(e.channel,{browserTransport:u.getTransport(),browserAPI:u,onSnapshot:e=>{o.panels.chat.loadMessages(e)},onUserMessage:e=>{o.panels.chat.addUserMessage(e)},onStatus:e=>{o.panels.chat.setProcessing(e===`processing`)},onTargetsChanged:()=>void i()});r=n,u.setTrayTargetProvider(n),o.panels.chat.setAgent(n),n.requestSnapshot();let i=async()=>{try{let e=await u.listPages();n.advertiseTargets(e.map(e=>({targetId:e.targetId,title:e.title,url:e.url})),t)}catch{}};s=setInterval(i,5e3),i(),$.info(`Follower sync wired to chat panel`,{trayId:e.trayId})},l=e=>{i?.cancel(),s&&=(clearInterval(s),null),r?.close(),r=null,i=u5({joinUrl:e,runtime:`slicc-standalone`,fetchImpl:A$()},{onConnected:e=>c(e),onReconnecting:e=>{$.info(`Follower reconnecting`,{attempt:e})},onGaveUp:e=>{$.warn(`Follower reconnect gave up`,{lastError:e})}})};if(window.addEventListener(`slicc:tray-join`,(e=>{l(e.detail.joinUrl)})),window.addEventListener(`beforeunload`,()=>{s&&clearInterval(s),r?.close(),i?.cancel()},{once:!0}),n?.joinUrl)l(n.joinUrl);else if(n?.workerBaseUrl){let e,t,r,i,a=new z5,s=()=>{t=new P5({browserTransport:u.getTransport(),browserAPI:u,getMessages:()=>o.panels.chat.getMessages(),getScoopJid:()=>p?.jid??`cone`,onFollowerMessage:(e,t)=>{o.panels.chat.addUserMessage(e),E.sendMessage(e,t)},onFollowerAbort:()=>{E.stop()},onFollowerCountChanged:e=>{e>0?a.activate():a.deactivate()}}),T=t,M$(()=>t.getConnectedFollowers()),u.setTrayTargetProvider(t),i&&clearInterval(i);let n=async()=>{try{let e=await u.listPages();t.setLocalTargets(e.map(e=>({targetId:e.targetId,title:e.title,url:e.url})))}catch{}};i=setInterval(n,5e3),n(),r=new c5({sendControlMessage:t=>e.sendControlMessage(t),onPeerConnected:(e,n)=>{$.info(`Tray follower data channel opened`,{controllerId:e.controllerId,bootstrapId:e.bootstrapId,attempt:e.attempt,runtime:e.runtime}),t.addFollower(e.bootstrapId,n,{runtime:e.runtime,connectedAt:e.connectedAt??void 0})}})};s(),d.add(e=>{t.broadcastEvent(e)}),e=new E$({workerBaseUrl:n.workerBaseUrl,runtime:`slicc-standalone`,fetchImpl:A$(),onControlMessage:e=>{if(e.type===`webhook.event`){O.handleWebhookEvent(e.webhookId,e.headers,e.body);return}r.handleControlMessage(e).catch(e=>{$.warn(`Tray leader bootstrap handling failed`,{error:e instanceof Error?e.message:String(e)})})},onReconnecting:(e,t)=>{$.info(`Leader tray reconnecting`,{attempt:e,lastError:t})},onReconnected:e=>{$.info(`Leader tray reconnected`,{trayId:e.trayId});let t=lo(window.location.href,e.workerBaseUrl,e.trayId);t!==window.location.href&&window.history.replaceState(window.history.state,``,t)},onReconnectGaveUp:(e,t)=>{$.warn(`Leader tray reconnect gave up`,{lastError:e,attempts:t})}}),F$(async()=>{t.stop(),r.stop(),e.stop(),await e.clearSession();let n=await e.start(),i=lo(window.location.href,n.workerBaseUrl,n.trayId);return i!==window.location.href&&window.history.replaceState(window.history.state,``,i),s(),S$()}),e.start().then(e=>{let t=lo(window.location.href,e.workerBaseUrl,e.trayId);t!==window.location.href&&window.history.replaceState(window.history.state,``,t)}).catch(e=>{$.warn(`Leader tray join failed`,{error:e instanceof Error?e.message:String(e)})}),window.addEventListener(`beforeunload`,()=>{clearInterval(i),t.stop(),r.stop(),e.stop(),a.deactivate()},{once:!0})}}$.info(`Orchestrator initialized — cone+scoops ready`,{scoopCount:b.getScoops().length}),R3().catch(()=>{})}v7().catch(e=>{$.error(`Fatal error`,e);let t=document.getElementById(`app`);if(t){let n=document.createElement(`div`);n.style.cssText=`padding: 2rem; text-align: center;`;let r=document.createElement(`h1`);r.style.color=`var(--s2-negative, #e34850)`,r.textContent=`Failed to start`;let i=document.createElement(`p`);i.style.color=`var(--s2-content-tertiary, #717171)`,i.textContent=e.message,n.appendChild(r),n.appendChild(i);let a=document.createElement(`button`);for(a.textContent=`Reset all data & reload`,a.style.cssText=`margin-top: 1rem; padding: 0.5rem 1.5rem; background: var(--s2-negative, #e34850); color: #fff; border: none; border-radius: 6px; cursor: pointer; font-size: 14px;`,a.addEventListener(`click`,async()=>{a.disabled=!0,a.textContent=`Resetting…`;let e=await indexedDB.databases();await Promise.all(e.map(e=>e.name?new Promise(t=>{let n=indexedDB.deleteDatabase(e.name);n.onsuccess=()=>t(),n.onerror=()=>t(),n.onblocked=()=>t()}):Promise.resolve())),location.reload()}),n.appendChild(a);t.firstChild;)t.removeChild(t.firstChild);t.appendChild(n)}});export{Ba as a,di as c,oo as i,ui as l,go as n,Va as o,so as r,Na as s,rK as t};
15863
+ `,document.head.appendChild(t),window.addEventListener(`message`,e=>{e.source===window.parent&&X5(e.data)&&o.setActiveTab(G5(`http://localhost/?tab=${e.data.tab??``}`))}),window.addEventListener(`keydown`,e=>{e.code===`Semicolon`&&(e.metaKey||e.ctrlKey)&&!e.shiftKey&&!e.altKey&&!e.repeat&&(e.preventDefault(),e.stopPropagation(),window.parent.postMessage({type:`slicc-electron-overlay:toggle`},`*`))},!0)}let c=_7();await o.panels.chat.initSession(`session-cone`),$.info(`Session initialized`);let u=new oc,d=new Set,f=e=>{$.debug(`Emit to UI`,{type:e.type,listenerCount:d.size});for(let t of d)try{t(e)}catch(t){$.error(`Listener error`,{eventType:e.type,error:t instanceof Error?t.message:String(t)})}},p=null,m=new Map,h=new Map;function _(){return Date.now().toString(36)+Math.random().toString(36).slice(2,8)}function v(e){let t=h.get(e);return t||(t=[],h.set(e,t)),t}function y(e,t){let n=v(e),r=m.get(e);if(r){let e=n.find(e=>e.id===r);if(e)return e}r=`scoop-${e}-${_()}`,m.set(e,r);let i=b.getScoops().find(t=>t.jid===e),a=i?.isCone?`cone`:i?.name??`unknown`,o={id:r,role:`assistant`,content:``,timestamp:Date.now(),toolCalls:[],isStreaming:!0,source:a,channel:t};return n.push(o),p?.jid===e&&f({type:`message_start`,messageId:r}),o}let b=new k8(o.getIframeContainer(),{onResponse:(e,t,n)=>{let r=y(e);n?r.content+=t:(r.content=t,r.isStreaming=!1),p?.jid===e&&(f({type:`content_delta`,messageId:r.id,text:t}),n||f({type:`content_done`,messageId:r.id}))},onResponseDone:e=>{let t=v(e),n=m.get(e);if(n){let r=t.find(e=>e.id===n);r&&(r.isStreaming=!1),p?.jid===e&&f({type:`content_done`,messageId:n}),m.delete(e)}},onSendMessage:(e,t)=>{$.debug(`Send message requested`,{targetJid:e,textLength:t.length});let n=`msg-${_()}`,r={id:n,chatJid:e,senderId:`assistant`,senderName:`sliccy`,content:t,timestamp:new Date().toISOString(),fromAssistant:!0,channel:`web`};b.handleMessage(r),v(e).push({id:n,role:`assistant`,content:t,timestamp:Date.now()}),p?.jid===e&&(f({type:`message_start`,messageId:n}),f({type:`content_delta`,messageId:n,text:t}),f({type:`content_done`,messageId:n}))},onStatusChange:(e,t)=>{if(o.panels.scoops.updateScoopStatus(e,t),o.updateScoopSwitcherStatus?.(e,t),p?.jid===e){if(o.setAgentProcessing(t===`processing`),t===`processing`)o.panels.chat.setProcessing(!0);else if(t===`ready`){o.panels.chat.setProcessing(!1);let t=m.get(e)??`done-${e}-${_()}`;m.delete(e),f({type:`turn_end`,messageId:t})}}},onError:(e,t)=>{$.error(`Scoop error`,{scoopJid:e,error:t}),p?.jid===e&&f({type:`error`,error:t})},getBrowserAPI:()=>u,onToolStart:(e,t,n)=>{if(new Set([`send_message`,`list_scoops`,`list_tasks`]).has(t))return;let r=y(e);r.toolCalls||=[],r.toolCalls.push({id:_(),name:t,input:n}),p?.jid===e&&f({type:`tool_use_start`,messageId:r.id,toolName:t,toolInput:n})},onToolEnd:(e,t,n,r)=>{if(new Set([`send_message`,`list_scoops`,`list_tasks`]).has(t))return;let i=v(e),a=m.get(e);if(a){let e=i.find(e=>e.id===a);if(e?.toolCalls){let i=[...e.toolCalls].reverse().find(e=>e.name===t&&e.result===void 0);i&&(i.result=n,i.isError=r)}}p?.jid===e&&a&&f({type:`tool_result`,messageId:a,toolName:t,result:n,isError:r})},onToolUI:(e,t,n,r)=>{let i=m.get(e);i?f({type:`tool_ui`,messageId:i,toolName:t,requestId:n,html:r}):$.warn(`Cannot emit tool_ui - no message ID for scoop`,{scoopJid:e,requestId:n})},onToolUIDone:(e,t)=>{let n=m.get(e);n&&f({type:`tool_ui_done`,messageId:n,requestId:t})},onIncomingMessage:(e,t)=>{if(wa(t.channel)){let n=new Date(t.timestamp).getTime(),r=t.channel;if(v(e).push({id:t.id,role:`user`,content:t.content,timestamp:n,source:`lick`,channel:r}),p?.jid===e)o.panels.chat.addLickMessage(t.id,t.content,r,n);else{let i=b.getScoops().find(t=>t.jid===e),a=i?.isCone?`session-cone`:i?`session-${i.folder}`:`session-${e}`;o.panels.chat.persistLickToSession(a,{id:t.id,content:t.content,channel:r,timestamp:n})}return}let n={id:t.id,role:`user`,content:t.channel===`delegation`?`**[Instructions from sliccy]**\n\n${t.content}`:t.content,timestamp:new Date(t.timestamp).getTime(),source:t.channel===`delegation`?`delegation`:void 0,channel:t.channel};v(e).push(n),p?.jid===e&&(f({type:`message_start`,messageId:t.id}),f({type:`content_delta`,messageId:t.id,text:n.content}),f({type:`content_done`,messageId:t.id}))}});await b.init(),o.panels.scoops.setOrchestrator(b),o.panels.memory.setOrchestrator(b),o.setScoopSwitcherOrchestrator?.(b);{let e=b.getSharedFS();e?Y8(b,e,b.getSessionStore()):$.warn(`AgentBridge not published — orchestrator.getSharedFS() returned null`)}let x=b.getSharedFS();if(x){o.panels.fileBrowser.setFs(x),$.info(`File browser wired to shared VFS`);let e=new BroadcastChannel(`preview-vfs`);e.onmessage=t=>{if(t.data?.type!==`preview-vfs-read`)return;let{id:n,path:r,asText:i}=t.data;(async()=>{try{let t=i?`utf-8`:`binary`,a=await x.readFile(r,{encoding:t});e.postMessage({type:`preview-vfs-response`,id:n,content:a})}catch(t){let i=t instanceof Error?t.message:String(t);i.includes(`ENOENT`)||$.error(`Preview VFS read failed`,{path:r,error:i}),e.postMessage({type:`preview-vfs-response`,id:n,error:i})}})()},v7(x,(e,t)=>{t===`error`?$.warn(`Dropped skill install failed`,{message:e}):$.info(`Dropped skill installed`,{message:e}),c(e,t)},async()=>{await o.panels.fileBrowser.refresh()});try{let{WasmShell:e}=await s(async()=>{let{WasmShell:e}=await Promise.resolve().then(()=>t6);return{WasmShell:e}},void 0),{fetchSecretEnvVars:t}=await s(async()=>{let{fetchSecretEnvVars:e}=await Promise.resolve().then(()=>o8);return{fetchSecretEnvVars:e}},void 0),n=await t(),r=new e({fs:x,browserAPI:u,env:Object.keys(n).length>0?n:void 0});await o.panels.terminal.mountShell(r),$.info(`Terminal mounted with shared VFS`);try{let{BshWatchdog:e}=await s(async()=>{let{BshWatchdog:e}=await import(`./bsh-watchdog-DYfdvOrR.js`);return{BshWatchdog:e}},__vite__mapDeps([19,13])),t=new e({browserAPI:u,scriptCatalog:r.getScriptCatalog(),fs:x});t.start(),window.addEventListener(`beforeunload`,()=>t.stop(),{once:!0}),$.info(`BSH navigation watchdog started`)}catch(e){$.warn(`Failed to start BSH watchdog`,e)}}catch(e){$.warn(`Failed to mount shell to terminal`,e)}}let C=b.getScoops(),w=C.some(e=>e.isCone);if(r)$.info(`Skipping local cone bootstrap while joining a tray without a configured provider`);else if(!w)p=await o.panels.scoops.createCone(),$.info(`Created cone`);else{let e=new URLSearchParams(window.location.search).get(`scoop`);if(e){let t=C.find(t=>t.folder===e);t?(p=t,$.info(`Restored scoop from URL`,{folder:e})):p=C.find(e=>e.isCone)??C[0]}else p=C.find(e=>e.isCone)??C[0]}p&&o.panels.memory.setSelectedScoop(p.jid);let T=null,E={sendMessage(e,t){if(!p){f({type:`error`,error:`No scoop selected`});return}let n={id:t??`msg-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,chatJid:p.jid,senderId:`user`,senderName:`User`,content:e,timestamp:new Date().toISOString(),fromAssistant:!1,channel:`web`};v(p.jid).push({id:n.id,role:`user`,content:e,timestamp:Date.now()}),T?.broadcastUserMessage(e,n.id),b.handleMessage(n),b.createScoopTab(p.jid)},onEvent(e){return d.add(e),()=>d.delete(e)},stop(){p&&(b.stopScoop(p.jid),b.clearQueuedMessages(p.jid).catch(e=>{$.error(`Failed to clear queued messages on stop`,{error:e instanceof Error?e.message:String(e)})}))}};o.panels.chat.setAgent(E),o.panels.chat.setDeleteQueuedMessageCallback(e=>{if(p){b.deleteQueuedMessage(p.jid,e).catch(t=>{$.error(`Failed to delete queued message`,{messageId:e,error:t instanceof Error?t.message:String(t)})});let t=h.get(p.jid);if(t){let n=t.findIndex(t=>t.id===e);n!==-1&&t.splice(n,1)}}}),$.info(`Cone agent handle wired to chat UI`);let{getLickManager:D}=await s(async()=>{let{getLickManager:e}=await Promise.resolve().then(()=>_8);return{getLickManager:e}},void 0),O=D();await O.init(),b.setLickManager(O);let ee=e=>{let t=e.type===`webhook`,n=e.type===`sprinkle`,r=e.type===`fswatch`,i=e.type===`session-reload`,a=e.type===`navigate`,s=t?e.webhookName:n?e.sprinkleName:r?e.fswatchName:i?`session-reload`:a?e.navigateUrl:e.cronName,c=t?e.webhookId:n?e.sprinkleName:r?e.fswatchId:i?`session-reload`:a?e.navigateUrl:e.cronId,l=e.type;if($.debug(`Lick event`,{type:e.type,name:s,targetScoop:e.targetScoop}),n&&e.sprinkleName===`welcome`){let t=e.body,n=t?.action;(n===`onboarding-complete`||n===`shortcut-migrate`)&&x?.writeFile(`/shared/.welcomed`,`1`).catch(e=>$.warn(`Failed to persist welcome marker`,e)),n===`shortcut-migrate`&&ne?.close(`welcome`),n===`onboarding-complete`&&t?.data?.mountWorkspace&&x&&h7(x).catch(e=>$.warn(`Failed to mount workspace from onboarding`,e))}if(n&&e.sprinkleName===`welcome`&&e.body?.action===`request-mount`){(async()=>{try{let e=window;if(!e.showDirectoryPicker)throw Error(`showDirectoryPicker not supported`);let t=await e.showDirectoryPicker({mode:`readwrite`});await m7(t),ne?.sendToSprinkle(`welcome`,{action:`mount-complete`,dirName:t.name})}catch(e){e.name!==`AbortError`&&$.warn(`Mount picker failed`,e),ne?.sendToSprinkle(`welcome`,{action:`mount-cancelled`})}})();return}let u=b.getScoops(),d;if(d=e.targetScoop?u.find(t=>t.name===e.targetScoop||t.folder===e.targetScoop||t.folder===`${e.targetScoop}-scoop`):u.find(e=>e.isCone),d){let u=`${l}-${c}-${Date.now()}`,f=t?`Webhook Event`:n?`Sprinkle Event`:r?`File Watch Event`:i?`Session Reload`:a?`Navigate Event`:`Cron Event`,m=null;if(i){let t=e.body;if(t?.reason===`mount-recovery`&&(m=l7(t.mounts??[]),m===null)){$.debug(`Dropping session-reload lick with empty mount-recovery list`);return}}m===null&&(m=`[${f}: ${s}]\n\`\`\`json\n${JSON.stringify(e.body,null,2)}\n\`\`\``);let h={id:u,chatJid:d.jid,senderId:l,senderName:`${l}:${s}`,content:m,timestamp:e.timestamp,fromAssistant:!1,channel:l},g=Date.now();if(v(d.jid).push({id:u,role:`user`,content:m,timestamp:g,source:`lick`,channel:l}),p?.jid===d.jid)o.panels.chat.addLickMessage(u,m,l,g);else{let e=d.isCone?`session-cone`:`session-${d.folder}`;o.panels.chat.persistLickToSession(e,{id:u,content:m,channel:l,timestamp:g})}$.info(`Routing lick to scoop`,{type:l,name:s,scoopJid:d.jid}),b.handleMessage(h)}else $.warn(`Lick target scoop not found`,{targetScoop:e.targetScoop})};O.setEventHandler(ee);let te=new hc(u.getTransport(),e=>{O.emitEvent({type:`navigate`,navigateUrl:e.url,targetScoop:void 0,timestamp:new Date().toISOString(),body:{url:e.url,sliccHeader:e.sliccHeader,title:e.title}})});(async()=>{try{await u.connect(),await te.start(),$.info(`Navigation watcher started`)}catch(e){$.warn(`Failed to start navigation watcher`,{error:e instanceof Error?e.message:String(e)})}})(),x&&Ls().then(async e=>{if(e.length===0)return;let{needsRecovery:t}=await o7(e,x,$);t.length!==0&&ee({type:`session-reload`,targetScoop:void 0,timestamp:new Date().toISOString(),body:{reason:`mount-recovery`,mounts:t}})}).catch(e=>$.warn(`Failed to restore persisted mounts`,e)),o.panels.chat.onInlineSprinkleLick=(e,t)=>{ee({type:`sprinkle`,sprinkleName:`inline`,targetScoop:void 0,timestamp:new Date().toISOString(),body:{action:e,data:t}})};let ne=null;if(x){if(ne=new a7(x,ee,{addSprinkle:(e,t,n,r)=>o.addSprinkle(e,t,n,r),removeSprinkle:e=>o.removeSprinkle(e)},()=>{let e=b.getScoops().find(e=>e.isCone);e&&(b.stopScoop(e.jid),b.clearQueuedMessages(e.jid).catch(e=>{$.error(`Failed to clear queued messages on sprinkle stopCone`,{error:e instanceof Error?e.message:String(e)})}))}),window.__slicc_sprinkleManager=ne,window.__slicc_reloadSkills=()=>b.reloadAllSkills(),await ne.refresh(),o.onSprinkleClose=e=>ne.close(e),o.getAvailableSprinkles=()=>{let e=new Set(ne.opened());return ne.available().filter(t=>!e.has(t.name)).map(e=>({name:e.name,title:e.title}))},o.onOpenSprinkle=(e,t)=>ne.open(e,t),o.updateAddButtons(),!await x.exists(`/shared/.welcomed`)&&localStorage.getItem(`slicc-welcomed`)&&(await x.writeFile(`/shared/.welcomed`,`1`).catch(()=>{}),localStorage.removeItem(`slicc-welcomed`)),!await x.exists(`/shared/.welcomed`)&&!r&&ne.available().some(e=>e.name===`welcome`))try{await ne.open(`welcome`)}catch(e){$.warn(`Failed to open welcome sprinkle`,e)}await ne.restoreOpenSprinkles(),$.info(`SprinkleManager initialized`)}let k=()=>{let e=q5(window.location.href),t=new WebSocket(e);t.onopen=()=>{$.info(`Lick WebSocket connected`)},t.onmessage=async e=>{try{let n=JSON.parse(e.data);if(n.requestId){let e;try{switch(n.type){case`list_webhooks`:e={type:`response`,requestId:n.requestId,data:O.listWebhooks()};break;case`create_webhook`:{let t=await O.createWebhook(n.name||`default`,n.scoop,n.filter),r=T$().session,i=r?.webhookUrl?Y5(r.webhookUrl,t.id):J5(window.location.href,t.id);e={type:`response`,requestId:n.requestId,data:{...t,url:i}};break}case`delete_webhook`:e=await O.deleteWebhook(n.id)?{type:`response`,requestId:n.requestId,data:{ok:!0}}:{type:`response`,requestId:n.requestId,data:{error:`Webhook not found`}};break;case`list_crontasks`:e={type:`response`,requestId:n.requestId,data:O.listCronTasks()};break;case`create_crontask`:{if(!n.name)throw Error(`name is required`);if(!n.cron)throw Error(`cron is required`);let t=await O.createCronTask(n.name,n.cron,n.scoop,n.filter);e={type:`response`,requestId:n.requestId,data:t};break}case`delete_crontask`:e=await O.deleteCronTask(n.id)?{type:`response`,requestId:n.requestId,data:{ok:!0}}:{type:`response`,requestId:n.requestId,data:{error:`Cron task not found`}};break;case`tray_status`:{let t=T$();e={type:`response`,requestId:n.requestId,data:{state:t.state,joinUrl:t.session?.joinUrl??null,workerBaseUrl:t.session?.workerBaseUrl??null,trayId:t.session?.trayId??null}};break}default:e={type:`response`,requestId:n.requestId,error:`Unknown request type: ${n.type}`}}}catch(t){e={type:`response`,requestId:n.requestId,error:t instanceof Error?t.message:String(t)}}t.send(JSON.stringify(e));return}if(n.type===`webhook_event`&&O.handleWebhookEvent(n.webhookId,n.headers,n.body),n.type===`navigate_event`){let e=typeof n.sliccHeader==`string`?n.sliccHeader:``,t=typeof n.url==`string`&&n.url.length>0?n.url:``;e&&t&&O.emitEvent({type:`navigate`,navigateUrl:t,targetScoop:void 0,timestamp:typeof n.timestamp==`string`?n.timestamp:new Date().toISOString(),body:{url:t,sliccHeader:e,title:typeof n.title==`string`?n.title:void 0}})}}catch(e){$.error(`Failed to process lick message`,{error:e instanceof Error?e.message:String(e)})}},t.onclose=()=>{$.warn(`Lick WebSocket disconnected, reconnecting in 3s...`),setTimeout(k,3e3)},t.onerror=e=>{$.error(`Lick WebSocket error`,{error:String(e)})}};k(),o.onModelChange=e=>{localStorage.setItem(`selected-model`,e),b.updateModel()};let re=new Set;o.onClearChat=async()=>{await b.clearAllMessages(),h.clear(),re.clear()},o.onClearFilesystem=async()=>{await b.resetFilesystem()};let ie=async e=>{$.info(`Scoop selected`,{jid:e.jid,name:e.name}),p=e,b.createScoopTab(e.jid),o.panels.memory.setSelectedScoop(e.jid),o.panels.scoops.setSelectedJid(e.jid);let t=e.isCone?`session-cone`:`session-${e.folder}`,n=h.get(e.jid),r=!re.has(e.jid),i=e.isCone?void 0:e.name;if(!r&&n&&n.length>0)await o.panels.chat.switchToContext(t,!e.isCone,i),o.panels.chat.loadMessages(n);else{if(await o.panels.chat.switchToContext(t,!e.isCone,i),o.panels.chat.getMessages().length===0){let t=await b.getMessagesForScoop(e.jid);for(let e of t){let t=e.channel===`delegation`;wa(e.channel)?o.panels.chat.addLickMessage(e.id,e.content,e.channel,new Date(e.timestamp).getTime()):t?o.panels.chat.addUserMessage(`**[Instructions from sliccy]**\n\n${e.content}`):e.fromAssistant?(f({type:`message_start`,messageId:e.id}),f({type:`content_delta`,messageId:e.id,text:e.content}),f({type:`content_done`,messageId:e.id})):o.panels.chat.addUserMessage(e.content)}}let n=o.panels.chat.getMessages(),r=new Set(n.map(e=>e.id)),a=v(e.jid),s=a.filter(e=>!r.has(e.id));a.length=0,a.push(...n,...s),s.length>0&&o.panels.chat.loadMessages(a)}e.isCone&&b.isProcessing(e.jid)&&o.panels.chat.setProcessing(!0),re.add(e.jid)};if(o.onScoopSelect=ie,p&&(b.createScoopTab(p.jid),await ie(p)),f7()&&await p7(o.panels.chat),a===`standalone`||a===`electron-overlay`){let e=await fo(),t=W5(a,e!==null)?no:null,n=await uo({locationHref:window.location.href,storage:window.localStorage,envBaseUrl:null,defaultWorkerBaseUrl:t,runtimeConfigFetcher:async()=>e}),r=null,i=null,s=null;P0(()=>T?(e,t)=>T.sendFsRequest(e,t):r?(e,t)=>r.sendFsRequest(e,t):null),pQ(()=>T?()=>T.getBestFollowerForTeleport():null),mQ(()=>T?()=>T.getConnectedFollowers():null);let c=e=>{s&&=(clearInterval(s),null),r?.close();let t=`follower-${e.bootstrapId}`,n=new z5(e.channel,{browserTransport:u.getTransport(),browserAPI:u,onSnapshot:e=>{o.panels.chat.loadMessages(e)},onUserMessage:e=>{o.panels.chat.addUserMessage(e)},onStatus:e=>{o.panels.chat.setProcessing(e===`processing`)},onTargetsChanged:()=>void i()});r=n,u.setTrayTargetProvider(n),o.panels.chat.setAgent(n),n.requestSnapshot();let i=async()=>{try{let e=await u.listPages();n.advertiseTargets(e.map(e=>({targetId:e.targetId,title:e.title,url:e.url})),t)}catch{}};s=setInterval(i,5e3),i(),$.info(`Follower sync wired to chat panel`,{trayId:e.trayId})},l=e=>{i?.cancel(),s&&=(clearInterval(s),null),r?.close(),r=null,i=p5({joinUrl:e,runtime:`slicc-standalone`,fetchImpl:N$()},{onConnected:e=>c(e),onReconnecting:e=>{$.info(`Follower reconnecting`,{attempt:e})},onGaveUp:e=>{$.warn(`Follower reconnect gave up`,{lastError:e})}})};if(window.addEventListener(`slicc:tray-join`,(e=>{l(e.detail.joinUrl)})),window.addEventListener(`beforeunload`,()=>{s&&clearInterval(s),r?.close(),i?.cancel()},{once:!0}),n?.joinUrl)l(n.joinUrl);else if(n?.workerBaseUrl){let e,t,r,i,a=new H5,s=()=>{t=new L5({browserTransport:u.getTransport(),browserAPI:u,getMessages:()=>o.panels.chat.getMessages(),getScoopJid:()=>p?.jid??`cone`,onFollowerMessage:(e,t)=>{o.panels.chat.addUserMessage(e),E.sendMessage(e,t)},onFollowerAbort:()=>{E.stop()},onFollowerCountChanged:e=>{e>0?a.activate():a.deactivate()}}),T=t,F$(()=>t.getConnectedFollowers()),u.setTrayTargetProvider(t),i&&clearInterval(i);let n=async()=>{try{let e=await u.listPages();t.setLocalTargets(e.map(e=>({targetId:e.targetId,title:e.title,url:e.url})))}catch{}};i=setInterval(n,5e3),n(),r=new d5({sendControlMessage:t=>e.sendControlMessage(t),onPeerConnected:(e,n)=>{$.info(`Tray follower data channel opened`,{controllerId:e.controllerId,bootstrapId:e.bootstrapId,attempt:e.attempt,runtime:e.runtime}),t.addFollower(e.bootstrapId,n,{runtime:e.runtime,connectedAt:e.connectedAt??void 0})}})};s(),d.add(e=>{t.broadcastEvent(e)}),e=new k$({workerBaseUrl:n.workerBaseUrl,runtime:`slicc-standalone`,fetchImpl:N$(),onControlMessage:e=>{if(e.type===`webhook.event`){O.handleWebhookEvent(e.webhookId,e.headers,e.body);return}r.handleControlMessage(e).catch(e=>{$.warn(`Tray leader bootstrap handling failed`,{error:e instanceof Error?e.message:String(e)})})},onReconnecting:(e,t)=>{$.info(`Leader tray reconnecting`,{attempt:e,lastError:t})},onReconnected:e=>{$.info(`Leader tray reconnected`,{trayId:e.trayId});let t=lo(window.location.href,e.workerBaseUrl,e.trayId);t!==window.location.href&&window.history.replaceState(window.history.state,``,t)},onReconnectGaveUp:(e,t)=>{$.warn(`Leader tray reconnect gave up`,{lastError:e,attempts:t})}}),R$(async()=>{t.stop(),r.stop(),e.stop(),await e.clearSession();let n=await e.start(),i=lo(window.location.href,n.workerBaseUrl,n.trayId);return i!==window.location.href&&window.history.replaceState(window.history.state,``,i),s(),T$()}),e.start().then(e=>{let t=lo(window.location.href,e.workerBaseUrl,e.trayId);t!==window.location.href&&window.history.replaceState(window.history.state,``,t)}).catch(e=>{$.warn(`Leader tray join failed`,{error:e instanceof Error?e.message:String(e)})}),window.addEventListener(`beforeunload`,()=>{clearInterval(i),t.stop(),r.stop(),e.stop(),a.deactivate()},{once:!0})}}$.info(`Orchestrator initialized — cone+scoops ready`,{scoopCount:b.getScoops().length}),V3().catch(()=>{})}x7().catch(e=>{$.error(`Fatal error`,e);let t=document.getElementById(`app`);if(t){let n=document.createElement(`div`);n.style.cssText=`padding: 2rem; text-align: center;`;let r=document.createElement(`h1`);r.style.color=`var(--s2-negative, #e34850)`,r.textContent=`Failed to start`;let i=document.createElement(`p`);i.style.color=`var(--s2-content-tertiary, #717171)`,i.textContent=e.message,n.appendChild(r),n.appendChild(i);let a=document.createElement(`button`);for(a.textContent=`Reset all data & reload`,a.style.cssText=`margin-top: 1rem; padding: 0.5rem 1.5rem; background: var(--s2-negative, #e34850); color: #fff; border: none; border-radius: 6px; cursor: pointer; font-size: 14px;`,a.addEventListener(`click`,async()=>{a.disabled=!0,a.textContent=`Resetting…`;let e=await indexedDB.databases();await Promise.all(e.map(e=>e.name?new Promise(t=>{let n=indexedDB.deleteDatabase(e.name);n.onsuccess=()=>t(),n.onerror=()=>t(),n.onblocked=()=>t()}):Promise.resolve())),location.reload()}),n.appendChild(a);t.firstChild;)t.removeChild(t.firstChild);t.appendChild(n)}});export{Ba as a,di as c,oo as i,ui as l,go as n,Va as o,so as r,Na as s,rK as t};