AGENT SKILL

cl_manage-prompts

Use when adding, editing, or moving an agent prompt used by the Canary web server or an MCP initialize instruction — those instruction sources are Markdown files under apps/web-server/prompts/, never inline strings in .ts files.

License 许可
MIT
最近更新
2026-11-14
Stars
★ 4
Forks
0

01 前言 Front Matter

name
cl_manage-prompts
description
Use when adding, editing, or moving an agent prompt used by the Canary web server or an MCP initialize instruction — those instruction sources are Markdown files under apps/web-server/prompts/, never inline strings in .ts files.

03 SKILL.md 正文

<!-- GENERATED FROM .claude/skills — DO NOT EDIT. Run npm run gen:skills after editing the source skill (the build does this too). -->

Managing Canary Lab's LLM Prompts

Every prompt the Canary web server sends to a spawned agent (Claude/Codex), plus every static MCP initialize instruction source, lives as a flat file in apps/web-server/prompts/ — never as a template literal or string constant buried in a server .ts file. Contributor-only scripts such as tools/generate-changelog.mjs are outside this runtime prompt contract. MCP files use the mcp-*-instructions.md naming pattern and are loaded by mcp/instructions.ts: the text above a file's <!-- initialize-cut --> marker is the profile's initialize lead (the Claude Code CLI keeps only the first 2048 characters of a server's instructions), and the whole file is the guide that the get_workflow_guide tool returns. One home, one loader: apps/web-server/src/shared/prompts.ts.

Why prompts get their own folder

  • Ships via build, like templates. tools/prepare-assets.mjs copies the whole folder into dist/apps/web-server/prompts/ — the same mechanism templates/project/ uses. A prompt inlined in a .ts file ships fine too, but hides among logic instead of reading as a first-class asset.
  • Diffable prose. A .md prompt reviews like copy, not like code — no string-escaping noise, no +/backtick clutter for a paragraph edit.
  • One loader, one contract. All templates share the same {{placeholder}} substitution rules (see below) instead of five call sites each rolling a slightly different replace(/\{\{(\w+)\}\}/g, ...).

Adding a new prompt

  1. Write the text as apps/web-server/prompts/<name>.md. Use {{placeholder}} slots only for parts a spawned-agent caller fills at runtime; MCP initialize instructions are static files loaded as-is.
  2. If the agent must return structured output validated against a JSON schema (codex's --output-schema), add a sibling apps/web-server/prompts/<name>.schema.json (see coverage-annotate.schema.json, prd-summary.schema.json, evaluation-rewrite.schema.json). Prompts that instead ask the agent to reply in a ```json fence (parsed with extractJson/hand-rolled parsing — see scout.md, plan-features.md) don't need one.
  3. In the .ts module that builds the prompt, import from ../../../shared/prompts (adjust ../ depth to reach apps/web-server/src/shared/) and use:
    • promptPath(name) — resolve <name> to its absolute path in the packaged prompts dir. Use this for a path you need to store/pass around (e.g. a manifest field re-read later), not just render once.
    • renderPrompt(name, vars) — the one-shot case: load + substitute in one call.
    • loadPromptTemplate(path) / renderPromptTemplate(template, vars) — the two steps split apart, for callers that accept an injected raw template string for tests or that resolve the path dynamically (opts.promptPath ?? HEAL_PROMPT_TEMPLATE_PATH in auto-heal.ts).
    • Static MCP instructions are loaded once by mcp/instructions.ts, which splits each file at <!-- initialize-cut --> into INSTRUCTIONS_BY_PROFILE (the lead) and WORKFLOW_GUIDES (the whole file). mcp/instructions.test.ts pins every lead ≤ 2048 chars and requires a cut lead to name get_workflow_guide; put a rule past the cut only if the lead still tells the agent where it lives.
  4. Never fs.readFileSync a prompt file directly, and never hand-roll another {{key}} regex — that's exactly the duplication this module exists to prevent.

The {{placeholder}} contract

  • A placeholder embedded in other text (- {{failedDir}}/<slug>/foo) — the variable's string value is substituted in; a missing key is left as literal {{key}} text (an out-of-sync template degrades visibly instead of silently losing text).
  • A line that holds nothing but one placeholder is dropped entirely when that placeholder is a known key resolving to '' — this is how optional bullets/sections (e.g. heal-agent.md's {{traceExtractHint}}) disappear cleanly instead of leaving a blank line. An unknown key on its own line is still left as literal text, same as the mixed-line case.
  • Pass JSON payloads pre-stringified (JSON.stringify(x, null, 2)) as a plain string var — the loader does no JSON-awareness, it's pure text substitution.

Guardrails that must survive any heal-prompt edit

heal-agent.md is where an agent is told what it may change. The rule itself is not literal text in the template — it arrives through placeholders filled from MODE_COPY in auto-heal.ts:

Placeholder service mode (has editable repos) test mode (zero editable repos)
{{healingDirective}} "Fix service/app code, not tests." "…no editable service repos. Fix the failing Playwright tests or their helpers."
{{testSpecRule}} Don't read the spec unless the failure can't be understood without it Read the spec + helpers — they're what you fix
{{closingDirective}} Fix the root cause in service/app code Fix the spec/helpers

So a rewrite of heal-agent.md can drop the guardrail without deleting a single word of it — just by dropping a placeholder. Rules:

  • Keep {{healingDirective}}, {{testSpecRule}}, and {{closingDirective}} in any version of this template. Grep them after editing.
  • test mode is the one sanctioned "edit the test" path and it is gated on detectHealMode finding zero editable repos (defaulting to service on any read error). Never widen it, and never make the service copy softer.
  • auto-heal.test.ts asserts the service-mode directive is present and that test mode does not carry it. If your edit makes those fail, the guardrail moved — fix the guardrail, not the assertion.
  • The same rule on the external/MCP surfaces is pinned by mcp/repair-guardrail.test.ts. Full context: cl_run-evidence-invariants.

What does NOT belong in prompts/

Lives here instead Why it's a different thing
apps/web-server/src/mcp/tool-groups/ — tool description: fields MCP tool schema metadata, not text sent to steer an agent's task.
templates/project/ Scaffold files copied into a user's workspace (feature configs, sample specs) — ships via the same build step, but it's product output, not a prompt. See cl_add-sample-feature.
.codex/skills/**/SKILL.md Claude Code skill definitions for contributors working on canary-lab itself, not agent-spawn prompts.

apps/web-server/prompts/sabotage-skills/ is the one exception that still lives inside prompts/: it's meta.json + skill.md pairs the benchmark feature loads (features/benchmark/logic/runtime/skills.ts), shaped differently from the flat {{placeholder}} templates because it isn't a prompt — it's a structured skill definition bundled with the package for the same reason prompts are (ships via dist/apps/web-server/prompts/, upgrades with the package).

apps/web-server/prompts/benchmark-study/ holds real {{placeholder}} templates, but only the contributor benchmark in tools/benchmark-study renders them (renderPrompt('benchmark-study/<name>.md', …)). They keep the one prompt home, yet never ship: tools/prepare-assets.mjs skips the folder and npm run smoke:pack fails if it reaches the tarball. Put a new benchmark-only prompt there, never at the flat top level.

Common mistakes

Mistake Consequence
Inlining a new agent prompt or MCP instruction as a template literal in a .ts file Works, but breaks the one-home rule — the next contributor won't think to look in prompts/, and it silently escapes the build's asset-copy step
Hand-rolling a new {{key}} substitution regex Recreates the exact duplication this module consolidated; extend renderPromptTemplate instead if it's missing a capability
Assuming a solo-placeholder line is always droppable when empty Only true for a known key; an unrecognized placeholder is deliberately kept (verified via apps/web-server/src/shared/prompts.test.ts)
Forgetting npm run smoke:pack after adding/renaming a .md/.schema.json file prepare-assets.mjs's copy step is only proven by the tarball smoke test, same as templates/

04 同仓库更多 Skills

ferterahadi
ferterahadi/canary-lab

off-by-one

暂无简介

测试与质量Skill与智能体开发
★ 4
ferterahadi
ferterahadi/canary-lab

multi-failure-cascade

暂无简介

测试与质量Skill与智能体开发
★ 4
ferterahadi
ferterahadi/canary-lab

broken-delete-contract

暂无简介

律师与法务测试与质量Skill与智能体开发
★ 4
ferterahadi
ferterahadi/canary-lab

canary-lab

Use when the user wants Canary Lab to take a product repo end to end — "test this app", "onboard this repo", "run a flight", "evaluate what I just built" — through the flight pipeline (start_flight / get_flight / respond_flight_checkpoint over MCP). One conducted pipeline continues a configured suite or takes bare repo(s) to a green, covered, healed run and publishes a downloadable Report; Parallel setup continues as Canary-owned background work. Use a focused skill only when the user asks for that single capability without asking for a Flight or /canary-lab.

测试与质量Skill与智能体开发
★ 4
ferterahadi
ferterahadi/canary-lab

canary-lab-verify

Use when verifying a Canary Lab feature against a RUNNING target — a deployed environment ("verify checkout on staging", "run the saved verify config", "check the deployed app") or a locally booted app ("verify a running app") — through the verify MCP tools (list/get/create/update_verification_config, boot_services, execute_verification, get_verification_result). No heal loop. For run + heal use canary-lab-run; for end-to-end onboarding use canary-lab (flight).

测试与质量Skill与智能体开发
★ 4
ferterahadi
ferterahadi/canary-lab

canary-lab-run

Use when running or healing an EXISTING Canary Lab feature locally — "run <feature>", "fix the failing run", "rerun 7cvh", "drive the heal loop" — through the repair MCP tools (start_run, wait_for_heal_task, signal_run, get_heal_context, pause_run, cancel_heal, abort_run). Fix failing runs by editing app/service code, not tests. For end-to-end onboarding of a new repo use canary-lab (flight); for deployed-environment checks use canary-lab-verify.

开发工程师测试与质量Skill与智能体开发
★ 4