UNPKG

grix-connector

Version:

Connect local AI coding agents (Claude, Codex, Gemini, Qwen, DeepSeek, Cursor, OpenCode, Pi, OpenHuman, Reasonix) to the Grix scheduling platform. Also serves as an OpenClaw plugin for Grix channel transport.

3 lines (2 loc) 2.28 kB
import{appendFileSync as B,existsSync as y,mkdirSync as x,renameSync as d,statSync as S,unlinkSync as L}from"node:fs";import{appendFile as w,mkdir as g,rename as _,rm as N,stat as l}from"node:fs/promises";import m from"node:path";const O=10*1024*1024,A=5,I="GRIX_CONNECTOR_LOG_MAX_BYTES",T="GRIX_CONNECTOR_LOG_MAX_FILES";function p(t,r){const e=typeof t=="number"?t:Number.parseInt(String(t??""),10);return Number.isFinite(e)&&e>0?Math.floor(e):r}function G(t=process.env){return{maxBytes:p(t[I],O),maxFiles:p(t[T],A)}}function E(t={}){const r=G();return{maxBytes:p(t.maxBytes,r.maxBytes),maxFiles:p(t.maxFiles,r.maxFiles)}}function u(t,r){return`${t}.${r}`}async function R(t,r=0,e={}){const{maxBytes:n,maxFiles:s}=E(e),f=await l(t).catch(o=>{if(o.code==="ENOENT")return null;throw o});if(!(!f||f.size+r<=n)){await g(m.dirname(t),{recursive:!0}),await N(u(t,s),{force:!0});for(let o=s-1;o>=1;o-=1){const c=u(t,o),i=u(t,o+1);await _(c,i).catch(a=>{if(a.code!=="ENOENT")throw a})}await _(t,u(t,1))}}async function Y(t,r,e={}){const n=typeof r=="string"?r:Buffer.from(r),s=typeof n=="string"?Buffer.byteLength(n):n.byteLength;await g(m.dirname(t),{recursive:!0}),await R(t,s,e),await w(t,n)}function X(t,r=0,e={}){const{maxBytes:n,maxFiles:s}=E(e);if(!y(t)||S(t).size+r<=n)return;x(m.dirname(t),{recursive:!0});const o=u(t,s);y(o)&&L(o);for(let c=s-1;c>=1;c-=1){const i=u(t,c);y(i)&&d(i,u(t,c+1))}d(t,u(t,1))}function b(t,r,e={}){const n=Buffer.from(r);x(m.dirname(t),{recursive:!0}),X(t,n.byteLength,e),B(t,n)}function $(t,r,e={}){F(process.stdout,t,e),F(process.stderr,r,e)}function F(t,r,e){const n=t.write.bind(t);t.write=((s,f,o)=>{const c=typeof f=="function"?f:o;try{const a=M(s,typeof f=="string"?f:"utf8");return b(r,a,e),c?.(null),!0}catch(i){return n(`grix-connector log write failed: ${i instanceof Error?i.message:String(i)} `),c?.(i instanceof Error?i:new Error(String(i))),!1}})}function M(t,r){return Buffer.isBuffer(t)?t:t instanceof Uint8Array?Buffer.from(t):Buffer.from(String(t??""),r)}export{O as DEFAULT_LOG_MAX_BYTES,A as DEFAULT_LOG_MAX_FILES,I as LOG_MAX_BYTES_ENV,T as LOG_MAX_FILES_ENV,Y as appendRotatingFile,b as appendRotatingFileSync,$ as installProcessLogRotation,G as resolveLogRotationOptions,R as rotateFileIfNeeded,X as rotateFileIfNeededSync};