diff --git "a/docs/audit/2026-08-22-Acosmi-CIMD\344\270\216\345\217\221\345\270\203\345\237\272\347\241\200\350\256\276\346\226\275\347\213\254\347\253\213\346\225\264\346\224\271\346\226\271\346\241\210.md" "b/docs/audit/2026-08-22-Acosmi-CIMD\344\270\216\345\217\221\345\270\203\345\237\272\347\241\200\350\256\276\346\226\275\347\213\254\347\253\213\346\225\264\346\224\271\346\226\271\346\241\210.md" new file mode 100644 index 0000000..388c30c --- /dev/null +++ "b/docs/audit/2026-08-22-Acosmi-CIMD\344\270\216\345\217\221\345\270\203\345\237\272\347\241\200\350\256\276\346\226\275\347\213\254\347\253\213\346\225\264\346\224\271\346\226\271\346\241\210.md" @@ -0,0 +1,702 @@ +# Acosmi CIMD 与发布基础设施独立整改方案 + +> 日期:2026-08-22(America/Los_Angeles) +> +> 合同号:`ACOSMI-MCP-P0-2026-08-22-v1` +> +> 文档角色:Acosmi-owned 实施真源 +> +> 状态:方案已固定,未实施;本次只读审计和文档拆分未修改 Acosmi 源码、生产服务、云资源、账号或密钥 +> +> 上位协调文档:《[插件库全仓 MCP 服务健康度根因审计与修复方案](./2026-08-22-插件库全仓MCP服务健康度-根因审计与修复方案.md)》(以下简称“主方案”) +> +> 源码基线:`/Users/fushihua/Desktop/Acosmi`,HEAD `c2a54e80fc98f15626a90caa26b3e8d1eda709ca` +> +> 生产基线:`root@59.110.139.37`,后端制品 `c0af25ab2aa4c285a5c4869d9ff48fda6a9849af`,构建时间 `2026-08-19T04:38:16Z` + +SSH 凭据继续使用用户指定的本地私钥文件;私钥路径、内容、指纹和可恢复参数不得写入仓库、制品、命令输出或审计证据。 + +## 0. 最终裁决与权威边界 + +本文档将 Acosmi 相关工作固定拆成三个独立工作包: + +| 工作包 | 内容 | 责任仓/系统 | 是否源码改动 | +| --- | --- | --- | --- | +| `ACOSMI-SRC-P0-1` | 删除两份 AS metadata 虚假广告,新增 CrabCode CIMD 公共路由及测试 | `Acosmi/nexus-v4/backend` | 是 | +| `ACOSMI-REL-P0-1` | 两段完整部署 bundle、发布流水线、生产部署、双地点验收与安全回滚 | Acosmi `.github/workflows/deploy-cn-nexus-backend.yml` 与生产 | 是发布自动化改动,不是业务源码 | +| `ACOSMI-OPS-P0-0A` | 跨云 DR、WORM、OIDC 双人审批、2-of-3 签名和 bootstrap canary | Acosmi Ops/Release | 否,为基础设施子轨 | + +权威分工固定为: + +1. Acosmi 后端文件、测试、两段制品、部署、回滚和 P0-0A 证据以本文档为实施真源。 +2. canonical client ID URL、callback、CIMD JSON、跨仓阻断关系、全局 release-lock schema 和联合解锁顺序以主方案为协调真源。 +3. 两份文档中任一交接合同字段变更,必须使用同一变更同步修订两文档;只修一处即验收失败。 +4. 三个工作包使用独立任务、工作树、评审和发布记录;不与 `CrabCode-Plugin` 或 `CrabCode` 改动合并为一个实施任务。 +5. P0-1 通过只代表 Acosmi 交付闭环,不代表 17 处 CIMD binding 可发布;联合解锁仍受主方案门禁约束。 + +## 1. 已证明的当前状态 + +### 1.1 生产运行态与责任层 + +2026-08-22 只读实测结果: + +```text +nginx = active +nexus = active +tkdist-java = active + +public GET https://acosmi.com/oauth/crabcode-client-metadata = 404 text/plain +local Host /oauth/crabcode-client-metadata = 404 text/plain +``` + +生效 Nginx 配置已有: + +```nginx +location /oauth/ { + proxy_pass http://127.0.0.1:8009; +} +``` + +因此根因已固定为 Go backend 没有 GET handler;不改 DNS、TLS 或 Nginx exact location。如实施变更包出现 Nginx 差异,必须 hard fail 并从本工作包移除。 + +### 1.2 Acosmi AS metadata 虚假广告 + +普通 metadata 与 desktop metadata 现在都输出: + +```json +"client_id_metadata_document_supported": true +``` + +实际行为却是: + +- `pkg/mcp/oauth_server.go` 的 `AuthorizationServer.Authorize` 对未注册 HTTPS client ID 仍返回 `invalid_client`; +- `internal/handler/desktop_oauth.go` 的 authorize 路径也只接受已注册 client; +- `FetchClientIDMetadata` 和 `DetermineClientRegistration` 没有生产调用链。 + +“Acosmi 托管 CrabCode 的客户端 metadata”与“Acosmi AS 自身支持 URL client ID”是两件事。本工作包实现前者,并删除后者的虚假广告;不实现后者。 + +### 1.3 现有 admin MCP OAuth handler 禁止复用 + +下列现有路由继续保持隔离: + +```text +POST /api/v4/plugins/mcp/oauth/authorize +GET /api/v4/plugins/mcp/oauth/callback +``` + +它们需要 owner/admin JWT,依赖未注入的 Gin context 值,state 可预测,token Redis key 没有 user/tenant/provider/resource 隔离,且 refresh token 会随 access token 记录一起删除。本工作包不修补、不扩建、不把它们作为 CrabCode OAuth broker。 + +## 2. `ACOSMI-SRC-P0-1`:后端源码实施合同 + +### 2.1 两个独立 commit 与两份可回滚制品 + +实施链从审计基线开始固定为三个直接父子 commit: + +```text +BASE = c2a54e80fc98f15626a90caa26b3e8d1eda709ca +R.parent = BASE +A.parent = R +B.parent = A +``` + +R 是第 3.2 节的发布自动化 commit,只允许修改: + +```text +.github/workflows/deploy-cn-nexus-backend.yml +nexus-v4/backend/Dockerfile +nexus-v4/infra/systemd/nexus-backend.service +``` + +A/B 在同一 Acosmi 源码评审中按下列顺序产生,并分别构建不可变制品: + +1. A=`metadata-safe`:只删除两处虚假 CIMD 能力广告并增加 metadata 测试。 +2. B=`cimd-enabled`:以 A 为父 commit,新增 CrabCode client metadata handler、路由和测试。 + +三个 direct-parent 断言任一失败即停止;禁止在 BASE→R→A→B 中间夹入任何其他 commit。A/B 不夹带格式化、依赖升级、admin OAuth handler、Nginx 或其他业务改动。A 和 B 均必须单独通过后端全量测试与构建。如实施前 Acosmi `main` 已不再以 BASE 为线性起点,禁止自动 rebase/夹带新改动;必须先重做只读基线审计并同步更新两份合同文档。 + +### 2.2 制品 A:删除虚假 AS metadata 能力 + +修改文件与唯一允许的业务改动: + +| 文件 | 固定改动 | +| --- | --- | +| `nexus-v4/backend/pkg/mcp/oauth_server.go` | 从 `AuthorizationServer.Metadata` 删除 `client_id_metadata_document_supported` key;必须是 key 缺席,不是输出 `false` | +| `nexus-v4/backend/internal/handler/desktop_oauth.go` | 从 `DesktopOAuthHandler.Metadata` 删除同名 key;必须是 key 缺席 | + +保留两处 `registration_endpoint`、DCR 路由和其他已实现 metadata 字段。不接线 server-side CIMD helper,不改 authorize 对未注册 client 的处置。 + +新增测试文件: + +```text +nexus-v4/backend/pkg/mcp/oauth_server_metadata_test.go +nexus-v4/backend/internal/handler/desktop_oauth_metadata_test.go +``` + +测试必须同时断言: + +- HTTP 200; +- JSON key `client_id_metadata_document_supported` 缺席; +- `registration_endpoint` 仍存在且与对应 issuer 一致; +- 不允许以 `false`、`null` 或空字符串代替 key 缺席。 + +### 2.3 制品 B:新增 CrabCode CIMD 公共端点 + +新增文件: + +```text +nexus-v4/backend/internal/handler/crabcode_client_metadata.go +``` + +固定导出无状态 Gin handler: + +```go +func CrabCodeClientMetadata(c *gin.Context) +``` + +修改: + +```text +nexus-v4/backend/cmd/api/routes_business.go +``` + +在 `registerOAuthASRoutes` 的公共 OAuth 路由同层注册: + +```go +root.GET("/oauth/crabcode-client-metadata", handler.CrabCodeClientMetadata) +``` + +端点不加 JWT、session、CSRF、tenant 或用户上下文,不读请求 query/body/header 来生成字段,不发 Set-Cookie,不执行网络、数据库、Redis 或文件系统 I/O。 + +唯一允许的响应是以下六个 key: + +```json +{ + "client_id": "https://acosmi.com/oauth/crabcode-client-metadata", + "client_name": "CrabCode", + "redirect_uris": [ + "http://127.0.0.1:3118/callback" + ], + "grant_types": [ + "authorization_code", + "refresh_token" + ], + "response_types": [ + "code" + ], + "token_endpoint_auth_method": "none" +} +``` + +HTTP 合同固定为: + +| 项 | 固定值/规则 | +| --- | --- | +| Method/path | `GET /oauth/crabcode-client-metadata` | +| Status | `200` | +| Redirect | 禁止所有 3xx | +| Content-Type | `application/json; charset=utf-8` | +| Cache-Control | `public, max-age=300, must-revalidate` | +| Body | UTF-8 JSON,不超过 5120 bytes,key 集合与上述 JSON 完全相同 | +| `client_id` | 与 canonical 请求 URL 逐字符相同 | +| Secret | `client_secret`、`client_secret_expires_at` 及任何等价字段必须缺席 | + +新增测试: + +```text +nexus-v4/backend/internal/handler/crabcode_client_metadata_test.go +``` + +测试使用 `httptest` 验证 exact key set、所有 scalar/array 值、headers、状态码、无 Location、无 Set-Cookie、body size 与 secret key 缺席。 + +路由层新增固定测试文件: + +```text +nexus-v4/backend/cmd/api/routes_business_oauth_test.go +``` + +该测试函数名固定为 `TestRegisterOAuthASRoutes_CrabCodeClientMetadataPublicGET`,必须通过实际 Gin engine 断言未登录 GET 命中 handler 并返回 200;POST 只允许返回 404 或 405,不得返回任何 2xx/3xx。 + +### 2.4 源码门禁与完成判定 + +禁止把 macOS/普通 runner 上的裸 `go test` 或 `go build` 作为验收证据;`cmd/api` 的 CGO 链需要七个 Linux Rust `.so`,且生产版本只能由 Docker build args 注入。 + +第 3.2 节的独立发布自动化 commit 必须在 `nexus-v4/backend/Dockerfile` 的 `go-builder` stage 中,完成 Rust builder 并将七库复制到 `/app/experiments/target/release` 之后、执行生产 `go build` 之前,固定执行: + +```dockerfile +RUN LD_LIBRARY_PATH=/app/experiments/target/release \ + go test ./internal/handler ./pkg/mcp ./cmd/api +RUN LD_LIBRARY_PATH=/app/experiments/target/release \ + go test ./... +``` + +A 和 B 必须分别在 protected workflow 的 Linux Docker build 中生成两条测试通过记录;任一失败都不得生成 bundle。生产构建同时传入 40 位 `GIT_COMMIT` 和 UTC RFC3339 `BUILD_TIME`。解包后执行 `LD_LIBRARY_PATH=./lib ./server --version`,输出必须包含当次 A 或 B commit 且不含 `unknown`。 + +`ACOSMI-SRC-P0-1` 完成的充要条件是:A/B 两 commit 可定位,A/B 两制品均通过全量测试和构建,差异只包含本节文件,且 B 的父链包含 A。 + +## 3. `ACOSMI-REL-P0-1`:发布、验收与回滚 + +### 3.1 制品记录 + +A 和 B 必须分别上传 primary 与 DR: + +```text +primary: oss://acosmi-private-releases-cn-hangzhou/nexus-backend///nexus-backend.tar.gz +DR: s3://acosmi-private-releases-dr-us-west-2/nexus-backend///nexus-backend.tar.gz +``` + +`` 是 40 位 Git commit,`` 是小写 64 位 bundle SHA-256。bundle 必须包含且只包含: + +```text +server +lib/libchatacosmi_core.so +lib/libchatacosmi_crypto.so +lib/libchatacosmi_jsonschema.so +lib/libchatacosmi_mcp_v2.so +lib/libchatacosmi_ratelimit.so +lib/libchatacosmi_sandbox.so +lib/libchatacosmi_tokenizer.so +deployment-manifest.json +``` + +`deployment-manifest.json` 固定包含 `schemaVersion=1`、`artifactRole`、`sourceCommit`、`buildIssuedAt`以及上述八个 payload 文件(不包括 manifest 自身)的 `path/sizeBytes/sha256`。禁止从 A/B 之外的 bundle 混拼 `server` 或 `.so`。发布记录必须同时包含: + +```text +artifactRole = metadata-safe | cimd-enabled +sourceCommit +buildIssuedAt +goVersion +versionOutput +sizeBytes +sha256 +primaryLocator +disasterRecoveryLocator +primaryReadbackSha256 +disasterRecoveryReadbackSha256 +deploymentManifestSha256 +safeRollbackCommit|null +safeRollbackBundleSha256|null +safeRollbackManifestSha256|null +ownerAttestation +approverAttestation +``` + +生产机 `/opt/acosmi/releases/...` 只是部署缓存,不是制品真源。A/B primary 和 DR 对象不得覆盖或删除。 + +### 3.2 发布流水线固定落点 + +修改现有 Acosmi 构建/发布文件: + +```text +.github/workflows/deploy-cn-nexus-backend.yml +nexus-v4/backend/Dockerfile +nexus-v4/infra/systemd/nexus-backend.service +``` + +发布自动化改动必须作为独立 commit 先合并并通过 non-production fixture,不进入 A/B 业务源码 commit;该 commit 未验收前禁止调度 A/B 生产发布。工作流文件只从受保护 `origin/main` 解析,固定增加并验证六个 `workflow_dispatch` 输入: + +```text +source_commit = 40 位 A 或 B commit +artifact_role = metadata-safe | cimd-enabled +execution_mode = fixture | release +safe_rollback_commit = artifact_role=cimd-enabled 时必填 A commit;metadata-safe 时必须为空 +safe_rollback_bundle_sha256 = cimd-enabled+fixture 时必填 F-A-BIN-01/F-A-FIXTURE-LIVE-01 的唯一 A SHA;cimd-enabled+release 时必填 A-BIN-01/A-LIVE-01 的唯一 A SHA;metadata-safe 时必须为空 +safe_rollback_manifest_sha256 = 与上述 mode-specific A bundle 绑定的 manifest SHA;metadata-safe 时必须为空 +``` + +工作流使用 `actions/checkout fetch-depth:0` 精确 checkout `source_commit`,构建前同时断言 `git rev-parse HEAD=source_commit` 且 `git merge-base --is-ancestor source_commit origin/main` 成功。它还必须按第 2.1 节重建 BASE→R→A→B 直接父子链并对每个 commit 执行 path allowlist;`cimd-enabled` 的 `safe_rollback_commit` 必须等于 `git rev-parse source_commit^`。`fixture` 模式的三个 safe rollback 输入必须匹配 F-A-BIN-01/F-A-FIXTURE-LIVE-01,`release` 模式必须匹配 A-BIN-01/A-LIVE-01;两种模式都必须从该 SHA 精确 locator 取回,禁止仅按 A commit 重建或选择另一 A bundle。 + +现有单 job `environment: production` 必须拆成以下固定 DAG: + +1. `build_test`:不绑定 production environment,不读生产 secret;完成 ref 门禁、Docker 内 CGO 全测试、构建、payload manifest 和 bundle digest。 +2. `quarantine`:将未批准 bundle 以 GitHub Actions 短期 artifact 保留 24 小时,记录平台 artifact digest;不上传 production primary/DR。 +3. `owner_attest`:`execution_mode=fixture` 使用 `backend-release-fixture-owner`,`release` 使用 `backend-release-owner`;由 owner IdP subject 对 digest subject 签名。 +4. `approver_attest`:分别使用 `backend-release-fixture-approver` 或 `backend-release-approver`;必须是与 owner 不同的 IdP subject,对同一 digest subject 签名。 +5. `mirror_readback`:只在两份 attestation 通过后使用 OIDC release role。`fixture` 只写 primary/DR `workflow-fixture//` 并双读回;`release` 写入正式内容寻址 locator 并双读回。 +6. `fixture_deploy`:仅 `execution_mode=fixture` 可进入,在无生产 secret、不连生产 DB/Redis/外部网络的临时 Linux VM/container 执行 systemd/current 迁移等价 fixture。A fixture 产生 F-A-BIN-01/F-A-FIXTURE-LIVE-01;B fixture 必须绑定该 A record、执行 B→A 原子回滚并产生 F-B-RBK-01。fixture 永不连接生产主机或进入 production deploy job。 +7. `deploy`:仅 `execution_mode=release` 可进入,使用受保护 `production` environment,下载已双读回的 primary bundle 并再验 digest/内层 manifest后部署。 + +两份批准的签名对象逐字节固定为: + +```text +JCS(["acosmi-backend-bundle-approval-v1",{ + artifactRole, + sourceCommit, + bundleSizeBytes, + bundleSha256, + deploymentManifestSha256, + workflowRunId, + executionMode, + systemdUnitSha256, + safeRollbackCommit, + safeRollbackBundleSha256, + safeRollbackManifestSha256 +}]) +``` + +只批 workflow run/environment 而不绑定上述 digest subject 不构成批准。`backend bundle stores + 四个 owner/approver environment + OIDC role + F-A-BIN-01 + F-A-FIXTURE-LIVE-01 + F-B-RBK-01` 共同构成 P0-0A 的最小 `ACOSMI-REL prerequisite`;它未通过时不部署生产 A/B,P0-0A 其余 2-of-3/HMAC/offline-root 门可继续并行。 + +生产 bundle 继续使用 `nexus-v4/backend/Dockerfile` 构建,`GIT_COMMIT=source_commit`,`BUILD_TIME` 只由工作流 UTC 时钟生成。从镜像提取 `server` 与七个 `.so`,生成 payload manifest,打包后按上述 DAG 批准、上传、独立重取并校验 bundle 与内层 manifest,再从已验收 primary 字节部署;禁止直接部署 runner 工作目录或 quarantine 中未双读回的字节。 + +R 对现有唯一生产部署工作流的改动只允许落在 input/build-test/quarantine/digest-attestation/mirror-readback/atomic-switch/rollback 区块。R validator 必须对 BASE 中现有 JWT fingerprint、PostgreSQL/Redis identity、`MOBILE_ROLLOUT_SALT`、Account Bridge 两把私钥/版本策略、schema bootstrap、health check 区块分别生成 baseline slice SHA,并断言 R 中这些 slice 逐字节不变。A/B 部署前后必须继续验证 JWT/PG/Redis identity,并断言 `MOBILE_ROLLOUT_SALT`、Account Bridge 私钥与策略的只显示 digest 全部未变;任一变化都中止并回滚当次切换。 + +生产部署不再直接解压覆盖 live `server/lib`,固定使用: + +```text +/opt/acosmi/releases//server +/opt/acosmi/releases//lib/*.so +/opt/acosmi/releases//deployment-manifest.json +/opt/acosmi/nexus-backend/current -> /opt/acosmi/releases/ +``` + +R 将仓内 `nexus-v4/infra/systemd/nexus-backend.service` 固定改为 `WorkingDirectory=/opt/acosmi/nexus-backend`、`ExecStart=/opt/acosmi/nexus-backend/current/server`、`LD_LIBRARY_PATH=/opt/acosmi/nexus-backend/current/lib`,`.env` 仍位于 `/opt/acosmi/nexus-backend/.env`。工作流对 unit 原始字节计算 `systemdUnitSha256`并纳入两份 digest approval。首次迁移前先把当前 live `server/lib` 复制到只读 `pre-A-observed` 版本目录并记录 manifest/version(仅允许 A 首次失败回退,不得成为 artifactRole),再备份线上 unit、安装 R unit、`systemctl daemon-reload`,将 `current` 先指向 `pre-A-observed` 并验证服务行为不变。迁移失败必须恢复原 unit/直连路径、daemon-reload 并重验基线健康。 + +每个 release 目录在 digest/内层 manifest/version 验证后设为只读;切换时先停止服务,用同文件系统 symlink rename 原子更换 `current`,再启动和 health check,禁止逐文件覆盖造成 binary/`.so` 混用。fixture 必须同时验证旧 unit→R unit/current 迁移、迁移失败恢复和 A/B 原子切换。 + +`cimd-enabled` 切换前必须将 digest approval 中 `safeRollbackBundleSha256/safeRollbackManifestSha256` 指向、已从 primary/DR 双读回验收的唯一 A bundle 预置到 `/opt/acosmi/releases//`,再次验证只读文件、manifest 和 version,且该目录不得被 cleanup。B 失败 trap 优先原子切回该本地 A cache;本地 cache 失效时才依次从同一 SHA 精确 A primary、DR 重取。三者都无法通过验证时保持服务停止并进入 P0 incident,禁止启动半部署 B 或混合 bundle。primary/DR 仍是制品真源,本地只读 A 仅是可用性缓存。 + +### 3.3 不可交换的部署顺序 + +1. 在 P0-0A 最小 `ACOSMI-REL prerequisite`(backend stores+四个 digest-specific approval environments+OIDC role+fixture)已通过后,从 A primary 重取完整 bundle,校验 bundle size/SHA 及内层 manifest,先在不连接生产 DB/Redis/外部服务的隔离 fixture 中验证 health+两份 metadata,再按第 3.2 节原子切换生产 A。P0-0A 其他子门可与 P0-1 继续并行。 +2. 验证 `/opt/acosmi/nexus-backend/current` 解析到 A-BIN-01 的 exact bundle SHA 目录,该目录八个 payload 都匹配 A manifest,`--version`=A commit、health 通过;同时验证普通和 desktop metadata 中 CIMD key 都缺席,且 DCR `registration_endpoint` 仍存在,然后才生成 A-LIVE-01。 +3. 从 B primary 重取完整 bundle,校验 bundle size/SHA 及内层 manifest,部署 B。 +4. 在 Acosmi CN 生产主机使用 loopback/SNI 验收。 +5. 在美国洛杉矶审计机使用公网 DNS/TLS 验收。 +6. 比较两地的 status、headers 和 JSON 语义;任一差异就回滚 B 至 A。 +7. 在任何 generation=2 宿主生产发布之前,按第 3.5 节对线上 B 执行一次受控 B→A 完整 bundle 回滚演练,验证 A version/内层 manifest/两份 AS metadata。 +8. 演练通过后,从已验收 primary 重取与第 3 步 SHA 完全相同的 B bundle,重新部署并重跑第 4–6 步全部验收,最终线上角色必须是 B=`cimd-enabled`。 +9. 只在发布流水线证据、A/B 验收、B→A 演练和演练后 B 最终态全部通过后写入 P0-1 完成证据。 + +禁止直接从当前生产制品跨过 A 部署 B。不修改 Nginx;部署前后都保留 Nginx 生效配置校验和,差异非空即中止。 + +A 在隔离 fixture 失败时不切换生产。A 已切换但在 `A-LIVE-01` 记录前失败时,只允许原子切回 `pre-A-observed` 目录,P0-1 保持 blocked、P0-0E remote=0;`A-LIVE-01` 通过后,`pre-A-observed` 永久丧失可执行回滚资格,后续只能使用 A 或保留两处 metadata key 缺席的更新 safe bundle。 + +### 3.4 生产验收命令与机器判定 + +A 部署后在 CN 主机执行: + +```bash +curl --fail-with-body --silent --show-error \ + --resolve acosmi.com:443:127.0.0.1 \ + https://acosmi.com/.well-known/oauth-authorization-server | \ + jq -e ' + (has("client_id_metadata_document_supported") | not) and + .issuer == "https://acosmi.com" and + .registration_endpoint == "https://acosmi.com/oauth/register" + ' + +curl --fail-with-body --silent --show-error \ + --resolve acosmi.com:443:127.0.0.1 \ + https://acosmi.com/.well-known/oauth-authorization-server/desktop | \ + jq -e ' + (has("client_id_metadata_document_supported") | not) and + .issuer == "https://acosmi.com" and + .registration_endpoint == "https://acosmi.com/oauth/desktop/register" + ' +``` + +B 部署后,CN 主机执行以下确定命令: + +```bash +curl --max-redirs 0 --fail-with-body --silent --show-error \ + --resolve acosmi.com:443:127.0.0.1 \ + --dump-header - \ + https://acosmi.com/oauth/crabcode-client-metadata + +curl --fail-with-body --silent --show-error \ + --resolve acosmi.com:443:127.0.0.1 \ + https://acosmi.com/oauth/crabcode-client-metadata | \ + jq -e ' + (keys | sort) == ([ + "client_id", + "client_name", + "grant_types", + "redirect_uris", + "response_types", + "token_endpoint_auth_method" + ] | sort) and + .client_id == "https://acosmi.com/oauth/crabcode-client-metadata" and + .client_name == "CrabCode" and + .redirect_uris == ["http://127.0.0.1:3118/callback"] and + .grant_types == ["authorization_code", "refresh_token"] and + .response_types == ["code"] and + .token_endpoint_auth_method == "none" + ' + +curl --fail-with-body --silent --show-error \ + --resolve acosmi.com:443:127.0.0.1 \ + https://acosmi.com/.well-known/oauth-authorization-server | \ + jq -e ' + (has("client_id_metadata_document_supported") | not) and + .issuer == "https://acosmi.com" and + .registration_endpoint == "https://acosmi.com/oauth/register" + ' + +curl --fail-with-body --silent --show-error \ + --resolve acosmi.com:443:127.0.0.1 \ + https://acosmi.com/.well-known/oauth-authorization-server/desktop | \ + jq -e ' + (has("client_id_metadata_document_supported") | not) and + .issuer == "https://acosmi.com" and + .registration_endpoint == "https://acosmi.com/oauth/desktop/register" + ' +``` + +洛杉矶审计机执行以下公网命令: + +```bash +curl --max-redirs 0 --fail-with-body --silent --show-error \ + --dump-header - \ + https://acosmi.com/oauth/crabcode-client-metadata + +curl --fail-with-body --silent --show-error \ + https://acosmi.com/oauth/crabcode-client-metadata | \ + jq -e ' + (keys | sort) == ([ + "client_id", + "client_name", + "grant_types", + "redirect_uris", + "response_types", + "token_endpoint_auth_method" + ] | sort) and + .client_id == "https://acosmi.com/oauth/crabcode-client-metadata" and + .client_name == "CrabCode" and + .redirect_uris == ["http://127.0.0.1:3118/callback"] and + .grant_types == ["authorization_code", "refresh_token"] and + .response_types == ["code"] and + .token_endpoint_auth_method == "none" + ' + +curl --fail-with-body --silent --show-error \ + https://acosmi.com/.well-known/oauth-authorization-server | \ + jq -e ' + (has("client_id_metadata_document_supported") | not) and + .issuer == "https://acosmi.com" and + .registration_endpoint == "https://acosmi.com/oauth/register" + ' + +curl --fail-with-body --silent --show-error \ + https://acosmi.com/.well-known/oauth-authorization-server/desktop | \ + jq -e ' + (has("client_id_metadata_document_supported") | not) and + .issuer == "https://acosmi.com" and + .registration_endpoint == "https://acosmi.com/oauth/desktop/register" + ' +``` + +两地验收器必须将两类合同分开判定: + +- CIMD:status=200、无 `Location`、无 `Set-Cookie`、Content-Type 等于 `application/json; charset=utf-8`、Cache-Control 等于 `public, max-age=300, must-revalidate`、body 不超过 5120 bytes,exact six-key JSON 及值全匹配。 +- 普通/desktop AS metadata:status=200、无 `Location`、Content-Type media type 为 `application/json`,`issuer=https://acosmi.com`,对应 `registration_endpoint` 逐字符匹配,虚假 CIMD key 缺席;不对 AS metadata 强加 CIMD 的 Cache-Control 或 5120-byte 限制。 + +洛杉矶公网组额外验收公网 DNS/TLS/反向代理/后端完整链。人工目测 curl 输出不能替代机器判定。 + +另外必须验证生产 binary `--version` 与 B commit 逐字符一致,以及 Nginx 部署前后配置校验和相同。 + +### 3.5 安全回滚 + +回滚目标唯一固定为已验收的 A=`metadata-safe`: + +1. B 任一本机/公网/版本验收失败时,停止 P0-1 完成证据写入。 +2. 按“已复验本地只读 A cache → A primary → A DR”的唯一顺序取得首个通过 bundle size/SHA、内层 manifest 和 version 验证的 A 目录,停止服务后原子将 `current` 切到该目录,重启并 health-check;禁止逐文件恢复。 +3. 重验两份 AS metadata 中虚假 key 缺席。 +4. 记录 B 失败的精确阶段、HTTP 差异、B SHA、A SHA、操作人与审批人证明。 +5. CrabCode 下游继续以 canonical reasonCode=`cimd-document-unavailable` fail-close,不在同一登录中切换 DCR。 + +在 `A-LIVE-01` 通过之后,禁止回滚到 A 之前任何仍输出 `client_id_metadata_document_supported=true` 的 bundle,也禁止混用 A/B/当前制品的 binary 与 `.so`。如 A 自身发现回归,只能从 A 源码线构建保留“两处 key 缺席”的新 safe bundle,不得恢复虚假广告。 + +第 3.3 节的计划内回滚演练在完成上述 A 验证后不停留于 A;必须重新部署原 B bundle、重跑 CN/LA CIMD、两份 AS metadata、version 和 Nginx checksum 验收,并生成 `B-FINAL-01`。故障触发的真实回滚则停在 A 并保持 profile fail-close,P0-1 不标记完成。 + +## 4. `ACOSMI-OPS-P0-0A`:独立运维/发布基础设施子轨 + +本节与 P0-1 源码改动相互独立,可并行执行,但是首份 production genesis lock 的强制前置。全局 lock schema、component approvals、lease、key-set transition 和宿主验证算法严格以主方案第 6.1、8、10 节为准;下述 Bootstrap canary schema 是主方案第 6.1 节的执行镜像,字段/JCS/locator 任一不一致即 hard fail。 + +P0-0A 必须一次性交付: + +1. 公开 primary 固定为 `Alibaba Cloud OSS/accountAlias=acosmi-release-cn/region=cn-hangzhou/oss://acosmi-mcp-safe-primary-cn-hangzhou/crabcode/mcp-safe/`,`https://updates.acosmi.com/crabcode/mcp-safe/` 逐 key 映射到 `oss://acosmi-mcp-safe-primary-cn-hangzhou/crabcode/mcp-safe/`;primary 开启 versioning+WORM,禁止删除/改写旧 version/bypass retention。在独立 AWS accountAlias=`acosmi-release-dr`/`us-west-2` 创建 `s3://acosmi-mcp-safe-dr-us-west-2/crabcode/`,runtime DR 使用不依赖 `acosmi.com` DNS zone 的 `https://acosmi-mcp-safe-dr-us-west-2.s3.us-west-2.amazonaws.com/crabcode/`。DR bucket policy 只允许 `crabcode/mcp-safe/**` 与 `crabcode/host/**` 两前缀下 exact object GET/HEAD,禁止 public List/Put/Delete;其他 sibling prefix 必须被拒绝。每个 `visibility=public` artifact 必须在签名 lock 中同时绑定 HTTPS primary `artifactRef`、AWS 直接 HTTPS `runtimeMirrorRef` 和同 key S3 `disasterRecoveryRef`,三者 size/SHA 一致;`visibility=release-private` 的 `runtimeMirrorRef=null`。 +2. 建立并验收 backend bundle primary=`Alibaba Cloud OSS/accountAlias=acosmi-release-cn/region=cn-hangzhou/oss://acosmi-private-releases-cn-hangzhou/`,DR=`AWS S3/accountAlias=acosmi-release-dr/region=us-west-2/s3://acosmi-private-releases-dr-us-west-2/`;另创建 evidence primary=`Alibaba Cloud OSS/accountAlias=acosmi-release-cn/region=cn-hangzhou/oss://acosmi-private-release-evidence-cn-hangzhou/`,DR=`Alibaba Cloud OSS/accountAlias=acosmi-legal-dr-cn/region=cn-shanghai/oss://acosmi-private-release-evidence-dr-cn-shanghai/`,provider/component approval 原文只进 evidence 私有库,回滚审计只写两库各自 `rollback-audit//.json`。实际 account ID 不入仓,只将与三个稳定 alias 绑定的 salted account-ID hash 写入 bootstrap 证据。建库前 `legal` 和 `data-governance` 必须分别签署数据分类/保留/境内备份 policy 的 digest-specific attestation,缺一即 `release-infrastructure-unavailable`。 +3. 为公开 primary/DR、backend bundle primary/DR、私有 evidence 和回滚审计开启 versioning + Object Lock Compliance/WORM。backend bundle、lock/envelope 和不含个人/合同原文的 component approval attestation 永久保留;provider 合同/批准函/联系人/reviewer 原文只在中国境内 primary/DR 保留至到期、撤销或最后生产引用三者中最晚日期 +7 年,只允许 `legal` 签名 legal hold 延长;回滚记录保留 7 年。业务身份无 delete、无 bypass retention、无改写旧 version 权限。 +4. 使用企业私仓 `workflow_dispatch` 及 OIDC/IdP,固定建立 `backend-release-fixture-owner|backend-release-fixture-approver|backend-release-owner|backend-release-approver` 四个 protected environment;owner/approver 必须是两个不同 IdP subject,并对第 3.2 节同一 bundle digest subject 分别签名,issuer、attestation public-key allowlist 和 environment ID 钉住到 validator。不建常驻审批服务。 +5. 创建 `thresholdPolicy=2-of-3` 的 A/B/C 三把 Ed25519 release key:A 归 `release-signing`,B 归独立账号 `security`,C 由 `security` + `acosmi-release` 双人线下保管。另建不参与日常签名的 offline release-root key,只在两把当前 key 永久不可恢复或已泄漏并有 `security`/`acosmi-release` 两份 IdP+WORM 证据时恢复 key set;recovery 演练只使用 test key set/test locator,不销毁或替换生产 key。 +6. 在私有 secret backend 创建 `providerEvidenceCommitmentKey`,备份由 `legal`/`security` 双人恢复;`legal` 与 `security` 分别持有 eligibility-verdict Ed25519 key,公开 verdict 必须两签。provider raw evidence 取回、HMAC 重算与 eligibility validator 固定在中国境内 VPC 的自托管 runner label=`self-hosted,linux,x64,cn-hangzhou,release-legal-validator` 执行,raw bytes 禁止进入 GitHub-hosted runner/artifact/cache/log,境外只接收最小双签 verdict+commitment;必须交付 egress deny 与 log/artifact 泄露扫描证据,并对公开 verdict 执行 provider/app/scope/region/distribution/reviewer/private URI/自由文本泄露扫描。 +7. 生成不可变 `release-infrastructure-bootstrap.json`,包含脱敏 account ID hash、region、公开 primary 底层 locator 及 HTTPS→object mapping SHA、公开 primary/DR/backend bundle primary/backend bundle DR/private evidence primary/private evidence DR 各自的 bucket policy SHA、Object Lock 模式/保留、OIDC issuer、四个 backend protected environment ID、CN 自托管 validator runner-pool digest/egress-policy SHA、retention/residency policy SHA 及 `legal`/`data-governance` attestation refs、releaseKeySetId、三个 keyId、offline-root keyId、thresholdPolicy、两个 verdict public keyId、commitmentKeyId 和验收时间。 + +### 4.1 Bootstrap canary 固定合同 + +P0-0A 不使用尚未存在的 production current head 自证。它用 CSPRNG 生成 128-bit random、32 位小写 hex `canaryId` 和独立 32-byte random `payload.bin`,只写 `bootstrap-canary//`。三类 payload locator 固定为: + +```text +payloadArtifactRef=https://updates.acosmi.com/crabcode/mcp-safe/bootstrap-canary//payload.bin +payloadRuntimeMirrorRef=https://acosmi-mcp-safe-dr-us-west-2.s3.us-west-2.amazonaws.com/crabcode/mcp-safe/bootstrap-canary//payload.bin +payloadDisasterRecoveryRef=s3://acosmi-mcp-safe-dr-us-west-2/crabcode/mcp-safe/bootstrap-canary//payload.bin +``` + +`BootstrapCanaryEnvelope` 字段固定为: + +```text +schemaVersion=1 +environment=test +canaryId +issuedAt +expiresAt=issuedAt+15 minutes +payloadArtifactRef +payloadRuntimeMirrorRef +payloadDisasterRecoveryRef +payloadSizeBytes=32 +payloadSha256 +signedAt +releaseKeySetId +previousReleaseKeySetId=null +keySetTransitionRef=null +thresholdPolicy=2-of-3 +signatures[{keyId,signatureAlgorithm=Ed25519,signature}] +``` + +至少两把不同 keyId 对下列 exact subject 签名: + +```text +JCS(["mcp-bootstrap-canary-v1",{ + schemaVersion, + environment, + canaryId, + issuedAt, + expiresAt, + payloadArtifactRef, + payloadRuntimeMirrorRef, + payloadDisasterRecoveryRef, + payloadSizeBytes, + payloadSha256, + signedAt, + releaseKeySetId, + previousReleaseKeySetId, + keySetTransitionRef, + thresholdPolicy +}]) +``` + +使用同一 release key set 但独立 domain separator。envelope 原始字节固定发布到: + +```text +https://updates.acosmi.com/crabcode/mcp-safe/bootstrap-canary//head.json +https://acosmi-mcp-safe-dr-us-west-2.s3.us-west-2.amazonaws.com/crabcode/mcp-safe/bootstrap-canary//head.json +s3://acosmi-mcp-safe-dr-us-west-2/crabcode/mcp-safe/bootstrap-canary//head.json +``` + +三个 bootstrap mutable head 的 origin/CDN/object metadata 都固定 `Cache-Control: no-store`,取回请求发送 `Cache-Control: no-cache`。内容寻址 payload/envelope 与 production lock/envelope/`heads/.json` 固定 `Cache-Control: public, max-age=31536000, immutable`;production mutable `head.json` 同样固定 `no-store`,宿主取回同样发送 `no-cache`。`https://updates.acosmi.com/crabcode/marketplace/current.json` 的 origin/CDN 也固定 `no-store`,generation=1/2 updater 请求固定 `no-cache`;内容寻址 marketplace 对象固定长缓存+`immutable`。 + +production validator 只接受 `mcp-release-lock schemaVersion=2,environment=production,lockSequence>=1`,在验签前就必须拒绝 `BootstrapCanaryEnvelope`;canary 不得更新 production `head.json`、不得进入 production lock chain 或宿主高水位。 + +### 4.2 P0-0A 验收 + +以下项目必须全部通过。所有故障演练只操作 `environment=test` canary/test identity/test secret backend:DNS 故障只在 clean fixture 的本地 resolver 对 `acosmi.com` 做 deny,primary 凭据故障只撤掉 canary job identity 或在该 job 内 deny primary egress,HMAC/offline-root recovery 只用 test key copy/test key set。禁止修改生产 DNS、撤销生产 release identity、破坏生产 secret/key 或对非 canary object 执行 delete/retention 负测: + +- primary 底层 OSS、`updates.acosmi.com` HTTPS 映射、AWS HTTPS/S3 写入/读回同一 canary payload/envelope,各自 size/SHA 一致且 HTTPS→object key 映射逐字符正确; +- 同一 canary payload 使用私有 release identity 写入 backend bundle primary/DR 的 `bootstrap-canary//payload.bin`,两处独立读回的 size/SHA 一致,且该 test object 不被接受为 backend artifactRole; +- 两处 cloud/account/region 确认不同; +- 无对象存储凭据 clean fixture 可从 primary 和 AWS 直接域名独立取回、验签、验 payload; +- 每个 public plugin/marketplace/host artifact 的 primary/runtimeMirror/DR 三定位按签名 lock 取回同一 size/SHA,在 primary 断开 clean fixture 中 generation=2 runtime 无凭据从 exact HTTPS `runtimeMirrorRef` 成功取回;private artifact 的 runtime mirror 必须为 null 且宿主不访问; +- `crabcode/mcp-safe/**` 与 `crabcode/host/**` 的 canary exact GET/HEAD 均通过,sibling prefix GET 与 ListBucket 均被拒绝; +- canary head 连续 Put v1/v2 生成两个 version ID,v1 仍可按 version ID 取回; +- canary head v1→v2 更新后,primary 底层 object、`updates.acosmi.com` CDN、AWS HTTPS/S3 立即无认证 GET 都返回 v2 字节和 `Cache-Control: no-store`;内容寻址对象返回长缓存+`immutable`; +- marketplace `current.json` 更新后立即无认证 GET 返回新 pointer 字节+`no-store`,generation=1/2 clean fixture 以 request `no-cache` 显式 refresh 后取得新 marketplace,内容寻址 marketplace 返回长缓存+`immutable`; +- delete、改写旧 version、bypass retention 全部被拒绝; +- clean fixture 本地 resolver deny `acosmi.com` 后,仍可从 AWS 直接域名取回并验签;生产 DNS 不变; +- 撤掉 canary job identity 的 primary 权限或在该 job deny primary egress 后从 DR 完成取回;生产 release identity 不撤销; +- 两个不同 IdP subject 产生可验的 owner/approver attestation; +- 2 签正向通过;1 签不足、重复 keyId、错 key、改字节均拒绝; +- test secret backend 中的 HMAC key copy 故障后双人恢复/重算一致,eligibility verdict 单签/错 profile/fingerprint/篡改 lease 全部拒绝;生产 HMAC key 不破坏、不轮换; +- 短时 HSM/网络故障禁止启用 offline root,满足永久不可恢复条件时 offline-root recovery 正向演练通过。 + +任一项失败:不生成首份 production genesis lock,remote profile 不解禁,已发布 emergency safe marketplace 继续生效。canary 保留为证据,不执行例外删除。 + +## 5. 与 CrabCode / CrabCode-Plugin 的交接合同 + +下表中“交接合同镜像”不授权 Acosmi 修改下游仓: + +| 交接项 | 固定合同 | Owner | Acosmi 责任 | +| --- | --- | --- | --- | +| 输入 callback | `http://127.0.0.1:3118/callback` | `crabcode-mcp` | 只在 CIMD JSON 中按原样输出,不修改宿主 listener | +| 输出 CIMD | public GET 200、固定 JSON/headers、无重定向 | `acosmi-backend` | 实现、测试、双地点发布验收 | +| 输出 AS metadata | 两份 metadata 都不含虚假 key | `acosmi-backend` | 实现、测试、先 A 后 B 部署 | +| 证据 | A/B backend commit/version、双地点 CIMD+AS metadata curl、bundle/inner-manifest size/SHA、primary+DR、双人 attestation | `acosmi-ops` | 生成可验、无 secret 的 evidence record | +| 联合解锁 | generation=2 + release gate + 真实 OAuth/reconnect/tools-list/canary | 联合门 | P0-1 证据只作为其中一个前置 | + +当前 Notion 10、Linear 5、Canva 1、Synapse 1,共 17 处 CIMD binding 继续 blocked。只有在 Acosmi P0-1 通过、CrabCode `authPolicyGeneration=2` 通过、签名 release gate 通过,且对应供应商逐 profile 真实授权、targeted reconnect、`tools/list` 与只读 canary 均通过后,该 profile 才能由更高序号 lock 解锁。 + +P0-1 本身不实现下列下游事项: + +- CrabCode 固定 3118 listener、PKCE、auth policy generation/fingerprint、凭据仓和 targeted reconnect; +- CrabCode-Plugin catalog/binding、provider basis、ToolSearch、Skill capability gate、marketplace 发布; +- Notion/Linear/Canva/Synapse 供应商账号、审批、scope 和 canary tenant。 + +## 6. 证据清单与完成门 + +### 6.1 P0-1 必须证据 + +| ID | 证据 | 机器判定 | 失败动作 | +| --- | --- | --- | --- | +| `REL-PIPE-01` | R commit + non-production fixture | BASE→R direct parent/path allowlist;Docker CGO 测试;unit digest/迁移/恢复;固有 JWT/PG/Redis/salt/Account Bridge/schema/health slice SHA 不变;DAG 双人 digest approval、bundle 双写/重取、原子 B→A trap 全通过 | 禁止构建/部署 A/B | +| `F-A-BIN-01` | fixture A bundle/manifest/digest/readback | fixture primary/DR 同字节,version=A | 最小 REL prerequisite 不通过 | +| `F-A-FIXTURE-LIVE-01` | 隔离 fixture A health+metadata | 两份虚假 key 缺席、DCR 存在 | 禁止 fixture B/生产 A | +| `F-B-RBK-01` | fixture B→A 原子回滚 | B 绑定 fixture A exact SHA,current 切 A,health/metadata 通过 | 禁止生产 A/B | +| `A-SRC-01` | A commit/diff | A.parent=R,只含两个 metadata 源码点和对应测试 | 不构建 A | +| `A-BIN-01` | A bundle size/SHA/version/inner manifest + primary/DR readback | 两地 bundle SHA 相同,内层 8 个 payload 全匹配 | 不部署 A | +| `A-LIVE-01` | A 生产 current/bundle/health/AS metadata | current target SHA=A-BIN-01,version=A commit,8 payload=manifest,health 通过,虚假 key 缺席且 DCR 仍存在 | 不部署 B | +| `B-SRC-01` | B commit/diff | B.parent=A,三个 safe rollback 输入匹配唯一 A artifact record,只含 handler/route/tests | 不构建 B | +| `B-BIN-01` | B bundle size/SHA/version/inner manifest + primary/DR readback | 两地 bundle SHA 相同,内层 8 个 payload 全匹配,version=B commit | 不部署 B | +| `B-LIVE-CN-01` | CN loopback/SNI CIMD + AS metadata | exact HTTP/JSON 合同 | 回滚 B 至 A | +| `B-LIVE-LA-01` | LA 公网 CIMD + AS metadata | 与 CN 语义一致 | 回滚 B 至 A | +| `B-NGX-01` | Nginx 部署前后 checksum | 完全相同 | 中止并移除配置差异 | +| `B-RBK-01` | B→A 完整 bundle 回滚演练 | A version 生效、binary/library 均来自 A manifest、两份 metadata key 缺席 | P0-1 不完成 | +| `B-FINAL-01` | 演练后重部署原 B 及全量复验 | 线上 SHA/version=B,CN/LA CIMD+AS metadata+headers 通过,Nginx checksum 未变 | P0-1 不完成 | + +P0-1 完成必须同时满足上表全部十四项。任一证据缺失或为 `not-tested` 时,状态固定为 `blocked`,不得写“条件通过”“基本完成”或“等待确认”。 + +### 6.2 P0-0A 必须证据 + +P0-0A 完成证据固定为:`release-infrastructure-bootstrap.json`、BootstrapCanaryEnvelope/payload 三类 exact locators/size/SHA、mutable head `no-store`/request `no-cache`/内容寻址 `immutable` 响应头及 v1→v2 立即新字节证据、public artifact primary/runtimeMirror/DR 三定位同 size/SHA 与 primary 断开后 runtime HTTPS mirror 取回证据、backend-store canary primary/DR readback、`mcp-safe/host` 前缀正测与 sibling/List 负测、Object Lock/version IDs/拒绝证据、rollback-audit primary/DR 同字节 size/SHA/readback/version-ID fixture、clean-fixture resolver deny、canary identity/egress 故障演练、四 protected environment 与 owner/approver digest-specific OIDC attestations、2-of-3 正负测、test HMAC recovery、eligibility 双签测试、CN 自托管 validator egress/log/artifact 泄露扫描、`legal`+`data-governance` retention/residency policy attestations 和 test-only offline-root recovery 演练。任一项缺失则 `release-infrastructure-unavailable`。 + +公开证据不得包含 token、authorization code、state、client secret、SSH 密钥/路径、完整授权 URL query、供应商合同原文、provider reviewer subject 或 provider/legal evidence private locator。Acosmi backend bundle primary/DR locator 按主方案 `artifacts[] visibility=release-private` 合同记录,不属于上述 provider evidence 禁入字段。 + +## 7. RACI + +| 事项 | Responsible | Approver | Consulted | +| --- | --- | --- | --- | +| A/B 源码、单测、全量回归 | `acosmi-backend` | `acosmi-release` | `crabcode-mcp`、`security` | +| R 发布自动化、systemd 原子迁移、fixture | `acosmi-ops` | `acosmi-release` | `acosmi-backend`、`security`、`qa-release` | +| A/B 构建、digest-specific 双人批准、primary/DR 发布 | `acosmi-ops` | `acosmi-release` | `release-signing`、`security` | +| CN/LA 双地点验收 | `acosmi-ops` | `acosmi-release` | `qa-release`、`support` | +| B→A 回滚与演练 | `acosmi-ops` | `acosmi-release` | `acosmi-backend`、`crabcode-mcp`、`security` | +| P0-0A public/backend 跨云 DR,private evidence 境内 DR/WORM/OIDC | `acosmi-ops` | `acosmi-release` | `security`、`legal`、`data-governance`、`cost-owner`、`qa-release` | +| private evidence 分类/保留/驻留地 policy | `data-governance` | `legal` | `security`、`acosmi-ops`、`cost-owner` | +| 2-of-3 key set/offline root | `release-signing` | `acosmi-release` | `security`、`crabcode-release`、`marketplace-approver` | +| callback/generation=2/reconnect | `crabcode-mcp` | `crabcode-release` | `acosmi-backend`、`plugin-platform` | +| 17 处 binding 解锁 | `plugin-platform` | `marketplace-approver` | `provider-integrations`、`qa-release`、`acosmi-release` | + +Responsible 与 Approver 不得是同一 IdP subject。无法验证身份分离时,发布与回滚演练都不得开始。 + +## 8. 明确非目标 + +本独立方案明确不执行: + +1. 不修改 Nginx、DNS 或 TLS 路由来解决 CIMD 404。 +2. 不在 Acosmi AS 授权服务端接线 CIMD URL client registration;未接线 helper 不计为能力。 +3. 不复用或扩建现有 admin MCP OAuth handler。 +4. 不建 confidential OAuth broker,不让客户 token 进入 Acosmi 服务端。 +5. 不建常驻 CIMD 探针;P0 只要求每次发布的 CN/LA 双地点验收。 +6. 不在同一登录中做 CIMD↔DCR fallback。 +7. 不在本任务修改 CrabCode callback、generation、credential store、reconnect 或 UI。 +8. 不在本任务修改插件 binding、Skill、ToolSearch、marketplace 或版本。 +9. 不把 GitHub nightly、DR、WORM、OIDC 或双人审批写成当前已有能力;只有第 6.2 节全部证据交付后才能改为已验收。 + +## 9. 可追溯映射与同步规则 + +| 本文档 | 主方案映射 | 同步级别 | +| --- | --- | --- | +| 第 1 节当前证据 | 第 3.1–3.3 节 | 证据基线变化时两文档同改 | +| `ACOSMI-SRC-P0-1` | 第 6.2 节 | URL/callback/JSON/headers/metadata 任一变化时两文档同改 | +| `ACOSMI-REL-P0-1` | 第 8 节发布/回滚顺序 | A/B 角色、发布顺序、回滚目标两文档同改 | +| `ACOSMI-OPS-P0-0A` | 第 6.1、8、10 节 | 本文只管 Acosmi-owned 落地/证据,全局 schema 主方案真源 | +| 交接合同 | 第 4、6.3、8、10、14 节 | 只有跨仓同一变更才可修改 | + +实施记录不覆写本方案。执行时应新建以合同号为前缀的 evidence/index 文件,逐项引用本文第 6 节 ID。所有项通过前,状态只能是 `planned`、`in-progress`、`blocked` 或 `passed`;`not-tested` 一律归入 `blocked`。 diff --git "a/docs/audit/2026-08-22-\346\217\222\344\273\266\345\272\223\345\205\250\344\273\223MCP\346\234\215\345\212\241\345\201\245\345\272\267\345\272\246-\346\240\271\345\233\240\345\256\241\350\256\241\344\270\216\344\277\256\345\244\215\346\226\271\346\241\210.md" "b/docs/audit/2026-08-22-\346\217\222\344\273\266\345\272\223\345\205\250\344\273\223MCP\346\234\215\345\212\241\345\201\245\345\272\267\345\272\246-\346\240\271\345\233\240\345\256\241\350\256\241\344\270\216\344\277\256\345\244\215\346\226\271\346\241\210.md" new file mode 100644 index 0000000..4049b65 --- /dev/null +++ "b/docs/audit/2026-08-22-\346\217\222\344\273\266\345\272\223\345\205\250\344\273\223MCP\346\234\215\345\212\241\345\201\245\345\272\267\345\272\246-\346\240\271\345\233\240\345\256\241\350\256\241\344\270\216\344\277\256\345\244\215\346\226\271\346\241\210.md" @@ -0,0 +1,2596 @@ +# 插件库全仓 MCP 服务健康度根因审计与修复方案 + +> 日期:2026-08-22(America/Los_Angeles) +> +> 文档版本:修订版 v2;已吸收插件仓、CrabCode 宿主、Acosmi 源码、生产服务器和供应商官方约束的前置审计结论 +> +> 审计性质:只读调查;本文件由用户明确要求后修订,修订过程不修改插件、宿主、服务器、账号、数据库或外部服务配置 +> +> 插件仓:`/Users/fushihua/Desktop/CrabCode-Plugin`,审计基准 HEAD `a9dc9abd71e2bdfbf33aafa58bcea0b2d42e3bd3`,工作树含用户既存未提交修改 +> +> CrabCode 宿主:`/Users/fushihua/Desktop/CrabCode`,审计基准 HEAD `199d9c27817e9de9d3f47752087a9db5ec7a09c8`,MCP SDK `1.29.0` +> +> Acosmi 上游源码:`/Users/fushihua/Desktop/Acosmi`,审计基准 HEAD `c2a54e80fc98f15626a90caa26b3e8d1eda709ca` +> +> Acosmi CN 生产:`root@59.110.139.37`;线上后端制品版本 `c0af25ab2aa4c285a5c4869d9ff48fda6a9849af`,构建时间 `2026-08-19T04:38:16Z` +> +> 公网探测位置:美国洛杉矶;生产服务器探测位置:中国大陆阿里云 ECS + +> **独立处理(Acosmi 工作流)**:合同号 `ACOSMI-MCP-P0-2026-08-22-v1`。Acosmi 后端源码、生产部署/回滚及 P0-0A 运维基础设施改由《[Acosmi CIMD 与发布基础设施独立整改方案](./2026-08-22-Acosmi-CIMD与发布基础设施独立整改方案.md)》单独实施。独立文档是 Acosmi 内部源码、测试、部署与回滚的实施真源;本文档仍是跨仓接口、全局 release lock 和联合解锁门的协调真源。任一跨仓合同字段变更必须在同一变更中同步修订两份文档。 + +## 0. 修订规则与最终裁决 + +本修订版不保留设计待决。外部审批、真实租户、供应商资格或端到端测试尚未满足时,默认动作统一为: + +```text +不发布可执行连接器 +不显示 OAuth CTA +不写 connected/usable +runtime reasonCode = 对应 blocker +``` + +`not-tested` 是证据状态,不是上线状态;任何 `not-tested` 连接器在生产中固定为 blocked。 + +最终裁决:**全仓 MCP 端到端健康度不合格,严重级别 P0;原始方案不能直接实施,本修订版是实施真源。** + +故障不是单一端点事故,而是以下合同连续断裂: + +```text +插件发布 + → 插件启用 + → MCP 独立激活 + → 配置与本地依赖就绪 + → 认证 profile 明确且可完成 + → initialize/tools-list + → 逻辑工具名可发现 + → 用户显式调用成功 +``` + +当前最高优先级事实: + +1. `https://acosmi.com/oauth/crabcode-client-metadata` 的 404 已定位为 Go 后端缺路由,不是 DNS、TLS 或 Nginx 丢路由; +2. 只发布 JSON 不能修好现有 CIMD:宿主使用随机 `localhost` 回调,而静态文档需要稳定、可验证的注册回调; +3. Acosmi 自己的两份 OAuth metadata 广告 `client_id_metadata_document_supported=true`,服务端却不接受 URL client ID; +4. SettingsPage 的鉴权状态也不可靠:当前 worker 把所有 HTTP/SSE 默认投影为 `notLoggedIn`; +5. GUI OAuth 成功后只更新展示状态,不清同配置 connection memoize,也不自动 reconnect/tools-list; +6. Asana standalone 仍使用已退役 SSE,HubSpot 仍使用 `/anthropic` 供应商绑定路径; +7. Slack 受 Marketplace/内部应用资格限制;Asana、HubSpot、BigQuery 需要预注册凭据; +8. Snowflake、Databricks、Benchling 引用 6 个不存在的 manifest `userConfig` 字段; +9. 12 个 LSP 不实现 MCP,不能通过改 manifest 一步变成全端可用 LSP; +10. 跨插件 token 共享、运行时远程 connector `$ref`、自动业务 canary 和本批建设 OAuth broker 均从本方案删除。 +11. 当前仓库不存在 `mcpConnectorProfiles.json`、Skill/prompt capability inventory 或 `mcp-release-lock*.json`,本次审计也未取得跨账号 DR/WORM/OIDC 双人审批已验收证据;它们是实施交付,不是当前能力。 + +## 1. 健康与证据口径 + +### 1.1 端到端健康 + +一个生产连接器同时满足以下条件才是 healthy: + +1. marketplace、manifest、`.mcp.json` 路径和 schema 有效; +2. 用户能理解并完成 MCP 独立激活; +3. required/optional/sensitive 配置和变量引用一致; +4. 本地依赖在激活前完成 doctor; +5. 认证 profile 是机器可读单值,不依靠 transport 猜测; +6. OAuth/Bearer/外部登录在当前客户端真实完成; +7. `initialize` 和 `tools/list` 在预算内成功; +8. 实际 tools/list 中 required tools 与 certified snapshot 的名称/schema hash 一致; +9. 模型能用安全的逻辑别名找到 canonical wire tool; +10. 用户显式调用时成功,错误能被准确分类; +11. 发布资格、供应商条款和组织管理员前置条件均满足。 + +以下状态必须分开: + +```text +published ≠ installed ≠ plugin-enabled ≠ mcp-activated + ≠ configured ≠ authenticated ≠ connected + ≠ discoverable ≠ callable ≠ provider-approved +``` + +### 1.2 探测结果枚举 + +机器可读证据只允许: + +```text +pass | fail | not-tested | not-applicable +``` + +解释规则: + +- HTTP 200 只证明该请求成功; +- HTTP 401 只证明该 URL 在探测时可达并拒绝匿名请求; +- 401 只有同时具备有效 `WWW-Authenticate`、RFC 9728 Protected Resource Metadata、Authorization Server Metadata 才称有效 OAuth challenge; +- `initialize/tools-list` 成功不代表业务工具已授权; +- 技术调用成功不代表 Acosmi 获得了使用第三方托管端点的生产资格; +- `not-tested` 固定阻断生产发布。 + +### 1.3 发布支持与运行时状态分离 + +本方案不新增 `supported/degraded/blocked` 第二套运行时状态机。发布面和运行面分别处理: + +- 发布面:远程与 `providerInteraction=external-service` 的 stdio `publish/block` 都进入本地 `.crabcode-plugin/connector-profiles.json`,只有 generation=2 宿主能在 effective publish/lease 通过后物化;只有 `providerInteraction=local-only` 的 stdio `publish` 进入 `.mcp.json`;tombstone 不进入任何运行/管理生成物; +- 运行面:扩展现有 `PluginMcpLifecycleMetadata.reasonCode`,不复制平行状态机。 + +新增 reason code 固定为: + +```text +endpoint-retired +non-production-endpoint +vendor-specific-endpoint +endpoint-unreachable +endpoint-tls-unreachable +region-access-denied +provider-contract-missing +provider-app-approval-required +protocol-mismatch +distribution-not-self-contained +legacy-remote-config +profile-integrity-failed +release-infrastructure-unavailable +release-head-stale +release-head-equivocation +control-service-unavailable +config-schema-missing +config-origin-invalid +secret-config-schema-missing +principal-config-missing +secure-storage-unavailable +provider-subject-mismatch +platform-unsupported +dependency-missing +auth-profile-unclassified +oauth-registration-unavailable +oauth-discovery-policy-mismatch +oauth-client-config-missing +authentication-required +external-auth-required +auth-state-unknown +cimd-document-unavailable +oauth-flow-in-progress +oauth-callback-port-in-use +oauth-callback-policy-mismatch +oauth-callback-busy +oauth-flow-stale +host-oauth-reconnect-missing +provider-e2e-unverified +requires-login +tool-alias-ambiguous +skill-dependency-unclassified +tool-contract-drift +connector-instance-ambiguous +``` + +未命中新 reason code 的既有状态继续使用: + +```text +plugin-disabled | inactive | requires-config | invalid-config +requires-dependency | required-not-local | ready +``` + +`nextAction` 只允许: + +```text +none | enablePlugin | activate | updatePlugin | configure | enterToken +installDependency | oauthLogin | externalLogin | diagnose | retry +selectCanonicalTool | selectConnection | replaceConnection +``` + +同一连接器只向用户暴露一个首要 blocker。优先级固定为: + +```text +retired / non-production / vendor-specific +→ provider contract / provider approval +→ protocol / distribution / legacy config +→ release-head-equivocation / release-infrastructure-unavailable / profile-integrity-failed / release-head-stale / control-service-unavailable +→ config / principal / secret / dependency +→ auth discovery / registration / client configuration +→ CIMD / host runtime +→ endpoint +→ provider E2E / readiness +→ tool contract / skill dependency / connection selection / tool alias +``` + +OAuth 按钮的唯一判定是 canonical `nextAction=oauthLogin`;reasonCode 只用于文案/审计,不作第二层 UI 条件。 + +reason code 与 nextAction 固定映射: + +| reasonCode | nextAction | +| --- | --- | +| `plugin-disabled` | `enablePlugin` | +| `inactive` | `activate` | +| `requires-config` / `invalid-config` | `configure` | +| `requires-dependency` | `installDependency` | +| `required-not-local` / `ready` | `none` | +| `endpoint-retired` / `non-production-endpoint` / `vendor-specific-endpoint` | `none` | +| `provider-contract-missing` / `provider-app-approval-required` | `none` | +| `protocol-mismatch` / `distribution-not-self-contained` | `none` | +| `legacy-remote-config` | `updatePlugin` | +| `profile-integrity-failed` | `updatePlugin` | +| `release-infrastructure-unavailable` | `none` | +| `release-head-stale` | `retry` | +| `release-head-equivocation` | `none` | +| `control-service-unavailable` | `retry` | +| `config-schema-missing` | `none` | +| `config-origin-invalid` | `configure` | +| `principal-config-missing` | `none` | +| `secret-config-schema-missing` | `none` | +| `secure-storage-unavailable` | `none` | +| `provider-subject-mismatch` | `replaceConnection` | +| `platform-unsupported` | `none` | +| `dependency-missing` | `installDependency` | +| `auth-profile-unclassified` / `oauth-registration-unavailable` | `none` | +| `oauth-discovery-policy-mismatch` | `none` | +| `oauth-client-config-missing` | `configure` | +| `authentication-required` | `enterToken` | +| `external-auth-required` | `externalLogin` | +| `auth-state-unknown` | `diagnose` | +| `requires-login` | `oauthLogin` | +| `cimd-document-unavailable` | `retry` | +| `oauth-flow-in-progress` | `none` | +| `oauth-callback-port-in-use` | `retry` | +| `oauth-callback-policy-mismatch` | `configure` | +| `oauth-callback-busy` | `retry` | +| `oauth-flow-stale` | `retry` | +| `host-oauth-reconnect-missing` / `provider-e2e-unverified` | `none` | +| `endpoint-unreachable` / `endpoint-tls-unreachable` | `retry` | +| `region-access-denied` | `none` | +| `tool-alias-ambiguous` | `selectCanonicalTool` | +| `skill-dependency-unclassified` / `tool-contract-drift` | `none` | +| `connector-instance-ambiguous` | `selectConnection` | + +`diagnose` 只执行一次无凭据 connect/initialize 探测:不注册 client、不打开浏览器、不删除 token、不写 secure storage。initialize 成功时把手工连接器收敛为 `authMode=none`;有效 401 challenge 收敛为 `requires-login`;缺注册路径收敛为 `oauth-registration-unavailable`;其他错误按 endpoint reason code 收敛。 + +`oauth-flow-in-progress` 不提供第二个操作按钮;只有第 4.2 节 `requestIntentKey` 完全相同的窗口才在分配 generation 前订阅已存在 leader 的 singleflight terminal result。不同 intent 返回 `oauth-callback-busy`,不得接收当前 flow 的 URL、token 或 terminal result。 + +`replaceConnection` 在用户确认后固定执行:关闭旧 instance → 最佳努力 revoke → 将旧 index 写为 deleted → 永久废弃旧 connectionInstanceId → 生成新 UUIDv4 instance → 返回新 instance 的 canonical blocker/nextAction。它不在旧 instance 上直接启动 OAuth,不得把新 provider subject 绑到旧 owner key。 + +## 2. 全仓盘点 + +### 2.1 当前总量 + +| 指标 | 数量 | +| --- | ---: | +| `plugins/*` 顶层插件 manifest | 77 | +| marketplace entries | 76 | +| 含 `.mcp.json` 的插件 | 43 | +| MCP 服务声明 | 130 | +| HTTP | 102 | +| SSE | 1 | +| stdio | 27 | +| 唯一远程 URL | 50 | +| 固定远程 URL | 47 | +| 租户模板 URL | 3 | +| 重复远程声明 | 53 | +| `requiredMcpServers` | 2(`mediaops`、`html-video`) | + +77 个顶层 manifest 与 76 个 marketplace entry 不相等:`crabcode-media-publisher`、`crabcode-security` 有本地 manifest 但不在 marketplace;`crabcode-setup` 的 marketplace source 指向仓库根而不是 `plugins/crabcode-setup`。本报告不把 marketplace entry 数误写成 manifest 数。 + +重复最多的远程端点: + +| 端点 | 声明次数 | +| --- | ---: | +| Slack | 10 | +| Notion | 10 | +| Atlassian | 10 | +| Asana | 7(6 个 V2 + 1 个退役 SSE) | +| Linear | 5 | +| HubSpot | 4 | + +重复声明说明连接器定义缺少 build-time 单一真源;它不授权运行时共享 token。 + +### 2.2 103 条远程声明互斥守恒 + +当前 103 条远程声明按认证与处置互斥分类: + +```text +17 CIMD + DCR +23 metadata DCR-only(目标 profile 中 22 OAuth DCR + 1 Tencent Docs Bearer) +10 Slack + 6 Asana V2 + 1 Asana SSE + 4 HubSpot + 1 BigQuery + 2 GitHub + 1 Greptile + 3 租户模板 + 4 Claude 专属 + 5 example + Similarweb + Owkin + 1 Open Targets +25 auth profile 未闭合 +--- +103 +``` + +CIMD + DCR 的 17 条: + +```text +Notion 10 + Linear 5 + Canva 1 + Synapse 1 +``` + +DCR-only metadata 的 23 条: + +```text +Amplitude US 3 + Amplitude EU 3 + Figma 3 ++ ClickUp 2 + Monday 2 ++ Ahrefs/Apollo/Close/Consensus/GitLab/Hex/Pendo/ + Tencent Docs/Wiley/ZoomInfo 各 1 +``` + +metadata 广告能力不等于目标 authMode。Tencent Docs 当前已有 sensitive Bearer token 合同,本方案保留 Bearer,不切换 DCR;因此目标 `oauth+dcr` binding 为 22。 + +auth profile 未闭合的 25 条: + +```text +Atlassian 10 + Intercom 3 + Guru 2 + Fireflies 2 ++ BioRender/Clay/Datadog/Definite/Klaviyo/ + Outreach/PagerDuty/Supermetrics 各 1 +``` + +结构整改后的绑定账面(包含 blocked binding,不等于唯一 profile 数或生产可执行数): + +| 指标 | 当前 | 目标 | +| --- | ---: | ---: | +| plugin-to-profile bindings | 130 | 117 | +| 被 binding 引用的 catalog profiles | 尚未建立 | 63(48 remote + 15 stdio) | +| unbound tombstones | 尚未建立 | 3(Asana SSE、HubSpot `/anthropic`、example) | +| HTTP | 102 | 102 | +| SSE | 1 | 0 | +| stdio | 27 | 15 | +| 唯一远程 URL | 50 | 48 | +| 固定远程 URL | 47 | 45 | +| 模板 URL | 3 | 3 | +| `requiredMcpServers` | 2 | P0-0 为 1(html-video);P1 mediaops 验收后为 2 | + +117 个 binding 由三项固定改造产生:Asana SSE 原位迁移为 HTTP V2、删除 12 个 LSP 伪 MCP binding、删除 example binding。63 个 bound profile 是 48 个远程 profile 与 15 个 stdio profile 的和;重复插件引用只增加 binding,不增加 profile。Asana SSE、HubSpot `/anthropic`、example 各保留一条 unbound tombstone,专门阻止旧配置回潮,不计入 63。 + +15 个目标 stdio profile 再互斥拆为 6 个 local-only(html-video、mediaops、Fakechat、Playwright、Serena、Laravel Boost)与 9 个 external-service(Discord、Telegram、iMessage、Context7、Alipay、DingTalk、Feishu、Firebase、Terraform)。iMessage 虽通过本地 Messages/AppleScript 中介,业务操作仍会进入 Apple 消息服务,不得冒充 local-only。前者通过各自 P1 gate 后才可进 `.mcp.json`;后者永不进 `.mcp.json`,只能由 generation=2 在 provider lease 通过后从 connector profile 物化/spawn。P0-0E/P0-0B 仍只保留 html-video 1 个 stdio runtime。 + +### 2.3 27 个 stdio 服务 + +| 分类 | 数量 | 当前裁决 | +| --- | ---: | --- | +| 第一方预构建 sidecar | 2 | 进程基础健康;另有身份/版本问题 | +| 误归类 LSP proxy | 12 | 不是 MCP,生产声明必须删除 | +| Discord/Fakechat/iMessage/Telegram | 4 | 实现 MCP,但发行物、配置和平台权限未闭合 | +| 第三方 wrapper | 9 | 外部依赖型,不能宣称安装即用 | + +### 2.4 固定公网端点实测 + +47 个固定 URL 的无凭据结果必须按下表解释: + +| 证据结果 | 数量 | 生产结论 | +| --- | ---: | --- | +| 匿名代表性调用成功 | 1 | PubMed 技术通过,但 `*.mcp.claude.com` 的生产使用资格未成立,因此仍不发布 | +| 握手成功、业务需要凭据 | 2 | Greptile、BigQuery;不能显示 usable | +| 仅握手成功、业务调用未验证 | 4 | bioRxiv、ChEMBL、ClinicalTrials、Open Targets;固定为 blocked | +| HTTP 401 | 36 | 只证明 HTTP 可达,不证明登录链健康 | +| HTTP 403 | 1 | Owkin;固定为 region-access-denied | +| TLS/连接失败 | 3 | `mcp.example.com` 与两个 Similarweb URL;固定阻断 | + +三条租户模板 URL 未发送网络请求;它们同时缺 manifest 配置合同,因此当前证据状态为 `not-tested`、发布状态为 blocked。 + +### 2.5 第一方本地 sidecar + +`crabcode-media-ops`: + +- `dist/server.js` 可直接启动; +- MCP 连接耗时 86ms; +- `tools/list` 返回 38 个工具; +- `mediaops.capabilities` 成功; +- 匿名 `mediaops.content.save` 返回 `AUTHENTICATION_REQUIRED`; +- 业务错误被装入普通 envelope,MCP result 的 `isError` 仍为 false; +- 默认配置没有 `local-editorial` 或可信 host principal。 + +`crabcode-html-video`: + +- dist-only bootstrap 通过; +- MCP 连接耗时 128ms; +- 暴露 5 个工具; +- 最小 `validateGraph` 调用成功; +- manifest/package 为 `0.1.2`,serverInfo 仍为 `0.1.0`。 + +`html-video` 版本漂移纳入 P0-0 safe baseline 发行卫生;它不是登录根因,但不修复就无法通过第一方版本 hard gate。 + +### 2.6 当前门禁 + +`bun run lint:mcp-contract` 的本轮结果: + +```text +MCP warnings = 27 +errors = 1 +``` + +唯一 error 是用户既存工作树中 `cn-legal-study` manifest 与 marketplace 版本不一致,与 MCP 健康无直接关系。 + +27 个 MCP warning: + +- 12 个 raw LSP proxy; +- 4 个频道启动时安装依赖; +- 4 个频道缺 `channels` 声明; +- 7 个浮动/未钉版本启动器。 + +当前 validator 没有检查: + +- endpoint/profile 官方真源; +- OAuth registration 方式; +- `WWW-Authenticate` 与 metadata; +- provider app 审批; +- `${user_config.*}` 引用与 manifest 双向一致; +- `${ENV_TOKEN}` 的安全配置入口; +- 业务级延迟认证; +- 逻辑工具别名; +- 第三方托管端点使用资格。 + +## 3. 生产服务器与 Acosmi 上游结论 + +> **独立处理(ACOSMI-SRC / ACOSMI-REL)**:本节仅保留跨仓根因证据与发布门。Acosmi 仓内修改、专项测试、生产发布和安全回滚须在独立任务/工作树/评审中按《[Acosmi CIMD 与发布基础设施独立整改方案](./2026-08-22-Acosmi-CIMD与发布基础设施独立整改方案.md)》执行;不得与 CrabCode-Plugin 或 CrabCode 变更合并为同一实施任务。 + +### 3.1 生产运行态 + +只读 SSH 实测: + +```text +host: iZ2ze3n41ornpm1iprmunhZ +nginx: active +nexus: active +tkdist-java: active +``` + +公网与本机 Host 探测: + +```text +GET https://acosmi.com/oauth/crabcode-client-metadata +→ 404, Content-Type: text/plain + +GET https://127.0.0.1/oauth/crabcode-client-metadata +Host: acosmi.com +→ 404, Content-Type: text/plain +``` + +Nginx 生效配置已经包含: + +```nginx +location /oauth/ { + proxy_pass http://127.0.0.1:8009; +} +``` + +所以 404 责任层固定为 Go 后端缺 GET handler。P0 不修改 Nginx,避免扩大线上手工配置漂移面。 + +### 3.2 Acosmi 自身虚假 CIMD 广告 + +生产普通及 desktop metadata 都返回: + +```json +{ + "registration_endpoint": "存在", + "client_id_metadata_document_supported": true +} +``` + +但 `AuthorizationServer.Authorize` 对未知 HTTPS client ID 直接返回 `invalid_client`;`DesktopOAuthHandler.Authorize` 也只查询已注册 client。源码中的 `FetchClientIDMetadata` 与 `DetermineClientRegistration` 均无生产调用点。 + +固定处置: + +1. 从普通 metadata 删除 `client_id_metadata_document_supported`; +2. 从 desktop metadata 删除同字段; +3. 保留 DCR; +4. 不在本批接线 AS 侧 CIMD; +5. 本方案保留未接线 helper,不把它计入可用能力。 + +### 3.3 现有 Acosmi MCP OAuth handler 禁止复用 + +现有端点: + +```text +POST /api/v4/plugins/mcp/oauth/authorize +GET /api/v4/plugins/mcp/oauth/callback +``` + +它们不能作为 CrabCode 下游 OAuth broker: + +- 路由要求 JWT 且角色为 owner/admin; +- client ID、secret、redirect URI 从 Gin context 读取,全仓没有相应 `c.Set`; +- state 是可预测 `userID|endpoint`; +- callback 丢弃解析出的 userID; +- Redis token key 只有 endpoint,没有 user/tenant/provider/resource; +- token 以普通 JSON 写 Redis; +- access token 到期后 5 分钟即删除整个记录,refresh token 一并丢失。 + +固定处置:保持隔离、默认不可用,不增量扩建,不把它写成 P0 可复用能力。 + +## 4. OAuth 与连接生命周期根因 + +### 4.1 CrabCode CIMD URL 404 + +宿主固定 client ID URL: + +```text +https://acosmi.com/oauth/crabcode-client-metadata +``` + +MCP SDK 在授权服务器广告 CIMD 时优先使用该 URL,不走 DCR。当前 URL 返回 404,影响: + +| 服务 | 声明数 | 当前注册能力 | +| --- | ---: | --- | +| Notion | 10 | CIMD=true,另有 DCR | +| Linear | 5 | CIMD=true,另有 DCR | +| Canva | 1 | CIMD=true,另有 DCR | +| Synapse | 1 | CIMD=true,另有 DCR | + +合计 17 处声明。Synapse metadata 已从 Acosmi CN 生产服务器只读复核:issuer=`https://mcp.synapse.org/`、registration endpoint 存在、CIMD=true。 + +现行参考: + +- [MCP Client Registration](https://modelcontextprotocol.io/specification/draft/basic/authorization/client-registration) +- [OAuth Client ID Metadata Document](https://datatracker.ietf.org/doc/draft-ietf-oauth-client-id-metadata-document/) +- [RFC 8252 Native Apps](https://www.rfc-editor.org/rfc/rfc8252) + +### 4.2 回调 URI 合同不闭合 + +当前宿主: + +```text +生成: http://localhost:<49152-65535随机端口>/callback +监听: 127.0.0.1:<同端口> +``` + +本方案固定改成: + +```text +CIMD / DCR / 预注册 profile: + http://127.0.0.1:3118/callback +``` + +进入 singleflight 和分配 credential generation 之前,control service 必须先执行 `discoverAuthPolicy`。`authDiscovery=fixed` 从 catalog 读取 issuer/resource;`authDiscovery=challenge-first` 则从无凭据 challenge/metadata 得出 issuer/resource。scope 独立按 `scopePolicy` 处理:`fixed` 只用 catalog fixedScopes,`challenge-first` 执行一次无凭据 initialize/HTTP challenge,按 `WWW-Authenticate scope → Protected Resource Metadata scopes_supported → minimumScopes` 得出。任何网络 discovery 只对已通过 endpoint/template SSRF gate 的 resolved endpoint 执行,并按 RFC 9728 取回 Protected Resource Metadata 和 Authorization Server Metadata。该阶段禁止 DCR、打开浏览器、绑定 callback、读/写 secure credential 或分配 generation;metadata GET 禁止 redirect,单文档上限 64 KiB,issuer/resource 必须为 public HTTPS 且通过 origin/SSRF policy。发现的 scopes 按 Unicode NFC、trim、去重、UTF-8 字典序规范化,且必须是 catalog maximum/fixed scope policy 允许的子集;issuer/resource/scope 缺失、歧义或越权时返回 `oauth-discovery-policy-mismatch`。只有 discovery 成功后才计算 authPolicyFingerprint/scopeFingerprint 并进入下述 request-intent singleflight;失败时 generationHighWatermark 不变。 + +immutable discovery snapshot 固定为 `JCS({authDiscovery,issuer,resource,authorizationEndpoint,tokenEndpoint,registrationEndpoint|null,tokenEndpointAuthMethods,codeChallengeMethods,normalizedScopes,protectedResourceMetadataSha256|null,authorizationServerMetadataSha256})`;URL 都是验证后 canonical 值,方法/scope 数组去重后按 UTF-8 字典序排序。`discoverySnapshotSha256` 是该 JCS 字节 SHA-256,不包含 challenge header 原文、cookie、authorization URL query 或任何凭据。 + +generation=2 的所有交互式 OAuth 与 credential CRUD 统一进入每个 OS 用户唯一的 MCP control service;GUI、TUI、CLI 都是经身份校验的 IPC client,不直接读写 secure index 或绑定 callback 端口。control service 先在全局 callback-port lock 内计算 `requestIntentKey=sha256(JCS([credentialOwnerId,connectorProfileId,connectionInstanceId,authPolicyFingerprint,scopeFingerprint]))`:已有同 key leader 时 follower 不分配 generation,只返回 `oauth-flow-in-progress` 并订阅;已有不同 key leader 时返回 `oauth-callback-busy`。只有 leader 按第 4.7 节分配唯一 `newGeneration`,然后形成 `flowIdentity=JCS([requestIntentKey,newGeneration])`。 + +交互流期间更新/清除 client ID、client secret、registration 或 policy 时,credential mutation 先把现有 leader 标记为 stale,等待其释放 callback-port lock,再执行新操作;新请求不得订阅已 stale flow。端口被非 control service 进程占用返回 `oauth-callback-port-in-use`,不静默换端口。DCR 注册记录持久化 `registeredRedirectUri=http://127.0.0.1:3118/callback`,后续授权逐字符复用;generation=1 随机端口 DCR client 不迁移。 + +control service IPC 安全合同固定为: + +- service 作为 generation=2 宿主产物一同签名/打包;macOS 由 per-user LaunchAgent、Windows 由 per-user startup task、Linux 由 `systemd --user` socket activation 启动,禁止系统级共享 daemon。首客户端只能通过 OS 级 singleton lock 启动一个实例,3 秒内 socket/pipe 未 ready 即返回 `control-service-unavailable`; +- macOS 使用 `$HOME/Library/Application Support/CrabCode/run/mcp-control-v2.sock`,父目录 owner=当前 UID/mode=0700,socket mode=0600,通过 `getpeereid` 验证 peer UID 与 service UID 相同; +- Linux 只使用 `$XDG_RUNTIME_DIR/crabcode/mcp-control-v2.sock`,要求 runtime dir owner=当前 UID/mode=0700,socket mode=0600,通过 `SO_PEERCRED` 验证 UID;`XDG_RUNTIME_DIR` 缺失/权限错误时不回退 `/tmp`; +- Windows 使用 `\\.\pipe\CrabCode\McpControlV2\`,DACL 只允许当前用户 SID,启用 `PIPE_REJECT_REMOTE_CLIENTS`,服务端通过 client process token 再次比对 SID; +- 三平台都禁止 TCP/HTTP/WebSocket fallback,禁止跨用户共享 socket/pipe; +- 协议只接受 4-byte big-endian length + UTF-8 JSON,`protocolVersion=2`,单帧上限 1 MiB,超限/未知 method/未知字段直接断开;method allowlist 只包含 status、OAuth start/cancel、credential set/update/clear、connection replace/select,不提供 token/secret export/read method; +- 每条 IPC 连接由 service 生成 256-bit `sessionNonce`,client 请求必须带该 nonce、UUIDv4 requestId 和从 1 递增的 uint64 sequence;service 缓存当前连接已见 requestId,拒绝 nonce 不符、重放、跳号/回退,断线后 nonce 立即失效; +- secret/token/code 只在内存请求对象和 OS credential backend 之间流转,IPC access/error/debug log 只记 method、requestId、脱敏 owner hash、result code 和 latency; +- socket/pipe 不存在、所有者/权限错误、peer UID/SID 不符或协议版本不匹配时返回 `control-service-unavailable`,不回退到客户端直接读写凭据。 + +必测负向用例为:伪造/不同 UID、不同 Windows SID、remote named-pipe client、错误 socket owner/mode、TCP 连接、>1 MiB 帧、未知字段/method、旧 nonce、重复 requestId、sequence 回退/跳号。全部必须在凭据读写前拒绝,且日志中 secret/token/code 命中数为 0。 + +### 4.3 不实施每次登录本地预检后切 DCR + +客户端能 GET CIMD 不等于授权服务器能 GET;按单次网络结果在 CIMD client ID 与 DCR client ID 间切换会制造身份、token 和注册记录分裂。 + +固定策略: + +- `clientRegistration=cimd` 始终使用 CIMD;文档不可达即返回 `cimd-document-unavailable`; +- `clientRegistration=dcr` 始终使用 DCR; +- `clientRegistration=preregistered-user` 始终使用用户配置的 client ID; +- 登录过程中不切换 registration; +- profile 变化通过 `authPolicyGeneration` 触发迁移。 + +DCR registration 只允许由用户显式 `nextAction=oauthLogin` 触发;安装、插件启用、状态列表、doctor、release probe 和普通 reconnect 均不得注册 OAuth client。 + +### 4.4 confidential provider 不能写成“注册一下” + +| Provider | 官方约束 | 本方案固定处置 | +| --- | --- | --- | +| Slack | confidential OAuth;只允许 Marketplace 已发布应用或内部应用使用 MCP | 面向全体用户保持 blocked,reason=`provider-app-approval-required`;本批不建 broker | +| Asana V2 | client ID + client secret + 精确 redirect | `preregistered-user`;用户创建 Asana MCP app,secret 存 OS credential backend | +| HubSpot | MCP auth app + client ID/secret + PKCE + 精确 redirect | canonical URL 固定为 `https://mcp.hubspot.com/`,使用 `preregistered-user`,secret 存 OS credential backend | +| BigQuery | 不支持 CIMD/DCR;OAuth client/Google identity | 本批只实现 `preregistered-user`,不实现 ADC | + +官方依据: + +- [Slack MCP Server](https://docs.slack.dev/ai/slack-mcp-server/) +- [Asana V2 MCP](https://developers.asana.com/docs/connecting-mcp-clients-to-asanas-v2-server) +- [HubSpot Remote MCP](https://developers.hubspot.com/docs/apps/developer-platform/build-apps/integrate-with-the-remote-hubspot-mcp-server) +- [Google Cloud MCP Authentication](https://docs.cloud.google.com/mcp/authenticate-mcp) + +### 4.5 SettingsPage 与 worker 鉴权状态错误 + +当前 `mcp-status-list.ts`: + +```text +HTTP/SSE → oauthCapable=true → notLoggedIn +``` + +该推断把以下连接器混在一起: + +```text +anonymous +bearer token +OAuth +ADC/CLI/external identity +unknown +``` + +结果: + +- 匿名/unknown HTTP 在没有显式 authStatus override 时出现 OAuth 按钮; +- Bearer 配置没有被 lifecycle 正确投影时出现 OAuth 按钮; +- plugin `authState=unknown + lifecycle=ready` 显示按钮,后端点击后又拒绝; +- 手工 HTTP/SSE 没有 lifecycle 时会被当前 authorization guard 放行并误启动 OAuth; +- `performMCPOAuthFlow` 在真正完成新授权前会删除旧本地 client/token,误点可破坏现有会话。 + +固定修复: + +1. worker 不再按 transport 生成 `notLoggedIn`; +2. build-time profile 提供 authMode/clientRegistration; +3. runtime 401/discovery 将 `unknown` 收敛为 `requires-login`; +4. 只有 `nextAction=oauthLogin` 时显示 CTA; +5. 重新授权使用 pending credential slot;新 token 成功后原子替换,失败保留但不发送 legacy token; +6. 旧 token 最佳努力撤销,撤销失败记录脱敏审计但不回滚新 token。 + +### 4.6 OAuth 成功不等于连接恢复 + +当前 GUI 链路: + +```text +performMCPOAuthFlow success + → mcpServer/oauthLogin/completed + → GUI store 显示 success +``` + +缺失: + +```text +exact connection cache eviction +active config revalidation +reconnect +initialize +tools/list +startup status +``` + +`mcp reload` 会清认证负缓存,但 `clearStaleServerCachesForConfigs` 对 active exact key 直接保留,旧 memoized `needs-auth` Promise 仍存在。 + +固定修复由 control worker 完成: + +```text +token success + → 重读 active config + → 复算 authPolicyFingerprint 并核对 pending generation + → 检查中途 disable/remove/policy blocker + → evictExistingServerCache(exact key) + → reconnect + → initialize/tools-list + → startupStatus/updated + → oauthLogin/completed +``` + +多窗口不各自发起 reload;只有 identity 匹配的窗口接收该 flow 结果。 + +callback 收到 code 后、token exchange 之前,以及 credential entry 写入后、index swap 之前,worker 都必须重读 catalog/active config/index,并同时满足:`computedAuthPolicyFingerprint=flow.authPolicyFingerprint`、`index.pending.generation=flow.newGeneration`、`index.pending.policyFingerprint=flow.authPolicyFingerprint`、`index.pending.discoverySnapshotSha256=flow.discoverySnapshotSha256`、内存 immutable discovery snapshot 重算 SHA 与该值一致、`index.currentState=legacy`、profile 未 disable/remove/block。不在 callback 中重新联网发现并悄然改变 flow;若 control service 已获得不同的新 discovery snapshot,必须先将旧 flow 标记 stale。任一不符时立即销毁内存 code/token,删除该 flow 已写的 pending credential entry,保留代际高水位和 legacy current,只向该 `flowIdentityHash` 发送 `oauth-flow-stale`;禁止 swap、reconnect 或广播 success。 + +### 4.7 凭据 key 缺少认证策略 generation + +当前 `getServerKey` 只纳入: + +```text +serverName + type + url + headers +``` + +它没有纳入 client ID、registration、issuer、resource、scope policy、callback profile。`clientInformation()` 又优先返回已存 client ID,因此存在旧记录时会继续使用旧 CIMD/DCR 身份。 + +固定新增: + +```text +authPolicyGeneration = 2 +authPolicyFingerprint = sha256(JCS([ + "mcp-auth-policy-v2", + profilePolicyFingerprint, + authMode, + clientRegistration, + preregisteredClientIdOrNull, + issuer, + resource, + normalized scopes, + callbackProfile, + discoverySnapshotSha256 +])) +``` + +fingerprint 只含 credential mutation/generation 分配前可获得的 catalog 与第 4.2 节无凭据 discovery 结果;完整 discovery snapshot 的 SHA-256 写入 pending 审计字段,但不写 raw response header/query。DCR 服务的 `preregisteredClientIdOrNull=null`,动态注册得到的 client ID 和 `credentialGeneration` 都不进入 fingerprint,避免 secure-storage 寻址自举循环。 + +`authMode!=oauth` 时 fingerprint 中 issuer/resource/normalizedScopes/callbackProfile/preregisteredClientIdOrNull 使用字面 `not-applicable`,`discoverySnapshotSha256` 使用 64 个零字符;禁止省略元素导致不同 authMode 的 tuple 长度不同。Bearer 的 config schema/binding 已由 profilePolicyFingerprint 覆盖,实际 token 值仍不进任何 fingerprint。 + +每个稳定 credential index record 保存: + +```text +schemaVersion=2 +revision +generationHighWatermark +currentState=active|legacy|deleted +currentPolicyFingerprint +currentCredentialGeneration|null +currentCredentialEntryKey|null +currentRegistrationEntryKey|null +providerSubjectHash|null +pending|null|{operation,policyFingerprint,discoverySnapshotSha256|null,generation,baseCredentialGeneration|null,credentialEntryKey|null,registrationEntryKey|null,expiresAt} +``` + +`generationHighWatermark` 是 index 内持久化、只增不减的代际高水位;`credentialGeneration` 不得作为下一代计算来源。OAuth client secret、Bearer/PAT、DCR client secret 的新增、更新、清除,authPolicyFingerprint 变化,以及 OAuth token refresh 都分配 `newGeneration=generationHighWatermark+1`。失败、超时、进程崩溃和清除操作都不得回退高水位或复用代际号。 + +`revision` 是每次 index 更新都 +1 的乐观并发版本。control service 对 `credentialIndexKey` 取跨进程命名互斥(macOS `flock` 锁定 app-state 下仅含 index hash 的 0600 lock file;Windows named mutex;Linux `flock`),锁内重读 secure index,只在 `revision=observedRevision` 时原子替换为 `revision+1`。revision 不符时丢弃未写入结果、重读并重新分配;禁止 last-writer-wins。control service 崩溃时 OS 释放互斥,下一进程按 pending 恢复规则接管。 + +index 状态语义固定为: + +- `active`:只有 current policy fingerprint 匹配且 current entry 读回校验成功时才可发送; +- `legacy`:current entry 仅为撤销/审计保留,generation=2 永不发送; +- `deleted`:本地不存在可用凭据,current credential/registration pointer 均为 null;`currentCredentialGeneration` 保留该次删除代际,防止旧写入复活。 + +迁移/轮换顺序: + +1. index 不存在时在 per-index 跨进程互斥内建立 `revision=1,generationHighWatermark=0,currentState=deleted`的空记录; +2. `authorize|replace|clear` leader 在同一互斥内重读 index,分配 `newGeneration=highWatermark+1`,以 revision compare-and-swap 原子持久化新高水位、`currentState=legacy`、`pending=null`,再读回校验;从这一步起旧 current 只保留但不得发送;CAS 失败时不得沿用已计算 generation; +3. 把含同一 `newGeneration` 的 pending 描述原子写进 index;`operation` 只能为 `authorize|replace|refresh|clear`,非 refresh 时 `baseCredentialGeneration=null`;OAuth authorize/replace/refresh 的 `discoverySnapshotSha256` 必须等于第 4.2 节该 flow 的不可变 discovery snapshot,Bearer/clear 为 null; +4. PKCE/auth code/token/新 secret 只保存在进程内 pending slot,TTL=5 分钟;DCR registration 写 pending registration entry; +5. 新 credential entry 写入并读回校验;已读回校验的 DCR registration 可先原子更新 `currentRegistrationEntryKey`,因用户拒绝/超时而重试时必须复用,不再注册; +6. `authorize|replace` 成功时单次原子更新 index:`current=pending,currentState=active,pending=null`; +7. `clear` 操作在本地删除决定后单次原子更新:`currentCredentialGeneration=newGeneration,currentCredentialEntryKey=null,currentRegistrationEntryKey=null,currentState=deleted,pending=null`;provider revoke 失败只记录脱敏 failure code,不得使本地旧凭据复活; +8. index swap 成功后最佳努力撤销并删除旧 credential/registration entry; +9. `authorize|replace` 授权/写入失败时清理 pending entry 并置 `pending=null`,但必须保留 `generationHighWatermark` 和 `currentState=legacy`;禁止恢复旧 current 为 active; +10. 进程启动发现未过期 pending 时按 operation 分流:`authorize|replace` 只有在 entry 读回、policy/subject 校验全部通过后才执行第 6 步;`clear` 完成第 7 步的 deleted 写入;`refresh` 使用下述 refresh 恢复规则。发现过期/损坏 `authorize|replace|clear` pending 时删除 pending entry 并保持 `currentState=legacy`; +11. 无 pending 但 `currentState=legacy|deleted` 时,启动恢复不得发送 Authorization header; +12. 记录 `auth-policy-migrated`、`credential-rotated`、`credential-refreshed`、`credential-cleared` 或对应 failure code,不记录 secret/token/code/state。 + +refresh 不使用上述“先把 current 置 legacy”的主动替换语义,其固定流程为: + +1. control service 按 `[credentialIndexKey,currentCredentialGeneration,currentPolicyFingerprint]` 做 per-index refresh singleflight;同 key follower 订阅,不发起第二个 token request; +2. leader 在跨进程互斥内重读 active index,以 revision CAS 分配 newGeneration、提高 high watermark,写入 `pending.operation=refresh,pending.baseCredentialGeneration=currentCredentialGeneration`,但保持 `currentState=active` 和旧 current pointer; +3. 锁外调用 token endpoint;响应含新 refresh token 时写入新值,不含时必须从旧 entry 复制原 refresh token,禁止写空;新 access/refresh token 只写 newGeneration entry 并读回校验; +4. 重新取互斥并同时校验 `pending.generation=newGeneration`、`pending.baseCredentialGeneration=currentCredentialGeneration`、policy fingerprint 未变、pending/immutable `discoverySnapshotSha256` 一致和 observed revision,才 CAS 切换 new current、保持 active、清 pending;任一不符则删除该 new entry,迟到/乱序响应不得覆盖已切换 current; +5. timeout、网络错误或 provider 5xx 时清 pending/new entry,保留 high watermark 与旧 active current;`invalid_grant|invalid_client` 或 provider 明确 revoked 时,清 pending 后把旧 current 置 legacy 并收敛为 `requires-login`; +6. 进程恢复发现 refresh pending 时,只有新 entry 完整、未过期且第 4 步全部条件仍成立才切换;否则清 pending/new entry 并保留旧 active current。 + +### 4.8 凭据 owner 与账号/租户隔离 + +generation=2 禁止裸字符串拼接。全部 identity 先按 RFC 8785 JSON Canonicalization Scheme 编码为 UTF-8,再做 SHA-256。 + +```text +hostPrincipal = 已登录时 ["account", tenantId, userId] + = 未登录时 ["installation", installationId] + +credentialOwnerId = hex(sha256(JCS([ + "mcp-owner-v2", + hostPrincipal, + pluginId, + connectorProfileId, + connectionInstanceId +]))) + +credentialIndexKey = "mcp2:index:" + hex(sha256(JCS([ + "mcp-credential-index-v2", + connectorProfileId, + credentialOwnerId +]))) + +credentialEntryKey(generation) = "mcp2:credential:" + hex(sha256(JCS([ + "mcp-credential-entry-v2", + credentialIndexKey, + generation +]))) + +registrationEntryKey(policyFingerprint) = "mcp2:registration:" + hex(sha256(JCS([ + "mcp-registration-entry-v2", + credentialIndexKey, + policyFingerprint +]))) +``` + +credentialIndexKey 不含 clientId、policyFingerprint 或 generation,因此进程重启前即可由非敏感 connection binding 定位 index;secure storage 只保存 hash key,不保存可枚举的原始账号 tuple。 + +`pluginId` 使用宿主现有 source-qualified `getPluginStorageId` 结果,不使用可碰撞的 display name。 + +生成规则: + +1. 已登录 CrabCode 时使用结构化 `hostPrincipal=["account",tenantId,userId]`; +2. 未登录时使用结构化 `hostPrincipal=["installation",installationId]`,其中 installationId 为 256-bit random 且只存 OS credential backend; +3. `connectionInstanceId` 是用户显式创建连接时生成的 UUIDv4,持久化在非敏感 `pluginConfigs[pluginId].mcpConnections[connectorProfileId][]` binding;同一连接重启保持,用户 disconnect 后永久废弃; +4. 一个 connectionInstanceId 只绑定一个 provider account。provider 返回稳定 subject/account ID 时把 SHA-256 写入 index;refresh/reconnect 发现 subject 变化即关闭连接、撤销 token、返回 `provider-subject-mismatch`,不得把同一 instance 改绑新账号; +5. provider 不返回 subject 时仍按 connectionInstanceId 隔离,禁止退回 profile-wide token; +6. CrabCode 登出、账号切换、tenant 切换立即关闭旧 owner 的内存连接并清缓存,不读取其 secure entry; +7. 登出不自动删除旧 owner 的落盘凭据;用户选择 disconnect 才执行 revoke/delete; +8. plugin disable 关闭连接但保留 owner-scoped 凭据;plugin uninstall 执行 disconnect,最佳努力 revoke 后删除本地 credential;两者都不把 credential 转移给其他 pluginId。 + +OAuth/Bearer profile 的 `credentialOwnerScope` 固定为 `host-principal+plugin+profile+connection-instance`;none/external/unsupported profile 固定为 `not-applicable`。 + +切换 provider account 必须 disconnect 旧 instance 并创建新 connectionInstanceId。回归使用两个 CrabCode 用户、两个 tenant、两个 pluginId、两个 profile、两个 connectionInstanceId 的 32 种 tuple,所有 key 必须不同;每个 instance 再分别绑定一个 provider subject 并验证 subject mismatch。额外加入冒号、斜线、Unicode 和空字符串编码负测。账号/tenant 切换后的首个请求不得携带旧 Authorization header。 + +## 5. 连接器 profile 单一真源 + +### 5.1 Profile 结构 + +中央目录只存在于插件仓 build-time,不作为客户端运行时网络依赖。 + +固定落点: + +```text +src/catalog/mcpConnectorProfiles.json +src/catalog/mcpConnectorProfileSchema.ts +src/catalog/skillConnectorInventory.json +src/catalog/promptCapabilityConnectorInventory.json +src/catalog/certified-tools/.json +scripts/generate-mcp-connector-profiles.ts +``` + +generator 的确定性输入只允许:上述 catalog/schema/inventory/certified-tools 文件、`plugins/*/.crabcode-plugin/plugin.json`、被 inventory 引用的 Skill/command/agent Markdown 及第一方 stdio 源模板。certified-tools JSON 文件名必须等于内容 SHA-256,并与 profile ref 及 release artifact digest 一致。generator 禁止读取用户 settings、环境 secret、OS credential backend、provider verdict/法务/供应商证据、HMAC key 或网络;输出 `.mcp.json`、`.crabcode-plugin/connector-profiles.json` 与 connector capability/status。 + +eligibility verdict 不进入 `catalogCommit` 或 generator 输入/包;release validator 在 catalog/plugin artifacts 完成后才输出 `.crabcode-plugin/release-staging/provider-verdicts/.json`,与 lock/envelope 一样被 Git ignore 并从 root setup/package include list 排除,随后作为 lock `artifacts[]` 公开内容寻址产物发布。因此纯 lease 续签不改 catalogCommit/plugin/marketplace digest。provider authorization basis、public terms 取证结果、provider/app/client/distribution/scope/region 集合、reviewerId、private locator、自由文本摘要、批准函/合同/联系人/价格都是 `release-private`,禁止进入 Git、插件包、公开 lock 或 generator 输出。公开 `officialReference` URL 必须为 HTTPS 且无 query/fragment,只作导航,不作资格证据。 + +插件 manifest 新增固定字段: + +```json +{ + "mcpConnectorProfiles": ["provider.profile-id"], + "mcpGeneratedArtifacts": { + "connectorProfilesSha256": "", + "connectorSkillsSha256": "", + "connectorCommandsSha256": "", + "connectorAgentsSha256": "", + "capabilityStatusSha256": "", + "stdioConfigSha256": "" + } +} +``` + +digest 必须是 64 位小写 hex。数组顺序按 profile ID 升序;重复 ID、未知 ID 和同一插件内重复 canonical server name 都是 hard error。不存在的生成物使用 64 个零字符,不省略字段。 + +目录 digest 算法固定为:按 UTF-8 相对路径字典序生成 `pathfileSha256` 清单,再对清单字节做 SHA-256;symlink 和特殊文件直接 hard fail。 + +catalog 顶层是三个互斥集合: + +```text +remoteProfiles: RemoteProfile[] +stdioProfiles: StdioProfile[] +tombstones: Tombstone[] +``` + +RemoteProfile 与 StdioProfile 的公共字段: + +```text +connectorProfileId +logicalServerName +providerKind +authMode +authDiscovery +issuer +clientRegistration +credentialSource +callbackProfile +resource +scopePolicy +minimumScopes +maximumScopes +fixedScopes +configSchema +configBindings +runtimeDependency +credentialOwnerScope +providerInteraction +releaseDecision +ownerTeam +approverTeam +costOwnerTeam +officialReference +certifiedToolsSnapshotRef +certifiedToolsSnapshotSha256 +``` + +上述是 `SourceProfile` 公共字段;source catalog 中 `profilePolicyFingerprint` 必须不存在。`GeneratedConnectorProfile` 是 `SourceProfile + {profilePolicyFingerprint}`,其中指纹必须为 64 位小写 hex,只能由 generator 写入审计镜像与 `.crabcode-plugin/connector-profiles.json`。SourceProfile 出现该字段或 GeneratedConnectorProfile 缺失/不匹配都 hard fail。 + +`profilePolicyFingerprint` 是 generator 派生的公开策略指纹,固定为 discriminated union: + +```text +commonPolicy = { + connectorProfileId, + kind, + transport, + authMode, + authDiscovery, + issuerPolicy, + resourcePolicy, + clientRegistration, + clientIdentityPolicy, + scopePolicy, + minimumScopes, + maximumScopes, + fixedScopes, + callbackProfile, + configSchemaSha256, + configBindingsSha256, + providerKind, + providerInteraction +} + +remotePolicy = { + endpointKind, + urlTemplate, + headersTemplateSha256, + oauthTemplateSha256, + authDoctorSha256 +} + +stdioPolicy = { + runtimeDependency, + executableTemplateSha256, + doctorContractSha256, + supportedPlatforms +} + +RemoteProfile: + sha256(JCS(["mcp-profile-policy-v2", commonPolicy, {remotePolicy}])) + +StdioProfile: + sha256(JCS(["mcp-profile-policy-v2", commonPolicy, {stdioPolicy}])) +``` + +remote 指纹中禁止 stdioPolicy 字段,stdio 指纹中禁止 remotePolicy/endpointKind/urlTemplate 字段;`supportedPlatforms` 去重后按 UTF-8 字典序排序,所有 template/doctor SHA 按不含 secret 实值的 canonical template 字节计算。 + +source catalog 禁止作者手填 `profilePolicyFingerprint`;generator 只在审计镜像和 `.crabcode-plugin/connector-profiles.json` 写入派生值。release validator/runtime 在使用前都重算,与写入值不同时返回 `profile-integrity-failed`。 + +`issuerPolicy/resourcePolicy` 对 OAuth fixed 使用 catalog canonical URL,对 OAuth challenge-first 使用字面值 `discovered-public-https`。`clientIdentityPolicy` 对 CIMD 使用固定 metadata client URL,对 DCR 使用 `dynamic-registration`,对 preregistered-user 使用 `user-configured-client-id:`,禁止纳入任何用户 clientId/clientSecret 值或 live discovery snapshot。`authMode!=oauth` 时 `issuerPolicy=resourcePolicy=clientIdentityPolicy=not-applicable`;Bearer token 字段约束已由 credentialSource/configSchemaSha256/configBindingsSha256 覆盖,external identity 由 credentialSource 与对应 variant 的 doctor SHA 覆盖。因此 Asana/HubSpot/BigQuery 的不同 BYO client 共享同一 profile 资格 verdict,但仍在下述 authPolicyFingerprint/credentialOwnerId 层按实际 client/账号/实例完全隔离。 + +release policy 再构成互斥 union: + +```text +PublishPolicy: + releaseDecision=publish + canaryContract=required + blockedReasonCode=forbidden + certifiedToolsSnapshotRef/Sha256=required + costOwnerTeam=required + +BlockPolicy: + releaseDecision=block + blockedReasonCode=required + canaryContract=optional + certifiedToolsSnapshotRef/Sha256=optional +``` + +`canaryContract` 存在时固定结构为 `{toolName,args,assertion,fixtureRef}`,四字段必须齐全,`args` 为 canonical JSON。`assertion` 只允许 `{jsonPath,op,expected}`,其中 `op=equals|exists|isArray|nonEmpty`,不执行任意脚本。`officialReference` 是非空数组:第三方 profile 只接受无 userinfo/query/fragment 的 HTTPS 官方文档 URL,第一方 profile 只接受仓库相对 `docs/` 或 `README.md` 路径。 + +`certifiedToolsSnapshotRef` 指向 release lock `artifacts[]` 中永久保留的 JSON;每个工具记录 `{logicalToolName,inputSchemaSha256,annotationsSha256}`,按 logicalToolName 排序。snapshot 只能由通过认证的 release fixture 实际 `tools/list` 生成,generator 不联网、只校验 snapshot SHA 和 requiredTools 子集。 + +blocked→publish 的认证循环由仓库外产品运行面的独立 release harness 打破:`scripts/certify-mcp-profile.ts` 只在受控 release job 中接受单一 profile ID。无凭据 contract-only 模式可验证 schema/doctor;需携凭据的 auth/initialize/tools-list/canary 模式只允许当前 blocker 为 `cimd-document-unavailable|host-oauth-reconnect-missing|oauth-client-config-missing|secret-config-schema-missing|provider-e2e-unverified`。tombstone,example/退役/vendor-specific/Claude-hosted denylist,以及 `provider-app-approval-required|provider-contract-missing|auth-profile-unclassified|endpoint-tls-unreachable|region-access-denied` 一律在读 credential 前 hard fail。 + +provider 资格循环固定分两步:先在零凭据/零网络的 release-private job 中完成 basis/evidence/HMAC/双签 verdict,经 `provider-integrations-approver` 审核后只把 blocker 从 `provider-app-approval-required` 改为 `provider-e2e-unverified`,releaseDecision 仍为 block、runtime config 仍为 0;之后 harness 才允许读 fixture credential 执行 E2E。禁止为了跑 probe 直接把 provider-approval blocker 跳到 publish。 + +凭据 probe 前必须先在 release-private validator 内验证互斥 `authorizationBasis=public-terms|written-approval|internal-app`。`public-terms` 要求当前公开条款明确覆盖 client/distribution/scopes/regions;`written-approval` 要求 provider/授权代理方的有效书面批准;`internal-app` 要求 Acosmi 或指定企业 tenant 管理员对 appId/tenant/distribution 的有效批准。本报告的公开 marketplace 不允许 internal-app effective publish;它只能用于另行隔离的 enterprise-private marketplace/lock,本仓 profile 继续 block。三种 basis 都必须验证 provider/app/client/distribution/scope/region 精确集合、issuedAt/expiresAt/reviewDueAt/revokedAt、法务决定与原始证据 SHA;source URL/附件/联系人/reviewer subject/private locator 全部只留在 private WORM。 + +```text +PrivateProviderEvidence{ + schemaVersion=2, + connectorProfileId, + profilePolicyFingerprint, + authorizationBasis, + providerId, + appId|null, + tenantIds[], + allowedClients[], + distributions[], + scopes[], + regions[], + coverageMode=entire-profile-domain|subset, + profileConfigDomainSha256, + coverageProofSha256, + sourceDocuments[{sourceUrl,contentSha256,retrievedAt,attachmentObjectSha256|null}], + providerApprovalSubject|null, + legalDecision=approve|block, + issuedAt, + expiresAt, + reviewDueAt, + revokedAt|null, + reviewerSubjects[], + privateAuditId, + issuer, + keyId, + signature +} +``` + +`public-terms` 要求 appId/providerApprovalSubject=null;`written-approval` 要求 providerApprovalSubject 为 provider/授权代理 subject;`internal-app` 要求 appId、tenantIds 和管理员 providerApprovalSubject 非空。所有集合去重并按 UTF-8 字典序排序,sourceDocuments 按 contentSha256 排序,签名覆盖除 `signature` 外的全部 JCS 字节;`expiresAt/reviewDueAt` 必须晚于 issuedAt,`revokedAt` 非 null 或 `legalDecision=block` 时禁止生成 approved verdict。 + +公开 marketplace 的 approved verdict 还必须 `coverageMode=entire-profile-domain`:`profileConfigDomainSha256=sha256(JCS({profilePolicyFingerprint,configSchema,configBindings,distribution=public-marketplace}))`,`coverageProofSha256` 指向 private WORM 中的机器覆盖结果。枚举字段必须证明 evidence allowed set 是 schema enum 的超集;regex/template/BYO client 等非有限值域必须有条款/书面批准明确覆盖整个公开值域/用户自备应用类别的签名 domain proof,禁止用一个 fixture 租户/app 推导整个值域。`coverageMode=subset` 或 tenantIds/appId/regions/allowedClients 只覆盖公开 schema 子集时,本仓 profile/verdict 必须 block;只能在 enterprise-private marketplace 新建一个不同 connectorProfileId、将该子集编进运行可见 configSchema 的限定 profile,重算 profilePolicyFingerprint,不得依赖 runtime 看不见的 hidden membership 放行用户值。 + +scope 覆盖也是 domain proof 的必须项:`scopePolicy=challenge-first` 时 private evidence scopes 必须是 catalog maximumScopes 的超集,`scopePolicy=fixed` 时必须是 fixedScopes 的超集;只覆盖 minimumScopes 不得生成 approved verdict。runtime 任何实际/step-up scopes 必须同时是 maximumScopes 与当前用户同意集合的子集。 + +完整 private evidence 按 RFC 8785 canonical 后计算 `evidenceCommitment=HMAC-SHA256(providerEvidenceCommitmentKey,JCS(privateEvidence))`;HMAC key 只存在 release/legal validator 的受保护 secret backend,每次发布从 private primary/DR 双取回原文并重算 commitment。禁止使用无盐 SHA 公开 provider/scope/region/distribution 低熵集合。 + +private evidence 只按 `privateAuditId` 写入 `oss://acosmi-private-release-evidence-cn-hangzhou/provider-evidence//.json` 和中国境内独立账号/异区域 DR `oss://acosmi-private-release-evidence-dr-cn-shanghai/provider-evidence//.json`;release-private audit index 为 `{privateAuditId,primaryRef,disasterRecoveryRef,sizeBytes,sha256,evidenceCommitment,commitmentKeyId,verdictSha256,validatedAt,validatorRunId}`,同样双写 WORM。该 index/ref 不进入公开 lock;公开面只能通过 HMAC commitment 与双签 verdict 证明 release validator 已验证,不能定位原文。供应商合同/批准函/联系人/reviewer subject 原文禁止写入 AWS 或中国境外 DR;其 WORM 保留截止日期固定为合同/批准到期、撤销日或最后一次生产引用日三者中最晚日期再加 7 年,只允许经 `legal` 签名 legal-hold 延长,禁止缩短。 + +release validator 只向 Git-ignored release staging/公开内容寻址 artifact 与 lock 输出: + +```text +ProviderEligibilityVerdict{ + schemaVersion=1, + connectorProfileId, + profilePolicyFingerprint, + eligibilityStatus=approved|blocked, + blockedReasonCode|null, + leaseNotBefore, + leaseNotAfter, + evidenceCommitment, + commitmentKeyId, + issuedAt, + signatures[ + {signerTeam=legal,keyId,signatureAlgorithm=Ed25519,signature}, + {signerTeam=security,keyId,signatureAlgorithm=Ed25519,signature} + ] +} +``` + +`verdictPayload` 固定为上述 verdict 排除 `signatures` 的对象,两个 signer 都对 `JCS(["mcp-provider-eligibility-v1",verdictPayload])` 签名;必须同时有 `legal` 和 `security` 两个独立 key 的有效签名。`leaseNotAfter<=min(private expiresAt,private reviewDueAt,issuedAt+30 days)`;blocked verdict 的 leaseNotBefore/leaseNotAfter 为 `not-applicable`。公开 verdict 不包含 authorizationBasis、provider/app/scope/region/distribution hash、reviewerId、privateWormRef、sourceUrl 或自由文本。release candidate 输入的 verdict file ref/SHA 只写入 lock `profileAuthorizationLeases.eligibilityVerdictRef/Sha256`,不写入 plugin profile/catalog 运行字节;因此纯 lease 续签不改 plugin/marketplace artifact。runtime host 验两个 verdict 签名、connectorProfileId/profilePolicyFingerprint/时效绑定,不重算 HMAC;release validator 负责重算 HMAC 并验该 commitment 已被 verdict 和 release lock 同时覆盖。 + +harness 只在 private basis/evidence 通过后读临时 fixture credential,禁止使用用户 settings/credential;出站防火墙只放行 profile 解析后的精确 scheme/hostname/port,template profile 只放行 private evidence 指定的 fixture tenant,3xx 改变 origin、DNS 重绑定到私网/特殊 IP 或任一额外 egress 均中止;credential 只允许 private evidence 内的 provider/app/distribution/scopes/regions。该脚本不进入插件包或 CrabCode runtime,失败/成功都不自动修改 catalog 或 releaseDecision。QA 与 provider approver 复核输出后,只能通过代码审核的后续 commit 写入 snapshot hash/canaryContract/releaseDecision。 + +lease 到期、private evidence 提前撤销或范围变更时,`provider-integrations` 在 4 小时内发起新 blocked verdict 和更高序号 lock,`provider-integrations-approver` 批准;在线 generation=2 宿主最多 60 分钟后驱逐该 profile。即使新 lock 未及发布,已签名 lease 到期后 runtime 也只 fail-close 该 profile。 + +RemoteProfile 专属字段: + +```text +kind=remote +transport=http | sse +endpointKind=fixed | template +executableTemplate.remote: + urlTemplate + headersTemplate + oauthTemplate + authDoctor +``` + +StdioProfile 专属字段: + +```text +kind=stdio +transport=stdio +executableTemplate.stdio: + command + args + envTemplate + doctor + supportedPlatforms +``` + +Tombstone 不是可绑定 profile,只包含: + +```text +connectorProfileId +logicalServerName +removedReasonCode +priorUrlTemplate +priorExecutableTemplateSha256 +removedAt +ownerTeam +approverTeam +``` + +profile 必须且只能进入 remoteProfiles 或 stdioProfiles;同一 ID 不得同时出现在 profile 与 tombstone。tombstone 永不进入 manifest binding、connector-profiles、`.mcp.json` 或 runtime config。 + +本方案 3 条 tombstone 都来自 remote profile,`priorUrlTemplate` 必填。generator 对每个 executableTemplate 计算 SHA-256,并同时比较 tombstone 的 ID、priorUrlTemplate 与 `priorExecutableTemplateSha256`;命中任一项即 hard fail,禁止换 ID 重新引入退役配置。 + +远程 endpoint 的单一真源只有 `urlTemplate`: + +- `endpointKind=fixed` 时 `urlTemplate` 禁止变量,且 `new URL(urlTemplate).href` 必须与原字符串逐字符相等;generator 由它派生只读 `derivedCanonicalEndpoint`,catalog 禁止作者填写第二份 canonicalEndpoint; +- `endpointKind=template` 时必须含 schema-declared placeholder,runtime 经安全 URL builder 得到 resolved endpoint;catalog 不保存 canonicalEndpoint; +- duplicate/profile identity 检查使用 `endpointKind + urlTemplate + authMode + clientRegistration` 的 canonical JSON hash。 + +`configBindings` 只允许: + +```text +urlHost | urlPathSegment | header | stdioEnv +oauthClientId | oauthClientSecret | externalRuntime +``` + +`oauthClientSecret` 只生成 secure-storage binding,不进入 `.mcp.json`;`header`/`stdioEnv` 的 sensitive 值只生成 user-config 占位符,不生成明文。 + +字段互斥与必填规则: + +```text +scopePolicy=challenge-first → minimumScopes/maximumScopes 必须存在,fixedScopes 必须不存在,minimumScopes 必须是 maximumScopes 子集 +scopePolicy=fixed → fixedScopes 必须存在,minimumScopes/maximumScopes 必须不存在 +scopePolicy=not-applicable → minimumScopes、maximumScopes、fixedScopes 必须都不存在 +releaseDecision=publish → executableTemplate、ownerTeam、approverTeam、costOwnerTeam、canaryContract、certifiedToolsSnapshotRef/Sha256 必须存在 +releaseDecision=publish → blockedReasonCode 必须不存在 +releaseDecision=publish → costOwnerTeam=cost-owner +releaseDecision=block → blockedReasonCode、ownerTeam、approverTeam 必须存在,canaryContract 可缺失 +authMode!=oauth → clientRegistration=not-applicable 且 scopePolicy=not-applicable +authMode=oauth → clientRegistration 只能为 cimd/dcr/preregistered-user,scopePolicy 不能为 not-applicable +authMode=oauth → callbackProfile=loopback-127.0.0.1-3118 +authMode=oauth → authDiscovery 只能为 fixed|challenge-first +authDiscovery=fixed → issuer/resource 必须是无 query/fragment 的 public HTTPS canonical URL +authDiscovery=challenge-first → kind=remote 且 authored issuer/resource 均=null,两者只能由第 4.2 节无凭据 discovery 得出 +authMode!=oauth → authDiscovery=not-applicable 且 issuer=not-applicable +authMode!=oauth → profilePolicyFingerprint 中 issuerPolicy/resourcePolicy/clientIdentityPolicy 全部=not-applicable +authMode!=oauth → callbackProfile=not-applicable +authMode!=oauth → resource=not-applicable +authMode=unsupported → releaseDecision=block +authMode=oauth/bearer → credentialSource=os-credential-backend +authMode=external → credentialSource=external-runtime +authMode=external → executableTemplate.remote.authDoctor 或 executableTemplate.stdio.doctor 必须存在 +authMode=none/unsupported → credentialSource=none +kind=stdio → runtimeDependency 不能为 none,remote 字段必须不存在 +kind=remote → runtimeDependency=none,stdio 字段必须不存在 +kind=remote → providerInteraction=external-service +runtimeDependency=container → executableTemplate.stdio.doctor 必须含 CLI/daemon/image 三项 +authMode=oauth/bearer → credentialOwnerScope=host-principal+plugin+profile+connection-instance +authMode=none/external/unsupported → credentialOwnerScope=not-applicable +sensitive config 存在 → credentialSource=os-credential-backend 或 external-runtime +providerKind=third-party 且 providerInteraction=external-service 且 catalog publish → 无论 remote/stdio,release lock profileAuthorizationLeases 必须恰有 1 条双签 verdict;只有 approved+未过期才 effective publish +providerInteraction=local-only 或 providerKind=first-party → profileAuthorizationLeases 不得含该 profile;local-only stdio 的代码许可/SBOM/依赖资格走 artifact release gate +``` + +`minimumScopes` 允许显式空数组;`maximumScopes` 与 `fixedScopes` 必须为非空、去重、UTF-8 字典序数组,challenge-first 的 minimum 差 maximum 必须为空。discovery/step-up 返回任一不在 maximumScopes 的 scope 都立即 `oauth-discovery-policy-mismatch`,不分配 generation。`ownerTeam` 与 `approverTeam` 必须是 RACI 角色表中的不同团队。 + +team ID 只允许: + +```text +plugin-platform | marketplace-approver +crabcode-mcp | crabcode-release +acosmi-backend | acosmi-ops | acosmi-release +security | legal | qa-release +data-governance +provider-integrations | provider-integrations-approver +release-signing | lock-composition | cost-owner +mediaops | support | customer-admin +``` + +机器 ID 与 RACI 显示角色唯一映射: + +| team ID | RACI 角色 | +| --- | --- | +| `plugin-platform` | CrabCode-Plugin owner / 插件发布负责人 | +| `marketplace-approver` | marketplace owner | +| `crabcode-mcp` | CrabCode MCP/worker/ToolSearch owner | +| `crabcode-release` | CrabCode release owner | +| `acosmi-backend` | Acosmi backend owner | +| `acosmi-ops` | Acosmi ops | +| `acosmi-release` | Acosmi release owner | +| `security` | 安全负责人 | +| `legal` | 法务与供应商合同负责人 | +| `data-governance` | 数据分类、保留、驻留地与跨境边界负责人 | +| `qa-release` | QA/集成/发布验收负责人 | +| `provider-integrations` | Provider integration owner | +| `provider-integrations-approver` | Acosmi provider integration 内部批准人;外部 provider 审批以 evidence 字段记录 | +| `release-signing` | release signing key custodian | +| `lock-composition` | MCP release lock composition owner | +| `cost-owner` | canary/第三方 API 成本负责人 | +| `mediaops` | mediaops 产品负责人 | +| `support` | 客服与用户沟通负责人 | +| `customer-admin` | 最终用户组织管理员 | + +枚举: + +```text +authMode: + none | bearer | oauth | external | unsupported + +authDiscovery: + not-applicable | fixed | challenge-first + +clientRegistration: + not-applicable | cimd | dcr | preregistered-user + +callbackProfile: + not-applicable | loopback-127.0.0.1-3118 + +credentialSource: + none | os-credential-backend | external-runtime + +releaseDecision: + publish | block + +scopePolicy: + not-applicable | challenge-first | fixed + +runtimeDependency: + none | bundled-sidecar | command | container | project-cli + +credentialOwnerScope: + not-applicable | host-principal+plugin+profile+connection-instance + +providerKind: + first-party | third-party + +providerInteraction: + local-only | external-service +``` + +`challenge-first` 固定优先级为 `WWW-Authenticate scope → Protected Resource Metadata scopes_supported → profile minimumScopes`;`fixed` 只请求 catalog 列出的 scopes。运行期 step-up 必须显示新增 scope 并重新取得用户同意;scope 集合变化进入 authPolicyFingerprint,禁止静默扩权。 + +同一 endpoint 可以有多个 profile。每个插件声明只能选择一个 profile。 + +正向例:GitHub 同一 URL 当前存在 PAT 与无 header 两种声明,不能用 URL 强迫它们共享一种认证方式。本批统一为 PAT profile;未认证的 crabwork 声明也改用该 profile。 + +### 5.2 生成物与凭据隔离 + +build-time catalog 生成两类本地发布物: + +```text +remote publish/block → 进入 `.crabcode-plugin/connector-profiles.json` +stdio + external-service + publish/block → 只进入 `.crabcode-plugin/connector-profiles.json` +stdio + local-only + publish → 进入 `.mcp.json` +stdio + local-only + block → 只进入 `.crabcode-plugin/connector-profiles.json` +tombstone → 两类生成物都不进入 +``` + +`.crabcode-plugin/connector-profiles.json` 是 generation=2 宿主的本地、schema-validated remote/leased-stdio profile 输入:effective publish 只能在 activation/config/auth/provider-lease gate 后物化为 runtime config/spawn,block 只供管理 UI 展示。generation=1 忽略该文件;remote 和 external-service stdio 永不进入 `.mcp.json`,因此旧宿主不会绕过 generation=2 lease gate。 + +generation=1 的真实 marketplace 安装/加载链 `pluginLoader/createPlugin.ts` 与 `pluginLoader/installSources.ts` 调用非 strict `PluginManifestSchema`,会剥离未知顶层字段并忽略 `mcpConnectorProfiles/mcpGeneratedArtifacts`;安装链不调用 `validatePlugin.ts` 的 strict schema。旧版手工 `crabcode plugin validate` 会 strict fail,但不参与 marketplace 安装。P0 包由 generation=2 validator 构建后发布;generation=1 只消费已构建包并读取 `providerInteraction=local-only` 的 stdio `.mcp.json`,所以兼容合同不矛盾。 + +profile `configSchema` 是连接器变量的单一真源。宿主管理 UI 将其与插件普通 `userConfig` 分区展示并写入同一插件 secure-config namespace;manifest 普通 `userConfig` 禁止重复声明 profile 已拥有的 key。generator 根据 profile schema 生成 `${user_config.KEY}` 引用,禁止手写第二份 schema。 + +生成合同: + +- 安装时不联网解析 connector `$ref`; +- 老版本宿主不会因目录服务不可达而失去配置; +- CI 对生成物 digest 做双向校验; +- URL/auth/config 不允许手工复制漂移; +- token 继续按 plugin instance + account/tenant + AS + client ID + resource + scope 隔离; +- 不跨插件共享 token、refresh token 或撤销状态。 + +### 5.3 已锁定 profile 处置 + +| 连接器/类别 | 声明数 | Profile/处置 | 发布门 | +| --- | ---: | --- | --- | +| Notion/Linear/Canva/Synapse | 17 | `oauth+cimd`;当前 `block:cimd-document-unavailable` | Acosmi CIMD 200、宿主 generation=2、四家分别完成真实授权/重启重连/固定只读 canary | +| OAuth DCR 连接器 | 22 | DCR-only metadata 组排除 Tencent Docs;`oauth+dcr`;当前 `block:host-oauth-reconnect-missing` | 宿主 targeted reconnect 完成;每家仍须通过真实授权与固定只读 canary,否则转 `block:provider-e2e-unverified` | +| Tencent Docs | 1 | `authMode=bearer`、`runtimeDependency=none`;保留 `tencent_docs_token` | sensitive token 进入 OS credential backend、header 注入和固定只读 canary 通过 | +| Slack | 10 | `authMode=unsupported`;`block:provider-app-approval-required` | 本方案内不解锁;Slack Marketplace 审批和 confidential broker 独立安全项目全部完成后另行立项 | +| Asana V2 | 6 | `oauth+preregistered-user`;`block:oauth-client-config-missing` | client ID/secret OS credential UI、固定 callback、真实授权、targeted reconnect、只读 canary 全通过 | +| Asana SSE | 当前 1 | target tombstone=`endpoint-retired`;standalone binding 原位改指 V2 HTTP profile | 按 Asana V2 门槛验收,旧 SSE profile ID 永不重新绑定 | +| HubSpot | 4 | `/anthropic` 生成 tombstone=`vendor-specific-endpoint`;四个 binding 改指 canonical URL=`https://mcp.hubspot.com/` 的 `oauth+preregistered-user` profile | 完成 MCP auth app、PKCE、refresh、`get_user_details` canary | +| BigQuery | 1 | `oauth+preregistered-user`;`block:oauth-client-config-missing` | 用户 OAuth client、OS credential backend、IAM test project、`list_dataset_ids` canary 全通过 | +| GitHub | 2 | `authMode=bearer`、`credentialSource=os-credential-backend`;`block:secret-config-schema-missing` | 两处统一 PAT header,sensitive 配置入 OS credential backend,固定只读 canary 通过 | +| Greptile | 1 | `authMode=bearer`、`credentialSource=os-credential-backend`;`block:secret-config-schema-missing` | API key 入 OS credential backend,固定只读 canary 通过 | +| Terraform | 1 | `authMode=bearer`、`runtimeDependency=container`;首要 `block:secret-config-schema-missing` | sensitive `TFE_TOKEN`、Docker doctor、固定镜像版本与 digest、固定只读 canary 全通过 | +| Snowflake/Databricks/Benchling | 3 | `block:config-schema-missing` | 6 个 required 字段、安全 URL builder、注入负测、真实租户 E2E 全通过 | +| `*.mcp.claude.com` | 4 | `block:provider-contract-missing` | 本方案内不解锁,不进入生产 `.mcp.json` | +| `mcp.example.com` | 当前 1 | target tombstone=`non-production-endpoint`,binding 删除 | 生产配置零命中 | +| Similarweb | 3 | `block:endpoint-tls-unreachable` | 本方案内不解锁 | +| Owkin | 1 | `block:region-access-denied` | 本方案内不解锁 | +| Open Targets | 1 | `none`;`block:provider-e2e-unverified` | 固定公开 ID 的只读 canary 成功后发布 | +| auth profile 未闭合连接器 | 25 | `authMode=unsupported`;`block:auth-profile-unclassified` | 本方案内不解禁,生产可执行数固定为 0;未来只能通过新的审计变更提交官方依据、唯一完整 profile、私有 authorization-basis 审查与公开最小 eligibility verdict、真实认证/targeted reconnect/tools-list/canary 证据和更高序号 release lock,不属于本方案未完成项 | + +PubMed 的技术调用证据保留,但其托管域属于 `mcp.claude.com`,releaseDecision 固定为 block;不能用它证明当前存在 production-approved 匿名连接器。 + +## 6. P0 实施批次 + +### 6.1 P0-0:先停止错误发布 + +责任仓:`CrabCode-Plugin` + +当前只读审计未取得下述发布/灾备基础设施已存在且验收通过的证据,因此其当前状态固定为 `release-infrastructure-unavailable`,不得假定已可用。该状态只阻断首份签名 lock 和任何 remote 重新解禁,不得阻断先沿现有发布链立即下发 P0-0E emergency containment。 + +P0-0E 只做机械、可快速复核的止血,Responsible=`plugin-platform`、Approver=`marketplace-approver`:发布包中所有 `.mcp.json` 均为空/不存在,唯一例外是 `html-video` 的单个 stdio server;所有 manifest `requiredMcpServers` 为空,唯一例外是 `html-video`;`mediaops`、12 个 LSP、远程 HTTP/SSE、wrapper/channel 都无可执行 MCP;marketplace 禁止“开箱即用/已连接/无需配置”。P0-0E 不等待 428 个 capability 分类、connector catalog、provider evidence 或新 lock;它不声称 remote-dependent prompt capability 已完成精确分类,但因 remote executable 为 0,这些 prompt 也无法执行远程 MCP 请求。 + +当前 43 个含 `.mcp.json` 的插件全部在 marketplace。P0-0E 对这 43 个插件逐一执行 `nextPatch(v)=major.minor.(patch+1)`,`v` 必须是修改前 manifest/marketplace/package(存在时)的相同版本,不相同先 hard fail;新版本同时写入 manifest、marketplace、package、serverInfo/dist 及现有 plugin cache key,禁止在原 SemVer 下覆盖字节。`html-video` 修改前 manifest/package/marketplace=`0.1.2`、serverInfo/dist=`0.1.0`;P0-0E 固定发布 `0.1.3`并使四处逐字符一致。 + +P0-0E 当次验收固定为:`remote HTTP/SSE runtime=0`、`stdio server=1(html-video)`、`requiredMcpServers 差集=0`、43 个旧版本→新 patch 版本在 generation=1/2 clean update fixture 均重新取包且 runtime remote=0、`html-video serverInfo/package/manifest/marketplace=0.1.3`、全部已知坏 URL 可执行命中数=0。验收后立即切换 emergency marketplace 并记录原始 size/SHA/source commit;内容寻址 marketplace 对象固定 `Cache-Control: public, max-age=31536000, immutable`,`https://updates.acosmi.com/crabcode/marketplace/current.json` 的 origin/CDN 固定 `Cache-Control: no-store`,generation=1/2 updater 取 pointer 发送 `Cache-Control: no-cache`。切换后必须立即无认证 GET 取得新 pointer 字节+`no-store`,两代 clean fixture 显式 refresh 必须取得新 marketplace;任一旧字节/错 header 则 P0-0E 未完成。 + +> **独立处理(ACOSMI-OPS)**:下述 P0-0A 是 Acosmi 运维/发布基础设施子轨,不是 Acosmi 业务源码改动,也不是插件仓改动。执行证据与回滚责任按《[Acosmi CIMD 与发布基础设施独立整改方案](./2026-08-22-Acosmi-CIMD与发布基础设施独立整改方案.md)》单独归档;全局 lock schema 仍以本文第 8 节为准。 + +P0-0E 发布后,P0-0A 基础设施 bootstrap 与 P0-0B 硬化生成可并行;P0-0A Responsible=`acosmi-ops`、Approver=`acosmi-release`、Consulted=`security|release-signing|cost-owner|qa-release`: + +1. 公开 primary 固定为 `Alibaba Cloud OSS/accountAlias=acosmi-release-cn/region=cn-hangzhou/oss://acosmi-mcp-safe-primary-cn-hangzhou/crabcode/mcp-safe/`,`https://updates.acosmi.com/crabcode/mcp-safe/` 必须逐 key 映射到 `oss://acosmi-mcp-safe-primary-cn-hangzhou/crabcode/mcp-safe/`;primary 开启 versioning+WORM,禁止删除/改写旧 version/bypass retention。在独立 AWS accountAlias=`acosmi-release-dr`/us-west-2 创建 versioning + Object Lock 的 `s3://acosmi-mcp-safe-dr-us-west-2/crabcode/`,runtime 第二 locator 直接使用不受 `acosmi.com` 注册商/权威 DNS zone 影响的 AWS 对象域名 `https://acosmi-mcp-safe-dr-us-west-2.s3.us-west-2.amazonaws.com/crabcode/`;DR bucket policy 只允许 `crabcode/mcp-safe/**` 与 `crabcode/host/**` 两个前缀下精确 object GET/HEAD,禁止 ListBucket/Put/Delete,写入只走私有 release role;两前缀的 canary object GET/HEAD 必须通过,其他 sibling prefix 与 bucket list 必须失败; +2. 建立并验收 Acosmi backend 完整部署包 primary=`Alibaba Cloud OSS/accountAlias=acosmi-release-cn/region=cn-hangzhou/oss://acosmi-private-releases-cn-hangzhou/`,DR=`AWS S3/accountAlias=acosmi-release-dr/region=us-west-2/s3://acosmi-private-releases-dr-us-west-2/`;另创建私有 release evidence primary=`Alibaba Cloud OSS/accountAlias=acosmi-release-cn/region=cn-hangzhou/oss://acosmi-private-release-evidence-cn-hangzhou/`,DR=`Alibaba Cloud OSS/accountAlias=acosmi-legal-dr-cn/region=cn-shanghai/oss://acosmi-private-release-evidence-dr-cn-shanghai/`,provider/component approval evidence 只能进后两处;`accountAlias` 是审计稳定别名,实际 account ID 只以 salted hash 写入 bootstrap 证据。backend 制品必须是 `server` + 七个 Rust `.so` + payload manifest 的不可变 bundle,禁止只保留 Go binary;建库前 `legal` 和 `data-governance` 必须分别签署数据分类/保留/境内备份 policy 的 digest-specific attestation,缺一即 `release-infrastructure-unavailable`; +3. 为公开 primary/DR、backend bundle primary/DR、private evidence 与回滚审计 bucket 开启 versioning + Object Lock Compliance/WORM。backend bundle、lock/envelope、不含个人/合同原文的 component approval attestation 永久保留;provider 合同/批准函/联系人/reviewer 原文只在中国境内 primary/DR 保留至到期、撤销或最后生产引用三者中最晚日期 +7 年,只允许 legal hold 延长;回滚审计记录保留 7 年。业务写入身份可以 Put 新 key,对固定 `head.json` 的 Put 必须产生新 object version,但没有删除、改写旧 version 或 bypass retention 权限; +4. 复用企业私仓 `workflow_dispatch` 与 OIDC/IdP,不新建常驻审批服务;固定建立 `backend-release-fixture-owner|backend-release-fixture-approver|backend-release-owner|backend-release-approver` 四个 protected environment,owner/approver 两个不同 IdP subject 必须对同一 backend bundle digest subject 分别签名,把 issuer、attestation public-key allowlist 和 environment ID 钉住在 release validator;单纯批准 workflow run 而不绑定 bundle/manifest digest 无效。backend stores、四 environment、OIDC role 与 non-production fixture 通过共同构成 P0-1 生产部署的最小 `ACOSMI-REL prerequisite`; +5. 创建 `thresholdPolicy=2-of-3` 的三把 Ed25519 release key:A 由 `release-signing` 的 release HSM/secret backend 保管,B 由独立账号的 `security` HSM/secret backend 保管,C 保存在 `security` + `acosmi-release` 双人实体保管的离线硬件中;日常发布用 A+B,A/B 任一不可用时可由剩余在线 key+C 完成。另创建不参与日常签名的 offline release-root key,其公钥随 generation=2 宿主钉住,只用于两把当前 key 经 `security`/`acosmi-release` 两份 IdP+WORM 证据确认已永久不可恢复或已妥协时授权新 key set;短时 HSM/网络故障禁止启用 root,只能用剩余 key+C、继续使用已验签 lock 或等待恢复。完成 2 签正向、1 签不足、重复 keyId、错 key、改字节、短时 outage 禁用 root 和 offline-root recovery 负/正测;offline-root recovery 演练只使用专用 test key set/test locator,禁止销毁或替换生产 key 来制造演练条件; +6. 在 release/legal validator 私有 secret backend 创建 `providerEvidenceCommitmentKey`,将加密备份分别存入 `legal`/`security` 双人恢复介质;在 `legal` 与 `security` 两个独立 secret backend 分别创建 eligibility-verdict Ed25519 key。provider raw evidence 取回、HMAC 重算和 eligibility validator 固定在中国境内 VPC 的自托管 runner label=`self-hosted,linux,x64,cn-hangzhou,release-legal-validator` 执行,raw bytes 禁止进入 GitHub-hosted runner/artifact/cache/log,境外只接收最小双签 verdict+commitment;验收必须包含 egress deny 与 log/artifact 泄露扫描证据。完成 HMAC 主库故障后双人恢复/重算一致、两签必须、单签/错 connectorProfileId/错 profilePolicyFingerprint/篡改 lease 失败,并对公开 verdict 执行 provider/app/scope/region/distribution/reviewer/private URI/自由文本泄露扫描; +7. 生成并永久保留 `release-infrastructure-bootstrap.json`,记录脱敏 account ID hash、region、公开 primary 底层 locator 及 HTTPS→object mapping SHA、公开 primary/DR/backend bundle primary/backend bundle DR/private evidence primary/private evidence DR 各自的 bucket policy SHA、Object Lock mode/retention、OIDC issuer、四个 backend protected environment ID、CN 自托管 validator runner-pool digest/egress-policy SHA、retention/residency policy SHA 及 `legal`/`data-governance` attestation refs、releaseKeySetId/三个 keyId/offline-root keyId/thresholdPolicy、provider verdict 两个 public keyId、commitmentKeyId 和验收时间。 + +P0-0A 不使用尚未存在的正式 current head 做自证。它先用 CSPRNG 生成 128-bit random、32 位小写 hex `canaryId` 和独立 32-byte random `payload.bin`,只在 `bootstrap-canary//` 下写入独立 `BootstrapCanaryEnvelope`。三类 payload locator 固定为 `https://updates.acosmi.com/crabcode/mcp-safe/bootstrap-canary//payload.bin`、`https://acosmi-mcp-safe-dr-us-west-2.s3.us-west-2.amazonaws.com/crabcode/mcp-safe/bootstrap-canary//payload.bin` 和 `s3://acosmi-mcp-safe-dr-us-west-2/crabcode/mcp-safe/bootstrap-canary//payload.bin`: + +```text +schemaVersion=1 +environment=test +canaryId +issuedAt +expiresAt=issuedAt+15 minutes +payloadArtifactRef +payloadRuntimeMirrorRef +payloadDisasterRecoveryRef +payloadSizeBytes=32 +payloadSha256 +signedAt +releaseKeySetId +previousReleaseKeySetId=null +keySetTransitionRef=null +thresholdPolicy=2-of-3 +signatures[{keyId,signatureAlgorithm=Ed25519,signature}] +``` + +至少 2 个不同 keyId 对 `JCS(["mcp-bootstrap-canary-v1",{schemaVersion,environment,canaryId,issuedAt,expiresAt,payloadArtifactRef,payloadRuntimeMirrorRef,payloadDisasterRecoveryRef,payloadSizeBytes,payloadSha256,signedAt,releaseKeySetId,previousReleaseKeySetId,keySetTransitionRef,thresholdPolicy}])` 签名,使用同一 releaseKeySet 但独立 domain separator。envelope 原始字节固定写入 `https://updates.acosmi.com/crabcode/mcp-safe/bootstrap-canary//head.json`、`https://acosmi-mcp-safe-dr-us-west-2.s3.us-west-2.amazonaws.com/crabcode/mcp-safe/bootstrap-canary//head.json` 和 `s3://acosmi-mcp-safe-dr-us-west-2/crabcode/mcp-safe/bootstrap-canary//head.json`;这三个 bootstrap mutable head 的 origin/CDN/object metadata 都必须返回 `Cache-Control: no-store`,取回请求发送 `Cache-Control: no-cache`。production validator 只接受 `mcp-release-lock schemaVersion=2,environment=production,lockSequence>=1`,在验签前就拒绝 BootstrapCanaryEnvelope。canary 字节不更新任何正式 `head.json`、不进入 production lock chain/本地高水位。 + +P0-0A 验收必须在公开 primary/DR 各写入同一 canary payload/envelope 并读回同一 size/SHA,验证两处 cloud/account/region 不同,从无对象存储凭据 clean fixture 分别通过 `https://updates.acosmi.com/crabcode/mcp-safe/bootstrap-canary//head.json` 和 `https://acosmi-mcp-safe-dr-us-west-2.s3.us-west-2.amazonaws.com/crabcode/mcp-safe/bootstrap-canary//head.json` 取回同一 BootstrapCanaryEnvelope 并验签/验 payload,对 canary head 连续 Put v1/v2 后验证产生两个 version ID 且 v1 仍可按 version ID 取回,验证 delete/改写旧 version/bypass retention 全部被拒绝,并对 `crabcode/mcp-safe/**`、`crabcode/host/**` 分别完成 canary exact GET/HEAD 正测及 sibling prefix/ListBucket 拒绝负测。所有故障演练只操作 `environment=test` canary/test identity/test secret backend:DNS 故障只在 clean fixture 本地 resolver deny `acosmi.com`,primary 凭据故障只撤掉 canary job identity 或在该 job deny primary egress,HMAC/offline-root recovery 只使用 test key copy/test key set,禁止修改生产 DNS、撤销生产 release identity、破坏生产 secret/key 或对非 canary object 做 delete/retention 负测。该 clean fixture 必须在本地 resolver deny 下通过 AWS 直接域名取回/验签,在 canary primary identity/egress 断开后从 DR 完成取回,并用两个不同 IdP subject 产生可验签的 owner/approver attestation。同一 canary payload 还必须使用 release 私有身份写入 `oss://acosmi-private-releases-cn-hangzhou/bootstrap-canary//payload.bin` 和 `s3://acosmi-private-releases-dr-us-west-2/bootstrap-canary//payload.bin`,再从两处独立读回并验证 size/SHA 一致;该对象只是 `environment=test` 的 store canary,禁止作为 backend artifactRole。任一项失败时首份 production lock 不生成、remote profile 不解禁;已发布 emergency safe marketplace 保持生效,不回到旧远程声明。canary 保留作证据,不执行例外删除。P0-0A 和 P0-0B 都通过后,才用 P0-0B 硬化 safe bytes 生成 `environment=production,lockSequence=1` 的 genesis 并首次更新正式 heads。 + +P0-0B 固定改动: + +P0-0B 对安全快照的 78 个 package artifact 全部再执行一次 `nextPatch`:每个 package 的基数 `v=maxSemVer(P0-0E version 如适用,manifest,marketplace 如存在,package 如存在)`,B 版本固定为 `major.minor.(patch+1)`。这会机械修复当前 `cn-legal-study` manifest=`0.2.1`/marketplace=`0.3.0` 不一致,B 使用 `0.3.1`。76 个 published package 的 manifest/marketplace/package/serverInfo/dist/cache key 按适用字段对齐;2 个 local-only 包 marketplace 值固定 `not-applicable`。P0-0B 禁止复用 P0-0E 或修改前 SemVer;`html-video` 因 E=`0.1.3`,B 固定=`0.1.4`。 + +1. 删除 `mcp.example.com` 可执行声明; +2. 删除 standalone Asana SSE,改为 V2 profile; +3. HubSpot 四处逐字符改为 `https://mcp.hubspot.com/`; +4. 为 example、Asana SSE、HubSpot `/anthropic` 生成 3 条 unbound tombstone; +5. Slack 在审批前不产生可激活配置; +6. `*.mcp.claude.com` 不产生生产可激活配置; +7. Similarweb 使用 `endpoint-tls-unreachable`,Owkin 使用 `region-access-denied`,本方案内均不解锁; +8. 3 个缺 schema 的租户模板保持 blocked; +9. 12 个 LSP 删除 `.mcp.json` 并从 MCP 分类移除; +10. 未有 profile pass 证据的远程声明只进入本地 `.crabcode-plugin/connector-profiles.json`,不进入 `.mcp.json`; +11. `mediaops` 在 local-editorial 产品化前使用 `principal-config-missing`,不进入生产 `.mcp.json`,并从 manifest `requiredMcpServers` 移除; +12. `requiredMcpServers` 必须是生成后 `.mcp.json` stdio server key 的子集; +13. `html-video` serverInfo 由 package version 生成,manifest/package/marketplace/dist 全部对齐 P0-0B `0.1.4`; +14. 完成第 6.6 节 431 条非 vendored Skill/agent/command inventory;428 个 runtime capability 中任一未分类项都不进入 safe baseline,remote-dependent callable capability 固定为 0;验收后上传 P0-0B 内容寻址包/marketplace 字节,固定将当前 pointer 从 P0-0E 切到同样 remote=0 的 P0-0B,但仍不生成任何 effective remote publish; +15. P0-0A/P0-0B 都通过后,从 P0-0B 已发布的内容寻址端重新取回硬化 safe bytes 并验证 size/SHA,上传 primary/DR,再生成第 8.1 节序号 1 的 genesis `mcp-release-lock.json`;禁止为了生成 lock 重构安全基线字节; +16. marketplace 文案不得使用“开箱即用”“已连接”“无需配置”。 + +验收: + +```text +生产 example URL 命中 = 0 +生产 Asana /sse 命中 = 0 +生产 HubSpot /anthropic 命中 = 0 +生产 raw LSP .mcp.json = 0 +未验证 profile 可激活数 = 0 +plugin-to-profile bindings = 117 +bound catalog profiles = 63(48 remote + 15 stdio) +unbound tombstones = 3 +binding HTTP / SSE / stdio = 102 / 0 / 15 +唯一远程 URL = 48(45 fixed + 3 template) +P0-0E/P0-0B 生产远程可执行声明 = 0 / 0 +P0-0E/P0-0B 第一方 sidecar 声明 = 1 / 1(html-video) +html-video P0-0E/P0-0B 四处版本 = 0.1.3 / 0.1.4 +P0-0B 78 package 版本复用数 = 0 +Skill raw/governed/runtime/support/vendored-ignored = 352 / 350 / 350 / 0 / 2 +agent raw/governed/runtime/support/vendored-ignored = 53 / 46 / 43 / 3 / 7 +command raw/governed/runtime/support/vendored-ignored = 35 / 35 / 35 / 0 / 0 +runtime capability 总数/未分类 = 428 / 0 +P0-0E 发布当次 remote runtime/executable = 0 / 0(不宣称 prompt capability 已分类) +P0-0E/P0-0B external-service stdio runtime = 0 / 0 +P0-0B 硬化后 remote-dependent callable capability = 0 +genesis 重取 safe bytes SHA = P0-0B 发布记录 SHA +safe baseline artifact size/hash/locator = lock 逐项一致 +release lock detached Ed25519 2-of-3 envelope = 门限验签通过 +``` + +回滚:只允许恢复已通过本修订版 release gate 的 profile;不得整体回滚到旧 marketplace。 + +### 6.2 P0-1:Acosmi CIMD 与 metadata 纠正(ACOSMI-SRC 独立工作流) + +责任仓:`Acosmi` + +> **实施边界**:本节定义跨仓接口合同;Acosmi 源码、测试、制品、部署和回滚必须作为 `ACOSMI-MCP-P0-2026-08-22-v1` 独立任务执行,实施步骤以《[Acosmi CIMD 与发布基础设施独立整改方案](./2026-08-22-Acosmi-CIMD与发布基础设施独立整改方案.md)》为准。本任务不同时修改 `CrabCode-Plugin` 或 `CrabCode`。 + +新增公共路由: + +```text +GET /oauth/crabcode-client-metadata +``` + +固定响应: + +```json +{ + "client_id": "https://acosmi.com/oauth/crabcode-client-metadata", + "client_name": "CrabCode", + "redirect_uris": [ + "http://127.0.0.1:3118/callback" + ], + "grant_types": [ + "authorization_code", + "refresh_token" + ], + "response_types": [ + "code" + ], + "token_endpoint_auth_method": "none" +} +``` + +响应合同: + +```text +status = 200 +redirect = 禁止 +content-type = application/json; charset=utf-8 +cache = public, max-age=300, must-revalidate +body ≤ 5120 bytes +client_id = 与请求 canonical URL 逐字符一致 +secret = 零字段 +``` + +同时删除两处 `client_id_metadata_document_supported` 广告。 + +落点固定为 Go handler;不增加 Nginx exact location。固定文件: + +```text +nexus-v4/backend/internal/handler/crabcode_client_metadata.go +``` + +路由注册到 `registerOAuthASRoutes` 同层公共路由。 + +验收: + +1. handler 单测逐字段比较 JSON; +2. 单测断言 Content-Type、Cache-Control、无 redirect、≤5KiB; +3. metadata 测试断言普通/desktop 两处 CIMD 字段均不存在; +4. 本机 Host 探测 200; +5. 公网 `curl --max-redirs 0` 200; +6. 中国大陆服务器与洛杉矶审计机结果一致; +7. 线上后端 `--version` 与发布 commit 一致。 +8. 在 generation=2 宿主生产发布前,执行一次 B→A 完整 bundle 生产回滚演练,验证 A 的两份 metadata 字段缺席; +9. 演练后从已验收 primary 重取同一 B bundle 再部署,重跑第 4–7 项并确认最终线上角色为 B=`cimd-enabled`; +10. 发布自动化 Docker 内 CGO 测试、A/B 双写/重取、B→A 完整 bundle trap 的 non-production fixture 全部通过。 + +本批只执行发布时双地点验收,不创建常驻探针:初次 B 上线阶段,Acosmi CN 生产服务器与洛杉矶审计机各执行 1 组 CIMD+普通/desktop AS metadata 验收;计划内 B→A→B 演练后两地必须再各执行 1 组完整验收。持续监控不属于 P0 完成条件,也不写成当前已有能力。 + +回滚固定使用两段安全制品:先产生/发布 A(`metadata-safe`,只删除两处虚假 CIMD 广告),再产生/发布 B(`cimd-enabled`,包含 A 且新增 CIMD 路由)。A/B 都必须是 `server`、七个 Rust `.so` 和 payload manifest 组成的完整部署 bundle,不允许单独换 binary。B 的 digest-specific approval 必须同时绑定 `safeRollbackCommit`、`safeRollbackBundleSha256`、`safeRollbackManifestSha256`,并与 A-BIN-01/A-LIVE-01 的唯一 A artifact record 一致;首份 remote-capable lock 的 `previousApproved.backendArtifactRole` 和本地预置目录必须指向该同一 A bundle SHA。生产使用 `/opt/acosmi/releases//` 只读版本目录与 `/opt/acosmi/nexus-backend/current` 原子 symlink 切换;切 B 前必须预置/复验该 A 本地缓存,B 故障优先原子切回 A,禁止逐文件覆盖混用 binary/library。A 在 `A-LIVE-01` 验收前切换失败,允许恢复审计基线旧 bundle,但 P0-1 保持 blocked、P0-0E remote=0;`A-LIVE-01` 通过后永久禁止再恢复仍广告 `client_id_metadata_document_supported=true` 的制品。B 故障时只能回滚至已验收 A。回滚期间宿主 profile 使用 `cimd-document-unavailable` 继续 fail-closed,不切换 DCR。 + +### 6.3 P0-2:CrabCode auth policy v2 + +责任仓:`CrabCode` + +固定改动: + +1. `MCP_CLIENT_METADATA_URL` 只对 `clientRegistration=cimd` 暴露; +2. CIMD/DCR/预注册 profile 全部使用 `127.0.0.1:3118/callback`; +3. DCR client information 同步持久化固定 `registeredRedirectUri`,重授权逐字符复用; +4. DCR client metadata 固定发送 `application_type=native`; +5. generation=2 拒绝非 3118 的 `MCP_OAUTH_CALLBACK_PORT`/profile override,返回 `oauth-callback-policy-mismatch`; +6. 固定端口 OAuth 先按 `[owner,profile,instance,authPolicyFingerprint,scopeFingerprint]` request intent 单飞;同 intent follower 不分配 generation,只有 leader 在 per-index 跨进程互斥/revision CAS 下分配 newGeneration 并形成 flow identity;不同 intent 返回 busy; +7. production generation=2 不读取 `MCP_OAUTH_CLIENT_METADATA_URL` 环境覆盖;测试通过依赖注入使用 staging fixture; +8. 增加 `authPolicyGeneration=2` 和 fingerprint; +9. 禁止按 HTTP/SSE 推断 OAuth; +10. worker 输出 canonical nextAction; +11. SettingsPage 只消费 nextAction; +12. CapabilityConsole 隐藏写面删除 OAuth CTA; +13. OAuth 新凭据按第 4.7 节先持久化 `generationHighWatermark`并使旧 current 进入 legacy,再使用内存 pending slot(TTL=5 分钟);成功后原子切换 active current,再撤销/删除 legacy; +14. OAuth 成功后 exact-key eviction + targeted reconnect; +15. reconnect 成功必须重新枚举 tools/resources/prompts; +16. OAuth URL/completed/startup notification 携带 flowIdentityHash,renderer 只投影到匹配 identity;token exchange 前和 index swap 前都重算 active policy/pending generation,不匹配返回 `oauth-flow-stale` 且零 success 广播; +17. 失败状态携带稳定 reason code,不只返回错误文本; +18. 管理 UI 读取插件内 `.crabcode-plugin/connector-profiles.json`,releaseDecision 不是 publish 时禁止构造 executable config; +19. 读取任何生成物前按 manifest `mcpGeneratedArtifacts` 复算 digest;不一致返回 `profile-integrity-failed`,零网络/零 spawn; +20. generation=2 遇到插件旧 `.mcp.json` 中的 HTTP/SSE 条目时不连接,返回 `legacy-remote-config` + `nextAction=updatePlugin`; +21. refresh 完整使用第 4.7 节独立 singleflight/generation/revision-CAS 流程;response 有新 refresh token 时写新值,未返回时复制旧值,禁止覆盖为空; +22. 交付第 4.2 节 per-user MCP control service、三平台启动器与经 peer UID/SID/协议重放防护的 IPC;GUI/TUI/CLI 禁止绕过 service 直读写 credential index; +23. 实现第 8.1 节签名 release head 两个独立公开 HTTPS 源取回、lock chain/本地高水位、每 profile eligibility lease 时效门禁、60 分钟最佳努力刷新与 rollback lock 的 exact remote eviction。 + +DCR 注册结果写入 `registrationEntryKey(authPolicyFingerprint)`,保存 client ID、服务端返回的 client secret、issuer、固定 registeredRedirectUri 和 policy fingerprint,不保存 token。写入读回成功后原子更新稳定 index 的 `currentRegistrationEntryKey`;相同 fingerprint 的后续授权先由 index 定位并复用,用户拒绝/超时不得再次注册。issuer/fingerprint 变化后创建新 registration entry,旧 entry 只在新授权成功后删除。 + +不实施: + +- 单次登录 CIMD↔DCR fallback; +- GUI 收广播后全局 reload; +- 自动打开内嵌 WebView; +- client secret 写 `.mcp.json`、settings JSON、日志或命令行; +- 误点 OAuth 时先删除现有有效 token。 + +验收测试: + +```text +anonymous HTTP → 无 OAuth CTA +Bearer HTTP → 配置 CTA,无 OAuth CTA +OAuth CIMD → 固定 callback,成功重连 +OAuth DCR → 固定 callback,持久 client 重授权不漂移 +OAuth DCR registration → application_type=native +OAuth DCR 拒绝后重试 → registration 请求累计仍为 1 +challenge-first discovery 成功 → 先确定 issuer/resource/scopes,再分配 generation +discovery 缺失/越 scope/私网 issuer → oauth-discovery-policy-mismatch,generation 不变 +step-up scope 超出 maximumScopes → oauth-discovery-policy-mismatch,零浏览器/零 token request +generation=2 callback override≠3118 → oauth-callback-policy-mismatch +OAuth preregistered-user → client secret 只进 OS credential backend +refresh 未返回新 refresh token → 旧 refresh token 保留 +两进程并发 refresh → 1 次 token request、1 个 newGeneration +refresh 乱序/迟到响应 → 不覆盖已切换 current +refresh 网络失败/崩溃 → 旧 active 保留、高水位不回退 +refresh invalid_grant → 旧 current=legacy、requires-login +external/ADC/CLI → nextAction=externalLogin,无 OAuth CTA +authState=unknown → 诊断 CTA,无 OAuth CTA +legacy remote .mcp → nextAction=updatePlugin,零网络请求 +policy fingerprint 变化 → 旧凭据不复用 +OAuth 中途 disable/remove → 零 reconnect +多窗口同 identity → 1 次 flow、1 次 reconnect +多窗口不同 identity → oauth-callback-busy,零结果串投 +两窗口同 requestIntentKey → 只有 leader 分配 1 个 newGeneration +两独立宿主进程并发 credential CRUD → generation 不重复、revision 不丢失、pending 不覆盖 +leader 在高水位写入后崩溃 → 接管进程保留高水位并以下一 generation 继续 +同 scope 中更换 client/policy → 新请求不订阅旧 flow +callback 前 policy/generation 变化 → oauth-flow-stale,零 swap/零 success +``` + +### 6.4 P0-3:Provider 与 secret 配置 + +责任仓:`CrabCode` + `CrabCode-Plugin` + +固定改动: + +1. 新增 plugin OAuth client configuration wire method; +2. client ID 可落非敏感配置; +3. client secret 只通过宿主 OS credential backend 落盘; +4. GUI/TUI 都能录入、更新、清除 OAuth client secret 与 Bearer/PAT;任一 sensitive credential 操作都先按第 4.7 节分配并持久化 `newGeneration=generationHighWatermark+1`; +5. 新增/更新 OAuth secret 在高水位持久化、旧 current 进入 legacy 后才进入内存 pending slot;用新 generation 完成 OAuth 后原子切换 active current,再撤销/删除旧 generation;Bearer/PAT 写入读回成功后原子切换;失败时高水位不回退、旧 current 保持 legacy 且不发送; +6. 清除任一 sensitive credential 时先分配新 generation,再原子写入 `currentState=deleted`的删除代际(与 connector tombstone 无关);本地 pointer 清空不以 provider revoke 成功为前提,随后最佳努力撤销并删除该 profile 的 token/client/discovery; +7. GitHub、Greptile、Terraform sensitive 字段进入正式配置入口; +8. `${VAR}`、`${user_config.KEY}` 与 manifest 做双向 hard gate; +9. 无条件引用的字段必须 `required:true`; +10. optional 字段缺失不得进入 substitution error; +11. provider profile 固定 callback 和官方配置指引进入 UI; +12. Notion、Linear、Canva、Synapse 共 17 条声明固定为 `oauth+cimd`; +13. 第 2.2 节列出的 DCR-advertised 声明按第 5.3 节目标 profile 生成; +14. 第 2.2 节列出的 25 条未分类声明保持 `auth-profile-unclassified`,本批不猜测认证方式; +15. 103 条远程声明的 authMode 空值数必须为 0,blocked 项也要有明确 profile 或明确 `unsupported`。 + +系统安全存储不可用时 reason=`secure-storage-unavailable`;禁止回退为 settings JSON、明文文件或进程环境长期保存 confidential client secret。 + +当前 `mcpbHandler.ts::saveMcpServerUserConfig` 只有 macOS Keychain,Windows/Linux 会回退 0600 `.credentials.json`;该回退不满足 generation=2 合同。P0-3 必须交付: + +```text +macOS → Keychain Services +Windows → Windows Credential Manager +Linux → Secret Service(org.freedesktop.secrets/libsecret) +``` + +三平台统一 credential CRUD 接口;backend 缺失、锁定或权限拒绝时返回 `secure-storage-unavailable`。generation=2 OAuth client secret、DCR client secret、access token、refresh token 不读取也不写 `.credentials.json`。三平台分别执行 create/read/update/delete/locked-backend 测试,并断言用户目录没有新增 credential 明文文件。 + +Asana/HubSpot/BigQuery 验收使用用户拥有的测试应用/项目;测试 secret 不进仓库、不进文档、不进测试快照。 + +计数验收: + +```text +CIMD profile 声明 = 17 +DCR-only metadata 声明 = 23 +目标 oauth+dcr bindings = 22 +Tencent Docs bearer binding = 1 +auth-profile-unclassified = 25,且可执行数为 0 +Asana /sse = 0 +HubSpot /anthropic = 0 +GitHub/Greptile/Terraform + secret schema 差集 = 0 +远程 profile authMode 空值 = 0 +``` + +### 6.5 P0-4:ToolSearch 逻辑别名 + +责任仓:`CrabCode` + +当前 wire 映射示例: + +```text +mediaops.originality.scan +→ mcp__p_f8b661bf8bd5aef7be4ecd44__h_7772461409afc880ef2654b7 +``` + +固定实现:建立 ToolSearch 私有 search-only alias index,不写 `Tool.aliases`。 + +索引字段: + +```text +canonical wire name +logical toolName +logical serverName +serverName.toolName +pluginId/serverName.toolName +pluginName 搜索关键词 +searchHint 搜索关键词 +``` + +规则: + +1. 精确稳定别名为 `pluginId/serverName.toolName`; +2. `serverName.toolName` 只在当前 active tool 集合唯一时可精确选择; +3. 同名多候选返回排序后的 canonical 候选并标记 ambiguous; +4. 禁止 first-wins; +5. displayName/searchHint 只参与排名,不参与精确执行; +6. alias 命中后只返回 canonical wire name; +7. 权限、审计、执行、来源隔离继续使用 wire name; +8. NFC Unicode 规范化后比较,精确匹配区分大小写; +9. 单 alias 输入上限 512 字符;超限不入索引并记录脱敏 warning; +10. builtin/插件别名碰撞不改变执行身份。 + +固定回归: + +```text +select:mediaops.originality.scan +select:/mediaops.originality.scan +重复 Slack 别名 → ambiguous +builtin 名碰撞 → canonical 权限身份不变 +超长/Unicode 工具名 → 有界且不崩溃 +``` + +### 6.6 P0-5:Skill 与 connector 能力联动 + +责任仓:`CrabCode` + `CrabCode-Plugin` + +本轮文件系统快照: + +```text +SKILL.md 磁盘原始数 = 352 +排除 node_modules vendored Skill = 2 +受治理/runtime Skill = 350 + manifest.skills 显式发现 = 332 + 无 manifest.skills 时默认 skills/ 发现 = 18 +agent Markdown 磁盘原始数 = 53 +排除 node_modules vendored agent = 7 +受治理 runtime/support agent = 43 / 3 + manifest.agents 显式发现 = 5 + 无 manifest.agents 时默认 agents/ 发现 = 38 +command Markdown 受治理/runtime = 35 / 35 +marketplace skills/agents/commands override = 0 +受治理 Markdown 合计 = 431(428 runtime + 3 support) +runtime prompt capabilities 合计 = 428(350+43+35) +canonical path / capability ID 重复 = 0 / 0 +manifest 引用缺失 = 0 +runtime connectorPolicy / connectorDependencies = 0 / 0 +``` + +P0-5 固定维护 `src/catalog/skillConnectorInventory.json` 与 `src/catalog/promptCapabilityConnectorInventory.json`,并生成字节一致的审计镜像。Skill inventory 逐一记录 350 个受治理 Skill;prompt inventory 逐一记录 46 个受治理 agent(43 runtime + 3 support)与 35 个 runtime command。九个 canonical realpath 位于 `node_modules` 的 vendored 文件(2 Skill + 7 agent)只进入 raw census 的 `vendored-ignored` 计数,不进入 capability inventory;manifest/marketplace 若显式引用此类路径则构建 hard fail。 + +每条 inventory 字段固定为 canonical path、source SHA-256、discoveryClass=`runtime|support`、discoverySource=`manifest|default-directory|support-reference`、manifest/marketplace ref 或 null、source-qualified pluginId、capabilityId、capabilityKind、connectorPolicy、connectorDependencies、supportOwnerCapabilityIds、sourceClosureSha256、effectiveConnectorDependencies、ownerTeam、approverTeam、approvedAt。discoveryClass/source 必须复用宿主 `createPlugin`/Skill/agent/command/marketplace loader 的真实默认路径、manifest 显式路径、递归和 canonical-realpath 去重规则,不能只按目录深度推断。release candidate 中新增/删除/移动文件或修改 manifest/marketplace 时,计数和 ID 随 commit 机械重算;missing path、canonical duplicate、capability ID duplicate 或任何 runtime capability 未分类都返回 `skill-dependency-unclassified` 且不发布。 + +runtime Skill/agent/command frontmatter 固定新增: + +```yaml +connectorPolicy: required +connectorDependencies: + - profileId: provider.profile-id + connectionPolicy: single-or-user-selected + requiredTools: + - logical-server.logical-tool +supportDependencies: + - path: skills/example/references/helper.md +``` + +`supportDependencies` 可省略;存在时只允许当前 plugin root 内的相对文件路径,canonical realpath 不得越界或进入 `node_modules`。任何会被该 capability 读入模型 prompt、用于 spawn 子 agent/command 或继续解析其他 prompt 文件的非 runtime 文件都必须显式列入;支持传递引用,禁止环。每个 support Markdown 自身也必须声明 `connectorPolicy` 与适用的 `connectorDependencies`,但不作为独立 callable capability。 + +connector-free capability 固定写 `connectorPolicy: none`,并禁止自身及传递 support closure 中出现未声明 MCP 依赖。本批不提供 optional dependency。一个 capability 能在无连接器时独立工作,就必须拆成不含 MCP 工具引用的 connector-free capability;自身或任一 support 文件包含 MCP 工具引用的,父 capability 一律使用 required,其 `effectiveConnectorDependencies` 是自身与全部传递 support 依赖的去重并集。 + +当前 3 个 support agent 固定是 `plugins/skill-creator/skills/skill-creator/agents/{analyzer,comparator,grader}.md`,它们的 `supportOwnerCapabilityIds` 必须包含 `skill-creator:skill-creator`;父 Skill 的 `sourceClosureSha256=sha256(JCS(sorted([{canonicalRelativePath,sourceSha256}])))`必须覆盖父 `SKILL.md` 及三个 support agent。任一 support 源文件变化都使父 capability 的 owner/approver 签认失效。 + +生成与运行规则: + +1. `connectorPolicy=none` 只有在 owner/approver 对当前 `sourceClosureSha256` 完成零 MCP 工具依赖签认,且静态扫描对父文件和传递 support closure 的 catalog logical server/tool 名命中为 0 时才进入标准 `skills/agents/commands` 路径;closure 任一 source SHA 变化立即使签认失效; +2. `connectorPolicy=required` 的 Skill 迁移到 `.crabcode-plugin/connector-skills//SKILL.md`,agent 迁移到 `.crabcode-plugin/connector-agents/.md`,command 迁移到 `.crabcode-plugin/connector-commands/.md`;原路径不得再包含可发现副本,manifest/marketplace 的 `skills/agents/commands` 不得引用新隐藏路径,因此 generation=1 无论默认发现还是显式 paths 都无法加载; +3. generator 先解析 support DAG,对 orphan support、环、越界/缺失路径、closure hash 漂移、support 中未声明的 logical MCP 引用 hard fail;再用 certifiedToolsSnapshot 证明 effective requiredTools 子集,不用描述文本或未经认证的 live endpoint; +4. capability 的全部 profile 都是 publish、runtime ready 且实际 tools/list 仍包含 snapshot/requiredTools 时,generation=2 才投影进对应 callable 集合; +5. actual tools/list 缺少 required tool 或 schema hash 漂移时 profile=`tool-contract-drift`,全部依赖 capability 立即退出 callable 集合; +6. 任一 profile 为 block/non-ready 或 dependency 指向 tombstone 时,只在 `.crabcode-plugin/capability-status.json` 记录 capability ID/kind、profile ID、requiredTools、首要 blocker; +7. generation=1 宿主忽略 connector capability/status 新路径,因此不会看到远程依赖 capability; +8. generation=2 管理 UI 展示 blocked capability,但模型 callable 集合不包含它; +9. 已开始的 capability 在 tool boundary 重新校验 profile/instance/tool contract 并 fail-closed; +10. blocked capability 不得靠 prompt 文案绕过能力门。 + +连接实例选择: + +```text +capabilityBindingOwnerId = hex(sha256(JCS([ + "mcp-capability-binding-owner-v2", + hostPrincipal, + pluginId +]))) +``` + +该 owner key 不含 profileId 或 connectionInstanceId,选择前即可计算。 + +1. 一个 profile 恰有 1 个 ready connectionInstance 时自动选择; +2. 有 0 个时沿用 profile blocker; +3. 有 2 个及以上时读取非敏感 `capabilityConnectorBindings[capabilityBindingOwnerId][capabilityKind][capabilityId][profileId]=connectionInstanceId`; +4. generation=2 新增 `capability/connector/select` wire method,参数固定 `{capabilityKind,capabilityId,profileId,connectionInstanceId}`;只接受当前 hostPrincipal/pluginId 下且 ready 的 instance; +5. 未选择、选择项非 ready 或 owner 不匹配时返回 `connector-instance-ambiguous` + `nextAction=selectConnection`; +6. 用户换 provider account 必须新建 connectionInstanceId,并为相关 capability 重新选择;旧选择不得自动跟随账号变化; +7. disconnect/uninstall 删除指向该 instance 的全部 capabilityConnectorBindings。 + +验收: + +```text +Skill raw/governed/runtime/support/vendored-ignored = 352/350/350/0/2 +agent raw/governed/runtime/support/vendored-ignored = 53/46/43/3/7 +command governed/runtime/support = 35/35/0 +runtime capability 总数 = 428 +428 个 runtime capability connectorPolicy 未分类数 = 0 +manifest/marketplace missing path、canonical duplicate、capability ID duplicate = 0/0/0 +support/runtime/orphan support = 3/428/0 +support DAG cycle、closure hash drift、undeclared support MCP reference = 0/0/0 +修改任一 skill-creator support agent → 父 Skill sourceClosureSha256 变化且旧签认失效 +远程 executable profile = 0 时,远程依赖 capability callable 数 = 0 +connector-dependent capability 在 generation=1 可发现数 = 0 +blocked capability 在 generation=2 管理面可见、模型面不可见 +profile 断开后下一次 capability discovery 立即移除 +requiredTools 不在 certified snapshot/存在歧义 → 构建 hard fail +两个 ready instance 未选择 → connector-instance-ambiguous +``` + +## 7. P1 本地服务整改 + +### 7.1 LSP:先移除伪 MCP,再单独产品化 + +P1-A1 立即执行: + +1. 12 个 `*-lsp` 删除 `.mcp.json`; +2. marketplace 不再把它们列为 MCP; +3. validator 对 raw LSP in `.mcp.json` hard error; +4. 不把“删除错误声明”描述为 LSP 已可用。 + +P1-A2 进入 LSP 产品化前必须同时完成: + +```text +TUI 与 GUI agent-worker 初始化一致 +ENABLE_LSP_TOOL 产品开关明确 +plugin identity 包含 marketplace/source +workspace/project/thread 定址隔离 +trust-before-spawn +binary doctor +stopped/error/ready 状态准确 +stdio transport 真正消费 manifest +每种语言真实 initialize/initialized +``` + +任一项未完成时 marketplace 状态保持 blocked;不直接把 12 个 manifest 改成 `lspServers` 后宣布修复。 + +### 7.2 四个第一方频道 + +共同合同: + +```text +启动时安装依赖 = 禁止 +发布物完整 = 必须 +依赖锁定 = 必须 +存在 secret 时安全配置入口 = 必须 +平台/权限 doctor = 必须 +``` + +固定处置: + +| 插件 | providerInteraction | 处置 | +| --- | --- | --- | +| Discord | `external-service` | 构建 dist;`DISCORD_BOT_TOKEN` 进入 sensitive userConfig;列出 bot/admin 权限;third-party verdict/lease 必填 | +| Telegram | `external-service` | 构建 dist;`TELEGRAM_BOT_TOKEN` 进入 sensitive userConfig;列出 bot 权限;third-party verdict/lease 必填 | +| iMessage | `external-service` | 仅 macOS;Full Disk Access、Messages Automation、chat.db 可读性进入 doctor;Apple 消息服务的 third-party verdict/lease 必填 | +| Fakechat | `local-only` | 仅 development tier;随机会话 token、Origin 校验、随机可用端口;生产 marketplace 不发布 | + +这里的“第一方频道插件”只指插件代码由 Acosmi 维护,不把 Discord/Telegram/Apple 托管服务误分为 first-party;三者 profile `providerKind=third-party,providerInteraction=external-service`。只有 Fakechat 本批固定 `providerInteraction=local-only`。 + +发布物允许包含完整、锁定的依赖目录;验收目标是“无运行时安装”,不是“目录中没有 node_modules”。 + +### 7.3 九个第三方 wrapper + +版本冻结算法固定为:P1-C 实施分支创建时只解析一次上游版本;npm 包记录精确 semver、registry integrity 与 lockfile,git 包记录完整 commit SHA,容器记录 tag 与 manifest digest。该批次后续构建只读锁定结果,不再次解析 dist-tag、默认分支或浮动 tag。 + +固定分类: + +| Wrapper | providerInteraction | 发行决策 | +| --- | --- | --- | +| Context7 | `external-service` | 插件构建时打包固定版本 JS 发行物;third-party verdict/lease 必填 | +| Alipay | `external-service` | 插件构建时打包固定版本 JS 发行物,补齐现有 sensitive 配置映射;third-party verdict/lease 必填 | +| DingTalk | `external-service` | 插件构建时打包固定版本 JS 发行物,禁止 `@latest`;third-party verdict/lease 必填 | +| Feishu | `external-service` | 插件构建时打包固定版本 JS 发行物,复用现有 sensitive 配置;third-party verdict/lease 必填 | +| Firebase | `external-service` | 外部 `firebase` CLI;doctor 检查版本与登录,不在 MCP 窗口下载;third-party verdict/lease 必填 | +| Playwright | `local-only` | 外部 Node/npm 与浏览器;doctor 检查固定 package/browser 版本,不在 MCP 窗口下载;provider lease 禁止 | +| Serena | `local-only` | 外部 `uvx`;固定 git commit,doctor 检查 uv 与本地 cache;provider lease 禁止 | +| Laravel Boost | `local-only` | 项目型 PHP/artisan;doctor 检查项目根、PHP、artisan 与命令存在;provider lease 禁止 | +| Terraform | `external-service` | 外部 Docker;镜像固定 `0.4.0` 及 digest,补 sensitive `TFE_TOKEN`;third-party verdict/lease 必填 | + +外部依赖型连接器在 doctor 未通过时 reason=`dependency-missing`,不 spawn、不首次下载。 + +### 7.4 三个租户模板 + +Snowflake 固定合同: + +1. `snowflake_account` 只接受字母、数字、点、下划线、连字符,首字符必须为字母或数字; +2. builder 只生成 HTTPS;解析后的 hostname 必须以 `.snowflakecomputing.com` 结尾且无 userinfo/port; +3. database、schema、mcp server 分别作为单一路径 segment 编码; +4. 任一 segment 为空或包含控制字符时拒绝。 + +Databricks 固定合同: + +1. 普通用户配置只接受 hostname,不接受 scheme、userinfo、port、path、query、fragment; +2. 公网 hostname 只接受 `.cloud.databricks.com`、`.azuredatabricks.net`、`.gcp.databricks.com` 后缀; +3. private enterprise hostname 只在 enterprise config scope 且命中管理员 allowlist 时接受; +4. localhost、特殊用途 IP 和未批准私网目标在普通 scope 拒绝。 + +Benchling 固定合同: + +1. tenant 使用正则 `^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$`; +2. builder 只生成 `https://.mcp.benchling.com/mcp`; +3. 大写、点、下划线、斜线、端口和空值全部拒绝。 + +三个模板都必须覆盖 scheme、userinfo、port、path traversal、query、fragment、控制字符和 Unicode 混淆负向测试。schema 未完成时 reason=`config-schema-missing`;schema 通过但真实租户 E2E 未完成时 reason=`provider-e2e-unverified`。 + +### 7.5 `mediaops` 身份 + +固定产品行为: + +1. 默认保持 fail-closed; +2. 只读 `capabilities` 可在无 principal 时调用; +3. 写工具在无 principal 时返回 `isError:true` + 稳定 `AUTHENTICATION_REQUIRED`; +4. 单机 `local-editorial` 必须由用户显式开启,并显示低保证提示; +5. 宿主注入稳定本地主体,不要求用户手写环境变量; +6. 团队审批模式保持 blocked,直到不同真人 subject 的 OAuth/签名断言通过; +7. 禁止用一个全角色静态账号伪造多人审批; +8. “MCP 已连接”和“治理写工具可用”分别显示。 + +上述 8 项全部通过后,generator 才恢复 `mediaops` stdio publish binding 和 manifest `requiredMcpServers=["mediaops"]`;恢复必须与同一次生成物提交完成,禁止先恢复 required 引用。 + +## 8. Release、凭据迁移与回滚顺序 + +发布顺序不可交换: + +```text +0. 立即沿现有链发布 P0-0E emergency containment(remote runtime/executable=0、仅 html-video;不等 capability 分类) +1A. `[ACOSMI-OPS 独立]` 执行 P0-0A 基础设施/跨云 DR/OIDC/2-of-3 signing 验收;先使 backend bundle primary/DR、四个 backend digest-specific owner/approver environment、OIDC role 可用,并通过 `environment=test` private-store canary 双读回与无生产部署的 workflow fixture,再允许 1C 生产部署;P0-0A 其余子门仍可并行 +1B. 与 1A 并行:执行 P0-0B catalog/tombstone/428 capability 分类与隐藏路径硬化,发布 remote-dependent callable=0 的硬化 safe bytes +1C. `[ACOSMI-SRC/REL 独立]` 与 1A/1B 并行完成 R→A→B 源码、Docker CGO 测试和 bundle 构建;其生产部署依赖 1A 的完整最小 `ACOSMI-REL prerequisite`(backend stores+四 digest-specific protected environments+OIDC role+non-production fixture)通过,然后先上线 A=`metadata-safe`,再上线 B=`cimd-enabled`,完成初次双地点、B→A→B 演练和最终 B 双地点验收 +2. 1A 和 1B 都通过后重取第 1B 步原始字节生成/发布 genesis lock;任一失败则保持第 0 步 emergency marketplace 且 remote 不解禁 +3. 1C 和 2 都通过后,CrabCode 发布内置 genesis trust anchor 的 authPolicyGeneration=2 +4. 三平台/CLI 验收 OAuth、targeted reconnect、ToolSearch、capability gate、release-head gate +5. 单 profile 的 provider basis/auth/reconnect/tools-list/canary 证据通过后,先上传内容寻址的 CrabCode-Plugin profile/endpoint/config 和 marketplace 字节,再发布引用它们的更高序号 lock/head,最后原子切换 marketplace pointer;只有该 profile 从 block 变为 publish,其余 blocker 不变 +6. generation=2 管理面读到同一 catalog-publish profile 与 approved/未过期 verdict lock,判定 effective publish 后才展示其 canonical `configure|oauthLogin|enterToken|externalLogin` CTA +7. 各用户再完成该 profile 的配置/重新授权;成功只影响该 owner/connectionInstance 的 runtime ready,不反向控制全局 marketplace releaseDecision +``` + +旧客户端处理: + +- generation=1 宿主安装 P0 新插件包后只读到 local-only stdio `.mcp.json`,看不到 remote 或 external-service stdio connector profile,因此不能绕过 blocker/lease; +- 插件仓不得在宿主 generation=2 公共制品验收前把远程 profile 改为 publish; +- generation=1 已安装的旧插件副本仍含远程 `.mcp.json`,服务器无法远程改写;P0 支持口径固定要求宿主与插件同时升级,未升级实例不宣称已修复; +- 客服文案明确要求升级宿主; +- 旧 token 不自动迁移到新 client identity; +- 新宿主检测 fingerprint 变化后执行受控重授权; +- 连接器更新不静默扩大 scope。 + +当前 CrabCode GitHub Actions 自动触发已因额度关闭。实施阶段固定使用: + +```text +本机完整硬闸 + + 企业私仓 workflow_dispatch + + 产物人工逐项验收 +``` + +本方案不把“nightly GitHub Actions 已运行”写成完成条件。 + +### 8.1 不可变 release lock + +每次解锁任一 profile 前,固定生成并随 marketplace 资产发布: + +```text +.crabcode-plugin/mcp-release-lock.json +``` + +该路径位于插件仓/marketplace 根,不位于单个插件目录。 + +字段: + +```text +schemaVersion=2 +environment=production +lockPhase=bootstrap | remote-capable +lockSequence +previousLockSha256|null +issuedAt +catalogCommit +catalogSha256 +bindingSnapshotSha256 +releaseKeySetId +previousReleaseKeySetId|null +keySetTransitionRef|null +keySetTransitionSha256|null +thresholdPolicy=2-of-3 +providerVerdictKeySet{ + keySetId, + legal{keyId,algorithm=Ed25519,publicKey}, + security{keyId,algorithm=Ed25519,publicKey} +} +artifacts[{ + role, + component=plugin|marketplace|host|backend|signing|composition, + artifactKind, + visibility, + validationAudience, + artifactRef, + runtimeMirrorRef|null, + disasterRecoveryRef, + releaseAssetName, + sourceCommit|null, + sizeBytes, + sha256, + retentionUntil, + costOwnerTeam +}] +crabCodeHost{version,commit,authPolicyGeneration,artifactRole} +acosmiBackend{commit,artifactRole} +marketplace{artifactRole} +safeBaseline{pluginArtifactRole,marketplaceArtifactRole} +previousApproved{hostArtifactRole,backendArtifactRole} +profileAuthorizationLeases[{ + connectorProfileId, + profilePolicyFingerprint, + eligibilityVerdictRef, + eligibilityVerdictSha256, + eligibilityStatus, + blockedReasonCode|null, + leaseNotBefore, + leaseNotAfter +}] +componentApprovals{ + plugin: ComponentApproval, + marketplace: ComponentApproval, + host: ComponentApproval, + backend: ComponentApproval, + signing: ComponentApproval, + composition: ComponentApproval +} + +ComponentApproval{ + approvalSubjectSha256, + ownerTeam, + ownerId, + ownerApprovedAt, + ownerApprovalEvidenceRef, + ownerApprovalEvidenceSha256, + approverTeam, + approverId, + approverApprovedAt, + approverApprovalEvidenceRef, + approverApprovalEvidenceSha256 +} +``` + +`artifactRole` 在同一 lock 内唯一;safeBaseline.plugin/marketplace 引用的 role 必须分别精确命中 `component=plugin|marketplace`的 release-content;previousApproved host/backend 非 `not-applicable` 时必须分别命中 `component=host|backend`。keySetTransitionRef/SHA 必须命中 `component=signing`,eligibility verdict ref/SHA 必须命中 `component=composition`。任何 component 错配 hard fail。每个 artifact 的 `costOwnerTeam` 固定为 `cost-owner`,由 RACI 中的 `acosmi-ops` 负责容量与保留策略执行。 + +`profileAuthorizationLeases` 按 connectorProfileId 升序且 ID 唯一,只能包含 catalog 中 `providerKind=third-party,providerInteraction=external-service,releaseDecision=publish`的 profile(remote 或 stdio);每个此类 profile 必须恰有 1 条,local-only、first-party、catalog block 和 tombstone 必须 0 条。entry 的 profileId/profilePolicyFingerprint/ref/SHA/status/reason/notBefore/notAfter 必须与双签 ProviderEligibilityVerdict 逐字段一致,verdict ref/SHA 必须精确命中 `artifacts[]` 一个 `artifactKind=release-content,component=composition,visibility=public,validationAudience=release-and-runtime`的 primary/DR 双副本。`approved` 必须 `blockedReasonCode=null,leaseNotBefore<=issuedAt x.component=c && x.artifactKind=release-content) + .sortBy(x.role UTF-8) + .map({role,component,artifactKind,visibility,validationAudience,artifactRef,runtimeMirrorRef,disasterRecoveryRef,releaseAssetName,sourceCommit,sizeBytes,sha256,retentionUntil,costOwnerTeam}) + +plugin subject = sha256(JCS(["mcp-component-plugin-v1",catalogCommit,catalogSha256,bindingSnapshotSha256,componentArtifacts(plugin)])) +marketplace subject = sha256(JCS(["mcp-component-marketplace-v1",marketplace,safeBaseline.marketplaceArtifactRole,componentArtifacts(marketplace)])) +host subject = sha256(JCS(["mcp-component-host-v1",crabCodeHost,componentArtifacts(host)])) +backend subject = sha256(JCS(["mcp-component-backend-v1",acosmiBackend,componentArtifacts(backend)])) +signing subject = sha256(JCS(["mcp-component-signing-v1",releaseKeySetId,previousReleaseKeySetId,keySetTransitionRef,keySetTransitionSha256,thresholdPolicy,providerVerdictKeySet.keySetId,componentArtifacts(signing)])) +composition subject = sha256(JCS(["mcp-component-composition-v1",releaseCandidateCoreSha256])) +``` + +每个 ComponentApproval 的 `approvalSubjectSha256` 必须等于对应上式。任一 release-content artifact 的 role/component/artifactRef/runtimeMirrorRef/disasterRecoveryRef/sourceCommit/size/SHA/保留/成本字段变化都改变对应 subject,禁止只哈希 role 指针。subject 未变时允许在新 lock 中复用旧证据;subject 任一字段变化都必须重做 owner/approver 证据。必测 fixture 对 public plugin/marketplace/host 的 runtimeMirrorRef 各篡改 1 byte,必须导致对应 approvalSubjectSha256 变化且旧 component approval hard fail。纯 `profileAuthorizationLeases` 的 verdict artifact 必须标记 `component=composition`,因此只使 composition subject 变化,其他五个 component 只有在各自 subject 不变时才可复用。 + +owner/approver 证据均由企业私仓 protected-environment/OIDC attestation job 使用企业 IdP 主体产生,固定含 `{schemaVersion=1,approvalId,componentName,approvalSubjectSha256,reusable=true,decision=approve,actorTeam,actorId,actorRole,approvedAt,protectedEnvironmentRunId,issuer,keyId,signature}`。`ownerId/approverId` 使用企业 IdP 稳定不透明 subject ID,不使用姓名/邮箱,两者必须不同。release validator 先从 evidenceRef 取回并校验 SHA-256、OIDC attestation 公钥、actor team/role 及 approvalSubjectSha256;evidenceRef/SHA 必须与 `artifacts[]` 中一个 `artifactKind=component-approval-evidence`、`visibility=release-private`、`validationAudience=release-validator-only`、永久且有 DR 的 artifact 逐字节一致。复用时必须逐字节比对 componentName/approvalSubjectSha256/actor team/role,不得仅按 approvalId 复用。单纯填写 team 字符串不构成批准。 + +phase 规则: + +```text +bootstrap: + lockSequence >= 1 + sequence=1 时 previousLockSha256=null;sequence>1 时必须指向前一 lock + effective remote publish profile = 0 + effective external-service stdio profile = 0 + crabCodeHost.artifactRole = not-applicable + acosmiBackend.artifactRole = not-applicable + previousApproved.hostArtifactRole = not-applicable + previousApproved.backendArtifactRole = not-applicable + +remote-capable: + lockSequence = 已接受最高序号 + 1 + previousLockSha256 = 已接受最高序号对应 lock SHA-256 + hostArtifactRole 必须指向 authPolicyGeneration=2 已批准资产 + backendArtifactRole 必须指向 P0-1 后、CIMD 200 且未广告虚假 CIMD 的 safe backend + previousApproved 两个 role 必须存在于 artifacts[] +``` + +首份 P0-0 lock 固定 `lockPhase=bootstrap,lockSequence=1,previousLockSha256=null`,它是 generation=2 宿主编译时钉住的 genesis lock,不引用 P0-1 前的旧 backend。P0-1/P0-2 验收后生成首份 `remote-capable` lock;若 genesis 后没有 bootstrap/rollback lock,它通常为序号 2,但机器规则固定为 `lockSequence=currentHighest+1,previousLockSha256=currentHead.lockSha256`,禁止写死序号 2。远程 profile 只有在 remote-capable lock 下才能 publish。此后每份 lock 序号恰好 +1 且 `previousLockSha256` 逐字节指向前一份;分叉、跳号或回指更旧 lock 均 hard fail。 + +首份 remote-capable lock 中,`crabCodeHost.artifactRole` 与 `previousApproved.hostArtifactRole` 都指向刚验收的 generation=2 safe host;`acosmiBackend.artifactRole` 指向 B=`cimd-enabled`,`previousApproved.backendArtifactRole` 必须指向 B approval 中三个 safe rollback 字段绑定的唯一 A=`metadata-safe` bundle,A/B 两个完整 bundle 都必须在该 lock `artifacts[]` 中且通过 primary/DR/内层 manifest 验收。A 无 CIMD 端点时宿主只能 fail-close,不得改走 DCR。后续 lock 才把 previousApproved 指向上一份 lock 的当前角色。 + +componentApprovals 固定 team 对: + +```text +plugin = plugin-platform / marketplace-approver +marketplace = plugin-platform / marketplace-approver +host = crabcode-mcp / crabcode-release +backend = acosmi-backend / acosmi-release +signing = release-signing / acosmi-release +composition = lock-composition / marketplace-approver +``` + +artifactRef 只允许不可变定位: + +```text +plugin/marketplace/safe baseline: + https://updates.acosmi.com/crabcode/mcp-safe// + runtime mirror: https://acosmi-mcp-safe-dr-us-west-2.s3.us-west-2.amazonaws.com/crabcode/mcp-safe// + DR: s3://acosmi-mcp-safe-dr-us-west-2/crabcode/mcp-safe// + +CrabCode host: + https://github.com/acosmi/crabcode/releases/download// + runtime mirror: https://acosmi-mcp-safe-dr-us-west-2.s3.us-west-2.amazonaws.com/crabcode/host/// + DR: s3://acosmi-mcp-safe-dr-us-west-2/crabcode/host/// + +Acosmi backend: + oss://acosmi-private-releases-cn-hangzhou/nexus-backend///nexus-backend.tar.gz + runtime mirror: null + DR: s3://acosmi-private-releases-dr-us-west-2/nexus-backend///nexus-backend.tar.gz + +component approval evidence: + oss://acosmi-private-release-evidence-cn-hangzhou/component-approval-evidence/.json + runtime mirror: null + DR: oss://acosmi-private-release-evidence-dr-cn-shanghai/component-approval-evidence/.json +``` + +`visibility=release-private` 的 artifactRef/disasterRecoveryRef 只允许上述 backend primary/DR 或 component evidence primary/DR,`runtimeMirrorRef` 必须为 null,禁止 GitHub/公开 updates locator;component evidence artifact role 只允许不可枚举的 `private-evidence-<128-bit-random>`,object key 只含内容 SHA,禁止出现 provider/profile/app/人员名称。provider private evidence 由独立 release-private audit index 定位,它的 ref 不进入公开 lock。`visibility=public` 的 `artifactRef` 必须是 HTTPS primary,`runtimeMirrorRef` 必须是上述 AWS 直接 HTTPS exact object,`disasterRecoveryRef` 必须是与 runtime mirror 同 key 的底层 S3 ref,三者 size/SHA 相同;不得指向 private bucket。`sizeBytes` 必须为正整数且与取回字节相等。`artifacts[]` 每一项都必须同时写入不同账号、不同区域的 `disasterRecoveryRef`,禁止 `not-applicable`。safe baseline、marketplace、plugin zip、certified tools snapshots、CrabCode 公共资产、Acosmi safe backend 与 component approval evidence 都固定 `retentionUntil=permanent`。生产机 `/opt/acosmi/releases/...` 只是已校验缓存,不是 artifactRef;release validator 使用底层 DR ref,runtime host 只使用公开 HTTPS `artifactRef/runtimeMirrorRef`。 + +lock、插件 zip、marketplace JSON、CrabCode 公共安装资产和 Acosmi backend 完整部署 bundle 都按原始字节计算 SHA-256。backend bundle 内部 payload manifest 还必须逐文件覆盖 `server`、七个 Rust `.so` 的相对路径/size/SHA,任一内层文件不匹配即拒绝。发布前 release validator 必须分别从所有 public/private artifactRef 和 disasterRecoveryRef 独立取回,对 public artifact 还必须无凭据取回 runtimeMirrorRef,逐项验证同一 size+sha256 及应用层证据签名;任一副本取回/比对失败都视为发布失败。runtime host 没有 private bucket 凭据,并行尝试 `validationAudience=release-and-runtime` 的公开 artifactRef/runtimeMirrorRef;primary 断开 fixture 必须从 exact HTTPS runtime mirror 取回同字节并通过 digest。宿主依据 detached threshold signature 验证完整 lock、private artifact digest 字段与最小公开 ProviderEligibilityVerdict 的双签名/profile-fingerprint/lease 绑定;它不访问 release-private URI 或重算 evidence HMAC。回滚禁止重新运行 generator 产生“等价”字节。 + +`safeBaseline.pluginArtifactRole` 必须指向一个全量、确定性的插件安全快照包。包内 `plugins-manifest.json` 固定 78 条 package artifact:`plugins/*` 下 77 个顶层 plugin manifest,加上仓库根 `.crabcode-plugin/plugin.json` 的 `crabcode-setup` 1 条。每条字段为 source-qualified pluginId、version、`sourcePath`、`marketplaceEntryName|null`、`marketplacePublished`、包内相对路径、sizeBytes、sha256;`crabcode-setup.sourcePath="."`。`marketplacePublished=true` 必须恰好 76 条(75 个顶层插件 + root setup),`marketplacePublished=false` 必须恰好 2 条(`crabcode-media-publisher`、`crabcode-security`)。 + +该快照只包含第 6.1 节安全基线:remote runtime=0、external-service stdio runtime=0、remote-dependent callable capability=0,且唯一可发布 MCP 为 `html-video` local-only stdio。`safeBaseline.marketplaceArtifactRole` 指向完整 76-entry marketplace JSON;与 `plugins-manifest.json` 比对时,marketplace 的 76 条只与 `marketplacePublished=true` 子集做 entry name/sourcePath/version/digest 双向差集,期望值为 0;两个 local-only 包只做包内 size/SHA 守恒,禁止要求它们出现在 marketplace。两个 safeBaseline role 必须在同一 lock 同时批准,禁止只回滚单个插件后继续使用旧 marketplace。 + +release lock 不得把自身放入 `artifacts[]`,避免自哈希递归。lock 生成后另生成: + +```text +.crabcode-plugin/mcp-release-lock.detached.json +``` + +detached envelope 的签名 payload 固定为 canonical JSON: + +```text +{ + environment, + releaseKeySetId, + previousReleaseKeySetId, + keySetTransitionRef, + keySetTransitionSha256, + thresholdPolicy, + lockSequence, + previousLockSha256, + issuedAt, + lockArtifactRef, + lockRuntimeMirrorRef, + lockDisasterRecoveryRef, + lockSizeBytes, + lockSha256, + signedAt +} +``` + +`signedAt` 使用 UTC RFC 3339,必须满足 `issuedAt<=signedAt<=issuedAt+15 minutes`;envelope 的 environment/releaseKeySetId/previousReleaseKeySetId/keySetTransitionRef/keySetTransitionSha256/thresholdPolicy/lockSequence/previousLockSha256/issuedAt 必须与取回 lock 逐字段一致。 + +envelope 另含 `signatures[{keyId,signatureAlgorithm=Ed25519,signature}]`;每个 signature 都对上述同一 RFC 8785 canonical payload 签名,正常发布必须有当前 releaseKeySetId 中 3 把 key 的至少 2 个不同 keyId 有效签名,重复 keyId 只计 1 个。`lockArtifactRef=https://updates.acosmi.com/crabcode/mcp-safe//mcp-release-lock.json`,`lockRuntimeMirrorRef=https://acosmi-mcp-safe-dr-us-west-2.s3.us-west-2.amazonaws.com/crabcode/mcp-safe//mcp-release-lock.json`,`lockDisasterRecoveryRef=s3://acosmi-mcp-safe-dr-us-west-2/crabcode/mcp-safe//mcp-release-lock.json`。detached envelope 以完全相同字节永久发布到 primary/public S3 mirror/private S3 DR 的内容寻址目录以及 `heads/.json`,这些不可变对象固定 `Cache-Control: public, max-age=31536000, immutable`。再将同一字节 Put 到 `https://updates.acosmi.com/crabcode/mcp-safe/head.json`、`https://acosmi-mcp-safe-dr-us-west-2.s3.us-west-2.amazonaws.com/crabcode/mcp-safe/head.json` 和底层 primary/S3 object;所有 mutable `head.json` 的 origin/CDN/object metadata 固定 `Cache-Control: no-store`,每次 Put 必须生成新 object version,旧 head version 受 WORM 保留。宿主取 head 必须发送 request `Cache-Control: no-cache`,禁止使用 HTTP cache 的 stale head。宿主只编译内置 offline-root 公钥、初始 releaseKeySet、genesis lock SHA-256 和两个公开 HTTPS head locator,不内置对象存储凭据/不访问 private URI;当前 lock/envelope 禁止进入该 lock `artifacts[]` 所哈希的任何 plugin、marketplace、host 或 backend 产物,也禁止进入 root setup 包。 + +`.crabcode-plugin/mcp-release-lock.json`、`.crabcode-plugin/mcp-release-lock.detached.json` 和 `.crabcode-plugin/release-staging/provider-verdicts/*.json` 都是 catalog commit 完成后的 Git-ignored release staging 输出,不提交进 `catalogCommit`、不进入任何当前产物的 package include list,避免 Git commit/envelope/artifact 自引用并保持纯 lease 更新不改 plugin 字节。发布顺序固定为:公开 verdict/primary/AWS DR 与 lock/envelope 内容寻址字节全部上传并读回校验 → 更新 AWS head 并立即验证无认证 GET 返回新字节+`no-store` → 更新 primary 底层 object/CDN head 并立即从底层 object、`updates.acosmi.com` 各执行无认证 GET,两处都必须返回新字节+`no-store`。任一旧字节/错 header 即发布失败。 + +宿主并行尝试两个公开 HTTPS head,单次 GET 超时 5 秒、禁止 redirect、head 上限 64 KiB、lock 上限 2 MiB,不发送 cookie、Authorization 或任何 connector/user ID。两者都可用时,同序号不同 SHA 返回 `release-head-equivocation`;序号不同时只接受能通过 `previousLockSha256` 链回本地高水位(首次安装则链回编译内置 genesis)的最高有效序号。只有一个可用时可用该源,但仍必须验门限签名/验 SHA/验链;首次安装两源都不可用且没有编译内置 genesis 可用时返回 `release-head-stale`,remote 保持 blocked。runtime host 验证 envelope/lock 门限签名、每个成功取回的 lock size/SHA、前链、公开 artifact 和每 profile 的签名 eligibility verdict/lease;对 componentApprovals 只校验完整字段/evidence digest 被 lock 门限签名覆盖,不访问 private evidence。全部 runtime 适用项通过后,把 `{lockSequence,lockSha256,lastSuccessfulHeadCheckAt}` 原子写入 OS credential backend 的 `mcp2:release-lock-high-watermark`;安全存储不可用时所有 remote profile 保持 blocked。低于高水位、同序号不同 SHA、无法连回本地高水位/genesis 的 lock 均拒绝。合法回滚必须发布“更高序号 + 前链正确 + 指向 safeBaseline”的新 lock,不得重新接受旧 lock。 + +generation=2 control service 在应用启动、插件安装/更新、marketplace refresh、新建 remote connection 前尝试取回 head;存在任一 third-party external-service profile 时每 60 分钟做一次最佳努力刷新。公开两源短时失败时,已缓存且验证过的全局 lock 继续有效,不会因 Acosmi 控制面短时不可达关闭无关 provider。每个 `providerKind=third-party,providerInteraction=external-service` tool boundary(remote 或 stdio)都校验该 profile verdict `eligibilityStatus=approved`、`now=2 distinct current keyId] + newKeyProofSignatures[>=2 distinct new keyId] + offlineRootSignature=forbidden + recoverySecurityEvidenceSha256=forbidden + recoveryReleaseEvidenceSha256=forbidden + +recovery: + currentKeySignatures=not-applicable + newKeyProofSignatures[>=2 distinct new keyId] + offlineRootSignature=required + recoverySecurityEvidenceSha256=required + recoveryReleaseEvidenceSha256=required +``` + +normal 用于仍可取得当前 2-of-3 的常规轮换,只需当前 2-of-3 授权 + 新 2-of-3 持有证明,offline root 明确禁止使用。recovery 只在两把当前 key 均已由 `security` 与 `acosmi-release` 两份 IdP+WORM 证据确认永久不可恢复或已妥协时使用;短时 HSM/网络/人员不可用不属于 recovery 条件。offlineRootSignature 对 `JCS(["mcp-release-keyset-update-recovery-v1",updateWithoutSignatures])` 签名。recovery 还必须由 `security` 与 `acosmi-release` 两个不同 IdP subject 分别批准,证据写入 private WORM,公开 update 只携带两份 SHA-256;release validator 取回/验签证据,runtime host 依据 offline-root 签名与证据 digest 字段接受 recovery,不访问 private URI。 + +过渡 lock 固定 `releaseKeySetId=newReleaseKeySetId,previousReleaseKeySetId=当前 set,keySetTransitionRef=,keySetTransitionSha256=`,ref/SHA 必须命中 `artifacts[]` 中公开 release-content 的 primary/DR 双副本。normal 过渡 envelope 必须同时携带旧 2-of-3 和新 2-of-3;recovery 过渡 envelope 不要求已丢失的旧签名,但必须携带新 set 2-of-3,且 keySetTransitionRef/SHA 的 recovery update/offline-root/双人 evidence digest 全部通过。下一 lock 才恢复 previousReleaseKeySetId/keySetTransitionRef/keySetTransitionSha256=null 并只接受新 set 2-of-3。单 key 丢失/泄露时由其余 2 把走 normal;recovery 完成后必须将事件/证据写 WORM 审计并更换 root 保管介质。旧的已验签 lock 在新 key set 生效前保持可用。 + +ReleaseKeySetUpdate 必须先于过渡 lock 发布到两个内容寻址 locator:`https://updates.acosmi.com/crabcode/mcp-safe/keysets//.json` 和 `https://acosmi-mcp-safe-dr-us-west-2.s3.us-west-2.amazonaws.com/crabcode/mcp-safe/keysets//.json`。宿主遇到未知 releaseKeySetId 时只从已被 envelope/lock 覆盖的 keySetTransitionRef 与对应 AWS locator 取回(禁止 redirect,上限 64 KiB),先校验 raw SHA=keySetTransitionSha256、newReleaseKeySetId 按公钥集重算一致、keySetSequence 恰好 +1、previous hash 与 activateAtLockSequence;`mode=normal` 要求 offlineRootSignature 禁止,并校验当前 2-of-3 + 新 2-of-3;`mode=recovery` 才校验 offline-root 签名、新 2-of-3 + security/acosmi-release 两份 evidence SHA/结构字段,明确不要求当前门限。只有对应 mode 全部通过才将 `{keySetSequence,releaseKeySetId}` 写入 OS credential backend 高水位。低序号、断链、mode 外字段、未达对应门限或未到 activateAtLockSequence 的 set 一律拒绝。 + +每个 componentApprovals 子项的 ownerTeam/approverTeam 都必须命中 canonical team map 且不相等,ownerId/approverId 不相等,两份证据的签名、SHA、actor role/team 和 approvalSubjectSha256 全部通过;6 个子项全部有效后 lock 才生效。任何产物 digest 与 lock 不一致时发布立即失败。 + +### 8.2 回滚触发与执行 + +以下任一条件触发安全回滚: + +```text +blocked/tombstoned profile 被物化为 runtime config +generation=2 对 legacy remote .mcp 发出网络请求 +credentialOwnerId 交叉隔离测试命中同一 key +secret/token/code/state 出现在文件、日志或错误响应 +发布资产 digest 与 release lock 不一致 +同一 certified profile 在两个独立 clean fixture 中均出现 OAuth terminal=success 但 targeted reconnect 未达到 ready +``` + +事故分类必须在 15 分钟内由 `qa-release`记录为互斥二选一: + +```text +connector-path: + provider/profile/catalog/endpoint/canary/backend 故障 + 且 release-head verifier/control-service/eviction/updater 两个 clean fixture 均通过 + +host-trust-path: + release-head 验签/取回/高水位/eviction、control service、credential index 或 updater 任一被怀疑 + 不允许使用 connector-path 的“先等新 lock”假设 +``` + +`connector-path` 固定执行: + +1. `plugin-platform` 先从 primary/DR 取回已批准 78-package safe baseline,对 76 个 `marketplacePublished=true` package 执行与 host-trust-path 相同的 `safeRepackVersion=nextPatch(maxSemVer(事故广告版本,已广告最高版本))`,只改版本/缓存元数据;2 个 local-only 包保持原 safe baseline 字节与 `marketplacePublished=false`。重新生成 78-entry plugins-manifest 和 76-entry marketplace,上传新内容寻址 snapshot/package/marketplace 但暂不切 pointer; +2. 事故涉及 backend 时,由 `acosmi-ops` 执行、`acosmi-release` 批准,按“`/opt/acosmi/releases//` 已复验只读缓存 → `previousApproved.backendArtifactRole` primary → DR”的唯一顺序取得首个通过 bundle/manifest/version 验证的完整目录,停止服务后原子将 `/opt/acosmi/nexus-backend/current` 切到该目录,重启并验 health/两份 AS metadata;current 与 previousApproved 两个 release 目录在对应 lock 可回滚期内均禁止 cleanup。禁止逐文件恢复、恢复 `client_id_metadata_document_supported=true` 或混用不同 bundle 的 binary/library。三个来源都失效时保持服务停止并进入 P0 incident,不运行半部署字节。事故不涉及 backend 时不改线上 backend; +3. `lock-composition` 在第 2 步完成后以当前已接受 lock 为前驱生成 `lockSequence+1` rollback lock:`previousLockSha256` 精确指向事故 lock,catalog/binding snapshot 固定 remote/external-service stdio effective publish=0、remote-dependent callable capability=0,`safeBaseline` 两个 role 指向第 1 步新 safe-repack 字节,host 记录当前字节;事故涉及 backend 时 `acosmiBackend.artifactRole=previousApproved.backendArtifactRole` 并与第 2 步已恢复线上 bundle 一致,不涉及 backend 时才沿用事故 lock 的当前 backend role。重做变化 subject 的 component approvals 与 2-of-3 签名,先更新 AWS DR head、后更新 primary head; +4. `qa-release` 在 generation=1/2 clean fixture 先验证事故版本→safeRepack 会重新取包,再在两个 generation=2 fixture 显式刷新 primary/AWS head,验证已接受新序号、旧 remote connection 已驱逐、remote runtime/callable 都为 0,并在 backend 事故时断言 lock role=线上完整 bundle role; +5. 验收后才原子将 `https://updates.acosmi.com/crabcode/marketplace/current.json` 切换到 76-entry safe-repack marketplace;pointer origin/CDN 必须 `Cache-Control: no-store`,generation=1/2 refresh 请求必须发送 `Cache-Control: no-cache`,切换后立即无认证 GET 必须返回新 pointer 字节+`no-store`,两代 fixture 必须取得新 marketplace 并继续 remote=0;内容寻址 marketplace 固定长缓存+`immutable`。中间任一步失败不切指针。`updater/latest.json` 继续沿用宿主现有 no-cache 合同,本 Acosmi 工作流不改其 schema。 + +`host-trust-path` 固定执行: + +1. 立即绕过故障 verifier:`plugin-platform` 从已批准 `safeBaseline.pluginArtifactRole` 取回 78-package 安全快照,不读事故 catalog;对 76 个 published package 使用 `safeRepackVersion=nextPatch(maxSemVer(当前事故 marketplace 版本,已广告最高版本))`,只改 manifest/marketplace/package/serverInfo/dist/cache-key 版本元数据,其余文件必须与 safe baseline 内层 SHA 一致;2 个 local-only 包保持原字节。生成新 78-entry plugins-manifest 与 76-entry safe-repack marketplace,经 `plugin-platform` owner/`marketplace-approver` approver 和 generation=1/2 旧版本→safeRepack clean update 验收后,沿现有独立 marketplace 链先上传内容寻址字节、后切换 pointer。该分支是“新 rollback head 前不切 pointer”的唯一例外,禁止把旧 safe SemVer 直接回指当成已安装用户回滚; +2. `provider-integrations` 冻结/撤销所有 Acosmi 控制的 provider app/client 并停止新授权;BYO app/token 不受 Acosmi 控制,无法伪称已中央撤销,由 `support` 立即通知用户 disconnect/revoke,并在后续 hotfix 中强制旧 profile/credential legacy; +3. 禁止 SemVer 降级;`crabcode-mcp` 以 `previousApproved.hostArtifactRole.sourceCommit` 为基线,只合入 fail-close/verifier/control-service 修复,生成从未发布且严格大于事故版本的 SemVer patch hotfix,完成签名/公证和三平台测试;旧 binary 只用于取证/离线 fixture; +4. updater 与 plugin update 未被怀疑时,hotfix 按当前真源分发:CLI/TUI 使用 `.github/workflows/release-pipeline.yml` 及 `src/utils/autoUpdater.ts`/`src/cli/update.ts` native updater;macOS Electron/Chromium GUI 使用 `.github/workflows/release-gui-mac.yml`;Windows Electron/Chromium + NSIS 使用 `.github/workflows/release-windows-cross-repo.yml`,且只由其 finalizer 在全部三平台资产验签后生成/发布 `updater/latest.json`。Tauri/WebView2 退役宿主禁止作为正式回滚路径。safe repack 独立走 marketplace update。任一相应 updater/finalizer 也被怀疑时,第 1 步对已安装用户只能保护之后能成功刷新的实例,禁止声称已完成全量止血。此时只发布新签名/公证的全量安装包及 SHA-256,`support` 要求用户手动升级,禁止继续声明旧宿主/插件已修复; +5. 两个 clean hotfix fixture 在 primary/AWS head 各独立测试通过后,才生成/发布更高序号 safe rollback lock,引用 hotfix artifact 并驱逐旧 remote。 + +两个分支共同执行:每次回滚把 `{rollbackId,incidentClass,trigger,incidentLockSha256,rollbackLockSha256|null,lockSequence|null,artifactRoles,executorTeam,executorId,approverTeam,approverId,startedAt,completedAt,result}` 作为同一原始字节双写到 `oss://acosmi-private-release-evidence-cn-hangzhou/rollback-audit//.json` 和 `oss://acosmi-private-release-evidence-dr-cn-shanghai/rollback-audit//.json`,分别读回并记录两个 ref、同一 size/SHA、object version ID,WORM retention=7 年;仓内只记 audit index URI/SHA,不记 actor 原文。不从当前 catalog 临时重算,不恢复退役、供应商专属、Claude 托管或 example endpoint。 + +回滚原则: + +1. Acosmi 回滚不触发宿主改用 DCR;连接器进入 `cimd-document-unavailable`; +2. CrabCode 回滚时 marketplace blocker 不解除; +3. 插件 endpoint 回滚不得恢复 Asana SSE、HubSpot `/anthropic`、Claude 托管端点或 example URL; +4. auth policy 回滚不复用 generation=2 token; +5. token 撤销失败不输出 token 内容。 + +## 9. 验收矩阵 + +### 9.1 每个生产 profile 的必测链 + +| 阶段 | 必须断言 | +| --- | --- | +| 发布 | releaseDecision=publish,官方依据、ownerTeam、approverTeam、release lock 均存在且有效 | +| 安装 | remote / external-service stdio:marketplace→manifest→`.crabcode-plugin/connector-profiles.json`→generation=2 effective gate | +| 安装 | local-only stdio:marketplace→manifest→`.mcp.json`;generation=1/2 都可读 | +| 激活 | plugin enabled 与 MCP activation 独立且可解释 | +| 配置 | required/optional/sensitive 与变量引用一致 | +| 依赖 | clean VM doctor;缺依赖不 spawn | +| 认证 | authMode/clientRegistration/credentialSource 单值明确 | +| 回调 | profile 固定 URI 与实际监听逐字符一致 | +| 握手 | `initialize` 在 10 秒内成功 | +| 枚举 | `tools/list` schema 合法、非空或有官方空清单依据 | +| 发现 | 逻辑别名能定位 canonical wire tool | +| 用户调用 | 用户显式触发的只读验收工具成功 | +| 错误 | auth/config/dependency/endpoint/provider 错误分类准确 | +| 重启 | token refresh 后重启可重连 | +| 撤销 | revoke/clear 后旧 token 不再使用 | + +### 9.2 OAuth 固定回归 + +```text +Notion → CIMD +Linear → CIMD +Canva → CIMD +Synapse → CIMD +Figma → DCR +Asana V2 → preregistered-user + OS credential backend +HubSpot → preregistered-user + OS credential backend +BigQuery → preregistered-user + IAM test project +Slack → provider-app-approval-required 负向阻断 +``` + +OAuth 每条回归必须覆盖: + +```text +首次授权 +用户拒绝 +state mismatch +callback port occupied +timeout +refresh +revoke +client/policy generation change +OAuth 成功后 targeted reconnect +中途 disable/remove +多窗口同 identity singleflight / 不同 identity busy +``` + +### 9.3 用户环境与 canary 分离 + +用户连接流程只自动执行: + +```text +initialize +tools/list +resources/list(服务声明时) +prompts/list(服务声明时) +``` + +禁止自动调用任意业务工具。业务 canary 只在供应商允许的隔离测试租户执行。只有 catalog 中同时存在精确 toolName、args 和 assertion 的 profile 才能通过 release gate;描述性文字不能代替机器合同。 + +| Profile | Canary | +| --- | --- | +| html-video | `validateGraph` + `tests/fixtures/mcp/html-video-minimal-graph.json`;断言 `valid=true`、零 errors | +| mediaops(P1 后) | `mediaops.capabilities`;断言返回 `local-editorial` 能力和主体分离约束;写路径由第 7.5 节独立验收 | +| Open Targets | 当前 `canaryContract=missing`,保持 blocked | +| GitHub | 当前 `canaryContract=missing`,保持 blocked | +| Greptile | 当前 `canaryContract=missing`,保持 blocked | +| Asana | 当前 `canaryContract=missing`,保持 blocked | +| HubSpot | 当前 `canaryContract=missing`,保持 blocked;认证后从真实 tools/list 与官方文档提交完整四字段合同 | +| BigQuery | 当前 `canaryContract=missing`,保持 blocked;认证后从真实成功响应提交完整四字段合同 | +| Terraform | 当前 `canaryContract=missing`,保持 blocked | + +canary 账号不得使用客户数据,不通过第三方代理传 token,不调用写工具。 + +Notion、Linear、Canva、Synapse 及 22 条 oauth+dcr profile 在本修订版中同样以 `canaryContract=missing` 起步;真实授权后必须提交精确机器合同,catalog 审核通过前保持 blocked。 + +### 9.4 本地服务 + +第一方随包 sidecar: + +```text +clean install +离线 cold start +无 installer/cache 副作用 +initialize/tools-list ≤ 10 秒 +dist 新鲜度 +serverInfo 与第一方 package/manifest 一致 +跨 macOS/Windows/Linux 适用平台验收 +``` + +第三方外部依赖型 wrapper 不要求离线可用;它们必须在 spawn 前完成 doctor,并给出可执行安装/登录说明。 + +## 10. 门禁整改 + +### 10.1 PR/static hard gate + +- raw LSP 禁止进入 `.mcp.json`; +- 生产 URL 禁止 example/退役/供应商专属 denylist; +- `connectorProfileId` 必须存在并指向单一 profile; +- remote/stdio/tombstone discriminated union 必须精确命中一种,variant 外字段数量为 0; +- fixed remote endpoint 的 authored canonicalEndpoint 字段命中数必须为 0,derived 值只由 urlTemplate 产生; +- manifest binding 指向 tombstone 的数量必须为 0;bound profile=63、tombstone=3、binding=117 三项分别守恒; +- build-time 生成物 digest 与 catalog 一致; +- `.mcp.json` 中每条记录必须是 `kind=stdio,providerInteraction=local-only,releaseDecision=publish` 且能沿 manifest `mcpConnectorProfiles` 回溯到唯一 catalog profile;remote 或 external-service stdio 在 `.mcp.json` 命中数必须为 0; +- 远程 URL 在 `.mcp.json` 的命中数必须为 0; +- releaseDecision=block 的 profile ID 在 runtime executable config 命中数必须为 0;tombstone gate 只比较 tombstone profile ID、旧 urlTemplate 和 priorExecutableTemplateSha256,禁止用 logicalServerName 阻断迁移后的 Asana/HubSpot; +- generation=1 宿主不得读取 `.crabcode-plugin/connector-profiles.json`;generation=2 loader 只物化 remote 或 external-service stdio 且 effective publish(catalog publish + 适用 lease)的 profile; +- 禁止 install-on-start; +- JS package/git/image 版本必须固定; +- required-local 第一方 sidecar 必须存在发布产物; +- `requiredMcpServers` 与生成后 `.mcp.json` stdio key 的差集必须为 0; +- P0-0E 43 个 marketplace MCP 插件必须各自 patch bump,P0-0B 78 个 package artifact 必须在 E/当前最高版本上再 patch bump;同 SemVer 不同 SHA、原版本覆盖或 cache key 未变均 hard fail; +- authMode/clientRegistration/credentialSource 必填; +- OAuth profile 的 authDiscovery/issuer/resource 必须精确命中 fixed 或 challenge-first variant;challenge-first authored issuer/resource 必须为 null,discovery 失败时 generation 变化数必须为 0; +- challenge-first scopePolicy 必须有 minimumScopes/maximumScopes 且 minimum⊆maximum,发现/step-up/实际授权 scope 差 maximum 必须为 0;private evidence scopes 必须覆盖 maximum,只覆盖 minimum 时 verdict 不得 approved; +- profilePolicyFingerprint 必须精确命中 remote/stdio discriminated 公式;remote 禁止 stdioPolicy,stdio 禁止 endpoint/url/remotePolicy,authMode!=oauth 时 issuer/resource/clientIdentity policy 全为 not-applicable,preregistered-user 禁止纳入实际 BYO clientId/secret; +- providerInteraction 必填;remote 必须 external-service,stdio 可 local-only|external-service;third-party external-service catalog-publish 必须有 lease,local-only/first-party lease 命中数必须为 0; +- SourceProfile 中 profilePolicyFingerprint 命中数必须为 0,GeneratedConnectorProfile 中缺失/非64位小写hex/重算不一致数必须为 0; +- release validator 必须在私有面精确命中 authorizationBasis union,双取回 private evidence、验时效/范围并重算 HMAC commitment;公开 profile/lock 只允许最小 ProviderEligibilityVerdict,禁止 basis/reviewer/private ref/低熵集合 hash/自由文本泄露; +- 公开 approved verdict 必须有 `coverageMode=entire-profile-domain` 的 private domain proof;subset tenant/app/region/client 授权对公开 profile 必须 block,禁止 runtime 依赖 hidden membership; +- 公开 marketplace 中 internal-app basis effective publish 数必须为 0;只能在不属于本报告产物的 enterprise-private marketplace/lock 处理; +- 第三方 officialReference 必须为官方 HTTPS 且无 userinfo/query/fragment;它不能代替 private evidence/verdict; +- 每个 catalog-publish third-party remote profile 必须有 legal+security 双签 verdict;只有 approved 且 `leaseNotAfter<=min(private expiresAt,private reviewDueAt,issuedAt+30 days)`/当前未过期时 effective publish,blocked/过期只 block 该 profile; +- `profileAuthorizationLeases` 与 catalog-publish third-party remote profile 必须一一对应,profileId/profilePolicyFingerprint/verdict ref/SHA/status/reason/lease 逐字段一致;stdio/first-party/catalog-block/tombstone 命中数为 0; +- 当前目标 first-party remote effective publish 数必须为 0;未来 first-party remote 未声明同等 per-profile safety lease 时 hard fail; +- Bearer/confidential secret 必须映射 secure config; +- `${user_config.KEY}` 与 manifest 双向一致; +- 无条件引用字段必须 required; +- 租户 URL 必须由安全 builder 生成,禁止自由字符串直接拼 host/path; +- 第一方 sidecar serverInfo version 与 package/manifest/marketplace 一致; +- Skill/agent/command 所需工具使用机器可读 `requiredTools`,不 grep 自由文本; +- 含 MCP 工具引用的 runtime/support capability 必须有 `connectorDependencies`,profile ID 与 effective requiredTools 差集为 0; +- `src/catalog/skillConnectorInventory.json` 必须精确记录 350 runtime Skill;`src/catalog/promptCapabilityConnectorInventory.json` 必须精确记录 43 runtime agent、3 support agent、35 runtime command;428 个 runtime capability 的 `connectorPolicy` 空值数为 0; +- support DAG 必须无 orphan/环/越界,`sourceClosureSha256` 覆盖父文件和全部传递 support;support 的 connectorDependencies 必须并入父 effective dependencies; +- 含 effective connectorDependencies 的 Skill/agent/command 在标准 `skills/agents/commands` 命中数必须为 0,只能位于 `.crabcode-plugin/connector-skills|connector-agents|connector-commands`,且不得被 manifest/marketplace 标准 paths 引用; +- profile 非 publish/ready 时,`.crabcode-plugin/capability-status.json` 对每个受影响 capability 恰有一条首要 blocker; +- effective requiredTools 必须存在 certified snapshot 与 ToolSearch 可发现路径; +- 新 blocker reason code 有正向与负向测试; +- ownerTeam/approverTeam 必须命中 canonical team map 且不相等; +- P0-0A 基础设施的跨账号/跨区域、versioning/WORM、拒删、DR 取回、OIDC 双人 attestation 证据必须全部通过; +- BootstrapCanaryEnvelope 只允许 `bootstrap-canary//`,production validator 命中数必须为 0;production head 只允许 `schemaVersion=2,environment=production,lockSequence>=1`; +- release lock 的 lockSequence/previousLockSha256 必须连续;同序号不同 SHA、低于宿主高水位或断链均 hard fail; +- 全局 lock 无短周期过期门;每个 publish 第三方 profile 的 eligibility lease 独立校验,D-7/D-3/D-1/D0 状态机只影响相应 profile; +- remote-capable release lock 的 6 个 componentApprovals 必须齐全;每项两个不同 IdP subject 的 evidence signature/SHA/subject 必须通过;bootstrap lock 的 host/backend previousApproved 必须为 not-applicable; +- 6 个 component approval 必须按 component-specific subject 重算;只有 subject 逐字节未变时可复用旧证据,纯 profile lease 更新必须至少使 composition subject/审批变化; +- 每个 artifact.component 必填,component subject 必须哈希按 role 排序的完整 release-content record(artifactRef/runtimeMirrorRef/disasterRecoveryRef/sourceCommit/size/SHA/保留/成本等);仅 role 字符串一致不得复用批准; +- safeBaseline `plugins-manifest.json` 必须为 78 条,其中 marketplacePublished=true/false 为 76/2,76-entry marketplace 与 true 子集双向差集为 0; +- rollback safe repack 的 76 个 published SemVer 必须逐一大于事故/历史已广告最高版本,非版本元数据文件 SHA 必须与已批准 safe baseline 一致;旧 safe pointer 直接回指命中数为 0; +- `mcp-release-lock.detached.json` Ed25519 2-of-3、primary/AWS lock size/SHA、public artifact primary/runtimeMirror/DR 三定位 size/SHA 必须全部验证通过,primary 断开时 generation=2 runtime 必须从 exact HTTPS mirror 成功取回;1 签/重复 keyId 必须失败;release validator 额外双取回并验证所有 release-private evidence,runtime host 不访问 private URI。 +- ReleaseKeySetUpdate 先统一验 content-addressed ID、keySetSequence/previous hash 和 activateAtLockSequence;`mode=normal` 必须旧 2-of-3 + 新 2-of-3,offline-root/recovery evidence 字段禁止;`mode=recovery` 必须 offline-root + 新 2-of-3 + security/acosmi-release 两份 IdP/WORM evidence SHA,旧签名明确 `not-applicable`;低序号/断链/mode 外字段/未达对应门限均 hard fail。 +- 普通 lock 的 previousReleaseKeySetId/keySetTransitionRef/keySetTransitionSha256 必须全为 null;过渡 lock 必须全非 null,ref/SHA 命中 `component=signing` 的公开 KeySetUpdate artifact,envelope 与 lock 逐字段一致; + +### 10.2 Live release gate + +release gate 按 transport/authMode 执行,非适用阶段必须显式写 `not-applicable`,禁止留空: + +| Profile | 必测 | 明确 not-applicable | +| --- | --- | --- | +| remote + none | DNS/TLS/HTTP、匿名 initialize/tools-list、固定 canary | WWW-Authenticate、OAuth metadata、registration、refresh | +| remote + bearer | DNS/TLS/HTTP、secret binding、带 Bearer initialize/tools-list、固定 canary | OAuth registration;refresh 由外部 token owner 管理时记 not-applicable | +| remote + oauth + challenge-first | DNS/TLS/HTTP、WWW-Authenticate、PRM、AS metadata、registration、callback/token、initialize/tools-list、refresh/restart、固定 canary | 无 | +| remote + oauth + fixed | DNS/TLS/HTTP、catalog 固定 AS metadata、registration/client config、callback/token、initialize/tools-list、refresh/restart、固定 canary | provider 不发送初始 challenge 时 WWW-Authenticate/PRM 记 not-applicable并附官方依据 | +| remote + external | DNS/TLS/HTTP、external auth doctor、credential injection、initialize/tools-list、固定 canary | MCP OAuth registration/callback;refresh 由外部 runtime 管理 | +| stdio + bundled-sidecar | package digest、离线 doctor/spawn、initialize/tools-list、固定 canary;external-service 额外验 verdict/lease 的 pre-spawn 与到期 kill | local-only:provider verdict/lease、DNS/TLS/HTTP、WWW-Authenticate、OAuth metadata | +| stdio + command/container/project-cli | dependency doctor、credential binding、spawn、initialize/tools-list、固定 canary;external-service 额外验 verdict/lease 的 pre-spawn 与到期 kill | local-only:provider verdict/lease;无网络端点时 DNS/TLS/HTTP/OAuth metadata | + +一次供应商瞬时失败不自动改 marketplace;任一适用阶段为 fail 或空值时,该 profile 不随本次发布解锁。 + +### 10.3 机器可读证据 + +实施阶段固定生成: + +```text +docs/audit/evidence/2026-08-22-mcp-health/connector-profiles.json +docs/audit/evidence/2026-08-22-mcp-health/connector-tombstones.json +docs/audit/evidence/2026-08-22-mcp-health/probe-results.jsonl +docs/audit/evidence/2026-08-22-mcp-health/provider-references.json +``` + +profile 证据记录必须包含以下字段,任何字段不得省略;非适用值写 `not-applicable`: + +```text +pluginId +logicalServerName +connectorProfileId +providerKind +providerInteraction +endpoint/template +transport +authMode +authDiscovery +issuer +resource +scopePolicy +minimumScopes +maximumScopes +fixedScopes +clientRegistration +runtimeDependency +credentialOwnerScope +profilePolicyFingerprint +authPolicyFingerprint +discoverySnapshotSha256 +probeTime +probeRegion +stage +result +httpStatus +sanitizedErrorCode +officialReference +releaseDecision +blockedReasonCode +ownerTeam +approverTeam +costOwnerTeam +canaryContractHash +certifiedToolsSnapshotSha256 +providerEligibilityVerdictSha256 +providerEligibilityStatus +providerEligibilityLeaseNotBefore +providerEligibilityLeaseNotAfter +providerEvidenceCommitment +lockSequence +lockSha256 +``` + +`connector-tombstones.json` 固定 3 条,每条字段为 `connectorProfileId/logicalServerName/removedReasonCode/priorUrlTemplate/priorExecutableTemplateSha256/removedAt/ownerTeam/approverTeam`;多一条、少一条或重新被 manifest binding 引用都 hard fail。 + +不得保存 token、authorization code、state、client secret、用户数据或完整授权 URL query。 + +## 11. 关联方 RACI 与影响 + +| 事项 | Responsible | Approver | Consulted / 受影响方 | +| --- | --- | --- | --- | +| CIMD handler、AS metadata(`ACOSMI-SRC` 独立) | `acosmi-backend` | `acosmi-release` | `acosmi-ops`、`crabcode-mcp`、`security` | +| 生产部署/回滚/双地点公开验收(`ACOSMI-REL` 独立) | `acosmi-ops` | `acosmi-release` | `support`、`security` | +| callback、auth profile、凭据迁移 | `crabcode-mcp` | `crabcode-release` | GUI/TUI、OS credential backend、`security` | +| targeted reconnect/status wire | `crabcode-mcp` | `crabcode-release` | GUI、多窗口、`support` | +| connector catalog/生成物 | `plugin-platform` | `marketplace-approver` | 各插件维护者、`provider-integrations` | +| Skill/agent/command/support closure 的 connectorDependencies/发布过滤 | `plugin-platform` | `marketplace-approver` | capability 维护者、`crabcode-mcp` | +| provider app/审批证据 | `provider-integrations` | `provider-integrations-approver` | `legal`、`security`、`customer-admin` | +| provider private evidence/HMAC commitment/最小 eligibility verdict 审查、lease 到期与双签 key | `legal` | `security` | `data-governance`、`provider-integrations`、`provider-integrations-approver`、`cost-owner` | +| private evidence 数据分类/保留/境内灾备 policy | `data-governance` | `legal` | `security`、`acosmi-ops`、`cost-owner` | +| BYO client 配置 | `customer-admin` | `provider-integrations-approver` | `support`、`security` | +| canary test tenant | `qa-release` | `security` | `acosmi-ops`、`cost-owner` | +| Claude 托管端点处置 | `provider-integrations` | `legal` | Anthropic、科研数据源维护者、`security` | +| marketplace/plugin 安全回滚 | `plugin-platform` | `marketplace-approver` | `crabcode-release`、`support` | +| CrabCode host fail-close/hotfix(禁止 SemVer 降级) | `crabcode-mcp` | `crabcode-release` | `plugin-platform`、`security`、三平台签名/公证维护者 | +| 回滚事故 connector-path/host-trust-path 分类 | `qa-release` | `crabcode-release` | `plugin-platform`、`crabcode-mcp`、`security`、`support` | +| Acosmi backend 安全回滚 | `acosmi-ops` | `acosmi-release` | `crabcode-mcp`、`security` | +| release lock composition | `lock-composition` | `marketplace-approver` | `plugin-platform`、`crabcode-release`、`acosmi-release`、`qa-release` | +| profile eligibility lease D-7 续签调度、D-3/D-1 升级 | `acosmi-ops` | `provider-integrations-approver` | `provider-integrations`、`legal`、`security`、`lock-composition`、`support`、`cost-owner` | +| release 2-of-3 key set/offline-root 保管、轮换/恢复 | `release-signing` | `acosmi-release` | `security`、`crabcode-release`、`marketplace-approver` | +| public lock/artifact 跨云 DR,private evidence 中国境内跨账号/跨区域 WORM | `acosmi-ops` | `acosmi-release` | `security`、`legal`、`data-governance`、`cost-owner` | + +关联影响固定披露: + +- Slack 审批未完成时,代码完成也不等于可发布; +- Asana/HubSpot/BigQuery BYO 流程增加用户创建应用、管理员授权和 OS credential 配置步骤; +- profile/client ID/scope 变化会触发重新授权; +- 删除旧端点会让现有坏连接器消失,而不是继续显示可登录; +- P0-0 更新后远程 `.mcp.json` 可执行声明初始为 0,现有远程能力暂时不可调用;旧 token 保留但不发送,profile 解锁时按 generation=2 重新授权; +- `mediaops` 在 P1 local-editorial 验收前同样不可执行;P0-0 初始只保留 `html-video` 一个生产 MCP 声明; +- 依赖 blocked connector 的 Skill 同期从 callable 能力集移除;管理 UI 显示对应 blocker,模型不再收到会调用缺失工具的 Skill; +- token 不跨插件共享,因此同一 provider 的不同 profile 必须分别授权; +- 禁止把第三方服务许可证与上游代码许可证混为一体; +- 供应商批准函/合同原文、联系人、reviewer subject、basis、详细范围与 private locator 只在法务私有 WORM 库;插件仓/公开 release lock 只暴露绑定 profile+fingerprint 的双签 eligibility 状态、最长 30 天 lease 和不可字典枚举的 HMAC commitment; +- provider 原文只在中国境内 `cn-hangzhou` primary/`cn-shanghai` 独立账号 DR 处理,不进 GitHub-hosted runner/artifact/cache/log;保留到期/撤销/最后生产引用中最晚日 +7 年,只允许 legal hold 延长; +- generation=2 在有 remote profile 时每 60 分钟最佳努力刷新签名 release head;primary/AWS 直接域名短时同时不可达不会使全局 lock 失效,但过期 profile lease 仍只 fail-close 该 provider,客服需区分该状态与 OAuth/token 失败; +- DR/WORM、protected environment attestation 和永久发布产物会产生持续存储/运维成本,由 `cost-owner` 预算签认、`acosmi-ops` 执行; +- generation=1 不读签名 release head,无法被远程 rollback lock 即时驱逐;支持与客服口径固定要求升级宿主及插件; +- 无客户 token 进入 Acosmi 服务端,本批不新增 token 托管责任。 + +## 12. 明确不做 + +- 不自动激活全仓 MCP; +- 不恢复或复用 Anthropic OAuth client ID; +- 不继续使用 HubSpot `/anthropic`; +- 不把 `*.mcp.claude.com` 技术可达当生产授权; +- 不在本批建设 confidential OAuth broker; +- 不复用现有 Acosmi admin MCP OAuth handler; +- 不把 client secret 放入插件仓、桌面包、settings JSON、日志或命令行; +- 不在登录过程中 CIMD/DCR 静默切换; +- 不跨插件、账号、租户或 resource 共享 token; +- 不新增运行时远程 connector `$ref`; +- 不按 HTTP/SSE transport 显示 OAuth CTA; +- 不让 GUI 收到 OAuth 广播后全局 reload; +- 不在用户连接时自动调用业务工具; +- 不把 provider basis、合同/批准原文、provider reviewer/provider private locator 或可枚举的低熵集合 hash 发布到 Git/公开 lock; +- 不把 LSP 伪装成 MCP; +- 不在 MCP 启动窗口安装依赖或下载浏览器/镜像; +- 不强制把 PHP、Docker、项目 CLI 打包进插件; +- 不以“目录没有 node_modules”代替发行完整性; +- 不放宽 `mediaops` 主体分离; +- 不让 wire hash 成为 Skill 稳定接口; +- 不把隐藏 CapabilityConsole 当当前生产主入口全面重构; +- 不把 GitHub Actions nightly 描述成当前已运行能力。 + +## 13. 可复算命令 + +```bash +# MCP 插件数 +find plugins -name .mcp.json -not -path '*/node_modules/*' | wc -l + +# 顶层插件 manifest / marketplace entries +find plugins -mindepth 3 -maxdepth 3 -path '*/.crabcode-plugin/plugin.json' | wc -l +jq '.plugins | length' .crabcode-plugin/marketplace.json + +# 服务声明与传输类型 +for f in plugins/*/.mcp.json; do + jq -r '(.mcpServers // .) | to_entries[] | (.value.type // "stdio")' "$f" +done | sort | uniq -c + +# 远程 URL 总量与唯一值 +for f in plugins/*/.mcp.json; do + jq -r '(.mcpServers // .) | to_entries[] | .value.url // empty' "$f" +done | sort | uniq -c + +# required MCP +for f in plugins/*/.crabcode-plugin/plugin.json; do + jq -r 'select(.requiredMcpServers != null) | [.name, (.requiredMcpServers|join(","))] | @tsv' "$f" +done + +# user_config 引用 +grep -H -o '\${user_config\.[^}]*}' plugins/*/.mcp.json | sort + +# ambient token 引用 +grep -H -o '\${[A-Z][A-Z0-9_]*}' plugins/*/.mcp.json | sort + +# 退役/供应商专属/示例端点;整改后期望 0 +grep -R -n -E 'mcp\.asana\.com/sse|mcp\.hubspot\.com/anthropic|mcp\.claude\.com|mcp\.example\.com' \ + plugins --include='.mcp.json' + +# raw LSP MCP;整改后期望 0 +find plugins -path '*-lsp/.mcp.json' -print + +# Prompt capability raw/governed 数:Skill 352/350,agent 53/46,command 35/35 +find plugins -type f -name SKILL.md | wc -l +find plugins -type f -name SKILL.md -not -path '*/node_modules/*' | wc -l +find plugins -type f -path '*/agents/*.md' | wc -l +find plugins -type f -path '*/agents/*.md' -not -path '*/node_modules/*' | wc -l +find plugins -type f -path '*/commands/*.md' -not -path '*/node_modules/*' | wc -l + +# manifest 显式 Skill refs=332,显式 agent refs=5,显式 command refs=0 +for f in plugins/*/.crabcode-plugin/plugin.json; do + jq -r '.skills // empty | if type=="array" then .[] else . end' "$f" +done | wc -l +for f in plugins/*/.crabcode-plugin/plugin.json; do + jq -r '.agents // empty | if type=="array" then .[] else . end' "$f" +done | wc -l +for f in plugins/*/.crabcode-plugin/plugin.json; do + jq -r '.commands // empty | if type=="array" then .[] elif type=="string" then . else empty end' "$f" +done | wc -l + +# 无显式字段时宿主默认发现:Skill=18、agent=38、command=35 +for f in plugins/*/.crabcode-plugin/plugin.json; do + if jq -e 'has("skills")|not' "$f" >/dev/null; then + p="${f%/.crabcode-plugin/plugin.json}" + find "$p/skills" -mindepth 2 -maxdepth 2 -type f -name SKILL.md 2>/dev/null + fi +done | wc -l +for f in plugins/*/.crabcode-plugin/plugin.json; do + if jq -e 'has("agents")|not' "$f" >/dev/null; then + p="${f%/.crabcode-plugin/plugin.json}" + find "$p/agents" -type f -name '*.md' 2>/dev/null + fi +done | wc -l +for f in plugins/*/.crabcode-plugin/plugin.json; do + if jq -e 'has("commands")|not' "$f" >/dev/null; then + p="${f%/.crabcode-plugin/plugin.json}" + find "$p/commands" -type f -name '*.md' 2>/dev/null + fi +done | wc -l + +# 当前受治理 support agent=3;marketplace 额外发现 override=0 +find plugins/skill-creator/skills/skill-creator/agents -type f -name '*.md' | wc -l +jq '[.plugins[] | select(.skills != null or .agents != null or .commands != null)] | length' \ + .crabcode-plugin/marketplace.json + +# runtime 合计=350+43+35=428;当前 dependency fields=0 +grep -R -l '^connectorDependencies:' plugins --include='SKILL.md' --include='*.md' \ + --exclude-dir=node_modules | wc -l + +# 当前静态契约检查 +bun run lint:mcp-contract +``` + +生产只读复核: + +```bash +curl --max-redirs 0 -sS -D - \ + https://acosmi.com/oauth/crabcode-client-metadata + +curl -sS https://acosmi.com/.well-known/oauth-authorization-server | \ + jq '{registration_endpoint,client_id_metadata_document_supported}' + +curl -sS https://acosmi.com/.well-known/oauth-authorization-server/desktop | \ + jq '{registration_endpoint,client_id_metadata_document_supported}' +``` + +## 14. 最终收口标准 + +| 层 | 当前裁决 | 收口标准 | +| --- | --- | --- | +| 公网端点 | 只有可达性聚合,不能称整体健康 | 每个 publish profile 有逐阶段 pass 证据 | +| CIMD | 404;回调合同不闭合 | 公网固定 JSON 200 + 127.0.0.1:3118 + Notion/Linear/Canva/Synapse 四家真实授权 | +| Acosmi AS | 虚假广告 CIMD | 两份 metadata 不再广告未实现能力 | +| OAuth UI | transport 推断产生死 CTA | canonical auth profile/nextAction 驱动 | +| OAuth 完成 | 只显示 success | exact eviction + reconnect + tools/list | +| 凭据迁移 | 旧 client/token 可被复用 | generation/fingerprint 隔离并受控重授权 | +| 无登录远程 | 0 个 production-approved 完整正例 | 供应商资格 + 固定 canary 同时通过 | +| 第一方 sidecar | 进程健康,身份/错误语义未闭合 | mediaops 模式和结构错误验收通过 | +| LSP | 12 个伪 MCP | MCP 声明归零;LSP 产品化独立验收 | +| 频道 | 运行时安装且配置缺失 | 自包含发行、secret/平台 doctor 完成 | +| 第三方 wrapper | 外部依赖未闭合 | 固定版本、spawn 前 doctor、无启动时下载 | +| ToolSearch | 逻辑别名缺失 | 私有 alias index、碰撞 fail-closed | +| 门禁 | warning 可掩盖确定故障 | static hard gate + release profile evidence | + +真正完成不是“更多行显示 connected”,而是每个被发布的 connector profile 都能走完整条可解释、可复现、可回滚的链路。任何未通过项都必须以精确 blocker 呈现;默认保持不可激活,禁止回退成“登录失败”“条件健康”“待确认”或“稍后处理”。