hapax-spine 0.1.1__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 (47) hide show
  1. hapax_spine-0.1.1/.gitignore +7 -0
  2. hapax_spine-0.1.1/LICENSE +104 -0
  3. hapax_spine-0.1.1/PKG-INFO +175 -0
  4. hapax_spine-0.1.1/README.md +51 -0
  5. hapax_spine-0.1.1/pyproject.toml +32 -0
  6. hapax_spine-0.1.1/src/hapax/spine/__init__.py +15 -0
  7. hapax_spine-0.1.1/src/hapax/spine/_config.py +58 -0
  8. hapax_spine-0.1.1/src/hapax/spine/affordance.py +332 -0
  9. hapax_spine-0.1.1/src/hapax/spine/coord_capabilities.py +587 -0
  10. hapax_spine-0.1.1/src/hapax/spine/coord_event_log.py +1115 -0
  11. hapax_spine-0.1.1/src/hapax/spine/coord_projection.py +527 -0
  12. hapax_spine-0.1.1/src/hapax/spine/dispatcher_policy.py +2809 -0
  13. hapax_spine-0.1.1/src/hapax/spine/edt_measure.py +923 -0
  14. hapax_spine-0.1.1/src/hapax/spine/gate_event_producer.py +310 -0
  15. hapax_spine-0.1.1/src/hapax/spine/gate_log.py +110 -0
  16. hapax_spine-0.1.1/src/hapax/spine/jsonl_append.py +137 -0
  17. hapax_spine-0.1.1/src/hapax/spine/langfuse_client.py +177 -0
  18. hapax_spine-0.1.1/src/hapax/spine/platform_capability_receipts.py +197 -0
  19. hapax_spine-0.1.1/src/hapax/spine/platform_capability_registry.py +1545 -0
  20. hapax_spine-0.1.1/src/hapax/spine/py.typed +0 -0
  21. hapax_spine-0.1.1/src/hapax/spine/quota_spend_ledger.py +1618 -0
  22. hapax_spine-0.1.1/src/hapax/spine/route_metadata_schema.py +2470 -0
  23. hapax_spine-0.1.1/src/hapax/spine/sdlc_router.py +650 -0
  24. hapax_spine-0.1.1/tests/fixtures/edt-platform-knobs.yaml +42 -0
  25. hapax_spine-0.1.1/tests/fixtures/platform-capability-registry.json +3876 -0
  26. hapax_spine-0.1.1/tests/fixtures/platform-capability-registry.schema.json +581 -0
  27. hapax_spine-0.1.1/tests/fixtures/quota-spend-ledger-fixtures.json +300 -0
  28. hapax_spine-0.1.1/tests/test_coord_capabilities.py +295 -0
  29. hapax_spine-0.1.1/tests/test_coord_event_log.py +431 -0
  30. hapax_spine-0.1.1/tests/test_coord_event_log_boot_reconcile.py +100 -0
  31. hapax_spine-0.1.1/tests/test_coord_event_log_cli.py +159 -0
  32. hapax_spine-0.1.1/tests/test_coord_event_log_spool_nonce.py +76 -0
  33. hapax_spine-0.1.1/tests/test_coord_projection.py +460 -0
  34. hapax_spine-0.1.1/tests/test_dispatcher_capability_fit_dimensions.py +449 -0
  35. hapax_spine-0.1.1/tests/test_dispatcher_policy.py +1748 -0
  36. hapax_spine-0.1.1/tests/test_edt_measure.py +775 -0
  37. hapax_spine-0.1.1/tests/test_gate_event_producer.py +130 -0
  38. hapax_spine-0.1.1/tests/test_gate_log.py +75 -0
  39. hapax_spine-0.1.1/tests/test_jsonl_append.py +212 -0
  40. hapax_spine-0.1.1/tests/test_langfuse_client.py +327 -0
  41. hapax_spine-0.1.1/tests/test_platform_capability_receipts.py +906 -0
  42. hapax_spine-0.1.1/tests/test_platform_capability_registry.py +611 -0
  43. hapax_spine-0.1.1/tests/test_quota_spend_ledger.py +777 -0
  44. hapax_spine-0.1.1/tests/test_quota_spend_ledger_claude_seed.py +144 -0
  45. hapax_spine-0.1.1/tests/test_route_metadata_schema.py +847 -0
  46. hapax_spine-0.1.1/tests/test_sdlc_router.py +689 -0
  47. hapax_spine-0.1.1/uv.lock +184 -0
@@ -0,0 +1,7 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.pyc
4
+ dist/
5
+ *.egg-info/
6
+ .pytest_cache/
7
+ .ruff_cache/
@@ -0,0 +1,104 @@
1
+ Business Source License 1.1
2
+
3
+ License text copyright (c) 2020 MariaDB Corporation Ab, All Rights Reserved.
4
+ "Business Source License" is a trademark of MariaDB Corporation Ab.
5
+
6
+ -----------------------------------------------------------------------------
7
+
8
+ Parameters
9
+
10
+ Licensor: Hapax Research LLC
11
+ Licensed Work: hapax-spine — the SDLC-runtime mechanism (append-only coord
12
+ event ledger, dispatch-policy evaluator, capability
13
+ registry + receipts, quota arithmetic, EDT measurement,
14
+ gate-event producer) for the Hapax n-DLC automation system.
15
+ The Licensed Work is (c) 2026 Hapax Research LLC.
16
+ Additional Use Grant: You may make production use of the Licensed Work, provided
17
+ that such production use does not include offering the
18
+ Licensed Work (or any modified or derivative version of it)
19
+ to third parties as a hosted or managed service whose
20
+ primary value to those third parties is the governed
21
+ n-DLC / agent-lifecycle automation that the Licensed Work
22
+ provides.
23
+ Change Date: 2030-07-03
24
+ Change License: Apache License, Version 2.0
25
+
26
+ For information about alternative licensing arrangements for the Licensed Work,
27
+ please contact the Licensor.
28
+
29
+ -----------------------------------------------------------------------------
30
+
31
+ Terms
32
+
33
+ The Licensor hereby grants you the right to copy, modify, create derivative
34
+ works, redistribute, and make non-production use of the Licensed Work. The
35
+ Licensor may make an Additional Use Grant, above, permitting limited production
36
+ use.
37
+
38
+ Effective on the Change Date, or the fourth anniversary of the first publicly
39
+ available distribution of a specific version of the Licensed Work under this
40
+ License, whichever comes first, the Licensor hereby grants you rights under the
41
+ terms of the Change License, and the rights granted in the paragraph above
42
+ terminate.
43
+
44
+ If your use of the Licensed Work does not comply with the requirements currently
45
+ in effect as described in this License, you must purchase a commercial license
46
+ from the Licensor, its affiliated entities, or authorized resellers, or you must
47
+ refrain from using the Licensed Work.
48
+
49
+ All copies of the original and modified Licensed Work, and derivative works of
50
+ the Licensed Work, are subject to this License. This License applies separately
51
+ for each version of the Licensed Work and the Change Date may vary for each
52
+ version of the Licensed Work released by Licensor.
53
+
54
+ You must conspicuously display this License on each original or modified copy of
55
+ the Licensed Work. If you receive the Licensed Work in original or modified form
56
+ from a third party, the terms and conditions set forth in this License apply to
57
+ your use of that work.
58
+
59
+ Any use of the Licensed Work in violation of this License will automatically
60
+ terminate your rights under this License for the current and all other versions
61
+ of the Licensed Work.
62
+
63
+ This License does not grant you any right in any trademark or logo of Licensor or
64
+ its affiliates (provided that you may use a trademark or logo of Licensor as
65
+ expressly required by this License).
66
+
67
+ TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON AN
68
+ "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS
69
+ OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF MERCHANTABILITY, FITNESS
70
+ FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND TITLE.
71
+
72
+ MariaDB hereby grants you permission to use this License's text to license your
73
+ works, and to refer to it using the trademark "Business Source License", as long
74
+ as you comply with the Covenants of Licensor below.
75
+
76
+ -----------------------------------------------------------------------------
77
+
78
+ Covenants of Licensor
79
+
80
+ In consideration of the right to use this License's text and the "Business Source
81
+ License" name and trademark, Licensor covenants to MariaDB, and to all other
82
+ recipients of the licensed work to be provided by Licensor:
83
+
84
+ 1. To specify as the Change License the GPL Version 2.0 or any later version, or
85
+ a license that is compatible with GPL Version 2.0 or a later version, where
86
+ "compatible" means that software provided under the Change License can be
87
+ included in a program with software provided under GPL Version 2.0 or a later
88
+ version. Licensor may specify additional Change Licenses without limitation.
89
+
90
+ 2. To either: (a) specify an additional grant of rights to use that does not
91
+ impose any additional restriction on the right granted in this License, as the
92
+ Additional Use Grant; or (b) insert the text "None".
93
+
94
+ 3. To specify a Change Date.
95
+
96
+ 4. Not to modify this License in any other way.
97
+
98
+ -----------------------------------------------------------------------------
99
+
100
+ Notices
101
+
102
+ The Business Source License (this document, or the "License") is not an Open
103
+ Source license. However, the Licensed Work will eventually be made available
104
+ under an Open Source License, as stated in this License.
@@ -0,0 +1,175 @@
1
+ Metadata-Version: 2.4
2
+ Name: hapax-spine
3
+ Version: 0.1.1
4
+ Summary: The SDLC-runtime mechanism (coord ledger, dispatch-policy evaluator, capability registry + receipts, quota arithmetic, EDT measurement, gate-event producer) for the Hapax n-DLC automation system.
5
+ Project-URL: Homepage, https://github.com/hapax-systems/hapax-spine
6
+ Project-URL: Repository, https://github.com/hapax-systems/hapax-spine
7
+ Author: Hapax Research LLC
8
+ License: Business Source License 1.1
9
+
10
+ License text copyright (c) 2020 MariaDB Corporation Ab, All Rights Reserved.
11
+ "Business Source License" is a trademark of MariaDB Corporation Ab.
12
+
13
+ -----------------------------------------------------------------------------
14
+
15
+ Parameters
16
+
17
+ Licensor: Hapax Research LLC
18
+ Licensed Work: hapax-spine — the SDLC-runtime mechanism (append-only coord
19
+ event ledger, dispatch-policy evaluator, capability
20
+ registry + receipts, quota arithmetic, EDT measurement,
21
+ gate-event producer) for the Hapax n-DLC automation system.
22
+ The Licensed Work is (c) 2026 Hapax Research LLC.
23
+ Additional Use Grant: You may make production use of the Licensed Work, provided
24
+ that such production use does not include offering the
25
+ Licensed Work (or any modified or derivative version of it)
26
+ to third parties as a hosted or managed service whose
27
+ primary value to those third parties is the governed
28
+ n-DLC / agent-lifecycle automation that the Licensed Work
29
+ provides.
30
+ Change Date: 2030-07-03
31
+ Change License: Apache License, Version 2.0
32
+
33
+ For information about alternative licensing arrangements for the Licensed Work,
34
+ please contact the Licensor.
35
+
36
+ -----------------------------------------------------------------------------
37
+
38
+ Terms
39
+
40
+ The Licensor hereby grants you the right to copy, modify, create derivative
41
+ works, redistribute, and make non-production use of the Licensed Work. The
42
+ Licensor may make an Additional Use Grant, above, permitting limited production
43
+ use.
44
+
45
+ Effective on the Change Date, or the fourth anniversary of the first publicly
46
+ available distribution of a specific version of the Licensed Work under this
47
+ License, whichever comes first, the Licensor hereby grants you rights under the
48
+ terms of the Change License, and the rights granted in the paragraph above
49
+ terminate.
50
+
51
+ If your use of the Licensed Work does not comply with the requirements currently
52
+ in effect as described in this License, you must purchase a commercial license
53
+ from the Licensor, its affiliated entities, or authorized resellers, or you must
54
+ refrain from using the Licensed Work.
55
+
56
+ All copies of the original and modified Licensed Work, and derivative works of
57
+ the Licensed Work, are subject to this License. This License applies separately
58
+ for each version of the Licensed Work and the Change Date may vary for each
59
+ version of the Licensed Work released by Licensor.
60
+
61
+ You must conspicuously display this License on each original or modified copy of
62
+ the Licensed Work. If you receive the Licensed Work in original or modified form
63
+ from a third party, the terms and conditions set forth in this License apply to
64
+ your use of that work.
65
+
66
+ Any use of the Licensed Work in violation of this License will automatically
67
+ terminate your rights under this License for the current and all other versions
68
+ of the Licensed Work.
69
+
70
+ This License does not grant you any right in any trademark or logo of Licensor or
71
+ its affiliates (provided that you may use a trademark or logo of Licensor as
72
+ expressly required by this License).
73
+
74
+ TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON AN
75
+ "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS
76
+ OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF MERCHANTABILITY, FITNESS
77
+ FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND TITLE.
78
+
79
+ MariaDB hereby grants you permission to use this License's text to license your
80
+ works, and to refer to it using the trademark "Business Source License", as long
81
+ as you comply with the Covenants of Licensor below.
82
+
83
+ -----------------------------------------------------------------------------
84
+
85
+ Covenants of Licensor
86
+
87
+ In consideration of the right to use this License's text and the "Business Source
88
+ License" name and trademark, Licensor covenants to MariaDB, and to all other
89
+ recipients of the licensed work to be provided by Licensor:
90
+
91
+ 1. To specify as the Change License the GPL Version 2.0 or any later version, or
92
+ a license that is compatible with GPL Version 2.0 or a later version, where
93
+ "compatible" means that software provided under the Change License can be
94
+ included in a program with software provided under GPL Version 2.0 or a later
95
+ version. Licensor may specify additional Change Licenses without limitation.
96
+
97
+ 2. To either: (a) specify an additional grant of rights to use that does not
98
+ impose any additional restriction on the right granted in this License, as the
99
+ Additional Use Grant; or (b) insert the text "None".
100
+
101
+ 3. To specify a Change Date.
102
+
103
+ 4. Not to modify this License in any other way.
104
+
105
+ -----------------------------------------------------------------------------
106
+
107
+ Notices
108
+
109
+ The Business Source License (this document, or the "License") is not an Open
110
+ Source license. However, the Licensed Work will eventually be made available
111
+ under an Open Source License, as stated in this License.
112
+ License-File: LICENSE
113
+ Keywords: agent-orchestration,capability-routing,dispatch,governance,n-dlc,sdlc,witnessed-ledger
114
+ Classifier: Development Status :: 3 - Alpha
115
+ Classifier: Intended Audience :: Developers
116
+ Classifier: License :: Other/Proprietary License
117
+ Classifier: Programming Language :: Python :: 3
118
+ Classifier: Programming Language :: Python :: 3.12
119
+ Classifier: Typing :: Typed
120
+ Requires-Python: >=3.12
121
+ Requires-Dist: pydantic>=2
122
+ Requires-Dist: pyyaml>=6
123
+ Description-Content-Type: text/markdown
124
+
125
+ # hapax-spine
126
+
127
+ **The SDLC-runtime mechanism behind the Hapax n-DLC automation system, as a small Python wheel.** It is
128
+ the governed core that turns a stream of work events into scored, routable, auditable state:
129
+
130
+ - an **append-only coordination event ledger** (+ its projection engine),
131
+ - a **capability registry + receipts** (capabilities identified by attested, measured behavior),
132
+ - a **dispatch-policy evaluator** (fail-closed, receipt-backed),
133
+ - **quota / spend arithmetic**, an **EDT** (equal-depth-of-treatment) fairness measurement engine, and a
134
+ **gate-event producer** (the observational evidence stream).
135
+
136
+ It is dependency-light (`pydantic`, `pyyaml`) and consumed by [reins](https://github.com/hapax-systems/reins)
137
+ (the cockpit) and, internally, by hapax-council.
138
+
139
+ ## Install
140
+
141
+ ```sh
142
+ uv add hapax-spine # or: pip install hapax-spine
143
+ ```
144
+
145
+ ## Use
146
+
147
+ ```python
148
+ import hapax.spine.dispatcher_policy as dp
149
+ import hapax.spine.platform_capability_registry as reg
150
+
151
+ # The instance supplies its config-DATA dir (the registry, quota fixtures, EDT knobs)
152
+ # via HAPAX_SPINE_CONFIG_DIR (or pass an explicit path). Import is always safe; only an
153
+ # unconfigured *load* fails loud.
154
+ registry = reg.load_platform_capability_registry() # env-injected path
155
+ sources = dp.load_dispatch_policy_sources(registry_path=my_registry_json) # or explicit
156
+ ```
157
+
158
+ Set `HAPAX_SPINE_CONFIG_DIR` (and `HAPAX_SPINE_REPO_ROOT`) to your instance's config directory.
159
+
160
+ ## Honest scope
161
+
162
+ hapax-spine ships the **mechanism**. In v0.1.x the instance **taxonomy** — the routing-class keyspace,
163
+ the reqvec dimensions, the provider/payment rails — ships as *council-default vocabulary*, not yet fully
164
+ injected (see the v1.1 instance-free milestone). So a second instance runs the same engine but currently
165
+ inherits those defaults; making the taxonomy (and the governance axioms) fully injectable is on the
166
+ roadmap. We don't claim capability-/axiom-agnosticism the code doesn't yet deliver.
167
+
168
+ The 15 modules were extracted history-preserving from hapax-council; the wheel is agents/logos-free and
169
+ imports only `pydantic` + `pyyaml`.
170
+
171
+ ## License
172
+
173
+ Source-available under the **Business Source License 1.1** (see `LICENSE`): free for all non-competing
174
+ use — self-host, build on it, run your own instance — converting to Apache-2.0 on the change date. Only
175
+ offering it as a competing hosted service is reserved.
@@ -0,0 +1,51 @@
1
+ # hapax-spine
2
+
3
+ **The SDLC-runtime mechanism behind the Hapax n-DLC automation system, as a small Python wheel.** It is
4
+ the governed core that turns a stream of work events into scored, routable, auditable state:
5
+
6
+ - an **append-only coordination event ledger** (+ its projection engine),
7
+ - a **capability registry + receipts** (capabilities identified by attested, measured behavior),
8
+ - a **dispatch-policy evaluator** (fail-closed, receipt-backed),
9
+ - **quota / spend arithmetic**, an **EDT** (equal-depth-of-treatment) fairness measurement engine, and a
10
+ **gate-event producer** (the observational evidence stream).
11
+
12
+ It is dependency-light (`pydantic`, `pyyaml`) and consumed by [reins](https://github.com/hapax-systems/reins)
13
+ (the cockpit) and, internally, by hapax-council.
14
+
15
+ ## Install
16
+
17
+ ```sh
18
+ uv add hapax-spine # or: pip install hapax-spine
19
+ ```
20
+
21
+ ## Use
22
+
23
+ ```python
24
+ import hapax.spine.dispatcher_policy as dp
25
+ import hapax.spine.platform_capability_registry as reg
26
+
27
+ # The instance supplies its config-DATA dir (the registry, quota fixtures, EDT knobs)
28
+ # via HAPAX_SPINE_CONFIG_DIR (or pass an explicit path). Import is always safe; only an
29
+ # unconfigured *load* fails loud.
30
+ registry = reg.load_platform_capability_registry() # env-injected path
31
+ sources = dp.load_dispatch_policy_sources(registry_path=my_registry_json) # or explicit
32
+ ```
33
+
34
+ Set `HAPAX_SPINE_CONFIG_DIR` (and `HAPAX_SPINE_REPO_ROOT`) to your instance's config directory.
35
+
36
+ ## Honest scope
37
+
38
+ hapax-spine ships the **mechanism**. In v0.1.x the instance **taxonomy** — the routing-class keyspace,
39
+ the reqvec dimensions, the provider/payment rails — ships as *council-default vocabulary*, not yet fully
40
+ injected (see the v1.1 instance-free milestone). So a second instance runs the same engine but currently
41
+ inherits those defaults; making the taxonomy (and the governance axioms) fully injectable is on the
42
+ roadmap. We don't claim capability-/axiom-agnosticism the code doesn't yet deliver.
43
+
44
+ The 15 modules were extracted history-preserving from hapax-council; the wheel is agents/logos-free and
45
+ imports only `pydantic` + `pyyaml`.
46
+
47
+ ## License
48
+
49
+ Source-available under the **Business Source License 1.1** (see `LICENSE`): free for all non-competing
50
+ use — self-host, build on it, run your own instance — converting to Apache-2.0 on the change date. Only
51
+ offering it as a competing hosted service is reserved.
@@ -0,0 +1,32 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "hapax-spine"
7
+ version = "0.1.1"
8
+ description = "The SDLC-runtime mechanism (coord ledger, dispatch-policy evaluator, capability registry + receipts, quota arithmetic, EDT measurement, gate-event producer) for the Hapax n-DLC automation system."
9
+ readme = "README.md"
10
+ requires-python = ">=3.12"
11
+ license = { file = "LICENSE" }
12
+ authors = [{ name = "Hapax Research LLC" }]
13
+ keywords = ["sdlc", "n-dlc", "agent-orchestration", "capability-routing", "dispatch", "governance", "witnessed-ledger"]
14
+ classifiers = [
15
+ "Development Status :: 3 - Alpha",
16
+ "Intended Audience :: Developers",
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3.12",
19
+ "Typing :: Typed",
20
+ "License :: Other/Proprietary License",
21
+ ]
22
+ dependencies = ["pydantic>=2", "pyyaml>=6"]
23
+
24
+ [project.urls]
25
+ Homepage = "https://github.com/hapax-systems/hapax-spine"
26
+ Repository = "https://github.com/hapax-systems/hapax-spine"
27
+
28
+ [tool.hatch.build.targets.wheel]
29
+ packages = ["src/hapax"]
30
+
31
+ [tool.hatch.metadata]
32
+ allow-direct-references = true
@@ -0,0 +1,15 @@
1
+ """hapax-spine — the SDLC-runtime MECHANISM, extracted history-preserving from hapax-council.
2
+
3
+ The append-only coord event ledger, the projection engine, the capability registry + receipts,
4
+ quota arithmetic, the dispatch-policy evaluator, the gate-event producer, and the EDT measurement
5
+ engine — the ~9.6k-LOC agents/logos-free cluster reins consumes.
6
+
7
+ v1 note (honest): the routing-class keyspace (frozen-11), reqvec dims, and provider/payment rails
8
+ ship as council-DEFAULT vocabulary, not yet fully injected — see the v1.1 instance-free milestone.
9
+ Config-DATA paths ARE injected: set HAPAX_SPINE_CONFIG_DIR (and HAPAX_SPINE_REPO_ROOT) or pass an
10
+ explicit path to the loaders; an unconfigured *load* fails loud, while *import* never raises.
11
+ """
12
+
13
+ from hapax.spine.edt_measure import NUM_ROUTING_CLASSES, ROUTING_CLASSES
14
+
15
+ __all__ = ["ROUTING_CLASSES", "NUM_ROUTING_CLASSES"]
@@ -0,0 +1,58 @@
1
+ """Import-safe config-DATA path resolution for hapax-spine.
2
+
3
+ The instance injects its config DATA dir (the platform-capability registry, quota fixtures, EDT knobs)
4
+ via ``HAPAX_SPINE_CONFIG_DIR`` — set it in the process env before import (council, reins, and the wheel's
5
+ own tests all do), or pass an explicit path to a loader.
6
+
7
+ INVARIANT (the extraction's verify-3 fix): module *import* NEVER raises — a module-level default is always
8
+ a real ``Path`` (a non-existent sentinel when unconfigured), so ``from hapax.spine.X import CONST`` stays
9
+ importable and typed. Only an actual *read* of an unconfigured path fails loud (the sentinel path literally
10
+ names the missing env var, so the error is self-describing).
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ import os
16
+ from pathlib import Path
17
+
18
+ CONFIG_DIR_ENV = "HAPAX_SPINE_CONFIG_DIR"
19
+ REPO_ROOT_ENV = "HAPAX_SPINE_REPO_ROOT"
20
+
21
+ # A path under this root can never exist, so an unconfigured open() fails loud while import stays safe.
22
+ _UNCONFIGURED_ROOT = Path("/nonexistent/hapax-spine__set_HAPAX_SPINE_CONFIG_DIR")
23
+
24
+
25
+ def _injected_config_dir() -> Path | None:
26
+ root = os.environ.get(CONFIG_DIR_ENV, "").strip()
27
+ return Path(root).expanduser() if root else None
28
+
29
+
30
+ def default_config_path(filename: str) -> Path:
31
+ """Eager module-constant value: the injected config dir joined to ``filename`` when the env is set at
32
+ import, else a self-describing non-existent sentinel. NEVER raises."""
33
+ d = _injected_config_dir()
34
+ return (d / filename) if d is not None else (_UNCONFIGURED_ROOT / filename)
35
+
36
+
37
+ def resolve_config_path(path: Path | None, filename: str) -> Path:
38
+ """Call-time loader resolver: an explicit ``path`` wins; else re-read the env FRESH (handles
39
+ env-set-after-import); FAIL LOUD when neither is available."""
40
+ if path is not None:
41
+ return Path(path)
42
+ d = _injected_config_dir()
43
+ if d is None:
44
+ raise RuntimeError(
45
+ f"hapax-spine: cannot load {filename!r} — set {CONFIG_DIR_ENV} to the instance config dir "
46
+ f"or pass an explicit path to the loader."
47
+ )
48
+ return d / filename
49
+
50
+
51
+ def repo_root() -> Path:
52
+ """The instance repo root (``HAPAX_SPINE_REPO_ROOT``), else the config dir's parent, else a sentinel.
53
+ Used only by relative-path resolvers that historically read council_root. Never raises."""
54
+ root = os.environ.get(REPO_ROOT_ENV, "").strip()
55
+ if root:
56
+ return Path(root).expanduser()
57
+ d = _injected_config_dir()
58
+ return d.parent if d is not None else _UNCONFIGURED_ROOT