Skip to content

Commit 9458a6b

Browse files
committed
fix(agent-context): preserve disabled context target
1 parent 10cbff3 commit 9458a6b

2 files changed

Lines changed: 37 additions & 8 deletions

File tree

src/specify_cli/agents.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -398,18 +398,19 @@ def resolve_skill_placeholders(
398398

399399
body = body.replace("{ARGS}", "$ARGUMENTS").replace("__AGENT__", agent_name)
400400

401-
# Resolve __CONTEXT_FILE__ from the agent-context extension config
402-
# when enabled. Fall back to init-options.json for projects that
403-
# haven't migrated or that explicitly disabled the extension.
401+
# Resolve __CONTEXT_FILE__ from the agent-context extension config.
402+
# When disabled, ignore stale context_files but keep the singular
403+
# context_file value so generated commands still point at the agent
404+
# context file managed before the extension was disabled.
404405
context_file = ""
405406
from .integrations.base import IntegrationBase
406407

407-
if IntegrationBase._agent_context_extension_enabled(project_root):
408-
# Local import: _load_agent_context_config lives in __init__.py which
409-
# imports agents.py, so a top-level import would be circular.
410-
from . import _load_agent_context_config
408+
# Local import: _load_agent_context_config lives in __init__.py which
409+
# imports agents.py, so a top-level import would be circular.
410+
from . import _load_agent_context_config
411411

412-
ac_cfg = _load_agent_context_config(project_root)
412+
ac_cfg = _load_agent_context_config(project_root)
413+
if IntegrationBase._agent_context_extension_enabled(project_root):
413414
context_files = ac_cfg.get("context_files")
414415
if isinstance(context_files, list):
415416
context_file_values = []
@@ -435,6 +436,10 @@ def resolve_skill_placeholders(
435436
context_file = IntegrationBase._validate_context_file_path(
436437
project_root, candidate
437438
)
439+
else:
440+
configured_context_file = ac_cfg.get("context_file")
441+
if isinstance(configured_context_file, str):
442+
context_file = configured_context_file.strip()
438443
if not context_file:
439444
context_file = init_opts.get("context_file") or ""
440445
body = body.replace("__CONTEXT_FILE__", context_file)

tests/extensions/test_extension_agent_context.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import os
77
import shutil
88
import subprocess
9+
import sys
910
from pathlib import Path
1011

1112
import pytest
@@ -155,6 +156,8 @@ def shlex_quote(value: str) -> str:
155156

156157
def _run_powershell_agent_context_script(project_root: Path) -> subprocess.CompletedProcess:
157158
script = EXT_DIR / "scripts" / "powershell" / "update-agent-context.ps1"
159+
env = os.environ.copy()
160+
env["PATH"] = str(Path(sys.executable).parent) + os.pathsep + env.get("PATH", "")
158161
return subprocess.run(
159162
[
160163
POWERSHELL,
@@ -165,6 +168,7 @@ def _run_powershell_agent_context_script(project_root: Path) -> subprocess.Compl
165168
str(script),
166169
],
167170
cwd=project_root,
171+
env=env,
168172
capture_output=True,
169173
text=True,
170174
timeout=30,
@@ -540,6 +544,26 @@ def test_disabled_extension_ignores_invalid_context_files(self, tmp_path):
540544

541545
assert content == "Read AGENTS.md"
542546

547+
def test_disabled_extension_uses_extension_context_file_before_init_options(
548+
self, tmp_path
549+
):
550+
_write_registry(tmp_path, enabled=False)
551+
_write_ext_config(
552+
tmp_path,
553+
context_file="AGENTS.md",
554+
context_files=["CLAUDE.md"],
555+
)
556+
save_init_options(tmp_path, {"context_file": "LEGACY.md"})
557+
558+
content = CommandRegistrar.resolve_skill_placeholders(
559+
"codex",
560+
{},
561+
"Read __CONTEXT_FILE__",
562+
tmp_path,
563+
)
564+
565+
assert content == "Read AGENTS.md"
566+
543567

544568
class TestBundledUpdaterPathValidation:
545569
def test_bash_script_contains_resolved_containment_check(self):

0 commit comments

Comments
 (0)