Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 deletions devtools/schema_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@

from polylogue.cli.shared.schema_command_support import build_schema_privacy_config
from polylogue.config import get_config
from polylogue.maintenance.schema_inference_gate import (
authorize_schema_generation,
resolve_schema_inference_archive_root,
)
from polylogue.schemas.operator.commit import commit_provider_schema
from polylogue.schemas.operator.models import SchemaCommitRequest

Expand Down Expand Up @@ -64,6 +68,11 @@ def _build_parser() -> argparse.ArgumentParser:
help="Preview what a commit would change without writing to --output-dir.",
)
parser.add_argument("--json", action="store_true", help="Output as JSON.")
parser.add_argument(
"--schema-inference-receipt",
type=Path,
help="Fresh authoritative PASS receipt from devtools verify schema-inference-gate.",
)
return parser


Expand All @@ -81,17 +90,25 @@ def main(argv: list[str] | None = None) -> int:
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),
)
config = get_config()
if not args.dry_run and args.schema_inference_receipt is None:
print("schema-commit: --schema-inference-receipt is required when persisting schema packages", file=sys.stderr)
return 1
request = SchemaCommitRequest(
provider=str(args.provider),
output_dir=output_dir,
db_path=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 args.dry_run:
result = commit_provider_schema(request)
else:
archive_root = resolve_schema_inference_archive_root(config, fallback_db_path=config.db_path)
with authorize_schema_generation(archive_root, args.schema_inference_receipt):
result = commit_provider_schema(request)

if not result.success:
error = result.generation.error or "Schema generation failed"
Expand Down
33 changes: 23 additions & 10 deletions devtools/schema_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
from polylogue.cli.shared.schema_rendering import render_schema_generate_result
from polylogue.config import get_config
from polylogue.core.json import JSONDocument
from polylogue.maintenance.schema_inference_gate import (
authorize_schema_generation,
resolve_schema_inference_archive_root,
)
from polylogue.schemas.operator.models import SchemaInferRequest
from polylogue.schemas.operator.workflow import infer_schema
from polylogue.storage.sqlite.connection_profile import open_readonly_connection
Expand Down Expand Up @@ -89,6 +93,12 @@ def _build_parser() -> argparse.ArgumentParser:
parser.add_argument(
"--receipt", type=Path, default=None, help="Write an aggregate-only generation receipt as JSON."
)
parser.add_argument(
"--schema-inference-receipt",
type=Path,
required=True,
help="Fresh authoritative PASS receipt from devtools verify schema-inference-gate.",
)
return parser


Expand All @@ -104,21 +114,24 @@ def on_progress(_phase: str, payload: JSONDocument) -> None:
print(f"schema-generate: {json.dumps(event, sort_keys=True)}", file=sys.stderr, flush=True)

try:
config = get_config()
privacy_config = build_schema_privacy_config(
privacy=args.privacy,
privacy_config_path=args.privacy_config,
)
result = infer_schema(
SchemaInferRequest(
provider=str(args.provider),
db_path=get_config().db_path,
max_samples=args.max_samples,
privacy_config=privacy_config,
cluster=bool(args.cluster),
full_corpus=bool(args.full_corpus),
progress_callback=on_progress if args.progress or args.receipt is not None else None,
archive_root = resolve_schema_inference_archive_root(config, fallback_db_path=config.db_path)
with authorize_schema_generation(archive_root, args.schema_inference_receipt):
result = infer_schema(
SchemaInferRequest(
provider=str(args.provider),
db_path=config.db_path,
max_samples=args.max_samples,
privacy_config=privacy_config,
cluster=bool(args.cluster),
full_corpus=bool(args.full_corpus),
progress_callback=on_progress if args.progress or args.receipt is not None else None,
)
)
)
except ValueError as exc:
print(f"schema-generate: {exc}", file=sys.stderr)
return 1
Expand Down
Loading