@onexapis/cli 1.1.45 → 1.1.47

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.mjs CHANGED
@@ -2673,12 +2673,12 @@ async function validateCommand(options) {
2673
2673
  }
2674
2674
  themeToValidate = options.theme;
2675
2675
  } else {
2676
- const isThemeDir = [
2676
+ const isThemeDir2 = [
2677
2677
  "theme.config.ts",
2678
2678
  "bundle-entry.ts",
2679
2679
  "manifest.ts"
2680
2680
  ].some((f) => fs.existsSync(path9.join(process.cwd(), f)));
2681
- if (isThemeDir) {
2681
+ if (isThemeDir2) {
2682
2682
  themeToValidate = path9.basename(process.cwd());
2683
2683
  logger.info(`Validating current theme: ${themeToValidate}`);
2684
2684
  } else {
@@ -3070,12 +3070,12 @@ async function buildCommand(options) {
3070
3070
  process.exit(1);
3071
3071
  }
3072
3072
  } else {
3073
- const isThemeDir = [
3073
+ const isThemeDir2 = [
3074
3074
  "theme.config.ts",
3075
3075
  "bundle-entry.ts",
3076
3076
  "manifest.ts"
3077
3077
  ].some((f) => fs.existsSync(path9.join(process.cwd(), f)));
3078
- if (isThemeDir) {
3078
+ if (isThemeDir2) {
3079
3079
  themePath = process.cwd();
3080
3080
  themeName = path9.basename(themePath);
3081
3081
  logger.info(`Building current theme: ${themeName}`);
@@ -3206,12 +3206,12 @@ async function packageCommand(options) {
3206
3206
  process.exit(1);
3207
3207
  }
3208
3208
  } else {
3209
- const isThemeDir = [
3209
+ const isThemeDir2 = [
3210
3210
  "theme.config.ts",
3211
3211
  "bundle-entry.ts",
3212
3212
  "manifest.ts"
3213
3213
  ].some((f) => fs.existsSync(path9.join(process.cwd(), f)));
3214
- if (isThemeDir) {
3214
+ if (isThemeDir2) {
3215
3215
  themePath = process.cwd();
3216
3216
  themeName = path9.basename(themePath);
3217
3217
  logger.info(`Packaging current theme: ${themeName}`);
@@ -3747,8 +3747,8 @@ function runInstall(cwd) {
3747
3747
  });
3748
3748
  }
3749
3749
  async function promptThemeName(originalName) {
3750
- const { default: inquirer7 } = await import('inquirer');
3751
- const { themeName } = await inquirer7.prompt([
3750
+ const { default: inquirer8 } = await import('inquirer');
3751
+ const { themeName } = await inquirer8.prompt([
3752
3752
  {
3753
3753
  type: "input",
3754
3754
  name: "themeName",
@@ -4225,12 +4225,12 @@ async function devCommand(options) {
4225
4225
  process.exit(1);
4226
4226
  }
4227
4227
  } else {
4228
- const isThemeDir = [
4228
+ const isThemeDir2 = [
4229
4229
  "theme.config.ts",
4230
4230
  "bundle-entry.ts",
4231
4231
  "manifest.ts"
4232
4232
  ].some((f) => fs.existsSync(path9.join(process.cwd(), f)));
4233
- if (isThemeDir) {
4233
+ if (isThemeDir2) {
4234
4234
  themePath = process.cwd();
4235
4235
  themeName = path9.basename(themePath);
4236
4236
  } else {
@@ -4658,12 +4658,12 @@ async function publishCommand(options) {
4658
4658
  if (options.theme) {
4659
4659
  themePath = path9.resolve(options.theme);
4660
4660
  } else {
4661
- const isThemeDir = [
4661
+ const isThemeDir2 = [
4662
4662
  "theme.config.ts",
4663
4663
  "bundle-entry.ts",
4664
4664
  "manifest.ts"
4665
4665
  ].some((f) => fs.existsSync(path9.join(process.cwd(), f)));
4666
- if (isThemeDir) {
4666
+ if (isThemeDir2) {
4667
4667
  themePath = process.cwd();
4668
4668
  } else {
4669
4669
  logger.error(
@@ -5013,6 +5013,218 @@ async function createZip(sourceDir, outputPath, exclude) {
5013
5013
  });
5014
5014
  }
5015
5015
 
5016
+ // src/commands/mcp.ts
5017
+ init_logger();
5018
+ var AI_CONTEXT_FILES = [
5019
+ "CLAUDE.md",
5020
+ "AGENTS.md",
5021
+ ".cursorrules",
5022
+ "THEME_REFERENCE.md",
5023
+ ".mcp.json"
5024
+ ];
5025
+ function resolveTargetDir(opts) {
5026
+ return path9.resolve(opts.cwd ?? process.cwd());
5027
+ }
5028
+ function resolveDefaultTemplateDir() {
5029
+ return path9.join(getTemplatesDir(), "default");
5030
+ }
5031
+ function isThemeDir(dir) {
5032
+ return fs.existsSync(path9.join(dir, "theme.config.ts")) || fs.existsSync(path9.join(dir, "theme.config.js"));
5033
+ }
5034
+ function inspectFiles(templateDir, targetDir) {
5035
+ return AI_CONTEXT_FILES.map((name) => {
5036
+ const templatePath = path9.join(templateDir, name);
5037
+ const targetPath = path9.join(targetDir, name);
5038
+ const exists = fs.existsSync(targetPath);
5039
+ let identical = false;
5040
+ if (exists && fs.existsSync(templatePath)) {
5041
+ try {
5042
+ const a = fs.readFileSync(templatePath, "utf-8");
5043
+ const b = fs.readFileSync(targetPath, "utf-8");
5044
+ identical = a.replace(/\r\n/g, "\n") === b.replace(/\r\n/g, "\n");
5045
+ } catch {
5046
+ identical = false;
5047
+ }
5048
+ }
5049
+ return { name, templatePath, targetPath, exists, identical };
5050
+ });
5051
+ }
5052
+ async function mcpSetupCommand(options = {}) {
5053
+ const targetDir = resolveTargetDir(options);
5054
+ const templateDir = resolveDefaultTemplateDir();
5055
+ logger.header("Install OneX MCP context files");
5056
+ logger.log(`Target: ${targetDir}`);
5057
+ logger.log("");
5058
+ if (!isThemeDir(targetDir)) {
5059
+ logger.error(
5060
+ `${targetDir} does not look like an OneX theme (no theme.config.ts found).`
5061
+ );
5062
+ logger.log("Run this command from the root of your theme project.");
5063
+ process.exitCode = 1;
5064
+ return;
5065
+ }
5066
+ const statuses = inspectFiles(templateDir, targetDir);
5067
+ const missing = statuses.filter((s) => !s.exists);
5068
+ if (missing.length === 0) {
5069
+ logger.success("All AI context files are already present.");
5070
+ logger.log(
5071
+ "Run `onexthm mcp upgrade` to refresh them to the latest version."
5072
+ );
5073
+ return;
5074
+ }
5075
+ logger.log(`Will install ${missing.length} file(s):`);
5076
+ for (const s of missing) logger.log(` + ${s.name}`);
5077
+ logger.log("");
5078
+ if (!options.yes) {
5079
+ const { confirm } = await inquirer.prompt([
5080
+ {
5081
+ type: "confirm",
5082
+ name: "confirm",
5083
+ message: "Proceed?",
5084
+ default: true
5085
+ }
5086
+ ]);
5087
+ if (!confirm) {
5088
+ logger.log("Cancelled.");
5089
+ return;
5090
+ }
5091
+ }
5092
+ for (const s of missing) {
5093
+ if (!fs.existsSync(s.templatePath)) {
5094
+ logger.warning(` ! ${s.name} not in template \u2014 skipped`);
5095
+ continue;
5096
+ }
5097
+ await fs.copy(s.templatePath, s.targetPath);
5098
+ logger.success(` \u2713 ${s.name}`);
5099
+ }
5100
+ logger.log("");
5101
+ logger.success("Done. Restart your AI client to pick up the new MCP server.");
5102
+ logger.log("");
5103
+ logger.log("Tip: if your theme uses the Figma MCP, edit .mcp.json and");
5104
+ logger.log(
5105
+ "replace __FIGMA_API_KEY__ with your Figma personal access token."
5106
+ );
5107
+ }
5108
+ async function mcpUpgradeCommand(options = {}) {
5109
+ const targetDir = resolveTargetDir(options);
5110
+ const templateDir = resolveDefaultTemplateDir();
5111
+ logger.header("Upgrade OneX MCP context files");
5112
+ logger.log(`Target: ${targetDir}`);
5113
+ logger.log("");
5114
+ if (!isThemeDir(targetDir)) {
5115
+ logger.error(
5116
+ `${targetDir} does not look like an OneX theme (no theme.config.ts found).`
5117
+ );
5118
+ process.exitCode = 1;
5119
+ return;
5120
+ }
5121
+ const statuses = inspectFiles(templateDir, targetDir);
5122
+ const toUpgrade = statuses.filter(
5123
+ (s) => !s.identical && s.name !== ".mcp.json"
5124
+ );
5125
+ const mcpJsonStatus = statuses.find((s) => s.name === ".mcp.json");
5126
+ if (mcpJsonStatus && !mcpJsonStatus.exists) {
5127
+ logger.warning(
5128
+ ".mcp.json is missing. Run `onexthm mcp setup` to install it."
5129
+ );
5130
+ }
5131
+ if (toUpgrade.length === 0) {
5132
+ logger.success("All AI context files are already up to date.");
5133
+ return;
5134
+ }
5135
+ logger.log("Files to update:");
5136
+ for (const s of toUpgrade) {
5137
+ const tag = !s.exists ? "+ new" : "~ changed";
5138
+ logger.log(` ${tag} ${s.name}`);
5139
+ }
5140
+ logger.log("");
5141
+ logger.log("(.mcp.json is never auto-upgraded \u2014 edit by hand if needed.)");
5142
+ logger.log("");
5143
+ if (!options.yes) {
5144
+ const { confirm } = await inquirer.prompt([
5145
+ {
5146
+ type: "confirm",
5147
+ name: "confirm",
5148
+ message: "Overwrite the file(s) above?",
5149
+ default: true
5150
+ }
5151
+ ]);
5152
+ if (!confirm) {
5153
+ logger.log("Cancelled.");
5154
+ return;
5155
+ }
5156
+ }
5157
+ for (const s of toUpgrade) {
5158
+ if (!fs.existsSync(s.templatePath)) {
5159
+ logger.warning(` ! ${s.name} not in template \u2014 skipped`);
5160
+ continue;
5161
+ }
5162
+ await fs.copy(s.templatePath, s.targetPath, { overwrite: true });
5163
+ logger.success(` \u2713 ${s.name}`);
5164
+ }
5165
+ logger.log("");
5166
+ logger.success("Done. Restart your AI client to pick up the new context.");
5167
+ }
5168
+ async function mcpDoctorCommand(options = {}) {
5169
+ const targetDir = resolveTargetDir(options);
5170
+ const templateDir = resolveDefaultTemplateDir();
5171
+ logger.header("OneX MCP doctor");
5172
+ logger.log(`Target: ${targetDir}`);
5173
+ logger.log("");
5174
+ if (!isThemeDir(targetDir)) {
5175
+ logger.error("Not an OneX theme directory (no theme.config.ts).");
5176
+ process.exitCode = 1;
5177
+ return;
5178
+ }
5179
+ logger.success("theme.config.ts present");
5180
+ const mcpJsonPath = path9.join(targetDir, ".mcp.json");
5181
+ if (!fs.existsSync(mcpJsonPath)) {
5182
+ logger.error(".mcp.json missing \u2014 run `onexthm mcp setup`");
5183
+ } else {
5184
+ try {
5185
+ const mcpJson = JSON.parse(fs.readFileSync(mcpJsonPath, "utf-8"));
5186
+ const servers = mcpJson?.mcpServers ?? {};
5187
+ if (servers.onexthm) {
5188
+ logger.success(".mcp.json registers `onexthm`");
5189
+ } else {
5190
+ logger.error(".mcp.json does not register `onexthm`");
5191
+ }
5192
+ if (servers.figma) {
5193
+ const arg = (servers.figma.args ?? []).join(" ");
5194
+ if (arg.includes("__FIGMA_API_KEY__")) {
5195
+ logger.warning(
5196
+ "figma server uses placeholder API key \u2014 replace __FIGMA_API_KEY__"
5197
+ );
5198
+ } else {
5199
+ logger.success(".mcp.json registers `figma`");
5200
+ }
5201
+ }
5202
+ } catch (err) {
5203
+ logger.error(`.mcp.json could not be parsed: ${err.message}`);
5204
+ }
5205
+ }
5206
+ const statuses = inspectFiles(templateDir, targetDir).filter(
5207
+ (s) => s.name !== ".mcp.json"
5208
+ );
5209
+ for (const s of statuses) {
5210
+ if (!s.exists) {
5211
+ logger.warning(`${s.name} missing`);
5212
+ } else if (!s.identical) {
5213
+ logger.warning(`${s.name} is out of date \u2014 run \`onexthm mcp upgrade\``);
5214
+ } else {
5215
+ logger.success(`${s.name} up to date`);
5216
+ }
5217
+ }
5218
+ const registryPath = path9.join(targetDir, "sections-registry.ts");
5219
+ if (fs.existsSync(registryPath)) {
5220
+ logger.success("sections-registry.ts present");
5221
+ } else {
5222
+ logger.warning(
5223
+ "sections-registry.ts missing \u2014 section tools won't auto-register"
5224
+ );
5225
+ }
5226
+ }
5227
+
5016
5228
  // src/cli.ts
5017
5229
  dotenv.config({
5018
5230
  path: path9.join(process.cwd(), ".env.local"),
@@ -5078,6 +5290,14 @@ program.command("config").description("Configure OneX CLI credentials (AWS, API
5078
5290
  program.command("login").description("Login to OneX platform").action(loginCommand);
5079
5291
  program.command("logout").description("Logout from OneX platform").action(logoutCommand);
5080
5292
  program.command("whoami").description("Show current logged-in developer").action(whoamiCommand);
5293
+ var mcpCmd = program.command("mcp").description("Manage MCP server registration and AI-context files");
5294
+ mcpCmd.command("setup").description(
5295
+ "Install .mcp.json + CLAUDE.md + AGENTS.md + .cursorrules into the current theme"
5296
+ ).option("-y, --yes", "Skip confirmation prompts").action(mcpSetupCommand);
5297
+ mcpCmd.command("upgrade").description(
5298
+ "Refresh AI-context files to the latest version from the bundled template"
5299
+ ).option("-y, --yes", "Skip confirmation prompts").action(mcpUpgradeCommand);
5300
+ mcpCmd.command("doctor").description("Diagnose MCP setup in the current theme directory").action(mcpDoctorCommand);
5081
5301
  program.command("publish").description("Build, scan, and publish theme to marketplace (requires login)").option("-t, --theme <path>", "Theme directory path").option(
5082
5302
  "--bump <type>",
5083
5303
  "Auto-bump version before publish (patch|minor|major)"