Skip to content

Commit 97dfba7

Browse files
committed
修正未完成解析的对话与任务修复分流
1 parent 973672c commit 97dfba7

16 files changed

Lines changed: 58 additions & 9 deletions

‎.github/workflows/ci.yml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ jobs:
3636
run: |
3737
git clone --quiet https://github.com/full-stack-plugins/codeguard-plugin.git ../codeguard-plugin
3838
git -C ../codeguard-plugin checkout --quiet 9e4adb1
39+
# 语料仍绑定历史9e4adb1;源码审计另绑定最新插件提交,两者不能混用。
40+
# 固定提交尚未在插件远端可达时先明确失败,避免构建之后才发现缺源码。
41+
git -C ../codeguard-plugin cat-file -e 'dec5f9d1361eefff493e120b4278939a243814a9^{commit}' || {
42+
echo 'Pinned plugin audit source dec5f9d is unavailable; publish its reviewed Git branch before source audit.' >&2
43+
exit 1
44+
}
3945
4046
- name: Verify crate layering debt does not grow
4147
run: python3 scripts/check_layering.py

‎crates/codeguard-cli/src/check_command.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2672,7 +2672,7 @@ pub fn run(args: &[String]) -> ExitCode {
26722672
.take(8)
26732673
{
26742674
println!(
2675-
" {} [{}] grammar 报告错误但恢复位置不完整;初检未完成,需适用原生工具确认。",
2675+
" {} [{}] 候选解析未完成,恢复位置无法完整核验;先对原始源码运行适用原生工具。原生确认合法时调查 grammar 版本/兼容性或扫描预算;原生诊断成立时才按真实位置修复。",
26762676
item["path"].as_str().unwrap_or("?"),
26772677
item["language"].as_str().unwrap_or("unknown")
26782678
);

‎crates/codeguard-cli/src/check_syntax_candidates.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ fn report(
443443
"authority":"candidate_unqualified","delivery_decision":"incomplete",
444444
"source_file_count":source_file_count,"skipped_count":skipped_count,
445445
"unrouted_count":unrouted_count,"native_preferred_count":native_preferred_count,"observations":observations,
446-
"next_action":"核对适用语言版本与原生 lint/编译器;候选恢复节点不是已确认违规,零恢复也不表示完整通过"
446+
"next_action":"核对适用语言版本,使用原生 lint/编译器对原始源码确认;原生确认合法时调查 grammar 版本/兼容性或扫描预算,诊断成立时才按真实位置修复;零恢复不表示完整通过"
447447
})
448448
}
449449

‎crates/codeguard-cli/src/claude_hook_command.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ fn summarize(path: &str, report: &Value) -> String {
437437
"按当前原生字节位置修复语法,再使用原工具复检;完整 lint、类型和项目构建仍须检查"
438438
}
439439
Some("require_native_lint_confirmation") => {
440-
"必须准备或修复适用的原生 lint/编译器,再确认疑似问题或恢复未完成检查;不要仅凭候选结果修改源码"
440+
"必须准备或修复适用的原生 lint/编译器,对原始源码确认;原生确认合法时调查 grammar 版本/兼容性或扫描预算,诊断成立时才按真实位置修复;不要仅凭候选结果修改源码"
441441
}
442442
Some("recommend_native_lint") => {
443443
"初检未发现恢复节点,建议安装适用原生 lint;这不表示完整检查通过"

‎crates/codeguard-cli/src/next_command.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ fn candidate(root: &Path, id: &str, fact: &Value) -> Result<Candidate, &'static
675675
if fact["first_diagnostic_reason"] == "go_package_structure_candidate" {
676676
"Go整文件候选未发现package声明;先恢复适用原生Go lint或编译器确认完整文件范围,核对声明应属于哪个包。注释或字符串不算声明;不得凭候选删除函数、猜包名或关闭任务,原生确认后只修复目标源码并复检"
677677
} else if fact["first_diagnostic_reason"] == "syntax_recovery_incomplete" {
678-
"固定 grammar 的恢复扫描未完成或错误无法定位;核对语言版本、grammar 限制并恢复适用原生 lint/编译器或提出具体能力决策。原生确认前不得修改源码,不虚构错误位置,不凭零恢复关闭任务"
678+
"固定 grammar 的恢复扫描未完成或错误无法定位;恢复适用原生 lint/编译器,对原始源码确认。原生确认合法时调查 grammar 版本/兼容性或扫描预算;原生诊断成立时才按真实位置修复。缺 adapter 提出具体能力决策;原生确认前不得修改源码,不虚构错误位置,不凭零恢复关闭任务"
679679
} else {
680680
"查看固定 grammar 与当前源码的疑似证据;通过同一任务的原生复检核对适用语法能力,工具或 adapter 缺失时提出具体恢复或能力决策,不能改用 Python 或凭 WASM 零恢复关闭任务"
681681
},

‎crates/codeguard-cli/src/syntax_task_recheck.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ pub(crate) fn guidance(root: &Path, brief: &Value) -> Option<Value> {
869869
&& original(root, brief).is_ok_and(|original| original["schema_version"] == "0.3.0")
870870
{
871871
guidance["step"] = json!(format!(
872-
"候选恢复扫描未完成或错误无法定位;原生确认前不得修改源码,不虚构错误位置。{step}"
872+
"候选恢复扫描未完成或错误无法定位;对原始源码运行适用原生工具,原生确认合法时调查 grammar 版本/兼容性或扫描预算,诊断成立时才按真实位置修复。原生确认前不得修改源码,不虚构错误位置。{step}"
873873
));
874874
}
875875
if report["target"]["language"] == "rust" {

‎crates/codeguard-cli/src/work_sync.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2116,7 +2116,7 @@ fn render_blocker_task(report: &ReportInput, blocker: &BlockerInput) -> String {
21162116
}
21172117
if blocker.diagnostic_reason.as_deref() == Some("syntax_recovery_incomplete") {
21182118
return format!(
2119-
"# {} 语法检查能力恢复任务\n\n- 问题证据:范围 `{}`;报告 `.codeguard/reports/{}.json`,摘要 `{}`;固定 grammar 的恢复扫描未完成或错误无法定位,恢复节点数组为空;报告保留源码和 grammar 身份,没有可用的源码错误位置。\n- 规则依据:初检完整性与原生确认要求;零恢复不能代表语法通过,本任务不是已确认源码违规。\n- 允许修改范围:适用检查工具、语言版本和 grammar 配置;原生确认前不得修改源码,不关闭检查器,不伪造定位。\n- 修复步骤:核对原报告的语言、版本与已知限制,恢复适用原生 lint/编译器或调查 grammar;确认 adapter 缺失时提出具体能力决策,不重复无依据的源码修补。\n- 复检命令:codeguard task verify {} . --format=json;codeguard next . --format=json 显示当前能力缺口,恢复检查后再对同一范围复扫。\n- 历史尝试:首次 run {};后续扫描和失败尝试保留在同一任务,正文不代表完整历史。\n- 关闭条件:同一源码范围的有效原生确认、完整覆盖及既有关闭策略均满足;安装、WASM 零恢复或勾选均不能关闭。\n",
2119+
"# {} 语法检查能力恢复任务\n\n- 问题证据:范围 `{}`;报告 `.codeguard/reports/{}.json`,摘要 `{}`;固定 grammar 的恢复扫描未完成或错误无法定位,恢复节点数组为空;报告保留源码和 grammar 身份,没有可用的源码错误位置。\n- 规则依据:初检完整性与原生确认要求;零恢复不能代表语法通过,本任务不是已确认源码违规。\n- 允许修改范围:适用检查工具、语言版本和 grammar 配置;原生确认前不得修改源码,不关闭检查器,不伪造定位。\n- 修复步骤:核对原报告的语言、版本与已知限制,恢复适用原生 lint/编译器并对原始源码确认;原生确认合法时调查 grammar 版本/兼容性或扫描预算,原生诊断成立时才按真实位置修复。确认 adapter 缺失时提出具体能力决策,不重复无依据的源码修补。\n- 复检命令:codeguard task verify {} . --format=json;codeguard next . --format=json 显示当前能力缺口,恢复检查后再对同一范围复扫。\n- 历史尝试:首次 run {};后续扫描和失败尝试保留在同一任务,正文不代表完整历史。\n- 关闭条件:同一源码范围的有效原生确认、完整覆盖及既有关闭策略均满足;安装、WASM 零恢复或勾选均不能关闭。\n",
21202120
blocker.id, blocker.scope, report.run_id, report.digest, blocker.id, report.run_id
21212121
);
21222122
}

‎crates/codeguard-cli/tests/check_all_grammar_candidates.rs‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ fn hidden_kotlin_recovery_is_visible_in_project_feedback() {
3232
assert_eq!(kotlin["recovery_count"], 0);
3333
assert_eq!(kotlin["reason"], "syntax_recovery_incomplete");
3434
assert_eq!(report["delivery_decision"], "incomplete");
35+
let guidance = report["syntax_candidates"]["next_action"].as_str().unwrap();
36+
assert!(
37+
guidance.contains("原始源码") && guidance.contains("原生确认合法"),
38+
"{guidance}"
39+
);
3540
let text_output = Command::new(env!("CARGO_BIN_EXE_codeguard"))
3641
// 固定缺原生工具分支,避免宿主 kotlinc 抢占候选观察。
3742
.env("PATH", &root)
@@ -41,7 +46,9 @@ fn hidden_kotlin_recovery_is_visible_in_project_feedback() {
4146
.unwrap();
4247
assert_eq!(text_output.status.code(), Some(3));
4348
assert!(
44-
String::from_utf8_lossy(&text_output.stdout).contains("grammar 报告错误但恢复位置不完整"),
49+
String::from_utf8_lossy(&text_output.stdout).contains("原生确认合法")
50+
&& !String::from_utf8_lossy(&text_output.stdout)
51+
.contains("grammar 报告错误但恢复位置不完整"),
4552
"{}",
4653
String::from_utf8_lossy(&text_output.stdout)
4754
);

‎crates/codeguard-cli/tests/hook_syntax_tasks.rs‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,8 @@ fn unlocated_recoveries_become_stable_environment_tasks_without_source_positions
572572
"历史尝试",
573573
"关闭条件",
574574
"无法定位",
575+
"原生确认合法",
576+
"原始源码",
575577
"不得修改源码",
576578
] {
577579
assert!(body.contains(field), "{field}: {body}");
@@ -587,7 +589,9 @@ fn unlocated_recoveries_become_stable_environment_tasks_without_source_positions
587589
let brief: Value = serde_json::from_slice(&show.stdout).unwrap();
588590
let step = brief["task"]["step"].as_str().unwrap();
589591
assert!(
590-
step.contains("无法定位") && step.contains("不得修改源码"),
592+
step.contains("无法定位")
593+
&& step.contains("不得修改源码")
594+
&& step.contains("原生确认合法"),
591595
"{brief}"
592596
);
593597
assert!(
@@ -611,7 +615,9 @@ fn unlocated_recoveries_become_stable_environment_tasks_without_source_positions
611615
let stale: Value = serde_json::from_slice(&changed.stdout).unwrap();
612616
let step = stale["task"]["step"].as_str().unwrap();
613617
assert!(
614-
step.contains("无法定位") && step.contains("不得修改源码"),
618+
step.contains("无法定位")
619+
&& step.contains("不得修改源码")
620+
&& step.contains("原生确认合法"),
615621
"{stale}"
616622
);
617623
assert_eq!(stale["task"]["native_diagnostic_positions"], json!([]));
@@ -838,6 +844,7 @@ fn unlocated_claude_context_explains_zero_positions_and_real_recovery_task() {
838844
context.contains("原生确认任务 CG-B-") && context.contains("codeguard task show"),
839845
"{context}"
840846
);
847+
assert!(context.contains("原生确认合法"), "{context}");
841848
assert!(!context.contains("建议安装适用原生 lint"), "{context}");
842849
assert!(context.chars().count() <= 1200);
843850
assert!(context.ends_with("候选语法能力尚未完整验收,完整项目与交付未评估。"));

‎docs/Codeguard-Architecture.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,3 +1159,5 @@ flowchart LR
11591159
```
11601160

11611161
This diagram describes the implemented source-level host-approved SDK path. Production automatic host approval integration remains pending; editable local history cannot grant project delivery permission.
1162+
1163+
Incomplete parser feedback now directs the agent to check the original source with the applicable native tool. If native confirmation accepts the source, investigate grammar version/compatibility or scan budgets; only actual native diagnostics guide source changes. Truncation alone does not establish a grammar error. This applies to project output, edit context, persisted tasks and next/task show; task identity and closure requirements are unchanged. [Acceptance](../tests/acceptance/incomplete-syntax-guidance.md)

0 commit comments

Comments
 (0)