pactkit-opencode 5.0.0__tar.gz → 5.0.3__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 (38) hide show
  1. {pactkit_opencode-5.0.0 → pactkit_opencode-5.0.3}/PKG-INFO +2 -2
  2. {pactkit_opencode-5.0.0 → pactkit_opencode-5.0.3}/pyproject.toml +3 -2
  3. {pactkit_opencode-5.0.0 → pactkit_opencode-5.0.3}/src/pactkit_opencode/deployer.py +77 -61
  4. {pactkit_opencode-5.0.0 → pactkit_opencode-5.0.3}/src/pactkit_opencode.egg-info/PKG-INFO +2 -2
  5. {pactkit_opencode-5.0.0 → pactkit_opencode-5.0.3}/src/pactkit_opencode.egg-info/SOURCES.txt +2 -0
  6. pactkit_opencode-5.0.3/src/pactkit_opencode.egg-info/requires.txt +1 -0
  7. pactkit_opencode-5.0.3/tests/test_review_round13_order.py +43 -0
  8. pactkit_opencode-5.0.3/tests/test_review_round14.py +38 -0
  9. pactkit_opencode-5.0.0/src/pactkit_opencode.egg-info/requires.txt +0 -1
  10. {pactkit_opencode-5.0.0 → pactkit_opencode-5.0.3}/README.md +0 -0
  11. {pactkit_opencode-5.0.0 → pactkit_opencode-5.0.3}/setup.cfg +0 -0
  12. {pactkit_opencode-5.0.0 → pactkit_opencode-5.0.3}/src/pactkit_opencode/__init__.py +0 -0
  13. {pactkit_opencode-5.0.0 → pactkit_opencode-5.0.3}/src/pactkit_opencode/declarations.py +0 -0
  14. {pactkit_opencode-5.0.0 → pactkit_opencode-5.0.3}/src/pactkit_opencode/enforcement.py +0 -0
  15. {pactkit_opencode-5.0.0 → pactkit_opencode-5.0.3}/src/pactkit_opencode.egg-info/dependency_links.txt +0 -0
  16. {pactkit_opencode-5.0.0 → pactkit_opencode-5.0.3}/src/pactkit_opencode.egg-info/entry_points.txt +0 -0
  17. {pactkit_opencode-5.0.0 → pactkit_opencode-5.0.3}/src/pactkit_opencode.egg-info/top_level.txt +0 -0
  18. {pactkit_opencode-5.0.0 → pactkit_opencode-5.0.3}/tests/test_a1_config_recovery.py +0 -0
  19. {pactkit_opencode-5.0.0 → pactkit_opencode-5.0.3}/tests/test_a2_mcp_retired.py +0 -0
  20. {pactkit_opencode-5.0.0 → pactkit_opencode-5.0.3}/tests/test_bug035_opencode_dual_layer.py +0 -0
  21. {pactkit_opencode-5.0.0 → pactkit_opencode-5.0.3}/tests/test_capability_contract.py +0 -0
  22. {pactkit_opencode-5.0.0 → pactkit_opencode-5.0.3}/tests/test_command_models_honesty.py +0 -0
  23. {pactkit_opencode-5.0.0 → pactkit_opencode-5.0.3}/tests/test_deploy_opencode_parity.py +0 -0
  24. {pactkit_opencode-5.0.0 → pactkit_opencode-5.0.3}/tests/test_gate_plugin_deploy.py +0 -0
  25. {pactkit_opencode-5.0.0 → pactkit_opencode-5.0.3}/tests/test_global_agents_ownership.py +0 -0
  26. {pactkit_opencode-5.0.0 → pactkit_opencode-5.0.3}/tests/test_host_body_snapshot.py +0 -0
  27. {pactkit_opencode-5.0.0 → pactkit_opencode-5.0.3}/tests/test_legacy_agents_migration.py +0 -0
  28. {pactkit_opencode-5.0.0 → pactkit_opencode-5.0.3}/tests/test_opencode_enforcement_channel.py +0 -0
  29. {pactkit_opencode-5.0.0 → pactkit_opencode-5.0.3}/tests/test_profile_contract.py +0 -0
  30. {pactkit_opencode-5.0.0 → pactkit_opencode-5.0.3}/tests/test_step6_self_sufficiency.py +0 -0
  31. {pactkit_opencode-5.0.0 → pactkit_opencode-5.0.3}/tests/test_step8_declaration_search_producer.py +0 -0
  32. {pactkit_opencode-5.0.0 → pactkit_opencode-5.0.3}/tests/test_story069_opencode_format.py +0 -0
  33. {pactkit_opencode-5.0.0 → pactkit_opencode-5.0.3}/tests/test_story070_opencode_compliance.py +0 -0
  34. {pactkit_opencode-5.0.0 → pactkit_opencode-5.0.3}/tests/test_story071_opencode_config_parity.py +0 -0
  35. {pactkit_opencode-5.0.0 → pactkit_opencode-5.0.3}/tests/test_story073_command_model_routing.py +0 -0
  36. {pactkit_opencode-5.0.0 → pactkit_opencode-5.0.3}/tests/test_story_work_units.py +0 -0
  37. {pactkit_opencode-5.0.0 → pactkit_opencode-5.0.3}/tests/test_user_command_scope.py +0 -0
  38. {pactkit_opencode-5.0.0 → pactkit_opencode-5.0.3}/tests/test_wire_format_contract.py +0 -0
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pactkit-opencode
3
- Version: 5.0.0
3
+ Version: 5.0.3
4
4
  Summary: PactKit adapter for OpenCode IDE
5
5
  License-Expression: MIT
6
6
  Requires-Python: >=3.10
7
- Requires-Dist: pactkit<5.1.0,>=5.0.0
7
+ Requires-Dist: pactkit<5.1.0,>=5.0.3
@@ -4,12 +4,13 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "pactkit-opencode"
7
- version = "5.0.0"
7
+ version = "5.0.3"
8
8
  description = "PactKit adapter for OpenCode IDE"
9
9
  requires-python = ">=3.10"
10
10
  license = "MIT"
11
11
  dependencies = [
12
- "pactkit>=5.0.0,<5.1.0",
12
+ # round4 #4: resolve_integration_config first ships in core 5.0.2.
13
+ "pactkit>=5.0.3,<5.1.0",
13
14
  ]
14
15
 
15
16
  [project.entry-points."pactkit.deployers"]
@@ -29,8 +29,8 @@ from pactkit.generators.deployer import (
29
29
  _deploy_skills,
30
30
  )
31
31
  from pactkit.generators.spi import generate_config_if_missing
32
- from pactkit_opencode import declarations
33
32
  from pactkit.utils import atomic_write
33
+ from pactkit_opencode import declarations
34
34
 
35
35
  # All canonical commands deploy. Sprint has a sequential capability fallback.
36
36
  OPENCODE_EXCLUDED_COMMANDS: frozenset[str] = frozenset()
@@ -152,6 +152,15 @@ class OpenCodeDeployer(DeployerBase):
152
152
 
153
153
  print("🚀 PactKit OpenCode Deployment")
154
154
 
155
+ # round18 #1: terminate before ANY global write — including the script-path
156
+ # post-processing that rewrites command files — if a component dir or nested
157
+ # entry escapes into a project.
158
+ if not project_only:
159
+ from pactkit.deploy_shared import assert_global_component_boundary
160
+ from pactkit.generators.deployer import _mkdir_within
161
+
162
+ assert_global_component_boundary(opencode_root, extra_dirs=("plugins",))
163
+
155
164
  # Prepare directories (global components only; project-only integration
156
165
  # writes no machine-global OpenCode state).
157
166
  agents_dir = opencode_root / "agents"
@@ -161,17 +170,29 @@ class OpenCodeDeployer(DeployerBase):
161
170
 
162
171
  if not project_only:
163
172
  for d in [opencode_root, agents_dir, skills_dir, commands_dir, rules_dir]:
164
- d.mkdir(parents=True, exist_ok=True)
173
+ _mkdir_within(opencode_root, d)
165
174
 
166
175
  # STORY-slim-008 R1+R2: Load config from project-level pactkit.yaml.
167
176
  # A global-only deployment never reads the project (Core supplies cfg).
168
177
  from pactkit.config import find_pactkit_yaml
169
178
 
170
- project_yaml = None if global_only else find_pactkit_yaml(project_root)
179
+ if global_only:
180
+ project_yaml = None
181
+ elif project_only:
182
+ # Review A#1: integration is scoped to the target project — never walk
183
+ # up to an outer project's YAML. Imported here so a global-only deploy
184
+ # never needs the integration API (round4 #4).
185
+ from pactkit.config import resolve_integration_config
186
+
187
+ _scoped_cfg, project_yaml = resolve_integration_config(project_root, format="opencode")
188
+ if config is None:
189
+ config = _scoped_cfg
190
+ else:
191
+ project_yaml = find_pactkit_yaml(project_root)
171
192
 
172
193
  if config is not None:
173
194
  cfg = config
174
- elif project_yaml is not None:
195
+ elif project_yaml is not None and project_yaml.is_file():
175
196
  auto_added = auto_merge_config_file(project_yaml)
176
197
  for item in auto_added:
177
198
  print(f" -> Auto-added: {item}")
@@ -192,61 +213,38 @@ class OpenCodeDeployer(DeployerBase):
192
213
  n_skills = n_commands = n_agents = n_plugins = 0
193
214
  if not project_only:
194
215
  # Deploy embedded skills (pactkit-board, pactkit-visualize, etc.)
216
+ # round21 #2: CLI-to-script conversion happens INSIDE _deploy_skills
217
+ # (content_transform) BEFORE the ownership check, so a user-edited skill
218
+ # is preserved against the final content — not rewritten by a post-pass.
195
219
  n_skills = _deploy_skills(
196
220
  skills_dir,
197
221
  enabled_skills,
198
222
  profile=self.profile,
223
+ content_transform=_replace_cli_with_scripts,
199
224
  )
200
225
  _cleanup_legacy_portable_methods(skills_dir, self.profile)
201
226
  _cleanup_legacy(skills_dir)
202
227
  # Clean up legacy command skills from skills/ directory (migrated to commands/)
203
228
  self._cleanup_command_skills(skills_dir)
204
229
 
205
- # Apply CLI-to-script replacement ONLY to PactKit-managed skill files
206
- # (STORY-slim-202611239641dc45a9fc): user-created skills stay untouched.
207
- from pactkit.prompts.skills import get_skill_manifest
208
- _skill_names = {s["name"] for s in get_skill_manifest()}
209
- for skill_md in skills_dir.glob("*/SKILL.md"):
210
- if skill_md.parent.name not in _skill_names:
211
- continue
212
- content = skill_md.read_text(encoding="utf-8")
213
- replaced = _replace_cli_with_scripts(content)
214
- if replaced != content:
215
- atomic_write(skill_md, replaced)
216
-
217
- # HOTFIX-slim-20260903d464746b1909: post-pass rewrites deployed bytes in
218
- # place; record the FINAL (transformed) digests or the next deploy cannot
219
- # prove ownership and re-produces .pactkit-new candidates.
220
- from pactkit.deploy_manifest import record_deployed_file
221
-
222
- for skill_md in skills_dir.glob("*/SKILL.md"):
223
- if skill_md.parent.name not in _skill_names:
224
- continue
225
- record_deployed_file(
226
- opencode_root, skill_md.relative_to(opencode_root).as_posix(),
227
- )
230
+ # round22 #2: ownership is recorded ONLY at the final manifest commit
231
+ # (write_deploy_manifest below), never mid-deploy by directory/file name.
232
+ # An early record_deployed_file glob claimed the on-disk bytes of a
233
+ # user-edited SKILL.md that preserve_or_write had just PRESERVED (writing
234
+ # a .pactkit-new candidate). If the gate-plugin write then failed, the
235
+ # final manifest never ran to exclude it, so the poisoned record survived
236
+ # and the next retry overwrote the user's original. pactkit_owned_files
237
+ # already skips any artifact with a .pactkit-new sibling, so the single
238
+ # final commit records confirmed-written files only.
228
239
 
229
240
  # Deploy commands to commands/ directory (OpenCode uses /command-name to invoke)
230
- n_commands = _deploy_commands(commands_dir, enabled_commands, profile=self.profile, config=cfg)
231
-
232
- # Apply CLI-to-script replacement ONLY to PactKit-managed command files
233
- # (STORY-slim-202611239641dc45a9fc): user-created commands stay untouched.
234
- from pactkit.prompts.commands import get_deployable_commands
235
- _cmd_catalog = set(get_deployable_commands())
236
- for cmd_md in commands_dir.glob("*.md"):
237
- if cmd_md.name not in _cmd_catalog:
238
- continue
239
- content = cmd_md.read_text(encoding="utf-8")
240
- replaced = _replace_cli_with_scripts(content)
241
- if replaced != content:
242
- atomic_write(cmd_md, replaced)
243
-
244
- for cmd_md in commands_dir.glob("*.md"):
245
- if cmd_md.name not in _cmd_catalog:
246
- continue
247
- record_deployed_file(
248
- opencode_root, cmd_md.relative_to(opencode_root).as_posix(),
249
- )
241
+ # round20 #2: the CLI-to-script conversion happens INSIDE _deploy_commands
242
+ # (content_transform) BEFORE the ownership check, so a user-edited command
243
+ # file is preserved against the final content — not rewritten by a post-pass.
244
+ n_commands = _deploy_commands(
245
+ commands_dir, enabled_commands, profile=self.profile, config=cfg,
246
+ content_transform=_replace_cli_with_scripts,
247
+ )
250
248
 
251
249
  # R4 (2026-09-11 review): retire instruction refs BEFORE _deploy_rules
252
250
  # deletes byte-identical legacy files — ref ownership is proven by the
@@ -286,22 +284,28 @@ class OpenCodeDeployer(DeployerBase):
286
284
  _deploy_ci(ci_provider, project_root, cfg)
287
285
 
288
286
  if not project_only:
289
- # STORY-slim-139 R2: machine-readable deployment manifest
287
+ import hashlib
288
+
290
289
  from pactkit.deploy_manifest import write_deploy_manifest
291
290
 
292
- write_deploy_manifest(opencode_root, "opencode", cfg)
293
-
294
- # STORY-slim-20260918dda35a04d01d: the pre-tool gate channel. Deployed
295
- # GLOBALLY (like every other OpenCode asset here), so the plugin sees
296
- # every project on the machine — it activates per project via the
297
- # markers baked into its source, and is inert elsewhere.
298
- #
299
- # MUST run AFTER write_deploy_manifest: that function REBUILDS the
300
- # manifest's `files` map from the declared components, and `plugins/`
301
- # is not one — recording earlier gets silently overwritten, and then
302
- # `pactkit uninstall` leaves the plugin behind as residue (R4).
291
+ # round13 #2: install the gate plugin BEFORE stamping the manifest
292
+ # complete. If the plugin write fails or is interrupted, the manifest
293
+ # is never stamped current, so `update --if-needed` repairs this Host
294
+ # instead of skipping it and leaving a missing/stale gate.
303
295
  n_plugins = self._deploy_gate_plugin(opencode_root)
304
296
 
297
+ # round14 #2: the plugin ownership lands in the SAME manifest commit as
298
+ # the version + input digest (extra_files), so an interruption between
299
+ # two writes cannot leave the Host stamped current while the plugin is
300
+ # absent from the uninstall inventory.
301
+ extra_files = {}
302
+ if n_plugins:
303
+ plugin_rel = "plugins/pactkit-gate.js"
304
+ extra_files[plugin_rel] = hashlib.sha256(
305
+ (opencode_root / plugin_rel).read_bytes()
306
+ ).hexdigest()
307
+ write_deploy_manifest(opencode_root, "opencode", cfg, extra_files=extra_files)
308
+
305
309
  print(
306
310
  f"\n✅ OpenCode: {n_agents} Agents, {n_skills} Skills, "
307
311
  f"{n_commands} Commands, {n_plugins} Gate plugin → {opencode_root}"
@@ -324,14 +328,26 @@ class OpenCodeDeployer(DeployerBase):
324
328
  Recorded in the deployment manifest, so `pactkit uninstall` removes it
325
329
  with the rest of the owned files — no residue (R4).
326
330
  """
327
- from pactkit.deploy_manifest import atomic_write, record_deployed_file
331
+ from pactkit.deploy_manifest import atomic_write
332
+ from pactkit.deploy_shared import project_write_target_or_none
328
333
  from pactkit.generators.opencode_plugin import render_plugin_source
329
334
 
335
+ plugin_rel = "plugins/pactkit-gate.js"
336
+ # round14 #1: a plugins/ dir reached through an escaping symlink would land
337
+ # the global gate plugin inside a project (Story B global boundary). The
338
+ # atomic write only protects the final replace; the parent dir link still
339
+ # decides where the temp and final file land, so check the real path first.
340
+ if project_write_target_or_none(opencode_root, plugin_rel) is None:
341
+ raise ValueError(
342
+ f"{plugin_rel} resolves outside the deploy root {opencode_root} "
343
+ "(symlink escape); refusing to write a global asset into a project"
344
+ )
330
345
  plugins_dir = opencode_root / "plugins"
331
346
  plugins_dir.mkdir(parents=True, exist_ok=True)
332
347
  plugin_path = plugins_dir / "pactkit-gate.js"
333
348
  atomic_write(plugin_path, render_plugin_source())
334
- record_deployed_file(opencode_root, plugin_path.relative_to(opencode_root).as_posix())
349
+ # Ownership is recorded by write_deploy_manifest(extra_files=...) in the
350
+ # same commit as the version + digest (round14 #2), not a separate write.
335
351
  return 1
336
352
 
337
353
  @staticmethod
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pactkit-opencode
3
- Version: 5.0.0
3
+ Version: 5.0.3
4
4
  Summary: PactKit adapter for OpenCode IDE
5
5
  License-Expression: MIT
6
6
  Requires-Python: >=3.10
7
- Requires-Dist: pactkit<5.1.0,>=5.0.0
7
+ Requires-Dist: pactkit<5.1.0,>=5.0.3
@@ -22,6 +22,8 @@ tests/test_host_body_snapshot.py
22
22
  tests/test_legacy_agents_migration.py
23
23
  tests/test_opencode_enforcement_channel.py
24
24
  tests/test_profile_contract.py
25
+ tests/test_review_round13_order.py
26
+ tests/test_review_round14.py
25
27
  tests/test_step6_self_sufficiency.py
26
28
  tests/test_step8_declaration_search_producer.py
27
29
  tests/test_story069_opencode_format.py
@@ -0,0 +1 @@
1
+ pactkit<5.1.0,>=5.0.3
@@ -0,0 +1,43 @@
1
+ """Review round 13 #2: the gate plugin is installed BEFORE the manifest is stamped
2
+ complete, so a failed/interrupted plugin install leaves the Host stale and
3
+ `update --if-needed` repairs it instead of skipping.
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ import pytest
9
+
10
+
11
+ def test_manifest_not_stamped_when_plugin_install_fails(tmp_path, monkeypatch):
12
+ import json
13
+
14
+ from pactkit_opencode.deployer import OpenCodeDeployer
15
+
16
+ oc = tmp_path / "opencode"
17
+ oc.mkdir()
18
+
19
+ def _boom(root):
20
+ raise OSError("plugin write interrupted")
21
+
22
+ monkeypatch.setattr(OpenCodeDeployer, "_deploy_gate_plugin", staticmethod(_boom))
23
+ with pytest.raises(OSError):
24
+ OpenCodeDeployer().deploy(target=str(oc), global_only=True)
25
+ # The manifest may exist from component recording, but it must NOT be stamped
26
+ # complete (version + input digest) — that stamp is what --if-needed trusts,
27
+ # and it is written only after the plugin lands. Without it the Host is stale
28
+ # and the next update repairs it instead of skipping.
29
+ manifest = oc / ".pactkit-deployed.json"
30
+ if manifest.exists():
31
+ data = json.loads(manifest.read_text())
32
+ assert "pactkit_version" not in data
33
+ assert "deploy_input_digest" not in data
34
+
35
+
36
+ def test_manifest_stamped_after_plugin_succeeds(tmp_path):
37
+ from pactkit_opencode.deployer import OpenCodeDeployer
38
+
39
+ oc = tmp_path / "opencode"
40
+ oc.mkdir()
41
+ OpenCodeDeployer().deploy(target=str(oc), global_only=True)
42
+ assert (oc / "plugins" / "pactkit-gate.js").is_file()
43
+ assert (oc / ".pactkit-deployed.json").is_file()
@@ -0,0 +1,38 @@
1
+ """Review round 14 (OpenCode).
2
+
3
+ #1 the global gate plugin refuses an escaping plugins/ symlink (Story B boundary)
4
+ #2 plugin ownership + version + digest land in ONE manifest commit
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import json
10
+
11
+ import pytest
12
+
13
+
14
+ def test_plugin_refuses_escaping_plugins_symlink(tmp_path):
15
+ from pactkit_opencode.deployer import OpenCodeDeployer
16
+
17
+ oc = tmp_path / "opencode"
18
+ oc.mkdir()
19
+ project = tmp_path / "project"
20
+ project.mkdir()
21
+ (oc / "plugins").symlink_to(project, target_is_directory=True)
22
+
23
+ with pytest.raises(ValueError, match="global deploy aborted|resolves outside"):
24
+ OpenCodeDeployer().deploy(target=str(oc), global_only=True)
25
+ assert list(project.iterdir()) == [] # nothing written into the project
26
+
27
+
28
+ def test_plugin_ownership_and_version_in_one_commit(tmp_path):
29
+ from pactkit_opencode.deployer import OpenCodeDeployer
30
+
31
+ oc = tmp_path / "opencode"
32
+ oc.mkdir()
33
+ OpenCodeDeployer().deploy(target=str(oc), global_only=True)
34
+ manifest = json.loads((oc / ".pactkit-deployed.json").read_text())
35
+ # version + digest + plugin ownership all present in the single manifest
36
+ assert "pactkit_version" in manifest
37
+ assert "deploy_input_digest" in manifest
38
+ assert "plugins/pactkit-gate.js" in manifest["files"]
@@ -1 +0,0 @@
1
- pactkit<5.1.0,>=5.0.0