Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .agents/plugins/marketplace.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
"source": {
"source": "url",
"url": "https://github.com/partme-ai/partme-codeguard-plugin.git",
"ref": "v0.14.9"
"ref": "v0.14.10"
},
"policy": {
"installation": "AVAILABLE",
"authentication": "ON_USE"
},
"category": "Developer Tools",
"version": "0.14.9",
"version": "0.14.10",
"description": "Evidence-backed code checks and Git content gates for AI assistants, with Maven/Gradle module impact analysis. Save hooks provide feedback; unverified checks are explicit.",
"icon": "https://cdn.jsdelivr.net/gh/full-stack-plugins/codeguard-plugin@v0.14.9/assets/official-logo.png",
"icon": "https://cdn.jsdelivr.net/gh/full-stack-plugins/codeguard-plugin@v0.14.10/assets/official-logo.png",
"interface": {
"displayName": "代码规范守卫",
"shortDescription": "Trustworthy code checks and Java impact analysis",
"logo": "https://cdn.jsdelivr.net/gh/full-stack-plugins/codeguard-plugin@v0.14.9/assets/official-logo.png"
"logo": "https://cdn.jsdelivr.net/gh/full-stack-plugins/codeguard-plugin@v0.14.10/assets/official-logo.png"
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion .codex-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codeguard",
"version": "0.14.9+codex.20260923",
"version": "0.14.10+codex.20260923",
"description": "Evidence-backed code checks and Git content gates for AI assistants, with Maven/Gradle module impact analysis. Save hooks provide feedback; unverified checks are explicit.",
"author": {
"name": "Full Stack Skills / PartMe.AI",
Expand Down
2 changes: 1 addition & 1 deletion .zcode-plugin/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"en": "CodeGuard",
"zh-CN": "代码规范检查"
},
"version": "0.14.9",
"version": "0.14.10",
"description": "Evidence-backed code checks and Git content gates for AI assistants, with Maven/Gradle module impact analysis. Save hooks provide feedback; unverified checks are explicit.",
"description_i18n": {
"en": "Evidence-backed code checks and Git content gates for AI assistants, with Maven/Gradle module impact analysis. Save hooks provide feedback; unverified checks are explicit.",
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Coverage is module-level, not a symbol call graph or business-semantic proof. A

## Git content integrity

A plain commit checks the index, not an unstaged repair. Supported preceding git add operations overlay predicted worktree paths; pure push checks HEAD and upstream differences. Without a resolvable upstream, the HEAD tree is checked. Sensitive-file rules use the same proposed scope; removing a sensitive file is not treated as introducing it.
A plain commit checks the index, not an unstaged repair. Supported preceding git add operations overlay predicted worktree paths; in a direct command chain without shell substitution, an add after the final commit is not projected backward into that commit or a following push. Pure push checks HEAD and upstream differences. Without a resolvable upstream, the HEAD tree is checked. Sensitive-file rules use the same proposed scope; removing a sensitive file is not treated as introducing it.

Checks materialize temporary Git blobs without stash, checkout or modifying the real index. The exact-content gate does not reuse the soft working-tree cache. Missing ignored dependencies remain UNVERIFIED rather than silently falling back to different source content.

Expand Down
2 changes: 1 addition & 1 deletion README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Maven 使用 verify 并追加 -DskipTests(测试代码仍编译,仅跳过执

## Git 内容一致性

纯 commit 检查 index,不会拿未暂存的修复冒充提交内容。已支持的前序 git add 操作叠加预测工作树路径;纯 push 检查 HEAD 和上游差异。无可解析上游时检查 HEAD 树。敏感文件规则采用同一预测范围;删除敏感文件不视为新增入库。
纯 commit 检查 index,不会拿未暂存的修复冒充提交内容。已支持的前序 git add 操作叠加预测工作树路径;不含 Shell 命令替换的直接命令链里,最后一次 commit 后的 add 不会倒算进此前提交或随后的 push。纯 push 检查 HEAD 和上游差异。无可解析上游时检查 HEAD 树。敏感文件规则采用同一预测范围;删除敏感文件不视为新增入库。

检查在临时目录物化 Git blobs,不 stash、不 checkout、不更改真实 index。精确内容门禁不复用软提醒的工作树缓存。快照缺 ignored 依赖时保持 UNVERIFIED,不改查另一份源码。

Expand Down
2 changes: 2 additions & 0 deletions docs/current-architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ flowchart TD
`execution` 只记录进程证据,不把非零退出自动认定为代码违规。`verdict`、CVE 与 Dockerfile 报告解析决定 PASS、FAIL 或 UNVERIFIED;入口仅按各自协议呈现和聚合退出码。Git 提交检查使用 index 或预测暂存快照,推送检查使用 HEAD;保存钩子只给反馈。计划、未执行和未验证不能宣传为通过。
`language_check` 将 `PlanExecution` 的实际命令依序映射为应用层有界 `execution_trace`(检查、修复、复检阶段);`check_application` 将其进一步压成 MCP 安全元数据,不回显原始 argv、环境覆盖或捕获输出。`auto_fix` 的 `fix_results` 也只公开状态与安全元数据;formatter stderr 尾部写入私有 `.codeguard-fix.log` 后只公开路径,日志不可用时不退回公开原文。失败日志保留各已执行检查的完整输出,可能含敏感文本,应排除出版本控制。项目日志和门禁截断日志共用 `storage.write_private_text` 的私有原子落盘;预置日志文件链接不被跟随,默认 `out` 目录为链接或不可写时不返回虚假日志路径,也不覆盖检查结论。终止命令仍决定既有状态、退出码和旧字段;未运行的计划命令不进入证据。
Git 命令的仓库定位与拟暂存解析共用入口传入的 cwd;显式 `cd`/`git -C` 无法绑定 Git 工作树时,硬门禁给出目标未验证并阻断,不退回到调用者仓或无关子仓。未给出显式目标且调用目录非仓时仍保留 workspace 子仓兜底。静态命令解析不等于完整 Shell 执行模拟。
workspace 兜底产生的每个子仓是合成目标,暂存观察也绑定该子仓根目录;不能继续以非 Git 的 workspace cwd 解析,从而把脏子仓的已知违规变成未知放行。
一条命令链中的 Git 副作用先绑定为仓库与操作的有序对,再按仓库聚合检查面:纯 push 不读取该仓未提交的 index,同仓 commit→push 则保留已有 HEAD 与拟提交内容的并集。仓库级、内联及链式 `skipGate` 均按目标仓与操作顺序生效;已存在的仓库配置也可被同链先行 `git config --unset` 取消。链式设置跨 `||`、`;` 或换行时无法证明生效,门禁要求拆分命令;写入其它文件的 config 设置也不构成本仓豁免。语法、仓库归属、间接脚本与拟暂存分析共用引号/转义感知切分;参数文本中的控制符不能合成豁免。解析能力仍限于受支持的静态 Shell 形态。
一层 `bash`/`sh`/`zsh` 的 `-c`(含组合短选项)及可读脚本现在携带调用目录与正文进入同一 Git 操作计划;脚本内的 `git add` 可进入拟暂存范围,外层和内层 Git 操作按仓分别检查。识别到无法建模的间接 Git 操作、脚本内 `skipGate` 配置变更或跨解释器的暂存/提交关系时,明确以 Git 意图 UNVERIFIED 阻断,不借用调用者仓的检查结果。动态脚本、任意控制流及 Python/Node 中构造的 subprocess 仍未建模。
不含脚本或命令替换的直接静态命令链,暂存事件先按目标仓和执行次序记录,再投影到该仓最后一次 commit:其后的 add 不会倒算到先前提交或随后的 push;两个 commit 之间的 add 仍进入检查面。带一层间接脚本或 `$(...)`/反引号命令替换的链仍保守合并暂存意图,不声称已经建立跨层事件时钟。
直接 Git 命令、解释器入口及 `skipGate` 状态/内联豁免解析共用裸前缀归一化;可解析的环境赋值、`env FOO=1`、`command` 和无参数 `sudo` 不会遮蔽后面的 Shell 提交或豁免取消。带值 wrapper 参数和运行时生成命令仍不在静态保证范围内。

## 模块所有权
Expand Down
2 changes: 1 addition & 1 deletion kimi.plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codeguard",
"version": "0.14.9",
"version": "0.14.10",
"description": "Evidence-backed code checks and Git content gates for AI assistants, with Maven/Gradle module impact analysis. Save hooks provide feedback; unverified checks are explicit.",
"author": {
"name": "Full Stack Skills / PartMe.AI"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@

## 7. 让位项(pre_tool_git_guard.py 并行修改活跃期,避免竞争写入)

- [ ] 7.1 `match_pathspec`:git status pathspec 引擎解析 add 目标(glob/目录/等价语法)接进 staging_intent(测试已备标 skip;当前手工 resolve 对 glob/目录按字面子处理 → 提交面算窄)
- [ ] 7.2 内联/链式豁免放行的用户即时明示(hookSpecificOutput 提醒,测试已备标 skip)
- [x] 7.1 已由架构重构接管:`git_staging.resolve_pathspecs` 成组调用只读 Git pathspec 查询,目录/glob/literal/exclude/`-u`/`-f` 与真实 Hook 敏感文件回归均已恢复为常规测试;无需另建第二份 `match_pathspec` 实现。
- [x] 7.2 已由架构重构接管:内联与链式豁免按目标仓审计并在 Hook additionalContext 明示,`test_inline_skip_emits_user_visible_notice` 与多仓豁免测试为常规回归。
- [ ] 7.3 双副本判定一致性核对(partme-ai 0.3.4 悬挂 hook 已用 fail-open 占位止血——宿主仍执行已删除的 hook 致全部 Bash 报错;根治=宿主禁用 codeguard@partme-ai 旧副本)
2 changes: 2 additions & 0 deletions openspec/changes/refactor-codeguard-architecture/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ MCP 的 `auto_fix` 还必须在应用层单独投影公开结果:`run_fix` 保

`path_policy` 是扫描排除表、产物识别与拟入库路径规则的单一来源;`scope` 和 `gate_lib` 只兼容导出/调用。策略接收已经确定的路径,不读取 Git,更不会执行建议中的移除操作。Git 快照采集仍在 git_snapshot,反馈格式仍在 reporting。

直接命令链的拟暂存分析分成静态事件观察与按提交时间投影:先把同仓 `add`/`commit` 及其调用目录记录为不可变事件,再只将最后一个 commit 及以前的 add 送往 Git pathspec 查询和内容快照。这样后续 add 不会回溯污染已完成提交,也不跳过两个 commit 之间的 add。旧的独立 `staging_intent` 调用默认仍返回整条链的暂存意图;硬门禁只在没有一层间接脚本或 Shell 命令替换时启用按提交投影。`$(...)`/反引号的内层实际先执行,而旧静态展开把它附在文本尾部;间接脚本与外层 add 的跨层顺序也尚无统一事件时钟。这两类命令继续采用保守并集,不能以局部排序缩小检查面。

这不是完整 Shell 解释器:分隔符/引用/动态拼接和复杂相对 cd 仍有既有边界。显式 `cd` 或
`git -C` 指向非 Git 目标时,解析器现在返回独立的目标故障,硬门禁阻断而不回退调用者仓;
无显式目标且 cwd 非仓时继续保留 workspace 一层子仓兜底。仓库定位和拟暂存解析共用入口
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,16 @@ index 或工作树;不支持的动态/交互式形态必须明确未验证,
显式 `cd` 或 `git -C` 已给出目标时,若该目标不是可解析的 Git 工作树,MUST 阻断
该 Git 副作用命令并报告目标不可确定;不得回退调用者仓或扫调用者一层子仓。
只有命令未给出显式目标且调用目录不是 Git 仓时,才保留既有 workspace 子仓兜底策略。
兜底为每个子仓构造的合成目标 MUST 同时用于暂存观察;不能仍以非 Git workspace 目录
解析 commit,导致脏子仓的已确认违规降级为无阻断的未知结果。
一条命令链触及多个仓库时,commit/push 门禁面和是否存在待提交操作 MUST 按仓库分别
归属;A 仓的 commit 不得使 B 仓的纯 push 检查包含 B 仓尚未提交的 index。若同一仓
同时 commit 和 push,则继续检查该仓已有待推送内容及拟提交内容,不得缩窄既有检查面。
对于没有间接脚本或命令替换的静态命令链,拟暂存面 MUST 按同仓 Git 操作的先后顺序投影:最后一个
commit 之后才出现的 add 不得回溯到已完成的 commit 或随后的 push;最后一个 commit 之前的
add(包括多个 commit 之间的 add)仍须检查。无法可靠排序的一层间接脚本继续采用保守并集
或明确 UNVERIFIED;`$(...)` 和反引号会先执行内层、再执行外层,现有静态展开无执行时钟,
也 MUST 保守合并。不得通过此优化遗漏可能提交的敏感内容。
仓库级 `codeguard.skipGate` 只豁免设置它的仓库,不得因 A 仓豁免而跳过同链 B 仓。
内联 `git -c codeguard.skipGate` 只豁免对应 Git 操作;链式 `git config` 设置/取消
须按命令顺序归属到目标仓,不得把 A 仓的豁免传播到 B 仓或此前操作。写入
Expand Down Expand Up @@ -330,6 +337,26 @@ index 或工作树;不支持的动态/交互式形态必须明确未验证,
- **WHEN** git add 指定包含与排除 pathspec,或字面文件名包含星号
- **THEN** 快照只覆盖 Git 实际匹配的文件,排除项及同名 glob 邻居不会被额外暂存

#### Scenario: Add after the final commit is not retroactive
- **WHEN** 同仓静态命令链先提交已暂存的安全文件,再 `git add .env`,可选地随后执行 push,但没有第二次 commit
- **THEN** 门禁仍检查已提交内容和待推送 HEAD,不把之后才 add 的 `.env` 算进先前提交;真实 index 不被观察过程改写

#### Scenario: Add between commits remains guarded
- **WHEN** 同仓静态命令链先提交安全文件,再 `git add .env` 并进行第二次 commit
- **THEN** 门禁将 `.env` 纳入第二次拟提交内容并阻断整条工具调用

#### Scenario: Another repository's later commit does not extend the cutoff
- **WHEN** A 仓先 commit 后 add 敏感文件,命令链随后在 B 仓 commit
- **THEN** A 仓后置 add 不因 B 仓较晚的 commit 被倒算入 A 的提交;两仓的预测 index 均不被改写

#### Scenario: Command substitution stages before its outer commit
- **WHEN** 外层 `git commit -m "safe $(git add .env)"` 或反引号等价形式触发内层暂存
- **THEN** 不按展开文本顺序将内层 add 裁成“提交后操作”;门禁仍将 `.env` 纳入拟提交面并阻断,index 不被观察过程改写

#### Scenario: Fallback uses its selected child repository
- **WHEN** 调用目录为非 Git workspace,兜底发现一个暂存违规的子仓及一个无提交面的子仓
- **THEN** 暂存观察绑定前者的合成仓根,继续阻断其真实违规,且不连坐后者

### Requirement: Dockerfile checks SHALL preserve scope and incomplete evidence

hadolint 与 Trivy config 的报告解析 MUST 与进程及 CLI 呈现分离。文本和 JSON MUST 使用同一
Expand Down
4 changes: 2 additions & 2 deletions openspec/changes/refactor-codeguard-architecture/tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
- [x] 5.1 增加自动架构依赖/循环检查并接入 CI,临时源码树注入反向依赖/函数内导入/相对导入环后确实拒绝;本地已验证,远端 CI 待发布阶段。不以文件行数当合格标准。
- [x] 5.2 四个历史 skipped 已全部恢复;Dockerfile CLI 接入统一报告解析与扫描应用,14 项真实进程边界测试通过;基线比较按诊断内容和次数核验并要求基线实际 FAIL,三项误豁免用例先红后绿。完整 433 项单测零跳过、142 项回归零失败。
- [x] 5.3 新增当前架构 Mermaid 与扩展指南;报告版本读取插件 manifest,双语 README 指向当前证据,旧设计标明历史范围;双语标题/链接/版本及本地链接存在性测试通过。发布版本仍需在 5.5 检查。
- [x] 5.4 全量单测/真实 hook 回归/ruff/语言 schema/vendor 离线与在线/本 change strict 和逐条规格追溯通过;第二十三批本地 517 项单测、143 项真实 Hook 回归、57 项/11 规则,证据见 verification.md。仅证明本地契约,不等同三宿主现场验收。
- [ ] 5.5 按仓规升级版本、生成市场元数据、授权的 PR/CI/不可变 tag/Release 闭环;第二十二批已发布 v0.14.8(插件 PR #54、市场 PR #12、源码 PR/main CI、注释 tag/正式 Release 均核对;市场 PR 无 CI 检查)。第二十三批门禁故障隔离目前仅在本地,发布需独立验证。宿主安装运行独立记录,未授权不得改宿主。
- [x] 5.4 全量单测/真实 hook 回归/ruff/语言 schema/vendor 离线与在线/本 change strict 和逐条规格追溯通过;第二十四批本地 521 项单测、143 项真实 Hook 回归、57 项/11 规则,证据见 verification.md。仅证明本地契约,不等同三宿主现场验收。
- [ ] 5.5 按仓规升级版本、生成市场元数据、授权的 PR/CI/不可变 tag/Release 闭环;第二十三批已发布 v0.14.9(插件 PR #55、市场 PR #13、源码 PR/main CI、注释 tag/正式 Release 均核对;市场 PR 无 CI 检查)。第二十四批静态 Git 命令顺序修正目前仅在本地,发布需独立验证。宿主安装运行独立记录,未授权不得改宿主。
- [ ] 5.6 完成全目标审计,代码/规格/证据一致后同步并归档 change,才可将整体优化标记完成。
Loading
Loading