@oddington/cli 0.1.64 → 0.1.65
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/dist/os.js +2 -2
- package/package.json +1 -1
package/dist/os.js
CHANGED
|
@@ -1465,7 +1465,7 @@ Review the changes before publishing.
|
|
|
1465
1465
|
|
|
1466
1466
|
Other options:
|
|
1467
1467
|
--json
|
|
1468
|
-
Return the results as JSON.`,z6=($)=>dg("sha256").update($).digest("hex"),l2=async($,J)=>(await X1($,J)).toString().trim();async function P4($,J){let Z=`${$}.${crypto.randomUUID()}.tmp`,Q=await tY(Z,"wx",384);try{await Q.writeFile(JSON.stringify(J)),await Q.sync()}finally{await Q.close()}await cg(Z,$);let W=await tY(lg($),"r");try{await W.sync()}finally{await W.close()}}function ng($,J){return DN($.item,J)}async function eY($,J,Z={}){let Q=Z.report??console.log,W=Z.request??W1,X=await kN($),Y=await(Z.identity??Z$)(),G=async(N,T)=>{if(T.format!==3)return!1;let P=await d$(g1(N,"run.json")).catch((D)=>{if(D.code!=="ENOENT")throw D}),O=P&&JSON.parse(P);return O?.id===T.id&&O.starter?.kind==="member"&&O.starter.id===Y.id},H=[];if(J!==void 0&&!/^[0-9a-f-]{36}$/.test(J))throw Error("Invalid local Run");for(let{slug:N}of Y.workspaces){let T=b$(N,Z).runs;if(!await p$(T).then(()=>!0).catch((O)=>{if(O.code==="ENOENT")return!1;throw O}))continue;H.push(T)}if(H.length>1){let N=[];for(let T of H){if(J){if(await M5(g1(T,J)).catch((O)=>{if(O.code!=="ENOENT")throw O}))N.push(T);continue}for(let P of(await bN(T)).filter((O)=>/^[0-9a-f-]{36}$/.test(O))){await p$(g1(T,P));let O=await d$(g1(T,P,"complete.json")).catch((j)=>{if(j.code!=="ENOENT")throw j});if(!O)continue;let D=JSON.parse(O),F=await d$(g1(T,P,"publication.json")).catch((j)=>{if(j.code!=="ENOENT")throw j});if(D.state==="complete"&&D.changes!=="not_needed"&&await G(g1(T,P),D)&&(!F||JSON.parse(F).state!=="published")){N.push(T);break}}}H=N}if(H.length!==1)throw Error("Select a Run with os routine publish <run>");let K=H[0],z=g1(K,"preparing.lock"),U=await tY(z,"wx",384).catch(()=>{throw Error(`Publication ownership unavailable: inspect ${z}`)}),V,L,B,_=J,M;try{try{await U.writeFile(JSON.stringify({pid:process.pid,root:X})),await U.sync()}finally{await U.close()}let N=(await bN(K)).filter((y)=>/^[0-9a-f-]{36}$/.test(y)),T=[];for(let y of N){let $0=await M5(g1(K,y));if($0.isSymbolicLink()||!$0.isDirectory())throw Error("Unsafe local Run directory");let U0=await d$(g1(K,y,"complete.json")).catch((g0)=>{if(g0.code==="ENOENT")return;throw g0});if(!U0)continue;let y0=JSON.parse(U0);if(y0.state!=="complete"||y0.changes==="not_needed"||!await G(g1(K,y),y0))continue;let R0=await d$(g1(K,y,"publication.json")).catch((g0)=>{if(g0.code==="ENOENT")return;throw g0});if(!R0||JSON.parse(R0).state!=="published")T.push(y)}let P=J??(T.length===1?T[0]:void 0);if(!P||!/^[0-9a-f-]{36}$/.test(P)||!N.includes(P))throw Error(`Select a Run with os routine publish <run>. Ready runs: ${T.join(", ")||"none"}`);let O=g1(K,P);if(_=P,(await M5(O)).isSymbolicLink())throw Error("Unsafe prepared run directory");let D=await d$(g1(O,"complete.json")).catch((y)=>{if(y.code==="ENOENT")throw Error("Run is incomplete or failed and cannot publish");throw y}),F=JSON.parse(D);if(JSON.parse(await d$(g1(O,"seal.json"))).sha256!==z6(D))throw Error("Sealed preparation changed");if(F.format!==3||F.id!==P||F.state!=="complete"||b$(F.authority.workspace,Z).runs!==K)throw Error("Run is incomplete or belongs to another workspace");if(!await G(O,F))throw Error("Unknown local Run");if(F.execution?.runId!==P||F.execution.state!=="succeeded")throw Error("Successful local Run required");if(F.authority.version!==F.execution.source.version)throw Error("Accepted source identity changed");if(F.changes==="not_needed")throw Error("Nothing needs to be sent to OS");await t9(g1(O,"source"),F.execution.source);let q=F.steps.filter((y)=>y.kind==="records");if(q.length&&await kN(await l2(X,["rev-parse","--show-toplevel"]))!==X)throw Error("Publish from the prepared repository root");let S=g1(O,"publication.json");L=S;let f=await d$(S).catch((y)=>{if(y.code==="ENOENT")return;throw y}),w=f?JSON.parse(f):{intent:z6(D),state:"ready_to_publish",receipts:{},files:{},items:{},reconciled:!1};if(w.intent!==z6(D))throw Error("Sealed preparation changed");try{z4(F.execution.contract.input,F.execution.input);for(let y of F.execution.reports){let $0=y.type==="finish"?F.execution.contract.result:y.type==="step"?F.execution.contract.steps.find((U0)=>U0.id===y.id)?.summary:void 0;if($0)z4($0,y.type==="finish"?y.result:y.type==="step"?y.summary:void 0)}for(let y of F.steps)if(y.kind==="managed-file"){if(G1(y.file),y.storage==="remote"){let $0=M$(y.metadata,m1);if($0.name!==y.file.name||$0.path!==y.file.path||$0.size!==y.file.size||$0.mediaType!==y.file.mediaType)throw Error("Invalid deferred File intent")}}else if(y.kind==="file")G1(y.managedFile),K2(y.file);else if(y.kind==="publication")for(let $0 of DQ(y.item.body))K2($0);for(let y of Object.values(w.managedFiles??{}))G1(y);for(let y of Object.values(w.files))K2(y)}catch{let y=w.attempted||Object.keys(w.receipts).length||Object.keys(w.items).length||Object.keys(w.files).length||Object.keys(w.managedFiles??{}).length;throw Error(`Prepared File contract is obsolete or invalid; preserve ${O} and prepare again before sending changes.`+(y?" Publication was already attempted; controller cutover recovery is required before preparing replacement work.":""))}M=w,w.receipts=Object.assign(Object.create(null),w.receipts),B=w.attempted;let R=o$(F.authority),I=new Map;for(let y of q){if(!l$(y.input,y.operation.request))throw Error("Prepared request differs from original intent");let $0=y.input.repository,U0=I.get($0);if(!U0)U0={requestKey:`records/${$0}`,input:{repository:$0,operations:[]},target:y.operation.target},I.set($0,U0);if(!l$(U0.target,y.operation.target))throw Error("Prepared repository binding changed");U0.input.operations.push({request:y.input,guards:y.operation.guards})}let m=[...I.values()].map(AN),i=(y,$0)=>y&&y.repository===$0&&typeof y.commit==="string"&&/^[0-9a-f]{40}$/.test(y.commit)&&typeof y.diff==="string";for(let[y,$0]of Object.entries(w.receipts)){let U0=m.find((y0)=>y0.requestKey===y);if(!U0||!i($0,U0.input.repository))throw Error("Invalid retained repository receipt; inspect retained progress")}w.automationName??=e6(Y.workspaces.find((y)=>y.slug===R.workspace)?.name);let a=()=>({...w,runId:P,directory:O,links:Object.values(w.items).map((y)=>`https://${R.workspace}.oddington.ai/inbox/${y.id}`)}),Y0;try{Y0=CN([...new Set(F.steps.flatMap((y)=>y.kind==="publication"&&y.item.kind==="ask"?(y.item.questions??[]).flatMap(($0)=>$0.handler?[$0.handler.id]:[]):[]))])}catch{}let d=await W(`/api/cli/local-routines/runs/${P}/publication`,{method:"POST",redirect:"error",body:JSON.stringify({intent:z6(D),handlers:Y0,terminal:{runId:P,state:F.execution.state,source:F.execution.source,input:F.execution.input,contract:F.execution.contract,scope:F.execution.scope}})});if(!d.ok){let y=await J$(d,65536,20000),$0;try{$0=y&&JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(y))}catch{}let U0=d.status===409&&$0?.code==="requirements_unavailable"?M9($0.requirements):void 0;if(U0)throw new C1(P9(U0));if(D2($0?.code))throw new c0($0.code);throw Error(d.status===401?I1:"OS could not admit this Run for publication.")}if(V=await d.json(),!V||!/^[0-9a-f-]{36}$/.test(V.runId)||!/^[0-9a-f]{64}$/.test(V.capability))throw Error("Invalid publication launch");if(V.runId!==P)throw Error("Publication must retain the original Run");if(Q(`Signed in to ${e6(Y.workspaces.find((y)=>y.slug===R.workspace)?.name)}.`),q.length&&(await l2(X,["symbolic-ref","HEAD"])!==F.checkout.branch||await l2(X,["remote","get-url","origin"])!==F.checkout.remote))throw Error("Prepared checkout binding changed");let X0=async(y,$0,U0={})=>{let R0=await(Z.request??((Z1,l)=>DJ(R.workspace,Z1,l,{fetch:Z.fetch})))(`/api/inbox/${y}`,{method:"POST",redirect:"error",headers:{"x-os-run":V.capability,"content-type":"application/json",...U0},body:typeof $0==="string"||$0 instanceof ArrayBuffer?$0:JSON.stringify($0)}),g0=await R0.json();if(!R0.ok)throw Error(String(g0.error??"Publication is pending; retry the same run"));return g0},P0=async(y)=>{let $0={method:"POST",redirect:"error",headers:{"x-os-run":V.capability,"x-os-workspace":R.workspace,"x-os-captured-records":"1","content-type":"application/json"},body:JSON.stringify(jN(y))},U0=Z.request?await Z.request("/api/data",$0):await(Z.fetch??fetch)(`https://${R.workspace}.oddington.ai/api/data`,$0),y0=await U0.json();if(!U0.ok)throw Error(String(y0.error??"Record publication is pending; retry the same run"));return y0},b0=F.steps.filter((y)=>y.kind==="file"),G0=F.steps.filter((y)=>y.kind==="managed-file"),g=F.steps.filter((y)=>y.kind==="publication"),h=[...g.filter((y)=>y.item.kind==="ask"),...g.filter((y)=>y.item.kind==="digest")];if(w.state==="published"){Q(`Published run ${P}. Results: ${S}`);for(let y of Object.values(w.items))Q(`https://${R.workspace}.oddington.ai/inbox/${y.id}`);return a()}if(Z.review)await Z.review({runId:P,routine:R.routine,workspace:R.workspace,handlerAvailability:SN(V.handlerAvailability,Y0??[]),sourceDigest:await X_(g1(O,"source"),F.execution.source)});let n=async()=>R,c=((y)=>Z6({root:y,storage:"local"},{context:n,runId:V.runId,capability:V.capability,workspace:R.workspace,expiresAt:V.expiresAt??new Date(8640000000000000).toISOString(),fetch:Z.fetch}))(d2(R.workspace,Z).root),A=Z6({storage:"remote",root:void 0},{context:n,runId:V.runId,capability:V.capability,workspace:R.workspace,expiresAt:V.expiresAt??new Date(8640000000000000).toISOString(),fetch:Z.fetch}),E=new Set(b0.map((y)=>y.file.id)),C=new Map;for(let y of h)for(let $0 of DQ(y.item.body)){if(E.has($0.id))continue;let U0=C.get($0.id);if(U0&&!l$(U0,$0))throw Error("Conflicting prepared File references");C.set($0.id,$0)}let x=z4(F.execution.contract.input,F.execution.input),u=_9(d2(R.workspace,Z),{workspace:R.workspace,member:{async current(){return{workspaceId:R.workspaceId,creator:{kind:"member",id:Y.id}}},request:(y,$0)=>Z.request?Z.request(new URL(String(y)).pathname,$0):E4(R.workspace,String(y),$0,{fetch:Z.fetch})}}),r=new Map;for(let y of C.values()){let $0=w.managedFiles?.[y.id];if($0){if(!l$(YQ({label:"Files",files:[$0]}).files[0],y))throw Error("Confirmed File descriptor changed");continue}let U0=x.find((Z1)=>Z1.id===y.id),y0=await(U0?u:c).local(),R0=await y0.has(y.id),g0=R0?await y0.get(y.id):await A.stream({suffix:`/${y.id}`,method:"GET",headers:{}}).then(async(Z1)=>{if(!Z1.ok)throw await Z1.body?.cancel(),new k([401,403].includes(Z1.status)?"access_denied":"unavailable",Z1.status,![401,403].includes(Z1.status));return G1(await Z1.json())});if(!l$(YQ({label:"Files",files:[g0]}).files[0],y)||U0&&!l$(U0,g0))throw Error("Prepared File reference changed");r.set(g0.id,{file:g0,...R0?{owner:y0}:{}})}for(let y of G0){if(!y.upload&&y.storage!=="remote"&&!C.has(y.file.id))continue;let $0=w.managedFiles?.[y.file.id];if($0){if(!l$($0,y.file))throw Error("Confirmed File descriptor changed");continue}let y0=await(x.find((g0)=>g0.id===y.file.id)?u:c).local();if(!l$(await y0.get(y.file.id),y.file))throw Error("Sealed File changed; rerun preparation");let R0=r.get(y.file.id);if(R0&&!l$(R0.file,y.file))throw Error("Conflicting prepared File references");r.set(y.file.id,{file:y.file,owner:y0})}let t=new Set;for(let y of q){let $0=y.operation,U0=R.repositories.find((R0)=>R0.target.repository===$0.request.repository);if(!(U0&&(F.checkout.githubRepositoryId!==void 0?U0.target.githubRepositoryId===F.checkout.githubRepositoryId:U0.target.remote===F.checkout.remote&&U0.target.targetRef===F.checkout.branch))||!U0.canWrite||!l$($0.target,U0.target))throw Error("Prepared repository binding changed");for(let[,R0]of $0.guards.paths)t.add(R0)}if(new Set(F.paths.map((y)=>y.path)).size!==F.paths.length||t.size!==F.paths.length||F.paths.some((y)=>!t.has(y.path)))throw Error("Prepared paths differ from declared operations");let K0=q.length?await l2(X,["rev-parse","HEAD"]):F.checkout.head,w0=new Map,z0=async()=>{if(!m.length||m.some((y0)=>!w.receipts[y0.requestKey]))return K0;let y=new Map;for(let y0 of m){let R0=w.receipts[y0.requestKey],g0=y0.target,Z1=async()=>{let l=`${g0.remote}
|
|
1468
|
+
Return the results as JSON.`,z6=($)=>dg("sha256").update($).digest("hex"),l2=async($,J)=>(await X1($,J)).toString().trim();async function P4($,J){let Z=`${$}.${crypto.randomUUID()}.tmp`,Q=await tY(Z,"wx",384);try{await Q.writeFile(JSON.stringify(J)),await Q.sync()}finally{await Q.close()}if(await cg(Z,$),process.platform==="win32")return;let W=await tY(lg($),"r");try{await W.sync()}finally{await W.close()}}function ng($,J){return DN($.item,J)}async function eY($,J,Z={}){let Q=Z.report??console.log,W=Z.request??W1,X=await kN($),Y=await(Z.identity??Z$)(),G=async(N,T)=>{if(T.format!==3)return!1;let P=await d$(g1(N,"run.json")).catch((D)=>{if(D.code!=="ENOENT")throw D}),O=P&&JSON.parse(P);return O?.id===T.id&&O.starter?.kind==="member"&&O.starter.id===Y.id},H=[];if(J!==void 0&&!/^[0-9a-f-]{36}$/.test(J))throw Error("Invalid local Run");for(let{slug:N}of Y.workspaces){let T=b$(N,Z).runs;if(!await p$(T).then(()=>!0).catch((O)=>{if(O.code==="ENOENT")return!1;throw O}))continue;H.push(T)}if(H.length>1){let N=[];for(let T of H){if(J){if(await M5(g1(T,J)).catch((O)=>{if(O.code!=="ENOENT")throw O}))N.push(T);continue}for(let P of(await bN(T)).filter((O)=>/^[0-9a-f-]{36}$/.test(O))){await p$(g1(T,P));let O=await d$(g1(T,P,"complete.json")).catch((j)=>{if(j.code!=="ENOENT")throw j});if(!O)continue;let D=JSON.parse(O),F=await d$(g1(T,P,"publication.json")).catch((j)=>{if(j.code!=="ENOENT")throw j});if(D.state==="complete"&&D.changes!=="not_needed"&&await G(g1(T,P),D)&&(!F||JSON.parse(F).state!=="published")){N.push(T);break}}}H=N}if(H.length!==1)throw Error("Select a Run with os routine publish <run>");let K=H[0],z=g1(K,"preparing.lock"),U=await tY(z,"wx",384).catch(()=>{throw Error(`Publication ownership unavailable: inspect ${z}`)}),V,L,B,_=J,M;try{try{await U.writeFile(JSON.stringify({pid:process.pid,root:X})),await U.sync()}finally{await U.close()}let N=(await bN(K)).filter((y)=>/^[0-9a-f-]{36}$/.test(y)),T=[];for(let y of N){let $0=await M5(g1(K,y));if($0.isSymbolicLink()||!$0.isDirectory())throw Error("Unsafe local Run directory");let U0=await d$(g1(K,y,"complete.json")).catch((g0)=>{if(g0.code==="ENOENT")return;throw g0});if(!U0)continue;let y0=JSON.parse(U0);if(y0.state!=="complete"||y0.changes==="not_needed"||!await G(g1(K,y),y0))continue;let R0=await d$(g1(K,y,"publication.json")).catch((g0)=>{if(g0.code==="ENOENT")return;throw g0});if(!R0||JSON.parse(R0).state!=="published")T.push(y)}let P=J??(T.length===1?T[0]:void 0);if(!P||!/^[0-9a-f-]{36}$/.test(P)||!N.includes(P))throw Error(`Select a Run with os routine publish <run>. Ready runs: ${T.join(", ")||"none"}`);let O=g1(K,P);if(_=P,(await M5(O)).isSymbolicLink())throw Error("Unsafe prepared run directory");let D=await d$(g1(O,"complete.json")).catch((y)=>{if(y.code==="ENOENT")throw Error("Run is incomplete or failed and cannot publish");throw y}),F=JSON.parse(D);if(JSON.parse(await d$(g1(O,"seal.json"))).sha256!==z6(D))throw Error("Sealed preparation changed");if(F.format!==3||F.id!==P||F.state!=="complete"||b$(F.authority.workspace,Z).runs!==K)throw Error("Run is incomplete or belongs to another workspace");if(!await G(O,F))throw Error("Unknown local Run");if(F.execution?.runId!==P||F.execution.state!=="succeeded")throw Error("Successful local Run required");if(F.authority.version!==F.execution.source.version)throw Error("Accepted source identity changed");if(F.changes==="not_needed")throw Error("Nothing needs to be sent to OS");await t9(g1(O,"source"),F.execution.source);let q=F.steps.filter((y)=>y.kind==="records");if(q.length&&await kN(await l2(X,["rev-parse","--show-toplevel"]))!==X)throw Error("Publish from the prepared repository root");let S=g1(O,"publication.json");L=S;let f=await d$(S).catch((y)=>{if(y.code==="ENOENT")return;throw y}),w=f?JSON.parse(f):{intent:z6(D),state:"ready_to_publish",receipts:{},files:{},items:{},reconciled:!1};if(w.intent!==z6(D))throw Error("Sealed preparation changed");try{z4(F.execution.contract.input,F.execution.input);for(let y of F.execution.reports){let $0=y.type==="finish"?F.execution.contract.result:y.type==="step"?F.execution.contract.steps.find((U0)=>U0.id===y.id)?.summary:void 0;if($0)z4($0,y.type==="finish"?y.result:y.type==="step"?y.summary:void 0)}for(let y of F.steps)if(y.kind==="managed-file"){if(G1(y.file),y.storage==="remote"){let $0=M$(y.metadata,m1);if($0.name!==y.file.name||$0.path!==y.file.path||$0.size!==y.file.size||$0.mediaType!==y.file.mediaType)throw Error("Invalid deferred File intent")}}else if(y.kind==="file")G1(y.managedFile),K2(y.file);else if(y.kind==="publication")for(let $0 of DQ(y.item.body))K2($0);for(let y of Object.values(w.managedFiles??{}))G1(y);for(let y of Object.values(w.files))K2(y)}catch{let y=w.attempted||Object.keys(w.receipts).length||Object.keys(w.items).length||Object.keys(w.files).length||Object.keys(w.managedFiles??{}).length;throw Error(`Prepared File contract is obsolete or invalid; preserve ${O} and prepare again before sending changes.`+(y?" Publication was already attempted; controller cutover recovery is required before preparing replacement work.":""))}M=w,w.receipts=Object.assign(Object.create(null),w.receipts),B=w.attempted;let R=o$(F.authority),I=new Map;for(let y of q){if(!l$(y.input,y.operation.request))throw Error("Prepared request differs from original intent");let $0=y.input.repository,U0=I.get($0);if(!U0)U0={requestKey:`records/${$0}`,input:{repository:$0,operations:[]},target:y.operation.target},I.set($0,U0);if(!l$(U0.target,y.operation.target))throw Error("Prepared repository binding changed");U0.input.operations.push({request:y.input,guards:y.operation.guards})}let m=[...I.values()].map(AN),i=(y,$0)=>y&&y.repository===$0&&typeof y.commit==="string"&&/^[0-9a-f]{40}$/.test(y.commit)&&typeof y.diff==="string";for(let[y,$0]of Object.entries(w.receipts)){let U0=m.find((y0)=>y0.requestKey===y);if(!U0||!i($0,U0.input.repository))throw Error("Invalid retained repository receipt; inspect retained progress")}w.automationName??=e6(Y.workspaces.find((y)=>y.slug===R.workspace)?.name);let a=()=>({...w,runId:P,directory:O,links:Object.values(w.items).map((y)=>`https://${R.workspace}.oddington.ai/inbox/${y.id}`)}),Y0;try{Y0=CN([...new Set(F.steps.flatMap((y)=>y.kind==="publication"&&y.item.kind==="ask"?(y.item.questions??[]).flatMap(($0)=>$0.handler?[$0.handler.id]:[]):[]))])}catch{}let d=await W(`/api/cli/local-routines/runs/${P}/publication`,{method:"POST",redirect:"error",body:JSON.stringify({intent:z6(D),handlers:Y0,terminal:{runId:P,state:F.execution.state,source:F.execution.source,input:F.execution.input,contract:F.execution.contract,scope:F.execution.scope}})});if(!d.ok){let y=await J$(d,65536,20000),$0;try{$0=y&&JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(y))}catch{}let U0=d.status===409&&$0?.code==="requirements_unavailable"?M9($0.requirements):void 0;if(U0)throw new C1(P9(U0));if(D2($0?.code))throw new c0($0.code);throw Error(d.status===401?I1:"OS could not admit this Run for publication.")}if(V=await d.json(),!V||!/^[0-9a-f-]{36}$/.test(V.runId)||!/^[0-9a-f]{64}$/.test(V.capability))throw Error("Invalid publication launch");if(V.runId!==P)throw Error("Publication must retain the original Run");if(Q(`Signed in to ${e6(Y.workspaces.find((y)=>y.slug===R.workspace)?.name)}.`),q.length&&(await l2(X,["symbolic-ref","HEAD"])!==F.checkout.branch||await l2(X,["remote","get-url","origin"])!==F.checkout.remote))throw Error("Prepared checkout binding changed");let X0=async(y,$0,U0={})=>{let R0=await(Z.request??((Z1,l)=>DJ(R.workspace,Z1,l,{fetch:Z.fetch})))(`/api/inbox/${y}`,{method:"POST",redirect:"error",headers:{"x-os-run":V.capability,"content-type":"application/json",...U0},body:typeof $0==="string"||$0 instanceof ArrayBuffer?$0:JSON.stringify($0)}),g0=await R0.json();if(!R0.ok)throw Error(String(g0.error??"Publication is pending; retry the same run"));return g0},P0=async(y)=>{let $0={method:"POST",redirect:"error",headers:{"x-os-run":V.capability,"x-os-workspace":R.workspace,"x-os-captured-records":"1","content-type":"application/json"},body:JSON.stringify(jN(y))},U0=Z.request?await Z.request("/api/data",$0):await(Z.fetch??fetch)(`https://${R.workspace}.oddington.ai/api/data`,$0),y0=await U0.json();if(!U0.ok)throw Error(String(y0.error??"Record publication is pending; retry the same run"));return y0},b0=F.steps.filter((y)=>y.kind==="file"),G0=F.steps.filter((y)=>y.kind==="managed-file"),g=F.steps.filter((y)=>y.kind==="publication"),h=[...g.filter((y)=>y.item.kind==="ask"),...g.filter((y)=>y.item.kind==="digest")];if(w.state==="published"){Q(`Published run ${P}. Results: ${S}`);for(let y of Object.values(w.items))Q(`https://${R.workspace}.oddington.ai/inbox/${y.id}`);return a()}if(Z.review)await Z.review({runId:P,routine:R.routine,workspace:R.workspace,handlerAvailability:SN(V.handlerAvailability,Y0??[]),sourceDigest:await X_(g1(O,"source"),F.execution.source)});let n=async()=>R,c=((y)=>Z6({root:y,storage:"local"},{context:n,runId:V.runId,capability:V.capability,workspace:R.workspace,expiresAt:V.expiresAt??new Date(8640000000000000).toISOString(),fetch:Z.fetch}))(d2(R.workspace,Z).root),A=Z6({storage:"remote",root:void 0},{context:n,runId:V.runId,capability:V.capability,workspace:R.workspace,expiresAt:V.expiresAt??new Date(8640000000000000).toISOString(),fetch:Z.fetch}),E=new Set(b0.map((y)=>y.file.id)),C=new Map;for(let y of h)for(let $0 of DQ(y.item.body)){if(E.has($0.id))continue;let U0=C.get($0.id);if(U0&&!l$(U0,$0))throw Error("Conflicting prepared File references");C.set($0.id,$0)}let x=z4(F.execution.contract.input,F.execution.input),u=_9(d2(R.workspace,Z),{workspace:R.workspace,member:{async current(){return{workspaceId:R.workspaceId,creator:{kind:"member",id:Y.id}}},request:(y,$0)=>Z.request?Z.request(new URL(String(y)).pathname,$0):E4(R.workspace,String(y),$0,{fetch:Z.fetch})}}),r=new Map;for(let y of C.values()){let $0=w.managedFiles?.[y.id];if($0){if(!l$(YQ({label:"Files",files:[$0]}).files[0],y))throw Error("Confirmed File descriptor changed");continue}let U0=x.find((Z1)=>Z1.id===y.id),y0=await(U0?u:c).local(),R0=await y0.has(y.id),g0=R0?await y0.get(y.id):await A.stream({suffix:`/${y.id}`,method:"GET",headers:{}}).then(async(Z1)=>{if(!Z1.ok)throw await Z1.body?.cancel(),new k([401,403].includes(Z1.status)?"access_denied":"unavailable",Z1.status,![401,403].includes(Z1.status));return G1(await Z1.json())});if(!l$(YQ({label:"Files",files:[g0]}).files[0],y)||U0&&!l$(U0,g0))throw Error("Prepared File reference changed");r.set(g0.id,{file:g0,...R0?{owner:y0}:{}})}for(let y of G0){if(!y.upload&&y.storage!=="remote"&&!C.has(y.file.id))continue;let $0=w.managedFiles?.[y.file.id];if($0){if(!l$($0,y.file))throw Error("Confirmed File descriptor changed");continue}let y0=await(x.find((g0)=>g0.id===y.file.id)?u:c).local();if(!l$(await y0.get(y.file.id),y.file))throw Error("Sealed File changed; rerun preparation");let R0=r.get(y.file.id);if(R0&&!l$(R0.file,y.file))throw Error("Conflicting prepared File references");r.set(y.file.id,{file:y.file,owner:y0})}let t=new Set;for(let y of q){let $0=y.operation,U0=R.repositories.find((R0)=>R0.target.repository===$0.request.repository);if(!(U0&&(F.checkout.githubRepositoryId!==void 0?U0.target.githubRepositoryId===F.checkout.githubRepositoryId:U0.target.remote===F.checkout.remote&&U0.target.targetRef===F.checkout.branch))||!U0.canWrite||!l$($0.target,U0.target))throw Error("Prepared repository binding changed");for(let[,R0]of $0.guards.paths)t.add(R0)}if(new Set(F.paths.map((y)=>y.path)).size!==F.paths.length||t.size!==F.paths.length||F.paths.some((y)=>!t.has(y.path)))throw Error("Prepared paths differ from declared operations");let K0=q.length?await l2(X,["rev-parse","HEAD"]):F.checkout.head,w0=new Map,z0=async()=>{if(!m.length||m.some((y0)=>!w.receipts[y0.requestKey]))return K0;let y=new Map;for(let y0 of m){let R0=w.receipts[y0.requestKey],g0=y0.target,Z1=async()=>{let l=`${g0.remote}
|
|
1469
1469
|
${g0.targetRef}`;if(!w0.has(l))await X1(X,["fetch","--quiet","--no-tags","--",g0.remote,g0.targetRef]),w0.set(l,await l2(X,["rev-parse","FETCH_HEAD"]));await X1(X,["merge-base","--is-ancestor",R0.commit,w0.get(l)])};await(Z.environment?s8(Z.environment,Z1):Z1());for(let l of y0.input.operations)for(let[,s]of l.guards.paths)y.set(s,R0.commit)}let $0=g1(O,`reconcile-${crypto.randomUUID()}.index`),U0=await l2(X,["show","-s","--format=%cI",K0]);try{return await s8({...process.env,GIT_INDEX_FILE:$0,GIT_AUTHOR_NAME:w.automationName,GIT_AUTHOR_EMAIL:"os@oddington.ai",GIT_AUTHOR_DATE:U0,GIT_COMMITTER_NAME:w.automationName,GIT_COMMITTER_EMAIL:"os@oddington.ai",GIT_COMMITTER_DATE:U0},async()=>{await X1(X,["read-tree",K0]);for(let[R0,g0]of y)await X1(X,["reset","--quiet",g0,"--",R0]);let y0=await l2(X,["write-tree"]);if(y0===await l2(X,["rev-parse",`${K0}^{tree}`]))return K0;return l2(X,["commit-tree",y0,"-p",K0,"-m",`Reconcile local Run ${P}`])})}finally{await fN($0,{force:!0})}},T0=m.every((y)=>w.receipts[y.requestKey]),L0=await z0(),q0=async(y)=>{let $0=m.length>0&&m.every((U0)=>w.receipts[U0.requestKey])&&K0===L0;if(!$0&&(await X1(X,["diff","--name-only","-z",F.checkout.head,K0,"--",y])).length)return!1;if(!(await X1(X,["diff","--cached","--name-only","-z",F.checkout.head,"--",y])).length)return!0;return $0&&!(await X1(X,["diff","--cached","--name-only","-z",K0,"--",y])).length},h0=async(y=F.paths)=>{for(let $0 of y){if(!$0.path||$0.path.split("/").some((Z1)=>!Z1||[".","..",".git"].includes(Z1)))throw Error("Invalid prepared path");let U0=g1(X,$0.path),y0=X;for(let Z1 of $0.path.split("/").slice(0,-1)){y0=g1(y0,Z1);let l=await M5(y0).catch((s)=>{if(s.code==="ENOENT")return;throw s});if(l&&(!l.isDirectory()||l.isSymbolicLink()))throw Error("Unsafe prepared parent")}let R0=await M5(U0).catch((Z1)=>{if(Z1.code==="ENOENT")return;throw Z1});if(R0&&(!R0.isFile()||R0.isSymbolicLink()||R0.mode&73))throw Error("Unsafe prepared record");let g0=R0?await xN(U0):null;if((g0===null?null:z6(g0))!==$0.sha256||!await q0($0.path))throw Error(`Prepared path changed: ${$0.path}; rerun preparation`)}};await h0();let t0=new Map;for(let y of b0){if(w.files[y.file.id])continue;let $0=await c.local();if(!l$(await $0.get(y.managedFile.id),y.managedFile))throw Error("Sealed File changed");let U0=new Uint8Array(await(await $0.read(y.managedFile.id)).arrayBuffer());if(await FQ(U0,y.file),z6(await x6(X,y.input))!==y.file.sha256)throw Error("Prepared source file changed");t0.set(y.file.id,U0)}await P4(S,w);let U1=async(y)=>{w.state="publishing",w.attempted=B=y,await P4(S,w)};w.managedFiles??={};let S1=b0.filter((y)=>!w.files[y.file.id]).length;for(let{file:y,owner:$0}of r.values())if($0&&!w.managedFiles[y.id]&&await $0.placement(y.id)==="local")S1++;let y1=`${S1} File${S1===1?"":"s"}`;if(S1)Q(`Uploading ${y1}…`);for(let{file:y,owner:$0}of r.values()){let U0=w.managedFiles[y.id];if(U0&&!l$(U0,y))throw Error("Confirmed File descriptor changed");if(U0)continue;await U1(`managed-upload/${y.id}`);let y0=$0?await $0.upload(y.id):y;if(!l$(y0,y))throw Error("Uploaded File differs from prepared reference");w.managedFiles[y.id]=y0,await P4(S,w)}for(let y of b0){if(w.files[y.file.id])continue;await U1(`file/${y.file.id}`);let $0=await X0("files",Uint8Array.from(t0.get(y.file.id)).buffer,{"content-type":"application/octet-stream","x-os-file":JSON.stringify({name:y.file.name})}),U0=await FQ(t0.get(y.file.id),$0);w.files[y.file.id]=U0,await P4(S,w)}if(S1)Q(`Uploaded ${y1}.`);for(let y of m){if(w.receipts[y.requestKey])continue;Q("Publishing Records…"),await U1(y.requestKey),await h0(F.paths.filter((y0)=>y.input.operations.some((R0)=>R0.guards.paths.some(([,g0])=>g0===y0.path))));let U0=(await P0({apply:y})).receipt;if(!i(U0,y.input.repository))throw Error("Authoritative receipt differs; inspect retained progress");w.receipts[y.requestKey]=U0,await P4(S,w),Q("Published Records.")}if(q.length){if(!T0)L0=await z0();let y=L0;await h0();for(let $0 of F.paths){let U0=await xN(g1(X,$0.path)).catch((R0)=>{if(R0.code==="ENOENT")return null;throw R0});if((U0===null?null:z6(U0))!==$0.sha256||!await q0($0.path))throw Error("Local reconciliation differs; preserve checkout and inspect receipts");if(await l2(X,["ls-tree","--name-only",y,"--",$0.path])?U0===null||!U0.equals(await X1(X,["cat-file","blob",`${y}:${$0.path}`])):U0!==null)throw Error("Local path differs from confirmed commit")}if(await X1(X,["update-ref",F.checkout.branch,y,K0]),F.paths.length)await X1(X,["reset","--quiet",y,"--",...F.paths.map(($0)=>$0.path)])}w.reconciled=!0,await P4(S,w);let e0=h.filter((y)=>!w.items[y.result.id]),g$={ask:e0.filter((y)=>y.item.kind==="ask").length,digest:e0.filter((y)=>y.item.kind==="digest").length},I$=new Set;for(let y of h){if(w.items[y.result.id])continue;let $0=y.item.kind,U0=`${g$[$0]} ${$0==="ask"?"Ask":"Digest"}${g$[$0]===1?"":"s"}`;if(!I$.has($0))Q(`Publishing ${U0}…`),I$.add($0);let y0=ng(y,w);await U1(`publication/${y.requestKey}`);let R0=await X0("publish",{requestKey:y.requestKey,item:y0});if(typeof R0.id!=="string"||!/^[0-9a-f-]{36}$/.test(R0.id))throw Error("Publication acknowledgment unavailable");if(w.items[y.result.id]&&w.items[y.result.id].id!==R0.id)throw Error("Confirmed publication identity changed");if(w.items[y.result.id]=R0,await P4(S,w),e0.filter((g0)=>g0.item.kind===$0).every((g0)=>w.items[g0.result.id]))Q(`Published ${U0}.`);Q(`https://${R.workspace}.oddington.ai/inbox/${R0.id}`)}return w.state="published",delete w.failed,await P4(S,w),Q(`Published run ${P}. Results: ${S}`),a()}catch(N){if(M&&L&&M.state!=="published")M.failed=!0,await P4(L,M);if(B)Q(`Sending changes is pending or uncertain after ${B}. Confirmed results: ${L}. Retry os routine publish ${_} from this root with unchanged content.`);else if(M)Q(`Prepared results remain available. Retry os routine publish ${_} from this root after resolving the failure.`);throw N}finally{try{if(V)await W(`/api/cli/local-routines/runs/${V.runId}/publication`,{method:"DELETE",redirect:"error",headers:{"x-os-run":V.capability}}).catch(()=>{return})}finally{await fN(z)}}}function ig($){if($.includes("--run")){if($[0]==="publish"&&$[1]==="--run"&&/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test($[2]??"")&&($.length===3||$.length===4&&$[3]==="--json"))throw Error(`Choose the Run by putting its ID after publish.
|
|
1470
1470
|
|
|
1471
1471
|
Use the Run ID without --run:
|
|
@@ -1684,7 +1684,7 @@ Run this command from the repository or any folder inside it.`);throw Error(AG)}
|
|
|
1684
1684
|
|
|
1685
1685
|
${X}
|
|
1686
1686
|
|
|
1687
|
-
Save your edits separately, then restore the generated file before running this command again.`)}let H=await TM(Q);G[$]=await Kh($,Z,J);let K=await TM(Q);if(K.length!==H.length||H.some((z)=>!K.some((U)=>U.path===z.path&&U.before===z.before)))throw Error(`Project files changed during schema generation: ${Q}. Retry after reviewing them.`);return await Hh(Q,[...H,{path:X,before:Y?.text,after:CM(G),mode:Y?.mode??420}],J.replace??DM),{repository:$,generated:X,projects:H.filter((z)=>z.before!==z.after).map((z)=>z.path)}}finally{await TG(W,{recursive:!0,force:!0})}}async function SM($){if($.length===0||$.includes("--help")||$.includes("-h")){console.log($[0]==="schema"?Wh:Qh);return}if($.length===1&&$[0]==="schema")throw Error(Xh);if($.length!==2||$[0]!=="schema")throw Error(vJ);let J=await zh($[1]);console.log(`Schema ${J.repository}: ${J.generated}`);for(let Z of J.projects)console.log(`Integrated ${Z}`)}var uJ={name:"@oddington/cli",version:"0.1.
|
|
1687
|
+
Save your edits separately, then restore the generated file before running this command again.`)}let H=await TM(Q);G[$]=await Kh($,Z,J);let K=await TM(Q);if(K.length!==H.length||H.some((z)=>!K.some((U)=>U.path===z.path&&U.before===z.before)))throw Error(`Project files changed during schema generation: ${Q}. Retry after reviewing them.`);return await Hh(Q,[...H,{path:X,before:Y?.text,after:CM(G),mode:Y?.mode??420}],J.replace??DM),{repository:$,generated:X,projects:H.filter((z)=>z.before!==z.after).map((z)=>z.path)}}finally{await TG(W,{recursive:!0,force:!0})}}async function SM($){if($.length===0||$.includes("--help")||$.includes("-h")){console.log($[0]==="schema"?Wh:Qh);return}if($.length===1&&$[0]==="schema")throw Error(Xh);if($.length!==2||$[0]!=="schema")throw Error(vJ);let J=await zh($[1]);console.log(`Schema ${J.repository}: ${J.generated}`);for(let Z of J.projects)console.log(`Integrated ${Z}`)}var uJ={name:"@oddington/cli",version:"0.1.65",description:"OS command-line client",license:"SEE LICENSE IN LICENSE",type:"module",bin:{os:"dist/os.js"},files:["dist","LICENSE","README.md"],engines:{node:">=22.12.0"},publishConfig:{access:"public"},scripts:{build:"bun run --filter @oddington/sdk build && bun run scripts/build.ts",check:"tsc --noEmit",prepack:"bun run scripts/prepack.ts","verify:package":"bun run scripts/verify-package.ts"},devDependencies:{"@babel/parser":"8.0.7","@types/node":"26.6.1","@types/semver":"^7.7.1",semver:"^7.7.3",typescript:"7.0.2"},dependencies:{"@oddington/sdk":"^0.1.36"},exports:{}};var IM=`Usage:
|
|
1688
1688
|
os --version
|
|
1689
1689
|
os login
|
|
1690
1690
|
os whoami
|