@fugood/bricks-cli 2.25.1-beta.3 → 2.25.1-beta.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/2486.js CHANGED
@@ -1 +1 @@
1
- export const __rspack_esm_id=2486;export const __rspack_esm_ids=[2486];export const __webpack_modules__={421(e,r,a){a.r(r),a.d(r,{buildDoctorReport:()=>h,renderDoctorReport:()=>v});var i,o,t=a(99436),s=a(85382),n=a(31802),c=a(8479),l=a(7586),p=a(47988),u=(i=t(function*(){try{return yield Promise.all([a.e(1826),a.e(6645),a.e(4479),a.e(7648),a.e(6042),a.e(1010),a.e(7233)]).then(a.bind(a,63288)),{available:!0}}catch(e){return{available:!1,error:e.message}}}),function(){return i.apply(this,arguments)}),k=(e,r,a)=>({severity:e,code:r,message:a}),h=(o=t(function*({version:e="2.25.1-beta.3",mcpCheck:r=u}={}){var a=(0,p.getCurrentProfile)(),i=(0,p.getCurrentProfileSource)(),o=(0,n.getConnectionContext)(a),t=o.tokenInfo,h=o.auth,d=o.baseUrl,v=o.activityLogBaseUrl,m=[],w={ok:!1,timestamp:new Date().toISOString(),cli:{name:"bricks",version:e},profile:{name:a,source:i},config:{path:p.CONFIG_PATH,baseUrl:d,activityLogBaseUrl:v},auth:{available:!!h,source:h?"config":"missing",kind:h?.kind||null,workspaceId:t?.workspaceId||null,workspaceName:t?.workspaceName||null,createdAt:t?.createdAt||null,tokenPreview:h?.kind==="token"?(0,l.$l)(h.token):null},connectivity:{workspace:{ok:!1,skipped:!h,error:null}},capabilities:{zeroArgMode:(0,c.isInteractiveTerminal)()?"interactive":"help",mcp:{available:!1,error:null}},issues:m};if(h)try{var b=yield(0,s.createClient)(d,h).workspace();w.connectivity.workspace={ok:!0,skipped:!1,error:null,id:b?._id||t.workspaceId||null,name:b?.name||t.workspaceName||null},w.auth.workspaceId=b?._id||w.auth.workspaceId,w.auth.workspaceName=b?.name||w.auth.workspaceName}catch(e){w.connectivity.workspace={ok:!1,skipped:!1,error:e.message},m.push(k("error","workspace_unreachable",`Workspace query failed for ${d}: ${e.message}`))}else m.push(k("warning","auth_missing","No usable credential for the current profile."));var f=yield r();return w.capabilities.mcp={available:f.available,error:f.error||null},f.available||m.push(k("warning","mcp_unavailable",`MCP stdio server is unavailable: ${f.error||"Unknown error"}`)),w.ok=0===m.length,w}),function(){return o.apply(this,arguments)}),d=(e,r,a)=>`${e.padEnd(14)} ${r}${a?` ${a}`:""}`,v=e=>{var r=[];if(r.push("BRICKS CLI Doctor"),r.push("─".repeat(60)),r.push(d("CLI","OK",`bricks v${e.cli.version}`)),r.push(d("Profile","OK",`${e.profile.name} (${e.profile.source})`)),r.push(d("BRICKS API","OK",e.config.baseUrl)),r.push(d("Activity Log","OK",e.config.activityLogBaseUrl)),e.auth.available){var a=e.auth.workspaceName||e.auth.workspaceId||"Unknown workspace",i=[e.auth.source,e.auth.kind,e.auth.tokenPreview].filter(Boolean).join(", ");r.push(d("Auth","OK",i?`${a} (${i})`:a))}else r.push(d("Auth","WARN","No usable credential for the current profile"));if(e.connectivity.workspace.skipped)r.push(d("Workspace","WARN","Skipped because no credential is available"));else if(e.connectivity.workspace.ok){var o=e.connectivity.workspace.name||e.connectivity.workspace.id||"Unknown workspace";r.push(d("Workspace","OK",o))}else r.push(d("Workspace","FAIL",e.connectivity.workspace.error));return e.capabilities.mcp.available?r.push(d("MCP","OK","STDIO server import is available")):r.push(d("MCP","WARN",e.capabilities.mcp.error)),r.push(d("Zero-arg mode",((e,r=!1)=>e?"OK":r?"WARN":"FAIL")("interactive"===e.capabilities.zeroArgMode,"help"===e.capabilities.zeroArgMode),"interactive"===e.capabilities.zeroArgMode?"Starts Ink interactive mode on TTY":"Shows help outside TTY contexts")),e.issues.length>0&&(r.push("─".repeat(60)),r.push("Issues"),e.issues.forEach(e=>{r.push(`- [${e.severity}] ${e.message}`)})),r.join("\n")}}};
1
+ export const __rspack_esm_id=2486;export const __rspack_esm_ids=[2486];export const __webpack_modules__={421(e,r,a){a.r(r),a.d(r,{buildDoctorReport:()=>h,renderDoctorReport:()=>v});var i,o,t=a(99436),s=a(85382),n=a(31802),c=a(8479),l=a(7586),p=a(47988),u=(i=t(function*(){try{return yield Promise.all([a.e(1826),a.e(6645),a.e(4479),a.e(7648),a.e(6042),a.e(1010),a.e(7233)]).then(a.bind(a,63288)),{available:!0}}catch(e){return{available:!1,error:e.message}}}),function(){return i.apply(this,arguments)}),k=(e,r,a)=>({severity:e,code:r,message:a}),h=(o=t(function*({version:e="2.25.1-beta.6",mcpCheck:r=u}={}){var a=(0,p.getCurrentProfile)(),i=(0,p.getCurrentProfileSource)(),o=(0,n.getConnectionContext)(a),t=o.tokenInfo,h=o.auth,d=o.baseUrl,v=o.activityLogBaseUrl,m=[],w={ok:!1,timestamp:new Date().toISOString(),cli:{name:"bricks",version:e},profile:{name:a,source:i},config:{path:p.CONFIG_PATH,baseUrl:d,activityLogBaseUrl:v},auth:{available:!!h,source:h?"config":"missing",kind:h?.kind||null,workspaceId:t?.workspaceId||null,workspaceName:t?.workspaceName||null,createdAt:t?.createdAt||null,tokenPreview:h?.kind==="token"?(0,l.$l)(h.token):null},connectivity:{workspace:{ok:!1,skipped:!h,error:null}},capabilities:{zeroArgMode:(0,c.isInteractiveTerminal)()?"interactive":"help",mcp:{available:!1,error:null}},issues:m};if(h)try{var b=yield(0,s.createClient)(d,h).workspace();w.connectivity.workspace={ok:!0,skipped:!1,error:null,id:b?._id||t.workspaceId||null,name:b?.name||t.workspaceName||null},w.auth.workspaceId=b?._id||w.auth.workspaceId,w.auth.workspaceName=b?.name||w.auth.workspaceName}catch(e){w.connectivity.workspace={ok:!1,skipped:!1,error:e.message},m.push(k("error","workspace_unreachable",`Workspace query failed for ${d}: ${e.message}`))}else m.push(k("warning","auth_missing","No usable credential for the current profile."));var f=yield r();return w.capabilities.mcp={available:f.available,error:f.error||null},f.available||m.push(k("warning","mcp_unavailable",`MCP stdio server is unavailable: ${f.error||"Unknown error"}`)),w.ok=0===m.length,w}),function(){return o.apply(this,arguments)}),d=(e,r,a)=>`${e.padEnd(14)} ${r}${a?` ${a}`:""}`,v=e=>{var r=[];if(r.push("BRICKS CLI Doctor"),r.push("─".repeat(60)),r.push(d("CLI","OK",`bricks v${e.cli.version}`)),r.push(d("Profile","OK",`${e.profile.name} (${e.profile.source})`)),r.push(d("BRICKS API","OK",e.config.baseUrl)),r.push(d("Activity Log","OK",e.config.activityLogBaseUrl)),e.auth.available){var a=e.auth.workspaceName||e.auth.workspaceId||"Unknown workspace",i=[e.auth.source,e.auth.kind,e.auth.tokenPreview].filter(Boolean).join(", ");r.push(d("Auth","OK",i?`${a} (${i})`:a))}else r.push(d("Auth","WARN","No usable credential for the current profile"));if(e.connectivity.workspace.skipped)r.push(d("Workspace","WARN","Skipped because no credential is available"));else if(e.connectivity.workspace.ok){var o=e.connectivity.workspace.name||e.connectivity.workspace.id||"Unknown workspace";r.push(d("Workspace","OK",o))}else r.push(d("Workspace","FAIL",e.connectivity.workspace.error));return e.capabilities.mcp.available?r.push(d("MCP","OK","STDIO server import is available")):r.push(d("MCP","WARN",e.capabilities.mcp.error)),r.push(d("Zero-arg mode",((e,r=!1)=>e?"OK":r?"WARN":"FAIL")("interactive"===e.capabilities.zeroArgMode,"help"===e.capabilities.zeroArgMode),"interactive"===e.capabilities.zeroArgMode?"Starts Ink interactive mode on TTY":"Shows help outside TTY contexts")),e.issues.length>0&&(r.push("─".repeat(60)),r.push("Issues"),e.issues.forEach(e=>{r.push(`- [${e.severity}] ${e.message}`)})),r.join("\n")}}};
package/lib/3774.js CHANGED
@@ -2,7 +2,7 @@ export const __rspack_esm_id=3774;export const __rspack_esm_ids=[3774];export co
2
2
  # MCP entry-editing audit log
3
3
  ${l}
4
4
  `)}}),function(e){return i.apply(this,arguments)}),c=(n=a(function*(e,t){var r=o.join(e,".bricks");yield(0,s.mkdir)(r,{recursive:!0}),yield d(e),yield(0,s.appendFile)(o.join(r,"edits.jsonl"),`${JSON.stringify(t)}
5
- `)}),function(e,t){return n.apply(this,arguments)}),p=()=>({session:process.env.BRICKS_CTOR_SESSION_ID||process.env.CODEX_SESSION_ID,agent:process.env.BRICKS_CTOR_AGENT_ID||process.env.USER})},98009(e,t,r){r.d(t,{Gp:()=>l,HJ:()=>u,Hn:()=>a,JJ:()=>p,Kx:()=>y,Pb:()=>m,RI:()=>o,bf:()=>c,jc:()=>f,u4:()=>s,zu:()=>d});var i=r(58135),n=r(76760),a={trailingComma:"all",tabWidth:2,semi:!1,singleQuote:!0,printWidth:100},s=e=>!!e&&"object"==typeof e&&!Array.isArray(e),o=(e,t)=>n.relative(e,t).replace(/\\/g,"/").replace(/^\.\/+/,""),l=e=>i.isIdentifier(e)?e.name:i.isStringLiteral(e)||i.isNumericLiteral(e)?String(e.value):null,d=e=>/^[$A-Z_a-z][$\w]*$/.test(e)?i.identifier(e):i.stringLiteral(e),c=(e,t)=>e.properties.find(e=>!!i.isObjectProperty(e)&&l(e.key)===t),p=(e,t)=>{var r=c(e,t);if(r&&i.isStringLiteral(r.value))return r.value.value},u=(e,t,r)=>{var n=c(e,t);if(n){n.value=r;return}e.properties.push(i.objectProperty(d(t),r))},f=(e,t)=>{var r=e.properties.findIndex(e=>!!i.isObjectProperty(e)&&l(e.key)===t);r>=0&&e.properties.splice(r,1)},m=(e,t)=>{var r=e.program.body,n=r.findLastIndex(e=>i.isImportDeclaration(e));r.splice(n+1,0,t)},y=(e,t,r)=>{var n=new Set(Array.from(r).filter(Boolean));if(0!==n.size){var a,s=function(e){return i.isImportDeclaration(e)&&"bricks-ctor"===e.source.value&&"type"===t==("type"===e.importKind)?(e.specifiers.forEach(e=>{if(i.isImportSpecifier(e)){var t=e.imported;i.isIdentifier(t)&&n.delete(t.name),i.isStringLiteral(t)&&n.delete(t.value)}}),n.forEach(t=>{e.specifiers.push(i.importSpecifier(i.identifier(t),i.identifier(t)))}),{v:void 0}):0};for(var o of e.program.body)if(0!==(a=s(o))&&a)return a.v;var l=i.importDeclaration(Array.from(n).map(e=>i.importSpecifier(i.identifier(e),i.identifier(e))),i.stringLiteral("bricks-ctor"));"type"===t&&(l.importKind="type"),m(e,l)}}},54452(e,t,r){r.d(t,{H:()=>c});var i,n,a=r(99436),s=r(75720),o=r(2985),l={FORCE_COLOR:"0",NO_COLOR:"1"},d=(i=a(function*(e){var t=yield(0,o.Re)(e);try{yield(0,s.sh)`bun compile`.cwd(e).env({...l,BRICKS_CTOR_ENABLE_EDITING_TOOLS:"0"}).text()}catch(e){var r=[e.stdout?.toString()??"",e.stderr?.toString()??"",e.message].filter(Boolean).join("\n").trim();return{status:"compile:failed",errors:r?[r]:["bun compile failed"]}}var i=yield(0,o.Re)(e);return{status:"compile:ok",errors:[],configChange:(0,o.m4)(t,i)}}),function(e){return i.apply(this,arguments)}),c=(n=a(function*(e,t){return(void 0!==t?t:!["0","false","no","off"].includes((process.env.BRICKS_CTOR_MCP_EDIT_VERIFY??"true").toLowerCase()))?d(e):{status:"skipped",errors:[]}}),function(e,t){return n.apply(this,arguments)})},85949(e,t,r){r.a(e,async function(e,i){try{r.r(t),r.d(t,{__test__:()=>tm,register:()=>tf});var n,a,s,o,l,d,c,p,u,f,m,y,v,h,b,w,x,g,_,j,P,k,E,S,$,A,I,O,C,N,T=r(68832),R=r(99436),D=r(44668),F=r(5018),L=r(63315),B=r(30409),K=r(40906),U=r(59410),z=r(2235),q=r(46773),M=r(80004),Y=r(58135),J=r(11978),H=r(79491),V=r(51455),G=r(77598),W=r(76760),X=r(84867),Z=r(54452),Q=r(98009),ee=r(3540),et=e([H]);function er(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(er=function(){return!!e})()}H=(et.then?(await et)():et)[0];var ei=z.default||z,en=M.default||M,ea={"bricks.ts":{kind:"brick",namespace:"bricks",varPrefix:"b",idType:"brick",idPrefix:"BRICK_",typename:"Brick"},"generators.ts":{kind:"generator",namespace:"generators",varPrefix:"g",idType:"generator",idPrefix:"GENERATOR_",typename:"Generator"},"canvases.ts":{kind:"canvas",namespace:"canvases",varPrefix:"c",idType:"canvas",idPrefix:"CANVAS_",typename:"Canvas"},"data.ts":{kind:"data",namespace:"data",varPrefix:"d",idType:"data",idPrefix:"PROPERTY_BANK_DATA_NODE_",typename:"Data"},"animations.ts":{kind:"animation",namespace:"animations",varPrefix:"a",idType:"animation",idPrefix:"ANIMATION_",typename:"Animation"}},es=function(e){function t(e,r,i,n=!1){var a,s,o;return F(this,t),s=t,o=[r],s=B(s),(a=L(this,er()?Reflect.construct(s,o||[],B(this).constructor):s.apply(this,o))).name="EntryEditingError",a.code=e,a.details=i,a.isMcpError=n,a}return K(t,e),D(t)}(U(Error)),eo=(e,t)=>{if(W.isAbsolute(t))throw new es("invalid_file","File must be project-relative",{file:t});var r=W.resolve(e,t),i=W.relative(e,r);if(i.startsWith("..")||W.isAbsolute(i))throw new es("invalid_file","File must stay inside the project directory",{file:t});return r},el=(e,t)=>{try{return(0,q.parse)(e,{sourceType:"module",plugins:["typescript","topLevelAwait"],errorRecovery:!1})}catch(e){throw new es("parse_failed",`Cannot parse ${t} as TypeScript: ${e.message}. Edit this file directly.`,{file:t},!0)}},ed=(n=R(function*(e,t){var r=yield(0,V.readFile)(t,"utf8"),i=(0,Q.RI)(e,t);return{source:r,ast:el(r,i),absPath:t,relPath:i,kind:(e=>{var t=W.basename(e),r=ea[t];if(!r)throw new es("unsupported_file",`Unsupported entry file: ${t}`,{file:e,expected:Object.keys(ea)});return r})(t)}}),function(e,t){return n.apply(this,arguments)}),ec=e=>e.program.body.flatMap(e=>{if(!Y.isExportNamedDeclaration(e)||!Y.isVariableDeclaration(e.declaration))return[];var t=e.declaration;return t.declarations.flatMap(r=>{if(!Y.isIdentifier(r.id))return[];var i,n=r.id.typeAnnotation;Y.isTSTypeAnnotation(n)&&Y.isTSTypeReference(n.typeAnnotation)&&Y.isIdentifier(n.typeAnnotation.typeName)&&(i=n.typeAnnotation.typeName.name);var a=Y.isObjectExpression(r.init)?r.init:void 0;return[{name:r.id.name,node:e,declaration:t,declarator:r,object:a,id:a?(0,Q.JJ)(a,"id"):void 0,alias:a?(0,Q.JJ)(a,"alias"):void 0,typeName:i}]})}),ep=(e,t)=>{var r=ec(e.ast);if(t.entry){var i=r.find(e=>e.name===t.entry);if(i)return i;var n=r.filter(e=>e.alias===t.entry);if(1===n.length)return n[0];if(n.length>1)throw new es("ambiguous_reference",`Alias is ambiguous: ${t.entry}`,{file:e.relPath,entry:t.entry,matches:n.map(e=>e.name)});throw new es("entry_not_found",`Entry not found (by name or alias): ${t.entry}`,{file:e.relPath,entry:t.entry})}if(t.id){var a=r.find(e=>e.id===t.id);if(!a)throw new es("entry_not_found",`Entry id not found: ${t.id}`,{file:e.relPath,id:t.id});return a}throw new es("missing_target","Provide entry or id")},eu=e=>e.split(W.sep).find(e=>/^subspace-\d+$/.test(e))||"unknown-subspace",ef=e=>{var t=e.split(W.sep),r=t.findIndex(e=>/^subspace-\d+$/.test(e));if(r<0)throw new es("invalid_file","Entry file must be inside subspaces/subspace-N",{file:e});return t.slice(0,r+1).join(W.sep)},em=(a=R(function*(e){var t=W.join(e,"subspaces");return(yield(0,V.readdir)(t,{withFileTypes:!0}).catch(()=>[])).filter(e=>e.isDirectory()&&/^subspace-\d+$/.test(e.name)).map(e=>W.join(t,e.name)).sort()}),function(e){return a.apply(this,arguments)}),ey=(s=R(function*(e){var t=Object.keys(ea),r=yield(0,V.readdir)(e,{withFileTypes:!0}).catch(()=>[]),i=new Set(r.filter(e=>e.isFile()).map(e=>e.name));return t.filter(e=>i.has(e)).map(t=>W.join(e,t))}),function(e){return s.apply(this,arguments)}),ev=(o=R(function*(e){var t=yield em(e);return(yield Promise.all(t.map(ey))).flat()}),function(e){return o.apply(this,arguments)}),eh=(l=R(function*(e,t){if(t.file)return eo(e,t.file);if(!t.id)throw new es("missing_file","Provide file, or provide id for global lookup");for(var r of yield ev(e)){var i=yield ed(e,r);if(ec(i.ast).find(e=>e.id===t.id))return r}throw new es("entry_not_found",`Entry id not found: ${t.id}`,{id:t.id})}),function(e,t){return l.apply(this,arguments)}),eb=(d=R(function*(e,t){var r=yield eh(e,t),i=yield ed(e,r),n=ep(i,t),a=((e,t)=>{if(!e.object)throw new es("fallback_recommended",`Entry ${e.name} in ${t} is not a top-level exported object literal. Edit this file directly for this one.`,{file:t,entry:e.name,check:"top-level export const object literal"});return e.object})(n,i.relPath);return{parsed:i,entry:n,object:a}}),function(e,t){return d.apply(this,arguments)}),ew=(e,t)=>Y.callExpression(Y.identifier("makeId"),t?[Y.stringLiteral(e),Y.stringLiteral(t)]:[Y.stringLiteral(e)]),ex=e=>{var t=[];for(var r of e.split(".").filter(Boolean))for(var i=/([^\[\]]+)|\[(\d+)\]/g,n=void 0;n=i.exec(r);)n[1]&&t.push({key:n[1]}),n[2]&&t.push({index:Number(n[2])});if(0===t.length)throw new es("invalid_path",`Invalid path: ${e}`,{path:e});return t},eg=e=>Y.isTSAsExpression(e)||Y.isTSSatisfiesExpression(e)||Y.isTSNonNullExpression(e)||Y.isParenthesizedExpression(e)?eg(e.expression):e,e_=(e,t)=>{var r=eg(e);if(!Y.isObjectExpression(r))throw new es("fallback_recommended",`Target path ${t} is not an object literal. Edit this file directly for this one.`,{path:t,expected:"object literal",actual:r.type});return r},ej=(e,t)=>{var r=eg(e);if(!Y.isArrayExpression(r))throw new es("fallback_recommended",`Target path ${t} is not an array literal. Edit this file directly for this one.`,{path:t,expected:"array literal",actual:r.type});return r},eP=e=>"array"==("index"in e?"array":"object")?Y.arrayExpression([]):Y.objectExpression([]),ek=(c=R(function*(e,t,r,i){for(var n=ex(t),a=e,s=0;s<n.length;s+=1){var o=n[s],l=s===n.length-1;if("key"in o){var d=e_(a,t);if(l)return void(0,Q.HJ)(d,o.key,(yield eF(r,i)));var c=n[s+1],p=(0,Q.bf)(d,o.key);p||(p=Y.objectProperty((0,Q.zu)(o.key),eP(c)),d.properties.push(p)),a=p.value;continue}var u=ej(a,t);if(o.index<0||o.index>u.elements.length)throw new es("invalid_path",`Array index out of range for ${t}`,{path:t,index:o.index});if(l){u.elements[o.index]=yield eF(r,i);return}u.elements[o.index]||(u.elements[o.index]=eP(n[s+1])),a=u.elements[o.index]}}),function(e,t,r,i){return c.apply(this,arguments)}),eE=(e,t)=>{for(var r=ex(t),i=e,n=0;n<r.length;n+=1){var a=r[n],s=n===r.length-1;if("key"in a){var o=e_(i,t);if(s)return void(0,Q.jc)(o,a.key);var l=(0,Q.bf)(o,a.key);if(!l)return;i=l.value;continue}var d=ej(i,t);if(a.index<0||a.index>=d.elements.length)return;if(s)return void d.elements.splice(a.index,1);var c=d.elements[a.index];if(!c)return;i=c}},eS=(e,t)=>{var r=(0,Q.bf)(e,"switches");if(!r)throw new es("fallback_recommended","Entry has no switches array",{path:"switches"});var i=ej(r.value,"switches"),n="number"==typeof t?t:i.elements.findIndex(e=>Y.isObjectExpression(e)&&(0,Q.JJ)(e,"id")===t);if(n<0||n>=i.elements.length)throw new es("entry_not_found",`Switch not found: ${t}`,{switch:t});var a=i.elements[n];if(!Y.isObjectExpression(a))throw new es("fallback_recommended",`Switch ${String(t)} is not an object literal. Edit this file directly for this one.`,{switch:t});return a},e$=(e,t)=>{var r=t.replace(/\.[tj]sx?$/,""),i=W.relative(W.dirname(e),r).replace(/\\/g,"/");return i.startsWith(".")||(i=`./${i}`),i},eA=e=>{var t=new Set;return e.program.body.forEach(e=>{Y.isImportDeclaration(e)?e.specifiers.forEach(e=>t.add(e.local.name)):Y.isExportNamedDeclaration(e)&&Y.isVariableDeclaration(e.declaration)&&e.declaration.declarations.forEach(e=>{Y.isIdentifier(e.id)&&t.add(e.id.name)})}),t},eI=(e,t,r)=>{for(var i of e.ast.program.body)if(Y.isImportDeclaration(i)&&i.source.value===t){var n=i.specifiers.find(e=>Y.isImportDefaultSpecifier(e));if(n)return n.local.name}var a=eA(e.ast),s=r;if(a.has(s)){for(var o=1;a.has(`${s}${o}`);)o+=1;s=`${s}${o}`}var l=Y.importDeclaration([Y.importDefaultSpecifier(Y.identifier(s))],Y.stringLiteral(t));return(0,Q.Pb)(e.ast,l),s},eO=e=>{(0,Q.Kx)(e.parsed.ast,"type",e.typeImports),(0,Q.Kx)(e.parsed.ast,"value",e.valueImports)},eC=(p=R(function*(e,t,r){if(null==r||""===r)return t;if("number"==typeof r)return W.join(e,"subspaces",`subspace-${r}`);var i=String(r);if(/^\d+$/.test(i))return W.join(e,"subspaces",`subspace-${i}`);if(/^subspace-\d+$/.test(i))return W.join(e,"subspaces",i);if(i.includes("/"))return eo(e,i);var n,a=yield em(e),s=function*(){var t=W.join(o,"index.ts"),r=yield(0,V.readFile)(t,"utf8").catch(()=>"");if(!r)return 0;var n=el(r,(0,Q.RI)(e,t)),a=!1;if(en(n,{ObjectProperty(e){"id"===(0,Q.Gp)(e.node.key)&&Y.isStringLiteral(e.node.value)&&e.node.value.value===i&&(a=!0,e.stop())}}),a)return{v:o}};for(var o of a)if(n=yield*s(),0!==n&&n)return n.v;throw new es("reference_not_found",`Subspace not found: ${i}`,{subspace:i})}),function(e,t,r){return p.apply(this,arguments)}),eN=(u=R(function*(e,t){var r,i,n=ef(e.parsed.absPath),a=yield eC(e.projectDir,n,t),s=W.basename(a),o=/^subspace-(\d+)$/.exec(s);if(!o)throw new es("invalid_subspace",`Not a subspace directory: ${s}`,{subspace:t});var l=W.join(a,"index.ts"),d=yield(0,V.readFile)(l,"utf8").catch(()=>null);if(null==d)throw new es("reference_not_found",`Subspace not found: ${t}`,{subspace:t});var c=(r=el(d,(0,Q.RI)(e.projectDir,l)),en(r,{ObjectProperty(e){if("id"===(0,Q.Gp)(e.node.key)){var t=e.node.value;Y.isStringLiteral(t)&&t.value.startsWith("SUBSPACE_")&&(i=t.value,e.stop())}}}),i);if(!c)throw new es("invalid_subspace",`Subspace index has no SUBSPACE_ id: ${s}/index.ts`,{subspace:t});return{id:c,index:Number(o[1]),label:s,indexPath:l,isCurrent:W.resolve(a)===W.resolve(n)}}),function(e,t){return u.apply(this,arguments)}),eT=(f=R(function*(e,t){var r=yield eN(e,t);if(r.isCurrent)return e.references.push({input:t,id:r.id,sameFile:!1,display:`'${r.id}'`,targetAbsPath:r.indexPath}),{resolved:r,expression:Y.stringLiteral(r.id)};var i=eI(e.parsed,`../${r.label}`,`subspace${r.index}`);return e.references.push({input:t,id:r.id,sameFile:!1,display:`() => ${i}`,targetAbsPath:r.indexPath}),{resolved:r,expression:Y.arrowFunctionExpression([],Y.identifier(i))}}),function(e,t){return f.apply(this,arguments)}),eR=(m=R(function*(e,t,r,i){var n=ef(t),a=yield eC(e,n,i),s=yield ey(a),o=[];for(var l of s){var d=yield ed(e,l),c=d.kind;for(var p of ec(d.ast))if(p.name===r||p.id===r||p.alias===r){var u=W.resolve(l)===W.resolve(t),f=W.basename(a);o.push({input:r,id:p.id,alias:p.alias,varName:p.name,namespace:c.namespace,display:`${c.namespace}.${p.name}`,targetAbsPath:l,sameFile:u,subspaceLabel:f,importSource:u?void 0:e$(t,l)})}}if(0===o.length)throw new es("reference_not_found",`Reference not found: ${r}`,{ref:r,subspace:i??W.basename(n)});if(o.length>1)throw new es("ambiguous_reference",`Reference is ambiguous: ${r}`,{ref:r,matches:o.map(t=>({file:(0,Q.RI)(e,t.targetAbsPath),entry:t.varName,id:t.id,alias:t.alias}))});return o[0]}),function(e,t,r,i){return m.apply(this,arguments)}),eD=(y=R(function*(e,t,r){var i=yield eR(t.projectDir,t.parsed.absPath,e,r);if(i.sameFile)return t.references.push(i),Y.identifier(i.varName);var n=ef(t.parsed.absPath),a=ef(i.targetAbsPath),s=i.subspaceLabel.replace(/[^a-zA-Z0-9_$]/g,""),o=n===a?i.namespace:`${s}${i.namespace[0].toUpperCase()}${i.namespace.slice(1)}`,l=((e,t,r,i)=>{for(var n of e.ast.program.body)if(Y.isImportDeclaration(n)&&n.source.value===r){var a=n.specifiers.find(Y.isImportNamespaceSpecifier);if(a)return a.local.name}var s=eA(e.ast),o=i;if(s.has(o)){for(var l=1;s.has(`${o}${l}`);)l+=1;o=`${o}${l}`}var d=Y.importDeclaration([Y.importNamespaceSpecifier(Y.identifier(o))],Y.stringLiteral(r));return(0,Q.Pb)(e.ast,d),o})(t.parsed,i.namespace,i.importSource,o);return i.importLocal=l,t.references.push({...i,display:`${l}.${i.varName}`,importLocal:l}),Y.memberExpression(Y.identifier(l),Y.identifier(i.varName))}),function(e,t,r){return y.apply(this,arguments)}),eF=(v=R(function*(e,t){if((0,Q.u4)(e)&&"string"==typeof e.expr&&1===Object.keys(e).length){var r=e.expr;try{return(0,q.parseExpression)(r,{plugins:["typescript"]})}catch(e){throw new es("invalid_expr",`Invalid TypeScript expression: ${e.message}`,{expr:r})}}if((0,Q.u4)(e)&&"string"==typeof e.link){t.valueImports.add("linkData");var i=yield eD(e.link,t,e.subspace);return Y.callExpression(Y.identifier("linkData"),[Y.arrowFunctionExpression([],i)])}if((0,Q.u4)(e)&&"string"==typeof e.ref){var n=yield eD(e.ref,t,e.subspace);return Y.arrowFunctionExpression([],n)}if(Array.isArray(e))return Y.arrayExpression((yield Promise.all(e.map(e=>eF(e,t)))));if((0,Q.u4)(e)){var a,s=yield Promise.all(Object.entries(e).map((a=R(function*([e,r]){return Y.objectProperty((0,Q.zu)(e),(yield eF(r,t)))}),function(e){return a.apply(this,arguments)})));return Y.objectExpression(s)}return void 0===e?Y.identifier("undefined"):Y.valueToNode(e)}),function(e,t){return v.apply(this,arguments)}),eL=e=>e.map(e=>({input:e.input,id:e.id,alias:e.alias,resolved:e.importLocal?`${e.importLocal}.${e.varName}`:e.sameFile?e.varName:e.display,file:e.targetAbsPath})),eB=(h=R(function*(e){var t=ei(e.ast,{comments:!0},e.source).code,r=yield(0,H.format)(e.absPath,t,Q.Hn);if(r.errors.length>0)throw new es("format_failed",`oxfmt failed for ${e.relPath}`,{file:e.relPath,errors:r.errors});return r.code}),function(e){return h.apply(this,arguments)}),eK=(b=R(function*(e){var t=yield eB(e);return el(t,e.relPath),yield(0,V.writeFile)(e.absPath,t),t}),function(e){return b.apply(this,arguments)}),eU=(e,t)=>{if(e){var r=eu(e.absPath);return`${t?.name||"entry"} (${e.kind.kind}, ${r})`}},ez=(w=R(function*(e,t,r,i){var n={ts:new Date().toISOString(),tool:t,op:r?.op||(r?.set?"set":r?.unset?"unset":t),target:{file:r?.file,entry:r?.entry,id:r?.id},provenance:(0,ee.S)()};try{var a=yield i(),s={...n,...a};return yield(0,ee.a)(e,s).catch(e=>{s.auditError=e.message}),s}catch(i){var o=i instanceof es?i:new es("error",i.message||String(i),void 0,!0),l="fallback_recommended"===o.code?"fallback_recommended":"error",d={...n,outcome:l,input:r,error:{code:o.code,message:o.message,details:o.details},summary:"fallback_recommended"===l?`${t} could not safely edit this standard path; edit the file directly`:`${t} failed: ${o.message}`,isError:o.isMcpError||"error"===l};return yield(0,ee.a)(e,d).catch(e=>{d.auditError=e.message}),d}}),function(e,t,r,i){return w.apply(this,arguments)}),eq=(x=R(function*(e,t){return ez(e,"edit_entry",t,R(function*(){var r=yield eb(e,t),i=r.parsed,n=r.entry,a=r.object,s={projectDir:e,parsed:i,references:[],typeImports:new Set,valueImports:new Set},o=null==t.switch?a:eS(a,t.switch);for(var l of Object.entries(t.set||{})){var d=T(l,2),c=d[0],p=d[1];yield ek(o,c,p,s)}for(var u of[...t.unset||[]].sort((e,t)=>{for(var r=ex(e).map(e=>"index"in e?e.index:-1),i=ex(t).map(e=>"index"in e?e.index:-1),n=0;n<Math.min(r.length,i.length);n+=1)if(r[n]!==i[n])return i[n]-r[n];return i.length-r.length}))eE(o,u);eO(s),yield eK(i);var f=yield(0,Z.H)(e,t.verify),m=eU(i,n);return{file:i.relPath,entry:n.name,id:n.id,change:{set:t.set||{},unset:t.unset||[],references:eL(s.references)},outcome:"compile:failed"===f.status?"verify_failed":"ok",verify:f,summary:`edited ${m} -> ${f.status}`}}))}),function(e,t){return x.apply(this,arguments)}),eM=e=>{switch(e){case"IfStatement":return"an if statement";case"ForStatement":case"ForOfStatement":case"ForInStatement":return"a for loop";case"WhileStatement":case"DoWhileStatement":return"a while loop";case"SwitchStatement":return"a switch statement";case"TryStatement":return"a try/catch block";case"FunctionDeclaration":return"a function declaration";case"ReturnStatement":return"a return before the final statement";default:return`a ${e}`}},eY=(e,t)=>{for(var r=0;r<e.length;r+=1){var i=e[r],n=r===e.length-1;if("ExpressionStatement"===i.type){var a=eJ(i.expression);if(a)return a;continue}if("VariableDeclaration"===i.type){for(var s of i.declarations)if("Identifier"!==s.id.type||!s.init)return"a destructuring or uninitialized declaration";continue}if(t&&n&&"ReturnStatement"===i.type){var o=i.argument?eJ(i.argument):null;if(o)return o;continue}return eM(i.type)}return null},eJ=e=>{if(e?.type!=="CallExpression"||e.arguments?.length||e.callee?.type!=="ArrowFunctionExpression"&&e.callee?.type!=="FunctionExpression")return null;var t=e.callee.body;return t?.type==="BlockStatement"?eY(t.body,!0):eJ(t)},eH=(g=R(function*(e,t){if(e?.expr)return eF(e,t);var r,i=(e=>{if(!(0,Q.u4)(e)||!(0,Q.u4)(e.action))return e;var t=e.action,r={handler:e.handler,name:t.name??t.__actionName,waitAsync:e.waitAsync};if(t.cast&&(r.cast=t.cast),Array.isArray(t.params))for(var i of(r.params={},t.params)){if(!(0,Q.u4)(i)||"string"!=typeof i.input)throw new es("invalid_action",'Compiled action params entries require { input: "name", value }',{param:i});r.params[i.input]=i.value}if(Array.isArray(t.dataParams))for(var n of(r.dataParams={},t.dataParams)){var a=(0,Q.u4)(n?.input)?n.input.ref:n?.input;if("string"!=typeof a||!a)throw new es("invalid_action","Compiled action dataParams entries require { input: dataRef, value }",{param:n});r.dataParams[a]=n.value}return r})(e),n=i?.name;if(!n)throw new es("invalid_action","Action requires name");if("PROPERTY_BANK_EXPRESSION"===n&&(0,Q.u4)(i.params)){var a=i.params.expression;"string"==typeof a&&(e=>{try{t=(0,J.qg)(e,{ecmaVersion:2020})}catch(t){throw new es("invalid_action",`PROPERTY_BANK_EXPRESSION does not parse: ${t.message}`,{expression:e})}var t,r=eY(t.body,!1);if(r)throw new es("invalid_action",`PROPERTY_BANK_EXPRESSION cannot evaluate ${r}: the runtime folds the expression into a single expression (expression statements, simple const/let declarations, and a final return inside an IIFE only). Use ternaries instead of statements, or move branching logic to a DataCalculationScript.`,{expression:e})})(a)}var s="System",o=i.cast;if("system"===i.handler||null==i.handler)r=Y.stringLiteral("system"),o||=`SystemAction${n.toLowerCase().split("_").filter(Boolean).map(e=>`${e[0].toUpperCase()}${e.slice(1)}`).join("")}`;else if((0,Q.u4)(i.handler)&&"string"==typeof i.handler.ref){var l=yield eR(t.projectDir,t.parsed.absPath,i.handler.ref,i.handler.subspace);if("bricks"!==l.namespace&&"generators"!==l.namespace)throw new es("invalid_action",`Action handler must be a brick or generator, got ${l.namespace}: ${i.handler.ref}`,{handler:i.handler});s="bricks"===l.namespace?"Brick":"Generator";var d=yield eD(i.handler.ref,t,i.handler.subspace);r=Y.arrowFunctionExpression([],d)}else if((0,Q.u4)(i.handler)&&null!=i.handler.subspace)r=(yield eT(t,i.handler.subspace)).expression,s="Subspace";else throw new es("invalid_action","Unsupported action handler",{handler:i.handler});var c=[Y.objectProperty(Y.identifier("__actionName"),Y.stringLiteral(n)),Y.objectProperty(Y.identifier("parent"),Y.stringLiteral(s)),Y.objectProperty(Y.identifier("name"),Y.stringLiteral(n))];if(i.params){var p,u=yield Promise.all(Object.entries(i.params).map((p=R(function*([e,r]){return Y.objectExpression([Y.objectProperty(Y.identifier("input"),Y.stringLiteral(e)),Y.objectProperty(Y.identifier("value"),(yield eF(r,t)))])}),function(e){return p.apply(this,arguments)})));c.push(Y.objectProperty(Y.identifier("params"),Y.arrayExpression(u)))}if(i.dataParams){var f,m=yield Promise.all(Object.entries(i.dataParams).map((f=R(function*([e,r]){var i=yield eD(e,t);return Y.objectExpression([Y.objectProperty(Y.identifier("input"),Y.arrowFunctionExpression([],i)),Y.objectProperty(Y.identifier("value"),(yield eF(r,t)))])}),function(e){return f.apply(this,arguments)})));c.push(Y.objectProperty(Y.identifier("dataParams"),Y.arrayExpression(m)))}var y=Y.objectExpression(c);return o&&(t.typeImports.add(o),y=Y.tsAsExpression(y,Y.tsTypeReference(Y.identifier(o)))),Y.objectExpression([Y.objectProperty(Y.identifier("handler"),r),Y.objectProperty(Y.identifier("action"),y),Y.objectProperty(Y.identifier("waitAsync"),Y.booleanLiteral(!!i.waitAsync))])}),function(e,t){return g.apply(this,arguments)}),eV=(e,t,r)=>{var i=(0,Q.bf)(e,t);return i||(i=Y.objectProperty((0,Q.zu)(t),Y.objectExpression([])),e.properties.push(i)),e_(i.value,r)},eG=(e,t,r)=>{var i=(0,Q.bf)(e,t);return i||(i=Y.objectProperty((0,Q.zu)(t),Y.arrayExpression([])),e.properties.push(i)),ej(i.value,r)},eW=(_=R(function*(e,t){return ez(e,"edit_events",t,R(function*(){var r=yield eb(e,t),i=r.parsed,n=r.entry,a=r.object,s={projectDir:e,parsed:i,references:[],typeImports:new Set,valueImports:new Set},o=null==t.switch?a:eS(a,t.switch),l=t.op;if("clear"===l||"remove"===l||"move"===l){var d=(0,Q.bf)(o,"events"),c=d?e_(d.value,"events"):null,p=c?(0,Q.bf)(c,t.event):null,u=p?ej(p.value,`events.${t.event}`):null;if("clear"===l)c&&(0,Q.jc)(c,t.event);else if("move"===l){if(null==t.index)throw new es("invalid_index","move requires index");if(!u||t.index<0||t.index>=u.elements.length)throw new es("invalid_index","move index out of range",{index:t.index});var f=Number(t.to);if(!Number.isFinite(f)||f<0||f>=u.elements.length)throw new es("invalid_index","move requires valid to index",{to:t.to});var m=u.elements.splice(t.index,1),y=T(m,1)[0];u.elements.splice(f,0,y)}else{if(null==t.index)throw new es("invalid_index","remove requires index");if(!u||t.index<0||t.index>=u.elements.length)throw new es("invalid_index","remove index out of range",{index:t.index});u.elements.splice(t.index,1),0===u.elements.length&&c&&(0,Q.jc)(c,t.event)}}else if("add"===l||"replace"===l){var v=yield eH(t.action,s),h=eV(o,"events","events"),b=eG(h,t.event,`events.${t.event}`),w=t.index??b.elements.length;if("replace"===l){if(w<0||w>=b.elements.length)throw new es("invalid_index","replace index out of range",{index:w});b.elements[w]=v}else{if(w<0||w>b.elements.length)throw new es("invalid_index","add index out of range",{index:w});b.elements.splice(w,0,v)}}else throw new es("invalid_op",`Unsupported edit_events op: ${l}`);eO(s),yield eK(i);var x=yield(0,Z.H)(e,t.verify);return{file:i.relPath,entry:n.name,id:n.id,change:{event:t.event,op:l,index:t.index,references:eL(s.references)},outcome:"compile:failed"===x.status?"verify_failed":"ok",verify:x,summary:`${l} event ${t.event} on ${eU(i,n)} -> ${x.status}`}}))}),function(e,t){return _.apply(this,arguments)}),eX=e=>{if((0,Q.u4)(e)&&"string"==typeof e.expr)return e;if(!(0,Q.u4)(e))throw new es("invalid_item","Canvas item requires frame { x, y, width, height }");for(var t of["x","y","width","height"])if("number"!=typeof e[t])throw new es("invalid_item",`Canvas item frame requires numeric ${t}`,{frame:e});return e},eZ=(j=R(function*(e,t,r){if(!e?.ref&&e?.subspace==null)throw new es("invalid_item","Canvas item requires ref (brick) or subspace (embed)");var i,n=eX(e.frame??r);if(e.ref){var a=yield eD(e.ref,t,e.subspace);i=Y.arrowFunctionExpression([],a)}else{var s=yield eT(t,e.subspace),o=s.resolved,l=s.expression;if(o.isCurrent)throw new es("invalid_item","A subspace cannot embed itself",{subspace:e.subspace});i=l}return Y.objectExpression([Y.objectProperty(Y.identifier("item"),i),Y.objectProperty(Y.identifier("frame"),(yield eF(n,t))),...null==e.hidden?[]:[Y.objectProperty(Y.identifier("hidden"),Y.booleanLiteral(!!e.hidden))]])}),function(e,t,r){return j.apply(this,arguments)}),eQ=(P=R(function*(e,t){return ez(e,"edit_canvas_items",t,R(function*(){var r=yield eb(e,t),i=r.parsed,n=r.entry,a=r.object;if("canvas"!==i.kind.kind)throw new es("invalid_file","edit_canvas_items only edits canvases.ts entries",{file:i.relPath});var s={projectDir:e,parsed:i,references:[],typeImports:new Set,valueImports:new Set},o=eG(a,"items","items"),l=t.op;if("add"===l||"replace"===l){var d=yield eZ(t.item,s,t.frame),c=t.index??o.elements.length;if("replace"===l){if(c<0||c>=o.elements.length)throw new es("invalid_index","replace index out of range",{index:c});o.elements[c]=d}else{if(c<0||c>o.elements.length)throw new es("invalid_index","add index out of range",{index:c});o.elements.splice(c,0,d)}}else if("remove"===l){if(null==t.index)throw new es("invalid_index","remove requires index");if(t.index<0||t.index>=o.elements.length)throw new es("invalid_index","remove index out of range",{index:t.index});o.elements.splice(t.index,1)}else if("move"===l){if(null==t.index)throw new es("invalid_index","move requires index");if(!t.frame)throw new es("invalid_item","move requires frame");if(t.index<0||t.index>=o.elements.length)throw new es("invalid_index","move index out of range",{index:t.index});var p=o.elements[t.index];if(!Y.isObjectExpression(p))throw new es("fallback_recommended","Canvas item is not an object literal",{index:t.index});(0,Q.HJ)(p,"frame",(yield eF(eX(t.frame),s)))}else throw new es("invalid_op",`Unsupported edit_canvas_items op: ${l}`);eO(s),yield eK(i);var u=yield(0,Z.H)(e,t.verify);return{file:i.relPath,entry:n.name,id:n.id,change:{op:l,index:t.index,references:eL(s.references)},outcome:"compile:failed"===u.status?"verify_failed":"ok",verify:u,summary:`${l} canvas item on ${eU(i,n)} -> ${u.status}`}}))}),function(e,t){return P.apply(this,arguments)}),e0=(k=R(function*(e,t){var r=(e=>{switch(e?.__typename){case"SwitchCondInnerStateCurrentCanvas":return{type:"inner_state",key:"current_canvas",value:e.value,subspace:e.subspace};case"SwitchCondInnerStateOutlet":return{type:"inner_state",outlet:e.outlet,value:e.value};case"SwitchCondData":return{type:"property_bank",ref:e.data??e.ref,value:e.value,subspace:e.subspace};case"SwitchCondPropertyBankByItemKey":return{type:"property_bank_by_item_key",ref:e.data??e.ref,value:e.value,subspace:e.subspace};default:return e}})(e);if(r?.expr)return eF(r,t);if(r?.type==="inner_state"&&"current_canvas"===r.key){var i=yield eD(r.value,t,r.subspace);return Y.objectExpression([Y.objectProperty(Y.identifier("__typename"),Y.stringLiteral("SwitchCondInnerStateCurrentCanvas")),Y.objectProperty(Y.identifier("value"),Y.arrowFunctionExpression([],i))])}if(r?.type==="inner_state"){var n=r.outlet||r.key;if(!n)throw new es("invalid_switch","Switch inner-state outlet condition requires outlet or key");return Y.objectExpression([Y.objectProperty(Y.identifier("__typename"),Y.stringLiteral("SwitchCondInnerStateOutlet")),Y.objectProperty(Y.identifier("outlet"),Y.stringLiteral(n)),Y.objectProperty(Y.identifier("value"),(yield eF(r.value,t)))])}var a=r?.ref||r?.data||r?.key;if(!a)throw new es("invalid_switch","Switch condition requires data ref");var s=yield eD(a,t,r.subspace);return Y.objectExpression([Y.objectProperty(Y.identifier("__typename"),Y.stringLiteral(r?.type==="property_bank_by_item_key"?"SwitchCondPropertyBankByItemKey":"SwitchCondData")),Y.objectProperty(Y.identifier("data"),Y.arrowFunctionExpression([],s)),Y.objectProperty(Y.identifier("value"),(yield eF(r.value,t)))])}),function(e,t){return k.apply(this,arguments)}),e1=new Set(["id","title","description","conds","override","property","outlets","animation","events","disabled","break"]),e4=(E=R(function*(e,t){for(var r of Object.keys(e))if(!e1.has(r))throw new es("invalid_switch",`Unknown switch field: ${r}`,{field:r,supported:Array.from(e1)});if(void 0!==e.events)throw new es("invalid_switch","Set switch events with edit_events using its switch parameter");if(e.id&&!/^BRICK_STATE_GROUP_[0-9a-fA-F-]{36}$/.test(e.id))throw new es("invalid_switch","Switch id must match BRICK_STATE_GROUP_<uuid>; omit id to generate one",{id:e.id});var i,n=e.id?Y.stringLiteral(e.id):ew("switch");e.id||t.valueImports.add("makeId");var a=[Y.objectProperty(Y.identifier("id"),n)];for(var s of(null!=e.title&&a.push(Y.objectProperty(Y.identifier("title"),Y.stringLiteral(e.title))),null!=e.description&&a.push(Y.objectProperty(Y.identifier("description"),Y.stringLiteral(e.description))),e.conds&&a.push(Y.objectProperty(Y.identifier("conds"),Y.arrayExpression((yield Promise.all(e.conds.map((i=R(function*(e){return Y.objectExpression([Y.objectProperty(Y.identifier("method"),Y.stringLiteral(e.method||"==")),Y.objectProperty(Y.identifier("cond"),(yield e0(e.cond||e,t)))])}),function(e){return i.apply(this,arguments)}))))))),e.override&&a.push(Y.objectProperty(Y.identifier("override"),(yield eF(e.override,t)))),["property","outlets","animation"]))null!=e[s]&&a.push(Y.objectProperty(Y.identifier(s),(yield eF(e[s],t))));return null!=e.disabled&&a.push(Y.objectProperty(Y.identifier("disabled"),Y.booleanLiteral(!!e.disabled))),null!=e.break&&a.push(Y.objectProperty(Y.identifier("break"),Y.booleanLiteral(!!e.break))),Y.objectExpression(a)}),function(e,t){return E.apply(this,arguments)}),e5=(S=R(function*(e,t){return ez(e,"edit_switches",t,R(function*(){var r=yield eb(e,t),i=r.parsed,n=r.entry,a=r.object,s={projectDir:e,parsed:i,references:[],typeImports:new Set,valueImports:new Set},o=eG(a,"switches","switches"),l=t.op,d=e=>"number"==typeof e?e:e?o.elements.findIndex(t=>Y.isObjectExpression(t)&&(0,Q.JJ)(t,"id")===e):-1;if("add"===l||"replace"===l){var c=yield e4(t.switch||{},s),p=null==t.index?o.elements.length:d(t.index);if("replace"===l){if(p<0||p>=o.elements.length)throw new es("invalid_index","replace index out of range",{index:p});o.elements[p]=c}else{if(p<0||p>o.elements.length)throw new es("invalid_index","add requires a valid switch id or index",{index:t.index});o.elements.splice(p,0,c)}}else if("remove"===l){var u=d(t.index);if(u<0||u>=o.elements.length)throw new es("invalid_index","remove requires a valid switch id or index",{index:t.index});o.elements.splice(u,1)}else if("move"===l){var f=d(t.index);if(f<0||f>=o.elements.length)throw new es("invalid_index","move requires a valid switch id or index",{index:t.index});var m=Number(t.to);if(!Number.isFinite(m)||m<0||m>=o.elements.length)throw new es("invalid_index","move requires valid to index",{to:t.to});var y=o.elements.splice(f,1),v=T(y,1)[0];o.elements.splice(m,0,v)}else throw new es("invalid_op",`Unsupported edit_switches op: ${l}`);eO(s),yield eK(i);var h=yield(0,Z.H)(e,t.verify);return{file:i.relPath,entry:n.name,id:n.id,change:{op:l,index:t.index,references:eL(s.references)},outcome:"compile:failed"===h.status?"verify_failed":"ok",verify:h,summary:`${l} switch on ${eU(i,n)} -> ${h.status}`}}))}),function(e,t){return S.apply(this,arguments)}),e9=($=R(function*(e,t,r,i){var n=[Y.objectProperty(Y.identifier("__typename"),Y.stringLiteral(e.typename)),Y.objectProperty(Y.identifier("id"),r)];return t.alias&&n.push(Y.objectProperty(Y.identifier("alias"),Y.stringLiteral(t.alias))),null!=t.title&&n.push(Y.objectProperty(Y.identifier("title"),Y.stringLiteral(t.title))),null!=t.description&&n.push(Y.objectProperty(Y.identifier("description"),Y.stringLiteral(t.description))),"brick"===e.kind||"generator"===e.kind?(n.push(Y.objectProperty(Y.identifier("templateKey"),Y.stringLiteral(t.templateKey||""))),n.push(Y.objectProperty(Y.identifier("property"),Y.objectExpression([]))),n.push(Y.objectProperty(Y.identifier("events"),Y.objectExpression([]))),n.push(Y.objectProperty(Y.identifier("outlets"),Y.objectExpression([]))),"brick"===e.kind&&n.push(Y.objectProperty(Y.identifier("animation"),Y.objectExpression([]))),n.push(Y.objectProperty(Y.identifier("switches"),Y.arrayExpression([])))):"canvas"===e.kind?(n.push(Y.objectProperty(Y.identifier("property"),Y.objectExpression([]))),n.push(Y.objectProperty(Y.identifier("events"),Y.objectExpression([]))),n.push(Y.objectProperty(Y.identifier("switches"),Y.arrayExpression([]))),n.push(Y.objectProperty(Y.identifier("items"),Y.arrayExpression([])))):"data"===e.kind?(n.push(Y.objectProperty(Y.identifier("type"),Y.stringLiteral(t.dataType||"any"))),n.push(Y.objectProperty(Y.identifier("schema"),Y.objectExpression([]))),n.push(Y.objectProperty(Y.identifier("events"),Y.objectExpression([]))),n.push(Y.objectProperty(Y.identifier("value"),Y.identifier("undefined")))):"animation"===e.kind&&(n.push(Y.objectProperty(Y.identifier("runType"),Y.stringLiteral("once"))),n.push(Y.objectProperty(Y.identifier("property"),Y.stringLiteral("opacity"))),n.push(Y.objectProperty(Y.identifier("config"),(yield eF({__type:"AnimationTimingConfig",toValue:1,duration:300,easing:"",delay:0,isInteraction:!0},i))))),Y.objectExpression(n)}),function(e,t,r,i){return $.apply(this,arguments)}),e8=(A=R(function*(e,t,r){var i=W.basename(t);for(var n of(yield ev(e)).filter(e=>W.basename(e)===i)){var a=yield ed(e,n);if(ec(a.ast).some(e=>e.alias===r))return!0}return!1}),function(e,t,r){return A.apply(this,arguments)}),e7=(I=R(function*(e,t){return ez(e,"new_entry",t,R(function*(){if(!t.file)throw new es("missing_file","new_entry requires file");if(!t.type)throw new es("missing_type","new_entry requires TypeScript type");var r=eo(e,t.file),i=yield ed(e,r),n=new Set(ec(i.ast).map(e=>e.name)),a="string"==typeof t.id?t.id:void 0,s=a||"string"!=typeof t.alias||!t.alias||(yield e8(e,r,t.alias))?void 0:t.alias,o=a?Y.stringLiteral(a):ew(i.kind.idType,s),l=t.entry||((e,t,r,i)=>{var n,a=(e=>{if(!e)return null;var t=e.replace(/[^a-zA-Z0-9_$]/g,"");return t?(/^[0-9]/.test(t)&&(t=`_${t}`),t):null})(i)||(r?`${t.varPrefix}${n=r.replace(/^[A-Z_]+/g,""),`${n.substr(15,3)}${n.substr(20,1)}`}`:`${t.varPrefix}Entry`);if(!e.has(a))return a;for(var s=1;e.has(`${a}${s}`);)s+=1;return`${a}${s}`})(n,i.kind,a,t.alias||t.title),d={projectDir:e,parsed:i,references:[],typeImports:new Set([t.type]),valueImports:new Set};a||d.valueImports.add("makeId");var c=yield e9(i.kind,t,o,d),p=Y.variableDeclarator(Y.identifier(l),c);for(var u of(p.id.typeAnnotation=Y.tsTypeAnnotation(Y.tsTypeReference(Y.identifier(t.type))),i.ast.program.body.push(Y.exportNamedDeclaration(Y.variableDeclaration("const",[p]))),Object.entries(t.set||{}))){var f=T(u,2),m=f[0],y=f[1];yield ek(c,m,y,d)}for(var v of t.events||[]){if(!(0,Q.u4)(v)||"string"!=typeof v.event||!v.event||!v.action)throw new es("invalid_action","events entries require { event, action }",{event:v});var h=eV(c,"events","events");eG(h,v.event,`events.${v.event}`).elements.push((yield eH(v.action,d)))}eO(d),yield eK(i);var b=yield(0,Z.H)(e,t.verify);return{file:i.relPath,entry:l,id:a,idExpression:a??(s?`makeId('${i.kind.idType}', '${s}')`:`makeId('${i.kind.idType}')`),change:{set:t.set||{},events:t.events||[],references:eL(d.references)},outcome:"compile:failed"===b.status?"verify_failed":"ok",verify:b,summary:`created ${l} (${i.kind.kind}, ${eu(i.absPath)}) -> ${b.status}`}}))}),function(e,t){return I.apply(this,arguments)}),e6=(e,t)=>{var r;return Y.isArrowFunctionExpression(e)&&0===e.params.length&&(r=e.body,!!r&&(Y.isIdentifier(r)?r.name===t.varName:!!Y.isMemberExpression(r)&&!!Y.isIdentifier(r.object)&&!!Y.isIdentifier(r.property)&&r.object.name===t.namespace&&r.property.name===t.varName))},e2=(e,t)=>Y.isCallExpression(e)&&Y.isIdentifier(e.callee,{name:"linkData"})&&e6(e.arguments[0],t),e3=(e,t)=>{if(!e)return!1;if(e6(e,t)||e2(e,t))return!0;var r=!1;return en(Y.file(Y.program([Y.expressionStatement(Y.cloneNode(e,!0))])),{ArrowFunctionExpression(e){e6(e.node,t)&&(r=!0,e.stop())},CallExpression(e){e2(e.node,t)&&(r=!0,e.stop())}}),r},te=(e,t,r,i=[],n={})=>{if(Y.isProgram(e))return void e.body.forEach((e,a)=>te(e,t,r,[...i,String(a)],n));if(Y.isExportNamedDeclaration(e)&&e.declaration)return void te(e.declaration,t,r,i,n);if(Y.isVariableDeclaration(e))return void e.declarations.forEach((e,a)=>te(e,t,r,[...i,String(a)],n));if(Y.isVariableDeclarator(e)&&e.init)return void te(e.init,t,r,i,n);if(Y.isObjectExpression(e)){for(var a=e.properties.length-1;a>=0;a-=1){var s=e.properties[a];if(Y.isObjectProperty(s)){var o=(0,Q.Gp)(s.key)||`property-${a}`,l=[...i,o];if(e6(s.value,t)||e2(s.value,t)){i.includes("outlets")?(e.properties.splice(a,1),r.push({action:"drop_outlet",path:l.join(".")})):n.dataCalc&&("output"===o||"error"===o)?(s.value=Y.nullLiteral(),r.push({action:"null_output",path:l.join(".")})):(s.value=Y.identifier("undefined"),r.push({action:"null_link",path:l.join(".")}));continue}te(s.value,t,r,l,n)}}return}if(Y.isArrayExpression(e))for(var d=i[i.length-1],c=i.includes("events")&&"events"!==d,p=n.dataCalc?["items","params","dataParams","conds","switches","inputs","outputs"]:["items","params","dataParams","conds","switches"],u=e.elements.length-1;u>=0;u-=1){var f=e.elements[u];if(f){var m=[...i,String(u)];if(e3(f,t)&&(p.includes(d)||c||e6(f,t))){e.elements.splice(u,1),r.push({action:c?"delete_event_handler":n.dataCalc&&("inputs"===d||"outputs"===d)?"remove_io_item":"remove_reference_item",path:m.join(".")});continue}te(f,t,r,m,n)}}},tt=(e,t)=>{var r=e.ast.program.body.indexOf(t.node);r>=0&&e.ast.program.body.splice(r,1)},tr=(O=R(function*(e,t,r){if("project"===r)return ev(e);var i=ef(t),n=yield ey(i),a=W.join(i,"data-calc"),s=yield(0,V.readdir)(a,{withFileTypes:!0}).catch(()=>[]);return[...n,...s.filter(e=>e.isFile()&&e.name.endsWith(".ts")).map(e=>W.join(a,e.name))]}),function(e,t,r){return O.apply(this,arguments)}),ti=(C=R(function*(e,t){return ez(e,"remove_entry",t,R(function*(){var r,i=yield eb(e,t),n=i.parsed,a=i.entry,s={varName:a.name,namespace:n.kind.namespace,id:a.id},o=yield tr(e,n.absPath,t.scope),l=[],d=yield Promise.all(o.map((r=R(function*(t){var r=yield(0,V.readFile)(t,"utf8");return{absPath:t,relPath:(0,Q.RI)(e,t),source:r,ast:el(r,(0,Q.RI)(e,t)),kind:ea[W.basename(t)]||n.kind}}),function(e){return r.apply(this,arguments)}))),c=function*(e){var t,r,i,o,d;(o=(e.absPath===n.absPath?(t=a.name,r=Y.cloneNode(e.ast,!0),i={...e,ast:r},tt(i,ep(i,{entry:t})),i):e).ast,d=[],en(o,{ArrowFunctionExpression(e){e6(e.node,s)&&d.push({type:"ref",loc:e.node.loc?.start})},CallExpression(e){e2(e.node,s)&&d.push({type:"link",loc:e.node.loc?.start})}}),d).forEach(t=>l.push({file:e.relPath,...t}))};for(var p of d)yield*c(p);if(t.strict&&l.length>0)return{file:n.relPath,entry:a.name,id:a.id,outcome:"refused",touchedSites:l,verify:{status:"skipped",errors:[]},summary:`refused to remove ${eU(n,a)}; ${l.length} reference(s) found`};var u=function*(e){var t=[],r={dataCalc:e.absPath.split(W.sep).includes("data-calc")};if(e.absPath===n.absPath&&(tt(e,ep(e,{entry:a.name})),t.push({action:"remove_entry",path:a.name})),te(e.ast.program,s,t,[],r),0===t.length)return 1;var i=yield eB(e);el(i,e.relPath),yield(0,V.writeFile)(e.absPath,i),t.forEach(t=>l.push({file:e.relPath,...t}))};for(var f of d)if(yield*u(f))continue;var m=yield(0,Z.H)(e,t.verify);return{file:n.relPath,entry:a.name,id:a.id,outcome:"compile:failed"===m.status?"verify_failed":"ok",touchedSites:l,verify:m,summary:`removed ${eU(n,a)} with ${l.length} touched site(s) -> ${m.status}`}}))}),function(e,t){return C.apply(this,arguments)}),tn=(N=R(function*(e,t){return ez(e,"new_subspace",t,R(function*(){var r=W.join(e,"root.ts"),i=(0,Q.RI)(e,r),n=yield(0,V.readFile)(r,"utf8").catch(()=>null);if(null==n)throw new es("invalid_file","Project has no root.ts to wire the subspace into");var a={source:n,ast:el(n,i),absPath:r,relPath:i},s=a.ast.program.body.find(e=>Y.isExportDefaultDeclaration(e));if(!s||!Y.isArrayExpression(s.declaration))throw new es("fallback_recommended","root.ts default export is not a subspace array literal; wire the new subspace manually",{file:i});var o=(yield em(e)).reduce((e,t)=>{var r=/^subspace-(\d+)$/.exec(W.basename(t));return r?Math.max(e,Number(r[1])):e},-1)+1,l=`subspace-${o}`,d=W.join(e,"subspaces",l),c=`SUBSPACE_${(0,G.randomUUID)()}`,p=`CANVAS_${(0,G.randomUUID)()}`,u=(({subspaceId:e,canvasId:t,title:r,description:i,layout:n,portal:a})=>{var s=[`width: ${n.width}`,`height: ${n.height}`,...n.resizeMode?[`resizeMode: '${n.resizeMode}'`]:[]];return{"data.ts":"import type { Data } from 'bricks-ctor'\n","bricks.ts":"import type { Brick } from 'bricks-ctor'\n","generators.ts":"import type { Generator } from 'bricks-ctor'\n","animations.ts":"import type { Animation } from 'bricks-ctor'\n","canvases.ts":`import type { Canvas } from 'bricks-ctor'
5
+ `)}),function(e,t){return n.apply(this,arguments)}),p=()=>({session:process.env.BRICKS_CTOR_SESSION_ID||process.env.CODEX_SESSION_ID,agent:process.env.BRICKS_CTOR_AGENT_ID||process.env.USER})},98009(e,t,r){r.d(t,{Gp:()=>v,HJ:()=>x,Hn:()=>c,JJ:()=>w,Kx:()=>j,LJ:()=>m,Pb:()=>g,RI:()=>u,bf:()=>b,jc:()=>_,u4:()=>p,z5:()=>y,zu:()=>h});var i,n,a=r(68832),s=r(99436),o=r(58135),l=r(51455),d=r(76760),c={trailingComma:"all",tabWidth:2,semi:!1,singleQuote:!0,printWidth:100},p=e=>!!e&&"object"==typeof e&&!Array.isArray(e),u=(e,t)=>d.relative(e,t).replace(/\\/g,"/").replace(/^\.\/+/,""),f=(e,t)=>{var r=d.relative(e,t);return""!==r&&(r.startsWith(`..${d.sep}`)||".."===r||d.isAbsolute(r))?null:t},m=(i=s(function*(e,t){var r=a((yield Promise.all([(0,l.realpath)(e),(0,l.realpath)(t)])),2);return f(r[0],r[1])}),function(e,t){return i.apply(this,arguments)}),y=(n=s(function*(e,t){var r=yield(0,l.lstat)(t).catch(e=>{if(e?.code==="ENOENT")return null;throw e}),i=yield(0,l.realpath)(e);if(r){var n=yield(0,l.realpath)(t).catch(e=>{if(e?.code==="ENOENT")return null;throw e});return n?f(i,n):null}var a=yield(0,l.realpath)(d.dirname(t));return f(i,d.join(a,d.basename(t)))}),function(e,t){return n.apply(this,arguments)}),v=e=>o.isIdentifier(e)?e.name:o.isStringLiteral(e)||o.isNumericLiteral(e)?String(e.value):null,h=e=>/^[$A-Z_a-z][$\w]*$/.test(e)?o.identifier(e):o.stringLiteral(e),b=(e,t)=>e.properties.find(e=>!!o.isObjectProperty(e)&&v(e.key)===t),w=(e,t)=>{var r=b(e,t);if(r&&o.isStringLiteral(r.value))return r.value.value},x=(e,t,r)=>{var i=b(e,t);if(i){i.value=r;return}e.properties.push(o.objectProperty(h(t),r))},_=(e,t)=>{var r=e.properties.findIndex(e=>!!o.isObjectProperty(e)&&v(e.key)===t);r>=0&&e.properties.splice(r,1)},g=(e,t)=>{var r=e.program.body,i=r.findLastIndex(e=>o.isImportDeclaration(e));r.splice(i+1,0,t)},j=(e,t,r)=>{var i=new Set(Array.from(r).filter(Boolean));if(0!==i.size){var n,a=function(e){return o.isImportDeclaration(e)&&"bricks-ctor"===e.source.value&&"type"===t==("type"===e.importKind)?(e.specifiers.forEach(e=>{if(o.isImportSpecifier(e)){var t=e.imported;o.isIdentifier(t)&&i.delete(t.name),o.isStringLiteral(t)&&i.delete(t.value)}}),i.forEach(t=>{e.specifiers.push(o.importSpecifier(o.identifier(t),o.identifier(t)))}),{v:void 0}):0};for(var s of e.program.body)if(0!==(n=a(s))&&n)return n.v;var l=o.importDeclaration(Array.from(i).map(e=>o.importSpecifier(o.identifier(e),o.identifier(e))),o.stringLiteral("bricks-ctor"));"type"===t&&(l.importKind="type"),g(e,l)}}},54452(e,t,r){r.d(t,{H:()=>c});var i,n,a=r(99436),s=r(75720),o=r(2985),l={FORCE_COLOR:"0",NO_COLOR:"1"},d=(i=a(function*(e){var t=yield(0,o.Re)(e);try{yield(0,s.sh)`bun compile`.cwd(e).env({...l,BRICKS_CTOR_ENABLE_EDITING_TOOLS:"0"}).text()}catch(e){var r=[e.stdout?.toString()??"",e.stderr?.toString()??"",e.message].filter(Boolean).join("\n").trim();return{status:"compile:failed",errors:r?[r]:["bun compile failed"]}}var i=yield(0,o.Re)(e);return{status:"compile:ok",errors:[],configChange:(0,o.m4)(t,i)}}),function(e){return i.apply(this,arguments)}),c=(n=a(function*(e,t){return(void 0!==t?t:!["0","false","no","off"].includes((process.env.BRICKS_CTOR_MCP_EDIT_VERIFY??"true").toLowerCase()))?d(e):{status:"skipped",errors:[]}}),function(e,t){return n.apply(this,arguments)})},85949(e,t,r){r.a(e,async function(e,i){try{r.r(t),r.d(t,{__test__:()=>tv,register:()=>ty});var n,a,s,o,l,d,c,p,u,f,m,y,v,h,b,w,x,_,g,j,P,k,E,S,$,A,I,O,C,N,T,R=r(68832),D=r(99436),F=r(44668),L=r(5018),B=r(63315),z=r(30409),K=r(40906),U=r(59410),q=r(2235),M=r(46773),Y=r(80004),J=r(58135),H=r(11978),V=r(79491),G=r(51455),W=r(77598),X=r(76760),Z=r(84867),Q=r(54452),ee=r(98009),et=r(3540),er=e([V]);function ei(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(ei=function(){return!!e})()}V=(er.then?(await er)():er)[0];var en=q.default||q,ea=Y.default||Y,es={"bricks.ts":{kind:"brick",namespace:"bricks",varPrefix:"b",idType:"brick",idPrefix:"BRICK_",typename:"Brick"},"generators.ts":{kind:"generator",namespace:"generators",varPrefix:"g",idType:"generator",idPrefix:"GENERATOR_",typename:"Generator"},"canvases.ts":{kind:"canvas",namespace:"canvases",varPrefix:"c",idType:"canvas",idPrefix:"CANVAS_",typename:"Canvas"},"data.ts":{kind:"data",namespace:"data",varPrefix:"d",idType:"data",idPrefix:"PROPERTY_BANK_DATA_NODE_",typename:"Data"},"animations.ts":{kind:"animation",namespace:"animations",varPrefix:"a",idType:"animation",idPrefix:"ANIMATION_",typename:"Animation"}},eo=function(e){function t(e,r,i,n=!1){var a,s,o;return L(this,t),s=t,o=[r],s=z(s),(a=B(this,ei()?Reflect.construct(s,o||[],z(this).constructor):s.apply(this,o))).name="EntryEditingError",a.code=e,a.details=i,a.isMcpError=n,a}return K(t,e),F(t)}(U(Error)),el=(e,t)=>{if(X.isAbsolute(t))throw new eo("invalid_file","File must be project-relative",{file:t});var r=X.resolve(e,t),i=X.relative(e,r);if(i.startsWith("..")||X.isAbsolute(i))throw new eo("invalid_file","File must stay inside the project directory",{file:t});return r},ed=(e,t)=>{try{return(0,M.parse)(e,{sourceType:"module",plugins:["typescript","topLevelAwait"],errorRecovery:!1})}catch(e){throw new eo("parse_failed",`Cannot parse ${t} as TypeScript: ${e.message}. Edit this file directly.`,{file:t},!0)}},ec=(n=D(function*(e,t){var r=yield(0,ee.LJ)(e,t);if(!r)throw new eo("invalid_file","File must stay inside the project directory",{file:(0,ee.RI)(e,t)});var i=yield(0,G.readFile)(r,"utf8"),n=(0,ee.RI)(e,t);return{source:i,ast:ed(i,n),projectDir:e,absPath:t,ioPath:r,relPath:n,kind:(e=>{var t=X.basename(e),r=es[t];if(!r)throw new eo("unsupported_file",`Unsupported entry file: ${t}`,{file:e,expected:Object.keys(es)});return r})(t)}}),function(e,t){return n.apply(this,arguments)}),ep=(a=D(function*(e,t){var r=yield(0,ee.z5)(e,t);if(!r)throw new eo("invalid_file","File must stay inside the project directory",{file:(0,ee.RI)(e,t)});return r}),function(e,t){return a.apply(this,arguments)}),eu=e=>e.program.body.flatMap(e=>{if(!J.isExportNamedDeclaration(e)||!J.isVariableDeclaration(e.declaration))return[];var t=e.declaration;return t.declarations.flatMap(r=>{if(!J.isIdentifier(r.id))return[];var i,n=r.id.typeAnnotation;J.isTSTypeAnnotation(n)&&J.isTSTypeReference(n.typeAnnotation)&&J.isIdentifier(n.typeAnnotation.typeName)&&(i=n.typeAnnotation.typeName.name);var a=J.isObjectExpression(r.init)?r.init:void 0;return[{name:r.id.name,node:e,declaration:t,declarator:r,object:a,id:a?(0,ee.JJ)(a,"id"):void 0,alias:a?(0,ee.JJ)(a,"alias"):void 0,typeName:i}]})}),ef=(e,t)=>{var r=eu(e.ast);if(t.entry){var i=r.find(e=>e.name===t.entry);if(i)return i;var n=r.filter(e=>e.alias===t.entry);if(1===n.length)return n[0];if(n.length>1)throw new eo("ambiguous_reference",`Alias is ambiguous: ${t.entry}`,{file:e.relPath,entry:t.entry,matches:n.map(e=>e.name)});throw new eo("entry_not_found",`Entry not found (by name or alias): ${t.entry}`,{file:e.relPath,entry:t.entry})}if(t.id){var a=r.find(e=>e.id===t.id);if(!a)throw new eo("entry_not_found",`Entry id not found: ${t.id}`,{file:e.relPath,id:t.id});return a}throw new eo("missing_target","Provide entry or id")},em=e=>e.split(X.sep).find(e=>/^subspace-\d+$/.test(e))||"unknown-subspace",ey=e=>{var t=e.split(X.sep),r=t.findIndex(e=>/^subspace-\d+$/.test(e));if(r<0)throw new eo("invalid_file","Entry file must be inside subspaces/subspace-N",{file:e});return t.slice(0,r+1).join(X.sep)},ev=(s=D(function*(e){var t=X.join(e,"subspaces");return(yield(0,G.readdir)(t,{withFileTypes:!0}).catch(()=>[])).filter(e=>e.isDirectory()&&/^subspace-\d+$/.test(e.name)).map(e=>X.join(t,e.name)).sort()}),function(e){return s.apply(this,arguments)}),eh=(o=D(function*(e){var t=Object.keys(es),r=yield(0,G.readdir)(e,{withFileTypes:!0}).catch(()=>[]),i=new Set(r.filter(e=>e.isFile()).map(e=>e.name));return t.filter(e=>i.has(e)).map(t=>X.join(e,t))}),function(e){return o.apply(this,arguments)}),eb=(l=D(function*(e){var t=yield ev(e);return(yield Promise.all(t.map(eh))).flat()}),function(e){return l.apply(this,arguments)}),ew=(d=D(function*(e,t){if(t.file)return el(e,t.file);if(!t.id)throw new eo("missing_file","Provide file, or provide id for global lookup");for(var r of yield eb(e)){var i=yield ec(e,r);if(eu(i.ast).find(e=>e.id===t.id))return r}throw new eo("entry_not_found",`Entry id not found: ${t.id}`,{id:t.id})}),function(e,t){return d.apply(this,arguments)}),ex=(c=D(function*(e,t){var r=yield ew(e,t),i=yield ec(e,r),n=ef(i,t),a=((e,t)=>{if(!e.object)throw new eo("fallback_recommended",`Entry ${e.name} in ${t} is not a top-level exported object literal. Edit this file directly for this one.`,{file:t,entry:e.name,check:"top-level export const object literal"});return e.object})(n,i.relPath);return{parsed:i,entry:n,object:a}}),function(e,t){return c.apply(this,arguments)}),e_=(e,t)=>J.callExpression(J.identifier("makeId"),t?[J.stringLiteral(e),J.stringLiteral(t)]:[J.stringLiteral(e)]),eg=e=>{var t=[];for(var r of e.split(".").filter(Boolean))for(var i=/([^\[\]]+)|\[(\d+)\]/g,n=void 0;n=i.exec(r);)n[1]&&t.push({key:n[1]}),n[2]&&t.push({index:Number(n[2])});if(0===t.length)throw new eo("invalid_path",`Invalid path: ${e}`,{path:e});return t},ej=e=>J.isTSAsExpression(e)||J.isTSSatisfiesExpression(e)||J.isTSNonNullExpression(e)||J.isParenthesizedExpression(e)?ej(e.expression):e,eP=(e,t)=>{var r=ej(e);if(!J.isObjectExpression(r))throw new eo("fallback_recommended",`Target path ${t} is not an object literal. Edit this file directly for this one.`,{path:t,expected:"object literal",actual:r.type});return r},ek=(e,t)=>{var r=ej(e);if(!J.isArrayExpression(r))throw new eo("fallback_recommended",`Target path ${t} is not an array literal. Edit this file directly for this one.`,{path:t,expected:"array literal",actual:r.type});return r},eE=e=>"array"==("index"in e?"array":"object")?J.arrayExpression([]):J.objectExpression([]),eS=(p=D(function*(e,t,r,i){for(var n=eg(t),a=e,s=0;s<n.length;s+=1){var o=n[s],l=s===n.length-1;if("key"in o){var d=eP(a,t);if(l)return void(0,ee.HJ)(d,o.key,(yield eB(r,i)));var c=n[s+1],p=(0,ee.bf)(d,o.key);p||(p=J.objectProperty((0,ee.zu)(o.key),eE(c)),d.properties.push(p)),a=p.value;continue}var u=ek(a,t);if(o.index<0||o.index>u.elements.length)throw new eo("invalid_path",`Array index out of range for ${t}`,{path:t,index:o.index});if(l){u.elements[o.index]=yield eB(r,i);return}u.elements[o.index]||(u.elements[o.index]=eE(n[s+1])),a=u.elements[o.index]}}),function(e,t,r,i){return p.apply(this,arguments)}),e$=(e,t)=>{for(var r=eg(t),i=e,n=0;n<r.length;n+=1){var a=r[n],s=n===r.length-1;if("key"in a){var o=eP(i,t);if(s)return void(0,ee.jc)(o,a.key);var l=(0,ee.bf)(o,a.key);if(!l)return;i=l.value;continue}var d=ek(i,t);if(a.index<0||a.index>=d.elements.length)return;if(s)return void d.elements.splice(a.index,1);var c=d.elements[a.index];if(!c)return;i=c}},eA=(e,t)=>{var r=(0,ee.bf)(e,"switches");if(!r)throw new eo("fallback_recommended","Entry has no switches array",{path:"switches"});var i=ek(r.value,"switches"),n="number"==typeof t?t:i.elements.findIndex(e=>J.isObjectExpression(e)&&(0,ee.JJ)(e,"id")===t);if(n<0||n>=i.elements.length)throw new eo("entry_not_found",`Switch not found: ${t}`,{switch:t});var a=i.elements[n];if(!J.isObjectExpression(a))throw new eo("fallback_recommended",`Switch ${String(t)} is not an object literal. Edit this file directly for this one.`,{switch:t});return a},eI=(e,t)=>{var r=t.replace(/\.[tj]sx?$/,""),i=X.relative(X.dirname(e),r).replace(/\\/g,"/");return i.startsWith(".")||(i=`./${i}`),i},eO=e=>{var t=new Set;return e.program.body.forEach(e=>{J.isImportDeclaration(e)?e.specifiers.forEach(e=>t.add(e.local.name)):J.isExportNamedDeclaration(e)&&J.isVariableDeclaration(e.declaration)&&e.declaration.declarations.forEach(e=>{J.isIdentifier(e.id)&&t.add(e.id.name)})}),t},eC=(e,t,r)=>{for(var i of e.ast.program.body)if(J.isImportDeclaration(i)&&i.source.value===t){var n=i.specifiers.find(e=>J.isImportDefaultSpecifier(e));if(n)return n.local.name}var a=eO(e.ast),s=r;if(a.has(s)){for(var o=1;a.has(`${s}${o}`);)o+=1;s=`${s}${o}`}var l=J.importDeclaration([J.importDefaultSpecifier(J.identifier(s))],J.stringLiteral(t));return(0,ee.Pb)(e.ast,l),s},eN=e=>{(0,ee.Kx)(e.parsed.ast,"type",e.typeImports),(0,ee.Kx)(e.parsed.ast,"value",e.valueImports)},eT=(u=D(function*(e,t,r){if(null==r||""===r)return t;if("number"==typeof r)return X.join(e,"subspaces",`subspace-${r}`);var i=String(r);if(/^\d+$/.test(i))return X.join(e,"subspaces",`subspace-${i}`);if(/^subspace-\d+$/.test(i))return X.join(e,"subspaces",i);if(i.includes("/"))return el(e,i);var n,a=yield ev(e),s=function*(){var t=X.join(o,"index.ts"),r=yield(0,G.readFile)(t,"utf8").catch(()=>"");if(!r)return 0;var n=ed(r,(0,ee.RI)(e,t)),a=!1;if(ea(n,{ObjectProperty(e){"id"===(0,ee.Gp)(e.node.key)&&J.isStringLiteral(e.node.value)&&e.node.value.value===i&&(a=!0,e.stop())}}),a)return{v:o}};for(var o of a)if(n=yield*s(),0!==n&&n)return n.v;throw new eo("reference_not_found",`Subspace not found: ${i}`,{subspace:i})}),function(e,t,r){return u.apply(this,arguments)}),eR=(f=D(function*(e,t){var r,i,n=ey(e.parsed.absPath),a=yield eT(e.projectDir,n,t),s=X.basename(a),o=/^subspace-(\d+)$/.exec(s);if(!o)throw new eo("invalid_subspace",`Not a subspace directory: ${s}`,{subspace:t});var l=X.join(a,"index.ts"),d=yield(0,G.readFile)(l,"utf8").catch(()=>null);if(null==d)throw new eo("reference_not_found",`Subspace not found: ${t}`,{subspace:t});var c=(r=ed(d,(0,ee.RI)(e.projectDir,l)),ea(r,{ObjectProperty(e){if("id"===(0,ee.Gp)(e.node.key)){var t=e.node.value;J.isStringLiteral(t)&&t.value.startsWith("SUBSPACE_")&&(i=t.value,e.stop())}}}),i);if(!c)throw new eo("invalid_subspace",`Subspace index has no SUBSPACE_ id: ${s}/index.ts`,{subspace:t});return{id:c,index:Number(o[1]),label:s,indexPath:l,isCurrent:X.resolve(a)===X.resolve(n)}}),function(e,t){return f.apply(this,arguments)}),eD=(m=D(function*(e,t){var r=yield eR(e,t);if(r.isCurrent)return e.references.push({input:t,id:r.id,sameFile:!1,display:`'${r.id}'`,targetAbsPath:r.indexPath}),{resolved:r,expression:J.stringLiteral(r.id)};var i=eC(e.parsed,`../${r.label}`,`subspace${r.index}`);return e.references.push({input:t,id:r.id,sameFile:!1,display:`() => ${i}`,targetAbsPath:r.indexPath}),{resolved:r,expression:J.arrowFunctionExpression([],J.identifier(i))}}),function(e,t){return m.apply(this,arguments)}),eF=(y=D(function*(e,t,r,i){var n=ey(t),a=yield eT(e,n,i),s=yield eh(a),o=[];for(var l of s){var d=yield ec(e,l),c=d.kind;for(var p of eu(d.ast))if(p.name===r||p.id===r||p.alias===r){var u=X.resolve(l)===X.resolve(t),f=X.basename(a);o.push({input:r,id:p.id,alias:p.alias,varName:p.name,namespace:c.namespace,display:`${c.namespace}.${p.name}`,targetAbsPath:l,sameFile:u,subspaceLabel:f,importSource:u?void 0:eI(t,l)})}}if(0===o.length)throw new eo("reference_not_found",`Reference not found: ${r}`,{ref:r,subspace:i??X.basename(n)});if(o.length>1)throw new eo("ambiguous_reference",`Reference is ambiguous: ${r}`,{ref:r,matches:o.map(t=>({file:(0,ee.RI)(e,t.targetAbsPath),entry:t.varName,id:t.id,alias:t.alias}))});return o[0]}),function(e,t,r,i){return y.apply(this,arguments)}),eL=(v=D(function*(e,t,r){var i=yield eF(t.projectDir,t.parsed.absPath,e,r);if(i.sameFile)return t.references.push(i),J.identifier(i.varName);var n=ey(t.parsed.absPath),a=ey(i.targetAbsPath),s=i.subspaceLabel.replace(/[^a-zA-Z0-9_$]/g,""),o=n===a?i.namespace:`${s}${i.namespace[0].toUpperCase()}${i.namespace.slice(1)}`,l=((e,t,r,i)=>{for(var n of e.ast.program.body)if(J.isImportDeclaration(n)&&n.source.value===r){var a=n.specifiers.find(J.isImportNamespaceSpecifier);if(a)return a.local.name}var s=eO(e.ast),o=i;if(s.has(o)){for(var l=1;s.has(`${o}${l}`);)l+=1;o=`${o}${l}`}var d=J.importDeclaration([J.importNamespaceSpecifier(J.identifier(o))],J.stringLiteral(r));return(0,ee.Pb)(e.ast,d),o})(t.parsed,i.namespace,i.importSource,o);return i.importLocal=l,t.references.push({...i,display:`${l}.${i.varName}`,importLocal:l}),J.memberExpression(J.identifier(l),J.identifier(i.varName))}),function(e,t,r){return v.apply(this,arguments)}),eB=(h=D(function*(e,t){if((0,ee.u4)(e)&&"string"==typeof e.expr&&1===Object.keys(e).length){var r=e.expr;try{return(0,M.parseExpression)(r,{plugins:["typescript"]})}catch(e){throw new eo("invalid_expr",`Invalid TypeScript expression: ${e.message}`,{expr:r})}}if((0,ee.u4)(e)&&"string"==typeof e.link){t.valueImports.add("linkData");var i=yield eL(e.link,t,e.subspace);return J.callExpression(J.identifier("linkData"),[J.arrowFunctionExpression([],i)])}if((0,ee.u4)(e)&&"string"==typeof e.ref){var n=yield eL(e.ref,t,e.subspace);return J.arrowFunctionExpression([],n)}if(Array.isArray(e))return J.arrayExpression((yield Promise.all(e.map(e=>eB(e,t)))));if((0,ee.u4)(e)){var a,s=yield Promise.all(Object.entries(e).map((a=D(function*([e,r]){return J.objectProperty((0,ee.zu)(e),(yield eB(r,t)))}),function(e){return a.apply(this,arguments)})));return J.objectExpression(s)}return void 0===e?J.identifier("undefined"):J.valueToNode(e)}),function(e,t){return h.apply(this,arguments)}),ez=e=>e.map(e=>({input:e.input,id:e.id,alias:e.alias,resolved:e.importLocal?`${e.importLocal}.${e.varName}`:e.sameFile?e.varName:e.display,file:e.targetAbsPath})),eK=(b=D(function*(e){var t=en(e.ast,{comments:!0},e.source).code,r=yield(0,V.format)(e.absPath,t,ee.Hn);if(r.errors.length>0)throw new eo("format_failed",`oxfmt failed for ${e.relPath}`,{file:e.relPath,errors:r.errors});return r.code}),function(e){return b.apply(this,arguments)}),eU=(w=D(function*(e){var t=yield eK(e);return ed(t,e.relPath),yield(0,G.writeFile)(e.ioPath??(yield ep(e.projectDir,e.absPath)),t),t}),function(e){return w.apply(this,arguments)}),eq=(e,t)=>{if(e){var r=em(e.absPath);return`${t?.name||"entry"} (${e.kind.kind}, ${r})`}},eM=(x=D(function*(e,t,r,i){var n={ts:new Date().toISOString(),tool:t,op:r?.op||(r?.set?"set":r?.unset?"unset":t),target:{file:r?.file,entry:r?.entry,id:r?.id},provenance:(0,et.S)()};try{var a=yield i(),s={...n,...a};return yield(0,et.a)(e,s).catch(e=>{s.auditError=e.message}),s}catch(i){var o=i instanceof eo?i:new eo("error",i.message||String(i),void 0,!0),l="fallback_recommended"===o.code?"fallback_recommended":"error",d={...n,outcome:l,input:r,error:{code:o.code,message:o.message,details:o.details},summary:"fallback_recommended"===l?`${t} could not safely edit this standard path; edit the file directly`:`${t} failed: ${o.message}`,isError:o.isMcpError||"error"===l};return yield(0,et.a)(e,d).catch(e=>{d.auditError=e.message}),d}}),function(e,t,r,i){return x.apply(this,arguments)}),eY=(_=D(function*(e,t){return eM(e,"edit_entry",t,D(function*(){var r=yield ex(e,t),i=r.parsed,n=r.entry,a=r.object,s={projectDir:e,parsed:i,references:[],typeImports:new Set,valueImports:new Set},o=null==t.switch?a:eA(a,t.switch);for(var l of Object.entries(t.set||{})){var d=R(l,2),c=d[0],p=d[1];yield eS(o,c,p,s)}for(var u of[...t.unset||[]].sort((e,t)=>{for(var r=eg(e).map(e=>"index"in e?e.index:-1),i=eg(t).map(e=>"index"in e?e.index:-1),n=0;n<Math.min(r.length,i.length);n+=1)if(r[n]!==i[n])return i[n]-r[n];return i.length-r.length}))e$(o,u);eN(s),yield eU(i);var f=yield(0,Q.H)(e,t.verify),m=eq(i,n);return{file:i.relPath,entry:n.name,id:n.id,change:{set:t.set||{},unset:t.unset||[],references:ez(s.references)},outcome:"compile:failed"===f.status?"verify_failed":"ok",verify:f,summary:`edited ${m} -> ${f.status}`}}))}),function(e,t){return _.apply(this,arguments)}),eJ=e=>{switch(e){case"IfStatement":return"an if statement";case"ForStatement":case"ForOfStatement":case"ForInStatement":return"a for loop";case"WhileStatement":case"DoWhileStatement":return"a while loop";case"SwitchStatement":return"a switch statement";case"TryStatement":return"a try/catch block";case"FunctionDeclaration":return"a function declaration";case"ReturnStatement":return"a return before the final statement";default:return`a ${e}`}},eH=(e,t)=>{for(var r=0;r<e.length;r+=1){var i=e[r],n=r===e.length-1;if("ExpressionStatement"===i.type){var a=eV(i.expression);if(a)return a;continue}if("VariableDeclaration"===i.type){for(var s of i.declarations)if("Identifier"!==s.id.type||!s.init)return"a destructuring or uninitialized declaration";continue}if(t&&n&&"ReturnStatement"===i.type){var o=i.argument?eV(i.argument):null;if(o)return o;continue}return eJ(i.type)}return null},eV=e=>{if(e?.type!=="CallExpression"||e.arguments?.length||e.callee?.type!=="ArrowFunctionExpression"&&e.callee?.type!=="FunctionExpression")return null;var t=e.callee.body;return t?.type==="BlockStatement"?eH(t.body,!0):eV(t)},eG=(g=D(function*(e,t){if(e?.expr)return eB(e,t);var r,i=(e=>{if(!(0,ee.u4)(e)||!(0,ee.u4)(e.action))return e;var t=e.action,r={handler:e.handler,name:t.name??t.__actionName,waitAsync:e.waitAsync};if(t.cast&&(r.cast=t.cast),Array.isArray(t.params))for(var i of(r.params={},t.params)){if(!(0,ee.u4)(i)||"string"!=typeof i.input)throw new eo("invalid_action",'Compiled action params entries require { input: "name", value }',{param:i});r.params[i.input]=i.value}if(Array.isArray(t.dataParams))for(var n of(r.dataParams={},t.dataParams)){var a=(0,ee.u4)(n?.input)?n.input.ref:n?.input;if("string"!=typeof a||!a)throw new eo("invalid_action","Compiled action dataParams entries require { input: dataRef, value }",{param:n});r.dataParams[a]=n.value}return r})(e),n=i?.name;if(!n)throw new eo("invalid_action","Action requires name");if("PROPERTY_BANK_EXPRESSION"===n&&(0,ee.u4)(i.params)){var a=i.params.expression;"string"==typeof a&&(e=>{try{t=(0,H.qg)(e,{ecmaVersion:2020})}catch(t){throw new eo("invalid_action",`PROPERTY_BANK_EXPRESSION does not parse: ${t.message}`,{expression:e})}var t,r=eH(t.body,!1);if(r)throw new eo("invalid_action",`PROPERTY_BANK_EXPRESSION cannot evaluate ${r}: the runtime folds the expression into a single expression (expression statements, simple const/let declarations, and a final return inside an IIFE only). Use ternaries instead of statements, or move branching logic to a DataCalculationScript.`,{expression:e})})(a)}var s="System",o=i.cast;if("system"===i.handler||null==i.handler)r=J.stringLiteral("system"),o||=`SystemAction${n.toLowerCase().split("_").filter(Boolean).map(e=>`${e[0].toUpperCase()}${e.slice(1)}`).join("")}`;else if((0,ee.u4)(i.handler)&&"string"==typeof i.handler.ref){var l=yield eF(t.projectDir,t.parsed.absPath,i.handler.ref,i.handler.subspace);if("bricks"!==l.namespace&&"generators"!==l.namespace)throw new eo("invalid_action",`Action handler must be a brick or generator, got ${l.namespace}: ${i.handler.ref}`,{handler:i.handler});s="bricks"===l.namespace?"Brick":"Generator";var d=yield eL(i.handler.ref,t,i.handler.subspace);r=J.arrowFunctionExpression([],d)}else if((0,ee.u4)(i.handler)&&null!=i.handler.subspace)r=(yield eD(t,i.handler.subspace)).expression,s="Subspace";else throw new eo("invalid_action","Unsupported action handler",{handler:i.handler});var c=[J.objectProperty(J.identifier("__actionName"),J.stringLiteral(n)),J.objectProperty(J.identifier("parent"),J.stringLiteral(s)),J.objectProperty(J.identifier("name"),J.stringLiteral(n))];if(i.params){var p,u=yield Promise.all(Object.entries(i.params).map((p=D(function*([e,r]){return J.objectExpression([J.objectProperty(J.identifier("input"),J.stringLiteral(e)),J.objectProperty(J.identifier("value"),(yield eB(r,t)))])}),function(e){return p.apply(this,arguments)})));c.push(J.objectProperty(J.identifier("params"),J.arrayExpression(u)))}if(i.dataParams){var f,m=yield Promise.all(Object.entries(i.dataParams).map((f=D(function*([e,r]){var i=yield eL(e,t);return J.objectExpression([J.objectProperty(J.identifier("input"),J.arrowFunctionExpression([],i)),J.objectProperty(J.identifier("value"),(yield eB(r,t)))])}),function(e){return f.apply(this,arguments)})));c.push(J.objectProperty(J.identifier("dataParams"),J.arrayExpression(m)))}var y=J.objectExpression(c);return o&&(t.typeImports.add(o),y=J.tsAsExpression(y,J.tsTypeReference(J.identifier(o)))),J.objectExpression([J.objectProperty(J.identifier("handler"),r),J.objectProperty(J.identifier("action"),y),J.objectProperty(J.identifier("waitAsync"),J.booleanLiteral(!!i.waitAsync))])}),function(e,t){return g.apply(this,arguments)}),eW=(e,t,r)=>{var i=(0,ee.bf)(e,t);return i||(i=J.objectProperty((0,ee.zu)(t),J.objectExpression([])),e.properties.push(i)),eP(i.value,r)},eX=(e,t,r)=>{var i=(0,ee.bf)(e,t);return i||(i=J.objectProperty((0,ee.zu)(t),J.arrayExpression([])),e.properties.push(i)),ek(i.value,r)},eZ=(j=D(function*(e,t){return eM(e,"edit_events",t,D(function*(){var r=yield ex(e,t),i=r.parsed,n=r.entry,a=r.object,s={projectDir:e,parsed:i,references:[],typeImports:new Set,valueImports:new Set},o=null==t.switch?a:eA(a,t.switch),l=t.op;if("clear"===l||"remove"===l||"move"===l){var d=(0,ee.bf)(o,"events"),c=d?eP(d.value,"events"):null,p=c?(0,ee.bf)(c,t.event):null,u=p?ek(p.value,`events.${t.event}`):null;if("clear"===l)c&&(0,ee.jc)(c,t.event);else if("move"===l){if(null==t.index)throw new eo("invalid_index","move requires index");if(!u||t.index<0||t.index>=u.elements.length)throw new eo("invalid_index","move index out of range",{index:t.index});var f=Number(t.to);if(!Number.isFinite(f)||f<0||f>=u.elements.length)throw new eo("invalid_index","move requires valid to index",{to:t.to});var m=u.elements.splice(t.index,1),y=R(m,1)[0];u.elements.splice(f,0,y)}else{if(null==t.index)throw new eo("invalid_index","remove requires index");if(!u||t.index<0||t.index>=u.elements.length)throw new eo("invalid_index","remove index out of range",{index:t.index});u.elements.splice(t.index,1),0===u.elements.length&&c&&(0,ee.jc)(c,t.event)}}else if("add"===l||"replace"===l){var v=yield eG(t.action,s),h=eW(o,"events","events"),b=eX(h,t.event,`events.${t.event}`),w=t.index??b.elements.length;if("replace"===l){if(w<0||w>=b.elements.length)throw new eo("invalid_index","replace index out of range",{index:w});b.elements[w]=v}else{if(w<0||w>b.elements.length)throw new eo("invalid_index","add index out of range",{index:w});b.elements.splice(w,0,v)}}else throw new eo("invalid_op",`Unsupported edit_events op: ${l}`);eN(s),yield eU(i);var x=yield(0,Q.H)(e,t.verify);return{file:i.relPath,entry:n.name,id:n.id,change:{event:t.event,op:l,index:t.index,references:ez(s.references)},outcome:"compile:failed"===x.status?"verify_failed":"ok",verify:x,summary:`${l} event ${t.event} on ${eq(i,n)} -> ${x.status}`}}))}),function(e,t){return j.apply(this,arguments)}),eQ=e=>{if((0,ee.u4)(e)&&"string"==typeof e.expr)return e;if(!(0,ee.u4)(e))throw new eo("invalid_item","Canvas item requires frame { x, y, width, height }");for(var t of["x","y","width","height"])if("number"!=typeof e[t])throw new eo("invalid_item",`Canvas item frame requires numeric ${t}`,{frame:e});return e},e0=(P=D(function*(e,t,r){if(!e?.ref&&e?.subspace==null)throw new eo("invalid_item","Canvas item requires ref (brick) or subspace (embed)");var i,n=eQ(e.frame??r);if(e.ref){var a=yield eL(e.ref,t,e.subspace);i=J.arrowFunctionExpression([],a)}else{var s=yield eD(t,e.subspace),o=s.resolved,l=s.expression;if(o.isCurrent)throw new eo("invalid_item","A subspace cannot embed itself",{subspace:e.subspace});i=l}return J.objectExpression([J.objectProperty(J.identifier("item"),i),J.objectProperty(J.identifier("frame"),(yield eB(n,t))),...null==e.hidden?[]:[J.objectProperty(J.identifier("hidden"),J.booleanLiteral(!!e.hidden))]])}),function(e,t,r){return P.apply(this,arguments)}),e1=(k=D(function*(e,t){return eM(e,"edit_canvas_items",t,D(function*(){var r=yield ex(e,t),i=r.parsed,n=r.entry,a=r.object;if("canvas"!==i.kind.kind)throw new eo("invalid_file","edit_canvas_items only edits canvases.ts entries",{file:i.relPath});var s={projectDir:e,parsed:i,references:[],typeImports:new Set,valueImports:new Set},o=eX(a,"items","items"),l=t.op;if("add"===l||"replace"===l){var d=yield e0(t.item,s,t.frame),c=t.index??o.elements.length;if("replace"===l){if(c<0||c>=o.elements.length)throw new eo("invalid_index","replace index out of range",{index:c});o.elements[c]=d}else{if(c<0||c>o.elements.length)throw new eo("invalid_index","add index out of range",{index:c});o.elements.splice(c,0,d)}}else if("remove"===l){if(null==t.index)throw new eo("invalid_index","remove requires index");if(t.index<0||t.index>=o.elements.length)throw new eo("invalid_index","remove index out of range",{index:t.index});o.elements.splice(t.index,1)}else if("move"===l){if(null==t.index)throw new eo("invalid_index","move requires index");if(!t.frame)throw new eo("invalid_item","move requires frame");if(t.index<0||t.index>=o.elements.length)throw new eo("invalid_index","move index out of range",{index:t.index});var p=o.elements[t.index];if(!J.isObjectExpression(p))throw new eo("fallback_recommended","Canvas item is not an object literal",{index:t.index});(0,ee.HJ)(p,"frame",(yield eB(eQ(t.frame),s)))}else throw new eo("invalid_op",`Unsupported edit_canvas_items op: ${l}`);eN(s),yield eU(i);var u=yield(0,Q.H)(e,t.verify);return{file:i.relPath,entry:n.name,id:n.id,change:{op:l,index:t.index,references:ez(s.references)},outcome:"compile:failed"===u.status?"verify_failed":"ok",verify:u,summary:`${l} canvas item on ${eq(i,n)} -> ${u.status}`}}))}),function(e,t){return k.apply(this,arguments)}),e4=(E=D(function*(e,t){var r=(e=>{switch(e?.__typename){case"SwitchCondInnerStateCurrentCanvas":return{type:"inner_state",key:"current_canvas",value:e.value,subspace:e.subspace};case"SwitchCondInnerStateOutlet":return{type:"inner_state",outlet:e.outlet,value:e.value};case"SwitchCondData":return{type:"property_bank",ref:e.data??e.ref,value:e.value,subspace:e.subspace};case"SwitchCondPropertyBankByItemKey":return{type:"property_bank_by_item_key",ref:e.data??e.ref,value:e.value,subspace:e.subspace};default:return e}})(e);if(r?.expr)return eB(r,t);if(r?.type==="inner_state"&&"current_canvas"===r.key){var i=yield eL(r.value,t,r.subspace);return J.objectExpression([J.objectProperty(J.identifier("__typename"),J.stringLiteral("SwitchCondInnerStateCurrentCanvas")),J.objectProperty(J.identifier("value"),J.arrowFunctionExpression([],i))])}if(r?.type==="inner_state"){var n=r.outlet||r.key;if(!n)throw new eo("invalid_switch","Switch inner-state outlet condition requires outlet or key");return J.objectExpression([J.objectProperty(J.identifier("__typename"),J.stringLiteral("SwitchCondInnerStateOutlet")),J.objectProperty(J.identifier("outlet"),J.stringLiteral(n)),J.objectProperty(J.identifier("value"),(yield eB(r.value,t)))])}var a=r?.ref||r?.data||r?.key;if(!a)throw new eo("invalid_switch","Switch condition requires data ref");var s=yield eL(a,t,r.subspace);return J.objectExpression([J.objectProperty(J.identifier("__typename"),J.stringLiteral(r?.type==="property_bank_by_item_key"?"SwitchCondPropertyBankByItemKey":"SwitchCondData")),J.objectProperty(J.identifier("data"),J.arrowFunctionExpression([],s)),J.objectProperty(J.identifier("value"),(yield eB(r.value,t)))])}),function(e,t){return E.apply(this,arguments)}),e5=new Set(["id","title","description","conds","override","property","outlets","animation","events","disabled","break"]),e9=(S=D(function*(e,t){for(var r of Object.keys(e))if(!e5.has(r))throw new eo("invalid_switch",`Unknown switch field: ${r}`,{field:r,supported:Array.from(e5)});if(void 0!==e.events)throw new eo("invalid_switch","Set switch events with edit_events using its switch parameter");if(e.id&&!/^BRICK_STATE_GROUP_[0-9a-fA-F-]{36}$/.test(e.id))throw new eo("invalid_switch","Switch id must match BRICK_STATE_GROUP_<uuid>; omit id to generate one",{id:e.id});var i,n=e.id?J.stringLiteral(e.id):e_("switch");e.id||t.valueImports.add("makeId");var a=[J.objectProperty(J.identifier("id"),n)];for(var s of(null!=e.title&&a.push(J.objectProperty(J.identifier("title"),J.stringLiteral(e.title))),null!=e.description&&a.push(J.objectProperty(J.identifier("description"),J.stringLiteral(e.description))),e.conds&&a.push(J.objectProperty(J.identifier("conds"),J.arrayExpression((yield Promise.all(e.conds.map((i=D(function*(e){return J.objectExpression([J.objectProperty(J.identifier("method"),J.stringLiteral(e.method||"==")),J.objectProperty(J.identifier("cond"),(yield e4(e.cond||e,t)))])}),function(e){return i.apply(this,arguments)}))))))),e.override&&a.push(J.objectProperty(J.identifier("override"),(yield eB(e.override,t)))),["property","outlets","animation"]))null!=e[s]&&a.push(J.objectProperty(J.identifier(s),(yield eB(e[s],t))));return null!=e.disabled&&a.push(J.objectProperty(J.identifier("disabled"),J.booleanLiteral(!!e.disabled))),null!=e.break&&a.push(J.objectProperty(J.identifier("break"),J.booleanLiteral(!!e.break))),J.objectExpression(a)}),function(e,t){return S.apply(this,arguments)}),e8=($=D(function*(e,t){return eM(e,"edit_switches",t,D(function*(){var r=yield ex(e,t),i=r.parsed,n=r.entry,a=r.object,s={projectDir:e,parsed:i,references:[],typeImports:new Set,valueImports:new Set},o=eX(a,"switches","switches"),l=t.op,d=e=>"number"==typeof e?e:e?o.elements.findIndex(t=>J.isObjectExpression(t)&&(0,ee.JJ)(t,"id")===e):-1;if("add"===l||"replace"===l){var c=yield e9(t.switch||{},s),p=null==t.index?o.elements.length:d(t.index);if("replace"===l){if(p<0||p>=o.elements.length)throw new eo("invalid_index","replace index out of range",{index:p});o.elements[p]=c}else{if(p<0||p>o.elements.length)throw new eo("invalid_index","add requires a valid switch id or index",{index:t.index});o.elements.splice(p,0,c)}}else if("remove"===l){var u=d(t.index);if(u<0||u>=o.elements.length)throw new eo("invalid_index","remove requires a valid switch id or index",{index:t.index});o.elements.splice(u,1)}else if("move"===l){var f=d(t.index);if(f<0||f>=o.elements.length)throw new eo("invalid_index","move requires a valid switch id or index",{index:t.index});var m=Number(t.to);if(!Number.isFinite(m)||m<0||m>=o.elements.length)throw new eo("invalid_index","move requires valid to index",{to:t.to});var y=o.elements.splice(f,1),v=R(y,1)[0];o.elements.splice(m,0,v)}else throw new eo("invalid_op",`Unsupported edit_switches op: ${l}`);eN(s),yield eU(i);var h=yield(0,Q.H)(e,t.verify);return{file:i.relPath,entry:n.name,id:n.id,change:{op:l,index:t.index,references:ez(s.references)},outcome:"compile:failed"===h.status?"verify_failed":"ok",verify:h,summary:`${l} switch on ${eq(i,n)} -> ${h.status}`}}))}),function(e,t){return $.apply(this,arguments)}),e6=(A=D(function*(e,t,r,i){var n=[J.objectProperty(J.identifier("__typename"),J.stringLiteral(e.typename)),J.objectProperty(J.identifier("id"),r)];return t.alias&&n.push(J.objectProperty(J.identifier("alias"),J.stringLiteral(t.alias))),null!=t.title&&n.push(J.objectProperty(J.identifier("title"),J.stringLiteral(t.title))),null!=t.description&&n.push(J.objectProperty(J.identifier("description"),J.stringLiteral(t.description))),"brick"===e.kind||"generator"===e.kind?(n.push(J.objectProperty(J.identifier("templateKey"),J.stringLiteral(t.templateKey||""))),n.push(J.objectProperty(J.identifier("property"),J.objectExpression([]))),n.push(J.objectProperty(J.identifier("events"),J.objectExpression([]))),n.push(J.objectProperty(J.identifier("outlets"),J.objectExpression([]))),"brick"===e.kind&&n.push(J.objectProperty(J.identifier("animation"),J.objectExpression([]))),n.push(J.objectProperty(J.identifier("switches"),J.arrayExpression([])))):"canvas"===e.kind?(n.push(J.objectProperty(J.identifier("property"),J.objectExpression([]))),n.push(J.objectProperty(J.identifier("events"),J.objectExpression([]))),n.push(J.objectProperty(J.identifier("switches"),J.arrayExpression([]))),n.push(J.objectProperty(J.identifier("items"),J.arrayExpression([])))):"data"===e.kind?(n.push(J.objectProperty(J.identifier("type"),J.stringLiteral(t.dataType||"any"))),n.push(J.objectProperty(J.identifier("schema"),J.objectExpression([]))),n.push(J.objectProperty(J.identifier("events"),J.objectExpression([]))),n.push(J.objectProperty(J.identifier("value"),J.identifier("undefined")))):"animation"===e.kind&&(n.push(J.objectProperty(J.identifier("runType"),J.stringLiteral("once"))),n.push(J.objectProperty(J.identifier("property"),J.stringLiteral("opacity"))),n.push(J.objectProperty(J.identifier("config"),(yield eB({__type:"AnimationTimingConfig",toValue:1,duration:300,easing:"",delay:0,isInteraction:!0},i))))),J.objectExpression(n)}),function(e,t,r,i){return A.apply(this,arguments)}),e7=(I=D(function*(e,t,r){var i=X.basename(t);for(var n of(yield eb(e)).filter(e=>X.basename(e)===i)){var a=yield ec(e,n);if(eu(a.ast).some(e=>e.alias===r))return!0}return!1}),function(e,t,r){return I.apply(this,arguments)}),e2=(O=D(function*(e,t){return eM(e,"new_entry",t,D(function*(){if(!t.file)throw new eo("missing_file","new_entry requires file");if(!t.type)throw new eo("missing_type","new_entry requires TypeScript type");var r=el(e,t.file),i=yield ec(e,r),n=new Set(eu(i.ast).map(e=>e.name)),a="string"==typeof t.id?t.id:void 0,s=a||"string"!=typeof t.alias||!t.alias||(yield e7(e,r,t.alias))?void 0:t.alias,o=a?J.stringLiteral(a):e_(i.kind.idType,s),l=t.entry||((e,t,r,i)=>{var n,a=(e=>{if(!e)return null;var t=e.replace(/[^a-zA-Z0-9_$]/g,"");return t?(/^[0-9]/.test(t)&&(t=`_${t}`),t):null})(i)||(r?`${t.varPrefix}${n=r.replace(/^[A-Z_]+/g,""),`${n.substr(15,3)}${n.substr(20,1)}`}`:`${t.varPrefix}Entry`);if(!e.has(a))return a;for(var s=1;e.has(`${a}${s}`);)s+=1;return`${a}${s}`})(n,i.kind,a,t.alias||t.title),d={projectDir:e,parsed:i,references:[],typeImports:new Set([t.type]),valueImports:new Set};a||d.valueImports.add("makeId");var c=yield e6(i.kind,t,o,d),p=J.variableDeclarator(J.identifier(l),c);for(var u of(p.id.typeAnnotation=J.tsTypeAnnotation(J.tsTypeReference(J.identifier(t.type))),i.ast.program.body.push(J.exportNamedDeclaration(J.variableDeclaration("const",[p]))),Object.entries(t.set||{}))){var f=R(u,2),m=f[0],y=f[1];yield eS(c,m,y,d)}for(var v of t.events||[]){if(!(0,ee.u4)(v)||"string"!=typeof v.event||!v.event||!v.action)throw new eo("invalid_action","events entries require { event, action }",{event:v});var h=eW(c,"events","events");eX(h,v.event,`events.${v.event}`).elements.push((yield eG(v.action,d)))}eN(d),yield eU(i);var b=yield(0,Q.H)(e,t.verify);return{file:i.relPath,entry:l,id:a,idExpression:a??(s?`makeId('${i.kind.idType}', '${s}')`:`makeId('${i.kind.idType}')`),change:{set:t.set||{},events:t.events||[],references:ez(d.references)},outcome:"compile:failed"===b.status?"verify_failed":"ok",verify:b,summary:`created ${l} (${i.kind.kind}, ${em(i.absPath)}) -> ${b.status}`}}))}),function(e,t){return O.apply(this,arguments)}),e3=(e,t)=>{var r;return J.isArrowFunctionExpression(e)&&0===e.params.length&&(r=e.body,!!r&&(J.isIdentifier(r)?r.name===t.varName:!!J.isMemberExpression(r)&&!!J.isIdentifier(r.object)&&!!J.isIdentifier(r.property)&&r.object.name===t.namespace&&r.property.name===t.varName))},te=(e,t)=>J.isCallExpression(e)&&J.isIdentifier(e.callee,{name:"linkData"})&&e3(e.arguments[0],t),tt=(e,t)=>{if(!e)return!1;if(e3(e,t)||te(e,t))return!0;var r=!1;return ea(J.file(J.program([J.expressionStatement(J.cloneNode(e,!0))])),{ArrowFunctionExpression(e){e3(e.node,t)&&(r=!0,e.stop())},CallExpression(e){te(e.node,t)&&(r=!0,e.stop())}}),r},tr=(e,t,r,i=[],n={})=>{if(J.isProgram(e))return void e.body.forEach((e,a)=>tr(e,t,r,[...i,String(a)],n));if(J.isExportNamedDeclaration(e)&&e.declaration)return void tr(e.declaration,t,r,i,n);if(J.isVariableDeclaration(e))return void e.declarations.forEach((e,a)=>tr(e,t,r,[...i,String(a)],n));if(J.isVariableDeclarator(e)&&e.init)return void tr(e.init,t,r,i,n);if(J.isObjectExpression(e)){for(var a=e.properties.length-1;a>=0;a-=1){var s=e.properties[a];if(J.isObjectProperty(s)){var o=(0,ee.Gp)(s.key)||`property-${a}`,l=[...i,o];if(e3(s.value,t)||te(s.value,t)){i.includes("outlets")?(e.properties.splice(a,1),r.push({action:"drop_outlet",path:l.join(".")})):n.dataCalc&&("output"===o||"error"===o)?(s.value=J.nullLiteral(),r.push({action:"null_output",path:l.join(".")})):(s.value=J.identifier("undefined"),r.push({action:"null_link",path:l.join(".")}));continue}tr(s.value,t,r,l,n)}}return}if(J.isArrayExpression(e))for(var d=i[i.length-1],c=i.includes("events")&&"events"!==d,p=n.dataCalc?["items","params","dataParams","conds","switches","inputs","outputs"]:["items","params","dataParams","conds","switches"],u=e.elements.length-1;u>=0;u-=1){var f=e.elements[u];if(f){var m=[...i,String(u)];if(tt(f,t)&&(p.includes(d)||c||e3(f,t))){e.elements.splice(u,1),r.push({action:c?"delete_event_handler":n.dataCalc&&("inputs"===d||"outputs"===d)?"remove_io_item":"remove_reference_item",path:m.join(".")});continue}tr(f,t,r,m,n)}}},ti=(e,t)=>{var r=e.ast.program.body.indexOf(t.node);r>=0&&e.ast.program.body.splice(r,1)},tn=(C=D(function*(e,t,r){if("project"===r)return eb(e);var i=ey(t),n=yield eh(i),a=X.join(i,"data-calc"),s=yield(0,G.readdir)(a,{withFileTypes:!0}).catch(()=>[]);return[...n,...s.filter(e=>e.isFile()&&e.name.endsWith(".ts")).map(e=>X.join(a,e.name))]}),function(e,t,r){return C.apply(this,arguments)}),ta=(N=D(function*(e,t){return eM(e,"remove_entry",t,D(function*(){var r,i=yield ex(e,t),n=i.parsed,a=i.entry,s={varName:a.name,namespace:n.kind.namespace,id:a.id},o=yield tn(e,n.absPath,t.scope),l=[],d=yield Promise.all(o.map((r=D(function*(t){var r=yield(0,G.readFile)(t,"utf8");return{absPath:t,relPath:(0,ee.RI)(e,t),source:r,ast:ed(r,(0,ee.RI)(e,t)),kind:es[X.basename(t)]||n.kind}}),function(e){return r.apply(this,arguments)}))),c=function*(e){var t,r,i,o,d;(o=(e.absPath===n.absPath?(t=a.name,r=J.cloneNode(e.ast,!0),i={...e,ast:r},ti(i,ef(i,{entry:t})),i):e).ast,d=[],ea(o,{ArrowFunctionExpression(e){e3(e.node,s)&&d.push({type:"ref",loc:e.node.loc?.start})},CallExpression(e){te(e.node,s)&&d.push({type:"link",loc:e.node.loc?.start})}}),d).forEach(t=>l.push({file:e.relPath,...t}))};for(var p of d)yield*c(p);if(t.strict&&l.length>0)return{file:n.relPath,entry:a.name,id:a.id,outcome:"refused",touchedSites:l,verify:{status:"skipped",errors:[]},summary:`refused to remove ${eq(n,a)}; ${l.length} reference(s) found`};var u=function*(t){var r=[],i={dataCalc:t.absPath.split(X.sep).includes("data-calc")};if(t.absPath===n.absPath&&(ti(t,ef(t,{entry:a.name})),r.push({action:"remove_entry",path:a.name})),tr(t.ast.program,s,r,[],i),0===r.length)return 1;var o=yield eK(t);ed(o,t.relPath),yield(0,G.writeFile)((yield ep(e,t.absPath)),o),r.forEach(e=>l.push({file:t.relPath,...e}))};for(var f of d)if(yield*u(f))continue;var m=yield(0,Q.H)(e,t.verify);return{file:n.relPath,entry:a.name,id:a.id,outcome:"compile:failed"===m.status?"verify_failed":"ok",touchedSites:l,verify:m,summary:`removed ${eq(n,a)} with ${l.length} touched site(s) -> ${m.status}`}}))}),function(e,t){return N.apply(this,arguments)}),ts=(T=D(function*(e,t){return eM(e,"new_subspace",t,D(function*(){var r=X.join(e,"root.ts"),i=(0,ee.RI)(e,r),n=yield(0,G.readFile)(r,"utf8").catch(()=>null);if(null==n)throw new eo("invalid_file","Project has no root.ts to wire the subspace into");var a={source:n,ast:ed(n,i),projectDir:e,absPath:r,relPath:i},s=a.ast.program.body.find(e=>J.isExportDefaultDeclaration(e));if(!s||!J.isArrayExpression(s.declaration))throw new eo("fallback_recommended","root.ts default export is not a subspace array literal; wire the new subspace manually",{file:i});var o=(yield ev(e)).reduce((e,t)=>{var r=/^subspace-(\d+)$/.exec(X.basename(t));return r?Math.max(e,Number(r[1])):e},-1)+1,l=`subspace-${o}`,d=X.join(e,"subspaces",l),c=`SUBSPACE_${(0,W.randomUUID)()}`,p=`CANVAS_${(0,W.randomUUID)()}`,u=(({subspaceId:e,canvasId:t,title:r,description:i,layout:n,portal:a})=>{var s=[`width: ${n.width}`,`height: ${n.height}`,...n.resizeMode?[`resizeMode: '${n.resizeMode}'`]:[]];return{"data.ts":"import type { Data } from 'bricks-ctor'\n","bricks.ts":"import type { Brick } from 'bricks-ctor'\n","generators.ts":"import type { Generator } from 'bricks-ctor'\n","animations.ts":"import type { Animation } from 'bricks-ctor'\n","canvases.ts":`import type { Canvas } from 'bricks-ctor'
6
6
 
7
7
  export const cMain: Canvas = {
8
8
  __typename: 'Canvas',
@@ -41,4 +41,4 @@ export default {
41
41
  } as Subspace
42
42
 
43
43
  export { bricks, generators, canvases, data }
44
- `}})({subspaceId:c,canvasId:p,title:t.title,description:t.description??"",layout:{width:t.layout?.width??96,height:t.layout?.height??54,resizeMode:t.layout?.resizeMode},portal:t.portal});yield(0,V.mkdir)(W.join(d,"data-calc"),{recursive:!0});var f=[];for(var m of Object.entries(u)){var y=T(m,2),v=y[0],h=y[1],b=W.join(d,v),w=yield(0,H.format)(b,h,Q.Hn);yield(0,V.writeFile)(b,w.errors.length>0?h:w.code),f.push((0,Q.RI)(e,b))}var x=eI(a,`./subspaces/${l}`,`subspace${o}`);s.declaration.elements.push(Y.identifier(x)),yield eK(a);var g=yield(0,Z.H)(e,t.verify);return{subspace:l,id:c,index:o,files:f,change:{op:"new_subspace",rootImport:x},outcome:"compile:failed"===g.status?"verify_failed":"ok",verify:g,summary:`new_subspace ${l} (${t.title}) wired into root.ts -> ${g.status}`}}))}),function(e,t){return N.apply(this,arguments)}),ta=e=>({content:[{type:"text",text:JSON.stringify(e,null,2)}],isError:e.isError||void 0}),ts=X.bz().describe('Value grammar: JSON scalars/arrays/objects emit literals; { link: "dataIdOrAlias" } emits linkData(() => data.dX) for property/data-link values; { ref: "idOrAliasOrVar", subspace?: "subspace-1"|1|"SUBSPACE_id" } emits () => namespace.varName; { expr: "raw TypeScript expression" } is spliced verbatim.'),to=X.Yj().describe("Dotted entry path to edit, for example title, property.url, outlets.response, animation.show, value, type, switches[0].property.text, or items[0].frame."),tl=X.Yj().describe("Project-relative entry file path, for example subspaces/subspace-0/bricks.ts, generators.ts, canvases.ts, data.ts, or animations.ts."),td=X.Yj().describe("Exported const name or entity alias to edit, for example bWelcomeText, gApiClient, cMain, or an alias like welcomeText."),tc=X.Yj().describe("Entry id fallback. When file is omitted, scans project subspaces for this id."),tp=X.zM().describe("Override compile verification for this call. Defaults to BRICKS_CTOR_MCP_EDIT_VERIFY, otherwise true."),tu={file:tl.optional(),entry:td.optional(),id:tc.optional(),verify:tp.optional()};function tf(e,t){var r,i,n,a,s,o,l;e.tool("edit_entry","Edit map-shaped facets on an existing bricks-ctor entry by source AST. Use set/unset with dotted paths and the shared value grammar.",{...tu,set:X.g1(to,ts).describe("Map of dotted paths to values. Values use the shared grammar: JSON literals, { link }, { ref }, or { expr }.").optional(),unset:X.YO(to).describe("Dotted paths to remove.").optional(),switch:X.KC([X.Yj(),X.ai()]).describe("Optional switch id or zero-based switch index; edits that switch object instead of the entry root.").optional()},(r=R(function*(e){return ta((yield eq(t,e)))}),function(e){return r.apply(this,arguments)})),e.tool("edit_events","Edit an event action array on an entry or switch. Adds/removes/replaces/moves/clears EventAction objects.",{...tu,event:X.Yj().describe("Camel-case source event key such as onPress, showStart, update, enter, or firstEnter."),op:X.k5(["add","remove","replace","move","clear"]).describe("Array operation. add inserts at index or appends; replace/remove require index; move reorders index to `to`; clear removes the event key."),index:X.ai().describe("Zero-based event action index. For add this is the insertion position.").optional(),to:X.ai().describe("Destination zero-based index for move.").optional(),action:ts.describe('For add/replace, the flattened form: { handler: "system"|{ref}|{subspace: "subspace-1"|1|"SUBSPACE_id"}, name: "ACTION_NAME", params?: { inputName: value }, dataParams?: { dataRef: value }, cast?: "TypeName", waitAsync?: boolean }. Cross-subspace {subspace} handlers emit a () => subspaceN getter; the emitting subspace itself stays a literal id. The compiled source form { handler, action: { name, params: [...], dataParams: [...] }, waitAsync } and { expr: "raw EventAction" } are also accepted.').optional(),switch:X.KC([X.Yj(),X.ai()]).describe("Optional switch id or zero-based switch index; edits that switch events object.").optional()},(i=R(function*(e){return ta((yield eW(t,e)))}),function(e){return i.apply(this,arguments)})),e.tool("edit_canvas_items","Edit a Canvas entry items array. Use add/remove/replace to place bricks or move to update an item frame.",{...tu,op:X.k5(["add","remove","replace","move"]).describe("Canvas item operation. add inserts/appends, replace/remove use index, move updates frame at index."),index:X.ai().describe("Zero-based canvas item index.").optional(),item:ts.describe('For add/replace: { ref: "brickIdOrAliasOrVar", subspace?: ..., frame: { x, y, width, height, ... }, hidden?: boolean } places a brick; { subspace: "subspace-1"|1|"SUBSPACE_id", frame: ... } without ref embeds that subspace (emits a () => subspaceN getter). Frames require numeric x/y/width/height.').optional(),frame:ts.describe("Replacement frame such as { x, y, width, height }. Required for move; for add/replace it is used when item.frame is omitted.").optional()},(n=R(function*(e){return ta((yield eQ(t,e)))}),function(e){return n.apply(this,arguments)})),e.tool("edit_switches","Edit an entry switches array. Use edit_entry/edit_events with switch when changing switch facet bodies.",{...tu,op:X.k5(["add","remove","replace","move"]).describe("Switch array operation. add inserts/appends, replace/remove use index, move reorders to `to`."),index:X.KC([X.Yj(),X.ai()]).describe("Switch id or zero-based switch index. For add, this is optional insertion position.").optional(),to:X.ai().describe("Destination zero-based index for move.").optional(),switch:ts.describe('For add/replace: { id? (BRICK_STATE_GROUP_<uuid>; omit to auto-generate), title?, description?, conds?: [{ method: "=="|"!="|">"|"<"|">="|"<=", cond }], override?: { animation?, event?, property?, outlet? }, property?, outlets?, animation?, disabled?, break? }. Cond forms: { type: "inner_state", key: "current_canvas", value: canvasRef }, { type: "inner_state", outlet: "outletName", value }, { type: "property_bank", ref: dataRef, value }, { type: "property_bank_by_item_key", ref: dataRef, value }, a compiled { __typename: "SwitchCond..." } object, or { expr }. Set switch events with edit_events using its switch parameter.').optional()},(a=R(function*(e){return ta((yield e5(t,e)))}),function(e){return a.apply(this,arguments)})),e.tool("new_entry","Create a minimal standard-style exported entry skeleton in an entry file, then optionally apply set/events edits.",{file:tl,entry:td.describe("Optional exported const name. Defaults from alias/title/id.").optional(),templateKey:X.Yj().describe("Brick/generator templateKey such as BRICK_TEXT or GENERATOR_HTTP.").optional(),type:X.Yj().describe("TypeScript type imported from bricks-ctor, for example BrickText, GeneratorHTTP, Canvas, Data, or Animation."),alias:X.Yj().describe("Optional entry alias. Also influences default exported const name.").optional(),title:X.Yj().describe("Optional entry title.").optional(),description:X.Yj().describe("Optional entry description.").optional(),id:tc.describe("Optional explicit id. If omitted, the tool generates one with the file-kind prefix.").optional(),dataType:X.Yj().describe("For data.ts only: initial Data.type value. Defaults to any.").optional(),set:X.g1(to,ts).describe("Optional initial dotted-path values applied after creating the skeleton. Values use JSON literals, { link }, { ref }, or { expr }.").optional(),events:X.YO(ts).describe("Optional initial event actions as objects with { event, action }.").optional(),verify:tp.optional()},(s=R(function*(e){return ta((yield e7(t,e)))}),function(e){return s.apply(this,arguments)})),e.tool("remove_entry","Remove an entry. By default cascades same-subspace references in standard entry object/array shapes; strict mode refuses when references exist.",{...tu,strict:X.zM().describe("When true, do not edit files; refuse and return reference sites if the entry is referenced.").optional(),scope:X.k5(["subspace","project"]).describe("Reference scan scope. subspace is default; project scans all subspaces.").optional()},(o=R(function*(e){return ta((yield ti(t,e)))}),function(e){return o.apply(this,arguments)})),e.tool("new_subspace","Scaffold a new subspaces/subspace-N directory (standard entry files + root canvas, fixed SUBSPACE_ id) and wire it into root.ts. Embed it afterwards with edit_canvas_items { subspace } or target it with edit_events { handler: { subspace } }.",{title:X.Yj().describe("Subspace title shown in the editor."),description:X.Yj().describe("Optional subspace description.").optional(),layout:X.Ik({width:X.ai(),height:X.ai(),resizeMode:X.k5(["cover","stretch"]).optional()}).describe("Subspace grid the embed frame scales; defaults to { width: 96, height: 54 }. Use a smaller grid plus resizeMode: 'stretch' for panel modules.").optional(),portal:X.k5(["top","left","bottom","right"]).describe("Dock the subspace to a viewport edge as an always-on overlay instead of a canvas-embeddable module.").optional(),verify:tp.optional()},(l=R(function*(e){return ta((yield tn(t,e)))}),function(e){return l.apply(this,arguments)}))}var tm={editEntry:eq,editEvents:eW,editCanvasItems:eQ,editSwitches:e5,newEntry:e7,newSubspace:tn,removeEntry:ti,resolveReference:eR};i()}catch(e){i(e)}})}};
44
+ `}})({subspaceId:c,canvasId:p,title:t.title,description:t.description??"",layout:{width:t.layout?.width??96,height:t.layout?.height??54,resizeMode:t.layout?.resizeMode},portal:t.portal});yield(0,G.mkdir)(X.join(d,"data-calc"),{recursive:!0});var f=[];for(var m of Object.entries(u)){var y=R(m,2),v=y[0],h=y[1],b=X.join(d,v),w=yield(0,V.format)(b,h,ee.Hn);yield(0,G.writeFile)((yield ep(e,b)),w.errors.length>0?h:w.code),f.push((0,ee.RI)(e,b))}var x=eC(a,`./subspaces/${l}`,`subspace${o}`);s.declaration.elements.push(J.identifier(x)),yield eU(a);var _=yield(0,Q.H)(e,t.verify);return{subspace:l,id:c,index:o,files:f,change:{op:"new_subspace",rootImport:x},outcome:"compile:failed"===_.status?"verify_failed":"ok",verify:_,summary:`new_subspace ${l} (${t.title}) wired into root.ts -> ${_.status}`}}))}),function(e,t){return T.apply(this,arguments)}),to=e=>({content:[{type:"text",text:JSON.stringify(e,null,2)}],isError:e.isError||void 0}),tl=Z.bz().describe('Value grammar: JSON scalars/arrays/objects emit literals; { link: "dataIdOrAlias" } emits linkData(() => data.dX) for property/data-link values; { ref: "idOrAliasOrVar", subspace?: "subspace-1"|1|"SUBSPACE_id" } emits () => namespace.varName; { expr: "raw TypeScript expression" } is spliced verbatim.'),td=Z.Yj().describe("Dotted entry path to edit, for example title, property.url, outlets.response, animation.show, value, type, switches[0].property.text, or items[0].frame."),tc=Z.Yj().describe("Project-relative entry file path, for example subspaces/subspace-0/bricks.ts, generators.ts, canvases.ts, data.ts, or animations.ts."),tp=Z.Yj().describe("Exported const name or entity alias to edit, for example bWelcomeText, gApiClient, cMain, or an alias like welcomeText."),tu=Z.Yj().describe("Entry id fallback. When file is omitted, scans project subspaces for this id."),tf=Z.zM().describe("Override compile verification for this call. Defaults to BRICKS_CTOR_MCP_EDIT_VERIFY, otherwise true."),tm={file:tc.optional(),entry:tp.optional(),id:tu.optional(),verify:tf.optional()};function ty(e,t){var r,i,n,a,s,o,l;e.tool("edit_entry","Edit map-shaped facets on an existing bricks-ctor entry by source AST. Use set/unset with dotted paths and the shared value grammar.",{...tm,set:Z.g1(td,tl).describe("Map of dotted paths to values. Values use the shared grammar: JSON literals, { link }, { ref }, or { expr }.").optional(),unset:Z.YO(td).describe("Dotted paths to remove.").optional(),switch:Z.KC([Z.Yj(),Z.ai()]).describe("Optional switch id or zero-based switch index; edits that switch object instead of the entry root.").optional()},(r=D(function*(e){return to((yield eY(t,e)))}),function(e){return r.apply(this,arguments)})),e.tool("edit_events","Edit an event action array on an entry or switch. Adds/removes/replaces/moves/clears EventAction objects.",{...tm,event:Z.Yj().describe("Camel-case source event key such as onPress, showStart, update, enter, or firstEnter."),op:Z.k5(["add","remove","replace","move","clear"]).describe("Array operation. add inserts at index or appends; replace/remove require index; move reorders index to `to`; clear removes the event key."),index:Z.ai().describe("Zero-based event action index. For add this is the insertion position.").optional(),to:Z.ai().describe("Destination zero-based index for move.").optional(),action:tl.describe('For add/replace, the flattened form: { handler: "system"|{ref}|{subspace: "subspace-1"|1|"SUBSPACE_id"}, name: "ACTION_NAME", params?: { inputName: value }, dataParams?: { dataRef: value }, cast?: "TypeName", waitAsync?: boolean }. Cross-subspace {subspace} handlers emit a () => subspaceN getter; the emitting subspace itself stays a literal id. The compiled source form { handler, action: { name, params: [...], dataParams: [...] }, waitAsync } and { expr: "raw EventAction" } are also accepted.').optional(),switch:Z.KC([Z.Yj(),Z.ai()]).describe("Optional switch id or zero-based switch index; edits that switch events object.").optional()},(i=D(function*(e){return to((yield eZ(t,e)))}),function(e){return i.apply(this,arguments)})),e.tool("edit_canvas_items","Edit a Canvas entry items array. Use add/remove/replace to place bricks or move to update an item frame.",{...tm,op:Z.k5(["add","remove","replace","move"]).describe("Canvas item operation. add inserts/appends, replace/remove use index, move updates frame at index."),index:Z.ai().describe("Zero-based canvas item index.").optional(),item:tl.describe('For add/replace: { ref: "brickIdOrAliasOrVar", subspace?: ..., frame: { x, y, width, height, ... }, hidden?: boolean } places a brick; { subspace: "subspace-1"|1|"SUBSPACE_id", frame: ... } without ref embeds that subspace (emits a () => subspaceN getter). Frames require numeric x/y/width/height.').optional(),frame:tl.describe("Replacement frame such as { x, y, width, height }. Required for move; for add/replace it is used when item.frame is omitted.").optional()},(n=D(function*(e){return to((yield e1(t,e)))}),function(e){return n.apply(this,arguments)})),e.tool("edit_switches","Edit an entry switches array. Use edit_entry/edit_events with switch when changing switch facet bodies.",{...tm,op:Z.k5(["add","remove","replace","move"]).describe("Switch array operation. add inserts/appends, replace/remove use index, move reorders to `to`."),index:Z.KC([Z.Yj(),Z.ai()]).describe("Switch id or zero-based switch index. For add, this is optional insertion position.").optional(),to:Z.ai().describe("Destination zero-based index for move.").optional(),switch:tl.describe('For add/replace: { id? (BRICK_STATE_GROUP_<uuid>; omit to auto-generate), title?, description?, conds?: [{ method: "=="|"!="|">"|"<"|">="|"<=", cond }], override?: { animation?, event?, property?, outlet? }, property?, outlets?, animation?, disabled?, break? }. Cond forms: { type: "inner_state", key: "current_canvas", value: canvasRef }, { type: "inner_state", outlet: "outletName", value }, { type: "property_bank", ref: dataRef, value }, { type: "property_bank_by_item_key", ref: dataRef, value }, a compiled { __typename: "SwitchCond..." } object, or { expr }. Set switch events with edit_events using its switch parameter.').optional()},(a=D(function*(e){return to((yield e8(t,e)))}),function(e){return a.apply(this,arguments)})),e.tool("new_entry","Create a minimal standard-style exported entry skeleton in an entry file, then optionally apply set/events edits.",{file:tc,entry:tp.describe("Optional exported const name. Defaults from alias/title/id.").optional(),templateKey:Z.Yj().describe("Brick/generator templateKey such as BRICK_TEXT or GENERATOR_HTTP.").optional(),type:Z.Yj().describe("TypeScript type imported from bricks-ctor, for example BrickText, GeneratorHTTP, Canvas, Data, or Animation."),alias:Z.Yj().describe("Optional entry alias. Also influences default exported const name.").optional(),title:Z.Yj().describe("Optional entry title.").optional(),description:Z.Yj().describe("Optional entry description.").optional(),id:tu.describe("Optional explicit id. If omitted, the tool generates one with the file-kind prefix.").optional(),dataType:Z.Yj().describe("For data.ts only: initial Data.type value. Defaults to any.").optional(),set:Z.g1(td,tl).describe("Optional initial dotted-path values applied after creating the skeleton. Values use JSON literals, { link }, { ref }, or { expr }.").optional(),events:Z.YO(tl).describe("Optional initial event actions as objects with { event, action }.").optional(),verify:tf.optional()},(s=D(function*(e){return to((yield e2(t,e)))}),function(e){return s.apply(this,arguments)})),e.tool("remove_entry","Remove an entry. By default cascades same-subspace references in standard entry object/array shapes; strict mode refuses when references exist.",{...tm,strict:Z.zM().describe("When true, do not edit files; refuse and return reference sites if the entry is referenced.").optional(),scope:Z.k5(["subspace","project"]).describe("Reference scan scope. subspace is default; project scans all subspaces.").optional()},(o=D(function*(e){return to((yield ta(t,e)))}),function(e){return o.apply(this,arguments)})),e.tool("new_subspace","Scaffold a new subspaces/subspace-N directory (standard entry files + root canvas, fixed SUBSPACE_ id) and wire it into root.ts. Embed it afterwards with edit_canvas_items { subspace } or target it with edit_events { handler: { subspace } }.",{title:Z.Yj().describe("Subspace title shown in the editor."),description:Z.Yj().describe("Optional subspace description.").optional(),layout:Z.Ik({width:Z.ai(),height:Z.ai(),resizeMode:Z.k5(["cover","stretch"]).optional()}).describe("Subspace grid the embed frame scales; defaults to { width: 96, height: 54 }. Use a smaller grid plus resizeMode: 'stretch' for panel modules.").optional(),portal:Z.k5(["top","left","bottom","right"]).describe("Dock the subspace to a viewport edge as an always-on overlay instead of a canvas-embeddable module.").optional(),verify:tf.optional()},(l=D(function*(e){return to((yield ts(t,e)))}),function(e){return l.apply(this,arguments)}))}var tv={editEntry:eY,editEvents:eZ,editCanvasItems:e1,editSwitches:e8,newEntry:e2,newSubspace:ts,removeEntry:ta,resolveReference:eF};i()}catch(e){i(e)}})}};
package/lib/3976.js CHANGED
@@ -1,14 +1,14 @@
1
- export const __rspack_esm_id=3976;export const __rspack_esm_ids=[3976];export const __webpack_modules__={79491(e){e.exports=import("oxfmt").then(function(e){return e})},48875(e,t){let r=["title","update_timestamp"],i=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),a=e=>void 0===e||"function"==typeof e||"symbol"==typeof e,n=e=>"number"!=typeof e||Number.isFinite(e)?e:null,o=e=>{if(!a(e))return Array.isArray(e)?e.map(e=>a(e)?null:o(e)):i(e)?Object.entries(e).reduce((e,[t,r])=>(a(r)||(e[t]=o(r)),e),{}):n(e)},s=(e,t)=>Object.prototype.hasOwnProperty.call(e,t)&&!a(e[t]),l=(e,t)=>{let r=e[t];return a(r)?null:r},c=(e,t)=>{if((e=n(e))===(t=n(t)))return!0;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r+=1)if(!c(l(e,r),l(t,r)))return!1;return!0}if(i(e)&&i(t)){let r=0;for(let i of Object.keys(e))if(!a(e[i])&&(r+=1,!s(t,i)||!c(e[i],t[i])))return!1;let i=0;for(let e of Object.keys(t))a(t[e])||(i+=1);return r===i}return!1},u=e=>{if(!i(e))return e;let t={...e};for(let e of r)delete t[e];return t},d=(e,t,r,a)=>{if(!c(e,t)){if(i(e)&&i(t)){for(let i of new Set([...Object.keys(e),...Object.keys(t)])){let n=s(e,i),l=s(t,i);if(!n&&!l)continue;let c=[...r,i];l?n?d(e[i],t[i],c,a):a.push({op:"set",path:c,value:o(t[i])}):a.push({op:"unset",path:c})}return}if(Array.isArray(e)&&Array.isArray(t)&&e.length===t.length){for(let i=0;i<t.length;i+=1)d(l(e,i),l(t,i),[...r,i],a);return}a.push({op:"set",path:r,value:o(t)})}};t.O2=(e,t)=>{let r=[];return d(u(e),u(t),[],r),r}},2985(e,t,r){r.d(t,{Re:()=>c,m4:()=>l});var i,a=r(99436),n=r(51455),o=r(76760),s=r(48875),l=(e,t)=>{if(null==e)return{status:"no_baseline"};if(null==t)return{status:"unavailable"};var r=(0,s.O2)(e,t);return{status:"ok",ops:r,opCount:r.length}},c=(i=a(function*(e){try{return JSON.parse((yield(0,n.readFile)(o.join(e,".bricks/build/application-config.json"),"utf8")))}catch{return null}}),function(e){return i.apply(this,arguments)})},3540(e,t,r){r.d(t,{S:()=>d,a:()=>u});var i,a,n=r(99436),o=r(51455),s=r(76760),l=".bricks/edits.jsonl",c=(i=n(function*(e){var t=s.join(e,".gitignore"),r=yield(0,o.readFile)(t,"utf8").catch(e=>{if(e?.code==="ENOENT")return"";throw e});if(!r.split(/\r?\n/).map(e=>e.trim()).some(e=>e===l||".bricks/"===e||".bricks"===e)){var i=r&&!r.endsWith("\n")?"\n":"";yield(0,o.writeFile)(t,`${r}${i}
1
+ export const __rspack_esm_id=3976;export const __rspack_esm_ids=[3976];export const __webpack_modules__={79491(e){e.exports=import("oxfmt").then(function(e){return e})},48875(e,r){let t=["title","update_timestamp"],i=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),a=e=>void 0===e||"function"==typeof e||"symbol"==typeof e,n=e=>"number"!=typeof e||Number.isFinite(e)?e:null,o=e=>{if(!a(e))return Array.isArray(e)?e.map(e=>a(e)?null:o(e)):i(e)?Object.entries(e).reduce((e,[r,t])=>(a(t)||(e[r]=o(t)),e),{}):n(e)},s=(e,r)=>Object.prototype.hasOwnProperty.call(e,r)&&!a(e[r]),l=(e,r)=>{let t=e[r];return a(t)?null:t},c=(e,r)=>{if((e=n(e))===(r=n(r)))return!0;if(Array.isArray(e)&&Array.isArray(r)){if(e.length!==r.length)return!1;for(let t=0;t<e.length;t+=1)if(!c(l(e,t),l(r,t)))return!1;return!0}if(i(e)&&i(r)){let t=0;for(let i of Object.keys(e))if(!a(e[i])&&(t+=1,!s(r,i)||!c(e[i],r[i])))return!1;let i=0;for(let e of Object.keys(r))a(r[e])||(i+=1);return t===i}return!1},u=e=>{if(!i(e))return e;let r={...e};for(let e of t)delete r[e];return r},d=(e,r,t,a)=>{if(!c(e,r)){if(i(e)&&i(r)){for(let i of new Set([...Object.keys(e),...Object.keys(r)])){let n=s(e,i),l=s(r,i);if(!n&&!l)continue;let c=[...t,i];l?n?d(e[i],r[i],c,a):a.push({op:"set",path:c,value:o(r[i])}):a.push({op:"unset",path:c})}return}if(Array.isArray(e)&&Array.isArray(r)&&e.length===r.length){for(let i=0;i<r.length;i+=1)d(l(e,i),l(r,i),[...t,i],a);return}a.push({op:"set",path:t,value:o(r)})}};r.O2=(e,r)=>{let t=[];return d(u(e),u(r),[],t),t}},2985(e,r,t){t.d(r,{Re:()=>c,m4:()=>l});var i,a=t(99436),n=t(51455),o=t(76760),s=t(48875),l=(e,r)=>{if(null==e)return{status:"no_baseline"};if(null==r)return{status:"unavailable"};var t=(0,s.O2)(e,r);return{status:"ok",ops:t,opCount:t.length}},c=(i=a(function*(e){try{return JSON.parse((yield(0,n.readFile)(o.join(e,".bricks/build/application-config.json"),"utf8")))}catch{return null}}),function(e){return i.apply(this,arguments)})},3540(e,r,t){t.d(r,{S:()=>d,a:()=>u});var i,a,n=t(99436),o=t(51455),s=t(76760),l=".bricks/edits.jsonl",c=(i=n(function*(e){var r=s.join(e,".gitignore"),t=yield(0,o.readFile)(r,"utf8").catch(e=>{if(e?.code==="ENOENT")return"";throw e});if(!t.split(/\r?\n/).map(e=>e.trim()).some(e=>e===l||".bricks/"===e||".bricks"===e)){var i=t&&!t.endsWith("\n")?"\n":"";yield(0,o.writeFile)(r,`${t}${i}
2
2
  # MCP entry-editing audit log
3
3
  ${l}
4
- `)}}),function(e){return i.apply(this,arguments)}),u=(a=n(function*(e,t){var r=s.join(e,".bricks");yield(0,o.mkdir)(r,{recursive:!0}),yield c(e),yield(0,o.appendFile)(s.join(r,"edits.jsonl"),`${JSON.stringify(t)}
5
- `)}),function(e,t){return a.apply(this,arguments)}),d=()=>({session:process.env.BRICKS_CTOR_SESSION_ID||process.env.CODEX_SESSION_ID,agent:process.env.BRICKS_CTOR_AGENT_ID||process.env.USER})},98009(e,t,r){r.d(t,{Gp:()=>l,HJ:()=>p,Hn:()=>n,JJ:()=>d,Kx:()=>m,Pb:()=>y,RI:()=>s,bf:()=>u,jc:()=>f,u4:()=>o,zu:()=>c});var i=r(58135),a=r(76760),n={trailingComma:"all",tabWidth:2,semi:!1,singleQuote:!0,printWidth:100},o=e=>!!e&&"object"==typeof e&&!Array.isArray(e),s=(e,t)=>a.relative(e,t).replace(/\\/g,"/").replace(/^\.\/+/,""),l=e=>i.isIdentifier(e)?e.name:i.isStringLiteral(e)||i.isNumericLiteral(e)?String(e.value):null,c=e=>/^[$A-Z_a-z][$\w]*$/.test(e)?i.identifier(e):i.stringLiteral(e),u=(e,t)=>e.properties.find(e=>!!i.isObjectProperty(e)&&l(e.key)===t),d=(e,t)=>{var r=u(e,t);if(r&&i.isStringLiteral(r.value))return r.value.value},p=(e,t,r)=>{var a=u(e,t);if(a){a.value=r;return}e.properties.push(i.objectProperty(c(t),r))},f=(e,t)=>{var r=e.properties.findIndex(e=>!!i.isObjectProperty(e)&&l(e.key)===t);r>=0&&e.properties.splice(r,1)},y=(e,t)=>{var r=e.program.body,a=r.findLastIndex(e=>i.isImportDeclaration(e));r.splice(a+1,0,t)},m=(e,t,r)=>{var a=new Set(Array.from(r).filter(Boolean));if(0!==a.size){var n,o=function(e){return i.isImportDeclaration(e)&&"bricks-ctor"===e.source.value&&"type"===t==("type"===e.importKind)?(e.specifiers.forEach(e=>{if(i.isImportSpecifier(e)){var t=e.imported;i.isIdentifier(t)&&a.delete(t.name),i.isStringLiteral(t)&&a.delete(t.value)}}),a.forEach(t=>{e.specifiers.push(i.importSpecifier(i.identifier(t),i.identifier(t)))}),{v:void 0}):0};for(var s of e.program.body)if(0!==(n=o(s))&&n)return n.v;var l=i.importDeclaration(Array.from(a).map(e=>i.importSpecifier(i.identifier(e),i.identifier(e))),i.stringLiteral("bricks-ctor"));"type"===t&&(l.importKind="type"),y(e,l)}}},54452(e,t,r){r.d(t,{H:()=>u});var i,a,n=r(99436),o=r(75720),s=r(2985),l={FORCE_COLOR:"0",NO_COLOR:"1"},c=(i=n(function*(e){var t=yield(0,s.Re)(e);try{yield(0,o.sh)`bun compile`.cwd(e).env({...l,BRICKS_CTOR_ENABLE_EDITING_TOOLS:"0"}).text()}catch(e){var r=[e.stdout?.toString()??"",e.stderr?.toString()??"",e.message].filter(Boolean).join("\n").trim();return{status:"compile:failed",errors:r?[r]:["bun compile failed"]}}var i=yield(0,s.Re)(e);return{status:"compile:ok",errors:[],configChange:(0,s.m4)(t,i)}}),function(e){return i.apply(this,arguments)}),u=(a=n(function*(e,t){return(void 0!==t?t:!["0","false","no","off"].includes((process.env.BRICKS_CTOR_MCP_EDIT_VERIFY??"true").toLowerCase()))?c(e):{status:"skipped",errors:[]}}),function(e,t){return a.apply(this,arguments)})},69899(e,t,r){r.a(e,async function(e,i){try{r.r(t),r.d(t,{__test__:()=>eJ,register:()=>eT});var a,n,o,s,l,c,u,d,p,f,y,m,b,v,h,g,x,_,w,j,k,I=r(68832),S=r(99436),$=r(44668),E=r(5018),O=r(63315),P=r(30409),C=r(40906),D=r(59410),A=r(2235),L=r(46773),R=r(58135),F=r(11978),N=r(79491),T=r(51455),J=r(76760),Y=r(84867),M=r(54452),z=r(98009),q=r(3540),H=e([N]);function K(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(K=function(){return!!e})()}N=(H.then?(await H)():H)[0];var B=A.default||A,W=function(e){function t(e,r,i,a=!1){var n,o,s;return E(this,t),o=t,s=[r],o=P(o),(n=O(this,K()?Reflect.construct(o,s||[],P(this).constructor):o.apply(this,s))).name="DataCalcEditingError",n.code=e,n.details=i,n.isMcpError=a,n}return C(t,e),$(t)}(D(Error)),U=(e,t)=>{if(J.isAbsolute(t))throw new W("invalid_file","File must be project-relative",{file:t});var r=J.resolve(e,t),i=J.relative(e,r);if(i.startsWith("..")||J.isAbsolute(i))throw new W("invalid_file","File must stay inside the project directory",{file:t});return r},V=(e,t)=>{try{return(0,L.parse)(e,{sourceType:"module",plugins:["typescript","topLevelAwait"],errorRecovery:!1})}catch(e){throw new W("parse_failed",`Cannot parse ${t} as TypeScript: ${e.message}. Edit this file directly.`,{file:t},!0)}},G=(a=S(function*(e,t){var r=yield(0,T.readFile)(t,"utf8"),i=(0,z.RI)(e,t);return{source:r,ast:V(r,i),absPath:t,relPath:i}}),function(e,t){return a.apply(this,arguments)}),Z=e=>e.program.body.flatMap(e=>R.isExportNamedDeclaration(e)&&R.isVariableDeclaration(e.declaration)?e.declaration.declarations.flatMap(e=>{if(!R.isIdentifier(e.id))return[];var t,r=e.id.typeAnnotation;R.isTSTypeAnnotation(r)&&R.isTSTypeReference(r.typeAnnotation)&&R.isIdentifier(r.typeAnnotation.typeName)&&(t=r.typeAnnotation.typeName.name);var i=R.isObjectExpression(e.init)?e.init:void 0;return[{name:e.id.name,object:i,id:i?(0,z.JJ)(i,"id"):void 0,alias:i?(0,z.JJ)(i,"alias"):void 0,typeName:t}]}):[]),Q=(e,t)=>{if(null==t||""===t)return J.join(e,"subspaces/subspace-0");if("number"==typeof t)return J.join(e,"subspaces",`subspace-${t}`);var r=String(t);if(/^\d+$/.test(r))return J.join(e,"subspaces",`subspace-${r}`);if(/^subspace-\d+$/.test(r))return J.join(e,"subspaces",r);if(r.includes("/"))return U(e,r);throw new W("unsupported_subspace",`Unsupported subspace locator: ${r}`,{subspace:r})},X=e=>{var t=J.basename(e),r=/^data-calculation-(.+)\.ts$/.exec(t);if(!r)throw new W("invalid_file","Expected data-calculation-{slug}.ts file",{file:e});return r[1]},ee=(n=S(function*(e){return(yield(0,T.readdir)(e,{withFileTypes:!0}).catch(()=>[])).filter(e=>e.isFile()&&/^data-calculation-.+\.ts$/.test(e.name)&&!e.name.endsWith(".sandbox.ts")).map(t=>J.join(e,t.name)).sort()}),function(e){return n.apply(this,arguments)}),et=e=>{var t=(0,z.bf)(e,"code")?.value;return t&&R.isExpression(t)?t:null},er=e=>{var t=R.isAwaitExpression(e)?e.argument:e;if(!R.isCallExpression(t))return null;var r=t.arguments[0];if(!R.isNewExpression(r)||!R.isIdentifier(r.callee)||"URL"!==r.callee.name)return null;var i=r.arguments[0];return R.isStringLiteral(i)?i.value:null},ei=(o=S(function*(e,t){if(t.file)a=U(e,t.file);else{var r,i,a,n=Q(e,t.subspace),o=J.join(n,"data-calc"),s=yield ee(o),l=t.calc;if(!l)throw new W("missing_calc","Provide file or subspace+calc");for(var c of s){if(l===X(c)){a=c;break}try{var u=yield G(e,c),d=Z(u.ast).find(e=>"dataCalculation"===e.name);if(d&&(l===d.alias||l===d.id)){a=c;break}}catch{continue}}}if(!a)throw new W("calc_not_found",`Data calc not found: ${t.calc}`,{calc:t.calc,subspace:t.subspace??"subspace-0"});var p=yield G(e,a),f=(e=>{var t=Z(e.ast).find(e=>"dataCalculation"===e.name);if(!t||!t.object)throw new W("fallback_recommended",`Data calc ${e.relPath} is not a single exported object literal. Edit this file directly for this one.`,{file:e.relPath,check:"export const dataCalculation object literal"});var r=(0,z.JJ)(t.object,"__typename");if("DataCalculationScript"!==r)throw new W("fallback_recommended",`Data calc ${e.relPath} is ${r||"not DataCalculationScript"}. DataCalculationMap is out of scope; edit this file directly.`,{file:e.relPath,typename:r});return t.object})(p),y=X(a),m=(r=et(f),(i=er(r))&&/^(\.\/)?[^/\\]+\.sandbox\.js$/.test(i)?i.replace(/^\.\//,""):`data-calculation-${y}.sandbox.js`);return{parsed:p,object:f,slug:y,sandboxFile:m}}),function(e,t){return o.apply(this,arguments)}),ea=e=>{for(var t of e.program.body)if(R.isImportDeclaration(t)&&"node:fs/promises"===t.source.value){t.specifiers.some(e=>R.isImportSpecifier(e)&&R.isIdentifier(e.imported)&&"readFile"===e.imported.name)||t.specifiers.push(R.importSpecifier(R.identifier("readFile"),R.identifier("readFile")));return}(0,z.Pb)(e,R.importDeclaration([R.importSpecifier(R.identifier("readFile"),R.identifier("readFile"))],R.stringLiteral("node:fs/promises")))},en=e=>{(0,z.Kx)(e.parsed.ast,"type",e.typeImports),(0,z.Kx)(e.parsed.ast,"value",e.valueImports)},eo=(s=S(function*(e,t,r,i){var a,n=(e=>{var t=e.split(J.sep),r=t.findIndex(e=>/^subspace-\d+$/.test(e));if(r<0)throw new W("invalid_file","Data-calc file must be inside subspaces/subspace-N/data-calc",{file:e});return t.slice(0,r+1).join(J.sep)})(t),o=null==i?n:Q(e,i),s=J.join(o,"data.ts"),l=yield G(e,s),c=Z(l.ast).filter(e=>e.name===r||e.id===r||e.alias===r);if(0===c.length)throw new W("reference_not_found",`Data reference not found: ${r}`,{ref:r,subspace:J.basename(o)});if(c.length>1)throw new W("ambiguous_reference",`Data reference is ambiguous: ${r}`,{ref:r,matches:c.map(t=>({file:(0,z.RI)(e,s),entry:t.name,id:t.id,alias:t.alias}))});var u=J.resolve(s)===J.resolve(t);return{input:r,id:c[0].id,alias:c[0].alias,varName:c[0].name,sameFile:u,importSource:u?void 0:((a=J.relative(J.dirname(t),s).replace(/\\/g,"/")).startsWith(".")||(a=`./${a}`),a.replace(/\.(ts|tsx|js|jsx)$/,""))}}),function(e,t,r,i){return s.apply(this,arguments)}),es=(l=S(function*(e,t){if((0,z.u4)(e)&&"string"==typeof e.expr)return(0,L.parseExpression)(e.expr,{plugins:["typescript"]});var r="string"==typeof e?e:(0,z.u4)(e)?e.ref:void 0;if("string"!=typeof r||!r)throw new W("invalid_ref","Data getter requires a data ref string");var i=yield eo(t.projectDir,t.parsed.absPath,r,(0,z.u4)(e)?e.subspace:void 0),a=i.sameFile?"data":((e,t,r)=>{for(var i of e.ast.program.body)if(R.isImportDeclaration(i)&&i.source.value===t){var a=i.specifiers.find(e=>R.isImportNamespaceSpecifier(e));if(a)return a.local.name}var n=(e=>{var t=new Set;for(var r of e.program.body){if(R.isImportDeclaration(r)){r.specifiers.forEach(e=>t.add(e.local.name));continue}R.isExportNamedDeclaration(r)&&R.isVariableDeclaration(r.declaration)&&r.declaration.declarations.forEach(e=>{R.isIdentifier(e.id)&&t.add(e.id.name)})}return t})(e.ast),o=r;if(n.has(o)){for(var s=1;n.has(`${o}${s}`);)s+=1;o=`${o}${s}`}var l=R.importDeclaration([R.importNamespaceSpecifier(R.identifier(o))],R.stringLiteral(t));return(0,z.Pb)(e.ast,l),o})(t.parsed,i.importSource||"../data","data");return t.references.push(i),R.arrowFunctionExpression([],R.memberExpression(R.identifier(a),R.identifier(i.varName)))}),function(e,t){return l.apply(this,arguments)}),el=(c=S(function*(e,t){return null==e?R.nullLiteral():es(e,t)}),function(e,t){return c.apply(this,arguments)}),ec=(u=S(function*(e,t){var r=J.join(e,"subspaces");for(var i of yield(0,T.readdir)(r,{withFileTypes:!0}).catch(()=>[]))if(i.isDirectory()&&/^subspace-\d+$/.test(i.name))for(var a of yield ee(J.join(r,i.name,"data-calc")))try{var n=yield G(e,a),o=Z(n.ast).find(e=>"dataCalculation"===e.name);if(o?.alias===t)return!0}catch{continue}return!1}),function(e,t){return u.apply(this,arguments)}),eu=new Set(["__typename","id","code","enableAsync","inputs","output","outputs","error"]),ed=e=>R.awaitExpression(R.callExpression(R.identifier("readFile"),[R.newExpression(R.identifier("URL"),[R.stringLiteral(`./${e}`),R.memberExpression(R.metaProperty(R.identifier("import"),R.identifier("meta")),R.identifier("url"))]),R.stringLiteral("utf8")])),ep=(d=S(function*(e,t){if((0,z.u4)(e)){if("string"==typeof e.expr)return(0,L.parseExpression)(e.expr,{plugins:["typescript"]});if("string"==typeof e.ref)return es(e,t)}if(null===e)return R.nullLiteral();if(void 0===e)return R.identifier("undefined");if("string"==typeof e)return R.stringLiteral(e);if("number"==typeof e)return R.numericLiteral(e);if("boolean"==typeof e)return R.booleanLiteral(e);if(Array.isArray(e))return R.arrayExpression((yield Promise.all(e.map(e=>ep(e,t)))));if((0,z.u4)(e)){var r,i=yield Promise.all(Object.entries(e).map((r=S(function*([e,r]){return R.objectProperty((0,z.zu)(e),(yield ep(r,t)))}),function(e){return r.apply(this,arguments)})));return R.objectExpression(i)}throw new W("invalid_value",`Unsupported value: ${String(e)}`)}),function(e,t){return d.apply(this,arguments)}),ef=(p=S(function*(e){var t=B(e.ast,{comments:!0},e.source).code,r=yield(0,N.format)(e.absPath,t,z.Hn);if(r.errors.length>0)throw new W("format_failed",`oxfmt failed for ${e.relPath}`,{file:e.relPath,errors:r.errors});return r.code}),function(e){return p.apply(this,arguments)}),ey=(f=S(function*(e){var t=yield ef(e);return V(t,e.relPath),yield(0,T.writeFile)(e.absPath,t),t}),function(e){return f.apply(this,arguments)}),em=e=>({content:[{type:"text",text:JSON.stringify(e,null,2)}],isError:e.isError||void 0}),eb=e=>e.map(e=>({input:e.input,id:e.id,alias:e.alias,entry:e.varName})),ev=(y=S(function*(e,t,r,i){var a=new Date().toISOString(),n=(0,q.S)();try{var o=yield i();return yield(0,q.a)(e,{ts:a,tool:t,input:r,provenance:n,outcome:o.outcome,summary:o.summary,result:o}),o}catch(i){var s=i instanceof W,l=s&&"fallback_recommended"===i.code?"fallback_recommended":"error",c={outcome:l,isError:"error"===l,error:{code:s?i.code:"unexpected_error",message:i.message,details:s?i.details:void 0},summary:`${t} failed: ${i.message}`};return yield(0,q.a)(e,{ts:a,tool:t,input:r,provenance:n,outcome:c.outcome,summary:c.summary,error:c.error}).catch(()=>void 0),c}}),function(e,t,r,i){return y.apply(this,arguments)}),eh=(m=S(function*(e,t){var r=new Set((yield ee(e)).map(X));if(t){var i=t.trim().replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"calc";if(!r.has(i))return i;for(var a=1;r.has(`${i}-${a}`);)a+=1;return`${i}-${a}`}for(var n=0;r.has(String(n));)n+=1;return String(n)}),function(e,t){return m.apply(this,arguments)}),eg=e=>{try{return(0,F.qg)(e,{sourceType:"module",ecmaVersion:2020}),!0}catch{return!1}},ex=e=>{var t=e??"";if((e=>{try{var t=(0,F.qg)(e,{sourceType:"module",ecmaVersion:2020}).body[0];return t?.type==="ExportNamedDeclaration"&&t.declaration?.type==="FunctionDeclaration"&&t.declaration.id?.name==="main"}catch{return!1}})(t))return t.endsWith("\n")?t:`${t}
6
- `;var r=t.trim();if(!r)return"export function main() {\n}\n";for(var i of["","async "]){var a=`export ${i}function main() {
7
- ${r}
4
+ `)}}),function(e){return i.apply(this,arguments)}),u=(a=n(function*(e,r){var t=s.join(e,".bricks");yield(0,o.mkdir)(t,{recursive:!0}),yield c(e),yield(0,o.appendFile)(s.join(t,"edits.jsonl"),`${JSON.stringify(r)}
5
+ `)}),function(e,r){return a.apply(this,arguments)}),d=()=>({session:process.env.BRICKS_CTOR_SESSION_ID||process.env.CODEX_SESSION_ID,agent:process.env.BRICKS_CTOR_AGENT_ID||process.env.USER})},98009(e,r,t){t.d(r,{Gp:()=>b,HJ:()=>x,Hn:()=>u,JJ:()=>g,Kx:()=>j,LJ:()=>y,Pb:()=>w,RI:()=>p,bf:()=>h,jc:()=>_,u4:()=>d,z5:()=>m,zu:()=>v});var i,a,n=t(68832),o=t(99436),s=t(58135),l=t(51455),c=t(76760),u={trailingComma:"all",tabWidth:2,semi:!1,singleQuote:!0,printWidth:100},d=e=>!!e&&"object"==typeof e&&!Array.isArray(e),p=(e,r)=>c.relative(e,r).replace(/\\/g,"/").replace(/^\.\/+/,""),f=(e,r)=>{var t=c.relative(e,r);return""!==t&&(t.startsWith(`..${c.sep}`)||".."===t||c.isAbsolute(t))?null:r},y=(i=o(function*(e,r){var t=n((yield Promise.all([(0,l.realpath)(e),(0,l.realpath)(r)])),2);return f(t[0],t[1])}),function(e,r){return i.apply(this,arguments)}),m=(a=o(function*(e,r){var t=yield(0,l.lstat)(r).catch(e=>{if(e?.code==="ENOENT")return null;throw e}),i=yield(0,l.realpath)(e);if(t){var a=yield(0,l.realpath)(r).catch(e=>{if(e?.code==="ENOENT")return null;throw e});return a?f(i,a):null}var n=yield(0,l.realpath)(c.dirname(r));return f(i,c.join(n,c.basename(r)))}),function(e,r){return a.apply(this,arguments)}),b=e=>s.isIdentifier(e)?e.name:s.isStringLiteral(e)||s.isNumericLiteral(e)?String(e.value):null,v=e=>/^[$A-Z_a-z][$\w]*$/.test(e)?s.identifier(e):s.stringLiteral(e),h=(e,r)=>e.properties.find(e=>!!s.isObjectProperty(e)&&b(e.key)===r),g=(e,r)=>{var t=h(e,r);if(t&&s.isStringLiteral(t.value))return t.value.value},x=(e,r,t)=>{var i=h(e,r);if(i){i.value=t;return}e.properties.push(s.objectProperty(v(r),t))},_=(e,r)=>{var t=e.properties.findIndex(e=>!!s.isObjectProperty(e)&&b(e.key)===r);t>=0&&e.properties.splice(t,1)},w=(e,r)=>{var t=e.program.body,i=t.findLastIndex(e=>s.isImportDeclaration(e));t.splice(i+1,0,r)},j=(e,r,t)=>{var i=new Set(Array.from(t).filter(Boolean));if(0!==i.size){var a,n=function(e){return s.isImportDeclaration(e)&&"bricks-ctor"===e.source.value&&"type"===r==("type"===e.importKind)?(e.specifiers.forEach(e=>{if(s.isImportSpecifier(e)){var r=e.imported;s.isIdentifier(r)&&i.delete(r.name),s.isStringLiteral(r)&&i.delete(r.value)}}),i.forEach(r=>{e.specifiers.push(s.importSpecifier(s.identifier(r),s.identifier(r)))}),{v:void 0}):0};for(var o of e.program.body)if(0!==(a=n(o))&&a)return a.v;var l=s.importDeclaration(Array.from(i).map(e=>s.importSpecifier(s.identifier(e),s.identifier(e))),s.stringLiteral("bricks-ctor"));"type"===r&&(l.importKind="type"),w(e,l)}}},54452(e,r,t){t.d(r,{H:()=>u});var i,a,n=t(99436),o=t(75720),s=t(2985),l={FORCE_COLOR:"0",NO_COLOR:"1"},c=(i=n(function*(e){var r=yield(0,s.Re)(e);try{yield(0,o.sh)`bun compile`.cwd(e).env({...l,BRICKS_CTOR_ENABLE_EDITING_TOOLS:"0"}).text()}catch(e){var t=[e.stdout?.toString()??"",e.stderr?.toString()??"",e.message].filter(Boolean).join("\n").trim();return{status:"compile:failed",errors:t?[t]:["bun compile failed"]}}var i=yield(0,s.Re)(e);return{status:"compile:ok",errors:[],configChange:(0,s.m4)(r,i)}}),function(e){return i.apply(this,arguments)}),u=(a=n(function*(e,r){return(void 0!==r?r:!["0","false","no","off"].includes((process.env.BRICKS_CTOR_MCP_EDIT_VERIFY??"true").toLowerCase()))?c(e):{status:"skipped",errors:[]}}),function(e,r){return a.apply(this,arguments)})},69899(e,r,t){t.a(e,async function(e,i){try{t.r(r),t.d(r,{__test__:()=>eM,register:()=>eY});var a,n,o,s,l,c,u,d,p,f,y,m,b,v,h,g,x,_,w,j,k,I,$=t(68832),S=t(99436),E=t(44668),O=t(5018),P=t(63315),D=t(30409),C=t(40906),A=t(59410),L=t(2235),R=t(46773),N=t(58135),F=t(11978),T=t(79491),J=t(51455),Y=t(76760),M=t(84867),z=t(54452),q=t(98009),H=t(3540),K=e([T]);function B(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(B=function(){return!!e})()}T=(K.then?(await K)():K)[0];var W=L.default||L,U=function(e){function r(e,t,i,a=!1){var n,o,s;return O(this,r),o=r,s=[t],o=D(o),(n=P(this,B()?Reflect.construct(o,s||[],D(this).constructor):o.apply(this,s))).name="DataCalcEditingError",n.code=e,n.details=i,n.isMcpError=a,n}return C(r,e),E(r)}(A(Error)),V=(e,r)=>{if(Y.isAbsolute(r))throw new U("invalid_file","File must be project-relative",{file:r});var t=Y.resolve(e,r),i=Y.relative(e,t);if(i.startsWith("..")||Y.isAbsolute(i))throw new U("invalid_file","File must stay inside the project directory",{file:r});return t},G=(e,r)=>{try{return(0,R.parse)(e,{sourceType:"module",plugins:["typescript","topLevelAwait"],errorRecovery:!1})}catch(e){throw new U("parse_failed",`Cannot parse ${r} as TypeScript: ${e.message}. Edit this file directly.`,{file:r},!0)}},Z=(a=S(function*(e,r){var t=yield(0,q.LJ)(e,r);if(!t)throw new U("invalid_file","File must stay inside the project directory",{file:(0,q.RI)(e,r)});var i=yield(0,J.readFile)(t,"utf8"),a=(0,q.RI)(e,r);return{source:i,ast:G(i,a),projectDir:e,absPath:r,ioPath:t,relPath:a}}),function(e,r){return a.apply(this,arguments)}),Q=(n=S(function*(e,r){var t=yield(0,q.z5)(e,r);if(!t)throw new U("invalid_file","File must stay inside the project directory",{file:(0,q.RI)(e,r)});return t}),function(e,r){return n.apply(this,arguments)}),X=e=>e.program.body.flatMap(e=>N.isExportNamedDeclaration(e)&&N.isVariableDeclaration(e.declaration)?e.declaration.declarations.flatMap(e=>{if(!N.isIdentifier(e.id))return[];var r,t=e.id.typeAnnotation;N.isTSTypeAnnotation(t)&&N.isTSTypeReference(t.typeAnnotation)&&N.isIdentifier(t.typeAnnotation.typeName)&&(r=t.typeAnnotation.typeName.name);var i=N.isObjectExpression(e.init)?e.init:void 0;return[{name:e.id.name,object:i,id:i?(0,q.JJ)(i,"id"):void 0,alias:i?(0,q.JJ)(i,"alias"):void 0,typeName:r}]}):[]),ee=(e,r)=>{if(null==r||""===r)return Y.join(e,"subspaces/subspace-0");if("number"==typeof r)return Y.join(e,"subspaces",`subspace-${r}`);var t=String(r);if(/^\d+$/.test(t))return Y.join(e,"subspaces",`subspace-${t}`);if(/^subspace-\d+$/.test(t))return Y.join(e,"subspaces",t);if(t.includes("/"))return V(e,t);throw new U("unsupported_subspace",`Unsupported subspace locator: ${t}`,{subspace:t})},er=e=>{var r=Y.basename(e),t=/^data-calculation-(.+)\.ts$/.exec(r);if(!t)throw new U("invalid_file","Expected data-calculation-{slug}.ts file",{file:e});return t[1]},et=(o=S(function*(e){return(yield(0,J.readdir)(e,{withFileTypes:!0}).catch(()=>[])).filter(e=>e.isFile()&&/^data-calculation-.+\.ts$/.test(e.name)&&!e.name.endsWith(".sandbox.ts")).map(r=>Y.join(e,r.name)).sort()}),function(e){return o.apply(this,arguments)}),ei=e=>{var r=(0,q.bf)(e,"code")?.value;return r&&N.isExpression(r)?r:null},ea=e=>{var r=N.isAwaitExpression(e)?e.argument:e;if(!N.isCallExpression(r))return null;var t=r.arguments[0];if(!N.isNewExpression(t)||!N.isIdentifier(t.callee)||"URL"!==t.callee.name)return null;var i=t.arguments[0];return N.isStringLiteral(i)?i.value:null},en=(s=S(function*(e,r){if(r.file)a=V(e,r.file);else{var t,i,a,n=ee(e,r.subspace),o=Y.join(n,"data-calc"),s=yield et(o),l=r.calc;if(!l)throw new U("missing_calc","Provide file or subspace+calc");for(var c of s){if(l===er(c)){a=c;break}try{var u=yield Z(e,c),d=X(u.ast).find(e=>"dataCalculation"===e.name);if(d&&(l===d.alias||l===d.id)){a=c;break}}catch{continue}}}if(!a)throw new U("calc_not_found",`Data calc not found: ${r.calc}`,{calc:r.calc,subspace:r.subspace??"subspace-0"});var p=yield Z(e,a),f=(e=>{var r=X(e.ast).find(e=>"dataCalculation"===e.name);if(!r||!r.object)throw new U("fallback_recommended",`Data calc ${e.relPath} is not a single exported object literal. Edit this file directly for this one.`,{file:e.relPath,check:"export const dataCalculation object literal"});var t=(0,q.JJ)(r.object,"__typename");if("DataCalculationScript"!==t)throw new U("fallback_recommended",`Data calc ${e.relPath} is ${t||"not DataCalculationScript"}. DataCalculationMap is out of scope; edit this file directly.`,{file:e.relPath,typename:t});return r.object})(p),y=er(a),m=(t=ei(f),(i=ea(t))&&/^(\.\/)?[^/\\]+\.sandbox\.js$/.test(i)?i.replace(/^\.\//,""):`data-calculation-${y}.sandbox.js`);return{parsed:p,object:f,slug:y,sandboxFile:m}}),function(e,r){return s.apply(this,arguments)}),eo=e=>{for(var r of e.program.body)if(N.isImportDeclaration(r)&&"node:fs/promises"===r.source.value){r.specifiers.some(e=>N.isImportSpecifier(e)&&N.isIdentifier(e.imported)&&"readFile"===e.imported.name)||r.specifiers.push(N.importSpecifier(N.identifier("readFile"),N.identifier("readFile")));return}(0,q.Pb)(e,N.importDeclaration([N.importSpecifier(N.identifier("readFile"),N.identifier("readFile"))],N.stringLiteral("node:fs/promises")))},es=e=>{(0,q.Kx)(e.parsed.ast,"type",e.typeImports),(0,q.Kx)(e.parsed.ast,"value",e.valueImports)},el=(l=S(function*(e,r,t,i){var a,n=(e=>{var r=e.split(Y.sep),t=r.findIndex(e=>/^subspace-\d+$/.test(e));if(t<0)throw new U("invalid_file","Data-calc file must be inside subspaces/subspace-N/data-calc",{file:e});return r.slice(0,t+1).join(Y.sep)})(r),o=null==i?n:ee(e,i),s=Y.join(o,"data.ts"),l=yield Z(e,s),c=X(l.ast).filter(e=>e.name===t||e.id===t||e.alias===t);if(0===c.length)throw new U("reference_not_found",`Data reference not found: ${t}`,{ref:t,subspace:Y.basename(o)});if(c.length>1)throw new U("ambiguous_reference",`Data reference is ambiguous: ${t}`,{ref:t,matches:c.map(r=>({file:(0,q.RI)(e,s),entry:r.name,id:r.id,alias:r.alias}))});var u=Y.resolve(s)===Y.resolve(r);return{input:t,id:c[0].id,alias:c[0].alias,varName:c[0].name,sameFile:u,importSource:u?void 0:((a=Y.relative(Y.dirname(r),s).replace(/\\/g,"/")).startsWith(".")||(a=`./${a}`),a.replace(/\.(ts|tsx|js|jsx)$/,""))}}),function(e,r,t,i){return l.apply(this,arguments)}),ec=(c=S(function*(e,r){if((0,q.u4)(e)&&"string"==typeof e.expr)return(0,R.parseExpression)(e.expr,{plugins:["typescript"]});var t="string"==typeof e?e:(0,q.u4)(e)?e.ref:void 0;if("string"!=typeof t||!t)throw new U("invalid_ref","Data getter requires a data ref string");var i=yield el(r.projectDir,r.parsed.absPath,t,(0,q.u4)(e)?e.subspace:void 0),a=i.sameFile?"data":((e,r,t)=>{for(var i of e.ast.program.body)if(N.isImportDeclaration(i)&&i.source.value===r){var a=i.specifiers.find(e=>N.isImportNamespaceSpecifier(e));if(a)return a.local.name}var n=(e=>{var r=new Set;for(var t of e.program.body){if(N.isImportDeclaration(t)){t.specifiers.forEach(e=>r.add(e.local.name));continue}N.isExportNamedDeclaration(t)&&N.isVariableDeclaration(t.declaration)&&t.declaration.declarations.forEach(e=>{N.isIdentifier(e.id)&&r.add(e.id.name)})}return r})(e.ast),o=t;if(n.has(o)){for(var s=1;n.has(`${o}${s}`);)s+=1;o=`${o}${s}`}var l=N.importDeclaration([N.importNamespaceSpecifier(N.identifier(o))],N.stringLiteral(r));return(0,q.Pb)(e.ast,l),o})(r.parsed,i.importSource||"../data","data");return r.references.push(i),N.arrowFunctionExpression([],N.memberExpression(N.identifier(a),N.identifier(i.varName)))}),function(e,r){return c.apply(this,arguments)}),eu=(u=S(function*(e,r){return null==e?N.nullLiteral():ec(e,r)}),function(e,r){return u.apply(this,arguments)}),ed=(d=S(function*(e,r){var t=Y.join(e,"subspaces");for(var i of yield(0,J.readdir)(t,{withFileTypes:!0}).catch(()=>[]))if(i.isDirectory()&&/^subspace-\d+$/.test(i.name))for(var a of yield et(Y.join(t,i.name,"data-calc")))try{var n=yield Z(e,a),o=X(n.ast).find(e=>"dataCalculation"===e.name);if(o?.alias===r)return!0}catch{continue}return!1}),function(e,r){return d.apply(this,arguments)}),ep=new Set(["__typename","id","code","enableAsync","inputs","output","outputs","error"]),ef=e=>N.awaitExpression(N.callExpression(N.identifier("readFile"),[N.newExpression(N.identifier("URL"),[N.stringLiteral(`./${e}`),N.memberExpression(N.metaProperty(N.identifier("import"),N.identifier("meta")),N.identifier("url"))]),N.stringLiteral("utf8")])),ey=(p=S(function*(e,r){if((0,q.u4)(e)){if("string"==typeof e.expr)return(0,R.parseExpression)(e.expr,{plugins:["typescript"]});if("string"==typeof e.ref)return ec(e,r)}if(null===e)return N.nullLiteral();if(void 0===e)return N.identifier("undefined");if("string"==typeof e)return N.stringLiteral(e);if("number"==typeof e)return N.numericLiteral(e);if("boolean"==typeof e)return N.booleanLiteral(e);if(Array.isArray(e))return N.arrayExpression((yield Promise.all(e.map(e=>ey(e,r)))));if((0,q.u4)(e)){var t,i=yield Promise.all(Object.entries(e).map((t=S(function*([e,t]){return N.objectProperty((0,q.zu)(e),(yield ey(t,r)))}),function(e){return t.apply(this,arguments)})));return N.objectExpression(i)}throw new U("invalid_value",`Unsupported value: ${String(e)}`)}),function(e,r){return p.apply(this,arguments)}),em=(f=S(function*(e){var r=W(e.ast,{comments:!0},e.source).code,t=yield(0,T.format)(e.absPath,r,q.Hn);if(t.errors.length>0)throw new U("format_failed",`oxfmt failed for ${e.relPath}`,{file:e.relPath,errors:t.errors});return t.code}),function(e){return f.apply(this,arguments)}),eb=(y=S(function*(e){var r=yield em(e);return G(r,e.relPath),yield(0,J.writeFile)(e.ioPath??(yield Q(e.projectDir,e.absPath)),r),r}),function(e){return y.apply(this,arguments)}),ev=e=>({content:[{type:"text",text:JSON.stringify(e,null,2)}],isError:e.isError||void 0}),eh=e=>e.map(e=>({input:e.input,id:e.id,alias:e.alias,entry:e.varName})),eg=(m=S(function*(e,r,t,i){var a=new Date().toISOString(),n=(0,H.S)();try{var o=yield i();return yield(0,H.a)(e,{ts:a,tool:r,input:t,provenance:n,outcome:o.outcome,summary:o.summary,result:o}),o}catch(i){var s=i instanceof U,l=s&&"fallback_recommended"===i.code?"fallback_recommended":"error",c={outcome:l,isError:"error"===l,error:{code:s?i.code:"unexpected_error",message:i.message,details:s?i.details:void 0},summary:`${r} failed: ${i.message}`};return yield(0,H.a)(e,{ts:a,tool:r,input:t,provenance:n,outcome:c.outcome,summary:c.summary,error:c.error}).catch(()=>void 0),c}}),function(e,r,t,i){return m.apply(this,arguments)}),ex=(b=S(function*(e,r){var t=new Set((yield et(e)).map(er));if(r){var i=r.trim().replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"calc";if(!t.has(i))return i;for(var a=1;t.has(`${i}-${a}`);)a+=1;return`${i}-${a}`}for(var n=0;t.has(String(n));)n+=1;return String(n)}),function(e,r){return b.apply(this,arguments)}),e_=e=>{try{return(0,F.qg)(e,{sourceType:"module",ecmaVersion:2020}),!0}catch{return!1}},ew=e=>{var r=e??"";if((e=>{try{var r=(0,F.qg)(e,{sourceType:"module",ecmaVersion:2020}).body[0];return r?.type==="ExportNamedDeclaration"&&r.declaration?.type==="FunctionDeclaration"&&r.declaration.id?.name==="main"}catch{return!1}})(r))return r.endsWith("\n")?r:`${r}
6
+ `;var t=r.trim();if(!t)return"export function main() {\n}\n";for(var i of["","async "]){var a=`export ${i}function main() {
7
+ ${t}
8
8
  }
9
- `;if(eg(a))return a}throw new W("invalid_code",/export\s+(async\s+)?function\s+main\s*\(/.test(t)?"Sandbox code does not parse as a module (note: top-level await requires export async function main)":"Sandbox code does not parse as a script body (statements with top-level return)")},e_=(b=S(function*(e,t){yield(0,T.mkdir)(t,{recursive:!0});var r=yield ee(t),i=r.map((e,t)=>{var r=X(e);return`import { dataCalculation as dataCalculation${t} } from './data-calculation-${r}'`}).join("\n"),a=r.map((e,t)=>`dataCalculation${t}`).join(",\n "),n=`${i}
9
+ `;if(e_(a))return a}throw new U("invalid_code",/export\s+(async\s+)?function\s+main\s*\(/.test(r)?"Sandbox code does not parse as a module (note: top-level await requires export async function main)":"Sandbox code does not parse as a script body (statements with top-level return)")},ej=(v=S(function*(e,r){yield(0,J.mkdir)(r,{recursive:!0});var t=yield et(r),i=t.map((e,r)=>{var t=er(e);return`import { dataCalculation as dataCalculation${r} } from './data-calculation-${t}'`}).join("\n"),a=t.map((e,r)=>`dataCalculation${r}`).join(",\n "),n=`${i}
10
10
 
11
11
  export const dataCalculation = [
12
12
  ${a}
13
13
  ]
14
- `,o=J.join(t,"index.ts"),s={absPath:o,relPath:(0,z.RI)(e,o),source:n,ast:V(n,(0,z.RI)(e,o))};return yield ey(s),(0,z.RI)(e,o)}),function(e,t){return b.apply(this,arguments)}),ew=(v=S(function*(e,t){var r=J.join(t,"index.ts"),i=(0,z.RI)(e,r),a=yield(0,T.readFile)(r,"utf8").catch(e=>{if(e?.code==="ENOENT")return null;throw e});if(null==a)return{warning:`${i} not found; wire the data-calc import manually`};var n=yield G(e,r),o=(e=>{for(var t of e.program.body)if(R.isExportDefaultDeclaration(t)){var r=t.declaration;if(R.isObjectExpression(r))return r;if(R.isTSAsExpression(r)&&R.isObjectExpression(r.expression))return r.expression}return null})(n.ast);if(!o)return{warning:`${i} has no default-export object; wire the data-calc import manually`};var s=(0,z.bf)(o,"dataCalculation");if(s&&R.isIdentifier(s.value))return null;if(s&&!(R.isArrayExpression(s.value)&&0===s.value.elements.length))return{warning:`${i} has a non-empty dataCalculation value; wire the data-calc import manually`};if(n.ast.program.body.some(e=>R.isImportDeclaration(e)&&("./data-calc"===e.source.value||"./data-calc/index"===e.source.value))||(0,z.Pb)(n.ast,R.importDeclaration([R.importSpecifier(R.identifier("dataCalculation"),R.identifier("dataCalculation"))],R.stringLiteral("./data-calc"))),s)s.value=R.identifier("dataCalculation"),R.isIdentifier(s.key)&&(s.shorthand=!0);else{var l=R.objectProperty(R.identifier("dataCalculation"),R.identifier("dataCalculation"));l.shorthand=!0,o.properties.push(l)}return yield ey(n),{touched:n.relPath}}),function(e,t){return v.apply(this,arguments)}),ej=(h=S(function*(e,t,r){if(!t.key)throw new W("missing_key",`${e} item requires key`);if(null==t.data)throw new W("missing_data",`${e} item requires data`);var i=[R.objectProperty(R.identifier("key"),R.stringLiteral(t.key)),R.objectProperty(R.identifier("data"),(yield es(t.data,r)))];return"inputs"===e&&i.push(R.objectProperty(R.identifier("trigger"),R.booleanLiteral(!1!==t.trigger))),R.objectExpression(i)}),function(e,t,r){return h.apply(this,arguments)}),ek=(g=S(function*(e,t,r){if("inputs"===e){var i=new Set;for(var a of t){if(i.has(a?.key))throw new W("duplicate_key",`Input key already exists: ${a.key}`,{key:a.key});i.add(a?.key)}}return R.arrayExpression((yield Promise.all(t.map(t=>ej(e,t,r)))))}),function(e,t,r){return g.apply(this,arguments)}),eI=(e,t)=>{if("number"==typeof t.index)return t.index;if(!t.key)return -1;var r=e.elements.map((e,t)=>({element:e,index:t})).filter(({element:e})=>R.isObjectExpression(e)&&(0,z.JJ)(e,"key")===t.key);if(r.length>1)throw new W("ambiguous_key",`IO key is ambiguous: ${t.key}`,{key:t.key,count:r.length});return r[0]?.index??-1},eS=(x=S(function*(e,t,r,i){let a;r.typeImports.add("DataCalculationScript"),r.valueImports.add("makeId"),ea(r.parsed.ast);var n=[R.objectProperty(R.identifier("__typename"),R.stringLiteral("DataCalculationScript")),R.objectProperty(R.identifier("id"),e.id?R.stringLiteral(e.id):(a="property_bank_calc",R.callExpression(R.identifier("makeId"),i?[R.stringLiteral(a),R.stringLiteral(i)]:[R.stringLiteral(a)])))];return e.alias&&n.push(R.objectProperty(R.identifier("alias"),R.stringLiteral(e.alias))),null!=e.title&&n.push(R.objectProperty(R.identifier("title"),R.stringLiteral(e.title))),null!=e.description&&n.push(R.objectProperty(R.identifier("description"),R.stringLiteral(e.description))),null!=e.note&&n.push(R.objectProperty(R.identifier("note"),R.stringLiteral(e.note))),n.push(R.objectProperty(R.identifier("code"),ed(t))),n.push(R.objectProperty(R.identifier("enableAsync"),R.booleanLiteral(!!e.enableAsync))),null!=e.triggerMode&&n.push(R.objectProperty(R.identifier("triggerMode"),R.stringLiteral(e.triggerMode))),n.push(R.objectProperty(R.identifier("inputs"),(yield ek("inputs",e.inputs||[],r)))),n.push(R.objectProperty(R.identifier("output"),(yield el(e.output,r)))),n.push(R.objectProperty(R.identifier("outputs"),(yield ek("outputs",e.outputs||[],r)))),n.push(R.objectProperty(R.identifier("error"),(yield el(e.error,r)))),R.objectExpression(n)}),function(e,t,r,i){return x.apply(this,arguments)}),e$=(_=S(function*(e,t){return ev(e,"new_data_calc",t,S(function*(){var r,i,a,n=Q(e,t.subspace),o=J.join(n,"data-calc");yield(0,T.mkdir)(o,{recursive:!0});var s=yield eh(o,t.alias),l=`data-calculation-${s}.sandbox.js`,c=J.join(o,`data-calculation-${s}.ts`),u=J.join(o,l),d=(r=(0,z.RI)(e,c),i="export const dataCalculation = {}\n",(a=V(i,r)).program.body=[],{ast:a,source:i,absPath:c,relPath:r}),p={projectDir:e,parsed:d,references:[],typeImports:new Set,valueImports:new Set},f=t.id||"string"!=typeof t.alias||!t.alias||(yield ec(e,t.alias))?void 0:t.alias,y=yield eS(t,l,p,f),m=R.variableDeclarator(R.identifier("dataCalculation"),y);m.id.typeAnnotation=R.tsTypeAnnotation(R.tsTypeReference(R.identifier("DataCalculationScript"))),d.ast.program.body.push(R.exportNamedDeclaration(R.variableDeclaration("const",[m]))),en(p),yield(0,T.writeFile)(u,ex(t.code)),yield ey(d);var b=[{file:(0,z.RI)(e,c),action:"create_calc"},{file:(0,z.RI)(e,u),action:"write_sandbox"}];b.push({file:yield e_(e,o),action:"regenerate_index"});var v=yield ew(e,n);v?.touched&&b.push({file:v.touched,action:"wire_subspace_index"});var h=yield(0,M.H)(e,t.verify);return{file:(0,z.RI)(e,c),subspace:J.basename(n),calc:s,idExpression:t.id??(f?`makeId('property_bank_calc', '${f}')`:"makeId('property_bank_calc')"),outcome:"compile:failed"===h.status?"verify_failed":"ok",touchedSites:b,...v?.warning?{warnings:[v.warning]}:{},verify:h,references:eb(p.references),summary:`created data calc ${s} in ${J.basename(n)} -> ${h.status}`}}))}),function(e,t){return _.apply(this,arguments)}),eE=(w=S(function*(e,t){return ev(e,"edit_data_calc",t,S(function*(){var r=yield ei(e,t),i={projectDir:e,parsed:r.parsed,references:[],typeImports:new Set,valueImports:new Set},a=[];for(var n of Object.entries(t.set||{})){var o=I(n,2),s=o[0],l=o[1];if("output"===s||"error"===s)(0,z.HJ)(r.object,s,(yield el(l,i)));else if("inputs"===s||"outputs"===s){if(!Array.isArray(l))throw new W("invalid_value",`${s} must be an array of IO items`);(0,z.HJ)(r.object,s,(yield ek(s,l,i)))}else if("code"===s)throw new W("invalid_field","Set code via the dedicated code parameter so it stays normalized to the sandbox file");else(0,z.HJ)(r.object,s,(yield ep(l,i)))}for(var c of t.unset||[]){if(eu.has(c))throw new W("invalid_field",`Cannot unset required field: ${c}`,{field:c});(0,z.jc)(r.object,c)}if(null!=t.code){var u=et(r.object);if(!(e=>{if(!e)return!1;if(R.isStringLiteral(e)||R.isTemplateLiteral(e))return!0;var t=er(e);return null!=t&&/^(\.\/)?[^/\\]+\.sandbox\.js$/.test(t)})(u))throw new W("fallback_recommended",`Data calc ${r.parsed.relPath} has an unsupported code expression. Edit this file directly for this one.`,{file:r.parsed.relPath,field:"code"});var d=r.sandboxFile,p=J.join(J.dirname(r.parsed.absPath),d);yield(0,T.writeFile)(p,ex(t.code)),ea(r.parsed.ast),(0,z.HJ)(r.object,"code",ed(d)),a.push({file:(0,z.RI)(e,p),action:"write_sandbox"})}en(i),yield ey(r.parsed),a.unshift({file:r.parsed.relPath,action:"edit_calc"});var f=yield(0,M.H)(e,t.verify);return{file:r.parsed.relPath,calc:r.slug,outcome:"compile:failed"===f.status?"verify_failed":"ok",touchedSites:a,verify:f,references:eb(i.references),summary:`edited data calc ${r.slug} -> ${f.status}`}}))}),function(e,t){return w.apply(this,arguments)}),eO=(j=S(function*(e,t){return ev(e,"edit_data_calc_io",t,S(function*(){var r=yield ei(e,t),i={projectDir:e,parsed:r.parsed,references:[],typeImports:new Set,valueImports:new Set},a=t.field,n=((e,t)=>{var r=(0,z.bf)(e,t);if(r){if(!R.isArrayExpression(r.value))throw new W("fallback_recommended",`${t} is not an array. Edit this file directly.`);return r.value}var i=R.arrayExpression([]);return e.properties.push(R.objectProperty(R.identifier(t),i)),i})(r.object,a),o=t.op;if("clear"===o)n.elements=[];else if("remove"===o){var s=eI(n,t);if(s<0||s>=n.elements.length)throw new W("invalid_index","remove requires a valid key or index");n.elements.splice(s,1)}else if("add"===o||"replace"===o){var l="replace"===o?eI(n,t):t.index;if("replace"===o&&(l<0||l>=n.elements.length))throw new W("invalid_index","replace requires a valid key or index");if("add"===o&&"number"==typeof l&&(l<0||l>n.elements.length))throw new W("invalid_index","add index out of range",{index:l});"inputs"===a&&((e,t,r)=>{if(e.elements.some((e,i)=>i!==r&&R.isObjectExpression(e)&&(0,z.JJ)(e,"key")===t))throw new W("duplicate_key",`Input key already exists: ${t}`,{key:t})})(n,t.key,"replace"===o?l:void 0);var c=yield ej(a,t,i);"replace"===o?n.elements[l]=c:n.elements.splice("number"==typeof l?l:n.elements.length,0,c)}else throw new W("invalid_op",`Unsupported edit_data_calc_io op: ${o}`);en(i),yield ey(r.parsed);var u=yield(0,M.H)(e,t.verify);return{file:r.parsed.relPath,calc:r.slug,outcome:"compile:failed"===u.status?"verify_failed":"ok",change:{field:a,op:o,key:t.key,index:t.index},verify:u,references:eb(i.references),summary:`${o} ${a} on data calc ${r.slug} -> ${u.status}`}}))}),function(e,t){return j.apply(this,arguments)}),eP=(k=S(function*(e,t){return ev(e,"remove_data_calc",t,S(function*(){var r=yield ei(e,t),i=J.dirname(r.parsed.absPath),a=J.join(i,r.sandboxFile);yield(0,T.rm)(r.parsed.absPath,{force:!0}),yield(0,T.rm)(a,{force:!0});var n=yield e_(e,i),o=yield(0,M.H)(e,t.verify);return{file:r.parsed.relPath,calc:r.slug,outcome:"compile:failed"===o.status?"verify_failed":"ok",touchedSites:[{file:r.parsed.relPath,action:"delete_calc"},{file:(0,z.RI)(e,a),action:"delete_sandbox"},{file:n,action:"regenerate_index"}],verify:o,summary:`removed data calc ${r.slug} -> ${o.status}`}}))}),function(e,t){return k.apply(this,arguments)}),eC=Y.bz().describe('Value grammar: JSON literals, bare data ref strings for output/error/IO data, { ref, subspace }, or { expr: "raw TypeScript expression" }.'),eD=Y.Yj().describe("Project-relative data-calc file path, for example subspaces/subspace-0/data-calc/data-calculation-total.ts."),eA=Y.KC([Y.Yj(),Y.ai()]).describe('Subspace locator. Defaults to subspace-0; accepts 0, "0", "subspace-0", or a project-relative subspace path.'),eL=Y.Yj().describe("Data calc locator inside the subspace: alias, explicit string id, or filename slug."),eR=Y.zM().describe("Override compile verification. Defaults to BRICKS_CTOR_MCP_EDIT_VERIFY, otherwise true."),eF={file:eD.optional(),subspace:eA.optional(),calc:eL.optional(),verify:eR.optional()},eN=Y.Ik({key:Y.Yj().describe('Sandbox input/output key, for example "price" or "total".'),data:eC.describe("Data ref as alias/id/varName, { ref, subspace }, or { expr }."),trigger:Y.zM().describe("Inputs only; defaults true.").optional()}).describe("DataCalculationScript IO item.");function eT(e,t){var r,i,a,n;e.tool("new_data_calc","Create a standard DataCalculationScript in data-calc/{calc}.ts plus its sandbox JS file, regenerate data-calc/index.ts, and wire minimal subspace indexes.",{subspace:eA.optional(),alias:Y.Yj().describe("Optional alias; also drives the filename slug.").optional(),title:Y.Yj().describe("Optional title.").optional(),description:Y.Yj().describe("Optional description.").optional(),note:Y.Yj().describe("Optional script note.").optional(),triggerMode:Y.k5(["auto","manual"]).describe("Optional trigger mode; omitted by default.").optional(),enableAsync:Y.zM().describe("Whether the sandbox main may be async. Defaults false.").optional(),code:Y.Yj().describe("Sandbox body. The tool wraps it as export function main() { ... } unless already wrapped.").optional(),inputs:Y.YO(eN).describe("Initial script inputs. Input keys must be unique.").optional(),outputs:Y.YO(eN).describe("Initial fan-out outputs. Output keys may repeat.").optional(),output:eC.describe("Single output data ref or null.").optional(),error:eC.describe("Error output data ref or null.").optional(),id:Y.Yj().describe("Optional explicit id. Defaults to source expression makeId('property_bank_calc').").optional(),verify:eR.optional()},(r=S(function*(e){return em((yield e$(t,e)))}),function(e){return r.apply(this,arguments)})),e.tool("edit_data_calc","Edit DataCalculationScript scalar fields, output/error refs, or sandbox code. Code edits normalize inline code to sandbox file-form.",{...eF,set:Y.g1(Y.Yj().describe("Top-level field path such as title, description, note, alias, triggerMode, enableAsync, output, or error."),eC).describe("Fields to set. output/error accept bare data ref strings, { ref, subspace }, { expr }, or null; inputs/outputs accept whole replacement arrays of { key, data, trigger? }. Use the code parameter for code.").optional(),unset:Y.YO(Y.Yj()).describe("Top-level fields to remove.").optional(),code:Y.Yj().describe("Replacement sandbox body. The tool wraps it as export function main() { ... } unless already wrapped.").optional()},(i=S(function*(e){return em((yield eE(t,e)))}),function(e){return i.apply(this,arguments)})),e.tool("edit_data_calc_io","Edit DataCalculationScript inputs or outputs arrays. Inputs require unique keys; outputs may repeat keys for fan-out.",{...eF,field:Y.k5(["inputs","outputs"]).describe("Which IO array to edit."),op:Y.k5(["add","remove","replace","clear"]).describe("Array operation."),key:Y.Yj().describe("IO key target. Ambiguous repeated output keys must use index.").optional(),index:Y.ai().describe("Zero-based IO index target or add insertion index.").optional(),data:eC.describe("For add/replace: data ref as string, { ref, subspace }, or { expr }.").optional(),trigger:Y.zM().describe("Inputs only; defaults true.").optional()},(a=S(function*(e){return em((yield eO(t,e)))}),function(e){return a.apply(this,arguments)})),e.tool("remove_data_calc","Remove a standard DataCalculationScript .ts file plus its sandbox file and regenerate data-calc/index.ts. No reverse cascade is needed.",eF,(n=S(function*(e){return em((yield eP(t,e)))}),function(e){return n.apply(this,arguments)}))}var eJ={newDataCalc:e$,editDataCalc:eE,editDataCalcIo:eO,removeDataCalc:eP,resolveCalcTarget:ei};i()}catch(e){i(e)}})}};
14
+ `,o=Y.join(r,"index.ts"),s={projectDir:e,absPath:o,relPath:(0,q.RI)(e,o),source:n,ast:G(n,(0,q.RI)(e,o))};return yield eb(s),(0,q.RI)(e,o)}),function(e,r){return v.apply(this,arguments)}),ek=(h=S(function*(e,r){var t=Y.join(r,"index.ts"),i=(0,q.RI)(e,t),a=yield(0,J.readFile)(t,"utf8").catch(e=>{if(e?.code==="ENOENT")return null;throw e});if(null==a)return{warning:`${i} not found; wire the data-calc import manually`};var n=yield Z(e,t),o=(e=>{for(var r of e.program.body)if(N.isExportDefaultDeclaration(r)){var t=r.declaration;if(N.isObjectExpression(t))return t;if(N.isTSAsExpression(t)&&N.isObjectExpression(t.expression))return t.expression}return null})(n.ast);if(!o)return{warning:`${i} has no default-export object; wire the data-calc import manually`};var s=(0,q.bf)(o,"dataCalculation");if(s&&N.isIdentifier(s.value))return null;if(s&&!(N.isArrayExpression(s.value)&&0===s.value.elements.length))return{warning:`${i} has a non-empty dataCalculation value; wire the data-calc import manually`};if(n.ast.program.body.some(e=>N.isImportDeclaration(e)&&("./data-calc"===e.source.value||"./data-calc/index"===e.source.value))||(0,q.Pb)(n.ast,N.importDeclaration([N.importSpecifier(N.identifier("dataCalculation"),N.identifier("dataCalculation"))],N.stringLiteral("./data-calc"))),s)s.value=N.identifier("dataCalculation"),N.isIdentifier(s.key)&&(s.shorthand=!0);else{var l=N.objectProperty(N.identifier("dataCalculation"),N.identifier("dataCalculation"));l.shorthand=!0,o.properties.push(l)}return yield eb(n),{touched:n.relPath}}),function(e,r){return h.apply(this,arguments)}),eI=(g=S(function*(e,r,t){if(!r.key)throw new U("missing_key",`${e} item requires key`);if(null==r.data)throw new U("missing_data",`${e} item requires data`);var i=[N.objectProperty(N.identifier("key"),N.stringLiteral(r.key)),N.objectProperty(N.identifier("data"),(yield ec(r.data,t)))];return"inputs"===e&&i.push(N.objectProperty(N.identifier("trigger"),N.booleanLiteral(!1!==r.trigger))),N.objectExpression(i)}),function(e,r,t){return g.apply(this,arguments)}),e$=(x=S(function*(e,r,t){if("inputs"===e){var i=new Set;for(var a of r){if(i.has(a?.key))throw new U("duplicate_key",`Input key already exists: ${a.key}`,{key:a.key});i.add(a?.key)}}var n=[];for(var o of r)n.push((yield eI(e,o,t)));return N.arrayExpression(n)}),function(e,r,t){return x.apply(this,arguments)}),eS=(e,r)=>{if("number"==typeof r.index)return r.index;if(!r.key)return -1;var t=e.elements.map((e,r)=>({element:e,index:r})).filter(({element:e})=>N.isObjectExpression(e)&&(0,q.JJ)(e,"key")===r.key);if(t.length>1)throw new U("ambiguous_key",`IO key is ambiguous: ${r.key}`,{key:r.key,count:t.length});return t[0]?.index??-1},eE=(_=S(function*(e,r,t,i){let a;t.typeImports.add("DataCalculationScript"),t.valueImports.add("makeId"),eo(t.parsed.ast);var n=[N.objectProperty(N.identifier("__typename"),N.stringLiteral("DataCalculationScript")),N.objectProperty(N.identifier("id"),e.id?N.stringLiteral(e.id):(a="property_bank_calc",N.callExpression(N.identifier("makeId"),i?[N.stringLiteral(a),N.stringLiteral(i)]:[N.stringLiteral(a)])))];return e.alias&&n.push(N.objectProperty(N.identifier("alias"),N.stringLiteral(e.alias))),null!=e.title&&n.push(N.objectProperty(N.identifier("title"),N.stringLiteral(e.title))),null!=e.description&&n.push(N.objectProperty(N.identifier("description"),N.stringLiteral(e.description))),null!=e.note&&n.push(N.objectProperty(N.identifier("note"),N.stringLiteral(e.note))),n.push(N.objectProperty(N.identifier("code"),ef(r))),n.push(N.objectProperty(N.identifier("enableAsync"),N.booleanLiteral(!!e.enableAsync))),null!=e.triggerMode&&n.push(N.objectProperty(N.identifier("triggerMode"),N.stringLiteral(e.triggerMode))),n.push(N.objectProperty(N.identifier("inputs"),(yield e$("inputs",e.inputs||[],t)))),n.push(N.objectProperty(N.identifier("output"),(yield eu(e.output,t)))),n.push(N.objectProperty(N.identifier("outputs"),(yield e$("outputs",e.outputs||[],t)))),n.push(N.objectProperty(N.identifier("error"),(yield eu(e.error,t)))),N.objectExpression(n)}),function(e,r,t,i){return _.apply(this,arguments)}),eO=(w=S(function*(e,r){return eg(e,"new_data_calc",r,S(function*(){var t,i,a,n=ee(e,r.subspace),o=Y.join(n,"data-calc");yield(0,J.mkdir)(o,{recursive:!0});var s=yield ex(o,r.alias),l=`data-calculation-${s}.sandbox.js`,c=Y.join(o,`data-calculation-${s}.ts`),u=Y.join(o,l),d=(t=(0,q.RI)(e,c),i="export const dataCalculation = {}\n",(a=G(i,t)).program.body=[],{ast:a,source:i,projectDir:e,absPath:c,relPath:t}),p={projectDir:e,parsed:d,references:[],typeImports:new Set,valueImports:new Set},f=r.id||"string"!=typeof r.alias||!r.alias||(yield ed(e,r.alias))?void 0:r.alias,y=yield eE(r,l,p,f),m=N.variableDeclarator(N.identifier("dataCalculation"),y);m.id.typeAnnotation=N.tsTypeAnnotation(N.tsTypeReference(N.identifier("DataCalculationScript"))),d.ast.program.body.push(N.exportNamedDeclaration(N.variableDeclaration("const",[m]))),es(p),yield(0,J.writeFile)((yield Q(e,u)),ew(r.code)),yield eb(d);var b=[{file:(0,q.RI)(e,c),action:"create_calc"},{file:(0,q.RI)(e,u),action:"write_sandbox"}];b.push({file:yield ej(e,o),action:"regenerate_index"});var v=yield ek(e,n);v?.touched&&b.push({file:v.touched,action:"wire_subspace_index"});var h=yield(0,z.H)(e,r.verify);return{file:(0,q.RI)(e,c),subspace:Y.basename(n),calc:s,idExpression:r.id??(f?`makeId('property_bank_calc', '${f}')`:"makeId('property_bank_calc')"),outcome:"compile:failed"===h.status?"verify_failed":"ok",touchedSites:b,...v?.warning?{warnings:[v.warning]}:{},verify:h,references:eh(p.references),summary:`created data calc ${s} in ${Y.basename(n)} -> ${h.status}`}}))}),function(e,r){return w.apply(this,arguments)}),eP=(j=S(function*(e,r){return eg(e,"edit_data_calc",r,S(function*(){var t=yield en(e,r),i={projectDir:e,parsed:t.parsed,references:[],typeImports:new Set,valueImports:new Set},a=[];for(var n of Object.entries(r.set||{})){var o=$(n,2),s=o[0],l=o[1];if("output"===s||"error"===s)(0,q.HJ)(t.object,s,(yield eu(l,i)));else if("inputs"===s||"outputs"===s){if(!Array.isArray(l))throw new U("invalid_value",`${s} must be an array of IO items`);(0,q.HJ)(t.object,s,(yield e$(s,l,i)))}else if("code"===s)throw new U("invalid_field","Set code via the dedicated code parameter so it stays normalized to the sandbox file");else(0,q.HJ)(t.object,s,(yield ey(l,i)))}for(var c of r.unset||[]){if(ep.has(c))throw new U("invalid_field",`Cannot unset required field: ${c}`,{field:c});(0,q.jc)(t.object,c)}if(null!=r.code){var u=ei(t.object);if(!(e=>{if(!e)return!1;if(N.isStringLiteral(e)||N.isTemplateLiteral(e))return!0;var r=ea(e);return null!=r&&/^(\.\/)?[^/\\]+\.sandbox\.js$/.test(r)})(u))throw new U("fallback_recommended",`Data calc ${t.parsed.relPath} has an unsupported code expression. Edit this file directly for this one.`,{file:t.parsed.relPath,field:"code"});var d=t.sandboxFile,p=Y.join(Y.dirname(t.parsed.absPath),d);yield(0,J.writeFile)((yield Q(e,p)),ew(r.code)),eo(t.parsed.ast),(0,q.HJ)(t.object,"code",ef(d)),a.push({file:(0,q.RI)(e,p),action:"write_sandbox"})}es(i),yield eb(t.parsed),a.unshift({file:t.parsed.relPath,action:"edit_calc"});var f=yield(0,z.H)(e,r.verify);return{file:t.parsed.relPath,calc:t.slug,outcome:"compile:failed"===f.status?"verify_failed":"ok",touchedSites:a,verify:f,references:eh(i.references),summary:`edited data calc ${t.slug} -> ${f.status}`}}))}),function(e,r){return j.apply(this,arguments)}),eD=(k=S(function*(e,r){return eg(e,"edit_data_calc_io",r,S(function*(){var t=yield en(e,r),i={projectDir:e,parsed:t.parsed,references:[],typeImports:new Set,valueImports:new Set},a=r.field,n=((e,r)=>{var t=(0,q.bf)(e,r);if(t){if(!N.isArrayExpression(t.value))throw new U("fallback_recommended",`${r} is not an array. Edit this file directly.`);return t.value}var i=N.arrayExpression([]);return e.properties.push(N.objectProperty(N.identifier(r),i)),i})(t.object,a),o=r.op;if("clear"===o)n.elements=[];else if("remove"===o){var s=eS(n,r);if(s<0||s>=n.elements.length)throw new U("invalid_index","remove requires a valid key or index");n.elements.splice(s,1)}else if("add"===o||"replace"===o){var l="replace"===o?eS(n,r):r.index;if("replace"===o&&(l<0||l>=n.elements.length))throw new U("invalid_index","replace requires a valid key or index");if("add"===o&&"number"==typeof l&&(l<0||l>n.elements.length))throw new U("invalid_index","add index out of range",{index:l});"inputs"===a&&((e,r,t)=>{if(e.elements.some((e,i)=>i!==t&&N.isObjectExpression(e)&&(0,q.JJ)(e,"key")===r))throw new U("duplicate_key",`Input key already exists: ${r}`,{key:r})})(n,r.key,"replace"===o?l:void 0);var c=yield eI(a,r,i);"replace"===o?n.elements[l]=c:n.elements.splice("number"==typeof l?l:n.elements.length,0,c)}else throw new U("invalid_op",`Unsupported edit_data_calc_io op: ${o}`);es(i),yield eb(t.parsed);var u=yield(0,z.H)(e,r.verify);return{file:t.parsed.relPath,calc:t.slug,outcome:"compile:failed"===u.status?"verify_failed":"ok",change:{field:a,op:o,key:r.key,index:r.index},verify:u,references:eh(i.references),summary:`${o} ${a} on data calc ${t.slug} -> ${u.status}`}}))}),function(e,r){return k.apply(this,arguments)}),eC=(I=S(function*(e,r){return eg(e,"remove_data_calc",r,S(function*(){var t=yield en(e,r),i=Y.dirname(t.parsed.absPath),a=Y.join(i,t.sandboxFile);yield(0,J.rm)(t.parsed.absPath,{force:!0}),yield(0,J.rm)(a,{force:!0});var n=yield ej(e,i),o=yield(0,z.H)(e,r.verify);return{file:t.parsed.relPath,calc:t.slug,outcome:"compile:failed"===o.status?"verify_failed":"ok",touchedSites:[{file:t.parsed.relPath,action:"delete_calc"},{file:(0,q.RI)(e,a),action:"delete_sandbox"},{file:n,action:"regenerate_index"}],verify:o,summary:`removed data calc ${t.slug} -> ${o.status}`}}))}),function(e,r){return I.apply(this,arguments)}),eA=M.bz().describe('Value grammar: JSON literals, bare data ref strings for output/error/IO data, { ref, subspace }, or { expr: "raw TypeScript expression" }.'),eL=M.Yj().describe("Project-relative data-calc file path, for example subspaces/subspace-0/data-calc/data-calculation-total.ts."),eR=M.KC([M.Yj(),M.ai()]).describe('Subspace locator. Defaults to subspace-0; accepts 0, "0", "subspace-0", or a project-relative subspace path.'),eN=M.Yj().describe("Data calc locator inside the subspace: alias, explicit string id, or filename slug."),eF=M.zM().describe("Override compile verification. Defaults to BRICKS_CTOR_MCP_EDIT_VERIFY, otherwise true."),eT={file:eL.optional(),subspace:eR.optional(),calc:eN.optional(),verify:eF.optional()},eJ=M.Ik({key:M.Yj().describe('Sandbox input/output key, for example "price" or "total".'),data:eA.describe("Data ref as alias/id/varName, { ref, subspace }, or { expr }."),trigger:M.zM().describe("Inputs only; defaults true.").optional()}).describe("DataCalculationScript IO item.");function eY(e,r){var t,i,a,n;e.tool("new_data_calc","Create a standard DataCalculationScript in data-calc/{calc}.ts plus its sandbox JS file, regenerate data-calc/index.ts, and wire minimal subspace indexes.",{subspace:eR.optional(),alias:M.Yj().describe("Optional alias; also drives the filename slug.").optional(),title:M.Yj().describe("Optional title.").optional(),description:M.Yj().describe("Optional description.").optional(),note:M.Yj().describe("Optional script note.").optional(),triggerMode:M.k5(["auto","manual"]).describe("Optional trigger mode; omitted by default.").optional(),enableAsync:M.zM().describe("Whether the sandbox main may be async. Defaults false.").optional(),code:M.Yj().describe("Sandbox body. The tool wraps it as export function main() { ... } unless already wrapped.").optional(),inputs:M.YO(eJ).describe("Initial script inputs. Input keys must be unique.").optional(),outputs:M.YO(eJ).describe("Initial fan-out outputs. Output keys may repeat.").optional(),output:eA.describe("Single output data ref or null.").optional(),error:eA.describe("Error output data ref or null.").optional(),id:M.Yj().describe("Optional explicit id. Defaults to source expression makeId('property_bank_calc').").optional(),verify:eF.optional()},(t=S(function*(e){return ev((yield eO(r,e)))}),function(e){return t.apply(this,arguments)})),e.tool("edit_data_calc","Edit DataCalculationScript scalar fields, output/error refs, or sandbox code. Code edits normalize inline code to sandbox file-form.",{...eT,set:M.g1(M.Yj().describe("Top-level field path such as title, description, note, alias, triggerMode, enableAsync, output, or error."),eA).describe("Fields to set. output/error accept bare data ref strings, { ref, subspace }, { expr }, or null; inputs/outputs accept whole replacement arrays of { key, data, trigger? }. Use the code parameter for code.").optional(),unset:M.YO(M.Yj()).describe("Top-level fields to remove.").optional(),code:M.Yj().describe("Replacement sandbox body. The tool wraps it as export function main() { ... } unless already wrapped.").optional()},(i=S(function*(e){return ev((yield eP(r,e)))}),function(e){return i.apply(this,arguments)})),e.tool("edit_data_calc_io","Edit DataCalculationScript inputs or outputs arrays. Inputs require unique keys; outputs may repeat keys for fan-out.",{...eT,field:M.k5(["inputs","outputs"]).describe("Which IO array to edit."),op:M.k5(["add","remove","replace","clear"]).describe("Array operation."),key:M.Yj().describe("IO key target. Ambiguous repeated output keys must use index.").optional(),index:M.ai().describe("Zero-based IO index target or add insertion index.").optional(),data:eA.describe("For add/replace: data ref as string, { ref, subspace }, or { expr }.").optional(),trigger:M.zM().describe("Inputs only; defaults true.").optional()},(a=S(function*(e){return ev((yield eD(r,e)))}),function(e){return a.apply(this,arguments)})),e.tool("remove_data_calc","Remove a standard DataCalculationScript .ts file plus its sandbox file and regenerate data-calc/index.ts. No reverse cascade is needed.",eT,(n=S(function*(e){return ev((yield eC(r,e)))}),function(e){return n.apply(this,arguments)}))}var eM={newDataCalc:eO,editDataCalc:eP,editDataCalcIo:eD,removeDataCalc:eC,resolveCalcTarget:en};i()}catch(e){i(e)}})}};
package/lib/6818.js CHANGED
@@ -1 +1 @@
1
- export const __rspack_esm_id=6818;export const __rspack_esm_ids=[6818];export const __webpack_modules__={53241(e,t,r){r.r(t),r.d(t,{detectChannel:()=>i,detectInstallMethod:()=>o});var a=r(73024),n=r(76760),s=r(48161),l=e=>{if(!e)return e;try{return a.realpathSync(e)}catch{return e}},i=({version:e,execPath:t}={})=>{var r=t||process.execPath;return r&&/[\\/]bricks-beta(?:\.exe)?$/i.test(r)||/-(beta|alpha|rc|next)\b/i.test(e||"2.25.1-beta.3")?"beta":"release"},o=({execPath:e=process.execPath,scriptPath:t=process.argv[1],homeDir:r=s.homedir(),realpath:a=l}={})=>{let i;var o=(i=e)?n.basename(i).replace(/\.exe$/i,""):"";if("bricks"===o||"bricks-beta"===o)return{method:"binary",execPath:e,installDir:n.dirname(e)};var c=a(t),p=((e,t)=>{if(!e)return null;var r=n.sep,a=`${r}node_modules${r}${t.replace(/\//g,r)}${r}`,s=e.indexOf(a);return -1===s?null:e.slice(0,s)})(c,"@fugood/bricks-cli");if(p){var b=n.sep,d=n.join(r,".bun","install","global");return p===d||p.startsWith(d+b)?{method:"bun",installRoot:p}:/[\\/](?:\.pnpm|pnpm[\\/]global)[\\/]/.test(p)?{method:"pnpm",installRoot:p}:/[\\/](?:\.yarn|yarn[\\/]global)[\\/]/.test(p)?{method:"yarn",installRoot:p}:{method:"npm",installRoot:p.endsWith(`${b}lib`)?p.slice(0,-`${b}lib`.length):p}}return{method:"unknown",execPath:e,scriptPath:c}}}};
1
+ export const __rspack_esm_id=6818;export const __rspack_esm_ids=[6818];export const __webpack_modules__={53241(e,t,r){r.r(t),r.d(t,{detectChannel:()=>i,detectInstallMethod:()=>o});var a=r(73024),n=r(76760),s=r(48161),l=e=>{if(!e)return e;try{return a.realpathSync(e)}catch{return e}},i=({version:e,execPath:t}={})=>{var r=t||process.execPath;return r&&/[\\/]bricks-beta(?:\.exe)?$/i.test(r)||/-(beta|alpha|rc|next)\b/i.test(e||"2.25.1-beta.6")?"beta":"release"},o=({execPath:e=process.execPath,scriptPath:t=process.argv[1],homeDir:r=s.homedir(),realpath:a=l}={})=>{let i;var o=(i=e)?n.basename(i).replace(/\.exe$/i,""):"";if("bricks"===o||"bricks-beta"===o)return{method:"binary",execPath:e,installDir:n.dirname(e)};var c=a(t),p=((e,t)=>{if(!e)return null;var r=n.sep,a=`${r}node_modules${r}${t.replace(/\//g,r)}${r}`,s=e.indexOf(a);return -1===s?null:e.slice(0,s)})(c,"@fugood/bricks-cli");if(p){var b=n.sep,d=n.join(r,".bun","install","global");return p===d||p.startsWith(d+b)?{method:"bun",installRoot:p}:/[\\/](?:\.pnpm|pnpm[\\/]global)[\\/]/.test(p)?{method:"pnpm",installRoot:p}:/[\\/](?:\.yarn|yarn[\\/]global)[\\/]/.test(p)?{method:"yarn",installRoot:p}:{method:"npm",installRoot:p.endsWith(`${b}lib`)?p.slice(0,-`${b}lib`.length):p}}return{method:"unknown",execPath:e,scriptPath:c}}}};
package/lib/7233.js CHANGED
@@ -2472,7 +2472,7 @@ ${((e,i)=>{switch(e){case"defined_properties":return Object.entries(i).map(([e,i
2472
2472
  timestamp
2473
2473
  }
2474
2474
  }
2475
- `,tX=J(function e(i,t){var n;X(this,e),this.baseUrl=i,this.auth="string"==typeof t?{token:t,getHeaders:(n=v(function*(){return{authorization:`Bearer ${t}`}}),function(){return n.apply(this,arguments)})}:t,this.token=this.auth?.token,this.graphqlUrl=`${i}/api/graphql`},[{key:"authHeaders",value:(o=v(function*(){var e=yield this.auth.getHeaders();return{Authorization:e.authorization,...tL(e,tH)}}),function(){return o.apply(this,arguments)})},{key:"graphql",value:(r=v(function*(e,i){var t=yield(0,B.Ay)(this.graphqlUrl,{method:"POST",headers:{"Content-Type":"application/json",...yield this.authHeaders(),Accept:"application/json"},body:JSON.stringify({query:e,variables:i})});if(!t.ok){var n=yield t.text().catch(()=>"");throw Error(`Activity-log query failed (${t.status}): ${n}`)}var a=yield t.json();if(a.errors?.length)throw Error(a.errors.map(e=>e.message).join("\n"));return a.data}),function(e,i){return r.apply(this,arguments)})},{key:"events",value:(s=v(function*(e,{limit:i,offset:t}={}){var n={...e};return null!=i&&(n.limit=i),null!=t&&(n.offset=t),(yield this.graphql(tz,{filter:n})).events}),function(e){return s.apply(this,arguments)})},{key:"screenshots",value:(d=v(function*(e){return(yield this.graphql(tJ,{filter:e})).screenshots}),function(e){return d.apply(this,arguments)})},{key:"downloadScreenshot",value:(c=v(function*(e,i,t){var n=`${this.baseUrl}/api/v1/${encodeURIComponent(e)}/${encodeURIComponent(i)}/screenshot?ts=${encodeURIComponent(t)}`,a=yield(0,B.Ay)(n,{headers:yield this.authHeaders()});if(!a.ok){var o=yield a.text().catch(()=>"");throw Error(`Screenshot fetch failed (${a.status}): ${o}`)}return Buffer.from((yield a.arrayBuffer()))}),function(e,i,t){return c.apply(this,arguments)})}]);function tQ(e,i,t){switch(t){case"user":return new iU(e,i);case"workspace":return new i7(e,i);default:throw Error(`Invalid token type: ${t}.`)}}process.env.STAGE,process.env.URL_BASE;var tZ="bricks-mcp",t0={bricks:process.env.BRICKS_API_SERVER||"https://display-beta.bricks.tools",media:process.env.MEDIA_API_SERVER||"https://media-beta.bricks.tools",activityLog:process.env.ACTIVITY_LOG_API_SERVER||"https://activity-log-beta.bricks.tools"};process.env.AUTH0_DOMAIN,process.env.CACHE_URL;var t1=t(1639);let t4=({type:e,title:i,template_key:t})=>{var n,a,o=(0,t1.M4)(e);switch(e){case"subspace":n={title:i,layout:{width:"number",height:"number"},root_canvas_id:"CANVAS_<UUID>",canvas_map:{},brick_map:{},animation_map:{},generator_map:{},property_bank_map:{},property_bank_calc_map:{}},a={"canvas_map.CANVAS_<UUID>.item_list":[{type:"subspace",subspace_id:"SUBSPACE_<UUID>",$note:"If not a root subspace, it can be linked to canvas in other subspace"}]};break;case"canvas":var r=Y(V.Ji);n={title:i,item_list:[],property:{$definitions:Object.fromEntries(Object.entries(r.propTypes).map(([e,i])=>[e,{...i,description:r.brickPropDescriptions[e]}]))},event_map:{$definitions:Object.fromEntries(Object.entries(r.eventTypes).map(([e])=>[e,{description:r.brickEventDescriptions[e]}]))}},a={property_bank_map:{[(0,t1.M4)("property_bank")]:{title:`Canvas ID: ${i}`,type:"string",value:o,routing:"read-only",kind:"auto-generated-item-id",idType:"canvas"}}};break;case"brick":var s=Y(V.dK.Basic),d=Y(V.brickMapping[t]);if(!d)throw Error(`Brick ${t} not found`);var c={...d,propTypes:{...s.propTypes,...d.propTypes},brickPropDescriptions:{...s.brickPropDescriptions,...d.brickPropDescriptions},eventTypes:{...s.eventTypes,...d.eventTypes},brickEventDescriptions:{...s.brickEventDescriptions,...d.brickEventDescriptions}};n={title:i,template_key:t,property:{$definitions:Object.fromEntries(Object.entries(c.propTypes).map(([e,i])=>[e,{...i,description:c.brickPropDescriptions[e]}]))},event_map:{$definitions:Object.fromEntries(Object.entries(c.eventTypes).map(([e])=>[e,{description:c.brickEventDescriptions[e]}]))},outlet:{$definitions:Object.fromEntries(Object.entries(c.outletTypes??{}).map(([e])=>[e,{description:(c.brickOutletDescriptions??{})[e]}]))},state_group:{"BRICK_STATE_GROUP_<UUID>":{}}},a={canvas_map:{"CANVAS_<UUID WHICH NEED DISPLAY THIS BRICK>":{item_list:[{type:"brick",brick_id:o,frame:{x:"number",y:"number",width:"number",height:"number",standby_mode:"custom|top|left|right|bottom",standby_delay:"number",standby_easing:{default:{method:"ease",duration:"number"}}}}]}}};break;case"state_group":n={title:i,description:"State Group Description",conds:[{type:"property_bank|inner_state",key:"PROPERTY_BANK#<Data Node ID>|[current_canvas|BRICK_<OUTLET NAME>]|",method:"==|!=|>|>=|<|<=",value:"value_to_compare"}],override:{property:!1,event:!1,outlet:!1},commented:!1,break:!1,property:{},outlet:{},animation:{}};break;case"generator":var l=Y(V.generatorMapping[t]);if(!l)throw Error(`Generator ${t} not found`);n={title:i,template_key:t,property:{$definitions:Object.fromEntries(Object.entries(l.propTypes).map(([e,i])=>[e,{...i,description:l.brickPropDescriptions[e]}]))},event_map:{$definitions:Object.fromEntries(Object.entries(l.eventTypes).map(([e])=>[e,{description:l.brickEventDescriptions[e]}]))},outlet:{$definitions:Object.fromEntries(Object.entries(l.outletTypes).map(([e])=>[e,{description:l.brickOutletDescriptions[e]}]))}};break;case"animation":n={title:i,type:"timing|decay|spring",property:"opacity|transform.translateX|transform.scale|etc",config:{$note:"Config for the animation"},compose_type:"parallel|sequence",item_list:[{animation_id:"ANIMATION_<SUB ANIMATION UUID>"}]};break;case"property_bank":n={title:i,description:"Property Bank Description",linkedFrom:"SUBSPACE_<UUID WHICH IS CROSS SUBSPACE>",type:"string|number|bool|object|array|any",kind:"color|datetime|id|media-resource-*|lottie-file-uri",unit:"grid|px|ms",routing:"read-only|default",value:"fit-to-type",event_map:{$note:`Available events: ${Object.keys(V.qJ.eventTypes).join(", ")}`},local_sync:{update_mode:"all|main-only|minor-only|dont-sync"},$remote_update_additional:{$note:"Configure remote update behavior",enable_remote_update:!0,bank_type:"create|create-device-specific"}};break;case"property_bank_command":break;case"property_bank_calc":var p=(0,t1.M4)("property_bank_command"),u=(0,t1.M4)("property_bank_command"),m=(0,t1.M4)("property_bank_command"),_="const { arg_name } = inputs;\n\nreturn { arg_name };";n={title:i,map:{$note:"Required, actual implementation","PROPERTY_BANK_DATA_NODE_<UUID>":{type:"data-node",properties:{},in:{change:null},out:{value:[{id:"PROPERTY_BANK_COMMAND_NODE_<UUID>",port:"value"}]},$note:"Use this to input data to the sandbox"},"PROPERTY_BANK_COMMAND_NODE_<UUID FIRST>":{type:"command-node-object",title:"Command: OBJECT_SET",properties:{command:"OBJECT_SET",args:{path:"arg_name"}},in:{obj:null,path:null,value:[{id:"PROPERTY_BANK_DATA_NODE_<UUID>",port:"value"}]},out:{result:[{id:`PROPERTY_BANK_COMMAND_NODE_<UUID NEXT> | ${p}`,port:"obj | inputs"}]}},"PROPERTY_BANK_COMMAND_NODE_<UUID SECOND>":{type:"command-node-object",title:"Command: OBJECT_SET",properties:{command:"OBJECT_SET",args:{path:"arg_name"}},in:{obj:[{id:"PROPERTY_BANK_COMMAND_NODE_<UUID PREVIOUS>",port:"result"}],path:null,value:[{id:"PROPERTY_BANK_DATA_NODE_<UUID SECOND>",port:"value"}]},out:{result:[{id:`PROPERTY_BANK_COMMAND_NODE_<UUID NEXT> | ${p}`,port:"obj | inputs"}]}},[p]:{type:"command-node-sandbox",title:"Command: SANDBOX_RUN_JAVASCRIPT",properties:{command:"SANDBOX_RUN_JAVASCRIPT",args:{code:_,enable_async:!1}},in:{code:null,inputs:[{id:"PROPERTY_BANK_COMMAND_NODE_<UUID FINAL>",port:"result"}]},out:{result:[{id:m,port:"result"},{id:u,port:"result"}]}},[m]:{type:"command-node-sandbox",title:"Command: SANDBOX_GET_ERROR",properties:{command:"SANDBOX_GET_ERROR"},in:{result:[{id:p,port:"result"}]},out:{result:[{id:"PROPERTY_BANK_DATA_NODE_<UUID RECEIVE ERROR>",port:"change"}],$note:"Set `result` as null if there is no error"}},[u]:{type:"command-node-sandbox",title:"Command: SANDBOX_GET_RETURN_VALUE",properties:{command:"SANDBOX_GET_RETURN_VALUE"},in:{result:[{id:p,port:"result"}]},out:{result:[{id:"PROPERTY_BANK_DATA_NODE_<UUID RECEIVE RESULT> | PROPERTY_BANK_COMMAND_NODE_<UUID PARSE RESULT> | null",port:"change"}]}},"PROPERTY_BANK_DATA_NODE_<UUID RECEIVE RESULT>":{type:"data-node",properties:{},in:{change:[{id:u,port:"result"}]},out:{value:null},$note:"Put full result into data node"},"PROPERTY_BANK_COMMAND_NODE_<UUID PARSE RESULT>":{type:"command-node-object",title:"Command: OBJECT_GET",properties:{command:"OBJECT_GET",args:{path:"obj_key"}},in:{obj:[{id:u,port:"obj"}]},out:{result:[{id:"PROPERTY_BANK_DATA_NODE_<UUID RECEIVE PARTIAL RESULT>",port:"change"}]},$note:"Parse result object into data node"},"PROPERTY_BANK_DATA_NODE_<UUID RECEIVE PARTIAL RESULT>":{type:"data-node",properties:{},in:{change:[{id:"PROPERTY_BANK_COMMAND_NODE_<UUID PARSE RESULT>",port:"result"}]},out:{value:null},$note:"Put partial result into data node"}},editor_info:{},type:"script",script_config:{title:i,enable_async:!1,inputs:{"PROPERTY_BANK_DATA_NODE_<UUID>":"arg_name"},disabled_triggers:{},error:"PROPERTY_BANK_DATA_NODE_<UUID RECEIVE ERROR> | null",output:"PROPERTY_BANK_DATA_NODE_<UUID RECEIVE RESULT> | null",outputs:{obj_key:"PROPERTY_BANK_DATA_NODE_<UUID RECEIVE PARTIAL RESULT>"},code:_,$note:"Required, info for GUI editor"}}}return T({id:o,example:n,extraInfo:a})};var t6="2.25.1-beta.3";function t2(){return t5.apply(this,arguments)}function t5(){return(t5=v(function*(e={}){var i,t,n=e.baseUrl||t0.bricks,a=e.activityLogBaseUrl||t0.activityLog,o=!e.token&&!!e.getAuthHeaders,r=e.token||!e.getAuthHeaders&&process.env.BRICKS_API_TOKEN,s=null;if(!r&&e.getAuthHeaders){var d=yield e.getAuthHeaders();r=d.authorization?.replace(/^Bearer /,""),s=d["x-bricks-workspace-id"]||null}if(!r)throw console.error("Error: API token is required"),console.error(o?"OAuth sign-in did not produce credentials. Run `bricks auth login` again.":"Please provide a token via options or set BRICKS_API_TOKEN environment variable"),Error("API token is required");var c=function(e){try{var i=e.queryStringParameters?.token;if(!i){var t=new Headers(e.headers);i=t.get("authorization")?.replace("Bearer ","")}if(!i)return{success:!1,message:"Authentication failed: No token provided"};var n=function(e){try{var i=e.split(".");if(i.length<3)return null;var t=JSON.parse(Buffer.from(i[0],"base64url").toString());if(!D.includes(t?.alg))return null;return JSON.parse(Buffer.from(i[1],"base64url").toString())}catch{return null}}(i);if(!n)return{success:!1,message:"Authentication failed: Invalid token"};var a=A.includes(n.iss)?"user":"workspace";if("workspace"===a){var o=Array.isArray(n.t)?n.t:[];n.permissions=o.reduce((e,i)=>{var t=k[i];return t&&e.push(t),e},[])}else n.permissions=Object.keys(I);return{success:!0,token:i,tokenInfo:n,tokenType:a}}catch(e){return{success:!1,message:`Authentication failed: ${e.message}`}}}({queryStringParameters:{token:r}});if(!c.success){var l=o?"Invalid OAuth session credentials — run `bricks auth login` again":"Invalid BRICKS_API_TOKEN";throw console.error(`Error: ${l}`),console.error(c.message),Error(l)}var p=new h._({name:tZ,version:t6});if(e.getAuthHeaders&&s){var u={token:r,getHeaders:e.getAuthHeaders};t={...c,tokenType:"workspace",tokenInfo:{...c.tokenInfo,w_id:s,permissions:Object.keys(I)},auth:u,client:tQ(n,u,"workspace")}}else t={...c,client:tQ(n,c.token,c.tokenType)};p.prompt("getting-started","Getting started with BRICKS",{},v(function*(){return{messages:[{role:"user",content:{type:"text",text:`Welcome to BRICKS — start here.
2475
+ `,tX=J(function e(i,t){var n;X(this,e),this.baseUrl=i,this.auth="string"==typeof t?{token:t,getHeaders:(n=v(function*(){return{authorization:`Bearer ${t}`}}),function(){return n.apply(this,arguments)})}:t,this.token=this.auth?.token,this.graphqlUrl=`${i}/api/graphql`},[{key:"authHeaders",value:(o=v(function*(){var e=yield this.auth.getHeaders();return{Authorization:e.authorization,...tL(e,tH)}}),function(){return o.apply(this,arguments)})},{key:"graphql",value:(r=v(function*(e,i){var t=yield(0,B.Ay)(this.graphqlUrl,{method:"POST",headers:{"Content-Type":"application/json",...yield this.authHeaders(),Accept:"application/json"},body:JSON.stringify({query:e,variables:i})});if(!t.ok){var n=yield t.text().catch(()=>"");throw Error(`Activity-log query failed (${t.status}): ${n}`)}var a=yield t.json();if(a.errors?.length)throw Error(a.errors.map(e=>e.message).join("\n"));return a.data}),function(e,i){return r.apply(this,arguments)})},{key:"events",value:(s=v(function*(e,{limit:i,offset:t}={}){var n={...e};return null!=i&&(n.limit=i),null!=t&&(n.offset=t),(yield this.graphql(tz,{filter:n})).events}),function(e){return s.apply(this,arguments)})},{key:"screenshots",value:(d=v(function*(e){return(yield this.graphql(tJ,{filter:e})).screenshots}),function(e){return d.apply(this,arguments)})},{key:"downloadScreenshot",value:(c=v(function*(e,i,t){var n=`${this.baseUrl}/api/v1/${encodeURIComponent(e)}/${encodeURIComponent(i)}/screenshot?ts=${encodeURIComponent(t)}`,a=yield(0,B.Ay)(n,{headers:yield this.authHeaders()});if(!a.ok){var o=yield a.text().catch(()=>"");throw Error(`Screenshot fetch failed (${a.status}): ${o}`)}return Buffer.from((yield a.arrayBuffer()))}),function(e,i,t){return c.apply(this,arguments)})}]);function tQ(e,i,t){switch(t){case"user":return new iU(e,i);case"workspace":return new i7(e,i);default:throw Error(`Invalid token type: ${t}.`)}}process.env.STAGE,process.env.URL_BASE;var tZ="bricks-mcp",t0={bricks:process.env.BRICKS_API_SERVER||"https://display-beta.bricks.tools",media:process.env.MEDIA_API_SERVER||"https://media-beta.bricks.tools",activityLog:process.env.ACTIVITY_LOG_API_SERVER||"https://activity-log-beta.bricks.tools"};process.env.AUTH0_DOMAIN,process.env.CACHE_URL;var t1=t(1639);let t4=({type:e,title:i,template_key:t})=>{var n,a,o=(0,t1.M4)(e);switch(e){case"subspace":n={title:i,layout:{width:"number",height:"number"},root_canvas_id:"CANVAS_<UUID>",canvas_map:{},brick_map:{},animation_map:{},generator_map:{},property_bank_map:{},property_bank_calc_map:{}},a={"canvas_map.CANVAS_<UUID>.item_list":[{type:"subspace",subspace_id:"SUBSPACE_<UUID>",$note:"If not a root subspace, it can be linked to canvas in other subspace"}]};break;case"canvas":var r=Y(V.Ji);n={title:i,item_list:[],property:{$definitions:Object.fromEntries(Object.entries(r.propTypes).map(([e,i])=>[e,{...i,description:r.brickPropDescriptions[e]}]))},event_map:{$definitions:Object.fromEntries(Object.entries(r.eventTypes).map(([e])=>[e,{description:r.brickEventDescriptions[e]}]))}},a={property_bank_map:{[(0,t1.M4)("property_bank")]:{title:`Canvas ID: ${i}`,type:"string",value:o,routing:"read-only",kind:"auto-generated-item-id",idType:"canvas"}}};break;case"brick":var s=Y(V.dK.Basic),d=Y(V.brickMapping[t]);if(!d)throw Error(`Brick ${t} not found`);var c={...d,propTypes:{...s.propTypes,...d.propTypes},brickPropDescriptions:{...s.brickPropDescriptions,...d.brickPropDescriptions},eventTypes:{...s.eventTypes,...d.eventTypes},brickEventDescriptions:{...s.brickEventDescriptions,...d.brickEventDescriptions}};n={title:i,template_key:t,property:{$definitions:Object.fromEntries(Object.entries(c.propTypes).map(([e,i])=>[e,{...i,description:c.brickPropDescriptions[e]}]))},event_map:{$definitions:Object.fromEntries(Object.entries(c.eventTypes).map(([e])=>[e,{description:c.brickEventDescriptions[e]}]))},outlet:{$definitions:Object.fromEntries(Object.entries(c.outletTypes??{}).map(([e])=>[e,{description:(c.brickOutletDescriptions??{})[e]}]))},state_group:{"BRICK_STATE_GROUP_<UUID>":{}}},a={canvas_map:{"CANVAS_<UUID WHICH NEED DISPLAY THIS BRICK>":{item_list:[{type:"brick",brick_id:o,frame:{x:"number",y:"number",width:"number",height:"number",standby_mode:"custom|top|left|right|bottom",standby_delay:"number",standby_easing:{default:{method:"ease",duration:"number"}}}}]}}};break;case"state_group":n={title:i,description:"State Group Description",conds:[{type:"property_bank|inner_state",key:"PROPERTY_BANK#<Data Node ID>|[current_canvas|BRICK_<OUTLET NAME>]|",method:"==|!=|>|>=|<|<=",value:"value_to_compare"}],override:{property:!1,event:!1,outlet:!1},commented:!1,break:!1,property:{},outlet:{},animation:{}};break;case"generator":var l=Y(V.generatorMapping[t]);if(!l)throw Error(`Generator ${t} not found`);n={title:i,template_key:t,property:{$definitions:Object.fromEntries(Object.entries(l.propTypes).map(([e,i])=>[e,{...i,description:l.brickPropDescriptions[e]}]))},event_map:{$definitions:Object.fromEntries(Object.entries(l.eventTypes).map(([e])=>[e,{description:l.brickEventDescriptions[e]}]))},outlet:{$definitions:Object.fromEntries(Object.entries(l.outletTypes).map(([e])=>[e,{description:l.brickOutletDescriptions[e]}]))}};break;case"animation":n={title:i,type:"timing|decay|spring",property:"opacity|transform.translateX|transform.scale|etc",config:{$note:"Config for the animation"},compose_type:"parallel|sequence",item_list:[{animation_id:"ANIMATION_<SUB ANIMATION UUID>"}]};break;case"property_bank":n={title:i,description:"Property Bank Description",linkedFrom:"SUBSPACE_<UUID WHICH IS CROSS SUBSPACE>",type:"string|number|bool|object|array|any",kind:"color|datetime|id|media-resource-*|lottie-file-uri",unit:"grid|px|ms",routing:"read-only|default",value:"fit-to-type",event_map:{$note:`Available events: ${Object.keys(V.qJ.eventTypes).join(", ")}`},local_sync:{update_mode:"all|main-only|minor-only|dont-sync"},$remote_update_additional:{$note:"Configure remote update behavior",enable_remote_update:!0,bank_type:"create|create-device-specific"}};break;case"property_bank_command":break;case"property_bank_calc":var p=(0,t1.M4)("property_bank_command"),u=(0,t1.M4)("property_bank_command"),m=(0,t1.M4)("property_bank_command"),_="const { arg_name } = inputs;\n\nreturn { arg_name };";n={title:i,map:{$note:"Required, actual implementation","PROPERTY_BANK_DATA_NODE_<UUID>":{type:"data-node",properties:{},in:{change:null},out:{value:[{id:"PROPERTY_BANK_COMMAND_NODE_<UUID>",port:"value"}]},$note:"Use this to input data to the sandbox"},"PROPERTY_BANK_COMMAND_NODE_<UUID FIRST>":{type:"command-node-object",title:"Command: OBJECT_SET",properties:{command:"OBJECT_SET",args:{path:"arg_name"}},in:{obj:null,path:null,value:[{id:"PROPERTY_BANK_DATA_NODE_<UUID>",port:"value"}]},out:{result:[{id:`PROPERTY_BANK_COMMAND_NODE_<UUID NEXT> | ${p}`,port:"obj | inputs"}]}},"PROPERTY_BANK_COMMAND_NODE_<UUID SECOND>":{type:"command-node-object",title:"Command: OBJECT_SET",properties:{command:"OBJECT_SET",args:{path:"arg_name"}},in:{obj:[{id:"PROPERTY_BANK_COMMAND_NODE_<UUID PREVIOUS>",port:"result"}],path:null,value:[{id:"PROPERTY_BANK_DATA_NODE_<UUID SECOND>",port:"value"}]},out:{result:[{id:`PROPERTY_BANK_COMMAND_NODE_<UUID NEXT> | ${p}`,port:"obj | inputs"}]}},[p]:{type:"command-node-sandbox",title:"Command: SANDBOX_RUN_JAVASCRIPT",properties:{command:"SANDBOX_RUN_JAVASCRIPT",args:{code:_,enable_async:!1}},in:{code:null,inputs:[{id:"PROPERTY_BANK_COMMAND_NODE_<UUID FINAL>",port:"result"}]},out:{result:[{id:m,port:"result"},{id:u,port:"result"}]}},[m]:{type:"command-node-sandbox",title:"Command: SANDBOX_GET_ERROR",properties:{command:"SANDBOX_GET_ERROR"},in:{result:[{id:p,port:"result"}]},out:{result:[{id:"PROPERTY_BANK_DATA_NODE_<UUID RECEIVE ERROR>",port:"change"}],$note:"Set `result` as null if there is no error"}},[u]:{type:"command-node-sandbox",title:"Command: SANDBOX_GET_RETURN_VALUE",properties:{command:"SANDBOX_GET_RETURN_VALUE"},in:{result:[{id:p,port:"result"}]},out:{result:[{id:"PROPERTY_BANK_DATA_NODE_<UUID RECEIVE RESULT> | PROPERTY_BANK_COMMAND_NODE_<UUID PARSE RESULT> | null",port:"change"}]}},"PROPERTY_BANK_DATA_NODE_<UUID RECEIVE RESULT>":{type:"data-node",properties:{},in:{change:[{id:u,port:"result"}]},out:{value:null},$note:"Put full result into data node"},"PROPERTY_BANK_COMMAND_NODE_<UUID PARSE RESULT>":{type:"command-node-object",title:"Command: OBJECT_GET",properties:{command:"OBJECT_GET",args:{path:"obj_key"}},in:{obj:[{id:u,port:"obj"}]},out:{result:[{id:"PROPERTY_BANK_DATA_NODE_<UUID RECEIVE PARTIAL RESULT>",port:"change"}]},$note:"Parse result object into data node"},"PROPERTY_BANK_DATA_NODE_<UUID RECEIVE PARTIAL RESULT>":{type:"data-node",properties:{},in:{change:[{id:"PROPERTY_BANK_COMMAND_NODE_<UUID PARSE RESULT>",port:"result"}]},out:{value:null},$note:"Put partial result into data node"}},editor_info:{},type:"script",script_config:{title:i,enable_async:!1,inputs:{"PROPERTY_BANK_DATA_NODE_<UUID>":"arg_name"},disabled_triggers:{},error:"PROPERTY_BANK_DATA_NODE_<UUID RECEIVE ERROR> | null",output:"PROPERTY_BANK_DATA_NODE_<UUID RECEIVE RESULT> | null",outputs:{obj_key:"PROPERTY_BANK_DATA_NODE_<UUID RECEIVE PARTIAL RESULT>"},code:_,$note:"Required, info for GUI editor"}}}return T({id:o,example:n,extraInfo:a})};var t6="2.25.1-beta.6";function t2(){return t5.apply(this,arguments)}function t5(){return(t5=v(function*(e={}){var i,t,n=e.baseUrl||t0.bricks,a=e.activityLogBaseUrl||t0.activityLog,o=!e.token&&!!e.getAuthHeaders,r=e.token||!e.getAuthHeaders&&process.env.BRICKS_API_TOKEN,s=null;if(!r&&e.getAuthHeaders){var d=yield e.getAuthHeaders();r=d.authorization?.replace(/^Bearer /,""),s=d["x-bricks-workspace-id"]||null}if(!r)throw console.error("Error: API token is required"),console.error(o?"OAuth sign-in did not produce credentials. Run `bricks auth login` again.":"Please provide a token via options or set BRICKS_API_TOKEN environment variable"),Error("API token is required");var c=function(e){try{var i=e.queryStringParameters?.token;if(!i){var t=new Headers(e.headers);i=t.get("authorization")?.replace("Bearer ","")}if(!i)return{success:!1,message:"Authentication failed: No token provided"};var n=function(e){try{var i=e.split(".");if(i.length<3)return null;var t=JSON.parse(Buffer.from(i[0],"base64url").toString());if(!D.includes(t?.alg))return null;return JSON.parse(Buffer.from(i[1],"base64url").toString())}catch{return null}}(i);if(!n)return{success:!1,message:"Authentication failed: Invalid token"};var a=A.includes(n.iss)?"user":"workspace";if("workspace"===a){var o=Array.isArray(n.t)?n.t:[];n.permissions=o.reduce((e,i)=>{var t=k[i];return t&&e.push(t),e},[])}else n.permissions=Object.keys(I);return{success:!0,token:i,tokenInfo:n,tokenType:a}}catch(e){return{success:!1,message:`Authentication failed: ${e.message}`}}}({queryStringParameters:{token:r}});if(!c.success){var l=o?"Invalid OAuth session credentials — run `bricks auth login` again":"Invalid BRICKS_API_TOKEN";throw console.error(`Error: ${l}`),console.error(c.message),Error(l)}var p=new h._({name:tZ,version:t6});if(e.getAuthHeaders&&s){var u={token:r,getHeaders:e.getAuthHeaders};t={...c,tokenType:"workspace",tokenInfo:{...c.tokenInfo,w_id:s,permissions:Object.keys(I)},auth:u,client:tQ(n,u,"workspace")}}else t={...c,client:tQ(n,c.token,c.tokenType)};p.prompt("getting-started","Getting started with BRICKS",{},v(function*(){return{messages:[{role:"user",content:{type:"text",text:`Welcome to BRICKS — start here.
2476
2476
 
2477
2477
  Before doing any complex work (application design, deployments, etc.),
2478
2478
  always consult the official docs rather than guessing.