pactkit-opencode 4.4.1__tar.gz → 5.0.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.
- {pactkit_opencode-4.4.1 → pactkit_opencode-5.0.0}/PKG-INFO +2 -2
- {pactkit_opencode-4.4.1 → pactkit_opencode-5.0.0}/pyproject.toml +2 -2
- {pactkit_opencode-4.4.1 → pactkit_opencode-5.0.0}/src/pactkit_opencode/declarations.py +6 -0
- {pactkit_opencode-4.4.1 → pactkit_opencode-5.0.0}/src/pactkit_opencode/deployer.py +127 -92
- {pactkit_opencode-4.4.1 → pactkit_opencode-5.0.0}/src/pactkit_opencode.egg-info/PKG-INFO +2 -2
- {pactkit_opencode-4.4.1 → pactkit_opencode-5.0.0}/src/pactkit_opencode.egg-info/SOURCES.txt +4 -0
- pactkit_opencode-5.0.0/src/pactkit_opencode.egg-info/requires.txt +1 -0
- pactkit_opencode-5.0.0/tests/test_command_models_honesty.py +49 -0
- pactkit_opencode-5.0.0/tests/test_global_agents_ownership.py +51 -0
- pactkit_opencode-5.0.0/tests/test_legacy_agents_migration.py +59 -0
- pactkit_opencode-5.0.0/tests/test_user_command_scope.py +54 -0
- pactkit_opencode-4.4.1/src/pactkit_opencode.egg-info/requires.txt +0 -1
- {pactkit_opencode-4.4.1 → pactkit_opencode-5.0.0}/README.md +0 -0
- {pactkit_opencode-4.4.1 → pactkit_opencode-5.0.0}/setup.cfg +0 -0
- {pactkit_opencode-4.4.1 → pactkit_opencode-5.0.0}/src/pactkit_opencode/__init__.py +0 -0
- {pactkit_opencode-4.4.1 → pactkit_opencode-5.0.0}/src/pactkit_opencode/enforcement.py +0 -0
- {pactkit_opencode-4.4.1 → pactkit_opencode-5.0.0}/src/pactkit_opencode.egg-info/dependency_links.txt +0 -0
- {pactkit_opencode-4.4.1 → pactkit_opencode-5.0.0}/src/pactkit_opencode.egg-info/entry_points.txt +0 -0
- {pactkit_opencode-4.4.1 → pactkit_opencode-5.0.0}/src/pactkit_opencode.egg-info/top_level.txt +0 -0
- {pactkit_opencode-4.4.1 → pactkit_opencode-5.0.0}/tests/test_a1_config_recovery.py +0 -0
- {pactkit_opencode-4.4.1 → pactkit_opencode-5.0.0}/tests/test_a2_mcp_retired.py +0 -0
- {pactkit_opencode-4.4.1 → pactkit_opencode-5.0.0}/tests/test_bug035_opencode_dual_layer.py +0 -0
- {pactkit_opencode-4.4.1 → pactkit_opencode-5.0.0}/tests/test_capability_contract.py +0 -0
- {pactkit_opencode-4.4.1 → pactkit_opencode-5.0.0}/tests/test_deploy_opencode_parity.py +0 -0
- {pactkit_opencode-4.4.1 → pactkit_opencode-5.0.0}/tests/test_gate_plugin_deploy.py +0 -0
- {pactkit_opencode-4.4.1 → pactkit_opencode-5.0.0}/tests/test_host_body_snapshot.py +0 -0
- {pactkit_opencode-4.4.1 → pactkit_opencode-5.0.0}/tests/test_opencode_enforcement_channel.py +0 -0
- {pactkit_opencode-4.4.1 → pactkit_opencode-5.0.0}/tests/test_profile_contract.py +0 -0
- {pactkit_opencode-4.4.1 → pactkit_opencode-5.0.0}/tests/test_step6_self_sufficiency.py +0 -0
- {pactkit_opencode-4.4.1 → pactkit_opencode-5.0.0}/tests/test_step8_declaration_search_producer.py +0 -0
- {pactkit_opencode-4.4.1 → pactkit_opencode-5.0.0}/tests/test_story069_opencode_format.py +0 -0
- {pactkit_opencode-4.4.1 → pactkit_opencode-5.0.0}/tests/test_story070_opencode_compliance.py +0 -0
- {pactkit_opencode-4.4.1 → pactkit_opencode-5.0.0}/tests/test_story071_opencode_config_parity.py +0 -0
- {pactkit_opencode-4.4.1 → pactkit_opencode-5.0.0}/tests/test_story073_command_model_routing.py +0 -0
- {pactkit_opencode-4.4.1 → pactkit_opencode-5.0.0}/tests/test_story_work_units.py +0 -0
- {pactkit_opencode-4.4.1 → pactkit_opencode-5.0.0}/tests/test_wire_format_contract.py +0 -0
|
@@ -4,12 +4,12 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "pactkit-opencode"
|
|
7
|
-
version = "
|
|
7
|
+
version = "5.0.0"
|
|
8
8
|
description = "PactKit adapter for OpenCode IDE"
|
|
9
9
|
requires-python = ">=3.10"
|
|
10
10
|
license = "MIT"
|
|
11
11
|
dependencies = [
|
|
12
|
-
"pactkit>=
|
|
12
|
+
"pactkit>=5.0.0,<5.1.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',
|
|
@@ -133,38 +133,41 @@ class OpenCodeDeployer(DeployerBase):
|
|
|
133
133
|
deployment_claim = declarations.DEPLOYMENT_CLAIM
|
|
134
134
|
input_translation = declarations.INPUT_TRANSLATION
|
|
135
135
|
|
|
136
|
-
def deploy(self, config=None, target=None, project_root=None, no_redetect=False
|
|
136
|
+
def deploy(self, config=None, target=None, project_root=None, no_redetect=False,
|
|
137
|
+
global_only=False, project_only=False):
|
|
137
138
|
"""Deploy PactKit configuration for OpenCode.
|
|
138
139
|
|
|
139
140
|
``project_root`` is **not** the deploy root: OpenCode installs globally
|
|
140
|
-
under ``~/.config/opencode``, and the two MUST NOT be confused.
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
alongside ``project_root``; it is a no-op here — this deployer's
|
|
147
|
-
stack probe only reads the filesystem and never writes the stack
|
|
148
|
-
back into the config.
|
|
141
|
+
under ``~/.config/opencode``, and the two MUST NOT be confused.
|
|
142
|
+
|
|
143
|
+
``global_only`` (STORY-slim-20261125f4db76f08fc5): a global Host
|
|
144
|
+
deployment must not read or write any project file. ``project_only``
|
|
145
|
+
(R3, ``pactkit integrate``) is the inverse: write only project artifacts,
|
|
146
|
+
never re-deploy the machine-global OpenCode components other projects load.
|
|
149
147
|
"""
|
|
148
|
+
if global_only and project_only:
|
|
149
|
+
raise ValueError("global_only and project_only are mutually exclusive")
|
|
150
150
|
opencode_root = Path(target) if target else Path.home() / ".config" / "opencode"
|
|
151
151
|
project_root = Path(project_root) if project_root is not None else Path.cwd()
|
|
152
152
|
|
|
153
153
|
print("🚀 PactKit OpenCode Deployment")
|
|
154
154
|
|
|
155
|
-
# Prepare directories
|
|
155
|
+
# Prepare directories (global components only; project-only integration
|
|
156
|
+
# writes no machine-global OpenCode state).
|
|
156
157
|
agents_dir = opencode_root / "agents"
|
|
157
158
|
skills_dir = opencode_root / "skills"
|
|
158
159
|
commands_dir = opencode_root / "commands"
|
|
159
160
|
rules_dir = opencode_root / "rules"
|
|
160
161
|
|
|
161
|
-
|
|
162
|
-
d
|
|
162
|
+
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)
|
|
163
165
|
|
|
164
|
-
# STORY-slim-008 R1+R2: Load config from project-level pactkit.yaml
|
|
166
|
+
# STORY-slim-008 R1+R2: Load config from project-level pactkit.yaml.
|
|
167
|
+
# A global-only deployment never reads the project (Core supplies cfg).
|
|
165
168
|
from pactkit.config import find_pactkit_yaml
|
|
166
169
|
|
|
167
|
-
project_yaml = find_pactkit_yaml(project_root)
|
|
170
|
+
project_yaml = None if global_only else find_pactkit_yaml(project_root)
|
|
168
171
|
|
|
169
172
|
if config is not None:
|
|
170
173
|
cfg = config
|
|
@@ -175,7 +178,8 @@ class OpenCodeDeployer(DeployerBase):
|
|
|
175
178
|
cfg = load_config(project_yaml)
|
|
176
179
|
else:
|
|
177
180
|
cfg = {}
|
|
178
|
-
|
|
181
|
+
if not global_only:
|
|
182
|
+
cfg = activate_pactkit_maintainer_overlay(cfg, project_root)
|
|
179
183
|
|
|
180
184
|
enabled_agents = cfg.get("agents", sorted(VALID_AGENTS))
|
|
181
185
|
enabled_skills = cfg.get("skills", sorted(VALID_SKILLS))
|
|
@@ -185,98 +189,125 @@ class OpenCodeDeployer(DeployerBase):
|
|
|
185
189
|
# Apply explicit format exclusions (currently none).
|
|
186
190
|
enabled_commands = [c for c in enabled_commands if c not in OPENCODE_EXCLUDED_COMMANDS]
|
|
187
191
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
_cleanup_legacy(skills_dir)
|
|
196
|
-
# Clean up legacy command skills from skills/ directory (migrated to commands/)
|
|
197
|
-
self._cleanup_command_skills(skills_dir)
|
|
198
|
-
|
|
199
|
-
# Apply CLI-to-script replacement to deployed embedded skill SKILL.md files
|
|
200
|
-
for skill_md in skills_dir.glob("*/SKILL.md"):
|
|
201
|
-
content = skill_md.read_text(encoding="utf-8")
|
|
202
|
-
replaced = _replace_cli_with_scripts(content)
|
|
203
|
-
if replaced != content:
|
|
204
|
-
atomic_write(skill_md, replaced)
|
|
205
|
-
|
|
206
|
-
# HOTFIX-slim-20260903d464746b1909: post-pass rewrites deployed bytes in
|
|
207
|
-
# place; record the FINAL (transformed) digests or the next deploy cannot
|
|
208
|
-
# prove ownership and re-produces .pactkit-new candidates.
|
|
209
|
-
from pactkit.deploy_manifest import record_deployed_file
|
|
210
|
-
|
|
211
|
-
for skill_md in skills_dir.glob("*/SKILL.md"):
|
|
212
|
-
record_deployed_file(
|
|
213
|
-
opencode_root, skill_md.relative_to(opencode_root).as_posix(),
|
|
192
|
+
n_skills = n_commands = n_agents = n_plugins = 0
|
|
193
|
+
if not project_only:
|
|
194
|
+
# Deploy embedded skills (pactkit-board, pactkit-visualize, etc.)
|
|
195
|
+
n_skills = _deploy_skills(
|
|
196
|
+
skills_dir,
|
|
197
|
+
enabled_skills,
|
|
198
|
+
profile=self.profile,
|
|
214
199
|
)
|
|
200
|
+
_cleanup_legacy_portable_methods(skills_dir, self.profile)
|
|
201
|
+
_cleanup_legacy(skills_dir)
|
|
202
|
+
# Clean up legacy command skills from skills/ directory (migrated to commands/)
|
|
203
|
+
self._cleanup_command_skills(skills_dir)
|
|
204
|
+
|
|
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
|
+
)
|
|
215
228
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
229
|
+
# 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
|
+
)
|
|
230
250
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
251
|
+
# R4 (2026-09-11 review): retire instruction refs BEFORE _deploy_rules
|
|
252
|
+
# deletes byte-identical legacy files — ref ownership is proven by the
|
|
253
|
+
# referenced file's content, so the files must still exist here.
|
|
254
|
+
providers = self._load_opencode_providers(opencode_root)
|
|
255
|
+
if not providers:
|
|
256
|
+
providers = self._load_opencode_providers(
|
|
257
|
+
Path(self.profile.global_config_dir).expanduser()
|
|
258
|
+
)
|
|
259
|
+
command_models = cfg.get("command_models", {})
|
|
260
|
+
if command_models:
|
|
261
|
+
# Honesty (STORY-slim-202611196170677f83b5): OpenCode requires
|
|
262
|
+
# model+template command entries; model-only routing is not written,
|
|
263
|
+
# so this config is ignored. Say so instead of silently dropping it.
|
|
264
|
+
print(
|
|
265
|
+
" ⚠️ command_models is set but OpenCode does not consume model-only "
|
|
266
|
+
"command routing (its command entries require model+template); "
|
|
267
|
+
"this configuration is not applied."
|
|
268
|
+
)
|
|
269
|
+
self._update_global_opencode_json(
|
|
270
|
+
opencode_root,
|
|
271
|
+
command_models=command_models,
|
|
272
|
+
providers=providers,
|
|
273
|
+
enabled_commands=enabled_commands,
|
|
238
274
|
)
|
|
239
|
-
command_models = cfg.get("command_models", {})
|
|
240
|
-
self._update_global_opencode_json(
|
|
241
|
-
opencode_root,
|
|
242
|
-
command_models=command_models,
|
|
243
|
-
providers=providers,
|
|
244
|
-
enabled_commands=enabled_commands,
|
|
245
|
-
)
|
|
246
275
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
276
|
+
_deploy_rules(opencode_root, enabled_rules, profile=self.profile)
|
|
277
|
+
_deploy_guides(opencode_root, profile=self.profile)
|
|
278
|
+
self._deploy_agents_md_inline(opencode_root)
|
|
250
279
|
|
|
251
|
-
|
|
280
|
+
n_agents = _deploy_agents(agents_dir, enabled_agents, profile=self.profile)
|
|
252
281
|
|
|
253
282
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
283
|
+
if not global_only:
|
|
284
|
+
ci_config = cfg.get("ci", {})
|
|
285
|
+
ci_provider = ci_config.get("provider", "none") if isinstance(ci_config, dict) else "none"
|
|
286
|
+
_deploy_ci(ci_provider, project_root, cfg)
|
|
257
287
|
|
|
258
|
-
|
|
259
|
-
|
|
288
|
+
if not project_only:
|
|
289
|
+
# STORY-slim-139 R2: machine-readable deployment manifest
|
|
290
|
+
from pactkit.deploy_manifest import write_deploy_manifest
|
|
260
291
|
|
|
261
|
-
|
|
292
|
+
write_deploy_manifest(opencode_root, "opencode", cfg)
|
|
262
293
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
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).
|
|
303
|
+
n_plugins = self._deploy_gate_plugin(opencode_root)
|
|
273
304
|
|
|
274
305
|
print(
|
|
275
306
|
f"\n✅ OpenCode: {n_agents} Agents, {n_skills} Skills, "
|
|
276
307
|
f"{n_commands} Commands, {n_plugins} Gate plugin → {opencode_root}"
|
|
277
308
|
)
|
|
278
309
|
|
|
279
|
-
if target is None:
|
|
310
|
+
if target is None and not global_only:
|
|
280
311
|
self._generate_project_agents_md(project_root)
|
|
281
312
|
self._generate_project_config(project_root)
|
|
282
313
|
|
|
@@ -367,7 +398,11 @@ class OpenCodeDeployer(DeployerBase):
|
|
|
367
398
|
"A user-invoked PactKit command loads only its own phase contract and declared shared modules.",
|
|
368
399
|
"",
|
|
369
400
|
]
|
|
370
|
-
|
|
401
|
+
# Global AGENTS.md is a user document with a PactKit-managed region;
|
|
402
|
+
# merge-semantics preserve user content (STORY-slim-20261120528a3b6615d3).
|
|
403
|
+
from pactkit.managed_docs import RUNTIME_INDEX_VERSION_RE, upsert_managed_block
|
|
404
|
+
upsert_managed_block(opencode_root / "AGENTS.md", "\n".join(lines),
|
|
405
|
+
legacy_version_pattern=RUNTIME_INDEX_VERSION_RE)
|
|
371
406
|
|
|
372
407
|
@staticmethod
|
|
373
408
|
def _resolve_opencode_model_id(short_name, providers):
|
|
@@ -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<5.1.0,>=5.0.0
|
|
@@ -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.1
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pactkit_opencode-4.4.1 → pactkit_opencode-5.0.0}/src/pactkit_opencode.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
{pactkit_opencode-4.4.1 → pactkit_opencode-5.0.0}/src/pactkit_opencode.egg-info/entry_points.txt
RENAMED
|
File without changes
|
{pactkit_opencode-4.4.1 → pactkit_opencode-5.0.0}/src/pactkit_opencode.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pactkit_opencode-4.4.1 → pactkit_opencode-5.0.0}/tests/test_opencode_enforcement_channel.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pactkit_opencode-4.4.1 → pactkit_opencode-5.0.0}/tests/test_step8_declaration_search_producer.py
RENAMED
|
File without changes
|
|
File without changes
|
{pactkit_opencode-4.4.1 → pactkit_opencode-5.0.0}/tests/test_story070_opencode_compliance.py
RENAMED
|
File without changes
|
{pactkit_opencode-4.4.1 → pactkit_opencode-5.0.0}/tests/test_story071_opencode_config_parity.py
RENAMED
|
File without changes
|
{pactkit_opencode-4.4.1 → pactkit_opencode-5.0.0}/tests/test_story073_command_model_routing.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|