universal-dev-standards 5.1.0-beta.7 → 5.1.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 (50) hide show
  1. package/README.md +6 -0
  2. package/bin/uds.js +2 -0
  3. package/bundled/ai/standards/translation-lifecycle-standards.ai.yaml +145 -0
  4. package/bundled/core/translation-lifecycle-standards.md +162 -0
  5. package/bundled/locales/zh-CN/CHANGELOG.md +32 -3
  6. package/bundled/locales/zh-CN/README.md +1 -1
  7. package/bundled/locales/zh-CN/core/anti-hallucination.md +22 -3
  8. package/bundled/locales/zh-CN/core/anti-sycophancy-prompting.md +192 -0
  9. package/bundled/locales/zh-CN/core/capability-declaration.md +123 -0
  10. package/bundled/locales/zh-CN/core/circuit-breaker.md +106 -0
  11. package/bundled/locales/zh-CN/core/dual-phase-output.md +103 -0
  12. package/bundled/locales/zh-CN/core/failure-source-taxonomy.md +99 -0
  13. package/bundled/locales/zh-CN/core/frontend-design-standards.md +289 -0
  14. package/bundled/locales/zh-CN/core/health-check-standards.md +144 -0
  15. package/bundled/locales/zh-CN/core/immutability-first.md +96 -0
  16. package/bundled/locales/zh-CN/core/packaging-standards.md +224 -0
  17. package/bundled/locales/zh-CN/core/recovery-recipe-registry.md +146 -0
  18. package/bundled/locales/zh-CN/core/retry-standards.md +131 -0
  19. package/bundled/locales/zh-CN/core/security-decision.md +104 -0
  20. package/bundled/locales/zh-CN/core/skill-standard-alignment-check.md +112 -0
  21. package/bundled/locales/zh-CN/core/standard-admission-criteria.md +104 -0
  22. package/bundled/locales/zh-CN/core/standard-lifecycle-management.md +116 -0
  23. package/bundled/locales/zh-CN/core/timeout-standards.md +117 -0
  24. package/bundled/locales/zh-CN/core/token-budget.md +108 -0
  25. package/bundled/locales/zh-CN/core/translation-lifecycle-standards.md +159 -0
  26. package/bundled/locales/zh-TW/CHANGELOG.md +32 -3
  27. package/bundled/locales/zh-TW/README.md +1 -1
  28. package/bundled/locales/zh-TW/core/anti-sycophancy-prompting.md +8 -0
  29. package/bundled/locales/zh-TW/core/capability-declaration.md +111 -0
  30. package/bundled/locales/zh-TW/core/circuit-breaker.md +111 -0
  31. package/bundled/locales/zh-TW/core/dual-phase-output.md +132 -0
  32. package/bundled/locales/zh-TW/core/failure-source-taxonomy.md +146 -0
  33. package/bundled/locales/zh-TW/core/frontend-design-standards.md +460 -0
  34. package/bundled/locales/zh-TW/core/health-check-standards.md +144 -0
  35. package/bundled/locales/zh-TW/core/immutability-first.md +159 -0
  36. package/bundled/locales/zh-TW/core/recovery-recipe-registry.md +146 -0
  37. package/bundled/locales/zh-TW/core/retry-standards.md +140 -0
  38. package/bundled/locales/zh-TW/core/security-decision.md +120 -0
  39. package/bundled/locales/zh-TW/core/skill-standard-alignment-check.md +112 -0
  40. package/bundled/locales/zh-TW/core/standard-admission-criteria.md +104 -0
  41. package/bundled/locales/zh-TW/core/standard-lifecycle-management.md +116 -0
  42. package/bundled/locales/zh-TW/core/timeout-standards.md +117 -0
  43. package/bundled/locales/zh-TW/core/token-budget.md +143 -0
  44. package/bundled/locales/zh-TW/core/translation-lifecycle-standards.md +159 -0
  45. package/package.json +2 -1
  46. package/src/commands/check.js +6 -0
  47. package/src/commands/init.js +6 -0
  48. package/src/commands/update.js +6 -0
  49. package/src/utils/detect-self-adoption.js +173 -0
  50. package/standards-registry.json +15 -4
@@ -0,0 +1,224 @@
1
+ ---
2
+ source: ../../../core/packaging-standards.md
3
+ source_version: 1.0.0
4
+ translation_version: 1.0.0
5
+ last_synced: 2026-04-20
6
+ status: current
7
+ ---
8
+
9
+ # 打包标准
10
+
11
+ > **语言**: [English](../../../core/packaging-standards.md) | 简体中文
12
+
13
+ **版本**: 1.0.0
14
+ **最后更新**: 2026-04-15
15
+ **适用性**: 使用 UDS/DevAP 工具链的项目
16
+ **范围**: 通用 (Universal)
17
+
18
+ ---
19
+
20
+ ## 目的
21
+
22
+ 本标准定义一套基于 Recipe 的打包框架,让用户项目可在 `.devap/packaging.yaml` 中声明打包目标(target)。UDS 负责提供 Recipe 定义与内置 Recipe 库;DevAP 则在 pipeline 中执行编排。
23
+
24
+ 框架的关注点分离如下:
25
+ - **用户项目**:声明「打包什么」(targets + 配置覆盖)
26
+ - **UDS**:定义「如何打包」(Recipe 结构 + 内置 Recipes)
27
+ - **DevAP**:执行「何时打包」(在 Review 与 Deploy 之间的 pipeline 阶段)
28
+
29
+ ---
30
+
31
+ ## 核心原则
32
+
33
+ | 原则 | 说明 |
34
+ |------|------|
35
+ | **Recipe-based** | 每个打包目标都参照一个具名 Recipe;不在 pipeline YAML 中编写临时脚本 |
36
+ | **声明式 targets** | 项目在 `.devap/packaging.yaml` 中声明 targets;DevAP 负责解析与执行 |
37
+ | **可定制** | 四个定制层允许配置覆盖、Hook 注入、自定义 Recipe 及 Escape Hatch |
38
+ | **整合至 Pipeline** | 打包作为独立阶段运行于 VibeOps pipeline 的 Review 与 Deploy 之间 |
39
+
40
+ ---
41
+
42
+ ## Recipe 结构
43
+
44
+ Recipe 是定义如何打包项目的 YAML 文件,字段定义如下:
45
+
46
+ ```yaml
47
+ # Recipe: <name>.yaml
48
+ name: <string> # 必填 — 唯一标识符(kebab-case)
49
+ description: <string> # 选填 — 人类可读描述
50
+ requires: # 选填 — 执行前必须存在的文件
51
+ - <file-path>
52
+ steps: # 必填 — 有序的构建/打包步骤清单
53
+ - run: <shell-command>
54
+ description: <string> # 选填 — 步骤描述
55
+ config: # 选填 — 默认配置值(可被用户项目覆盖)
56
+ <key>: <value>
57
+ hooks: # 选填 — 生命周期 hooks(~ 表示不执行)
58
+ preBuild: ~
59
+ postBuild: ~
60
+ prePublish: ~
61
+ postPublish: ~
62
+ ```
63
+
64
+ ### 必填与选填字段
65
+
66
+ | 字段 | 必填 | 说明 |
67
+ |------|------|------|
68
+ | `name` | 是 | 唯一标识符,kebab-case 格式 |
69
+ | `steps` | 是 | 至少需要一个步骤 |
70
+ | `description` | 否 | 人类可读描述 |
71
+ | `requires` | 否 | 前置条件文件检查 |
72
+ | `config` | 否 | 默认配置值;所有 key 均可被用户项目覆盖 |
73
+ | `hooks` | 否 | 生命周期 hook 插入点;`~` 表示不执行 |
74
+
75
+ ### 步骤变量
76
+
77
+ 配置值与运行时上下文可在 `run` 命令中使用 `{variable}` 占位符:
78
+
79
+ | 变量 | 来源 | 示例 |
80
+ |------|------|------|
81
+ | `{registry}` | `config.registry` | `ghcr.io` |
82
+ | `{name}` | `package.json#name` 或 `config.name` | `my-app` |
83
+ | `{version}` | `package.json#version` 或 `config.version` | `1.2.3` |
84
+ | `{platforms}` | `config.platforms` | `linux/amd64,linux/arm64` |
85
+ | `{output_dir}` | `config.output_dir` | `dist/installers` |
86
+
87
+ ---
88
+
89
+ ## 内置 Recipes
90
+
91
+ UDS 随附四个内置 Recipe,位于 `recipes/` 目录:
92
+
93
+ | Recipe | 文件 | 使用场景 |
94
+ |--------|------|----------|
95
+ | `npm-library` | `recipes/npm-library.yaml` | 不含执行入口的 npm 包 |
96
+ | `npm-cli` | `recipes/npm-cli.yaml` | 含 `bin` 字段的 npm 包(CLI 工具) |
97
+ | `docker-service` | `recipes/docker-service.yaml` | Docker 容器镜像构建与推送 |
98
+ | `windows-installer` | `recipes/windows-installer.yaml` | Windows 安装包(.msi / .exe)通过用户脚本 |
99
+
100
+ ### 选择 Recipe 的决策流程
101
+
102
+ ```
103
+ 产出物是 npm 包吗?
104
+ ├── 是 → package.json 是否含有 "bin" 字段?
105
+ │ ├── 是 → npm-cli
106
+ │ └── 否 → npm-library
107
+ └── 否 → 产出物是容器镜像吗?
108
+ ├── 是 → docker-service
109
+ └── 否 → 产出物是 Windows 安装包吗?
110
+ ├── 是 → windows-installer
111
+ └── 否 → 编写自定义 Recipe(参见定制层)
112
+ ```
113
+
114
+ ---
115
+
116
+ ## 定制层
117
+
118
+ 需要偏离内置 Recipe 默认值的项目,应使用最低适用层:
119
+
120
+ | 层级 | 机制 | 使用时机 |
121
+ |------|------|----------|
122
+ | **L1 — 配置覆盖** | `.devap/packaging.yaml` 中的 `config:` 块 | 更改默认值(registry URL、tag、输出目录)|
123
+ | **L2 — Hook 注入** | `.devap/packaging.yaml` 中的 `hooks:` 块 | 在构建或发布前后执行额外命令 |
124
+ | **L3 — 自定义 Recipe** | 项目 `.devap/recipes/` 中的新 `.yaml` 文件 | 完全不同的构建流程;内置 Recipe 不适用 |
125
+ | **L4 — Escape Hatch** | target 定义中以 `script:` 替代 `recipe:` | 原始 shell 脚本,无合适的 Recipe 抽象 |
126
+
127
+ ### L1 示例 — 配置覆盖
128
+
129
+ ```yaml
130
+ # .devap/packaging.yaml
131
+ targets:
132
+ - name: publish-npm
133
+ recipe: npm-library
134
+ config:
135
+ registry: https://npm.pkg.github.com
136
+ access: restricted
137
+ tag: beta
138
+ ```
139
+
140
+ ### L2 示例 — Hook 注入
141
+
142
+ ```yaml
143
+ # .devap/packaging.yaml
144
+ targets:
145
+ - name: docker-push
146
+ recipe: docker-service
147
+ hooks:
148
+ postPush: |
149
+ curl -X POST https://hooks.example.com/deploy-notify \
150
+ -d "{\"version\": \"{version}\"}"
151
+ ```
152
+
153
+ ### L3 示例 — 自定义 Recipe
154
+
155
+ ```yaml
156
+ # .devap/recipes/electron-app.yaml
157
+ name: electron-app
158
+ description: 构建 Electron 桌面应用程序
159
+ requires:
160
+ - package.json
161
+ - electron-builder.yml
162
+ steps:
163
+ - run: npm run build
164
+ - run: npx electron-builder --publish never
165
+ config:
166
+ output_dir: dist
167
+ ```
168
+
169
+ ### L4 示例 — Escape Hatch
170
+
171
+ ```yaml
172
+ # .devap/packaging.yaml
173
+ targets:
174
+ - name: legacy-bundle
175
+ script: |
176
+ ./scripts/legacy-bundle.sh
177
+ mv output/ dist/bundle/
178
+ ```
179
+
180
+ ---
181
+
182
+ ## 打包验收标准
183
+
184
+ 当以下**所有**条件均满足时,打包执行视为**成功**:
185
+
186
+ | 标准 | 阈值 | 备注 |
187
+ |------|------|------|
188
+ | 所有 `requires` 文件存在 | 100% | 在任何步骤执行前检查 |
189
+ | 所有步骤以 exit code 0 结束 | 100% | 任何非零 exit 使执行失败 |
190
+ | `postBuild` 产出物存在 | 存在于预期路径 | 构建步骤后由 DevAP 验证 |
191
+ | Hook 命令以 exit code 0 结束 | 100% | Hook 失败会传播为步骤失败 |
192
+ | 已发布产出物可被取回 | HTTP 200 / registry 查询成功 | 由 DevAP 在发布后进行 smoke check |
193
+
194
+ ### 失败处理
195
+
196
+ | 失败类型 | 行动 | 可重试? |
197
+ |----------|------|----------|
198
+ | `requires` 文件缺失 | 立即失败,报告缺失路径 | 否 |
199
+ | 步骤非零 exit | 立即失败,若已定义则执行 `postBuild` hook | 可配置(默认:否)|
200
+ | Hook 非零 exit | 立即失败 | 否 |
201
+ | 发布无法连接 | 以指数退避重试最多 3 次 | 是(3×)|
202
+
203
+ ---
204
+
205
+ ## 相关标准
206
+
207
+ - [部署标准](deployment-standards.md) — 打包后的部署阶段
208
+ - [Pipeline 整合标准](pipeline-integration-standards.md) — CI/CD pipeline 配置
209
+ - [Check-in 标准](checkin-standards.md) — 打包前的质量关卡
210
+ - [版本控制标准](versioning.md) — 包产出物使用的版本号
211
+
212
+ ---
213
+
214
+ ## 版本历史
215
+
216
+ | 版本 | 日期 | 变更 |
217
+ |------|------|------|
218
+ | 1.0.0 | 2026-04-15 | 初始发行 — XSPEC-034 Phase 1 |
219
+
220
+ ---
221
+
222
+ ## 许可证
223
+
224
+ 本标准以 [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) 许可发布。
@@ -0,0 +1,146 @@
1
+ ---
2
+ source: ../../../core/recovery-recipe-registry.md
3
+ source_version: 1.0.0
4
+ translation_version: 1.0.0
5
+ last_synced: 2026-04-20
6
+ status: current
7
+ ---
8
+
9
+ # 恢复配方注册表标准
10
+
11
+ > **语言**: [English](../../../core/recovery-recipe-registry.md) | 简体中文
12
+
13
+ **版本**: 1.0.0
14
+ **最后更新**: 2026-04-16
15
+ **适用范围**: 所有 Agent 执行恢复逻辑
16
+ **Scope**: universal
17
+ **来源**: XSPEC-046(claw-code ROADMAP Phase 3 Recovery Recipes,DEC-035)
18
+ **依赖**: failure-source-taxonomy(XSPEC-045)
19
+
20
+ ---
21
+
22
+ ## 目的
23
+
24
+ 恢复配方注册表:将分散的恢复逻辑统一为 YAML 可配置的 Recipe,以 `failureSource` 为匹配键。
25
+
26
+ 各模块(Fix Loop、Circuit Breaker、Guardian 自动修复、Staging 重试)的恢复逻辑统一为可外部化的 Recovery Recipe 格式。每个 Recipe 通过 `failureSource`(XSPEC-045)匹配触发条件,选择对应的恢复策略,并定义升级路径(escalation)。无匹配 Recipe 时 fallback 到现有行为(向后兼容)。
27
+
28
+ ---
29
+
30
+ ## 核心规范
31
+
32
+ - 每个 Recovery Recipe 必须有唯一 ID(`RR-NNN` 格式)
33
+ - `match.failure_source` 必须是 failure-source-taxonomy 中定义的 8 类之一
34
+ - `escalation.on_exhaust` 必须定义,不得无限循环(如 escalation 指向自身)
35
+ - 无匹配 Recipe 时,系统必须 fallback 到现有默认行为(不得抛出错误)
36
+ - 用户自定义 Recipe 优先于内置 Recipe(同 `failureSource` 时,用户配置的先匹配)
37
+ - Recipe config 格式错误时 fallback 到策略默认值(不中断执行)
38
+
39
+ ---
40
+
41
+ ## 6 个内置恢复策略
42
+
43
+ ### `fix_loop`
44
+
45
+ - **描述**:注入结构化错误反馈,重试任务(现有 Fix Loop)
46
+ - **默认 config**:`max_attempts: 3`, `budget_usd: 0.50`
47
+ - **最适合**:`compilation`, `test_failure`
48
+
49
+ ### `circuit_breaker`
50
+
51
+ - **描述**:三态断路器保护(XSPEC-036),连续失败后开路避免雪崩
52
+ - **默认 config**:`failure_threshold: 3`, `cooldown_ms: 30000`
53
+ - **最适合**:`tool_failure`, `prompt_delivery`
54
+
55
+ ### `rebase_and_retry`
56
+
57
+ - **描述**:先执行 git rebase 同步基准分支,再重试任务 / 迭代
58
+ - **默认 config**:`max_attempts: 1`, `base_branch: "main"`
59
+ - **最适合**:`branch_divergence`
60
+ - **依赖**:XSPEC-047 Branch Drift Detection
61
+
62
+ ### `model_switch`
63
+
64
+ - **描述**:切换至备用模型后重试
65
+ - **默认 config**:`fallback_models: [...]`, `max_attempts: 2`
66
+ - **最适合**:`model_degradation`, `prompt_delivery`
67
+
68
+ ### `degraded_mode`
69
+
70
+ - **描述**:以降级模式继续执行(如:跳过质量验证、以部分结果继续)
71
+ - **结果状态**:`done_with_concerns`
72
+ - **最适合**:`resource_exhaustion`, `model_degradation`
73
+
74
+ ### `human_checkpoint`
75
+
76
+ - **描述**:暂停执行,等待人工介入(提供失败细节供判断)
77
+ - **最适合**:`policy_violation`, `branch_divergence`
78
+ - **备注**:所有其他策略的最终升级路径
79
+
80
+ ---
81
+
82
+ ## Recipe YAML 格式
83
+
84
+ ```yaml
85
+ id: RR-NNN # 必填,唯一标识符
86
+ name: string # 必填,可读名称
87
+ match: # 必填
88
+ failure_source: <FailureSource> # 必填
89
+ severity: [critical, high, ...] # 选填;省略表示匹配所有 severity
90
+ strategy: <RecoveryStrategy> # 必填
91
+ config: {} # 选填;覆盖策略默认值
92
+ escalation: # 必填
93
+ on_exhaust: <RecoveryStrategy> # 必填;不得指向自身
94
+ message: string # 选填;升级时的通知消息
95
+ ```
96
+
97
+ ---
98
+
99
+ ## 5 个默认 Recipe
100
+
101
+ | ID | 名称 | 匹配条件 | 策略 | 升级路径 |
102
+ |----|------|----------|------|---------|
103
+ | `RR-001` | Fix Loop for Compilation Errors | `compilation` | `fix_loop`(3次, $0.50) | `human_checkpoint` |
104
+ | `RR-002` | Fix Loop for Test Failures | `test_failure` | `fix_loop`(3次, $0.50) | `human_checkpoint` |
105
+ | `RR-003` | Model Switch for Degradation | `model_degradation` | `model_switch`(2次) | `degraded_mode` |
106
+ | `RR-004` | Rebase for Branch Divergence | `branch_divergence` | `rebase_and_retry`(1次) | `human_checkpoint`(需人工解决冲突) |
107
+ | `RR-005` | Degraded Mode for Resource Exhaustion | `resource_exhaustion` | `degraded_mode` | `human_checkpoint` |
108
+
109
+ ---
110
+
111
+ ## 类型定义
112
+
113
+ ### RecoveryStrategy
114
+
115
+ ```
116
+ fix_loop | circuit_breaker | rebase_and_retry | model_switch | degraded_mode | human_checkpoint
117
+ ```
118
+
119
+ ### RecoveryRecipe
120
+
121
+ | 字段 | 类型 | 必填 |
122
+ |------|------|------|
123
+ | `id` | `string`(RR-NNN 格式) | 是 |
124
+ | `name` | `string` | 是 |
125
+ | `match.failure_source` | `FailureSource` | 是 |
126
+ | `match.severity` | `string[]`(可选) | 否 |
127
+ | `strategy` | `RecoveryStrategy` | 是 |
128
+ | `config` | `object`(可选) | 否 |
129
+ | `escalation.on_exhaust` | `RecoveryStrategy` | 是 |
130
+ | `escalation.message` | `string`(可选) | 否 |
131
+
132
+ ---
133
+
134
+ ## 集成点
135
+
136
+ ### DevAP
137
+
138
+ - `packages/core/src/types.ts` — `RecoveryRecipe` / `RecoveryStrategy` type
139
+ - `packages/core/src/recovery-registry.ts` — Registry 实现与默认 recipe
140
+ - `packages/core/src/orchestrator.ts` — fix loop 前查询 Registry
141
+
142
+ ### VibeOps
143
+
144
+ - `src/types/index.ts` — 独立定义 `RecoveryRecipe`(AGPL 隔离)
145
+ - `src/runner/recovery-registry.ts` — 独立实现
146
+ - `recovery-recipes.yaml` — 默认 recipe 配置
@@ -0,0 +1,131 @@
1
+ ---
2
+ source: ../../../core/retry-standards.md
3
+ source_version: 1.0.0
4
+ translation_version: 1.0.0
5
+ last_synced: 2026-04-20
6
+ status: current
7
+ ---
8
+
9
+ # 重试策略标准
10
+
11
+ > **语言**: [English](../../../core/retry-standards.md) | 简体中文
12
+
13
+ **版本**: 1.0.0
14
+ **最后更新**: 2026-04-17
15
+ **状态**: Trial(到期 2026-10-17)
16
+ **适用范围**: universal
17
+ **来源**: XSPEC-067(DEC-043 Wave 1 可靠性套件)
18
+
19
+ ---
20
+
21
+ ## 目的
22
+
23
+ 重试策略标准:指数退避加抖动、重试上限、依 failure-source 分类的重试规则。
24
+
25
+ 延伸既有 circuit-breaker 与 failure-source-taxonomy,补齐 retry 层的标准化规则。避免各组件各自实现重试造成行为不一致(无上限重试、无 jitter 导致 thundering herd)。
26
+
27
+ ---
28
+
29
+ ## 核心规范
30
+
31
+ - 所有重试逻辑必须使用 exponential + jitter,禁止固定间隔或无 jitter 的纯指数
32
+ - 重试必须有明确上限(`max_attempts`),禁止无限重试
33
+ - 重试决策必须先参考 failure-source-taxonomy 分类,fail-fast 类别不得重试
34
+ - 重试必须与 circuit-breaker 整合:OPEN 状态下不得重试,直接 fail-fast
35
+ - 每次重试都应通过遥测事件上报(`retry_attempted` / `retry_exhausted`)
36
+
37
+ ---
38
+
39
+ ## 退避公式
40
+
41
+ **Exponential with full jitter**:
42
+
43
+ ```
44
+ wait_ms = min(cap_ms, base_ms * 2^attempt) * (0.5 + random() * 0.5)
45
+ ```
46
+
47
+ | 参数 | 默认值 | 说明 |
48
+ |------|--------|------|
49
+ | `base_ms` | `100` | 基础等待时间 |
50
+ | `cap_ms` | `30000` | 等待时间上限 |
51
+ | `max_attempts` | `5` | 最大重试次数 |
52
+ | `jitter_ratio` | `0.5` | ±50% 抖动 |
53
+
54
+ **理由**:
55
+ - Exponential 随重试次数指数退避,避免短时间大量请求
56
+ - Jitter ±50% 避免 thundering herd(所有 client 同时重试)
57
+ - cap_ms=30s 避免超长等待,与典型 request timeout 对齐
58
+
59
+ ---
60
+
61
+ ## 依 failure-source 的重试规则
62
+
63
+ | 失败来源 | 可重试 | max_attempts | base_ms | 备注 |
64
+ |---------|--------|-------------|---------|------|
65
+ | `transient_network` | ✅ | 5 | 100 | 短暂网络抖动,指数退避通常可恢复 |
66
+ | `rate_limit` | ✅ | 3 | 1000 | 底数加大预留额度恢复时间;优先采用 Retry-After header |
67
+ | `upstream_unavailable` | ✅ | 3 | 500 | 重试前先查 circuit-breaker |
68
+ | `tool_failure` | ✅ | 2 | 200 | 工具层失败通常非 transient,仅给 2 次机会 |
69
+ | `prompt_delivery` | ✅ | 2 | 100 | 超过 2 次改走 model_switch |
70
+ | `authentication` | ❌ | — | — | fail-fast;凭证错误重试不会变对 |
71
+ | `validation` | ❌ | — | — | fail-fast;input 错误重试结果不变 |
72
+ | `policy_violation` | ❌ | — | — | fail-fast;安全决策禁止绕过 |
73
+ | `quota_exhausted` | ❌ | — | — | fail-fast;等 budget reset 或升级 tier |
74
+
75
+ ---
76
+
77
+ ## 与 circuit-breaker 整合
78
+
79
+ | 规则 | 说明 |
80
+ |------|------|
81
+ | Rule 1 | 每次重试前检查对应 breaker 的 state;若为 OPEN 立即回传 `CircuitOpenError`,不消耗 `max_attempts` |
82
+ | Rule 2 | 重试全部耗尽(`retry_exhausted`)计入 breaker 的 failure count |
83
+ | Rule 3 | HALF_OPEN 状态下仅允许 1 次探针重试,不套用 `max_attempts` |
84
+
85
+ ---
86
+
87
+ ## 遥测事件
88
+
89
+ **`retry_attempted`**(每次重试前上传,第 0 次原始调用不算)
90
+
91
+ | 字段 | 类型 |
92
+ |------|------|
93
+ | `operation` | `string` |
94
+ | `attempt` | `number` |
95
+ | `max_attempts` | `number` |
96
+ | `failure_source` | `FailureSource \| null` |
97
+ | `wait_ms` | `number` |
98
+
99
+ **`retry_exhausted`**(达到 max_attempts 仍失败时上传)
100
+
101
+ | 字段 | 类型 |
102
+ |------|------|
103
+ | `operation` | `string` |
104
+ | `attempts` | `number` |
105
+ | `final_failure_source` | `FailureSource` |
106
+
107
+ ---
108
+
109
+ ## 情境示例
110
+
111
+ **情境 1:指数退避计算**
112
+ - 条件:调用下游 API 失败,failure_source=transient_network,已重试 2 次
113
+ - 第 3 次重试等待时间:`min(30000, 100 * 2^3) * [0.5..1.0] = 400~800ms`
114
+
115
+ **情境 2:authentication fail-fast**
116
+ - 条件:API 回传 401,failure_source=authentication
117
+ - 结果:立即 fail-fast,不进入退避,不计入 circuit-breaker failure count
118
+
119
+ **情境 3:circuit OPEN 跳过重试**
120
+ - 条件:对应 breaker 为 OPEN,cooldown 剩 15s
121
+ - 结果:立即回传 CircuitOpenError,不消耗 max_attempts
122
+
123
+ ---
124
+
125
+ ## 错误码
126
+
127
+ | 代码 | 说明 |
128
+ |------|------|
129
+ | `RETRY-001` | `RETRY_EXHAUSTED` — 达到 max_attempts 仍失败 |
130
+ | `RETRY-002` | `RETRY_SKIPPED_NON_RETRYABLE` — failure_source 属 fail-fast 类别 |
131
+ | `RETRY-003` | `RETRY_SKIPPED_CIRCUIT_OPEN` — breaker OPEN 状态下跳过重试 |
@@ -0,0 +1,104 @@
1
+ ---
2
+ source: ../../../core/security-decision.md
3
+ source_version: 1.0.0
4
+ translation_version: 1.0.0
5
+ last_synced: 2026-04-20
6
+ status: current
7
+ ---
8
+
9
+ # 安全决策标准
10
+
11
+ > **语言**: [English](../../../core/security-decision.md) | 简体中文
12
+
13
+ **版本**: 1.0.0
14
+ **最后更新**: 2026-04-17
15
+ **状态**: Trial(到期 2026-10-17)
16
+ **适用范围**: universal
17
+ **来源**: XSPEC-068(DEC-043 Wave 1 可靠性套件)
18
+
19
+ ---
20
+
21
+ ## 目的
22
+
23
+ 安全决策铁律:deny > ask > allow 优先级仲裁,确保所有安全相关决策不被绕过。
24
+
25
+ 当多个规则对同一操作产生冲突的安全决策时(一个规则说 allow,另一个说 deny),必须有明确的优先级仲裁机制。本标准定义三态优先级(deny > ask > allow),并禁止任何代码路径绕过 deny 决策。
26
+
27
+ ---
28
+
29
+ ## 核心规范
30
+
31
+ - 安全决策优先级:`deny` > `ask` > `allow`
32
+ - 任何 `deny` 决策均不可被 `allow` 或 `ask` 覆盖
33
+ - `policy_violation` 类失败必须触发 `deny`,不得重试
34
+ - 安全决策必须记录遥测事件(`security_decision_made`)
35
+ - 禁止在安全决策路径上使用 try/catch 静默吞掉异常
36
+
37
+ ---
38
+
39
+ ## 三态优先级
40
+
41
+ | 优先级 | 决策 | 说明 |
42
+ |--------|------|------|
43
+ | 最高 | `deny` | 明确拒绝,不可被覆盖;记录原因 |
44
+ | 中间 | `ask` | 需要用户确认后才可执行 |
45
+ | 最低 | `allow` | 默认放行,前提是无 deny/ask 规则匹配 |
46
+
47
+ ### 仲裁逻辑
48
+
49
+ ```
50
+ if (任何规则产生 deny) → deny(终止,不继续检查)
51
+ else if (任何规则产生 ask) → ask(等待用户确认)
52
+ else → allow
53
+ ```
54
+
55
+ ---
56
+
57
+ ## 禁止的模式
58
+
59
+ | 禁止 | 原因 |
60
+ |------|------|
61
+ | 捕获 `DenyError` 并继续执行 | 绕过安全决策 |
62
+ | 在 `deny` 后重试操作 | `policy_violation` 不可重试 |
63
+ | 在 `ask` 阶段超时后自动 allow | 应超时后自动 deny |
64
+ | 忽略安全决策遥测日志 | 无审计追踪 |
65
+
66
+ ---
67
+
68
+ ## 遥测事件
69
+
70
+ **`security_decision_made`**(每次安全决策时上报)
71
+
72
+ | 字段 | 类型 |
73
+ |------|------|
74
+ | `operation` | `string` |
75
+ | `decision` | `deny\|ask\|allow` |
76
+ | `matchedRule` | `string` |
77
+ | `reason` | `string` |
78
+ | `timestamp` | `string` |
79
+
80
+ ---
81
+
82
+ ## 情境示例
83
+
84
+ **情境 1:deny 优先于 allow**
85
+ - 条件:规则 A 产生 allow,规则 B 产生 deny
86
+ - 结果:最终决策为 deny,操作被拒绝,记录原因
87
+
88
+ **情境 2:ask 超时**
89
+ - 条件:操作需要用户确认(ask),用户 30 秒内未响应
90
+ - 结果:超时后自动转为 deny(不允许自动 allow)
91
+
92
+ **情境 3:policy_violation 不重试**
93
+ - 条件:操作触发 `policy_violation`,决策为 deny
94
+ - 结果:立即终止,不进入重试逻辑,记录 `security_decision_made`
95
+
96
+ ---
97
+
98
+ ## 错误码
99
+
100
+ | 代码 | 说明 |
101
+ |------|------|
102
+ | `SEC-001` | `OPERATION_DENIED` — 安全决策为 deny,操作被拒绝 |
103
+ | `SEC-002` | `ASK_TIMEOUT` — 用户确认超时,自动转为 deny |
104
+ | `SEC-003` | `SECURITY_BYPASS_DETECTED` — 检测到绕过安全决策的代码路径 |