feat(orchestration): permissions 规则 YAML 化(#4 / ADR-0011 D-8b) - #15
Merged
Conversation
把 PermissionEngine 的 allow/ask/deny 规则从硬编码 TS 数组搬到外置 YAML, 解锁运维不发版调权限 + dev/staging/prod 差异化 + audit 追踪独立化。 加载优先级(loadDefaultPermissions): INALPHA_PERMISSIONS_FILE env → config/permissions.default.yaml → DEFAULT_PERMISSIONS 常量(仅默认 yaml 缺失时兜底) 失败语义:env 指定路径 / 默认 yaml 文件存在时,加载失败 strict throw 带文件路径与字段诊断;仅"env 未设 + 默认 yaml 不存在"才回退常量并 console.warn 一次——对应 issue #4 验收第 4 条。 新增: - packages/orchestration/config/permissions.default.yaml(1:1 等价于 DEFAULT_PERMISSIONS,带 inline comment 复述设计意图) - src/permissions/schema.ts(zod 校验结构) - src/permissions/yaml_loader.ts(loadPermissionConfigFromFile / resolveDefaultYamlPath / loadDefaultPermissions;路径用 import.meta.url 解析不依赖 cwd) - tests/permissions-yaml-loader.test.ts(覆盖等价性 / env override / 4 条 strict throw 路径) 接入:wired-tools.ts buildDefaultPermissionEngine 改用 loadDefaultPermissions; DEFAULT_PERMISSIONS 常量保留作 builtin fallback 与现有 4 个测试基线。 验证:pnpm typecheck 通过;permissions 相关 5 个测试文件 113/113 通过; check-consistency.sh 失败 0。workflows.hello 的并行 timing flake 与本 PR 无关 (重跑通过)。 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Deploying inalpha-web with
|
| Latest commit: |
f3d6b3d
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://27b09791.inalpha-web.pages.dev |
| Branch Preview URL: | https://feat-permissions-yaml-d8b.inalpha-web.pages.dev |
Comment on lines
+14
to
+15
| allow: z.array(z.string()), | ||
| ask: z.array(z.string()), |
Contributor
There was a problem hiding this comment.
[medium] ask 和 deny 未设 .optional().default([]),导致自定义 YAML 若省略空数组就会报 schema mismatch: ask: Required。这个 PR 的核心用例是允许运维写自己的 YAML,严格要求三个数组全写会增加配置成本。建议:
Suggested change
| allow: z.array(z.string()), | |
| ask: z.array(z.string()), | |
| ask: z.array(z.string()).optional().default([]), | |
| deny: z.array(z.string()).optional().default([]), |
这样 PermissionConfigParsed 推断类型不变(string[]),loadPermissionConfigFromFile 返回的对象仍满足 PermissionConfig。— 依据 CLAUDE.md §9 可维护性:面向运维的配置接口应降低必填门槛
Contributor
Review(CLAUDE.md §3 / §3.1 / §3.2 / §4 / §7–9)整体质量高:错误语义设计清晰(env 指定路径 strict throw / 默认 yaml 不存在 warn+fallback)、测试覆盖 9 case、 必修无 critical / major 级别问题。 可选优化
LGTM,合并后 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
把
PermissionEngine的 allow/ask/deny 规则从defaults.ts硬编码 TS 数组搬到外置 YAML(config/permissions.default.yaml),解决 issue #4 的 4 个痛点:改权限不再要发版 / 多环境差异化可行 / audit 追踪独立 / 兑现 ADR-0011 §规则文件示例的设计承诺。加载优先级(
loadDefaultPermissions):失败语义:env 指定路径 或 默认 yaml 文件存在时,加载失败 strict throw 带文件路径与 zod 字段诊断;仅"env 未设 + 默认 yaml 不存在"才回退常量并
console.warn一次——对应 issue #4 验收第 4 条 "YAML 解析失败 / schema 不匹配时启动失败并打印明确错误"。改动
新增(4 文件):
packages/orchestration/config/permissions.default.yaml— 1:1 等价于DEFAULT_PERMISSIONS,带 inline comment 复述设计意图(含paper.promote_candidateMVP allow workaround 注释 + sandboxtimeoutMs<=60000predicate)src/permissions/schema.ts— zodPermissionConfigSchema,只校结构;规则字符串语法由parseRule抛错src/permissions/yaml_loader.ts—loadPermissionConfigFromFile/resolveDefaultYamlPath/loadDefaultPermissions;路径用import.meta.url解析不依赖 cwd(规避 vitest / mastra dev 漂移)tests/permissions-yaml-loader.test.ts— 9 case,覆盖等价性 / env override / 6 条 strict throw 路径修改(4 文件):
src/mastra/wired-tools.ts—buildDefaultPermissionEngine()改用loadDefaultPermissions()src/permissions/index.ts— 多导出loadDefaultPermissions/loadPermissionConfigFromFile/resolveDefaultYamlPath/PermissionConfigSchema;DEFAULT_PERMISSIONS保留作 builtin fallback + 现有测试基线package.json/pnpm-lock.yaml— 加yaml@^2.9.0(ISC license,与 AGPL-3.0 兼容)验收对应(issue #4)
default yaml 加载后逐字段等于 DEFAULT_PERMISSIONS 常量deep equal passpermissions.test.ts/wired-tools.test.ts/strategy-authoring.test.ts/sandbox.test.ts5 个文件 113/113 通过INALPHA_PERMISSIONS_FILEenv 切换生效 — 测试env 指向自定义 yaml 时结果反映该文件而非默认passTest plan
pnpm -C packages/orchestration typecheck— cleanbash scripts/check-consistency.sh— 失败 0INALPHA_PERMISSIONS_FILE=/tmp/custom.yaml bash scripts/dev.sh验证 mastra :4111 启动加载自定义 yaml不在范围(out-of-scope)
pnpm permissions:explainCLI(可后续 chore;engine 已有list()方法支撑)关联
🤖 Generated with Claude Code