@bevel-software/platform-core-backend 0.26.0 → 0.27.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/agent-guide/access-control.md +17 -0
- package/agent-guide/conventions.md +8 -0
- package/agent-guide/html-views.md +83 -0
- package/agent-guide/new-knowledge-base.md +24 -0
- package/agent-guide/tool-manuals.md +10 -0
- package/dist/assets.d.ts +19 -0
- package/dist/assets.d.ts.map +1 -1
- package/dist/assets.js +26 -2
- package/dist/assets.js.map +1 -1
- package/dist/core/catalog-revision.d.ts +19 -1
- package/dist/core/catalog-revision.d.ts.map +1 -1
- package/dist/core/catalog-revision.js +14 -3
- package/dist/core/catalog-revision.js.map +1 -1
- package/dist/core/create-core-server.d.ts +5 -0
- package/dist/core/create-core-server.d.ts.map +1 -1
- package/dist/core/create-core-server.js +54 -3
- package/dist/core/create-core-server.js.map +1 -1
- package/dist/core/create-core-services.d.ts +26 -0
- package/dist/core/create-core-services.d.ts.map +1 -1
- package/dist/core/create-core-services.js +100 -8
- package/dist/core/create-core-services.js.map +1 -1
- package/dist/core/lifecycle.d.ts +16 -1
- package/dist/core/lifecycle.d.ts.map +1 -1
- package/dist/core/lifecycle.js +18 -1
- package/dist/core/lifecycle.js.map +1 -1
- package/dist/core-config.d.ts +21 -0
- package/dist/core-config.d.ts.map +1 -1
- package/dist/core-config.js +22 -1
- package/dist/core-config.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/modules/access/access-control.interface.d.ts +8 -0
- package/dist/modules/access/access-control.interface.d.ts.map +1 -1
- package/dist/modules/access/access-control.service.d.ts +1 -0
- package/dist/modules/access/access-control.service.d.ts.map +1 -1
- package/dist/modules/access/access-control.service.js +11 -0
- package/dist/modules/access/access-control.service.js.map +1 -1
- package/dist/modules/access/directory-sync-bot.js +1 -1
- package/dist/modules/access/directory-sync-bot.js.map +1 -1
- package/dist/modules/agent-guide/agent-guide.d.ts +6 -0
- package/dist/modules/agent-guide/agent-guide.d.ts.map +1 -1
- package/dist/modules/agent-guide/agent-guide.js +8 -0
- package/dist/modules/agent-guide/agent-guide.js.map +1 -1
- package/dist/modules/agent-guide/index.d.ts +1 -1
- package/dist/modules/agent-guide/index.d.ts.map +1 -1
- package/dist/modules/agent-guide/index.js +1 -1
- package/dist/modules/agent-guide/index.js.map +1 -1
- package/dist/modules/agent-instructions/compose.d.ts +5 -0
- package/dist/modules/agent-instructions/compose.d.ts.map +1 -1
- package/dist/modules/agent-instructions/compose.js +19 -2
- package/dist/modules/agent-instructions/compose.js.map +1 -1
- package/dist/modules/agent-instructions/shared-file-rules.js +19 -19
- package/dist/modules/agent-instructions/shared-file-rules.js.map +1 -1
- package/dist/modules/audit/agent-audit.service.d.ts +21 -2
- package/dist/modules/audit/agent-audit.service.d.ts.map +1 -1
- package/dist/modules/audit/agent-audit.service.js +43 -2
- package/dist/modules/audit/agent-audit.service.js.map +1 -1
- package/dist/modules/audit/agent-connection.routes.d.ts +34 -0
- package/dist/modules/audit/agent-connection.routes.d.ts.map +1 -0
- package/dist/modules/audit/agent-connection.routes.js +38 -0
- package/dist/modules/audit/agent-connection.routes.js.map +1 -0
- package/dist/modules/audit/audit.contract.d.ts +24 -0
- package/dist/modules/audit/audit.contract.d.ts.map +1 -1
- package/dist/modules/audit/audit.contract.js.map +1 -1
- package/dist/modules/audit/index.d.ts +1 -0
- package/dist/modules/audit/index.d.ts.map +1 -1
- package/dist/modules/audit/index.js +1 -0
- package/dist/modules/audit/index.js.map +1 -1
- package/dist/modules/auth/account.routes.d.ts.map +1 -1
- package/dist/modules/auth/account.routes.js +10 -3
- package/dist/modules/auth/account.routes.js.map +1 -1
- package/dist/modules/auth/auth.middleware.d.ts +7 -0
- package/dist/modules/auth/auth.middleware.d.ts.map +1 -1
- package/dist/modules/auth/auth.middleware.js +1 -1
- package/dist/modules/auth/auth.middleware.js.map +1 -1
- package/dist/modules/code-mode/code-mode.tool.d.ts.map +1 -1
- package/dist/modules/code-mode/code-mode.tool.js +11 -3
- package/dist/modules/code-mode/code-mode.tool.js.map +1 -1
- package/dist/modules/database/core-schema.d.ts +96 -0
- package/dist/modules/database/core-schema.d.ts.map +1 -1
- package/dist/modules/database/core-schema.js +32 -3
- package/dist/modules/database/core-schema.js.map +1 -1
- package/dist/modules/embed/account-link.service.d.ts +42 -0
- package/dist/modules/embed/account-link.service.d.ts.map +1 -0
- package/dist/modules/embed/account-link.service.js +50 -0
- package/dist/modules/embed/account-link.service.js.map +1 -0
- package/dist/modules/embed/embed-link.d.ts +58 -0
- package/dist/modules/embed/embed-link.d.ts.map +1 -0
- package/dist/modules/embed/embed-link.js +160 -0
- package/dist/modules/embed/embed-link.js.map +1 -0
- package/dist/modules/embed/embed.errors.d.ts +30 -0
- package/dist/modules/embed/embed.errors.d.ts.map +1 -0
- package/dist/modules/embed/embed.errors.js +42 -0
- package/dist/modules/embed/embed.errors.js.map +1 -0
- package/dist/modules/embed/embed.interface.d.ts +204 -0
- package/dist/modules/embed/embed.interface.d.ts.map +1 -0
- package/dist/modules/embed/embed.interface.js +2 -0
- package/dist/modules/embed/embed.interface.js.map +1 -0
- package/dist/modules/embed/embed.routes.d.ts +59 -0
- package/dist/modules/embed/embed.routes.d.ts.map +1 -0
- package/dist/modules/embed/embed.routes.js +343 -0
- package/dist/modules/embed/embed.routes.js.map +1 -0
- package/dist/modules/embed/embed.service.d.ts +169 -0
- package/dist/modules/embed/embed.service.d.ts.map +1 -0
- package/dist/modules/embed/embed.service.js +627 -0
- package/dist/modules/embed/embed.service.js.map +1 -0
- package/dist/modules/embed/embed.tools.d.ts +51 -0
- package/dist/modules/embed/embed.tools.d.ts.map +1 -0
- package/dist/modules/embed/embed.tools.js +170 -0
- package/dist/modules/embed/embed.tools.js.map +1 -0
- package/dist/modules/embed/mcp-app.d.ts +64 -0
- package/dist/modules/embed/mcp-app.d.ts.map +1 -0
- package/dist/modules/embed/mcp-app.js +147 -0
- package/dist/modules/embed/mcp-app.js.map +1 -0
- package/dist/modules/embed/mcp-app.routes.d.ts +21 -0
- package/dist/modules/embed/mcp-app.routes.d.ts.map +1 -0
- package/dist/modules/embed/mcp-app.routes.js +36 -0
- package/dist/modules/embed/mcp-app.routes.js.map +1 -0
- package/dist/modules/github-app/github-app.connection.d.ts +15 -0
- package/dist/modules/github-app/github-app.connection.d.ts.map +1 -1
- package/dist/modules/github-app/github-app.connection.js +34 -3
- package/dist/modules/github-app/github-app.connection.js.map +1 -1
- package/dist/modules/kb-fs/locking-filesystem.d.ts +65 -0
- package/dist/modules/kb-fs/locking-filesystem.d.ts.map +1 -1
- package/dist/modules/kb-fs/locking-filesystem.js +300 -0
- package/dist/modules/kb-fs/locking-filesystem.js.map +1 -1
- package/dist/modules/kb-sync/kb-sync.interface.d.ts +5 -0
- package/dist/modules/kb-sync/kb-sync.interface.d.ts.map +1 -1
- package/dist/modules/kb-sync/kb-sync.service.d.ts.map +1 -1
- package/dist/modules/kb-sync/kb-sync.service.js +6 -0
- package/dist/modules/kb-sync/kb-sync.service.js.map +1 -1
- package/dist/modules/mcp/mcp-auth.middleware.d.ts.map +1 -1
- package/dist/modules/mcp/mcp-auth.middleware.js +2 -1
- package/dist/modules/mcp/mcp-auth.middleware.js.map +1 -1
- package/dist/modules/mcp/mcp.service.d.ts +28 -1
- package/dist/modules/mcp/mcp.service.d.ts.map +1 -1
- package/dist/modules/mcp/mcp.service.js +64 -8
- package/dist/modules/mcp/mcp.service.js.map +1 -1
- package/dist/modules/mcp/oauth/bevel-oauth-provider.d.ts +24 -0
- package/dist/modules/mcp/oauth/bevel-oauth-provider.d.ts.map +1 -1
- package/dist/modules/mcp/oauth/bevel-oauth-provider.js +32 -4
- package/dist/modules/mcp/oauth/bevel-oauth-provider.js.map +1 -1
- package/dist/modules/onboarding/onboarding.contract.d.ts +80 -0
- package/dist/modules/onboarding/onboarding.contract.d.ts.map +1 -0
- package/dist/modules/onboarding/onboarding.contract.js +7 -0
- package/dist/modules/onboarding/onboarding.contract.js.map +1 -0
- package/dist/modules/onboarding/onboarding.routes.d.ts +18 -0
- package/dist/modules/onboarding/onboarding.routes.d.ts.map +1 -0
- package/dist/modules/onboarding/onboarding.routes.js +81 -0
- package/dist/modules/onboarding/onboarding.routes.js.map +1 -0
- package/dist/modules/onboarding/starter-pack.service.d.ts +213 -0
- package/dist/modules/onboarding/starter-pack.service.d.ts.map +1 -0
- package/dist/modules/onboarding/starter-pack.service.js +492 -0
- package/dist/modules/onboarding/starter-pack.service.js.map +1 -0
- package/dist/modules/onboarding/starter-packs.d.ts +78 -0
- package/dist/modules/onboarding/starter-packs.d.ts.map +1 -0
- package/dist/modules/onboarding/starter-packs.js +156 -0
- package/dist/modules/onboarding/starter-packs.js.map +1 -0
- package/dist/modules/plugins/index.d.ts +1 -1
- package/dist/modules/plugins/index.d.ts.map +1 -1
- package/dist/modules/plugins/index.js +1 -1
- package/dist/modules/plugins/index.js.map +1 -1
- package/dist/modules/plugins/plugin-provision.service.d.ts +19 -0
- package/dist/modules/plugins/plugin-provision.service.d.ts.map +1 -1
- package/dist/modules/plugins/plugin-provision.service.js +18 -1
- package/dist/modules/plugins/plugin-provision.service.js.map +1 -1
- package/dist/modules/plugins/plugins.routes.d.ts +0 -36
- package/dist/modules/plugins/plugins.routes.d.ts.map +1 -1
- package/dist/modules/plugins/plugins.routes.js +31 -0
- package/dist/modules/plugins/plugins.routes.js.map +1 -1
- package/dist/modules/settings/deployment-settings.service.d.ts +34 -0
- package/dist/modules/settings/deployment-settings.service.d.ts.map +1 -1
- package/dist/modules/settings/deployment-settings.service.js +134 -1
- package/dist/modules/settings/deployment-settings.service.js.map +1 -1
- package/dist/modules/settings/repository-source.d.ts +1 -0
- package/dist/modules/settings/repository-source.d.ts.map +1 -1
- package/dist/modules/settings/repository-source.js +3 -3
- package/dist/modules/settings/repository-source.js.map +1 -1
- package/dist/modules/skills/skills.tools.d.ts.map +1 -1
- package/dist/modules/skills/skills.tools.js +50 -32
- package/dist/modules/skills/skills.tools.js.map +1 -1
- package/dist/modules/tool-auth/connection-key-rejection.d.ts +10 -1
- package/dist/modules/tool-auth/connection-key-rejection.d.ts.map +1 -1
- package/dist/modules/tool-auth/connection-key-rejection.js +11 -3
- package/dist/modules/tool-auth/connection-key-rejection.js.map +1 -1
- package/dist/modules/tool-auth/external-api-key.interface.d.ts +8 -0
- package/dist/modules/tool-auth/external-api-key.interface.d.ts.map +1 -1
- package/dist/modules/tool-auth/external-api-key.service.d.ts +24 -2
- package/dist/modules/tool-auth/external-api-key.service.d.ts.map +1 -1
- package/dist/modules/tool-auth/external-api-key.service.js +59 -2
- package/dist/modules/tool-auth/external-api-key.service.js.map +1 -1
- package/dist/modules/tool-auth/tool-auth.middleware.d.ts.map +1 -1
- package/dist/modules/tool-auth/tool-auth.middleware.js +9 -4
- package/dist/modules/tool-auth/tool-auth.middleware.js.map +1 -1
- package/dist/modules/tool-helpers/index.d.ts +28 -1
- package/dist/modules/tool-helpers/index.d.ts.map +1 -1
- package/dist/modules/tool-helpers/index.js +28 -1
- package/dist/modules/tool-helpers/index.js.map +1 -1
- package/dist/modules/tool-helpers/route-argument-check.d.ts +10 -0
- package/dist/modules/tool-helpers/route-argument-check.d.ts.map +1 -0
- package/dist/modules/tool-helpers/route-argument-check.js +132 -0
- package/dist/modules/tool-helpers/route-argument-check.js.map +1 -0
- package/dist/modules/tool-helpers/route-tool-schemas.d.ts +89 -0
- package/dist/modules/tool-helpers/route-tool-schemas.d.ts.map +1 -0
- package/dist/modules/tool-helpers/route-tool-schemas.js +113 -0
- package/dist/modules/tool-helpers/route-tool-schemas.js.map +1 -0
- package/dist/modules/tool-helpers/tool-def.d.ts +71 -0
- package/dist/modules/tool-helpers/tool-def.d.ts.map +1 -1
- package/dist/modules/tool-helpers/tool-def.js +70 -6
- package/dist/modules/tool-helpers/tool-def.js.map +1 -1
- package/dist/modules/tool-helpers/tool-handler.d.ts +46 -6
- package/dist/modules/tool-helpers/tool-handler.d.ts.map +1 -1
- package/dist/modules/tool-helpers/tool-handler.js +157 -8
- package/dist/modules/tool-helpers/tool-handler.js.map +1 -1
- package/dist/modules/tool-helpers/tool.contract.d.ts +9 -0
- package/dist/modules/tool-helpers/tool.contract.d.ts.map +1 -1
- package/dist/modules/tool-helpers/tool.contract.js.map +1 -1
- package/dist/modules/tool-manuals/tool-manuals.tools.d.ts.map +1 -1
- package/dist/modules/tool-manuals/tool-manuals.tools.js +14 -5
- package/dist/modules/tool-manuals/tool-manuals.tools.js.map +1 -1
- package/dist/modules/tool-registry/description-length.d.ts +6 -2
- package/dist/modules/tool-registry/description-length.d.ts.map +1 -1
- package/dist/modules/tool-registry/description-length.js +27 -5
- package/dist/modules/tool-registry/description-length.js.map +1 -1
- package/dist/modules/tool-registry/guide-first.d.ts +4 -0
- package/dist/modules/tool-registry/guide-first.d.ts.map +1 -1
- package/dist/modules/tool-registry/guide-first.js +9 -1
- package/dist/modules/tool-registry/guide-first.js.map +1 -1
- package/dist/modules/workflow/agent-tools/change-request-read.tools.d.ts +53 -0
- package/dist/modules/workflow/agent-tools/change-request-read.tools.d.ts.map +1 -1
- package/dist/modules/workflow/agent-tools/change-request-read.tools.js +97 -68
- package/dist/modules/workflow/agent-tools/change-request-read.tools.js.map +1 -1
- package/dist/modules/workflow/agent-tools/workflow.tools.d.ts +8 -1
- package/dist/modules/workflow/agent-tools/workflow.tools.d.ts.map +1 -1
- package/dist/modules/workflow/agent-tools/workflow.tools.js +124 -37
- package/dist/modules/workflow/agent-tools/workflow.tools.js.map +1 -1
- package/dist/modules/workflow/file-lock.service.d.ts +29 -5
- package/dist/modules/workflow/file-lock.service.d.ts.map +1 -1
- package/dist/modules/workflow/file-lock.service.js +62 -5
- package/dist/modules/workflow/file-lock.service.js.map +1 -1
- package/dist/modules/workflow/git/git.service.d.ts +72 -1
- package/dist/modules/workflow/git/git.service.d.ts.map +1 -1
- package/dist/modules/workflow/git/git.service.js +172 -36
- package/dist/modules/workflow/git/git.service.js.map +1 -1
- package/dist/modules/workflow/git/node-git-runner.d.ts +15 -0
- package/dist/modules/workflow/git/node-git-runner.d.ts.map +1 -1
- package/dist/modules/workflow/git/node-git-runner.js +78 -6
- package/dist/modules/workflow/git/node-git-runner.js.map +1 -1
- package/dist/modules/workflow/pending-commits.service.d.ts +15 -0
- package/dist/modules/workflow/pending-commits.service.d.ts.map +1 -1
- package/dist/modules/workflow/pending-commits.service.js +25 -1
- package/dist/modules/workflow/pending-commits.service.js.map +1 -1
- package/dist/modules/workflow/pending-commits.worker.d.ts +6 -1
- package/dist/modules/workflow/pending-commits.worker.d.ts.map +1 -1
- package/dist/modules/workflow/pending-commits.worker.js +23 -6
- package/dist/modules/workflow/pending-commits.worker.js.map +1 -1
- package/dist/modules/workflow/recovery-bot.js +1 -1
- package/dist/modules/workflow/recovery-bot.js.map +1 -1
- package/dist/modules/workflow/review-workflow/review-workflow.service.d.ts.map +1 -1
- package/dist/modules/workflow/review-workflow/review-workflow.service.js +2 -1
- package/dist/modules/workflow/review-workflow/review-workflow.service.js.map +1 -1
- package/dist/modules/workflow/sanitize-error.d.ts +16 -0
- package/dist/modules/workflow/sanitize-error.d.ts.map +1 -1
- package/dist/modules/workflow/sanitize-error.js +45 -0
- package/dist/modules/workflow/sanitize-error.js.map +1 -1
- package/dist/modules/workflow/workflow.service.d.ts +183 -15
- package/dist/modules/workflow/workflow.service.d.ts.map +1 -1
- package/dist/modules/workflow/workflow.service.js +805 -106
- package/dist/modules/workflow/workflow.service.js.map +1 -1
- package/dist/modules/workspace/agent-download.builder.d.ts +105 -0
- package/dist/modules/workspace/agent-download.builder.d.ts.map +1 -0
- package/dist/modules/workspace/agent-download.builder.js +238 -0
- package/dist/modules/workspace/agent-download.builder.js.map +1 -0
- package/dist/modules/workspace/agent-download.routes.d.ts +77 -0
- package/dist/modules/workspace/agent-download.routes.d.ts.map +1 -0
- package/dist/modules/workspace/agent-download.routes.js +156 -0
- package/dist/modules/workspace/agent-download.routes.js.map +1 -0
- package/dist/modules/workspace/agent-download.store.d.ts +225 -0
- package/dist/modules/workspace/agent-download.store.d.ts.map +1 -0
- package/dist/modules/workspace/agent-download.store.js +423 -0
- package/dist/modules/workspace/agent-download.store.js.map +1 -0
- package/dist/modules/workspace/agent-upload.store.d.ts +10 -1
- package/dist/modules/workspace/agent-upload.store.d.ts.map +1 -1
- package/dist/modules/workspace/agent-upload.store.js +16 -6
- package/dist/modules/workspace/agent-upload.store.js.map +1 -1
- package/dist/modules/workspace/file-readers/raw-mime.d.ts +6 -0
- package/dist/modules/workspace/file-readers/raw-mime.d.ts.map +1 -0
- package/dist/modules/workspace/file-readers/raw-mime.js +38 -0
- package/dist/modules/workspace/file-readers/raw-mime.js.map +1 -0
- package/dist/modules/workspace/file-readers/text-reader.d.ts +5 -5
- package/dist/modules/workspace/file-readers/text-reader.d.ts.map +1 -1
- package/dist/modules/workspace/file-readers/text-reader.js +5 -8
- package/dist/modules/workspace/file-readers/text-reader.js.map +1 -1
- package/dist/modules/workspace/first-run.d.ts +111 -0
- package/dist/modules/workspace/first-run.d.ts.map +1 -0
- package/dist/modules/workspace/first-run.js +181 -0
- package/dist/modules/workspace/first-run.js.map +1 -0
- package/dist/modules/workspace/move-links.d.ts +92 -0
- package/dist/modules/workspace/move-links.d.ts.map +1 -0
- package/dist/modules/workspace/move-links.js +173 -0
- package/dist/modules/workspace/move-links.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 +3 -13
- package/dist/modules/workspace/startup/steps/seed-tree.js.map +1 -1
- package/dist/modules/workspace/workspace.routes.d.ts.map +1 -1
- package/dist/modules/workspace/workspace.routes.js +63 -22
- package/dist/modules/workspace/workspace.routes.js.map +1 -1
- package/dist/modules/workspace/workspace.service.d.ts +75 -2
- package/dist/modules/workspace/workspace.service.d.ts.map +1 -1
- package/dist/modules/workspace/workspace.service.js +197 -24
- package/dist/modules/workspace/workspace.service.js.map +1 -1
- package/dist/modules/workspace/workspace.tools.d.ts +59 -1
- package/dist/modules/workspace/workspace.tools.d.ts.map +1 -1
- package/dist/modules/workspace/workspace.tools.js +443 -65
- package/dist/modules/workspace/workspace.tools.js.map +1 -1
- package/dist/modules/write-access/write-access.d.ts.map +1 -1
- package/dist/modules/write-access/write-access.js +9 -0
- package/dist/modules/write-access/write-access.js.map +1 -1
- package/dist/shared/domain-errors.d.ts +73 -1
- package/dist/shared/domain-errors.d.ts.map +1 -1
- package/dist/shared/domain-errors.js +86 -12
- package/dist/shared/domain-errors.js.map +1 -1
- package/dist/shared/git.contract.d.ts +10 -1
- package/dist/shared/git.contract.d.ts.map +1 -1
- package/dist/shared/git.contract.js.map +1 -1
- package/dist/shared/utf8-text.d.ts +15 -0
- package/dist/shared/utf8-text.d.ts.map +1 -0
- package/dist/shared/utf8-text.js +20 -0
- package/dist/shared/utf8-text.js.map +1 -0
- package/dist/tenancy/static-tenant-source.d.ts +2 -1
- package/dist/tenancy/static-tenant-source.d.ts.map +1 -1
- package/dist/tenancy/static-tenant-source.js +9 -2
- package/dist/tenancy/static-tenant-source.js.map +1 -1
- package/mcp-app/page.html +349 -0
- package/migrations/0017_atlassian_account_links.sql +37 -0
- package/migrations/meta/0017_snapshot.json +2396 -0
- package/migrations/meta/_journal.json +8 -1
- package/package.json +5 -3
- package/src/__tests__/packaged-assets-ship.test.ts +16 -4
- package/src/assets.ts +28 -2
- package/src/core/__tests__/catalog-revision.test.ts +40 -0
- package/src/core/__tests__/gated-boot.test.ts +1 -0
- package/src/core/__tests__/lifecycle.test.ts +14 -0
- package/src/core/catalog-revision.ts +15 -2
- package/src/core/create-core-server.ts +67 -3
- package/src/core/create-core-services.ts +140 -6
- package/src/core/lifecycle.ts +28 -2
- package/src/core-config.ts +24 -1
- package/src/index.ts +2 -2
- package/src/modules/access/__tests__/access-control.service.test.ts +19 -0
- package/src/modules/access/access-control.interface.ts +13 -0
- package/src/modules/access/access-control.service.ts +16 -0
- package/src/modules/access/directory-sync-bot.ts +1 -1
- package/src/modules/agent-guide/__tests__/agent-guide.test.ts +58 -0
- package/src/modules/agent-guide/__tests__/agent-guide.tools.test.ts +19 -1
- package/src/modules/agent-guide/agent-guide.ts +9 -0
- package/src/modules/agent-guide/index.ts +1 -0
- package/src/modules/agent-instructions/__tests__/shared-file-rules.test.ts +14 -0
- package/src/modules/agent-instructions/compose.ts +17 -2
- package/src/modules/agent-instructions/shared-file-rules.ts +19 -19
- package/src/modules/audit/__tests__/agent-audit.service.test.ts +64 -4
- package/src/modules/audit/__tests__/agent-connection.routes.test.ts +102 -0
- package/src/modules/audit/agent-audit.service.ts +58 -3
- package/src/modules/audit/agent-connection.routes.ts +56 -0
- package/src/modules/audit/audit.contract.ts +26 -0
- package/src/modules/audit/index.ts +1 -0
- package/src/modules/auth/__tests__/account.routes.test.ts +5 -3
- package/src/modules/auth/account.routes.ts +10 -3
- package/src/modules/auth/auth.middleware.ts +1 -1
- package/src/modules/code-mode/__tests__/code-mode.tool.test.ts +18 -2
- package/src/modules/code-mode/code-mode.tool.ts +13 -2
- package/src/modules/database/core-schema.ts +33 -3
- package/src/modules/embed/__tests__/account-links.migration.test.ts +98 -0
- package/src/modules/embed/__tests__/embed-link.test.ts +122 -0
- package/src/modules/embed/__tests__/embed.routes.test.ts +362 -0
- package/src/modules/embed/__tests__/embed.service.lock.test.ts +193 -0
- package/src/modules/embed/__tests__/embed.service.test.ts +805 -0
- package/src/modules/embed/__tests__/embed.tools.test.ts +304 -0
- package/src/modules/embed/__tests__/mcp-app.test.ts +207 -0
- package/src/modules/embed/account-link.service.ts +76 -0
- package/src/modules/embed/embed-link.ts +180 -0
- package/src/modules/embed/embed.errors.ts +43 -0
- package/src/modules/embed/embed.interface.ts +203 -0
- package/src/modules/embed/embed.routes.ts +363 -0
- package/src/modules/embed/embed.service.ts +705 -0
- package/src/modules/embed/embed.tools.ts +206 -0
- package/src/modules/embed/mcp-app.routes.ts +41 -0
- package/src/modules/embed/mcp-app.ts +173 -0
- package/src/modules/github-app/__tests__/github-app.test.ts +76 -0
- package/src/modules/github-app/github-app.connection.ts +38 -4
- package/src/modules/kb-fs/__tests__/move-with-edits.test.ts +304 -0
- package/src/modules/kb-fs/locking-filesystem.ts +287 -0
- package/src/modules/kb-sync/__tests__/kb-sync.service.test.ts +35 -0
- package/src/modules/kb-sync/kb-sync.interface.ts +2 -0
- package/src/modules/kb-sync/kb-sync.service.ts +6 -0
- package/src/modules/mcp/__tests__/bevel-oauth-provider.test.ts +68 -11
- package/src/modules/mcp/__tests__/mcp-proxy-helpers.test.ts +37 -2
- package/src/modules/mcp/__tests__/mcp.app.e2e.test.ts +200 -0
- package/src/modules/mcp/__tests__/mcp.e2e.test.ts +3 -1
- package/src/modules/mcp/__tests__/mcp.service.test.ts +23 -13
- package/src/modules/mcp/__tests__/tool-call-interface.e2e.test.ts +499 -0
- package/src/modules/mcp/mcp-auth.middleware.ts +2 -1
- package/src/modules/mcp/mcp.service.ts +81 -12
- package/src/modules/mcp/oauth/bevel-oauth-provider.ts +42 -4
- package/src/modules/onboarding/__tests__/onboarding.routes.test.ts +163 -0
- package/src/modules/onboarding/__tests__/starter-pack.service.test.ts +635 -0
- package/src/modules/onboarding/__tests__/starter-packs.test.ts +169 -0
- package/src/modules/onboarding/onboarding.contract.ts +85 -0
- package/src/modules/onboarding/onboarding.routes.ts +85 -0
- package/src/modules/onboarding/starter-pack.service.ts +580 -0
- package/src/modules/onboarding/starter-packs.ts +182 -0
- package/src/modules/plugins/__tests__/plugins.tools.test.ts +25 -2
- package/src/modules/plugins/index.ts +1 -0
- package/src/modules/plugins/plugin-provision.service.ts +22 -1
- package/src/modules/plugins/plugins.routes.ts +29 -0
- package/src/modules/settings/__tests__/deployment-settings.service.test.ts +150 -1
- package/src/modules/settings/__tests__/repository-source.test.ts +9 -0
- package/src/modules/settings/deployment-settings.service.ts +131 -1
- package/src/modules/settings/repository-source.ts +4 -4
- package/src/modules/skills/__tests__/skills.tools.description.test.ts +5 -1
- package/src/modules/skills/skills.tools.ts +55 -35
- package/src/modules/tool-auth/__tests__/connection-key-rejection.test.ts +32 -0
- package/src/modules/tool-auth/__tests__/external-api-key.service.test.ts +65 -0
- package/src/modules/tool-auth/connection-key-rejection.ts +13 -3
- package/src/modules/tool-auth/external-api-key.interface.ts +9 -0
- package/src/modules/tool-auth/external-api-key.service.ts +61 -4
- package/src/modules/tool-auth/tool-auth.middleware.ts +13 -4
- package/src/modules/tool-helpers/__tests__/branch-declaration.test.ts +502 -0
- package/src/modules/tool-helpers/__tests__/route-argument-check.test.ts +337 -0
- package/src/modules/tool-helpers/index.ts +34 -1
- package/src/modules/tool-helpers/route-argument-check.ts +149 -0
- package/src/modules/tool-helpers/route-tool-schemas.ts +171 -0
- package/src/modules/tool-helpers/tool-def.ts +132 -7
- package/src/modules/tool-helpers/tool-handler.ts +196 -8
- package/src/modules/tool-helpers/tool.contract.ts +9 -0
- package/src/modules/tool-manuals/tool-manuals.tools.ts +15 -5
- package/src/modules/tool-registry/__tests__/own-tool-schemas.test.ts +14 -1
- package/src/modules/tool-registry/__tests__/tool-description-length.test.ts +23 -10
- package/src/modules/tool-registry/description-length.ts +34 -7
- package/src/modules/tool-registry/guide-first.ts +8 -1
- package/src/modules/workflow/__tests__/file-lock.service.deletion-gate.test.ts +104 -0
- package/src/modules/workflow/__tests__/pending-commits.repository-replaced.test.ts +66 -0
- package/src/modules/workflow/__tests__/pending-commits.worker.test.ts +31 -2
- package/src/modules/workflow/__tests__/preserve-roles-yaml.test.ts +110 -6
- package/src/modules/workflow/__tests__/sanitize-error.test.ts +89 -1
- package/src/modules/workflow/__tests__/workflow.routes.push-refused.test.ts +202 -0
- package/src/modules/workflow/__tests__/workflow.service.branch-in-use.test.ts +6 -6
- package/src/modules/workflow/__tests__/workflow.service.delete-branch.test.ts +1026 -0
- package/src/modules/workflow/__tests__/workflow.service.facade.test.ts +468 -10
- package/src/modules/workflow/__tests__/workflow.service.folder-proposals.test.ts +4 -0
- package/src/modules/workflow/__tests__/workflow.service.releaseLock.test.ts +5 -4
- package/src/modules/workflow/__tests__/workflow.service.update-from-target.test.ts +54 -2
- package/src/modules/workflow/agent-tools/__tests__/change-request-read.tools.test.ts +41 -5
- package/src/modules/workflow/agent-tools/__tests__/workflow.tools.test.ts +127 -2
- package/src/modules/workflow/agent-tools/change-request-read.tools.ts +157 -122
- package/src/modules/workflow/agent-tools/workflow.tools.ts +129 -35
- package/src/modules/workflow/file-lock.service.ts +67 -5
- package/src/modules/workflow/git/__tests__/git.service.deleteBranch.test.ts +164 -0
- package/src/modules/workflow/git/__tests__/git.service.pull.test.ts +48 -1
- package/src/modules/workflow/git/__tests__/node-git-runner.test.ts +231 -2
- package/src/modules/workflow/git/git.service.ts +176 -38
- package/src/modules/workflow/git/node-git-runner.ts +82 -7
- package/src/modules/workflow/pending-commits.service.ts +29 -1
- package/src/modules/workflow/pending-commits.worker.ts +24 -6
- package/src/modules/workflow/recovery-bot.ts +1 -1
- package/src/modules/workflow/review-workflow/review-workflow.service.ts +2 -1
- package/src/modules/workflow/sanitize-error.ts +50 -0
- package/src/modules/workflow/workflow.service.ts +879 -112
- package/src/modules/workspace/__tests__/agent-downloads.test.ts +823 -0
- package/src/modules/workspace/__tests__/first-run.test.ts +234 -0
- package/src/modules/workspace/__tests__/git-internals.security.test.ts +5 -2
- package/src/modules/workspace/__tests__/md-links.test.ts +353 -0
- package/src/modules/workspace/__tests__/move-links.test.ts +261 -0
- package/src/modules/workspace/__tests__/rest-tool-arguments.test.ts +219 -0
- package/src/modules/workspace/__tests__/workspace-paths-inside-the-repo.test.ts +3 -0
- package/src/modules/workspace/__tests__/workspace.routes.delete.test.ts +102 -0
- package/src/modules/workspace/__tests__/workspace.routes.download.test.ts +52 -5
- package/src/modules/workspace/__tests__/workspace.routes.folder-zip-access.test.ts +190 -0
- package/src/modules/workspace/__tests__/workspace.service.forget-clone-races.test.ts +8 -4
- package/src/modules/workspace/__tests__/workspace.service.test.ts +50 -8
- package/src/modules/workspace/__tests__/workspace.tools.branch-errors.test.ts +44 -1
- package/src/modules/workspace/__tests__/workspace.tools.test.ts +409 -12
- package/src/modules/workspace/agent-download.builder.ts +308 -0
- package/src/modules/workspace/agent-download.routes.ts +183 -0
- package/src/modules/workspace/agent-download.store.ts +533 -0
- package/src/modules/workspace/agent-upload.store.ts +23 -7
- package/src/modules/workspace/file-readers/raw-mime.ts +40 -0
- package/src/modules/workspace/file-readers/text-reader.ts +5 -8
- package/src/modules/workspace/first-run.ts +222 -0
- package/src/modules/workspace/move-links.ts +237 -0
- package/src/modules/workspace/startup/steps/seed-tree.ts +3 -12
- package/src/modules/workspace/workspace.routes.ts +64 -22
- package/src/modules/workspace/workspace.service.ts +202 -25
- package/src/modules/workspace/workspace.tools.ts +492 -63
- package/src/modules/write-access/__tests__/write-access.test.ts +13 -0
- package/src/modules/write-access/write-access.ts +9 -0
- package/src/shared/domain-errors.ts +108 -11
- package/src/shared/git.contract.ts +8 -1
- package/src/shared/utf8-text.ts +21 -0
- package/src/tenancy/__tests__/static-tenant-source.test.ts +1 -0
- package/src/tenancy/static-tenant-source.ts +10 -2
- package/starter-packs/README.md +103 -0
- package/starter-packs/engineering/KnowledgeBase/About us.md +9 -0
- package/starter-packs/engineering/KnowledgeBase/Architecture.md +9 -0
- package/starter-packs/engineering/KnowledgeBase/Glossary.md +9 -0
- package/starter-packs/engineering/KnowledgeBase/How we ship.md +9 -0
- package/starter-packs/engineering/Plugins/engineering-starter/LICENSE +21 -0
- package/starter-packs/engineering/Plugins/engineering-starter/SOURCE.md +20 -0
- package/starter-packs/engineering/Plugins/engineering-starter/access.md +19 -0
- package/starter-packs/engineering/Plugins/engineering-starter/plugin.json +10 -0
- package/starter-packs/engineering/Plugins/engineering-starter/skills/office-hours/SKILL.md +171 -0
- package/starter-packs/engineering/Plugins/engineering-starter/skills/office-hours/sections/phase-2a-startup-diagnostic.md +157 -0
- package/starter-packs/engineering/Plugins/engineering-starter/skills/office-hours/sections/phase-2b-builder-brainstorm.md +39 -0
- package/starter-packs/engineering/Plugins/engineering-starter/skills/plan-ceo-review/SKILL.md +144 -0
- package/starter-packs/engineering/Plugins/engineering-starter/skills/plan-eng-review/SKILL.md +144 -0
- package/starter-packs/engineering/Plugins/engineering-starter/skills/review/SKILL.md +80 -0
- package/starter-packs/engineering/Plugins/engineering-starter/skills/review/checklist.md +184 -0
- package/starter-packs/engineering/pack.yaml +11 -0
- package/starter-packs/general/KnowledgeBase/About us.md +9 -0
- package/starter-packs/general/KnowledgeBase/Glossary.md +9 -0
- package/starter-packs/general/KnowledgeBase/How we work.md +9 -0
- package/starter-packs/general/Plugins/general-starter/LICENSE +202 -0
- package/starter-packs/general/Plugins/general-starter/SOURCE.md +10 -0
- package/starter-packs/general/Plugins/general-starter/access.md +19 -0
- package/starter-packs/general/Plugins/general-starter/plugin.json +10 -0
- package/starter-packs/general/Plugins/general-starter/skills/memory-management/SKILL.md +332 -0
- package/starter-packs/general/Plugins/general-starter/skills/productivity-start/SKILL.md +163 -0
- package/starter-packs/general/Plugins/general-starter/skills/productivity-update/SKILL.md +167 -0
- package/starter-packs/general/Plugins/general-starter/skills/task-management/SKILL.md +83 -0
- package/starter-packs/general/pack.yaml +10 -0
- package/starter-packs/operations/KnowledgeBase/Glossary.md +9 -0
- package/starter-packs/operations/KnowledgeBase/How we work.md +9 -0
- package/starter-packs/operations/KnowledgeBase/Processes.md +9 -0
- package/starter-packs/operations/KnowledgeBase/Tools we use.md +9 -0
- package/starter-packs/operations/KnowledgeBase/Vendors.md +9 -0
- package/starter-packs/operations/Plugins/operations-starter/LICENSE +202 -0
- package/starter-packs/operations/Plugins/operations-starter/SOURCE.md +10 -0
- package/starter-packs/operations/Plugins/operations-starter/access.md +19 -0
- package/starter-packs/operations/Plugins/operations-starter/plugin.json +10 -0
- package/starter-packs/operations/Plugins/operations-starter/skills/capacity-plan/SKILL.md +111 -0
- package/starter-packs/operations/Plugins/operations-starter/skills/change-request/SKILL.md +119 -0
- package/starter-packs/operations/Plugins/operations-starter/skills/compliance-tracking/SKILL.md +44 -0
- package/starter-packs/operations/Plugins/operations-starter/skills/process-doc/SKILL.md +80 -0
- package/starter-packs/operations/Plugins/operations-starter/skills/process-optimization/SKILL.md +39 -0
- package/starter-packs/operations/Plugins/operations-starter/skills/risk-assessment/SKILL.md +40 -0
- package/starter-packs/operations/Plugins/operations-starter/skills/runbook/SKILL.md +85 -0
- package/starter-packs/operations/Plugins/operations-starter/skills/status-report/SKILL.md +75 -0
- package/starter-packs/operations/Plugins/operations-starter/skills/vendor-review/SKILL.md +102 -0
- package/starter-packs/operations/pack.yaml +12 -0
- package/starter-packs/sales/KnowledgeBase/About us.md +9 -0
- package/starter-packs/sales/KnowledgeBase/Customers.md +9 -0
- package/starter-packs/sales/KnowledgeBase/Glossary.md +9 -0
- package/starter-packs/sales/KnowledgeBase/How we sell.md +9 -0
- package/starter-packs/sales/KnowledgeBase/Objections.md +9 -0
- package/starter-packs/sales/KnowledgeBase/Pricing.md +9 -0
- package/starter-packs/sales/Plugins/sales-starter/LICENSE +202 -0
- package/starter-packs/sales/Plugins/sales-starter/SOURCE.md +10 -0
- package/starter-packs/sales/Plugins/sales-starter/access.md +19 -0
- package/starter-packs/sales/Plugins/sales-starter/plugin.json +10 -0
- package/starter-packs/sales/Plugins/sales-starter/skills/account-context/SKILL.md +94 -0
- package/starter-packs/sales/Plugins/sales-starter/skills/account-plan/SKILL.md +95 -0
- package/starter-packs/sales/Plugins/sales-starter/skills/account-research/SKILL.md +99 -0
- package/starter-packs/sales/Plugins/sales-starter/skills/account-tiering/SKILL.md +101 -0
- package/starter-packs/sales/Plugins/sales-starter/skills/call-prep/SKILL.md +111 -0
- package/starter-packs/sales/Plugins/sales-starter/skills/call-summary/SKILL.md +111 -0
- package/starter-packs/sales/Plugins/sales-starter/skills/close-plan/SKILL.md +106 -0
- package/starter-packs/sales/Plugins/sales-starter/skills/competitive-intelligence/SKILL.md +102 -0
- package/starter-packs/sales/Plugins/sales-starter/skills/create-an-asset/SKILL.md +105 -0
- package/starter-packs/sales/Plugins/sales-starter/skills/crm-hygiene-check/SKILL.md +103 -0
- package/starter-packs/sales/Plugins/sales-starter/skills/customer-health/SKILL.md +108 -0
- package/starter-packs/sales/Plugins/sales-starter/skills/customer-voice/SKILL.md +94 -0
- package/starter-packs/sales/Plugins/sales-starter/skills/daily-briefing/SKILL.md +61 -0
- package/starter-packs/sales/Plugins/sales-starter/skills/deal-advance-gap/SKILL.md +102 -0
- package/starter-packs/sales/Plugins/sales-starter/skills/deal-review/SKILL.md +105 -0
- package/starter-packs/sales/Plugins/sales-starter/skills/deal-signals/SKILL.md +96 -0
- package/starter-packs/sales/Plugins/sales-starter/skills/deal-slip-scenario/SKILL.md +104 -0
- package/starter-packs/sales/Plugins/sales-starter/skills/draft-outreach/SKILL.md +116 -0
- package/starter-packs/sales/Plugins/sales-starter/skills/end-of-day/SKILL.md +114 -0
- package/starter-packs/sales/Plugins/sales-starter/skills/expansion-whitespace/SKILL.md +97 -0
- package/starter-packs/sales/Plugins/sales-starter/skills/forecast/SKILL.md +100 -0
- package/starter-packs/sales/Plugins/sales-starter/skills/handle-objection/SKILL.md +93 -0
- package/starter-packs/sales/Plugins/sales-starter/skills/inbox-sweep/SKILL.md +114 -0
- package/starter-packs/sales/Plugins/sales-starter/skills/lead-triage/SKILL.md +106 -0
- package/starter-packs/sales/Plugins/sales-starter/skills/log-activity/SKILL.md +111 -0
- package/starter-packs/sales/Plugins/sales-starter/skills/pipeline-review/SKILL.md +97 -0
- package/starter-packs/sales/Plugins/sales-starter/skills/renewal-radar/SKILL.md +95 -0
- package/starter-packs/sales/Plugins/sales-starter/skills/rep-context/SKILL.md +90 -0
- package/starter-packs/sales/Plugins/sales-starter/skills/route-lead/SKILL.md +111 -0
- package/starter-packs/sales/Plugins/sales-starter/skills/sales-setup/SKILL.md +200 -0
- package/starter-packs/sales/Plugins/sales-starter/skills/schedule-meeting/SKILL.md +99 -0
- package/starter-packs/sales/Plugins/sales-starter/skills/stakeholder-map/SKILL.md +107 -0
- package/starter-packs/sales/Plugins/sales-starter/skills/team-pipeline/SKILL.md +105 -0
- package/starter-packs/sales/Plugins/sales-starter/skills/update-opportunity/SKILL.md +112 -0
- package/starter-packs/sales/Plugins/sales-starter/skills/weekly-wrap/SKILL.md +90 -0
- package/starter-packs/sales/Plugins/sales-starter/skills/win-loss-review/SKILL.md +88 -0
- package/starter-packs/sales/pack.yaml +13 -0
- package/starter-packs/support/KnowledgeBase/Escalations.md +9 -0
- package/starter-packs/support/KnowledgeBase/Glossary.md +9 -0
- package/starter-packs/support/KnowledgeBase/Known issues.md +9 -0
- package/starter-packs/support/KnowledgeBase/Products.md +9 -0
- package/starter-packs/support/KnowledgeBase/Tone of voice.md +9 -0
- package/starter-packs/support/Plugins/support-starter/LICENSE +202 -0
- package/starter-packs/support/Plugins/support-starter/SOURCE.md +10 -0
- package/starter-packs/support/Plugins/support-starter/access.md +19 -0
- package/starter-packs/support/Plugins/support-starter/plugin.json +10 -0
- package/starter-packs/support/Plugins/support-starter/skills/customer-escalation/SKILL.md +246 -0
- package/starter-packs/support/Plugins/support-starter/skills/customer-research/SKILL.md +250 -0
- package/starter-packs/support/Plugins/support-starter/skills/draft-response/SKILL.md +416 -0
- package/starter-packs/support/Plugins/support-starter/skills/kb-article/SKILL.md +350 -0
- package/starter-packs/support/Plugins/support-starter/skills/ticket-triage/SKILL.md +273 -0
- package/starter-packs/support/pack.yaml +12 -0
|
@@ -2,16 +2,16 @@ import { spawn } from 'node:child_process';
|
|
|
2
2
|
import nodeFs from 'node:fs/promises';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
import AdmZip from 'adm-zip';
|
|
5
|
-
import { ToolError } from '../tool-helpers/tool.contract.js';
|
|
5
|
+
import { hasHttpStatus, ToolError } from '../tool-helpers/tool.contract.js';
|
|
6
6
|
import { BRANCH_INPUT, toolDef } from '../tool-helpers/tool-def.js';
|
|
7
7
|
import { notifyAgentRead, assertAgentWriteAllowed, SESSION_ID_INPUT, } from './agent-access.gate.js';
|
|
8
8
|
import { requireInternalSource, requireExternalSource } from '../tool-auth/tool-auth.middleware.js';
|
|
9
9
|
import { workspaceIdForBranch } from '../../shared/workspace-id.js';
|
|
10
|
-
import {
|
|
10
|
+
import { GitInternalsError, WorkflowValidationError } from '../../shared/domain-errors.js';
|
|
11
11
|
// Leaf-level shared primitive (same exception `workspace.service.ts` already
|
|
12
12
|
// relies on) — not a workflow service, so this stays inside the module boundary.
|
|
13
13
|
import { assertValidBranchName } from '../kb-fs/branch-name.js';
|
|
14
|
-
import { assertInsideRepo, assertRepoRootNameFree, assertRepoRootNameFreeArgs, isInsideRepo, normalizePathArgs, } from '../kb-fs/repo-path.js';
|
|
14
|
+
import { assertInsideRepo, assertRepoRootNameFree, assertRepoRootNameFreeArgs, isInsideRepo, normalizePathArgs, normalizeWorkspacePath, } from '../kb-fs/repo-path.js';
|
|
15
15
|
import { GitGuardedFilesystem } from '../kb-fs/git-guarded-filesystem.js';
|
|
16
16
|
import { assertNoGitInternalsSegment, assertNotGitInternals, hasGitInternalsSegment } from '../../shared/git-internals.js';
|
|
17
17
|
import { isRolesYamlPath } from '../access-model/roles-yaml-guard.js';
|
|
@@ -24,17 +24,24 @@ import { fileTypeOf, needsContent } from './file-readers/content-mode.js';
|
|
|
24
24
|
import { createFileReaderRegistry } from './file-readers/file-reader.registry.js';
|
|
25
25
|
import { DocumentReader } from './file-readers/document-reader.js';
|
|
26
26
|
import { mcpImageResult } from '@bevel-software/platform-mcp-core';
|
|
27
|
-
import { folderPlaceholderPath, isFolderPlaceholder, isPlatformFile, isPlatformFolder, platformFileCreationRefusal, platformFileRefusal, platformFileUploadRefusal, platformFolderRefusal, entryExistsMessage, } from '@bevel-software/platform-shared';
|
|
27
|
+
import { folderPlaceholderPath, isFolderPlaceholder, isPlatformFile, isPlatformFolder, platformFileCreationRefusal, platformFileRefusal, platformFileUploadRefusal, platformFolderRefusal, isRepositoryOwnFile, repositoryOwnFileDeleteRefusal, entryExistsMessage, } from '@bevel-software/platform-shared';
|
|
28
28
|
import { AccessDeniedError } from '../access-model/access-errors.js';
|
|
29
29
|
import { AGENT_GUIDE_FILE, isAgentGuidePath, isManagedGuide, withPlatformGuideAppended, } from '../agent-guide/agent-guide.js';
|
|
30
30
|
import { removeEmptyDirs } from './empty-dirs.js';
|
|
31
|
+
import { FIRST_RUN_SECTION_ID, firstRunNote, knowledgeFolderIsNew } from './first-run.js';
|
|
32
|
+
import { planMoveLinks } from './move-links.js';
|
|
33
|
+
import { MoveLockedError, MoveRacedError } from '../kb-fs/locking-filesystem.js';
|
|
31
34
|
import { rethrowAsWriteDenial } from './write-denial.js';
|
|
32
35
|
import { notFound, orDeclaredNotFound, orNotFound } from './not-found.js';
|
|
33
36
|
import { logger } from '../../shared/logging.js';
|
|
34
37
|
import { printable } from '../../shared/printable.js';
|
|
35
38
|
import { DestinationTakenError, inspectDestination } from '../../shared/rename-no-replace.js';
|
|
39
|
+
import { buildDownload } from './agent-download.builder.js';
|
|
40
|
+
import { DOWNLOAD_MAX_FILES, ZIP_DOWNLOAD_MAX_BYTES } from './workspace.service.js';
|
|
36
41
|
import { isSymlinkZipEntry, isZipNoiseEntry, readZipEntry, zipEntryName, zipEntryNameRefusal, zipEntrySegments, } from './zip-entry-rules.js';
|
|
37
42
|
const log = logger('workspace-tools');
|
|
43
|
+
/** Types that run scripts wherever they are opened, sent by `request_file_download` as plain bytes. */
|
|
44
|
+
const ACTIVE_CONTENT_TYPES = new Set(['image/svg+xml', 'text/html', 'application/xhtml+xml']);
|
|
38
45
|
/** How many files `file_stat` counts under a folder before it stops and says so. */
|
|
39
46
|
const DESCENDANTS_CAP = 10_000;
|
|
40
47
|
/** How many of a folder's files a `delete_folder` answer names. */
|
|
@@ -610,7 +617,7 @@ const BATCH_SAVE_WARNINGS_OUTPUT = {
|
|
|
610
617
|
* the tools were built has to be written here rather than onto the shared
|
|
611
618
|
* `SESSION_ID_INPUT` constant.
|
|
612
619
|
*/
|
|
613
|
-
function sessionIdInputOf(def) {
|
|
620
|
+
export function sessionIdInputOf(def) {
|
|
614
621
|
const inputs = def.inputs;
|
|
615
622
|
return inputs?.properties?.body?.properties?.sessionId;
|
|
616
623
|
}
|
|
@@ -653,7 +660,27 @@ uploads,
|
|
|
653
660
|
* the harnesses that are about the file primitives; without it the two
|
|
654
661
|
* tools read the disk and nothing else.
|
|
655
662
|
*/
|
|
656
|
-
agentGuide
|
|
663
|
+
agentGuide,
|
|
664
|
+
/**
|
|
665
|
+
* The download-link store behind `request_file_download` — the way an agent
|
|
666
|
+
* takes files OUT without their content passing through the model. Optional
|
|
667
|
+
* for the harnesses about the file primitives; without it the tool is not
|
|
668
|
+
* mounted.
|
|
669
|
+
*/
|
|
670
|
+
downloads,
|
|
671
|
+
/**
|
|
672
|
+
* The starter pack the knowledge base was filled from, if any (see
|
|
673
|
+
* `modules/onboarding`): its untouched pages do not end the `firstRun`
|
|
674
|
+
* note, and the note names the pages it suggests. Optional; without it the
|
|
675
|
+
* note reads the knowledge folder alone.
|
|
676
|
+
*/
|
|
677
|
+
starterPacks,
|
|
678
|
+
/**
|
|
679
|
+
* The one tree walk (see `shared/fs.contract.ts`), for the `firstRun`
|
|
680
|
+
* note's look at the knowledge folder. Optional for the harnesses about the
|
|
681
|
+
* file primitives; without it `start_session` answers the id alone.
|
|
682
|
+
*/
|
|
683
|
+
disk) {
|
|
657
684
|
const { kbDirName } = kb;
|
|
658
685
|
/**
|
|
659
686
|
* The one extension→reader registry every read-shaped decision routes
|
|
@@ -992,6 +1019,26 @@ agentGuide) {
|
|
|
992
1019
|
const rel = toKbRelative(norm, kbDirName);
|
|
993
1020
|
return rel !== null && isPlatformFolder(rel, kb.layout) ? platformFolderRefusal(rel) : undefined;
|
|
994
1021
|
};
|
|
1022
|
+
/**
|
|
1023
|
+
* Why `delete_file` may not delete the FILE at `path` whoever asks, or
|
|
1024
|
+
* undefined when the caller's write access decides. Narrower than
|
|
1025
|
+
* {@link managedReason}: a nested `access.md` never moves, but whoever may
|
|
1026
|
+
* write it may delete it — as in the app — and its folder then follows its
|
|
1027
|
+
* parent's rules. The root's `access.md` and `roles.yaml` are deleted by
|
|
1028
|
+
* nobody. Judged on the on-disk spelling, as `managedReason` is.
|
|
1029
|
+
*/
|
|
1030
|
+
const fileDeleteRefusal = (path) => {
|
|
1031
|
+
const norm = path.replace(/^\.?\/+/, '').replace(/\/+$/, '');
|
|
1032
|
+
if (isGitMetadata(norm))
|
|
1033
|
+
return managedReason(norm, 'file');
|
|
1034
|
+
const rel = toKbRelative(norm, kbDirName);
|
|
1035
|
+
if (rel === null || !isPlatformFile(rel, kb.layout))
|
|
1036
|
+
return undefined;
|
|
1037
|
+
if (isRepositoryOwnFile(rel, kb.layout))
|
|
1038
|
+
return repositoryOwnFileDeleteRefusal(rel);
|
|
1039
|
+
const name = rel.slice(rel.lastIndexOf('/') + 1);
|
|
1040
|
+
return name === 'access.md' ? undefined : `${name} is a platform file and cannot be deleted through the agent tools.`;
|
|
1041
|
+
};
|
|
995
1042
|
/** The workspace root on disk for `branch`. */
|
|
996
1043
|
const workspaceRoot = (branch, ctx) => ctx.workspaceService.getWorkspacePath(workspaceIdForBranch(branch));
|
|
997
1044
|
/**
|
|
@@ -1203,12 +1250,6 @@ agentGuide) {
|
|
|
1203
1250
|
// description from the END, where what is specific to the tool sits. The
|
|
1204
1251
|
// rules themselves are in the handshake instructions and in the managed
|
|
1205
1252
|
// guide (see `shared-file-rules.ts`), stated once and from one text.
|
|
1206
|
-
// Whether a call to this tool MUST name a branch, read off the tool's own
|
|
1207
|
-
// declaration rather than assumed of the family. Every tool mounted here
|
|
1208
|
-
// requires `branch` today; keying on the schema means a tool that declares
|
|
1209
|
-
// it optional (and resolves absence itself, as `list_tool_setup` does on its
|
|
1210
|
-
// own route) is not handed a refusal it never asked for.
|
|
1211
|
-
const requiresBranch = (spec.inputs.required ?? []).includes('branch');
|
|
1212
1253
|
const describe = () => (typeof spec.description === 'function' ? spec.description() : spec.description) +
|
|
1213
1254
|
(spec.gated ? agentAccessGate.notes.gatedToolNote() : '');
|
|
1214
1255
|
const def = toolDef({
|
|
@@ -1217,8 +1258,14 @@ agentGuide) {
|
|
|
1217
1258
|
path,
|
|
1218
1259
|
inputs: spec.inputs,
|
|
1219
1260
|
outputs: spec.outputs,
|
|
1261
|
+
refusesItself: spec.refusesItself,
|
|
1220
1262
|
tags: spec.write ? ['workspace', 'write'] : ['workspace'],
|
|
1221
1263
|
});
|
|
1264
|
+
// Every tool here declares `branch` required in its inputs, which is how
|
|
1265
|
+
// `toolDef` records it: the tool handler refuses a branch-less call before
|
|
1266
|
+
// the path work below and before any handler. Most of these tools would
|
|
1267
|
+
// meet the same refusal one layer down at `getFilesystem`, but not all —
|
|
1268
|
+
// `unzip` hands `branch` straight to the workspace service by id.
|
|
1222
1269
|
registry.registerInternalTool(def);
|
|
1223
1270
|
if (!spec.internalOnly)
|
|
1224
1271
|
registry.registerExternalTool(def);
|
|
@@ -1265,17 +1312,6 @@ agentGuide) {
|
|
|
1265
1312
|
// path, and exempting it there would be a workspace-relative path that
|
|
1266
1313
|
// never reached the repository — the whole bug, spelled with a prefix.
|
|
1267
1314
|
toolHandler(async (args, ctx) => {
|
|
1268
|
-
// FIRST, before the path work and before any handler: every tool
|
|
1269
|
-
// mounted here declares `branch` as a required, non-empty string, and
|
|
1270
|
-
// nothing enforced that, so a call that named none was carried down
|
|
1271
|
-
// until `workspaceIdForBranch` made a workspace directory out of the
|
|
1272
|
-
// missing value. Most of these tools would meet the same refusal one
|
|
1273
|
-
// layer down at `getFilesystem`, but not all of them do — `unzip`
|
|
1274
|
-
// hands `branch` straight to the workspace service by id — so the
|
|
1275
|
-
// check belongs on the mount every one of them shares rather than on
|
|
1276
|
-
// the resolver only some of them reach.
|
|
1277
|
-
if (requiresBranch && !spec.resolvesBranchItself)
|
|
1278
|
-
assertBranchProvided(args.branch);
|
|
1279
1315
|
// BEFORE the normaliser: see `assertToolPathsNotGitInternals`.
|
|
1280
1316
|
if (spec.fileTool !== false)
|
|
1281
1317
|
await assertToolPathsNotGitInternals(args, ctx);
|
|
@@ -1303,7 +1339,9 @@ agentGuide) {
|
|
|
1303
1339
|
catch (err) {
|
|
1304
1340
|
return rethrowAsWriteDenial(err, { tool: spec.name, branch: args.branch, userEmail: ctx.user.email, userId: ctx.user.id }, accessControl, kb, changeGate);
|
|
1305
1341
|
}
|
|
1306
|
-
},
|
|
1342
|
+
},
|
|
1343
|
+
// `execute_command` resolves its own branch (see `resolvesBranchItself`).
|
|
1344
|
+
{ write: spec.write, writeScope: spec.writeScope, ...(spec.resolvesBranchItself ? { branch: 'own' } : {}) }));
|
|
1307
1345
|
};
|
|
1308
1346
|
// ── session bootstrap (external agents) ─────────────────────────────────
|
|
1309
1347
|
// Every read/write tool below takes a `sessionId`: the conversation the
|
|
@@ -1331,12 +1369,15 @@ agentGuide) {
|
|
|
1331
1369
|
// transport hiccup on its first call as an unrecoverable start.
|
|
1332
1370
|
const startSessionDef = toolDef({
|
|
1333
1371
|
name: 'start_session',
|
|
1334
|
-
description: 'Mint
|
|
1372
|
+
description: 'Mint this conversation\'s id: the `sessionId` KnowledgeBase tools take. Call this ONCE, at the start of your work — minting a new id mid-run starts a second conversation as far as the server is concerned. The id is also a chat session in the app, so you can hand the SAME id to the `ask` tool: your reads and your questions are then one conversation. Pass the returned id as `sessionId` on every later KnowledgeBase tool call, inside `call_tool_chain` too. RETRYING IS SAFE: a call that fails created nothing, so retry it. If a retry lands after a success you hold two independent ids, which is harmless: keep passing the one you already used and ignore the other. Returns `{ sessionId }`, plus `firstRun` while the knowledge base is still empty: a note to act on.',
|
|
1335
1373
|
path: '/api/agent/tools/start_session',
|
|
1336
1374
|
inputs: { type: 'object', properties: {}, additionalProperties: false },
|
|
1337
1375
|
outputs: {
|
|
1338
1376
|
type: 'object',
|
|
1339
|
-
properties: {
|
|
1377
|
+
properties: {
|
|
1378
|
+
sessionId: str('The minted session id — pass it as `sessionId` on subsequent KnowledgeBase tool calls and to `ask`.'),
|
|
1379
|
+
firstRun: str(`Present only while the knowledge base holds nothing but its starter guide (and a starter pack's untouched pages): what to offer the person (the guide's \`${FIRST_RUN_SECTION_ID}\` section says how).`),
|
|
1380
|
+
},
|
|
1340
1381
|
required: ['sessionId'],
|
|
1341
1382
|
},
|
|
1342
1383
|
tags: ['workspace'],
|
|
@@ -1353,9 +1394,99 @@ agentGuide) {
|
|
|
1353
1394
|
// per-chat sessionIds over its lifetime.
|
|
1354
1395
|
requireExternalSource, toolHandler(async (_args, ctx) => {
|
|
1355
1396
|
const { sessionId } = await sessionSink.createSession(ctx.user.id, new Date());
|
|
1356
|
-
|
|
1397
|
+
const firstRun = await firstRunFor(ctx);
|
|
1398
|
+
return firstRun ? { sessionId, firstRun } : { sessionId };
|
|
1357
1399
|
}));
|
|
1400
|
+
/**
|
|
1401
|
+
* The `firstRun` note (see `first-run.ts`) while the default branch's
|
|
1402
|
+
* knowledge folder holds nothing but the starter guide, else null. Asked of
|
|
1403
|
+
* a clone that is ALREADY there — never one this call would have to make, so
|
|
1404
|
+
* the first call of a conversation does no clone — and never allowed to fail
|
|
1405
|
+
* the call: minting the id is what `start_session` is for, and the note is a
|
|
1406
|
+
* courtesy on top of it.
|
|
1407
|
+
*/
|
|
1408
|
+
const firstRunFor = async (ctx) => {
|
|
1409
|
+
try {
|
|
1410
|
+
if (!disk || !kb.isBranchModelConfigured())
|
|
1411
|
+
return null;
|
|
1412
|
+
const workspaceId = kb.defaultWorkspaceId();
|
|
1413
|
+
if (!(await ctx.workspaceService.hasBootstrappedWorkspace(workspaceId)))
|
|
1414
|
+
return null;
|
|
1415
|
+
const knowledgeDir = kb.layout.knowledgeBaseDir;
|
|
1416
|
+
// GATED LIKE A READ. The note says what the knowledge folder holds —
|
|
1417
|
+
// nothing, or a pack's pages still as the pack wrote them — so it goes
|
|
1418
|
+
// only to a caller who may read that folder, and judges the folder as
|
|
1419
|
+
// THEY may see it: a page they may not read does not make it old for
|
|
1420
|
+
// them (`mayRead` below), since reading the folder is no leave to learn
|
|
1421
|
+
// what restricted pages sit in it.
|
|
1422
|
+
if (!(await accessControl.canRead(workspaceId, ctx.user.email, knowledgeDir)))
|
|
1423
|
+
return null;
|
|
1424
|
+
const root = await ctx.workspaceService.getWorkspacePath(workspaceId);
|
|
1425
|
+
const mayRead = async (rels) => {
|
|
1426
|
+
const verdicts = await accessControl.canReadBatch(workspaceId, ctx.user.email, rels.map((rel) => `${knowledgeDir}/${rel}`));
|
|
1427
|
+
return new Map(rels.map((rel) => [rel, verdicts.get(`${knowledgeDir}/${rel}`) === true]));
|
|
1428
|
+
};
|
|
1429
|
+
// A starter pack's pages, still as the pack wrote them, are tasks to
|
|
1430
|
+
// fill in rather than pages anyone wrote: they leave the note standing,
|
|
1431
|
+
// and the note names what the pack suggests drafting first. A pack
|
|
1432
|
+
// page the caller may not read keeps the note away altogether: it
|
|
1433
|
+
// names the pack and what it suggests drafting, which is about pages
|
|
1434
|
+
// this caller is not to know of — in the checkout or gone from it.
|
|
1435
|
+
const starter = (await starterPacks?.firstRunStarter()) ?? null;
|
|
1436
|
+
const pages = starter ? await readableStarterPages(ctx, workspaceId, knowledgeDir, starter.pages) : undefined;
|
|
1437
|
+
if (starter && pages && pages.size < starter.pages.size)
|
|
1438
|
+
return null;
|
|
1439
|
+
if (!(await knowledgeFolderIsNew(disk, join(root, kbDirName), knowledgeDir, pages, mayRead)))
|
|
1440
|
+
return null;
|
|
1441
|
+
return firstRunNote(`${kbDirName}/${knowledgeDir}`, starter ?? undefined);
|
|
1442
|
+
}
|
|
1443
|
+
catch (err) {
|
|
1444
|
+
log.debug('start_session: could not tell whether the knowledge base is new', {
|
|
1445
|
+
error: err instanceof Error ? err.message : String(err),
|
|
1446
|
+
});
|
|
1447
|
+
return null;
|
|
1448
|
+
}
|
|
1449
|
+
};
|
|
1450
|
+
/** The starter pages (paths below the knowledge folder → text) the caller may read, and no other. */
|
|
1451
|
+
const readableStarterPages = async (ctx, workspaceId, knowledgeDir, pages) => {
|
|
1452
|
+
const rels = [...pages.keys()];
|
|
1453
|
+
const verdicts = await accessControl.canReadBatch(workspaceId, ctx.user.email, rels.map((rel) => `${knowledgeDir}/${rel}`));
|
|
1454
|
+
return new Map(rels.filter((rel) => verdicts.get(`${knowledgeDir}/${rel}`)).map((rel) => [rel, pages.get(rel)]));
|
|
1455
|
+
};
|
|
1358
1456
|
// ── reads ──────────────────────────────────────────────────────────────
|
|
1457
|
+
/**
|
|
1458
|
+
* What reading a workspace file ANSWERS, gate and all — `read_file`'s whole
|
|
1459
|
+
* behaviour minus the spill ref and the `offset`/`limit` slice, which are
|
|
1460
|
+
* that tool's own arguments.
|
|
1461
|
+
*
|
|
1462
|
+
* Factored out because a second tool has to answer the same way: `open_page`
|
|
1463
|
+
* (see `modules/embed`) promises the file's text "the way `read_file` does",
|
|
1464
|
+
* and the refusals `read_file` gives for a path the caller may not read or
|
|
1465
|
+
* one that does not exist. Any of that re-derived there would be a second
|
|
1466
|
+
* answer to a question with one correct answer — the access gate, the read
|
|
1467
|
+
* hook, the extraction and the not-found message all have to match, and a
|
|
1468
|
+
* copy drifts on the first change to any of them.
|
|
1469
|
+
*/
|
|
1470
|
+
const readForTool = async (branch, p, ctx) => {
|
|
1471
|
+
// The guide's name at the repository root answers with the platform's
|
|
1472
|
+
// guide, which is text the code owns and every agent may read: no gate
|
|
1473
|
+
// and no read hook for it. A file the knowledge base keeps under that
|
|
1474
|
+
// name is ITS OWN conventions page and is read as any file is — gated,
|
|
1475
|
+
// noted — and comes first, with the guide after it. A copy of the
|
|
1476
|
+
// guide an earlier release wrote to disk (still on a draft, say) is
|
|
1477
|
+
// recognised by its header and not served a second time.
|
|
1478
|
+
if (agentGuide && isAgentGuidePath(toKbRelative(p, kbDirName) ?? '')) {
|
|
1479
|
+
return { kind: 'text', text: await guideAt(branch, ctx, p) };
|
|
1480
|
+
}
|
|
1481
|
+
await notifyAgentRead(agentAccessGate, ctx, branch, p);
|
|
1482
|
+
await assertCanRead(readGateFor(branch, ctx), p);
|
|
1483
|
+
const fs = await ctx.getFilesystem(branch);
|
|
1484
|
+
// Reading (extraction, image and binary handling included) happens AFTER
|
|
1485
|
+
// the access gate and the read hook above — a document read is still a
|
|
1486
|
+
// KB read. ONE registry dispatch picks the reader by extension.
|
|
1487
|
+
const bytes = await orNotFound(p, async () => asBytes(await fs.readFile(p)));
|
|
1488
|
+
return readers.readerFor(p).read(bytes, p);
|
|
1489
|
+
};
|
|
1359
1490
|
mount({
|
|
1360
1491
|
name: 'read_file',
|
|
1361
1492
|
gated: true,
|
|
@@ -1397,26 +1528,7 @@ agentGuide) {
|
|
|
1397
1528
|
? content.slice(start, limit !== undefined ? start + limit : undefined)
|
|
1398
1529
|
: content;
|
|
1399
1530
|
};
|
|
1400
|
-
|
|
1401
|
-
// guide, which is text the code owns and every agent may read: no gate
|
|
1402
|
-
// and no read hook for it. A file the knowledge base keeps under that
|
|
1403
|
-
// name is ITS OWN conventions page and is read as any file is — gated,
|
|
1404
|
-
// noted — and comes first, with the guide after it. A copy of the
|
|
1405
|
-
// guide an earlier release wrote to disk (still on a draft, say) is
|
|
1406
|
-
// recognised by its header and not served a second time.
|
|
1407
|
-
if (agentGuide && isAgentGuidePath(toKbRelative(p, kbDirName) ?? '')) {
|
|
1408
|
-
return { path: p, content: slice(await guideAt(a.branch, ctx, p)) };
|
|
1409
|
-
}
|
|
1410
|
-
await notifyAgentRead(agentAccessGate, ctx, a.branch, p);
|
|
1411
|
-
await assertCanRead(readGateFor(a.branch, ctx), p);
|
|
1412
|
-
const fs = await ctx.getFilesystem(a.branch);
|
|
1413
|
-
// Reading (extraction, image and binary handling included) happens AFTER
|
|
1414
|
-
// the access gate and the read hook above — a document read is still a
|
|
1415
|
-
// KB read. ONE registry dispatch picks the reader by
|
|
1416
|
-
// extension; everything below just maps its ReadResult onto the tool's
|
|
1417
|
-
// result shape.
|
|
1418
|
-
const bytes = await orNotFound(p, async () => asBytes(await fs.readFile(p)));
|
|
1419
|
-
const result = await readers.readerFor(p).read(bytes, p);
|
|
1531
|
+
const result = await readForTool(a.branch, p, ctx);
|
|
1420
1532
|
// Images return the picture itself as an MCP image content block, so a
|
|
1421
1533
|
// multimodal model SEES it. The handler returns the `McpImageResult`
|
|
1422
1534
|
// sentinel; the MCP result shaping (`toCallToolResult` in
|
|
@@ -1583,8 +1695,8 @@ agentGuide) {
|
|
|
1583
1695
|
'never move or delete, judged like the dry runs (on a draft branch writes are not gated); `movable` judges the SOURCE ' +
|
|
1584
1696
|
'side only, so the destination still wants a `move_file` dry run. ' +
|
|
1585
1697
|
'For a folder, `descendants` counts the files under it at any depth; counting stops at 10000 and ' +
|
|
1586
|
-
'`descendantsTruncated` says so, past which `movable` and `deletable` are false
|
|
1587
|
-
'
|
|
1698
|
+
'`descendantsTruncated` says so, past which `movable` and `deletable` are false (not judged in full): run the ' +
|
|
1699
|
+
'`move_file` or `delete_folder` dry run for the real verdict.',
|
|
1588
1700
|
inputs: {
|
|
1589
1701
|
type: 'object',
|
|
1590
1702
|
properties: {
|
|
@@ -1734,7 +1846,11 @@ agentGuide) {
|
|
|
1734
1846
|
// `mime` below, so it is never passed through.
|
|
1735
1847
|
delete stat.mimeType;
|
|
1736
1848
|
const kind = stat.type === 'directory' ? 'folder' : 'file';
|
|
1737
|
-
const
|
|
1849
|
+
const onDisk = await onDiskSpelling(root, p);
|
|
1850
|
+
const managed = managedReason(onDisk, kind) !== undefined;
|
|
1851
|
+
// A nested `access.md` is managed — it never moves — yet deleted by
|
|
1852
|
+
// whoever may write it, so a FILE's delete is judged on its own rule.
|
|
1853
|
+
const undeletable = kind === 'file' ? fileDeleteRefusal(onDisk) !== undefined : managed;
|
|
1738
1854
|
const verdicts = await accessAt(branch, ctx, p);
|
|
1739
1855
|
const access = a.explainAccess === true ? { ...verdicts, ...(await explainAccessAt(branch, ctx, p, kind)) } : verdicts;
|
|
1740
1856
|
const link = !plain || viaLink !== undefined;
|
|
@@ -1753,7 +1869,7 @@ agentGuide) {
|
|
|
1753
1869
|
// `movable`/`deletable` false rather than judging part of a folder
|
|
1754
1870
|
// and calling it the whole (`delete_folder`'s dry run, which walks
|
|
1755
1871
|
// uncapped, remains the authority for a folder that large).
|
|
1756
|
-
const decided = managed || link;
|
|
1872
|
+
const decided = (managed && undeletable) || link;
|
|
1757
1873
|
const { files, links, truncated } = kind === 'folder'
|
|
1758
1874
|
? await filesUnder(fs, p, DESCENDANTS_CAP)
|
|
1759
1875
|
: { files: [p], links: [], truncated: false };
|
|
@@ -1774,9 +1890,9 @@ agentGuide) {
|
|
|
1774
1890
|
const out = {
|
|
1775
1891
|
...stat,
|
|
1776
1892
|
managed,
|
|
1777
|
-
movable: open,
|
|
1893
|
+
movable: open && !managed,
|
|
1778
1894
|
// delete_folder also refuses a folder holding a link.
|
|
1779
|
-
deletable: open && links.length === 0,
|
|
1895
|
+
deletable: open && !undeletable && links.length === 0,
|
|
1780
1896
|
access,
|
|
1781
1897
|
};
|
|
1782
1898
|
if (kind === 'folder') {
|
|
@@ -1806,7 +1922,7 @@ agentGuide) {
|
|
|
1806
1922
|
mount({
|
|
1807
1923
|
name: 'grep',
|
|
1808
1924
|
gated: true,
|
|
1809
|
-
description: 'Regex
|
|
1925
|
+
description: 'Regex search across the workspace. Returns `{ matches: [{ path, line, text }] }` (capped). Use to find where something is defined/referenced. `path` may name a DIRECTORY (searches the subtree) or a single FILE (searches just that file); a path with nothing at it is an error, never an empty result. Searches INSIDE Office and OpenDocument files (.docx/.pptx/.xlsx, .odt/.odp/.ods), PDFs and email files (.eml/.msg) via their extracted text — matches there carry the extraction\'s line numbers, and the `[slide N]`/`[sheet: Name]`/`[page N]`/`[from]`/`[subject]` marker lines locate them; a bounded number of not-yet-extracted documents is extracted per call, and the result notes how many were skipped (re-run to cover them).',
|
|
1810
1926
|
inputs: {
|
|
1811
1927
|
type: 'object',
|
|
1812
1928
|
properties: {
|
|
@@ -1947,6 +2063,8 @@ agentGuide) {
|
|
|
1947
2063
|
// ── writes (through the lock/commit pipeline) ───────────────────────────
|
|
1948
2064
|
mount({
|
|
1949
2065
|
name: 'write_file',
|
|
2066
|
+
// A mode that is not one of the three answers `bad_mode`, which lists them.
|
|
2067
|
+
refusesItself: ['mode'],
|
|
1950
2068
|
gated: true,
|
|
1951
2069
|
description: 'Write a workspace TEXT file. The change is committed + pushed as you. Returns `{ path, bytes, outcome }`, where `outcome` is ' +
|
|
1952
2070
|
'`created`, `replaced` or `updated`.' +
|
|
@@ -2019,6 +2137,8 @@ agentGuide) {
|
|
|
2019
2137
|
});
|
|
2020
2138
|
mount({
|
|
2021
2139
|
name: 'write_files',
|
|
2140
|
+
// A mode that is not one of the three answers `bad_mode`, which lists them.
|
|
2141
|
+
refusesItself: ['mode'],
|
|
2022
2142
|
gated: true,
|
|
2023
2143
|
description: 'Batch-write many files in ONE commit — far faster than calling write_file once per file when ' +
|
|
2024
2144
|
'creating many files at once (e.g. seeding a knowledge base). Each entry is `{ path, content }`, and the files it ' +
|
|
@@ -2079,9 +2199,11 @@ agentGuide) {
|
|
|
2079
2199
|
proposable: true,
|
|
2080
2200
|
handler: async (a, ctx) => {
|
|
2081
2201
|
const files = a.files ?? [];
|
|
2202
|
+
// The mode is judged before anything else, so an empty batch with a mode
|
|
2203
|
+
// that is not one answers `bad_mode` like any other call would.
|
|
2204
|
+
const mode = modeOf(a);
|
|
2082
2205
|
if (files.length === 0)
|
|
2083
2206
|
return { count: 0, files: [] };
|
|
2084
|
-
const mode = modeOf(a);
|
|
2085
2207
|
// The POLICY gate still judges the whole batch: a restricted run is a
|
|
2086
2208
|
// call that should not have been made at all, not a per-path outcome.
|
|
2087
2209
|
// The write hook is asked PER PATH, below, so a path it refuses is that
|
|
@@ -2306,11 +2428,9 @@ agentGuide) {
|
|
|
2306
2428
|
throw new ToolError(`"${path}" is a folder, not a file — use delete_folder to delete it and the files under it.`, 400);
|
|
2307
2429
|
}
|
|
2308
2430
|
const onDisk = await onDiskSpelling(root, path);
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
throw new ToolError(`${onDisk.slice(onDisk.lastIndexOf('/') + 1)} is a platform file and cannot be deleted through the agent tools.`, 400);
|
|
2313
|
-
}
|
|
2431
|
+
const refused = fileDeleteRefusal(onDisk);
|
|
2432
|
+
if (refused !== undefined)
|
|
2433
|
+
throw new ToolError(refused, 400);
|
|
2314
2434
|
await assertNoSymlinkOnPath(root, path, true);
|
|
2315
2435
|
if ((await writeBlocked(branch, ctx, [path])).length > 0)
|
|
2316
2436
|
throw await writeRefusal(branch, path);
|
|
@@ -2492,12 +2612,13 @@ agentGuide) {
|
|
|
2492
2612
|
gated: true,
|
|
2493
2613
|
// A plain string again: what refuses a move names the guide, and that is in
|
|
2494
2614
|
// the shared rules now, which are rebuilt from the layout where they live.
|
|
2495
|
-
description: 'Move or rename a workspace FILE or FOLDER; a folder moves recursively, with everything under it. `dest` is the full new path, not the folder to move into.
|
|
2615
|
+
description: 'Move or rename a workspace FILE or FOLDER; a folder moves recursively, with everything under it. `dest` is the full new path, not the folder to move into. Committed + pushed as you. ' +
|
|
2496
2616
|
'The destination must not exist — a move never overwrites a file or merges into a folder. Access follows the ' +
|
|
2497
2617
|
'DESTINATION folder, so a move can change what you (and others) may do with the file: the dry run answers ' +
|
|
2498
2618
|
'`{ src, dest, kind, descendants, access: { before, after }, accessChanges, allowed, reason? }`, where `access` is your ' +
|
|
2499
2619
|
'own `{ read, write, download, owner }` at the source and at the destination AS IT WILL BE once the move has landed, ' +
|
|
2500
|
-
'with every `access.md` inside a moved folder counted at its new place, and a move whose `accessChanges` is true wants `confirm: true`.'
|
|
2620
|
+
'with every `access.md` inside a moved folder counted at its new place, and a move whose `accessChanges` is true wants `confirm: true`. ' +
|
|
2621
|
+
'Links are rewritten by default, in one commit with the move: those in the moved files and those in other markdown files pointing at them (`links` reports them). `rewriteLinks: false` turns that off. Path mentions in plain prose or code are never changed.',
|
|
2501
2622
|
inputs: {
|
|
2502
2623
|
type: 'object',
|
|
2503
2624
|
properties: {
|
|
@@ -2506,6 +2627,7 @@ agentGuide) {
|
|
|
2506
2627
|
dest: wsPath(kbDirName, 'Destination path — the full new path; must not exist yet'),
|
|
2507
2628
|
dryRun: { type: 'boolean', description: 'Answer with the impact and change nothing.' },
|
|
2508
2629
|
confirm: { type: 'boolean', description: 'Required when the move changes your access. Set it only after a dry run.' },
|
|
2630
|
+
rewriteLinks: { type: 'boolean', description: 'Rewrite the links into, out of and between the moved files (default true). `false` moves without touching any link.' },
|
|
2509
2631
|
sessionId: SESSION_ID_INPUT,
|
|
2510
2632
|
},
|
|
2511
2633
|
required: ['branch', 'src', 'dest'],
|
|
@@ -2526,6 +2648,11 @@ agentGuide) {
|
|
|
2526
2648
|
confirmationRequired: { type: 'boolean', description: 'True when the call stopped for want of `confirm: true`.' },
|
|
2527
2649
|
message: str('One sentence on what happened (or did not).'),
|
|
2528
2650
|
moved: { type: 'boolean', description: 'True once the move landed.' },
|
|
2651
|
+
links: {
|
|
2652
|
+
type: 'object',
|
|
2653
|
+
description: 'The link rewrite, the same on a dry run and on the move: `{ filesEdited, linksRewritten, edits: [{ path, from, to }] (the first 100), ' +
|
|
2654
|
+
'notRewritten: [{ path, reason, links }], unsearched? }`. Absent with `rewriteLinks: false`.',
|
|
2655
|
+
},
|
|
2529
2656
|
},
|
|
2530
2657
|
required: ['src', 'dest', 'moved'],
|
|
2531
2658
|
},
|
|
@@ -2616,6 +2743,52 @@ agentGuide) {
|
|
|
2616
2743
|
: occupiedBy !== null
|
|
2617
2744
|
? entryExistsMessage(occupiedBy, dest)
|
|
2618
2745
|
: undefined;
|
|
2746
|
+
// The links are planned only for a move that may run: a refused one
|
|
2747
|
+
// reads no page. The plan is the same on a dry run and on the move.
|
|
2748
|
+
const rewriteLinks = a.rewriteLinks !== false;
|
|
2749
|
+
const linkPlan = rewriteLinks && reason === undefined
|
|
2750
|
+
? await planMoveLinks({
|
|
2751
|
+
src,
|
|
2752
|
+
dest,
|
|
2753
|
+
branch,
|
|
2754
|
+
kbDirName,
|
|
2755
|
+
allFiles: await (async () => {
|
|
2756
|
+
const { files, links } = await filesUnder(fs, kbDirName);
|
|
2757
|
+
const symlinks = new Set(links);
|
|
2758
|
+
return files.filter((f) => !symlinks.has(f));
|
|
2759
|
+
})(),
|
|
2760
|
+
canRead: (paths) => resolveReadableMap((wid, email, rels) => accessControl.canReadBatch(wid, email, rels), workspaceIdForBranch(branch), ctx.user.email, kbDirName, paths),
|
|
2761
|
+
writeBlocked: (paths) => writeBlocked(branch, ctx, paths),
|
|
2762
|
+
// Through the guarded filesystem the tools read with, never the raw
|
|
2763
|
+
// disk: a page replaced by a link since the listing is refused there
|
|
2764
|
+
// instead of read through to wherever the link points.
|
|
2765
|
+
readText: async (p) => String(await fs.readFile(p, { encoding: 'utf8' })),
|
|
2766
|
+
// The read hook, for every page the answer would NAME — an edited
|
|
2767
|
+
// one, one left with its links listed — and for no page merely
|
|
2768
|
+
// searched: naming is the disclosure, and the hook's refusal makes
|
|
2769
|
+
// the page one the caller cannot read, covered by the one sentence.
|
|
2770
|
+
readRefused: async (path) => {
|
|
2771
|
+
try {
|
|
2772
|
+
await notifyAgentRead(agentAccessGate, ctx, branch, path);
|
|
2773
|
+
return false;
|
|
2774
|
+
}
|
|
2775
|
+
catch {
|
|
2776
|
+
return true;
|
|
2777
|
+
}
|
|
2778
|
+
},
|
|
2779
|
+
// The write hook, for a page the move would edit, at its post-move path.
|
|
2780
|
+
writeRefusal: async (_lockAt, path) => {
|
|
2781
|
+
try {
|
|
2782
|
+
await assertAgentWriteAllowed(agentAccessGate, ctx, branch, path);
|
|
2783
|
+
return null;
|
|
2784
|
+
}
|
|
2785
|
+
catch (err) {
|
|
2786
|
+
return `refused: ${err instanceof Error ? err.message : String(err)}`;
|
|
2787
|
+
}
|
|
2788
|
+
},
|
|
2789
|
+
})
|
|
2790
|
+
: undefined;
|
|
2791
|
+
const moveReason = reason ?? linkPlan?.overCap;
|
|
2619
2792
|
const impact = {
|
|
2620
2793
|
src,
|
|
2621
2794
|
dest,
|
|
@@ -2623,8 +2796,9 @@ agentGuide) {
|
|
|
2623
2796
|
descendants,
|
|
2624
2797
|
access: { before, after },
|
|
2625
2798
|
accessChanges,
|
|
2626
|
-
allowed:
|
|
2627
|
-
...(
|
|
2799
|
+
allowed: moveReason === undefined,
|
|
2800
|
+
...(moveReason !== undefined ? { reason: moveReason } : {}),
|
|
2801
|
+
...(linkPlan ? { links: linkPlan.report } : {}),
|
|
2628
2802
|
};
|
|
2629
2803
|
if (a.dryRun === true)
|
|
2630
2804
|
return { ...impact, dryRun: true, moved: false };
|
|
@@ -2639,6 +2813,8 @@ agentGuide) {
|
|
|
2639
2813
|
}
|
|
2640
2814
|
if (collision)
|
|
2641
2815
|
throw new ToolError(reason, 409);
|
|
2816
|
+
if (linkPlan?.overCap !== undefined)
|
|
2817
|
+
throw new ToolError(linkPlan.overCap, 400);
|
|
2642
2818
|
if (accessChanges && a.confirm !== true) {
|
|
2643
2819
|
return {
|
|
2644
2820
|
...impact,
|
|
@@ -2651,7 +2827,42 @@ agentGuide) {
|
|
|
2651
2827
|
// no-replace move is what guarantees it. A destination created between
|
|
2652
2828
|
// the two — by another agent, or by the sidebar, which moves without
|
|
2653
2829
|
// taking this lock — comes back here as a refusal, not an overwrite.
|
|
2654
|
-
|
|
2830
|
+
if (linkPlan === undefined) {
|
|
2831
|
+
await asEntryExists(() => fs.moveFile(src, dest));
|
|
2832
|
+
}
|
|
2833
|
+
else {
|
|
2834
|
+
// The move and every link edit, one commit. Under the locks, each page
|
|
2835
|
+
// is checked to still hold the bytes its edit was computed from.
|
|
2836
|
+
const edits = linkPlan.edits.map((e) => ({ path: e.path, lockAt: e.lockAt, content: e.content }));
|
|
2837
|
+
const check = async () => {
|
|
2838
|
+
for (const e of linkPlan.edits) {
|
|
2839
|
+
const now = await fs.readFile(e.lockAt, { encoding: 'utf8' }).then(String, () => null);
|
|
2840
|
+
if (now !== e.original) {
|
|
2841
|
+
throw new ToolError(`"${e.lockAt}" changed while the move was being planned, so nothing was moved. Run the move again.`, 409);
|
|
2842
|
+
}
|
|
2843
|
+
}
|
|
2844
|
+
};
|
|
2845
|
+
const summary = `Move ${src} to ${dest}`.slice(0, 200);
|
|
2846
|
+
const locking = fs;
|
|
2847
|
+
try {
|
|
2848
|
+
if (typeof locking.moveWithEdits === 'function') {
|
|
2849
|
+
await asEntryExists(() => locking.moveWithEdits(src, dest, edits, summary, check));
|
|
2850
|
+
}
|
|
2851
|
+
else {
|
|
2852
|
+
// A filesystem without the one-commit move (none the agent is
|
|
2853
|
+
// handed for writing): the move, then each edit.
|
|
2854
|
+
await check();
|
|
2855
|
+
await asEntryExists(() => fs.moveFile(src, dest));
|
|
2856
|
+
for (const e of edits)
|
|
2857
|
+
await fs.writeFile(e.path, e.content);
|
|
2858
|
+
}
|
|
2859
|
+
}
|
|
2860
|
+
catch (err) {
|
|
2861
|
+
if (err instanceof MoveLockedError || err instanceof MoveRacedError)
|
|
2862
|
+
throw new ToolError(err.message, 409);
|
|
2863
|
+
throw err;
|
|
2864
|
+
}
|
|
2865
|
+
}
|
|
2655
2866
|
// Moving the last file — or a whole folder — out leaves the folder it
|
|
2656
2867
|
// came from in place, like a delete.
|
|
2657
2868
|
await keepFolderOf(fs, ctx, branch, src, kbDirName);
|
|
@@ -3065,6 +3276,8 @@ agentGuide) {
|
|
|
3065
3276
|
});
|
|
3066
3277
|
mount({
|
|
3067
3278
|
name: 'apply_file_upload',
|
|
3279
|
+
// A mode that is not one of the three answers `bad_mode`, which lists them.
|
|
3280
|
+
refusesItself: ['mode'],
|
|
3068
3281
|
gated: true,
|
|
3069
3282
|
description: 'Land a file you have already uploaded (see `request_file_upload`) in a folder on a branch, in ONE commit, as you. ' +
|
|
3070
3283
|
'A single file lands under the name it was sent with; a zip lands as its entries, keeping their folder structure. ' +
|
|
@@ -3127,6 +3340,169 @@ agentGuide) {
|
|
|
3127
3340
|
handler: async (a, ctx) => applyFileUpload(a, ctx, uploads),
|
|
3128
3341
|
});
|
|
3129
3342
|
}
|
|
3343
|
+
// ── downloads (bytes that never pass through the model, the other way) ──
|
|
3344
|
+
// The twin of the upload pair: `read_file` answers content INTO the
|
|
3345
|
+
// conversation, so an agent that needs exact bytes on its own disk had no
|
|
3346
|
+
// way to get them. `request_file_download` judges every file on its own,
|
|
3347
|
+
// captures the ones that pass, and answers a one-time link per file (and a
|
|
3348
|
+
// zip per requested folder) that any HTTP client can fetch.
|
|
3349
|
+
/** The type a file's link answers with: the reader's, as `file_stat` reports it — but never active content. */
|
|
3350
|
+
const downloadContentType = (p, bytes) => {
|
|
3351
|
+
const reader = readers.readerFor(p);
|
|
3352
|
+
const mime = fileTypeOf(reader, p, needsContent(reader) ? bytes : undefined).mime;
|
|
3353
|
+
// SVG and HTML run scripts wherever they are opened — saved to disk and
|
|
3354
|
+
// re-opened under `file://`, too — so they go out as bytes, as the app's
|
|
3355
|
+
// own Download button sends them.
|
|
3356
|
+
return ACTIVE_CONTENT_TYPES.has(mime) ? 'application/octet-stream' : mime;
|
|
3357
|
+
};
|
|
3358
|
+
if (downloads) {
|
|
3359
|
+
mount({
|
|
3360
|
+
name: 'request_file_download',
|
|
3361
|
+
gated: true,
|
|
3362
|
+
description: 'Copy knowledge-base files onto your own disk without their content passing through the conversation — the ' +
|
|
3363
|
+
'way out, as `request_file_upload` is the way in. Give `branch` and `paths` (files or folders). Every file, ' +
|
|
3364
|
+
'each one inside a folder too, is included only if you may read AND download that file. Returns ' +
|
|
3365
|
+
'`{ expiresAt, expiresInSeconds, files: [{ path, bytes, sha256, downloadUrl }], folders: [{ path, bytes, ' +
|
|
3366
|
+
'downloadUrl, files }], refused: [{ path, reason }] }`: a link per file, with its own content type, and per ' +
|
|
3367
|
+
`folder a zip at full repository paths (\`apply_file_upload\` it at \`${kbDirName}/\` to put every file back). ` +
|
|
3368
|
+
'Fetch with any HTTP client (`curl -o <name> "<downloadUrl>"`, or the address without its last segment and an ' +
|
|
3369
|
+
'`x-download-token` header). Each link works ONCE, for 15 minutes, and serves the files as they are now. ' +
|
|
3370
|
+
'Refused: `not found` (missing or named-but-unreadable; folders omit unreadable files), ' +
|
|
3371
|
+
'`download permission required`; no link when nothing is included. At most 500 MB per request.',
|
|
3372
|
+
inputs: {
|
|
3373
|
+
type: 'object',
|
|
3374
|
+
properties: {
|
|
3375
|
+
branch: BRANCH_INPUT,
|
|
3376
|
+
paths: {
|
|
3377
|
+
type: 'array',
|
|
3378
|
+
minItems: 1,
|
|
3379
|
+
items: { type: 'string' },
|
|
3380
|
+
description: `Files and folders to download, under \`${kbDirName}/\` (e.g. \`${kbDirName}/KnowledgeBase/Foo.md\`), with or without a leading slash — a path without that prefix is placed under \`${kbDirName}/\`.`,
|
|
3381
|
+
},
|
|
3382
|
+
sessionId: SESSION_ID_INPUT,
|
|
3383
|
+
},
|
|
3384
|
+
required: ['branch', 'paths'],
|
|
3385
|
+
additionalProperties: false,
|
|
3386
|
+
},
|
|
3387
|
+
outputs: {
|
|
3388
|
+
type: 'object',
|
|
3389
|
+
properties: {
|
|
3390
|
+
expiresAt: {
|
|
3391
|
+
type: ['string', 'null'],
|
|
3392
|
+
description: 'ISO-8601 instant after which every link of this answer is gone; null when no link was issued.',
|
|
3393
|
+
},
|
|
3394
|
+
expiresInSeconds: int('Seconds until `expiresAt`; 0 when no link was issued.'),
|
|
3395
|
+
files: {
|
|
3396
|
+
type: 'array',
|
|
3397
|
+
description: 'One entry per included file, each named once however many times it was asked for.',
|
|
3398
|
+
items: {
|
|
3399
|
+
type: 'object',
|
|
3400
|
+
properties: {
|
|
3401
|
+
path: str('The workspace path.'),
|
|
3402
|
+
bytes: int('Size in bytes.'),
|
|
3403
|
+
sha256: str('SHA-256 of the bytes the link serves, hex.'),
|
|
3404
|
+
downloadUrl: str('One-time link to the file itself.'),
|
|
3405
|
+
},
|
|
3406
|
+
required: ['path', 'bytes', 'sha256', 'downloadUrl'],
|
|
3407
|
+
},
|
|
3408
|
+
},
|
|
3409
|
+
folders: {
|
|
3410
|
+
type: 'array',
|
|
3411
|
+
description: 'One entry per requested folder that kept at least one file.',
|
|
3412
|
+
items: {
|
|
3413
|
+
type: 'object',
|
|
3414
|
+
properties: {
|
|
3415
|
+
path: str('The folder, as requested.'),
|
|
3416
|
+
bytes: int('Uncompressed total of the files in its zip.'),
|
|
3417
|
+
downloadUrl: str('One-time link to the zip.'),
|
|
3418
|
+
files: { type: 'array', items: { type: 'string' }, description: 'The workspace paths the zip holds.' },
|
|
3419
|
+
},
|
|
3420
|
+
required: ['path', 'bytes', 'downloadUrl', 'files'],
|
|
3421
|
+
},
|
|
3422
|
+
},
|
|
3423
|
+
refused: {
|
|
3424
|
+
type: 'array',
|
|
3425
|
+
description: 'Every path left out, with why.',
|
|
3426
|
+
items: {
|
|
3427
|
+
type: 'object',
|
|
3428
|
+
properties: { path: str('The path left out.'), reason: str('Why: `not found`, `download permission required`, or the deployment\'s own words.') },
|
|
3429
|
+
required: ['path', 'reason'],
|
|
3430
|
+
},
|
|
3431
|
+
},
|
|
3432
|
+
},
|
|
3433
|
+
required: ['expiresAt', 'expiresInSeconds', 'files', 'folders', 'refused'],
|
|
3434
|
+
},
|
|
3435
|
+
// A download is a READ: a read-only deployment still serves it. A
|
|
3436
|
+
// read-only CREDENTIAL may not take bytes out, though.
|
|
3437
|
+
write: false,
|
|
3438
|
+
writeScope: true,
|
|
3439
|
+
handler: async (a, ctx) => requestFileDownload(a, ctx, downloads),
|
|
3440
|
+
});
|
|
3441
|
+
}
|
|
3442
|
+
/** `request_file_download`'s handler: judge, capture, and issue the links. */
|
|
3443
|
+
async function requestFileDownload(a, ctx, store) {
|
|
3444
|
+
const branch = a.branch;
|
|
3445
|
+
const raw = a.paths;
|
|
3446
|
+
if (!Array.isArray(raw) || raw.length === 0 || raw.some((p) => typeof p !== 'string' || p.trim() === '')) {
|
|
3447
|
+
throw new ToolError('Name at least one path to download in `paths`: an array of file and folder paths.', 400);
|
|
3448
|
+
}
|
|
3449
|
+
// At the cap, say so before a branch is resolved; the slot below counts again.
|
|
3450
|
+
store.assertCanIssue(ctx.user);
|
|
3451
|
+
// Resolves (clones, if need be) the branch's workspace, as a read does —
|
|
3452
|
+
// so an unknown branch is the call's refusal, not every path's.
|
|
3453
|
+
await ctx.getFilesystem(branch);
|
|
3454
|
+
const workspaceId = workspaceIdForBranch(branch);
|
|
3455
|
+
const refusedSpelling = [];
|
|
3456
|
+
const requested = [];
|
|
3457
|
+
for (const p of raw) {
|
|
3458
|
+
try {
|
|
3459
|
+
// As written: a name may begin or end with a space, and trimming it
|
|
3460
|
+
// would ask for another file. A trailing slash is the one spelling
|
|
3461
|
+
// folded, so `Shared/` and `Shared` are one request, not two zips.
|
|
3462
|
+
requested.push(normalizeWorkspacePath(p, kbDirName).replace(/\/+$/, ''));
|
|
3463
|
+
}
|
|
3464
|
+
catch (err) {
|
|
3465
|
+
if (!hasHttpStatus(err))
|
|
3466
|
+
throw err;
|
|
3467
|
+
refusedSpelling.push({ path: p, reason: err.message });
|
|
3468
|
+
}
|
|
3469
|
+
}
|
|
3470
|
+
// A slot is taken before anything is built (a caller at the cap is told
|
|
3471
|
+
// so at once) and given back when nothing is issued.
|
|
3472
|
+
return store.withRequestSlot(ctx.user, async (issue) => {
|
|
3473
|
+
const built = await buildDownload(requested, {
|
|
3474
|
+
kbDirName,
|
|
3475
|
+
maxBytes: ZIP_DOWNLOAD_MAX_BYTES,
|
|
3476
|
+
maxFiles: DOWNLOAD_MAX_FILES,
|
|
3477
|
+
candidatesAt: (p) => ctx.workspaceService.downloadCandidatesAt(workspaceId, p),
|
|
3478
|
+
canReadBatch: (paths) => accessControl.canReadBatch(workspaceId, ctx.user.email, paths),
|
|
3479
|
+
canDownloadBatch: (paths) => accessControl.canDownloadBatch(workspaceId, ctx.user.email, paths),
|
|
3480
|
+
// The folder-level gate the app's zip route applies, before the files.
|
|
3481
|
+
canDownloadFolder: (p) => accessControl.canDownload(workspaceId, ctx.user.email, toKbRelative(p, kbDirName) ?? p),
|
|
3482
|
+
notifyRead: (p) => notifyAgentRead(agentAccessGate, ctx, branch, p),
|
|
3483
|
+
readFile: (p) => ctx.workspaceService.readFileBinary(workspaceId, p),
|
|
3484
|
+
contentTypeOf: downloadContentType,
|
|
3485
|
+
});
|
|
3486
|
+
const refused = [...refusedSpelling, ...built.refused];
|
|
3487
|
+
if (built.artifacts.length === 0) {
|
|
3488
|
+
return { expiresAt: null, expiresInSeconds: 0, files: [], folders: [], refused };
|
|
3489
|
+
}
|
|
3490
|
+
const issued = await issue(built.artifacts);
|
|
3491
|
+
const urls = issued.downloadUrls;
|
|
3492
|
+
return {
|
|
3493
|
+
expiresAt: issued.expiresAt,
|
|
3494
|
+
expiresInSeconds: issued.expiresInSeconds,
|
|
3495
|
+
files: built.files.map((f, i) => ({ ...f, downloadUrl: urls[i] })),
|
|
3496
|
+
folders: built.folders.map((f, i) => ({
|
|
3497
|
+
path: f.path,
|
|
3498
|
+
bytes: f.bytes,
|
|
3499
|
+
downloadUrl: urls[built.files.length + i],
|
|
3500
|
+
files: f.files,
|
|
3501
|
+
})),
|
|
3502
|
+
refused,
|
|
3503
|
+
};
|
|
3504
|
+
});
|
|
3505
|
+
}
|
|
3130
3506
|
// ── shell (internal-only) ───────────────────────────────────────────────
|
|
3131
3507
|
mount({
|
|
3132
3508
|
name: 'execute_command',
|
|
@@ -3309,5 +3685,7 @@ agentGuide) {
|
|
|
3309
3685
|
});
|
|
3310
3686
|
},
|
|
3311
3687
|
});
|
|
3688
|
+
// The one read `open_page` borrows — see `readForTool` above.
|
|
3689
|
+
return { readForTool };
|
|
3312
3690
|
}
|
|
3313
3691
|
//# sourceMappingURL=workspace.tools.js.map
|