@x-otto/env 0.1.0-alpha.2 → 0.1.0-alpha.3

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/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region src/build-id.d.ts
2
- declare const BUILD_ID = 4570;
2
+ declare const BUILD_ID = 4599;
3
3
  //#endregion
4
4
  //#region src/config-layers.d.ts
5
5
  /**
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{homedir as e,hostname as t}from"node:os";import{existsSync as n,readFileSync as r}from"node:fs";import{dirname as i,join as a,normalize as o,sep as s}from"node:path";import{spawnSync as c}from"node:child_process";const l=4570;function u(e){let{cwd:t,homedir:n,workspaceRoot:r}=e,i=e.claudeCompat??q(),o=[];return o.push({kind:`otto`,scope:`project`,dir:j(a(t,`.otto`))}),r&&j(r)!==j(t)&&o.push({kind:`otto`,scope:`repository`,dir:j(a(r,`.otto`))}),i&&o.push({kind:`claude`,scope:`project`,dir:j(a(t,`.claude`))}),n&&o.push({kind:`otto`,scope:`user`,dir:j(a(n,`.otto`))}),i&&n&&o.push({kind:`claude`,scope:`user`,dir:j(a(n,`.claude`))}),o}function d(e){try{return process.kill(e,0),!0}catch{return!1}}function f(){return t()}function p(e,t,n){return`${e}:${t}:${n}`}function m(e){let t=e.indexOf(`:`);if(t===-1)return{token:e};let n=e.indexOf(`:`,t+1);if(n===-1)return{token:e};let r=e.slice(0,t),i=e.slice(t+1,n),a=e.slice(n+1),o=Number(i),s=Number.isFinite(o)&&o>0?o:void 0;return s!==void 0&&a.length>0?{token:r,pid:s,host:a}:{token:r}}function h(e){let t=e.trim().match(/^(?:(\d+)-)?(?:(\d+):)?(\d+):(\d+)$/);if(!t)return 0;let[,n,r,i,a]=t;return(Number(n??0)*86400+Number(r??0)*3600+Number(i)*60+Number(a))*1e3}function ee(e){return e.match(/--continue\s+([0-9a-f-]{36})/)?.[1]}function te(e){let t=e.match(/--restart-generation=(\d+)/);return t?Number(t[1]):void 0}function g(e=`bin/otto.js`){let t=c(`ps`,[`-axo`,`pid=,ppid=,rss=,tty=,etime=,args=`],{encoding:`utf8`,timeout:1e4,maxBuffer:16*1024*1024});return t.status!==0||!t.stdout?[]:_(t.stdout,e)}function _(e,t=`bin/otto.js`){let n=[];for(let r of e.split(`
1
+ import{homedir as e,hostname as t}from"node:os";import{existsSync as n,readFileSync as r}from"node:fs";import{dirname as i,join as a,normalize as o,sep as s}from"node:path";import{spawnSync as c}from"node:child_process";const l=4599;function u(e){let{cwd:t,homedir:n,workspaceRoot:r}=e,i=e.claudeCompat??q(),o=[];return o.push({kind:`otto`,scope:`project`,dir:j(a(t,`.otto`))}),r&&j(r)!==j(t)&&o.push({kind:`otto`,scope:`repository`,dir:j(a(r,`.otto`))}),i&&o.push({kind:`claude`,scope:`project`,dir:j(a(t,`.claude`))}),n&&o.push({kind:`otto`,scope:`user`,dir:j(a(n,`.otto`))}),i&&n&&o.push({kind:`claude`,scope:`user`,dir:j(a(n,`.claude`))}),o}function d(e){try{return process.kill(e,0),!0}catch{return!1}}function f(){return t()}function p(e,t,n){return`${e}:${t}:${n}`}function m(e){let t=e.indexOf(`:`);if(t===-1)return{token:e};let n=e.indexOf(`:`,t+1);if(n===-1)return{token:e};let r=e.slice(0,t),i=e.slice(t+1,n),a=e.slice(n+1),o=Number(i),s=Number.isFinite(o)&&o>0?o:void 0;return s!==void 0&&a.length>0?{token:r,pid:s,host:a}:{token:r}}function h(e){let t=e.trim().match(/^(?:(\d+)-)?(?:(\d+):)?(\d+):(\d+)$/);if(!t)return 0;let[,n,r,i,a]=t;return(Number(n??0)*86400+Number(r??0)*3600+Number(i)*60+Number(a))*1e3}function ee(e){return e.match(/--continue\s+([0-9a-f-]{36})/)?.[1]}function te(e){let t=e.match(/--restart-generation=(\d+)/);return t?Number(t[1]):void 0}function g(e=`bin/otto.js`){let t=c(`ps`,[`-axo`,`pid=,ppid=,rss=,tty=,etime=,args=`],{encoding:`utf8`,timeout:1e4,maxBuffer:16*1024*1024});return t.status!==0||!t.stdout?[]:_(t.stdout,e)}function _(e,t=`bin/otto.js`){let n=[];for(let r of e.split(`
2
2
  `)){if(!r.includes(t))continue;let e=r.match(/^\s*(\d+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(\S+)\s+(.*)$/);if(!e)continue;let[,i,a,o,s,c,l]=e;l.includes(`spawn-helper`)||n.push({pid:Number(i),ppid:Number(a),rssKb:Number(o),tty:s,etimeMs:h(c),command:l,sessionId:ee(l),generation:te(l)})}return n}function v(){if(process.platform===`darwin`)return!1;try{if(n(`/.dockerenv`))return!0;if(n(`/proc/1/cgroup`)){let e=r(`/proc/1/cgroup`,`utf8`);return/docker|kubepods|containerd/.test(e)}}catch{}return!1}const y={stream:{maxRetries:5,initialDelayMs:500,backoffFactor:2,maxDelayMs:6e4},networkDisconnect:{maxRetries:5,intervalMs:3e4},mcp:{maxReconnectAttempts:3,reconnectDelayMs:500,requestTimeoutMs:3e4},schedule:{retryBackoffMs:0},errorRetry:{maxAttempts:5,intervalMs:3e4},oauth:{refreshLockTimeoutMs:15e3}},b={stream:[`maxRetries`,`initialDelayMs`,`backoffFactor`,`maxDelayMs`],networkDisconnect:[`maxRetries`,`intervalMs`],mcp:[`maxReconnectAttempts`,`reconnectDelayMs`,`requestTimeoutMs`],schedule:[`retryBackoffMs`],errorRetry:[`maxAttempts`,`intervalMs`],oauth:[`refreshLockTimeoutMs`]},x=Object.keys(b),S=new Set([`mcp.maxReconnectAttempts`,`schedule.retryBackoffMs`]);function ne(e,t,n){return typeof n!=`number`||!Number.isFinite(n)||(S.has(`${e}.${t}`)?n<0:n<=0)?!1:e===`oauth`&&t===`refreshLockTimeoutMs`?n>=1e3:!0}function C(e,t){if(typeof e!=`object`||!e||Array.isArray(e)){t(`resilience config must be an object, got: ${typeof e}`);return}let n={},r=e;for(let e of Object.keys(r)){if(!x.includes(e)){t(`resilience config has unknown top-level key "${e}", ignored`);continue}let i=e,a=r[e];if(typeof a!=`object`||!a||Array.isArray(a)){t(`resilience.${i} must be an object, got: ${typeof a}, ignored`);continue}let o=a,s={};for(let e of Object.keys(o)){if(!b[i].includes(e)){t(`resilience.${i}.${e} is not a recognized field, ignored`);continue}let n=o[e];if(!ne(i,e,n)){t(`resilience.${i}.${e} has invalid value (${JSON.stringify(n)}), ignored`);continue}s[e]=n}Object.keys(s).length>0&&(n[i]=s)}return n}function w(e,t=e=>console.warn(`[resilience-config] ${e}`)){if(!e)return;let n;try{n=JSON.parse(e)}catch(e){t(`OTTO_RESILIENCE_CONFIG is not valid JSON, ignoring entirely: ${e instanceof Error?e.message:String(e)}`);return}return C(n,t)}function T(e,t){return t?{...e,...t}:e}function re(e,t,n=e=>console.warn(`[resilience-config] ${e}`)){let r=[w(process.env.OTTO_RESILIENCE_CONFIG,n),t?C(t,n):void 0,e?C(e,n):void 0],i={stream:{...y.stream},networkDisconnect:{...y.networkDisconnect},mcp:{...y.mcp},schedule:{...y.schedule},errorRetry:{...y.errorRetry},oauth:{...y.oauth}};for(let e of r)e&&(i={stream:T(i.stream,e.stream),networkDisconnect:T(i.networkDisconnect,e.networkDisconnect),mcp:T(i.mcp,e.mcp),schedule:T(i.schedule,e.schedule),errorRetry:T(i.errorRetry,e.errorRetry),oauth:T(i.oauth,e.oauth)});return i}const E=[];function D(e){let t=E.splice(0);for(let n of t)e(n)}function O(){return E.splice(0)}const k=(e,t)=>{if(e===void 0)return t;let n=parseInt(e,10);return isNaN(n)||n<=0?(E.push(`Invalid environment variable value: ${e}. Using default: ${t}`),t):n},A=(e,t)=>{if(e===void 0)return t;let n=parseFloat(e);return isNaN(n)||n<=0||n>1?(E.push(`Invalid fraction environment variable value: ${e}. Using default: ${t}`),t):n};function j(e){return o(e).replaceAll(s===`\\`?`\\`:s,`/`)}function M(e){let t=e;for(;;){if(n(a(t,`pnpm-workspace.yaml`)))return t;let e=i(t);if(e===t)return;t=e}}function N(){try{let e=j(`${j(new URL(`.`,import.meta.url).pathname)}/../package.json`);return JSON.parse(r(e,`utf-8`)).version||`unknown`}catch{return`unknown`}}const P=N(),F=`otto/${P}`,I=`.otto`,L=process.env.OTTO_CONFIG_FILENAME||`config.json`,R=`${I}/${L}`,z=j(process.env.OTTO_HOME||`${e()}/.otto`),B=`${z}/sessions`,V=`${B}/locks`,H=`${z}/daemon`,U=j(e()+`/.config/otto`),W=j(`${process.cwd()}/${I}`),G=`.claude`,K=j(`${e()}/${G}`);function q(){let e=process.env.OTTO_CLAUDE_COMPAT?.toLowerCase();return!(e===`0`||e===`false`||e===`no`||e===`off`)}function J(){if(!q())return!1;let e=process.env.OTTO_CLAUDE_COMPAT_SETTINGS?.toLowerCase();return e===`1`||e===`true`||e===`yes`||e===`on`}function Y(){if(!q())return!1;let e=process.env.OTTO_CLAUDE_COMPAT_HOOKS?.toLowerCase();return e===`1`||e===`true`||e===`yes`||e===`on`}const X=process.env.OTTO_LOG_FILE?j(process.env.OTTO_LOG_FILE):``,Z=k(process.env.OTTO_SERVICE_PORT,8417),ie=process.env.OTTO_SERVICE_URL??`http://127.0.0.1:${Z}`,ae=()=>(process.env.OTTO_NPM_SNIFF_REGISTRIES??``).split(`,`).map(e=>e.trim().replace(/\/+$/,``)).filter(e=>e.length>0),oe=process.env.OTTO_LOG_LEVEL||(process.env.NODE_ENV===`production`?`info`:`trace`),se=process.env.OTTO_OFFLINE===`1`||process.env.OTTO_OFFLINE?.toLowerCase()===`true`||process.env.OTTO_OFFLINE?.toLowerCase()===`yes`;function Q(){let e=process.env.OTTO_SHADOW?.toLowerCase();return e===`1`||e===`true`||e===`yes`||e===`on`}const ce=j(process.env.OTTO_AUTH_PATH||`${U}/auth.json`),$=j(process.env.OTTO_IDENTITY_PATH||`${z}/identity.json`);async function le(e){let t=e??$;try{let{readFile:e}=await import(`node:fs/promises`),n=await e(t,`utf-8`),r=JSON.parse(n);return typeof r.userId==`string`&&typeof r.token==`string`&&typeof r.serviceUrl==`string`&&typeof r.loginAt==`number`?r:null}catch{return null}}export{ce as AUTH_PATH,l as BUILD_ID,K as CLAUDE_HOME,G as CLAUDE_ROOT,y as DEFAULT_RESILIENCE_CONFIG,X as LOG_FILE,oe as LOG_LEVEL,L as OTTO_CONFIG_FILENAME,H as OTTO_DAEMON_DIR,z as OTTO_HOME,$ as OTTO_IDENTITY_PATH,R as OTTO_PROJECT_CONFIG_RELPATH,W as OTTO_PROJECT_DIR,I as OTTO_ROOT,B as OTTO_SESSIONS_DIR,V as OTTO_SESSION_LOCKS_DIR,F as OTTO_USER_AGENT,U as OTTO_USER_CONFIG_DIR,P as SDK_VERSION,Z as SERVICE_PORT,ie as SERVICE_URL,se as SETTING_OFFLINE_MODE_ENABLED,f as currentHostname,m as decodeLeaseToken,O as drainEnvWarnings,p as encodeLeaseToken,M as findWorkspaceRoot,D as flushEnvWarnings,q as isClaudeCompatEnabled,Y as isClaudeHooksCompatEnabled,J as isClaudeSettingsCompatEnabled,v as isContainerEnvironment,d as isProcessAlive,Q as isShadowModeEnabled,g as listOttoProcesses,le as loadUserIdentity,k as normalizeEnv,A as normalizeEnvFraction,j as normalizePath,h as parseEtimeMs,_ as parseOttoProcessTable,w as parseResilienceEnv,u as resolveConfigLayers,ae as resolveNpmSniffRegistries,re as resolveResilienceConfig,C as validateResilienceOverride};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@x-otto/env",
3
- "version": "0.1.0-alpha.2",
3
+ "version": "0.1.0-alpha.3",
4
4
  "files": [
5
5
  "dist"
6
6
  ],