@bevel-software/platform-core-backend 0.13.6 → 0.15.1
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/THIRD-PARTY-NOTICES.md +6 -6
- package/dist/core/catalog-cache-invalidation.d.ts +29 -0
- package/dist/core/catalog-cache-invalidation.d.ts.map +1 -0
- package/dist/core/catalog-cache-invalidation.js +71 -0
- package/dist/core/catalog-cache-invalidation.js.map +1 -0
- package/dist/core/create-core-server.d.ts.map +1 -1
- package/dist/core/create-core-server.js +101 -9
- package/dist/core/create-core-server.js.map +1 -1
- package/dist/core/create-core-services.d.ts +20 -1
- package/dist/core/create-core-services.d.ts.map +1 -1
- package/dist/core/create-core-services.js +105 -43
- package/dist/core/create-core-services.js.map +1 -1
- package/dist/core-config.d.ts.map +1 -1
- package/dist/core-config.js +12 -5
- package/dist/core-config.js.map +1 -1
- package/dist/modules/access/access-control.interface.d.ts +18 -6
- package/dist/modules/access/access-control.interface.d.ts.map +1 -1
- package/dist/modules/access/access-control.service.d.ts +26 -1
- package/dist/modules/access/access-control.service.d.ts.map +1 -1
- package/dist/modules/access/access-control.service.js +213 -71
- package/dist/modules/access/access-control.service.js.map +1 -1
- package/dist/modules/access/access.routes.d.ts.map +1 -1
- package/dist/modules/access/access.routes.js +59 -7
- package/dist/modules/access/access.routes.js.map +1 -1
- package/dist/modules/access-model/access-grammar.d.ts +51 -1
- package/dist/modules/access-model/access-grammar.d.ts.map +1 -1
- package/dist/modules/access-model/access-grammar.js +95 -1
- package/dist/modules/access-model/access-grammar.js.map +1 -1
- package/dist/modules/access-model/group-files.d.ts.map +1 -1
- package/dist/modules/access-model/group-files.js +4 -1
- package/dist/modules/access-model/group-files.js.map +1 -1
- package/dist/modules/access-model/kb-read-filter.d.ts +12 -0
- package/dist/modules/access-model/kb-read-filter.d.ts.map +1 -1
- package/dist/modules/access-model/kb-read-filter.js +15 -0
- package/dist/modules/access-model/kb-read-filter.js.map +1 -1
- package/dist/modules/access-model/plugin-principals.d.ts +49 -0
- package/dist/modules/access-model/plugin-principals.d.ts.map +1 -0
- package/dist/modules/access-model/plugin-principals.js +125 -0
- package/dist/modules/access-model/plugin-principals.js.map +1 -0
- package/dist/modules/connection-probe/connection-probe.contract.d.ts +43 -0
- package/dist/modules/connection-probe/connection-probe.contract.d.ts.map +1 -0
- package/dist/modules/connection-probe/connection-probe.contract.js +2 -0
- package/dist/modules/connection-probe/connection-probe.contract.js.map +1 -0
- package/dist/modules/connection-probe/connection-probe.service.d.ts +94 -0
- package/dist/modules/connection-probe/connection-probe.service.d.ts.map +1 -0
- package/dist/modules/connection-probe/connection-probe.service.js +684 -0
- package/dist/modules/connection-probe/connection-probe.service.js.map +1 -0
- package/dist/modules/connection-probe/index.d.ts +3 -0
- package/dist/modules/connection-probe/index.d.ts.map +1 -0
- package/dist/modules/connection-probe/index.js +3 -0
- package/dist/modules/connection-probe/index.js.map +1 -0
- package/dist/modules/database/core-schema.d.ts +326 -0
- package/dist/modules/database/core-schema.d.ts.map +1 -1
- package/dist/modules/database/core-schema.js +52 -0
- package/dist/modules/database/core-schema.js.map +1 -1
- package/dist/modules/diff/diff.routes.d.ts.map +1 -1
- package/dist/modules/diff/diff.routes.js +3 -5
- package/dist/modules/diff/diff.routes.js.map +1 -1
- package/dist/modules/kb-fs/mutex.d.ts +37 -0
- package/dist/modules/kb-fs/mutex.d.ts.map +1 -1
- package/dist/modules/kb-fs/mutex.js +48 -5
- package/dist/modules/kb-fs/mutex.js.map +1 -1
- package/dist/modules/kb-sync/index.d.ts +6 -0
- package/dist/modules/kb-sync/index.d.ts.map +1 -0
- package/dist/modules/kb-sync/index.js +5 -0
- package/dist/modules/kb-sync/index.js.map +1 -0
- package/dist/modules/kb-sync/kb-sync.interface.d.ts +77 -0
- package/dist/modules/kb-sync/kb-sync.interface.d.ts.map +1 -0
- package/dist/modules/kb-sync/kb-sync.interface.js +2 -0
- package/dist/modules/kb-sync/kb-sync.interface.js.map +1 -0
- package/dist/modules/kb-sync/kb-sync.routes.d.ts +70 -0
- package/dist/modules/kb-sync/kb-sync.routes.d.ts.map +1 -0
- package/dist/modules/kb-sync/kb-sync.routes.js +135 -0
- package/dist/modules/kb-sync/kb-sync.routes.js.map +1 -0
- package/dist/modules/kb-sync/kb-sync.service.d.ts +45 -0
- package/dist/modules/kb-sync/kb-sync.service.d.ts.map +1 -0
- package/dist/modules/kb-sync/kb-sync.service.js +183 -0
- package/dist/modules/kb-sync/kb-sync.service.js.map +1 -0
- package/dist/modules/kb-sync/sync-auth.d.ts +59 -0
- package/dist/modules/kb-sync/sync-auth.d.ts.map +1 -0
- package/dist/modules/kb-sync/sync-auth.js +62 -0
- package/dist/modules/kb-sync/sync-auth.js.map +1 -0
- package/dist/modules/kb-sync/sync-payload.d.ts +32 -0
- package/dist/modules/kb-sync/sync-payload.d.ts.map +1 -0
- package/dist/modules/kb-sync/sync-payload.js +105 -0
- package/dist/modules/kb-sync/sync-payload.js.map +1 -0
- package/dist/modules/marketplace/git-http.routes.d.ts +42 -0
- package/dist/modules/marketplace/git-http.routes.d.ts.map +1 -0
- package/dist/modules/marketplace/git-http.routes.js +190 -0
- package/dist/modules/marketplace/git-http.routes.js.map +1 -0
- package/dist/modules/marketplace/github-facade/github-facade-admin.routes.d.ts +23 -0
- package/dist/modules/marketplace/github-facade/github-facade-admin.routes.d.ts.map +1 -0
- package/dist/modules/marketplace/github-facade/github-facade-admin.routes.js +59 -0
- package/dist/modules/marketplace/github-facade/github-facade-admin.routes.js.map +1 -0
- package/dist/modules/marketplace/github-facade/github-facade-codes.store.d.ts +59 -0
- package/dist/modules/marketplace/github-facade/github-facade-codes.store.d.ts.map +1 -0
- package/dist/modules/marketplace/github-facade/github-facade-codes.store.js +96 -0
- package/dist/modules/marketplace/github-facade/github-facade-codes.store.js.map +1 -0
- package/dist/modules/marketplace/github-facade/github-facade-credentials.service.d.ts +99 -0
- package/dist/modules/marketplace/github-facade/github-facade-credentials.service.d.ts.map +1 -0
- package/dist/modules/marketplace/github-facade/github-facade-credentials.service.js +147 -0
- package/dist/modules/marketplace/github-facade/github-facade-credentials.service.js.map +1 -0
- package/dist/modules/marketplace/github-facade/github-facade.routes.d.ts +47 -0
- package/dist/modules/marketplace/github-facade/github-facade.routes.d.ts.map +1 -0
- package/dist/modules/marketplace/github-facade/github-facade.routes.js +228 -0
- package/dist/modules/marketplace/github-facade/github-facade.routes.js.map +1 -0
- package/dist/modules/marketplace/github-facade/github-facade.service.d.ts +109 -0
- package/dist/modules/marketplace/github-facade/github-facade.service.d.ts.map +1 -0
- package/dist/modules/marketplace/github-facade/github-facade.service.js +172 -0
- package/dist/modules/marketplace/github-facade/github-facade.service.js.map +1 -0
- package/dist/modules/marketplace/github-facade/index.d.ts +6 -0
- package/dist/modules/marketplace/github-facade/index.d.ts.map +1 -0
- package/dist/modules/marketplace/github-facade/index.js +6 -0
- package/dist/modules/marketplace/github-facade/index.js.map +1 -0
- package/dist/modules/marketplace/index.d.ts +4 -0
- package/dist/modules/marketplace/index.d.ts.map +1 -0
- package/dist/modules/marketplace/index.js +4 -0
- package/dist/modules/marketplace/index.js.map +1 -0
- package/dist/modules/marketplace/marketplace-repo.service.d.ts +122 -0
- package/dist/modules/marketplace/marketplace-repo.service.d.ts.map +1 -0
- package/dist/modules/marketplace/marketplace-repo.service.js +300 -0
- package/dist/modules/marketplace/marketplace-repo.service.js.map +1 -0
- package/dist/modules/mcp/oauth/bevel-oauth-provider.d.ts.map +1 -1
- package/dist/modules/mcp/oauth/bevel-oauth-provider.js +4 -0
- package/dist/modules/mcp/oauth/bevel-oauth-provider.js.map +1 -1
- package/dist/modules/mcp/oauth/oauth-consent.routes.d.ts +14 -8
- package/dist/modules/mcp/oauth/oauth-consent.routes.d.ts.map +1 -1
- package/dist/modules/mcp/oauth/oauth-consent.routes.js +13 -1
- package/dist/modules/mcp/oauth/oauth-consent.routes.js.map +1 -1
- package/dist/modules/mcp/oauth/oauth-state.d.ts +13 -2
- package/dist/modules/mcp/oauth/oauth-state.d.ts.map +1 -1
- package/dist/modules/mcp/oauth/oauth-state.js +3 -1
- package/dist/modules/mcp/oauth/oauth-state.js.map +1 -1
- package/dist/modules/plugins/compile/compile-marketplace.d.ts +97 -0
- package/dist/modules/plugins/compile/compile-marketplace.d.ts.map +1 -0
- package/dist/modules/plugins/compile/compile-marketplace.js +240 -0
- package/dist/modules/plugins/compile/compile-marketplace.js.map +1 -0
- package/dist/modules/plugins/compile/marketplace-compiler.service.d.ts +66 -0
- package/dist/modules/plugins/compile/marketplace-compiler.service.d.ts.map +1 -0
- package/dist/modules/plugins/compile/marketplace-compiler.service.js +132 -0
- package/dist/modules/plugins/compile/marketplace-compiler.service.js.map +1 -0
- package/dist/modules/plugins/discovery/bundle-dialect/bundle.source.d.ts +37 -0
- package/dist/modules/plugins/discovery/bundle-dialect/bundle.source.d.ts.map +1 -0
- package/dist/modules/plugins/discovery/bundle-dialect/bundle.source.js +135 -0
- package/dist/modules/plugins/discovery/bundle-dialect/bundle.source.js.map +1 -0
- package/dist/modules/plugins/discovery/bundle-dialect/registry.d.ts +45 -0
- package/dist/modules/plugins/discovery/bundle-dialect/registry.d.ts.map +1 -0
- package/dist/modules/plugins/discovery/bundle-dialect/registry.js +147 -0
- package/dist/modules/plugins/discovery/bundle-dialect/registry.js.map +1 -0
- package/dist/modules/plugins/discovery/kb-plugin-source.d.ts +37 -0
- package/dist/modules/plugins/discovery/kb-plugin-source.d.ts.map +1 -0
- package/dist/modules/plugins/discovery/kb-plugin-source.js +107 -0
- package/dist/modules/plugins/discovery/kb-plugin-source.js.map +1 -0
- package/dist/modules/plugins/discovery/native.source.d.ts +15 -0
- package/dist/modules/plugins/discovery/native.source.d.ts.map +1 -0
- package/dist/modules/plugins/discovery/native.source.js +102 -0
- package/dist/modules/plugins/discovery/native.source.js.map +1 -0
- package/dist/modules/plugins/discovery/plugin-source.d.ts +96 -0
- package/dist/modules/plugins/discovery/plugin-source.d.ts.map +1 -0
- package/dist/modules/plugins/discovery/plugin-source.js +2 -0
- package/dist/modules/plugins/discovery/plugin-source.js.map +1 -0
- package/dist/modules/plugins/index.d.ts +10 -1
- package/dist/modules/plugins/index.d.ts.map +1 -1
- package/dist/modules/plugins/index.js +8 -0
- package/dist/modules/plugins/index.js.map +1 -1
- package/dist/modules/plugins/plugin-links.d.ts +66 -0
- package/dist/modules/plugins/plugin-links.d.ts.map +1 -0
- package/dist/modules/plugins/plugin-links.js +160 -0
- package/dist/modules/plugins/plugin-links.js.map +1 -0
- package/dist/modules/plugins/plugin-links.service.d.ts +114 -0
- package/dist/modules/plugins/plugin-links.service.d.ts.map +1 -0
- package/dist/modules/plugins/plugin-links.service.js +304 -0
- package/dist/modules/plugins/plugin-links.service.js.map +1 -0
- package/dist/modules/plugins/plugin-provision.service.d.ts +39 -3
- package/dist/modules/plugins/plugin-provision.service.d.ts.map +1 -1
- package/dist/modules/plugins/plugin-provision.service.js +152 -52
- package/dist/modules/plugins/plugin-provision.service.js.map +1 -1
- package/dist/modules/plugins/plugin-rename.service.d.ts +69 -0
- package/dist/modules/plugins/plugin-rename.service.d.ts.map +1 -0
- package/dist/modules/plugins/plugin-rename.service.js +245 -0
- package/dist/modules/plugins/plugin-rename.service.js.map +1 -0
- package/dist/modules/plugins/plugins.contract.d.ts +27 -1
- package/dist/modules/plugins/plugins.contract.d.ts.map +1 -1
- package/dist/modules/plugins/plugins.routes.d.ts +7 -1
- package/dist/modules/plugins/plugins.routes.d.ts.map +1 -1
- package/dist/modules/plugins/plugins.routes.js +120 -12
- package/dist/modules/plugins/plugins.routes.js.map +1 -1
- package/dist/modules/plugins/plugins.service.d.ts +50 -3
- package/dist/modules/plugins/plugins.service.d.ts.map +1 -1
- package/dist/modules/plugins/plugins.service.js +108 -47
- package/dist/modules/plugins/plugins.service.js.map +1 -1
- package/dist/modules/secrets-vault/db-secrets-vault.service.js +1 -1
- package/dist/modules/secrets-vault/db-secrets-vault.service.js.map +1 -1
- package/dist/modules/secrets-vault/secrets-vault.routes.d.ts +6 -0
- package/dist/modules/secrets-vault/secrets-vault.routes.d.ts.map +1 -1
- package/dist/modules/secrets-vault/secrets-vault.routes.js +31 -1
- package/dist/modules/secrets-vault/secrets-vault.routes.js.map +1 -1
- package/dist/modules/settings/deployment-settings.service.d.ts +9 -0
- package/dist/modules/settings/deployment-settings.service.d.ts.map +1 -1
- package/dist/modules/settings/deployment-settings.service.js +82 -2
- package/dist/modules/settings/deployment-settings.service.js.map +1 -1
- package/dist/modules/settings/setup.routes.d.ts +26 -0
- package/dist/modules/settings/setup.routes.d.ts.map +1 -1
- package/dist/modules/settings/setup.routes.js +9 -1
- package/dist/modules/settings/setup.routes.js.map +1 -1
- package/dist/modules/skills/index.d.ts +1 -0
- package/dist/modules/skills/index.d.ts.map +1 -1
- package/dist/modules/skills/index.js +1 -0
- package/dist/modules/skills/index.js.map +1 -1
- package/dist/modules/skills/pending-skills.service.d.ts.map +1 -1
- package/dist/modules/skills/pending-skills.service.js +9 -4
- package/dist/modules/skills/pending-skills.service.js.map +1 -1
- package/dist/modules/skills/skill-access-requests.routes.d.ts +38 -0
- package/dist/modules/skills/skill-access-requests.routes.d.ts.map +1 -0
- package/dist/modules/skills/skill-access-requests.routes.js +168 -0
- package/dist/modules/skills/skill-access-requests.routes.js.map +1 -0
- package/dist/modules/skills/skills.contract.d.ts +31 -0
- package/dist/modules/skills/skills.contract.d.ts.map +1 -1
- package/dist/modules/skills/skills.routes.d.ts +28 -3
- package/dist/modules/skills/skills.routes.d.ts.map +1 -1
- package/dist/modules/skills/skills.routes.js +42 -3
- package/dist/modules/skills/skills.routes.js.map +1 -1
- package/dist/modules/skills/skills.service.d.ts +4 -0
- package/dist/modules/skills/skills.service.d.ts.map +1 -1
- package/dist/modules/skills/skills.service.js +83 -22
- package/dist/modules/skills/skills.service.js.map +1 -1
- package/dist/modules/tool-auth/external-api-key.interface.d.ts +18 -1
- package/dist/modules/tool-auth/external-api-key.interface.d.ts.map +1 -1
- package/dist/modules/tool-auth/external-api-key.interface.js +2 -1
- package/dist/modules/tool-auth/external-api-key.interface.js.map +1 -1
- package/dist/modules/tool-auth/external-api-key.service.d.ts +13 -4
- package/dist/modules/tool-auth/external-api-key.service.d.ts.map +1 -1
- package/dist/modules/tool-auth/external-api-key.service.js +26 -9
- package/dist/modules/tool-auth/external-api-key.service.js.map +1 -1
- package/dist/modules/tool-manuals/mcp-json-discovery.d.ts +36 -0
- package/dist/modules/tool-manuals/mcp-json-discovery.d.ts.map +1 -1
- package/dist/modules/tool-manuals/mcp-json-discovery.js +130 -83
- package/dist/modules/tool-manuals/mcp-json-discovery.js.map +1 -1
- package/dist/modules/tool-manuals/mcp-server-edit.service.d.ts.map +1 -1
- package/dist/modules/tool-manuals/mcp-server-edit.service.js +10 -4
- package/dist/modules/tool-manuals/mcp-server-edit.service.js.map +1 -1
- package/dist/modules/tool-manuals/tool-manuals.contract.d.ts +83 -0
- package/dist/modules/tool-manuals/tool-manuals.contract.d.ts.map +1 -1
- package/dist/modules/tool-manuals/tool-manuals.service.d.ts +15 -2
- package/dist/modules/tool-manuals/tool-manuals.service.d.ts.map +1 -1
- package/dist/modules/tool-manuals/tool-manuals.service.js +199 -38
- package/dist/modules/tool-manuals/tool-manuals.service.js.map +1 -1
- package/dist/modules/workflow/git/git.service.d.ts +58 -3
- package/dist/modules/workflow/git/git.service.d.ts.map +1 -1
- package/dist/modules/workflow/git/git.service.js +325 -60
- package/dist/modules/workflow/git/git.service.js.map +1 -1
- package/dist/modules/workflow/git/pull-request.service.d.ts +6 -0
- package/dist/modules/workflow/git/pull-request.service.d.ts.map +1 -1
- package/dist/modules/workflow/git/pull-request.service.js +8 -0
- package/dist/modules/workflow/git/pull-request.service.js.map +1 -1
- package/dist/modules/workflow/workflow.routes.d.ts +2 -1
- package/dist/modules/workflow/workflow.routes.d.ts.map +1 -1
- package/dist/modules/workflow/workflow.routes.js +98 -9
- package/dist/modules/workflow/workflow.routes.js.map +1 -1
- package/dist/modules/workflow/workflow.service.d.ts +133 -9
- package/dist/modules/workflow/workflow.service.d.ts.map +1 -1
- package/dist/modules/workflow/workflow.service.js +462 -52
- package/dist/modules/workflow/workflow.service.js.map +1 -1
- package/dist/modules/workspace/startup/steps/plugin-manifests.step.d.ts +35 -0
- package/dist/modules/workspace/startup/steps/plugin-manifests.step.d.ts.map +1 -0
- package/dist/modules/workspace/startup/steps/plugin-manifests.step.js +121 -0
- package/dist/modules/workspace/startup/steps/plugin-manifests.step.js.map +1 -0
- package/dist/modules/workspace/startup/steps/seed-tree.d.ts.map +1 -1
- package/dist/modules/workspace/startup/steps/seed-tree.js +46 -2
- package/dist/modules/workspace/startup/steps/seed-tree.js.map +1 -1
- package/dist/modules/workspace/startup/steps/template-files.step.d.ts.map +1 -1
- package/dist/modules/workspace/startup/steps/template-files.step.js +112 -25
- package/dist/modules/workspace/startup/steps/template-files.step.js.map +1 -1
- package/dist/modules/workspace/workspace.routes.d.ts.map +1 -1
- package/dist/modules/workspace/workspace.routes.js +11 -14
- package/dist/modules/workspace/workspace.routes.js.map +1 -1
- package/dist/modules/workspace/workspace.service.d.ts +38 -1
- package/dist/modules/workspace/workspace.service.d.ts.map +1 -1
- package/dist/modules/workspace/workspace.service.js +131 -20
- package/dist/modules/workspace/workspace.service.js.map +1 -1
- package/dist/shared/domain-errors.d.ts +20 -0
- package/dist/shared/domain-errors.d.ts.map +1 -1
- package/dist/shared/domain-errors.js +29 -0
- package/dist/shared/domain-errors.js.map +1 -1
- package/dist/shared/fs-errors.d.ts +8 -0
- package/dist/shared/fs-errors.d.ts.map +1 -0
- package/dist/shared/fs-errors.js +11 -0
- package/dist/shared/fs-errors.js.map +1 -0
- package/dist/shared/fs-walk.d.ts +20 -6
- package/dist/shared/fs-walk.d.ts.map +1 -1
- package/dist/shared/fs-walk.js +35 -27
- package/dist/shared/fs-walk.js.map +1 -1
- package/dist/shared/kb-walk.d.ts +52 -0
- package/dist/shared/kb-walk.d.ts.map +1 -0
- package/dist/shared/kb-walk.js +76 -0
- package/dist/shared/kb-walk.js.map +1 -0
- package/dist/shared/path-order.d.ts +18 -0
- package/dist/shared/path-order.d.ts.map +1 -0
- package/dist/shared/path-order.js +35 -0
- package/dist/shared/path-order.js.map +1 -0
- package/dist/shared/token-crypto.d.ts +17 -2
- package/dist/shared/token-crypto.d.ts.map +1 -1
- package/dist/shared/token-crypto.js +25 -8
- package/dist/shared/token-crypto.js.map +1 -1
- package/dist/shared/ttl-cache.d.ts +28 -1
- package/dist/shared/ttl-cache.d.ts.map +1 -1
- package/dist/shared/ttl-cache.js +33 -1
- package/dist/shared/ttl-cache.js.map +1 -1
- package/kb-template/.bevelignore +1 -1
- package/kb-template/AGENTS.md +95 -30
- package/kb-template/Skills/.gitkeep +0 -0
- package/migrations/0005_github_facade.sql +25 -0
- package/migrations/meta/0005_snapshot.json +1717 -0
- package/migrations/meta/_journal.json +7 -0
- package/package.json +6 -6
- package/src/__tests__/core-config.admin.test.ts +21 -0
- package/src/__tests__/kb-layout-config.test.ts +110 -0
- package/src/core/__tests__/catalog-cache-invalidation.test.ts +146 -0
- package/src/core/catalog-cache-invalidation.ts +92 -0
- package/src/core/create-core-server.ts +126 -7
- package/src/core/create-core-services.ts +173 -41
- package/src/core-config.ts +14 -7
- package/src/modules/access/__tests__/access-control.invalidate-race.test.ts +86 -0
- package/src/modules/access/__tests__/access-control.service.test.ts +19 -3
- package/src/modules/access/__tests__/access-plugin-principals.test.ts +368 -0
- package/src/modules/access/__tests__/groups-admin.service.test.ts +8 -0
- package/src/modules/access/access-control.interface.ts +20 -9
- package/src/modules/access/access-control.service.ts +240 -78
- package/src/modules/access/access.routes.ts +96 -14
- package/src/modules/access-model/__tests__/access-grammar.test.ts +18 -0
- package/src/modules/access-model/__tests__/plugin-token-canonical.test.ts +40 -0
- package/src/modules/access-model/access-grammar.ts +114 -2
- package/src/modules/access-model/group-files.ts +4 -0
- package/src/modules/access-model/kb-read-filter.ts +22 -0
- package/src/modules/access-model/plugin-principals.ts +137 -0
- package/src/modules/connection-probe/__tests__/connection-probe.service.test.ts +685 -0
- package/src/modules/connection-probe/connection-probe.contract.ts +44 -0
- package/src/modules/connection-probe/connection-probe.service.ts +734 -0
- package/src/modules/connection-probe/index.ts +2 -0
- package/src/modules/database/core-schema.ts +54 -0
- package/src/modules/diff/diff.routes.ts +9 -5
- package/src/modules/kb-fs/__tests__/mutex.test.ts +107 -0
- package/src/modules/kb-fs/mutex.ts +50 -5
- package/src/modules/kb-sync/__tests__/kb-sync.routes.test.ts +297 -0
- package/src/modules/kb-sync/__tests__/kb-sync.service.test.ts +295 -0
- package/src/modules/kb-sync/__tests__/sync-auth.test.ts +118 -0
- package/src/modules/kb-sync/__tests__/sync-payload.test.ts +148 -0
- package/src/modules/kb-sync/index.ts +19 -0
- package/src/modules/kb-sync/kb-sync.interface.ts +79 -0
- package/src/modules/kb-sync/kb-sync.routes.ts +197 -0
- package/src/modules/kb-sync/kb-sync.service.ts +201 -0
- package/src/modules/kb-sync/sync-auth.ts +118 -0
- package/src/modules/kb-sync/sync-payload.ts +143 -0
- package/src/modules/marketplace/__tests__/github-facade.test.ts +443 -0
- package/src/modules/marketplace/__tests__/marketplace-git.test.ts +179 -0
- package/src/modules/marketplace/git-http.routes.ts +193 -0
- package/src/modules/marketplace/github-facade/github-facade-admin.routes.ts +78 -0
- package/src/modules/marketplace/github-facade/github-facade-codes.store.ts +145 -0
- package/src/modules/marketplace/github-facade/github-facade-credentials.service.ts +208 -0
- package/src/modules/marketplace/github-facade/github-facade.routes.ts +268 -0
- package/src/modules/marketplace/github-facade/github-facade.service.ts +221 -0
- package/src/modules/marketplace/github-facade/index.ts +25 -0
- package/src/modules/marketplace/index.ts +3 -0
- package/src/modules/marketplace/marketplace-repo.service.ts +337 -0
- package/src/modules/mcp/oauth/bevel-oauth-provider.ts +3 -0
- package/src/modules/mcp/oauth/oauth-consent.routes.ts +24 -2
- package/src/modules/mcp/oauth/oauth-state.ts +15 -3
- package/src/modules/plugins/__tests__/bundle-dialect.e2e.test.ts +163 -0
- package/src/modules/plugins/__tests__/compile-marketplace.test.ts +294 -0
- package/src/modules/plugins/__tests__/plugin-index.service.test.ts +56 -12
- package/src/modules/plugins/__tests__/plugin-links.service.test.ts +287 -0
- package/src/modules/plugins/__tests__/plugin-provision.service.test.ts +205 -5
- package/src/modules/plugins/__tests__/plugin-rename.service.test.ts +394 -0
- package/src/modules/plugins/__tests__/plugins.routes.test.ts +80 -33
- package/src/modules/plugins/compile/compile-marketplace.ts +403 -0
- package/src/modules/plugins/compile/marketplace-compiler.service.ts +150 -0
- package/src/modules/plugins/discovery/__tests__/kb-plugin-source.test.ts +329 -0
- package/src/modules/plugins/discovery/bundle-dialect/bundle.source.ts +140 -0
- package/src/modules/plugins/discovery/bundle-dialect/registry.ts +175 -0
- package/src/modules/plugins/discovery/kb-plugin-source.ts +114 -0
- package/src/modules/plugins/discovery/native.source.ts +122 -0
- package/src/modules/plugins/discovery/plugin-source.ts +99 -0
- package/src/modules/plugins/index.ts +10 -0
- package/src/modules/plugins/plugin-links.service.ts +363 -0
- package/src/modules/plugins/plugin-links.ts +184 -0
- package/src/modules/plugins/plugin-provision.service.ts +160 -54
- package/src/modules/plugins/plugin-rename.service.ts +298 -0
- package/src/modules/plugins/plugins.contract.ts +28 -1
- package/src/modules/plugins/plugins.routes.ts +128 -11
- package/src/modules/plugins/plugins.service.ts +106 -53
- package/src/modules/secrets-vault/__tests__/connect-pending.route.test.ts +12 -0
- package/src/modules/secrets-vault/__tests__/oauth-return-to.route.test.ts +10 -3
- package/src/modules/secrets-vault/__tests__/tool-owner-gate.route.test.ts +26 -0
- package/src/modules/secrets-vault/db-secrets-vault.service.ts +1 -1
- package/src/modules/secrets-vault/secrets-vault.routes.ts +35 -1
- package/src/modules/settings/__tests__/deployment-settings.service.test.ts +57 -0
- package/src/modules/settings/__tests__/setup.routes.sync-status.test.ts +77 -0
- package/src/modules/settings/deployment-settings.service.ts +95 -2
- package/src/modules/settings/setup.routes.ts +24 -0
- package/src/modules/skills/__tests__/skill-access-requests.routes.test.ts +128 -0
- package/src/modules/skills/__tests__/skills.service.test.ts +85 -0
- package/src/modules/skills/index.ts +1 -0
- package/src/modules/skills/pending-skills.service.ts +7 -5
- package/src/modules/skills/skill-access-requests.routes.ts +199 -0
- package/src/modules/skills/skills.contract.ts +32 -0
- package/src/modules/skills/skills.routes.ts +59 -3
- package/src/modules/skills/skills.service.ts +84 -22
- package/src/modules/tool-auth/external-api-key.interface.ts +20 -1
- package/src/modules/tool-auth/external-api-key.service.ts +31 -13
- package/src/modules/tool-manuals/__tests__/mcp-json-discovery.test.ts +35 -1
- package/src/modules/tool-manuals/__tests__/tool-manuals.cli.test.ts +2 -0
- package/src/modules/tool-manuals/__tests__/tool-manuals.health-check.test.ts +104 -0
- package/src/modules/tool-manuals/__tests__/tool-manuals.service.test.ts +56 -0
- package/src/modules/tool-manuals/mcp-json-discovery.ts +154 -76
- package/src/modules/tool-manuals/mcp-server-edit.service.ts +13 -4
- package/src/modules/tool-manuals/tool-manuals.contract.ts +89 -0
- package/src/modules/tool-manuals/tool-manuals.service.ts +210 -37
- package/src/modules/workflow/__tests__/preserve-roles-yaml.test.ts +1 -1
- package/src/modules/workflow/__tests__/workflow.routes.history-read-gate.test.ts +139 -0
- package/src/modules/workflow/__tests__/workflow.service.branch-in-use.test.ts +337 -0
- package/src/modules/workflow/__tests__/workflow.service.commitFileWhileLocked.test.ts +1 -0
- package/src/modules/workflow/__tests__/workflow.service.deleted-branch-sweep.test.ts +7 -1
- package/src/modules/workflow/__tests__/workflow.service.facade.test.ts +97 -10
- package/src/modules/workflow/__tests__/workflow.service.releaseLock.test.ts +119 -2
- package/src/modules/workflow/__tests__/workflow.service.sync.test.ts +437 -0
- package/src/modules/workflow/git/__tests__/git.service.history-guards.test.ts +86 -0
- package/src/modules/workflow/git/__tests__/git.service.postMergePull.test.ts +3 -3
- package/src/modules/workflow/git/__tests__/git.service.pull.test.ts +47 -4
- package/src/modules/workflow/git/__tests__/git.service.syncFromRemote.test.ts +253 -0
- package/src/modules/workflow/git/git.service.ts +354 -63
- package/src/modules/workflow/git/pull-request.service.ts +9 -0
- package/src/modules/workflow/workflow.routes.ts +104 -4
- package/src/modules/workflow/workflow.service.ts +505 -64
- package/src/modules/workspace/__tests__/workspace.routes.read-gate.test.ts +6 -7
- package/src/modules/workspace/__tests__/workspace.service.list-cloned.test.ts +93 -0
- package/src/modules/workspace/__tests__/workspace.service.missing-branch.test.ts +28 -0
- package/src/modules/workspace/__tests__/workspace.service.read-filter.test.ts +42 -12
- package/src/modules/workspace/startup/steps/__tests__/steps.test.ts +219 -4
- package/src/modules/workspace/startup/steps/plugin-manifests.step.ts +129 -0
- package/src/modules/workspace/startup/steps/seed-tree.ts +44 -2
- package/src/modules/workspace/startup/steps/template-files.step.ts +131 -27
- package/src/modules/workspace/workspace.routes.ts +17 -21
- package/src/modules/workspace/workspace.service.ts +128 -19
- package/src/shared/__tests__/filename.test.ts +0 -0
- package/src/shared/__tests__/fs-walk.test.ts +22 -1
- package/src/shared/__tests__/kb-walk.test.ts +107 -0
- package/src/shared/__tests__/path-order.test.ts +24 -0
- package/src/shared/__tests__/token-crypto.test.ts +34 -0
- package/src/shared/__tests__/ttl-cache.test.ts +55 -0
- package/src/shared/domain-errors.ts +29 -0
- package/src/shared/fs-errors.ts +10 -0
- package/src/shared/fs-walk.ts +38 -23
- package/src/shared/kb-walk.ts +95 -0
- package/src/shared/path-order.ts +33 -0
- package/src/shared/token-crypto.ts +28 -10
- package/src/shared/ttl-cache.ts +33 -1
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { createHash, randomBytes, timingSafeEqual } from 'node:crypto';
|
|
2
|
+
import { signAuthRequest } from '../../mcp/oauth/oauth-state.js';
|
|
3
|
+
/**
|
|
4
|
+
* The KIND stored on a connection key minted through the facade, and the
|
|
5
|
+
* plaintext prefix that kind is minted with. `gho_` is what a GitHub OAuth
|
|
6
|
+
* token looks like — the shape a consumer expecting a GitHub Enterprise host
|
|
7
|
+
* accepts; the key is otherwise an ordinary connection key — hashed at rest,
|
|
8
|
+
* revocable from the person's external-agent page, accepted by every surface
|
|
9
|
+
* a connection key is. The kind, not the label, is what tells such a key
|
|
10
|
+
* apart: a label is the person's to edit.
|
|
11
|
+
*/
|
|
12
|
+
export const GITHUB_LINK_KEY_KIND = 'github-link';
|
|
13
|
+
export const GITHUB_LINK_KEY_PREFIX = 'gho_';
|
|
14
|
+
/** claude.ai and Cowork: the consumer this facade was built against. */
|
|
15
|
+
export const CLAUDE_CONSUMER = {
|
|
16
|
+
id: 'claude',
|
|
17
|
+
name: 'Claude',
|
|
18
|
+
redirectHosts: ['claude.ai'],
|
|
19
|
+
keyLabel: 'Claude (claude.ai and Cowork)',
|
|
20
|
+
};
|
|
21
|
+
const CODE_TTL_MS = 10 * 60_000;
|
|
22
|
+
const CODE_BYTES = 10;
|
|
23
|
+
export class GitHubFacadeRequestError extends Error {
|
|
24
|
+
status;
|
|
25
|
+
code;
|
|
26
|
+
constructor(status, code, message) {
|
|
27
|
+
super(message);
|
|
28
|
+
this.status = status;
|
|
29
|
+
this.code = code;
|
|
30
|
+
this.name = 'GitHubFacadeRequestError';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The "connect your GitHub Enterprise account" flow, as a consumer such as claude.ai drives it
|
|
35
|
+
* against a GitHub Enterprise host — with hexis standing where GitHub would.
|
|
36
|
+
*
|
|
37
|
+
* 1. The browser lands on `/login/oauth/authorize?client_id&redirect_uri&state`.
|
|
38
|
+
* We check the client id is ours and the redirect goes to claude.ai,
|
|
39
|
+
* pack the request into the SAME signed state the MCP authorization
|
|
40
|
+
* flow uses, and send the browser to the SPA's `/connect` page — where a
|
|
41
|
+
* hexis session (or a sign-in) attaches a person to the request.
|
|
42
|
+
* 2. Finish on that page comes back through the consent routes with the
|
|
43
|
+
* state; {@link completeConsent} stores a one-time code bound to that
|
|
44
|
+
* person and returns the callback URL carrying it.
|
|
45
|
+
* 3. Anthropic's backend posts the code with our client id and secret to
|
|
46
|
+
* `/login/oauth/access_token`; {@link exchangeCode} turns it into a
|
|
47
|
+
* connection key for that person — the token every later fetch carries.
|
|
48
|
+
*
|
|
49
|
+
* Nothing here is remembered in the process: credentials and codes are read
|
|
50
|
+
* from their stores on every step, so the replica that issued a code and the
|
|
51
|
+
* replica that exchanges it need not be the same one.
|
|
52
|
+
*/
|
|
53
|
+
export class GitHubFacade {
|
|
54
|
+
deps;
|
|
55
|
+
constructor(deps) {
|
|
56
|
+
this.deps = deps;
|
|
57
|
+
}
|
|
58
|
+
/** Where to send the browser for an authorize request, or a 4xx to answer with. */
|
|
59
|
+
async authorizeRedirect(query) {
|
|
60
|
+
const clientId = str(query.client_id);
|
|
61
|
+
const redirectUri = str(query.redirect_uri);
|
|
62
|
+
const state = str(query.state);
|
|
63
|
+
const creds = await this.deps.credentials.ensure();
|
|
64
|
+
if (!clientId || !safeEqual(clientId, creds.clientId)) {
|
|
65
|
+
throw new GitHubFacadeRequestError(400, 'unknown_client', 'Unknown client_id.');
|
|
66
|
+
}
|
|
67
|
+
if (!this.consumerFor(redirectUri)) {
|
|
68
|
+
throw new GitHubFacadeRequestError(400, 'invalid_redirect', 'redirect_uri does not belong to a known consumer.');
|
|
69
|
+
}
|
|
70
|
+
const signed = signAuthRequest(this.deps.stateSecret, {
|
|
71
|
+
c: clientId,
|
|
72
|
+
r: redirectUri,
|
|
73
|
+
s: state || undefined,
|
|
74
|
+
gh: true,
|
|
75
|
+
});
|
|
76
|
+
const url = new URL('/connect', this.deps.publicFrontendUrl);
|
|
77
|
+
url.searchParams.set('oauth', signed);
|
|
78
|
+
return url.toString();
|
|
79
|
+
}
|
|
80
|
+
/** True when a verified state is one of ours (a GitHub-shaped link, not an MCP client). */
|
|
81
|
+
isFacadeRequest(st) {
|
|
82
|
+
return st.gh === true;
|
|
83
|
+
}
|
|
84
|
+
/** What the consent page should say is asking, for one of our states. */
|
|
85
|
+
clientNameFor(st) {
|
|
86
|
+
return this.consumerFor(st.r)?.name ?? 'an external product';
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* The person approved on `/connect`: a one-time code for them, and the
|
|
90
|
+
* claude.ai callback to send the browser to. Supersedes any live code the
|
|
91
|
+
* same person already had for this client.
|
|
92
|
+
*/
|
|
93
|
+
async completeConsent(userId, st) {
|
|
94
|
+
const creds = await this.deps.credentials.ensure();
|
|
95
|
+
if (!safeEqual(st.c, creds.clientId) || !this.consumerFor(st.r)) {
|
|
96
|
+
throw new GitHubFacadeRequestError(400, 'invalid_request', 'The authorization request is not one of ours.');
|
|
97
|
+
}
|
|
98
|
+
const code = randomBytes(CODE_BYTES).toString('hex');
|
|
99
|
+
await this.deps.codes.put({
|
|
100
|
+
codeHash: hashCode(code),
|
|
101
|
+
userId,
|
|
102
|
+
clientId: st.c,
|
|
103
|
+
redirectUri: st.r,
|
|
104
|
+
expiresAt: new Date(Date.now() + CODE_TTL_MS),
|
|
105
|
+
});
|
|
106
|
+
const url = new URL(st.r);
|
|
107
|
+
url.searchParams.set('code', code);
|
|
108
|
+
if (st.s)
|
|
109
|
+
url.searchParams.set('state', st.s);
|
|
110
|
+
return { redirectTo: url.toString() };
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* The token exchange. Client id and secret must be ours and the code live;
|
|
114
|
+
* every check runs BEFORE the code is spent, so a request that is wrong
|
|
115
|
+
* about something else (its redirect, say) can be corrected and retried.
|
|
116
|
+
* Spending is one conditional update in the store — the first exchange
|
|
117
|
+
* wins, on whichever replica, and only the winner mints.
|
|
118
|
+
*/
|
|
119
|
+
async exchangeCode(body) {
|
|
120
|
+
const creds = await this.deps.credentials.ensure();
|
|
121
|
+
const clientId = str(body.client_id);
|
|
122
|
+
const clientSecret = str(body.client_secret);
|
|
123
|
+
const code = str(body.code);
|
|
124
|
+
if (!clientId || !clientSecret || !safeEqual(clientId, creds.clientId) || !safeEqual(clientSecret, creds.clientSecret)) {
|
|
125
|
+
throw new GitHubFacadeRequestError(401, 'incorrect_client_credentials', 'The client_id and/or client_secret passed are incorrect.');
|
|
126
|
+
}
|
|
127
|
+
const pending = code ? await this.deps.codes.peek(hashCode(code)) : null;
|
|
128
|
+
if (!pending || pending.clientId !== clientId) {
|
|
129
|
+
throw new GitHubFacadeRequestError(400, 'bad_verification_code', 'The code passed is incorrect or expired.');
|
|
130
|
+
}
|
|
131
|
+
const redirectUri = str(body.redirect_uri);
|
|
132
|
+
if (redirectUri && redirectUri !== pending.redirectUri) {
|
|
133
|
+
throw new GitHubFacadeRequestError(400, 'redirect_uri_mismatch', 'The redirect_uri does not match the authorization.');
|
|
134
|
+
}
|
|
135
|
+
const spent = await this.deps.codes.consume(pending.codeHash);
|
|
136
|
+
if (!spent) {
|
|
137
|
+
throw new GitHubFacadeRequestError(400, 'bad_verification_code', 'The code passed is incorrect or expired.');
|
|
138
|
+
}
|
|
139
|
+
// The consumer is the one the code was issued for — the redirect the
|
|
140
|
+
// person approved names it — so the key is labelled for that product.
|
|
141
|
+
const consumer = this.consumerFor(spent.redirectUri);
|
|
142
|
+
const minted = await this.deps.keys.mint(spent.userId, consumer?.keyLabel ?? 'GitHub-compatible link', {
|
|
143
|
+
kind: GITHUB_LINK_KEY_KIND,
|
|
144
|
+
});
|
|
145
|
+
return { access_token: minted.plaintext, token_type: 'bearer', scope: '' };
|
|
146
|
+
}
|
|
147
|
+
/** The consumer whose callback a redirect_uri is, or null — https only, host exactly. */
|
|
148
|
+
consumerFor(redirectUri) {
|
|
149
|
+
let parsed;
|
|
150
|
+
try {
|
|
151
|
+
parsed = new URL(redirectUri);
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
if (parsed.protocol !== 'https:')
|
|
157
|
+
return null;
|
|
158
|
+
return this.deps.consumers.find((c) => c.redirectHosts.includes(parsed.hostname)) ?? null;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function hashCode(code) {
|
|
162
|
+
return createHash('sha256').update(code).digest('hex');
|
|
163
|
+
}
|
|
164
|
+
function str(v) {
|
|
165
|
+
return typeof v === 'string' ? v : '';
|
|
166
|
+
}
|
|
167
|
+
function safeEqual(a, b) {
|
|
168
|
+
const ab = Buffer.from(a);
|
|
169
|
+
const bb = Buffer.from(b);
|
|
170
|
+
return ab.length === bb.length && timingSafeEqual(ab, bb);
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=github-facade.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"github-facade.service.js","sourceRoot":"","sources":["../../../../src/modules/marketplace/github-facade/github-facade.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEvE,OAAO,EAAE,eAAe,EAA4B,MAAM,gCAAgC,CAAC;AAI3F;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,aAAa,CAAC;AAClD,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC;AAqB7C,wEAAwE;AACxE,MAAM,CAAC,MAAM,eAAe,GAAyB;IACnD,EAAE,EAAE,QAAQ;IACZ,IAAI,EAAE,QAAQ;IACd,aAAa,EAAE,CAAC,WAAW,CAAC;IAC5B,QAAQ,EAAE,+BAA+B;CAC1C,CAAC;AAEF,MAAM,WAAW,GAAG,EAAE,GAAG,MAAM,CAAC;AAChC,MAAM,UAAU,GAAG,EAAE,CAAC;AAkBtB,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IAEtC;IACA;IAFX,YACW,MAAc,EACd,IAAY,EACrB,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAC;QAJN,WAAM,GAAN,MAAM,CAAQ;QACd,SAAI,GAAJ,IAAI,CAAQ;QAIrB,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;IACzC,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,OAAO,YAAY;IACM;IAA7B,YAA6B,IAAs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C;AAED,SAAS,GAAG,CAAC,CAAU;IACrB,OAAO,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACxC,CAAC;AAED,SAAS,SAAS,CAAC,CAAS,EAAE,CAAS;IACrC,MAAM,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC1B,MAAM,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC1B,OAAO,EAAE,CAAC,MAAM,KAAK,EAAE,CAAC,MAAM,IAAI,eAAe,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;AAC5D,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { GitHubFacadeCredentialsService, DbGitHubFacadeCredentialsStore, MemoryGitHubFacadeCredentialsStore, GitHubFacadeUnavailableError, type GitHubFacadeCredentials, type GitHubFacadeCredentialsStore, } from './github-facade-credentials.service.js';
|
|
2
|
+
export { DbGitHubFacadeCodeStore, MemoryGitHubFacadeCodeStore, type GitHubFacadeCodeStore, type PendingFacadeCode, } from './github-facade-codes.store.js';
|
|
3
|
+
export { GitHubFacade, GitHubFacadeRequestError, GITHUB_LINK_KEY_KIND, GITHUB_LINK_KEY_PREFIX, CLAUDE_CONSUMER, type GitHubFacadeConsumer, type GitHubFacadeDeps, } from './github-facade.service.js';
|
|
4
|
+
export { createGitHubFacadeRoutes, type GitHubFacadeRoutesDeps } from './github-facade.routes.js';
|
|
5
|
+
export { createGitHubFacadeAdminRoutes, type GitHubFacadeAdminRoutesDeps } from './github-facade-admin.routes.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/modules/marketplace/github-facade/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,8BAA8B,EAC9B,8BAA8B,EAC9B,kCAAkC,EAClC,4BAA4B,EAC5B,KAAK,uBAAuB,EAC5B,KAAK,4BAA4B,GAClC,MAAM,wCAAwC,CAAC;AAChD,OAAO,EACL,uBAAuB,EACvB,2BAA2B,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,GACvB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,YAAY,EACZ,wBAAwB,EACxB,oBAAoB,EACpB,sBAAsB,EACtB,eAAe,EACf,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,GACtB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,wBAAwB,EAAE,KAAK,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAClG,OAAO,EAAE,6BAA6B,EAAE,KAAK,2BAA2B,EAAE,MAAM,iCAAiC,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { GitHubFacadeCredentialsService, DbGitHubFacadeCredentialsStore, MemoryGitHubFacadeCredentialsStore, GitHubFacadeUnavailableError, } from './github-facade-credentials.service.js';
|
|
2
|
+
export { DbGitHubFacadeCodeStore, MemoryGitHubFacadeCodeStore, } from './github-facade-codes.store.js';
|
|
3
|
+
export { GitHubFacade, GitHubFacadeRequestError, GITHUB_LINK_KEY_KIND, GITHUB_LINK_KEY_PREFIX, CLAUDE_CONSUMER, } from './github-facade.service.js';
|
|
4
|
+
export { createGitHubFacadeRoutes } from './github-facade.routes.js';
|
|
5
|
+
export { createGitHubFacadeAdminRoutes } from './github-facade-admin.routes.js';
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/modules/marketplace/github-facade/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,8BAA8B,EAC9B,8BAA8B,EAC9B,kCAAkC,EAClC,4BAA4B,GAG7B,MAAM,wCAAwC,CAAC;AAChD,OAAO,EACL,uBAAuB,EACvB,2BAA2B,GAG5B,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,YAAY,EACZ,wBAAwB,EACxB,oBAAoB,EACpB,sBAAsB,EACtB,eAAe,GAGhB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,wBAAwB,EAA+B,MAAM,2BAA2B,CAAC;AAClG,OAAO,EAAE,6BAA6B,EAAoC,MAAM,iCAAiC,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { MarketplaceRepoService, type MarketplaceCompiler, type EnsureResult } from './marketplace-repo.service.js';
|
|
2
|
+
export { createMarketplaceGitRoutes, type MarketplaceKeyResolver } from './git-http.routes.js';
|
|
3
|
+
export * from './github-facade/index.js';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/modules/marketplace/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,KAAK,mBAAmB,EAAE,KAAK,YAAY,EAAE,MAAM,+BAA+B,CAAC;AACpH,OAAO,EAAE,0BAA0B,EAAE,KAAK,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC/F,cAAc,0BAA0B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/modules/marketplace/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAA+C,MAAM,+BAA+B,CAAC;AACpH,OAAO,EAAE,0BAA0B,EAA+B,MAAM,sBAAsB,CAAC;AAC/F,cAAc,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { type ChildProcess } from 'node:child_process';
|
|
2
|
+
import type { VirtualTree } from '../plugins/compile/compile-marketplace.js';
|
|
3
|
+
/** What the repo service asks the compiler for — the one seam it has. */
|
|
4
|
+
export interface MarketplaceCompiler {
|
|
5
|
+
sourceCommit(): Promise<string>;
|
|
6
|
+
compileFor(audience: {
|
|
7
|
+
userEmail: string;
|
|
8
|
+
},
|
|
9
|
+
/** The commit the tree is compiled from, when the caller already read it. */
|
|
10
|
+
sourceCommit?: string): Promise<VirtualTree & {
|
|
11
|
+
sourceCommit: string;
|
|
12
|
+
}>;
|
|
13
|
+
}
|
|
14
|
+
export interface EnsureResult {
|
|
15
|
+
/** The git namespace the caller's tree lives in. */
|
|
16
|
+
namespace: string;
|
|
17
|
+
/** True when a new commit was written this call. */
|
|
18
|
+
compiled: boolean;
|
|
19
|
+
sourceCommit: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* ONE bare repository, ONE git namespace per caller.
|
|
23
|
+
*
|
|
24
|
+
* Every person's compiled marketplace is a branch in its own namespace
|
|
25
|
+
* (`refs/namespaces/<ns>/refs/heads/main`), which is exactly what git
|
|
26
|
+
* namespaces exist for (gitnamespaces(7)): `git http-backend` run with
|
|
27
|
+
* `GIT_NAMESPACE=<ns>` advertises only that namespace's refs, so a clone sees
|
|
28
|
+
* a repository whose `main` is their tree and nothing else — while every
|
|
29
|
+
* identical skill across callers is one blob in one object store.
|
|
30
|
+
*
|
|
31
|
+
* Freshness is LAZY and keyed on the knowledge base's default-branch commit:
|
|
32
|
+
* every input to a compile (skills, manifests, access rules, roles, groups)
|
|
33
|
+
* lives in that repository, so "same source commit" means "same answer".
|
|
34
|
+
* The last compiled source per namespace sits in a sidecar file rather than
|
|
35
|
+
* a commit trailer, so an unchanged tree costs no commit and no re-check.
|
|
36
|
+
*
|
|
37
|
+
* Each recompile appends a commit whose parent is the namespace's current
|
|
38
|
+
* head, so a client's `git pull` is always a fast-forward — including when
|
|
39
|
+
* access was withdrawn and files vanish. Writes go through git plumbing
|
|
40
|
+
* against a temporary index: no working tree of the bare repo, no checkout.
|
|
41
|
+
*
|
|
42
|
+
* Read-only by construction: `http.receivepack` is pinned off (http-backend
|
|
43
|
+
* would otherwise enable pushes for an authenticated REMOTE_USER), and the
|
|
44
|
+
* route refuses the receive-pack service before git ever sees it.
|
|
45
|
+
*/
|
|
46
|
+
export declare class MarketplaceRepoService {
|
|
47
|
+
/** Absolute path of the bare repository (created on first use). */
|
|
48
|
+
readonly repoDir: string;
|
|
49
|
+
private readonly compiler;
|
|
50
|
+
private readonly committer;
|
|
51
|
+
private readonly locks;
|
|
52
|
+
private initialised;
|
|
53
|
+
constructor(
|
|
54
|
+
/** Absolute path of the bare repository (created on first use). */
|
|
55
|
+
repoDir: string, compiler: MarketplaceCompiler, committer?: {
|
|
56
|
+
name: string;
|
|
57
|
+
email: string;
|
|
58
|
+
});
|
|
59
|
+
/** The directory `GIT_PROJECT_ROOT` points at, and the repo's name under it. */
|
|
60
|
+
get projectRoot(): string;
|
|
61
|
+
get repoName(): string;
|
|
62
|
+
/** The namespace for a user id — one path segment, stable, opaque. */
|
|
63
|
+
static namespaceFor(userId: string): string;
|
|
64
|
+
ensureRepo(): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Bring the caller's namespace up to the knowledge base's current commit,
|
|
67
|
+
* compiling only when it moved. Serialised per namespace: two fetches
|
|
68
|
+
* arriving together compile once.
|
|
69
|
+
*/
|
|
70
|
+
ensureCompiled(user: {
|
|
71
|
+
id: string;
|
|
72
|
+
email: string;
|
|
73
|
+
}): Promise<EnsureResult>;
|
|
74
|
+
/**
|
|
75
|
+
* The caller's namespace and its head commit, compiled if stale — what the
|
|
76
|
+
* GitHub-shaped REST surface (the Cowork path) reads instead of cloning.
|
|
77
|
+
*/
|
|
78
|
+
headFor(user: {
|
|
79
|
+
id: string;
|
|
80
|
+
email: string;
|
|
81
|
+
}): Promise<{
|
|
82
|
+
namespace: string;
|
|
83
|
+
sha: string;
|
|
84
|
+
}>;
|
|
85
|
+
/** One commit as the REST surface describes it. */
|
|
86
|
+
describeCommit(sha: string): Promise<{
|
|
87
|
+
sha: string;
|
|
88
|
+
tree: string;
|
|
89
|
+
message: string;
|
|
90
|
+
authorName: string;
|
|
91
|
+
authorEmail: string;
|
|
92
|
+
date: string;
|
|
93
|
+
}>;
|
|
94
|
+
/**
|
|
95
|
+
* Whether `sha` is the namespace's head or one of its ancestors — the only
|
|
96
|
+
* commits a caller may read as that namespace. The object store is shared
|
|
97
|
+
* across everyone, so a sha alone is never enough.
|
|
98
|
+
*/
|
|
99
|
+
contains(namespace: string, sha: string): Promise<boolean>;
|
|
100
|
+
/** The tree at `sha` as a zip stream, every path under `prefix/`. Check {@link contains} first. */
|
|
101
|
+
archiveZip(sha: string, prefix: string): ChildProcess;
|
|
102
|
+
private refOf;
|
|
103
|
+
private headOf;
|
|
104
|
+
/**
|
|
105
|
+
* Write `tree` as a commit on the namespace's branch. Materialises the
|
|
106
|
+
* virtual tree into a scratch directory, stages it into a throwaway index
|
|
107
|
+
* against the bare object store, and commits — no working tree involved.
|
|
108
|
+
* When the tree hash equals the head's, nothing is committed.
|
|
109
|
+
*/
|
|
110
|
+
private commitTree;
|
|
111
|
+
/**
|
|
112
|
+
* Point the namespace's HEAD at its branch — valid before the branch
|
|
113
|
+
* exists. A read first: the symref is written only when absent or wrong,
|
|
114
|
+
* so the common path touches nothing.
|
|
115
|
+
*/
|
|
116
|
+
private ensureHead;
|
|
117
|
+
private sidecarDir;
|
|
118
|
+
private readSidecar;
|
|
119
|
+
private writeSidecar;
|
|
120
|
+
private git;
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=marketplace-repo.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"marketplace-repo.service.d.ts","sourceRoot":"","sources":["../../../src/modules/marketplace/marketplace-repo.service.ts"],"names":[],"mappings":"AAGA,OAAO,EAAmB,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGxE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2CAA2C,CAAC;AAI7E,yEAAyE;AACzE,MAAM,WAAW,mBAAmB;IAClC,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAChC,UAAU,CACR,QAAQ,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;K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MAAM,CAAA;KAAE,CAAC;IAO/F,mDAAmD;IAC7C,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;QACzC,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,UAAU,EAAE,MAAM,CAAC;QACnB,WAAW,EAAE,MAAM,CAAC;QACpB,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IAcF;;;;OAIG;IACG,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAwBhE,mGAAmG;IACnG,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,YAAY;IASrD,OAAO,CAAC,KAAK;YAIC,MAAM;IASpB;;;;;OAKG;YACW,UAAU;IAoDxB;;;;OAIG;YACW,UAAU;IAUxB,OAAO,CAAC,UAAU;YAIJ,WAAW;YAQX,YAAY;IAI1B,OAAO,CAAC,GAAG;CAGZ"}
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { execFile, spawn } from 'node:child_process';
|
|
5
|
+
import { promisify } from 'node:util';
|
|
6
|
+
import { WorkspaceMutex } from '../kb-fs/mutex.js';
|
|
7
|
+
const execFileAsync = promisify(execFile);
|
|
8
|
+
/**
|
|
9
|
+
* ONE bare repository, ONE git namespace per caller.
|
|
10
|
+
*
|
|
11
|
+
* Every person's compiled marketplace is a branch in its own namespace
|
|
12
|
+
* (`refs/namespaces/<ns>/refs/heads/main`), which is exactly what git
|
|
13
|
+
* namespaces exist for (gitnamespaces(7)): `git http-backend` run with
|
|
14
|
+
* `GIT_NAMESPACE=<ns>` advertises only that namespace's refs, so a clone sees
|
|
15
|
+
* a repository whose `main` is their tree and nothing else — while every
|
|
16
|
+
* identical skill across callers is one blob in one object store.
|
|
17
|
+
*
|
|
18
|
+
* Freshness is LAZY and keyed on the knowledge base's default-branch commit:
|
|
19
|
+
* every input to a compile (skills, manifests, access rules, roles, groups)
|
|
20
|
+
* lives in that repository, so "same source commit" means "same answer".
|
|
21
|
+
* The last compiled source per namespace sits in a sidecar file rather than
|
|
22
|
+
* a commit trailer, so an unchanged tree costs no commit and no re-check.
|
|
23
|
+
*
|
|
24
|
+
* Each recompile appends a commit whose parent is the namespace's current
|
|
25
|
+
* head, so a client's `git pull` is always a fast-forward — including when
|
|
26
|
+
* access was withdrawn and files vanish. Writes go through git plumbing
|
|
27
|
+
* against a temporary index: no working tree of the bare repo, no checkout.
|
|
28
|
+
*
|
|
29
|
+
* Read-only by construction: `http.receivepack` is pinned off (http-backend
|
|
30
|
+
* would otherwise enable pushes for an authenticated REMOTE_USER), and the
|
|
31
|
+
* route refuses the receive-pack service before git ever sees it.
|
|
32
|
+
*/
|
|
33
|
+
export class MarketplaceRepoService {
|
|
34
|
+
repoDir;
|
|
35
|
+
compiler;
|
|
36
|
+
committer;
|
|
37
|
+
locks = new WorkspaceMutex();
|
|
38
|
+
initialised = null;
|
|
39
|
+
constructor(
|
|
40
|
+
/** Absolute path of the bare repository (created on first use). */
|
|
41
|
+
repoDir, compiler, committer = {
|
|
42
|
+
name: 'Hexis',
|
|
43
|
+
email: 'hexis@localhost',
|
|
44
|
+
}) {
|
|
45
|
+
this.repoDir = repoDir;
|
|
46
|
+
this.compiler = compiler;
|
|
47
|
+
this.committer = committer;
|
|
48
|
+
}
|
|
49
|
+
/** The directory `GIT_PROJECT_ROOT` points at, and the repo's name under it. */
|
|
50
|
+
get projectRoot() {
|
|
51
|
+
return path.dirname(this.repoDir);
|
|
52
|
+
}
|
|
53
|
+
get repoName() {
|
|
54
|
+
return path.basename(this.repoDir);
|
|
55
|
+
}
|
|
56
|
+
/** The namespace for a user id — one path segment, stable, opaque. */
|
|
57
|
+
static namespaceFor(userId) {
|
|
58
|
+
return `u-${userId.replace(/[^A-Za-z0-9._-]+/g, '_').slice(0, 120)}`;
|
|
59
|
+
}
|
|
60
|
+
async ensureRepo() {
|
|
61
|
+
this.initialised ??= (async () => {
|
|
62
|
+
await fs.mkdir(this.projectRoot, { recursive: true });
|
|
63
|
+
const isRepo = await fs
|
|
64
|
+
.access(path.join(this.repoDir, 'HEAD'))
|
|
65
|
+
.then(() => true, () => false);
|
|
66
|
+
if (!isRepo)
|
|
67
|
+
await this.git(['init', '--bare', '--quiet', this.repoDir]);
|
|
68
|
+
await this.git(['-C', this.repoDir, 'config', 'http.receivepack', 'false']);
|
|
69
|
+
await this.git(['-C', this.repoDir, 'config', 'http.uploadpack', 'true']);
|
|
70
|
+
await fs.mkdir(this.sidecarDir(), { recursive: true });
|
|
71
|
+
})().catch((err) => {
|
|
72
|
+
// A failed initialisation is retried by the next request, not
|
|
73
|
+
// remembered until restart: a volume that was briefly unavailable must
|
|
74
|
+
// not turn every later fetch into a 500.
|
|
75
|
+
this.initialised = null;
|
|
76
|
+
throw err;
|
|
77
|
+
});
|
|
78
|
+
await this.initialised;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Bring the caller's namespace up to the knowledge base's current commit,
|
|
82
|
+
* compiling only when it moved. Serialised per namespace: two fetches
|
|
83
|
+
* arriving together compile once.
|
|
84
|
+
*/
|
|
85
|
+
async ensureCompiled(user) {
|
|
86
|
+
await this.ensureRepo();
|
|
87
|
+
const namespace = MarketplaceRepoService.namespaceFor(user.id);
|
|
88
|
+
return this.locks.run(`ns:${namespace}`, async () => {
|
|
89
|
+
const last = await this.readSidecar(namespace);
|
|
90
|
+
const head = await this.headOf(namespace);
|
|
91
|
+
let current = await this.compiler.sourceCommit();
|
|
92
|
+
if (last === current && head !== null) {
|
|
93
|
+
// Unchanged source is still a served namespace: its HEAD is checked
|
|
94
|
+
// on every fetch (a read) and written only when it is missing, so a
|
|
95
|
+
// crash after an earlier branch update cannot leave a clone that sees
|
|
96
|
+
// no default branch — and the cache hit stays a read on a healthy repo.
|
|
97
|
+
await this.ensureHead(namespace);
|
|
98
|
+
return { namespace, compiled: false, sourceCommit: current };
|
|
99
|
+
}
|
|
100
|
+
// The commit just read is the one the tree is stamped with: a second
|
|
101
|
+
// read that failed would otherwise record a placeholder as the compiled
|
|
102
|
+
// source and make every later fetch recompile. And the checkout can
|
|
103
|
+
// move WHILE we compile from it (a merge landing mid-read), so the
|
|
104
|
+
// commit is re-read afterwards: a tree stamped with a commit it was
|
|
105
|
+
// not compiled from would freeze that caller on a stale tree until the
|
|
106
|
+
// next change. Bounded — a checkout that moves on every attempt is
|
|
107
|
+
// served the latest attempt rather than never.
|
|
108
|
+
let tree = await this.compiler.compileFor({ userEmail: user.email }, current);
|
|
109
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
110
|
+
const after = await this.compiler.sourceCommit();
|
|
111
|
+
if (after === current)
|
|
112
|
+
break;
|
|
113
|
+
current = after;
|
|
114
|
+
tree = await this.compiler.compileFor({ userEmail: user.email }, current);
|
|
115
|
+
}
|
|
116
|
+
const sha = await this.commitTree(namespace, tree, head);
|
|
117
|
+
await this.writeSidecar(namespace, tree.sourceCommit);
|
|
118
|
+
return { namespace, compiled: sha !== head, sourceCommit: tree.sourceCommit };
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* The caller's namespace and its head commit, compiled if stale — what the
|
|
123
|
+
* GitHub-shaped REST surface (the Cowork path) reads instead of cloning.
|
|
124
|
+
*/
|
|
125
|
+
async headFor(user) {
|
|
126
|
+
const { namespace } = await this.ensureCompiled(user);
|
|
127
|
+
const sha = await this.headOf(namespace);
|
|
128
|
+
if (!sha)
|
|
129
|
+
throw new Error(`namespace ${namespace} has no head after compiling`);
|
|
130
|
+
return { namespace, sha };
|
|
131
|
+
}
|
|
132
|
+
/** One commit as the REST surface describes it. */
|
|
133
|
+
async describeCommit(sha) {
|
|
134
|
+
assertObjectId(sha);
|
|
135
|
+
const { stdout } = await this.git(['-C', this.repoDir, 'log', '-1', '--format=%H%n%T%n%an%n%ae%n%aI%n%B', sha]);
|
|
136
|
+
const [full, tree, authorName, authorEmail, date, ...rest] = stdout.split('\n');
|
|
137
|
+
return {
|
|
138
|
+
sha: full ?? sha,
|
|
139
|
+
tree: tree ?? '',
|
|
140
|
+
message: rest.join('\n').trim(),
|
|
141
|
+
authorName: authorName ?? '',
|
|
142
|
+
authorEmail: authorEmail ?? '',
|
|
143
|
+
date: date ?? '',
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Whether `sha` is the namespace's head or one of its ancestors — the only
|
|
148
|
+
* commits a caller may read as that namespace. The object store is shared
|
|
149
|
+
* across everyone, so a sha alone is never enough.
|
|
150
|
+
*/
|
|
151
|
+
async contains(namespace, sha) {
|
|
152
|
+
if (!looksLikeObjectId(sha))
|
|
153
|
+
return false;
|
|
154
|
+
const head = await this.headOf(namespace);
|
|
155
|
+
if (!head)
|
|
156
|
+
return false;
|
|
157
|
+
// Two questions with two answers each, and only "no" is ever silent:
|
|
158
|
+
// a commit git does not have is simply not contained; a commit it has
|
|
159
|
+
// is an ancestor (exit 0) or not (exit 1); anything else — a corrupt
|
|
160
|
+
// store, a lock, a bad ref — is a failure the caller must hear about,
|
|
161
|
+
// not a 404 wearing its clothes.
|
|
162
|
+
try {
|
|
163
|
+
await this.git(['-C', this.repoDir, 'rev-parse', '--verify', '--quiet', `${sha}^{commit}`]);
|
|
164
|
+
}
|
|
165
|
+
catch (err) {
|
|
166
|
+
if (exitCodeOf(err) === 1)
|
|
167
|
+
return false;
|
|
168
|
+
throw err;
|
|
169
|
+
}
|
|
170
|
+
try {
|
|
171
|
+
await this.git(['-C', this.repoDir, 'merge-base', '--is-ancestor', sha, head]);
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
catch (err) {
|
|
175
|
+
if (exitCodeOf(err) === 1)
|
|
176
|
+
return false;
|
|
177
|
+
throw err;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/** The tree at `sha` as a zip stream, every path under `prefix/`. Check {@link contains} first. */
|
|
181
|
+
archiveZip(sha, prefix) {
|
|
182
|
+
assertObjectId(sha);
|
|
183
|
+
return spawn('git', ['-C', this.repoDir, 'archive', '--format=zip', `--prefix=${prefix}/`, sha], {
|
|
184
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
// --- internal --------------------------------------------------------------
|
|
188
|
+
refOf(namespace) {
|
|
189
|
+
return `refs/namespaces/${namespace}/refs/heads/main`;
|
|
190
|
+
}
|
|
191
|
+
async headOf(namespace) {
|
|
192
|
+
try {
|
|
193
|
+
const { stdout } = await this.git(['-C', this.repoDir, 'rev-parse', '--verify', '--quiet', this.refOf(namespace)]);
|
|
194
|
+
return stdout.trim() || null;
|
|
195
|
+
}
|
|
196
|
+
catch {
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Write `tree` as a commit on the namespace's branch. Materialises the
|
|
202
|
+
* virtual tree into a scratch directory, stages it into a throwaway index
|
|
203
|
+
* against the bare object store, and commits — no working tree involved.
|
|
204
|
+
* When the tree hash equals the head's, nothing is committed.
|
|
205
|
+
*/
|
|
206
|
+
async commitTree(namespace, tree, parent) {
|
|
207
|
+
const scratch = await fs.mkdtemp(path.join(os.tmpdir(), 'hexis-marketplace-'));
|
|
208
|
+
// The throwaway index lives BESIDE the scratch worktree, never inside it:
|
|
209
|
+
// `git add -A` would otherwise stage the index (and its lock) into every
|
|
210
|
+
// compiled tree.
|
|
211
|
+
const indexDir = await fs.mkdtemp(path.join(os.tmpdir(), 'hexis-marketplace-index-'));
|
|
212
|
+
try {
|
|
213
|
+
for (const [rel, bytes] of tree.files) {
|
|
214
|
+
// The compiler sanitises every segment it invents, but the tree is
|
|
215
|
+
// built from repository content, so the sink checks containment
|
|
216
|
+
// itself: nothing is written outside the scratch directory.
|
|
217
|
+
const abs = path.resolve(scratch, rel);
|
|
218
|
+
if (!abs.startsWith(scratch + path.sep)) {
|
|
219
|
+
throw new Error(`refusing to materialise "${rel}": escapes the scratch tree`);
|
|
220
|
+
}
|
|
221
|
+
await fs.mkdir(path.dirname(abs), { recursive: true });
|
|
222
|
+
await fs.writeFile(abs, bytes);
|
|
223
|
+
}
|
|
224
|
+
const index = path.join(indexDir, 'index');
|
|
225
|
+
const env = { ...process.env, GIT_INDEX_FILE: index, GIT_DIR: this.repoDir, GIT_WORK_TREE: scratch };
|
|
226
|
+
await this.git(['add', '-A', '--', '.'], { cwd: scratch, env });
|
|
227
|
+
const treeSha = (await this.git(['write-tree'], { env })).stdout.trim();
|
|
228
|
+
if (parent) {
|
|
229
|
+
const parentTree = (await this.git(['-C', this.repoDir, 'rev-parse', `${parent}^{tree}`])).stdout.trim();
|
|
230
|
+
if (parentTree === treeSha)
|
|
231
|
+
return parent;
|
|
232
|
+
}
|
|
233
|
+
const message = `Compile marketplace from ${tree.sourceCommit}\n\nHexis-Source-Commit: ${tree.sourceCommit}\n`;
|
|
234
|
+
const commitEnv = {
|
|
235
|
+
...process.env,
|
|
236
|
+
GIT_AUTHOR_NAME: this.committer.name,
|
|
237
|
+
GIT_AUTHOR_EMAIL: this.committer.email,
|
|
238
|
+
GIT_COMMITTER_NAME: this.committer.name,
|
|
239
|
+
GIT_COMMITTER_EMAIL: this.committer.email,
|
|
240
|
+
};
|
|
241
|
+
const args = ['-C', this.repoDir, 'commit-tree', treeSha, '-m', message, ...(parent ? ['-p', parent] : [])];
|
|
242
|
+
const sha = (await this.git(args, { env: commitEnv })).stdout.trim();
|
|
243
|
+
// HEAD FIRST, then the branch: a symbolic ref may dangle, a branch
|
|
244
|
+
// without a HEAD is a clone that checks out nothing. Ordered so that a
|
|
245
|
+
// crash between the two leaves the recoverable state.
|
|
246
|
+
await this.ensureHead(namespace);
|
|
247
|
+
await this.git(['-C', this.repoDir, 'update-ref', this.refOf(namespace), sha, ...(parent ? [parent] : [])]);
|
|
248
|
+
return sha;
|
|
249
|
+
}
|
|
250
|
+
finally {
|
|
251
|
+
await fs.rm(scratch, { recursive: true, force: true });
|
|
252
|
+
await fs.rm(indexDir, { recursive: true, force: true });
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Point the namespace's HEAD at its branch — valid before the branch
|
|
257
|
+
* exists. A read first: the symref is written only when absent or wrong,
|
|
258
|
+
* so the common path touches nothing.
|
|
259
|
+
*/
|
|
260
|
+
async ensureHead(namespace) {
|
|
261
|
+
const head = `refs/namespaces/${namespace}/HEAD`;
|
|
262
|
+
const current = await this.git(['-C', this.repoDir, 'symbolic-ref', '--quiet', head]).then((r) => r.stdout.trim(), () => null);
|
|
263
|
+
if (current === this.refOf(namespace))
|
|
264
|
+
return;
|
|
265
|
+
await this.git(['-C', this.repoDir, 'symbolic-ref', head, this.refOf(namespace)]);
|
|
266
|
+
}
|
|
267
|
+
sidecarDir() {
|
|
268
|
+
return path.join(this.repoDir, 'hexis-namespaces');
|
|
269
|
+
}
|
|
270
|
+
async readSidecar(namespace) {
|
|
271
|
+
try {
|
|
272
|
+
return (await fs.readFile(path.join(this.sidecarDir(), `${namespace}.json`), 'utf-8')).trim() || null;
|
|
273
|
+
}
|
|
274
|
+
catch {
|
|
275
|
+
return null;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
async writeSidecar(namespace, sourceCommit) {
|
|
279
|
+
await fs.writeFile(path.join(this.sidecarDir(), `${namespace}.json`), sourceCommit);
|
|
280
|
+
}
|
|
281
|
+
git(args, opts = {}) {
|
|
282
|
+
return execFileAsync('git', args, { cwd: opts.cwd, env: opts.env ?? process.env, maxBuffer: 64 * 1024 * 1024 });
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
/** The exit code an execFile failure carries, or null when the process never ran. */
|
|
286
|
+
function exitCodeOf(err) {
|
|
287
|
+
const code = err?.code;
|
|
288
|
+
return typeof code === 'number' ? code : null;
|
|
289
|
+
}
|
|
290
|
+
function looksLikeObjectId(sha) {
|
|
291
|
+
return /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/.test(sha);
|
|
292
|
+
}
|
|
293
|
+
function assertObjectId(sha) {
|
|
294
|
+
// An object id is the only thing these commands accept as a revision — a
|
|
295
|
+
// ref name, an option, anything git would interpret, is refused before it
|
|
296
|
+
// reaches the argument list.
|
|
297
|
+
if (!looksLikeObjectId(sha))
|
|
298
|
+
throw new Error(`not an object id: ${sha}`);
|
|
299
|
+
}
|
|
300
|
+
//# sourceMappingURL=marketplace-repo.service.js.map
|