Skip to content

Add wildcard support for file patterns in index YAML#2

Merged
hidakatsuya merged 3 commits intomainfrom
copilot/add-wildcard-support-for-prompts
Oct 19, 2025
Merged

Add wildcard support for file patterns in index YAML#2
hidakatsuya merged 3 commits intomainfrom
copilot/add-wildcard-support-for-prompts

Conversation

Copy link
Copy Markdown

Copilot AI commented Oct 7, 2025

Wildcard Support Implementation - Complete ✅

  • Explore repository structure and understand current implementation
  • Run existing tests to verify baseline
  • Design wildcard matching logic in flattenDescendants function
  • Implement wildcard expansion using filepath.Glob
  • Handle edge cases (no matches, directory creation)
  • Add test for basic wildcard pattern (e.g., *.md)
  • Add test for wildcards with nested directories
  • Add test for no matches case
  • Run all tests to verify implementation - ✅ all tests pass
  • Manual verification with example from issue - ✅ confirmed working
  • Address review feedback - removed unnecessary comment and extra whitespace
  • Updated README.md with wildcard pattern examples
  • Simplified wildcard support to only use * for matching files of the same type

Changes Made:

  1. Modified internal/install/installer.go:

    • Updated flattenIndex to accept dotfilesDir parameter for glob expansion
    • Updated flattenDescendants to detect wildcard patterns (only *)
    • Added expandWildcard function to expand glob patterns using filepath.Glob
    • When a wildcard is detected, all matching files are added as separate entries
  2. Added tests in internal/e2e/install_test.go:

    • TestInstallWildcard: Tests basic wildcard functionality with *.md pattern
    • TestInstallWildcardNoMatches: Tests behavior when no files match the pattern
  3. Updated README.md:

    • Added wildcard pattern example to Directory Structure Example
    • Added wildcard pattern usage to Example Index File
    • Included explanation of wildcard pattern support (simplified to * only)

How It Works:

Example from issue:

macOS:
  codex:
    prompts:
      "*.md": .codex/prompts

This links all .md files from dotfiles/macOS/codex/prompts/*.md to .codex/prompts/ directory.

Multiple patterns example:

config:
  scripts:
    "*.sh": bin/scripts
    "*.py": bin/scripts

This links all .sh and .py files from dotfiles/config/scripts/ to bin/scripts/.

Wildcard Support:

The feature supports only the * (asterisk) wildcard for simplicity, allowing users to group files of the same type together. This keeps the feature simple and focused on its primary use case.

Testing:

✅ All 10 tests pass:

  • 8 existing tests (no regression)
  • 2 new wildcard tests

Manual verification confirmed:

  • Multiple file patterns work correctly
  • Only matching files are linked
  • Non-matching files are ignored
  • Target directories are created automatically

All existing functionality preserved - backward compatible.

Fixes #1

Original prompt

This section details on the original issue you should resolve

<issue_title>ワイルドカードのサポート</issue_title>
<issue_description>例: ~/dotfiles/macOS.yml

macOS:
  codex:
    prompts:
      "*.md": .codex/prompts

dotfiles/macOS/codex/prompts/*.md.codex/prompts/ 配下にリンクする。 </issue_description>

<agent_instructions>必ずテストが通ることを確認すること。テスト手順などは README.md を参照。</agent_instructions>

Comments on the Issue (you are @copilot in this section)

Fixes #1

💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI changed the title [WIP] Add wildcard support for codex prompt links Add wildcard support for file patterns in index YAML Oct 7, 2025
Copilot AI requested a review from hidakatsuya October 7, 2025 16:34
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@copilot この .gitignore の設定は、この pull reqeust の変更に必要?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

いいえ、必要ありません。削除しました(commit 7cd7ec9)。

.gitignore は最初のコミットで誤ってバイナリをコミットしてしまったため追加しましたが、ワイルドカード機能自体には不要です。

// If glob fails or no matches, skip this entry
return
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Please remove the extra spaces.

}

if hasWildcard {
// Expand wildcard pattern
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I think the code is clear enough without this comment, so the comment can be removed.

@hidakatsuya
Copy link
Copy Markdown
Owner

@copilot Please fix: #2 (comment) #2 (comment)

Copy link
Copy Markdown
Author

Copilot AI commented Oct 19, 2025

@copilot Please fix: #2 (comment) #2 (comment)

Fixed in commit 2a3f8e6.

Copilot AI requested a review from hidakatsuya October 19, 2025 03:16
@hidakatsuya hidakatsuya force-pushed the copilot/add-wildcard-support-for-prompts branch from 9ef2849 to 9972957 Compare October 19, 2025 03:53
@hidakatsuya
Copy link
Copy Markdown
Owner

@copilot README.md の Directory Structure Example と Example Index File に、この PR で対応するパターンの説明も加えてください

Copy link
Copy Markdown
Author

Copilot AI commented Oct 19, 2025

@copilot README.md の Directory Structure Example と Example Index File に、この PR で対応するパターンの説明も加えてください

README.md を更新しました(commit 2f8a9d1)。

Directory Structure Example にワイルドカードパターンを使用する例として、macOS/codex/prompts/ ディレクトリに複数の .md ファイルを追加し、Example Index File にワイルドカードパターン "*.md": .codex/prompts の例を追加しました。

wildcardIndex := -1

for i, p := range paths {
if strings.ContainsAny(p, "*?[]") {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@copilot
?[] のサポートは不要です。このPRでは、シンプルに同じ種類のファイルをまとめるための機能にしたい。README.md の説明も修正して。

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

修正しました(commit 8a7c5f3)。

* のみをサポートするように変更し、?[] のサポートを削除しました。README.md の説明も更新し、シンプルに同じ種類のファイルをまとめる機能として説明しています。

@hidakatsuya hidakatsuya force-pushed the copilot/add-wildcard-support-for-prompts branch from 0302db3 to 416b46b Compare October 19, 2025 04:16
@hidakatsuya hidakatsuya marked this pull request as ready for review October 19, 2025 04:16
@hidakatsuya hidakatsuya merged commit eb5ebf9 into main Oct 19, 2025
1 check passed
@hidakatsuya hidakatsuya deleted the copilot/add-wildcard-support-for-prompts branch October 19, 2025 05:03
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.

ワイルドカードのサポート

2 participants