zcode-expert-system 0.0.0-stage → 3.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.zcode-plugin/plugin.json +25 -0
- package/LICENSE +30 -0
- package/README.md +548 -2
- package/README_CN.md +444 -0
- package/SKILL.md +357 -0
- package/agents/expert-academic-anthropologist.md +124 -0
- package/agents/expert-academic-geographer.md +126 -0
- package/agents/expert-academic-historian.md +122 -0
- package/agents/expert-academic-narratologist.md +117 -0
- package/agents/expert-academic-psychologist.md +117 -0
- package/agents/expert-academic-statistician.md +40 -0
- package/agents/expert-academic-study-planner.md +262 -0
- package/agents/expert-accounts-payable-agent.md +102 -0
- package/agents/expert-agentic-identity-trust.md +388 -0
- package/agents/expert-agents-orchestrator.md +366 -0
- package/agents/expert-authenticity-appraiser.md +38 -0
- package/agents/expert-automation-governance-architect.md +215 -0
- package/agents/expert-blender-addon-engineer.md +233 -0
- package/agents/expert-business-strategist.md +487 -0
- package/agents/expert-change-management-consultant.md +495 -0
- package/agents/expert-chief-executive-officer.md +104 -0
- package/agents/expert-chief-financial-officer.md +390 -0
- package/agents/expert-chief-marketing-officer.md +95 -0
- package/agents/expert-chief-of-staff.md +278 -0
- package/agents/expert-chief-operating-officer.md +88 -0
- package/agents/expert-chief-product-officer.md +91 -0
- package/agents/expert-chief-technology-officer.md +98 -0
- package/agents/expert-corporate-training-designer.md +191 -0
- package/agents/expert-customer-service.md +40 -0
- package/agents/expert-customer-success-manager.md +458 -0
- package/agents/expert-data-consolidation-agent.md +327 -0
- package/agents/expert-data-privacy-officer.md +411 -0
- package/agents/expert-design-brand-guardian.md +321 -0
- package/agents/expert-design-image-prompt-engineer.md +255 -0
- package/agents/expert-design-inclusive-visuals-specialist.md +177 -0
- package/agents/expert-design-persona-walkthrough.md +271 -0
- package/agents/expert-design-ui-designer.md +382 -0
- package/agents/expert-design-ui-finish-gate-reviewer.md +40 -0
- package/agents/expert-design-ux-architect.md +482 -0
- package/agents/expert-design-ux-researcher.md +328 -0
- package/agents/expert-design-video-prompt-engineer.md +110 -0
- package/agents/expert-design-visual-storyteller.md +159 -0
- package/agents/expert-design-whimsy-injector.md +453 -0
- package/agents/expert-economy-designer.md +40 -0
- package/agents/expert-engineering-ai-data-remediation-engineer.md +209 -0
- package/agents/expert-engineering-ai-engineer.md +161 -0
- package/agents/expert-engineering-api-platform-engineer.md +40 -0
- package/agents/expert-engineering-ats-validator-architect.md +38 -0
- package/agents/expert-engineering-autonomous-optimization-architect.md +115 -0
- package/agents/expert-engineering-backend-architect.md +234 -0
- package/agents/expert-engineering-china-network-engineer.md +33 -0
- package/agents/expert-engineering-cms-developer.md +534 -0
- package/agents/expert-engineering-code-reviewer.md +172 -0
- package/agents/expert-engineering-codebase-onboarding-engineer.md +172 -0
- package/agents/expert-engineering-data-engineer.md +324 -0
- package/agents/expert-engineering-data-visualization-engineer.md +40 -0
- package/agents/expert-engineering-database-optimizer.md +175 -0
- package/agents/expert-engineering-database-reliability-engineer.md +40 -0
- package/agents/expert-engineering-desktop-app-engineer.md +40 -0
- package/agents/expert-engineering-developer-tooling-engineer.md +40 -0
- package/agents/expert-engineering-devops-automator.md +375 -0
- package/agents/expert-engineering-dingtalk-integration-developer.md +574 -0
- package/agents/expert-engineering-drupal-performance.md +40 -0
- package/agents/expert-engineering-drupal-shopping-cart.md +359 -0
- package/agents/expert-engineering-email-intelligence-engineer.md +349 -0
- package/agents/expert-engineering-embedded-firmware-engineer.md +168 -0
- package/agents/expert-engineering-embedded-linux-driver-engineer.md +255 -0
- package/agents/expert-engineering-feishu-integration-developer.md +597 -0
- package/agents/expert-engineering-filament-optimization-specialist.md +283 -0
- package/agents/expert-engineering-finops-engineer.md +40 -0
- package/agents/expert-engineering-fpga-digital-design-engineer.md +227 -0
- package/agents/expert-engineering-frontend-developer.md +224 -0
- package/agents/expert-engineering-gaussdb-expert.md +40 -0
- package/agents/expert-engineering-git-workflow-master.md +220 -0
- package/agents/expert-engineering-i18n-engineer.md +40 -0
- package/agents/expert-engineering-identity-access-engineer.md +40 -0
- package/agents/expert-engineering-incident-response-commander.md +465 -0
- package/agents/expert-engineering-iot-fleet-engineer.md +40 -0
- package/agents/expert-engineering-iot-solution-architect.md +220 -0
- package/agents/expert-engineering-it-service-manager.md +560 -0
- package/agents/expert-engineering-knowledge-graph-engineer.md +40 -0
- package/agents/expert-engineering-llm-post-training-engineer.md +40 -0
- package/agents/expert-engineering-mechanical-design-engineer.md +311 -0
- package/agents/expert-engineering-minimal-change-engineer.md +206 -0
- package/agents/expert-engineering-mobile-app-builder.md +434 -0
- package/agents/expert-engineering-mobile-release-engineer.md +40 -0
- package/agents/expert-engineering-multi-agent-systems-architect.md +599 -0
- package/agents/expert-engineering-network-engineer-china.md +162 -0
- package/agents/expert-engineering-network-engineer.md +40 -0
- package/agents/expert-engineering-orgscript-engineer.md +112 -0
- package/agents/expert-engineering-payments-billing-engineer.md +40 -0
- package/agents/expert-engineering-pc-host-engineer.md +231 -0
- package/agents/expert-engineering-pdf-engine-architect.md +32 -0
- package/agents/expert-engineering-platform-engineer.md +32 -0
- package/agents/expert-engineering-privacy-engineer.md +40 -0
- package/agents/expert-engineering-prompt-engineer.md +203 -0
- package/agents/expert-engineering-rag-pipeline-engineer.md +40 -0
- package/agents/expert-engineering-rapid-prototyper.md +461 -0
- package/agents/expert-engineering-realtime-collaboration-engineer.md +40 -0
- package/agents/expert-engineering-rust-refactoring-specialist.md +40 -0
- package/agents/expert-engineering-search-relevance-engineer.md +40 -0
- package/agents/expert-engineering-section-508-specialist.md +40 -0
- package/agents/expert-engineering-security-engineer.md +303 -0
- package/agents/expert-engineering-senior-developer.md +177 -0
- package/agents/expert-engineering-servicenow-developer-mentor.md +32 -0
- package/agents/expert-engineering-software-architect.md +200 -0
- package/agents/expert-engineering-solidity-smart-contract-engineer.md +541 -0
- package/agents/expert-engineering-sre.md +233 -0
- package/agents/expert-engineering-technical-writer.md +409 -0
- package/agents/expert-engineering-threat-detection-engineer.md +553 -0
- package/agents/expert-engineering-universal-document-compiler.md +32 -0
- package/agents/expert-engineering-uswds-developer.md +40 -0
- package/agents/expert-engineering-video-streaming-engineer.md +40 -0
- package/agents/expert-engineering-voice-ai-integration-engineer.md +560 -0
- package/agents/expert-engineering-webassembly-engineer.md +40 -0
- package/agents/expert-engineering-wechat-mini-program-developer.md +288 -0
- package/agents/expert-engineering-wordpress-performance.md +40 -0
- package/agents/expert-engineering-wordpress-shopping-cart.md +345 -0
- package/agents/expert-esg-sustainability-officer.md +395 -0
- package/agents/expert-finance-bookkeeper-controller.md +271 -0
- package/agents/expert-finance-financial-analyst.md +244 -0
- package/agents/expert-finance-financial-forecaster.md +213 -0
- package/agents/expert-finance-fpa-analyst.md +272 -0
- package/agents/expert-finance-fraud-detector.md +241 -0
- package/agents/expert-finance-hk-stock-compliance-reviewer.md +316 -0
- package/agents/expert-finance-investment-researcher.md +283 -0
- package/agents/expert-finance-invoice-manager.md +242 -0
- package/agents/expert-finance-tax-strategist.md +250 -0
- package/agents/expert-game-audio-engineer.md +265 -0
- package/agents/expert-game-designer.md +168 -0
- package/agents/expert-gaokao-college-advisor.md +333 -0
- package/agents/expert-gis-3d-scene-developer.md +110 -0
- package/agents/expert-gis-analyst.md +90 -0
- package/agents/expert-gis-bim-specialist.md +107 -0
- package/agents/expert-gis-cartography-designer.md +149 -0
- package/agents/expert-gis-drone-reality-mapping.md +119 -0
- package/agents/expert-gis-geoai-ml-engineer.md +104 -0
- package/agents/expert-gis-geoprocessing-specialist.md +96 -0
- package/agents/expert-gis-qa-engineer.md +132 -0
- package/agents/expert-gis-solution-engineer.md +100 -0
- package/agents/expert-gis-spatial-data-engineer.md +96 -0
- package/agents/expert-gis-spatial-data-scientist.md +110 -0
- package/agents/expert-gis-technical-consultant.md +85 -0
- package/agents/expert-gis-web-gis-developer.md +107 -0
- package/agents/expert-godot-gameplay-scripter.md +335 -0
- package/agents/expert-godot-multiplayer-engineer.md +296 -0
- package/agents/expert-godot-shader-developer.md +267 -0
- package/agents/expert-government-digital-presales-consultant.md +362 -0
- package/agents/expert-grant-writer.md +510 -0
- package/agents/expert-healthcare-aging-parent-care-companion.md +40 -0
- package/agents/expert-healthcare-clinical-evidence-agent.md +40 -0
- package/agents/expert-healthcare-customer-service.md +388 -0
- package/agents/expert-healthcare-innovation-strategist.md +40 -0
- package/agents/expert-healthcare-marketing-compliance.md +394 -0
- package/agents/expert-healthcare-sovereign-health-systems-agent.md +40 -0
- package/agents/expert-hospitality-guest-services.md +597 -0
- package/agents/expert-hr-onboarding.md +450 -0
- package/agents/expert-hr-performance-reviewer.md +248 -0
- package/agents/expert-hr-recruiter.md +232 -0
- package/agents/expert-identity-graph-operator.md +270 -0
- package/agents/expert-language-translator.md +275 -0
- package/agents/expert-legal-billing-time-tracking.md +566 -0
- package/agents/expert-legal-client-intake.md +487 -0
- package/agents/expert-legal-contract-reviewer.md +240 -0
- package/agents/expert-legal-document-review.md +452 -0
- package/agents/expert-legal-policy-writer.md +308 -0
- package/agents/expert-level-designer.md +209 -0
- package/agents/expert-livestock-archive-auditor.md +135 -0
- package/agents/expert-loan-officer-assistant.md +549 -0
- package/agents/expert-lsp-index-engineer.md +334 -0
- package/agents/expert-ma-integration-manager.md +426 -0
- package/agents/expert-macos-spatial-metal-engineer.md +337 -0
- package/agents/expert-marketing-aeo-foundations.md +263 -0
- package/agents/expert-marketing-agentic-search-optimizer.md +312 -0
- package/agents/expert-marketing-ai-citation-strategist.md +169 -0
- package/agents/expert-marketing-app-store-optimizer.md +319 -0
- package/agents/expert-marketing-baidu-seo-specialist.md +220 -0
- package/agents/expert-marketing-bilibili-content-strategist.md +40 -0
- package/agents/expert-marketing-bilibili-strategist.md +194 -0
- package/agents/expert-marketing-book-co-author.md +109 -0
- package/agents/expert-marketing-carousel-growth-engine.md +215 -0
- package/agents/expert-marketing-china-ecommerce-operator.md +277 -0
- package/agents/expert-marketing-china-market-localization-strategist.md +282 -0
- package/agents/expert-marketing-content-creator.md +145 -0
- package/agents/expert-marketing-cross-border-ecommerce.md +260 -0
- package/agents/expert-marketing-daily-news-briefing.md +303 -0
- package/agents/expert-marketing-developer-community-builder.md +32 -0
- package/agents/expert-marketing-douyin-strategist.md +150 -0
- package/agents/expert-marketing-ecommerce-operator.md +216 -0
- package/agents/expert-marketing-email-strategist.md +248 -0
- package/agents/expert-marketing-global-podcast-strategist.md +204 -0
- package/agents/expert-marketing-growth-hacker.md +121 -0
- package/agents/expert-marketing-instagram-curator.md +179 -0
- package/agents/expert-marketing-knowledge-commerce-strategist.md +384 -0
- package/agents/expert-marketing-kuaishou-strategist.md +182 -0
- package/agents/expert-marketing-linkedin-content-creator.md +232 -0
- package/agents/expert-marketing-livestream-commerce-coach.md +303 -0
- package/agents/expert-marketing-multi-platform-publisher.md +216 -0
- package/agents/expert-marketing-podcast-strategist.md +278 -0
- package/agents/expert-marketing-pr-communications-manager.md +472 -0
- package/agents/expert-marketing-private-domain-operator.md +309 -0
- package/agents/expert-marketing-reddit-community-builder.md +127 -0
- package/agents/expert-marketing-search-growth-orchestrator.md +372 -0
- package/agents/expert-marketing-seo-specialist.md +298 -0
- package/agents/expert-marketing-short-video-editing-coach.md +413 -0
- package/agents/expert-marketing-social-media-strategist.md +118 -0
- package/agents/expert-marketing-tiktok-strategist.md +124 -0
- package/agents/expert-marketing-twitter-engager.md +132 -0
- package/agents/expert-marketing-video-optimization-specialist.md +128 -0
- package/agents/expert-marketing-wechat-official-account.md +158 -0
- package/agents/expert-marketing-wechat-operator.md +156 -0
- package/agents/expert-marketing-weibo-strategist.md +241 -0
- package/agents/expert-marketing-weixin-channels-strategist.md +297 -0
- package/agents/expert-marketing-x-twitter-intelligence-analyst.md +160 -0
- package/agents/expert-marketing-xiaohongshu-operator.md +139 -0
- package/agents/expert-marketing-xiaohongshu-specialist.md +151 -0
- package/agents/expert-marketing-zhihu-strategist.md +175 -0
- package/agents/expert-medical-billing-coding-specialist.md +489 -0
- package/agents/expert-narrative-designer.md +244 -0
- package/agents/expert-operations-manager.md +398 -0
- package/agents/expert-organizational-psychologist.md +390 -0
- package/agents/expert-paid-media-auditor.md +170 -0
- package/agents/expert-paid-media-creative-strategist.md +173 -0
- package/agents/expert-paid-media-paid-social-strategist.md +180 -0
- package/agents/expert-paid-media-ppc-strategist.md +180 -0
- package/agents/expert-paid-media-programmatic-buyer.md +177 -0
- package/agents/expert-paid-media-search-query-analyst.md +182 -0
- package/agents/expert-paid-media-tracking-specialist.md +199 -0
- package/agents/expert-personal-growth-mentor.md +158 -0
- package/agents/expert-product-behavioral-nudge-engine.md +246 -0
- package/agents/expert-product-dx-engineer.md +32 -0
- package/agents/expert-product-feedback-synthesizer.md +175 -0
- package/agents/expert-product-manager.md +474 -0
- package/agents/expert-product-sprint-prioritizer.md +133 -0
- package/agents/expert-product-trend-researcher.md +143 -0
- package/agents/expert-project-management-experiment-tracker.md +206 -0
- package/agents/expert-project-management-jira-workflow-steward.md +249 -0
- package/agents/expert-project-management-meeting-notes-specialist.md +94 -0
- package/agents/expert-project-management-project-shepherd.md +202 -0
- package/agents/expert-project-management-studio-operations.md +208 -0
- package/agents/expert-project-management-studio-producer.md +211 -0
- package/agents/expert-project-manager-senior.md +135 -0
- package/agents/expert-prompt-engineer.md +176 -0
- package/agents/expert-real-estate-buyer-seller.md +594 -0
- package/agents/expert-recruitment-specialist.md +49 -0
- package/agents/expert-report-distribution-agent.md +354 -0
- package/agents/expert-research-synthesist.md +40 -0
- package/agents/expert-resume-tailor.md +40 -0
- package/agents/expert-retail-customer-returns.md +564 -0
- package/agents/expert-roblox-avatar-creator.md +298 -0
- package/agents/expert-roblox-experience-designer.md +306 -0
- package/agents/expert-roblox-systems-scripter.md +325 -0
- package/agents/expert-sales-account-strategist.md +243 -0
- package/agents/expert-sales-coach.md +291 -0
- package/agents/expert-sales-data-extraction-agent.md +159 -0
- package/agents/expert-sales-deal-strategist.md +204 -0
- package/agents/expert-sales-discovery-coach.md +230 -0
- package/agents/expert-sales-engineer.md +200 -0
- package/agents/expert-sales-offer-lead-gen-strategist.md +256 -0
- package/agents/expert-sales-outbound-strategist.md +208 -0
- package/agents/expert-sales-outreach.md +40 -0
- package/agents/expert-sales-pipeline-analyst.md +284 -0
- package/agents/expert-sales-proposal-strategist.md +233 -0
- package/agents/expert-security-ai-generated-code-auditor.md +40 -0
- package/agents/expert-security-appsec-engineer.md +490 -0
- package/agents/expert-security-architect.md +303 -0
- package/agents/expert-security-blockchain-security-auditor.md +462 -0
- package/agents/expert-security-cloud-security-architect.md +522 -0
- package/agents/expert-security-compliance-auditor.md +157 -0
- package/agents/expert-security-incident-responder.md +436 -0
- package/agents/expert-security-penetration-tester.md +398 -0
- package/agents/expert-security-secrets-credential-engineer.md +40 -0
- package/agents/expert-security-senior-secops.md +751 -0
- package/agents/expert-security-threat-detection-engineer.md +533 -0
- package/agents/expert-security-threat-intelligence-analyst.md +643 -0
- package/agents/expert-specialized-ai-policy-writer.md +217 -0
- package/agents/expert-specialized-chief-of-staff.md +40 -0
- package/agents/expert-specialized-civil-engineer.md +355 -0
- package/agents/expert-specialized-codebase-archaeologist.md +40 -0
- package/agents/expert-specialized-cultural-intelligence-strategist.md +168 -0
- package/agents/expert-specialized-developer-advocate.md +334 -0
- package/agents/expert-specialized-document-generator.md +346 -0
- package/agents/expert-specialized-fedramp-rmf-compliance.md +40 -0
- package/agents/expert-specialized-focus-music-architect.md +32 -0
- package/agents/expert-specialized-french-consulting-market.md +46 -0
- package/agents/expert-specialized-korean-business-navigator.md +46 -0
- package/agents/expert-specialized-master-plan-architect.md +40 -0
- package/agents/expert-specialized-mcp-builder.md +351 -0
- package/agents/expert-specialized-meeting-assistant.md +236 -0
- package/agents/expert-specialized-model-qa.md +507 -0
- package/agents/expert-specialized-pricing-analyst.md +242 -0
- package/agents/expert-specialized-pricing-optimizer.md +254 -0
- package/agents/expert-specialized-risk-assessor.md +240 -0
- package/agents/expert-specialized-salesforce-architect.md +179 -0
- package/agents/expert-specialized-strategy-duel-agent.md +129 -0
- package/agents/expert-specialized-workflow-architect.md +596 -0
- package/agents/expert-study-abroad-advisor.md +281 -0
- package/agents/expert-supply-chain-garment-factory-planning-engineer.md +262 -0
- package/agents/expert-supply-chain-inventory-forecaster.md +212 -0
- package/agents/expert-supply-chain-route-optimizer.md +224 -0
- package/agents/expert-supply-chain-strategist.md +581 -0
- package/agents/expert-supply-chain-vendor-evaluator.md +232 -0
- package/agents/expert-support-analytics-reporter.md +364 -0
- package/agents/expert-support-executive-summary-generator.md +217 -0
- package/agents/expert-support-finance-tracker.md +447 -0
- package/agents/expert-support-infrastructure-maintainer.md +623 -0
- package/agents/expert-support-legal-compliance-checker.md +587 -0
- package/agents/expert-support-recruitment-specialist.md +508 -0
- package/agents/expert-support-support-responder.md +584 -0
- package/agents/expert-technical-artist.md +230 -0
- package/agents/expert-technical-translator-agent.md +167 -0
- package/agents/expert-terminal-integration-specialist.md +236 -0
- package/agents/expert-testing-accessibility-auditor.md +329 -0
- package/agents/expert-testing-api-tester.md +305 -0
- package/agents/expert-testing-embedded-qa-engineer.md +258 -0
- package/agents/expert-testing-evidence-collector.md +153 -0
- package/agents/expert-testing-performance-benchmarker.md +196 -0
- package/agents/expert-testing-reality-checker.md +235 -0
- package/agents/expert-testing-test-automation-engineer.md +40 -0
- package/agents/expert-testing-test-results-analyzer.md +313 -0
- package/agents/expert-testing-tool-evaluator.md +402 -0
- package/agents/expert-testing-workflow-optimizer.md +458 -0
- package/agents/expert-travel-planner.md +38 -0
- package/agents/expert-unity-architect.md +272 -0
- package/agents/expert-unity-editor-tool-developer.md +300 -0
- package/agents/expert-unity-multiplayer-engineer.md +238 -0
- package/agents/expert-unity-shader-graph-artist.md +270 -0
- package/agents/expert-unreal-multiplayer-architect.md +314 -0
- package/agents/expert-unreal-systems-engineer.md +311 -0
- package/agents/expert-unreal-technical-artist.md +256 -0
- package/agents/expert-unreal-world-builder.md +274 -0
- package/agents/expert-visionos-spatial-engineer.md +282 -0
- package/agents/expert-xr-cockpit-interaction-specialist.md +220 -0
- package/agents/expert-xr-immersive-developer.md +229 -0
- package/agents/expert-xr-interface-architect.md +253 -0
- package/agents/expert-zk-steward.md +228 -0
- package/agents/manager-academic-research.md +96 -0
- package/agents/manager-agent-governance.md +90 -0
- package/agents/manager-ai-llm.md +94 -0
- package/agents/manager-backend-architecture.md +106 -0
- package/agents/manager-business-strategy.md +102 -0
- package/agents/manager-business-support.md +96 -0
- package/agents/manager-customer-support.md +95 -0
- package/agents/manager-data-database.md +92 -0
- package/agents/manager-data-knowledge.md +88 -0
- package/agents/manager-data-testing.md +105 -0
- package/agents/manager-design-creative.md +103 -0
- package/agents/manager-devops-operations.md +92 -0
- package/agents/manager-embedded-iot.md +90 -0
- package/agents/manager-engineering-quality.md +94 -0
- package/agents/manager-finance-tax.md +99 -0
- package/agents/manager-frontend-client.md +116 -0
- package/agents/manager-game-dev.md +120 -0
- package/agents/manager-gis.md +104 -0
- package/agents/manager-government-public.md +84 -0
- package/agents/manager-healthcare.md +88 -0
- package/agents/manager-hr.md +87 -0
- package/agents/manager-language-translation.md +82 -0
- package/agents/manager-legal-compliance.md +86 -0
- package/agents/manager-marketing-growth.md +138 -0
- package/agents/manager-network-engineering.md +83 -0
- package/agents/manager-paid-media.md +92 -0
- package/agents/manager-product-management.md +90 -0
- package/agents/manager-project-management.md +94 -0
- package/agents/manager-sales-customer.md +97 -0
- package/agents/manager-security-compliance.md +109 -0
- package/agents/manager-spatial-computing.md +90 -0
- package/agents/manager-supply-chain.md +87 -0
- package/bin/cli.js +67 -0
- package/commands/wf/archive.md +107 -0
- package/commands/wf/check.md +68 -0
- package/commands/wf/deliver.md +76 -0
- package/commands/wf/design.md +56 -0
- package/commands/wf/dispatch.md +76 -0
- package/commands/wf/env.md +81 -0
- package/commands/wf/implement.md +96 -0
- package/commands/wf/plan.md +78 -0
- package/commands/wf/resume.md +59 -0
- package/commands/wf/spec.md +88 -0
- package/commands/wf/triage.md +50 -0
- package/commands/wf/verify.md +93 -0
- package/config/categories.json +557 -0
- package/config/experts.json +3318 -0
- package/config/workflow.json +847 -0
- package/context/context-manager.py +317 -0
- package/docs/workflow-fusion-design.md +239 -0
- package/hooks/hooks.json +20 -0
- package/hooks/prepend-global-rules-reminder.mjs +297 -0
- package/package.json +51 -3
- package/references/openspec-manual-mode.md +97 -0
- package/references/roles/analyst.md +62 -0
- package/references/roles/implementer.md +67 -0
- package/references/roles/investigator.md +88 -0
- package/references/roles/orchestrator.md +66 -0
- package/references/roles/reviewer.md +103 -0
- package/references/stage-S0-triage.md +56 -0
- package/references/stage-S1-design.md +53 -0
- package/references/stage-S2-spec.md +134 -0
- package/references/stage-S3-plan.md +84 -0
- package/references/stage-S4-env-baseline.md +80 -0
- package/references/stage-S5-implement.md +138 -0
- package/references/stage-S6-verify-review.md +80 -0
- package/references/stage-S7-deliver.md +81 -0
- package/references/stage-S8-sync-archive.md +162 -0
- package/references/workflow-tree.md +98 -0
- package/scripts/embedding_client.py +44 -0
- package/scripts/install.js +898 -0
- package/scripts/llm_client.py +202 -0
- package/scripts/openspec_engine.py +632 -0
- package/scripts/sdd/review-package +65 -0
- package/scripts/sdd/sdd-workspace +108 -0
- package/scripts/sdd/task-brief +49 -0
- package/scripts/workflow_check.py +1942 -0
- package/skill_entry.py +193 -0
- package/templates/bug-report.md +86 -0
- package/templates/minimal-contract.md +54 -0
- package/templates/plan-sections.md +190 -0
- package/templates/progress.md +89 -0
- package/templates/review-report.md +51 -0
- package/templates/task-report.md +84 -0
- package/vendor/skills/LICENSE +21 -0
- package/vendor/skills/PROVENANCE.md +79 -0
- package/vendor/skills/zes-brainstorming/SKILL.md +302 -0
- package/vendor/skills/zes-brainstorming/builder-check-prompt.md +23 -0
- package/vendor/skills/zes-code-review/SKILL.md +103 -0
- package/vendor/skills/zes-finishing/SKILL.md +233 -0
- package/vendor/skills/zes-openspec-apply-change/SKILL.md +206 -0
- package/vendor/skills/zes-openspec-archive-change/SKILL.md +221 -0
- package/vendor/skills/zes-openspec-explore/SKILL.md +356 -0
- package/vendor/skills/zes-openspec-propose/SKILL.md +175 -0
- package/vendor/skills/zes-openspec-sync-specs/SKILL.md +290 -0
- package/vendor/skills/zes-openspec-update-change/SKILL.md +109 -0
- package/vendor/skills/zes-receiving-review/SKILL.md +213 -0
- package/vendor/skills/zes-sdd/SKILL.md +345 -0
- package/vendor/skills/zes-sdd/references/batching.md +11 -0
- package/vendor/skills/zes-sdd/references/cannot-verify.md +10 -0
- package/vendor/skills/zes-sdd/references/final-review.md +47 -0
- package/vendor/skills/zes-sdd/references/fix-loop.md +77 -0
- package/vendor/skills/zes-sdd/references/handling-reports.md +15 -0
- package/vendor/skills/zes-sdd/references/preflight.md +26 -0
- package/vendor/skills/zes-sdd/references/resuming.md +12 -0
- package/vendor/skills/zes-systematic-debugging/SKILL.md +291 -0
- package/vendor/skills/zes-systematic-debugging/condition-based-waiting.md +115 -0
- package/vendor/skills/zes-systematic-debugging/defense-in-depth.md +122 -0
- package/vendor/skills/zes-systematic-debugging/find-polluter.sh +72 -0
- package/vendor/skills/zes-systematic-debugging/root-cause-tracing.md +169 -0
- package/vendor/skills/zes-tdd/SKILL.md +338 -0
- package/vendor/skills/zes-tdd/writing-good-tests.md +198 -0
- package/vendor/skills/zes-verification/SKILL.md +128 -0
- package/vendor/skills/zes-writing-plans/SKILL.md +212 -0
- package/zcode_dev_workflow.py +1136 -0
- package/zcode_expert_system.py +1016 -0
|
@@ -0,0 +1,1942 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
工作流阶段完整性核对(机械可验)
|
|
5
|
+
|
|
6
|
+
设计原则:**纯 Markdown 检查表一定会被跳过,必须机械可验。**
|
|
7
|
+
本脚本只做机器能判定的部分——文件存在性、计数对齐、占位符扫描、
|
|
8
|
+
账本身份、状态-勾选一致性、delta 来源。语义质量(评审是否到位、
|
|
9
|
+
根因是否真到位)不由脚本判定,交角色契约与主控。
|
|
10
|
+
|
|
11
|
+
唯一声明源:config/workflow.json(阶段/门禁/产物/证据级)。
|
|
12
|
+
本脚本不内嵌任何阶段常量,避免文档与实现漂移。
|
|
13
|
+
|
|
14
|
+
用法:
|
|
15
|
+
python scripts/workflow_check.py --change <change> [--plan <plan.md>] [--scale medium]
|
|
16
|
+
python scripts/workflow_check.py --change <change> --json
|
|
17
|
+
|
|
18
|
+
退出码:
|
|
19
|
+
0 全部通过
|
|
20
|
+
1 有 FAIL 项
|
|
21
|
+
2 参数/环境错误
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
import argparse
|
|
25
|
+
import io
|
|
26
|
+
import json
|
|
27
|
+
import os
|
|
28
|
+
import re
|
|
29
|
+
import sys
|
|
30
|
+
from datetime import datetime
|
|
31
|
+
from pathlib import Path
|
|
32
|
+
|
|
33
|
+
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
34
|
+
WORKFLOW_PATH = os.path.join(BASE_DIR, "config", "workflow.json")
|
|
35
|
+
|
|
36
|
+
OK = "OK"
|
|
37
|
+
WARN = "WARN"
|
|
38
|
+
FAIL = "FAIL"
|
|
39
|
+
SKIP = "SKIP"
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _force_utf8_stdout():
|
|
43
|
+
"""让 stdout/stderr 用 UTF-8 输出,避免非 UTF-8 控制台抛 UnicodeEncodeError。
|
|
44
|
+
|
|
45
|
+
背景(缺陷 #3 同族,P8 批次二补齐):中文 Windows 默认代码页 CP936 编不了
|
|
46
|
+
emoji 与 ✅/❌,而本工具的输出会携带账本/计划/路径的内容片段
|
|
47
|
+
(`项目根:%s` 打印、S4.LEDGER_ID 的首行摘要、--json 的
|
|
48
|
+
`ensure_ascii=False`),在 CP936 终端会 UnicodeEncodeError →
|
|
49
|
+
未捕获 traceback、rc=1——门禁工具自己先炸。四个 CLI 入口中本文件
|
|
50
|
+
是最后一个补齐的(另三个见各自同名函数)。
|
|
51
|
+
|
|
52
|
+
只挂 main()(CLI 入口),不挂 run():库调用方不应被改变 stdio 行为。
|
|
53
|
+
不改 ensure_ascii(会把中文与 emoji 全转成 \\uXXXX,破坏可读性与下游断言);
|
|
54
|
+
errors="replace" 仅作重配失败时的兜底,不得当主手段(emoji 变 ? 是数据损坏)。
|
|
55
|
+
"""
|
|
56
|
+
for stream_name in ("stdout", "stderr"):
|
|
57
|
+
stream = getattr(sys, stream_name, None)
|
|
58
|
+
reconfigure = getattr(stream, "reconfigure", None)
|
|
59
|
+
if reconfigure is None:
|
|
60
|
+
continue
|
|
61
|
+
try:
|
|
62
|
+
reconfigure(encoding="utf-8", errors="replace")
|
|
63
|
+
except (AttributeError, ValueError, OSError):
|
|
64
|
+
pass
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
# ---------------------------------------------------------------------------
|
|
68
|
+
# 理由码字典(固定,供测试断言;替代中文字面匹配)
|
|
69
|
+
#
|
|
70
|
+
# 设计意图:SKIP 只剩一个合法含义——「按声明这项本来就不该查」。
|
|
71
|
+
# 其余一切「没查成」都是 FAIL。这条规则由 Report.enforce_reasons() 机械执行,
|
|
72
|
+
# 所以未来新增的检查项自动继承,不需要靠 review 抓。
|
|
73
|
+
#
|
|
74
|
+
# 理由码前缀决定状态是否合法:
|
|
75
|
+
# inapplicable: → SKIP 唯一合法前缀(这项不该查)
|
|
76
|
+
# soft: → WARN 唯一合法前缀(此刻不必成立,将来才成立)
|
|
77
|
+
# unverifiable: / malformed: / missing: → 必须配 FAIL(查不了 / 格式错 / 应存在而缺)
|
|
78
|
+
# ---------------------------------------------------------------------------
|
|
79
|
+
|
|
80
|
+
REASON_INAPPLICABLE = "inapplicable"
|
|
81
|
+
REASON_SOFT = "soft"
|
|
82
|
+
REASON_UNVERIFIABLE = "unverifiable"
|
|
83
|
+
REASON_MALFORMED = "malformed"
|
|
84
|
+
REASON_MISSING = "missing"
|
|
85
|
+
|
|
86
|
+
VALID_SKIP_PREFIXES = (REASON_INAPPLICABLE + ":",)
|
|
87
|
+
VALID_WARN_PREFIXES = (REASON_SOFT + ":",)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
# ---------------------------------------------------------------------------
|
|
91
|
+
# 基础工具
|
|
92
|
+
# ---------------------------------------------------------------------------
|
|
93
|
+
|
|
94
|
+
def load_workflow():
|
|
95
|
+
with io.open(WORKFLOW_PATH, "r", encoding="utf-8") as f:
|
|
96
|
+
return json.load(f)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
class Report(object):
|
|
100
|
+
def __init__(self):
|
|
101
|
+
self.items = []
|
|
102
|
+
|
|
103
|
+
def add(self, gate, check, status, detail="", id=None, reason=None):
|
|
104
|
+
self.items.append({
|
|
105
|
+
"gate": gate, "check": check, "status": status,
|
|
106
|
+
"detail": detail, "id": id, "reason": reason})
|
|
107
|
+
|
|
108
|
+
def count(self, status):
|
|
109
|
+
return sum(1 for i in self.items if i["status"] == status)
|
|
110
|
+
|
|
111
|
+
def has_fail(self):
|
|
112
|
+
return self.count(FAIL) > 0
|
|
113
|
+
|
|
114
|
+
def enforce_reasons(self):
|
|
115
|
+
"""INV-R2:状态与理由码必须匹配,否则机械改判 FAIL。
|
|
116
|
+
|
|
117
|
+
两件事在这里自动完成,不依赖各检查器自觉:
|
|
118
|
+
|
|
119
|
+
1. SKIP 而理由码不以 `inapplicable:` 开头 → 改判 FAIL。
|
|
120
|
+
这是把「拿 SKIP 当放过」在架构上堵死:一处新的 `return SKIP`
|
|
121
|
+
即使忘了写理由,也不会变成假绿。
|
|
122
|
+
2. WARN 而理由码不以 `soft:` 开头 → 改判 FAIL。
|
|
123
|
+
WARN 只允许表达「此刻不必成立」,不允许表达「查不了」。
|
|
124
|
+
"""
|
|
125
|
+
for item in self.items:
|
|
126
|
+
reason = item["reason"] or ""
|
|
127
|
+
if item["status"] == SKIP and not reason.startswith(VALID_SKIP_PREFIXES):
|
|
128
|
+
item["status"] = FAIL
|
|
129
|
+
item["reason"] = "inapplicable:invalid"
|
|
130
|
+
item["detail"] = ("[inapplicable:invalid] SKIP 缺少合法理由码"
|
|
131
|
+
"(应写明「为何不该查」);原 detail: " + (item["detail"] or ""))
|
|
132
|
+
elif item["status"] == WARN and not reason.startswith(VALID_WARN_PREFIXES):
|
|
133
|
+
item["status"] = FAIL
|
|
134
|
+
item["reason"] = "malformed:soft_reason"
|
|
135
|
+
item["detail"] = ("[malformed:soft_reason] WARN 只用于「此刻不必成立」,"
|
|
136
|
+
"查不了/格式错必须判 FAIL;原 detail: "
|
|
137
|
+
+ (item["detail"] or ""))
|
|
138
|
+
|
|
139
|
+
def render(self):
|
|
140
|
+
lines = []
|
|
141
|
+
cur = None
|
|
142
|
+
for i in self.items:
|
|
143
|
+
if i["gate"] != cur:
|
|
144
|
+
cur = i["gate"]
|
|
145
|
+
lines.append("")
|
|
146
|
+
lines.append("【%s】" % cur)
|
|
147
|
+
mark = {OK: "[ OK ]", WARN: "[WARN]", FAIL: "[FAIL]", SKIP: "[SKIP]"}[i["status"]]
|
|
148
|
+
line = " %s %s" % (mark, i["check"])
|
|
149
|
+
if i["detail"]:
|
|
150
|
+
line += " —— %s" % i["detail"]
|
|
151
|
+
lines.append(line)
|
|
152
|
+
lines.append("")
|
|
153
|
+
lines.append("汇总:OK %d / WARN %d / FAIL %d / SKIP %d" % (
|
|
154
|
+
self.count(OK), self.count(WARN), self.count(FAIL), self.count(SKIP)))
|
|
155
|
+
return "\n".join(lines)
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def read(path):
|
|
159
|
+
"""读取文本文件。
|
|
160
|
+
|
|
161
|
+
**用 `utf-8-sig` 而非 `utf-8`**(P6 复核审查 A-1 的核心修复):
|
|
162
|
+
BOM(U+FEFF)在 `utf-8` 下会作为普通字符保留在字符串开头,而
|
|
163
|
+
Python 的 `\\s` 不匹配 U+FEFF、JavaScript 的 `\\s` 匹配 —— 同一行
|
|
164
|
+
在检查器里不算任务、在 OpenSpec 真相源里算任务。
|
|
165
|
+
|
|
166
|
+
后果是**假绿**:带 BOM 的 tasks.md 若首行未完成,该行从分子分母
|
|
167
|
+
同时消失(done==total),归档门禁通过;而 `openspec archive` 会按
|
|
168
|
+
真实计数拒绝。Windows 记事本与多数编辑器默认存 UTF-8 with BOM。
|
|
169
|
+
|
|
170
|
+
`utf-8-sig` 对不含 BOM 的文件行为与 `utf-8` 完全一致,
|
|
171
|
+
含 BOM 时自动剥掉开头那一个。
|
|
172
|
+
"""
|
|
173
|
+
try:
|
|
174
|
+
with io.open(path, "r", encoding="utf-8-sig") as f:
|
|
175
|
+
return f.read()
|
|
176
|
+
except (OSError, UnicodeDecodeError):
|
|
177
|
+
return None
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
# ---------------------------------------------------------------------------
|
|
181
|
+
# tasks.md 勾选解析
|
|
182
|
+
#
|
|
183
|
+
# 正则直接镜像 OpenSpec 自己的解析器(真相源):
|
|
184
|
+
# node_modules/@fission-ai/openspec/dist/utils/task-progress.js
|
|
185
|
+
# 其注释逐条记录了本类漏洞:只认 `-` 会漏掉 `*`/`+`/`1.` 的任务;
|
|
186
|
+
# 锚定列 0 会漏掉嵌套子任务;只认 `[ ]`/`[x]` 会让 `[~]` 缩小分母
|
|
187
|
+
# (即「写 [~] 反而让完成度看起来更高」)。这里逐条对齐,避免与真相源漂移。
|
|
188
|
+
#
|
|
189
|
+
# 关键细节:闭括号后不得紧跟 `(` 或 `[`——那是 Markdown 链接语法
|
|
190
|
+
# (`- [Some doc](./d.md)`),否则每个链接列表都会变成一堆「未完成任务」。
|
|
191
|
+
#
|
|
192
|
+
# 两处与 JS 真相源的刻意对齐(P6 复核审查发现):
|
|
193
|
+
# 1. `\ufeff?` 前置 —— 即使 read() 已用 utf-8-sig,这里再兜一层:
|
|
194
|
+
# 任何来源(含用户手工传入的字符串)带 BOM 都不该让首行任务消失。
|
|
195
|
+
# 2. `\d` 全部改成 `[0-9]` —— Python 的 `\d` 是 Unicode 感知的
|
|
196
|
+
# (匹配全角 `1`),JS 的只认 ASCII。不换会导致中文文档里的
|
|
197
|
+
# 全角编号在检查器算任务、在真相源不算,分母虚增。
|
|
198
|
+
# ---------------------------------------------------------------------------
|
|
199
|
+
|
|
200
|
+
_TASK_LINE_PATTERN = re.compile(
|
|
201
|
+
r"^\ufeff?\s*(?:[-*+]|[0-9]{1,9}[.)])\s*\[(?:\s*([^\]\s]?)\s*\](?![([])|\s+\])\s*(.*)")
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
def parse_task_lines(text):
|
|
205
|
+
"""逐行解析勾选框,返回 [(done_bool, description), ...](文档序)。
|
|
206
|
+
|
|
207
|
+
每一条匹配到的行都计入,不论它是否在代码围栏/HTML 注释里——
|
|
208
|
+
这是 OpenSpec 的取舍:把示例误当任务是可纠正的假阳性(响),
|
|
209
|
+
而丢掉真实任务是静默的假阴性(不响)。
|
|
210
|
+
"""
|
|
211
|
+
out = []
|
|
212
|
+
for line in (text or "").splitlines():
|
|
213
|
+
m = _TASK_LINE_PATTERN.match(line)
|
|
214
|
+
if m:
|
|
215
|
+
mark = (m.group(1) or "").lower()
|
|
216
|
+
out.append((mark == "x", (m.group(2) or "").strip()))
|
|
217
|
+
return out
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
def count_checkboxes(text):
|
|
221
|
+
"""统计 tasks.md 的勾选。只有 x/X 算完成(OpenSpec 归档口径)。
|
|
222
|
+
|
|
223
|
+
返回 done/todo/other 三项,且恒有 done + todo + other == 总任务行数。
|
|
224
|
+
口径:空框 [] 算 todo;仅 x/X 算 done([ x ] 带空格同样算 x,与官方
|
|
225
|
+
task-progress.js 口径一致);其余非空非 x([~]/[1] 等)算 other。
|
|
226
|
+
单独分出 other 只为诊断信息更具体(异形标记 vs 空框),不影响完成判定。
|
|
227
|
+
"""
|
|
228
|
+
done = todo = other = 0
|
|
229
|
+
for line in (text or "").splitlines():
|
|
230
|
+
m = _TASK_LINE_PATTERN.match(line)
|
|
231
|
+
if not m:
|
|
232
|
+
continue
|
|
233
|
+
mark = (m.group(1) or "").lower()
|
|
234
|
+
if mark == "x":
|
|
235
|
+
done += 1
|
|
236
|
+
elif mark == "":
|
|
237
|
+
todo += 1
|
|
238
|
+
else:
|
|
239
|
+
other += 1
|
|
240
|
+
return {"done": done, "todo": todo, "other": other}
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
def detect_bullet_styles(text):
|
|
244
|
+
"""诊断用:报告 tasks.md 里实际出现过哪些列表符,供 malformed 时提示用户。"""
|
|
245
|
+
styles = []
|
|
246
|
+
for line in (text or "").splitlines():
|
|
247
|
+
m = re.match(r"^\s*([-*+]|\d{1,9}[.)])\s*\[", line)
|
|
248
|
+
if m and m.group(1) not in styles:
|
|
249
|
+
styles.append(m.group(1))
|
|
250
|
+
return styles
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
# ---------------------------------------------------------------------------
|
|
254
|
+
# 段名精确匹配
|
|
255
|
+
#
|
|
256
|
+
# 修的不是「正则写错」,而是「把前缀匹配当前缀匹配用」:
|
|
257
|
+
# `^#+\s*Review` 会命中 `## Review Focus`,于是 S3 的计划必备段
|
|
258
|
+
# `## Review Focus` 冒充了 S6 的审查结论段 `## Review`;
|
|
259
|
+
# `Spec` 会命中 `## Specification`,架构段会命中 `## Architecture Notes`。
|
|
260
|
+
# 必备段检查因此形同虚设——任何段只要「以必备段名开头」就算写了。
|
|
261
|
+
# ---------------------------------------------------------------------------
|
|
262
|
+
|
|
263
|
+
def _section_re(name):
|
|
264
|
+
"""精确段名:允许行尾括注(`## Review(审查结论)`),禁止前缀吞并。"""
|
|
265
|
+
return re.compile(
|
|
266
|
+
r"^#{1,6}[ \t]+%s[ \t]*(?:[((::][^\n]*)?$" % re.escape(name),
|
|
267
|
+
re.M | re.I)
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
def strip_code_fences(text):
|
|
271
|
+
"""剥离 ``` 围栏块:模板里的示例段不得充当真实证据。"""
|
|
272
|
+
if not text:
|
|
273
|
+
return ""
|
|
274
|
+
return re.sub(r"^[ \t]*```.*?^[ \t]*```[ \t]*$", "", text, flags=re.M | re.S)
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
def has_section(text, name):
|
|
278
|
+
"""计划/账本里是否存在名为 name 的段(精确匹配,忽略围栏块内的示例)。"""
|
|
279
|
+
return _section_re(name).search(strip_code_fences(text)) is not None
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
def section_body(text, name, keep_fences=False):
|
|
283
|
+
"""取某段正文(到下一个同级或更高级标题为止)。找不到返回 None。
|
|
284
|
+
|
|
285
|
+
keep_fences=False(默认)会剥离 ``` 围栏块——用于「段存在性」判断,
|
|
286
|
+
防模板示例冒充真实段落。
|
|
287
|
+
|
|
288
|
+
keep_fences=True 保留围栏内容——用于「段内结论载体」判断。
|
|
289
|
+
理由:`templates/plan-sections.md` 规定 `## Review` 的内容就写在
|
|
290
|
+
```markdown 围栏里(那是填写位);若这里也剥掉,模板照抄的文档
|
|
291
|
+
永远被判「段存在但无结论」,而它其实填得好好的。
|
|
292
|
+
实测症状:本计划文档正确写了 spec/quality,却被判 soft:review_section_empty。
|
|
293
|
+
"""
|
|
294
|
+
clean = text if keep_fences else strip_code_fences(text)
|
|
295
|
+
m = _section_re(name).search(clean)
|
|
296
|
+
if not m:
|
|
297
|
+
return None
|
|
298
|
+
start = m.end()
|
|
299
|
+
level = len(re.match(r"#+", clean[m.start():]).group(0))
|
|
300
|
+
rest = clean[start:]
|
|
301
|
+
stop = re.search(r"^#{1,%d}[ \t]+\S" % level, rest, re.M)
|
|
302
|
+
return rest[:stop.start()] if stop else rest
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
def strip_quoted_markers(text):
|
|
306
|
+
"""剥离「文档里引用的示例」再找标记,避免把说明文字当成真实结论。
|
|
307
|
+
|
|
308
|
+
真实场景(本计划文档自身就踩到):计划文档会写
|
|
309
|
+
「修前:`independence: L0 设想` + `independence: L2` → 判 L0」这类**引用**。
|
|
310
|
+
取最坏值策略下,这些引用会被当成真实标记,
|
|
311
|
+
于是「正确记录了修复内容」的文档反而被判 L2 禁止交付——
|
|
312
|
+
这正是「过度收紧造成假红」的典型形态。
|
|
313
|
+
|
|
314
|
+
**剥什么、留什么**(A-6 修复后):
|
|
315
|
+
|
|
316
|
+
剥掉:
|
|
317
|
+
- 行内代码 `` `...` `` 的内容 —— 引用与模板示例都在其中
|
|
318
|
+
- **无键名**的表格行 —— 纯数据对照表(如「| L0 | 独立审查 |」),
|
|
319
|
+
那不是结论,只是级别说明
|
|
320
|
+
|
|
321
|
+
保留:
|
|
322
|
+
- **含键名**的表格行 —— 例如 `| independence | L0 |`
|
|
323
|
+
表格是本项目模板的主推排版(Baseline、Integration Verification、
|
|
324
|
+
Triage 全是表格)。整行丢弃会让「用表格填标记」被判缺标记(假红),
|
|
325
|
+
而它对 L0 和 L2 的错法还不一致——L2 本该 FAIL 却变成「缺标记」。
|
|
326
|
+
|
|
327
|
+
判据是「行内有没有出现被找的那个键名」。这里不硬编码键名列表,
|
|
328
|
+
而是把整行保留、由调用方的正则去判断——表格行里的 `| independence | L0 |`
|
|
329
|
+
与正文里的 `independence: L0` 会被同一个正则命中,因为 `\\s*[::]\\s*`
|
|
330
|
+
在表格里退化为 `\\s+|\\s*` 的宽松匹配。
|
|
331
|
+
"""
|
|
332
|
+
# 表格行里常见的「键 | 值」分隔:`| key | value |`
|
|
333
|
+
TABLE_KV = re.compile(
|
|
334
|
+
r"\|\s*(?:independence|spec|quality|reviewer|implementer|round)\s*\|",
|
|
335
|
+
re.I)
|
|
336
|
+
out = []
|
|
337
|
+
for line in (text or "").splitlines():
|
|
338
|
+
stripped = line.lstrip()
|
|
339
|
+
if stripped.startswith("|"):
|
|
340
|
+
if TABLE_KV.search(line):
|
|
341
|
+
# 含键名的表格行:把 `| key | value |` 改写成 `key: value`,
|
|
342
|
+
# 让下游正则无需为表格做特殊处理
|
|
343
|
+
cells = [c.strip() for c in line.strip().strip("|").split("|")]
|
|
344
|
+
if len(cells) >= 2 and cells[0] and cells[1]:
|
|
345
|
+
out.append("%s: %s" % (cells[0], cells[1]))
|
|
346
|
+
else:
|
|
347
|
+
out.append(line)
|
|
348
|
+
# 无键名的表格行:纯数据对照表,丢弃
|
|
349
|
+
continue
|
|
350
|
+
out.append(re.sub(r"`[^`]*`", "", line)) # 去掉行内代码引用
|
|
351
|
+
return "\n".join(out)
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
# ---------------------------------------------------------------------------
|
|
355
|
+
# 规模 / 裁剪
|
|
356
|
+
# ---------------------------------------------------------------------------
|
|
357
|
+
|
|
358
|
+
TRIM_MODES = ("必", "简", "条", "-")
|
|
359
|
+
|
|
360
|
+
# 「简」模式下每个阶段保留的机器承重项。定义依据只有一条:
|
|
361
|
+
# **该项是下游机械消费的输入,还是给人看的格式?**
|
|
362
|
+
#
|
|
363
|
+
# 下游消费 → 简也必须查:
|
|
364
|
+
# S3 的计划文件存在(task-brief 要读)、`### Task N:`(task-brief 正则依赖)、
|
|
365
|
+
# 勾选框(openspec list --json 的 totalTasks 来源)
|
|
366
|
+
# 纯格式/给人看 → 简可省:
|
|
367
|
+
# 8 个必备段的「存在性」——脚本无法验证「Architecture 段的内容是否成立」,
|
|
368
|
+
# 查 `^## Architecture` 只能证明有人写了标题。
|
|
369
|
+
LIGHT_KEEP = {
|
|
370
|
+
"S3": ("plan_exists", "task_titles", "placeholders", "align"),
|
|
371
|
+
"S6": ("independence",),
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
def scale_keys(wf):
|
|
376
|
+
"""workflow.json 声明的合法规模键(按声明序)。"""
|
|
377
|
+
return [k for k in wf.get("scale", {}) if not k.startswith("$")]
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
def normalize_scale(wf, scale):
|
|
381
|
+
"""规范化规模值。返回 (key, valid)。
|
|
382
|
+
|
|
383
|
+
**严格相等,不做大小写/空白宽容**(有意为之):
|
|
384
|
+
`--scale` 直接决定哪些门禁执行,属于「判定输入」,不接受猜测。
|
|
385
|
+
`Medium` / ` medium` / `LIGHT` 一律判非法并报错列出合法取值——
|
|
386
|
+
这比「猜成 medium 然后悄悄放行」安全:后者会让一次笔误变成
|
|
387
|
+
一次未经声明的门禁裁剪,而报告里看不出任何异常。
|
|
388
|
+
"""
|
|
389
|
+
key = scale if isinstance(scale, str) else ""
|
|
390
|
+
return key, key in scale_keys(wf)
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
def trim_of(wf, scale_key, sid):
|
|
394
|
+
"""该规模下该阶段的裁剪标记。合法规模下必然命中;非法返回 None。"""
|
|
395
|
+
matrix = wf.get("trim_matrix", {})
|
|
396
|
+
row = matrix.get(scale_key)
|
|
397
|
+
if not isinstance(row, dict):
|
|
398
|
+
return None
|
|
399
|
+
return row.get(sid)
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
def gate_label(wf, sid):
|
|
403
|
+
"""门禁显示名从 workflow.json 派生,避免 39 处硬编码各自漂移。"""
|
|
404
|
+
try:
|
|
405
|
+
st = _stage(wf, sid)
|
|
406
|
+
except KeyError:
|
|
407
|
+
return sid
|
|
408
|
+
short = st.get("short") or st.get("name") or sid
|
|
409
|
+
return "%s · %s %s" % (st.get("gate", ""), st["id"], short)
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
def light_wants(ctx, sid, item):
|
|
413
|
+
"""「简」模式下是否检查某个可选项。非「简」时一律检查。"""
|
|
414
|
+
if ctx.get("trim") != "简":
|
|
415
|
+
return True
|
|
416
|
+
keep = LIGHT_KEEP.get(sid)
|
|
417
|
+
if keep is None:
|
|
418
|
+
return True
|
|
419
|
+
return item in keep
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
# ---------------------------------------------------------------------------
|
|
423
|
+
# 各阶段检查
|
|
424
|
+
# ---------------------------------------------------------------------------
|
|
425
|
+
|
|
426
|
+
def _triage_has_domain_rows(ltext):
|
|
427
|
+
"""账本 Triage 段是否含 S0 即产生的域路由两行(领域 / 专家)。
|
|
428
|
+
|
|
429
|
+
只查 `## Triage` 段内的表格行——C3 约束:Dispatches 派发行 S5 才产生,
|
|
430
|
+
禁查;限定段内也天然把派发行排除在外。行格式对齐 templates/progress.md
|
|
431
|
+
Triage 表与真实账本:
|
|
432
|
+
| 领域(category) | backend-architecture |
|
|
433
|
+
| 专家(name/basis) | 软件架构师(semantic) |
|
|
434
|
+
两行齐备才算「有行」——只补一行仍是域路由信息不完整,判缺。
|
|
435
|
+
"""
|
|
436
|
+
body = section_body(ltext or "", "Triage")
|
|
437
|
+
if not body:
|
|
438
|
+
return False
|
|
439
|
+
keys = []
|
|
440
|
+
for line in body.splitlines():
|
|
441
|
+
s = line.strip()
|
|
442
|
+
if not s.startswith("|"):
|
|
443
|
+
continue
|
|
444
|
+
first = s.strip("|").split("|")[0].strip()
|
|
445
|
+
if first:
|
|
446
|
+
keys.append(first)
|
|
447
|
+
return (any("领域" in k for k in keys)
|
|
448
|
+
and any("专家" in k for k in keys))
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
def check_S0(ctx, rep, wf):
|
|
452
|
+
"""S0:环境探测必须真实发生,规模必须合法可裁剪。"""
|
|
453
|
+
label = gate_label(wf, "S0")
|
|
454
|
+
|
|
455
|
+
probed = ctx["env_probed"]
|
|
456
|
+
rep.add(label, "环境已探测(git / openspec root)",
|
|
457
|
+
OK if probed else FAIL,
|
|
458
|
+
ctx["env_summary"] if probed
|
|
459
|
+
else "[unverifiable:root] 项目根不可读:%s" % ctx["root"],
|
|
460
|
+
id="S0.ENV",
|
|
461
|
+
reason=None if probed else "unverifiable:root")
|
|
462
|
+
|
|
463
|
+
scale = ctx["scale"]
|
|
464
|
+
valid = ctx["scale_valid"]
|
|
465
|
+
if not scale:
|
|
466
|
+
rep.add(label, "规模已分类", FAIL,
|
|
467
|
+
"[unverifiable:scale] 未提供 --scale;本工具不做推断",
|
|
468
|
+
id="S0.SCALE", reason="unverifiable:scale")
|
|
469
|
+
elif not valid:
|
|
470
|
+
rep.add(label, "规模已分类", FAIL,
|
|
471
|
+
"[unverifiable:scale] scale=%r 不在 %s 内——未知规模无法查裁剪矩阵,"
|
|
472
|
+
"本次按最严(全部阶段按「必」)执行"
|
|
473
|
+
% (scale, "|".join(scale_keys(wf))),
|
|
474
|
+
id="S0.SCALE", reason="unverifiable:scale")
|
|
475
|
+
else:
|
|
476
|
+
row = wf.get("trim_matrix", {}).get(ctx["scale_key"], {})
|
|
477
|
+
rep.add(label, "规模已分类", OK,
|
|
478
|
+
"scale=%s(裁剪:%s)" % (
|
|
479
|
+
ctx["scale_key"],
|
|
480
|
+
" ".join("%s=%s" % (k, v) for k, v in row.items()
|
|
481
|
+
if not k.startswith("$"))),
|
|
482
|
+
id="S0.SCALE")
|
|
483
|
+
|
|
484
|
+
# --- S0.DOMAIN(enforce-domain-routing A 案六格判定表,design §3) ---
|
|
485
|
+
#
|
|
486
|
+
# 判定表(首列=账本 Scale,双语):
|
|
487
|
+
# 任何规模 + 无账本 → SKIP inapplicable:no_ledger
|
|
488
|
+
# 任何规模 + 账本不可读 → FAIL malformed_ledger
|
|
489
|
+
# readonly + 有账本 → SKIP inapplicable:readonly_no_ledger_expected(D4)
|
|
490
|
+
# 非只读 + 有账本 + 缺行 → FAIL s0_domain_missing(A 案执法核心格)
|
|
491
|
+
# 非只读 + 有账本 + 有行 → OK
|
|
492
|
+
#
|
|
493
|
+
# 账本关联(#11):给了 --plan 时只查 plan 关联 workspace 的账本
|
|
494
|
+
# (find_workspace),**不做 discover_ledger 全仓兜底**——本仓存在遗留
|
|
495
|
+
# 账本(openspec-impl / vendor-skills,均无 Triage 域路由行),扫全仓
|
|
496
|
+
# 会让遗留账本无限期 FAIL。未给 --plan 时沿用 ctx["ledger"](现有发现
|
|
497
|
+
# 机制,readonly 逃逸守卫依赖它)。
|
|
498
|
+
# Scale 双语(#10):账本 Scale 段实测写中文(「中任务」「只读」),
|
|
499
|
+
# readonly 判定走 parse_scale_section 的双语解析;解析不出(段缺失/
|
|
500
|
+
# 歧义)回退 --scale。执法偏向:两边都无法确定规模时按非只读执法。
|
|
501
|
+
if ctx["plan"]:
|
|
502
|
+
ws = find_workspace(ctx["root"], ctx["plan"])
|
|
503
|
+
ledger = (os.path.join(ws, "progress.md")
|
|
504
|
+
if ws and os.path.exists(os.path.join(ws, "progress.md"))
|
|
505
|
+
else None)
|
|
506
|
+
else:
|
|
507
|
+
ledger = ctx["ledger"]
|
|
508
|
+
|
|
509
|
+
if ledger is None:
|
|
510
|
+
rep.add(label, "Triage 域路由行(S0.DOMAIN)", SKIP,
|
|
511
|
+
"[inapplicable:no_ledger] 无关联账本——S0 账本锚不存在,无从执法",
|
|
512
|
+
id="S0.DOMAIN", reason="inapplicable:no_ledger")
|
|
513
|
+
return
|
|
514
|
+
ltext = read(ledger)
|
|
515
|
+
if ltext is None:
|
|
516
|
+
rep.add(label, "Triage 域路由行(S0.DOMAIN)", FAIL,
|
|
517
|
+
"[malformed_ledger] 账本存在但读不出(%s)——「查不了」不允许静默放行"
|
|
518
|
+
% ledger,
|
|
519
|
+
id="S0.DOMAIN", reason="malformed_ledger")
|
|
520
|
+
return
|
|
521
|
+
recorded = parse_scale_section(ltext)
|
|
522
|
+
is_readonly = (recorded == "readonly") if recorded else (ctx["scale_key"] == "readonly")
|
|
523
|
+
if is_readonly:
|
|
524
|
+
rep.add(label, "Triage 域路由行(S0.DOMAIN)", SKIP,
|
|
525
|
+
"[inapplicable:readonly_no_ledger_expected] readonly 按裁剪不产生账本"
|
|
526
|
+
"(D4)——本格判 SKIP,不按账本执法、不造假绿",
|
|
527
|
+
id="S0.DOMAIN", reason="inapplicable:readonly_no_ledger_expected")
|
|
528
|
+
return
|
|
529
|
+
if _triage_has_domain_rows(ltext):
|
|
530
|
+
rep.add(label, "Triage 域路由行(S0.DOMAIN)", OK,
|
|
531
|
+
"Triage 段含域路由两行(领域/专家)——非只读任务执法锚在位",
|
|
532
|
+
id="S0.DOMAIN")
|
|
533
|
+
else:
|
|
534
|
+
rep.add(label, "Triage 域路由行(S0.DOMAIN)", FAIL,
|
|
535
|
+
"[s0_domain_missing] 账本缺 Triage 域路由两行(「领域(category)」"
|
|
536
|
+
"与「专家(name/basis)」)——A 案执法:有账本的非只读任务缺行即 FAIL",
|
|
537
|
+
id="S0.DOMAIN", reason="s0_domain_missing")
|
|
538
|
+
|
|
539
|
+
|
|
540
|
+
def check_S1(ctx, rep, wf):
|
|
541
|
+
"""S1:阶段一不落盘是设计,这里只查有没有违规落盘。"""
|
|
542
|
+
label = gate_label(wf, "S1")
|
|
543
|
+
specs_dir = os.path.join(ctx["root"], "docs", "superpowers", "specs")
|
|
544
|
+
if not os.path.isdir(specs_dir):
|
|
545
|
+
rep.add(label, "设计未违规落盘(R3)", OK, "docs/superpowers/specs/ 不存在",
|
|
546
|
+
id="S1.DESIGN_LEAK")
|
|
547
|
+
return
|
|
548
|
+
# 「本次」的机械判据只能是日期。旧实现还匹配文件名含 "design",
|
|
549
|
+
# 会把一年前的 old-redesign.md 判成本次违规(实测 WARN 误报)。
|
|
550
|
+
files = [f for f in os.listdir(specs_dir) if f.endswith(".md")]
|
|
551
|
+
stale = [f for f in files if ctx["today"] in f]
|
|
552
|
+
if not stale:
|
|
553
|
+
rep.add(label, "设计未违规落盘(R3)", OK, "无本次设计文件",
|
|
554
|
+
id="S1.DESIGN_LEAK")
|
|
555
|
+
return
|
|
556
|
+
bad = []
|
|
557
|
+
for f in stale:
|
|
558
|
+
head = read(os.path.join(specs_dir, f))
|
|
559
|
+
if head is None or "非权威" not in head[:200]:
|
|
560
|
+
# 三态:不可读 ≠ 未标注。不可读文件显式标注,防「读不出」
|
|
561
|
+
# 被压成「查过且未标注」(A-9)。
|
|
562
|
+
bad.append(f if head is not None else f + "(不可读)")
|
|
563
|
+
if bad:
|
|
564
|
+
rep.add(label, "设计未违规落盘(R3)", WARN,
|
|
565
|
+
"[soft:design_not_marked] 存在未标注『非权威』的设计文件:%s"
|
|
566
|
+
% ", ".join(bad[:3]),
|
|
567
|
+
id="S1.DESIGN_LEAK", reason="soft:design_not_marked")
|
|
568
|
+
else:
|
|
569
|
+
rep.add(label, "设计未违规落盘(R3)", OK, "已标注非权威",
|
|
570
|
+
id="S1.DESIGN_LEAK")
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
def _archived_entry(ctx):
|
|
574
|
+
"""在 openspec/changes/archive/ 下找「日期前缀 + 精确变更名」的目录。
|
|
575
|
+
|
|
576
|
+
精确匹配,不用子串:旧实现 `ctx["change"] in e` 会让 `my-change`
|
|
577
|
+
命中 `archive/2026-01-01-my-change-v2/`。
|
|
578
|
+
"""
|
|
579
|
+
if not ctx.get("change"):
|
|
580
|
+
return None
|
|
581
|
+
arch = os.path.join(ctx["root"], "openspec", "changes", "archive")
|
|
582
|
+
if not os.path.isdir(arch):
|
|
583
|
+
return None
|
|
584
|
+
pat = re.compile(r"^\d{4}-\d{2}-\d{2}-%s$" % re.escape(ctx["change"]))
|
|
585
|
+
for name in sorted(os.listdir(arch)):
|
|
586
|
+
if pat.match(name) and os.path.isdir(os.path.join(arch, name)):
|
|
587
|
+
return name
|
|
588
|
+
return None
|
|
589
|
+
|
|
590
|
+
|
|
591
|
+
def check_S2(ctx, rep, wf):
|
|
592
|
+
"""规格产物存在性。路径来自 workflow.json 的 artifacts 声明。
|
|
593
|
+
|
|
594
|
+
**三态分流**是这里的核心(缺陷 #1):
|
|
595
|
+
未初始化 OpenSpec 且调用方未显式 --change、且该规模下 S2 为条件触发
|
|
596
|
+
(trim="条")→ SKIP(非 OpenSpec 项目是合法形态)
|
|
597
|
+
已显式 --change 却未初始化 OpenSpec → FAIL(调用方声明本阶段适用,
|
|
598
|
+
目录却不存在,事实与声明不符)
|
|
599
|
+
已初始化但变更目录不存在 → FAIL(拼错 / 未创建 / 已归档,
|
|
600
|
+
都不是「不适用」)
|
|
601
|
+
fail-closed:宁可错杀漏报也不放行无法核实的规格。
|
|
602
|
+
"""
|
|
603
|
+
label = gate_label(wf, "S2")
|
|
604
|
+
stage = _stage(wf, "S2")
|
|
605
|
+
change_dir = ctx["change_dir"]
|
|
606
|
+
|
|
607
|
+
# 变更名本身非法(含 `..` 等):已在 run() 记过 S0.CHANGE_NAME,
|
|
608
|
+
# 这里不再把它当「目录不存在」重复报,而是明确指向格式问题。
|
|
609
|
+
if ctx.get("change_invalid"):
|
|
610
|
+
rep.add(label, "变更目录存在", FAIL,
|
|
611
|
+
"[malformed:change_name] %r 不是合法变更名,无法定位目录"
|
|
612
|
+
% ctx["change"],
|
|
613
|
+
id="S2.CHANGE_DIR", reason="malformed:change_name")
|
|
614
|
+
return
|
|
615
|
+
|
|
616
|
+
if not change_dir or not os.path.isdir(change_dir):
|
|
617
|
+
if ctx.get("change"):
|
|
618
|
+
archived = _archived_entry(ctx)
|
|
619
|
+
if not ctx["openspec"]:
|
|
620
|
+
rep.add(label, "变更目录存在", FAIL,
|
|
621
|
+
"[unverifiable:no_openspec_root] 未初始化 OpenSpec,"
|
|
622
|
+
"但已显式声明 --change=%r:无法核验(root:null 不是免责理由)"
|
|
623
|
+
% ctx["change"],
|
|
624
|
+
id="S2.CHANGE_DIR", reason="unverifiable:no_openspec_root")
|
|
625
|
+
elif archived:
|
|
626
|
+
rep.add(label, "变更目录存在", FAIL,
|
|
627
|
+
"[missing:change_dir] 变更 %r 已归档到 %s;"
|
|
628
|
+
"请核对进行中的变更,不要对已结束的变更做门禁核对"
|
|
629
|
+
% (ctx["change"], archived),
|
|
630
|
+
id="S2.CHANGE_DIR", reason="missing:change_dir")
|
|
631
|
+
else:
|
|
632
|
+
rep.add(label, "变更目录存在", FAIL,
|
|
633
|
+
"[missing:change_dir] openspec/changes/%s 不存在"
|
|
634
|
+
"(拼写错误?或该变更尚未创建?若尚未进入 S2,请先不要传 --change)"
|
|
635
|
+
% ctx["change"],
|
|
636
|
+
id="S2.CHANGE_DIR", reason="missing:change_dir")
|
|
637
|
+
else:
|
|
638
|
+
# 本阶段未被裁剪,但调用方没给 --change。
|
|
639
|
+
# 必/简 → 无法核验(FAIL);条 → 触发条件不成立(SKIP)。
|
|
640
|
+
trim = ctx.get("trim") or "必"
|
|
641
|
+
if trim in ("必", "简"):
|
|
642
|
+
rep.add(label, "变更目录存在", FAIL,
|
|
643
|
+
"[unverifiable:change_required] 该规模下 S2 不被裁剪,"
|
|
644
|
+
"必须提供 --change(当前 scale=%s)" % ctx.get("scale_key"),
|
|
645
|
+
id="S2.CHANGE_DIR", reason="unverifiable:change_required")
|
|
646
|
+
else:
|
|
647
|
+
rep.add(label, "变更目录存在", SKIP,
|
|
648
|
+
"[inapplicable:trigger:openspec] scale=%s 下 S2 为条件触发;"
|
|
649
|
+
"openspec=%s 且未提供 --change,触发条件不成立"
|
|
650
|
+
% (ctx.get("scale_key"), "有" if ctx.get("openspec") else "无"),
|
|
651
|
+
id="S2.CHANGE_DIR", reason="inapplicable:trigger:openspec")
|
|
652
|
+
return
|
|
653
|
+
|
|
654
|
+
rep.add(label, "变更目录存在", OK, change_dir, id="S2.CHANGE_DIR")
|
|
655
|
+
|
|
656
|
+
for art in stage["artifacts"]:
|
|
657
|
+
name = os.path.basename(art["path"].rstrip("/"))
|
|
658
|
+
required = art.get("required", False)
|
|
659
|
+
if art.get("glob"):
|
|
660
|
+
found = expand_artifact(ctx["root"], art["path"], ctx["change"])
|
|
661
|
+
if found:
|
|
662
|
+
rep.add(label, "%s(glob)" % name, OK, "%d 个匹配" % len(found),
|
|
663
|
+
id="S2.ARTIFACT:%s" % name)
|
|
664
|
+
else:
|
|
665
|
+
rep.add(label, "%s(glob)" % name, FAIL,
|
|
666
|
+
"[missing:%s] 未找到:%s%s" % (
|
|
667
|
+
name, art["path"],
|
|
668
|
+
"(required=true)" if required else ""),
|
|
669
|
+
id="S2.ARTIFACT:%s" % name, reason="missing:%s" % name)
|
|
670
|
+
continue
|
|
671
|
+
p = os.path.join(change_dir, name)
|
|
672
|
+
exists = os.path.exists(p)
|
|
673
|
+
if exists:
|
|
674
|
+
rep.add(label, name, OK, "", id="S2.ARTIFACT:%s" % name)
|
|
675
|
+
elif required:
|
|
676
|
+
rep.add(label, name, FAIL,
|
|
677
|
+
"[missing:%s] 缺失:%s(required=true)" % (name, p),
|
|
678
|
+
id="S2.ARTIFACT:%s" % name, reason="missing:%s" % name)
|
|
679
|
+
else:
|
|
680
|
+
# 非必需产物缺失:**不扣分**。
|
|
681
|
+
#
|
|
682
|
+
# 旧实现 emit WARN 但 reason=None,被 enforce_reasons() 机械改判
|
|
683
|
+
# FAIL(malformed:soft_reason)—— 「非必需缺失」变成了 FAIL,
|
|
684
|
+
# 与声明语义完全相反。这里改为不入项:声明本身就是「可选项」,
|
|
685
|
+
# 缺失就是它的预期状态之一,不该产生噪音。
|
|
686
|
+
continue
|
|
687
|
+
|
|
688
|
+
|
|
689
|
+
def _declared_parent_dir(wf, sid, fallback):
|
|
690
|
+
"""从配置声明的 glob 产物路径里推出「父目录」,用于逐能力核对。
|
|
691
|
+
|
|
692
|
+
A-14 修复的一部分:S8 需要知道「主 spec 放在哪个根目录下」,
|
|
693
|
+
而这个根目录在 `workflow.json` 里已经声明了
|
|
694
|
+
(`openspec/specs/<capability>/spec.md`)。
|
|
695
|
+
旧实现写死 `openspec/specs`,于是改配置不生效。
|
|
696
|
+
|
|
697
|
+
取法:找该阶段第一个 `glob: true` 且文件名是 `spec.md` 的产物,
|
|
698
|
+
取它的倒数第二段(`<capability>` 的父级)。
|
|
699
|
+
找不到就用 fallback —— 不因为配置形状意外而让整个检查崩溃。
|
|
700
|
+
"""
|
|
701
|
+
try:
|
|
702
|
+
stage = _stage(wf, sid)
|
|
703
|
+
except KeyError:
|
|
704
|
+
return os.path.join(os.getcwd(), fallback)
|
|
705
|
+
for art in stage.get("artifacts", []):
|
|
706
|
+
if not art.get("glob"):
|
|
707
|
+
continue
|
|
708
|
+
if os.path.basename(art["path"].rstrip("/")) != "spec.md":
|
|
709
|
+
continue
|
|
710
|
+
parts = [p for p in art["path"].replace("\\", "/").split("/") if p]
|
|
711
|
+
# parts 形如 ["openspec", "specs", "<capability>", "spec.md"]
|
|
712
|
+
# 父目录 = 去掉最后两段
|
|
713
|
+
if len(parts) >= 3:
|
|
714
|
+
return "/".join(parts[:-2])
|
|
715
|
+
return fallback
|
|
716
|
+
|
|
717
|
+
|
|
718
|
+
def _ledger_completed_ids(ledger_text):
|
|
719
|
+
"""账本中标记为完成的任务号集合。
|
|
720
|
+
|
|
721
|
+
三处收紧(缺陷 #6):
|
|
722
|
+
行锚定 `^\\s*` —— 旧实现 `Task\\s+\\d+.*:\\s*complete` 的 `\\s*` 可跨行,
|
|
723
|
+
`Task 1:` ⏎ `complete` 会被算成完成。
|
|
724
|
+
词尾 `\\b` —— `complete_pending` / `complete-x` 不再算完成;
|
|
725
|
+
同时接受 `completed`(`complete(?:d)?`)这一既有合法写法。
|
|
726
|
+
集合去重 —— 同一 Task 的重试追加行不重复计数。
|
|
727
|
+
|
|
728
|
+
同一行可能写多个 complete(`Task 1: complete (a) | Task 2: complete (b)`),
|
|
729
|
+
旧实现的贪婪 `.*` 会把它们合并成 1 条。这里用 `finditer` 而非 `match`,
|
|
730
|
+
逐个提取,同一行多个也能全数计入。
|
|
731
|
+
"""
|
|
732
|
+
ids = set()
|
|
733
|
+
pat = re.compile(
|
|
734
|
+
r"(?:^|\s)(?:[-*+]\s*)?Task\s+(\d+)\b[^\n:|]*:\s*complete(?:d)?\b", re.I)
|
|
735
|
+
for line in (ledger_text or "").splitlines():
|
|
736
|
+
clean = line.replace("**", "").replace("__", "").replace("`", "")
|
|
737
|
+
for m in pat.finditer(clean):
|
|
738
|
+
ids.add(m.group(1))
|
|
739
|
+
return ids
|
|
740
|
+
|
|
741
|
+
|
|
742
|
+
def _tasks_done_ids(tasks_text):
|
|
743
|
+
"""tasks.md 中已勾选叶子所属的一级任务号。
|
|
744
|
+
|
|
745
|
+
返回 (ids, n_done, n_no_id):
|
|
746
|
+
ids —— 从 `- [x] 1.1 a` 的描述里提取的 `1`
|
|
747
|
+
n_done —— 已勾选叶子总数
|
|
748
|
+
n_no_id —— 没有数字编号的已勾选叶子数
|
|
749
|
+
|
|
750
|
+
**`n_no_id` 的用途在 A-5 修复后变了**:它不再决定「是否退化到计数比较」,
|
|
751
|
+
只用来产出「有无编号叶子」的提示。原因:
|
|
752
|
+
|
|
753
|
+
`references/stage-S3-plan.md:46` 明文允许 `1 Task ≥ N 叶子`(covers 语法),
|
|
754
|
+
所以「勾选叶子数」与「账本任务号数」本来就不是同一单位。
|
|
755
|
+
原逻辑只要有**一个**叶子没写编号就切到计数比较,于是
|
|
756
|
+
`- [x] 1.1 a` / `- [x] 1.2 b` / `- [x] 无编号 c` → 3 != 1 → FAIL
|
|
757
|
+
而把第三行改成 `1.3 c` 就 OK。**同一事实,只因一个编号就全红。**
|
|
758
|
+
|
|
759
|
+
退化条件改为「**全部**叶子都无编号」——那种情况下确实没有任务号可比,
|
|
760
|
+
计数比较是唯一可行的判据。混合情况一律走 id-set 比较(更精确),
|
|
761
|
+
无编号叶子另出一条 WARN 提示补编号。
|
|
762
|
+
"""
|
|
763
|
+
ids, n_done, n_no_id = set(), 0, 0
|
|
764
|
+
for is_done, desc in parse_task_lines(tasks_text):
|
|
765
|
+
if not is_done:
|
|
766
|
+
continue
|
|
767
|
+
n_done += 1
|
|
768
|
+
m = re.match(r"\s*([0-9]+)", desc or "")
|
|
769
|
+
if m:
|
|
770
|
+
ids.add(m.group(1))
|
|
771
|
+
else:
|
|
772
|
+
n_no_id += 1
|
|
773
|
+
return ids, n_done, n_no_id
|
|
774
|
+
|
|
775
|
+
|
|
776
|
+
def check_S3(ctx, rep, wf):
|
|
777
|
+
"""计划文档:存在 + 必备段 + 任务标题 + 占位符 + 与 tasks.md 对齐。"""
|
|
778
|
+
label = gate_label(wf, "S3")
|
|
779
|
+
stage = _stage(wf, "S3")
|
|
780
|
+
|
|
781
|
+
text = read(ctx["plan"]) if ctx["plan"] else None
|
|
782
|
+
if not ctx["plan"]:
|
|
783
|
+
rep.add(label, "计划文档", FAIL,
|
|
784
|
+
"[unverifiable:plan_required] 该规模下 S3 不被裁剪,必须提供 --plan",
|
|
785
|
+
id="S3.PLAN", reason="unverifiable:plan_required")
|
|
786
|
+
return
|
|
787
|
+
if text is None:
|
|
788
|
+
rep.add(label, "计划文档存在", FAIL,
|
|
789
|
+
"[malformed:plan_unreadable] 无法读取 %s" % ctx["plan"],
|
|
790
|
+
id="S3.PLAN", reason="malformed:plan_unreadable")
|
|
791
|
+
return
|
|
792
|
+
rep.add(label, "计划文档存在", OK, ctx["plan"], id="S3.PLAN")
|
|
793
|
+
|
|
794
|
+
# 必备段:精确匹配(前缀匹配会让 `## Specification` 冒充 `## Spec`)
|
|
795
|
+
for sec in stage["required_sections"]:
|
|
796
|
+
if not light_wants(ctx, "S3", "sections"):
|
|
797
|
+
continue # 「简」模式不查段名——它只证明有人写了标题,不证明内容
|
|
798
|
+
has = has_section(text, sec)
|
|
799
|
+
if has:
|
|
800
|
+
rep.add(label, "必备段:%s" % sec, OK, "", id="S3.SECTION:%s" % sec)
|
|
801
|
+
else:
|
|
802
|
+
rep.add(label, "必备段:%s" % sec, FAIL,
|
|
803
|
+
"[missing:section] 缺 `## %s` 段(精确段名,`## %sXxx` 不算)"
|
|
804
|
+
% (sec, sec),
|
|
805
|
+
id="S3.SECTION:%s" % sec, reason="missing:section")
|
|
806
|
+
|
|
807
|
+
# 任务标题:无论「必」还是「简」都必须查——task-brief 脚本按它解析
|
|
808
|
+
tasks = re.findall(r"^#+\s+Task\s+(\d+)\s*:", text, re.M)
|
|
809
|
+
if tasks:
|
|
810
|
+
rep.add(label, "任务标题格式 '### Task N:'", OK,
|
|
811
|
+
"找到 %d 个 Task:%s" % (len(tasks), ",".join(tasks[:10])),
|
|
812
|
+
id="S3.TASK_TITLES")
|
|
813
|
+
else:
|
|
814
|
+
rep.add(label, "任务标题格式 '### Task N:'", FAIL,
|
|
815
|
+
"[missing:task_title] 一个都没匹配到——task-brief 脚本按 "
|
|
816
|
+
"`### Task N:` 解析,缺了它无法派发",
|
|
817
|
+
id="S3.TASK_TITLES", reason="missing:task_title")
|
|
818
|
+
|
|
819
|
+
placeholders = re.findall(r"TBD|TODO|适当的错误处理|同 Task [0-9]", text)
|
|
820
|
+
if placeholders:
|
|
821
|
+
rep.add(label, "无占位符", FAIL,
|
|
822
|
+
"[malformed:placeholder] 命中 %d 处:%s"
|
|
823
|
+
% (len(placeholders), sorted(set(placeholders))),
|
|
824
|
+
id="S3.PLACEHOLDERS", reason="malformed:placeholder")
|
|
825
|
+
else:
|
|
826
|
+
rep.add(label, "无占位符", OK, "", id="S3.PLACEHOLDERS")
|
|
827
|
+
|
|
828
|
+
# 双账本对齐:计划 Task 数 ≥ 1 且 tasks.md 有叶子
|
|
829
|
+
if ctx["change_dir"] and os.path.isdir(ctx["change_dir"]):
|
|
830
|
+
ttext = read(os.path.join(ctx["change_dir"], "tasks.md"))
|
|
831
|
+
if ttext is not None:
|
|
832
|
+
leaves = count_checkboxes(ttext)
|
|
833
|
+
total_leaves = leaves["done"] + leaves["todo"] + leaves["other"]
|
|
834
|
+
ok = total_leaves > 0 and len(tasks) >= 1
|
|
835
|
+
rep.add(label, "计划 Task 与 tasks.md 叶子对齐",
|
|
836
|
+
OK if ok else FAIL,
|
|
837
|
+
("tasks.md 叶子 %d 条 / 计划 Task %d 个(1 Task ≥ 1 叶子)"
|
|
838
|
+
% (total_leaves, len(tasks))) if ok else
|
|
839
|
+
"[malformed:leaf_align] tasks.md 叶子 %d 条 / 计划 Task %d 个"
|
|
840
|
+
% (total_leaves, len(tasks)),
|
|
841
|
+
id="S3.ALIGN",
|
|
842
|
+
reason=None if ok else "malformed:leaf_align")
|
|
843
|
+
|
|
844
|
+
|
|
845
|
+
def check_S4(ctx, rep, wf):
|
|
846
|
+
"""基线与账本:防丢的两处重点。"""
|
|
847
|
+
label = gate_label(wf, "S4")
|
|
848
|
+
|
|
849
|
+
text = read(ctx["plan"]) if ctx["plan"] else None
|
|
850
|
+
if not ctx["plan"]:
|
|
851
|
+
rep.add(label, "基线记录", FAIL,
|
|
852
|
+
"[unverifiable:plan_required] 该规模下 S4 不被裁剪,必须提供 --plan",
|
|
853
|
+
id="S4.BASELINE", reason="unverifiable:plan_required")
|
|
854
|
+
return
|
|
855
|
+
if text is None:
|
|
856
|
+
# 提供了但读不出 ≠ 没提供(A-9 同族):前者是 Q2 失败(malformed),
|
|
857
|
+
# 报错该指向文件编码/权限;混同的文案会教用户去补传 --plan。
|
|
858
|
+
rep.add(label, "基线记录", FAIL,
|
|
859
|
+
"[malformed:plan_unreadable] 无法读取 %s" % ctx["plan"],
|
|
860
|
+
id="S4.BASELINE", reason="malformed:plan_unreadable")
|
|
861
|
+
return
|
|
862
|
+
|
|
863
|
+
has_baseline = has_section(text, "Baseline")
|
|
864
|
+
if has_baseline:
|
|
865
|
+
rep.add(label, "基线主副本在计划文档(防 workspace 删除丢失)", OK, "",
|
|
866
|
+
id="S4.BASELINE")
|
|
867
|
+
else:
|
|
868
|
+
rep.add(label, "基线主副本在计划文档(防 workspace 删除丢失)", FAIL,
|
|
869
|
+
"[missing:baseline] 计划文档缺 `## Baseline` 段——"
|
|
870
|
+
"基线证据会在删 workspace 时消失",
|
|
871
|
+
id="S4.BASELINE", reason="missing:baseline")
|
|
872
|
+
|
|
873
|
+
ledger = ctx["ledger"]
|
|
874
|
+
if not ledger:
|
|
875
|
+
# 账本缺失的三态分流(A-4 修复)。
|
|
876
|
+
#
|
|
877
|
+
# 原实现一律判 `missing:ledger` FAIL —— 但「交付完成 + workspace 已按
|
|
878
|
+
# 铁律 11 清理」是**正常终态**,按规范做完交付的项目回查门禁必然 rc=1。
|
|
879
|
+
# 更糟的是原提示给的出路是「请用 --scale light」——教人用降级绕门禁。
|
|
880
|
+
#
|
|
881
|
+
# 正确做法照 check_S5 已有的范式:按 tasks.md 是否还有未完成项区分。
|
|
882
|
+
# 全部完成 + 无账本 → WARN soft:workspace_cleaned(正常清理)
|
|
883
|
+
# 仍有未完成 / tasks.md 不可读 → FAIL missing:ledger(证据缺失)
|
|
884
|
+
ttext = None
|
|
885
|
+
if ctx["change_dir"] and os.path.isdir(ctx["change_dir"]):
|
|
886
|
+
ttext = read(os.path.join(ctx["change_dir"], "tasks.md"))
|
|
887
|
+
leaves = count_checkboxes(ttext) if ttext is not None else None
|
|
888
|
+
unfinished = (leaves["todo"] + leaves["other"]) if leaves else 0
|
|
889
|
+
if leaves is not None and unfinished == 0:
|
|
890
|
+
rep.add(label, "账本存在", WARN,
|
|
891
|
+
"[soft:workspace_cleaned] 无账本,但 tasks.md 已全部完成——"
|
|
892
|
+
"疑似交付后按铁律 11 清理(正常终态);若为交付前核对请补 --plan",
|
|
893
|
+
id="S4.LEDGER", reason="soft:workspace_cleaned")
|
|
894
|
+
else:
|
|
895
|
+
why = ("tasks.md 不可读,无法判断是否已完成"
|
|
896
|
+
if leaves is None
|
|
897
|
+
else "tasks.md 仍有 %d 项未完成" % unfinished)
|
|
898
|
+
rep.add(label, "账本存在", FAIL,
|
|
899
|
+
"[missing:ledger] 找不到 .superpowers/sdd/<plan>/progress.md,"
|
|
900
|
+
"且 %s——实施证据缺失" % why,
|
|
901
|
+
id="S4.LEDGER", reason="missing:ledger")
|
|
902
|
+
return
|
|
903
|
+
ltext = read(ledger)
|
|
904
|
+
if ltext is None:
|
|
905
|
+
# 账本存在但读不出 ≠ 空账本(A-9):前者是 Q2 失败(malformed),
|
|
906
|
+
# 后者才是格式问题。混同会把「读不出」印成「空账本」误导排查方向。
|
|
907
|
+
rep.add(label, "账本首行为身份行(INV4)", FAIL,
|
|
908
|
+
"[malformed:ledger_unreadable] 账本存在但读不出(无效 UTF-8 / 权限),"
|
|
909
|
+
"身份行无从核验",
|
|
910
|
+
id="S4.LEDGER_ID", reason="malformed:ledger_unreadable")
|
|
911
|
+
return
|
|
912
|
+
first = ltext.splitlines()[0] if ltext else ""
|
|
913
|
+
if first.startswith("# SDD ledger — plan:"):
|
|
914
|
+
rep.add(label, "账本首行为身份行(INV4)", OK, first[:80], id="S4.LEDGER_ID")
|
|
915
|
+
else:
|
|
916
|
+
rep.add(label, "账本首行为身份行(INV4)", FAIL,
|
|
917
|
+
"[malformed:ledger_identity] 首行必须是 `# SDD ledger — plan: <计划路径>`;"
|
|
918
|
+
"实际:%s" % (first[:80] or "空账本"),
|
|
919
|
+
id="S4.LEDGER_ID", reason="malformed:ledger_identity")
|
|
920
|
+
|
|
921
|
+
|
|
922
|
+
def check_S5(ctx, rep, wf):
|
|
923
|
+
"""每任务产物 + 三元对齐。
|
|
924
|
+
|
|
925
|
+
三元对齐的判据从「计数相等」改为「任务号集合相等」(缺陷 #6 的语义层):
|
|
926
|
+
`references/stage-S3-plan.md:46` 明文允许一个 Task 覆盖多个叶子
|
|
927
|
+
(`1 Task ≥ 1 叶子`),计数相等在这个合法形态下必然假红;
|
|
928
|
+
反过来说,计数相等也证明不了「是同一批任务」。
|
|
929
|
+
只有叶子无数字编号时才退化回计数比较。
|
|
930
|
+
"""
|
|
931
|
+
label = gate_label(wf, "S5")
|
|
932
|
+
|
|
933
|
+
if not ctx["workspace"]:
|
|
934
|
+
# 交付后 workspace 已按铁律 11 清理属正常态;但「变更未完成 + 无 workspace」
|
|
935
|
+
# 是证据缺失,不能静默。
|
|
936
|
+
ttext = (read(os.path.join(ctx["change_dir"], "tasks.md"))
|
|
937
|
+
if ctx["change_dir"] and os.path.isdir(ctx["change_dir"]) else None)
|
|
938
|
+
leaves = count_checkboxes(ttext) if ttext is not None else None
|
|
939
|
+
unfinished = leaves and (leaves["todo"] + leaves["other"]) > 0
|
|
940
|
+
if unfinished:
|
|
941
|
+
rep.add(label, "任务产物", FAIL,
|
|
942
|
+
"[missing:workspace] tasks.md 仍有 %d 项未完成,"
|
|
943
|
+
"但找不到 .superpowers/sdd/<plan>/;实施证据缺失"
|
|
944
|
+
% (leaves["todo"] + leaves["other"]),
|
|
945
|
+
id="S5.WORKSPACE", reason="missing:workspace")
|
|
946
|
+
else:
|
|
947
|
+
rep.add(label, "任务产物", SKIP,
|
|
948
|
+
"[inapplicable:no_workspace] 无 SDD workspace(可能已按铁律 11 清理)",
|
|
949
|
+
id="S5.WORKSPACE", reason="inapplicable:no_workspace")
|
|
950
|
+
return
|
|
951
|
+
|
|
952
|
+
files = os.listdir(ctx["workspace"]) if os.path.isdir(ctx["workspace"]) else []
|
|
953
|
+
briefs = [f for f in files if re.match(r"task-\d+-brief\.md$", f)]
|
|
954
|
+
reports = [f for f in files if re.match(r"task-\d+-report\.md$", f)]
|
|
955
|
+
if briefs:
|
|
956
|
+
rep.add(label, "任务 brief 已生成", OK, "%d 份" % len(briefs), id="S5.BRIEF")
|
|
957
|
+
else:
|
|
958
|
+
rep.add(label, "任务 brief 已生成", FAIL,
|
|
959
|
+
"[missing:brief] workspace 存在但一份 task-N-brief.md 都没有",
|
|
960
|
+
id="S5.BRIEF", reason="missing:brief")
|
|
961
|
+
if reports:
|
|
962
|
+
rep.add(label, "实施报告已生成", OK, "%d 份" % len(reports), id="S5.REPORT")
|
|
963
|
+
else:
|
|
964
|
+
rep.add(label, "实施报告已生成", FAIL,
|
|
965
|
+
"[missing:report] workspace 存在但一份 task-N-report.md 都没有",
|
|
966
|
+
id="S5.REPORT", reason="missing:report")
|
|
967
|
+
|
|
968
|
+
if ctx["change_dir"] and os.path.isdir(ctx["change_dir"]):
|
|
969
|
+
ttext = read(os.path.join(ctx["change_dir"], "tasks.md"))
|
|
970
|
+
ltext = read(ctx["ledger"]) if ctx["ledger"] else None
|
|
971
|
+
# 证据面显式化(A-9 同族):tasks.md/账本「存在但读不出」不得静默蒸发——
|
|
972
|
+
# 三元对齐是 S5 的机器承重项,读不出=查不了=FAIL(malformed:*)。
|
|
973
|
+
# ctx["ledger"] 非空已由 run() 用 os.path.exists 保证文件存在,
|
|
974
|
+
# 故 ltext None 即「读不出」;tasks.md 需 os.path.isfile 区分「缺失」与「读不出」。
|
|
975
|
+
if ttext is None and os.path.isfile(os.path.join(ctx["change_dir"], "tasks.md")):
|
|
976
|
+
rep.add(label, "三元对齐:tasks.md 勾选 == ledger complete(INV2/INV6)",
|
|
977
|
+
FAIL, "[malformed:tasks_unreadable] tasks.md 存在但读不出,"
|
|
978
|
+
"三元对齐无从核对",
|
|
979
|
+
id="S5.TRIAD", reason="malformed:tasks_unreadable")
|
|
980
|
+
elif ltext is None and ctx["ledger"]:
|
|
981
|
+
rep.add(label, "三元对齐:tasks.md 勾选 == ledger complete(INV2/INV6)",
|
|
982
|
+
FAIL, "[malformed:ledger_unreadable] 账本存在但读不出,"
|
|
983
|
+
"三元对齐无从核对",
|
|
984
|
+
id="S5.TRIAD", reason="malformed:ledger_unreadable")
|
|
985
|
+
elif ttext is not None and ltext is not None:
|
|
986
|
+
done_ids, n_done, n_no_id = _tasks_done_ids(ttext)
|
|
987
|
+
ledger_ids = _ledger_completed_ids(ltext)
|
|
988
|
+
|
|
989
|
+
# 退化条件:**全部**叶子都无编号(A-5 修复)。
|
|
990
|
+
# 原条件是「有一个就退化」,导致文档允许的 `1 Task ≥ N 叶子`
|
|
991
|
+
# 在混入任一无编号叶子时必然假红。
|
|
992
|
+
all_unnumbered = n_done > 0 and n_no_id == n_done
|
|
993
|
+
if all_unnumbered:
|
|
994
|
+
ok = n_done == len(ledger_ids)
|
|
995
|
+
basis = "count"
|
|
996
|
+
detail = "勾选 %d / ledger complete %d(全部叶子无编号,按计数比较)" % (
|
|
997
|
+
n_done, len(ledger_ids))
|
|
998
|
+
else:
|
|
999
|
+
ok = done_ids == ledger_ids
|
|
1000
|
+
basis = "id-set"
|
|
1001
|
+
detail = "已完成任务号 %s / ledger complete %s" % (
|
|
1002
|
+
sorted(done_ids), sorted(ledger_ids))
|
|
1003
|
+
if n_no_id:
|
|
1004
|
+
detail += ";另有 %d 个无编号叶子未参与比较" % n_no_id
|
|
1005
|
+
|
|
1006
|
+
# 无编号叶子单独出提示:不影响主判据,但留下可操作信息。
|
|
1007
|
+
# 这是「把不可判定项显式化」——不改判据,只提示补编号。
|
|
1008
|
+
if n_no_id and not all_unnumbered:
|
|
1009
|
+
rep.add(label, "叶子编号完整性", WARN,
|
|
1010
|
+
"[soft:unnumbered_leaf] 有 %d 个已勾选叶子没写数字编号,"
|
|
1011
|
+
"未参与任务号比较;建议补成 `- [x] N.M 描述` 以便精确核对"
|
|
1012
|
+
% n_no_id,
|
|
1013
|
+
id="S5.LEAF_NUMBERING", reason="soft:unnumbered_leaf")
|
|
1014
|
+
|
|
1015
|
+
if ok:
|
|
1016
|
+
rep.add(label, "三元对齐:tasks.md 勾选 == ledger complete(INV2/INV6)",
|
|
1017
|
+
OK, "%s(basis=%s)" % (detail, basis), id="S5.TRIAD")
|
|
1018
|
+
else:
|
|
1019
|
+
rep.add(label, "三元对齐:tasks.md 勾选 == ledger complete(INV2/INV6)",
|
|
1020
|
+
FAIL, "[malformed:triad] %s(basis=%s)" % (detail, basis),
|
|
1021
|
+
id="S5.TRIAD", reason="malformed:triad")
|
|
1022
|
+
|
|
1023
|
+
|
|
1024
|
+
def check_S6(ctx, rep, wf):
|
|
1025
|
+
"""审查独立性标记 + Rulings / Review 段。
|
|
1026
|
+
|
|
1027
|
+
independence 是**全流程唯一硬性交付禁止项**(L2 = 禁止交付),
|
|
1028
|
+
所以取值策略必须偏保守:文本顺序不是契约,账本是「裁决 + 讨论 + 历史」
|
|
1029
|
+
混写的自由文本,无法机械判定哪句是最终结论。取**最坏值**——
|
|
1030
|
+
它单调且有界,只能造成假红(清掉一行即可),不可能造成假绿(禁止交付项失效)。
|
|
1031
|
+
|
|
1032
|
+
旧实现用 `re.search` 取**首个**匹配,于是「independence: L0 设想」这几个字
|
|
1033
|
+
就能把末位的 L2 洗白——实测判 `[ OK ] 级别 L0`。
|
|
1034
|
+
"""
|
|
1035
|
+
label = gate_label(wf, "S6")
|
|
1036
|
+
|
|
1037
|
+
# review-<N>.md 的存在性(P9 复审收口:本项前置——后面的 INDEPENDENCE
|
|
1038
|
+
# FAIL/SKIP 早退路径不得吞掉它,报告完整性):config/workflow.json S6
|
|
1039
|
+
# artifacts 声明 required:true,旧实现从不列 workspace 目录 → 声明无人
|
|
1040
|
+
# 消费(实测满绿假绿)。硬约束(A-14 裁决):workspace 已删必须
|
|
1041
|
+
# inapplicable——交付后跨阶段核对不能因 workspace 清理而假红。
|
|
1042
|
+
workspace = ctx.get("workspace") or ""
|
|
1043
|
+
if not workspace or not os.path.isdir(workspace):
|
|
1044
|
+
rep.add(label, "审查报告 review-<N>.md", SKIP,
|
|
1045
|
+
"[inapplicable:no_workspace] workspace 不存在或已删,审查报告无从核对",
|
|
1046
|
+
id="S6.REVIEW_REPORT", reason="inapplicable:no_workspace")
|
|
1047
|
+
else:
|
|
1048
|
+
reviews = sorted(f for f in os.listdir(workspace)
|
|
1049
|
+
if re.match(r"^review-[0-9]+\.md$", f))
|
|
1050
|
+
if reviews:
|
|
1051
|
+
rep.add(label, "审查报告 review-<N>.md", OK, ", ".join(reviews[:3]),
|
|
1052
|
+
id="S6.REVIEW_REPORT")
|
|
1053
|
+
else:
|
|
1054
|
+
rep.add(label, "审查报告 review-<N>.md", FAIL,
|
|
1055
|
+
"[missing:review_report] workspace 存在但零个 review-<N>.md"
|
|
1056
|
+
"(config/workflow.json S6 声明 required:true)",
|
|
1057
|
+
id="S6.REVIEW_REPORT", reason="missing:review_report")
|
|
1058
|
+
|
|
1059
|
+
ltext = read(ctx["ledger"]) if ctx["ledger"] else None
|
|
1060
|
+
ptext = read(ctx["plan"]) if ctx["plan"] else None
|
|
1061
|
+
|
|
1062
|
+
# 证据三态(A-9 同族):「没有证据」才能 SKIP;「有证据但读不出」是
|
|
1063
|
+
# Q2 失败 → FAIL。混同会让独立性核验(L2 = 禁止交付的唯一硬项)
|
|
1064
|
+
# 被静默归为「不该查」。
|
|
1065
|
+
if ctx["ledger"] and ltext is None:
|
|
1066
|
+
rep.add(label, "审查独立性标记 L0/L1/L2", FAIL,
|
|
1067
|
+
"[malformed:ledger_unreadable] 账本存在但读不出,独立性标记无从核验",
|
|
1068
|
+
id="S6.INDEPENDENCE", reason="malformed:ledger_unreadable")
|
|
1069
|
+
return
|
|
1070
|
+
# SKIP 仅限「证据确实不存在」(计划 Task 6 第 3 条,P9 复审 🟡 收口):
|
|
1071
|
+
# ctx 里声明了 plan 但读不出 ≠ 没有证据——「声明了却查不出」按
|
|
1072
|
+
# missing:independence 落 FAIL(fail-closed),不把「查不了」印成「不该查」。
|
|
1073
|
+
if not ctx["ledger"] and not ctx["plan"]:
|
|
1074
|
+
rep.add(label, "审查独立性标记 L0/L1/L2", SKIP,
|
|
1075
|
+
"[inapplicable:no_evidence] 无账本与计划,无从核验独立性",
|
|
1076
|
+
id="S6.INDEPENDENCE", reason="inapplicable:no_evidence")
|
|
1077
|
+
return
|
|
1078
|
+
|
|
1079
|
+
order = {"L0": 0, "L1": 1, "L2": 2}
|
|
1080
|
+
marker = re.compile(r"independence\s*[::]\s*(L[012])\b", re.I)
|
|
1081
|
+
|
|
1082
|
+
hits = [] # [(来源, 级别)]
|
|
1083
|
+
for src, txt in (("ledger", ltext), ("plan", ptext)):
|
|
1084
|
+
if txt is None:
|
|
1085
|
+
continue
|
|
1086
|
+
# 标记取值:剥引用(行内代码 / 表格行),但**保留围栏内容**——
|
|
1087
|
+
# templates/plan-sections.md 规定 ## Review 的内容就写在 ```markdown 里。
|
|
1088
|
+
whole = marker.findall(strip_quoted_markers(txt))
|
|
1089
|
+
# 优先只认 ## Review 段内的标记;段内没有才回退到全文(遗留写法)
|
|
1090
|
+
body = section_body(txt, "Review", keep_fences=True)
|
|
1091
|
+
in_section = marker.findall(strip_quoted_markers(body)) if body is not None else []
|
|
1092
|
+
for lvl in (in_section or whole):
|
|
1093
|
+
hits.append((src, lvl.upper()))
|
|
1094
|
+
|
|
1095
|
+
if not hits:
|
|
1096
|
+
rep.add(label, "审查独立性标记 L0/L1/L2", FAIL,
|
|
1097
|
+
"[missing:independence] 未找到 independence 标记——"
|
|
1098
|
+
"L2(无审查)禁止交付,缺标记等同未审查",
|
|
1099
|
+
id="S6.INDEPENDENCE", reason="missing:independence")
|
|
1100
|
+
else:
|
|
1101
|
+
worst_src, worst = max(hits, key=lambda h: order[h[1]])
|
|
1102
|
+
all_hits = ",".join("%s:%s" % (s, l) for s, l in hits)
|
|
1103
|
+
if worst == "L2":
|
|
1104
|
+
rep.add(label, "审查独立性标记 L0/L1/L2", FAIL,
|
|
1105
|
+
"[forbidden:independence_l2] 级别 L2(无审查,禁止交付);"
|
|
1106
|
+
"全部标记:%s(取最坏值)" % all_hits,
|
|
1107
|
+
id="S6.INDEPENDENCE", reason="forbidden:independence_l2")
|
|
1108
|
+
else:
|
|
1109
|
+
rep.add(label, "审查独立性标记 L0/L1/L2", OK,
|
|
1110
|
+
"级别 %s(来源 %s;全部标记:%s)" % (worst, worst_src, all_hits),
|
|
1111
|
+
id="S6.INDEPENDENCE")
|
|
1112
|
+
|
|
1113
|
+
if ptext is not None:
|
|
1114
|
+
if light_wants(ctx, "S6", "rulings"):
|
|
1115
|
+
if has_section(ptext, "Rulings"):
|
|
1116
|
+
rep.add(label, "Rulings 已持久化到计划文档", OK, "", id="S6.RULINGS")
|
|
1117
|
+
else:
|
|
1118
|
+
rep.add(label, "Rulings 已持久化到计划文档", WARN,
|
|
1119
|
+
"[soft:missing_rulings] 计划文档缺 `## Rulings` 段——"
|
|
1120
|
+
"删 workspace 后决策永久丢失",
|
|
1121
|
+
id="S6.RULINGS", reason="soft:missing_rulings")
|
|
1122
|
+
|
|
1123
|
+
# 段存在 ≠ 结论已写:必须看到结论载体(spec/quality/三态/independence)
|
|
1124
|
+
#
|
|
1125
|
+
# 注意 section_body 只取「## Review」到下一个同级标题之间的正文。
|
|
1126
|
+
# 若结论写在 `## Review` 下的子标题(`### 批次 P0 审查结论`)里,
|
|
1127
|
+
# 那仍在同一段内,会被正常读取;但如果文档把结论写在别的二级段
|
|
1128
|
+
# (例如 `## Integration Verification`)里,就不该算「Review 段有结论」。
|
|
1129
|
+
body = section_body(ptext, "Review", keep_fences=True)
|
|
1130
|
+
if body is None:
|
|
1131
|
+
# 退一步:全文里是否有 Review 类承载段(`## Review(…)` 已被
|
|
1132
|
+
# _section_re 覆盖,这里只处理「结论段换了标题」的宽松情形)
|
|
1133
|
+
rep.add(label, "审查结论已持久化", WARN,
|
|
1134
|
+
"[soft:missing_review_section] 计划文档缺 `## Review` 段"
|
|
1135
|
+
"(注意 `## Review Focus` 不算)",
|
|
1136
|
+
id="S6.REVIEW", reason="soft:missing_review_section")
|
|
1137
|
+
else:
|
|
1138
|
+
carriers = re.findall(
|
|
1139
|
+
r"spec\s*[::]\s*(?:✅|❌)|quality\s*[::]"
|
|
1140
|
+
r"|APPROVED|NEEDS_FIX|BLOCKED"
|
|
1141
|
+
r"|independence\s*[::]\s*L[012]", body, re.I)
|
|
1142
|
+
if carriers:
|
|
1143
|
+
rep.add(label, "审查结论已持久化", OK,
|
|
1144
|
+
"%d 处结论载体" % len(carriers), id="S6.REVIEW")
|
|
1145
|
+
else:
|
|
1146
|
+
rep.add(label, "审查结论已持久化", WARN,
|
|
1147
|
+
"[soft:review_section_empty] `## Review` 段存在但无结论载体"
|
|
1148
|
+
"(需 spec ✅/❌、quality、三态或 independence)",
|
|
1149
|
+
id="S6.REVIEW", reason="soft:review_section_empty")
|
|
1150
|
+
|
|
1151
|
+
|
|
1152
|
+
def check_S7(ctx, rep, wf):
|
|
1153
|
+
label = gate_label(wf, "S7")
|
|
1154
|
+
text = read(ctx["plan"]) if ctx["plan"] else None
|
|
1155
|
+
if not ctx["plan"]:
|
|
1156
|
+
rep.add(label, "集成后重测记录", FAIL,
|
|
1157
|
+
"[unverifiable:plan_required] 该规模下 S7 不被裁剪,必须提供 --plan",
|
|
1158
|
+
id="S7.INTEGRATION", reason="unverifiable:plan_required")
|
|
1159
|
+
return
|
|
1160
|
+
if text is None:
|
|
1161
|
+
# 提供了但读不出 ≠ 没提供(A-9 同族,对齐 check_S3 先例)。
|
|
1162
|
+
rep.add(label, "集成后重测记录", FAIL,
|
|
1163
|
+
"[malformed:plan_unreadable] 无法读取 %s" % ctx["plan"],
|
|
1164
|
+
id="S7.INTEGRATION", reason="malformed:plan_unreadable")
|
|
1165
|
+
return
|
|
1166
|
+
if has_section(text, "Integration Verification"):
|
|
1167
|
+
rep.add(label, "集成后重测已记录", OK, "", id="S7.INTEGRATION")
|
|
1168
|
+
else:
|
|
1169
|
+
rep.add(label, "集成后重测已记录", FAIL,
|
|
1170
|
+
"[missing:integration_verification] 计划文档缺 "
|
|
1171
|
+
"`## Integration Verification`——不得沿用集成前结果",
|
|
1172
|
+
id="S7.INTEGRATION", reason="missing:integration_verification")
|
|
1173
|
+
|
|
1174
|
+
|
|
1175
|
+
def check_S8(ctx, rep, wf):
|
|
1176
|
+
"""归档条件:只认 x/X,且不能有 PARKED 残留。
|
|
1177
|
+
|
|
1178
|
+
这里的核心修复是**不再提前 `return`**:tasks.md 解析不出勾选框
|
|
1179
|
+
不等于「本阶段不适用」,而是格式非法——必须 FAIL,且
|
|
1180
|
+
PARKED / 主 spec / 归档目录三项检查仍要照常执行。
|
|
1181
|
+
旧实现在 total==0 时 `return`,一次格式问题就能让归档门禁整段消失。
|
|
1182
|
+
"""
|
|
1183
|
+
label = gate_label(wf, "S8")
|
|
1184
|
+
if not ctx["change_dir"] or not os.path.isdir(ctx["change_dir"]):
|
|
1185
|
+
rep.add(label, "归档条件", SKIP,
|
|
1186
|
+
"[inapplicable:no_change] 无变更目录,归档条件无从核对",
|
|
1187
|
+
id="S8.ARCHIVE_GATE", reason="inapplicable:no_change")
|
|
1188
|
+
return
|
|
1189
|
+
|
|
1190
|
+
tpath = os.path.join(ctx["change_dir"], "tasks.md")
|
|
1191
|
+
ttext = read(tpath)
|
|
1192
|
+
if ttext is None:
|
|
1193
|
+
rep.add(label, "completedTasks == totalTasks(只认 x/X)", FAIL,
|
|
1194
|
+
"[missing:tasks_md] 变更目录存在但读不到 tasks.md",
|
|
1195
|
+
id="S8.COUNT", reason="missing:tasks_md")
|
|
1196
|
+
else:
|
|
1197
|
+
c = count_checkboxes(ttext)
|
|
1198
|
+
total = c["done"] + c["todo"] + c["other"]
|
|
1199
|
+
if total == 0:
|
|
1200
|
+
styles = detect_bullet_styles(ttext)
|
|
1201
|
+
rep.add(label, "completedTasks == totalTasks(只认 x/X)", FAIL,
|
|
1202
|
+
"[malformed:tasks_md] tasks.md 存在但解析不到任何勾选框;"
|
|
1203
|
+
"识别到的列表符:%s(支持 -, *, +, 1./1))"
|
|
1204
|
+
% (",".join(styles) if styles else "无"),
|
|
1205
|
+
id="S8.COUNT", reason="malformed:tasks_md")
|
|
1206
|
+
else:
|
|
1207
|
+
all_done = c["todo"] == 0 and c["other"] == 0
|
|
1208
|
+
detail = "%d/%d 完成;未完成 %d;异形标记 %d" % (
|
|
1209
|
+
c["done"], total, c["todo"], c["other"])
|
|
1210
|
+
if all_done:
|
|
1211
|
+
rep.add(label, "completedTasks == totalTasks(只认 x/X)", OK,
|
|
1212
|
+
detail, id="S8.COUNT")
|
|
1213
|
+
else:
|
|
1214
|
+
rep.add(label, "completedTasks == totalTasks(只认 x/X)", FAIL,
|
|
1215
|
+
"[malformed:incomplete] " + detail, id="S8.COUNT",
|
|
1216
|
+
reason="malformed:incomplete")
|
|
1217
|
+
|
|
1218
|
+
# PARKED:优先读 .status.json(与 openspec_engine.py archive-change 一致),
|
|
1219
|
+
# 退化到账本正则检查(保留对旧项目的兼容)。
|
|
1220
|
+
#
|
|
1221
|
+
# P1-4:两处口径统一——**任一**出现 PARKED 即判 FAIL。旧实现在
|
|
1222
|
+
# .status.json 存在且 parked=false 时直接 OK,不查账本,账本中真实
|
|
1223
|
+
# 存在的 PARKED 任务被漏判,违反 W8「PARKED 默认禁归档」。
|
|
1224
|
+
# openspec_engine.py archive-change 只读 .status.json(无账本上下文),
|
|
1225
|
+
# 本检查器有账本,故在 .status.json 未标记时仍以账本兜底,两工具
|
|
1226
|
+
# 对「已标记」的判定一致,对「账本残留」由本检查器补位。
|
|
1227
|
+
status_path = os.path.join(ctx["change_dir"], ".status.json")
|
|
1228
|
+
status_text = read(status_path)
|
|
1229
|
+
parked_from_status = False
|
|
1230
|
+
if status_text is not None:
|
|
1231
|
+
try:
|
|
1232
|
+
status = json.loads(status_text)
|
|
1233
|
+
except (json.JSONDecodeError, ValueError):
|
|
1234
|
+
status = {}
|
|
1235
|
+
parked_from_status = _status_flag(status, "parked", "PARKED")
|
|
1236
|
+
if parked_from_status:
|
|
1237
|
+
rep.add(label, "无 PARKED 残留(W8)", FAIL,
|
|
1238
|
+
"[forbidden:parked] .status.json 中 parked=true——默认禁归档,须迁出到新 change",
|
|
1239
|
+
id="S8.PARKED", reason="forbidden:parked")
|
|
1240
|
+
elif ctx["ledger"] is None:
|
|
1241
|
+
# .status.json 未标记 parked 且无账本:以 .status.json 为准(若无则
|
|
1242
|
+
# 无法确认,显式 WARN 而非静默 OK)
|
|
1243
|
+
if status_text is None:
|
|
1244
|
+
rep.add(label, "无 PARKED 残留(W8)", WARN,
|
|
1245
|
+
"[soft:no_ledger] 无账本且无 .status.json,无法确认是否有 PARKED 残留",
|
|
1246
|
+
id="S8.PARKED", reason="soft:no_ledger")
|
|
1247
|
+
else:
|
|
1248
|
+
rep.add(label, "无 PARKED 残留(W8)", OK, "", id="S8.PARKED")
|
|
1249
|
+
else:
|
|
1250
|
+
# .status.json 未标记 parked:查账本兜底
|
|
1251
|
+
ltext = read(ctx["ledger"])
|
|
1252
|
+
if ltext is None:
|
|
1253
|
+
rep.add(label, "无 PARKED 残留(W8)", FAIL,
|
|
1254
|
+
"[malformed:ledger_unreadable] 账本存在但读不出,「无残留」无法证明",
|
|
1255
|
+
id="S8.PARKED", reason="malformed:ledger_unreadable")
|
|
1256
|
+
elif ltext == "":
|
|
1257
|
+
rep.add(label, "无 PARKED 残留(W8)", WARN,
|
|
1258
|
+
"[soft:ledger_empty] 账本存在但为空(无身份行),证明力不完整",
|
|
1259
|
+
id="S8.PARKED", reason="soft:ledger_empty")
|
|
1260
|
+
else:
|
|
1261
|
+
parked = len(re.findall(r"\bPARKED\b|:\s*parked", ltext, re.I))
|
|
1262
|
+
if parked == 0:
|
|
1263
|
+
rep.add(label, "无 PARKED 残留(W8)", OK, "", id="S8.PARKED")
|
|
1264
|
+
else:
|
|
1265
|
+
rep.add(label, "无 PARKED 残留(W8)", FAIL,
|
|
1266
|
+
"[forbidden:parked] %d 处 parked——默认禁归档,须迁出到新 change"
|
|
1267
|
+
% parked, id="S8.PARKED", reason="forbidden:parked")
|
|
1268
|
+
|
|
1269
|
+
# 主 spec:优先逐个能力核对,退化到目录存在性
|
|
1270
|
+
#
|
|
1271
|
+
# **路径从配置派生,不硬编码**(A-14 修复):旧实现写死 `openspec/specs`,
|
|
1272
|
+
# 实测把声明改成 `specs2/<capability>/spec.md` 并把证据搬过去后,
|
|
1273
|
+
# S8 仍报 `openspec/specs` 缺失 —— 「读了文件但不按配置读」。
|
|
1274
|
+
# 这是任何字面量扫描都抓不到的形态,只能靠行为测试盯住。
|
|
1275
|
+
specs_dir = os.path.join(ctx["root"],
|
|
1276
|
+
_declared_parent_dir(wf, "S8", fallback="openspec/specs"))
|
|
1277
|
+
caps = sorted({p.name for p in Path(ctx["change_dir"], "specs").glob("*")
|
|
1278
|
+
if p.is_dir()}) if os.path.isdir(
|
|
1279
|
+
os.path.join(ctx["change_dir"], "specs")) else []
|
|
1280
|
+
if caps:
|
|
1281
|
+
missing = [c for c in caps
|
|
1282
|
+
if not os.path.isfile(os.path.join(specs_dir, c, "spec.md"))]
|
|
1283
|
+
if not missing:
|
|
1284
|
+
# P0-1:文件存在 ≠ 内容合法。与 openspec_engine.validate-specs 同口径
|
|
1285
|
+
# 做真实内容校验(## Purpose 非空),缺 Purpose 的主 spec 判 FAIL,
|
|
1286
|
+
# 否则「文件存在就 OK」的假绿会让污染的 spec 被归档。
|
|
1287
|
+
#
|
|
1288
|
+
# 复用 openspec_engine 的切分/校验逻辑,保持两工具口径一致,
|
|
1289
|
+
# 避免在检查器里重新手写一份规则导致再次漂移。
|
|
1290
|
+
purpose_bad = []
|
|
1291
|
+
try:
|
|
1292
|
+
from openspec_engine import _split_sections, _has_purpose
|
|
1293
|
+
except Exception:
|
|
1294
|
+
_split_sections = None
|
|
1295
|
+
_has_purpose = None
|
|
1296
|
+
if _split_sections is not None:
|
|
1297
|
+
for c in caps:
|
|
1298
|
+
main_spec = os.path.join(specs_dir, c, "spec.md")
|
|
1299
|
+
try:
|
|
1300
|
+
text = read(main_spec)
|
|
1301
|
+
except OSError:
|
|
1302
|
+
text = None
|
|
1303
|
+
if text is None:
|
|
1304
|
+
continue
|
|
1305
|
+
if not _has_purpose(_split_sections(text)):
|
|
1306
|
+
purpose_bad.append(c)
|
|
1307
|
+
if purpose_bad:
|
|
1308
|
+
rep.add(label, "主 spec 已同步(逐能力)", FAIL,
|
|
1309
|
+
"[missing:spec_sync] %d 个主 spec 缺非空 ## Purpose:%s(%s/<cap>/spec.md)"
|
|
1310
|
+
% (len(purpose_bad), "、".join(purpose_bad), specs_dir),
|
|
1311
|
+
id="S8.SPEC_SYNC", reason="missing:spec_sync")
|
|
1312
|
+
else:
|
|
1313
|
+
rep.add(label, "主 spec 已同步(逐能力)", OK,
|
|
1314
|
+
"%d 个能力均已同步且含非空 ## Purpose" % len(caps), id="S8.SPEC_SYNC")
|
|
1315
|
+
else:
|
|
1316
|
+
rep.add(label, "主 spec 已同步(逐能力)", FAIL,
|
|
1317
|
+
"[missing:spec_sync] 未同步的能力:%s(应在 %s/<cap>/spec.md)"
|
|
1318
|
+
% (", ".join(missing), specs_dir), id="S8.SPEC_SYNC",
|
|
1319
|
+
reason="missing:spec_sync")
|
|
1320
|
+
elif os.path.isdir(specs_dir):
|
|
1321
|
+
rep.add(label, "主 spec 目录存在(sync 后)", OK, specs_dir, id="S8.SPEC_SYNC")
|
|
1322
|
+
else:
|
|
1323
|
+
rep.add(label, "主 spec 目录存在(sync 后)", WARN,
|
|
1324
|
+
"[soft:no_specs_dir] %s 不存在,可能未 sync" % specs_dir,
|
|
1325
|
+
id="S8.SPEC_SYNC", reason="soft:no_specs_dir")
|
|
1326
|
+
|
|
1327
|
+
# 归档目录:精确匹配 + 缺失也要产出检查项(旧实现整块消失)
|
|
1328
|
+
archived = _archived_entry(ctx)
|
|
1329
|
+
arch = os.path.join(ctx["root"], "openspec", "changes", "archive")
|
|
1330
|
+
if archived:
|
|
1331
|
+
rep.add(label, "归档目录已生成", OK, archived, id="S8.ARCHIVE")
|
|
1332
|
+
elif ctx.get("change"):
|
|
1333
|
+
rep.add(label, "归档目录已生成",
|
|
1334
|
+
FAIL if ctx.get("expect_archive") else WARN,
|
|
1335
|
+
("[missing:archive_entry] archive/ 下无 `YYYY-MM-DD-%s` 目录"
|
|
1336
|
+
% ctx["change"]) if ctx.get("expect_archive") else
|
|
1337
|
+
"[soft:future_event:archive] 变更尚未归档(若此刻正在归档,请加 --expect-archive)",
|
|
1338
|
+
id="S8.ARCHIVE",
|
|
1339
|
+
reason="missing:archive_entry" if ctx.get("expect_archive")
|
|
1340
|
+
else "soft:future_event:archive")
|
|
1341
|
+
else:
|
|
1342
|
+
rep.add(label, "归档目录已生成", SKIP,
|
|
1343
|
+
"[inapplicable:no_change] 无变更名,无从核对归档目录",
|
|
1344
|
+
id="S8.ARCHIVE", reason="inapplicable:no_change")
|
|
1345
|
+
|
|
1346
|
+
|
|
1347
|
+
# ---------------------------------------------------------------------------
|
|
1348
|
+
# 辅助
|
|
1349
|
+
# ---------------------------------------------------------------------------
|
|
1350
|
+
|
|
1351
|
+
def _status_flag(status: dict, *keys) -> bool:
|
|
1352
|
+
"""与 openspec_engine.py 的 _status_flag 语义一致:任一键存在且为真即 true。"""
|
|
1353
|
+
for k in keys:
|
|
1354
|
+
if k in status and status[k]:
|
|
1355
|
+
return True
|
|
1356
|
+
return False
|
|
1357
|
+
|
|
1358
|
+
|
|
1359
|
+
def _stage(wf, sid):
|
|
1360
|
+
for s in wf["stages"]:
|
|
1361
|
+
if s["id"] == sid:
|
|
1362
|
+
return s
|
|
1363
|
+
raise KeyError(sid)
|
|
1364
|
+
|
|
1365
|
+
|
|
1366
|
+
def expand_artifact(root, pattern, change):
|
|
1367
|
+
"""按占位符逐层枚举子目录展开 artifact 路径,返回实际存在的路径列表。
|
|
1368
|
+
|
|
1369
|
+
相比旧的 `while "<" in seg: seg = dirname(seg)` + 全树 `os.walk`:
|
|
1370
|
+
旧实现在 `<capability>/spec.md` 这类形态下会把 seg 退化成空串,
|
|
1371
|
+
等于 walk 整个仓库根(无界);且依赖「占位符嵌套深度」这个隐式前提。
|
|
1372
|
+
本实现逐层枚举,天然有界,且不会越出 artifact 声明的前缀。
|
|
1373
|
+
|
|
1374
|
+
占位符(含 `<...>`)的段必须在目录位置——它表示「枚举这一层的子目录」。
|
|
1375
|
+
若占位符出现在文件名位置,无法枚举,返回空列表(由调用方报 malformed)。
|
|
1376
|
+
"""
|
|
1377
|
+
rel = (pattern or "").replace("<change>", change or "")
|
|
1378
|
+
parts = [p for p in rel.replace("\\", "/").split("/") if p]
|
|
1379
|
+
if not parts:
|
|
1380
|
+
return []
|
|
1381
|
+
if "<" in parts[-1]:
|
|
1382
|
+
return [] # 文件名位占位符 → 无法定位
|
|
1383
|
+
|
|
1384
|
+
cur = [root]
|
|
1385
|
+
for idx, part in enumerate(parts):
|
|
1386
|
+
nxt = []
|
|
1387
|
+
last = (idx == len(parts) - 1)
|
|
1388
|
+
for base in cur:
|
|
1389
|
+
if "<" in part:
|
|
1390
|
+
if not os.path.isdir(base):
|
|
1391
|
+
continue
|
|
1392
|
+
for name in sorted(os.listdir(base)):
|
|
1393
|
+
sub = os.path.join(base, name)
|
|
1394
|
+
if os.path.isdir(sub):
|
|
1395
|
+
nxt.append(sub)
|
|
1396
|
+
else:
|
|
1397
|
+
p = os.path.join(base, part)
|
|
1398
|
+
if os.path.exists(p) or last:
|
|
1399
|
+
nxt.append(p)
|
|
1400
|
+
cur = nxt
|
|
1401
|
+
if not cur:
|
|
1402
|
+
return []
|
|
1403
|
+
return [p for p in cur if os.path.exists(p)]
|
|
1404
|
+
|
|
1405
|
+
|
|
1406
|
+
def _detect_git_repo(start=None):
|
|
1407
|
+
"""判断是否在 git 仓库内(与 zcode_dev_workflow.detect_git 同口径)。
|
|
1408
|
+
|
|
1409
|
+
空 `.git` 目录不算仓库(目录形态须含 HEAD);文件形态须以 `gitdir:` 开头
|
|
1410
|
+
(worktree / submodule)。向上逐级查找,到根才放弃。
|
|
1411
|
+
"""
|
|
1412
|
+
cur = os.path.abspath(start or os.getcwd())
|
|
1413
|
+
while True:
|
|
1414
|
+
candidate = os.path.join(cur, ".git")
|
|
1415
|
+
if os.path.isdir(candidate):
|
|
1416
|
+
if os.path.isfile(os.path.join(candidate, "HEAD")):
|
|
1417
|
+
return True
|
|
1418
|
+
elif os.path.isfile(candidate):
|
|
1419
|
+
try:
|
|
1420
|
+
with open(candidate, "r", encoding="utf-8", errors="replace") as f:
|
|
1421
|
+
head = f.read(64)
|
|
1422
|
+
if head.lstrip().startswith("gitdir:"):
|
|
1423
|
+
return True
|
|
1424
|
+
except OSError:
|
|
1425
|
+
pass
|
|
1426
|
+
parent = os.path.dirname(cur)
|
|
1427
|
+
if parent == cur:
|
|
1428
|
+
return False
|
|
1429
|
+
cur = parent
|
|
1430
|
+
|
|
1431
|
+
|
|
1432
|
+
def detect_env(root):
|
|
1433
|
+
"""探测环境:git / openspec root。只读,不产生任何副作用。
|
|
1434
|
+
|
|
1435
|
+
git 判定与 zcode_dev_workflow.detect_git 同口径(_detect_git_repo),
|
|
1436
|
+
不再用裸 os.path.exists(.git)——空 `.git` 目录会假阳性。
|
|
1437
|
+
"""
|
|
1438
|
+
has_git = _detect_git_repo(root)
|
|
1439
|
+
os_dir = os.path.join(root, "openspec")
|
|
1440
|
+
has_openspec = os.path.isdir(os_dir)
|
|
1441
|
+
parts = []
|
|
1442
|
+
parts.append("git=%s" % ("有" if has_git else "无"))
|
|
1443
|
+
parts.append("openspec=%s" % ("有" if has_openspec else "无"))
|
|
1444
|
+
return {
|
|
1445
|
+
"git": has_git,
|
|
1446
|
+
"openspec": has_openspec,
|
|
1447
|
+
"summary": ", ".join(parts),
|
|
1448
|
+
}
|
|
1449
|
+
|
|
1450
|
+
|
|
1451
|
+
def find_workspace(root, plan_path):
|
|
1452
|
+
"""定位 SDD workspace。优先按计划 basename,找不到再扫亲代目录名。"""
|
|
1453
|
+
base = os.path.join(root, ".superpowers", "sdd")
|
|
1454
|
+
if not os.path.isdir(base):
|
|
1455
|
+
return None
|
|
1456
|
+
slug = os.path.splitext(os.path.basename(plan_path))[0]
|
|
1457
|
+
cand = os.path.join(base, slug)
|
|
1458
|
+
if os.path.isdir(cand):
|
|
1459
|
+
return cand
|
|
1460
|
+
parent = os.path.basename(os.path.dirname(plan_path))
|
|
1461
|
+
for name in (slug, "%s-%s" % (parent, slug)):
|
|
1462
|
+
cand = os.path.join(base, name)
|
|
1463
|
+
if os.path.isdir(cand):
|
|
1464
|
+
return cand
|
|
1465
|
+
return None
|
|
1466
|
+
|
|
1467
|
+
|
|
1468
|
+
def discover_ledger(root):
|
|
1469
|
+
"""在没有 `--plan` 的情况下找账本。
|
|
1470
|
+
|
|
1471
|
+
**为什么必须有它(P6 复核审查 A-2)**:
|
|
1472
|
+
`ctx["ledger"]` 原先只从 `find_workspace(plan)` 推导,于是不给 `--plan`
|
|
1473
|
+
时 `ctx["ledger"]` 恒为 None → 「规模与账本一致」交叉校验整体短路。
|
|
1474
|
+
实测后果是一条零门槛后门:
|
|
1475
|
+
有未完成任务 + `--scale readonly` + 不给 `--plan` → **rc=0**
|
|
1476
|
+
同一夹具给出 `--plan` → rc=1(账本 scale 冲突)
|
|
1477
|
+
即任何变更只要声称只读、不传计划,就能拿到「无 FAIL 项」。
|
|
1478
|
+
|
|
1479
|
+
现在改为:`--plan` 缺失时在 `.superpowers/sdd/` 下枚举候选 workspace,
|
|
1480
|
+
取**唯一一个**带 progress.md 的用于交叉校验。
|
|
1481
|
+
- 命中 0 个 → 返回 (None, None):确实没有账本,不做交叉校验
|
|
1482
|
+
- 命中 1 个 → 返回其账本路径
|
|
1483
|
+
- 命中多个 → 返回 (None, "多条候选"):歧义,交给调用方报 WARN
|
|
1484
|
+
(不猜,猜错会拿错误账本判冲突)
|
|
1485
|
+
"""
|
|
1486
|
+
base = os.path.join(root, ".superpowers", "sdd")
|
|
1487
|
+
if not os.path.isdir(base):
|
|
1488
|
+
return None, None
|
|
1489
|
+
candidates = []
|
|
1490
|
+
for name in sorted(os.listdir(base)):
|
|
1491
|
+
ledger = os.path.join(base, name, "progress.md")
|
|
1492
|
+
if os.path.isfile(ledger):
|
|
1493
|
+
candidates.append(ledger)
|
|
1494
|
+
if len(candidates) == 1:
|
|
1495
|
+
return candidates[0], None
|
|
1496
|
+
if len(candidates) > 1:
|
|
1497
|
+
return None, "多条候选:%s" % ", ".join(
|
|
1498
|
+
os.path.basename(os.path.dirname(p)) for p in candidates[:4])
|
|
1499
|
+
return None, None
|
|
1500
|
+
|
|
1501
|
+
|
|
1502
|
+
# ---------------------------------------------------------------------------
|
|
1503
|
+
# 自检:配置 ↔ 代码一致性
|
|
1504
|
+
#
|
|
1505
|
+
# 回答「谁验证验证器」的第一层:这个脚本本身是用来验证修复质量的,
|
|
1506
|
+
# 它自己坏掉时不能指望它自证。所以把「配置声明的形状」与「代码期望的形状」
|
|
1507
|
+
# 做机械比对,任何一侧漂移都当场暴露(rc=2),而不是等到第 12 步炸。
|
|
1508
|
+
#
|
|
1509
|
+
# 注意:这里只校验**结构**(id 集合、门禁覆盖、裁剪矩阵完整性),
|
|
1510
|
+
# 不校验语义(评审是否到位、根因是否真到位)——那交角色契约与主控。
|
|
1511
|
+
# ---------------------------------------------------------------------------
|
|
1512
|
+
|
|
1513
|
+
CHECKER_IDS = ("S0", "S1", "S2", "S3", "S4", "S5", "S6", "S7", "S8")
|
|
1514
|
+
|
|
1515
|
+
|
|
1516
|
+
def self_check(wf):
|
|
1517
|
+
"""返回 drift 列表;空列表表示配置与代码一致。"""
|
|
1518
|
+
errors = []
|
|
1519
|
+
stage_ids = [s["id"] for s in wf.get("stages", [])]
|
|
1520
|
+
|
|
1521
|
+
# 1. 检查器注册表 ↔ 声明源双射
|
|
1522
|
+
if set(stage_ids) != set(CHECKER_IDS):
|
|
1523
|
+
errors.append("检查器注册表与 stages 不一致:声明 %s / 代码 %s"
|
|
1524
|
+
% (sorted(stage_ids), sorted(CHECKER_IDS)))
|
|
1525
|
+
|
|
1526
|
+
# 2. 每个 stage 引用的门禁必须存在
|
|
1527
|
+
gates = wf.get("gates", {})
|
|
1528
|
+
for s in wf.get("stages", []):
|
|
1529
|
+
for gid in str(s.get("gate", "")).split("+"):
|
|
1530
|
+
gid = gid.strip()
|
|
1531
|
+
if gid and gid not in gates:
|
|
1532
|
+
errors.append("%s 引用了未声明的门禁 %r" % (s["id"], gid))
|
|
1533
|
+
|
|
1534
|
+
# 3. 裁剪矩阵:行与规模键一致、每格取值合法
|
|
1535
|
+
keys = scale_keys(wf)
|
|
1536
|
+
matrix = wf.get("trim_matrix", {})
|
|
1537
|
+
declared_rows = set(k for k in matrix if not k.startswith("$"))
|
|
1538
|
+
if declared_rows != set(keys):
|
|
1539
|
+
errors.append("trim_matrix 行与 scale 键不一致:矩阵 %s / 规模 %s"
|
|
1540
|
+
% (sorted(declared_rows), sorted(keys)))
|
|
1541
|
+
for sc in keys:
|
|
1542
|
+
row = matrix.get(sc) or {}
|
|
1543
|
+
for sid in stage_ids:
|
|
1544
|
+
mark = row.get(sid)
|
|
1545
|
+
if mark not in TRIM_MODES:
|
|
1546
|
+
errors.append("trim_matrix[%s][%s] = %r 不是合法裁剪标记 %s"
|
|
1547
|
+
% (sc, sid, mark, "/".join(TRIM_MODES)))
|
|
1548
|
+
|
|
1549
|
+
# 4. 门禁标签派生依赖 short 字段
|
|
1550
|
+
for s in wf.get("stages", []):
|
|
1551
|
+
if not s.get("short"):
|
|
1552
|
+
errors.append("%s 缺 short 字段——gate_label() 会退化成全名" % s["id"])
|
|
1553
|
+
|
|
1554
|
+
# 5. glob 产物的路径必须可定界
|
|
1555
|
+
#
|
|
1556
|
+
# 只对 `glob: true` 的产物要求「文件名位置不得是占位符」——因为 glob 产物
|
|
1557
|
+
# 由 expand_artifact() 逐层枚举目录来定位,文件名位若放占位符则无从枚举。
|
|
1558
|
+
# 非 glob 产物的文件名占位符是合法的:`task-<N>-brief.md`、
|
|
1559
|
+
# `review-<N>.md` 这类由 check_S5/check_S6 用正则匹配,不经过 expand_artifact。
|
|
1560
|
+
# `review-<N>.md` 的存在性由 check_S6 的 S6.REVIEW_REPORT 项核对;
|
|
1561
|
+
# 其余检查读的是账本与计划文本。
|
|
1562
|
+
# (初版把规则套到全部产物,实测误报 9 处,全部是合法写法。)
|
|
1563
|
+
for s in wf.get("stages", []):
|
|
1564
|
+
for a in s.get("artifacts", []):
|
|
1565
|
+
if not a.get("glob"):
|
|
1566
|
+
continue
|
|
1567
|
+
base = os.path.basename(a["path"].rstrip("/"))
|
|
1568
|
+
if "<" in base:
|
|
1569
|
+
errors.append("%s 的 glob 产物路径不可定界(文件名位含占位符,"
|
|
1570
|
+
"expand_artifact 无法枚举):%s" % (s["id"], a["path"]))
|
|
1571
|
+
|
|
1572
|
+
# 6. L2 必须仍被标注为禁止交付(check_S6 的输出文案依赖此事实)
|
|
1573
|
+
levels = wf.get("reviewer_independence", {}).get("levels", {}) or {}
|
|
1574
|
+
l2 = levels.get("L2")
|
|
1575
|
+
hint = l2 if isinstance(l2, str) else str(
|
|
1576
|
+
(l2 or {}).get("deliverable") or (l2 or {}).get("note")
|
|
1577
|
+
or (l2 or {}).get("meaning") or "")
|
|
1578
|
+
if "禁止" not in hint:
|
|
1579
|
+
errors.append("reviewer_independence.levels.L2 未标注禁止交付——"
|
|
1580
|
+
"S6 的 L2 拦截语义失去依据(当前值:%r)" % (l2,))
|
|
1581
|
+
|
|
1582
|
+
# 7. 「简」模式保留项必须引用真实存在的阶段
|
|
1583
|
+
for sid in LIGHT_KEEP:
|
|
1584
|
+
if sid not in stage_ids:
|
|
1585
|
+
errors.append("LIGHT_KEEP 声明了不存在的阶段 %r" % sid)
|
|
1586
|
+
|
|
1587
|
+
# 8. component_registry 必须覆盖所有 stages[].components;internal 路径必须存在;
|
|
1588
|
+
# required: true 的资产缺失即配置漂移。
|
|
1589
|
+
registry = wf.get("component_registry", {}) or {}
|
|
1590
|
+
reg_keys = set(registry.keys())
|
|
1591
|
+
_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
1592
|
+
for s in wf.get("stages", []):
|
|
1593
|
+
for comp in s.get("components", []):
|
|
1594
|
+
if comp not in reg_keys:
|
|
1595
|
+
errors.append("stage %s 的组件 %r 未在 component_registry 登记" % (s["id"], comp))
|
|
1596
|
+
else:
|
|
1597
|
+
entry = registry[comp]
|
|
1598
|
+
internal = entry.get("internal")
|
|
1599
|
+
if internal and not os.path.exists(os.path.join(_root, internal)):
|
|
1600
|
+
# P2-1:部署布局备用候选。部署下 _root = <技能根>/skills/zcode-expert-system/,
|
|
1601
|
+
# 技能文件在 <技能根>/skills/zes-*/<文件>;取父目录 + internal
|
|
1602
|
+
# 倒数第二段目录名 + 文件名作为备用候选,存在则不报 DRIFT。
|
|
1603
|
+
parts = internal.split("/")
|
|
1604
|
+
backup = os.path.join(os.path.dirname(_root), parts[-2], parts[-1])
|
|
1605
|
+
if not os.path.exists(backup):
|
|
1606
|
+
errors.append("组件 %r 声明的 internal 路径不存在:%s" % (comp, internal))
|
|
1607
|
+
if entry.get("required") is True:
|
|
1608
|
+
scripts = entry.get("scripts") or {}
|
|
1609
|
+
for script_name, script_rel in scripts.items():
|
|
1610
|
+
if not os.path.exists(os.path.join(_root, script_rel)):
|
|
1611
|
+
errors.append("组件 %r 的必需脚本 %s 路径不存在:%s"
|
|
1612
|
+
% (comp, script_name, script_rel))
|
|
1613
|
+
|
|
1614
|
+
return errors
|
|
1615
|
+
|
|
1616
|
+
|
|
1617
|
+
def explain(ctx):
|
|
1618
|
+
"""解析明细:FAIL 时让用户 30 秒自查是不是格式问题,而不是怀疑工具。"""
|
|
1619
|
+
lines = ["", "解析明细"]
|
|
1620
|
+
if ctx.get("change_dir"):
|
|
1621
|
+
tp = os.path.join(ctx["change_dir"], "tasks.md")
|
|
1622
|
+
ttext = read(tp)
|
|
1623
|
+
if ttext is None:
|
|
1624
|
+
lines.append(" tasks.md: 读不到 %s" % tp)
|
|
1625
|
+
else:
|
|
1626
|
+
c = count_checkboxes(ttext)
|
|
1627
|
+
lines.append(" tasks.md: done=%d todo=%d other=%d,列表符=%s"
|
|
1628
|
+
% (c["done"], c["todo"], c["other"],
|
|
1629
|
+
",".join(detect_bullet_styles(ttext)) or "无"))
|
|
1630
|
+
if ctx.get("ledger"):
|
|
1631
|
+
ltext = read(ctx["ledger"])
|
|
1632
|
+
lines.append(" ledger complete 行:%s"
|
|
1633
|
+
% ((",".join(sorted(_ledger_completed_ids(ltext))) or "无")
|
|
1634
|
+
if ltext is not None else "读不出"))
|
|
1635
|
+
if ctx.get("plan"):
|
|
1636
|
+
ptext = read(ctx["plan"])
|
|
1637
|
+
secs = (re.findall(r"^#{1,6}[ \t]+(.+?)[ \t]*$", ptext, re.M)
|
|
1638
|
+
if ptext is not None else [])
|
|
1639
|
+
lines.append(" 计划段名:%s"
|
|
1640
|
+
% ((", ".join(secs[:14]) or "无")
|
|
1641
|
+
if ptext is not None else "读不出"))
|
|
1642
|
+
lines.append("")
|
|
1643
|
+
return "\n".join(lines)
|
|
1644
|
+
|
|
1645
|
+
|
|
1646
|
+
# ---------------------------------------------------------------------------
|
|
1647
|
+
# 主流程
|
|
1648
|
+
# ---------------------------------------------------------------------------
|
|
1649
|
+
|
|
1650
|
+
def run(change=None, plan=None, scale=None, root=None, expect_archive=False):
|
|
1651
|
+
wf = load_workflow()
|
|
1652
|
+
root = os.path.abspath(root or os.getcwd())
|
|
1653
|
+
env = detect_env(root)
|
|
1654
|
+
|
|
1655
|
+
# 相对路径按 --root 解析,不按进程 cwd——否则跨目录核对会静默指向错误文件
|
|
1656
|
+
if plan and not os.path.isabs(plan):
|
|
1657
|
+
plan = os.path.join(root, plan)
|
|
1658
|
+
|
|
1659
|
+
scale_key, scale_valid = normalize_scale(wf, scale)
|
|
1660
|
+
|
|
1661
|
+
# --change 只允许单段名字:`../../docs` 会让 change_dir 逃出 openspec/changes/
|
|
1662
|
+
change_ok = bool(change) and re.match(r"^[A-Za-z0-9][A-Za-z0-9._-]*$", change or "")
|
|
1663
|
+
change_invalid = bool(change) and not change_ok
|
|
1664
|
+
|
|
1665
|
+
ctx = {
|
|
1666
|
+
"root": root,
|
|
1667
|
+
"change": change,
|
|
1668
|
+
"change_dir": (os.path.join(root, "openspec", "changes", change)
|
|
1669
|
+
if change and change_ok else None),
|
|
1670
|
+
"change_invalid": change_invalid,
|
|
1671
|
+
"plan": os.path.abspath(plan) if plan else None,
|
|
1672
|
+
"scale": scale,
|
|
1673
|
+
"scale_key": scale_key,
|
|
1674
|
+
"scale_valid": scale_valid,
|
|
1675
|
+
"today": datetime.now().strftime("%Y-%m-%d"),
|
|
1676
|
+
# 环境探测必须真实发生:旧实现写死 True,导致 --root 指向不存在目录
|
|
1677
|
+
# 也报 `[ OK ] 环境已探测`(实测 rc=0)。
|
|
1678
|
+
"env_probed": os.path.isdir(root),
|
|
1679
|
+
"env_summary": env["summary"],
|
|
1680
|
+
"git": env["git"],
|
|
1681
|
+
"openspec": env["openspec"],
|
|
1682
|
+
"expect_archive": expect_archive,
|
|
1683
|
+
"trim": None,
|
|
1684
|
+
}
|
|
1685
|
+
ctx["workspace"] = find_workspace(root, ctx["plan"]) if ctx["plan"] else None
|
|
1686
|
+
ctx["ledger"] = (os.path.join(ctx["workspace"], "progress.md")
|
|
1687
|
+
if ctx["workspace"] and os.path.exists(
|
|
1688
|
+
os.path.join(ctx["workspace"], "progress.md")) else None)
|
|
1689
|
+
# 不给 --plan 时也要能找到账本,否则「规模与账本一致」交叉校验会短路,
|
|
1690
|
+
# 形成「声称 readonly + 不传计划 ⇒ rc=0」的后门(P6 A-2)。
|
|
1691
|
+
ctx["ledger_ambiguous"] = None
|
|
1692
|
+
if ctx["ledger"] is None:
|
|
1693
|
+
discovered, ambiguity = discover_ledger(root)
|
|
1694
|
+
if discovered:
|
|
1695
|
+
ctx["ledger"] = discovered
|
|
1696
|
+
elif ambiguity:
|
|
1697
|
+
ctx["ledger_ambiguous"] = ambiguity
|
|
1698
|
+
|
|
1699
|
+
rep = Report()
|
|
1700
|
+
|
|
1701
|
+
# P3-3:消费 ctx["ledger_ambiguous"](旧实现只写不读,歧义静默)。
|
|
1702
|
+
# 多账本并存导致 discover_ledger 无法唯一确定账本时,以 WARN 告知,
|
|
1703
|
+
# 不致 rc≠0(WARN 不触发失败),保持 fail-closed 粒度仅补通知。
|
|
1704
|
+
if ctx.get("ledger_ambiguous"):
|
|
1705
|
+
rep.add(gate_label(wf, "S0"), "账本唯一性", WARN,
|
|
1706
|
+
"[warn:ledger_ambiguous] %s —— 多个 progress.md 候选,未做规模与账本交叉校验"
|
|
1707
|
+
% ctx["ledger_ambiguous"],
|
|
1708
|
+
id="S0.LEDGER_AMBIGUOUS", reason="soft:ledger_ambiguous")
|
|
1709
|
+
|
|
1710
|
+
# --change 名非法:先记一条,后续 S2 据此 FAIL
|
|
1711
|
+
if change_invalid:
|
|
1712
|
+
rep.add(gate_label(wf, "S0"), "变更名格式合法", FAIL,
|
|
1713
|
+
"[malformed:change_name] %r 不是合法的变更名(只允许字母数字与 ._-),"
|
|
1714
|
+
"且 `..` 会逃出 openspec/changes/" % change,
|
|
1715
|
+
id="S0.CHANGE_NAME", reason="malformed:change_name")
|
|
1716
|
+
|
|
1717
|
+
# 只读误标防护(R-A):声明 readonly 却给了 change/plan —— 自相矛盾。
|
|
1718
|
+
#
|
|
1719
|
+
# 为什么是 **FAIL** 而不是 WARN(P6 复核审查 A-2):
|
|
1720
|
+
# 只读任务按 trim_matrix 不产生 change 也不产生 plan,所以「声明只读
|
|
1721
|
+
# 却指名变更/计划」不是「将来才成立的可宽限项」,而是**当下的矛盾**。
|
|
1722
|
+
# 判 WARN 时它不足以让 rc≠0——实测「有未完成任务 + readonly + 不给 --plan」
|
|
1723
|
+
# 得到 rc=0,唯一信号就是这条 WARN。那就是一道后门。
|
|
1724
|
+
if scale_valid and scale_key == "readonly" and (change or plan):
|
|
1725
|
+
rep.add(gate_label(wf, "S0"), "规模标注自洽", FAIL,
|
|
1726
|
+
"[malformed:readonly_mismatch] 声明 --scale readonly 却提供了 "
|
|
1727
|
+
"%s——只读任务按 trim_matrix 不产生 change 也不产生 plan;"
|
|
1728
|
+
"这是自相矛盾的声明,且 readonly 会跳过 S1-S8 全部门禁"
|
|
1729
|
+
% "/".join(x for x in (("--change" if change else None),
|
|
1730
|
+
("--plan" if plan else None)) if x),
|
|
1731
|
+
id="S0.SCALE_MISMATCH", reason="malformed:readonly_mismatch")
|
|
1732
|
+
|
|
1733
|
+
_BY_ID = {"S0": check_S0, "S1": check_S1, "S2": check_S2, "S3": check_S3,
|
|
1734
|
+
"S4": check_S4, "S5": check_S5, "S6": check_S6, "S7": check_S7,
|
|
1735
|
+
"S8": check_S8}
|
|
1736
|
+
# 检查器注册表与声明源必须一致(--self-check 也查这条,这里防运行时缺项)
|
|
1737
|
+
stage_ids = [s["id"] for s in wf["stages"]]
|
|
1738
|
+
checkers = [(_BY_ID[sid], sid) for sid in stage_ids if sid in _BY_ID]
|
|
1739
|
+
|
|
1740
|
+
for fn, sid in checkers:
|
|
1741
|
+
trim = "必" if not scale_valid else trim_of(wf, scale_key, sid)
|
|
1742
|
+
if trim == "-":
|
|
1743
|
+
rep.add(gate_label(wf, sid), "阶段已裁剪(trim_matrix)", SKIP,
|
|
1744
|
+
"[inapplicable:trim] %s 在 scale=%s 下为 '-'"
|
|
1745
|
+
% (sid, scale_key or "-"),
|
|
1746
|
+
id="%s.TRIM" % sid, reason="inapplicable:trim")
|
|
1747
|
+
continue
|
|
1748
|
+
ctx["trim"] = trim or "必"
|
|
1749
|
+
before = len(rep.items)
|
|
1750
|
+
try:
|
|
1751
|
+
fn(ctx, rep, wf)
|
|
1752
|
+
except Exception as exc: # 单阶段异常不拖垮整体
|
|
1753
|
+
rep.add(gate_label(wf, sid), "执行异常", FAIL,
|
|
1754
|
+
"[unverifiable:exception] %s: %s" % (type(exc).__name__, exc),
|
|
1755
|
+
id="%s.EXCEPTION" % sid, reason="unverifiable:exception")
|
|
1756
|
+
# INV-R1 无静默:未被裁剪的阶段必须至少产出一条检查项。
|
|
1757
|
+
# 这一条独立于各检查器实现——即使未来某人又写了一处提前 return 也不会静默。
|
|
1758
|
+
if len(rep.items) == before:
|
|
1759
|
+
rep.add(gate_label(wf, sid), "阶段未产出检查项", FAIL,
|
|
1760
|
+
"[unverifiable:no_items] 该阶段在被裁剪之外却没有任何检查项——"
|
|
1761
|
+
"疑似检查器提前返回",
|
|
1762
|
+
id="%s.STAGE_EMPTY" % sid, reason="unverifiable:no_items")
|
|
1763
|
+
|
|
1764
|
+
# 账本规模与 --scale 交叉校验(R-B):只靠调用方自报挡不住「标 readonly 逃门禁」
|
|
1765
|
+
if scale_valid and ctx["ledger"]:
|
|
1766
|
+
_apply_ledger_scale_conflict(ctx, rep, wf, scale_key)
|
|
1767
|
+
|
|
1768
|
+
rep.enforce_reasons()
|
|
1769
|
+
return rep, ctx
|
|
1770
|
+
|
|
1771
|
+
|
|
1772
|
+
# 规模标签 ↔ 英文键的映射。
|
|
1773
|
+
#
|
|
1774
|
+
# 为什么需要它(P6 复核审查 A-3):
|
|
1775
|
+
# `templates/progress.md` 规定 `## Scale` 填**中文**
|
|
1776
|
+
# (`<只读 | 轻量 | 中任务 | 大任务 | Bug>`),而旧实现只认英文键。
|
|
1777
|
+
# 双向都错:填空模板会被正则命中 `Bug` 判成 scale=bug(假红);
|
|
1778
|
+
# 如实填「轻量」则正则不命中、检测静默 return(假绿)。
|
|
1779
|
+
SCALE_LABEL = {
|
|
1780
|
+
"只读": "readonly",
|
|
1781
|
+
"轻量": "light",
|
|
1782
|
+
"中任务": "medium",
|
|
1783
|
+
"大任务": "large",
|
|
1784
|
+
"bug": "bug",
|
|
1785
|
+
}
|
|
1786
|
+
|
|
1787
|
+
|
|
1788
|
+
def parse_scale_section(text):
|
|
1789
|
+
"""从 `## Scale` 段解析规模键。无法确定时返回 None。
|
|
1790
|
+
|
|
1791
|
+
三条规则:
|
|
1792
|
+
1. **先剥模板占位符**:`<只读 | 轻量 | ... | Bug>` 是待填格式,
|
|
1793
|
+
不是真实取值。不剥会让「照抄模板」被判 scale=bug 冲突。
|
|
1794
|
+
2. 同时接受中文标签与英文键(见 SCALE_LABEL)。
|
|
1795
|
+
3. **出现多个不同规模 → 返回 None**(视为无法确定,不猜)。
|
|
1796
|
+
猜错的代价是「降级检测」失效或误报冲突,两个方向都坏。
|
|
1797
|
+
|
|
1798
|
+
段缺失或只有占位符时返回 None——调用方据此跳过检查(不是判冲突)。
|
|
1799
|
+
"""
|
|
1800
|
+
body = section_body(text or "", "Scale")
|
|
1801
|
+
if not body:
|
|
1802
|
+
return None
|
|
1803
|
+
|
|
1804
|
+
# 1. 剥模板占位符:`<...>` 内的内容是待填说明,不是取值
|
|
1805
|
+
clean = re.sub(r"<[^>\n]*>", " ", body)
|
|
1806
|
+
|
|
1807
|
+
found = set()
|
|
1808
|
+
# 中文标签(先匹配长的,避免「大任务」被「任务」之类吃掉)
|
|
1809
|
+
for label in sorted(SCALE_LABEL, key=len, reverse=True):
|
|
1810
|
+
if label in clean.lower():
|
|
1811
|
+
found.add(SCALE_LABEL[label])
|
|
1812
|
+
# 英文键(整词,避免 `bug` 命中 `debug`)
|
|
1813
|
+
for key in ("readonly", "light", "medium", "large", "bug"):
|
|
1814
|
+
if re.search(r"\b%s\b" % key, clean, re.I):
|
|
1815
|
+
found.add(key)
|
|
1816
|
+
|
|
1817
|
+
if len(found) != 1:
|
|
1818
|
+
return None # 0 个 = 未填;多个 = 歧义,都不猜
|
|
1819
|
+
return found.pop()
|
|
1820
|
+
|
|
1821
|
+
|
|
1822
|
+
def _apply_ledger_scale_conflict(ctx, rep, wf, scale_key):
|
|
1823
|
+
"""账本记录的 ## Scale 与 --scale 不一致 → FAIL。
|
|
1824
|
+
|
|
1825
|
+
账本是 S0 的产出,留了当时的分类结论;与最终 --scale 冲突说明中途改了口径,
|
|
1826
|
+
而规格明确「规模只能升级不能降级」(workflow.json scale.ratchet)。
|
|
1827
|
+
"""
|
|
1828
|
+
ltext = read(ctx["ledger"])
|
|
1829
|
+
if ltext is None:
|
|
1830
|
+
# 账本存在但读不出:交叉校验「查不了」→ FAIL(A-9)。
|
|
1831
|
+
# 旧实现压成空串后静默 return,而 readonly 下账本是唯一检查对象,
|
|
1832
|
+
# 整次核对就此空转还 rc=0(实测后门)。
|
|
1833
|
+
rep.add(gate_label(wf, "S0"), "规模与账本一致", FAIL,
|
|
1834
|
+
"[malformed:ledger_unreadable] 账本存在但读不出,规模交叉校验无从进行",
|
|
1835
|
+
id="S0.SCALE_CONFLICT", reason="malformed:ledger_unreadable")
|
|
1836
|
+
return
|
|
1837
|
+
recorded = parse_scale_section(ltext)
|
|
1838
|
+
if recorded is None:
|
|
1839
|
+
# 未填或歧义:不判冲突(无法确定就不猜),但要留痕。
|
|
1840
|
+
# 三态再分(A-9):缺段与「有段但查不出」是两种失败——
|
|
1841
|
+
# 缺段:readonly 下账本是唯一检查对象,缺段=整次核对空转 → FAIL;
|
|
1842
|
+
# 其他规模下账本缺段属历史格式包袱,维持静默(防大面积假红,
|
|
1843
|
+
# proj 夹具的常规账本就没有 Scale 段)。
|
|
1844
|
+
# 有段但未填/歧义/只有占位符:查了但查不出结论 → WARN(A-15 裁决范围,不升级)。
|
|
1845
|
+
if not section_body(ltext, "Scale"):
|
|
1846
|
+
if scale_key == "readonly":
|
|
1847
|
+
rep.add(gate_label(wf, "S0"), "规模与账本一致", FAIL,
|
|
1848
|
+
"[missing:scale_section] 账本缺 `## Scale` 段——S0 产出缺失"
|
|
1849
|
+
"(readonly 下账本唯一,缺段即整次核对空转)",
|
|
1850
|
+
id="S0.SCALE_CONFLICT", reason="missing:scale_section")
|
|
1851
|
+
else:
|
|
1852
|
+
rep.add(gate_label(wf, "S0"), "规模与账本一致", WARN,
|
|
1853
|
+
"[soft:scale_unparsable] 账本 `## Scale` 段无法确定规模"
|
|
1854
|
+
"(未填 / 填了多个 / 只有模板占位符)",
|
|
1855
|
+
id="S0.SCALE_CONFLICT", reason="soft:scale_unparsable")
|
|
1856
|
+
return
|
|
1857
|
+
if recorded == scale_key:
|
|
1858
|
+
return
|
|
1859
|
+
order = {k: i for i, k in enumerate(scale_keys(wf))}
|
|
1860
|
+
downgrade = order.get(scale_key, 99) < order.get(recorded, -1)
|
|
1861
|
+
rep.add(gate_label(wf, "S0"), "规模与账本一致", FAIL,
|
|
1862
|
+
"[malformed:scale_conflict] 账本记录 scale=%s,而 --scale=%s%s;"
|
|
1863
|
+
"规模只能升级不能降级——请修正 --scale 或更新账本"
|
|
1864
|
+
% (recorded, scale_key, "(疑似降级)" if downgrade else ""),
|
|
1865
|
+
id="S0.SCALE_CONFLICT", reason="malformed:scale_conflict")
|
|
1866
|
+
|
|
1867
|
+
|
|
1868
|
+
def main(argv=None):
|
|
1869
|
+
_force_utf8_stdout()
|
|
1870
|
+
wf = load_workflow()
|
|
1871
|
+
ap = argparse.ArgumentParser(description="工作流阶段完整性核对")
|
|
1872
|
+
ap.add_argument("--change", help="OpenSpec change 名")
|
|
1873
|
+
ap.add_argument("--plan", help="实施计划文档路径")
|
|
1874
|
+
ap.add_argument("--scale", help="规模:%s" % "|".join(scale_keys(wf)))
|
|
1875
|
+
ap.add_argument("--root", help="项目根(默认当前目录)")
|
|
1876
|
+
ap.add_argument("--json", action="store_true", help="输出 JSON")
|
|
1877
|
+
ap.add_argument("--expect-archive", action="store_true",
|
|
1878
|
+
help="此刻正在归档:归档目录缺失判 FAIL 而非 WARN")
|
|
1879
|
+
ap.add_argument("--self-check", action="store_true",
|
|
1880
|
+
help="只校验配置与代码的一致性(不核项目内容),rc=2 表示有 drift")
|
|
1881
|
+
ap.add_argument("--explain", action="store_true",
|
|
1882
|
+
help="打印 tasks.md / 账本 / 计划的解析明细,便于自查格式问题")
|
|
1883
|
+
args = ap.parse_args(argv)
|
|
1884
|
+
|
|
1885
|
+
# 非法 --scale 走参数错误(rc=2),与「内容不合格」(rc=1)区分开。
|
|
1886
|
+
# 不做宽容匹配:`Medium`/` medium` 一律拒绝——门禁参数不接受猜测,
|
|
1887
|
+
# 否则一次笔误会变成一次未声明的门禁裁剪,而报告里看不出异常。
|
|
1888
|
+
# 这里显式 print + return 2 而非 argparse.error()(后者抛 SystemExit),
|
|
1889
|
+
# 使 main() 保持「返回码函数」契约,便于被测试与库调用方直接消费。
|
|
1890
|
+
if args.scale is not None:
|
|
1891
|
+
_, valid = normalize_scale(wf, args.scale)
|
|
1892
|
+
if not valid:
|
|
1893
|
+
print("参数错误:--scale 取值非法:%r(可选:%s)"
|
|
1894
|
+
% (args.scale, "|".join(scale_keys(wf))), file=sys.stderr)
|
|
1895
|
+
return 2
|
|
1896
|
+
|
|
1897
|
+
if args.self_check:
|
|
1898
|
+
errors = self_check(wf)
|
|
1899
|
+
print("配置自检")
|
|
1900
|
+
if errors:
|
|
1901
|
+
for e in errors:
|
|
1902
|
+
print(" [DRIFT] %s" % e)
|
|
1903
|
+
print("\n结论:发现 %d 处配置与代码漂移。" % len(errors))
|
|
1904
|
+
return 2
|
|
1905
|
+
print(" [ OK ] 配置与代码一致")
|
|
1906
|
+
print("\n结论:无漂移。")
|
|
1907
|
+
return 0
|
|
1908
|
+
|
|
1909
|
+
rep, ctx = run(change=args.change, plan=args.plan,
|
|
1910
|
+
scale=args.scale, root=args.root,
|
|
1911
|
+
expect_archive=args.expect_archive)
|
|
1912
|
+
|
|
1913
|
+
if args.json:
|
|
1914
|
+
print(json.dumps({
|
|
1915
|
+
"root": ctx["root"],
|
|
1916
|
+
"change": ctx["change"],
|
|
1917
|
+
"plan": ctx["plan"],
|
|
1918
|
+
"scale": ctx["scale_key"],
|
|
1919
|
+
"env": {"git": ctx["git"], "openspec": ctx["openspec"]},
|
|
1920
|
+
"workspace": ctx["workspace"],
|
|
1921
|
+
"summary": {s: rep.count(s) for s in (OK, WARN, FAIL, SKIP)},
|
|
1922
|
+
"items": rep.items,
|
|
1923
|
+
}, ensure_ascii=False, indent=2))
|
|
1924
|
+
else:
|
|
1925
|
+
print("工作流完整性核对")
|
|
1926
|
+
print("项目根:%s" % ctx["root"])
|
|
1927
|
+
print("变更:%s | 计划:%s | 规模:%s" % (
|
|
1928
|
+
ctx["change"] or "-", ctx["plan"] or "-", ctx["scale_key"] or "-"))
|
|
1929
|
+
print("环境:%s" % ctx["env_summary"])
|
|
1930
|
+
if args.explain:
|
|
1931
|
+
print(explain(ctx))
|
|
1932
|
+
print(rep.render())
|
|
1933
|
+
if rep.has_fail():
|
|
1934
|
+
print("\n结论:存在 FAIL 项,不得进入下一阶段。")
|
|
1935
|
+
else:
|
|
1936
|
+
print("\n结论:无 FAIL 项(WARN 项需人工确认)。")
|
|
1937
|
+
|
|
1938
|
+
return 1 if rep.has_fail() else 0
|
|
1939
|
+
|
|
1940
|
+
|
|
1941
|
+
if __name__ == "__main__":
|
|
1942
|
+
sys.exit(main())
|