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