Skip to content

Feat/add spec mining - #28

Merged
bartrosa merged 11 commits into
mainfrom
feat/add-spec-mining
May 28, 2026
Merged

bartrosa merged 11 commits into
mainfrom
feat/add-spec-mining

Conversation

@bartrosa

Copy link
Copy Markdown
Owner

Summary

Introduces a seven-stage mining workflow on pickled-spec that turns a Python repo into inventory, code context, stories, Gherkin features, rule tags, and evaluation reports. Dogfoods the pickled monorepo under dogfood/mining-output/.

Also fixes several friction items discovered during dogfood runs: line-based tag injection, call-graph resolver robustness, and defensive stripping of LLM markdown fences before structured parsing.

What's new

Mining CLI (pickled-spec mine)

Stage Command Primary output
Inventory mine inventory inventory.json
Code mine code code-context/*.md
Stories mine stories stories/*.story.md
Features mine features features/*.feature
Tag mine tag tags-proposals.json + in-file tags
Evaluate mine evaluate evaluation/coverage.json, ambiguity.json
Report mine report mining-report.md
  • mine all runs the full pipeline; --quick / --interactive, --surfaces, --overwrite-* supported.
  • Code stage: AST-based reader with body / callgraph depth, --max-hops default 2, cycle detection, callee caps.
  • Stories stage consumes code-context/ and can surface docstring drift.
  • Documentation: docs/mining.md, ADRs 0005–0007.

LLM output hardening (friction #17)

  • New shared helper: pickled_core.llm.sanitize.strip_markdown_fence.
  • Applied in all structured-output drafters (Gherkin, YAML, SQL, JSON, OpenAPI, HCL).
  • Strips only a single outermost fence wrapping the entire response; inner fences and trailing prose are preserved.
  • Replaces ad-hoc fence handling in IaCDrafter.
  • Tests: packages/pickled-core/tests/test_llm_sanitize.py (unit + per-drafter canned-LLM cases).

Tag injection fix (friction #16)

  • Tag stage uses line-based insertion instead of character offsets.
  • Repair path for legacy Scen@tag / enario: corruption; evaluate skips unparseable features with warnings.

Resolver / inventory

  • Safer handling of Literal[...] and typing annotations in import resolution.
  • Constructor-then-method, annotated params, noise filters for stdlib/decorators.
  • Bombardment fixtures under tests/fixtures/resolver_zoo/.

Other

  • py.typed on pickled-bdd for mypy when pickled-core imports BDD types.
  • feature_glob configuration for flexible feature paths.
  • Rules gates_runner multi-ruleset improvements.

Dogfood impact

On existing dogfood/mining-output/ before fence-strip:

  • Ambiguity parse error: 2 (features starting with ```)
  • After fix (verified on corrupted files + unit tests): 0 expected on re-run

Remaining fail / warn verdicts are scenario-quality / gate calibration, not parse corruption.

Test plan

uv sync --extra mcp
uv run pytest -q
uv run mypy packages/pickled-core/src
uv run ruff check packages/pickled-core/src/pickled_core/llm/ \
  packages/pickled-core/tests/test_llm_sanitize.py \
  packages/pickled-bdd/src/pickled_bdd/drafter.py \
  packages/pickled-rules/src/pickled_rules/drafter.py \
  packages/pickled-data/src/pickled_data/drafter.py \
  packages/pickled-diff/src/pickled_diff/drafter.py \
  packages/pickled-schema/src/pickled_schema/openapi/drafter.py \
  packages/pickled-iac/src/pickled_iac/drafter.py

uv run pytest -q packages/pickled-core/tests/test_llm_sanitize.py -v

# Optional full pipeline proof
uv run pickled-spec mine all . --output /tmp/nofence/ \
  --depth callgraph --max-hops 2 \
  --ruleset-config dogfood/pickled.ruleset.yaml --verbose

python3 -c "
import json
from collections import Counter
d = json.load(open('/tmp/nofence/evaluation/ambiguity.json'))
c = Counter(f['verdict'] for f in d['features'])
assert c.get('error', 0) == 0
print('ZERO PARSE ERRORS', dict(c))
"
grep -l '^\`\`\`' /tmp/nofence/features/*.feature || echo 'no stray fences'

Notes for reviewers

  • Large diff includes committed dogfood/mining-output/ artifacts; focus review on packages/pickled-core/src/pickled_core/mine/, drafters, and tests.
  • strip_markdown_fence is intentionally not applied to rationale / advisor prose fields.
  • Full uv run ruff check packages/ may still surface pre-existing issues outside this branch’s touched paths.

bartrosa added 11 commits May 28, 2026 17:22
- Introduced multiple new stages for the mining pipeline, including code extraction, feature drafting, and evaluation.
- Added error handling classes for actionable messages during the mining process.
- Implemented functionality to parse and collect ADRs, enriching gate documentation with summaries.
- Enhanced CLI commands to support new features and improved inventory management.
- Created new utility functions for managing code context and handling cycles in the mining process.
- Introduced `feature_glob` option in the configuration to specify the location of feature files relative to the workspace root, defaulting to `features/**/*.feature`.
- Updated the `gates_runner.py` to utilize the `feature_glob` setting for locating feature files.
- Enhanced the README.md to document the new `feature_glob` configuration and its usage.
- Added tests to verify the functionality of default and custom `feature_glob` settings.
- Introduced ADRs for the pickled-diff package, cache and budget management, and workspace layout.
- Added new packages for callgraph and resolver tests, including various modules and CLI functionalities.
- Created minimal fixtures for testing, including a tiny target package with a basic CLI.
- Updated project configurations to support new package structures and dependencies.
- Consolidated ambiguity gate logic into a dedicated function `run_ambiguity_gate` for improved clarity and reusability.
- Updated the `check` command to utilize the new function, maintaining backward compatibility with an alias for the ambiguity gate.
- Enhanced JSON output formatting for gate results and added exit handling based on verdicts.
- Improved feature drafting by stripping markdown fences from generated text, ensuring cleaner output.
- Added tests to verify the equivalence of the `ambiguity` command to the `check` command with the ambiguity gate.
- Integrated `strip_markdown_fence` function to clean up generated text in the `MigrationDrafter` class.
- Updated the output handling to ensure cleaner and more readable results from the drafting process.
- Added `strip_markdown_fence` function to clean up generated text in the `CorpusDrafter` class.
- Updated output handling to ensure cleaner and more readable results from the drafting process.
- Added `strip_markdown_fence` to clean up LLM output in the `OpenAPIDrafter` class.
- Updated YAML loading to ensure cleaner and more structured results from the drafting process.
- Replaced manual markdown fence handling with `strip_markdown_fence` in the `IaCDrafter` class.
- Enhanced the output from the LLM by ensuring cleaner Terraform HCL results without unnecessary fences or commentary.
- Integrated `enrich_inventory_data` function to enhance the payload generated in the `main` function of `inventory_functionality.py`.
- Improved data handling for better inventory management and output consistency.
- Added comprehensive documentation for the `pickled-spec mine` pipeline, detailing its stages and usage.
- Introduced a new `mining.md` file outlining the mining process and commands for extracting behavioral specifications from Python repositories.
- Documented the `code` stage for static code reading, enhancing story generation with observed code and enabling drift detection against docstrings.
- Established ADRs for the mining pipeline decisions, including code reading and code-aware story generation, to ensure clarity and future reference.
- Introduced new JSON and Markdown files for mining output, including `inventory.json`, `mining-report.md`, and `tags-proposals.json`.
- Added detailed code context files for various surfaces, enhancing traceability and understanding of the mining process.
- Implemented a structure for tracking cycles and code definitions, improving the overall mining pipeline documentation and output.
@bartrosa
bartrosa merged commit 5c3328d into main May 28, 2026
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant