Files
cleveragents-core/scripts/update_context_policy.py
T
HAL9000 91d497ca03
CI / load-versions (pull_request) Successful in 8s
CI / push-validation (pull_request) Successful in 9s
CI / build (pull_request) Successful in 17s
CI / helm (pull_request) Successful in 18s
CI / lint (pull_request) Successful in 20s
CI / quality (pull_request) Successful in 20s
CI / typecheck (pull_request) Successful in 47s
CI / security (pull_request) Successful in 1m20s
CI / unit_tests (pull_request) Successful in 5m57s
CI / docker (pull_request) Successful in 2m17s
CI / integration_tests (pull_request) Successful in 8m51s
CI / coverage (pull_request) Successful in 11m41s
CI / status-check (pull_request) Successful in 1s
fix(context-policy): resolve AmbiguousStep conflict and fix ruff formatting
Rename step decorators in context_policy_strategy_config_steps.py from
'the strategy should be "{strategy}"' to 'the policy strategy should be
"{strategy}"' (and likewise for the None variant) to avoid collision with
the identically-patterned step already registered in
plan_merge_strategy_steps.py. Update the feature file to match.

Also apply ruff format to the three files flagged by CI lint gate:
- features/steps/context_policy_strategy_config_steps.py
- scripts/update_context_policy.py
- src/cleveragents/domain/models/core/context_policy.py

ISSUES CLOSED: #7572
2026-06-19 00:18:05 -04:00

120 lines
3.9 KiB
Python

#!/usr/bin/env python3
"""Update context_policy.py with strategy configuration support."""
import sys
from pathlib import Path
# Read the file
policy_file = Path("src/cleveragents/domain/models/core/context_policy.py")
content = policy_file.read_text()
# Update the imports to include Any
content = content.replace(
"from typing import TYPE_CHECKING", "from typing import TYPE_CHECKING, Any"
)
# Add VALID_STRATEGIES constant after VALID_PHASES
old_phases = (
"VALID_PHASES: frozenset[str] = frozenset("
'{"default", "strategize", "execute", "apply"})'
)
new_phases = (
"VALID_PHASES: frozenset[str] = frozenset("
'{"default", "strategize", "execute", "apply"})\n\n'
"VALID_STRATEGIES: frozenset[str] = frozenset({\n"
' "basic",\n'
' "semantic",\n'
' "relevance_scoring",\n'
' "adaptive",\n'
' "fusion",\n'
"})"
)
content = content.replace(old_phases, new_phases)
# Update the docstring for ProjectContextPolicy to mention strategy
old_docstring = (
"class ProjectContextPolicy(BaseModel):\n"
' """Controls what context is available during each ACMS phase.\n'
"\n"
" Uses view inheritance: ``default`` → ``strategize`` →\n"
" ``execute`` → ``apply``. Each phase can override or inherit\n"
" from its parent.\n"
"\n"
" An empty ``ProjectContextPolicy()`` defaults to including\n"
" everything (the ``default_view`` has empty include lists which\n"
' means "all").\n'
' """'
)
new_docstring = (
"class ProjectContextPolicy(BaseModel):\n"
' """Controls what context is available during each ACMS phase.\n'
"\n"
" Uses view inheritance: ``default`` → ``strategize`` →\n"
" ``execute`` → ``apply``. Each phase can override or inherit\n"
" from its parent.\n"
"\n"
" An empty ``ProjectContextPolicy()`` defaults to including\n"
" everything (the ``default_view`` has empty include lists which\n"
' means "all").\n'
"\n"
" Optionally specifies a context assembly strategy and its\n"
" configuration parameters.\n"
' """'
)
content = content.replace(old_docstring, new_docstring)
# Add strategy and strategy_config fields before the resolve_view method
old_fields = (
" apply_view: ContextView | None = Field(\n"
" default=None,\n"
' description=("Overrides for Apply (inherits from execute if None)"),\n'
" )\n"
"\n"
" def resolve_view(self, phase: str) -> ContextView:"
)
error_msg = "f\"Invalid strategy '{v}': must be one of {sorted(VALID_STRATEGIES)}\""
new_fields = (
" apply_view: ContextView | None = Field(\n"
" default=None,\n"
' description=("Overrides for Apply (inherits from execute if None)"),\n'
" )\n"
" strategy: str | None = Field(\n"
" default=None,\n"
" description=(\n"
' "Context assembly strategy name. "\n'
' "Valid values: basic, semantic, relevance_scoring, adaptive, fusion"\n'
" ),\n"
" )\n"
" strategy_config: dict[str, Any] | None = Field(\n"
" default=None,\n"
' description="Strategy-specific configuration parameters",\n'
" )\n"
"\n"
' @field_validator("strategy")\n'
" @classmethod\n"
" def _validate_strategy(\n"
" cls: type[ProjectContextPolicy],\n"
" v: str | None,\n"
" ) -> str | None:\n"
' """Validate that strategy name is in the list of valid strategies."""\n'
" if v is not None and v not in VALID_STRATEGIES:\n"
" raise ValueError(\n"
" " + error_msg + "\n"
" )\n"
" return v\n"
"\n"
" def resolve_view(self, phase: str) -> ContextView:"
)
content = content.replace(old_fields, new_fields)
# Write the updated content
policy_file.write_text(content)
print("Updated context_policy.py successfully")
sys.exit(0)