Skip to content

fix: derive plan path from feature.json in update-agent-context#3069

Open
amirreza225 wants to merge 20 commits into
github:mainfrom
amirreza225:fix/3067-feature-json-plan-path
Open

fix: derive plan path from feature.json in update-agent-context#3069
amirreza225 wants to merge 20 commits into
github:mainfrom
amirreza225:fix/3067-feature-json-plan-path

Conversation

@amirreza225

Copy link
Copy Markdown

Summary

  • update-agent-context.sh and update-agent-context.ps1 now prefer .specify/feature.json (written by /speckit-specify) over the mtime heuristic when no explicit plan_path argument is given
  • Falls back to most-recently-modified specs/*/plan.md only when feature.json is absent or the derived plan.md does not exist yet (e.g. /speckit-plan hasn't run yet)
  • Handles absolute feature_directory values in both scripts, normalizing to project-relative paths for the context file output
  • PowerShell implementation is PS 5.1-compatible: nested Join-Path, IsPathRooted guard (Unix Join-Path does not treat absolute ChildPaths as "wins"), and manual prefix-strip instead of GetRelativePath

Fixes #3067

AI disclosure

This PR was written with AI assistance (Claude Code). All changes were reviewed, tested, and understood by me before submission.

Manual test results

Agent: Claude Code | OS/Shell: macOS/zsh

Command tested Notes
/speckit.specify/speckit.plan CLAUDE.md references the correct active feature's plan.md
Multi-spec repo with stale plan touched after specify CLAUDE.md still points to active feature, not the stale one

Test plan

  • uv run pytest tests/extensions/test_update_agent_context_feature_json.py — 4 new bash tests pass (2 PS skipped, no pwsh on CI)
  • uv run pytest tests/test_agent_config_consistency.py tests/extensions/test_extension_agent_context.py — all 62 existing tests pass

Copilot AI review requested due to automatic review settings June 19, 2026 12:47
@amirreza225 amirreza225 requested a review from mnriem as a code owner June 19, 2026 12:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the agent-context extension’s context refresh scripts so that, when no explicit plan_path argument is provided, they derive the active plan.md from .specify/feature.json (written by /speckit-specify) and only fall back to the “most recently modified specs/*/plan.md” heuristic when that source is unavailable or not yet present. It also adds tests to validate the new feature.json-first behavior.

Changes:

  • Bash: Prefer .specify/feature.json to resolve the active plan.md, with mtime fallback retained.
  • PowerShell: Implement the same “feature.json-first, mtime-second” selection logic and normalize feature paths.
  • Tests: Add coverage ensuring feature.json overrides the mtime heuristic (bash + PowerShell where available).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
extensions/agent-context/scripts/bash/update-agent-context.sh Uses .specify/feature.json to select the active plan when plan_path isn’t provided; retains mtime fallback.
extensions/agent-context/scripts/powershell/update-agent-context.ps1 Mirrors bash behavior in PowerShell, including absolute-path normalization and mtime fallback.
tests/extensions/test_update_agent_context_feature_json.py Adds tests validating feature.json-first selection and stale-plan avoidance.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread extensions/agent-context/scripts/bash/update-agent-context.sh
Comment thread tests/extensions/test_update_agent_context_feature_json.py

@mnriem mnriem left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address Copilot feedback

@amirreza225

Copy link
Copy Markdown
Author

All three Copilot comments have been addressed in commit 80600a2:

  1. GetRelativePath not available in PS 5.1 — replaced with a manual prefix-strip using StartsWith/Substring in both the feature.json path and the mtime fallback sections of update-agent-context.ps1.

  2. open() missing explicit encoding — added encoding="utf-8" to the json.load(open(...)) call in the feature.json snippet in update-agent-context.sh.

  3. No tests for absolute feature_directory — added two new bash tests:

    • test_bash_absolute_feature_dir_under_project_root: absolute path under $PROJECT_ROOT → context file contains project-relative path (not machine-specific absolute)
    • test_bash_absolute_feature_dir_outside_project_root: absolute path outside $PROJECT_ROOT → absolute path preserved as-is

All 70 tests pass locally.

@amirreza225

Copy link
Copy Markdown
Author

Please address Copilot feedback

Done

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

Comment thread tests/extensions/test_update_agent_context_feature_json.py Outdated
Comment thread tests/extensions/test_update_agent_context_feature_json.py Outdated
Comment thread tests/extensions/test_update_agent_context_feature_json.py Outdated
Comment thread tests/extensions/test_update_agent_context_feature_json.py Outdated
Comment thread tests/extensions/test_update_agent_context_feature_json.py Outdated
Copilot AI review requested due to automatic review settings June 19, 2026 18:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread tests/extensions/test_update_agent_context_feature_json.py Outdated
Comment thread tests/extensions/test_update_agent_context_feature_json.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot's findings

  • Files reviewed: 3/3 changed files
  • Comments generated: 2

Comment thread extensions/agent-context/scripts/bash/update-agent-context.sh
Copilot AI review requested due to automatic review settings June 19, 2026 18:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

@mnriem mnriem left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address Copilot feedback

Copilot AI review requested due to automatic review settings June 19, 2026 18:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

@mnriem

mnriem commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

Please address Copilot feedback

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

Comment thread extensions/agent-context/scripts/bash/update-agent-context.sh
Comment thread extensions/agent-context/scripts/bash/update-agent-context.sh
Comment thread extensions/agent-context/scripts/bash/update-agent-context.sh Outdated
Comment thread tests/extensions/test_update_agent_context_feature_json.py
Comment thread tests/extensions/test_update_agent_context_feature_json.py Outdated
Comment thread tests/extensions/test_update_agent_context_feature_json.py
Copilot AI review requested due to automatic review settings June 19, 2026 19:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread tests/extensions/test_update_agent_context_feature_json.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot's findings

  • Files reviewed: 3/3 changed files
  • Comments generated: 2

Comment on lines +88 to +94
result = subprocess.run(
["bash", str(UPDATE_AGENT_CTX_SH)],
cwd=tmp_path,
capture_output=True,
text=True,
check=False,
)
Comment on lines +241 to +255
@@ -217,8 +250,9 @@ plans = sorted(
print(plans[0] if plans else "")
PY
)"
if [[ -n "$_plan_abs" ]]; then
PLAN_PATH="${_plan_abs#"$PROJECT_ROOT/"}"
if [[ -n "$_plan_abs" ]]; then
PLAN_PATH="${_plan_abs#"$PROJECT_ROOT/"}"
fi

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment on lines +13 to +36
from tests.extensions.test_extension_agent_context import (
BASH,
POWERSHELL,
_bash_posix_path,
_install_agent_context_config,
_run_bash_agent_context_script,
_run_powershell_agent_context_script,
)


def _setup_project(root: Path, context_file: str = "CLAUDE.md") -> None:
"""Write agent-context extension config as JSON.

JSON is valid YAML so bash+PyYAML can parse it, and PowerShell's built-in
ConvertFrom-Json can parse it without needing powershell-yaml or Python.
"""
_install_agent_context_config(
root,
context_file=context_file,
context_markers={
"start": "<!-- SPECKIT START -->",
"end": "<!-- SPECKIT END -->",
},
)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@amirreza225

Copy link
Copy Markdown
Author

@mnriem Hi can you run the checks?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot's findings

  • Files reviewed: 3/3 changed files
  • Comments generated: 2

Comment thread extensions/agent-context/scripts/bash/update-agent-context.sh
Comment thread tests/extensions/test_update_agent_context_feature_json.py

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment on lines +223 to +229
# feature_directory may be relative or absolute (absolute paths outside PROJECT_ROOT
# are preserved as-is by _persist_feature_json in common.sh).
if [[ "$_feature_dir" == /* ]]; then
_candidate="$_feature_dir/plan.md"
else
_candidate="$PROJECT_ROOT/$_feature_dir/plan.md"
fi

@mnriem mnriem left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address Copilot feedback and fix test & lint errors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: update-agent-context.sh:123-137

3 participants