vibe64 0.1.59 → 0.1.61
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 +1228 -1210
- package/bin/server.js +392 -376
- package/bin/upgrade-state.js +4457 -4430
- package/dist/assets/{GithubBrowserTabs-D_nMB5Y1.js → GithubBrowserTabs-DAgQxPXI.js} +1 -1
- package/dist/assets/{LocalDatabaseServer-BgO_aeUg.js → LocalDatabaseServer-m1G8ZS5i.js} +1 -1
- package/dist/assets/SelectField-DwWoHC2p.js +1 -0
- package/dist/assets/{ShellOutlet-Cr8SJs7s.js → ShellOutlet-CdjsJfg9.js} +1 -1
- package/dist/assets/Vibe64AuthSettingsButton-D3sB4BfM.js +5 -0
- package/dist/assets/{Vibe64AuthSettingsButton-DRTKdimW.css → Vibe64AuthSettingsButton-DFfFPrd7.css} +1 -1
- package/dist/assets/{Vibe64ConversationLog-DtOgxPNR.js → Vibe64ConversationLog-B-L5QsVr.js} +4 -4
- package/dist/assets/{Vibe64ConversationLog-NH61odld.css → Vibe64ConversationLog-ksf1U6PP.css} +1 -1
- package/dist/assets/{Vibe64DashboardShell-DhPE6H3P.js → Vibe64DashboardShell-CMzX3wRM.js} +1 -1
- package/dist/assets/{Vibe64DashboardShell-Bpnbjs4l.css → Vibe64DashboardShell-D0GNI4V8.css} +1 -1
- package/dist/assets/{Vibe64DatabaseWorkspace-cfn8TTxQ.css → Vibe64DatabaseWorkspace-De4sbXAN.css} +1 -1
- package/dist/assets/{Vibe64DatabaseWorkspace-CHV0cd3l.js → Vibe64DatabaseWorkspace-Dewhs6_T.js} +2 -2
- package/dist/assets/Vibe64DestinationButton-CdyyK9tj.js +1 -0
- package/dist/assets/Vibe64DestinationButton-ZxY1Lwie.css +1 -0
- package/dist/assets/Vibe64FileArea-DluZTu-c.js +1 -0
- package/dist/assets/{Vibe64FileArea-mydNQQl8.css → Vibe64FileArea-ZEzsvLt2.css} +1 -1
- package/dist/assets/Vibe64OutputControls-BfbdD25Y.js +8 -0
- package/dist/assets/{Vibe64RepositoryWorkspace-DUSMn4pR.js → Vibe64RepositoryWorkspace-CBsySPXN.js} +1 -1
- package/dist/assets/{Vibe64SessionFiles-BXt__PJL.js → Vibe64SessionFiles--wtVe_KC.js} +1 -1
- package/dist/assets/{Vibe64SessionSourceEditor-NyG6niQM.js → Vibe64SessionSourceEditor-BouH4fXC.js} +1 -1
- package/dist/assets/Vibe64UiStoryboardView--E04EEF8.js +8 -0
- package/dist/assets/{Vibe64UiStoryboardView-CtlJWiCY.css → Vibe64UiStoryboardView-DqLN6ofL.css} +1 -1
- package/dist/assets/{Vibe64UnavailableSessions-CCPWJo8e.js → Vibe64UnavailableSessions-94bFpxMK.js} +1 -1
- package/dist/assets/_pageId_-Ch4OpUkd.js +1 -0
- package/dist/assets/_sessionId_-7PyIUeUr.css +1 -0
- package/dist/assets/_sessionId_-DGT4d2La.js +1 -0
- package/dist/assets/{_sessionTool_-CKPNp5fF.js → _sessionTool_-CBf51mfK.js} +1 -1
- package/dist/assets/_sessionTool_-DiYoi-BF.css +1 -0
- package/dist/assets/_slug_-C8VNMRVH.js +14 -0
- package/dist/assets/_slug_-CZmGS16g.css +1 -0
- package/dist/assets/access-BAOx4iCS.js +1 -0
- package/dist/assets/access-BH1OsqPS.css +1 -0
- package/dist/assets/{app-D9FegZf0.js → app-Bs6-Hv23.js} +1 -1
- package/dist/assets/{assistantRouting-D4SnnxJn.js → assistantRouting-BS0ZW5Ki.js} +1 -1
- package/dist/assets/{changes-DtfJc780.js → changes-C6eMQ9YE.js} +1 -1
- package/dist/assets/{client-CUQfIUus.css → client-BBJzQIWS.css} +1 -1
- package/dist/assets/{client-BBqNv4HL.js → client-CIF5Y1Aj.js} +1 -1
- package/dist/assets/{client-B8u2_Svv.css → client-CM6TGZc9.css} +1 -1
- package/dist/assets/{client-DnjkdG6K.js → client-CVgL_ShV.js} +1 -1
- package/dist/assets/{client-DuDOzb5A.js → client-HWj_BNVZ.js} +2 -2
- package/dist/assets/{client-Dra4Vp3A.js → client-qAKnahkF.js} +2 -2
- package/dist/assets/{client-mU-LObHG.js → client-qpL_kR4u.js} +2 -2
- package/dist/assets/{conversation-QpMeXw70.js → conversation-DbF0OrZB.js} +3 -3
- package/dist/assets/{conversation-La-pkh5h.css → conversation-ZN3-8jbz.css} +1 -1
- package/dist/assets/{dashboard-B26QwE6y.js → dashboard-CzLsa0w0.js} +1 -1
- package/dist/assets/{english-definitions-I9tIXY2u.js → english-definitions-BA8v5wP1.js} +1 -1
- package/dist/assets/{env-BXsvM592.js → env-BqJ_GWbz.js} +1 -1
- package/dist/assets/{error-kdRkyK9x.js → error-BQ7r64JO.js} +1 -1
- package/dist/assets/{error-CX8_snYL.js → error-BqMxhgpB.js} +1 -1
- package/dist/assets/errorMessageHelpers-BjIt31kK.js +1 -0
- package/dist/assets/{errors-DErd0NON.js → errors-D17nJYne.js} +1 -1
- package/dist/assets/{health-C4WtefLm.js → health-CIqrHpVK.js} +1 -1
- package/dist/assets/history-BCjhpyP8.js +1 -0
- package/dist/assets/history-BSIuLgnI.css +1 -0
- package/dist/assets/{httpClient-BRO3GqjU.js → httpClient-Bwitq9Xf.js} +1 -1
- package/dist/assets/i18n-BkxO7BMl.js +1 -0
- package/dist/assets/{i18n-B5lc019_.js → i18n-Dm74yE_M.js} +1 -1
- package/dist/assets/index-Ctygjyf8.css +1 -0
- package/dist/assets/index-fXKdz8oR.js +134 -0
- package/dist/assets/{integrations-CrI893NK.css → integrations-CwgrZgmM.css} +1 -1
- package/dist/assets/{integrations-CQNJxkMu.js → integrations-cgbpgNNd.js} +12 -5
- package/dist/assets/issues-AhouA6nE.js +1 -0
- package/dist/assets/issues-D46llNv-.css +1 -0
- package/dist/assets/{learning-0cINHUSN.js → learning-DZXWgVEW.js} +1 -1
- package/dist/assets/{pages-DbF-yXqO.js → pages-5jaEclQo.js} +1 -1
- package/dist/assets/{pages-CIKw99GN.js → pages-BUUwIXBf.js} +1 -1
- package/dist/assets/{pathname-DOqQPPVa.js → pathname-JHQIKk21.js} +1 -1
- package/dist/assets/{placement-BAaZQhAh.js → placement-1lT0lW3-.js} +1 -1
- package/dist/assets/{placement-Lk1Lpy6s.js → placement-B2V88UDJ.js} +1 -1
- package/dist/assets/{project-files-CklWobqZ.js → project-files-BS2gdDSz.js} +1 -1
- package/dist/assets/publish-Bq_LPmX2.js +3 -0
- package/dist/assets/{publish-DOybV3Qz.css → publish-C9O0tDPB.css} +1 -1
- package/dist/assets/pull-requests-BvChbjCD.js +1 -0
- package/dist/assets/pull-requests-DtqrTix0.css +1 -0
- package/dist/assets/{repository-wJZei_NJ.js → repository-Dkow-18G.js} +1 -1
- package/dist/assets/settings-BKZcbISO.css +1 -0
- package/dist/assets/settings-r5RWQVzw.js +1 -0
- package/dist/assets/{shared-X5MxTHwl.js → shared-B6plZPQ_.js} +1 -1
- package/dist/assets/{studioGateApi-CHIdcQvD.js → studioGateApi-UqmdV50W.js} +1 -1
- package/dist/assets/{studioUrls-oIU1Eq_t.js → studioUrls-k_pQIuPs.js} +1 -1
- package/dist/assets/useArchivedVibe64Sessions-C0MVJuyX.js +1 -0
- package/dist/assets/useAssistantAttachments-BkYZckgz.js +2 -0
- package/dist/assets/useCommand-CNDe8gM-.js +1 -0
- package/dist/assets/{useEndpointResource-61E93qP-.js → useEndpointResource-CmMwteuX.js} +1 -1
- package/dist/assets/{usePaths-B-QGqa_I.js → usePaths-CvUbx5-V.js} +1 -1
- package/dist/assets/{useUiFeedback-CycH_fvY.js → useUiFeedback-CWb6o71Z.js} +1 -1
- package/dist/assets/useVibe64ConversationLog-CUWEZhnf.js +2 -0
- package/dist/assets/{useVibe64Learning-DZCyrfpy.js → useVibe64Learning-RE4HXHqo.js} +1 -1
- package/dist/assets/{useVibe64SessionData-rBvWMqyc.js → useVibe64SessionData-kGr7R7lG.js} +1 -1
- package/dist/assets/{useVibe64SessionSelection-C546mBu8.js → useVibe64SessionSelection-BZ7WnRv0.js} +1 -1
- package/dist/assets/validators-HqYRjxEO.js +1 -0
- package/dist/assets/{vibe64FileUpload-D0Lv2mMJ.js → vibe64FileUpload-BDkcaUyk.js} +1 -1
- package/dist/assets/vibe64GithubProject-CJneIo5O.js +1 -0
- package/dist/assets/vibe64RepositoryRealtime-R5QhcJ4H.js +1 -0
- package/dist/assets/vibe64SessionFocus-BCojr4E-.css +1 -0
- package/dist/assets/vibe64SessionFocus-CHKCMxcJ.js +1 -0
- package/dist/index.html +29 -27
- package/docs/colleague-usage/ai-tasks.md +15 -4
- package/docs/colleague-usage/back-navigation.md +16 -13
- package/docs/colleague-usage/coding-agent-goal-pause.md +15 -1
- package/docs/colleague-usage/coding-agent-goals.md +23 -3
- package/docs/colleague-usage/coding-agent-recovery.md +3 -1
- package/docs/colleague-usage/coding-agents.md +19 -1
- package/docs/colleague-usage/colleague-watches.md +1 -1
- package/docs/colleague-usage/connected-projects.md +1 -1
- package/docs/colleague-usage/connected-repositories.md +16 -4
- package/docs/colleague-usage/dashboard-navigation.md +14 -11
- package/docs/colleague-usage/database.md +1 -1
- package/docs/colleague-usage/development-env.md +21 -12
- package/docs/colleague-usage/files.md +2 -1
- package/docs/colleague-usage/github-work.md +51 -12
- package/docs/colleague-usage/health-checks.md +1 -1
- package/docs/colleague-usage/integrations.md +2 -2
- package/docs/colleague-usage/learning-teacher-guide.md +3 -2
- package/docs/colleague-usage/pages.md +1 -2
- package/docs/colleague-usage/preview-browser-checks.md +3 -0
- package/docs/colleague-usage/preview.md +29 -0
- package/docs/colleague-usage/project-messages.md +4 -3
- package/docs/colleague-usage/project-settings.md +3 -0
- package/docs/colleague-usage/session-archive.md +11 -0
- package/docs/colleague-usage/sessions.md +8 -7
- package/docs/colleague-usage/temporary-chats.md +4 -3
- package/docs/colleague-usage/ui-pass.md +1 -1
- package/docs/colleague-usage/usage-map.md +3 -2
- package/docs/colleague-usage/workspace-preparation.md +12 -0
- package/node_modules/@jskit-ai/agent/CHANGELOG.md +5 -0
- package/node_modules/@jskit-ai/agent/package.json +1 -1
- package/node_modules/@jskit-ai/assistant-core/CHANGELOG.md +8 -0
- package/node_modules/@jskit-ai/assistant-core/locales/en.json +4 -1
- package/node_modules/@jskit-ai/assistant-core/package.json +1 -1
- package/node_modules/@jskit-ai/assistant-runtime/CHANGELOG.md +4 -0
- package/node_modules/@jskit-ai/assistant-runtime/package.json +1 -1
- package/node_modules/@jskit-ai/assistant-voice/package.json +1 -1
- package/node_modules/@jskit-ai/connector-google-calendar/CHANGELOG.md +4 -0
- package/node_modules/@jskit-ai/connector-google-calendar/package.json +1 -1
- package/node_modules/@jskit-ai/connectors-catalog/CHANGELOG.md +1 -0
- package/node_modules/@jskit-ai/connectors-catalog/package.json +1 -1
- package/node_modules/@jskit-ai/connectors-core/CHANGELOG.md +2 -0
- package/node_modules/@jskit-ai/connectors-core/README.md +4 -0
- package/node_modules/@jskit-ai/connectors-core/package.json +1 -1
- package/node_modules/@jskit-ai/http-runtime/CHANGELOG.md +1 -0
- package/node_modules/@jskit-ai/http-runtime/package.json +1 -1
- package/node_modules/@jskit-ai/kernel/CHANGELOG.md +8 -0
- package/node_modules/@jskit-ai/kernel/package.json +3 -1
- package/node_modules/@jskit-ai/payments-core/CHANGELOG.md +1 -0
- package/node_modules/@jskit-ai/payments-core/locales/en.json +2 -1
- package/node_modules/@jskit-ai/payments-core/package.json +1 -1
- package/node_modules/@jskit-ai/realtime/CHANGELOG.md +1 -0
- package/node_modules/@jskit-ai/realtime/package.json +1 -1
- package/node_modules/@jskit-ai/resource-core/CHANGELOG.md +1 -0
- package/node_modules/@jskit-ai/resource-core/package.json +1 -1
- package/node_modules/@jskit-ai/uploads-runtime/package.json +1 -1
- package/node_modules/@local/vibe64-ai-tasks/package.json +2 -1
- package/node_modules/@local/vibe64-execution/src/host/execHelper.js +463 -442
- package/node_modules/@local/vibe64-genesis/bin/genesis +17 -11
- package/node_modules/@local/vibe64-genesis/bin/vibe64-genesis-host-context +827 -813
- package/node_modules/@local/vibe64-genesis/src/server/agentSpecs.js +93 -67
- package/node_modules/@local/vibe64-genesis/src/server/index.js +608 -584
- package/node_modules/@local/vibe64-genesis/src/server/promptContext.js +180 -175
- package/node_modules/@local/vibe64-runtime/src/server/codexAppServerProcess.js +490 -479
- package/node_modules/@local/vibe64-source-editor/src/server/searchIndexWorker.js +12 -11
- package/node_modules/@local/vibe64-system-graph/README.md +9 -5
- package/node_modules/@local/vibe64-terminals/src/server/opencodeSessionEnvironmentPlugin.js +262 -252
- package/node_modules/@local/vibe64-terminals/src/server/sessionWorkOperationCommand.js +1026 -981
- package/node_modules/json-rest-schema/README.md +3 -1
- package/node_modules/json-rest-schema/package.json +1 -1
- package/package.json +17 -17
- package/server.bundle.mjs +43244 -42953
- package/dist/assets/Vibe64AuthSettingsButton-Bx9patil.js +0 -5
- package/dist/assets/Vibe64FileArea-DIDyAUvD.js +0 -1
- package/dist/assets/Vibe64OutputControls-mNWUWLSm.js +0 -8
- package/dist/assets/Vibe64UiStoryboardView-BXH2MSWn.js +0 -8
- package/dist/assets/_pageId_-D54CqzqG.js +0 -1
- package/dist/assets/_sessionId_-B5V2Fs2n.css +0 -1
- package/dist/assets/_sessionId_-CW044RVi.js +0 -1
- package/dist/assets/_sessionTool_-Be88HWbv.css +0 -1
- package/dist/assets/_slug_-CRtFhc0A.js +0 -14
- package/dist/assets/_slug_-WWvJTLoc.css +0 -1
- package/dist/assets/access-ChMLRErk.js +0 -1
- package/dist/assets/access-Cm2lrMF6.css +0 -1
- package/dist/assets/errorMessageHelpers-L2GsOwCP.js +0 -1
- package/dist/assets/history-BhqQz5jH.css +0 -1
- package/dist/assets/history-HHPFoNi3.js +0 -1
- package/dist/assets/index-BBfSvf2i.css +0 -1
- package/dist/assets/index-Bvd00puv.js +0 -134
- package/dist/assets/issues-BHr_nI-9.js +0 -1
- package/dist/assets/issues-CpBRQTQ_.css +0 -1
- package/dist/assets/publish-Cot797YN.js +0 -3
- package/dist/assets/pull-requests-DnEm9m_1.css +0 -1
- package/dist/assets/pull-requests-ybnixBv0.js +0 -1
- package/dist/assets/settings-DJByC5Wb.js +0 -1
- package/dist/assets/settings-bEkDjn0Y.css +0 -1
- package/dist/assets/useArchivedVibe64Sessions-B-DtXrk-.js +0 -1
- package/dist/assets/useAssistantAttachments-CkseokGM.js +0 -2
- package/dist/assets/useCommand-D96utlVe.js +0 -1
- package/dist/assets/useVibe64ConversationLog-BVANhCHq.js +0 -2
- package/dist/assets/validators-B3YzM6px.js +0 -1
- package/dist/assets/vibe64GithubProject-DNl0aDcC.js +0 -1
- package/dist/assets/vibe64RepositoryRealtime-BPsE5l5E.js +0 -1
- package/dist/assets/vibe64SessionFocus-CxX2nK6F.js +0 -1
- package/dist/assets/vibe64SessionFocus-DW73PN_o.css +0 -1
package/bin/run.js
CHANGED
|
@@ -1,304 +1,310 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire as __vibe64CreateRequire } from 'node:module';const require=__vibe64CreateRequire(import.meta.url);
|
|
3
|
-
var
|
|
4
|
-
ditor/src/server/agentSpecs.js",import.meta.url).href,
|
|
5
|
-
[{name:"integration-setup-command",title:"Integration setup command protocol and integrations.json",text:
|
|
3
|
+
var qu=Object.defineProperty;var g=(e,t,r)=>()=>{if(r)throw r[0];try{return e&&(t=e(e=0)),t}catch(n){throw r=[n],n}};var xi=(e,t)=>{for(var r in t)qu(e,r,{get:t[r],enumerable:!0})};import{readFile as Xu}from"node:fs/promises";var Ku,Li,Mi,Di=g(()=>{Ku=new URL("./../node_modules/@local/vibe64-source-e\
|
|
4
|
+
ditor/src/server/agentSpecs.js",import.meta.url).href,Li=e=>()=>Xu(new URL(`../../docs/${e}`,Ku),"utf8"),Mi=Object.freeze(
|
|
5
|
+
[{name:"integration-setup-command",title:"Integration setup command protocol and integrations.json",text:Li("application\
|
|
6
6
|
-integration-setup.md")},{name:"integration-payments-laravel",title:"Implementing the integration setup payment operatio\
|
|
7
|
-
ns in Laravel",text:
|
|
8
|
-
return!!(e&&typeof e=="object"&&!Array.isArray(e))}var
|
|
9
|
-
dBack","unknown"])});function dr(e){return B(e)?{...e}:{}}var
|
|
7
|
+
ns in Laravel",text:Li("application-payments-laravel.md")}])});var Ot,lr,Qu,ur,Ui=g(()=>{Ot="email",lr="login",Qu="user-id",ur=Object.freeze([Ot,lr,Qu])});function V(e,{fallback:t=""}={}){return String(e||"").trim()||t}function re(e,{fallback:t={}}={}){return B(e)?e:{...t}}function B(e){
|
|
8
|
+
return!!(e&&typeof e=="object"&&!Array.isArray(e))}var Vw,G=g(()=>{Vw=Object.freeze(["none","pending","committed","rolle\
|
|
9
|
+
dBack","unknown"])});function dr(e){return B(e)?{...e}:{}}var An=g(()=>{G()});var ae,pr=g(()=>{An();ae=class extends Error{constructor(t,r,n={}){super(r,n.cause===void 0?void 0:{cause:n.cause}),this.
|
|
10
10
|
name="AppError",this.status=Number(t)||500,this.statusCode=this.status,this.code=n.code||"APP_ERROR",this.params=dr(n.params),
|
|
11
11
|
n.messageCode&&(this.messageCode=String(n.messageCode),this.messageParams=dr(n.messageParams)),this.details=n.details,this.
|
|
12
|
-
headers=n.headers||{}}}});var
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
headers=n.headers||{}}}});var Vi=g(()=>{G()});var Gi=g(()=>{G()});function Y(e){if(e===null||typeof e!="object")return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null||
|
|
13
|
+
ed(t)}function ed(e){return e!==null&&typeof e=="object"&&Object.getPrototypeOf(e)===null&&Reflect.ownKeys(e).length===0}
|
|
14
|
+
var tt=g(()=>{});function On(e){return e!==null&&typeof e=="object"&&Y(e.structure)&&Y(e.operations)&&typeof e.validateWith=="function"&&
|
|
15
15
|
typeof e.toJsonSchema=="function"&&typeof e.cleanup=="function"}function mr(e,t){if(!Object.hasOwn(t,"items"))return null;
|
|
16
|
-
let{items:r}=t;if(
|
|
17
|
-
" must define items as either a Schema instance or a field definition object.`);return{kind:"definition",definition:r}}function
|
|
18
|
-
if(!Object.hasOwn(t,"values"))return null;let{values:r}=t;if(
|
|
16
|
+
let{items:r}=t;if(On(r))return{kind:"schema",schema:r};if(!Y(r)||typeof r.type!="string")throw new Error(`Array field "${e}\
|
|
17
|
+
" must define items as either a Schema instance or a field definition object.`);return{kind:"definition",definition:r}}function Pt(e,t){
|
|
18
|
+
if(!Object.hasOwn(t,"values"))return null;let{values:r}=t;if(On(r))return{kind:"schema",schema:r};if(!Y(r)||typeof r.type!=
|
|
19
19
|
"string")throw new Error(`Object field "${e}" must define values as either a Schema instance or a field definition objec\
|
|
20
20
|
t.`);return{kind:"definition",definition:r}}function fr(e,t){let r=Object.hasOwn(t,"schema"),n=Object.hasOwn(t,"values"),
|
|
21
21
|
o=Object.hasOwn(t,"additionalProperties");if(r&&n)throw new Error(`Object field "${e}" cannot define both schema and val\
|
|
22
22
|
ues.`);if(o&&t.additionalProperties!==!0)throw new Error(`Object field "${e}" only supports additionalProperties: true.`);
|
|
23
23
|
if(n&&t.additionalProperties===!0)throw new Error(`Object field "${e}" cannot define both values and additionalPropertie\
|
|
24
|
-
s: true.`);if(r){if(!
|
|
25
|
-
kind:"nested",schema:t.schema,allowAdditionalProperties:t.additionalProperties===!0}}return n?{kind:"map",valuesConfig:
|
|
26
|
-
e,t)}:t.additionalProperties===!0?{kind:"opaque"}:{kind:"plain"}}var
|
|
27
|
-
()
|
|
28
|
-
let n
|
|
24
|
+
s: true.`);if(r){if(!On(t.schema))throw new Error(`Object field "${e}" must define schema as a Schema instance.`);return{
|
|
25
|
+
kind:"nested",schema:t.schema,allowAdditionalProperties:t.additionalProperties===!0}}return n?{kind:"map",valuesConfig:Pt(
|
|
26
|
+
e,t)}:t.additionalProperties===!0?{kind:"opaque"}:{kind:"plain"}}var Pn=g(()=>{tt()});function rt(e){return e?.type==="number"||e?.type==="integer"||e?.type==="epochMilliseconds"||e?.type==="epochSeconds"}function Rn(e,t=""){
|
|
27
|
+
if(Y(e))for(let[r,n]of Object.entries(e)){if(!Y(n))continue;let o=t?`${t}.${r}`:r;for(let i of["minItems","maxItems"]){if(!Object.
|
|
28
|
+
hasOwn(n,i))continue;let s=n[i];if(n.type!=="array"||!Number.isInteger(s)||s<0)throw new Error(`Field "${o}" ${i} must b\
|
|
29
|
+
e a non-negative integer on an array field.`)}if(n.minItems>n.maxItems)throw new Error(`Field "${o}" minItems (${n.minItems}\
|
|
30
|
+
) is above its maxItems (${n.maxItems}).`);n.type==="array"&&Y(n.items)&&typeof n.items.type=="string"&&Rn({"[]":n.items},
|
|
31
|
+
o)}}var hr=g(()=>{tt()});function sd(e){return e%4===0&&(e%100!==0||e%400===0)}function ad(e,t){return t===2?sd(e)?29:28:id[t-1]}function Ki(e,t,r){
|
|
32
|
+
let n=Number(e),o=Number(t),i=Number(r);return o>=1&&o<=12&&i>=1&&i<=ad(n,o)}function Rt(e,t){let r=e.temporalPrecision;
|
|
29
33
|
if(r!==void 0){if(!Number.isInteger(r)||r<0)throw new Error(`temporalPrecision for "${t}" must be a non-negative integer\
|
|
30
|
-
.`);return r}}function
|
|
31
|
-
let t=
|
|
32
|
-
null&&
|
|
33
|
-
|
|
34
|
-
return`^${
|
|
35
|
-
let r;if(typeof e=="number")r=e;else if(typeof e=="string"&&
|
|
36
|
-
r)||r<-t||r>t?null:r===0?0:r}var
|
|
37
|
-
\\d{4}",
|
|
38
|
-
](?:${
|
|
39
|
-
new RegExp(`^${
|
|
40
|
-
|
|
41
|
-
has(e))throw new Error(`${t}() received unsafe path segment "${e}".`)}function
|
|
42
|
-
/\[(.+?)\]/g,".$1").replace(/^\.+/,"").replace(/\.+/g,".").replace(/\.$/,"")}function
|
|
43
|
-
let o=r?
|
|
34
|
+
.`);return r}}function Xi(e,t){return e===void 0?!0:t===void 0||e.length<=t}function Qi(e){if(typeof e!="string")return!1;
|
|
35
|
+
let t=td.exec(e);return t!==null&&Ki(t[1],t[2],t[3])}function Zi(e,t){if(typeof e!="string")return!1;let r=rd.exec(e);return r!==
|
|
36
|
+
null&&Xi(r[1],t)}function es(e,t){if(typeof e!="string")return!1;let r=nd.exec(e);return r===null?!1:Ki(r[1],r[2],r[3])&&
|
|
37
|
+
Xi(r[4],t)}function ts(e){return e===void 0?"(?:\\.\\d+)?":e===0?"":`(?:\\.\\d{1,${e}})?`}function rs(e,t){let r=Rt(e,t);
|
|
38
|
+
return`^${gr}(?::${nt}${ts(r)})?$`}function ns(e,t){let r=Rt(e,t);return`^${Yi}T${gr}:${nt}${ts(r)}${qi}$`}function Cn(e,t){
|
|
39
|
+
let r;if(typeof e=="number")r=e;else if(typeof e=="string"&&od.test(e))r=Number(e);else return null;return!Number.isSafeInteger(
|
|
40
|
+
r)||r<-t||r>t?null:r===0?0:r}var Nn,Bi,Hi,zi,Fi,nt,gr,qi,Wi,Yi,Ji,td,rd,nd,od,id,kn=g(()=>{Nn="^(?:0|-?[1-9]\\d*)$",Bi="\
|
|
41
|
+
\\d{4}",Hi="0[1-9]|1[0-2]",zi="0[1-9]|[12]\\d|3[01]",Fi="[01]\\d|2[0-3]",nt="[0-5]\\d",gr=`(?:${Fi}):${nt}`,qi=`(?:Z|[+-\
|
|
42
|
+
](?:${Fi}):${nt})`,Wi=`(${Bi})-(${Hi})-(${zi})`,Yi=`${Bi}-(?:${Hi})-(?:${zi})`,Ji=`^${Yi}$`,td=new RegExp(`^${Wi}$`),rd=
|
|
43
|
+
new RegExp(`^${gr}(?::${nt}(?:\\.(\\d+))?)?$`),nd=new RegExp(`^${Wi}T${gr}:${nt}(?:\\.(\\d+))?${qi}$`),od=new RegExp(Nn),
|
|
44
|
+
id=[31,28,31,30,31,30,31,31,30,31,30,31]});function P(e,t,r){Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0})}function ld(e,t){if(cd.
|
|
45
|
+
has(e))throw new Error(`${t}() received unsafe path segment "${e}".`)}function ud(e){return typeof e!="string"?e:e.replace(
|
|
46
|
+
/\[(.+?)\]/g,".$1").replace(/^\.+/,"").replace(/\.+/g,".").replace(/\.$/,"")}function xn(e,t,{normalize:r=!1,allowEmpty:n=!1}={}){
|
|
47
|
+
let o=r?ud(e):e;if(typeof o!="string"||o.trim()===""){if(n&&o==="")return[];throw new Error(`${t}() expects a non-empty \
|
|
44
48
|
dotted path string.`)}let i=o.split(".");if(i.some(s=>s===""))throw new Error(`${t}() received an invalid path "${o}".`);
|
|
45
|
-
for(let s of i)
|
|
46
|
-
[
|
|
47
|
-
ject"&&!Array.isArray(n)&&!Array.isArray(o)){
|
|
49
|
+
for(let s of i)ld(s,t);return i}var cd,Nt=g(()=>{cd=new Set(["__proto__","prototype","constructor"])});function os(e){return{anyOf:[{type:"integer",minimum:-e,maximum:e},{type:"string",pattern:Nn}]}}function Me(e,t){return{
|
|
50
|
+
[Te]:{[e]:t}}}function Un(e,t){for(let r of Object.keys(t)){let n=t[r],o=e[r];if(n&&o&&typeof n=="object"&&typeof o=="ob\
|
|
51
|
+
ject"&&!Array.isArray(n)&&!Array.isArray(o)){Un(o,n);continue}e[r]=n}}function gd(e,t){if(!t||typeof t!="object"||Array.
|
|
48
52
|
isArray(t))throw new Error("JSON Schema export hooks must return an object or null.");for(let r of Object.keys(t)){if(r===
|
|
49
|
-
|
|
50
|
-
e[r]=t[r]}}function
|
|
51
|
-
1?e:{anyOf:n}}function
|
|
52
|
-
let r=e.types[t.type];if(typeof r.toJsonSchema=="function")return r.toJsonSchema;let n=
|
|
53
|
-
`Type '${t.type}' cannot be exported to JSON Schema without a toJsonSchema hook.`);return n}function
|
|
54
|
-
hasOwn(e.validators,t))return null;let n=e.validators[t];if(typeof n.toJsonSchema=="function")return n.toJsonSchema;let o=
|
|
53
|
+
Te&&e[r]&&typeof e[r]=="object"&&typeof t[r]=="object"&&!Array.isArray(e[r])&&!Array.isArray(t[r])){Un(e[r],t[r]);continue}
|
|
54
|
+
e[r]=t[r]}}function wd(e,t){let n=[...Array.isArray(e.anyOf)&&Object.keys(e).length===1?e.anyOf:[e],...t];return n.length===
|
|
55
|
+
1?e:{anyOf:n}}function yd(e,t){if(!Object.hasOwn(e.types,t.type))throw new Error(`No casting function for type: ${t.type}`);
|
|
56
|
+
let r=e.types[t.type];if(typeof r.toJsonSchema=="function")return r.toJsonSchema;let n=fd[t.type];if(!n)throw new Error(
|
|
57
|
+
`Type '${t.type}' cannot be exported to JSON Schema without a toJsonSchema hook.`);return n}function _d(e,t,r){if(!Object.
|
|
58
|
+
hasOwn(e.validators,t))return null;let n=e.validators[t];if(typeof n.toJsonSchema=="function")return n.toJsonSchema;let o=hd[t];
|
|
55
59
|
if(o)return o;throw new Error(`Validator '${t}' on field '${r}' cannot be exported to JSON Schema without a toJsonSchema\
|
|
56
|
-
hook.`)}function
|
|
57
|
-
`Unsupported JSON Schema export mode '${e}'. Expected 'create', 'replace', or 'patch'.`)}function
|
|
58
|
-
void 0&&t.operation!==void 0){let r=
|
|
60
|
+
hook.`)}function is(e){if(e===void 0)return"create";if(["create","replace","patch"].includes(e))return e;throw new Error(
|
|
61
|
+
`Unsupported JSON Schema export mode '${e}'. Expected 'create', 'replace', or 'patch'.`)}function Ed(e,t={}){if(t.mode!==
|
|
62
|
+
void 0&&t.operation!==void 0){let r=is(t.mode);if(r!==t.operation)throw new Error(`Conflicting JSON Schema export option\
|
|
59
63
|
s: mode '${r}' does not match operation '${t.operation}'.`)}if(t.operation!==void 0){if(!Object.hasOwn(e.operations,t.operation))
|
|
60
|
-
throw new Error(`Unknown JSON Schema export operation '${t.operation}'.`);return t.operation}return
|
|
64
|
+
throw new Error(`Unknown JSON Schema export operation '${t.operation}'.`);return t.operation}return is(t.mode)}function bd(e,t={}){
|
|
61
65
|
if(t.operationName!==void 0&&t.operationDescriptor!==void 0)return{operationName:t.operationName,operation:t.operationDescriptor};
|
|
62
|
-
let r=
|
|
63
|
-
t,
|
|
64
|
-
e[
|
|
65
|
-
"_").replace(/^_+|_+$/g,"")||"operation"}function
|
|
66
|
-
function
|
|
67
|
-
r&&i.operation===n&&i.additionalProperties===o)||null}function
|
|
68
|
-
return e.nextDefinitionId+=1,n}function
|
|
66
|
+
let r=Ed(e,t);return{operationName:r,operation:e.operations[r]}}function vd(e={}){let t={...e};return Object.defineProperty(
|
|
67
|
+
t,jn,{value:{definitions:{},nodes:[],nextDefinitionId:1,rootNode:null},enumerable:!1}),t}function yr(e={}){return e[jn]?
|
|
68
|
+
e[jn]:{definitions:{},nodes:[],nextDefinitionId:1,rootNode:null}}function Sd(e){return String(e).replace(/[^a-zA-Z0-9]+/g,
|
|
69
|
+
"_").replace(/^_+|_+$/g,"")||"operation"}function Ln(e){return Y(e)&&Object.keys(e).length===1&&typeof e.$ref=="string"}
|
|
70
|
+
function wr(e){return Ln(e)?{allOf:[e]}:e}function Id(e,t,r,n,o){return e.nodes.find(i=>i.schema===t&&i.operationName===
|
|
71
|
+
r&&i.operation===n&&i.additionalProperties===o)||null}function Td(e,t){let r=Sd(t),n=`SchemaNode_${e.nextDefinitionId}_${r}`;
|
|
72
|
+
return e.nextDefinitionId+=1,n}function ss(e,t,r,n,o,{root:i=!1}={}){let s=yr(t),a=Id(s,e,r,n,o);if(a)return i&&(a.pointer=
|
|
69
73
|
"#",s.rootNode=a),a;let c={schema:e,operationName:r,operation:n,additionalProperties:o,status:"new",definitionName:i?null:
|
|
70
|
-
|
|
71
|
-
if(e.status==="built")return{$ref:e.pointer};if(e.status==="building")return{$ref:e.pointer};let r=
|
|
72
|
-
ing",e.pointer!=="#"&&(r.definitions[e.definitionName]={});let n=
|
|
73
|
-
return e.status="built",e.pointer==="#"?n:(r.definitions[e.definitionName]=n,{$ref:e.pointer})}function
|
|
74
|
-
let i=
|
|
75
|
-
referenceBacked:t}}function
|
|
76
|
-
n)),n.enforceRequired&&
|
|
77
|
-
0&&(a.required=s),a}function
|
|
78
|
-
n,"replace",s.schema.operations.replace,!1)),[
|
|
79
|
-
"schema")?"replace":o,c=a==="replace"?e.operations.replace:i;return
|
|
80
|
-
let s=
|
|
81
|
-
[
|
|
82
|
-
place"?e.operations.replace:i;return
|
|
83
|
-
t,r);if(a.kind==="nested")return Ct(
|
|
84
|
-
"opaque")return Ct({type:"object",additionalProperties:!0});if(a.kind==="map")return Ct({type:"object",additionalProperties:
|
|
85
|
-
e,t,r,n,o,i)})}let s=
|
|
74
|
+
Td(s,r),pointer:i?"#":null};return i?s.rootNode=c:c.pointer=`#/definitions/${c.definitionName}`,s.nodes.push(c),c}function as(e,t){
|
|
75
|
+
if(e.status==="built")return{$ref:e.pointer};if(e.status==="building")return{$ref:e.pointer};let r=yr(t);e.status="build\
|
|
76
|
+
ing",e.pointer!=="#"&&(r.definitions[e.definitionName]={});let n=Ad(e.schema,t,e.operationName,e.operation,e.additionalProperties);
|
|
77
|
+
return e.status="built",e.pointer==="#"?n:(r.definitions[e.definitionName]=n,{$ref:e.pointer})}function Vn(e,t,r,n,o=!1){
|
|
78
|
+
let i=yr(t),s=ss(e,t,r,n,o);return i.rootNode===s?{$ref:"#"}:as(s,t)}function Ct(e,{referenceBacked:t=!1}={}){return{schema:e,
|
|
79
|
+
referenceBacked:t}}function Ad(e,t,r,n,o=!1){let i={},s=[];for(let[c,l]of Object.entries(e.structure))P(i,c,Gn(e,c,l,t,r,
|
|
80
|
+
n)),n.enforceRequired&&l.required===!0&&s.push(c);let a={type:"object",properties:i,additionalProperties:o};return s.length>
|
|
81
|
+
0&&(a.required=s),a}function Od(e,t,r,n,o,i){let s=mr(t,r);if(!s)return null;if(s.kind==="schema")return{...wr(Vn(s.schema,
|
|
82
|
+
n,"replace",s.schema.operations.replace,!1)),[Te]:{castType:"object"}};let a=r.items.type==="object"&&Object.hasOwn(r.items,
|
|
83
|
+
"schema")?"replace":o,c=a==="replace"?e.operations.replace:i;return Gn(e,`${t}[]`,r.items,n,a,c)}function Pd(e,t,r,n,o,i){
|
|
84
|
+
let s=Pt(t,r);if(!s)return null;if(s.kind==="schema")return{...wr(Vn(s.schema,n,"replace",s.schema.operations.replace,!1)),
|
|
85
|
+
[Te]:{castType:"object"}};let a=s.definition.type==="object"&&Object.hasOwn(s.definition,"schema")?"replace":o,c=a==="re\
|
|
86
|
+
place"?e.operations.replace:i;return Gn(e,`${t}.*`,s.definition,n,a,c)}function Rd(e,t,r,n,o,i){if(r.type==="object"){let a=fr(
|
|
87
|
+
t,r);if(a.kind==="nested")return Ct(Vn(a.schema,n,o,i,a.allowAdditionalProperties===!0),{referenceBacked:!0});if(a.kind===
|
|
88
|
+
"opaque")return Ct({type:"object",additionalProperties:!0});if(a.kind==="map")return Ct({type:"object",additionalProperties:Pd(
|
|
89
|
+
e,t,r,n,o,i)})}let s=yd(e,r)({schema:e,fieldName:t,definition:r,operation:o,mode:o,options:n});if(!s||typeof s!="object"||
|
|
86
90
|
Array.isArray(s))throw new Error(`Type '${r.type}' on field '${t}' returned an invalid JSON Schema fragment.`);if(r.type===
|
|
87
|
-
"array"){let a=
|
|
88
|
-
function
|
|
89
|
-
|
|
90
|
-
continue;let h=
|
|
91
|
-
c[
|
|
92
|
-
let m=
|
|
91
|
+
"array"){let a=Od(e,t,r,n,o,i);if(a)return Ct({...s,items:a},{referenceBacked:Ln(s)})}return Ct(s,{referenceBacked:Ln(s)})}
|
|
92
|
+
function Gn(e,t,r,n,o,i){let s={schema:e,fieldName:t,definition:r,operation:o,mode:o,options:n},a=Rd(e,t,r,n,o,i),c=a.referenceBacked?
|
|
93
|
+
wr(a.schema):{...a.schema},l={castType:r.type};for(let f of Object.keys(r)){if(f==="type"||!Object.hasOwn(e.validators,f))
|
|
94
|
+
continue;let h=_d(e,f,t);if(!h)continue;let w=h({...s,parameterName:f,parameterValue:r[f],fieldSchema:{...c}});w&&gd(c,w)}
|
|
95
|
+
c[Te]&&(Un(l,c[Te]),delete c[Te]);let u=[];r.nullable===!0&&u.push({type:"null"}),r.nullOnEmpty===!0&&u.push({const:""});
|
|
96
|
+
let m=wr(wd(c,u));if(r.defaultTo!==void 0&&i.applyDefaults)if(typeof r.defaultTo!="function"){let f=e._normalizeDefault(
|
|
93
97
|
r,r.defaultTo,{fieldPath:t,currentObject:{},containerKey:t,objectBeforeCast:{},options:{},settings:e._buildOperationSettings(
|
|
94
98
|
o,i,{})});if(Object.keys(f.errors).length>0){let h=Object.values(f.errors)[0];throw new Error(`defaultTo for "${t}" is i\
|
|
95
|
-
nvalid (${h.code}).`)}m.default=f.value}else
|
|
96
|
-
t),{operationName:n,operation:o}=
|
|
97
|
-
o,i,{root:!0}),c={$schema:
|
|
98
|
-
|
|
99
|
-
ema"
|
|
100
|
-
"y","on"],
|
|
99
|
+
nvalid (${h.code}).`)}m.default=f.value}else l.defaults={providedByFunction:!0};return m[Te]=l,m}function cs(e,t={}){let r=vd(
|
|
100
|
+
t),{operationName:n,operation:o}=bd(e,r),i=r.additionalProperties===void 0?!1:r.additionalProperties,s=yr(r),a=ss(e,r,n,
|
|
101
|
+
o,i,{root:!0}),c={$schema:dd,...as(a,r)};return Object.keys(s.definitions).length>0&&(c.definitions=s.definitions),c}var dd,
|
|
102
|
+
Te,$n,jn,pd,md,fd,hd,ls=g(()=>{Pn();hr();kn();tt();Nt();dd="http://json-schema.org/draft-07/schema#",Te="x-json-rest-sch\
|
|
103
|
+
ema",$n=["object","array","string","number","boolean"],jn=Symbol("json-rest-schema.exportContext"),pd=["true","1","yes",
|
|
104
|
+
"y","on"],md=["false","0","no","n","off"];fd={none:()=>({type:$n}),blob:()=>({type:$n}),serialize:()=>({type:$n}),object:()=>({
|
|
101
105
|
type:"object"}),array:()=>({type:"array"}),file:()=>({type:"string"}),string:()=>({type:"string"}),number:()=>({type:["n\
|
|
102
|
-
umber","string"]}),integer:()=>({type:["integer","string"]}),epochMilliseconds:()=>
|
|
103
|
-
dateTime:({definition:e,fieldName:t})=>({type:"string",format:"date-time",pattern:
|
|
104
|
-
date",pattern:
|
|
105
|
-
strictBoolean===!0)return{type:"boolean"};let t=new Set([...
|
|
106
|
-
[...
|
|
107
|
-
{type:"string",enum:[...r,...t]}]}},id:()=>({type:["integer","string"],minimum:1,pattern:"^[1-9][0-9]*$"})},
|
|
106
|
+
umber","string"]}),integer:()=>({type:["integer","string"]}),epochMilliseconds:()=>os(864e13),epochSeconds:()=>os(864e10),
|
|
107
|
+
dateTime:({definition:e,fieldName:t})=>({type:"string",format:"date-time",pattern:ns(e,t)}),date:()=>({type:"string",format:"\
|
|
108
|
+
date",pattern:Ji}),time:({definition:e,fieldName:t})=>({type:"string",pattern:rs(e,t)}),boolean:({definition:e})=>{if(e.
|
|
109
|
+
strictBoolean===!0)return{type:"boolean"};let t=new Set([...pd,String(e.stringTrueWhen||"true").trim().toLowerCase()]),r=new Set(
|
|
110
|
+
[...md,String(e.stringFalseWhen||"false").trim().toLowerCase()]);return{anyOf:[{type:"boolean"},{type:"number",enum:[0,1]},
|
|
111
|
+
{type:"string",enum:[...r,...t]}]}},id:()=>({type:["integer","string"],minimum:1,pattern:"^[1-9][0-9]*$"})},hd={minLength:({
|
|
108
112
|
definition:e,parameterValue:t})=>e.type==="string"?{minLength:t}:null,maxLength:({definition:e,parameterValue:t})=>e.type===
|
|
109
|
-
"string"?{maxLength:t}:null,min:({definition:e,parameterValue:t})=>
|
|
113
|
+
"string"?{maxLength:t}:null,min:({definition:e,parameterValue:t})=>rt(e)?{minimum:t}:null,max:({definition:e,parameterValue:t})=>rt(
|
|
110
114
|
e)?{maximum:t}:null,pattern:({definition:e,parameterValue:t})=>e.type==="string"?{pattern:t instanceof RegExp?t.source:t}:
|
|
111
|
-
null,enum:({parameterValue:e})=>({enum:e}),
|
|
112
|
-
|
|
113
|
-
{
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
o=
|
|
122
|
-
|
|
123
|
-
function
|
|
115
|
+
null,enum:({parameterValue:e})=>({enum:e}),minItems:({definition:e,parameterValue:t})=>e.type==="array"?{minItems:t}:null,
|
|
116
|
+
maxItems:({definition:e,parameterValue:t})=>e.type==="array"?{maxItems:t}:null,notEmpty:({parameterValue:e,definition:t})=>!e||
|
|
117
|
+
t.type==="array"?null:{minLength:1},uppercase:({parameterValue:e})=>e?Me("transforms",{uppercase:!0}):null,lowercase:({parameterValue:e})=>e?
|
|
118
|
+
Me("transforms",{lowercase:!0}):null,length:({parameterValue:e})=>Me("transforms",{length:e}),unsigned:({parameterValue:e})=>e?
|
|
119
|
+
Me("metadata",{unsigned:!0}):null,precision:({parameterValue:e})=>Me("metadata",{precision:e}),scale:({parameterValue:e})=>Me(
|
|
120
|
+
"metadata",{scale:e}),temporalPrecision:({parameterValue:e})=>Me("metadata",{temporalPrecision:e}),strictBoolean:()=>null,
|
|
121
|
+
required:()=>null,nullable:()=>null,nullOnEmpty:()=>null,defaultTo:()=>null}});function us(e){return e!==null&&(typeof e=="object"||typeof e=="function")&&typeof e.then=="function"}function Wn(e){return e instanceof
|
|
122
|
+
st}function Nd(){return{self:!1,children:{}}}function ds(e){return Object.keys(e.children).length>0}function De(e,t){return`${e}\
|
|
123
|
+
.${String(t)}`}function ws(e,t){return e===""?String(t):De(e,t)}function ps(e,t){if(e===t)return"";let r=`${t}.`;return e.
|
|
124
|
+
startsWith(r)?e.slice(r.length):null}function ot(e,t){let r={};for(let n of Object.values(e)){let o=De(t,n.field);P(r,o,
|
|
125
|
+
{...n,field:o})}return r}function Fn(e){return xn(e,"validatePath")}function ms(e){let t={};for(let r of e){let n=Fn(r),
|
|
126
|
+
o=t;for(let i=0;i<n.length;i++){let s=n[i];Object.hasOwn(o,s)||P(o,s,Nd()),i===n.length-1&&(o[s].self=!0),o=o[s].children}}
|
|
127
|
+
return t}function Cd(e,t){let r=e;for(let n of t){if(r==null||typeof r!="object"||!Object.hasOwn(r,n))return;r=r[n]}return r}
|
|
128
|
+
function _r(e){return e===null?!0:Array.isArray(e)||Y(e)?Object.keys(e).length>0:e!==void 0}function fs(e){return[...e].
|
|
124
129
|
sort((t,r)=>{let n=/^[0-9]+$/.test(t),o=/^[0-9]+$/.test(r);return n&&o?Number(t)-Number(r):n?-1:o?1:t.localeCompare(r)})}
|
|
125
|
-
function
|
|
130
|
+
function kd(e){return/^[0-9]+$/.test(e)}function xd(e,t=new WeakMap){if(t.has(e))return t.get(e);let r=Object.create(st.
|
|
126
131
|
prototype);return t.set(e,r),r.structure=null,r.types=e.types,r.validators=e.validators,r.operations=e.operations,r.structure=
|
|
127
|
-
Er(
|
|
128
|
-
"object")return e;if(
|
|
132
|
+
br(Er(e.structure,t)),r._installOperationMethods(),Object.freeze(r)}function Er(e,t=new WeakMap){if(e===null||typeof e!=
|
|
133
|
+
"object")return e;if(Wn(e))return xd(e,t);if(e instanceof Date)return new Date(e.getTime());if(e instanceof RegExp){let n=new RegExp(
|
|
129
134
|
e.source,e.flags);return n.lastIndex=e.lastIndex,n}if(t.has(e))return t.get(e);if(Array.isArray(e)){let n=[];t.set(e,n);
|
|
130
|
-
for(let o of e)n.push(
|
|
131
|
-
o,t));return r}function
|
|
132
|
-
isArray(e))for(let r of e)
|
|
133
|
-
return Er(
|
|
134
|
-
e.structure,n))return null;let i=e.structure[n];if(o.length<1)return i;let s=
|
|
135
|
-
if(t?.type==="object"){let o=e._resolveObjectFieldMode(n,t);return o.kind!=="nested"?null:
|
|
136
|
-
"array"){let o=e._resolveArrayItemsConfig(n,t);if(!o||r.length<1)return null;let[i,...s]=r;if(!
|
|
137
|
-
n,i);return o.kind==="schema"?s.length<1?null:
|
|
138
|
-
function
|
|
139
|
-
"");n.length>0?r.skipFields=n:delete r.skipFields}if(
|
|
140
|
-
let s=
|
|
141
|
-
let o=t[r];if(!n.includes(o))throw new Error(`Operation "${e}" must define ${r} as one of: ${n.join(", ")}.`)}function
|
|
135
|
+
for(let o of e)n.push(Er(o,t));return n}if(!Y(e))return e;let r={};t.set(e,r);for(let[n,o]of Object.entries(e))P(r,n,Er(
|
|
136
|
+
o,t));return r}function br(e,t=new WeakSet){if(e===null||typeof e!="object"||t.has(e)||Wn(e))return e;if(t.add(e),Array.
|
|
137
|
+
isArray(e))for(let r of e)br(r,t);else for(let r of Reflect.ownKeys(e))br(e[r],t);return Object.freeze(e)}function Bn(e){
|
|
138
|
+
return br(Er(e))}function qn(e,t,r=""){if(!Wn(e)||!Array.isArray(t)||t.length<1)return null;let[n,...o]=t;if(!Object.hasOwn(
|
|
139
|
+
e.structure,n))return null;let i=e.structure[n];if(o.length<1)return i;let s=ws(r,n);return ys(e,i,o,s)}function ys(e,t,r,n){
|
|
140
|
+
if(t?.type==="object"){let o=e._resolveObjectFieldMode(n,t);return o.kind!=="nested"?null:qn(o.schema,r,n)}if(t?.type===
|
|
141
|
+
"array"){let o=e._resolveArrayItemsConfig(n,t);if(!o||r.length<1)return null;let[i,...s]=r;if(!kd(i))return null;let a=De(
|
|
142
|
+
n,i);return o.kind==="schema"?s.length<1?null:qn(o.schema,s,a):s.length<1?o.definition:ys(e,o.definition,s,a)}return null}
|
|
143
|
+
function it(e,t){let r={...e};if(Array.isArray(e.skipFields)){let n=e.skipFields.map(o=>ps(o,t)).filter(o=>o!==null&&o!==
|
|
144
|
+
"");n.length>0?r.skipFields=n:delete r.skipFields}if(Y(e.skipParams)){let n={};for(let[o,i]of Object.entries(e.skipParams)){
|
|
145
|
+
let s=ps(o,t);s===null||s===""||P(n,s,i)}Object.keys(n).length>0?r.skipParams=n:delete r.skipParams}return r}function hs(e,t,r,n){
|
|
146
|
+
let o=t[r];if(!n.includes(o))throw new Error(`Operation "${e}" must define ${r} as one of: ${n.join(", ")}.`)}function zn(e,t,r,n=!0){
|
|
142
147
|
let o=t[r];if(!(o===void 0&&!n)&&typeof o!="boolean")throw new Error(`Operation "${e}" must define ${r} as a boolean.`)}
|
|
143
|
-
function
|
|
144
|
-
return
|
|
145
|
-
["validated","input"]),
|
|
148
|
+
function jd(e,t){if(typeof t!="object"||t===null||Array.isArray(t))throw new Error(`Operation "${e}" must be an object.`);
|
|
149
|
+
return hs(e,t,"targetFields",["schema","input"]),zn(e,t,"enforceRequired"),zn(e,t,"applyDefaults"),hs(e,t,"outputFields",
|
|
150
|
+
["validated","input"]),zn(e,t,"rejectExplicitUndefined",!1),Object.freeze({targetFields:t.targetFields,enforceRequired:t.
|
|
146
151
|
enforceRequired,applyDefaults:t.applyDefaults,outputFields:t.outputFields,rejectExplicitUndefined:t.rejectExplicitUndefined===
|
|
147
|
-
void 0?!0:t.rejectExplicitUndefined})}function
|
|
148
|
-
"Schema operations must be an object.");let t=Object.create(null);for(let[r,n]of Object.entries(
|
|
149
|
-
entries(e))
|
|
150
|
-
e))
|
|
151
|
-
()=>{
|
|
152
|
-
outputFields:"validated",rejectExplicitUndefined:!0}),replace:Object.freeze({targetFields:"schema",enforceRequired:!0,
|
|
153
|
-
outputFields:"validated",rejectExplicitUndefined:!0}),patch:Object.freeze({targetFields:"input",enforceRequired:!1,
|
|
154
|
-
outputFields:"input",rejectExplicitUndefined:!0})});
|
|
155
|
-
validators=
|
|
156
|
-
|
|
157
|
-
{field:t,code:r,message:n,params:o},i}_paramToBeSkipped(t,r,n){return typeof r!="object"||r===null
|
|
158
|
-
r[n].includes(t))}_fieldToBeSkipped(t,r){return Array.isArray(r.skipFields)&&r.skipFields.includes(
|
|
159
|
-
for(let[n,o]of Object.entries(r))
|
|
152
|
+
void 0?!0:t.rejectExplicitUndefined})}function Ld(e={}){if(typeof e!="object"||e===null||Array.isArray(e))throw new Error(
|
|
153
|
+
"Schema operations must be an object.");let t=Object.create(null);for(let[r,n]of Object.entries($d))P(t,r,n);for(let[r,n]of Object.
|
|
154
|
+
entries(e))P(t,r,jd(r,n));return Object.freeze(t)}function gs(e){let t=Object.create(null);for(let[r,n]of Object.entries(
|
|
155
|
+
e))P(t,r,n);return Object.freeze(t)}function Md(e){let t={...e};return delete t.operation,delete t.mode,t}var Hn,$d,st,_s=g(
|
|
156
|
+
()=>{ls();Pn();Nt();tt();hr();Hn=new WeakMap;$d=Object.freeze({create:Object.freeze({targetFields:"schema",enforceRequired:!0,
|
|
157
|
+
applyDefaults:!0,outputFields:"validated",rejectExplicitUndefined:!0}),replace:Object.freeze({targetFields:"schema",enforceRequired:!0,
|
|
158
|
+
applyDefaults:!0,outputFields:"validated",rejectExplicitUndefined:!0}),patch:Object.freeze({targetFields:"input",enforceRequired:!1,
|
|
159
|
+
applyDefaults:!1,outputFields:"input",rejectExplicitUndefined:!0})});st=class{constructor(t,r,n,o={}){Rn(t),this.structure=
|
|
160
|
+
t,this.types=gs(r),this.validators=gs(n),this.operations=Ld(o),this._installOperationMethods()}_typeError(t){return this.
|
|
161
|
+
_paramError(t,"TYPE_CAST_FAILED","Value could not be cast to the required type.")}_paramError(t,r,n,o={}){let i=new Error(
|
|
162
|
+
n);return i.errorObject={field:t,code:r,message:n,params:o},i}_paramToBeSkipped(t,r,n){return typeof r!="object"||r===null?
|
|
163
|
+
!1:!!(Array.isArray(r[n])&&r[n].includes(t))}_fieldToBeSkipped(t,r){return Array.isArray(r.skipFields)&&r.skipFields.includes(
|
|
164
|
+
t)}_mergeErrors(t,r){for(let[n,o]of Object.entries(r))P(t,n,o)}_singleErrorMap(t){let r={};return P(r,t.field,t),r}_assertSupportedOptions(t={}){
|
|
160
165
|
if(Object.hasOwn(t,"onlyObjectValues"))throw new Error("Unsupported validation option `onlyObjectValues`. Call `patch()`\
|
|
161
166
|
directly.");if(Object.hasOwn(t,"mode"))throw new Error("Unsupported validation option `mode`. Call `validateWith()` or \
|
|
162
167
|
an operation method directly.");if(Object.hasOwn(t,"operation"))throw new Error("Unsupported validation option `operatio\
|
|
163
168
|
n`. Call `validateWith()` or an operation method directly.")}_buildOperationSettings(t,r,n){return{operationName:t,operation:r,
|
|
164
169
|
targetFieldNames:r.targetFields==="input"?Object.keys(n):Object.keys(this.structure),outputFieldNames:r.outputFields==="\
|
|
165
170
|
input"?Object.keys(n):Object.keys(this.structure),enforceRequired:r.enforceRequired,applyDefaults:r.applyDefaults,rejectExplicitUndefined:r.
|
|
166
|
-
rejectExplicitUndefined,defaultedFields:new Set,isFieldPresent:o=>Object.hasOwn(n,o)}}_assertPlainObjectInput(t,r){if(!
|
|
171
|
+
rejectExplicitUndefined,defaultedFields:new Set,isFieldPresent:o=>Object.hasOwn(n,o)}}_assertPlainObjectInput(t,r){if(!Y(
|
|
167
172
|
r))throw new Error(`${t}() expects a plain object input.`)}_resolvePathValidationRequest(t={}){let r=t.operation??t.mode??
|
|
168
173
|
"patch";if(Object.hasOwn(t,"operation")&&Object.hasOwn(t,"mode")&&t.operation!==t.mode)throw new Error("Path validation \
|
|
169
174
|
options `operation` and `mode` must match when both are provided.");if(!Object.hasOwn(this.operations,r))throw new Error(
|
|
170
|
-
`Unknown operation "${r}".`);let n=this.operations[r];return{operationName:r,operation:n,validationOptions:
|
|
175
|
+
`Unknown operation "${r}".`);let n=this.operations[r];return{operationName:r,operation:n,validationOptions:Md(t)}}_buildOperationResult(t,r,n){
|
|
171
176
|
let o={};for(let i of n.outputFieldNames){if(!Object.hasOwn(this.structure,i))continue;let s=n.isFieldPresent(i);(r[i]!==
|
|
172
|
-
void 0||s&&t[i]===null||n.defaultedFields.has(i))&&(!s&&!n.defaultedFields.has(i)||
|
|
173
|
-
return fr(t,r)}_resolveArrayItemsConfig(t,r){return mr(t,r)}_resolveObjectValuesConfig(t,r){return
|
|
177
|
+
void 0||s&&t[i]===null||n.defaultedFields.has(i))&&(!s&&!n.defaultedFields.has(i)||P(o,i,r[i]))}return o}_resolveObjectFieldMode(t,r){
|
|
178
|
+
return fr(t,r)}_resolveArrayItemsConfig(t,r){return mr(t,r)}_resolveObjectValuesConfig(t,r){return Pt(t,r)}_buildArrayItemSettings(t,r){
|
|
174
179
|
return t.type==="object"&&Object.hasOwn(t,"schema")?{...r,operationName:"replace",operation:this.operations.replace}:r}_castValue(t,r,n,o,i,s,a,c){
|
|
175
|
-
let
|
|
176
|
-
`No casting function for type: ${t.type}`);let m=this.types[t.type];if(r===null)return
|
|
180
|
+
let l=t.nullable===!0||a.nullable===!0,u=t.nullOnEmpty===!0||a.nullOnEmpty===!0;if(!Object.hasOwn(this.types,t.type))throw new Error(
|
|
181
|
+
`No casting function for type: ${t.type}`);let m=this.types[t.type];if(r===null)return l?(P(o,i,null),{errors:{},shouldContinue:!1}):
|
|
177
182
|
{errors:this._singleErrorMap({field:n,code:"NOT_NULLABLE",message:"Field cannot be null",params:{}}),shouldContinue:!1};
|
|
178
|
-
if(r===""&&
|
|
183
|
+
if(r===""&&u)return P(o,i,null),{errors:{},shouldContinue:!1};let f={schema:this,definition:t,value:r,fieldName:n,object:o,
|
|
179
184
|
objectBeforeCast:s,valueBeforeCast:r,options:a,mode:c.operationName,operation:c.operationName,fieldPresent:!0,computedOptions:{
|
|
180
|
-
nullable:u
|
|
181
|
-
n,h,
|
|
185
|
+
nullable:l||u,nullOnEmpty:u},throwTypeError:()=>{throw this._typeError(n)},throwParamError:(h,w,I)=>{throw this._paramError(
|
|
186
|
+
n,h,w,I)}};try{let h=m(f);if(us(h))throw new Error(`Type handler for "${t.type}" must be synchronous.`);h!==void 0&&(P(o,
|
|
182
187
|
i,h),f.value=h)}catch(h){if(h.errorObject)return{errors:this._singleErrorMap(h.errorObject),shouldContinue:!1};throw h}return{
|
|
183
188
|
errors:{},context:f,shouldContinue:!0}}_runFieldValidators(t,r,n,o,i,s){for(let a of Object.keys(t)){if(a==="type"||this.
|
|
184
189
|
_paramToBeSkipped(a,s.skipParams,r)||!Object.hasOwn(this.validators,a))continue;let c=this.validators[a];try{i.parameterName=
|
|
185
|
-
a,i.parameterValue=t[a];let
|
|
186
|
-
(
|
|
187
|
-
let
|
|
188
|
-
context:
|
|
189
|
-
t,n,o,i,
|
|
190
|
-
let
|
|
190
|
+
a,i.parameterValue=t[a];let l=c(i);if(us(l))throw new Error(`Validator handler for "${a}" must be synchronous.`);l!==void 0&&
|
|
191
|
+
(P(n,o,l),i.value=l)}catch(l){if(l.errorObject)return this._singleErrorMap(l.errorObject);throw l}}return{}}_normalizeAndValidateValue(t,r,n,o,i,s,a,c){
|
|
192
|
+
let l=this._castValue(t,r,n,o,i,s,a,c);if(Object.keys(l.errors).length>0)return l.errors;if(!l.shouldContinue)return{};let{
|
|
193
|
+
context:u}=l,m=this._validateNestedValue(t,n,o,i,a,c);return Object.keys(m).length>0?m:(u.value=o[i],this._runFieldValidators(
|
|
194
|
+
t,n,o,i,u,a))}_normalizeDefault(t,r,{fieldPath:n,currentObject:o,containerKey:i,objectBeforeCast:s,options:a,settings:c}){
|
|
195
|
+
let l={...o};return P(l,i,r),{errors:this._normalizeAndValidateValue(t,r,n,l,i,s,a,c),value:l[i]}}_validateNestedValue(t,r,n,o,i,s){
|
|
191
196
|
if(t.type==="object"){let c=this._resolveObjectFieldMode(r,t);return c.kind==="nested"?this._validateNestedObjectSchema(
|
|
192
197
|
c,r,n,o,i,s):c.kind==="map"?this._validateObjectValues(r,n,o,c.valuesConfig,i,s):{}}if(t.type!=="array")return{};let a=this.
|
|
193
198
|
_resolveArrayItemsConfig(r,t);return a?this._validateArrayItems(r,n,o,a,i,s):{}}_validateNestedObjectSchema(t,r,n,o,i,s){
|
|
194
|
-
let a=n[o],c=t.allowAdditionalProperties?this._extractKnownObjectFields(a,t.schema):a,
|
|
195
|
-
s.operationName,s.operation,c,
|
|
196
|
-
a,t.schema,
|
|
197
|
-
entries(t))Object.hasOwn(r.structure,o)&&
|
|
198
|
-
keys(t)){if(!Object.hasOwn(r.structure,i)){
|
|
199
|
-
n))Object.hasOwn(o,i)||
|
|
200
|
-
keys(a)){let m=De(t,
|
|
201
|
-
_mergeErrors(
|
|
202
|
-
schema._validateWithOperation("replace",o.schema.operations.replace,f,
|
|
203
|
-
|
|
204
|
-
definition,s));this._mergeErrors(
|
|
205
|
-
c.length;
|
|
206
|
-
this._mergeErrors(
|
|
207
|
-
schema._validateWithOperation("replace",o.schema.operations.replace,c[
|
|
208
|
-
|
|
209
|
-
o.definition,s));this._mergeErrors(
|
|
210
|
-
let s=this.structure[t];if(this._fieldToBeSkipped(t,o))return{};let a=i.isFieldPresent(t),c=r[t],
|
|
211
|
-
s.required&&(!a||
|
|
212
|
-
Field is required",params:{}}):a?
|
|
199
|
+
let a=n[o],c=t.allowAdditionalProperties?this._extractKnownObjectFields(a,t.schema):a,l=t.schema._validateWithOperation(
|
|
200
|
+
s.operationName,s.operation,c,it(i,r));return P(n,o,t.allowAdditionalProperties?this._mergeKnownAndPassthroughObjectFields(
|
|
201
|
+
a,t.schema,l.validatedObject):l.validatedObject),ot(l.errors,r)}_extractKnownObjectFields(t,r){let n={};for(let[o,i]of Object.
|
|
202
|
+
entries(t))Object.hasOwn(r.structure,o)&&P(n,o,i);return n}_mergeKnownAndPassthroughObjectFields(t,r,n){let o={};for(let i of Object.
|
|
203
|
+
keys(t)){if(!Object.hasOwn(r.structure,i)){P(o,i,t[i]);continue}Object.hasOwn(n,i)&&P(o,i,n[i])}for(let[i,s]of Object.entries(
|
|
204
|
+
n))Object.hasOwn(o,i)||P(o,i,s);return o}_validateObjectValues(t,r,n,o,i,s){let a=r[n],c={...a},l={};P(r,n,c);for(let u of Object.
|
|
205
|
+
keys(a)){let m=De(t,u);if(this._fieldToBeSkipped(m,i))continue;let f=c[u];if(f===void 0){s.rejectExplicitUndefined?this.
|
|
206
|
+
_mergeErrors(l,this._singleErrorMap(this._typeError(m).errorObject)):delete c[u];continue}if(o.kind==="schema"){let w=o.
|
|
207
|
+
schema._validateWithOperation("replace",o.schema.operations.replace,f,it(i,m));P(c,u,w.validatedObject),this._mergeErrors(
|
|
208
|
+
l,ot(w.errors,m));continue}let h=this._normalizeAndValidateValue(o.definition,f,m,c,u,a,i,this._buildArrayItemSettings(o.
|
|
209
|
+
definition,s));this._mergeErrors(l,h)}return l}_validateArrayItems(t,r,n,o,i,s){let a=r[n],c=a.slice(),l={};P(r,n,c);for(let u=0;u<
|
|
210
|
+
c.length;u++){let m=De(t,u);if(this._fieldToBeSkipped(m,i))continue;if(!Object.hasOwn(a,u)||c[u]===void 0){s.rejectExplicitUndefined?
|
|
211
|
+
this._mergeErrors(l,this._singleErrorMap(this._typeError(m).errorObject)):delete c[u];continue}if(o.kind==="schema"){let h=o.
|
|
212
|
+
schema._validateWithOperation("replace",o.schema.operations.replace,c[u],it(i,m));P(c,u,h.validatedObject),this._mergeErrors(
|
|
213
|
+
l,ot(h.errors,m));continue}let f=this._normalizeAndValidateValue(o.definition,c[u],m,c,u,a,i,this._buildArrayItemSettings(
|
|
214
|
+
o.definition,s));this._mergeErrors(l,f)}return l}_validateField(t,r,n,o,i){if(!Object.hasOwn(this.structure,t))return{};
|
|
215
|
+
let s=this.structure[t];if(this._fieldToBeSkipped(t,o))return{};let a=i.isFieldPresent(t),c=r[t],l=c===void 0;return i.enforceRequired&&
|
|
216
|
+
s.required&&(!a||l)&&!this._paramToBeSkipped("required",o.skipParams,t)?this._singleErrorMap({field:t,code:"REQUIRED",message:"\
|
|
217
|
+
Field is required",params:{}}):a?l?i.rejectExplicitUndefined?this._singleErrorMap(this._typeError(t).errorObject):{}:this.
|
|
213
218
|
_normalizeAndValidateValue(s,c,t,n,t,r,o,i):{}}_validateWithOperation(t,r,n,o){this._assertSupportedOptions(o);let i={},
|
|
214
|
-
s={...n},a=this._buildOperationSettings(t,r,n);for(let c of Object.keys(n))Object.hasOwn(this.structure,c)||
|
|
215
|
-
code:"FIELD_NOT_ALLOWED",message:"Field not allowed",params:{}});for(let c of a.targetFieldNames){let
|
|
216
|
-
c,n,s,o,a);this._mergeErrors(i,
|
|
217
|
-
this.structure[c].defaultTo!==void 0){let
|
|
218
|
-
m=this._normalizeDefault(u,
|
|
219
|
-
_mergeErrors(i,m.errors),Object.keys(m.errors).length>0)continue;
|
|
220
|
-
_buildOperationResult(n,s,a),errors:i}}_validateSelectedTree(t,r,n,o,i=""){let s={},a={};for(let c of
|
|
221
|
-
let
|
|
222
|
-
c,t[c],r,a,n,o,
|
|
223
|
-
hasOwn(this.structure,t))return{};let c=this.structure[t],
|
|
224
|
-
let m=Object.hasOwn(n,t),f=n[t],h={};if(!m){if(
|
|
225
|
-
a)&&this._mergeErrors(h,this._singleErrorMap({field:a,code:"REQUIRED",message:"Field is required",params:{}})),
|
|
219
|
+
s={...n},a=this._buildOperationSettings(t,r,n);for(let c of Object.keys(n))Object.hasOwn(this.structure,c)||P(i,c,{field:c,
|
|
220
|
+
code:"FIELD_NOT_ALLOWED",message:"Field not allowed",params:{}});for(let c of a.targetFieldNames){let l=this._validateField(
|
|
221
|
+
c,n,s,o,a);this._mergeErrors(i,l)}if(a.applyDefaults){for(let c of Object.keys(this.structure))if(!a.isFieldPresent(c)&&
|
|
222
|
+
this.structure[c].defaultTo!==void 0){let l=this.structure[c],u=typeof l.defaultTo=="function"?l.defaultTo():l.defaultTo,
|
|
223
|
+
m=this._normalizeDefault(l,u,{fieldPath:c,currentObject:s,containerKey:c,objectBeforeCast:n,options:o,settings:a});if(this.
|
|
224
|
+
_mergeErrors(i,m.errors),Object.keys(m.errors).length>0)continue;P(s,c,m.value),a.defaultedFields.add(c)}}return{validatedObject:this.
|
|
225
|
+
_buildOperationResult(n,s,a),errors:i}}_validateSelectedTree(t,r,n,o,i=""){let s={},a={};for(let c of fs(Object.keys(t))){
|
|
226
|
+
let l=ws(i,c);if(!Object.hasOwn(this.structure,c))throw new Error(`Unknown schema path "${l}".`);let u=this._validateSelectedField(
|
|
227
|
+
c,t[c],r,a,n,o,l);this._mergeErrors(s,u)}return{validatedObject:a,errors:s}}_validateSelectedField(t,r,n,o,i,s,a){if(!Object.
|
|
228
|
+
hasOwn(this.structure,t))return{};let c=this.structure[t],l=r.self===!0,u=ds(r);if(this._fieldToBeSkipped(a,i))return{};
|
|
229
|
+
let m=Object.hasOwn(n,t),f=n[t],h={};if(!m){if(l&&s.enforceRequired&&c.required&&!this._paramToBeSkipped("required",i.skipParams,
|
|
230
|
+
a)&&this._mergeErrors(h,this._singleErrorMap({field:a,code:"REQUIRED",message:"Field is required",params:{}})),l&&s.applyDefaults&&
|
|
226
231
|
c.defaultTo!==void 0){let d=typeof c.defaultTo=="function"?c.defaultTo():c.defaultTo,p=this._normalizeDefault(c,d,{fieldPath:a,
|
|
227
232
|
currentObject:o,containerKey:t,objectBeforeCast:n,options:i,settings:s});this._mergeErrors(h,p.errors),Object.keys(p.errors).
|
|
228
|
-
length===0&&
|
|
229
|
-
a).errorObject):{};let
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
n,t);if(c.kind!=="nested")throw new Error(`Schema path "${n}" does not support nested field selection.`);let
|
|
234
|
-
|
|
235
|
-
|
|
233
|
+
length===0&&P(o,t,p.value)}return h}if(f===void 0)return l&&s.rejectExplicitUndefined?this._singleErrorMap(this._typeError(
|
|
234
|
+
a).errorObject):{};let w={[t]:f};if(l){let d=this._normalizeAndValidateValue(c,f,a,w,t,n,i,s);return Object.hasOwn(w,t)&&
|
|
235
|
+
w[t]!==void 0?P(o,t,w[t]):w[t]===null&&P(o,t,null),d}if(!u)return{};let I=this._castValue(c,f,a,w,t,n,i,s);if(Object.keys(
|
|
236
|
+
I.errors).length>0)return I.errors;if(!I.shouldContinue)return{};let S=this._validateSelectedDescendants(c,r.children,a,
|
|
237
|
+
w,t,i,s);return _r(w[t])&&P(o,t,w[t]),S}_validateSelectedDescendants(t,r,n,o,i,s,a){if(t.type==="object"){let c=this._resolveObjectFieldMode(
|
|
238
|
+
n,t);if(c.kind!=="nested")throw new Error(`Schema path "${n}" does not support nested field selection.`);let l=o[i];if(!Y(
|
|
239
|
+
l))return{};let u=c.schema._validateSelectedTree(r,l,it(s,n),{...a,defaultedFields:new Set});return P(o,i,u.validatedObject),
|
|
240
|
+
ot(u.errors,n)}if(t.type==="array"){let c=this._resolveArrayItemsConfig(n,t);if(!c)throw new Error(`Schema path "${n}" d\
|
|
236
241
|
oes not define array items for nested selection.`);return this._validateSelectedArrayItems(n,o,i,c,r,s,a)}throw new Error(
|
|
237
|
-
`Schema path "${n}" does not support nested field selection.`)}_validateSelectedArrayItems(t,r,n,o,i,s,a){let c=[],
|
|
238
|
-
|
|
239
|
-
id because array segments must use numeric indexes.`);let f=Number(m),h=De(t,f),
|
|
240
|
-
h,s))continue;if(!Object.hasOwn(
|
|
241
|
-
if(d===void 0){
|
|
242
|
-
let E=o.schema._validateWithOperation("replace",o.schema.operations.replace,d,
|
|
243
|
-
this._mergeErrors(
|
|
244
|
-
operationName:"replace",operation:o.schema.operations.replace,defaultedFields:new Set});
|
|
245
|
-
this._mergeErrors(
|
|
246
|
-
o.definition,d,h,_,0,
|
|
247
|
-
continue}if(!S)continue;let b=this._castValue(o.definition,d,h,_,0,
|
|
248
|
-
|
|
249
|
-
s,p);
|
|
242
|
+
`Schema path "${n}" does not support nested field selection.`)}_validateSelectedArrayItems(t,r,n,o,i,s,a){let c=[],l=r[n],
|
|
243
|
+
u={};P(r,n,c);for(let m of fs(Object.keys(i))){if(!/^[0-9]+$/.test(m))throw new Error(`Schema path "${De(t,m)}" is inval\
|
|
244
|
+
id because array segments must use numeric indexes.`);let f=Number(m),h=De(t,f),w=i[m],I=w.self===!0,S=ds(w);if(this._fieldToBeSkipped(
|
|
245
|
+
h,s))continue;if(!Object.hasOwn(l,f)){I&&a.rejectExplicitUndefined&&P(u,h,this._typeError(h).errorObject);continue}let d=l[f];
|
|
246
|
+
if(d===void 0){I&&a.rejectExplicitUndefined&&P(u,h,this._typeError(h).errorObject);continue}if(o.kind==="schema"){if(I){
|
|
247
|
+
let E=o.schema._validateWithOperation("replace",o.schema.operations.replace,d,it(s,h));_r(E.validatedObject)&&P(c,f,E.validatedObject),
|
|
248
|
+
this._mergeErrors(u,ot(E.errors,h));continue}if(!S)continue;let y=o.schema._validateSelectedTree(w.children,d,it(s,h),{...a,
|
|
249
|
+
operationName:"replace",operation:o.schema.operations.replace,defaultedFields:new Set});_r(y.validatedObject)&&P(c,f,y.validatedObject),
|
|
250
|
+
this._mergeErrors(u,ot(y.errors,h));continue}let p=this._buildArrayItemSettings(o.definition,a),_=[d];if(I){let y=this._normalizeAndValidateValue(
|
|
251
|
+
o.definition,d,h,_,0,l,s,p);Object.hasOwn(_,0)&&_[0]!==void 0?P(c,f,_[0]):_[0]===null&&P(c,f,null),this._mergeErrors(u,y);
|
|
252
|
+
continue}if(!S)continue;let b=this._castValue(o.definition,d,h,_,0,l,s,p);if(Object.keys(b.errors).length>0){this._mergeErrors(
|
|
253
|
+
u,b.errors);continue}if(!b.shouldContinue)continue;let v=this._validateSelectedDescendants(o.definition,w.children,h,_,0,
|
|
254
|
+
s,p);_r(_[0])&&P(c,f,_[0]),this._mergeErrors(u,v)}return u}validateWith(t,r,n={}){if(!Object.hasOwn(this.operations,t))throw new Error(
|
|
250
255
|
`Unknown operation "${t}".`);let o=this.operations[t];return this._assertPlainObjectInput(t,r),this._validateWithOperation(
|
|
251
|
-
t,o,r,n)}validateAt(t,r,n={}){this._assertPlainObjectInput("validateAt",r);let o=
|
|
252
|
-
_resolvePathValidationRequest(n),c=this._validateSelectedTree(
|
|
256
|
+
t,o,r,n)}validateAt(t,r,n={}){this._assertPlainObjectInput("validateAt",r);let o=Fn(t),{operationName:i,operation:s,validationOptions:a}=this.
|
|
257
|
+
_resolvePathValidationRequest(n),c=this._validateSelectedTree(ms([t]),r,a,this._buildOperationSettings(i,s,r));return{validatedValue:Cd(
|
|
253
258
|
c.validatedObject,o),errors:c.errors}}validatePaths(t,r,n={}){if(this._assertPlainObjectInput("validatePaths",r),!Array.
|
|
254
259
|
isArray(t)||t.length===0)throw new Error("validatePaths() expects a non-empty array of schema paths.");let{operationName:o,
|
|
255
|
-
operation:i,validationOptions:s}=this._resolvePathValidationRequest(n);return this._validateSelectedTree(
|
|
260
|
+
operation:i,validationOptions:s}=this._resolvePathValidationRequest(n);return this._validateSelectedTree(ms(t),r,s,this.
|
|
256
261
|
_buildOperationSettings(o,i,r))}_installOperationMethods(){for(let t of Object.keys(this.operations)){if(t in this)throw new Error(
|
|
257
262
|
`Operation name "${t}" is reserved and cannot be used as a schema method.`);this[t]=(r,n={})=>this.validateWith(t,r,n)}}toJsonSchema(t={}){
|
|
258
|
-
return
|
|
259
|
-
"")throw new Error("Field path must be a non-empty string.");let r=
|
|
260
|
-
let r=this.getFieldDefinition(t);return!r||typeof r.messages!="object"||r.
|
|
261
|
-
let n={};for(let o of Object.keys(t))Object.hasOwn(this.structure,
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
u,
|
|
265
|
-
|
|
263
|
+
return cs(this,t)}getFieldDefinitions(){return Hn.has(this)||Hn.set(this,Bn(this.structure)),Hn.get(this)}getFieldDefinition(t){
|
|
264
|
+
if(typeof t!="string"||t.trim()==="")throw new Error("Field path must be a non-empty string.");let r=qn(this,Fn(t.trim()));
|
|
265
|
+
return r===null?null:Bn(r)}getFieldMessages(t){let r=this.getFieldDefinition(t);return!r||typeof r.messages!="object"||r.
|
|
266
|
+
messages===null?Object.freeze({}):Bn(r.messages)}cleanup(t,r){let n={};for(let o of Object.keys(t))Object.hasOwn(this.structure,
|
|
267
|
+
o)&&this.structure[o][r]&&P(n,o,t[o]);return n}}});var hy,Dd,gy,Ud,Vd,Es,Gd,bs,vs,Ss=g(()=>{({parse:hy,stringify:Dd}=JSON),{keys:gy}=Object,Ud=String,Vd="string",Es="objec\
|
|
268
|
+
t",Gd=(e,t)=>t,bs=(e,t,r)=>{let n=Ud(t.push(r)-1);return e.set(r,n),n},vs=(e,t,r)=>{let n=t&&typeof t===Es?(u,m)=>u===""||
|
|
269
|
+
-1<t.indexOf(u)?m:void 0:t||Gd,o=new Map,i=[],s=[],a=+bs(o,i,n.call({"":e},"",e)),c=!a;for(;a<i.length;)c=!0,s[a]=Dd(i[a++],
|
|
270
|
+
l,r);return"["+s.join(",")+"]";function l(u,m){if(c)return c=!c,m;let f=n.call(this,u,m);switch(typeof f){case Es:if(f===
|
|
271
|
+
null)return f;case Vd:return o.get(f)||bs(o,i,f)}return f}}});function Fd(e){return e!==null&&(typeof e=="object"||typeof e=="function")&&typeof e.then=="function"}function Is(e){if(typeof e==
|
|
266
272
|
"number")return Number.isFinite(e)?e:null;if(typeof e=="bigint"){let t=Number(e);return Number.isSafeInteger(t)?t:null}if(typeof e==
|
|
267
|
-
"string"){let t=e.trim();if(t==="")return null;let r=Number(t);return Number.isFinite(r)?r:null}return null}function
|
|
273
|
+
"string"){let t=e.trim();if(t==="")return null;let r=Number(t);return Number.isFinite(r)?r:null}return null}function Yn(e,t){
|
|
268
274
|
if(Object.is(e,t))return!0;if(e instanceof Date&&t instanceof Date)return e.getTime()===t.getTime();if(e instanceof RegExp&&
|
|
269
275
|
t instanceof RegExp)return e.source===t.source&&e.flags===t.flags;if(Array.isArray(e)||Array.isArray(t)){if(!Array.isArray(
|
|
270
|
-
e)||!Array.isArray(t)||e.length!==t.length)return!1;for(let o=0;o<e.length;o++)if(!
|
|
276
|
+
e)||!Array.isArray(t)||e.length!==t.length)return!1;for(let o=0;o<e.length;o++)if(!Yn(e[o],t[o]))return!1;return!0}if(e===
|
|
271
277
|
null||t===null||typeof e!="object"||typeof t!="object"||Object.getPrototypeOf(e)!==Object.getPrototypeOf(t))return!1;let r=Object.
|
|
272
|
-
keys(e),n=Object.keys(t);if(r.length!==n.length)return!1;for(let o of r)if(!Object.hasOwn(t,o)||!
|
|
273
|
-
return!0}var
|
|
274
|
-
no","n","off"]);
|
|
278
|
+
keys(e),n=Object.keys(t);if(r.length!==n.length)return!1;for(let o of r)if(!Object.hasOwn(t,o)||!Yn(e[o],t[o]))return!1;
|
|
279
|
+
return!0}var Hd,zd,qd,Ts,As=g(()=>{Ss();hr();kn();tt();Hd=new Set(["true","1","yes","y","on"]),zd=new Set(["false","0","\
|
|
280
|
+
no","n","off"]);qd={install(e){let{addType:t,addValidator:r}=e;t("none",n=>n.value),t("file",n=>{let o=n.value;o==null&&
|
|
275
281
|
n.throwTypeError();let i=typeof o;if(i==="string"||i==="number"||i==="boolean"){let s=o.toString();return n.definition.noTrim?
|
|
276
282
|
s:s.trim()}n.throwTypeError()}),t("string",n=>{let o=n.value;if(o==null)return"";let i=typeof o;if(i==="string"||i==="nu\
|
|
277
283
|
mber"||i==="boolean"){let s=o.toString();return n.definition.noTrim?s:s.trim()}n.throwTypeError()}),t("blob",n=>n.value),
|
|
278
|
-
t("number",n=>{let o=
|
|
279
|
-
!Number.isInteger(o))&&n.throwTypeError(),o}),t("epochMilliseconds",n=>{let o=
|
|
280
|
-
o}),t("epochSeconds",n=>{let o=
|
|
281
|
-
n.fieldName);return
|
|
282
|
-
"time",n=>{let o=
|
|
283
|
-
type==="array"&&!Array.isArray(n.value)?[n.value]:n.value),t("object",n=>(
|
|
284
|
-
|
|
284
|
+
t("number",n=>{let o=Is(n.value);return o===null&&n.throwTypeError(),o}),t("integer",n=>{let o=Is(n.value);return(o===null||
|
|
285
|
+
!Number.isInteger(o))&&n.throwTypeError(),o}),t("epochMilliseconds",n=>{let o=Cn(n.value,864e13);return o===null&&n.throwTypeError(),
|
|
286
|
+
o}),t("epochSeconds",n=>{let o=Cn(n.value,864e10);return o===null&&n.throwTypeError(),o}),t("dateTime",n=>{let o=Rt(n.definition,
|
|
287
|
+
n.fieldName);return es(n.value,o)||n.throwTypeError(),n.value}),t("date",n=>(Qi(n.value)||n.throwTypeError(),n.value)),t(
|
|
288
|
+
"time",n=>{let o=Rt(n.definition,n.fieldName);return Zi(n.value,o)||n.throwTypeError(),n.value}),t("array",n=>n.definition.
|
|
289
|
+
type==="array"&&!Array.isArray(n.value)?[n.value]:n.value),t("object",n=>(Y(n.value)||n.throwTypeError(),n.value)),t("se\
|
|
290
|
+
rialize",n=>{try{return JSON.stringify(n.value)}catch{try{return vs(n.value)}catch{n.throwTypeError()}}}),t("boolean",n=>{
|
|
285
291
|
if(typeof n.value=="boolean")return n.value;if(typeof n.value=="number"){if(n.value===1)return!0;if(n.value===0)return!1;
|
|
286
292
|
n.throwTypeError()}if(typeof n.value=="bigint"){if(n.value===1n)return!0;if(n.value===0n)return!1;n.throwTypeError()}if(typeof n.
|
|
287
293
|
value=="string"){let o=String(n.definition.stringFalseWhen||"false").trim().toLowerCase(),i=String(n.definition.stringTrueWhen||
|
|
288
|
-
"true").trim().toLowerCase(),s=n.value.trim().toLowerCase(),a=new Set([...
|
|
294
|
+
"true").trim().toLowerCase(),s=n.value.trim().toLowerCase(),a=new Set([...zd,o]),c=new Set([...Hd,i]);if(a.has(s))return!1;
|
|
289
295
|
if(c.has(s))return!0}n.throwTypeError()}),t("id",n=>{if(typeof n.value=="number"){if(Number.isSafeInteger(n.value)&&n.value>
|
|
290
296
|
0)return n.value;n.throwTypeError()}if(typeof n.value=="bigint"){if(n.value>0n&&n.value<=BigInt(Number.MAX_SAFE_INTEGER))
|
|
291
297
|
return Number(n.value);n.throwTypeError()}if(typeof n.value=="string"){let o=n.value.trim();/^[1-9][0-9]*$/.test(o)||n.throwTypeError();
|
|
292
298
|
let i=Number(o);return Number.isSafeInteger(i)||n.throwTypeError(),i}n.throwTypeError()}),r("minLength",n=>{n.value!==void 0&&
|
|
293
299
|
n.definition.type==="string"&&n.value.toString&&n.value.toString().length<n.parameterValue&&n.throwParamError("MIN_LENGT\
|
|
294
300
|
H",`Length must be at least ${n.parameterValue} characters.`,{min:n.parameterValue,actual:n.value.toString().length})}),
|
|
295
|
-
r("min",n=>{n.value!==void 0&&
|
|
301
|
+
r("min",n=>{n.value!==void 0&&rt(n.definition)&&typeof n.value=="number"&&n.value<n.parameterValue&&n.throwParamError("M\
|
|
296
302
|
IN_VALUE",`Value must be at least ${n.parameterValue}.`,{min:n.parameterValue,actual:n.value})}),r("maxLength",n=>{n.value!==
|
|
297
303
|
void 0&&n.definition.type==="string"&&n.value.toString&&n.value.toString().length>n.parameterValue&&n.throwParamError("M\
|
|
298
304
|
AX_LENGTH",`Length must be no more than ${n.parameterValue} characters.`,{max:n.parameterValue,actual:n.value.toString().
|
|
299
|
-
length})}),r("max",n=>{n.value!==void 0&&
|
|
305
|
+
length})}),r("max",n=>{n.value!==void 0&&rt(n.definition)&&typeof n.value=="number"&&n.value>n.parameterValue&&n.throwParamError(
|
|
300
306
|
"MAX_VALUE",`Value must be no more than ${n.parameterValue}.`,{max:n.parameterValue,actual:n.value})}),r("enum",n=>{if(!Array.
|
|
301
|
-
isArray(n.parameterValue))throw new Error(`Enum for ${n.fieldName} must be an array.`);n.parameterValue.some(i=>
|
|
307
|
+
isArray(n.parameterValue))throw new Error(`Enum for ${n.fieldName} must be an array.`);n.parameterValue.some(i=>Yn(i,n.value))||
|
|
302
308
|
n.throwParamError("ENUM_VALUE","Value must match one of the allowed enum values.",{allowed:n.parameterValue})}),r("patte\
|
|
303
309
|
rn",n=>{if(n.value===void 0||n.definition.type!=="string"||typeof n.value!="string")return;let o=n.parameterValue,i=o instanceof
|
|
304
310
|
RegExp?new RegExp(o.source,o.flags):typeof o=="string"?new RegExp(o):null;if(!i)throw new Error(`Pattern for ${n.fieldName}\
|
|
@@ -306,144 +312,148 @@ RegExp?new RegExp(o.source,o.flags):typeof o=="string"?new RegExp(o):null;if(!i)
|
|
|
306
312
|
{pattern:i.source})}),r("strictBoolean",n=>{if(n.parameterValue){if(n.definition.type!=="boolean")throw new Error(`stric\
|
|
307
313
|
tBoolean can only be used on boolean fields (${n.fieldName}).`);typeof n.valueBeforeCast!="boolean"&&n.throwParamError("\
|
|
308
314
|
STRICT_BOOLEAN","Value must be a boolean.")}}),r("validator",n=>{if(typeof n.parameterValue!="function")throw new Error(
|
|
309
|
-
`Validator for ${n.fieldName} must be a function.`);let o=n.parameterValue(n.value,n.object,n);if(
|
|
315
|
+
`Validator for ${n.fieldName} must be a function.`);let o=n.parameterValue(n.value,n.object,n);if(Fd(o))throw new Error(
|
|
310
316
|
`Custom validator for "${n.fieldName}" must be synchronous.`);typeof o=="string"&&n.throwParamError("CUSTOM_VALIDATOR_FA\
|
|
311
317
|
ILED",o)}),r("uppercase",n=>{if(typeof n.value=="string")return n.value.toUpperCase()}),r("lowercase",n=>{if(typeof n.value==
|
|
312
318
|
"string")return n.value.toLowerCase()}),r("length",n=>{if(typeof n.value=="string")return n.value.substr(0,n.parameterValue);
|
|
313
319
|
Number.isInteger(Number(n.valueBeforeCast))&&String(n.valueBeforeCast).length>n.parameterValue&&n.throwParamError("RANGE\
|
|
314
320
|
_EXCEEDED","Numeric value is out of the allowed character range.",{max:n.parameterValue,actual:String(n.valueBeforeCast).
|
|
315
|
-
length})}),r("
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
"
|
|
323
|
-
|
|
324
|
-
|
|
321
|
+
length})}),r("minItems",n=>{Array.isArray(n.value)&&n.value.length<n.parameterValue&&n.throwParamError("MIN_ITEMS",`Must\
|
|
322
|
+
have at least ${n.parameterValue} items.`,{min:n.parameterValue,actual:n.value.length})}),r("maxItems",n=>{Array.isArray(
|
|
323
|
+
n.value)&&n.value.length>n.parameterValue&&n.throwParamError("MAX_ITEMS",`Must have no more than ${n.parameterValue} ite\
|
|
324
|
+
ms.`,{max:n.parameterValue,actual:n.value.length})}),r("notEmpty",n=>{n.parameterValue&&typeof n.value=="string"&&n.value===
|
|
325
|
+
""&&n.throwParamError("NOT_EMPTY","Field cannot be empty.")}),r("required",()=>{}),r("unsigned",()=>{}),r("precision",()=>{}),
|
|
326
|
+
r("scale",()=>{}),r("temporalPrecision",n=>{if(n.definition.type!=="time"&&n.definition.type!=="dateTime")throw new Error(
|
|
327
|
+
`temporalPrecision can only be used on time or dateTime fields (${n.fieldName}).`)}),r("nullable",()=>{}),r("nullOnEmpty",
|
|
328
|
+
()=>{}),r("defaultTo",()=>{})}},Ts=qd});var Os=g(()=>{Nt()});function Wd(e,t,r){if(typeof r!="function")throw new Error(`Type handler for '${t}' must be a function.`);P(e,t,r)}function Yd(e,t,r){
|
|
329
|
+
if(typeof r!="function")throw new Error(`Validator handler for '${t}' must be a function.`);P(e,t,r)}function Sr(e={}){let t=Object.
|
|
330
|
+
create(null);for(let[r,n]of Object.entries(e))P(t,r,n);return t}function Ps(e,t){if(typeof e.install!="function")throw new Error(
|
|
331
|
+
"Plugin must have an install method.");e.install(t)}function Rs(e,t,r){Cs.set(e,t),ks.set(e,r),Object.defineProperty(e,xs,
|
|
332
|
+
{value:Object.freeze({getTypes:()=>t,getValidators:()=>r}),enumerable:!1,configurable:!1,writable:!1})}function Jd(e){if(!e||
|
|
333
|
+
typeof e!="object"&&typeof e!="function")return null;let t=Cs.get(e),r=ks.get(e);if(t&&r)return{types:t,validators:r};let n=e[xs];
|
|
325
334
|
return n&&typeof n.getTypes=="function"&&typeof n.getValidators=="function"?{types:n.getTypes(),validators:n.getValidators()}:
|
|
326
335
|
typeof e=="object"&&e.types&&typeof e.types=="object"&&e.validators&&typeof e.validators=="object"&&typeof e.create=="fu\
|
|
327
336
|
nction"&&typeof e.replace=="function"&&typeof e.patch=="function"&&typeof e.toJsonSchema=="function"?{types:e.types,validators:e.
|
|
328
|
-
validators}:null}function
|
|
329
|
-
|
|
330
|
-
conflicting ${r} "${n}".`)
|
|
331
|
-
t)};let o=Object.create(null),i=Object.create(null);for(let s of n){let a=
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
let c=new
|
|
335
|
-
|
|
336
|
-
{types:a.types,validators:a.validators,installCore:!1})},r&&
|
|
337
|
-
|
|
338
|
-
|
|
337
|
+
validators}:null}function Kd(e){return e.length===1&&Array.isArray(e[0])?e[0]:e}function Ns(e,t,r){for(let[n,o]of Object.
|
|
338
|
+
entries(t)){if(Object.hasOwn(e,n)&&e[n]!==o){if(vr.has(o))continue;if(!vr.has(e[n]))throw new Error(`Cannot merge schema\
|
|
339
|
+
factories with conflicting ${r} "${n}".`)}P(e,n,o)}}function Xd(e,t,r){let n=Kd(r).filter(Boolean);if(n.length<1)return{
|
|
340
|
+
types:Sr(e),validators:Sr(t)};let o=Object.create(null),i=Object.create(null);for(let s of n){let a=Jd(s);if(!a)throw new Error(
|
|
341
|
+
"Factory sources must be schema instances or schema factories created by json-rest-schema.");Ns(o,a.types,"type"),Ns(i,a.
|
|
342
|
+
validators,"validator")}return{types:o,validators:i}}function $s({types:e={},validators:t={},installCore:r=!0}={}){let n=Sr(
|
|
343
|
+
e),o=Sr(t),i=(s,a={})=>{let c=new st(s,n,o,a.operations);return Rs(c,n,o),c};return Rs(i,n,o),i.addType=(s,a)=>{Wd(n,s,a)},
|
|
344
|
+
i.addValidator=(s,a)=>{Yd(o,s,a)},i.use=s=>{Ps(s,{addType:i.addType,addValidator:i.addValidator})},i.createFactory=(...s)=>{
|
|
345
|
+
let a=Xd(n,o,s);return $s({types:a.types,validators:a.validators,installCore:!1})},r&&Ps(Ts,{addType:(s,a)=>{vr.add(a),i.
|
|
346
|
+
addType(s,a)},addValidator:(s,a)=>{vr.add(a),i.addValidator(s,a)}}),i}var Cs,ks,xs,vr,$,Ue=g(()=>{_s();As();Os();Nt();Cs=
|
|
347
|
+
new WeakMap,ks=new WeakMap,xs=Symbol.for("json-rest-schema.registry-metadata"),vr=new WeakSet;$=$s({installCore:!0})});var My,js=g(()=>{Ue();G();My=Object.freeze({schema:$({}),mode:"replace"})});var Ls=g(()=>{G();Gi();pr();js()});function ep(e){return String(e||"").trim().toLowerCase()}function Xn(e,t){let r=ep(e);if(!Ms.test(r))throw new TypeError(
|
|
348
|
+
`${t} must match ${Ms.toString()}.`);return r}function Jn(e,t){if(e==null)return Object.freeze({});if(!B(e))throw new TypeError(
|
|
339
349
|
`${t} must be an object mapping local names to capability ids.`);let r={},n=new Set;for(let[o,i]of Object.entries(e)){let s=String(
|
|
340
|
-
o||"").trim();if(!
|
|
350
|
+
o||"").trim();if(!Zd.test(s))throw new TypeError(`${t} local name "${s}" must be a JavaScript identifier.`);let a=Xn(i,`${t}\
|
|
341
351
|
.${s}`);if(n.has(a))throw new TypeError(`${t} declares capability "${a}" more than once.`);n.add(a),r[s]=a}return Object.
|
|
342
|
-
freeze(r)}function
|
|
352
|
+
freeze(r)}function tp(e,t,r){if(e==null)return Object.freeze({});if(!B(e))throw new TypeError(`${r}.hints must be an obj\
|
|
343
353
|
ect mapping required capability ids to what to register.`);let n=new Set(Object.values(t)),o={};for(let[i,s]of Object.entries(
|
|
344
|
-
e)){let a=
|
|
354
|
+
e)){let a=Xn(i,`${r}.hints key`);if(!n.has(a))throw new TypeError(`${r}.hints names "${a}", which the provider does not \
|
|
345
355
|
require.`);if(typeof s!="string"||!s.trim())throw new TypeError(`${r}.hints["${a}"] must be the text that says what to r\
|
|
346
|
-
egister.`);o[a]=s.trim()}return Object.freeze(o)}function
|
|
356
|
+
egister.`);o[a]=s.trim()}return Object.freeze(o)}function rp(e){let t=new Map;for(let[r,n]of Object.entries(e))for(let o of Object.
|
|
347
357
|
keys(n)){if(t.has(o))throw new TypeError(`Provider local name "${o}" is declared by both ${t.get(o)} and ${r}.`);t.set(o,
|
|
348
|
-
r)}}function
|
|
349
|
-
ovided.`);return e}function
|
|
350
|
-
let c=
|
|
351
|
-
provides:m});let f=
|
|
352
|
-
optional:
|
|
353
|
-
G();
|
|
354
|
-
tration is closed after the first payload is resolved.");let
|
|
355
|
-
is required.");if(typeof
|
|
356
|
-
|
|
357
|
-
isFinite(c)?Number(c):0,contribute:
|
|
358
|
-
(
|
|
358
|
+
r)}}function Kn(e,t){if(e==null)return null;if(typeof e!="function")throw new TypeError(`${t} must be a function when pr\
|
|
359
|
+
ovided.`);return e}function Ir({id:e,requires:t={},optional:r={},provides:n={},hints:o={},setup:i,boot:s=null,shutdown:a=null}={}){
|
|
360
|
+
let c=Xn(e,"Provider id"),l=Jn(t,`${c}.requires`),u=Jn(r,`${c}.optional`),m=Jn(n,`${c}.provides`);rp({requires:l,optional:u,
|
|
361
|
+
provides:m});let f=Kn(i,`${c}.setup`);if(!f)throw new TypeError(`${c}.setup is required.`);return Object.freeze({id:c,requires:l,
|
|
362
|
+
optional:u,provides:m,hints:tp(o,l,c),setup:f,boot:Kn(s,`${c}.boot`),shutdown:Kn(a,`${c}.shutdown`)})}var Ms,Zd,Qn=g(()=>{
|
|
363
|
+
G();Ms=/^[a-z][a-z0-9_.-]*$/u,Zd=/^[A-Za-z_$][A-Za-z0-9_$]*$/u});var Ds,Us=g(()=>{Ds="public"});var Vs=g(()=>{});var Bs=g(()=>{G()});var np,Hs,zs=g(()=>{Vs();Bs();np="/api",Hs=`${np}/bootstrap`});function Zn(){let e=[],t=new Set,r=!1;function n({id:a,order:c=0,contribute:l}={}){if(r)throw new Error("Bootstrap regis\
|
|
364
|
+
tration is closed after the first payload is resolved.");let u=V(a);if(!u)throw new TypeError("Bootstrap contributor id \
|
|
365
|
+
is required.");if(typeof l!="function")throw new TypeError(`Bootstrap contributor "${u}" requires contribute().`);if(t.has(
|
|
366
|
+
u))throw new Error(`Bootstrap contributor "${u}" is duplicated.`);return t.add(u),e.push(Object.freeze({id:u,order:Number.
|
|
367
|
+
isFinite(c)?Number(c):0,contribute:l})),s}async function o(a={}){r=!0;let c={},l=e.map((u,m)=>({entry:u,index:m})).sort(
|
|
368
|
+
(u,m)=>u.entry.order-m.entry.order||u.index-m.index).map(({entry:u})=>u);for(let u of l){let m=await u.contribute(Object.
|
|
359
369
|
freeze({...B(a)?a:{},payload:Object.freeze({...c})}));c={...c,...B(m)?m:{}}}return Object.freeze(c)}function i(){return Object.
|
|
360
370
|
freeze({sealed:r,contributorIds:Object.freeze(e.map(a=>a.id).sort())})}let s=Object.freeze({register:n,resolve:o,diagnostics:i});
|
|
361
|
-
return s}var
|
|
362
|
-
untime.bootstrap"},setup({http:e}){let t=
|
|
371
|
+
return s}var eo=g(()=>{G()});var op,Fs=g(()=>{Qn();Us();zs();eo();op=Ir({id:"runtime.bootstrap",requires:{http:"runtime.http"},provides:{bootstrap:"r\
|
|
372
|
+
untime.bootstrap"},setup({http:e}){let t=Zn();return e.router.register("GET",Hs,{auth:Ds,meta:{tags:["bootstrap"],summary:"\
|
|
363
373
|
Resolve app bootstrap payload"}},async(r,n)=>{n.code(200).send(await t.resolve({request:r,reply:n,query:r.query||{}}))}),
|
|
364
|
-
{bootstrap:t}}})});function
|
|
374
|
+
{bootstrap:t}}})});function ip(e){if(!B(e))throw new TypeError("Event listener must be an object.");let t=String(e.id||"").trim();if(!t)throw new TypeError(
|
|
365
375
|
"Event listener id is required.");if(typeof e.handle!="function")throw new TypeError(`Event listener "${t}" requires han\
|
|
366
376
|
dle().`);if(e.matches!=null&&typeof e.matches!="function")throw new TypeError(`Event listener "${t}" matches must be a f\
|
|
367
|
-
unction when provided.`);return Object.freeze({id:t,handle:e.handle,matches:e.matches??null})}function
|
|
377
|
+
unction when provided.`);return Object.freeze({id:t,handle:e.handle,matches:e.matches??null})}function sp(e){if(!B(e))throw new TypeError(
|
|
368
378
|
"Published event must be an object.");let t=String(e.type||"").trim();if(!t)throw new TypeError("Published event type is\
|
|
369
|
-
required.");return Object.freeze({...e,type:t})}function
|
|
370
|
-
throw new Error(`Event listener "${a.id}" is duplicated.`);return t.add(a.id),e.push(a),i}async function n(s){let a=
|
|
379
|
+
required.");return Object.freeze({...e,type:t})}function to(){let e=[],t=new Set;function r(s){let a=ip(s);if(t.has(a.id))
|
|
380
|
+
throw new Error(`Event listener "${a.id}" is duplicated.`);return t.add(a.id),e.push(a),i}async function n(s){let a=sp(s);
|
|
371
381
|
for(let c of e)c.matches&&c.matches(a)!==!0||await c.handle(a);return a}function o(){return Object.freeze({listenerIds:Object.
|
|
372
|
-
freeze(e.map(s=>s.id))})}let i=Object.freeze({register:r,publish:n,diagnostics:o});return i}var
|
|
382
|
+
freeze(e.map(s=>s.id))})}let i=Object.freeze({register:r,publish:n,diagnostics:o});return i}var ro=g(()=>{G()});var ap,qs=g(()=>{Qn();ro();ap=Ir({id:"runtime.events",provides:{events:"runtime.events"},setup(){return{events:to()}}})});var Tr=g(()=>{pr();Vi();Ls();Fs();eo();qs();ro()});var Ws=g(()=>{});function Ys(e,t={}){let{missingStatus:r=404}=t,n=e?.errors?.[0]?.code||e?.code||"";return n==="vibe64_session_not_found"?
|
|
373
383
|
r:n.startsWith("vibe64_invalid")?400:n==="vibe64_command_requires_terminal"||n==="vibe64_agent_write_mode_busy"||n==="vi\
|
|
374
384
|
be64_agent_attachment_session_unavailable"||n==="vibe64_project_not_selected"||n==="vibe64_project_not_ready"||n==="vibe\
|
|
375
385
|
64_project_source_lock_timeout"||n==="vibe64_development_database_scope_busy"||n==="vibe64_project_session_policy_lock_t\
|
|
376
386
|
imeout"||n==="vibe64_session_creation_limit"||n==="vibe64_workspace_setup_retry_not_available"||n==="vibe64_workspace_se\
|
|
377
|
-
tup_running"?409:e?.ok===!1?400:200}var
|
|
378
|
-
|
|
379
|
-
if(!
|
|
380
|
-
let n=String(t.value||"").trim(),o=r===
|
|
381
|
-
64_preview_identity_selector_missing");if(r===
|
|
382
|
-
nvalid.","vibe64_preview_identity_email_invalid");if(r!==
|
|
383
|
-
alid.":"Preview identity user id is invalid.",r===
|
|
384
|
-
er_id_invalid");return{type:r,value:o}}function
|
|
387
|
+
tup_running"?409:e?.ok===!1?400:200}var Js=g(()=>{});function Ve(e,t,r={}){let{status:n=Ys({ok:!1,code:t}),...o}=r;return new ae(n,e,{...o,code:t})}var Ks=g(()=>{Tr();G();Ws();
|
|
388
|
+
Js()});import cp from"node:crypto";function lp(e={}){let t=e&&typeof e=="object"&&!Array.isArray(e)?e:{},r=String(t.type||"").trim();
|
|
389
|
+
if(!ur.includes(r))throw Ve("Preview identity selector type is invalid.","vibe64_preview_identity_selector_type_invalid");
|
|
390
|
+
let n=String(t.value||"").trim(),o=r===Ot?n.toLowerCase():n;if(!o)throw Ve("Preview identity selector is missing.","vibe\
|
|
391
|
+
64_preview_identity_selector_missing");if(r===Ot&&(!o.includes("@")||o.length>320))throw Ve("Preview identity email is i\
|
|
392
|
+
nvalid.","vibe64_preview_identity_email_invalid");if(r!==Ot&&o.length>256)throw Ve(r===lr?"Preview identity login is inv\
|
|
393
|
+
alid.":"Preview identity user id is invalid.",r===lr?"vibe64_preview_identity_login_invalid":"vibe64_preview_identity_us\
|
|
394
|
+
er_id_invalid");return{type:r,value:o}}function ea(e={}){let t=e&&typeof e=="object"&&!Array.isArray(e)?e:{};if(Object.hasOwn(
|
|
385
395
|
t,"subject"))throw Ve("Preview identity login requires an explicit application selector.","vibe64_preview_identity_subje\
|
|
386
|
-
ct_unsupported");let r=String(t.operation||
|
|
387
|
-
valid.","vibe64_preview_identity_operation_invalid");return{operation:r,...r===
|
|
388
|
-
|
|
389
|
-
guest","you"]),
|
|
390
|
-
function
|
|
391
|
-
command failed.",{code:t,params:n})}function
|
|
392
|
-
targetHref:n=""}=t,o=
|
|
393
|
-
"Application preview identity target must use HTTP.");return{operation:o.operation,protocol:
|
|
394
|
-
operation===
|
|
396
|
+
ct_unsupported");let r=String(t.operation||ue).trim();if(![ue,at].includes(r))throw Ve("Preview identity operation is in\
|
|
397
|
+
valid.","vibe64_preview_identity_operation_invalid");return{operation:r,...r===ue?{selector:lp(t.selector)}:{}}}var U_,ue,
|
|
398
|
+
at,Xs,Qs,Zs,V_,no=g(()=>{Ui();Ks();U_=cp.randomBytes(32),ue="login-as",at="logout",Xs="selector",Qs=new Set(["default","\
|
|
399
|
+
guest","you"]),Zs=32,V_=Object.freeze(["projectScope","sessionSourceRoot","sessionId","targetHref","terminalSessionId"])});var kt,oo=g(()=>{kt="vibe64_preview_token"});import{randomUUID as up}from"node:crypto";import{VIBE64_PREVIEW_IDENTITY_COMMAND_PROTOCOL as ta}from"@local/vibe64-genesis/server";
|
|
400
|
+
function ct(e="",t="vibe64_preview_identity_command_failed",r=502,n={}){return new ae(r,e||"Application preview identity\
|
|
401
|
+
command failed.",{code:t,params:n})}function pp(e={}){return{kind:Xs,selector:e.selector}}function na(e={},t={}){let{requestId:r=up(),
|
|
402
|
+
targetHref:n=""}=t,o=ea(e),i=String(n||"").trim(),s=new URL(i);if(!["http:","https:"].includes(s.protocol))throw new Error(
|
|
403
|
+
"Application preview identity target must use HTTP.");return{operation:o.operation,protocol:ta,requestId:String(r),...o.
|
|
404
|
+
operation===ue?{subject:pp(o)}:{},target:{href:s.toString(),origin:s.origin}}}function mp(e=[]){if(!Array.isArray(e))throw ct(
|
|
395
405
|
"Application preview identity command returned invalid cookies.","vibe64_preview_identity_command_cookies_invalid");let t=e;
|
|
396
|
-
if(t.length>
|
|
406
|
+
if(t.length>io)throw ct("Application preview identity command returned too many cookies.","vibe64_preview_identity_comma\
|
|
397
407
|
nd_cookies_too_many");return t.map((r,n)=>{let o=String(r||""),i=o.split(";",1)[0]||"",s=i.indexOf("="),a=(s<0?i:i.slice(
|
|
398
|
-
0,s)).trim();if(!o||Buffer.byteLength(o)>
|
|
399
|
-
test(o))throw
|
|
400
|
-
_cookie_invalid",502,{cookie:n+1});return o})}function
|
|
408
|
+
0,s)).trim();if(!o||Buffer.byteLength(o)>so||/[\r\n]/u.test(o)||s<1||!dp.test(a)||a===xt||a.startsWith(`${xt}_`)||/(?:^|;)\s*domain\s*=/iu.
|
|
409
|
+
test(o))throw ct(`Application preview identity command returned invalid cookie ${n+1}.`,"vibe64_preview_identity_command\
|
|
410
|
+
_cookie_invalid",502,{cookie:n+1});return o})}function fp(e=null){if(!e||typeof e!="object"||Array.isArray(e))return null;
|
|
401
411
|
let t={displayName:String(e.displayName||e.name||"").trim().slice(0,256),email:String(e.email||"").trim().toLowerCase().
|
|
402
412
|
slice(0,320),login:String(e.login||"").trim().slice(0,256),userId:String(e.userId||e.id||"").trim().slice(0,256),username:String(
|
|
403
|
-
e.username||"").trim().slice(0,256)};return Object.values(t).some(Boolean)?t:null}function
|
|
404
|
-
requestId:n=""}=t;if(!e||typeof e!="object"||Array.isArray(e))throw
|
|
405
|
-
valid JSON.","vibe64_preview_identity_command_json_invalid");if(e.protocol!==
|
|
406
|
-
typeof e.ok!="boolean")throw
|
|
407
|
-
eview_identity_command_response_invalid");let o=
|
|
413
|
+
e.username||"").trim().slice(0,256)};return Object.values(t).some(Boolean)?t:null}function hp(e={},t={}){let{operation:r=ue,
|
|
414
|
+
requestId:n=""}=t;if(!e||typeof e!="object"||Array.isArray(e))throw ct("Application preview identity command returned in\
|
|
415
|
+
valid JSON.","vibe64_preview_identity_command_json_invalid");if(e.protocol!==ta||String(e.requestId||"")!==String(n||"")||
|
|
416
|
+
typeof e.ok!="boolean")throw ct("Application preview identity command returned an invalid protocol response.","vibe64_pr\
|
|
417
|
+
eview_identity_command_response_invalid");let o=mp(e.setCookie);if(e.ok===!1){let a=Number(e.statusCode);return{code:String(
|
|
408
418
|
e.code||"vibe64_preview_identity_application_rejected").trim().slice(0,128),error:String(e.error||"Application preview i\
|
|
409
419
|
dentity was rejected.").trim().slice(0,2e3),ok:!1,setCookie:o,signedOut:e.signedOut===!0,statusCode:Number.isInteger(a)&&
|
|
410
|
-
a>=400&&a<600?a:400}}let i=r===
|
|
420
|
+
a>=400&&a<600?a:400}}let i=r===at||e.signedOut===!0,s=i?null:fp(e.identity);if(o.length<1||!i&&!s)throw ct("Application \
|
|
411
421
|
preview identity command did not return an authenticated browser session.","vibe64_preview_identity_command_session_miss\
|
|
412
|
-
ing");return{identity:s,ok:!0,setCookie:o,signedOut:i,statusCode:200}}var
|
|
413
|
-
512*1024,
|
|
422
|
+
ing");return{identity:s,ok:!0,setCookie:o,signedOut:i,statusCode:200}}var ra,io,so,xt,dp,Y_,oa=g(()=>{Tr();no();oo();ra=
|
|
423
|
+
512*1024,io=64,so=16*1024,xt=kt,dp=/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/u;Y_=Object.freeze({normalizePreviewIdentityCommandResponse:hp})});var ia=g(()=>{});function sa(e=""){return _p.find(t=>t.pattern.test(String(e)))?.kind||""}function vp(e){if(!be(e)||e.startsWith("/")||e.
|
|
414
424
|
includes("\\")||e.includes("\0"))return!1;let t=e.split("/");return t.every(r=>r&&r!=="."&&r!=="..")&&!t.includes("node_\
|
|
415
|
-
modules")}var
|
|
416
|
-
directory:"VIBE64_USAGE_RECORDING_DIR",sourceRoot:"VIBE64_USAGE_SOURCE_ROOT",targetKind:"VIBE64_USAGE_TARGET_KIND"}),
|
|
417
|
-
Object.freeze(["starting","recording","stopping","stopped","failed","unavailable"]),
|
|
418
|
-
it","request-limit","size-limit","target-exited","session-ended","error"]),
|
|
419
|
-
1024*1024,
|
|
425
|
+
modules")}var gp,X_,wp,yp,ca,$t,Q_,Z_,eE,_p,Ep,bp,Ar,be,aa,tE,rE,la=g(()=>{gp="vibe64.usage-trace.v1",X_=Object.freeze({
|
|
426
|
+
directory:"VIBE64_USAGE_RECORDING_DIR",sourceRoot:"VIBE64_USAGE_SOURCE_ROOT",targetKind:"VIBE64_USAGE_TARGET_KIND"}),wp=
|
|
427
|
+
Object.freeze(["starting","recording","stopping","stopped","failed","unavailable"]),yp=Object.freeze(["person","time-lim\
|
|
428
|
+
it","request-limit","size-limit","target-exited","session-ended","error"]),ca=Object.freeze(["nodejs","python","php"]),$t=
|
|
429
|
+
1024*1024,Q_=Object.freeze({durationMs:600*1e3,capturedRequests:2e3,hitsBytesPerProcess:16*$t,hitsBytesPerRecording:32*$t,
|
|
420
430
|
proxyRequestLines:2e4,interactions:500,bufferedBytesPerProcess:64*$t,flushIntervalMs:1e3,flushEntries:2e3,traceLineBytes:64*
|
|
421
|
-
1024,indexBytes:4*$t,plumbingShare:.8,plumbingMinimumRequests:3}),
|
|
422
|
-
60*1e3}),
|
|
431
|
+
1024,indexBytes:4*$t,plumbingShare:.8,plumbingMinimumRequests:3}),Z_=Object.freeze({maxRecordings:10,maxBytes:64*$t,maxAgeMs:10080*
|
|
432
|
+
60*1e3}),eE=Object.freeze(["click","enter","submit"]),_p=Object.freeze([Object.freeze({kind:"request",pattern:/^r_[0-9]{6}$/u}),
|
|
423
433
|
Object.freeze({kind:"local-request",pattern:/^l_[0-9]+_[0-9]+$/u}),Object.freeze({kind:"run",pattern:/^run_[0-9]+$/u}),Object.
|
|
424
|
-
freeze({kind:"background",pattern:/^bg_[0-9]+$/u})]),
|
|
425
|
-
isSafeInteger(e)&&e>=0,be=e=>typeof e=="string"&&e.length>0,
|
|
426
|
-
e.column)&&e.column>0;
|
|
427
|
-
e.pid)&&e.pid>0&&be(e.startedAt),tracer:e=>
|
|
428
|
-
function:e=>
|
|
434
|
+
freeze({kind:"background",pattern:/^bg_[0-9]+$/u})]),Ep=/^sha256:[0-9a-f]{64}$/u,bp=Object.freeze(["ready","idle"]);Ar=e=>Number.
|
|
435
|
+
isSafeInteger(e)&&e>=0,be=e=>typeof e=="string"&&e.length>0,aa=e=>!!e&&Number.isSafeInteger(e.line)&&e.line>0&&Number.isSafeInteger(
|
|
436
|
+
e.column)&&e.column>0;tE=Object.freeze({header:e=>e.schema===gp&&ca.includes(e.runtime)&&be(e.runtimeVersion)&&Number.isSafeInteger(
|
|
437
|
+
e.pid)&&e.pid>0&&be(e.startedAt),tracer:e=>bp.includes(e.state),file:e=>Ar(e.fileIndex)&&vp(e.path)&&Ep.test(e.hash||""),
|
|
438
|
+
function:e=>Ar(e.functionIndex)&&Ar(e.fileIndex)&&typeof e.name=="string"&&aa(e.start)&&aa(e.end),scope:e=>sa(e.scope)===
|
|
429
439
|
e.kind&&be(e.startedAt)&&(e.endedAt===void 0||be(e.endedAt))&&(e.label===void 0||be(e.label)&&["local-request","run"].includes(
|
|
430
|
-
e.kind)),hits:e=>
|
|
440
|
+
e.kind)),hits:e=>sa(e.scope)!==""&&Array.isArray(e.counts)&&e.counts.every(t=>Array.isArray(t)&&t.length===2&&Ar(t[0])&&
|
|
431
441
|
(t[1]===null||Number.isSafeInteger(t[1])&&t[1]>0)),diagnostic:e=>be(e.code)&&(e.path===void 0||be(e.path)),truncated:e=>be(
|
|
432
|
-
e.reason)}),
|
|
433
|
-
return
|
|
442
|
+
e.reason)}),rE=Object.freeze({USAGE_RECORDING_STATES:wp,USAGE_RECORDING_STOP_REASONS:yp,USAGE_TRACER_RUNTIMES:ca})});function Sp(e=""){try{let t=new URL(e),r=t.protocol==="https:",n=t.port||(r?"443":"80");return`${r?"__Host-":""}${ua}_${n}`}catch{
|
|
443
|
+
return ua}}function Ip(e="",t={}){let{proxyOrigin:r="",targetOrigin:n=""}=t,o=String(e||"").trim();if(!o||!r||!n)return o;
|
|
434
444
|
try{let i=new URL(o,n),s=new URL(r),a=new URL(n);return a.protocol=s.protocol,i.origin!==n&&i.origin!==a.origin?o:(s.pathname=
|
|
435
|
-
i.pathname,s.search=
|
|
445
|
+
i.pathname,s.search=Tp(i.search),s.hash=i.hash,s.toString())}catch{return o}}function Tp(e=""){let t=String(e||"");if(!t||
|
|
436
446
|
t==="?")return"";let r=t.startsWith("?")?t.slice(1):t;if(!r)return"";let n=r.split("&").filter(o=>{let i=o.indexOf("="),
|
|
437
|
-
s=i<0?o:o.slice(0,i);return
|
|
438
|
-
String(e||"").replace(/\+/gu," "))}catch{return String(e||"")}}var
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
11",
|
|
442
|
-
73/"}),
|
|
443
|
-
identity:{displayName:"Admin",email:"admin@example.com",userId:"1"}}),
|
|
444
|
-
user_not_found",error:"No active user has that email.",statusCode:404,setCookie:[]}),
|
|
445
|
-
entity-command",title:"Preview identity command protocol",exampleRequest:
|
|
446
|
-
identity command protocol (\`${
|
|
447
|
+
s=i<0?o:o.slice(0,i);return Ap(s)!==kt});return n.length>0?`?${n.join("&")}`:""}function Ap(e=""){try{return decodeURIComponent(
|
|
448
|
+
String(e||"").replace(/\+/gu," "))}catch{return String(e||"")}}var ua,da,uE,pa=g(()=>{ia();la();oo();ua=kt,da=/^vibe64-launch-[a-f0-9]{12}$/u;
|
|
449
|
+
uE=Object.freeze({previewTokenCookieName:Sp,proxiedLocation:Ip})});import{VIBE64_PREVIEW_IDENTITY_COMMAND_PROTOCOL as Or}from"@local/vibe64-genesis/server";var ao,ma,co,fa,ha,ga,wa,ya=g(()=>{
|
|
450
|
+
no();oa();pa();ao=e=>JSON.stringify(e,null,2),ma=ur.map(e=>`\`${e}\``).join(", "),co="6f1c2a7e-3d4b-4c55-9a10-2b7d8e9f0a\
|
|
451
|
+
11",fa=na({operation:ue,selector:{type:"email",value:"admin@example.com"}},{requestId:co,targetHref:"http://127.0.0.1:51\
|
|
452
|
+
73/"}),ha=Object.freeze({protocol:Or,requestId:co,ok:!0,setCookie:["app_session=abc123; Path=/; HttpOnly; SameSite=Lax"],
|
|
453
|
+
identity:{displayName:"Admin",email:"admin@example.com",userId:"1"}}),ga=Object.freeze({protocol:Or,requestId:co,ok:!1,code:"\
|
|
454
|
+
user_not_found",error:"No active user has that email.",statusCode:404,setCookie:[]}),wa=Object.freeze([{name:"preview-id\
|
|
455
|
+
entity-command",title:"Preview identity command protocol",exampleRequest:fa,exampleResponses:[ha,ga],text:()=>`# Preview\
|
|
456
|
+
identity command protocol (\`${Or}\`)
|
|
447
457
|
|
|
448
458
|
An application-owned executable, declared under an Outputs web target's \`#### Preview identity\` block (grammar: \`vibe64-\
|
|
449
459
|
helper spec outputs\`), that signs the Preview browser in as an existing application account or signs it out. Vibe64 neve\
|
|
@@ -457,51 +467,51 @@ adds only the Enabled and Secret names, not the project's Env values, so the com
|
|
|
457
467
|
ration itself (for example its generated environment file). For an enabled run the declared Enabled environment name is \
|
|
458
468
|
\`true\` and the Secret environment name holds a fresh per-run secret. Keep the exchange disabled unless both are present;\
|
|
459
469
|
it is a development-preview control, never a production sign-in API.
|
|
460
|
-
- stdin: one JSON request line. stdout: one JSON response (at most ${
|
|
470
|
+
- stdin: one JSON request line. stdout: one JSON response (at most ${ra} bytes). Exit 0 after writing the response; a no\
|
|
461
471
|
n-zero exit or timeout fails the exchange. Write diagnostics to stderr.
|
|
462
472
|
- Use the same database and configuration as the server behind \`target.origin\` (for a test target, its test database).
|
|
463
473
|
- A JSKIT application's executable can call \`runManagedPreviewIdentityCommand\` from \`@jskit-ai/auth-web/server/managedPr\
|
|
464
474
|
eviewIdentity\`. Pass it the application's environment, this protocol and the Preview's launch hostnames, since it reads \
|
|
465
475
|
no environment on its own and its defaults are JSKIT's neutral protocol and loopback only: \`runManagedPreviewIdentityCom\
|
|
466
|
-
mand({ env: process.env, protocol: "${
|
|
476
|
+
mand({ env: process.env, protocol: "${Or}", localHostnames: [${da}] })\`.
|
|
467
477
|
|
|
468
478
|
## Request
|
|
469
479
|
|
|
470
|
-
- \`operation\`: \`${
|
|
480
|
+
- \`operation\`: \`${ue}\` or \`${at}\`.
|
|
471
481
|
- \`protocol\`, \`requestId\`: echo both in the response.
|
|
472
|
-
- \`subject\` (${
|
|
482
|
+
- \`subject\` (${ue} only): \`{"kind":"selector","selector":{"type":\u2026,"value":\u2026}}\` with type ${ma}. Email val\
|
|
473
483
|
ues arrive lowercased.
|
|
474
484
|
- \`target\`: \`{"href","origin"}\` of the application page the cookies are for.
|
|
475
485
|
|
|
476
486
|
\`\`\`json
|
|
477
|
-
${
|
|
487
|
+
${ao(fa)}
|
|
478
488
|
\`\`\`
|
|
479
489
|
|
|
480
490
|
## Response
|
|
481
491
|
|
|
482
492
|
- Always: \`protocol\`, the same \`requestId\`, boolean \`ok\`, and \`setCookie\`: an array of complete Set-Cookie header values\
|
|
483
|
-
(at most ${
|
|
493
|
+
(at most ${io}, each at most ${so} bytes, no line breaks, no \`Domain\` attribute, never named \`${xt}\` or \`${xt}_*\`)\
|
|
484
494
|
.
|
|
485
|
-
- \`ok: true\`: at least one cookie. For ${
|
|
486
|
-
\`, \`username\`. For ${
|
|
495
|
+
- \`ok: true\`: at least one cookie. For ${ue}, \`identity\` with at least one of \`displayName\`, \`email\`, \`login\`, \`userId\
|
|
496
|
+
\`, \`username\`. For ${at} (or \`"signedOut": true\`), the cookies that clear the session.
|
|
487
497
|
- \`ok: false\`: \`code\` (at most 128 characters), \`error\` (a person-readable reason, at most 2000), \`statusCode\` 400 throu\
|
|
488
498
|
gh 599 (default 400), optional \`signedOut\`, and \`setCookie\` (may be empty).
|
|
489
499
|
|
|
490
500
|
\`\`\`json
|
|
491
|
-
${
|
|
501
|
+
${ao(ha)}
|
|
492
502
|
\`\`\`
|
|
493
503
|
|
|
494
504
|
\`\`\`json
|
|
495
|
-
${
|
|
505
|
+
${ao(ga)}
|
|
496
506
|
\`\`\`
|
|
497
507
|
`},{name:"preview-identities",title:"Managed app identities",text:()=>`# Managed app identities
|
|
498
508
|
|
|
499
509
|
The ordered list of named existing application accounts that Preview and managed Playwright can sign in as through the a\
|
|
500
510
|
pplication's Preview identity command (\`vibe64-helper spec preview-identity-command\`).
|
|
501
511
|
|
|
502
|
-
- Each entry has a \`name\`, a selector \`type\` (${
|
|
503
|
-
e, start with a lowercase letter and use at most 64 lowercase letters, digits, \`_\` or \`-\`; ${[...
|
|
504
|
-
join(", ")} are reserved. At most ${
|
|
512
|
+
- Each entry has a \`name\`, a selector \`type\` (${ma}) and the application's \`value\` for that account. Names are uniqu\
|
|
513
|
+
e, start with a lowercase letter and use at most 64 lowercase letters, digits, \`_\` or \`-\`; ${[...Qs].map(e=>`\`${e}\``).
|
|
514
|
+
join(", ")} are reserved. At most ${Zs} entries; the first is the default.
|
|
505
515
|
- Entries are selectors only, never passwords. A saved entry does not prove that the account exists or can reach a page:\
|
|
506
516
|
verify the selected account's actual Preview access.
|
|
507
517
|
- Read the list and the Stack's declared types with \`vibe64-helper preview identities\`; \`vibe64-helper preview status\` s\
|
|
@@ -520,31 +530,31 @@ Entry shape:
|
|
|
520
530
|
\`\`\`json
|
|
521
531
|
{"name":"admin","type":"email","value":"admin@example.com"}
|
|
522
532
|
\`\`\`
|
|
523
|
-
`}])});var
|
|
524
|
-
function
|
|
525
|
-
cts:",...
|
|
526
|
-
`)}async function
|
|
533
|
+
`}])});var Ea={};xi(Ea,{__testables:()=>Cp,runAgentSpecCli:()=>Np});import{readFile as Pp}from"node:fs/promises";import{VIBE64_GENESIS_AGENT_SPECS as Rp}from"@local/vibe64-genesis/server/agentSpecs";
|
|
534
|
+
function _a(){let e=Math.max(...Pr.map(({name:t})=>t.length));return["Usage: vibe64 spec <name>","","Vibe64-owned contra\
|
|
535
|
+
cts:",...Pr.map(({name:t,title:r})=>` ${t.padEnd(e)} ${r}`)].join(`
|
|
536
|
+
`)}async function Np(e=[],{write:t=n=>process.stdout.write(`${n.trimEnd()}
|
|
527
537
|
`),writeError:r=n=>process.stderr.write(`${n.trimEnd()}
|
|
528
|
-
`)}={}){let[n]=e;if(!n||n==="--help"||n==="-h")return t(
|
|
538
|
+
`)}={}){let[n]=e;if(!n||n==="--help"||n==="-h")return t(_a()),0;let o=e.length===1&&Pr.find(i=>i.name===n);return o?(t(await o.
|
|
529
539
|
text()),0):(r(`Unknown Vibe64 spec: ${e.join(" ")}.
|
|
530
540
|
|
|
531
|
-
${
|
|
532
|
-
freeze([...
|
|
533
|
-
e",text:()=>
|
|
534
|
-
e))Ae(e[r],t);return Object.freeze(e)}var jt=g(()=>{});function
|
|
535
|
-
eate",context:r="schema definition.mode"}={}){let n=
|
|
536
|
-
call(n,"mode")?V(n.mode).toLowerCase():"";if(!i)return o;if(!
|
|
537
|
-
replace, patch.`);return i}function
|
|
538
|
-
getFieldMessages(r)):{}}function
|
|
539
|
-
e,r.join(".")))}function
|
|
540
|
-
return null;let n=V(r.message);if(!n)return null;let o=V(r.code);return o?{message:n,code:o,params:
|
|
541
|
-
function
|
|
542
|
-
Object.keys(s).length<1
|
|
543
|
-
params:{...i,...c.params}}:{message:c.message};let
|
|
544
|
-
message:
|
|
545
|
-
i,s]of Object.entries(r)){let a=V(i);if(!a)continue;if(typeof s=="string"){n[a]=s;continue}let{message:c,code:
|
|
546
|
-
a,s,t);n[a]=c,
|
|
547
|
-
["create","replace","patch"]),
|
|
541
|
+
${_a()}`),2)}var Op,Pr,Cp,ba=g(()=>{Di();ya();Op=new URL("./../server/lib/agentSpecCli.js",import.meta.url).href,Pr=Object.
|
|
542
|
+
freeze([...Rp,...wa,...Mi,{name:"training-content",title:"Teaching content format for vibe64 training validate and bundl\
|
|
543
|
+
e",text:()=>Pp(new URL("../../docs/training-content.md",Op),"utf8")}]);Cp=Object.freeze({VIBE64_AGENT_SPECS:Pr})});function Ae(e,t=new WeakSet){if(!e||typeof e!="object"||t.has(e))return e;t.add(e);for(let r of Object.getOwnPropertyNames(
|
|
544
|
+
e))Ae(e[r],t);return Object.freeze(e)}var jt=g(()=>{});function Rr(e){return!!e&&typeof e=="object"&&jp.every(t=>typeof e[t]=="function")}function Sa(e=null,{defaultMode:t="cr\
|
|
545
|
+
eate",context:r="schema definition.mode"}={}){let n=re(e),o=V(t).toLowerCase()||"create",i=Object.prototype.hasOwnProperty.
|
|
546
|
+
call(n,"mode")?V(n.mode).toLowerCase():"";if(!i)return o;if(!kp.has(i))throw new TypeError(`${r} must be one of: create,\
|
|
547
|
+
replace, patch.`);return i}function Ia(e=null,t=""){let r=V(t);if(!r)return{};let n=re(e);return Rr(n.schema)?re(n.schema.
|
|
548
|
+
getFieldMessages(r)):{}}function Lp(e=null,t=""){let r=V(t).split(".").filter(Boolean);return r.length<2?{}:(r.pop(),Ia(
|
|
549
|
+
e,r.join(".")))}function va(e,t){let r=t?e[t]:void 0;if(typeof r=="string"){let i=V(r);return i?{message:i}:null}if(!B(r))
|
|
550
|
+
return null;let n=V(r.message);if(!n)return null;let o=V(r.code);return o?{message:n,code:o,params:re(r.params)}:{message:n}}
|
|
551
|
+
function Mp(e,t,r=null){let n=V(t?.code).toUpperCase(),o=xp[n]||{},i=re(t?.params),s=Ia(r,e),a=n==="FIELD_NOT_ALLOWED"&&
|
|
552
|
+
Object.keys(s).length<1?Lp(r,e):s,c=va(a,o.messageKey)||va(a,"default");if(c)return c.code?{message:c.message,code:c.code,
|
|
553
|
+
params:{...i,...c.params}}:{message:c.message};let l=V(t?.message);if(l)return o.code?{message:l,code:o.code,params:i}:{
|
|
554
|
+
message:l};let u=V(t?.code);return u?{message:u}:{...$p,params:{}}}function lo(e={},t=null){let r=re(e),n={},o={};for(let[
|
|
555
|
+
i,s]of Object.entries(r)){let a=V(i);if(!a)continue;if(typeof s=="string"){n[a]=s;continue}let{message:c,code:l,params:u}=Mp(
|
|
556
|
+
a,s,t);n[a]=c,l&&(o[a]={code:l,params:u})}return{fieldErrors:n,fieldErrorCodes:o}}var kp,xp,$p,jp,uo=g(()=>{G();kp=new Set(
|
|
557
|
+
["create","replace","patch"]),xp=Object.freeze({REQUIRED:{messageKey:"required",code:"kernel.validation.field.required"},
|
|
548
558
|
TYPE_CAST_FAILED:{messageKey:"default",code:"kernel.validation.field.typeCastFailed"},NOT_NULLABLE:{messageKey:"default",
|
|
549
559
|
code:"kernel.validation.field.notNullable"},MIN_LENGTH:{messageKey:"minLength",code:"kernel.validation.field.minLength"},
|
|
550
560
|
MAX_LENGTH:{messageKey:"maxLength",code:"kernel.validation.field.maxLength"},MIN_ITEMS:{messageKey:"minItems",code:"kern\
|
|
@@ -554,23 +564,23 @@ messageKey:"pattern",code:"kernel.validation.field.pattern"},ENUM_VALUE:{message
|
|
|
554
564
|
.enumValue"},FIELD_NOT_ALLOWED:{messageKey:"additionalProperties",code:"kernel.validation.field.notAllowed"},CUSTOM_VALIDATOR_FAILED:{
|
|
555
565
|
messageKey:"validator",code:""},STRICT_BOOLEAN:{messageKey:"default",code:"kernel.validation.field.strictBoolean"},RANGE_EXCEEDED:{
|
|
556
566
|
messageKey:"default",code:"kernel.validation.field.rangeExceeded"},NOT_EMPTY:{messageKey:"default",code:"kernel.validati\
|
|
557
|
-
on.field.notEmpty"}})
|
|
558
|
-
reate","replace","patch","toJsonSchema"])});function
|
|
559
|
-
prototype.hasOwnProperty.call(e,"mode"))}function
|
|
560
|
-
if(!
|
|
561
|
-
call(n,"schema"))throw new TypeError(`${t}.schema is required.`);if(!
|
|
562
|
-
be a json-rest-schema schema instance.`);let o={schema:n.schema},i=V(r).toLowerCase();return o.mode=
|
|
563
|
-
"patch",context:`${t}.mode`}),Object.freeze(o)}function
|
|
564
|
-
e,{context:r,defaultMode:n});return o?o.schema[o.mode](t):null}var Lt=g(()=>{G();
|
|
565
|
-
freeze({schema:
|
|
566
|
-
|
|
567
|
-
e,o?{cause:o}:void 0);if(e===
|
|
567
|
+
on.field.notEmpty"}}),$p=Object.freeze({code:"kernel.validation.invalid",message:"Invalid value."}),jp=Object.freeze(["c\
|
|
568
|
+
reate","replace","patch","toJsonSchema"])});function Dp(e){return!!e&&typeof e=="object"&&!Array.isArray(e)&&(Object.prototype.hasOwnProperty.call(e,"schema")||Object.
|
|
569
|
+
prototype.hasOwnProperty.call(e,"mode"))}function Nr(e,{context:t="schema definition",defaultMode:r=""}={}){if(e==null)return null;
|
|
570
|
+
if(!Dp(e))throw new TypeError(`${t} must be a schema definition object.`);let n=re(e);if(!Object.prototype.hasOwnProperty.
|
|
571
|
+
call(n,"schema"))throw new TypeError(`${t}.schema is required.`);if(!Rr(n.schema))throw new TypeError(`${t}.schema must \
|
|
572
|
+
be a json-rest-schema schema instance.`);let o={schema:n.schema},i=V(r).toLowerCase();return o.mode=Sa(n,{defaultMode:i||
|
|
573
|
+
"patch",context:`${t}.mode`}),Object.freeze(o)}function po(e,t,{context:r="schema definition",defaultMode:n=""}={}){let o=Nr(
|
|
574
|
+
e,{context:r,defaultMode:n});return o?o.schema[o.mode](t):null}var Lt=g(()=>{G();uo()});var Ta=g(()=>{Ue();G();jt();Lt()});var Aa=g(()=>{Ue();jt();Lt()});var Up,Vp,Oa=g(()=>{Ue();Up=$({cursor:{type:"id",required:!1},limit:{type:"number",required:!1,min:1,unsigned:!0}}),Vp=Object.
|
|
575
|
+
freeze({schema:Up,mode:"patch"})});var Pa,Gp,Ra=g(()=>{Pa=Object.freeze({type:"string",pattern:"^(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d)?$",minLength:5}),
|
|
576
|
+
Gp=Object.freeze({...Pa,nullable:!0})});var Na=g(()=>{G()});function ka({message:e=Ca,fieldErrors:t=null,fieldErrorCodes:r=null,errors:n=null,cause:o,statusCode:i=null}={}){let s=new Error(
|
|
577
|
+
e,o?{cause:o}:void 0);if(e===Ca&&(s.messageCode="kernel.validation.schemaFailed",s.messageParams={}),Number.isInteger(i)&&
|
|
568
578
|
i>=400&&i<=599&&(s.statusCode=i),B(t)){let a=B(r)&&Object.keys(r).length>0?r:null;s.fieldErrors=t,a&&(s.fieldErrorCodes=
|
|
569
579
|
a),s.details={...s.details||{},fieldErrors:t,...a?{fieldErrorCodes:a}:{}}}else n!=null&&(s.details={...s.details||{},errors:n});
|
|
570
|
-
return s}function
|
|
571
|
-
e,t,{defaultMode:r==="output"?"replace":"patch",context:n}),{fieldErrors:s,fieldErrorCodes:a}=
|
|
572
|
-
s).length>0)throw
|
|
573
|
-
|
|
580
|
+
return s}function mo(e,t,{phase:r="input",context:n="schema definition",statusCode:o=null}={}){if(e==null)return t;let i=po(
|
|
581
|
+
e,t,{defaultMode:r==="output"?"replace":"patch",context:n}),{fieldErrors:s,fieldErrorCodes:a}=lo(i.errors,e);if(Object.keys(
|
|
582
|
+
s).length>0)throw ka({fieldErrors:s,fieldErrorCodes:a,statusCode:o});return i.validatedObject??t}var Ca,xa=g(()=>{G();Lt();
|
|
583
|
+
Ca="Schema validation failed."});var qE,$a=g(()=>{G();qE=new Map([{keyword:"required",code:"kernel.validation.required"},{keyword:"type",code:"kernel.val\
|
|
574
584
|
idation.type"},{keyword:"minLength",code:"kernel.validation.minLength"},{keyword:"maxLength",code:"kernel.validation.max\
|
|
575
585
|
Length"},{keyword:"minimum",code:"kernel.validation.minimum"},{keyword:"maximum",code:"kernel.validation.maximum"},{keyword:"\
|
|
576
586
|
exclusiveMinimum",code:"kernel.validation.exclusiveMinimum"},{keyword:"exclusiveMaximum",code:"kernel.validation.exclusi\
|
|
@@ -582,89 +592,89 @@ tion.maxItems"},{keyword:"additionalItems",code:"kernel.validation.additionalIte
|
|
|
582
592
|
kernel.validation.maxProperties"},{keyword:"additionalProperties",code:"kernel.validation.additionalProperties"},{keyword:"\
|
|
583
593
|
propertyNames",code:"kernel.validation.propertyNames"},{keyword:"oneOf",code:"kernel.validation.oneOf"},{keyword:"anyOf",
|
|
584
594
|
code:"kernel.validation.anyOf"},{keyword:"not",code:"kernel.validation.not"},{keyword:"if",code:"kernel.validation.if"}].
|
|
585
|
-
map(({keyword:e,code:t})=>[e,t]))});var
|
|
586
|
-
|
|
587
|
-
id must be a canonical positive integer string."}}}}),mode:"patch"})});var
|
|
588
|
-
let n=
|
|
589
|
-
s.`);return n}var N,M,H,
|
|
595
|
+
map(({keyword:e,code:t})=>[e,t]))});var ja,fo,Bp,Hp,La=g(()=>{Ue();jt();ja="^[1-9][0-9]*$",fo=Ae({type:"string",minLength:1,pattern:ja}),Bp=Ae({...fo,nullable:!0}),
|
|
596
|
+
Hp=Ae({schema:$({recordId:{...fo,required:!0,messages:{pattern:{code:"kernel.validation.recordIdInvalid",message:"Record\
|
|
597
|
+
id must be a canonical positive integer string."}}}}),mode:"patch"})});var Ma=g(()=>{G()});var Cr=g(()=>{Ue();An();Ta();Aa();Oa();Ra();Na();uo();Lt();xa();$a();La();Ma()});import{isDeepStrictEqual as zp}from"node:util";function xr(e,t){let r=Kp.get(e?.schemaVersion)||Ua;return ce(r,e,t)}function ce(e,t,r){
|
|
598
|
+
let n=mo({schema:e,mode:"create"},t,{context:r});if(!zp(t,n))throw new Error(`${r}: unknown fields or noncanonical value\
|
|
599
|
+
s.`);return n}var N,M,H,kr,Fp,qp,Da,Ua,Wp,Va,Yp,Jp,Kp,me,$r,jr,Ga,lt=g(()=>{Cr();N={type:"string",required:!0,noTrim:!0,
|
|
590
600
|
minLength:1,maxLength:256},M={...N,maxLength:64},H=(e,t=100)=>({type:"array",required:!0,maxLength:t,items:e,validator:r=>Array.
|
|
591
|
-
isArray(r)&&r.length>t?`Expected at most ${t} items.`:void 0}),
|
|
592
|
-
24),
|
|
601
|
+
isArray(r)&&r.length>t?`Expected at most ${t} items.`:void 0}),kr={type:"integer",required:!0,enum:[1]},Fp=H($({code:M}),
|
|
602
|
+
24),qp=$({id:M,kind:{...N,enum:["answer","practical"]},required:{type:"boolean",required:!0},rubric:N,evidence:{type:"ob\
|
|
593
603
|
ject",required:!1,schema:$({producer:{...N,enum:["workspace","colleague","exercise","code"]},operation:M,check:{...M,required:!1},
|
|
594
|
-
explanationRequired:{type:"boolean",required:!1},files:{...H(N,8),required:!1,minLength:1}})}})
|
|
604
|
+
explanationRequired:{type:"boolean",required:!1},files:{...H(N,8),required:!1,minLength:1}})}}),Da={code:M,title:N,prerequisites:Fp,
|
|
595
605
|
estimatedMinutes:{type:"integer",required:!0,min:1,max:180},visuals:H($({id:M,descriptor:N}),12),exercise:{type:"object",
|
|
596
606
|
required:!1,schema:$({kind:{...N,enum:["bundled"]},source:N,reuse:{...N,enum:["attempt","sequence"]},sequenceId:{...M,required:!1},
|
|
597
607
|
sequenceMode:{...N,required:!1,enum:["create","continue"]}})},checks:{...H($({id:M,file:N,assets:{...H(N,32),required:!1},
|
|
598
608
|
kind:{...N,required:!1,enum:["response","code"]},timeoutSeconds:{type:"integer",required:!1,min:1,max:60}}),12),required:!1},
|
|
599
609
|
appRoutes:{...H($({method:{...N,enum:["POST","PUT","PATCH","DELETE"]},path:{...N,maxLength:128,pattern:"^/[A-Za-z0-9._~:\
|
|
600
|
-
/-]*$"}}),16),required:!1}},
|
|
610
|
+
/-]*$"}}),16),required:!1}},Ua=$({schemaVersion:kr,...Da,document:N,assessments:H(qp,32)}),Wp=$({id:M,title:N,body:N,required:{
|
|
601
611
|
type:"boolean",required:!0},visual:{type:"object",required:!1,schema:$({id:M,play:{...H($({name:M,parameters:{type:"obje\
|
|
602
612
|
ct",required:!0}}),16),required:!1}})},guide:{type:"object",required:!1,schema:$({target:M,navigate:{type:"boolean",required:!1},
|
|
603
613
|
filePath:{...N,required:!1,maxLength:512},caption:{...N,required:!1}})},check:{type:"object",required:!0,schema:$({kind:{
|
|
604
614
|
...N,enum:["auto","choice","review","self","fact","none"]},check:{...M,required:!1},fact:{...M,required:!1},files:{...H(
|
|
605
615
|
N,8),required:!1},question:{...N,required:!1,maxLength:2e3},options:{...H(N,8),required:!1},answer:{...H({type:"integer",
|
|
606
616
|
required:!0,min:0,max:7},8),required:!1},rubric:{...N,required:!1,maxLength:600},evidence:{...H({...N,enum:["changes","c\
|
|
607
|
-
onversation"]},2),required:!1}})}}),
|
|
608
|
-
r",required:!0,enum:[2]},...
|
|
609
|
-
io","project"]}}),
|
|
617
|
+
onversation"]},2),required:!1}})}}),Va={...Da,notes:{...N,required:!1},steps:H(Wp,32)},Yp=$({schemaVersion:{type:"intege\
|
|
618
|
+
r",required:!0,enum:[2]},...Va}),Jp=$({schemaVersion:{type:"integer",required:!0,enum:[3]},...Va,stage:{...N,enum:["stud\
|
|
619
|
+
io","project"]}}),Kp=new Map([[1,Ua],[2,Yp],[3,Jp]]),me=e=>e?.schemaVersion===2||e?.schemaVersion===3;$r=$({schemaVersion:kr,
|
|
610
620
|
topicId:M,domainId:M,title:N,status:{...N,enum:["preview","released"]},outline:N,prerequisites:H($({topicId:M}),24),lessons:H(
|
|
611
621
|
$({code:M,descriptor:N,status:{...N,enum:["draft","published"]},required:{type:"boolean",required:!0}}),64),places:{...H(
|
|
612
|
-
M,64),required:!1},activities:{...H(M,64),required:!1},facts:{...H(M,64),required:!1}}),
|
|
622
|
+
M,64),required:!1},activities:{...H(M,64),required:!1},facts:{...H(M,64),required:!1}}),jr=$({schemaVersion:kr,courseId:M,
|
|
613
623
|
title:N,release:N,status:{...N,enum:["preview","released"]},topics:H($({topicId:M,release:N}),32),orientation:{...M,required:!1}}),
|
|
614
|
-
|
|
624
|
+
Ga=$({schemaVersion:kr,id:M,title:N,svg:N,controller:N,assets:{...H(N,32),required:!1},initialState:M,states:H(M,32),description:{
|
|
615
625
|
...N,maxLength:2e3},commands:H($({name:M,parameters:H($({name:M,required:{type:"boolean",required:!0},maxLength:{type:"i\
|
|
616
|
-
nteger",required:!0,min:1,max:256}}),8),completionState:M,description:{...N,maxLength:2e3}}),32)})});function
|
|
617
|
-
test(e.id||""))throw
|
|
618
|
-
bel.`);if(!
|
|
626
|
+
nteger",required:!0,min:1,max:256}}),8),completionState:M,description:{...N,maxLength:2e3}}),32)})});function ne(e){return Object.assign(new Error(e),{code:"VIBE64_TRAINING_VOCABULARY_INVALID"})}function rm(e){if(!B(e)||!Se.
|
|
627
|
+
test(e.id||""))throw ne("A place needs a lowercase id.");let t=`Place ${e.id}`;if(!za(e.label))throw ne(`${t} needs a la\
|
|
628
|
+
bel.`);if(!Xp.has(e.scope))throw ne(`${t} scope is studio or project.`);let r=e.who??"everyone";if(!Qp.has(r))throw ne(`${t}\
|
|
619
629
|
who is everyone or owner.`);let n=e.open??null;if(n!==null){let i=Object.keys(n||{}).sort().join(",");if(!(i==="pane"||
|
|
620
630
|
i==="databaseView,pane"?e.scope==="project"&&Se.test(n.pane):i==="route"?e.scope==="studio"&&typeof n.route=="string"&&/^\/app(?:\/[a-z0-9-]+)*$/u.
|
|
621
|
-
test(n.route):i==="learning"&&n.learning===!0))throw
|
|
622
|
-
hing.`)}if(!Array.isArray(e.steps)||!e.steps.length||e.steps.length>6||e.steps.some(i=>!Se.test(i?.id||"")||!
|
|
623
|
-
e.steps.at(-1).id!==e.id)throw
|
|
631
|
+
test(n.route):i==="learning"&&n.learning===!0))throw ne(`${t} opens a project pane, a studio /app route, Courses, or not\
|
|
632
|
+
hing.`)}if(!Array.isArray(e.steps)||!e.steps.length||e.steps.length>6||e.steps.some(i=>!Se.test(i?.id||"")||!za(i.label))||
|
|
633
|
+
e.steps.at(-1).id!==e.id)throw ne(`${t} needs 1 to 6 labelled steps ending with itself.`);let o=e.shown??(n?.pane?[{pane:n.
|
|
624
634
|
pane,...n.databaseView?{databaseView:n.databaseView}:{}}]:n?.route?[{route:n.route}]:[]);if(!Array.isArray(o)||o.some(i=>!B(
|
|
625
|
-
i)||!Object.keys(i).length))throw
|
|
626
|
-
throw
|
|
635
|
+
i)||!Object.keys(i).length))throw ne(`${t} shown is a list of page focus matchers.`);if(e.event!==void 0&&!Se.test(e.event))
|
|
636
|
+
throw ne(`${t} event is a lowercase activity name.`);return Object.freeze({id:e.id,label:e.label,scope:e.scope,who:r,open:n&&
|
|
627
637
|
Object.freeze({...n}),steps:Object.freeze(e.steps.map(i=>z(i.id,i.label))),shown:Object.freeze(o.map(i=>Object.freeze({...i}))),
|
|
628
|
-
...e.event?{event:e.event}:{}})}function
|
|
629
|
-
if(!Se.test(e.event||""))throw
|
|
630
|
-
throw
|
|
631
|
-
{}})}function
|
|
632
|
-
stringify(h)===JSON.stringify(
|
|
638
|
+
...e.event?{event:e.event}:{}})}function nm(e){if(!B(e)||!Se.test(e.id||""))throw ne("An activity needs a lowercase id.");
|
|
639
|
+
if(!Se.test(e.event||""))throw ne(`Activity ${e.id} needs its page activity event.`);if(e.place!==void 0&&!Se.test(e.place))
|
|
640
|
+
throw ne(`Activity ${e.id} place is a place id.`);return Object.freeze({id:e.id,event:e.event,...e.place?{place:e.place}:
|
|
641
|
+
{}})}function go(){return!1}function yo({places:e=Zp,activities:t=em,facts:r=tm}={}){let n=new Map,o=new Map,i=new Set,s=(h,w)=>JSON.
|
|
642
|
+
stringify(h)===JSON.stringify(w);function a({places:h=[],activities:w=[],facts:I=[]}={}){let S=h.map(rm),d=w.map(nm);for(let p of[
|
|
633
643
|
...S,...d])if(n.has(p.id)&&!s(n.get(p.id),p)||o.has(p.id)&&!s(o.get(p.id),p)||S.includes(p)&&o.has(p.id)||d.includes(p)&&
|
|
634
|
-
n.has(p.id))throw
|
|
635
|
-
A fact needs a lowercase id.");for(let p of S)n.set(p.id,p);for(let p of d)o.set(p.id,p);for(let p of
|
|
636
|
-
activities:t,facts:r});function c(h){return n.get(h)||null}function
|
|
644
|
+
n.has(p.id))throw ne(`${p.id} is already registered with another meaning.`);for(let p of I)if(!Se.test(p||""))throw ne("\
|
|
645
|
+
A fact needs a lowercase id.");for(let p of S)n.set(p.id,p);for(let p of d)o.set(p.id,p);for(let p of I)i.add(p)}a({places:e,
|
|
646
|
+
activities:t,facts:r});function c(h){return n.get(h)||null}function l(h){return o.get(h)||null}function u(h){return i.has(
|
|
637
647
|
h)}function m(){return[...n.values()]}function f(){return new Set([...[...o.values()].map(h=>h.event),...[...n.values()].
|
|
638
|
-
filter(h=>h.event).map(h=>h.event)])}return Object.freeze({register:a,place:c,activity:
|
|
639
|
-
declaredPlace:
|
|
640
|
-
map(m=>m.id));for(let m of[...e,...t,...r])if(!Se.test(m||""))throw
|
|
648
|
+
filter(h=>h.event).map(h=>h.event)])}return Object.freeze({register:a,place:c,activity:l,hasFact:u,places:m,events:f,declared:go,
|
|
649
|
+
declaredPlace:go,declaredActivity:go})}function Lr({places:e=[],activities:t=[],facts:r=[]}={}){let n=yo(),o=new Set(n.places().
|
|
650
|
+
map(m=>m.id));for(let m of[...e,...t,...r])if(!Se.test(m||""))throw ne(`Declared name ${m} is not a lowercase id.`);let i=new Set(
|
|
641
651
|
e.filter(m=>!o.has(m))),s=new Set(t.filter(m=>!n.activity(m)));function a(m){return i.has(m)}function c(m){return s.has(
|
|
642
|
-
m)}function
|
|
643
|
-
place:n.place,activity:n.activity,hasFact:
|
|
644
|
-
function Oe(e,t,r){return new ae(422,e,{code:t,params:r})}function
|
|
645
|
-
e.target):null,n=!r&&t.declaredPlace(e.target);if(!r&&!n){let c=t.places().map(
|
|
652
|
+
m)}function l(m){return a(m)||c(m)}function u(m){return n.hasFact(m)||r.includes(m)}return Object.freeze({register:n.register,
|
|
653
|
+
place:n.place,activity:n.activity,hasFact:u,places:n.places,events:n.events,declared:l,declaredPlace:a,declaredActivity:c})}
|
|
654
|
+
function Oe(e,t,r){return new ae(422,e,{code:t,params:r})}function Fa(e={},t=Ge){let r=typeof e.target=="string"?t.place(
|
|
655
|
+
e.target):null,n=!r&&t.declaredPlace(e.target);if(!r&&!n){let c=t.places().map(l=>l.id).join(", ");throw Oe(`Use one of \
|
|
646
656
|
this installation's guide places: ${c}.`,"VIBE64_TRAINING_GUIDE_INVALID",{places:c})}let o=e.target,i=e.navigate??!1,s=e.
|
|
647
657
|
highlight??!0;if(typeof i!="boolean"||typeof s!="boolean")throw Oe("navigate and highlight are booleans.","VIBE64_TRAINI\
|
|
648
658
|
NG_GUIDE_FLAGS_INVALID");if(!i&&!s)throw Oe("Point at the place (highlight) or open it (navigate); this request does nei\
|
|
649
659
|
ther.","VIBE64_TRAINING_GUIDE_ACTION_MISSING");if(i&&o==="dashboard")throw Oe("Dashboard has no single view to open. Poi\
|
|
650
660
|
nt at it, or open one Dashboard section such as files or database-erd.","VIBE64_TRAINING_GUIDE_DASHBOARD_UNOPENABLE");if(i&&
|
|
651
|
-
r&&!
|
|
661
|
+
r&&!om(r))throw Oe(`${r.label} has no view to open; point at it instead.`,"VIBE64_TRAINING_GUIDE_PLACE_UNOPENABLE",{place:r.
|
|
652
662
|
label});let a={target:o,navigate:i,highlight:s};if(e.filePath!==void 0){if(o!=="files")throw Oe("filePath is only for th\
|
|
653
|
-
e files place.","VIBE64_TRAINING_GUIDE_FILE_PATH_MISPLACED");if(typeof e.filePath!="string"||!
|
|
663
|
+
e files place.","VIBE64_TRAINING_GUIDE_FILE_PATH_MISPLACED");if(typeof e.filePath!="string"||!_o.test(e.filePath))throw Oe(
|
|
654
664
|
"Use a relative practice project file path without '..'.","VIBE64_TRAINING_GUIDE_FILE_PATH_INVALID");a.filePath=e.filePath}
|
|
655
|
-
if(e.caption!==void 0){if(typeof e.caption!="string"||!e.caption.trim()||e.caption.length>
|
|
656
|
-
1 to ${
|
|
665
|
+
if(e.caption!==void 0){if(typeof e.caption!="string"||!e.caption.trim()||e.caption.length>wo)throw Oe(`Use a caption of \
|
|
666
|
+
1 to ${wo} characters.`,"VIBE64_TRAINING_GUIDE_CAPTION_INVALID",{limit:wo});a.caption=e.caption.trim()}return a}function qa(e,t={},r=Ge){
|
|
657
667
|
let n=r.place(e);return n?.shown.length?n.shown.some(o=>Object.entries(o).every(([i,s])=>i==="route"?typeof t.route=="st\
|
|
658
|
-
ring"&&(t.route===s||t.route.startsWith(`${s}/`)):t[i]===s)):null}function
|
|
668
|
+
ring"&&(t.route===s||t.route.startsWith(`${s}/`)):t[i]===s)):null}function im(e,t=Ge){let r=new Set,n=new Set,o=new Set;
|
|
659
669
|
for(let i of Array.isArray(e?.beats)?e.beats:[]){if(i.kind==="check")continue;let s=t.activity(i.target);s||t.declaredActivity(
|
|
660
670
|
i.target)?(n.add(i.target),s?.place&&r.add(s.place)):r.add(i.target)}return e?.guide?.target&&r.add(e.guide.target),e?.check?.
|
|
661
|
-
kind==="fact"&&o.add(e.check.fact),{places:[...r],activities:[...n],facts:[...o]}}var Se,
|
|
662
|
-
Ge,
|
|
663
|
-
owner"]),z=(e,t)=>Object.freeze({id:e,label:t}),
|
|
664
|
-
"Database"),
|
|
665
|
-
steps:[
|
|
666
|
-
project",open:{pane:"database",databaseView:"erd"},steps:[ve,
|
|
667
|
-
a",scope:"project",open:{pane:"database",databaseView:"data"},steps:[ve,
|
|
671
|
+
kind==="fact"&&o.add(e.check.fact),{places:[...r],activities:[...n],facts:[...o]}}var Se,Xp,Qp,z,Ba,ve,Ha,ho,Zp,em,tm,za,
|
|
672
|
+
Ge,_o,wo,om,Rb,Mr=g(()=>{pr();G();Se=/^[a-z][a-z0-9-]{0,63}$/u,Xp=new Set(["studio","project"]),Qp=new Set(["everyone","\
|
|
673
|
+
owner"]),z=(e,t)=>Object.freeze({id:e,label:t}),Ba=z("preview","Preview"),ve=z("dashboard","Dashboard"),Ha=z("database",
|
|
674
|
+
"Database"),ho=z("account-menu","Account menu"),Zp=[{id:"preview",label:"Preview",scope:"project",open:{pane:"preview"},
|
|
675
|
+
steps:[Ba]},{id:"dashboard",label:"Dashboard",scope:"project",open:null,steps:[ve]},{id:"database-erd",label:"ERD",scope:"\
|
|
676
|
+
project",open:{pane:"database",databaseView:"erd"},steps:[ve,Ha,z("database-erd","ERD")]},{id:"database-data",label:"Dat\
|
|
677
|
+
a",scope:"project",open:{pane:"database",databaseView:"data"},steps:[ve,Ha,z("database-data","Data")]},{id:"files",label:"\
|
|
668
678
|
Files",scope:"project",open:{pane:"files"},steps:[ve,z("files","Files")]},{id:"changes",label:"Current changes",scope:"p\
|
|
669
679
|
roject",open:{pane:"changes"},steps:[ve,z("changes","Current changes")]},{id:"git-log",label:"Git log",scope:"project",open:{
|
|
670
680
|
pane:"repository"},steps:[ve,z("git-log","Git log")]},{id:"session-info",label:"Session info",scope:"project",open:{pane:"\
|
|
@@ -672,56 +682,56 @@ session"},steps:[ve,z("session-info","Session info")]},{id:"architecture",label:
|
|
|
672
682
|
system"},steps:[ve,z("architecture","Architecture")]},{id:"publish",label:"Publish",scope:"project",open:{pane:"publish"},
|
|
673
683
|
steps:[ve,z("publish","Publish")]},{id:"chat",label:"Coding chat",scope:"project",open:null,shown:[{pane:"chat"},{chatVisible:!0}],
|
|
674
684
|
steps:[z("chat","Coding chat")]},{id:"save",label:"Save",scope:"project",open:null,event:"saved",steps:[z("save","Save")]},
|
|
675
|
-
{id:"reload-preview",label:"Reload preview",scope:"project",open:null,event:"preview-reloaded",steps:[
|
|
685
|
+
{id:"reload-preview",label:"Reload preview",scope:"project",open:null,event:"preview-reloaded",steps:[Ba,z("reload-previ\
|
|
676
686
|
ew","Reload preview")]},{id:"learning",label:"Learning",scope:"studio",open:{learning:!0},shown:[],event:"learn-toggled",
|
|
677
687
|
steps:[z("learning","Learning")]},{id:"lesson",label:"Lesson",scope:"studio",open:null,shown:[{pane:"lesson"}],steps:[z(
|
|
678
688
|
"lesson","Lesson")]},{id:"lesson-bar",label:"Lesson step bar",scope:"studio",open:null,steps:[z("lesson-bar","Lesson ste\
|
|
679
689
|
p bar")]},{id:"courses",label:"Courses",scope:"studio",open:null,shown:[{learningOpen:!0}],steps:[z("courses","Courses")]},
|
|
680
690
|
{id:"colleague",label:"Colleague",scope:"studio",open:null,event:"colleague-opened",steps:[z("colleague","Colleague")]},
|
|
681
|
-
{id:"account-menu",label:"Account menu",scope:"studio",open:null,steps:[
|
|
682
|
-
ngs",scope:"studio",open:null,steps:[
|
|
683
|
-
studio",open:null,steps:[
|
|
691
|
+
{id:"account-menu",label:"Account menu",scope:"studio",open:null,steps:[ho]},{id:"account-settings",label:"Account setti\
|
|
692
|
+
ngs",scope:"studio",open:null,steps:[ho,z("account-settings","Account settings")]},{id:"ai-setup",label:"AI setup",scope:"\
|
|
693
|
+
studio",open:null,steps:[ho,z("ai-setup","AI setup")]}],em=[{id:"send-message",event:"message-sent",place:"chat"},{id:"a\
|
|
684
694
|
gent-finished",event:"agent-finished"},{id:"file-opened",event:"file-opened",place:"files"},{id:"app-pressed",event:"app\
|
|
685
|
-
-pressed",place:"preview"},{id:"colleague-minimised",event:"colleague-minimised",place:"colleague"}],
|
|
686
|
-
e=>typeof e=="string"&&e.trim().length>0&&e.length<=64;Ge=
|
|
687
|
-
|
|
688
|
-
e);if(!n)throw
|
|
689
|
-
if(o==="check"&&i==="review"){if(a.trim()||s!==void 0)throw
|
|
690
|
-
c.`);return{kind:o,target:i,text:""}}if(!a.trim())throw
|
|
691
|
-
text:a.trim()};if(s!==void 0&&!(o==="do"&&i==="file-opened"))throw
|
|
692
|
-
a path.`);if(o==="show"&&!
|
|
693
|
-
othing the learner can do or be at.`);if(o==="check"&&!
|
|
694
|
-
if(s!==void 0){if(!
|
|
695
|
-
"send-message"?
|
|
696
|
-
...
|
|
697
|
-
ed prompt of at most ${
|
|
698
|
-
return{body:r,beats:null};let o=r.slice(n.index+n[0].length),i=/^```[ \t]*$/mu.exec(o);if(!i)throw
|
|
699
|
-
s not closed with ```.");if(o.slice(i.index+i[0].length).trim())throw
|
|
695
|
+
-pressed",place:"preview"},{id:"colleague-minimised",event:"colleague-minimised",place:"colleague"}],tm=["ai-ready"];za=
|
|
696
|
+
e=>typeof e=="string"&&e.trim().length>0&&e.length<=64;Ge=yo({facts:[]});_o=/^(?!\/)(?!.*(?:^|\/)\.\.(?:\/|$))[^\u0000-\u001f\\]{1,512}$/u,
|
|
697
|
+
wo=256;om=e=>!!e?.open;Rb=Object.freeze({createLearningVocabulary:yo,lessonStepNeeds:im})});function oe(e){return Object.assign(new Error(e),{code:"VIBE64_TRAINING_BEATS_INVALID"})}function mm(e,t,r){let n=lm.exec(
|
|
698
|
+
e);if(!n)throw oe(`beat ${t} must read "<show|do|check> <target>: <text>".`);let[,o,i,s,a=""]=n,c=`beat ${t} (${o} ${i})`;
|
|
699
|
+
if(o==="check"&&i==="review"){if(a.trim()||s!==void 0)throw oe(`${c} takes no text: the bar shows the step's check.rubri\
|
|
700
|
+
c.`);return{kind:o,target:i,text:""}}if(!a.trim())throw oe(`${c} needs its text after the colon.`);let l={kind:o,target:i,
|
|
701
|
+
text:a.trim()};if(s!==void 0&&!(o==="do"&&i==="file-opened"))throw oe(`${c} takes no argument; only do file-opened names\
|
|
702
|
+
a path.`);if(o==="show"&&!pm(i,r))throw oe(`${c} names an unknown place.`);if(o==="do"&&!dm(i,r))throw oe(`${c} names n\
|
|
703
|
+
othing the learner can do or be at.`);if(o==="check"&&!Eo[i])throw oe(`${c} must be check auto, review, done or fact.`);
|
|
704
|
+
if(s!==void 0){if(!_o.test(s))throw oe(`${c} needs a relative practice project file path without '..'.`);l.path=s}let u=i===
|
|
705
|
+
"send-message"?am:sm;if(l.text.length>u)throw oe(`${c} text is longer than ${u} characters.`);if(i==="send-message"){let m=[
|
|
706
|
+
...l.text.matchAll(um)].map(f=>f[1].trim());if(m.length!==1||!m[0]||m[0].length>Ya)throw oe(`${c} needs exactly one quot\
|
|
707
|
+
ed prompt of at most ${Ya} characters.`);l.prompt=m[0]}return l}function Dr(e,t=Ge){let r=String(e??""),n=cm.exec(r);if(!n)
|
|
708
|
+
return{body:r,beats:null};let o=r.slice(n.index+n[0].length),i=/^```[ \t]*$/mu.exec(o);if(!i)throw oe("the beats block i\
|
|
709
|
+
s not closed with ```.");if(o.slice(i.index+i[0].length).trim())throw oe("the beats block must end the step text.");let s=o.
|
|
700
710
|
slice(0,i.index).split(`
|
|
701
|
-
`).map(
|
|
702
|
-
map((u
|
|
711
|
+
`).map(l=>l.trim()).filter(Boolean);if(!s.length||s.length>Wa)throw oe(`a beats block holds 1 to ${Wa} beats.`);let a=s.
|
|
712
|
+
map((l,u)=>mm(l,u+1,t)),c=a.filter(l=>l.kind==="check");if(c.length>1||c.length&&a.at(-1).kind!=="check")throw oe("a ste\
|
|
703
713
|
p has at most one check beat, and it is the last.");return{body:r.slice(0,n.index).replace(/\s+$/u,`
|
|
704
|
-
`),beats:a}}function
|
|
705
|
-
function
|
|
706
|
-
scope==="project":!t.declared(e.target)}var
|
|
707
|
-
freeze({auto:"auto",review:"review",done:"self",fact:"fact"}),
|
|
708
|
-
|
|
709
|
-
place(e)||t.declaredPlace(e))});import{createHash as
|
|
710
|
-
let n=new Set;for(let o of e){let i=t?o[t]:o;if(!
|
|
714
|
+
`),beats:a}}function fm(e,t=Ge){if(!e||e.kind==="check")return"";let r=t.activity(e.target);return r?r.place||"":e.target}
|
|
715
|
+
function Ja(e,t=Ge){if(e.kind==="check")return e.target==="auto"||e.target==="review";let r=t.place(fm(e,t));return r?r.
|
|
716
|
+
scope==="project":!t.declared(e.target)}var Wa,sm,Ya,am,Eo,cm,lm,um,dm,pm,bo=g(()=>{Mr();Wa=8,sm=160,Ya=500,am=600,Eo=Object.
|
|
717
|
+
freeze({auto:"auto",review:"review",done:"self",fact:"fact"}),cm=/^```beats[ \t]*$/mu,lm=/^(show|do|check)[ \t]+([a-z][a-z-]*)(?:[ \t]+([^:]+?))?[ \t]*(?::[ \t]*(.*))?$/u,
|
|
718
|
+
um=/["“]([^"“”]+)["”]/gu;dm=(e,t)=>!!(t.activity(e)||t.place(e)?.event||qa(e,{},t)!==null||t.declared(e)),pm=(e,t)=>!!(t.
|
|
719
|
+
place(e)||t.declaredPlace(e))});import{createHash as hm}from"node:crypto";function K(e){return hm("sha256").update(e).digest("hex")}var ut=g(()=>{});import{lstat as gm,readFile as wm,readdir as ym,realpath as Ka}from"node:fs/promises";import ie from"node:path";function fe(e,t,r){
|
|
720
|
+
let n=new Set;for(let o of e){let i=t?o[t]:o;if(!Ur(i)||n.has(i))throw new Error(`${r}: invalid or duplicate ID ${i}.`);
|
|
711
721
|
n.add(i)}return n}function L(e){return Array.isArray(e)?`[${e.map(L).join(",")}]`:e&&typeof e=="object"?`{${Object.keys(
|
|
712
|
-
e).sort().map(t=>`${JSON.stringify(t)}:${L(e[t])}`).join(",")}}`:JSON.stringify(e)}function
|
|
722
|
+
e).sort().map(t=>`${JSON.stringify(t)}:${L(e[t])}`).join(",")}}`:JSON.stringify(e)}function Qa(e,t){let r=e.get(t.path);
|
|
713
723
|
if(r&&(r.sha256!==t.sha256||r.bytes!==t.bytes))throw new Error(`Source changed between lesson snapshots: ${t.path}. Vali\
|
|
714
|
-
date and retry.`);e.set(t.path,t)}function Be(e){let t=new Map;for(let r of e)for(let n of r.files)
|
|
715
|
-
async function
|
|
724
|
+
date and retry.`);e.set(t.path,t)}function Be(e){let t=new Map;for(let r of e)for(let n of r.files)Qa(t,n);return[...t.values()]}
|
|
725
|
+
async function _m(e){let t=await Ka(e);async function r(i,s=t){if(typeof i!="string"||!i||i.includes("\\")||ie.isAbsolute(
|
|
716
726
|
i))throw new Error(`Invalid topic-relative path: ${i}.`);let a=ie.resolve(s,i),c=ie.relative(t,a);if(c===".."||c.startsWith(
|
|
717
|
-
`..${ie.sep}`)||ie.isAbsolute(c))throw new Error(`Path escapes topic: ${i}.`);if(await
|
|
727
|
+
`..${ie.sep}`)||ie.isAbsolute(c))throw new Error(`Path escapes topic: ${i}.`);if(await Ka(a)!==a)throw new Error(`Symlin\
|
|
718
728
|
k content is not supported: ${i}.`);return{filename:a,relative:c.split(ie.sep).join("/")}}async function n(i,s=t){let a=await r(
|
|
719
|
-
i,s),c=await
|
|
720
|
-
relative}.`);return{...a,bytes:await
|
|
721
|
-
a.bytes.toString("utf8"))}}return Object.freeze({root:t,resolve:r,read:n,json:o})}function
|
|
729
|
+
i,s),c=await gm(a.filename);if(!c.isFile()||c.size>1024*1024)throw new Error(`Expected a regular file of at most 1 MiB: ${a.
|
|
730
|
+
relative}.`);return{...a,bytes:await wm(a.filename)}}async function o(i,s=t){let a=await n(i,s);return{...a,value:JSON.parse(
|
|
731
|
+
a.bytes.toString("utf8"))}}return Object.freeze({root:t,resolve:r,read:n,json:o})}function Em(e){let t=new Map(e.map(i=>[
|
|
722
732
|
i.code,i])),r=new Set,n=new Set;function o(i){if(n.has(i))throw new Error(`Prerequisite cycle at ${i}.`);if(r.has(i))return;
|
|
723
733
|
let s=t.get(i);if(!s)throw new Error(`Unknown prerequisite ${i}.`);n.add(i);for(let a of s.prerequisites)o(a.code);n.delete(
|
|
724
|
-
i),r.add(i)}for(let i of e)o(i.code)}function
|
|
734
|
+
i),r.add(i)}for(let i of e)o(i.code)}function bm(e,t,r,n){r(t);let o=t.bytes.toString("utf8");fe(e.assessments,"id","Ass\
|
|
725
735
|
essments");for(let i of e.assessments){let[s,a,c]=i.rubric.split("#");if(s!==e.document||!a||c||!new RegExp(`^<a id="${i.
|
|
726
736
|
id}"></a>$`,"mu").test(o)||a!==i.id)throw new Error(`Missing explicit rubric anchor for ${i.id}.`);if(i.kind==="practica\
|
|
727
737
|
l"&&!i.evidence)throw new Error(`Practical assessment ${i.id} needs an evidence producer.`);if(i.kind==="answer"&&i.evidence)
|
|
@@ -729,205 +739,205 @@ throw new Error(`Answer assessment ${i.id} uses its admitted answer, not a pract
|
|
|
729
739
|
has(i.evidence.check))throw new Error(`Unknown check for ${i.id}.`);if(i.evidence?.producer==="exercise"&&(!e.exercise||
|
|
730
740
|
!i.evidence.check))throw new Error(`Exercise assessment ${i.id} needs its declared exercise and check.`);if(i.evidence?.
|
|
731
741
|
check&&!["exercise","code"].includes(i.evidence.producer))throw new Error(`Only exercise or code evidence runs a declare\
|
|
732
|
-
d check: ${i.id}.`);let
|
|
733
|
-
code"){if(!e.exercise||!i.evidence.check||
|
|
734
|
-
needs its declared exercise, files and a code check.`)}else if(i.evidence?.files||i.evidence?.check&&
|
|
735
|
-
`Only code evidence names edited files or runs a code check: ${i.id}.`)}}function
|
|
742
|
+
d check: ${i.id}.`);let l=(e.checks||[]).find(u=>u.id===i.evidence?.check)?.kind||"response";if(i.evidence?.producer==="\
|
|
743
|
+
code"){if(!e.exercise||!i.evidence.check||l!=="code"||!i.evidence.files?.length)throw new Error(`Code assessment ${i.id}\
|
|
744
|
+
needs its declared exercise, files and a code check.`)}else if(i.evidence?.files||i.evidence?.check&&l==="code")throw new Error(
|
|
745
|
+
`Only code evidence names edited files or runs a code check: ${i.id}.`)}}function vm(e,t,r,n,o,i){let s=a=>{throw new Error(
|
|
736
746
|
`Lesson ${n}: ${a}`)};e.schemaVersion===3&&e.stage==="project"&&!e.exercise&&s("a project lesson needs its exercise (a p\
|
|
737
747
|
ractice project)."),e.steps.length||s("needs at least one step."),fe(e.steps,"id","Steps"),e.steps.some(a=>a.required)||
|
|
738
748
|
s("needs a required step.");for(let a of e.steps){let c=`step ${a.id}`;if(a.visual){let h=t.get(a.visual.id);h||s(`${c} \
|
|
739
|
-
shows undeclared visual ${a.visual.id}.`);for(let
|
|
740
|
-
`${c} plays undeclared command ${
|
|
741
|
-
nd ${
|
|
742
|
-
`${c} command ${
|
|
743
|
-
name} parameter ${d} must be a string of at most ${_.maxLength} characters.`)}for(let d of
|
|
744
|
-
hasOwn(S,d.name)&&s(`${c} command ${
|
|
745
|
-
|
|
746
|
-
target} needs the lesson's exercise (a practice project).`)}let
|
|
747
|
-
beats: ${h.message}`)}if(
|
|
748
|
-
kind==="check");h&&
|
|
749
|
-
let
|
|
750
|
-
ect).`)}let
|
|
751
|
-
"fact"],self:[],none:[]}[
|
|
752
|
-
heck cannot declare ${f.join(", ")}.`),
|
|
753
|
-
"fact"&&(e.schemaVersion!==3&&s(`${c} fact check needs lesson format 3.`),(!
|
|
754
|
-
an unknown fact; declare a host's fact in the topic's facts.`)),
|
|
749
|
+
shows undeclared visual ${a.visual.id}.`);for(let w of a.visual.play||[]){let I=h.commands.find(d=>d.name===w.name);I||s(
|
|
750
|
+
`${c} plays undeclared command ${w.name}.`);let S=w.parameters;(!S||typeof S!="object"||Array.isArray(S))&&s(`${c} comma\
|
|
751
|
+
nd ${w.name} needs a parameters object.`);for(let[d,p]of Object.entries(S)){let _=I.parameters.find(b=>b.name===d);_||s(
|
|
752
|
+
`${c} command ${w.name} has undeclared parameter ${d}.`),(typeof p!="string"||p.length>_.maxLength)&&s(`${c} command ${w.
|
|
753
|
+
name} parameter ${d} must be a string of at most ${_.maxLength} characters.`)}for(let d of I.parameters)d.required&&!Object.
|
|
754
|
+
hasOwn(S,d.name)&&s(`${c} command ${w.name} needs parameter ${d.name}.`)}}if(a.guide){let{caption:h,...w}=a.guide;try{Fa(
|
|
755
|
+
w,i)}catch(I){s(`${c} guide: ${I.message}`)}i.place(a.guide.target)?.scope==="project"&&!e.exercise&&s(`${c} guide ${a.guide.
|
|
756
|
+
target} needs the lesson's exercise (a practice project).`)}let l=null;try{({beats:l}=Dr(o.get(a.body),i))}catch(h){s(`${c}\
|
|
757
|
+
beats: ${h.message}`)}if(l){a.guide&&s(`${c} has both beats and a guide; its beats replace the guide.`);let h=l.find(I=>I.
|
|
758
|
+
kind==="check");h&&Eo[h.target]!==a.check.kind&&s(`${c} beat check ${h.target} does not match its ${a.check.kind} check.`);
|
|
759
|
+
let w=l.find(I=>Ja(I,i));w&&!e.exercise&&s(`${c} beat ${w.kind} ${w.target} needs the lesson's exercise (a practice proj\
|
|
760
|
+
ect).`)}let u=a.check,m={auto:["check","files"],choice:["question","options","answer"],review:["rubric","evidence"],fact:[
|
|
761
|
+
"fact"],self:[],none:[]}[u.kind],f=Object.keys(u).filter(h=>h!=="kind"&&!m.includes(h));if(f.length&&s(`${c} ${u.kind} c\
|
|
762
|
+
heck cannot declare ${f.join(", ")}.`),u.kind==="none"&&a.required&&s(`${c} has no check and cannot be required.`),u.kind===
|
|
763
|
+
"fact"&&(e.schemaVersion!==3&&s(`${c} fact check needs lesson format 3.`),(!u.fact||!i.hasFact(u.fact))&&s(`${c} checks \
|
|
764
|
+
an unknown fact; declare a host's fact in the topic's facts.`)),u.kind==="auto"){(!u.check||!r.has(u.check))&&s(`${c} na\
|
|
755
765
|
mes an unknown check.`),e.exercise||s(`${c} runs a declared check and needs the lesson's exercise.`);let h=e.checks.find(
|
|
756
|
-
|
|
757
|
-
k needs 1-8 exercise files":"names files, but only a code check edits files"}.`)}if(
|
|
758
|
-
s(`${c} review needs its rubric.`),e.exercise||s(`${c} reviews practice work and needs the lesson's exercise.`);let h=
|
|
766
|
+
I=>I.id===u.check),w=u.files||[];(h.kind==="code"?w.length<1||w.length>8:w.length)&&s(`${c} ${h.kind==="code"?"code chec\
|
|
767
|
+
k needs 1-8 exercise files":"names files, but only a code check edits files"}.`)}if(u.kind==="review"){u.rubric?.trim()||
|
|
768
|
+
s(`${c} review needs its rubric.`),e.exercise||s(`${c} reviews practice work and needs the lesson's exercise.`);let h=u.
|
|
759
769
|
evidence||["changes"];(h[0]!=="changes"||h.length>2||h.length===2&&h[1]!=="conversation")&&s(`${c} review evidence is ["\
|
|
760
|
-
changes"] or ["changes", "conversation"].`)}if(
|
|
761
|
-
choice needs question, options and answer.`),(
|
|
762
|
-
new Set(
|
|
763
|
-
tions.`)}}}async function
|
|
770
|
+
changes"] or ["changes", "conversation"].`)}if(u.kind==="choice"){let{question:h,options:w,answer:I}=u;(!h||!w||!I)&&s(`${c}\
|
|
771
|
+
choice needs question, options and answer.`),(w.length<2||w.length>8)&&s(`${c} choice needs 2-8 options.`),(!I.length||
|
|
772
|
+
new Set(I).size!==I.length||I.some(S=>S>=w.length))&&s(`${c} choice answer must list unique option indexes within its op\
|
|
773
|
+
tions.`)}}}async function Sm(e,t,{authoring:r,installed:n,vocabulary:o}){let i=await e.json(t.descriptor),s=xr(i.value,t.
|
|
764
774
|
code);if(s.code!==t.code)throw new Error(`Lesson code mismatch: ${t.code}.`);if(r&&s.schemaVersion!==3)throw new Error(`\
|
|
765
775
|
Lesson ${t.code} uses retired lesson format ${s.schemaVersion}. Author it in format 3 with steps and its stage.`);let a=ie.
|
|
766
|
-
dirname(i.filename),c=new Map;function
|
|
767
|
-
[...c.values()].reduce((p,_)=>p+_.bytes,0)>32*1024*1024)throw new Error(`Lesson ${t.code} exceeds bundle limits.`)}
|
|
768
|
-
let
|
|
769
|
-
checks||[]){
|
|
770
|
-
read(s.document,a),
|
|
771
|
-
read(d,a);
|
|
776
|
+
dirname(i.filename),c=new Map;function l(d){if(Qa(c,{path:d.relative,sha256:K(d.bytes),bytes:d.bytes.length}),c.size>512||
|
|
777
|
+
[...c.values()].reduce((p,_)=>p+_.bytes,0)>32*1024*1024)throw new Error(`Lesson ${t.code} exceeds bundle limits.`)}l(i);
|
|
778
|
+
let u=new Set,m=new Map;fe(s.prerequisites,"code","Lesson prerequisites");let f=fe(s.checks||[],"id","Checks");for(let d of s.
|
|
779
|
+
checks||[]){l(await e.read(d.file,a));for(let p of d.assets||[])l(await e.read(p,a))}if(s.schemaVersion===1&&bm(s,await e.
|
|
780
|
+
read(s.document,a),l,f),me(s))for(let d of[s.notes,...new Set(s.steps.map(p=>p.body))]){if(d===void 0)continue;let p=await e.
|
|
781
|
+
read(d,a);l(p),u.add(p.relative),m.set(d,p.bytes.toString("utf8"))}if(s.appRoutes&&!s.exercise)throw new Error(`Lesson ${t.
|
|
772
782
|
code} can declare app routes only with its exercise.`);let h=new Set;for(let d of s.appRoutes||[]){if(d.path!=="/"&&!d.path.
|
|
773
783
|
slice(1).split("/").every(_=>_===":id"||/^[A-Za-z0-9._~-]+$/u.test(_)))throw new Error(`Invalid app route path for ${t.code}\
|
|
774
784
|
: ${d.path}.`);let p=`${d.method} ${d.path}`;if(h.has(p))throw new Error(`Lesson ${t.code} has a duplicate app route: ${p}\
|
|
775
785
|
.`);h.add(p)}for(let d of s.checks||[])if(d.timeoutSeconds!==void 0&&d.kind!=="code")throw new Error(`Only a code check \
|
|
776
786
|
declares a timeout: ${d.id}.`);if(s.schemaVersion===1&&!s.assessments.some(d=>d.required))throw new Error(`Lesson ${t.code}\
|
|
777
|
-
needs a required assessment.`);fe(s.visuals,"id","Visuals");let
|
|
778
|
-
descriptor,a),_=ce(
|
|
787
|
+
needs a required assessment.`);fe(s.visuals,"id","Visuals");let w=new Map;for(let d of s.visuals){let p=await e.json(d.
|
|
788
|
+
descriptor,a),_=ce(Ga,p.value,d.id);if(_.id!==d.id)throw new Error(`Visual ID mismatch: ${d.id}.`);let b=fe(_.states,null,
|
|
779
789
|
"Visual states");if(!b.has(_.initialState))throw new Error(`Unknown initial visual state: ${_.initialState}.`);fe(_.commands,
|
|
780
|
-
"name","Visual commands");for(let
|
|
781
|
-
nchanged"&&!b.has(
|
|
782
|
-
dirname(p.filename);for(let
|
|
790
|
+
"name","Visual commands");for(let y of _.commands)if(fe(y.parameters,"name","Command parameters"),y.completionState!=="u\
|
|
791
|
+
nchanged"&&!b.has(y.completionState))throw new Error(`Unknown completion state: ${y.name}.`);l(p),w.set(_.id,_);let v=ie.
|
|
792
|
+
dirname(p.filename);for(let y of[_.svg,_.controller,..._.assets||[]]){let E=await e.read(y,v);l(E),u.add(E.relative)}}if(s.
|
|
783
793
|
exercise){let d=s.exercise;if(d.reuse==="sequence"){if(!d.sequenceId||!d.sequenceMode)throw new Error(`Invalid exercise \
|
|
784
794
|
sequence for ${t.code}.`)}else if(d.sequenceId||d.sequenceMode)throw new Error(`Invalid exercise sequence for ${t.code}.`);
|
|
785
|
-
if(d.sequenceId&&!
|
|
786
|
-
for(let
|
|
787
|
-
let E=ie.relative(e.root,ie.join(v,
|
|
788
|
-
read(E);
|
|
789
|
-
id}`,v.evidence?.files||[]]):s.steps.map(v=>[`Code step ${v.id}`,v.check.files||[]]);for(let[v,
|
|
790
|
-
split("/");if(E.includes("\\")||ie.posix.isAbsolute(E)||A.some(
|
|
791
|
-
relative}/${E}`:E))throw new Error(`${v} names a file outside its bundled exercise: ${E}.`)}if(new Set(
|
|
792
|
-
throw new Error(`${v} repeats a declared file.`)}}let
|
|
795
|
+
if(d.sequenceId&&!Ur(d.sequenceId))throw new Error("Invalid exercise sequence ID.");let p=await e.resolve(d.source,a);async function _(v){
|
|
796
|
+
for(let y of(await ym(v,{withFileTypes:!0})).sort((E,A)=>E.name<A.name?-1:E.name>A.name?1:0)){if(Xa.has(y.name))continue;
|
|
797
|
+
let E=ie.relative(e.root,ie.join(v,y.name)),A=await e.resolve(E);if(y.isDirectory())await _(A.filename);else{let T=await e.
|
|
798
|
+
read(E);l(T),u.add(T.relative)}}}await _(p.filename);let b=s.schemaVersion===1?s.assessments.map(v=>[`Code assessment ${v.
|
|
799
|
+
id}`,v.evidence?.files||[]]):s.steps.map(v=>[`Code step ${v.id}`,v.check.files||[]]);for(let[v,y]of b){for(let E of y){let A=E.
|
|
800
|
+
split("/");if(E.includes("\\")||ie.posix.isAbsolute(E)||A.some(T=>!T||T==="."||T===".."||Xa.has(T))||!c.has(p.relative?`${p.
|
|
801
|
+
relative}/${E}`:E))throw new Error(`${v} names a file outside its bundled exercise: ${E}.`)}if(new Set(y).size!==y.length)
|
|
802
|
+
throw new Error(`${v} repeats a declared file.`)}}let I="";if(me(s))try{vm(s,w,f,t.code,m,o)}catch(d){if(!n)throw d;I=d.
|
|
793
803
|
message}let S={schemaVersion:1,code:s.code,files:[...c.values()].sort((d,p)=>d.path<p.path?-1:d.path>p.path?1:0)};return{
|
|
794
|
-
lesson:s,manifest:S,hash:
|
|
795
|
-
installed:n=!1}=t,o=await
|
|
796
|
-
test(i.value.version||""))throw new Error("Topic package needs a learn- name and an exact release version.");let s=ce(
|
|
797
|
-
i.value.vibe64Training,"Topic");if(!
|
|
804
|
+
lesson:s,manifest:S,hash:K(L(S)),descriptorPath:i.relative,served:u,...I?{problem:I}:{}}}async function He(e,t={}){let{authoring:r=!1,
|
|
805
|
+
installed:n=!1}=t,o=await _m(e),i=await o.json("package.json");if(!/^learn-[a-z0-9-]+$/u.test(i.value.name||"")||!/^\d+\.\d+\.\d+$/u.
|
|
806
|
+
test(i.value.version||""))throw new Error("Topic package needs a learn- name and an exact release version.");let s=ce($r,
|
|
807
|
+
i.value.vibe64Training,"Topic");if(!Ur(s.topicId)||!Ur(s.domainId))throw new Error("Invalid topic or domain ID.");let a=await o.
|
|
798
808
|
read(s.outline);if(fe(s.lessons,"code","Lessons"),fe(s.prerequisites,"topicId","Topic prerequisites"),!s.lessons.length)
|
|
799
|
-
throw new Error("A topic needs lessons.");if(s.status==="released"&&s.lessons.some(
|
|
800
|
-
throw new Error("A released topic contains required draft lessons.");let c
|
|
801
|
-
let{served:
|
|
802
|
-
required:
|
|
803
|
-
ptor cannot also be a step body, notes, visual or exercise file.`);
|
|
804
|
-
code:S}of
|
|
805
|
-
t precede ${
|
|
806
|
-
lesson.code} requires draft ${S}.`)}let m=new Map;for(let{lesson:
|
|
807
|
-
"sequence")continue;let d=(await o.resolve(
|
|
808
|
-
sequenceId);if(
|
|
809
|
-
m.set(
|
|
810
|
-
`Invalid create/continue sequence: ${
|
|
811
|
-
h={schemaVersion:1,topic:s,release:i.value.version,files:f,lessons:
|
|
812
|
-
code,hash:
|
|
813
|
-
topicHash:
|
|
814
|
-
test(e)});import{execFile as
|
|
815
|
-
import{promisify as
|
|
816
|
-
":")){let r=new Error("A valid OS username is required.");throw r.code="vibe64_invalid_os_username",r}return t}function
|
|
809
|
+
throw new Error("A topic needs lessons.");if(s.status==="released"&&s.lessons.some(w=>w.required&&w.status!=="published"))
|
|
810
|
+
throw new Error("A released topic contains required draft lessons.");let c=Lr(s),l=[],u=new Set;for(let w of s.lessons){
|
|
811
|
+
let{served:I,...S}=await Sm(o,w,{authoring:r,installed:n,vocabulary:c});for(let d of I)u.add(d);l.push({...S,status:w.status,
|
|
812
|
+
required:w.required})}for(let{descriptorPath:w,lesson:I}of l)if(me(I)&&u.has(w))throw new Error(`Lesson ${I.code} descri\
|
|
813
|
+
ptor cannot also be a step body, notes, visual or exercise file.`);Em(l.map(w=>w.lesson));for(let[w,I]of l.entries())for(let{
|
|
814
|
+
code:S}of I.lesson.prerequisites){let d=l.findIndex(p=>p.lesson.code===S);if(d>=w)throw new Error(`Prerequisite ${S} mus\
|
|
815
|
+
t precede ${I.lesson.code}.`);if(I.status==="published"&&l[d].status!=="published")throw new Error(`Published lesson ${I.
|
|
816
|
+
lesson.code} requires draft ${S}.`)}let m=new Map;for(let{lesson:w,descriptorPath:I,status:S}of l){if(w.exercise?.reuse!==
|
|
817
|
+
"sequence")continue;let d=(await o.resolve(w.exercise.source,ie.dirname(ie.join(o.root,I)))).relative,p=m.get(w.exercise.
|
|
818
|
+
sequenceId);if(w.exercise.sequenceMode==="create"){if(p)throw new Error(`Invalid create/continue sequence: ${w.code}.`);
|
|
819
|
+
m.set(w.exercise.sequenceId,{source:d,status:S})}else if(!p||p.source!==d||S==="published"&&p.status!=="published")throw new Error(
|
|
820
|
+
`Invalid create/continue sequence: ${w.code}.`)}let f=[i,a].map(w=>({path:w.relative,sha256:K(w.bytes),bytes:w.bytes.length})),
|
|
821
|
+
h={schemaVersion:1,topic:s,release:i.value.version,files:f,lessons:l.map(({lesson:w,hash:I,status:S,required:d})=>({code:w.
|
|
822
|
+
code,hash:I,status:S,required:d}))};return Be([h,...l.map(w=>w.manifest)]),{topic:s,release:i.value.version,bundles:l,topicManifest:h,
|
|
823
|
+
topicHash:K(L(h))}}var Xa,Ur,dt=g(()=>{lt();Mr();bo();ut();Xa=new Set([".git","node_modules",".genesis"]),Ur=e=>/^[a-zA-Z][a-zA-Z0-9-]{0,63}$/u.
|
|
824
|
+
test(e)});import{execFile as Im}from"node:child_process";import{readFile as Tm}from"node:fs/promises";import vo from"node:os";import Am from"node:path";
|
|
825
|
+
import{promisify as Om}from"node:util";function ec(e=""){let t=V(e);if(!t||t.includes("/")||t.includes("\\")||t.includes(
|
|
826
|
+
":")){let r=new Error("A valid OS username is required.");throw r.code="vibe64_invalid_os_username",r}return t}function tc([
|
|
817
827
|
e,t,r,n,o,i]=[]){if(!/^\d+$/u.test(t)||!/^\d+$/u.test(r))return null;let s=Number(t),a=Number(r);return!Number.isSafeInteger(
|
|
818
828
|
s)||!Number.isSafeInteger(a)?null:{displayName:String(n||"").split(",")[0],gid:a,home:String(o||""),shell:String(i||""),
|
|
819
|
-
uid:s,username:String(e||"")}}function
|
|
820
|
-
t[3],t[4],t[5],t[6]])}function
|
|
821
|
-
split(/\r?\n/u)){let o=/^\s*([a-z]+):\s?(.*)$/u.exec(n);o&&(r[o[1]]=o[2].trim())}return
|
|
822
|
-
dir,r.shell])}).filter(Boolean)}async function
|
|
823
|
-
string"?n:n?.stdout)||"")}function Mt({homedir:e=
|
|
824
|
-
env.USER||process.env.LOGNAME),o=
|
|
829
|
+
uid:s,username:String(e||"")}}function So(e=""){let t=String(e||"").trim().split(":");return t.length<7?null:tc([t[0],t[2],
|
|
830
|
+
t[3],t[4],t[5],t[6]])}function Rm(e=""){return String(e||"").split(/\r?\n[\t ]*\r?\n/u).map(t=>{let r={};for(let n of t.
|
|
831
|
+
split(/\r?\n/u)){let o=/^\s*([a-z]+):\s?(.*)$/u.exec(n);o&&(r[o[1]]=o[2].trim())}return tc([r.name,r.uid,r.gid,r.gecos,r.
|
|
832
|
+
dir,r.shell])}).filter(Boolean)}async function Za(e,t,r){let n=await e(t,r,{encoding:"utf8"});return String((typeof n=="\
|
|
833
|
+
string"?n:n?.stdout)||"")}function Mt({homedir:e=vo.homedir,userInfo:t=vo.userInfo}={}){let r=t(),n=V(r?.username||process.
|
|
834
|
+
env.USER||process.env.LOGNAME),o=Am.resolve(String(r?.homedir||e()||""));return{displayName:String(r?.username||n),gid:Number.
|
|
825
835
|
isSafeInteger(r?.gid)?r.gid:null,home:o,shell:String(r?.shell||""),uid:Number.isSafeInteger(r?.uid)?r.uid:null,username:n}}
|
|
826
|
-
async function
|
|
836
|
+
async function Vr(e="",{execFileFn:t=Pm,platform:r=process.platform,readFileFn:n=Tm,userInfo:o=vo.userInfo}={}){let i=ec(
|
|
827
837
|
e);if(r==="linux"&&!/^\d+$/u.test(i)){let c=[...(await n("/etc/nsswitch.conf","utf8").catch(()=>"")).matchAll(/^[\t ]*passwd[\t ]*:[\t ]*([^#\r\n]*)/gmu)],
|
|
828
|
-
|
|
829
|
-
"/etc/passwd","utf8").catch(()=>"")).split(/\r?\n/u).map(
|
|
830
|
-
n"){let a=Mt({userInfo:o});if(a.username===i)return a;[s]=
|
|
831
|
-
s=
|
|
832
|
-
nd: ${i}`);throw a.code="vibe64_os_user_not_found",a}return s}var
|
|
833
|
-
isSafeInteger(t)&&t>=0?t:null}function C(e=""){let t=
|
|
834
|
-
t);if(!r||!n)return!1;let o=
|
|
835
|
-
return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}function
|
|
836
|
-
([t,r])=>[
|
|
837
|
-
[e]){let o=
|
|
838
|
-
isFinite(t)?t:0}function
|
|
839
|
-
return{displayName:
|
|
840
|
-
Mt())}async function
|
|
841
|
-
username,USER:r.username,XDG_CACHE_HOME:
|
|
842
|
-
join(r.home,".local","share")}}function
|
|
843
|
-
getuid=="function"?process.getuid():null}}var
|
|
844
|
-
output:o="",outputEncoding:i="utf8",pid:s=null,signal:a="",stderr:c="",stdout:
|
|
845
|
-
let h=
|
|
846
|
-
`)).trim();return{code:
|
|
847
|
-
Number(s):null,signal:
|
|
848
|
-
ct"&&!Array.isArray(m)?{execution:m}:{},...typeof f=="boolean"?{retryable:f}:{}}}function
|
|
849
|
-
d",r={}){let n=
|
|
850
|
-
stderr??(r.outputEncoding==="base64"?Buffer.from(n).toString("base64"):n),stdout:r.stdout??""})}var Fe=g(()=>{q()});import{spawn as
|
|
851
|
-
import{stripVTControlCharacters as
|
|
852
|
-
let r=t.codePointAt(0);return r<=65535?`\\u${r.toString(16).padStart(4,"0")}`:`\\U${r.toString(16)}`})}function
|
|
838
|
+
l=c.length===1?c[0][1].trim().split(/\s+/u):[];if(l[0]==="files"&&(l.length===1||/^[a-z_][a-z0-9_-]*$/iu.test(l[1]))){let m=(await n(
|
|
839
|
+
"/etc/passwd","utf8").catch(()=>"")).split(/\r?\n/u).map(So).find(f=>f?.username===i);if(m)return m}}let s;if(r==="darwi\
|
|
840
|
+
n"){let a=Mt({userInfo:o});if(a.username===i)return a;[s]=Rm(await Za(t,"dscacheutil",["-q","user","-a","name",i]))}else
|
|
841
|
+
s=So((await Za(t,"getent",["passwd",i])).split(/\r?\n/u)[0]);if(!s||s.username!==i){let a=new Error(`OS user was not fou\
|
|
842
|
+
nd: ${i}`);throw a.code="vibe64_os_user_not_found",a}return s}var Pm,Yb,Gr=g(()=>{G();Pm=Om(Im);Yb=Object.freeze({parsePasswdLine:So})});var rc=g(()=>{Gr();G()});import Br from"node:path";function R(e=""){return String(e??"").trim()}function Io(e=null){let t=Number(e);return Number.
|
|
843
|
+
isSafeInteger(t)&&t>=0?t:null}function C(e=""){let t=R(e);return t?Br.resolve(t):""}function Pe(e="",t=""){let r=C(e),n=C(
|
|
844
|
+
t);if(!r||!n)return!1;let o=Br.relative(r,n);return o!==".."&&!o.startsWith(`..${Br.sep}`)&&!Br.isAbsolute(o)}function J(e={}){
|
|
845
|
+
return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}function le(e={}){return Object.fromEntries(Object.entries(J(e)).map(
|
|
846
|
+
([t,r])=>[R(t),String(r??"")]).filter(([t])=>!!t))}function ze(e=[]){let t=[],r=new Set;for(let n of Array.isArray(e)?e:
|
|
847
|
+
[e]){let o=R(n);!o||r.has(o)||(r.add(o),t.push(o))}return t}function pt(e){let t=Date.parse(String(e||"").trim());return Number.
|
|
848
|
+
isFinite(t)?t:0}function Ie(...e){for(let t of e){let r=R(t);if(r)return r}return""}var q=g(()=>{});import Nm from"node:os";import To from"node:path";function Ao(e={}){let t=R(e.username),r=C(e.home||(t?`/home/${t}`:Nm.homedir()));
|
|
849
|
+
return{displayName:R(e.displayName||t),gid:Io(e.gid),home:r,shell:R(e.shell),uid:Io(e.uid),username:t}}function Oo(){return Ao(
|
|
850
|
+
Mt())}async function Po(e="",t={}){return Ao(await Vr(e,t))}function Dt(e={},t={}){let r=Ao(e);return{...t,HOME:r.home,LOGNAME:r.
|
|
851
|
+
username,USER:r.username,XDG_CACHE_HOME:To.join(r.home,".cache"),XDG_CONFIG_HOME:To.join(r.home,".config"),XDG_DATA_HOME:To.
|
|
852
|
+
join(r.home,".local","share")}}function nc(){return{gid:typeof process.getgid=="function"?process.getgid():null,uid:typeof process.
|
|
853
|
+
getuid=="function"?process.getuid():null}}var mt=g(()=>{Gr();q()});function Cm(e=0){let t=Number(e);return Number.isSafeInteger(t)?t:1}function Ut({code:e="",error:t="",exitCode:r=0,ok:n=null,
|
|
854
|
+
output:o="",outputEncoding:i="utf8",pid:s=null,signal:a="",stderr:c="",stdout:l="",timedOut:u=!1,execution:m=null,retryable:f=null}={}){
|
|
855
|
+
let h=Cm(r),w=String(l||""),I=String(c||""),S=String(o||[w,I].filter(Boolean).join(`
|
|
856
|
+
`)).trim();return{code:R(e),error:R(t),exitCode:h,ok:n===null?h===0:n===!0,output:S,pid:Number.isSafeInteger(Number(s))?
|
|
857
|
+
Number(s):null,signal:R(a),stderr:I,stdout:w,...i==="base64"?{outputEncoding:i}:{},timedOut:u===!0,...m&&typeof m=="obje\
|
|
858
|
+
ct"&&!Array.isArray(m)?{execution:m}:{},...typeof f=="boolean"?{retryable:f}:{}}}function X(e="",t="vibe64_command_faile\
|
|
859
|
+
d",r={}){let n=R(e)||"Vibe64 command failed.";return Ut({...r,code:t,error:n,exitCode:1,ok:!1,output:R(r.output)||n,stderr:r.
|
|
860
|
+
stderr??(r.outputEncoding==="base64"?Buffer.from(n).toString("base64"):n),stdout:r.stdout??""})}var Fe=g(()=>{q()});import{spawn as km}from"node:child_process";import{statSync as xm}from"node:fs";import $m from"node:path";import{StringDecoder as jm}from"node:string_decoder";
|
|
861
|
+
import{stripVTControlCharacters as Lm}from"node:util";function ac(e){return e.replaceAll(Um,t=>{if(ic[t]!==void 0)return ic[t];
|
|
862
|
+
let r=t.codePointAt(0);return r<=65535?`\\u${r.toString(16).padStart(4,"0")}`:`\\U${r.toString(16)}`})}function Vm(e){return Lm(
|
|
853
863
|
e).split(`
|
|
854
|
-
`).map(
|
|
855
|
-
`)}function
|
|
856
|
-
'"','""')}"`:`'${n.replaceAll("'","'\\''")}'`}).join(" ")}function
|
|
857
|
-
return r;try{if(!
|
|
864
|
+
`).map(ac).join(`
|
|
865
|
+
`)}function Gm(e,t){return[e,...t].map(r=>{let n=ac(String(r));return Dm.test(n)?n:process.platform==="win32"?`"${n.replaceAll(
|
|
866
|
+
'"','""')}"`:`'${n.replaceAll("'","'\\''")}'`}).join(" ")}function Bm(e,t){let r=String(e?.message??e);if(t===process.cwd())
|
|
867
|
+
return r;try{if(!xm(t).isDirectory())return`The "cwd" option is not a directory: ${t}.
|
|
858
868
|
${r}`}catch(n){return`The "cwd" option is invalid: ${t}.
|
|
859
869
|
${n.message}
|
|
860
|
-
${r}`}return r}function
|
|
870
|
+
${r}`}return r}function Hm(e){let t=e.forcefullyTerminated?` and was forcefully terminated after ${sc} milliseconds`:"";
|
|
861
871
|
if(e.timedOut)return`Command timed out after ${e.timeout} milliseconds${t}`;if(e.maxBuffer)return`Command's ${e.maxBuffer.
|
|
862
872
|
stream} was larger than ${e.maxBuffer.limit} ${e.maxBuffer.unit}${t}`;if(e.spawnError?.code!==void 0)return`Command fail\
|
|
863
|
-
ed with ${e.spawnError.code}${t}`;if(e.signal){let r=
|
|
864
|
-
""}`}return e.exitCode!==void 0?`Command failed with exit code ${e.exitCode}`:"Command failed"}function
|
|
865
|
-
|
|
866
|
-
${t}`:""}`}function
|
|
873
|
+
ed with ${e.spawnError.code}${t}`;if(e.signal){let r=Mm[e.signal];return`Command was killed with ${e.signal}${r?` (${r})`:
|
|
874
|
+
""}`}return e.exitCode!==void 0?`Command failed with exit code ${e.exitCode}`:"Command failed"}function zm(e){let t=e.spawnError?
|
|
875
|
+
Vm(Bm(e.spawnError,e.cwd)):e.maxBuffer?"maxBuffer exceeded":"";return`${Hm(e)}: ${e.commandLine}${t?`
|
|
876
|
+
${t}`:""}`}function Ro(e,t){let r=new jm(e),n=[],o=0,i=!1;return{write(s){if(i)return!1;let a=r.write(s);return o+a.length>
|
|
867
877
|
t?(n.push(a.slice(0,t-o)),o=t,i=!0,!1):(n.push(a),o+=a.length,!0)},text(){if(!i){let s=r.end();s&&n.push(s.slice(0,t-o)),
|
|
868
|
-
i=!0}return n.join("")}}}function
|
|
869
|
-
utf8",timeout:c=0}={}){let
|
|
870
|
-
f=
|
|
871
|
-
h={commandLine:
|
|
872
|
-
|
|
873
|
-
()=>{!
|
|
874
|
-
{limit:
|
|
878
|
+
i=!0}return n.join("")}}}function cc(e,t,{cwd:r="",env:n={},input:o=void 0,maxBuffer:i=oc,onOutput:s=null,outputEncoding:a="\
|
|
879
|
+
utf8",timeout:c=0}={}){let l=Number.isSafeInteger(i)&&i>0?i:oc,u={all:Ro(a,l*2),stderr:Ro(a,l),stdout:Ro(a,l)},m=o!=null,
|
|
880
|
+
f=km(e,t,{cwd:r||void 0,detached:process.platform!=="win32",env:n,stdio:[m?"pipe":"ignore","pipe","pipe"],windowsHide:!0}),
|
|
881
|
+
h={commandLine:Gm(e,t),cwd:$m.resolve(r||"."),forcefullyTerminated:!1,maxBuffer:null,spawnError:null,timedOut:!1,timeout:c},
|
|
882
|
+
w=!1,I=null,S=()=>{};f.on("error",v=>{h.spawnError||=v,f.pid===void 0&&S()});let d=()=>{w||!f.kill("SIGTERM")||I||(I=setTimeout(
|
|
883
|
+
()=>{!w&&f.kill("SIGKILL")&&(h.forcefullyTerminated=!0)},sc))},p=(v,y)=>E=>{if(u.all.write(E),u[v].write(E)||(h.maxBuffer||=
|
|
884
|
+
{limit:l,stream:v,unit:"characters"},y.destroy()),typeof s=="function")try{s(String(E||""))}catch{}};f.stdout&&f.stdout.
|
|
875
885
|
on("data",p("stdout",f.stdout)),f.stderr&&f.stderr.on("data",p("stderr",f.stderr)),m&&f.stdin&&(f.stdin.on("error",()=>{}),
|
|
876
|
-
f.stdin.end(o));let _=c>0?setTimeout(()=>{h.timedOut=!0,d()},c):null;return{completion:new Promise(v=>{S=(
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
shortMessage:
|
|
880
|
-
once("close",S)}),kill:v=>f.kill(v),pid:f.pid}}var
|
|
886
|
+
f.stdin.end(o));let _=c>0?setTimeout(()=>{h.timedOut=!0,d()},c):null;return{completion:new Promise(v=>{S=(y,E)=>{if(w)return;
|
|
887
|
+
w=!0,clearTimeout(_),clearTimeout(I);let A=h.spawnError?{}:{exitCode:typeof y=="number"&&y>=0?y:void 0,signal:E||void 0},
|
|
888
|
+
T=h.spawnError||h.timedOut||h.maxBuffer||A.exitCode!==0;v({all:u.all.text(),code:h.spawnError?.code,exitCode:A.exitCode,
|
|
889
|
+
shortMessage:T?zm({...h,...A}):"",signal:A.signal,stderr:u.stderr.text(),stdout:u.stdout.text(),timedOut:h.timedOut})},f.
|
|
890
|
+
once("close",S)}),kill:v=>f.kill(v),pid:f.pid}}var oc,sc,Mm,Dm,Um,ic,lc=g(()=>{oc=1e8,sc=5e3,Mm=Object.freeze({SIGABRT:"\
|
|
881
891
|
Aborted",SIGALRM:"Timeout or timer",SIGHUP:"Terminal closed",SIGINT:"User interruption with CTRL-C",SIGKILL:"Forced term\
|
|
882
892
|
ination",SIGPIPE:"Broken pipe or socket",SIGQUIT:"User interruption with CTRL-\\",SIGSEGV:"Segmentation fault",SIGTERM:"\
|
|
883
|
-
Termination",SIGUSR1:"Application-specific signal",SIGUSR2:"Application-specific signal"}),
|
|
884
|
-
"\\p{Separator}|\\p{Other}","gu"),
|
|
885
|
-
import
|
|
886
|
-
let t=
|
|
893
|
+
Termination",SIGUSR1:"Application-specific signal",SIGUSR2:"Application-specific signal"}),Dm=/^[\w./-]+$/u,Um=new RegExp(
|
|
894
|
+
"\\p{Separator}|\\p{Other}","gu"),ic=Object.freeze({" ":" ","\b":"\\b","\f":"\\f","\n":"\\n","\r":"\\r"," ":"\\t"})});import{spawn as pc}from"node:child_process";import{mkdir as qm,open as Wm,readdir as Ym,readFile as Jm}from"node:fs/promises";
|
|
895
|
+
import Km from"node:path";import{fileURLToPath as Xm}from"node:url";function tf(e){if(process.platform!=="win32"){if(!de){
|
|
896
|
+
let t=pc(process.execPath,[ef],{cwd:"/",detached:!0,stdio:["pipe","ignore","ignore"]});t.once("error",()=>{de===t&&(de=null)}),
|
|
887
897
|
t.once("exit",()=>{de===t&&(de=null)}),t.stdin.on("error",()=>{}),t.unref(),t.stdin.unref(),de=t;for(let r of qe.values())
|
|
888
898
|
r.scopeEmpty!==!0&&r.pid!==e&&t.stdin.write(`+${r.pid}
|
|
889
899
|
`)}de.stdin.write(`+${e}
|
|
890
|
-
`)}}function
|
|
891
|
-
`),![...qe.values()].some(t=>t.scopeEmpty!==!0)&&(de.stdin.end(),de=null))}async function
|
|
892
|
-
dirname(e),{recursive:!0}),
|
|
893
|
-
!0,i(s))};e.once("spawn",()=>o(t)),e.once("error",i=>o(r,i))})}async function
|
|
894
|
-
try{o=await
|
|
895
|
-
detached:!0,env:n,stdio:i});await
|
|
896
|
-
s.pid)),s.once("exit",()=>{!
|
|
897
|
-
s.unref(),Ut({execution:e.execution,exitCode:0,ok:!0,output:"Detached command started.",pid:s.pid})}catch(i){return
|
|
900
|
+
`)}}function rf(e){de&&(de.stdin.write(`-${e}
|
|
901
|
+
`),![...qe.values()].some(t=>t.scopeEmpty!==!0)&&(de.stdin.end(),de=null))}async function nf(e=""){return e?(await qm(Km.
|
|
902
|
+
dirname(e),{recursive:!0}),Wm(e,"w",384)):null}async function of(e){return new Promise((t,r)=>{let n=!1,o=(i,s)=>{n||(n=
|
|
903
|
+
!0,i(s))};e.once("spawn",()=>o(t)),e.once("error",i=>o(r,i))})}async function mc(e={},t={}){let{cwd:r="",env:n={}}=t,o=null;
|
|
904
|
+
try{o=await nf(e.logPath);let i=o?["ignore",o.fd,o.fd]:["ignore","ignore","ignore"],s=pc(e.command,e.args,{cwd:r||void 0,
|
|
905
|
+
detached:!0,env:n,stdio:i});await of(s);let a=e.execution?.id||"";return a&&(qe.set(a,{child:s,pid:Number(s.pid)}),tf(Number(
|
|
906
|
+
s.pid)),s.once("exit",()=>{!Hr(s.pid)&&qe.has(a)&&(qe.set(a,{child:s,pid:Number(s.pid),scopeEmpty:!0}),rf(Number(s.pid)))})),
|
|
907
|
+
s.unref(),Ut({execution:e.execution,exitCode:0,ok:!0,output:"Detached command started.",pid:s.pid})}catch(i){return X(i?.
|
|
898
908
|
message||"Detached command failed to start.",i?.code||"vibe64_command_detached_failed",{execution:e.execution})}finally{
|
|
899
|
-
await o?.close().catch(()=>null)}}function
|
|
909
|
+
await o?.close().catch(()=>null)}}function Hr(e=null){let t=Number(e);if(!Number.isSafeInteger(t)||t<=0)return!1;if(process.
|
|
900
910
|
platform==="win32"){let r=[...qe.values()].find(n=>n.pid===t);return r?.child?.exitCode===null&&r?.child?.signalCode===null}
|
|
901
|
-
try{return process.kill(-t,0),!0}catch(r){return r?.code==="EPERM"}}function
|
|
911
|
+
try{return process.kill(-t,0),!0}catch(r){return r?.code==="EPERM"}}function uc(e=null,t="SIGTERM"){if(!Hr(e))return!1;try{
|
|
902
912
|
return process.platform==="win32"?[...qe.values()].find(n=>n.pid===Number(e))?.child?.kill(t):process.kill(-Number(e),t),
|
|
903
|
-
!0}catch(r){if(r?.code==="ESRCH")return!1;throw r}}async function
|
|
904
|
-
"linux"||!Number.isSafeInteger(r)||r<=0)return[];let n=[];for(let o of await
|
|
905
|
-
if(!/^\d+$/u.test(o))continue;let i=await
|
|
906
|
-
s+2).split(" ");Number(a[2])!==r||a[0]==="Z"||n.push({command:i.slice(i.indexOf("(")+1,s),pid:Number(o)})}return n}async function
|
|
907
|
-
let r=Date.now()+Math.max(0,Number(t)||0);for(;
|
|
908
|
-
async function
|
|
909
|
-
(
|
|
910
|
-
cution/src/server/engines/detached.js",import.meta.url).href,qe=new Map,
|
|
911
|
-
|
|
912
|
-
outputEncoding:
|
|
913
|
-
if(
|
|
914
|
-
maxBuffer:a,onOutput:c,outputEncoding:
|
|
915
|
-
A=
|
|
916
|
-
i.id,h),
|
|
917
|
-
b.completion:{exitCode:1})]),E=typeof
|
|
918
|
-
re_timed_out":
|
|
919
|
-
|
|
920
|
-
f=
|
|
921
|
-
if(!await(
|
|
922
|
-
"The command finished",
|
|
923
|
-
`${v}, and its execution scope did not become empty${
|
|
924
|
-
outputEncoding:
|
|
925
|
-
|
|
926
|
-
execution:_,outputEncoding:
|
|
927
|
-
sharedCacheRoot:"",execHelperPath:"",sharedGroupAccess:!1})});function
|
|
928
|
-
r running commands as another user.");throw r.code="vibe64_exec_helper_unavailable",r}return t}function
|
|
929
|
-
...e,schema:
|
|
930
|
-
and",args:s=[]}={}){return
|
|
913
|
+
!0}catch(r){if(r?.code==="ESRCH")return!1;throw r}}async function fc(e=null,t=10){let r=Number(e);if(process.platform!==
|
|
914
|
+
"linux"||!Number.isSafeInteger(r)||r<=0)return[];let n=[];for(let o of await Ym("/proc").catch(()=>[])){if(n.length>=t)break;
|
|
915
|
+
if(!/^\d+$/u.test(o))continue;let i=await Jm(`/proc/${o}/stat`,"utf8").catch(()=>""),s=i.lastIndexOf(")"),a=s<0?[]:i.slice(
|
|
916
|
+
s+2).split(" ");Number(a[2])!==r||a[0]==="Z"||n.push({command:i.slice(i.indexOf("(")+1,s),pid:Number(o)})}return n}async function dc(e=null,t=0){
|
|
917
|
+
let r=Date.now()+Math.max(0,Number(t)||0);for(;Hr(e)&&Date.now()<r;)await new Promise(n=>setTimeout(n,25));return!Hr(e)}
|
|
918
|
+
async function zr(e=null,t={}){let{killTimeoutMs:r=Zm,termTimeoutMs:n=Qm}=t;uc(e,"SIGTERM");let o=await dc(e,n);return o||
|
|
919
|
+
(uc(e,"SIGKILL"),o=await dc(e,r)),o}var Fm,qe,Qm,Zm,ef,de,Vt=g(()=>{Fe();Fm=new URL("./../node_modules/@local/vibe64-exe\
|
|
920
|
+
cution/src/server/engines/detached.js",import.meta.url).href,qe=new Map,Qm=3e3,Zm=1e3,ef=Xm(new URL("./detachedReaper.js",
|
|
921
|
+
Fm)),de=null});async function Gt(e="",t=[],r={}){let{cwd:n="",env:o={},execution:i=null,input:s=void 0,maxBuffer:a=void 0,onOutput:c=null,
|
|
922
|
+
outputEncoding:l="utf8",signal:u=null,timeout:m=15e3}=r,f,h,w,I=null,S=Promise.withResolvers(),d=()=>{w||=h(),w.then(S.resolve)};
|
|
923
|
+
if(u?.aborted)return X("Command cancelled.","vibe64_command_cancelled",{execution:i});try{let b=cc(e,t,{cwd:n,env:o,input:s,
|
|
924
|
+
maxBuffer:a,onOutput:c,outputEncoding:l,timeout:m});I=Number(b.pid);let v;h=()=>{if(!v){let A;process.platform!=="win32"?
|
|
925
|
+
A=zr(I).catch(()=>!1):(b.kill("SIGKILL"),A=b.completion.then(()=>!0)),v=A.then(T=>(T||(v=null),T))}return v},i?.id&&hc.set(
|
|
926
|
+
i.id,h),u?.addEventListener("abort",d,{once:!0}),u?.aborted&&d();let y=await Promise.race([b.completion,S.promise.then(A=>A?
|
|
927
|
+
b.completion:{exitCode:1})]),E=typeof y.exitCode=="number"?y.exitCode:1;f=Ut({code:y.timedOut===!0?"vibe64_command_captu\
|
|
928
|
+
re_timed_out":y.code?"vibe64_command_capture_failed":"",error:E===0?"":y.shortMessage,exitCode:E,output:y.all||(E===0?"":
|
|
929
|
+
y.shortMessage),outputEncoding:l,signal:y.signal,stderr:y.stderr,stdout:y.stdout,timedOut:y.timedOut===!0,execution:i})}catch(b){
|
|
930
|
+
f=X(b.message,"vibe64_command_capture_failed",{execution:i,outputEncoding:l})}finally{u?.removeEventListener("abort",d)}
|
|
931
|
+
if(!await(w||h?.()||!0)){let b=await fc(I),v=f?.timedOut?"The command timed out":u?.aborted?"The command was cancelled":
|
|
932
|
+
"The command finished",y=b.length?`: ${b.map(E=>`${E.command} (pid ${E.pid})`).join(", ")} still running`:"";return{...X(
|
|
933
|
+
`${v}, and its execution scope did not become empty${y}.`,"vibe64_execution_drain_failed",{execution:i,output:f?.output,
|
|
934
|
+
outputEncoding:l,signal:f?.signal,stderr:f?.stderr,stdout:f?.stdout,timedOut:f?.timedOut}),remainingProcesses:b}}i?.id&&
|
|
935
|
+
hc.delete(i.id);let _=i&&{...i,state:"finished"};return u?.aborted?X("Command cancelled.","vibe64_command_cancelled",{...f,
|
|
936
|
+
execution:_,outputEncoding:l}):_?{...f,execution:_}:f}var hc,Bt=g(()=>{Fe();lc();Vt();hc=new Map});function he(){return globalThis[sf]||af}var sf,af,Re=g(()=>{sf=Symbol.for("vibe64.hostProfile"),af=Object.freeze({runtimePackRoot:"",
|
|
937
|
+
sharedCacheRoot:"",execHelperPath:"",sharedGroupAccess:!1})});function No(e=""){let t=String(e||"").trim()||he().execHelperPath;if(!t){let r=new Error("This computer has no helper fo\
|
|
938
|
+
r running commands as another user.");throw r.code="vibe64_exec_helper_unavailable",r}return t}function gc(e={}){return{
|
|
939
|
+
...e,schema:cf,schemaVersion:lf}}function Fr({actor:e={},command:t="",cwd:r="",env:n={},input:o,operation:i="vibe64-comm\
|
|
940
|
+
and",args:s=[]}={}){return gc({args:Array.isArray(s)?s.map(a=>String(a)):[],command:t,cwd:r,env:n,gid:e.user?.gid,home:e.
|
|
931
941
|
user?.home,inputBase64:o==null?"":Buffer.isBuffer(o)?o.toString("base64"):Buffer.from(String(o)).toString("base64"),operation:i,
|
|
932
942
|
uid:e.user?.uid,username:e.user?.username})}function Ht(e={}){return e.mode==="pty"&&e.envPolicy==="auth"&&!["assistant",
|
|
933
943
|
"codex"].includes(e.purpose)?"account-auth-terminal":e.purpose==="codex"&&e.mode==="capture"&&e.envPolicy==="auth"||e.purpose===
|
|
@@ -936,87 +946,87 @@ uid:e.user?.uid,username:e.user?.username})}function Ht(e={}){return e.mode==="p
|
|
|
936
946
|
includes(e.execution?.operationId)||e.mode==="capture"&&e.execution?.kind==="assistant"&&e.execution?.operationId==="ope\
|
|
937
947
|
ncode-catalog"?"opencode-app-server":e.purpose==="account"?"account-status":e.purpose==="github"?"github-workflow-comman\
|
|
938
948
|
d":e.purpose==="github-api"?"github-api-command":e.purpose==="workspace-cache"?"workspace-cache-command":e.purpose==="he\
|
|
939
|
-
alth"?"health-status":"vibe64-command"}async function
|
|
949
|
+
alth"?"health-status":"vibe64-command"}async function Co(e={},{env:t,helperPath:r="",maxBuffer:n=void 0,outputEncoding:o="\
|
|
940
950
|
utf8",runCapture:i=Gt,signal:s=null,timeout:a=15e3}){let c={env:t,input:`${JSON.stringify(e)}
|
|
941
951
|
`,outputEncoding:o,signal:s,timeout:a};return Number.isSafeInteger(Number(n))&&Number(n)>0&&(c.maxBuffer=Number(n)),i("s\
|
|
942
|
-
udo",["-n",
|
|
943
|
-
upport/symlinkSafeRequire.js",import.meta.url).href,
|
|
944
|
-
{callbackPath:"/auth/login",customScheme:"",appLinkDomains:Object.freeze([])})
|
|
945
|
-
targetSdk:35,versionCode:1,versionName:"1.0.0"})});var
|
|
946
|
-
freeze(["capabilities","kind","metadata","migrations","runtime","vite"])});var
|
|
947
|
-
function
|
|
948
|
-
let n=String(e||"").trim();if(!n||!
|
|
949
|
-
th.`,r);return n}function
|
|
952
|
+
udo",["-n",No(r),"execute"],c)}var cf,lf,qr=g(()=>{Bt();Re();cf="vibe64.exec-helper.payload",lf=1});import{createRequire as df}from"node:module";var uf,Rv,wc=g(()=>{uf=new URL("./../node_modules/@jskit-ai/kernel/server/s\
|
|
953
|
+
upport/symlinkSafeRequire.js",import.meta.url).href,Rv=df(uf)});var jv,Lv,Mv,Dv,yc=g(()=>{G();jv=Object.freeze(["bundled","dev_server"]),Lv=Object.freeze(["capacitor"]),Mv=Object.freeze(
|
|
954
|
+
{callbackPath:"/auth/login",customScheme:"",appLinkDomains:Object.freeze([])}),Dv=Object.freeze({packageName:"",minSdk:26,
|
|
955
|
+
targetSdk:35,versionCode:1,versionName:"1.0.0"})});var _c=g(()=>{G();yc()});var ko=g(()=>{});var xo=g(()=>{});var Ec=g(()=>{ko();G();xo()});var bc=g(()=>{});var nS,oS,vc=g(()=>{jt();G();bc();ko();nS=Object.freeze(["dependencies","optionalDependencies","peerDependencies"]),oS=Object.
|
|
956
|
+
freeze(["capabilities","kind","metadata","migrations","runtime","vite"])});var $o=g(()=>{G()});import ff from"node:child_process";import{constants as jo}from"node:fs";import{open as hf}from"node:fs/promises";import Lo from"node:path";
|
|
957
|
+
function Mo(e="",t=Do){let r=new Error(e||"Exclusive file lock failed.");return r.code=t,r}function Sc(e="",t="path",r=Do){
|
|
958
|
+
let n=String(e||"").trim();if(!n||!Lo.isAbsolute(n)||Lo.normalize(n)!==n)throw Mo(`${t} must be a normalized absolute pa\
|
|
959
|
+
th.`,r);return n}function wf(e,t){return new Promise((r,n)=>{let o=ff.spawn("/usr/bin/flock",["--exclusive","--nonblock",
|
|
950
960
|
"3"],{cwd:t,env:{PATH:"/usr/bin:/bin"},stdio:["ignore","ignore","pipe",e]}),i="";o.stderr.on("data",s=>{i=`${i}${String(
|
|
951
|
-
s||"")}`.slice(-4096)}),o.once("error",n),o.once("close",s=>r({status:s,stderr:i.trim()}))})}async function
|
|
952
|
-
errorCode:r=
|
|
953
|
-
432),s;try{s=await
|
|
954
|
-
ck failed."),r)}if(s.status!==0){if(await i.close(),s.status===
|
|
955
|
-
ed${s.stderr?`: ${s.stderr}`:"."}`,r)}let a=!1;return async()=>{a||(a=!0,await i.close())}}var
|
|
956
|
-
lock_failed",
|
|
957
|
-
session?.metadata?.session_git_command_actor_user_key)}async function
|
|
958
|
-
e.applicationAccount)return{actor:t,applicationAccount:!0,credentialScope:t,requiresRealUser:!1,user:await
|
|
959
|
-
if(t==="daemon"||t==="app")return{actor:t,credentialScope:t,requiresRealUser:!1,user:
|
|
961
|
+
s||"")}`.slice(-4096)}),o.once("error",n),o.once("close",s=>r({status:s,stderr:i.trim()}))})}async function ft(e="",{cwd:t="",
|
|
962
|
+
errorCode:r=Do}={}){let n=Sc(e,"lockPath",r),o=t?Sc(t,"cwd",r):Lo.dirname(n),i=await hf(n,jo.O_CREAT|jo.O_NOFOLLOW|jo.O_RDWR,
|
|
963
|
+
432),s;try{s=await wf(i.fd,o)}catch(c){throw await i.close().catch(()=>null),Mo(c?.message||String(c||"Exclusive file lo\
|
|
964
|
+
ck failed."),r)}if(s.status!==0){if(await i.close(),s.status===gf)return null;throw Mo(`Exclusive file lock process fail\
|
|
965
|
+
ed${s.stderr?`: ${s.stderr}`:"."}`,r)}let a=!1;return async()=>{a||(a=!0,await i.close())}}var Do,gf,Ic=g(()=>{Do="file_\
|
|
966
|
+
lock_failed",gf=1});var yf,mS,Tc=g(()=>{yf="jskit-client-build",mS=new RegExp(`<meta name="${yf}" content="([0-9a-f]+)"`,"u")});import Ef from"node:path";var _S,Ac=g(()=>{Tc();$o();_S=Ef.join("dist","index.html")});var Wr=g(()=>{wc();_c();Ec();xo();vc();$o();Ic();Ac()});var Oc=g(()=>{Wr()});function bf(e={}){return Ie(e.userKey,e.project?.ownerUserKey,e.project?.ownerUsername,e.project?.ownerUser?.username,e.
|
|
967
|
+
session?.metadata?.session_git_command_actor_user_key)}async function Pc(e={}){let t=R(e.actor)||"daemon";if(t==="app"&&
|
|
968
|
+
e.applicationAccount)return{actor:t,applicationAccount:!0,credentialScope:t,requiresRealUser:!1,user:await Po(e.applicationAccount)};
|
|
969
|
+
if(t==="daemon"||t==="app")return{actor:t,credentialScope:t,requiresRealUser:!1,user:Oo()};let r=bf(e);if(!r){let n=new Error(
|
|
960
970
|
"A user key is required for real-user command execution.");throw n.code="vibe64_command_actor_user_required",n}return{actor:t,
|
|
961
|
-
credentialScope:"user",requiresRealUser:!0,user:await
|
|
962
|
-
user?.gid}function
|
|
963
|
-
if(!e.requiresRealUser)return;let n=C(t.session?.sourceRoot||t.session?.sourcePath),o=C(r);if(!n||!o||!
|
|
971
|
+
credentialScope:"user",requiresRealUser:!0,user:await Po(r)}}var Rc=g(()=>{q();mt()});import Nc from"node:path";function ht(e={}){let t=nc();return t.uid===null||t.gid===null||t.uid===e.user?.uid&&t.gid===e.
|
|
972
|
+
user?.gid}function Uo(){return!!he().execHelperPath}function Yr(e={}){return e.requiresRealUser?Uo()||!ht(e):!1}function Cc(e={},t={},r=""){
|
|
973
|
+
if(!e.requiresRealUser)return;let n=C(t.session?.sourceRoot||t.session?.sourcePath),o=C(r);if(!n||!o||!Pe(n,o))return;let i=new Error(
|
|
964
974
|
"Commands in a session's source must run as the editor's own user, not as a person's account.");throw i.code="vibe64_com\
|
|
965
|
-
mand_managed_source_real_user_forbidden",i}function
|
|
966
|
-
if(!(!e.requiresRealUser&&o&&n===o)&&r&&n&&
|
|
967
|
-
he resolved actor home.");throw i.code="vibe64_command_home_actor_mismatch",i}}var
|
|
975
|
+
mand_managed_source_real_user_forbidden",i}function kc(e={},t={}){let r=C(e.user?.home),n=C(t.HOME),o=C(t.VIBE64_CREDENTIAL_HOME);
|
|
976
|
+
if(!(!e.requiresRealUser&&o&&n===o)&&r&&n&&Nc.resolve(r)!==Nc.resolve(n)){let i=new Error("Command HOME does not match t\
|
|
977
|
+
he resolved actor home.");throw i.code="vibe64_command_home_actor_mismatch",i}}var Jr=g(()=>{mt();Re();q()});function Kr(...e){let t={};for(let r of e){let n=le(r);for(let o of zt)n[o]!==void 0&&(t[o]=n[o])}return t}var zt,Xr=g(()=>{
|
|
968
978
|
q();zt=Object.freeze(["DATABASE_URL","DB_CLIENT","DB_DATABASE","DB_HOST","DB_NAME","DB_PASSWORD","DB_PORT","DB_USER","DB\
|
|
969
979
|
_USERNAME","MYSQL_DATABASE","MYSQL_HOST","MYSQL_PWD","MYSQL_TCP_PORT","PGDATABASE","PGHOST","PGPASSWORD","PGPORT","PGUSE\
|
|
970
|
-
R","VIBE64_MYSQL_USER"])});import{spawn as
|
|
971
|
-
import{stat as
|
|
972
|
-
replace(/[^a-z0-9-]+/gu,"-").replace(/^-+|-+$/gu,"").slice(0,63)||t}function
|
|
973
|
-
o=
|
|
980
|
+
R","VIBE64_MYSQL_USER"])});import{spawn as vf,spawnSync as Sf}from"node:child_process";import{createHash as If}from"node:crypto";import{statSync as Uc}from"node:fs";
|
|
981
|
+
import{stat as Vc}from"node:fs/promises";import Qr from"node:path";function $c(e="",t="vibe64"){return R(e).toLowerCase().
|
|
982
|
+
replace(/[^a-z0-9-]+/gu,"-").replace(/^-+|-+$/gu,"").slice(0,63)||t}function Of(...e){for(let t of e){let r=J(t),n=J(r.user),
|
|
983
|
+
o=Ie(r.name,r.userName,r.user_name,r.gitUserName,r.git_user_name,n.name,n.userName,n.user_name),i=Ie(r.email,r.userEmail,
|
|
974
984
|
r.user_email,r.gitUserEmail,r.git_user_email,n.email,n.userEmail,n.user_email);if(o&&i)return{authorEmail:i,authorName:o,
|
|
975
|
-
committerEmail:i,committerName:o,source:"configured"}}return null}function
|
|
976
|
-
t.login,t.username),n=
|
|
977
|
-
committerName:r,source:"github"}}function
|
|
978
|
-
authorEmail:`${r}@${n}${
|
|
979
|
-
fallback"}}function
|
|
980
|
-
isDirectory()?t:""}catch{return""}}async function
|
|
981
|
-
t:""}function
|
|
982
|
-
`)){let n=/^user\.(name|email)(?: (.*))?$/iu.exec(r);n&&(t[n[1].toLowerCase()]=
|
|
983
|
-
...e?{cwd:e}:{},env:t,stdio:["ignore","pipe","ignore"],timeout:
|
|
984
|
-
utf8"});return r.error||r.signal?{transient:!0,values:null}:{transient:!1,values:r.status===0||r.status===1?
|
|
985
|
-
null}}function
|
|
985
|
+
committerEmail:i,committerName:o,source:"configured"}}return null}function Pf(e={}){let t=J(e),r=Ie(t.name,t.displayName,
|
|
986
|
+
t.login,t.username),n=Ie(t.email,t.publicEmail,t.verifiedEmail);return!r||!n?null:{authorEmail:n,authorName:r,committerEmail:n,
|
|
987
|
+
committerName:r,source:"github"}}function Rf({workspace:e="",userKey:t=""}={}){let r=$c(t,"user"),n=$c(e,"local");return{
|
|
988
|
+
authorEmail:`${r}@${n}${xc}`,authorName:`${r} via Vibe64`,committerEmail:`vibe64@${n}${xc}`,committerName:"Vibe64",source:"\
|
|
989
|
+
fallback"}}function Vo(e=""){let t=R(e);return t&&Qr.isAbsolute(t)?t:""}function jc(e=""){let t=Vo(e);try{return t&&Uc(t).
|
|
990
|
+
isDirectory()?t:""}catch{return""}}async function Lc(e=""){let t=Vo(e);return t&&await Vc(t).then(r=>r.isDirectory(),()=>!1)?
|
|
991
|
+
t:""}function Hc(e=""){let t={};for(let r of String(e||"").split(`
|
|
992
|
+
`)){let n=/^user\.(name|email)(?: (.*))?$/iu.exec(r);n&&(t[n[1].toLowerCase()]=R(n[2]))}return t}function zc(e,t){return{
|
|
993
|
+
...e?{cwd:e}:{},env:t,stdio:["ignore","pipe","ignore"],timeout:Tf}}function Mc(e,t){let r=Sf("git",Gc,{...zc(e,t),encoding:"\
|
|
994
|
+
utf8"});return r.error||r.signal?{transient:!0,values:null}:{transient:!1,values:r.status===0||r.status===1?Hc(r.stdout):
|
|
995
|
+
null}}function Dc(e,t){return new Promise(r=>{let n="",o=!1,i=a=>{o||(o=!0,r(a))},s=vf("git",Gc,zc(e,t));s.stdout.setEncoding(
|
|
986
996
|
"utf8"),s.stdout.on("data",a=>{n+=a}),s.once("error",()=>i({transient:!0,values:null})),s.once("close",(a,c)=>i(c?{transient:!0,
|
|
987
|
-
values:null}:{transient:!1,values:a===0||a===1?
|
|
988
|
-
email,authorName:e.name,committerEmail:e.email,committerName:e.name,source:"git-config"}}function
|
|
989
|
-
env.PATH||e.PATH}}function
|
|
990
|
-
e.HOME),r=
|
|
991
|
-
g"):""].filter(Boolean)}async function
|
|
992
|
-
mtimeMs}:${n.ctimeMs}`,()=>"missing")))).join("|")}function
|
|
993
|
-
:${r.size}:${r.mtimeMs}:${r.ctimeMs}`}catch{return"missing"}}).join("|")}function
|
|
994
|
-
([o],[i])=>o<i?-1:o>i?1:0);return
|
|
995
|
-
await
|
|
996
|
-
function
|
|
997
|
-
values:o.values}}function
|
|
998
|
-
r&&We.delete(o);return null}async function
|
|
999
|
-
read).values;let a={expiresAt:i+
|
|
1000
|
-
a&&We.delete(n):a.values=c.values,c.values}function
|
|
1001
|
-
hasOwn(s,"values"))return s.values;let a=
|
|
1002
|
-
revision:o,values:a.values}),a.values}async function
|
|
1003
|
-
let[r,n]=await Promise.all([
|
|
1004
|
-
typeof t!="object"?null:
|
|
1005
|
-
null:{authorEmail:n,authorName:r,committerEmail:n,committerName:r,source:"git-config"}}function
|
|
1006
|
-
project:r={},session:n={}}){let o=
|
|
1007
|
-
VIBE64_GIT_USER_NAME,email:e.VIBE64_GIT_USER_EMAIL})||
|
|
1008
|
-
let i=
|
|
1009
|
-
t.VIBE64_RUNTIME_NAMESPACE),userKey:
|
|
1010
|
-
LOGNAME)})}async function
|
|
1011
|
-
{})||
|
|
1012
|
-
return
|
|
1013
|
-
ME",Je="GIT_AUTHOR_EMAIL",Ke="GIT_COMMITTER_NAME",Xe="GIT_COMMITTER_EMAIL",
|
|
1014
|
-
"--get-regexp","^user\\.(name|email)$"],
|
|
997
|
+
values:null}:{transient:!1,values:a===0||a===1?Hc(n):null}))})}function Fc(e=null){return!e?.name||!e?.email?null:{authorEmail:e.
|
|
998
|
+
email,authorName:e.name,committerEmail:e.email,committerName:e.name,source:"git-config"}}function qc(e={}){return{...e,PATH:process.
|
|
999
|
+
env.PATH||e.PATH}}function Wc(e={}){if(Object.hasOwn(e,"GIT_CONFIG_GLOBAL"))return[String(e.GIT_CONFIG_GLOBAL)];let t=Vo(
|
|
1000
|
+
e.HOME),r=R(e.XDG_CONFIG_HOME)||(t?Qr.join(t,".config"):"");return[r?Qr.join(r,"git","config"):"",t?Qr.join(t,".gitconfi\
|
|
1001
|
+
g"):""].filter(Boolean)}async function Nf(e={}){return(await Promise.all(Wc(e).map(r=>Vc(r).then(n=>`${n.ino}:${n.size}:${n.
|
|
1002
|
+
mtimeMs}:${n.ctimeMs}`,()=>"missing")))).join("|")}function Cf(e={}){return Wc(e).map(t=>{try{let r=Uc(t);return`${r.ino}\
|
|
1003
|
+
:${r.size}:${r.mtimeMs}:${r.ctimeMs}`}catch{return"missing"}}).join("|")}function Yc(e,t,r){let n=Object.entries(r).sort(
|
|
1004
|
+
([o],[i])=>o<i?-1:o>i?1:0);return If("sha256").update(JSON.stringify([e,t,n])).digest("hex")}async function kf(e,t,r){let n=e?
|
|
1005
|
+
await Dc(e,r):null;if(n?.values)return n;let o=await Dc(t,r);return{transient:!!(n?.transient||o.transient),values:o.values}}
|
|
1006
|
+
function xf(e,t,r){let n=e?Mc(e,r):null;if(n?.values)return n;let o=Mc(t,r);return{transient:!!(n?.transient||o.transient),
|
|
1007
|
+
values:o.values}}function Jc(e,t,r){let n=We.get(e);if(n&&n.revision===t&&n.expiresAt>r)return n;for(let[o,i]of We)i.expiresAt<=
|
|
1008
|
+
r&&We.delete(o);return null}async function $f(e,t,r){let n=Yc(e,t,r),o=await Nf(r),i=Date.now(),s=Jc(n,o,i);if(s)return(await s.
|
|
1009
|
+
read).values;let a={expiresAt:i+Bc,read:kf(e,t,r),revision:o};We.set(n,a);let c=await a.read;return c.transient?We.get(n)===
|
|
1010
|
+
a&&We.delete(n):a.values=c.values,c.values}function jf(e,t,r){let n=Yc(e,t,r),o=Cf(r),i=Date.now(),s=Jc(n,o,i);if(s&&Object.
|
|
1011
|
+
hasOwn(s,"values"))return s.values;let a=xf(e,t,r);return a.transient||We.set(n,{expiresAt:i+Bc,read:Promise.resolve(a),
|
|
1012
|
+
revision:o,values:a.values}),a.values}async function Lf({cwd:e="",env:t=null}={}){if(!t||typeof t!="object")return null;
|
|
1013
|
+
let[r,n]=await Promise.all([Lc(e),Lc(t.HOME)]);return Fc(await $f(r,n,qc(t)))}function Mf({cwd:e="",env:t=null}={}){return!t||
|
|
1014
|
+
typeof t!="object"?null:Fc(jf(jc(e),jc(t.HOME),qc(t)))}function Df(e={}){let t=J(e),r=R(t.name),n=R(t.email);return!r||!n?
|
|
1015
|
+
null:{authorEmail:n,authorName:r,committerEmail:n,committerName:r,source:"git-config"}}function Kc({env:e,personGitIdentity:t=null,
|
|
1016
|
+
project:r={},session:n={}}){let o=J(n.metadata);return Of(r.gitIdentity,r.config?.git,n.gitIdentity,o.git_identity,{name:e.
|
|
1017
|
+
VIBE64_GIT_USER_NAME,email:e.VIBE64_GIT_USER_EMAIL})||Df(t)}function Xc({actor:e={},env:t,project:r={},session:n={},userKey:o=""}){
|
|
1018
|
+
let i=J(n.metadata);return Pf(r.githubUser||n.githubUser||i.github_user)||Rf({workspace:Ie(r.workspace,t.VIBE64_WORKSPACE,
|
|
1019
|
+
t.VIBE64_RUNTIME_NAMESPACE),userKey:Ie(o,e.user?.username,t.VIBE64_GIT_USER_KEY,t.VIBE64_USER_KEY,t.VIBE64_USER,t.USER,t.
|
|
1020
|
+
LOGNAME)})}async function Uf(e){return Kc(e)||await Lf(e.gitConfig||{})||Xc(e)}function Vf(e){return Kc(e)||Mf(e.gitConfig||
|
|
1021
|
+
{})||Xc(e)}function Qc(e){return{[Je]:e.authorEmail,[Ye]:e.authorName,[Xe]:e.committerEmail,[Ke]:e.committerName}}async function Zc(e){
|
|
1022
|
+
return Qc(await Uf(e))}function el(e){return Qc(Vf(e))}var Ye,Je,Ke,Xe,xc,Tf,Gc,Bc,Af,We,gt=g(()=>{q();Ye="GIT_AUTHOR_NA\
|
|
1023
|
+
ME",Je="GIT_AUTHOR_EMAIL",Ke="GIT_COMMITTER_NAME",Xe="GIT_COMMITTER_EMAIL",xc=".users.vibe64.invalid",Tf=2e3,Gc=["config",
|
|
1024
|
+
"--get-regexp","^user\\.(name|email)$"],Bc=3e4,Af=['git config --global user.name "Your Name"','git config --global user\
|
|
1015
1025
|
.email "you@example.com"'].join(`
|
|
1016
|
-
`);We=new Map});import
|
|
1017
|
-
|
|
1018
|
-
let e=
|
|
1019
|
-
|
|
1026
|
+
`);We=new Map});import Go from"node:path";function Q({root:e=""}={}){return C(e||he().runtimePackRoot)}function Ho(e=""){let t=Q();return(t?
|
|
1027
|
+
wt[R(e)]?.binDirs||[]:[]).map(n=>Go.join(t,n))}function tl(){let e=Q();return e?[Go.join(e,"guard-bin")]:[]}function zo(){
|
|
1028
|
+
let e=Q();return e?[Go.join(e,"policy-bin")]:[]}function Gf(e=""){let t=R(e);return[...wt[t]?.managedCommands||[]]}var wt,
|
|
1029
|
+
Bo,lI,ge=g(()=>{q();Re();wt=Object.freeze({awsebcli:{binDirs:["awsebcli/bin"],managedCommands:["eb"]},bubblewrap:{binDirs:[
|
|
1020
1030
|
"bubblewrap/bin"],managedCommands:[]},bun:{binDirs:["bun/bin"],dependencyFiles:["package.json","bun.lock","bun.lockb","p\
|
|
1021
1031
|
ackage-lock.json"],managedCommands:["bun"]},composer:{binDirs:["composer/bin"],dependencyFiles:["composer.json","compose\
|
|
1022
1032
|
r.lock"],managedCommands:["composer"]},cpp:{binDirs:["cpp/bin"],dependencyFiles:["CMakeLists.txt","vcpkg.json","vcpkg-co\
|
|
@@ -1045,275 +1055,277 @@ tor-clis/lib/node_modules/opencode-ai/package.json"],managedCommands:["claude","
|
|
|
1045
1055
|
in"],managedCommands:["php"]},playwright:{binDirs:["playwright/bin"],identityPaths:["playwright/runtime.env","playwright\
|
|
1046
1056
|
/browsers"],managedCommands:["playwright"]},postgresql:{binDirs:["postgresql/bin"],managedCommands:["initdb","pg_ctl","p\
|
|
1047
1057
|
g_isready","postgres","psql"]},ripgrep:{binDirs:["ripgrep/bin"],managedCommands:[]},sqlite:{binDirs:["sqlite/bin"],managedCommands:[
|
|
1048
|
-
"sqlite3"]}}),
|
|
1049
|
-
ubblewrap","bun","php","composer","awsebcli","cpp","python","ruby","go","java","kotlin","csharp","rust","playwright"]);
|
|
1050
|
-
Object.freeze({runtimePackManagedCommands:
|
|
1051
|
-
if(!t)return"";let r=
|
|
1052
|
-
/\r?\n/u).filter(i=>i.startsWith("playwright_version=")).map(i=>i.slice(19).trim());if(o.length!==1||!
|
|
1053
|
-
`Invalid managed Playwright runtime manifest: ${r}.`);return o[0]}function
|
|
1054
|
-
r=C(he().sharedCacheRoot),n=
|
|
1055
|
-
{[
|
|
1056
|
-
ATH",
|
|
1057
|
-
|
|
1058
|
-
llers cannot provide execution policy env: ${t}.`);throw r.code="vibe64_command_env_policy_reserved",r}}function
|
|
1059
|
-
let{envPolicy:r="session"}=t,n=
|
|
1060
|
-
"deployment"?o:{...o,...
|
|
1058
|
+
"sqlite3"]}}),Bo=Object.freeze(["operator-clis","node26","git","gh","mysql","mariadb","postgresql","sqlite","ripgrep","b\
|
|
1059
|
+
ubblewrap","bun","php","composer","awsebcli","cpp","python","ruby","go","java","kotlin","csharp","rust","playwright"]);lI=
|
|
1060
|
+
Object.freeze({runtimePackManagedCommands:Gf})});import{readFileSync as Bf}from"node:fs";import rl from"node:path";function qf({runtimePackRoot:e=""}={}){let t=Q({root:e});
|
|
1061
|
+
if(!t)return"";let r=rl.join(t,nl,zf),n;try{n=Bf(r,"utf8")}catch(i){if(i?.code==="ENOENT")return"";throw i}let o=n.split(
|
|
1062
|
+
/\r?\n/u).filter(i=>i.startsWith("playwright_version=")).map(i=>i.slice(19).trim());if(o.length!==1||!Ff.test(o[0]))throw new Error(
|
|
1063
|
+
`Invalid managed Playwright runtime manifest: ${r}.`);return o[0]}function ol({runtimePackRoot:e=""}={}){let t=Q({root:e}),
|
|
1064
|
+
r=C(he().sharedCacheRoot),n=qf({runtimePackRoot:t});return{...r?{[Zr]:r}:{},...t?{[Ft]:rl.join(t,nl,Hf),[Fo]:"1"}:{},...n?
|
|
1065
|
+
{[qo]:n}:{}}}var Zr,Ft,Fo,qo,nl,Hf,zf,Ff,qt=g(()=>{q();Re();ge();Zr="VIBE64_SHARED_CACHE_ROOT",Ft="PLAYWRIGHT_BROWSERS_P\
|
|
1066
|
+
ATH",Fo="PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD",qo="VIBE64_PLAYWRIGHT_VERSION",nl="playwright",Hf="browsers",zf="runtime.env",
|
|
1067
|
+
Ff=/^\d+\.\d+\.\d+$/u});function yt(e={}){for(let t of Object.keys(le(e)))if(Wf.has(t)||t.startsWith("XDG_")){let r=new Error(`Vibe64 command ca\
|
|
1068
|
+
llers cannot provide execution policy env: ${t}.`);throw r.code="vibe64_command_env_policy_reserved",r}}function en(e={},t={}){
|
|
1069
|
+
let{envPolicy:r="session"}=t,n=le(e);yt(n);let o=Object.fromEntries(Object.entries(n).filter(([i])=>!Yf.has(i)));return r===
|
|
1070
|
+
"deployment"?o:{...o,...Kr(n)}}var Wf,Yf,tn=g(()=>{q();Xr();gt();qt();Wf=new Set(["HOME","LOGNAME","PATH","TMPDIR","USER",
|
|
1061
1071
|
"VIBE64_EXECUTION_ID","VIBE64_MANAGED_EXECUTION_REQUIRED","XDG_CACHE_HOME","XDG_CONFIG_HOME","XDG_DATA_HOME","XDG_RUNTIM\
|
|
1062
|
-
E_DIR"]),
|
|
1072
|
+
E_DIR"]),Yf=new Set([...zt,Je,Ye,Xe,Ke,Ft,Fo,qo,Zr])});function Jf(e=""){let t=C(e);return t==="/home"||t.startsWith("/home/")}function il({actor:e={},request:t={}}={}){let r=t.
|
|
1063
1073
|
credentialHome||{},n=C(r.home);if(!n)return{};let o=C(e.user?.home);if(e.requiresRealUser&&o&&n!==o){let a=new Error("Co\
|
|
1064
1074
|
mmand credential home must match the resolved real-user actor home.");throw a.code="vibe64_command_credential_home_actor\
|
|
1065
|
-
_mismatch",a}if(!e.requiresRealUser&&
|
|
1066
|
-
ng real-user actor.");throw a.code="vibe64_command_credential_home_real_user_required",a}let i=
|
|
1075
|
+
_mismatch",a}if(!e.requiresRealUser&&Jf(n)&&o&&!Pe(o,n)){let a=new Error("A /home credential directory requires a matchi\
|
|
1076
|
+
ng real-user actor.");throw a.code="vibe64_command_credential_home_real_user_required",a}let i=R(r.username||e.user?.username);
|
|
1067
1077
|
return{...Dt({home:n,username:i},{VIBE64_CREDENTIAL_HOME:n}),...C(r.cacheRoot)?{XDG_CACHE_HOME:C(r.cacheRoot)}:{},...C(r.
|
|
1068
1078
|
configRoot)?{XDG_CONFIG_HOME:C(r.configRoot)}:{},...C(r.dataRoot)?{XDG_DATA_HOME:C(r.dataRoot)}:{},...C(r.stateRoot)?{XDG_STATE_HOME:C(
|
|
1069
|
-
r.stateRoot)}:{}}}var
|
|
1070
|
-
isAbsolute(o))continue;let i=
|
|
1079
|
+
r.stateRoot)}:{}}}var sl=g(()=>{mt();q()});import al from"node:path";function Zf(e=[]){let t=new Set,r=[];for(let n of Array.isArray(e)?e:[e]){let o=R(n);if(!o||!al.
|
|
1080
|
+
isAbsolute(o))continue;let i=al.resolve(o);t.has(i)||(t.add(i),r.push(i))}return r}function Wt(e={},t=[]){let r={...e&&typeof e==
|
|
1071
1081
|
"object"&&!Array.isArray(e)?e:{}},n=Number.parseInt(String(r.GIT_CONFIG_COUNT||"0"),10),o=Number.isSafeInteger(n)&&n>=0?
|
|
1072
|
-
n:0;for(let i of Array.isArray(t)?t:[]){let s=
|
|
1073
|
-
i?.value??""),o+=1)}return r.GIT_CONFIG_COUNT=String(o),r}function
|
|
1074
|
-
function
|
|
1075
|
-
return{GH_PROMPT_DISABLED:"1",GIT_PAGER:"cat",GIT_TERMINAL_PROMPT:"0",PAGER:"cat"}}function
|
|
1076
|
-
return Wt(e,
|
|
1077
|
-
var
|
|
1078
|
-
url.https://github.com/.insteadOf",value:"ssh://git@github.com/"}]),
|
|
1079
|
-
m.helper",value:"!/usr/bin/env gh auth git-credential"}]),
|
|
1082
|
+
n:0;for(let i of Array.isArray(t)?t:[]){let s=R(i?.key);s&&(r[`GIT_CONFIG_KEY_${o}`]=s,r[`GIT_CONFIG_VALUE_${o}`]=String(
|
|
1083
|
+
i?.value??""),o+=1)}return r.GIT_CONFIG_COUNT=String(o),r}function cl(e=[]){return Zf(e).map(t=>({key:"safe.directory",value:t}))}
|
|
1084
|
+
function ll(e={},t=[]){return Wt(e,cl(t))}function eh(e=[]){return cl(e).flatMap(t=>["-c",`${t.key}=${t.value}`])}function Wo(){
|
|
1085
|
+
return{GH_PROMPT_DISABLED:"1",GIT_PAGER:"cat",GIT_TERMINAL_PROMPT:"0",PAGER:"cat"}}function Yo(e={}){return Wt(e,Kf)}function th(e={}){
|
|
1086
|
+
return Wt(e,Xf)}function rh(e={}){return Wt(e,Qf)}function ul(e={}){return th(Yo(e))}function dl(e={}){return rh(Yo(e))}
|
|
1087
|
+
var Kf,Xf,Qf,OI,pl=g(()=>{q();Kf=Object.freeze([{key:"url.https://github.com/.insteadOf",value:"git@github.com:"},{key:"\
|
|
1088
|
+
url.https://github.com/.insteadOf",value:"ssh://git@github.com/"}]),Xf=Object.freeze([{key:"credential.https://github.co\
|
|
1089
|
+
m.helper",value:"!/usr/bin/env gh auth git-credential"}]),Qf=Object.freeze([{key:"credential.https://github.com.helper",
|
|
1080
1090
|
value:`!f() { case "$1" in get) printf '%s\\n' username=x-access-token "password=\${VIBE64_GIT_AUTH_TOKEN}" ;; esac; }; f`}]);
|
|
1081
|
-
|
|
1082
|
-
code="vibe64_command_git_auth_token_required",t}return
|
|
1083
|
-
request:e={}}={}){let t={GIT_TERMINAL_PROMPT:"0"},r=t;return e.gitTransport==="github-token"?r=
|
|
1084
|
-
github-https"||e.purpose==="github")&&(r=
|
|
1085
|
-
BE64_GIT_AUTH_TOKEN"});import
|
|
1086
|
-
function
|
|
1087
|
-
()=>{q();ge();
|
|
1088
|
-
function Yt(e=""){return String(e||"").split(":").map(
|
|
1089
|
-
t)}catch{return!1}})}function
|
|
1090
|
-
0)-Number(/\d+/u.exec(r)?.[0]||0))}catch{return[]}}function
|
|
1091
|
+
OI=Object.freeze({applyGitConfigEntriesToEnv:Wt,githubSshToHttpsGitEnv:Yo,gitSafeDirectoryArgs:eh})});function oh(e={}){if(!e.gitAuthToken){let t=new Error("Token-backed GitHub transport requires a gitAuthToken.");throw t.
|
|
1092
|
+
code="vibe64_command_git_auth_token_required",t}return dl({...Wo(),GIT_TERMINAL_PROMPT:"0",[nh]:e.gitAuthToken})}function ml({
|
|
1093
|
+
request:e={}}={}){let t={GIT_TERMINAL_PROMPT:"0"},r=t;return e.gitTransport==="github-token"?r=oh(e):(e.gitTransport==="\
|
|
1094
|
+
github-https"||e.purpose==="github")&&(r=ul({...t,...Wo()})),ll(r,e.gitSafeDirectories||[])}var nh,fl=g(()=>{pl();nh="VI\
|
|
1095
|
+
BE64_GIT_AUTH_TOKEN"});import hl from"node:path";function gl({env:e={}}={}){return Q()?C(e[Jo])||(C(e.HOME)?hl.join(C(e.HOME),".local"):""):""}
|
|
1096
|
+
function wl(e={}){let t=gl(e);return t?{[Jo]:t}:{}}function yl(e={}){let t=gl(e);return t?[hl.join(t,"bin")]:[]}var Jo,Ko=g(
|
|
1097
|
+
()=>{q();ge();Jo="NPM_CONFIG_PREFIX"});import{existsSync as ih,readdirSync as sh}from"node:fs";import ah from"node:os";import Ne from"node:path";import rn from"node:process";
|
|
1098
|
+
function Yt(e=""){return String(e||"").split(":").map(R).filter(Boolean)}function El(e=[]){return e.filter(t=>{try{return ih(
|
|
1099
|
+
t)}catch{return!1}})}function _l(e="",t=/^$/u){try{return sh(e).filter(r=>t.test(r)).sort((r,n)=>Number(/\d+/u.exec(n)?.[0]||
|
|
1100
|
+
0)-Number(/\d+/u.exec(r)?.[0]||0))}catch{return[]}}function ch(e){if(Q())return[];let t=String(e.HOME||ah.homedir()||"");
|
|
1091
1101
|
if(!Ne.isAbsolute(t))return[];let r=Ne.isAbsolute(String(e.XDG_DATA_HOME||""))?e.XDG_DATA_HOME:Ne.join(t,".local/share"),
|
|
1092
|
-
n=Ne.isAbsolute(String(e.MISE_DATA_DIR||""))?e.MISE_DATA_DIR:Ne.join(r,"mise");return
|
|
1093
|
-
n,"shims"),...[".claude/local",".opencode/bin",".cargo/bin",".bun/bin"].map(o=>Ne.join(t,o))])}function
|
|
1094
|
-
let e=["/opt/homebrew","/usr/local"];return[...Yt(
|
|
1095
|
-
[...
|
|
1096
|
-
t=>[...
|
|
1097
|
-
env:e,existingPath:t="",inheritedPath:r="",runtimes:n=[],shimDirs:o=[]}){return ze([...Yt(o.join(":")),...
|
|
1098
|
-
i=>
|
|
1099
|
-
Jt="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"});import
|
|
1100
|
-
e)?e:{}).map(([t,r])=>[String(t||"").trim(),String(r??"")]).filter(([t])=>t&&!
|
|
1101
|
-
!t.startsWith("GH_")&&!t.startsWith("XDG_")))}function
|
|
1102
|
-
e.project?.deployment?.env]:[e.project?.runtimeConfigEnv,e.project?.databaseEnv]}function
|
|
1103
|
-
envPolicy==="deployment"?(
|
|
1104
|
-
oyment"?[]:t.envPolicy==="project"?
|
|
1105
|
-
baseEnv:t,localPath:r="",request:n={}}){let o=Array.isArray(n.runtimes)?n.runtimes.join(":"):"",i=
|
|
1106
|
-
t.XDG_RUNTIME_DIR||"").trim(),c={...Dt(e.user,
|
|
1107
|
-
...
|
|
1108
|
-
|
|
1109
|
-
shimDirs||[]});return{...
|
|
1102
|
+
n=Ne.isAbsolute(String(e.MISE_DATA_DIR||""))?e.MISE_DATA_DIR:Ne.join(r,"mise");return El([Ne.join(t,".local/bin"),Ne.join(
|
|
1103
|
+
n,"shims"),...[".claude/local",".opencode/bin",".cargo/bin",".bun/bin"].map(o=>Ne.join(t,o))])}function lh(){if(Q())return[];
|
|
1104
|
+
let e=["/opt/homebrew","/usr/local"];return[...Yt(rn.env.PATH),...rn.platform==="darwin"?["/opt/homebrew/bin"]:[],...El(
|
|
1105
|
+
[..._l("/usr/lib/postgresql",/^\d+$/u).slice(0,1).map(t=>`/usr/lib/postgresql/${t}/bin`),...rn.platform==="darwin"?e.flatMap(
|
|
1106
|
+
t=>[..._l(`${t}/opt`,/^postgresql@\d+$/u).slice(0,1).map(r=>`${t}/opt/${r}/bin`),`${t}/opt/mariadb/bin`]):[]])]}function bl({
|
|
1107
|
+
env:e,existingPath:t="",inheritedPath:r="",runtimes:n=[],shimDirs:o=[]}){return ze([...Yt(o.join(":")),...zo(),...n.flatMap(
|
|
1108
|
+
i=>Ho(i)),...tl(),...Yt(t||(r?"":e.PATH)),...ch(rn.env),...Yt(r),...lh(),...Yt(Jt)]).join(":")}var Jt,nn=g(()=>{q();ge();
|
|
1109
|
+
Jt="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"});import uh from"node:path";function mh(e={}){return Object.fromEntries(Object.entries(e&&typeof e=="object"&&!Array.isArray(
|
|
1110
|
+
e)?e:{}).map(([t,r])=>[String(t||"").trim(),String(r??"")]).filter(([t])=>t&&!dh.has(t)&&!ph.has(t)&&!t.startsWith("GIT_")&&
|
|
1111
|
+
!t.startsWith("GH_")&&!t.startsWith("XDG_")))}function Xo(e={}){return e.envPolicy==="deployment"?[e.project?.deploymentEnv,
|
|
1112
|
+
e.project?.deployment?.env]:[e.project?.runtimeConfigEnv,e.project?.databaseEnv]}function fh(e={}){return Xo(e).reduce((t,r)=>e.
|
|
1113
|
+
envPolicy==="deployment"?(yt(r),{...t,...le(r)}):{...t,...en(r,e)},{})}function hh(e={},t={}){return t.envPolicy==="depl\
|
|
1114
|
+
oyment"?[]:t.envPolicy==="project"?Xo(t):[e,...Xo(t),t.project?.databaseEnv,t.session?.databaseEnv]}function vl({actor:e={},
|
|
1115
|
+
baseEnv:t,localPath:r="",request:n={}}){let o=Array.isArray(n.runtimes)?n.runtimes.join(":"):"",i=ol(),s=en(n.env,n),a=String(
|
|
1116
|
+
t.XDG_RUNTIME_DIR||"").trim(),c={...Dt(e.user,mh(t)),...ht(e)&&uh.isAbsolute(a)?{XDG_RUNTIME_DIR:a}:{},...Kr(...hh(t,n)),
|
|
1117
|
+
...fh(n),...ml({actor:e,request:n}),...s,...il({actor:e,request:n}),...i},l={...c,...wl({env:c}),VIBE64_DECLARED_RUNTIMES:o},
|
|
1118
|
+
u=bl({env:l,existingPath:[...yl({env:l}),l.PATH].filter(Boolean).join(":"),inheritedPath:r,runtimes:n.runtimes,shimDirs:n.
|
|
1119
|
+
shimDirs||[]});return{...l,PATH:u,...Q()?{}:{VIBE64_TOOL_PATH:u}}}function Sl({actor:e={},baseEnv:t,request:r={}},n){return{
|
|
1110
1120
|
actor:e,env:t,gitConfig:{cwd:r.cwd,env:n},personGitIdentity:r.personGitIdentity,project:r.project,session:r.session,userKey:r.
|
|
1111
|
-
userKey}}async function
|
|
1112
|
-
resolvedGitIdentityEnv||
|
|
1113
|
-
q();
|
|
1114
|
-
_RUNTIME_DIR"]),
|
|
1115
|
-
found.",ok:!1}}function Ce(e=""){return String(e||"default").trim()||"default"}function
|
|
1116
|
-
for(let n=0;n<
|
|
1117
|
-
`,r-1),!(r<0));n+=1);return r>=0&&(t=t.slice(r+1)),t.length>
|
|
1118
|
-
"running"||e.status==="closing"}function
|
|
1119
|
-
!0}catch{return!1}}function
|
|
1120
|
-
let{outputLimit:r=0}=t,n=String(e||""),o=
|
|
1121
|
-
o),outputTruncated:!0}}function ke(e,t={}){let r=
|
|
1121
|
+
userKey}}async function Il(e){let t=vl(e);return{...t,...await Zc(Sl(e,t))}}function Qo(e){let t=vl(e);return{...t,...e.
|
|
1122
|
+
resolvedGitIdentityEnv||el(Sl(e,t))}}var dh,ph,Zo=g(()=>{Jr();mt();Xr();tn();Xr();sl();fl();gt();gt();qt();Ko();nn();ge();
|
|
1123
|
+
q();dh=new Set([...zt,Je,Ye,Xe,Ke,"HOME","LOGNAME","PATH","USER","XDG_CACHE_HOME","XDG_CONFIG_HOME","XDG_DATA_HOME","XDG\
|
|
1124
|
+
_RUNTIME_DIR"]),ph=new Set(["NODE_ENV"])});import{Buffer as gh}from"node:buffer";function Al(){return{code:"terminal_session_not_found",error:"Terminal session not\
|
|
1125
|
+
found.",ok:!1}}function Ce(e=""){return String(e||"default").trim()||"default"}function an(e){let t=String(e||""),r=t.length;
|
|
1126
|
+
for(let n=0;n<wh&&(r=t.lastIndexOf(`
|
|
1127
|
+
`,r-1),!(r<0));n+=1);return r>=0&&(t=t.slice(r+1)),t.length>Tl&&(t=t.slice(t.length-Tl)),t}function Kt(e={}){return e.status===
|
|
1128
|
+
"running"||e.status==="closing"}function ei(e={}){return Kt(e)||e.status==="exited"}function Pl(e,t){try{return t(ke(e))===
|
|
1129
|
+
!0}catch{return!1}}function _h(e=0){let t=Math.floor(Number(e||0));return Number.isFinite(t)&&t>0?t:0}function Eh(e="",t={}){
|
|
1130
|
+
let{outputLimit:r=0}=t,n=String(e||""),o=_h(r);return!o||n.length<=o?{output:n,outputTruncated:!1}:{output:n.slice(n.length-
|
|
1131
|
+
o),outputTruncated:!0}}function ke(e,t={}){let r=Eh(e.output,t);return{ok:!0,closeError:e.closeError||"",cols:e.cols||on,
|
|
1122
1132
|
createdAt:e.createdAt||"",id:e.id,commandPreview:e.commandPreview,exitCode:e.exitCode,inputVersion:e.inputVersion||0,lastInputAt:e.
|
|
1123
1133
|
lastInputAt||"",lastInputBytes:e.lastInputBytes||0,lastOutputAt:e.lastOutputAt||"",lastOutputBytes:e.lastOutputBytes||0,
|
|
1124
1134
|
metadata:e.metadata||{},output:r.output,outputTruncated:r.outputTruncated,outputVersion:e.outputVersion||0,rows:e.rows||
|
|
1125
|
-
|
|
1126
|
-
e));return!Number.isFinite(t)||t<0?0:Math.min(t,
|
|
1127
|
-
e.lastInputAt),
|
|
1128
|
-
e);return r>0?Math.max(0,Number(t)-r):0}function
|
|
1129
|
-
e.detachedCleanupTimer=null)}var
|
|
1130
|
-
60*1e3,
|
|
1131
|
-
metadata:e.metadata,type:"metadata"}),ke(e))}function
|
|
1135
|
+
sn,status:e.status}}function Rl(e=""){return gh.byteLength(String(e||""),"utf8")}function Xt(e=0){let t=Math.floor(Number(
|
|
1136
|
+
e));return!Number.isFinite(t)||t<0?0:Math.min(t,yh)}function bh(e={}){return Math.max(pt(e.lastSubscriberDetachedAt),pt(
|
|
1137
|
+
e.lastInputAt),pt(e.lastOutputAt),pt(e.createdAt))}function ti(e={},t=Date.now()){if(e.subscribers?.size)return 0;let r=bh(
|
|
1138
|
+
e);return r>0?Math.max(0,Number(t)-r):0}function cn(e={}){e.detachedCleanupTimer&&(clearTimeout(e.detachedCleanupTimer),
|
|
1139
|
+
e.detachedCleanupTimer=null)}var Tl,wh,on,sn,sT,yh,aT,Ol,_t=g(()=>{q();Tl=256*1024,wh=300,on=100,sn=28,sT=600*1e3,yh=1440*
|
|
1140
|
+
60*1e3,aT=Object.freeze({"ctrl-c":"",enter:"\r",escape:"\x1B",tab:" "});Ol=new Map});function Nl(e,t={}){return!e||!t||typeof t!="object"||Array.isArray(t)?ke(e):(e.metadata={...e.metadata||{},...t},we(e,{
|
|
1141
|
+
metadata:e.metadata,type:"metadata"}),ke(e))}function Cl(e,t=""){let r=Rl(t);r<1||(e.outputVersion=Number(e.outputVersion||
|
|
1132
1142
|
0)+1,e.lastOutputAt=new Date().toISOString(),e.lastOutputBytes=r)}function we(e,t){if(e?.subscribers?.size)for(let r of[
|
|
1133
|
-
...e.subscribers])try{r(t)}catch{e.subscribers.delete(r)}}function
|
|
1134
|
-
e||"Terminal PTY error.");return{code:t,message:r}}function
|
|
1143
|
+
...e.subscribers])try{r(t)}catch{e.subscribers.delete(r)}}function vh(e){let t=String(e?.code||""),r=String(e?.message||
|
|
1144
|
+
e||"Terminal PTY error.");return{code:t,message:r}}function kl(e,t){if(!e)return;let r=vh(t);e.lastWriteErrorAt=new Date().
|
|
1135
1145
|
toISOString(),e.lastWriteErrorCode=r.code,e.lastWriteError=r.message,console.warn("Vibe64 terminal PTY write error.",{code:r.
|
|
1136
1146
|
code,id:e.id,metadata:e.metadata||{},message:r.message,namespace:e.namespace||""}),we(e,{code:r.code,error:r.message,type:"\
|
|
1137
|
-
error"})}function
|
|
1147
|
+
error"})}function xl(e){let t=e?.terminal?._writeStream;!t||typeof t.on!="function"||t.on("error",r=>{kl(e,r)})}function $l(e,t,r=t){
|
|
1138
1148
|
let n=`\r
|
|
1139
1149
|
[studio] ${r}\r
|
|
1140
|
-
`;e.closeError=t,e.output=
|
|
1150
|
+
`;e.closeError=t,e.output=an(`${e.output}${n}`),we(e,{chunk:n,type:"output"}),we(e,{error:t,type:"error"})}async function jl(e,{
|
|
1141
1151
|
code:t,flag:r,hook:n,label:o,payload:i}){if(e[r])return null;e[r]=!0;try{return await e[n](i),null}catch(s){let a=String(
|
|
1142
|
-
s?.message||s||`${o}.`),c=s instanceof Error?s:new Error(a);return c.code||=t
|
|
1152
|
+
s?.message||s||`${o}.`),c=s instanceof Error?s:new Error(a);return c.code||=t,$l(e,a,`${o}: ${a}`),c}}function Qe(e,t){let r=`${String(
|
|
1143
1153
|
t?.code||"terminal_cleanup_failed")}:${String(t?.message||"")}`;return e.reportedLifecycleFailures||=new Set,e.reportedLifecycleFailures.
|
|
1144
|
-
has(r)||(e.reportedLifecycleFailures.add(r)
|
|
1154
|
+
has(r)||(e.reportedLifecycleFailures.add(r),$l(e,String(t?.message||t||"Terminal cleanup failed."))),t}function ln(e,t=[]){
|
|
1145
1155
|
let r=new AggregateError(t,`Terminal session could not close cleanly: ${e.id}`);return r.code=t.some(n=>String(n?.code||
|
|
1146
|
-
"").startsWith("terminal_exit_"))?"terminal_exit_unverified":"terminal_cleanup_failed",r.terminalSessionId=e.id,r}function
|
|
1147
|
-
return e.stopHookCompletion||(e.stopHookCompletion=Promise.resolve().then(()=>
|
|
1156
|
+
"").startsWith("terminal_exit_"))?"terminal_exit_unverified":"terminal_cleanup_failed",r.terminalSessionId=e.id,r}function Sh(e,t){
|
|
1157
|
+
return e.stopHookCompletion||(e.stopHookCompletion=Promise.resolve().then(()=>jl(e,{code:"terminal_stop_hook_failed",flag:"\
|
|
1148
1158
|
stopHookStarted",hook:"onStop",label:"Terminal stop failed",payload:{id:e.id,output:e.output,reason:t,status:e.status}}))),
|
|
1149
|
-
e.stopHookCompletion}function
|
|
1159
|
+
e.stopHookCompletion}function ri(e,t){return e.closeHookCompletion||(e.closeHookCompletion=Promise.resolve().then(()=>jl(
|
|
1150
1160
|
e,{code:"terminal_close_hook_failed",flag:"closeHookStarted",hook:"onClose",label:"Terminal finalization failed",payload:{
|
|
1151
|
-
exitCode:e.exitCode,id:e.id,output:e.output,reason:t,status:e.status}}))),e.closeHookCompletion}function
|
|
1152
|
-
"exited"&&(e.status="exited",we(e,{closeError:e.closeError||"",exitCode:e.exitCode,status:e.status,type:"status"}))}function
|
|
1153
|
-
return e.scopeDrainCompletion||(e.scopeDrainCompletion=(async()=>{if(process.platform!=="win32"&&!await
|
|
1161
|
+
exitCode:e.exitCode,id:e.id,output:e.output,reason:t,status:e.status}}))),e.closeHookCompletion}function ni(e){e.status!==
|
|
1162
|
+
"exited"&&(e.status="exited",we(e,{closeError:e.closeError||"",exitCode:e.exitCode,status:e.status,type:"status"}))}function oi(e){
|
|
1163
|
+
return e.scopeDrainCompletion||(e.scopeDrainCompletion=(async()=>{if(process.platform!=="win32"&&!await zr(e.terminal.pid)){
|
|
1154
1164
|
let t=new Error(`Terminal execution scope did not become empty: ${e.id}`);throw t.code="terminal_execution_drain_failed",
|
|
1155
|
-
t}})(),e.scopeDrainCompletion.catch(()=>null)),e.scopeDrainCompletion}async function
|
|
1156
|
-
Qe(e,t)}try{await Promise.all([
|
|
1165
|
+
t}})(),e.scopeDrainCompletion.catch(()=>null)),e.scopeDrainCompletion}async function Ll(e){try{await e.scopeDrainCompletion}catch(t){
|
|
1166
|
+
Qe(e,t)}try{await Promise.all([ri(e,e.stopReason||"exit"),e.stopHookCompletion])}catch(t){Qe(e,t)}ni(e)}async function ii(e,t="\
|
|
1157
1167
|
stop"){if(!e||e.processExited)return{failures:[]};e.stopReason||=String(t||"stop"),e.status==="running"&&(e.status="clos\
|
|
1158
|
-
ing",we(e,{exitCode:e.exitCode,status:e.status,type:"status"}));let r=[];if(
|
|
1168
|
+
ing",we(e,{exitCode:e.exitCode,status:e.status,type:"status"}));let r=[];if(Sh(e,e.stopReason),!e.processExited&&!e.killStarted){
|
|
1159
1169
|
e.killStarted=!0;try{e.terminal.kill()}catch(n){e.killStarted=!1;let o=n instanceof Error?n:new Error(String(n||"Termina\
|
|
1160
|
-
l process could not be killed."));o.code||="terminal_kill_failed",r.push(Qe(e,o))}}try{await
|
|
1161
|
-
n))}return{failures:r}}var
|
|
1162
|
-
ok:!1}:null}var
|
|
1163
|
-
e.delete(r);let n=Ce(t);e.size<1&&Ze.get(n)===e&&Ze.delete(n)}function
|
|
1164
|
-
filter(r=>r.startsWith(t))}function
|
|
1165
|
-
o=[];for(let i of n){let s=
|
|
1166
|
-
()=>{
|
|
1167
|
-
let n=Math.max(0,r-
|
|
1168
|
-
let{namespace:r="default"}=t,n=
|
|
1169
|
-
let s=[];if(
|
|
1170
|
-
s.push(Qe(o,
|
|
1171
|
-
o.closeHookCompletion])).filter(Boolean);if(o.processExited&&
|
|
1172
|
-
ok:!0,closed:!0,...c.length>0?{cleanupErrors:c.map(
|
|
1173
|
-
o.closePromise===i&&(o.closePromise=null)}}async function
|
|
1174
|
-
if(!
|
|
1175
|
-
r.id,{namespace:t})}}}var
|
|
1176
|
-
filter:e,namespacePrefix:t}){return
|
|
1170
|
+
l process could not be killed."));o.code||="terminal_kill_failed",r.push(Qe(e,o))}}try{await oi(e)}catch(n){r.push(Qe(e,
|
|
1171
|
+
n))}return{failures:r}}var si=g(()=>{Vt();_t()});function Th(e="default"){return Ih.get(Ce(e))||null}function Ml(e="default"){let t=Th(e);return t?{code:t.code,error:t.error,
|
|
1172
|
+
ok:!1}:null}var Ih,Dl=g(()=>{_t();Ih=new Map});function Et(e){return Ze.get(Ce(e))||Ol}function Ul(e){let t=Ce(e);return Ze.has(t)||Ze.set(t,new Map),Ze.get(t)}function Vl(e,t,r){
|
|
1173
|
+
e.delete(r);let n=Ce(t);e.size<1&&Ze.get(n)===e&&Ze.delete(n)}function Ah(e=""){let t=String(e||"");return[...Ze.keys()].
|
|
1174
|
+
filter(r=>r.startsWith(t))}function un({namespace:e="",namespacePrefix:t="",runningOnly:r=!1}={}){let n=e?[Ce(e)]:Ah(t),
|
|
1175
|
+
o=[];for(let i of n){let s=Et(i);for(let a of s.values())r&&!Kt(a)||o.push({namespace:i,session:a})}return o}var Ze,ai=g(
|
|
1176
|
+
()=>{_t();Ze=new Map});function dn(e={},t="default"){if(cn(e),!ei(e)||e.subscribers?.size)return;let r=Xt(e.detachedIdleTimeoutMs);if(r<1)return;
|
|
1177
|
+
let n=Math.max(0,r-ti(e));e.detachedCleanupTimer=setTimeout(()=>{e.detachedCleanupTimer=null,Oh({namespace:t})},n)}async function ci(e,t={}){
|
|
1178
|
+
let{namespace:r="default"}=t,n=Et(r),o=n.get(e);if(!o)return{ok:!0,closed:!1};if(o.closePromise)return o.closePromise;let i=(async()=>{
|
|
1179
|
+
let s=[];if(cn(o),!o.processExited){let l=await ii(o,"close");if(l.failures.length)throw ln(o,l.failures)}try{await o.exitCompletion}catch(l){
|
|
1180
|
+
s.push(Qe(o,l))}try{await o.scopeDrainCompletion}catch(l){s.push(Qe(o,l))}let c=(await Promise.all([o.stopHookCompletion,
|
|
1181
|
+
o.closeHookCompletion])).filter(Boolean);if(o.processExited&&ni(o),s.length>0)throw ln(o,[...s,...c]);return Vl(n,r,e),{
|
|
1182
|
+
ok:!0,closed:!0,...c.length>0?{cleanupErrors:c.map(l=>String(l?.message||l))}:{}}})();o.closePromise=i;try{return await i}finally{
|
|
1183
|
+
o.closePromise===i&&(o.closePromise=null)}}async function Oh({namespace:e}){for(let{namespace:t,session:r}of un({namespace:e})){
|
|
1184
|
+
if(!ei(r)||r.subscribers?.size)continue;let n=Xt(r.detachedIdleTimeoutMs);if(!(n<1)){if(ti(r)<n){dn(r,t);continue}await ci(
|
|
1185
|
+
r.id,{namespace:t})}}}var li=g(()=>{q();si();ai();_t()});import Rh from"node:crypto";import{createRequire as Nh}from"node:module";function ui(){}function Ch(){return!0}function xh({
|
|
1186
|
+
filter:e,namespacePrefix:t}){return un({namespacePrefix:t,runningOnly:!0}).filter(r=>Pl(r.session,e)).length}function Gl({
|
|
1177
1187
|
args:e,command:t,commandPreview:r,cwd:n=process.cwd(),env:o={},maxRunning:i=0,metadata:s={},namespace:a="default",namespaceLimitPrefix:c="",
|
|
1178
|
-
runningLimitFilter:
|
|
1179
|
-
if(
|
|
1180
|
-
if(_)return ke(_);let b=Number(i||0),v=c||a;if(b>0&&
|
|
1181
|
-
t",error:`Terminal limit reached (${b}).`};let
|
|
1182
|
-
env:
|
|
1183
|
-
env:
|
|
1184
|
-
F=>{U=F}),k={id:d,closeHookCompletion:null,closePromise:null,commandPreview:A,cols:
|
|
1185
|
-
cwd:n,detachedCleanupTimer:null,detachedIdleTimeoutMs:Xt(
|
|
1186
|
-
toISOString(),metadata:
|
|
1188
|
+
runningLimitFilter:l=Ch,onClose:u=ui,onOutput:m=ui,onStop:f=ui,reuseRunning:h=!1,detachedIdleTimeoutMs:w=0}){let I=Ml(a);
|
|
1189
|
+
if(I)return I;let S=Et(a),d=Rh.randomUUID(),p=typeof h=="function"?h:()=>!!h,_=h?[...S.values()].find(F=>Kt(F)&&p(F)):null;
|
|
1190
|
+
if(_)return ke(_);let b=Number(i||0),v=c||a;if(b>0&&xh({filter:l,namespacePrefix:v})>=b)return{ok:!1,code:"terminal_limi\
|
|
1191
|
+
t",error:`Terminal limit reached (${b}).`};let y=typeof o=="function"?o({id:d,namespace:a}):o,E=typeof e=="function"?e({
|
|
1192
|
+
env:y,id:d,namespace:a}):e,A=typeof r=="function"?r({args:E,env:y,id:d,namespace:a}):r,T=typeof s=="function"?s({args:E,
|
|
1193
|
+
env:y,id:d,namespace:a}):s,O=kh("node-pty").spawn(t,E,{cols:on,cwd:n,env:J(y),name:"xterm-color",rows:sn}),U,x=new Promise(
|
|
1194
|
+
F=>{U=F}),k={id:d,closeHookCompletion:null,closePromise:null,commandPreview:A,cols:on,createdAt:new Date().toISOString(),
|
|
1195
|
+
cwd:n,detachedCleanupTimer:null,detachedIdleTimeoutMs:Xt(w),exitCompletion:x,exitCode:null,lastSubscriberAttachedAt:"",lastSubscriberDetachedAt:new Date().
|
|
1196
|
+
toISOString(),metadata:T&&typeof T=="object"&&!Array.isArray(T)?T:{},onClose:u,onStop:f,inputVersion:0,lastInputAt:"",lastInputBytes:0,
|
|
1187
1197
|
lastOutputAt:"",lastOutputBytes:0,lastWriteError:"",lastWriteErrorAt:"",lastWriteErrorCode:"",output:"",outputVersion:0,
|
|
1188
|
-
processExited:!1,killStarted:!1,reportedLifecycleFailures:new Set,resolveExitCompletion:U,rows:
|
|
1189
|
-
scopeDrainCompletion:null,namespace:a,subscribers:new Set,terminal:O};return
|
|
1198
|
+
processExited:!1,killStarted:!1,reportedLifecycleFailures:new Set,resolveExitCompletion:U,rows:sn,status:"running",stopHookCompletion:null,
|
|
1199
|
+
scopeDrainCompletion:null,namespace:a,subscribers:new Set,terminal:O};return xl(k),O.onData(F=>{Cl(k,F),k.output=an(k.output+
|
|
1190
1200
|
F),we(k,{chunk:F,lastOutputAt:k.lastOutputAt,outputVersion:k.outputVersion,type:"output"});try{m({chunk:F,output:k.output,
|
|
1191
|
-
session:ke(k),updateMetadata(
|
|
1192
|
-
we(k,{error:pe,type:"error"})}
|
|
1193
|
-
k),we(k,{exitCode:F,status:k.status,type:"status"}),
|
|
1194
|
-
d,k),
|
|
1195
|
-
ke(i,{outputLimit:n}):
|
|
1196
|
-
execution/src/server/engines/terminalSessions.js",import.meta.url).href;Nh
|
|
1197
|
-
function
|
|
1198
|
-
r real-user PTY execution.");throw n.code="vibe64_command_pty_helper_payload_root_required",n}let r=
|
|
1199
|
-
"exec-helper-payloads");return
|
|
1200
|
-
let{actor:r,cwd:n,env:o,resolveEnv:i}=t,s=e.terminal||{},a=e.envFactory?i:o;return
|
|
1201
|
-
|
|
1202
|
-
a,input:e.input,operation:Ht(e)});return
|
|
1203
|
-
`,{mode:384}),["-n",
|
|
1204
|
-
command:e.command,cwd:n,env:a}}async function
|
|
1205
|
-
{},{onClose:a=
|
|
1206
|
-
commandPreview:s.commandPreview,cwd:
|
|
1201
|
+
session:ke(k),updateMetadata(ee){return Nl(k,ee)}})}catch(ee){let pe=String(ee?.message||ee||"Terminal output hook faile\
|
|
1202
|
+
d.");we(k,{error:pe,type:"error"})}dn(k,a)}),O.onExit(({exitCode:F})=>{k.processExited=!0,k.exitCode=F,k.status="closing",
|
|
1203
|
+
oi(k),we(k,{exitCode:F,status:k.status,type:"status"}),ri(k,k.stopReason||"exit"),k.resolveExitCompletion(),Ll(k)}),Ul(a).
|
|
1204
|
+
set(d,k),dn(k,a),$h(d,{namespace:a})}function $h(e,t={}){let{namespace:r="default",outputLimit:n=0}=t,i=Et(r).get(e);return i?
|
|
1205
|
+
ke(i,{outputLimit:n}):Al()}var Ph,kh,Bl=g(()=>{q();_t();si();Dl();li();ai();Ph=new URL("./../node_modules/@local/vibe64-\
|
|
1206
|
+
execution/src/server/engines/terminalSessions.js",import.meta.url).href;kh=Nh(Ph)});import{randomUUID as jh}from"node:crypto";import{mkdirSync as Lh,writeFileSync as Mh}from"node:fs";import di from"node:path";
|
|
1207
|
+
function Dh(){}function Uh(e=""){let t=String(e||"").trim();if(!t){let n=new Error("A helper payload root is required fo\
|
|
1208
|
+
r real-user PTY execution.");throw n.code="vibe64_command_pty_helper_payload_root_required",n}let r=di.join(di.resolve(t),
|
|
1209
|
+
"exec-helper-payloads");return Lh(r,{mode:448,recursive:!0}),di.join(r,`${process.pid}-${Date.now()}-${jh()}.json`)}function Vh(e,t){
|
|
1210
|
+
let{actor:r,cwd:n,env:o,resolveEnv:i}=t,s=e.terminal||{},a=e.envFactory?i:o;return Yr(r)?{args:(c={})=>{let l=Uh(s.helperPayloadRoot),
|
|
1211
|
+
u=typeof e.args=="function"?e.args(c):e.args,m=Fr({actor:r,args:u,command:e.command,cwd:n,env:typeof a=="function"?a(c):
|
|
1212
|
+
a,input:e.input,operation:Ht(e)});return Mh(l,`${JSON.stringify(m)}
|
|
1213
|
+
`,{mode:384}),["-n",No(),"execute",l]},command:"sudo",cwd:s.helperPayloadRoot,env:{PATH:process.env.PATH||Jt}}:{args:e.args,
|
|
1214
|
+
command:e.command,cwd:n,env:a}}async function zl(e={},t={}){let{actor:r,cwd:n,env:o,resolveEnv:i}=t;try{let s=e.terminal||
|
|
1215
|
+
{},{onClose:a=Dh}=s,c=e.execution?.id||"",l=Vh(e,{actor:r,cwd:n,env:o,resolveEnv:i}),u=Gl({args:l.args,command:l.command,
|
|
1216
|
+
commandPreview:s.commandPreview,cwd:l.cwd,detachedIdleTimeoutMs:s.detachedIdleTimeoutMs,env:l.env,maxRunning:s.maxRunning,
|
|
1207
1217
|
metadata:s.metadata,namespace:s.namespace,namespaceLimitPrefix:s.namespaceLimitPrefix,onClose:async m=>{try{await a(m)}finally{
|
|
1208
|
-
c&&
|
|
1209
|
-
runningLimitFilter:s.runningLimitFilter});return
|
|
1210
|
-
execution:e.execution}:
|
|
1211
|
-
{execution:e.execution})}}var
|
|
1212
|
-
resolveLinks:n=!0}=t,o=
|
|
1213
|
-
c,o));if(s.length>0){if(!n)return o;let c=
|
|
1214
|
-
s outside the allowed roots.");throw a.code="vibe64_command_cwd_outside_allowed_roots",a}var
|
|
1215
|
-
id Vibe64 command request.");return r.code=t,r}function xe(e="",t=[],r="",n="value"){let o=
|
|
1216
|
-
`Unsupported Vibe64 command ${n}: ${o||"(empty)"}.`,`vibe64_command_${n}_unsupported`);return o}function
|
|
1217
|
-
mode:r="capture"}=t;if(typeof e=="function"){if(r!=="pty")throw
|
|
1218
|
+
c&&Hl.set(c,{id:m.id,namespace:s.namespace,scopeEmpty:!0})}},onOutput:s.onOutput,onStop:s.onStop,reuseRunning:s.reuseRunning,
|
|
1219
|
+
runningLimitFilter:s.runningLimitFilter});return u?.ok===!0&&c&&Hl.set(c,{id:u.id,namespace:s.namespace}),u?.ok===!0?{...u,
|
|
1220
|
+
execution:e.execution}:u}catch(s){return X(s?.message||"Vibe64 PTY command failed.",s?.code||"vibe64_command_pty_failed",
|
|
1221
|
+
{execution:e.execution})}}var Hl,pi=g(()=>{Fe();nn();Bl();li();qr();Jr();Hl=new Map});import{realpathSync as Fl}from"node:fs";function Gh(e=""){return C(e||process.cwd())}function ql(e="",t={}){let{allowedRoots:r=[],
|
|
1222
|
+
resolveLinks:n=!0}=t,o=Gh(e),i=(Array.isArray(r)?r:[r]).map(C).filter(Boolean);if(i.length===0)return o;let s=i.filter(c=>Pe(
|
|
1223
|
+
c,o));if(s.length>0){if(!n)return o;let c=Fl(o);if(s.some(l=>Pe(Fl(l),c)))return c}let a=new Error("Vibe64 command cwd i\
|
|
1224
|
+
s outside the allowed roots.");throw a.code="vibe64_command_cwd_outside_allowed_roots",a}var Wl=g(()=>{q()});import{randomUUID as Bh}from"node:crypto";function te(e="",t="vibe64_command_request_invalid"){let r=new Error(e||"Inval\
|
|
1225
|
+
id Vibe64 command request.");return r.code=t,r}function xe(e="",t=[],r="",n="value"){let o=R(e)||r;if(!t.includes(o))throw te(
|
|
1226
|
+
`Unsupported Vibe64 command ${n}: ${o||"(empty)"}.`,`vibe64_command_${n}_unsupported`);return o}function eg(e=[],t={}){let{
|
|
1227
|
+
mode:r="capture"}=t;if(typeof e=="function"){if(r!=="pty")throw te("Function-valued command args are only supported for \
|
|
1218
1228
|
PTY commands.","vibe64_command_args_function_requires_pty");return e}return(Array.isArray(e)?e:[e]).map(n=>String(n??""))}
|
|
1219
|
-
function
|
|
1220
|
-
nv is only supported for PTY commands.","vibe64_command_env_function_requires_pty");return{env:{},envFactory:e}}let n=
|
|
1221
|
-
e);return
|
|
1222
|
-
let t=
|
|
1223
|
-
maxRunning:t.maxRunning,metadata:t.metadata,namespace:
|
|
1224
|
-
onClose,onOutput:t.onOutput,onStop:t.onStop,reuseRunning:t.reuseRunning,runningLimitFilter:t.runningLimitFilter}}function
|
|
1225
|
-
let t=
|
|
1226
|
-
gid:Number.isSafeInteger(Number(t.gid??t.hostGid))?Number(t.gid??t.hostGid):null,home:r,scope:
|
|
1227
|
-
uid:Number.isSafeInteger(Number(t.uid??t.hostUid))?Number(t.uid??t.hostUid):null,username:
|
|
1228
|
-
t.userKey)}:{}}function
|
|
1229
|
-
capture",purpose:t="terminal"}={}){return t==="preview"?"preview":e==="pty"?"terminal":"job"}function
|
|
1230
|
-
if(!t)return"";if(!/^[A-Za-z0-9](?:[A-Za-z0-9._:-]{0,254}[A-Za-z0-9])?$/u.test(t))throw
|
|
1231
|
-
ntifier: ${t}.`,"vibe64_execution_identifier_invalid");return t}function
|
|
1232
|
-
purpose:o="terminal",session:i={}}=t,s=
|
|
1233
|
-
|
|
1234
|
-
throw
|
|
1235
|
-
s.ownerId||i.sessionId);if(c==="service"&&!
|
|
1236
|
-
_owner_required");let
|
|
1237
|
-
lityKey","environment"].includes(m))||!/^[a-z0-9][a-z0-9_-]{0,127}$/u.test(
|
|
1238
|
-
"")||!["development","test","production"].includes(
|
|
1239
|
-
"vibe64_resource_profile_invalid");return Object.freeze({...
|
|
1240
|
-
s.controlGenerationId),...s.workflowId===void 0||s.workflowId===null||s.workflowId===""?{}:{workflowId:
|
|
1241
|
-
id:
|
|
1242
|
-
projectSlug:
|
|
1243
|
-
"string"||!/^[a-f0-9]{8}-[a-f0-9]{4}-[1-8][a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$/iu.test(e))throw
|
|
1244
|
-
uires a valid managed workflow id.","vibe64_workflow_id_invalid");return e.toLowerCase()}function
|
|
1245
|
-
e)?
|
|
1246
|
-
imes"),n=
|
|
1247
|
-
|
|
1248
|
-
required");let n=xe(t.mode,
|
|
1249
|
-
"Cancellation signals require a finite capture command.","vibe64_command_signal_invalid");let o=
|
|
1250
|
-
{mode:n}),s=xe(t.purpose,
|
|
1251
|
-
Vibe64 runtime: ${
|
|
1252
|
-
"";if(typeof
|
|
1253
|
-
ployment"||Object.keys(i.env).length||i.envFactory||Object.keys(o).length))throw
|
|
1229
|
+
function tg(e={},t={}){let{mode:r="capture"}=t;if(typeof e=="function"){if(r!=="pty")throw te("Function-valued command e\
|
|
1230
|
+
nv is only supported for PTY commands.","vibe64_command_env_function_requires_pty");return{env:{},envFactory:e}}let n=le(
|
|
1231
|
+
e);return yt(n),{env:n,envFactory:null}}function mi(e=[]){return(Array.isArray(e)?e:[e]).map(C).filter(Boolean)}function rg(e={}){
|
|
1232
|
+
let t=J(e);return{commandPreview:t.commandPreview,detachedIdleTimeoutMs:t.detachedIdleTimeoutMs,helperPayloadRoot:C(t.helperPayloadRoot),
|
|
1233
|
+
maxRunning:t.maxRunning,metadata:t.metadata,namespace:R(t.namespace),namespaceLimitPrefix:R(t.namespaceLimitPrefix),onClose:t.
|
|
1234
|
+
onClose,onOutput:t.onOutput,onStop:t.onStop,reuseRunning:t.reuseRunning,runningLimitFilter:t.runningLimitFilter}}function ng(e={}){
|
|
1235
|
+
let t=J(e),r=C(t.home||t.toolHomeSource);return r?{cacheRoot:C(t.cacheRoot),configRoot:C(t.configRoot),dataRoot:C(t.dataRoot),
|
|
1236
|
+
gid:Number.isSafeInteger(Number(t.gid??t.hostGid))?Number(t.gid??t.hostGid):null,home:r,scope:R(t.scope),stateRoot:C(t.stateRoot),
|
|
1237
|
+
uid:Number.isSafeInteger(Number(t.uid??t.hostUid))?Number(t.uid??t.hostUid):null,username:R(t.username||t.ownerUserKey||
|
|
1238
|
+
t.userKey)}:{}}function og(e="capture"){return e==="detached"?"service":e==="pty"?"interactive":"finite"}function ig({mode:e="\
|
|
1239
|
+
capture",purpose:t="terminal"}={}){return t==="preview"?"preview":e==="pty"?"terminal":"job"}function bt(e=""){let t=R(e);
|
|
1240
|
+
if(!t)return"";if(!/^[A-Za-z0-9](?:[A-Za-z0-9._:-]{0,254}[A-Za-z0-9])?$/u.test(t))throw te(`Invalid Vibe64 execution ide\
|
|
1241
|
+
ntifier: ${t}.`,"vibe64_execution_identifier_invalid");return t}function Jl(e={},t={}){let{mode:r="capture",project:n={},
|
|
1242
|
+
purpose:o="terminal",session:i={}}=t,s=J(e),a=xe(s.kind,Kh,ig({mode:r,purpose:o}),"execution_kind"),c=xe(s.lifecycle,Xh,
|
|
1243
|
+
og(r),"execution_lifecycle");if(r==="detached"&&c!=="service"||r==="pty"&&c!=="interactive"||r==="capture"&&c!=="finite")
|
|
1244
|
+
throw te(`Execution lifecycle ${c} is incompatible with command mode ${r}.`,"vibe64_execution_lifecycle_incompatible");let l=bt(
|
|
1245
|
+
s.ownerId||i.sessionId);if(c==="service"&&!l)throw te("Service execution requires a durable owner id.","vibe64_execution\
|
|
1246
|
+
_owner_required");let u=s.resourceProfile;if(u!=null&&(!u||typeof u!="object"||Object.keys(u).some(m=>!["key","compatibi\
|
|
1247
|
+
lityKey","environment"].includes(m))||!/^[a-z0-9][a-z0-9_-]{0,127}$/u.test(u.key||"")||!/^[a-f0-9]{64}$/u.test(u.compatibilityKey||
|
|
1248
|
+
"")||!["development","test","production"].includes(u.environment)))throw te("Invalid activity resource profile identity.",
|
|
1249
|
+
"vibe64_resource_profile_invalid");return Object.freeze({...u?{resourceProfile:Object.freeze({...u})}:{},controlGenerationId:bt(
|
|
1250
|
+
s.controlGenerationId),...s.workflowId===void 0||s.workflowId===null||s.workflowId===""?{}:{workflowId:sg(s.workflowId)},
|
|
1251
|
+
id:Bh(),kind:a,label:R(s.label),lifecycle:c,operationId:bt(s.operationId),ownerId:l,parentExecutionId:bt(s.parentExecutionId),
|
|
1252
|
+
projectSlug:bt(s.projectSlug||n.slug||n.projectSlug),sessionId:bt(s.sessionId||i.sessionId)})}function sg(e){if(typeof e!=
|
|
1253
|
+
"string"||!/^[a-f0-9]{8}-[a-f0-9]{4}-[1-8][a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$/iu.test(e))throw te("Execution req\
|
|
1254
|
+
uires a valid managed workflow id.","vibe64_workflow_id_invalid");return e.toLowerCase()}function ag(e=""){return Zh.has(
|
|
1255
|
+
e)?Bo:[]}function Yl(e={},t=""){return Object.prototype.hasOwnProperty.call(e,t)}function cg(e={},t=""){let r=Yl(e,"runt\
|
|
1256
|
+
imes"),n=Yl(e,"runtime");if(!r&&!n)return ze(ag(t));let o=r?e.runtimes:e.runtime;return ze((Array.isArray(o)?o:[o]).map(
|
|
1257
|
+
R).filter(Boolean))}function Kl(e={}){let t=J(e),r=R(t.command);if(!r)throw te("A command is required.","vibe64_command_\
|
|
1258
|
+
required");let n=xe(t.mode,qh,"capture","mode");if(t.signal!=null&&(!(t.signal instanceof AbortSignal)||n!=="capture"))throw te(
|
|
1259
|
+
"Cancellation signals require a finite capture command.","vibe64_command_signal_invalid");let o=le(t.baseEnv),i=tg(t.env,
|
|
1260
|
+
{mode:n}),s=xe(t.purpose,Fh,"terminal","purpose"),a=cg(t,s);for(let w of a)if(!Object.hasOwn(wt,w))throw te(`Unsupported\
|
|
1261
|
+
Vibe64 runtime: ${w}.`,"vibe64_command_runtime_unsupported");let c=J(t.project),l=J(t.session),u=t.releaseEnvironmentFile??
|
|
1262
|
+
"";if(typeof u!="string"||u&&(!u.startsWith("/")||/[\r\n\0]/u.test(u)||n!=="capture"||t.actor!=="app"||t.envPolicy!=="de\
|
|
1263
|
+
ployment"||Object.keys(i.env).length||i.envFactory||Object.keys(o).length))throw te("Release environment files require a\
|
|
1254
1264
|
finite application deployment command without caller Env.","vibe64_command_release_environment_invalid");let m=t.usageRecordingPreload??
|
|
1255
1265
|
"";if(typeof m!="string"||m&&(!m.startsWith("/")||/[\s"'\\\0]/u.test(m)||!["preview","output"].includes(s)||t.actor==="a\
|
|
1256
|
-
pp"))throw
|
|
1257
|
-
ding_preload_invalid");let f=t.applicationAccount??"";if(typeof f!="string"||f&&(!
|
|
1258
|
-
ure"))throw
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
"
|
|
1262
|
-
t.
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
t.
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
freeze(["
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
function
|
|
1266
|
+
pp"))throw te("A usage recording preload belongs only to a Preview or Output target launch.","vibe64_command_usage_recor\
|
|
1267
|
+
ding_preload_invalid");let f=t.applicationAccount??"";if(typeof f!="string"||f&&(!zh.test(f)||t.actor!=="app"||n!=="capt\
|
|
1268
|
+
ure"))throw te("Application accounts run only finite application commands.","vibe64_command_application_account_invalid");
|
|
1269
|
+
let h=t.sandboxAllowances??[];if(!Array.isArray(h)||h.some(w=>typeof w!="string"||!/^[a-z][a-z0-9-]*$/u.test(w))||new Set(
|
|
1270
|
+
h).size!==h.length||h.length>0&&!f)throw te("Sandbox allowances belong only to an application account's own commands.","\
|
|
1271
|
+
vibe64_command_sandbox_allowances_invalid");return{actor:xe(t.actor,Hh,"daemon","actor"),applicationAccount:f,allowedRoots:mi(
|
|
1272
|
+
t.allowedRoots),args:eg(t.args,{mode:n}),baseEnv:o,command:r,cwd:C(t.cwd||process.cwd()),env:i.env,envFactory:i.envFactory,
|
|
1273
|
+
envPolicy:xe(t.envPolicy,Yh,"session","env_policy"),releaseEnvironmentFile:u,sandboxAllowances:[...h],execution:Jl(t.execution,
|
|
1274
|
+
{mode:n,project:c,purpose:s,session:l}),credentialHome:ng(t.credentialHome),gitAuthToken:R(t.gitAuthToken),gitSafeDirectories:mi(
|
|
1275
|
+
t.gitSafeDirectories),personGitIdentity:{email:R(t.personGitIdentity?.email),name:R(t.personGitIdentity?.name)},gitTransport:xe(
|
|
1276
|
+
t.gitTransport,Jh,"none","git_transport"),inheritProcessEnv:!u&&t.inheritProcessEnv!==!1,input:t.input,logPath:C(t.logPath),
|
|
1277
|
+
maxBuffer:Number.isSafeInteger(Number(t.maxBuffer))&&Number(t.maxBuffer)>0?Number(t.maxBuffer):Qh,mode:n,onOutput:typeof t.
|
|
1278
|
+
onOutput=="function"?t.onOutput:null,outputEncoding:xe(t.outputEncoding,Wh,"utf8","output_encoding"),project:c,purpose:s,
|
|
1279
|
+
runtimes:a,session:l,signal:t.signal??null,shimDirs:mi(t.shimDirs),terminal:rg(t.terminal),timeout:Number.isSafeInteger(
|
|
1280
|
+
Number(t.timeout))&&Number(t.timeout)>0?Number(t.timeout):15e3,usageRecordingPreload:m,userKey:R(t.userKey)}}var Hh,zh,Fh,
|
|
1281
|
+
qh,Wh,Yh,Jh,Kh,Xh,Qh,Zh,sA,Xl=g(()=>{q();tn();ge();Hh=Object.freeze(["daemon","owner-user","named-user","app"]),zh=/^[a-z_][a-z0-9_-]{0,31}$/u,
|
|
1282
|
+
Fh=Object.freeze(["account","assistant","terminal","codex","github","github-api","source-editor","preview","output","dep\
|
|
1283
|
+
loyment","health","workspace-cache","source"]),qh=Object.freeze(["capture","pty","detached"]),Wh=Object.freeze(["utf8","\
|
|
1284
|
+
base64"]),Yh=Object.freeze(["session","project","preview","auth","deployment"]),Jh=Object.freeze(["none","github-https",
|
|
1285
|
+
"github-token"]),Kh=Object.freeze(["assistant","browser","control","job","preview","service","terminal"]),Xh=Object.freeze(
|
|
1286
|
+
["finite","interactive","service"]),Qh=1e3*1e3*100,Zh=new Set(["assistant","codex","deployment","output","preview","sour\
|
|
1287
|
+
ce","terminal"]);sA=Object.freeze({normalizeExecutionDescriptor:Jl})});function fi(){return lg}function pn(e){return["1","true"].includes(String(e[Ql]||"").trim().toLowerCase())}var lg,Ql,mn=g(
|
|
1288
|
+
()=>{Bt();Vt();pi();Fe();lg=null,Ql="VIBE64_MANAGED_EXECUTION_REQUIRED"});import{realpathSync as Zl,statSync as dg}from"node:fs";import $e from"node:path";import{fileURLToPath as pg}from"node:url";
|
|
1289
|
+
function mg(e){let t=[$e.resolve($e.dirname(e),"../../../vibe64-usage-recording/runtime/node")];for(let r=$e.dirname(e);t.
|
|
1278
1290
|
push($e.join(r,"node_modules/@local/vibe64-usage-recording/runtime/node")),$e.dirname(r)!==r;r=$e.dirname(r));return t.flatMap(
|
|
1279
|
-
r=>{try{return[
|
|
1280
|
-
|
|
1281
|
-
der is not part of this Vibe64 installation."),{code:"vibe64_usage_recording_preload_invalid"})}var
|
|
1282
|
-
"./../node_modules/@local/vibe64-execution/src/server/usageRecordingPreload.js",import.meta.url).href});function
|
|
1283
|
-
e_environment_unavailable",{execution:e.execution}):e.applicationAccount?
|
|
1284
|
-
aged host.","vibe64_application_account_unavailable",{execution:e.execution}):null}async function
|
|
1285
|
-
cwd:n,env:o,requiresHelper:i,resolveEnv:s}=t,a=
|
|
1286
|
-
|
|
1287
|
-
e.mode==="detached"?r.requiresRealUser&&(!
|
|
1288
|
-
er is required.","vibe64_command_detached_real_user_unsupported",{execution:e.execution}):
|
|
1289
|
-
{...await
|
|
1291
|
+
r=>{try{return[Zl(r)]}catch{return[]}})}function eu(e="",t=pg(ug)){try{if($e.resolve(e)===e&&Zl(e)===e&&dg(e).isFile()&&
|
|
1292
|
+
mg(t).some(r=>e.startsWith(`${r}${$e.sep}`)))return`--import=${e}`}catch{}throw Object.assign(new Error("The usage recor\
|
|
1293
|
+
der is not part of this Vibe64 installation."),{code:"vibe64_usage_recording_preload_invalid"})}var ug,tu=g(()=>{ug=new URL(
|
|
1294
|
+
"./../node_modules/@local/vibe64-execution/src/server/usageRecordingPreload.js",import.meta.url).href});function ru(e){return e.releaseEnvironmentFile?X("Release environment execution requires a managed host.","vibe64_releas\
|
|
1295
|
+
e_environment_unavailable",{execution:e.execution}):e.applicationAccount?X("Application account execution requires a man\
|
|
1296
|
+
aged host.","vibe64_application_account_unavailable",{execution:e.execution}):null}async function fg(e,t={}){let{actor:r,
|
|
1297
|
+
cwd:n,env:o,requiresHelper:i,resolveEnv:s}=t,a=ru(e);if(a)return a;if(e.usageRecordingPreload){let c=eu(e.usageRecordingPreload),
|
|
1298
|
+
l=s;o={...o,NODE_OPTIONS:c},s=u=>({...l(u),NODE_OPTIONS:c})}return e.mode==="pty"?zl(e,{actor:r,cwd:n,env:o,resolveEnv:s}):
|
|
1299
|
+
e.mode==="detached"?r.requiresRealUser&&(!ht(r)||i)?X("Detached real-user command execution is unsupported when the help\
|
|
1300
|
+
er is required.","vibe64_command_detached_real_user_unsupported",{execution:e.execution}):mc(e,{actor:r,cwd:n,env:o}):i?
|
|
1301
|
+
{...await Co(Fr({actor:r,args:e.args,command:e.command,cwd:n,env:o,input:e.input,operation:Ht(e)}),{env:process.env,maxBuffer:e.
|
|
1290
1302
|
maxBuffer,outputEncoding:e.outputEncoding,signal:e.signal,timeout:e.timeout}),execution:e.execution}:Gt(e.command,e.args,
|
|
1291
1303
|
{cwd:n,env:o,execution:e.execution,input:e.input,maxBuffer:e.maxBuffer,onOutput:e.onOutput,outputEncoding:e.outputEncoding,
|
|
1292
|
-
signal:e.signal,timeout:e.timeout})}async function Qt(e={}){let t=null;try{if(t=
|
|
1293
|
-
d cancelled.","vibe64_command_cancelled",{execution:t.execution});let r=await
|
|
1294
|
-
...t.baseEnv}:{...t.baseEnv},o=(d={})=>({...d,VIBE64_EXECUTION_ID:t.execution.id}),i=
|
|
1295
|
-
r),
|
|
1296
|
-
request:t.releaseEnvironmentFile?{...t,project:{},session:{}}:t})),m=Object.fromEntries([Je,Ye,Xe,Ke].map(d=>[d,
|
|
1297
|
-
|
|
1298
|
-
args=="function"?t.args(d):t.args,
|
|
1299
|
-
...t,env:t.envFactory(d),envFactory:null}}):
|
|
1300
|
-
if(i)return await i.runCommand(t,{actor:r,baseEnv:n,cwd:f,env:
|
|
1301
|
-
(s?
|
|
1302
|
-
ilable",{execution:t.execution,retryable:!1}):
|
|
1303
|
-
64_command_failed",{execution:t?.execution})}}var
|
|
1304
|
-
|
|
1305
|
-
execution/src/server/gitTurnCheckpoint.js",import.meta.url).href,
|
|
1306
|
-
6e4,
|
|
1307
|
-
e||"").trim();return
|
|
1308
|
-
function
|
|
1309
|
-
r)&&
|
|
1310
|
-
"darwin"&&
|
|
1311
|
-
"brew"&&!o&&["git","cpp"].includes(
|
|
1312
|
-
if(!s&&i.mise&&(s=n?`mise use -g ${i.mise}`:`${
|
|
1313
|
-
"sudo ")||r==="apt"&&s.includes("--with-deps");return{command:s,sudo:a,note:a?
|
|
1314
|
-
|
|
1304
|
+
signal:e.signal,timeout:e.timeout})}async function Qt(e={}){let t=null;try{if(t=Kl(e),t.signal?.aborted)return X("Comman\
|
|
1305
|
+
d cancelled.","vibe64_command_cancelled",{execution:t.execution});let r=await Pc(t),n=t.inheritProcessEnv?{...process.env,
|
|
1306
|
+
...t.baseEnv}:{...t.baseEnv},o=(d={})=>({...d,VIBE64_EXECUTION_ID:t.execution.id}),i=fi(),s=pn(n)||pn(process.env),a=Yr(
|
|
1307
|
+
r),l=!(!!i||s||Uo())&&ht(r)?[n.PATH,process.env.PATH].filter(Boolean).join(":"):"",u=o(await Il({actor:r,baseEnv:n,localPath:l,
|
|
1308
|
+
request:t.releaseEnvironmentFile?{...t,project:{},session:{}}:t})),m=Object.fromEntries([Je,Ye,Xe,Ke].map(d=>[d,u[d]]));
|
|
1309
|
+
kc(r,u);let f=ql(t.cwd,{allowedRoots:t.allowedRoots,resolveLinks:!t.applicationAccount});Cc(r,t,f);let h=(d={})=>typeof t.
|
|
1310
|
+
args=="function"?t.args(d):t.args,w=(d={})=>o(t.envFactory?Qo({actor:r,baseEnv:n,localPath:l,resolvedGitIdentityEnv:m,request:{
|
|
1311
|
+
...t,env:t.envFactory(d),envFactory:null}}):u),I=(d=t,p={})=>fg(d,{actor:r,cwd:f,env:u,requiresHelper:a,resolveEnv:w,...p});
|
|
1312
|
+
if(i)return await i.runCommand(t,{actor:r,baseEnv:n,cwd:f,env:u,resolveArgs:h,resolveEnv:w,runLocal:I});let S=ru(t);return S||
|
|
1313
|
+
(s?X("Managed execution safety is unavailable. Vibe64 did not start this work.","vibe64_managed_execution_provider_unava\
|
|
1314
|
+
ilable",{execution:t.execution,retryable:!1}):I())}catch(r){return X(r?.message||"Vibe64 command failed.",r?.code||"vibe\
|
|
1315
|
+
64_command_failed",{execution:t?.execution})}}var fn=g(()=>{Rc();Zo();gt();Bt();qr();Vt();pi();Wl();Jr();Xl();Fe();mn();
|
|
1316
|
+
tu()});import{fileURLToPath as gg}from"node:url";var hg,MA,DA,UA,VA,nu=g(()=>{Re();hg=new URL("./../node_modules/@local/vibe64-\
|
|
1317
|
+
execution/src/server/gitTurnCheckpoint.js",import.meta.url).href,MA=gg(new URL("./gitTurnCheckpointCommand.js",hg)),DA=15*
|
|
1318
|
+
6e4,UA=512*1024*1024,VA=1024*1024*1024});var HA,ou=g(()=>{q();HA=Object.freeze(["LANG","LC_ALL","NO_PROXY","PATH","SSL_CERT_DIR","SSL_CERT_FILE","TZ"])});var iu=g(()=>{});import{existsSync as wg}from"node:fs";import hn from"node:path";import su from"node:process";function hi(e=""){let t=String(
|
|
1319
|
+
e||"").trim();return _g[t]||t}function cu({platform:e=su.platform,aptGet:t=!1}={}){return e==="darwin"?"brew":t?"apt":""}
|
|
1320
|
+
function Eg(e,t=Jt){return[...String(e.PATH||"").split(hn.delimiter),...String(t||"").split(hn.delimiter)].some(r=>hn.isAbsolute(
|
|
1321
|
+
r)&&wg(hn.join(r,"apt-get")))}function wn({env:e,platform:t=su.platform,systemPath:r}){return cu({platform:t,aptGet:t!==
|
|
1322
|
+
"darwin"&&Eg(e,r)})}function yn(e="",t={}){let{family:r="",mise:n=!1,xcode:o=!0}=t,i=gn[hi(e)];if(!i)return null;if(r===
|
|
1323
|
+
"brew"&&!o&&["git","cpp"].includes(hi(e)))return{command:"xcode-select --install",sudo:!1,note:""};let s=i.any||i[r]||"";
|
|
1324
|
+
if(!s&&i.mise&&(s=n?`mise use -g ${i.mise}`:`${yg} && ~/.local/bin/mise use -g ${i.mise}`),!s)return null;let a=s.startsWith(
|
|
1325
|
+
"sudo ")||r==="apt"&&s.includes("--with-deps");return{command:s,sudo:a,note:a?au:""}}var au,yg,KA,gn,_g,XA,Zt=g(()=>{nn();
|
|
1326
|
+
au="You'll be asked for your computer password. Nothing shows while you type.",yg="curl -fsSL https://mise.run | sh",KA=
|
|
1315
1327
|
Object.freeze({linux:"https://github.com/mobily-enterprises/vibe64/blob/main/docs/colleague-usage/set-up-linux.md",darwin:"\
|
|
1316
|
-
https://github.com/mobily-enterprises/vibe64/blob/main/docs/colleague-usage/set-up-macos.md"}),
|
|
1328
|
+
https://github.com/mobily-enterprises/vibe64/blob/main/docs/colleague-usage/set-up-macos.md"}),gn=Object.freeze({claude:{
|
|
1317
1329
|
name:"Claude Code",run:[["claude"]],guideUrl:"https://code.claude.com/docs/en/setup",any:"curl -fsSL https://claude.ai/i\
|
|
1318
1330
|
nstall.sh | bash"},codex:{name:"Codex",run:[["codex"]],guideUrl:"https://github.com/openai/codex",any:"curl -fsSL https:\
|
|
1319
1331
|
//chatgpt.com/codex/install.sh | sh"},opencode:{name:"opencode",run:[["opencode"]],guideUrl:"https://opencode.ai/docs/",
|
|
@@ -1337,17 +1349,17 @@ rl -fsSL https://php.new/install/linux)"',brew:'/bin/bash -c "$(curl -fsSL https
|
|
|
1337
1349
|
ild tools",setup:"build-tools",run:[["cc","gcc","clang"],["make"]],guideUrl:"https://guides.rubyonrails.org/install_ruby\
|
|
1338
1350
|
_on_rails.html",detail:"Some packages compile native code, so they need a compiler and a few libraries.",apt:"sudo apt i\
|
|
1339
1351
|
nstall build-essential pkg-config libyaml-dev libssl-dev zlib1g-dev libpq-dev default-libmysqlclient-dev libgmp-dev",brew:"\
|
|
1340
|
-
brew install pkg-config libyaml openssl@3 gmp"}}),
|
|
1341
|
-
function
|
|
1342
|
-
`)}function
|
|
1352
|
+
brew install pkg-config libyaml openssl@3 gmp"}}),_g=Object.freeze({composer:"php"});XA=Object.freeze({SUDO_NOTE:au,localToolFamily:cu})});function lu({env:e,platform:t,systemPath:r}){return yn("git",{family:wn({env:e,platform:t,systemPath:r})})?.command||""}
|
|
1353
|
+
function bg(e={}){return[e.error,e.stderr,e.output].filter(Boolean).join(`
|
|
1354
|
+
`)}function vg(e,t){let r=bg(e);if(/spawn(?:Sync)? git ENOENT|(?:^|\s)git: (?:command )?not found/mu.test(r)){let n=lu(t);
|
|
1343
1355
|
return{code:"vibe64_git_missing",installCommand:n,message:n?`Git isn't installed on this computer. Install it with: ${n}`:
|
|
1344
1356
|
"Git isn't installed on this computer. Install Git, then try again."}}return/unknown option [`']initial-branch/u.test(r)?
|
|
1345
|
-
{code:"vibe64_git_too_old",installCommand:
|
|
1357
|
+
{code:"vibe64_git_too_old",installCommand:lu(t),message:"This Git is too old for Vibe64. Update Git to version 2.28 or n\
|
|
1346
1358
|
ewer, then try again."}:/gpg failed to sign|failed to sign the data|signing failed|couldn't (?:load|find) (?:public )?key|incorrect passphrase/iu.
|
|
1347
1359
|
test(r)?{code:"vibe64_git_signing_failed",installCommand:"",message:"Your Git is set to sign every commit, and signing d\
|
|
1348
1360
|
idn't work here. Vibe64 can't type a key passphrase for you. Make one signed commit in a terminal to check your key work\
|
|
1349
|
-
s and is unlocked, then try again."}:null}var
|
|
1350
|
-
backups.git",
|
|
1361
|
+
s and is unlocked, then try again."}:null}var eO,uu=g(()=>{Zt();eO=Object.freeze({describeGitFailure:vg})});var gi=g(()=>{});import du from"node:path";function Tg(e=""){return e?du.join(du.dirname(e),pu):""}var pu,mu,Ig,iO,sO,fu=g(()=>{gi();pu="\
|
|
1362
|
+
backups.git",mu="vibe64-atomic",Ig=`backup_canonical_ref() {
|
|
1351
1363
|
vibe64_backup_repository="$1"
|
|
1352
1364
|
vibe64_source_repository="$2"
|
|
1353
1365
|
vibe64_source_ref="$3"
|
|
@@ -1365,13 +1377,13 @@ r "$vibe64_backup_repository" rev-parse --verify "$vibe64_backup_ref"
|
|
|
1365
1377
|
' "$vibe64_source_ref" >&2
|
|
1366
1378
|
return 1
|
|
1367
1379
|
fi
|
|
1368
|
-
}`,
|
|
1380
|
+
}`,iO=`#!/bin/sh
|
|
1369
1381
|
set -eu
|
|
1370
1382
|
|
|
1371
1383
|
zero_object=0000000000000000000000000000000000000000
|
|
1372
1384
|
git_dir="$(git rev-parse --absolute-git-dir)"
|
|
1373
1385
|
repository_root="$(dirname "$git_dir")"
|
|
1374
|
-
backup_repository="$repository_root/${
|
|
1386
|
+
backup_repository="$repository_root/${pu}"
|
|
1375
1387
|
if [ -L "$repository_root" ] || [ -L "$backup_repository" ] || [ -L "$repository_root/mutation.lock" ]; then
|
|
1376
1388
|
printf '[vibe64] Canonical repository storage must not use symlinked role paths.
|
|
1377
1389
|
' >&2
|
|
@@ -1380,7 +1392,7 @@ fi
|
|
|
1380
1392
|
exec 8>"$repository_root/mutation.lock"
|
|
1381
1393
|
flock -x 8
|
|
1382
1394
|
|
|
1383
|
-
if [ "\${GIT_PUSH_OPTION_COUNT:-0}" != "1" ] || [ "\${GIT_PUSH_OPTION_0:-}" != "${
|
|
1395
|
+
if [ "\${GIT_PUSH_OPTION_COUNT:-0}" != "1" ] || [ "\${GIT_PUSH_OPTION_0:-}" != "${mu}" ]; then
|
|
1384
1396
|
printf '[vibe64] Canonical repository pushes must use the Vibe64 atomic mutation path.
|
|
1385
1397
|
' >&2
|
|
1386
1398
|
exit 1
|
|
@@ -1391,7 +1403,7 @@ if [ "$(git --git-dir "$backup_repository" rev-parse --is-bare-repository 2>/dev
|
|
|
1391
1403
|
exit 1
|
|
1392
1404
|
fi
|
|
1393
1405
|
|
|
1394
|
-
${
|
|
1406
|
+
${Ig}
|
|
1395
1407
|
|
|
1396
1408
|
updates_file="$(mktemp "$repository_root/.pre-receive.XXXXXX")"
|
|
1397
1409
|
cleanup_updates_file() {
|
|
@@ -1439,366 +1451,372 @@ while read -r old_object _new_object ref_name; do
|
|
|
1439
1451
|
backup_canonical_ref "$backup_repository" "$git_dir" "$ref_name" "$old_object" "$backup_ref"
|
|
1440
1452
|
fi
|
|
1441
1453
|
done <"$updates_file"
|
|
1442
|
-
`;
|
|
1443
|
-
wserWorkerSource.js",import.meta.url).href});var
|
|
1454
|
+
`;sO=Object.freeze({CANONICAL_REPOSITORY_PUSH_OPTION:mu,canonicalRepositoryBackupPath:Tg})});var hu=g(()=>{qt();ge()});var wi=g(()=>{});var gu=g(()=>{});var wu=g(()=>{});var yi=g(()=>{});var wO,yu=g(()=>{gu();wu();yi();wO=new URL("./../node_modules/@local/vibe64-execution/src/server/runtime/agentPreviewBro\
|
|
1455
|
+
wserWorkerSource.js",import.meta.url).href});var Og,_u=g(()=>{Og=["Usage:"," vibe64-helper preview ensure [--target <target-id>] [--wait] [--json] [--timeout-ms <ms\
|
|
1444
1456
|
>]"," vibe64-helper preview targets [--json]"," vibe64-helper preview status [--json]"," vibe64-helper preview stop [\
|
|
1445
|
-
--json]"," vibe64-helper preview
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
" vibe64-helper preview browser
|
|
1450
|
-
vibe64-helper preview identities
|
|
1451
|
-
|
|
1452
|
-
-identity <default|guest|configured-name>] test [playwright test
|
|
1453
|
-
|
|
1454
|
-
status/ensure/restart/stop --json: ready, stoppedIntent, stale,
|
|
1455
|
-
}, currentPage {url, route, title, observedAt}, terminal {id, status,
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1457
|
+
--json]"," vibe64-helper preview open <path> [--json]"," vibe64-helper preview inspect-url"," vibe64-helper preview s\
|
|
1458
|
+
creenshot [--output <path>]"," vibe64-helper preview browser ensure"," vibe64-helper preview browser eval < playwright\
|
|
1459
|
+
-code.js"," vibe64-helper preview browser identity <default|guest|configured-name>"," vibe64-helper preview browser st\
|
|
1460
|
+
orage-state <default|guest|configured-name> --output <new-path>"," vibe64-helper preview browser screenshot [--output <\
|
|
1461
|
+
path>]"," vibe64-helper preview browser status"," vibe64-helper preview browser reset"," vibe64-helper preview browse\
|
|
1462
|
+
r close"," vibe64-helper preview identities"," vibe64-helper preview identities save < identities.json"," vibe64-help\
|
|
1463
|
+
er preview logs [--lines <count>] [--json]"," vibe64-helper preview restart [--wait] [--json] [--timeout-ms <ms>]"," v\
|
|
1464
|
+
ibe64-helper playwright [--target <target-id>] [--identity <default|guest|configured-name>] test [playwright test argume\
|
|
1465
|
+
nts]"," vibe64-helper playwright [--target <target-id>] [--identity <default|guest|configured-name>] npm-run <package-s\
|
|
1466
|
+
cript> [-- script arguments]","","JSON output:"," status/ensure/restart/stop --json: ready, stoppedIntent, stale, outpu\
|
|
1467
|
+
tTargetId, endpoints.browser {url, hostname, port}, currentPage {url, route, title, observedAt}, terminal {id, status, r\
|
|
1468
|
+
unning, exitCode, command, createdAt}, defaultIdentity, identities [{name, type}], identityTypes, diagnostics {latest, l\
|
|
1469
|
+
og, directApplicationEndpoint}."," open --json: path, moved (how many of the person's open Previews moved to it), error\
|
|
1470
|
+
s (why one that answered did not move)."," screenshot: outputPath, byteLength, sha256, capturedAt, url, title, width, h\
|
|
1471
|
+
eight, luminance, darkPixelPercentage, domTextLength, domTextSummary."," browser eval: result (the code's JSON-safe ret\
|
|
1472
|
+
urn value), logs [{level, values}] from console, url (the page afterwards)."," identities: the project's Managed app id\
|
|
1473
|
+
entities [{name, type, value}] (first is the default) and the Stack's declared Preview identity types.",' identities sa\
|
|
1474
|
+
ve: replaces the whole ordered list with the JSON array on stdin (or {"identities": [...]}); each type must be declared.\
|
|
1475
|
+
Save only names and accounts the person asked for or confirmed; never create app accounts or change roles for this. The\
|
|
1476
|
+
n verify each with preview browser identity <name>.'," browser storage-state: writes the identity's Playwright storage \
|
|
1477
|
+
state to a new file at --output; the interactive browser keeps its identity.","","When the person asks to see a page, ru\
|
|
1478
|
+
n preview open with its path inside the app (/orders/42?tab=notes): it moves every Preview pane they have open for this \
|
|
1479
|
+
session to that page, as their Preview address box would, and they see a note that the AI opened it. Only paths starting\
|
|
1480
|
+
with a single / are accepted, never other sites. If it reports moved: 0, give them the path to type into the Preview ad\
|
|
1481
|
+
dress box instead. Your own browser commands never move their pane.","Screenshot commands emit JSON metadata for a uniqu\
|
|
1482
|
+
ely named, immutable PNG.","For browser navigation, use preview inspect-url or the status Browser URL; these use the man\
|
|
1483
|
+
aged Preview proxy.","Inside browser eval, navigate with await page.goto(new URL('/your-path', preview.url).href).","The\
|
|
1484
|
+
direct application endpoint in diagnostics bypasses Preview identity; do not use it for interactive browsing.","The bro\
|
|
1485
|
+
wser keeps its page between browser commands. After each command the page keeps running for 30 seconds, then pauses (no \
|
|
1486
|
+
timers, animations or network handling) until the next browser command. For a longer wait, wait inside the command, for \
|
|
1487
|
+
example with await page.waitForSelector(...).","Five minutes after the last browser command ends, the browser closes; th\
|
|
1488
|
+
e next command opens a fresh page, so select its identity again if needed.","Managed Playwright suites and live preview \
|
|
1489
|
+
browser actions are sequential. Wait on the suite through cleanup and restoration before browser actions or Preview ensu\
|
|
1490
|
+
re/restart/target changes; confirm playwright status has no active run and preview status is ready. Read-only status and\
|
|
1491
|
+
logs are safe during a suite.","For background commands, wait on the existing execution/session with about a 30-second \
|
|
1492
|
+
window where supported: set yield_time_ms: 30000 for an empty command poll. Reserve shorter waits for interactive input \
|
|
1493
|
+
or a specific immediate check; do not repeatedly reread empty or unchanged logs between brief waits.","This is the canon\
|
|
1494
|
+
ical preview server for the configured primary application.","Do not start a duplicate copy of that application on anoth\
|
|
1495
|
+
er port.","A distinct secondary application explicitly requested by the user, such as a reference app, may run separatel\
|
|
1496
|
+
y without replacing this preview."].join(`
|
|
1479
1497
|
`)+`
|
|
1480
|
-
`});var
|
|
1481
|
-
-execution/src/server/conversationExecution.js",import.meta.url).href,
|
|
1498
|
+
`});var Eu=g(()=>{});import{fileURLToPath as kg}from"node:url";var Cg,PO,bu=g(()=>{fn();mn();Re();Cg=new URL("./../node_modules/@local/vibe64\
|
|
1499
|
+
-execution/src/server/conversationExecution.js",import.meta.url).href,PO=kg(new URL("./engines/stdioBridge.js",Cg))});var $O,vu=g(()=>{fn();Zt();ge();$O=["skip=$1; version=$2; shift 2",'for name in "$@"; do',' found=$(command -v -- "$nam\
|
|
1482
1500
|
e" 2>/dev/null) || continue'," case $found in /*) ;; *) continue ;; esac",' if [ -n "$skip" ]; then case $found in /us\
|
|
1483
1501
|
r/bin/*) continue ;; esac; fi',` printf '%s\\n' "$found"`,' exec "$found" $version 2>&1',"done","exit 127"].join(`
|
|
1484
|
-
`)});var
|
|
1485
|
-
any:n}=
|
|
1486
|
-
ge();
|
|
1487
|
-
maxBuffer:f=1024*1024}=
|
|
1488
|
-
roject",gitSafeDirectories:[t],input:m,maxBuffer:f,mode:"capture",outputEncoding:
|
|
1489
|
-
if(h.ok!==!0)throw Object.assign(new Error(h.error||"Git could not read the pinned topic."),{code:h.code});return
|
|
1490
|
-
ase64"?Buffer.from(h.stdout,"base64"):h.stdout.trim()};if(await
|
|
1502
|
+
`)});var xg,Su=g(()=>{Zt();ge();xg=Object.freeze(Object.fromEntries(["claude","codex","opencode"].map(e=>{let{name:t,guideUrl:r,
|
|
1503
|
+
any:n}=gn[e];return[e,Object.freeze({name:t,guideUrl:r,install:n})]})))});import{execFile as $g}from"node:child_process";import{promisify as jg}from"node:util";var GO,Iu=g(()=>{GO=jg($g)});var Tu=g(()=>{Gr();rc();mt();qr();Oc();fn();Bt();Fe();mn();nu();Zo();ou();iu();tn();Ko();gt();uu();gi();fu();q();qt();Re();
|
|
1504
|
+
ge();hu();wi();yu();yi();_u();Eu();bu();Zt();vu();Su();Iu();wi()});import{realpath as Au}from"node:fs/promises";async function er(e){let t=await Au(e),r=async(c,l="utf8",u={})=>{let{input:m,
|
|
1505
|
+
maxBuffer:f=1024*1024}=u,h=await Qt({actor:"daemon",allowedRoots:[t],args:["-C",t,...c],command:"git",cwd:t,envPolicy:"p\
|
|
1506
|
+
roject",gitSafeDirectories:[t],input:m,maxBuffer:f,mode:"capture",outputEncoding:l,purpose:"source",runtimes:["git"],timeout:6e4});
|
|
1507
|
+
if(h.ok!==!0)throw Object.assign(new Error(h.error||"Git could not read the pinned topic."),{code:h.code});return l==="b\
|
|
1508
|
+
ase64"?Buffer.from(h.stdout,"base64"):h.stdout.trim()};if(await Au(await r(["rev-parse","--show-toplevel"]))!==t)throw new Error(
|
|
1491
1509
|
"Choose the topic repository root.");let n=await r(["rev-parse","HEAD"]);if(await r(["status","--porcelain","--untracked\
|
|
1492
1510
|
-files=all"]))throw new Error("Commit the topic content before generating a pinned course manifest.");let o=await He(t),
|
|
1493
1511
|
i=JSON.parse(await r(["show",`${n}:package.json`])),s=String(i.repository?.url||"").match(/^https:\/\/github\.com\/([a-zA-Z0-9_.-]+\/learn-[a-zA-Z0-9_.-]+)\.git$/u)?.[1];
|
|
1494
1512
|
if(!s)throw new Error("Topic package needs its canonical https://github.com/<owner>/learn-<topic>.git repository URL.");
|
|
1495
|
-
let a=Be([o.topicManifest,...o.bundles.map(c=>c.manifest)]);for(let c=0;c<a.length;){let
|
|
1496
|
-
byteLength(a[
|
|
1497
|
-
c,
|
|
1498
|
-
h=0;for(let
|
|
1499
|
-
h,
|
|
1500
|
-
`Topic input differs from its pinned commit: ${
|
|
1501
|
-
a while reading the pinned topic.");c=
|
|
1513
|
+
let a=Be([o.topicManifest,...o.bundles.map(c=>c.manifest)]);for(let c=0;c<a.length;){let l=c,u=0;do u+=a[l].bytes+Buffer.
|
|
1514
|
+
byteLength(a[l].path)+128,l+=1;while(l<a.length&&u+a[l].bytes+Buffer.byteLength(a[l].path)+128<=1024*1024);let m=a.slice(
|
|
1515
|
+
c,l),f=await r(["cat-file","--batch","-Z"],"base64",{input:m.map(w=>`${n}:${w.path}\0`).join(""),maxBuffer:2*1024*1024}),
|
|
1516
|
+
h=0;for(let w of m){let I=f.indexOf(0,h),S=I<0?null:/^(?:[a-f0-9]{40}|[a-f0-9]{64}) blob (0|[1-9][0-9]*)$/u.exec(f.subarray(
|
|
1517
|
+
h,I).toString("ascii")),d=S?Number(S[1]):-1,p=I+1+d;if(d!==w.bytes||f[p]!==0||K(f.subarray(I+1,p))!==w.sha256)throw new Error(
|
|
1518
|
+
`Topic input differs from its pinned commit: ${w.path}.`);h=p+1}if(h!==f.length)throw new Error("Unexpected trailing dat\
|
|
1519
|
+
a while reading the pinned topic.");c=l}if(await r(["rev-parse","HEAD"])!==n||await r(["status","--porcelain","--untrack\
|
|
1502
1520
|
ed-files=all"]))throw new Error("Topic changed during manifest generation. Commit and retry.");return{topicId:o.topic.topicId,
|
|
1503
|
-
release:o.release,repository:s,commit:n,topicManifest:o.topicManifest,topicHash:o.topicHash}}function tr(e,t){let r=ce(
|
|
1521
|
+
release:o.release,repository:s,commit:n,topicManifest:o.topicManifest,topicHash:o.topicHash}}function tr(e,t){let r=ce(jr,
|
|
1504
1522
|
e,"Course");if(!/^[a-z][a-z0-9-]{0,63}$/u.test(r.courseId)||!/^\d+\.\d+\.\d+$/u.test(r.release)||!r.topics.length)throw new Error(
|
|
1505
1523
|
"Course needs an ID, exact release and at least one whole topic.");let n=new Set,o=r.topics.map(i=>{if(n.has(i.topicId))
|
|
1506
|
-
throw new Error(`Duplicate course topic: ${i.topicId}.`);n.add(i.topicId);let s=t.filter(
|
|
1524
|
+
throw new Error(`Duplicate course topic: ${i.topicId}.`);n.add(i.topicId);let s=t.filter(u=>u.topicId===i.topicId&&u.release===
|
|
1507
1525
|
i.release);if(s.length!==1)throw new Error(`Resolve exactly one pinned topic release: ${i.topicId}@${i.release}.`);let a=s[0];
|
|
1508
1526
|
if(!/^[a-zA-Z0-9_.-]+\/learn-[a-zA-Z0-9_.-]+$/u.test(a.repository||"")||!/^[a-f0-9]{40}$/u.test(a.commit||""))throw new Error(
|
|
1509
1527
|
`Topic requires a repository and immutable commit: ${i.topicId}.`);let c=a.topicManifest;if(!c||c.schemaVersion!==1||c.topic?.
|
|
1510
|
-
topicId!==i.topicId||c.release!==i.release||
|
|
1511
|
-
topicId}.`);if(ce(
|
|
1512
|
-
rse requires a released topic: ${i.topicId}.`);let
|
|
1513
|
-
|
|
1514
|
-
let f=c.lessons[
|
|
1528
|
+
topicId!==i.topicId||c.release!==i.release||K(L(c))!==a.topicHash)throw new Error(`Topic manifest identity mismatch: ${i.
|
|
1529
|
+
topicId}.`);if(ce($r,c.topic,i.topicId),r.status==="released"&&c.topic.status!=="released")throw new Error(`Released cou\
|
|
1530
|
+
rse requires a released topic: ${i.topicId}.`);let l=c.topic.lessons;if(!Array.isArray(l)||!l.length||!Array.isArray(c.lessons)||
|
|
1531
|
+
l.length!==c.lessons.length)throw new Error(`Incomplete whole-topic inventory: ${i.topicId}.`);for(let[u,m]of l.entries()){
|
|
1532
|
+
let f=c.lessons[u];if(f.code!==m.code||f.status!==m.status||f.required!==m.required||!/^[a-f0-9]{64}$/u.test(f.hash||""))
|
|
1515
1533
|
throw new Error(`Changed whole-topic order or lesson identity: ${i.topicId}.`);if(r.status==="released"&&f.required&&f.status!==
|
|
1516
1534
|
"published")throw new Error(`Released course includes required draft: ${f.code}.`)}return{topicId:i.topicId,release:i.release,
|
|
1517
|
-
repository:a.repository,commit:a.commit,manifestHash:a.topicHash,lessons:c.lessons.map(
|
|
1535
|
+
repository:a.repository,commit:a.commit,manifestHash:a.topicHash,lessons:c.lessons.map(u=>({...u}))}});if(r.orientation!==
|
|
1518
1536
|
void 0&&!o.some(i=>i.lessons.some(s=>s.code===r.orientation&&s.status==="published")))throw new Error(`Course orientatio\
|
|
1519
1537
|
n ${r.orientation} must be a published lesson of the course.`);return{schemaVersion:1,courseId:r.courseId,release:r.release,
|
|
1520
|
-
status:r.status,topics:o}}var
|
|
1521
|
-
return
|
|
1522
|
-
assign(new Error(e,r?{cause:r}:void 0),{code:t})}var
|
|
1538
|
+
status:r.status,topics:o}}var _n=g(()=>{Tu();dt();lt();ut()});function vt(e,t,r){let{statusCode:n,cause:o,...i}=r,s=new ae(n,e,{...i,code:t});return o&&(s.cause=o),s}function En(e,t,r=409,n={}){
|
|
1539
|
+
return vt(e,t,{...n,statusCode:r})}function ye(e,t,r,n){return vt(e,t,{statusCode:r,cause:n})}function _i(e,t,r){return Object.
|
|
1540
|
+
assign(new Error(e,r?{cause:r}:void 0),{code:t})}var LR,bn=g(()=>{Tr();LR=128*1024});var Ou=g(()=>{});import{lstat as Lg,readFile as Mg,readdir as Dg,realpath as Ug}from"node:fs/promises";import D from"node:path";function Ei(e){
|
|
1523
1541
|
return me(e)?{...e,steps:e.steps.map(t=>{if(t.check.kind!=="choice")return t;let{answer:r,...n}=t.check;return{...t,check:n}})}:
|
|
1524
|
-
e}function et(e,t={}){let r=ce(
|
|
1525
|
-
r.topicId)||r.commit!==(t.commit??r.commit)||!/^\d+\.\d+\.\d+$/u.test(r.release)||!
|
|
1542
|
+
e}function et(e,t={}){let r=ce(Gg,e,"Installed topic pin");if(!je.test(r.topicId)||!bi.test(r.commit)||r.topicId!==(t.topicId??
|
|
1543
|
+
r.topicId)||r.commit!==(t.commit??r.commit)||!/^\d+\.\d+\.\d+$/u.test(r.release)||!Vg.test(r.repository)||!nr.test(r.topicHash))
|
|
1526
1544
|
throw new Error("Installed pin does not match the requested topic, commit or canonical source identity.");if(r.topicHash!==
|
|
1527
1545
|
(t.topicHash??r.topicHash))throw new Error("Installed topic differs from the trusted course or attempt pin.");return r}async function or(e,t){
|
|
1528
|
-
let r=await
|
|
1546
|
+
let r=await Lg(e);if(r.isSymbolicLink()||await Ug(e)!==e)throw new Error("Installed content cannot use symlink or direct\
|
|
1529
1547
|
ory aliases.");if(t?!r.isDirectory():!r.isFile())throw new Error(`Installed content needs a regular ${t?"directory":"fil\
|
|
1530
|
-
e"}.`);return r}async function
|
|
1531
|
-
limit.`);let n=await
|
|
1532
|
-
let t=[],r=0;async function n(o){await or(o,!0);for(let i of await
|
|
1548
|
+
e"}.`);return r}async function St(e,t){if((await or(e,!1)).size>t)throw new Error(`Installed file exceeds its ${t}-byte \
|
|
1549
|
+
limit.`);let n=await Mg(e);if(n.length>t)throw new Error(`Installed file exceeds its ${t}-byte limit.`);return n}async function Bg(e){
|
|
1550
|
+
let t=[],r=0;async function n(o){await or(o,!0);for(let i of await Dg(o,{withFileTypes:!0})){if(++r>65536)throw new Error(
|
|
1533
1551
|
"Installed snapshot exceeds 65536 directory entries.");let s=D.join(o,i.name);i.isDirectory()?await n(s):(await or(s,!1),
|
|
1534
|
-
t.push(D.relative(e,s).split(D.sep).join("/")))}}return await n(e),t.sort()}function ir({systemRoot:e}){return
|
|
1535
|
-
function
|
|
1536
|
-
te server-owned system root.");let r=D.resolve(e),n=new Map;function o(d){return
|
|
1552
|
+
t.push(D.relative(e,s).split(D.sep).join("/")))}}return await n(e),t.sort()}function ir({systemRoot:e}){return zg(e,Hg)}
|
|
1553
|
+
function zg(e,t){if(typeof e!="string"||!e||!D.isAbsolute(e))throw new Error("Installed teaching content needs an absolu\
|
|
1554
|
+
te server-owned system root.");let r=D.resolve(e),n=new Map;function o(d){return En(`Lesson ${d.lesson.code} ("${d.lesson.
|
|
1537
1555
|
title}") cannot be taught by this version of Vibe64: ${d.problem} Update the course in Courses, or ask its authors for a\
|
|
1538
1556
|
fixed release.`,"VIBE64_TRAINING_LESSON_UNUSABLE",422,{params:{lessonCode:d.lesson.code,lessonTitle:d.lesson.title,problem:d.
|
|
1539
|
-
problem}})}async function i(d={}){let p=await s(d);return{...p,bundles:p.bundles.map(_=>({..._,lesson:
|
|
1540
|
-
topicId:d,commit:p,topicHash:_}={}){if(typeof d!="string"||typeof p!="string"||!je.test(d)||!
|
|
1557
|
+
problem}})}async function i(d={}){let p=await s(d);return{...p,bundles:p.bundles.map(_=>({..._,lesson:Ei(_.lesson)}))}}async function s({
|
|
1558
|
+
topicId:d,commit:p,topicHash:_}={}){if(typeof d!="string"||typeof p!="string"||!je.test(d)||!bi.test(p))throw new Error(
|
|
1541
1559
|
"Choose a valid topic ID and its exact 40-character lowercase Git commit.");if(typeof _!="string"||!nr.test(_))throw new Error(
|
|
1542
1560
|
"Provide the trusted 64-character topic hash from the course or saved attempt.");let b=JSON.stringify([d,p,_]),v=n.get(b);
|
|
1543
1561
|
return v||(v=a({topicId:d,commit:p,topicHash:_}).finally(()=>n.delete(b)),n.set(b,v)),structuredClone(await v)}async function a({
|
|
1544
|
-
topicId:d,commit:p,topicHash:_}){try{let b=D.join(r,"training"),v=D.join(b,"content"),
|
|
1545
|
-
r,b,v,
|
|
1546
|
-
topicHash:_}),
|
|
1562
|
+
topicId:d,commit:p,topicHash:_}){try{let b=D.join(r,"training"),v=D.join(b,"content"),y=D.join(v,d),E=D.join(y,p);for(let se of[
|
|
1563
|
+
r,b,v,y,E])await or(se,!0);let A=et(JSON.parse((await St(D.join(E,"pin.json"),4096)).toString("utf8")),{topicId:d,commit:p,
|
|
1564
|
+
topicHash:_}),T=JSON.parse((await St(D.join(E,"bundle.json"),32*1024*1024)).toString("utf8")),O=D.join(E,"files"),U=await Bg(
|
|
1547
1565
|
O),x=await He(O,{installed:!0}),k={schemaVersion:1,topic:x.topic,release:x.release,topicHash:x.topicHash,topicManifest:x.
|
|
1548
|
-
topicManifest,lessons:x.bundles.map(({lesson:se,hash:Ee,status:
|
|
1549
|
-
required:
|
|
1566
|
+
topicManifest,lessons:x.bundles.map(({lesson:se,hash:Ee,status:Hu,required:zu,manifest:Fu})=>({code:se.code,hash:Ee,status:Hu,
|
|
1567
|
+
required:zu,manifest:Fu}))};if(L(T)!==L(k))throw new Error("Installed bundle is incomplete, reordered, unsupported or ch\
|
|
1550
1568
|
anged from its source files.");if(x.topic.topicId!==A.topicId||x.release!==A.release||x.topicHash!==A.topicHash)throw new Error(
|
|
1551
1569
|
"Installed topic identity differs from its pin.");let F=Be([x.topicManifest,...x.bundles.map(se=>se.manifest)]);if(L(U)!==
|
|
1552
|
-
L(F.map(se=>se.path).sort()))throw new Error("Installed snapshot has missing or unrecorded files.");let
|
|
1553
|
-
O,"package.json"),1024*1024),pe=F.find(se=>se.path==="package.json");if(
|
|
1554
|
-
"Installed source changed during reading.");if(JSON.parse(
|
|
1570
|
+
L(F.map(se=>se.path).sort()))throw new Error("Installed snapshot has missing or unrecorded files.");let ee=await St(D.join(
|
|
1571
|
+
O,"package.json"),1024*1024),pe=F.find(se=>se.path==="package.json");if(ee.length!==pe.bytes||K(ee)!==pe.sha256)throw new Error(
|
|
1572
|
+
"Installed source changed during reading.");if(JSON.parse(ee.toString("utf8")).repository?.url!==`https://github.com/${A.
|
|
1555
1573
|
repository}.git`)throw new Error("Installed package repository URL differs from its canonical pin.");return{pin:A,...x}}catch(b){
|
|
1556
|
-
let v=["ENOENT","ENOTDIR"].includes(b.code),
|
|
1574
|
+
let v=["ENOENT","ENOTDIR"].includes(b.code),y=new Error(v?`Pinned teaching content ${d}@${p} is missing. Ask the owner t\
|
|
1557
1575
|
o install that exact revision.`:`Pinned teaching content ${d}@${p} is invalid: ${b.message} Ask the owner to reinstall t\
|
|
1558
|
-
he verified snapshot.`,{cause:b});throw
|
|
1559
|
-
async function c({pin:d,manifest:p},_,b){let v=D.join(r,"training","content",d.topicId,d.commit,"files"),
|
|
1560
|
-
b),E=D.relative(v,
|
|
1561
|
-
ecorded installed file.");let
|
|
1562
|
-
lesson changed while reading. Ask the owner to reinstall the verified snapshot.");return{path:E,bytes:
|
|
1563
|
-
topicId:d,commit:p,topicHash:_,lessonCode:b,lessonHash:v}={}){if(typeof d!="string"||!je.test(d)||typeof p!="string"||!
|
|
1576
|
+
he verified snapshot.`,{cause:b});throw y.code=v?"VIBE64_TRAINING_CONTENT_MISSING":"VIBE64_TRAINING_CONTENT_INVALID",y}}
|
|
1577
|
+
async function c({pin:d,manifest:p},_,b){let v=D.join(r,"training","content",d.topicId,d.commit,"files"),y=D.resolve(v,_,
|
|
1578
|
+
b),E=D.relative(v,y).split(D.sep).join("/"),A=p.files.find(O=>O.path===E);if(!A)throw new Error("Lesson requested an unr\
|
|
1579
|
+
ecorded installed file.");let T=await St(y,1024*1024);if(T.length!==A.bytes||K(T)!==A.sha256)throw new Error("Installed \
|
|
1580
|
+
lesson changed while reading. Ask the owner to reinstall the verified snapshot.");return{path:E,bytes:T}}async function l({
|
|
1581
|
+
topicId:d,commit:p,topicHash:_,lessonCode:b,lessonHash:v}={}){if(typeof d!="string"||!je.test(d)||typeof p!="string"||!bi.
|
|
1564
1582
|
test(p)||typeof _!="string"||!nr.test(_)||typeof b!="string"||!je.test(b)||typeof v!="string"||!nr.test(v))throw new Error(
|
|
1565
|
-
"Choose an exact pinned topic and lesson identity.");try{let
|
|
1566
|
-
|
|
1567
|
-
"utf8")),{topicId:d,commit:p,topicHash:_}),U=JSON.parse((await
|
|
1568
|
-
x=U.topicManifest;if(!x||
|
|
1569
|
-
st differs from the trusted identity.");let k=x.lessons.find(Ee=>Ee.code===b),F=x.topic.lessons.find(Ee=>Ee.code===b),
|
|
1570
|
-
lessons.find(Ee=>Ee.code===b);if(!k||!F||!
|
|
1571
|
-
differs from the trusted content hash.");if(!t(k.status))throw new Error(`Lesson ${b} is draft and cannot be taught.
|
|
1572
|
-
|
|
1573
|
-
se=
|
|
1574
|
-
|
|
1575
|
-
Ask the owner to restore the exact snapshot.`,{cause:
|
|
1576
|
-
|
|
1577
|
-
p.lesson)}}async function m({topicId:d,commit:p,topicHash:_,lessonCode:b,lessonHash:v}={}){if(typeof b!="
|
|
1578
|
-
"string"||!je.test(b)||!nr.test(v))throw new Error("Choose a declared lesson code and its exact 64-
|
|
1579
|
-
|
|
1580
|
-
`Lesson ${b} is not declared in this pinned topic.`);if(!t(E.status))throw new Error(`Lesson ${b} is
|
|
1581
|
-
taught. Choose a published lesson.`);if(E.hash!==v)throw new Error(`Lesson ${b} content hash changed.
|
|
1582
|
-
pinned revision or explicitly start a new attempt.`);if(E.problem)throw o(E);let A=Object.fromEntries(["
|
|
1583
|
-
|
|
1584
|
-
descriptorPath,declarations:A}}async function f(d={}){let p=await
|
|
1585
|
-
let O=await c(p,_,
|
|
1586
|
-
|
|
1587
|
-
O=[];for(let U of p.lesson.steps){let{body:x,beats:k}=
|
|
1588
|
-
{}})}return{...p,steps:O,...p.lesson.notes===void 0?{}:{notesText:(await b(p.lesson.notes)).text},
|
|
1589
|
-
schemaVersion!==1)throw new Error(`Lesson ${p.lesson.code} uses an unsupported format.`);let
|
|
1590
|
-
E=p.lesson.assessments.map(
|
|
1591
|
-
index})).sort((
|
|
1592
|
-
E[O+1]?.position??
|
|
1593
|
-
"string"||!je.test(d))throw new Error("Choose a declared step ID.");let{pin:_,lesson:b,hash:v}=await m(
|
|
1594
|
-
`Lesson ${b.code} has no steps.`);let
|
|
1595
|
-
is pinned lesson.`);if(
|
|
1596
|
-
code,lessonHash:v,stepId:d,answer:[...
|
|
1597
|
-
visualId:
|
|
1598
|
-
commit:p,topicHash:_,lessonCode:b,lessonHash:v}),A=E.visuals.find(k=>k.id===
|
|
1599
|
-
|
|
1600
|
-
O=await c(E,
|
|
1601
|
-
k));return{pin:E.pin,lessonCode:E.lesson.code,lessonHash:E.hash,...A,
|
|
1602
|
-
commit:p,topicHash:_,lessonCode:b,lessonHash:v,checkId:
|
|
1603
|
-
a declared check ID.");let E=await f({topicId:d,commit:p,topicHash:_,lessonCode:b,
|
|
1604
|
-
x=>x.id===
|
|
1605
|
-
O=await c(E,
|
|
1606
|
-
hash,check:A,file:O,assets:U}}async function S({topicId:d,commit:p,topicHash:_,
|
|
1607
|
-
admissionOnly:E=!1}={}){if(E===!0&&
|
|
1608
|
-
|
|
1609
|
-
new Error(`Lesson ${b} has no declared bundled exercise.`),{code:"
|
|
1610
|
-
D.posix.dirname(
|
|
1611
|
-
if(
|
|
1612
|
-
path.slice(k.length),cr=await c(
|
|
1613
|
-
readLesson:f,readAdmissionIdentity:
|
|
1614
|
-
Gg,
|
|
1615
|
-
|
|
1616
|
-
schemaVersion:{type:"integer",required:!0,enum:[1]},topicId:{...rr,maxLength:64},release:rr,
|
|
1617
|
-
maxLength:40},topicHash:{...rr,maxLength:64}});
|
|
1618
|
-
import
|
|
1619
|
-
throw new Error(`${t} must be a normalized absolute, non-root server-owned directory.`);return e}function
|
|
1620
|
-
relative(e,t);return!r||r!==".."&&!r.startsWith(`..${
|
|
1621
|
-
await
|
|
1583
|
+
"Choose an exact pinned topic and lesson identity.");try{let y=D.join(r,"training"),E=D.join(y,"content"),A=D.join(E,d),
|
|
1584
|
+
T=D.join(A,p);for(let Ee of[r,y,E,A,T])await or(Ee,!0);let O=et(JSON.parse((await St(D.join(T,"pin.json"),4096)).toString(
|
|
1585
|
+
"utf8")),{topicId:d,commit:p,topicHash:_}),U=JSON.parse((await St(D.join(T,"bundle.json"),32*1024*1024)).toString("utf8")),
|
|
1586
|
+
x=U.topicManifest;if(!x||K(L(x))!==_||x.topic.topicId!==d||x.release!==O.release)throw new Error("Installed topic manife\
|
|
1587
|
+
st differs from the trusted identity.");let k=x.lessons.find(Ee=>Ee.code===b),F=x.topic.lessons.find(Ee=>Ee.code===b),ee=U.
|
|
1588
|
+
lessons.find(Ee=>Ee.code===b);if(!k||!F||!ee||k.hash!==v||K(L(ee.manifest))!==v)throw new Error("Installed lesson manife\
|
|
1589
|
+
st differs from the trusted content hash.");if(!t(k.status))throw new Error(`Lesson ${b} is draft and cannot be taught. \
|
|
1590
|
+
Choose a published lesson.`);let pe={pin:O,manifest:ee.manifest,hash:v,descriptorPath:F.descriptor},cr=await c(pe,".",F.
|
|
1591
|
+
descriptor),se=xr(JSON.parse(cr.bytes.toString("utf8")),b);if(se.code!==b)throw new Error("Installed lesson descriptor i\
|
|
1592
|
+
dentity changed.");return{...pe,lesson:Ei(se)}}catch(y){let E=new Error(`Pinned teaching identity ${d}@${p} is invalid: ${y.
|
|
1593
|
+
message} Ask the owner to restore the exact snapshot.`,{cause:y});throw E.code=["ENOENT","ENOTDIR"].includes(y.code)?"VI\
|
|
1594
|
+
BE64_TRAINING_CONTENT_MISSING":"VIBE64_TRAINING_CONTENT_INVALID",E}}async function u(d={}){let p=await m(d);return{...p,
|
|
1595
|
+
lesson:Ei(p.lesson)}}async function m({topicId:d,commit:p,topicHash:_,lessonCode:b,lessonHash:v}={}){if(typeof b!="strin\
|
|
1596
|
+
g"||typeof v!="string"||!je.test(b)||!nr.test(v))throw new Error("Choose a declared lesson code and its exact 64-charact\
|
|
1597
|
+
er lowercase content hash.");let y=await s({topicId:d,commit:p,topicHash:_}),E=y.bundles.find(T=>T.lesson.code===b);if(!E)
|
|
1598
|
+
throw new Error(`Lesson ${b} is not declared in this pinned topic.`);if(!t(E.status))throw new Error(`Lesson ${b} is dra\
|
|
1599
|
+
ft and cannot be taught. Choose a published lesson.`);if(E.hash!==v)throw new Error(`Lesson ${b} content hash changed. R\
|
|
1600
|
+
esume its exact pinned revision or explicitly start a new attempt.`);if(E.problem)throw o(E);let A=Object.fromEntries(["\
|
|
1601
|
+
places","activities","facts"].map(T=>[T,[...y.topic[T]||[]]]));return{pin:y.pin,lesson:E.lesson,manifest:E.manifest,hash:E.
|
|
1602
|
+
hash,descriptorPath:E.descriptorPath,declarations:A}}async function f(d={}){let p=await u(d),_=D.dirname(p.descriptorPath);
|
|
1603
|
+
async function b(T){let O=await c(p,_,T);return{path:O.path,text:O.bytes.toString("utf8")}}let v=[];for(let T of p.lesson.
|
|
1604
|
+
visuals){let O=await b(T.descriptor);v.push({id:T.id,descriptorPath:O.path,visual:JSON.parse(O.text)})}if(me(p.lesson)){
|
|
1605
|
+
let T=Lr(p.declarations),O=[];for(let U of p.lesson.steps){let{body:x,beats:k}=Dr((await b(U.body)).text,T);O.push({...U,
|
|
1606
|
+
bodyText:x,...k?{beats:k}:{}})}return{...p,steps:O,...p.lesson.notes===void 0?{}:{notesText:(await b(p.lesson.notes)).text},
|
|
1607
|
+
visuals:v}}if(p.lesson.schemaVersion!==1)throw new Error(`Lesson ${p.lesson.code} uses an unsupported format.`);let y=await b(
|
|
1608
|
+
p.lesson.document),E=p.lesson.assessments.map(T=>({id:T.id,reference:T.rubric,position:new RegExp(`^<a id="${T.id}"></a>\
|
|
1609
|
+
$`,"mu").exec(y.text).index})).sort((T,O)=>T.position-O.position),A=E.map((T,O)=>({id:T.id,reference:T.reference,text:y.
|
|
1610
|
+
text.slice(T.position,E[O+1]?.position??y.text.length)}));return{...p,document:y,rubrics:A,visuals:v}}async function h({
|
|
1611
|
+
stepId:d,...p}={}){if(typeof d!="string"||!je.test(d))throw new Error("Choose a declared step ID.");let{pin:_,lesson:b,hash:v}=await m(
|
|
1612
|
+
p);if(!me(b))throw new Error(`Lesson ${b.code} has no steps.`);let y=b.steps.find(E=>E.id===d);if(!y)throw new Error(`St\
|
|
1613
|
+
ep ${d} is not declared in this pinned lesson.`);if(y.check.kind!=="choice")throw new Error(`Step ${d} is not a choice s\
|
|
1614
|
+
tep.`);return{pin:_,lessonCode:b.code,lessonHash:v,stepId:d,answer:[...y.check.answer]}}async function w({topicId:d,commit:p,
|
|
1615
|
+
topicHash:_,lessonCode:b,lessonHash:v,visualId:y}={}){if(typeof y!="string"||!je.test(y))throw new Error("Choose a decla\
|
|
1616
|
+
red visual ID.");let E=await f({topicId:d,commit:p,topicHash:_,lessonCode:b,lessonHash:v}),A=E.visuals.find(k=>k.id===y);
|
|
1617
|
+
if(!A)throw vt(`Visual ${y} is not declared in this pinned lesson.`,"VIBE64_TRAINING_VISUAL_UNDECLARED",{statusCode:400,
|
|
1618
|
+
params:{visualId:y}});let T=D.dirname(A.descriptorPath),O=await c(E,T,A.visual.svg),U=await c(E,T,A.visual.controller),x=[];
|
|
1619
|
+
for(let k of A.visual.assets||[])x.push(await c(E,T,k));return{pin:E.pin,lessonCode:E.lesson.code,lessonHash:E.hash,...A,
|
|
1620
|
+
svg:O,controller:U,assets:x}}async function I({topicId:d,commit:p,topicHash:_,lessonCode:b,lessonHash:v,checkId:y}={}){if(typeof y!=
|
|
1621
|
+
"string"||!je.test(y))throw new Error("Choose a declared check ID.");let E=await f({topicId:d,commit:p,topicHash:_,lessonCode:b,
|
|
1622
|
+
lessonHash:v}),A=E.lesson.checks?.find(x=>x.id===y);if(!A)throw new Error(`Check ${y} is not declared in this pinned les\
|
|
1623
|
+
son.`);let T=D.dirname(E.descriptorPath),O=await c(E,T,A.file),U=[];for(let x of A.assets||[])U.push(await c(E,T,x));return{
|
|
1624
|
+
pin:E.pin,lessonCode:E.lesson.code,lessonHash:E.hash,check:A,file:O,assets:U}}async function S({topicId:d,commit:p,topicHash:_,
|
|
1625
|
+
lessonCode:b,lessonHash:v,metadataOnly:y=!1,admissionOnly:E=!1}={}){if(E===!0&&y!==!0)throw new TypeError("Admission rea\
|
|
1626
|
+
ds cannot supply exercise content.");let T=await(E===!0?l:y===!0?u:f)({topicId:d,commit:p,topicHash:_,lessonCode:b,lessonHash:v}),
|
|
1627
|
+
O=T.lesson.exercise;if(!O)throw Object.assign(new Error(`Lesson ${b} has no declared bundled exercise.`),{code:"VIBE64_T\
|
|
1628
|
+
RAINING_EXERCISE_MISSING"});let U=D.posix.join(D.posix.dirname(T.descriptorPath),O.source),x={pin:T.pin,lessonCode:T.lesson.
|
|
1629
|
+
code,lessonHash:T.hash,exercise:O,sourcePath:U};if(y===!0)return x;let k=U==="."?"":`${U}/`,F=[];for(let ee of T.manifest.
|
|
1630
|
+
files){if(!ee.path.startsWith(k))continue;let pe=ee.path.slice(k.length),cr=await c(T,U,pe);F.push({path:pe,bytes:cr.bytes})}
|
|
1631
|
+
return{...x,files:F}}return Object.freeze({readTopic:i,readLesson:f,readAdmissionIdentity:l,readVisual:w,readCheck:I,readExercise:S,
|
|
1632
|
+
readChoiceAnswer:h})}var je,bi,nr,Vg,rr,Gg,Hg,vi=g(()=>{Cr();dt();lt();bo();Mr();Ou();ut();bn();je=/^[a-zA-Z][a-zA-Z0-9-]{0,63}$/u,
|
|
1633
|
+
bi=/^[a-f0-9]{40}$/u,nr=/^[a-f0-9]{64}$/u,Vg=/^[a-zA-Z0-9_.-]+\/learn-[a-zA-Z0-9_.-]+$/u,rr={type:"string",required:!0,noTrim:!0,
|
|
1634
|
+
minLength:1,maxLength:256},Gg=$({schemaVersion:{type:"integer",required:!0,enum:[1]},topicId:{...rr,maxLength:64},release:rr,
|
|
1635
|
+
repository:rr,commit:{...rr,maxLength:40},topicHash:{...rr,maxLength:64}});Hg=e=>e==="published"});import{randomUUID as Fg}from"node:crypto";import{lstat as qg,mkdir as Ii,realpath as Wg,rename as Yg,rm as Jg,writeFile as Kg}from"node:fs/promises";
|
|
1636
|
+
import Z from"node:path";function Pu(e,t){if(typeof e!="string"||!Z.isAbsolute(e)||Z.resolve(e)!==e||e===Z.parse(e).root)
|
|
1637
|
+
throw new Error(`${t} must be a normalized absolute, non-root server-owned directory.`);return e}function Ru(e,t){let r=Z.
|
|
1638
|
+
relative(e,t);return!r||r!==".."&&!r.startsWith(`..${Z.sep}`)&&!Z.isAbsolute(r)}async function _e(e,t,r=!0){let n;try{n=
|
|
1639
|
+
await qg(e)}catch(o){if(r&&o.code==="ENOENT")return null;throw o}if(n.isSymbolicLink()||await Wg(e)!==e)throw new Error(
|
|
1622
1640
|
"Training installation cannot use symlink or directory aliases.");if(t?!n.isDirectory():!n.isFile())throw new Error(`Tra\
|
|
1623
1641
|
ining installation needs a regular ${t?"directory":"file"}: ${e}.`);if(!t&&(n.nlink!==1||n.size!==0))throw new Error("Tr\
|
|
1624
|
-
aining installation lock must be an unaliased empty regular file; inspect it before retrying.");return n}async function
|
|
1625
|
-
let r=
|
|
1626
|
-
code!=="EEXIST")throw t}await _e(e,!0,!1)}function
|
|
1627
|
-
pshot conflicts with the approved owner pin. Keep existing content and check the exact source revision.")}async function
|
|
1628
|
-
let{topicId:r,release:n,repository:o,commit:i,topicHash:s}=await er(e);
|
|
1629
|
-
commit:i,topicHash:s},t)}function
|
|
1630
|
-
sourceRoot:o,pin:i}={}){let s={...et(i)};
|
|
1631
|
-
throw new Error("Trusted topic source must be separate from the training installation namespace.");let c=
|
|
1632
|
-
nt"),
|
|
1633
|
-
await
|
|
1642
|
+
aining installation lock must be an unaliased empty regular file; inspect it before retrying.");return n}async function vn(e,t=!1){
|
|
1643
|
+
let r=Z.dirname(e);return r!==e&&await vn(r,t),_e(e,!0,t)}async function Xg(e){try{await Ii(e,{mode:448})}catch(t){if(t.
|
|
1644
|
+
code!=="EEXIST")throw t}await _e(e,!0,!1)}function Sn(e,t){if(L(e)!==L(t))throw new Error("Topic source or installed sna\
|
|
1645
|
+
pshot conflicts with the approved owner pin. Keep existing content and check the exact source revision.")}async function Si(e,t){
|
|
1646
|
+
let{topicId:r,release:n,repository:o,commit:i,topicHash:s}=await er(e);Sn({schemaVersion:1,topicId:r,release:n,repository:o,
|
|
1647
|
+
commit:i,topicHash:s},t)}function Nu({systemRoot:e}){let t=Pu(e,"Training system root"),r=ir({systemRoot:t});async function n({
|
|
1648
|
+
sourceRoot:o,pin:i}={}){let s={...et(i)};Pu(o,"Trusted topic source root");let a=Z.join(t,"training");if(Ru(o,a)||Ru(a,o))
|
|
1649
|
+
throw new Error("Trusted topic source must be separate from the training installation namespace.");let c=Z.join(a,"conte\
|
|
1650
|
+
nt"),l=Z.join(c,s.topicId),u=Z.join(l,s.commit),m=Z.join(a,".install-locks"),f=Z.join(m,`${s.topicId}-${s.commit}.lock`);
|
|
1651
|
+
await vn(t);let h=await vn(o,!0);for(let d of[a,c,l,m])await _e(d,!0);if(await _e(f,!1),await _e(u,!0))Sn((await r.readTopic(
|
|
1634
1652
|
s)).pin,s);else{if(!h)throw new Error("Trusted topic source is missing. Prepare the approved local repository before ins\
|
|
1635
|
-
talling its pin.");await
|
|
1653
|
+
talling its pin.");await Si(o,s)}for(let d of[a,c,l,m])await Xg(d);let I=await ft(f);if(!I)throw En("This topic revision\
|
|
1636
1654
|
is being installed. Retry after the current owner operation finishes.","VIBE64_TRAINING_INSTALL_BUSY");let S;try{await _e(
|
|
1637
|
-
f,!1,!1);for(let v of[t,a,c,
|
|
1638
|
-
...v}}await
|
|
1639
|
-
"content",s.topicId);await
|
|
1640
|
-
await
|
|
1641
|
-
`,{flag:"wx",mode:384}),await ir({systemRoot:S}).readTopic(s),await _e(
|
|
1642
|
-
ination appeared during installation. Keep it unchanged and retry the verified pin.");await
|
|
1643
|
-
s);return
|
|
1644
|
-
freeze({installTopic:n})}var
|
|
1645
|
-
import
|
|
1646
|
-
mode:n});let s=
|
|
1647
|
-
o!==void 0&&await
|
|
1655
|
+
f,!1,!1);for(let v of[t,a,c,l,m])await _e(v,!0,!1);if(await _e(u,!0)){let v=await r.readTopic(s);return Sn(v.pin,s),{installed:!1,
|
|
1656
|
+
...v}}await vn(o),await Si(o,s);let d=Z.join(a,`.install-${Fg()}`);await Ii(d,{mode:448}),S=d;let p=Z.join(S,"training",
|
|
1657
|
+
"content",s.topicId);await Ii(p,{recursive:!0,mode:448});let _=Z.join(p,s.commit);if(await Ti(["bundle",o,_],{write(){}}),
|
|
1658
|
+
await Si(o,s),await Kg(Z.join(_,"pin.json"),`${L(s)}
|
|
1659
|
+
`,{flag:"wx",mode:384}),await ir({systemRoot:S}).readTopic(s),await _e(l,!0,!1),await _e(u,!0))throw new Error("The dest\
|
|
1660
|
+
ination appeared during installation. Keep it unchanged and retry the verified pin.");await Yg(_,u);let b=await r.readTopic(
|
|
1661
|
+
s);return Sn(b.pin,s),{installed:!0,...b}}finally{try{S&&await Jg(S,{recursive:!0,force:!0})}finally{await I()}}}return Object.
|
|
1662
|
+
freeze({installTopic:n})}var Cu=g(()=>{Wr();_n();Ai();dt();bn();vi()});import{randomUUID as Qg}from"node:crypto";import{chmod as Zg,mkdir as ew,rename as tw,rm as rw,writeFile as nw}from"node:fs/promises";
|
|
1663
|
+
import Oi from"node:path";async function ow(e,t,r={}){let{directoryMode:n,fileMode:o}=r,i=Oi.dirname(e);await ew(i,{recursive:!0,
|
|
1664
|
+
mode:n});let s=Oi.join(i,`.${Oi.basename(e)}.${process.pid}.${Qg()}.tmp`);try{await nw(s,t,{encoding:"utf8",flag:"wx",mode:o}),
|
|
1665
|
+
o!==void 0&&await Zg(s,o),await tw(s,e)}finally{await rw(s,{force:!0})}}async function ku(e,t,r={}){await ow(e,`${JSON.stringify(
|
|
1648
1666
|
t,null,2)}
|
|
1649
|
-
`,r)}var
|
|
1667
|
+
`,r)}var xu=g(()=>{});import{lstat as iw,mkdir as sw,readFile as aw,realpath as cw}from"node:fs/promises";import Le from"node:path";function Ri(e){
|
|
1650
1668
|
if(!Number.isSafeInteger(e)||e<0)throw new Error("Supply the expected revision from a fresh installed catalogue read.")}
|
|
1651
|
-
function
|
|
1669
|
+
function Ni({systemRoot:e}){if(typeof e!="string"||!Le.isAbsolute(e)||Le.resolve(e)!==e||e===Le.parse(e).root)throw new Error(
|
|
1652
1670
|
"Installed catalogue needs a canonical absolute, non-root server-owned system root.");let t=Le.join(e,"training"),r=Le.join(
|
|
1653
1671
|
t,"catalogue.json"),n=Le.join(t,"catalogue.lock"),o=ir({systemRoot:e});async function i(){let S=[t];for(let _=e;S.unshift(
|
|
1654
|
-
_),_!==Le.dirname(_);_=Le.dirname(_));let d=!1,p=null;for(let _ of[...S,r,n]){let b;try{b=await
|
|
1655
|
-
"ENOENT")continue;throw
|
|
1672
|
+
_),_!==Le.dirname(_);_=Le.dirname(_));let d=!1,p=null;for(let _ of[...S,r,n]){let b;try{b=await iw(_)}catch(y){if(y.code===
|
|
1673
|
+
"ENOENT")continue;throw y}let v=_!==r&&_!==n;if(b.isSymbolicLink()||await cw(_)!==_||(v?!b.isDirectory():!b.isFile()||b.
|
|
1656
1674
|
nlink!==1))throw new Error("Installed catalogue paths must be canonical directories and unaliased regular files.");if(_===
|
|
1657
1675
|
e&&(d=!0),_===r&&(p=b),_===n&&b.size!==0)throw new Error("Installed catalogue lock contains unexplained data. Inspect it\
|
|
1658
1676
|
; do not unlink it.")}return{rootExists:d,catalogueStat:p}}async function s(S){let d=S.lock.topics;if(!Array.isArray(d)||
|
|
1659
1677
|
d.length!==S.course.topics.length||d.length>32)throw new Error("The approved course lock must contain every selected who\
|
|
1660
|
-
le topic in order.");let p=[],_=[],b=[];for(let
|
|
1661
|
-
repository:
|
|
1678
|
+
le topic in order.");let p=[],_=[],b=[];for(let y of d){let E=et({schemaVersion:1,topicId:y?.topicId,release:y?.release,
|
|
1679
|
+
repository:y?.repository,commit:y?.commit,topicHash:y?.manifestHash}),A=await o.readTopic(E);if(L(A.pin)!==L(E))throw new Error(
|
|
1662
1680
|
"Installed topic identity differs from the approved course lock.");b.push({topicId:E.topicId,release:E.release,title:A.topicManifest.
|
|
1663
|
-
topic.title});for(let
|
|
1681
|
+
topic.title});for(let T of A.bundles)_.push({topicId:E.topicId,topicRelease:E.release,code:T.lesson.code,hash:T.hash,title:T.
|
|
1664
1682
|
lesson.title});p.push({topicId:A.pin.topicId,release:A.release,repository:A.pin.repository,commit:A.pin.commit,topicManifest:A.
|
|
1665
1683
|
topicManifest,topicHash:A.topicHash})}let v=tr(S.course,p);if(L(S.lock)!==L(v))throw new Error("The approved course lock\
|
|
1666
1684
|
differs from the complete installed topic inventory. Regenerate and review its exact release.");return{lessonTitles:_,topicTitles:b}}
|
|
1667
1685
|
async function a({includeLessonTitles:S=!1}={}){if(typeof S!="boolean")throw new TypeError("Lesson title projection requ\
|
|
1668
1686
|
ires an explicit Boolean read option.");try{let{catalogueStat:d}=await i();if(!d)return{schemaVersion:1,revision:0,courses:[]};
|
|
1669
|
-
if(d.size>
|
|
1670
|
-
"Installed catalogue exceeds its 1 MiB limit.");let _=ce(
|
|
1687
|
+
if(d.size>Pi)throw new Error("Installed catalogue exceeds its 1 MiB limit.");let p=await aw(r);if(p.length>Pi)throw new Error(
|
|
1688
|
+
"Installed catalogue exceeds its 1 MiB limit.");let _=ce(lw,JSON.parse(p.toString("utf8")),"Installed catalogue");if(_.courses.
|
|
1671
1689
|
length&&_.revision<1)throw new Error("Installed catalogue revision conflicts with its course inventory.");let b=new Set;
|
|
1672
|
-
for(let v of _.courses){let
|
|
1673
|
-
e contains duplicate course releases.");b.add(
|
|
1674
|
-
topicTitles:A})}return _}catch(d){throw
|
|
1690
|
+
for(let v of _.courses){let y=`${v.course.courseId}@${v.course.release}`;if(b.has(y))throw new Error("Installed catalogu\
|
|
1691
|
+
e contains duplicate course releases.");b.add(y);let{lessonTitles:E,topicTitles:A}=await s(v);S&&Object.assign(v,{lessonTitles:E,
|
|
1692
|
+
topicTitles:A})}return _}catch(d){throw _i(`Installed catalogue is invalid: ${d.message} Keep existing state and ask the\
|
|
1675
1693
|
owner to restore the exact approved catalogue or pinned content. No automatic repair was performed.`,"VIBE64_TRAINING_C\
|
|
1676
1694
|
ATALOGUE_INVALID",d)}}async function c(){let{rootExists:S}=await i();if(!S)throw new Error("Prepare the server-owned sys\
|
|
1677
|
-
tem root before changing the catalogue.");try{await
|
|
1695
|
+
tem root before changing the catalogue.");try{await sw(t,{mode:448})}catch(p){if(p.code!=="EEXIST")throw p}await i();let d=await ft(
|
|
1678
1696
|
n);if(!d)throw ye("Installed catalogue is being updated. Retry after the current owner operation finishes.","VIBE64_TRAI\
|
|
1679
|
-
NING_CATALOGUE_BUSY",409);return d}function
|
|
1680
|
-
rent revision before deliberately retrying this enablement change.","VIBE64_TRAINING_CATALOGUE_REVISION_CONFLICT",409)}async function
|
|
1697
|
+
NING_CATALOGUE_BUSY",409);return d}function l(S,d){if(S.revision!==d)throw ye("Installed catalogue changed. Read its cur\
|
|
1698
|
+
rent revision before deliberately retrying this enablement change.","VIBE64_TRAINING_CATALOGUE_REVISION_CONFLICT",409)}async function u(S,d){
|
|
1681
1699
|
if(S.revision===Number.MAX_SAFE_INTEGER)throw new Error("Installed catalogue reached its revision limit. No change was w\
|
|
1682
1700
|
ritten.");let p={...S,revision:S.revision+1};if(Buffer.byteLength(`${JSON.stringify(p,null,2)}
|
|
1683
|
-
`)>
|
|
1684
|
-
fileMode:384})}catch(_){throw
|
|
1701
|
+
`)>Pi)throw new Error("Installed catalogue exceeds its 1 MiB limit. No change was written.");try{await ku(r,p,{directoryMode:448,
|
|
1702
|
+
fileMode:384})}catch(_){throw _i("Catalogue save was not confirmed; atomic rename may already have succeeded. Read the c\
|
|
1685
1703
|
urrent catalogue before deliberately retrying. Do not assume the course changed or remained unchanged.","VIBE64_TRAINING\
|
|
1686
1704
|
_CATALOGUE_SAVE_UNCONFIRMED",_)}return{revision:p.revision,entry:d,changed:!0}}async function m({course:S,lock:d,expectedRevision:p}={}){
|
|
1687
|
-
|
|
1688
|
-
try{let v=await a();
|
|
1689
|
-
_.course.release);if(
|
|
1705
|
+
Ri(p);let _=structuredClone(ce($u,{course:S,lock:d,enabled:!0},"Approved installed course"));await a(),await s(_);let b=await c();
|
|
1706
|
+
try{let v=await a();l(v,p),await s(_);let y=v.courses.find(E=>E.course.courseId===_.course.courseId&&E.course.release===
|
|
1707
|
+
_.course.release);if(y){if(L(y.course)!==L(_.course)||L(y.lock)!==L(_.lock))throw ye("This installed course release is i\
|
|
1690
1708
|
mmutable. Resume its approved pin or publish and approve a different course release.","VIBE64_TRAINING_COURSE_RELEASE_CO\
|
|
1691
|
-
NFLICT",409);return
|
|
1709
|
+
NFLICT",409);return y.enabled?{revision:v.revision,entry:y,changed:!1}:(y.enabled=!0,await u(v,y))}if(v.courses.length>=
|
|
1692
1710
|
sr)throw new Error("Installed catalogue reached its 16 course-release limit. Remove a release with vibe64 training remov\
|
|
1693
|
-
e-course to free a place; no release was removed.");return v.courses.push(_),await
|
|
1694
|
-
courseId:S,release:d,expectedRevision:p},_){if(
|
|
1711
|
+
e-course to free a place; no release was removed.");return v.courses.push(_),await u(v,_)}finally{await b()}}async function f({
|
|
1712
|
+
courseId:S,release:d,expectedRevision:p},_){if(Ri(p),typeof S!="string"||!/^[a-z][a-z0-9-]{0,63}$/u.test(S)||typeof d!="\
|
|
1695
1713
|
string"||!/^\d+\.\d+\.\d+$/u.test(d))throw new Error(`${_?"Remove":"Disable"} an exact installed course ID and three-par\
|
|
1696
|
-
t release.`);if(!(await a()).courses.some(
|
|
1714
|
+
t release.`);if(!(await a()).courses.some(y=>y.course.courseId===S&&y.course.release===d))throw ye("This course release \
|
|
1697
1715
|
is not installed in the catalogue. Read the current catalogue before retrying.","VIBE64_TRAINING_COURSE_MISSING",404);let v=await c();
|
|
1698
|
-
try{let
|
|
1716
|
+
try{let y=await a();l(y,p);let E=y.courses.find(A=>A.course.courseId===S&&A.course.release===d);if(!E)throw ye("This cou\
|
|
1699
1717
|
rse release is no longer in the catalogue. Read the current catalogue before retrying.","VIBE64_TRAINING_COURSE_REMOVED",
|
|
1700
|
-
404);return _?(
|
|
1701
|
-
entry:E,changed:!1}}finally{await v()}}let h=S=>f(S,!1),
|
|
1702
|
-
|
|
1718
|
+
404);return _?(y.courses=y.courses.filter(A=>A!==E),await u(y,E)):E.enabled?(E.enabled=!1,await u(y,E)):{revision:y.revision,
|
|
1719
|
+
entry:E,changed:!1}}finally{await v()}}let h=S=>f(S,!1),w=S=>f(S,!0);async function I({title:S,topics:d,expectedRevision:p}){
|
|
1720
|
+
Ri(p);let _=typeof S=="string"?S.trim():"";if(!_||_.length>120)throw ye("Name the course with 1 to 120 characters.","VIB\
|
|
1703
1721
|
E64_TRAINING_COURSE_NAME_INVALID",400);if(!Array.isArray(d)||!d.length||d.length>32||new Set(d.map(O=>`${O?.topicId}@${O?.
|
|
1704
1722
|
release}`)).size!==d.length||new Set(d.map(O=>O?.topicId)).size!==d.length)throw ye("Choose 1 to 32 different whole topi\
|
|
1705
1723
|
cs for the course.","VIBE64_TRAINING_COURSE_TOPICS_INVALID",400);let b=await a(),v=b.courses.filter(O=>O.enabled&&O.course.
|
|
1706
|
-
status==="released").flatMap(O=>O.lock.topics),
|
|
1724
|
+
status==="released").flatMap(O=>O.lock.topics),y=[];for(let O of d){let U=v.find(k=>k.topicId===O.topicId&&k.release===O.
|
|
1707
1725
|
release);if(!U)throw ye(`Topic ${O.topicId}@${O.release} is not part of an enabled released course. Refresh courses and \
|
|
1708
1726
|
choose an installed topic.`,"VIBE64_TRAINING_COURSE_TOPIC_UNAVAILABLE",404);let x=await o.readTopic(et({schemaVersion:1,
|
|
1709
|
-
topicId:U.topicId,release:U.release,repository:U.repository,commit:U.commit,topicHash:U.manifestHash}));
|
|
1727
|
+
topicId:U.topicId,release:U.release,repository:U.repository,commit:U.commit,topicHash:U.manifestHash}));y.push({topicId:x.
|
|
1710
1728
|
pin.topicId,release:x.release,repository:x.pin.repository,commit:x.pin.commit,topicManifest:x.topicManifest,topicHash:x.
|
|
1711
1729
|
topicHash})}let A={schemaVersion:1,courseId:`custom-${_.toLowerCase().replace(/[^a-z0-9]+/gu,"-").replace(/^-+|-+$/gu,"").
|
|
1712
|
-
slice(0,48).replace(/-+$/u,"")||
|
|
1713
|
-
topicId,release:O.release}))},
|
|
1714
|
-
ourse with this name already exists. Choose another name.","VIBE64_TRAINING_COURSE_EXISTS",409);if(!
|
|
1715
|
-
sr)throw
|
|
1716
|
-
_LIMIT",{statusCode:409,params:{limit:sr}});return m({course:A,lock:tr(A,
|
|
1717
|
-
enableCourse:m,disableCourse:h,removeCourse:
|
|
1718
|
-
|
|
1719
|
-
type:"boolean",required:!0}}),
|
|
1720
|
-
min:0,max:Number.MAX_SAFE_INTEGER},courses:H(
|
|
1721
|
-
import W from"node:path";import{randomUUID as
|
|
1722
|
-
"install-topic"){let[,c,
|
|
1723
|
-
pic-directory> <system-root>");let
|
|
1724
|
-
schemaVersion:1,topicId:m,release:f,repository:h,commit:
|
|
1725
|
-
{sourceRoot:
|
|
1726
|
-
urses"){if(e.length!==2||!e[1])throw new Error("Usage: vibe64 training installed-courses <system-root>");let c=await
|
|
1730
|
+
slice(0,48).replace(/-+$/u,"")||K(_).slice(0,12)}`,title:_,release:"1.0.0",status:"released",topics:d.map(O=>({topicId:O.
|
|
1731
|
+
topicId,release:O.release}))},T=b.courses.find(O=>O.course.courseId===A.courseId);if(T&&L(T.course)!==L(A))throw ye("A c\
|
|
1732
|
+
ourse with this name already exists. Choose another name.","VIBE64_TRAINING_COURSE_EXISTS",409);if(!T&&b.courses.length>=
|
|
1733
|
+
sr)throw vt(`This installation already has ${sr} course releases. No course was created.`,"VIBE64_TRAINING_COURSE_CREATE\
|
|
1734
|
+
_LIMIT",{statusCode:409,params:{limit:sr}});return m({course:A,lock:tr(A,y),expectedRevision:p})}return Object.freeze({readCatalogue:a,
|
|
1735
|
+
enableCourse:m,disableCourse:h,removeCourse:w,createCourse:I})}var sr,Pi,$u,lw,ju=g(()=>{Cr();Wr();xu();_n();dt();lt();vi();
|
|
1736
|
+
bn();ut();sr=16,Pi=1024*1024,$u=$({course:{type:"object",required:!0,schema:jr},lock:{type:"object",required:!0},enabled:{
|
|
1737
|
+
type:"boolean",required:!0}}),lw=$({schemaVersion:{type:"integer",required:!0,enum:[1]},revision:{type:"integer",required:!0,
|
|
1738
|
+
min:0,max:Number.MAX_SAFE_INTEGER},courses:H($u,sr)})});var Du={};xi(Du,{runTrainingCli:()=>Ti});import{mkdir as Lu,readFile as In,realpath as It,rename as uw,rm as Mu,writeFile as Ci}from"node:fs/promises";
|
|
1739
|
+
import W from"node:path";import{randomUUID as dw}from"node:crypto";async function Ti(e,{write:t=r=>console.log(r)}={}){if(e[0]===
|
|
1740
|
+
"install-topic"){let[,c,l]=e;if(e.length!==3||!c||!l)throw new Error("Usage: vibe64 training install-topic <committed-to\
|
|
1741
|
+
pic-directory> <system-root>");let u=await It(c),{topicId:m,release:f,repository:h,commit:w,topicHash:I}=await er(u),S={
|
|
1742
|
+
schemaVersion:1,topicId:m,release:f,repository:h,commit:w,topicHash:I},d=await Nu({systemRoot:W.resolve(l)}).installTopic(
|
|
1743
|
+
{sourceRoot:u,pin:S});return t(JSON.stringify({ok:!0,installed:d.installed,pin:d.pin},null,2)),0}if(e[0]==="installed-co\
|
|
1744
|
+
urses"){if(e.length!==2||!e[1])throw new Error("Usage: vibe64 training installed-courses <system-root>");let c=await Ni(
|
|
1727
1745
|
{systemRoot:W.resolve(e[1])}).readCatalogue();return t(JSON.stringify({ok:!0,...c},null,2)),0}if(["enable-course","disab\
|
|
1728
|
-
le-course","remove-course"].includes(e[0])){let[c,u,
|
|
1746
|
+
le-course","remove-course"].includes(e[0])){let[c,l,u,m,f]=e;if(e.length!==5||!l||!u||!m||!/^(0|[1-9][0-9]*)$/u.test(f||
|
|
1729
1747
|
"")||!Number.isSafeInteger(Number(f)))throw new Error(c==="enable-course"?"Usage: vibe64 training enable-course <course.\
|
|
1730
1748
|
json> <course.lock.json> <system-root> <expected-revision>":`Usage: vibe64 training ${c} <courseId> <release> <system-ro\
|
|
1731
|
-
ot> <expected-revision>`);let h=
|
|
1732
|
-
parse(await
|
|
1733
|
-
urse":"disableCourse"]({courseId:
|
|
1734
|
-
"publish-manifest"){let[,c,...
|
|
1735
|
-
n> <committed-topic-directory...>");let
|
|
1736
|
-
|
|
1737
|
-
let f=JSON.parse(await
|
|
1749
|
+
ot> <expected-revision>`);let h=Ni({systemRoot:W.resolve(m)}),w=Number(f),I=c==="enable-course"?await h.enableCourse({course:JSON.
|
|
1750
|
+
parse(await In(l,"utf8")),lock:JSON.parse(await In(u,"utf8")),expectedRevision:w}):await h[c==="remove-course"?"removeCo\
|
|
1751
|
+
urse":"disableCourse"]({courseId:l,release:u,expectedRevision:w});return t(JSON.stringify({ok:!0,...I},null,2)),0}if(e[0]===
|
|
1752
|
+
"publish-manifest"){let[,c,...l]=e;if(!c||!l.length)throw new Error("Usage: vibe64 training publish-manifest <course.jso\
|
|
1753
|
+
n> <committed-topic-directory...>");let u=await It(c),m=W.join(await It(W.dirname(W.resolve(c))),"course.lock.json");if(m===
|
|
1754
|
+
u||W.basename(c)==="course.lock.json")throw new Error("Course lock output must not replace its input course descriptor.");
|
|
1755
|
+
let f=JSON.parse(await In(u,"utf8")),h=[];for(let S of l){let d=await It(S),p=W.relative(d,m);if(!p||!p.startsWith(`..${W.
|
|
1738
1756
|
sep}`)&&p!==".."&&!W.isAbsolute(p))throw new Error("Course lock output must be outside every pinned source topic.");await He(
|
|
1739
|
-
d,{authoring:!0}),h.push(await er(d))}let
|
|
1740
|
-
`,{flag:"wx"}),await
|
|
1741
|
-
status,lockPath:m,topics:
|
|
1757
|
+
d,{authoring:!0}),h.push(await er(d))}let w=tr(f,h),I=`${m}.tmp-${dw()}`;try{await Ci(I,`${L(w)}
|
|
1758
|
+
`,{flag:"wx"}),await uw(I,m)}finally{await Mu(I,{force:!0})}return t(JSON.stringify({ok:!0,courseId:w.courseId,status:w.
|
|
1759
|
+
status,lockPath:m,topics:w.topics.length},null,2)),0}let[r,n,o]=e;if(!["validate","bundle"].includes(r)||!n||r==="bundle"&&
|
|
1742
1760
|
!o||e.length!==(r==="bundle"?3:2))throw new Error("Usage: vibe64 training validate <topic-directory> | bundle <topic-dir\
|
|
1743
|
-
ectory> <new-output-directory>");let i=await
|
|
1744
|
-
release:s.release,topicHash:s.topicHash,topicManifest:s.topicManifest,lessons:s.bundles.map(({lesson:c,hash:
|
|
1745
|
-
manifest:f})=>({code:c.code,hash:
|
|
1746
|
-
W.dirname(c)),W.basename(c)),
|
|
1747
|
-
"Bundle output must be outside the source topic.");await
|
|
1748
|
-
for(let f of m){let h=await
|
|
1749
|
-
path}. Validate and retry.`);let
|
|
1750
|
-
await
|
|
1751
|
-
`,{flag:"wx"})}catch(m){throw await
|
|
1752
|
-
status:s.topic.status,lessons:s.bundles.map(({lesson:c,hash:
|
|
1753
|
-
schemaVersion,...c.stage?{stage:c.stage}:{},...me(c)?{steps:c.steps.length}:{}}))},null,2)),0}var
|
|
1754
|
-
|
|
1755
|
-
import ar from"node:path";import{fileURLToPath as
|
|
1756
|
-
resolve(String(e||""));try{return t(r)}catch{return r}}function
|
|
1757
|
-
return n
|
|
1758
|
-
return`'${String(e).replaceAll("'","'\\''")}'`}function
|
|
1759
|
-
"${String(e).replaceAll('"','\\"')}"`}function
|
|
1760
|
-
...t}={}){return
|
|
1761
|
-
env,osReleaseText:t=
|
|
1762
|
-
!0:/\bmicrosoft\b|\bwsl\b/iu.test(String(t||""))}function
|
|
1763
|
-
return[Tt(e),Tt(t),...r.map(n=>Tt(n))].join(" ")}function
|
|
1761
|
+
ectory> <new-output-directory>");let i=await It(n),s=await He(i,{authoring:r==="validate"}),a={schemaVersion:1,topic:s.topic,
|
|
1762
|
+
release:s.release,topicHash:s.topicHash,topicManifest:s.topicManifest,lessons:s.bundles.map(({lesson:c,hash:l,status:u,required:m,
|
|
1763
|
+
manifest:f})=>({code:c.code,hash:l,status:u,required:m,manifest:f}))};if(r==="bundle"){let c=W.resolve(o),l=W.join(await It(
|
|
1764
|
+
W.dirname(c)),W.basename(c)),u=W.relative(i,l);if(!u||!u.startsWith(`..${W.sep}`)&&u!==".."&&!W.isAbsolute(u))throw new Error(
|
|
1765
|
+
"Bundle output must be outside the source topic.");await Lu(l);try{let m=Be([s.topicManifest,...s.bundles.map(f=>f.manifest)]);
|
|
1766
|
+
for(let f of m){let h=await In(W.join(i,f.path));if(K(h)!==f.sha256)throw new Error(`Source changed during bundling: ${f.
|
|
1767
|
+
path}. Validate and retry.`);let w=W.join(l,"files",f.path);await Lu(W.dirname(w),{recursive:!0}),await Ci(w,h,{flag:"wx"})}
|
|
1768
|
+
await Ci(W.join(l,"bundle.json"),`${L(a)}
|
|
1769
|
+
`,{flag:"wx"})}catch(m){throw await Mu(l,{recursive:!0,force:!0}),m}}return t(JSON.stringify({ok:!0,topicId:s.topic.topicId,
|
|
1770
|
+
status:s.topic.status,lessons:s.bundles.map(({lesson:c,hash:l,status:u})=>({code:c.code,hash:l,status:u,schemaVersion:c.
|
|
1771
|
+
schemaVersion,...c.stage?{stage:c.stage}:{},...me(c)?{steps:c.steps.length}:{}}))},null,2)),0}var Ai=g(()=>{dt();lt();_n();
|
|
1772
|
+
Cu();ju();ut()});import{spawn as Uu}from"node:child_process";import{readFileSync as mw}from"node:fs";import{release as Tn}from"node:os";import j from"node:process";
|
|
1773
|
+
import ar from"node:path";import{fileURLToPath as fw}from"node:url";import{realpathSync as Wu}from"node:fs";import Yu from"node:path";import Ju from"node:process";function $i(e,t){let r=Yu.
|
|
1774
|
+
resolve(String(e||""));try{return t(r)}catch{return r}}function ji({entrypointPath:e,argv:t=Ju.argv,realpath:r=Wu}){let n=t[1];
|
|
1775
|
+
return n?$i(n,r)===$i(e,r):!1}var pw=new URL("./run.js",import.meta.url).href,Vu=fw(pw),Gu=ar.dirname(Vu),At=ar.join(Gu,"server.js");function Tt(e=""){
|
|
1776
|
+
return`'${String(e).replaceAll("'","'\\''")}'`}function hw(e=""){return JSON.stringify(String(e))}function ki(e=""){return`\
|
|
1777
|
+
"${String(e).replaceAll('"','\\"')}"`}function gw(e="",t=[]){return[ki(e),...t.map(r=>ki(r))].join(" ")}function ww({entrypointPath:e=Vu,
|
|
1778
|
+
...t}={}){return ji({entrypointPath:e,...t})}function Bu(e=j.cwd()){return ar.basename(e)||"target"}function yw({env:e=j.
|
|
1779
|
+
env,osReleaseText:t=Tn(),platform:r=j.platform}={}){return r!=="linux"?!1:String(e.WSL_DISTRO_NAME||e.WSL_INTEROP||"").trim()?
|
|
1780
|
+
!0:/\bmicrosoft\b|\bwsl\b/iu.test(String(t||""))}function _w({nodePath:e=j.execPath,serverPath:t=At,serverArgs:r=[]}={}){
|
|
1781
|
+
return[Tt(e),Tt(t),...r.map(n=>Tt(n))].join(" ")}function Ew({cwd:e=j.cwd(),nodePath:t=j.execPath,serverArgs:r=[],serverPath:n=At,
|
|
1764
1782
|
title:o=`Vibe64 - ${ar.basename(j.cwd())||"target"}`}={}){return["finish_vibe64_terminal() {",' status="$1"',' message\
|
|
1765
1783
|
="$2"',' if [ "$status" -ne 0 ]; then',` printf '\\n%s Exit status %s. Press Enter to close this terminal...' "$messa\
|
|
1766
1784
|
ge" "$status"`," IFS= read -r _"," fi",' exit "$status"',"}",`cd ${Tt(e)}`,"status=$?",'if [ "$status" -ne 0 ]; the\
|
|
1767
1785
|
n',' finish_vibe64_terminal "$status" "Vibe64 could not enter the target directory."',"fi",`printf '\\033]0;%s\\007' ${Tt(
|
|
1768
|
-
o)}`,
|
|
1769
|
-
`)}function
|
|
1770
|
-
distroName:e="",shellScript:t=""}={}){let r=String(e||"").trim();return[...r?["-d",r]:[],"--","bash","-lc",
|
|
1771
|
-
cwd:e=j.cwd(),env:t=j.env,shellScript:r="",title:n=`Vibe64 - ${
|
|
1772
|
-
return[{command:"wt.exe",args:["new-window","--title",n,"wsl.exe",...o]},{command:"cmd.exe",args:["/d","/c",`start ${
|
|
1773
|
-
n)} ${
|
|
1774
|
-
platform,serverArgs:i=[],serverPath:s=
|
|
1775
|
-
title:a});if(o==="darwin")return[{command:"osascript",args:["-e",['tell application "Terminal"',"activate",`do script ${
|
|
1786
|
+
o)}`,_w({nodePath:t,serverArgs:r,serverPath:n}),'finish_vibe64_terminal "$?" "Vibe64 server exited."'].join(`
|
|
1787
|
+
`)}function bw(e=""){return`printf %s ${Buffer.from(String(e||""),"utf8").toString("base64")} | base64 -d | bash`}function vw({
|
|
1788
|
+
distroName:e="",shellScript:t=""}={}){let r=String(e||"").trim();return[...r?["-d",r]:[],"--","bash","-lc",bw(t)]}function Sw({
|
|
1789
|
+
cwd:e=j.cwd(),env:t=j.env,shellScript:r="",title:n=`Vibe64 - ${Bu(e)}`}={}){let o=vw({distroName:t.WSL_DISTRO_NAME,shellScript:r});
|
|
1790
|
+
return[{command:"wt.exe",args:["new-window","--title",n,"wsl.exe",...o]},{command:"cmd.exe",args:["/d","/c",`start ${ki(
|
|
1791
|
+
n)} ${gw("wsl.exe",o)}`]}]}function Iw({cwd:e=j.cwd(),env:t=j.env,nodePath:r=j.execPath,osReleaseText:n=Tn(),platform:o=j.
|
|
1792
|
+
platform,serverArgs:i=[],serverPath:s=At}={}){let a=`Vibe64 - ${Bu(e)}`,c=Ew({cwd:e,nodePath:r,serverArgs:i,serverPath:s,
|
|
1793
|
+
title:a});if(o==="darwin")return[{command:"osascript",args:["-e",['tell application "Terminal"',"activate",`do script ${hw(
|
|
1776
1794
|
c)}`,"end tell"].join(`
|
|
1777
|
-
`)]}];let
|
|
1795
|
+
`)]}];let l=[t.TERMINAL?{command:t.TERMINAL,args:["-e","bash","-lc",c]}:null,{command:"x-terminal-emulator",args:["-e","\
|
|
1778
1796
|
bash","-lc",c]},{command:"gnome-terminal",args:["--","bash","-lc",c]},{command:"konsole",args:["-e","bash","-lc",c]},{command:"\
|
|
1779
|
-
xfce4-terminal",args:["--command",`bash -lc ${Tt(c)}`]},{command:"xterm",args:["-e","bash","-lc",c]}].filter(Boolean);return
|
|
1780
|
-
{env:t,osReleaseText:n,platform:o})?[...
|
|
1781
|
-
(n,o)=>{let i=
|
|
1782
|
-
cwd:e=j.cwd(),env:t=j.env,nodePath:r=j.execPath,osReleaseText:n=
|
|
1783
|
-
let a=
|
|
1784
|
-
|
|
1785
|
-
started.")}async function
|
|
1786
|
-
r,[o,...n],{cwd:e,env:t,stdio:"inherit"});return new Promise((s,a)=>{i.once("error",a),i.once("exit",(c,
|
|
1787
|
-
return}s(Number(c||0))})})}function
|
|
1788
|
-
|
|
1789
|
-
terprises/vibe64/blob/main/docs/colleague-usage/${e==="darwin"?"set-up-macos":"set-up-linux"}.md`}function
|
|
1790
|
-
platform,nodeVersion:t=j.versions.node,requiredMajor:r=
|
|
1797
|
+
xfce4-terminal",args:["--command",`bash -lc ${Tt(c)}`]},{command:"xterm",args:["-e","bash","-lc",c]}].filter(Boolean);return yw(
|
|
1798
|
+
{env:t,osReleaseText:n,platform:o})?[...Sw({cwd:e,env:t,shellScript:c,title:a}),...l]:l}function Tw(e,t=[],r={}){return new Promise(
|
|
1799
|
+
(n,o)=>{let i=Uu(e,t,{...r,detached:!0,stdio:"ignore"});i.once("error",o),i.once("spawn",()=>{i.unref(),n(i)})})}async function Aw({
|
|
1800
|
+
cwd:e=j.cwd(),env:t=j.env,nodePath:r=j.execPath,osReleaseText:n=Tn(),platform:o=j.platform,serverArgs:i=[],serverPath:s=At}={}){
|
|
1801
|
+
let a=Iw({cwd:e,env:t,nodePath:r,osReleaseText:n,platform:o,serverArgs:i,serverPath:s}),c=[];for(let l of a)try{return await Tw(
|
|
1802
|
+
l.command,l.args,{cwd:e,env:t}),l}catch(u){c.push(u)}throw new AggregateError(c,"No supported terminal emulator could be\
|
|
1803
|
+
started.")}async function Ow({cwd:e=j.cwd(),env:t=j.env,nodePath:r=j.execPath,serverArgs:n=[],serverPath:o=At}={}){let i=Uu(
|
|
1804
|
+
r,[o,...n],{cwd:e,env:t,stdio:"inherit"});return new Promise((s,a)=>{i.once("error",a),i.once("exit",(c,l)=>{if(l){s(1);
|
|
1805
|
+
return}s(Number(c||0))})})}function Pw(e=ar.join(Gu,"..","package.json")){try{return/^\D*(\d+)/u.exec(String(JSON.parse(
|
|
1806
|
+
mw(e,"utf8")).engines?.node||""))?.[1]||""}catch{return""}}function Rw(e=j.platform){return`https://github.com/mobily-en\
|
|
1807
|
+
terprises/vibe64/blob/main/docs/colleague-usage/${e==="darwin"?"set-up-macos":"set-up-linux"}.md`}function Nw({platform:e=j.
|
|
1808
|
+
platform,nodeVersion:t=j.versions.node,requiredMajor:r=Pw()}={}){if(e==="win32")return["Vibe64 runs on Windows inside WS\
|
|
1791
1809
|
L2 (Ubuntu), not in PowerShell or Command Prompt.","Step by step: https://github.com/mobily-enterprises/vibe64/blob/main\
|
|
1792
1810
|
/docs/colleague-usage/set-up-windows.md"].join(`
|
|
1793
1811
|
`);let n=String(t||"").split(".")[0];return r&&n!==r?[`Vibe64 needs Node.js ${r}; this is Node.js ${t}.`,`To install it \
|
|
1794
1812
|
with mise, run: curl -fsSL https://mise.run | sh && ~/.local/bin/mise use -g node@${r}`,"Then add mise to your shell, op\
|
|
1795
|
-
en a new terminal and run npx vibe64 again:",`${
|
|
1796
|
-
`):""}async function
|
|
1797
|
-
argv.slice(2),serverPath:s=
|
|
1813
|
+
en a new terminal and run npx vibe64 again:",`${Rw(e)}#nodejs-and-mise`].join(`
|
|
1814
|
+
`):""}async function Cw({cwd:e=j.cwd(),env:t=j.env,nodePath:r=j.execPath,osReleaseText:n=Tn(),platform:o=j.platform,serverArgs:i=j.
|
|
1815
|
+
argv.slice(2),serverPath:s=At}={}){try{return await Aw({cwd:e,env:t,nodePath:r,osReleaseText:n,platform:o,serverArgs:i,serverPath:s}),
|
|
1798
1816
|
console.log("Vibe64 is starting in a new terminal window."),0}catch(a){return console.warn(`${a.message} Starting Vibe64\
|
|
1799
|
-
in this terminal instead.`),
|
|
1800
|
-
then(({runAgentSpecCli:n})=>n(j.argv.slice(3))),training:()=>Promise.resolve().then(()=>(
|
|
1801
|
-
j.argv.slice(3)))},t=
|
|
1802
|
-
n}).catch(n=>{console.error("Failed to run Vibe64:",n),j.exitCode=1})}export{
|
|
1803
|
-
Tt as quoteShellArg,
|
|
1804
|
-
|
|
1817
|
+
in this terminal instead.`),Ow({cwd:e,env:t,nodePath:r,serverArgs:i,serverPath:s})}}if(ww()){let e={spec:()=>Promise.resolve().then(()=>(ba(),Ea)).
|
|
1818
|
+
then(({runAgentSpecCli:n})=>n(j.argv.slice(3))),training:()=>Promise.resolve().then(()=>(Ai(),Du)).then(({runTrainingCli:n})=>n(
|
|
1819
|
+
j.argv.slice(3)))},t=Nw();t&&(console.error(t),j.exit(1)),(Object.hasOwn(e,j.argv[2])?e[j.argv[2]]():Cw()).then(n=>{j.exitCode=
|
|
1820
|
+
n}).catch(n=>{console.error("Failed to run Vibe64:",n),j.exitCode=1})}export{At as SERVER_ENTRYPOINT,ww as isDirectCliExecution,yw as isWslEnvironment,Aw as launchInNewTerminal,Nw as launcherProblem,
|
|
1821
|
+
Tt as quoteShellArg,Cw as runLauncher,_w as serverShellCommand,Bu as targetNameFromCwd,Iw as terminalLaunchCandidates,Ew as terminalShellScript,
|
|
1822
|
+
vw as wslServerCommandArgs,Sw as wslTerminalLaunchCandidates};
|