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