rulesync 8.10.0 → 8.12.0

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.
@@ -1039,10 +1039,6 @@ var JsonLogger = class extends BaseLogger {
1039
1039
  }
1040
1040
  };
1041
1041
 
1042
- // src/lib/generate.ts
1043
- import { join as join145 } from "path";
1044
- import { intersection } from "es-toolkit";
1045
-
1046
1042
  // src/features/commands/commands-processor.ts
1047
1043
  import { basename as basename2, join as join22, relative as relative3 } from "path";
1048
1044
  import { z as z16 } from "zod/mini";
@@ -4200,7 +4196,8 @@ var CODEXCLI_HOOK_EVENTS = [
4200
4196
  "preToolUse",
4201
4197
  "postToolUse",
4202
4198
  "beforeSubmitPrompt",
4203
- "stop"
4199
+ "stop",
4200
+ "permissionRequest"
4204
4201
  ];
4205
4202
  var hooksRecordSchema = z17.record(z17.string(), z17.array(HookDefinitionSchema));
4206
4203
  var HooksConfigSchema = z17.looseObject({
@@ -4317,7 +4314,8 @@ var CANONICAL_TO_CODEXCLI_EVENT_NAMES = {
4317
4314
  preToolUse: "PreToolUse",
4318
4315
  postToolUse: "PostToolUse",
4319
4316
  beforeSubmitPrompt: "UserPromptSubmit",
4320
- stop: "Stop"
4317
+ stop: "Stop",
4318
+ permissionRequest: "PermissionRequest"
4321
4319
  };
4322
4320
  var CODEXCLI_TO_CANONICAL_EVENT_NAMES = Object.fromEntries(
4323
4321
  Object.entries(CANONICAL_TO_CODEXCLI_EVENT_NAMES).map(([k, v]) => [v, k])
@@ -19229,9 +19227,7 @@ var CopilotRule = class _CopilotRule extends ToolRule {
19229
19227
  }
19230
19228
  toRulesyncRule() {
19231
19229
  let globs;
19232
- if (this.isRoot()) {
19233
- globs = ["**/*"];
19234
- } else if (this.frontmatter.applyTo) {
19230
+ if (this.frontmatter.applyTo) {
19235
19231
  globs = this.frontmatter.applyTo.split(",").map((g) => g.trim());
19236
19232
  }
19237
19233
  const rulesyncFrontmatter = {
@@ -19272,7 +19268,7 @@ var CopilotRule = class _CopilotRule extends ToolRule {
19272
19268
  if (root) {
19273
19269
  return new _CopilotRule({
19274
19270
  baseDir,
19275
- frontmatter: copilotFrontmatter,
19271
+ frontmatter: {},
19276
19272
  body,
19277
19273
  relativeDirPath: paths.root.relativeDirPath,
19278
19274
  relativeFilePath: paths.root.relativeFilePath,
@@ -19298,12 +19294,14 @@ var CopilotRule = class _CopilotRule extends ToolRule {
19298
19294
  }
19299
19295
  static async fromFile({
19300
19296
  baseDir = process.cwd(),
19297
+ relativeDirPath,
19301
19298
  relativeFilePath,
19302
19299
  validate = true,
19303
19300
  global = false
19304
19301
  }) {
19305
19302
  const paths = this.getSettablePaths({ global });
19306
- const isRoot = relativeFilePath === paths.root.relativeFilePath;
19303
+ const isRoot = relativeDirPath ? join126(relativeDirPath, relativeFilePath) === join126(paths.root.relativeDirPath, paths.root.relativeFilePath) : relativeFilePath === paths.root.relativeFilePath;
19304
+ const resolvedRelativeDirPath = relativeDirPath ?? (isRoot ? paths.root.relativeDirPath : paths.nonRoot?.relativeDirPath ?? paths.root.relativeDirPath);
19307
19305
  if (isRoot) {
19308
19306
  const relativePath2 = join126(paths.root.relativeDirPath, paths.root.relativeFilePath);
19309
19307
  const filePath2 = join126(baseDir, relativePath2);
@@ -19321,7 +19319,7 @@ var CopilotRule = class _CopilotRule extends ToolRule {
19321
19319
  if (!paths.nonRoot) {
19322
19320
  throw new Error(`nonRoot path is not set for ${relativeFilePath}`);
19323
19321
  }
19324
- const relativePath = join126(paths.nonRoot.relativeDirPath, relativeFilePath);
19322
+ const relativePath = join126(resolvedRelativeDirPath, relativeFilePath);
19325
19323
  const filePath = join126(baseDir, relativePath);
19326
19324
  const fileContent = await readFileContent(filePath);
19327
19325
  const { frontmatter, body: content } = parseFrontmatter(fileContent, filePath);
@@ -19331,7 +19329,7 @@ var CopilotRule = class _CopilotRule extends ToolRule {
19331
19329
  }
19332
19330
  return new _CopilotRule({
19333
19331
  baseDir,
19334
- relativeDirPath: paths.nonRoot.relativeDirPath,
19332
+ relativeDirPath: resolvedRelativeDirPath,
19335
19333
  relativeFilePath: relativeFilePath.endsWith(".instructions.md") ? relativeFilePath : relativeFilePath.replace(/\.md$/, ".instructions.md"),
19336
19334
  frontmatter: result.data,
19337
19335
  body: content.trim(),
@@ -19346,7 +19344,7 @@ var CopilotRule = class _CopilotRule extends ToolRule {
19346
19344
  global = false
19347
19345
  }) {
19348
19346
  const paths = this.getSettablePaths({ global });
19349
- const isRoot = relativeFilePath === paths.root.relativeFilePath;
19347
+ const isRoot = join126(relativeDirPath, relativeFilePath) === join126(paths.root.relativeDirPath, paths.root.relativeFilePath);
19350
19348
  return new _CopilotRule({
19351
19349
  baseDir,
19352
19350
  relativeDirPath,
@@ -22301,7 +22299,239 @@ ${toonContent}`;
22301
22299
  }
22302
22300
  };
22303
22301
 
22302
+ // src/lib/convert.ts
22303
+ async function convertFromTool(params) {
22304
+ const ctx = params;
22305
+ const [
22306
+ rulesCount,
22307
+ ignoreCount,
22308
+ mcpCount,
22309
+ commandsCount,
22310
+ subagentsCount,
22311
+ skillsCount,
22312
+ hooksCount,
22313
+ permissionsCount
22314
+ ] = [
22315
+ await runFeatureConvert(ctx, buildRulesStrategy(ctx)),
22316
+ await runFeatureConvert(ctx, buildIgnoreStrategy(ctx)),
22317
+ await runFeatureConvert(ctx, buildMcpStrategy(ctx)),
22318
+ await runFeatureConvert(ctx, buildCommandsStrategy(ctx)),
22319
+ await runFeatureConvert(ctx, buildSubagentsStrategy(ctx)),
22320
+ await runFeatureConvert(ctx, buildSkillsStrategy(ctx)),
22321
+ await runFeatureConvert(ctx, buildHooksStrategy(ctx)),
22322
+ await runFeatureConvert(ctx, buildPermissionsStrategy(ctx))
22323
+ ];
22324
+ return {
22325
+ rulesCount,
22326
+ ignoreCount,
22327
+ mcpCount,
22328
+ commandsCount,
22329
+ subagentsCount,
22330
+ skillsCount,
22331
+ hooksCount,
22332
+ permissionsCount
22333
+ };
22334
+ }
22335
+ async function runFeatureConvert(ctx, strategy) {
22336
+ if (!strategy) return 0;
22337
+ const { config, fromTool, toTools, logger } = ctx;
22338
+ const {
22339
+ feature,
22340
+ itemLabel,
22341
+ allTargets,
22342
+ importableTargets = allTargets,
22343
+ createProcessor,
22344
+ loadSource,
22345
+ toRulesync,
22346
+ fromRulesync,
22347
+ write
22348
+ } = strategy;
22349
+ if (!config.getFeatures(fromTool).includes(feature)) {
22350
+ return 0;
22351
+ }
22352
+ if (!allTargets.includes(fromTool)) {
22353
+ logger.warn(`Source tool '${fromTool}' does not support feature '${feature}'. Skipping.`);
22354
+ return 0;
22355
+ }
22356
+ if (!importableTargets.includes(fromTool)) {
22357
+ logger.warn(`Conversion from ${fromTool} ${feature} is not supported. Skipping.`);
22358
+ return 0;
22359
+ }
22360
+ const sourceProcessor = createProcessor({ toolTarget: fromTool, dryRun: false });
22361
+ const sourceItems = await loadSource(sourceProcessor);
22362
+ if (sourceItems.length === 0) {
22363
+ logger.warn(`No ${feature} files found for ${fromTool}. Skipping ${feature} conversion.`);
22364
+ return 0;
22365
+ }
22366
+ const rulesyncItems = await toRulesync(sourceProcessor, sourceItems);
22367
+ let totalCount = 0;
22368
+ for (const toTool of toTools) {
22369
+ if (!allTargets.includes(toTool)) {
22370
+ logger.warn(`Destination tool '${toTool}' does not support feature '${feature}'. Skipping.`);
22371
+ continue;
22372
+ }
22373
+ const destProcessor = createProcessor({
22374
+ toolTarget: toTool,
22375
+ dryRun: config.isPreviewMode()
22376
+ });
22377
+ const destItems = await fromRulesync(destProcessor, rulesyncItems);
22378
+ const { count } = await write(destProcessor, destItems);
22379
+ totalCount += count;
22380
+ if (config.getVerbose() && count > 0) {
22381
+ const verb = config.isPreviewMode() ? "Would convert" : "Converted";
22382
+ logger.success(`${verb} ${count} ${itemLabel} for ${toTool}`);
22383
+ }
22384
+ }
22385
+ return totalCount;
22386
+ }
22387
+ function getBaseDir(config) {
22388
+ return config.getBaseDirs()[0] ?? ".";
22389
+ }
22390
+ function buildRulesStrategy(ctx) {
22391
+ const { config, logger } = ctx;
22392
+ const global = config.getGlobal();
22393
+ const baseDir = getBaseDir(config);
22394
+ const allTargets = RulesProcessor.getToolTargets({ global });
22395
+ return {
22396
+ feature: "rules",
22397
+ itemLabel: "rule file(s)",
22398
+ allTargets,
22399
+ createProcessor: ({ toolTarget, dryRun }) => new RulesProcessor({ baseDir, toolTarget, global, dryRun, logger }),
22400
+ loadSource: (p) => p.loadToolFiles(),
22401
+ toRulesync: (p, files) => p.convertToolFilesToRulesyncFiles(files),
22402
+ fromRulesync: (p, files) => p.convertRulesyncFilesToToolFiles(files),
22403
+ write: (p, files) => p.writeAiFiles(files)
22404
+ };
22405
+ }
22406
+ function buildIgnoreStrategy(ctx) {
22407
+ const { config, logger } = ctx;
22408
+ if (config.getGlobal()) {
22409
+ logger.debug("Skipping ignore conversion (not supported in global mode)");
22410
+ return null;
22411
+ }
22412
+ const baseDir = getBaseDir(config);
22413
+ const allTargets = IgnoreProcessor.getToolTargets();
22414
+ return {
22415
+ feature: "ignore",
22416
+ itemLabel: "ignore file(s)",
22417
+ allTargets,
22418
+ createProcessor: ({ toolTarget, dryRun }) => new IgnoreProcessor({
22419
+ baseDir,
22420
+ toolTarget,
22421
+ dryRun,
22422
+ logger,
22423
+ featureOptions: config.getFeatureOptions(toolTarget, "ignore")
22424
+ }),
22425
+ loadSource: (p) => p.loadToolFiles(),
22426
+ toRulesync: (p, files) => p.convertToolFilesToRulesyncFiles(files),
22427
+ fromRulesync: (p, files) => p.convertRulesyncFilesToToolFiles(files),
22428
+ write: (p, files) => p.writeAiFiles(files)
22429
+ };
22430
+ }
22431
+ function buildMcpStrategy(ctx) {
22432
+ const { config, logger } = ctx;
22433
+ const global = config.getGlobal();
22434
+ const baseDir = getBaseDir(config);
22435
+ const allTargets = McpProcessor.getToolTargets({ global });
22436
+ return {
22437
+ feature: "mcp",
22438
+ itemLabel: "MCP file(s)",
22439
+ allTargets,
22440
+ createProcessor: ({ toolTarget, dryRun }) => new McpProcessor({ baseDir, toolTarget, global, dryRun, logger }),
22441
+ loadSource: (p) => p.loadToolFiles(),
22442
+ toRulesync: (p, files) => p.convertToolFilesToRulesyncFiles(files),
22443
+ fromRulesync: (p, files) => p.convertRulesyncFilesToToolFiles(files),
22444
+ write: (p, files) => p.writeAiFiles(files)
22445
+ };
22446
+ }
22447
+ function buildCommandsStrategy(ctx) {
22448
+ const { config, logger } = ctx;
22449
+ const global = config.getGlobal();
22450
+ const baseDir = getBaseDir(config);
22451
+ const allTargets = CommandsProcessor.getToolTargets({ global, includeSimulated: false });
22452
+ return {
22453
+ feature: "commands",
22454
+ itemLabel: "command file(s)",
22455
+ allTargets,
22456
+ createProcessor: ({ toolTarget, dryRun }) => new CommandsProcessor({ baseDir, toolTarget, global, dryRun, logger }),
22457
+ loadSource: (p) => p.loadToolFiles(),
22458
+ toRulesync: (p, files) => p.convertToolFilesToRulesyncFiles(files),
22459
+ fromRulesync: (p, files) => p.convertRulesyncFilesToToolFiles(files),
22460
+ write: (p, files) => p.writeAiFiles(files)
22461
+ };
22462
+ }
22463
+ function buildSubagentsStrategy(ctx) {
22464
+ const { config, logger } = ctx;
22465
+ const global = config.getGlobal();
22466
+ const baseDir = getBaseDir(config);
22467
+ const allTargets = SubagentsProcessor.getToolTargets({ global, includeSimulated: false });
22468
+ return {
22469
+ feature: "subagents",
22470
+ itemLabel: "subagent file(s)",
22471
+ allTargets,
22472
+ createProcessor: ({ toolTarget, dryRun }) => new SubagentsProcessor({ baseDir, toolTarget, global, dryRun, logger }),
22473
+ loadSource: (p) => p.loadToolFiles(),
22474
+ toRulesync: (p, files) => p.convertToolFilesToRulesyncFiles(files),
22475
+ fromRulesync: (p, files) => p.convertRulesyncFilesToToolFiles(files),
22476
+ write: (p, files) => p.writeAiFiles(files)
22477
+ };
22478
+ }
22479
+ function buildSkillsStrategy(ctx) {
22480
+ const { config, logger } = ctx;
22481
+ const global = config.getGlobal();
22482
+ const baseDir = getBaseDir(config);
22483
+ const allTargets = SkillsProcessor.getToolTargets({ global });
22484
+ return {
22485
+ feature: "skills",
22486
+ itemLabel: "skill(s)",
22487
+ allTargets,
22488
+ createProcessor: ({ toolTarget, dryRun }) => new SkillsProcessor({ baseDir, toolTarget, global, dryRun, logger }),
22489
+ loadSource: (p) => p.loadToolDirs(),
22490
+ toRulesync: (p, dirs) => p.convertToolDirsToRulesyncDirs(dirs),
22491
+ fromRulesync: (p, dirs) => p.convertRulesyncDirsToToolDirs(dirs),
22492
+ write: (p, dirs) => p.writeAiDirs(dirs)
22493
+ };
22494
+ }
22495
+ function buildHooksStrategy(ctx) {
22496
+ const { config, logger } = ctx;
22497
+ const global = config.getGlobal();
22498
+ const baseDir = getBaseDir(config);
22499
+ const allTargets = HooksProcessor.getToolTargets({ global });
22500
+ const importableTargets = HooksProcessor.getToolTargets({ global, importOnly: true });
22501
+ return {
22502
+ feature: "hooks",
22503
+ itemLabel: "hooks file(s)",
22504
+ allTargets,
22505
+ importableTargets,
22506
+ createProcessor: ({ toolTarget, dryRun }) => new HooksProcessor({ baseDir, toolTarget, global, dryRun, logger }),
22507
+ loadSource: (p) => p.loadToolFiles(),
22508
+ toRulesync: (p, files) => p.convertToolFilesToRulesyncFiles(files),
22509
+ fromRulesync: (p, files) => p.convertRulesyncFilesToToolFiles(files),
22510
+ write: (p, files) => p.writeAiFiles(files)
22511
+ };
22512
+ }
22513
+ function buildPermissionsStrategy(ctx) {
22514
+ const { config, logger } = ctx;
22515
+ const global = config.getGlobal();
22516
+ const baseDir = getBaseDir(config);
22517
+ const allTargets = PermissionsProcessor.getToolTargets({ global });
22518
+ const importableTargets = PermissionsProcessor.getToolTargets({ global, importOnly: true });
22519
+ return {
22520
+ feature: "permissions",
22521
+ itemLabel: "permissions file(s)",
22522
+ allTargets,
22523
+ importableTargets,
22524
+ createProcessor: ({ toolTarget, dryRun }) => new PermissionsProcessor({ baseDir, toolTarget, global, dryRun, logger }),
22525
+ loadSource: (p) => p.loadToolFiles(),
22526
+ toRulesync: (p, files) => p.convertToolFilesToRulesyncFiles(files),
22527
+ fromRulesync: (p, files) => p.convertRulesyncFilesToToolFiles(files),
22528
+ write: (p, files) => p.writeAiFiles(files)
22529
+ };
22530
+ }
22531
+
22304
22532
  // src/lib/generate.ts
22533
+ import { join as join145 } from "path";
22534
+ import { intersection } from "es-toolkit";
22305
22535
  async function processFeatureGeneration(params) {
22306
22536
  const { config, processor, toolFiles } = params;
22307
22537
  let totalCount = 0;
@@ -23054,7 +23284,6 @@ export {
23054
23284
  CLIError,
23055
23285
  ConsoleLogger,
23056
23286
  JsonLogger,
23057
- PermissionsProcessor,
23058
23287
  SKILL_FILE_NAME,
23059
23288
  RulesyncSkillFrontmatterSchema,
23060
23289
  RulesyncSkill,
@@ -23066,6 +23295,7 @@ export {
23066
23295
  RulesyncRuleFrontmatterSchema,
23067
23296
  RulesyncRule,
23068
23297
  RulesProcessor,
23298
+ convertFromTool,
23069
23299
  checkRulesyncDirExists,
23070
23300
  generate,
23071
23301
  importFromTool