mostlyright-data 0.31.46__tar.gz → 0.31.48__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 (133) hide show
  1. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/PKG-INFO +1 -1
  2. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/SKILL.md +14 -6
  3. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/references/enriching-with-small-models.md +83 -16
  4. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/references/preparing-table-search.md +7 -2
  5. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/references/readers.md +6 -0
  6. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/references/sources.md +38 -5
  7. mostlyright_data-0.31.48/src/mostlyright/data_harness/__init__.py +113 -0
  8. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/skill_assets.py +16 -11
  9. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/activity.py +52 -7
  10. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/delivery.py +202 -67
  11. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/download.py +45 -12
  12. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/enrichment.py +222 -14
  13. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/recipe.py +12 -4
  14. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/recipe_explain.py +21 -6
  15. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/recipe_lint.py +71 -0
  16. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/recipe_test.py +22 -4
  17. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/refresh_rehearsal.py +11 -5
  18. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/release_check.py +5 -1
  19. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/router.py +380 -281
  20. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/runs.py +9 -6
  21. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/session.py +138 -17
  22. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/transport.py +328 -24
  23. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/user_agent.py +9 -7
  24. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/v4_artifacts.py +272 -75
  25. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/v4_query.py +3 -3
  26. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/v4_runs.py +4 -2
  27. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/v4_search.py +253 -8
  28. mostlyright_data-0.31.46/src/mostlyright/data_harness/__init__.py +0 -58
  29. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/.gitignore +0 -0
  30. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/README.md +0 -0
  31. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/pyproject.toml +0 -0
  32. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/scripts/hatch_build.py +0 -0
  33. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/agents/openai.yaml +0 -0
  34. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/references/1-open-the-page-and-the-link-to-it-in-the-first-message.md +0 -0
  35. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/references/2-brief-two-to-four-questions-each-with-a-recommended-answer.md +0 -0
  36. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/references/3-probe-read-a-source-before-committing-to-it.md +0 -0
  37. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/references/4-decide-say-what-you-chose-what-you-refused-and-ask-one-question.md +0 -0
  38. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/references/5-draft-one-recipe-document-one-call.md +0 -0
  39. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/references/6-build-one-run-sized-to-acquire-every-measured-source-whole.md +0 -0
  40. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/references/7-interrogate-ask-the-run-what-it-actually-delivered.md +0 -0
  41. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/references/8-fix-revise-the-document-and-register-it-again.md +0 -0
  42. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/references/9-present-only-what-survived-inspection-with-caveats.md +0 -0
  43. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/references/agent-protocol.md +0 -0
  44. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/references/autonomous-delivery.md +0 -0
  45. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/references/before-the-first-tool-call.md +0 -0
  46. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/references/boundaries.md +0 -0
  47. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/references/cloud-authentication-preflight.md +0 -0
  48. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/references/commands.md +0 -0
  49. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/references/live-run.md +0 -0
  50. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/references/making-a-table-incremental.md +0 -0
  51. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/references/narrating-the-run.md +0 -0
  52. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/references/not-hosted-yet.md +0 -0
  53. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/references/one-install.md +0 -0
  54. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/references/patterns.md +0 -0
  55. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/references/predicting-with-tabular-models.md +0 -0
  56. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/references/prediction-labels.md +0 -0
  57. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/references/promote.md +0 -0
  58. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/references/receipts.md +0 -0
  59. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/references/recipe-test.md +0 -0
  60. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/references/recording-a-stream-venue.md +0 -0
  61. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/references/recovering-an-import-failure.md +0 -0
  62. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/references/reference-pages.md +0 -0
  63. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/references/required-protocol.md +0 -0
  64. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/references/satellite-signals.md +0 -0
  65. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/references/source-credentials.md +0 -0
  66. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/references/the-one-thing-to-say-about-the-skill-itself.md +0 -0
  67. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/references/transforms.md +0 -0
  68. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/references/user-communication-contract.md +0 -0
  69. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/references/writing-a-decision-record.md +0 -0
  70. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/skills/mr-data-build/scripts/write_research_notebook.py +0 -0
  71. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/agent_protocol.py +0 -0
  72. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/canonical.py +0 -0
  73. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/key_seam.py +0 -0
  74. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/page_coverage.py +0 -0
  75. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/part_check_evidence.py +0 -0
  76. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/session_probes.py +0 -0
  77. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/table_manifest.py +0 -0
  78. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/__init__.py +0 -0
  79. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/backoff.py +0 -0
  80. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/categories.py +0 -0
  81. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/dataset-categories-v1.json +0 -0
  82. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/dataset_layout.py +0 -0
  83. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/description_shape.py +0 -0
  84. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/fast_features.py +0 -0
  85. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/matching_benchmark.py +0 -0
  86. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/probe.py +0 -0
  87. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/progress_rate.py +0 -0
  88. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/progress_vocabulary.py +0 -0
  89. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/recipe_brief.py +0 -0
  90. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/recipe_forecast.py +0 -0
  91. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/research.py +0 -0
  92. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/run_diagnose.py +0 -0
  93. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/run_prefix.py +0 -0
  94. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/stream.py +0 -0
  95. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/stream_venue.py +0 -0
  96. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/studio_capabilities.py +0 -0
  97. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/support.py +0 -0
  98. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/table_search_contract.json +0 -0
  99. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/table_view.py +0 -0
  100. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/v4.py +0 -0
  101. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/v4_catalog.py +0 -0
  102. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/v4_connected.py +0 -0
  103. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/v4_connections.py +0 -0
  104. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/v4_dataset_covers.py +0 -0
  105. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/v4_datasets.py +0 -0
  106. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/v4_handoff.py +0 -0
  107. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/v4_matching.py +0 -0
  108. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/v4_narrative.py +0 -0
  109. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/v4_public.py +0 -0
  110. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/v4_public_pull.py +0 -0
  111. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/v4_reader.py +0 -0
  112. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/v4_search_contract.py +0 -0
  113. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/v4_secrets.py +0 -0
  114. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/v4_stream.py +0 -0
  115. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/v4_tables.py +0 -0
  116. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/thin/vocabulary.py +0 -0
  117. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/ux/__init__.py +0 -0
  118. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/ux/attendance.py +0 -0
  119. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/ux/clarification.py +0 -0
  120. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/ux/cloud_auth.py +0 -0
  121. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/ux/commands/__init__.py +0 -0
  122. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/ux/commands/auth.py +0 -0
  123. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/ux/commands/clarify.py +0 -0
  124. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/ux/commands/login.py +0 -0
  125. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/ux/commands/whoami.py +0 -0
  126. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/ux/credential_native.py +0 -0
  127. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/ux/credential_store.py +0 -0
  128. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/ux/credentials.py +0 -0
  129. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/ux/login.py +0 -0
  130. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/ux/path_kind.py +0 -0
  131. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/ux/plain_file.py +0 -0
  132. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/ux/remediation.py +0 -0
  133. {mostlyright_data-0.31.46 → mostlyright_data-0.31.48}/src/mostlyright/data_harness/ux/render.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mostlyright-data
3
- Version: 0.31.46
3
+ Version: 0.31.48
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/
@@ -13,7 +13,7 @@ Act as the person's data scientist, not as an order taker. Most people know thei
13
13
  not know which dataset serves it. The request is the floor, never the ceiling. Work out the
14
14
  goal, then design the table a data scientist would want for it. Add the sources that explain
15
15
  or complete the requested one and join them. Derive what a rule can settle. Use the small
16
- models (classify, extract, match) for the judgement no rule can make. Use a prediction where a
16
+ models (classify, extract, standardize, match) for the judgement no rule can make. Use a prediction where a
17
17
  column is known for some rows and wanted for others. Where more data can be joined and then
18
18
  classified, plan all of it. Do not wait for the person to name a source, a column or a model.
19
19
  Recommend the fuller design in the brief, in the same question form, so it costs no extra turn.
@@ -189,10 +189,17 @@ step 6. The stage 3 reference holds its rule. Gate 4 is step 6.
189
189
  do not register or queue a recipe that omits it; report the capability limit and wait.
190
190
  Do not add search to existing recipes or rebuild existing datasets without an explicit request.
191
191
  Put the deterministic derivations found in step 4 into the first revision, and the joins
192
- step 4 allows. Add a classify
193
- or extract source when the brief asked for that judgement or the person accepted the offer,
192
+ step 4 allows. Add a classify,
193
+ extract, standardize or match source when the brief asked for that judgement or the person accepted the offer,
194
194
  from the binding `mr-data models` lists, and let a rule settle every row it can before the
195
195
  model reads the rest ([writing a classify source](references/enriching-with-small-models.md#writing-a-classify-source)).
196
+ When enriching rows from a table's website URL column across many third-party domains, fetch the
197
+ pages with `public.https.collection@2.0.0` (`source_rows` `url_column` +
198
+ `pages.allow_any_public_origin: true`) pinned to `html.web_extract@1.8.0`
199
+ (`mode: "readable_text"`), test bounded with `pages.max_fetches_per_run: 30` over the real
200
+ upstream source, and choose `classify` (`gemini-decisions`) for fixed categories, booleans, or
201
+ multilingual normalization versus `extract` for verbatim spans
202
+ ([heterogeneous public websites](references/sources.md#extracting-from-heterogeneous-public-websites-allow_any_public_origin)).
196
203
  Register a live predict table only after a backtest table has compared it with a baseline
197
204
  ([predicting with tabular models](references/predicting-with-tabular-models.md)).
198
205
  Put the predictions in the table people read, in their own `predicted_<target>` columns beside
@@ -417,8 +424,9 @@ chat, and pass on its answer.
417
424
  the observed version as [search preparation](references/preparing-table-search.md) describes.
418
425
  Search preparation runs independently: pending or failed indexing never means the data build
419
426
  failed, and declared metadata alone never proves observed search quality. Before delivery,
420
- run a battery of at least 40 queries the table's users would type through `search explain`
421
- and fix every miss in the recipe
427
+ run a battery of at least 40 queries the table's users would type in one batched
428
+ `mr-data search explain TABLE_ID --version VERSION_ID --queries-file queries.txt --json`
429
+ call (or repeatable `--query` flags) and fix every miss in the recipe
422
430
  ([query battery](references/preparing-table-search.md#run-a-query-battery-before-you-deliver)).
423
431
  Report rows and coverage actually verified, checks, limitations and the stable dataset link.
424
432
  End with what would make the table better: the remaining enhancements, deterministic ones
@@ -433,7 +441,7 @@ chat, and pass on its answer.
433
441
  | Reader coordinate and options | [Readers](references/readers.md) |
434
442
  | Connector or collection | [Sources](references/sources.md) |
435
443
  | One request per row of another source, such as a decision model scoring each row | [Per-row requests](references/sources.md#authoring-a-per-row-request) |
436
- | Which small models this deployment serves, the rule-first ladder, and classify, extract and translate sources | [Enriching with small models](references/enriching-with-small-models.md) |
444
+ | Which small models this deployment serves, the rule-first ladder, and classify, extract, standardize, match and translate sources | [Enriching with small models](references/enriching-with-small-models.md) |
437
445
  | Activity at named places from satellite images: parking, oil storage, construction, plant heat, ships, trucks, water | [Satellite signals](references/satellite-signals.md) |
438
446
  | Predict a column from other columns | [Predicting with tabular models](references/predicting-with-tabular-models.md) |
439
447
  | SQL and joins | [Transforms](references/transforms.md) |
@@ -7,20 +7,20 @@ could be better while you probe, say what you found, and recommend what to add.
7
7
 
8
8
  ### What this deployment serves
9
9
 
10
- Run `mr-data models --json` once per session, before the brief message. It lists five tasks and
11
- whether each is served here, read from the server's platform credential listing. A sixth,
12
- `translate`, is listed only where its binding is registered; where it is absent, translation is
13
- not offered. Where its `note` says this workspace has no translate allowance, every call would be
14
- refused, so do not offer it either.
10
+ Run `mr-data models --json` once per session, before the brief message. It lists each enrichment
11
+ task and whether it is served here, read from the server's platform credential listing.
12
+ `standardize` and `translate` appear only where their bindings are registered; where a binding is
13
+ absent or its `note` says this workspace has no allowance, do not offer it.
15
14
 
16
15
  | Task | What it does | Binding |
17
16
  | --- | --- | --- |
18
17
  | 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 |
19
18
  | 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) |
20
- | match | Links the same entity across tables or within one. | none yet: `planned` |
19
+ | match | Verifies whether pairs of arbitrary records (companies, people, products, addresses, etc.) represent the same entity across tables or within one. | `match` (platform `/v1/match`; [writing a match source](#writing-a-match-source)) |
21
20
  | observe | Measures activity at a place from satellite images, one series per place: parking, oil storage, construction, stored vehicles, plant heat, truck traffic, water area, ships, crop health, snow cover. | `sat` ([writing a sat source](#writing-a-sat-source)) |
22
21
  | predict | Predicts a column for rows where it is unknown from rows where it is known: a number with a range, or a label with class probabilities. | `predict` (TabICLv2, self-hosted; [writing a predict source](#writing-a-predict-source)) |
23
- | translate | Translates a text column into English, keeping the original beside it. Listed only where served. | `translate` (Google's Gemini through its OpenAI-compatible route; [writing a translate source](#writing-a-translate-source)) |
22
+ | translate | Translates a text column into English, keeping the original beside it. Listed only where served. | `translate` (platform `/v1/translate` or legacy Gemini OpenAI-compatible route; [writing a translate source](#writing-a-translate-source)) |
23
+ | standardize | Cleans and standardizes messy entity names into `canonical_name`, deterministic ASCII `match_key`, and structured components (`legal_form`, `qualifier`, `dba`). Listed only where served. | `standardize` (platform `/v1/standardize`; [writing a standardize source](#writing-a-standardize-source)) |
24
24
 
25
25
  Each served binding comes with its route, its pinned `model`, its rate, today's usage and quota,
26
26
  and a `request_template`. The rest of this paragraph is for per-row requests; predict is
@@ -37,8 +37,8 @@ Keep `classify` and `openrouter-decisions` for recipes already written against t
37
37
  Google's token rate, about 140 rows a second with one choice question per row and about 48 with forty
38
38
  yes/no questions, so ask few questions per row (see below); a wider recipe is slowed by 429s.
39
39
 
40
- Each binding also comes with a `pages_template`: `request_timeout_seconds` 120 and `retries` 3.
41
- Write both into the collection's `pages`. They exist for Clef and the extraction model and cost
40
+ Each binding also comes with a `pages_template`: `request_timeout_seconds` 120, `retries` 3, and `min_interval_milliseconds` 25.
41
+ Write them into the collection's `pages`. They exist for Clef and the extraction model and cost
42
42
  nothing on `gemini-decisions`. Clef and the extraction model scale to zero when idle,
43
43
  and their first instance takes three to five minutes to load. The server starts loading it when the
44
44
  run is admitted, and until the service has answered once it spreads each member's attempts over
@@ -48,9 +48,9 @@ that still fails says `it never answered, likely a 3 to 5 minute cold start` in
48
48
  `ROW_REQUEST_UNAVAILABLE` detail: tell the person the model was starting up and run it again, which keeps every saved
49
49
  answer.
50
50
 
51
- A task listed `not_served` or `planned` is offered as coming, never written into a recipe. For
52
- `match`, join on a normalized deterministic key now and say that model matching for the rows the
53
- key cannot settle is coming.
51
+ A task listed `not_served` or `planned` is offered as coming, never written into a recipe. When
52
+ `match` is listed `planned` or has no allowance, join on a normalized deterministic key now and
53
+ say that model matching for the rows the key cannot settle is coming.
54
54
 
55
55
  ### The ladder: a rule first, a model for the rest
56
56
 
@@ -74,7 +74,9 @@ judgement no rule can make. Both are improvements to offer.
74
74
  - classify: what a row's text is about, whether it states something, its sentiment or intent,
75
75
  which of the person's categories it belongs to.
76
76
  - extract: facts stated in prose, a page or a document that no column holds.
77
- - match, once served: two records that are the same entity under different spellings.
77
+ - standardize, where listed: messy entity names cleaned into `canonical_name` and deterministic
78
+ ASCII `match_key` (plus `legal_form`, `qualifier`, `dba`).
79
+ - match, where served: two records that may represent the same entity across arbitrary schemas.
78
80
  - translate, where listed: an English column beside text in another language.
79
81
 
80
82
  **Both together.** When a rule settles most rows, settle those in the transform and let the
@@ -114,6 +116,26 @@ also keep the rows it settled from being sent at all: see [Needs server 4.14](#n
114
116
  offers, deterministic ones first, each with the column it reads and what it would add. One
115
117
  concrete sentence each, not a menu of everything possible.
116
118
 
119
+ ### Choosing `classify` vs `extract` on website text
120
+
121
+ When you fetch third-party websites with `public.https.collection@2.0.0` (`source_rows`
122
+ `url_column` + `pages.allow_any_public_origin: true`) and `html.web_extract@1.8.0`
123
+ (`mode: "readable_text"`), pick the downstream model by the shape of the answer you need:
124
+
125
+ - **Use `classify` (`gemini-decisions` first) for fixed categories, enums, booleans, or
126
+ multilingual normalization** — for example determining whether a site offers self-service bays
127
+ vs an automatic tunnel, whether a venue is open 24/7, or assigning a standardized industry or
128
+ topic label across pages written in German, French, Polish, or Russian. `gemini-decisions`
129
+ understands multilingual text directly without a translation step, answers in ~250 ms per row
130
+ with zero cold start, and returns calibrated per-label probabilities.
131
+ - **Use `extract` only for verbatim spans pulled from the page text** — exact company names,
132
+ prices, street addresses, phone numbers, dates, or lists of named offers. Every extracted value
133
+ must appear verbatim in the input text or it is dropped, so `extract` returns blanks whenever a
134
+ category name is normalized or in a different language than the source page, and its service
135
+ takes 3–5 minutes to cold-start when idle.
136
+
137
+ Do not force a fixed categorical or multilingual labelling task through `extract`.
138
+
117
139
  ### Writing a classify source
118
140
 
119
141
  A classify source is a [per-row request](sources.md#authoring-a-per-row-request) over the source
@@ -165,8 +187,9 @@ An extract source has the same per-row shape with the extraction body
165
187
 
166
188
  - `input` is `{"view": "input", "text": "{text_column}"}`. `text` is the only placeholder, and it
167
189
  names a column of the upstream source, never of the transform. Give it visible text, not raw
168
- HTML: read the page in the upstream source with a Reader such as `html.web_extract`
169
- ([Readers](readers.md)).
190
+ HTML: read the page in the upstream source with `html.web_extract@1.8.0` (`mode: "readable_text"`)
191
+ for heterogeneous public websites, or a pinned `html.web_extract` DOM selector for a single
192
+ structured publisher ([Readers](readers.md)).
170
193
  - `fields` is a literal list of 1 to 64 `{name, description}` entries. Changing it changes the
171
194
  source's capture identity, so settle the list in the brief.
172
195
  - `one: true` asks for a single object per row, for a detail page; leave it out for a list of
@@ -321,7 +344,8 @@ A translated quotation is a translation, not the speaker's words. Label it so wh
321
344
 
322
345
  Name the model by what it does, not by its binding: "a small classification model reads each
323
346
  report and labels the weather regime", "a small extraction model pulls the issuer and the amount
324
- out of each filing". Say how many rows it would read, that it costs the person nothing, and what
347
+ out of each filing", "a small standardization model cleans company names into a canonical name
348
+ and match key", "a small matching model verifies ambiguous pairs across both tables". Say how many rows it would read, that it costs the person nothing, and what
325
349
  the new columns would be called. Never say a model was used when the table has no source that
326
350
  called it, and never present a model's label as fact: it is a label with a probability. A predicted value is a
327
351
  prediction with its range, never a measurement.
@@ -343,3 +367,46 @@ and the transform settles which label wins.
343
367
  - Where the per-row interval is served too, state `pages.revisit` as a long interval, up to a
344
368
  year: the model is pinned and the question fixed, so an answer does not change and should be
345
369
  carried forward ([a freshness bound](making-a-table-incremental.md#a-freshness-bound-on-per-row-answers)).
370
+
371
+ ### Writing a standardize source
372
+
373
+ A standardize source is a [per-row request](sources.md#authoring-a-per-row-request) over the
374
+ distinct values of a messy entity name column (organizations, people, places, products). Copy the
375
+ listing's `request_template` and `pages_template`, rename `name_column` to the upstream column in
376
+ `parameters`, `body_template`, and `carry_columns` (keep `"id"` in `carry_columns` and
377
+ `max_chars: 512`), and set `entity_type` to `org`, `person`, `place`, `product`, `generic`, or
378
+ `auto`. Deduplicate upstream distinct names before calling the endpoint so repeated rows pay once.
379
+ Read top-level `status`, `canonical_name`, `match_key`, `entity_type`, `components/legal_form`,
380
+ `components/qualifier`, and `components/dba` directly from the JSON response, keeping the original
381
+ name beside `canonical_name` and `match_key`.
382
+
383
+ > Note on `/v1/translate`: when `list_models` serves `translate` on `/v1/translate`, use the
384
+ > served `{model, text, source_language, target_language}` body (never send legacy Gemini
385
+ > `messages`/`response_format`) and read top-level `status`, `source_language`, `target_language`,
386
+ > and `translated_text` directly.
387
+
388
+ ### Writing a match source
389
+
390
+ A match source is a [per-row request](sources.md#authoring-a-per-row-request) that verifies
391
+ whether two arbitrary JSON records (`left` and `right`) represent the same real-world entity
392
+ across any schema (`company`, `person`, `product`, `address`, `vessel`, `invoice`, or `auto`).
393
+ Follow the ladder so you never pay for O(N^2) pairs:
394
+
395
+ 1. Standardize messy name columns first with [a standardize source](#writing-a-standardize-source)
396
+ (or a SQL key) and auto-link exact `match_key` hits in SQL for free.
397
+ 2. Block possible near-matches in SQL (shared prefix, domain, postal code, or trigram similarity)
398
+ in a supporting table (`table.version@1.0.0`, declaring the needed `"columns"` in `parquet.tabular@1.0.0` `reader.decode_options`) so only ambiguous pairs reach the model — a
399
+ `source_rows` per-row source reads an upstream `source`, never the same recipe's `transform`.
400
+ 3. Copy the listing's `request_template` and `pages_template`, extend `parameters`, `left`, and
401
+ `right` inside `body_template` with any disambiguating columns (`domain`, `city`, `postal_code`,
402
+ `sku`, `email`) — set `"required": false` on optional sparse parameters so pairs with nulls in
403
+ an attribute are not skipped — set `record_type` (and optional `criteria`, up to 500 chars),
404
+ and list the upstream pair's key column(s) (e.g. `pair_id`, or `left_id` and `right_id`) in
405
+ `carry_columns`.
406
+ 4. Read the scalar fields `match` (`yes` / `no` / `uncertain`), `confidence`
407
+ (`high` / `medium` / `low`), `score` (`0..1`), and `reason` directly with `json.tabular`.
408
+ Because `matched_fields` and `conflicting_fields` are JSON arrays, either omit them or use
409
+ `json.tabular@1.4.0` with `"non_scalar": "json"` on `/matched_fields` and `/conflicting_fields`
410
+ so admission does not reject array values. Auto-link `match = 'yes'` with `confidence = 'high'`
411
+ and flag `uncertain` rows for review. Skip `match` when its `note` says this workspace has no
412
+ match allowance.
@@ -353,6 +353,9 @@ the dashboard's explain, or through `search explain`:
353
353
 
354
354
  ```sh
355
355
  mr-data search explain TABLE_ID --version VERSION_ID --query "stocks under 10" --json
356
+ # Or explain a whole query battery concurrently in one command (newline-delimited or JSON array):
357
+ mr-data search explain TABLE_ID --version VERSION_ID --queries-file queries.txt --json
358
+ mr-data search explain TABLE_ID --version VERSION_ID --query "stocks under 10" --query "top gainers" --json
356
359
  ```
357
360
 
358
361
  Read `filters` and `order_by` to check the deterministic interpretation. To test an
@@ -384,8 +387,10 @@ you judge ranking. `try` runs on published tables only, against their live versi
384
387
  ### Run a query battery before you deliver
385
388
 
386
389
  A few spot checks miss most gaps. Before you deliver a table with search, write a battery of at
387
- least 40 queries that the people who use the table would type, and run every one through
388
- `search explain`. Take the queries from the brief and the product, not from the column names.
390
+ least 40 queries that the people who use the table would type into a file (one query per line or
391
+ a JSON array of strings) and run all of them in a single batched `mr-data search explain TABLE_ID
392
+ --version VERSION_ID --queries-file queries.txt --json` call (avoid 40 separate CLI invocations).
393
+ Take the queries from the brief and the product, not from the column names.
389
394
  Cover each kind:
390
395
 
391
396
  | Kind | Examples |
@@ -117,6 +117,12 @@ decoder. Zero matches and multiple matches both refuse.
117
117
  | `html.web_extract@1.0.0` | `mode: dom` with closed CSS-like record/field selectors, or `mode: json` with an inert JSON script selector and RFC 6901 field pointers. |
118
118
  | `html.web_extract@1.1.0` | Same settings as 1.0.0; extracted text follows DOM order, with one space at block-element boundaries and `<br>` and none between inline runs. |
119
119
  | `html.web_extract@1.2.0` | Same text as 1.1.0; bounded integer `:nth-child(N)` / `:nth-of-type(N)` and field `scope: ancestor` with `ancestor_selector`. Requires the corresponding deployed certification. |
120
+ | `html.web_extract@1.3.0` | Adds `value: html` (an element's own source markup); optional `required: false` multi-match returns null; `mode: json` adds `non_scalar`. |
121
+ | `html.web_extract@1.4.0` | Adds `value: count` and `value: inert_json` on DOM columns. |
122
+ | `html.web_extract@1.5.0` | Same settings and text as 1.4.0 with a 250,000-node DOM ceiling for large pages. |
123
+ | `html.web_extract@1.6.0` | Adds `mode: text_chunks` with a single-match `selector`, emitting `chunk_index`, `chunk_count`, and lossless 256 KiB `text` chunks. |
124
+ | `html.web_extract@1.7.0` | Same settings and modes as 1.6.0 over browser-implied end tags (300,000-node ceiling) for pages with unclosed `<p>`, `<li>`, and table tags. |
125
+ | `html.web_extract@1.8.0` | Same as 1.7.0 plus lenient HTML charset decoding (UTF-8, meta charset single-byte European/Cyrillic encodings, cp1252 fallback) and `mode: readable_text` (optional `max_chars` 512–65,536, default 16,384), emitting one row per page with fixed columns `title`, `meta_description`, `text`, and `text_length`. Use this coordinate for heterogeneous third-party websites. |
120
126
  | `protobuf.tabular@1.0.0` | Digest-pinned base64 FileDescriptorSet, fully-qualified message type, `single` or `length_delimited` framing, and fields with an explicit repeated `explode` or `refuse` choice. |
121
127
  | `parquet.tabular@1.0.0` | Optional `columns` selects a bounded ordered Parquet projection. |
122
128
  | `parquet.tabular@1.1.0` | Required `columns` of `{path, as}` select fields through structs by dotted path. An optional row filter keeps the rows every predicate in its `all` list admits. A public HTTPS source is read by range: only the footer and the selected column chunks are fetched. |
@@ -53,15 +53,17 @@ Write it as a source whose connector is that coordinate plus a `collection` memb
53
53
  this is not arbitrary recursive crawling. It requires the matching server API/worker release.
54
54
  A `source_rows` discovery may state a [per-row `request`](#authoring-a-per-row-request) instead
55
55
  of `url_column`.
56
- - `collection.pages` says what may be fetched and how much. It names `allowed_origins`, which
57
- must include the discovery address's own origin. It may state `max_pages`, `max_fetches_per_run`
56
+ - `collection.pages` says what may be fetched and how much. It names either `allowed_origins`
57
+ (which must include the discovery address's own origin) or, for a credential-free public
58
+ `source_rows` `url_column` or `explicit` collection over third-party sites,
59
+ `allow_any_public_origin: true` (never both). It may state `max_pages`, `max_fetches_per_run`
58
60
  (up to 50 000, or up to 4 000 000 on a per-row request collection), `concurrency` (up to
59
61
  10 000), `request_timeout_seconds`, `retries` and a `revisit` rule. `retries` is 0 to 3 and 2
60
62
  when left out. Registration refuses 4 or more. Its pace is `min_interval_milliseconds` in whole
61
63
  milliseconds. Left out, a collection starts at 1000 ms and adapts down to 250 ms. The legacy
62
- whole-second `min_interval_seconds` is the other spelling. Only `allowed_origins` is required.
63
- Every other member has a stated meaning when it is left out. [Pace and width](#pace-and-width)
64
- says which to state.
64
+ whole-second `min_interval_seconds` is the other spelling. One of `allowed_origins` or
65
+ `allow_any_public_origin: true` is required. Every other member has a stated meaning when it is
66
+ left out. [Pace and width](#pace-and-width) says which to state.
65
67
  - `limits.max_requests` is REQUIRED and bounds every request the run makes, discovery and detail
66
68
  pages together. `limits.max_source_bytes` bounds the fetched bytes; `limits.max_rows` clamps the
67
69
  merged relation.
@@ -119,6 +121,37 @@ redirects are likely — trailing slashes, `http`→`https`, `www`, which is mos
119
121
  `limits.max_requests >= discovery.max_requests + 2 * max_fetches_per_run`. A budget larger than the
120
122
  corpus can absorb costs nothing.
121
123
 
124
+ #### Extracting from heterogeneous public websites (`allow_any_public_origin`)
125
+
126
+ When an upstream table already has a URL column pointing to many distinct third-party websites
127
+ (for example a `website` column across hundreds or thousands of businesses, venues, or
128
+ organizations), do **not** hand-copy domains into `pages.allowed_origins` or build a fake
129
+ `explicit` list to work around origin limits. Declare a `source_rows` `url_column` collection with:
130
+
131
+ - `pages.allow_any_public_origin: true` (and omit `pages.allowed_origins`), on a credential-free
132
+ (`credential_mode: "none"`) `data_classification: "public"` source.
133
+ - Reader pin `html.web_extract@1.8.0` with canonical decode options
134
+ `{"max_chars":16384,"mode":"readable_text"}` (normalize with `/v4/readers/normalize` or
135
+ `mr-data reader normalize`). It decodes UTF-8 and common legacy European/Cyrillic charsets
136
+ leniently, strips scripts, styles, navigation, headers, footers, forms, and hidden overlays,
137
+ never fails on missing `<body>` or multiple tags, and emits four fixed columns per page:
138
+ `title`, `meta_description`, `text`, `text_length`.
139
+ - `limits.max_requests >= 3 * pages.max_fetches_per_run` to cover redirect hops (`apex` → `www`,
140
+ canonical domain moves) and retries.
141
+
142
+ Under `allow_any_public_origin: true`, dirty URLs in the upstream column are normalized before
143
+ fetching (`http://` upgraded to `https://`, bare hostnames like `www.example.de` prefixed with
144
+ `https://`, `#fragments` stripped, internationalized domains converted to punycode), and
145
+ malformed, non-HTTPS, IP-literal, or private/internal addresses are cleanly skipped per row
146
+ without failing the run. Safe public HTTPS redirects (`apex` ↔ `www`, canonical host moves) are
147
+ followed automatically, while private/loopback/metadata targets remain blocked on every hop.
148
+
149
+ To run a bounded scratch test before a full build, keep the same `source_rows` `url_column`
150
+ discovery over the real upstream table and set `pages.max_fetches_per_run: 30` (and
151
+ `limits.max_requests: 90`). The collection fetches up to 30 real sites, tolerates unreachable or
152
+ broken individual websites cleanly, and lets you inspect the extracted `title` and `text` before
153
+ scaling `max_fetches_per_run` to the full corpus.
154
+
122
155
  For a dependent graph, declare recipe-level `acquisition_limits` with `max_requests` and
123
156
  `max_source_bytes`. Every source must explicitly state both ceilings; their sums must fit the
124
157
  totals. Unused capacity does not transfer between sources.
@@ -0,0 +1,113 @@
1
+ """The hosted ``mr-data`` client package, and the closed public surface it actually provides.
2
+
3
+ ⚠ AN EXPORT IS A PROMISE THE INSTALLED WHEEL HAS TO KEEP. This module used to resolve fifty-eight
4
+ names through a ``__getattr__`` over a table of module coordinates, and the table outlived the
5
+ modules: the execution engine moved to Studio and every coordinate naming ``pipeline``, ``offline``,
6
+ ``recipe``, ``contracts``, ``local_contracts``, ``studio_boundary`` or ``review`` became an import
7
+ that raises inside the shipped wheel. A dynamic coordinate is also invisible to the ownership
8
+ scanner, so nothing held the table to the tree. Both problems have the same fix: the exports are
9
+ plain imports of modules this distribution ships, so a missing one is an ImportError at build and
10
+ test time rather than an AttributeError in somebody else's program.
11
+
12
+ What is left is the canonical-JSON leaf, which the wire contracts share, and the version. Every
13
+ command surface is reached through :mod:`mostlyright.data_harness.thin`.
14
+ """
15
+
16
+ import os as _os
17
+ import sys as _sys
18
+
19
+ from mostlyright.data_harness.agent_protocol import (
20
+ PROTOCOL_SCHEMA,
21
+ RECOVERY_CATEGORIES,
22
+ normalize_reader_options,
23
+ recovery_from,
24
+ recovery_next_step,
25
+ )
26
+ from mostlyright.data_harness.canonical import (
27
+ CanonicalJSONError,
28
+ canonical_json_bytes,
29
+ canonical_sha256,
30
+ parse_canonical_json,
31
+ parse_json,
32
+ )
33
+
34
+ _CACHED_VERSION: str | None = None
35
+
36
+
37
+ def _fast_dist_version() -> str | None:
38
+ """Read ``Version:`` directly from ``mostlyright_data-*.dist-info/METADATA`` without importing
39
+ ``importlib.metadata`` (which loads ``email`` and ``zipfile`` on every CLI start)."""
40
+
41
+ matches: list[str] = []
42
+ seen_dirs: set[str] = set()
43
+ for entry in _sys.path:
44
+ if not entry or entry in seen_dirs:
45
+ continue
46
+ seen_dirs.add(entry)
47
+ try:
48
+ with _os.scandir(entry) as it:
49
+ for item in it:
50
+ name = item.name
51
+ if name.startswith("mostlyright_data-") and name.endswith(".dist-info"):
52
+ meta = _os.path.join(item.path, "METADATA")
53
+ if _os.path.isfile(meta):
54
+ matches.append(meta)
55
+ except OSError:
56
+ continue
57
+ if matches:
58
+ break
59
+ if len(matches) != 1:
60
+ return None
61
+ try:
62
+ with open(matches[0], encoding="utf-8") as fh:
63
+ for line in fh:
64
+ if line in ("\n", "\r\n", ""):
65
+ break
66
+ if line.startswith("Version:"):
67
+ value = line.partition(":")[2].strip()
68
+ return value or None
69
+ except OSError:
70
+ return None
71
+ return None
72
+
73
+
74
+ def package_version() -> str:
75
+ """Return the installed distribution version or an honest source-tree fallback."""
76
+
77
+ global _CACHED_VERSION
78
+ if _CACHED_VERSION is not None:
79
+ return _CACHED_VERSION
80
+ fast = _fast_dist_version()
81
+ if fast is not None:
82
+ _CACHED_VERSION = fast
83
+ return fast
84
+ from importlib import metadata as _metadata
85
+
86
+ try:
87
+ _CACHED_VERSION = _metadata.version("mostlyright-data")
88
+ except _metadata.PackageNotFoundError:
89
+ return "uninstalled"
90
+ return _CACHED_VERSION
91
+
92
+
93
+ def __getattr__(name: str) -> str:
94
+ if name == "__version__":
95
+ value = package_version()
96
+ globals()["__version__"] = value
97
+ return value
98
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
99
+
100
+ __all__ = [
101
+ "PROTOCOL_SCHEMA",
102
+ "RECOVERY_CATEGORIES",
103
+ "CanonicalJSONError",
104
+ "__version__",
105
+ "canonical_json_bytes",
106
+ "canonical_sha256",
107
+ "normalize_reader_options",
108
+ "package_version",
109
+ "parse_canonical_json",
110
+ "parse_json",
111
+ "recovery_from",
112
+ "recovery_next_step",
113
+ ]
@@ -39,10 +39,7 @@ tests keep reading it there, and the wheel carries the same bytes at
39
39
 
40
40
  from __future__ import annotations
41
41
 
42
- import hashlib
43
42
  import os
44
- import shutil
45
- import tempfile
46
43
  from pathlib import Path
47
44
 
48
45
  __all__ = [
@@ -66,13 +63,14 @@ _AMBIENT_SUFFIXES = frozenset({".pyc", ".pyo"})
66
63
 
67
64
  _STAMP_NAME = ".mr-data-skill.json"
68
65
  _OPT_OUT = "MOSTLYRIGHT_SKILL_AUTOINSTALL"
66
+ _SANDBOX_ENV = "MOSTLYRIGHT_SANDBOX"
69
67
 
70
68
 
71
69
  def packaged_skill_tree() -> Path | None:
72
70
  """The skill tree carried inside this wheel, or ``None`` in a source checkout."""
73
71
 
74
- candidate = Path(__file__).resolve().parent / "skill_tree" / SKILL_NAME
75
- return candidate if candidate.is_dir() else None
72
+ candidate = os.path.join(os.path.dirname(os.path.abspath(__file__)), "skill_tree", SKILL_NAME)
73
+ return Path(candidate) if os.path.isdir(candidate) else None
76
74
 
77
75
 
78
76
  def _target_root(target: str) -> Path:
@@ -119,6 +117,8 @@ def tree_digest(root: Path) -> str:
119
117
 
120
118
  if not root.is_dir() or root.is_symlink():
121
119
  raise ValueError(f"skill tree is not a plain directory: {root}")
120
+ import hashlib
121
+
122
122
  accumulator = hashlib.sha256()
123
123
  pending = [root]
124
124
  entries: list[tuple[str, bytes]] = []
@@ -165,6 +165,8 @@ def _write_stamp(destination: Path, *, version: str, digest: str) -> None:
165
165
 
166
166
 
167
167
  def _copy_tree(source: Path, destination: Path) -> None:
168
+ import shutil
169
+
168
170
  shutil.copytree(
169
171
  source,
170
172
  destination,
@@ -182,6 +184,9 @@ def install_tree(source: Path, destination: Path, *, version: str) -> None:
182
184
  and removed only once the new one is in place.
183
185
  """
184
186
 
187
+ import shutil
188
+ import tempfile
189
+
185
190
  destination.parent.mkdir(parents=True, exist_ok=True)
186
191
  staging = Path(tempfile.mkdtemp(prefix=f".{SKILL_NAME}.", dir=destination.parent))
187
192
  staged = staging / SKILL_NAME
@@ -197,12 +202,10 @@ def install_tree(source: Path, destination: Path, *, version: str) -> None:
197
202
 
198
203
 
199
204
  def _package_version() -> str:
200
- from importlib.metadata import PackageNotFoundError, version
205
+ from mostlyright.data_harness import package_version
201
206
 
202
- try:
203
- return version("mostlyright-data")
204
- except PackageNotFoundError:
205
- return "0"
207
+ running = package_version()
208
+ return "0" if running == "uninstalled" else running
206
209
 
207
210
 
208
211
  def ensure_installed(target: str = "claude") -> str:
@@ -214,7 +217,9 @@ def ensure_installed(target: str = "claude") -> str:
214
217
  command's, and this runs before all of them.
215
218
  """
216
219
 
217
- if os.environ.get(_OPT_OUT, "").strip() in {"0", "false", "no"}:
220
+ if os.environ.get(_OPT_OUT, "").strip().lower() in {"0", "false", "no"}:
221
+ return "opted-out"
222
+ if os.environ.get(_SANDBOX_ENV, "").strip().lower() not in {"", "0", "false", "no"}:
218
223
  return "opted-out"
219
224
  source = packaged_skill_tree()
220
225
  if source is None:
@@ -53,9 +53,9 @@ from mostlyright.data_harness.thin import THIN_SCHEMA_PREFIX
53
53
  from mostlyright.data_harness.thin.session import StudioSessionProvider, dataset_dashboard_url
54
54
  from mostlyright.data_harness.thin.transport import (
55
55
  REQUEST_TIMEOUT_SECONDS,
56
+ ReusableHttpsTransport,
56
57
  ThinLaneError,
57
58
  Transport,
58
- UrlLibTransport,
59
59
  )
60
60
  from mostlyright.data_harness.thin.v4 import (
61
61
  COMMAND_REQUEST_VERSION_FLOOR,
@@ -987,23 +987,60 @@ def open_client(*, timeout: float = REQUEST_TIMEOUT_SECONDS) -> StudioV4Activity
987
987
 
988
988
  global _COMMAND_TRANSPORT
989
989
  if _COMMAND_TRANSPORT is None:
990
- _COMMAND_TRANSPORT = UrlLibTransport(timeout=timeout)
990
+ _COMMAND_TRANSPORT = ReusableHttpsTransport(timeout=timeout)
991
991
  return _client_on(_COMMAND_TRANSPORT)
992
992
 
993
993
 
994
994
  def _reporting_client(budget: _Budget) -> StudioV4ActivityClient:
995
995
  """The AUTOMATIC half's client, bounded by one deadline across every request it makes."""
996
996
 
997
- return _client_on(UrlLibTransport(timeout=budget.remaining))
997
+ transport = ReusableHttpsTransport(timeout=budget.remaining)
998
+ from mostlyright.data_harness.thin.session import cached_fresh_session
999
+ from mostlyright.data_harness.ux.credentials import resolve_cloud_credentials
1000
+
1001
+ if _SESSION is not None:
1002
+ fresh = _SESSION.fresh_or_none()
1003
+ if fresh is not None:
1004
+ return StudioV4ActivityClient(StudioSessionProvider(fresh), transport=transport)
1005
+ else:
1006
+ creds = resolve_cloud_credentials()
1007
+ fresh = cached_fresh_session(creds)
1008
+ if fresh is not None:
1009
+ return StudioV4ActivityClient(StudioSessionProvider(fresh), transport=transport)
1010
+ return _client_on(transport, budgeted=True)
998
1011
 
999
1012
 
1000
- def _client_on(transport: Transport) -> StudioV4ActivityClient:
1013
+ def _client_on(transport: Transport, *, budgeted: bool = False) -> StudioV4ActivityClient:
1001
1014
  global _SESSION
1002
- from mostlyright.data_harness.thin.session import open_renewable_session
1015
+ from mostlyright.data_harness.thin.session import (
1016
+ cached_fresh_session,
1017
+ open_renewable_session,
1018
+ )
1003
1019
  from mostlyright.data_harness.ux.credentials import resolve_cloud_credentials
1004
1020
 
1005
1021
  if _SESSION is None:
1006
- _SESSION = open_renewable_session(resolve_cloud_credentials(), transport=transport)
1022
+ creds = resolve_cloud_credentials()
1023
+ fresh = cached_fresh_session(creds) if budgeted else None
1024
+ if fresh is not None:
1025
+ return StudioV4ActivityClient(StudioSessionProvider(fresh), transport=transport)
1026
+ _SESSION = open_renewable_session(
1027
+ creds,
1028
+ transport=transport,
1029
+ renewal_transport=None,
1030
+ _cache_result=True,
1031
+ )
1032
+ if budgeted:
1033
+ fresh = _SESSION.fresh_or_none()
1034
+ if fresh is not None:
1035
+ return StudioV4ActivityClient(StudioSessionProvider(fresh), transport=transport)
1036
+ # Re-exchange under the short activity budget rather than blocking on a 30s renewal.
1037
+ creds = resolve_cloud_credentials()
1038
+ _SESSION = open_renewable_session(
1039
+ creds,
1040
+ transport=transport,
1041
+ renewal_transport=None,
1042
+ _cache_result=True,
1043
+ )
1007
1044
  return StudioV4ActivityClient(_SESSION, transport=transport)
1008
1045
 
1009
1046
 
@@ -1011,9 +1048,17 @@ def forget_session() -> None:
1011
1048
  """Drop the cached session, transport and document. For tests, and for nothing else."""
1012
1049
 
1013
1050
  global _SESSION, _COMMAND_TRANSPORT
1051
+ from mostlyright.data_harness.thin.session import forget_cached_sessions
1052
+
1014
1053
  _SESSION = None
1015
- _COMMAND_TRANSPORT = None
1054
+ transport, _COMMAND_TRANSPORT = _COMMAND_TRANSPORT, None
1055
+ if transport is not None and hasattr(transport, "close"):
1056
+ try:
1057
+ transport.close()
1058
+ except Exception:
1059
+ pass
1016
1060
  _DOCUMENTS.clear()
1061
+ forget_cached_sessions()
1017
1062
 
1018
1063
 
1019
1064
  __all__ = [