pactkit-opencode 5.0.3__tar.gz → 5.2.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. {pactkit_opencode-5.0.3 → pactkit_opencode-5.2.1}/PKG-INFO +2 -2
  2. {pactkit_opencode-5.0.3 → pactkit_opencode-5.2.1}/README.md +0 -2
  3. {pactkit_opencode-5.0.3 → pactkit_opencode-5.2.1}/pyproject.toml +2 -2
  4. {pactkit_opencode-5.0.3 → pactkit_opencode-5.2.1}/src/pactkit_opencode/deployer.py +9 -8
  5. {pactkit_opencode-5.0.3 → pactkit_opencode-5.2.1}/src/pactkit_opencode.egg-info/PKG-INFO +2 -2
  6. pactkit_opencode-5.2.1/src/pactkit_opencode.egg-info/requires.txt +1 -0
  7. {pactkit_opencode-5.0.3 → pactkit_opencode-5.2.1}/tests/test_bug035_opencode_dual_layer.py +3 -3
  8. {pactkit_opencode-5.0.3 → pactkit_opencode-5.2.1}/tests/test_deploy_opencode_parity.py +38 -16
  9. {pactkit_opencode-5.0.3 → pactkit_opencode-5.2.1}/tests/test_step8_declaration_search_producer.py +11 -50
  10. {pactkit_opencode-5.0.3 → pactkit_opencode-5.2.1}/tests/test_story069_opencode_format.py +10 -15
  11. pactkit_opencode-5.2.1/tests/test_story070_opencode_compliance.py +137 -0
  12. {pactkit_opencode-5.0.3 → pactkit_opencode-5.2.1}/tests/test_story_work_units.py +2 -1
  13. {pactkit_opencode-5.0.3 → pactkit_opencode-5.2.1}/tests/test_user_command_scope.py +17 -9
  14. pactkit_opencode-5.0.3/src/pactkit_opencode.egg-info/requires.txt +0 -1
  15. pactkit_opencode-5.0.3/tests/test_story070_opencode_compliance.py +0 -261
  16. {pactkit_opencode-5.0.3 → pactkit_opencode-5.2.1}/setup.cfg +0 -0
  17. {pactkit_opencode-5.0.3 → pactkit_opencode-5.2.1}/src/pactkit_opencode/__init__.py +0 -0
  18. {pactkit_opencode-5.0.3 → pactkit_opencode-5.2.1}/src/pactkit_opencode/declarations.py +0 -0
  19. {pactkit_opencode-5.0.3 → pactkit_opencode-5.2.1}/src/pactkit_opencode/enforcement.py +0 -0
  20. {pactkit_opencode-5.0.3 → pactkit_opencode-5.2.1}/src/pactkit_opencode.egg-info/SOURCES.txt +0 -0
  21. {pactkit_opencode-5.0.3 → pactkit_opencode-5.2.1}/src/pactkit_opencode.egg-info/dependency_links.txt +0 -0
  22. {pactkit_opencode-5.0.3 → pactkit_opencode-5.2.1}/src/pactkit_opencode.egg-info/entry_points.txt +0 -0
  23. {pactkit_opencode-5.0.3 → pactkit_opencode-5.2.1}/src/pactkit_opencode.egg-info/top_level.txt +0 -0
  24. {pactkit_opencode-5.0.3 → pactkit_opencode-5.2.1}/tests/test_a1_config_recovery.py +0 -0
  25. {pactkit_opencode-5.0.3 → pactkit_opencode-5.2.1}/tests/test_a2_mcp_retired.py +0 -0
  26. {pactkit_opencode-5.0.3 → pactkit_opencode-5.2.1}/tests/test_capability_contract.py +0 -0
  27. {pactkit_opencode-5.0.3 → pactkit_opencode-5.2.1}/tests/test_command_models_honesty.py +0 -0
  28. {pactkit_opencode-5.0.3 → pactkit_opencode-5.2.1}/tests/test_gate_plugin_deploy.py +0 -0
  29. {pactkit_opencode-5.0.3 → pactkit_opencode-5.2.1}/tests/test_global_agents_ownership.py +0 -0
  30. {pactkit_opencode-5.0.3 → pactkit_opencode-5.2.1}/tests/test_host_body_snapshot.py +0 -0
  31. {pactkit_opencode-5.0.3 → pactkit_opencode-5.2.1}/tests/test_legacy_agents_migration.py +0 -0
  32. {pactkit_opencode-5.0.3 → pactkit_opencode-5.2.1}/tests/test_opencode_enforcement_channel.py +0 -0
  33. {pactkit_opencode-5.0.3 → pactkit_opencode-5.2.1}/tests/test_profile_contract.py +0 -0
  34. {pactkit_opencode-5.0.3 → pactkit_opencode-5.2.1}/tests/test_review_round13_order.py +0 -0
  35. {pactkit_opencode-5.0.3 → pactkit_opencode-5.2.1}/tests/test_review_round14.py +0 -0
  36. {pactkit_opencode-5.0.3 → pactkit_opencode-5.2.1}/tests/test_step6_self_sufficiency.py +0 -0
  37. {pactkit_opencode-5.0.3 → pactkit_opencode-5.2.1}/tests/test_story071_opencode_config_parity.py +0 -0
  38. {pactkit_opencode-5.0.3 → pactkit_opencode-5.2.1}/tests/test_story073_command_model_routing.py +0 -0
  39. {pactkit_opencode-5.0.3 → pactkit_opencode-5.2.1}/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.3
3
+ Version: 5.2.1
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.3
7
+ Requires-Dist: pactkit<5.3.0,>=5.2.1
@@ -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,13 +4,13 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "pactkit-opencode"
7
- version = "5.0.3"
7
+ version = "5.2.1"
8
8
  description = "PactKit adapter for OpenCode IDE"
9
9
  requires-python = ">=3.10"
10
10
  license = "MIT"
11
11
  dependencies = [
12
12
  # round4 #4: resolve_integration_config first ships in core 5.0.2.
13
- "pactkit>=5.0.3,<5.1.0",
13
+ "pactkit>=5.2.1,<5.3.0",
14
14
  ]
15
15
 
16
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,
@@ -147,6 +145,11 @@ 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
 
@@ -163,13 +166,12 @@ class OpenCodeDeployer(DeployerBase):
163
166
 
164
167
  # Prepare directories (global components only; project-only integration
165
168
  # writes no machine-global OpenCode state).
166
- agents_dir = opencode_root / "agents"
167
169
  skills_dir = opencode_root / "skills"
168
170
  commands_dir = opencode_root / "commands"
169
171
  rules_dir = opencode_root / "rules"
170
172
 
171
173
  if not project_only:
172
- for d in [opencode_root, agents_dir, skills_dir, commands_dir, rules_dir]:
174
+ for d in [opencode_root, skills_dir, commands_dir, rules_dir]:
173
175
  _mkdir_within(opencode_root, d)
174
176
 
175
177
  # STORY-slim-008 R1+R2: Load config from project-level pactkit.yaml.
@@ -202,7 +204,6 @@ class OpenCodeDeployer(DeployerBase):
202
204
  if not global_only:
203
205
  cfg = activate_pactkit_maintainer_overlay(cfg, project_root)
204
206
 
205
- enabled_agents = cfg.get("agents", sorted(VALID_AGENTS))
206
207
  enabled_skills = cfg.get("skills", sorted(VALID_SKILLS))
207
208
  enabled_commands = cfg.get("commands", sorted(VALID_COMMANDS))
208
209
  enabled_rules = cfg.get("rules", sorted(DEFAULT_RULE_IDS))
@@ -210,7 +211,7 @@ class OpenCodeDeployer(DeployerBase):
210
211
  # Apply explicit format exclusions (currently none).
211
212
  enabled_commands = [c for c in enabled_commands if c not in OPENCODE_EXCLUDED_COMMANDS]
212
213
 
213
- n_skills = n_commands = n_agents = n_plugins = 0
214
+ n_skills = n_commands = n_plugins = 0
214
215
  if not project_only:
215
216
  # Deploy embedded skills (pactkit-board, pactkit-visualize, etc.)
216
217
  # round21 #2: CLI-to-script conversion happens INSIDE _deploy_skills
@@ -275,7 +276,7 @@ class OpenCodeDeployer(DeployerBase):
275
276
  _deploy_guides(opencode_root, profile=self.profile)
276
277
  self._deploy_agents_md_inline(opencode_root)
277
278
 
278
- n_agents = _deploy_agents(agents_dir, enabled_agents, profile=self.profile)
279
+ retire_bundled_roles(opencode_root)
279
280
 
280
281
 
281
282
  if not global_only:
@@ -307,7 +308,7 @@ class OpenCodeDeployer(DeployerBase):
307
308
  write_deploy_manifest(opencode_root, "opencode", cfg, extra_files=extra_files)
308
309
 
309
310
  print(
310
- f"\n✅ OpenCode: {n_agents} Agents, {n_skills} Skills, "
311
+ f"\n✅ OpenCode: {n_skills} Skills, "
311
312
  f"{n_commands} Commands, {n_plugins} Gate plugin → {opencode_root}"
312
313
  )
313
314
 
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pactkit-opencode
3
- Version: 5.0.3
3
+ Version: 5.2.1
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.3
7
+ Requires-Dist: pactkit<5.3.0,>=5.2.1
@@ -0,0 +1 @@
1
+ pactkit<5.3.0,>=5.2.1
@@ -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"] == []
@@ -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
+
@@ -19,7 +19,8 @@ def test_opencode_uses_native_current_session_contract_without_portable_methods(
19
19
  manifest = json.loads((tmp_path / ".pactkit-deployed.json").read_text())
20
20
  assert manifest["host_capabilities"]["execution_mode"] == "portable"
21
21
  assert manifest["workflow_continuation"]["stop_hook_required"] is False
22
- assert len(manifest["skills"]) == 13
22
+ assert len(manifest["skills"]) == 11
23
+ assert {"pactkit-draw", "pactkit-review"}.isdisjoint(manifest["skills"])
23
24
 
24
25
 
25
26
  def test_opencode_upgrade_removes_only_unmodified_portable_methods(tmp_path):
@@ -39,16 +39,24 @@ def test_user_command_not_rewritten(tmp_path):
39
39
  assert user_cmd.read_text(encoding="utf-8") == original, "用户自建命令被转换改写"
40
40
 
41
41
 
42
- def test_pactkit_commands_still_transformed(tmp_path):
43
- """AC2:PactKit 管理的命令文件仍做 CLI→脚本转换(既有功能不回归)。"""
42
+ def test_pactkit_commands_still_transformed(tmp_path, monkeypatch):
43
+ """A managed command with legacy CLI text still gets translated on deploy."""
44
+ from pactkit_opencode.deployer import OpenCodeDeployer
45
+
46
+ from pactkit.prompts import commands
47
+
44
48
  home = tmp_path / "home"
45
49
  target = tmp_path / "deploy"
46
50
  home.mkdir()
47
51
  target.mkdir()
48
- assert _deploy_opencode(target, home).returncode == 0
49
- cmd_dir = target / "commands"
50
- pactkit_cmds = [p for p in cmd_dir.glob("*.md") if p.name != "my-team.md"]
51
- assert pactkit_cmds, "无 PactKit 命令部署"
52
- assert any("scripts/" in p.read_text(encoding="utf-8") for p in pactkit_cmds), (
53
- "PactKit 命令未被转换(CLI→脚本回归)"
54
- )
52
+ monkeypatch.setenv("HOME", str(home))
53
+ monkeypatch.setenv("USERPROFILE", str(home))
54
+ monkeypatch.setenv("XDG_CONFIG_HOME", str(home / ".config"))
55
+ original = "---\ndescription: synthetic legacy managed command\n---\nRun `pactkit visualize` for graphs.\n"
56
+ monkeypatch.setattr(commands, "get_deployable_commands", lambda: {"project-debug.md": original})
57
+
58
+ OpenCodeDeployer().deploy(config={}, target=target)
59
+
60
+ rendered = (target / "commands/project-debug.md").read_text(encoding="utf-8")
61
+ assert "`pactkit visualize`" not in rendered
62
+ assert "python3 ~/.config/opencode/skills/pactkit-visualize/scripts/visualize.py" in rendered
@@ -1 +0,0 @@
1
- pactkit<5.1.0,>=5.0.3
@@ -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)