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