codexgpt 1.0.0
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/AGENTS.example.md +20 -0
- package/CHANGELOG.md +342 -0
- package/CHATGPT_PROMPT.md +12 -0
- package/CLOUDFLARED_VERIFIED_INSTALL.md +94 -0
- package/CODEX_PROMPT.md +12 -0
- package/CONTRIBUTING.md +62 -0
- package/DOMAIN_SETUP.md +275 -0
- package/FAQ.md +366 -0
- package/FAQ_ZH.md +329 -0
- package/LICENSE +21 -0
- package/PUBLIC_LAUNCH_CHECKLIST.md +111 -0
- package/README.md +490 -0
- package/README_ZH.md +747 -0
- package/SECURITY.md +295 -0
- package/config.example.env +103 -0
- package/dist/access/fullAccessLease.js +148 -0
- package/dist/access/fullAccessLease.js.map +1 -0
- package/dist/access/protectedRoots.js +122 -0
- package/dist/access/protectedRoots.js.map +1 -0
- package/dist/access/rootAdmission.js +347 -0
- package/dist/access/rootAdmission.js.map +1 -0
- package/dist/analysis/cache.js +27 -0
- package/dist/analysis/cache.js.map +1 -0
- package/dist/analysis/classify.js +102 -0
- package/dist/analysis/classify.js.map +1 -0
- package/dist/analysis/extract.js +139 -0
- package/dist/analysis/extract.js.map +1 -0
- package/dist/analysis/graph.js +22 -0
- package/dist/analysis/graph.js.map +1 -0
- package/dist/analysis/impact.js +167 -0
- package/dist/analysis/impact.js.map +1 -0
- package/dist/analysis/index.js +215 -0
- package/dist/analysis/index.js.map +1 -0
- package/dist/analysis/inventory.js +51 -0
- package/dist/analysis/inventory.js.map +1 -0
- package/dist/analysis/providers.js +24 -0
- package/dist/analysis/providers.js.map +1 -0
- package/dist/analysis/rank.js +27 -0
- package/dist/analysis/rank.js.map +1 -0
- package/dist/analysis/types.js +8 -0
- package/dist/analysis/types.js.map +1 -0
- package/dist/audit/canonicalJson.js +79 -0
- package/dist/audit/canonicalJson.js.map +1 -0
- package/dist/audit/diagnostics.js +128 -0
- package/dist/audit/diagnostics.js.map +1 -0
- package/dist/audit/index.js +12 -0
- package/dist/audit/index.js.map +1 -0
- package/dist/audit/lifecycleV3.js +53 -0
- package/dist/audit/lifecycleV3.js.map +1 -0
- package/dist/audit/lifecycleV4.js +70 -0
- package/dist/audit/lifecycleV4.js.map +1 -0
- package/dist/audit/lock.js +195 -0
- package/dist/audit/lock.js.map +1 -0
- package/dist/audit/queryTool.js +120 -0
- package/dist/audit/queryTool.js.map +1 -0
- package/dist/audit/runtime.js +48 -0
- package/dist/audit/runtime.js.map +1 -0
- package/dist/audit/schemas.js +640 -0
- package/dist/audit/schemas.js.map +1 -0
- package/dist/audit/store.js +1309 -0
- package/dist/audit/store.js.map +1 -0
- package/dist/audit/transactionParticipant.js +45 -0
- package/dist/audit/transactionParticipant.js.map +1 -0
- package/dist/audit/types.js +11 -0
- package/dist/audit/types.js.map +1 -0
- package/dist/auth/audit.js +44 -0
- package/dist/auth/audit.js.map +1 -0
- package/dist/auth/authorizationStore.js +333 -0
- package/dist/auth/authorizationStore.js.map +1 -0
- package/dist/auth/challenges.js +25 -0
- package/dist/auth/challenges.js.map +1 -0
- package/dist/auth/clientStore.js +469 -0
- package/dist/auth/clientStore.js.map +1 -0
- package/dist/auth/cloudflareConfig.js +112 -0
- package/dist/auth/cloudflareConfig.js.map +1 -0
- package/dist/auth/configuration.js +167 -0
- package/dist/auth/configuration.js.map +1 -0
- package/dist/auth/credentialStore.js +65 -0
- package/dist/auth/credentialStore.js.map +1 -0
- package/dist/auth/deploymentLock.js +220 -0
- package/dist/auth/deploymentLock.js.map +1 -0
- package/dist/auth/deploymentRegistry.js +149 -0
- package/dist/auth/deploymentRegistry.js.map +1 -0
- package/dist/auth/errors.js +26 -0
- package/dist/auth/errors.js.map +1 -0
- package/dist/auth/grantStore.js +307 -0
- package/dist/auth/grantStore.js.map +1 -0
- package/dist/auth/index.js +39 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/keyManager.js +148 -0
- package/dist/auth/keyManager.js.map +1 -0
- package/dist/auth/localAdminSession.js +173 -0
- package/dist/auth/localAdminSession.js.map +1 -0
- package/dist/auth/metadata.js +69 -0
- package/dist/auth/metadata.js.map +1 -0
- package/dist/auth/oauthProvider.js +589 -0
- package/dist/auth/oauthProvider.js.map +1 -0
- package/dist/auth/ownerApproval.js +51 -0
- package/dist/auth/ownerApproval.js.map +1 -0
- package/dist/auth/policyIdentity.js +189 -0
- package/dist/auth/policyIdentity.js.map +1 -0
- package/dist/auth/rateLimits.js +66 -0
- package/dist/auth/rateLimits.js.map +1 -0
- package/dist/auth/recovery.js +275 -0
- package/dist/auth/recovery.js.map +1 -0
- package/dist/auth/requestContext.js +34 -0
- package/dist/auth/requestContext.js.map +1 -0
- package/dist/auth/resourceMiddleware.js +147 -0
- package/dist/auth/resourceMiddleware.js.map +1 -0
- package/dist/auth/runtimeStatus.js +51 -0
- package/dist/auth/runtimeStatus.js.map +1 -0
- package/dist/auth/schemas.js +84 -0
- package/dist/auth/schemas.js.map +1 -0
- package/dist/auth/stateStore.js +468 -0
- package/dist/auth/stateStore.js.map +1 -0
- package/dist/auth/tokenService.js +631 -0
- package/dist/auth/tokenService.js.map +1 -0
- package/dist/auth/toolSecurity.js +108 -0
- package/dist/auth/toolSecurity.js.map +1 -0
- package/dist/auth/types.js +6 -0
- package/dist/auth/types.js.map +1 -0
- package/dist/auth/windowsDpapi.js +193 -0
- package/dist/auth/windowsDpapi.js.map +1 -0
- package/dist/bashOps.js +292 -0
- package/dist/bashOps.js.map +1 -0
- package/dist/capabilitiesOps.js +412 -0
- package/dist/capabilitiesOps.js.map +1 -0
- package/dist/changesets/crypto.js +92 -0
- package/dist/changesets/crypto.js.map +1 -0
- package/dist/changesets/index.js +9 -0
- package/dist/changesets/index.js.map +1 -0
- package/dist/changesets/moveStore.js +237 -0
- package/dist/changesets/moveStore.js.map +1 -0
- package/dist/changesets/moveUndo.js +386 -0
- package/dist/changesets/moveUndo.js.map +1 -0
- package/dist/changesets/schemas.js +234 -0
- package/dist/changesets/schemas.js.map +1 -0
- package/dist/changesets/store.js +573 -0
- package/dist/changesets/store.js.map +1 -0
- package/dist/changesets/types.js +9 -0
- package/dist/changesets/types.js.map +1 -0
- package/dist/changesets/undo.js +525 -0
- package/dist/changesets/undo.js.map +1 -0
- package/dist/changesets/unifiedUndo.js +31 -0
- package/dist/changesets/unifiedUndo.js.map +1 -0
- package/dist/cliEnvironment.js +85 -0
- package/dist/cliEnvironment.js.map +1 -0
- package/dist/codexSessions.js +733 -0
- package/dist/codexSessions.js.map +1 -0
- package/dist/codexgptSupertool.js +216 -0
- package/dist/codexgptSupertool.js.map +1 -0
- package/dist/codexproSupertool.js +204 -0
- package/dist/codexproSupertool.js.map +1 -0
- package/dist/config.js +733 -0
- package/dist/config.js.map +1 -0
- package/dist/control/localApprovalClient.js +287 -0
- package/dist/control/localApprovalClient.js.map +1 -0
- package/dist/control/localApprovalServer.js +466 -0
- package/dist/control/localApprovalServer.js.map +1 -0
- package/dist/control/runtime.js +178 -0
- package/dist/control/runtime.js.map +1 -0
- package/dist/control/schemas.js +184 -0
- package/dist/control/schemas.js.map +1 -0
- package/dist/control/windowsLocalControl.js +348 -0
- package/dist/control/windowsLocalControl.js.map +1 -0
- package/dist/fsOps.js +541 -0
- package/dist/fsOps.js.map +1 -0
- package/dist/git/admission.js +26 -0
- package/dist/git/admission.js.map +1 -0
- package/dist/git/branchService.js +51 -0
- package/dist/git/branchService.js.map +1 -0
- package/dist/git/capabilities.js +143 -0
- package/dist/git/capabilities.js.map +1 -0
- package/dist/git/commitService.js +344 -0
- package/dist/git/commitService.js.map +1 -0
- package/dist/git/durableState.js +151 -0
- package/dist/git/durableState.js.map +1 -0
- package/dist/git/execution.js +451 -0
- package/dist/git/execution.js.map +1 -0
- package/dist/git/fileTransaction.js +50 -0
- package/dist/git/fileTransaction.js.map +1 -0
- package/dist/git/indexService.js +421 -0
- package/dist/git/indexService.js.map +1 -0
- package/dist/git/integrations.js +653 -0
- package/dist/git/integrations.js.map +1 -0
- package/dist/git/locks.js +287 -0
- package/dist/git/locks.js.map +1 -0
- package/dist/git/mutationContext.js +92 -0
- package/dist/git/mutationContext.js.map +1 -0
- package/dist/git/mutationJournal.js +91 -0
- package/dist/git/mutationJournal.js.map +1 -0
- package/dist/git/mutationService.js +352 -0
- package/dist/git/mutationService.js.map +1 -0
- package/dist/git/normalization.js +57 -0
- package/dist/git/normalization.js.map +1 -0
- package/dist/git/objectQuarantine.js +243 -0
- package/dist/git/objectQuarantine.js.map +1 -0
- package/dist/git/opaqueRecordStore.js +187 -0
- package/dist/git/opaqueRecordStore.js.map +1 -0
- package/dist/git/operationStore.js +287 -0
- package/dist/git/operationStore.js.map +1 -0
- package/dist/git/parsers.js +311 -0
- package/dist/git/parsers.js.map +1 -0
- package/dist/git/privateIndex.js +79 -0
- package/dist/git/privateIndex.js.map +1 -0
- package/dist/git/productionBootstrap.js +39 -0
- package/dist/git/productionBootstrap.js.map +1 -0
- package/dist/git/readService.js +846 -0
- package/dist/git/readService.js.map +1 -0
- package/dist/git/recovery.js +417 -0
- package/dist/git/recovery.js.map +1 -0
- package/dist/git/repositoryIdentity.js +611 -0
- package/dist/git/repositoryIdentity.js.map +1 -0
- package/dist/git/repositoryStore.js +237 -0
- package/dist/git/repositoryStore.js.map +1 -0
- package/dist/git/resources.js +113 -0
- package/dist/git/resources.js.map +1 -0
- package/dist/git/restoreService.js +178 -0
- package/dist/git/restoreService.js.map +1 -0
- package/dist/git/reviewToken.js +86 -0
- package/dist/git/reviewToken.js.map +1 -0
- package/dist/git/stashService.js +566 -0
- package/dist/git/stashService.js.map +1 -0
- package/dist/git/stateToken.js +139 -0
- package/dist/git/stateToken.js.map +1 -0
- package/dist/gitOps.js +147 -0
- package/dist/gitOps.js.map +1 -0
- package/dist/guard.js +608 -0
- package/dist/guard.js.map +1 -0
- package/dist/guidance/diagnostics.js +14 -0
- package/dist/guidance/diagnostics.js.map +1 -0
- package/dist/guidance/instructions.js +167 -0
- package/dist/guidance/instructions.js.map +1 -0
- package/dist/guidance/mode.js +18 -0
- package/dist/guidance/mode.js.map +1 -0
- package/dist/guidance/openaiSkillMetadata.js +29 -0
- package/dist/guidance/openaiSkillMetadata.js.map +1 -0
- package/dist/guidance/safeTextReader.js +171 -0
- package/dist/guidance/safeTextReader.js.map +1 -0
- package/dist/guidance/skillCatalog.js +70 -0
- package/dist/guidance/skillCatalog.js.map +1 -0
- package/dist/guidance/skillDiscovery.js +353 -0
- package/dist/guidance/skillDiscovery.js.map +1 -0
- package/dist/guidance/skillMetadata.js +115 -0
- package/dist/guidance/skillMetadata.js.map +1 -0
- package/dist/guidance/skillResources.js +146 -0
- package/dist/guidance/skillResources.js.map +1 -0
- package/dist/handoffOps.js +449 -0
- package/dist/handoffOps.js.map +1 -0
- package/dist/http/localAdminApp.js +203 -0
- package/dist/http/localAdminApp.js.map +1 -0
- package/dist/http/oauthMcpRuntime.js +294 -0
- package/dist/http/oauthMcpRuntime.js.map +1 -0
- package/dist/http/publicApp.js +350 -0
- package/dist/http/publicApp.js.map +1 -0
- package/dist/http/securityHeaders.js +11 -0
- package/dist/http/securityHeaders.js.map +1 -0
- package/dist/http.js +2076 -0
- package/dist/http.js.map +1 -0
- package/dist/moves/engine.js +1079 -0
- package/dist/moves/engine.js.map +1 -0
- package/dist/moves/index.js +6 -0
- package/dist/moves/index.js.map +1 -0
- package/dist/moves/planner.js +270 -0
- package/dist/moves/planner.js.map +1 -0
- package/dist/moves/recovery.js +557 -0
- package/dist/moves/recovery.js.map +1 -0
- package/dist/moves/service.js +300 -0
- package/dist/moves/service.js.map +1 -0
- package/dist/moves/types.js +11 -0
- package/dist/moves/types.js.map +1 -0
- package/dist/mutations/index.js +4 -0
- package/dist/mutations/index.js.map +1 -0
- package/dist/mutations/lifecycle.js +165 -0
- package/dist/mutations/lifecycle.js.map +1 -0
- package/dist/mutations/localService.js +163 -0
- package/dist/mutations/localService.js.map +1 -0
- package/dist/mutations/runtime.js +322 -0
- package/dist/mutations/runtime.js.map +1 -0
- package/dist/mutations/types.js +2 -0
- package/dist/mutations/types.js.map +1 -0
- package/dist/mutations/writers.js +360 -0
- package/dist/mutations/writers.js.map +1 -0
- package/dist/patchOps.js +420 -0
- package/dist/patchOps.js.map +1 -0
- package/dist/policy/approval.js +306 -0
- package/dist/policy/approval.js.map +1 -0
- package/dist/policy/audit.js +88 -0
- package/dist/policy/audit.js.map +1 -0
- package/dist/policy/authorizationFacts.js +187 -0
- package/dist/policy/authorizationFacts.js.map +1 -0
- package/dist/policy/compat.js +104 -0
- package/dist/policy/compat.js.map +1 -0
- package/dist/policy/context.js +31 -0
- package/dist/policy/context.js.map +1 -0
- package/dist/policy/enforcement.js +46 -0
- package/dist/policy/enforcement.js.map +1 -0
- package/dist/policy/evaluator.js +338 -0
- package/dist/policy/evaluator.js.map +1 -0
- package/dist/policy/executionCapabilities.js +80 -0
- package/dist/policy/executionCapabilities.js.map +1 -0
- package/dist/policy/executionResources.js +192 -0
- package/dist/policy/executionResources.js.map +1 -0
- package/dist/policy/fullAccessResources.js +23 -0
- package/dist/policy/fullAccessResources.js.map +1 -0
- package/dist/policy/hardPolicy.js +50 -0
- package/dist/policy/hardPolicy.js.map +1 -0
- package/dist/policy/identity.js +142 -0
- package/dist/policy/identity.js.map +1 -0
- package/dist/policy/integration.js +331 -0
- package/dist/policy/integration.js.map +1 -0
- package/dist/policy/pendingApprovals.js +301 -0
- package/dist/policy/pendingApprovals.js.map +1 -0
- package/dist/policy/profileStore.js +367 -0
- package/dist/policy/profileStore.js.map +1 -0
- package/dist/policy/resources.js +249 -0
- package/dist/policy/resources.js.map +1 -0
- package/dist/policy/runtime.js +713 -0
- package/dist/policy/runtime.js.map +1 -0
- package/dist/policy/schemas.js +625 -0
- package/dist/policy/schemas.js.map +1 -0
- package/dist/policy/toolPolicy.js +141 -0
- package/dist/policy/toolPolicy.js.map +1 -0
- package/dist/policy/transport.js +10 -0
- package/dist/policy/transport.js.map +1 -0
- package/dist/policy/types.js +31 -0
- package/dist/policy/types.js.map +1 -0
- package/dist/proContext.js +675 -0
- package/dist/proContext.js.map +1 -0
- package/dist/process/authority.js +18 -0
- package/dist/process/authority.js.map +1 -0
- package/dist/process/backendDiscovery.js +83 -0
- package/dist/process/backendDiscovery.js.map +1 -0
- package/dist/process/commandCompiler.js +71 -0
- package/dist/process/commandCompiler.js.map +1 -0
- package/dist/process/outputCursor.js +67 -0
- package/dist/process/outputCursor.js.map +1 -0
- package/dist/process/outputQuota.js +94 -0
- package/dist/process/outputQuota.js.map +1 -0
- package/dist/process/outputRing.js +138 -0
- package/dist/process/outputRing.js.map +1 -0
- package/dist/process/processAuditCoordinator.js +52 -0
- package/dist/process/processAuditCoordinator.js.map +1 -0
- package/dist/process/processManager.js +311 -0
- package/dist/process/processManager.js.map +1 -0
- package/dist/process/runCommand.js +332 -0
- package/dist/process/runCommand.js.map +1 -0
- package/dist/process/streamingRedactor.js +105 -0
- package/dist/process/streamingRedactor.js.map +1 -0
- package/dist/process/types.js +2 -0
- package/dist/process/types.js.map +1 -0
- package/dist/process/windowsHostClient.js +604 -0
- package/dist/process/windowsHostClient.js.map +1 -0
- package/dist/process/windowsHostProtocol.js +270 -0
- package/dist/process/windowsHostProtocol.js.map +1 -0
- package/dist/process/windowsPersistentBackend.js +263 -0
- package/dist/process/windowsPersistentBackend.js.map +1 -0
- package/dist/productionRuntime.js +907 -0
- package/dist/productionRuntime.js.map +1 -0
- package/dist/profileStore.js +231 -0
- package/dist/profileStore.js.map +1 -0
- package/dist/redact.js +124 -0
- package/dist/redact.js.map +1 -0
- package/dist/searchOps.js +186 -0
- package/dist/searchOps.js.map +1 -0
- package/dist/selfTestOps.js +786 -0
- package/dist/selfTestOps.js.map +1 -0
- package/dist/semantic/budgets.js +12 -0
- package/dist/semantic/budgets.js.map +1 -0
- package/dist/semantic/builtin/typescriptAssets.js +68 -0
- package/dist/semantic/builtin/typescriptAssets.js.map +1 -0
- package/dist/semantic/builtin/typescriptProvider.js +211 -0
- package/dist/semantic/builtin/typescriptProvider.js.map +1 -0
- package/dist/semantic/builtin/typescriptWorker.js +365 -0
- package/dist/semantic/builtin/typescriptWorker.js.map +1 -0
- package/dist/semantic/diffPreview.js +36 -0
- package/dist/semantic/diffPreview.js.map +1 -0
- package/dist/semantic/index.js +11 -0
- package/dist/semantic/index.js.map +1 -0
- package/dist/semantic/manager.js +522 -0
- package/dist/semantic/manager.js.map +1 -0
- package/dist/semantic/positions.js +86 -0
- package/dist/semantic/positions.js.map +1 -0
- package/dist/semantic/previewStore.js +276 -0
- package/dist/semantic/previewStore.js.map +1 -0
- package/dist/semantic/projectResolver.js +309 -0
- package/dist/semantic/projectResolver.js.map +1 -0
- package/dist/semantic/sourceSnapshot.js +54 -0
- package/dist/semantic/sourceSnapshot.js.map +1 -0
- package/dist/semantic/status.js +46 -0
- package/dist/semantic/status.js.map +1 -0
- package/dist/semantic/types.js +2 -0
- package/dist/semantic/types.js.map +1 -0
- package/dist/server.js +8676 -0
- package/dist/server.js.map +1 -0
- package/dist/stdio.js +64 -0
- package/dist/stdio.js.map +1 -0
- package/dist/toolCardWidget.js +2000 -0
- package/dist/toolCardWidget.js.map +1 -0
- package/dist/tools/contracts/catalog.js +111 -0
- package/dist/tools/contracts/catalog.js.map +1 -0
- package/dist/tools/contracts/index.js +8 -0
- package/dist/tools/contracts/index.js.map +1 -0
- package/dist/tools/contracts/registration.js +27 -0
- package/dist/tools/contracts/registration.js.map +1 -0
- package/dist/tools/contracts/schemas.js +11 -0
- package/dist/tools/contracts/schemas.js.map +1 -0
- package/dist/tools/contracts/types.js +2 -0
- package/dist/tools/contracts/types.js.map +1 -0
- package/dist/tools/contracts/v3.js +76 -0
- package/dist/tools/contracts/v3.js.map +1 -0
- package/dist/tools/contracts/v4.js +39 -0
- package/dist/tools/contracts/v4.js.map +1 -0
- package/dist/tools/contracts/v5.js +20 -0
- package/dist/tools/contracts/v5.js.map +1 -0
- package/dist/tools/phase3dServer.js +350 -0
- package/dist/tools/phase3dServer.js.map +1 -0
- package/dist/tools/schemas/applyPatch.js +388 -0
- package/dist/tools/schemas/applyPatch.js.map +1 -0
- package/dist/tools/schemas/bash.js +202 -0
- package/dist/tools/schemas/bash.js.map +1 -0
- package/dist/tools/schemas/closeWorkspace.js +105 -0
- package/dist/tools/schemas/closeWorkspace.js.map +1 -0
- package/dist/tools/schemas/codexContext.js +402 -0
- package/dist/tools/schemas/codexContext.js.map +1 -0
- package/dist/tools/schemas/codexSessions.js +328 -0
- package/dist/tools/schemas/codexSessions.js.map +1 -0
- package/dist/tools/schemas/codexgpt.js +1068 -0
- package/dist/tools/schemas/codexgpt.js.map +1 -0
- package/dist/tools/schemas/codexgptInventory.js +359 -0
- package/dist/tools/schemas/codexgptInventory.js.map +1 -0
- package/dist/tools/schemas/codexgptSelfTest.js +563 -0
- package/dist/tools/schemas/codexgptSelfTest.js.map +1 -0
- package/dist/tools/schemas/codexpro.js +917 -0
- package/dist/tools/schemas/codexpro.js.map +1 -0
- package/dist/tools/schemas/codexproInventory.js +352 -0
- package/dist/tools/schemas/codexproInventory.js.map +1 -0
- package/dist/tools/schemas/codexproSelfTest.js +546 -0
- package/dist/tools/schemas/codexproSelfTest.js.map +1 -0
- package/dist/tools/schemas/common.js +21 -0
- package/dist/tools/schemas/common.js.map +1 -0
- package/dist/tools/schemas/createTaskWorktree.js +51 -0
- package/dist/tools/schemas/createTaskWorktree.js.map +1 -0
- package/dist/tools/schemas/edit.js +321 -0
- package/dist/tools/schemas/edit.js.map +1 -0
- package/dist/tools/schemas/execution.js +330 -0
- package/dist/tools/schemas/execution.js.map +1 -0
- package/dist/tools/schemas/exportProContext.js +370 -0
- package/dist/tools/schemas/exportProContext.js.map +1 -0
- package/dist/tools/schemas/getTaskWorktree.js +19 -0
- package/dist/tools/schemas/getTaskWorktree.js.map +1 -0
- package/dist/tools/schemas/gitBranch.js +42 -0
- package/dist/tools/schemas/gitBranch.js.map +1 -0
- package/dist/tools/schemas/gitCommit.js +40 -0
- package/dist/tools/schemas/gitCommit.js.map +1 -0
- package/dist/tools/schemas/gitCreateBranch.js +22 -0
- package/dist/tools/schemas/gitCreateBranch.js.map +1 -0
- package/dist/tools/schemas/gitDiff.js +222 -0
- package/dist/tools/schemas/gitDiff.js.map +1 -0
- package/dist/tools/schemas/gitLog.js +41 -0
- package/dist/tools/schemas/gitLog.js.map +1 -0
- package/dist/tools/schemas/gitRestore.js +47 -0
- package/dist/tools/schemas/gitRestore.js.map +1 -0
- package/dist/tools/schemas/gitStage.js +33 -0
- package/dist/tools/schemas/gitStage.js.map +1 -0
- package/dist/tools/schemas/gitStash.js +102 -0
- package/dist/tools/schemas/gitStash.js.map +1 -0
- package/dist/tools/schemas/gitStatus.js +226 -0
- package/dist/tools/schemas/gitStatus.js.map +1 -0
- package/dist/tools/schemas/gitV4Common.js +205 -0
- package/dist/tools/schemas/gitV4Common.js.map +1 -0
- package/dist/tools/schemas/guidance.js +40 -0
- package/dist/tools/schemas/guidance.js.map +1 -0
- package/dist/tools/schemas/handoffToAgent.js +276 -0
- package/dist/tools/schemas/handoffToAgent.js.map +1 -0
- package/dist/tools/schemas/handoffToCodex.js +137 -0
- package/dist/tools/schemas/handoffToCodex.js.map +1 -0
- package/dist/tools/schemas/inspectWorkspace.js +379 -0
- package/dist/tools/schemas/inspectWorkspace.js.map +1 -0
- package/dist/tools/schemas/listTaskWorktrees.js +21 -0
- package/dist/tools/schemas/listTaskWorktrees.js.map +1 -0
- package/dist/tools/schemas/listWorkspaces.js +134 -0
- package/dist/tools/schemas/listWorkspaces.js.map +1 -0
- package/dist/tools/schemas/loadSkill.js +619 -0
- package/dist/tools/schemas/loadSkill.js.map +1 -0
- package/dist/tools/schemas/mergeTaskWorktree.js +105 -0
- package/dist/tools/schemas/mergeTaskWorktree.js.map +1 -0
- package/dist/tools/schemas/movePaths.js +175 -0
- package/dist/tools/schemas/movePaths.js.map +1 -0
- package/dist/tools/schemas/openCurrentWorkspace.js +174 -0
- package/dist/tools/schemas/openCurrentWorkspace.js.map +1 -0
- package/dist/tools/schemas/openFullAccessWorkspace.js +81 -0
- package/dist/tools/schemas/openFullAccessWorkspace.js.map +1 -0
- package/dist/tools/schemas/openWorkspace.js +193 -0
- package/dist/tools/schemas/openWorkspace.js.map +1 -0
- package/dist/tools/schemas/queryAuditEvents.js +193 -0
- package/dist/tools/schemas/queryAuditEvents.js.map +1 -0
- package/dist/tools/schemas/read.js +199 -0
- package/dist/tools/schemas/read.js.map +1 -0
- package/dist/tools/schemas/readCodexSession.js +353 -0
- package/dist/tools/schemas/readCodexSession.js.map +1 -0
- package/dist/tools/schemas/readHandoff.js +446 -0
- package/dist/tools/schemas/readHandoff.js.map +1 -0
- package/dist/tools/schemas/removeTaskWorktree.js +40 -0
- package/dist/tools/schemas/removeTaskWorktree.js.map +1 -0
- package/dist/tools/schemas/search.js +235 -0
- package/dist/tools/schemas/search.js.map +1 -0
- package/dist/tools/schemas/semantic.js +195 -0
- package/dist/tools/schemas/semantic.js.map +1 -0
- package/dist/tools/schemas/serverConfig.js +157 -0
- package/dist/tools/schemas/serverConfig.js.map +1 -0
- package/dist/tools/schemas/showChanges.js +283 -0
- package/dist/tools/schemas/showChanges.js.map +1 -0
- package/dist/tools/schemas/transactionResult.js +11 -0
- package/dist/tools/schemas/transactionResult.js.map +1 -0
- package/dist/tools/schemas/tree.js +136 -0
- package/dist/tools/schemas/tree.js.map +1 -0
- package/dist/tools/schemas/undoChangeSet.js +152 -0
- package/dist/tools/schemas/undoChangeSet.js.map +1 -0
- package/dist/tools/schemas/waitForHandoff.js +462 -0
- package/dist/tools/schemas/waitForHandoff.js.map +1 -0
- package/dist/tools/schemas/workspaceSnapshot.js +145 -0
- package/dist/tools/schemas/workspaceSnapshot.js.map +1 -0
- package/dist/tools/schemas/write.js +285 -0
- package/dist/tools/schemas/write.js.map +1 -0
- package/dist/transactions/atomicFs.js +438 -0
- package/dist/transactions/atomicFs.js.map +1 -0
- package/dist/transactions/atomicStateFile.js +190 -0
- package/dist/transactions/atomicStateFile.js.map +1 -0
- package/dist/transactions/engine.js +574 -0
- package/dist/transactions/engine.js.map +1 -0
- package/dist/transactions/index.js +12 -0
- package/dist/transactions/index.js.map +1 -0
- package/dist/transactions/installation.js +158 -0
- package/dist/transactions/installation.js.map +1 -0
- package/dist/transactions/manifestV2Store.js +96 -0
- package/dist/transactions/manifestV2Store.js.map +1 -0
- package/dist/transactions/participantRecovery.js +98 -0
- package/dist/transactions/participantRecovery.js.map +1 -0
- package/dist/transactions/recovery.js +513 -0
- package/dist/transactions/recovery.js.map +1 -0
- package/dist/transactions/schemas.js +365 -0
- package/dist/transactions/schemas.js.map +1 -0
- package/dist/transactions/stateRoot.js +63 -0
- package/dist/transactions/stateRoot.js.map +1 -0
- package/dist/transactions/types.js +11 -0
- package/dist/transactions/types.js.map +1 -0
- package/dist/transactions/workspaceLock.js +201 -0
- package/dist/transactions/workspaceLock.js.map +1 -0
- package/dist/workspaceOps.js +924 -0
- package/dist/workspaceOps.js.map +1 -0
- package/dist/worktrees/candidateWorkspace.js +566 -0
- package/dist/worktrees/candidateWorkspace.js.map +1 -0
- package/dist/worktrees/manager.js +258 -0
- package/dist/worktrees/manager.js.map +1 -0
- package/dist/worktrees/materializer.js +60 -0
- package/dist/worktrees/materializer.js.map +1 -0
- package/dist/worktrees/mergeExecute.js +498 -0
- package/dist/worktrees/mergeExecute.js.map +1 -0
- package/dist/worktrees/mergePlanStore.js +247 -0
- package/dist/worktrees/mergePlanStore.js.map +1 -0
- package/dist/worktrees/mergePrepare.js +709 -0
- package/dist/worktrees/mergePrepare.js.map +1 -0
- package/dist/worktrees/recovery.js +294 -0
- package/dist/worktrees/recovery.js.map +1 -0
- package/dist/worktrees/remove.js +296 -0
- package/dist/worktrees/remove.js.map +1 -0
- package/dist/worktrees/remover.js +57 -0
- package/dist/worktrees/remover.js.map +1 -0
- package/dist/worktrees/root.js +47 -0
- package/dist/worktrees/root.js.map +1 -0
- package/dist/worktrees/service.js +245 -0
- package/dist/worktrees/service.js.map +1 -0
- package/dist/worktrees/store.js +156 -0
- package/dist/worktrees/store.js.map +1 -0
- package/dist/worktrees/treeManifest.js +106 -0
- package/dist/worktrees/treeManifest.js.map +1 -0
- package/dist/worktrees/verificationReceipts.js +215 -0
- package/dist/worktrees/verificationReceipts.js.map +1 -0
- package/dist/worktrees/verificationTerminal.js +23 -0
- package/dist/worktrees/verificationTerminal.js.map +1 -0
- package/dist/worktrees/workspaceAuthority.js +64 -0
- package/dist/worktrees/workspaceAuthority.js.map +1 -0
- package/docs/favicon.svg +5 -0
- package/docs/index.html +624 -0
- package/docs/og.svg +52 -0
- package/docs/script.js +33 -0
- package/docs/star.svg +11 -0
- package/docs/styles.css +1571 -0
- package/docs/zh.html +428 -0
- package/package.json +121 -0
- package/scripts/analysis-cli-smoke.mjs +81 -0
- package/scripts/analysis-smoke.mjs +179 -0
- package/scripts/atomic-file.mjs +137 -0
- package/scripts/ci-change-classifier.mjs +59 -0
- package/scripts/ci-failure-summary.mjs +92 -0
- package/scripts/cloudflared-installer.mjs +215 -0
- package/scripts/cloudflared-release.mjs +63 -0
- package/scripts/codexgpt-entry.mjs +235 -0
- package/scripts/codexgpt.mjs +4987 -0
- package/scripts/connector-auth-output-shim.cjs +66 -0
- package/scripts/doctor-smoke.mjs +90 -0
- package/scripts/doctor.mjs +165 -0
- package/scripts/exact-head-ci.mjs +126 -0
- package/scripts/execute-handoff-smoke-platform-compat.mjs +38 -0
- package/scripts/execute-handoff-smoke.mjs +1117 -0
- package/scripts/g8-u-live-probe.mjs +208 -0
- package/scripts/http-smoke-compat.mjs +151 -0
- package/scripts/http-smoke.mjs +776 -0
- package/scripts/long-task-runner.mjs +1037 -0
- package/scripts/oauth-admin.mjs +1608 -0
- package/scripts/output-bounds.mjs +29 -0
- package/scripts/owned-temp-root.d.mts +50 -0
- package/scripts/owned-temp-root.mjs +567 -0
- package/scripts/phase-4a-smoke.mjs +36 -0
- package/scripts/policy-windows-spike.mjs +135 -0
- package/scripts/pro-apply.mjs +152 -0
- package/scripts/pro-bundle.mjs +121 -0
- package/scripts/pro-smoke.mjs +97 -0
- package/scripts/process-identity.mjs +67 -0
- package/scripts/repository-policy.mjs +166 -0
- package/scripts/run-and-summarize.mjs +134 -0
- package/scripts/run-smoke.mjs +52 -0
- package/scripts/run-with-cleanup.mjs +98 -0
- package/scripts/settings-smoke-platform-compat.mjs +85 -0
- package/scripts/settings-smoke.mjs +769 -0
- package/scripts/smoke-platform-compat.mjs +302 -0
- package/scripts/smoke.mjs +1180 -0
- package/scripts/stress-contract-compat.mjs +94 -0
- package/scripts/stress.mjs +882 -0
- package/scripts/test-domains.mjs +247 -0
- package/scripts/test-execution-profile-manifest.mjs +273 -0
- package/scripts/test-execution-profiles.mjs +147 -0
- package/scripts/test-performance-reporter.mjs +291 -0
- package/scripts/toolchain-manager.mjs +266 -0
- package/scripts/toolchains.json +19 -0
- package/scripts/windows-conpty-probe-child.mjs +82 -0
- package/scripts/windows-conpty-worker.ps1 +24 -0
- package/scripts/windows-credential-host-manifest.json +16 -0
- package/scripts/windows-credential-host-protocol-v1.json +16 -0
- package/scripts/windows-credential-host.cs +256 -0
- package/scripts/windows-credential-host.ps1 +26 -0
- package/scripts/windows-local-control-manifest.json +23 -0
- package/scripts/windows-local-control-spike.cs +738 -0
- package/scripts/windows-local-control-spike.mjs +415 -0
- package/scripts/windows-local-control-spike.ps1 +35 -0
- package/scripts/windows-local-control.cs +738 -0
- package/scripts/windows-local-control.ps1 +35 -0
- package/scripts/windows-native-api-inventory-v1.json +90 -0
- package/scripts/windows-process-host-manifest.json +20 -0
- package/scripts/windows-process-host-protocol-v1.json +59 -0
- package/scripts/windows-process-host.cs +2385 -0
- package/scripts/windows-process-host.ps1 +59 -0
- package/scripts/windows-realpath-shim.cjs +78 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export const OUTPUT_REDACTION_CAPABILITY = 'best_effort_known_patterns';
|
|
2
|
+
|
|
3
|
+
function utf8Prefix(buffer, maxBytes) {
|
|
4
|
+
let end = Math.min(buffer.byteLength, Math.max(0, maxBytes));
|
|
5
|
+
while (end > 0 && end < buffer.byteLength && (buffer[end] & 0xc0) === 0x80) {
|
|
6
|
+
end -= 1;
|
|
7
|
+
}
|
|
8
|
+
return buffer.subarray(0, end).toString('utf8');
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function trimUtf8Bytes(value, maxBytes) {
|
|
12
|
+
const limit = Math.max(0, Math.floor(Number(maxBytes) || 0));
|
|
13
|
+
const text = String(value);
|
|
14
|
+
const buffer = Buffer.from(text, 'utf8');
|
|
15
|
+
if (buffer.byteLength <= limit) return { text, truncated: false };
|
|
16
|
+
|
|
17
|
+
const marker = `\n...[output truncated to ${limit} bytes]`;
|
|
18
|
+
const markerBuffer = Buffer.from(marker, 'utf8');
|
|
19
|
+
if (markerBuffer.byteLength >= limit) {
|
|
20
|
+
return { text: utf8Prefix(markerBuffer, limit), truncated: true };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const prefix = utf8Prefix(buffer, limit - markerBuffer.byteLength);
|
|
24
|
+
return { text: `${prefix}${marker}`, truncated: true };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function boundedTextArtifact(header, detail, maxBytes) {
|
|
28
|
+
return trimUtf8Bytes(`${header}\n\n${String(detail)}\n`, maxBytes).text;
|
|
29
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export interface OwnedTempMarkerV1 {
|
|
2
|
+
readonly schemaVersion: 1;
|
|
3
|
+
readonly kind: "codexgpt-owned-temp";
|
|
4
|
+
readonly purpose: string;
|
|
5
|
+
readonly rootName: string;
|
|
6
|
+
readonly pid: number;
|
|
7
|
+
readonly nonce: string;
|
|
8
|
+
readonly processStartedAt?: string;
|
|
9
|
+
readonly createdAt: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface OwnedTempRoot {
|
|
13
|
+
readonly path: string;
|
|
14
|
+
readonly marker: OwnedTempMarkerV1;
|
|
15
|
+
cleanup(): Promise<void>;
|
|
16
|
+
cleanupSync(): void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface OwnedTempOptions {
|
|
20
|
+
baseRoot?: string;
|
|
21
|
+
sweep?: boolean;
|
|
22
|
+
sweepLimit?: number;
|
|
23
|
+
hostEnvironment?: NodeJS.ProcessEnv;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface OwnedTempEnvironment {
|
|
27
|
+
readonly rootPath: string;
|
|
28
|
+
readonly tempPath: string;
|
|
29
|
+
readonly marker: OwnedTempMarkerV1;
|
|
30
|
+
readonly environment: Readonly<NodeJS.ProcessEnv>;
|
|
31
|
+
cleanup(): Promise<void>;
|
|
32
|
+
cleanupSync(): void;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface OwnedTempSweepResult {
|
|
36
|
+
readonly scanned: number;
|
|
37
|
+
readonly removed: number;
|
|
38
|
+
readonly active: number;
|
|
39
|
+
readonly invalid: number;
|
|
40
|
+
readonly limited: boolean;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export const OWNED_TEMP_SCHEMA_VERSION: 1;
|
|
44
|
+
export const OWNED_TEMP_MARKER: string;
|
|
45
|
+
export const OWNED_TEMP_PREFIX: string;
|
|
46
|
+
export function createOwnedTempRoot(purpose: string, options?: OwnedTempOptions): Promise<OwnedTempRoot>;
|
|
47
|
+
export function createOwnedTempRootSync(purpose: string, options?: OwnedTempOptions): OwnedTempRoot;
|
|
48
|
+
export function createOwnedTempEnvironment(purpose: string, options?: OwnedTempOptions): Promise<OwnedTempEnvironment>;
|
|
49
|
+
export function sweepStaleOwnedTempRoots(options?: Pick<OwnedTempOptions, "baseRoot"> & { limit?: number }): Promise<OwnedTempSweepResult>;
|
|
50
|
+
export function sweepStaleOwnedTempRootsSync(options?: Pick<OwnedTempOptions, "baseRoot"> & { limit?: number }): OwnedTempSweepResult;
|
|
@@ -0,0 +1,567 @@
|
|
|
1
|
+
import { randomBytes, randomInt } from "node:crypto";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import fsp from "node:fs/promises";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { processCreationTimeSync, processIsAlive } from "./process-identity.mjs";
|
|
7
|
+
|
|
8
|
+
export const OWNED_TEMP_SCHEMA_VERSION = 1;
|
|
9
|
+
export const OWNED_TEMP_MARKER = ".codexgpt-owned-temp-v1.json";
|
|
10
|
+
export const OWNED_TEMP_PREFIX = "codexgpt-owned-v1-";
|
|
11
|
+
|
|
12
|
+
const PURPOSE_PATTERN = /^[a-z][a-z0-9-]{0,31}$/u;
|
|
13
|
+
const ROOT_NAME_PATTERN = /^codexgpt-owned-v1-([a-z][a-z0-9-]{0,31})-([1-9][0-9]{0,9})-([a-f0-9]{16})-([A-Za-z0-9_-]{6,})$/u;
|
|
14
|
+
const CLAIM_NAME_PATTERN = /^(codexgpt-owned-v1-[a-z][a-z0-9-]{0,31}-[1-9][0-9]{0,9}-[a-f0-9]{16}-[A-Za-z0-9_-]{6,})\.claim-([a-f0-9]{32})$/u;
|
|
15
|
+
const MAX_MARKER_BYTES = 4096;
|
|
16
|
+
const DEFAULT_SWEEP_LIMIT = 1024;
|
|
17
|
+
const activeRoots = new Map();
|
|
18
|
+
const sweepOffsets = new Map();
|
|
19
|
+
let exitCleanupInstalled = false;
|
|
20
|
+
let currentProcessStartedAt;
|
|
21
|
+
let currentProcessIdentityChecked = false;
|
|
22
|
+
|
|
23
|
+
function ownedTempError(code) {
|
|
24
|
+
const error = new Error(code);
|
|
25
|
+
error.code = code;
|
|
26
|
+
return error;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function samePath(left, right) {
|
|
30
|
+
const a = path.resolve(left);
|
|
31
|
+
const b = path.resolve(right);
|
|
32
|
+
return process.platform === "win32"
|
|
33
|
+
? a.toLocaleLowerCase("en-US") === b.toLocaleLowerCase("en-US")
|
|
34
|
+
: a === b;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function assertPurpose(purpose) {
|
|
38
|
+
if (typeof purpose !== "string" || !PURPOSE_PATTERN.test(purpose)) {
|
|
39
|
+
throw ownedTempError("OWNED_TEMP_PURPOSE_INVALID");
|
|
40
|
+
}
|
|
41
|
+
return purpose;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function boundedSweepLimit(value) {
|
|
45
|
+
const parsed = value ?? DEFAULT_SWEEP_LIMIT;
|
|
46
|
+
if (!Number.isSafeInteger(parsed) || parsed < 1 || parsed > 10_000) {
|
|
47
|
+
throw ownedTempError("OWNED_TEMP_SWEEP_LIMIT_INVALID");
|
|
48
|
+
}
|
|
49
|
+
return parsed;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function directoryIdentity(stat) {
|
|
53
|
+
return Object.freeze({ dev: String(stat.dev), ino: String(stat.ino) });
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function identityMatches(stat, expected) {
|
|
57
|
+
return !expected || (String(stat.dev) === expected.dev && String(stat.ino) === expected.ino);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function normalizeBaseSync(baseRoot = os.tmpdir()) {
|
|
61
|
+
const requested = path.resolve(baseRoot);
|
|
62
|
+
const lexical = fs.lstatSync(requested, { bigint: true });
|
|
63
|
+
if (!lexical.isDirectory() || lexical.isSymbolicLink()) throw ownedTempError("OWNED_TEMP_BASE_UNSAFE");
|
|
64
|
+
const canonical = fs.realpathSync.native(requested);
|
|
65
|
+
return canonical;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function normalizeBase(baseRoot = os.tmpdir()) {
|
|
69
|
+
const requested = path.resolve(baseRoot);
|
|
70
|
+
const lexical = await fsp.lstat(requested, { bigint: true });
|
|
71
|
+
if (!lexical.isDirectory() || lexical.isSymbolicLink()) throw ownedTempError("OWNED_TEMP_BASE_UNSAFE");
|
|
72
|
+
const canonical = await fsp.realpath(requested);
|
|
73
|
+
return canonical;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function markerKeysAreExact(marker) {
|
|
77
|
+
if (!marker || typeof marker !== "object" || Array.isArray(marker)) return false;
|
|
78
|
+
const keys = Object.keys(marker).sort().join("\0");
|
|
79
|
+
const legacy = [
|
|
80
|
+
"createdAt",
|
|
81
|
+
"kind",
|
|
82
|
+
"nonce",
|
|
83
|
+
"pid",
|
|
84
|
+
"purpose",
|
|
85
|
+
"rootName",
|
|
86
|
+
"schemaVersion"
|
|
87
|
+
].sort().join("\0");
|
|
88
|
+
const current = [
|
|
89
|
+
"createdAt",
|
|
90
|
+
"kind",
|
|
91
|
+
"nonce",
|
|
92
|
+
"pid",
|
|
93
|
+
"processStartedAt",
|
|
94
|
+
"purpose",
|
|
95
|
+
"rootName",
|
|
96
|
+
"schemaVersion"
|
|
97
|
+
].sort().join("\0");
|
|
98
|
+
return keys === legacy || keys === current;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function validateMarker(marker, rootName) {
|
|
102
|
+
const match = ROOT_NAME_PATTERN.exec(rootName);
|
|
103
|
+
if (
|
|
104
|
+
!markerKeysAreExact(marker) ||
|
|
105
|
+
marker.schemaVersion !== OWNED_TEMP_SCHEMA_VERSION ||
|
|
106
|
+
marker.kind !== "codexgpt-owned-temp" ||
|
|
107
|
+
typeof marker.purpose !== "string" ||
|
|
108
|
+
!PURPOSE_PATTERN.test(marker.purpose) ||
|
|
109
|
+
typeof marker.rootName !== "string" ||
|
|
110
|
+
marker.rootName !== rootName ||
|
|
111
|
+
!Number.isSafeInteger(marker.pid) ||
|
|
112
|
+
marker.pid < 1 ||
|
|
113
|
+
typeof marker.nonce !== "string" ||
|
|
114
|
+
!/^[a-f0-9]{16}$/u.test(marker.nonce) ||
|
|
115
|
+
typeof marker.createdAt !== "string" ||
|
|
116
|
+
!Number.isFinite(Date.parse(marker.createdAt)) ||
|
|
117
|
+
(Object.hasOwn(marker, "processStartedAt") && (
|
|
118
|
+
typeof marker.processStartedAt !== "string" ||
|
|
119
|
+
marker.processStartedAt.length < 1 ||
|
|
120
|
+
marker.processStartedAt.length > 256
|
|
121
|
+
)) ||
|
|
122
|
+
!match ||
|
|
123
|
+
match[1] !== marker.purpose ||
|
|
124
|
+
Number(match[2]) !== marker.pid ||
|
|
125
|
+
match[3] !== marker.nonce
|
|
126
|
+
) throw ownedTempError("OWNED_TEMP_MARKER_INVALID");
|
|
127
|
+
return Object.freeze({ ...marker });
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function parseCandidateName(rootName) {
|
|
131
|
+
const direct = ROOT_NAME_PATTERN.exec(rootName);
|
|
132
|
+
if (direct) return { actualRootName: rootName, markerRootName: rootName, match: direct, claimed: false };
|
|
133
|
+
const claim = CLAIM_NAME_PATTERN.exec(rootName);
|
|
134
|
+
if (!claim) return null;
|
|
135
|
+
const original = claim[1];
|
|
136
|
+
const originalMatch = ROOT_NAME_PATTERN.exec(original);
|
|
137
|
+
if (!originalMatch) return null;
|
|
138
|
+
return { actualRootName: rootName, markerRootName: original, match: originalMatch, claimed: true };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function candidatePath(baseRoot, rootName) {
|
|
142
|
+
if (!parseCandidateName(rootName)) throw ownedTempError("OWNED_TEMP_PATH_INVALID");
|
|
143
|
+
const candidate = path.resolve(baseRoot, rootName);
|
|
144
|
+
if (!samePath(path.dirname(candidate), baseRoot)) throw ownedTempError("OWNED_TEMP_PATH_INVALID");
|
|
145
|
+
return candidate;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function readVerifiedOwnedRootSync(baseRoot, rootName, expectedIdentity) {
|
|
149
|
+
const parsed = parseCandidateName(rootName);
|
|
150
|
+
if (!parsed) throw ownedTempError("OWNED_TEMP_PATH_INVALID");
|
|
151
|
+
const root = candidatePath(baseRoot, rootName);
|
|
152
|
+
const lexical = fs.lstatSync(root, { bigint: true });
|
|
153
|
+
if (!lexical.isDirectory() || lexical.isSymbolicLink() || !identityMatches(lexical, expectedIdentity)) {
|
|
154
|
+
throw ownedTempError("OWNED_TEMP_IDENTITY_CHANGED");
|
|
155
|
+
}
|
|
156
|
+
const canonical = fs.realpathSync.native(root);
|
|
157
|
+
if (!samePath(canonical, root)) throw ownedTempError("OWNED_TEMP_IDENTITY_CHANGED");
|
|
158
|
+
const markerPath = path.join(root, OWNED_TEMP_MARKER);
|
|
159
|
+
const markerLexical = fs.lstatSync(markerPath, { bigint: true });
|
|
160
|
+
if (
|
|
161
|
+
!markerLexical.isFile() ||
|
|
162
|
+
markerLexical.isSymbolicLink() ||
|
|
163
|
+
markerLexical.nlink !== 1n ||
|
|
164
|
+
markerLexical.size < 2n ||
|
|
165
|
+
markerLexical.size > BigInt(MAX_MARKER_BYTES)
|
|
166
|
+
) throw ownedTempError("OWNED_TEMP_MARKER_INVALID");
|
|
167
|
+
const descriptor = fs.openSync(markerPath, "r");
|
|
168
|
+
try {
|
|
169
|
+
const bytes = fs.readFileSync(descriptor);
|
|
170
|
+
const stable = fs.fstatSync(descriptor, { bigint: true });
|
|
171
|
+
if (
|
|
172
|
+
!stable.isFile() ||
|
|
173
|
+
stable.nlink !== 1n ||
|
|
174
|
+
stable.dev !== markerLexical.dev ||
|
|
175
|
+
stable.ino !== markerLexical.ino ||
|
|
176
|
+
stable.size !== markerLexical.size ||
|
|
177
|
+
stable.mtimeNs !== markerLexical.mtimeNs
|
|
178
|
+
) throw ownedTempError("OWNED_TEMP_MARKER_INVALID");
|
|
179
|
+
return {
|
|
180
|
+
root,
|
|
181
|
+
identity: directoryIdentity(lexical),
|
|
182
|
+
marker: validateMarker(JSON.parse(bytes.toString("utf8")), parsed.markerRootName)
|
|
183
|
+
};
|
|
184
|
+
} finally {
|
|
185
|
+
fs.closeSync(descriptor);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
async function readVerifiedOwnedRoot(baseRoot, rootName, expectedIdentity) {
|
|
190
|
+
const parsed = parseCandidateName(rootName);
|
|
191
|
+
if (!parsed) throw ownedTempError("OWNED_TEMP_PATH_INVALID");
|
|
192
|
+
const root = candidatePath(baseRoot, rootName);
|
|
193
|
+
const lexical = await fsp.lstat(root, { bigint: true });
|
|
194
|
+
if (!lexical.isDirectory() || lexical.isSymbolicLink() || !identityMatches(lexical, expectedIdentity)) {
|
|
195
|
+
throw ownedTempError("OWNED_TEMP_IDENTITY_CHANGED");
|
|
196
|
+
}
|
|
197
|
+
const canonical = await fsp.realpath(root);
|
|
198
|
+
if (!samePath(canonical, root)) throw ownedTempError("OWNED_TEMP_IDENTITY_CHANGED");
|
|
199
|
+
const markerPath = path.join(root, OWNED_TEMP_MARKER);
|
|
200
|
+
const markerLexical = await fsp.lstat(markerPath, { bigint: true });
|
|
201
|
+
if (
|
|
202
|
+
!markerLexical.isFile() ||
|
|
203
|
+
markerLexical.isSymbolicLink() ||
|
|
204
|
+
markerLexical.nlink !== 1n ||
|
|
205
|
+
markerLexical.size < 2n ||
|
|
206
|
+
markerLexical.size > BigInt(MAX_MARKER_BYTES)
|
|
207
|
+
) throw ownedTempError("OWNED_TEMP_MARKER_INVALID");
|
|
208
|
+
const handle = await fsp.open(markerPath, "r");
|
|
209
|
+
try {
|
|
210
|
+
const [bytes, stable] = await Promise.all([handle.readFile(), handle.stat({ bigint: true })]);
|
|
211
|
+
if (
|
|
212
|
+
!stable.isFile() ||
|
|
213
|
+
stable.nlink !== 1n ||
|
|
214
|
+
stable.dev !== markerLexical.dev ||
|
|
215
|
+
stable.ino !== markerLexical.ino ||
|
|
216
|
+
stable.size !== markerLexical.size ||
|
|
217
|
+
stable.mtimeNs !== markerLexical.mtimeNs
|
|
218
|
+
) throw ownedTempError("OWNED_TEMP_MARKER_INVALID");
|
|
219
|
+
return {
|
|
220
|
+
root,
|
|
221
|
+
identity: directoryIdentity(lexical),
|
|
222
|
+
marker: validateMarker(JSON.parse(bytes.toString("utf8")), parsed.markerRootName)
|
|
223
|
+
};
|
|
224
|
+
} finally {
|
|
225
|
+
await handle.close();
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function processStartedAt() {
|
|
230
|
+
if (!currentProcessIdentityChecked) {
|
|
231
|
+
currentProcessStartedAt = processCreationTimeSync(process.pid);
|
|
232
|
+
currentProcessIdentityChecked = true;
|
|
233
|
+
}
|
|
234
|
+
return currentProcessStartedAt;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function ownerIsActive(marker, cache) {
|
|
238
|
+
if (!processIsAlive(marker.pid)) return false;
|
|
239
|
+
if (!Object.hasOwn(marker, "processStartedAt")) return true;
|
|
240
|
+
let current = cache.get(marker.pid);
|
|
241
|
+
if (!cache.has(marker.pid)) {
|
|
242
|
+
current = processCreationTimeSync(marker.pid);
|
|
243
|
+
cache.set(marker.pid, current);
|
|
244
|
+
}
|
|
245
|
+
return !current || current === marker.processStartedAt;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function claimName(markerRootName) {
|
|
249
|
+
return `${markerRootName}.claim-${randomBytes(16).toString("hex")}`;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function removeVerifiedRootSync(baseRoot, rootName, expectedIdentity) {
|
|
253
|
+
const verified = readVerifiedOwnedRootSync(baseRoot, rootName, expectedIdentity);
|
|
254
|
+
const finalIdentity = fs.lstatSync(verified.root, { bigint: true });
|
|
255
|
+
if (!identityMatches(finalIdentity, verified.identity)) throw ownedTempError("OWNED_TEMP_IDENTITY_CHANGED");
|
|
256
|
+
const claimedRootName = claimName(verified.marker.rootName);
|
|
257
|
+
const claimedRoot = candidatePath(baseRoot, claimedRootName);
|
|
258
|
+
fs.renameSync(verified.root, claimedRoot);
|
|
259
|
+
const claimed = readVerifiedOwnedRootSync(baseRoot, claimedRootName, verified.identity);
|
|
260
|
+
fs.rmSync(claimed.root, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
async function removeVerifiedRoot(baseRoot, rootName, expectedIdentity) {
|
|
264
|
+
const verified = await readVerifiedOwnedRoot(baseRoot, rootName, expectedIdentity);
|
|
265
|
+
const finalIdentity = await fsp.lstat(verified.root, { bigint: true });
|
|
266
|
+
if (!identityMatches(finalIdentity, verified.identity)) throw ownedTempError("OWNED_TEMP_IDENTITY_CHANGED");
|
|
267
|
+
const claimedRootName = claimName(verified.marker.rootName);
|
|
268
|
+
const claimedRoot = candidatePath(baseRoot, claimedRootName);
|
|
269
|
+
await fsp.rename(verified.root, claimedRoot);
|
|
270
|
+
const claimed = await readVerifiedOwnedRoot(baseRoot, claimedRootName, verified.identity);
|
|
271
|
+
await fsp.rm(claimed.root, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function installExitCleanup() {
|
|
275
|
+
if (exitCleanupInstalled) return;
|
|
276
|
+
exitCleanupInstalled = true;
|
|
277
|
+
process.once("exit", () => {
|
|
278
|
+
for (const record of [...activeRoots.values()]) {
|
|
279
|
+
try {
|
|
280
|
+
removeVerifiedRootSync(record.baseRoot, record.rootName, record.identity);
|
|
281
|
+
} catch {
|
|
282
|
+
// A changed or locked root is intentionally preserved for a later exact sweep.
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function createMarker(purpose, rootName, nonce) {
|
|
289
|
+
const startedAt = processStartedAt();
|
|
290
|
+
return Object.freeze({
|
|
291
|
+
schemaVersion: OWNED_TEMP_SCHEMA_VERSION,
|
|
292
|
+
kind: "codexgpt-owned-temp",
|
|
293
|
+
purpose,
|
|
294
|
+
rootName,
|
|
295
|
+
pid: process.pid,
|
|
296
|
+
nonce,
|
|
297
|
+
...(startedAt ? { processStartedAt: startedAt } : {}),
|
|
298
|
+
createdAt: new Date().toISOString()
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function makeHandle(record) {
|
|
303
|
+
let cleaned = false;
|
|
304
|
+
let cleanupPromise;
|
|
305
|
+
return Object.freeze({
|
|
306
|
+
path: record.root,
|
|
307
|
+
marker: record.marker,
|
|
308
|
+
async cleanup() {
|
|
309
|
+
if (cleaned) return;
|
|
310
|
+
if (!cleanupPromise) {
|
|
311
|
+
cleanupPromise = (async () => {
|
|
312
|
+
await removeVerifiedRoot(record.baseRoot, record.rootName, record.identity);
|
|
313
|
+
cleaned = true;
|
|
314
|
+
activeRoots.delete(record.root);
|
|
315
|
+
})();
|
|
316
|
+
}
|
|
317
|
+
try {
|
|
318
|
+
await cleanupPromise;
|
|
319
|
+
} finally {
|
|
320
|
+
if (!cleaned) cleanupPromise = undefined;
|
|
321
|
+
}
|
|
322
|
+
},
|
|
323
|
+
cleanupSync() {
|
|
324
|
+
if (cleaned) return;
|
|
325
|
+
if (cleanupPromise) throw ownedTempError("OWNED_TEMP_CLEANUP_IN_PROGRESS");
|
|
326
|
+
removeVerifiedRootSync(record.baseRoot, record.rootName, record.identity);
|
|
327
|
+
cleaned = true;
|
|
328
|
+
activeRoots.delete(record.root);
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
function selectedCandidateNames(baseRoot, entries, limit, result) {
|
|
334
|
+
const names = [];
|
|
335
|
+
for (const entry of entries) {
|
|
336
|
+
if (!entry.isDirectory() || !entry.name.startsWith(OWNED_TEMP_PREFIX)) continue;
|
|
337
|
+
if (parseCandidateName(entry.name)) names.push(entry.name);
|
|
338
|
+
else result.invalid += 1;
|
|
339
|
+
}
|
|
340
|
+
names.sort();
|
|
341
|
+
result.limited = names.length > limit;
|
|
342
|
+
if (names.length === 0) return [];
|
|
343
|
+
let offset = sweepOffsets.get(baseRoot);
|
|
344
|
+
if (!Number.isSafeInteger(offset)) offset = randomInt(names.length);
|
|
345
|
+
offset %= names.length;
|
|
346
|
+
const count = Math.min(limit, names.length);
|
|
347
|
+
const selected = Array.from({ length: count }, (_, index) => names[(offset + index) % names.length]);
|
|
348
|
+
sweepOffsets.delete(baseRoot);
|
|
349
|
+
sweepOffsets.set(baseRoot, (offset + count) % names.length);
|
|
350
|
+
if (sweepOffsets.size > 128) sweepOffsets.delete(sweepOffsets.keys().next().value);
|
|
351
|
+
return selected;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function removeEmptyUnmarkedRootSync(baseRoot, rootName) {
|
|
355
|
+
const parsed = parseCandidateName(rootName);
|
|
356
|
+
if (!parsed || parsed.claimed) return "invalid";
|
|
357
|
+
const root = candidatePath(baseRoot, rootName);
|
|
358
|
+
const lexical = fs.lstatSync(root, { bigint: true });
|
|
359
|
+
if (!lexical.isDirectory() || lexical.isSymbolicLink()) return "invalid";
|
|
360
|
+
if (activeRoots.has(root) || processIsAlive(Number(parsed.match[2]))) return "active";
|
|
361
|
+
try {
|
|
362
|
+
fs.lstatSync(path.join(root, OWNED_TEMP_MARKER));
|
|
363
|
+
return "invalid";
|
|
364
|
+
} catch (error) {
|
|
365
|
+
if (error?.code !== "ENOENT") return "invalid";
|
|
366
|
+
}
|
|
367
|
+
if (!samePath(fs.realpathSync.native(root), root)) return "invalid";
|
|
368
|
+
if (fs.readdirSync(root).length !== 0) return "invalid";
|
|
369
|
+
const stable = fs.lstatSync(root, { bigint: true });
|
|
370
|
+
if (!identityMatches(stable, directoryIdentity(lexical))) return "invalid";
|
|
371
|
+
fs.rmdirSync(root);
|
|
372
|
+
return "removed";
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
async function removeEmptyUnmarkedRoot(baseRoot, rootName) {
|
|
376
|
+
const parsed = parseCandidateName(rootName);
|
|
377
|
+
if (!parsed || parsed.claimed) return "invalid";
|
|
378
|
+
const root = candidatePath(baseRoot, rootName);
|
|
379
|
+
const lexical = await fsp.lstat(root, { bigint: true });
|
|
380
|
+
if (!lexical.isDirectory() || lexical.isSymbolicLink()) return "invalid";
|
|
381
|
+
if (activeRoots.has(root) || processIsAlive(Number(parsed.match[2]))) return "active";
|
|
382
|
+
try {
|
|
383
|
+
await fsp.lstat(path.join(root, OWNED_TEMP_MARKER));
|
|
384
|
+
return "invalid";
|
|
385
|
+
} catch (error) {
|
|
386
|
+
if (error?.code !== "ENOENT") return "invalid";
|
|
387
|
+
}
|
|
388
|
+
if (!samePath(await fsp.realpath(root), root)) return "invalid";
|
|
389
|
+
if ((await fsp.readdir(root)).length !== 0) return "invalid";
|
|
390
|
+
const stable = await fsp.lstat(root, { bigint: true });
|
|
391
|
+
if (!identityMatches(stable, directoryIdentity(lexical))) return "invalid";
|
|
392
|
+
await fsp.rmdir(root);
|
|
393
|
+
return "removed";
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
export function sweepStaleOwnedTempRootsSync(options = {}) {
|
|
397
|
+
const baseRoot = normalizeBaseSync(options.baseRoot);
|
|
398
|
+
const limit = boundedSweepLimit(options.limit);
|
|
399
|
+
const result = { scanned: 0, removed: 0, active: 0, invalid: 0, limited: false };
|
|
400
|
+
const names = selectedCandidateNames(
|
|
401
|
+
baseRoot,
|
|
402
|
+
fs.readdirSync(baseRoot, { withFileTypes: true }),
|
|
403
|
+
limit,
|
|
404
|
+
result
|
|
405
|
+
);
|
|
406
|
+
const identityCache = new Map();
|
|
407
|
+
for (const rootName of names) {
|
|
408
|
+
result.scanned += 1;
|
|
409
|
+
try {
|
|
410
|
+
const verified = readVerifiedOwnedRootSync(baseRoot, rootName);
|
|
411
|
+
if (activeRoots.has(verified.root) || ownerIsActive(verified.marker, identityCache)) {
|
|
412
|
+
result.active += 1;
|
|
413
|
+
continue;
|
|
414
|
+
}
|
|
415
|
+
removeVerifiedRootSync(baseRoot, rootName, verified.identity);
|
|
416
|
+
result.removed += 1;
|
|
417
|
+
} catch (error) {
|
|
418
|
+
try {
|
|
419
|
+
const state = removeEmptyUnmarkedRootSync(baseRoot, rootName);
|
|
420
|
+
result[state] += 1;
|
|
421
|
+
} catch {
|
|
422
|
+
result.invalid += 1;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
return Object.freeze(result);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
export async function sweepStaleOwnedTempRoots(options = {}) {
|
|
430
|
+
const baseRoot = await normalizeBase(options.baseRoot);
|
|
431
|
+
const limit = boundedSweepLimit(options.limit);
|
|
432
|
+
const result = { scanned: 0, removed: 0, active: 0, invalid: 0, limited: false };
|
|
433
|
+
const names = selectedCandidateNames(
|
|
434
|
+
baseRoot,
|
|
435
|
+
await fsp.readdir(baseRoot, { withFileTypes: true }),
|
|
436
|
+
limit,
|
|
437
|
+
result
|
|
438
|
+
);
|
|
439
|
+
const identityCache = new Map();
|
|
440
|
+
for (const rootName of names) {
|
|
441
|
+
result.scanned += 1;
|
|
442
|
+
try {
|
|
443
|
+
const verified = await readVerifiedOwnedRoot(baseRoot, rootName);
|
|
444
|
+
if (activeRoots.has(verified.root) || ownerIsActive(verified.marker, identityCache)) {
|
|
445
|
+
result.active += 1;
|
|
446
|
+
continue;
|
|
447
|
+
}
|
|
448
|
+
await removeVerifiedRoot(baseRoot, rootName, verified.identity);
|
|
449
|
+
result.removed += 1;
|
|
450
|
+
} catch (error) {
|
|
451
|
+
try {
|
|
452
|
+
const state = await removeEmptyUnmarkedRoot(baseRoot, rootName);
|
|
453
|
+
result[state] += 1;
|
|
454
|
+
} catch {
|
|
455
|
+
result.invalid += 1;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
return Object.freeze(result);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
export function createOwnedTempRootSync(purpose, options = {}) {
|
|
463
|
+
const safePurpose = assertPurpose(purpose);
|
|
464
|
+
const baseRoot = normalizeBaseSync(options.baseRoot);
|
|
465
|
+
if (options.sweep !== false) sweepStaleOwnedTempRootsSync({ baseRoot, limit: options.sweepLimit });
|
|
466
|
+
const nonce = randomBytes(8).toString("hex");
|
|
467
|
+
const prefix = path.join(baseRoot, `${OWNED_TEMP_PREFIX}${safePurpose}-${process.pid}-${nonce}-`);
|
|
468
|
+
const root = fs.mkdtempSync(prefix);
|
|
469
|
+
const rootName = path.basename(root);
|
|
470
|
+
const lexical = fs.lstatSync(root, { bigint: true });
|
|
471
|
+
if (!lexical.isDirectory() || lexical.isSymbolicLink()) throw ownedTempError("OWNED_TEMP_CREATE_UNSAFE");
|
|
472
|
+
let marker;
|
|
473
|
+
try {
|
|
474
|
+
marker = createMarker(safePurpose, rootName, nonce);
|
|
475
|
+
fs.writeFileSync(path.join(root, OWNED_TEMP_MARKER), `${JSON.stringify(marker)}\n`, {
|
|
476
|
+
encoding: "utf8",
|
|
477
|
+
flag: "wx",
|
|
478
|
+
mode: 0o600
|
|
479
|
+
});
|
|
480
|
+
} catch (error) {
|
|
481
|
+
try {
|
|
482
|
+
const current = fs.lstatSync(root, { bigint: true });
|
|
483
|
+
if (identityMatches(current, directoryIdentity(lexical)) && fs.readdirSync(root).length === 0) {
|
|
484
|
+
fs.rmdirSync(root);
|
|
485
|
+
}
|
|
486
|
+
} catch {
|
|
487
|
+
// A non-empty or identity-changed root is preserved for exact stale-root recovery.
|
|
488
|
+
}
|
|
489
|
+
throw error;
|
|
490
|
+
}
|
|
491
|
+
const record = Object.freeze({ root, rootName, baseRoot, identity: directoryIdentity(lexical), marker });
|
|
492
|
+
activeRoots.set(root, record);
|
|
493
|
+
installExitCleanup();
|
|
494
|
+
return makeHandle(record);
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
export async function createOwnedTempRoot(purpose, options = {}) {
|
|
498
|
+
const safePurpose = assertPurpose(purpose);
|
|
499
|
+
const baseRoot = await normalizeBase(options.baseRoot);
|
|
500
|
+
if (options.sweep !== false) await sweepStaleOwnedTempRoots({ baseRoot, limit: options.sweepLimit });
|
|
501
|
+
const nonce = randomBytes(8).toString("hex");
|
|
502
|
+
const prefix = path.join(baseRoot, `${OWNED_TEMP_PREFIX}${safePurpose}-${process.pid}-${nonce}-`);
|
|
503
|
+
const root = await fsp.mkdtemp(prefix);
|
|
504
|
+
const rootName = path.basename(root);
|
|
505
|
+
const lexical = await fsp.lstat(root, { bigint: true });
|
|
506
|
+
if (!lexical.isDirectory() || lexical.isSymbolicLink()) throw ownedTempError("OWNED_TEMP_CREATE_UNSAFE");
|
|
507
|
+
let marker;
|
|
508
|
+
try {
|
|
509
|
+
marker = createMarker(safePurpose, rootName, nonce);
|
|
510
|
+
await fsp.writeFile(path.join(root, OWNED_TEMP_MARKER), `${JSON.stringify(marker)}\n`, {
|
|
511
|
+
encoding: "utf8",
|
|
512
|
+
flag: "wx",
|
|
513
|
+
mode: 0o600
|
|
514
|
+
});
|
|
515
|
+
} catch (error) {
|
|
516
|
+
try {
|
|
517
|
+
const current = await fsp.lstat(root, { bigint: true });
|
|
518
|
+
if (identityMatches(current, directoryIdentity(lexical)) && (await fsp.readdir(root)).length === 0) {
|
|
519
|
+
await fsp.rmdir(root);
|
|
520
|
+
}
|
|
521
|
+
} catch {
|
|
522
|
+
// A non-empty or identity-changed root is preserved for exact stale-root recovery.
|
|
523
|
+
}
|
|
524
|
+
throw error;
|
|
525
|
+
}
|
|
526
|
+
const record = Object.freeze({ root, rootName, baseRoot, identity: directoryIdentity(lexical), marker });
|
|
527
|
+
activeRoots.set(root, record);
|
|
528
|
+
installExitCleanup();
|
|
529
|
+
return makeHandle(record);
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
export async function createOwnedTempEnvironment(purpose, options = {}) {
|
|
533
|
+
const hostEnvironment = options.hostEnvironment ?? process.env;
|
|
534
|
+
const inheritedBaseRoot = hostEnvironment.CODEXGPT_OWNED_TEMP_BASE;
|
|
535
|
+
const owned = await createOwnedTempRoot(purpose, {
|
|
536
|
+
...options,
|
|
537
|
+
...(options.baseRoot === undefined && inheritedBaseRoot
|
|
538
|
+
? { baseRoot: inheritedBaseRoot }
|
|
539
|
+
: {})
|
|
540
|
+
});
|
|
541
|
+
const ownedBaseRoot = path.dirname(owned.path);
|
|
542
|
+
const tempPath = path.join(owned.path, "child-temp");
|
|
543
|
+
try {
|
|
544
|
+
await fsp.mkdir(tempPath, { mode: 0o700 });
|
|
545
|
+
} catch (error) {
|
|
546
|
+
try {
|
|
547
|
+
await owned.cleanup();
|
|
548
|
+
} catch (cleanupError) {
|
|
549
|
+
throw new AggregateError([error, cleanupError], "OWNED_TEMP_ENVIRONMENT_CREATE_FAILED");
|
|
550
|
+
}
|
|
551
|
+
throw error;
|
|
552
|
+
}
|
|
553
|
+
return Object.freeze({
|
|
554
|
+
rootPath: owned.path,
|
|
555
|
+
tempPath,
|
|
556
|
+
marker: owned.marker,
|
|
557
|
+
environment: Object.freeze({
|
|
558
|
+
...hostEnvironment,
|
|
559
|
+
CODEXGPT_OWNED_TEMP_BASE: ownedBaseRoot,
|
|
560
|
+
TEMP: tempPath,
|
|
561
|
+
TMP: tempPath,
|
|
562
|
+
TMPDIR: tempPath
|
|
563
|
+
}),
|
|
564
|
+
cleanup: owned.cleanup,
|
|
565
|
+
cleanupSync: owned.cleanupSync
|
|
566
|
+
});
|
|
567
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
import {
|
|
8
|
+
CONTRACT_V1_CHILD_TOOLS,
|
|
9
|
+
CONTRACT_V2_CHILD_TOOLS,
|
|
10
|
+
CONTRACT_V3_CHILD_TOOLS
|
|
11
|
+
} from "../dist/tools/contracts/index.js";
|
|
12
|
+
|
|
13
|
+
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
14
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(root, "scripts", "windows-process-host-manifest.json"), "utf8"));
|
|
15
|
+
const digest = (relativePath) => createHash("sha256")
|
|
16
|
+
.update(fs.readFileSync(path.join(root, relativePath)))
|
|
17
|
+
.digest("hex");
|
|
18
|
+
|
|
19
|
+
assert.equal(CONTRACT_V1_CHILD_TOOLS.length, 28);
|
|
20
|
+
assert.equal(CONTRACT_V2_CHILD_TOOLS.length, 31);
|
|
21
|
+
assert.equal(CONTRACT_V3_CHILD_TOOLS.length, 39);
|
|
22
|
+
assert.equal(CONTRACT_V3_CHILD_TOOLS.includes("bash"), false);
|
|
23
|
+
assert.equal(manifest.productionCSharpSha256, digest(manifest.productionCSharp));
|
|
24
|
+
assert.equal(manifest.productionPowerShellSha256, digest(manifest.productionPowerShell));
|
|
25
|
+
assert.equal(manifest.conPtyWorkerSha256, digest(manifest.conPtyWorker));
|
|
26
|
+
assert.equal(manifest.conPtyProbeChildSha256, digest(manifest.conPtyProbeChild));
|
|
27
|
+
assert.equal(manifest.protocolSha256, digest(manifest.protocolAuthority));
|
|
28
|
+
|
|
29
|
+
process.stdout.write(JSON.stringify({
|
|
30
|
+
schemaVersion: 1,
|
|
31
|
+
ok: true,
|
|
32
|
+
contracts: { v1: 28, v2: 31, v3: 39 },
|
|
33
|
+
nativeHost: "manifest_verified",
|
|
34
|
+
conptyWorker: "manifest_verified",
|
|
35
|
+
conptyProbeChild: "manifest_verified"
|
|
36
|
+
}) + "\n");
|