diff --git a/README.md b/README.md index e499a6f4..81cc7a65 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ Version output includes `cli_version`, `target`, and protocol information. Disco The workspace requires `std`. The opt-in `wasm-precheck` build feature uses a bounded Rust worker with pinned Java, TypeScript, and TSX grammar candidates. It currently reaches only single-file `lint java` and `lint typescript` requests without explicit native context; `.tsx` uses its own grammar. It is absent from the published npm `0.1.2` package. No `no_std`, completed project-wide WASM fallback, zero-unsafe, or fastest-runtime claim is made. Runtime OS calls require safety review; a comprehensive security audit is not claimed. -The current source-built CLI's `codeguard grammar status --format=json` reports the coverage gap without loading grammars or running lint: the pinned CodeGraph source has 30 vendored WASM files plus two distinct grammars resolved through its dependency; CodeGuard has three unqualified candidates and zero released syntax capabilities. The separate [coverage inventory](grammars/codegraph-coverage.json) is not an approved asset manifest. COBOL's 16.4 MB source asset also exceeds the current Rust loader's 8 MiB limit. +The current source-built CLI's `codeguard grammar status --format=json` reports the coverage gap without loading grammars or running lint: the pinned CodeGraph source has 30 vendored WASM files plus two distinct grammars resolved through its dependency; CodeGuard has four unqualified asset candidates (Java, Python, TypeScript, TSX) and zero released syntax capabilities. Python is pinned and Rust-loadable but has no CLI fallback path. The separate [coverage inventory](grammars/codegraph-coverage.json) is not an approved asset manifest. COBOL's 16.4 MB source asset also exceeds the current Rust loader's 8 MiB limit. ### npm installation and one-off use diff --git a/README.zh-CN.md b/README.zh-CN.md index ef56fcbb..d19d5c5c 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -96,7 +96,7 @@ cargo build --locked -p codeguard-cli 工作区要求 `std`。可选 `wasm-precheck` 构建特性已用固定的 Java、TypeScript、TSX grammar 候选资产与有界 Rust worker,为缺少显式原生上下文的 `lint java`、`lint typescript` 单文件请求提供疑似语法观察;`.tsx` 使用独立 grammar。公开 npm `0.1.2` 不含该路径。不声称 `no_std`、已完成项目级 WASM 兜底、零 unsafe 或性能最快。运行层系统调用需要安全审查,当前不宣称已完成整体安全审计。 -当前源码构建的 CLI 可用 `codeguard grammar status --format=json` 只读展示来源覆盖缺口,不加载 grammar 或运行 lint:固定 CodeGraph 来源含 30 份随仓 WASM,另有两种独立 grammar 从其依赖取得;CodeGuard 当前有三份未验收候选,已发行语法能力为零。[覆盖库存](grammars/codegraph-coverage.json)不是已批准资产清单。COBOL 来源资产约 16.4 MB,还超过当前 Rust 加载器的 8 MiB 限额。 +当前源码构建的 CLI 可用 `codeguard grammar status --format=json` 只读展示来源覆盖缺口,不加载 grammar 或运行 lint:固定 CodeGraph 来源含 30 份随仓 WASM,另有两种独立 grammar 从其依赖取得;CodeGuard 当前有 Java、Python、TypeScript、TSX 四份未验收资产候选,已发行语法能力为零。Python 已固定并通过 Rust 加载试验,但尚未接入 CLI 兜底。[覆盖库存](grammars/codegraph-coverage.json)不是已批准资产清单。COBOL 来源资产约 16.4 MB,还超过当前 Rust 加载器的 8 MiB 限额。 ### npm 安装与一次性调用 diff --git a/crates/codeguard-adapters/src/grammar_asset_manifest.rs b/crates/codeguard-adapters/src/grammar_asset_manifest.rs index 83b8f843..f1297ad8 100644 --- a/crates/codeguard-adapters/src/grammar_asset_manifest.rs +++ b/crates/codeguard-adapters/src/grammar_asset_manifest.rs @@ -9,6 +9,7 @@ const CODEGRAPH_LICENSE_SHA256: &str = "e6d98f98c666bebe065ac2492a0a19232cc318d4d67bac3ca42ffb77bacc8809"; const JAVA_COMMIT: &str = "94703d5a6bed02b98e438d7cad1136c01a60ba2c"; const TYPESCRIPT_COMMIT: &str = "f975a621f4e7f532fe322e13c4f79495e0a7b2e7"; +const PYTHON_COMMIT: &str = "bffb65a8cfe4e46290331dfef0dbf0ef3679de11"; /// 代码来源、许可和每份候选 grammar 的固定身份。 #[derive(Clone, Debug, Deserialize, Eq, PartialEq)] @@ -68,7 +69,7 @@ pub struct GrammarAsset { pub release_status: String, } -/// 读取仓内固定清单,并检查 CodeGraph 许可证及三份资产的原始字节。 +/// 读取仓内固定清单,并检查 CodeGraph 许可证及四份资产的原始字节。 pub fn bundled_grammar_candidates() -> Result { let manifest = parse_grammar_asset_manifest(include_bytes!("../../../grammars/manifest.json"))?; let codegraph_license = include_bytes!("../../../grammars/LICENSE.codegraph"); @@ -85,6 +86,10 @@ pub fn bundled_grammar_candidates() -> Result { include_bytes!("../../../grammars/typescript/parser.wasm").as_slice(), include_bytes!("../../../grammars/typescript/LICENSE").as_slice(), ), + "python" => ( + include_bytes!("../../../grammars/python/parser.wasm").as_slice(), + include_bytes!("../../../grammars/python/LICENSE").as_slice(), + ), "tsx" => ( include_bytes!("../../../grammars/tsx/parser.wasm").as_slice(), include_bytes!("../../../grammars/typescript/LICENSE").as_slice(), @@ -110,7 +115,7 @@ pub fn parse_grammar_asset_manifest(raw: &[u8]) -> Result Result Result ( + "https://github.com/tree-sitter/tree-sitter-python", + PYTHON_COMMIT, + "v0.23.6", + "python/parser.wasm", + "a7fdc587e77bd729b9f5b783c659be23c896e305a2c374472bed7114d9e01fac", + 456131, + "python/LICENSE", + "d724405ce238a22c0d35769c5a36b386ad5958192efe8bbb304fb2896254575f", + ), "typescript" => ( "https://github.com/tree-sitter/tree-sitter-typescript", TYPESCRIPT_COMMIT, diff --git a/crates/codeguard-adapters/tests/grammar_asset_manifest.rs b/crates/codeguard-adapters/tests/grammar_asset_manifest.rs index c5a99096..cb9f7ee0 100644 --- a/crates/codeguard-adapters/tests/grammar_asset_manifest.rs +++ b/crates/codeguard-adapters/tests/grammar_asset_manifest.rs @@ -5,13 +5,17 @@ use codeguard_adapters::{ #[test] fn bundled_candidates_pin_source_bytes_license_and_abi_without_claiming_support() { let manifest = bundled_grammar_candidates().expect("bundled manifest"); - assert_eq!(manifest.assets.len(), 3); + assert_eq!(manifest.assets.len(), 4); for asset in &manifest.assets { let (wasm, license) = match asset.language.as_str() { "java" => ( include_bytes!("../../../grammars/java/parser.wasm").as_slice(), include_bytes!("../../../grammars/java/LICENSE").as_slice(), ), + "python" => ( + include_bytes!("../../../grammars/python/parser.wasm").as_slice(), + include_bytes!("../../../grammars/python/LICENSE").as_slice(), + ), "typescript" => ( include_bytes!("../../../grammars/typescript/parser.wasm").as_slice(), include_bytes!("../../../grammars/typescript/LICENSE").as_slice(), @@ -64,4 +68,17 @@ fn changed_wasm_license_or_abi_never_qualifies_a_candidate() { assert!(verify_grammar_asset(&asset, wasm, license).is_err()); asset.sha256 = "0".repeat(64); assert!(verify_grammar_asset(&asset, wasm, license).is_err()); + + let python = manifest + .assets + .iter() + .find(|asset| asset.language == "python") + .expect("Python candidate"); + let python_wasm = include_bytes!("../../../grammars/python/parser.wasm"); + let python_license = include_bytes!("../../../grammars/python/LICENSE"); + assert!(verify_grammar_asset(python, python_wasm, python_license).is_ok()); + let mut altered_python = python_wasm.to_vec(); + altered_python[64] ^= 1; + assert!(verify_grammar_asset(python, &altered_python, python_license).is_err()); + assert!(verify_grammar_asset(python, python_wasm, license).is_err()); } diff --git a/crates/codeguard-cli/tests/grammar_status_cli.rs b/crates/codeguard-cli/tests/grammar_status_cli.rs index 78daef0c..2f30b2b5 100644 --- a/crates/codeguard-cli/tests/grammar_status_cli.rs +++ b/crates/codeguard-cli/tests/grammar_status_cli.rs @@ -12,7 +12,7 @@ fn codegraph_coverage_is_explicit_and_never_claims_parser_or_gate_completion() { assert_eq!(report["report_type"], "grammar_coverage_inventory"); assert_eq!(report["codegraph_grammar_count"], 32); assert_eq!(report["codegraph_vendored_count"], 30); - assert_eq!(report["candidate_count"], 3); + assert_eq!(report["candidate_count"], 4); assert_eq!(report["released_count"], 0); assert_eq!(report["authority"], "source_inventory_only"); assert_eq!(report["parser_capability"], "unverified"); @@ -25,7 +25,7 @@ fn codegraph_coverage_is_explicit_and_never_claims_parser_or_gate_completion() { assert_eq!(asset["released"], false); assert!(!asset["gap"].as_str().unwrap().is_empty()); } - for language in ["java", "typescript", "tsx"] { + for language in ["java", "python", "typescript", "tsx"] { let asset = assets .iter() .find(|row| row["language"] == language) diff --git a/crates/codeguard-runtime/tests/wasm_grammar_load.rs b/crates/codeguard-runtime/tests/wasm_grammar_load.rs index b9119d75..0bc8afca 100644 --- a/crates/codeguard-runtime/tests/wasm_grammar_load.rs +++ b/crates/codeguard-runtime/tests/wasm_grammar_load.rs @@ -3,11 +3,34 @@ use codeguard_runtime::WasmGrammar; const JAVA: &[u8] = include_bytes!("../../../grammars/java/parser.wasm"); +const PYTHON: &[u8] = include_bytes!("../../../grammars/python/parser.wasm"); const TYPESCRIPT: &[u8] = include_bytes!("../../../grammars/typescript/parser.wasm"); const TSX: &[u8] = include_bytes!("../../../grammars/tsx/parser.wasm"); #[test] fn pinned_grammars_load_offline_and_parse_valid_sources() { + let mut python = WasmGrammar::load( + "python", + PYTHON, + "a7fdc587e77bd729b9f5b783c659be23c896e305a2c374472bed7114d9e01fac", + 14, + ) + .expect("固定 Python WASM 应可由 Rust 加载"); + assert_eq!(python.abi_version(), 14); + assert!( + !python + .parse(b"def greet(name):\n return name\n") + .unwrap() + .root_node() + .has_error() + ); + assert!( + python + .parse(b"def greet(\n") + .unwrap() + .root_node() + .has_error() + ); let mut java = WasmGrammar::load( "java", JAVA, diff --git a/docs/Codeguard-Architecture.md b/docs/Codeguard-Architecture.md index 6207a4d1..ab945cd0 100644 --- a/docs/Codeguard-Architecture.md +++ b/docs/Codeguard-Architecture.md @@ -28,7 +28,7 @@ The existing [OpenSpec change](../openspec/changes/introduce-rust-codeguard-cli/ | [Core aggregation](../crates/codeguard-core/src/aggregate.rs), [delivery gate](../crates/codeguard-core/src/delivery_gate.rs) | Pure result semantics, not trusted public gate availability | | [Acceptance records](../tests/acceptance) | Scoped observations, test method, and residual gaps | -WASM requirements and 18 implementation tasks are recorded in the existing change. An opt-in Rust worker, pinned Java/TypeScript/TSX grammar candidates, and narrow single-file feedback schemas now exist. Project-wide native-first routing, qualified grammar ranges, stable syntax tasks, and host integrations remain incomplete; design examples are not current command output. +WASM requirements and 18 implementation tasks are recorded in the existing change. An opt-in Rust worker and narrow Java/TypeScript/TSX single-file feedback paths now exist; Python is an additional pinned, Rust-loadable asset candidate without CLI fallback. Project-wide native-first routing, qualified grammar ranges, capability-matched task closure, and host integrations remain incomplete; design examples are not current command output. ## 2. Architectural drivers @@ -241,7 +241,7 @@ A completed native violation never selects fallback to obtain a clean result. A Reuse pinned CodeGraph grammar WASM artifacts and applicable upstream licenses, source references, patches and corpus cases. Do not copy CodeGraph's graph extraction or source-blanking heuristics into a syntax verdict. CodeGraph's `src/extraction/grammars.ts` loads language artifacts through `web-tree-sitter`; successful loading there does not prove compatibility with Codeguard's Rust runtime. The local source review on 2026-09-28 found modified grammar artifacts and about 65 MB of grammar files, so a live directory is not a release input. -The read-only `codeguard grammar status` command now projects a [pinned CodeGraph coverage inventory](../grammars/codegraph-coverage.json): 30 vendored WASM files and two dependency-provided grammars, with Java, TypeScript and TSX as CodeGuard candidates and none qualified for release. This inventory is deliberately separate from the pinned [candidate asset manifest](../grammars/manifest.json). In particular, the COBOL source file exceeds the current loader's 8 MiB input limit. Inventory rows never trigger loading or count as supported parser capability. +The read-only `codeguard grammar status` command now projects a [pinned CodeGraph coverage inventory](../grammars/codegraph-coverage.json): 30 vendored WASM files and two dependency-provided grammars, with Java, Python, TypeScript and TSX as CodeGuard asset candidates and none qualified for release. Python has no CLI fallback route. This inventory is deliberately separate from the pinned [candidate asset manifest](../grammars/manifest.json). In particular, the COBOL source file exceeds the current loader's 8 MiB input limit. Inventory rows never trigger loading or count as supported parser capability. ```text grammars/ # proposed release assets, not project state diff --git a/docs/Codeguard-Architecture.zh_CN.md b/docs/Codeguard-Architecture.zh_CN.md index c206f26e..6f87a636 100644 --- a/docs/Codeguard-Architecture.zh_CN.md +++ b/docs/Codeguard-Architecture.zh_CN.md @@ -28,7 +28,7 @@ | [核心聚合](../crates/codeguard-core/src/aggregate.rs)、[交付门禁](../crates/codeguard-core/src/delivery_gate.rs) | 纯结果语义,不代表公开可信门禁已可用 | | [验收记录](../tests/acceptance) | 限定范围的观察、测试方法和剩余缺口 | -WASM 的规范与 18 项实施任务已纳入既有 change;可选 Rust worker、固定 Java/TypeScript/TSX grammar 候选资产和局部单文件反馈 schema 已存在。项目级原生优先调度、grammar 版本范围验收、稳定语法任务及宿主接线仍未完成;设计示例不是当前命令输出。 +WASM 的规范与 18 项实施任务已纳入既有 change;可选 Rust worker 与 Java/TypeScript/TSX 局部单文件反馈路径已存在。Python 新增为固定且通过 Rust 加载试验的资产候选,尚未接入 CLI 兜底。项目级原生优先调度、grammar 版本范围验收、任务的能力匹配关闭及宿主接线仍未完成;设计示例不是当前命令输出。 ## 2. 架构驱动 @@ -241,7 +241,7 @@ flowchart TD 复用固定版本的 CodeGraph grammar WASM,以及适用的上游许可证、源码引用、补丁和语料。不能把 CodeGraph 的图提取或源码遮盖启发式直接用于语法判定。CodeGraph 的 `src/extraction/grammars.ts` 通过 `web-tree-sitter` 加载语言资产,在那里可加载不证明兼容 Codeguard 的 Rust 运行时。发行时必须固定不可变的来源与资产清单,不能把正在修改的本地目录直接当作发行输入。 -只读 `codeguard grammar status` 现投影[固定来源覆盖库存](../grammars/codegraph-coverage.json):CodeGraph 随仓 30 份 WASM,依赖提供另两种独立 grammar;CodeGuard 有 Java、TypeScript、TSX 三份候选,尚无已验收发行能力。覆盖库存与[候选资产清单](../grammars/manifest.json)分开,不能凭库存行自动加载或宣称支持。尤其 COBOL 来源资产超过当前加载器 8 MiB 限额。 +只读 `codeguard grammar status` 现投影[固定来源覆盖库存](../grammars/codegraph-coverage.json):CodeGraph 随仓 30 份 WASM,依赖提供另两种独立 grammar;CodeGuard 有 Java、Python、TypeScript、TSX 四份资产候选,尚无已验收发行能力。Python 只通过固定字节与 Rust 加载试验,未接入 lint。覆盖库存与[候选资产清单](../grammars/manifest.json)分开,不能凭库存行自动加载或宣称支持。尤其 COBOL 来源资产超过当前加载器 8 MiB 限额。 ```text grammars/ # 规划中的发行资产,不是项目状态 diff --git a/docs/Codeguard-Technical-Design.md b/docs/Codeguard-Technical-Design.md index 73f0eba2..b6915a90 100644 --- a/docs/Codeguard-Technical-Design.md +++ b/docs/Codeguard-Technical-Design.md @@ -14,7 +14,7 @@ The existing [OpenSpec change](../openspec/changes/introduce-rust-codeguard-cli/ Current source is the authority for callable behavior. Target contracts are labelled as such. The product priority is configuration discovery → native results → useful repair guidance. Internal consistency checks support this experience; they are not a demand for users to manually construct execution certificates. -WASM requirements and 18 implementation tasks are recorded in the existing change. Candidate Rust worker, pinned Java/TypeScript/TSX assets, and narrow single-file reports now exist behind an opt-in feature; project-wide native-first routing, qualified grammar ranges, and host integrations remain incomplete. Design examples are not current command output. +WASM requirements and 18 implementation tasks are recorded in the existing change. Candidate Rust worker and narrow Java/TypeScript/TSX single-file reports now exist behind an opt-in feature; Python is pinned and Rust-loadable but has no CLI fallback. Project-wide native-first routing, qualified grammar ranges, and host integrations remain incomplete. Design examples are not current command output. ## 2. Technology choices and trade-offs @@ -191,7 +191,7 @@ The opt-in CLI build first checks for a local ESLint 10 package and a single ord Import only pinned WASM bytes with upstream license, commit/patch provenance, SHA-256, ABI, tested runtime and language/dialect ranges, corpus reference and known gaps. Verify each copied CodeGraph artifact in the selected Rust Tree-sitter runtime; do not copy TypeScript extraction logic or assume CodeGraph support equals syntax acceptance. A release manifest belongs to distribution assets, not writable `.codeguard/` project state. -Use `codeguard grammar status --format=json` to query the separate source coverage inventory. It reports 32 distinct CodeGraph grammar assets, three CodeGuard candidates, and zero released capabilities without running a parser. The two dependency-provided assets lack pinned bytes, and COBOL exceeds the current 8 MiB loader limit; these remain explicit gaps before any per-language qualification. +Use `codeguard grammar status --format=json` to query the separate source coverage inventory. It reports 32 distinct CodeGraph grammar assets, four CodeGuard asset candidates, and zero released capabilities without running a parser. Python is Rust-loadable but has no CLI lint fallback. The two dependency-provided assets lack pinned bytes, and COBOL exceeds the current 8 MiB loader limit; these remain explicit gaps before any per-language qualification. Use a parent-controlled parser worker with a total deadline, per-file input bound, memory/process limit and capped diagnostics. Lazy-load selected grammars, parse without general network/filesystem imports, and terminate a stuck worker without losing native results from other modules. Host-specific enforcement and Rust MSRV compatibility must be tested; numeric production budgets remain measurement-driven rather than invented promises. diff --git a/docs/Codeguard-Technical-Design.zh_CN.md b/docs/Codeguard-Technical-Design.zh_CN.md index 47d9345f..0df01dec 100644 --- a/docs/Codeguard-Technical-Design.zh_CN.md +++ b/docs/Codeguard-Technical-Design.zh_CN.md @@ -14,7 +14,7 @@ 可调用行为以当前源码为准,目标契约明确标注。产品优先级是配置发现 → 原生结果 → 有用的修复指引。内部一致性校验为这个体验服务,不要求用户手工构造执行证明。 -WASM 的规范与 18 项实施任务已纳入既有 change;可选特性下的 Rust worker、固定 Java/TypeScript/TSX 资产及局部单文件候选报告已存在,项目级原生优先调度、grammar 版本范围验收与宿主接线仍未完成。设计示例不是当前命令输出。 +WASM 的规范与 18 项实施任务已纳入既有 change;可选特性下的 Rust worker 与 Java/TypeScript/TSX 局部单文件候选报告已存在,Python 固定资产通过 Rust 加载试验但尚无 CLI 兜底。项目级原生优先调度、grammar 版本范围验收与宿主接线仍未完成。设计示例不是当前命令输出。 ## 2. 技术选型与权衡 @@ -191,7 +191,7 @@ flowchart LR 只引入固定 WASM 字节及上游许可证、提交/补丁来源、SHA-256、ABI、已验证运行时和语言/方言范围、语料引用与已知缺口。逐个验证 CodeGraph 资产与选定 Rust Tree-sitter 运行时兼容,不能复制 TypeScript 提取逻辑或把 CodeGraph 支持等同语法验收。发行清单属于分发资产,不属于可写的 `.codeguard/` 项目状态。 -可用 `codeguard grammar status --format=json` 查询独立的来源覆盖库存。它只读报告 CodeGraph 32 种独立 grammar、CodeGuard 三份候选和零项已发行能力,不运行解析器。依赖提供的两份资产尚未固定字节,COBOL 超过现有加载器的 8 MiB 限额;每语言验收前仍须解决这些缺口。 +可用 `codeguard grammar status --format=json` 查询独立的来源覆盖库存。它只读报告 CodeGraph 32 种独立 grammar、CodeGuard 四份资产候选和零项已发行能力,不运行解析器;Python 候选未接入 lint。依赖提供的两份资产尚未固定字节,COBOL 超过现有加载器的 8 MiB 限额;每语言验收前仍须解决这些缺口。 由父进程控制解析工作进程,设置总截止时间、单文件输入上限、内存/进程限制及诊断数量上限。按需加载 grammar,不提供通用网络/文件系统导入;终止卡住的进程时保留其它模块的原生结果。宿主约束执行和 Rust MSRV 兼容性须测试,生产数值预算须经测量后确定,不编造性能承诺。 diff --git a/docs/Codeguard-Trust-and-Distribution.md b/docs/Codeguard-Trust-and-Distribution.md index a2a38bf8..b4e4df47 100644 --- a/docs/Codeguard-Trust-and-Distribution.md +++ b/docs/Codeguard-Trust-and-Distribution.md @@ -48,9 +48,9 @@ Network publication verifies signature and exact site permission before transfer The recorded npm `@partme.ai/codeguard@0.1.0` publication wraps an Apple Silicon macOS Rust binary. Node forwards argv/cwd/environment/streams/exit and is not another checker implementation. Current packaging has no automatic grammar download or install hook. Public installation verification is scoped in [npm acceptance](../tests/acceptance/npm-public-candidate.md); immutable source/tag and multi-platform qualification remain separate. -The repository now includes a [candidate asset manifest](../grammars/manifest.json), fixed-commit Java, TypeScript and TSX WASM bytes with their CodeGraph and upstream MIT licenses. The [Rust verifier](../crates/codeguard-adapters/src/grammar_asset_manifest.rs) checks provenance fields and exact bytes. Rust offline loading and basic parsing tests pass for these three candidates; language versions, dialects, full corpora, complete CLI routing and a real MSRV build remain unvalidated. They therefore remain `candidate_unvalidated`. See [scoped acceptance](../tests/acceptance/grammar-asset-candidates.md) and [TSX correction](../tests/acceptance/tsx-grammar-candidate.md). The optional source build uses them for narrow single-file fallback; public npm still does not package or select them. +The repository now includes a [candidate asset manifest](../grammars/manifest.json), fixed-commit Java, Python, TypeScript and TSX WASM bytes with their CodeGraph and upstream MIT licenses. The [Rust verifier](../crates/codeguard-adapters/src/grammar_asset_manifest.rs) checks provenance fields and exact bytes. Rust offline loading and basic parsing tests pass for these four candidates; language versions, dialects, full corpora, complete CLI routing and a real MSRV build remain unvalidated. They therefore remain `candidate_unvalidated`. See [scoped acceptance](../tests/acceptance/grammar-asset-candidates.md), [Python asset acceptance](../tests/acceptance/python-grammar-asset-candidate.md) and [TSX correction](../tests/acceptance/tsx-grammar-candidate.md). The optional source build has narrow Java/TypeScript/TSX single-file fallback; Python has no CLI route. Public npm still does not package or select these assets. -CodeGraph loads grammar WASM with JavaScript `web-tree-sitter`, which was also used for the initial ABI observation. CodeGuard's Rust [WasmGrammar](../crates/codeguard-runtime/src/wasm_grammar.rs) loads the **same pinned bytes** through Tree-sitter `WasmStore` and parses Java, TypeScript and TSX in tests. The grammar assets are shared; the JavaScript loader is not. Node only forwards the npm command. Rust loading proves limited compatibility of this path, not syntax accuracy or completion of every OpenSpec 14.2 criterion. +CodeGraph loads grammar WASM with JavaScript `web-tree-sitter`, which was also used for the initial ABI observation. CodeGuard's Rust [WasmGrammar](../crates/codeguard-runtime/src/wasm_grammar.rs) loads the **same pinned bytes** through Tree-sitter `WasmStore` and parses Java, Python, TypeScript and TSX in tests. The grammar assets are shared; the JavaScript loader is not. Node only forwards the npm command. Rust loading proves limited compatibility of this path, not syntax accuracy or completion of every OpenSpec 14.2 criterion. Full WASM distribution still requires pinned patches, compatibility ranges and corpora. Copying an active build directory is not a release contract. Users should not require tree-sitter-cli. The Rust parser host needs memory/time limits, safe loading, integrity verification and explicit unsupported/error status. diff --git a/docs/Codeguard-Trust-and-Distribution.zh_CN.md b/docs/Codeguard-Trust-and-Distribution.zh_CN.md index a9919d23..7743a74f 100644 --- a/docs/Codeguard-Trust-and-Distribution.zh_CN.md +++ b/docs/Codeguard-Trust-and-Distribution.zh_CN.md @@ -71,9 +71,9 @@ Git 联合入口现进一步核对每跳已签名基线的原生祖先关系( npm 已发布 macOS arm64 0.1.0;Node 只转发到打包的 Rust 二进制,无检测或解析逻辑,无安装生命周期脚本。默认本地 private 打包与显式 public 模式分开。当前缺不可变源码/tag 绑定,多平台支持不能由打包器分支或交叉编译推断。使用方式归 [README](../README.zh-CN.md#npm-安装与一次性调用)。 -目前已有[候选资产清单](../grammars/manifest.json)及固定提交的 Java、TypeScript、TSX WASM,保留 CodeGraph 和上游 MIT 许可证;[Rust 校验器](../crates/codeguard-adapters/src/grammar_asset_manifest.rs)核对来源字段和原始字节。三份资产的 Rust 离线加载及基本解析测试已通过;语言版本、方言、完整语料、完整调度和 MSRV 实编仍未验收,所以资产仍标记为 `candidate_unvalidated`。详见[局部验收](../tests/acceptance/grammar-asset-candidates.md)和 [TSX 纠错验收](../tests/acceptance/tsx-grammar-candidate.md)。可选源码构建已用于局部单文件兜底,公开 npm 包仍不含这些字节或检查路径。 +目前已有[候选资产清单](../grammars/manifest.json)及固定提交的 Java、Python、TypeScript、TSX WASM,保留 CodeGraph 和上游 MIT 许可证;[Rust 校验器](../crates/codeguard-adapters/src/grammar_asset_manifest.rs)核对来源字段和原始字节。四份资产的 Rust 离线加载及基本解析测试已通过;语言版本、方言、完整语料、完整调度和 MSRV 实编仍未验收,所以资产仍标记为 `candidate_unvalidated`。详见[局部验收](../tests/acceptance/grammar-asset-candidates.md)、[Python 资产验收](../tests/acceptance/python-grammar-asset-candidate.md)和 [TSX 纠错验收](../tests/acceptance/tsx-grammar-candidate.md)。可选源码构建仅有 Java/TypeScript/TSX 的局部单文件兜底,Python 尚无 CLI 路由;公开 npm 包仍不含这些字节或检查路径。 -CodeGraph 使用 JavaScript `web-tree-sitter` 加载 grammar WASM,初始 ABI 观察也沿用该加载器。CodeGuard 的 Rust [WasmGrammar](../crates/codeguard-runtime/src/wasm_grammar.rs) 已使用 Tree-sitter `WasmStore` 加载**同一固定字节**并在测试中解析 Java、TypeScript、TSX。这里复用的是 grammar 资产,不是 JavaScript 加载器;Node 仅负责 npm 命令转发。Rust 加载成功只证明该加载路径的有限兼容性,不证明语法判定准确,也不代表 OpenSpec 14.2 的全部验收完成。 +CodeGraph 使用 JavaScript `web-tree-sitter` 加载 grammar WASM,初始 ABI 观察也沿用该加载器。CodeGuard 的 Rust [WasmGrammar](../crates/codeguard-runtime/src/wasm_grammar.rs) 已使用 Tree-sitter `WasmStore` 加载**同一固定字节**并在测试中解析 Java、Python、TypeScript、TSX。这里复用的是 grammar 资产,不是 JavaScript 加载器;Node 仅负责 npm 命令转发。Rust 加载成功只证明该加载路径的有限兼容性,不证明语法判定准确,也不代表 OpenSpec 14.2 的全部验收完成。 完整 WASM 发行仍须固定补丁、兼容范围及语料,不得复制活动目录或运行时取 latest。包内资产应离线可用,按需加载;取消或部分覆盖不缓存 clean。升级/回滚重新核验资产和缓存身份,保留历史观察与白名单失效记录。完整生产声明还需平台、宿主、原生工具和质量评测分别验收。 diff --git a/grammars/manifest.json b/grammars/manifest.json index 83405b52..25f52cc5 100644 --- a/grammars/manifest.json +++ b/grammars/manifest.json @@ -42,6 +42,24 @@ "known_limitations": ["Rust loader smoke passed; MSRV build, dialect versions, isolation and syntax corpus are not yet validated"], "release_status": "candidate_unvalidated" }, + { + "language": "python", + "dialect": "python", + "grammar_repository": "https://github.com/tree-sitter/tree-sitter-python", + "grammar_commit": "bffb65a8cfe4e46290331dfef0dbf0ef3679de11", + "grammar_version": "v0.23.6", + "path": "python/parser.wasm", + "sha256": "a7fdc587e77bd729b9f5b783c659be23c896e305a2c374472bed7114d9e01fac", + "bytes": 456131, + "license": "python/LICENSE", + "license_sha256": "d724405ce238a22c0d35769c5a36b386ad5958192efe8bbb304fb2896254575f", + "abi_version": 14, + "codegraph_runtime": "web-tree-sitter 0.25.3", + "codeguard_runtime_validation": "rust_loader_smoke_passed", + "language_versions": [], + "known_limitations": ["Rust loader smoke passed; Python language versions, dialects, isolation and syntax corpus are not yet validated"], + "release_status": "candidate_unvalidated" + }, { "language": "tsx", "dialect": "tsx", diff --git a/grammars/python/LICENSE b/grammars/python/LICENSE new file mode 100644 index 00000000..ff8ed93c --- /dev/null +++ b/grammars/python/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2016 Max Brunsfeld + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/grammars/python/parser.wasm b/grammars/python/parser.wasm new file mode 100644 index 00000000..8b3bc8a7 Binary files /dev/null and b/grammars/python/parser.wasm differ diff --git a/openspec/changes/introduce-rust-codeguard-cli/tasks.md b/openspec/changes/introduce-rust-codeguard-cli/tasks.md index 8ad815cf..4cc3803b 100644 --- a/openspec/changes/introduce-rust-codeguard-cli/tasks.md +++ b/openspec/changes/introduce-rust-codeguard-cli/tasks.md @@ -1026,10 +1026,10 @@ TDD缺自动同步先RED。相关普通:build9、work sync15、next6,共30 ## 14. S14 WASM 语法初检完善 -状态:全部待实施。统一规格 [syntax-precheck](specs/syntax-precheck/spec.md)。依赖已有 CLI/原生调度/工作台切片,不等待整个 S13;本阶段验收进入 S12、S13。各任务须先失败样本后实现与回归;不改写原生规则。责任为模块维护职责,非已分配人员。 +状态:逐项实施中,未达到整体验收。统一规格 [syntax-precheck](specs/syntax-precheck/spec.md)。依赖已有 CLI/原生调度/工作台切片,不等待整个 S13;本阶段验收进入 S12、S13。各任务须先失败样本后实现与回归;不改写原生规则。责任为模块维护职责,非已分配人员。 -- [ ] 14.1 资产清单与来源。责任:adapters / 发布。规格:SP04。依赖:无。验收:固定 CodeGraph 来源提交、grammar 版本、许可证、SHA-256、ABI、语言/方言;缺来源、错散列和不兼容样本拒绝加载。进行中:已从固定 CodeGraph 提交复制 Java/TypeScript/TSX WASM 与 MIT 许可证,清单和 Rust 校验拒绝来源/字节/声明 ABI 漂移;三份资产已由 Rust 离线加载并实测 ABI;[局部证据](../../../tests/acceptance/grammar-asset-candidates.md)。新增与批准资产清单分离的[完整来源覆盖库存](../../../grammars/codegraph-coverage.json)及只读 `grammar status`:固定提交中的 30 份随仓 WASM 已逐字节核对,另两种依赖资产标为未固定,COBOL 的 16.4 MB 超出当前 8 MiB 加载限额;[覆盖验收](../../../tests/acceptance/codegraph-grammar-coverage.md)。其余 grammar 的上游许可证/版本、Rust 加载、语言版本/方言、语料及可发行验收仍缺,不勾选。 -- [ ] 14.2 Rust WASM 加载器。责任:runtime。规格:SP04,SP05。依赖:14.1。验收:支持固定资产离线加载;不依赖 Node 解析器、CodeGraph 或用户安装 tree-sitter-cli;通过有效/损坏/错 ABI 样本及 MSRV。进行中:可选 `wasm-precheck` 特性已通过 Java/TypeScript/TSX Rust `WasmStore` 加载与反例测试,并由私有工作进程从 stdin 处理真实源码、父进程核对身份与恢复锚点,见[局部验收](../../../tests/acceptance/syntax-worker-candidate.md);本机无 Rust 1.85,MSRV 实编及正式 `lint/check` 接线尚缺。 +- [ ] 14.1 资产清单与来源。责任:adapters / 发布。规格:SP04。依赖:无。验收:固定 CodeGraph 来源提交、grammar 版本、许可证、SHA-256、ABI、语言/方言;缺来源、错散列和不兼容样本拒绝加载。进行中:已从固定 CodeGraph 提交复制 Java/Python/TypeScript/TSX WASM 与 MIT 许可证,清单和 Rust 校验拒绝来源/字节/声明 ABI 漂移;四份资产已由 Rust 离线加载并实测 ABI,Python 尚无 lint 路由;见[Python 资产局部验收](../../../tests/acceptance/python-grammar-asset-candidate.md);[局部证据](../../../tests/acceptance/grammar-asset-candidates.md)。新增与批准资产清单分离的[完整来源覆盖库存](../../../grammars/codegraph-coverage.json)及只读 `grammar status`:固定提交中的 30 份随仓 WASM 已逐字节核对,另两种依赖资产标为未固定,COBOL 的 16.4 MB 超出当前 8 MiB 加载限额;[覆盖验收](../../../tests/acceptance/codegraph-grammar-coverage.md)。其余 grammar 的上游许可证/版本、Rust 加载,以及所有候选的语言版本/方言、语料及可发行验收仍缺,不勾选。 +- [ ] 14.2 Rust WASM 加载器。责任:runtime。规格:SP04,SP05。依赖:14.1。验收:支持固定资产离线加载;不依赖 Node 解析器、CodeGraph 或用户安装 tree-sitter-cli;通过有效/损坏/错 ABI 样本及 MSRV。进行中:可选 `wasm-precheck` 特性已通过 Java/Python/TypeScript/TSX Rust `WasmStore` 加载与反例测试,并由私有工作进程从 stdin 处理真实源码、父进程核对身份与恢复锚点,见[局部验收](../../../tests/acceptance/syntax-worker-candidate.md);本机无 Rust 1.85,MSRV 实编及正式 `lint/check` 接线尚缺。 - [ ] 14.3 进程资源隔离。责任:runtime。规格:SP05。依赖:14.2。验收:验证超时、内存、输出、取消与崩溃;损坏 grammar 不阻塞其他模块、不遗留进程。进行中:Unix 候选 worker 复用受控进程组内核,输入 1 MiB、输出 64 KiB,父进程有共同截止时间和取消;崩溃后代清理、输出洪泛、运行中取消及随后正常解析均增加真实子进程反例。Linux 2 GiB `RLIMIT_AS`、3 GiB 分配负例与 worker 故障隔离在 [Ubuntu CI](https://github.com/full-stack-plugins/codeguard/actions/runs/36478461118) 真实通过;Wasmtime 虚拟预留缩小。macOS 本机硬限制实测不支持,候选仍不具内存隔离权威;见[局部验收](../../../tests/acceptance/syntax-worker-candidate.md)。其它目标平台、损坏 grammar 隔离及正式调度仍缺,不勾选。 - [ ] 14.4 语言覆盖与源码映射。责任:adapters。规格:SP06。依赖:14.2。验收:识别 ERROR/MISSING,合并恢复节点;测试 Unicode、换行、嵌入语言、新语法和未知版本,不将不支持当源码违规。进行中:Rust 已提取两类原始节点,adapters 核对 UTF-8/CRLF 字节锚点并转换 Unicode 标量列;结构祖先归组保留并列错误,预算截断保持不完整;[局部证据](../../../tests/acceptance/syntax-recovery-candidate.md)。级联归并语料、版本/嵌入语言及原生对照仍缺。 - [ ] 14.5 原生工具准备探测。责任:adapters。规格:SP01,SP03。依赖:现有配置发现。验收:识别项目本地工具、wrapper、版本和无效配置;PATH 缺失不等于未安装,不对坏配置重复建议安装。进行中:ESLint 本地包/入口及 Maven Wrapper 脚本/发行配置已有只读候选分类,`detect` 与 `check` 已输出固定路径观察的候选;`node_modules` 普通源码遍历被排除,链接和损坏配置保留阻塞;发现协议升级为 0.4.0,聚合协议升级为 0.31.0 并保留旧 schema;[局部证据](../../../tests/acceptance/native-tool-readiness-candidates.md)。单文件 TypeScript 本地候选已接通受控原生版本探针,见 [原生优先局部验收](../../../tests/acceptance/native-first-eslint-candidate.md);单文件 TypeScript 现进一步区分本地包确实未观察到与配置歧义、链接入口、包身份损坏等环境阻塞;阻塞不被误当成工具缺失而触发 WASM,见同一[原生优先局部验收](../../../tests/acceptance/native-first-eslint-candidate.md)。显式工具自动选择、其它语言及多模块原生优先调度、更多构建器和真实多平台验收尚缺,不勾选。 diff --git a/schemas/grammar-asset-manifest.schema.json b/schemas/grammar-asset-manifest.schema.json index 322f954d..ed469b3e 100644 --- a/schemas/grammar-asset-manifest.schema.json +++ b/schemas/grammar-asset-manifest.schema.json @@ -14,8 +14,8 @@ "build_tool": {"const": "tree-sitter-cli 0.25.10 build --wasm"}, "assets": { "type": "array", - "minItems": 3, - "maxItems": 3, + "minItems": 4, + "maxItems": 4, "items": {"$ref": "#/$defs/asset"} } }, @@ -27,15 +27,15 @@ "additionalProperties": false, "required": ["language", "dialect", "grammar_repository", "grammar_commit", "grammar_version", "path", "sha256", "bytes", "license", "license_sha256", "abi_version", "codegraph_runtime", "codeguard_runtime_validation", "language_versions", "known_limitations", "release_status"], "properties": { - "language": {"enum": ["java", "typescript", "tsx"]}, - "dialect": {"enum": ["java", "typescript", "tsx"]}, + "language": {"enum": ["java", "python", "typescript", "tsx"]}, + "dialect": {"enum": ["java", "python", "typescript", "tsx"]}, "grammar_repository": {"type": "string", "pattern": "^https://github.com/tree-sitter/tree-sitter-"}, "grammar_commit": {"$ref": "#/$defs/commit"}, "grammar_version": {"type": "string", "pattern": "^v[0-9]+\\.[0-9]+\\.[0-9]+$"}, - "path": {"enum": ["java/parser.wasm", "typescript/parser.wasm", "tsx/parser.wasm"]}, + "path": {"enum": ["java/parser.wasm", "python/parser.wasm", "typescript/parser.wasm", "tsx/parser.wasm"]}, "sha256": {"$ref": "#/$defs/sha256"}, "bytes": {"type": "integer", "minimum": 8, "maximum": 8388608}, - "license": {"enum": ["java/LICENSE", "typescript/LICENSE"]}, + "license": {"enum": ["java/LICENSE", "python/LICENSE", "typescript/LICENSE"]}, "license_sha256": {"$ref": "#/$defs/sha256"}, "abi_version": {"const": 14}, "codegraph_runtime": {"const": "web-tree-sitter 0.25.3"}, diff --git a/tests/acceptance/codegraph-grammar-coverage.md b/tests/acceptance/codegraph-grammar-coverage.md index 559c52b8..84941035 100644 --- a/tests/acceptance/codegraph-grammar-coverage.md +++ b/tests/acceptance/codegraph-grammar-coverage.md @@ -9,3 +9,5 @@ 未完成:其余 30 份资产的上游版本/许可证、Rust ABI 与真实加载、各语言版本/方言/语料、原生对照、运行时预算和发行打包。此库存不证明任何新增语言已可进行语法初检,不改变原生 lint 或交付门禁。 后续增量:[TSX 候选纠错](tsx-grammar-candidate.md)将 TSX 纳入候选资产,当前源码构建的 `grammar status` 候选数变为 3,仍无已验收发行能力。上面的 2 候选与 2/2 测试记录保留为本次覆盖库存引入时的验收快照。 + +再后续的 [Python 资产候选](python-grammar-asset-candidate.md)使当前候选数变为 4;Python 尚未接入 lint,已发行能力仍为 0。上述数值均为各次增量当时的记录。 diff --git a/tests/acceptance/grammar-asset-candidates.md b/tests/acceptance/grammar-asset-candidates.md index f6adab8c..60de9f5d 100644 --- a/tests/acceptance/grammar-asset-candidates.md +++ b/tests/acceptance/grammar-asset-candidates.md @@ -16,3 +16,5 @@ Rust 加载器的 `wasm_grammar_load` 测试先因缺少 `WasmGrammar` 编译失 OpenSpec 14.1 和 14.2 仍不勾选:语言/方言版本边界、MSRV 实编、进程隔离、错误节点/位置和可发行验收仍需后续任务补齐。加载成功不意味着语法规则准确或原生 lint 义务已完成。 后续增量:[TSX 候选纠错](tsx-grammar-candidate.md)把同一来源仓库的 TSX 独立 WASM 加入固定候选清单;当前候选资产数为 3。本页的“两份”及初次验收命令属于原 Java/TypeScript 引入时的历史快照。 + +更晚的 [Python 资产候选](python-grammar-asset-candidate.md)把当前候选数提高到 4;Python 只通过固定字节、许可证及 Rust 离线加载试验,尚无 CLI 语法初检路径。上述“3”仍是 TSX 引入当时的历史数值。 diff --git a/tests/acceptance/python-grammar-asset-candidate.md b/tests/acceptance/python-grammar-asset-candidate.md new file mode 100644 index 00000000..24e9b261 --- /dev/null +++ b/tests/acceptance/python-grammar-asset-candidate.md @@ -0,0 +1,9 @@ +# Python WASM 固定资产候选:局部验收(2026-09-29) + +对应 OpenSpec 14.1、14.2。CodeGraph 固定提交 `40f112453583a2304c4b605a3a9d6545919662bd` 的 `src/extraction/wasm/tree-sitter-python.wasm` 已复制到 `grammars/python/parser.wasm`;两者 SHA-256 均为 `a7fdc587e77bd729b9f5b783c659be23c896e305a2c374472bed7114d9e01fac`,长度均为 456131 字节。CodeGraph 引入该字节的提交 `c2503e2` 记录它对应 `tree-sitter-python 0.23.6`;上游 `v0.23.6` 标签解析为 `bffb65a8cfe4e46290331dfef0dbf0ef3679de11`。该提交的 MIT `LICENSE` 随资产保存,SHA-256 为 `d724405ce238a22c0d35769c5a36b386ad5958192efe8bbb304fb2896254575f`。固定清单同时保留 CodeGraph 自身许可证和来源身份。 + +先将资产清单测试的候选数量从 3 改为 4,测试因只有 3 项失败;随后加入固定字节、许可证与清单项。Rust 资产校验核对来源提交、路径、长度、SHA-256、许可证、声明 ABI 和未验收状态,并拒绝 Python 字节或许可证被替换。`WasmGrammar` 在离线测试中实测 ABI 14,能解析一个有效函数,损坏语法产生恢复错误;错误哈希和 ABI 的既有反例仍在。`codeguard grammar status --format=json` 现在列出 4 个候选、0 个已验收发行能力,Python 的缺口为 `language_qualification_and_release_pending`,且不执行解析。 + +本次**只增加资产候选**。Python 的语言版本/方言范围、合法与非法语料、原生 Ruff/编译器对照、worker 资源隔离、`lint python` 原生优先接线、任务复检、包内分发与宿主对话均未验收。Python WASM 不能代替原生 lint,也不赋予交付通过权威;OpenSpec 14.1、14.2 保持未完成。 + +验证:`cargo test --locked -p codeguard-adapters --test grammar_asset_manifest` 3/3 通过;`cargo test --locked -p codeguard-runtime --features wasm-precheck --test wasm_grammar_load` 2/2 通过;`cargo test --locked -p codeguard-cli --test grammar_status_cli` 2/2 通过。`cargo test --workspace --locked --quiet --no-fail-fast` 整体退出 0,默认 ignored 的真实原生工具测试未计作通过。全 workspace、全部 targets、启用 `codeguard-cli/wasm-precheck` 的 Clippy `-D warnings`,格式、分层检查、OpenSpec strict、清单 Draft 2020-12 schema 验证和 diff 检查均通过。本机无 Rust 1.85,MSRV 实编仍未验收。