vibe64 0.1.50 → 0.1.51
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.
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
import { createRequire as __vibe64CreateRequire } from 'node:module';const require=__vibe64CreateRequire(import.meta.url);
|
|
3
3
|
import{spawn as pr,spawnSync as P}from"node:child_process";import{createHash as dr}from"node:crypto";import{chmodSync as fr,
|
|
4
4
|
closeSync as w,constants as $,existsSync as Y,fchmodSync as de,fchownSync as ne,fstatSync as J,lstatSync as Ee,mkdirSync as Z,
|
|
5
|
-
openSync as M,readFileSync as N,readSync as ft,readdirSync as fe,realpathSync as
|
|
5
|
+
openSync as M,readFileSync as N,readSync as ft,readdirSync as fe,realpathSync as ie,renameSync as Se,rmSync as Ve,statSync as hr,
|
|
6
6
|
unlinkSync as q,writeFileSync as he}from"node:fs";import p from"node:path";import{createConnection as gr}from"node:net";
|
|
7
7
|
import{constants as wr}from"node:os";import h from"node:process";var yr=4*1024*1024,Er=1024*1024,ht=4*Math.ceil(yr/3)+Er,
|
|
8
8
|
B=$.O_RDONLY|$.O_DIRECTORY|$.O_NOFOLLOW,gt=$.O_WRONLY|$.O_CREAT|$.O_EXCL|$.O_NOFOLLOW,Sr=$.O_RDONLY|$.O_NOFOLLOW|$.O_NONBLOCK,
|
|
9
|
-
|
|
9
|
+
vr=/^[A-Za-z0-9][A-Za-z0-9._-]{0,254}$/u,br=64*1024,wt=[".local","state","vibe64","users"],yt=64*1024,xr=64,kr=64*1024,Or=10,
|
|
10
10
|
Ar=15e3,Mr="vibe64.exec-helper.payload",Nr=1,_r=new Set(["account-auth-terminal","application-account","account-status",
|
|
11
11
|
"codex-app-server","create-system-user","deployment-service","enable-system-user","github-api-command","github-toolchain",
|
|
12
12
|
"github-workflow-command","health-status","managed-execution","managed-service","opencode-app-server","vibe64-command","\
|
|
13
13
|
workspace-cache-command"]),Et=new Set(["bash","gh","git"]),St=/^[A-Za-z_][A-Za-z0-9_]*$/u,Tr=new Set(["BASH_ENV","ENV","\
|
|
14
14
|
GCONV_PATH","GETCONF_DIR","GLIBC_TUNABLES","HOSTALIASES","LOCALDOMAIN","LD_AUDIT","LD_LIBRARY_PATH","LD_PRELOAD","LOCPAT\
|
|
15
|
-
H","MALLOC_TRACE","NIS_PATH","NLSPATH","NODE_OPTIONS","RESOLV_HOST_CONF","RES_OPTIONS","TZDIR"]),
|
|
15
|
+
H","MALLOC_TRACE","NIS_PATH","NLSPATH","NODE_OPTIONS","RESOLV_HOST_CONF","RES_OPTIONS","TZDIR"]),ve=["/opt/vibe64/runtim\
|
|
16
16
|
e-packs/policy-bin","/opt/vibe64/runtime-packs/operator-clis/bin","/opt/vibe64/runtime-packs/node26/bin","/opt/vibe64/ru\
|
|
17
17
|
ntime-packs/git/bin","/opt/vibe64/runtime-packs/gh/bin","/opt/vibe64/runtime-packs/ripgrep/bin","/opt/vibe64/runtime-pac\
|
|
18
18
|
ks/bubblewrap/bin","/opt/vibe64/runtime-packs/bun/bin","/opt/vibe64/runtime-packs/php/bin","/opt/vibe64/runtime-packs/co\
|
|
@@ -21,8 +21,8 @@ on/bin","/opt/vibe64/runtime-packs/ruby/bin","/opt/vibe64/runtime-packs/go/bin",
|
|
|
21
21
|
pt/vibe64/runtime-packs/kotlin/bin","/opt/vibe64/runtime-packs/csharp/bin","/opt/vibe64/runtime-packs/rust/bin","/opt/vi\
|
|
22
22
|
be64/runtime-packs/mariadb/bin","/opt/vibe64/runtime-packs/postgresql/bin","/opt/vibe64/runtime-packs/sqlite/bin","/opt/\
|
|
23
23
|
vibe64/runtime-packs/playwright/bin","/opt/vibe64/runtime-packs/guard-bin","/usr/local/sbin","/usr/local/bin","/usr/sbin",
|
|
24
|
-
"/usr/bin","/sbin","/bin"].join(":"),
|
|
25
|
-
["root"]),Ue="/etc/vibe64",Ge=p.join(Ue,"people"),
|
|
24
|
+
"/usr/bin","/sbin","/bin"].join(":"),vt=/^[a-z][a-z0-9_-]{0,61}[a-z0-9]$/u,G="vibe64",U="v64d_",be="/var/lib/vibe64",Rr=new Set(
|
|
25
|
+
["root"]),Ue="/etc/vibe64",Ge=p.join(Ue,"people"),bt="vibe64.person-registration",xt=4096,Pe=3,Ir="/etc/vibe64/person-su\
|
|
26
26
|
do-commands",$r=new Set(["adm","admin","disk","docker","incus","incus-admin","kmem","libvirt","lxd","root","shadow","sta\
|
|
27
27
|
ff","sudo","wheel"]),We="v64a_",kt=new RegExp(`^${We}[a-f0-9]{12}$`,"u"),xe=p.join(Ue,"applications"),Ot="vibe64.applica\
|
|
28
28
|
tion-account",ke="/var/lib/vibe64-apps",ge="/etc/systemd/system",at="resource-controller.sock",Re="/run/vibe64-applicati\
|
|
@@ -34,19 +34,19 @@ d"){await Hr(h.argv[3]||"");return}if(h.argv[2]==="run-release-service"){Hn(h.ar
|
|
|
34
34
|
"upgrade-person-registry"){if(h.argv.length!==4)throw new Error("Usage: vibe64-exec-helper upgrade-person-registry <work\
|
|
35
35
|
space>");xn(h.argv[3]);return}if(h.argv[2]==="register-person"){if(h.argv.length!==5)throw new Error("Usage: vibe64-exec\
|
|
36
36
|
-helper register-person <workspace> <username>");Xt(h.argv[3],h.argv[4]);return}if(h.argv[2]==="check-person"){if(h.argv.
|
|
37
|
-
length!==4)throw new Error("Usage: vibe64-exec-helper check-person <username>");
|
|
37
|
+
length!==4)throw new Error("Usage: vibe64-exec-helper check-person <username>");ce(h.argv[3]),ze(F(h.argv[3]),Me(h.argv[3]));
|
|
38
38
|
return}if(h.argv[2]!=="execute"||h.argv.length>4)throw new Error("Usage: vibe64-exec-helper execute [payload-json-file]");
|
|
39
39
|
let e=h.argv[3]||"",t=e?Fr(e,Q()):Yn();wn(t);let r=String(t.operation||"").trim();if(!_r.has(r))throw new Error("Vibe64 \
|
|
40
40
|
exec helper rejected an unknown operation.");if(e&&r!=="managed-execution")throw new Error("Vibe64 exec helper accepts a\
|
|
41
41
|
payload file only for a managed execution.");if(r==="deployment-service"){Pn(t);return}if(r==="managed-service"){Dn(t);
|
|
42
42
|
return}if(r==="managed-execution"){Wr(t);return}if(r==="application-account"){On(t);return}let n=O(t.username);if(r==="c\
|
|
43
|
-
reate-system-user"||r==="enable-system-user"){yn(r,t,n);return}
|
|
43
|
+
reate-system-user"||r==="enable-system-user"){yn(r,t,n);return}ce(n);let o=String(t.command||"").trim();if(!Et.has(o))throw new Error(
|
|
44
44
|
"Vibe64 exec helper rejected an unknown command.");let s=F(n);oe("uid",t.uid,s.uid),oe("gid",t.gid,s.gid);let i=Q();Ht(i,
|
|
45
45
|
s);let c=ar(t.cwd||"",i.username,{operation:r,targetUser:s}),a=it(t.env||{},s,i.username,r),u=Array.isArray(t.args)?t.args.
|
|
46
46
|
map(d=>String(d)):[],l=t.inputBase64?Buffer.from(String(t.inputBase64),"base64"):void 0;h.umask(7);let m=Gr(s,o,u,{cwd:c,
|
|
47
47
|
env:a,...l===void 0?{stdio:"inherit"}:{input:l,stdio:["pipe","inherit","inherit"]}});if(m.error)throw m.error;h.exit(typeof m.
|
|
48
48
|
status=="number"?m.status:1)}function Gr(e,t,r,n){return P("/usr/bin/setpriv",["--no-new-privs","--","/usr/sbin/runuser",
|
|
49
|
-
"-u",e.username,"--","/usr/bin/env","--",`PATH=${n.env.PATH}`,t,...r],{...n,env:{...n.env,PATH:
|
|
49
|
+
"-u",e.username,"--","/usr/bin/env","--",`PATH=${n.env.PATH}`,t,...r],{...n,env:{...n.env,PATH:ve}})}function Wr(e={}){let t=Q(),
|
|
50
50
|
r=Ne(G),n=String(e.action||"").trim();if(n.startsWith("workflow-")){let D=Zr(e,t);h.stdout.write(`${JSON.stringify(D)}
|
|
51
51
|
`),D.ok!==!0&&(h.exitCode=1);return}if(n==="release-ended"){h.stdout.write(`${JSON.stringify(gn(t,e.keepExecutionIds))}
|
|
52
52
|
`);return}let o=z(e.executionId),s=ye(o,t);if(n==="inspect"){mn(s,o,t);return}if(n==="stop"){let D=hn(s,o,t,{termTimeoutMs:fn(
|
|
@@ -62,24 +62,24 @@ helper rejected an unsupported real-user managed command.");let S=Array.isArray(
|
|
|
62
62
|
e.env||{},m,t.username,f);if(e.usageRecordingPreload){if(d)throw new Error("An application account does not run the usag\
|
|
63
63
|
e recorder.");R.NODE_OPTIONS=io(e.usageRecordingPreload)}let C="";if(e.releaseEnvironmentFile){if(!d)throw new Error("Re\
|
|
64
64
|
lease environment requires an application's own execution.");C=Jt(e.releaseEnvironmentFile,d,{cwd:g,daemonUid:t.uid,gid:m.
|
|
65
|
-
gid})}let I=K(e.memoryMaxBytes,pe,_t,"memory limit"),
|
|
66
|
-
work-slice memory limit"),_=K(e.workTasksMax,Ce,De,"work-slice task limit");if(I>b
|
|
67
|
-
per rejected an execution limit above its work-slice limit.");let st=Ye(t);if(e.workflow){let D=Rt(e.workflow,t),
|
|
68
|
-
if(
|
|
69
|
-
without its active workflow group.");if(I>
|
|
70
|
-
an execution limit above its workflow limit.");st=D.unitName}else Yr(t,{memoryMaxBytes:
|
|
65
|
+
gid})}let I=K(e.memoryMaxBytes,pe,_t,"memory limit"),b=K(e.tasksMax,Ce,De,"task limit"),v=K(e.workMemoryMaxBytes,Br,Fe,"\
|
|
66
|
+
work-slice memory limit"),_=K(e.workTasksMax,Ce,De,"work-slice task limit");if(I>v||b>_)throw new Error("Vibe64 exec hel\
|
|
67
|
+
per rejected an execution limit above its work-slice limit.");let st=Ye(t);if(e.workflow){let D=Rt(e.workflow,t),ue=X(D);
|
|
68
|
+
if(ue.activeState!=="active"||!ue.controlGroup||ue.finishedAt)throw new Error("Vibe64 exec helper rejected an execution \
|
|
69
|
+
without its active workflow group.");if(I>ue.memoryMaxBytes||b>ue.tasksMax)throw new Error("Vibe64 exec helper rejected \
|
|
70
|
+
an execution limit above its workflow limit.");st=D.unitName}else Yr(t,{memoryMaxBytes:v,tasksMax:_});let Te=d?$t(t,{create:!0}):
|
|
71
71
|
jt(t,{create:!0,gid:r}),ct=Te.create(o,m,{...d?{application:!0}:{},args:S,command:y,controllerLeaseName:l,cwd:g,env:R,inputBase64:String(
|
|
72
72
|
e.inputBase64||""),inputPresent:e.inputPresent===!0,...C?{releaseEnvironmentFile:C}:{},executionId:o},{privateDirectory:i===
|
|
73
73
|
"detached"}),ur=p.join(ct,"command.json"),lr=p.resolve(h.argv[1]),mr=["--quiet",`--unit=${s}`,"--service-type=exec",`--s\
|
|
74
74
|
lice=${st}`,`--property=Description=Vibe64 ${c} execution`,...It(m,{receiptRoot:ct}).map(D=>`--property=${D}`),`--proper\
|
|
75
75
|
ty=WorkingDirectory=${g}`,"--property=KillMode=control-group","--property=ExitType=cgroup","--property=OOMPolicy=stop","\
|
|
76
76
|
--property=MemoryAccounting=yes","--property=IOAccounting=yes","--property=TasksAccounting=yes",`--property=MemoryMax=${I}`,
|
|
77
|
-
`--property=TasksMax=${
|
|
77
|
+
`--property=TasksMax=${b}`,"--property=TimeoutStopSec=10s",...i==="capture"?["--property=LogLevelMax=notice","--wait","-\
|
|
78
78
|
-pipe"]:[],...i==="pty"?["--wait","--pty"]:[],...m.username!==t.username?["/usr/bin/setpriv","--no-new-privs","--"]:[],lr,
|
|
79
79
|
"run-managed",ur],re=P("systemd-run",mr,{stdio:"inherit"});if((i!=="detached"||re.error||re.status!==0)&&Te.remove(o),Te.
|
|
80
|
-
close(),re.error)throw re.error;h.exit(typeof re.status=="number"?re.status:1)}function Fr(e="",t={},{managedRoot:r=
|
|
80
|
+
close(),re.error)throw re.error;h.exit(typeof re.status=="number"?re.status:1)}function Fr(e="",t={},{managedRoot:r=be}={}){
|
|
81
81
|
let n=p.join(r,T(O(t.username))),o=["tmp","managed-execution-payloads"],s=p.basename(String(e));if(e!==p.join(n,...o,s)||
|
|
82
|
-
!
|
|
82
|
+
!vr.test(s))throw new Error("Vibe64 exec helper rejected an unsafe managed execution payload path.");let i=ae(n,o);try{if(J(
|
|
83
83
|
i).uid!==t.uid)throw new Error("Vibe64 exec helper refused a managed execution payload directory owned by another user.");
|
|
84
84
|
let c=H(i,s,{maxBytes:ht,uid:t.uid});return q(E(i,s)),tr(c)}finally{w(i)}}async function Hr(e=""){let t=p.resolve(String(
|
|
85
85
|
e||"")),r=N(t,"utf8");q(t);let n=JSON.parse(r);if(n?.schema!=="vibe64.managed-execution.command"||n?.schemaVersion!==1)throw new Error(
|
|
@@ -213,7 +213,7 @@ LOOP","ENOTDIR","ENXIO","EVIBE64UNSAFEFILE"]);function Pt(e="",{create:t=!1,gid:
|
|
|
213
213
|
t&&we(e,o);let i;try{i=M(e,B)}catch(c){if(!t&&c?.code==="ENOENT")return on;throw c}try{let c=J(i).uid;if(c!==s&&c!==n)throw new Error(
|
|
214
214
|
"Vibe64 exec helper refused an execution receipt directory owned by another user.");t&&(ne(i,s,r),de(i,o))}catch(c){throw w(
|
|
215
215
|
i),c}return{close:()=>w(i),entries:()=>fe(E(i)),remove:c=>Ve(E(i,z(c)),{force:!0,recursive:!0}),result(c=""){let a=z(c),
|
|
216
|
-
u=-1;try{u=M(E(i,a),B);let l=JSON.parse(H(u,"result.json",{maxBytes:
|
|
216
|
+
u=-1;try{u=M(E(i,a),B);let l=JSON.parse(H(u,"result.json",{maxBytes:br,uid:J(u).uid}));return l?.schema==="vibe64.manage\
|
|
217
217
|
d-execution.result"&&l.schemaVersion===1&&l.executionId===a?l:{}}catch(l){if(l instanceof SyntaxError||sn.has(l?.code))return{};
|
|
218
218
|
throw l}finally{u>=0&&w(u)}},create(c="",a={},u={},{privateDirectory:l=!1}={}){let m=z(c),d=E(i,m);Z(d,{mode:448});let f=M(
|
|
219
219
|
d,B);try{let g={...u.env};if(l){Z(E(f,"private"),{mode:448});let S=M(E(f,"private"),B);try{ne(S,a.uid,a.gid)}finally{w(S)}
|
|
@@ -225,10 +225,10 @@ he(n,`${JSON.stringify({...t,schema:"vibe64.managed-execution.result",schemaVers
|
|
|
225
225
|
`,{flag:"wx",mode:384}),Se(n,r)}function un(){let e=String(N("/proc/self/cgroup","utf8")||"").split(`
|
|
226
226
|
`).find(i=>i.startsWith("0::")),t=String(e||"").slice(3).replace(/^\/+/,""),r=t?p.join("/sys/fs/cgroup",t):"";if(!r||!Y(
|
|
227
227
|
r))return{};let n=mt(p.join(r,"cpu.stat")),o=mt(p.join(r,"memory.events")),s=ln(p.join(r,"io.stat"));return{resourceCounters:Xe(
|
|
228
|
-
r),cpuUsageNSec:String(Number(n.usage_usec||0)*1e3),ioReadBytes:String(s.readBytes),ioWriteBytes:String(s.writeBytes),memoryCurrent:
|
|
229
|
-
p.join(r,"memory.current")),memoryPeak:
|
|
230
|
-
oomKillCount:String(Number(o.oom_kill||0)),taskLimit:Ct(r),tasksCurrent:
|
|
231
|
-
r,"pids.peak"))}}function
|
|
228
|
+
r),cpuUsageNSec:String(Number(n.usage_usec||0)*1e3),ioReadBytes:String(s.readBytes),ioWriteBytes:String(s.writeBytes),memoryCurrent:le(
|
|
229
|
+
p.join(r,"memory.current")),memoryPeak:le(p.join(r,"memory.peak")),memorySwapCurrent:le(p.join(r,"memory.swap.current")),
|
|
230
|
+
oomKillCount:String(Number(o.oom_kill||0)),taskLimit:Ct(r),tasksCurrent:le(p.join(r,"pids.current")),tasksPeak:le(p.join(
|
|
231
|
+
r,"pids.peak"))}}function le(e=""){try{let t=String(N(e,"utf8")||"0").trim();return/^[0-9]+$/u.test(t)?t:"0"}catch(t){if(t?.
|
|
232
232
|
code==="ENOENT")return"0";throw t}}function Ct(e,t=N){if(!e)return null;try{let r=c=>{try{return A(/^max\s+(\d+)$/mu.exec(
|
|
233
233
|
t(p.join(e,c),"utf8"))?.[1])}catch{return null}},n=r("pids.events.local"),o=r("pids.events"),s=n>0?n:o;if(!(s>0))return null;
|
|
234
234
|
let i=t("/proc/self/mountinfo","utf8").split(`
|
|
@@ -275,19 +275,19 @@ recordedAt:new Date(a).toISOString()}}return null}function dn(e,{unitName:t,work
|
|
|
275
275
|
"string"||Buffer.byteLength(e)>128*1024)return null;let s=e.trim().split(/\r?\n/u);if(s.length>64)return null;let i=s.flatMap(
|
|
276
276
|
a=>{try{return[JSON.parse(a)]}catch{return[]}}),c=null;for(let a of i){let u=Number(a?.__REALTIME_TIMESTAMP)/1e3;if(!Number.
|
|
277
277
|
isFinite(u)||u<n||u>o)continue;let l=a.MESSAGE;if(typeof l=="string"&&l.startsWith("oom-kill:")&&l.endsWith(",task_memcg\
|
|
278
|
-
=")){let
|
|
278
|
+
=")){let v=i.find(_=>/^[a-f0-9]{32}$/u.test(a.__SEQNUM_ID||"")&&_?.__SEQNUM_ID===a.__SEQNUM_ID&&_?._BOOT_ID===a._BOOT_ID&&
|
|
279
279
|
/^[a-f0-9]{32}$/u.test(a._BOOT_ID||"")&&Number.isSafeInteger(Number(a.__SEQNUM))&&Number(_.__SEQNUM)===Number(a.__SEQNUM)+
|
|
280
280
|
1&&Number(_._SOURCE_MONOTONIC_TIMESTAMP)>=Number(a._SOURCE_MONOTONIC_TIMESTAMP)&&Number(_._SOURCE_MONOTONIC_TIMESTAMP)-Number(
|
|
281
|
-
a._SOURCE_MONOTONIC_TIMESTAMP)<=1e6&&/^\/[a-zA-Z0-9_./-]+,task=[^,]+,pid=\d+,uid=\d+$/u.test(_.MESSAGE||""));
|
|
281
|
+
a._SOURCE_MONOTONIC_TIMESTAMP)<=1e6&&/^\/[a-zA-Z0-9_./-]+,task=[^,]+,pid=\d+,uid=\d+$/u.test(_.MESSAGE||""));v&&(l+=v.MESSAGE)}
|
|
282
282
|
let m=typeof l=="string"&&l.match(/^oom-kill:constraint=(CONSTRAINT_[A-Z_]+),.*?,(?:oom_memcg=(\/[^,]+)|(global_oom)),task_memcg=(\/[^,]+),task=/u);
|
|
283
283
|
if(!m)continue;let[,d,f,g,y]=m,S=y.split("/"),R=S.indexOf(`vibe64-${r}-work.slice`),C=S.indexOf(t);if(S[1]!=="vibe64.sli\
|
|
284
|
-
ce"||R<2||C<=R||S.some((
|
|
285
|
-
_NONE"&&g)I="host";else if(d==="CONSTRAINT_MEMCG"&&f&&(y===f||y.startsWith(`${f}/`))){let
|
|
286
|
-
0,C+1).join("/");I=f===_||f.startsWith(`${_}/`)?"execution":
|
|
287
|
-
.slice`?"workspace":
|
|
288
|
-
rkflow":/-work-p[a-f0-9]{64}-s[a-f0-9]{64}\.slice$/u.test(
|
|
289
|
-
"ancestor"}else return null;let
|
|
290
|
-
nel-journal",scope:I,cgroup:
|
|
284
|
+
ce"||R<2||C<=R||S.some((v,_)=>_>0&&(v==="."||v===".."||!/^[a-zA-Z0-9_.-]+$/u.test(v))))continue;let I;if(d==="CONSTRAINT\
|
|
285
|
+
_NONE"&&g)I="host";else if(d==="CONSTRAINT_MEMCG"&&f&&(y===f||y.startsWith(`${f}/`))){let v=f.split("/").at(-1),_=S.slice(
|
|
286
|
+
0,C+1).join("/");I=f===_||f.startsWith(`${_}/`)?"execution":v===`vibe64-${r}-work.slice`?"workspace_work":v===`vibe64-${r}\
|
|
287
|
+
.slice`?"workspace":v==="vibe64.slice"?"platform":/-work-p[a-f0-9]{64}-s[a-f0-9]{64}-w[a-f0-9]{32}\.slice$/u.test(v)?"wo\
|
|
288
|
+
rkflow":/-work-p[a-f0-9]{64}-s[a-f0-9]{64}\.slice$/u.test(v)?"session":/-work-p[a-f0-9]{64}\.slice$/u.test(v)?"project":
|
|
289
|
+
"ancestor"}else return null;let b=f||"";if(c&&c.cgroup!==b)return null;(!c||u>Date.parse(c.recordedAt))&&(c={source:"ker\
|
|
290
|
+
nel-journal",scope:I,cgroup:b,recordedAt:new Date(u).toISOString()})}return c}function fn(e){if(e==null)return Le;if(!Number.
|
|
291
291
|
isSafeInteger(e)||e<0)throw new Error("Vibe64 exec helper rejected an invalid managed execution stop timeout.");return Math.
|
|
292
292
|
min(e,Le)}function hn(e="",t="",r={},{termTimeoutMs:n=Le,run:o=j,readState:s=()=>Dt(e,t,r),removeRuntime:i=()=>{let u=Ke(
|
|
293
293
|
r);try{u.remove(t)}finally{u.close()}},now:c=Date.now,wait:a=u=>Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,
|
|
@@ -303,50 +303,51 @@ split(/\r?\n/u)){let[d="",,f=""]=m.trim().split(/\s+/u);!d||s.has(d)||(f==="fail
|
|
|
303
303
|
let u=0,l=n();try{for(let m of l.entries()){if(!Nt.test(m)||m!==m.toLowerCase())continue;let d=ye(m,e);s.has(d)||c.has(d)||
|
|
304
304
|
(l.remove(m),u+=1)}}finally{l.close()}for(let m=0;m<a.length;m+=256)o(a.slice(m,m+256));return{ok:!0,released:u,reset:a.
|
|
305
305
|
length}}function wn(e={}){if(e?.schema!==Mr||e?.schemaVersion!==Nr)throw new Error("Vibe64 exec helper rejected a non-no\
|
|
306
|
-
rmalized execution payload.")}function yn(e="",t={},r=""){
|
|
306
|
+
rmalized execution payload.")}function yn(e="",t={},r=""){ce(r);let n=Lt(Q());if(Ne(G),e==="create-system-user"){qn(r,String(
|
|
307
307
|
t.password||"")),Xt(n,r);return}En(n,r)}function En(e="",t="",{addToGroup:r=s=>rr(s,G),resolveUser:n=F,...o}={}){Ft(e,n(
|
|
308
308
|
t),o),r(t)}function Lt(e={}){let t=String(e.username||"");if(!t.startsWith(U))throw new Error("Only a workspace daemon a\
|
|
309
309
|
cts as its people.");return Ae(t.slice(U.length))}function Ae(e=""){if(!/^[a-z][a-z0-9]{0,62}$/u.test(String(e)))throw new Error(
|
|
310
|
-
"Vibe64 exec helper rejected an invalid workspace name.");return e}function
|
|
310
|
+
"Vibe64 exec helper rejected an invalid workspace name.");return e}function se(e="",t=0){let r=M(e,B);try{let n=J(r);if(!n.
|
|
311
311
|
isDirectory()||n.uid!==t||(n.mode&18)!==0)throw new Error("A Vibe64 registry is not a directory only root can change.")}catch(n){
|
|
312
312
|
throw w(r),n}return r}function ee(e="",{create:t=!1,registryRoot:r="",registryUid:n=0}={}){t&&Z(r,{mode:493,recursive:!0});
|
|
313
|
-
let o=
|
|
313
|
+
let o=se(r,n);try{let s=te(e);return t&&we(E(o,s),493),se(E(o,s),n)}finally{w(o)}}function Sn(e="",t="",r={}){let n=r.registryUid??
|
|
314
314
|
0,o;try{o=ee(e,{registryRoot:Ge,...r})}catch{return null}try{let s=JSON.parse(H(o,`${t}.json`,{maxBytes:xt,othersMayWrite:!1,
|
|
315
|
-
uid:n}));return s?.schema===
|
|
315
|
+
uid:n}));return s?.schema===bt&&s.schemaVersion===1&&s.username===t&&Number.isSafeInteger(s.uid)?{uid:s.uid,username:t}:
|
|
316
316
|
null}catch{return null}finally{w(o)}}function Bt(e,t={}){let r=`${te(t.username)}.json`,n=`.${r}.${h.pid}.tmp`,o=M(E(e,n),
|
|
317
317
|
gt,420);try{de(o,420),he(o,`${JSON.stringify(t)}
|
|
318
|
-
`)}finally{w(o)}Se(E(e,n),E(e,r))}function Vt(e,t={}){Bt(e,{schema:
|
|
318
|
+
`)}finally{w(o)}Se(E(e,n),E(e,r))}function Vt(e,t={}){Bt(e,{schema:bt,schemaVersion:1,uid:t.uid,username:t.username})}function Ut(e=""){
|
|
319
319
|
return Object.assign(new Error(e),{exitCode:Pe})}function Be(e=""){let t=(r,n)=>{let o=new RegExp(`^[\\t ]*${r}[\\t ]+(\\d\
|
|
320
320
|
+)[\\t ]*$`,"mu").exec(String(e));return o?Number(o[1]):n};return{max:t("UID_MAX",6e4),min:t("UID_MIN",1e3)}}function Gt(e={},{
|
|
321
|
-
groups:t=[],loginUids:r=Be(),
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
`),o
|
|
326
|
-
|
|
327
|
-
l=>
|
|
328
|
-
|
|
329
|
-
t in a directory only root can
|
|
321
|
+
groups:t=[],loginUids:r=Be(),resolveProgram:n=i=>i,sudoCommands:o=[],sudoListing:s=""}={}){let{uid:i,username:c}=e;if(!Number.
|
|
322
|
+
isSafeInteger(i)||i<r.min||i>r.max)return`${c} is a system account (uid ${i}), not a person's login.`;let a=t.find(u=>$r.
|
|
323
|
+
has(u));return a?`${c} is in the administrators' group ${a}.`:vn(c,s,o,n)}function vn(e="",t="",r=[],n=o=>o){if(t.includes(
|
|
324
|
+
`User ${e} is not allowed to run sudo on `))return"";let o=t.split(`
|
|
325
|
+
`),s=o.findIndex(l=>l.startsWith(`User ${e} may run the following commands on `)),i=s<0?[]:o.slice(s+1).filter(l=>l.trim()),
|
|
326
|
+
c=l=>{let[m,...d]=l.split(" ");try{return[n(m),...d].join(" ")}catch{return l}},a=new Set(r.map(c));return i.length>0&&i.
|
|
327
|
+
every(l=>{let m=/^ {4}\(root\) NOPASSWD: (.+)$/u.exec(l);return!!m&&m[1].split(", ").every(d=>a.has(c(d)))})?"":`${e} ha\
|
|
328
|
+
s sudo rules.`}function bn(e=Ir,t=0){let r;try{r=M(p.dirname(e),B)}catch(n){if(n.code==="ENOENT")return[];throw n}try{let n=J(
|
|
329
|
+
r);if(n.uid!==t||(n.mode&18)!==0)throw new Error("The Vibe64 person sudo commands are not in a directory only root can c\
|
|
330
|
+
hange.");return H(r,p.basename(e),{maxBytes:4096,othersMayWrite:!1,uid:t}).split(`
|
|
330
331
|
`).map(o=>o.trim()).filter(Boolean)}catch(n){if(n.code==="ENOENT")return[];throw n}finally{w(r)}}function Wt(){try{return Be(
|
|
331
332
|
N("/etc/login.defs","utf8"))}catch{return Be()}}function Me(e=""){let t=Wt(),r=P("/usr/bin/sudo",["-n","-l","-U",e],{encoding:"\
|
|
332
333
|
utf8",env:{COLUMNS:"100000",LANG:"C",LC_ALL:"C",PATH:"/usr/sbin:/usr/bin:/sbin:/bin"}});return{groups:tt(e),loginUids:t,
|
|
333
|
-
sudoCommands:
|
|
334
|
-
|
|
335
|
-
username),Sn(e,t.username,n)?.uid!==t.uid)throw Ut(`OS user ${t.username} is not registered as a Vibe64 person
|
|
336
|
-
|
|
337
|
-
username}`);let s=r(t.username);return ze(t,s),s}function Ht(e={},t={},r={}){if(!Ft(Lt(e),t,r).groups.includes(
|
|
338
|
-
`OS user is not enabled for the shared Vibe64 group: ${t.username}`);ro(e,t.username)}function Xt(e="",t="",{
|
|
339
|
-
i,G),facts:n=Me,resolveUser:o=F,...s}={}){Ae(e),
|
|
340
|
-
create:!0});try{Vt(c,i)}finally{w(c)}return r(t),i}function xn(e="",{facts:t=Me,registryRoot:r=Ge,
|
|
341
|
-
stdout.write(`${i}
|
|
342
|
-
`),resolveUser:s=F}={}){Ae(e);let i=s(`${U}${e}`);Z(r,{mode:493,recursive:!0});let c=
|
|
334
|
+
resolveProgram:ie,sudoCommands:bn(),sudoListing:r.error?"":String(r.stdout||"")}}function ze(e={},t={}){let r=Gt(e,t);if(r)
|
|
335
|
+
throw Ut(`Vibe64 never runs commands as an administrator or system account: ${r}`)}function Ft(e="",t={},{facts:r=Me,...n}={}){
|
|
336
|
+
if(ce(t.username),Sn(e,t.username,n)?.uid!==t.uid)throw Ut(`OS user ${t.username} is not registered as a Vibe64 person o\
|
|
337
|
+
f workspace ${e}. A server administrator registers an existing account with: sudo ${p.resolve(h.argv[1])} register-perso\
|
|
338
|
+
n ${e} ${t.username}`);let s=r(t.username);return ze(t,s),s}function Ht(e={},t={},r={}){if(!Ft(Lt(e),t,r).groups.includes(
|
|
339
|
+
G))throw new Error(`OS user is not enabled for the shared Vibe64 group: ${t.username}`);ro(e,t.username)}function Xt(e="",t="",{
|
|
340
|
+
addToGroup:r=i=>rr(i,G),facts:n=Me,resolveUser:o=F,...s}={}){Ae(e),ce(t),o(`${U}${e}`);let i=o(t);ze(i,n(t));let c=ee(e,
|
|
341
|
+
{registryRoot:Ge,...s,create:!0});try{Vt(c,i)}finally{w(c)}return r(t),i}function xn(e="",{facts:t=Me,registryRoot:r=Ge,
|
|
342
|
+
registryUid:n=0,report:o=i=>h.stdout.write(`${i}
|
|
343
|
+
`),resolveUser:s=F}={}){Ae(e);let i=s(`${U}${e}`);Z(r,{mode:493,recursive:!0});let c=se(r,n);try{try{return w(ee(e,{registryRoot:r,
|
|
343
344
|
registryUid:n})),{imported:[],refused:[]}}catch(d){if(d.code!=="ENOENT")throw d}let a=`.${e}.upgrading`;Ve(E(c,a),{force:!0,
|
|
344
|
-
recursive:!0}),Z(E(c,a),{mode:493});let u=
|
|
345
|
+
recursive:!0}),Z(E(c,a),{mode:493});let u=se(E(c,a),n),l=[],m=[];try{for(let d of kn(i)){let f;try{ce(d),f=s(d)}catch{continue}
|
|
345
346
|
let g=t(d);if(!g.groups.includes(G))continue;let y=Gt(f,g);if(y){m.push(d),o(`[vibe64-exec-helper] Not registering ${d} \
|
|
346
347
|
as a Vibe64 person of ${e}: ${y}`);continue}Vt(u,f),l.push(d),o(`[vibe64-exec-helper] Registered ${d} as a Vibe64 person\
|
|
347
|
-
of ${e}.`)}}finally{w(u)}return Se(E(c,a),E(c,e)),{imported:l,refused:m}}finally{w(c)}}function kn(e={}){let t;try{t=
|
|
348
|
+
of ${e}.`)}}finally{w(u)}return Se(E(c,a),E(c,e)),{imported:l,refused:m}}finally{w(c)}}function kn(e={}){let t;try{t=ae(
|
|
348
349
|
e.home,wt)}catch(r){if(r.code==="ENOENT")return[];throw r}try{let r=[];for(let n of fe(E(t)).sort()){let o=n.endsWith(".\
|
|
349
|
-
json")?n.slice(0,-5):"";if(
|
|
350
|
+
json")?n.slice(0,-5):"";if(vt.test(o))try{JSON.parse(H(t,n,{maxBytes:yt,uid:e.uid}))?.username===o&&r.push(o)}catch{}}return r}finally{
|
|
350
351
|
w(t)}}function On(e={}){let t=Q(),r=String(e.action||"").trim();if(r!=="ensure"&&r!=="retire")throw new Error("Vibe64 ex\
|
|
351
352
|
ec helper rejected an unknown application account action.");let n=r==="ensure"?{account:Nn(t,e.project)}:Tn(t,e.project);
|
|
352
353
|
h.stdout.write(`${JSON.stringify({ok:!0,...n})}
|
|
@@ -366,23 +367,23 @@ return null}try{let s=JSON.parse(H(o,`${te(t)}.json`,{maxBytes:xt,othersMayWrite
|
|
|
366
367
|
1&&s.username===t&&Number.isSafeInteger(s.uid)&&Number.isSafeInteger(s.gid)&&Mt.test(String(s.project))?{gid:s.gid,project:s.
|
|
367
368
|
project,uid:s.uid,username:t}:null}catch{return null}finally{w(o)}}function Kt(e={},t={},{registryRoot:r=xe,registryUid:n=0}={}){
|
|
368
369
|
let o=ee(e.workspace,{create:!0,registryRoot:r,registryUid:n});try{Bt(o,{gid:t.gid,project:e.project,schema:Ot,schemaVersion:1,
|
|
369
|
-
uid:t.uid,username:e.username})}finally{w(o)}}function
|
|
370
|
+
uid:t.uid,username:e.username})}finally{w(o)}}function me(e,t="",{gid:r,mode:n,uid:o},{verify:s=!0}={}){let i=E(e,te(t)),
|
|
370
371
|
c=we(i,448);if(!c&&!s)return{created:c,descriptor:-1};let a=M(i,B);try{if(c)ne(a,o,r),de(a,n);else if(s){let u=J(a);if(u.
|
|
371
372
|
uid!==o||u.gid!==r||n===457&&(u.mode&18)!==0)throw new Error(`The application area's ${t} directory is not the one the h\
|
|
372
373
|
elper made.`)}return{created:c,descriptor:a}}catch(u){throw w(a),u}}function et(e={},{areaGid:t=0,areaUid:r=0,create:n=!0}={}){
|
|
373
374
|
let o=M(p.dirname(e.areaRoot),$.O_RDONLY|$.O_DIRECTORY);try{for(let s of[p.basename(e.areaRoot),e.workspace,e.project]){
|
|
374
|
-
let i;n?i=
|
|
375
|
+
let i;n?i=me(o,s,{gid:t,mode:457,uid:r}).descriptor:i=se(E(o,te(s)),r),w(o),o=i}return o}catch(s){throw w(o),s}}function An(e={},t={},r={},{
|
|
375
376
|
areaGid:n=0,areaUid:o=0,grantDaemonSearch:s=i=>k("setfacl",["-m",`u:${O(t.username)}:x`,`/proc/${h.pid}/fd/${i}`])}={}){
|
|
376
|
-
let i=et(e,{areaGid:n,areaUid:o}),c=[i];try{let a={gid:r.gid,mode:448,uid:r.uid};c.push(
|
|
377
|
-
uid:t.uid}).descriptor);let u=
|
|
377
|
+
let i=et(e,{areaGid:n,areaUid:o}),c=[i];try{let a={gid:r.gid,mode:448,uid:r.uid};c.push(me(i,"handover",{gid:r.gid,mode:1512,
|
|
378
|
+
uid:t.uid}).descriptor);let u=me(i,"app",a).descriptor;c.push(u),c.push(me(u,"home",a,{verify:!1}).descriptor);let l=me(
|
|
378
379
|
i,"database",a);c.push(l.descriptor),l.created&&s(l.descriptor)}finally{for(let a of c)a>=0&&w(a)}}function Mn(e={},{applicationLimit:t,
|
|
379
|
-
managedRoot:r,registryRoot:n,registryUid:o}){try{w(
|
|
380
|
+
managedRoot:r,registryRoot:n,registryUid:o}){try{w(ae(p.join(r,e.workspace),["projects",...e.folder]))}catch(i){throw["E\
|
|
380
381
|
LOOP","ENOENT","ENOTDIR"].includes(i.code)?new Error(`Vibe64 exec helper refused an application account: ${e.workspace} \
|
|
381
382
|
has no project ${e.folder.join("/")}.`):i}let s=0;try{let i=ee(e.workspace,{registryRoot:n,registryUid:o});try{s=fe(E(i)).
|
|
382
383
|
filter(c=>c.endsWith(".json")&&kt.test(c.slice(0,-5))).length}finally{w(i)}}catch(i){if(i.code!=="ENOENT")throw i}if(s>=
|
|
383
384
|
t)throw new Error(`Vibe64 exec helper refused an application account: ${e.workspace} already has ${t}, its limit. Retire\
|
|
384
385
|
unused ones first.`)}function Nn(e={},t="",{applicationLimit:r=Cr,areaRoot:n=ke,createUser:o=m=>k("useradd",["--system",
|
|
385
|
-
"--user-group","--no-create-home","--home-dir",m.home,"--shell",At,m.username]),facts:s=qe,managedRoot:i=
|
|
386
|
+
"--user-group","--no-create-home","--home-dir",m.home,"--shell",At,m.username]),facts:s=qe,managedRoot:i=be,registryRoot:c=xe,
|
|
386
387
|
registryUid:a=0,resolveUser:u=rt,...l}={}){let m=Je(e,t,{areaRoot:n}),d={registryRoot:c,registryUid:a},f=Qe(m.workspace,
|
|
387
388
|
m.username,d),g=u(m.username);if(f){if(!g||g.uid!==f.uid||g.gid!==f.gid||f.project!==m.project)throw new Error(`The regi\
|
|
388
389
|
stered application account ${m.username} is not the account on this host.`)}else Mn(m,{applicationLimit:r,managedRoot:i,
|
|
@@ -393,16 +394,16 @@ et(e,{areaUid:t,create:!1})}catch(n){if(n.code==="ENOENT")return[];throw n}try{l
|
|
|
393
394
|
if(o.code==="ENOENT")return[];throw o}try{return fe(E(n)).sort()}finally{w(n)}}finally{w(r)}}function Tn(e={},t="",{areaRoot:r=ke,
|
|
394
395
|
areaUid:n=0,deleteUser:o=d=>k("userdel",[d]),facts:s=qe,registryRoot:i=xe,registryUid:c=0,resolveUser:a=rt,running:u=d=>P(
|
|
395
396
|
"pgrep",["-U",String(d)]).status!==1,unitRoot:l=ge,unitUid:m=0}={}){let d=Je(e,t,{areaRoot:r}),f={registryRoot:i,registryUid:c},
|
|
396
|
-
g=Qe(d.workspace,d.username,f),y=a(d.username);if(y){let
|
|
397
|
-
d.username));if(
|
|
398
|
-
{unitRoot:l,unitUid:m,workspace:d.workspace}).find(({lines:_})=>_.includes(`User=${d.username}`));if(
|
|
399
|
-
The application's release service ${
|
|
397
|
+
g=Qe(d.workspace,d.username,f),y=a(d.username);if(y){let b=g&&g.uid!==y.uid?"it is not the registered account.":Ze(y,d,s(
|
|
398
|
+
d.username));if(b)throw new Error(`Vibe64 exec helper refused to retire application account ${d.username}: ${b}`);let v=qt(
|
|
399
|
+
{unitRoot:l,unitUid:m,workspace:d.workspace}).find(({lines:_})=>_.includes(`User=${d.username}`));if(v)throw new Error(`\
|
|
400
|
+
The application's release service ${v.name} is still installed. Remove it before retiring the application.`)}let S=_n(d,
|
|
400
401
|
{areaUid:n});if(S.length>0)throw new Error(`The application's database directory still holds ${S.slice(0,5).join(", ")}${S.
|
|
401
402
|
length>5?` and ${S.length-5} more`:""}. Give its production database back to the editor before retiring the application.`);
|
|
402
|
-
let R=()=>{let
|
|
403
|
+
let R=()=>{let b=ee(d.workspace,f);try{q(E(b,`${d.username}.json`))}finally{w(b)}},C=!!(g&&y);if(C&&R(),y&&u(y.uid))throw C&&
|
|
403
404
|
Kt(d,y,f),new Error("The application still runs. Stop its release service before retiring it.");let I=-1;try{I=et(d,{areaUid:n,
|
|
404
|
-
create:!1})}catch(
|
|
405
|
-
{force:!0,recursive:!0})}finally{w(
|
|
405
|
+
create:!1})}catch(b){if(b.code!=="ENOENT")throw b}if(I>=0){w(I);let b=se(p.join(r,d.workspace),n);try{Ve(E(b,d.project),
|
|
406
|
+
{force:!0,recursive:!0})}finally{w(b)}}return g&&!C&&R(),y&&o(d.username),{retired:!!(y||g||I>=0)}}function zt(e={},t="",{
|
|
406
407
|
areaRoot:r=ke,facts:n=qe,resolveUser:o=F,...s}={}){let i=O(t),c=Qe(Yt(e),i,s);if(!c)throw new Error(`${i} is not an appl\
|
|
407
408
|
ication account of this workspace.`);let a=Je(e,c.project,{areaRoot:r}),u=o(i),l=a.username!==i||c.uid!==u.uid||c.gid!==
|
|
408
409
|
u.gid?"it is not the registered account.":Ze(u,a,n(i));if(l)throw new Error(`Vibe64 exec helper refused application acco\
|
|
@@ -415,7 +416,7 @@ m||V(m,r).length>0))throw new Error("Release environment must belong to the appl
|
|
|
415
416
|
daemonUid:r=-1,gid:n=-1}={}){let o=String(e.workingDirectory||""),s=Jt(e.environmentFile,t,{cwd:o,daemonUid:r,gid:n}),i=p.
|
|
416
417
|
basename(p.dirname(s)),c=p.join(t.appRoot,"releases",i,"workspace"),a=V(c,o),u=String(e.startScript||""),l=Ee(u);if(p.resolve(
|
|
417
418
|
o)!==o||o!==c&&a.length===0||u!==p.join(p.dirname(s),"start.sh")||!l.isFile()||l.uid!==r||l.gid!==n||(l.mode&18)!==0||(l.
|
|
418
|
-
mode&8)===0)throw new Error("A release service must run its own release's workspace and start script.");try{w(
|
|
419
|
+
mode&8)===0)throw new Error("A release service must run its own release's workspace and start script.");try{w(ae(t.appRoot,
|
|
419
420
|
["releases",i,"workspace",...a]))}catch(m){throw new Error(`A release service's working directory must be a real folder \
|
|
420
421
|
of its release's workspace: ${m.code||m.message}`)}return{environmentFile:s,startScript:u,workingDirectory:o}}function qt({
|
|
421
422
|
unitRoot:e=ge,unitUid:t=0,workspace:r=""}={}){let n=`vibe64-release-${r}-`,o=M(e,B);try{let s=[];for(let i of fe(E(o)))if(!(!i.
|
|
@@ -456,7 +457,7 @@ property=RequiredBy","--value"]).stdout||"").split(/\s+/u).filter(Boolean).filte
|
|
|
456
457
|
requiredBy:o,state:"required"};let s=!n(r(e));return s&&pt(t,["stop",e]),String(t("systemctl",["is-enabled",e]).stdout||
|
|
457
458
|
"").trim()==="enabled"&&pt(t,["disable",e]),{ok:!0,requiredBy:[],state:s?"stopped":"inactive"}}function pt(e,t=[]){let r=e(
|
|
458
459
|
"systemctl",t);if(r.status!==0)throw new Error(String(r.stderr||r.stdout||`systemctl ${t[0]} failed.`).trim())}function Bn({
|
|
459
|
-
owner:e={},pidFile:t="",unitName:r="",workspaceRoot:n=p.join(
|
|
460
|
+
owner:e={},pidFile:t="",unitName:r="",workspaceRoot:n=p.join(be,T(O(e.username)))}={}){let o=t?Un(t,e,n):null;if(o)try{Vn(
|
|
460
461
|
o,e,r)}finally{o.close()}}function Vn(e,t={},r=""){let n=e.read();if(n===null)return;if(!/^[1-9][0-9]*$/u.test(n))throw new Error(
|
|
461
462
|
"Vibe64 managed service PID file is invalid.");let o=Number(n);if(!Number.isSafeInteger(o)||o<=1)throw new Error("Vibe64\
|
|
462
463
|
managed service PID is invalid.");if(!je(o)){e.remove(n);return}let s=Gn(o);if(s===null){e.remove(n);return}if(s!==t.uid)
|
|
@@ -464,7 +465,7 @@ throw new Error("Vibe64 managed service PID belongs to another OS user.");if(Wn(
|
|
|
464
465
|
if(a?.code==="ESRCH"){e.remove(n);return}throw a}let i=Date.now()+3e4,c=new Int32Array(new SharedArrayBuffer(4));for(;je(
|
|
465
466
|
o)&&Date.now()<i;)Atomics.wait(c,0,0,100);if(je(o))throw new Error("Vibe64 managed service process did not stop cleanly \
|
|
466
467
|
during ownership transfer.");e.remove(n)}function Un(e="",t={},r=""){let n=V(x(r),p.dirname(e));if(n.length===0)throw new Error(
|
|
467
|
-
"Vibe64 exec helper rejected a managed service PID file outside its workspace.");let o;try{o=
|
|
468
|
+
"Vibe64 exec helper rejected a managed service PID file outside its workspace.");let o;try{o=ae(r,n)}catch(c){if(c?.code===
|
|
468
469
|
"ENOENT")return null;throw c}let s=p.basename(e),i=()=>{try{return H(o,s,{maxBytes:xr,uid:t.uid}).trim()}catch(c){if(c?.
|
|
469
470
|
code==="ENOENT")return null;throw c}};return{close:()=>w(o),read:i,remove(c=""){i()===c&&q(E(o,s))}}}function je(e=0){try{
|
|
470
471
|
return h.kill(e,0),!0}catch(t){if(t?.code==="ESRCH")return!1;throw t}}function Gn(e=0){let t="";try{t=N(`/proc/${e}/stat\
|
|
@@ -493,7 +494,7 @@ t}function Yn(){return tr(Kn())}function tr(e=""){let t;try{t=JSON.parse(e)}catc
|
|
|
493
494
|
yload is not valid JSON.")}if(!t||typeof t!="object"||Array.isArray(t))throw new Error("Vibe64 exec helper payload must \
|
|
494
495
|
be a JSON object.");return t}function E(e,t=""){return p.join(`/proc/self/fd/${e}`,t)}function we(e="",t=511){try{return Z(
|
|
495
496
|
e,{mode:t}),!0}catch(r){if(r?.code!=="EEXIST")throw r;return!1}}function te(e=""){let t=String(e);if(!t||t==="."||t===".\
|
|
496
|
-
."||/[/\0]/u.test(t))throw new Error("Vibe64 exec helper rejected an unsafe file name.");return t}function
|
|
497
|
+
."||/[/\0]/u.test(t))throw new Error("Vibe64 exec helper rejected an unsafe file name.");return t}function ae(e="",t=[]){
|
|
497
498
|
let r=M(e,$.O_RDONLY|$.O_DIRECTORY);try{for(let n of t){let o=M(E(r,te(n)),B);w(r),r=o}}catch(n){throw w(r),n}return r}function H(e,t="",{
|
|
498
499
|
maxBytes:r=0,othersMayWrite:n=!0,uid:o=-1}={}){let s=M(E(e,te(t)),Sr);try{let i=J(s);if(!i.isFile()||i.uid!==o||!n&&(i.mode&
|
|
499
500
|
18)!==0)throw Object.assign(new Error("Vibe64 exec helper refused a file that is not its owner's regular file."),{code:"\
|
|
@@ -505,8 +506,8 @@ c helper payload is too large.");e.push(Buffer.from(t.subarray(0,s)))}catch(s){i
|
|
|
505
506
|
"EAGAIN"||s?.code==="EWOULDBLOCK")&&Date.now()<n){Atomics.wait(r,0,0,Or);continue}throw s?.code==="EAGAIN"||s?.code==="E\
|
|
506
507
|
WOULDBLOCK"?new Error("Vibe64 exec helper timed out waiting for its payload."):s}return Buffer.concat(e,o).toString("utf\
|
|
507
508
|
8")}function O(e=""){let t=String(e||"").trim();if(!t||/[/:\\\r\n]/u.test(t))throw new Error("Vibe64 exec helper rejecte\
|
|
508
|
-
d an unsafe username.");return t}function zn(e=""){if(!
|
|
509
|
-
orted username.")}function
|
|
509
|
+
d an unsafe username.");return t}function zn(e=""){if(!vt.test(e))throw new Error("Vibe64 exec helper rejected an unsupp\
|
|
510
|
+
orted username.")}function ce(e=""){if(zn(e),e.startsWith(U))throw new Error("Vibe64 daemon Unix accounts cannot be mana\
|
|
510
511
|
ged as app users.");if(e.startsWith(We))throw new Error("Vibe64 application accounts are never people.");if(Rr.has(e))throw new Error(
|
|
511
512
|
"Privileged Unix accounts cannot be managed as Vibe64 app users.")}function F(e=""){let t=P("getent",["passwd",e],{encoding:"\
|
|
512
513
|
utf8"});if(t.status!==0)throw new Error(`OS user was not found: ${e}`);let n=String(t.stdout||"").split(/\r?\n/u)[0].split(
|
|
@@ -532,7 +533,7 @@ if(V(x(nr(t)),n).length>0)return n;throw new Error("Vibe64 exec helper rejected
|
|
|
532
533
|
pace service root.")}function V(e="",t=""){let r=String(e||"").trim(),n=String(t||"").trim();if(!r||!n)return[];let o=p.
|
|
533
534
|
relative(p.resolve(r),p.resolve(n));return!o||o===".."||o.startsWith(`..${p.sep}`)||p.isAbsolute(o)?[]:o.split(p.sep).filter(
|
|
534
535
|
Boolean)}function x(e,{allowMissingLeaf:t=!1}={}){let r=p.resolve(e);if(t)try{Ee(r)}catch(n){if(n.code!=="ENOENT")throw n;
|
|
535
|
-
return p.join(
|
|
536
|
+
return p.join(ie(p.dirname(r)),p.basename(r))}return ie(r)}function _e(e="",t={}){let r=String(e||"").trim(),n=T(O(t.username));
|
|
536
537
|
if(!t.username?.startsWith(U)||!r.startsWith(`vibe64-release-${n}-`)||!r.endsWith(".service")||!/^[A-Za-z0-9_.@:-]+$/u.test(
|
|
537
538
|
r)||r.includes("/")||r.includes(".."))throw new Error("Vibe64 exec helper rejected an unsafe deployment service unit nam\
|
|
538
539
|
e.");return r}function nt(e="",t={}){let r=String(e||"").trim(),n=p.basename(p.dirname(nr(t)));if(!r.startsWith(`vibe64-\
|
|
@@ -547,18 +548,18 @@ startScript:s="",unitName:i="",user:c={},workingDirectory:a=""}={}){let u=Array.
|
|
|
547
548
|
tion=Vibe64 release service ${i}`,`After=${["network-online.target",...u].join(" ")}`,"Wants=network-online.target",...u.
|
|
548
549
|
length>0?[`Requires=${u.join(" ")}`]:[],"StartLimitIntervalSec=60","StartLimitBurst=5","","[Service]","Type=simple",...It(
|
|
549
550
|
c),...cr(n),`SocketBindAllow=tcp:${Zt(r)}`,"SocketBindAllow=udp","SocketBindDeny=any",`WorkingDirectory=${L(a)}`,`Enviro\
|
|
550
|
-
nment=PATH=${L(
|
|
551
|
+
nment=PATH=${L(ve)}`,"Environment=TMPDIR=/tmp",`ExecStart=/usr/bin/setpriv --no-new-privs -- ${L(t)} run-release-service\
|
|
551
552
|
"${L(e)}" "${L(s)}"`,"Restart=always","RestartSec=3","KillSignal=SIGTERM","TimeoutStopSec=30","","[Install]","WantedBy=\
|
|
552
553
|
multi-user.target",""].join(`
|
|
553
554
|
`)}function to({owner:e={},pidFile:t="",processModel:r="simple",startScript:n="",unitName:o="",workingDirectory:s=""}={}){
|
|
554
555
|
let i=ir(r);return["[Unit]",`Description=Vibe64 managed service ${o}`,"After=network-online.target","Wants=network-onlin\
|
|
555
|
-
e.target","","[Service]",`Type=${i}`,...Qn(e),...cr(e),`WorkingDirectory=${L(s)}`,`Environment=PATH=${L(
|
|
556
|
+
e.target","","[Service]",`Type=${i}`,...Qn(e),...cr(e),`WorkingDirectory=${L(s)}`,`Environment=PATH=${L(ve)}`,`Environme\
|
|
556
557
|
nt=TMPDIR=${L(ot(e.username))}`,`ExecStart=${L(n)}`,...i==="forking"?[`PIDFile=${L(t)}`]:[],"Restart=on-failure","Restar\
|
|
557
558
|
tSec=3","TimeoutStartSec=90","TimeoutStopSec=30",""].join(`
|
|
558
559
|
`)}function L(e=""){let t=String(e||"").trim();if(!t||/[\r\n]/u.test(t))throw new Error("Vibe64 exec helper rejected an \
|
|
559
560
|
unsafe systemd value.");return t.replaceAll("\\","\\\\").replaceAll('"','\\"')}function oe(e="uid",t=null,r=null){if(!Number.
|
|
560
561
|
isSafeInteger(t)||t<0||t!==r)throw new Error(`Vibe64 exec helper ${e} mismatch.`)}function ro(e={},t=""){let r=null;try{
|
|
561
|
-
let n=
|
|
562
|
+
let n=ae(e.home,wt);try{r=JSON.parse(H(n,`${t}.json`,{maxBytes:yt,uid:e.uid}))}finally{w(n)}}catch{r=null}if(r?.username!==
|
|
562
563
|
t||r?.status!=="active")throw new Error("OS user is not enabled for Vibe64.")}function ar(e="",t="",{operation:r="",targetUser:n={}}={}){
|
|
563
564
|
if(r==="health-status")return ot(t);if(r==="workspace-cache-command"){let s=p.join(n.home,".local/state/vibe64/cache-mai\
|
|
564
565
|
ntenance"),i=x(e),c=V(s,i);if(n.username!==t||x(s)!==s||i!==e||c.length!==1||!/^[a-z][a-z0-9-]*-[A-Za-z0-9]{6}$/u.test(c[0]))
|
|
@@ -579,12 +580,12 @@ per rejected an empty managed project path.");let n=x(r),o=x(p.join("/var/lib/vi
|
|
|
579
580
|
let r=String(e||"").trim(),n=String(t.home||"").trim();if(!r||!n)throw new Error("Vibe64 exec helper rejected an empty u\
|
|
580
581
|
ser command path.");let o=x(r),s=x(n);if(o===s||o.startsWith(`${s}${p.sep}`))return o;throw new Error("Vibe64 exec helpe\
|
|
581
582
|
r rejected a command path outside the target user home.")}function T(e=""){return e.startsWith(U)?e.slice(U.length):e}function ot(e=""){
|
|
582
|
-
return p.join(
|
|
583
|
+
return p.join(be,T(O(e)),"tmp")}function io(e="",t=h.argv[1]){let r=String(e);try{let n=ie(t),o=[p.resolve(p.dirname(n),
|
|
583
584
|
"../../../vibe64-usage-recording/runtime/node")];for(let i=p.dirname(n);o.push(p.join(i,"node_modules/@local/vibe64-usag\
|
|
584
|
-
e-recording/runtime/node")),p.dirname(i)!==i;i=p.dirname(i));let s=o.filter(i=>Y(i)).map(i=>
|
|
585
|
-
test(r)&&p.resolve(r)===r&&
|
|
585
|
+
e-recording/runtime/node")),p.dirname(i)!==i;i=p.dirname(i));let s=o.filter(i=>Y(i)).map(i=>ie(i));if(p.isAbsolute(r)&&!/[\s"'\\]/u.
|
|
586
|
+
test(r)&&p.resolve(r)===r&&ie(r)===r&&hr(r).isFile()&&s.some(i=>r.startsWith(`${i}${p.sep}`)))return`--import=${r}`}catch{}
|
|
586
587
|
throw new Error("Vibe64 exec helper rejected a usage recording preload outside its runtime.")}function it(e={},t={},r="",n=""){
|
|
587
|
-
let o={PATH:
|
|
588
|
+
let o={PATH:ve,TERM:h.env.TERM||"xterm-256color"};for(let[s,i]of Object.entries(e))!St.test(s)||Tr.has(s)||s.startsWith(
|
|
588
589
|
"LD_")||s.startsWith("DYLD_")||(o[s]=String(i));if(n==="opencode-app-server"){let s=p.join(Oe({username:r}),"vibe64","ag\
|
|
589
590
|
ent-providers","opencode");for(let i of["HOME","XDG_CACHE_HOME","XDG_CONFIG_HOME","XDG_DATA_HOME","XDG_STATE_HOME"]){let c=String(
|
|
590
591
|
e[i]||"").trim();if(!p.isAbsolute(c)||V(s,c).length===0)throw new Error(`Vibe64 exec helper rejected OpenCode ${i} outsi\
|
|
@@ -599,7 +600,7 @@ eo as deploymentServiceUnit,En as enablePerson,Nn as ensureApplicationAccount,Bn
|
|
|
599
600
|
nn as ensureWorkspaceRuntimeBase,it as helperChildEnv,Be as loginUidRange,Tt as managedExecutionControllerLeaseName,dn as managedExecutionOomBoundary,
|
|
600
601
|
Oe as managedExecutionRuntimeBase,Kr as managedExecutionSliceCgroup,Dt as managedExecutionState,fn as managedExecutionStopTimeoutMs,
|
|
601
602
|
en as managedExecutionTargetUser,Ct as managedExecutionTaskLimitCounters,pn as managedExecutionTaskLimitJournal,Xe as managedWorkflowCounters,
|
|
602
|
-
Rt as managedWorkflowIdentity,Pt as openManagedExecutionReceipts,Xn as parseEnvironmentFile,Gt as personAccountProblem,
|
|
603
|
+
Rt as managedWorkflowIdentity,Pt as openManagedExecutionReceipts,Xn as parseEnvironmentFile,Gt as personAccountProblem,bn as personSudoCommands,
|
|
603
604
|
Qe as readApplicationRegistration,Sn as readPersonRegistration,Xt as registerPerson,zt as registeredApplicationUser,gn as releaseEndedManagedExecutions,
|
|
604
605
|
ar as resolveAllowedCwd,oo as resolveAllowedUserHomePath,Rn as resolveApplicationCwd,Tn as retireApplicationAccount,Gr as runUserCommand,
|
|
605
606
|
hn as stopManagedExecution,Ln as stopManagedServiceUnit,xn as upgradePersonRegistry,io as usageRecordingNodeOptions};
|