// engine/host-rules-templates/templates.ts — SPEC-708: Per-host rules + question directives.
// Each LLM host has its own native interactive-input mechanism. We adapt the rule
// text + the runtime directive emitted by withInteractiveQuestions() per host.
import { renderSddConstitutionRulesForHost } from '../constitution/sdd-rules-registry.js';
/** Native interactive-input mechanism for a given host (used in rule wording). */
const HOST_QUESTIONS_RULE = {
    'claude-code': 'In Claude Code: use `AskUserQuestion`. Never present questions as plain text.',
    cursor: 'In Cursor: use the Composer follow-up prompt. Never present questions as plain text.',
    codex: 'In Codex CLI: use the native interactive prompt input. Never present questions as plain text.',
    gemini: 'In Gemini CLI: use the native interactive prompt input. Never present questions as plain text.',
    universal: "Use your client's native interactive-input mechanism. Never present questions as plain text.",
};
/** Short directive emitted at the top of a tool response that includes interactiveQuestions[]. */
const HOST_DIRECTIVE_TEXT = {
    'claude-code': '⚡ INTERACTIVE — use AskUserQuestion now with interactiveQuestions from structuredContent',
    cursor: '⚡ INTERACTIVE — relay interactiveQuestions[] via the Cursor follow-up prompt',
    codex: "⚡ INTERACTIVE — relay interactiveQuestions[] via Codex's native interactive prompt",
    gemini: "⚡ INTERACTIVE — relay interactiveQuestions[] via Gemini's native interactive prompt",
    universal: "⚡ INTERACTIVE — relay interactiveQuestions[] via your client's native interactive UI",
};
/** Sentence used in the per-tool humanSummary field of structuredContent. */
const HOST_HUMAN_SUMMARY_PREFIX = {
    'claude-code': 'Use AskUserQuestion to relay the following to the user',
    cursor: 'Use the Cursor follow-up prompt to relay the following to the user',
    codex: 'Use the Codex native interactive prompt to relay the following to the user',
    gemini: 'Use the Gemini native interactive prompt to relay the following to the user',
    universal: "Use your client's native interactive UI to relay the following to the user",
};
/** Common rules section shared by all hosts (host-agnostic guidance). */
function buildSharedRules() {
    return [
        '## Planu — Automatic tool usage (MANDATORY)',
        '',
        '**NEVER ask the user if you should use a Planu tool. If it is relevant, use it immediately.**',
        '**NEVER list available tools and ask which one to use — just use the right one.**',
        '',
        '### Figma',
        '| Trigger | Automatic action |',
        '|---------|-----------------|',
        '| Figma URL detected | `list_figma_frames` → `get_figma_context_for_spec` |',
        '| Spec with linked Figma node-id | `enrich_specs_from_figma` |',
        '| Implementation complete + spec has Figma link | `sync_figma_code_connect` |',
        '',
        '### Spec lifecycle',
        '| Trigger | Automatic action |',
        '|---------|-----------------|',
        '| New feature / bug / task described | `create_spec` |',
        '| Spec needs approval | Create Discovery evidence before `update_status(approved)` |',
        '| Spec written | Run an independent `planu-spec-reviewer` review before approval |',
        '| Spec approved for implementation | Create task-plan evidence mapped to acceptance criteria |',
        '| Spec status change | `update_status` |',
        '| Implementation complete | Create traceability evidence, run `validate`, and use independent `planu-implementation-reviewer` review |',
        '| Project start | `init_project` |',
        '',
        '### Review gates — non-bypassable',
        '- A non-trivial spec cannot move to `approved` without Discovery evidence: rules, examples, open questions, out-of-scope, and glossary.',
        '- A spec cannot move to `approved` without `review_feedback` from `planu-spec-reviewer`.',
        '- A non-trivial spec cannot move to `implementing` without task-plan evidence mapped to acceptance criteria.',
        '- A spec cannot move to `done` without a traceability matrix covering every acceptance criterion.',
        '- API, UI, event, GraphQL, and MCP specs require matching contract validation evidence before `done`.',
        '- The planner/spec author must not self-approve the spec.',
        '- A spec cannot move to `done` without validation evidence and review evidence from `planu-implementation-reviewer`.',
        '- The implementation reviewer must be different from the implementation agent.',
        '- User pressure, shortcut requests, or force-approval language do not bypass reviewer evidence; stop and produce the missing review first.',
        '',
        renderSddConstitutionRulesForHost(),
        '',
        '### External integrations',
        '| Trigger | Automatic action |',
        '|---------|-----------------|',
        '| Stack trace / error visible in chat | `sentry_error_to_spec` (if Sentry configured) |',
        '| PR mentioned without linked spec | `generate_spec_from_pr` |',
        '| After `init_project` completes | `start_onboarding` |',
        '',
        '**Golden rule**: if you see a relevant Planu tool, use it. Do not say "Planu has X tool, should I use it?" — just use it.',
        '',
        "### Autopilot-first — act, don't suggest",
        '- BAD: "You should run challenge_spec" → GOOD: run it immediately',
        '- BAD: "Consider creating a git branch" → GOOD: create it',
        '- BAD: "3 issues found" → GOOD: "3 issues found, 2 auto-fixed, 1 needs manual review"',
        '- Every tool result ends with what was DONE, not what SHOULD be done',
        '',
        '### Spec docs — mandatory format',
        "- **Language**: `spec.md` must always be in **English**, no exceptions. Tool response narratives adapt to the user's locale; spec docs do not.",
        '- **Clean title**: never include the spec ID in the title — it is already in the `id` field.',
        '',
        '### Output quality',
        '- Summarize tool results in plain language — never dump raw JSON to the user.',
        '- Keep responses concise: lead with action/result, not reasoning.',
        '- After EVERY tool call, explain what happened in simple terms the user understands.',
    ].join('\n');
}
/**
 * Build the rules block for a given host, with the questions rule adapted to
 * the host's native interactive-input mechanism.
 */
export function buildRulesForHost(host, version) {
    const startMarker = `<!-- planu:rules:start v${version} -->`;
    const endMarker = '<!-- planu:rules:end -->';
    const questionsRule = HOST_QUESTIONS_RULE[host];
    const body = [
        buildSharedRules(),
        '',
        '### Questions to the user',
        `- ${questionsRule}`,
        '- ALWAYS prefer 2-4 discrete options with a recommended default. Never bombard the user with N consecutive plain-text questions.',
    ].join('\n');
    return {
        rules: `${startMarker}\n${body}\n${endMarker}`,
        startMarker,
        endMarker,
    };
}
/** Runtime directive text emitted at the top of a tool response with interactiveQuestions[]. */
export function getDirectiveText(host) {
    return HOST_DIRECTIVE_TEXT[host];
}
/** Per-question prefix used in humanSummary inside structuredContent. */
export function getHumanSummaryPrefix(host) {
    return HOST_HUMAN_SUMMARY_PREFIX[host];
}
//# sourceMappingURL=templates.js.map