Skip to content

Commit 2849e6d

Browse files
authored
Apply review feedback: drop dead try/except, guard ext-config creation, explicit ConvertFrom-Yaml check
1 parent b848b62 commit 2849e6d

3 files changed

Lines changed: 26 additions & 23 deletions

File tree

extensions/agent-context/scripts/powershell/update-agent-context.ps1

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,21 @@ $ProjectRoot = (Get-Location).Path
5959
$ExtConfig = Join-Path $ProjectRoot '.specify/extensions/agent-context/agent-context-config.yml'
6060

6161
if (-not (Test-Path -LiteralPath $ExtConfig)) {
62-
Write-Host "agent-context: $ExtConfig not found; nothing to do."
62+
Write-Warning "agent-context: $ExtConfig not found; nothing to do."
6363
exit 0
6464
}
6565

66-
try {
67-
$Options = Get-Content -LiteralPath $ExtConfig -Raw | ConvertFrom-Yaml -ErrorAction Stop
68-
} catch {
69-
# ConvertFrom-Yaml may not be available on all systems.
70-
# Fall back to Python+PyYAML for consistent parsing semantics.
66+
$Options = $null
67+
if (Get-Command ConvertFrom-Yaml -ErrorAction SilentlyContinue) {
68+
try {
69+
$Options = Get-Content -LiteralPath $ExtConfig -Raw | ConvertFrom-Yaml -ErrorAction Stop
70+
} catch {
71+
$Options = $null # fall through to Python fallback
72+
}
73+
}
74+
75+
if ($null -eq $Options) {
76+
# ConvertFrom-Yaml unavailable or failed; fall back to Python+PyYAML.
7177
$pythonCmd = $null
7278
foreach ($candidate in @('python3', 'python')) {
7379
if (Get-Command $candidate -ErrorAction SilentlyContinue) {
@@ -126,7 +132,7 @@ if (-not (Test-ConfigObject -Object $Options)) {
126132

127133
$ContextFile = Get-ConfigValue -Object $Options -Key 'context_file'
128134
if (-not $ContextFile) {
129-
Write-Host 'agent-context: context_file not set in extension config; nothing to do.'
135+
Write-Warning 'agent-context: context_file not set in extension config; nothing to do.'
130136
exit 0
131137
}
132138

src/specify_cli/__init__.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,11 +1592,14 @@ def _clear_init_options_for_integration(project_root: Path, integration_key: str
15921592
opts.pop("ai", None)
15931593
opts.pop("ai_skills", None)
15941594
save_init_options(project_root, opts)
1595-
# Clear context_file in the extension config too. If the config file
1596-
# does not exist yet, create it so no stale target can persist.
1597-
_update_agent_context_config_file(
1598-
project_root, "", preserve_markers=True
1599-
)
1595+
# Clear context_file in the extension config if it already exists.
1596+
# Avoid creating the config (and parent dirs) in projects where the
1597+
# agent-context extension was never installed.
1598+
ext_cfg_path = project_root / _AGENT_CTX_EXT_CONFIG
1599+
if ext_cfg_path.exists():
1600+
_update_agent_context_config_file(
1601+
project_root, "", preserve_markers=True
1602+
)
16001603
elif has_legacy_context_keys:
16011604
save_init_options(project_root, opts)
16021605

src/specify_cli/agents.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -376,17 +376,11 @@ def resolve_skill_placeholders(
376376

377377
# Resolve __CONTEXT_FILE__ from the agent-context extension config.
378378
# Fall back to init-options.json for projects that haven't migrated.
379-
context_file = ""
380-
try:
381-
# Local import: _load_agent_context_config lives in __init__.py
382-
# which imports agents.py, so a top-level import would be circular.
383-
from . import _load_agent_context_config
384-
ac_cfg = _load_agent_context_config(project_root)
385-
context_file = ac_cfg.get("context_file") or ""
386-
except ImportError:
387-
# Best-effort read: if the helper cannot be imported (e.g. during
388-
# circular import setup), fall back to init-options.json below.
389-
context_file = ""
379+
# Local import: _load_agent_context_config lives in __init__.py which
380+
# imports agents.py, so a top-level import would be circular.
381+
from . import _load_agent_context_config
382+
ac_cfg = _load_agent_context_config(project_root)
383+
context_file = ac_cfg.get("context_file") or ""
390384
if not context_file:
391385
context_file = init_opts.get("context_file") or ""
392386
body = body.replace("__CONTEXT_FILE__", context_file)

0 commit comments

Comments
 (0)