aethis-cli 0.53.2__tar.gz → 0.55.0__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 (120) hide show
  1. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/PKG-INFO +17 -1
  2. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/README.md +16 -0
  3. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/_version.py +1 -1
  4. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/client.py +38 -0
  5. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/commands/generate_cmd.py +161 -5
  6. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli.egg-info/PKG-INFO +17 -1
  7. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli.egg-info/SOURCES.txt +1 -0
  8. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/pyproject.toml +1 -1
  9. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_acceptance_contract.py +131 -0
  10. aethis_cli-0.55.0/tests/test_bundle_contract.py +483 -0
  11. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_guidance_cli.py +1 -0
  12. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/LICENSE +0 -0
  13. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/__init__.py +0 -0
  14. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/__main__.py +0 -0
  15. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/_terminal_safe.py +0 -0
  16. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/auth.py +0 -0
  17. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/auth_helpers.py +0 -0
  18. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/auth_providers.py +0 -0
  19. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/commands/__init__.py +0 -0
  20. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/commands/_id_utils.py +0 -0
  21. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/commands/account_cmd.py +0 -0
  22. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/commands/cancel_cmd.py +0 -0
  23. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/commands/decide_cmd.py +0 -0
  24. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/commands/explain_cmd.py +0 -0
  25. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/commands/fields_cmd.py +0 -0
  26. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/commands/guidance_cmd.py +0 -0
  27. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/commands/init_cmd.py +0 -0
  28. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/commands/login_cmd.py +0 -0
  29. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/commands/mcp_cmd.py +0 -0
  30. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/commands/profile_cmd.py +0 -0
  31. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/commands/projects_cmd.py +0 -0
  32. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/commands/publish_cmd.py +0 -0
  33. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/commands/refine_cmd.py +0 -0
  34. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/commands/review_cmd.py +0 -0
  35. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/commands/rulebooks_cmd.py +0 -0
  36. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/commands/rulesets_cmd.py +0 -0
  37. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/commands/status_cmd.py +0 -0
  38. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/commands/test_cmd.py +0 -0
  39. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/commands/update_cmd.py +0 -0
  40. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/commands/usage_cmd.py +0 -0
  41. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/commands/whoami_cmd.py +0 -0
  42. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/config.py +0 -0
  43. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/contract.py +0 -0
  44. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/decision_view.py +0 -0
  45. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/errors.py +0 -0
  46. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/generation_status.py +0 -0
  47. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/main.py +0 -0
  48. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/output.py +0 -0
  49. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/prompts.py +0 -0
  50. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/py.typed +0 -0
  51. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/render.py +0 -0
  52. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/source_safeguards.py +0 -0
  53. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/source_targets.py +0 -0
  54. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli/update_check.py +0 -0
  55. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli.egg-info/dependency_links.txt +0 -0
  56. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli.egg-info/entry_points.txt +0 -0
  57. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli.egg-info/requires.txt +0 -0
  58. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/aethis_cli.egg-info/top_level.txt +0 -0
  59. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/setup.cfg +0 -0
  60. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_account_cmd.py +0 -0
  61. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_auth.py +0 -0
  62. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_auth_providers.py +0 -0
  63. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_cancel_cmd.py +0 -0
  64. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_capability_boundary.py +0 -0
  65. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_client.py +0 -0
  66. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_collection_computed_prerequisite_transport.py +0 -0
  67. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_config.py +0 -0
  68. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_contract_decide.py +0 -0
  69. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_contract_identity_and_sources.py +0 -0
  70. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_contract_request_surface.py +0 -0
  71. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_contract_rulebook_decide.py +0 -0
  72. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_credential_server.py +0 -0
  73. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_credential_url_parser.py +0 -0
  74. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_decide_cmd.py +0 -0
  75. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_documented_commands_run.py +0 -0
  76. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_empty_input_guards.py +0 -0
  77. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_explain_cmd.py +0 -0
  78. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_fact_links_transport.py +0 -0
  79. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_field_behaviour_metadata_transport.py +0 -0
  80. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_field_dependency_and_identity_transport.py +0 -0
  81. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_field_display_metadata_transport.py +0 -0
  82. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_field_notes_validation.py +0 -0
  83. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_fields_cmd.py +0 -0
  84. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_generate_display_name.py +0 -0
  85. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_generate_failure_reporting.py +0 -0
  86. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_generate_fields.py +0 -0
  87. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_generate_no_publish.py +0 -0
  88. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_generate_replace_tests.py +0 -0
  89. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_generation_models.py +0 -0
  90. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_generation_status.py +0 -0
  91. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_id_utils.py +0 -0
  92. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_init.py +0 -0
  93. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_json_projection_pinning.py +0 -0
  94. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_lazy_auth.py +0 -0
  95. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_login_headless.py +0 -0
  96. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_main.py +0 -0
  97. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_mcp_cmd.py +0 -0
  98. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_output.py +0 -0
  99. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_presence_default_basis_transport.py +0 -0
  100. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_profiles.py +0 -0
  101. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_project_file_trust.py +0 -0
  102. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_prompts.py +0 -0
  103. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_publish_display_name.py +0 -0
  104. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_publish_force.py +0 -0
  105. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_publish_rulebook_flags.py +0 -0
  106. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_publish_source_targets.py +0 -0
  107. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_release_tooling.py +0 -0
  108. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_render.py +0 -0
  109. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_review_cmd.py +0 -0
  110. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_rulebooks_cmd.py +0 -0
  111. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_rulesets_b1b_lifecycle.py +0 -0
  112. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_source_safeguards.py +0 -0
  113. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_spacecraft_example_pin.py +0 -0
  114. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_status_cmd.py +0 -0
  115. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_transport_error_rendering.py +0 -0
  116. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_update_check.py +0 -0
  117. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_update_cmd.py +0 -0
  118. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_usage.py +0 -0
  119. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_value_space_transport.py +0 -0
  120. {aethis_cli-0.53.2 → aethis_cli-0.55.0}/tests/test_whoami_cmd.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aethis-cli
3
- Version: 0.53.2
3
+ Version: 0.55.0
4
4
  Summary: CLI for the Aethis developer API — author, test, and publish rulesets
5
5
  Author-email: Aethis <eng@aethis.ai>
6
6
  License-Expression: MIT
@@ -299,6 +299,10 @@ If a publish fails after files were uploaded, those files stay in the project
299
299
  and are reused on the next attempt (matched by `sha256`), so retrying does not
300
300
  duplicate them.
301
301
 
302
+ ### Bundle contract (input invariants)
303
+
304
+ Add `contracts/bundle.yaml` to the project folder (beside `fields/` and `tests/`) to declare consistency rules across inputs, for example that an end date must not be before a start date. `aethis generate` and `aethis refine` send it before generation and confirm the build captured it. To clear a stored contract, delete the file: the next run clears it (on an engine that supports it). See the CHANGELOG entry for 0.54.0 for the file format.
305
+
302
306
  ### Guidance (project-level)
303
307
 
304
308
  Project guidance lives in `.aethis/guidance/hints.yaml` and is uploaded by `aethis generate`. These commands manage hints server-side after upload.
@@ -463,8 +467,20 @@ tests:
463
467
  space.medical.cert_valid: false
464
468
  expect:
465
469
  outcome: not_eligible
470
+ - name: "Undetermined — renewal before joined"
471
+ inputs:
472
+ member.joined_date: "2026-05-01"
473
+ member.renewal_date: "2026-04-01"
474
+ expect:
475
+ outcome: undetermined
476
+ field_errors:
477
+ member.renewal_date: The renewal date must not be before the joined date.
466
478
  ```
467
479
 
480
+ `field_errors` asserts that a rule from `contracts/bundle.yaml` rejected the input:
481
+ it maps each field id to the exact message you authored, and is only valid with
482
+ `outcome: undetermined`. An older API host may reject the key; the host's message is shown as-is.
483
+
468
484
  This file is the authoritative suite: `aethis generate` uploads it in full and
469
485
  **replaces** the project's test cases with it, so running generate twice leaves
470
486
  one copy, not two. The upload reports how many existing cases it overwrote. An
@@ -264,6 +264,10 @@ If a publish fails after files were uploaded, those files stay in the project
264
264
  and are reused on the next attempt (matched by `sha256`), so retrying does not
265
265
  duplicate them.
266
266
 
267
+ ### Bundle contract (input invariants)
268
+
269
+ Add `contracts/bundle.yaml` to the project folder (beside `fields/` and `tests/`) to declare consistency rules across inputs, for example that an end date must not be before a start date. `aethis generate` and `aethis refine` send it before generation and confirm the build captured it. To clear a stored contract, delete the file: the next run clears it (on an engine that supports it). See the CHANGELOG entry for 0.54.0 for the file format.
270
+
267
271
  ### Guidance (project-level)
268
272
 
269
273
  Project guidance lives in `.aethis/guidance/hints.yaml` and is uploaded by `aethis generate`. These commands manage hints server-side after upload.
@@ -428,8 +432,20 @@ tests:
428
432
  space.medical.cert_valid: false
429
433
  expect:
430
434
  outcome: not_eligible
435
+ - name: "Undetermined — renewal before joined"
436
+ inputs:
437
+ member.joined_date: "2026-05-01"
438
+ member.renewal_date: "2026-04-01"
439
+ expect:
440
+ outcome: undetermined
441
+ field_errors:
442
+ member.renewal_date: The renewal date must not be before the joined date.
431
443
  ```
432
444
 
445
+ `field_errors` asserts that a rule from `contracts/bundle.yaml` rejected the input:
446
+ it maps each field id to the exact message you authored, and is only valid with
447
+ `outcome: undetermined`. An older API host may reject the key; the host's message is shown as-is.
448
+
433
449
  This file is the authoritative suite: `aethis generate` uploads it in full and
434
450
  **replaces** the project's test cases with it, so running generate twice leaves
435
451
  one copy, not two. The upload reports how many existing cases it overwrote. An
@@ -1,3 +1,3 @@
1
1
  """Version info — updated per release."""
2
2
 
3
- __version__ = "0.53.2"
3
+ __version__ = "0.55.0"
@@ -133,6 +133,7 @@ class AethisClient:
133
133
  # upload?" — one probe per client, not one per call.
134
134
  self._test_replace_support: Any = _UNPROBED
135
135
  self._test_acceptance_contract_support: Any = _UNPROBED
136
+ self._bundle_contract_support: Any = _UNPROBED
136
137
  # Cached property names the engine advertises, per schema model — one
137
138
  # probe per model per client, not one per call.
138
139
  self._field_spec_properties: dict[str, Optional[set[str]]] = {}
@@ -419,6 +420,43 @@ class AethisClient:
419
420
  self._test_acceptance_contract_support = answer
420
421
  return answer
421
422
 
423
+ def supports_bundle_contract(self) -> Optional[bool]:
424
+ """Whether this engine advertises the project bundle-contract route.
425
+
426
+ True only when the published API lists a ``PUT`` operation on
427
+ ``.../projects/{project_id}/bundle-contract``. An unreadable schema is
428
+ ``None``, which is not an answer about the engine.
429
+ """
430
+ if self._bundle_contract_support is not _UNPROBED:
431
+ return self._bundle_contract_support # type: ignore[return-value]
432
+ try:
433
+ resp = self._client.get("/openapi.json", timeout=15.0)
434
+ resp.raise_for_status()
435
+ paths = resp.json()["paths"]
436
+ answer: Optional[bool] = any(
437
+ isinstance(path, str)
438
+ and path.endswith("/projects/{project_id}/bundle-contract")
439
+ and isinstance(item, dict)
440
+ and "put" in item
441
+ for path, item in paths.items()
442
+ )
443
+ except (httpx.HTTPError, ValueError, KeyError, TypeError, AttributeError):
444
+ answer = None
445
+ self._bundle_contract_support = answer
446
+ return answer
447
+
448
+ def set_bundle_contract(self, project_id: str, contract: bytes) -> dict:
449
+ """Store the project's bundle contract (``{"schema_version": 1}`` alone clears it).
450
+
451
+ ``contract`` is the exact JSON body, already checked by the caller; it is sent as given.
452
+ """
453
+ return self._request(
454
+ "PUT",
455
+ f"/api/v1/public/projects/{project_id}/bundle-contract",
456
+ content=contract,
457
+ headers={"Content-Type": "application/json"},
458
+ )
459
+
422
460
  def _schema_properties(self, model: str) -> Optional[set[str]]:
423
461
  """The property names this engine advertises on ``model``.
424
462
 
@@ -44,6 +44,7 @@ _MAX_ACCEPTANCE_CASES = 500
44
44
  _MAX_LEGACY_CASES = 100
45
45
  _MAX_ACCEPTANCE_ID_LENGTH = 300
46
46
  _MAX_ACCEPTANCE_LIST_LENGTH = 500
47
+ _MAX_FIELD_ERROR_MESSAGE_LENGTH = 20000
47
48
  _KNOWN_CONTRACT_SEMANTIC_KEYS = {
48
49
  "contract_version",
49
50
  "expected_review_bindings",
@@ -59,6 +60,7 @@ _KNOWN_CONTRACT_SEMANTIC_KEYS = {
59
60
  "resolution_fields",
60
61
  "unmapped_count",
61
62
  "useful_unknown_fields",
63
+ "field_errors",
62
64
  }
63
65
 
64
66
 
@@ -107,10 +109,29 @@ def _strict_string_list(value: Any, path: str) -> list[str]:
107
109
  return value
108
110
 
109
111
 
112
+ def _strict_field_errors(value: Any, path: str) -> dict[str, str]:
113
+ if not isinstance(value, dict) or not value:
114
+ raise AcceptanceContractError(f"{path} must be a non-empty object mapping field ids to messages")
115
+ if len(value) > _MAX_ACCEPTANCE_LIST_LENGTH:
116
+ raise AcceptanceContractError(f"{path} must contain at most {_MAX_ACCEPTANCE_LIST_LENGTH} entries")
117
+ for key, message in value.items():
118
+ if not isinstance(key, str) or not key.strip():
119
+ raise AcceptanceContractError(f"{path} keys must be non-empty strings")
120
+ if len(key) > _MAX_ACCEPTANCE_ID_LENGTH:
121
+ raise AcceptanceContractError(f"{path} keys must be at most {_MAX_ACCEPTANCE_ID_LENGTH} code points")
122
+ if not isinstance(message, str) or not message:
123
+ raise AcceptanceContractError(f"{path}[{key!r}] must be a non-empty string")
124
+ if len(message) > _MAX_FIELD_ERROR_MESSAGE_LENGTH:
125
+ raise AcceptanceContractError(
126
+ f"{path}[{key!r}] must be at most {_MAX_FIELD_ERROR_MESSAGE_LENGTH} code points"
127
+ )
128
+ return dict(value)
129
+
130
+
110
131
  def _normalise_expectations(value: Any, path: str) -> dict[str, Any]:
111
132
  if not isinstance(value, dict):
112
133
  raise AcceptanceContractError(f"{path} must be an object")
113
- unknown = set(value) - {"pending_reviews", "useful_unknown_fields"}
134
+ unknown = set(value) - {"pending_reviews", "useful_unknown_fields", "field_errors"}
114
135
  if unknown:
115
136
  raise AcceptanceContractError(f"{path} contains unsupported key(s): {', '.join(sorted(unknown))}")
116
137
  if not value:
@@ -138,6 +159,8 @@ def _normalise_expectations(value: Any, path: str) -> dict[str, Any]:
138
159
  out["useful_unknown_fields"] = _strict_string_list(
139
160
  value["useful_unknown_fields"], f"{path}.useful_unknown_fields"
140
161
  )
162
+ if "field_errors" in value:
163
+ out["field_errors"] = _strict_field_errors(value["field_errors"], f"{path}.field_errors")
141
164
  return out
142
165
 
143
166
 
@@ -177,13 +200,21 @@ def _normalise_test_cases(cases: Any, path: str, *, yaml_shape: bool) -> list[di
177
200
  if yaml_shape:
178
201
  values = case.get("inputs", {})
179
202
  expect = case.get("expect", {})
180
- if not isinstance(expect, dict) or set(expect) - {"outcome", "pending_reviews", "useful_unknown_fields"}:
203
+ if not isinstance(expect, dict) or set(expect) - {
204
+ "outcome",
205
+ "pending_reviews",
206
+ "useful_unknown_fields",
207
+ "field_errors",
208
+ }:
181
209
  raise AcceptanceContractError(
182
- f"{case_path}.expect may contain only outcome, pending_reviews, and useful_unknown_fields"
210
+ f"{case_path}.expect may contain only outcome, pending_reviews, useful_unknown_fields, "
211
+ "and field_errors"
183
212
  )
184
213
  outcome = expect.get("outcome", "eligible")
185
214
  expectations = {
186
- key: expect[key] for key in ("pending_reviews", "useful_unknown_fields") if key in expect
215
+ key: expect[key]
216
+ for key in ("pending_reviews", "useful_unknown_fields", "field_errors")
217
+ if key in expect
187
218
  } or None
188
219
  else:
189
220
  values = case.get("field_values")
@@ -202,6 +233,10 @@ def _normalise_test_cases(cases: Any, path: str, *, yaml_shape: bool) -> list[di
202
233
  normal = {"name": name, "field_values": values, "expected_outcome": outcome}
203
234
  if expectations is not None:
204
235
  normal["expectations"] = _normalise_expectations(expectations, f"{case_path}.expectations")
236
+ if "field_errors" in normal["expectations"] and outcome != "undetermined":
237
+ raise AcceptanceContractError(
238
+ f"{case_path}.expectations.field_errors is only valid when expected_outcome is undetermined"
239
+ )
205
240
  out.append(normal)
206
241
  return out
207
242
 
@@ -1513,6 +1548,17 @@ def _run_generate(
1513
1548
  # Local field validation first: nothing below may reach the engine
1514
1549
  # (guidance accumulates on the project) for a vocabulary that is invalid.
1515
1550
  _validate_project_fields(project_dir)
1551
+ # The bundle contract is checked before any engine call: a malformed
1552
+ # file, or an engine that cannot hold it, must not leave a half-sent run.
1553
+ bundle_contract = _load_bundle_contract(project_dir)
1554
+ bundle_advertised: Optional[bool] = None
1555
+ if bundle_contract is not None:
1556
+ bundle_advertised = client.supports_bundle_contract()
1557
+ if bundle_advertised is not True:
1558
+ raise BundleContractError(
1559
+ "contracts/bundle.yaml is present but this engine does not advertise the bundle contract "
1560
+ "route; stopping before any upload or generation"
1561
+ )
1516
1562
  # Parse, validate, canonicalise and capability-check the complete test
1517
1563
  # plan before project creation, guidance, source, field or test writes.
1518
1564
  # The frozen snapshot is the payload uploaded later in this run.
@@ -1565,6 +1611,10 @@ def _run_generate(
1565
1611
  _upload_rulebook_guidance(client, pid, project_dir)
1566
1612
  _upload_field_vocabulary(client, pid, project_dir)
1567
1613
 
1614
+ if bundle_contract is None:
1615
+ bundle_advertised = client.supports_bundle_contract()
1616
+ bundle_digest = _send_bundle_contract(client, pid, bundle_contract, bundle_advertised)
1617
+
1568
1618
  # Upload the exact test payload prepared before any project mutation.
1569
1619
  _upload_prepared_test_cases(client, pid, prepared_tests)
1570
1620
 
@@ -1599,12 +1649,20 @@ def _run_generate(
1599
1649
  console.print(f"[{_style}]{_rem} {_noun} left in the current 24h window.[/{_style}]")
1600
1650
 
1601
1651
  if not poll:
1652
+ if bundle_digest:
1653
+ console.print(f"Bundle contract digest {bundle_digest}: check it against the job status later.")
1602
1654
  console.print("Use 'aethis status' to check progress.")
1603
1655
  return
1604
1656
 
1605
1657
  # Poll with progress spinner
1606
1658
  outcome = _poll_until_done(
1607
- client, pid, project_dir, timeout, no_publish=no_publish, shown_thinking_warnings=shown_thinking_warnings
1659
+ client,
1660
+ pid,
1661
+ project_dir,
1662
+ timeout,
1663
+ no_publish=no_publish,
1664
+ shown_thinking_warnings=shown_thinking_warnings,
1665
+ expected_bundle_digest=bundle_digest,
1608
1666
  )
1609
1667
 
1610
1668
  # Surface how the produced field vocabulary compares to what was pinned,
@@ -1622,6 +1680,10 @@ def _run_generate(
1622
1680
  console.print(f"[red]Acceptance contract rejected: {e}[/red]")
1623
1681
  raise typer.Exit(code=1)
1624
1682
 
1683
+ except BundleContractError as e:
1684
+ console.print(f"[red]Bundle contract rejected: {escape(safe_text(str(e)))}[/red]")
1685
+ raise typer.Exit(code=1)
1686
+
1625
1687
  except AethisAPIError as e:
1626
1688
  error_panel(e)
1627
1689
  # An API error anywhere in the run — including mid-poll, where the job
@@ -1650,6 +1712,89 @@ def _run_generate(
1650
1712
  raise typer.Exit(code=1)
1651
1713
 
1652
1714
 
1715
+ class BundleContractError(Exception):
1716
+ """The local bundle contract file cannot safely reach an engine."""
1717
+
1718
+
1719
+ _BUNDLE_CONTRACT_KEYS = ("schema_version", "input_invariants")
1720
+
1721
+
1722
+ def _load_bundle_contract(project_dir: Path) -> Optional[bytes]:
1723
+ """Load, check and serialise ``contracts/bundle.yaml`` in one guarded step.
1724
+
1725
+ Returns the exact JSON bytes to send, or ``None`` when there is no file.
1726
+ Anything that goes wrong while reading, parsing, checking or serialising is
1727
+ one refusal that names the file, so no other encoder can disagree with the
1728
+ body that was checked. Only the top-level shape is checked here; the engine
1729
+ validates the invariants themselves.
1730
+ """
1731
+ path = project_dir / "contracts" / "bundle.yaml"
1732
+ if not path.is_file():
1733
+ return None
1734
+ try:
1735
+ return _check_bundle_contract(path)
1736
+ except BundleContractError:
1737
+ raise
1738
+ except Exception as e: # noqa: BLE001 - every failure here is the same refusal
1739
+ raise BundleContractError(
1740
+ f"{path} could not be read as a bundle contract ({type(e).__name__}: {e}); "
1741
+ 'quote dates and other special values, for example "2000-01-01"'
1742
+ ) from None
1743
+
1744
+
1745
+ def _check_bundle_contract(path: Path) -> bytes:
1746
+ raw = yaml.load(path.read_text(encoding="utf-8"), Loader=_UniqueKeyLoader)
1747
+ if not isinstance(raw, dict):
1748
+ raise BundleContractError(f"{path} must be a YAML mapping with schema_version: 1 and input_invariants")
1749
+ unknown = [k for k in raw if k not in _BUNDLE_CONTRACT_KEYS]
1750
+ if unknown:
1751
+ raise BundleContractError(
1752
+ f"{path} has unknown top-level key(s) {', '.join(repr(str(k)) for k in unknown)}; "
1753
+ f"the allowed keys are {', '.join(_BUNDLE_CONTRACT_KEYS)}"
1754
+ )
1755
+ version = raw.get("schema_version")
1756
+ if type(version) is not int or version != 1:
1757
+ raise BundleContractError(f"{path} must set schema_version: 1 (an integer)")
1758
+ invariants = raw.get("input_invariants")
1759
+ if not isinstance(invariants, list) or not invariants:
1760
+ raise BundleContractError(
1761
+ f"{path} must set input_invariants to a non-empty list; "
1762
+ "to clear the stored contract, delete the file instead"
1763
+ )
1764
+ return json.dumps(raw, allow_nan=False).encode("utf-8")
1765
+
1766
+
1767
+ def _stored_digest(payload: Any) -> Optional[str]:
1768
+ digest = payload.get("bundle_contract_digest") if isinstance(payload, dict) else None
1769
+ return digest if isinstance(digest, str) and digest else None
1770
+
1771
+
1772
+ def _send_bundle_contract(
1773
+ client: AethisClient, pid: str, contract: Optional[bytes], advertised: Optional[bool]
1774
+ ) -> Optional[str]:
1775
+ """Send the contract (or, with no file, clear a stale one); return the engine's digest."""
1776
+ if contract is not None:
1777
+ result = client.set_bundle_contract(pid, contract)
1778
+ digest = _stored_digest(result)
1779
+ if digest is None:
1780
+ raise BundleContractError("the engine did not return a bundle contract digest; stopping before generation")
1781
+ info(f"Bundle contract stored ({digest})")
1782
+ return digest
1783
+ if advertised is None:
1784
+ warn("A stored bundle contract could not be checked (the engine's API schema could not be read); continuing.")
1785
+ return None
1786
+ if advertised is True:
1787
+ try:
1788
+ stored = _stored_digest(client.get_project(pid))
1789
+ except (AethisAPIError, httpx.HTTPError):
1790
+ warn("A stored bundle contract could not be checked (the project lookup failed); continuing.")
1791
+ return None
1792
+ if stored is not None:
1793
+ client.set_bundle_contract(pid, b'{"schema_version": 1}')
1794
+ info("No contracts/bundle.yaml: cleared the bundle contract stored on the project")
1795
+ return None
1796
+
1797
+
1653
1798
  def _upload_test_cases(
1654
1799
  client: AethisClient,
1655
1800
  pid: str,
@@ -2091,6 +2236,7 @@ def _poll_until_done(
2091
2236
  *,
2092
2237
  no_publish: bool = False,
2093
2238
  shown_thinking_warnings: Optional[set[tuple[str, str]]] = None,
2239
+ expected_bundle_digest: Optional[str] = None,
2094
2240
  ) -> GenerationOutcome:
2095
2241
  """Poll a generation to completion and report how it ended.
2096
2242
 
@@ -2168,6 +2314,16 @@ def _poll_until_done(
2168
2314
  # stays as the fallback because engines that record nothing on
2169
2315
  # the job still have to yield something usable.
2170
2316
  ruleset_id = _resolved_ruleset_id(result)
2317
+ if expected_bundle_digest is not None:
2318
+ seen = job.get("bundle_contract_digest")
2319
+ if seen != expected_bundle_digest:
2320
+ console.print()
2321
+ console.print(
2322
+ "[bold red]Bundle contract not captured:[/bold red] the build reports "
2323
+ f"{escape(safe_text(str(seen)))} but the stored contract is {expected_bundle_digest}. "
2324
+ "Nothing was published."
2325
+ )
2326
+ return GenerationOutcome("contract_mismatch", ruleset_id, job.get("value_spaces_resolved"))
2171
2327
  # The status payload the source questions are read from: the
2172
2328
  # engine attaches them only once the job names its ruleset, so
2173
2329
  # keep the latest one the re-poll below fetches.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aethis-cli
3
- Version: 0.53.2
3
+ Version: 0.55.0
4
4
  Summary: CLI for the Aethis developer API — author, test, and publish rulesets
5
5
  Author-email: Aethis <eng@aethis.ai>
6
6
  License-Expression: MIT
@@ -299,6 +299,10 @@ If a publish fails after files were uploaded, those files stay in the project
299
299
  and are reused on the next attempt (matched by `sha256`), so retrying does not
300
300
  duplicate them.
301
301
 
302
+ ### Bundle contract (input invariants)
303
+
304
+ Add `contracts/bundle.yaml` to the project folder (beside `fields/` and `tests/`) to declare consistency rules across inputs, for example that an end date must not be before a start date. `aethis generate` and `aethis refine` send it before generation and confirm the build captured it. To clear a stored contract, delete the file: the next run clears it (on an engine that supports it). See the CHANGELOG entry for 0.54.0 for the file format.
305
+
302
306
  ### Guidance (project-level)
303
307
 
304
308
  Project guidance lives in `.aethis/guidance/hints.yaml` and is uploaded by `aethis generate`. These commands manage hints server-side after upload.
@@ -463,8 +467,20 @@ tests:
463
467
  space.medical.cert_valid: false
464
468
  expect:
465
469
  outcome: not_eligible
470
+ - name: "Undetermined — renewal before joined"
471
+ inputs:
472
+ member.joined_date: "2026-05-01"
473
+ member.renewal_date: "2026-04-01"
474
+ expect:
475
+ outcome: undetermined
476
+ field_errors:
477
+ member.renewal_date: The renewal date must not be before the joined date.
466
478
  ```
467
479
 
480
+ `field_errors` asserts that a rule from `contracts/bundle.yaml` rejected the input:
481
+ it maps each field id to the exact message you authored, and is only valid with
482
+ `outcome: undetermined`. An older API host may reject the key; the host's message is shown as-is.
483
+
468
484
  This file is the authoritative suite: `aethis generate` uploads it in full and
469
485
  **replaces** the project's test cases with it, so running generate twice leaves
470
486
  one copy, not two. The upload reports how many existing cases it overwrote. An
@@ -56,6 +56,7 @@ tests/test_acceptance_contract.py
56
56
  tests/test_account_cmd.py
57
57
  tests/test_auth.py
58
58
  tests/test_auth_providers.py
59
+ tests/test_bundle_contract.py
59
60
  tests/test_cancel_cmd.py
60
61
  tests/test_capability_boundary.py
61
62
  tests/test_client.py
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "aethis-cli"
3
- version = "0.53.2"
3
+ version = "0.55.0"
4
4
  description = "CLI for the Aethis developer API — author, test, and publish rulesets"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"
@@ -653,3 +653,134 @@ def test_run_rejects_contract_boundaries_before_any_remote_call(tmp_path, monkey
653
653
 
654
654
  assert raised.value.exit_code == 1
655
655
  assert client.method_calls == []
656
+
657
+
658
+ # --- field_errors expectation -------------------------------------------------
659
+
660
+ _FIELD_ERRORS = {"member.renewal_date": "The renewal date must not be before the joined date."}
661
+
662
+
663
+ def _field_errors_case(**overrides: object) -> dict:
664
+ case: dict = {
665
+ "name": "renewal before joined",
666
+ "field_values": {"member.joined_date": "2026-05-01", "member.renewal_date": "2026-04-01"},
667
+ "expected_outcome": "undetermined",
668
+ "expectations": {"field_errors": dict(_FIELD_ERRORS)},
669
+ }
670
+ case.update(overrides)
671
+ return case
672
+
673
+
674
+ def test_field_errors_in_normalised_shape_is_accepted_and_transported(tmp_path):
675
+ contract = {"contract_version": 1, "test_cases": [_field_errors_case()]}
676
+ loaded = generate_cmd._load_acceptance_contract(_write_contract(tmp_path, contract))
677
+ assert loaded["test_cases"][0]["expected_outcome"] == "undetermined"
678
+ assert loaded["test_cases"][0]["expectations"] == {"field_errors": _FIELD_ERRORS}
679
+
680
+
681
+ def test_field_errors_in_expect_author_shape_is_normalised(tmp_path):
682
+ tests = tmp_path / "tests"
683
+ tests.mkdir()
684
+ (tests / "scenarios.yaml").write_text(
685
+ """tests:
686
+ - name: renewal before joined
687
+ inputs: {member.joined_date: "2026-05-01", member.renewal_date: "2026-04-01"}
688
+ expect:
689
+ outcome: undetermined
690
+ field_errors:
691
+ member.renewal_date: The renewal date must not be before the joined date.
692
+ """,
693
+ encoding="utf-8",
694
+ )
695
+ contract, _name = generate_cmd._load_scenarios_contract(tmp_path)
696
+ case = contract["test_cases"][0]
697
+ assert case["expected_outcome"] == "undetermined"
698
+ assert case["expectations"] == {"field_errors": _FIELD_ERRORS}
699
+
700
+
701
+ def test_field_errors_may_sit_beside_other_expectations(tmp_path):
702
+ case = _field_errors_case()
703
+ case["expectations"]["useful_unknown_fields"] = ["member.joined_date"]
704
+ case["expectations"]["pending_reviews"] = {"resolution_fields": ["member.joined_date"], "unmapped_count": 0}
705
+ loaded = generate_cmd._load_acceptance_contract(
706
+ _write_contract(tmp_path, {"contract_version": 1, "test_cases": [case]})
707
+ )
708
+ assert loaded["test_cases"][0]["expectations"] == case["expectations"]
709
+
710
+
711
+ def test_contract_without_field_errors_is_unchanged(tmp_path):
712
+ loaded = generate_cmd._load_acceptance_contract(_write_contract(tmp_path, _contract()))
713
+ assert loaded == _contract()
714
+ # Literal computed on the previous release (origin/main before field_errors) for this exact contract.
715
+ assert (
716
+ generate_cmd._acceptance_contract_digest(loaded)
717
+ == "sha256:15acfcf51d581642f276188f7d55a761dace4290eb8b013a2a8c89b125b04841"
718
+ )
719
+
720
+
721
+ def test_field_error_message_boundaries_and_whitespace(tmp_path):
722
+ for message in ("m" * 20000, " "):
723
+ case = _field_errors_case()
724
+ case["expectations"] = {"field_errors": {"f": message}}
725
+ loaded = generate_cmd._load_acceptance_contract(
726
+ _write_contract(tmp_path, {"contract_version": 1, "test_cases": [case]})
727
+ )
728
+ assert loaded["test_cases"][0]["expectations"]["field_errors"] == {"f": message}
729
+
730
+
731
+ @pytest.mark.parametrize(
732
+ ("field_errors", "outcome", "message"),
733
+ [
734
+ ({}, "undetermined", r"expectations\.field_errors must be a non-empty object"),
735
+ ([], "undetermined", r"expectations\.field_errors must be a non-empty object"),
736
+ ("x", "undetermined", r"expectations\.field_errors must be a non-empty object"),
737
+ ({"": "msg"}, "undetermined", r"expectations\.field_errors keys must be non-empty strings"),
738
+ ({"f": 3}, "undetermined", r"expectations\.field_errors\['f'\] must be a non-empty string"),
739
+ ({"f": ""}, "undetermined", r"expectations\.field_errors\['f'\] must be a non-empty string"),
740
+ ({"f": None}, "undetermined", r"expectations\.field_errors\['f'\] must be a non-empty string"),
741
+ ({"f" * 301: "msg"}, "undetermined", r"keys must be at most 300"),
742
+ ({"f": "m" * 20001}, "undetermined", r"must be at most 20000"),
743
+ ({"f": "msg"}, "eligible", r"field_errors is only valid when expected_outcome is undetermined"),
744
+ ({"f": "msg"}, "not_eligible", r"field_errors is only valid when expected_outcome is undetermined"),
745
+ ],
746
+ )
747
+ def test_field_errors_refusals_in_normalised_shape(tmp_path, field_errors, outcome, message):
748
+ case = _field_errors_case(expected_outcome=outcome)
749
+ case["expectations"] = {"field_errors": field_errors}
750
+ path = _write_contract(tmp_path, {"contract_version": 1, "test_cases": [case]})
751
+ with pytest.raises(generate_cmd.AcceptanceContractError, match=message):
752
+ generate_cmd._load_acceptance_contract(path)
753
+
754
+
755
+ @pytest.mark.parametrize("outcome", ["eligible", "not_eligible"])
756
+ def test_field_errors_refused_for_wrong_outcome_in_expect_shape(tmp_path, outcome):
757
+ tests = tmp_path / "tests"
758
+ tests.mkdir()
759
+ (tests / "scenarios.yaml").write_text(
760
+ f"""tests:
761
+ - name: wrong outcome
762
+ inputs: {{}}
763
+ expect:
764
+ outcome: {outcome}
765
+ field_errors: {{member.renewal_date: Too early.}}
766
+ """,
767
+ encoding="utf-8",
768
+ )
769
+ with pytest.raises(generate_cmd.AcceptanceContractError, match="only valid when expected_outcome is undetermined"):
770
+ generate_cmd._load_scenarios_contract(tmp_path)
771
+
772
+
773
+ def test_field_errors_refused_in_expect_shape_when_outcome_defaults(tmp_path):
774
+ tests = tmp_path / "tests"
775
+ tests.mkdir()
776
+ (tests / "scenarios.yaml").write_text(
777
+ """tests:
778
+ - name: default outcome
779
+ inputs: {}
780
+ expect:
781
+ field_errors: {member.renewal_date: Too early.}
782
+ """,
783
+ encoding="utf-8",
784
+ )
785
+ with pytest.raises(generate_cmd.AcceptanceContractError, match="only valid when expected_outcome is undetermined"):
786
+ generate_cmd._load_scenarios_contract(tmp_path)