@onexapis/cli 1.1.45 → 1.1.46

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.js CHANGED
@@ -2716,12 +2716,12 @@ async function validateCommand(options) {
2716
2716
  }
2717
2717
  themeToValidate = options.theme;
2718
2718
  } else {
2719
- const isThemeDir = [
2719
+ const isThemeDir2 = [
2720
2720
  "theme.config.ts",
2721
2721
  "bundle-entry.ts",
2722
2722
  "manifest.ts"
2723
2723
  ].some((f) => fs__default.default.existsSync(path9__default.default.join(process.cwd(), f)));
2724
- if (isThemeDir) {
2724
+ if (isThemeDir2) {
2725
2725
  themeToValidate = path9__default.default.basename(process.cwd());
2726
2726
  logger.info(`Validating current theme: ${themeToValidate}`);
2727
2727
  } else {
@@ -3113,12 +3113,12 @@ async function buildCommand(options) {
3113
3113
  process.exit(1);
3114
3114
  }
3115
3115
  } else {
3116
- const isThemeDir = [
3116
+ const isThemeDir2 = [
3117
3117
  "theme.config.ts",
3118
3118
  "bundle-entry.ts",
3119
3119
  "manifest.ts"
3120
3120
  ].some((f) => fs__default.default.existsSync(path9__default.default.join(process.cwd(), f)));
3121
- if (isThemeDir) {
3121
+ if (isThemeDir2) {
3122
3122
  themePath = process.cwd();
3123
3123
  themeName = path9__default.default.basename(themePath);
3124
3124
  logger.info(`Building current theme: ${themeName}`);
@@ -3249,12 +3249,12 @@ async function packageCommand(options) {
3249
3249
  process.exit(1);
3250
3250
  }
3251
3251
  } else {
3252
- const isThemeDir = [
3252
+ const isThemeDir2 = [
3253
3253
  "theme.config.ts",
3254
3254
  "bundle-entry.ts",
3255
3255
  "manifest.ts"
3256
3256
  ].some((f) => fs__default.default.existsSync(path9__default.default.join(process.cwd(), f)));
3257
- if (isThemeDir) {
3257
+ if (isThemeDir2) {
3258
3258
  themePath = process.cwd();
3259
3259
  themeName = path9__default.default.basename(themePath);
3260
3260
  logger.info(`Packaging current theme: ${themeName}`);
@@ -3790,8 +3790,8 @@ function runInstall(cwd) {
3790
3790
  });
3791
3791
  }
3792
3792
  async function promptThemeName(originalName) {
3793
- const { default: inquirer7 } = await import('inquirer');
3794
- const { themeName } = await inquirer7.prompt([
3793
+ const { default: inquirer8 } = await import('inquirer');
3794
+ const { themeName } = await inquirer8.prompt([
3795
3795
  {
3796
3796
  type: "input",
3797
3797
  name: "themeName",
@@ -4268,12 +4268,12 @@ async function devCommand(options) {
4268
4268
  process.exit(1);
4269
4269
  }
4270
4270
  } else {
4271
- const isThemeDir = [
4271
+ const isThemeDir2 = [
4272
4272
  "theme.config.ts",
4273
4273
  "bundle-entry.ts",
4274
4274
  "manifest.ts"
4275
4275
  ].some((f) => fs__default.default.existsSync(path9__default.default.join(process.cwd(), f)));
4276
- if (isThemeDir) {
4276
+ if (isThemeDir2) {
4277
4277
  themePath = process.cwd();
4278
4278
  themeName = path9__default.default.basename(themePath);
4279
4279
  } else {
@@ -4701,12 +4701,12 @@ async function publishCommand(options) {
4701
4701
  if (options.theme) {
4702
4702
  themePath = path9__default.default.resolve(options.theme);
4703
4703
  } else {
4704
- const isThemeDir = [
4704
+ const isThemeDir2 = [
4705
4705
  "theme.config.ts",
4706
4706
  "bundle-entry.ts",
4707
4707
  "manifest.ts"
4708
4708
  ].some((f) => fs__default.default.existsSync(path9__default.default.join(process.cwd(), f)));
4709
- if (isThemeDir) {
4709
+ if (isThemeDir2) {
4710
4710
  themePath = process.cwd();
4711
4711
  } else {
4712
4712
  logger.error(
@@ -5056,6 +5056,210 @@ async function createZip(sourceDir, outputPath, exclude) {
5056
5056
  });
5057
5057
  }
5058
5058
 
5059
+ // src/commands/mcp.ts
5060
+ init_logger();
5061
+ var AI_CONTEXT_FILES = [
5062
+ "CLAUDE.md",
5063
+ "AGENTS.md",
5064
+ ".cursorrules",
5065
+ "THEME_REFERENCE.md",
5066
+ ".mcp.json"
5067
+ ];
5068
+ function resolveTargetDir(opts) {
5069
+ return path9__default.default.resolve(opts.cwd ?? process.cwd());
5070
+ }
5071
+ function resolveDefaultTemplateDir() {
5072
+ return path9__default.default.join(getTemplatesDir(), "default");
5073
+ }
5074
+ function isThemeDir(dir) {
5075
+ return fs__default.default.existsSync(path9__default.default.join(dir, "theme.config.ts")) || fs__default.default.existsSync(path9__default.default.join(dir, "theme.config.js"));
5076
+ }
5077
+ function inspectFiles(templateDir, targetDir) {
5078
+ return AI_CONTEXT_FILES.map((name) => {
5079
+ const templatePath = path9__default.default.join(templateDir, name);
5080
+ const targetPath = path9__default.default.join(targetDir, name);
5081
+ const exists = fs__default.default.existsSync(targetPath);
5082
+ let identical = false;
5083
+ if (exists && fs__default.default.existsSync(templatePath)) {
5084
+ try {
5085
+ const a = fs__default.default.readFileSync(templatePath, "utf-8");
5086
+ const b = fs__default.default.readFileSync(targetPath, "utf-8");
5087
+ identical = a.replace(/\r\n/g, "\n") === b.replace(/\r\n/g, "\n");
5088
+ } catch {
5089
+ identical = false;
5090
+ }
5091
+ }
5092
+ return { name, templatePath, targetPath, exists, identical };
5093
+ });
5094
+ }
5095
+ async function mcpSetupCommand(options = {}) {
5096
+ const targetDir = resolveTargetDir(options);
5097
+ const templateDir = resolveDefaultTemplateDir();
5098
+ logger.header("Install OneX MCP context files");
5099
+ logger.log(`Target: ${targetDir}`);
5100
+ logger.log("");
5101
+ if (!isThemeDir(targetDir)) {
5102
+ logger.error(
5103
+ `${targetDir} does not look like an OneX theme (no theme.config.ts found).`
5104
+ );
5105
+ logger.log("Run this command from the root of your theme project.");
5106
+ process.exitCode = 1;
5107
+ return;
5108
+ }
5109
+ const statuses = inspectFiles(templateDir, targetDir);
5110
+ const missing = statuses.filter((s) => !s.exists);
5111
+ if (missing.length === 0) {
5112
+ logger.success("All AI context files are already present.");
5113
+ logger.log("Run `onexthm mcp upgrade` to refresh them to the latest version.");
5114
+ return;
5115
+ }
5116
+ logger.log(`Will install ${missing.length} file(s):`);
5117
+ for (const s of missing) logger.log(` + ${s.name}`);
5118
+ logger.log("");
5119
+ if (!options.yes) {
5120
+ const { confirm } = await inquirer__default.default.prompt([
5121
+ {
5122
+ type: "confirm",
5123
+ name: "confirm",
5124
+ message: "Proceed?",
5125
+ default: true
5126
+ }
5127
+ ]);
5128
+ if (!confirm) {
5129
+ logger.log("Cancelled.");
5130
+ return;
5131
+ }
5132
+ }
5133
+ for (const s of missing) {
5134
+ if (!fs__default.default.existsSync(s.templatePath)) {
5135
+ logger.warning(` ! ${s.name} not in template \u2014 skipped`);
5136
+ continue;
5137
+ }
5138
+ await fs__default.default.copy(s.templatePath, s.targetPath);
5139
+ logger.success(` \u2713 ${s.name}`);
5140
+ }
5141
+ logger.log("");
5142
+ logger.success("Done. Restart your AI client to pick up the new MCP server.");
5143
+ logger.log("");
5144
+ logger.log("Tip: if your theme uses the Figma MCP, edit .mcp.json and");
5145
+ logger.log("replace __FIGMA_API_KEY__ with your Figma personal access token.");
5146
+ }
5147
+ async function mcpUpgradeCommand(options = {}) {
5148
+ const targetDir = resolveTargetDir(options);
5149
+ const templateDir = resolveDefaultTemplateDir();
5150
+ logger.header("Upgrade OneX MCP context files");
5151
+ logger.log(`Target: ${targetDir}`);
5152
+ logger.log("");
5153
+ if (!isThemeDir(targetDir)) {
5154
+ logger.error(
5155
+ `${targetDir} does not look like an OneX theme (no theme.config.ts found).`
5156
+ );
5157
+ process.exitCode = 1;
5158
+ return;
5159
+ }
5160
+ const statuses = inspectFiles(templateDir, targetDir);
5161
+ const toUpgrade = statuses.filter(
5162
+ (s) => !s.identical && s.name !== ".mcp.json"
5163
+ );
5164
+ const mcpJsonStatus = statuses.find((s) => s.name === ".mcp.json");
5165
+ if (mcpJsonStatus && !mcpJsonStatus.exists) {
5166
+ logger.warning(
5167
+ ".mcp.json is missing. Run `onexthm mcp setup` to install it."
5168
+ );
5169
+ }
5170
+ if (toUpgrade.length === 0) {
5171
+ logger.success("All AI context files are already up to date.");
5172
+ return;
5173
+ }
5174
+ logger.log("Files to update:");
5175
+ for (const s of toUpgrade) {
5176
+ const tag = !s.exists ? "+ new" : "~ changed";
5177
+ logger.log(` ${tag} ${s.name}`);
5178
+ }
5179
+ logger.log("");
5180
+ logger.log("(.mcp.json is never auto-upgraded \u2014 edit by hand if needed.)");
5181
+ logger.log("");
5182
+ if (!options.yes) {
5183
+ const { confirm } = await inquirer__default.default.prompt([
5184
+ {
5185
+ type: "confirm",
5186
+ name: "confirm",
5187
+ message: "Overwrite the file(s) above?",
5188
+ default: true
5189
+ }
5190
+ ]);
5191
+ if (!confirm) {
5192
+ logger.log("Cancelled.");
5193
+ return;
5194
+ }
5195
+ }
5196
+ for (const s of toUpgrade) {
5197
+ if (!fs__default.default.existsSync(s.templatePath)) {
5198
+ logger.warning(` ! ${s.name} not in template \u2014 skipped`);
5199
+ continue;
5200
+ }
5201
+ await fs__default.default.copy(s.templatePath, s.targetPath, { overwrite: true });
5202
+ logger.success(` \u2713 ${s.name}`);
5203
+ }
5204
+ logger.log("");
5205
+ logger.success("Done. Restart your AI client to pick up the new context.");
5206
+ }
5207
+ async function mcpDoctorCommand(options = {}) {
5208
+ const targetDir = resolveTargetDir(options);
5209
+ const templateDir = resolveDefaultTemplateDir();
5210
+ logger.header("OneX MCP doctor");
5211
+ logger.log(`Target: ${targetDir}`);
5212
+ logger.log("");
5213
+ if (!isThemeDir(targetDir)) {
5214
+ logger.error("Not an OneX theme directory (no theme.config.ts).");
5215
+ process.exitCode = 1;
5216
+ return;
5217
+ }
5218
+ logger.success("theme.config.ts present");
5219
+ const mcpJsonPath = path9__default.default.join(targetDir, ".mcp.json");
5220
+ if (!fs__default.default.existsSync(mcpJsonPath)) {
5221
+ logger.error(".mcp.json missing \u2014 run `onexthm mcp setup`");
5222
+ } else {
5223
+ try {
5224
+ const mcpJson = JSON.parse(fs__default.default.readFileSync(mcpJsonPath, "utf-8"));
5225
+ const servers = mcpJson?.mcpServers ?? {};
5226
+ if (servers.onexthm) {
5227
+ logger.success(".mcp.json registers `onexthm`");
5228
+ } else {
5229
+ logger.error(".mcp.json does not register `onexthm`");
5230
+ }
5231
+ if (servers.figma) {
5232
+ const arg = (servers.figma.args ?? []).join(" ");
5233
+ if (arg.includes("__FIGMA_API_KEY__")) {
5234
+ logger.warning("figma server uses placeholder API key \u2014 replace __FIGMA_API_KEY__");
5235
+ } else {
5236
+ logger.success(".mcp.json registers `figma`");
5237
+ }
5238
+ }
5239
+ } catch (err) {
5240
+ logger.error(`.mcp.json could not be parsed: ${err.message}`);
5241
+ }
5242
+ }
5243
+ const statuses = inspectFiles(templateDir, targetDir).filter(
5244
+ (s) => s.name !== ".mcp.json"
5245
+ );
5246
+ for (const s of statuses) {
5247
+ if (!s.exists) {
5248
+ logger.warning(`${s.name} missing`);
5249
+ } else if (!s.identical) {
5250
+ logger.warning(`${s.name} is out of date \u2014 run \`onexthm mcp upgrade\``);
5251
+ } else {
5252
+ logger.success(`${s.name} up to date`);
5253
+ }
5254
+ }
5255
+ const registryPath = path9__default.default.join(targetDir, "sections-registry.ts");
5256
+ if (fs__default.default.existsSync(registryPath)) {
5257
+ logger.success("sections-registry.ts present");
5258
+ } else {
5259
+ logger.warning("sections-registry.ts missing \u2014 section tools won't auto-register");
5260
+ }
5261
+ }
5262
+
5059
5263
  // src/cli.ts
5060
5264
  dotenv__default.default.config({
5061
5265
  path: path9__default.default.join(process.cwd(), ".env.local"),
@@ -5121,6 +5325,10 @@ program.command("config").description("Configure OneX CLI credentials (AWS, API
5121
5325
  program.command("login").description("Login to OneX platform").action(loginCommand);
5122
5326
  program.command("logout").description("Logout from OneX platform").action(logoutCommand);
5123
5327
  program.command("whoami").description("Show current logged-in developer").action(whoamiCommand);
5328
+ var mcpCmd = program.command("mcp").description("Manage MCP server registration and AI-context files");
5329
+ mcpCmd.command("setup").description("Install .mcp.json + CLAUDE.md + AGENTS.md + .cursorrules into the current theme").option("-y, --yes", "Skip confirmation prompts").action(mcpSetupCommand);
5330
+ mcpCmd.command("upgrade").description("Refresh AI-context files to the latest version from the bundled template").option("-y, --yes", "Skip confirmation prompts").action(mcpUpgradeCommand);
5331
+ mcpCmd.command("doctor").description("Diagnose MCP setup in the current theme directory").action(mcpDoctorCommand);
5124
5332
  program.command("publish").description("Build, scan, and publish theme to marketplace (requires login)").option("-t, --theme <path>", "Theme directory path").option(
5125
5333
  "--bump <type>",
5126
5334
  "Auto-bump version before publish (patch|minor|major)"