instructions-template.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. * The marker-fenced agent-instructions block the installer writes into each
  3. * agent's instructions file (CLAUDE.md / AGENTS.md / GEMINI.md).
  4. *
  5. * History: pre-#529 the installer wrote a full usage playbook here, which
  6. * duplicated the MCP `initialize` instructions for the main agent — so it
  7. * was removed and `mcp/server-instructions.ts` became the single source of
  8. * truth. A much smaller block returned for #704, because the MCP
  9. * instructions cannot reach two audiences that the instructions FILE does
  10. * reach:
  11. *
  12. * - **Task-tool subagents** — they receive the project instructions file
  13. * in their context but NOT the MCP initialize instructions. They hold
  14. * the codegraph MCP tools only as deferred names and rarely think to
  15. * load them: measured on a forced-delegation flow question (excalidraw,
  16. * sonnet, high effort), subagents loaded + used codegraph in ~1 of 9
  17. * runs without this block, and consistently with it — including runs
  18. * with zero Read/grep fallback.
  19. * - **Non-MCP harnesses** — agents with no MCP client at all can still
  20. * run the `codegraph explore` CLI, which prints the same output as the
  21. * MCP tool.
  22. *
  23. * Keep this block SHORT. The main agent reads it every turn on top of the
  24. * server instructions — the #529 duplication-cost argument still bounds
  25. * its size. Command names and the two surfaces, nothing more.
  26. */
  27. /** Markers used by the marker-based section write/removal. */
  28. export const CODEGRAPH_SECTION_START = '<!-- CODEGRAPH_START -->';
  29. export const CODEGRAPH_SECTION_END = '<!-- CODEGRAPH_END -->';
  30. /**
  31. * The full block, markers included, exactly as written to disk.
  32. *
  33. * The wording is deliberately CONDITIONAL ("in repositories indexed by…"):
  34. * a global install writes this into a user-scope file (~/.claude/CLAUDE.md,
  35. * ~/.codex/AGENTS.md) that applies to every project the user opens —
  36. * including unindexed ones, where an unconditional "this repository is
  37. * indexed" claim would send subagents into failing codegraph calls (the
  38. * noise the unindexed-session policy exists to prevent).
  39. */
  40. export const CODEGRAPH_INSTRUCTIONS_BLOCK = `${CODEGRAPH_SECTION_START}
  41. ## CodeGraph
  42. In repositories indexed by CodeGraph (a \`.codegraph/\` directory exists at the repo root), reach for it BEFORE grep/find or reading files when you need to understand or locate code:
  43. - **MCP tool** (when available): \`codegraph_explore\` answers most code questions in one call — the relevant symbols' verbatim source plus the call paths between them, including dynamic-dispatch hops grep can't follow. Name a file or symbol in the query to read its current line-numbered source. If it's listed but deferred, load it by name via tool search.
  44. - **Shell** (always works): \`codegraph explore "<symbol names or question>"\` prints the same output.
  45. If there is no \`.codegraph/\` directory, skip CodeGraph entirely — indexing is the user's decision.
  46. ${CODEGRAPH_SECTION_END}`;