mostlyright-data 0.31.13__tar.gz → 0.31.15__tar.gz

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.
Files changed (142) hide show
  1. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/.gitignore +3 -0
  2. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/PKG-INFO +1 -2
  3. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/pyproject.toml +2 -9
  4. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/references/commands.md +1 -1
  5. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/references/enriching-with-small-models.md +33 -8
  6. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/references/patterns.md +3 -2
  7. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/references/readers.md +12 -2
  8. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/references/source-credentials.md +2 -1
  9. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/references/sources.md +9 -1
  10. mostlyright_data-0.31.15/src/mostlyright/data_harness/key_seam.py +7 -0
  11. mostlyright_data-0.31.15/src/mostlyright/data_harness/session_probes.py +324 -0
  12. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/table_manifest.py +0 -371
  13. mostlyright_data-0.31.15/src/mostlyright/data_harness/thin/__init__.py +34 -0
  14. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/enrichment.py +23 -10
  15. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/probe.py +5 -8
  16. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/recipe.py +2 -2
  17. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/research.py +8 -247
  18. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/router.py +1 -33
  19. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/runs.py +2 -6
  20. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/session.py +25 -22
  21. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/support.py +32 -8
  22. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/table_search_contract.json +8 -2
  23. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/transport.py +7 -9
  24. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/v4.py +3 -4
  25. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/v4_artifacts.py +5 -5
  26. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/v4_datasets.py +23 -12
  27. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/v4_narrative.py +369 -30
  28. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/v4_query.py +93 -6
  29. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/v4_reader.py +26 -0
  30. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/v4_search.py +3 -1
  31. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/vocabulary.py +0 -99
  32. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/ux/attendance.py +0 -11
  33. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/ux/clarification.py +3 -3
  34. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/ux/cloud_auth.py +1 -8
  35. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/ux/credentials.py +0 -78
  36. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/ux/login.py +6 -26
  37. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/ux/path_kind.py +14 -37
  38. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/ux/remediation.py +14 -24
  39. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/ux/render.py +5 -91
  40. mostlyright_data-0.31.13/src/mostlyright/data_harness/formats.py +0 -411
  41. mostlyright_data-0.31.13/src/mostlyright/data_harness/hosted_crawler_protocol.py +0 -115
  42. mostlyright_data-0.31.13/src/mostlyright/data_harness/key_seam.py +0 -353
  43. mostlyright_data-0.31.13/src/mostlyright/data_harness/session_probes.py +0 -722
  44. mostlyright_data-0.31.13/src/mostlyright/data_harness/thin/__init__.py +0 -58
  45. mostlyright_data-0.31.13/src/mostlyright/data_harness/thin/acquire.py +0 -1146
  46. mostlyright_data-0.31.13/src/mostlyright/data_harness/thin/acquire_cancel.py +0 -579
  47. mostlyright_data-0.31.13/src/mostlyright/data_harness/thin/approvals.py +0 -931
  48. mostlyright_data-0.31.13/src/mostlyright/data_harness/thin/commands.py +0 -428
  49. mostlyright_data-0.31.13/src/mostlyright/data_harness/thin/narrative.py +0 -727
  50. mostlyright_data-0.31.13/src/mostlyright/data_harness/thin/parity.py +0 -1082
  51. mostlyright_data-0.31.13/src/mostlyright/data_harness/thin/propose.py +0 -2877
  52. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/README.md +0 -0
  53. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/scripts/hatch_build.py +0 -0
  54. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/SKILL.md +0 -0
  55. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/agents/openai.yaml +0 -0
  56. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/references/1-open-the-page-and-the-link-to-it-in-the-first-message.md +0 -0
  57. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/references/2-brief-two-to-four-questions-each-with-a-recommended-answer.md +0 -0
  58. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/references/3-probe-read-a-source-before-committing-to-it.md +0 -0
  59. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/references/4-decide-say-what-you-chose-what-you-refused-and-ask-one-question.md +0 -0
  60. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/references/5-draft-one-recipe-document-one-call.md +0 -0
  61. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/references/6-build-one-run-sized-to-acquire-every-measured-source-whole.md +0 -0
  62. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/references/7-interrogate-ask-the-run-what-it-actually-delivered.md +0 -0
  63. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/references/8-fix-revise-the-document-and-register-it-again.md +0 -0
  64. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/references/9-present-only-what-survived-inspection-with-caveats.md +0 -0
  65. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/references/agent-protocol.md +0 -0
  66. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/references/autonomous-delivery.md +0 -0
  67. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/references/before-the-first-tool-call.md +0 -0
  68. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/references/boundaries.md +0 -0
  69. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/references/cloud-authentication-preflight.md +0 -0
  70. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/references/cross-repository-protocol-reference.md +0 -0
  71. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/references/installation-parity.md +0 -0
  72. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/references/live-run.md +0 -0
  73. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/references/making-a-table-incremental.md +0 -0
  74. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/references/narrating-the-run.md +0 -0
  75. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/references/not-hosted-yet.md +0 -0
  76. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/references/one-install.md +0 -0
  77. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/references/prediction-labels.md +0 -0
  78. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/references/preparing-table-search.md +0 -0
  79. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/references/promote.md +0 -0
  80. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/references/receipts.md +0 -0
  81. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/references/recipe-test.md +0 -0
  82. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/references/recording-a-stream-venue.md +0 -0
  83. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/references/recovering-an-import-failure.md +0 -0
  84. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/references/reference-pages.md +0 -0
  85. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/references/required-protocol.md +0 -0
  86. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/references/the-one-thing-to-say-about-the-skill-itself.md +0 -0
  87. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/references/transforms.md +0 -0
  88. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/references/user-communication-contract.md +0 -0
  89. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/references/writing-a-decision-record.md +0 -0
  90. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/skills/mr-data-build/scripts/write_research_notebook.py +0 -0
  91. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/__init__.py +0 -0
  92. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/agent_protocol.py +0 -0
  93. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/canonical.py +0 -0
  94. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/page_coverage.py +0 -0
  95. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/part_check_evidence.py +0 -0
  96. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/skill_assets.py +0 -0
  97. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/activity.py +0 -0
  98. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/backoff.py +0 -0
  99. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/categories.py +0 -0
  100. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/dataset-categories-v1.json +0 -0
  101. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/delivery.py +0 -0
  102. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/description_shape.py +0 -0
  103. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/download.py +0 -0
  104. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/fast_features.py +0 -0
  105. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/matching_benchmark.py +0 -0
  106. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/progress_rate.py +0 -0
  107. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/progress_vocabulary.py +0 -0
  108. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/recipe_brief.py +0 -0
  109. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/recipe_explain.py +0 -0
  110. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/recipe_forecast.py +0 -0
  111. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/recipe_lint.py +0 -0
  112. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/recipe_test.py +0 -0
  113. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/refresh_rehearsal.py +0 -0
  114. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/release_check.py +0 -0
  115. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/run_diagnose.py +0 -0
  116. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/run_prefix.py +0 -0
  117. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/stream.py +0 -0
  118. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/stream_venue.py +0 -0
  119. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/studio_capabilities.py +0 -0
  120. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/table_view.py +0 -0
  121. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/user_agent.py +0 -0
  122. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/v4_catalog.py +0 -0
  123. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/v4_connected.py +0 -0
  124. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/v4_connections.py +0 -0
  125. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/v4_dataset_covers.py +0 -0
  126. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/v4_handoff.py +0 -0
  127. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/v4_matching.py +0 -0
  128. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/v4_public.py +0 -0
  129. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/v4_runs.py +0 -0
  130. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/v4_search_contract.py +0 -0
  131. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/v4_secrets.py +0 -0
  132. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/v4_stream.py +0 -0
  133. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/thin/v4_tables.py +0 -0
  134. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/ux/__init__.py +0 -0
  135. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/ux/commands/__init__.py +0 -0
  136. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/ux/commands/auth.py +0 -0
  137. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/ux/commands/clarify.py +0 -0
  138. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/ux/commands/login.py +0 -0
  139. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/ux/commands/whoami.py +0 -0
  140. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/ux/credential_native.py +0 -0
  141. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/ux/credential_store.py +0 -0
  142. {mostlyright_data-0.31.13 → mostlyright_data-0.31.15}/src/mostlyright/data_harness/ux/plain_file.py +0 -0
@@ -23,3 +23,6 @@ build/
23
23
  # Recorded as issue #311; ignored here so the window cannot cost anybody a rewritten branch in
24
24
  # the meantime.
25
25
  .mostlyright-performance-*/
26
+
27
+ # A local upload record. Nothing in the repository reads it.
28
+ uploaded_snapshots.json
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mostlyright-data
3
- Version: 0.31.13
3
+ Version: 0.31.15
4
4
  Summary: Mostly Right hosted CLI for reviewed datasets
5
5
  Project-URL: Homepage, https://mostlyright.md/
6
6
  Project-URL: Documentation, https://mostlyright.md/docs/guides/cli/
@@ -9,7 +9,6 @@ Provides-Extra: build
9
9
  Requires-Dist: hatch-vcs==0.5.0; extra == 'build'
10
10
  Requires-Dist: hatchling==1.28.0; extra == 'build'
11
11
  Requires-Dist: setuptools-scm==10.3.4; extra == 'build'
12
- Requires-Dist: uv-build==0.11.3; extra == 'build'
13
12
  Requires-Dist: vcs-versioning==2.6.0; extra == 'build'
14
13
  Description-Content-Type: text/markdown
15
14
 
@@ -22,16 +22,13 @@ build = [
22
22
  "hatch-vcs==0.5.0",
23
23
  "hatchling==1.28.0",
24
24
  "setuptools-scm==10.3.4",
25
- "uv-build==0.11.3",
26
25
  "vcs-versioning==2.6.0",
27
26
  ]
28
27
 
29
28
  [dependency-groups]
30
29
  dev = [
31
- "cmarkgfm>=2025.10.22",
32
30
  "jsonschema[format]>=4.23,<5",
33
31
  "pytest>=8.3",
34
- "pytest-xdist>=3.6",
35
32
  # Test-only, and only for `tests/test_thin_v4_contract.py`'s cross-check of its hand-written
36
33
  # OpenAPI scan against a real parser. It never enters the distribution, whose runtime
37
34
  # dependency list is empty; the guard it unblocks was unreachable in every configuration
@@ -60,8 +57,8 @@ cache-keys = [{ file = "pyproject.toml" }, { git = { commit = true, tags = true
60
57
  source = "vcs"
61
58
 
62
59
  # Only `v<digits>` tags are releases. A commit after the last one builds as that release's
63
- # version, as a checkout between releases always has: `mr-data propose` records the version as
64
- # plain X.Y.Z and refuses anything else. A tree without git history builds as 0.0.0.
60
+ # version, as a checkout between releases always has: the published CLI reports plain X.Y.Z
61
+ # and refuses a local version suffix. A tree without git history builds as 0.0.0.
65
62
  [tool.hatch.version.raw-options]
66
63
  tag_regex = "^v(?P<version>[0-9]+(?:\\.[0-9]+)*(?:(?:a|b|rc)[0-9]+)?)$"
67
64
  version_scheme = "only-version"
@@ -77,8 +74,6 @@ only-include = [
77
74
  "src/mostlyright/data_harness/__init__.py",
78
75
  "src/mostlyright/data_harness/agent_protocol.py",
79
76
  "src/mostlyright/data_harness/canonical.py",
80
- "src/mostlyright/data_harness/formats.py",
81
- "src/mostlyright/data_harness/hosted_crawler_protocol.py",
82
77
  "src/mostlyright/data_harness/key_seam.py",
83
78
  "src/mostlyright/data_harness/page_coverage.py",
84
79
  "src/mostlyright/data_harness/part_check_evidence.py",
@@ -115,8 +110,6 @@ only-include = [
115
110
  "src/mostlyright/data_harness/__init__.py",
116
111
  "src/mostlyright/data_harness/agent_protocol.py",
117
112
  "src/mostlyright/data_harness/canonical.py",
118
- "src/mostlyright/data_harness/formats.py",
119
- "src/mostlyright/data_harness/hosted_crawler_protocol.py",
120
113
  "src/mostlyright/data_harness/key_seam.py",
121
114
  "src/mostlyright/data_harness/page_coverage.py",
122
115
  "src/mostlyright/data_harness/part_check_evidence.py",
@@ -17,7 +17,7 @@ run in full.
17
17
  | `mr-data clarify` | Check whether clarification is allowed. Use `--attended` for an active user chat and `--unattended` for a scheduled invocation; an explicit operator veto such as `MOSTLYRIGHT_ATTENDED=0` still wins. A non-TTY subprocess does not prove the user is absent. The command does not ask the person in chat or wait for a reply; the agent must do that. It exits non-zero when nobody can answer or the recipe is already registered. |
18
18
  | `mr-data probe` | `probe SOURCE_ID QUESTION_ID --dataset DATASET_ID [--kind source_inspect\|sample_rows\|profile_columns\|evaluate_expression]` asks one already-registered source one question and prints the answer. **It rides the frozen `/v3/sessions` routes, which a deployment may have switched off, so do not plan a source inspection around it.** Both positionals are identifiers. `QUESTION_ID` is a question identifier, which no v4 registration receipt returns. The v4 way to look at a source before registering it is `mr-data source inspect`, in the next row. The other way to read one is a bounded run of a scratch table, never of the real table, as [the probe rule](3-probe-read-a-source-before-committing-to-it.md#the-probe-rule-test-on-a-scratch-table-never-on-the-real-table) says. |
19
19
  | `mr-data source` | `source inspect` takes a bounded look at one source, and it is the v4 path where `probe` is not. [Stage 3](3-probe-read-a-source-before-committing-to-it.md) says when to use it. It starts one of three ways, and each prints the `session_id`, `probe_id` and `source_id`, plus the `dataset_id` and `question_id` when it has them. For a new public HTTPS CSV that needs no key, give `--dataset-id`, `--question`, `--source-name`, `--source-url`, `--claimed-basis` and `--claim-evidence-digest`: it prepares the source and opens a session. For a source already prepared, give `--dataset-id`, `--question-id` and `--source-id`, which opens a session. In a session you already hold, give `--session-id` with `--source-id`. `--context-source-id` adds a source to a session it opens. `--session-id` with `--probe-id` reads the answer back. A look is bounded to 65,536 bytes, 1,000 rows and 300 seconds. `queued` and `truncated` are not complete answers, and `capability_unavailable` means this deployment cannot inspect, so read the source by a bounded run of a scratch table instead, as [the probe rule](3-probe-read-a-source-before-committing-to-it.md#the-probe-rule-test-on-a-scratch-table-never-on-the-real-table) says. What it finds is exploratory evidence, not a run and not a receipt. |
20
- | `mr-data reader` | `reader normalize --family-id ID --family-version VERSION --options-file FILE [--workspace-id ID]` asks Studio's Reader service to apply one certified family's own defaults and option rules to a JSON object of options, at most 64 KiB, and prints the normalized `decode_options` and `decode_options_json`. The second is the text a recipe carries as `reader.decode_options`, pinned as [Readers](readers.md) describes. It changes nothing, and this client does not validate or invent a family's options: Studio decides. Run it for every Reader pin before you register, so a wrong option is refused here and not inside a run. |
20
+ | `mr-data reader` | `reader normalize --family-id ID --family-version VERSION --options-file FILE [--workspace-id ID]` asks Studio's Reader service to apply one certified family's own defaults and option rules to a JSON object of options, at most 64 KiB, and prints the normalized `decode_options`, `decode_options_json` and `options_digest`. The second is the text a recipe carries as `reader.decode_options`, and the third is the `reader.options_digest` registration accepts for exactly those options, pinned as [Readers](readers.md) describes. It changes nothing, and this client does not validate or invent a family's options: Studio decides. Run it for every Reader pin before you register, so a wrong option is refused here and not inside a run. |
21
21
  | `mr-data catalog` | `catalog search "QUESTION"` asks the sealed public-source catalogue which of its entries might answer a question and ranks them best first. Every ranked entry comes back with the disposition its own facts earned — `admitted`, `human_escalation_required` or `refused` — because an entry the catalogue could not vouch for is still a finding. `--format csv` states the one data format the question requires — one token per question, never repeated — and it is not a filter: an entry that does not declare that format still comes back ranked, with disposition `refused` and `filters_match` false, so nothing is held back; `--limit N` ranks at most N, up to 25. It fetches nothing and registers nothing. The catalogue holds one provider (Data.gov) and only part of it, so it is never exhaustive and an empty answer is not evidence that no such source exists. When the answer is `catalog_unavailable`, this deployment has no catalogue to search: record the lane and carry on. |
22
22
  | `mr-data public` | Read Mostly Right's public dataset catalogue. `public search "QUERY"` ranks published datasets (`--topic`, `--limit` and `--cursor` narrow and page it), `show SLUG` reads one overview, `tables SLUG` lists its table identifiers, `schema TABLE_ID` reads one table's schema, `sample TABLE_ID` prints its published preview rows, `lookup "QUERY"` is the connector search shape and `fetch SLUG` returns the dataset's Markdown document. Those seven need no login. `query TABLE_ID`, with `--body` or `--body-file`, and `download-url TABLE_ID` do need `mr-data login`: they ask Cloud, with the device key, to run one query over a public table and to say how it can be downloaded. Preview rows are not a query, and no table bytes pass through the command. |
23
23
  | `mr-data connected` | `connected list` shows the public datasets connected to this workspace and `connected add SLUG` connects one by its slug. It needs `mr-data login`: both ask Cloud, with the device key, over the routes MCP's `list_connected_datasets` and `connect_dataset` use. |
@@ -12,7 +12,7 @@ whether each is served here, read from Studio's platform credential listing.
12
12
 
13
13
  | Task | What it does | Binding |
14
14
  | --- | --- | --- |
15
- | classify | Labels each row from a text column with yes/no or choice questions: a topic, a category, a sentiment, a flag no keyword rule decides. Each answer carries a probability per label. | `classify` (Clef, self-hosted) first; `openrouter-decisions` (TypeSafe's Jev) answers the same questions |
15
+ | classify | Labels each row from a text column with yes/no or choice questions: a topic, a category, a sentiment, a flag no keyword rule decides. Each answer carries a probability per label. | `gemini-decisions` (Mostly Right Classify: Gemini Decision 1) first; `classify` (Clef, self-hosted) and `openrouter-decisions` (TypeSafe's Jev) answer the same questions |
16
16
  | extract | Pulls named fields (names, amounts, dates, places) out of page or document text into columns. Every value appears verbatim in the input or is dropped. | `extract` (the extraction model, NuExtract-based) |
17
17
  | match | Links the same entity across tables or within one. | none yet: `planned` |
18
18
 
@@ -20,14 +20,19 @@ Each served binding comes with its route, its pinned `model`, its rate, today's
20
20
  and a `request_template`. Copy `origin`, `method`, `path_template` and `model` from the listing
21
21
  exactly, and write the same origin as the source's `connector.origin` and as the only entry of
22
22
  `pages.allowed_origins`. Clef's and the extraction model's origins are this deployment's own
23
- service addresses, which no one can guess: the platform credential is chosen by that route and pin, so a guessed origin or a model
24
- alias is refused at registration with `PLATFORM_CREDENTIAL_UNBOUND`. The person enrols no key.
23
+ service addresses, which no one can guess, and Mostly Right Classify's is Google's Gemini API.
24
+ The platform credential is chosen by that route and pin, so a guessed origin or a model alias is
25
+ refused at registration with `PLATFORM_CREDENTIAL_UNBOUND`. The person enrols no key.
25
26
  The person pays nothing for these calls. They count against the workspace's daily quota, which
26
- `mr-data recipe forecast` reports. Prefer `classify` over `openrouter-decisions` for new work:
27
- Mostly Right pays OpenRouter per Jev call, and Clef answers the same request body.
27
+ `mr-data recipe forecast` reports. Prefer `gemini-decisions` for new work: it answers a row in a
28
+ quarter of a second, has no cold start, and was the most accurate of the three on choice questions.
29
+ Keep `classify` and `openrouter-decisions` for recipes already written against them. Its ceiling is
30
+ Google's token rate, about 140 rows a second with one choice question per row and about 48 with forty
31
+ yes/no questions, so ask few questions per row (see below); a wider recipe is slowed by 429s.
28
32
 
29
33
  Each binding also comes with a `pages_template`: `request_timeout_seconds` 120 and `retries` 3.
30
- Write both into the collection's `pages`. Clef and the extraction model scale to zero when idle,
34
+ Write both into the collection's `pages`. They exist for Clef and the extraction model and cost
35
+ nothing on `gemini-decisions`. Clef and the extraction model scale to zero when idle,
31
36
  and their first instance takes three to five minutes to load. Studio starts loading it when the
32
37
  run is admitted, and until the service has answered once it spreads each member's attempts over
33
38
  six minutes rather than seconds. The longer timeout and the fourth attempt let the last one land
@@ -102,11 +107,12 @@ also keep the rows it settled from being sent at all: see [Needs Studio 4.14](#n
102
107
  A classify source is a [per-row request](sources.md#authoring-a-per-row-request) over the source
103
108
  that holds the text. Start from the listing's `request_template` and fill in:
104
109
 
105
- - `parameters` and the `{text_column}` placeholder in `state`: rename both to the upstream
110
+ - `parameters` and the `{text_column}` placeholder in `state` (`input` on `gemini-decisions`):
111
+ rename both to the upstream
106
112
  source's column that holds the text. The template's `text_column` and `id` are placeholders,
107
113
  and registration refuses a parameter or carried column the upstream does not have.
108
114
  - `questions`: one entry per column you want. A `choice` question names its labels as keys of
109
- `criteria` (1 to 64); include a "none fits" label so a row is never forced into a wrong one. A
115
+ `criteria` (1 to 64, or 2 to 255 on `gemini-decisions`); include a "none fits" label so a row is never forced into a wrong one. A
110
116
  `noul` question answers one statement true or false, and its `criteria` may describe only
111
117
  `true` and `false`. A `score` question rates the text on a list of 1 to 64 levels. Keep the
112
118
  instructions to one sentence about the text alone. `state` takes at most 65,536 characters.
@@ -121,6 +127,25 @@ The Reader reads each label's probability by JSON pointer, as the Jev example in
121
127
  table that publishes a model's label names the model pin in the column description and keeps the
122
128
  probability beside the label.
123
129
 
130
+ ### Writing a Mostly Right Classify source
131
+
132
+ `gemini-decisions` takes the same questions with these differences, and its `request_template`
133
+ already has them:
134
+
135
+ - The text goes in `input`, not `state`.
136
+ - Each label in `criteria` takes a string. Write `""` when the label says it all; `null` is refused.
137
+ - Question keys match `[A-Za-z0-9_-]{1,64}`, a choice question takes 2 to 255 labels, and a label has no
138
+ control or zero-width characters. Write a family emoji as its word (`family`), since its
139
+ joiners are refused.
140
+ - It takes `noul`, `choice` and `score` questions; only `choice` has been measured against Clef
141
+ and Jev.
142
+ - The answer carries no `id` and no `model`. Read the probabilities only, or declare `/id` and
143
+ `/model` `required: false`.
144
+
145
+ When a row gets several labels from one list (emoji, tags, genres), ask one `choice` question over
146
+ the whole list and keep the top three by probability, not one yes/no question per label. It costs
147
+ a third of the tokens and picks the same top three.
148
+
124
149
  ### Writing an extract source
125
150
 
126
151
  An extract source has the same per-row shape with the extraction body
@@ -225,8 +225,9 @@ for the days that can still change, through the two request `parameters` it rend
225
225
  unit reads its own page count, so size `limits.max_requests` from a measured unit.
226
226
  [Paging a keyed API in parallel](sources.md#paging-a-keyed-api-in-parallel) has the rules.
227
227
 
228
- `options_digest` is the SHA-256 of the canonical JSON of `decode_options`. Registration names it
229
- when the two disagree.
228
+ `options_digest` is the SHA-256 of the canonical JSON of `decode_options`, and
229
+ `mr-data reader normalize` prints it for the options it returns. Registration names the digest it
230
+ expected when the two disagree.
230
231
 
231
232
  ```json
232
233
  {
@@ -57,9 +57,17 @@ mr-data reader normalize --family-id json.tabular --family-version 1.1.0 \
57
57
 
58
58
  `options.json` holds the keys the source needs, at most 64 KiB. Studio applies the family's own
59
59
  defaults and option rules. The answer's `decode_options_json` is the text to write as
60
- `reader.decode_options`. A refusal arrives here, before any run is spent. Run it for every
60
+ `reader.decode_options`, and its `options_digest` is the `reader.options_digest` to pin beside it.
61
+ That digest binds the default-filled options the answer returns, not the subset in `options.json`,
62
+ so copy both together. A refusal arrives here, before any run is spent. Run it for every
61
63
  Reader pin before you register.
62
64
 
65
+ `normalize` checks the options against the family, not against the place the pin goes. A
66
+ Generic API `generic_api.response.reader` admits fewer coordinates: `json.tabular` `1.0.0`,
67
+ `1.1.0` or `1.2.0`, `delimited_text` `1.0.0` or `1.1.0`, and `parquet.tabular` `1.0.0`.
68
+ `json.tabular` `1.3.0` and `1.4.0` normalize but are refused there. The highest-version advice
69
+ below applies inside that set.
70
+
63
71
  A column that may be absent from a record must state `"required": false`. Publishers routinely omit
64
72
  a key rather than sending null, and a required column that is missing refuses the record.
65
73
 
@@ -87,6 +95,7 @@ decoder. Zero matches and multiple matches both refuse.
87
95
  | `archive.zip@1.0.0` | `member`; `member_format` (`csv` or `tsv`); optional `header: true`. |
88
96
  | `archive.zip@1.1.0` | Same, plus `member_format: semicolon` for publishers such as DWD. |
89
97
  | `archive.zip@1.2.0` | Same as `archive.zip@1.1.0`; also accepts a response served as `application/octet-stream`. |
98
+ | `archive.zip@4.0.0` | Exact safe `member`, `member_format: lines` and `encoding: utf-8 or cp1252`; no header. Streams the member's physical lines as line_number, raw_line, as `archive.tar@2.0.0` does for one member. |
90
99
  | `archive.gzip@1.0.0` | `member_format`; optional `header: true`. `member` is invalid. |
91
100
  | `archive.gzip@1.1.0` | Same; also accepts a response served as `application/octet-stream`. |
92
101
  | `archive.tar@1.0.0` | Same as `archive.zip@1.0.0`. |
@@ -181,7 +190,8 @@ Use `public.https.api@1.0.0` only when `keyless_window` is literal `true`. Other
181
190
  The new adapter uses the existing `generic_api.response` Reader contract. For Binance klines,
182
191
  state `format: json`, `records_pointer: ""`, and `reader.family_id: json.tabular` with
183
192
  `family_version: 1.0.0` (or the already admitted `1.1.0`). Pin `options_digest` to the SHA-256
184
- of the canonical decode options, rather than inserting a placeholder digest. These decode
193
+ of the canonical decode options, the `options_digest` `mr-data reader normalize` prints, rather
194
+ than inserting a placeholder digest. These decode
185
195
  options project a root JSON array of arrays, with RFC 6901 numeric indexes into each row:
186
196
 
187
197
  ```json
@@ -39,7 +39,8 @@ A [per-row request](sources.md#authoring-a-per-row-request) presents a key by it
39
39
  `request.auth` says. A saved connection cannot stand in for it.
40
40
  - `platform` presents a key Mostly Right holds, so the user enrols nothing.
41
41
 
42
- The platform key serves every binding `mr-data models --json` lists: Clef for classification,
42
+ The platform key serves every binding `mr-data models --json` lists: Mostly Right Classify
43
+ (Gemini Decision 1) and Clef for classification,
43
44
  the extraction model where it is served, and OpenRouter's decisions endpoint for TypeSafe's Jev
44
45
  decision model, pinned to `typesafe/jev-1.13`. Do not ask the user for a key to use any of them. A user who
45
46
  prefers their own key enrols it with `mr-data keys set`. The source then states
@@ -185,6 +185,8 @@ movie in an upstream `movies` source. It uses three labels. Its connector states
185
185
  `"adapter_id": "public.https.collection@2.0.0"`, `"credential_mode": "platform"`,
186
186
  `"origin": "https://openrouter.ai"` and a `json.tabular` Reader pin with `records_pointer` `""`.
187
187
  Its `limits.max_requests` is 4000, which reserves four attempts for each of up to 1000 requests.
188
+ The same source on `gemini-decisions` names Gemini's route and pin, puts the text in `input`
189
+ instead of `state`, and writes `""` for each label instead of `null`.
188
190
 
189
191
  ```json
190
192
  "collection": {
@@ -265,7 +267,9 @@ deploy.
265
267
 
266
268
  The platform credential needs no key from anyone, and any subscribed workspace may use it. Each
267
269
  binding is one route and one pinned model, and `mr-data models --json` lists the ones this
268
- deployment serves: Clef for classification (`classify`), TypeSafe's Jev through OpenRouter
270
+ deployment serves: Mostly Right Classify for classification (`gemini-decisions`,
271
+ `POST https://generativelanguage.googleapis.com/v1beta/decisions` with `/model` set to
272
+ `gemini-decision-1`), Clef (`classify`), TypeSafe's Jev through OpenRouter
269
273
  (`openrouter-decisions`, `POST https://openrouter.ai/api/alpha/decisions` with `/model` set to
270
274
  `typesafe/jev-1.13`) and, where it is served, the extraction model (`extract`). Pin the exact
271
275
  model the listing names. A floating alias such as `~typesafe/jev-latest` is refused at
@@ -335,6 +339,10 @@ to separate them. No per-row collection may derive its rows from a `closed` or `
335
339
  `pagination` is a `page` or `offset` walk with a required `parallel` member, in one of two forms.
336
340
  Prefer the counted form.
337
341
 
342
+ `@2.1.0` refuses `{"kind": "none", "max_pages": 1}`, and `cursor` and `link` walks too. For one
343
+ request, use `@2.0.0`. Use `authenticated.https.connector@3.0.0` instead when the request
344
+ declares a `per_call` cost, which `@2.0.0` does not admit.
345
+
338
346
  | Form | Members | Use it when |
339
347
  | --- | --- | --- |
340
348
  | counted | `total_pages_pointer`, `max_page_bytes`, `min_interval_milliseconds`, optional `concurrency` | the first page states how many pages exist. A `page` walk over a `json` response only |
@@ -0,0 +1,7 @@
1
+ """The environment variable holding the legacy shared API key.
2
+
3
+ The name matches Cloud's ``LEGACY_API_KEY_ENV`` in ``api-key.ts``: one secret, one variable, on
4
+ both the sending and the receiving side.
5
+ """
6
+
7
+ LEGACY_API_KEY_ENV = "MOSTLYRIGHT_API_KEY"
@@ -0,0 +1,324 @@
1
+ """The probe vocabulary a research session speaks (ADR 0021).
2
+
3
+ Studio owns the probe *kind* enum and nothing else about a probe. Its contract says so in as many
4
+ words: a probe request and a probe result are "opaque to Studio", size-bounded, digested, and
5
+ stored uninterpreted, "so the harness can add a probe parameter or a result field without a Studio
6
+ contract change". This module is the other half of that arrangement -- the place where the bodies
7
+ under those four kinds are actually specified, so that "opaque to Studio" does not degrade into
8
+ "unspecified anywhere".
9
+
10
+ **Why the kind enum is not restated as a choice.** ``research-session.schema.json`` closes
11
+ ``probe_kind`` to four values. Restating them here as a *harness* decision would invite the two
12
+ spellings to drift; :data:`PROBE_KINDS` is therefore the same four, and
13
+ ``tests/test_thin_research.py`` asserts it equals the contract's own ``probe_kind`` enum. What
14
+ this repository decides is the body, and only the body.
15
+
16
+ **Why every request names a source.** All four kinds carry ``source_id``, including
17
+ ``evaluate_expression``. It costs one field and buys two things. Probe progress can then be emitted
18
+ as the ``source_probe_started`` / ``source_probe_settled`` pair -- which travel as Studio's
19
+ ``attempt_progress`` and ``source_probe_completed`` event types, exactly the two the
20
+ research-session design names -- without mislabelling a probe id as a source id. And the session's
21
+ ``context.source_ids`` becomes an enforceable allowlist: a probe that names a source the session
22
+ was not opened against is refused before anything is read, which is the whole of a probe's
23
+ authority check.
24
+
25
+ **Why expressions are an AST and never a string.** ``evaluate_expression`` is the one kind a caller
26
+ could reasonably expect to accept a little language. It does not. The request carries a closed,
27
+ bounded, non-recursive-by-construction operator tree; there is no parser, no ``eval``, no
28
+ comprehension over caller text, and no operator whose cost is superlinear in anything the caller
29
+ controls. A probe body arrives from Studio having been stored uninterpreted, which means it arrives
30
+ with exactly as much trust as the client that submitted it -- that is to say, none.
31
+ """
32
+
33
+ from __future__ import annotations
34
+
35
+ import math
36
+ from collections.abc import Mapping
37
+ from typing import Any, Final
38
+
39
+ from mostlyright.data_harness.canonical import canonical_json_bytes
40
+
41
+ #: The vocabulary's own version, carried on every result body. It is not Studio's
42
+ #: ``schema_version``: Studio versions the envelope, this versions what the harness puts inside it,
43
+ #: and the point of the arrangement is that this number can move without Studio moving.
44
+ PROBE_SCHEMA_VERSION: Final = "mr-session-probes.v1"
45
+
46
+ #: Studio's closed enum, restated so this module loads without the generated client, and asserted
47
+ #: equal to it by the test suite.
48
+ PROBE_KINDS: Final[tuple[str, ...]] = (
49
+ "source_inspect",
50
+ "sample_rows",
51
+ "profile_columns",
52
+ "evaluate_expression",
53
+ )
54
+
55
+ #: Studio's own bounds on the two opaque bodies, restated because the worker must refuse an
56
+ #: oversized result *before* spending a request on it. Studio enforces these too; a worker that
57
+ #: relied on that alone would learn about the ceiling by being rejected, after the work.
58
+ PROBE_REQUEST_MAX_BYTES: Final = 64 * 1024
59
+ PROBE_RESULT_MAX_BYTES: Final = 256 * 1024
60
+
61
+ #: How many rows any probe may pull back, and how many any probe may look at. The first bounds the
62
+ #: answer, the second bounds the work: a profile over a million rows is not an interactive probe.
63
+ MAX_SAMPLE_ROWS: Final = 200
64
+ MAX_SCAN_ROWS: Final = 50_000
65
+ DEFAULT_SCAN_ROWS: Final = 10_000
66
+ #: A cell is rendered as a short token or a number. A probe answer is a preview, not an export, so
67
+ #: a long string is truncated in the answer rather than the answer being refused.
68
+ MAX_CELL_CHARS: Final = 512
69
+ MAX_PROFILE_COLUMNS: Final = 256
70
+ #: Expression trees are bounded twice: by depth, so nesting cannot be used to build a large tree
71
+ #: from a small body, and by operand count at each node.
72
+ MAX_EXPRESSION_DEPTH: Final = 8
73
+ MAX_EXPRESSION_OPERANDS: Final = 16
74
+
75
+ #: The aggregate an ``evaluate_expression`` probe may compute. Closed, and every member is one
76
+ #: pass over at most ``MAX_SCAN_ROWS`` values.
77
+ AGGREGATES: Final[tuple[str, ...]] = ("count", "sum", "min", "max", "avg")
78
+
79
+ #: The predicate operators a filter may use. Closed, and every member is one comparison between one
80
+ #: cell and one caller literal. Nothing here matches, searches, or concatenates.
81
+ COMPARISONS: Final[tuple[str, ...]] = ("eq", "ne", "lt", "le", "gt", "ge")
82
+ UNARY_TESTS: Final[tuple[str, ...]] = ("is_null", "is_not_null")
83
+ CONNECTIVES: Final[tuple[str, ...]] = ("and", "or", "not")
84
+
85
+
86
+ class ProbeVocabularyError(ValueError):
87
+ """A probe body that is not in the vocabulary. Carries the code the probe fails with."""
88
+
89
+ def __init__(self, code: str, detail: str) -> None:
90
+ super().__init__(f"{code}: {detail}")
91
+ self.code = code
92
+ self.detail = detail
93
+
94
+
95
+ # ------------------------------------------------------------------------------------------
96
+ # Runtime validation. Hand written, total, and refusing rather than coercing.
97
+ # ------------------------------------------------------------------------------------------
98
+
99
+
100
+ def _require(condition: bool, code: str, detail: str) -> None:
101
+ if not condition:
102
+ raise ProbeVocabularyError(code, detail)
103
+
104
+
105
+ def _object(value: Any, label: str) -> dict[str, Any]:
106
+ _require(
107
+ isinstance(value, dict) and all(isinstance(key, str) for key in value),
108
+ "PROBE_REQUEST_INVALID",
109
+ f"{label} must be an object with string keys",
110
+ )
111
+ return dict(value)
112
+
113
+
114
+ def _exact_keys(value: Mapping[str, Any], required: set[str], optional: set[str]) -> None:
115
+ present = set(value)
116
+ missing = sorted(required - present)
117
+ _require(not missing, "PROBE_REQUEST_INVALID", f"missing field(s): {', '.join(missing)}")
118
+ unknown = sorted(present - required - optional)
119
+ _require(not unknown, "PROBE_REQUEST_INVALID", f"unknown field(s): {', '.join(unknown)}")
120
+
121
+
122
+ def _uuid_text(value: Any, label: str) -> str:
123
+ _require(isinstance(value, str), "PROBE_REQUEST_INVALID", f"{label} must be a string")
124
+ text = str(value)
125
+ parts = text.split("-")
126
+ shape = [8, 4, 4, 4, 12]
127
+ ok = len(parts) == 5 and all(
128
+ len(part) == width and all(character in "0123456789abcdef" for character in part)
129
+ for part, width in zip(parts, shape, strict=True)
130
+ )
131
+ _require(ok, "PROBE_REQUEST_INVALID", f"{label} must be a lowercase UUID")
132
+ return text
133
+
134
+
135
+ def _bounded_int(value: Any, label: str, *, minimum: int, maximum: int) -> int:
136
+ # `type(...) is int` rather than isinstance: bool is a subclass of int, and a caller that sent
137
+ # `true` for a row limit made a mistake that must surface as one.
138
+ _require(type(value) is int, "PROBE_REQUEST_INVALID", f"{label} must be an integer")
139
+ _require(
140
+ minimum <= value <= maximum,
141
+ "PROBE_REQUEST_INVALID",
142
+ f"{label} must be in [{minimum}, {maximum}]",
143
+ )
144
+ return int(value)
145
+
146
+
147
+ def _column_name(value: Any, label: str) -> str:
148
+ _require(
149
+ isinstance(value, str) and 1 <= len(value) <= 256,
150
+ "PROBE_REQUEST_INVALID",
151
+ f"{label} must be a string of 1..256 characters",
152
+ )
153
+ return str(value)
154
+
155
+
156
+ def _column_list(value: Any, label: str) -> tuple[str, ...]:
157
+ _require(isinstance(value, list), "PROBE_REQUEST_INVALID", f"{label} must be an array")
158
+ _require(
159
+ 1 <= len(value) <= MAX_PROFILE_COLUMNS,
160
+ "PROBE_REQUEST_INVALID",
161
+ f"{label} must name between 1 and {MAX_PROFILE_COLUMNS} columns",
162
+ )
163
+ names = tuple(_column_name(item, f"{label} entry") for item in value)
164
+ _require(len(set(names)) == len(names), "PROBE_REQUEST_INVALID", f"{label} repeats a column")
165
+ return names
166
+
167
+
168
+ def _scalar(value: Any, label: str) -> Any:
169
+ if value is None or isinstance(value, bool):
170
+ return value
171
+ if isinstance(value, str):
172
+ _require(
173
+ len(value) <= MAX_CELL_CHARS,
174
+ "PROBE_REQUEST_INVALID",
175
+ f"{label} exceeds {MAX_CELL_CHARS} characters",
176
+ )
177
+ return value
178
+ if type(value) in {int, float}:
179
+ _require(
180
+ not isinstance(value, float) or math.isfinite(value),
181
+ "PROBE_REQUEST_INVALID",
182
+ f"{label} must be a finite number",
183
+ )
184
+ return value
185
+ raise ProbeVocabularyError("PROBE_REQUEST_INVALID", f"{label} is not an admitted literal")
186
+
187
+
188
+ def _predicate(value: Any, *, depth: int) -> dict[str, Any]:
189
+ _require(
190
+ depth <= MAX_EXPRESSION_DEPTH,
191
+ "PROBE_EXPRESSION_TOO_DEEP",
192
+ f"predicate nests deeper than {MAX_EXPRESSION_DEPTH}",
193
+ )
194
+ node = _object(value, "predicate")
195
+ operator = node.get("op")
196
+ _require(isinstance(operator, str), "PROBE_REQUEST_INVALID", "predicate op must be a string")
197
+ if operator in COMPARISONS:
198
+ _exact_keys(node, {"op", "column", "value"}, set())
199
+ return {
200
+ "op": operator,
201
+ "column": _column_name(node["column"], "predicate column"),
202
+ "value": _scalar(node["value"], "predicate value"),
203
+ }
204
+ if operator in UNARY_TESTS:
205
+ _exact_keys(node, {"op", "column"}, set())
206
+ return {"op": operator, "column": _column_name(node["column"], "predicate column")}
207
+ if operator in {"and", "or"}:
208
+ _exact_keys(node, {"op", "operands"}, set())
209
+ operands = node["operands"]
210
+ _require(
211
+ isinstance(operands, list) and 1 <= len(operands) <= MAX_EXPRESSION_OPERANDS,
212
+ "PROBE_REQUEST_INVALID",
213
+ f"{operator} takes 1..{MAX_EXPRESSION_OPERANDS} operands",
214
+ )
215
+ return {
216
+ "op": operator,
217
+ "operands": [_predicate(item, depth=depth + 1) for item in operands],
218
+ }
219
+ if operator == "not":
220
+ _exact_keys(node, {"op", "operand"}, set())
221
+ return {"op": "not", "operand": _predicate(node["operand"], depth=depth + 1)}
222
+ raise ProbeVocabularyError(
223
+ "PROBE_REQUEST_INVALID", f"predicate op {operator!r} is not admitted"
224
+ )
225
+
226
+
227
+ def probe_kind(value: Any) -> str:
228
+ """Admit one Studio probe kind, or refuse with the code the probe fails under."""
229
+
230
+ _require(
231
+ isinstance(value, str) and value in PROBE_KINDS,
232
+ "PROBE_KIND_UNSUPPORTED",
233
+ f"probe kind {value!r} is not in the vocabulary",
234
+ )
235
+ return str(value)
236
+
237
+
238
+ def validate_probe_request(kind: str, request: Any) -> dict[str, Any]:
239
+ """Admit one probe request body and return it normalized, with defaults filled in.
240
+
241
+ Normalizing here rather than at each use is deliberate: the executor should never see an
242
+ absent ``scan_rows`` and choose a default of its own, because two executors choosing two
243
+ defaults is how a probe stops being reproducible.
244
+ """
245
+
246
+ kind = probe_kind(kind)
247
+ body = _object(request, "probe request")
248
+ encoded = canonical_json_bytes(body)
249
+ _require(
250
+ len(encoded) <= PROBE_REQUEST_MAX_BYTES,
251
+ "PROBE_REQUEST_TOO_LARGE",
252
+ f"probe request is {len(encoded)} canonical bytes, over {PROBE_REQUEST_MAX_BYTES}",
253
+ )
254
+ if kind == "source_inspect":
255
+ _exact_keys(body, {"source_id"}, {"scan_rows"})
256
+ return {
257
+ "source_id": _uuid_text(body["source_id"], "source_id"),
258
+ "scan_rows": _bounded_int(
259
+ body.get("scan_rows", DEFAULT_SCAN_ROWS),
260
+ "scan_rows",
261
+ minimum=1,
262
+ maximum=MAX_SCAN_ROWS,
263
+ ),
264
+ }
265
+ if kind == "sample_rows":
266
+ _exact_keys(body, {"source_id", "limit"}, {"offset", "columns"})
267
+ normalized: dict[str, Any] = {
268
+ "source_id": _uuid_text(body["source_id"], "source_id"),
269
+ "limit": _bounded_int(body["limit"], "limit", minimum=1, maximum=MAX_SAMPLE_ROWS),
270
+ "offset": _bounded_int(
271
+ body.get("offset", 0), "offset", minimum=0, maximum=MAX_SCAN_ROWS
272
+ ),
273
+ }
274
+ if "columns" in body:
275
+ normalized["columns"] = list(_column_list(body["columns"], "columns"))
276
+ return normalized
277
+ if kind == "profile_columns":
278
+ _exact_keys(body, {"source_id"}, {"scan_rows", "columns"})
279
+ profiled: dict[str, Any] = {
280
+ "source_id": _uuid_text(body["source_id"], "source_id"),
281
+ "scan_rows": _bounded_int(
282
+ body.get("scan_rows", DEFAULT_SCAN_ROWS),
283
+ "scan_rows",
284
+ minimum=1,
285
+ maximum=MAX_SCAN_ROWS,
286
+ ),
287
+ }
288
+ if "columns" in body:
289
+ profiled["columns"] = list(_column_list(body["columns"], "columns"))
290
+ return profiled
291
+ _exact_keys(body, {"source_id", "expression"}, {"scan_rows"})
292
+ expression = _object(body["expression"], "expression")
293
+ _exact_keys(expression, {"aggregate"}, {"column", "where"})
294
+ aggregate = expression["aggregate"]
295
+ _require(
296
+ isinstance(aggregate, str) and aggregate in AGGREGATES,
297
+ "PROBE_REQUEST_INVALID",
298
+ f"aggregate {aggregate!r} is not admitted",
299
+ )
300
+ normalized_expression: dict[str, Any] = {"aggregate": str(aggregate)}
301
+ if aggregate == "count":
302
+ # `count` over a column would silently mean one of two different things -- rows, or
303
+ # non-null values in that column -- so it takes no column at all and always means rows.
304
+ _require(
305
+ "column" not in expression,
306
+ "PROBE_REQUEST_INVALID",
307
+ "count takes no column; it counts matched rows",
308
+ )
309
+ else:
310
+ _require(
311
+ "column" in expression,
312
+ "PROBE_REQUEST_INVALID",
313
+ f"{aggregate} requires a column",
314
+ )
315
+ normalized_expression["column"] = _column_name(expression["column"], "expression column")
316
+ if "where" in expression:
317
+ normalized_expression["where"] = _predicate(expression["where"], depth=1)
318
+ return {
319
+ "source_id": _uuid_text(body["source_id"], "source_id"),
320
+ "scan_rows": _bounded_int(
321
+ body.get("scan_rows", DEFAULT_SCAN_ROWS), "scan_rows", minimum=1, maximum=MAX_SCAN_ROWS
322
+ ),
323
+ "expression": normalized_expression,
324
+ }