Skip to content

[BUG] apm compile silently drops global instructions (no applyTo) from generated AGENTS.md #1072

@ic4-y

Description

@ic4-y

Bug Description

apm compile silently omits instruction files that have no applyTo frontmatter field from the generated AGENTS.md output. The optimizer reports them as placed (rel: 100% at ./AGENTS.md), but the compiled file does not contain their content.

Environment

  • APM version: 0.8.10 and 0.11.0 (pip installed)
  • Python version: 3.13
  • OS: Linux (NixOS)

Steps to Reproduce

# 1. Create a fresh test project
mkdir -p /tmp/apm-bug/.apm/instructions
cd /tmp/apm-bug

# 2. Write minimal apm.yml
cat > apm.yml << 'EOF'
name: test-bug
version: 1.0.0
type: hybrid
target: opencode
EOF

# 3. Create a global instruction (no applyTo)
cat > .apm/instructions/global.instructions.md << 'EOF'
---
description: Global instruction without applyTo
---

This should appear in AGENTS.md.
EOF

# 4. Create a scoped instruction (has applyTo)
cat > .apm/instructions/scoped.instructions.md << 'EOF'
---
description: Scoped instruction with applyTo
applyTo: "*.md"
---

This appears in AGENTS.md for *.md files.
EOF

# 5. Compile
apm compile -t all

Expected Behavior

AGENTS.md should contain both instructions:

  • The global instruction (applied to all files)
  • The scoped instruction (applied to *.md files)

Actual Behavior

$ apm compile -t all
[*] Starting context compilation...
...
Optimizing placements...

  Pattern              Source          Co…   Placement           Metrics
  ──────────────────────────────────────────────────────────────────────
  (global)             global.instr…   1/1   ./AGENTS.md         rel: 100%
  *.md                 scoped.instr…   0/1   ./AGENTS.md         rel: 0%

Generated 1 AGENTS.md file

The optimizer says the global instruction is placed at ./AGENTS.md with rel: 100%, but the actual file only contains the scoped instruction:

$ cat AGENTS.md
# AGENTS.md
<!-- Generated by APM CLI from distributed .apm/ primitives -->
<!-- Source: local -->

## Files matching `*.md`
<!-- Source: local .apm/instructions/scoped.instructions.md -->
This appears in AGENTS.md for *.md files.

The global instruction's content is completely absent.

Additional Context

  • Adding applyTo: "**" to the global instruction makes it appear in the output — so the compiler can handle it, but only when an explicit pattern is present.
  • This affects all targets (AGENTS.md and CLAUDE.md).
  • Verified on both apm-cli 0.8.10 (nixpkgs) and 0.11.0 (pip).
  • No existing issues found for this specific behavior after searching the issue tracker.

Suspected Location

Likely in the compile/optimizer logic where instructions without an applyTo pattern are classified as (global) but then dropped during file generation. The optimizer's placement matrix includes them but the actual file writer appears to skip them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions