// engine/universal-rules/rules/planu-dogfood-bugs.ts — SPEC-779
// Universal rule: Planu Dogfood Bugs (mandatory for all Planu-using projects)
/** Shared markdown body (same for all hosts). */
function buildBody() {
    return `# Planu Dogfood Bugs (MANDATORY — STRICT)

> Planu dogfoods itself: this repo IS Planu, and every session uses Planu MCP tools to manage Planu's own SDD lifecycle. When a bug is observed in Planu while using Planu, the bug MUST become a tracked spec **in the same turn it is observed** — not deferred to a backlog, not noted in chat, not saved for later.

## The rule

Whenever a Planu MCP tool returns wrong, stale, silent, or irrelevant output during normal use, you MUST stop and call \`mcp__planu__create_spec\` immediately with a detailed bugfix spec, then continue the original flow.

## Triggers (any of these fires the rule)

- A tool returns wrong data (e.g. \`list_specs\` shows different counts than \`status.json\`)
- A tool fails silently (no error, but expected side-effect didn't happen)
- A state file (\`planu/status.json\`, \`planu/session-context.md\`, \`data/projects/*/\`) is out of sync with reality
- A tool's output contains hallucinated or irrelevant content (e.g. \`create_spec\` suggests \`client-detection.ts\` for a release-pipeline spec)
- A tool requires manual workaround (e.g. \`update_status\` failing with \`projectPath\` and needing a separate \`list_specs\` call to fetch \`projectId\`)
- A check (\`check_readiness\`, \`validate\`) emits a blocker that is provably false given the spec content
- A timeout that produces partial state without clear error semantics
- An autopilot cascade hook is registered but not running on its trigger event

## Required spec content (no exceptions for "small" bugs)

The bugfix spec must include:

1. **Reproducer** — exact tool call, exact response observed, exact expected response
2. **Root cause hypothesis** — pointer to file path + line number in \`src/\` where the bug likely lives
3. **BDD acceptance criteria** with \`FILES:\`, \`FUNCTIONS:\`, \`TEST:\` markers per scenario
4. **Files to CREATE / MODIFY** with exact paths
5. **Implementation order** scoped at Sonnet (so a cheap implementer can execute without re-thinking)
6. **Anticipated test breaks** — which existing tests will need snapshot updates

## Tags + classification

- \`tags\`: \`["bug", "P0|P1|P2", "<subsystem>", "dogfood"]\` minimum
- \`type\`: \`bugfix\`
- \`acFormat\`: \`bdd\`
- \`feature\`: subsystem name (e.g. "Cascade Reliability", "Spec Quality Gates", "Tool Reliability")

Priority guide:
- **P0**: breaks the workflow, requires manual workaround, or causes silent data corruption
- **P1**: produces friction in the spec quality flow (false negatives, missed validations)
- **P2**: degrades output quality (irrelevant suggestions, hallucinated content)

## Anti-patterns

- "I'll note this for later" → **NO**, create the spec now
- "It's a small bug, doesn't deserve a spec" → **NO**, every dogfood bug is a spec
- "I'll create a TODO comment in the code" → **NO**, code TODOs rot
- "Let me check if there's already a spec for it" → fine, but if not, create one immediately
- Saving multiple bugs to chat as a list without filing them → **NO**, file in parallel via multiple \`create_spec\` calls in one message

## How this rule integrates with the rest of the workflow

- The bug-spec creation is non-blocking: continue the original task after filing
- If multiple bugs are observed in one session, file them in PARALLEL (\`create_spec\` calls in a single message — idempotency keys prevent duplicates on timeout)
- After filing, move the spec to \`review\` and notify the user briefly: "Bug filed as SPEC-XXX, continuing"
- The user approves bugs in batches when convenient
`;
}
export const planuDogfoodBugsRule = {
    id: 'planu-dogfood-bugs',
    name: 'Planu Dogfood Bugs',
    description: 'Mandatory rule for Planu-using projects: any observed Planu bug must become a spec immediately.',
    category: 'dogfood',
    applicableHosts: ['all'],
    defaultEnabled: true,
    buildContent: (_host) => buildBody(),
};
//# sourceMappingURL=planu-dogfood-bugs.js.map