@fugood/bricks-cli 2.26.0-beta.1 → 2.26.0-beta.2

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/3976.js CHANGED
@@ -2,13 +2,13 @@ export const __rspack_esm_id=3976;export const __rspack_esm_ids=[3976];export co
2
2
  # MCP entry-editing audit log
3
3
  ${l}
4
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:()=>w,Hn:()=>u,JJ:()=>g,Kx:()=>I,LJ:()=>y,Pb:()=>k,R0:()=>x,RI:()=>p,Zj:()=>_,bf:()=>h,jc:()=>j,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},_=e=>e.program.body.flatMap(e=>{if(!s.isExportNamedDeclaration(e)||!s.isVariableDeclaration(e.declaration))return[];var r=e.declaration;return r.declarations.flatMap(t=>{if(!s.isIdentifier(t.id))return[];var i,a=t.id.typeAnnotation;s.isTSTypeAnnotation(a)&&s.isTSTypeReference(a.typeAnnotation)&&s.isIdentifier(a.typeAnnotation.typeName)&&(i=a.typeAnnotation.typeName.name);var n=s.isObjectExpression(t.init)?t.init:void 0;return[{name:t.id.name,node:e,declaration:r,declarator:t,object:n,id:n?g(n,"id"):void 0,alias:n?g(n,"alias"):void 0,typeName:i}]})}),x=(e,r)=>{var t=new Set;for(var i of e.program.body){if(s.isImportDeclaration(i)){i.specifiers.forEach(e=>t.add(e.local.name));continue}s.isExportNamedDeclaration(i)&&s.isVariableDeclaration(i.declaration)&&i.declaration.declarations.forEach(e=>{s.isIdentifier(e.id)&&t.add(e.id.name)})}if(!t.has(r))return r;for(var a=1;t.has(`${r}${a}`);)a+=1;return`${r}${a}`},w=(e,r,t)=>{var i=h(e,r);if(i){i.value=t;return}e.properties.push(s.objectProperty(v(r),t))},j=(e,r)=>{var t=e.properties.findIndex(e=>!!s.isObjectProperty(e)&&b(e.key)===r);t>=0&&e.properties.splice(t,1)},k=(e,r)=>{var t=e.program.body,i=t.findLastIndex(e=>s.isImportDeclaration(e));t.splice(i+1,0,r)},I=(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"),k(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"1"!==process.env.BRICKS_CTOR_MCP_DISABLE_COMPILE&&(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__:()=>eY,register:()=>eJ});var a,n,o,s,l,c,u,d,p,f,y,m,b,v,h,g,_,x,w,j,k,I,S=t(68832),$=t(99436),E=t(44668),O=t(5018),P=t(63315),C=t(30409),D=t(40906),A=t(59410),R=t(2235),L=t(46773),N=t(58135),T=t(11978),F=t(79491),J=t(51455),Y=t(76760),M=t(84867),z=t(54452),q=t(98009),B=t(3540),H=e([F]);function K(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(K=function(){return!!e})()}F=(H.then?(await H)():H)[0];var W=R.default||R,Z=function(e){function r(e,t,i,a=!1){var n,o,s;return O(this,r),o=r,s=[t],o=C(o),(n=P(this,K()?Reflect.construct(o,s||[],C(this).constructor):o.apply(this,s))).name="DataCalcEditingError",n.code=e,n.details=i,n.isMcpError=a,n}return D(r,e),E(r)}(A(Error)),U=(e,r)=>{if(Y.isAbsolute(r))throw new Z("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 Z("invalid_file","File must stay inside the project directory",{file:r});return t},V=(e,r)=>{try{return(0,L.parse)(e,{sourceType:"module",plugins:["typescript","topLevelAwait"],errorRecovery:!1})}catch(e){throw new Z("parse_failed",`Cannot parse ${r} as TypeScript: ${e.message}. Edit this file directly.`,{file:r},!0)}},G=(a=$(function*(e,r){var t=yield(0,q.LJ)(e,r);if(!t)throw new Z("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:V(i,a),projectDir:e,absPath:r,ioPath:t,relPath:a}}),function(e,r){return a.apply(this,arguments)}),Q=(n=$(function*(e,r){var t=yield(0,q.z5)(e,r);if(!t)throw new Z("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,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 U(e,t);throw new Z("unsupported_subspace",`Unsupported subspace locator: ${t}`,{subspace:t})},ee=e=>{var r=Y.basename(e),t=/^data-calculation-(.+)\.ts$/.exec(r);if(!t)throw new Z("invalid_file","Expected data-calculation-{slug}.ts file",{file:e});return t[1]},er=(o=$(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)}),et=e=>{var r=(0,q.bf)(e,"code")?.value;return r&&N.isExpression(r)?r:null},ei=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},ea=(s=$(function*(e,r){if(r.file)a=U(e,r.file);else{var t,i,a,n=X(e,r.subspace),o=Y.join(n,"data-calc"),s=yield er(o),l=r.calc;if(!l)throw new Z("missing_calc","Provide file or subspace+calc");for(var c of s){if(l===ee(c)){a=c;break}try{var u=yield G(e,c),d=(0,q.Zj)(u.ast).find(e=>"dataCalculation"===e.name);if(d&&(l===d.alias||l===d.id)){a=c;break}}catch{continue}}}if(!a)throw new Z("calc_not_found",`Data calc not found: ${r.calc}`,{calc:r.calc,subspace:r.subspace??"subspace-0"});var p=yield G(e,a),f=(e=>{var r=(0,q.Zj)(e.ast).find(e=>"dataCalculation"===e.name);if(!r||!r.object)throw new Z("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 Z("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=ee(a),m=(t=et(f),(i=ei(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)}),en=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")))},eo=e=>{(0,q.Kx)(e.parsed.ast,"type",e.typeImports),(0,q.Kx)(e.parsed.ast,"value",e.valueImports)},es=(l=$(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 Z("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:X(e,i),s=Y.join(o,"data.ts"),l=yield G(e,s),c=(0,q.Zj)(l.ast).filter(e=>e.name===t||e.id===t||e.alias===t);if(0===c.length)throw new Z("reference_not_found",`Data reference not found: ${t}`,{ref:t,subspace:Y.basename(o)});if(c.length>1)throw new Z("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)}),el=(c=$(function*(e,r){if((0,q.u4)(e)&&"string"==typeof e.expr)return(0,L.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 Z("invalid_ref","Data getter requires a data ref string");var i=yield es(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=(0,q.R0)(e.ast,t),o=N.importDeclaration([N.importNamespaceSpecifier(N.identifier(n))],N.stringLiteral(r));return(0,q.Pb)(e.ast,o),n})(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)}),ec=(u=$(function*(e,r){return null==e?N.nullLiteral():el(e,r)}),function(e,r){return u.apply(this,arguments)}),eu=(d=$(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 er(Y.join(t,i.name,"data-calc")))try{var n=yield G(e,a),o=(0,q.Zj)(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)}),ed=new Set(["__typename","id","code","enableAsync","inputs","output","outputs","error"]),ep=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")])),ef=(p=$(function*(e,r){if((0,q.u4)(e)){if("string"==typeof e.expr)return(0,L.parseExpression)(e.expr,{plugins:["typescript"]});if("string"==typeof e.ref)return el(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=>ef(e,r)))));if((0,q.u4)(e)){var t,i=yield Promise.all(Object.entries(e).map((t=$(function*([e,t]){return N.objectProperty((0,q.zu)(e),(yield ef(t,r)))}),function(e){return t.apply(this,arguments)})));return N.objectExpression(i)}throw new Z("invalid_value",`Unsupported value: ${String(e)}`)}),function(e,r){return p.apply(this,arguments)}),ey=(f=$(function*(e){var r=W(e.ast,{comments:!0},e.source).code,t=yield(0,F.format)(e.absPath,r,q.Hn);if(t.errors.length>0)throw new Z("format_failed",`oxfmt failed for ${e.relPath}`,{file:e.relPath,errors:t.errors});return t.code}),function(e){return f.apply(this,arguments)}),em=(y=$(function*(e){var r=yield ey(e);return V(r,e.relPath),yield(0,J.writeFile)(e.ioPath??(yield Q(e.projectDir,e.absPath)),r),r}),function(e){return y.apply(this,arguments)}),eb=e=>({content:[{type:"text",text:JSON.stringify(e,null,2)}],isError:e.isError||void 0}),ev=e=>e.map(e=>({input:e.input,id:e.id,alias:e.alias,entry:e.varName})),eh=(m=$(function*(e,r,t,i){var a=new Date().toISOString(),n=(0,B.S)();try{var o=yield i();return yield(0,B.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 Z,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,B.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)}),eg=(b=$(function*(e,r){var t=new Set((yield er(e)).map(ee));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,T.qg)(e,{sourceType:"module",ecmaVersion:2020}),!0}catch{return!1}},ex=e=>{var r=e??"";if((e=>{try{var r=(0,T.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}
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:()=>w,Hn:()=>u,JJ:()=>g,Kx:()=>I,LJ:()=>y,Pb:()=>k,R0:()=>x,RI:()=>p,Zj:()=>_,bf:()=>h,jc:()=>j,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},_=e=>e.program.body.flatMap(e=>{if(!s.isExportNamedDeclaration(e)||!s.isVariableDeclaration(e.declaration))return[];var r=e.declaration;return r.declarations.flatMap(t=>{if(!s.isIdentifier(t.id))return[];var i,a=t.id.typeAnnotation;s.isTSTypeAnnotation(a)&&s.isTSTypeReference(a.typeAnnotation)&&s.isIdentifier(a.typeAnnotation.typeName)&&(i=a.typeAnnotation.typeName.name);var n=s.isObjectExpression(t.init)?t.init:void 0;return[{name:t.id.name,node:e,declaration:r,declarator:t,object:n,id:n?g(n,"id"):void 0,alias:n?g(n,"alias"):void 0,typeName:i}]})}),x=(e,r)=>{var t=new Set;for(var i of e.program.body){if(s.isImportDeclaration(i)){i.specifiers.forEach(e=>t.add(e.local.name));continue}s.isExportNamedDeclaration(i)&&s.isVariableDeclaration(i.declaration)&&i.declaration.declarations.forEach(e=>{s.isIdentifier(e.id)&&t.add(e.id.name)})}if(!t.has(r))return r;for(var a=1;t.has(`${r}${a}`);)a+=1;return`${r}${a}`},w=(e,r,t)=>{var i=h(e,r);if(i){i.value=t;return}e.properties.push(s.objectProperty(v(r),t))},j=(e,r)=>{var t=e.properties.findIndex(e=>!!s.isObjectProperty(e)&&b(e.key)===r);t>=0&&e.properties.splice(t,1)},k=(e,r)=>{var t=e.program.body,i=t.findLastIndex(e=>s.isImportDeclaration(e));t.splice(i+1,0,r)},I=(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"),k(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"1"!==process.env.BRICKS_CTOR_MCP_DISABLE_COMPILE&&(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__:()=>eD,register:()=>eC});var a,n,o,s,l,c,u,d,p,f,y,m,b,v,h,g,_,x,w,j,k,I,S=t(68832),$=t(99436),E=t(2235),O=t(46773),P=t(58135),C=t(11978),D=t(79491),A=t(51455),L=t(76760),R=t(84867),N=t(54452),T=t(98009),F=t(3540),J=e([D]);D=(J.then?(await J)():J)[0];var Y=E.default||E;class eA extends Error{constructor(e,r,t,i=!1){super(r),this.name="DataCalcEditingError",this.code=e,this.details=t,this.isMcpError=i}}var M=(e,r)=>{if(L.isAbsolute(r))throw new eA("invalid_file","File must be project-relative",{file:r});var t=L.resolve(e,r),i=L.relative(e,t);if(i.startsWith("..")||L.isAbsolute(i))throw new eA("invalid_file","File must stay inside the project directory",{file:r});return t},z=(e,r)=>{try{return(0,O.parse)(e,{sourceType:"module",plugins:["typescript","topLevelAwait"],errorRecovery:!1})}catch(e){throw new eA("parse_failed",`Cannot parse ${r} as TypeScript: ${e.message}. Edit this file directly.`,{file:r},!0)}},q=(a=$(function*(e,r){var t=yield(0,T.LJ)(e,r);if(!t)throw new eA("invalid_file","File must stay inside the project directory",{file:(0,T.RI)(e,r)});var i=yield(0,A.readFile)(t,"utf8"),a=(0,T.RI)(e,r);return{source:i,ast:z(i,a),projectDir:e,absPath:r,ioPath:t,relPath:a}}),function(e,r){return a.apply(this,arguments)}),H=(n=$(function*(e,r){var t=yield(0,T.z5)(e,r);if(!t)throw new eA("invalid_file","File must stay inside the project directory",{file:(0,T.RI)(e,r)});return t}),function(e,r){return n.apply(this,arguments)}),K=(e,r)=>{if(null==r||""===r)return L.join(e,"subspaces/subspace-0");if("number"==typeof r)return L.join(e,"subspaces",`subspace-${r}`);var t=String(r);if(/^\d+$/.test(t))return L.join(e,"subspaces",`subspace-${t}`);if(/^subspace-\d+$/.test(t))return L.join(e,"subspaces",t);if(t.includes("/"))return M(e,t);throw new eA("unsupported_subspace",`Unsupported subspace locator: ${t}`,{subspace:t})},B=e=>{var r=L.basename(e),t=/^data-calculation-(.+)\.ts$/.exec(r);if(!t)throw new eA("invalid_file","Expected data-calculation-{slug}.ts file",{file:e});return t[1]},W=(o=$(function*(e){return(yield(0,A.readdir)(e,{withFileTypes:!0}).catch(()=>[])).filter(e=>e.isFile()&&/^data-calculation-.+\.ts$/.test(e.name)&&!e.name.endsWith(".sandbox.ts")).map(r=>L.join(e,r.name)).sort()}),function(e){return o.apply(this,arguments)}),Z=e=>{var r=(0,T.bf)(e,"code")?.value;return r&&P.isExpression(r)?r:null},U=e=>{var r=P.isAwaitExpression(e)?e.argument:e;if(!P.isCallExpression(r))return null;var t=r.arguments[0];if(!P.isNewExpression(t)||!P.isIdentifier(t.callee)||"URL"!==t.callee.name)return null;var i=t.arguments[0];return P.isStringLiteral(i)?i.value:null},V=(s=$(function*(e,r){if(r.file)a=M(e,r.file);else{var t,i,a,n=K(e,r.subspace),o=L.join(n,"data-calc"),s=yield W(o),l=r.calc;if(!l)throw new eA("missing_calc","Provide file or subspace+calc");for(var c of s){if(l===B(c)){a=c;break}try{var u=yield q(e,c),d=(0,T.Zj)(u.ast).find(e=>"dataCalculation"===e.name);if(d&&(l===d.alias||l===d.id)){a=c;break}}catch{continue}}}if(!a)throw new eA("calc_not_found",`Data calc not found: ${r.calc}`,{calc:r.calc,subspace:r.subspace??"subspace-0"});var p=yield q(e,a),f=(e=>{var r=(0,T.Zj)(e.ast).find(e=>"dataCalculation"===e.name);if(!r||!r.object)throw new eA("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,T.JJ)(r.object,"__typename");if("DataCalculationScript"!==t)throw new eA("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=B(a),m=(t=Z(f),(i=U(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)}),G=e=>{for(var r of e.program.body)if(P.isImportDeclaration(r)&&"node:fs/promises"===r.source.value){r.specifiers.some(e=>P.isImportSpecifier(e)&&P.isIdentifier(e.imported)&&"readFile"===e.imported.name)||r.specifiers.push(P.importSpecifier(P.identifier("readFile"),P.identifier("readFile")));return}(0,T.Pb)(e,P.importDeclaration([P.importSpecifier(P.identifier("readFile"),P.identifier("readFile"))],P.stringLiteral("node:fs/promises")))},Q=e=>{(0,T.Kx)(e.parsed.ast,"type",e.typeImports),(0,T.Kx)(e.parsed.ast,"value",e.valueImports)},X=(l=$(function*(e,r,t,i){var a,n=(e=>{var r=e.split(L.sep),t=r.findIndex(e=>/^subspace-\d+$/.test(e));if(t<0)throw new eA("invalid_file","Data-calc file must be inside subspaces/subspace-N/data-calc",{file:e});return r.slice(0,t+1).join(L.sep)})(r),o=null==i?n:K(e,i),s=L.join(o,"data.ts"),l=yield q(e,s),c=(0,T.Zj)(l.ast).filter(e=>e.name===t||e.id===t||e.alias===t);if(0===c.length)throw new eA("reference_not_found",`Data reference not found: ${t}`,{ref:t,subspace:L.basename(o)});if(c.length>1)throw new eA("ambiguous_reference",`Data reference is ambiguous: ${t}`,{ref:t,matches:c.map(r=>({file:(0,T.RI)(e,s),entry:r.name,id:r.id,alias:r.alias}))});var u=L.resolve(s)===L.resolve(r);return{input:t,id:c[0].id,alias:c[0].alias,varName:c[0].name,sameFile:u,importSource:u?void 0:((a=L.relative(L.dirname(r),s).replace(/\\/g,"/")).startsWith(".")||(a=`./${a}`),a.replace(/\.(ts|tsx|js|jsx)$/,""))}}),function(e,r,t,i){return l.apply(this,arguments)}),ee=(c=$(function*(e,r){if((0,T.u4)(e)&&"string"==typeof e.expr)return(0,O.parseExpression)(e.expr,{plugins:["typescript"]});var t="string"==typeof e?e:(0,T.u4)(e)?e.ref:void 0;if("string"!=typeof t||!t)throw new eA("invalid_ref","Data getter requires a data ref string");var i=yield X(r.projectDir,r.parsed.absPath,t,(0,T.u4)(e)?e.subspace:void 0),a=i.sameFile?"data":((e,r,t)=>{for(var i of e.ast.program.body)if(P.isImportDeclaration(i)&&i.source.value===r){var a=i.specifiers.find(e=>P.isImportNamespaceSpecifier(e));if(a)return a.local.name}var n=(0,T.R0)(e.ast,t),o=P.importDeclaration([P.importNamespaceSpecifier(P.identifier(n))],P.stringLiteral(r));return(0,T.Pb)(e.ast,o),n})(r.parsed,i.importSource||"../data","data");return r.references.push(i),P.arrowFunctionExpression([],P.memberExpression(P.identifier(a),P.identifier(i.varName)))}),function(e,r){return c.apply(this,arguments)}),er=(u=$(function*(e,r){return null==e?P.nullLiteral():ee(e,r)}),function(e,r){return u.apply(this,arguments)}),et=(d=$(function*(e,r){var t=L.join(e,"subspaces");for(var i of yield(0,A.readdir)(t,{withFileTypes:!0}).catch(()=>[]))if(i.isDirectory()&&/^subspace-\d+$/.test(i.name))for(var a of yield W(L.join(t,i.name,"data-calc")))try{var n=yield q(e,a),o=(0,T.Zj)(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)}),ei=new Set(["__typename","id","code","enableAsync","inputs","output","outputs","error"]),ea=e=>P.awaitExpression(P.callExpression(P.identifier("readFile"),[P.newExpression(P.identifier("URL"),[P.stringLiteral(`./${e}`),P.memberExpression(P.metaProperty(P.identifier("import"),P.identifier("meta")),P.identifier("url"))]),P.stringLiteral("utf8")])),en=(p=$(function*(e,r){if((0,T.u4)(e)){if("string"==typeof e.expr)return(0,O.parseExpression)(e.expr,{plugins:["typescript"]});if("string"==typeof e.ref)return ee(e,r)}if(null===e)return P.nullLiteral();if(void 0===e)return P.identifier("undefined");if("string"==typeof e)return P.stringLiteral(e);if("number"==typeof e)return P.numericLiteral(e);if("boolean"==typeof e)return P.booleanLiteral(e);if(Array.isArray(e))return P.arrayExpression((yield Promise.all(e.map(e=>en(e,r)))));if((0,T.u4)(e)){var t,i=yield Promise.all(Object.entries(e).map((t=$(function*([e,t]){return P.objectProperty((0,T.zu)(e),(yield en(t,r)))}),function(e){return t.apply(this,arguments)})));return P.objectExpression(i)}throw new eA("invalid_value",`Unsupported value: ${String(e)}`)}),function(e,r){return p.apply(this,arguments)}),eo=(f=$(function*(e){var r=Y(e.ast,{comments:!0},e.source).code,t=yield(0,D.format)(e.absPath,r,T.Hn);if(t.errors.length>0)throw new eA("format_failed",`oxfmt failed for ${e.relPath}`,{file:e.relPath,errors:t.errors});return t.code}),function(e){return f.apply(this,arguments)}),es=(y=$(function*(e){var r=yield eo(e);return z(r,e.relPath),yield(0,A.writeFile)(e.ioPath??(yield H(e.projectDir,e.absPath)),r),r}),function(e){return y.apply(this,arguments)}),el=e=>({content:[{type:"text",text:JSON.stringify(e,null,2)}],isError:e.isError||void 0}),ec=e=>e.map(e=>({input:e.input,id:e.id,alias:e.alias,entry:e.varName})),eu=(m=$(function*(e,r,t,i){var a=new Date().toISOString(),n=(0,F.S)();try{var o=yield i();return yield(0,F.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 eA,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,F.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)}),ed=(b=$(function*(e,r){var t=new Set((yield W(e)).map(B));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)}),ep=e=>{try{return(0,C.qg)(e,{sourceType:"module",ecmaVersion:2020}),!0}catch{return!1}},ef=e=>{var r=e??"";if((e=>{try{var r=(0,C.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
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
7
  ${t}
8
8
  }
9
- `;if(e_(a))return a}throw new Z("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)")},ew=(v=$(function*(e,r){yield(0,J.mkdir)(r,{recursive:!0});var t=yield er(r),i=t.map((e,r)=>{var t=ee(e);return`import { dataCalculation as dataCalculation${r} } from './data-calculation-${t}'`}).join("\n"),a=t.map((e,r)=>`dataCalculation${r}`).join(",\n "),n=`${i}
9
+ `;if(ep(a))return a}throw new eA("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)")},ey=(v=$(function*(e,r){yield(0,A.mkdir)(r,{recursive:!0});var t=yield W(r),i=t.map((e,r)=>{var t=B(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=Y.join(r,"index.ts"),s={projectDir:e,absPath:o,relPath:(0,q.RI)(e,o),source:n,ast:V(n,(0,q.RI)(e,o))};return yield em(s),(0,q.RI)(e,o)}),function(e,r){return v.apply(this,arguments)}),ej=(h=$(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 G(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 em(n),{touched:n.relPath}}),function(e,r){return h.apply(this,arguments)}),ek=(g=$(function*(e,r,t){if(!r.key)throw new Z("missing_key",`${e} item requires key`);if(null==r.data)throw new Z("missing_data",`${e} item requires data`);var i=[N.objectProperty(N.identifier("key"),N.stringLiteral(r.key)),N.objectProperty(N.identifier("data"),(yield el(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)}),eI=(_=$(function*(e,r,t){if("inputs"===e){var i=new Set;for(var a of r){if(i.has(a?.key))throw new Z("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 ek(e,o,t)));return N.arrayExpression(n)}),function(e,r,t){return _.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 Z("ambiguous_key",`IO key is ambiguous: ${r.key}`,{key:r.key,count:t.length});return t[0]?.index??-1},e$=(x=$(function*(e,r,t,i){let a;t.typeImports.add("DataCalculationScript"),t.valueImports.add("makeId"),en(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"),ep(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 eI("inputs",e.inputs||[],t)))),n.push(N.objectProperty(N.identifier("output"),(yield ec(e.output,t)))),n.push(N.objectProperty(N.identifier("outputs"),(yield eI("outputs",e.outputs||[],t)))),n.push(N.objectProperty(N.identifier("error"),(yield ec(e.error,t)))),N.objectExpression(n)}),function(e,r,t,i){return x.apply(this,arguments)}),eE=(w=$(function*(e,r){return eh(e,"new_data_calc",r,$(function*(){var t,i,a,n=X(e,r.subspace),o=Y.join(n,"data-calc");yield(0,J.mkdir)(o,{recursive:!0});var s=yield eg(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=V(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 eu(e,r.alias))?void 0:r.alias,y=yield e$(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]))),eo(p),yield(0,J.writeFile)((yield Q(e,u)),ex(r.code)),yield em(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 ew(e,o),action:"regenerate_index"});var v=yield ej(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:ev(p.references),summary:`created data calc ${s} in ${Y.basename(n)} -> ${h.status}`}}))}),function(e,r){return w.apply(this,arguments)}),eO=(j=$(function*(e,r){return eh(e,"edit_data_calc",r,$(function*(){var t=yield ea(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=S(n,2),s=o[0],l=o[1];if("output"===s||"error"===s)(0,q.HJ)(t.object,s,(yield ec(l,i)));else if("inputs"===s||"outputs"===s){if(!Array.isArray(l))throw new Z("invalid_value",`${s} must be an array of IO items`);(0,q.HJ)(t.object,s,(yield eI(s,l,i)))}else if("code"===s)throw new Z("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 ef(l,i)))}for(var c of r.unset||[]){if(ed.has(c))throw new Z("invalid_field",`Cannot unset required field: ${c}`,{field:c});(0,q.jc)(t.object,c)}if(null!=r.code){var u=et(t.object);if(!(e=>{if(!e)return!1;if(N.isStringLiteral(e)||N.isTemplateLiteral(e))return!0;var r=ei(e);return null!=r&&/^(\.\/)?[^/\\]+\.sandbox\.js$/.test(r)})(u))throw new Z("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)),ex(r.code)),en(t.parsed.ast),(0,q.HJ)(t.object,"code",ep(d)),a.push({file:(0,q.RI)(e,p),action:"write_sandbox"})}eo(i),yield em(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:ev(i.references),summary:`edited data calc ${t.slug} -> ${f.status}`}}))}),function(e,r){return j.apply(this,arguments)}),eP=(k=$(function*(e,r){return eh(e,"edit_data_calc_io",r,$(function*(){var t=yield ea(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 Z("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 Z("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 Z("invalid_index","replace requires a valid key or index");if("add"===o&&"number"==typeof l&&(l<0||l>n.elements.length))throw new Z("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 Z("duplicate_key",`Input key already exists: ${r}`,{key:r})})(n,r.key,"replace"===o?l:void 0);var c=yield ek(a,r,i);"replace"===o?n.elements[l]=c:n.elements.splice("number"==typeof l?l:n.elements.length,0,c)}else throw new Z("invalid_op",`Unsupported edit_data_calc_io op: ${o}`);eo(i),yield em(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:ev(i.references),summary:`${o} ${a} on data calc ${t.slug} -> ${u.status}`}}))}),function(e,r){return k.apply(this,arguments)}),eC=(I=$(function*(e,r){return eh(e,"remove_data_calc",r,$(function*(){var t=yield ea(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 ew(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)}),eD=M.bz().describe('Value grammar: JSON literals, bare data ref strings for output/error/IO data, { ref, subspace }, or { expr: "raw TypeScript expression" }.'),eA=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.'),eL=M.Yj().describe("Data calc locator inside the subspace: alias, explicit string id, or filename slug."),eN=M.zM().describe("Override compile verification. Defaults to BRICKS_CTOR_MCP_EDIT_VERIFY, otherwise true."),eT={file:eA.optional(),subspace:eR.optional(),calc:eL.optional(),verify:eN.optional()},eF=M.Ik({key:M.Yj().describe('Sandbox input/output key, for example "price" or "total".'),data:eD.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 eJ(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(eF).describe("Initial script inputs. Input keys must be unique.").optional(),outputs:M.YO(eF).describe("Initial fan-out outputs. Output keys may repeat.").optional(),output:eD.describe("Single output data ref or null.").optional(),error:eD.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:eN.optional()},(t=$(function*(e){return eb((yield eE(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."),eD).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=$(function*(e){return eb((yield eO(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:eD.describe("For add/replace: data ref as string, { ref, subspace }, or { expr }.").optional(),trigger:M.zM().describe("Inputs only; defaults true.").optional()},(a=$(function*(e){return eb((yield eP(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=$(function*(e){return eb((yield eC(r,e)))}),function(e){return n.apply(this,arguments)}))}var eY={newDataCalc:eE,editDataCalc:eO,editDataCalcIo:eP,removeDataCalc:eC,resolveCalcTarget:ea};i()}catch(e){i(e)}})}};
14
+ `,o=L.join(r,"index.ts"),s={projectDir:e,absPath:o,relPath:(0,T.RI)(e,o),source:n,ast:z(n,(0,T.RI)(e,o))};return yield es(s),(0,T.RI)(e,o)}),function(e,r){return v.apply(this,arguments)}),em=(h=$(function*(e,r){var t=L.join(r,"index.ts"),i=(0,T.RI)(e,t),a=yield(0,A.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 q(e,t),o=(e=>{for(var r of e.program.body)if(P.isExportDefaultDeclaration(r)){var t=r.declaration;if(P.isObjectExpression(t))return t;if(P.isTSAsExpression(t)&&P.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,T.bf)(o,"dataCalculation");if(s&&P.isIdentifier(s.value))return null;if(s&&!(P.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=>P.isImportDeclaration(e)&&("./data-calc"===e.source.value||"./data-calc/index"===e.source.value))||(0,T.Pb)(n.ast,P.importDeclaration([P.importSpecifier(P.identifier("dataCalculation"),P.identifier("dataCalculation"))],P.stringLiteral("./data-calc"))),s)s.value=P.identifier("dataCalculation"),P.isIdentifier(s.key)&&(s.shorthand=!0);else{var l=P.objectProperty(P.identifier("dataCalculation"),P.identifier("dataCalculation"));l.shorthand=!0,o.properties.push(l)}return yield es(n),{touched:n.relPath}}),function(e,r){return h.apply(this,arguments)}),eb=(g=$(function*(e,r,t){if(!r.key)throw new eA("missing_key",`${e} item requires key`);if(null==r.data)throw new eA("missing_data",`${e} item requires data`);var i=[P.objectProperty(P.identifier("key"),P.stringLiteral(r.key)),P.objectProperty(P.identifier("data"),(yield ee(r.data,t)))];return"inputs"===e&&i.push(P.objectProperty(P.identifier("trigger"),P.booleanLiteral(!1!==r.trigger))),P.objectExpression(i)}),function(e,r,t){return g.apply(this,arguments)}),ev=(_=$(function*(e,r,t){if("inputs"===e){var i=new Set;for(var a of r){if(i.has(a?.key))throw new eA("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 eb(e,o,t)));return P.arrayExpression(n)}),function(e,r,t){return _.apply(this,arguments)}),eh=(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})=>P.isObjectExpression(e)&&(0,T.JJ)(e,"key")===r.key);if(t.length>1)throw new eA("ambiguous_key",`IO key is ambiguous: ${r.key}`,{key:r.key,count:t.length});return t[0]?.index??-1},eg=(x=$(function*(e,r,t,i){let a;t.typeImports.add("DataCalculationScript"),t.valueImports.add("makeId"),G(t.parsed.ast);var n=[P.objectProperty(P.identifier("__typename"),P.stringLiteral("DataCalculationScript")),P.objectProperty(P.identifier("id"),e.id?P.stringLiteral(e.id):(a="property_bank_calc",P.callExpression(P.identifier("makeId"),i?[P.stringLiteral(a),P.stringLiteral(i)]:[P.stringLiteral(a)])))];return e.alias&&n.push(P.objectProperty(P.identifier("alias"),P.stringLiteral(e.alias))),null!=e.title&&n.push(P.objectProperty(P.identifier("title"),P.stringLiteral(e.title))),null!=e.description&&n.push(P.objectProperty(P.identifier("description"),P.stringLiteral(e.description))),null!=e.note&&n.push(P.objectProperty(P.identifier("note"),P.stringLiteral(e.note))),n.push(P.objectProperty(P.identifier("code"),ea(r))),n.push(P.objectProperty(P.identifier("enableAsync"),P.booleanLiteral(!!e.enableAsync))),null!=e.triggerMode&&n.push(P.objectProperty(P.identifier("triggerMode"),P.stringLiteral(e.triggerMode))),n.push(P.objectProperty(P.identifier("inputs"),(yield ev("inputs",e.inputs||[],t)))),n.push(P.objectProperty(P.identifier("output"),(yield er(e.output,t)))),n.push(P.objectProperty(P.identifier("outputs"),(yield ev("outputs",e.outputs||[],t)))),n.push(P.objectProperty(P.identifier("error"),(yield er(e.error,t)))),P.objectExpression(n)}),function(e,r,t,i){return x.apply(this,arguments)}),e_=(w=$(function*(e,r){return eu(e,"new_data_calc",r,$(function*(){var t,i,a,n=K(e,r.subspace),o=L.join(n,"data-calc");yield(0,A.mkdir)(o,{recursive:!0});var s=yield ed(o,r.alias),l=`data-calculation-${s}.sandbox.js`,c=L.join(o,`data-calculation-${s}.ts`),u=L.join(o,l),d=(t=(0,T.RI)(e,c),i="export const dataCalculation = {}\n",(a=z(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 et(e,r.alias))?void 0:r.alias,y=yield eg(r,l,p,f),m=P.variableDeclarator(P.identifier("dataCalculation"),y);m.id.typeAnnotation=P.tsTypeAnnotation(P.tsTypeReference(P.identifier("DataCalculationScript"))),d.ast.program.body.push(P.exportNamedDeclaration(P.variableDeclaration("const",[m]))),Q(p),yield(0,A.writeFile)((yield H(e,u)),ef(r.code)),yield es(d);var b=[{file:(0,T.RI)(e,c),action:"create_calc"},{file:(0,T.RI)(e,u),action:"write_sandbox"}];b.push({file:yield ey(e,o),action:"regenerate_index"});var v=yield em(e,n);v?.touched&&b.push({file:v.touched,action:"wire_subspace_index"});var h=yield(0,N.H)(e,r.verify);return{file:(0,T.RI)(e,c),subspace:L.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:ec(p.references),summary:`created data calc ${s} in ${L.basename(n)} -> ${h.status}`}}))}),function(e,r){return w.apply(this,arguments)}),ex=(j=$(function*(e,r){return eu(e,"edit_data_calc",r,$(function*(){var t=yield V(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=S(n,2),s=o[0],l=o[1];if("output"===s||"error"===s)(0,T.HJ)(t.object,s,(yield er(l,i)));else if("inputs"===s||"outputs"===s){if(!Array.isArray(l))throw new eA("invalid_value",`${s} must be an array of IO items`);(0,T.HJ)(t.object,s,(yield ev(s,l,i)))}else if("code"===s)throw new eA("invalid_field","Set code via the dedicated code parameter so it stays normalized to the sandbox file");else(0,T.HJ)(t.object,s,(yield en(l,i)))}for(var c of r.unset||[]){if(ei.has(c))throw new eA("invalid_field",`Cannot unset required field: ${c}`,{field:c});(0,T.jc)(t.object,c)}if(null!=r.code){var u=Z(t.object);if(!(e=>{if(!e)return!1;if(P.isStringLiteral(e)||P.isTemplateLiteral(e))return!0;var r=U(e);return null!=r&&/^(\.\/)?[^/\\]+\.sandbox\.js$/.test(r)})(u))throw new eA("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=L.join(L.dirname(t.parsed.absPath),d);yield(0,A.writeFile)((yield H(e,p)),ef(r.code)),G(t.parsed.ast),(0,T.HJ)(t.object,"code",ea(d)),a.push({file:(0,T.RI)(e,p),action:"write_sandbox"})}Q(i),yield es(t.parsed),a.unshift({file:t.parsed.relPath,action:"edit_calc"});var f=yield(0,N.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:ec(i.references),summary:`edited data calc ${t.slug} -> ${f.status}`}}))}),function(e,r){return j.apply(this,arguments)}),ew=(k=$(function*(e,r){return eu(e,"edit_data_calc_io",r,$(function*(){var t=yield V(e,r),i={projectDir:e,parsed:t.parsed,references:[],typeImports:new Set,valueImports:new Set},a=r.field,n=((e,r)=>{var t=(0,T.bf)(e,r);if(t){if(!P.isArrayExpression(t.value))throw new eA("fallback_recommended",`${r} is not an array. Edit this file directly.`);return t.value}var i=P.arrayExpression([]);return e.properties.push(P.objectProperty(P.identifier(r),i)),i})(t.object,a),o=r.op;if("clear"===o)n.elements=[];else if("remove"===o){var s=eh(n,r);if(s<0||s>=n.elements.length)throw new eA("invalid_index","remove requires a valid key or index");n.elements.splice(s,1)}else if("add"===o||"replace"===o){var l="replace"===o?eh(n,r):r.index;if("replace"===o&&(l<0||l>=n.elements.length))throw new eA("invalid_index","replace requires a valid key or index");if("add"===o&&"number"==typeof l&&(l<0||l>n.elements.length))throw new eA("invalid_index","add index out of range",{index:l});"inputs"===a&&((e,r,t)=>{if(e.elements.some((e,i)=>i!==t&&P.isObjectExpression(e)&&(0,T.JJ)(e,"key")===r))throw new eA("duplicate_key",`Input key already exists: ${r}`,{key:r})})(n,r.key,"replace"===o?l:void 0);var c=yield eb(a,r,i);"replace"===o?n.elements[l]=c:n.elements.splice("number"==typeof l?l:n.elements.length,0,c)}else throw new eA("invalid_op",`Unsupported edit_data_calc_io op: ${o}`);Q(i),yield es(t.parsed);var u=yield(0,N.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:ec(i.references),summary:`${o} ${a} on data calc ${t.slug} -> ${u.status}`}}))}),function(e,r){return k.apply(this,arguments)}),ej=(I=$(function*(e,r){return eu(e,"remove_data_calc",r,$(function*(){var t=yield V(e,r),i=L.dirname(t.parsed.absPath),a=L.join(i,t.sandboxFile);yield(0,A.rm)(t.parsed.absPath,{force:!0}),yield(0,A.rm)(a,{force:!0});var n=yield ey(e,i),o=yield(0,N.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,T.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)}),ek=R.bz().describe('Value grammar: JSON literals, bare data ref strings for output/error/IO data, { ref, subspace }, or { expr: "raw TypeScript expression" }.'),eI=R.Yj().describe("Project-relative data-calc file path, for example subspaces/subspace-0/data-calc/data-calculation-total.ts."),eS=R.KC([R.Yj(),R.ai()]).describe('Subspace locator. Defaults to subspace-0; accepts 0, "0", "subspace-0", or a project-relative subspace path.'),e$=R.Yj().describe("Data calc locator inside the subspace: alias, explicit string id, or filename slug."),eE=R.zM().describe("Override compile verification. Defaults to BRICKS_CTOR_MCP_EDIT_VERIFY, otherwise true."),eO={file:eI.optional(),subspace:eS.optional(),calc:e$.optional(),verify:eE.optional()},eP=R.Ik({key:R.Yj().describe('Sandbox input/output key, for example "price" or "total".'),data:ek.describe("Data ref as alias/id/varName, { ref, subspace }, or { expr }."),trigger:R.zM().describe("Inputs only; defaults true.").optional()}).describe("DataCalculationScript IO item.");function eC(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:eS.optional(),alias:R.Yj().describe("Optional alias; also drives the filename slug.").optional(),title:R.Yj().describe("Optional title.").optional(),description:R.Yj().describe("Optional description.").optional(),note:R.Yj().describe("Optional script note.").optional(),triggerMode:R.k5(["auto","manual"]).describe("Optional trigger mode; omitted by default.").optional(),enableAsync:R.zM().describe("Whether the sandbox main may be async. Defaults false.").optional(),code:R.Yj().describe("Sandbox body. The tool wraps it as export function main() { ... } unless already wrapped.").optional(),inputs:R.YO(eP).describe("Initial script inputs. Input keys must be unique.").optional(),outputs:R.YO(eP).describe("Initial fan-out outputs. Output keys may repeat.").optional(),output:ek.describe("Single output data ref or null.").optional(),error:ek.describe("Error output data ref or null.").optional(),id:R.Yj().describe("Optional explicit id. Defaults to source expression makeId('property_bank_calc').").optional(),verify:eE.optional()},(t=$(function*(e){return el((yield e_(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.",{...eO,set:R.g1(R.Yj().describe("Top-level field path such as title, description, note, alias, triggerMode, enableAsync, output, or error."),ek).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:R.YO(R.Yj()).describe("Top-level fields to remove.").optional(),code:R.Yj().describe("Replacement sandbox body. The tool wraps it as export function main() { ... } unless already wrapped.").optional()},(i=$(function*(e){return el((yield ex(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.",{...eO,field:R.k5(["inputs","outputs"]).describe("Which IO array to edit."),op:R.k5(["add","remove","replace","clear"]).describe("Array operation."),key:R.Yj().describe("IO key target. Ambiguous repeated output keys must use index.").optional(),index:R.ai().describe("Zero-based IO index target or add insertion index.").optional(),data:ek.describe("For add/replace: data ref as string, { ref, subspace }, or { expr }.").optional(),trigger:R.zM().describe("Inputs only; defaults true.").optional()},(a=$(function*(e){return el((yield ew(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.",eO,(n=$(function*(e){return el((yield ej(r,e)))}),function(e){return n.apply(this,arguments)}))}var eD={newDataCalc:e_,editDataCalc:ex,editDataCalcIo:ew,removeDataCalc:ej,resolveCalcTarget:V};i()}catch(e){i(e)}})}};