@preventive/triage 1.0.0-alpha.8 → 1.0.0-alpha.80
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/LICENSE-APACHE +202 -0
- package/README.md +16 -0
- package/api/reap.ts +16 -78
- package/cli.js +6 -0
- package/client/dependency-paths.d.ts +3 -0
- package/client/dependency-paths.js +36 -0
- package/client/finding-link.js +305 -0
- package/client/linked-findings.d.ts +1 -0
- package/client/linked-findings.js +115 -0
- package/common/bundle-commit.d.ts +1 -0
- package/common/bundle-commit.js +4 -0
- package/common/bundle-compare-diff.d.ts +6 -0
- package/common/bundle-compare-diff.js +377 -0
- package/common/bundle-compare-inputs.d.ts +3 -0
- package/common/bundle-compare-inputs.js +141 -0
- package/common/bundle-compare-versions.js +172 -0
- package/common/bundle-comparison.d.ts +8 -0
- package/common/bundle-comparison.js +69 -0
- package/common/bundle-imports.js +20 -0
- package/common/bundle-metadata.d.ts +15 -0
- package/common/bundle-metadata.js +226 -0
- package/common/bundle-pkg-of.d.ts +1 -0
- package/common/bundle-pkg-of.js +90 -0
- package/common/bundle-reasons.d.ts +6 -0
- package/common/bundle-reasons.js +58 -0
- package/common/bundle-source-links.d.ts +6 -0
- package/common/bundle-source-links.js +216 -0
- package/common/bundle-sourcemap.d.ts +10 -0
- package/common/bundle-sourcemap.js +100 -0
- package/common/bundle-sources.d.ts +10 -0
- package/common/bundle-sources.js +374 -0
- package/common/bundle-stats.js +41 -0
- package/common/bundle-tabs.js +1 -0
- package/common/code-language.js +66 -0
- package/common/default-scan-models.ts +36 -0
- package/common/dependency-reviews.d.ts +18 -0
- package/common/dependency-reviews.js +64 -0
- package/common/finding-duplicates.js +63 -0
- package/common/finding-filters.js +313 -0
- package/common/finding-id.js +47 -0
- package/common/finding-repo.d.ts +5 -0
- package/common/finding-repo.js +67 -0
- package/common/github-issue-labels.d.ts +1 -0
- package/common/github-issue-labels.js +11 -0
- package/common/github-pr.ts +56 -0
- package/common/gzip.js +59 -0
- package/common/line-diff.d.ts +14 -0
- package/common/line-diff.js +181 -0
- package/common/linked-workspace-groups.js +63 -0
- package/common/managed/agent-tasks.ts +292 -0
- package/common/managed/comments.ts +43 -0
- package/common/managed/dependency-routes.js +25 -0
- package/common/managed/directory-packages.ts +28 -0
- package/common/managed/finding-detail.d.ts +5 -0
- package/common/managed/finding-detail.js +75 -0
- package/common/managed/finding-values.d.ts +2 -0
- package/common/managed/finding-values.js +138 -0
- package/common/managed/github-agents.ts +114 -0
- package/common/managed/github-logins.ts +49 -0
- package/common/managed/lite-name.d.ts +2 -0
- package/common/managed/lite-name.js +20 -0
- package/common/managed/npm-packages.d.ts +9 -0
- package/common/managed/npm-packages.js +63 -0
- package/common/managed/permissions.ts +31 -0
- package/common/managed/report-content.ts +72 -0
- package/common/managed/report-filter.ts +120 -0
- package/common/managed/repository-alias.ts +65 -0
- package/common/managed/review-view-routes.js +23 -0
- package/common/managed/risk-routes.js +30 -0
- package/common/managed/roles.ts +41 -0
- package/common/managed/routes.d.ts +2 -0
- package/common/managed/routes.js +385 -0
- package/common/managed/scan-models.ts +6 -0
- package/common/managed/stasis-config.ts +7 -0
- package/common/managed/team-app.d.ts +19 -0
- package/common/managed/team-app.js +129 -0
- package/common/managed/team-filters.js +26 -0
- package/common/managed/triage.ts +83 -0
- package/common/managed/upload-seal.ts +126 -0
- package/common/pretty-json.js +98 -0
- package/common/pretty-kinds.js +20 -0
- package/common/pretty-print.d.ts +6 -0
- package/common/pretty-print.js +36 -0
- package/common/pretty-sourcemap.js +70 -0
- package/common/repo-commit.d.ts +4 -0
- package/common/repo-commit.js +30 -0
- package/common/revalidation-conflicts.js +48 -0
- package/common/revalidation-input-groups.js +56 -0
- package/common/save-error-reason.ts +20 -7
- package/common/scan-server.ts +13 -0
- package/common/security-links.d.ts +5 -0
- package/common/security-links.js +33 -0
- package/common/server-info.ts +46 -0
- package/common/sourcemap-listing.js +78 -0
- package/common/sourcemap-mappings.js +136 -0
- package/common/sourcemap-unlist.js +85 -0
- package/common/stasis-files.d.ts +5 -0
- package/common/stasis-files.js +20 -0
- package/common/stasis-tgz.d.ts +6 -0
- package/common/stasis-tgz.js +27 -0
- package/common/utf8.d.ts +3 -0
- package/common/utf8.js +45 -0
- package/common/whitespace-insensitive.js +19 -0
- package/common/workspace-app.js +91 -0
- package/common/workspace-groups.js +176 -0
- package/out/activity.js +2 -0
- package/out/brotli-fallback.js +3 -3
- package/out/chunk-2XUEZHIP.js +28 -0
- package/out/chunk-55YIWY3H.js +5 -0
- package/out/chunk-5AVGKFMR.js +1 -0
- package/out/chunk-5CJKUV53.js +1 -0
- package/out/chunk-5EAVJAD2.js +3 -0
- package/out/chunk-5M2X3QPK.js +6 -0
- package/out/chunk-5QWPKTCE.js +40 -0
- package/out/chunk-6CCSTJWB.js +1 -0
- package/out/chunk-6VOB5WXX.js +2 -0
- package/out/chunk-6Y6PZ2BU.js +9 -0
- package/out/chunk-74JZTGTO.js +11 -0
- package/out/chunk-7BKKYVWR.js +7 -0
- package/out/chunk-7C7DWL7I.js +1 -0
- package/out/chunk-7HP2VYIC.js +2 -0
- package/out/chunk-7YFJUT2P.js +1 -0
- package/out/chunk-7YO4QV5P.js +1 -0
- package/out/chunk-A4BBBHQU.js +1 -0
- package/out/chunk-B64CTMVU.js +4 -0
- package/out/chunk-BEKYZCPX.js +14 -0
- package/out/chunk-C4Z6ZBXV.js +10 -0
- package/out/chunk-CU3FPB3P.js +1 -0
- package/out/chunk-DEVAORP2.js +1 -0
- package/out/chunk-DUASGS2O.js +8 -0
- package/out/chunk-DUS5ARE2.js +53 -0
- package/out/chunk-EEJA7JBI.js +13 -0
- package/out/chunk-FSU2PLJL.js +1 -0
- package/out/chunk-GBMAXAYK.js +3 -0
- package/out/chunk-GO7FT4OD.js +1 -0
- package/out/chunk-GX5UXWT4.js +1 -0
- package/out/chunk-ITUKKCCK.js +10 -0
- package/out/chunk-IYPY47MC.js +1 -0
- package/out/chunk-JXBRWLMA.js +4 -0
- package/out/chunk-K4XJHM2T.js +1 -0
- package/out/chunk-LBD3M3J6.js +1 -0
- package/out/chunk-LVSLM7HB.js +1 -0
- package/out/chunk-LVW7WWV4.js +1 -0
- package/out/chunk-MV66NL3G.js +3 -0
- package/out/chunk-N57OWFKY.js +15 -0
- package/out/chunk-NRPC74AM.js +1 -0
- package/out/chunk-OOJM4CTU.js +1 -0
- package/out/chunk-OWSEQOL5.js +1 -0
- package/out/chunk-PKLVXUEI.js +11 -0
- package/out/chunk-PLGH63UC.js +2 -0
- package/out/chunk-PNHBZGDD.js +1 -0
- package/out/chunk-PTFYDJUP.js +1 -0
- package/out/chunk-PWFUOLZK.js +17 -0
- package/out/chunk-PXK7EU4V.js +1 -0
- package/out/chunk-QD3IBSF4.js +7 -0
- package/out/chunk-QI66YA4F.js +1 -0
- package/out/chunk-QRKFPLA4.js +80 -0
- package/out/chunk-R3NZFXVR.js +1 -0
- package/out/chunk-R5O6FAW4.js +2 -0
- package/out/chunk-RPNO56H2.js +1 -0
- package/out/chunk-SSPDMA6D.js +1 -0
- package/out/chunk-SZWPYLPC.js +1 -0
- package/out/chunk-TUII34K2.js +1 -0
- package/out/chunk-UJP4PQJA.js +1 -0
- package/out/chunk-UJSJMXEG.js +1 -0
- package/out/chunk-UR4WYMIP.js +1 -0
- package/out/chunk-VHEXSGGP.js +1 -0
- package/out/chunk-VYYUMYVW.js +9 -0
- package/out/chunk-VZPPX6MV.js +1 -0
- package/out/chunk-WCDYSIKG.js +1 -0
- package/out/chunk-XM4RLC4A.js +2 -0
- package/out/chunk-YKCRCNYZ.js +266 -0
- package/out/chunk-ZQHLECTI.js +1 -0
- package/out/client-managed-import.js +4 -0
- package/out/client-managed.js +37 -0
- package/out/client-sync.js +11 -17
- package/out/compare.js +26 -0
- package/out/dialogs.js +40 -0
- package/out/github-issue-authorized.html +3 -0
- package/out/github-issue-authorized.js +1 -0
- package/out/graph.js +19 -4
- package/out/index.html +104 -24
- package/out/prism.js +14 -10
- package/out/scan.js +2 -0
- package/out/stasis.svg +20 -0
- package/out/terminal.js +367 -39
- package/out/view.css +1 -1
- package/out/view.js +19 -147
- package/package.json +409 -64
- package/risk/actions/findings.js +161 -0
- package/risk/actions/resolve.js +287 -0
- package/risk/actions/scripts/commands.js +182 -0
- package/risk/actions/scripts/grade.js +113 -0
- package/risk/actions/scripts/packages.js +123 -0
- package/risk/actions/scripts/shell.js +169 -0
- package/risk/actions/uses.js +94 -0
- package/risk/actions/workflow.js +183 -0
- package/risk/files/characters.js +341 -0
- package/risk/files/hosts.js +206 -0
- package/risk/files/readability.js +185 -0
- package/risk/files/runs-code.js +563 -0
- package/risk/files/script.js +402 -0
- package/risk/files/source-map-link.js +43 -0
- package/risk/files/stamps.js +47 -0
- package/risk/index.d.ts +294 -0
- package/risk/index.js +12 -0
- package/risk/npm/assess.js +285 -0
- package/risk/npm/combined.js +68 -0
- package/risk/npm/compare.js +236 -0
- package/risk/npm/dependencies.js +172 -0
- package/risk/npm/diff.js +79 -0
- package/risk/npm/downloads.js +84 -0
- package/risk/npm/files.js +445 -0
- package/risk/npm/held.js +67 -0
- package/risk/npm/install-scripts.js +34 -0
- package/risk/npm/malware.js +38 -0
- package/risk/npm/manifest.js +65 -0
- package/risk/npm/new-dependency.js +60 -0
- package/risk/npm/old-version.js +108 -0
- package/risk/npm/registry.js +393 -0
- package/risk/npm/release.js +85 -0
- package/risk/npm/score.js +59 -0
- package/risk/npm/specs.js +124 -0
- package/risk/npm/tarball.js +169 -0
- package/server-common/database-config.ts +16 -0
- package/server-common/initialize.ts +18 -0
- package/server-common/npm-advisories.ts +101 -0
- package/{server → server-common}/origin.ts +5 -5
- package/server-common/reap.ts +48 -0
- package/server-common/scan-config.ts +19 -0
- package/server-common/standalone.ts +29 -0
- package/server-common/storage-crypto.ts +182 -0
- package/server-common/storage-log.ts +38 -0
- package/server-common/vercel-blob.ts +103 -0
- package/server-e2e/app.ts +487 -0
- package/{server → server-e2e}/bus-receiver.ts +2 -1
- package/{server → server-e2e}/cli.js +9 -4
- package/{server → server-e2e}/config.ts +50 -42
- package/{server → server-e2e}/db-neon.ts +2 -2
- package/{server → server-e2e}/db-revision-sql.ts +1 -1
- package/{server → server-e2e}/db-stmt.ts +2 -2
- package/{server → server-e2e}/db.ts +7 -7
- package/{server → server-e2e}/http.ts +44 -13
- package/{server → server-e2e}/hub.ts +40 -9
- package/server-e2e/index.ts +17 -0
- package/server-e2e/lifecycle.ts +95 -0
- package/{server → server-e2e}/neon-driver.ts +2 -2
- package/{server → server-e2e}/npm-proxy.ts +12 -145
- package/{server → server-e2e}/objstore/blob-vercel.ts +10 -114
- package/{server → server-e2e}/objstore/blob.ts +1 -1
- package/{server → server-e2e}/objstore/fetch-mint-guard.ts +2 -2
- package/{server → server-e2e}/objstore/handlers.ts +9 -8
- package/{server → server-e2e}/objstore/init.ts +19 -27
- package/{server → server-e2e}/objstore/reaper.ts +1 -1
- package/{server → server-e2e}/objstore/rest-deny.ts +1 -1
- package/{server → server-e2e}/objstore/rest-mint.ts +3 -3
- package/{server → server-e2e}/objstore/rest.ts +3 -3
- package/{server → server-e2e}/objstore/store-neon.ts +6 -10
- package/{server → server-e2e}/objstore/store.ts +7 -7
- package/{server → server-e2e}/objstore/tokens.ts +2 -2
- package/{server → server-e2e}/pubsub.ts +12 -9
- package/{server → server-e2e}/sign.ts +4 -4
- package/{server → server-e2e}/sse-server.ts +60 -33
- package/{server → server-e2e}/static.ts +18 -17
- package/{server → server-e2e}/sync-handlers.ts +64 -30
- package/{server → server-e2e}/ws-server.ts +20 -9
- package/server-managed/activity.ts +247 -0
- package/server-managed/agent-merges.ts +109 -0
- package/server-managed/app-agents.ts +23 -0
- package/server-managed/avatar-store.ts +13 -0
- package/server-managed/blob-store.ts +26 -0
- package/server-managed/brotli.ts +10 -0
- package/server-managed/bundle-advisories.ts +79 -0
- package/server-managed/bundle-advisory-inventory.ts +85 -0
- package/server-managed/bundle-build-diagnostics.d.ts +10 -0
- package/server-managed/bundle-build-diagnostics.js +23 -0
- package/server-managed/bundle-build-leases.ts +41 -0
- package/server-managed/bundle-build-worker.js +380 -0
- package/server-managed/bundle-build.ts +326 -0
- package/server-managed/bundle-cache.ts +261 -0
- package/server-managed/bundle-catalog.ts +29 -0
- package/server-managed/bundle-commits.ts +133 -0
- package/server-managed/bundle-dependency-reviews.ts +91 -0
- package/server-managed/bundle-store.ts +24 -0
- package/server-managed/bundle-summary-cache.ts +139 -0
- package/server-managed/bundle-validation.ts +33 -0
- package/server-managed/bundle.ts +151 -0
- package/server-managed/cache-storage.ts +20 -0
- package/server-managed/cli.js +21 -0
- package/server-managed/combined.ts +43 -0
- package/server-managed/comments.ts +138 -0
- package/server-managed/commit-coauthors.ts +105 -0
- package/server-managed/commit-lockfiles.ts +78 -0
- package/server-managed/comparison.ts +51 -0
- package/server-managed/config.ts +163 -0
- package/server-managed/content-access.ts +15 -0
- package/server-managed/crypto.ts +25 -0
- package/server-managed/db-methods.ts +1914 -0
- package/server-managed/db-neon.ts +398 -0
- package/server-managed/db-schema.ts +263 -0
- package/server-managed/db-table-names.ts +22 -0
- package/server-managed/db.ts +149 -0
- package/server-managed/dependabot-access.ts +61 -0
- package/server-managed/dependabot-alerts.ts +180 -0
- package/server-managed/dependency-review-comments.ts +143 -0
- package/server-managed/dependency-reviews.ts +369 -0
- package/server-managed/github-accounts.ts +59 -0
- package/server-managed/github-actions.ts +71 -0
- package/server-managed/github-app.ts +347 -0
- package/server-managed/github-errors.ts +92 -0
- package/server-managed/github-graphql.ts +42 -0
- package/server-managed/github-issue-links.ts +264 -0
- package/server-managed/github-issue-oauth.ts +30 -0
- package/server-managed/github-issues.ts +157 -0
- package/server-managed/github-link-oauth.ts +56 -0
- package/server-managed/github-links.ts +204 -0
- package/server-managed/github-metadata.ts +213 -0
- package/server-managed/github-oauth.ts +264 -0
- package/server-managed/github-pulls.ts +257 -0
- package/server-managed/github-requests.ts +181 -0
- package/server-managed/github-users.ts +30 -0
- package/server-managed/github-values.ts +26 -0
- package/server-managed/history-windows.ts +172 -0
- package/server-managed/http-response.ts +76 -0
- package/server-managed/http.ts +6324 -0
- package/server-managed/import-triage.ts +51 -0
- package/server-managed/index.ts +204 -0
- package/server-managed/kept-briefly.ts +37 -0
- package/server-managed/kept.ts +28 -0
- package/server-managed/link-reports.ts +149 -0
- package/server-managed/listed-activity.ts +39 -0
- package/server-managed/locked-packages.ts +234 -0
- package/server-managed/lockfile-scope.ts +58 -0
- package/server-managed/lru.ts +30 -0
- package/server-managed/managed-issues.ts +92 -0
- package/server-managed/management-catalog.ts +45 -0
- package/server-managed/management.ts +116 -0
- package/server-managed/npm-delta-worker.js +142 -0
- package/server-managed/npm-delta.ts +277 -0
- package/server-managed/npm-insights.ts +455 -0
- package/server-managed/npm-kept.ts +265 -0
- package/server-managed/npm-loads.ts +259 -0
- package/server-managed/npm-manifest.ts +117 -0
- package/server-managed/npm-packages.ts +469 -0
- package/server-managed/npm-patch-paths.ts +86 -0
- package/server-managed/npm-patch.ts +455 -0
- package/server-managed/npm-provenance.ts +127 -0
- package/server-managed/npm-risk.ts +287 -0
- package/server-managed/object-storage-disk.ts +147 -0
- package/server-managed/object-storage-vercel.ts +71 -0
- package/server-managed/object-storage.ts +82 -0
- package/server-managed/package-entry-points.ts +127 -0
- package/server-managed/pretty-copies.ts +22 -0
- package/server-managed/pretty-format.d.ts +3 -0
- package/server-managed/pretty-format.js +13 -0
- package/server-managed/pretty-print.ts +442 -0
- package/server-managed/public-workspace.ts +243 -0
- package/server-managed/pull-comment-reviews.ts +161 -0
- package/server-managed/pull-dependencies.ts +370 -0
- package/server-managed/pull-dependency-reviews.ts +407 -0
- package/server-managed/pull-reviews.ts +202 -0
- package/server-managed/queue.ts +54 -0
- package/server-managed/release-commits.ts +85 -0
- package/server-managed/rename-diff-worker.js +30 -0
- package/server-managed/rename-diff.ts +237 -0
- package/server-managed/repo-path.ts +21 -0
- package/server-managed/report-migration.ts +32 -0
- package/server-managed/report-opening.ts +77 -0
- package/server-managed/report-query.ts +10 -0
- package/server-managed/report-response.ts +16 -0
- package/server-managed/report-sources.ts +185 -0
- package/server-managed/report-store.ts +77 -0
- package/server-managed/repository-actions.ts +220 -0
- package/server-managed/repository-agents.ts +422 -0
- package/server-managed/repository-aliases.ts +119 -0
- package/server-managed/repository-browser.ts +361 -0
- package/server-managed/repository-changes.ts +280 -0
- package/server-managed/repository-code.ts +222 -0
- package/server-managed/repository-dependency-reviews.ts +182 -0
- package/server-managed/repository-discovery.ts +83 -0
- package/server-managed/repository-history.ts +428 -0
- package/server-managed/repository-issues.ts +293 -0
- package/server-managed/repository-policy.ts +27 -0
- package/server-managed/repository-pulls.ts +207 -0
- package/server-managed/repository-pulse.ts +477 -0
- package/server-managed/repository-risk-assess.ts +108 -0
- package/server-managed/repository-risk-audit.ts +78 -0
- package/server-managed/repository-risk-caches.ts +37 -0
- package/server-managed/repository-risk-read.ts +260 -0
- package/server-managed/repository-risk-stasis.ts +61 -0
- package/server-managed/repository-risk-turn.ts +97 -0
- package/server-managed/repository-risk.ts +516 -0
- package/server-managed/repository-squashes.ts +160 -0
- package/server-managed/repository-stamp.ts +41 -0
- package/server-managed/request-timing.ts +63 -0
- package/server-managed/reviewed-dependencies.ts +170 -0
- package/server-managed/revisions.ts +35 -0
- package/server-managed/scan-downloads.ts +121 -0
- package/server-managed/session.ts +132 -0
- package/server-managed/slugs.ts +38 -0
- package/server-managed/solidity-entry-points.ts +71 -0
- package/server-managed/sql-postgres.ts +34 -0
- package/server-managed/sql.ts +107 -0
- package/server-managed/stasis-config.ts +147 -0
- package/server-managed/stasis-dependencies.ts +221 -0
- package/server-managed/static.ts +28 -0
- package/server-managed/storage-command.ts +16 -0
- package/server-managed/storage-db.ts +183 -0
- package/server-managed/storage-encryption.ts +288 -0
- package/server-managed/storage-maintenance.ts +259 -0
- package/server-managed/storage-payload.ts +121 -0
- package/server-managed/storage-stores.ts +91 -0
- package/server-managed/storage.ts +82 -0
- package/server-managed/team-app-summaries.ts +56 -0
- package/server-managed/team-app.ts +156 -0
- package/server-managed/team-catalog.ts +7 -0
- package/server-managed/team-feed.ts +180 -0
- package/server-managed/team-npm-scopes.ts +103 -0
- package/server-managed/team-reports.ts +368 -0
- package/server-managed/triage-response.ts +16 -0
- package/server-managed/type-only-proof.js +161 -0
- package/server-managed/type-only-worker.js +31 -0
- package/server-managed/type-only.ts +135 -0
- package/server-managed/uploads.ts +106 -0
- package/server-managed/upstream-cache.ts +256 -0
- package/server-managed/view-as.ts +58 -0
- package/server-managed/worker-turns.ts +76 -0
- package/server-managed/workspace-shares.ts +170 -0
- package/server.ts +70 -0
- package/strip-types-loader.js +13 -10
- package/server/index.ts +0 -480
- package/server/lifecycle.ts +0 -208
- /package/{LICENSE → LICENSE-MIT} +0 -0
- /package/{server → server-e2e}/auth.ts +0 -0
- /package/{server → server-e2e}/config.example.json +0 -0
- /package/{server → server-e2e}/objstore/blob-fs.ts +0 -0
- /package/{server → server-e2e}/objstore/fs.ts +0 -0
- /package/{server → server-e2e}/objstore/sign.ts +0 -0
- /package/{server → server-e2e}/peer.ts +0 -0
- /package/{server → server-e2e}/sse-session.ts +0 -0
- /package/{server → server-e2e}/util.ts +0 -0
- /package/{server → server-e2e}/validation.ts +0 -0
|
@@ -26,6 +26,8 @@ type WireRevision = {
|
|
|
26
26
|
signature: string
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
type SubscriptionLookup = { resume: () => void }
|
|
30
|
+
|
|
29
31
|
// Structured result of the shared save pipeline (`commitSave`), rendered
|
|
30
32
|
// per transport: WS → protocol frames; REST → JSON + HTTP status.
|
|
31
33
|
type SaveOutcome =
|
|
@@ -79,6 +81,7 @@ export type SyncHandlersDeps = {
|
|
|
79
81
|
// payload budget. Optional: a SQLite deployment passes a no-op.
|
|
80
82
|
publishRevision: (tag: string, revisionId: string) => void
|
|
81
83
|
subscribe: (socket: WebSocket, tag: string) => void
|
|
84
|
+
pauseBroadcasts: (socket: WebSocket) => () => void
|
|
82
85
|
getNonce: (socket: WebSocket) => string | undefined
|
|
83
86
|
requiresAuth: (socket: WebSocket) => boolean
|
|
84
87
|
// Whether an operator password is configured. The REST save plane's
|
|
@@ -101,7 +104,7 @@ export type SyncHandlersDeps = {
|
|
|
101
104
|
export type SyncHandlers = {
|
|
102
105
|
handleSave: (socket: WebSocket, msg: SaveMsg) => Promise<void>
|
|
103
106
|
// Session-independent REST save plane (`POST /api/sync/save`), wired into
|
|
104
|
-
// the HTTP dispatcher in server/http.ts. Runs the same pipeline as
|
|
107
|
+
// the HTTP dispatcher in server-e2e/http.ts. Runs the same pipeline as
|
|
105
108
|
// `handleSave` and renders the outcome as a JSON response.
|
|
106
109
|
handleSaveRest: (req: IncomingMessage, res: ServerResponse) => Promise<void>
|
|
107
110
|
handleSubscribe: (socket: WebSocket, msg: SubscribeMsg) => Promise<void>
|
|
@@ -112,6 +115,9 @@ export type SyncHandlers = {
|
|
|
112
115
|
|
|
113
116
|
export function createSyncHandlers(deps: SyncHandlersDeps): SyncHandlers {
|
|
114
117
|
const { handle, send, broadcast, publishRevision, subscribe, getNonce, requiresAuth, passwordConfigured, sendUnauthorized, workspaceExists, objstoreResources, debug } = deps
|
|
118
|
+
// Only the newest lookup for a socket/tag may publish a snapshot.
|
|
119
|
+
// Versions cannot order different object incarnations (or deletions).
|
|
120
|
+
const subscriptionLookups = new WeakMap<WebSocket, Map<string, SubscriptionLookup>>()
|
|
115
121
|
|
|
116
122
|
// Typed wrapper for the three `workspace-save-error` emit sites
|
|
117
123
|
// (too-large at handleSave, stale-base after the catch-up, busy at
|
|
@@ -238,6 +244,14 @@ export function createSyncHandlers(deps: SyncHandlersDeps): SyncHandlers {
|
|
|
238
244
|
// chain in the 409 body. Either way the catch-up clears the client's
|
|
239
245
|
// pending and the error is a no-op on the now-missing pending (a
|
|
240
246
|
// recoverable race — client rebases + re-saves).
|
|
247
|
+
//
|
|
248
|
+
// The catch-up CAN be empty: a client holding a base from a chain
|
|
249
|
+
// this deployment no longer has (wiped / moved DB, SQLite→Neon
|
|
250
|
+
// migration — head=null, no keyframe, no rows) gets `revisions: []`.
|
|
251
|
+
// The client detects that shape (pending survives the catch-up) and
|
|
252
|
+
// answers with a full-state push re-anchored at base=null, which
|
|
253
|
+
// commits as the new chain root — see the client's
|
|
254
|
+
// `handleSaveError` stale-base branch.
|
|
241
255
|
const revisions = chainForWire(await chainFrom(handle, tag, baseNorm))
|
|
242
256
|
if (debug) console.log(`save (stale base ${baseNorm} vs head ${commit.head}) → chain ${revisions.length}`)
|
|
243
257
|
return { kind: 'stale-base', base: baseNorm, revisions }
|
|
@@ -291,7 +305,7 @@ export function createSyncHandlers(deps: SyncHandlersDeps): SyncHandlers {
|
|
|
291
305
|
// maps the outcome to a JSON + HTTP status the client switches on. SSE-mode
|
|
292
306
|
// clients POST here so a save doesn't take over their event-stream; a 401
|
|
293
307
|
// routes them to the in-band frame (which runs the operator auth flow).
|
|
294
|
-
// Mounted + gated (same-origin, shutdown, idle-timeout) in server/http.ts.
|
|
308
|
+
// Mounted + gated (same-origin, shutdown, idle-timeout) in server-e2e/http.ts.
|
|
295
309
|
async function handleSaveRest(req: IncomingMessage, res: ServerResponse): Promise<void> {
|
|
296
310
|
const body = await readSaveBody(req)
|
|
297
311
|
if (!body || typeof body !== 'object') { respondJson(res, 400, { reason: 'bad-request' }); return }
|
|
@@ -340,34 +354,54 @@ export function createSyncHandlers(deps: SyncHandlersDeps): SyncHandlers {
|
|
|
340
354
|
return
|
|
341
355
|
}
|
|
342
356
|
const tag = msg.workspaceTag
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
//
|
|
350
|
-
//
|
|
351
|
-
//
|
|
352
|
-
//
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
357
|
+
const lookups = subscriptionLookups.get(socket) ?? new Map<string, SubscriptionLookup>()
|
|
358
|
+
subscriptionLookups.set(socket, lookups)
|
|
359
|
+
const previous = lookups.get(tag)
|
|
360
|
+
const resume = deps.pauseBroadcasts(socket)
|
|
361
|
+
const lookup = { resume }
|
|
362
|
+
lookups.set(tag, lookup)
|
|
363
|
+
// Acquire the replacement's pause before releasing its predecessor so
|
|
364
|
+
// buffered broadcasts cannot overtake the replacement snapshot. A hung
|
|
365
|
+
// obsolete read must not keep the whole socket paused. The hub's release
|
|
366
|
+
// is idempotent, so the old finally can still call it when the read ends.
|
|
367
|
+
previous?.resume()
|
|
368
|
+
try {
|
|
369
|
+
subscribe(socket, tag)
|
|
370
|
+
// Explicit ack — distinguishes "the server processed my subscribe
|
|
371
|
+
// and registered me as a peer" from "the WebSocket is open". A
|
|
372
|
+
// client that sent a malformed / bad-sig subscribe never gets this;
|
|
373
|
+
// a client that did gets one before the chain arrives. Lets the UI
|
|
374
|
+
// surface a `connecting → online` transition based on real handshake
|
|
375
|
+
// completion, not just socket state.
|
|
376
|
+
//
|
|
377
|
+
// The ack also carries the objstore inventory snapshot: the same
|
|
378
|
+
// subscribe that registers this socket for objstore-put / -deleted
|
|
379
|
+
// broadcasts seeds the client's initial inventory in one handshake.
|
|
380
|
+
// The client keeps it live thereafter from those broadcasts.
|
|
381
|
+
// Returns [] for a triage-only workspace. A lookup failure is NOT an
|
|
382
|
+
// empty inventory: clients interpret absent resources as deletions.
|
|
383
|
+
// Reconnect to retry the complete handshake on either transport.
|
|
384
|
+
const resources = await objstoreResources(tag)
|
|
385
|
+
if (socket.readyState !== socket.OPEN || lookups.get(tag) !== lookup) return
|
|
386
|
+
// `from` is the last revision id the client claims to have applied —
|
|
387
|
+
// now a base64url string, not an integer. We send only revisions
|
|
388
|
+
// after that. Client lying about `from` just means they get a
|
|
389
|
+
// smaller catch-up — their subsequent saves will reveal stale state
|
|
390
|
+
// on the usual base-mismatch path. Null / missing → full chain.
|
|
391
|
+
const fromId = typeof msg.from === 'string' ? msg.from : null
|
|
392
|
+
const revisions = chainForWire(await chainFrom(handle, tag, fromId))
|
|
393
|
+
if (socket.readyState !== socket.OPEN || lookups.get(tag) !== lookup) return
|
|
394
|
+
if (debug) console.log(`subscribe ${debugTag(tag)} from=${fromId?.slice(0, 8) ?? 'null'} → chain ${revisions.length}`)
|
|
395
|
+
send(socket, { type: 'workspace-subscribed', workspaceTag: tag, resources })
|
|
396
|
+
send(socket, { type: 'workspace-state', workspaceTag: tag, revisions })
|
|
397
|
+
} catch (err) {
|
|
398
|
+
if (lookups.get(tag) !== lookup) return
|
|
399
|
+
if (debug) console.warn('subscribe: snapshot lookup failed', debugTag(tag), err)
|
|
400
|
+
socket.close(1011, 'subscription unavailable')
|
|
401
|
+
} finally {
|
|
402
|
+
if (lookups.get(tag) === lookup) lookups.delete(tag)
|
|
403
|
+
resume()
|
|
404
|
+
}
|
|
371
405
|
}
|
|
372
406
|
|
|
373
407
|
return { handleSave, handleSaveRest, handleSubscribe, sendSaveError }
|
|
@@ -16,6 +16,7 @@ import { Buffer } from 'node:buffer'
|
|
|
16
16
|
import type { IncomingMessage as HttpRequest } from 'node:http'
|
|
17
17
|
import { decodeUtf8 } from '../common/utf8.js'
|
|
18
18
|
import type { SaveErrorReason } from '../common/save-error-reason.ts'
|
|
19
|
+
import type { ServerInfo } from '../common/server-info.ts'
|
|
19
20
|
import { Peer, type PeerRegistry } from './peer.ts'
|
|
20
21
|
import { errMsg, errStack, randomId } from './util.ts'
|
|
21
22
|
import type { SaveMsg, SubscribeMsg } from './sign.ts'
|
|
@@ -36,6 +37,9 @@ type IncomingMessage = {
|
|
|
36
37
|
// SSE path doesn't need them.
|
|
37
38
|
export type PeerConnectionDeps = {
|
|
38
39
|
peers: PeerRegistry
|
|
40
|
+
// The mode this server advertises, emitted as the first `server-info`
|
|
41
|
+
// frame on every connection (see setupPeerConnection).
|
|
42
|
+
serverInfo: ServerInfo
|
|
39
43
|
send: (socket: WebSocket, msg: object) => void
|
|
40
44
|
unsubscribeAll: (socket: WebSocket) => void
|
|
41
45
|
handleSave: (socket: WebSocket, msg: SaveMsg) => Promise<void>
|
|
@@ -60,7 +64,7 @@ export type WsServerDeps = PeerConnectionDeps & {
|
|
|
60
64
|
// `as unknown as WebSocket`; only the subset both expose is used.
|
|
61
65
|
export function setupPeerConnection(socket: WebSocket, req: HttpRequest, deps: PeerConnectionDeps): void {
|
|
62
66
|
const {
|
|
63
|
-
peers, send, unsubscribeAll, handleSave, handleSubscribe, handleAuthenticate,
|
|
67
|
+
peers, serverInfo, send, unsubscribeAll, handleSave, handleSubscribe, handleAuthenticate,
|
|
64
68
|
sendSaveError, objstore, track, isShuttingDown, maxInflightPerSocket, debug,
|
|
65
69
|
} = deps
|
|
66
70
|
if (debug) console.log(`connect from ${req.socket.remoteAddress}`)
|
|
@@ -71,13 +75,20 @@ export function setupPeerConnection(socket: WebSocket, req: HttpRequest, deps: P
|
|
|
71
75
|
const peer = new Peer(randomId())
|
|
72
76
|
peers.set(socket, peer)
|
|
73
77
|
socket.on('pong', () => { peer.alive = true })
|
|
74
|
-
// Issue the per-connection challenge nonce
|
|
75
|
-
// send anything that needs it
|
|
76
|
-
//
|
|
77
|
-
//
|
|
78
|
-
//
|
|
78
|
+
// Issue the per-connection challenge nonce FIRST — before the client can
|
|
79
|
+
// send anything that needs it, AND as frame #0 so clients/tests that
|
|
80
|
+
// positionally read the first frame as the challenge keep working. The
|
|
81
|
+
// client signs it into every `workspace-subscribe` (see canonicalSubscribe
|
|
82
|
+
// in server-e2e/sign.ts); a captured subscribe frame can't be replayed from
|
|
83
|
+
// a different connection because that connection's nonce differs and the
|
|
79
84
|
// signature won't verify against the new canonical bytes. Round-9 H2.
|
|
80
85
|
send(socket, { type: 'challenge', nonce: peer.challenge })
|
|
86
|
+
// Then advertise the sync protocol (the mode probe), right after the
|
|
87
|
+
// challenge — the WS plane and the SSE fallback share this path. A client
|
|
88
|
+
// uses it to detect the mode, cache it, and refuse a cross-mode switch.
|
|
89
|
+
// Unauthenticated + mode-agnostic; an older client ignores it (predicate
|
|
90
|
+
// readers skip it; the workspaceTag demux drops it).
|
|
91
|
+
send(socket, { type: 'server-info', ...serverInfo })
|
|
81
92
|
// Per-socket handlers are DELIBERATELY NOT serialized (vs the
|
|
82
93
|
// client-side `messageQueue = messageQueue.then(...)` Promise
|
|
83
94
|
// chain inside `client/triage-sync.ts:onTransportMessage`).
|
|
@@ -86,10 +97,10 @@ export function setupPeerConnection(socket: WebSocket, req: HttpRequest, deps: P
|
|
|
86
97
|
// boundaries inside the handlers. Per-resource correctness needs
|
|
87
98
|
// no in-process lock: `commitRevision` resolves concurrent saves
|
|
88
99
|
// via its single gated INSERT (one snapshot + the
|
|
89
|
-
// `UNIQUE(workspace_tag, seq)` PK — see `server/db.ts`), and the
|
|
100
|
+
// `UNIQUE(workspace_tag, seq)` PK — see `server-e2e/db.ts`), and the
|
|
90
101
|
// objstore handlers (`commitPut` / `beginPut` / `deleteObject`)
|
|
91
102
|
// via the version compare-and-set + content-addressing (see
|
|
92
|
-
// `server/objstore/store.ts`), backed by post-await
|
|
103
|
+
// `server-e2e/objstore/store.ts`), backed by post-await
|
|
93
104
|
// `readyState === OPEN` rechecks in every objstore handler. The
|
|
94
105
|
// unbounded fan-out is capped by `maxInflightPerSocket` (see
|
|
95
106
|
// also the `'busy'` NACK at the cap below). Concurrent dispatch
|
|
@@ -129,7 +140,7 @@ export function setupPeerConnection(socket: WebSocket, req: HttpRequest, deps: P
|
|
|
129
140
|
// shedding load. Pings go through a fast inline `send(pong)`
|
|
130
141
|
// path BELOW that doesn't bump the per-socket inflight counter,
|
|
131
142
|
// so a ping-spam at the cap can't outrun the gate. Transport
|
|
132
|
-
// audit `server/index.ts:590` + post-#58 audit follow-up.
|
|
143
|
+
// audit `server-e2e/index.ts:590` + post-#58 audit follow-up.
|
|
133
144
|
if (parsed.type === 'ping') {
|
|
134
145
|
send(socket, { type: 'pong' })
|
|
135
146
|
return
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
// Persistent workspace activity. Uploads are recorded in the same transaction
|
|
2
|
+
// as their metadata; triage reuses its existing immutable trail, including
|
|
3
|
+
// legacy entries. Never copy annotation bodies or credentials into this feed.
|
|
4
|
+
import { randomUUID } from 'node:crypto'
|
|
5
|
+
import type { DatabaseSync } from 'node:sqlite'
|
|
6
|
+
import { type ManagedSql, sqliteTransaction } from './sql.ts'
|
|
7
|
+
import { inUserTeamScope } from './db-schema.ts'
|
|
8
|
+
|
|
9
|
+
export interface ActivityInput {
|
|
10
|
+
kind: 'access' | 'repository' | 'visibility' | 'delete'
|
|
11
|
+
actor: string
|
|
12
|
+
actorId?: string | null
|
|
13
|
+
action: string
|
|
14
|
+
repo?: string | null
|
|
15
|
+
reportId?: string | null
|
|
16
|
+
bundleId?: string | null
|
|
17
|
+
repoId?: number | null
|
|
18
|
+
repoDirectory?: string | null
|
|
19
|
+
report?: string | null
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface ActivityContext {
|
|
23
|
+
finding: string
|
|
24
|
+
reportId: string
|
|
25
|
+
report: string
|
|
26
|
+
repo: string | null
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// `actor` is the login of who acted as it is now, else the one recorded;
|
|
30
|
+
// `actorId` the user they are (null for a legacy login), and `actorName` the
|
|
31
|
+
// name they chose to show, as it is now.
|
|
32
|
+
export type ActivityEntry = {
|
|
33
|
+
id: string; kind: string; actor: string | null; actorId: string | null; actorName: string | null; action: string
|
|
34
|
+
repo: string | null; reportId: string | null; report: string | null
|
|
35
|
+
finding: string | null; at: number
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface ActivityQuery {
|
|
39
|
+
page: number
|
|
40
|
+
limit: number
|
|
41
|
+
kind: string
|
|
42
|
+
query: string
|
|
43
|
+
repo?: string
|
|
44
|
+
actor?: string
|
|
45
|
+
// null = admin; [] = no accessible findings. Context is supplied by the
|
|
46
|
+
// server, never by the client. It also replaces potentially private context
|
|
47
|
+
// from an old report carrying the same globally shared finding.
|
|
48
|
+
contexts: ActivityContext[] | null
|
|
49
|
+
userId?: string
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface ActivityFilters {
|
|
53
|
+
repos: string[]
|
|
54
|
+
// `id` is the actor's filter key; `userId` the user, null for a legacy login.
|
|
55
|
+
users: { id: string; userId: string | null; login: string; name: string | null; detail: string | null }[]
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface ActivityStore {
|
|
59
|
+
recordActivity(entry: ActivityInput, at: number): Promise<void>
|
|
60
|
+
listActivityReports(userId: string): Promise<Omit<ActivityContext, 'finding'>[]>
|
|
61
|
+
listActivity(query: ActivityQuery): Promise<{ history: ActivityEntry[]; total: number; page: number; limit: number; filters: ActivityFilters }>
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const triageFields = `'triage:' || e.seq AS id, 'triage' AS kind,
|
|
65
|
+
COALESCE(u.login, e.actor_login) AS actor, e.actor_id AS actorId,
|
|
66
|
+
CASE WHEN e.color IS NULL AND e.triage IS NULL AND e.comment IS NULL AND e.fix IS NULL AND e.flagged IS NULL
|
|
67
|
+
THEN 'cleared triage' ELSE 'updated triage' END AS action`
|
|
68
|
+
const commentFields = `'comment:' || e.seq AS id, 'triage' AS kind,
|
|
69
|
+
COALESCE(u.login, e.actor_login) AS actor, e.actor_id AS actorId, e.action`
|
|
70
|
+
// The events of a finding trail (`table`), with `fields` and the context each
|
|
71
|
+
// recorded.
|
|
72
|
+
const recordedEvents = (fields: string, table: string) => `SELECT ${fields}, e.repo, e.report_id AS reportId, e.report, e.finding_id AS finding, e.at
|
|
73
|
+
FROM ${table} e LEFT JOIN managed_user u ON u.id = e.actor_id`
|
|
74
|
+
const adminSource = `${recordedEvents(triageFields, 'managed_finding_triage_event')}
|
|
75
|
+
UNION ALL ${recordedEvents(commentFields, 'managed_finding_comment_event')} UNION ALL
|
|
76
|
+
SELECT id, kind, actor, actor_id AS actorId, action, repo, report_id AS reportId, report, NULL AS finding, at FROM managed_activity`
|
|
77
|
+
// The events of the accessible findings in a finding trail (`table`), with
|
|
78
|
+
// `fields` and the context the server gives each finding. Keep the finite
|
|
79
|
+
// set of accessible findings outside the indexed event lookup. Scanning all
|
|
80
|
+
// events against json_each for every row is quadratic.
|
|
81
|
+
const contextEvents = (fields: string, table: string) => `SELECT ${fields},
|
|
82
|
+
json_extract(c.value, '$.repo') AS repo, json_extract(c.value, '$.reportId') AS reportId,
|
|
83
|
+
json_extract(c.value, '$.report') AS report, e.finding_id AS finding, e.at
|
|
84
|
+
FROM json_each(:contexts) c
|
|
85
|
+
CROSS JOIN ${table} e ON e.finding_id = json_extract(c.value, '$.finding')
|
|
86
|
+
LEFT JOIN managed_user u ON u.id = e.actor_id`
|
|
87
|
+
const managerSource = `${contextEvents(triageFields, 'managed_finding_triage_event')}
|
|
88
|
+
UNION ALL ${contextEvents(commentFields, 'managed_finding_comment_event')}
|
|
89
|
+
UNION ALL SELECT a.id, a.kind, a.actor, a.actor_id AS actorId,
|
|
90
|
+
CASE WHEN a.kind = 'repository' THEN 'changed a report repository assignment' ELSE a.action END AS action,
|
|
91
|
+
p.full_name AS repo, r.id AS reportId, r.filename AS report, NULL AS finding, a.at
|
|
92
|
+
FROM managed_activity a JOIN managed_report r ON r.id = a.report_id
|
|
93
|
+
LEFT JOIN managed_selected_repo p ON p.repo_id = r.repo_id
|
|
94
|
+
WHERE ${inUserTeamScope(':userId', 'r')}
|
|
95
|
+
UNION ALL SELECT a.id, a.kind, a.actor, a.actor_id AS actorId,
|
|
96
|
+
CASE WHEN a.kind = 'repository' THEN 'changed a bundle repository assignment' ELSE a.action END AS action,
|
|
97
|
+
p.full_name AS repo, NULL AS reportId, b.filename AS report, NULL AS finding, a.at
|
|
98
|
+
FROM managed_activity a JOIN managed_bundle b ON b.id = a.bundle_id
|
|
99
|
+
LEFT JOIN managed_selected_repo p ON p.repo_id = b.repo_id
|
|
100
|
+
WHERE a.report_id IS NULL AND ${inUserTeamScope(':userId', 'b')}
|
|
101
|
+
UNION ALL SELECT a.id, a.kind, a.actor, a.actor_id AS actorId, a.action, a.repo, a.report_id AS reportId,
|
|
102
|
+
a.report, NULL AS finding, a.at FROM managed_activity a
|
|
103
|
+
WHERE a.kind = 'delete' AND (a.report_id IS NOT NULL OR a.bundle_id IS NOT NULL)
|
|
104
|
+
AND NOT EXISTS (SELECT 1 FROM managed_report WHERE id = a.report_id)
|
|
105
|
+
AND NOT EXISTS (SELECT 1 FROM managed_bundle WHERE id = a.bundle_id)
|
|
106
|
+
AND ${inUserTeamScope(':userId', 'a')}`
|
|
107
|
+
|
|
108
|
+
export const ACTIVITY_SCHEMA = `
|
|
109
|
+
CREATE TABLE IF NOT EXISTS managed_activity (
|
|
110
|
+
id TEXT PRIMARY KEY, kind TEXT NOT NULL, actor TEXT, action TEXT NOT NULL,
|
|
111
|
+
repo TEXT, report_id TEXT, report TEXT, at INTEGER NOT NULL,
|
|
112
|
+
bundle_id TEXT, repo_id INTEGER, repo_directory TEXT, actor_id TEXT
|
|
113
|
+
) STRICT;
|
|
114
|
+
CREATE INDEX IF NOT EXISTS managed_activity_at_idx ON managed_activity(at, id);
|
|
115
|
+
CREATE INDEX IF NOT EXISTS finding_triage_event_at_idx ON managed_finding_triage_event(at, seq);
|
|
116
|
+
`
|
|
117
|
+
|
|
118
|
+
export function initActivityMethods(db: DatabaseSync): void {
|
|
119
|
+
db.exec(ACTIVITY_SCHEMA)
|
|
120
|
+
migrateActivityScope(db)
|
|
121
|
+
db.exec('CREATE INDEX IF NOT EXISTS managed_activity_actor_at_idx ON managed_activity(actor_id, at)')
|
|
122
|
+
// Stable upload IDs make backfill idempotent, including after restarts.
|
|
123
|
+
// Snapshots deliberately have no cascading FKs: deletion is itself activity.
|
|
124
|
+
// CREATE TRIGGER IF NOT EXISTS keeps an older body; replace the one that
|
|
125
|
+
// predates server-built bundles so builds are not recorded as uploads.
|
|
126
|
+
const bundleTrigger = db.prepare("SELECT sql FROM sqlite_schema WHERE type = 'trigger' AND name = 'managed_bundle_activity'").get() as { sql: string } | undefined
|
|
127
|
+
if (bundleTrigger && !bundleTrigger.sql.includes('provenance')) db.exec('DROP TRIGGER managed_bundle_activity')
|
|
128
|
+
for (const type of ['report', 'bundle']) {
|
|
129
|
+
const columns = `id, kind, actor, action, repo, report_id, report, at, bundle_id, actor_id`
|
|
130
|
+
const values = (alias: string) => `'${type}-upload:' || ${alias}.id, 'upload',
|
|
131
|
+
COALESCE(${alias}.uploaded_by_login, (SELECT login FROM managed_user WHERE id = ${alias}.uploaded_by)), ${uploadAction(type, alias)},
|
|
132
|
+
(SELECT full_name FROM managed_selected_repo WHERE repo_id = ${alias}.repo_id),
|
|
133
|
+
${type === 'report' ? `${alias}.id` : 'NULL'}, ${alias}.filename, ${alias}.uploaded_at,
|
|
134
|
+
${type === 'bundle' ? `${alias}.id` : 'NULL'}, ${alias}.uploaded_by`
|
|
135
|
+
db.exec(`
|
|
136
|
+
CREATE TRIGGER IF NOT EXISTS managed_${type}_activity AFTER INSERT ON managed_${type}
|
|
137
|
+
BEGIN INSERT INTO managed_activity (${columns}) SELECT ${values('NEW')}; END;
|
|
138
|
+
INSERT OR IGNORE INTO managed_activity (${columns}) SELECT ${values('source')} FROM managed_${type} source;
|
|
139
|
+
`)
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// The creation entry for a stored report or bundle. Shared with the Postgres
|
|
144
|
+
// trigger function; `alias` is the trigger row (NEW) or a backfill alias.
|
|
145
|
+
export function uploadAction(type: string, alias: string): string {
|
|
146
|
+
return type === 'bundle' ? `CASE WHEN ${alias}.provenance = 'build' THEN 'built a bundle' ELSE 'uploaded a bundle' END` : `'uploaded a ${type}'`
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export function activityMethods(db: ManagedSql): ActivityStore {
|
|
150
|
+
const insert = db.prepare(`INSERT INTO managed_activity (id, kind, actor, action, repo, report_id, report, at, bundle_id, repo_id, repo_directory, actor_id)
|
|
151
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
|
152
|
+
const admin = activityStatements(db, adminSource)
|
|
153
|
+
const manager = activityStatements(db, managerSource)
|
|
154
|
+
const reports = db.prepare(`SELECT r.id AS reportId, r.filename AS report, p.full_name AS repo
|
|
155
|
+
FROM managed_report r JOIN managed_selected_repo p ON p.repo_id = r.repo_id
|
|
156
|
+
WHERE ${inUserTeamScope('?', 'r')}
|
|
157
|
+
ORDER BY r.uploaded_at DESC, r.id`)
|
|
158
|
+
return {
|
|
159
|
+
async recordActivity(entry, at) {
|
|
160
|
+
await insert.run(randomUUID(), entry.kind, entry.actor, entry.action, entry.repo ?? null, entry.reportId ?? null, entry.report ?? null, at,
|
|
161
|
+
entry.bundleId ?? null, entry.repoId ?? null, entry.repoDirectory ?? null, entry.actorId ?? null)
|
|
162
|
+
},
|
|
163
|
+
async listActivityReports(userId) {
|
|
164
|
+
return (await reports.all(userId)) as Omit<ActivityContext, 'finding'>[]
|
|
165
|
+
},
|
|
166
|
+
async listActivity({ page, limit, kind, query, repo = '', actor = '', contexts, userId }) {
|
|
167
|
+
const stmts = contexts == null ? admin : manager
|
|
168
|
+
const scope = contexts == null ? {} : { contexts: JSON.stringify(contexts), userId: userId ?? '' }
|
|
169
|
+
const params = { ...scope, kind, query, repo, actor }
|
|
170
|
+
const read = async (at: number) => (await stmts.rows.all({ ...params, limit, offset: (at - 1) * limit })) as (ActivityEntry & { total: number | string })[]
|
|
171
|
+
// A page's rows carry the total. Only a page past the last has none to
|
|
172
|
+
// carry it: it is counted, and the last page read in its place.
|
|
173
|
+
let currentPage = page, rows = await read(page)
|
|
174
|
+
let total = rows.length > 0 ? Number(rows[0]!.total) : 0
|
|
175
|
+
if (rows.length === 0 && page > 1) {
|
|
176
|
+
total = Number(((await stmts.count.get(params)) as { total: number | string }).total)
|
|
177
|
+
currentPage = Math.min(page, Math.max(1, Math.ceil(total / limit)))
|
|
178
|
+
if (currentPage !== page) rows = total === 0 ? [] : await read(currentPage)
|
|
179
|
+
}
|
|
180
|
+
const history = rows.map(({ total: _total, ...entry }) => entry)
|
|
181
|
+
const filters: ActivityFilters = { repos: [], users: [] }
|
|
182
|
+
type FacetRow = { facet: string; id: string; userId: string | null; login: string; name: string | null; detail: string | null }
|
|
183
|
+
for (const row of (await stmts.filters.all(scope)) as FacetRow[]) {
|
|
184
|
+
if (row.facet === 'repo') filters.repos.push(row.id)
|
|
185
|
+
else filters.users.push({ id: row.id, userId: row.userId, login: row.login, name: row.name, detail: row.detail })
|
|
186
|
+
}
|
|
187
|
+
return { history, total, page: currentPage, limit, filters }
|
|
188
|
+
},
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Both rows and selector choices come from the authorized source. Keep legacy
|
|
193
|
+
// login-only actors separate: a historical login is not proof of user identity.
|
|
194
|
+
// A user shows by their login and name as they are now, as in the selector.
|
|
195
|
+
function activityStatements(db: ManagedSql, source: string) {
|
|
196
|
+
const activity = `WITH events AS (${source}), activity AS (
|
|
197
|
+
SELECT e.id, e.kind, COALESCE(u.login, e.actor) AS actor, e.actorId, u.name AS actorName, e.action,
|
|
198
|
+
e.repo, e.reportId, e.report, e.finding, e.at, COALESCE('user:' || e.actorId, 'legacy:' || e.actor) AS actorKey
|
|
199
|
+
FROM events e LEFT JOIN managed_user u ON u.id = e.actorId
|
|
200
|
+
)`
|
|
201
|
+
const filtered = `${activity} SELECT id, kind, actor, actorId, actorName, action, repo, reportId, report, finding, at FROM activity
|
|
202
|
+
WHERE (:kind = 'all' OR kind = :kind)
|
|
203
|
+
AND (:repo = '' OR repo = :repo) AND (:actor = '' OR actorKey = :actor)
|
|
204
|
+
AND (:query = '' OR instr(lower(coalesce(actor, '') || ' ' || coalesce(actorName, '') || ' ' || action || ' ' ||
|
|
205
|
+
coalesce(repo, '') || ' ' || coalesce(report, '') || ' ' || coalesce(finding, '')), lower(:query)) > 0)`
|
|
206
|
+
// A page's rows each carry the total, so the source is read once for both;
|
|
207
|
+
// the selector choices, repositories then users, once between them.
|
|
208
|
+
return {
|
|
209
|
+
count: db.prepare(`SELECT count(*) AS total FROM (${filtered}) AS filtered`),
|
|
210
|
+
rows: db.prepare(`SELECT filtered.*, count(*) OVER () AS total FROM (${filtered}) AS filtered ORDER BY at DESC,
|
|
211
|
+
CASE WHEN kind = 'triage' THEN CAST(substr(id, instr(id, ':') + 1) AS INTEGER) ELSE 0 END DESC,
|
|
212
|
+
id DESC LIMIT :limit OFFSET :offset`),
|
|
213
|
+
filters: db.prepare(`${activity} SELECT 'repo' AS facet, repo AS id, NULL AS userId, repo AS login, NULL AS name, NULL AS detail,
|
|
214
|
+
repo AS sort, '' AS tiebreak
|
|
215
|
+
FROM (SELECT DISTINCT repo FROM activity WHERE repo IS NOT NULL AND repo <> '') AS repos
|
|
216
|
+
UNION ALL SELECT 'user' AS facet, a.actorKey AS id, a.actorId AS userId, COALESCE(a.actor, a.actorId) AS login, a.actorName AS name,
|
|
217
|
+
CASE WHEN a.actorId IS NULL THEN 'Legacy actor' ELSE NULL END AS detail, COALESCE(a.actor, a.actorId) AS sort, a.actorKey AS tiebreak FROM (
|
|
218
|
+
SELECT actorKey, actorId, actor, actorName, ROW_NUMBER() OVER (PARTITION BY actorKey ORDER BY at DESC, id DESC) AS position
|
|
219
|
+
FROM activity WHERE actorKey IS NOT NULL AND actorKey <> 'legacy:'
|
|
220
|
+
) a WHERE a.position = 1
|
|
221
|
+
ORDER BY facet, sort, tiebreak`),
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function migrateActivityScope(db: DatabaseSync): void {
|
|
226
|
+
const columns = new Set((db.prepare('PRAGMA table_info(managed_activity)').all() as { name: string }[]).map(column => column.name))
|
|
227
|
+
const missing = [['bundle_id', 'TEXT'], ['repo_id', 'INTEGER'], ['repo_directory', 'TEXT'], ['actor_id', 'TEXT']].filter(([name]) => !columns.has(name!))
|
|
228
|
+
if (missing.length === 0) return
|
|
229
|
+
sqliteTransaction(db, 'BEGIN', () => {
|
|
230
|
+
for (const [name, type] of missing) db.exec(`ALTER TABLE managed_activity ADD COLUMN ${name} ${type}`)
|
|
231
|
+
if (!columns.has('bundle_id') || !columns.has('actor_id')) {
|
|
232
|
+
db.exec('DROP TRIGGER IF EXISTS managed_report_activity; DROP TRIGGER IF EXISTS managed_bundle_activity;')
|
|
233
|
+
}
|
|
234
|
+
if (!columns.has('bundle_id')) db.exec("UPDATE managed_activity SET bundle_id = substr(id, 15) WHERE id LIKE 'bundle-upload:%'")
|
|
235
|
+
if (!columns.has('actor_id')) {
|
|
236
|
+
// Existing upload targets retain a reliable uploader identity. Do not
|
|
237
|
+
// guess identities from historical logins: names can change or be reused.
|
|
238
|
+
for (const type of ['report', 'bundle']) {
|
|
239
|
+
db.exec(`UPDATE managed_activity SET actor_id = (
|
|
240
|
+
SELECT uploaded_by FROM managed_${type} WHERE id = substr(managed_activity.id, 15)
|
|
241
|
+
) WHERE id LIKE '${type}-upload:%'`)
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
// Legacy deletions/assignments without a durable target/scope remain
|
|
245
|
+
// admin-only; neither filenames nor repository names authorize access.
|
|
246
|
+
})
|
|
247
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// The commits agents' pull requests brought to a repository's default
|
|
2
|
+
// branch, for its Pulse (repository-pulse.ts commitStats), as the pull
|
|
3
|
+
// requests kept tell them (repository-pulls.ts readPulls: whose each is,
|
|
4
|
+
// and what one merged brought).
|
|
5
|
+
import type { PullList } from './repository-pulls.ts'
|
|
6
|
+
import type { HistoryCommit } from './repository-history.ts'
|
|
7
|
+
|
|
8
|
+
// How long before or after a pull request rebased onto the branch was merged
|
|
9
|
+
// its copies are committed.
|
|
10
|
+
const REBASE_SKEW_MS = 10 * 60_000
|
|
11
|
+
|
|
12
|
+
// The agents' pull requests merged since a year's start, as read so far
|
|
13
|
+
// (agentMerges): the commits each brought, and when it was merged; those
|
|
14
|
+
// rebased onto the branch by their last commit there, when merged, and
|
|
15
|
+
// their commits' subjects, the oldest first (agentCommits); and how far the
|
|
16
|
+
// pull requests are read, as the list tells (repository-pulls.ts PullList:
|
|
17
|
+
// `through`, `reach`, `next`). And of every pull request merged, an agent's
|
|
18
|
+
// or not, its merge commit, when and its number (`pulls`, by which the
|
|
19
|
+
// Commits tab tells those squashed too, http.ts pulseMerges; none of one
|
|
20
|
+
// kept before numbers were), and one rebased so (`pullRebases`), for the
|
|
21
|
+
// commits pushed to the branch directly to be told (directCommits).
|
|
22
|
+
export interface AgentMerges extends Pick<PullList, 'through' | 'reach' | 'next'> { merges: [string, number][]; rebases: Rebase[]
|
|
23
|
+
pulls?: [sha: string, at: number, number?: number][]; pullRebases?: Rebase[] }
|
|
24
|
+
// A pull request rebased onto the branch: its last commit there, when it was
|
|
25
|
+
// merged, its latest commits' subjects, the oldest first, and how many more
|
|
26
|
+
// it had than those read (`more`).
|
|
27
|
+
type Rebase = [sha: string, at: number, subjects: string[], more?: number]
|
|
28
|
+
|
|
29
|
+
// What the pull requests merged since `since` of those read (`list`) brought:
|
|
30
|
+
// an agent's, its merge commit, a squash merge's one commit, and one merged
|
|
31
|
+
// with a merge commit, its own commits too; and every one's merge commit,
|
|
32
|
+
// those rebased by their commits' subjects.
|
|
33
|
+
export function agentMerges(list: PullList, since: number): AgentMerges {
|
|
34
|
+
const merges = new Map<string, number>()
|
|
35
|
+
const [rebases, pulls, pullRebases]: [Rebase[], [string, number, number][], Rebase[]] = [[], [], []]
|
|
36
|
+
for (const { number, merged } of list.rows) {
|
|
37
|
+
if (!merged || merged.at < since) continue
|
|
38
|
+
const { sha, at, subjects, more = 0 } = merged
|
|
39
|
+
const rebase: Rebase | null = subjects ? more > 0 ? [sha, at, subjects, more] : [sha, at, subjects] : null
|
|
40
|
+
pulls.push([sha, at, number])
|
|
41
|
+
if (rebase) pullRebases.push(rebase)
|
|
42
|
+
if (!merged.agent) continue
|
|
43
|
+
for (const oid of [sha, ...merged.own ?? []]) merges.set(oid, at)
|
|
44
|
+
if (rebase) rebases.push(rebase)
|
|
45
|
+
}
|
|
46
|
+
return { merges: [...merges], rebases, through: list.through, ...list.reach === undefined ? {} : { reach: list.reach }, next: list.next, pulls, pullRebases }
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Whether two reads of the pull requests merged (agentMerges) bring the
|
|
50
|
+
// same commits, the agents' and every one's (`pulls`, `pullRebases`, which
|
|
51
|
+
// tell those pushed directly), whatever order each read them in.
|
|
52
|
+
export function sameMerges(a: AgentMerges, b: AgentMerges) {
|
|
53
|
+
const sorted = (entries: unknown[] = []) => entries.map(entry => JSON.stringify(entry)).toSorted()
|
|
54
|
+
const brought = (read: AgentMerges) => JSON.stringify([read.merges, read.rebases, read.pulls, read.pullRebases].map(sorted))
|
|
55
|
+
return brought(a) === brought(b)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// A commit's subject as GitHub heads its message: whole, or, past what it
|
|
59
|
+
// shows, cut short before an ellipsis.
|
|
60
|
+
const headed = (subject: string, headline: string) => headline.endsWith('…') ? subject.startsWith(headline.slice(0, -1)) : subject === headline
|
|
61
|
+
|
|
62
|
+
// The commits of `commits` (a year's) the agents' pull requests brought
|
|
63
|
+
// (`read`, agentMerges): those it names, and of one rebased, its commits'
|
|
64
|
+
// copies, the last and those below it on their first parents, as long as
|
|
65
|
+
// each one's subject is that of one of its commits older than the last
|
|
66
|
+
// matched, as Commits tells a rebase (repository-squashes.ts squashedPulls),
|
|
67
|
+
// past those of its commits the rebase left none of (an empty one GitHub
|
|
68
|
+
// counted no files of), and, past them all, as many more as it had before
|
|
69
|
+
// its latest read; a squash merge's one commit alone, its subject the pull
|
|
70
|
+
// request's own.
|
|
71
|
+
export function agentCommits(read: AgentMerges, commits: HistoryCommit[]): Set<string> {
|
|
72
|
+
const shas = new Set(read.merges.map(([sha]) => sha))
|
|
73
|
+
const bySha = new Map(commits.map(commit => [commit.sha, commit]))
|
|
74
|
+
for (const [last, merged, subjects, more = 0] of read.rebases) {
|
|
75
|
+
let commit = bySha.get(last)
|
|
76
|
+
let at = subjects.length - 1
|
|
77
|
+
for (; commit && at >= 0; commit = bySha.get(commit.parents[0] ?? '')) {
|
|
78
|
+
const [copied, upTo] = [commit, at]
|
|
79
|
+
const found = subjects.findLastIndex((subject, index) => index <= upTo && headed(copied.subject, subject))
|
|
80
|
+
if (found < 0) break
|
|
81
|
+
shas.add(commit.sha)
|
|
82
|
+
at = found - 1
|
|
83
|
+
}
|
|
84
|
+
// Each of its latest commits read copied, as many as it had before them
|
|
85
|
+
// the commits below, on their first parents, as long as each was
|
|
86
|
+
// committed as it was merged, as a rebase commits its copies: not past
|
|
87
|
+
// its first, its empty ones, which a rebase leaves out, counted too.
|
|
88
|
+
const copiedAsMerged = (when: number | null) => when !== null && Math.abs(when - merged) <= REBASE_SKEW_MS
|
|
89
|
+
for (let rest = at < 0 ? more : 0; commit && rest > 0 && copiedAsMerged(commit.committedAt); rest--, commit = bySha.get(commit.parents[0] ?? '')) {
|
|
90
|
+
shas.add(commit.sha)
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return shas
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// The commits of `commits` (a year's, from the branch's `head`) pushed to
|
|
97
|
+
// it directly: on its first parents from the head, none a merge, none a
|
|
98
|
+
// pull request brought (`read.pulls`: its merge commit, a squash's one
|
|
99
|
+
// commit, or the copies of one rebased onto it, as agentCommits tells
|
|
100
|
+
// them); those a merge brought from its other parents, not.
|
|
101
|
+
export function directCommits(read: AgentMerges, commits: HistoryCommit[], head: string): Set<string> {
|
|
102
|
+
const pulled = agentCommits({ ...read, merges: (read.pulls ?? []).map(([sha, at]) => [sha, at]), rebases: read.pullRebases ?? [] }, commits)
|
|
103
|
+
const bySha = new Map(commits.map(commit => [commit.sha, commit]))
|
|
104
|
+
const direct = new Set<string>()
|
|
105
|
+
for (let commit = bySha.get(head); commit; commit = bySha.get(commit.parents[0] ?? '')) {
|
|
106
|
+
if (commit.parents.length <= 1 && !pulled.has(commit.sha)) direct.add(commit.sha)
|
|
107
|
+
}
|
|
108
|
+
return direct
|
|
109
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// The agents the server knows by their GitHub Apps or accounts (the Agents
|
|
2
|
+
// tab's, server-managed/repository-agents.ts, whose marks the Commits tab
|
|
3
|
+
// reads on commits too, repository-history.ts).
|
|
4
|
+
import type { AppAgent, AppAgentMarks } from '../common/managed/agent-tasks.ts'
|
|
5
|
+
import { GITHUB_AGENTS, type GithubAgent } from '../common/managed/github-agents.ts'
|
|
6
|
+
|
|
7
|
+
// The agents known by their GitHub Apps or accounts, beside Claude and
|
|
8
|
+
// Codex: those of GITHUB_AGENTS with branches of their own, in its order
|
|
9
|
+
// (common/managed/github-agents.ts, where each is told, its accounts among
|
|
10
|
+
// it), each its id and name, its avatar (its mark, served by
|
|
11
|
+
// /api/avatar/<avatar>, a GitHub App's, `app-<id>`), the fingerprint it
|
|
12
|
+
// leaves, and its branches' prefix.
|
|
13
|
+
export const APP_AGENTS: readonly (AppAgent & AppAgentMarks)[] = Object.entries<GithubAgent>(GITHUB_AGENTS)
|
|
14
|
+
.flatMap(([id, { name, avatar, prefix, fingerprint }]) => prefix ? [{ id, name, prefix, ...avatar ? { avatar } : {}, ...fingerprint ? { fingerprint } : {} }] : [])
|
|
15
|
+
// The prefixes of the branches agents work on: Claude Code's and Codex's,
|
|
16
|
+
// and the app agents'.
|
|
17
|
+
export const AGENT_BRANCH_PREFIXES = ['claude/', 'codex/', ...APP_AGENTS.map(agent => agent.prefix)]
|
|
18
|
+
// What the marks agents leave on commits are read by, as the history keeps
|
|
19
|
+
// them (repository-history.ts commitMarks), and branches' tips and the
|
|
20
|
+
// commits the app agents' accounts authored (repository-agents.ts): bumped
|
|
21
|
+
// as how they are told changes, so that the Agents tab reads again those
|
|
22
|
+
// kept by older rules.
|
|
23
|
+
export const AGENT_MARKS_READ = 1
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Shared avatar cache interface, implemented by storage-stores.ts.
|
|
2
|
+
import type { Buffer } from 'node:buffer'
|
|
3
|
+
|
|
4
|
+
export interface CachedAvatar {
|
|
5
|
+
contentType: string
|
|
6
|
+
bytes: Buffer
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface AvatarStore {
|
|
10
|
+
put(id: string, contentType: string, bytes: Buffer): Promise<void>
|
|
11
|
+
get(id: string): Promise<CachedAvatar | null>
|
|
12
|
+
delete(id: string): Promise<void>
|
|
13
|
+
}
|