@linzumi/cli 1.0.228 → 1.0.230
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/README.md +1 -1
- package/dist/impl-res/index.js +239 -239
- package/dist/impl-ts/index.js +467 -460
- package/dist/impl-ts/tcp-tunnel-cli.mjs +93 -0
- package/dist/index.js +1 -1
- package/dist/tcp-tunnel-cli.mjs +93 -0
- package/package.json +1 -1
- package/scripts/build-core-supervisor-parity-oracle.mjs +4 -0
- package/scripts/build-protocol-parity-oracle.mjs +3 -0
- package/scripts/build.mjs +34 -1
- package/scripts/bump-cli-version.mjs +1 -1
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import{readFileSync as N,writeFileSync as C,mkdirSync as F,renameSync as U,rmSync as A}from"node:fs";import{homedir as $}from"node:os";import{join as g,dirname as z}from"node:path";var f="ts",l="rescript",B=2e4,V=2,Z=20;function E(){return g($(),".linzumi")}function J(){return g(E(),"commanderImpl")}function W(){return g(E(),"commanderImplFallback.json")}function Y(t){return g(t,"commanderImplLaunchAttempts.json")}function H(){return Y(E())}function K(t=process.env){let e=Number.parseInt(t.LINZUMI_COMMANDER_IMPL_EXIT_WINDOW_MS??"",10);return Number.isFinite(e)&&e>0?e:B}function G(t=process.env){let e=Number.parseInt(t.LINZUMI_COMMANDER_IMPL_FALLBACK_AFTER??"",10);return Number.isFinite(e)&&e>0?e:V}function X(t){try{let e=N(t,"utf8").trim();return e===f||e===l?e:void 0}catch{return}}function I(t){try{let e=JSON.parse(N(t,"utf8"));return e!==null&&typeof e=="object"?e:void 0}catch{return}}function T(t,e){let n=`${t}.tmp.${process.pid}.${Math.random().toString(16).slice(2,8)}`;try{return F(z(t),{recursive:!0}),C(n,`${JSON.stringify(e)}
|
|
2
|
-
`),U(n,t),!0}catch{try{A(n,{force:!0})}catch{}return!1}}function R(t,e){return T(t,e)}function q(t){try{return A(t,{force:!0}),!0}catch{return!1}}function b(t){try{let e=JSON.parse(N(t,"utf8"));return Array.isArray(e)?e:[]}catch{return[]}}function S(t,e){return T(t,e.slice(-Z))}function Q(t,{isPidAlive:e,ownPid:n}){return t.map(
|
|
2
|
+
`),U(n,t),!0}catch{try{A(n,{force:!0})}catch{}return!1}}function R(t,e){return T(t,e)}function q(t){try{return A(t,{force:!0}),!0}catch{return!1}}function b(t){try{let e=JSON.parse(N(t,"utf8"));return Array.isArray(e)?e:[]}catch{return[]}}function S(t,e){return T(t,e.slice(-Z))}function Q(t,{isPidAlive:e,ownPid:n}){return t.map(i=>i.exited_at!==void 0&&i.exited_at!==null||i.pid===n||e(i.pid)?i:{...i,exited_at:null,exit_code:null,uptime_ms:null,short_lived:i.joined!==!0,swept:!0})}function ee(t){if(typeof t!="number"||!Number.isFinite(t))return!1;try{return process.kill(t,0),!0}catch(e){return e!==null&&typeof e=="object"&&e.code==="EPERM"}}function L(t){let e=0;for(let n=t.length-1;n>=0;n-=1){let i=t[n];if(i.exited_at===void 0){if(i.impl===l&&i.joined===!0)break;continue}if(i.impl!==l)break;if(i.short_lived===!0)e+=1;else break}return e}function te({env:t,cacheValue:e,sentinel:n}){let i=(t.LINZUMI_COMMANDER_IMPL??"").trim();return i===f||i===l?{impl:i,source:"override"}:n!==void 0?{impl:f,source:"fallback_sentinel"}:e===f||e===l?{impl:e,source:"cache"}:{impl:f,source:"default"}}function ne(t,e=process.env){if(e.LINZUMI_THREAD_RUNNER_ROLE==="thread"||e.LINZUMI_ONBOARDING_DISCOVERY_ROLE!==void 0||t.includes("--help")||t.includes("-h"))return!1;let[n,...i]=t;if(n==="run"||n==="start")return!0;if(n==="connect"){let[r]=i;return r!==void 0&&r.startsWith("-")}return n==="local-codex-runner"?i.length>0:!1}var re="/api/v1/observability/logs",ie="https://serve.linzumi.com";function oe(t=process.env){let e=(t.LINZUMI_TELEMETRY_BASE_URL??"").trim();return e!==""?e.replace(/\/+$/,""):ie}function se(t=process.env){let e=(t.LINZUMI_TELEMETRY??"").trim().toLowerCase();return e==="0"||e==="false"?!0:t.NODE_ENV==="test"||t.VITEST!==void 0}function k(t){return Object.entries(t).filter(([,e])=>e!=null).map(([e,n])=>({key:e,value:typeof n=="boolean"?{boolValue:n}:typeof n=="number"?Number.isSafeInteger(n)?{intValue:`${n}`}:{doubleValue:n}:{stringValue:String(n)}}))}function h(t,e,{env:n=process.env,severity:i="INFO",fetchImpl:r}={}){try{if(se(n))return Promise.resolve();let d={resourceLogs:[{resource:{attributes:k({"service.name":"linzumi-cli","os.platform":process.platform,"host.arch":process.arch})},scopeLogs:[{scope:{name:"linzumi-cli"},logRecords:[{timeUnixNano:`${BigInt(Date.now())*1000000n}`,severityNumber:i==="ERROR"?17:9,severityText:i,body:{stringValue:t},attributes:k(e)}]}]}]},w=r??fetch;return Promise.resolve().then(()=>w(`${oe(n)}${re}`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(d),signal:AbortSignal.timeout(2e3)})).then(y=>{y.arrayBuffer().catch(()=>{})}).catch(()=>{})}catch{return Promise.resolve()}}function ce(t,e){let n=!1;return{attempts:t.map(r=>r.short_lived===!0&&r.posted!==!0?(h("commander.chooser.short_lived_exit",{impl:r.impl,exit_code:r.exit_code??-1,uptime_ms:r.uptime_ms??-1,consecutive_count:r.consecutive_count??1},{env:e,severity:"ERROR"}),r.fallback_engaged===!0&&r.fallback_posted!==!0?(h("commander.chooser.fallback_engaged",{from_impl:l,to_impl:f,consecutive_short_lived_exits:r.consecutive_count??0},{env:e,severity:"ERROR"}),n=!0,{...r,posted:!0,fallback_posted:!0}):(n=!0,{...r,posted:!0})):r),changed:n}}async function ae(t){let e=process.env,n=E(),i=J(),r=W(),d=H(),w=K(e),y=G(e),M=ne(t,e);if(M)try{let s=Q(b(d),{isPidAlive:ee,ownPid:process.pid}),c=L(s);if(c>=y&&I(r)===void 0){let u=s.findLast(o=>o.short_lived===!0);R(r,{consecutive_short_lived_exits:c,last_exit_code:u?.exit_code??null,written_at:new Date().toISOString()}),h("commander.chooser.fallback_engaged",{from_impl:l,to_impl:f,consecutive_short_lived_exits:c},{env:e,severity:"ERROR"})}S(d,s)}catch{}let P=I(r),m=te({env:e,cacheValue:X(i),sentinel:P});h("commander.chooser.launched",{impl:m.impl,source:m.source},{env:e});let D=m.source!=="override"&&M,v=Date.now(),a={joined:!1,sentinelCleared:!1,effectiveImpl:void 0};if(a.effectiveImpl=m.impl,D){let s=b(d);s=ce(s,e).attempts,s.push({impl:m.impl,source:m.source,pid:process.pid,started_at:new Date(v).toISOString()}),S(d,s),process.on("exit",u=>{try{let o=Date.now()-v,p=b(d),_=p.findLast(x=>x.pid===process.pid&&x.exited_at===void 0);if(_===void 0)return;if(_.exited_at=new Date().toISOString(),_.exit_code=u,_.uptime_ms=o,_.joined=a.joined,_.short_lived=m.impl===l&&!a.joined&&o<w&&u!==0,_.short_lived){let x=L(p);_.consecutive_count=x,x>=y&&I(r)===void 0&&(_.fallback_engaged=!0,R(r,{consecutive_short_lived_exits:x,last_exit_code:u,written_at:new Date().toISOString()}))}S(d,p)}catch{}})}globalThis.__linzumiCommanderChooserMarkJoined=()=>{if(a.joined)return;a.joined=!0;let s;try{if(D){let u=b(d),o=u.findLast(p=>p.pid===process.pid&&p.exited_at===void 0);o!==void 0&&(o.joined=!0,o.joined_at=new Date().toISOString(),S(d,u))}let c=I(r);if(c!==void 0&&a.effectiveImpl===f&&c.reported_at===void 0&&(s={from_impl:l,to_impl:f,consecutive_short_lived_exits:c.consecutive_short_lived_exits??0,sentinel_written_at:c.written_at??null},h("commander.chooser.fallback_reported",s,{env:e,severity:"ERROR"}),R(r,{...c,reported_at:new Date().toISOString()})),c!==void 0&&a.effectiveImpl===l){let u=Math.max(0,w-(Date.now()-v));setTimeout(()=>{!a.sentinelCleared&&I(r)!==void 0&&(a.sentinelCleared=!0,q(r),h("commander.chooser.sentinel_cleared",{healthy_run_ms:Date.now()-v},{env:e}))},u).unref?.()}}catch{}return s};let j=m.impl===l?"./impl-res/index.js":"./impl-ts/index.js",O;try{O=await import(j)}catch(s){if(m.impl===l){let c=1;try{let u=b(d),o=u.findLast(p=>p.pid===process.pid&&p.exited_at===void 0);o!==void 0&&(o.exited_at=new Date().toISOString(),o.exit_code=null,o.uptime_ms=Date.now()-v,o.joined=!1,o.short_lived=!0,o.posted=!0),c=L(u),o!==void 0&&(o.consecutive_count=c),S(d,u)}catch{}if(h("commander.chooser.short_lived_exit",{impl:l,exit_code:-1,uptime_ms:Date.now()-v,consecutive_count:c},{env:e,severity:"ERROR"}),c>=y)I(r)===void 0&&(R(r,{consecutive_short_lived_exits:c,last_exit_code:null,written_at:new Date().toISOString()}),h("commander.chooser.fallback_engaged",{from_impl:l,to_impl:f,consecutive_short_lived_exits:c},{env:e,severity:"ERROR"})),process.stderr.write(`linzumi: the rescript commander bundle failed to load (${s instanceof Error?s.message:String(s)}); falling back to the bundled TS implementation
|
|
3
3
|
`),a.effectiveImpl=f,O=await import("./impl-ts/index.js");else throw s}else throw s}globalThis.__linzumiCommanderChooserDecision={impl:a.effectiveImpl,source:m.source,home:n},await O.main(t)}export{l as IMPL_RESCRIPT,f as IMPL_TS,oe as chooserTelemetryBaseUrl,q as clearSentinel,J as commanderImplCachePath,L as consecutiveShortLivedRescriptExits,V as defaultFallbackAfterConsecutive,ee as defaultIsPidAlive,B as defaultShortLivedExitWindowMs,G as fallbackAfterConsecutive,W as fallbackSentinelPath,ne as isTrackedCommanderLaunch,H as launchAttemptsPath,Y as launchAttemptsPathOf,E as linzumiHomeDir,ae as main,h as postChooserEvent,b as readAttempts,X as readCachedImpl,I as readSentinel,te as resolveImplDecision,K as shortLivedExitWindowMs,Q as sweepDeadAttempts,S as writeAttempts,R as writeSentinel};
|