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