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