Skip to content

fix(pi-cursor-agent): Parse context files from Pi 0.85+ project_context format - #34

Open
david-torres wants to merge 1 commit into
sudosubin:mainfrom
david-torres:fix/pi-cursor-agent-project-context-format
Open

david-torres wants to merge 1 commit into
sudosubin:mainfrom
david-torres:fix/pi-cursor-agent-project-context-format

Conversation

@david-torres

Copy link
Copy Markdown

Problem

Pi 0.85 changed how context files (AGENTS.md / CLAUDE.md) are embedded in the system prompt. The legacy format:

# Project Context

Project-specific instructions and guidelines:

## /abs/path/AGENTS.md
...

was replaced by XML blocks (core/system-prompt.js in pi 0.85.1):

<project_context>

Project-specific instructions and guidelines:

<project_instructions path="/abs/path/AGENTS.md">
...
</project_instructions>

</project_context>

The bridge parser (src/bridge/pi-context/parser.ts) only recognizes the legacy # Project Context heading, so context file extraction now returns nothing. The failure is silent and worse than a no-op: the <available_skills> marker survived the format change, so skills still extract, hasExtracted stays true, and cleanedPrompt strips everything except the preserved metadata lines — the context files are dropped entirely rather than passed through in the prompt. The feature added in #12 (for #11) effectively regressed to 'AGENTS.md is never delivered' for anyone on current Pi.

Fix

Parse the new XML format first and fall back to the legacy heading format for older Pi versions. Path and content trimming and the empty-check match the legacy behavior. cleanedPrompt handling is unchanged and correctly strips the XML block once extraction succeeds (covered by a new test).

Tests

  • extracts context files from Pi 0.85+ XML format
  • XML format preserves markdown headings inside context file content — content containing # Project Context / ## /not/a/file lines stays intact (the legacy splitter would have mangled it)
  • cleanedPrompt strips XML-format context block

All existing legacy-format tests unchanged and passing (37/37), tsc and biome check clean. Also verified manually against the exact prompt buildSystemPrompt in pi 0.85.1 produces for a real repo with global + project AGENTS.md: both files extract with byte-identical content.

Longer term it may be worth asking Pi for structured access to context files at the provider boundary instead of re-parsing the rendered prompt — happy to open a follow-up issue if useful.

…xt format

Pi 0.85 changed how context files (AGENTS.md / CLAUDE.md) are embedded in
the system prompt: the legacy '# Project Context' heading with '## /abs/path'
sections was replaced by <project_context>/<project_instructions path="...">
XML blocks (see core/system-prompt.js in pi 0.85.1).

The bridge parser only knew the legacy format, so context file extraction
returned nothing. Because skills still extracted successfully, hasExtracted
stayed true and cleanedPrompt discarded the rest of the prompt — silently
dropping every AGENTS.md instead of injecting them as cursor rules (sudosubin#11, sudosubin#12).

Parse the new XML format first and fall back to the legacy heading format for
older Pi versions.
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.

1 participant