spaex 5.4.2__tar.gz → 5.4.4__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 (111) hide show
  1. {spaex-5.4.2 → spaex-5.4.4}/PKG-INFO +2 -2
  2. {spaex-5.4.2 → spaex-5.4.4}/README.md +1 -1
  3. {spaex-5.4.2 → spaex-5.4.4}/pyproject.toml +1 -1
  4. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/cli/add.py +93 -183
  5. spaex-5.4.4/src/spaex/cli/singleton_categories.py +167 -0
  6. {spaex-5.4.2 → spaex-5.4.4}/src/spaex.egg-info/PKG-INFO +2 -2
  7. {spaex-5.4.2 → spaex-5.4.4}/src/spaex.egg-info/SOURCES.txt +1 -0
  8. {spaex-5.4.2 → spaex-5.4.4}/setup.cfg +0 -0
  9. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/__init__.py +0 -0
  10. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/__main__.py +0 -0
  11. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/behavior/__init__.py +0 -0
  12. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/behavior/bootstrap.py +0 -0
  13. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/behavior/clauses.py +0 -0
  14. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/behavior/composer/__init__.py +0 -0
  15. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/behavior/composer/batching.py +0 -0
  16. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/behavior/composer/clarifications.py +0 -0
  17. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/behavior/composer/clarify.py +0 -0
  18. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/behavior/composer/completeness.py +0 -0
  19. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/behavior/composer/failure.py +0 -0
  20. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/behavior/composer/invoke.py +0 -0
  21. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/behavior/composer/prompt.py +0 -0
  22. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/behavior/composer/reduce.py +0 -0
  23. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/behavior/emit.py +0 -0
  24. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/behavior/fragment.py +0 -0
  25. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/behavior/materialize.py +0 -0
  26. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/behavior/orchestrate.py +0 -0
  27. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/behavior/precheck.py +0 -0
  28. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/behavior/stale.py +0 -0
  29. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/cli/__init__.py +0 -0
  30. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/cli/behavior_commands.py +0 -0
  31. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/cli/constitution.py +0 -0
  32. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/cli/diagnostics.py +0 -0
  33. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/cli/install.py +0 -0
  34. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/cli/main.py +0 -0
  35. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/cli/reinstall_options.py +0 -0
  36. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/cli/remove.py +0 -0
  37. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/cli/skills.py +0 -0
  38. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/cli/status.py +0 -0
  39. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/constitution/__init__.py +0 -0
  40. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/constitution/publish.py +0 -0
  41. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/constitution/resolve.py +0 -0
  42. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/constitution/safety.py +0 -0
  43. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/constitution/show.py +0 -0
  44. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/git/__init__.py +0 -0
  45. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/git/cache.py +0 -0
  46. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/git/molecule_store.py +0 -0
  47. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/git/publisher_fetch.py +0 -0
  48. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/git/remote.py +0 -0
  49. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/git/revparse.py +0 -0
  50. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/git/show.py +0 -0
  51. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/install/__init__.py +0 -0
  52. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/install/delta.py +0 -0
  53. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/install/errors.py +0 -0
  54. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/install/generation.py +0 -0
  55. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/install/generic_atoms.py +0 -0
  56. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/install/git_env.py +0 -0
  57. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/install/git_exclude.py +0 -0
  58. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/install/hook_runner.py +0 -0
  59. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/install/inflight.py +0 -0
  60. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/install/local_publish.py +0 -0
  61. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/install/local_scope.py +0 -0
  62. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/install/lock.py +0 -0
  63. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/install/manifest_lock.py +0 -0
  64. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/install/nix_packages.py +0 -0
  65. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/install/overlay.py +0 -0
  66. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/install/side_effects.py +0 -0
  67. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/install/write_and_reinstall.py +0 -0
  68. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/integrations/__init__.py +0 -0
  69. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/integrations/runner.py +0 -0
  70. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/integrations/speckit.py +0 -0
  71. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/io/__init__.py +0 -0
  72. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/io/atomic.py +0 -0
  73. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/io/json_deterministic.py +0 -0
  74. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/io/state.py +0 -0
  75. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/io/transaction.py +0 -0
  76. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/io/writer_lock.py +0 -0
  77. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/model/__init__.py +0 -0
  78. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/model/_immutable.py +0 -0
  79. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/model/atom_category.py +0 -0
  80. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/model/consumer_manifest.py +0 -0
  81. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/model/install_lock.py +0 -0
  82. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/model/local_manifest.py +0 -0
  83. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/model/molecule_id.py +0 -0
  84. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/model/molecule_manifest.py +0 -0
  85. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/model/publisher_manifest.py +0 -0
  86. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/model/repo_relative_path.py +0 -0
  87. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/model/source_url.py +0 -0
  88. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/model/version_constraint.py +0 -0
  89. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/paths.py +0 -0
  90. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/report/__init__.py +0 -0
  91. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/report/compose.py +0 -0
  92. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/report/staleness.py +0 -0
  93. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/report/trace.py +0 -0
  94. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/schema/__init__.py +0 -0
  95. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/schema/data/consumer-manifest.v4.schema.json +0 -0
  96. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/schema/data/install-lock.v4.schema.json +0 -0
  97. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/schema/data/local-manifest.v1.schema.json +0 -0
  98. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/schema/data/molecule-manifest.v4.schema.json +0 -0
  99. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/schema/data/publisher-manifest.v4.schema.json +0 -0
  100. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/schema/loader.py +0 -0
  101. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/schema/validator.py +0 -0
  102. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/skills/__init__.py +0 -0
  103. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/skills/installer.py +0 -0
  104. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/util/__init__.py +0 -0
  105. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/util/errors.py +0 -0
  106. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/util/exit_codes.py +0 -0
  107. {spaex-5.4.2 → spaex-5.4.4}/src/spaex/util/path_containment.py +0 -0
  108. {spaex-5.4.2 → spaex-5.4.4}/src/spaex.egg-info/dependency_links.txt +0 -0
  109. {spaex-5.4.2 → spaex-5.4.4}/src/spaex.egg-info/entry_points.txt +0 -0
  110. {spaex-5.4.2 → spaex-5.4.4}/src/spaex.egg-info/requires.txt +0 -0
  111. {spaex-5.4.2 → spaex-5.4.4}/src/spaex.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: spaex
3
- Version: 5.4.2
3
+ Version: 5.4.4
4
4
  Summary: spaex 4.0: reproducible coding harnesses for any repo. Compose skills, MCPs, constitutions, slash commands, and dev-environment files into a single project; add/remove/install/migrate/constitution show CLI.
5
5
  Author: spaex contributors
6
6
  License: Apache-2.0
@@ -27,7 +27,7 @@ spaex composes a coding harness for a single repo out of reusable pieces (MCPs,
27
27
 
28
28
  ## What you can do today
29
29
 
30
- - `spaex add <source-url> <molecule-ids...>`: adopt one or more molecules from a publisher repo into `.spaex/manifest.json` and install them in one invocation.
30
+ - `spaex add <source-url> <molecule-ids...>`: adopt one or more molecules from a publisher repo into `.spaex/manifest.json` and install them in one invocation. `add` only adds: when the source resolves to a newer revision, molecules already adopted from it are kept and re-pinned to that revision (listed in the output); only `spaex remove` retracts a molecule.
31
31
  - `spaex remove <molecule-ids...>`: retract one or more molecules from `.spaex/manifest.json` and re-run install (files that only the retracted molecule contributed are deleted).
32
32
  - `spaex install`: publish adopted molecules atomically into their participating roots. Writes `.spaex/install.lock`.
33
33
  - `spaex constitution show`: print the effective spaex constitution to stdout, assembled from adopted molecules per `install.lock`.
@@ -8,7 +8,7 @@ spaex composes a coding harness for a single repo out of reusable pieces (MCPs,
8
8
 
9
9
  ## What you can do today
10
10
 
11
- - `spaex add <source-url> <molecule-ids...>`: adopt one or more molecules from a publisher repo into `.spaex/manifest.json` and install them in one invocation.
11
+ - `spaex add <source-url> <molecule-ids...>`: adopt one or more molecules from a publisher repo into `.spaex/manifest.json` and install them in one invocation. `add` only adds: when the source resolves to a newer revision, molecules already adopted from it are kept and re-pinned to that revision (listed in the output); only `spaex remove` retracts a molecule.
12
12
  - `spaex remove <molecule-ids...>`: retract one or more molecules from `.spaex/manifest.json` and re-run install (files that only the retracted molecule contributed are deleted).
13
13
  - `spaex install`: publish adopted molecules atomically into their participating roots. Writes `.spaex/install.lock`.
14
14
  - `spaex constitution show`: print the effective spaex constitution to stdout, assembled from adopted molecules per `install.lock`.
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "spaex"
7
- version = "5.4.2"
7
+ version = "5.4.4"
8
8
  description = "spaex 4.0: reproducible coding harnesses for any repo. Compose skills, MCPs, constitutions, slash commands, and dev-environment files into a single project; add/remove/install/migrate/constitution show CLI."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.14,<3.15"
@@ -16,6 +16,7 @@ from pathlib import Path
16
16
  from typing import TypeVar
17
17
 
18
18
  from spaex.cli.reinstall_options import add_reinstall_arguments, reinstall_kwargs
19
+ from spaex.cli.singleton_categories import refuse_singleton_conflict
19
20
  from spaex.git import publisher_fetch
20
21
  from spaex.git import show as git_show
21
22
  from spaex.install import local_scope
@@ -29,13 +30,11 @@ from spaex.install.write_and_reinstall import write_and_reinstall
29
30
  from spaex.io.state import default_state_root
30
31
  from spaex.model.consumer_manifest import ConsumerManifest, flatten_compound_pins
31
32
  from spaex.model.local_manifest import LocalManifest
32
- from spaex.model.molecule_manifest import MoleculeManifest
33
33
  from spaex.model.publisher_manifest import PublisherManifest
34
34
  from spaex.model.source_url import canonicalize
35
35
  from spaex.paths import MANIFEST_RELATIVE_PATH, local_manifest_path, manifest_path
36
36
  from spaex.util import exit_codes
37
37
  from spaex.util.errors import (
38
- ConstitutionAlreadyAdoptedError,
39
38
  HaexError,
40
39
  InteractiveSelectionUnavailableError,
41
40
  LocalAdoptionShadowedError,
@@ -43,12 +42,8 @@ from spaex.util.errors import (
43
42
  PublisherManifestInvalidError,
44
43
  PublisherManifestMissingError,
45
44
  UsageError,
46
- WorkflowMoleculeAlreadyAdoptedError,
47
45
  )
48
46
 
49
- _WORKFLOW_CATEGORY = "workflow"
50
- _CONSTITUTION_CATEGORY = "constitution"
51
-
52
47
 
53
48
  def _load_publisher_manifest(repo_dir: Path, sha: str, source: str) -> PublisherManifest:
54
49
  """Load the pinned publisher manifest and map failures to typed refusals."""
@@ -77,27 +72,6 @@ def _load_publisher_manifest(repo_dir: Path, sha: str, source: str) -> Publisher
77
72
  ) from exc
78
73
 
79
74
 
80
- def _load_molecule_manifest(
81
- repo_dir: Path, sha: str, molecule_dir_path: str, molecule_id: str
82
- ) -> MoleculeManifest:
83
- molecule_bytes = git_show.show_bytes(
84
- repo_dir,
85
- sha,
86
- f"{molecule_dir_path}/manifest.json",
87
- not_found_error=PublisherManifestInvalidError,
88
- )
89
- try:
90
- return MoleculeManifest.from_json(molecule_bytes)
91
- except (ValueError, KeyError) as exc:
92
- raise PublisherManifestInvalidError(
93
- message=(
94
- f"molecule manifest for {molecule_id!r} at "
95
- f"{molecule_dir_path}/manifest.json is invalid: {exc}"
96
- ),
97
- context={"molecule_id": molecule_id, "path": molecule_dir_path},
98
- ) from exc
99
-
100
-
101
75
  def _select_molecule_ids(
102
76
  args: argparse.Namespace,
103
77
  publisher: PublisherManifest,
@@ -171,115 +145,71 @@ def _verify_ids_in_source(molecule_ids: tuple[str, ...], publisher: PublisherMan
171
145
  )
172
146
 
173
147
 
174
- def _categories_declared_by(
175
- molecule_ids: tuple[str, ...],
176
- publisher: PublisherManifest,
177
- repo_dir: Path,
178
- sha: str,
179
- ) -> dict[str, tuple[str, ...]]:
180
- """Return {category: (molecule_ids that declare it)} for the added set."""
181
- result: dict[str, list[str]] = {}
182
- for mid in molecule_ids:
183
- entry = publisher.molecules[mid]
184
- molecule = _load_molecule_manifest(repo_dir, sha, entry.path, mid)
185
- for category, paths in molecule.atoms.items():
186
- if paths:
187
- result.setdefault(category, []).append(mid)
188
- return {k: tuple(v) for k, v in result.items()}
189
-
190
-
191
- def _existing_category_owners(
192
- manifest: ConsumerManifest,
193
- state_root: Path,
194
- category: str,
195
- ) -> tuple[str, ...]:
196
- """Return currently-adopted molecule ids that declare ``category``.
148
+ @dataclasses.dataclass(frozen=True)
149
+ class _CarriedOver:
150
+ """Already adopted molecules an add re-pins from ``old_revision`` (never empty)."""
197
151
 
198
- Reads publisher and molecule manifests from the existing publisher clones.
199
- A missing clone is treated as "no owner" for this pre-check — install
200
- itself will surface any clone-availability refusal downstream.
201
- """
202
- from spaex.git.cache import clone_dir
152
+ old_revision: str
153
+ molecule_ids: tuple[str, ...]
154
+
155
+
156
+ def _carried_over(
157
+ manifest: ConsumerManifest | LocalManifest,
158
+ source: str,
159
+ revision: str,
160
+ added_ids: tuple[str, ...],
161
+ ) -> _CarriedOver | None:
162
+ """Return the molecules re-pinned implicitly by this add, else ``None``.
203
163
 
204
- owners: list[str] = []
164
+ Only a compound for ``source`` at a different revision carries molecules
165
+ over; ``add`` never removes an adopted molecule.
166
+ """
205
167
  for compound in manifest.compounds:
206
- repo_dir = clone_dir(state_root, compound.source)
207
- if not repo_dir.is_dir():
208
- continue
209
- try:
210
- publisher_bytes = git_show.show_bytes(
211
- repo_dir,
212
- compound.revision,
213
- "manifest.json",
214
- not_found_error=PublisherManifestInvalidError,
215
- )
216
- publisher = PublisherManifest.from_json(publisher_bytes)
217
- except (ValueError, KeyError, HaexError):
218
- continue
219
- for mid in compound.molecules:
220
- entry = publisher.molecules.get(mid)
221
- if entry is None:
222
- continue
223
- try:
224
- molecule_bytes = git_show.show_bytes(
225
- repo_dir,
226
- compound.revision,
227
- f"{entry.path}/manifest.json",
228
- not_found_error=PublisherManifestInvalidError,
229
- )
230
- molecule = MoleculeManifest.from_json(molecule_bytes)
231
- except (ValueError, KeyError, HaexError):
232
- continue
233
- if molecule.atoms.get(category):
234
- owners.append(mid)
235
- return tuple(owners)
168
+ if compound.source == source and compound.revision != revision:
169
+ ids = tuple(sorted(set(compound.molecules) - set(added_ids)))
170
+ return _CarriedOver(compound.revision, ids) if ids else None
171
+ return None
236
172
 
237
173
 
238
- def _refuse_singleton_conflict(
239
- added_category_declarers: dict[str, tuple[str, ...]],
240
- existing_manifest: ConsumerManifest,
241
- state_root: Path,
242
- added_set: set[str],
243
- retracted_set: set[str],
174
+ def _verify_carried_over_in_source(
175
+ carried: _CarriedOver | None, publisher: PublisherManifest, remove_command: str
244
176
  ) -> None:
245
- """Refuse pre-write when a singleton-category rule is violated."""
246
- for category, refuse_exc in (
247
- (_CONSTITUTION_CATEGORY, ConstitutionAlreadyAdoptedError),
248
- (_WORKFLOW_CATEGORY, WorkflowMoleculeAlreadyAdoptedError),
249
- ):
250
- adding = added_category_declarers.get(category, ())
251
- if not adding:
252
- continue
253
- unique_adding = tuple(sorted(set(adding)))
254
- if len(unique_adding) > 1:
255
- raise refuse_exc(
256
- message=(
257
- f"add refuses: category {category!r} would be declared by "
258
- f"multiple molecules: {', '.join(unique_adding)}"
259
- ),
260
- context={
261
- "category": category,
262
- "adopted_by": "",
263
- "adding": ",".join(unique_adding),
264
- },
265
- )
266
- current_owners = tuple(
267
- owner
268
- for owner in _existing_category_owners(existing_manifest, state_root, category)
269
- if owner not in added_set and owner not in retracted_set
177
+ if carried is None:
178
+ return
179
+ missing = [mid for mid in carried.molecule_ids if mid not in publisher.molecules]
180
+ if missing:
181
+ raise MoleculeIdNotInSourceError(
182
+ message=(
183
+ f"already adopted molecule(s) no longer declared by publisher "
184
+ f"{publisher.publisher!r} at the new revision: {', '.join(missing)}"
185
+ ),
186
+ context={"publisher": publisher.publisher, "missing": ",".join(missing)},
187
+ hint=(
188
+ "`spaex add` never drops an adopted molecule; run "
189
+ f"`{remove_command} {','.join(missing)}` first, then add again."
190
+ ),
270
191
  )
271
- if current_owners:
272
- raise refuse_exc(
273
- message=(
274
- f"add refuses: category {category!r} already adopted by "
275
- f"{', '.join(current_owners)}; would-be-added: {', '.join(adding)}"
276
- ),
277
- context={
278
- "category": category,
279
- "adopted_by": ",".join(current_owners),
280
- "adding": ",".join(adding),
281
- },
282
- )
192
+
193
+
194
+ def _write_report(
195
+ scope: str,
196
+ source: str,
197
+ revision: str,
198
+ added_ids: tuple[str, ...],
199
+ carried: _CarriedOver | None,
200
+ ) -> None:
201
+ sys.stdout.write(
202
+ f"added {len(added_ids)} molecule(s){scope} at {source}@{revision[:12]}:\n"
203
+ )
204
+ for mid in added_ids:
205
+ sys.stdout.write(f" {mid}\n")
206
+ if carried is not None:
207
+ sys.stdout.write(
208
+ f"re-pinned {len(carried.molecule_ids)} carried-over molecule(s) "
209
+ f"({carried.old_revision[:12]} -> {revision[:12]}):\n"
210
+ )
211
+ for mid in carried.molecule_ids:
212
+ sys.stdout.write(f" {mid}\n")
283
213
 
284
214
 
285
215
  ManifestT = TypeVar("ManifestT", ConsumerManifest, LocalManifest)
@@ -291,38 +221,23 @@ def _mutate_compounds(
291
221
  revision: str,
292
222
  added_ids: tuple[str, ...],
293
223
  ) -> ManifestT:
294
- """Return the manifest (project or local overlay) with the compound merged/replaced/added."""
224
+ """Return the manifest (project or local overlay) with the compound merged/re-pinned/added."""
295
225
  from spaex.model.consumer_manifest import CompoundEntry
296
226
 
297
227
  new_compounds: list[CompoundEntry] = []
298
228
  consumed = False
299
229
  for compound in manifest.compounds:
300
230
  if compound.source == source:
301
- if compound.revision == revision:
302
- merged = tuple(sorted(set(compound.molecules) | set(added_ids)))
303
- new_compounds.append(
304
- CompoundEntry(
305
- source=source,
306
- revision=revision,
307
- molecules=merged,
308
- track=compound.track,
309
- config=compound.config,
310
- )
311
- )
312
- else:
313
- new_compounds.append(
314
- CompoundEntry(
315
- source=source,
316
- revision=revision,
317
- molecules=tuple(sorted(set(added_ids))),
318
- track=compound.track,
319
- config={
320
- molecule_id: config
321
- for molecule_id, config in compound.config.items()
322
- if molecule_id in added_ids
323
- },
324
- )
231
+ # Same revision merges; a different revision re-pins the whole
232
+ # compound. Either way `add` only adds: existing molecules, `track`
233
+ # and `config` are kept.
234
+ new_compounds.append(
235
+ dataclasses.replace(
236
+ compound,
237
+ revision=revision,
238
+ molecules=tuple(sorted(set(compound.molecules) | set(added_ids))),
325
239
  )
240
+ )
326
241
  consumed = True
327
242
  else:
328
243
  new_compounds.append(compound)
@@ -400,24 +315,15 @@ def run(args: argparse.Namespace) -> int:
400
315
  current_manifest = ConsumerManifest.from_json(path.read_bytes())
401
316
  if getattr(args, "local", False):
402
317
  return _add_local(
403
- args, repo_root, lock, current_manifest, canonical_source, sha, molecule_ids
318
+ args, repo_root, lock, current_manifest, canonical_source, sha,
319
+ molecule_ids, publisher, repo_dir, state_root,
404
320
  )
405
321
 
406
- added_category_declarers = _categories_declared_by(
407
- molecule_ids, publisher, repo_dir, sha
408
- )
409
- retracted_set = {
410
- molecule_id
411
- for compound in current_manifest.compounds
412
- if compound.source == canonical_source and compound.revision != sha
413
- for molecule_id in compound.molecules
414
- }
415
- _refuse_singleton_conflict(
416
- added_category_declarers,
417
- current_manifest,
418
- state_root,
419
- added_set=set(molecule_ids),
420
- retracted_set=retracted_set,
322
+ carried = _carried_over(current_manifest, canonical_source, sha, molecule_ids)
323
+ _verify_carried_over_in_source(carried, publisher, "spaex remove")
324
+ incoming_ids = molecule_ids + (carried.molecule_ids if carried else ())
325
+ refuse_singleton_conflict(
326
+ current_manifest, incoming_ids, publisher, repo_dir, sha, state_root
421
327
  )
422
328
 
423
329
  new_manifest = _mutate_compounds(
@@ -437,11 +343,7 @@ def run(args: argparse.Namespace) -> int:
437
343
  abort_on_behavior_contradiction=False,
438
344
  )
439
345
 
440
- sys.stdout.write(
441
- f"added {len(molecule_ids)} molecule(s) at {canonical_source}@{sha[:12]}:\n"
442
- )
443
- for mid in molecule_ids:
444
- sys.stdout.write(f" {mid}\n")
346
+ _write_report("", canonical_source, sha, molecule_ids, carried)
445
347
  return exit_code
446
348
 
447
349
 
@@ -453,6 +355,9 @@ def _add_local(
453
355
  canonical_source: str,
454
356
  sha: str,
455
357
  molecule_ids: tuple[str, ...],
358
+ publisher: PublisherManifest,
359
+ repo_dir: Path,
360
+ state_root: Path,
456
361
  ) -> int:
457
362
  """Spec 029: adopt into the local overlay; the project manifest is never written."""
458
363
  shadowed = sorted(set(molecule_ids) & set(flatten_compound_pins(project)))
@@ -465,14 +370,23 @@ def _add_local(
465
370
  context={"molecules": ",".join(shadowed)},
466
371
  )
467
372
  overlay = local_scope.load_overlay(repo_root) or LocalManifest(spaex_version="4", compounds=())
373
+ carried = _carried_over(overlay, canonical_source, sha, molecule_ids)
374
+ _verify_carried_over_in_source(carried, publisher, "spaex remove --local")
375
+ incoming_ids = molecule_ids + (carried.molecule_ids if carried else ())
376
+ refuse_singleton_conflict(
377
+ overlay.as_consumer_manifest(project.identity),
378
+ incoming_ids,
379
+ publisher,
380
+ repo_dir,
381
+ sha,
382
+ state_root,
383
+ )
468
384
  new_overlay = _mutate_compounds(overlay, canonical_source, sha, molecule_ids)
469
385
  exit_code = write_and_reinstall(
470
386
  repo_root,
471
387
  new_overlay.to_json_bytes(),
472
388
  lock,
473
- skip_hooks=bool(getattr(args, "skip_hooks", False)),
474
- speckit_agents=getattr(args, "speckit_agents", None),
475
- no_speckit_integrations=bool(getattr(args, "no_speckit_integrations", False)),
389
+ **reinstall_kwargs(args),
476
390
  abort_on_behavior_contradiction=False,
477
391
  target=local_manifest_path(repo_root),
478
392
  )
@@ -483,11 +397,7 @@ def _add_local(
483
397
  for molecule_id in molecule_ids:
484
398
  if molecule_id in hook_ids:
485
399
  sys.stdout.write(local_scope.HOOK_WARNING.format(molecule_id=molecule_id))
486
- sys.stdout.write(
487
- f"added {len(molecule_ids)} molecule(s) locally at {canonical_source}@{sha[:12]}:\n"
488
- )
489
- for mid in molecule_ids:
490
- sys.stdout.write(f" {mid}\n")
400
+ _write_report(" locally", canonical_source, sha, molecule_ids, carried)
491
401
  return exit_code
492
402
 
493
403
 
@@ -0,0 +1,167 @@
1
+ """Add-time singleton-category pre-check for `spaex add` (Spec 013 FR-019, FR-020).
2
+
3
+ A repository adopts at most one workflow molecule and at most one
4
+ constitution-contributing molecule. `spaex add` refuses before it writes
5
+ anything when the molecules a compound will hold after the add would break
6
+ either rule.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ from pathlib import Path
12
+
13
+ from spaex.git import show as git_show
14
+ from spaex.git.cache import clone_dir
15
+ from spaex.model.atom_category import LEGACY_CONSTITUTION_CATEGORY
16
+ from spaex.model.consumer_manifest import ConsumerManifest
17
+ from spaex.model.molecule_manifest import MoleculeManifest
18
+ from spaex.model.publisher_manifest import PublisherManifest
19
+ from spaex.util.errors import (
20
+ ConstitutionAlreadyAdoptedError,
21
+ HaexError,
22
+ PublisherManifestInvalidError,
23
+ WorkflowMoleculeAlreadyAdoptedError,
24
+ )
25
+
26
+ _WORKFLOW_CATEGORY = "workflow"
27
+
28
+
29
+ def _load_molecule_manifest(
30
+ repo_dir: Path, sha: str, molecule_dir_path: str, molecule_id: str
31
+ ) -> MoleculeManifest:
32
+ molecule_bytes = git_show.show_bytes(
33
+ repo_dir,
34
+ sha,
35
+ f"{molecule_dir_path}/manifest.json",
36
+ not_found_error=PublisherManifestInvalidError,
37
+ )
38
+ try:
39
+ return MoleculeManifest.from_json(molecule_bytes)
40
+ except (ValueError, KeyError) as exc:
41
+ raise PublisherManifestInvalidError(
42
+ message=(
43
+ f"molecule manifest for {molecule_id!r} at "
44
+ f"{molecule_dir_path}/manifest.json is invalid: {exc}"
45
+ ),
46
+ context={"molecule_id": molecule_id, "path": molecule_dir_path},
47
+ ) from exc
48
+
49
+
50
+ def _categories_declared_by(
51
+ molecule_ids: tuple[str, ...],
52
+ publisher: PublisherManifest,
53
+ repo_dir: Path,
54
+ sha: str,
55
+ ) -> dict[str, tuple[str, ...]]:
56
+ """Return {category: (molecule_ids that declare it)} for ``molecule_ids``."""
57
+ result: dict[str, list[str]] = {}
58
+ for mid in molecule_ids:
59
+ entry = publisher.molecules[mid]
60
+ molecule = _load_molecule_manifest(repo_dir, sha, entry.path, mid)
61
+ for category, paths in molecule.atoms.items():
62
+ if paths:
63
+ result.setdefault(category, []).append(mid)
64
+ return {k: tuple(v) for k, v in result.items()}
65
+
66
+
67
+ def _existing_category_owners(
68
+ manifest: ConsumerManifest,
69
+ state_root: Path,
70
+ category: str,
71
+ ) -> tuple[str, ...]:
72
+ """Return currently-adopted molecule ids that declare ``category``.
73
+
74
+ Reads publisher and molecule manifests from the existing publisher clones.
75
+ A missing clone is treated as "no owner" for this pre-check — install
76
+ itself will surface any clone-availability refusal downstream.
77
+ """
78
+ owners: list[str] = []
79
+ for compound in manifest.compounds:
80
+ repo_dir = clone_dir(state_root, compound.source)
81
+ if not repo_dir.is_dir():
82
+ continue
83
+ try:
84
+ publisher_bytes = git_show.show_bytes(
85
+ repo_dir,
86
+ compound.revision,
87
+ "manifest.json",
88
+ not_found_error=PublisherManifestInvalidError,
89
+ )
90
+ publisher = PublisherManifest.from_json(publisher_bytes)
91
+ except (ValueError, KeyError, HaexError):
92
+ continue
93
+ for mid in compound.molecules:
94
+ entry = publisher.molecules.get(mid)
95
+ if entry is None:
96
+ continue
97
+ try:
98
+ molecule_bytes = git_show.show_bytes(
99
+ repo_dir,
100
+ compound.revision,
101
+ f"{entry.path}/manifest.json",
102
+ not_found_error=PublisherManifestInvalidError,
103
+ )
104
+ molecule = MoleculeManifest.from_json(molecule_bytes)
105
+ except (ValueError, KeyError, HaexError):
106
+ continue
107
+ if molecule.atoms.get(category):
108
+ owners.append(mid)
109
+ return tuple(owners)
110
+
111
+
112
+ def refuse_singleton_conflict(
113
+ existing_manifest: ConsumerManifest,
114
+ incoming_ids: tuple[str, ...],
115
+ publisher: PublisherManifest,
116
+ repo_dir: Path,
117
+ sha: str,
118
+ state_root: Path,
119
+ ) -> None:
120
+ """Refuse pre-write when a singleton-category rule is violated.
121
+
122
+ ``incoming_ids`` is every molecule the same-source compound will hold after
123
+ the add (added plus carried-over), read at ``sha``; its entries in
124
+ ``existing_manifest`` are therefore not counted as current owners.
125
+ """
126
+ added_category_declarers = _categories_declared_by(incoming_ids, publisher, repo_dir, sha)
127
+ incoming_set = set(incoming_ids)
128
+ for category, refuse_exc in (
129
+ (LEGACY_CONSTITUTION_CATEGORY, ConstitutionAlreadyAdoptedError),
130
+ (_WORKFLOW_CATEGORY, WorkflowMoleculeAlreadyAdoptedError),
131
+ ):
132
+ adding = added_category_declarers.get(category, ())
133
+ if not adding:
134
+ continue
135
+ unique_adding = tuple(sorted(set(adding)))
136
+ if len(unique_adding) > 1:
137
+ raise refuse_exc(
138
+ message=(
139
+ f"add refuses: category {category!r} would be declared by "
140
+ f"multiple molecules: {', '.join(unique_adding)}"
141
+ ),
142
+ context={
143
+ "category": category,
144
+ "adopted_by": "",
145
+ "adding": ",".join(unique_adding),
146
+ },
147
+ )
148
+ current_owners = tuple(
149
+ owner
150
+ for owner in _existing_category_owners(existing_manifest, state_root, category)
151
+ if owner not in incoming_set
152
+ )
153
+ if current_owners:
154
+ raise refuse_exc(
155
+ message=(
156
+ f"add refuses: category {category!r} already adopted by "
157
+ f"{', '.join(current_owners)}; would-be-added: {', '.join(adding)}"
158
+ ),
159
+ context={
160
+ "category": category,
161
+ "adopted_by": ",".join(current_owners),
162
+ "adding": ",".join(adding),
163
+ },
164
+ )
165
+
166
+
167
+ __all__ = ["refuse_singleton_conflict"]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: spaex
3
- Version: 5.4.2
3
+ Version: 5.4.4
4
4
  Summary: spaex 4.0: reproducible coding harnesses for any repo. Compose skills, MCPs, constitutions, slash commands, and dev-environment files into a single project; add/remove/install/migrate/constitution show CLI.
5
5
  Author: spaex contributors
6
6
  License: Apache-2.0
@@ -27,7 +27,7 @@ spaex composes a coding harness for a single repo out of reusable pieces (MCPs,
27
27
 
28
28
  ## What you can do today
29
29
 
30
- - `spaex add <source-url> <molecule-ids...>`: adopt one or more molecules from a publisher repo into `.spaex/manifest.json` and install them in one invocation.
30
+ - `spaex add <source-url> <molecule-ids...>`: adopt one or more molecules from a publisher repo into `.spaex/manifest.json` and install them in one invocation. `add` only adds: when the source resolves to a newer revision, molecules already adopted from it are kept and re-pinned to that revision (listed in the output); only `spaex remove` retracts a molecule.
31
31
  - `spaex remove <molecule-ids...>`: retract one or more molecules from `.spaex/manifest.json` and re-run install (files that only the retracted molecule contributed are deleted).
32
32
  - `spaex install`: publish adopted molecules atomically into their participating roots. Writes `.spaex/install.lock`.
33
33
  - `spaex constitution show`: print the effective spaex constitution to stdout, assembled from adopted molecules per `install.lock`.
@@ -36,6 +36,7 @@ src/spaex/cli/install.py
36
36
  src/spaex/cli/main.py
37
37
  src/spaex/cli/reinstall_options.py
38
38
  src/spaex/cli/remove.py
39
+ src/spaex/cli/singleton_categories.py
39
40
  src/spaex/cli/skills.py
40
41
  src/spaex/cli/status.py
41
42
  src/spaex/constitution/__init__.py
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes