// Force strict mode and setup for ESM
"use strict";
import {
  mapSkillConfigToStatus
} from "./chunk-6IAWPIQ6.js";
import {
  loadSettings
} from "./chunk-AFPB2TZB.js";
import {
  STATUS_SCHEMA_VERSION
} from "./chunk-7MFZZRJS.js";
import {
  writeStderrLine
} from "./chunk-Y6Z2O3WR.js";
import {
  SkillManager,
  isSafeModeEnv
} from "./chunk-IQ7FOOIH.js";
import {
  init_esbuild_shims
} from "./chunk-A4BMJM77.js";
import {
  __name
} from "./chunk-J2S4EL5Y.js";

// packages/cli/src/serve/workspace-skills-status.ts
init_esbuild_shims();
function createWorkspaceSkillsStatusProvider() {
  const managers = /* @__PURE__ */ new Map();
  return (workspaceCwd) => buildWorkspaceSkillsStatus(workspaceCwd, managers);
}
__name(createWorkspaceSkillsStatusProvider, "createWorkspaceSkillsStatusProvider");
async function buildWorkspaceSkillsStatus(workspaceCwd, managers) {
  try {
    let skillManager = managers.get(workspaceCwd);
    if (!skillManager) {
      const shim = {
        // Honor the safe-mode env the same way `Config` does when no explicit
        // flag is passed, so an operator running in safe mode gets the same
        // bundled-only listing the child would produce.
        isSafeMode: /* @__PURE__ */ __name(() => isSafeModeEnv(), "isSafeMode"),
        // Bare mode is the interactive `--bare` CLI flag; the daemon never runs
        // bare, so it is always off here.
        getBareMode: /* @__PURE__ */ __name(() => false, "getBareMode"),
        getProjectRoot: /* @__PURE__ */ __name(() => workspaceCwd, "getProjectRoot"),
        // Extension skills need active-extension context that only the child
        // has; omit them here and let the session snapshot surface them.
        getActiveExtensions: /* @__PURE__ */ __name(() => [], "getActiveExtensions")
      };
      skillManager = new SkillManager(shim);
      managers.set(workspaceCwd, skillManager);
    }
    const disabled = readDisabledSkillNames(workspaceCwd);
    const skills = await skillManager.listSkills();
    return {
      v: STATUS_SCHEMA_VERSION,
      workspaceCwd,
      initialized: true,
      skills: skills.map((skill) => mapSkillConfigToStatus(skill, disabled))
    };
  } catch (error) {
    const message = error instanceof Error ? error.message : String(error);
    writeStderrLine(
      `qwen serve: daemon-local skills enumeration failed for ${workspaceCwd}: ${message}`
    );
    return {
      v: STATUS_SCHEMA_VERSION,
      workspaceCwd,
      initialized: false,
      skills: [],
      errors: [
        {
          kind: "skills",
          status: "error",
          error: message
        }
      ]
    };
  }
}
__name(buildWorkspaceSkillsStatus, "buildWorkspaceSkillsStatus");
function readDisabledSkillNames(workspaceCwd) {
  const raw = loadSettings(workspaceCwd, false).merged.skills?.disabled;
  if (!Array.isArray(raw)) return /* @__PURE__ */ new Set();
  return new Set(
    raw.filter((name) => typeof name === "string").map((name) => name.trim().toLowerCase()).filter(Boolean)
  );
}
__name(readDisabledSkillNames, "readDisabledSkillNames");

export {
  createWorkspaceSkillsStatusProvider
};
/**
 * @license
 * Copyright 2025 Qwen Team
 * SPDX-License-Identifier: Apache-2.0
 */
