@synadia-ai/agent-fabric-claude-code 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +4 -4
- package/.mcp.json +14 -0
- package/BUILD +4 -0
- package/LICENSE +18 -17
- package/README.md +52 -441
- package/hooks/hooks.json +31 -0
- package/hooks/session-event.js +11 -0
- package/package.json +23 -72
- package/runtime/chunk-prncr0vg.js +38 -0
- package/runtime/fabric.js +7 -0
- package/runtime/server.js +63 -0
- package/skills/configure/SKILL.md +190 -0
- package/skills/configure/list-contexts.sh +22 -0
- package/CHANGELOG.md +0 -18
- package/dist/index.cjs +0 -277
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -63
- package/dist/index.d.ts +0 -63
- package/dist/index.js +0 -248
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{a as Gt,f as Vt,g as fe,j as Ye,l as Ke,m as he,w as Ze,x as re}from"./chunk-prncr0vg.js";import{AsyncLocalStorage as zt}from"async_hooks";var Zt=Gt(Vt(),1);import{execFile as Xt}from"child_process";import{createHash as Qe,randomUUID as Pe}from"crypto";import{mkdir as Jt,realpath as Wt}from"fs/promises";import{tmpdir as Yt,platform as Le,arch as $e,homedir as qe}from"os";import{join as pe,resolve as Kt}from"path";import{mkdirSync as Qt,readFileSync as er,writeFileSync as tr,renameSync as rr,lstatSync as Fo,realpathSync as yo,openSync as Eo,constants as bo,fsyncSync as wo,closeSync as Ao}from"fs";var nr=1,Ae="TRACE.edges",et="thread_id",tt="root_id";var rt=/[\u0000-\u0020\u007f\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]/;function or(e){if(e===void 0)return;let t=e.edgeSubject;if(t===void 0||t===null)return;let r=(n)=>{throw new fe(`trace.edgeSubject ${JSON.stringify(t)}: ${n}`)};if(typeof t!=="string")r("must be a string or null");if(t.length===0)r("must not be empty");for(let n of t.split(".")){if(n.length===0)r("must not contain an empty token");if(rt.test(n))r("must not contain whitespace or control characters");if(n.includes("*")||n.includes(">"))r("must not contain wildcards")}}var ir=Symbol.for("@synadia-ai/agent-fabric:trace-record-counts"),se=(()=>{let e=globalThis;return e[ir]??={published:0,dropped:0}})();function nt(){se.published+=1}function Fe(){se.dropped+=1}function sr(){return Object.freeze({published:se.published,dropped:se.dropped})}var ar=Symbol.for("@synadia-ai/agent-fabric:trace-scope"),ot=(()=>{let e=globalThis;return e[ar]??=new zt})();function Ce(e,t){return ot.run(e,t)}function X(){return ot.getStore()}var _e=32,ur=new RegExp(`^[0-9a-f]{${_e}}$`);function ye(e){return ur.test(e)}function ge(){let e=new Uint8Array(_e/2);crypto.getRandomValues(e);let t="";for(let r of e)t+=r.toString(16).padStart(2,"0");return t}var cr=256,it=/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/;function Se(e){if(it.test(e))return!1;let t=Array.from(e).length;return t>0&&t<=cr}function dr(e,t,r,n,o,i){let s=ge(),a={version:nr,kind:"edge",record_id:s,ts:Math.floor(Date.now()/1000),agent:e,thread_id:t,parent_id:r,root_id:n,tool_call_id:o,turn_count_hint:i};return{recordId:s,payload:new TextEncoder().encode(JSON.stringify(a))}}var lr="toolCallId";function st(e={}){or(e);let t=e.edgeSubject===void 0?Ae:e.edgeSubject;return{promptInterceptor:fr(t),requestInterceptor:Dr,heartbeatExtras:t===null?()=>({}):()=>{let r=sr();return{records_published:r.published,records_dropped:r.dropped}}}}function fr(e){return{beforePrompt(t){let r=t.context[lr],n=typeof r==="string"&&Se(r)?r:null,o={...hr(),toolCallId:n};return{fields:{[et]:o.threadId,[tt]:o.rootId},state:o}},async beforePublish(t,r){let n=r?.state;if(e===null||n===void 0)return;await pr(t,e,n)}}}function hr(){let e=ge(),t=X();if(t===void 0)return{threadId:e,parentId:null,rootId:e,turnCountHint:0};return{threadId:e,parentId:t.threadId,rootId:t.rootId,turnCountHint:t.turnCountHint}}async function pr(e,t,r){if(!e.identity.canSign){gr(e.connection),Fe();return}try{let n=await e.identity.selfId(),o=dr(n,r.threadId,r.parentId,r.rootId,r.toolCallId,r.turnCountHint);await e.identity.publishSigned(t,o.payload,{nonce:o.recordId}),nt()}catch(n){Fe(),console.warn(`@synadia-ai/agent-fabric: failed to publish edge record on ${t}`,n)}}var Me=new WeakSet;function gr(e){if(Me.has(e))return;Me.add(e),console.warn("@synadia-ai/agent-fabric: tracing is enabled but no identity signer is configured; edge records are not published (consumers ignore unsigned records). Pass identity: { signer } to sign them.")}var Dr={async aroundRequest(e,t){await Ce(vr(e.envelope.extras??{}),t)}},mr="envelope `thread_id` and `root_id` must be given together";function vr(e){let t=Ue(e,et),r=Ue(e,tt);if(t===void 0!==(r===void 0))throw new re(400,mr);if(t!==void 0&&r!==void 0)return{threadId:t,rootId:r,turnCountHint:0};let n=ge();return{threadId:n,rootId:n,turnCountHint:0}}function Ue(e,t){let r=Object.hasOwn(e,t)?e[t]:void 0;if(r===void 0||r===null)return;if(typeof r!=="string")throw new re(400,`envelope \`${t}\` must be a string`);if(r==="")return;if(!ye(r))throw new re(400,`envelope \`${t}\` must be ${_e} lowercase hex characters`);return r}var Fr=1,yr=2,Er=new Set(["claude","openclaw"]),br=new Set(["start","end"]),wr=new Set(["ok","error","timeout"]),Ar=new Set(["final_text","no_reply","shutdown","delivery","expired"]),Cr=256;function at(e){if(typeof e!=="string"||e.length===0)return!1;if(rt.test(e))return!1;if(it.test(e))return!1;return Array.from(e).length<=Cr}function Ee(){return Math.floor(Date.now()/1000)}function _r(e,t,r,n,o,i,s,a=Ee(),l){if(!Er.has(n))throw Error(`buildServedRecord: harness must be "claude" or "openclaw", got ${n}`);if(!br.has(i))throw Error(`buildServedRecord: phase must be "start" or "end", got ${i}`);if(i==="end"&&s===void 0)throw Error("buildServedRecord: an end record needs a status");if(i==="start"&&s!==void 0)throw Error("buildServedRecord: a start record carries no status");if(s!==void 0&&!wr.has(s))throw Error(`buildServedRecord: status must be "ok", "error" or "timeout", got ${s}`);if(i==="start"&&l!==void 0)throw Error("buildServedRecord: a start record carries no reason");if(l!==void 0&&!Ar.has(l))throw Error(`buildServedRecord: reason must be "final_text", "no_reply", "shutdown", "delivery" or "expired", got ${l}`);if(!at(o))throw Error("buildServedRecord: harnessThreadId is not a usable harness thread id");if(!Number.isInteger(a)||a<0)throw Error("buildServedRecord: ts must be a non-negative integer of unix seconds");let f=ge(),h={version:l!==void 0?yr:Fr,kind:"served",record_id:f,ts:a,agent:e,thread_id:t,root_id:r,harness:n,harness_thread_id:o,phase:i,...s!==void 0?{status:s}:{},...l!==void 0?{reason:l}:{}};return{recordId:f,payload:new TextEncoder().encode(JSON.stringify(h))}}var Sr=()=>({debug:()=>{return},info:()=>{return},warn:(e,t)=>console.warn(`@synadia-ai/agent-fabric: ${e}`,t??""),error:(e,t)=>console.error(`@synadia-ai/agent-fabric: ${e}`,t??"")}),Br=class{#e;#t;#r;#n=!1;#o=Promise.resolve();constructor(e){this.#e=e.agents,this.#t=e.subject??Ae,this.#r=e.logger??Sr()}get subject(){return this.#t}beginTurn(e,t){let r=Ee(),n,o=!1;return{bind:(i)=>{if(o){this.#r.warn("served: harness thread id bound after the turn ended; no served record");return}if(n!==void 0){if(i!==n)this.#r.warn("served: harness thread id already bound for this prompt; ignored");return}if(!at(i)){this.#r.warn("served: unusable harness thread id bound; no served record");return}n=i,this.publish(e,t,i,"start",void 0,r)},settle:(i,s,a)=>{if(o)return;if(o=!0,n===void 0)return;let l=s===void 0?Ee():Math.floor(s/1000);this.publish(e,t,n,"end",i,l,a)}}}publish(e,t,r,n,o,i,s){let a=this.#o.then(()=>this.#i(e,t,r,n,o,i,s));return this.#o=a,a}flush(){return this.#o}async#i(e,t,r,n,o,i,s){try{let a=await this.#e.selfId(),l=_r(a,e.threadId,e.rootId,t,r,n,o,i,s);await this.#e.publishSigned(this.#t,l.payload,{nonce:l.recordId}),nt()}catch(a){if(Fe(),Rr(a)){if(this.#n)return;this.#n=!0,this.#r.warn("served: no identity signer is configured; served records are not published (consumers ignore unsigned records). Pass identity: { signer } to sign them.");return}this.#r.warn("served: failed to publish served record",{subject:this.#t,phase:n,reason:a instanceof Error?a.message:String(a)})}}};function Rr(e){return e instanceof Ye||e instanceof Error&&e.name==="SenderSignatureRequiredError"}function ut(e){return new Br(e)}var ae="sp-ref:";var ct=/sp-(?:ref|r1):[A-Za-z0-9_-]+/g,Be="scratchpad_refs_ok";function ue(e){return e.match(ct)??[]}function He(e,t){return e.replace(ct,(r)=>t===void 0||t.includes(r)?"":r).replace(/[ \t]+$/gm,"").replace(/\n{3,}/g,`
|
|
3
|
+
|
|
4
|
+
`).trim()}function xr(e){if(!e.startsWith(ae))return;let t;try{t=JSON.parse(Buffer.from(e.slice(ae.length),"base64url").toString("utf8"))}catch{return}if(typeof t!=="object"||t===null)return;let r=t.creator;return typeof r==="string"&&r!==""?r:void 0}function be(e){return e[Be]==="true"}function ne(e){let t=e.indexOf(".");if(t<=0||t===e.length-1)throw Error(`not an agent identity: ${e}`);return{account:e.slice(0,t),user:e.slice(t+1)}}var dt="sp-grant",kr=1e4,me="agents.prompt.",Tr=`agents.${dt}.`;function lt(e){if(!e.startsWith(me)||e===me)throw Error(`not a prompt address: ${e}`);return Tr+e.slice(me.length)}function Ir(e){let{trace:t}=e;return JSON.stringify({reference:e.reference,grantee:e.grantee,...t!==void 0?{trace:{thread_id:t.thread_id,root_id:t.root_id,...t.tool_call_id!==void 0?{tool_call_id:t.tool_call_id}:{}}}:{}})}function Or(e){return JSON.stringify(e.granted?{granted:!0}:{granted:!1,reason:e.reason})}async function Nr(e,t,r,n={}){let o;try{let a=await e.requestSigned(lt(t),Ir(r),{timeoutMs:n.timeoutMs??kr});o=JSON.parse(a.string())}catch(a){return T(`no answer from ${t}: ${ce(a)}`)}if(typeof o!=="object"||o===null)return T("refused without a reason");let{granted:i,reason:s}=o;if(i===!0)return{granted:!0};return T(typeof s==="string"?s:"refused without a reason")}async function jr(e,t,r,n=he){let o=Lr(t);if(o===void 0)return T("not a grant request");let i,s;try{i=ne(e),s=ne(o.grantee)}catch{return T("grantee is not an agent identity")}let a=o.trace,l=a!==void 0?{threadId:a.thread_id,rootId:a.root_id}:void 0,f=!1;try{f=await r.owns(o.reference)}catch{}if(!f)return T("the reference does not point into this agent's volume");let h;try{h=await r.granted(o.reference,i)}catch(D){return n.error("grant request: the ledger could not be read",{error:ce(D)}),T("the grant could not be made")}if(h===void 0)return T("this agent holds no live read grant it made to the requester on that reference");if(h!=="first-hand")return T("the requester's own grant was made at another agent's request; only an agent this agent handed the reference itself may ask for another");if(s.account===i.account&&s.user===i.user)return T("a grant request is for another agent, not for the requester");try{await r.grantRead(o.reference,s,l,a?.tool_call_id,"on-request")}catch(D){return n.error("grant request: the grant failed",{error:ce(D)}),T("the grant could not be made")}return n.info("grant request: granted",{grantee:o.grantee,requester:e}),{granted:!0}}function Pr(e){let{scratchPad:t}=e,r=e.logger??he,n=new Ze({minSenderTrust:"signed",logger:r});async function o(i){let s=await n.admitPrompt(i);if(!s.ok)return T(s.description);let a=s.sender;if(a?.trust!=="verified")return T("a grant request must be signed");return jr(a.id,i.string(),t,r)}return{name:dt,subject:lt(e.promptAddress),queue:"agents",handler:(i,s)=>{if(i)return;o(s).catch((a)=>(r.error("grant request failed",{error:ce(a)}),T("the grant could not be made"))).then((a)=>{if(!a.granted)r.info("grant request refused",{reason:a.reason});s.respond(Or(a))})}}}function Lr(e){let t;try{t=JSON.parse(e)}catch{return}if(typeof t!=="object"||t===null||Array.isArray(t))return;let{reference:r,grantee:n,trace:o}=t;if(typeof r!=="string"||typeof n!=="string")return;if(typeof o!=="object"||o===null)return{reference:r,grantee:n};let{thread_id:i,root_id:s,tool_call_id:a}=o;if(typeof i!=="string"||typeof s!=="string"||!ye(i)||!ye(s))return{reference:r,grantee:n};return{reference:r,grantee:n,trace:{thread_id:i,root_id:s,...typeof a==="string"&&Se(a)?{tool_call_id:a}:{}}}}function T(e){return{granted:!1,reason:e}}function ce(e){return e instanceof Error?e.message:String(e)}var ft="reads_scratchpad_references",$r=class{requestInterceptor;#e;#t;#r;#n;#o=new Set;#i=new Map;constructor(e){this.#e=e.scratchPad,this.#t=e.agents,this.#r=e.discoverTimeoutMs,this.#n=e.grantRequestTimeoutMs,this.requestInterceptor={aroundRequest:(t,r)=>(this.remember(t.envelope.prompt),r())}}remember(e){for(let t of ue(e))this.#o.add(t)}async grantCaller(e,t){if(this.remember(e),t?.trust!=="verified")return!1;if(!await this.#e.owns(e))throw Error("the reference points into another agent's volume; only its creator grants");return await this.#e.grantRead(e,ne(t.id),Ge(),void 0,"first-hand"),!0}discoveryFields(e){return this.#s(e),{[ft]:be(e.metadata)}}async beforePrompt(e){let{address:t,target:r}=e,n=ue(e.prompt);if(n.length===0)return;if(!be(r.metadata)){let m=He(e.prompt);if(m==="")return{error:`the prompt was not sent: "${t}" does not read ScratchPad references (discover_agents: reads_scratchpad_references is false), and the prompt held nothing but references; put the content they point at into the prompt itself`};return{prompt:m,fields:{references_removed:n.length,note:`"${t}" does not read ScratchPad references: ${n.length} reference(s) were removed from your prompt, it got only the text, and nothing was granted`}}}let o=[...new Set(n)],i=o.filter((m)=>!this.#o.has(m));if(i.length>0)return{error:`the prompt was not sent: ${i.length} of its ScratchPad references (${i[0].slice(0,24)}\u2026) is not one you were given. Copy each reference exactly as you received it, the whole token, or leave it out.`};if(r.identity===void 0||!r.idSigVerified)return{error:`cannot hand a ScratchPad reference to "${t}": its identity is not verified, so no read grant can be issued; put the content in the prompt instead`};let s=ne(r.identity),a=Ge(),l=e.toolCallId!==void 0&&Se(e.toolCallId)?e.toolCallId:void 0,f=[],h="";for(let m of o){try{if(await this.#e.owns(m)){await this.#e.grantRead(m,s,a,l,"first-hand");continue}}catch(x){return{error:`could not grant "${t}" read on ${m.slice(0,32)}\u2026: ${Mr(x)}; the prompt was not sent`}}let w=await this.#a(m,t,r.identity,a,l);if(!w.granted)f.push(m),h=w.reason}if(f.length===0)return;let D=n.filter((m)=>f.includes(m)).length,C=He(e.prompt,f);if(C==="")return{error:`the prompt was not sent: it held nothing but references, and their creator did not grant "${t}" read (${h}); put the content they point at into the prompt itself`};return{prompt:C,fields:{references_removed:D,note:`${D} reference(s) were removed from your prompt, and "${t}" got only the text: you did not create that content, and its creator did not grant "${t}" read (${h}). If it needs the content, put the content itself in a prompt`}}}afterReply(e){this.remember(e.text)}async#a(e,t,r,n,o){let i=xr(e);if(i===void 0&&this.#e.resolveReference)try{i=(await this.#e.resolveReference(e,n)).creator}catch{return{granted:!1,reason:"the reference could not be resolved"}}if(i===void 0)return{granted:!1,reason:"the reference does not name its creator"};if(i===t)return{granted:!0};let s=await this.#u(i);if(s===void 0||!s.idSigVerified)return{granted:!1,reason:`its creator, ${i}, is not on the fabric with a verified identity`};let a={reference:e,grantee:r,...n!==void 0?{trace:{thread_id:n.threadId,root_id:n.rootId,...o!==void 0?{tool_call_id:o}:{}}}:{}};return Nr(this.#t,i,a,this.#n!==void 0?{timeoutMs:this.#n}:{})}async#u(e){let t=this.#i.get(e);if(t!==void 0)return t;try{let r=await this.#t.discover(this.#r!==void 0?{timeoutMs:this.#r}:{});for(let n of r)this.#s(n)}catch{}return this.#i.get(e)}#s(e){let t=this.#i.get(e.promptSubject);if(t===void 0||e.idSigVerified||!t.idSigVerified)this.#i.set(e.promptSubject,e)}};function qr(e){return new $r(e)}function Ge(){let e=X();return e!==void 0?{threadId:e.threadId,rootId:e.rootId}:void 0}function Mr(e){return e instanceof Error?e.message:String(e)}var Ur=class extends Error{code;unknown;local;constructor(e,t,r={}){super(t,r.cause===void 0?void 0:{cause:r.cause});this.name="NativeScratchPadError",this.code=e,this.unknown=r.unknown??!1,this.local=r.local??!1}};function Hr(e,t){return new Ur("invalid",e,{local:!0,cause:t})}var Gr=/[\u0378\u0379\u0380-\u0383\u038B\u038D\u03A2\u0530\u0557\u0558\u058B\u058C\u0590\u05C8-\u05CF\u05EB-\u05EE\u05F5-\u05FF\u070E\u074B\u074C\u07B2-\u07BF\u07FB\u07FC\u082E\u082F\u083F\u085C\u085D\u085F\u086B-\u086F\u088F\u0892-\u0897\u0984\u098D\u098E\u0991\u0992\u09A9\u09B1\u09B3-\u09B5\u09BA\u09BB\u09C5\u09C6\u09C9\u09CA\u09CF-\u09D6\u09D8-\u09DB\u09DE\u09E4\u09E5\u09FF\u0A00\u0A04\u0A0B-\u0A0E\u0A11\u0A12\u0A29\u0A31\u0A34\u0A37\u0A3A\u0A3B\u0A3D\u0A43-\u0A46\u0A49\u0A4A\u0A4E-\u0A50\u0A52-\u0A58\u0A5D\u0A5F-\u0A65\u0A77-\u0A80\u0A84\u0A8E\u0A92\u0AA9\u0AB1\u0AB4\u0ABA\u0ABB\u0AC6\u0ACA\u0ACE\u0ACF\u0AD1-\u0ADF\u0AE4\u0AE5\u0AF2-\u0AF8\u0B00\u0B04\u0B0D\u0B0E\u0B11\u0B12\u0B29\u0B31\u0B34\u0B3A\u0B3B\u0B45\u0B46\u0B49\u0B4A\u0B4E-\u0B54\u0B58-\u0B5B\u0B5E\u0B64\u0B65\u0B78-\u0B81\u0B84\u0B8B-\u0B8D\u0B91\u0B96-\u0B98\u0B9B\u0B9D\u0BA0-\u0BA2\u0BA5-\u0BA7\u0BAB-\u0BAD\u0BBA-\u0BBD\u0BC3-\u0BC5\u0BC9\u0BCE\u0BCF\u0BD1-\u0BD6\u0BD8-\u0BE5\u0BFB-\u0BFF\u0C0D\u0C11\u0C29\u0C3A\u0C3B\u0C45\u0C49\u0C4E-\u0C54\u0C57\u0C5B\u0C5C\u0C5E\u0C5F\u0C64\u0C65\u0C70-\u0C76\u0C8D\u0C91\u0CA9\u0CB4\u0CBA\u0CBB\u0CC5\u0CC9\u0CCE-\u0CD4\u0CD7-\u0CDC\u0CDF\u0CE4\u0CE5\u0CF0\u0CF4-\u0CFF\u0D0D\u0D11\u0D45\u0D49\u0D50-\u0D53\u0D64\u0D65\u0D80\u0D84\u0D97-\u0D99\u0DB2\u0DBC\u0DBE\u0DBF\u0DC7-\u0DC9\u0DCB-\u0DCE\u0DD5\u0DD7\u0DE0-\u0DE5\u0DF0\u0DF1\u0DF5-\u0E00\u0E3B-\u0E3E\u0E5C-\u0E80\u0E83\u0E85\u0E8B\u0EA4\u0EA6\u0EBE\u0EBF\u0EC5\u0EC7\u0ECF\u0EDA\u0EDB\u0EE0-\u0EFF\u0F48\u0F6D-\u0F70\u0F98\u0FBD\u0FCD\u0FDB-\u0FFF\u10C6\u10C8-\u10CC\u10CE\u10CF\u1249\u124E\u124F\u1257\u1259\u125E\u125F\u1289\u128E\u128F\u12B1\u12B6\u12B7\u12BF\u12C1\u12C6\u12C7\u12D7\u1311\u1316\u1317\u135B\u135C\u137D-\u137F\u139A-\u139F\u13F6\u13F7\u13FE\u13FF\u169D-\u169F\u16F9-\u16FF\u1716-\u171E\u1737-\u173F\u1754-\u175F\u176D\u1771\u1774-\u177F\u17DE\u17DF\u17EA-\u17EF\u17FA-\u17FF\u181A-\u181F\u1879-\u187F\u18AB-\u18AF\u18F6-\u18FF\u191F\u192C-\u192F\u193C-\u193F\u1941-\u1943\u196E\u196F\u1975-\u197F\u19AC-\u19AF\u19CA-\u19CF\u19DB-\u19DD\u1A1C\u1A1D\u1A5F\u1A7D\u1A7E\u1A8A-\u1A8F\u1A9A-\u1A9F\u1AAE\u1AAF\u1ACF-\u1AFF\u1B4D-\u1B4F\u1B7F\u1BF4-\u1BFB\u1C38-\u1C3A\u1C4A-\u1C4C\u1C89-\u1C8F\u1CBB\u1CBC\u1CC8-\u1CCF\u1CFB-\u1CFF\u1F16\u1F17\u1F1E\u1F1F\u1F46\u1F47\u1F4E\u1F4F\u1F58\u1F5A\u1F5C\u1F5E\u1F7E\u1F7F\u1FB5\u1FC5\u1FD4\u1FD5\u1FDC\u1FF0\u1FF1\u1FF5\u1FFF\u2065\u2072\u2073\u208F\u209D-\u209F\u20C1-\u20CF\u20F1-\u20FF\u218C-\u218F\u2427-\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\uDC00\uDC02-\uDC1F\uDC80-\uDCFF\uDDF0-\uDFFF]|[\uDBBF\uDBFF][\uDFFE\uDFFF]/;var Vr=524288,ht=921600;var zr=8192,Xr=128,Jr=16384,Wr=131072;var Yr=Vr;var Kr=8,pt=8,Zr=16,Qr=3600,en="AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";var Co=Object.freeze({object_bytes:ht,read_bytes:Yr,control_bytes:Jr,reply_bytes:Wr,writers:Kr,retentions:pt,grants:Zr,grant_seconds:Qr});function E(e,t){if(!e)throw Hr(t)}function De(e,t,r=[]){E(typeof e==="object"&&e!==null&&!Array.isArray(e),"expected JSON object");let n=e;return E(t.every((o)=>Object.hasOwn(n,o)),"required field is absent"),E(Object.keys(n).every((o)=>t.includes(o)||r.includes(o)),"unknown field"),n}function K(e,t=Number.MAX_SAFE_INTEGER,r=0){E(typeof e==="number"&&Number.isSafeInteger(e)&&e>=r&&e<=t,"integer outside its bound")}function oe(e,t,r=0){E(typeof e==="string"&&Buffer.from(e).toString("utf8")===e,"invalid Unicode text"),E(Buffer.byteLength(e)<=t&&Buffer.byteLength(e)>=r,"text outside its byte bound")}function gt(e){E(typeof e==="string"&&/^[A-Za-z0-9_-]{43}$/.test(e),"invalid content identity");let t=Buffer.from(e,"base64url");E(t.length===32&&t.toString("base64url")===e,"noncanonical content identity")}function tn(e,t){E(typeof e==="string"&&/^[A-Z2-7]{56}$/.test(e),"invalid public NKEY");let r="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",n=0,o=0,i=[];for(let a of e)if(o=o<<5|r.indexOf(a),n+=5,n>=8)n-=8,i.push(o>>>n&255);E(i.length===35&&i[0]===(t==="account"?0:160),"wrong NKEY kind");let s=0;for(let a of i.slice(0,33)){s^=a<<8;for(let l=0;l<8;l++)s=(s<<1^(s&32768?4129:0))&65535}E(i[33]===(s&255)&&i[34]===s>>>8,"NKEY checksum differs")}function Dt(e){oe(e,255,1),E(e!=="."&&e!==".."&&!/[\x00-\x1f\x7f/]/.test(e),"forbidden entry name"),E(rn(e)===e,"entry name is not NFC")}function rn(e){let t="",r="";for(let n of e)if(Gr.test(n))t+=r.normalize("NFC")+n,r="";else r+=n;return t+r.normalize("NFC")}function nn(e,t=4096){if(oe(e,t,1),E(e.startsWith("/"),"path must be absolute"),e==="/")return;let r=e.slice(1).split("/");E(r.length<=Xr,"path exceeds its depth bound");for(let n of r)Dt(n)}function on(e){E(typeof e==="string"&&/^[0-9A-Za-z]{1,64}$/.test(e),"invalid volume name")}function mt(e){let t=De(e,["volume","creation_id"]);on(t.volume),E(typeof t.creation_id==="string"&&/^[0-9a-f]{32}$/.test(t.creation_id),"invalid volume creation identity")}function sn(e){let t=De(e,["slot","generation"]);K(t.slot,pt-1),K(t.generation,void 0,1)}function vt(e,t){if(e===t)return!0;if(!e||!t||typeof e!=="object"||typeof t!=="object")return!1;let r=e,n=t;return Object.keys(r).length===Object.keys(n).length&&Object.keys(r).every((o)=>Object.hasOwn(n,o)&&vt(r[o],n[o]))}function an(e,t=!0){let r=JSON.stringify(e);return E(r!==void 0,"value cannot be encoded as JSON"),r=r.replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029"),t?r.replace(/</g,"\\u003c").replace(/>/g,"\\u003e").replace(/&/g,"\\u0026"):r}var un=class extends Error{constructor(e,t){super(t);this.reason=e,this.name="CodecError"}reason};function j(e,t){throw new un(e,t)}function cn(e,t){return Qe("sha256").update(e).update("\x00").update(t).digest("base64url")}function dn(e){return cn("scratchpad:v1:tree",e)}function V(e,t){if(K(t),t<24)return Buffer.from([e<<5|t]);if(t<=255)return Buffer.from([e<<5|24,t]);if(t<=65535){let n=Buffer.alloc(3);return n[0]=e<<5|25,n.writeUInt16BE(t,1),n}if(t<=4294967295){let n=Buffer.alloc(5);return n[0]=e<<5|26,n.writeUInt32BE(t,1),n}let r=Buffer.alloc(9);return r[0]=e<<5|27,r.writeBigUInt64BE(BigInt(t),1),r}function ln(e){return Buffer.concat([V(2,e.length),e])}function H(e){let t=Buffer.from(e);return Buffer.concat([V(3,t.length),t])}function fn(e){if(typeof e!=="string"||Buffer.from(e).toString("utf8")!==e)j("utf8","invalid entry name UTF-8");if(Buffer.byteLength(e)===0||Buffer.byteLength(e)>255)j("name-length","entry name length exceeds bound");if(e==="."||e===".."||/[\x00-\x1f\x7f/]/.test(e))j("name-forbidden","forbidden entry name");try{Dt(e)}catch{j("not-nfc","entry name is not NFC")}}function hn(e){if(fn(e.name),e.type==="symlink"){if(e.executable||e.object!==void 0&&e.object!==en)j("type-invalid","symlink has file fields");let t=e.linkTarget??"";if(typeof t!=="string"||Buffer.from(t).toString("utf8")!==t)j("utf8","invalid symlink UTF-8");if(Buffer.byteLength(t)===0||Buffer.byteLength(t)>4096||t.includes("\x00"))j("target-invalid","invalid symlink target")}else{if(e.type!=="file"&&e.type!=="directory")j("type-invalid","unknown entry type");if(gt(e.object),e.linkTarget||e.type==="directory"&&e.executable)j("type-invalid","entry has fields of another type")}}function pn(e){for(let o of e)hn(o);let t=[...e].sort((o,i)=>Buffer.compare(Buffer.from(o.name),Buffer.from(i.name)));for(let o=1;o<t.length;o++)if(t[o].name===t[o-1].name)j("duplicate-name","duplicate tree entry");if(e.length>zr)j("entry-count","tree entry count exceeds bound");let r=[V(5,1),H("e"),V(4,e.length)],n=r.reduce((o,i)=>o+i.length,0);for(let o of t){let i=[V(5,o.executable?4:3)];if(o.type==="symlink")i.push(H("l"),H(o.linkTarget));else i.push(H("i"),ln(Buffer.from(o.object,"base64url")));if(i.push(H("n"),H(o.name),H("t"),V(0,o.type==="file"?0:o.type==="directory"?1:2)),o.executable)i.push(H("x"),V(0,1));if(n+=i.reduce((s,a)=>s+a.length,0),n>ht)j("node-size","tree node byte count exceeds bound");r.push(...i)}return Buffer.concat(r)}dn(pn([]));function Ft(e){let t=De(e,["version","creator","account","target","root","generation","path","retention","expires_at"]);E(t.version===2,"reference version must be two"),oe(t.creator,512,1),tn(t.account,"account"),mt(t.target),gt(t.root),K(t.generation,void 0,1),nn(t.path,256),sn(t.retention),K(t.expires_at,void 0,1)}function gn(e){Ft(e);let t={version:2,creator:e.creator,account:e.account,target:{volume:e.target.volume,creation_id:e.target.creation_id},root:e.root,generation:e.generation,path:e.path,retention:{slot:e.retention.slot,generation:e.retention.generation},expires_at:e.expires_at},r="sp-ref:"+Buffer.from(an(t,!1)).toString("base64url");return E(Buffer.byteLength(r)<=16384,"reference exceeds byte bound"),r}var we="sp-r1:",de=66;function yt(e){oe(e,de,de),E(/^sp-r1:[A-Za-z0-9_-]{60}$/.test(e),"malformed short reference");let t=Buffer.from(e.slice(we.length),"base64url");E(t.length===45&&t[32]<64,"invalid short reference slots");let r=Number(t.readBigUInt64BE(24));K(r,void 0,1);let n={route:t.subarray(0,8).toString("hex"),creation_id:t.subarray(8,24).toString("hex"),retention:{slot:t[32]>>3,generation:r},path_index:t[32]&7};return mt({volume:"Reference",creation_id:n.creation_id}),n}function Dn(e,t){return Qe("sha256").update(`scratchpad-reference-volume-v1\x00${e}\x00${t}`).digest().subarray(0,8).toString("hex")}function mn(e){let t=De(e,["short","expanded"]);oe(t.short,de,de);let r=yt(t.short);Ft(t.expanded),E(r.route===Dn(t.expanded.account,t.expanded.target.volume)&&r.creation_id===t.expanded.target.creation_id&&vt(r.retention,t.expanded.retention),"short reference binding differs")}var vn="sp",Fn=600,Ve=600,yn=5,ze=16,En=16384,Et=16777216,bn=Math.ceil(Et/3)*4+65536,wn=262144,An=65536,bt=/^A[A-Z2-7]{55}$/,Cn=/^[0-9A-Za-z]{1,64}$/,_n=/^[0-9a-f]{32}$/,Sn=/^[A-Za-z0-9_-]{43}$/,Bn=/^[A-Za-z0-9_-]+$/,Rn=/^[A-Za-z0-9+/]*={0,2}$/,F=class extends Error{constructor(e,t,r){super(e);this.code=t,this.unknown=r,this.name="ScratchPadError"}code;unknown},k=(e)=>typeof e==="object"&&e!==null&&!Array.isArray(e),le=(e,t)=>Object.keys(e).length===t.length&&t.every((r)=>(r in e)),te=(e)=>Number.isSafeInteger(e)&&e>0,wt=(e)=>Buffer.byteLength(e,"utf8");function At(e){return k(e)&&le(e,["volume","creation_id"])&&typeof e.volume==="string"&&Cn.test(e.volume)&&typeof e.creation_id==="string"&&_n.test(e.creation_id)}function xn(e){if(typeof e!=="string"||!e.startsWith("/")||wt(e)>256)return!1;if(e==="/")return!0;return e.slice(1).split("/").every((t)=>t!==""&&t!=="."&&t!=="..")}function ve(e){let t=(s)=>{throw Error(`malformed ScratchPad reference: ${s}`)};if(typeof e!=="string"||!e.startsWith(ae))t("no sp-ref: prefix");if(e.length>En)t("longer than 16 KiB");let r=e.slice(ae.length);if(!Bn.test(r)||r.length%4===1)t("not unpadded base64url");let n;try{n=JSON.parse(Buffer.from(r,"base64url").toString("utf8"))}catch{t("not JSON")}let o=["version","creator","account","target","root","generation","path","retention","expires_at"];if(!k(n)||!le(n,o))return t("not the version 2 fields");let i=n.retention;if(n.version!==2||typeof n.creator!=="string"||n.creator.length===0||wt(n.creator)>512||typeof n.account!=="string"||!bt.test(n.account)||!At(n.target)||typeof n.root!=="string"||!Sn.test(n.root)||!te(n.generation)||!xn(n.path)||!k(i)||!le(i,["slot","generation"])||!Number.isSafeInteger(i.slot)||i.slot<0||i.slot>7||!te(i.generation)||!te(n.expires_at))t("a field is out of shape");return n}var G=()=>Math.floor(Date.now()/1000),Xe=8,kn=16,Tn=["close","apply","release","grant"],In=["workspace","not_found"],z=(e)=>Number.isSafeInteger(e)&&e>=0;function On(e){let t=(f)=>{throw new F(`sp describe: ${f}`,"malformed_reply",!1)};if(!k(e)||!k(e.volume))return t("the reply names no volume");let{volume:r,control:n}=e,o;if(n!==null&&n!==void 0){if(!k(n)||typeof n.kind!=="string"||!Tn.includes(n.kind))return t("the saved control request is out of shape");o=n.kind}if(typeof r.closed!=="boolean")return t("the volume names no closed state");let{retentions:i,grants:s}=r;if(!Array.isArray(i)||i.length!==Xe)return t("not eight retention slots");if(!Array.isArray(s)||s.length!==kn)return t("not sixteen grant slots");let a=i.map((f)=>{if(!k(f)||!z(f.generation))return t("a retention slot is out of shape");let h=f.pin;if(h===void 0||h===null)return{generation:f.generation,until:void 0};if(!k(h)||!z(h.until)||typeof h.root!=="string")return t("a retention pin is out of shape");return{generation:f.generation,until:h.until}}),l=[];for(let f of s){if(!k(f)||!z(f.generation))return t("a grant slot is out of shape");let h=f.grant;if(h===void 0||h===null)continue;let D=k(h)?h.retention:void 0;if(!k(h)||!z(h.until)||!k(D)||!z(D.slot)||D.slot>=Xe||!te(D.generation))return t("a grant is out of shape");l.push({slot:D.slot,generation:D.generation,until:h.until})}return{closed:r.closed,control:o,retentions:a,grants:l}}function Nn(e){let t=(o)=>{throw new F(`sp spool-remove: ${o}`,"malformed_reply",!1)};if(!k(e)||typeof e.present!=="boolean")return t("the reply says no spool state");let r=e.present,n=["present","files","bytes","removable","applied"];if(r)n.push("phase");if(!le(e,n)||r&&(typeof e.phase!=="string"||e.phase==="")||!z(e.files)||!z(e.bytes)||typeof e.removable!=="boolean"||typeof e.applied!=="boolean")return t("the spool state is out of shape");return{present:r,removable:e.removable,applied:e.applied}}function jn(e,t=G()){let r=e.control==="close"||e.control==="apply";if(e.closed&&!r)return"the volume is closed, and no cleanup of this agent's is saved";if(r)return;return e.retentions.some((o,i)=>o.until===void 0||o.until!==0&&o.until<=t&&!e.grants.some((s)=>s.slot===i&&s.generation===o.generation&&s.until>t))?void 0:"every retention slot holds a live pin"}function Pn(e){if(!("creds"in e.nats)||e.nats.creds===void 0)throw Error("ScratchPad: the sp CLI needs NATS_URL and NATS_CREDS; a NATS context or an nkey seed alone is not supported");let t=["--url",e.nats.url,"--creds",e.nats.creds],r=e.bin??vn,n=e.dir??pe(Yt(),`scratchpad-${e.volume}`),o=Math.min(e.grantTtlS??Ve,Ve),i,s,a=Promise.resolve(),l=!0,f,h=new Map;function D(u){let d=a.then(u);return a=d.catch(()=>{return}),d}let C=new Map;async function m(u,d){if(!u.startsWith(we))return ve(u);yt(u);let c=C.get(u);if(c&&c.expires_at>G())return structuredClone(c);let p=await x("resolve",["--ref",u],{trace:d}),S={short:u,expanded:p?.reference};if(mn(S),p.full_reference!==gn(S.expanded))throw new F("sp resolve: expanded token differs from descriptor","malformed_reply",!1);let y=ve(p.full_reference);if(y.expires_at<=G())throw Error("the reference has expired");if(C.delete(u),C.set(u,y),C.size>64)C.delete(C.keys().next().value);return structuredClone(y)}async function w(){return i??=(async()=>(await Jt(n,{recursive:!0,mode:448}),Wt(n)))(),i}async function x(u,d,c={}){let p=c.trace?["--thread-id",c.trace.threadId,"--root-id",c.trace.rootId]:[];if(c.trace&&c.toolCallId!==void 0)p.push("--tool-call-id",c.toolCallId);let S=["read","resolve"].includes(u)?[]:["--volume",e.volume],y=[u,...t,"--dir",await w(),...S,...d,...p],O=c.maxStdout??wn,{code:N,stdout:B,stderr:P}=await new Promise((b)=>{Xt(r,y,{maxBuffer:Math.max(O,An),encoding:"utf8"},(Mt,Ut,Ht)=>{let Y=Mt;b({code:Y===null?0:typeof Y.code==="number"?Y.code:null,stdout:Ut??"",stderr:Ht||(Y!==null&&typeof Y.code==="string"?Y.message:"")})}).stdin?.end(c.stdin??"")});if(N===null&&/^spawn .*(ENOENT|EACCES)/m.test(P))throw new F(`sp ${u}: ${P.trim()}`,"spawn_failed",!1);if(N===0&&B.length<=O)try{return JSON.parse(B)}catch{}let A={code:N===0?"malformed_reply":"failed",message:P.trim().slice(0,512)||`exit ${N??"by signal"}`,unknown:c.mutation===!0};if(N!==0)try{let b=JSON.parse(P).error;if(k(b)&&typeof b.code==="string")A={code:b.code,message:typeof b.message==="string"?b.message:"",unknown:b.unknown===!0||c.mutation===!0&&typeof b.unknown!=="boolean"}}catch{}throw new F(`sp ${u}: ${A.code}${A.unknown?" (outcome unknown)":""}: ${A.message}`,A.code,A.unknown)}function M(u,d){let c=u,p=c?.principal?.account;if(typeof p!=="string"||!bt.test(p)||!At(c.target))throw new F(`sp ${d}: the reply names no principal and target`,"malformed_reply",!1);if(c.target.volume!==e.volume)throw new F(`sp ${d}: the workspace is bound to another volume`,"invalid",!1);return{account:p,target:{volume:c.target.volume,creation_id:c.target.creation_id}}}async function U(u){return s??=M(await x("init",[],{trace:u,mutation:!0}),"init"),s}async function g(u){if(s!==void 0)return s;try{s=M(await x("describe",[],{trace:u}),"describe")}catch(d){if(d instanceof F&&In.includes(d.code))return;throw d}return s}let v=(u,d)=>d!==void 0&&u.account===d.account&&u.target.volume===d.target.volume&&u.target.creation_id===d.target.creation_id,_=(u,d)=>JSON.stringify([u.account,u.target.volume,u.target.creation_id,u.root,u.path,d.account,d.user]);function I(){let u=G();for(let[d,c]of h)if(Math.max(c["first-hand"]??0,c["on-request"]??0)<=u)h.delete(d)}function q(u,d,c){h.set(u,{...h.get(u),[d]:c})}function J(u,d){let c=u;if(!k(c)||!k(c.handle)||!te(c.expires_at))throw new F("sp grant: the reply names no handle and expiry","malformed_reply",!0);return Math.min(c.expires_at,d.expires_at)}async function Z(u,d,c,p){return x("publish-file",["--source","-","--path",d,"--operation-id",c,"--creator",e.creator,"--ttl-seconds",String(Fn)],{trace:p,stdin:u,mutation:!0})}async function W(u){if(!l)return;try{await x("recover",[],{trace:u,mutation:!0})}catch(d){if(!(d instanceof F)||d.unknown)throw d}l=!1}async function Q(u,d){let c;try{let p=Nn(await x("spool-remove",["--apply"],{trace:d,mutation:!0}));if(!p.present||p.applied)return;c="the refused publication's spool is protected"}catch(p){if(p instanceof F&&p.unknown)throw p;c=`its spool was not removed: ${p.message}`}throw l=!0,new F(`${u.message}; cleanup not started: ${c}`,u.code,!1)}async function Lt(u){return On(await x("describe",[],{trace:u}))}async function $t(u,d,c){if(e.creator===void 0)throw Error("ScratchPad: a reference names its creator; this ScratchPad was made without one");let p=await U(c);await W(c);let S=Pe(),y;try{y=await Z(u,d,S,c)}catch(B){if(B instanceof F&&B.unknown)l=!0;if(!(B instanceof F)||B.code!=="capacity"||B.unknown)throw B;await Q(B,c);let P;try{P=jn(await Lt(c))}catch(A){throw new F(`${B.message}; cleanup not started: ${A.message}`,B.code,!1)}if(P!==void 0)throw new F(`${B.message}; cleanup not started: ${P}`,B.code,!1);try{await x("maintain",["--apply"],{trace:c,mutation:!0})}catch(A){l=!0;let b=!(A instanceof F)||A.unknown;throw new F(`${B.message}; cleanup: ${A.message}`,b&&A instanceof F?A.code:b?"failed":B.code,b)}try{y=await Z(u,d,S,c)}catch(A){if(A instanceof F&&A.unknown)l=!0;throw A}}let O=y?.reference;if(typeof O!=="string"||!k(y.receipt))throw l=!0,new F("sp publish-file: the reply names no receipt and reference","malformed_reply",!0);let N=await m(O,c);if(!v(N,p)||N.path!==d||N.creator!==e.creator)throw new F("sp publish-file: the reference names another volume, path or creator","malformed_reply",!1);return O}async function je(u,d,c,p){return J(await x("grant",u,{trace:d,toolCallId:c,mutation:!0}),p)}async function qt(u,d,c,p,S){let y=await m(u,c);if(!v(y,await g(c)))throw Error("the reference points into another agent's volume; only its creator can grant read on it");if(await W(c),f!==void 0){let b=f;try{q(b.key,b.kind,await je(b.args,void 0,void 0,b.ref)),f=void 0}catch(ie){if(!(ie instanceof F)||ie.unknown)throw ie;f=void 0}}let O=y.expires_at-G()-yn,N=Math.floor(Math.min(o,O));if(N<1)throw Error("the reference has expired, or is about to; there is nothing left to grant on");let B=_(y,d);if(I(),!h.has(B)&&h.size>=ze)throw Error(`this agent already holds ${ze} live grants; try again when one expires`);let P=c?["--thread-id",c.threadId,"--root-id",c.rootId]:[];if(c&&p!==void 0)P.push("--tool-call-id",p);let A=["--ref",u,"--grantee-account",d.account,"--grantee-user",d.user,"--operation-id",Pe(),"--ttl-seconds",String(N)];try{q(B,S,await je(A,c,p,y))}catch(b){if(b instanceof F&&b.unknown)f={args:[...A,...P],key:B,kind:S,ref:y};throw b}}return{commit(u,d,c){return D(()=>$t(u,d,c))},async read(u,d){if((await m(u,d)).expires_at<=G())throw Error("the reference has expired");let p=await x("read",["--ref",u],{trace:d,maxStdout:bn}),{data_base64:S,bytes:y}=p??{};if(typeof S!=="string"||!Rn.test(S)||!Number.isSafeInteger(y)||y>Et)throw new F("sp read: the reply carries no data","malformed_reply",!1);let O=Buffer.from(S,"base64");if(O.length!==y||O.toString("base64")!==S)throw new F("sp read: the data does not match its length","malformed_reply",!1);try{return new TextDecoder("utf-8",{fatal:!0}).decode(O)}catch{throw Error("the referenced file is not UTF-8 text")}},resolveReference:m,async owns(u){let d;try{d=await m(u)}catch{return!1}return v(d,await g(X()))},grantRead(u,d,c,p,S="first-hand"){return D(()=>qt(u,d,c,p,S))},granted(u,d){let c=(p)=>{if(!v(p,s))return;let S=h.get(_(p,d)),y=G();if((S?.["first-hand"]??0)>y)return"first-hand";if((S?.["on-request"]??0)>y)return"on-request";return};if(u.startsWith(we))return m(u).then(c,()=>{return});try{return c(ve(u))}catch{return}}}}var Ln="SCRATCHPAD_VOLUME",$n="SCRATCHPAD_BIN",qn="SCRATCHPAD_DIR";var Mn=409;function Un(e){return`the agent's model is waiting inside a prompt of this tree (root ${e}); a prompt of the same tree cannot be served until that call returns`}function Hn(e){if(typeof e!=="object"||e===null||Array.isArray(e))return;let t=e.open_calls;if(t===void 0)return 0;return typeof t==="number"&&Number.isInteger(t)&&t>=0?t:void 0}function Gn(e){return(typeof e==="object"||typeof e==="function")&&e!==null&&typeof e.then==="function"}function Ct(){let e=new Map,t=new Map,r=(o)=>{let i=t.get(o);if(i===void 0)return!1;for(let s of i)if(s.waiting)return!0;return!1},n=(o,i,s)=>{o.running-=1;let a=i?Hn(s):void 0;if(a===void 0)return;if(o.open=a,o.running===0&&o.open===0)o.waiting=!1};return{requestInterceptor:{async aroundRequest(o,i){let s=X();if(s===void 0){await i();return}let{rootId:a}=s;if(r(a))throw new re(Mn,Un(a));let l={rootId:a,waiting:!1,running:0,open:0};e.set(s,l);let f=t.get(a);if(f===void 0)t.set(a,f=new Set);f.add(l);try{await i()}finally{if(e.delete(s),f.delete(l),f.size===0)t.delete(a)}}},promptInterceptor:{beforePrompt(){let o=X(),i=o===void 0?void 0:e.get(o);if(i!==void 0)i.waiting=!0}},aroundToolCall(o,i){let s=o===void 0?void 0:e.get(o);if(s===void 0)return i();s.running+=1;let a;try{a=i()}catch(l){throw n(s,!1),l}if(Gn(a))a.then((l)=>n(s,!0,l),()=>n(s,!1));else n(s,!0,a);return a},serving:(o)=>t.has(o),waiting:r}}var Vn=Symbol.for("synadia.fabric.scratchpad.workspace-owners.v1"),zn=globalThis,_o=zn[Vn]??=new Set;var Je="edgeSubject",Xn="SYNADIA_FABRIC_EDGE_SUBJECT";function _t(e,t=process.env){if(Object.hasOwn(e,Je))return e[Je];let r=t[Xn];if(r!==void 0)return r;return Ae}var St="scratchpad",R={url:"SP_NATS_URL",creds:"SP_NATS_CREDS",dir:qn,volume:Ln,creator:"SP_CREATOR",threadId:"SP_THREAD_ID",rootId:"SP_ROOT_ID",callerAccount:"SP_CALLER_ACCOUNT",callerUser:"SP_CALLER_USER",grants:"SP_GRANTS_FILE"};async function Re(e,t){let r=e.logger,n=e.options[St],o=n!==null&&typeof n==="object"?n:{},i=(D,C)=>{let m=o[D];if(typeof m==="string"&&m!=="")return m;let w=t[C];return w===void 0||w===""?void 0:w},s=i("volume",R.volume);if(s===void 0)return;let a=i("url","NATS_URL"),l=i("creds","NATS_CREDS");if(a===void 0||l===void 0){let D=t.NATS_CONTEXT||ee(e.settings.config.context);if(D!==void 0)try{let{fields:C}=await Ke(D);a??=ee(C.url),l??=ee(C.creds)}catch(C){r.warn(`agent-fabric: ScratchPad is off: the NATS context "${D}" could not be read (${String(C)})`);return}}if(a??=ee(e.settings.config.url),l??=ee(e.settings.config.credentials),a===void 0||l===void 0){r.warn("agent-fabric: ScratchPad is off: sp needs a NATS URL and a credentials file (options.scratchpad, NATS_URL and NATS_CREDS, a NATS context with both, or url and credentials in the plugin's configuration)");return}let f=i("dir",R.dir);if(f===void 0&&e.settings.stateDir!==void 0)f=pe(e.settings.stateDir,"scratchpad");if(f!==void 0){f=Kt(We(f));try{Qt(f,{recursive:!0,mode:448})}catch(D){r.warn(`agent-fabric: ScratchPad workspace ${f} could not be created (${String(D)})`)}}let h=f!==void 0?`${f}.grants`:void 0;if(h!==void 0)Wn(h,r);return{url:a,creds:We(l),volume:s,...f!==void 0?{dir:f}:{},...h!==void 0?{grants:h}:{}}}function xe(e,t){if(t[R.url]=e.url,t[R.creds]=e.creds,t[R.volume]=e.volume,e.dir!==void 0)t[R.dir]=e.dir;if(e.grants!==void 0)t[R.grants]=e.grants}var ke=class{constructor(e){this.env=e}env;#e;enter(e,t){if(this.#t(),this.#e=e.id,t!==void 0)this.env[R.threadId]=t.threadId,this.env[R.rootId]=t.rootId;if(e.caller!==void 0)try{let r=ne(e.caller);this.env[R.callerAccount]=r.account,this.env[R.callerUser]=r.user}catch{}}leave(e){if(this.#e===e.id)this.#t(),this.#e=void 0}#t(){delete this.env[R.threadId],delete this.env[R.rootId],delete this.env[R.callerAccount],delete this.env[R.callerUser]}};function Bt(e,t){let r=e[$n];if(r!==void 0&&r!=="")return r;let n=Le()==="darwin"?"darwin":Le()==="linux"?"linux":void 0,o=$e()==="arm64"?"arm64":$e()==="x64"?"amd64":void 0;if(n===void 0||o===void 0)return;return pe(t,"bin",`sp-${n}-${o}`)}var Te=class{#e;#t;#r=[];requestInterceptor={aroundRequest:(e,t)=>{if(this.#e===void 0)this.#r.push(e.envelope.prompt);else this.#e.remember(e.envelope.prompt);return t()}};start(e){let{scratchPad:t,agents:r,service:n}=e;this.#t=t,this.#e=qr({scratchPad:t,agents:r});for(let s of this.#r.splice(0))this.#e.remember(s);if(n===void 0)return;let o=e.logger??he,i=Pr({promptAddress:n.subject.prompt,scratchPad:t,logger:o});try{n.service.addEndpoint(i.name,{subject:i.subject,...i.queue!==void 0?{queue:i.queue}:{},handler:i.handler})}catch(s){o.warn(`agent-fabric: grant requests are not answered: ${String(s)}`)}}discoveryFields(e){return this.#e?.discoveryFields(e)??{[ft]:be(e.metadata)}}async beforePrompt(e){let t=this.#e,r=this.#t;if(t===void 0||r===void 0){if(ue(e.prompt).length===0)return;return{error:"the prompt was not sent: ScratchPad is not ready yet; try again in a moment"}}for(let n of new Set(ue(e.prompt)))if(await r.owns(n))t.remember(n);return t.beforePrompt(e)}afterReply(e){this.#e?.afterReply(e)}};function Rt(e,t,r,n){let o=Bt(r,n);if(o===void 0)return;let i=Pn({volume:e.volume,nats:{url:e.url,creds:e.creds},bin:o,creator:t,...e.dir!==void 0?{dir:e.dir}:{}});return e.grants!==void 0?Yn(i,e.grants):i}var Jn=/^(\d+) (\S+) (\S+) (sp-(?:ref|r1):[A-Za-z0-9_-]+)$/;function xt(e){let t;try{t=er(e,"utf8")}catch{return[]}let r=[];for(let n of t.split(`
|
|
5
|
+
`)){let o=Jn.exec(n);if(o===null)continue;r.push({expiresAt:Number(o[1]),grantee:{account:o[2],user:o[3]},reference:o[4]})}return r}function Wn(e,t){let r=Math.floor(Date.now()/1000),n=xt(e).filter((o)=>o.expiresAt>r);try{let o=`${e}.${process.pid}.tmp`;tr(o,n.map((i)=>`${i.expiresAt} ${i.grantee.account} ${i.grantee.user} ${i.reference}
|
|
6
|
+
`).join(""),{mode:384}),rr(o,e)}catch(o){t.warn(`agent-fabric: ScratchPad grants file ${e} could not be written (${String(o)})`)}}function Yn(e,t,r=()=>Date.now()/1000){return{...e.resolveReference?{resolveReference:(n,o)=>e.resolveReference(n,o)}:{},owns:(n)=>e.owns(n),grantRead:(n,o,i,s,a)=>e.grantRead(n,o,i,s,a),async granted(n,o){let i=await e.granted(n,o);if(i==="first-hand")return i;let s=r();return xt(t).some((l)=>l.reference===n&&l.grantee.account===o.account&&l.grantee.user===o.user&&l.expiresAt>s)?"first-hand":i}}}function ee(e){return typeof e==="string"&&e!==""?e:void 0}function We(e){if(e==="~")return qe();if(e.startsWith("~/"))return pe(qe(),e.slice(2));return e}import{mkdirSync as Kn,renameSync as Zn,rmSync as Qn,writeFileSync as eo}from"fs";import{dirname as to,join as ro}from"path";import{fileURLToPath as no}from"url";var oo=no(new URL("../skills/scratchpad",import.meta.url));function kt(e,t,r){return Rt(e,t,r,oo)}function Tt(e,t,r=process.ppid){let n=t.CLAUDE_PID;return ro(e,"agent-fabric",`${n!==void 0&&/^\d+$/.test(n)?n:String(r)}.env`)}var io=new Set(Object.values(R));class Ie{path;vars={};constructor(e){this.path=e}write(){let e="";for(let[r,n]of Object.entries(this.vars)){if(!io.has(r)||n===void 0||/[\r\n]/.test(n))continue;e+=`${r}=${n}
|
|
7
|
+
`}Kn(to(this.path),{recursive:!0,mode:448});let t=`${this.path}.${process.pid}.tmp`;eo(t,e,{mode:384}),Zn(t,this.path)}remove(){Qn(this.path,{force:!0})}}var L="agent-fabric",It="claude",Ot=120000,Nt=`${L}: senderIdentity is off; trace records are signed, so none will be published and each counts as dropped on the heartbeat. Set senderIdentity to signed.`,jt=`${L}: no Claude Code session id known for this prompt, so no served pair; its model calls stand as a harness thread of their own. Are the plugin's hooks registered?`,so=/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/;function Oe(e){return typeof e==="string"&&so.test(e)}function ao(e){let t=e.stopWaitMs;if(t===void 0)return Ot;if(typeof t!=="number"||!Number.isFinite(t)||t<0)throw new fe(`${L}: options.stopWaitMs must be a number of ms \u2265 0`);return t}async function Ne(e,t=process.env){return Pt(e,t,await Re(e,t))}function Pt(e,t=process.env,r){let n=_t(e.options,t),o=ao(e.options),i=st({edgeSubject:n}),s=Ct(),a=e.logger,l,f,h=new Map,D=[],C=(g)=>{let v=D.indexOf(g);if(v>=0)D.splice(v,1);clearTimeout(g.timer)},m=!1,w;if(r!==void 0)if(e.settings.stateDir!==void 0)w=new Ie(Tt(e.settings.stateDir,t));else a.warn(`${L}: the plugin names no state directory, so the skill's scripts/sp gets no ScratchPad settings`);let x=()=>{if(w===void 0)return;try{w.write()}catch(g){a.warn(`${L}: ScratchPad's settings for scripts/sp: ${String(g)}`)}};if(r!==void 0&&w!==void 0)xe(r,w.vars),x();let M=w!==void 0?new ke(w.vars):void 0,U=r!==void 0?new Te:void 0;return{name:L,requestInterceptors:[i.requestInterceptor,s.requestInterceptor,...U!==void 0?[U.requestInterceptor]:[]],promptInterceptors:[i.promptInterceptor,s.promptInterceptor],heartbeatExtras:i.heartbeatExtras,...U!==void 0?{toolExtensions:[U],metadata:{[Be]:"true"}}:{},started({agents:g,service:v}){if(e.settings.senderIdentity!=="signed"&&!m)m=!0,a.warn(Nt);if(n!==null)l=ut({agents:g,subject:n,logger:a});if(a.info(`${L}: tracing ${v.subject.prompt}`+(n===null?" (propagate-only: lineage forwarded, no edge or served record published)":`, edge and served records on ${n}`)),r!==void 0&&U!==void 0){if(w!==void 0)w.vars[R.creator]=v.subject.prompt,x();let _=kt(r,v.subject.prompt,t);if(_!==void 0)U.start({scratchPad:_,agents:g,service:v,logger:a});else a.warn(`${L}: no sp for this platform (set SCRATCHPAD_BIN); references in prompt_agent are not handed on, and grant requests not answered`);a.info(`${L}: ScratchPad volume ${r.volume}`+(r.dir!==void 0?`, workspace ${r.dir}`:", no workspace")+(w!==void 0?`, for the skill's scripts/sp through ${w.path}`:""))}},async stopping(){for(let g of[...D])C(g),g.turn.settle("ok",g.repliedAtMs);for(let[g,v]of h)h.delete(g),v.turn?.settle("error",void 0,"shutdown");w?.remove(),await l?.flush()},events:{sessionStarted(g){if(Oe(g))f=g},promptAccepted(g){let v=X();if(M!==void 0)M.enter(g,v),x();if(v===void 0)return;let _=g.sessionId??f,I=Oe(_)?_:void 0,q;if(I===void 0)a.warn(jt);else q=l?.beginTurn(v,It),q?.bind(I);h.set(g.id,{request:g,scope:v,sessionId:I,turn:q})},promptEnded(g,v,_,I){let q=h.get(g.id);if(h.delete(g.id),M!==void 0){M.leave(g);let Q=[...h.values()].at(-1);if(Q!==void 0)M.enter(Q.request,Q.scope);x()}if(q===void 0)return;let{turn:J,sessionId:Z}=q;if(J===void 0||Z===void 0)return;if(v!=="ok"||I==="final_text"){J.settle(v,_,I);return}let W={sessionId:Z,turn:J,repliedAtMs:_,timer:setTimeout(()=>{C(W),J.settle("ok",_)},o)};W.timer.unref?.(),D.push(W)},turnStopped(g,v){for(let _ of[...D]){if(g!==void 0&&_.sessionId!==g)continue;if(_.repliedAtMs>=v)continue;C(_),_.turn.settle("ok",v)}},aroundToolCall(g,v,_){let I=g===void 0?void 0:h.get(g.id)?.scope;return I===void 0?_():Ce(I,()=>s.aroundToolCall(I,_))}}}}export{Ne as default};
|