// @bun
var __defProp = Object.defineProperty;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __hasOwnProp = Object.prototype.hasOwnProperty;
function __accessProp(key) {
  return this[key];
}
var __toCommonJS = (from) => {
  var entry = (__moduleCache ??= new WeakMap).get(from), desc;
  if (entry)
    return entry;
  entry = __defProp({}, "__esModule", { value: true });
  if (from && typeof from === "object" || typeof from === "function") {
    for (var key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(entry, key))
        __defProp(entry, key, {
          get: __accessProp.bind(from, key),
          enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
        });
  }
  __moduleCache.set(from, entry);
  return entry;
};
var __moduleCache;
var __returnValue = (v) => v;
function __exportSetter(name, newValue) {
  this[name] = __returnValue.bind(null, newValue);
}
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, {
      get: all[name],
      enumerable: true,
      configurable: true,
      set: __exportSetter.bind(all, name)
    });
};
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
var __require = import.meta.require;

// src/lib/package-version.ts
import { existsSync, readFileSync } from "fs";
import { dirname, join } from "path";
import { fileURLToPath } from "url";
function getPackageVersion(fromUrl = import.meta.url) {
  try {
    let dir = dirname(fileURLToPath(fromUrl));
    for (let i = 0;i < 5; i++) {
      const pkgPath = join(dir, "package.json");
      if (existsSync(pkgPath)) {
        return JSON.parse(readFileSync(pkgPath, "utf-8")).version || "0.0.0";
      }
      const parent = dirname(dir);
      if (parent === dir)
        break;
      dir = parent;
    }
  } catch {
    return "0.0.0";
  }
  return "0.0.0";
}

// src/mcp/token-utils.ts
var CORE_MCP_TOOLS = new Set([
  "add_comment",
  "bootstrap",
  "claim_next_task",
  "complete_task",
  "create_task",
  "fail_task",
  "get_context",
  "get_health",
  "get_next_task",
  "get_status",
  "get_task",
  "get_tasks_changed_since",
  "heartbeat",
  "list_agents",
  "list_tasks",
  "register_agent",
  "release_agent",
  "start_task",
  "suggest_agent_name"
]);
var MCP_TOOL_GROUPS = {
  core: [...CORE_MCP_TOOLS],
  tasks: [
    "archive_completed",
    "approve_task",
    "build_agent_context_pack",
    "bulk_create_tasks",
    "bulk_delete_tasks",
    "bulk_update_tasks",
    "cancel_task",
    "check_task_done_contract",
    "claim_task",
    "clone_task",
    "delete_task",
    "extend_task",
    "get_active_work",
    "get_archived_tasks",
    "get_blocked_tasks",
    "get_blocking_tasks",
    "get_my_tasks",
    "get_review_queue",
    "list_review_queue",
    "get_sla_breaches",
    "get_stale_tasks",
    "get_task_contract",
    "check_task_lock",
    "list_my_tasks",
    "lock_task",
    "move_task",
    "patrol_tasks",
    "prioritize_task",
    "reassign_task",
    "record_task_review",
    "approve_review_item",
    "claim_review_item",
    "release_task",
    "request_review_queue",
    "return_review_item",
    "reopen_review_item",
    "request_task_review",
    "reschedule_task",
    "search_tasks",
    "save_search_view",
    "list_search_views",
    "run_search_view",
    "delete_search_view",
    "standup",
    "set_task_contract",
    "task_context",
    "unlock_task",
    "unarchive_task",
    "update_task"
  ],
  projects: [
    "bootstrap_project",
    "approve_approval_gate",
    "create_milestone",
    "create_plan",
    "create_branch_work_plan",
    "create_project",
    "create_roadmap",
    "create_task_list",
    "delete_milestone",
    "delete_plan",
    "delete_project",
    "delete_roadmap",
    "delete_task_list",
    "check_approval_gate",
    "check_local_notifications",
    "check_runner_sandbox",
    "check_workspace_permission",
    "explain_policy_pack",
    "explain_runner_sandbox",
    "expire_approval_gate",
    "evaluate_terminal_watch_rules",
    "get_focus",
    "get_plan",
    "get_planning_forecast",
    "get_audit_ledger",
    "check_release_compatibility",
    "get_roadmap_summary",
    "validate_policy_pack",
    "get_project",
    "get_secret_safety",
    "preview_retention_cleanup",
    "apply_retention_cleanup",
    "get_task_list",
    "get_workspace_trust",
    "list_approval_gates",
    "list_local_event_hooks",
    "list_terminal_notification_rules",
    "list_encryption_profiles",
    "list_policy_packs",
    "list_capacity_profiles",
    "list_audit_ledger_checkpoints",
    "list_roadmaps",
    "list_runner_sandbox_profiles",
    "list_workspace_trust_profiles",
    "list_plans",
    "list_projects",
    "list_task_lists",
    "preview_natural_language_intake",
    "remove_policy_pack",
    "remove_encryption_profile",
    "remove_local_event_hook",
    "remove_terminal_notification_rule",
    "remove_runner_sandbox_profile",
    "remove_workspace_trust",
    "reject_approval_gate",
    "require_approval_gate",
    "set_focus",
    "set_capacity_profile",
    "seal_audit_ledger",
    "set_secret_safety",
    "set_encryption_profile",
    "set_local_event_hook",
    "set_terminal_notification_rule",
    "set_policy_pack",
    "set_release_group",
    "verify_audit_ledger",
    "set_runner_sandbox_profile",
    "set_workspace_trust",
    "remove_capacity_profile",
    "unfocus",
    "update_plan",
    "update_project",
    "update_milestone",
    "update_roadmap",
    "update_task_list",
    "test_local_event_hook",
    "test_terminal_notification_rule",
    "get_encryption_status",
    "encrypt_local_value",
    "decrypt_local_value",
    "scan_secret_text",
    "export_roadmap",
    "import_roadmap"
  ],
  resources: [
    "add_task_dependency",
    "add_task_file",
    "add_task_relationship",
    "bulk_find_tasks_by_files",
    "check_file_lock",
    "create_comment",
    "create_knowledge_record",
    "create_knowledge_snapshot",
    "create_retrospective",
    "create_risk",
    "create_handoff",
    "capture_environment_snapshot",
    "check_local_integrity",
    "compare_environment_snapshots",
    "create_local_backup",
    "create_inbox_item",
    "delete_comment",
    "detect_file_relationships",
    "export_handoff",
    "export_agent_reliability_scorecards",
    "export_knowledge_records",
    "export_retrospectives",
    "export_risk_register",
    "find_path",
    "find_task_by_commit",
    "find_tasks_by_file",
    "find_tasks_by_git_ref",
    "generate_release_notes",
    "add_task_verification",
    "add_task_run_artifact",
    "add_task_run_command",
    "add_task_run_event",
    "add_task_run_file",
    "acknowledge_handoff",
    "build_local_report",
    "cancel_agent_run_dispatch",
    "finish_task_run",
    "find_duplicate_tasks",
    "get_verification_provider_capabilities",
    "get_comments",
    "get_critical_path",
    "get_agent_reliability_scorecard",
    "get_file_heat_map",
    "get_impact_analysis",
    "get_inbox_item",
    "get_onboarding_fixture",
    "get_local_snapshot",
    "get_latest_handoff",
    "get_related_entities",
    "read_handoff",
    "recover_stale_session_handoff",
    "close_risk",
    "get_task_git_refs",
    "get_task_run_ledger",
    "get_usage_ledger",
    "list_agent_run_adapters",
    "list_agent_run_queue",
    "verify_task_run_artifacts",
    "verify_local_backup",
    "get_task_traceability",
    "get_task_commits",
    "get_task_dependencies",
    "get_task_relationships",
    "get_task_watchers",
    "import_handoff",
    "import_external_issues",
    "import_onboarding_fixture",
    "link_task_git_ref",
    "link_task_to_commit",
    "list_active_files",
    "list_comments",
    "list_file_locks",
    "list_handoffs",
    "list_inbox_items",
    "list_knowledge_records",
    "list_local_report_types",
    "list_onboarding_fixtures",
    "list_review_routing_rules",
    "list_local_snapshots",
    "list_retrospectives",
    "list_risks",
    "list_task_runs",
    "list_verification_providers",
    "merge_duplicate_task",
    "queue_agent_run",
    "remove_agent_run_adapter",
    "remove_review_routing_rule",
    "restore_local_backup",
    "retry_agent_run_dispatch",
    "resolve_mentions",
    "run_next_agent_dispatch",
    "search_knowledge_records",
    "score_plan_health",
    "score_project_health",
    "set_agent_run_adapter",
    "set_review_routing_rule",
    "set_verification_provider",
    "simulate_agent_replay",
    "discover_local_extensions",
    "inspect_local_extension",
    "install_local_extension",
    "list_local_extensions",
    "remove_local_extension",
    "test_local_extension_compatibility",
    "list_task_files",
    "lock_file",
    "create_calendar_item",
    "list_calendar_events",
    "export_calendar_ics",
    "import_calendar_ics",
    "create_board",
    "list_boards",
    "get_board_snapshot",
    "move_board_card",
    "log_time",
    "start_focus_session",
    "pause_focus_session",
    "resume_focus_session",
    "stop_focus_session",
    "list_focus_sessions",
    "get_idle_focus_prompts",
    "remove_task_dependency",
    "remove_task_relationship",
    "remove_verification_provider",
    "poll_local_snapshots",
    "run_verification_provider",
    "start_task_run",
    "sync_kg",
    "unlock_file",
    "unwatch_task",
    "update_comment",
    "update_risk",
    "watch_task"
  ],
  agents: [
    "auto_assign_task",
    "delete_agent",
    "get_agent",
    "get_agent_metrics",
    "get_capable_agents",
    "get_leaderboard",
    "get_my_workload",
    "get_org_chart",
    "get_project_org_chart",
    "get_time_report",
    "list_project_agent_roles",
    "rebalance_workload",
    "rename_agent",
    "set_project_agent_role",
    "set_reports_to",
    "unarchive_agent",
    "update_agent"
  ],
  metadata: [
    "create_label",
    "create_tag",
    "delete_label",
    "delete_tag",
    "get_label",
    "get_activity_timeline",
    "get_recent_activity",
    "get_tag",
    "get_task_fields",
    "get_task_graph",
    "get_task_history",
    "get_task_stats",
    "list_workflow_states",
    "list_labels",
    "list_tags",
    "migrate_workflow_states",
    "query_tasks_by_workflow_state",
    "query_tasks_by_fields",
    "search_tools",
    "describe_tools",
    "set_task_workflow_state",
    "set_task_fields",
    "update_label",
    "update_tag"
  ],
  dispatch: [
    "cancel_dispatch",
    "dispatch_task_list",
    "dispatch_tasks",
    "dispatch_to_multiple",
    "list_dispatches",
    "run_due_dispatches"
  ],
  templates: [
    "create_task_from_template",
    "create_template",
    "delete_template",
    "export_template",
    "import_template",
    "init_templates",
    "list_template_library",
    "list_templates",
    "preview_template",
    "template_history",
    "update_template",
    "write_template_library"
  ],
  webhooks: ["create_webhook", "delete_webhook", "list_webhooks"],
  machines: [
    "machines_archive",
    "machines_delete",
    "machines_heartbeat",
    "machines_list",
    "machines_register",
    "machines_set_primary",
    "machines_topology",
    "machines_unarchive"
  ],
  maintenance: ["extract_todos", "get_sla_breaches", "notify_upcoming_deadlines", "run_doctor", "score_task", "watch_source_todos"]
};
var MCP_PROFILE_GROUPS = {
  minimal: ["core"],
  core: ["core"],
  standard: ["core", "tasks", "projects", "resources", "agents", "metadata"],
  agent: ["core", "tasks", "projects", "resources"],
  maintainer: ["core", "tasks", "projects", "resources", "agents", "metadata", "dispatch", "maintenance"]
};
function splitTokens(value) {
  return (value || "").split(",").map((item) => item.trim().toLowerCase()).filter(Boolean);
}
function addGroupTools(toolNames, groupName) {
  const tools = MCP_TOOL_GROUPS[groupName];
  if (!tools)
    return false;
  for (const tool of tools)
    toolNames.add(tool);
  return true;
}
function shouldRegisterToolForProfile(name, profileValue = process.env["TODOS_PROFILE"], groupValue = process.env["TODOS_TOOL_GROUPS"]) {
  const profileTokens = splitTokens(profileValue || "minimal");
  const groupTokens = splitTokens(groupValue);
  if (profileTokens.includes("full") || profileTokens.includes("all"))
    return true;
  const tools = new Set;
  let matchedProfile = false;
  for (const token of profileTokens) {
    const profileGroups = MCP_PROFILE_GROUPS[token];
    if (profileGroups) {
      matchedProfile = true;
      for (const group of profileGroups)
        addGroupTools(tools, group);
      continue;
    }
    if (addGroupTools(tools, token)) {
      matchedProfile = true;
      continue;
    }
    if (token.startsWith("tool:")) {
      matchedProfile = true;
      tools.add(token.slice("tool:".length));
    }
  }
  if (!matchedProfile) {
    addGroupTools(tools, "core");
  }
  for (const token of groupTokens) {
    if (token === "full" || token === "all")
      return true;
    if (!addGroupTools(tools, token) && token.startsWith("tool:")) {
      tools.add(token.slice("tool:".length));
    }
  }
  return tools.has(name);
}

// src/mcp.ts
function source(version) {
  return {
    packageName: "@hasna/todos",
    repository: "hasna/todos",
    version
  };
}
function uniqueSorted(values) {
  return [...new Set(values)].sort((left, right) => left.localeCompare(right));
}
function getAllMcpToolNames() {
  return uniqueSorted(Object.values(MCP_TOOL_GROUPS).flatMap((tools) => [...tools]));
}
function groupsForTool(toolName) {
  return Object.entries(MCP_TOOL_GROUPS).filter(([, tools]) => tools.includes(toolName)).map(([group]) => group).sort((left, right) => left.localeCompare(right));
}
function profilesForTool(toolName) {
  return Object.entries(MCP_PROFILE_GROUPS).filter(([, groups]) => groups.some((group) => MCP_TOOL_GROUPS[group]?.includes(toolName))).map(([profile]) => profile).sort((left, right) => left.localeCompare(right));
}
function getMcpToolNames(options = {}) {
  const profile = options.profile ?? "minimal";
  const groups = options.groups ?? "";
  return getAllMcpToolNames().filter((toolName) => shouldRegisterToolForProfile(toolName, profile, groups));
}
function createMcpManifest(options = {}) {
  const version = options.version ?? getPackageVersion(import.meta.url);
  return {
    schemaVersion: 1,
    generatedAt: options.generatedAt ?? new Date().toISOString(),
    package: source(version),
    server: {
      name: "todos",
      binary: "todos-mcp",
      transport: "stdio",
      profileEnvironmentVariable: "TODOS_PROFILE",
      groupEnvironmentVariable: "TODOS_TOOL_GROUPS"
    },
    groups: MCP_TOOL_GROUPS,
    profiles: MCP_PROFILE_GROUPS,
    tools: getAllMcpToolNames().map((toolName) => ({
      name: toolName,
      groups: groupsForTool(toolName),
      profiles: profilesForTool(toolName),
      core: CORE_MCP_TOOLS.has(toolName),
      stability: CORE_MCP_TOOLS.has(toolName) ? "stable" : "experimental"
    }))
  };
}
var TODOS_MCP_MANIFEST = createMcpManifest({
  generatedAt: "1970-01-01T00:00:00.000Z"
});
export {
  shouldRegisterToolForProfile,
  getMcpToolNames,
  createMcpManifest,
  TODOS_MCP_MANIFEST,
  MCP_TOOL_GROUPS,
  MCP_PROFILE_GROUPS,
  CORE_MCP_TOOLS
};
