const TASK_PLAN_TOOL_NAME = "meta.update_task_plan";
const TASK_PLAN_TOOL_NAME_SDK = "meta__update_task_plan";
const TASK_PLAN_MAX_TASKS = 8;
const TASK_PLAN_LABEL_MAX_CHARS = 80;
const TASK_PLAN_DETAIL_MAX_CHARS = 160;
const TASK_PLAN_ID_MAX_CHARS = 80;
const TASK_PLAN_TOOL_NAME_MAX_CHARS = 160;
const TASK_PLAN_RUNTIME_PROMPT_SECTION = [
  "TASK PLAN (RUNTIME)",
  "For every tool-using turn, first call `meta.update_task_plan` with 2-5 concise user-visible steps. Then call the domain/search/attachment/mutation tools.",
  "Task labels are visible progress UI. Never include hidden reasoning, chain-of-thought, scratchpad notes, or XML thinking tags.",
  "When a planned step maps to a known tool, include `toolName` so the chat can advance that row from pending to running to done.",
  "Skip `meta.update_task_plan` for pure capability, example-question, or how-can-you-help prompts where no data tool is needed."
].join("\n");
const HIDDEN_REASONING_PATTERNS = [
  /\bchain[-\s]?of[-\s]?thought\b/i,
  /\binternal\s+(?:reasoning|thoughts?)\b/i,
  /\bprivate\s+(?:reasoning|thoughts?)\b/i,
  /\bhidden\s+(?:reasoning|thoughts?)\b/i,
  /\bscratch\s*pad\b/i,
  /\bscratchpad\b/i,
  /\b(?:my\s+)?reasoning\s*:/i,
  /<\/?\s*(?:thinking|thought|reasoning|scratchpad)\b/i
];
const CONTROL_CHARS = /[\u0000-\u001f\u007f]/g;
const WHITESPACE = /\s+/g;
function normalizeTaskPlanToolName(toolName) {
  if (typeof toolName !== "string") return void 0;
  const trimmed = toolName.trim();
  if (!trimmed) return void 0;
  const dotted = trimmed.replace(/__/g, ".");
  const safe = dotted.replace(/[^a-zA-Z0-9._:-]/g, "").slice(0, TASK_PLAN_TOOL_NAME_MAX_CHARS);
  return safe.length > 0 ? safe : void 0;
}
function isTaskPlanToolName(toolName) {
  return normalizeTaskPlanToolName(toolName) === TASK_PLAN_TOOL_NAME;
}
function looksLikeHiddenReasoning(value) {
  return HIDDEN_REASONING_PATTERNS.some((pattern) => pattern.test(value));
}
function sanitizeTaskPlanText(value, maxChars) {
  if (typeof value !== "string") return null;
  const normalized = value.replace(CONTROL_CHARS, " ").replace(WHITESPACE, " ").trim();
  if (!normalized) return null;
  if (looksLikeHiddenReasoning(normalized)) return null;
  return normalized.slice(0, maxChars);
}
function sanitizeTaskPlanId(value) {
  if (typeof value !== "string") return void 0;
  const normalized = value.trim().replace(/\s+/g, "-").replace(/[^a-zA-Z0-9._:-]/g, "").slice(0, TASK_PLAN_ID_MAX_CHARS);
  return normalized.length > 0 ? normalized : void 0;
}
function sanitizeAgentTaskPlanInput(input) {
  if (!input || typeof input !== "object") {
    return { tasks: [] };
  }
  const rawTasks = input.tasks;
  if (!Array.isArray(rawTasks)) {
    return { tasks: [] };
  }
  const tasks = [];
  for (const rawTask of rawTasks.slice(0, TASK_PLAN_MAX_TASKS)) {
    if (!rawTask || typeof rawTask !== "object") continue;
    const value = rawTask;
    const label = sanitizeTaskPlanText(value.label, TASK_PLAN_LABEL_MAX_CHARS);
    if (!label) continue;
    const detail = sanitizeTaskPlanText(value.detail, TASK_PLAN_DETAIL_MAX_CHARS) ?? void 0;
    const id = sanitizeTaskPlanId(value.id);
    const toolName = normalizeTaskPlanToolName(value.toolName);
    tasks.push({
      ...id ? { id } : {},
      label,
      ...detail ? { detail } : {},
      ...toolName ? { toolName } : {}
    });
  }
  return { tasks };
}
export {
  TASK_PLAN_DETAIL_MAX_CHARS,
  TASK_PLAN_ID_MAX_CHARS,
  TASK_PLAN_LABEL_MAX_CHARS,
  TASK_PLAN_MAX_TASKS,
  TASK_PLAN_RUNTIME_PROMPT_SECTION,
  TASK_PLAN_TOOL_NAME,
  TASK_PLAN_TOOL_NAME_MAX_CHARS,
  TASK_PLAN_TOOL_NAME_SDK,
  isTaskPlanToolName,
  looksLikeHiddenReasoning,
  normalizeTaskPlanToolName,
  sanitizeAgentTaskPlanInput,
  sanitizeTaskPlanId,
  sanitizeTaskPlanText
};
//# sourceMappingURL=task-plan-labels.js.map
