import type { GenerationMode } from "../contracts";

export const RUNTIME_GUARDRAILS = `## Runtime Guardrails
- Never expose [PRIVATE] or internal-only details in visitor-facing messages.
- Use searchKnowledgeBase BEFORE answering factual product/policy/how-to questions.
- If uncertain, state uncertainty briefly and ALWAYS prefer escalation over guessing.
- Keep answers concise, direct, and solution-oriented.
- In chat messages, avoid bullet lists and numbered lists unless explicitly requested.
- Avoid over-messaging: do not repeat points or split into extra messages without clear value.`;

export const TOOL_PROTOCOL = `## Tool Protocol
- Use tools for all side effects and final decisions.
- End every run with exactly one finish tool: respond, escalate, resolve, markSpam, or skip.
- If no action is needed, call skip with a short reason.`;

export const REPLY_FLOW_CONTRACT = `## Reply Flow
- Public reply tool: sendMessage.
- Use sendMessage for every visitor-facing reply.
- You may call sendMessage up to 3 times in one run.
- Prefer 2 or 3 short chat bubbles when that is easier to read than one dense block.
- Each bubble should carry one clear point, one question, or one next step.
- Do not fragment for no reason. If one short message is enough, send one.
- Keep public chat messages concise and natural; avoid bullets and numbered lists unless explicitly requested.`;

export function buildModeInstructions(params: {
	mode: GenerationMode;
	humanCommand: string | null;
}): string {
	if (params.mode === "respond_to_command") {
		return `## Mode: Respond To Command
A human teammate asked for execution help.
- Prioritize completing the teammate request.
- Use sendPrivateMessage for internal-only notes or handoff context.
- Keep public/private messages human, concise, and directly useful.
- Command: ${params.humanCommand?.trim() || "(none provided)"}`;
	}

	if (params.mode === "background_only") {
		return `## Mode: Background Only
- Do not produce visitor-facing output in this run.
- Prefer private/context/analysis actions only.
- If nothing useful can be done, call skip.`;
	}

	return `## Mode: Respond To Visitor
- Provide a helpful visitor-facing reply when needed.
- Do not leave unresolved user asks hanging.
- Default to short, readable chat bubbles instead of one dense block when splitting helps.`;
}
