Skip to content

fix: normalize CRLF/CR line endings in all file readers#1

Open
ClaytonHunt wants to merge 1 commit into
disler:mainfrom
ClaytonHunt:fix/normalize-line-endings
Open

fix: normalize CRLF/CR line endings in all file readers#1
ClaytonHunt wants to merge 1 commit into
disler:mainfrom
ClaytonHunt:fix/normalize-line-endings

Conversation

@ClaytonHunt
Copy link
Copy Markdown

Problem

All six extensions that read .md agent files or YAML configs use regex patterns like /^---\n…\n---\n/ and .split("\n") to parse frontmatter and config. On Windows, files often have CRLF line endings — these patterns silently fail, so agents don't load, teams don't activate, and rules don't apply, with no error message to indicate why.

Fix

Add .replace(/\r\n/g, "\n").replace(/\r/g, "\n") immediately after every readFileSync call, before any parsing occurs. This is a no-op for files that already use LF and only activates when CRLF or CR is present.

Files changed

File Read site
agent-chain.ts parseAgentFile(), agent-chain.yaml
agent-team.ts parseAgentFile(), teams.yaml
cross-agent.ts scanCommands(), scanAgents()
damage-control.ts damage-control-rules.yaml
pi-pi.ts before_agent_startpi-orchestrator.md
system-select.ts scanAgents()

10 one-liner changes across 6 files. Completely non-breaking for all existing LF users.

Extensions that read .md agent files, YAML configs, and the
pi-orchestrator prompt use regex patterns and .split('\n') that
silently fail when files contain Windows CRLF or legacy Mac CR
line endings.

Add .replace(/\r\n/g, '\n').replace(/\r/g, '\n') immediately
after every readFileSync call, before any parsing happens.

Files affected and what they read:
- agent-chain.ts  : parseAgentFile() .md files, agent-chain.yaml
- agent-team.ts   : parseAgentFile() .md files, teams.yaml
- cross-agent.ts  : scanCommands() .md files, scanAgents() .md files
- damage-control.ts : damage-control-rules.yaml
- pi-pi.ts        : before_agent_start pi-orchestrator.md
- system-select.ts  : scanAgents() .md files

Fixes silent breakage for Windows users where agents/teams/rules
fail to load without any error message.
Copilot AI review requested due to automatic review settings February 23, 2026 16:57
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Normalizes Windows CRLF/legacy CR line endings to LF immediately after reading agent/config files so existing frontmatter regexes and split("\n") parsing behave consistently across platforms (especially Windows).

Changes:

  • Normalize line endings (\r\n/\r) to \n after readFileSync in each extension that parses agent markdown or YAML.
  • Apply the normalization at all relevant read sites (agent markdown scans/parsers, and YAML config reads).

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
extensions/system-select.ts Normalizes agent .md file contents before frontmatter parsing during directory scan.
extensions/pi-pi.ts Normalizes expert agent .md files and pi-orchestrator.md before frontmatter/template parsing.
extensions/damage-control.ts Normalizes .pi/damage-control-rules.yaml content prior to YAML parsing.
extensions/cross-agent.ts Normalizes discovered command/agent .md content before frontmatter parsing.
extensions/agent-team.ts Normalizes agent .md files and teams.yaml prior to frontmatter/teams parsing.
extensions/agent-chain.ts Normalizes agent .md files and agent-chain.yaml prior to frontmatter/chain parsing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

jetnet pushed a commit to jetnet/pi-coms that referenced this pull request May 23, 2026
- Add .replace(/\r\n/g, '\n').replace(/\r/g, '\n') to readFileSync calls
  in cross-agent.ts, system-select.ts, damage-control.ts (PR disler#1)
- Add ⚠️ LIMITATION docstring to damage-control.ts documenting that
  subagent processes are not protected unless the extension is forwarded
  (Issue disler#24)
jetnet pushed a commit to jetnet/pi-coms that referenced this pull request May 23, 2026
agent-team.ts, agent-chain.ts, pi-pi.ts, subagent-widget.ts:

- Deduplicate parseAgentFile() → use shared agent-loader (SEC-001, PR disler#3)
- Clamp renderCard width to prevent RangeError: Invalid count -1
  on narrow terminals (Issue disler#17, PR disler#20)
- Use process.execPath + findPiCli() for snap-safe subprocess
  spawning (PR disler#13)
- Forward damage-control.ts extension to subagent processes when
  present, falling back to --no-extensions (Issue disler#24)
- Normalize CRLF line endings in all readFileSync calls (PR disler#1)
- Wrap 'No experts found' message with truncateToWidth() (PR disler#20)
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.

3 participants