pactkit-opencode 5.0.0__tar.gz → 5.1.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 (39) hide show
  1. {pactkit_opencode-5.0.0 → pactkit_opencode-5.1.0}/PKG-INFO +2 -2
  2. {pactkit_opencode-5.0.0 → pactkit_opencode-5.1.0}/README.md +0 -2
  3. {pactkit_opencode-5.0.0 → pactkit_opencode-5.1.0}/pyproject.toml +3 -2
  4. {pactkit_opencode-5.0.0 → pactkit_opencode-5.1.0}/src/pactkit_opencode/deployer.py +86 -69
  5. {pactkit_opencode-5.0.0 → pactkit_opencode-5.1.0}/src/pactkit_opencode.egg-info/PKG-INFO +2 -2
  6. {pactkit_opencode-5.0.0 → pactkit_opencode-5.1.0}/src/pactkit_opencode.egg-info/SOURCES.txt +2 -0
  7. pactkit_opencode-5.1.0/src/pactkit_opencode.egg-info/requires.txt +1 -0
  8. {pactkit_opencode-5.0.0 → pactkit_opencode-5.1.0}/tests/test_bug035_opencode_dual_layer.py +3 -3
  9. {pactkit_opencode-5.0.0 → pactkit_opencode-5.1.0}/tests/test_deploy_opencode_parity.py +38 -16
  10. pactkit_opencode-5.1.0/tests/test_review_round13_order.py +43 -0
  11. pactkit_opencode-5.1.0/tests/test_review_round14.py +38 -0
  12. {pactkit_opencode-5.0.0 → pactkit_opencode-5.1.0}/tests/test_step8_declaration_search_producer.py +11 -50
  13. {pactkit_opencode-5.0.0 → pactkit_opencode-5.1.0}/tests/test_story069_opencode_format.py +10 -15
  14. pactkit_opencode-5.1.0/tests/test_story070_opencode_compliance.py +137 -0
  15. pactkit_opencode-5.0.0/src/pactkit_opencode.egg-info/requires.txt +0 -1
  16. pactkit_opencode-5.0.0/tests/test_story070_opencode_compliance.py +0 -261
  17. {pactkit_opencode-5.0.0 → pactkit_opencode-5.1.0}/setup.cfg +0 -0
  18. {pactkit_opencode-5.0.0 → pactkit_opencode-5.1.0}/src/pactkit_opencode/__init__.py +0 -0
  19. {pactkit_opencode-5.0.0 → pactkit_opencode-5.1.0}/src/pactkit_opencode/declarations.py +0 -0
  20. {pactkit_opencode-5.0.0 → pactkit_opencode-5.1.0}/src/pactkit_opencode/enforcement.py +0 -0
  21. {pactkit_opencode-5.0.0 → pactkit_opencode-5.1.0}/src/pactkit_opencode.egg-info/dependency_links.txt +0 -0
  22. {pactkit_opencode-5.0.0 → pactkit_opencode-5.1.0}/src/pactkit_opencode.egg-info/entry_points.txt +0 -0
  23. {pactkit_opencode-5.0.0 → pactkit_opencode-5.1.0}/src/pactkit_opencode.egg-info/top_level.txt +0 -0
  24. {pactkit_opencode-5.0.0 → pactkit_opencode-5.1.0}/tests/test_a1_config_recovery.py +0 -0
  25. {pactkit_opencode-5.0.0 → pactkit_opencode-5.1.0}/tests/test_a2_mcp_retired.py +0 -0
  26. {pactkit_opencode-5.0.0 → pactkit_opencode-5.1.0}/tests/test_capability_contract.py +0 -0
  27. {pactkit_opencode-5.0.0 → pactkit_opencode-5.1.0}/tests/test_command_models_honesty.py +0 -0
  28. {pactkit_opencode-5.0.0 → pactkit_opencode-5.1.0}/tests/test_gate_plugin_deploy.py +0 -0
  29. {pactkit_opencode-5.0.0 → pactkit_opencode-5.1.0}/tests/test_global_agents_ownership.py +0 -0
  30. {pactkit_opencode-5.0.0 → pactkit_opencode-5.1.0}/tests/test_host_body_snapshot.py +0 -0
  31. {pactkit_opencode-5.0.0 → pactkit_opencode-5.1.0}/tests/test_legacy_agents_migration.py +0 -0
  32. {pactkit_opencode-5.0.0 → pactkit_opencode-5.1.0}/tests/test_opencode_enforcement_channel.py +0 -0
  33. {pactkit_opencode-5.0.0 → pactkit_opencode-5.1.0}/tests/test_profile_contract.py +0 -0
  34. {pactkit_opencode-5.0.0 → pactkit_opencode-5.1.0}/tests/test_step6_self_sufficiency.py +0 -0
  35. {pactkit_opencode-5.0.0 → pactkit_opencode-5.1.0}/tests/test_story071_opencode_config_parity.py +0 -0
  36. {pactkit_opencode-5.0.0 → pactkit_opencode-5.1.0}/tests/test_story073_command_model_routing.py +0 -0
  37. {pactkit_opencode-5.0.0 → pactkit_opencode-5.1.0}/tests/test_story_work_units.py +0 -0
  38. {pactkit_opencode-5.0.0 → pactkit_opencode-5.1.0}/tests/test_user_command_scope.py +0 -0
  39. {pactkit_opencode-5.0.0 → pactkit_opencode-5.1.0}/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.1.0
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.2.0,>=5.1.0
@@ -12,7 +12,6 @@
12
12
 
13
13
  - **Commands** (`commands/*.md`) — 11 PDCA workflow commands, auto-discovered by OpenCode (invoked via `/project-plan`, `/project-act`, etc.)
14
14
  - **Skills** (`skills/*/SKILL.md`) — 10 embedded skills loaded by AI agent on demand
15
- - **Agents** (`agents/*.md`) — 9 specialized agent definitions
16
15
  - **Rules** (`rules/*.md`) — Governance rules loaded per-command
17
16
 
18
17
  ## Installation
@@ -48,7 +47,6 @@ Then in OpenCode, use commands like:
48
47
  ├── AGENTS.md # Global constitution
49
48
  ├── rules/ # Governance rule modules
50
49
  ├── commands/ # 11 PDCA command playbooks (auto-discovered by OpenCode)
51
- ├── agents/ # 9 agent definitions (mode: subagent)
52
50
  ├── skills/ # 10 skill packages (AI agent loads on demand)
53
51
  └── opencode.json # Global config (model routing, instructions)
54
52
 
@@ -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.1.0"
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.1.0,<5.2.0",
13
14
  ]
14
15
 
15
16
  [project.entry-points."pactkit.deployers"]
@@ -10,7 +10,6 @@ from pathlib import Path
10
10
  from pactkit import __version__
11
11
  from pactkit.config import (
12
12
  DEFAULT_RULE_IDS,
13
- VALID_AGENTS,
14
13
  VALID_COMMANDS,
15
14
  VALID_SKILLS,
16
15
  activate_pactkit_maintainer_overlay,
@@ -21,7 +20,6 @@ from pactkit.generators.deploy_base import DeployerBase, register_deployer
21
20
  from pactkit.generators.deployer import (
22
21
  _cleanup_legacy,
23
22
  _cleanup_legacy_portable_methods,
24
- _deploy_agents,
25
23
  _deploy_ci,
26
24
  _deploy_commands,
27
25
  _deploy_guides,
@@ -29,8 +27,8 @@ from pactkit.generators.deployer import (
29
27
  _deploy_skills,
30
28
  )
31
29
  from pactkit.generators.spi import generate_config_if_missing
32
- from pactkit_opencode import declarations
33
30
  from pactkit.utils import atomic_write
31
+ from pactkit_opencode import declarations
34
32
 
35
33
  # All canonical commands deploy. Sprint has a sequential capability fallback.
36
34
  OPENCODE_EXCLUDED_COMMANDS: frozenset[str] = frozenset()
@@ -147,31 +145,56 @@ class OpenCodeDeployer(DeployerBase):
147
145
  """
148
146
  if global_only and project_only:
149
147
  raise ValueError("global_only and project_only are mutually exclusive")
148
+ # Protect direct calls and forced installs before any target changes.
149
+ try:
150
+ from pactkit.deploy_manifest import retire_bundled_roles
151
+ except ImportError as exc:
152
+ raise RuntimeError("PactKit Core 5.0.4 or newer is required by the opencode adapter") from exc
150
153
  opencode_root = Path(target) if target else Path.home() / ".config" / "opencode"
151
154
  project_root = Path(project_root) if project_root is not None else Path.cwd()
152
155
 
153
156
  print("🚀 PactKit OpenCode Deployment")
154
157
 
158
+ # round18 #1: terminate before ANY global write — including the script-path
159
+ # post-processing that rewrites command files — if a component dir or nested
160
+ # entry escapes into a project.
161
+ if not project_only:
162
+ from pactkit.deploy_shared import assert_global_component_boundary
163
+ from pactkit.generators.deployer import _mkdir_within
164
+
165
+ assert_global_component_boundary(opencode_root, extra_dirs=("plugins",))
166
+
155
167
  # Prepare directories (global components only; project-only integration
156
168
  # writes no machine-global OpenCode state).
157
- agents_dir = opencode_root / "agents"
158
169
  skills_dir = opencode_root / "skills"
159
170
  commands_dir = opencode_root / "commands"
160
171
  rules_dir = opencode_root / "rules"
161
172
 
162
173
  if not project_only:
163
- for d in [opencode_root, agents_dir, skills_dir, commands_dir, rules_dir]:
164
- d.mkdir(parents=True, exist_ok=True)
174
+ for d in [opencode_root, skills_dir, commands_dir, rules_dir]:
175
+ _mkdir_within(opencode_root, d)
165
176
 
166
177
  # STORY-slim-008 R1+R2: Load config from project-level pactkit.yaml.
167
178
  # A global-only deployment never reads the project (Core supplies cfg).
168
179
  from pactkit.config import find_pactkit_yaml
169
180
 
170
- project_yaml = None if global_only else find_pactkit_yaml(project_root)
181
+ if global_only:
182
+ project_yaml = None
183
+ elif project_only:
184
+ # Review A#1: integration is scoped to the target project — never walk
185
+ # up to an outer project's YAML. Imported here so a global-only deploy
186
+ # never needs the integration API (round4 #4).
187
+ from pactkit.config import resolve_integration_config
188
+
189
+ _scoped_cfg, project_yaml = resolve_integration_config(project_root, format="opencode")
190
+ if config is None:
191
+ config = _scoped_cfg
192
+ else:
193
+ project_yaml = find_pactkit_yaml(project_root)
171
194
 
172
195
  if config is not None:
173
196
  cfg = config
174
- elif project_yaml is not None:
197
+ elif project_yaml is not None and project_yaml.is_file():
175
198
  auto_added = auto_merge_config_file(project_yaml)
176
199
  for item in auto_added:
177
200
  print(f" -> Auto-added: {item}")
@@ -181,7 +204,6 @@ class OpenCodeDeployer(DeployerBase):
181
204
  if not global_only:
182
205
  cfg = activate_pactkit_maintainer_overlay(cfg, project_root)
183
206
 
184
- enabled_agents = cfg.get("agents", sorted(VALID_AGENTS))
185
207
  enabled_skills = cfg.get("skills", sorted(VALID_SKILLS))
186
208
  enabled_commands = cfg.get("commands", sorted(VALID_COMMANDS))
187
209
  enabled_rules = cfg.get("rules", sorted(DEFAULT_RULE_IDS))
@@ -189,64 +211,41 @@ class OpenCodeDeployer(DeployerBase):
189
211
  # Apply explicit format exclusions (currently none).
190
212
  enabled_commands = [c for c in enabled_commands if c not in OPENCODE_EXCLUDED_COMMANDS]
191
213
 
192
- n_skills = n_commands = n_agents = n_plugins = 0
214
+ n_skills = n_commands = n_plugins = 0
193
215
  if not project_only:
194
216
  # Deploy embedded skills (pactkit-board, pactkit-visualize, etc.)
217
+ # round21 #2: CLI-to-script conversion happens INSIDE _deploy_skills
218
+ # (content_transform) BEFORE the ownership check, so a user-edited skill
219
+ # is preserved against the final content — not rewritten by a post-pass.
195
220
  n_skills = _deploy_skills(
196
221
  skills_dir,
197
222
  enabled_skills,
198
223
  profile=self.profile,
224
+ content_transform=_replace_cli_with_scripts,
199
225
  )
200
226
  _cleanup_legacy_portable_methods(skills_dir, self.profile)
201
227
  _cleanup_legacy(skills_dir)
202
228
  # Clean up legacy command skills from skills/ directory (migrated to commands/)
203
229
  self._cleanup_command_skills(skills_dir)
204
230
 
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
- )
231
+ # round22 #2: ownership is recorded ONLY at the final manifest commit
232
+ # (write_deploy_manifest below), never mid-deploy by directory/file name.
233
+ # An early record_deployed_file glob claimed the on-disk bytes of a
234
+ # user-edited SKILL.md that preserve_or_write had just PRESERVED (writing
235
+ # a .pactkit-new candidate). If the gate-plugin write then failed, the
236
+ # final manifest never ran to exclude it, so the poisoned record survived
237
+ # and the next retry overwrote the user's original. pactkit_owned_files
238
+ # already skips any artifact with a .pactkit-new sibling, so the single
239
+ # final commit records confirmed-written files only.
228
240
 
229
241
  # 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
- )
242
+ # round20 #2: the CLI-to-script conversion happens INSIDE _deploy_commands
243
+ # (content_transform) BEFORE the ownership check, so a user-edited command
244
+ # file is preserved against the final content — not rewritten by a post-pass.
245
+ n_commands = _deploy_commands(
246
+ commands_dir, enabled_commands, profile=self.profile, config=cfg,
247
+ content_transform=_replace_cli_with_scripts,
248
+ )
250
249
 
251
250
  # R4 (2026-09-11 review): retire instruction refs BEFORE _deploy_rules
252
251
  # deletes byte-identical legacy files — ref ownership is proven by the
@@ -277,7 +276,7 @@ class OpenCodeDeployer(DeployerBase):
277
276
  _deploy_guides(opencode_root, profile=self.profile)
278
277
  self._deploy_agents_md_inline(opencode_root)
279
278
 
280
- n_agents = _deploy_agents(agents_dir, enabled_agents, profile=self.profile)
279
+ retire_bundled_roles(opencode_root)
281
280
 
282
281
 
283
282
  if not global_only:
@@ -286,24 +285,30 @@ class OpenCodeDeployer(DeployerBase):
286
285
  _deploy_ci(ci_provider, project_root, cfg)
287
286
 
288
287
  if not project_only:
289
- # STORY-slim-139 R2: machine-readable deployment manifest
288
+ import hashlib
289
+
290
290
  from pactkit.deploy_manifest import write_deploy_manifest
291
291
 
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).
292
+ # round13 #2: install the gate plugin BEFORE stamping the manifest
293
+ # complete. If the plugin write fails or is interrupted, the manifest
294
+ # is never stamped current, so `update --if-needed` repairs this Host
295
+ # instead of skipping it and leaving a missing/stale gate.
303
296
  n_plugins = self._deploy_gate_plugin(opencode_root)
304
297
 
298
+ # round14 #2: the plugin ownership lands in the SAME manifest commit as
299
+ # the version + input digest (extra_files), so an interruption between
300
+ # two writes cannot leave the Host stamped current while the plugin is
301
+ # absent from the uninstall inventory.
302
+ extra_files = {}
303
+ if n_plugins:
304
+ plugin_rel = "plugins/pactkit-gate.js"
305
+ extra_files[plugin_rel] = hashlib.sha256(
306
+ (opencode_root / plugin_rel).read_bytes()
307
+ ).hexdigest()
308
+ write_deploy_manifest(opencode_root, "opencode", cfg, extra_files=extra_files)
309
+
305
310
  print(
306
- f"\n✅ OpenCode: {n_agents} Agents, {n_skills} Skills, "
311
+ f"\n✅ OpenCode: {n_skills} Skills, "
307
312
  f"{n_commands} Commands, {n_plugins} Gate plugin → {opencode_root}"
308
313
  )
309
314
 
@@ -324,14 +329,26 @@ class OpenCodeDeployer(DeployerBase):
324
329
  Recorded in the deployment manifest, so `pactkit uninstall` removes it
325
330
  with the rest of the owned files — no residue (R4).
326
331
  """
327
- from pactkit.deploy_manifest import atomic_write, record_deployed_file
332
+ from pactkit.deploy_manifest import atomic_write
333
+ from pactkit.deploy_shared import project_write_target_or_none
328
334
  from pactkit.generators.opencode_plugin import render_plugin_source
329
335
 
336
+ plugin_rel = "plugins/pactkit-gate.js"
337
+ # round14 #1: a plugins/ dir reached through an escaping symlink would land
338
+ # the global gate plugin inside a project (Story B global boundary). The
339
+ # atomic write only protects the final replace; the parent dir link still
340
+ # decides where the temp and final file land, so check the real path first.
341
+ if project_write_target_or_none(opencode_root, plugin_rel) is None:
342
+ raise ValueError(
343
+ f"{plugin_rel} resolves outside the deploy root {opencode_root} "
344
+ "(symlink escape); refusing to write a global asset into a project"
345
+ )
330
346
  plugins_dir = opencode_root / "plugins"
331
347
  plugins_dir.mkdir(parents=True, exist_ok=True)
332
348
  plugin_path = plugins_dir / "pactkit-gate.js"
333
349
  atomic_write(plugin_path, render_plugin_source())
334
- record_deployed_file(opencode_root, plugin_path.relative_to(opencode_root).as_posix())
350
+ # Ownership is recorded by write_deploy_manifest(extra_files=...) in the
351
+ # same commit as the version + digest (round14 #2), not a separate write.
335
352
  return 1
336
353
 
337
354
  @staticmethod
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pactkit-opencode
3
- Version: 5.0.0
3
+ Version: 5.1.0
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.2.0,>=5.1.0
@@ -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.2.0,>=5.1.0
@@ -32,11 +32,11 @@ class TestR1NoGlobalOpencodeJson:
32
32
  deploy(format="opencode", target=str(out))
33
33
  assert (out / "AGENTS.md").is_file()
34
34
 
35
- def test_global_deploy_has_agents_dir(self, tmp_path):
36
- """agents/ IS created in global deployment."""
35
+ def test_global_deploy_does_not_install_bundled_roles(self, tmp_path):
36
+ """Global deploy leaves native roles to the user."""
37
37
  out = tmp_path / "opencode-global"
38
38
  deploy(format="opencode", target=str(out))
39
- assert (out / "agents").is_dir()
39
+ assert not list((out / "agents").glob("*.md"))
40
40
 
41
41
  def test_global_deploy_has_commands_dir(self, tmp_path):
42
42
  """commands/ IS created — OpenCode uses /command-name to invoke."""
@@ -28,12 +28,12 @@ _PROJECT_ROOT = Path(__file__).parent.parent.parent
28
28
  class TestOpenCodeSelectiveDeploy:
29
29
  """AC1: _deploy_opencode reads pactkit.yaml and filters agents/commands."""
30
30
 
31
- def test_opencode_deploys_only_configured_agents(self, tmp_path, monkeypatch):
32
- """When pactkit.yaml has 3 agents, only 3 agent files are created."""
33
- from pactkit.config import VALID_AGENTS, VALID_COMMANDS, VALID_RULES, VALID_SKILLS
31
+ def test_opencode_ignores_old_explicit_roles(self, tmp_path, monkeypatch):
32
+ """Legacy selections cannot bring back the bundled catalog."""
33
+ from pactkit.config import VALID_COMMANDS, VALID_RULES, VALID_SKILLS
34
34
 
35
35
  # Create a pactkit.yaml with 3 specific agents
36
- three_agents = sorted(VALID_AGENTS)[:3]
36
+ three_agents = ["qa-engineer", "code-explorer", "system-medic"]
37
37
  config_yaml = yaml.dump(
38
38
  {
39
39
  "stack": "python",
@@ -60,14 +60,10 @@ class TestOpenCodeSelectiveDeploy:
60
60
  # Resolve macOS /var → /private/var symlink
61
61
  agents_dir = Path(output_path).resolve() / "agents"
62
62
  deployed_agents = list(agents_dir.glob("*.md")) if agents_dir.exists() else []
63
- assert len(deployed_agents) == len(three_agents), (
64
- f"Expected {len(three_agents)} agents, got {len(deployed_agents)}: "
65
- f"{[f.name for f in deployed_agents]}, agents_dir={agents_dir}"
66
- )
63
+ assert deployed_agents == []
67
64
 
68
- def test_opencode_deploys_all_agents_when_no_config(self, tmp_path):
69
- """When no pactkit.yaml exists, all agents are deployed (fallback)."""
70
- from pactkit.config import VALID_AGENTS
65
+ def test_opencode_deploys_no_bundled_agents_when_no_config(self, tmp_path):
66
+ """Without an explicit choice, OpenCode emits no bundled role files."""
71
67
 
72
68
  # No pactkit.yaml — no .opencode dir either
73
69
  with patch.object(OpenCodeDeployer, "_generate_project_agents_md"):
@@ -78,9 +74,7 @@ class TestOpenCodeSelectiveDeploy:
78
74
 
79
75
  agents_dir = tmp_path / "output" / "agents"
80
76
  deployed_agents = list(agents_dir.glob("*.md")) if agents_dir.exists() else []
81
- assert len(deployed_agents) == len(VALID_AGENTS), (
82
- f"Expected all {len(VALID_AGENTS)} agents, got {len(deployed_agents)}"
83
- )
77
+ assert deployed_agents == []
84
78
 
85
79
 
86
80
  # ---------------------------------------------------------------------------
@@ -93,13 +87,13 @@ class TestOpenCodeAutoMerge:
93
87
 
94
88
  def test_auto_merge_called_when_yaml_exists(self, tmp_path):
95
89
  """auto_merge_config_file must be called during OpenCode deployment."""
96
- from pactkit.config import VALID_AGENTS, VALID_COMMANDS, VALID_RULES, VALID_SKILLS
90
+ from pactkit.config import VALID_COMMANDS, VALID_RULES, VALID_SKILLS
97
91
 
98
92
  config_yaml = yaml.dump(
99
93
  {
100
94
  "stack": "python",
101
95
  "version": "1.0.0",
102
- "agents": sorted(VALID_AGENTS),
96
+ "agents": ["qa-engineer"],
103
97
  "commands": sorted(VALID_COMMANDS),
104
98
  "skills": sorted(VALID_SKILLS),
105
99
  "rules": sorted(VALID_RULES),
@@ -300,3 +294,31 @@ class TestGenerateConfigIfMissing:
300
294
  _generate_config_if_missing(format="opencode")
301
295
 
302
296
  assert existing.read_text() == "version: existing\n", "Should not overwrite existing yaml"
297
+
298
+
299
+ def test_explicit_opt_out_retires_owned_roles_and_keeps_user_customization(tmp_path):
300
+ import json
301
+
302
+ root = tmp_path / "opencode"
303
+ deployer = OpenCodeDeployer()
304
+ import hashlib
305
+
306
+ agents = root / "agents"
307
+ agents.mkdir(parents=True)
308
+ files = {}
309
+ for name in ("qa-engineer", "code-explorer"):
310
+ path = agents / f"{name}.md"
311
+ path.write_bytes(b"old bundled role")
312
+ files[f"agents/{name}.md"] = hashlib.sha256(path.read_bytes()).hexdigest()
313
+ (root / ".pactkit-deployed.json").write_text(json.dumps({
314
+ "format": "opencode", "agents": ["qa-engineer", "code-explorer"], "files": files,
315
+ }))
316
+ assert (agents / "qa-engineer.md").is_file()
317
+ custom = agents / "code-explorer.md"
318
+ assert custom.is_file()
319
+ custom.write_text("User-owned edit\n")
320
+ for _ in range(2):
321
+ deployer.deploy(target=str(root), config={"agents": []}, global_only=True)
322
+ assert not (agents / "qa-engineer.md").exists()
323
+ assert custom.read_text() == "User-owned edit\n"
324
+ assert json.loads((root / ".pactkit-deployed.json").read_text())["agents"] == []
@@ -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"]
@@ -14,9 +14,8 @@ because the path fell to `resolve_pactkit_yaml_dir`'s directory-existence
14
14
  fallback (measured 2026-09-26). A file whose contents belong to another host is
15
15
  a lifecycle fact nobody can act on.
16
16
 
17
- The chosen fix is **A — really generate it** (owner 2026-09-26), so all four
18
- hosts follow the same model: the project-root `pactkit.yaml` is the hand-written
19
- shared policy, and each host directory gets a generated override.
17
+ The declared path is still readable when intentionally configured. Normal
18
+ integration does not create policy files; explicit Core configuration does.
20
19
  """
21
20
 
22
21
  from __future__ import annotations
@@ -112,61 +111,23 @@ class TestTheThreeFactsAgree:
112
111
  f"{list(PACTKIT_YAML_CANDIDATES)}"
113
112
  )
114
113
 
115
- def test_the_declared_path_is_where_this_host_writes(self, project):
116
- """声明 == 生产者。这是缺的那一半——前两处一直一致,只有它在缺席。"""
114
+ def test_optional_config_is_not_created_by_deploy(self, project):
117
115
  from pactkit.profiles import get_profile
118
-
119
116
  from pactkit_opencode import OpenCodeDeployer
120
117
 
121
118
  OpenCodeDeployer().deploy()
119
+ assert not (project / get_profile("opencode").pactkit_yaml_path).exists()
120
+ assert not (project / "pactkit.yaml").exists()
122
121
 
123
- declared = project / get_profile("opencode").pactkit_yaml_path
124
- assert declared.is_file(), (
125
- f"本宿主声明 {declared!r} 却从不生产它——"
126
- f"found: {sorted(p.relative_to(project).as_posix() for p in project.rglob('pactkit.yaml'))}"
127
- )
128
-
129
- def test_it_is_cores_canonical_output(self, project):
130
- """内容来自 core 的 canonical generator,不是本仓的第二份模板。
131
-
132
- 逐字段断言会在「core 改了格式而本仓漂移」时照样通过;比字节不会。
133
-
134
- **两层各比各的生成器**(STORY-slim-20260928c7b15e04a216 Step 1a):
135
- 共享根对 `generate_default_yaml`,宿主路径对 `generate_sparse_host_yaml`。
136
- 只比其中一层,另一层就能悄悄漂移。
137
- """
138
- from pactkit.cleaners import detect_stacks
139
- from pactkit.config import generate_default_yaml, generate_sparse_host_yaml
140
- from pactkit.profiles import get_profile
141
-
122
+ def test_explicit_config_is_canonical_and_preserved(self, project):
123
+ from pactkit.config import generate_default_yaml, generate_sparse_host_yaml, write_initial_config_layers
142
124
  from pactkit_opencode import OpenCodeDeployer
143
125
 
126
+ shared, host = write_initial_config_layers(project, format="opencode", stack="python")
144
127
  OpenCodeDeployer().deploy()
145
-
146
- shared = (project / "pactkit.yaml").read_text()
147
- assert shared == generate_default_yaml(stack=detect_stacks(project))
148
-
149
- host = (project / get_profile("opencode").pactkit_yaml_path).read_text()
150
- assert host == generate_sparse_host_yaml()
151
-
152
- def test_the_config_is_valid_and_carries_the_format_version(self, project):
153
- from pactkit.config import VALID_STACKS
154
- from pactkit.profiles import get_profile
155
-
156
- from pactkit_opencode import OpenCodeDeployer
157
-
158
- OpenCodeDeployer().deploy()
159
-
160
- data = yaml.safe_load(
161
- (project / get_profile("opencode").pactkit_yaml_path).read_text()
162
- )
163
- assert data["schema_version"] == 1
164
- # 策略在共享根里;宿主层是**覆盖**,不是策略的第二份副本。
165
- shared = yaml.safe_load((project / "pactkit.yaml").read_text())
166
- assert shared["stack"] in VALID_STACKS
167
- assert "stack" not in data, (
168
- f"宿主层重复了项目策略:{sorted(data)}"
169
- )
128
+ assert shared.read_text() == generate_default_yaml(stack="python")
129
+ assert host.read_text() == generate_sparse_host_yaml()
130
+ assert "stack" not in yaml.safe_load(host.read_text())
170
131
 
171
132
 
172
133
  class TestTheCrossWriteIsClosed:
@@ -48,11 +48,11 @@ class TestR2GlobalDeployment:
48
48
  deploy(format="opencode", target=str(out))
49
49
  assert (out / "AGENTS.md").is_file()
50
50
 
51
- def test_agents_dir_exists(self, tmp_path):
51
+ def test_no_managed_roles_are_written(self, tmp_path):
52
52
  """agents/ directory is created."""
53
53
  out = tmp_path / "opencode"
54
54
  deploy(format="opencode", target=str(out))
55
- assert (out / "agents").is_dir()
55
+ assert not list((out / "agents").glob("*.md"))
56
56
 
57
57
  def test_commands_dir_created(self, tmp_path):
58
58
  """commands/ directory IS created — OpenCode uses /command-name to invoke."""
@@ -131,24 +131,19 @@ class TestR3ProjectDeployment:
131
131
 
132
132
 
133
133
  # ===========================================================================
134
- # R7: Agent tools format conversion (STORY-069 R7)
134
+ # R7: Preserve user-owned native agent permissions
135
135
  # ===========================================================================
136
136
 
137
137
 
138
- class TestR7AgentToolsFormat:
139
- """R7: Agent tools converted to OpenCode record format."""
140
-
141
- def test_agent_tools_is_record(self, tmp_path):
142
- """Agent tools should be record format, not string."""
138
+ class TestNativeAgentToolsUnchanged:
139
+ def test_user_agent_tools_stay_as_written(self, tmp_path):
143
140
  out = tmp_path / "opencode"
141
+ agent = out / "agents" / "system-architect.md"
142
+ agent.parent.mkdir(parents=True)
143
+ authored = b"---\nmode: subagent\ntools:\n read: true\n write: false\n---\nOwned by the user\n"
144
+ agent.write_bytes(authored)
144
145
  deploy(format="opencode", target=str(out))
145
- agent_content = (out / "agents" / "system-architect.md").read_text()
146
- # Should NOT have "tools: Read, Write" string format
147
- assert "tools: Read" not in agent_content
148
- assert "tools: [" not in agent_content
149
- # Should have record format with indented keys
150
- assert "tools:" in agent_content
151
- assert "read: true" in agent_content or "write: true" in agent_content
146
+ assert agent.read_bytes() == authored
152
147
 
153
148
 
154
149
  # ===========================================================================
@@ -0,0 +1,137 @@
1
+ """
2
+ STORY-070: OpenCode Format Compliance — Fix Spec-Implementation Gaps
3
+ Tests for OpenCode-native agent/command format conversion.
4
+ """
5
+
6
+ from unittest.mock import patch
7
+
8
+ from pactkit.generators.deployer import deploy
9
+
10
+
11
+ # ===========================================================================
12
+ # AC1: Command frontmatter conversion
13
+ # ===========================================================================
14
+
15
+
16
+ class TestAC1CommandFrontmatter:
17
+ """AC1: Commands use OpenCode frontmatter (agent: build, no allowed-tools)."""
18
+
19
+ def _extract_frontmatter(self, content):
20
+ """Extract YAML frontmatter from content that may have rule headers.
21
+
22
+ STORY-slim-011: OpenCode commands have inline rule content before the
23
+ --- frontmatter block. Find the --- block containing 'description:'.
24
+ """
25
+ import re
26
+ matches = list(re.finditer(r'---\n(.*?)\n---', content, re.DOTALL))
27
+ assert matches, f"No frontmatter found in content starting with: {content[:80]}"
28
+ for m in matches:
29
+ if "description:" in m.group(1):
30
+ return m.group(1)
31
+ return matches[-1].group(1)
32
+
33
+ def test_command_has_agent_build(self, tmp_path):
34
+ """Command frontmatter contains 'agent: build'."""
35
+ out = tmp_path / "oc"
36
+ deploy(format="opencode", target=str(out))
37
+ content = (out / "commands" / "project-plan.md").read_text()
38
+ frontmatter = self._extract_frontmatter(content)
39
+ assert "agent: build" in frontmatter
40
+
41
+ def test_command_no_allowed_tools(self, tmp_path):
42
+ """Command frontmatter does NOT contain 'allowed-tools'."""
43
+ out = tmp_path / "oc"
44
+ deploy(format="opencode", target=str(out))
45
+ content = (out / "commands" / "project-plan.md").read_text()
46
+ frontmatter = self._extract_frontmatter(content)
47
+ assert "allowed-tools" not in frontmatter
48
+
49
+ def test_all_commands_converted(self, tmp_path):
50
+ """All command files use OpenCode frontmatter."""
51
+ from pactkit.config import VALID_COMMANDS
52
+ EXCLUDED = frozenset()
53
+ out = tmp_path / "oc"
54
+ deploy(format="opencode", target=str(out))
55
+ commands_dir = out / "commands"
56
+ for cmd_name in VALID_COMMANDS - EXCLUDED:
57
+ cmd_file = commands_dir / f"{cmd_name}.md"
58
+ assert cmd_file.exists(), f"{cmd_name}.md missing in commands/"
59
+ content = cmd_file.read_text()
60
+ frontmatter = self._extract_frontmatter(content)
61
+ assert "allowed-tools" not in frontmatter, f"{cmd_name} still has allowed-tools"
62
+ assert "agent: build" in frontmatter, f"{cmd_name} missing agent: build"
63
+
64
+ def test_command_body_preserved(self, tmp_path):
65
+ """Command body content is preserved after frontmatter conversion."""
66
+ out = tmp_path / "oc"
67
+ deploy(format="opencode", target=str(out))
68
+ content = (out / "commands" / "project-plan.md").read_text()
69
+ # Body should still contain the command content
70
+ assert "# Command: Plan" in content
71
+
72
+ def test_classic_format_unchanged(self, tmp_path):
73
+ """Classic format still uses allowed-tools (not converted).
74
+ pactkit 2.7.0: commands deploy to skills/{name}/SKILL.md in classic format."""
75
+ out = tmp_path / "classic"
76
+ deploy(format="classic", target=str(out))
77
+ content = (out / "skills" / "project-plan" / "SKILL.md").read_text()
78
+ parts = content.split("---", 2)
79
+ frontmatter = parts[1]
80
+ assert "allowed-tools" in frontmatter
81
+
82
+
83
+ class TestBundledRolesRetired:
84
+ def test_default_deploys_no_bundled_roles(self, tmp_path):
85
+ for host in ("classic", "opencode"):
86
+ out = tmp_path / host
87
+ deploy(format=host, target=str(out))
88
+ assert list((out / "agents").glob("*.md")) == []
89
+ assert (out / "AGENTS.md").is_file() or (out / "CLAUDE.md").is_file()
90
+
91
+ def test_preexisting_native_role_is_preserved_verbatim(self, tmp_path):
92
+ role = tmp_path / "agents" / "system-architect.md"
93
+ role.parent.mkdir()
94
+ raw = b"---\nmode: subagent\nmodel: custom\n---\nUser-owned architecture role\n"
95
+ role.write_bytes(raw)
96
+ for _ in range(2):
97
+ deploy(format="opencode", target=str(tmp_path))
98
+ assert role.read_bytes() == raw
99
+ assert list(role.parent.glob("*.md")) == [role]
100
+
101
+
102
+ # ===========================================================================
103
+ # AC5: upgrade command supports opencode
104
+ # ===========================================================================
105
+
106
+
107
+ class TestAC5UpgradeOpenCode:
108
+ """AC5: pactkit upgrade --format opencode works."""
109
+
110
+ def test_upgrade_accepts_opencode(self, tmp_path):
111
+ """pactkit upgrade --format opencode deploys successfully."""
112
+ from pactkit.cli import main
113
+
114
+ out = tmp_path / "upgrade-out"
115
+ with patch("sys.argv", ["pactkit", "upgrade", "--format", "opencode", "-t", str(out)]):
116
+ main()
117
+ assert (out / "AGENTS.md").is_file()
118
+ assert not list((out / "agents").glob("*.md"))
119
+ assert (out / "commands" / "project-plan.md").is_file()
120
+
121
+
122
+ # ===========================================================================
123
+ # AC6: No regression in classic format
124
+ # ===========================================================================
125
+
126
+
127
+ class TestAC6ClassicRegression:
128
+ """AC6: Classic format behavior unchanged."""
129
+
130
+ def test_classic_commands_have_allowed_tools(self, tmp_path):
131
+ """Classic commands still have allowed-tools.
132
+ pactkit 2.7.0: commands deploy to skills/{name}/SKILL.md in classic format."""
133
+ out = tmp_path / "classic"
134
+ deploy(format="classic", target=str(out))
135
+ content = (out / "skills" / "project-act" / "SKILL.md").read_text()
136
+ assert "allowed-tools" in content
137
+
@@ -1 +0,0 @@
1
- pactkit<5.1.0,>=5.0.0
@@ -1,261 +0,0 @@
1
- """
2
- STORY-070: OpenCode Format Compliance — Fix Spec-Implementation Gaps
3
- Tests for OpenCode-native agent/command format conversion.
4
- """
5
-
6
- import re # noqa: I001
7
- from unittest.mock import patch
8
-
9
- from pactkit.generators.deployer import deploy
10
-
11
-
12
- # ===========================================================================
13
- # AC1: Command frontmatter conversion
14
- # ===========================================================================
15
-
16
-
17
- class TestAC1CommandFrontmatter:
18
- """AC1: Commands use OpenCode frontmatter (agent: build, no allowed-tools)."""
19
-
20
- def _extract_frontmatter(self, content):
21
- """Extract YAML frontmatter from content that may have rule headers.
22
-
23
- STORY-slim-011: OpenCode commands have inline rule content before the
24
- --- frontmatter block. Find the --- block containing 'description:'.
25
- """
26
- import re
27
- matches = list(re.finditer(r'---\n(.*?)\n---', content, re.DOTALL))
28
- assert matches, f"No frontmatter found in content starting with: {content[:80]}"
29
- for m in matches:
30
- if "description:" in m.group(1):
31
- return m.group(1)
32
- return matches[-1].group(1)
33
-
34
- def test_command_has_agent_build(self, tmp_path):
35
- """Command frontmatter contains 'agent: build'."""
36
- out = tmp_path / "oc"
37
- deploy(format="opencode", target=str(out))
38
- content = (out / "commands" / "project-plan.md").read_text()
39
- frontmatter = self._extract_frontmatter(content)
40
- assert "agent: build" in frontmatter
41
-
42
- def test_command_no_allowed_tools(self, tmp_path):
43
- """Command frontmatter does NOT contain 'allowed-tools'."""
44
- out = tmp_path / "oc"
45
- deploy(format="opencode", target=str(out))
46
- content = (out / "commands" / "project-plan.md").read_text()
47
- frontmatter = self._extract_frontmatter(content)
48
- assert "allowed-tools" not in frontmatter
49
-
50
- def test_all_commands_converted(self, tmp_path):
51
- """All command files use OpenCode frontmatter."""
52
- from pactkit.config import VALID_COMMANDS
53
- EXCLUDED = frozenset()
54
- out = tmp_path / "oc"
55
- deploy(format="opencode", target=str(out))
56
- commands_dir = out / "commands"
57
- for cmd_name in VALID_COMMANDS - EXCLUDED:
58
- cmd_file = commands_dir / f"{cmd_name}.md"
59
- assert cmd_file.exists(), f"{cmd_name}.md missing in commands/"
60
- content = cmd_file.read_text()
61
- frontmatter = self._extract_frontmatter(content)
62
- assert "allowed-tools" not in frontmatter, f"{cmd_name} still has allowed-tools"
63
- assert "agent: build" in frontmatter, f"{cmd_name} missing agent: build"
64
-
65
- def test_command_body_preserved(self, tmp_path):
66
- """Command body content is preserved after frontmatter conversion."""
67
- out = tmp_path / "oc"
68
- deploy(format="opencode", target=str(out))
69
- content = (out / "commands" / "project-plan.md").read_text()
70
- # Body should still contain the command content
71
- assert "# Command: Plan" in content
72
-
73
- def test_classic_format_unchanged(self, tmp_path):
74
- """Classic format still uses allowed-tools (not converted).
75
- pactkit 2.7.0: commands deploy to skills/{name}/SKILL.md in classic format."""
76
- out = tmp_path / "classic"
77
- deploy(format="classic", target=str(out))
78
- content = (out / "skills" / "project-plan" / "SKILL.md").read_text()
79
- parts = content.split("---", 2)
80
- frontmatter = parts[1]
81
- assert "allowed-tools" in frontmatter
82
-
83
-
84
- # ===========================================================================
85
- # AC2: Agent mode: subagent and no name field
86
- # ===========================================================================
87
-
88
-
89
- class TestAC2AgentMode:
90
- """AC2: Agent files have mode: subagent and no name field."""
91
-
92
- def test_agent_has_mode_subagent(self, tmp_path):
93
- """Agent frontmatter contains 'mode: subagent'."""
94
- out = tmp_path / "oc"
95
- deploy(format="opencode", target=str(out))
96
- content = (out / "agents" / "system-architect.md").read_text()
97
- parts = content.split("---", 2)
98
- frontmatter = parts[1]
99
- assert "mode: subagent" in frontmatter
100
-
101
- def test_agent_no_name_field(self, tmp_path):
102
- """Agent frontmatter does NOT contain 'name:' field."""
103
- out = tmp_path / "oc"
104
- deploy(format="opencode", target=str(out))
105
- content = (out / "agents" / "system-architect.md").read_text()
106
- parts = content.split("---", 2)
107
- frontmatter = parts[1]
108
- # Check that there's no 'name:' line in frontmatter
109
- for line in frontmatter.strip().split("\n"):
110
- assert not line.strip().startswith("name:"), f"Found unexpected name field: {line}"
111
-
112
- def test_all_agents_have_mode(self, tmp_path):
113
- """All agent files have mode: subagent."""
114
- out = tmp_path / "oc"
115
- deploy(format="opencode", target=str(out))
116
- agents_dir = out / "agents"
117
- for agent_file in agents_dir.glob("*.md"):
118
- content = agent_file.read_text()
119
- parts = content.split("---", 2)
120
- frontmatter = parts[1]
121
- assert "mode: subagent" in frontmatter, f"{agent_file.name} missing mode: subagent"
122
-
123
- def test_classic_format_keeps_name(self, tmp_path):
124
- """Classic format still includes name field (not converted)."""
125
- out = tmp_path / "classic"
126
- deploy(format="classic", target=str(out))
127
- content = (out / "agents" / "system-architect.md").read_text()
128
- parts = content.split("---", 2)
129
- frontmatter = parts[1]
130
- assert "name: system-architect" in frontmatter
131
-
132
-
133
- # ===========================================================================
134
- # AC3: Agent Claude Code fields cleaned
135
- # ===========================================================================
136
-
137
-
138
- class TestAC3AgentFieldCleanup:
139
- """AC3: Claude Code-specific fields removed in OpenCode format."""
140
-
141
- def test_no_permission_mode(self, tmp_path):
142
- """Agent frontmatter does NOT contain permissionMode."""
143
- out = tmp_path / "oc"
144
- deploy(format="opencode", target=str(out))
145
- content = (out / "agents" / "system-architect.md").read_text()
146
- parts = content.split("---", 2)
147
- frontmatter = parts[1]
148
- assert "permissionMode" not in frontmatter
149
-
150
- def test_no_memory_field(self, tmp_path):
151
- """Agent frontmatter does NOT contain memory field."""
152
- out = tmp_path / "oc"
153
- deploy(format="opencode", target=str(out))
154
- content = (out / "agents" / "system-architect.md").read_text()
155
- parts = content.split("---", 2)
156
- frontmatter = parts[1]
157
- # 'memory' should not appear as a frontmatter key
158
- for line in frontmatter.strip().split("\n"):
159
- assert not line.strip().startswith("memory:"), f"Found unexpected memory field: {line}"
160
-
161
- def test_no_skills_field(self, tmp_path):
162
- """Agent frontmatter does NOT contain skills field."""
163
- out = tmp_path / "oc"
164
- deploy(format="opencode", target=str(out))
165
- content = (out / "agents" / "system-architect.md").read_text()
166
- parts = content.split("---", 2)
167
- frontmatter = parts[1]
168
- for line in frontmatter.strip().split("\n"):
169
- assert not line.strip().startswith("skills:"), f"Found unexpected skills field: {line}"
170
-
171
- def test_all_agents_cleaned(self, tmp_path):
172
- """All agent files have Claude Code fields removed."""
173
- out = tmp_path / "oc"
174
- deploy(format="opencode", target=str(out))
175
- agents_dir = out / "agents"
176
- claude_fields = ["permissionMode", "memory:", "skills:"]
177
- for agent_file in agents_dir.glob("*.md"):
178
- content = agent_file.read_text()
179
- parts = content.split("---", 2)
180
- frontmatter = parts[1]
181
- for field in claude_fields:
182
- # Check each line to avoid false positives from body content
183
- for line in frontmatter.strip().split("\n"):
184
- stripped = line.strip()
185
- if field.endswith(":"):
186
- assert not stripped.startswith(field), f"{agent_file.name} has {field} in frontmatter"
187
- else:
188
- assert field not in stripped, f"{agent_file.name} has {field} in frontmatter"
189
-
190
-
191
- # ===========================================================================
192
- # AC4: Agent model inherit omitted
193
- # ===========================================================================
194
-
195
-
196
- class TestAC4AgentModelInherit:
197
- """AC4: model field omitted when value is 'inherit'."""
198
-
199
- def test_no_model_inherit(self, tmp_path):
200
- """Agent frontmatter does NOT contain 'model: inherit'."""
201
- out = tmp_path / "oc"
202
- deploy(format="opencode", target=str(out))
203
- # Default pactkit.yaml has agent_models, but without config override,
204
- # deploy uses all defaults which resolve to 'inherit'
205
- content = (out / "agents" / "system-architect.md").read_text()
206
- parts = content.split("---", 2)
207
- frontmatter = parts[1]
208
- assert "model: inherit" not in frontmatter
209
-
210
-
211
- # ===========================================================================
212
- # AC5: upgrade command supports opencode
213
- # ===========================================================================
214
-
215
-
216
- class TestAC5UpgradeOpenCode:
217
- """AC5: pactkit upgrade --format opencode works."""
218
-
219
- def test_upgrade_accepts_opencode(self, tmp_path):
220
- """pactkit upgrade --format opencode deploys successfully."""
221
- from pactkit.cli import main
222
-
223
- out = tmp_path / "upgrade-out"
224
- with patch("sys.argv", ["pactkit", "upgrade", "--format", "opencode", "-t", str(out)]):
225
- main()
226
- assert (out / "AGENTS.md").is_file()
227
- assert (out / "agents").is_dir()
228
-
229
-
230
- # ===========================================================================
231
- # AC6: No regression in classic format
232
- # ===========================================================================
233
-
234
-
235
- class TestAC6ClassicRegression:
236
- """AC6: Classic format behavior unchanged."""
237
-
238
- def test_classic_agents_have_name(self, tmp_path):
239
- """Classic agents still have name field."""
240
- out = tmp_path / "classic"
241
- deploy(format="classic", target=str(out))
242
- content = (out / "agents" / "senior-developer.md").read_text()
243
- assert "name: senior-developer" in content
244
-
245
- def test_classic_commands_have_allowed_tools(self, tmp_path):
246
- """Classic commands still have allowed-tools.
247
- pactkit 2.7.0: commands deploy to skills/{name}/SKILL.md in classic format."""
248
- out = tmp_path / "classic"
249
- deploy(format="classic", target=str(out))
250
- content = (out / "skills" / "project-act" / "SKILL.md").read_text()
251
- assert "allowed-tools" in content
252
-
253
- def test_classic_agents_have_simple_tools(self, tmp_path):
254
- """Classic agents still use string tools format."""
255
- out = tmp_path / "classic"
256
- deploy(format="classic", target=str(out))
257
- content = (out / "agents" / "senior-developer.md").read_text()
258
- parts = content.split("---", 2)
259
- frontmatter = parts[1]
260
- # Classic should have tools as string, not record
261
- assert "tools: Read" in frontmatter or "tools: [" in frontmatter or re.search(r"tools:.*Read", frontmatter)