pactkit-opencode 4.4.0__tar.gz → 4.4.2__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 (36) hide show
  1. {pactkit_opencode-4.4.0 → pactkit_opencode-4.4.2}/PKG-INFO +2 -2
  2. {pactkit_opencode-4.4.0 → pactkit_opencode-4.4.2}/pyproject.toml +2 -2
  3. {pactkit_opencode-4.4.0 → pactkit_opencode-4.4.2}/src/pactkit_opencode/declarations.py +6 -0
  4. {pactkit_opencode-4.4.0 → pactkit_opencode-4.4.2}/src/pactkit_opencode/deployer.py +30 -3
  5. {pactkit_opencode-4.4.0 → pactkit_opencode-4.4.2}/src/pactkit_opencode.egg-info/PKG-INFO +2 -2
  6. {pactkit_opencode-4.4.0 → pactkit_opencode-4.4.2}/src/pactkit_opencode.egg-info/SOURCES.txt +4 -0
  7. pactkit_opencode-4.4.2/src/pactkit_opencode.egg-info/requires.txt +1 -0
  8. pactkit_opencode-4.4.2/tests/test_command_models_honesty.py +49 -0
  9. pactkit_opencode-4.4.2/tests/test_global_agents_ownership.py +51 -0
  10. pactkit_opencode-4.4.2/tests/test_legacy_agents_migration.py +59 -0
  11. pactkit_opencode-4.4.2/tests/test_user_command_scope.py +54 -0
  12. pactkit_opencode-4.4.0/src/pactkit_opencode.egg-info/requires.txt +0 -1
  13. {pactkit_opencode-4.4.0 → pactkit_opencode-4.4.2}/README.md +0 -0
  14. {pactkit_opencode-4.4.0 → pactkit_opencode-4.4.2}/setup.cfg +0 -0
  15. {pactkit_opencode-4.4.0 → pactkit_opencode-4.4.2}/src/pactkit_opencode/__init__.py +0 -0
  16. {pactkit_opencode-4.4.0 → pactkit_opencode-4.4.2}/src/pactkit_opencode/enforcement.py +0 -0
  17. {pactkit_opencode-4.4.0 → pactkit_opencode-4.4.2}/src/pactkit_opencode.egg-info/dependency_links.txt +0 -0
  18. {pactkit_opencode-4.4.0 → pactkit_opencode-4.4.2}/src/pactkit_opencode.egg-info/entry_points.txt +0 -0
  19. {pactkit_opencode-4.4.0 → pactkit_opencode-4.4.2}/src/pactkit_opencode.egg-info/top_level.txt +0 -0
  20. {pactkit_opencode-4.4.0 → pactkit_opencode-4.4.2}/tests/test_a1_config_recovery.py +0 -0
  21. {pactkit_opencode-4.4.0 → pactkit_opencode-4.4.2}/tests/test_a2_mcp_retired.py +0 -0
  22. {pactkit_opencode-4.4.0 → pactkit_opencode-4.4.2}/tests/test_bug035_opencode_dual_layer.py +0 -0
  23. {pactkit_opencode-4.4.0 → pactkit_opencode-4.4.2}/tests/test_capability_contract.py +0 -0
  24. {pactkit_opencode-4.4.0 → pactkit_opencode-4.4.2}/tests/test_deploy_opencode_parity.py +0 -0
  25. {pactkit_opencode-4.4.0 → pactkit_opencode-4.4.2}/tests/test_gate_plugin_deploy.py +0 -0
  26. {pactkit_opencode-4.4.0 → pactkit_opencode-4.4.2}/tests/test_host_body_snapshot.py +0 -0
  27. {pactkit_opencode-4.4.0 → pactkit_opencode-4.4.2}/tests/test_opencode_enforcement_channel.py +0 -0
  28. {pactkit_opencode-4.4.0 → pactkit_opencode-4.4.2}/tests/test_profile_contract.py +0 -0
  29. {pactkit_opencode-4.4.0 → pactkit_opencode-4.4.2}/tests/test_step6_self_sufficiency.py +0 -0
  30. {pactkit_opencode-4.4.0 → pactkit_opencode-4.4.2}/tests/test_step8_declaration_search_producer.py +0 -0
  31. {pactkit_opencode-4.4.0 → pactkit_opencode-4.4.2}/tests/test_story069_opencode_format.py +0 -0
  32. {pactkit_opencode-4.4.0 → pactkit_opencode-4.4.2}/tests/test_story070_opencode_compliance.py +0 -0
  33. {pactkit_opencode-4.4.0 → pactkit_opencode-4.4.2}/tests/test_story071_opencode_config_parity.py +0 -0
  34. {pactkit_opencode-4.4.0 → pactkit_opencode-4.4.2}/tests/test_story073_command_model_routing.py +0 -0
  35. {pactkit_opencode-4.4.0 → pactkit_opencode-4.4.2}/tests/test_story_work_units.py +0 -0
  36. {pactkit_opencode-4.4.0 → pactkit_opencode-4.4.2}/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: 4.4.0
3
+ Version: 4.4.2
4
4
  Summary: PactKit adapter for OpenCode IDE
5
5
  License-Expression: MIT
6
6
  Requires-Python: >=3.10
7
- Requires-Dist: pactkit<4.5.0,>=4.4.0
7
+ Requires-Dist: pactkit<4.5.0,>=4.4.2
@@ -4,12 +4,12 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "pactkit-opencode"
7
- version = "4.4.0"
7
+ version = "4.4.2"
8
8
  description = "PactKit adapter for OpenCode IDE"
9
9
  requires-python = ">=3.10"
10
10
  license = "MIT"
11
11
  dependencies = [
12
- "pactkit>=4.4.0,<4.5.0",
12
+ "pactkit>=4.4.2,<4.5.0",
13
13
  ]
14
14
 
15
15
  [project.entry-points."pactkit.deployers"]
@@ -65,6 +65,12 @@ PROFILE = FormatProfile(
65
65
  rules_import_style='inline',
66
66
  excluded_agent_fields=frozenset({'memory', 'permissionMode', 'skills'}),
67
67
  excluded_commands=frozenset(),
68
+ # OpenCode (the host) supports model routing via model+template command
69
+ # entries — this flag records that host capability and is the distinguishing
70
+ # True in the capability set (the v4 §10.3 guard requires the flag to vary).
71
+ # The adapter does NOT write model-only routing (OpenCode rejects it); when
72
+ # command_models is set it warns explicitly rather than silently ignoring it
73
+ # (STORY-slim-202611196170677f83b5).
68
74
  supports_model_routing=True,
69
75
  skills_path_var='~/.config/opencode/skills',
70
76
  command_deploy_form='flat',
@@ -196,8 +196,13 @@ class OpenCodeDeployer(DeployerBase):
196
196
  # Clean up legacy command skills from skills/ directory (migrated to commands/)
197
197
  self._cleanup_command_skills(skills_dir)
198
198
 
199
- # Apply CLI-to-script replacement to deployed embedded skill SKILL.md files
199
+ # Apply CLI-to-script replacement ONLY to PactKit-managed skill files
200
+ # (STORY-slim-202611239641dc45a9fc): user-created skills stay untouched.
201
+ from pactkit.prompts.skills import get_skill_manifest
202
+ _skill_names = {s["name"] for s in get_skill_manifest()}
200
203
  for skill_md in skills_dir.glob("*/SKILL.md"):
204
+ if skill_md.parent.name not in _skill_names:
205
+ continue
201
206
  content = skill_md.read_text(encoding="utf-8")
202
207
  replaced = _replace_cli_with_scripts(content)
203
208
  if replaced != content:
@@ -209,6 +214,8 @@ class OpenCodeDeployer(DeployerBase):
209
214
  from pactkit.deploy_manifest import record_deployed_file
210
215
 
211
216
  for skill_md in skills_dir.glob("*/SKILL.md"):
217
+ if skill_md.parent.name not in _skill_names:
218
+ continue
212
219
  record_deployed_file(
213
220
  opencode_root, skill_md.relative_to(opencode_root).as_posix(),
214
221
  )
@@ -216,14 +223,21 @@ class OpenCodeDeployer(DeployerBase):
216
223
  # Deploy commands to commands/ directory (OpenCode uses /command-name to invoke)
217
224
  n_commands = _deploy_commands(commands_dir, enabled_commands, profile=self.profile, config=cfg)
218
225
 
219
- # Apply CLI-to-script replacement to deployed command files
226
+ # Apply CLI-to-script replacement ONLY to PactKit-managed command files
227
+ # (STORY-slim-202611239641dc45a9fc): user-created commands stay untouched.
228
+ from pactkit.prompts.commands import get_deployable_commands
229
+ _cmd_catalog = set(get_deployable_commands())
220
230
  for cmd_md in commands_dir.glob("*.md"):
231
+ if cmd_md.name not in _cmd_catalog:
232
+ continue
221
233
  content = cmd_md.read_text(encoding="utf-8")
222
234
  replaced = _replace_cli_with_scripts(content)
223
235
  if replaced != content:
224
236
  atomic_write(cmd_md, replaced)
225
237
 
226
238
  for cmd_md in commands_dir.glob("*.md"):
239
+ if cmd_md.name not in _cmd_catalog:
240
+ continue
227
241
  record_deployed_file(
228
242
  opencode_root, cmd_md.relative_to(opencode_root).as_posix(),
229
243
  )
@@ -237,6 +251,15 @@ class OpenCodeDeployer(DeployerBase):
237
251
  Path(self.profile.global_config_dir).expanduser()
238
252
  )
239
253
  command_models = cfg.get("command_models", {})
254
+ if command_models:
255
+ # Honesty (STORY-slim-202611196170677f83b5): OpenCode requires
256
+ # model+template command entries; model-only routing is not written,
257
+ # so this config is ignored. Say so instead of silently dropping it.
258
+ print(
259
+ " ⚠️ command_models is set but OpenCode does not consume model-only "
260
+ "command routing (its command entries require model+template); "
261
+ "this configuration is not applied."
262
+ )
240
263
  self._update_global_opencode_json(
241
264
  opencode_root,
242
265
  command_models=command_models,
@@ -367,7 +390,11 @@ class OpenCodeDeployer(DeployerBase):
367
390
  "A user-invoked PactKit command loads only its own phase contract and declared shared modules.",
368
391
  "",
369
392
  ]
370
- atomic_write(opencode_root / "AGENTS.md", "\n".join(lines))
393
+ # Global AGENTS.md is a user document with a PactKit-managed region;
394
+ # merge-semantics preserve user content (STORY-slim-20261120528a3b6615d3).
395
+ from pactkit.managed_docs import RUNTIME_INDEX_VERSION_RE, upsert_managed_block
396
+ upsert_managed_block(opencode_root / "AGENTS.md", "\n".join(lines),
397
+ legacy_version_pattern=RUNTIME_INDEX_VERSION_RE)
371
398
 
372
399
  @staticmethod
373
400
  def _resolve_opencode_model_id(short_name, providers):
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pactkit-opencode
3
- Version: 4.4.0
3
+ Version: 4.4.2
4
4
  Summary: PactKit adapter for OpenCode IDE
5
5
  License-Expression: MIT
6
6
  Requires-Python: >=3.10
7
- Requires-Dist: pactkit<4.5.0,>=4.4.0
7
+ Requires-Dist: pactkit<4.5.0,>=4.4.2
@@ -14,9 +14,12 @@ tests/test_a1_config_recovery.py
14
14
  tests/test_a2_mcp_retired.py
15
15
  tests/test_bug035_opencode_dual_layer.py
16
16
  tests/test_capability_contract.py
17
+ tests/test_command_models_honesty.py
17
18
  tests/test_deploy_opencode_parity.py
18
19
  tests/test_gate_plugin_deploy.py
20
+ tests/test_global_agents_ownership.py
19
21
  tests/test_host_body_snapshot.py
22
+ tests/test_legacy_agents_migration.py
20
23
  tests/test_opencode_enforcement_channel.py
21
24
  tests/test_profile_contract.py
22
25
  tests/test_step6_self_sufficiency.py
@@ -26,4 +29,5 @@ tests/test_story070_opencode_compliance.py
26
29
  tests/test_story071_opencode_config_parity.py
27
30
  tests/test_story073_command_model_routing.py
28
31
  tests/test_story_work_units.py
32
+ tests/test_user_command_scope.py
29
33
  tests/test_wire_format_contract.py
@@ -0,0 +1 @@
1
+ pactkit<4.5.0,>=4.4.2
@@ -0,0 +1,49 @@
1
+ """STORY-slim-202611196170677f83b5: opencode command_models 契约诚实性(R3)。
2
+
3
+ OpenCode 的 command 条目需 model+template,model-only 路由不被消费。adapter 因此
4
+ 声明 supports_model_routing=False,并在 command_models 被设置时显式告警(而非静默忽略)。
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import os
10
+ import subprocess
11
+ import sys
12
+ from pathlib import Path
13
+
14
+ import pactkit_opencode # noqa: F401 (registers host)
15
+ from pactkit.profiles import get_profile
16
+
17
+ REPO = Path(__file__).resolve().parents[2]
18
+ CORE = REPO.parent / "pactkit"
19
+
20
+
21
+ def test_opencode_declares_host_model_routing_capability():
22
+ # Host capability (model+template); the adapter warns on model-only config
23
+ # rather than silently ignoring it. The flag is the distinguishing True in
24
+ # the capability set (v4 §10.3 guard).
25
+ assert get_profile("opencode").supports_model_routing is True
26
+
27
+
28
+ def test_command_models_config_warns_not_silently_ignored(tmp_path):
29
+ home = tmp_path / "home"
30
+ proj = tmp_path / "proj"
31
+ home.mkdir()
32
+ proj.mkdir()
33
+ (proj / "pactkit.yaml").write_text(
34
+ "schema_version: 1\ncommand_models:\n project-act: sonnet\n",
35
+ encoding="utf-8",
36
+ )
37
+ env = {**os.environ, "HOME": str(home), "USERPROFILE": str(home),
38
+ "PYTHONPATH": f"{REPO / 'src'}:{CORE / 'src'}"}
39
+ for var in ("CLAUDECODE", "CLAUDE_CODE_ENTRYPOINT", "CODEX_SESSION_ID", "CODEX_THREAD_ID"):
40
+ env.pop(var, None)
41
+ proc = subprocess.run(
42
+ [sys.executable, "-m", "pactkit", "init", "--format", "opencode",
43
+ "--no-git", "--no-external", "--non-interactive"],
44
+ cwd=proj, env=env, capture_output=True, text=True, timeout=180,
45
+ )
46
+ assert proc.returncode == 0, proc.stderr[-800:]
47
+ assert "command_models" in proc.stdout and "not applied" in proc.stdout, (
48
+ "command_models should warn that it is not applied, not be silently dropped"
49
+ )
@@ -0,0 +1,51 @@
1
+ """STORY-slim-20261120528a3b6615d3: 全局 AGENTS.md ownership(opencode)。"""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ import subprocess
7
+ import sys
8
+ from pathlib import Path
9
+
10
+ REPO = Path(__file__).resolve().parents[1]
11
+ CORE = REPO.parent / "pactkit"
12
+
13
+
14
+ def _deploy_opencode(target: Path, home: Path) -> subprocess.CompletedProcess:
15
+ env = {**os.environ, "HOME": str(home), "USERPROFILE": str(home),
16
+ "PYTHONPATH": f"{REPO / 'src'}:{CORE / 'src'}"}
17
+ for var in ("CLAUDECODE", "CLAUDE_CODE_ENTRYPOINT", "CODEX_SESSION_ID", "CODEX_THREAD_ID"):
18
+ env.pop(var, None)
19
+ return subprocess.run(
20
+ [sys.executable, "-m", "pactkit", "init", "--format", "opencode",
21
+ "--target", str(target), "--no-git", "--no-external", "--non-interactive"],
22
+ cwd=target, env=env, capture_output=True, text=True, timeout=180,
23
+ )
24
+
25
+
26
+ def test_global_agents_preserves_user_content(tmp_path):
27
+ home = tmp_path / "home"
28
+ target = tmp_path / "deploy"
29
+ home.mkdir()
30
+ target.mkdir()
31
+ (target / "AGENTS.md").write_text(
32
+ "# My global instructions\n\nUSER-OWNED-CONTENT-KEEP-ME\n", encoding="utf-8"
33
+ )
34
+ proc = _deploy_opencode(target, home)
35
+ assert proc.returncode == 0, proc.stderr[-800:]
36
+ body = (target / "AGENTS.md").read_text(encoding="utf-8")
37
+ assert "USER-OWNED-CONTENT-KEEP-ME" in body, "user content clobbered by deploy"
38
+ assert "pactkit:start" in body and "pactkit:end" in body, "managed block missing"
39
+
40
+
41
+ def test_global_agents_idempotent_redeploy(tmp_path):
42
+ home = tmp_path / "home"
43
+ target = tmp_path / "deploy"
44
+ home.mkdir()
45
+ target.mkdir()
46
+ (target / "AGENTS.md").write_text("USER-CONTENT\n", encoding="utf-8")
47
+ assert _deploy_opencode(target, home).returncode == 0
48
+ assert _deploy_opencode(target, home).returncode == 0
49
+ second = (target / "AGENTS.md").read_text(encoding="utf-8")
50
+ assert "USER-CONTENT" in second
51
+ assert second.count("pactkit:start") == 1, "managed block duplicated on redeploy"
@@ -0,0 +1,59 @@
1
+ """STORY-slim-20261123ea97a0e84212: opencode 全局 AGENTS 旧版升级迁移(真实部署)。"""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ import re
7
+ import subprocess
8
+ import sys
9
+ from pathlib import Path
10
+
11
+ REPO = Path(__file__).resolve().parents[1]
12
+ CORE = REPO.parent / "pactkit"
13
+
14
+
15
+ def _deploy_opencode(target: Path, home: Path) -> subprocess.CompletedProcess:
16
+ env = {**os.environ, "HOME": str(home), "USERPROFILE": str(home),
17
+ "PYTHONPATH": f"{REPO / 'src'}:{CORE / 'src'}"}
18
+ for var in ("CLAUDECODE", "CLAUDE_CODE_ENTRYPOINT", "CODEX_SESSION_ID", "CODEX_THREAD_ID"):
19
+ env.pop(var, None)
20
+ return subprocess.run(
21
+ [sys.executable, "-m", "pactkit", "init", "--format", "opencode",
22
+ "--target", str(target), "--no-git", "--no-external", "--non-interactive"],
23
+ cwd=target, env=env, capture_output=True, text=True, timeout=180,
24
+ )
25
+
26
+
27
+ def _legacy_from_deployed(deployed: str) -> str:
28
+ body = deployed.split("<!-- pactkit:start -->\n", 1)[1].split("\n<!-- pactkit:end -->", 1)[0]
29
+ return re.sub(r"# PactKit Runtime Contract \(v[0-9.]+\)",
30
+ "# PactKit Runtime Contract (v4.4.1)", body)
31
+
32
+
33
+ def test_legacy_v441_upgrade_migrates_no_double_rules(tmp_path):
34
+ """AC1:旧版整份规则升级 → 单一受管区块,无双份。"""
35
+ home = tmp_path / "home"
36
+ target = tmp_path / "deploy"
37
+ home.mkdir()
38
+ target.mkdir()
39
+ assert _deploy_opencode(target, home).returncode == 0
40
+ agents = target / "AGENTS.md"
41
+ agents.write_text(_legacy_from_deployed(agents.read_text(encoding="utf-8")), encoding="utf-8")
42
+ assert _deploy_opencode(target, home).returncode == 0
43
+ result = agents.read_text(encoding="utf-8")
44
+ assert result.count("<!-- pactkit:start -->") == 1, "升级后双份受管区块"
45
+ assert result.count("## Active Command Rules") == 1, "升级后双份规则正文"
46
+
47
+
48
+ def test_user_edited_legacy_preserved_on_upgrade(tmp_path):
49
+ """AC2:用户在旧版上加内容 → 升级保留用户内容。"""
50
+ home = tmp_path / "home"
51
+ target = tmp_path / "deploy"
52
+ home.mkdir()
53
+ target.mkdir()
54
+ assert _deploy_opencode(target, home).returncode == 0
55
+ agents = target / "AGENTS.md"
56
+ legacy = _legacy_from_deployed(agents.read_text(encoding="utf-8"))
57
+ agents.write_text(legacy + "\nUSER-EDIT-KEEP-ME\n", encoding="utf-8")
58
+ assert _deploy_opencode(target, home).returncode == 0
59
+ assert "USER-EDIT-KEEP-ME" in agents.read_text(encoding="utf-8"), "用户编辑内容被删"
@@ -0,0 +1,54 @@
1
+ """STORY-slim-202611239641dc45a9fc: opencode 命令转换仅限 PactKit 管理文件。"""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ import subprocess
7
+ import sys
8
+ from pathlib import Path
9
+
10
+ REPO = Path(__file__).resolve().parents[1]
11
+ CORE = REPO.parent / "pactkit"
12
+
13
+
14
+ def _deploy_opencode(target: Path, home: Path) -> subprocess.CompletedProcess:
15
+ env = {**os.environ, "HOME": str(home), "USERPROFILE": str(home),
16
+ "PYTHONPATH": f"{REPO / 'src'}:{CORE / 'src'}"}
17
+ for var in ("CLAUDECODE", "CLAUDE_CODE_ENTRYPOINT", "CODEX_SESSION_ID", "CODEX_THREAD_ID"):
18
+ env.pop(var, None)
19
+ return subprocess.run(
20
+ [sys.executable, "-m", "pactkit", "init", "--format", "opencode",
21
+ "--target", str(target), "--no-git", "--no-external", "--non-interactive"],
22
+ cwd=target, env=env, capture_output=True, text=True, timeout=180, check=False,
23
+ )
24
+
25
+
26
+ def test_user_command_not_rewritten(tmp_path):
27
+ """AC1:用户自建 commands/my-team.md 逐字节保留(pactkit visualize 不被改写)。"""
28
+ home = tmp_path / "home"
29
+ target = tmp_path / "deploy"
30
+ home.mkdir()
31
+ target.mkdir()
32
+ cmd_dir = target / "commands"
33
+ cmd_dir.mkdir(parents=True)
34
+ user_cmd = cmd_dir / "my-team.md"
35
+ original = "---\ndescription: team convention\n---\nRun `pactkit visualize` for graphs.\n"
36
+ user_cmd.write_text(original, encoding="utf-8")
37
+ proc = _deploy_opencode(target, home)
38
+ assert proc.returncode == 0, proc.stderr[-600:]
39
+ assert user_cmd.read_text(encoding="utf-8") == original, "用户自建命令被转换改写"
40
+
41
+
42
+ def test_pactkit_commands_still_transformed(tmp_path):
43
+ """AC2:PactKit 管理的命令文件仍做 CLI→脚本转换(既有功能不回归)。"""
44
+ home = tmp_path / "home"
45
+ target = tmp_path / "deploy"
46
+ home.mkdir()
47
+ 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
+ )
@@ -1 +0,0 @@
1
- pactkit<4.5.0,>=4.4.0