exports.id=4031,exports.ids=[4031],exports.modules={12140:(a,b,c)=>{"use strict";c.d(b,{Md:()=>p,u0:()=>m,y4:()=>n});var d=c(73024),e=c(76760),f=c.n(e),g=c(77598),h=c.n(g),i=c(73652);let j=f().join((0,i._)(),"audit");function k(a){return f().join(j,`${a}.jsonl`)}function l(a=new Date){return a.toISOString().slice(0,10)}async function m(a){let b={ts:a.ts??new Date().toISOString(),...a};await d.promises.mkdir(j,{recursive:!0});let c=k(l());await d.promises.appendFile(c,JSON.stringify(b)+"\n","utf8")}async function n(a={}){let b,c=await o(),e=a.date??c[0]??l(),f=a.limit??500,g=k(e);try{b=await d.promises.readFile(g,"utf8")}catch{return{date:e,entries:[],availableDates:c}}let h=[],i=b.split(/\r?\n/);for(let b=i.length-1;b>=0&&h.length<f;b--){let c,d=i[b];if(d){try{c=JSON.parse(d)}catch{continue}(function(a,b){if(!b)return!0;if(b.utilityId&&a.utilityId!==b.utilityId||b.method&&a.method!==b.method||b.phase&&a.phase!==b.phase)return!1;if(b.status){let c=!a.error;if("ok"===b.status&&!c||"error"===b.status&&c)return!1}return!0})(c,a.filter)&&h.push(c)}}return{date:e,entries:h,availableDates:c}}async function o(){let a;try{a=await d.promises.readdir(j)}catch{return[]}return a.filter(a=>/^\d{4}-\d{2}-\d{2}\.jsonl$/.test(a)).map(a=>a.replace(/\.jsonl$/,"")).sort().reverse()}async function p(a,b){let c=h().randomUUID().replace(/-/g,"").slice(0,16),d=Date.now();await m({ts:new Date().toISOString(),utilityId:a.utilityId,scope:a.scope,channel:a.channel,method:a.method,phase:"start",correlationId:c,...a.parentCorrelationId?{parentCorrelationId:a.parentCorrelationId}:{},args:q(a.args)});try{let e=await b(c);return await m({ts:new Date().toISOString(),utilityId:a.utilityId,scope:a.scope,channel:a.channel,method:a.method,phase:"end",correlationId:c,durationMs:Date.now()-d,result:q(e)}),e}catch(e){let b=e instanceof Error?e.message:String(e);throw await m({ts:new Date().toISOString(),utilityId:a.utilityId,scope:a.scope,channel:a.channel,method:a.method,phase:"end",correlationId:c,durationMs:Date.now()-d,error:b}),e}}function q(a,b=0){if(null==a)return a;if("string"==typeof a)return a.length>2e3?a.slice(0,2e3)+"…[truncated]":a;if("object"!=typeof a)return a;if(b>3)return"[…]";if(Array.isArray(a))return a.slice(0,50).map(a=>q(a,b+1));let c={},d=0;for(let[e,f]of Object.entries(a)){if(d++>=50){c["…"]="truncated";break}c[e]=q(f,b+1)}return c}},28200:(a,b,c)=>{"use strict";c.d(b,{iG:()=>m});var d=c(76760),e=c.n(d),f=c(73024),g=c(73652);let h=null,i=!1,j=!1;async function k(){if(j)return null;try{return await Promise.resolve().then(c.t.bind(c,79868,23))}catch{return j=!0,null}}async function l(){if(h&&i)return{raw:h};let a=await k();if(!a)return null;let b=(0,g._)();await f.promises.mkdir(b,{recursive:!0});let c=e().join(b,"sessions.db"),d=new a.DatabaseSync(c);return d.exec("PRAGMA journal_mode = WAL"),d.exec("PRAGMA synchronous = NORMAL"),d.exec("PRAGMA temp_store = MEMORY"),function(a){a.exec(`
    CREATE TABLE IF NOT EXISTS meta (
      key TEXT PRIMARY KEY,
      value TEXT NOT NULL
    );

    CREATE TABLE IF NOT EXISTS documents (
      id          INTEGER PRIMARY KEY,
      source      TEXT    NOT NULL,
      root_id     TEXT    NOT NULL,
      root_path   TEXT    NOT NULL,
      ref         TEXT    NOT NULL,
      file_path   TEXT    NOT NULL UNIQUE,
      title       TEXT,
      iso_date    TEXT,
      mtime_ms    INTEGER NOT NULL,
      indexed_at  INTEGER NOT NULL
    );

    CREATE INDEX IF NOT EXISTS idx_documents_root ON documents(root_id);
    CREATE INDEX IF NOT EXISTS idx_documents_source ON documents(source);
    CREATE INDEX IF NOT EXISTS idx_documents_date ON documents(iso_date);

    CREATE VIRTUAL TABLE IF NOT EXISTS documents_fts USING fts5(
      title,
      body,
      tokenize = 'unicode61 remove_diacritics 2'
    );
  `);let b=a.prepare("SELECT value FROM meta WHERE key = 'schema_version'").get();if(b){if(b.value!==String(1))throw Error(`sessions.db schema_version mismatch (expected 1, found ${b.value})`)}else a.prepare("INSERT INTO meta (key, value) VALUES ('schema_version', ?)").run(String(1))}(d),h=d,i=!0,{raw:d}}async function m(a,b={}){let c,d=function(a){if(!a)return"";let b=a.replace(/[\^*:"]/g," ").replace(/\s+/g," ").trim();if(!b)return"";let c=new Set(["AND","OR","NOT","NEAR"]);return b.split(" ").map(a=>a?c.has(a.toUpperCase())?a.toUpperCase():/[()]/.test(a)?a:`${a}*`:a).filter(Boolean).join(" ")}(a);if(!d)return[];let e=await l();if(!e)return[];let f=e.raw,g=Math.max(1,Math.min(100,b.limit??20)),h=["documents_fts MATCH ?"],i=[d];b.rootId&&(h.push("d.root_id = ?"),i.push(b.rootId)),b.source&&(h.push("d.source = ?"),i.push(b.source)),b.since&&(h.push("d.iso_date >= ?"),i.push(b.since)),b.until&&(h.push("d.iso_date <= ?"),i.push(b.until));let j=`
    SELECT
      d.id        AS id,
      d.source    AS source,
      d.root_id   AS root_id,
      d.root_path AS root_path,
      d.ref       AS ref,
      d.title     AS title,
      d.iso_date  AS iso_date,
      bm25(documents_fts) AS rank,
      snippet(documents_fts, 1, '{{', '}}', '…', 12) AS snippet
    FROM documents_fts
    JOIN documents d ON d.id = documents_fts.rowid
    WHERE ${h.join(" AND ")}
    ORDER BY rank ASC
    LIMIT ?
  `;i.push(g);try{c=f.prepare(j).all(...i)}catch(b){let a=d.replace(/[()"^*:]/g," ").trim();if(!a||a===d)throw b;i[0]=a,c=f.prepare(j).all(...i)}return c.map(a=>({id:a.id,source:a.source,rootId:a.root_id,rootPath:a.root_path,ref:a.ref,title:a.title,isoDate:a.iso_date,rank:a.rank,snippet:a.snippet}))}c(87841),c(53905),c(54287)},49556:(a,b,c)=>{"use strict";c.a(a,async(a,d)=>{try{c.d(b,{runServerAction:()=>m});var e=c(75919),f=c(76760),g=c.n(f),h=c(73136),i=c(99861),j=c(99066),k=c(12140),l=a([i,j]);async function m(a){let b=(0,i.actionBundlePath)(a.utility.dir,a.action.name),c=(0,h.pathToFileURL)(b).toString(),d=function(){let a="lib/server/utilities/worker-bootstrap.js",b=process.env.REFLEX_PKG_ROOT;if(b)return g().resolve(b,a);let c=null;try{c=61880}catch{}return"string"==typeof c&&g().isAbsolute(c)?c:g().resolve(process.cwd(),a)}();return new Promise((b,f)=>{let g=new e.Worker(d,{workerData:{bundleUrl:c,actionName:a.action.name,utilityId:a.utility.manifest.id,scope:a.utility.scope},env:{},eval:!1,resourceLimits:{maxOldGenerationSizeMb:256,maxYoungGenerationSizeMb:64}}),h=!1,i=(c,d,e)=>{h||(h=!0,clearTimeout(l),g.removeAllListeners(),g.terminate().catch(()=>{}),c?((0,k.u0)({ts:new Date().toISOString(),utilityId:a.utility.manifest.id,scope:a.utility.scope,channel:"worker",method:`action:${a.action.name}`,phase:"end",correlationId:a.parentCorrelationId??"(detached)",error:e??c.message}),f(c)):b(d))},l=setTimeout(()=>{i(Error("server action timed out"),void 0,"timeout")},a.action.timeoutMs);g.on("error",a=>i(a)),g.on("exit",a=>{0!==a&&i(Error(`worker exited with code ${a}`))}),g.on("message",async b=>{if(b&&"object"==typeof b){if("host-rpc"===b.type){let c=b.id,d=b.method,e=b.args;try{let b=await (0,j.p)({utility:a.utility,channel:"worker",...a.parentCorrelationId?{parentCorrelationId:a.parentCorrelationId}:{}},d,e);g.postMessage({type:"host-rpc-result",id:c,ok:!0,result:b})}catch(a){g.postMessage({type:"host-rpc-result",id:c,ok:!1,error:a instanceof Error?a.message:String(a)})}return}"invoke-result"===b.type&&(b.ok?i(null,b.result):i(Error(b.error||"server action failed")))}}),g.postMessage({type:"invoke",args:a.args})})}[i,j]=l.then?(await l)():l,d()}catch(a){d(a)}})},61880:(a,b,c)=>{"use strict";var d=c(75919);if(!d.parentPort)throw Error("worker-bootstrap.js must be loaded as a worker_threads child");let e=new Map,f=1,g=new Proxy({},{get(a,b){if("string"==typeof b)return function a(b){return new Proxy(function(){},{get(c,d){if("string"==typeof d&&"then"!==d&&"catch"!==d&&"finally"!==d)return a(b?`${b}.${d}`:d)},apply:(a,c,g)=>{var h;return h=g[0],new Promise((a,c)=>{let g=f++;e.set(g,{resolve:a,reject:c}),d.parentPort.postMessage({type:"host-rpc",id:g,method:b,args:h})})}})}(b)}});globalThis.__reflexHost=g,d.parentPort.on("message",async a=>{if(a&&"host-rpc-result"===a.type){let b=e.get(a.id);if(!b)return;e.delete(a.id),a.ok?b.resolve(a.result):b.reject(Error(a.error||"rpc failed"));return}if(a&&"invoke"===a.type)try{let b=await c(74664)(d.workerData.bundleUrl),e=b[d.workerData.actionName]??b.default;if("function"!=typeof e)throw Error(`action "${d.workerData.actionName}" must export a function (named export or default)`);let f=await e(a.args,g);d.parentPort.postMessage({type:"invoke-result",ok:!0,result:f})}catch(a){d.parentPort.postMessage({type:"invoke-result",ok:!1,error:a&&a.message?a.message:String(a)})}})},74664:a=>{function b(a){return Promise.resolve().then(()=>{var b=Error("Cannot find module '"+a+"'");throw b.code="MODULE_NOT_FOUND",b})}b.keys=()=>[],b.resolve=b,b.id=74664,a.exports=b},99066:(a,b,c)=>{"use strict";c.a(a,async(a,d)=>{try{c.d(b,{p:()=>q});var e=c(73024),f=c(76760),g=c.n(f),h=c(56149),i=c(12140),j=c(99353),k=c(56942),l=c(19319),m=c(28200),n=c(53905),o=c(36017),p=a([j]);j=(p.then?(await p)():p)[0];let aj=h.Ik({task:h.k5(["chat","quick","rag","embed"]).default("quick"),prompt:h.Yj().min(1),model:h.Yj().optional()}),ak=h.Ik({kind:h.Yj().min(1).max(64),title:h.Yj().min(1).max(200),body:h.Yj().default(""),meta:h.g1(h.Yj(),h.L5()).optional(),slug:h.Yj().optional(),date:h.Yj().optional(),rootId:h.Yj().optional()}),al=h.Ik({kind:h.Yj().optional(),query:h.Yj().optional(),rootId:h.Yj().optional()}),am=h.Ik({relPath:h.Yj().min(1),rootId:h.Yj().optional()}),an=h.Ik({path:h.Yj().min(1),content:h.Yj().optional()}),ao=h.Ik({url:h.Yj().url(),method:h.k5(["GET","POST","PUT","DELETE","PATCH"]).default("GET"),headers:h.g1(h.Yj(),h.Yj()).optional(),body:h.KC([h.Yj(),h.g1(h.Yj(),h.L5())]).optional()}),ap=h.Ik({query:h.Yj().min(1).max(512)}),aq=h.Ik({type:h.Yj().min(1).max(64),payload:h.L5().optional()}),ar=h.Ik({server:h.Yj().min(1).optional(),tool:h.Yj().min(1),args:h.g1(h.Yj(),h.L5()).default({})}),as=h.Ik({server:h.Yj().min(1).optional()}),at=h.Ik({key:h.Yj().min(1)}),au=h.Ik({name:h.Yj().min(1),args:h.L5().optional()}),av=h.Ik({prompt:h.Yj().min(1).max(4e4),rootId:h.Yj().optional(),harness:h.Yj().optional(),model:h.Yj().optional(),language:h.Yj().optional(),label:h.Yj().optional(),timeoutMs:h.ai().int().min(1e3).max(9e5).optional()}),aw=h.Ik({rootId:h.Yj().optional()}),ax=h.Ik({workflowId:h.Yj().min(1),rootId:h.Yj().optional()}),ay=h.Ik({workflowId:h.Yj().min(1),rootId:h.Yj().optional(),input:h.L5().optional()}),az=h.Ik({prompt:h.Yj().min(1).max(8e3),provider:h.k5(["gemini","codex"]).optional(),size:h.Yj().max(40).optional(),aspectRatio:h.Yj().max(40).optional(),referenceImageUrls:h.YO(h.Yj().url()).max(6).optional(),alt:h.Yj().max(280).optional(),rootId:h.Yj().optional()}),aA=h.Ik({query:h.Yj().min(1).max(200),provider:h.k5(["unsplash","pexels","brave"]).optional(),count:h.ai().int().min(1).max(24).optional()}),aB=h.Ik({sourceUrl:h.Yj().url(),rootId:h.Yj().optional()}),aC=h.Ik({source:h.Yj().min(1).max(2e4)}),aD=h.Ik({kind:h.k5(["workflow","chat"]),id:h.Yj().optional(),prompt:h.Yj().optional()}).strict(),aE=h.Ik({kind:h.k5(["image","text","file"]),file:h.Yj().min(1).max(500),caption:h.Yj().max(500).optional()}).strict(),aF=h.Ik({title:h.Yj().min(1).max(280),body:h.Yj().max(5e4).default(""),type:h.k5(["feature","bug","refactor","docs","chore","research","review","call","idea"]).default("feature"),status:h.k5(["backlog","ready","in-progress","review","done","blocked"]).default("backlog"),priority:h.k5(["low","normal","high"]).default("normal"),labels:h.YO(h.Yj()).default([]),assignee:h.Yj().nullable().default(null),parent:h.Yj().nullable().default(null),links:h.Ik({blocks:h.YO(h.Yj()).optional(),blockedBy:h.YO(h.Yj()).optional(),related:h.YO(h.Yj()).optional()}).default({}),pre:h.YO(aD).default([]),post:h.YO(aD).default([]),attachments:h.YO(aE).default([])}),aG=h.Ik({id:h.Yj().min(1),patch:h.Ik({title:h.Yj().min(1).max(280).optional(),body:h.Yj().max(5e4).optional(),type:h.k5(["feature","bug","refactor","docs","chore","research","review","call","idea"]).optional(),status:h.k5(["backlog","ready","in-progress","review","done","blocked"]).optional(),priority:h.k5(["low","normal","high"]).optional(),labels:h.YO(h.Yj()).optional(),assignee:h.Yj().nullable().optional(),parent:h.Yj().nullable().optional(),links:h.Ik({blocks:h.YO(h.Yj()).optional(),blockedBy:h.YO(h.Yj()).optional(),related:h.YO(h.Yj()).optional()}).optional(),pre:h.YO(aD).optional(),post:h.YO(aD).optional(),attachments:h.YO(aE).optional()}).default({})}),aH=h.Ik({id:h.Yj().min(1)}),aI=h.Ik({id:h.Yj().min(1),harness:h.Yj().optional(),model:h.Yj().optional()}),aJ=h.Ik({id:h.Yj().min(1),outcome:h.k5(["done","review","blocked"])}),aK=h.Ik({branch:h.Yj().min(1),intoRef:h.Yj().optional()}),aL=h.Ik({slug:h.Yj().min(1),branch:h.Yj().min(1),force:h.zM().default(!1),deleteBranch:h.zM().default(!0)}),aM=h.Ik({slug:h.Yj().min(1),branch:h.Yj().min(1),baseRef:h.Yj().optional()}),aN=h.Ik({query:h.Yj().min(1).max(512),rootId:h.Yj().optional(),source:h.k5(["journal","topic"]).optional(),since:h.Yj().optional(),until:h.Yj().optional(),limit:h.ai().int().min(1).max(50).default(10)}),aO=h.Ik({query:h.Yj().min(1).max(200),alt:h.Yj().max(280).default(""),context:h.Yj().max(2e3).default(""),candidates:h.YO(h.Ik({url:h.Yj().url(),thumb:h.Yj().url(),attribution:h.Ik({name:h.Yj().default(""),link:h.Yj().default("")})})).min(1).max(12),rootId:h.Yj().optional()}),aP=h.Ik({widgetId:h.Yj().optional(),snapshot:h.Ik({kind:h.k5(["markdown","news-list","link-list","kpi","checklist","quote","kb-pinned","progress","image","stat-table","map","action-list"]),title:h.Yj().optional(),description:h.Yj().optional(),data:h.g1(h.Yj(),h.L5()).default({})}),rootId:h.Yj().optional()});async function q(a,b,c){let d={utilityId:a.utility.manifest.id,scope:a.utility.scope,channel:a.channel,method:b,args:c,...a.parentCorrelationId?{parentCorrelationId:a.parentCorrelationId}:{}};return(0,i.Md)(d,async d=>{switch(b){case"llm.complete":return x(a,aj.parse(c));case"kb.add":return y(a,ak.parse(c));case"kb.list":return z(a,al.parse(c));case"kb.read":return A(a,am.parse(c));case"fs.read":return C(a,an.parse(c));case"fs.write":return D(a,an.parse(c));case"fs.list":return E(a,an.parse(c));case"web.fetch":return F(a,ao.parse(c));case"web.search":return G(a,ap.parse(c));case"audit.log":return H(a,aq.parse(c),d);case"actions.invoke":return I(a,au.parse(c),d);case"mcp.call":return u(a,ar.parse(c));case"mcp.listServers":return v(a);case"mcp.listTools":return w(a,as.parse(c));case"secrets.get":return r(a,at.parse(c));case"secrets.list":return s(a);case"agent.invoke":return J(a,av.parse(c));case"workflow.list":return K(a,aw.parse(c));case"workflow.read":return L(a,ax.parse(c));case"workflow.run":return M(a,ay.parse(c));case"cards.update":return N(a,aP.parse(c));case"images.generate":return O(a,az.parse(c));case"images.search":return P(a,aA.parse(c));case"images.attach":return Q(a,aB.parse(c));case"images.pickBest":return R(a,aO.parse(c));case"mermaid.validate":return U(a,aC.parse(c));case"tasks.create":return V(a,aF.parse(c));case"tasks.update":return W(a,aG.parse(c));case"tasks.delete":return X(a,aH.parse(c));case"tasks.get":return Y(a,aH.parse(c));case"tasks.list":return Z(a);case"tasks.dispatch":return $(a,aI.parse(c));case"tasks.observe":return _(a,aH.parse(c));case"tasks.complete":return aa(a,aJ.parse(c));case"git.isRepo":return ab(a);case"git.hasRemote":return ac(a);case"git.hasGhCli":return ad();case"git.worktree.create":return ae(a,aM.parse(c));case"git.worktree.merge":return af(a,aK.parse(c));case"git.worktree.remove":return ag(a,aL.parse(c));case"git.worktree.list":return ah(a);case"sessions.search":return ai(a,aN.parse(c));default:throw Error(`Unknown host method: ${b}`)}})}async function r(a,b){if(!(a.utility.manifest.secrets??[]).find(a=>a.key===b.key))throw Error(`secret "${b.key}" is not declared in manifest.secrets`);let{getSecret:d}=await c.e(8514).then(c.bind(c,28514)),e=await d(a.utility.scope,a.utility.manifest.id,b.key,a.utility.rootId);if(null==e)throw Error(`secret "${b.key}" is not set — fill it in the utility's panel`);return{value:e}}async function s(a){let b=a.utility.manifest.secrets??[],{listSecretKeys:d}=await c.e(8514).then(c.bind(c,28514)),e=new Set(await d(a.utility.scope,a.utility.manifest.id,a.utility.rootId));return{secrets:b.map(a=>({key:a.key,set:e.has(a.key),required:a.required,label:a.label,description:a.description}))}}async function t(a,b){let d=a.utility.manifest.mcpServers??[],f=b;if(!f)if(1===d.length)f=d[0];else if(a.utility.manifest.source?.type==="mcp"){let b=g().join(a.utility.dir,"mcp.json"),d=await e.promises.readFile(b,"utf8").catch(()=>null);if(!d)throw Error(`mcp config missing at ${b}`);let{McpConfigSchema:f}=await Promise.resolve().then(c.bind(c,97453));return{config:f.parse(JSON.parse(d)),serverId:"(bundled)"}}else throw Error(0===d.length?"manifest.mcpServers is empty — declare which server you want to use":"multiple mcpServers declared — pass `server` explicitly");if(!d.includes(f))throw Error(`mcp server "${f}" is not in manifest.mcpServers — declare it to gain access`);let{getMcpServer:h}=await Promise.resolve().then(c.bind(c,580)),i=await h(f);if(!i)throw Error(`mcp server "${f}" is not registered — add it in Settings → MCP`);return{config:i.config,serverId:f}}async function u(a,b){let{config:d,serverId:e}=await t(a,b.server),{callTool:f}=await Promise.resolve().then(c.bind(c,97453)),g=await f(d,b.tool,b.args);return{server:e,...void 0!==g.isError?{isError:g.isError}:{},content:g.content}}async function v(a){let b=a.utility.manifest.mcpServers??[],{listMcpServers:d}=await Promise.resolve().then(c.bind(c,580)),e=await d(),f=new Map(e.map(a=>[a.id,a]));return{servers:b.map(a=>{let b=f.get(a);return{id:a,label:b?.label??a,description:b?.description??"",registered:!!b}})}}async function w(a,b){let{config:d,serverId:e}=await t(a,b.server),{connectAndListTools:f}=await Promise.resolve().then(c.bind(c,97453)),g=await f(d);return{server:e,tools:g.tools}}async function x(a,b){S(a.utility.manifest,!!a.utility.manifest.permissions.llm?.tasks?.includes(b.task),`llm.${b.task} not granted in manifest`);let c={...(await (0,o.loadSettings)()).assignments[b.task],...b.model?{model:b.model}:{}};return{text:await (0,j.quickComplete)(c,b.prompt,{timeoutMs:6e4})}}async function y(a,b){if(S(a.utility.manifest,!!a.utility.manifest.permissions.kb?.write,"kb.write not granted"),a.utility.manifest.permissions.kb?.kinds&&!a.utility.manifest.permissions.kb.kinds.includes(b.kind))throw Error(`kb kind "${b.kind}" not in manifest allowlist`);let c=await T(a,b.rootId),d=await (0,k.j)({rootPath:c.path,directive:{kind:b.kind,title:b.title,...b.body?{body:b.body}:{},...b.meta?{meta:b.meta}:{},...b.slug?{slug:b.slug}:{},...b.date?{date:b.date}:{}},provenance:{kind:"utility",id:a.utility.manifest.id,version:a.utility.manifest.version}});return{relPath:d.relPath,absPath:d.absPath}}async function z(a,b){S(a.utility.manifest,!!a.utility.manifest.permissions.kb?.read,"kb.read not granted");let c=await T(a,b.rootId),d=await (0,l.dj)(c.path),e=b.query?.toLowerCase();return d.filter(a=>(!b.kind||a.rel.split("/")[0]===b.kind||a.meta.kind===b.kind)&&(!e||!!`${a.rel} ${a.meta.title??""}`.toLowerCase().includes(e))&&!0).map(a=>({relPath:a.rel,title:a.meta.title,kind:a.meta.kind,modifiedAt:a.modifiedAt}))}async function A(a,b){S(a.utility.manifest,!!a.utility.manifest.permissions.kb?.read,"kb.read not granted");let c=await T(a,b.rootId);return{content:await (0,l.IK)(c.path,b.relPath)}}function B(a,b){if(b.startsWith("/")||b.includes(".."))throw Error(`unsafe fs path: ${b}`);let c=g().join(a.utility.dir,"data"),d=g().resolve(c,b),e=g().relative(c,d);if(e.startsWith("..")||g().isAbsolute(e))throw Error(`fs path escapes data dir: ${b}`);return d}async function C(a,b){S(a.utility.manifest,!!a.utility.manifest.permissions.fs?.sandbox,"fs not granted");let c=B(a,b.path);return{content:await e.promises.readFile(c,"utf8")}}async function D(a,b){if(S(a.utility.manifest,!!a.utility.manifest.permissions.fs?.sandbox,"fs not granted"),"string"!=typeof b.content)throw Error("fs.write requires content (string)");let c=B(a,b.path);return await e.promises.mkdir(g().dirname(c),{recursive:!0}),await e.promises.writeFile(c,b.content,"utf8"),{ok:!0,bytes:Buffer.byteLength(b.content,"utf8")}}async function E(a,b){S(a.utility.manifest,!!a.utility.manifest.permissions.fs?.sandbox,"fs not granted");let c=B(a,b.path||".");try{return{entries:(await e.promises.readdir(c,{withFileTypes:!0})).map(a=>({name:a.name,isDir:a.isDirectory()}))}}catch{return{entries:[]}}}async function F(a,b){let c,d=a.utility.manifest.permissions.web?.fetch?.domains??[];try{c=new URL(b.url).hostname}catch{throw Error(`invalid url: ${b.url}`)}if(!d.some(a=>c===a||c.endsWith(`.${a}`)))throw Error(`web.fetch denied: domain "${c}" not in whitelist (${d.join(", ")})`);let e={method:b.method,...b.headers?{headers:b.headers}:{},signal:AbortSignal.timeout(2e4)};void 0!==b.body&&"GET"!==b.method&&(e.body="string"==typeof b.body?b.body:JSON.stringify(b.body));let f=await fetch(b.url,e),g=await f.text(),h={};return f.headers.forEach((a,b)=>{h[b]=a}),{status:f.status,headers:h,body:g}}async function G(a,b){S(a.utility.manifest,!!a.utility.manifest.permissions.web?.search,"web.search not granted");let c=await (0,o.loadSettings)(),d={...c.assignments.quick,allowedTools:Array.from(new Set([...c.assignments.quick.allowedTools??[],"WebSearch"]))},e=`Use the WebSearch tool to find recent results for the query below.
Return ONLY a JSON object on a single line with shape:
  {"results":[{"title":"…","url":"…","snippet":"…"}]}
No prose, no markdown fences. Max 8 results.

Query: ${b.query}`,f=await (0,j.quickComplete)(d,e,{timeoutMs:6e4}),g=/\{[\s\S]*\}/.exec(f);if(!g)return{results:[]};try{return{results:(JSON.parse(g[0]).results??[]).filter(a=>"string"==typeof a.url&&"string"==typeof a.title).map(a=>({title:a.title,url:a.url,...a.snippet?{snippet:a.snippet}:{}}))}}catch{return{results:[]}}}async function H(a,b,c){return S(a.utility.manifest,!!a.utility.manifest.permissions.audit?.write,"audit.write not granted"),await (0,i.u0)({ts:new Date().toISOString(),utilityId:a.utility.manifest.id,scope:a.utility.scope,channel:a.channel,method:`app:${b.type}`,phase:"end",correlationId:c,args:b.payload}),{ok:!0}}async function I(a,b,d){if("worker"===a.channel)throw Error("actions.invoke can only be called from the UI iframe, not from inside a worker");S(a.utility.manifest,!!a.utility.manifest.permissions.workers?.enabled,"workers.enabled not granted");let e=a.utility.manifest.serverActions.find(a=>a.name===b.name);if(!e)throw Error(`unknown server action: ${b.name}`);let{runServerAction:f}=await Promise.resolve().then(c.bind(c,49556));return f({utility:a.utility,action:e,args:b.args,parentCorrelationId:d})}async function J(a,b){S(a.utility.manifest,!!a.utility.manifest.permissions.agent?.invoke,"agent.invoke not granted");let d=await T(a,b.rootId),{runHeadlessAgent:e}=await Promise.resolve().then(c.bind(c,3724));return await e({rootId:d.id,prompt:b.prompt,label:b.label??`[utility ${a.utility.manifest.id}] agent.invoke`,...b.harness?{harness:b.harness}:{},...b.model?{model:b.model}:{},...b.language?{language:b.language}:{},...void 0!==b.timeoutMs?{timeoutMs:b.timeoutMs}:{}})}async function K(a,b){S(a.utility.manifest,!!a.utility.manifest.permissions.workflow?.read,"workflow.read not granted");let d=await T(a,b.rootId),{listWorkflows:e}=await Promise.resolve().then(c.bind(c,73928));return(await e(d.path)).map(a=>({id:a.id,label:a.label,...a.description?{description:a.description}:{},trigger:a.trigger,stepCount:a.steps.length,updatedAt:a.updatedAt}))}async function L(a,b){S(a.utility.manifest,!!a.utility.manifest.permissions.workflow?.read,"workflow.read not granted");let d=await T(a,b.rootId),{readWorkflow:e}=await Promise.resolve().then(c.bind(c,73928)),f=await e(d.path,b.workflowId);if(!f)throw Error(`workflow "${b.workflowId}" not found`);return f}async function M(a,b){S(a.utility.manifest,!!a.utility.manifest.permissions.workflow?.run,"workflow.run not granted");let d=await T(a,b.rootId),{runWorkflow:e}=await Promise.resolve().then(c.bind(c,55143)),f=await e(d.id,b.workflowId,b.input);if(!f.ok)throw Error(f.error);return f.run}async function N(a,b){let d=await T(a,b.rootId),e=b.widgetId??`utility:${a.utility.manifest.id}`,{readWidget:f,writeWidget:g}=await Promise.resolve().then(c.bind(c,69509)),h=await f(d.path,e),i={kind:b.snapshot.kind,data:b.snapshot.data,...b.snapshot.title?{title:b.snapshot.title}:{},...b.snapshot.description?{description:b.snapshot.description}:{}};if(h&&"utility-card"===h.kind){let a=h.data,b={...h,data:{...a,inner:i},updatedAt:new Date().toISOString()};await g(d.path,b)}else throw Error(`cards.update: no utility-card widget for ${a.utility.manifest.id}`);return{ok:!0,widgetId:e}}async function O(a,b){S(a.utility.manifest,!!a.utility.manifest.permissions.images?.generate,"images.generate not granted");let d=await T(a,b.rootId),{generateImage:e}=await Promise.resolve().then(c.bind(c,84579)),f=await e({rootId:d.id,prompt:b.prompt,...b.provider?{provider:b.provider}:{},...b.size?{size:b.size}:{},...b.aspectRatio?{aspectRatio:b.aspectRatio}:{},...b.referenceImageUrls?{referenceImageUrls:b.referenceImageUrls}:{},...b.alt?{alt:b.alt}:{}});return{url:f.urlPath,sha:f.sha,size:f.size,mime:f.mime,provider:f.provider}}async function P(a,b){S(a.utility.manifest,!!a.utility.manifest.permissions.images?.search,"images.search not granted");let{searchImages:d}=await Promise.resolve().then(c.bind(c,84579));return{results:await d({query:b.query,...b.provider?{provider:b.provider}:{},...b.count?{count:b.count}:{}})}}async function Q(a,b){if(S(a.utility.manifest,!!a.utility.manifest.permissions.images?.attach,"images.attach not granted"),a.utility.manifest.permissions.images?.search)try{new URL(b.sourceUrl)}catch{throw Error(`invalid sourceUrl: ${b.sourceUrl}`)}else{let c,d=a.utility.manifest.permissions.web?.fetch?.domains??[];try{c=new URL(b.sourceUrl).hostname}catch{throw Error(`invalid sourceUrl: ${b.sourceUrl}`)}if(!d.some(a=>c===a||c.endsWith(`.${a}`)))throw Error(`images.attach denied: domain "${c}" not in web.fetch whitelist (${d.join(", ")||"(empty)"}). Grant images.search to allow arbitrary search-result URLs.`)}let d=await T(a,b.rootId),{attachRemote:e}=await Promise.resolve().then(c.bind(c,84579)),f=await e({rootId:d.id,sourceUrl:b.sourceUrl});return{url:f.urlPath,sha:f.sha,size:f.size,mime:f.mime}}async function R(a,b){S(a.utility.manifest,!!a.utility.manifest.permissions.images?.search,"images.pickBest requires images.search permission");let d=await T(a,b.rootId),{pickBestImage:e}=await c.e(4066).then(c.bind(c,64066)),f=await e({rootId:d.id,query:b.query,alt:b.alt,context:b.context,candidates:b.candidates});return{pickIndex:f.pickIndex,reason:f.reason,via:f.via}}function S(a,b,c){if(!b)throw Error(`permission denied: ${c}`)}async function T(a,b){let c=b??a.utility.rootId;if(!c)throw Error("no rootId available: project-scoped operation requires a project root");let d=await (0,n.getRoot)(c);if(!d)throw Error(`unknown rootId: ${c}`);return{id:d.id,path:d.path}}let aQ=null;async function U(a,b){let d=b.source.trim();if(!d)return{ok:!1,error:"empty diagram"};let e=function(a){let b=a.split("\n").map(a=>a.trim()).filter(Boolean),c=b[0]??"";if(!["graph","flowchart","sequenceDiagram","classDiagram","stateDiagram","stateDiagram-v2","erDiagram","journey","gantt","pie","gitGraph","mindmap","timeline","quadrantChart","requirementDiagram","C4Context","sankey-beta","xychart-beta","block-beta"].some(a=>c===a||c.startsWith(`${a} `)))return`unrecognised diagram type at line 1: "${c.slice(0,80)}"`;for(let a=1;a<b.length;a++){let c=b[a],d=/\b[A-Za-z0-9_]+\[([^\]]+)\]/.exec(c);if(!d)continue;let e=d[1];if(!(e.startsWith('"')&&e.endsWith('"'))){if(/^[\\/(>{]/.test(e))return`line ${a+1}: node label starts with a shape-modifier character ("${e.slice(0,30)}") — wrap the label in double quotes`;if(/[()\\/{}|]/.test(e))return`line ${a+1}: node label contains special characters ("${e.slice(0,30)}") — wrap the label in double quotes`}}return null}(d);if(e)return{ok:!1,error:e};try{if(!aQ){let a=await c.e(6483).then(c.bind(c,86483)),b=a.default?.parse??a.parse;if("function"!=typeof b)return{ok:!0};aQ=b.bind(a.default??a)}return await aQ(d),{ok:!0}}catch(a){return{ok:!1,error:a instanceof Error?a.message:String(a)}}}async function V(a,b){let{path:d}=await T(a),{createTask:e}=await Promise.resolve().then(c.bind(c,26380));return{id:(await e(d,b)).id}}async function W(a,b){let{path:d}=await T(a),{updateTask:e}=await Promise.resolve().then(c.bind(c,26380));return{ok:!!await e(d,b.id,b.patch)}}async function X(a,b){let{path:d}=await T(a),{deleteTask:e}=await Promise.resolve().then(c.bind(c,26380));return{ok:await e(d,b.id)}}async function Y(a,b){let{path:d}=await T(a),{getTask:e}=await Promise.resolve().then(c.bind(c,26380));return e(d,b.id)}async function Z(a){let{path:b}=await T(a),{listTasks:d}=await Promise.resolve().then(c.bind(c,26380));return{tasks:await d(b)}}async function $(a,b){let{id:d}=await T(a),{dispatchTask:e}=await c.e(9179).then(c.bind(c,99179));return e({rootId:d,taskId:b.id,...b.harness?{harness:b.harness}:{},...b.model?{model:b.model}:{}})}async function _(a,b){let{id:d}=await T(a),{observeTask:e}=await c.e(7220).then(c.bind(c,37220));return e({rootId:d,taskId:b.id})}async function aa(a,b){let{path:d}=await T(a),{updateTask:e}=await Promise.resolve().then(c.bind(c,26380));return{ok:!!await e(d,b.id,{status:b.outcome})}}async function ab(a){let{path:b}=await T(a),{isGitRepo:d}=await c.e(126).then(c.bind(c,60126));return{ok:await d(b)}}async function ac(a){let{path:b}=await T(a),{hasRemote:d}=await c.e(126).then(c.bind(c,60126));return{ok:await d(b)}}async function ad(){let{hasGhCli:a}=await c.e(126).then(c.bind(c,60126));return{ok:await a()}}async function ae(a,b){let{path:d}=await T(a),{createWorktree:e}=await c.e(126).then(c.bind(c,60126));return e({rootPath:d,slug:b.slug,branch:b.branch,...b.baseRef?{baseRef:b.baseRef}:{}})}async function af(a,b){let{path:d}=await T(a),{mergeWorktree:e}=await c.e(126).then(c.bind(c,60126));return e({rootPath:d,branch:b.branch,...b.intoRef?{intoRef:b.intoRef}:{}})}async function ag(a,b){let{path:d}=await T(a),{removeWorktree:e}=await c.e(126).then(c.bind(c,60126));return e({rootPath:d,slug:b.slug,branch:b.branch,force:b.force,deleteBranch:b.deleteBranch})}async function ah(a){let{path:b}=await T(a),{listWorktrees:d}=await c.e(126).then(c.bind(c,60126));return{worktrees:await d(b)}}async function ai(a,b){if(!a.utility.manifest.permissions.sessions?.search)throw Error(`utility "${a.utility.manifest.id}" lacks permissions.sessions.search`);let c={limit:b.limit};return void 0!==b.rootId&&(c.rootId=b.rootId),void 0!==b.source&&(c.source=b.source),void 0!==b.since&&(c.since=b.since),void 0!==b.until&&(c.until=b.until),{hits:await (0,m.iG)(b.query,c)}}d()}catch(a){d(a)}})}};