Skip to content

fix: find plans in nested spec directories#3405

Open
marcelsafin wants to merge 2 commits into
github:mainfrom
marcelsafin:fix/3024-nested-specs-plan
Open

fix: find plans in nested spec directories#3405
marcelsafin wants to merge 2 commits into
github:mainfrom
marcelsafin:fix/3024-nested-specs-plan

Conversation

@marcelsafin

Copy link
Copy Markdown
Contributor

Description

Fixes #3024

The agent-context extension's plan auto-discovery (mtime fallback) globbed one level only: specs/*/plan.md. Repos that scope specs via SPECIFY_FEATURE_DIRECTORY put plans at specs/<scope>/<feature>/plan.md, so the glob matched nothing and the SPECKIT block silently refreshed without a plan path.

Both script variants now recurse: the bash variant's embedded Python uses specs.glob("**/plan.md") and the PowerShell variant uses Get-ChildItem -Recurse -File -Filter plan.md. Most-recently-modified match still wins, and the feature.json path (which already handles nested directories) stays untouched. The command doc's one-level wording is updated.

Testing

  • Tested locally with uv run specify --help
  • Ran existing tests with uv sync && uv run pytest (3810 passed)
  • Tested with a sample project (if applicable)

New TestPlanDiscovery tests run both script variants against a project with an older flat plan and a newer nested plan, and assert the nested one lands in AGENTS.md (also proving mtime ordering across depths).

AI Disclosure

  • I did not use AI assistance for this contribution
  • I did use AI assistance (describe below)

Written with GitHub Copilot CLI; I reviewed the diff and test results.

The agent-context mtime fallback used a one-level specs/*/plan.md
glob, so scoped layouts (specs/<scope>/<feature>/plan.md via
SPECIFY_FEATURE_DIRECTORY) never matched and the SPECKIT block was
written without a plan path. Recurse in both script variants and
update the command doc wording.

Fixes github#3024

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@marcelsafin marcelsafin requested a review from mnriem as a code owner July 8, 2026 08:42
Copilot AI review requested due to automatic review settings July 8, 2026 08:42

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 fixes agent-context extension plan auto-discovery for repositories that organize specs in nested directories (e.g. specs/<scope>/<feature>/plan.md) by making the mtime-based fallback search recursive in both Bash and PowerShell variants.

Changes:

  • Update Bash script fallback from a one-level glob to recursive **/plan.md discovery.
  • Update PowerShell script fallback to recursively find plan.md under specs/ and select the most recently modified.
  • Add tests covering nested plan discovery for both script variants and update command documentation wording.

Reviewed changes

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

File Description
tests/extensions/test_extension_agent_context.py Adds regression tests ensuring nested specs/**/plan.md is discovered via the mtime fallback.
extensions/agent-context/scripts/powershell/update-agent-context.ps1 Switches fallback plan discovery to recursive Get-ChildItem -Recurse -File -Filter plan.md.
extensions/agent-context/scripts/bash/update-agent-context.sh Switches fallback plan discovery to recursive specs.glob("**/plan.md").
extensions/agent-context/commands/speckit.agent-context.update.md Updates docs to describe any-depth plan auto-detection behavior.

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

Comment on lines 310 to 314
plans = sorted(
specs.glob("*/plan.md"),
specs.glob("**/plan.md"),
key=lambda p: p.stat().st_mtime,
reverse=True,
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Switched to max(..., default=None), same behavior without sorting the full list.

- **PowerShell**: `.specify/extensions/agent-context/scripts/powershell/update-agent-context.ps1 [plan_path]`

When `plan_path` is omitted, the script auto-detects the most recently modified `specs/*/plan.md`.
When `plan_path` is omitted, the script auto-detects the most recently modified `specs/**/plan.md` (any depth, so scoped layouts like `specs/<scope>/<feature>/plan.md` are found).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Missed that one, updated the Behavior section to the any-depth wording.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 8, 2026 08:50

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 4 out of 4 changed files in this pull request and generated no new comments.

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.

Review details

  • Files reviewed: 4/4 changed files
  • Comments generated: 0 new
  • Review effort level: Low

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]: agent-context extension ignores scoped/nested spec directories (SPECIFY_FEATURE_DIRECTORY), so plan auto-discovery finds nothing

3 participants