@tangle-network/sandbox-cli 0.23.253 → 0.23.255

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.
@@ -1 +0,0 @@
1
- import{t as e}from"./errors-DrYiP5_c.mjs";import{A as t,C as n,E as r,N as i,d as a,f as o,j as s,l as c,m as l,n as u,s as d,u as f,v as p,z as m}from"./graph-CfJIUB0U.mjs";import{u as h}from"./graph-run-input-BpulR6gB.mjs";import{t as g}from"./graph-native-CFPI9Z4Z.mjs";import{createLearningJudge as _,graphLearningModule as v,learningCampaignIdentity as y,learningImprovementOptions as b,learningOptimizer as x,withLearningCampaign as S}from"./graph-learning-CNX2gxvA.mjs";import{basename as C,dirname as w,join as T}from"node:path";import{agentCandidateResolvedModelSchema as E,agentProfileSchema as D,canonicalAgentProfileDigest as O,canonicalCandidateDigest as k}from"@tangle-network/agent-interface";import{homedir as A}from"node:os";import{readFile as j,realpath as M,writeFile as N}from"node:fs/promises";import{campaignScenarioIdentity as ee}from"@tangle-network/agent-eval/campaign";import{FileCoordinationLog as P,FileResultBlobStore as F,canonicalObservedModelParts as I,createPrivateCasArtifactPort as L,graphFlowSpawnProfile as R,graphFromStored as z,graphRegistry as B,loadGraph as V,observedModelHasSnapshot as H,observedModelMatchesDeclared as U,validateStoredGraph as te}from"@tangle-network/agent-runtime/kernel";import{discoverDurableSupervisionRun as W,readSettleRecord as G,readSpawnJournal as K}from"@tangle-network/agent-runtime/durable";import{AnalystRegistry as ne}from"@tangle-network/agent-eval/analyst";import{proposeAgentProfileImprovement as re}from"@tangle-network/agent-runtime/intelligence";const q=import.meta.url;async function ie(e,t,r){let i=T(A(),`.tangle`,`runs`,e),a=await h(e),o=await V(B(T(A(),`.tangle`,`graph-registry`)),a.graphDigest);if(!o)throw Error(`Measured graph registry snapshot is unavailable`);let s=te(o);if(s.digest!==a.graphDigest)throw Error(`Measured compiled graph identity changed`);n(s.nodes.find(e=>e.id===t)?.profile,r);let[c,l,u]=await Promise.all([G(i),W(i),K(i)]);if(!c||c.tree.root!==e||!u.cursor||u.truncated||u.remainingBytes)throw Error(`Exact completed graph settlement or full journal is unavailable`);let d=new F(T(i,`blobs`)),f=c.tree.nodes.filter(e=>e.label===t);if(!f.length||!s.entry||f.some(t=>t.parent!==e))throw Error(`Canonical profile measurement currently requires a retained native flow graph`);let p=z(s,{trigger:a.trigger??{}}),m=new P(l.coordinationLogPath),g=[];for(let e of l.coordinationStreams){if(e.unscopedRecords||!e.ownerIds.length)throw Error(`Flow execution has no exact coordination owner binding`);for(let t of e.ownerIds){let n=await m.load(e.runId,t);for(let e of n.records)e.event.type===`route`&&e.event.route.kind===`traversal`&&g.push(e.event.route)}}for(let e of f){let t=g.filter(t=>t.workerId===e.id),n=new Set(t.map(e=>O(R(p,e)))),r=u.records.find(t=>t.kind===`event`&&t.event.kind===`spawned`&&t.event.id===e.id);if(n.size!==1||!e.identity?.profileDigest||!n.has(e.identity.profileDigest)||r?.kind!==`event`||r.event.kind!==`spawned`||!r.event.profileRef||O(D.parse(await d.get(r.event.profileRef)))!==e.identity.profileDigest)throw Error(`Executed node differs from its exact retained flow edge/profile derivation`)}let _=f.map(e=>e.providerModel);if(_.some(e=>e?.status!==`known`||!e.attempts.length))throw Error(`Selected profile has no complete provider-served model identity`);let v=[...new Set(_.flatMap(e=>e?.models??[]))],y=r.model?.default,b=r.model?.provider,x=r.model?.reasoningEffort;if(!y||!b||!x||!v.length||v.some(e=>!H(e)||!U(e,y)))throw Error(`Missing or contradictory exact served model/snapshot/effort binding`);let S=[...new Set(v.map(e=>I(e)?.snapshot))];if(S.length!==1||!S[0])throw Error(`Provider observations changed their model snapshot`);return{resolvedModel:E.parse({requested:y,provider:b,model:y.startsWith(`${b}/`)?y.slice(b.length+1):y,snapshot:S[0],reasoningEffort:x})}}const ae=async()=>Promise.all([import.meta.url,q,v,p,l,g,d,f].map(async e=>u(await j(new URL(e)))));async function oe(e,t){let n=await M(e),r=C(n,`.json`);if(C(w(n))!==`versions`||!/^[a-f0-9]{64}$/.test(r))throw Error(`--assessment must name an existing dataset/versions/<digest>.json frozen manifest`);let a=await s(w(w(n)),r);if(await M(a.root)===await M(t.dataset.root))throw Error(`Final assessment requires a separate frozen dataset, outside all search partitions`);let c=t.dataset.cases,l=new Set,u=new Set;for(let e of a.cases){let n=o(e);if(l.has(e.unit)||u.has(n))throw Error(`Final assessment requires distinct independent task units; repeated observations cannot become extra independent cases`);if(l.add(e.unit),u.add(n),e.domain!==t.suite.domain||e.trigger===void 0||e.kind===`retained-graph`&&(e.outcome===`unavailable`||!e.sourceDigest))throw Error(`Final assessment contains unavailable or incompatible retained task inputs`);if(i(c,{...e,digest:n},o))throw Error(`Final assessment overlaps a search train/dev/test task or independent unit`)}if(!a.cases.length)throw Error(`Final assessment manifest is empty`);return a}const se=(e,t)=>({identity:n,profile:r})=>k({sourceIdentity:n,executionContext:e,graphSource:t(r)});async function J(t,n,i,s,l,d,f={}){return S({file:t,datasetDirectory:n,suiteFile:i,directory:s,seat:d,bindings:f},async({admission:n,reflection:s,completed:d,open:f,retain:p})=>{let{root:m,suite:h,profile:g,sourceForProfile:v,dataset:S}=n;if(h.mutation!==`agent-profile`||!h.assessment)throw Error(`Canonical full-profile learning requires mutation=agent-profile and explicit assessment policy/limits in the suite`);let C=h.assessment;if(n.calibration.some(e=>e.passed===void 0))throw Error(`Canonical assessment calibration requires an explicit evaluator passed verdict before native dispatch`);if(C.policy.deltaThreshold!==h.minimumEffect||C.policy.budgetUsd!==void 0&&C.policy.budgetUsd!==0)throw Error(`Assessment policy contradicts the selected effect or subscription-only campaign budget`);let w=await oe(l,n);if(n.loaded.graph.gates?.length&&[...S.cases,...w.cases].some(e=>e.gateChoices===void 0))throw Error(`Gated replay requires retained gate choices; reingest historical inputs before canonical assessment`);let E=await ae(),D=await r(),O=k({kind:`canonical-graph-profile-learning`,learning:await y(n,s,D),sourcePath:await M(t),implementation:E,executionEnvironment:D,assessment:{root:w.root,version:w.version}}),A=await d(O);if(A)return A;let j=S.cases.find(e=>e.split===`train`&&e.kind===`retained-graph`&&e.origin===`local`&&e.sourceDigest===n.baselineDigest);if(!j)throw Error(`Canonical baseline needs a retained local train run of the exact current source to attest its served model`);let N=await ie(j.run,h.node,g),P=x(n,s),F=await p(S);await c({domain:h.domain,root:m,identity:O,evaluatorDigest:n.evaluatorIdentity,cases:S.cases});let I=await f(O),R=await a({domain:h.domain,root:m,identity:O,evaluatorDigest:n.evaluatorIdentity,stage:`assessment`,cases:[...S.cases,...w.cases]}),z={requestId:R.requestId,claimDigest:k({identity:O,domain:h.domain,objective:h.objective,assessment:C,evaluator:n.evaluatorIdentity}),populationId:h.domain,inputDigest:k([...w.cases].sort((e,t)=>e.id.localeCompare(t.id))),unitIds:w.cases.map(e=>e.unit),sourceDigests:w.cases.map(o),developmentSourceDigests:S.cases.filter(e=>e.split!==`test`).map(o)},B=await R.ledger.reserve(z);if(!B.succeeded)throw Error(`Final assessment refused: ${B.error.message}`);let V=B.value.record,H=_(n,new Map([...F,...await p(w)]),I.invocation),{agent:U,executionRef:te,...W}=await b(n,s,O,{...I,judge:H},P);if(!U)throw Error(`Canonical profile search has no native executor`);let G=L(T(m,`artifacts`),`graph-profile-learning`),K=Buffer.from(JSON.stringify({evaluatorIdentity:n.evaluatorIdentity,evaluator:h.evaluator})),q={name:`independent-domain-evaluator`,version:n.evaluatorIdentity,format:`tangle-grader`,artifact:await G.put({executionId:`graph-profile:${O}`,purpose:`grader-evidence`,bytes:K})},J={kind:`agent-profile-improvement-execution-ref`,identity:`graph-profile:${h.node}:${O}`,digest:O},Y=`graph-profile:${u(await M(t))}:${h.node}`,X=se(O,v),le={kind:`native-graph-profile`,sourceIdentity:Y,sourceRevision:n.baselineDigest,sourceDigest:X({identity:Y,profile:g})},Z=w.cases.map(e=>({kind:`agent-profile-improvement-task`,digestAlgorithm:`rfc8785-sha256`,scenario:{id:e.id,kind:e.kind,digest:ee(e).scenarioDigest},grader:q,model:N.resolvedModel,limits:C.limits})),Q=async()=>{throw new e(`GRAPH_PROFILE_MEASUREMENT_UNSUPPORTED`,`Full-profile final measurement is not available in this CLI`,`Canonical full-profile learning retains a hold until native runs report complete accounting`,`tangle graph improve --help`)},$=await re({runId:`graph-profile:${O}`,source:le,profile:g,stateDigest:X,allowIncomplete:!0,budgetUsd:0,maxConcurrency:1,signal:I.signal,analysis:{registry:new ne,inputs:{},findingsStore:null},improvement:W,benchmark:{tasks:Z,reps:h.reps,seeds:Z.flatMap((e,t)=>Array.from({length:h.reps},(e,n)=>t*h.reps+n)),policy:C.policy},executor:{executionRef:J,optimize:U,measure:Q},modelBinding:Q});try{return await ce({result:$,admission:n,campaign:I,fresh:w,file:t,suiteFile:i,identity:O,implementation:E,executionEnvironment:D,finalEvidence:V})}finally{await $.improvement.dispose()}})}async function ce(n){let{result:r,admission:i,campaign:a,fresh:o,file:s,suiteFile:c,identity:l,implementation:d,executionEnvironment:f,finalEvidence:p}=n,{root:h,suite:g,dataset:_,sourceForProfile:v}=i,y=v(r.improvement.candidate.profile),b=u(y),x=T(h,`${b}.graph.yaml`);await N(x,y,{mode:384,flush:!0});let{dispose:S,...C}=r.improvement,w={version:1,kind:`canonical-graph-profile-learning`,identity:l,implementation:d,executionEnvironment:f,sourcePath:await M(s),candidate:x,candidateDigest:b,baselineDigest:i.baselineDigest,node:g.node,dataset:{root:o.root,version:o.version},searchDataset:{root:_.root,version:_.version},finalEvidence:p,suite:await M(c),evaluatorIdentity:i.evaluatorIdentity,canonical:{...r,improvement:C}},E=async e=>{let n={...w,...e,campaignBudget:{limits:g.budget,readout:a.pool.readout()}},r=await t(h,n);return await m(T(h,`result.json`),{record:r}),{...n,record:r}};if(`status`in r&&r.status===`held`)return E({decision:`hold`,operational:{admissible:!1,reasons:r.reasons}});throw new e(`GRAPH_PROFILE_MEASUREMENT_UNSUPPORTED`,`Full-profile final measurement is not available in this CLI`,`Canonical full-profile learning retains a hold until native runs report complete accounting`,`tangle graph improve --help`)}export{J as learnGraphProfile};