-
Notifications
You must be signed in to change notification settings - Fork 1
feat(devtools): add lab schema commit, the real full-corpus persist path #3538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b47f251
feat(devtools): add lab schema commit, the real full-corpus persist path
Sinity b22c241
Merge remote-tracking branch 'origin/master' into feature/devtools/sc…
Sinity 8f921dc
fix(schema): declare index v54 SEMANTIC_REPARSE for PR #3537's classi…
Sinity cdc6a01
fix(schemas): union anyOf/oneOf branch types instead of overwriting
Sinity File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| """Commit a real full-corpus schema generation into committed packages. | ||
|
|
||
| ``devtools lab schema generate`` only ever produces a preview | ||
| ``GenerationResult`` -- it never writes to ``polylogue/schemas/providers/``. | ||
| This command is the actual persisting entry point (polylogue-k45pq): | ||
| it calls ``generate_all_schemas`` for real via | ||
| ``polylogue.schemas.operator.commit.commit_provider_schema`` and reports | ||
| which package versions changed, plus whether any previously-committed leaf | ||
| type was lost or narrowed. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
| import json | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| from polylogue.cli.shared.schema_command_support import build_schema_privacy_config | ||
| from polylogue.config import get_config | ||
| from polylogue.schemas.operator.commit import commit_provider_schema | ||
| from polylogue.schemas.operator.models import SchemaCommitRequest | ||
|
|
||
| REPO_ROOT = Path(__file__).resolve().parents[1] | ||
| DEFAULT_OUTPUT_DIR = REPO_ROOT / "polylogue" / "schemas" / "providers" | ||
|
|
||
|
|
||
| def _build_parser() -> argparse.ArgumentParser: | ||
| parser = argparse.ArgumentParser( | ||
| description="Commit a real full-corpus provider schema generation into committed packages." | ||
| ) | ||
| parser.add_argument("--provider", required=True, help="Provider to generate and commit schema for.") | ||
| parser.add_argument( | ||
| "--output-dir", | ||
| type=Path, | ||
| default=None, | ||
| help=f"Committed schema package root to write into (default: {DEFAULT_OUTPUT_DIR}).", | ||
| ) | ||
| parser.add_argument("--max-samples", type=int, default=None, help="Limit samples for generation.") | ||
| parser.add_argument( | ||
| "--full-corpus", | ||
| action="store_true", | ||
| default=True, | ||
| help="Bypass all sample caps for full-corpus schema generation (default: on).", | ||
| ) | ||
| parser.add_argument( | ||
| "--no-full-corpus", | ||
| dest="full_corpus", | ||
| action="store_false", | ||
| help="Generate from a capped sample window instead of the full corpus.", | ||
| ) | ||
| parser.add_argument( | ||
| "--privacy", | ||
| choices=("strict", "standard", "permissive"), | ||
| default=None, | ||
| help="Privacy preset level. Defaults to standard.", | ||
| ) | ||
| parser.add_argument("--privacy-config", type=Path, default=None, help="Path to TOML privacy config overrides.") | ||
| parser.add_argument( | ||
| "--dry-run", | ||
| "--check", | ||
| dest="dry_run", | ||
| action="store_true", | ||
| help="Preview what a commit would change without writing to --output-dir.", | ||
| ) | ||
| parser.add_argument("--json", action="store_true", help="Output as JSON.") | ||
| return parser | ||
|
|
||
|
|
||
| def main(argv: list[str] | None = None) -> int: | ||
| parser = _build_parser() | ||
| args = parser.parse_args(argv) | ||
|
|
||
| try: | ||
| privacy_config = build_schema_privacy_config( | ||
| privacy=args.privacy, | ||
| privacy_config_path=args.privacy_config, | ||
| ) | ||
| except ValueError as exc: | ||
| print(f"schema-commit: {exc}", file=sys.stderr) | ||
| return 1 | ||
| output_dir = args.output_dir if args.output_dir is not None else DEFAULT_OUTPUT_DIR | ||
|
|
||
| result = commit_provider_schema( | ||
| SchemaCommitRequest( | ||
| provider=str(args.provider), | ||
| output_dir=output_dir, | ||
| db_path=get_config().db_path, | ||
| max_samples=args.max_samples, | ||
| privacy_config=privacy_config, | ||
| full_corpus=bool(args.full_corpus), | ||
| dry_run=bool(args.dry_run), | ||
| ) | ||
| ) | ||
|
|
||
| if not result.success: | ||
| error = result.generation.error or "Schema generation failed" | ||
| if args.json: | ||
| print(json.dumps({"provider": result.provider, "success": False, "error": error}, sort_keys=True)) | ||
| else: | ||
| print(f"schema-commit: {error}", file=sys.stderr) | ||
| return 1 | ||
|
|
||
| if args.json: | ||
| print(json.dumps(result.to_dict(), sort_keys=True, indent=2)) | ||
| else: | ||
| mode = "DRY RUN (no files written)" if result.dry_run else f"committed to {output_dir}" | ||
| print(f"schema-commit: {result.provider} -- {mode}") | ||
| print(f" sample_count={result.generation.sample_count}") | ||
| for version_report in result.versions: | ||
| flags = [] | ||
| if version_report.narrowed_paths: | ||
| flags.append(f"NARROWED({len(version_report.narrowed_paths)})") | ||
| if version_report.added_paths: | ||
| flags.append(f"added({len(version_report.added_paths)})") | ||
| suffix = f" [{', '.join(flags)}]" if flags else "" | ||
| print( | ||
| f" {version_report.version}: {version_report.status} " | ||
| f"sample_count={version_report.sample_count}{suffix}" | ||
| ) | ||
| if result.narrowed: | ||
| print( | ||
| " WARNING: a previously-committed leaf type was lost or narrowed -- " | ||
| "review before trusting this commit.", | ||
| file=sys.stderr, | ||
| ) | ||
|
|
||
| return 1 if result.narrowed else 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| raise SystemExit(main()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.