vibe64 0.1.76 → 0.1.77
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/bin/run.js +370 -370
- package/bin/server.js +1 -2
- package/bin/upgrade-state.js +969 -969
- package/docs/colleague-usage/development-env.md +9 -0
- package/node_modules/@local/vibe64-execution/src/host/execHelper.js +526 -520
- package/node_modules/@local/vibe64-terminals/src/server/sessionWorkOperationCommand.js +282 -282
- package/package.json +1 -1
- package/server.bundle.mjs +9740 -9738
|
@@ -1,422 +1,426 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire as __vibe64CreateRequire } from 'node:module';const require=__vibe64CreateRequire(import.meta.url);
|
|
3
|
-
import S from"node:process";import{spawnSync as
|
|
4
|
-
fchmodSync as
|
|
5
|
-
unlinkSync as
|
|
6
|
-
import
|
|
7
|
-
realpathSync as
|
|
8
|
-
|
|
9
|
-
n.uid!==t||(n.mode&18)!==0)throw new Error("A Vibe64 registry is not a directory only root can change.")}catch(n){throw
|
|
10
|
-
r),n}return r}function h(e,t=""){return q.join(`/proc/self/fd/${e}`,t)}function
|
|
11
|
-
|
|
3
|
+
import S from"node:process";import{spawnSync as xn}from"node:child_process";import{createHash as qs}from"node:crypto";import{closeSync as D,constants as Tn,
|
|
4
|
+
fchmodSync as Zs,fchownSync as Qs,fstatSync as ei,lstatSync as Mn,openSync as _t,readdirSync as ur,readFileSync as ti,rmSync as ri,
|
|
5
|
+
unlinkSync as ni}from"node:fs";import b from"node:path";import In from"node:process";import{spawnSync as Ne}from"node:child_process";import{closeSync as Jo,mkdirSync as qo,rmSync as Hr,symlinkSync as Zo}from"node:fs";
|
|
6
|
+
import Ce from"node:path";import Ct from"node:process";import{closeSync as ke,constants as H,fstatSync as Wr,fsyncSync as Ho,lstatSync as Xo,mkdirSync as Yo,openSync as $e,readSync as Ko,
|
|
7
|
+
realpathSync as Fr}from"node:fs";import q from"node:path";var C=H.O_RDONLY|H.O_DIRECTORY|H.O_NOFOLLOW,st=H.O_WRONLY|H.O_CREAT|
|
|
8
|
+
H.O_EXCL|H.O_NOFOLLOW,zo=H.O_RDONLY|H.O_NOFOLLOW|H.O_NONBLOCK;function X(e="",t=0){let r=$e(e,C);try{let n=Wr(r);if(!n.isDirectory()||
|
|
9
|
+
n.uid!==t||(n.mode&18)!==0)throw new Error("A Vibe64 registry is not a directory only root can change.")}catch(n){throw ke(
|
|
10
|
+
r),n}return r}function h(e,t=""){return q.join(`/proc/self/fd/${e}`,t)}function it(e=""){let t=$e(e,C);try{Ho(t)}finally{
|
|
11
|
+
ke(t)}}function ue(e="",t=511){try{return Yo(e,{mode:t}),!0}catch(r){if(r?.code!=="EEXIST")throw r;return!1}}function se(e=""){
|
|
12
12
|
let t=String(e);if(!t||t==="."||t===".."||/[/\0]/u.test(t))throw new Error("Vibe64 exec helper rejected an unsafe file n\
|
|
13
|
-
ame.");return t}function Z(e="",t=[]){let r
|
|
14
|
-
r),r=o}}catch(n){throw
|
|
15
|
-
t)),
|
|
13
|
+
ame.");return t}function Z(e="",t=[]){let r=$e(e,H.O_RDONLY|H.O_DIRECTORY);try{for(let n of t){let o=$e(h(r,se(n)),C);ke(
|
|
14
|
+
r),r=o}}catch(n){throw ke(r),n}return r}function T(e,t="",{maxBytes:r=0,othersMayWrite:n=!0,uid:o=-1}={}){let i=$e(h(e,se(
|
|
15
|
+
t)),zo);try{let s=Wr(i);if(!s.isFile()||s.uid!==o||!n&&(s.mode&18)!==0)throw Object.assign(new Error("Vibe64 exec helper\
|
|
16
16
|
refused a file that is not its owner's regular file."),{code:"EVIBE64UNSAFEFILE"});let a=Buffer.alloc(r+1),c=0;for(;c<a.
|
|
17
|
-
length;){let u=
|
|
18
|
-
fused a file that is too large."),{code:"EVIBE64UNSAFEFILE"});return a.toString("utf8",0,c)}finally{
|
|
17
|
+
length;){let u=Ko(i,a,c,a.length-c,null);if(u===0)break;c+=u}if(c>r)throw Object.assign(new Error("Vibe64 exec helper re\
|
|
18
|
+
fused a file that is too large."),{code:"EVIBE64UNSAFEFILE"});return a.toString("utf8",0,c)}finally{ke(i)}}function R(e="",t=""){
|
|
19
19
|
let r=String(e||"").trim(),n=String(t||"").trim();if(!r||!n)return[];let o=q.relative(q.resolve(r),q.resolve(n));return!o||
|
|
20
20
|
o===".."||o.startsWith(`..${q.sep}`)||q.isAbsolute(o)?[]:o.split(q.sep).filter(Boolean)}function v(e,{allowMissingLeaf:t=!1}={}){
|
|
21
|
-
let r=q.resolve(e);if(t)try{
|
|
22
|
-
r)}var
|
|
23
|
-
r/lib/vibe64",
|
|
24
|
-
if(!t)return
|
|
21
|
+
let r=q.resolve(e);if(t)try{Xo(r)}catch(n){if(n.code!=="ENOENT")throw n;return q.join(Fr(q.dirname(r)),q.basename(r))}return Fr(
|
|
22
|
+
r)}var Pt=[".local","state","vibe64","users"],Dt=64*1024,Ut=/^[a-z][a-z0-9_-]{0,61}[a-z0-9]$/u,k="vibe64",P="v64d_",pe="/va\
|
|
23
|
+
r/lib/vibe64",Qo=new Set(["root"]),es="/etc/vibe64";function ts(e=Ct.env){let t=String(e.VIBE64_HOST_SETTINGS_ROOT??"");
|
|
24
|
+
if(!t)return es;if(!Ce.isAbsolute(t)||Ce.resolve(t)!==t||t==="/")throw new Error(`Vibe64 exec helper refused its setting\
|
|
25
25
|
s folder VIBE64_HOST_SETTINGS_ROOT=${JSON.stringify(t)}: it is not an absolute, normalized path other than /.`);return t}
|
|
26
|
-
var Q=
|
|
27
|
-
"Vibe64 exec helper rejected an unsafe username.");return t}function
|
|
28
|
-
c helper rejected an unsupported username.")}function le(e=""){if(
|
|
29
|
-
nix accounts cannot be managed as app users.");if(e.startsWith(
|
|
30
|
-
ople.");if(
|
|
26
|
+
var Q=ts(),at="v64s_",ve="/usr/sbin/nologin";function w(e=""){let t=String(e||"").trim();if(!t||/[/:\\\r\n]/u.test(t))throw new Error(
|
|
27
|
+
"Vibe64 exec helper rejected an unsafe username.");return t}function rs(e=""){if(!Ut.test(e))throw new Error("Vibe64 exe\
|
|
28
|
+
c helper rejected an unsupported username.")}function le(e=""){if(rs(e),e.startsWith(P))throw new Error("Vibe64 daemon U\
|
|
29
|
+
nix accounts cannot be managed as app users.");if(e.startsWith(at))throw new Error("Vibe64 staging accounts are never pe\
|
|
30
|
+
ople.");if(Qo.has(e))throw new Error("Privileged Unix accounts cannot be managed as Vibe64 app users.")}function $(e=""){
|
|
31
31
|
let t=Ne("getent",["passwd",e],{encoding:"utf8"});if(t.status!==0)throw new Error(`OS user was not found: ${e}`);let n=String(
|
|
32
32
|
t.stdout||"").split(/\r?\n/u)[0].split(":");if(n.length<7||n[0]!==e)throw new Error(`OS user was not found: ${e}`);let o=Number(
|
|
33
33
|
n[2]),i=Number(n[3]);if(!Number.isSafeInteger(o)||!Number.isSafeInteger(i))throw new Error(`OS user has invalid uid/gid:\
|
|
34
|
-
${e}`);return{gid:i,home:n[5],shell:n[6],uid:o,username:e}}function j(){let e=w(
|
|
34
|
+
${e}`);return{gid:i,home:n[5],shell:n[6],uid:o,username:e}}function j(){let e=w(Ct.env.SUDO_USER||"");return $(e)}function Pe(e=""){
|
|
35
35
|
let t=Ne("id",["-nG",e],{encoding:"utf8"});if(t.status!==0)throw new Error(`Could not read the groups of OS user ${e}.`);
|
|
36
|
-
return String(t.stdout||"").trim().split(/\s+/u)}function
|
|
36
|
+
return String(t.stdout||"").trim().split(/\s+/u)}function Xr(e="",t=""){let r=[];try{r=Pe(e)}catch{}if(!r.includes(t))throw new Error(
|
|
37
37
|
`OS user is not enabled for the shared Vibe64 group: ${e}`)}function ge(e=""){try{return $(e)}catch{return null}}function he(e=""){
|
|
38
38
|
let t=Ne("getent",["group",e],{encoding:"utf8"}),r=Number(String(t.stdout||"").split(":")[2]);if(t.status!==0||!Number.isSafeInteger(
|
|
39
|
-
r))throw new Error(`Required OS group was not found: ${e}`);return r}function
|
|
40
|
-
extrausers"]:[]}function
|
|
39
|
+
r))throw new Error(`Required OS group was not found: ${e}`);return r}function Gt(e="files"){return e==="extrausers"?["--\
|
|
40
|
+
extrausers"]:[]}function Yr(e="",t="",r="files",n=[]){if(r==="extrausers")throw new Error("This host keeps its accounts \
|
|
41
41
|
in the extra users database, where people sign in without a password: the helper creates no person with one here.");if(ge(
|
|
42
42
|
e))throw new Error(`OS user already exists: ${e}`);if(!t||/[\r\n]/u.test(t))throw new Error("A valid initial password is\
|
|
43
43
|
required to create an OS user.");_("useradd",[...n,"--create-home","--user-group","--shell","/bin/bash",e]);let o=Ne("c\
|
|
44
44
|
hpasswd",{encoding:"utf8",input:`${e}:${t}
|
|
45
|
-
`});if(o.status!==0)throw new Error(String(o.stderr||o.stdout||"Could not set OS user password.").trim())}function
|
|
46
|
-
files"){if(r==="extrausers"){_("gpasswd",["--extrausers","-a",e,t]);return}_("usermod",["-a","-G",t,e])}var
|
|
47
|
-
/extrausers";function
|
|
48
|
-
ell",t,e]);return}let i=
|
|
49
|
-
|
|
45
|
+
`});if(o.status!==0)throw new Error(String(o.stderr||o.stdout||"Could not set OS user password.").trim())}function jt(e="",t="",r="\
|
|
46
|
+
files"){if(r==="extrausers"){_("gpasswd",["--extrausers","-a",e,t]);return}_("usermod",["-a","-G",t,e])}var ns="/var/lib\
|
|
47
|
+
/extrausers";function Lt(e="",t="",r="files",{prefixParent:n="/run",run:o=_}={}){if(r!=="extrausers"){o("usermod",["--sh\
|
|
48
|
+
ell",t,e]);return}let i=Ce.join(n,`vibe64-accounts-${Ct.pid}`);Hr(i,{force:!0,recursive:!0}),qo(i,{mode:448});try{Zo(ns,
|
|
49
|
+
Ce.join(i,"etc")),o("usermod",["--prefix",i,"--shell",t,e])}finally{Hr(i,{force:!0,recursive:!0})}}function _(e="",t=[]){
|
|
50
50
|
let r=Ne(e,t,{encoding:"utf8"});if(r.status!==0)throw new Error(String(r.stderr||r.stdout||`${e} failed.`).trim());return String(
|
|
51
51
|
r.stdout||"").trim()}function N(e="",t=[]){return Ne(e,t,{encoding:"utf8"})}function me(e="uid",t=null,r=null){if(!Number.
|
|
52
|
-
isSafeInteger(t)||t<0||t!==r)throw new Error(`Vibe64 exec helper ${e} mismatch.`)}function
|
|
53
|
-
let n=Z(e.home,
|
|
54
|
-
t||r?.status!=="active")throw new Error("OS user is not enabled for Vibe64.")}function O(e=""){return e.startsWith(
|
|
55
|
-
slice(
|
|
56
|
-
statSync as
|
|
52
|
+
isSafeInteger(t)||t<0||t!==r)throw new Error(`Vibe64 exec helper ${e} mismatch.`)}function Kr(e={},t=""){let r=null;try{
|
|
53
|
+
let n=Z(e.home,Pt);try{r=JSON.parse(T(n,`${t}.json`,{maxBytes:Dt,uid:e.uid}))}finally{Jo(n)}}catch{r=null}if(r?.username!==
|
|
54
|
+
t||r?.status!=="active")throw new Error("OS user is not enabled for Vibe64.")}function O(e=""){return e.startsWith(P)?e.
|
|
55
|
+
slice(P.length):e}function De(e=""){return Ce.join(pe,O(w(e)),"tmp")}import{spawnSync as os}from"node:child_process";import{closeSync as ss,existsSync as Ue,readFileSync as is,realpathSync as Bt,
|
|
56
|
+
statSync as as}from"node:fs";import E from"node:path";import zr from"node:process";var ct=new Set(["bash","gh","git"]),Jr=/^[A-Za-z_][A-Za-z0-9_]*$/u,cs=new Set(["BASH_ENV","ENV","GCONV_PATH","GETCONF_DI\
|
|
57
57
|
R","GLIBC_TUNABLES","HOSTALIASES","LOCALDOMAIN","LD_AUDIT","LD_LIBRARY_PATH","LD_PRELOAD","LOCPATH","MALLOC_TRACE","NIS_\
|
|
58
|
-
PATH","NLSPATH","NODE_OPTIONS","RESOLV_HOST_CONF","RES_OPTIONS","TZDIR"]),
|
|
59
|
-
usr/bin:/sbin:/bin",
|
|
58
|
+
PATH","NLSPATH","NODE_OPTIONS","RESOLV_HOST_CONF","RES_OPTIONS","TZDIR"]),qr="/usr/local/sbin:/usr/local/bin:/usr/sbin:/\
|
|
59
|
+
usr/bin:/sbin:/bin",us=E.join(Q,"exec-helper.env"),ls=16384;function Zr(e,t,r,n){return os("/usr/bin/setpriv",["--no-new\
|
|
60
60
|
-privs","--","/usr/sbin/runuser","-u",e.username,"--","/usr/bin/env","--",`PATH=${n.env.PATH}`,t,...r],{...n,env:{...n.env,
|
|
61
|
-
PATH:
|
|
62
|
-
"").trim();if(!r)return E.join(
|
|
61
|
+
PATH:qr}})}function Ge(e={}){return`/run/vibe64-${O(w(e.username))}`}function Qr(e="",t=B()){let r=String(t.VIBE64_AGENT_RUNTIME_ROOT||
|
|
62
|
+
"").trim();if(!r)return E.join(Ge({username:e}),"vibe64","agent-providers");if(!E.isAbsolute(r)||E.resolve(r)!==r||r==="\
|
|
63
63
|
/")throw new Error("Vibe64 exec helper settings name a VIBE64_AGENT_RUNTIME_ROOT that is not an absolute, normalized fol\
|
|
64
|
-
der.");return E.join(r,O(w(e)))}function Ee(e=""){return
|
|
65
|
-
t)}catch(n){if(n.code==="ENOENT")return{};throw n}try{return
|
|
66
|
-
if(n.code==="ENOENT")return{};throw n}finally{
|
|
64
|
+
der.");return E.join(r,O(w(e)))}function Ee(e=""){return en(is(e,"utf8"))}function B(e=us,t=0){let r;try{r=X(E.dirname(e),
|
|
65
|
+
t)}catch(n){if(n.code==="ENOENT")return{};throw n}try{return en(T(r,E.basename(e),{maxBytes:ls,othersMayWrite:!1,uid:t}))}catch(n){
|
|
66
|
+
if(n.code==="ENOENT")return{};throw n}finally{ss(r)}}function ut(e=B()){let t=String(e.PATH||"").trim();if(!t)return qr;
|
|
67
67
|
if(t.split(":").some(r=>!E.isAbsolute(r)))throw new Error("Vibe64 exec helper settings name a PATH folder that is not ab\
|
|
68
|
-
solute.");return t}function
|
|
68
|
+
solute.");return t}function en(e=""){let t={},r=l=>`
|
|
69
69
|
\r`.includes(l),n=l=>l===`
|
|
70
|
-
`||l==="\r",o="pre-key",i="",s="",a=0,c=l=>{s+=l,a=s.length},u=()=>{let l=i.trim();
|
|
70
|
+
`||l==="\r",o="pre-key",i="",s="",a=0,c=l=>{s+=l,a=s.length},u=()=>{let l=i.trim();Jr.test(l)&&(t[l]=s.slice(0,a)),i="",
|
|
71
71
|
s="",a=0,o="pre-key"};for(let l of String(e))o==="pre-key"?l==="#"||l===";"?o="comment":r(l)||(i=l,o="key"):o==="key"?n(
|
|
72
72
|
l)?(i="",o="pre-key"):l==="="?o="pre-value":i+=l:o==="pre-value"||o==="value"?n(l)?u():l==="\\"?o="value-escape":o==="pr\
|
|
73
73
|
e-value"&&l==="'"?o="single":o==="pre-value"&&l==='"'?o="double":r(l)?o==="value"&&(s+=l):(c(l),o="value"):o==="value-es\
|
|
74
74
|
cape"?(n(l)||c(l),o="value"):o==="single"?l==="'"?o="pre-value":c(l):o==="double"?l==='"'?o="pre-value":l==="\\"?o="doub\
|
|
75
75
|
le-escape":c(l):o==="double-escape"?('"\\`$'.includes(l)?c(l):n(l)||c(`\\${l}`),o="double"):o==="comment"?l==="\\"?o="co\
|
|
76
76
|
mment-escape":n(l)&&(o="pre-key"):o="comment";return o!=="pre-key"&&o!=="key"&&o!=="comment"&&o!=="comment-escape"&&u(),
|
|
77
|
-
t}function
|
|
77
|
+
t}function lt(e="",t="",{operation:r="",settings:n=void 0,targetUser:o={}}={}){if(r==="health-status")return De(t);if(r===
|
|
78
78
|
"workspace-cache-command"){let s=E.join(o.home,".local/state/vibe64/cache-maintenance"),a=v(e),c=R(s,a);if(o.username!==
|
|
79
79
|
t||v(s)!==s||a!==e||c.length!==1||!/^[a-z][a-z0-9-]*-[A-Za-z0-9]{6}$/u.test(c[0]))throw new Error("Cache maintenance req\
|
|
80
80
|
uires an owned workspace scratch directory.");return a}let i=String(e||"").trim();if(!i)return"/";if(r==="account-auth-t\
|
|
81
|
-
erminal"||r==="account-status"||r==="github-api-command")return
|
|
82
|
-
i),a=E.join(o.home,".local","state","vibe64","projects");if(
|
|
83
|
-
let c=E.join(o.home,".local","state","vibe64","colleague");if(
|
|
81
|
+
erminal"||r==="account-status"||r==="github-api-command")return ds(i,o);if(r==="vibe64-command"&&o.username===t){let s=v(
|
|
82
|
+
i),a=E.join(o.home,".local","state","vibe64","projects");if(Ue(a)){let l=v(a);if(s===l||s.startsWith(`${l}${E.sep}`))return s}
|
|
83
|
+
let c=E.join(o.home,".local","state","vibe64","colleague");if(Ue(c)){let l=R(v(c),s),m=l.at(-1)||"",d=l.length===4&&l[1]===
|
|
84
84
|
"learn"&&/^(lobby|[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})$/u.test(l[2]);if((l.length===2||d)&&/^[A-Za-z0-9_-]+$/u.
|
|
85
85
|
test(l[0])&&/^colleague_[a-f0-9]{32}$/u.test(m))return s}let u=E.join(o.home,".local","state","vibe64","training-sources");
|
|
86
|
-
if(
|
|
87
|
-
test(l[0]))return s}}if(r==="codex-app-server"||r==="opencode-app-server"){let s=v(i),a=Number(o.uid),c=[
|
|
88
|
-
isSafeInteger(a)&&a>=0&&c.push(E.join("/run/user",String(a),"vibe64","agent-providers"));for(let u of c){if(!
|
|
86
|
+
if(Ue(u)){let l=R(v(u),s);if(l.length===1&&/^(catalogue|topic)-[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/u.
|
|
87
|
+
test(l[0]))return s}}if(r==="codex-app-server"||r==="opencode-app-server"){let s=v(i),a=Number(o.uid),c=[Qr(t,n)];Number.
|
|
88
|
+
isSafeInteger(a)&&a>=0&&c.push(E.join("/run/user",String(a),"vibe64","agent-providers"));for(let u of c){if(!Ue(u))continue;
|
|
89
89
|
let l=v(u),m=R(l,s),d=m[0],f=r==="opencode-app-server"?d==="opencode":d==="codex-app-server"||/^codex-app-server-[a-f0-9]{12}$/u.
|
|
90
|
-
test(d),p=r==="codex-app-server"&&m.length===1,g=m.length===2&&m[1]==="workspace";if(f&&(p||g))return s}}return
|
|
91
|
-
function
|
|
90
|
+
test(d),p=r==="codex-app-server"&&m.length===1,g=m.length===2&&m[1]==="workspace";if(f&&(p||g))return s}}return ms(i,t)}
|
|
91
|
+
function ms(e="",t=""){let r=String(e||"").trim();if(!r)throw new Error("Vibe64 exec helper rejected an empty managed pr\
|
|
92
92
|
oject path.");let n=v(r),o=v(E.join("/var/lib/vibe64",O(t),"projects"));if(n.startsWith(`${o}${E.sep}`))return n;throw new Error(
|
|
93
|
-
"Vibe64 exec helper rejected a command path outside the owner project root.")}function
|
|
93
|
+
"Vibe64 exec helper rejected a command path outside the owner project root.")}function ds(e="",t={}){let r=String(e||"").
|
|
94
94
|
trim(),n=String(t.home||"").trim();if(!r||!n)throw new Error("Vibe64 exec helper rejected an empty user command path.");
|
|
95
95
|
let o=v(r),i=v(n);if(o===i||o.startsWith(`${i}${E.sep}`))return o;throw new Error("Vibe64 exec helper rejected a command\
|
|
96
|
-
path outside the target user home.")}function
|
|
96
|
+
path outside the target user home.")}function tn(e="",t=zr.argv[1]){let r=String(e);try{let n=Bt(t),o=[E.resolve(E.dirname(
|
|
97
97
|
n),"../../../vibe64-usage-recording/runtime/node")];for(let s=E.dirname(n);o.push(E.join(s,"node_modules/@local/vibe64-u\
|
|
98
|
-
sage-recording/runtime/node")),E.dirname(s)!==s;s=E.dirname(s));let i=o.filter(s=>
|
|
99
|
-
!/[\s"'\\]/u.test(r)&&E.resolve(r)===r&&
|
|
100
|
-
rt=${r}`}catch{}throw new Error("Vibe64 exec helper rejected a usage recording preload outside its runtime.")}function
|
|
101
|
-
let i={TERM:
|
|
102
|
-
s.startsWith("DYLD_")||(i[s]=String(a));if(i.PATH||=
|
|
98
|
+
sage-recording/runtime/node")),E.dirname(s)!==s;s=E.dirname(s));let i=o.filter(s=>Ue(s)).map(s=>Bt(s));if(E.isAbsolute(r)&&
|
|
99
|
+
!/[\s"'\\]/u.test(r)&&E.resolve(r)===r&&Bt(r)===r&&as(r).isFile()&&i.some(s=>r.startsWith(`${s}${E.sep}`)))return`--impo\
|
|
100
|
+
rt=${r}`}catch{}throw new Error("Vibe64 exec helper rejected a usage recording preload outside its runtime.")}function je(e={},t={},r="",n="",o=void 0){
|
|
101
|
+
let i={TERM:zr.env.TERM||"xterm-256color"};for(let[s,a]of Object.entries(e))!Jr.test(s)||cs.has(s)||s.startsWith("LD_")||
|
|
102
|
+
s.startsWith("DYLD_")||(i[s]=String(a));if(i.PATH||=ut(),n==="opencode-app-server"){let s=E.join(Qr(r,o),"opencode");for(let a of[
|
|
103
103
|
"HOME","XDG_CACHE_HOME","XDG_CONFIG_HOME","XDG_DATA_HOME","XDG_STATE_HOME"]){let c=String(e[a]||"").trim();if(!E.isAbsolute(
|
|
104
104
|
c)||R(s,c).length===0)throw new Error(`Vibe64 exec helper rejected OpenCode ${a} outside its provider runtime.`);i[a]=E.
|
|
105
105
|
resolve(c)}}else i.HOME=t.home,i.XDG_CACHE_HOME=E.join(t.home,".cache"),i.XDG_CONFIG_HOME=E.join(t.home,".config"),i.XDG_DATA_HOME=
|
|
106
|
-
E.join(t.home,".local","share");return i.LOGNAME=t.username,i.USER=t.username,i.TMPDIR=t.stagingAccount?"/tmp":
|
|
107
|
-
mkdirSync as
|
|
108
|
-
import
|
|
109
|
-
function te(e=
|
|
110
|
-
host's Vibe64 exec helper settings name an unknown account database (VIBE64_ACCOUNT_DATABASE):
|
|
111
|
-
.");return t}var
|
|
112
|
-
"VIBE64_PERSON_ID_BAND",["UID_MIN","UID_MAX","GID_MIN","GID_MAX"]]]);function
|
|
113
|
-
let s=String(e[t]||"").trim();if(!s)return[];let a=/^([1-9][0-9]{0,4})-([1-9][0-9]{0,4})$/u.exec(
|
|
114
|
-
Number(a[2])]:[0,0];if(!a||c>u||u>=65534)throw new Error(`This host's Vibe64 exec helper
|
|
115
|
-
numbers (${t}) that is not FIRST-LAST with FIRST no greater than LAST and both below 65534.`);
|
|
116
|
-
-K",`${n}=${u}`,"-K",`${o}=${c}`,"-K",`${i}=${u}`]})}function
|
|
117
|
-
isAbsolute(n)||
|
|
118
|
-
that is not an absolute path other than /.`);return n}function
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
106
|
+
E.join(t.home,".local","share");return i.LOGNAME=t.username,i.USER=t.username,i.TMPDIR=t.stagingAccount?"/tmp":De(r),i}import{spawnSync as Ss}from"node:child_process";import{closeSync as ie,fchmodSync as ws,fstatSync as ys,fsyncSync as Wt,
|
|
107
|
+
mkdirSync as Ht,openSync as nn,readdirSync as As,readFileSync as _s,realpathSync as Os,renameSync as on,rmSync as Ns,writeFileSync as vs}from"node:fs";
|
|
108
|
+
import ft from"node:path";import sn from"node:process";import be from"node:path";import fs from"node:process";var ps=Object.freeze(["files","extrausers"]),Le="/etc/systemd/system",gs="/etc/sudoers.d",hs=be.join(Q,"staging-ssh"),rn=/^(?:\/[A-Za-z0-9._+-]+)+$/u,
|
|
109
|
+
Te="VIBE64_RUNTIME_PACK_ROOT";function te(e=B()){let t=String(e.VIBE64_ACCOUNT_DATABASE||"").trim()||"files";if(!ps.includes(
|
|
110
|
+
t))throw new Error("This host's Vibe64 exec helper settings name an unknown account database (VIBE64_ACCOUNT_DATABASE): \
|
|
111
|
+
it is files or extrausers.");return t}var Es=Object.freeze([["VIBE64_SYSTEM_ID_BAND",["SYS_UID_MIN","SYS_UID_MAX","SYS_G\
|
|
112
|
+
ID_MIN","SYS_GID_MAX"]],["VIBE64_PERSON_ID_BAND",["UID_MIN","UID_MAX","GID_MIN","GID_MAX"]]]);function mt(e=B()){return Es.
|
|
113
|
+
flatMap(([t,[r,n,o,i]])=>{let s=String(e[t]||"").trim();if(!s)return[];let a=/^([1-9][0-9]{0,4})-([1-9][0-9]{0,4})$/u.exec(
|
|
114
|
+
s),[c,u]=a?[Number(a[1]),Number(a[2])]:[0,0];if(!a||c>u||u>=65534)throw new Error(`This host's Vibe64 exec helper settin\
|
|
115
|
+
gs name a band of account numbers (${t}) that is not FIRST-LAST with FIRST no greater than LAST and both below 65534.`);
|
|
116
|
+
return["-K",`${r}=${c}`,"-K",`${n}=${u}`,"-K",`${o}=${c}`,"-K",`${i}=${u}`]})}function Vt(e,t,r){let n=String(e[t]||"").
|
|
117
|
+
trim();if(!n)return r;if(!be.isAbsolute(n)||be.resolve(n)!==n||n==="/")throw new Error(`This host's Vibe64 exec helper s\
|
|
118
|
+
ettings name a folder (${t}) that is not an absolute path other than /.`);return n}function V(e=B()){return Vt(e,"VIBE64\
|
|
119
|
+
_SYSTEMD_UNIT_ROOT",Le)}function dt(e=B()){return Vt(e,"VIBE64_SUDOERS_ROOT",gs)}function xe(e=B()){return Vt(e,"VIBE64_\
|
|
120
|
+
STAGING_KEYS_ROOT",hs)}function Ft(e=B()){let t=String(e[Te]||"").trim();if(!t)return"";if(!rn.test(t)||be.resolve(t)!==
|
|
121
|
+
t)throw new Error(`This host's Vibe64 exec helper settings name a runtime pack folder (${Te}) that is not an absolute, n\
|
|
122
|
+
ormalized path of letters, digits and . _ + - alone.`);return t}function re(e=B(),t=fs.argv[1]){let r=String(e.VIBE64_EXEC_HELPER_COMMAND||
|
|
123
|
+
"").trim();if(!r)return be.resolve(t);if(!rn.test(r)||be.resolve(r)!==r)throw new Error("This host's Vibe64 exec helper \
|
|
124
|
+
settings name a helper command (VIBE64_EXEC_HELPER_COMMAND) that is not an absolute, normalized path of letters, digits \
|
|
125
|
+
and . _ + - alone.");return r}var Yt=ft.join(Q,"people"),an="vibe64.person-registration",Kt=4096,pt=3,bs=ft.join(Q,"person-sudo-commands"),Ts=new Set(
|
|
126
|
+
["adm","admin","disk","docker","incus","incus-admin","kmem","libvirt","lxd","root","shadow","staff","sudo","wheel"]);function cn(e="",t={},r=""){
|
|
127
|
+
le(r);let n=un(j());if(he(k),e==="create-system-user"){Yr(r,String(t.password||""),te(),mt()),qt(n,r);return}xs(n,r)}function xs(e="",t="",{
|
|
128
|
+
addToGroup:r=i=>jt(i,k,te()),resolveUser:n=$,...o}={}){fn(e,n(t),o),r(t)}function un(e={}){let t=String(e.username||"");
|
|
129
|
+
if(!t.startsWith(P))throw new Error("Only a workspace daemon acts as its people.");return Be(t.slice(P.length))}function Be(e=""){
|
|
127
130
|
if(!/^[a-z][a-z0-9]{0,62}$/u.test(String(e)))throw new Error("Vibe64 exec helper rejected an invalid workspace name.");return e}
|
|
128
|
-
function de(e="",{create:t=!1,registryRoot:r="",registryUid:n=0}={}){t&&
|
|
129
|
-
e);return t&&ue(h(o,i),493),
|
|
130
|
-
registryRoot:
|
|
131
|
-
schema===
|
|
132
|
-
ie(o)}}function
|
|
131
|
+
function de(e="",{create:t=!1,registryRoot:r="",registryUid:n=0}={}){t&&Ht(r,{mode:493,recursive:!0});let o=X(r,n);try{let i=se(
|
|
132
|
+
e);return t&&ue(h(o,i),493),X(h(o,i),n)}finally{ie(o)}}function Ms(e="",t="",r={}){let n=r.registryUid??0,o;try{o=de(e,{
|
|
133
|
+
registryRoot:Yt,...r})}catch{return null}try{let i=JSON.parse(T(o,`${t}.json`,{maxBytes:Kt,othersMayWrite:!1,uid:n}));return i?.
|
|
134
|
+
schema===an&&i.schemaVersion===1&&i.username===t&&Number.isSafeInteger(i.uid)?{uid:i.uid,username:t}:null}catch{return null}finally{
|
|
135
|
+
ie(o)}}function zt(e,t={}){let r=`${se(t.username)}.json`,n=`.${r}.${sn.pid}.tmp`,o=nn(h(e,n),st,420);try{ws(o,420),vs(o,
|
|
133
136
|
`${JSON.stringify(t)}
|
|
134
|
-
`),
|
|
135
|
-
username})}function
|
|
137
|
+
`),Wt(o)}finally{ie(o)}on(h(e,n),h(e,r)),Wt(e)}function ln(e,t={}){zt(e,{schema:an,schemaVersion:1,uid:t.uid,username:t.
|
|
138
|
+
username})}function mn(e=""){return Object.assign(new Error(e),{exitCode:pt})}function Xt(e=""){let t=(r,n)=>{let o=new RegExp(
|
|
136
139
|
`^[\\t ]*${r}[\\t ]+(\\d+)[\\t ]*$`,"mu").exec(String(e));return o?Number(o[1]):n};return{max:t("UID_MAX",6e4),min:t("UI\
|
|
137
|
-
D_MIN",1e3)}}function
|
|
140
|
+
D_MIN",1e3)}}function dn(e={},{groups:t=[],loginUids:r=Xt(),resolveProgram:n=s=>s,sudoCommands:o=[],sudoListing:i=""}={}){
|
|
138
141
|
let{uid:s,username:a}=e;if(!Number.isSafeInteger(s)||s<r.min||s>r.max)return`${a} is a system account (uid ${s}), not a \
|
|
139
|
-
person's login.`;let c=t.find(u=>
|
|
142
|
+
person's login.`;let c=t.find(u=>Ts.has(u));return c?`${a} is in the administrators' group ${c}.`:Is(a,i,o,n)}function Is(e="",t="",r=[],n=o=>o){
|
|
140
143
|
if(t.includes(`User ${e} is not allowed to run sudo on `))return"";let o=t.split(`
|
|
141
144
|
`),i=o.findIndex(l=>l.startsWith(`User ${e} may run the following commands on `)),s=i<0?[]:o.slice(i+1).filter(l=>l.trim()),
|
|
142
145
|
a=l=>{let[m,...d]=l.split(" ");try{return[n(m),...d].join(" ")}catch{return l}},c=new Set(r.map(a));return s.length>0&&s.
|
|
143
146
|
every(l=>{let m=/^ {4}\(root\) NOPASSWD: (.+)$/u.exec(l);return!!m&&m[1].split(", ").every(d=>c.has(a(d)))})?"":`${e} ha\
|
|
144
|
-
s sudo rules.`}function
|
|
145
|
-
let n=
|
|
146
|
-
oot can change.");return T(r,
|
|
147
|
-
`).map(o=>o.trim()).filter(Boolean)}catch(n){if(n.code==="ENOENT")return[];throw n}finally{ie(r)}}function
|
|
148
|
-
|
|
149
|
-
utf8",env:{COLUMNS:"100000",LANG:"C",LC_ALL:"C",PATH:"/usr/sbin:/usr/bin:/sbin:/bin"}});return{groups
|
|
150
|
-
resolveProgram:
|
|
151
|
-
throw
|
|
152
|
-
if(le(t.username),
|
|
147
|
+
s sudo rules.`}function Rs(e=bs,t=0){let r;try{r=nn(ft.dirname(e),C)}catch(n){if(n.code==="ENOENT")return[];throw n}try{
|
|
148
|
+
let n=ys(r);if(n.uid!==t||(n.mode&18)!==0)throw new Error("The Vibe64 person sudo commands are not in a directory only r\
|
|
149
|
+
oot can change.");return T(r,ft.basename(e),{maxBytes:4096,othersMayWrite:!1,uid:t}).split(`
|
|
150
|
+
`).map(o=>o.trim()).filter(Boolean)}catch(n){if(n.code==="ENOENT")return[];throw n}finally{ie(r)}}function Jt(){try{return Xt(
|
|
151
|
+
_s("/etc/login.defs","utf8"))}catch{return Xt()}}function Ve(e=""){let t=Jt(),r=Ss("/usr/bin/sudo",["-n","-l","-U",e],{encoding:"\
|
|
152
|
+
utf8",env:{COLUMNS:"100000",LANG:"C",LC_ALL:"C",PATH:"/usr/sbin:/usr/bin:/sbin:/bin"}});return{groups:Pe(e),loginUids:t,
|
|
153
|
+
resolveProgram:Os,sudoCommands:Rs(),sudoListing:r.error?"":String(r.stdout||"")}}function gt(e={},t={}){let r=dn(e,t);if(r)
|
|
154
|
+
throw mn(`Vibe64 never runs commands as an administrator or system account: ${r}`)}function fn(e="",t={},{facts:r=Ve,...n}={}){
|
|
155
|
+
if(le(t.username),Ms(e,t.username,n)?.uid!==t.uid)throw mn(`OS user ${t.username} is not registered as a Vibe64 person o\
|
|
153
156
|
f workspace ${e}. A server administrator registers an existing account with: sudo ${re()} register-person ${e} ${t.username}`);
|
|
154
|
-
let i=r(t.username);return
|
|
155
|
-
S user is not enabled for the shared Vibe64 group: ${t.username}`);
|
|
156
|
-
s,k,te()),facts:n=
|
|
157
|
-
...i,create:!0});try{
|
|
158
|
-
report:o=s=>
|
|
159
|
-
`),resolveUser:i=$}={}){
|
|
160
|
-
registryUid:n})),{imported:[],refused:[]}}catch(d){if(d.code!=="ENOENT")throw d}let c=`.${e}.upgrading`;
|
|
161
|
-
recursive:!0}),
|
|
162
|
-
let p=t(d);if(!p.groups.includes(k))continue;let g=
|
|
163
|
-
as a Vibe64 person of ${e}: ${g}`);continue}
|
|
164
|
-
of ${e}.`)}}finally{ie(u)}return
|
|
165
|
-
try{t=Z(e.home,
|
|
166
|
-
".json")?n.slice(0,-5):"";if(
|
|
167
|
-
return r}finally{ie(t)}}import{closeSync as
|
|
168
|
-
writeFileSync as
|
|
169
|
-
ging-${e}`)}function
|
|
170
|
-
rootUid:r=
|
|
171
|
-
|
|
172
|
-
elper refused ${e}: it is not root's own folder.`)}function
|
|
173
|
-
e)}.${
|
|
174
|
-
dirname(e))}function
|
|
175
|
-
accountDatabase:n=te(),keysRoot:o=
|
|
157
|
+
let i=r(t.username);return gt(t,i),i}function ht(e={},t={},r={}){if(!fn(un(e),t,r).groups.includes(k))throw new Error(`O\
|
|
158
|
+
S user is not enabled for the shared Vibe64 group: ${t.username}`);Kr(e,t.username)}function qt(e="",t="",{addToGroup:r=s=>jt(
|
|
159
|
+
s,k,te()),facts:n=Ve,resolveUser:o=$,...i}={}){Be(e),le(t),o(`${P}${e}`);let s=o(t);gt(s,n(t));let a=de(e,{registryRoot:Yt,
|
|
160
|
+
...i,create:!0});try{ln(a,s)}finally{ie(a)}return r(t),s}function pn(e="",{facts:t=Ve,registryRoot:r=Yt,registryUid:n=0,
|
|
161
|
+
report:o=s=>sn.stdout.write(`${s}
|
|
162
|
+
`),resolveUser:i=$}={}){Be(e);let s=i(`${P}${e}`);Ht(r,{mode:493,recursive:!0});let a=X(r,n);try{try{return ie(de(e,{registryRoot:r,
|
|
163
|
+
registryUid:n})),{imported:[],refused:[]}}catch(d){if(d.code!=="ENOENT")throw d}let c=`.${e}.upgrading`;Ns(h(a,c),{force:!0,
|
|
164
|
+
recursive:!0}),Ht(h(a,c),{mode:493});let u=X(h(a,c),n),l=[],m=[];try{for(let d of ks(s)){let f;try{le(d),f=i(d)}catch{continue}
|
|
165
|
+
let p=t(d);if(!p.groups.includes(k))continue;let g=dn(f,p);if(g){m.push(d),o(`[vibe64-exec-helper] Not registering ${d} \
|
|
166
|
+
as a Vibe64 person of ${e}: ${g}`);continue}ln(u,f),l.push(d),o(`[vibe64-exec-helper] Registered ${d} as a Vibe64 person\
|
|
167
|
+
of ${e}.`)}}finally{ie(u)}return on(h(a,c),h(a,e)),Wt(a),{imported:l,refused:m}}finally{ie(a)}}function ks(e={}){let t;
|
|
168
|
+
try{t=Z(e.home,Pt)}catch(r){if(r.code==="ENOENT")return[];throw r}try{let r=[];for(let n of As(h(t)).sort()){let o=n.endsWith(
|
|
169
|
+
".json")?n.slice(0,-5):"";if(Ut.test(o))try{JSON.parse(T(t,n,{maxBytes:Dt,uid:e.uid}))?.username===o&&r.push(o)}catch{}}
|
|
170
|
+
return r}finally{ie(t)}}import{closeSync as $s,fsyncSync as Cs,lstatSync as Zt,mkdirSync as Ps,openSync as Ds,renameSync as Us,unlinkSync as En,
|
|
171
|
+
writeFileSync as Gs}from"node:fs";import Fe from"node:path";import js from"node:process";var Et="/bin/sh",Qt=0;function er(e="",t=xe()){return Fe.join(t,e)}function Sn(e="",t=dt()){return Fe.join(t,`vibe64-sta\
|
|
172
|
+
ging-${e}`)}function Ls(e=""){try{return Zt(e),!0}catch(t){if(t?.code==="ENOENT")return!1;throw t}}function St(e="",{keysRoot:t=xe(),
|
|
173
|
+
rootUid:r=Qt}={}){try{let n=Zt(er(e,t));return n.isFile()&&n.uid===r&&(n.mode&18)===0}catch{return!1}}function Bs(e=xe(),t=Qt){
|
|
174
|
+
Ps(e,{mode:493,recursive:!0});let r=Zt(e);if(!r.isDirectory()||r.uid!==t||(r.mode&18)!==0)throw new Error(`Vibe64 exec h\
|
|
175
|
+
elper refused ${e}: it is not root's own folder.`)}function gn(e="",t="",r=420,n=null){let o=`${Fe.dirname(e)}/.${Fe.basename(
|
|
176
|
+
e)}.${js.pid}`,i=Ds(o,"wx",r);try{try{Gs(i,t),Cs(i)}finally{$s(i)}n&&n(o),Us(o,e)}catch(s){try{En(o)}catch{}throw s}it(Fe.
|
|
177
|
+
dirname(e))}function hn(e=""){if(!Ls(e))return!1;try{return En(e),!0}catch(t){if(t?.code==="ENOENT")return!1;throw t}}function wn(e,t,r,{
|
|
178
|
+
accountDatabase:n=te(),keysRoot:o=xe(),prefixParent:i,rootUid:s=Qt,runRoot:a=_,sudoersRoot:c=dt()}={}){Bs(o,s),gn(er(e.username,
|
|
176
179
|
o),`command="${r} staging-shell",restrict,pty,from="127.0.0.1,::1" ${t} vibe64-staging
|
|
177
|
-
`,420),
|
|
178
|
-
`,288,u=>a("visudo",["-cqf",u])),e.shell!==
|
|
180
|
+
`,420),gn(Sn(e.username,c),`${e.username} ALL=(root) NOPASSWD: ${r} staging-service *
|
|
181
|
+
`,288,u=>a("visudo",["-cqf",u])),e.shell!==Et&&Lt(e.username,Et,n,{prefixParent:i,run:a})}function Vs(e="",t=N){let r=t(
|
|
179
182
|
"atq",[]);if(r.status!==0)return;let n=String(r.stdout||"").split(`
|
|
180
|
-
`).map(o=>o.trim().split(/\s+/u)).filter(o=>o.length>1&&o.at(-1)===e).map(([o])=>o);n.length>0&&t("atrm",n)}function
|
|
181
|
-
accountDatabase:r=te(),keysRoot:n=
|
|
182
|
-
|
|
183
|
-
loginctl",["terminate-user",t]),s("crontab",["-u",t,"-r"]),
|
|
184
|
-
e.home||"");if(!
|
|
185
|
-
s home to hide its private state.");return
|
|
186
|
-
username}`,"UMask=0077",...
|
|
187
|
-
"UMask=0007"]}function
|
|
188
|
-
elper rejected a staging service port.");return t}var
|
|
183
|
+
`).map(o=>o.trim().split(/\s+/u)).filter(o=>o.length>1&&o.at(-1)===e).map(([o])=>o);n.length>0&&t("atrm",n)}function wt(e,t,{
|
|
184
|
+
accountDatabase:r=te(),keysRoot:n=xe(),prefixParent:o,runRoot:i=_,runRootAllowFailure:s=N,sudoersRoot:a=dt()}={}){let c=hn(
|
|
185
|
+
er(t,n)),u=hn(Sn(t,a));return e&&(e.shell!==ve&&Lt(t,ve,r,{prefixParent:o,run:i}),s("loginctl",["disable-linger",t]),s("\
|
|
186
|
+
loginctl",["terminate-user",t]),s("crontab",["-u",t,"-r"]),Vs(t,s)),c||u}import{existsSync as Xs}from"node:fs";import We from"node:path";import yn from"node:path";var Fs="editor-private",Ws=Object.freeze([".local","state","vibe64"]);function Hs(e={}){let t=String(
|
|
187
|
+
e.home||"");if(!yn.isAbsolute(t)||/[\r\n\s"\\]/u.test(t))throw new Error("Vibe64 exec helper needs the workspace daemon'\
|
|
188
|
+
s home to hide its private state.");return yn.join(t,...Ws,Fs)}function yt(e={}){return`InaccessiblePaths=-${Hs(e)}`}function tr(e={},{receiptRoot:t="",sandboxAllowances:r=[]}={}){return e.stagingAccount?[`User=${e.username}`,`Group=${e.
|
|
189
|
+
username}`,"UMask=0077",...zs(e.stagingAccount,[t],r)]:[`User=${e.username}`,`Group=${k}`,"SupplementaryGroups=nix-users",
|
|
190
|
+
"UMask=0007"]}function rr(e){let t=Number(e);if(!Number.isSafeInteger(t)||t<1024||t>65535)throw new Error("Vibe64 exec h\
|
|
191
|
+
elper rejected a staging service port.");return t}var nr=Object.freeze({fuse:Object.freeze({devices:Object.freeze(["/dev\
|
|
189
192
|
/fuse"]),namespaces:Object.freeze(["user","mnt"]),systemCalls:Object.freeze(["@mount"])}),gvisor:Object.freeze({devices:Object.
|
|
190
193
|
freeze([]),namespaces:Object.freeze(["user","mnt","pid","ipc","uts","net"]),systemCalls:Object.freeze(["@mount","ptrace"])})}),
|
|
191
|
-
|
|
194
|
+
Ys=Object.freeze(["user","mnt","pid","ipc","uts","net"]);function Ks(e=[]){let t=e.map(i=>{let s=nr[i];if(!s)throw new Error(
|
|
192
195
|
"Vibe64 exec helper rejected an unknown staging sandbox allowance.");return s}),r=[...new Set(t.flatMap(i=>i.devices))],
|
|
193
196
|
n=new Set(t.flatMap(i=>i.namespaces)),o=[...new Set(t.flatMap(i=>i.systemCalls))];return{devices:r.flatMap(i=>[`DeviceAl\
|
|
194
|
-
low=${i} rw`,`BindPaths=${i}`]),namespaces:n.size>0?`RestrictNamespaces=${
|
|
195
|
-
mespaces=yes",systemCalls:["SystemCallFilter=@system-service",...o].join(" ")}}function
|
|
197
|
+
low=${i} rw`,`BindPaths=${i}`]),namespaces:n.size>0?`RestrictNamespaces=${Ys.filter(i=>n.has(i)).join(" ")}`:"RestrictNa\
|
|
198
|
+
mespaces=yes",systemCalls:["SystemCallFilter=@system-service",...o].join(" ")}}function zs(e={},t=[],r=[]){let n=Ks(r);return[
|
|
196
199
|
"NoNewPrivileges=yes","PrivateTmp=yes","PrivateDevices=yes",...n.devices,"PrivateIPC=yes","TemporaryFileSystem=/dev/shm:\
|
|
197
|
-
mode=1777,nosuid,nodev","ProtectSystem=strict",`ReadWritePaths=${[e.appRoot,e.databaseRoot,...t.filter(Boolean)].map(
|
|
200
|
+
mode=1777,nosuid,nodev","ProtectSystem=strict",`ReadWritePaths=${[e.appRoot,e.databaseRoot,...t.filter(Boolean)].map(Y).
|
|
198
201
|
join(" ")}`,"ProtectHome=yes","ProtectProc=invisible","ProtectKernelTunables=yes","ProtectKernelModules=yes","ProtectKer\
|
|
199
202
|
nelLogs=yes","ProtectControlGroups=yes",n.namespaces,"LockPersonality=yes","CapabilityBoundingSet=","RestrictAddressFami\
|
|
200
203
|
lies=AF_INET AF_INET6 AF_UNIX AF_NETLINK","SystemCallArchitectures=native",n.systemCalls,"SystemCallErrorNumber=EPERM",`\
|
|
201
|
-
InaccessiblePaths=${Q}`]}function
|
|
202
|
-
${r} does not exist.`);return n}function
|
|
203
|
-
could not resolve the managed service workspace.");return
|
|
204
|
+
InaccessiblePaths=${Q}`]}function or(e="",t={},r="path"){let n=sr(e,t);if(!Xs(n))throw new Error(`Vibe64 managed service\
|
|
205
|
+
${r} does not exist.`);return n}function An(e={}){let t=w(e.username),r=O(t);if(!r)throw new Error("Vibe64 exec helper \
|
|
206
|
+
could not resolve the managed service workspace.");return We.join("/var/lib/vibe64",r,"services")}function sr(e="",t={}){
|
|
204
207
|
let r=String(e||"").trim();if(!r)throw new Error("Vibe64 exec helper rejected an empty managed service path.");let n=v(r,
|
|
205
|
-
{allowMissingLeaf:!0});if(R(v(
|
|
206
|
-
path outside the workspace service root.")}function
|
|
207
|
-
startsWith(
|
|
208
|
-
"/")||r.includes(".."))throw new Error("Vibe64 exec helper rejected an unsafe staging unit name.");return r}function
|
|
209
|
-
let r=String(e||"").trim(),n=
|
|
208
|
+
{allowMissingLeaf:!0});if(R(v(An(t)),n).length>0)return n;throw new Error("Vibe64 exec helper rejected a managed service\
|
|
209
|
+
path outside the workspace service root.")}function He(e="",t={}){let r=String(e||"").trim(),n=O(w(t.username));if(!t.username?.
|
|
210
|
+
startsWith(P)||!r.startsWith(`vibe64-staging-${n}-`)||!r.endsWith(".service")||!/^[A-Za-z0-9_.@:-]+$/u.test(r)||r.includes(
|
|
211
|
+
"/")||r.includes(".."))throw new Error("Vibe64 exec helper rejected an unsafe staging unit name.");return r}function At(e="",t={}){
|
|
212
|
+
let r=String(e||"").trim(),n=We.basename(We.dirname(An(t)));if(!r.startsWith(`vibe64-managed-${n}-`)||!r.endsWith(".serv\
|
|
210
213
|
ice")||!/^[A-Za-z0-9_.@:-]+$/u.test(r)||r.includes("/")||r.includes(".."))throw new Error("Vibe64 exec helper rejected a\
|
|
211
|
-
n unsafe managed service unit name.");return r}function
|
|
212
|
-
e")throw new Error("Vibe64 exec helper rejected an unsupported managed service process model.");return t}function
|
|
213
|
-
return
|
|
214
|
-
`Group=${k}`,"SupplementaryGroups=nix-users","UMask=0007",
|
|
214
|
+
n unsafe managed service unit name.");return r}function ir(e=""){let t=String(e||"").trim();if(t!=="forking"&&t!=="simpl\
|
|
215
|
+
e")throw new Error("Vibe64 exec helper rejected an unsupported managed service process model.");return t}function ar(e="",t={},r=V()){
|
|
216
|
+
return We.join(r,He(e,t))}function _n(e="",t={},r=V()){return We.join(r,At(e,t))}function Js(e={}){return[`User=${Y(e.username)}`,
|
|
217
|
+
`Group=${k}`,"SupplementaryGroups=nix-users","UMask=0007",yt(e)]}function On(e={}){return[`Slice=vibe64-${O(w(e.username))}\
|
|
215
218
|
-work.slice`,"MemoryAccounting=yes","IOAccounting=yes","TasksAccounting=yes","KillMode=control-group","OOMPolicy=stop"]}
|
|
216
|
-
function
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
"
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
219
|
+
var cr=`Environment=${Te}=`;function Nn({runtimePackRoot:e="",servicePath:t=""}={}){return[`Environment=PATH=${Y(t)}`,...e?
|
|
220
|
+
[`${cr}${Y(e)}`]:[]]}function vn({environmentFile:e="",helperPath:t="",loopbackPort:r=0,owner:n={},requiredUnits:o=[],runtimePackRoot:i="",
|
|
221
|
+
sandboxAllowances:s=[],servicePath:a="",startScript:c="",unitName:u="",user:l={},workingDirectory:m=""}={}){let d=Array.
|
|
222
|
+
isArray(o)?o:[];return["[Unit]",`Description=Vibe64 staging service ${u}`,`After=${["network-online.target",...d].join("\
|
|
223
|
+
")}`,"Wants=network-online.target",...d.length>0?[`Requires=${d.join(" ")}`]:[],"StartLimitIntervalSec=60","StartLimitB\
|
|
224
|
+
urst=5","","[Service]","Type=simple",...tr(l,{sandboxAllowances:s}),...On(n),`SocketBindAllow=tcp:${rr(r)}`,"SocketBindA\
|
|
225
|
+
llow=udp","SocketBindDeny=any",`WorkingDirectory=${Y(m)}`,...Nn({runtimePackRoot:i,servicePath:a}),"Environment=TMPDIR=/\
|
|
226
|
+
tmp",`ExecStart=/usr/bin/setpriv --no-new-privs -- ${Y(t)} run-staging-unit "${Y(e)}" "${Y(c)}"`,"Restart=always","Resta\
|
|
227
|
+
rtSec=3","KillSignal=SIGTERM","TimeoutStopSec=30","","[Install]","WantedBy=multi-user.target",""].join(`
|
|
228
|
+
`)}function bn({owner:e={},pidFile:t="",processModel:r="simple",runtimePackRoot:n="",servicePath:o="",startScript:i="",unitName:s="",
|
|
229
|
+
workingDirectory:a=""}={}){let c=ir(r);return["[Unit]",`Description=Vibe64 managed service ${s}`,"After=network-online.t\
|
|
230
|
+
arget","Wants=network-online.target","","[Service]",`Type=${c}`,...Js(e),...On(e),`WorkingDirectory=${Y(a)}`,...Nn({runtimePackRoot:n,
|
|
231
|
+
servicePath:o}),`Environment=TMPDIR=${Y(De(e.username))}`,`ExecStart=${Y(i)}`,...c==="forking"?[`PIDFile=${Y(t)}`]:[],"R\
|
|
232
|
+
estart=on-failure","RestartSec=3","TimeoutStartSec=90","TimeoutStopSec=30",""].join(`
|
|
233
|
+
`)}function Y(e=""){let t=String(e||"").trim();if(!t||/[\r\n]/u.test(t))throw new Error("Vibe64 exec helper rejected an \
|
|
234
|
+
unsafe systemd value.");return t.replaceAll("\\","\\\\").replaceAll('"','\\"')}var Ye=new RegExp(`^${at}[a-f0-9]{12}$`,"u"),Ot=b.join(Q,"staging-accounts"),Rn="vibe64.staging-account",kn=/^[a-z0-9][a-z0-9_-]{0,47}$/u,
|
|
235
|
+
oi=/^[A-Za-z0-9_-]{1,171}$/u,si=/^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$/u,ii=100;function Nt(e=B()){
|
|
232
236
|
let t=String(e.VIBE64_STAGING_AREA_ROOT||"").trim();if(!b.isAbsolute(t)||b.resolve(t)!==t||t==="/")throw new Error("This\
|
|
233
|
-
host's Vibe64 exec helper settings name no staging area (VIBE64_STAGING_AREA_ROOT).");return t}function
|
|
234
|
-
keys(
|
|
237
|
+
host's Vibe64 exec helper settings name no staging area (VIBE64_STAGING_AREA_ROOT).");return t}function vt(e,t=B()){let r=Object.
|
|
238
|
+
keys(nr),n=String(t.VIBE64_STAGING_SANDBOX_ALLOWANCES||"").split(/\s+/u).filter(Boolean);if(n.some(s=>!r.includes(s)))throw new Error(
|
|
235
239
|
"This host's Vibe64 exec helper settings name an unknown staging sandbox allowance (VIBE64_STAGING_SANDBOX_ALLOWANCES).");
|
|
236
240
|
let o=e??[];if(!Array.isArray(o)||o.some(s=>typeof s!="string"||!r.includes(s))||new Set(o).size!==o.length)throw new Error(
|
|
237
241
|
"Vibe64 exec helper rejected a staging sandbox allowance it does not know.");let i=o.filter(s=>!n.includes(s));if(i.length>
|
|
238
242
|
0)throw new Error(`Vibe64 exec helper refused staging sandbox allowance ${i.join(", ")}: this host's owner does not perm\
|
|
239
|
-
it it (VIBE64_STAGING_SANDBOX_ALLOWANCES).`);return[...o].sort()}function
|
|
243
|
+
it it (VIBE64_STAGING_SANDBOX_ALLOWANCES).`);return[...o].sort()}function $n(e={}){let t=j(),r=String(e.action||"").trim();
|
|
240
244
|
if(r!=="ensure"&&r!=="retire")throw new Error("Vibe64 exec helper rejected an unknown staging account action.");let n=r===
|
|
241
|
-
"ensure"?{account:
|
|
242
|
-
`)}function
|
|
243
|
-
ng accounts.");return
|
|
244
|
-
"/"),i=o.at(-1),s=o.length===4&&o[0]===".learning"&&
|
|
245
|
-
if(!
|
|
245
|
+
"ensure"?{account:ui(t,e.project)}:mi(t,e.project);In.stdout.write(`${JSON.stringify({ok:!0,...n})}
|
|
246
|
+
`)}function Cn(e={}){let t=String(e.username||"");if(!t.startsWith(P))throw new Error("Only a workspace daemon has stagi\
|
|
247
|
+
ng accounts.");return Be(t.slice(P.length))}function Ke(e={},t="",{areaRoot:r=Nt()}={}){let n=Cn(e),o=String(t||"").split(
|
|
248
|
+
"/"),i=o.at(-1),s=o.length===4&&o[0]===".learning"&&oi.test(o[1])&&si.test(o[2])&&i===`training-${o[2].replaceAll("-","")}`;
|
|
249
|
+
if(!kn.test(i)||o.length>1&&!s)throw new Error("Vibe64 exec helper rejected an invalid project name.");let a=b.join(r,n,
|
|
246
250
|
i);return{appRoot:b.join(a,"app"),areaRoot:r,databaseRoot:b.join(a,"database"),folder:o,handoverRoot:b.join(a,"handover"),
|
|
247
|
-
home:b.join(a,"app","home"),project:i,projectRoot:a,username:`${
|
|
248
|
-
0,12)}`,workspace:n}}function
|
|
249
|
-
groupGid:r.status===0?Number(String(r.stdout).split(":")[2]):-1,groups:n,loginUids:t,stagingAccess:
|
|
251
|
+
home:b.join(a,"app","home"),project:i,projectRoot:a,username:`${at}${qs("sha256").update(`${n}\0${i}`).digest("hex").slice(
|
|
252
|
+
0,12)}`,workspace:n}}function lr(e=""){let t=Jt(),r=xn("getent",["group",e],{encoding:"utf8"}),n=[];try{n=Pe(e)}catch{}return{
|
|
253
|
+
groupGid:r.status===0?Number(String(r.stdout).split(":")[2]):-1,groups:n,loginUids:t,stagingAccess:St(e)}}function mr(e={},t={},r={}){
|
|
250
254
|
if(e.username!==t.username||!Number.isSafeInteger(e.uid)||e.uid<=0||e.uid>=r.loginUids.min)return`${e.username} is not a\
|
|
251
|
-
system account.`;let n=e.shell===ve||e.shell===
|
|
255
|
+
system account.`;let n=e.shell===ve||e.shell===Et&&r.stagingAccess===!0;return e.home!==t.home||!n?`${e.username} does \
|
|
252
256
|
not have its application's home and no login.`:r.groupGid!==e.gid||r.groups.length!==1||r.groups[0]!==e.username?`${e.username}\
|
|
253
|
-
is in a group other than its own.`:""}function
|
|
257
|
+
is in a group other than its own.`:""}function dr(e="",t="",{registryRoot:r=Ot,registryUid:n=0}={}){if(!Ye.test(String(
|
|
254
258
|
t)))return null;let o;try{o=de(e,{registryRoot:r,registryUid:n})}catch{return null}try{let i=JSON.parse(T(o,`${se(t)}.js\
|
|
255
|
-
on`,{maxBytes:
|
|
256
|
-
i.uid)&&Number.isSafeInteger(i.gid)&&
|
|
257
|
-
return null}finally{
|
|
258
|
-
registryRoot:r,registryUid:n});try{
|
|
259
|
-
|
|
260
|
-
descriptor:-1};let c=
|
|
259
|
+
on`,{maxBytes:Kt,othersMayWrite:!1,uid:n}));return i?.schema===Rn&&i.schemaVersion===1&&i.username===t&&Number.isSafeInteger(
|
|
260
|
+
i.uid)&&Number.isSafeInteger(i.gid)&&kn.test(String(i.project))?{gid:i.gid,project:i.project,uid:i.uid,username:t}:null}catch{
|
|
261
|
+
return null}finally{D(o)}}function Pn(e={},t={},{registryRoot:r=Ot,registryUid:n=0}={}){let o=de(e.workspace,{create:!0,
|
|
262
|
+
registryRoot:r,registryUid:n});try{zt(o,{gid:t.gid,project:e.project,schema:Rn,schemaVersion:1,uid:t.uid,username:e.username})}finally{
|
|
263
|
+
D(o)}}function Xe(e,t="",{gid:r,mode:n,uid:o},{verify:i=!0}={}){let s=h(e,se(t)),a=ue(s,448);if(!a&&!i)return{created:a,
|
|
264
|
+
descriptor:-1};let c=_t(s,C);try{if(a)Qs(c,o,r),Zs(c,n);else if(i){let u=ei(c);if(u.uid!==o||u.gid!==r||n===457&&(u.mode&
|
|
261
265
|
18)!==0)throw new Error(`The staging area's ${t} directory is not the one the helper made.`)}return{created:a,descriptor:c}}catch(u){
|
|
262
|
-
throw
|
|
263
|
-
try{for(let i of[b.basename(e.areaRoot),e.workspace,e.project]){let s;n?s=
|
|
264
|
-
h(o,se(i)),r),
|
|
265
|
-
"setfacl",["-m",`u:${w(t.username)}:x`,`/proc/${
|
|
266
|
-
gid:r.gid,mode:448,uid:r.uid};a.push(
|
|
267
|
-
a.push(u),a.push(
|
|
268
|
-
for(let c of a)c>=0&&
|
|
266
|
+
throw D(c),u}}function fr(e={},{areaGid:t=0,areaUid:r=0,create:n=!0}={}){let o=_t(b.dirname(e.areaRoot),Tn.O_RDONLY|Tn.O_DIRECTORY);
|
|
267
|
+
try{for(let i of[b.basename(e.areaRoot),e.workspace,e.project]){let s;n?s=Xe(o,i,{gid:t,mode:457,uid:r}).descriptor:s=X(
|
|
268
|
+
h(o,se(i)),r),D(o),o=s}return o}catch(i){throw D(o),i}}function ai(e={},t={},r={},{areaGid:n=0,areaUid:o=0,grantDaemonSearch:i=s=>_(
|
|
269
|
+
"setfacl",["-m",`u:${w(t.username)}:x`,`/proc/${In.pid}/fd/${s}`])}={}){let s=fr(e,{areaGid:n,areaUid:o}),a=[s];try{let c={
|
|
270
|
+
gid:r.gid,mode:448,uid:r.uid};a.push(Xe(s,"handover",{gid:r.gid,mode:1512,uid:t.uid}).descriptor);let u=Xe(s,"app",c).descriptor;
|
|
271
|
+
a.push(u),a.push(Xe(u,"home",c,{verify:!1}).descriptor);let l=Xe(s,"database",c);a.push(l.descriptor),l.created&&i(l.descriptor)}finally{
|
|
272
|
+
for(let c of a)c>=0&&D(c)}}function ci(e={},{stagingAccountLimit:t,managedRoot:r,registryRoot:n,registryUid:o}){try{D(Z(
|
|
269
273
|
b.join(r,e.workspace),["projects",...e.folder]))}catch(s){throw["ELOOP","ENOENT","ENOTDIR"].includes(s.code)?new Error(`\
|
|
270
274
|
Vibe64 exec helper refused a staging account: ${e.workspace} has no project ${e.folder.join("/")}.`):s}let i=0;try{let s=de(
|
|
271
|
-
e.workspace,{registryRoot:n,registryUid:o});try{i=
|
|
272
|
-
|
|
273
|
-
already has ${t}, its limit. Retire unused ones first.`)}function
|
|
274
|
-
createUser:o=m=>_("useradd",[...
|
|
275
|
-
ll",ve,m.username]),facts:i=
|
|
276
|
-
t,{areaRoot:n}),d={registryRoot:a,registryUid:c},f=
|
|
275
|
+
e.workspace,{registryRoot:n,registryUid:o});try{i=ur(h(s)).filter(a=>a.endsWith(".json")&&Ye.test(a.slice(0,-5))).length}finally{
|
|
276
|
+
D(s)}}catch(s){if(s.code!=="ENOENT")throw s}if(i>=t)throw new Error(`Vibe64 exec helper refused a staging account: ${e.workspace}\
|
|
277
|
+
already has ${t}, its limit. Retire unused ones first.`)}function ui(e={},t="",{stagingAccountLimit:r=ii,areaRoot:n=Nt(),
|
|
278
|
+
createUser:o=m=>_("useradd",[...Gt(te()),...mt(),"--system","--user-group","--no-create-home","--home-dir",m.home,"--she\
|
|
279
|
+
ll",ve,m.username]),facts:i=lr,managedRoot:s=pe,registryRoot:a=Ot,registryUid:c=0,resolveUser:u=ge,...l}={}){let m=Ke(e,
|
|
280
|
+
t,{areaRoot:n}),d={registryRoot:a,registryUid:c},f=dr(m.workspace,m.username,d),p=u(m.username);if(f){if(!p||p.uid!==f.uid||
|
|
277
281
|
p.gid!==f.gid||f.project!==m.project)throw new Error(`The registered staging account ${m.username} is not the account on\
|
|
278
|
-
this host.`)}else
|
|
279
|
-
"it was not created.";if(g)throw new Error(`Vibe64 exec helper refused staging account ${m.username}: ${g}`);return f||
|
|
280
|
-
m,p,d),
|
|
281
|
-
function
|
|
282
|
-
try{let n;try{n=
|
|
283
|
-
|
|
284
|
-
facts:s=
|
|
285
|
-
unitUid:d=0}={}){let f=
|
|
286
|
-
if(y){let A=g&&g.uid!==y.uid?"it is not the registered account.":
|
|
287
|
-
helper refused to retire staging account ${f.username}: ${A}`);let I=
|
|
288
|
-
({lines:
|
|
289
|
-
is still installed. Remove it before retiring the account.`)}let M=
|
|
282
|
+
this host.`)}else ci(m,{stagingAccountLimit:r,managedRoot:s,...d}),p||(o(m),p=u(m.username));let g=p?mr(p,m,i(m.username)):
|
|
283
|
+
"it was not created.";if(g)throw new Error(`Vibe64 exec helper refused staging account ${m.username}: ${g}`);return f||Pn(
|
|
284
|
+
m,p,d),ai(m,e,p,l),{appRoot:m.appRoot,databaseRoot:m.databaseRoot,handoverRoot:m.handoverRoot,home:m.home,username:m.username}}
|
|
285
|
+
function li(e={},{areaUid:t=0}={}){let r;try{r=fr(e,{areaUid:t,create:!1})}catch(n){if(n.code==="ENOENT")return[];throw n}
|
|
286
|
+
try{let n;try{n=_t(h(r,"database"),C)}catch(o){if(o.code==="ENOENT")return[];throw o}try{return ur(h(n)).sort()}finally{
|
|
287
|
+
D(n)}}finally{D(r)}}function mi(e={},t="",{areaRoot:r=Nt(),areaUid:n=0,deleteUser:o=f=>_("userdel",[...Gt(te()),f]),endStagingAccess:i=wt,
|
|
288
|
+
facts:s=lr,registryRoot:a=Ot,registryUid:c=0,resolveUser:u=ge,running:l=f=>xn("pgrep",["-U",String(f)]).status!==1,unitRoot:m=V(),
|
|
289
|
+
unitUid:d=0}={}){let f=Ke(e,t,{areaRoot:r}),p={registryRoot:a,registryUid:c},g=dr(f.workspace,f.username,p),y=u(f.username);
|
|
290
|
+
if(y){let A=g&&g.uid!==y.uid?"it is not the registered account.":mr(y,f,s(f.username));if(A)throw new Error(`Vibe64 exec\
|
|
291
|
+
helper refused to retire staging account ${f.username}: ${A}`);let I=bt({unitRoot:m,unitUid:d,workspace:f.workspace}).find(
|
|
292
|
+
({lines:ot})=>ot.includes(`User=${f.username}`));if(I)throw new Error(`This staging account's staging service ${I.name} \
|
|
293
|
+
is still installed. Remove it before retiring the account.`)}let M=li(f,{areaUid:n});if(M.length>0)throw new Error(`This\
|
|
290
294
|
staging account's database directory still holds ${M.slice(0,5).join(", ")}${M.length>5?` and ${M.length-5} more`:""}. \
|
|
291
|
-
Give its staging database back to the editor before retiring the account.`);let G=()=>{let A=de(f.workspace,p);try{
|
|
292
|
-
A,`${f.username}.json`))}finally{
|
|
295
|
+
Give its staging database back to the editor before retiring the account.`);let G=()=>{let A=de(f.workspace,p);try{ni(h(
|
|
296
|
+
A,`${f.username}.json`))}finally{D(A)}},z=!!(g&&y);if(z&&G(),y&&l(y.uid))throw z&&Pn(f,y,p),new Error("The staging app s\
|
|
293
297
|
till runs: its staging service, or a staging login of its AI sessions. Stop its staging service, and end its AI sessions\
|
|
294
|
-
' staging access, before retiring it.");y&&i(y,f.username);let J=-1;try{J=
|
|
295
|
-
"ENOENT")throw A}if(J>=0){
|
|
296
|
-
A)}}return g&&!
|
|
298
|
+
' staging access, before retiring it.");y&&i(y,f.username);let J=-1;try{J=fr(f,{areaUid:n,create:!1})}catch(A){if(A.code!==
|
|
299
|
+
"ENOENT")throw A}if(J>=0){D(J);let A=X(b.join(r,f.workspace),n);try{ri(h(A,f.project),{force:!0,recursive:!0})}finally{D(
|
|
300
|
+
A)}}return g&&!z&&G(),y&&o(f.username),{retired:!!(y||g||J>=0)}}function pr(e="",t=()=>ti("/proc/self/mountinfo","utf8")){
|
|
297
301
|
let r=v(e),n={mountPoint:"",options:[]};for(let o of String(t()).split(`
|
|
298
302
|
`)){let[,,,,i="",s=""]=o.split(" "),a=i.replace(/\\([0-7]{3})/gu,(c,u)=>String.fromCharCode(Number.parseInt(u,8)));(a===
|
|
299
303
|
r||R(a,r).length>0)&&a.length>=n.mountPoint.length&&(n={mountPoint:a,options:s.split(",")})}if(!n.options.includes("nosu\
|
|
300
304
|
id"))throw new Error(`Vibe64 exec helper refused to run application code: this host's staging area is not mounted nosuid\
|
|
301
|
-
at ${r}, so a set-user-ID or set-group-ID file there would take effect. Host setup mounts it so.`)}function
|
|
302
|
-
areaRoot:r=
|
|
303
|
-
is not a staging account of this workspace.`);let u=
|
|
304
|
-
c.gid!==l.gid?"it is not the registered account.":
|
|
305
|
-
account ${a}: ${m}`);return
|
|
305
|
+
at ${r}, so a set-user-ID or set-group-ID file there would take effect. Host setup mounts it so.`)}function Me(e={},t="",{
|
|
306
|
+
areaRoot:r=Nt(),facts:n=lr,mountInfo:o,resolveUser:i=$,...s}={}){let a=w(t),c=dr(Cn(e),a,s);if(!c)throw new Error(`${a} \
|
|
307
|
+
is not a staging account of this workspace.`);let u=Ke(e,c.project,{areaRoot:r}),l=i(a),m=u.username!==a||c.uid!==l.uid||
|
|
308
|
+
c.gid!==l.gid?"it is not the registered account.":mr(l,u,n(a));if(m)throw new Error(`Vibe64 exec helper refused staging \
|
|
309
|
+
account ${a}: ${m}`);return pr(r,o),{...l,stagingAccount:u}}function Dn(e="",t={}){let r=v(String(e||"").trim()||t.home);
|
|
306
310
|
for(let n of[t.appRoot,t.databaseRoot]){let o=v(n);if(r===o||R(o,r).length>0)return r}throw new Error("Vibe64 exec helpe\
|
|
307
|
-
r rejected an application command path outside its area.")}function
|
|
308
|
-
let i=String(e||""),[s="",a="",...c]=R(t.handoverRoot,i),u=
|
|
311
|
+
r rejected an application command path outside its area.")}function gr(e="",t={},{cwd:r="",daemonUid:n=-1,gid:o=-1}={}){
|
|
312
|
+
let i=String(e||""),[s="",a="",...c]=R(t.handoverRoot,i),u=Mn(i),l=[b.join(t.appRoot,"sources",s),b.join(t.appRoot,"rele\
|
|
309
313
|
ases",s,"workspace")];if(!s||a!=="environment"||c.length>0||v(i)!==i||!u.isFile()||u.uid!==n||u.gid!==o||(u.mode&23)!==0||
|
|
310
314
|
!l.some(m=>r===m||R(m,r).length>0))throw new Error("Staging environment must belong to the application's selected releas\
|
|
311
|
-
e.");return i}function
|
|
315
|
+
e.");return i}function Un(e={},t={},{daemonUid:r=-1,gid:n=-1}={}){let o=String(e.workingDirectory||""),i=gr(e.environmentFile,
|
|
312
316
|
t,{cwd:o,daemonUid:r,gid:n}),s=b.basename(b.dirname(i)),a=b.join(t.appRoot,"releases",s,"workspace"),c=R(a,o),u=String(e.
|
|
313
|
-
startScript||""),l=
|
|
317
|
+
startScript||""),l=Mn(u);if(b.resolve(o)!==o||o!==a&&c.length===0||u!==b.join(b.dirname(i),"start.sh")||!l.isFile()||l.uid!==
|
|
314
318
|
r||l.gid!==n||(l.mode&18)!==0||(l.mode&8)===0)throw new Error("A staging service must run its own release's workspace an\
|
|
315
|
-
d start script.");try{
|
|
319
|
+
d start script.");try{D(Z(t.appRoot,["releases",s,"workspace",...c]))}catch(m){throw new Error(`A staging service's work\
|
|
316
320
|
ing directory must be a real folder of its release's workspace: ${m.code||m.message}`)}return{environmentFile:i,startScript:u,
|
|
317
|
-
workingDirectory:o}}function
|
|
318
|
-
let i=[];for(let s of
|
|
321
|
+
workingDirectory:o}}function bt({unitRoot:e=V(),unitUid:t=0,workspace:r=""}={}){let n=`vibe64-staging-${r}-`,o=_t(e,C);try{
|
|
322
|
+
let i=[];for(let s of ur(h(o)))if(!(!s.startsWith("vibe64-staging-")||!s.endsWith(".service")))try{i.push({lines:T(o,s,{
|
|
319
323
|
maxBytes:64*1024,othersMayWrite:!1,uid:t}).split(`
|
|
320
324
|
`),name:s})}catch(a){if(!s.startsWith(n))continue;throw Object.assign(new Error(`Staging unit ${s} of workspace ${r} is \
|
|
321
|
-
not a unit file root wrote: ${a.message}`),{code:a.code})}return i}finally{
|
|
322
|
-
unitName:r="",unitRoot:n=
|
|
325
|
+
not a unit file root wrote: ${a.message}`),{code:a.code})}return i}finally{D(o)}}function Gn({loopbackPort:e=0,owner:t={},
|
|
326
|
+
unitName:r="",unitRoot:n=V(),unitUid:o=0,user:i={}}={}){let s=O(w(t.username)),a=String(i.stagingAccount?.project||"").replace(
|
|
323
327
|
/[^a-z0-9]+/gu,"-").replace(/^-+|-+$/gu,"");if(!a||!new RegExp(`^vibe64-staging-${s}-${a}-[a-f0-9]{12}\\.service$`,"u").
|
|
324
|
-
test(r))throw new Error(`Staging service ${r} is not named for application ${i.username}'s project.`);for(let{lines:c,name:u}of
|
|
328
|
+
test(r))throw new Error(`Staging service ${r} is not named for application ${i.username}'s project.`);for(let{lines:c,name:u}of bt(
|
|
325
329
|
{unitRoot:n,unitUid:o,workspace:s}))if(u===r){if(!c.includes(`User=${i.username}`))throw new Error(`Staging service ${r}\
|
|
326
330
|
belongs to another account.`)}else if(c.includes(`SocketBindAllow=tcp:${e}`))throw new Error(`Port ${e} belongs to anot\
|
|
327
|
-
her staging service.`)}import{closeSync as
|
|
328
|
-
|
|
329
|
-
tmp","managed-execution-payloads"],i=
|
|
330
|
-
4 exec helper rejected an unsafe managed execution payload path.");let s=Z(n,o);try{if(
|
|
331
|
-
"Vibe64 exec helper refused a managed execution payload directory owned by another user.");let a=T(s,i,{maxBytes
|
|
332
|
-
uid});return
|
|
333
|
-
"Vibe64 exec helper rejected a non-normalized execution payload.")}function
|
|
331
|
+
her staging service.`)}import{closeSync as di,fstatSync as fi,readSync as pi,unlinkSync as gi}from"node:fs";import hr from"node:path";var hi=4*1024*1024,Ei=1024*1024,jn=4*Math.ceil(hi/3)+Ei,Si=/^[A-Za-z0-9][A-Za-z0-9._-]{0,254}$/u,wi=64*1024,yi=10,Ai=15e3,
|
|
332
|
+
_i="vibe64.exec-helper.payload",Oi=1;function Ln(e="",t={},{managedRoot:r=pe}={}){let n=hr.join(r,O(w(t.username))),o=["\
|
|
333
|
+
tmp","managed-execution-payloads"],i=hr.basename(String(e));if(e!==hr.join(n,...o,i)||!Si.test(i))throw new Error("Vibe6\
|
|
334
|
+
4 exec helper rejected an unsafe managed execution payload path.");let s=Z(n,o);try{if(fi(s).uid!==t.uid)throw new Error(
|
|
335
|
+
"Vibe64 exec helper refused a managed execution payload directory owned by another user.");let a=T(s,i,{maxBytes:jn,uid:t.
|
|
336
|
+
uid});return gi(h(s,i)),Fn(a)}finally{di(s)}}function Bn(e={}){if(e?.schema!==_i||e?.schemaVersion!==Oi)throw new Error(
|
|
337
|
+
"Vibe64 exec helper rejected a non-normalized execution payload.")}function Vn(){return Fn(Ni())}function Fn(e=""){let t;
|
|
334
338
|
try{t=JSON.parse(e)}catch{throw new Error("Vibe64 exec helper payload is not valid JSON.")}if(!t||typeof t!="object"||Array.
|
|
335
|
-
isArray(t))throw new Error("Vibe64 exec helper payload must be a JSON object.");return t}function
|
|
336
|
-
allocUnsafe(
|
|
337
|
-
if(i===0)break;if(o+=i,o
|
|
339
|
+
isArray(t))throw new Error("Vibe64 exec helper payload must be a JSON object.");return t}function Ni(){let e=[],t=Buffer.
|
|
340
|
+
allocUnsafe(wi),r=new Int32Array(new SharedArrayBuffer(4)),n=Date.now()+Ai,o=0;for(;;)try{let i=pi(0,t,0,t.length,null);
|
|
341
|
+
if(i===0)break;if(o+=i,o>jn)throw new Error("Vibe64 exec helper payload is too large.");e.push(Buffer.from(t.subarray(0,
|
|
338
342
|
i)))}catch(i){if(i?.code==="EINTR")continue;if((i?.code==="EAGAIN"||i?.code==="EWOULDBLOCK")&&Date.now()<n){Atomics.wait(
|
|
339
|
-
r,0,0,
|
|
340
|
-
its payload."):i}return Buffer.concat(e,o).toString("utf8")}import{spawn as
|
|
341
|
-
import{createConnection as
|
|
342
|
-
control","job","preview","service","terminal"]),
|
|
343
|
-
1024,
|
|
344
|
-
if(e.stagingAccount===!0){let s=
|
|
345
|
-
t.username),i=o===t.username?t:n(o);return me("uid",e.uid,i.uid),me("gid",e.gid,i.gid),i.username!==t.username?
|
|
346
|
-
i.username,k),i}function
|
|
347
|
-
an invalid managed execution id.");return t.toLowerCase()}function
|
|
348
|
-
"Vibe64 exec helper rejected an unknown managed execution kind.");return t}function
|
|
349
|
-
if(!
|
|
343
|
+
r,0,0,yi);continue}throw i?.code==="EAGAIN"||i?.code==="EWOULDBLOCK"?new Error("Vibe64 exec helper timed out waiting for\
|
|
344
|
+
its payload."):i}return Buffer.concat(e,o).toString("utf8")}import{spawn as Zi,spawnSync as Qi}from"node:child_process";import{readFileSync as ea,unlinkSync as ta}from"node:fs";import fe from"node:path";
|
|
345
|
+
import{createConnection as ra}from"node:net";import{constants as na}from"node:os";import U from"node:process";var Er=/^[a-f0-9]{8}-[a-f0-9]{4}-[1-8][a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$/iu,vi=new Set(["assistant","browser","\
|
|
346
|
+
control","job","preview","service","terminal"]),bi=new Set(["capture","detached","pty"]),Se=64*1024*1024,Tt=1024*1024*1024*
|
|
347
|
+
1024,Wn=256*1024*1024,ze=1024*1024*1024*1024,Je=8,qe=8192;function Hn(e={},t={},{assertInGroup:r=Xr,resolveUser:n=$}={}){
|
|
348
|
+
if(e.stagingAccount===!0){let s=Me(t,e.username);return me("uid",e.uid,s.uid),me("gid",e.gid,s.gid),s}let o=w(e.username||
|
|
349
|
+
t.username),i=o===t.username?t:n(o);return me("uid",e.uid,i.uid),me("gid",e.gid,i.gid),i.username!==t.username?ht(t,i):r(
|
|
350
|
+
i.username,k),i}function K(e=""){let t=String(e||"").trim();if(!Er.test(t))throw new Error("Vibe64 exec helper rejected \
|
|
351
|
+
an invalid managed execution id.");return t.toLowerCase()}function Xn(e=""){let t=String(e||"").trim();if(!vi.has(t))throw new Error(
|
|
352
|
+
"Vibe64 exec helper rejected an unknown managed execution kind.");return t}function Yn(e=""){let t=String(e||"").trim();
|
|
353
|
+
if(!bi.has(t))throw new Error("Vibe64 exec helper rejected an unknown managed execution mode.");return t}function ne(e,t,r,n="\
|
|
350
354
|
value"){let o=Number(e);if(!Number.isSafeInteger(o)||o<t||o>r)throw new Error(`Vibe64 exec helper rejected an invalid ma\
|
|
351
|
-
naged execution ${n}.`);return o}function we(e="",t={}){return`vibe64-exec-${O(w(t.username))}-${
|
|
352
|
-
.service`}function
|
|
353
|
-
readdirSync as
|
|
354
|
-
return
|
|
355
|
+
naged execution ${n}.`);return o}function we(e="",t={}){return`vibe64-exec-${O(w(t.username))}-${K(e).replaceAll("-","")}\
|
|
356
|
+
.service`}function Ze(e={}){return`vibe64-${O(w(e.username))}-work.slice`}import{chmodSync as Ti,closeSync as ye,fchmodSync as wr,fchownSync as Qe,fstatSync as yr,mkdirSync as Kn,openSync as Ie,
|
|
357
|
+
readdirSync as xi,renameSync as Mi,rmSync as Ii,writeFileSync as zn}from"node:fs";import et from"node:path";import Ri from"node:process";var ki=64*1024,Sr="/run/vibe64-staging-accounts";function Ar(e={},{create:t=!1}={}){t&&(ue(Sr),Ti(Sr,457));let r=O(w(e.username));
|
|
358
|
+
return Jn(et.join(Sr,r),{create:t,mode:457})}function xt(e={}){let t=_r(e),r;try{r=Ar(e)}catch(o){throw t.close(),o}let n=[
|
|
355
359
|
t,r];return{close:()=>n.forEach(o=>o.close()),entries:()=>n.flatMap(o=>o.entries()),remove:o=>n.forEach(i=>i.remove(o)),
|
|
356
|
-
result:o=>n.map(i=>i.result(o)).find(i=>i.executionId)||{}}}function
|
|
357
|
-
|
|
360
|
+
result:o=>n.map(i=>i.result(o)).find(i=>i.executionId)||{}}}function _r(e={},{create:t=!1,gid:r=null}={}){let n=Ge(e);return t&&
|
|
361
|
+
$i(n,{gid:r,uid:e.uid}),Jn(et.join(n,"executions"),{create:t,gid:t?r:0,legacyUid:e.uid,uid:0})}function $i(e="",{gid:t=null,
|
|
358
362
|
uid:r=null}={}){if(!Number.isSafeInteger(r)||r<0||!Number.isSafeInteger(t)||t<0)throw new Error("Vibe64 exec helper need\
|
|
359
|
-
s the daemon's uid and the shared group's gid.");ue(e,488);let n=
|
|
360
|
-
t),(o.mode&4095)!==1512&&
|
|
361
|
-
helper has no execution receipt directory.")},entries:()=>[],remove(){},result:()=>({})}),
|
|
362
|
-
"ENOTDIR","ENXIO","EVIBE64UNSAFEFILE"]);function
|
|
363
|
-
e,o);let s;try{s=
|
|
364
|
-
"Vibe64 exec helper refused an execution receipt directory owned by another user.");t&&(
|
|
365
|
-
s),a}return{close:()=>ye(s),entries:()=>
|
|
366
|
-
u=-1;try{u=
|
|
367
|
-
ged-execution.result"&&l.schemaVersion===1&&l.executionId===c?l:{}}catch(l){if(l instanceof SyntaxError||
|
|
368
|
-
return{};throw l}finally{u>=0&&ye(u)}},create(a="",c={},u={},{privateDirectory:l=!1}={}){let m=
|
|
369
|
-
let f=
|
|
370
|
-
ye(y)}p.VIBE64_EXECUTION_PRIVATE_DIR=
|
|
363
|
+
s the daemon's uid and the shared group's gid.");ue(e,488);let n=Ie(e,C);try{let o=yr(n);(o.uid!==r||o.gid!==t)&&Qe(n,r,
|
|
364
|
+
t),(o.mode&4095)!==1512&&wr(n,1512)}finally{ye(n)}}var Ci=Object.freeze({close(){},create(){throw new Error("Vibe64 exec\
|
|
365
|
+
helper has no execution receipt directory.")},entries:()=>[],remove(){},result:()=>({})}),Pi=new Set(["ENOENT","ELOOP",
|
|
366
|
+
"ENOTDIR","ENXIO","EVIBE64UNSAFEFILE"]);function Jn(e="",{create:t=!1,gid:r=0,legacyUid:n=0,mode:o=488,uid:i=0}={}){t&&ue(
|
|
367
|
+
e,o);let s;try{s=Ie(e,C)}catch(a){if(!t&&a?.code==="ENOENT")return Ci;throw a}try{let a=yr(s).uid;if(a!==i&&a!==n)throw new Error(
|
|
368
|
+
"Vibe64 exec helper refused an execution receipt directory owned by another user.");t&&(Qe(s,i,r),wr(s,o))}catch(a){throw ye(
|
|
369
|
+
s),a}return{close:()=>ye(s),entries:()=>xi(h(s)),remove:a=>Ii(h(s,K(a)),{force:!0,recursive:!0}),result(a=""){let c=K(a),
|
|
370
|
+
u=-1;try{u=Ie(h(s,c),C);let l=JSON.parse(T(u,"result.json",{maxBytes:ki,uid:yr(u).uid}));return l?.schema==="vibe64.mana\
|
|
371
|
+
ged-execution.result"&&l.schemaVersion===1&&l.executionId===c?l:{}}catch(l){if(l instanceof SyntaxError||Pi.has(l?.code))
|
|
372
|
+
return{};throw l}finally{u>=0&&ye(u)}},create(a="",c={},u={},{privateDirectory:l=!1}={}){let m=K(a),d=h(s,m);Kn(d,{mode:448});
|
|
373
|
+
let f=Ie(d,C);try{let p={...u.env};if(l){Kn(h(f,"private"),{mode:448});let y=Ie(h(f,"private"),C);try{Qe(y,c.uid,c.gid)}finally{
|
|
374
|
+
ye(y)}p.VIBE64_EXECUTION_PRIVATE_DIR=et.join(e,m,"private")}let g=Ie(h(f,"command.json"),st,384);try{zn(g,`${JSON.stringify(
|
|
371
375
|
{...u,env:p,schema:"vibe64.managed-execution.command",schemaVersion:1})}
|
|
372
|
-
`),
|
|
373
|
-
let r=
|
|
374
|
-
pid}`;
|
|
375
|
-
`,{flag:"wx",mode:384}),
|
|
376
|
-
import
|
|
377
|
-
writeFileSync as
|
|
376
|
+
`),wr(g,384),Qe(g,c.uid,c.gid)}finally{ye(g)}Qe(f,c.uid,c.gid)}finally{ye(f)}return et.join(e,m)}}}function qn(e={},t=""){
|
|
377
|
+
let r=xt(e);try{return r.result(t)}finally{r.close()}}function Zn(e="",t={}){let r=et.join(e,"result.json"),n=`${r}.tmp-${Ri.
|
|
378
|
+
pid}`;zn(n,`${JSON.stringify({...t,schema:"vibe64.managed-execution.result",schemaVersion:1})}
|
|
379
|
+
`,{flag:"wx",mode:384}),Mi(n,r)}import{spawnSync as no}from"node:child_process";import{existsSync as so,readFileSync as rt}from"node:fs";import ee from"node:path";
|
|
380
|
+
import Yi from"node:process";import{closeSync as Di,lstatSync as Ui,mkdirSync as Gi,openSync as ji,readFileSync as Ae,renameSync as Li,unlinkSync as Qn,
|
|
381
|
+
writeFileSync as Bi}from"node:fs";import L from"node:path";import eo from"node:process";function to(e={},{memoryMaxBytes:t=0,tasksMax:r=0}={},{read:n=Ae,run:o=_,runAllowFailure:i=N}={}){let s=Ze(e);Fi(s,{memoryMaxBytes:t,
|
|
378
382
|
tasksMax:r},n)||(i("systemctl",["is-active","--quiet",s]).status!==0&&o("systemctl",["start",s]),o("systemctl",["set-pro\
|
|
379
383
|
perty","--runtime",s,`MemoryMax=${t}`,`TasksMax=${r}`,"MemoryAccounting=yes","IOAccounting=yes","TasksAccounting=yes"]))}
|
|
380
|
-
function
|
|
381
|
-
slice(0,n+1).join("-")}.slice`))}function
|
|
384
|
+
function Vi(e=""){let t=String(e).replace(/\.slice$/u,"").split("-");return L.join("/sys/fs/cgroup",...t.map((r,n)=>`${t.
|
|
385
|
+
slice(0,n+1).join("-")}.slice`))}function Fi(e="",{memoryMaxBytes:t=0,tasksMax:r=0}={},n=Ae){let o=Vi(e);try{let i=String(
|
|
382
386
|
n(L.join(o,"cgroup.controllers"),"utf8")).trim().split(/\s+/u),s=Number(String(n(L.join(o,"memory.max"),"utf8")).trim()),
|
|
383
387
|
a=Number(String(n(L.join(o,"pids.max"),"utf8")).trim());return["memory","io","pids"].every(c=>i.includes(c))&&Number.isSafeInteger(
|
|
384
|
-
s)&&s<=t&&t-s<4096&&a===r}catch{return!1}}function
|
|
388
|
+
s)&&s<=t&&t-s<4096&&a===r}catch{return!1}}function vr(e={},t={}){let r=K(e.id);for(let a of[e.projectKey,e.sessionKey])if(typeof a!=
|
|
385
389
|
"string"||!/^[a-f0-9]{64}$/u.test(a))throw new Error("Vibe64 exec helper rejected an invalid workflow accounting identit\
|
|
386
|
-
y.");let n=w(t.username);if(!n.startsWith(
|
|
390
|
+
y.");let n=w(t.username);if(!n.startsWith(P))throw new Error("Managed workflow accounting requires a workspace daemon ow\
|
|
387
391
|
ner.");let o=O(n);if(!/^[a-z](?:[a-z0-9-]{0,61}[a-z0-9])?$/u.test(o))throw new Error("Invalid managed workflow workspace\
|
|
388
392
|
identity.");let i=`vibe64-${o}-work-p${e.projectKey}.slice`,s=`${i.slice(0,-6)}-s${e.sessionKey}.slice`;return{id:r,workspace:o,
|
|
389
393
|
projectKey:e.projectKey,sessionKey:e.sessionKey,projectUnit:i,sessionUnit:s,unitName:`${s.slice(0,-6)}-w${r.replaceAll("\
|
|
390
|
-
-","")}.slice`}}function
|
|
391
|
-
parse(Ae(
|
|
392
|
-
"Invalid managed workflow result identity.");return t}catch(t){if(t.code==="ENOENT")return null;throw t}}function
|
|
393
|
-
let r=
|
|
394
|
-
let s=
|
|
395
|
-
result directory.")}let n=`${r}.tmp-${
|
|
394
|
+
-","")}.slice`}}function br(e){return L.join("/run/vibe64-workflows",e.workspace,`${e.id}.json`)}function Wi(e){try{let t=JSON.
|
|
395
|
+
parse(Ae(br(e),"utf8"));if(t.schema!=="vibe64.managed-workflow.result.v1"||t.unitName!==e.unitName||t.id!==e.id)throw new Error(
|
|
396
|
+
"Invalid managed workflow result identity.");return t}catch(t){if(t.code==="ENOENT")return null;throw t}}function Hi(e,t){
|
|
397
|
+
let r=br(e);for(let i of["/run/vibe64-workflows",L.dirname(r)]){try{Gi(i,{mode:448})}catch(a){if(a.code!=="EEXIST")throw a}
|
|
398
|
+
let s=Ui(i);if(!s.isDirectory()||s.isSymbolicLink()||s.uid!==0||(s.mode&63)!==0)throw new Error("Unsafe managed workflow\
|
|
399
|
+
result directory.")}let n=`${r}.tmp-${eo.pid}`,o=ji(n,"wx",384);try{try{Bi(o,`${JSON.stringify({...t,schema:"vibe64.man\
|
|
396
400
|
aged-workflow.result.v1"})}
|
|
397
|
-
`)}finally{
|
|
401
|
+
`)}finally{Di(o)}Li(n,r)}catch(i){try{Qn(n)}catch(s){if(s.code!=="ENOENT")throw new AggregateError([i,s],"Workflow recei\
|
|
398
402
|
pt write and cleanup failed.")}throw i}}function ae(e){let t=N("systemctl",["show",e.unitName,"--no-pager","--property=L\
|
|
399
403
|
oadState,ActiveState,ControlGroup,MemoryMax,TasksMax"]),r=Object.fromEntries(String(t.stdout||"").trim().split(`
|
|
400
404
|
`).map(s=>{let a=s.indexOf("=");return[s.slice(0,a),s.slice(a+1)]})),n=String(r.ControlGroup||"");if(n&&(L.posix.basename(
|
|
401
405
|
n)!==e.unitName||!n.includes(`/vibe64-${e.workspace}-work.slice/`)))throw new Error("Managed workflow group does not bel\
|
|
402
406
|
ong to its workspace.");let o={id:e.id,unitName:e.unitName,activeState:r.ActiveState||"unknown",controlGroup:n,memoryMaxBytes:x(
|
|
403
|
-
r.MemoryMax),tasksMax:x(r.TasksMax),...
|
|
404
|
-
(o.scopeEmpty=!0);let i=
|
|
405
|
-
"string"&&/^[0-9]+$/u.test(e.trim())&&Number.isSafeInteger(Number(e))?Number(e):null}function
|
|
407
|
+
r.MemoryMax),tasksMax:x(r.TasksMax),...Mt(n?L.join("/sys/fs/cgroup",n):"")};t.status===0&&r.ActiveState==="inactive"&&!n&&
|
|
408
|
+
(o.scopeEmpty=!0);let i=Wi(e);return i?{...i,activeState:o.activeState,controlGroup:o.controlGroup}:o}function x(e){return typeof e==
|
|
409
|
+
"string"&&/^[0-9]+$/u.test(e.trim())&&Number.isSafeInteger(Number(e))?Number(e):null}function Mt(e=""){function t(a){if(!e)
|
|
406
410
|
return"";try{return Ae(L.join(e,a),"utf8")}catch(c){if(c.code==="ENOENT"||c.code==="ENODEV")return"";throw c}}function r(a){
|
|
407
411
|
return Object.fromEntries(t(a).trim().split(`
|
|
408
412
|
`).map(c=>{let[u,l]=c.trim().split(/\s+/u);return[u,x(l)]}))}let n=r("memory.events"),o=r("memory.stat"),i=r("cgroup.eve\
|
|
409
|
-
nts"),s=t("memory.pressure");return{sampledAt:new Date().toISOString(),sampledMonotonicMs:Number(
|
|
413
|
+
nts"),s=t("memory.pressure");return{sampledAt:new Date().toISOString(),sampledMonotonicMs:Number(eo.hrtime.bigint()/1000000n),
|
|
410
414
|
scopeEmpty:i.populated===0?!0:i.populated===1?!1:null,memoryCurrentBytes:x(t("memory.current")),memoryPeakBytes:x(t("mem\
|
|
411
415
|
ory.peak")),memorySwapCurrentBytes:x(t("memory.swap.current")),memoryAnonBytes:o.anon??null,memoryFileBytes:o.file??null,
|
|
412
416
|
memoryKernelBytes:o.kernel??null,swapInPages:o.pswpin??null,swapOutPages:o.pswpout??null,memoryPressureSomeTotalUsec:x(/^some\s+.*\btotal=([0-9]+)(?:\s|$)/mu.
|
|
413
417
|
exec(s)?.[1]),oomCount:n.oom??null,oomKillCount:n.oom_kill??null,limitHitCount:n.max??null,reclaimCount:n.high??null,tasksCurrent:x(
|
|
414
|
-
t("pids.current")),peakScope:"workflow-lifetime"}}function
|
|
415
|
-
"workflow-inspect")return{ok:!0,...ae(r)};if(n==="workflow-grow"||n==="workflow-limits")return
|
|
418
|
+
t("pids.current")),peakScope:"workflow-lifetime"}}function ro(e,t){let r=vr(e.workflow,t),n=String(e.action||"");if(n===
|
|
419
|
+
"workflow-inspect")return{ok:!0,...ae(r)};if(n==="workflow-grow"||n==="workflow-limits")return Xi(e,r,t);if(n==="workflo\
|
|
416
420
|
w-forget"){let o=ae(r);if(o.scopeEmpty!==!0||o.activeState!=="inactive")throw new Error("Only a completed workflow recei\
|
|
417
|
-
pt can be acknowledged.");try{
|
|
418
|
-
ate"){let o=ne(e.memoryMaxBytes,Se,ze,"workflow memory limit"),i=ne(e.tasksMax,
|
|
419
|
-
mctl",["show",
|
|
421
|
+
pt can be acknowledged.");try{Qn(br(r))}catch(i){if(i.code!=="ENOENT")throw i}return{ok:!0,id:r.id}}if(n==="workflow-cre\
|
|
422
|
+
ate"){let o=ne(e.memoryMaxBytes,Se,ze,"workflow memory limit"),i=ne(e.tasksMax,Je,qe,"workflow task limit"),s=x(_("syste\
|
|
423
|
+
mctl",["show",Ze(t),"--property=MemoryMax","--value"]));if(s===null||o>s)throw new Error("Vibe64 exec helper rejected a \
|
|
420
424
|
workflow above its proven work-slice memory limit.");let a=ae(r);if(a.finishedAt)throw new Error("A completed workflow i\
|
|
421
425
|
dentity cannot be reused.");if(a.activeState==="active"){if(a.memoryMaxBytes!==o||a.tasksMax!==i)throw new Error("An act\
|
|
422
426
|
ive workflow cannot be reconfigured by retrying creation.");return{ok:!0,...a}}_("busctl",["--system","call","org.freede\
|
|
@@ -425,9 +429,9 @@ unitName,"fail","5","MemoryMax","t",String(o),"TasksMax","t",String(i),"MemoryAc
|
|
|
425
429
|
"true","TasksAccounting","b","true","0"]),_("systemctl",["start",r.unitName]);let c=ae(r);if(c.memoryMaxBytes!==o||c.tasksMax!==
|
|
426
430
|
i||c.scopeEmpty!==!0)throw new Error("Managed workflow creation could not prove its limits and empty accounting group.");
|
|
427
431
|
return{ok:!0,...c}}if(n==="workflow-finish"){let o=ae(r);if(!o.finishedAt){if(o.scopeEmpty!==!0)return{ok:!1,code:"workf\
|
|
428
|
-
low_not_empty",...o};
|
|
432
|
+
low_not_empty",...o};Hi(r,{...o,finishedAt:new Date().toISOString()})}let i=N("systemctl",["stop",r.unitName]),s=ae(r);if(s.
|
|
429
433
|
activeState!=="inactive"||s.controlGroup||s.scopeEmpty!==!0)throw new Error(String(i.stderr||"Managed workflow group did\
|
|
430
|
-
not stop.").trim());return{ok:!0,...s}}throw new Error("Vibe64 exec helper rejected an unknown workflow action.")}function
|
|
434
|
+
not stop.").trim());return{ok:!0,...s}}throw new Error("Vibe64 exec helper rejected an unknown workflow action.")}function Or(e,t,r,n){
|
|
431
435
|
let o=Object.fromEntries(_("systemctl",["show",e,"--no-pager","--property=ActiveState,ControlGroup,MemoryMax"]).split(`
|
|
432
436
|
`).map(c=>{let u=c.indexOf("=");return[c.slice(0,u),c.slice(u+1)]}));if(o.ActiveState!=="active"||o.ControlGroup!==t)throw new Error(
|
|
433
437
|
"Memory growth requires the same active, owned accounting group.");let i=x(Ae(L.join("/sys/fs/cgroup",t,"memory.max"),"u\
|
|
@@ -435,51 +439,51 @@ tf8")),s=x(o.MemoryMax);if(s===null||i!==Math.floor(s/r)*r)throw new Error("The
|
|
|
435
439
|
fied.");let a=Ae(L.join("/sys/fs/cgroup",t,"memory.high"),"utf8").trim();if(a!=="max"&&(x(a)===null||n>Number(a)))throw Object.
|
|
436
440
|
assign(new Error("Memory growth is blocked by the target's memory.high limit."),{limitingGroup:{controlGroup:t,limit:"me\
|
|
437
441
|
mory.high",maximumBytes:x(a),requestedBytes:n??null}});return{unitName:e,controlGroup:t,memoryMaxBytes:s,effectiveMemoryMaxBytes:i,
|
|
438
|
-
memoryHighBytes:a==="max"?null:x(a)}}function
|
|
442
|
+
memoryHighBytes:a==="max"?null:x(a)}}function Nr(e,t){let r=[];for(let n=L.posix.dirname(e);n!=="/";n=L.posix.dirname(n)){
|
|
439
443
|
let o={controlGroup:n};for(let[i,s]of[["memory.max","memoryMaxBytes"],["memory.high","memoryHighBytes"]]){let a=Ae(L.join(
|
|
440
444
|
"/sys/fs/cgroup",n,i),"utf8").trim(),c=a==="max"?null:x(a);if(a!=="max"&&(c===null||t>c))throw Object.assign(new Error(`\
|
|
441
445
|
Memory growth is blocked by an ancestor ${i} limit.`),{limitingGroup:{controlGroup:n,limit:i,maximumBytes:c,requestedBytes:t}});
|
|
442
|
-
o[s]=c}r.push(o)}return r}function
|
|
446
|
+
o[s]=c}r.push(o)}return r}function Xi(e,t,r){let n=e.action==="workflow-limits",o=!1,i=[],s=[],a=[],c=[],u=null;try{let l=ae(
|
|
443
447
|
t);if(l.activeState!=="active"||!l.controlGroup||l.finishedAt)throw new Error("Memory growth requires an active workflow\
|
|
444
448
|
.");let m=ne(e.memoryMaxBytes,Se,ze,"workflow memory limit");if(!Array.isArray(e.executions)||e.executions.length>128)throw new Error(
|
|
445
449
|
"Memory growth requires a bounded list of owned executions.");if(u=x(_("getconf",["PAGESIZE"])),!u||u>Se)throw new Error(
|
|
446
450
|
"The kernel memory limit granularity is unavailable.");a=[{unitName:t.unitName,controlGroup:l.controlGroup,memoryMaxBytes:Math.
|
|
447
451
|
floor(m/u)*u,expectedMemoryMaxBytes:e.expectedMemoryMaxBytes}];for(let d of e.executions){let f=we(d?.id,r);if(a.some(g=>g.
|
|
448
|
-
unitName===f))throw new Error("Duplicate memory growth execution.");let p=ne(d.memoryMaxBytes,Se,
|
|
452
|
+
unitName===f))throw new Error("Duplicate memory growth execution.");let p=ne(d.memoryMaxBytes,Se,Tt,"execution memory li\
|
|
449
453
|
mit");if(p>m)throw new Error("Execution memory growth exceeds its workflow allowance.");a.push({unitName:f,controlGroup:`${l.
|
|
450
|
-
controlGroup}/${f}`,memoryMaxBytes:Math.floor(p/u)*u,expectedMemoryMaxBytes:d.expectedMemoryMaxBytes})}if(i=a.map(d=>
|
|
451
|
-
d.unitName,d.controlGroup,u,n?void 0:d.memoryMaxBytes)),n)return{ok:!0,id:t.id,pageSizeBytes:u,before:i,after:i,ancestors:
|
|
454
|
+
controlGroup}/${f}`,memoryMaxBytes:Math.floor(p/u)*u,expectedMemoryMaxBytes:d.expectedMemoryMaxBytes})}if(i=a.map(d=>Or(
|
|
455
|
+
d.unitName,d.controlGroup,u,n?void 0:d.memoryMaxBytes)),n)return{ok:!0,id:t.id,pageSizeBytes:u,before:i,after:i,ancestors:Nr(
|
|
452
456
|
l.controlGroup)};for(let[d,f]of a.entries())if(f.expectedMemoryMaxBytes!==i[d].memoryMaxBytes||f.memoryMaxBytes<i[d].effectiveMemoryMaxBytes)
|
|
453
|
-
throw new Error("Memory growth cannot lower a live limit or apply to stale limits.");c=
|
|
457
|
+
throw new Error("Memory growth cannot lower a live limit or apply to stale limits.");c=Nr(l.controlGroup,a[0].memoryMaxBytes);
|
|
454
458
|
for(let[d,f]of a.entries())i[d].memoryMaxBytes!==f.memoryMaxBytes&&(o=!0,_("systemctl",["set-property","--runtime",f.unitName,
|
|
455
|
-
`MemoryMax=${f.memoryMaxBytes}`]));if(s=a.map(d=>
|
|
459
|
+
`MemoryMax=${f.memoryMaxBytes}`]));if(s=a.map(d=>Or(d.unitName,d.controlGroup,u,d.memoryMaxBytes)),c=Nr(l.controlGroup,a[0].
|
|
456
460
|
memoryMaxBytes),!s.every((d,f)=>d.memoryMaxBytes===a[f].memoryMaxBytes))throw new Error("Memory growth readback did not \
|
|
457
461
|
match the requested limits.");return{ok:!0,id:t.id,changeState:o?"applied":"unchanged",pageSizeBytes:u,before:i,after:s,
|
|
458
|
-
ancestors:c}}catch(l){let m="unchanged";return o&&(s=a.map(d=>{try{return
|
|
462
|
+
ancestors:c}}catch(l){let m="unchanged";return o&&(s=a.map(d=>{try{return Or(d.unitName,d.controlGroup,u)}catch{return null}}),
|
|
459
463
|
m=s.some(d=>d===null)?"unknown":s.every((d,f)=>d.memoryMaxBytes===i[f].memoryMaxBytes)?"unchanged":"partial"),{ok:!1,id:t.
|
|
460
464
|
id,code:"workflow_memory_growth_failed",changeState:m,error:String(l?.message||l),limitingGroup:l?.limitingGroup??null,pageSizeBytes:u,
|
|
461
|
-
before:i,after:s,ancestors:c}}}var
|
|
462
|
-
`).find(s=>s.startsWith("0::")),t=String(e||"").slice(3).replace(/^\/+/,""),r=t?ee.join("/sys/fs/cgroup",t):"";if(!r||!
|
|
463
|
-
r))return{};let n=
|
|
464
|
-
r),cpuUsageNSec:String(Number(n.usage_usec||0)*1e3),ioReadBytes:String(i.readBytes),ioWriteBytes:String(i.writeBytes),memoryCurrent:
|
|
465
|
-
ee.join(r,"memory.current")),memoryPeak:
|
|
466
|
-
oomKillCount:String(Number(o.oom_kill||0)),taskLimit:
|
|
467
|
-
r,"pids.peak"))}}function
|
|
468
|
-
code==="ENOENT")return"0";throw t}}function
|
|
465
|
+
before:i,after:s,ancestors:c}}}var Tr=15e3,Ki=4096;function io(){let e=String(rt("/proc/self/cgroup","utf8")||"").split(`
|
|
466
|
+
`).find(s=>s.startsWith("0::")),t=String(e||"").slice(3).replace(/^\/+/,""),r=t?ee.join("/sys/fs/cgroup",t):"";if(!r||!so(
|
|
467
|
+
r))return{};let n=oo(ee.join(r,"cpu.stat")),o=oo(ee.join(r,"memory.events")),i=zi(ee.join(r,"io.stat"));return{resourceCounters:Mt(
|
|
468
|
+
r),cpuUsageNSec:String(Number(n.usage_usec||0)*1e3),ioReadBytes:String(i.readBytes),ioWriteBytes:String(i.writeBytes),memoryCurrent:tt(
|
|
469
|
+
ee.join(r,"memory.current")),memoryPeak:tt(ee.join(r,"memory.peak")),memorySwapCurrent:tt(ee.join(r,"memory.swap.current")),
|
|
470
|
+
oomKillCount:String(Number(o.oom_kill||0)),taskLimit:ao(r),tasksCurrent:tt(ee.join(r,"pids.current")),tasksPeak:tt(ee.join(
|
|
471
|
+
r,"pids.peak"))}}function tt(e=""){try{let t=String(rt(e,"utf8")||"0").trim();return/^[0-9]+$/u.test(t)?t:"0"}catch(t){if(t?.
|
|
472
|
+
code==="ENOENT")return"0";throw t}}function ao(e,t=rt){if(!e)return null;try{let r=a=>{try{return x(/^max\s+(\d+)$/mu.exec(
|
|
469
473
|
t(ee.join(e,a),"utf8"))?.[1])}catch{return null}},n=r("pids.events.local"),o=r("pids.events"),i=n>0?n:o;if(!(i>0))return null;
|
|
470
474
|
let s=t("/proc/self/mountinfo","utf8").split(`
|
|
471
475
|
`).find(a=>a.split(" ")[4]==="/sys/fs/cgroup"&&a.includes(" - cgroup2 "));return{source:"cgroup-pids-events",count:i,scope:n>
|
|
472
|
-
0&&s&&!s.split(/[ ,]/u).includes("pids_localevents")?"execution":"unknown"}}catch{return null}}function
|
|
473
|
-
fromEntries(String(
|
|
474
|
-
n||"")?[[r,n]]:[]}))}catch(t){if(t?.code==="ENOENT")return{};throw t}}function
|
|
476
|
+
0&&s&&!s.split(/[ ,]/u).includes("pids_localevents")?"execution":"unknown"}}catch{return null}}function oo(e=""){try{return Object.
|
|
477
|
+
fromEntries(String(rt(e,"utf8")||"").split(/\r?\n/u).flatMap(t=>{let[r,n]=t.trim().split(/\s+/u);return r&&/^[0-9]+$/u.test(
|
|
478
|
+
n||"")?[[r,n]]:[]}))}catch(t){if(t?.code==="ENOENT")return{};throw t}}function zi(e=""){let t="";try{t=rt(e,"utf8")}catch(o){
|
|
475
479
|
if(o?.code==="ENOENT")return{readBytes:0,writeBytes:0};throw o}let r=0,n=0;for(let o of String(t||"").split(/\r?\n/u))for(let i of o.
|
|
476
480
|
trim().split(/\s+/u).slice(1)){let[s,a]=i.split("=");s==="rbytes"&&(r+=Number(a||0)),s==="wbytes"&&(n+=Number(a||0))}return{
|
|
477
|
-
readBytes:r,writeBytes:n}}function
|
|
481
|
+
readBytes:r,writeBytes:n}}function co(e="",t="",r={},{query:n=N,readResult:o=qn}={}){let i=n("systemctl",["show",e,"--no\
|
|
478
482
|
-pager","--timestamp=us+utc","--property=LoadState,ActiveState,SubState,Result,ExecMainCode,ExecMainStatus,ExecMainStart\
|
|
479
483
|
Timestamp,ExecMainExitTimestamp,MainPID,ControlGroup,MemoryCurrent,MemoryPeak,MemorySwapCurrent,TasksCurrent,TasksMax,CP\
|
|
480
484
|
UUsageNSec,IOReadBytes,IOWriteBytes"]),s={};for(let y of String(i.stdout||"").split(/\r?\n/u)){let M=y.indexOf("=");M>0&&
|
|
481
485
|
(s[y.slice(0,M)]=y.slice(M+1))}s.LoadState==="not-found"&&(s={LoadState:"not-found"});let a=String(s.ControlGroup||"").trim(),
|
|
482
|
-
c=a?ee.join("/sys/fs/cgroup",a.replace(/^\/+/,"")):"",u=
|
|
486
|
+
c=a?ee.join("/sys/fs/cgroup",a.replace(/^\/+/,"")):"",u=Mt(c),l=c&&so(c)?u.scopeEmpty:!0,m=t?o(r,t):{},d=Date.parse(m.exitObservedAt||
|
|
483
487
|
""),f=Number.isFinite(d)?"runner":"systemd",p=Number.isFinite(d)?d:Date.parse(s.ExecMainExitTimestamp||""),g=Number.isFinite(
|
|
484
488
|
p)&&p>0&&p<=Date.now()?new Date(p).toISOString():"";return{resourceCounters:m.resourceCounters||u,activeState:String(s.ActiveState||
|
|
485
489
|
(m.executionId?"inactive":"unknown")),controlGroup:a,cpuUsageNSec:ce(s.CPUUsageNSec,m.cpuUsageNSec),execMainCode:String(
|
|
@@ -487,27 +491,27 @@ s.ExecMainCode||m.execMainCode||""),execMainStatus:String(s.ExecMainStatus||m.ex
|
|
|
487
491
|
f:"",ioReadBytes:ce(s.IOReadBytes,m.ioReadBytes),ioWriteBytes:ce(s.IOWriteBytes,m.ioWriteBytes),loadState:String(s.LoadState&&
|
|
488
492
|
s.LoadState!=="not-found"?s.LoadState:m.executionId?"recorded":"not-found"),mainPid:String(s.MainPID||"0"),memoryCurrent:ce(
|
|
489
493
|
s.MemoryCurrent,m.memoryCurrent),memoryPeak:ce(s.MemoryPeak,m.memoryPeak),memorySwapCurrent:ce(s.MemorySwapCurrent,m.memorySwapCurrent),
|
|
490
|
-
oomKillCount:ce(m.oomKillCount),taskLimit:m.taskLimit||
|
|
494
|
+
oomKillCount:ce(m.oomKillCount),taskLimit:m.taskLimit||ao(c),result:String(s.Result||m.result||""),signal:String(m.signal||
|
|
491
495
|
""),controllerLeaseClosed:m.controllerLeaseClosed===!0,scopeEmpty:l,startedAt:s.ExecMainStartTimestamp||m.startedAt||"",
|
|
492
496
|
subState:String(s.SubState||"unknown"),tasksCurrent:ce(s.TasksCurrent,m.tasksCurrent),tasksPeak:ce(m.tasksPeak),tasksMax:String(
|
|
493
497
|
s.TasksMax||"0"),unitName:e}}function ce(...e){return String(e.reduce((t,r)=>{let n=Number(r);return Number.isFinite(n)&&
|
|
494
|
-
n>t?n:t},0))}function
|
|
495
|
-
if((n.result==="oom-kill"||Number(n.oomKillCount)>0)&&s>0&&a>=s){let c=Math.min(Date.now(),a+1e3),u=
|
|
498
|
+
n>t?n:t},0))}function uo(e="",t="",r={}){let n=co(e,t,r),o=null,i=n.taskLimit,s=Date.parse(n.startedAt),a=Date.parse(n.exitObservedAt);
|
|
499
|
+
if((n.result==="oom-kill"||Number(n.oomKillCount)>0)&&s>0&&a>=s){let c=Math.min(Date.now(),a+1e3),u=no("journalctl",["-k",
|
|
496
500
|
"--boot=0","--no-pager","--output=json","--output-fields=__REALTIME_TIMESTAMP,__SEQNUM_ID,__SEQNUM,_BOOT_ID,_SOURCE_MONO\
|
|
497
501
|
TONIC_TIMESTAMP,MESSAGE","--lines=65","--case-sensitive=yes",`--since=@${s/1e3}`,`--until=@${c/1e3}`,`--grep=^oom-kill:|\
|
|
498
502
|
^/[^,]*/${e.replaceAll(".","\\.")}(?:/[^,]*)?,task=`],{encoding:"utf8",timeout:2e3,maxBuffer:128*1024});!u.error&&u.status===
|
|
499
|
-
0&&(o=
|
|
500
|
-
a>=s){let c=Math.min(Date.now(),a+1e3),u=
|
|
503
|
+
0&&(o=qi(u.stdout,{unitName:e,workspace:O(r.username),startedAt:s,until:c}))}if(!i&&n.result&&n.result!=="success"&&s>0&&
|
|
504
|
+
a>=s){let c=Math.min(Date.now(),a+1e3),u=no("journalctl",["-k","--boot=0","--no-pager","--output=json","--output-fields=\
|
|
501
505
|
__REALTIME_TIMESTAMP,MESSAGE","--lines=65","--case-sensitive=yes",`--since=@${s/1e3}`,`--until=@${c/1e3}`,`--grep=^cgrou\
|
|
502
506
|
p: fork rejected by pids controller in /.*${e.replaceAll(".","\\.")}(?:/|$)`],{encoding:"utf8",timeout:2e3,maxBuffer:128*
|
|
503
|
-
1024});!u.error&&u.status===0&&(i=
|
|
507
|
+
1024});!u.error&&u.status===0&&(i=Ji(u.stdout,{unitName:e,workspace:O(r.username),startedAt:s,until:c}))}Yi.stdout.write(
|
|
504
508
|
`${JSON.stringify({executionId:t,ok:!0,...n,oomBoundary:o,taskLimit:i})}
|
|
505
|
-
`)}function
|
|
509
|
+
`)}function Ji(e,{unitName:t,workspace:r,startedAt:n,until:o}){if(typeof e!="string"||Buffer.byteLength(e)>128*1024)return null;
|
|
506
510
|
let i=e.trim().split(/\r?\n/u);if(i.length>64)return null;for(let s of i){let a;try{a=JSON.parse(s)}catch{continue}let c=Number(
|
|
507
511
|
a?.__REALTIME_TIMESTAMP)/1e3;if(!Number.isFinite(c)||c<n||c>o)continue;let u=typeof a.MESSAGE=="string"&&/^cgroup: fork rejected by pids controller in (\/[a-zA-Z0-9_./-]{1,2048})$/u.
|
|
508
512
|
exec(a.MESSAGE)?.[1];if(!u)continue;let l=u.split("/"),m=l.indexOf(`vibe64-${r}-work.slice`);if(!(l[1]!=="vibe64.slice"||
|
|
509
513
|
m<2||l.indexOf(t)<=m||l.some((d,f)=>f>0&&(!d||d==="."||d===".."))))return{source:"kernel-journal",scope:"unknown",count:null,
|
|
510
|
-
recordedAt:new Date(c).toISOString()}}return null}function
|
|
514
|
+
recordedAt:new Date(c).toISOString()}}return null}function qi(e,{unitName:t,workspace:r,startedAt:n,until:o}){if(typeof e!=
|
|
511
515
|
"string"||Buffer.byteLength(e)>128*1024)return null;let i=e.trim().split(/\r?\n/u);if(i.length>64)return null;let s=i.flatMap(
|
|
512
516
|
c=>{try{return[JSON.parse(c)]}catch{return[]}}),a=null;for(let c of s){let u=Number(c?.__REALTIME_TIMESTAMP)/1e3;if(!Number.
|
|
513
517
|
isFinite(u)||u<n||u>o)continue;let l=c.MESSAGE;if(typeof l=="string"&&l.startsWith("oom-kill:")&&l.endsWith(",task_memcg\
|
|
@@ -517,249 +521,251 @@ isFinite(u)||u<n||u>o)continue;let l=c.MESSAGE;if(typeof l=="string"&&l.startsWi
|
|
|
517
521
|
c._SOURCE_MONOTONIC_TIMESTAMP)<=1e6&&/^\/[a-zA-Z0-9_./-]+,task=[^,]+,pid=\d+,uid=\d+$/u.test(I.MESSAGE||""));A&&(l+=A.MESSAGE)}
|
|
518
522
|
let m=typeof l=="string"&&l.match(/^oom-kill:constraint=(CONSTRAINT_[A-Z_]+),.*?,(?:oom_memcg=(\/[^,]+)|(global_oom)),task_memcg=(\/[^,]+),task=/u);
|
|
519
523
|
if(!m)continue;let[,d,f,p,g]=m,y=g.split("/"),M=y.indexOf(`vibe64-${r}-work.slice`),G=y.indexOf(t);if(y[1]!=="vibe64.sli\
|
|
520
|
-
ce"||M<2||G<=M||y.some((A,I)=>I>0&&(A==="."||A===".."||!/^[a-zA-Z0-9_.-]+$/u.test(A))))continue;let
|
|
521
|
-
_NONE"&&p)
|
|
522
|
-
0,G+1).join("/");
|
|
524
|
+
ce"||M<2||G<=M||y.some((A,I)=>I>0&&(A==="."||A===".."||!/^[a-zA-Z0-9_.-]+$/u.test(A))))continue;let z;if(d==="CONSTRAINT\
|
|
525
|
+
_NONE"&&p)z="host";else if(d==="CONSTRAINT_MEMCG"&&f&&(g===f||g.startsWith(`${f}/`))){let A=f.split("/").at(-1),I=y.slice(
|
|
526
|
+
0,G+1).join("/");z=f===I||f.startsWith(`${I}/`)?"execution":A===`vibe64-${r}-work.slice`?"workspace_work":A===`vibe64-${r}\
|
|
523
527
|
.slice`?"workspace":A==="vibe64.slice"?"platform":/-work-p[a-f0-9]{64}-s[a-f0-9]{64}-w[a-f0-9]{32}\.slice$/u.test(A)?"wo\
|
|
524
528
|
rkflow":/-work-p[a-f0-9]{64}-s[a-f0-9]{64}\.slice$/u.test(A)?"session":/-work-p[a-f0-9]{64}\.slice$/u.test(A)?"project":
|
|
525
529
|
"ancestor"}else return null;let J=f||"";if(a&&a.cgroup!==J)return null;(!a||u>Date.parse(a.recordedAt))&&(a={source:"ker\
|
|
526
|
-
nel-journal",scope:
|
|
530
|
+
nel-journal",scope:z,cgroup:J,recordedAt:new Date(u).toISOString()})}return a}function lo(e){if(e==null)return Tr;if(!Number.
|
|
527
531
|
isSafeInteger(e)||e<0)throw new Error("Vibe64 exec helper rejected an invalid managed execution stop timeout.");return Math.
|
|
528
|
-
min(e,
|
|
532
|
+
min(e,Tr)}function mo(e="",t="",r={},{termTimeoutMs:n=Tr,run:o=N,readState:i=()=>co(e,t,r),removeRuntime:s=()=>{let u=xt(
|
|
529
533
|
r);try{u.remove(t)}finally{u.close()}},now:a=Date.now,wait:c=u=>Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,
|
|
530
534
|
0,u)}={}){let u=i();u.scopeEmpty||o("systemctl",["stop","--no-block",e]);let l=a()+n,m=u.scopeEmpty?u:i();for(;!m.scopeEmpty&&
|
|
531
535
|
a()<l;)c(25),m=i();return m.scopeEmpty||o("systemctl",["kill","--kill-who=all","--signal=SIGKILL",e]),u.scopeEmpty||(o("\
|
|
532
536
|
systemctl",["stop",e]),m=i()),m.scopeEmpty&&(s(),o("systemctl",["reset-failed",e])),{executionId:t,ok:m.scopeEmpty,scopeEmpty:m.
|
|
533
|
-
scopeEmpty,stopped:u.scopeEmpty===!1,...m}}function
|
|
534
|
-
-plain","--no-legend","--full",`vibe64-exec-${O(w(e.username))}-*.service`]),openReceipts:n=()=>
|
|
535
|
-
"systemctl",["reset-failed",...i])}={}){if(!Array.isArray(t)||t.length>
|
|
536
|
-
bounded list of the executions to keep.");let i=new Set(t.map(m=>we(
|
|
537
|
+
scopeEmpty,stopped:u.scopeEmpty===!1,...m}}function fo(e={},t=[],{listUnits:r=()=>N("systemctl",["list-units","--all","-\
|
|
538
|
+
-plain","--no-legend","--full",`vibe64-exec-${O(w(e.username))}-*.service`]),openReceipts:n=()=>xt(e),resetFailed:o=i=>N(
|
|
539
|
+
"systemctl",["reset-failed",...i])}={}){if(!Array.isArray(t)||t.length>Ki)throw new Error("Vibe64 exec helper requires a\
|
|
540
|
+
bounded list of the executions to keep.");let i=new Set(t.map(m=>we(K(m),e))),s=r();if(s.error||s.status!==0)throw new Error(
|
|
537
541
|
"Vibe64 exec helper could not list the workspace's execution units.");let a=new Set,c=[];for(let m of String(s.stdout||"").
|
|
538
542
|
split(/\r?\n/u)){let[d="",,f=""]=m.trim().split(/\s+/u);!d||i.has(d)||(f==="failed"?c.push(d):f!=="inactive"&&a.add(d))}
|
|
539
|
-
let u=0,l=n();try{for(let m of l.entries()){if(!
|
|
543
|
+
let u=0,l=n();try{for(let m of l.entries()){if(!Er.test(m)||m!==m.toLowerCase())continue;let d=we(m,e);i.has(d)||a.has(d)||
|
|
540
544
|
(l.remove(m),u+=1)}}finally{l.close()}for(let m=0;m<c.length;m+=256)o(c.slice(m,m+256));return{ok:!0,released:u,reset:c.
|
|
541
|
-
length}}var
|
|
542
|
-
"workflow-")){let
|
|
543
|
-
`),
|
|
544
|
-
`);return}let o=
|
|
545
|
-
e.termTimeoutMs)});U.stdout.write(`${JSON.stringify(
|
|
546
|
-
`),
|
|
547
|
-
on action.");let s=
|
|
548
|
-
teractive":"service"))throw new Error("Vibe64 exec helper rejected a managed execution lifecycle mismatch.");let l=
|
|
549
|
-
controllerLeaseName,c,t),m=
|
|
550
|
-
only finite commands.");let f=String(e.commandOperation||"").trim(),p=d?
|
|
545
|
+
length}}var po="resource-controller.sock",xr=5e3,oa=5e3;function ho(e={}){let t=j(),r=he(k),n=String(e.action||"").trim();if(n.startsWith(
|
|
546
|
+
"workflow-")){let W=ro(e,t);U.stdout.write(`${JSON.stringify(W)}
|
|
547
|
+
`),W.ok!==!0&&(U.exitCode=1);return}if(n==="release-ended"){U.stdout.write(`${JSON.stringify(fo(t,e.keepExecutionIds))}
|
|
548
|
+
`);return}let o=K(e.executionId),i=we(o,t);if(n==="inspect"){uo(i,o,t);return}if(n==="stop"){let W=mo(i,o,t,{termTimeoutMs:lo(
|
|
549
|
+
e.termTimeoutMs)});U.stdout.write(`${JSON.stringify(W)}
|
|
550
|
+
`),W.scopeEmpty||U.exit(1);return}if(n!=="start")throw new Error("Vibe64 exec helper rejected an unknown managed executi\
|
|
551
|
+
on action.");let s=Yn(e.mode),a=Xn(e.kind),c=String(e.lifecycle||"").trim();if(c!==(s==="capture"?"finite":s==="pty"?"in\
|
|
552
|
+
teractive":"service"))throw new Error("Vibe64 exec helper rejected a managed execution lifecycle mismatch.");let l=So(e.
|
|
553
|
+
controllerLeaseName,c,t),m=Hn(e,t),d=m.stagingAccount||null;if(d&&s!=="capture")throw new Error("A staging account runs \
|
|
554
|
+
only finite commands.");let f=String(e.commandOperation||"").trim(),p=d?Dn(e.cwd||"",d):lt(e.cwd||"",t.username,{operation:f,
|
|
551
555
|
targetUser:m}),g=String(e.command||"").trim();if(!g||/[\r\n]/u.test(g))throw new Error("Vibe64 exec helper rejected an i\
|
|
552
|
-
nvalid managed execution command.");if(!d&&m.username!==t.username&&!
|
|
553
|
-
helper rejected an unsupported real-user managed command.");let y=Array.isArray(e.args)?e.args.map(
|
|
556
|
+
nvalid managed execution command.");if(!d&&m.username!==t.username&&!ct.has(fe.basename(g)))throw new Error("Vibe64 exec\
|
|
557
|
+
helper rejected an unsupported real-user managed command.");let y=Array.isArray(e.args)?e.args.map(W=>String(W)):[],M=je(
|
|
554
558
|
e.env||{},m,t.username,f);if(e.usageRecordingPreload){if(d)throw new Error("A staging account does not run the usage rec\
|
|
555
|
-
order.");M.NODE_OPTIONS=
|
|
556
|
-
environment requires a staging account's own execution.");G=
|
|
559
|
+
order.");M.NODE_OPTIONS=tn(e.usageRecordingPreload)}let G="";if(e.stagingEnvironmentFile){if(!d)throw new Error("Staging\
|
|
560
|
+
environment requires a staging account's own execution.");G=gr(e.stagingEnvironmentFile,d,{cwd:p,daemonUid:t.uid,gid:m.
|
|
557
561
|
gid})}if(e.sandboxAllowances!==void 0&&!d)throw new Error("Sandbox allowances require a staging account's own execution.");
|
|
558
|
-
let
|
|
559
|
-
e.workMemoryMaxBytes,
|
|
560
|
-
"Vibe64 exec helper rejected an execution limit above its work-slice limit.");let
|
|
561
|
-
t),
|
|
562
|
-
n execution without its active workflow group.");if(J>
|
|
563
|
-
er rejected an execution limit above its workflow limit.");
|
|
564
|
-
|
|
562
|
+
let z=d?vt(e.sandboxAllowances):[],J=ne(e.memoryMaxBytes,Se,Tt,"memory limit"),A=ne(e.tasksMax,Je,qe,"task limit"),I=ne(
|
|
563
|
+
e.workMemoryMaxBytes,Wn,ze,"work-slice memory limit"),ot=ne(e.workTasksMax,Je,qe,"work-slice task limit");if(J>I||A>ot)throw new Error(
|
|
564
|
+
"Vibe64 exec helper rejected an execution limit above its work-slice limit.");let Br=Ze(t);if(e.workflow){let W=vr(e.workflow,
|
|
565
|
+
t),Re=ae(W);if(Re.activeState!=="active"||!Re.controlGroup||Re.finishedAt)throw new Error("Vibe64 exec helper rejected a\
|
|
566
|
+
n execution without its active workflow group.");if(J>Re.memoryMaxBytes||A>Re.tasksMax)throw new Error("Vibe64 exec help\
|
|
567
|
+
er rejected an execution limit above its workflow limit.");Br=W.unitName}else to(t,{memoryMaxBytes:I,tasksMax:ot});let $t=d?
|
|
568
|
+
Ar(t,{create:!0}):_r(t,{create:!0,gid:r}),Vr=$t.create(o,m,{...d?{stagingAccount:!0}:{},args:y,command:g,controllerLeaseName:l,
|
|
565
569
|
cwd:p,env:M,inputBase64:String(e.inputBase64||""),inputPresent:e.inputPresent===!0,...G?{stagingEnvironmentFile:G}:{},executionId:o},
|
|
566
|
-
{privateDirectory:s==="detached"}),
|
|
567
|
-
c",`--slice=${
|
|
568
|
-
--property=${
|
|
570
|
+
{privateDirectory:s==="detached"}),Vo=fe.join(Vr,"command.json"),Fo=re(),Wo=["--quiet",`--unit=${i}`,"--service-type=exe\
|
|
571
|
+
c",`--slice=${Br}`,`--property=Description=Vibe64 ${a} execution`,...tr(m,{receiptRoot:Vr,sandboxAllowances:z}).map(W=>`\
|
|
572
|
+
--property=${W}`),...d?[]:[`--property=${yt(t)}`],`--property=WorkingDirectory=${p}`,"--property=KillMode=control-group",
|
|
569
573
|
"--property=ExitType=cgroup","--property=OOMPolicy=stop","--property=MemoryAccounting=yes","--property=IOAccounting=yes",
|
|
570
574
|
"--property=TasksAccounting=yes",`--property=MemoryMax=${J}`,`--property=TasksMax=${A}`,"--property=TimeoutStopSec=10s",
|
|
571
575
|
...s==="capture"?["--property=LogLevelMax=notice","--wait","--pipe"]:[],...s==="pty"?["--wait","--pty"]:[],...m.username!==
|
|
572
|
-
t.username?["/usr/bin/setpriv","--no-new-privs","--"]:[],
|
|
573
|
-
if((s!=="detached"||Oe.error||Oe.status!==0)
|
|
574
|
-
number"?Oe.status:1)}async function
|
|
576
|
+
t.username?["/usr/bin/setpriv","--no-new-privs","--"]:[],Fo,"run-managed",Vo],Oe=Qi("systemd-run",Wo,{stdio:"inherit"});
|
|
577
|
+
if((s!=="detached"||Oe.error||Oe.status!==0)&&$t.remove(o),$t.close(),Oe.error)throw Oe.error;U.exit(typeof Oe.status=="\
|
|
578
|
+
number"?Oe.status:1)}async function Eo(e=""){let t=fe.resolve(String(e||"")),r=ea(t,"utf8");ta(t);let n=JSON.parse(r);if(n?.
|
|
575
579
|
schema!=="vibe64.managed-execution.command"||n?.schemaVersion!==1)throw new Error("Vibe64 managed execution runner rejec\
|
|
576
580
|
ted an invalid payload.");let o=String(n.command||"").trim();if(!o||/[\r\n]/u.test(o))throw new Error("Vibe64 managed ex\
|
|
577
|
-
ecution runner rejected an invalid command.");let i=
|
|
578
|
-
i):null;U.umask(n.stagingAccount===!0?63:7);let a=null,c=null,u=!1,l=()=>{u=!0,a&&c===null&&(c=
|
|
579
|
-
let m=new Date().toISOString(),d="";try{a=
|
|
580
|
-
env:n.stagingEnvironmentFile?
|
|
581
|
+
ecution runner rejected an invalid command.");let i=So(n.controllerLeaseName,n.controllerLeaseName?"service":""),s=i?await sa(
|
|
582
|
+
i):null;U.umask(n.stagingAccount===!0?63:7);let a=null,c=null,u=!1,l=()=>{u=!0,a&&c===null&&(c=go(a))};s?.once("close",l);
|
|
583
|
+
let m=new Date().toISOString(),d="";try{a=Zi(o,Array.isArray(n.args)?n.args.map(String):[],{cwd:String(n.cwd||"/"),detached:!!s,
|
|
584
|
+
env:n.stagingEnvironmentFile?je({...U.env,...Ee(n.stagingEnvironmentFile),...n.env},{stagingAccount:n.stagingAccount===!0,
|
|
581
585
|
home:n.env.HOME,username:n.env.USER},n.env.USER):n.env&&typeof n.env=="object"&&!Array.isArray(n.env)?n.env:{},stdio:n.inputPresent===
|
|
582
586
|
!0?["pipe","inherit","inherit"]:"inherit"}),n.inputPresent===!0&&a.stdin.end(Buffer.from(String(n.inputBase64||""),"base\
|
|
583
|
-
64")),u&&(c=
|
|
584
|
-
r",y),a.stdin?.on("error",G=>{G.code!=="EPIPE"&&y(G)}),a.once("close",(G,
|
|
585
|
-
c!==null&&await
|
|
586
|
-
{},executionId:
|
|
587
|
+
64")),u&&(c=go(a));let f=await new Promise((g,y)=>{let M="";a.once("exit",()=>{M=new Date().toISOString()}),a.once("erro\
|
|
588
|
+
r",y),a.stdin?.on("error",G=>{G.code!=="EPIPE"&&y(G)}),a.once("close",(G,z)=>g({signal:z,status:G,exitObservedAt:M}))});
|
|
589
|
+
c!==null&&await ia(a,c.startedAt);let p=typeof f.status=="number"?f.status:1;Zn(fe.dirname(t),{...io(),...u?{controllerLeaseClosed:!0}:
|
|
590
|
+
{},executionId:K(n.executionId),startedAt:m,exitObservedAt:f.exitObservedAt,execMainCode:f.signal?"killed":"exited",execMainStatus:f.
|
|
587
591
|
signal||String(p),result:f.signal?"signal":p===0?"success":"exit-code",signal:String(f.signal||"")}),d=f.signal||"",U.exitCode=
|
|
588
|
-
d?128+(
|
|
589
|
-
function
|
|
590
|
-
controller lease on a finite execution.");return""}if(!(r?n===fe.join(
|
|
591
|
-
basename(n)===
|
|
592
|
-
return new Promise((t,r)=>{let n=
|
|
592
|
+
d?128+(na.signals[d]||0):p}finally{c!==null&&clearTimeout(c.timer),s?.off("close",l),s?.destroy()}d&&s&&U.kill(U.pid,d)}
|
|
593
|
+
function So(e="",t="",r=null){let n=String(e||"");if(t!=="service"){if(n)throw new Error("Vibe64 exec helper rejected a \
|
|
594
|
+
controller lease on a finite execution.");return""}if(!(r?n===fe.join(Ge(r),po):fe.isAbsolute(n)&&fe.resolve(n)===n&&fe.
|
|
595
|
+
basename(n)===po))throw new Error("Vibe64 exec helper rejected an invalid managed service controller lease.");return n}function sa(e=""){
|
|
596
|
+
return new Promise((t,r)=>{let n=ra({path:e}),o=setTimeout(()=>{n.destroy(),r(new Error("Vibe64 managed service could no\
|
|
593
597
|
t attach to its controller lease."))},3e3);o.unref(),n.once("connect",()=>{clearTimeout(o),n.removeListener("error",i),n.
|
|
594
598
|
on("error",()=>n.destroy()),t(n)}),n.once("error",i);function i(s){clearTimeout(o),n.destroy(),r(new Error(`Vibe64 manag\
|
|
595
|
-
ed service controller lease is unavailable: ${s?.code||s}`))}})}function
|
|
596
|
-
()=>
|
|
597
|
-
t;if(n>=
|
|
598
|
-
`);return}!r&&n>=
|
|
599
|
-
pid);if(!Number.isSafeInteger(t)||t<=1)return!1;try{return U.kill(-t,0),!0}catch(r){return r?.code==="EPERM"}}function
|
|
599
|
+
ed service controller lease is unavailable: ${s?.code||s}`))}})}function go(e=null){let t=Date.now();Mr(e,"SIGTERM");let r=setTimeout(
|
|
600
|
+
()=>Mr(e,"SIGKILL"),xr);return r.unref(),{startedAt:t,timer:r}}async function ia(e,t){let r=!1;for(;aa(e);){let n=Date.now()-
|
|
601
|
+
t;if(n>=xr+oa){U.stderr.write(`Vibe64 managed service process tree did not stop after SIGKILL.
|
|
602
|
+
`);return}!r&&n>=xr&&(Mr(e,"SIGKILL"),r=!0),await new Promise(o=>setTimeout(o,25))}}function aa(e=null){let t=Number(e?.
|
|
603
|
+
pid);if(!Number.isSafeInteger(t)||t<=1)return!1;try{return U.kill(-t,0),!0}catch(r){return r?.code==="EPERM"}}function Mr(e=null,t="\
|
|
600
604
|
SIGTERM"){let r=Number(e?.pid);if(!(!Number.isSafeInteger(r)||r<=1))try{U.kill(-r,t)}catch(n){if(n?.code==="ESRCH")return;
|
|
601
605
|
try{e.kill(t)}catch(o){o?.code!=="ESRCH"&&U.stderr.write(`Vibe64 managed service process tree could not be stopped.
|
|
602
|
-
`)}}}import{spawnSync as
|
|
603
|
-
import
|
|
604
|
-
import _e from"node:path";import oe from"node:process";var
|
|
605
|
-
t);return}if(r==="remove"){
|
|
606
|
-
staging unit action.");let o=
|
|
607
|
-
a=[...new Set((Array.isArray(e.requiredUnits)?e.requiredUnits:[]).map(d=>
|
|
608
|
-
owner:t,unitName:n,unitRoot:u,user:o});let l=
|
|
609
|
-
sandboxAllowances:s,servicePath:
|
|
610
|
-
var
|
|
611
|
-
e)||e<1||e>
|
|
612
|
-
"Vibe64 exec helper rejected a service output start time.");return{lines:e,since:t}}function
|
|
613
|
-
function
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
["Service state:",o,...s?["","Recent service output:",s]:[]].join(`
|
|
606
|
+
`)}}}import{spawnSync as Gr}from"node:child_process";import{existsSync as Oa,readFileSync as jr,readlinkSync as Lr}from"node:fs";
|
|
607
|
+
import Na from"node:os";import Dr from"node:path";import F from"node:process";import{closeSync as It,fsyncSync as ca,openSync as ua,readdirSync as la,readFileSync as yo,unlinkSync as kr,writeFileSync as ma}from"node:fs";
|
|
608
|
+
import _e from"node:path";import oe from"node:process";var da=64;function Ao(e={}){let t=j();he(k);let r=String(e.action||"").trim(),n=He(e.unitName,t);if(r==="inspect"){pa(n,
|
|
609
|
+
t);return}if(r==="remove"){_a(n,t);return}if(r!=="install-start")throw new Error("Vibe64 exec helper rejected an unknown\
|
|
610
|
+
staging unit action.");let o=Me(t,e.stagingAccount),i=Un(e,o.stagingAccount,{daemonUid:t.uid,gid:o.gid}),s=vt(e.sandboxAllowances),
|
|
611
|
+
a=[...new Set((Array.isArray(e.requiredUnits)?e.requiredUnits:[]).map(d=>At(d,t)))],c=rr(e.loopbackPort),u=V();Gn({loopbackPort:c,
|
|
612
|
+
owner:t,unitName:n,unitRoot:u,user:o});let l=ar(n,t,u),m=vn({...i,helperPath:re(),loopbackPort:c,owner:t,requiredUnits:a,
|
|
613
|
+
runtimePackRoot:Ft(),sandboxAllowances:s,servicePath:ut(),unitName:n,user:o});vo({activation:"restart",unit:m,unitName:n,
|
|
614
|
+
unitPath:l,unitRoot:u})}var _o=80,wo=5e3,fa=/^[0-9A-Za-z][0-9A-Za-z :.+-]{0,63}$/u;function Oo({lines:e=_o,since:t=""}={}){
|
|
615
|
+
if(!Number.isSafeInteger(e)||e<1||e>wo)throw new Error(`Vibe64 exec helper reads 1 to ${wo} lines of a service's output.`);
|
|
616
|
+
if(t&&!fa.test(t))throw new Error("Vibe64 exec helper rejected a service output start time.");return{lines:e,since:t}}function pa(e="",t={}){
|
|
617
|
+
He(e,t),Rt(e)}function Rt(e="",{lines:t=_o,since:r="",timestamps:n=!1}={}){let o=_("systemctl",["show",e,"--no-pager","-\
|
|
618
|
+
-property=ActiveState,SubState,Result,ExecMainCode,ExecMainStatus,NRestarts"]),i=N("journalctl",["--unit",e,"--no-pager",
|
|
619
|
+
n?"--output=short-iso":"--output=cat",`--lines=${t}`,...r?[`--since=${r}`]:[]]),s=String(i.stdout||i.stderr||"").trim();
|
|
620
|
+
oe.stdout.write(["Service state:",o,...s?["","Recent service output:",s]:[]].join(`
|
|
617
621
|
`)+`
|
|
618
|
-
`)}function
|
|
619
|
-
`${JSON.stringify(
|
|
620
|
-
`);return}if(r==="restart"){oe.stdout.write(`${JSON.stringify(
|
|
621
|
-
`);return}if(r!=="install-start")throw new Error("Vibe64 exec helper rejected an unknown managed service action.");let o=
|
|
622
|
-
e.workingDirectory,t,"workingDirectory"),i=
|
|
623
|
-
t):"",c=
|
|
624
|
-
|
|
625
|
-
query:t=N}={}){let r=s=>String(t("systemctl",["is-active",s]).stdout||"").trim(),n=s=>s==="inactive"||
|
|
626
|
-
t("systemctl",["show",e,"--property=RequiredBy","--value"]).stdout||"").split(/\s+/u).filter(Boolean).
|
|
627
|
-
if(o.length>0)return{ok:!0,requiredBy:o,state:"required"};let i=!n(r(e));return i&&
|
|
628
|
-
["is-enabled",e]).stdout||"").trim()==="enabled"&&
|
|
629
|
-
function
|
|
630
|
-
"loaded")return{ok:!0,restarted:[],state:"absent"};let r=o=>o==="inactive"||o==="failed",n=String(t(
|
|
631
|
-
e,"--property=RequiredBy","--value"]).stdout||"").split(/\s+/u).filter(Boolean).filter(o=>!r(String(
|
|
632
|
-
|
|
633
|
-
"systemctl",t);if(r.status!==0)throw new Error(String(r.stderr||r.stdout||`systemctl ${t[0]} failed.`).trim())}function
|
|
634
|
-
owner:e={},pidFile:t="",unitName:r="",workspaceRoot:n=_e.join(pe,O(w(e.username)))}={}){let o=t?
|
|
635
|
-
|
|
622
|
+
`)}function No(e={}){let t=j();he(k);let r=String(e.action||"").trim(),n=At(e.unitName,t);if(r==="stop"){oe.stdout.write(
|
|
623
|
+
`${JSON.stringify(ga(n))}
|
|
624
|
+
`);return}if(r==="restart"){oe.stdout.write(`${JSON.stringify(ha(n))}
|
|
625
|
+
`);return}if(r!=="install-start")throw new Error("Vibe64 exec helper rejected an unknown managed service action.");let o=or(
|
|
626
|
+
e.workingDirectory,t,"workingDirectory"),i=or(e.startScript,t,"startScript"),s=ir(e.processModel),a=s==="forking"?sr(e.pidFile,
|
|
627
|
+
t):"",c=V(),u=_n(n,t,c),l=bn({owner:t,pidFile:a,processModel:s,runtimePackRoot:Ft(),servicePath:ut(),startScript:i,unitName:n,
|
|
628
|
+
workingDirectory:o});Ea({owner:t,pidFile:a,unitName:n}),vo({activation:"start",enable:!1,unit:l,unitName:n,unitPath:u,unitRoot:c})}
|
|
629
|
+
function ga(e="",{query:t=N}={}){let r=s=>String(t("systemctl",["is-active",s]).stdout||"").trim(),n=s=>s==="inactive"||
|
|
630
|
+
s==="failed",o=String(t("systemctl",["show",e,"--property=RequiredBy","--value"]).stdout||"").split(/\s+/u).filter(Boolean).
|
|
631
|
+
filter(s=>!n(r(s)));if(o.length>0)return{ok:!0,requiredBy:o,state:"required"};let i=!n(r(e));return i&&Rr(t,["stop",e]),
|
|
632
|
+
String(t("systemctl",["is-enabled",e]).stdout||"").trim()==="enabled"&&Rr(t,["disable",e]),{ok:!0,requiredBy:[],state:i?
|
|
633
|
+
"stopped":"inactive"}}function ha(e="",{query:t=N}={}){if(String(t("systemctl",["show",e,"--property=LoadState","--value"]).
|
|
634
|
+
stdout||"").trim()!=="loaded")return{ok:!0,restarted:[],state:"absent"};let r=o=>o==="inactive"||o==="failed",n=String(t(
|
|
635
|
+
"systemctl",["show",e,"--property=RequiredBy","--value"]).stdout||"").split(/\s+/u).filter(Boolean).filter(o=>!r(String(
|
|
636
|
+
t("systemctl",["is-active",o]).stdout||"").trim()));return Rr(t,["restart",e]),{ok:!0,restarted:n,state:"restarted"}}function Rr(e,t=[]){
|
|
637
|
+
let r=e("systemctl",t);if(r.status!==0)throw new Error(String(r.stderr||r.stdout||`systemctl ${t[0]} failed.`).trim())}function Ea({
|
|
638
|
+
owner:e={},pidFile:t="",unitName:r="",workspaceRoot:n=_e.join(pe,O(w(e.username)))}={}){let o=t?wa(t,e,n):null;if(o)try{
|
|
639
|
+
Sa(o,e,r)}finally{o.close()}}function Sa(e,t={},r=""){let n=e.read();if(n===null)return;if(!/^[1-9][0-9]*$/u.test(n))throw new Error(
|
|
636
640
|
"Vibe64 managed service PID file is invalid.");let o=Number(n);if(!Number.isSafeInteger(o)||o<=1)throw new Error("Vibe64\
|
|
637
|
-
managed service PID is invalid.");if(!
|
|
638
|
-
throw new Error("Vibe64 managed service PID belongs to another OS user.");if(
|
|
639
|
-
if(c?.code==="ESRCH"){e.remove(n);return}throw c}let s=Date.now()+3e4,a=new Int32Array(new SharedArrayBuffer(4));for(;
|
|
640
|
-
o)&&Date.now()<s;)Atomics.wait(a,0,0,100);if(
|
|
641
|
-
during ownership transfer.");e.remove(n)}function
|
|
641
|
+
managed service PID is invalid.");if(!Ir(o)){e.remove(n);return}let i=ya(o);if(i===null){e.remove(n);return}if(i!==t.uid)
|
|
642
|
+
throw new Error("Vibe64 managed service PID belongs to another OS user.");if(Aa(o,r))return;try{oe.kill(o,"SIGTERM")}catch(c){
|
|
643
|
+
if(c?.code==="ESRCH"){e.remove(n);return}throw c}let s=Date.now()+3e4,a=new Int32Array(new SharedArrayBuffer(4));for(;Ir(
|
|
644
|
+
o)&&Date.now()<s;)Atomics.wait(a,0,0,100);if(Ir(o))throw new Error("Vibe64 managed service process did not stop cleanly \
|
|
645
|
+
during ownership transfer.");e.remove(n)}function wa(e="",t={},r=""){let n=R(v(r),_e.dirname(e));if(n.length===0)throw new Error(
|
|
642
646
|
"Vibe64 exec helper rejected a managed service PID file outside its workspace.");let o;try{o=Z(r,n)}catch(a){if(a?.code===
|
|
643
|
-
"ENOENT")return null;throw a}let i=_e.basename(e),s=()=>{try{return T(o,i,{maxBytes:
|
|
644
|
-
code==="ENOENT")return null;throw a}};return{close:()=>
|
|
645
|
-
try{return oe.kill(e,0),!0}catch(t){if(t?.code==="ESRCH")return!1;throw t}}function
|
|
647
|
+
"ENOENT")return null;throw a}let i=_e.basename(e),s=()=>{try{return T(o,i,{maxBytes:da,uid:t.uid}).trim()}catch(a){if(a?.
|
|
648
|
+
code==="ENOENT")return null;throw a}};return{close:()=>It(o),read:s,remove(a=""){s()===a&&kr(h(o,i))}}}function Ir(e=0){
|
|
649
|
+
try{return oe.kill(e,0),!0}catch(t){if(t?.code==="ESRCH")return!1;throw t}}function ya(e=0){let t="";try{t=yo(`/proc/${e}\
|
|
646
650
|
/status`,"utf8")}catch(o){if(o?.code==="ENOENT")return null;throw o}let r=String(t||"").match(/^Uid:\s+([0-9]+)/mu),n=Number(
|
|
647
|
-
r?.[1]);if(!Number.isSafeInteger(n))throw new Error("Vibe64 managed service process UID is unavailable.");return n}function
|
|
648
|
-
let r=`/${t}`,n="";try{n=
|
|
651
|
+
r?.[1]);if(!Number.isSafeInteger(n))throw new Error("Vibe64 managed service process UID is unavailable.");return n}function Aa(e=0,t=""){
|
|
652
|
+
let r=`/${t}`,n="";try{n=yo(`/proc/${e}/cgroup`,"utf8")}catch(o){if(o?.code==="ENOENT")return!1;throw o}return String(n||
|
|
649
653
|
"").split(`
|
|
650
|
-
`).some(o=>o.trim().endsWith(r))}function
|
|
651
|
-
unitName:s="",unitPath:a="",unitRoot:c=
|
|
652
|
-
ed an unsupported systemd activation.");let u=c!==
|
|
653
|
-
i),
|
|
654
|
+
`).some(o=>o.trim().endsWith(r))}function vo({activation:e="start",enable:t=!0,rootUid:r=0,run:n=_,runAllowFailure:o=N,unit:i="",
|
|
655
|
+
unitName:s="",unitPath:a="",unitRoot:c=V()}={}){if(e!=="start"&&e!=="restart")throw new Error("Vibe64 exec helper reject\
|
|
656
|
+
ed an unsupported systemd activation.");let u=c!==Le;u&&It(bo(c,r));let l=`${a}.tmp-${oe.pid}`,m=ua(l,"w",420);try{ma(m,
|
|
657
|
+
i),ca(m)}finally{It(m)}try{n("mv",[l,a])}catch(d){try{kr(l)}catch{}throw d}it(_e.dirname(a)),u&&n("systemctl",[t?"enable":
|
|
654
658
|
"link","--runtime",a]),n("systemctl",["daemon-reload"]),t&&!u&&n("systemctl",["enable",s]),o("systemctl",["reset-failed",
|
|
655
|
-
s]);try{n("systemctl",[e,s])}catch(d){throw o("systemctl",["stop",s]),d}}function
|
|
659
|
+
s]);try{n("systemctl",[e,s])}catch(d){throw o("systemctl",["stop",s]),d}}function bo(e="",t=0){try{return X(e,t)}catch(r){
|
|
656
660
|
throw new Error(`Vibe64 exec helper refused unit folder ${e}: it is not a folder only root can change${r.code?` (${r.code}\
|
|
657
|
-
)`:""}.`)}}function
|
|
658
|
-
ime"],e]),N("systemctl",["reset-failed",e]);try{
|
|
659
|
-
mon-reload"])}function
|
|
661
|
+
)`:""}.`)}}function _a(e="",t={},r=V()){He(e,t),N("systemctl",["stop",e]),N("systemctl",["disable",...r===Le?[]:["--runt\
|
|
662
|
+
ime"],e]),N("systemctl",["reset-failed",e]);try{kr(ar(e,t,r))}catch(n){if(n?.code!=="ENOENT")throw n}_("systemctl",["dae\
|
|
663
|
+
mon-reload"])}function To({rootUid:e=0,runAllowFailure:t=N,unitRoot:r=V()}={}){if(r===Le)return;let n=[],o=(a,c)=>{let u=t(
|
|
660
664
|
"systemctl",a);return u.status===0?!0:(n.push(`${c}: ${String(u.stderr||u.stdout||`systemctl ${a[0]} failed.`).trim()}`),
|
|
661
|
-
!1)},i=[],s=
|
|
665
|
+
!1)},i=[],s=bo(r,e);try{for(let a of la(h(s)).sort()){let c=/^vibe64-(staging|managed)-[A-Za-z0-9_.@:-]+\.service$/u.exec(
|
|
662
666
|
a)?.[1];if(!c)continue;try{T(s,a,{maxBytes:64*1024,othersMayWrite:!1,uid:e})}catch(l){n.push(`${a}: not a unit file root\
|
|
663
667
|
wrote (${l.code||l.message})`);continue}let u=c==="staging";o([u?"enable":"link","--runtime",_e.join(r,a)],a)&&u&&i.push(
|
|
664
|
-
a)}}finally{
|
|
668
|
+
a)}}finally{It(s)}o(["daemon-reload"],"daemon-reload");for(let a of i)o(["start","--no-block",a],a);if(n.length>0)throw new Error(
|
|
665
669
|
`Vibe64 exec helper could not relink every unit in ${r}:
|
|
666
670
|
${n.join(`
|
|
667
|
-
`)}`)}function
|
|
668
|
-
exec-helper run-staging-unit <environment-file> <start-script>");
|
|
669
|
-
424b4456d9802ca8333ed424a":"closed","8d45620c1a4348dbb17410da57c60c66":"opened"}),
|
|
670
|
-
|
|
671
|
-
freeze(["/usr/lib/openssh/sftp-server","/usr/libexec/openssh/sftp-server","/usr/lib/sftp-server"]),
|
|
672
|
-
|
|
673
|
-
`)}function
|
|
674
|
-
"").trim();if(!
|
|
675
|
-
|
|
676
|
-
n.username)});return}if(r==="activity"){
|
|
677
|
-
ec helper rejected an unknown staging access action.")}function
|
|
678
|
-
t=json",`--lines=${
|
|
679
|
-
`).filter(Boolean);return{entries:n.slice(
|
|
680
|
-
return Number.isFinite(a)?[{at:new Date(a).toISOString(),entry:s}]:[]}catch{return[]}}),olderOmitted:n.length
|
|
681
|
-
runRootAllowFailure:t=N}={}){if(!e)return{entries:[],olderOmitted:{host:!1,login:!1}};let r=
|
|
682
|
-
systemd-logind.service",`USER_ID=${e.username}`],t),n=
|
|
683
|
-
...r.entries.flatMap(({at:i,entry:s})=>{let a=
|
|
671
|
+
`)}`)}function xo(e="",t=""){if(oe.argv.length!==5||!_e.isAbsolute(e)||!_e.isAbsolute(t))throw new Error("Usage: vibe64-\
|
|
672
|
+
exec-helper run-staging-unit <environment-file> <start-script>");pr(oe.cwd()),oe.execve(t,[t],{...oe.env,...Ee(e)})}var va=/^ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI[A-Za-z0-9+/]{43}$/u,Co="vibe64-staging",$r=500,ba=Object.freeze({"3354939\
|
|
673
|
+
424b4456d9802ca8333ed424a":"closed","8d45620c1a4348dbb17410da57c60c66":"opened"}),Ta=200,xa=/^[A-Za-z0-9._:-]{1,128}$/u,
|
|
674
|
+
Ma=/^[A-Za-z0-9]{1,32}$/u,nt=Object.freeze(["/bin/bash","--noprofile","--norc"]),Ia='[ "$#" -eq 0 ] || exec "$@"',Mo=Object.
|
|
675
|
+
freeze(["/usr/lib/openssh/sftp-server","/usr/libexec/openssh/sftp-server","/usr/lib/sftp-server"]),Ra=/ run-staging-unit "((?:[^"\\]|\\.)*)" "((?:[^"\\]|\\.)*)"$/u,
|
|
676
|
+
Io="/usr/bin/nsenter";function Cr(e){F.stdout.write(`${JSON.stringify({ok:!0,...e})}
|
|
677
|
+
`)}function Po(e={}){let t=j(),r=String(e.action||"").trim(),n=Ke(t,e.project);if(r==="grant"){let o=String(e.publicKey||
|
|
678
|
+
"").trim();if(!va.test(o))throw new Error("Vibe64 exec helper accepts one ssh-ed25519 public key for staging access.");wn(
|
|
679
|
+
Me(t,n.username),o,re()),Cr({account:n.username});return}if(r==="revoke"){Cr({account:n.username,revoked:wt(ge(n.username),
|
|
680
|
+
n.username)});return}if(r==="activity"){Cr({account:n.username,...ka(ge(n.username))});return}throw new Error("Vibe64 ex\
|
|
681
|
+
ec helper rejected an unknown staging access action.")}function Ro(e=[],t=N){let r=t("journalctl",["--no-pager","--outpu\
|
|
682
|
+
t=json",`--lines=${$r+1}`,...e]),n=String(r.stdout||"").split(`
|
|
683
|
+
`).filter(Boolean);return{entries:n.slice(-$r).flatMap(i=>{try{let s=JSON.parse(i),a=Number(s.__REALTIME_TIMESTAMP)/1e3;
|
|
684
|
+
return Number.isFinite(a)?[{at:new Date(a).toISOString(),entry:s}]:[]}catch{return[]}}),olderOmitted:n.length>$r}}function ka(e,{
|
|
685
|
+
runRootAllowFailure:t=N}={}){if(!e)return{entries:[],olderOmitted:{host:!1,login:!1}};let r=Ro(["_UID=0","_SYSTEMD_UNIT=\
|
|
686
|
+
systemd-logind.service",`USER_ID=${e.username}`],t),n=Ro([`SYSLOG_IDENTIFIER=${Co}`,`_UID=${e.uid}`],t);return{entries:[
|
|
687
|
+
...r.entries.flatMap(({at:i,entry:s})=>{let a=ba[s.MESSAGE_ID];return a&&typeof s.SESSION_ID=="string"?[{at:i,event:a,login:s.
|
|
684
688
|
SESSION_ID,source:"host"}]:[]}),...n.entries.flatMap(({at:i,entry:s})=>typeof s.MESSAGE=="string"?[{at:i,message:s.MESSAGE,
|
|
685
|
-
source:"login"}]:[])].sort((i,s)=>i.at.localeCompare(s.at)),olderOmitted:{host:r.olderOmitted,login:n.olderOmitted}}}function
|
|
686
|
-
return e.replace(/\\(.)/gu,"$1")}function
|
|
687
|
-
""}function
|
|
688
|
-
({lines:s})=>s.includes(`User=${e}`)),o=n.find(({name:s})=>t(s))||n.at(-1);if(!o)return null;let i=
|
|
689
|
+
source:"login"}]:[])].sort((i,s)=>i.at.localeCompare(s.at)),olderOmitted:{host:r.olderOmitted,login:n.olderOmitted}}}function Ur(e=""){
|
|
690
|
+
return e.replace(/\\(.)/gu,"$1")}function Pr(e=[],t=""){let r=e.find(n=>n.startsWith(t));return r?Ur(r.slice(t.length)):
|
|
691
|
+
""}function Do(e,{isActive:t=n=>Gr("systemctl",["is-active","--quiet",n]).status===0,units:r=()=>bt()}={}){let n=r().filter(
|
|
692
|
+
({lines:s})=>s.includes(`User=${e}`)),o=n.find(({name:s})=>t(s))||n.at(-1);if(!o)return null;let i=Ra.exec(o.lines.find(
|
|
689
693
|
s=>s.startsWith("ExecStart="))||"");if(!i)throw new Error(`Staging unit ${o.name} does not start a Vibe64 staging servic\
|
|
690
|
-
e.`);return{environmentFile
|
|
691
|
-
o.lines,"WorkingDirectory=")}}function
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
return{argv:[
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
["
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
694
|
+
e.`);return{environmentFile:Ur(i[1]),name:o.name,path:Pr(o.lines,"Environment=PATH="),runtimePackRoot:Pr(o.lines,cr),startScript:Ur(
|
|
695
|
+
i[2]),workingDirectory:Pr(o.lines,"WorkingDirectory=")}}function Uo(e={}){return e.runtimePackRoot?{[Te]:e.runtimePackRoot}:
|
|
696
|
+
{}}function $a(e=""){return Object.fromEntries(["enter","logs","restart","status"].map(t=>[`BASH_FUNC_staging-${t}%%`,`(\
|
|
697
|
+
) { sudo -n ${e} staging-service ${t} "$@"
|
|
698
|
+
}`]))}function Ca(e="",t=Mo.find(r=>Oa(r))){if(!e)return{argv:[...nt],sftp:!1};let r=e.trim().split(/\s+/u)[0];if(r==="i\
|
|
699
|
+
nternal-sftp"||Mo.includes(r)){if(!t)throw new Error("This host has no SFTP server for scp and sftp.");return{argv:[t],sftp:!0}}
|
|
700
|
+
return{argv:[...nt,"-c",e],sftp:!1}}function Go(e=""){return jr(e,"utf8").split(`
|
|
701
|
+
`).includes(Ia)}function ko(e={}){Gr("logger",["--tag",Co,"--",JSON.stringify(e)],{stdio:"ignore"})}function Pa(e,{env:t=F.
|
|
702
|
+
env,helperPath:r="",readEnvironment:n=Ee}={}){let o={...t};return delete o.BASH_ENV,delete o.ENV,{...o,PATH:e.path||t.PATH||
|
|
703
|
+
"",...Uo(e),...n(e.environmentFile),...$a(r),VIBE64_STAGING_UNIT:e.name}}function jo({env:e=F.env,helperPath:t=re()}={}){
|
|
704
|
+
let r=Na.userInfo().username;if(!Ye.test(r))throw new Error("Only a staging account's staging login starts here.");let n=Do(
|
|
705
|
+
r);n||(F.stderr.write(`This project has no release installed on this host, so there is no staging to enter. Publish it f\
|
|
706
|
+
irst.
|
|
707
|
+
`),F.exit(1));let o=String(e.SSH_ORIGINAL_COMMAND||""),i=String(e.VIBE64_AGENT_ENV_COMMAND_SESSION_ID||""),s=String(e.XDG_SESSION_ID||
|
|
708
|
+
""),a={login:Ma.test(s)?s:"",release:Dr.basename(Dr.dirname(n.environmentFile)),session:xa.test(i)?i:""},c=Ca(o);ko({...a,
|
|
709
|
+
command:o.slice(0,2e3),event:"start"});let[u,...l]=!c.sftp&&Go(n.startScript)?[n.startScript,...c.argv]:c.argv,m=Date.now();
|
|
710
|
+
for(let p of["SIGINT","SIGQUIT"])F.on(p,()=>{});let d=Gr(u,l,{cwd:n.workingDirectory,env:Pa(n,{env:e,helperPath:t}),stdio:"\
|
|
711
|
+
inherit"}),f=typeof d.status=="number"?d.status:1;ko({...a,durationMs:Date.now()-m,event:"end",exitCode:f}),F.exit(f)}function kt(){
|
|
712
|
+
return new Error(["Usage, inside a staging login:"," staging-logs [--lines <n>] [--since <time>] the running staging \
|
|
713
|
+
service's newest output (200 lines)"," staging-status its state and newest output"," st\
|
|
714
|
+
aging-restart restart it, then show its state"," staging-enter [command...] \
|
|
715
|
+
run the command, or a shell, where the running service"," runs: the\
|
|
716
|
+
files it sees, its own mounts included"].join(`
|
|
717
|
+
`))}function Da(e=[]){let t={};for(let r=0;r<e.length;r+=1){let[n,o]=e[r].includes("=")?[e[r].slice(0,e[r].indexOf("=")),
|
|
718
|
+
e[r].slice(e[r].indexOf("=")+1)]:[e[r],void 0];if(!["--lines","--since"].includes(n)||n in t)throw kt();let i=o??e[r+1];
|
|
719
|
+
if(i===void 0)throw kt();o===void 0&&(r+=1),t[n]=i}if(t["--lines"]!==void 0&&!/^\d{1,4}$/u.test(t["--lines"]))throw kt();
|
|
720
|
+
return Oo({lines:t["--lines"]===void 0?Ta:Number(t["--lines"]),since:t["--since"]||""})}function Lo(e=[],{env:t=F.env}={}){
|
|
721
|
+
let r=w(t.SUDO_USER||"");if(!Ye.test(r)||String($(r).uid)!==String(t.SUDO_UID||""))throw new Error("Only a staging accou\
|
|
722
|
+
nt's staging login may use staging-service.");if(!St(r))throw new Error("AI sessions may not use this staging now: the w\
|
|
723
|
+
orkspace owner has turned that off.");let n=Do(r);if(!n)throw new Error("This project has no release installed on this h\
|
|
724
|
+
ost.");let[o="",...i]=e;if(o==="enter"){La(n,$(r),i[0]==="--"?i.slice(1):i,{env:t});return}if(o==="logs"){Rt(n.name,{...Da(
|
|
725
|
+
i),timestamps:!0});return}if(i.length>0||!["restart","status"].includes(o))throw kt();o==="restart"&&_("systemctl",["res\
|
|
726
|
+
tart",n.name]),Rt(n.name,{lines:20,timestamps:!0})}function Ua({command:e=[],env:t={},helperPath:r="",mountNamespace:n="",
|
|
727
|
+
pid:o=0,unit:i={},user:s={},userNamespace:a=null}={}){let c=a||s;return{args:[Io,`--target=${o}`,"--mount",...a?["--user"]:
|
|
722
728
|
[],`--setgid=${c.gid}`,`--setuid=${c.uid}`,"--",r,"staging-enter",n,i.environmentFile,i.startScript,i.workingDirectory,...e],
|
|
723
|
-
env:{HOME:s.home,LANG:t.LANG||"C.UTF-8",LOGNAME:s.username,PATH:i.path||t.PATH||"",SHELL:
|
|
724
|
-
username,VIBE64_STAGING_UNIT:i.name},file:
|
|
725
|
-
`)){let[n,o,i]=r.trim().split(/\s+/u).map(Number);if(t>=o&&t<o+i)return n+t-o}return null}function
|
|
726
|
-
o),read:n=o=>
|
|
727
|
-
/gid_map`),t.gid),uid
|
|
729
|
+
env:{HOME:s.home,LANG:t.LANG||"C.UTF-8",LOGNAME:s.username,PATH:i.path||t.PATH||"",...Uo(i),SHELL:nt[0],TERM:t.TERM||"du\
|
|
730
|
+
mb",USER:s.username,VIBE64_STAGING_UNIT:i.name},file:Io}}function $o(e="",t=-1){for(let r of String(e).split(`
|
|
731
|
+
`)){let[n,o,i]=r.trim().split(/\s+/u).map(Number);if(t>=o&&t<o+i)return n+t-o}return null}function Ga(e,t,{link:r=o=>Lr(
|
|
732
|
+
o),read:n=o=>jr(o,"utf8")}={}){if(r(`/proc/${e}/ns/user`)===r("/proc/self/ns/user"))return null;let o={gid:$o(n(`/proc/${e}\
|
|
733
|
+
/gid_map`),t.gid),uid:$o(n(`/proc/${e}/uid_map`),t.uid)};if(o.uid===null||o.gid===null)throw new Error("The running stag\
|
|
728
734
|
ing service runs in a user namespace of its own that does not include its account, so staging-enter cannot join it.");return o}
|
|
729
|
-
function
|
|
730
|
-
`).find(n=>n.startsWith("0::"));return r?r.slice(3):""}catch{return""}}function
|
|
731
|
-
execve(c,u,l),link:i=c=>
|
|
735
|
+
function ja(e,t){try{let r=t(`/proc/${e}/cgroup`).split(`
|
|
736
|
+
`).find(n=>n.startsWith("0::"));return r?r.slice(3):""}catch{return""}}function La(e={},t={},r=[],{env:n=F.env,execve:o=(c,u,l)=>F.
|
|
737
|
+
execve(c,u,l),link:i=c=>Lr(c),read:s=c=>jr(c,"utf8"),runRoot:a=_}={}){let c=Object.fromEntries(a("systemctl",["show",e.name,
|
|
732
738
|
"--property=MainPID","--property=ControlGroup"]).split(`
|
|
733
739
|
`).map(g=>[g.slice(0,g.indexOf("=")),g.slice(g.indexOf("=")+1)])),u=Number(c.MainPID);if(!Number.isSafeInteger(u)||u<=0)
|
|
734
740
|
throw new Error(`The running staging service ${e.name} is not running, so there is nothing to enter. staging-status show\
|
|
735
|
-
s why; staging-restart starts it again.`);let l=()=>{let g
|
|
741
|
+
s why; staging-restart starts it again.`);let l=()=>{let g=ja(u,s);return!!c.ControlGroup&&(g===c.ControlGroup||g.startsWith(
|
|
736
742
|
`${c.ControlGroup}/`))},m=new Error(`The running staging service ${e.name} changed while staging-enter started; try agai\
|
|
737
|
-
n.`);if(!l())throw m;let d=i(`/proc/${u}/ns/mnt`),f=
|
|
738
|
-
mountNamespace:d,pid:u,unit:e,user:t,userNamespace:f});o(p.file,p.args,p.env)}function
|
|
739
|
-
[...
|
|
740
|
-
env:i=
|
|
743
|
+
n.`);if(!l())throw m;let d=i(`/proc/${u}/ns/mnt`),f=Ga(u,t,{link:i,read:s});if(!l())throw m;let p=Ua({command:r,env:n,helperPath:re(),
|
|
744
|
+
mountNamespace:d,pid:u,unit:e,user:t,userNamespace:f});o(p.file,p.args,p.env)}function Ba(e=[],t=""){let r=e.length>0?e:
|
|
745
|
+
[...nt];return t?[t,...r]:e.length>0?[...nt,"-c",'exec "$@"',"staging-enter",...e]:r}function Bo([e="",t="",r="",n="",...o]=[],{
|
|
746
|
+
env:i=F.env,link:s=a=>Lr(a)}={}){if(!/^mnt:\[\d+\]$/u.test(e)||![t,r,n].every(u=>Dr.isAbsolute(u)))throw new Error("Only\
|
|
741
747
|
staging-enter, in a staging account's staging login, starts here.");if(s("/proc/self/ns/mnt")!==e)throw new Error("stag\
|
|
742
|
-
ing-enter did not reach the running staging service: its main process changed meanwhile. Try again.");
|
|
743
|
-
o,
|
|
748
|
+
ing-enter did not reach the running staging service: its main process changed meanwhile. Try again.");F.chdir(n);let[a,...c]=Ba(
|
|
749
|
+
o,Go(r)?r:"");F.execve(a,[a,...c],{...i,...Ee(t)})}var Va=new Set(["account-auth-terminal","staging-account","account-status","codex-app-server","create-system-user","stag\
|
|
744
750
|
ing-unit","enable-system-user","github-api-command","github-toolchain","github-workflow-command","health-status","manage\
|
|
745
|
-
d-execution","managed-service","opencode-app-server","staging-access","vibe64-command","workspace-cache-command"]);async function
|
|
746
|
-
if(S.argv[2]==="run-managed"){await
|
|
747
|
-
"");return}if(S.argv[2]==="staging-shell"&&S.argv.length===3){
|
|
748
|
-
3));return}if(S.argv[2]==="staging-enter"){
|
|
749
|
-
length!==4)throw new Error("Usage: vibe64-exec-helper upgrade-person-registry <workspace>");
|
|
751
|
+
d-execution","managed-service","opencode-app-server","staging-access","vibe64-command","workspace-cache-command"]);async function Fa(){
|
|
752
|
+
if(S.argv[2]==="run-managed"){await Eo(S.argv[3]||"");return}if(S.argv[2]==="run-staging-unit"){xo(S.argv[3]||"",S.argv[4]||
|
|
753
|
+
"");return}if(S.argv[2]==="staging-shell"&&S.argv.length===3){jo();return}if(S.argv[2]==="staging-service"){Lo(S.argv.slice(
|
|
754
|
+
3));return}if(S.argv[2]==="staging-enter"){Bo(S.argv.slice(3));return}if(S.argv[2]==="upgrade-person-registry"){if(S.argv.
|
|
755
|
+
length!==4)throw new Error("Usage: vibe64-exec-helper upgrade-person-registry <workspace>");pn(S.argv[3]);return}if(S.argv[2]===
|
|
750
756
|
"register-person"){if(S.argv.length!==5)throw new Error("Usage: vibe64-exec-helper register-person <workspace> <username\
|
|
751
|
-
>");
|
|
752
|
-
ec-helper relink-units");
|
|
753
|
-
exec-helper check-person <username>");le(S.argv[3]),
|
|
754
|
-
length>4)throw new Error("Usage: vibe64-exec-helper execute [payload-json-file]");let e=S.argv[3]||"",t=e?
|
|
755
|
-
|
|
757
|
+
>");qt(S.argv[3],S.argv[4]);return}if(S.argv[2]==="relink-units"){if(S.argv.length!==3)throw new Error("Usage: vibe64-ex\
|
|
758
|
+
ec-helper relink-units");To();return}if(S.argv[2]==="check-person"){if(S.argv.length!==4)throw new Error("Usage: vibe64-\
|
|
759
|
+
exec-helper check-person <username>");le(S.argv[3]),gt($(S.argv[3]),Ve(S.argv[3]));return}if(S.argv[2]!=="execute"||S.argv.
|
|
760
|
+
length>4)throw new Error("Usage: vibe64-exec-helper execute [payload-json-file]");let e=S.argv[3]||"",t=e?Ln(e,j()):Vn();
|
|
761
|
+
Bn(t);let r=String(t.operation||"").trim();if(!Va.has(r))throw new Error("Vibe64 exec helper rejected an unknown operati\
|
|
756
762
|
on.");if(e&&r!=="managed-execution")throw new Error("Vibe64 exec helper accepts a payload file only for a managed execut\
|
|
757
|
-
ion.");if(r==="staging-unit"){
|
|
758
|
-
if(r==="staging-account"){
|
|
759
|
-
ser"||r==="enable-system-user"){
|
|
760
|
-
"Vibe64 exec helper rejected an unknown command.");let i=$(n);me("uid",t.uid,i.uid),me("gid",t.gid,i.gid);let s=j();
|
|
761
|
-
i);let a=
|
|
762
|
-
map(d=>String(d)):[],l=t.inputBase64?Buffer.from(String(t.inputBase64),"base64"):void 0;S.umask(7);let m=
|
|
763
|
+
ion.");if(r==="staging-unit"){Ao(t);return}if(r==="managed-service"){No(t);return}if(r==="managed-execution"){ho(t);return}
|
|
764
|
+
if(r==="staging-account"){$n(t);return}if(r==="staging-access"){Po(t);return}let n=w(t.username);if(r==="create-system-u\
|
|
765
|
+
ser"||r==="enable-system-user"){cn(r,t,n);return}le(n);let o=String(t.command||"").trim();if(!ct.has(o))throw new Error(
|
|
766
|
+
"Vibe64 exec helper rejected an unknown command.");let i=$(n);me("uid",t.uid,i.uid),me("gid",t.gid,i.gid);let s=j();ht(s,
|
|
767
|
+
i);let a=lt(t.cwd||"",s.username,{operation:r,targetUser:i}),c=je(t.env||{},i,s.username,r),u=Array.isArray(t.args)?t.args.
|
|
768
|
+
map(d=>String(d)):[],l=t.inputBase64?Buffer.from(String(t.inputBase64),"base64"):void 0;S.umask(7);let m=Zr(i,o,u,{cwd:a,
|
|
763
769
|
env:c,...l===void 0?{stdio:"inherit"}:{input:l,stdio:["pipe","inherit","inherit"]}});if(m.error)throw m.error;S.exit(typeof m.
|
|
764
|
-
status=="number"?m.status:1)}import.meta.main&&
|
|
765
|
-
`),S.exit(e?.exitCode===
|
|
770
|
+
status=="number"?m.status:1)}import.meta.main&&Fa().catch(e=>{S.stderr.write(`${String(e?.message||e)}
|
|
771
|
+
`),S.exit(e?.exitCode===pt?pt:2)});
|