changeguard 0.0.0-stage → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/CHANGELOG.md +440 -0
  2. package/LICENSE +202 -0
  3. package/LICENSE-PROPRIETARY +94 -0
  4. package/README.md +317 -2
  5. package/SECURITY.md +40 -0
  6. package/data/changes/openai.seed.json +87 -0
  7. package/data/changes/shopify.seed.json +42 -0
  8. package/data/changes/stripe.seed.json +60 -0
  9. package/data/changes/supabase.seed.json +56 -0
  10. package/data/changes/twilio.seed.json +63 -0
  11. package/data/openapi/openai/meta.json +9 -0
  12. package/data/openapi/openai/new.json +24 -0
  13. package/data/openapi/openai/old.json +68 -0
  14. package/data/providers/openai.json +60 -0
  15. package/data/providers/shopify.json +52 -0
  16. package/data/providers/stripe.json +57 -0
  17. package/data/providers/supabase.json +56 -0
  18. package/data/providers/twilio.json +57 -0
  19. package/dist/analyze/go-analyzer.js +343 -0
  20. package/dist/analyze/index.js +77 -0
  21. package/dist/analyze/js-analyzer.js +380 -0
  22. package/dist/analyze/parser.js +78 -0
  23. package/dist/analyze/py-analyzer.js +313 -0
  24. package/dist/analyze/rules.js +1 -0
  25. package/dist/analyze/ts-utils.js +62 -0
  26. package/dist/cli.js +335 -0
  27. package/dist/codemod/apply.js +159 -0
  28. package/dist/config.js +121 -0
  29. package/dist/deps/manifests.js +145 -0
  30. package/dist/github/api.js +136 -0
  31. package/dist/github/auth.js +54 -0
  32. package/dist/impact/engine.js +384 -0
  33. package/dist/ingest/canonical.js +52 -0
  34. package/dist/ingest/changelog-html.js +63 -0
  35. package/dist/ingest/feed-client.js +99 -0
  36. package/dist/ingest/feed-keys.js +198 -0
  37. package/dist/ingest/feed.js +178 -0
  38. package/dist/ingest/github-releases.js +59 -0
  39. package/dist/ingest/note-parser.js +274 -0
  40. package/dist/ingest/openapi-diff.js +217 -0
  41. package/dist/ingest/store.js +181 -0
  42. package/dist/llm/explanation.js +273 -0
  43. package/dist/mcp/format.js +116 -0
  44. package/dist/mcp/index.js +29 -0
  45. package/dist/mcp/protocol.js +36 -0
  46. package/dist/mcp/server.js +110 -0
  47. package/dist/mcp/standalone.js +12 -0
  48. package/dist/mcp/tools.js +189 -0
  49. package/dist/notify/index.js +174 -0
  50. package/dist/providers/registry.js +215 -0
  51. package/dist/report/html.js +194 -0
  52. package/dist/report/markdown.js +90 -0
  53. package/dist/report/pr-draft.js +37 -0
  54. package/dist/scan.js +168 -0
  55. package/dist/source/repo-source.js +100 -0
  56. package/dist/types.js +6 -0
  57. package/dist/util/http.js +40 -0
  58. package/dist/util/logger.js +61 -0
  59. package/dist/util/metrics.js +99 -0
  60. package/dist/util/request-context.js +22 -0
  61. package/dist/util/task-queue.js +69 -0
  62. package/dist/util/versions.js +52 -0
  63. package/fixtures/sample-repo/cmd/billing/main.go +47 -0
  64. package/fixtures/sample-repo/go.mod +12 -0
  65. package/fixtures/sample-repo/package.json +17 -0
  66. package/fixtures/sample-repo/requirements.txt +7 -0
  67. package/fixtures/sample-repo/services/ai.py +65 -0
  68. package/fixtures/sample-repo/src/billing.ts +68 -0
  69. package/package.json +84 -4
@@ -0,0 +1,94 @@
1
+ # ChangeGuard — Proprietary License
2
+
3
+ Copyright (c) 2026 the ChangeGuard authors. All rights reserved.
4
+
5
+ This repository is **dual-licensed**. `LICENSE` contains the full, unmodified
6
+ Apache License 2.0. This file defines its scope and governs everything that
7
+ Apache-2.0 does not cover.
8
+
9
+ ## 1. Apache-2.0 scope
10
+
11
+ The following paths are licensed under the Apache License, Version 2.0:
12
+
13
+ | Path | Contents |
14
+ | --- | --- |
15
+ | `src/cli.ts` | CLI entrypoint (`demo`, `scan`, `pr-preview`, `pr-open`) and the optional loader for the proprietary admin extension; it contains no import of proprietary modules (see §3) |
16
+ | `src/scan.ts`, `src/types.ts`, `src/config.ts` | Scan orchestration, shared types, configuration plumbing |
17
+ | `src/analyze/**` | Tree-sitter parsers and JS/TS/Python/Go analyzers |
18
+ | `src/impact/**` | Deterministic impact / rules engine |
19
+ | `src/codemod/**` | Codemod patch generation |
20
+ | `src/deps/**` | Manifest and dependency collection |
21
+ | `src/source/**` | Repository source abstraction (local / virtual) |
22
+ | `src/providers/**` | Provider registry and host rules |
23
+ | `src/ingest/**` | Change-ingestion engine (GitHub Releases, changelog HTML, OpenAPI diff, local store) |
24
+ | `src/report/**` | Markdown / HTML reports and PR body drafts |
25
+ | `src/llm/**` | Optional explanation layer (template-first) |
26
+ | `src/notify/**` | Outbound notification channels (GitHub Issue, Slack, email) |
27
+ | `src/github/**` | GitHub API client (token and GitHub App installation auth) |
28
+ | `src/util/**` | HTTP, logging, task-queue and version helpers |
29
+ | `data/**` | Bundled offline seed records and OpenAPI snapshots required by the CLI |
30
+ | `fixtures/**` | Sample repository used by tests and the demo |
31
+ | `tests/engine.test.ts`, `tests/analyzers.test.ts`, `tests/codemod.test.ts`, `tests/scan-e2e.test.ts`, `tests/openapi-diff.test.ts`, `tests/manifests.test.ts`, `tests/note-parser.test.ts`, `tests/license-boundary.test.ts`, `tests/feed.test.ts` | Tests for Apache-2.0 modules |
32
+ | `scripts/**` | Development and diagnostic scripts |
33
+ | `docs/**`, `manuals/**` | Public architecture notes and public product manuals |
34
+ | `.github/**` | CI configuration |
35
+ | Root config files (`package.json`, `package-lock.json`, `tsconfig.json`, `vitest.config.ts`, `.env.example`, `.gitignore`, `.npmrc`, `.dockerignore`) | Build, test and tooling configuration |
36
+
37
+ ## 2. Proprietary scope
38
+
39
+ The following paths are **not** licensed under Apache-2.0. All rights are
40
+ reserved; no license, express or implied, is granted except by a separate
41
+ written agreement with the copyright holder.
42
+
43
+ | Path | Contents |
44
+ | --- | --- |
45
+ | `src/server/**` | Hosted control plane: HTTP routing, console/dashboard, authentication and sessions, GitHub and Stripe webhooks, scheduler, usage reporting |
46
+ | `src/store/**` | Multi-tenant persistence: tenants, hashed API keys, audit log, billing state, SQLite access |
47
+ | `src/cli-admin.ts` | CLI admin extension: `serve`, `tenant`, `key`, `plan`, `audit`, `bind-installation`; the only CLI module allowed to import `src/server/**` and `src/store/**` |
48
+ | `Dockerfile`, `docker-compose.yml`, `docker-compose.multi.yml` | Deployment packaging for the hosted service |
49
+ | `tests/phase3.test.ts`, `tests/phase4.test.ts`, `tests/phase5.test.ts`, `tests/security.test.ts`, `tests/manual-search.test.ts`, `tests/cli-admin.test.ts` | Tests that exercise proprietary modules (`src/server`, `src/store`, `src/cli-admin`) |
50
+
51
+ Everything not listed in §1 is proprietary, including any file added later
52
+ unless it is explicitly placed under §1 in this file.
53
+
54
+ The **hosted change feed**, its production curation pipeline, customer data,
55
+ and any operational infrastructure outside this repository are proprietary
56
+ and are not covered by Apache-2.0.
57
+
58
+ ## 3. Mixed paths — how the boundary is applied
59
+
60
+ Some files legitimately serve both products. The rule is: **the license follows
61
+ the module's purpose, and an import never relicenses the imported module.**
62
+
63
+ - **`src/cli.ts` / `src/cli-admin.ts`** — the CLI was split so the Apache-2.0
64
+ entrypoint contains no proprietary command and no import of
65
+ `src/server/**` or `src/store/**`, not even a dynamic one. `src/cli.ts` calls
66
+ `import('./cli-admin.js')`; the proprietary extension registers `serve`,
67
+ `tenant`, `key`, `plan`, `audit` and `bind-installation`. When the extension
68
+ is absent (Apache-2.0-only distribution) the entrypoint registers stubs with
69
+ the same command names that explain what is missing and exit non-zero. The
70
+ scan commands keep working unchanged.
71
+ - **`src/scanner` dependencies consumed by the server** — `scan.ts`, `notify/**`,
72
+ `github/**`, `report/**` stay Apache-2.0; the hosted server is allowed to
73
+ consume them under Apache-2.0. The reverse is not true: Apache-2.0 code must
74
+ not depend on proprietary modules to run.
75
+ - **`data/**`** — this is the offline snapshot the CLI needs to scan without
76
+ network access, therefore Apache-2.0. The hosted feed service that publishes
77
+ fresh records is proprietary and lives outside this repository.
78
+ - **`tests/**`** — a test follows the license of the module it exercises. Tests
79
+ that import `src/server` or `src/store` are proprietary (see §2).
80
+ - **Licensing is not a technical access control.** Nothing in `src/server` or
81
+ `src/store` becomes open source merely because it is distributed in the
82
+ repository or referenced by Apache-2.0 code.
83
+
84
+ ## 4. Redistribution of the Apache-2.0 portion
85
+
86
+ You may use, reproduce, modify and distribute the Apache-2.0 paths, including
87
+ as part of a product, provided you comply with the Apache License 2.0
88
+ (notably: retain copyright and license notices, state significant changes,
89
+ and include a copy of the license). You may **not** copy, modify, distribute,
90
+ host or commercially exploit the proprietary paths without written permission.
91
+
92
+ The npm tarball is constrained by the `files` allowlist in `package.json`: it
93
+ ships the Apache-2.0 portion only, so `dist/server/**`, `dist/store/**`,
94
+ `dist/cli-admin.*` and the Docker files are never published.
package/README.md CHANGED
@@ -1,3 +1,318 @@
1
- # Temporary Holding Version
1
+ # ChangeGuard 变更哨兵
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ > **一句话**:盯住 Stripe / OpenAI / Shopify / Twilio / Supabase 五家厂商的破坏性变更,自动扫描你的 TS / JS / Python / Go 代码定位影响点,输出可追溯的报告、PR 草稿与 codemod 补丁,Slack / Email 即时推送。判定由确定性规则引擎完成,LLM 可选润色。
4
+
5
+ - 零原生依赖:Node.js ≥ 22.13(`node:sqlite` 要求)+ 4 个纯 JS 包,Windows / macOS / Linux 开箱即用
6
+ - 离线优先:核心流水线无网络运行,`npm run demo` 内置样例仓库完整端到端
7
+ - 可审计:每条 finding 带规则 ID、命中位置、置信度;所有敏感操作写审计日志
8
+ - 多租户 SaaS:API Key(sha256)/ HMAC Cookie / GitHub SSO,Free/Pro/Team 三档,Stripe Checkout 零 SDK
9
+ - 手册内置:控制台导航含「手册」标签,支持跨手册全局搜索 + 页内 TreeWalker 高亮
10
+
11
+ ---
12
+
13
+ ## 快速开始
14
+
15
+ ```bash
16
+ npm install
17
+ npm run demo # 离线跑通完整流水线(不需要任何配置)
18
+ npm run serve # 启动 HTTP 服务:控制台 http://localhost:8787
19
+ ```
20
+
21
+ 启动后浏览器打开 http://localhost:8787 。控制台顶栏四标签:**控制台 · 设置 · 手册 · 套餐**。
22
+
23
+ ### 安装(试用 / 内部分发,tarball)
24
+
25
+ npm 官方 registry 暂未发布本包(注册通道不可用),试用版以 tarball 分发:
26
+
27
+ ```bash
28
+ # 1) 拿到 changeguard-<版本>.tgz 后全局安装
29
+ npm install -g ./changeguard-0.6.1.tgz
30
+ # 2) 核对版本(应输出与 tgz 一致的版本号)
31
+ changeguard --version
32
+ # 3) 扫描任意本地仓库
33
+ changeguard scan <你的项目路径> --since 2025-01-01
34
+ ```
35
+
36
+ 维护者一侧打包一条命令(跑完与 npm 发布相同的八项门禁,产出可直接分发的 tgz 并自动做安装回验):
37
+
38
+ ```bash
39
+ npm run publish:tarball # 产物落在 ../trial-kit/,可用 --dest <dir> 覆盖
40
+ ```
41
+
42
+ 详见 `docs/tarball-distribution.md`。
43
+
44
+ ---
45
+
46
+ ## 架构分层
47
+
48
+ ```
49
+ CLI 入口 demo / scan / serve src/cli.ts
50
+ │
51
+ ▼
52
+ 编排层 scanRepository → 清单解析 / 代码分析 / 变更采集 / 影响引擎
53
+ │
54
+ ├─ 解析层 Tree-sitter WASM:JS / TS / Python / Go 调用点
55
+ ├─ 变更层 GitHub Releases · OpenAPI diff · Changelog HTML · 本地种子数据
56
+ ├─ 引擎层 确定性规则 R1–R9(重命名 / 参数变更 / 废弃 / 移除 / 类型…)
57
+ ├─ 输出层 HTML / Markdown / PR 草稿 / codemod.patch
58
+ └─ 润色层 LLM 事后解释(可选,核心结论不受影响)
59
+ ```
60
+
61
+ ## 功能矩阵
62
+
63
+ | 维度 | 支持 |
64
+ |---|---|
65
+ | 厂商 | Stripe · OpenAI · Shopify · Twilio · Supabase;注册表数据驱动(`data/providers/*.json`),扩厂商零代码(见「扩展厂商」) |
66
+ | 语言 | TypeScript / JavaScript · Python · Go |
67
+ | 清单 | `package.json` · `requirements*.txt` / `pyproject.toml` · `go.mod` |
68
+ | 规则 | 9 条确定性引擎规则(R1–R9),每条带 `ruleId` + 严重级 |
69
+ | 输出 | HTML 影响报告 · Markdown · JSON · PR 草稿 · unified diff codemod.patch |
70
+ | 通知 | Slack Webhook · SMTP 隐式 TLS · GitHub Issue(去重合并) |
71
+ | 认证 | 控制台密码(HMAC Cookie)· API Key(服务端只存 sha256)· GitHub OAuth SSO |
72
+ | 计费 | Free(2 仓 / 10 扫 / 月)· Pro(25 / 500 / $49)· Team(100 / 5000 / $99) |
73
+ | 部署 | CLI 本地 · HTTP 服务 · Docker 单机 · Docker 多实例 |
74
+
75
+ ## 性能基线(本机实测,2026-11-17)
76
+
77
+ 合成仓库 = TS/Python/Go 混合(70/20/10),每文件 2 个真实厂商调用点;`node dist/cli.js scan`
78
+ 端到端(含 Node 启动 ≈0.1s):
79
+
80
+ | 仓库规模 | 调用点 | 扫描耗时 |
81
+ |---|---|---|
82
+ | 100 文件 | 200 | **0.75 s** |
83
+ | 500 文件 | 1,000 | **0.84 s** |
84
+ | 2,000 文件 | 4,000 | **1.99 s** |
85
+
86
+ 边际成本 ≈ **0.65 ms/文件**(Tree-sitter 解析 + 9 条规则引擎 + 报告生成)。典型中型仓库
87
+ (数百文件)通常在 1 秒内完成。
88
+
89
+ 复现:`npx tsx scripts/gen-synth-repo.ts --files 2000 --out .changeguard/synth` 后用
90
+ `changeguard scan .changeguard/synth --since 2020-01-01 --out <dir>` 计时。
91
+
92
+ ## MCP 接入(agent 场景)
93
+
94
+ `changeguard mcp` 把扫描引擎包装成 MCP Server(stdio),让 Claude Code / Cursor / Cline 在改代码前先查「这个 API 最近有没有破坏性变更」,直接拿到 `文件:行` 级影响定位。三个只读工具:`list_breaking_changes` / `check_impact` / `get_feed_status`。本地运行、只读、不联网、零新增依赖。
95
+
96
+ ```json
97
+ { "mcpServers": { "changeguard": { "command": "npx", "args": ["-y", "changeguard", "mcp"] } } }
98
+ ```
99
+
100
+ 完整协议契约(工具 schema / 三种客户端配置 / 安全边界)见 `docs/mcp.md`。
101
+
102
+ ## 命令参考(CLI)
103
+
104
+ | 命令 | 说明 |
105
+ |---|---|
106
+ | `changeguard demo [--out <dir>]` | 离线跑通内置样例仓库全流程 |
107
+ | `changeguard scan <path> [--since <iso>] [--online] [--feed <path\|url>] [--trusted-keys <file>] [--out <dir>] [--json] [--only-matched]` | 扫描本地仓库;`--online` 抓取厂商 Releases(缓存 6h);`--feed` 使用签名变更 feed(验签失败即回退);`--only-matched` 仅保留锚定到具体文件的命中(过滤仓库级/依赖级提醒) |
108
+ | `changeguard pr-preview <path> [--feed <path\|url>] [--trusted-keys <file>]` | Dry-run:打印 PR 标题 / 正文 / unified diff,不改任何仓库 |
109
+ | `changeguard pr-open <owner/repo> [--since <iso>] [--base <branch>] [--installation <id>] [--feed <path\|url>] [--trusted-keys <file>]` | **真实创建 DRAFT PR**:远程拉代码 → 扫描 → codemod patches → GitHub 新分支 + commit + DRAFT PR;base 自动探测 main → master;需要 `GITHUB_TOKEN` 或 App installation 凭据 |
110
+ | `changeguard serve` | 启动 HTTP 服务(控制台 + `/webhook` GitHub App + `/webhook/stripe` 计费) |
111
+ | `changeguard tenant create <name> --plan <free\|pro\|team>` / `tenant list` | 多租户管理 |
112
+ | `changeguard key create --tenant <id> [--name]` / `key list` / `key revoke <id>` | API Key 管理;明文仅创建时打印一次 |
113
+ | `changeguard plan <tenantId> <plan>` | 手工调整套餐(不走 Stripe) |
114
+ | `changeguard bind-installation <installationId> <tenantId>` | 把 GitHub App 安装绑定到租户 |
115
+ | `changeguard audit list [--tenant <id>] [--action <name>] [--limit <n>]` | 查询审计日志 |
116
+
117
+ 开发期可用 `npx tsx src/cli.ts <命令>` 直接运行;`npm run build` 后二进制入口 `changeguard` 指到 `dist/cli.js`。
118
+
119
+ > 管理类命令(`serve` / `tenant` / `key` / `plan` / `audit` / `bind-installation`)由专有扩展 `src/cli-admin.ts` 提供。Apache-2.0 分发包中不含该扩展,调用时会给出一行明确提示并以非零码退出;扫描类命令不受影响。
120
+
121
+ ### 签名变更 feed
122
+
123
+ `--feed` 读取一份 ed25519 签名的变更 feed。信任是**两层**的:包内长期根公钥
124
+ (`BUILTIN_ROOT_KEYS`)签名一份 keyring,keyring 再授权具体签名钥。因此日常轮换
125
+ 签名钥只需重新签发 keyring,已安装的 CLI 无需升级;只有根钥更换才需要发版。
126
+
127
+ **fail-closed**:keyring 被篡改 / 被未知根钥签名 / 缺签名,或 feed 签名缺失、
128
+ `kid` 不在已验证的 keyring、签名钥已退役、载荷被篡改,都会拒绝该 feed,不会
129
+ 「验不过当没验」。默认行为是 warning + 回退到内置离线快照(exit 0);
130
+ **CI/流水线请设置 `CHANGEGUARD_FEED_STRICT=1`**,此时任何验签失败都会以 exit 1
131
+ 结束且禁止回退。keyring 与 feed 都可以用 `http(s)://` URL 分发(根签名本地校验,
132
+ 端点无法自证)。schema、原因码、轮换与生产密钥清单见 [`docs/feed.md`](docs/feed.md)。
133
+
134
+ ```bash
135
+ npm run feed:keygen -- --out .keys/root1 # 根钥(离线保管私钥)
136
+ npm run feed:keygen -- --out .keys/sign1 # 签名钥
137
+ npm run feed:keyring -- --root-key .keys/root1.private.pem --root-kid <kid> --keys signing-keys.json
138
+ npm run feed:sign -- --key .keys/sign1.private.pem --kid <kid> --since 2023-01-01
139
+ CHANGEGUARD_FEED_ROOT_KEYS=.keys/root1.public.json \
140
+ npx tsx src/cli.ts scan <repo> --feed .changeguard/feed.json --trusted-keys .changeguard/keyring.json
141
+ ```
142
+
143
+ > 仓库内已内置引导信任链(root 公钥 + 签名 keyring,2026-11-13 本地生成;根私钥
144
+ > 留在 git-ignored 的 `.keys/`,不入库)。面向外部用户前应按 `docs/feed.md` §7
145
+ > 在隔离环境重走密钥仪式并通过根钥轮换替换。
146
+
147
+ ## 控制台页面
148
+
149
+ | 页面 | 路由 | 功能 |
150
+ |---|---|---|
151
+ | 控制台 | `/` | 账户用量 / 立即扫描 / 扫描历史 / API Keys / 审计事件 |
152
+ | 设置 | `/settings` | 租户改名 · 默认扫描参数(回溯天数 1–730 / 在线模式,持久化 DB)· 通知渠道状态 + 测试发送按钮 · 快捷入口 |
153
+ | 手册 | `/manuals` | 产品介绍手册 + 使用手册;支持跨手册全局搜索(输入即时过滤);手册页右下角浮动搜索框支持 TreeWalker 高亮定位(`?q=` 深链自动定位) |
154
+ | 套餐 | `/pricing` | 三档展示 + Stripe Checkout(零 SDK,`stripeCheckoutReady()` 自动判断)· 配额说明 |
155
+
156
+ ## 环境变量
157
+
158
+ 所有变量可放置在项目根 `.env`(启动时自动加载,已有系统环境变量优先)。示例见 `.env.example`。
159
+
160
+ | 分组 | 变量 | 说明 |
161
+ |---|---|---|
162
+ | **LLM(可选)** | `LLM_BASE_URL` `LLM_API_KEY` `LLM_MODEL` | 任意 OpenAI 兼容端点;不配即离线模板解释 |
163
+ | **GitHub App** | `GITHUB_APP_ID` `GITHUB_PRIVATE_KEY` `GITHUB_WEBHOOK_SECRET` `GITHUB_TOKEN` | 私钥支持 PEM 内容或文件路径;Webhook 验签必需 |
164
+ | **GitHub OAuth** | `GITHUB_OAUTH_CLIENT_ID` `GITHUB_OAUTH_CLIENT_SECRET` | 控制台 SSO 登录,可选 |
165
+ | **通知** | `SLACK_WEBHOOK_URL` `SMTP_URL` `EMAIL_TO` | SMTP 隐式 TLS,收件人逗号分隔 |
166
+ | **运行时** | `PORT` `CHANGEGUARD_DB_PATH` `CHANGEGUARD_CACHE_DIR` `CHANGEGUARD_SCAN_INTERVAL_HOURS` `CHANGEGUARD_SCHEDULED_REPOS` `CHANGEGUARD_LOG` `CHANGEGUARD_LOG_FORMAT` `CHANGEGUARD_AUDIT_RETENTION_DAYS` | DB 与缓存位置;定时扫描(0 关闭);`CHANGEGUARD_LOG=debug` 降阈值;`CHANGEGUARD_LOG_FORMAT=json` 输出 JSON 行(每行带 `requestId`/`tenantId`/`actor`,响应头 `X-Request-Id` 可回传追踪);审计日志保留天数(默认 90,0 关闭轮转) |
167
+ | **可观测性** | `CHANGEGUARD_METRICS_TOKEN` | 设置后开放 `GET /metrics`(Prometheus 文本格式,`Bearer` 或 `?token=` 鉴权);未设置时端点 404(fail-closed) |
168
+ | **签名 feed** | `CHANGEGUARD_FEED_KEYS` `CHANGEGUARD_FEED_ROOT_KEYS` `CHANGEGUARD_FEED_STRICT` | 签名 keyring(文件或 URL,优先级低于 `--trusted-keys`);额外根钥文件(与内置根钥合并);`=1` 时验签失败非零退出且禁止回退(CI 必用) |
169
+ | **控制台** | `CHANGEGUARD_CONSOLE_PASSWORD` `CHANGEGUARD_SESSION_SECRET` | 口令启用登录(默认锁);会话密钥建议生产必设,未设则每进程随机生成 |
170
+ | **安全开关** | `CHANGEGUARD_ALLOW_ANONYMOUS_CONSOLE` `CHANGEGUARD_ALLOW_UNSIGNED_WEBHOOK` `CHANGEGUARD_TRUST_PROXY` `CHANGEGUARD_SECURE_COOKIES` | 前两个仅本地开发使用,默认关闭(拒绝匿名控制台 / 拒绝未验签 webhook);后两个用于反向代理部署 |
171
+ | **Stripe 计费** | `STRIPE_WEBHOOK_SECRET` `STRIPE_SECRET_KEY` `STRIPE_PRICE_PRO` `STRIPE_PRICE_TEAM` | Webhook secret 是开关;两个付费档价格 ID 在 Stripe Dashboard 创建 |
172
+
173
+ ## 部署
174
+
175
+ **本地**:
176
+
177
+ ```bash
178
+ cp .env.example .env # 按需填写
179
+ npm run serve # http://localhost:8787
180
+ ```
181
+
182
+ **Docker 单机**:
183
+
184
+ ```bash
185
+ docker compose up -d # docker-compose.yml
186
+ ```
187
+
188
+ **Docker 多实例**:
189
+
190
+ ```bash
191
+ docker compose -f docker-compose.multi.yml up -d
192
+ ```
193
+
194
+ > 务必把 `.changeguard/`(DB + 缓存)与 `.env` 作为卷挂载;否则容器重建丢数据。镜像无原生编译步骤,构建快体积小。
195
+
196
+ ## 安全默认值(fail-closed)
197
+
198
+ 服务默认按「生产可用」的安全姿态启动,未配置凭据时**不会**放行:
199
+
200
+ | 项 | 默认行为 | 本地开发如何开启 |
201
+ |---|---|---|
202
+ | 控制台 / JSON API | 默认要求登录;既无口令也无 GitHub OAuth 时返回 503 并提示配置方式 | `CHANGEGUARD_ALLOW_ANONYMOUS_CONSOLE=1`(仅开发) |
203
+ | `POST /webhook` | 未设 `GITHUB_WEBHOOK_SECRET` 时一律 401 | `CHANGEGUARD_ALLOW_UNSIGNED_WEBHOOK=1`(仅开发) |
204
+ | 会话 Cookie | `CHANGEGUARD_SESSION_SECRET` 未设时按进程随机生成,重启即失效 | 固定设置 `CHANGEGUARD_SESSION_SECRET` |
205
+ | 登录 | 同一 IP 15 分钟内最多 10 次尝试,超出返回 429 + `Retry-After` | — |
206
+ | 响应头 | CSP / `X-Content-Type-Options` / `X-Frame-Options` / `Referrer-Policy` / `Permissions-Policy` | — |
207
+ | Cookie `Secure` | 直连 TLS 或 `CHANGEGUARD_TRUST_PROXY=1` 且 `X-Forwarded-Proto: https` 时自动加 | `CHANGEGUARD_SECURE_COOKIES=1` 强制开启 |
208
+
209
+ 反向代理部署时设置 `CHANGEGUARD_TRUST_PROXY=1`,否则限速会按代理 IP 聚合、Cookie 也不会带 `Secure`。
210
+
211
+ 本地最简启动(放行控制台与未验签 webhook):
212
+
213
+ ```bash
214
+ CHANGEGUARD_ALLOW_ANONYMOUS_CONSOLE=1 CHANGEGUARD_ALLOW_UNSIGNED_WEBHOOK=1 npm run serve
215
+ ```
216
+
217
+ ## Stripe 真实联调(测试模式)
218
+
219
+ 1. [Stripe Dashboard → Billing → Products](https://dashboard.stripe.com/test/products) 分别创建两个 Product(Pro / Team),每个 Product 创建一个 **Recurring** 价格(`recurring`,每月,任意金额),拿到 `price_xxx` 格式的价格 ID
220
+ 2. 测试模式拿到测试密钥:[API Keys](https://dashboard.stripe.com/test/apikeys) → `sk_test_xxx`(Secret Key)和 `whsec_xxx`(Webhook Signing Secret,需要在 [Webhooks](https://dashboard.stripe.com/test/webhooks) 添加 endpoint 并 Endpoint Secret)
221
+ 3. `.env` 里填上:
222
+ ```
223
+ STRIPE_SECRET_KEY=sk_test_xxx
224
+ STRIPE_PRICE_PRO=price_xxx
225
+ STRIPE_PRICE_TEAM=price_yyy
226
+ STRIPE_WEBHOOK_SECRET=whsec_xxx
227
+ ```
228
+ 4. 安装官方 Stripe CLI(npm 上没有官方包,请勿 `npx stripe`):
229
+
230
+ ```bash
231
+ # macOS
232
+ brew install stripe/stripe-cli/stripe
233
+ # Windows (Scoop)
234
+ scoop install stripe
235
+ # 其他平台:https://github.com/stripe/stripe-cli/releases 下载对应二进制并加入 PATH
236
+ ```
237
+
238
+ 然后启动本地转发:
239
+
240
+ ```bash
241
+ stripe login # 第一次用浏览器授权
242
+ stripe listen --forward-to localhost:8787/webhook/stripe
243
+ # 输出里有一个临时 webhook secret(whsec_…),Stripe Dashboard 里的 endpoint 用它
244
+ ```
245
+ 5. 启动服务后,浏览器访问 `/pricing`,点「升级到 Pro / Team」,Stripe 官方 Checkout 页面填测试卡号 `4242 4242 4242 4242`,完成支付
246
+ 6. 回到控制台 `/api/account` 可看到套餐已变(Stripe webhook 回调 → 自动 `setTenantPlan`)
247
+
248
+ ## 测试
249
+
250
+ ```bash
251
+ npm run typecheck # TypeScript strict 全量检查
252
+ npm test # vitest 全量(90+ 用例分三层)
253
+ ```
254
+
255
+ 测试分层:
256
+
257
+ | 文件 | 覆盖 |
258
+ |---|---|
259
+ | `tests/engine.test.ts` `analyzers.test.ts` `openapi-diff.test.ts` | 核心流水线(引擎规则 / 语言分析器 / OpenAPI diff) |
260
+ | `tests/phase3.test.ts` | 多租户 + 认证 |
261
+ | `tests/phase4.test.ts` | 计费 + Webhook |
262
+ | `tests/phase5.test.ts` | 设置功能(租户改名 + 默认扫描参数 + 通知测试) |
263
+ | `tests/manual-search.test.ts` | 手册搜索(路由层 + 搜索素材前提 + 脚本接线) |
264
+ | `tests/scan-e2e.test.ts` `note-parser.test.ts` `codemod.test.ts` `manifests.test.ts` | 单元 |
265
+
266
+ ## 文档
267
+
268
+ - 产品介绍手册:控制台 → 手册 或 [变更目录 `/manuals/product`]
269
+ - 使用手册:控制台 → 手册 或 [变更目录 `/manuals/usage`]
270
+ - 架构设计文档:[`docs/architecture.md`](docs/architecture.md)
271
+ - 签名变更 feed(schema / 规范化 / 轮换 / 回退):[`docs/feed.md`](docs/feed.md)
272
+
273
+ ## License
274
+
275
+ 本仓库采用双许可(dual license):
276
+
277
+ - **Apache-2.0** —— 独立 CLI 与扫描器:扫描核心、规则引擎、语言 analyzer、报告/通知、离线 seed 快照等。完整许可见 [LICENSE](LICENSE)。
278
+ - **专有(All rights reserved)** —— 托管服务端、计费、账号与租户存储、控制台、部署打包:`src/server/`、`src/store/`、Docker 相关文件。适用范围、保留权利与混合文件拆分原则见 [LICENSE-PROPRIETARY](LICENSE-PROPRIETARY)。
279
+
280
+ 不在 Apache-2.0 清单内的路径,一律以 `LICENSE-PROPRIETARY` 为准。npm 分发包仅含 Apache-2.0 部分(`package.json` 的 `files` 白名单排除了 `dist/server`、`dist/store`、`dist/cli-admin` 与 Docker 文件)。
281
+
282
+ ## 扩展厂商(数据驱动,零代码)
283
+
284
+ 厂商注册表是纯数据:每家厂商 = `data/providers/<id>.json` 一份 manifest,启动时严格校验(字段错误直接 fail-fast,错误信息带文件名与字段)。新增一家厂商**不需要改任何代码**:
285
+
286
+ 1. 写 `data/providers/<id>.json`(文件名必须等于 `id`,小写 slug):
287
+
288
+ ```json
289
+ {
290
+ "id": "acme",
291
+ "name": "Acme API",
292
+ "website": "https://acme.dev",
293
+ "packages": { "npm": ["acme-sdk"], "pypi": ["acme"], "go": ["github.com/acme/acme-go"] },
294
+ "hosts": ["api.acme.dev"],
295
+ "factories": { "javascript": ["createAcmeClient"] },
296
+ "sources": {
297
+ "changelog": { "url": "https://acme.dev/changelog", "kind": "html" },
298
+ "githubReleases": [
299
+ { "ecosystem": "npm", "language": "javascript", "owner": "acme", "repo": "acme-node" }
300
+ ]
301
+ }
302
+ }
303
+ ```
304
+
305
+ 2. (可选)放 `data/changes/<id>.seed.json` 提供离线变更记录(无种子时离线无 finding,`--online` 仍可抓 Releases)。
306
+ 3. (可选)放 `data/openapi/<id>/meta.json` + 快照对,启用 OpenAPI diff。
307
+
308
+ 随即生效:清单识别、Tree-sitter 调用点规则、host 匹配、在线变更采集全部自动覆盖新厂商。规则见 `src/providers/registry.ts` 的 `validateProviderManifest`(生态限 npm/pypi/go,语言限 javascript/python/go)。
309
+
310
+ ## 限制 / 未来
311
+
312
+ - Go 语言:检测链路已闭环(go.mod 清单 → Tree-sitter 调用点 → 引擎规则 → 报告,e2e 钉死);codemod 自动改写仅覆盖 JS/TS/Python,Go 只报不改
313
+ - 可观测性:`/metrics`(Prometheus 文本格式)提供扫描/LLM/队列指标;结构化日志(JSON 行 + requestId 串联)已有;仍无分布式 tracing
314
+ - 厂商:注册表已数据驱动(见上节);语言 analyzer 仍是 JS/TS/Python/Go 四条固定规则管道
315
+
316
+ ---
317
+
318
+ `npm run build` → 二进制产物在 `dist/cli.js`,`npm publish` 可发布到 npm。
package/SECURITY.md ADDED
@@ -0,0 +1,40 @@
1
+ # 安全政策
2
+
3
+ ## 报告漏洞
4
+
5
+ 如果你发现本项目的安全问题,请发送邮件至 **security@changeguard.dev**(发布前请替换为真实可达邮箱),或通过代码托管平台的安全通告功能私下报告。
6
+
7
+ **请不要**在公开 issue 中披露安全漏洞细节。
8
+
9
+ ## 我们承诺
10
+
11
+ | 项 | 承诺 |
12
+ |---|---|
13
+ | 确认收到 | 3 个工作日内 |
14
+ | 初步评估 | 7 个工作日内给出影响范围与修复计划 |
15
+ | 修复时限 | 高危 30 天内;中危 90 天内;低危按版本节奏 |
16
+ | 披露协调 | 修复发布后与你协商公开披露时间 |
17
+
18
+ ## 范围内
19
+
20
+ - 本仓库代码(CLI、扫描器、规则引擎、服务端)
21
+ - 官方发布的 npm 包与构建产物
22
+ - 签名变更 feed 的验签逻辑(信任链绕过即高危)
23
+
24
+ ## 范围外
25
+
26
+ - 第三方依赖自身的漏洞(请报告给上游;我们会在收到安全通告后跟进升级)
27
+ - 社会工程学攻击
28
+ - 需要物理接触设备的攻击
29
+
30
+ ## 安全设计说明(审阅者参考)
31
+
32
+ - **fail-closed 默认**:未配置的端点不暴露(如 `/metrics` 未设 token 时 404);签名校验失败即拒绝;控制台未配置访问控制时保持锁定姿态。
33
+ - **密钥卫生**:API 密钥仅存 `sha256` 哈希;会话为 HMAC 签名 Cookie,无服务端会话存储;私钥生成脚本拒绝写入未被 git 忽略的路径。
34
+ - **变更数据完整性**:签名 feed 使用 ed25519;根钥轮换走 keyring 机制(见 `docs/feed.md`)。
35
+ - **判定确定性**:影响判定只由确定性规则完成,LLM 仅生成文字解释,不参与判定(`src/llm/explanation.ts` 架构约束)。
36
+
37
+ ## 已知边界
38
+
39
+ - 开发依赖链当前有 1 个无修复版本的 moderate 级 ReDoS 通告(minimatch,eslint 传递依赖,不随发布产物分发)。
40
+ - 单机 SQLite 单写者约束:多实例部署需只读副本,见部署文档。
@@ -0,0 +1,87 @@
1
+ [
2
+ {
3
+ "id": "openai-edits-sunset-2024-01",
4
+ "providerId": "openai",
5
+ "kind": "breaking",
6
+ "title": "Edits API (POST /v1/edits) removed",
7
+ "summary": "The legacy Edits endpoint and its SDK helpers were shut down on 2024-01-04. The text-davinci-edit-001 / code-davinci-edit-001 models are no longer served.",
8
+ "body": "OpenAI retired the Edits API. Migrate edit-style workflows to Chat Completions with gpt-4o / gpt-4o-mini using editing prompts, or use the Responses API.",
9
+ "source": "release-note",
10
+ "sourceUrl": "https://platform.openai.com/docs/changelog",
11
+ "date": "2024-01-04",
12
+ "operations": [
13
+ {
14
+ "method": "POST",
15
+ "pathTemplate": "/v1/edits",
16
+ "scope": "operation",
17
+ "sdkPaths": {
18
+ "javascript": ["edits.create"],
19
+ "python": ["edits.create"]
20
+ }
21
+ },
22
+ {
23
+ "scope": "request-field",
24
+ "target": "instruction",
25
+ "detail": "removed with endpoint",
26
+ "sdkPaths": {
27
+ "javascript": ["edits.create"],
28
+ "python": ["edits.create"]
29
+ }
30
+ },
31
+ {
32
+ "scope": "enum",
33
+ "target": "model",
34
+ "detail": "removed:text-davinci-edit-001,code-davinci-edit-001",
35
+ "sdkPaths": {
36
+ "javascript": ["edits.create"],
37
+ "python": ["edits.create"]
38
+ }
39
+ }
40
+ ],
41
+ "renames": [],
42
+ "versions": [
43
+ { "ecosystem": "npm", "package": "openai", "removedIn": "5.0.0" },
44
+ { "ecosystem": "pypi", "package": "openai", "removedIn": "2.0.0" }
45
+ ],
46
+ "migration": "Replace client.edits.create({ model: 'text-davinci-edit-001', input, instruction }) with client.chat.completions.create({ model: 'gpt-4o-mini', messages: [{ role: 'user', content: `${instruction}\\n\\n${input}` }] }). Update raw HTTP callers from POST https://api.openai.com/v1/edits to POST https://api.openai.com/v1/chat/completions.",
47
+ "parserSignals": ["changelog:endpoint-sunset", "manual:curated-seed"],
48
+ "confidence": "high"
49
+ },
50
+ {
51
+ "id": "openai-legacy-completions-models-2024-01",
52
+ "providerId": "openai",
53
+ "kind": "breaking",
54
+ "title": "Legacy Completions models text-davinci-003 retired",
55
+ "summary": "The text-davinci-003 / text-davinci-002 models served via POST /v1/completions were retired on 2024-01-04.",
56
+ "body": "Legacy completion models are no longer available. Use a current model through Chat Completions instead.",
57
+ "source": "release-note",
58
+ "sourceUrl": "https://platform.openai.com/docs/changelog",
59
+ "date": "2024-01-04",
60
+ "operations": [
61
+ {
62
+ "method": "POST",
63
+ "pathTemplate": "/v1/completions",
64
+ "scope": "operation",
65
+ "sdkPaths": {
66
+ "javascript": ["completions.create"],
67
+ "python": ["completions.create"]
68
+ }
69
+ },
70
+ {
71
+ "scope": "enum",
72
+ "target": "model",
73
+ "detail": "removed:text-davinci-003,text-davinci-002,text-davinci-001,GPTTextDavinci003,GPTTextDavinci002",
74
+ "sdkPaths": {
75
+ "javascript": ["completions.create"],
76
+ "python": ["completions.create"],
77
+ "go": ["CreateChatCompletion", "CreateCompletion"]
78
+ }
79
+ }
80
+ ],
81
+ "renames": [],
82
+ "versions": [],
83
+ "migration": "Move from completions.create({ model: 'text-davinci-003', prompt }) to chat.completions.create({ model: 'gpt-4o-mini', messages: [{ role: 'user', content: prompt }] }). In go-openai use ChatCompletionRequest with GPT4oMini / GPT35Turbo.",
84
+ "parserSignals": ["changelog:model-retirement", "manual:curated-seed"],
85
+ "confidence": "high"
86
+ }
87
+ ]
@@ -0,0 +1,42 @@
1
+ [
2
+ {
3
+ "id": "shopify-admin-rest-sunset-2025-04",
4
+ "providerId": "shopify",
5
+ "kind": "breaking",
6
+ "title": "Admin REST API sunset: migrate to GraphQL Admin API (2025-04)",
7
+ "summary": "Shopify removed the remaining Admin REST API surface in API version 2025-04. REST resource clients such as rest.Product.all/find/count are removed from the SDKs; the GraphQL Admin API must be used instead.",
8
+ "body": "As of 2025-04, REST Admin endpoints are no longer available and SDK resource helpers were deleted. Use the GraphQL client and product queries/mutations.",
9
+ "source": "changelog",
10
+ "sourceUrl": "https://shopify.dev/changelog",
11
+ "date": "2025-01-07",
12
+ "operations": [
13
+ {
14
+ "method": "GET",
15
+ "pathTemplate": "/admin/api/{version}/products.json",
16
+ "scope": "operation",
17
+ "sdkPaths": {
18
+ "javascript": ["rest.Product.all", "rest.Product.find", "rest.Product.count", "rest.Product.save", "rest.Product.delete"],
19
+ "python": ["Product.find", "Product.all", "Product.count", "Product.save"],
20
+ "go": ["Product.List", "Product.Find", "Product.Create"]
21
+ }
22
+ },
23
+ {
24
+ "scope": "sdk-method",
25
+ "target": "rest resource namespace",
26
+ "detail": "entire shopify.rest.* REST namespace removed",
27
+ "sdkPaths": {
28
+ "javascript": ["rest.*"],
29
+ "python": []
30
+ }
31
+ }
32
+ ],
33
+ "renames": [],
34
+ "versions": [
35
+ { "ecosystem": "npm", "package": "@shopify/shopify-api", "removedIn": "10.0.0" },
36
+ { "ecosystem": "pypi", "package": "shopifyapi", "removedIn": "13.0.0" }
37
+ ],
38
+ "migration": "Replace shopify.rest.Product.all(session) with a GraphQL Admin query: POST /admin/api/2025-04/graphql.json with { products(first: 50) { edges { node { id title } } } }. In the JS SDK use shopify.clients.Graphql; in Python use the GraphQL endpoint with shopify tokens rather than shopifyapi.Product.",
39
+ "parserSignals": ["changelog:api-version-sunset", "manual:curated-seed"],
40
+ "confidence": "high"
41
+ }
42
+ ]
@@ -0,0 +1,60 @@
1
+ [
2
+ {
3
+ "id": "stripe-charges-sources-sunset-2024",
4
+ "providerId": "stripe",
5
+ "kind": "breaking",
6
+ "title": "Legacy Charges / Sources payment flow removed",
7
+ "summary": "Creating charges directly with card/source tokens (Charges API + Sources) is no longer supported. The PaymentIntents API is the only supported integration path.",
8
+ "body": "Charges.create with source, and the SetSource parameter helpers in the Go SDK, were removed in the current major SDK lines. Use PaymentIntent confirm flows instead.",
9
+ "source": "changelog",
10
+ "sourceUrl": "https://docs.stripe.com/changelog",
11
+ "date": "2024-04-11",
12
+ "operations": [
13
+ {
14
+ "method": "POST",
15
+ "pathTemplate": "/v1/charges",
16
+ "scope": "operation",
17
+ "sdkPaths": {
18
+ "javascript": ["charges.create", "charges.retrieve", "charges.list", "charges.update", "charges.capture"],
19
+ "python": ["Charge.create", "Charge.retrieve", "Charge.list", "Charge.modify"],
20
+ "go": ["charge.New", "charge.Get", "charge.List"]
21
+ }
22
+ },
23
+ {
24
+ "scope": "sdk-method",
25
+ "target": "SetSource",
26
+ "detail": "ChargeParams.SetSource removed; use PaymentIntentParams.SetPaymentMethod",
27
+ "sdkPaths": {
28
+ "go": ["SetSource"]
29
+ }
30
+ },
31
+ {
32
+ "scope": "sdk-method",
33
+ "target": "ChargeParams",
34
+ "detail": "ChargeParams source field removed",
35
+ "sdkPaths": {
36
+ "go": ["ChargeParams"]
37
+ }
38
+ },
39
+ {
40
+ "scope": "parameter",
41
+ "target": "source",
42
+ "detail": "replaced by payment_method / confirm PaymentIntent flow",
43
+ "sdkPaths": {
44
+ "javascript": ["charges.create", "charges.update"],
45
+ "python": ["Charge.create", "Charge.modify"],
46
+ "go": ["SetSource"]
47
+ }
48
+ }
49
+ ],
50
+ "renames": [],
51
+ "versions": [
52
+ { "ecosystem": "npm", "package": "stripe", "removedIn": "15.0.0" },
53
+ { "ecosystem": "pypi", "package": "stripe", "removedIn": "6.0.0" },
54
+ { "ecosystem": "go", "package": "github.com/stripe/stripe-go/v78", "removedIn": "v79.0.0" }
55
+ ],
56
+ "migration": "Migrate from Charges to PaymentIntents: 1) create a PaymentIntent server-side, 2) collect card details with Stripe.js elements, 3) confirm the payment. Replace stripe.charges.create({ source: tok }) with paymentIntents.create({ amount, currency, payment_method, confirm: true }). In Go use paymentintent.New with PaymentIntentParams and SetPaymentMethod.",
57
+ "parserSignals": ["changelog:api-sunset", "manual:curated-seed"],
58
+ "confidence": "high"
59
+ }
60
+ ]