diff --git a/project-docs/phase13-legal-knowledge-template-library/README.md b/project-docs/phase13-legal-knowledge-template-library/README.md new file mode 100644 index 00000000..cce9d5db --- /dev/null +++ b/project-docs/phase13-legal-knowledge-template-library/README.md @@ -0,0 +1,28 @@ +# Phase 13 Legal Knowledge And Template Library + +This package is the production pilot data foundation for the AI Contract Platform legal knowledge base and contract template library. + +Current scope: + +1. Mainland China enterprise civil and commercial contract scenarios. +2. Official legal source inventory. +3. Legal knowledge card schema. +4. Contract review risk rule schema. +5. Standard clause library schema. +6. Contract template schema. +7. Golden sample schema for review, generation, and KB Q&A. +8. Expert review register schema. + +Important rules: + +1. Do not store real customer contracts, personal information, secrets, Webhook URLs, or administrator passwords in this package. +2. Third-party articles may only be clues. They cannot be final legal authority. +3. A source can become production-ready only after official source detail, validity, and legal reviewer fields are completed. +4. Generated contracts and review findings must cite source IDs instead of unsupported model memory. +5. This package supports legal and business review. It does not replace advice from qualified legal professionals. + +Status: + +- Phase 13.0 schema baseline: in progress. +- Phase 13.1 official source inventory: in progress. +- Production publishing: blocked until legal/business review is complete. diff --git a/project-docs/phase13-legal-knowledge-template-library/clause-library/README.md b/project-docs/phase13-legal-knowledge-template-library/clause-library/README.md new file mode 100644 index 00000000..b7a4e11f --- /dev/null +++ b/project-docs/phase13-legal-knowledge-template-library/clause-library/README.md @@ -0,0 +1,3 @@ +# Clause Library + +Standard clauses will be added after legal source and review rule baselines are approved. Every clause must be listed in `inventories/clause-library-inventory.csv`. diff --git a/project-docs/phase13-legal-knowledge-template-library/clause-library/common/README.md b/project-docs/phase13-legal-knowledge-template-library/clause-library/common/README.md new file mode 100644 index 00000000..087b0830 --- /dev/null +++ b/project-docs/phase13-legal-knowledge-template-library/clause-library/common/README.md @@ -0,0 +1,3 @@ +# Common Clauses + +Scope: definitions, payment, delivery, acceptance, breach, termination, force majeure, notice, governing law, and dispute resolution. diff --git a/project-docs/phase13-legal-knowledge-template-library/clause-library/labor-service/README.md b/project-docs/phase13-legal-knowledge-template-library/clause-library/labor-service/README.md new file mode 100644 index 00000000..085e582c --- /dev/null +++ b/project-docs/phase13-legal-knowledge-template-library/clause-library/labor-service/README.md @@ -0,0 +1,3 @@ +# Labor And Service Clauses + +Scope: labor service boundary, work scope, fee, confidentiality, compliance, and employment-risk warnings. diff --git a/project-docs/phase13-legal-knowledge-template-library/clause-library/nda/README.md b/project-docs/phase13-legal-knowledge-template-library/clause-library/nda/README.md new file mode 100644 index 00000000..ac3ec739 --- /dev/null +++ b/project-docs/phase13-legal-knowledge-template-library/clause-library/nda/README.md @@ -0,0 +1,3 @@ +# NDA Clauses + +Scope: confidential information, exclusions, confidentiality term, use restrictions, breach, and return/destruction. diff --git a/project-docs/phase13-legal-knowledge-template-library/clause-library/purchase/README.md b/project-docs/phase13-legal-knowledge-template-library/clause-library/purchase/README.md new file mode 100644 index 00000000..7f0a8dec --- /dev/null +++ b/project-docs/phase13-legal-knowledge-template-library/clause-library/purchase/README.md @@ -0,0 +1,3 @@ +# Purchase Clauses + +Scope: purchase order, delivery, quality acceptance, payment, warranty, and return/replacement clauses. diff --git a/project-docs/phase13-legal-knowledge-template-library/clause-library/service/README.md b/project-docs/phase13-legal-knowledge-template-library/clause-library/service/README.md new file mode 100644 index 00000000..50983546 --- /dev/null +++ b/project-docs/phase13-legal-knowledge-template-library/clause-library/service/README.md @@ -0,0 +1,3 @@ +# Service Clauses + +Scope: service scope, milestones, acceptance, service level, payment, and breach clauses. diff --git a/project-docs/phase13-legal-knowledge-template-library/clause-library/software-saas/README.md b/project-docs/phase13-legal-knowledge-template-library/clause-library/software-saas/README.md new file mode 100644 index 00000000..883883cf --- /dev/null +++ b/project-docs/phase13-legal-knowledge-template-library/clause-library/software-saas/README.md @@ -0,0 +1,3 @@ +# Software And SaaS Clauses + +Scope: software license, SaaS service level, data processing, cybersecurity, account management, and service suspension. diff --git a/project-docs/phase13-legal-knowledge-template-library/clause-library/technology-development/README.md b/project-docs/phase13-legal-knowledge-template-library/clause-library/technology-development/README.md new file mode 100644 index 00000000..fed041c2 --- /dev/null +++ b/project-docs/phase13-legal-knowledge-template-library/clause-library/technology-development/README.md @@ -0,0 +1,3 @@ +# Technology Development Clauses + +Scope: deliverables, milestones, technical成果, acceptance, IP ownership, confidentiality, and maintenance. diff --git a/project-docs/phase13-legal-knowledge-template-library/contract-templates/README.md b/project-docs/phase13-legal-knowledge-template-library/contract-templates/README.md new file mode 100644 index 00000000..463af9a2 --- /dev/null +++ b/project-docs/phase13-legal-knowledge-template-library/contract-templates/README.md @@ -0,0 +1,3 @@ +# Contract Templates + +Production templates will be added after clause library and variable schema review. Every template must be listed in `inventories/contract-template-inventory.csv`. diff --git a/project-docs/phase13-legal-knowledge-template-library/contract-templates/labor-service/README.md b/project-docs/phase13-legal-knowledge-template-library/contract-templates/labor-service/README.md new file mode 100644 index 00000000..e8a64e7f --- /dev/null +++ b/project-docs/phase13-legal-knowledge-template-library/contract-templates/labor-service/README.md @@ -0,0 +1,3 @@ +# Labor And Service Templates + +Planned first-batch template: labor/service-related agreement. diff --git a/project-docs/phase13-legal-knowledge-template-library/contract-templates/nda/README.md b/project-docs/phase13-legal-knowledge-template-library/contract-templates/nda/README.md new file mode 100644 index 00000000..6dc28ab3 --- /dev/null +++ b/project-docs/phase13-legal-knowledge-template-library/contract-templates/nda/README.md @@ -0,0 +1,3 @@ +# NDA Templates + +Planned first-batch template: non-disclosure agreement. diff --git a/project-docs/phase13-legal-knowledge-template-library/contract-templates/purchase/README.md b/project-docs/phase13-legal-knowledge-template-library/contract-templates/purchase/README.md new file mode 100644 index 00000000..4a40f652 --- /dev/null +++ b/project-docs/phase13-legal-knowledge-template-library/contract-templates/purchase/README.md @@ -0,0 +1,3 @@ +# Purchase Contract Templates + +Planned first-batch template: purchase contract. diff --git a/project-docs/phase13-legal-knowledge-template-library/contract-templates/service/README.md b/project-docs/phase13-legal-knowledge-template-library/contract-templates/service/README.md new file mode 100644 index 00000000..ccf254ad --- /dev/null +++ b/project-docs/phase13-legal-knowledge-template-library/contract-templates/service/README.md @@ -0,0 +1,3 @@ +# Service Contract Templates + +Planned first-batch template: service contract. diff --git a/project-docs/phase13-legal-knowledge-template-library/contract-templates/software-saas/README.md b/project-docs/phase13-legal-knowledge-template-library/contract-templates/software-saas/README.md new file mode 100644 index 00000000..9aa105f9 --- /dev/null +++ b/project-docs/phase13-legal-knowledge-template-library/contract-templates/software-saas/README.md @@ -0,0 +1,3 @@ +# Software And SaaS Templates + +Planned first-batch template: software/SaaS service contract. diff --git a/project-docs/phase13-legal-knowledge-template-library/contract-templates/technology-development/README.md b/project-docs/phase13-legal-knowledge-template-library/contract-templates/technology-development/README.md new file mode 100644 index 00000000..948685a1 --- /dev/null +++ b/project-docs/phase13-legal-knowledge-template-library/contract-templates/technology-development/README.md @@ -0,0 +1,3 @@ +# Technology Development Templates + +Planned first-batch template: technology development contract. diff --git a/project-docs/phase13-legal-knowledge-template-library/evidence/README.md b/project-docs/phase13-legal-knowledge-template-library/evidence/README.md new file mode 100644 index 00000000..618f7809 --- /dev/null +++ b/project-docs/phase13-legal-knowledge-template-library/evidence/README.md @@ -0,0 +1,3 @@ +# Evidence + +This folder stores Phase 13 gate outputs, legal review evidence, import dry-run evidence, and production pilot publication evidence. diff --git a/project-docs/phase13-legal-knowledge-template-library/field-dictionary.md b/project-docs/phase13-legal-knowledge-template-library/field-dictionary.md new file mode 100644 index 00000000..e1dac35a --- /dev/null +++ b/project-docs/phase13-legal-knowledge-template-library/field-dictionary.md @@ -0,0 +1,41 @@ +# Phase 13 Field Dictionary + +## Common Fields + +| Field | Meaning | +|---|---| +| status | Lifecycle status: DRAFT, LEGAL_REVIEW, BUSINESS_REVIEW, APPROVED, PUBLISHED, DEPRECATED | +| owner | Asset owner responsible for maintenance | +| legal_reviewer | Legal reviewer; pending values cannot be published | +| business_reviewer | Business reviewer; pending values cannot be published | +| source_ids | Semicolon-separated legal source IDs | +| review_required | true when legal or business review is required before pilot import | +| production_ready | true only after review and gate pass | + +## Legal Source Fields + +| Field | Meaning | +|---|---| +| source_id | Unique legal source ID | +| title | Source title | +| source_type | law, judicial_interpretation, administrative_regulation, departmental_rule, official_guidance | +| issuer | Issuing authority | +| official_domain | Official source domain | +| source_url | Official portal or detail URL | +| retrieval_hint | How to retrieve the source from official portal | +| effective_date | Effective date or VERIFY_REQUIRED | +| validity_status | EFFECTIVE, DEPRECATED, SUPERSEDED, VERIFY_REQUIRED | +| contract_scope | Contract scenarios covered | +| knowledge_domain | Phase 13 domain folder | + +## Template Fields + +| Field | Meaning | +|---|---| +| template_id | Unique template ID | +| template_name | User-facing template name | +| contract_type | Contract type | +| variable_schema_path | Schema file path for variables | +| clause_ids | Bound standard clause IDs | +| generation_sample_ids | Bound generation sample IDs | +| review_rule_ids | Bound review rules | diff --git a/project-docs/phase13-legal-knowledge-template-library/governance-rules.md b/project-docs/phase13-legal-knowledge-template-library/governance-rules.md new file mode 100644 index 00000000..34eafdc4 --- /dev/null +++ b/project-docs/phase13-legal-knowledge-template-library/governance-rules.md @@ -0,0 +1,49 @@ +# Phase 13 Governance Rules + +## Scope + +Default jurisdiction is mainland China. Default business scope is enterprise civil and commercial contracts. + +## Allowed Statuses + +| Status | Meaning | +|---|---| +| DRAFT | Created but not reviewed | +| LEGAL_REVIEW | Waiting for legal professional review | +| BUSINESS_REVIEW | Waiting for business owner review | +| APPROVED | Reviewed and can enter pilot import | +| PUBLISHED | Imported into pilot or production environment | +| DEPRECATED | Superseded or no longer valid | + +## ID Prefixes + +| Prefix | Asset | +|---|---| +| LAW | Official legal source | +| KC | Legal knowledge card | +| RULE | Contract review risk rule | +| CLAUSE | Standard clause | +| TPL | Contract template | +| REVIEW-SAMPLE | Review golden sample | +| GEN-SAMPLE | Generation golden sample | +| KBQA-SAMPLE | KB Q&A golden sample | +| EXPERT | Expert review record | + +## Production Readiness + +An asset is not production-ready unless: + +1. Source IDs are traceable to official domains. +2. Validity status is verified. +3. Legal reviewer is recorded for legal assets. +4. Business reviewer is recorded for business templates or clauses. +5. Regression or acceptance sample is recorded. + +## Refusal Boundary + +The platform must refuse or ask for human review when: + +1. The requested contract type is outside the approved template scope. +2. The legal source is missing or not verified. +3. The answer would require legal judgment beyond the knowledge card. +4. A high-risk clause has no approved fallback wording. diff --git a/project-docs/phase13-legal-knowledge-template-library/inventories/README.md b/project-docs/phase13-legal-knowledge-template-library/inventories/README.md new file mode 100644 index 00000000..30c0558a --- /dev/null +++ b/project-docs/phase13-legal-knowledge-template-library/inventories/README.md @@ -0,0 +1,9 @@ +# Phase 13 Inventories + +Inventories are the only approved entry point for Phase 13 assets. Every legal source, knowledge card, rule, clause, template, sample, and review record must be listed here before it can be imported into the platform. + +First-batch rule: + +1. `legal-source-inventory.csv` may contain official source collection targets with `VERIFY_REQUIRED`. +2. No asset may be marked `PUBLISHED` until legal/business review is complete. +3. Header-only inventories are allowed during Phase 13.0, but they must pass schema checks. diff --git a/project-docs/phase13-legal-knowledge-template-library/inventories/clause-library-inventory.csv b/project-docs/phase13-legal-knowledge-template-library/inventories/clause-library-inventory.csv new file mode 100644 index 00000000..ae720c87 --- /dev/null +++ b/project-docs/phase13-legal-knowledge-template-library/inventories/clause-library-inventory.csv @@ -0,0 +1 @@ +clause_id,clause_name,contract_type,clause_category,source_ids,applicable_conditions,excluded_conditions,variant_group,risk_notes_path,clause_path,status,owner,legal_reviewer,business_reviewer,review_required,production_ready,notes diff --git a/project-docs/phase13-legal-knowledge-template-library/inventories/contract-template-inventory.csv b/project-docs/phase13-legal-knowledge-template-library/inventories/contract-template-inventory.csv new file mode 100644 index 00000000..1636fa0d --- /dev/null +++ b/project-docs/phase13-legal-knowledge-template-library/inventories/contract-template-inventory.csv @@ -0,0 +1 @@ +template_id,template_name,contract_type,template_path,variable_schema_path,required_variables,optional_variables,clause_ids,review_rule_ids,generation_sample_ids,status,owner,legal_reviewer,business_reviewer,review_required,production_ready,notes diff --git a/project-docs/phase13-legal-knowledge-template-library/inventories/expert-review-register.csv b/project-docs/phase13-legal-knowledge-template-library/inventories/expert-review-register.csv new file mode 100644 index 00000000..9a1e430d --- /dev/null +++ b/project-docs/phase13-legal-knowledge-template-library/inventories/expert-review-register.csv @@ -0,0 +1 @@ +review_id,asset_type,asset_id,reviewer,reviewer_role,review_date,review_result,required_changes,follow_up_owner,evidence_path,status,notes diff --git a/project-docs/phase13-legal-knowledge-template-library/inventories/generation-golden-sample-inventory.csv b/project-docs/phase13-legal-knowledge-template-library/inventories/generation-golden-sample-inventory.csv new file mode 100644 index 00000000..f4f29ec8 --- /dev/null +++ b/project-docs/phase13-legal-knowledge-template-library/inventories/generation-golden-sample-inventory.csv @@ -0,0 +1 @@ +sample_id,template_id,contract_type,variable_payload_path,expected_document_path,expected_review_rule_ids,expected_source_citations,status,owner,legal_reviewer,business_reviewer,review_required,production_ready,notes diff --git a/project-docs/phase13-legal-knowledge-template-library/inventories/kb-qa-golden-sample-inventory.csv b/project-docs/phase13-legal-knowledge-template-library/inventories/kb-qa-golden-sample-inventory.csv new file mode 100644 index 00000000..62dba7ea --- /dev/null +++ b/project-docs/phase13-legal-knowledge-template-library/inventories/kb-qa-golden-sample-inventory.csv @@ -0,0 +1 @@ +sample_id,question,expected_answer_boundary,expected_source_ids,expected_citation_required,expected_refusal_required,status,owner,legal_reviewer,review_required,production_ready,notes diff --git a/project-docs/phase13-legal-knowledge-template-library/inventories/legal-knowledge-card-inventory.csv b/project-docs/phase13-legal-knowledge-template-library/inventories/legal-knowledge-card-inventory.csv new file mode 100644 index 00000000..4797a507 --- /dev/null +++ b/project-docs/phase13-legal-knowledge-template-library/inventories/legal-knowledge-card-inventory.csv @@ -0,0 +1 @@ +knowledge_card_id,title,source_ids,legal_question,applicable_scenarios,non_applicable_scenarios,summary_path,original_reference,answer_boundary,status,owner,legal_reviewer,review_required,production_ready,notes diff --git a/project-docs/phase13-legal-knowledge-template-library/inventories/legal-source-inventory.csv b/project-docs/phase13-legal-knowledge-template-library/inventories/legal-source-inventory.csv new file mode 100644 index 00000000..20046a10 --- /dev/null +++ b/project-docs/phase13-legal-knowledge-template-library/inventories/legal-source-inventory.csv @@ -0,0 +1,21 @@ +source_id,title,source_type,issuer,official_domain,source_url,retrieval_hint,effective_date,validity_status,contract_scope,knowledge_domain,review_required,status,owner,legal_reviewer,collection_date,notes +LAW-CIVIL-001,中华人民共和国民法典,law,全国人民代表大会,flk.npc.gov.cn,https://flk.npc.gov.cn/,国家法律法规数据库检索:中华人民共和国民法典,2021-01-01,VERIFY_REQUIRED,合同通用;合同编;civil liability,civil-code,true,LEGAL_REVIEW,legal-ops,pending,2026-05-01,第一批核心法源;需补充官方详情页和条款索引 +LAW-CONTRACT-001,最高人民法院关于适用中华人民共和国民法典合同编通则若干问题的解释,judicial_interpretation,最高人民法院,www.court.gov.cn,https://www.court.gov.cn/,最高人民法院官网检索:民法典 合同编 通则 解释,VERIFY_REQUIRED,VERIFY_REQUIRED,合同通用;合同成立;效力;履行,judicial-interpretations,true,LEGAL_REVIEW,legal-ops,pending,2026-05-01,需法务确认法释编号和施行日期 +LAW-COMPANY-001,中华人民共和国公司法,law,全国人民代表大会,flk.npc.gov.cn,https://flk.npc.gov.cn/,国家法律法规数据库检索:中华人民共和国公司法,VERIFY_REQUIRED,VERIFY_REQUIRED,主体资格;授权代表;公司治理,company-commercial,true,LEGAL_REVIEW,legal-ops,pending,2026-05-01,用于主体资格和授权审核 +LAW-LABOR-001,中华人民共和国劳动合同法,law,全国人民代表大会,flk.npc.gov.cn,https://flk.npc.gov.cn/,国家法律法规数据库检索:中华人民共和国劳动合同法,VERIFY_REQUIRED,VERIFY_REQUIRED,劳动合同;劳务边界,labor-employment,true,LEGAL_REVIEW,legal-ops,pending,2026-05-01,用于劳动与劳务模板边界 +LAW-LABOR-002,中华人民共和国劳动法,law,全国人民代表大会,flk.npc.gov.cn,https://flk.npc.gov.cn/,国家法律法规数据库检索:中华人民共和国劳动法,VERIFY_REQUIRED,VERIFY_REQUIRED,劳动用工;劳动保护,labor-employment,true,LEGAL_REVIEW,legal-ops,pending,2026-05-01,用于劳动相关合同风险识别 +LAW-TENDER-001,中华人民共和国招标投标法,law,全国人民代表大会,flk.npc.gov.cn,https://flk.npc.gov.cn/,国家法律法规数据库检索:中华人民共和国招标投标法,VERIFY_REQUIRED,VERIFY_REQUIRED,采购;招投标,procurement-tendering,true,LEGAL_REVIEW,legal-ops,pending,2026-05-01,用于采购合同合规边界 +LAW-PROCUREMENT-001,中华人民共和国政府采购法,law,全国人民代表大会,flk.npc.gov.cn,https://flk.npc.gov.cn/,国家法律法规数据库检索:中华人民共和国政府采购法,VERIFY_REQUIRED,VERIFY_REQUIRED,政府采购;采购流程,procurement-tendering,true,LEGAL_REVIEW,legal-ops,pending,2026-05-01,用于政府采购场景提示 +LAW-DATA-001,中华人民共和国个人信息保护法,law,全国人民代表大会,flk.npc.gov.cn,https://flk.npc.gov.cn/,国家法律法规数据库检索:中华人民共和国个人信息保护法,VERIFY_REQUIRED,VERIFY_REQUIRED,个人信息;数据处理;隐私,data-privacy,true,LEGAL_REVIEW,legal-ops,pending,2026-05-01,用于数据处理和隐私条款 +LAW-DATA-002,中华人民共和国数据安全法,law,全国人民代表大会,flk.npc.gov.cn,https://flk.npc.gov.cn/,国家法律法规数据库检索:中华人民共和国数据安全法,VERIFY_REQUIRED,VERIFY_REQUIRED,数据安全;数据处理,data-privacy,true,LEGAL_REVIEW,legal-ops,pending,2026-05-01,用于数据安全条款和审核 +LAW-DATA-003,中华人民共和国网络安全法,law,全国人民代表大会,flk.npc.gov.cn,https://flk.npc.gov.cn/,国家法律法规数据库检索:中华人民共和国网络安全法,VERIFY_REQUIRED,VERIFY_REQUIRED,网络服务;SaaS;数据安全,data-privacy,true,LEGAL_REVIEW,legal-ops,pending,2026-05-01,用于软件和SaaS合同条款 +LAW-IP-001,中华人民共和国著作权法,law,全国人民代表大会,flk.npc.gov.cn,https://flk.npc.gov.cn/,国家法律法规数据库检索:中华人民共和国著作权法,VERIFY_REQUIRED,VERIFY_REQUIRED,知识产权;软件著作权,intellectual-property,true,LEGAL_REVIEW,legal-ops,pending,2026-05-01,用于软件服务和技术开发模板 +LAW-IP-002,中华人民共和国专利法,law,全国人民代表大会,flk.npc.gov.cn,https://flk.npc.gov.cn/,国家法律法规数据库检索:中华人民共和国专利法,VERIFY_REQUIRED,VERIFY_REQUIRED,知识产权;技术成果,intellectual-property,true,LEGAL_REVIEW,legal-ops,pending,2026-05-01,用于技术开发成果归属 +LAW-IP-003,中华人民共和国商标法,law,全国人民代表大会,flk.npc.gov.cn,https://flk.npc.gov.cn/,国家法律法规数据库检索:中华人民共和国商标法,VERIFY_REQUIRED,VERIFY_REQUIRED,品牌授权;商标使用,intellectual-property,true,LEGAL_REVIEW,legal-ops,pending,2026-05-01,用于品牌和商标授权条款 +LAW-COMMERCIAL-001,中华人民共和国反不正当竞争法,law,全国人民代表大会,flk.npc.gov.cn,https://flk.npc.gov.cn/,国家法律法规数据库检索:中华人民共和国反不正当竞争法,VERIFY_REQUIRED,VERIFY_REQUIRED,商业秘密;竞争限制,company-commercial,true,LEGAL_REVIEW,legal-ops,pending,2026-05-01,用于保密和竞争相关条款 +LAW-ARBITRATION-001,中华人民共和国仲裁法,law,全国人民代表大会,flk.npc.gov.cn,https://flk.npc.gov.cn/,国家法律法规数据库检索:中华人民共和国仲裁法,VERIFY_REQUIRED,VERIFY_REQUIRED,争议解决;仲裁,company-commercial,true,LEGAL_REVIEW,legal-ops,pending,2026-05-01,用于争议解决条款 +LAW-CIVIL-PROCEDURE-001,中华人民共和国民事诉讼法,law,全国人民代表大会,flk.npc.gov.cn,https://flk.npc.gov.cn/,国家法律法规数据库检索:中华人民共和国民事诉讼法,VERIFY_REQUIRED,VERIFY_REQUIRED,争议解决;管辖,company-commercial,true,LEGAL_REVIEW,legal-ops,pending,2026-05-01,用于管辖和诉讼条款 +LAW-E-SIGN-001,中华人民共和国电子签名法,law,全国人民代表大会,flk.npc.gov.cn,https://flk.npc.gov.cn/,国家法律法规数据库检索:中华人民共和国电子签名法,VERIFY_REQUIRED,VERIFY_REQUIRED,电子签约;电子数据,company-commercial,true,LEGAL_REVIEW,legal-ops,pending,2026-05-01,用于电子合同签署场景 +LAW-E-COMMERCE-001,中华人民共和国电子商务法,law,全国人民代表大会,flk.npc.gov.cn,https://flk.npc.gov.cn/,国家法律法规数据库检索:中华人民共和国电子商务法,VERIFY_REQUIRED,VERIFY_REQUIRED,SaaS;平台服务;线上交易,company-commercial,true,LEGAL_REVIEW,legal-ops,pending,2026-05-01,用于线上服务合同边界 +LAW-MARKET-001,中华人民共和国消费者权益保护法,law,全国人民代表大会,flk.npc.gov.cn,https://flk.npc.gov.cn/,国家法律法规数据库检索:中华人民共和国消费者权益保护法,VERIFY_REQUIRED,VERIFY_REQUIRED,服务合同;消费者场景,company-commercial,true,LEGAL_REVIEW,legal-ops,pending,2026-05-01,用于B2C服务合同提示 +LAW-TECH-001,最高人民法院关于审理技术合同纠纷案件适用法律若干问题的解释,judicial_interpretation,最高人民法院,www.court.gov.cn,https://www.court.gov.cn/,最高人民法院官网检索:技术合同纠纷 司法解释,VERIFY_REQUIRED,VERIFY_REQUIRED,技术开发;技术服务,judicial-interpretations,true,LEGAL_REVIEW,legal-ops,pending,2026-05-01,需法务确认现行有效版本 diff --git a/project-docs/phase13-legal-knowledge-template-library/inventories/review-golden-sample-inventory.csv b/project-docs/phase13-legal-knowledge-template-library/inventories/review-golden-sample-inventory.csv new file mode 100644 index 00000000..9fad9848 --- /dev/null +++ b/project-docs/phase13-legal-knowledge-template-library/inventories/review-golden-sample-inventory.csv @@ -0,0 +1 @@ +sample_id,contract_type,risk_categories,source_ids,input_sample_path,expected_findings_path,expected_severity,expected_source_citations,status,owner,legal_reviewer,review_required,production_ready,notes diff --git a/project-docs/phase13-legal-knowledge-template-library/inventories/review-risk-rule-inventory.csv b/project-docs/phase13-legal-knowledge-template-library/inventories/review-risk-rule-inventory.csv new file mode 100644 index 00000000..921db345 --- /dev/null +++ b/project-docs/phase13-legal-knowledge-template-library/inventories/review-risk-rule-inventory.csv @@ -0,0 +1 @@ +rule_id,risk_category,risk_name,severity,source_ids,clause_ids,trigger_condition,review_output_template,modification_suggestion_path,human_review_required,status,owner,legal_reviewer,review_sample_ids,production_ready,notes diff --git a/project-docs/phase13-legal-knowledge-template-library/legal-sources/README.md b/project-docs/phase13-legal-knowledge-template-library/legal-sources/README.md new file mode 100644 index 00000000..23ffbe10 --- /dev/null +++ b/project-docs/phase13-legal-knowledge-template-library/legal-sources/README.md @@ -0,0 +1,9 @@ +# Legal Sources + +This folder stores official legal source extraction notes after the source has been confirmed from an approved official domain. + +Current first-batch inventory lives in: + +`../inventories/legal-source-inventory.csv` + +No raw copied full law text should be stored here unless copyright and source policy are confirmed. Prefer structured references, article ranges, official URLs, and extraction notes. diff --git a/project-docs/phase13-legal-knowledge-template-library/legal-sources/civil-code/README.md b/project-docs/phase13-legal-knowledge-template-library/legal-sources/civil-code/README.md new file mode 100644 index 00000000..ef9fac99 --- /dev/null +++ b/project-docs/phase13-legal-knowledge-template-library/legal-sources/civil-code/README.md @@ -0,0 +1,3 @@ +# Civil Code Sources + +Scope: Civil Code general provisions, contract formation, validity, performance, breach, termination, and liability. diff --git a/project-docs/phase13-legal-knowledge-template-library/legal-sources/company-commercial/README.md b/project-docs/phase13-legal-knowledge-template-library/legal-sources/company-commercial/README.md new file mode 100644 index 00000000..0783decf --- /dev/null +++ b/project-docs/phase13-legal-knowledge-template-library/legal-sources/company-commercial/README.md @@ -0,0 +1,3 @@ +# Company And Commercial Sources + +Scope: company authority, commercial operations, dispute resolution, arbitration, electronic signatures, and competition-related contract risks. diff --git a/project-docs/phase13-legal-knowledge-template-library/legal-sources/data-privacy/README.md b/project-docs/phase13-legal-knowledge-template-library/legal-sources/data-privacy/README.md new file mode 100644 index 00000000..99e80214 --- /dev/null +++ b/project-docs/phase13-legal-knowledge-template-library/legal-sources/data-privacy/README.md @@ -0,0 +1,3 @@ +# Data And Privacy Sources + +Scope: personal information protection, data security, cybersecurity, data processing, and SaaS data clauses. diff --git a/project-docs/phase13-legal-knowledge-template-library/legal-sources/intellectual-property/README.md b/project-docs/phase13-legal-knowledge-template-library/legal-sources/intellectual-property/README.md new file mode 100644 index 00000000..f01e53dc --- /dev/null +++ b/project-docs/phase13-legal-knowledge-template-library/legal-sources/intellectual-property/README.md @@ -0,0 +1,3 @@ +# Intellectual Property Sources + +Scope: copyright, patent, trademark, technical成果, software deliverables, licensing, and ownership clauses. diff --git a/project-docs/phase13-legal-knowledge-template-library/legal-sources/judicial-interpretations/README.md b/project-docs/phase13-legal-knowledge-template-library/legal-sources/judicial-interpretations/README.md new file mode 100644 index 00000000..0f2a01a2 --- /dev/null +++ b/project-docs/phase13-legal-knowledge-template-library/legal-sources/judicial-interpretations/README.md @@ -0,0 +1,3 @@ +# Judicial Interpretation Sources + +Scope: Supreme People's Court interpretations and official judicial guidance for contract disputes. diff --git a/project-docs/phase13-legal-knowledge-template-library/legal-sources/labor-employment/README.md b/project-docs/phase13-legal-knowledge-template-library/legal-sources/labor-employment/README.md new file mode 100644 index 00000000..bf1b142c --- /dev/null +++ b/project-docs/phase13-legal-knowledge-template-library/legal-sources/labor-employment/README.md @@ -0,0 +1,3 @@ +# Labor And Employment Sources + +Scope: labor contract, labor service boundary, employment compliance, and worker protection. diff --git a/project-docs/phase13-legal-knowledge-template-library/legal-sources/procurement-tendering/README.md b/project-docs/phase13-legal-knowledge-template-library/legal-sources/procurement-tendering/README.md new file mode 100644 index 00000000..0a92ffa2 --- /dev/null +++ b/project-docs/phase13-legal-knowledge-template-library/legal-sources/procurement-tendering/README.md @@ -0,0 +1,3 @@ +# Procurement And Tendering Sources + +Scope: procurement, bidding, tendering, government procurement, and purchase contract compliance. diff --git a/project-docs/phase13-legal-knowledge-template-library/qa-samples/README.md b/project-docs/phase13-legal-knowledge-template-library/qa-samples/README.md new file mode 100644 index 00000000..1e4d0bfb --- /dev/null +++ b/project-docs/phase13-legal-knowledge-template-library/qa-samples/README.md @@ -0,0 +1,3 @@ +# QA Samples + +Golden samples are used by review quality, generation quality, and KB Q&A gates. Sample inventories live in `../inventories/`. diff --git a/project-docs/phase13-legal-knowledge-template-library/qa-samples/generation/README.md b/project-docs/phase13-legal-knowledge-template-library/qa-samples/generation/README.md new file mode 100644 index 00000000..6ef622fd --- /dev/null +++ b/project-docs/phase13-legal-knowledge-template-library/qa-samples/generation/README.md @@ -0,0 +1,3 @@ +# Generation Samples + +Generation samples will be added after first-batch templates are drafted. diff --git a/project-docs/phase13-legal-knowledge-template-library/qa-samples/kb-qa/README.md b/project-docs/phase13-legal-knowledge-template-library/qa-samples/kb-qa/README.md new file mode 100644 index 00000000..19336e0f --- /dev/null +++ b/project-docs/phase13-legal-knowledge-template-library/qa-samples/kb-qa/README.md @@ -0,0 +1,3 @@ +# KB QA Samples + +KB Q&A samples will validate source citation, refusal boundary, and human-review prompts. diff --git a/project-docs/phase13-legal-knowledge-template-library/qa-samples/review/README.md b/project-docs/phase13-legal-knowledge-template-library/qa-samples/review/README.md new file mode 100644 index 00000000..117f51a0 --- /dev/null +++ b/project-docs/phase13-legal-knowledge-template-library/qa-samples/review/README.md @@ -0,0 +1,3 @@ +# Review Samples + +Review samples will be added after review risk rules are drafted. diff --git a/project-docs/闭环交付与深度开发方案-2026-05-01.md b/project-docs/闭环交付与深度开发方案-2026-05-01.md index 9c7bcc27..4fb4895d 100644 --- a/project-docs/闭环交付与深度开发方案-2026-05-01.md +++ b/project-docs/闭环交付与深度开发方案-2026-05-01.md @@ -24,7 +24,7 @@ | 阶段 10:生产化交付包、培训移交与验收闭环 | PASS_WITH_WEBHOOK_BLOCKED | `project-docs/阶段10-生产化交付包培训移交与验收闭环执行记录-2026-05-01.md` | | 阶段 11:规模化运营、多租户组织接入与 SLA 闭环 | PASS_WITH_WEBHOOK_BLOCKED | `project-docs/阶段11-规模化运营多租户组织接入与SLA闭环执行记录-2026-05-01.md` | | 阶段 12:V2 产品演进、集成扩展与长期路线图闭环 | PASS_WITH_WEBHOOK_BLOCKED | `project-docs/阶段12-V2产品演进集成扩展与长期路线图闭环执行记录-2026-05-01.md` | -| 阶段 13:法律知识库与合同模板库建设闭环 | PLANNED | `project-docs/阶段13-法律知识库与合同模板库建设闭环方案-2026-05-01.md` | +| 阶段 13:法律知识库与合同模板库建设闭环 | IN_PROGRESS | `project-docs/阶段13-法律知识库与合同模板库建设闭环方案-2026-05-01.md`、`project-docs/阶段13-法律知识库与合同模板库建设闭环第一批执行记录-2026-05-01.md` | 阶段 1 已完成源码闭环与生产入口闭环,生产无人 E2E `18/18` 通过。阶段 2 已完成 Review 重试、Knowledge Base 文档重试、Review -> Chat -> Contract 上下文联动、首页交付工作台和阶段 2 自动化无人闭环,本地与生产 E2E 均 `7/7` 通过。阶段 3 已完成系统 readiness、试点交付准备页、默认账号说明、演示样本数据、依赖健康门禁和阶段 3 自动化无人闭环,本地与生产 E2E 均 `5/5` 通过。 @@ -246,3 +246,5 @@ AI合同平台阶段 1、阶段 2、阶段 3、阶段 4、阶段 5、阶段 6、 阶段 11 已完成完整闭环:`scripts/run-scale-ops-gate.ps1` 已固化为规模化运营、多租户组织接入与 SLA/SLO 统一门禁,最终证据为 `project-docs/qa-artifacts/phase11-scale-ops-gate/2026-05-01T19-12-28-407/`。最终门禁在干净工作区下执行,容量指标 `7` 项、性能指标 `7` 项、租户隔离检查 `7` 项、Ready 组织 `3` 个、规划用户 `200`、SLA/SLO 指标 `8` 项、集成项 `6` 项、风险项 `6` 项全部通过,必需失败项为 `0`,警告项为 `0`。阶段状态为 `PASS_WITH_WEBHOOK_BLOCKED`,外部 Webhook 阻塞继续作为前序外部条件保留。 阶段 12 已完成完整闭环:`scripts/run-v2-roadmap-gate.ps1` 已固化为 V2 产品演进、集成扩展与长期路线图统一门禁,阶段证据为 `project-docs/qa-artifacts/phase12-v2-roadmap-gate/2026-05-01T19-22-48-772/`。V2 需求 `12` 项、首批开发 `6` 项、路线图 `12` 项、范围决策 `12` 项、集成扩展 `6` 项、技术预研 `5` 项、验收标准 `10` 项全部通过,必需失败项为 `0`。阶段状态为 `PASS_WITH_WEBHOOK_BLOCKED`,外部 Webhook 阻塞继续作为唯一外部条件保留。阶段 8-12 已收束为可实施的 V2 `now/next/later/blocked` 路线图。 + +阶段 13 已进入第一批建设:`project-docs/phase13-legal-knowledge-template-library/` 资料包、`9` 个 inventory schema、第一批 `20` 条官方法源采集任务和 `scripts/run-legal-knowledge-library-gate.ps1` 已落地。第一批门禁状态为 `PASS_WITH_LEGAL_REVIEW_REQUIRED`,必需失败项为 `0`;所有法源均保持 `LEGAL_REVIEW` 和 `VERIFY_REQUIRED`,在法务复核前不得作为生产确定性依据。 diff --git a/project-docs/阶段13-法律知识库与合同模板库建设闭环方案-2026-05-01.md b/project-docs/阶段13-法律知识库与合同模板库建设闭环方案-2026-05-01.md index cccbee34..d2d7d58b 100644 --- a/project-docs/阶段13-法律知识库与合同模板库建设闭环方案-2026-05-01.md +++ b/project-docs/阶段13-法律知识库与合同模板库建设闭环方案-2026-05-01.md @@ -394,4 +394,6 @@ project-docs/phase13-legal-knowledge-template-library/ 5. 实现 `scripts/run-legal-knowledge-library-gate.ps1` 的第一版,只做结构、字段、法源白名单和敏感信息门禁。 6. 第一版门禁通过后,再开始填充法源、知识卡、规则、条款和模板正文。 -阶段 13 当前状态:`PLANNED`。 +阶段 13 当前状态:`IN_PROGRESS`。 + +当前第一批执行结果:`13.0` 和 `13.1` 已完成工程化底座,资料包、清单 schema、第一批 `20` 条官方法源采集任务和 `scripts/run-legal-knowledge-library-gate.ps1` 已落地。门禁状态为 `PASS_WITH_LEGAL_REVIEW_REQUIRED`,所有法源在法务复核前不得作为生产确定性依据。 diff --git a/project-docs/阶段13-法律知识库与合同模板库建设闭环第一批执行记录-2026-05-01.md b/project-docs/阶段13-法律知识库与合同模板库建设闭环第一批执行记录-2026-05-01.md new file mode 100644 index 00000000..e52e36aa --- /dev/null +++ b/project-docs/阶段13-法律知识库与合同模板库建设闭环第一批执行记录-2026-05-01.md @@ -0,0 +1,110 @@ +# AI合同平台 阶段 13 法律知识库与合同模板库建设闭环第一批执行记录(2026-05-01) + +## 一、阶段结论 + +阶段 13 第一批已完成 `13.0 治理口径与资料 schema` 和 `13.1 法源资料采集` 的工程化底座,当前状态为 `PASS_WITH_LEGAL_REVIEW_REQUIRED`。 + +本批次不是最终生产发布,而是把法律知识库与合同模板库从“想法”落成可校验的资料包结构、清单 schema、第一批官方法源采集任务和自动化门禁。所有法源均标记为 `LEGAL_REVIEW` 和 `VERIFY_REQUIRED`,在法务复核完成前不得作为生产确定性依据。 + +## 二、本批次交付 + +新增资料包: + +`project-docs/phase13-legal-knowledge-template-library/` + +关键交付物: + +1. `README.md` +2. `governance-rules.md` +3. `field-dictionary.md` +4. `inventories/legal-source-inventory.csv` +5. `inventories/legal-knowledge-card-inventory.csv` +6. `inventories/review-risk-rule-inventory.csv` +7. `inventories/clause-library-inventory.csv` +8. `inventories/contract-template-inventory.csv` +9. `inventories/review-golden-sample-inventory.csv` +10. `inventories/generation-golden-sample-inventory.csv` +11. `inventories/kb-qa-golden-sample-inventory.csv` +12. `inventories/expert-review-register.csv` +13. `legal-sources/*/README.md` +14. `clause-library/*/README.md` +15. `contract-templates/*/README.md` +16. `qa-samples/*/README.md` +17. `evidence/README.md` +18. `scripts/run-legal-knowledge-library-gate.ps1` + +## 三、第一批法源范围 + +第一批已建立 `20` 条官方法源采集任务,覆盖以下知识域: + +1. `civil-code` +2. `judicial-interpretations` +3. `company-commercial` +4. `labor-employment` +5. `procurement-tendering` +6. `data-privacy` +7. `intellectual-property` + +法源入口仅允许白名单官方域名,包括: + +1. `flk.npc.gov.cn` +2. `www.npc.gov.cn` +3. `www.court.gov.cn` +4. `gongbao.court.gov.cn` +5. `www.gov.cn` +6. `www.moj.gov.cn` +7. `www.samr.gov.cn` +8. `www.cac.gov.cn` +9. `www.mohrss.gov.cn` +10. `www.cnipa.gov.cn` + +## 四、自动化门禁结果 + +执行命令: + +```powershell +powershell.exe -NoProfile -ExecutionPolicy Bypass -File scripts\run-legal-knowledge-library-gate.ps1 +``` + +门禁输出: + +```text +PHASE13_LEGAL_KNOWLEDGE_LIBRARY_GATE_PASS_WITH_LEGAL_REVIEW_REQUIRED D:\ai-contract-platform\project-docs\qa-artifacts\phase13-legal-knowledge-library-gate\2026-05-01T19-56-24-115 +``` + +门禁证据: + +`project-docs/qa-artifacts/phase13-legal-knowledge-library-gate/2026-05-01T19-56-24-115/` + +门禁统计: + +| 指标 | 结果 | +|---|---:| +| 法源采集任务 | 20 | +| 官方白名单域名 | 10 | +| 知识域覆盖 | 7 | +| Inventory 文件 | 9 | +| 必需失败项 | 0 | +| 法务复核待办 | 20 | + +说明:本批次在提交前运行,因此存在非阻塞工作区提示。提交后需再次运行同一门禁,确认工作区干净状态。 + +## 五、当前保留项 + +| 保留项 | 状态 | 说明 | +|---|---|---| +| 法源详情页确认 | LEGAL_REVIEW | 当前 `source_url` 记录官方入口,后续需补充或确认官方详情页 | +| 生效日期与有效状态 | VERIFY_REQUIRED | 不在未复核状态下写死可能变化或可能误记的生效信息 | +| 法律专家复核 | PENDING | `legal_reviewer` 当前为 `pending` | +| 生产发布 | BLOCKED_BY_REVIEW | 复核完成前不得进入生产索引或作为确定性依据 | + +## 六、下一步 + +下一批应进入 `13.2 法律知识卡建设` 和 `13.3 合同审核规则库`: + +1. 对 20 条法源逐条补充官方详情页、有效状态和法务复核记录。 +2. 从民法典合同编和合同编通则司法解释开始拆解法律知识卡。 +3. 先建立付款、违约、解除、争议解决、保密、知识产权、数据处理等高频审核规则。 +4. 将审核规则绑定法源 ID、严重等级、修改建议和黄金样本。 + +阶段 13 第一批当前状态:`PASS_WITH_LEGAL_REVIEW_REQUIRED`。 diff --git a/scripts/run-legal-knowledge-library-gate.ps1 b/scripts/run-legal-knowledge-library-gate.ps1 new file mode 100644 index 00000000..efbc2296 --- /dev/null +++ b/scripts/run-legal-knowledge-library-gate.ps1 @@ -0,0 +1,466 @@ +param( + [string]$ArtifactRoot = "", + [string]$LibraryRoot = "", + [int]$MinLegalSources = 20, + [switch]$FailOnWarn, + [switch]$FailOnLegalReviewRequired +) + +$ErrorActionPreference = "Stop" + +$repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path +$timestamp = Get-Date -Format "yyyy-MM-ddTHH-mm-ss-fff" + +if ([string]::IsNullOrWhiteSpace($ArtifactRoot)) { + $ArtifactRoot = Join-Path $repoRoot "project-docs\qa-artifacts\phase13-legal-knowledge-library-gate" +} +if ([string]::IsNullOrWhiteSpace($LibraryRoot)) { + $LibraryRoot = Join-Path $repoRoot "project-docs\phase13-legal-knowledge-template-library" +} +foreach ($pathName in @("ArtifactRoot", "LibraryRoot")) { + $value = Get-Variable -Name $pathName -ValueOnly + if (-not [System.IO.Path]::IsPathRooted($value)) { + Set-Variable -Name $pathName -Value (Join-Path $repoRoot $value) + } +} + +$artifactDir = Join-Path $ArtifactRoot $timestamp +New-Item -ItemType Directory -Force -Path $artifactDir | Out-Null + +$summaryJson = Join-Path $artifactDir "legal-knowledge-library-gate-summary.json" +$summaryMd = Join-Path $artifactDir "legal-knowledge-library-gate-summary.md" +$gitStatusPath = Join-Path $artifactDir "git-status.txt" +$sourceReportCsv = Join-Path $artifactDir "phase13-legal-source-report.csv" +$inventoryReportCsv = Join-Path $artifactDir "phase13-inventory-schema-report.csv" + +$checks = New-Object System.Collections.Generic.List[object] +$inventoryReport = New-Object System.Collections.Generic.List[object] + +$allowedDomains = @( + "flk.npc.gov.cn", + "www.npc.gov.cn", + "www.court.gov.cn", + "gongbao.court.gov.cn", + "www.gov.cn", + "www.moj.gov.cn", + "www.samr.gov.cn", + "www.cac.gov.cn", + "www.mohrss.gov.cn", + "www.cnipa.gov.cn" +) + +function Add-Check { + param( + [string]$Key, + [string]$Label, + [ValidateSet("pass", "fail", "warn", "skip", "blocked")] + [string]$Status, + [string]$Detail, + [bool]$Required = $true, + [hashtable]$Meta = @{} + ) + + $checks.Add([ordered]@{ + key = $Key + label = $Label + status = $Status + required = $Required + detail = $Detail + meta = $Meta + }) | Out-Null +} + +function Save-Json { + param([string]$Path, [object]$Value) + $Value | ConvertTo-Json -Depth 20 | Set-Content -Encoding UTF8 -Path $Path +} + +function Get-CsvHeader { + param([string]$Path) + if (-not (Test-Path -LiteralPath $Path -PathType Leaf)) { + return @() + } + $firstLine = Get-Content -LiteralPath $Path -Encoding UTF8 -TotalCount 1 + if ([string]::IsNullOrWhiteSpace($firstLine)) { + return @() + } + return @($firstLine.Split(",") | ForEach-Object { $_.Trim() }) +} + +function Test-CsvHeader { + param( + [string]$Path, + [string[]]$Columns + ) + $header = Get-CsvHeader -Path $Path + $missing = @($Columns | Where-Object { $header -notcontains $_ }) + return [pscustomobject]@{ + ok = ($missing.Count -eq 0) + missing = $missing + header = $header + } +} + +function Import-CsvRows { + param([string]$Path) + if (-not (Test-Path -LiteralPath $Path -PathType Leaf)) { + return @() + } + return @(Import-Csv -LiteralPath $Path) +} + +function Test-RequiredFlag { + param([string]$Value) + if ([string]::IsNullOrWhiteSpace($Value)) { + return $false + } + return @("true", "yes", "1", "required") -contains $Value.ToLowerInvariant() +} + +function Test-AllowedOfficialUrl { + param([string]$Url) + if ([string]::IsNullOrWhiteSpace($Url)) { + return $false + } + try { + $uri = [System.Uri]$Url + return $allowedDomains -contains $uri.Host.ToLowerInvariant() + } catch { + return $false + } +} + +function Add-RequiredFileCheck { + param( + [string]$Key, + [string]$Label, + [string]$RelativePath, + [string[]]$Columns + ) + $path = Join-Path $repoRoot $RelativePath + if (-not (Test-Path -LiteralPath $path -PathType Leaf)) { + Add-Check -Key $Key -Label $Label -Status "fail" -Detail "Missing file: $RelativePath" -Meta @{ path = $path } + $inventoryReport.Add([pscustomobject][ordered]@{ + key = $Key + label = $Label + path = $RelativePath + exists = $false + schema_ok = $false + rows = "" + missing_columns = "file_missing" + }) | Out-Null + return @() + } + + $schema = Test-CsvHeader -Path $path -Columns $Columns + $rows = Import-CsvRows -Path $path + $inventoryReport.Add([pscustomobject][ordered]@{ + key = $Key + label = $Label + path = $RelativePath + exists = $true + schema_ok = $schema.ok + rows = $rows.Count + missing_columns = ($schema.missing -join ";") + }) | Out-Null + + if ($schema.ok) { + Add-Check -Key $Key -Label $Label -Status "pass" -Detail "Schema OK, rows=$($rows.Count)" -Meta @{ path = $path } + } else { + Add-Check -Key $Key -Label $Label -Status "fail" -Detail "Missing columns: $($schema.missing -join ',')" -Meta @{ path = $path; missing = $schema.missing } + } + return $rows +} + +function Test-SecretLeak { + param([string]$Root) + $adminPasswordLiteral = [string]::Concat([char]54, [char]53, [char]52, [char]51, [char]50, [char]49) + $hits = New-Object System.Collections.Generic.List[object] + $files = @(Get-ChildItem -LiteralPath $Root -Recurse -File -ErrorAction SilentlyContinue) + $scriptPath = Join-Path $repoRoot "scripts\run-legal-knowledge-library-gate.ps1" + if (Test-Path -LiteralPath $scriptPath -PathType Leaf) { + $files += Get-Item -LiteralPath $scriptPath + } + foreach ($file in $files) { + $match = Select-String -LiteralPath $file.FullName -Pattern $adminPasswordLiteral -List -ErrorAction SilentlyContinue + if ($match) { + $hits.Add([pscustomobject]@{ path = $file.FullName; pattern = "admin_password_literal" }) | Out-Null + } + } + return $hits.ToArray() +} + +if (-not (Test-Path "$HOME\.Codex\skills\gstack\bin")) { + Add-Check -Key "gstack" -Label "gstack preflight" -Status "fail" -Detail "gstack is missing" +} else { + Add-Check -Key "gstack" -Label "gstack preflight" -Status "pass" -Detail "GSTACK_OK" +} + +$branch = (git -C $repoRoot rev-parse --abbrev-ref HEAD).Trim() +$commit = (git -C $repoRoot rev-parse HEAD).Trim() +$remoteUrl = (git -C $repoRoot remote get-url origin).Trim() +$gitStatus = git -C $repoRoot status --short +($gitStatus -join [Environment]::NewLine) | Set-Content -Encoding UTF8 -Path $gitStatusPath + +if ($remoteUrl -match "192\.168\.3\.90") { + Add-Check -Key "origin_remote" -Label "origin remote" -Status "pass" -Detail "origin points to 192.168.3.90" -Meta @{ branch = $branch; commit = $commit; remote = $remoteUrl } +} else { + Add-Check -Key "origin_remote" -Label "origin remote" -Status "fail" -Detail "origin does not point to 192.168.3.90" -Meta @{ branch = $branch; commit = $commit; remote = $remoteUrl } +} + +if ($gitStatus) { + Add-Check -Key "working_tree" -Label "working tree" -Status "warn" -Required $false -Detail "Working tree has uncommitted changes; gate is advisory" -Meta @{ artifact = $gitStatusPath } +} else { + Add-Check -Key "working_tree" -Label "working tree" -Status "pass" -Detail "Working tree is clean" -Meta @{ artifact = $gitStatusPath } +} + +if (Test-Path -LiteralPath $LibraryRoot -PathType Container) { + Add-Check -Key "library_root" -Label "phase13 library root" -Status "pass" -Detail "Library root exists" -Meta @{ root = $LibraryRoot } +} else { + Add-Check -Key "library_root" -Label "phase13 library root" -Status "fail" -Detail "Library root is missing" -Meta @{ root = $LibraryRoot } +} + +$requiredDirs = @( + "project-docs\phase13-legal-knowledge-template-library\inventories", + "project-docs\phase13-legal-knowledge-template-library\legal-sources\civil-code", + "project-docs\phase13-legal-knowledge-template-library\legal-sources\judicial-interpretations", + "project-docs\phase13-legal-knowledge-template-library\legal-sources\company-commercial", + "project-docs\phase13-legal-knowledge-template-library\legal-sources\labor-employment", + "project-docs\phase13-legal-knowledge-template-library\legal-sources\data-privacy", + "project-docs\phase13-legal-knowledge-template-library\legal-sources\intellectual-property", + "project-docs\phase13-legal-knowledge-template-library\legal-sources\procurement-tendering", + "project-docs\phase13-legal-knowledge-template-library\clause-library\common", + "project-docs\phase13-legal-knowledge-template-library\contract-templates\purchase", + "project-docs\phase13-legal-knowledge-template-library\qa-samples\review", + "project-docs\phase13-legal-knowledge-template-library\evidence" +) + +$missingDirs = @($requiredDirs | Where-Object { -not (Test-Path -LiteralPath (Join-Path $repoRoot $_) -PathType Container) }) +if ($missingDirs.Count -eq 0) { + Add-Check -Key "directory_structure" -Label "directory structure" -Status "pass" -Detail "Required directories exist" +} else { + Add-Check -Key "directory_structure" -Label "directory structure" -Status "fail" -Detail "Missing directories: $($missingDirs -join ',')" -Meta @{ missing = $missingDirs } +} + +$commonDocFiles = @( + "project-docs\phase13-legal-knowledge-template-library\README.md", + "project-docs\phase13-legal-knowledge-template-library\governance-rules.md", + "project-docs\phase13-legal-knowledge-template-library\field-dictionary.md" +) +foreach ($docPath in $commonDocFiles) { + $absoluteDocPath = Join-Path $repoRoot $docPath + $key = "doc_" + ([System.IO.Path]::GetFileNameWithoutExtension($docPath) -replace "[^A-Za-z0-9]+", "_") + if (Test-Path -LiteralPath $absoluteDocPath -PathType Leaf) { + Add-Check -Key $key -Label $docPath -Status "pass" -Detail "Document exists" -Meta @{ path = $absoluteDocPath } + } else { + Add-Check -Key $key -Label $docPath -Status "fail" -Detail "Document missing" -Meta @{ path = $absoluteDocPath } + } +} + +$legalSourceColumns = @("source_id", "title", "source_type", "issuer", "official_domain", "source_url", "retrieval_hint", "effective_date", "validity_status", "contract_scope", "knowledge_domain", "review_required", "status", "owner", "legal_reviewer", "collection_date", "notes") +$knowledgeCardColumns = @("knowledge_card_id", "title", "source_ids", "legal_question", "applicable_scenarios", "non_applicable_scenarios", "summary_path", "original_reference", "answer_boundary", "status", "owner", "legal_reviewer", "review_required", "production_ready", "notes") +$riskRuleColumns = @("rule_id", "risk_category", "risk_name", "severity", "source_ids", "clause_ids", "trigger_condition", "review_output_template", "modification_suggestion_path", "human_review_required", "status", "owner", "legal_reviewer", "review_sample_ids", "production_ready", "notes") +$clauseColumns = @("clause_id", "clause_name", "contract_type", "clause_category", "source_ids", "applicable_conditions", "excluded_conditions", "variant_group", "risk_notes_path", "clause_path", "status", "owner", "legal_reviewer", "business_reviewer", "review_required", "production_ready", "notes") +$templateColumns = @("template_id", "template_name", "contract_type", "template_path", "variable_schema_path", "required_variables", "optional_variables", "clause_ids", "review_rule_ids", "generation_sample_ids", "status", "owner", "legal_reviewer", "business_reviewer", "review_required", "production_ready", "notes") +$reviewSampleColumns = @("sample_id", "contract_type", "risk_categories", "source_ids", "input_sample_path", "expected_findings_path", "expected_severity", "expected_source_citations", "status", "owner", "legal_reviewer", "review_required", "production_ready", "notes") +$generationSampleColumns = @("sample_id", "template_id", "contract_type", "variable_payload_path", "expected_document_path", "expected_review_rule_ids", "expected_source_citations", "status", "owner", "legal_reviewer", "business_reviewer", "review_required", "production_ready", "notes") +$kbQaSampleColumns = @("sample_id", "question", "expected_answer_boundary", "expected_source_ids", "expected_citation_required", "expected_refusal_required", "status", "owner", "legal_reviewer", "review_required", "production_ready", "notes") +$expertReviewColumns = @("review_id", "asset_type", "asset_id", "reviewer", "reviewer_role", "review_date", "review_result", "required_changes", "follow_up_owner", "evidence_path", "status", "notes") + +$legalSourceRows = Add-RequiredFileCheck -Key "inventory_legal_sources" -Label "legal source inventory" -RelativePath "project-docs\phase13-legal-knowledge-template-library\inventories\legal-source-inventory.csv" -Columns $legalSourceColumns +Add-RequiredFileCheck -Key "inventory_knowledge_cards" -Label "legal knowledge card inventory" -RelativePath "project-docs\phase13-legal-knowledge-template-library\inventories\legal-knowledge-card-inventory.csv" -Columns $knowledgeCardColumns | Out-Null +Add-RequiredFileCheck -Key "inventory_risk_rules" -Label "review risk rule inventory" -RelativePath "project-docs\phase13-legal-knowledge-template-library\inventories\review-risk-rule-inventory.csv" -Columns $riskRuleColumns | Out-Null +Add-RequiredFileCheck -Key "inventory_clauses" -Label "clause library inventory" -RelativePath "project-docs\phase13-legal-knowledge-template-library\inventories\clause-library-inventory.csv" -Columns $clauseColumns | Out-Null +Add-RequiredFileCheck -Key "inventory_templates" -Label "contract template inventory" -RelativePath "project-docs\phase13-legal-knowledge-template-library\inventories\contract-template-inventory.csv" -Columns $templateColumns | Out-Null +Add-RequiredFileCheck -Key "inventory_review_samples" -Label "review golden sample inventory" -RelativePath "project-docs\phase13-legal-knowledge-template-library\inventories\review-golden-sample-inventory.csv" -Columns $reviewSampleColumns | Out-Null +Add-RequiredFileCheck -Key "inventory_generation_samples" -Label "generation golden sample inventory" -RelativePath "project-docs\phase13-legal-knowledge-template-library\inventories\generation-golden-sample-inventory.csv" -Columns $generationSampleColumns | Out-Null +Add-RequiredFileCheck -Key "inventory_kb_qa_samples" -Label "KB QA golden sample inventory" -RelativePath "project-docs\phase13-legal-knowledge-template-library\inventories\kb-qa-golden-sample-inventory.csv" -Columns $kbQaSampleColumns | Out-Null +Add-RequiredFileCheck -Key "inventory_expert_reviews" -Label "expert review register" -RelativePath "project-docs\phase13-legal-knowledge-template-library\inventories\expert-review-register.csv" -Columns $expertReviewColumns | Out-Null + +if ($legalSourceRows.Count -ge $MinLegalSources) { + Add-Check -Key "legal_source_minimum" -Label "legal source minimum" -Status "pass" -Detail "Legal sources=$($legalSourceRows.Count), minimum=$MinLegalSources" +} else { + Add-Check -Key "legal_source_minimum" -Label "legal source minimum" -Status "fail" -Detail "Legal sources=$($legalSourceRows.Count), minimum=$MinLegalSources" +} + +$duplicateSourceIds = @($legalSourceRows | Group-Object source_id | Where-Object { $_.Count -gt 1 } | Select-Object -ExpandProperty Name) +if ($duplicateSourceIds.Count -eq 0) { + Add-Check -Key "legal_source_ids_unique" -Label "legal source IDs unique" -Status "pass" -Detail "No duplicate legal source IDs" +} else { + Add-Check -Key "legal_source_ids_unique" -Label "legal source IDs unique" -Status "fail" -Detail "Duplicate IDs: $($duplicateSourceIds -join ',')" -Meta @{ duplicates = $duplicateSourceIds } +} + +$missingRequiredFields = @($legalSourceRows | Where-Object { + [string]::IsNullOrWhiteSpace($_.source_id) -or + [string]::IsNullOrWhiteSpace($_.title) -or + [string]::IsNullOrWhiteSpace($_.issuer) -or + [string]::IsNullOrWhiteSpace($_.source_url) -or + [string]::IsNullOrWhiteSpace($_.retrieval_hint) -or + [string]::IsNullOrWhiteSpace($_.status) -or + [string]::IsNullOrWhiteSpace($_.owner) +} | Select-Object -ExpandProperty source_id) +if ($missingRequiredFields.Count -eq 0) { + Add-Check -Key "legal_source_required_fields" -Label "legal source required fields" -Status "pass" -Detail "Required fields are populated" +} else { + Add-Check -Key "legal_source_required_fields" -Label "legal source required fields" -Status "fail" -Detail "Rows missing required fields: $($missingRequiredFields -join ',')" -Meta @{ rows = $missingRequiredFields } +} + +$nonOfficialUrls = @($legalSourceRows | Where-Object { -not (Test-AllowedOfficialUrl -Url $_.source_url) } | Select-Object -ExpandProperty source_id) +if ($nonOfficialUrls.Count -eq 0) { + Add-Check -Key "official_source_urls" -Label "official source URLs" -Status "pass" -Detail "All legal source URLs use official allowlisted domains" +} else { + Add-Check -Key "official_source_urls" -Label "official source URLs" -Status "fail" -Detail "Non-allowlisted source URLs: $($nonOfficialUrls -join ',')" -Meta @{ rows = $nonOfficialUrls; allowed_domains = $allowedDomains } +} + +$unknownValidityRows = @($legalSourceRows | Where-Object { $_.validity_status -eq "VERIFY_REQUIRED" -or $_.effective_date -eq "VERIFY_REQUIRED" } | Select-Object -ExpandProperty source_id) +if ($unknownValidityRows.Count -gt 0) { + Add-Check -Key "legal_review_required" -Label "legal review required" -Status "warn" -Required $false -Detail "Legal source validity still requires legal review: $($unknownValidityRows.Count) rows" -Meta @{ rows = $unknownValidityRows } +} else { + Add-Check -Key "legal_review_required" -Label "legal review required" -Status "pass" -Detail "Legal source validity is verified" +} + +$publishedWithoutReview = @($legalSourceRows | Where-Object { + @("APPROVED", "PUBLISHED") -contains $_.status -and + ([string]::IsNullOrWhiteSpace($_.legal_reviewer) -or $_.legal_reviewer -eq "pending" -or $_.validity_status -eq "VERIFY_REQUIRED") +} | Select-Object -ExpandProperty source_id) +if ($publishedWithoutReview.Count -eq 0) { + Add-Check -Key "no_unreviewed_publication" -Label "no unreviewed publication" -Status "pass" -Detail "No legal source is published without review" +} else { + Add-Check -Key "no_unreviewed_publication" -Label "no unreviewed publication" -Status "fail" -Detail "Published/approved rows missing review: $($publishedWithoutReview -join ',')" -Meta @{ rows = $publishedWithoutReview } +} + +$statusValues = @("DRAFT", "LEGAL_REVIEW", "BUSINESS_REVIEW", "APPROVED", "PUBLISHED", "DEPRECATED") +$invalidStatuses = @($legalSourceRows | Where-Object { $statusValues -notcontains $_.status } | Select-Object -ExpandProperty source_id) +if ($invalidStatuses.Count -eq 0) { + Add-Check -Key "legal_source_status_values" -Label "legal source status values" -Status "pass" -Detail "Legal source statuses are allowed" +} else { + Add-Check -Key "legal_source_status_values" -Label "legal source status values" -Status "fail" -Detail "Invalid statuses: $($invalidStatuses -join ',')" -Meta @{ rows = $invalidStatuses; allowed = $statusValues } +} + +$domainsCovered = @($legalSourceRows | Select-Object -ExpandProperty knowledge_domain -Unique) +$requiredDomains = @("civil-code", "judicial-interpretations", "company-commercial", "labor-employment", "data-privacy", "intellectual-property", "procurement-tendering") +$missingKnowledgeDomains = @($requiredDomains | Where-Object { $domainsCovered -notcontains $_ }) +if ($missingKnowledgeDomains.Count -eq 0) { + Add-Check -Key "knowledge_domain_coverage" -Label "knowledge domain coverage" -Status "pass" -Detail "Domains covered: $($domainsCovered -join ',')" +} else { + Add-Check -Key "knowledge_domain_coverage" -Label "knowledge domain coverage" -Status "fail" -Detail "Missing knowledge domains: $($missingKnowledgeDomains -join ',')" -Meta @{ missing = $missingKnowledgeDomains } +} + +$secretHits = Test-SecretLeak -Root $LibraryRoot +if ($secretHits.Count -eq 0) { + Add-Check -Key "secret_scan" -Label "secret scan" -Status "pass" -Detail "No administrator password literal found in Phase 13 package or gate script" +} else { + Add-Check -Key "secret_scan" -Label "secret scan" -Status "fail" -Detail "Sensitive literal found" -Meta @{ hits = $secretHits } +} + +$legalSourceRows | + Select-Object source_id,title,issuer,official_domain,source_url,effective_date,validity_status,status,legal_reviewer,knowledge_domain | + Export-Csv -LiteralPath $sourceReportCsv -NoTypeInformation -Encoding UTF8 +$inventoryReport | Export-Csv -LiteralPath $inventoryReportCsv -NoTypeInformation -Encoding UTF8 + +$failedRequired = @($checks | Where-Object { $_.required -and $_.status -eq "fail" }).Count +$warnings = @($checks | Where-Object { $_.status -eq "warn" }).Count +$legalReviewRequired = $unknownValidityRows.Count + +$overallStatus = if ($failedRequired -gt 0) { + "FAIL" +} elseif ($legalReviewRequired -gt 0) { + "PASS_WITH_LEGAL_REVIEW_REQUIRED" +} elseif ($warnings -gt 0) { + "WARN" +} else { + "PASS" +} +$alertSeverity = if ($overallStatus -eq "FAIL") { + "critical" +} elseif ($overallStatus -eq "PASS_WITH_LEGAL_REVIEW_REQUIRED") { + "review_required" +} elseif ($overallStatus -eq "WARN") { + "warning" +} else { + "none" +} + +$summary = [ordered]@{ + name = "phase13-legal-knowledge-library-gate" + status = $overallStatus + alert_severity = $alertSeverity + generated_at = (Get-Date).ToUniversalTime().ToString("o") + artifact_dir = $artifactDir + branch = $branch + commit = $commit + remote = $remoteUrl + library_root = $LibraryRoot + checks = $checks.ToArray() + metrics = [ordered]@{ + legal_sources = $legalSourceRows.Count + allowed_domains = $allowedDomains.Count + knowledge_domains = $domainsCovered.Count + legal_review_required = $legalReviewRequired + inventory_files = $inventoryReport.Count + } + artifacts = [ordered]@{ + legal_source_report = $sourceReportCsv + inventory_schema_report = $inventoryReportCsv + } + totals = [ordered]@{ + total = $checks.Count + failed_required = $failedRequired + warnings = $warnings + legal_review_required = $legalReviewRequired + } +} +Save-Json -Path $summaryJson -Value $summary + +$md = New-Object System.Collections.Generic.List[string] +$md.Add("# Phase 13 Legal Knowledge Library Gate") | Out-Null +$md.Add("") | Out-Null +$md.Add("- Status: $overallStatus") | Out-Null +$md.Add("- Alert severity: $alertSeverity") | Out-Null +$md.Add("- Generated at: $($summary.generated_at)") | Out-Null +$md.Add("- Branch: $branch") | Out-Null +$md.Add("- Commit: $commit") | Out-Null +$md.Add("- Artifact dir: $artifactDir") | Out-Null +$md.Add("- Library root: $LibraryRoot") | Out-Null +$md.Add("") | Out-Null +$md.Add("## Metrics") | Out-Null +$md.Add("") | Out-Null +$md.Add("| Metric | Count |") | Out-Null +$md.Add("|---|---:|") | Out-Null +$md.Add("| Legal sources | $($legalSourceRows.Count) |") | Out-Null +$md.Add("| Allowed official domains | $($allowedDomains.Count) |") | Out-Null +$md.Add("| Knowledge domains | $($domainsCovered.Count) |") | Out-Null +$md.Add("| Inventory files | $($inventoryReport.Count) |") | Out-Null +$md.Add("| Legal review required rows | $legalReviewRequired |") | Out-Null +$md.Add("") | Out-Null +$md.Add("## Checks") | Out-Null +$md.Add("") | Out-Null +$md.Add("| Check | Required | Status | Detail |") | Out-Null +$md.Add("|---|---:|---|---|") | Out-Null +foreach ($check in $checks) { + $detail = ([string]$check.detail).Replace("|", "/") + $md.Add("| $($check.label) | $($check.required) | $($check.status.ToUpperInvariant()) | $detail |") | Out-Null +} +$md.Add("") | Out-Null +$md.Add("Local artifacts:") | Out-Null +$md.Add("") | Out-Null +$md.Add('- `legal-knowledge-library-gate-summary.json`') | Out-Null +$md.Add('- `legal-knowledge-library-gate-summary.md`') | Out-Null +$md.Add('- `phase13-legal-source-report.csv`') | Out-Null +$md.Add('- `phase13-inventory-schema-report.csv`') | Out-Null +$md | Set-Content -Encoding UTF8 -Path $summaryMd + +if ($overallStatus -eq "FAIL") { + Write-Host "PHASE13_LEGAL_KNOWLEDGE_LIBRARY_GATE_FAIL $artifactDir" + throw "Phase 13 legal knowledge library gate failed. See $summaryMd" +} +if ($overallStatus -eq "WARN" -and $FailOnWarn) { + Write-Host "PHASE13_LEGAL_KNOWLEDGE_LIBRARY_GATE_WARN $artifactDir" + throw "Phase 13 legal knowledge library gate has warnings. See $summaryMd" +} +if ($overallStatus -eq "PASS_WITH_LEGAL_REVIEW_REQUIRED" -and $FailOnLegalReviewRequired) { + Write-Host "PHASE13_LEGAL_KNOWLEDGE_LIBRARY_GATE_PASS_WITH_LEGAL_REVIEW_REQUIRED $artifactDir" + throw "Phase 13 legal knowledge library gate requires legal review. See $summaryMd" +} + +Write-Host "PHASE13_LEGAL_KNOWLEDGE_LIBRARY_GATE_$overallStatus $artifactDir"