-
Notifications
You must be signed in to change notification settings - Fork 49
Description
Describe the bug
apm compile fails with Distributed compilation failed: 'ts,js,mts,mjs' when an instruction uses an applyTo pattern containing multiple brace groups, e.g. **/*.{test,spec}.{ts,js,mts,mjs}.
The root cause is in _expand_glob_pattern() at src/apm_cli/compilation/context_optimizer.py (line ~755). The method:
- Finds the first brace group
{test,spec}via regex - Replaces it with
{}, producing**/*.{}.{ts,js,mts,mjs} - Calls Python's
str.format()on the result — which interprets the second brace group{ts,js,mts,mjs}as a format placeholder - This raises
KeyError: 'ts,js,mts,mjs'
The exception propagates up to compile_distributed() which catches it generically, producing the unhelpful error message.
To Reproduce
- Create an instruction file with
applyTo: "**/*.{test,spec}.{ts,js,mts,mjs}"in its frontmatter - Run
apm compile --verbose - Compilation fails with:
Compilation failed with 1 errors: ❌ Distributed compilation failed: 'ts,js,mts,mjs'
Expected behavior
The pattern should be fully expanded into all combinations:
**/*.test.ts,**/*.test.js,**/*.test.mts,**/*.test.mjs**/*.spec.ts,**/*.spec.js,**/*.spec.mts,**/*.spec.mjs
Environment (please complete the following information):
- OS: macOS
- Python Version: 3.13.11
- APM Version: 0.7.4
- VSCode Version: N/A (CLI only)
Logs
⚙️ Starting context compilation...
Compiling for AGENTS.md (VSCode/Copilot) - detected .github/ folder
Verbose mode: showing source attribution and optimizer analysis
⏱️ 📊 Project Analysis: 7.7ms
Compilation failed with 1 errors:
❌ Distributed compilation failed: 'ts,js,mts,mjs'
Additional context
Single brace group patterns like **/*.{ts,tsx} are widely used across the APM ecosystem — in APM's own templates (hello-world), official docs (examples.md), and tests. The brace expansion logic in _expand_glob_pattern handles single groups correctly but fails on multiple groups. Multi-brace patterns like **/*.{test,spec}.{ts,js,mts,mjs} are standard glob syntax (supported by VS Code's files.include/files.exclude, bash, zsh, etc.) and should be expected in applyTo values.
The fix should recursively expand all brace groups in a pattern, not just the first one. Additionally, str.format() should be avoided since remaining brace groups in the string will be misinterpreted as format placeholders — string concatenation or str.replace() (with maxcount=1) would be safer.