ARTICLE DETAIL

资讯详情

深耕网站视觉设计与运营推广的一线实战洞察。

oh-my-openagent 重命名变更集代码质量审查实录:agent-command-string 审计闸门为何在 1190 个测试中唯一飘红

oh-my-openagent 重命名变更集代码质量审查实录:agent-command-string 审计闸门为何在 1190 个测试中唯一飘红 oh-my-openagent 重命名变更集代码质量审查实录agent-command-string 审计闸门为何在 1190 个测试中唯一飘红【免费下载链接】oh-my-openagentOmO: Just type mass ulw keyword with your prompt. Now you are the master of graph engineering.项目地址: https://gitcode.com/gh_mirrors/oh/oh-my-openagent导读本文以 oh-my-openagentOmO仓库内 .omo/evidence/20260809-omo-agent-toolkit-rename/F2.md 这份代码质量审查Code-Quality Review报告为主线完整还原一次omo→omo-agent-toolkit重命名变更集从 typecheck、全量测试、仓库法则对照到违规项判定的全过程。你将看到一个上线即永久变红的审计闸门audit gate如何因自我匹配self-scan而失效一行代码的修复为何足以让 1190 个测试从 1 红恢复全绿以及#given/#when/#then测试法则、无行号指纹、allowlist 分类等工程约束在 script/agent-command-string-scan.ts 等源码中的真实落地形态。1. 审查背景一次跨 142 个文件的重命名重构本次审查针对的是omo-agent-toolkit重命名变更集其元数据如下Worktree.local-ignore/worktrees/omo-agent-toolkit-rename分支feat/omo-agent-toolkit-rename基于origin/dev的 7 个提交审查 Diffgit diff origin/dev...HEAD共 142 个文件排除.omo证据产物后可审查源码 diff 为 3,323 行审查者senpi-task 子任务st_019fe5d1只读分析所有结论均通过实际执行命令验证审查遵循三条主线真实命令结果typecheck、scoped tests、仓库法则对照AGENTS.md 的硬性约定、测试质量评估AI-slop 注释与同义反复检查。所有结果都标注为 REAL RESULT强调不是推理而是运行产物。重命名的最终形态可以从当前 package.json 的bin映射看到——omo条目已被移除omo-agent-toolkit与四个保留别名oh-my-opencode、oh-my-openagent、lazycodex、lazycodex-ai共同指向共享入口bin/oh-my-opencode.jsbin: { oh-my-opencode: bin/oh-my-opencode.js, oh-my-openagent: bin/oh-my-opencode.js, omo-agent-toolkit: bin/oh-my-opencode.js, lazycodex: bin/oh-my-opencode.js, lazycodex-ai: bin/oh-my-opencode.js }2. 第一道关卡全仓 typecheck 零诊断审查命令bun run typechecktsgo 根项目 typecheck:scripttypecheck:packages覆盖 29 个 package 项目真实结果TYPECHECK_EXIT0PASS。根目录、script/以及全部 package tsconfig 均零诊断通过。对一次横跨 142 个文件、涉及 bin 映射、CLI 安装参数解析、postinstall 脚本的重命名来说类型层面的完整性是第一道必须迈过的门槛——这一关干净通过说明重命名没有破坏任何导出签名与调用关系。3. 第二道关卡scoped 测试 1,190 例 1 红审查命令bun test bin script packages/omo-opencode/src/cli packages/omo-senpi/src/components/ulw-loop真实结果TEST_EXIT1 1189 pass 1 fail 2929 expect() calls Ran 1190 tests across 186 files. [11.83s] (fail) agent command string audit #given tracked source files #when legacy agent and human commands are scanned #then every hit is categorizedFAIL — 唯一一条红测试且已用bun test script/agent-command-string-audit.test.ts单独复现0 pass / 1 fail排除排序或偶发flake因素。失败 diff 如下 collectHits() vs allowlist script/agent-command-string-audit.allowlist.json:5: omo ulw-loop, ... (33 hits total, ALL inside script/agent-command-string-audit.allowlist.json itself) - Expected - 0 Received 33 at script/agent-command-string-audit.test.ts:57:273.1 根因审计闸门自我匹配永远无法通过这条红测试不是代码回归而是审计机制自身的逻辑缺陷。审计闸门会扫描每一个git ls-files追踪的文件用正则\bomo (ulw-loop|boulder|install|...)\b等模式查找遗留命令字符串但isExcluded()审查时位于 script/agent-command-string-audit.test.ts 第 16-22 行没有排除 allowlist 文件自身。问题因此成立allowlist 的每条目本身就是一个遗留命令字符串例如script/agent-command-string-audit.allowlist.json:5: omo ulw-loop于是闸门对自己扫描出了 33 次未分类命中。变更集的最后一个提交migrate remaining agent commands … with an audit gate因此落地了一个永久变红的闸门——这恰恰是审计闸门要防止的事情。3.2 修复方案一行排除审查给出的修复只有一行把 allowlist 加入isExcluded()排除列表|| filePath script/agent-command-string-audit.allowlist.json备选方案是在collectHits()中跳过ALLOWLIST_PATH但放进isExcluded更简单且与既有 CHANGELOG /.omo的排除模式一致。这一修复在当前仓库源码中已经落地查看 script/agent-command-string-scan.ts 的isExcluded()可以看到排除列表已包含ALLOWLIST_RELATIVE_PATH即 allowlist 自身与审查建议完全一致export function isExcluded(filePath: string): boolean { return filePath ALLOWLIST_RELATIVE_PATH || filePath AUDIT_TEST_RELATIVE_PATH || filePath SCAN_MODULE_RELATIVE_PATH || filePath SCAN_TEST_RELATIVE_PATH || filePath CHANGELOG.md || filePath.endsWith(/CHANGELOG.md) || filePath .omo || filePath.startsWith(.omo/) || filePath.split(/).some((part) part node_modules || part install-dist || part dist) }3.3 审计闸门的机制设计无行号指纹为什么审计闸门要用指纹而不是直接比对行号script/agent-command-string-scan.ts 中fingerprintSource()的注释给出了明确的安全理由Deliberately line-number-free: a release version stamp or a doc edit shifts every line below it, and a line-pinned fingerprint turns that shift into a red release gate. The count keeps the audit sensitive to a NEW legacy command occurrence inside an already-allowlisted file.即指纹刻意不携带行号——一次版本戳更新或文档编辑会把其下所有行号整体下移行号固定的指纹会把这种行移变成一次虚假的发布闸门变红而保留出现次数则让闸门对已放行文件内新增一条遗留命令仍然敏感。fingerprintSource()的实现要点三个扫描模式script/agent-command-string-scan.tsAGENT_COMMAND_RE\bomo (ulw-loop|boulder)\b、HUMAN_COMMAND_RE\bomo (install|uninstall|cleanup|doctor|run|get-local-version|version|mcp)\b、BARE_BIN_REcommand -v omo、/bin/omo、omo、$(which omo)等裸二进制引用指纹键为${filePath}: ${match[0]}出现次数大于 1 时以xN后缀标注仅扫描git ls-files追踪文件script/agent-command-string-scan.ts并过滤排除列表、node_modules、install-dist、dist等目录。配套的 script/agent-command-string-scan.test.ts 用三个场景验证了这个设计契约行移位后指纹不变、已放行文件新增一条命令后指纹变化、全新文件中的遗留命令按路径上报。3.4 闸门的断言结构script/agent-command-string-audit.test.ts 包含两道断言分类闸门collectHits(WORKSPACE_ROOT)必须恰好等于 allowlist 中四个分类emit-migrate、test-expectation、input-compat-preserve、docs条目的并集其中emit-migrate与test-expectation必须保持为空数组有意设计的债务闸门——任何人往这两个分类写入新条目都会触发失败。无行号 pin 约束allowlist 条目不得携带路径:行号:前缀防止文档与发布戳的行位移破坏发布闸门。当前 script/agent-command-string-audit.allowlist.json 的input-compat-preserve与docs分类展示了放行条目的形态例如packages/omo-codex/plugin/components/ulw-loop/src/codex-hook.ts: omo ulw-loop、packages/omo-native/bin/lib/launcher.js: omo ulw-loop、AGENTS.md: omo doctor等——每条都是为兼容旧输入而有意保留的遗留命令位置。4. 第三道关卡对照 AGENTS.md 仓库法则审查将 diff 逐条对照 AGENTS.md 的工程法则结果如下表原文完整继承法则结果禁止as anyCLEAN — 零新增一处 grep 误报文档行中的 alias anywhere 散文禁止ts-ignore/ts-expect-errorCLEAN — 零新增禁止压制 lintCLEAN — 零新增eslint-disable或等价物代码中禁止 emojiCLEAN — 无新增。packages/omo-senpi/plugin/extensions/omo.js中的⚡ ultraworking是已检入压缩构建产物中的既有内容diff 仅重盖了 bundle 哈希并重命名了字符串kebab-case 文件命名CLEAN — 新文件全部为 kebab-casebin-map.test.ts、agent-command-string-audit.test.ts、agent-command-string-audit.allowlist.json、postinstall.test.tscreateXXX工厂模式N/A — 无新增组件/工厂resolveOmoBin/toSpawnTarget是既有导出、原地修改barrelindex.ts仅导出NOT INTRODUCED —packages/omo-senpi/src/components/ulw-loop/index.ts承载业务逻辑但早于本 diffhunk 仅替换omo→omo-agent-toolkit字符串属既有状况不计入本次变更~200 LOC 软性文件规模上限PRE-EXISTING OVERAGE WORSENED —packages/omo-codex/src/install/codex-cache-bins.ts由 229 行增至 255 行本就超限本次再增 26 行而未抽取。仅作观察软性上限#given/#when/#then前缀测试、禁止 AAAONE VIOLATION — 见下方 V2未出现 Arrange-Act-Assert禁止空 catch 块CLEAN — 新增removeGeneratedRuntimeWrapper的 catch 对非 ENOENT 重新抛出readActiveStatus为 log-and-return压缩产物中的catch{}为既有输出禁止万能 util/helper/service 文件CLEAN — 无新增4.1 V1BLOCKING审计闸门测试在 HEAD 即为红位置script/agent-command-string-audit.test.ts 分类闸门测试审查时约第 57 行问题闸门未排除自身 allowlist产生 33 次未分类自我命中随包发布即永久失败违反理由变更集不得携带一条红测试落地一个永远无法通过的闸门比没有闸门更糟修复在isExcluded()中排除script/agent-command-string-audit.allowlist.json重跑套件至全绿4.2 V2minor新测试缺少#given/#when/#then前缀位置packages/omo-opencode/src/cli/install-platform-resolution.test.ts 第 170、180、190、200、208 行附近的五个OMO_EDITION install routing测试问题使用纯英文描述名 裸// when/// then注释全程无#given/#when/#then前缀而仓库法则要求强制前缀。同一次 diff 中新增的doctor-target.test.ts测试带有前缀说明 diff 内部风格不一致修复建议改写为#given OMO_EDITIONcodex #when resolving install args for a non-codex invocation #then the platform defaults to codex形式从当前源码看这五个测试仍然存在且描述名未变如OMO_EDITIONcodex defaults a non-codex invocation name to the codex platform第 170 行说明该 minor 违规在审查后尚未完全清理——这是审查结论未被完全消费的可见证据。4.3 V3minorbin-map 测试头部注释是 AI-slop位置script/bin-map.test.ts 头部问题第 1 行仅复述文件名// script/bin-map.test.ts第 2 行叙述变更事件omo - omo-agent-toolkit rename而非陈述持久契约均为噪音describe字符串已经说明了被测内容修复删除这两行当前仓库的 script/bin-map.test.ts 已从 import 直接开始、头部注释被删除V3 修复已经落地。4.4 被检查且未标记的实质性 WHY 注释应保留审查明确指出以下注释属于解释非显然安全理由的实质性注释不得删除ulw-loop 组件中 Deliberately NO PATH lookup of the bare nameomo 块与.jsspawn 说明避免对裸名omo做 PATH 查找的刻意设计postinstall.mjs 中关于 npm ≥7 隐藏生命周期输出的说明解释为何通知是 best-effort.github/workflows/publish.yml中升级模拟upgrade-simulation契约注释记录标记版 vs 用户自有遗留包装器的安全不变量packages/omo-codex/plugin/components/bootstrap/src/setup.ts的降级路径注释仅字符串更新.omo/evidence/20260809-omo-agent-toolkit-rename/ 下lead-codex-qa.sh、lead-npm-qa.sh的 ISOLATION CONTRACT 头部隔离契约属安全文档经确认不予标记5. 第四道关卡同义反复评估每个新测试逐一过筛同义反复指那种无论如何都不可能失败的测试——它不检测任何真实行为。审查对本次新增的每个测试文件逐一评估5.1 script/bin-map.test.ts3 个测试均为真实变更探测器…the omo bin entry is absent— 若omo被重新加回 bin map 即失败真实有效…omo-agent-toolkit points at the shared entry— 若入口被移除或改指即失败真实有效…the four surviving aliases keep the shared entry— 若四个别名任一漂移即失败真实有效5.2 script/agent-command-string-audit.test.ts1 个测试…every hit is categorized—非同义反复是实时闸门其当前恰好失败本身就是证明但正如 V1 所示随包发布状态下它无法通过当前失败模式是自扫描而非真实回归。emit-migrate/test-expectation的toEqual([])断言是有意设计的债务闸门——任何人往这两个分类登记新条目都会失败属于设计内行为5.3 postinstall.test.ts审查时为 3 个测试均执行真实 postinstall.mjs 于隔离 fixture HOMEannounces the omo-agent-toolkit rename exactly once— 通知被删除、改写或打印两次即失败真实有效never fails the install regardless of platform binary resolution— postinstall 在 fixture 环境非零退出即失败。断言真实但命名过度承诺只覆盖一种环境形态regardless of platform binary resolution并未做平台变化测试属命名瑕疵而非同义反复stays idempotent across repeated runs—命名不当它断言两次运行各打印一次通知运行间一致性真正的幂等第二次运行什么都不打印反而会让该测试失败。建议改名为prints the notice exactly once on every run审查结论不存在无法失败的测试。每个新测试都命名了一个可被回归击穿的行为。从当前 postinstall.test.ts 看该文件已演进为 4 个测试并补齐了#given/#when/#then前缀新增了finishes when the opencode version probe never returns用挂起 opencode shim 验证 postinstall 在版本探测永不返回时仍能在超时前正常结束且announces … exactly once与stays idempotent across repeated runs的断言逻辑保持与审查描述一致。6. 审查裁决与修复闭环6.1 最终 Verdict原文One blocking defect (V1: the audit-gate test is red at HEAD by self-scan, confirmed by real test runs, full-suite and standalone) plus two minor violations (V2 missing#given/#when/#thenprefixes in the new install-platform-resolution tests, V3 slop header comments in bin-map.test.ts). Everything else — typecheck, remaining 1,189 tests, banned-pattern scan, naming, catches, comment quality, generated artifacts — is clean.REJECT — fix V1 (excludescript/agent-command-string-audit.allowlist.jsoninisExcluded(), suite must go 1190/1190 green), V2, and V3, then re-submit.即拒绝合并REJECT。必须修复 V1在isExcluded()中排除 allowlist 自身套件须恢复 1190/1190 全绿、V2、V3 后重新提交。6.2 审查闭环的仓库现状印证对比当前仓库 HEAD可以观察到这次审查驱动的修复闭环V1 已修复script/agent-command-string-scan.ts 的isExcluded()已将 allowlist 文件自身列入排除正是审查建议的一行修复V3 已修复script/bin-map.test.ts 头部两行噪音注释已删除V2 残留packages/omo-opencode/src/cli/install-platform-resolution.test.ts 的五个OMO_EDITION路由测试仍使用裸// when/// then注释、无#given前缀尚未按建议重命名postinstall 测试持续演进由审查时的 3 个增至 4 个并补齐前缀、新增挂起探测场景。这正体现了 AGENTS.md 所强制的证据驱动工作流.omo/evidence/20260809-omo-agent-toolkit-rename/目录下留存了 F1-F4 审查文档、lead-codex-qa.sh/lead-npm-qa.shQA 脚本与各任务日志审查结论有据可查、修复进度可追溯。7. 可复用的审查方法论要点从这份 F2 报告可以提炼出一套可移植的变更集质量审查清单用真实命令结果说话typecheck 与 scoped tests 必须实际执行并记录退出码与通过/失败计数杜绝应该能过的推断红测试必须单独复现TEST_EXIT1后先以单文件复跑bun test script/agent-command-string-audit.test.ts区分真实回归与排序/偶发闸门类工具要审查其自指性审计/门禁工具若扫描仓库自身文件必须确认排除列表覆盖自身输入allowlist、测试、扫描模块、CHANGELOG、证据目录否则会出现闸门对自己 33 次命中式的永久红法则对照要逐条留痕as any、ts-ignore、lint 压制、emoji、命名、空 catch、万能文件等每一条都给出 CLEAN / 违规 / N/A 的判定与证据区分实质性注释与 AI-slop复述文件名、叙述变更事件的注释是噪音解释非显然安全理由的 WHY 注释必须保留——并明确列出不要删清单测试逐条做同义反复检查每个新测试都必须能指出哪个行为回归会让它变红命名不得过度承诺regardless of platform 却没有平台变化矩阵。【免费下载链接】oh-my-openagentOmO: Just type mass ulw keyword with your prompt. Now you are the master of graph engineering.项目地址: https://gitcode.com/gh_mirrors/oh/oh-my-openagent创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表