@pragma-sh/scratchpad-viewer 0.1.0 → 0.3.0

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.
package/dist/index.cjs CHANGED
@@ -118,7 +118,7 @@ Defaulting to 2020, but this will stop working in the future.\`)),t.ecmaVersion=
118
118
  \`},r)),a}function qu(e,t){return e&&"run"in e?async function(n,i){let r=Fu(n,{file:i,...t});await e.run(r,i)}:function(n,i){return Fu(n,{file:i,...e||t})}}function xh(e){if(e)throw e}var Xu=qt(kb(),1);function wl(e){if(typeof e!="object"||e===null)return!1;let t=Object.getPrototypeOf(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)}function yh(){let e=[],t={run:n,use:i};return t;function n(...r){let a=-1,s=r.pop();if(typeof s!="function")throw new TypeError("Expected function as last argument, not "+s);o(null,...r);function o(u,...f){let p=e[++a],h=-1;if(u){s(u);return}for(;++h<r.length;)(f[h]===null||f[h]===void 0)&&(f[h]=r[h]);r=f,p?Eb(p,o)(...f):s(null,...f)}}function i(r){if(typeof r!="function")throw new TypeError("Expected \`middelware\` to be a function, not "+r);return e.push(r),t}}function Eb(e,t){let n;return i;function i(...s){let o=e.length>s.length,u;o&&s.push(r);try{u=e.apply(this,s)}catch(f){let p=f;if(o&&n)throw p;return r(p)}o||(u&&u.then&&typeof u.then=="function"?u.then(a,r):u instanceof Error?r(u):a(u))}function r(s,...o){n||(n=!0,t(s,...o))}function a(s){r(null,s)}}var Cb=(function(e){let i=this.constructor.prototype,r=i[e],a=function(){return r.apply(a,arguments)};return Object.setPrototypeOf(a,i),a});var M6={}.hasOwnProperty,wh=class e extends Cb{constructor(){super("copy"),this.Compiler=void 0,this.Parser=void 0,this.attachers=[],this.compiler=void 0,this.freezeIndex=-1,this.frozen=void 0,this.namespace={},this.parser=void 0,this.transformers=yh()}copy(){let t=new e,n=-1;for(;++n<this.attachers.length;){let i=this.attachers[n];t.use(...i)}return t.data((0,Xu.default)(!0,{},this.namespace)),t}data(t,n){return typeof t=="string"?arguments.length===2?(Sh("data",this.frozen),this.namespace[t]=n,this):M6.call(this.namespace,t)&&this.namespace[t]||void 0:t?(Sh("data",this.frozen),this.namespace=t,this):this.namespace}freeze(){if(this.frozen)return this;let t=this;for(;++this.freezeIndex<this.attachers.length;){let[n,...i]=this.attachers[this.freezeIndex];if(i[0]===!1)continue;i[0]===!0&&(i[0]=void 0);let r=n.call(t,...i);typeof r=="function"&&this.transformers.use(r)}return this.frozen=!0,this.freezeIndex=Number.POSITIVE_INFINITY,this}parse(t){this.freeze();let n=Ju(t),i=this.parser||this.Parser;return bh("parse",i),i(String(n),n)}process(t,n){let i=this;return this.freeze(),bh("process",this.parser||this.Parser),vh("process",this.compiler||this.Compiler),n?r(void 0,n):new Promise(r);function r(a,s){let o=Ju(t),u=i.parse(o);i.run(u,o,function(p,h,g){if(p||!h||!g)return f(p);let m=h,v=i.stringify(m,g);z6(v)?g.value=v:g.result=v,f(p,g)});function f(p,h){p||!h?s(p):a?a(h):n(void 0,h)}}}processSync(t){let n=!1,i;return this.freeze(),bh("processSync",this.parser||this.Parser),vh("processSync",this.compiler||this.Compiler),this.process(t,r),Ab("processSync","process",n),i;function r(a,s){n=!0,xh(a),i=s}}run(t,n,i){_b(t),this.freeze();let r=this.transformers;return!i&&typeof n=="function"&&(i=n,n=void 0),i?a(void 0,i):new Promise(a);function a(s,o){let u=Ju(n);r.run(t,u,f);function f(p,h,g){let m=h||t;p?o(p):s?s(m):i(void 0,m,g)}}}runSync(t,n){let i=!1,r;return this.run(t,n,a),Ab("runSync","run",i),r;function a(s,o){xh(s),r=o,i=!0}}stringify(t,n){this.freeze();let i=Ju(n),r=this.compiler||this.Compiler;return vh("stringify",r),_b(t),r(t,i)}use(t,...n){let i=this.attachers,r=this.namespace;if(Sh("use",this.frozen),t!=null)if(typeof t=="function")u(t,n);else if(typeof t=="object")Array.isArray(t)?o(t):s(t);else throw new TypeError("Expected usable value, not \`"+t+"\`");return this;function a(f){if(typeof f=="function")u(f,[]);else if(typeof f=="object")if(Array.isArray(f)){let[p,...h]=f;u(p,h)}else s(f);else throw new TypeError("Expected usable value, not \`"+f+"\`")}function s(f){if(!("plugins"in f)&&!("settings"in f))throw new Error("Expected usable value but received an empty preset, which is probably a mistake: presets typically come with \`plugins\` and sometimes with \`settings\`, but this has neither");o(f.plugins),f.settings&&(r.settings=(0,Xu.default)(!0,r.settings,f.settings))}function o(f){let p=-1;if(f!=null)if(Array.isArray(f))for(;++p<f.length;){let h=f[p];a(h)}else throw new TypeError("Expected a list of plugins, not \`"+f+"\`")}function u(f,p){let h=-1,g=-1;for(;++h<i.length;)if(i[h][0]===f){g=h;break}if(g===-1)i.push([f,...p]);else if(p.length>0){let[m,...v]=p,S=i[g][1];wl(S)&&wl(m)&&(m=(0,Xu.default)(!0,S,m)),i[g]=[f,m,...v]}}}},kh=new wh().freeze();function bh(e,t){if(typeof t!="function")throw new TypeError("Cannot \`"+e+"\` without \`parser\`")}function vh(e,t){if(typeof t!="function")throw new TypeError("Cannot \`"+e+"\` without \`compiler\`")}function Sh(e,t){if(t)throw new Error("Cannot call \`"+e+"\` on a frozen processor.\\nCreate a new processor first, by calling it: use \`processor()\` instead of \`processor\`.")}function _b(e){if(!wl(e)||typeof e.type!="string")throw new TypeError("Expected node, got \`"+e+"\`")}function Ab(e,t,n){if(!n)throw new Error("\`"+e+"\` finished async. Use \`"+t+"\` instead")}function Ju(e){return R6(e)?e:new Pr(e)}function R6(e){return!!(e&&typeof e=="object"&&"message"in e&&"messages"in e)}function z6(e){return typeof e=="string"||B6(e)}function B6(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}function ai(e,t){let n=["start","end","loc","range"],i=-1;for(;++i<n.length;){let r=n[i];r in e&&(t[r]=e[r])}}function Xa(e,t){let n=-1,i=[],r=[],a;for(;++n<e.length;){let s=e[n];s.type==="ImportNamespaceSpecifier"?a=s:r.push(s)}if(a){let s={type:"VariableDeclarator",id:a.local,init:t};ai(a,s),i.push(s)}return i.push({type:"VariableDeclarator",id:{type:"ObjectPattern",properties:r.map(function(s){let o=s.type==="ImportSpecifier"?s.imported:s.type==="ExportSpecifier"?s.exported:{type:"Identifier",name:"default"},u=s.local;s.type==="ExportSpecifier"&&(u=o,o=s.local),u.type;let f={type:"Property",kind:"init",shorthand:o.type==="Identifier"&&u.type==="Identifier"&&o.name===u.name,method:!1,computed:!1,key:o,value:u};return ai(s,f),f})},init:a?{type:"Identifier",name:a.local.name}:t}),i}function Kn(e){let t=-1,n;for(;++t<e.length;){let i=e[t],r=typeof i=="string"&&Mt(i)?{type:"Identifier",name:i}:{type:"Literal",value:i};n=n?{type:"MemberExpression",object:n,property:r,computed:r.type==="Literal",optional:!1}:r}return n.type,n}function Eh(e){let t=-1,n;for(;++t<e.length;){let i=e[t];typeof i=="string"&&Mt(i,{jsx:!0}),""+i;let r={type:"JSXIdentifier",name:i};n=n?{type:"JSXMemberExpression",object:n,property:r}:r}return n}function Tb(e){let{outputFormat:t}=e||{};return function(n){if(n.comments&&(n.comments=n.comments.filter(function(i){return!i.data?._mdxIsPragmaComment})),t==="function-body"){let i=0;for(;i<n.body.length;){let a=n.body[i];if("directive"in a&&a.directive)i++;else break}let r=n.body[i];r&&r.type==="ImportDeclaration"&&typeof r.source.value=="string"&&/\\/jsx-(dev-)?runtime$/.test(r.source.value)&&(n.body[i]={type:"VariableDeclaration",kind:"const",declarations:Xa(r.specifiers,Kn(["arguments",0]))})}}}function kl(){let e=[{block:!1,defined:[]}];return{enter:t,exit:n,scopes:e};function t(a){if(a.type==="ArrowFunctionExpression"){e.push({block:!1,defined:[]});for(let s of a.params)r(s,!1)}else if(a.type==="BlockStatement"||a.type==="DoWhileStatement"||a.type==="ForInStatement"||a.type==="ForOfStatement"||a.type==="ForStatement"||a.type==="WhileStatement")e.push({block:!0,defined:[]});else if(a.type==="CatchClause")e.push({block:!0,defined:[]}),a.param&&r(a.param,!0);else if(a.type==="ClassDeclaration")i(a.id.name,!1);else if(a.type==="FunctionDeclaration"){a.id&&i(a.id.name,!1),e.push({block:!1,defined:[]});for(let s of a.params)r(s,!1)}else if(a.type==="FunctionExpression"){a.id&&i(a.id.name,!1),e.push({block:!1,defined:[]});for(let s of a.params)r(s,!1)}else if(a.type==="ImportDeclaration")for(let s of a.specifiers)i(s.local.name,!1);else if(a.type==="VariableDeclaration")for(let s of a.declarations)r(s.id,a.kind!=="var")}function n(a){if(a.type==="ArrowFunctionExpression"||a.type==="FunctionDeclaration"||a.type==="FunctionExpression"){let s=e.pop();s.block}else if(a.type==="BlockStatement"||a.type==="CatchClause"||a.type==="DoWhileStatement"||a.type==="ForInStatement"||a.type==="ForOfStatement"||a.type==="ForStatement"||a.type==="WhileStatement"){let s=e.pop();s.block}}function i(a,s){let o=e.length,u;for(;o--&&(u=e[o],!(s||!u.block)););u.defined.push(a)}function r(a,s){if(a.type==="ArrayPattern")for(let o of a.elements)o&&r(o,s);else if(a.type==="AssignmentPattern")r(a.left,s);else if(a.type==="Identifier")i(a.name,s);else if(a.type==="ObjectPattern")for(let o of a.properties)o.type==="Property"?r(o.value,s):(o.type,r(o,s));else a.type,r(a.argument,s)}}function Nb(e){return e.type==="FunctionDeclaration"?{...e,type:"FunctionExpression"}:(e.type,{...e,type:"ClassExpression"})}function Db(e){return e.type==="FunctionDeclaration"||e.type==="ClassDeclaration"||e.type==="VariableDeclaration"}function Ob(e){let t=e.baseUrl||void 0,n=typeof t=="object"?t.href:t,i=e.outputFormat||"program",r=e.pragma===void 0?"React.createElement":e.pragma,a=e.pragmaFrag===void 0?"React.Fragment":e.pragmaFrag,s=e.pragmaImportSource||"react",o=e.jsxImportSource||"react",u=e.jsxRuntime||"automatic";return function(p,h){let g=[],m=[],v=0,S,N,y;if(u==="classic"&&a&&Gu(p,"@jsxFrag",a),u==="classic"&&r&&Gu(p,"@jsx",r),u==="automatic"&&o&&Gu(p,"@jsxImportSource",o),u&&Gu(p,"@jsxRuntime",u),u==="classic"&&s){if(!r)throw new Error("Missing \`pragma\` in classic runtime with \`pragmaImportSource\`");M({type:"ImportDeclaration",specifiers:[{type:"ImportDefaultSpecifier",local:{type:"Identifier",name:r.split(".")[0]}}],attributes:[],source:{type:"Literal",value:s}})}for(y of p.body)if(y.type==="ExportDefaultDeclaration")S&&h.fail("Unexpected duplicate layout, expected a single layout (previous: "+gt(Gt(S))+")",{ancestors:[p,y],place:Gt(y),ruleId:"duplicate-layout",source:"recma-document"}),S=y,m.push({type:"VariableDeclaration",kind:"const",declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:"MDXLayout"},init:Db(y.declaration)?Nb(y.declaration):y.declaration}]});else if(y.type==="ExportNamedDeclaration"&&y.source){let T=y.source;y.specifiers=y.specifiers.filter(function(A){if(A.exported.type==="Identifier"&&A.exported.name==="default"){S&&h.fail("Unexpected duplicate layout, expected a single layout (previous: "+gt(Gt(S))+")",{ancestors:[p,y,A],place:Gt(y),ruleId:"duplicate-layout",source:"recma-document"}),S=A;let L=[];if(A.local.type==="Identifier"&&A.local.name==="default")L.push({type:"ImportDefaultSpecifier",local:{type:"Identifier",name:"MDXLayout"}});else{let ee={type:"ImportSpecifier",imported:A.local,local:{type:"Identifier",name:"MDXLayout"}};ai(A.local,ee),L.push(ee)}let V={type:"Literal",value:T.value};ai(T,V);let D={type:"ImportDeclaration",specifiers:L,attributes:[],source:V};return ai(A,D),M(D),!1}return!0}),y.specifiers.length>0&&d(y)}else y.type==="ExportNamedDeclaration"||y.type==="ExportAllDeclaration"?d(y):y.type==="ImportDeclaration"?M(y):y.type==="ExpressionStatement"&&(y.expression.type==="JSXElement"||y.expression.type==="JSXFragment")?(N=!0,m.push(...f(y.expression,i,!!S))):m.push(y);N||m.push(...f(void 0,i,!!S)),g.push(["MDXContent","default"]),i==="function-body"&&m.push({type:"ReturnStatement",argument:{type:"ObjectExpression",properties:[...Array.from({length:v}).map(function(T,A){return{type:"SpreadElement",argument:{type:"Identifier",name:"_exportAll"+(A+1)}}}),...g.map(function(T){return{type:"Property",kind:"init",method:!1,computed:!1,shorthand:typeof T=="string",key:{type:"Identifier",name:typeof T=="string"?T:T[1]},value:{type:"Identifier",name:typeof T=="string"?T:T[0]}}})]}}),p.body=m;let w=!1,k=!1;(n||i==="function-body")&&ni(p,{enter(T){if((T.type==="ExportAllDeclaration"||T.type==="ExportNamedDeclaration"||T.type==="ImportDeclaration")&&T.source){let A=T.source.value;try{new URL(A)}catch{(A.startsWith("/")||A.startsWith("./")||A.startsWith("../"))&&(A=new URL(A,n).href)}let L={type:"Literal",value:A};ai(T.source,L),T.source=L;return}if(T.type==="ImportExpression"){k=!0;let A={type:"CallExpression",callee:{type:"Identifier",name:"_resolveDynamicMdxSpecifier"},arguments:[T.source],optional:!1};T.source=A;return}if(T.type==="MemberExpression"&&"object"in T&&T.object.type==="MetaProperty"&&T.property.type==="Identifier"&&T.object.meta.name==="import"&&T.object.property.name==="meta"&&T.property.name==="url"){w=!0;let A={type:"Identifier",name:"_importMetaUrl"};ai(T,A),this.replace(A)}}}),k&&(n||(w=!0),p.body.push(V6(n?{type:"Literal",value:n}:{type:"Identifier",name:"_importMetaUrl"}))),w&&p.body.unshift(...U6());function d(T){if(T.type==="ExportNamedDeclaration"){if(T.declaration){let A=kl();ni(T,{enter(L){A.enter(L),(L.type==="ArrowFunctionExpression"||L.type==="FunctionDeclaration"||L.type==="FunctionExpression")&&(this.skip(),A.exit(L))},leave:A.exit}),g.push(...A.scopes[0].defined)}for(y of T.specifiers)y.exported.type==="Identifier"?g.push(y.exported.name):(y.exported.value,g.push(y.exported.value))}M(T)}function M(T){let A,L;if(i==="function-body")if(T.type==="ImportDeclaration"||T.type==="ExportAllDeclaration"||T.type==="ExportNamedDeclaration"&&T.source){T.source;let V={type:"ImportExpression",source:T.source};ai(T,V),L={type:"AwaitExpression",argument:V},(T.type==="ImportDeclaration"||T.type==="ExportNamedDeclaration")&&T.specifiers.length===0?A={type:"ExpressionStatement",expression:L}:A={type:"VariableDeclaration",kind:"const",declarations:T.type==="ExportAllDeclaration"?[{type:"VariableDeclarator",id:{type:"Identifier",name:"_exportAll"+ ++v},init:L}]:Xa(T.specifiers,L)}}else if(T.declaration)A=T.declaration;else{let V=[];for(let D of T.specifiers)D.exported.type==="Identifier"&&D.local.type==="Identifier"&&D.local.name!==D.exported.name&&V.push({type:"VariableDeclarator",id:D.exported,init:D.local});V.length>0&&(A={type:"VariableDeclaration",kind:"const",declarations:V})}else A=T;A&&m.push(A)}};function f(p,h,g){let v={type:"JSXElement",openingElement:{type:"JSXOpeningElement",name:{type:"JSXIdentifier",name:"MDXLayout"},attributes:[{type:"JSXSpreadAttribute",argument:{type:"Identifier",name:"props"}}],selfClosing:!1},closingElement:{type:"JSXClosingElement",name:{type:"JSXIdentifier",name:"MDXLayout"}},children:[{type:"JSXElement",openingElement:{type:"JSXOpeningElement",name:{type:"JSXIdentifier",name:"_createMdxContent"},attributes:[{type:"JSXSpreadAttribute",argument:{type:"Identifier",name:"props"}}],selfClosing:!0},closingElement:null,children:[]}]};g||(v={type:"ConditionalExpression",test:{type:"Identifier",name:"MDXLayout"},consequent:v,alternate:{type:"CallExpression",callee:{type:"Identifier",name:"_createMdxContent"},arguments:[{type:"Identifier",name:"props"}],optional:!1}});let S=p||{type:"Identifier",name:"undefined"};S.type==="JSXFragment"&&S.children.length===1&&S.children[0].type==="JSXElement"&&(S=S.children[0]);let N=!1;ni(S,{enter(w){if(w.type==="ArrowFunctionExpression"||w.type==="FunctionDeclaration"||w.type==="FunctionExpression")return this.skip();(w.type==="AwaitExpression"||w.type==="ForOfStatement"&&w.await)&&(N=!0)}});let y={type:"FunctionDeclaration",id:{type:"Identifier",name:"MDXContent"},params:[{type:"AssignmentPattern",left:{type:"Identifier",name:"props"},right:{type:"ObjectExpression",properties:[]}}],body:{type:"BlockStatement",body:[{type:"ReturnStatement",argument:v}]}};return[{type:"FunctionDeclaration",async:N,id:{type:"Identifier",name:"_createMdxContent"},params:[{type:"Identifier",name:"props"}],body:{type:"BlockStatement",body:[{type:"ReturnStatement",argument:S}]}},h==="program"?{type:"ExportDefaultDeclaration",declaration:y}:y]}}function Gu(e,t,n){e.comments?.unshift({type:"Block",value:t+" "+n,data:{_mdxIsPragmaComment:!0}})}function V6(e){return{type:"FunctionDeclaration",id:{type:"Identifier",name:"_resolveDynamicMdxSpecifier"},generator:!1,async:!1,params:[{type:"Identifier",name:"d"}],body:{type:"BlockStatement",body:[{type:"IfStatement",test:{type:"BinaryExpression",left:{type:"UnaryExpression",operator:"typeof",prefix:!0,argument:{type:"Identifier",name:"d"}},operator:"!==",right:{type:"Literal",value:"string"}},consequent:{type:"ReturnStatement",argument:{type:"Identifier",name:"d"}},alternate:null},{type:"TryStatement",block:{type:"BlockStatement",body:[{type:"ExpressionStatement",expression:{type:"NewExpression",callee:{type:"Identifier",name:"URL"},arguments:[{type:"Identifier",name:"d"}]}},{type:"ReturnStatement",argument:{type:"Identifier",name:"d"}}]},handler:{type:"CatchClause",param:null,body:{type:"BlockStatement",body:[]}},finalizer:null},{type:"IfStatement",test:{type:"LogicalExpression",left:{type:"LogicalExpression",left:{type:"CallExpression",callee:Kn(["d","startsWith"]),arguments:[{type:"Literal",value:"/"}],optional:!1},operator:"||",right:{type:"CallExpression",callee:Kn(["d","startsWith"]),arguments:[{type:"Literal",value:"./"}],optional:!1}},operator:"||",right:{type:"CallExpression",callee:Kn(["d","startsWith"]),arguments:[{type:"Literal",value:"../"}],optional:!1}},consequent:{type:"ReturnStatement",argument:{type:"MemberExpression",object:{type:"NewExpression",callee:{type:"Identifier",name:"URL"},arguments:[{type:"Identifier",name:"d"},e]},property:{type:"Identifier",name:"href"},computed:!1,optional:!1}},alternate:null},{type:"ReturnStatement",argument:{type:"Identifier",name:"d"}}]}}}function U6(){return[{type:"VariableDeclaration",declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:"_importMetaUrl"},init:Kn(["arguments",0,"baseUrl"])}],kind:"const"},{type:"IfStatement",test:{type:"UnaryExpression",operator:"!",prefix:!0,argument:{type:"Identifier",name:"_importMetaUrl"}},consequent:{type:"ThrowStatement",argument:{type:"NewExpression",callee:{type:"Identifier",name:"Error"},arguments:[{type:"Literal",value:"Unexpected missing \`options.baseUrl\` needed to support \`export \\u2026 from\`, \`import\`, or \`import.meta.url\` when generating \`function-body\`"}]}},alternate:null}]}function Ch(e){let t=-1,n;for(;++t<e.length;){let i=e[t];n=n?{type:"BinaryExpression",left:n,operator:"+",right:i}:i}return n}function Ib(e){let{development:t,outputFormat:n,providerImportSource:i}=e;return function(r,a){let s=kl(),o=[],u=!1,f=!1;if(ni(r,{enter(p){s.enter(p),(p.type==="FunctionDeclaration"||p.type==="FunctionExpression"||p.type==="ArrowFunctionExpression")&&(o.push({components:[],idToInvalidComponentName:new Map,node:p,objects:[],references:{},tags:[]}),Ga(p,"MDXContent")&&!_h(s.scopes,"MDXLayout")&&o[0].components.push("MDXLayout"));let h=o[0];if(!(!h||!Ga(h.node,"_createMdxContent")&&!i)&&p.type==="JSXElement"){let g=p.openingElement.name;if(g.type==="JSXMemberExpression"){let m=[];for(;g.type==="JSXMemberExpression";)m.unshift(g.property.name),g=g.object;m.unshift(g.name);let v=m.join("."),S=g.name,N=_h(s.scopes,S);!Object.hasOwn(h.references,v)&&(!N||o.length===1&&o[0].node.type==="FunctionDeclaration"&&Ga(o[0].node,"_createMdxContent"))&&(h.references[v]={component:!0,node:p}),!h.objects.includes(S)&&!N&&h.objects.push(S)}else if(g.type!=="JSXNamespacedName"){if(Mt(g.name)&&!/^[a-z]/.test(g.name)){let m=g.name;_h(s.scopes,m)||(m!=="MDXLayout"&&!Object.hasOwn(h.references,m)&&(h.references[m]={component:!0,node:p}),h.components.includes(m)||h.components.push(m))}else if(!(p.data&&p.data._mdxExplicitJsx)){let m=g.name;h.tags.includes(m)||h.tags.push(m);let v=["_components",m];if(Mt(m)===!1){let S=h.idToInvalidComponentName.get(m);S===void 0&&(S=\`_component\${h.idToInvalidComponentName.size}\`,h.idToInvalidComponentName.set(m,S)),v=[S]}p.openingElement.name=Eh(v),p.closingElement&&(p.closingElement.name=Eh(v))}}}},leave(p){s.exit(p);let h=[],g=[],m=[],v=[];if(p.type==="FunctionDeclaration"||p.type==="FunctionExpression"||p.type==="ArrowFunctionExpression"){let S=o[o.length-1],N;for(N of S.tags.sort())h.push({type:"Property",kind:"init",key:Mt(N)?{type:"Identifier",name:N}:{type:"Literal",value:N},value:{type:"Literal",value:N},method:!1,shorthand:!1,computed:!1});g.push(...S.components);for(N of S.objects)g.includes(N)||g.push(N);g.sort();let y=[];if(h.length>0||g.length>0||S.idToInvalidComponentName.size>0){if(i&&(u=!0,m.push({type:"CallExpression",callee:{type:"Identifier",name:"_provideComponents"},arguments:[],optional:!1})),(Ga(S.node,"MDXContent")||Ga(S.node,"_createMdxContent"))&&m.push(Kn(["props","components"])),h.length>0||m.length>1)for(let A of m)h.push({type:"SpreadElement",argument:A});let M=h.length>0?{type:"ObjectExpression",properties:h}:{type:"LogicalExpression",operator:"||",left:m[0],right:{type:"ObjectExpression",properties:[]}},T;if(g.length>0&&(T={type:"ObjectPattern",properties:g.map(function(A){return{type:"Property",kind:"init",key:{type:"Identifier",name:A==="MDXLayout"?"wrapper":A},value:{type:"Identifier",name:A},method:!1,shorthand:A!=="MDXLayout",computed:!1}})}),S.tags.length>0&&(v.push({type:"VariableDeclarator",id:{type:"Identifier",name:"_components"},init:M}),M={type:"Identifier",name:"_components"}),Ga(S.node,"_createMdxContent"))for(let[A,L]of[...S.idToInvalidComponentName].sort(function([V],[D]){return V.localeCompare(D)}))v.push({type:"VariableDeclarator",id:{type:"Identifier",name:L},init:{type:"MemberExpression",object:{type:"Identifier",name:"_components"},property:{type:"Literal",value:A},computed:!0,optional:!1}});T&&v.push({type:"VariableDeclarator",id:T,init:M}),v.length>0&&y.push({type:"VariableDeclaration",kind:"const",declarations:v})}let w;for(w in S.references)if(Object.hasOwn(S.references,w)){let M=w.split("."),T=0;for(;++T<M.length;){let A=M.slice(0,T).join(".");Object.hasOwn(S.references,A)||(S.references[A]={component:!1,node:S.references[w].node})}}let k=Object.keys(S.references).sort(),d=-1;for(;++d<k.length;){let M=k[d],T=S.references[M],A=gt(Gt(T.node)),L=[{type:"Literal",value:M},{type:"Literal",value:T.component}];f=!0,t&&A&&L.push({type:"Literal",value:A}),y.push({type:"IfStatement",test:{type:"UnaryExpression",operator:"!",prefix:!0,argument:Kn(M.split("."))},consequent:{type:"ExpressionStatement",expression:{type:"CallExpression",callee:{type:"Identifier",name:"_missingMdxReference"},arguments:L,optional:!1}},alternate:void 0})}y.length>0&&(p.body.type!=="BlockStatement"&&(p.body={type:"BlockStatement",body:[{type:"ReturnStatement",argument:p.body}]}),p.body.body.unshift(...y)),o.pop()}}}),u&&i&&r.body.unshift(j6(i,n)),f){let p=[{type:"Literal",value:"Expected "},{type:"ConditionalExpression",test:{type:"Identifier",name:"component"},consequent:{type:"Literal",value:"component"},alternate:{type:"Literal",value:"object"}},{type:"Literal",value:" \`"},{type:"Identifier",name:"id"},{type:"Literal",value:"\` to be defined: you likely forgot to import, pass, or provide it."}],h=[{type:"Identifier",name:"id"},{type:"Identifier",name:"component"}];t&&(p.push({type:"ConditionalExpression",test:{type:"Identifier",name:"place"},consequent:Ch([{type:"Literal",value:"\\nIt\\u2019s referenced in your code at \`"},{type:"Identifier",name:"place"},{type:"Literal",value:(a.path?"\` in \`"+a.path:"")+"\`"}]),alternate:{type:"Literal",value:""}}),h.push({type:"Identifier",name:"place"})),r.body.push({type:"FunctionDeclaration",id:{type:"Identifier",name:"_missingMdxReference"},generator:!1,async:!1,params:h,body:{type:"BlockStatement",body:[{type:"ThrowStatement",argument:{type:"NewExpression",callee:{type:"Identifier",name:"Error"},arguments:[Ch(p)]}}]}})}n==="function-body"&&r.body.unshift({type:"ExpressionStatement",expression:{type:"Literal",value:"use strict"},directive:"use strict"})}}function j6(e,t){let n=[{type:"ImportSpecifier",imported:{type:"Identifier",name:"useMDXComponents"},local:{type:"Identifier",name:"_provideComponents"}}];return t==="function-body"?{type:"VariableDeclaration",kind:"const",declarations:Xa(n,Kn(["arguments",0]))}:{type:"ImportDeclaration",specifiers:n,attributes:[],source:{type:"Literal",value:e}}}function Ga(e,t){return!!(e&&"id"in e&&e.id&&e.id.name===t)}function _h(e,t){let n=e.length;for(;n--;)if(e[n].defined.includes(t))return!0;return!1}function Lb(){return function(e){Ai(e,"raw",function(t,n,i){if(i&&typeof n=="number")return i.children.splice(n,1),n})}}var P6=/\\s+/g,F6=/[\\t\\n\\v\\f\\r ]+/g;function Mb(e,t){t?typeof t=="string"&&(t={style:t}):t={};let n=t.preserveLineEndings?q6:H6;return String(e).replace(t.style==="html"?F6:P6,t.trim?J6(n):n)}function q6(e){let t=/\\r?\\n|\\r/.exec(e);return t?t[0]:" "}function H6(){return" "}function J6(e){return t;function t(n,i,r){return i===0||i+n.length===r.length?"":e(n)}}function Rb(){return function(e){Ai(e,function(t,n,i){let r=-1,a=!0,s=!1;if(i&&typeof n=="number"&&t.type==="paragraph"){let o=t.children;for(;++r<o.length;){let u=o[r];if(u.type==="mdxJsxTextElement"||u.type==="mdxTextExpression")s=!0;else if(!(u.type==="text"&&Mb(u.value,{style:"html",trim:!0})==="")){a=!1;break}}if(a&&s){r=-1;let u=[];for(;++r<o.length;){let f=o[r];f.type==="mdxJsxTextElement"&&(f.type="mdxJsxFlowElement"),f.type==="mdxTextExpression"&&(f.type="mdxFlowExpression"),f.type==="text"&&/^[\\t\\r\\n ]+$/.test(String(f.value))||u.push(f)}return i.children.splice(n,1,...u),n}}if(t.type==="mdxJsxFlowElement"||t.type==="mdxJsxTextElement"){let o=t.data||(t.data={});o._mdxExplicitJsx=!0}(t.type==="mdxFlowExpression"||t.type==="mdxTextExpression"||t.type==="mdxjsEsm")&&t.data&&t.data.estree&&ni(t.data.estree,{enter(o){if(o.type==="JSXElement"){let u=o.data||(o.data={});u._mdxExplicitJsx=!0}}})})}}var zb=["mdxFlowExpression","mdxJsxFlowElement","mdxJsxTextElement","mdxTextExpression","mdxjsEsm"];var Bb=["compilers","filepath","hastPlugins","mdPlugins","skipExport","wrapExport"],Vb=!1;function Ub(e){let t=e||{},n=-1;for(;++n<Bb.length;){let a=Bb[n];a in t&&(""+a,void 0)}t.format==="detect"&&void 0,(t.jsxRuntime==="classic"||t.pragma||t.pragmaFrag||t.pragmaImportSource)&&!Vb&&(Vb=!0,console.warn("Unexpected deprecated option \`jsxRuntime: 'classic'\`, \`pragma\`, \`pragmaFrag\`, or \`pragmaImportSource\`; see <https://mdxjs.com/migrating/v3/> on how to migrate"));let i=kh().use(Mu);t.format!=="md"&&i.use(Iu);let r=t.remarkRehypeOptions||{};return i.use(Rb).use(t.remarkPlugins||[]).use(qu,{...r,allowDangerousHtml:!0,passThrough:[...r.passThrough||[],...zb]}).use(t.rehypePlugins||[]),t.format==="md"&&i.use(Lb),i.use(lu,t).use(Ob,t).use(Ib,t),t.jsx||i.use(Qo,t).use(Tb,t),i.use($o).use(eu,t).use(t.recmaPlugins||[]),i}function jb(e,t){let{file:n,options:i}=G0(e,t);return Ub(i).process(n)}function Pb(e){let{Fragment:t,baseUrl:n,development:i,jsx:r,jsxDEV:a,jsxs:s,useMDXComponents:o,...u}=e||{};if(!t)throw new Error("Expected \`Fragment\` given to \`evaluate\`");if(i){if(!a)throw new Error("Expected \`jsxDEV\` given to \`evaluate\`")}else{if(!r)throw new Error("Expected \`jsx\` given to \`evaluate\`");if(!s)throw new Error("Expected \`jsxs\` given to \`evaluate\`")}return{compiletime:{...u,development:i,outputFormat:"function-body",providerImportSource:o?"#":void 0},runtime:{Fragment:t,baseUrl:n,jsx:r,jsxDEV:a,jsxs:s,useMDXComponents:o}}}var X6=Object.getPrototypeOf(Ah).constructor;async function Ah(e,t){return new X6(String(e))(t)}async function Th(e,t){let{compiletime:n,runtime:i}=Pb(t);return Ah(await jb(e,n),i)}var Zu={};tl(Zu,{AssetsClient:()=>_l,FanoutsClient:()=>Al,HealthClient:()=>Tl,PRAGMA_ENV_KEYS:()=>at,PragmaClient:()=>Yu,PragmaGatewayError:()=>Cl,PragmaTransportError:()=>si,PushClient:()=>Nl,ScratchpadsClient:()=>Dl,ThemeClient:()=>Ol,WhiteboardsClient:()=>Il,WorkspaceClient:()=>Ll,awaitAgentAnswer:()=>Kb,awaitAgentDecision:()=>Zb,base64ToBytes:()=>Qu,bytesToBase64:()=>zh,hasPragmaEnvironment:()=>Za,promptAgent:()=>h4,readEnv:()=>st,reportAttention:()=>Xb,reportCleared:()=>Gb,reportMessage:()=>Qb,reportSessionName:()=>Yb,reportStarted:()=>Hb,reportStopped:()=>Jb,runtimeAgentId:()=>Vh,scratchpadBridge:()=>p4});var at={gatewayUrl:"PRAGMA_GATEWAY_URL",gatewayToken:"PRAGMA_GATEWAY_TOKEN",tabId:"PRAGMA_TAB_ID",worktreeId:"PRAGMA_WORKTREE_ID"};function st(e,t){let n=globalThis.process;return t?.[e]??n?.env?.[e]}function Za(e){return!!(st(at.gatewayUrl,e)&&st(at.gatewayToken,e)&&st(at.tabId,e)&&st(at.worktreeId,e))}var ke={health:"/v1/health",version:"/v1/version",rpc:e=>\`/v1/rpc/\${encodeURIComponent(e)}\`,sessions:"/v1/sessions",sessionEvents:e=>\`/v1/sessions/\${encodeURIComponent(e)}/events\`,sessionInput:e=>\`/v1/sessions/\${encodeURIComponent(e)}/input\`,sessionResize:e=>\`/v1/sessions/\${encodeURIComponent(e)}/resize\`,session:e=>\`/v1/sessions/\${encodeURIComponent(e)}\`,agentReports:"/v1/agents/reports",agentMessages:"/v1/agents/messages",agentAnswers:"/v1/agents/answers",agentDecisions:"/v1/agents/decisions",agentInputs:"/v1/agents/inputs",agentInterrupts:"/v1/agents/interrupts",agentCatalog:"/v1/agents/catalog",agentEvents:"/v1/agents/events",asset:e=>\`/v1/assets/\${encodeURIComponent(e)}\`,theme:"/v1/theme",scratchpads:"/v1/scratchpads",agentsSeen:e=>\`/v1/tabs/\${encodeURIComponent(e)}/agents/seen\`,subscription:e=>\`/v1/subscriptions/\${encodeURIComponent(e)}\`,control:e=>\`/v1/control/\${encodeURIComponent(e)}\`,pushTokens:"/v1/push/tokens",pushTest:"/v1/push/test",pushPresence:"/v1/push/presence"},Cl=class extends Error{code;httpStatus;details;cause;constructor(t,n){super(t,{cause:n.cause}),this.name="PragmaGatewayError",this.code=n.code,this.httpStatus=n.httpStatus,this.details=n.details,this.cause=n.cause}},si=class extends Error{cause;constructor(t,n){super(t,{cause:n}),this.name="PragmaTransportError",this.cause=n}};async function*Rh(e,t){if(!e.body)throw new si("gateway response is not streamable");let n=e.body.getReader(),i=new TextDecoder,r="",a=()=>{n.cancel()};t?.addEventListener("abort",a,{once:!0});try{for(;;){if(t?.aborted)return;let{done:s,value:o}=await n.read();if(s)break;r+=i.decode(o,{stream:!0});let u=r.indexOf(\`
119
119
  \`);for(;u>=0;){let f=r.slice(0,u).trim();r=r.slice(u+1),f&&(yield JSON.parse(f)),u=r.indexOf(\`
120
120
  \`)}}r+=i.decode(),r.trim()&&(yield JSON.parse(r))}finally{t?.removeEventListener("abort",a),await n.cancel().catch(()=>{})}}var ra=class{baseUrl;token;fetch;headers;constructor(t={}){let{baseUrl:n,token:i}=G6(t);this.baseUrl=n,this.token=i,this.fetch=Y6(t.fetch),this.headers=t.headers??{}}async request(t,n={}){let i=await this.raw(t,n);if(!(i.status===204||i.status===202))return Z6(i)}async raw(t,n={}){let i={...this.headers,...n.headers,authorization:\`Bearer \${this.token}\`},r;n.rawBody?r=n.rawBody:n.body!==void 0&&(i["content-type"]=i["content-type"]??"application/json",r=JSON.stringify(n.body));let a;try{a=await this.fetch(Q6(this.baseUrl,t),{method:n.method??(r?"POST":"GET"),headers:i,body:r,signal:n.signal})}catch(s){throw new si("failed to reach Pragma gateway",s)}if(!a.ok)throw await K6(a);return a}};function G6(e){let t=qb(e.baseUrl??st(at.gatewayUrl)??""),n=e.token??st(at.gatewayToken)??"";if(!t||!n)throw new si("Pragma gateway baseUrl and token are required");return{baseUrl:t,token:n}}function Y6(e){let t=e??globalThis.fetch?.bind(globalThis);if(!t)throw new si("global fetch is not available");return t}function Q6(e,t){return\`\${qb(e)}\${t.startsWith("/")?t:\`/\${t}\`}\`}async function Z6(e){try{return await e.json()}catch(t){throw new si("gateway returned non-JSON response",t)}}async function K6(e){let t={};try{t=await e.json()}catch(n){throw new si("gateway returned non-JSON error response",n)}return new Cl(t.message??\`gateway returned \${e.status}\`,{code:t.code??"internal",httpStatus:e.status,details:t.details})}function qb(e){return e.replace(/\\/+$/,"")}var aa=class{transport;constructor(t){this.transport=t}report(t,n={}){return this.transport.request(ke.agentReports,{method:"POST",body:t,signal:n.signal})}reportMessage(t,n={}){return this.transport.request(ke.agentMessages,{method:"POST",body:t,signal:n.signal})}reportDecision(t,n={}){return this.transport.request(ke.agentDecisions,{method:"POST",body:t,signal:n.signal})}reportAnswer(t,n={}){return this.transport.request(ke.agentAnswers,{method:"POST",body:t,signal:n.signal})}reportInput(t,n={}){return this.transport.request(ke.agentInputs,{method:"POST",body:t,signal:n.signal})}reportInterrupt(t,n={}){return this.transport.request(ke.agentInterrupts,{method:"POST",body:t,signal:n.signal})}reportStarted(t){return Ya(this,t,"running",null)}reportStopped(t){return Ya(this,t,"done",null)}reportAttention(t){return Ya(this,t,"attention",t.kind??"question")}reportCleared(t){return Ya(this,t,"cleared",null)}reportSessionName(t){return Ya(this,t,null,null,t.name)}catalog(t={}){return this.transport.request(ke.agentCatalog,{method:"GET",signal:t.signal})}launch(t,n={}){return this.transport.request(ke.control("agentSessionLaunch"),{method:"POST",body:t,signal:n.signal})}markAgentsSeen(t,n={}){return this.transport.request(ke.agentsSeen(t.tabId),{method:"POST",body:{},signal:n.signal})}async connect(t){let{agent:n,tabId:i,worktreeId:r}=t,a=new AbortController,s=()=>a.abort();t.signal?.addEventListener("abort",s);let o=this.readStream.bind(this);async function*u(){try{for await(let p of o({signal:a.signal}))W6(p,n,i)&&(yield p)}finally{t.signal?.removeEventListener("abort",s)}}let f={[Symbol.asyncIterator]:u,send:(p,h={})=>this.reportInput({agent:n,worktreeId:r,tabId:i,text:p,...h.requestId?{requestId:h.requestId}:{}},{signal:a.signal}),answer:(p,h)=>this.reportAnswer({agent:n,worktreeId:r,tabId:i,requestId:p,dismissed:h===null,...h!==null?{answer:h}:{}},{signal:a.signal}),decide:(p,h)=>this.reportDecision({agent:n,worktreeId:r,tabId:i,requestId:p,approved:h},{signal:a.signal}),interrupt:p=>this.reportInterrupt({agent:n,worktreeId:r,tabId:i,...p?{requestId:p}:{}},{signal:a.signal}),close:()=>a.abort()};return t.prompt!==void 0&&await f.send(t.prompt),f}async*readStream(t={}){let n=await this.transport.raw(ke.agentEvents,{signal:t.signal});yield*Rh(n,t.signal)}async awaitDecision(t){let n=new AbortController,i=()=>n.abort();t.signal?.addEventListener("abort",i);let r=t.timeoutMs&&t.timeoutMs>0?setTimeout(()=>n.abort(),t.timeoutMs):void 0;try{for await(let a of this.readStream({signal:n.signal}))if(a.type==="agentDecision"&&a.decision.requestId===t.requestId&&a.decision.agent===t.agent)return a.decision.approved;return null}catch{return null}finally{r&&clearTimeout(r),t.signal?.removeEventListener("abort",i)}}async awaitAnswer(t){let n=new AbortController,i=()=>n.abort();t.signal?.addEventListener("abort",i);let r=t.timeoutMs&&t.timeoutMs>0?setTimeout(()=>n.abort(),t.timeoutMs):void 0;try{for await(let a of this.readStream({signal:n.signal}))if(a.type==="agentAnswer"&&a.answer.requestId===t.requestId&&a.answer.agent===t.agent)return a.answer.dismissed?null:a.answer.answer??"";return null}catch{return null}finally{r&&clearTimeout(r),t.signal?.removeEventListener("abort",i)}}};function W6(e,t,n){switch(e.type){case"agent":return e.agent===t&&e.tabId===n;case"agentMessage":return e.message.agent===t&&e.message.tabId===n;case"agentDecision":return e.decision.agent===t&&e.decision.tabId===n;case"agentAnswer":return e.answer.agent===t&&e.answer.tabId===n;case"agentInput":return e.input.agent===t&&e.input.tabId===n;case"agentInterrupt":return e.interrupt.agent===t&&e.interrupt.tabId===n}}function Hb(e){return Ml(e,"running",null)}function Jb(e){return Ml(e,"done",null)}function Xb(e){return Ml(e,"attention",e.kind??"question")}function Gb(e){return Ml(e,"cleared",null)}function Yb(e){return Ml(e,null,null,e.name)}async function Qb(e){if(!e.client&&!Za(e.env))return;let t=e.client?.agents??new aa(new ra({baseUrl:st(at.gatewayUrl,e.env),token:st(at.gatewayToken,e.env)}));await e4(t,e)}async function Zb(e){return!e.client&&!Za(e.env)?null:(e.client?.agents??new aa(new ra({baseUrl:st(at.gatewayUrl,e.env),token:st(at.gatewayToken,e.env)}))).awaitDecision({agent:e.agent,requestId:e.requestId,timeoutMs:e.timeoutMs,signal:e.signal})}async function Kb(e){return!e.client&&!Za(e.env)?null:(e.client?.agents??new aa(new ra({baseUrl:st(at.gatewayUrl,e.env),token:st(at.gatewayToken,e.env)}))).awaitAnswer({agent:e.agent,requestId:e.requestId,timeoutMs:e.timeoutMs,signal:e.signal})}async function Ml(e,t,n,i){if(!e.client&&!Za(e.env))return;let r=e.client?.agents??new aa(new ra({baseUrl:st(at.gatewayUrl,e.env),token:st(at.gatewayToken,e.env)}));await Ya(r,e,t,n,i)}async function Ya(e,t,n,i,r){let a=t.worktreeId??st(at.worktreeId,t.env),s=st(at.tabId,t.env);!a||!s||await e.report($6(t,{worktreeId:a,tabId:s},n,i,r),{signal:t.signal})}function $6(e,t,n,i,r){return{agent:e.agent,worktreeId:t.worktreeId,tabId:t.tabId,status:n,attentionKind:i,...r?{sessionName:r}:{},...e.command?{command:e.command}:{},...e.question?{question:e.question}:{},...e.options&&e.options.length>0?{options:e.options}:{},...e.questions&&e.questions.length>0?{questions:e.questions}:{},...e.requestId?{requestId:e.requestId}:{}}}async function e4(e,t){let n=t.message.worktreeId??t.worktreeId??st(at.worktreeId,t.env),i=t.message.tabId??st(at.tabId,t.env);!n||!i||await e.reportMessage({...t.message,agent:t.message.agent??t.agent,worktreeId:n,tabId:i},{signal:t.signal})}var El="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function zh(e){let t="";for(let n=0;n<e.length;n+=3){let i=e[n]??0,r=e[n+1]??0,a=e[n+2]??0;t+=El[i>>2],t+=El[(i&3)<<4|r>>4],t+=n+1<e.length?El[(r&15)<<2|a>>6]:"=",t+=n+2<e.length?El[a&63]:"="}return t}function Qu(e){let t=e.replace(/\\s/g,"");if(t.length%4!==0)throw new TypeError("invalid base64 length");let n=[];for(let i=0;i<t.length;i+=4){let r=[t[i],t[i+1],t[i+2],t[i+3]],a=r.map(p=>p==="="?0:El.indexOf(p??""));if(a.some(p=>p<0))throw new TypeError("invalid base64 character");let s=a[0]??0,o=a[1]??0,u=a[2]??0,f=a[3]??0;n.push(s<<2|o>>4),r[2]!=="="&&n.push((o&15)<<4|u>>2),r[3]!=="="&&n.push((u&3)<<6|f)}return new Uint8Array(n)}var _l=class{transport;constructor(t){this.transport=t}async fetch(t,n={}){let i=await this.transport.raw(ke.asset(t),{signal:n.signal}),r=i.headers.get("content-type")??"application/octet-stream";return{bytes:new Uint8Array(await i.arrayBuffer()),mime:r}}async toDataUri(t,n={}){let{bytes:i,mime:r}=await this.fetch(t,n);return\`data:\${r};base64,\${zh(i)}\`}},Nh=class{transport;constructor(t){this.transport=t}async*subscribe(t,n={}){let i=new URLSearchParams;n.cursor&&i.set("cursor",n.cursor),n.worktreeId&&i.set("worktreeId",n.worktreeId),n.cwd&&i.set("cwd",n.cwd);let r=i.toString()?\`?\${i}\`:"",a=await this.transport.raw(\`\${ke.subscription(t)}\${r}\`,{signal:n.signal});for await(let s of Rh(a,n.signal))(s.type==="snapshot"||s.type==="delta")&&(yield s)}},Dh=class{transport;constructor(t){this.transport=t}run(t){return this.transport.request(ke.rpc("exec"),{body:{...t,env:t.env??[],maxConcurrent:t.maxConcurrent??1}})}},Al=class{transport;events;constructor(t,n){this.transport=t,this.events=n}create(t,n={}){return this.rpc("create",t,n)}get(t,n={}){return this.rpc("get",t,n)}async read(t,n={}){let i=await this.rpc("read",t,n);return{fanoutId:i.fanoutId,targets:i.targets.map(({data:r,...a})=>({...a,raw:Qu(r)}))}}send(t,n={}){return this.rpc("send",t,n)}retry(t,n={}){return this.rpc("retry",t,n)}cancel(t,n={}){return this.rpc("cancel",t,n)}pick(t,n={}){return this.rpc("pick",t,n)}async*subscribe(t={}){for await(let n of this.events.subscribe("fanouts",{signal:t.signal})){let i=this.narrow(n);if(!t.fanoutId){yield i;continue}yield{...i,payload:{fanouts:i.payload.fanouts.filter(r=>r.id===t.fanoutId)}}}}narrow(t){return{type:t.type,subscription:t.subscription,payload:t.payload??{fanouts:[]}}}rpc(t,n,i){return this.transport.request(ke.rpc("fanouts"),{method:"POST",body:{action:t,...n},signal:i.signal})}},Oh=class{transport;constructor(t){this.transport=t}listDir(t){return this.rpc("listDir",t)}createFile(t){return this.rpc("createFile",t)}createFolder(t){return this.rpc("createFolder",t)}pathExists(t){return this.rpc("pathExists",t)}readFile(t){return this.rpc("readFile",t)}writeFile(t){return this.rpc("writeFile",t)}rename(t){return this.rpc("rename",t)}delete(t){return this.rpc("delete",t)}rpc(t,n){return this.transport.request(ke.rpc("filesystem"),{body:{op:t,...n}})}},Ih=class{transport;constructor(t){this.transport=t}worktreeChanges(t){return this.rpc("worktreeChanges",t)}mergedStatus(t){return this.rpc("mergedStatus",t)}fileDiff(t){return this.rpc("fileDiff",t)}discardUnstagedFile(t){return this.rpc("discardUnstagedFile",t)}discardAllUnstaged(t){return this.rpc("discardAllUnstaged",t)}stageFile(t){return this.rpc("stageFile",t)}stageAll(t){return this.rpc("stageAll",t)}unstageFile(t){return this.rpc("unstageFile",t)}unstageAll(t){return this.rpc("unstageAll",t)}commitStaged(t){return this.rpc("commitStaged",t)}mergeWorktreeToParent(t){return this.rpc("mergeWorktreeToParent",t)}prFileDiff(t){return this.rpc("prFileDiff",t)}githubRepoInfo(t){return this.rpc("githubRepoInfo",t)}githubDefaultPrTitle(t){return this.rpc("githubDefaultPrTitle",t)}githubFetchAndSync(t){return this.rpc("githubFetchAndSync",t)}githubPullBranch(t){return this.rpc("githubPullBranch",t)}githubSyncBranch(t){return this.rpc("githubSyncBranch",t)}githubPushBranch(t){return this.rpc("githubPushBranch",t)}githubDeleteRemoteBranch(t){return this.rpc("githubDeleteRemoteBranch",t)}ensurePragmaExcluded(t){return this.rpc("ensurePragmaExcluded",t)}createWorktree(t){return this.rpc("createWorktree",t)}removeWorktree(t){return this.rpc("removeWorktree",t)}deleteBranch(t){return this.rpc("deleteBranch",t)}isDirty(t){return this.rpc("isDirty",t)}rpc(t,n){return this.transport.request(ke.rpc("git"),{body:{op:t,...n}})}},Tl=class{transport;constructor(t){this.transport=t}check(t={}){return this.transport.request(ke.health,{signal:t.signal})}},Nl=class{transport;constructor(t){this.transport=t}register(t,n={}){return this.transport.request(ke.pushTokens,{method:"POST",body:t,signal:n.signal})}unregister(t={}){return this.transport.request(ke.pushTokens,{method:"DELETE",body:{},signal:t.signal})}list(t={}){return this.transport.request(ke.pushTokens,{method:"GET",signal:t.signal})}test(t={}){return this.transport.request(ke.pushTest,{method:"POST",body:{},signal:t.signal})}presence(t,n={}){return this.transport.request(ke.pushPresence,{method:"POST",body:t,signal:n.signal})}};function Wb(e,t){if(typeof e!="object"||e===null)return!1;let n=e;return Object.entries(t).every(([i,r])=>r(n[i]))}var ia=e=>typeof e=="string",Qa=e=>typeof e=="number";function Lh(e){return t=>t===null||e(t)}function Fb(e){return\`\${e}.comments.json\`}function t4(e){let t=JSON.parse(e);if(!Array.isArray(t))throw new Error("Scratchpad comments must be an array.");return t.filter(r4)}function n4(e){return\`\${JSON.stringify(e,null,2)}
121
- \`}function i4(e,t,n,i){return{id:i,from:0,to:0,quote:e.quote,text:t.trim(),createdAt:n,resolvedAt:null,blockIndex:e.index}}function r4(e){return Wb(e,{id:ia,from:Qa,to:Qa,quote:ia,text:ia,createdAt:Qa,resolvedAt:Lh(Qa)})}var a4={daemon:{protocolVersion:"0.1.0",socketFile:"daemon.sock",lockFile:"server.lock",logFile:"server.log"},gateway:{apiVersion:"0.0.0",discoveryFile:"gateway.json",tokenFile:"gateway-token",devicesFile:"gateway-devices.json",tokenHeader:"authorization",deviceHeaders:{id:"x-pragma-device-id",name:"x-pragma-device-name",platform:"x-pragma-device-platform",appVersion:"x-pragma-app-version"},push:{sendUrl:"https://exp.host/--/api/v2/push/send",batchSize:100,presenceTtlMs:9e4,tokenPrefixes:["ExponentPushToken[","ExpoPushToken["]},web:{enabled:!1,basePath:"/web",manifestFile:"manifest.json",resourceDir:"web"}},platform:{defaultBackend:"native",shells:{macos:"/bin/zsh",linux:"/bin/sh",windows:["pwsh.exe","powershell.exe"]},wsl:{launcher:"wsl.exe",listArgs:["--list","--verbose"],serverBinary:"pragma-server"}},tunnel:{defaultCommand:"ngrok http {port} --log stdout --log-format json",defaultUrlPattern:'(https://[^\\\\s"]+)'},plugins:{configFileName:".pragma/config.json",storageScopes:["global","project"]},theme:{fileName:".pragma/theme.json",modes:["light","dark"]},keybindings:{configFileName:".pragma/keybindings.json"},bench:{hookGlobal:"__PRAGMA_BENCH__",runnerGlobal:"__PRAGMA_BENCH_RUNNER__",markerPrefix:"PRAGMABENCH",tabTitle:"pragma-bench"},agentStatus:{soundsDirName:".pragma/assets/sounds",maxSoundSeconds:5,maxSoundBytes:5242880,soundExtensions:["mp3","wav","ogg","oga","m4a","aac","flac","webm"],notificationsEnabled:!0,notificationText:{doneTitle:"{agent} finished",attentionTitle:"{agent} needs attention",questionTitle:"{agent} is waiting for an answer",commandTitle:"{agent} wants to run a command",locationSeparator:" / ",tabSuffix:' \\xB7 tab "{tab}"',unknownLocation:"Open Pragma to continue."}},terminalDefaults:{hiddenDistros:["docker-desktop","docker-desktop-data"],rememberLastShell:!1,maxDroppedFileBytes:10485760,droppedFilesDirName:"pragma-dropped-files",droppedFilesMaxAgeMs:864e5},tabs:{defaultTitles:{fallback:"Shell",browser:"New tab",log:"Server Logs",scratchpad:"Scratchpad",whiteboard:"Whiteboard",prReview:"PR Review",pluginWebview:"Plugin"}},files:{chunkBytes:4194304,maxBinaryBytes:268435456},fanout:{stateFile:"fanouts.json",branchPrefix:"fanout",minMembers:2,defaultJobs:4,deliveryTimeoutMs:15e3,envFanoutId:"PRAGMA_FANOUT_ID",envMemberId:"PRAGMA_FANOUT_MEMBER_ID"},scratchpads:{directory:".pragma/scratchpads",extension:"mdx",frontmatterKey:"pragmaScratchpad",version:1},whiteboards:{databaseFile:"whiteboards.db",defaultTitle:"Whiteboard",maxTitleChars:200,maxSceneBytes:8388608,maxRenderDimension:4096},protocol:{rpcMethods:["git","filesystem","database","kanban","worktrees","projects","tabs","settings","github","ai","exec","automations","plugins","tunnel","scratchpads","whiteboards","wsl","fanouts"],events:["agentStatus","worktreeChanged","kanbanChanged","tabsChanged","fileChanged","echoMode","automationPending","automationsChanged","workspace","fanouts"],errors:["invalidPayload","unsupportedMethod","notFound","staleWrite","permissionDenied","internal"]},scripts:{maxConcurrentCommands:4,configPath:".pragma/scripts.json",migrationSources:[{id:"superset",label:"Superset",configPaths:[".superset/config.json"]},{id:"emdash",label:"Emdash",configPaths:[".emdash.json"]},{id:"orca",label:"Orca",configPaths:["orca.yaml","orca.yml",".orca/config.json"]}],migrationCommitMessage:"chore(config): add pragma-app.sh config"},agents:{startDelayMs:500,altScreenExtraWaitMs:15e3,altScreenSettleMs:500},github:{oauthClientId:"Ov23li1WfY05SeQNp5tk",scopes:["repo"],deviceCodeUrl:"https://github.com/login/device/code",deviceVerifyUrl:"https://github.com/login/device",accessTokenUrl:"https://github.com/login/oauth/access_token",apiBaseUrl:"https://api.github.com",homepageUrl:"https://github.com/pragma-sh/pragma",prSignature:{enabled:!0,startMarker:"<!-- pragma:pr-signature -->",endMarker:"<!-- /pragma:pr-signature -->",linkLabel:"Open worktree in Pragma",openUrl:"https://pragma-app.sh/open"}},app:{name:"Pragma",identifier:"com.pragma.app",version:"0.1.0"},onboarding:{mediaBaseUrl:"https://pragma-app.sh/media",skill:{id:"pragma",targets:[{id:"all-agents",directory:".agents/skills",label:"All agents"},{id:"claude-code",directory:".claude/skills",label:"Claude Code"}]}},updates:{checkUrl:"https://pragma-app.sh/api/updates",devCheckUrl:"http://localhost:3000/api/updates",pollIntervalMs:3e5,autoDownload:!0,manifestFile:"release.json",uiDirName:"ui",buttonLabel:"Install Update",changelogLabel:"View changelog",restartWarningTitle:"This update restarts the app server",restartWarningBody:"Open terminal sessions will stop. Save anything you need before installing.",applyModes:["reload","restart"],platforms:["darwin-aarch64","darwin-x86_64","linux-x86_64-deb","linux-x86_64-rpm","linux-x86_64-appimage","linux-aarch64-deb","linux-aarch64-rpm","linux-aarch64-appimage","windows-x86_64"]},window:{defaultWidth:1024,defaultHeight:768,minWidth:640,minHeight:480,titlebarHeight:38,trafficLightInset:12},editorLaunchers:{defaultEditorId:"system",options:[{id:"system",name:"File Explorer",brandIcon:"lucide:folder-open",brandColor:"#38bdf8",cliCommand:null},{id:"vscode",name:"VS Code",brandIcon:"simple-icons:visualstudiocode",brandColor:"#007acc",cliCommand:"code"},{id:"cursor",name:"Cursor",brandIcon:"simple-icons:cursor",brandColor:"#ffffff",cliCommand:"cursor"},{id:"windsurf",name:"Windsurf",brandIcon:"simple-icons:windsurf",brandColor:"#00c7be",cliCommand:"windsurf"},{id:"zed",name:"Zed",brandIcon:"simple-icons:zedindustries",brandColor:"#084ccf",cliCommand:"zed"},{id:"sublime-text",name:"Sublime Text",brandIcon:"simple-icons:sublimetext",brandColor:"#ff9800",cliCommand:"subl"},{id:"intellij-idea",name:"IntelliJ IDEA",brandIcon:"simple-icons:intellijidea",brandColor:"#ff2d8f",cliCommand:"idea"}]}},Bh=a4,s4=/^---\\r?\\n([\\s\\S]*?)\\r?\\n---(?:\\r?\\n)?/;function $b(e){let t=s4.exec(e);if(!t)throw new Error("This MDX file is not a managed Pragma scratchpad.");return{metadata:o4(l4(t[1]??"")),body:e.slice(t[0].length),frontmatter:t[0]}}function l4(e){let t=Bh.scratchpads.frontmatterKey,n=e.split(/\\r?\\n/).find(i=>i.startsWith(\`\${t}: \`));if(!n)throw new Error("Scratchpad frontmatter is missing managed metadata.");return n.slice(t.length+2)}function o4(e){let t=JSON.parse(e);if(!c4(t)||t.version!==Bh.scratchpads.version)throw new Error("Scratchpad metadata is invalid or uses an unsupported version.");return t}function u4(e,t){let n=$b(e),i={...n.metadata,agentTabId:t.tabId,agentId:t.agentId},r=Bh.scratchpads.frontmatterKey,a=\`\${r}: \${JSON.stringify(i)}\`,s=n.frontmatter.split(/\\r?\\n/),o=s.findIndex(u=>u.startsWith(\`\${r}: \`));if(o<0)throw new Error("Scratchpad frontmatter is missing managed metadata.");return s[o]=a,\`\${s.join(\`
121
+ \`}function i4(e,t,n,i){return{id:i,from:0,to:0,quote:e.quote,text:t.trim(),createdAt:n,resolvedAt:null,blockIndex:e.index}}function r4(e){return Wb(e,{id:ia,from:Qa,to:Qa,quote:ia,text:ia,createdAt:Qa,resolvedAt:Lh(Qa)})}var a4={daemon:{protocolVersion:"0.3.0",socketFile:"daemon.sock",lockFile:"server.lock",logFile:"server.log"},gateway:{apiVersion:"0.0.0",discoveryFile:"gateway.json",tokenFile:"gateway-token",devicesFile:"gateway-devices.json",tokenHeader:"authorization",deviceHeaders:{id:"x-pragma-device-id",name:"x-pragma-device-name",platform:"x-pragma-device-platform",appVersion:"x-pragma-app-version"},push:{sendUrl:"https://exp.host/--/api/v2/push/send",batchSize:100,presenceTtlMs:9e4,tokenPrefixes:["ExponentPushToken[","ExpoPushToken["]},web:{enabled:!1,basePath:"/web",manifestFile:"manifest.json",resourceDir:"web"}},platform:{defaultBackend:"native",shells:{macos:"/bin/zsh",linux:"/bin/sh",windows:["pwsh.exe","powershell.exe"]},wsl:{launcher:"wsl.exe",listArgs:["--list","--verbose"],serverBinary:"pragma-server"}},tunnel:{defaultCommand:"ngrok http {port} --log stdout --log-format json",defaultUrlPattern:'(https://[^\\\\s"]+)'},plugins:{configFileName:".pragma/config.json",storageScopes:["global","project"]},theme:{fileName:".pragma/theme.json",modes:["light","dark"]},keybindings:{configFileName:".pragma/keybindings.json"},bench:{hookGlobal:"__PRAGMA_BENCH__",runnerGlobal:"__PRAGMA_BENCH_RUNNER__",markerPrefix:"PRAGMABENCH",tabTitle:"pragma-bench"},agentStatus:{soundsDirName:".pragma/assets/sounds",maxSoundSeconds:5,maxSoundBytes:5242880,soundExtensions:["mp3","wav","ogg","oga","m4a","aac","flac","webm"],notificationsEnabled:!0,notificationText:{doneTitle:"{agent} finished",attentionTitle:"{agent} needs attention",questionTitle:"{agent} is waiting for an answer",commandTitle:"{agent} wants to run a command",locationSeparator:" / ",tabSuffix:' \\xB7 tab "{tab}"',unknownLocation:"Open Pragma to continue."}},terminalDefaults:{hiddenDistros:["docker-desktop","docker-desktop-data"],rememberLastShell:!1,maxDroppedFileBytes:10485760,droppedFilesDirName:"pragma-dropped-files",droppedFilesMaxAgeMs:864e5},tabs:{defaultTitles:{fallback:"Shell",browser:"New tab",log:"Server Logs",scratchpad:"Scratchpad",whiteboard:"Whiteboard",prReview:"PR Review",pluginWebview:"Plugin"}},files:{chunkBytes:4194304,maxBinaryBytes:268435456},fanout:{stateFile:"fanouts.json",branchPrefix:"fanout",minMembers:2,defaultJobs:4,deliveryTimeoutMs:15e3,envFanoutId:"PRAGMA_FANOUT_ID",envMemberId:"PRAGMA_FANOUT_MEMBER_ID"},scratchpads:{directory:".pragma/scratchpads",extension:"mdx",frontmatterKey:"pragmaScratchpad",version:1},whiteboards:{databaseFile:"whiteboards.db",defaultTitle:"Whiteboard",maxTitleChars:200,maxSceneBytes:8388608,maxRenderDimension:4096},protocol:{rpcMethods:["git","filesystem","database","kanban","worktrees","projects","tabs","settings","github","ai","exec","automations","plugins","tunnel","scratchpads","whiteboards","wsl","fanouts"],events:["agentStatus","worktreeChanged","kanbanChanged","tabsChanged","fileChanged","echoMode","automationPending","automationsChanged","workspace","fanouts"],errors:["invalidPayload","unsupportedMethod","notFound","staleWrite","permissionDenied","internal"]},scripts:{maxConcurrentCommands:4,configPath:".pragma/scripts.json",migrationSources:[{id:"superset",label:"Superset",configPaths:[".superset/config.json"]},{id:"emdash",label:"Emdash",configPaths:[".emdash.json"]},{id:"orca",label:"Orca",configPaths:["orca.yaml","orca.yml",".orca/config.json"]}],migrationCommitMessage:"chore(config): add pragma-app.sh config"},agents:{startDelayMs:500,altScreenExtraWaitMs:15e3,altScreenSettleMs:500},github:{oauthClientId:"Ov23li1WfY05SeQNp5tk",scopes:["repo"],deviceCodeUrl:"https://github.com/login/device/code",deviceVerifyUrl:"https://github.com/login/device",accessTokenUrl:"https://github.com/login/oauth/access_token",apiBaseUrl:"https://api.github.com",homepageUrl:"https://github.com/pragma-sh/pragma",prSignature:{enabled:!0,startMarker:"<!-- pragma:pr-signature -->",endMarker:"<!-- /pragma:pr-signature -->",linkLabel:"Open worktree in Pragma",openUrl:"https://pragma-app.sh/open"}},app:{name:"Pragma",identifier:"com.pragma.app",version:"0.3.0"},onboarding:{mediaBaseUrl:"https://pragma-app.sh/media",skill:{id:"pragma",targets:[{id:"all-agents",directory:".agents/skills",label:"All agents"},{id:"claude-code",directory:".claude/skills",label:"Claude Code"}]}},updates:{checkUrl:"https://pragma-app.sh/api/updates",devCheckUrl:"http://localhost:3000/api/updates",pollIntervalMs:3e5,autoDownload:!0,manifestFile:"release.json",uiDirName:"ui",buttonLabel:"Install Update",changelogLabel:"View changelog",restartWarningTitle:"This update restarts the app server",restartWarningBody:"Open terminal sessions will stop. Save anything you need before installing.",applyModes:["reload","restart"],platforms:["darwin-aarch64","darwin-x86_64","linux-x86_64-deb","linux-x86_64-rpm","linux-x86_64-appimage","linux-aarch64-deb","linux-aarch64-rpm","linux-aarch64-appimage","windows-x86_64"]},window:{defaultWidth:1024,defaultHeight:768,minWidth:640,minHeight:480,titlebarHeight:38,trafficLightInset:12},editorLaunchers:{defaultEditorId:"system",options:[{id:"system",name:"File Explorer",brandIcon:"lucide:folder-open",brandColor:"#38bdf8",cliCommand:null},{id:"vscode",name:"VS Code",brandIcon:"simple-icons:visualstudiocode",brandColor:"#007acc",cliCommand:"code"},{id:"cursor",name:"Cursor",brandIcon:"simple-icons:cursor",brandColor:"#ffffff",cliCommand:"cursor"},{id:"windsurf",name:"Windsurf",brandIcon:"simple-icons:windsurf",brandColor:"#00c7be",cliCommand:"windsurf"},{id:"zed",name:"Zed",brandIcon:"simple-icons:zedindustries",brandColor:"#084ccf",cliCommand:"zed"},{id:"sublime-text",name:"Sublime Text",brandIcon:"simple-icons:sublimetext",brandColor:"#ff9800",cliCommand:"subl"},{id:"intellij-idea",name:"IntelliJ IDEA",brandIcon:"simple-icons:intellijidea",brandColor:"#ff2d8f",cliCommand:"idea"}]}},Bh=a4,s4=/^---\\r?\\n([\\s\\S]*?)\\r?\\n---(?:\\r?\\n)?/;function $b(e){let t=s4.exec(e);if(!t)throw new Error("This MDX file is not a managed Pragma scratchpad.");return{metadata:o4(l4(t[1]??"")),body:e.slice(t[0].length),frontmatter:t[0]}}function l4(e){let t=Bh.scratchpads.frontmatterKey,n=e.split(/\\r?\\n/).find(i=>i.startsWith(\`\${t}: \`));if(!n)throw new Error("Scratchpad frontmatter is missing managed metadata.");return n.slice(t.length+2)}function o4(e){let t=JSON.parse(e);if(!c4(t)||t.version!==Bh.scratchpads.version)throw new Error("Scratchpad metadata is invalid or uses an unsupported version.");return t}function u4(e,t){let n=$b(e),i={...n.metadata,agentTabId:t.tabId,agentId:t.agentId},r=Bh.scratchpads.frontmatterKey,a=\`\${r}: \${JSON.stringify(i)}\`,s=n.frontmatter.split(/\\r?\\n/),o=s.findIndex(u=>u.startsWith(\`\${r}: \`));if(o<0)throw new Error("Scratchpad frontmatter is missing managed metadata.");return s[o]=a,\`\${s.join(\`
122
122
  \`)}\${n.body}\`}function c4(e){return Wb(e,{version:Qa,id:ia,title:ia,agentTabId:Lh(ia),agentId:Lh(ia),createdAt:Qa})}var Dl=class{transport;fs;agents;constructor(t,n,i){this.transport=t,this.fs=n,this.agents=i}getScratchpads(t){let n=\`?root=\${encodeURIComponent(t.root)}\`;return this.transport.request(\`\${ke.scratchpads}\${n}\`,{signal:t.signal})}async getComments(t){let n=Fb(t.filePath),{root:i}=t;if(!await this.fs.pathExists({root:i,path:n}))return[];let r=await this.fs.readFile({root:i,path:n});return r.binary||r.truncated?[]:t4(r.text)}async comment(t){let{root:n,filePath:i,block:r,text:a}=t,s=i4(r,a,t.createdAt??Date.now(),t.id??f4()),o=await this.getComments({root:n,filePath:i});return await this.writeComments({root:n,filePath:i},[...o,s]),s}async setComments(t,n){await this.writeComments(t,n)}async attachAgent(t){let{root:n,filePath:i,tabId:r,agentId:a}=t,s=t.contents??await this.readScratchpad(n,i);await this.fs.writeFile({root:n,path:i,contents:u4(s,{tabId:r,agentId:a})})}async sendAttached(t){let{root:n,filePath:i,worktreeId:r,text:a}=t,s=t.contents??await this.readScratchpad(n,i),{metadata:o}=$b(s);if(!o.agentTabId||!o.agentId)return{delivered:!1};let u=Vh(o.agentId);return await this.agents.reportInput({agent:u,worktreeId:r,tabId:o.agentTabId,text:a},{signal:t.signal}),{delivered:!0,agent:u,tabId:o.agentTabId}}async readScratchpad(t,n){let i=await this.fs.readFile({root:t,path:n});if(i.binary)throw new Error(\`Scratchpad \${n} is not text.\`);if(i.truncated)throw new Error(\`Scratchpad \${n} was truncated by the host.\`);return i.text}writeComments(t,n){return this.fs.writeFile({root:t.root,path:Fb(t.filePath),contents:n4(n)})}};function Vh(e){return e.split(".").at(-1)??e}function f4(){return\`\${Date.now().toString(36)}-\${Math.random().toString(36).slice(2,10)}\`}var Mh=class{transport;constructor(t){this.transport=t}spawn(t,n={}){return this.transport.request(ke.sessions,{method:"POST",body:t,signal:n.signal})}async*attach(t,n={}){let i=await this.transport.raw(ke.sessionEvents(t),{signal:n.signal});yield*Rh(i,n.signal)}write(t,n,i={}){return this.transport.request(ke.sessionInput(t),{method:"POST",rawBody:n,headers:{"content-type":"application/octet-stream"},signal:i.signal})}resize(t,n,i={}){return this.transport.request(ke.sessionResize(t),{method:"POST",body:n,signal:i.signal})}kill(t,n={}){return this.transport.request(ke.session(t),{method:"DELETE",signal:n.signal})}rename(t,n){return this.transport.request(ke.control("tabRename"),{method:"POST",body:{tabId:t,title:n}})}killForCwd(t,n={}){return this.transport.request(\`\${ke.sessions}?cwd=\${encodeURIComponent(t)}\`,{method:"DELETE",signal:n.signal})}},Ol=class{transport;constructor(t){this.transport=t}get(t={}){let n=t.root?\`?root=\${encodeURIComponent(t.root)}\`:"";return this.transport.request(\`\${ke.theme}\${n}\`,{signal:t.signal})}},Il=class{transport;constructor(t){this.transport=t}create(t){return this.rpc("create",t)}get(t){return this.rpc("get",t)}list(t){return this.rpc("list",t)}search(t){return this.rpc("list",t)}edit(t){return this.rpc("edit",t)}async delete(t){await this.rpc("delete",t)}async view(t){let n=await this.rpc("view",t);return Qu(n.data)}rpc(t,n){return this.transport.request(ke.rpc("whiteboards"),{method:"POST",body:{action:t,...n}})}},Ll=class{events;constructor(t){this.events=t}async*subscribe(t={}){for await(let n of this.events.subscribe("workspace",t))yield this.narrow(n)}narrow(t){return{type:t.type,subscription:t.subscription,payload:t.payload??{projects:[],worktrees:[],tabs:[]}}}},Yu=class{fs;git;exec;sessions;agents;assets;events;workspace;fanouts;push;theme;health;scratchpads;whiteboards;transport;constructor(t={}){this.transport=new ra(t),this.fs=new Oh(this.transport),this.git=new Ih(this.transport),this.exec=new Dh(this.transport),this.sessions=new Mh(this.transport),this.agents=new aa(this.transport),this.assets=new _l(this.transport),this.events=new Nh(this.transport),this.workspace=new Ll(this.events),this.fanouts=new Al(this.transport,this.events),this.push=new Nl(this.transport),this.theme=new Ol(this.transport),this.health=new Tl(this.transport),this.scratchpads=new Dl(this.transport,this.fs,this.agents),this.whiteboards=new Il(this.transport)}rpc(t,n,i={}){return this.transport.request(ke.rpc(t),{method:"POST",body:n,signal:i.signal})}createBoardDraft(t,n={}){return this.transport.request(ke.control("boardDraftCreate"),{method:"POST",body:t,signal:n.signal})}};function ev(){let e=globalThis.pragmaScratchpad;if(!e)throw new Error("@pragma-sh/scratchpad can only prompt agents inside a Pragma scratchpad");return e}function p4(){return ev()}async function h4(e,t={}){let n=e.trim();if(!n)return!1;let i=ev(),r=await i.promptAgent(n);if(r==="sent")return!0;if(r==="cancelled")return!1;let a=()=>i.requestAgentAttachment(),s=await t.onMissingAgent?.({text:n,attach:a});if(!(t.onMissingAgent?s===!0:await a()))return!1;let u=await i.promptAgent(n);if(u==="sent")return!0;if(u==="cancelled")return!1;throw new Error("Selected agent tab is no longer available")}var Wu={};tl(Wu,{Badge:()=>k4,Button:()=>y4,Card:()=>w4,Input:()=>b4,Progress:()=>S4,Textarea:()=>v4});var la=qt(sa(),1),rv="pragma-scratchpad-styles",g4=\`
123
123
  .pragma-card {
124
124
  display: grid;
package/dist/index.js CHANGED
@@ -61,7 +61,7 @@ Defaulting to 2020, but this will stop working in the future.\`)),t.ecmaVersion=
61
61
  \`},r)),a}function qu(e,t){return e&&"run"in e?async function(n,i){let r=Fu(n,{file:i,...t});await e.run(r,i)}:function(n,i){return Fu(n,{file:i,...e||t})}}function xh(e){if(e)throw e}var Xu=qt(kb(),1);function wl(e){if(typeof e!="object"||e===null)return!1;let t=Object.getPrototypeOf(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)}function yh(){let e=[],t={run:n,use:i};return t;function n(...r){let a=-1,s=r.pop();if(typeof s!="function")throw new TypeError("Expected function as last argument, not "+s);o(null,...r);function o(u,...f){let p=e[++a],h=-1;if(u){s(u);return}for(;++h<r.length;)(f[h]===null||f[h]===void 0)&&(f[h]=r[h]);r=f,p?Eb(p,o)(...f):s(null,...f)}}function i(r){if(typeof r!="function")throw new TypeError("Expected \`middelware\` to be a function, not "+r);return e.push(r),t}}function Eb(e,t){let n;return i;function i(...s){let o=e.length>s.length,u;o&&s.push(r);try{u=e.apply(this,s)}catch(f){let p=f;if(o&&n)throw p;return r(p)}o||(u&&u.then&&typeof u.then=="function"?u.then(a,r):u instanceof Error?r(u):a(u))}function r(s,...o){n||(n=!0,t(s,...o))}function a(s){r(null,s)}}var Cb=(function(e){let i=this.constructor.prototype,r=i[e],a=function(){return r.apply(a,arguments)};return Object.setPrototypeOf(a,i),a});var M6={}.hasOwnProperty,wh=class e extends Cb{constructor(){super("copy"),this.Compiler=void 0,this.Parser=void 0,this.attachers=[],this.compiler=void 0,this.freezeIndex=-1,this.frozen=void 0,this.namespace={},this.parser=void 0,this.transformers=yh()}copy(){let t=new e,n=-1;for(;++n<this.attachers.length;){let i=this.attachers[n];t.use(...i)}return t.data((0,Xu.default)(!0,{},this.namespace)),t}data(t,n){return typeof t=="string"?arguments.length===2?(Sh("data",this.frozen),this.namespace[t]=n,this):M6.call(this.namespace,t)&&this.namespace[t]||void 0:t?(Sh("data",this.frozen),this.namespace=t,this):this.namespace}freeze(){if(this.frozen)return this;let t=this;for(;++this.freezeIndex<this.attachers.length;){let[n,...i]=this.attachers[this.freezeIndex];if(i[0]===!1)continue;i[0]===!0&&(i[0]=void 0);let r=n.call(t,...i);typeof r=="function"&&this.transformers.use(r)}return this.frozen=!0,this.freezeIndex=Number.POSITIVE_INFINITY,this}parse(t){this.freeze();let n=Ju(t),i=this.parser||this.Parser;return bh("parse",i),i(String(n),n)}process(t,n){let i=this;return this.freeze(),bh("process",this.parser||this.Parser),vh("process",this.compiler||this.Compiler),n?r(void 0,n):new Promise(r);function r(a,s){let o=Ju(t),u=i.parse(o);i.run(u,o,function(p,h,g){if(p||!h||!g)return f(p);let m=h,v=i.stringify(m,g);z6(v)?g.value=v:g.result=v,f(p,g)});function f(p,h){p||!h?s(p):a?a(h):n(void 0,h)}}}processSync(t){let n=!1,i;return this.freeze(),bh("processSync",this.parser||this.Parser),vh("processSync",this.compiler||this.Compiler),this.process(t,r),Ab("processSync","process",n),i;function r(a,s){n=!0,xh(a),i=s}}run(t,n,i){_b(t),this.freeze();let r=this.transformers;return!i&&typeof n=="function"&&(i=n,n=void 0),i?a(void 0,i):new Promise(a);function a(s,o){let u=Ju(n);r.run(t,u,f);function f(p,h,g){let m=h||t;p?o(p):s?s(m):i(void 0,m,g)}}}runSync(t,n){let i=!1,r;return this.run(t,n,a),Ab("runSync","run",i),r;function a(s,o){xh(s),r=o,i=!0}}stringify(t,n){this.freeze();let i=Ju(n),r=this.compiler||this.Compiler;return vh("stringify",r),_b(t),r(t,i)}use(t,...n){let i=this.attachers,r=this.namespace;if(Sh("use",this.frozen),t!=null)if(typeof t=="function")u(t,n);else if(typeof t=="object")Array.isArray(t)?o(t):s(t);else throw new TypeError("Expected usable value, not \`"+t+"\`");return this;function a(f){if(typeof f=="function")u(f,[]);else if(typeof f=="object")if(Array.isArray(f)){let[p,...h]=f;u(p,h)}else s(f);else throw new TypeError("Expected usable value, not \`"+f+"\`")}function s(f){if(!("plugins"in f)&&!("settings"in f))throw new Error("Expected usable value but received an empty preset, which is probably a mistake: presets typically come with \`plugins\` and sometimes with \`settings\`, but this has neither");o(f.plugins),f.settings&&(r.settings=(0,Xu.default)(!0,r.settings,f.settings))}function o(f){let p=-1;if(f!=null)if(Array.isArray(f))for(;++p<f.length;){let h=f[p];a(h)}else throw new TypeError("Expected a list of plugins, not \`"+f+"\`")}function u(f,p){let h=-1,g=-1;for(;++h<i.length;)if(i[h][0]===f){g=h;break}if(g===-1)i.push([f,...p]);else if(p.length>0){let[m,...v]=p,S=i[g][1];wl(S)&&wl(m)&&(m=(0,Xu.default)(!0,S,m)),i[g]=[f,m,...v]}}}},kh=new wh().freeze();function bh(e,t){if(typeof t!="function")throw new TypeError("Cannot \`"+e+"\` without \`parser\`")}function vh(e,t){if(typeof t!="function")throw new TypeError("Cannot \`"+e+"\` without \`compiler\`")}function Sh(e,t){if(t)throw new Error("Cannot call \`"+e+"\` on a frozen processor.\\nCreate a new processor first, by calling it: use \`processor()\` instead of \`processor\`.")}function _b(e){if(!wl(e)||typeof e.type!="string")throw new TypeError("Expected node, got \`"+e+"\`")}function Ab(e,t,n){if(!n)throw new Error("\`"+e+"\` finished async. Use \`"+t+"\` instead")}function Ju(e){return R6(e)?e:new Pr(e)}function R6(e){return!!(e&&typeof e=="object"&&"message"in e&&"messages"in e)}function z6(e){return typeof e=="string"||B6(e)}function B6(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}function ai(e,t){let n=["start","end","loc","range"],i=-1;for(;++i<n.length;){let r=n[i];r in e&&(t[r]=e[r])}}function Xa(e,t){let n=-1,i=[],r=[],a;for(;++n<e.length;){let s=e[n];s.type==="ImportNamespaceSpecifier"?a=s:r.push(s)}if(a){let s={type:"VariableDeclarator",id:a.local,init:t};ai(a,s),i.push(s)}return i.push({type:"VariableDeclarator",id:{type:"ObjectPattern",properties:r.map(function(s){let o=s.type==="ImportSpecifier"?s.imported:s.type==="ExportSpecifier"?s.exported:{type:"Identifier",name:"default"},u=s.local;s.type==="ExportSpecifier"&&(u=o,o=s.local),u.type;let f={type:"Property",kind:"init",shorthand:o.type==="Identifier"&&u.type==="Identifier"&&o.name===u.name,method:!1,computed:!1,key:o,value:u};return ai(s,f),f})},init:a?{type:"Identifier",name:a.local.name}:t}),i}function Kn(e){let t=-1,n;for(;++t<e.length;){let i=e[t],r=typeof i=="string"&&Mt(i)?{type:"Identifier",name:i}:{type:"Literal",value:i};n=n?{type:"MemberExpression",object:n,property:r,computed:r.type==="Literal",optional:!1}:r}return n.type,n}function Eh(e){let t=-1,n;for(;++t<e.length;){let i=e[t];typeof i=="string"&&Mt(i,{jsx:!0}),""+i;let r={type:"JSXIdentifier",name:i};n=n?{type:"JSXMemberExpression",object:n,property:r}:r}return n}function Tb(e){let{outputFormat:t}=e||{};return function(n){if(n.comments&&(n.comments=n.comments.filter(function(i){return!i.data?._mdxIsPragmaComment})),t==="function-body"){let i=0;for(;i<n.body.length;){let a=n.body[i];if("directive"in a&&a.directive)i++;else break}let r=n.body[i];r&&r.type==="ImportDeclaration"&&typeof r.source.value=="string"&&/\\/jsx-(dev-)?runtime$/.test(r.source.value)&&(n.body[i]={type:"VariableDeclaration",kind:"const",declarations:Xa(r.specifiers,Kn(["arguments",0]))})}}}function kl(){let e=[{block:!1,defined:[]}];return{enter:t,exit:n,scopes:e};function t(a){if(a.type==="ArrowFunctionExpression"){e.push({block:!1,defined:[]});for(let s of a.params)r(s,!1)}else if(a.type==="BlockStatement"||a.type==="DoWhileStatement"||a.type==="ForInStatement"||a.type==="ForOfStatement"||a.type==="ForStatement"||a.type==="WhileStatement")e.push({block:!0,defined:[]});else if(a.type==="CatchClause")e.push({block:!0,defined:[]}),a.param&&r(a.param,!0);else if(a.type==="ClassDeclaration")i(a.id.name,!1);else if(a.type==="FunctionDeclaration"){a.id&&i(a.id.name,!1),e.push({block:!1,defined:[]});for(let s of a.params)r(s,!1)}else if(a.type==="FunctionExpression"){a.id&&i(a.id.name,!1),e.push({block:!1,defined:[]});for(let s of a.params)r(s,!1)}else if(a.type==="ImportDeclaration")for(let s of a.specifiers)i(s.local.name,!1);else if(a.type==="VariableDeclaration")for(let s of a.declarations)r(s.id,a.kind!=="var")}function n(a){if(a.type==="ArrowFunctionExpression"||a.type==="FunctionDeclaration"||a.type==="FunctionExpression"){let s=e.pop();s.block}else if(a.type==="BlockStatement"||a.type==="CatchClause"||a.type==="DoWhileStatement"||a.type==="ForInStatement"||a.type==="ForOfStatement"||a.type==="ForStatement"||a.type==="WhileStatement"){let s=e.pop();s.block}}function i(a,s){let o=e.length,u;for(;o--&&(u=e[o],!(s||!u.block)););u.defined.push(a)}function r(a,s){if(a.type==="ArrayPattern")for(let o of a.elements)o&&r(o,s);else if(a.type==="AssignmentPattern")r(a.left,s);else if(a.type==="Identifier")i(a.name,s);else if(a.type==="ObjectPattern")for(let o of a.properties)o.type==="Property"?r(o.value,s):(o.type,r(o,s));else a.type,r(a.argument,s)}}function Nb(e){return e.type==="FunctionDeclaration"?{...e,type:"FunctionExpression"}:(e.type,{...e,type:"ClassExpression"})}function Db(e){return e.type==="FunctionDeclaration"||e.type==="ClassDeclaration"||e.type==="VariableDeclaration"}function Ob(e){let t=e.baseUrl||void 0,n=typeof t=="object"?t.href:t,i=e.outputFormat||"program",r=e.pragma===void 0?"React.createElement":e.pragma,a=e.pragmaFrag===void 0?"React.Fragment":e.pragmaFrag,s=e.pragmaImportSource||"react",o=e.jsxImportSource||"react",u=e.jsxRuntime||"automatic";return function(p,h){let g=[],m=[],v=0,S,N,y;if(u==="classic"&&a&&Gu(p,"@jsxFrag",a),u==="classic"&&r&&Gu(p,"@jsx",r),u==="automatic"&&o&&Gu(p,"@jsxImportSource",o),u&&Gu(p,"@jsxRuntime",u),u==="classic"&&s){if(!r)throw new Error("Missing \`pragma\` in classic runtime with \`pragmaImportSource\`");M({type:"ImportDeclaration",specifiers:[{type:"ImportDefaultSpecifier",local:{type:"Identifier",name:r.split(".")[0]}}],attributes:[],source:{type:"Literal",value:s}})}for(y of p.body)if(y.type==="ExportDefaultDeclaration")S&&h.fail("Unexpected duplicate layout, expected a single layout (previous: "+gt(Gt(S))+")",{ancestors:[p,y],place:Gt(y),ruleId:"duplicate-layout",source:"recma-document"}),S=y,m.push({type:"VariableDeclaration",kind:"const",declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:"MDXLayout"},init:Db(y.declaration)?Nb(y.declaration):y.declaration}]});else if(y.type==="ExportNamedDeclaration"&&y.source){let T=y.source;y.specifiers=y.specifiers.filter(function(A){if(A.exported.type==="Identifier"&&A.exported.name==="default"){S&&h.fail("Unexpected duplicate layout, expected a single layout (previous: "+gt(Gt(S))+")",{ancestors:[p,y,A],place:Gt(y),ruleId:"duplicate-layout",source:"recma-document"}),S=A;let L=[];if(A.local.type==="Identifier"&&A.local.name==="default")L.push({type:"ImportDefaultSpecifier",local:{type:"Identifier",name:"MDXLayout"}});else{let ee={type:"ImportSpecifier",imported:A.local,local:{type:"Identifier",name:"MDXLayout"}};ai(A.local,ee),L.push(ee)}let V={type:"Literal",value:T.value};ai(T,V);let D={type:"ImportDeclaration",specifiers:L,attributes:[],source:V};return ai(A,D),M(D),!1}return!0}),y.specifiers.length>0&&d(y)}else y.type==="ExportNamedDeclaration"||y.type==="ExportAllDeclaration"?d(y):y.type==="ImportDeclaration"?M(y):y.type==="ExpressionStatement"&&(y.expression.type==="JSXElement"||y.expression.type==="JSXFragment")?(N=!0,m.push(...f(y.expression,i,!!S))):m.push(y);N||m.push(...f(void 0,i,!!S)),g.push(["MDXContent","default"]),i==="function-body"&&m.push({type:"ReturnStatement",argument:{type:"ObjectExpression",properties:[...Array.from({length:v}).map(function(T,A){return{type:"SpreadElement",argument:{type:"Identifier",name:"_exportAll"+(A+1)}}}),...g.map(function(T){return{type:"Property",kind:"init",method:!1,computed:!1,shorthand:typeof T=="string",key:{type:"Identifier",name:typeof T=="string"?T:T[1]},value:{type:"Identifier",name:typeof T=="string"?T:T[0]}}})]}}),p.body=m;let w=!1,k=!1;(n||i==="function-body")&&ni(p,{enter(T){if((T.type==="ExportAllDeclaration"||T.type==="ExportNamedDeclaration"||T.type==="ImportDeclaration")&&T.source){let A=T.source.value;try{new URL(A)}catch{(A.startsWith("/")||A.startsWith("./")||A.startsWith("../"))&&(A=new URL(A,n).href)}let L={type:"Literal",value:A};ai(T.source,L),T.source=L;return}if(T.type==="ImportExpression"){k=!0;let A={type:"CallExpression",callee:{type:"Identifier",name:"_resolveDynamicMdxSpecifier"},arguments:[T.source],optional:!1};T.source=A;return}if(T.type==="MemberExpression"&&"object"in T&&T.object.type==="MetaProperty"&&T.property.type==="Identifier"&&T.object.meta.name==="import"&&T.object.property.name==="meta"&&T.property.name==="url"){w=!0;let A={type:"Identifier",name:"_importMetaUrl"};ai(T,A),this.replace(A)}}}),k&&(n||(w=!0),p.body.push(V6(n?{type:"Literal",value:n}:{type:"Identifier",name:"_importMetaUrl"}))),w&&p.body.unshift(...U6());function d(T){if(T.type==="ExportNamedDeclaration"){if(T.declaration){let A=kl();ni(T,{enter(L){A.enter(L),(L.type==="ArrowFunctionExpression"||L.type==="FunctionDeclaration"||L.type==="FunctionExpression")&&(this.skip(),A.exit(L))},leave:A.exit}),g.push(...A.scopes[0].defined)}for(y of T.specifiers)y.exported.type==="Identifier"?g.push(y.exported.name):(y.exported.value,g.push(y.exported.value))}M(T)}function M(T){let A,L;if(i==="function-body")if(T.type==="ImportDeclaration"||T.type==="ExportAllDeclaration"||T.type==="ExportNamedDeclaration"&&T.source){T.source;let V={type:"ImportExpression",source:T.source};ai(T,V),L={type:"AwaitExpression",argument:V},(T.type==="ImportDeclaration"||T.type==="ExportNamedDeclaration")&&T.specifiers.length===0?A={type:"ExpressionStatement",expression:L}:A={type:"VariableDeclaration",kind:"const",declarations:T.type==="ExportAllDeclaration"?[{type:"VariableDeclarator",id:{type:"Identifier",name:"_exportAll"+ ++v},init:L}]:Xa(T.specifiers,L)}}else if(T.declaration)A=T.declaration;else{let V=[];for(let D of T.specifiers)D.exported.type==="Identifier"&&D.local.type==="Identifier"&&D.local.name!==D.exported.name&&V.push({type:"VariableDeclarator",id:D.exported,init:D.local});V.length>0&&(A={type:"VariableDeclaration",kind:"const",declarations:V})}else A=T;A&&m.push(A)}};function f(p,h,g){let v={type:"JSXElement",openingElement:{type:"JSXOpeningElement",name:{type:"JSXIdentifier",name:"MDXLayout"},attributes:[{type:"JSXSpreadAttribute",argument:{type:"Identifier",name:"props"}}],selfClosing:!1},closingElement:{type:"JSXClosingElement",name:{type:"JSXIdentifier",name:"MDXLayout"}},children:[{type:"JSXElement",openingElement:{type:"JSXOpeningElement",name:{type:"JSXIdentifier",name:"_createMdxContent"},attributes:[{type:"JSXSpreadAttribute",argument:{type:"Identifier",name:"props"}}],selfClosing:!0},closingElement:null,children:[]}]};g||(v={type:"ConditionalExpression",test:{type:"Identifier",name:"MDXLayout"},consequent:v,alternate:{type:"CallExpression",callee:{type:"Identifier",name:"_createMdxContent"},arguments:[{type:"Identifier",name:"props"}],optional:!1}});let S=p||{type:"Identifier",name:"undefined"};S.type==="JSXFragment"&&S.children.length===1&&S.children[0].type==="JSXElement"&&(S=S.children[0]);let N=!1;ni(S,{enter(w){if(w.type==="ArrowFunctionExpression"||w.type==="FunctionDeclaration"||w.type==="FunctionExpression")return this.skip();(w.type==="AwaitExpression"||w.type==="ForOfStatement"&&w.await)&&(N=!0)}});let y={type:"FunctionDeclaration",id:{type:"Identifier",name:"MDXContent"},params:[{type:"AssignmentPattern",left:{type:"Identifier",name:"props"},right:{type:"ObjectExpression",properties:[]}}],body:{type:"BlockStatement",body:[{type:"ReturnStatement",argument:v}]}};return[{type:"FunctionDeclaration",async:N,id:{type:"Identifier",name:"_createMdxContent"},params:[{type:"Identifier",name:"props"}],body:{type:"BlockStatement",body:[{type:"ReturnStatement",argument:S}]}},h==="program"?{type:"ExportDefaultDeclaration",declaration:y}:y]}}function Gu(e,t,n){e.comments?.unshift({type:"Block",value:t+" "+n,data:{_mdxIsPragmaComment:!0}})}function V6(e){return{type:"FunctionDeclaration",id:{type:"Identifier",name:"_resolveDynamicMdxSpecifier"},generator:!1,async:!1,params:[{type:"Identifier",name:"d"}],body:{type:"BlockStatement",body:[{type:"IfStatement",test:{type:"BinaryExpression",left:{type:"UnaryExpression",operator:"typeof",prefix:!0,argument:{type:"Identifier",name:"d"}},operator:"!==",right:{type:"Literal",value:"string"}},consequent:{type:"ReturnStatement",argument:{type:"Identifier",name:"d"}},alternate:null},{type:"TryStatement",block:{type:"BlockStatement",body:[{type:"ExpressionStatement",expression:{type:"NewExpression",callee:{type:"Identifier",name:"URL"},arguments:[{type:"Identifier",name:"d"}]}},{type:"ReturnStatement",argument:{type:"Identifier",name:"d"}}]},handler:{type:"CatchClause",param:null,body:{type:"BlockStatement",body:[]}},finalizer:null},{type:"IfStatement",test:{type:"LogicalExpression",left:{type:"LogicalExpression",left:{type:"CallExpression",callee:Kn(["d","startsWith"]),arguments:[{type:"Literal",value:"/"}],optional:!1},operator:"||",right:{type:"CallExpression",callee:Kn(["d","startsWith"]),arguments:[{type:"Literal",value:"./"}],optional:!1}},operator:"||",right:{type:"CallExpression",callee:Kn(["d","startsWith"]),arguments:[{type:"Literal",value:"../"}],optional:!1}},consequent:{type:"ReturnStatement",argument:{type:"MemberExpression",object:{type:"NewExpression",callee:{type:"Identifier",name:"URL"},arguments:[{type:"Identifier",name:"d"},e]},property:{type:"Identifier",name:"href"},computed:!1,optional:!1}},alternate:null},{type:"ReturnStatement",argument:{type:"Identifier",name:"d"}}]}}}function U6(){return[{type:"VariableDeclaration",declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:"_importMetaUrl"},init:Kn(["arguments",0,"baseUrl"])}],kind:"const"},{type:"IfStatement",test:{type:"UnaryExpression",operator:"!",prefix:!0,argument:{type:"Identifier",name:"_importMetaUrl"}},consequent:{type:"ThrowStatement",argument:{type:"NewExpression",callee:{type:"Identifier",name:"Error"},arguments:[{type:"Literal",value:"Unexpected missing \`options.baseUrl\` needed to support \`export \\u2026 from\`, \`import\`, or \`import.meta.url\` when generating \`function-body\`"}]}},alternate:null}]}function Ch(e){let t=-1,n;for(;++t<e.length;){let i=e[t];n=n?{type:"BinaryExpression",left:n,operator:"+",right:i}:i}return n}function Ib(e){let{development:t,outputFormat:n,providerImportSource:i}=e;return function(r,a){let s=kl(),o=[],u=!1,f=!1;if(ni(r,{enter(p){s.enter(p),(p.type==="FunctionDeclaration"||p.type==="FunctionExpression"||p.type==="ArrowFunctionExpression")&&(o.push({components:[],idToInvalidComponentName:new Map,node:p,objects:[],references:{},tags:[]}),Ga(p,"MDXContent")&&!_h(s.scopes,"MDXLayout")&&o[0].components.push("MDXLayout"));let h=o[0];if(!(!h||!Ga(h.node,"_createMdxContent")&&!i)&&p.type==="JSXElement"){let g=p.openingElement.name;if(g.type==="JSXMemberExpression"){let m=[];for(;g.type==="JSXMemberExpression";)m.unshift(g.property.name),g=g.object;m.unshift(g.name);let v=m.join("."),S=g.name,N=_h(s.scopes,S);!Object.hasOwn(h.references,v)&&(!N||o.length===1&&o[0].node.type==="FunctionDeclaration"&&Ga(o[0].node,"_createMdxContent"))&&(h.references[v]={component:!0,node:p}),!h.objects.includes(S)&&!N&&h.objects.push(S)}else if(g.type!=="JSXNamespacedName"){if(Mt(g.name)&&!/^[a-z]/.test(g.name)){let m=g.name;_h(s.scopes,m)||(m!=="MDXLayout"&&!Object.hasOwn(h.references,m)&&(h.references[m]={component:!0,node:p}),h.components.includes(m)||h.components.push(m))}else if(!(p.data&&p.data._mdxExplicitJsx)){let m=g.name;h.tags.includes(m)||h.tags.push(m);let v=["_components",m];if(Mt(m)===!1){let S=h.idToInvalidComponentName.get(m);S===void 0&&(S=\`_component\${h.idToInvalidComponentName.size}\`,h.idToInvalidComponentName.set(m,S)),v=[S]}p.openingElement.name=Eh(v),p.closingElement&&(p.closingElement.name=Eh(v))}}}},leave(p){s.exit(p);let h=[],g=[],m=[],v=[];if(p.type==="FunctionDeclaration"||p.type==="FunctionExpression"||p.type==="ArrowFunctionExpression"){let S=o[o.length-1],N;for(N of S.tags.sort())h.push({type:"Property",kind:"init",key:Mt(N)?{type:"Identifier",name:N}:{type:"Literal",value:N},value:{type:"Literal",value:N},method:!1,shorthand:!1,computed:!1});g.push(...S.components);for(N of S.objects)g.includes(N)||g.push(N);g.sort();let y=[];if(h.length>0||g.length>0||S.idToInvalidComponentName.size>0){if(i&&(u=!0,m.push({type:"CallExpression",callee:{type:"Identifier",name:"_provideComponents"},arguments:[],optional:!1})),(Ga(S.node,"MDXContent")||Ga(S.node,"_createMdxContent"))&&m.push(Kn(["props","components"])),h.length>0||m.length>1)for(let A of m)h.push({type:"SpreadElement",argument:A});let M=h.length>0?{type:"ObjectExpression",properties:h}:{type:"LogicalExpression",operator:"||",left:m[0],right:{type:"ObjectExpression",properties:[]}},T;if(g.length>0&&(T={type:"ObjectPattern",properties:g.map(function(A){return{type:"Property",kind:"init",key:{type:"Identifier",name:A==="MDXLayout"?"wrapper":A},value:{type:"Identifier",name:A},method:!1,shorthand:A!=="MDXLayout",computed:!1}})}),S.tags.length>0&&(v.push({type:"VariableDeclarator",id:{type:"Identifier",name:"_components"},init:M}),M={type:"Identifier",name:"_components"}),Ga(S.node,"_createMdxContent"))for(let[A,L]of[...S.idToInvalidComponentName].sort(function([V],[D]){return V.localeCompare(D)}))v.push({type:"VariableDeclarator",id:{type:"Identifier",name:L},init:{type:"MemberExpression",object:{type:"Identifier",name:"_components"},property:{type:"Literal",value:A},computed:!0,optional:!1}});T&&v.push({type:"VariableDeclarator",id:T,init:M}),v.length>0&&y.push({type:"VariableDeclaration",kind:"const",declarations:v})}let w;for(w in S.references)if(Object.hasOwn(S.references,w)){let M=w.split("."),T=0;for(;++T<M.length;){let A=M.slice(0,T).join(".");Object.hasOwn(S.references,A)||(S.references[A]={component:!1,node:S.references[w].node})}}let k=Object.keys(S.references).sort(),d=-1;for(;++d<k.length;){let M=k[d],T=S.references[M],A=gt(Gt(T.node)),L=[{type:"Literal",value:M},{type:"Literal",value:T.component}];f=!0,t&&A&&L.push({type:"Literal",value:A}),y.push({type:"IfStatement",test:{type:"UnaryExpression",operator:"!",prefix:!0,argument:Kn(M.split("."))},consequent:{type:"ExpressionStatement",expression:{type:"CallExpression",callee:{type:"Identifier",name:"_missingMdxReference"},arguments:L,optional:!1}},alternate:void 0})}y.length>0&&(p.body.type!=="BlockStatement"&&(p.body={type:"BlockStatement",body:[{type:"ReturnStatement",argument:p.body}]}),p.body.body.unshift(...y)),o.pop()}}}),u&&i&&r.body.unshift(j6(i,n)),f){let p=[{type:"Literal",value:"Expected "},{type:"ConditionalExpression",test:{type:"Identifier",name:"component"},consequent:{type:"Literal",value:"component"},alternate:{type:"Literal",value:"object"}},{type:"Literal",value:" \`"},{type:"Identifier",name:"id"},{type:"Literal",value:"\` to be defined: you likely forgot to import, pass, or provide it."}],h=[{type:"Identifier",name:"id"},{type:"Identifier",name:"component"}];t&&(p.push({type:"ConditionalExpression",test:{type:"Identifier",name:"place"},consequent:Ch([{type:"Literal",value:"\\nIt\\u2019s referenced in your code at \`"},{type:"Identifier",name:"place"},{type:"Literal",value:(a.path?"\` in \`"+a.path:"")+"\`"}]),alternate:{type:"Literal",value:""}}),h.push({type:"Identifier",name:"place"})),r.body.push({type:"FunctionDeclaration",id:{type:"Identifier",name:"_missingMdxReference"},generator:!1,async:!1,params:h,body:{type:"BlockStatement",body:[{type:"ThrowStatement",argument:{type:"NewExpression",callee:{type:"Identifier",name:"Error"},arguments:[Ch(p)]}}]}})}n==="function-body"&&r.body.unshift({type:"ExpressionStatement",expression:{type:"Literal",value:"use strict"},directive:"use strict"})}}function j6(e,t){let n=[{type:"ImportSpecifier",imported:{type:"Identifier",name:"useMDXComponents"},local:{type:"Identifier",name:"_provideComponents"}}];return t==="function-body"?{type:"VariableDeclaration",kind:"const",declarations:Xa(n,Kn(["arguments",0]))}:{type:"ImportDeclaration",specifiers:n,attributes:[],source:{type:"Literal",value:e}}}function Ga(e,t){return!!(e&&"id"in e&&e.id&&e.id.name===t)}function _h(e,t){let n=e.length;for(;n--;)if(e[n].defined.includes(t))return!0;return!1}function Lb(){return function(e){Ai(e,"raw",function(t,n,i){if(i&&typeof n=="number")return i.children.splice(n,1),n})}}var P6=/\\s+/g,F6=/[\\t\\n\\v\\f\\r ]+/g;function Mb(e,t){t?typeof t=="string"&&(t={style:t}):t={};let n=t.preserveLineEndings?q6:H6;return String(e).replace(t.style==="html"?F6:P6,t.trim?J6(n):n)}function q6(e){let t=/\\r?\\n|\\r/.exec(e);return t?t[0]:" "}function H6(){return" "}function J6(e){return t;function t(n,i,r){return i===0||i+n.length===r.length?"":e(n)}}function Rb(){return function(e){Ai(e,function(t,n,i){let r=-1,a=!0,s=!1;if(i&&typeof n=="number"&&t.type==="paragraph"){let o=t.children;for(;++r<o.length;){let u=o[r];if(u.type==="mdxJsxTextElement"||u.type==="mdxTextExpression")s=!0;else if(!(u.type==="text"&&Mb(u.value,{style:"html",trim:!0})==="")){a=!1;break}}if(a&&s){r=-1;let u=[];for(;++r<o.length;){let f=o[r];f.type==="mdxJsxTextElement"&&(f.type="mdxJsxFlowElement"),f.type==="mdxTextExpression"&&(f.type="mdxFlowExpression"),f.type==="text"&&/^[\\t\\r\\n ]+$/.test(String(f.value))||u.push(f)}return i.children.splice(n,1,...u),n}}if(t.type==="mdxJsxFlowElement"||t.type==="mdxJsxTextElement"){let o=t.data||(t.data={});o._mdxExplicitJsx=!0}(t.type==="mdxFlowExpression"||t.type==="mdxTextExpression"||t.type==="mdxjsEsm")&&t.data&&t.data.estree&&ni(t.data.estree,{enter(o){if(o.type==="JSXElement"){let u=o.data||(o.data={});u._mdxExplicitJsx=!0}}})})}}var zb=["mdxFlowExpression","mdxJsxFlowElement","mdxJsxTextElement","mdxTextExpression","mdxjsEsm"];var Bb=["compilers","filepath","hastPlugins","mdPlugins","skipExport","wrapExport"],Vb=!1;function Ub(e){let t=e||{},n=-1;for(;++n<Bb.length;){let a=Bb[n];a in t&&(""+a,void 0)}t.format==="detect"&&void 0,(t.jsxRuntime==="classic"||t.pragma||t.pragmaFrag||t.pragmaImportSource)&&!Vb&&(Vb=!0,console.warn("Unexpected deprecated option \`jsxRuntime: 'classic'\`, \`pragma\`, \`pragmaFrag\`, or \`pragmaImportSource\`; see <https://mdxjs.com/migrating/v3/> on how to migrate"));let i=kh().use(Mu);t.format!=="md"&&i.use(Iu);let r=t.remarkRehypeOptions||{};return i.use(Rb).use(t.remarkPlugins||[]).use(qu,{...r,allowDangerousHtml:!0,passThrough:[...r.passThrough||[],...zb]}).use(t.rehypePlugins||[]),t.format==="md"&&i.use(Lb),i.use(lu,t).use(Ob,t).use(Ib,t),t.jsx||i.use(Qo,t).use(Tb,t),i.use($o).use(eu,t).use(t.recmaPlugins||[]),i}function jb(e,t){let{file:n,options:i}=G0(e,t);return Ub(i).process(n)}function Pb(e){let{Fragment:t,baseUrl:n,development:i,jsx:r,jsxDEV:a,jsxs:s,useMDXComponents:o,...u}=e||{};if(!t)throw new Error("Expected \`Fragment\` given to \`evaluate\`");if(i){if(!a)throw new Error("Expected \`jsxDEV\` given to \`evaluate\`")}else{if(!r)throw new Error("Expected \`jsx\` given to \`evaluate\`");if(!s)throw new Error("Expected \`jsxs\` given to \`evaluate\`")}return{compiletime:{...u,development:i,outputFormat:"function-body",providerImportSource:o?"#":void 0},runtime:{Fragment:t,baseUrl:n,jsx:r,jsxDEV:a,jsxs:s,useMDXComponents:o}}}var X6=Object.getPrototypeOf(Ah).constructor;async function Ah(e,t){return new X6(String(e))(t)}async function Th(e,t){let{compiletime:n,runtime:i}=Pb(t);return Ah(await jb(e,n),i)}var Zu={};tl(Zu,{AssetsClient:()=>_l,FanoutsClient:()=>Al,HealthClient:()=>Tl,PRAGMA_ENV_KEYS:()=>at,PragmaClient:()=>Yu,PragmaGatewayError:()=>Cl,PragmaTransportError:()=>si,PushClient:()=>Nl,ScratchpadsClient:()=>Dl,ThemeClient:()=>Ol,WhiteboardsClient:()=>Il,WorkspaceClient:()=>Ll,awaitAgentAnswer:()=>Kb,awaitAgentDecision:()=>Zb,base64ToBytes:()=>Qu,bytesToBase64:()=>zh,hasPragmaEnvironment:()=>Za,promptAgent:()=>h4,readEnv:()=>st,reportAttention:()=>Xb,reportCleared:()=>Gb,reportMessage:()=>Qb,reportSessionName:()=>Yb,reportStarted:()=>Hb,reportStopped:()=>Jb,runtimeAgentId:()=>Vh,scratchpadBridge:()=>p4});var at={gatewayUrl:"PRAGMA_GATEWAY_URL",gatewayToken:"PRAGMA_GATEWAY_TOKEN",tabId:"PRAGMA_TAB_ID",worktreeId:"PRAGMA_WORKTREE_ID"};function st(e,t){let n=globalThis.process;return t?.[e]??n?.env?.[e]}function Za(e){return!!(st(at.gatewayUrl,e)&&st(at.gatewayToken,e)&&st(at.tabId,e)&&st(at.worktreeId,e))}var ke={health:"/v1/health",version:"/v1/version",rpc:e=>\`/v1/rpc/\${encodeURIComponent(e)}\`,sessions:"/v1/sessions",sessionEvents:e=>\`/v1/sessions/\${encodeURIComponent(e)}/events\`,sessionInput:e=>\`/v1/sessions/\${encodeURIComponent(e)}/input\`,sessionResize:e=>\`/v1/sessions/\${encodeURIComponent(e)}/resize\`,session:e=>\`/v1/sessions/\${encodeURIComponent(e)}\`,agentReports:"/v1/agents/reports",agentMessages:"/v1/agents/messages",agentAnswers:"/v1/agents/answers",agentDecisions:"/v1/agents/decisions",agentInputs:"/v1/agents/inputs",agentInterrupts:"/v1/agents/interrupts",agentCatalog:"/v1/agents/catalog",agentEvents:"/v1/agents/events",asset:e=>\`/v1/assets/\${encodeURIComponent(e)}\`,theme:"/v1/theme",scratchpads:"/v1/scratchpads",agentsSeen:e=>\`/v1/tabs/\${encodeURIComponent(e)}/agents/seen\`,subscription:e=>\`/v1/subscriptions/\${encodeURIComponent(e)}\`,control:e=>\`/v1/control/\${encodeURIComponent(e)}\`,pushTokens:"/v1/push/tokens",pushTest:"/v1/push/test",pushPresence:"/v1/push/presence"},Cl=class extends Error{code;httpStatus;details;cause;constructor(t,n){super(t,{cause:n.cause}),this.name="PragmaGatewayError",this.code=n.code,this.httpStatus=n.httpStatus,this.details=n.details,this.cause=n.cause}},si=class extends Error{cause;constructor(t,n){super(t,{cause:n}),this.name="PragmaTransportError",this.cause=n}};async function*Rh(e,t){if(!e.body)throw new si("gateway response is not streamable");let n=e.body.getReader(),i=new TextDecoder,r="",a=()=>{n.cancel()};t?.addEventListener("abort",a,{once:!0});try{for(;;){if(t?.aborted)return;let{done:s,value:o}=await n.read();if(s)break;r+=i.decode(o,{stream:!0});let u=r.indexOf(\`
62
62
  \`);for(;u>=0;){let f=r.slice(0,u).trim();r=r.slice(u+1),f&&(yield JSON.parse(f)),u=r.indexOf(\`
63
63
  \`)}}r+=i.decode(),r.trim()&&(yield JSON.parse(r))}finally{t?.removeEventListener("abort",a),await n.cancel().catch(()=>{})}}var ra=class{baseUrl;token;fetch;headers;constructor(t={}){let{baseUrl:n,token:i}=G6(t);this.baseUrl=n,this.token=i,this.fetch=Y6(t.fetch),this.headers=t.headers??{}}async request(t,n={}){let i=await this.raw(t,n);if(!(i.status===204||i.status===202))return Z6(i)}async raw(t,n={}){let i={...this.headers,...n.headers,authorization:\`Bearer \${this.token}\`},r;n.rawBody?r=n.rawBody:n.body!==void 0&&(i["content-type"]=i["content-type"]??"application/json",r=JSON.stringify(n.body));let a;try{a=await this.fetch(Q6(this.baseUrl,t),{method:n.method??(r?"POST":"GET"),headers:i,body:r,signal:n.signal})}catch(s){throw new si("failed to reach Pragma gateway",s)}if(!a.ok)throw await K6(a);return a}};function G6(e){let t=qb(e.baseUrl??st(at.gatewayUrl)??""),n=e.token??st(at.gatewayToken)??"";if(!t||!n)throw new si("Pragma gateway baseUrl and token are required");return{baseUrl:t,token:n}}function Y6(e){let t=e??globalThis.fetch?.bind(globalThis);if(!t)throw new si("global fetch is not available");return t}function Q6(e,t){return\`\${qb(e)}\${t.startsWith("/")?t:\`/\${t}\`}\`}async function Z6(e){try{return await e.json()}catch(t){throw new si("gateway returned non-JSON response",t)}}async function K6(e){let t={};try{t=await e.json()}catch(n){throw new si("gateway returned non-JSON error response",n)}return new Cl(t.message??\`gateway returned \${e.status}\`,{code:t.code??"internal",httpStatus:e.status,details:t.details})}function qb(e){return e.replace(/\\/+$/,"")}var aa=class{transport;constructor(t){this.transport=t}report(t,n={}){return this.transport.request(ke.agentReports,{method:"POST",body:t,signal:n.signal})}reportMessage(t,n={}){return this.transport.request(ke.agentMessages,{method:"POST",body:t,signal:n.signal})}reportDecision(t,n={}){return this.transport.request(ke.agentDecisions,{method:"POST",body:t,signal:n.signal})}reportAnswer(t,n={}){return this.transport.request(ke.agentAnswers,{method:"POST",body:t,signal:n.signal})}reportInput(t,n={}){return this.transport.request(ke.agentInputs,{method:"POST",body:t,signal:n.signal})}reportInterrupt(t,n={}){return this.transport.request(ke.agentInterrupts,{method:"POST",body:t,signal:n.signal})}reportStarted(t){return Ya(this,t,"running",null)}reportStopped(t){return Ya(this,t,"done",null)}reportAttention(t){return Ya(this,t,"attention",t.kind??"question")}reportCleared(t){return Ya(this,t,"cleared",null)}reportSessionName(t){return Ya(this,t,null,null,t.name)}catalog(t={}){return this.transport.request(ke.agentCatalog,{method:"GET",signal:t.signal})}launch(t,n={}){return this.transport.request(ke.control("agentSessionLaunch"),{method:"POST",body:t,signal:n.signal})}markAgentsSeen(t,n={}){return this.transport.request(ke.agentsSeen(t.tabId),{method:"POST",body:{},signal:n.signal})}async connect(t){let{agent:n,tabId:i,worktreeId:r}=t,a=new AbortController,s=()=>a.abort();t.signal?.addEventListener("abort",s);let o=this.readStream.bind(this);async function*u(){try{for await(let p of o({signal:a.signal}))W6(p,n,i)&&(yield p)}finally{t.signal?.removeEventListener("abort",s)}}let f={[Symbol.asyncIterator]:u,send:(p,h={})=>this.reportInput({agent:n,worktreeId:r,tabId:i,text:p,...h.requestId?{requestId:h.requestId}:{}},{signal:a.signal}),answer:(p,h)=>this.reportAnswer({agent:n,worktreeId:r,tabId:i,requestId:p,dismissed:h===null,...h!==null?{answer:h}:{}},{signal:a.signal}),decide:(p,h)=>this.reportDecision({agent:n,worktreeId:r,tabId:i,requestId:p,approved:h},{signal:a.signal}),interrupt:p=>this.reportInterrupt({agent:n,worktreeId:r,tabId:i,...p?{requestId:p}:{}},{signal:a.signal}),close:()=>a.abort()};return t.prompt!==void 0&&await f.send(t.prompt),f}async*readStream(t={}){let n=await this.transport.raw(ke.agentEvents,{signal:t.signal});yield*Rh(n,t.signal)}async awaitDecision(t){let n=new AbortController,i=()=>n.abort();t.signal?.addEventListener("abort",i);let r=t.timeoutMs&&t.timeoutMs>0?setTimeout(()=>n.abort(),t.timeoutMs):void 0;try{for await(let a of this.readStream({signal:n.signal}))if(a.type==="agentDecision"&&a.decision.requestId===t.requestId&&a.decision.agent===t.agent)return a.decision.approved;return null}catch{return null}finally{r&&clearTimeout(r),t.signal?.removeEventListener("abort",i)}}async awaitAnswer(t){let n=new AbortController,i=()=>n.abort();t.signal?.addEventListener("abort",i);let r=t.timeoutMs&&t.timeoutMs>0?setTimeout(()=>n.abort(),t.timeoutMs):void 0;try{for await(let a of this.readStream({signal:n.signal}))if(a.type==="agentAnswer"&&a.answer.requestId===t.requestId&&a.answer.agent===t.agent)return a.answer.dismissed?null:a.answer.answer??"";return null}catch{return null}finally{r&&clearTimeout(r),t.signal?.removeEventListener("abort",i)}}};function W6(e,t,n){switch(e.type){case"agent":return e.agent===t&&e.tabId===n;case"agentMessage":return e.message.agent===t&&e.message.tabId===n;case"agentDecision":return e.decision.agent===t&&e.decision.tabId===n;case"agentAnswer":return e.answer.agent===t&&e.answer.tabId===n;case"agentInput":return e.input.agent===t&&e.input.tabId===n;case"agentInterrupt":return e.interrupt.agent===t&&e.interrupt.tabId===n}}function Hb(e){return Ml(e,"running",null)}function Jb(e){return Ml(e,"done",null)}function Xb(e){return Ml(e,"attention",e.kind??"question")}function Gb(e){return Ml(e,"cleared",null)}function Yb(e){return Ml(e,null,null,e.name)}async function Qb(e){if(!e.client&&!Za(e.env))return;let t=e.client?.agents??new aa(new ra({baseUrl:st(at.gatewayUrl,e.env),token:st(at.gatewayToken,e.env)}));await e4(t,e)}async function Zb(e){return!e.client&&!Za(e.env)?null:(e.client?.agents??new aa(new ra({baseUrl:st(at.gatewayUrl,e.env),token:st(at.gatewayToken,e.env)}))).awaitDecision({agent:e.agent,requestId:e.requestId,timeoutMs:e.timeoutMs,signal:e.signal})}async function Kb(e){return!e.client&&!Za(e.env)?null:(e.client?.agents??new aa(new ra({baseUrl:st(at.gatewayUrl,e.env),token:st(at.gatewayToken,e.env)}))).awaitAnswer({agent:e.agent,requestId:e.requestId,timeoutMs:e.timeoutMs,signal:e.signal})}async function Ml(e,t,n,i){if(!e.client&&!Za(e.env))return;let r=e.client?.agents??new aa(new ra({baseUrl:st(at.gatewayUrl,e.env),token:st(at.gatewayToken,e.env)}));await Ya(r,e,t,n,i)}async function Ya(e,t,n,i,r){let a=t.worktreeId??st(at.worktreeId,t.env),s=st(at.tabId,t.env);!a||!s||await e.report($6(t,{worktreeId:a,tabId:s},n,i,r),{signal:t.signal})}function $6(e,t,n,i,r){return{agent:e.agent,worktreeId:t.worktreeId,tabId:t.tabId,status:n,attentionKind:i,...r?{sessionName:r}:{},...e.command?{command:e.command}:{},...e.question?{question:e.question}:{},...e.options&&e.options.length>0?{options:e.options}:{},...e.questions&&e.questions.length>0?{questions:e.questions}:{},...e.requestId?{requestId:e.requestId}:{}}}async function e4(e,t){let n=t.message.worktreeId??t.worktreeId??st(at.worktreeId,t.env),i=t.message.tabId??st(at.tabId,t.env);!n||!i||await e.reportMessage({...t.message,agent:t.message.agent??t.agent,worktreeId:n,tabId:i},{signal:t.signal})}var El="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function zh(e){let t="";for(let n=0;n<e.length;n+=3){let i=e[n]??0,r=e[n+1]??0,a=e[n+2]??0;t+=El[i>>2],t+=El[(i&3)<<4|r>>4],t+=n+1<e.length?El[(r&15)<<2|a>>6]:"=",t+=n+2<e.length?El[a&63]:"="}return t}function Qu(e){let t=e.replace(/\\s/g,"");if(t.length%4!==0)throw new TypeError("invalid base64 length");let n=[];for(let i=0;i<t.length;i+=4){let r=[t[i],t[i+1],t[i+2],t[i+3]],a=r.map(p=>p==="="?0:El.indexOf(p??""));if(a.some(p=>p<0))throw new TypeError("invalid base64 character");let s=a[0]??0,o=a[1]??0,u=a[2]??0,f=a[3]??0;n.push(s<<2|o>>4),r[2]!=="="&&n.push((o&15)<<4|u>>2),r[3]!=="="&&n.push((u&3)<<6|f)}return new Uint8Array(n)}var _l=class{transport;constructor(t){this.transport=t}async fetch(t,n={}){let i=await this.transport.raw(ke.asset(t),{signal:n.signal}),r=i.headers.get("content-type")??"application/octet-stream";return{bytes:new Uint8Array(await i.arrayBuffer()),mime:r}}async toDataUri(t,n={}){let{bytes:i,mime:r}=await this.fetch(t,n);return\`data:\${r};base64,\${zh(i)}\`}},Nh=class{transport;constructor(t){this.transport=t}async*subscribe(t,n={}){let i=new URLSearchParams;n.cursor&&i.set("cursor",n.cursor),n.worktreeId&&i.set("worktreeId",n.worktreeId),n.cwd&&i.set("cwd",n.cwd);let r=i.toString()?\`?\${i}\`:"",a=await this.transport.raw(\`\${ke.subscription(t)}\${r}\`,{signal:n.signal});for await(let s of Rh(a,n.signal))(s.type==="snapshot"||s.type==="delta")&&(yield s)}},Dh=class{transport;constructor(t){this.transport=t}run(t){return this.transport.request(ke.rpc("exec"),{body:{...t,env:t.env??[],maxConcurrent:t.maxConcurrent??1}})}},Al=class{transport;events;constructor(t,n){this.transport=t,this.events=n}create(t,n={}){return this.rpc("create",t,n)}get(t,n={}){return this.rpc("get",t,n)}async read(t,n={}){let i=await this.rpc("read",t,n);return{fanoutId:i.fanoutId,targets:i.targets.map(({data:r,...a})=>({...a,raw:Qu(r)}))}}send(t,n={}){return this.rpc("send",t,n)}retry(t,n={}){return this.rpc("retry",t,n)}cancel(t,n={}){return this.rpc("cancel",t,n)}pick(t,n={}){return this.rpc("pick",t,n)}async*subscribe(t={}){for await(let n of this.events.subscribe("fanouts",{signal:t.signal})){let i=this.narrow(n);if(!t.fanoutId){yield i;continue}yield{...i,payload:{fanouts:i.payload.fanouts.filter(r=>r.id===t.fanoutId)}}}}narrow(t){return{type:t.type,subscription:t.subscription,payload:t.payload??{fanouts:[]}}}rpc(t,n,i){return this.transport.request(ke.rpc("fanouts"),{method:"POST",body:{action:t,...n},signal:i.signal})}},Oh=class{transport;constructor(t){this.transport=t}listDir(t){return this.rpc("listDir",t)}createFile(t){return this.rpc("createFile",t)}createFolder(t){return this.rpc("createFolder",t)}pathExists(t){return this.rpc("pathExists",t)}readFile(t){return this.rpc("readFile",t)}writeFile(t){return this.rpc("writeFile",t)}rename(t){return this.rpc("rename",t)}delete(t){return this.rpc("delete",t)}rpc(t,n){return this.transport.request(ke.rpc("filesystem"),{body:{op:t,...n}})}},Ih=class{transport;constructor(t){this.transport=t}worktreeChanges(t){return this.rpc("worktreeChanges",t)}mergedStatus(t){return this.rpc("mergedStatus",t)}fileDiff(t){return this.rpc("fileDiff",t)}discardUnstagedFile(t){return this.rpc("discardUnstagedFile",t)}discardAllUnstaged(t){return this.rpc("discardAllUnstaged",t)}stageFile(t){return this.rpc("stageFile",t)}stageAll(t){return this.rpc("stageAll",t)}unstageFile(t){return this.rpc("unstageFile",t)}unstageAll(t){return this.rpc("unstageAll",t)}commitStaged(t){return this.rpc("commitStaged",t)}mergeWorktreeToParent(t){return this.rpc("mergeWorktreeToParent",t)}prFileDiff(t){return this.rpc("prFileDiff",t)}githubRepoInfo(t){return this.rpc("githubRepoInfo",t)}githubDefaultPrTitle(t){return this.rpc("githubDefaultPrTitle",t)}githubFetchAndSync(t){return this.rpc("githubFetchAndSync",t)}githubPullBranch(t){return this.rpc("githubPullBranch",t)}githubSyncBranch(t){return this.rpc("githubSyncBranch",t)}githubPushBranch(t){return this.rpc("githubPushBranch",t)}githubDeleteRemoteBranch(t){return this.rpc("githubDeleteRemoteBranch",t)}ensurePragmaExcluded(t){return this.rpc("ensurePragmaExcluded",t)}createWorktree(t){return this.rpc("createWorktree",t)}removeWorktree(t){return this.rpc("removeWorktree",t)}deleteBranch(t){return this.rpc("deleteBranch",t)}isDirty(t){return this.rpc("isDirty",t)}rpc(t,n){return this.transport.request(ke.rpc("git"),{body:{op:t,...n}})}},Tl=class{transport;constructor(t){this.transport=t}check(t={}){return this.transport.request(ke.health,{signal:t.signal})}},Nl=class{transport;constructor(t){this.transport=t}register(t,n={}){return this.transport.request(ke.pushTokens,{method:"POST",body:t,signal:n.signal})}unregister(t={}){return this.transport.request(ke.pushTokens,{method:"DELETE",body:{},signal:t.signal})}list(t={}){return this.transport.request(ke.pushTokens,{method:"GET",signal:t.signal})}test(t={}){return this.transport.request(ke.pushTest,{method:"POST",body:{},signal:t.signal})}presence(t,n={}){return this.transport.request(ke.pushPresence,{method:"POST",body:t,signal:n.signal})}};function Wb(e,t){if(typeof e!="object"||e===null)return!1;let n=e;return Object.entries(t).every(([i,r])=>r(n[i]))}var ia=e=>typeof e=="string",Qa=e=>typeof e=="number";function Lh(e){return t=>t===null||e(t)}function Fb(e){return\`\${e}.comments.json\`}function t4(e){let t=JSON.parse(e);if(!Array.isArray(t))throw new Error("Scratchpad comments must be an array.");return t.filter(r4)}function n4(e){return\`\${JSON.stringify(e,null,2)}
64
- \`}function i4(e,t,n,i){return{id:i,from:0,to:0,quote:e.quote,text:t.trim(),createdAt:n,resolvedAt:null,blockIndex:e.index}}function r4(e){return Wb(e,{id:ia,from:Qa,to:Qa,quote:ia,text:ia,createdAt:Qa,resolvedAt:Lh(Qa)})}var a4={daemon:{protocolVersion:"0.1.0",socketFile:"daemon.sock",lockFile:"server.lock",logFile:"server.log"},gateway:{apiVersion:"0.0.0",discoveryFile:"gateway.json",tokenFile:"gateway-token",devicesFile:"gateway-devices.json",tokenHeader:"authorization",deviceHeaders:{id:"x-pragma-device-id",name:"x-pragma-device-name",platform:"x-pragma-device-platform",appVersion:"x-pragma-app-version"},push:{sendUrl:"https://exp.host/--/api/v2/push/send",batchSize:100,presenceTtlMs:9e4,tokenPrefixes:["ExponentPushToken[","ExpoPushToken["]},web:{enabled:!1,basePath:"/web",manifestFile:"manifest.json",resourceDir:"web"}},platform:{defaultBackend:"native",shells:{macos:"/bin/zsh",linux:"/bin/sh",windows:["pwsh.exe","powershell.exe"]},wsl:{launcher:"wsl.exe",listArgs:["--list","--verbose"],serverBinary:"pragma-server"}},tunnel:{defaultCommand:"ngrok http {port} --log stdout --log-format json",defaultUrlPattern:'(https://[^\\\\s"]+)'},plugins:{configFileName:".pragma/config.json",storageScopes:["global","project"]},theme:{fileName:".pragma/theme.json",modes:["light","dark"]},keybindings:{configFileName:".pragma/keybindings.json"},bench:{hookGlobal:"__PRAGMA_BENCH__",runnerGlobal:"__PRAGMA_BENCH_RUNNER__",markerPrefix:"PRAGMABENCH",tabTitle:"pragma-bench"},agentStatus:{soundsDirName:".pragma/assets/sounds",maxSoundSeconds:5,maxSoundBytes:5242880,soundExtensions:["mp3","wav","ogg","oga","m4a","aac","flac","webm"],notificationsEnabled:!0,notificationText:{doneTitle:"{agent} finished",attentionTitle:"{agent} needs attention",questionTitle:"{agent} is waiting for an answer",commandTitle:"{agent} wants to run a command",locationSeparator:" / ",tabSuffix:' \\xB7 tab "{tab}"',unknownLocation:"Open Pragma to continue."}},terminalDefaults:{hiddenDistros:["docker-desktop","docker-desktop-data"],rememberLastShell:!1,maxDroppedFileBytes:10485760,droppedFilesDirName:"pragma-dropped-files",droppedFilesMaxAgeMs:864e5},tabs:{defaultTitles:{fallback:"Shell",browser:"New tab",log:"Server Logs",scratchpad:"Scratchpad",whiteboard:"Whiteboard",prReview:"PR Review",pluginWebview:"Plugin"}},files:{chunkBytes:4194304,maxBinaryBytes:268435456},fanout:{stateFile:"fanouts.json",branchPrefix:"fanout",minMembers:2,defaultJobs:4,deliveryTimeoutMs:15e3,envFanoutId:"PRAGMA_FANOUT_ID",envMemberId:"PRAGMA_FANOUT_MEMBER_ID"},scratchpads:{directory:".pragma/scratchpads",extension:"mdx",frontmatterKey:"pragmaScratchpad",version:1},whiteboards:{databaseFile:"whiteboards.db",defaultTitle:"Whiteboard",maxTitleChars:200,maxSceneBytes:8388608,maxRenderDimension:4096},protocol:{rpcMethods:["git","filesystem","database","kanban","worktrees","projects","tabs","settings","github","ai","exec","automations","plugins","tunnel","scratchpads","whiteboards","wsl","fanouts"],events:["agentStatus","worktreeChanged","kanbanChanged","tabsChanged","fileChanged","echoMode","automationPending","automationsChanged","workspace","fanouts"],errors:["invalidPayload","unsupportedMethod","notFound","staleWrite","permissionDenied","internal"]},scripts:{maxConcurrentCommands:4,configPath:".pragma/scripts.json",migrationSources:[{id:"superset",label:"Superset",configPaths:[".superset/config.json"]},{id:"emdash",label:"Emdash",configPaths:[".emdash.json"]},{id:"orca",label:"Orca",configPaths:["orca.yaml","orca.yml",".orca/config.json"]}],migrationCommitMessage:"chore(config): add pragma-app.sh config"},agents:{startDelayMs:500,altScreenExtraWaitMs:15e3,altScreenSettleMs:500},github:{oauthClientId:"Ov23li1WfY05SeQNp5tk",scopes:["repo"],deviceCodeUrl:"https://github.com/login/device/code",deviceVerifyUrl:"https://github.com/login/device",accessTokenUrl:"https://github.com/login/oauth/access_token",apiBaseUrl:"https://api.github.com",homepageUrl:"https://github.com/pragma-sh/pragma",prSignature:{enabled:!0,startMarker:"<!-- pragma:pr-signature -->",endMarker:"<!-- /pragma:pr-signature -->",linkLabel:"Open worktree in Pragma",openUrl:"https://pragma-app.sh/open"}},app:{name:"Pragma",identifier:"com.pragma.app",version:"0.1.0"},onboarding:{mediaBaseUrl:"https://pragma-app.sh/media",skill:{id:"pragma",targets:[{id:"all-agents",directory:".agents/skills",label:"All agents"},{id:"claude-code",directory:".claude/skills",label:"Claude Code"}]}},updates:{checkUrl:"https://pragma-app.sh/api/updates",devCheckUrl:"http://localhost:3000/api/updates",pollIntervalMs:3e5,autoDownload:!0,manifestFile:"release.json",uiDirName:"ui",buttonLabel:"Install Update",changelogLabel:"View changelog",restartWarningTitle:"This update restarts the app server",restartWarningBody:"Open terminal sessions will stop. Save anything you need before installing.",applyModes:["reload","restart"],platforms:["darwin-aarch64","darwin-x86_64","linux-x86_64-deb","linux-x86_64-rpm","linux-x86_64-appimage","linux-aarch64-deb","linux-aarch64-rpm","linux-aarch64-appimage","windows-x86_64"]},window:{defaultWidth:1024,defaultHeight:768,minWidth:640,minHeight:480,titlebarHeight:38,trafficLightInset:12},editorLaunchers:{defaultEditorId:"system",options:[{id:"system",name:"File Explorer",brandIcon:"lucide:folder-open",brandColor:"#38bdf8",cliCommand:null},{id:"vscode",name:"VS Code",brandIcon:"simple-icons:visualstudiocode",brandColor:"#007acc",cliCommand:"code"},{id:"cursor",name:"Cursor",brandIcon:"simple-icons:cursor",brandColor:"#ffffff",cliCommand:"cursor"},{id:"windsurf",name:"Windsurf",brandIcon:"simple-icons:windsurf",brandColor:"#00c7be",cliCommand:"windsurf"},{id:"zed",name:"Zed",brandIcon:"simple-icons:zedindustries",brandColor:"#084ccf",cliCommand:"zed"},{id:"sublime-text",name:"Sublime Text",brandIcon:"simple-icons:sublimetext",brandColor:"#ff9800",cliCommand:"subl"},{id:"intellij-idea",name:"IntelliJ IDEA",brandIcon:"simple-icons:intellijidea",brandColor:"#ff2d8f",cliCommand:"idea"}]}},Bh=a4,s4=/^---\\r?\\n([\\s\\S]*?)\\r?\\n---(?:\\r?\\n)?/;function $b(e){let t=s4.exec(e);if(!t)throw new Error("This MDX file is not a managed Pragma scratchpad.");return{metadata:o4(l4(t[1]??"")),body:e.slice(t[0].length),frontmatter:t[0]}}function l4(e){let t=Bh.scratchpads.frontmatterKey,n=e.split(/\\r?\\n/).find(i=>i.startsWith(\`\${t}: \`));if(!n)throw new Error("Scratchpad frontmatter is missing managed metadata.");return n.slice(t.length+2)}function o4(e){let t=JSON.parse(e);if(!c4(t)||t.version!==Bh.scratchpads.version)throw new Error("Scratchpad metadata is invalid or uses an unsupported version.");return t}function u4(e,t){let n=$b(e),i={...n.metadata,agentTabId:t.tabId,agentId:t.agentId},r=Bh.scratchpads.frontmatterKey,a=\`\${r}: \${JSON.stringify(i)}\`,s=n.frontmatter.split(/\\r?\\n/),o=s.findIndex(u=>u.startsWith(\`\${r}: \`));if(o<0)throw new Error("Scratchpad frontmatter is missing managed metadata.");return s[o]=a,\`\${s.join(\`
64
+ \`}function i4(e,t,n,i){return{id:i,from:0,to:0,quote:e.quote,text:t.trim(),createdAt:n,resolvedAt:null,blockIndex:e.index}}function r4(e){return Wb(e,{id:ia,from:Qa,to:Qa,quote:ia,text:ia,createdAt:Qa,resolvedAt:Lh(Qa)})}var a4={daemon:{protocolVersion:"0.3.0",socketFile:"daemon.sock",lockFile:"server.lock",logFile:"server.log"},gateway:{apiVersion:"0.0.0",discoveryFile:"gateway.json",tokenFile:"gateway-token",devicesFile:"gateway-devices.json",tokenHeader:"authorization",deviceHeaders:{id:"x-pragma-device-id",name:"x-pragma-device-name",platform:"x-pragma-device-platform",appVersion:"x-pragma-app-version"},push:{sendUrl:"https://exp.host/--/api/v2/push/send",batchSize:100,presenceTtlMs:9e4,tokenPrefixes:["ExponentPushToken[","ExpoPushToken["]},web:{enabled:!1,basePath:"/web",manifestFile:"manifest.json",resourceDir:"web"}},platform:{defaultBackend:"native",shells:{macos:"/bin/zsh",linux:"/bin/sh",windows:["pwsh.exe","powershell.exe"]},wsl:{launcher:"wsl.exe",listArgs:["--list","--verbose"],serverBinary:"pragma-server"}},tunnel:{defaultCommand:"ngrok http {port} --log stdout --log-format json",defaultUrlPattern:'(https://[^\\\\s"]+)'},plugins:{configFileName:".pragma/config.json",storageScopes:["global","project"]},theme:{fileName:".pragma/theme.json",modes:["light","dark"]},keybindings:{configFileName:".pragma/keybindings.json"},bench:{hookGlobal:"__PRAGMA_BENCH__",runnerGlobal:"__PRAGMA_BENCH_RUNNER__",markerPrefix:"PRAGMABENCH",tabTitle:"pragma-bench"},agentStatus:{soundsDirName:".pragma/assets/sounds",maxSoundSeconds:5,maxSoundBytes:5242880,soundExtensions:["mp3","wav","ogg","oga","m4a","aac","flac","webm"],notificationsEnabled:!0,notificationText:{doneTitle:"{agent} finished",attentionTitle:"{agent} needs attention",questionTitle:"{agent} is waiting for an answer",commandTitle:"{agent} wants to run a command",locationSeparator:" / ",tabSuffix:' \\xB7 tab "{tab}"',unknownLocation:"Open Pragma to continue."}},terminalDefaults:{hiddenDistros:["docker-desktop","docker-desktop-data"],rememberLastShell:!1,maxDroppedFileBytes:10485760,droppedFilesDirName:"pragma-dropped-files",droppedFilesMaxAgeMs:864e5},tabs:{defaultTitles:{fallback:"Shell",browser:"New tab",log:"Server Logs",scratchpad:"Scratchpad",whiteboard:"Whiteboard",prReview:"PR Review",pluginWebview:"Plugin"}},files:{chunkBytes:4194304,maxBinaryBytes:268435456},fanout:{stateFile:"fanouts.json",branchPrefix:"fanout",minMembers:2,defaultJobs:4,deliveryTimeoutMs:15e3,envFanoutId:"PRAGMA_FANOUT_ID",envMemberId:"PRAGMA_FANOUT_MEMBER_ID"},scratchpads:{directory:".pragma/scratchpads",extension:"mdx",frontmatterKey:"pragmaScratchpad",version:1},whiteboards:{databaseFile:"whiteboards.db",defaultTitle:"Whiteboard",maxTitleChars:200,maxSceneBytes:8388608,maxRenderDimension:4096},protocol:{rpcMethods:["git","filesystem","database","kanban","worktrees","projects","tabs","settings","github","ai","exec","automations","plugins","tunnel","scratchpads","whiteboards","wsl","fanouts"],events:["agentStatus","worktreeChanged","kanbanChanged","tabsChanged","fileChanged","echoMode","automationPending","automationsChanged","workspace","fanouts"],errors:["invalidPayload","unsupportedMethod","notFound","staleWrite","permissionDenied","internal"]},scripts:{maxConcurrentCommands:4,configPath:".pragma/scripts.json",migrationSources:[{id:"superset",label:"Superset",configPaths:[".superset/config.json"]},{id:"emdash",label:"Emdash",configPaths:[".emdash.json"]},{id:"orca",label:"Orca",configPaths:["orca.yaml","orca.yml",".orca/config.json"]}],migrationCommitMessage:"chore(config): add pragma-app.sh config"},agents:{startDelayMs:500,altScreenExtraWaitMs:15e3,altScreenSettleMs:500},github:{oauthClientId:"Ov23li1WfY05SeQNp5tk",scopes:["repo"],deviceCodeUrl:"https://github.com/login/device/code",deviceVerifyUrl:"https://github.com/login/device",accessTokenUrl:"https://github.com/login/oauth/access_token",apiBaseUrl:"https://api.github.com",homepageUrl:"https://github.com/pragma-sh/pragma",prSignature:{enabled:!0,startMarker:"<!-- pragma:pr-signature -->",endMarker:"<!-- /pragma:pr-signature -->",linkLabel:"Open worktree in Pragma",openUrl:"https://pragma-app.sh/open"}},app:{name:"Pragma",identifier:"com.pragma.app",version:"0.3.0"},onboarding:{mediaBaseUrl:"https://pragma-app.sh/media",skill:{id:"pragma",targets:[{id:"all-agents",directory:".agents/skills",label:"All agents"},{id:"claude-code",directory:".claude/skills",label:"Claude Code"}]}},updates:{checkUrl:"https://pragma-app.sh/api/updates",devCheckUrl:"http://localhost:3000/api/updates",pollIntervalMs:3e5,autoDownload:!0,manifestFile:"release.json",uiDirName:"ui",buttonLabel:"Install Update",changelogLabel:"View changelog",restartWarningTitle:"This update restarts the app server",restartWarningBody:"Open terminal sessions will stop. Save anything you need before installing.",applyModes:["reload","restart"],platforms:["darwin-aarch64","darwin-x86_64","linux-x86_64-deb","linux-x86_64-rpm","linux-x86_64-appimage","linux-aarch64-deb","linux-aarch64-rpm","linux-aarch64-appimage","windows-x86_64"]},window:{defaultWidth:1024,defaultHeight:768,minWidth:640,minHeight:480,titlebarHeight:38,trafficLightInset:12},editorLaunchers:{defaultEditorId:"system",options:[{id:"system",name:"File Explorer",brandIcon:"lucide:folder-open",brandColor:"#38bdf8",cliCommand:null},{id:"vscode",name:"VS Code",brandIcon:"simple-icons:visualstudiocode",brandColor:"#007acc",cliCommand:"code"},{id:"cursor",name:"Cursor",brandIcon:"simple-icons:cursor",brandColor:"#ffffff",cliCommand:"cursor"},{id:"windsurf",name:"Windsurf",brandIcon:"simple-icons:windsurf",brandColor:"#00c7be",cliCommand:"windsurf"},{id:"zed",name:"Zed",brandIcon:"simple-icons:zedindustries",brandColor:"#084ccf",cliCommand:"zed"},{id:"sublime-text",name:"Sublime Text",brandIcon:"simple-icons:sublimetext",brandColor:"#ff9800",cliCommand:"subl"},{id:"intellij-idea",name:"IntelliJ IDEA",brandIcon:"simple-icons:intellijidea",brandColor:"#ff2d8f",cliCommand:"idea"}]}},Bh=a4,s4=/^---\\r?\\n([\\s\\S]*?)\\r?\\n---(?:\\r?\\n)?/;function $b(e){let t=s4.exec(e);if(!t)throw new Error("This MDX file is not a managed Pragma scratchpad.");return{metadata:o4(l4(t[1]??"")),body:e.slice(t[0].length),frontmatter:t[0]}}function l4(e){let t=Bh.scratchpads.frontmatterKey,n=e.split(/\\r?\\n/).find(i=>i.startsWith(\`\${t}: \`));if(!n)throw new Error("Scratchpad frontmatter is missing managed metadata.");return n.slice(t.length+2)}function o4(e){let t=JSON.parse(e);if(!c4(t)||t.version!==Bh.scratchpads.version)throw new Error("Scratchpad metadata is invalid or uses an unsupported version.");return t}function u4(e,t){let n=$b(e),i={...n.metadata,agentTabId:t.tabId,agentId:t.agentId},r=Bh.scratchpads.frontmatterKey,a=\`\${r}: \${JSON.stringify(i)}\`,s=n.frontmatter.split(/\\r?\\n/),o=s.findIndex(u=>u.startsWith(\`\${r}: \`));if(o<0)throw new Error("Scratchpad frontmatter is missing managed metadata.");return s[o]=a,\`\${s.join(\`
65
65
  \`)}\${n.body}\`}function c4(e){return Wb(e,{version:Qa,id:ia,title:ia,agentTabId:Lh(ia),agentId:Lh(ia),createdAt:Qa})}var Dl=class{transport;fs;agents;constructor(t,n,i){this.transport=t,this.fs=n,this.agents=i}getScratchpads(t){let n=\`?root=\${encodeURIComponent(t.root)}\`;return this.transport.request(\`\${ke.scratchpads}\${n}\`,{signal:t.signal})}async getComments(t){let n=Fb(t.filePath),{root:i}=t;if(!await this.fs.pathExists({root:i,path:n}))return[];let r=await this.fs.readFile({root:i,path:n});return r.binary||r.truncated?[]:t4(r.text)}async comment(t){let{root:n,filePath:i,block:r,text:a}=t,s=i4(r,a,t.createdAt??Date.now(),t.id??f4()),o=await this.getComments({root:n,filePath:i});return await this.writeComments({root:n,filePath:i},[...o,s]),s}async setComments(t,n){await this.writeComments(t,n)}async attachAgent(t){let{root:n,filePath:i,tabId:r,agentId:a}=t,s=t.contents??await this.readScratchpad(n,i);await this.fs.writeFile({root:n,path:i,contents:u4(s,{tabId:r,agentId:a})})}async sendAttached(t){let{root:n,filePath:i,worktreeId:r,text:a}=t,s=t.contents??await this.readScratchpad(n,i),{metadata:o}=$b(s);if(!o.agentTabId||!o.agentId)return{delivered:!1};let u=Vh(o.agentId);return await this.agents.reportInput({agent:u,worktreeId:r,tabId:o.agentTabId,text:a},{signal:t.signal}),{delivered:!0,agent:u,tabId:o.agentTabId}}async readScratchpad(t,n){let i=await this.fs.readFile({root:t,path:n});if(i.binary)throw new Error(\`Scratchpad \${n} is not text.\`);if(i.truncated)throw new Error(\`Scratchpad \${n} was truncated by the host.\`);return i.text}writeComments(t,n){return this.fs.writeFile({root:t.root,path:Fb(t.filePath),contents:n4(n)})}};function Vh(e){return e.split(".").at(-1)??e}function f4(){return\`\${Date.now().toString(36)}-\${Math.random().toString(36).slice(2,10)}\`}var Mh=class{transport;constructor(t){this.transport=t}spawn(t,n={}){return this.transport.request(ke.sessions,{method:"POST",body:t,signal:n.signal})}async*attach(t,n={}){let i=await this.transport.raw(ke.sessionEvents(t),{signal:n.signal});yield*Rh(i,n.signal)}write(t,n,i={}){return this.transport.request(ke.sessionInput(t),{method:"POST",rawBody:n,headers:{"content-type":"application/octet-stream"},signal:i.signal})}resize(t,n,i={}){return this.transport.request(ke.sessionResize(t),{method:"POST",body:n,signal:i.signal})}kill(t,n={}){return this.transport.request(ke.session(t),{method:"DELETE",signal:n.signal})}rename(t,n){return this.transport.request(ke.control("tabRename"),{method:"POST",body:{tabId:t,title:n}})}killForCwd(t,n={}){return this.transport.request(\`\${ke.sessions}?cwd=\${encodeURIComponent(t)}\`,{method:"DELETE",signal:n.signal})}},Ol=class{transport;constructor(t){this.transport=t}get(t={}){let n=t.root?\`?root=\${encodeURIComponent(t.root)}\`:"";return this.transport.request(\`\${ke.theme}\${n}\`,{signal:t.signal})}},Il=class{transport;constructor(t){this.transport=t}create(t){return this.rpc("create",t)}get(t){return this.rpc("get",t)}list(t){return this.rpc("list",t)}search(t){return this.rpc("list",t)}edit(t){return this.rpc("edit",t)}async delete(t){await this.rpc("delete",t)}async view(t){let n=await this.rpc("view",t);return Qu(n.data)}rpc(t,n){return this.transport.request(ke.rpc("whiteboards"),{method:"POST",body:{action:t,...n}})}},Ll=class{events;constructor(t){this.events=t}async*subscribe(t={}){for await(let n of this.events.subscribe("workspace",t))yield this.narrow(n)}narrow(t){return{type:t.type,subscription:t.subscription,payload:t.payload??{projects:[],worktrees:[],tabs:[]}}}},Yu=class{fs;git;exec;sessions;agents;assets;events;workspace;fanouts;push;theme;health;scratchpads;whiteboards;transport;constructor(t={}){this.transport=new ra(t),this.fs=new Oh(this.transport),this.git=new Ih(this.transport),this.exec=new Dh(this.transport),this.sessions=new Mh(this.transport),this.agents=new aa(this.transport),this.assets=new _l(this.transport),this.events=new Nh(this.transport),this.workspace=new Ll(this.events),this.fanouts=new Al(this.transport,this.events),this.push=new Nl(this.transport),this.theme=new Ol(this.transport),this.health=new Tl(this.transport),this.scratchpads=new Dl(this.transport,this.fs,this.agents),this.whiteboards=new Il(this.transport)}rpc(t,n,i={}){return this.transport.request(ke.rpc(t),{method:"POST",body:n,signal:i.signal})}createBoardDraft(t,n={}){return this.transport.request(ke.control("boardDraftCreate"),{method:"POST",body:t,signal:n.signal})}};function ev(){let e=globalThis.pragmaScratchpad;if(!e)throw new Error("@pragma-sh/scratchpad can only prompt agents inside a Pragma scratchpad");return e}function p4(){return ev()}async function h4(e,t={}){let n=e.trim();if(!n)return!1;let i=ev(),r=await i.promptAgent(n);if(r==="sent")return!0;if(r==="cancelled")return!1;let a=()=>i.requestAgentAttachment(),s=await t.onMissingAgent?.({text:n,attach:a});if(!(t.onMissingAgent?s===!0:await a()))return!1;let u=await i.promptAgent(n);if(u==="sent")return!0;if(u==="cancelled")return!1;throw new Error("Selected agent tab is no longer available")}var Wu={};tl(Wu,{Badge:()=>k4,Button:()=>y4,Card:()=>w4,Input:()=>b4,Progress:()=>S4,Textarea:()=>v4});var la=qt(sa(),1),rv="pragma-scratchpad-styles",g4=\`
66
66
  .pragma-card {
67
67
  display: grid;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pragma-sh/scratchpad-viewer",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "Read-only scratchpad renderer: one self-contained HTML document that evaluates scratchpad MDX with live @pragma-sh/scratchpad components and a touch comment layer.",
5
5
  "homepage": "https://github.com/pragma-sh/pragma#readme",
6
6
  "bugs": "https://github.com/pragma-sh/pragma/issues",
@@ -36,7 +36,7 @@
36
36
  "lint": "oxlint ."
37
37
  },
38
38
  "dependencies": {
39
- "@pragma-sh/scratchpad-contract": "^0.1.0"
39
+ "@pragma-sh/scratchpad-contract": "^0.3.0"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@mdx-js/mdx": "^3.1.1",