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:
- Wrap
parseFrontmatter in try/catch (same as readFileSync).
- On error: skip the file, log a warning naming the full file path and the underlying YAML error (and ideally the offending frontmatter key).
- Continue loading the remaining agents.
- 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).
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
Repro
Drop an agent file with invalid YAML frontmatter into any discovered agent dir, e.g.
<cwd>/.pi/agents/feature-implementer.mdwith an unquoted multi-linedescription:containinguser: "..."/assistant: "..."blocks (colon+space inside a plain scalar):Run
pi(TUI orpi -p):Result: pi does not start at all. (Note: Claude Code tolerates this frontmatter, pi-subagents does not — cross-tool agent files like
.claude/agents/*.mdshared via symlink are a realistic source.)Root cause (in code)
src/custom-agents.tswraps onlyreadFileSyncin try/catch (lines 50-52);parseFrontmatterat 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:
parseFrontmatterin try/catch (same asreadFileSync).line 2, column 14without a filename is unactionable when agents are discovered from multiple directories (<cwd>/.pi/agents/,<cwd>/.agents/agents/,~/.pi/agent/agents/, skills).