@tangle-network/sandbox-cli 0.23.2 → 0.23.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/sandbox-cli",
3
- "version": "0.23.2",
3
+ "version": "0.23.4",
4
4
  "description": "CLI for Tangle Sandbox operations",
5
5
  "type": "module",
6
6
  "engines": {
@@ -26,7 +26,7 @@
26
26
  "@tangle-network/agent-runtime": "^9.0.12",
27
27
  "@tangle-network/harness-sessions": "^1.0.2",
28
28
  "@tangle-network/hub-sdk": "1.0.30",
29
- "@tangle-network/sandbox": "^1.0.415",
29
+ "@tangle-network/sandbox": "^1.0.416",
30
30
  "@tangle-network/sdk-cli-runner": "^0.3.12",
31
31
  "chalk": "^5.6.2",
32
32
  "cli-bridge": "https://codeload.github.com/drewstone/cli-bridge/tar.gz/e36c675aafde9e51aca828cb28a2dfb3f885867b",
@@ -87,8 +87,8 @@
87
87
  "author": "Tangle Network",
88
88
  "license": "MIT",
89
89
  "tangleRelease": {
90
- "sourceSha": "2471332475d4da857c59d555a46feae3f248e8c1",
91
- "mergedAt": "2026-11-15T23:08:19-08:00"
90
+ "sourceSha": "c9b8d88ebc113a7d1655de8c89142f3a86e11992",
91
+ "mergedAt": "2026-11-15T23:36:56-08:00"
92
92
  },
93
93
  "scripts": {
94
94
  "build": "tsdown",
@@ -1 +0,0 @@
1
- import{o as e}from"./index.mjs";import{dirname as t,join as n,resolve as r}from"node:path";import{randomBytes as i}from"node:crypto";import{canonicalCandidateDigest as a}from"@tangle-network/agent-interface";import{z as o}from"zod";import{homedir as s}from"node:os";import c,{readFile as l}from"node:fs/promises";import{SearchEnvironmentFault as u}from"@tangle-network/agent-runtime";import{readSettleRecord as d}from"@tangle-network/agent-runtime/durable";import{createBudgetPool as f}from"@tangle-network/agent-runtime/kernel";const p=e=>`${e}.tmp-${i(6).toString(`hex`)}`,m=new Map;function h(e){let t=r(e),n=m.get(t)??{};if(m.set(t,n),n.queued)return n.queued;let i=(n.running??Promise.resolve()).catch(()=>void 0).then(async()=>{n.running=i,n.queued=void 0;try{let e=await c.open(t,`r`);await e.sync().finally(()=>e.close())}finally{n.queued||m.delete(t)}});return n.queued=i,i}async function g(e,n,r={}){let{mode:i=384,owner:a,directory:o}=typeof r==`number`?{mode:r}:r;if(o&&!/^(?!\.\.?$)[^/]+$/.test(e))throw Error(`Not an entry name in the open directory: ${e}`);let s=o?`/proc/self/fd/${o.fd}/${e}`:e,l=p(s);try{let e=await c.open(l,`wx`,i);try{a&&await e.chown(a.uid,a.gid),typeof r!=`number`&&await e.chmod(i),await e.writeFile(n,`utf-8`),await e.sync()}finally{await e.close()}await c.rename(l,s)}catch(e){throw await c.rm(l,{force:!0}).catch(()=>void 0),e}await(o?o.sync():h(t(s)))}const _=o.number().int().positive(),v=async e=>JSON.parse(await l(e,`utf8`)),y=(e,t)=>g(e,JSON.stringify(t));function b(e,t){let n=e.readout(),r=n.tokensKnown?n.deadlineMs>0&&Date.now()>=n.deadlineMs?`Campaign deadline exhausted`:t.maxTokens!==void 0&&n.tokensCapped&&t.maxTokens>n.tokensLeft?`Campaign token ceiling cannot fund the next graph`:t.maxIterations!==void 0&&n.iterationsCapped&&t.maxIterations>n.iterationsLeft?`Campaign iteration ceiling cannot fund the next graph`:void 0:`Campaign token accounting is incomplete`;if(r)throw Object.assign(new u(r),{code:`GRAPH_CAMPAIGN_BUDGET_EXHAUSTED`})}const x=o.strictObject({runId:o.uuid(),budget:o.object({maxTokens:_,maxIterations:_,deadlineMs:_}).passthrough(),sourceDigest:o.string(),graphDigest:o.string()});async function S(t,r,i,c){let l=n(t,`budget.json`),p;try{p=await v(l)}catch(e){if(e.code!==`ENOENT`)throw e;p={identity:i,startedAt:Date.now()}}if(p.identity!==i)throw Error(`Campaign configuration changed; use a new campaign directory`);let m=p.readout;if(m?.reservedTokens)throw Error(`Campaign backing has unresolved historical reservations`);let h=async t=>{let r=await d(n(s(),`.tangle`,`runs`,t.runId));if(!r)return;let i=await e(t.runId);if(r.tree.root!==t.runId||t.sourceDigest!==void 0&&i.sourceDigest!==t.sourceDigest||t.graphDigest!==void 0&&i.graphDigest!==t.graphDigest)throw Error(`Campaign settlement does not match its exact admitted graph`);return{settled:r,digest:a({runId:t.runId,sourceDigest:i.sourceDigest,graphDigest:i.graphDigest,spend:r.spentTotal})}},g=f(r,p.startedAt),_=o.record(o.uuid(),o.string()).parse(p.settlements??{});for(let[e,t]of Object.entries(_)){let n=await h({runId:e});if(!n||n.digest!==t)throw Error(`Historical campaign settlement is missing or changed; accounting cannot resume`);g.observe(n.settled.spentTotal,{alreadySpent:!0}),c?.(e,n.settled.spentTotal)}if(m&&a(m)!==a(JSON.parse(JSON.stringify(g.readout()))))throw Error(`Historical campaign backing cannot be reconstructed from its retained settlements`);let S=p.pending===void 0?void 0:x.parse(p.pending),C=m??g.readout(),w,T=()=>y(l,{identity:i,startedAt:p.startedAt,readout:S?C:g.readout(),settlements:_,...S?{pending:S}:{}}),E=(e,t=!1)=>{t||b(g,e.budget),C=g.readout();let n=g.reserve(e.budget,{assignment:e.runId,stage:`executing`});if(!n.ok)throw new u(`Campaign cannot reserve the next graph's complete ceiling`);w=n.ticket,S=e},D=async()=>{if(!S||!w)return;let e=await h(S);if(!e)return;let t=w,n;try{g.reconcile(t,e.settled.spentTotal)}catch(e){if(g.openReservations().some(({ticketId:e})=>e===t.id))throw await T(),e;n=e}let r=S.runId;if(_[r]=e.digest,S=void 0,w=void 0,await T(),c?.(r,e.settled.spentTotal),n)throw n};if(S){let e=S;S=void 0,E(e,!0),await D()}return await T(),{pool:g,checkpoint:async e=>{if(e){if(_[e.runId]){let t=await h(e);if(!t||t.digest!==_[e.runId])throw Error(`An accounted campaign settlement changed`);c?.(e.runId,t.settled.spentTotal);return}if(S&&a(S)!==a(e))throw new u(`Campaign must reconcile its exact pending run ${S.runId} before admitting another graph`);S||E(e)}else{if(await D(),S)throw new u(`Campaign run ${S.runId} has no retained settlement; its reservation remains pending`);g.assertNoOpenTickets()}await T()},startedAt:p.startedAt,pendingAttempt:()=>S&&structuredClone(S)}}export{S as openGraphCampaignBudget,v as readCampaignJson,h as t,y as writeCampaignJson};