Skip to content

Malformed frontmatter in ONE agent file aborts the entire extension load — pi won't start; should skip the file and warn #212

Description

@daromaj

Summary

A single malformed agent file (bad YAML in its frontmatter) aborts the whole extension load, which kills pi entirely (exit 1 before the TUI/prompt starts). The error message does not identify the offending file.

Environment

  • pi: 0.84.1
  • pi-subagents: 0.14.3

Repro

Drop an agent file with invalid YAML frontmatter into any discovered agent dir, e.g. <cwd>/.pi/agents/feature-implementer.md with an unquoted multi-line description: containing user: "..." / assistant: "..." blocks (colon+space inside a plain scalar):

---
name: feature-implementer
description: Use this agent when the user requests implementation of a new feature
user: "example block inside the description"
---

Run pi (TUI or pi -p):

Error: Failed to load extension ".../pi-subagents/src/index.ts": Failed to load extension: Nested mappings are not allowed in compact mappings at line 2, column 14:
description: Use this agent when the user requests implementation of a new feat…

Result: pi does not start at all. (Note: Claude Code tolerates this frontmatter, pi-subagents does not — cross-tool agent files like .claude/agents/*.md shared via symlink are a realistic source.)

Root cause (in code)

src/custom-agents.ts wraps only readFileSync in try/catch (lines 50-52); parseFrontmatter at line 56 is outside any guard, so a parse error propagates up and fails the whole extension load.

Suggested fix

Fail per-file, not per-batch:

  1. Wrap parseFrontmatter in try/catch (same as readFileSync).
  2. On error: skip the file, log a warning naming the full file path and the underlying YAML error (and ideally the offending frontmatter key).
  3. Continue loading the remaining agents.
  4. Even when aborting is kept as an option, include the file path in the error — line 2, column 14 without a filename is unactionable when agents are discovered from multiple directories (<cwd>/.pi/agents/, <cwd>/.agents/agents/, ~/.pi/agent/agents/, skills).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions