feat: spec validation engine + parser + CLI#786
Conversation
|
are you implementing this using remote-factory it self? why it's not updating factory/discovery/spec.py |
|
maybe because you are running it from an old commit. the spec.py was just merged this morning |
oh yeah did not pull it ig |
|
i think your version is better than what's in main. 2 things i'd like to preserve to have it merged
|
|
Scaffold the spec module with source file collection (respecting .gitignore, excluding node_modules/.factory/__pycache__), file batching for Haiku context window, and async generate_spec() entry point. Add spec_extractor.md (Haiku extraction prompt) and spec_annotator.md (Researcher annotation prompt) for the two-stage pipeline.
Define spec_generate_workflow() in definitions.py with the extract → gate → annotate → gate → validate_stub → gate pipeline. Register as 'spec-generate' in register_all(). Add 'factory spec generate <path>' CLI subcommand with argparse sub-subparser and handler registration. Add comprehensive tests for source file collection, file batching, workflow graph validation, and node structure.
Narrow getattr result from Any | None to str via str() cast, and align fallback lambda parameter name with cmd_spec_generate signature.
Add factory/spec/parser.py with RepoSpec model and parse_spec() for regex-based Markdown parsing of .factory/repo_spec.md. Add factory/spec/validate.py with validate_spec() that runs path existence checks, Python import cross-referencing via ast.parse, orphan/hub module detection, and afferent/efferent coupling metrics with instability computation. Writes results to .factory/spec_validation.md.
Replace the placeholder echo PASS FnNode with a real validate
node that runs 'factory spec validate {project_path}', reading
repo_spec.md and writing spec_validation.md. Update existing
tests for the renamed node.
Wire cmd_spec_validate handler into the spec subparser and handler dict. Re-export parse_spec and validate_spec from the spec module __init__.
Test Markdown parsing (modules, edges, contracts, entry points, change impact), path existence checks, Python import cross-ref, orphan/hub detection, coupling metrics, and validation report output.
Add factory/spec/update.py with DiffScope model, scope_diff() for mapping diffs to affected spec modules, and update_spec() async orchestration entry point. Add spec_patcher.md agent prompt for incremental Haiku-based spec patching. Update __init__.py re-exports.
Add spec_update_workflow() defining W₁₀: diff_scope → patch → gate_patch → revalidate → gate_revalidate. Add non-blocking spec_update FnNode to improve and research workflows after archivist, conditionally running if repo_spec.md exists.
Add cmd_spec_scope and cmd_spec_update handlers. Wire scope and update as sub-subcommands under the spec subparser with event emission for observability.
Add tests/test_spec_update.py with 34 tests covering diff parsing, file-to-module mapping, scope formatting, scope_diff integration, W₁₀ graph validation, registry count, and improve workflow spec_update node integration. Update existing test assertions for 10-workflow registry count.
Add get_impact() to extract the subgraph centered on a named module from the repo spec, returning a compact Markdown snippet for agent context inclusion. Wire as 'factory spec impact <module> --project <path>'.
Add conditional 'Repo Spec (if available)' sections to strategist, builder, qa, and ceo prompts so agents consult the spec for dependency analysis, blast radius, and change impact during their workflows.
The test asserted 8 workflows but register_all() now returns 10 after spec-generate and spec-update were added.
Rename all file path references from repo_spec.md to GRAPH-SPEC.md across Python source, agent prompts, workflow definitions, and tests. Variable and function names (parse_spec, validate_spec, etc.) are unchanged — only the on-disk filename changes.
Modify resolve_spec() to look for GRAPH-SPEC.md (committed at root, then generated in .factory/). Replace procedural generate_spec() body with delegation to factory.spec.generate.generate_spec(). Remove old helpers (_read_readme_summary, _detect_source_dirs, _read_top_level_deps, _fetch_github_issues) — the agent pipeline handles extraction directly.
Rename section heading from SPEC.md to GRAPH-SPEC. Update status messages to reference GRAPH-SPEC.md paths and the new CLI command 'factory spec generate' for absent specs.
Replace SPEC.md Diff with GRAPH-SPEC Diff throughout. Update diff format from section-level entries (Section 2.3) to module-level entries (module 'store'). Remove redundant Repo Spec section heading in favor of GRAPH-SPEC.
Opus provides stronger architectural reasoning needed for RFC-style spec generation with structural graph sections, normative language precision, and coupling metric computation. Increase batch token limit from 80K to 160K to leverage Opus's larger context window.
Replace Python ast.parse and regex-based import cross-referencing with a Haiku agent call for language-agnostic verification. Keep tier 1 structural checks (path existence, orphan/hub detection, coupling metrics) as pure Python. Update tests to mock the Haiku invoke_agent call.
Add ProjectIdentity, goals, abstraction levels, and coupling metrics to the parser. Update agent prompts for RFC-style output. Fix regex quantifiers in _extract_section and _parse_table_rows that prevented parsing numbered section headers (e.g. "## 5. Change Impact").
Update builder, QA, and CEO prompt headings from "## Repo Spec (if available)" to "## GRAPH-SPEC (if available)".
f2b73ae to
007dc7d
Compare
Sentrux Quality ReportAbsoluteDiff (vs base branch) |
The spec format was renamed to GRAPH-SPEC but introspect.py still checked for the old SPEC.md filename, causing has_spec to always return false.
Replace per-file _is_gitignored subprocess calls with a single _get_gitignored batch using git check-ignore --stdin.
The discover CLI tests were calling generate_spec which spawns a real claude agent. CI has no claude binary, so mock the call to return stub GRAPH-SPEC content.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #786 +/- ##
==========================================
- Coverage 87.11% 86.56% -0.55%
==========================================
Files 81 87 +6
Lines 12245 12891 +646
==========================================
+ Hits 10667 11159 +492
- Misses 1578 1732 +154 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
✅ Factory Review: KEEPVerdict: KEEP Posted by Factory CEO |
Summary
factory/spec/parser.py— regex-based Markdown parser for.factory/repo_spec.mdwithRepoSpecmodel containing modules, dependency edges, shared contracts, entry points, and change impact entriesfactory/spec/validate.py— automated validation engine with path existence checks, Python import cross-referencing (viaast.parse), orphan/hub module detection, afferent/efferent coupling metrics, and instability computationfactory spec validate <project_path>CLI subcommandvalidate_stubplaceholder with realvalidateFnNode runningfactory spec validateparse_specandvalidate_specfromfactory.spectest_all_skills_exportedassertion: expect 10 workflows (was 8) after spec-generate and spec-update additionsTest plan
ruff checkpasses on all changed filesmypypasses on all changed filesast.parse