Skip to content

Restore citation metadata for XML prompts#208

Merged
bmdavis419 merged 6 commits intomainfrom
restore-citation-metadata
Mar 5, 2026
Merged

Restore citation metadata for XML prompts#208
bmdavis419 merged 6 commits intomainfrom
restore-citation-metadata

Conversation

@bmdavis419
Copy link
Collaborator

@bmdavis419 bmdavis419 commented Mar 4, 2026

Greptile Summary

This PR refactors the agent instruction format from plain text lines to structured XML, restoring citation metadata for XML-aware prompts. It also introduces a richer BASE_PROMPT constant in loop.ts with explicit persona, tool-calling, and output-contract sections.

  • service.ts: createCollectionInstructionBlock now outputs XML (<resource>, <repo_url>, <github_blob_prefix>, <focus_paths>, etc.) using new escapeXml, xmlLine, and xmlPathBlock helpers; a new createCollectionInstructions wrapper wraps all resources in <available_resources>.
  • loop.ts: Old inline prompt string replaced by a BASE_PROMPT constant; buildSystemPrompt now simply concatenates BASE_PROMPT and agentInstructions.
  • service.test.ts: Test helpers made more flexible; two new tests verify git and npm XML citation metadata fields end-to-end.
  • Convex generated files (api.d.ts, server.d.ts, api.js, dataModel.d.ts, server.js): Formatting-only changes (double → single quotes, 2-space → tab indent).
  • Version bumped from 2.0.32.0.4 in CLI, server packages, and bun.lock; @typescript/native-preview dev dependency updated.

Confidence Score: 4/5

  • Safe to merge; the format change is well-tested and intentional, with two minor style nits around the npm citation rule.
  • The core logic change (plain-text → XML instructions) is covered by new unit tests and doesn't touch any data model or API contracts. The two flagged issues are style-level concerns in LLM instruction text, not functional regressions. Generated Convex files are formatting-only.
  • apps/server/src/collections/service.ts — review the npm citation_rule string for the XML-escaped <file> placeholder and the version-missing fallback text.

Important Files Changed

Filename Overview
apps/server/src/collections/service.ts Core change: refactors agentInstructions output from plain text to XML format using new escapeXml helper and structured xmlLine/xmlPathBlock utilities. Two minor issues: the <file> placeholder in the npm citation rule gets XML-escaped to &lt;file&gt;, and the fallback text when npm version metadata is missing produces a confusing LLM instruction.
apps/server/src/collections/service.test.ts Test helpers refactored to be more flexible; two new tests added for git and npm citation metadata in agent instructions. Coverage looks thorough for the new XML format.
apps/server/src/agent/loop.ts Adds a new BASE_PROMPT constant with detailed XML-structured system prompt instructions (persona, tool-calling rules, output contract) and simplifies buildSystemPrompt to concatenate BASE_PROMPT with agentInstructions.

Last reviewed commit: dd7275a

@vercel
Copy link

vercel bot commented Mar 4, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
better-context Ready Ready Preview, Comment Mar 5, 2026 8:34pm

Request Review

Copy link
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

- Emotional register: direct, calm, and concise
- Formatting: bulleted/numbered lists are good + codeblocks
- Length: be through with your response, don't let it get too long though
- Default follow-through: don't ask permission to do the research, just do it and answer the question. ask for clarifications + suggest good follow up if needed
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: "through" should be "thorough"

"be through with your response" is grammatically incorrect — it should be "be thorough with your response" (meaning detailed/complete).

Suggested change
- Default follow-through: don't ask permission to do the research, just do it and answer the question. ask for clarifications + suggest good follow up if needed
- Length: be thorough with your response, don't let it get too long though
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/server/src/agent/loop.ts
Line: 69

Comment:
Typo: "through" should be "thorough"

"be through with your response" is grammatically incorrect — it should be "be thorough with your response" (meaning detailed/complete).

```suggestion
- Length: be thorough with your response, don't let it get too long though
```

How can I resolve this? If you propose a fix, please make it concise.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

</dig_deeper_nudge>

<output_contract>
- Return a through answer to the user's question with real code examples
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: "through" should be "thorough"

Same issue as above — "Return a through answer" should be "Return a thorough answer".

Suggested change
- Return a through answer to the user's question with real code examples
- Return a thorough answer to the user's question with real code examples
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/server/src/agent/loop.ts
Line: 99

Comment:
Typo: "through" should be "thorough"

Same issue as above — "Return a through answer" should be "Return a thorough answer".

```suggestion
- Return a thorough answer to the user's question with real code examples
```

How can I resolve this? If you propose a fix, please make it concise.

- Emit `<special_notes>` only when resource instructions are provided
- Reuse derived repo and npm URL prefixes when building citation metadata
- Update collection service tests for special_notes presence and absence
@bmdavis419 bmdavis419 merged commit 43edeac into main Mar 5, 2026
4 of 7 checks passed
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