agentsmesh 0.20.0 → 0.22.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.
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { z } from 'zod';
2
- import { stringify, parse } from 'yaml';
3
- import { join, basename, dirname, relative, win32, posix, sep, extname, resolve } from 'path';
2
+ import { parse, stringify } from 'yaml';
3
+ import { join, relative, sep, dirname, isAbsolute, resolve, basename, win32, posix, extname } from 'path';
4
4
  import { access, readdir, readFile, realpath, stat, rm, mkdir, lstat, unlink, writeFile, rename, chmod, mkdtemp, cp } from 'fs/promises';
5
- import { constants, existsSync, realpathSync, statSync, readFileSync } from 'fs';
5
+ import { existsSync, readFileSync, writeFileSync, mkdirSync, appendFileSync, constants, realpathSync, statSync } from 'fs';
6
6
  import { parse as parse$1 } from 'smol-toml';
7
7
  import { Buffer } from 'buffer';
8
8
  import { homedir, tmpdir } from 'os';
@@ -12,6 +12,7 @@ import { fileURLToPath, pathToFileURL, URL } from 'url';
12
12
  import { promisify } from 'util';
13
13
  import * as tar from 'tar';
14
14
  import { createTwoFilesPatch } from 'diff';
15
+ import picomatch from 'picomatch';
15
16
 
16
17
  var __defProp = Object.defineProperty;
17
18
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -768,6 +769,33 @@ async function readDirRecursive(dir, visited, branchSegments) {
768
769
  );
769
770
  }
770
771
  }
772
+ async function readDirRecursiveNoSymlinks(dir, branchSegments) {
773
+ const currentBranchSegments = branchSegments ?? [basename(dir)];
774
+ try {
775
+ const entries = await readdir(dir, { withFileTypes: true });
776
+ const files = [];
777
+ for (const ent of entries) {
778
+ if (ent.isSymbolicLink()) continue;
779
+ const full = join(dir, ent.name);
780
+ if (ent.isDirectory()) {
781
+ const nextSegments = [...currentBranchSegments, ent.name];
782
+ if (shouldSkipRecursiveBranch(nextSegments)) continue;
783
+ files.push(...await readDirRecursiveNoSymlinks(full, nextSegments));
784
+ } else if (ent.isFile()) {
785
+ files.push(full);
786
+ }
787
+ }
788
+ return files;
789
+ } catch (err) {
790
+ const e = err;
791
+ if (e.code === "ENOENT" || e.code === "ENOTDIR" || e.code === "EACCES") return [];
792
+ throw new FileSystemError(
793
+ dir,
794
+ `Failed to read directory ${dir}: ${e.message}. Check permissions.`,
795
+ { cause: err, errnoCode: e.code }
796
+ );
797
+ }
798
+ }
771
799
  var MAX_RECURSIVE_DEPTH, MAX_SEGMENT_REPETITIONS;
772
800
  var init_fs_traverse = __esm({
773
801
  "src/utils/filesystem/fs-traverse.ts"() {
@@ -1022,7 +1050,7 @@ ${legacy}`, "");
1022
1050
  }
1023
1051
  return result.trim();
1024
1052
  }
1025
- var ROOT_INSTRUCTION_BODY_V1, ROOT_INSTRUCTION_BODY_V2, ROOT_INSTRUCTION_BODY_V3, ROOT_INSTRUCTION_BODY_V4, ROOT_INSTRUCTION_BODY_V5, ROOT_INSTRUCTION_BODY_V6, ROOT_INSTRUCTION_BODY_V7, ROOT_INSTRUCTION_BODY_V8, ROOT_INSTRUCTION_BODY, LEGACY_AGENTSMESH_ROOT_INSTRUCTION_PARAGRAPH, LEGACY_AGENTSMESH_ROOT_INSTRUCTION_SECTION, AGENTSMESH_CONTRACT_WITH_V1_BODY, AGENTSMESH_CONTRACT_WITH_V2_BODY, AGENTSMESH_CONTRACT_WITH_V3_BODY, AGENTSMESH_CONTRACT_WITH_V4_BODY, AGENTSMESH_CONTRACT_WITH_V5_BODY, AGENTSMESH_CONTRACT_WITH_V6_BODY, AGENTSMESH_CONTRACT_WITH_V7_BODY, AGENTSMESH_CONTRACT_WITH_V8_BODY, AGENTSMESH_ROOT_INSTRUCTION_PARAGRAPH, LEGACY_FORMS;
1053
+ var ROOT_INSTRUCTION_BODY_V1, ROOT_INSTRUCTION_BODY_V2, ROOT_INSTRUCTION_BODY_V3, ROOT_INSTRUCTION_BODY_V4, ROOT_INSTRUCTION_BODY_V5, ROOT_INSTRUCTION_BODY_V6, ROOT_INSTRUCTION_BODY_V7, ROOT_INSTRUCTION_BODY_V8, ROOT_INSTRUCTION_BODY_V9, ROOT_INSTRUCTION_BODY_V10, ROOT_INSTRUCTION_BODY, LEGACY_AGENTSMESH_ROOT_INSTRUCTION_PARAGRAPH, LEGACY_AGENTSMESH_ROOT_INSTRUCTION_SECTION, AGENTSMESH_CONTRACT_WITH_V1_BODY, AGENTSMESH_CONTRACT_WITH_V2_BODY, AGENTSMESH_CONTRACT_WITH_V3_BODY, AGENTSMESH_CONTRACT_WITH_V4_BODY, AGENTSMESH_CONTRACT_WITH_V5_BODY, AGENTSMESH_CONTRACT_WITH_V6_BODY, AGENTSMESH_CONTRACT_WITH_V7_BODY, AGENTSMESH_CONTRACT_WITH_V8_BODY, AGENTSMESH_CONTRACT_WITH_V9_BODY, AGENTSMESH_CONTRACT_WITH_V10_BODY, AGENTSMESH_ROOT_INSTRUCTION_PARAGRAPH, LEGACY_FORMS;
1026
1054
  var init_root_instruction_paragraph = __esm({
1027
1055
  "src/targets/projection/root-instruction-paragraph.ts"() {
1028
1056
  init_managed_blocks();
@@ -1034,7 +1062,9 @@ var init_root_instruction_paragraph = __esm({
1034
1062
  ROOT_INSTRUCTION_BODY_V6 = "Create canonical files in `.agentsmesh`: `rules/_root.md` and `rules/*.md` are Markdown rules; `commands/*.md`, `agents/*.md`, and `skills/*/SKILL.md` plus supporting files use Claude-style frontmatter Markdown; `mcp.json` is MCP JSON; `hooks.yaml` and `permissions.yaml` are YAML; `ignore` is gitignore-style text. Then run `agentsmesh generate`.";
1035
1063
  ROOT_INSTRUCTION_BODY_V7 = "`.agentsmesh` is the only folder you edit or add these files in: `rules/_root.md` and `rules/*.md` are Markdown rules; `commands/*.md`, `agents/*.md`, and `skills/*/SKILL.md` plus supporting files use Claude-style frontmatter Markdown; `mcp.json` is MCP JSON; `hooks.yaml` and `permissions.yaml` are YAML; `ignore` is gitignore-style text. Do not edit generated tool files; run `agentsmesh generate`.";
1036
1064
  ROOT_INSTRUCTION_BODY_V8 = "`agentsmesh.yaml` selects targets/features (`agentsmesh.local.yaml` overrides locally), and `.agentsmesh` is the only place to add or edit canonical items: `rules/_root.md`, `rules/*.md`, `commands/*.md`, `agents/*.md`, `skills/*/SKILL.md` plus supporting files, `mcp.json`, `hooks.yaml`, `permissions.yaml`, and `ignore`; if missing run `agentsmesh init`, use `agentsmesh import --from <tool>` for native configs, `agentsmesh install <source>` or `install --sync` for reusable packs, then run `agentsmesh generate`. Use `diff`, `lint`, `check`, `watch`, `matrix`, and `merge` as needed; never edit generated tool files.";
1037
- ROOT_INSTRUCTION_BODY = "`agentsmesh.yaml` selects targets/features (`agentsmesh.local.yaml` overrides locally), and `.agentsmesh` is the only place to add or edit canonical items: `rules/_root.md`, `rules/*.md`, `commands/*.md`, `agents/*.md`, `skills/*/SKILL.md` plus supporting files, `mcp.json`, `hooks.yaml`, `permissions.yaml`, and `ignore`; if missing run `agentsmesh init`, use `agentsmesh import --from <tool>` for native configs, `agentsmesh install <source>` or `install --sync` for reusable packs, then run `agentsmesh generate`. Use `diff`, `lint`, `check`, `watch`, `matrix`, `merge`, and `refresh` as needed; never edit generated tool files.";
1065
+ ROOT_INSTRUCTION_BODY_V9 = "`agentsmesh.yaml` selects targets/features (`agentsmesh.local.yaml` overrides locally), and `.agentsmesh` is the only place to add or edit canonical items: `rules/_root.md`, `rules/*.md`, `commands/*.md`, `agents/*.md`, `skills/*/SKILL.md` plus supporting files, `mcp.json`, `hooks.yaml`, `permissions.yaml`, and `ignore`; if missing run `agentsmesh init`, use `agentsmesh import --from <tool>` for native configs, `agentsmesh install <source>` or `install --sync` for reusable packs, then run `agentsmesh generate`. Use `diff`, `lint`, `check`, `watch`, `matrix`, `merge`, and `refresh` as needed; never edit generated tool files.";
1066
+ ROOT_INSTRUCTION_BODY_V10 = "**MUST follow when changing any rule, agent, command, skill, hook, MCP server, permission, or ignore pattern.** `agentsmesh.yaml` selects targets/features (`agentsmesh.local.yaml` overrides locally), and `.agentsmesh` is the only place to add or edit canonical items: `rules/_root.md`, `rules/*.md`, `commands/*.md`, `agents/*.md`, `skills/*/SKILL.md` plus supporting files, `mcp.json`, `hooks.yaml`, `permissions.yaml`, and `ignore`; if missing run `agentsmesh init`, use `agentsmesh import --from <tool>` for native configs, `agentsmesh install <source>` or `install --sync` for reusable packs, then run `agentsmesh generate`. Use `diff`, `lint`, `check`, `watch`, `matrix`, `merge`, and `refresh` as needed; never edit generated tool files.";
1067
+ ROOT_INSTRUCTION_BODY = "**NEVER edit generated files** (`.claude/`, `.cursor/`, `AGENTS.md`, `.github/copilot-instructions.md`, and similar target outputs) \u2014 `agentsmesh generate` overwrites them. **All changes MUST go through `.agentsmesh` first**: edit `rules/_root.md`, `rules/*.md`, `commands/*.md`, `agents/*.md`, `skills/*/SKILL.md` plus supporting files, `mcp.json`, `hooks.yaml`, `permissions.yaml`, and `ignore`; `agentsmesh.yaml` selects targets/features (`agentsmesh.local.yaml` overrides locally); if missing run `agentsmesh init`, use `agentsmesh import --from <tool>` for native configs, `agentsmesh install <source>` or `install --sync` for reusable packs, then run `agentsmesh generate`. Use `diff`, `lint`, `check`, `watch`, `matrix`, `merge`, and `refresh` as needed.";
1038
1068
  LEGACY_AGENTSMESH_ROOT_INSTRUCTION_PARAGRAPH = ROOT_INSTRUCTION_BODY_V1;
1039
1069
  LEGACY_AGENTSMESH_ROOT_INSTRUCTION_SECTION = `## Project-Specific Rules
1040
1070
 
@@ -1063,12 +1093,20 @@ ${ROOT_INSTRUCTION_BODY_V7}`;
1063
1093
  AGENTSMESH_CONTRACT_WITH_V8_BODY = `## AgentsMesh Generation Contract
1064
1094
 
1065
1095
  ${ROOT_INSTRUCTION_BODY_V8}`;
1096
+ AGENTSMESH_CONTRACT_WITH_V9_BODY = `## AgentsMesh Generation Contract
1097
+
1098
+ ${ROOT_INSTRUCTION_BODY_V9}`;
1099
+ AGENTSMESH_CONTRACT_WITH_V10_BODY = `## AgentsMesh Generation Contract
1100
+
1101
+ ${ROOT_INSTRUCTION_BODY_V10}`;
1066
1102
  AGENTSMESH_ROOT_INSTRUCTION_PARAGRAPH = `${ROOT_CONTRACT_START}
1067
1103
  ## AgentsMesh Generation Contract
1068
1104
 
1069
1105
  ${ROOT_INSTRUCTION_BODY}
1070
1106
  ${ROOT_CONTRACT_END}`;
1071
1107
  LEGACY_FORMS = [
1108
+ AGENTSMESH_CONTRACT_WITH_V10_BODY,
1109
+ AGENTSMESH_CONTRACT_WITH_V9_BODY,
1072
1110
  AGENTSMESH_CONTRACT_WITH_V8_BODY,
1073
1111
  AGENTSMESH_CONTRACT_WITH_V7_BODY,
1074
1112
  AGENTSMESH_CONTRACT_WITH_V6_BODY,
@@ -1248,7 +1286,7 @@ function generateEmbeddedSkills(canonical, skillsDir) {
1248
1286
  }
1249
1287
  return outputs;
1250
1288
  }
1251
- async function importEmbeddedSkills(projectRoot, skillsDir, fromTool, results, normalize) {
1289
+ async function importEmbeddedSkills(projectRoot, skillsDir, fromTool, results, normalize2) {
1252
1290
  const entries = await readdir(join(projectRoot, skillsDir), {
1253
1291
  encoding: "utf8",
1254
1292
  withFileTypes: true
@@ -1263,7 +1301,7 @@ async function importEmbeddedSkills(projectRoot, skillsDir, fromTool, results, n
1263
1301
  const destinationSkillDir = join(projectRoot, AB_SKILLS, entry.name);
1264
1302
  const destinationSkillFile = join(destinationSkillDir, "SKILL.md");
1265
1303
  const { frontmatter, body } = parseFrontmatter(
1266
- normalize(sourceSkillContent, sourceSkillFile, destinationSkillFile)
1304
+ normalize2(sourceSkillContent, sourceSkillFile, destinationSkillFile)
1267
1305
  );
1268
1306
  const projectedCommand = parseCommandSkillFrontmatter(frontmatter, entry.name);
1269
1307
  if (projectedCommand) {
@@ -1273,7 +1311,7 @@ async function importEmbeddedSkills(projectRoot, skillsDir, fromTool, results, n
1273
1311
  const commandPath = join(destDir, `${projectedCommand.name}.md`);
1274
1312
  await writeFileAtomic(
1275
1313
  commandPath,
1276
- serializeImportedCommand(projectedCommand, normalize(body, sourceSkillFile, commandPath))
1314
+ serializeImportedCommand(projectedCommand, normalize2(body, sourceSkillFile, commandPath))
1277
1315
  );
1278
1316
  results.push({
1279
1317
  fromTool,
@@ -1291,7 +1329,7 @@ async function importEmbeddedSkills(projectRoot, skillsDir, fromTool, results, n
1291
1329
  const agentPath = join(destDir, `${projectedAgent.name}.md`);
1292
1330
  await writeFileAtomic(
1293
1331
  agentPath,
1294
- serializeImportedAgent(projectedAgent, normalize(body, sourceSkillFile, agentPath))
1332
+ serializeImportedAgent(projectedAgent, normalize2(body, sourceSkillFile, agentPath))
1295
1333
  );
1296
1334
  results.push({
1297
1335
  fromTool,
@@ -1322,7 +1360,7 @@ async function importEmbeddedSkills(projectRoot, skillsDir, fromTool, results, n
1322
1360
  if (sourceContent === null) continue;
1323
1361
  const destinationPath = join(destinationSkillDir, relativePath);
1324
1362
  await mkdirp(dirname(destinationPath));
1325
- await writeFileAtomic(destinationPath, normalize(sourceContent, sourcePath, destinationPath));
1363
+ await writeFileAtomic(destinationPath, normalize2(sourceContent, sourcePath, destinationPath));
1326
1364
  results.push({
1327
1365
  fromTool,
1328
1366
  fromPath: sourcePath,
@@ -2479,7 +2517,7 @@ var init_import_descriptor = __esm({
2479
2517
  ];
2480
2518
  }
2481
2519
  });
2482
- async function runSingleFile(spec, sources, projectRoot, fromTool, normalize) {
2520
+ async function runSingleFile(spec, sources, projectRoot, fromTool, normalize2) {
2483
2521
  if (!spec.canonicalRootFilename) {
2484
2522
  throw new Error(`singleFile spec for ${spec.feature} must set canonicalRootFilename`);
2485
2523
  }
@@ -2490,7 +2528,7 @@ async function runSingleFile(spec, sources, projectRoot, fromTool, normalize) {
2490
2528
  if (content === null) continue;
2491
2529
  await mkdirp(destDir);
2492
2530
  const destPath = join(destDir, spec.canonicalRootFilename);
2493
- const normalizeTo = (destinationFile) => normalize(content, srcPath, destinationFile);
2531
+ const normalizeTo = (destinationFile) => normalize2(content, srcPath, destinationFile);
2494
2532
  if (spec.map) {
2495
2533
  let mapping;
2496
2534
  try {
@@ -2533,7 +2571,7 @@ async function runSingleFile(spec, sources, projectRoot, fromTool, normalize) {
2533
2571
  }
2534
2572
  return [];
2535
2573
  }
2536
- async function runDirectory(spec, sources, projectRoot, fromTool, normalize) {
2574
+ async function runDirectory(spec, sources, projectRoot, fromTool, normalize2) {
2537
2575
  const mapper = resolveMapper(spec);
2538
2576
  const destDir = join(projectRoot, spec.canonicalDir);
2539
2577
  const results = [];
@@ -2544,7 +2582,7 @@ async function runDirectory(spec, sources, projectRoot, fromTool, normalize) {
2544
2582
  destDir,
2545
2583
  extensions: [...spec.extensions ?? [".md"]],
2546
2584
  fromTool,
2547
- normalize,
2585
+ normalize: normalize2,
2548
2586
  mapEntry: async ({ srcPath, relativePath, content, normalizeTo }) => {
2549
2587
  if (isPreservedBoilerplate(basename(srcPath))) return null;
2550
2588
  let mapping;
@@ -2649,28 +2687,28 @@ async function runMcpJson(spec, sources, projectRoot, fromTool) {
2649
2687
  }
2650
2688
  return [];
2651
2689
  }
2652
- function dispatchSpec(spec, sources, projectRoot, fromTool, normalize) {
2690
+ function dispatchSpec(spec, sources, projectRoot, fromTool, normalize2) {
2653
2691
  switch (spec.mode) {
2654
2692
  case "singleFile":
2655
- return runSingleFile(spec, sources, projectRoot, fromTool, normalize);
2693
+ return runSingleFile(spec, sources, projectRoot, fromTool, normalize2);
2656
2694
  case "directory":
2657
- return runDirectory(spec, sources, projectRoot, fromTool, normalize);
2695
+ return runDirectory(spec, sources, projectRoot, fromTool, normalize2);
2658
2696
  case "flatFile":
2659
2697
  return runFlatFile(spec, sources, projectRoot, fromTool);
2660
2698
  case "mcpJson":
2661
2699
  return runMcpJson(spec, sources, projectRoot, fromTool);
2662
2700
  }
2663
2701
  }
2664
- async function runSpec(spec, scope, projectRoot, fromTool, normalize) {
2702
+ async function runSpec(spec, scope, projectRoot, fromTool, normalize2) {
2665
2703
  const primary = resolveScopedSources(spec.source, scope);
2666
2704
  const fallback = resolveScopedSources(spec.fallbacks, scope);
2667
2705
  if (primary.length === 0 && fallback.length === 0) return [];
2668
2706
  if (primary.length > 0) {
2669
- const results = await dispatchSpec(spec, primary, projectRoot, fromTool, normalize);
2707
+ const results = await dispatchSpec(spec, primary, projectRoot, fromTool, normalize2);
2670
2708
  if (results.length > 0) return results;
2671
2709
  }
2672
2710
  if (fallback.length > 0) {
2673
- return dispatchSpec(spec, fallback, projectRoot, fromTool, normalize);
2711
+ return dispatchSpec(spec, fallback, projectRoot, fromTool, normalize2);
2674
2712
  }
2675
2713
  return [];
2676
2714
  }
@@ -2683,11 +2721,11 @@ function specsForFeature(importer, feature) {
2683
2721
  async function runDescriptorImport(descriptor31, projectRoot, scope, options) {
2684
2722
  const importer = descriptor31.importer;
2685
2723
  if (!importer) return [];
2686
- const normalize = options?.normalize ?? await createImportReferenceNormalizer(descriptor31.id, projectRoot, scope);
2724
+ const normalize2 = options?.normalize ?? await createImportReferenceNormalizer(descriptor31.id, projectRoot, scope);
2687
2725
  const results = [];
2688
2726
  for (const feature of IMPORT_FEATURE_ORDER) {
2689
2727
  for (const spec of specsForFeature(importer, feature)) {
2690
- results.push(...await runSpec(spec, scope, projectRoot, descriptor31.id, normalize));
2728
+ results.push(...await runSpec(spec, scope, projectRoot, descriptor31.id, normalize2));
2691
2729
  }
2692
2730
  }
2693
2731
  return results;
@@ -2711,10 +2749,10 @@ var init_descriptor_import_runner = __esm({
2711
2749
  async function importFromAider(projectRoot, options = {}) {
2712
2750
  const scope = options.scope ?? "project";
2713
2751
  const results = [];
2714
- const normalize = await createImportReferenceNormalizer(AIDER_TARGET, projectRoot, scope);
2715
- results.push(...await runDescriptorImport(descriptor, projectRoot, scope, { normalize }));
2752
+ const normalize2 = await createImportReferenceNormalizer(AIDER_TARGET, projectRoot, scope);
2753
+ results.push(...await runDescriptorImport(descriptor, projectRoot, scope, { normalize: normalize2 }));
2716
2754
  const skillsDir = scope === "global" ? AIDER_GLOBAL_SKILLS_DIR : AIDER_SKILLS_DIR;
2717
- await importEmbeddedSkills(projectRoot, skillsDir, AIDER_TARGET, results, normalize);
2755
+ await importEmbeddedSkills(projectRoot, skillsDir, AIDER_TARGET, results, normalize2);
2718
2756
  return results;
2719
2757
  }
2720
2758
  var init_importer = __esm({
@@ -4953,10 +4991,10 @@ var init_mcp_import = __esm({
4953
4991
  async function importFromAmp(projectRoot, options = {}) {
4954
4992
  const scope = options.scope ?? "project";
4955
4993
  const results = [];
4956
- const normalize = await createImportReferenceNormalizer(AMP_TARGET, projectRoot, scope);
4957
- results.push(...await runDescriptorImport(descriptor3, projectRoot, scope, { normalize }));
4994
+ const normalize2 = await createImportReferenceNormalizer(AMP_TARGET, projectRoot, scope);
4995
+ results.push(...await runDescriptorImport(descriptor3, projectRoot, scope, { normalize: normalize2 }));
4958
4996
  const skillsDir = scope === "global" ? AMP_GLOBAL_SKILLS_DIR : AMP_SKILLS_DIR;
4959
- await importEmbeddedSkills(projectRoot, skillsDir, AMP_TARGET, results, normalize);
4997
+ await importEmbeddedSkills(projectRoot, skillsDir, AMP_TARGET, results, normalize2);
4960
4998
  const mcpFile = scope === "global" ? AMP_GLOBAL_MCP_FILE : AMP_MCP_FILE;
4961
4999
  await importAmpMcp(projectRoot, mcpFile, results);
4962
5000
  return results;
@@ -5304,7 +5342,7 @@ var init_embedded_rules = __esm({
5304
5342
  init_import_metadata();
5305
5343
  }
5306
5344
  });
5307
- async function importRootRule(projectRoot, results, normalize, scope) {
5345
+ async function importRootRule(projectRoot, results, normalize2, scope) {
5308
5346
  const primary = scope === "global" ? ANTIGRAVITY_GLOBAL_ROOT : ANTIGRAVITY_RULES_ROOT;
5309
5347
  const candidates = scope === "project" ? [primary, ANTIGRAVITY_RULES_ROOT_LEGACY] : [primary];
5310
5348
  for (const rel2 of candidates) {
@@ -5318,10 +5356,10 @@ async function importRootRule(projectRoot, results, normalize, scope) {
5318
5356
  rulesDir: ANTIGRAVITY_CANONICAL_RULES_DIR,
5319
5357
  sourcePath: srcPath,
5320
5358
  fromTool: ANTIGRAVITY_TARGET,
5321
- normalize
5359
+ normalize: normalize2
5322
5360
  });
5323
5361
  results.push(...split.results);
5324
- const { body } = parseFrontmatter(normalize(split.rootContent, srcPath, destPath));
5362
+ const { body } = parseFrontmatter(normalize2(split.rootContent, srcPath, destPath));
5325
5363
  const output = await serializeImportedRuleWithFallback(destPath, { root: true }, body);
5326
5364
  await mkdirp(join(projectRoot, ANTIGRAVITY_CANONICAL_RULES_DIR));
5327
5365
  await writeFileAtomic(destPath, output);
@@ -5337,15 +5375,15 @@ async function importRootRule(projectRoot, results, normalize, scope) {
5337
5375
  async function importFromAntigravity(projectRoot, options = {}) {
5338
5376
  const scope = options.scope ?? "project";
5339
5377
  const results = [];
5340
- const normalize = await createImportReferenceNormalizer(ANTIGRAVITY_TARGET, projectRoot, scope);
5341
- await importRootRule(projectRoot, results, normalize, scope);
5342
- results.push(...await runDescriptorImport(descriptor4, projectRoot, scope, { normalize }));
5378
+ const normalize2 = await createImportReferenceNormalizer(ANTIGRAVITY_TARGET, projectRoot, scope);
5379
+ await importRootRule(projectRoot, results, normalize2, scope);
5380
+ results.push(...await runDescriptorImport(descriptor4, projectRoot, scope, { normalize: normalize2 }));
5343
5381
  await importEmbeddedSkills(
5344
5382
  projectRoot,
5345
5383
  scope === "global" ? ANTIGRAVITY_GLOBAL_SKILLS_DIR : ANTIGRAVITY_SKILLS_DIR,
5346
5384
  ANTIGRAVITY_TARGET,
5347
5385
  results,
5348
- normalize
5386
+ normalize2
5349
5387
  );
5350
5388
  return results;
5351
5389
  }
@@ -5761,7 +5799,7 @@ function canonicalRuleMeta(frontmatter, isRoot) {
5761
5799
  }
5762
5800
  return meta;
5763
5801
  }
5764
- async function importRules(projectRoot, results, normalize, scope) {
5802
+ async function importRules(projectRoot, results, normalize2, scope) {
5765
5803
  const rulesDir = scope === "global" ? AUGMENT_CODE_GLOBAL_RULES_DIR : AUGMENT_CODE_RULES_DIR;
5766
5804
  const destDir = join(projectRoot, AUGMENT_CODE_CANONICAL_RULES_DIR);
5767
5805
  results.push(
@@ -5770,7 +5808,7 @@ async function importRules(projectRoot, results, normalize, scope) {
5770
5808
  destDir,
5771
5809
  extensions: [".md"],
5772
5810
  fromTool: AUGMENT_CODE_TARGET,
5773
- normalize,
5811
+ normalize: normalize2,
5774
5812
  mapEntry: async ({ relativePath, normalizeTo }) => {
5775
5813
  const isRoot = relativePath === "_root.md" || basename(relativePath) === "_root.md";
5776
5814
  const destPath = join(destDir, relativePath);
@@ -5789,7 +5827,7 @@ async function importRules(projectRoot, results, normalize, scope) {
5789
5827
  })
5790
5828
  );
5791
5829
  }
5792
- async function importCommands(projectRoot, results, normalize, scope) {
5830
+ async function importCommands(projectRoot, results, normalize2, scope) {
5793
5831
  const commandsDir = scope === "global" ? AUGMENT_CODE_GLOBAL_COMMANDS_DIR : AUGMENT_CODE_COMMANDS_DIR;
5794
5832
  const destDir = join(projectRoot, ".agentsmesh/commands");
5795
5833
  results.push(
@@ -5798,7 +5836,7 @@ async function importCommands(projectRoot, results, normalize, scope) {
5798
5836
  destDir,
5799
5837
  extensions: [".md"],
5800
5838
  fromTool: AUGMENT_CODE_TARGET,
5801
- normalize,
5839
+ normalize: normalize2,
5802
5840
  mapEntry: async ({ relativePath, normalizeTo }) => {
5803
5841
  const name = basename(relativePath, ".md");
5804
5842
  const destPath = join(destDir, `${name}.md`);
@@ -5821,11 +5859,11 @@ async function importCommands(projectRoot, results, normalize, scope) {
5821
5859
  async function importFromAugmentCode(projectRoot, options = {}) {
5822
5860
  const scope = options.scope ?? "project";
5823
5861
  const results = [];
5824
- const normalize = await createImportReferenceNormalizer(AUGMENT_CODE_TARGET, projectRoot, scope);
5825
- await importRules(projectRoot, results, normalize, scope);
5826
- await importCommands(projectRoot, results, normalize, scope);
5862
+ const normalize2 = await createImportReferenceNormalizer(AUGMENT_CODE_TARGET, projectRoot, scope);
5863
+ await importRules(projectRoot, results, normalize2, scope);
5864
+ await importCommands(projectRoot, results, normalize2, scope);
5827
5865
  const skillsDir = scope === "global" ? AUGMENT_CODE_GLOBAL_SKILLS_DIR : AUGMENT_CODE_SKILLS_DIR;
5828
- await importEmbeddedSkills(projectRoot, skillsDir, AUGMENT_CODE_TARGET, results, normalize);
5866
+ await importEmbeddedSkills(projectRoot, skillsDir, AUGMENT_CODE_TARGET, results, normalize2);
5829
5867
  const settingsFile = scope === "global" ? AUGMENT_CODE_GLOBAL_SETTINGS_FILE : AUGMENT_CODE_SETTINGS_FILE;
5830
5868
  await importAugmentSettings(projectRoot, settingsFile, results);
5831
5869
  if (scope === "project") {
@@ -6443,7 +6481,7 @@ var init_settings_helpers2 = __esm({
6443
6481
  init_constants7();
6444
6482
  }
6445
6483
  });
6446
- async function importClaudeSkills(projectRoot, results, normalize) {
6484
+ async function importClaudeSkills(projectRoot, results, normalize2) {
6447
6485
  const skillsBaseDir = join(projectRoot, CLAUDE_SKILLS_DIR);
6448
6486
  const destBase = join(projectRoot, CLAUDE_CANONICAL_SKILLS_DIR);
6449
6487
  const allFiles = await readDirRecursive(skillsBaseDir);
@@ -6454,7 +6492,7 @@ async function importClaudeSkills(projectRoot, results, normalize) {
6454
6492
  const destSkillDir = join(destBase, skillName);
6455
6493
  const skillMdContent = await readFileSafe(skillMdPath);
6456
6494
  if (skillMdContent === null) continue;
6457
- const normalizedSkillMd = normalize(
6495
+ const normalizedSkillMd = normalize2(
6458
6496
  skillMdContent,
6459
6497
  skillMdPath,
6460
6498
  join(destSkillDir, "SKILL.md")
@@ -6472,7 +6510,7 @@ async function importClaudeSkills(projectRoot, results, normalize) {
6472
6510
  const relPath = relative(skillDir, filePath);
6473
6511
  const destPath = join(destSkillDir, relPath);
6474
6512
  await mkdirp(dirname(destPath));
6475
- const normalized = normalize(fileContent, filePath, destPath);
6513
+ const normalized = normalize2(fileContent, filePath, destPath);
6476
6514
  await writeFileAtomic(
6477
6515
  destPath,
6478
6516
  relPath === "SKILL.md" ? await serializeImportedSkillWithFallback(
@@ -6504,9 +6542,9 @@ var init_importer_skills = __esm({
6504
6542
  async function importFromClaudeCode(projectRoot, options = {}) {
6505
6543
  const scope = options.scope ?? "project";
6506
6544
  const results = [];
6507
- const normalize = await createImportReferenceNormalizer("claude-code", projectRoot, scope);
6508
- results.push(...await runDescriptorImport(descriptor6, projectRoot, scope, { normalize }));
6509
- await importClaudeSkills(projectRoot, results, normalize);
6545
+ const normalize2 = await createImportReferenceNormalizer("claude-code", projectRoot, scope);
6546
+ results.push(...await runDescriptorImport(descriptor6, projectRoot, scope, { normalize: normalize2 }));
6547
+ await importClaudeSkills(projectRoot, results, normalize2);
6510
6548
  await importClaudeHooksJson(projectRoot, results);
6511
6549
  await importSettings(projectRoot, results);
6512
6550
  return results;
@@ -6966,7 +7004,7 @@ var init_importer_mappers = __esm({
6966
7004
  init_constants8();
6967
7005
  }
6968
7006
  });
6969
- async function importClineRules(projectRoot, results, normalize) {
7007
+ async function importClineRules(projectRoot, results, normalize2) {
6970
7008
  const destRulesDir = join(projectRoot, CLINE_CANONICAL_RULES_DIR);
6971
7009
  const clineRulesPath = join(projectRoot, CLINE_RULES_DIR);
6972
7010
  const clineRulesRaw = join(projectRoot, CLINE_RULES_DIR);
@@ -6982,7 +7020,7 @@ async function importClineRules(projectRoot, results, normalize) {
6982
7020
  await mkdirp(destRulesDir);
6983
7021
  const destPath = join(destRulesDir, "_root.md");
6984
7022
  const { frontmatter, body } = parseFrontmatter(
6985
- normalize(flatContent, clineRulesRaw, destPath)
7023
+ normalize2(flatContent, clineRulesRaw, destPath)
6986
7024
  );
6987
7025
  const hasRoot = frontmatter.root === true;
6988
7026
  const outFm = hasRoot ? frontmatter : { ...frontmatter, root: true };
@@ -7008,7 +7046,7 @@ async function importClineRules(projectRoot, results, normalize) {
7008
7046
  await mkdirp(destRulesDir);
7009
7047
  const destPath = join(destRulesDir, "_root.md");
7010
7048
  const { frontmatter, body } = parseFrontmatter(
7011
- normalize(agentsMdContent, agentsMdPath, destPath)
7049
+ normalize2(agentsMdContent, agentsMdPath, destPath)
7012
7050
  );
7013
7051
  const hasRoot = frontmatter.root === true;
7014
7052
  const outFm = hasRoot ? frontmatter : { ...frontmatter, root: true };
@@ -7030,7 +7068,7 @@ async function importClineRules(projectRoot, results, normalize) {
7030
7068
  rootSourcePath = first;
7031
7069
  await mkdirp(destRulesDir);
7032
7070
  const destPath = join(destRulesDir, "_root.md");
7033
- const { frontmatter, body } = parseFrontmatter(normalize(fc, first, destPath));
7071
+ const { frontmatter, body } = parseFrontmatter(normalize2(fc, first, destPath));
7034
7072
  const hasRoot = frontmatter.root === true;
7035
7073
  const outFm = hasRoot ? frontmatter : { ...frontmatter, root: true };
7036
7074
  const outContent = await serializeImportedRuleWithFallback(destPath, outFm, body);
@@ -7048,7 +7086,7 @@ async function importClineRules(projectRoot, results, normalize) {
7048
7086
  rootSourcePath = rootPath;
7049
7087
  await mkdirp(destRulesDir);
7050
7088
  const destPath = join(destRulesDir, "_root.md");
7051
- const { frontmatter, body } = parseFrontmatter(normalize(rootContent, rootPath, destPath));
7089
+ const { frontmatter, body } = parseFrontmatter(normalize2(rootContent, rootPath, destPath));
7052
7090
  const hasRoot = frontmatter.root === true;
7053
7091
  const outFm = hasRoot ? frontmatter : { ...frontmatter, root: true };
7054
7092
  const outContent = await serializeImportedRuleWithFallback(destPath, outFm, body);
@@ -7066,7 +7104,7 @@ async function importClineRules(projectRoot, results, normalize) {
7066
7104
  destDir: destRulesDir,
7067
7105
  extensions: [".md"],
7068
7106
  fromTool: "cline",
7069
- normalize,
7107
+ normalize: normalize2,
7070
7108
  mapEntry: async ({ srcPath, relativePath, normalizeTo }) => {
7071
7109
  if (srcPath === rootSourcePath) return null;
7072
7110
  return mapClineRuleFile(relativePath, destRulesDir, normalizeTo);
@@ -7353,12 +7391,12 @@ var init_skill_import_pipeline = __esm({
7353
7391
  });
7354
7392
 
7355
7393
  // src/targets/cline/skills-adapter.ts
7356
- async function importClineSkills(projectRoot, results, normalize, skillsRelDir = CLINE_SKILLS_DIR) {
7394
+ async function importClineSkills(projectRoot, results, normalize2, skillsRelDir = CLINE_SKILLS_DIR) {
7357
7395
  const options = {
7358
7396
  projectRoot,
7359
7397
  destCanonicalSkillsDir: CLINE_CANONICAL_SKILLS_DIR,
7360
7398
  targetName: "cline",
7361
- normalize,
7399
+ normalize: normalize2,
7362
7400
  results
7363
7401
  };
7364
7402
  await importSkillsDirectory([skillsRelDir], options, [
@@ -7412,8 +7450,8 @@ var init_hook_importer = __esm({
7412
7450
  });
7413
7451
  async function importFromCline(projectRoot) {
7414
7452
  const results = [];
7415
- const normalize = await createImportReferenceNormalizer(CLINE_TARGET, projectRoot);
7416
- const clineRulesIsFile = await importClineRules(projectRoot, results, normalize);
7453
+ const normalize2 = await createImportReferenceNormalizer(CLINE_TARGET, projectRoot);
7454
+ const clineRulesIsFile = await importClineRules(projectRoot, results, normalize2);
7417
7455
  const ignorePath = join(projectRoot, CLINE_IGNORE);
7418
7456
  const ignoreContent = await readFileSafe(ignorePath);
7419
7457
  if (ignoreContent !== null && ignoreContent.trim()) {
@@ -7444,12 +7482,12 @@ async function importFromCline(projectRoot) {
7444
7482
  destDir: destCommandsDir,
7445
7483
  extensions: [".md"],
7446
7484
  fromTool: "cline",
7447
- normalize,
7485
+ normalize: normalize2,
7448
7486
  mapEntry: ({ relativePath, normalizeTo }) => mapClineWorkflowFile(relativePath, destCommandsDir, normalizeTo)
7449
7487
  })
7450
7488
  );
7451
7489
  }
7452
- await importClineSkills(projectRoot, results, normalize);
7490
+ await importClineSkills(projectRoot, results, normalize2);
7453
7491
  await importClineHooks(projectRoot, results);
7454
7492
  return results;
7455
7493
  }
@@ -8032,12 +8070,12 @@ var init_mcp_helpers = __esm({
8032
8070
  });
8033
8071
 
8034
8072
  // src/targets/codex-cli/skills-adapter.ts
8035
- async function importSkills(projectRoot, results, normalize) {
8073
+ async function importSkills(projectRoot, results, normalize2) {
8036
8074
  const options = {
8037
8075
  projectRoot,
8038
8076
  destCanonicalSkillsDir: CODEX_CANONICAL_SKILLS_DIR,
8039
8077
  targetName: CODEX_TARGET,
8040
- normalize,
8078
+ normalize: normalize2,
8041
8079
  results
8042
8080
  };
8043
8081
  await importSkillsDirectory([CODEX_SKILLS_DIR, CODEX_SKILLS_FALLBACK_DIR], options, [
@@ -8051,7 +8089,7 @@ var init_skills_adapter2 = __esm({
8051
8089
  init_constants28();
8052
8090
  }
8053
8091
  });
8054
- async function importCodexAgentsFromToml(projectRoot, results, normalize) {
8092
+ async function importCodexAgentsFromToml(projectRoot, results, normalize2) {
8055
8093
  const agentsPath = join(projectRoot, CODEX_AGENTS_DIR);
8056
8094
  const agentsDestDir = join(projectRoot, CODEX_CANONICAL_AGENTS_DIR);
8057
8095
  try {
@@ -8071,7 +8109,7 @@ async function importCodexAgentsFromToml(projectRoot, results, normalize) {
8071
8109
  const mcpServers = Array.isArray(parsed.mcp_servers) ? parsed.mcp_servers.filter((s) => typeof s === "string") : [];
8072
8110
  await mkdirp(agentsDestDir);
8073
8111
  const destPath = join(agentsDestDir, `${name}.md`);
8074
- const normalizedBody = normalize(body, srcPath, destPath);
8112
+ const normalizedBody = normalize2(body, srcPath, destPath);
8075
8113
  const agent = {
8076
8114
  name,
8077
8115
  description,
@@ -8147,7 +8185,7 @@ var init_codex_rules_embed = __esm({
8147
8185
  init_constants28();
8148
8186
  }
8149
8187
  });
8150
- async function importCodexNonRootRuleFiles(projectRoot, destDir, normalize) {
8188
+ async function importCodexNonRootRuleFiles(projectRoot, destDir, normalize2) {
8151
8189
  const results = [];
8152
8190
  const codexRulesPath = join(projectRoot, CODEX_RULES_DIR);
8153
8191
  try {
@@ -8158,7 +8196,7 @@ async function importCodexNonRootRuleFiles(projectRoot, destDir, normalize) {
8158
8196
  if (!content) continue;
8159
8197
  const relativePath = relative(codexRulesPath, srcPath).replace(/\\/g, "/");
8160
8198
  const destPath = join(destDir, relativePath);
8161
- const { frontmatter, body } = parseFrontmatter(normalize(content, srcPath, destPath));
8199
+ const { frontmatter, body } = parseFrontmatter(normalize2(content, srcPath, destPath));
8162
8200
  await mkdirp(destDir);
8163
8201
  const outFm = frontmatter.root === true ? frontmatter : { ...frontmatter, root: false };
8164
8202
  const outContent = await serializeImportedRuleWithFallback(destPath, outFm, body);
@@ -8186,7 +8224,7 @@ async function importCodexNonRootRuleFiles(projectRoot, destDir, normalize) {
8186
8224
  globs: embedded.meta.globs,
8187
8225
  root: false
8188
8226
  },
8189
- normalize(embedded.body, srcPath, destPath)
8227
+ normalize2(embedded.body, srcPath, destPath)
8190
8228
  );
8191
8229
  await writeFileAtomic(destPath, outContent);
8192
8230
  } else {
@@ -8198,7 +8236,7 @@ async function importCodexNonRootRuleFiles(projectRoot, destDir, normalize) {
8198
8236
  globs: [],
8199
8237
  codex_emit: "execution"
8200
8238
  },
8201
- normalize(raw.trim(), srcPath, destPath)
8239
+ normalize2(raw.trim(), srcPath, destPath)
8202
8240
  );
8203
8241
  await writeFileAtomic(destPath, outContent);
8204
8242
  }
@@ -8222,7 +8260,7 @@ var init_import_codex_non_root_rules = __esm({
8222
8260
  init_codex_rules_embed();
8223
8261
  }
8224
8262
  });
8225
- async function importCodexRules(projectRoot, results, normalize, normalizeWindsurf, layoutScope) {
8263
+ async function importCodexRules(projectRoot, results, normalize2, normalizeWindsurf, layoutScope) {
8226
8264
  const codexPath = join(projectRoot, CODEX_MD);
8227
8265
  const agentsPath = join(projectRoot, AGENTS_MD);
8228
8266
  const globalOverridePath = join(projectRoot, CODEX_GLOBAL_AGENTS_OVERRIDE_MD);
@@ -8244,14 +8282,14 @@ async function importCodexRules(projectRoot, results, normalize, normalizeWindsu
8244
8282
  rulesDir: CODEX_CANONICAL_RULES_DIR,
8245
8283
  sourcePath,
8246
8284
  fromTool: "codex-cli",
8247
- normalize
8285
+ normalize: normalize2
8248
8286
  });
8249
8287
  results.push(...split.results);
8250
- const normalizedContent = sourcePath === agentsPath || sourcePath === globalAgentsPath || sourcePath === globalOverridePath ? normalize(
8288
+ const normalizedContent = sourcePath === agentsPath || sourcePath === globalAgentsPath || sourcePath === globalOverridePath ? normalize2(
8251
8289
  normalizeWindsurf(split.rootContent, sourcePath, destPath),
8252
8290
  sourcePath,
8253
8291
  destPath
8254
- ) : normalize(split.rootContent, sourcePath, destPath);
8292
+ ) : normalize2(split.rootContent, sourcePath, destPath);
8255
8293
  const { frontmatter, body } = parseFrontmatter(normalizedContent);
8256
8294
  const outFm = frontmatter.root === true ? frontmatter : { ...frontmatter, root: true };
8257
8295
  const outContent = await serializeImportedRuleWithFallback(destPath, outFm, body);
@@ -8263,8 +8301,8 @@ async function importCodexRules(projectRoot, results, normalize, normalizeWindsu
8263
8301
  feature: "rules"
8264
8302
  });
8265
8303
  }
8266
- await importInstructionMirrors(projectRoot, destDir, results, normalize);
8267
- results.push(...await importCodexNonRootRuleFiles(projectRoot, destDir, normalize));
8304
+ await importInstructionMirrors(projectRoot, destDir, results, normalize2);
8305
+ results.push(...await importCodexNonRootRuleFiles(projectRoot, destDir, normalize2));
8268
8306
  if (layoutScope !== "global") {
8269
8307
  results.push(
8270
8308
  ...await importFileDirectory({
@@ -8272,7 +8310,7 @@ async function importCodexRules(projectRoot, results, normalize, normalizeWindsu
8272
8310
  destDir,
8273
8311
  extensions: ["AGENTS.md", "AGENTS.override.md"],
8274
8312
  fromTool: "codex-cli",
8275
- normalize,
8313
+ normalize: normalize2,
8276
8314
  mapEntry: async ({ srcPath, normalizeTo }) => {
8277
8315
  const relDir = relative(projectRoot, dirname(srcPath)).replace(/\\/g, "/");
8278
8316
  const fileName = basename(srcPath);
@@ -8306,7 +8344,7 @@ async function importCodexRules(projectRoot, results, normalize, normalizeWindsu
8306
8344
  );
8307
8345
  }
8308
8346
  }
8309
- async function importInstructionMirrors(projectRoot, destDir, results, normalize) {
8347
+ async function importInstructionMirrors(projectRoot, destDir, results, normalize2) {
8310
8348
  try {
8311
8349
  const files = await readDirRecursive(join(projectRoot, CODEX_INSTRUCTIONS_DIR));
8312
8350
  const instructionFiles = files.filter((file) => file.endsWith(".md"));
@@ -8317,7 +8355,7 @@ async function importInstructionMirrors(projectRoot, destDir, results, normalize
8317
8355
  const content = await readFileSafe(srcPath);
8318
8356
  if (!content) continue;
8319
8357
  const destPath = join(destDir, relativePath);
8320
- const { frontmatter, body } = parseFrontmatter(normalize(content, srcPath, destPath));
8358
+ const { frontmatter, body } = parseFrontmatter(normalize2(content, srcPath, destPath));
8321
8359
  await mkdirp(destDir);
8322
8360
  const outFm = frontmatter.root === true ? frontmatter : { ...frontmatter, root: false };
8323
8361
  const outContent = await serializeImportedRuleWithFallback(destPath, outFm, body);
@@ -8350,15 +8388,15 @@ var init_importer_rules2 = __esm({
8350
8388
  async function importFromCodex(projectRoot, options) {
8351
8389
  const layoutScope = options?.scope ?? "project";
8352
8390
  const results = [];
8353
- const normalize = await createImportReferenceNormalizer(CODEX_TARGET, projectRoot, layoutScope);
8391
+ const normalize2 = await createImportReferenceNormalizer(CODEX_TARGET, projectRoot, layoutScope);
8354
8392
  const normalizeWindsurf = await createImportReferenceNormalizer(
8355
8393
  "windsurf",
8356
8394
  projectRoot,
8357
8395
  layoutScope
8358
8396
  );
8359
- await importCodexRules(projectRoot, results, normalize, normalizeWindsurf, layoutScope);
8360
- await importSkills(projectRoot, results, normalize);
8361
- await importCodexAgentsFromToml(projectRoot, results, normalize);
8397
+ await importCodexRules(projectRoot, results, normalize2, normalizeWindsurf, layoutScope);
8398
+ await importSkills(projectRoot, results, normalize2);
8399
+ await importCodexAgentsFromToml(projectRoot, results, normalize2);
8362
8400
  await importMcp(projectRoot, results);
8363
8401
  return results;
8364
8402
  }
@@ -8731,9 +8769,9 @@ async function importMcp2(projectRoot, results) {
8731
8769
  }
8732
8770
  async function importFromContinue(projectRoot) {
8733
8771
  const results = [];
8734
- const normalize = await createImportReferenceNormalizer(CONTINUE_TARGET, projectRoot);
8735
- results.push(...await runDescriptorImport(descriptor9, projectRoot, "project", { normalize }));
8736
- await importEmbeddedSkills(projectRoot, CONTINUE_SKILLS_DIR, CONTINUE_TARGET, results, normalize);
8772
+ const normalize2 = await createImportReferenceNormalizer(CONTINUE_TARGET, projectRoot);
8773
+ results.push(...await runDescriptorImport(descriptor9, projectRoot, "project", { normalize: normalize2 }));
8774
+ await importEmbeddedSkills(projectRoot, CONTINUE_SKILLS_DIR, CONTINUE_TARGET, results, normalize2);
8737
8775
  await importMcp2(projectRoot, results);
8738
8776
  return results;
8739
8777
  }
@@ -9398,14 +9436,14 @@ var init_hook_parser = __esm({
9398
9436
  init_constants29();
9399
9437
  }
9400
9438
  });
9401
- async function importSkills2(projectRoot, results, normalize, skillsDirRel = COPILOT_SKILLS_DIR) {
9439
+ async function importSkills2(projectRoot, results, normalize2, skillsDirRel = COPILOT_SKILLS_DIR) {
9402
9440
  const skillsDir = join(projectRoot, skillsDirRel);
9403
9441
  const directorySkills = await findDirectorySkills(skillsDir);
9404
9442
  const options = {
9405
9443
  projectRoot,
9406
9444
  destCanonicalSkillsDir: COPILOT_CANONICAL_SKILLS_DIR,
9407
9445
  targetName: COPILOT_TARGET,
9408
- normalize,
9446
+ normalize: normalize2,
9409
9447
  results
9410
9448
  };
9411
9449
  for (const [skillName, skillDir] of directorySkills) {
@@ -9423,12 +9461,12 @@ var init_skills_adapter3 = __esm({
9423
9461
  async function importFromCopilot(projectRoot, options = {}) {
9424
9462
  const scope = options.scope ?? "project";
9425
9463
  const results = [];
9426
- const normalize = await createImportReferenceNormalizer(COPILOT_TARGET, projectRoot, scope);
9427
- results.push(...await runDescriptorImport(descriptor10, projectRoot, scope, { normalize }));
9464
+ const normalize2 = await createImportReferenceNormalizer(COPILOT_TARGET, projectRoot, scope);
9465
+ results.push(...await runDescriptorImport(descriptor10, projectRoot, scope, { normalize: normalize2 }));
9428
9466
  await importSkills2(
9429
9467
  projectRoot,
9430
9468
  results,
9431
- normalize,
9469
+ normalize2,
9432
9470
  scope === "global" ? COPILOT_GLOBAL_SKILLS_DIR : COPILOT_SKILLS_DIR
9433
9471
  );
9434
9472
  if (scope === "project") await importHooks(projectRoot, results);
@@ -10049,10 +10087,10 @@ var init_generator12 = __esm({
10049
10087
  async function importFromCrush(projectRoot, options = {}) {
10050
10088
  const scope = options.scope ?? "project";
10051
10089
  const results = [];
10052
- const normalize = await createImportReferenceNormalizer(CRUSH_TARGET, projectRoot, scope);
10053
- results.push(...await runDescriptorImport(descriptor11, projectRoot, scope, { normalize }));
10090
+ const normalize2 = await createImportReferenceNormalizer(CRUSH_TARGET, projectRoot, scope);
10091
+ results.push(...await runDescriptorImport(descriptor11, projectRoot, scope, { normalize: normalize2 }));
10054
10092
  const skillsDir = scope === "global" ? CRUSH_GLOBAL_SKILLS_DIR : CRUSH_SKILLS_DIR;
10055
- await importEmbeddedSkills(projectRoot, skillsDir, CRUSH_TARGET, results, normalize);
10093
+ await importEmbeddedSkills(projectRoot, skillsDir, CRUSH_TARGET, results, normalize2);
10056
10094
  await importCrushConfigJson(projectRoot, results);
10057
10095
  return results;
10058
10096
  }
@@ -10737,7 +10775,7 @@ var init_import_root_helpers = __esm({
10737
10775
  init_constants11();
10738
10776
  }
10739
10777
  });
10740
- async function importCursorRules(projectRoot, results, normalize) {
10778
+ async function importCursorRules(projectRoot, results, normalize2) {
10741
10779
  const destDir = join(projectRoot, CURSOR_CANONICAL_RULES_DIR);
10742
10780
  let rootWritten = false;
10743
10781
  const rulesDir = join(projectRoot, CURSOR_RULES_DIR);
@@ -10747,7 +10785,7 @@ async function importCursorRules(projectRoot, results, normalize) {
10747
10785
  destDir,
10748
10786
  extensions: [".mdc"],
10749
10787
  fromTool: "cursor",
10750
- normalize,
10788
+ normalize: normalize2,
10751
10789
  mapEntry: async ({ srcPath, relativePath, normalizeTo }) => {
10752
10790
  if (rootWritten) {
10753
10791
  const raw = await readFileSafe(srcPath);
@@ -10771,7 +10809,7 @@ async function importCursorRules(projectRoot, results, normalize) {
10771
10809
  results,
10772
10810
  sourcePath: agentsPath,
10773
10811
  content: agentsContent,
10774
- normalize
10812
+ normalize: normalize2
10775
10813
  });
10776
10814
  }
10777
10815
  }
@@ -10784,7 +10822,7 @@ async function importCursorRules(projectRoot, results, normalize) {
10784
10822
  results,
10785
10823
  sourcePath: cursorRulesPath,
10786
10824
  content: cursorRulesContent,
10787
- normalize
10825
+ normalize: normalize2
10788
10826
  });
10789
10827
  }
10790
10828
  }
@@ -10929,14 +10967,14 @@ var init_settings_helpers3 = __esm({
10929
10967
  init_constants11();
10930
10968
  }
10931
10969
  });
10932
- async function importSkills3(projectRoot, results, normalize, skillsRelDir = CURSOR_SKILLS_DIR) {
10970
+ async function importSkills3(projectRoot, results, normalize2, skillsRelDir = CURSOR_SKILLS_DIR) {
10933
10971
  const skillsDir = join(projectRoot, skillsRelDir);
10934
10972
  const directorySkills = await findDirectorySkills(skillsDir);
10935
10973
  const options = {
10936
10974
  projectRoot,
10937
10975
  destCanonicalSkillsDir: CURSOR_CANONICAL_SKILLS_DIR,
10938
10976
  targetName: "cursor",
10939
- normalize,
10977
+ normalize: normalize2,
10940
10978
  results
10941
10979
  };
10942
10980
  for (const [skillName, skillDir] of directorySkills) {
@@ -10988,7 +11026,7 @@ async function hasGlobalCursorArtifacts(projectRoot) {
10988
11026
  if (commandFiles.some((f) => f.endsWith(".md"))) return true;
10989
11027
  return false;
10990
11028
  }
10991
- async function importGlobalCursorRulesFromDir(projectRoot, results, normalize) {
11029
+ async function importGlobalCursorRulesFromDir(projectRoot, results, normalize2) {
10992
11030
  const destDir = join(projectRoot, CURSOR_CANONICAL_RULES_DIR);
10993
11031
  let rootWritten = false;
10994
11032
  const rulesDir = join(projectRoot, CURSOR_RULES_DIR);
@@ -10997,7 +11035,7 @@ async function importGlobalCursorRulesFromDir(projectRoot, results, normalize) {
10997
11035
  destDir,
10998
11036
  extensions: [".mdc"],
10999
11037
  fromTool: CURSOR_TARGET2,
11000
- normalize,
11038
+ normalize: normalize2,
11001
11039
  mapEntry: async ({ srcPath, relativePath, normalizeTo }) => {
11002
11040
  if (rootWritten) {
11003
11041
  const raw = await readFileSafe(srcPath);
@@ -11014,7 +11052,7 @@ async function importGlobalCursorRulesFromDir(projectRoot, results, normalize) {
11014
11052
  results.push(...batch);
11015
11053
  return rootWritten;
11016
11054
  }
11017
- async function importGlobalUserRules(projectRoot, results, normalize) {
11055
+ async function importGlobalUserRules(projectRoot, results, normalize2) {
11018
11056
  const srcPath = join(projectRoot, CURSOR_GLOBAL_USER_RULES);
11019
11057
  const raw = await readFileSafe(srcPath);
11020
11058
  if (raw === null || raw.trim() === "") return false;
@@ -11023,10 +11061,10 @@ async function importGlobalUserRules(projectRoot, results, normalize) {
11023
11061
  results,
11024
11062
  sourcePath: srcPath,
11025
11063
  content: raw.trim(),
11026
- normalize
11064
+ normalize: normalize2
11027
11065
  });
11028
11066
  }
11029
- async function importGlobalDotCursorAgents(projectRoot, results, normalize) {
11067
+ async function importGlobalDotCursorAgents(projectRoot, results, normalize2) {
11030
11068
  const srcPath = join(projectRoot, CURSOR_DOT_CURSOR_AGENTS);
11031
11069
  const raw = await readFileSafe(srcPath);
11032
11070
  if (raw === null || raw.trim() === "") return false;
@@ -11035,7 +11073,7 @@ async function importGlobalDotCursorAgents(projectRoot, results, normalize) {
11035
11073
  results,
11036
11074
  sourcePath: srcPath,
11037
11075
  content: raw.trim(),
11038
- normalize
11076
+ normalize: normalize2
11039
11077
  });
11040
11078
  }
11041
11079
  async function importGlobalMcp(projectRoot, results) {
@@ -11059,7 +11097,7 @@ async function importGlobalMcp(projectRoot, results) {
11059
11097
  feature: "mcp"
11060
11098
  });
11061
11099
  }
11062
- async function importGlobalAgents(projectRoot, results, normalize) {
11100
+ async function importGlobalAgents(projectRoot, results, normalize2) {
11063
11101
  const agentsDir = join(projectRoot, CURSOR_AGENTS_DIR);
11064
11102
  const destDir = join(projectRoot, CURSOR_CANONICAL_AGENTS_DIR);
11065
11103
  results.push(
@@ -11068,12 +11106,12 @@ async function importGlobalAgents(projectRoot, results, normalize) {
11068
11106
  destDir,
11069
11107
  extensions: [".md"],
11070
11108
  fromTool: CURSOR_TARGET2,
11071
- normalize,
11109
+ normalize: normalize2,
11072
11110
  mapEntry: ({ relativePath, normalizeTo }) => mapCursorAgentFile(relativePath, destDir, normalizeTo)
11073
11111
  })
11074
11112
  );
11075
11113
  }
11076
- async function importGlobalCommands(projectRoot, results, normalize) {
11114
+ async function importGlobalCommands(projectRoot, results, normalize2) {
11077
11115
  const commandsDir = join(projectRoot, CURSOR_COMMANDS_DIR);
11078
11116
  const destDir = join(projectRoot, CURSOR_CANONICAL_COMMANDS_DIR);
11079
11117
  results.push(
@@ -11082,7 +11120,7 @@ async function importGlobalCommands(projectRoot, results, normalize) {
11082
11120
  destDir,
11083
11121
  extensions: [".md"],
11084
11122
  fromTool: CURSOR_TARGET2,
11085
- normalize,
11123
+ normalize: normalize2,
11086
11124
  mapEntry: ({ relativePath, normalizeTo }) => mapCursorCommandFile(relativePath, destDir, normalizeTo)
11087
11125
  })
11088
11126
  );
@@ -11104,14 +11142,14 @@ var init_import_global_exports_helpers = __esm({
11104
11142
  async function importFromCursorGlobalExports(projectRoot) {
11105
11143
  if (!await hasGlobalCursorArtifacts(projectRoot)) return [];
11106
11144
  const results = [];
11107
- const normalize = await createImportReferenceNormalizer(CURSOR_TARGET2, projectRoot, "global");
11108
- let rootWritten = await importGlobalCursorRulesFromDir(projectRoot, results, normalize);
11109
- if (!rootWritten) rootWritten = await importGlobalUserRules(projectRoot, results, normalize);
11110
- if (!rootWritten) await importGlobalDotCursorAgents(projectRoot, results, normalize);
11145
+ const normalize2 = await createImportReferenceNormalizer(CURSOR_TARGET2, projectRoot, "global");
11146
+ let rootWritten = await importGlobalCursorRulesFromDir(projectRoot, results, normalize2);
11147
+ if (!rootWritten) rootWritten = await importGlobalUserRules(projectRoot, results, normalize2);
11148
+ if (!rootWritten) await importGlobalDotCursorAgents(projectRoot, results, normalize2);
11111
11149
  await importGlobalMcp(projectRoot, results);
11112
- await importSkills3(projectRoot, results, normalize, CURSOR_SKILLS_DIR);
11113
- await importGlobalAgents(projectRoot, results, normalize);
11114
- await importGlobalCommands(projectRoot, results, normalize);
11150
+ await importSkills3(projectRoot, results, normalize2, CURSOR_SKILLS_DIR);
11151
+ await importGlobalAgents(projectRoot, results, normalize2);
11152
+ await importGlobalCommands(projectRoot, results, normalize2);
11115
11153
  await importSettings2(projectRoot, results);
11116
11154
  await importIgnore(projectRoot, results);
11117
11155
  return results;
@@ -11150,10 +11188,10 @@ async function importFromCursor(projectRoot, options = {}) {
11150
11188
  return importFromCursorGlobalExports(projectRoot);
11151
11189
  }
11152
11190
  const results = [];
11153
- const normalize = await createImportReferenceNormalizer("cursor", projectRoot);
11154
- await importCursorRules(projectRoot, results, normalize);
11155
- results.push(...await runDescriptorImport(descriptor12, projectRoot, "project", { normalize }));
11156
- await importSkills3(projectRoot, results, normalize);
11191
+ const normalize2 = await createImportReferenceNormalizer("cursor", projectRoot);
11192
+ await importCursorRules(projectRoot, results, normalize2);
11193
+ results.push(...await runDescriptorImport(descriptor12, projectRoot, "project", { normalize: normalize2 }));
11194
+ await importSkills3(projectRoot, results, normalize2);
11157
11195
  await importMcp3(projectRoot, results);
11158
11196
  await importSettings2(projectRoot, results);
11159
11197
  await importIgnore(projectRoot, results);
@@ -11511,14 +11549,14 @@ var init_generator15 = __esm({
11511
11549
  async function importFromDeepagentsCli(projectRoot, options = {}) {
11512
11550
  const scope = options.scope ?? "project";
11513
11551
  const results = [];
11514
- const normalize = await createImportReferenceNormalizer(
11552
+ const normalize2 = await createImportReferenceNormalizer(
11515
11553
  DEEPAGENTS_CLI_TARGET,
11516
11554
  projectRoot,
11517
11555
  scope
11518
11556
  );
11519
- results.push(...await runDescriptorImport(descriptor13, projectRoot, scope, { normalize }));
11557
+ results.push(...await runDescriptorImport(descriptor13, projectRoot, scope, { normalize: normalize2 }));
11520
11558
  const skillsDir = scope === "global" ? DEEPAGENTS_CLI_GLOBAL_SKILLS_DIR : DEEPAGENTS_CLI_SKILLS_DIR;
11521
- await importEmbeddedSkills(projectRoot, skillsDir, DEEPAGENTS_CLI_TARGET, results, normalize);
11559
+ await importEmbeddedSkills(projectRoot, skillsDir, DEEPAGENTS_CLI_TARGET, results, normalize2);
11522
11560
  return results;
11523
11561
  }
11524
11562
  var init_importer13 = __esm({
@@ -11845,10 +11883,10 @@ var init_mcp_import2 = __esm({
11845
11883
  async function importFromFactoryDroid(projectRoot, options = {}) {
11846
11884
  const scope = options.scope ?? "project";
11847
11885
  const results = [];
11848
- const normalize = await createImportReferenceNormalizer(FACTORY_DROID_TARGET, projectRoot, scope);
11849
- results.push(...await runDescriptorImport(descriptor14, projectRoot, scope, { normalize }));
11886
+ const normalize2 = await createImportReferenceNormalizer(FACTORY_DROID_TARGET, projectRoot, scope);
11887
+ results.push(...await runDescriptorImport(descriptor14, projectRoot, scope, { normalize: normalize2 }));
11850
11888
  const skillsDir = scope === "global" ? FACTORY_DROID_GLOBAL_SKILLS_DIR : FACTORY_DROID_SKILLS_DIR;
11851
- await importEmbeddedSkills(projectRoot, skillsDir, FACTORY_DROID_TARGET, results, normalize);
11889
+ await importEmbeddedSkills(projectRoot, skillsDir, FACTORY_DROID_TARGET, results, normalize2);
11852
11890
  const mcpFile = scope === "global" ? FACTORY_DROID_GLOBAL_MCP_FILE : FACTORY_DROID_MCP_FILE;
11853
11891
  await importFactoryDroidMcp(projectRoot, mcpFile, results);
11854
11892
  return results;
@@ -12662,7 +12700,7 @@ var init_importer_strip = __esm({
12662
12700
  "src/targets/gemini-cli/importer-strip.ts"() {
12663
12701
  }
12664
12702
  });
12665
- async function importGeminiSkillsAndAgents(projectRoot, results, normalize) {
12703
+ async function importGeminiSkillsAndAgents(projectRoot, results, normalize2) {
12666
12704
  const geminiSkillsPath = join(projectRoot, GEMINI_SKILLS_DIR);
12667
12705
  const skillDirs = await readDirRecursive(geminiSkillsPath);
12668
12706
  const skillMdFiles = skillDirs.filter((f) => basename(f) === "SKILL.md");
@@ -12678,7 +12716,7 @@ async function importGeminiSkillsAndAgents(projectRoot, results, normalize) {
12678
12716
  const agentPath = join(agentsDir, `${projectedAgent.name}.md`);
12679
12717
  await writeFileAtomic(
12680
12718
  agentPath,
12681
- serializeImportedAgent(projectedAgent, normalize(rawParsed.body, srcPath, agentPath))
12719
+ serializeImportedAgent(projectedAgent, normalize2(rawParsed.body, srcPath, agentPath))
12682
12720
  );
12683
12721
  results.push({
12684
12722
  fromTool: "gemini-cli",
@@ -12689,7 +12727,7 @@ async function importGeminiSkillsAndAgents(projectRoot, results, normalize) {
12689
12727
  continue;
12690
12728
  }
12691
12729
  const destPath = join(projectRoot, GEMINI_CANONICAL_SKILLS_DIR, skillName, "SKILL.md");
12692
- const normalized = normalize(content, srcPath, destPath);
12730
+ const normalized = normalize2(content, srcPath, destPath);
12693
12731
  const skillDir = join(projectRoot, GEMINI_CANONICAL_SKILLS_DIR, skillName);
12694
12732
  await mkdirp(skillDir);
12695
12733
  const { frontmatter, body } = parseFrontmatter(normalized);
@@ -12711,7 +12749,7 @@ async function importGeminiSkillsAndAgents(projectRoot, results, normalize) {
12711
12749
  const relPath = relative(dirname(srcPath), absPath).replace(/\\/g, "/");
12712
12750
  const destSupportPath = join(skillDir, relPath);
12713
12751
  await mkdirp(dirname(destSupportPath));
12714
- await writeFileAtomic(destSupportPath, normalize(supportContent, absPath, destSupportPath));
12752
+ await writeFileAtomic(destSupportPath, normalize2(supportContent, absPath, destSupportPath));
12715
12753
  results.push({
12716
12754
  fromTool: "gemini-cli",
12717
12755
  fromPath: absPath,
@@ -12733,7 +12771,7 @@ async function importGeminiSkillsAndAgents(projectRoot, results, normalize) {
12733
12771
  const agentsDir = join(projectRoot, GEMINI_CANONICAL_AGENTS_DIR);
12734
12772
  await mkdirp(agentsDir);
12735
12773
  const destPath = join(agentsDir, relativeMdPath);
12736
- const normalizedBody = normalize(body, srcPath, destPath);
12774
+ const normalizedBody = normalize2(body, srcPath, destPath);
12737
12775
  await writeFileAtomic(
12738
12776
  destPath,
12739
12777
  await serializeImportedAgentWithFallback(
@@ -12767,7 +12805,7 @@ var init_importer_skills_agents = __esm({
12767
12805
  init_constants30();
12768
12806
  }
12769
12807
  });
12770
- async function importRootRule2(projectRoot, results, normalize) {
12808
+ async function importRootRule2(projectRoot, results, normalize2) {
12771
12809
  const normalizeCodex = await createImportReferenceNormalizer("codex-cli", projectRoot);
12772
12810
  const rulesDir = join(projectRoot, GEMINI_CANONICAL_RULES_DIR);
12773
12811
  const compatAgentsRootPath = join(projectRoot, GEMINI_COMPAT_AGENTS);
@@ -12798,10 +12836,10 @@ async function importRootRule2(projectRoot, results, normalize) {
12798
12836
  rulesDir: GEMINI_CANONICAL_RULES_DIR,
12799
12837
  sourcePath: rootSourcePath,
12800
12838
  fromTool: GEMINI_TARGET,
12801
- normalize
12839
+ normalize: normalize2
12802
12840
  });
12803
12841
  results.push(...split.results);
12804
- const compatNormalized = normalize(split.rootContent, rootSourcePath, destPath);
12842
+ const compatNormalized = normalize2(split.rootContent, rootSourcePath, destPath);
12805
12843
  const normalizedRoot = stripProjectRootCanonicalPrefix(
12806
12844
  compatNormalized.replace(/\.agents\/skills\//g, ".agentsmesh/skills/").replace(/\.agents\\skills\\/g, ".agentsmesh/skills/"),
12807
12845
  projectRoot
@@ -12823,10 +12861,10 @@ async function importRootRule2(projectRoot, results, normalize) {
12823
12861
  }
12824
12862
  async function importFromGemini(projectRoot) {
12825
12863
  const results = [];
12826
- const normalize = await createImportReferenceNormalizer(GEMINI_TARGET, projectRoot);
12827
- await importRootRule2(projectRoot, results, normalize);
12828
- results.push(...await runDescriptorImport(descriptor15, projectRoot, "project", { normalize }));
12829
- await importGeminiSkillsAndAgents(projectRoot, results, normalize);
12864
+ const normalize2 = await createImportReferenceNormalizer(GEMINI_TARGET, projectRoot);
12865
+ await importRootRule2(projectRoot, results, normalize2);
12866
+ results.push(...await runDescriptorImport(descriptor15, projectRoot, "project", { normalize: normalize2 }));
12867
+ await importGeminiSkillsAndAgents(projectRoot, results, normalize2);
12830
12868
  await importGeminiSettings(projectRoot, results);
12831
12869
  await importGeminiIgnore(projectRoot, results);
12832
12870
  results.push(...await importGeminiPolicies(projectRoot));
@@ -13227,10 +13265,10 @@ var init_generator19 = __esm({
13227
13265
  async function importFromGoose(projectRoot, options = {}) {
13228
13266
  const scope = options.scope ?? "project";
13229
13267
  const results = [];
13230
- const normalize = await createImportReferenceNormalizer(GOOSE_TARGET, projectRoot, scope);
13231
- results.push(...await runDescriptorImport(descriptor16, projectRoot, scope, { normalize }));
13268
+ const normalize2 = await createImportReferenceNormalizer(GOOSE_TARGET, projectRoot, scope);
13269
+ results.push(...await runDescriptorImport(descriptor16, projectRoot, scope, { normalize: normalize2 }));
13232
13270
  const skillsDir = scope === "global" ? GOOSE_GLOBAL_SKILLS_DIR : GOOSE_SKILLS_DIR;
13233
- await importEmbeddedSkills(projectRoot, skillsDir, GOOSE_TARGET, results, normalize);
13271
+ await importEmbeddedSkills(projectRoot, skillsDir, GOOSE_TARGET, results, normalize2);
13234
13272
  return results;
13235
13273
  }
13236
13274
  var init_importer16 = __esm({
@@ -13462,8 +13500,8 @@ var init_generator20 = __esm({
13462
13500
  // src/targets/jules/importer.ts
13463
13501
  async function importFromJules(projectRoot, options = {}) {
13464
13502
  const scope = options.scope ?? "project";
13465
- const normalize = await createImportReferenceNormalizer(JULES_TARGET, projectRoot, scope);
13466
- return runDescriptorImport(descriptor17, projectRoot, scope, { normalize });
13503
+ const normalize2 = await createImportReferenceNormalizer(JULES_TARGET, projectRoot, scope);
13504
+ return runDescriptorImport(descriptor17, projectRoot, scope, { normalize: normalize2 });
13467
13505
  }
13468
13506
  var init_importer17 = __esm({
13469
13507
  "src/targets/jules/importer.ts"() {
@@ -13732,7 +13770,7 @@ var init_generator21 = __esm({
13732
13770
  init_constants16();
13733
13771
  }
13734
13772
  });
13735
- async function importRootRule3(projectRoot, results, normalize) {
13773
+ async function importRootRule3(projectRoot, results, normalize2) {
13736
13774
  const sources = [JUNIE_DOT_AGENTS, JUNIE_GUIDELINES, JUNIE_CI_GUIDELINES, JUNIE_AGENTS_FALLBACK];
13737
13775
  const destPath = join(projectRoot, JUNIE_CANONICAL_ROOT_RULE);
13738
13776
  for (const relPath of sources) {
@@ -13745,10 +13783,10 @@ async function importRootRule3(projectRoot, results, normalize) {
13745
13783
  rulesDir: JUNIE_CANONICAL_RULES_DIR,
13746
13784
  sourcePath: srcPath,
13747
13785
  fromTool: JUNIE_TARGET,
13748
- normalize
13786
+ normalize: normalize2
13749
13787
  });
13750
13788
  results.push(...split.results);
13751
- const { frontmatter, body } = parseFrontmatter(normalize(split.rootContent, srcPath, destPath));
13789
+ const { frontmatter, body } = parseFrontmatter(normalize2(split.rootContent, srcPath, destPath));
13752
13790
  const output = await serializeImportedRuleWithFallback(
13753
13791
  destPath,
13754
13792
  {
@@ -13770,10 +13808,10 @@ async function importRootRule3(projectRoot, results, normalize) {
13770
13808
  }
13771
13809
  async function importFromJunie(projectRoot) {
13772
13810
  const results = [];
13773
- const normalize = await createImportReferenceNormalizer(JUNIE_TARGET, projectRoot);
13774
- await importRootRule3(projectRoot, results, normalize);
13775
- results.push(...await runDescriptorImport(descriptor18, projectRoot, "project", { normalize }));
13776
- await importEmbeddedSkills(projectRoot, JUNIE_SKILLS_DIR, JUNIE_TARGET, results, normalize);
13811
+ const normalize2 = await createImportReferenceNormalizer(JUNIE_TARGET, projectRoot);
13812
+ await importRootRule3(projectRoot, results, normalize2);
13813
+ results.push(...await runDescriptorImport(descriptor18, projectRoot, "project", { normalize: normalize2 }));
13814
+ await importEmbeddedSkills(projectRoot, JUNIE_SKILLS_DIR, JUNIE_TARGET, results, normalize2);
13777
13815
  return results;
13778
13816
  }
13779
13817
  var init_importer18 = __esm({
@@ -14165,7 +14203,7 @@ async function pathExists(absolutePath) {
14165
14203
  return false;
14166
14204
  }
14167
14205
  }
14168
- async function importLegacyRules(projectRoot, results, normalize) {
14206
+ async function importLegacyRules(projectRoot, results, normalize2) {
14169
14207
  const srcDir = join(projectRoot, KILO_CODE_LEGACY_RULES_DIR);
14170
14208
  if (!await pathExists(srcDir)) return;
14171
14209
  const destDir = join(projectRoot, KILO_CODE_CANONICAL_RULES_DIR);
@@ -14174,7 +14212,7 @@ async function importLegacyRules(projectRoot, results, normalize) {
14174
14212
  const rootContent = hasCurrentRoot ? null : await readFileSafe(rootSourceFile);
14175
14213
  if (rootContent !== null) {
14176
14214
  const destPath = join(projectRoot, CANONICAL_ROOT_RULE_PATH);
14177
- const normalized = normalize(rootContent, rootSourceFile, destPath);
14215
+ const normalized = normalize2(rootContent, rootSourceFile, destPath);
14178
14216
  const { body } = parseFrontmatter(normalized);
14179
14217
  const serialized = await serializeImportedRuleWithFallback(destPath, { root: true }, body);
14180
14218
  await writeFileAtomic(destPath, serialized);
@@ -14191,7 +14229,7 @@ async function importLegacyRules(projectRoot, results, normalize) {
14191
14229
  destDir,
14192
14230
  extensions: [".md"],
14193
14231
  fromTool: KILO_CODE_TARGET,
14194
- normalize,
14232
+ normalize: normalize2,
14195
14233
  mapEntry: async ({ srcPath, relativePath, content, normalizeTo }) => {
14196
14234
  const mapping = await kiloNonRootRuleMapper({
14197
14235
  absolutePath: srcPath,
@@ -14207,7 +14245,7 @@ async function importLegacyRules(projectRoot, results, normalize) {
14207
14245
  })
14208
14246
  );
14209
14247
  }
14210
- async function importLegacyWorkflows(projectRoot, results, normalize) {
14248
+ async function importLegacyWorkflows(projectRoot, results, normalize2) {
14211
14249
  const srcDir = join(projectRoot, KILO_CODE_LEGACY_WORKFLOWS_DIR);
14212
14250
  if (!await pathExists(srcDir)) return;
14213
14251
  const destDir = join(projectRoot, KILO_CODE_CANONICAL_COMMANDS_DIR);
@@ -14217,7 +14255,7 @@ async function importLegacyWorkflows(projectRoot, results, normalize) {
14217
14255
  destDir,
14218
14256
  extensions: [".md"],
14219
14257
  fromTool: KILO_CODE_TARGET,
14220
- normalize,
14258
+ normalize: normalize2,
14221
14259
  mapEntry: async ({ srcPath, relativePath, content, normalizeTo }) => {
14222
14260
  const mapping = await kiloCommandMapper({
14223
14261
  absolutePath: srcPath,
@@ -14232,7 +14270,7 @@ async function importLegacyWorkflows(projectRoot, results, normalize) {
14232
14270
  })
14233
14271
  );
14234
14272
  }
14235
- async function importLegacyModes(projectRoot, results, normalize) {
14273
+ async function importLegacyModes(projectRoot, results, normalize2) {
14236
14274
  const sourceFile = join(projectRoot, KILO_CODE_LEGACY_MODES_FILE);
14237
14275
  const content = await readFileSafe(sourceFile);
14238
14276
  if (content === null) return;
@@ -14261,7 +14299,7 @@ ${whenToUse}` : role;
14261
14299
  if (description) frontmatter.description = description;
14262
14300
  if (typeof mode.name === "string" && mode.name.length > 0) frontmatter.name = mode.name;
14263
14301
  const serialized = await serializeImportedAgentWithFallback(destPath, frontmatter, body);
14264
- const normalized = normalize(serialized, sourceFile, destPath);
14302
+ const normalized = normalize2(serialized, sourceFile, destPath);
14265
14303
  await writeFileAtomic(destPath, normalized);
14266
14304
  results.push({
14267
14305
  feature: "agents",
@@ -14274,25 +14312,25 @@ ${whenToUse}` : role;
14274
14312
  async function importFromKiloCode(projectRoot, options = {}) {
14275
14313
  const scope = options.scope ?? "project";
14276
14314
  const results = [];
14277
- const normalize = await createImportReferenceNormalizer(KILO_CODE_TARGET, projectRoot, scope);
14278
- results.push(...await runDescriptorImport(descriptor19, projectRoot, scope, { normalize }));
14315
+ const normalize2 = await createImportReferenceNormalizer(KILO_CODE_TARGET, projectRoot, scope);
14316
+ results.push(...await runDescriptorImport(descriptor19, projectRoot, scope, { normalize: normalize2 }));
14279
14317
  await importEmbeddedSkills(
14280
14318
  projectRoot,
14281
14319
  KILO_CODE_SKILLS_DIR,
14282
14320
  KILO_CODE_TARGET,
14283
14321
  results,
14284
- normalize
14322
+ normalize2
14285
14323
  );
14286
14324
  if (scope === "project") {
14287
- await importLegacyRules(projectRoot, results, normalize);
14288
- await importLegacyWorkflows(projectRoot, results, normalize);
14289
- await importLegacyModes(projectRoot, results, normalize);
14325
+ await importLegacyRules(projectRoot, results, normalize2);
14326
+ await importLegacyWorkflows(projectRoot, results, normalize2);
14327
+ await importLegacyModes(projectRoot, results, normalize2);
14290
14328
  await importEmbeddedSkills(
14291
14329
  projectRoot,
14292
14330
  KILO_CODE_LEGACY_SKILLS_DIR,
14293
14331
  KILO_CODE_TARGET,
14294
14332
  results,
14295
- normalize
14333
+ normalize2
14296
14334
  );
14297
14335
  }
14298
14336
  return results;
@@ -14761,14 +14799,14 @@ function canonicalRuleMeta2(frontmatter) {
14761
14799
  if (inclusion === "fileMatch") meta.trigger = "glob";
14762
14800
  return meta;
14763
14801
  }
14764
- async function importRoot(projectRoot, results, normalize, scope) {
14802
+ async function importRoot(projectRoot, results, normalize2, scope) {
14765
14803
  const candidates = scope === "global" ? [KIRO_GLOBAL_STEERING_AGENTS_MD, KIRO_AGENTS_MD] : [KIRO_AGENTS_MD, KIRO_GLOBAL_STEERING_AGENTS_MD];
14766
14804
  for (const rel2 of candidates) {
14767
14805
  const srcPath = join(projectRoot, rel2);
14768
14806
  const content = await readFileSafe(srcPath);
14769
14807
  if (content === null) continue;
14770
14808
  const destPath = join(projectRoot, KIRO_CANONICAL_ROOT_RULE);
14771
- const { frontmatter, body } = parseFrontmatter(normalize(content, srcPath, destPath));
14809
+ const { frontmatter, body } = parseFrontmatter(normalize2(content, srcPath, destPath));
14772
14810
  await writeFileAtomic(
14773
14811
  destPath,
14774
14812
  await serializeImportedRuleWithFallback(destPath, { ...frontmatter, root: true }, body)
@@ -14782,7 +14820,7 @@ async function importRoot(projectRoot, results, normalize, scope) {
14782
14820
  return;
14783
14821
  }
14784
14822
  }
14785
- async function importNonRootRules(projectRoot, results, normalize) {
14823
+ async function importNonRootRules(projectRoot, results, normalize2) {
14786
14824
  const destDir = join(projectRoot, KIRO_CANONICAL_RULES_DIR);
14787
14825
  results.push(
14788
14826
  ...await importFileDirectory({
@@ -14790,7 +14828,7 @@ async function importNonRootRules(projectRoot, results, normalize) {
14790
14828
  destDir,
14791
14829
  extensions: [".md"],
14792
14830
  fromTool: KIRO_TARGET,
14793
- normalize,
14831
+ normalize: normalize2,
14794
14832
  mapEntry: async ({ relativePath, normalizeTo }) => {
14795
14833
  if (basename(relativePath) === "AGENTS.md") return null;
14796
14834
  const destPath = join(destDir, relativePath);
@@ -14832,11 +14870,11 @@ async function importHooks2(projectRoot, results) {
14832
14870
  async function importFromKiro(projectRoot, options = {}) {
14833
14871
  const scope = options.scope ?? "project";
14834
14872
  const results = [];
14835
- const normalize = await createImportReferenceNormalizer(KIRO_TARGET, projectRoot, scope);
14836
- await importRoot(projectRoot, results, normalize, scope);
14837
- await importNonRootRules(projectRoot, results, normalize);
14838
- results.push(...await runDescriptorImport(descriptor20, projectRoot, scope, { normalize }));
14839
- await importEmbeddedSkills(projectRoot, KIRO_SKILLS_DIR, KIRO_TARGET, results, normalize);
14873
+ const normalize2 = await createImportReferenceNormalizer(KIRO_TARGET, projectRoot, scope);
14874
+ await importRoot(projectRoot, results, normalize2, scope);
14875
+ await importNonRootRules(projectRoot, results, normalize2);
14876
+ results.push(...await runDescriptorImport(descriptor20, projectRoot, scope, { normalize: normalize2 }));
14877
+ await importEmbeddedSkills(projectRoot, KIRO_SKILLS_DIR, KIRO_TARGET, results, normalize2);
14840
14878
  if (scope === "project") await importHooks2(projectRoot, results);
14841
14879
  return results;
14842
14880
  }
@@ -15220,9 +15258,9 @@ async function importMcp4(projectRoot, scope, results) {
15220
15258
  async function importFromOpenCode(projectRoot, options = {}) {
15221
15259
  const scope = options.scope ?? "project";
15222
15260
  const results = [];
15223
- const normalize = await createImportReferenceNormalizer(OPENCODE_TARGET, projectRoot, scope);
15224
- results.push(...await runDescriptorImport(descriptor21, projectRoot, scope, { normalize }));
15225
- await importEmbeddedSkills(projectRoot, OPENCODE_SKILLS_DIR, OPENCODE_TARGET, results, normalize);
15261
+ const normalize2 = await createImportReferenceNormalizer(OPENCODE_TARGET, projectRoot, scope);
15262
+ results.push(...await runDescriptorImport(descriptor21, projectRoot, scope, { normalize: normalize2 }));
15263
+ await importEmbeddedSkills(projectRoot, OPENCODE_SKILLS_DIR, OPENCODE_TARGET, results, normalize2);
15226
15264
  await importMcp4(projectRoot, scope, results);
15227
15265
  return results;
15228
15266
  }
@@ -15581,10 +15619,10 @@ var init_generator25 = __esm({
15581
15619
  async function importFromPiAgent(projectRoot, options = {}) {
15582
15620
  const scope = options.scope ?? "project";
15583
15621
  const results = [];
15584
- const normalize = await createImportReferenceNormalizer(PI_AGENT_TARGET, projectRoot, scope);
15585
- results.push(...await runDescriptorImport(descriptor22, projectRoot, scope, { normalize }));
15622
+ const normalize2 = await createImportReferenceNormalizer(PI_AGENT_TARGET, projectRoot, scope);
15623
+ results.push(...await runDescriptorImport(descriptor22, projectRoot, scope, { normalize: normalize2 }));
15586
15624
  const skillsDir = scope === "global" ? PI_AGENT_GLOBAL_SKILLS_DIR : PI_AGENT_SKILLS_DIR;
15587
- await importEmbeddedSkills(projectRoot, skillsDir, PI_AGENT_TARGET, results, normalize);
15625
+ await importEmbeddedSkills(projectRoot, skillsDir, PI_AGENT_TARGET, results, normalize2);
15588
15626
  return results;
15589
15627
  }
15590
15628
  var init_importer22 = __esm({
@@ -15873,9 +15911,18 @@ function generateIgnore12(canonical) {
15873
15911
  if (!canonical.ignore || canonical.ignore.length === 0) return [];
15874
15912
  return [{ path: QWEN_IGNORE, content: canonical.ignore.join("\n") }];
15875
15913
  }
15914
+ function renderQwenGlobalInstructions(canonical) {
15915
+ const root = canonical.rules.find((rule) => rule.root);
15916
+ const nonRootRules = canonical.rules.filter((rule) => {
15917
+ if (rule.root) return false;
15918
+ return rule.targets.length === 0 || rule.targets.includes(QWEN_CODE_TARGET);
15919
+ });
15920
+ return appendEmbeddedRulesBlock(root?.body.trim() ?? "", nonRootRules);
15921
+ }
15876
15922
  var init_generator26 = __esm({
15877
15923
  "src/targets/qwen-code/generator.ts"() {
15878
15924
  init_markdown();
15925
+ init_managed_blocks();
15879
15926
  init_constants21();
15880
15927
  }
15881
15928
  });
@@ -15884,10 +15931,10 @@ var init_generator26 = __esm({
15884
15931
  async function importFromQwenCode(projectRoot, options = {}) {
15885
15932
  const scope = options.scope ?? "project";
15886
15933
  const results = [];
15887
- const normalize = await createImportReferenceNormalizer(QWEN_CODE_TARGET, projectRoot, scope);
15888
- results.push(...await runDescriptorImport(descriptor23, projectRoot, scope, { normalize }));
15934
+ const normalize2 = await createImportReferenceNormalizer(QWEN_CODE_TARGET, projectRoot, scope);
15935
+ results.push(...await runDescriptorImport(descriptor23, projectRoot, scope, { normalize: normalize2 }));
15889
15936
  const skillsDir = scope === "global" ? QWEN_GLOBAL_SKILLS_DIR : QWEN_SKILLS_DIR;
15890
- await importEmbeddedSkills(projectRoot, skillsDir, QWEN_CODE_TARGET, results, normalize);
15937
+ await importEmbeddedSkills(projectRoot, skillsDir, QWEN_CODE_TARGET, results, normalize2);
15891
15938
  return results;
15892
15939
  }
15893
15940
  var init_importer23 = __esm({
@@ -15958,6 +16005,7 @@ var init_qwen_code2 = __esm({
15958
16005
  };
15959
16006
  globalLayout22 = {
15960
16007
  rootInstructionPath: QWEN_GLOBAL_ROOT,
16008
+ renderPrimaryRootInstruction: renderQwenGlobalInstructions,
15961
16009
  skillDir: QWEN_GLOBAL_SKILLS_DIR,
15962
16010
  managedOutputs: {
15963
16011
  dirs: [QWEN_GLOBAL_COMMANDS_DIR, QWEN_GLOBAL_AGENTS_DIR, QWEN_GLOBAL_SKILLS_DIR],
@@ -16154,14 +16202,14 @@ var init_generator27 = __esm({
16154
16202
  async function importFromReplitAgent(projectRoot, options = {}) {
16155
16203
  const scope = options.scope ?? "project";
16156
16204
  const results = [];
16157
- const normalize = await createImportReferenceNormalizer(REPLIT_AGENT_TARGET, projectRoot, scope);
16158
- results.push(...await runDescriptorImport(descriptor24, projectRoot, scope, { normalize }));
16205
+ const normalize2 = await createImportReferenceNormalizer(REPLIT_AGENT_TARGET, projectRoot, scope);
16206
+ results.push(...await runDescriptorImport(descriptor24, projectRoot, scope, { normalize: normalize2 }));
16159
16207
  await importEmbeddedSkills(
16160
16208
  projectRoot,
16161
16209
  REPLIT_AGENT_SKILLS_DIR,
16162
16210
  REPLIT_AGENT_TARGET,
16163
16211
  results,
16164
- normalize
16212
+ normalize2
16165
16213
  );
16166
16214
  return results;
16167
16215
  }
@@ -16452,7 +16500,7 @@ var init_import_mappers9 = __esm({
16452
16500
  };
16453
16501
  }
16454
16502
  });
16455
- async function importPerModeRules(projectRoot, results, normalize) {
16503
+ async function importPerModeRules(projectRoot, results, normalize2) {
16456
16504
  const rooDir = join(projectRoot, ROO_CODE_DIR);
16457
16505
  let entries;
16458
16506
  try {
@@ -16469,7 +16517,7 @@ async function importPerModeRules(projectRoot, results, normalize) {
16469
16517
  destDir,
16470
16518
  extensions: [".md"],
16471
16519
  fromTool: ROO_CODE_TARGET,
16472
- normalize,
16520
+ normalize: normalize2,
16473
16521
  mapEntry: async ({ srcPath, relativePath, content, normalizeTo }) => {
16474
16522
  const mapping = await rooNonRootRuleMapper({
16475
16523
  absolutePath: srcPath,
@@ -16488,10 +16536,10 @@ async function importPerModeRules(projectRoot, results, normalize) {
16488
16536
  async function importFromRooCode(projectRoot, options = {}) {
16489
16537
  const scope = options.scope ?? "project";
16490
16538
  const results = [];
16491
- const normalize = await createImportReferenceNormalizer(ROO_CODE_TARGET, projectRoot, scope);
16492
- results.push(...await runDescriptorImport(descriptor25, projectRoot, scope, { normalize }));
16493
- await importPerModeRules(projectRoot, results, normalize);
16494
- await importEmbeddedSkills(projectRoot, ROO_CODE_SKILLS_DIR, ROO_CODE_TARGET, results, normalize);
16539
+ const normalize2 = await createImportReferenceNormalizer(ROO_CODE_TARGET, projectRoot, scope);
16540
+ results.push(...await runDescriptorImport(descriptor25, projectRoot, scope, { normalize: normalize2 }));
16541
+ await importPerModeRules(projectRoot, results, normalize2);
16542
+ await importEmbeddedSkills(projectRoot, ROO_CODE_SKILLS_DIR, ROO_CODE_TARGET, results, normalize2);
16495
16543
  return results;
16496
16544
  }
16497
16545
  var init_importer25 = __esm({
@@ -16805,10 +16853,10 @@ var init_generator29 = __esm({
16805
16853
  async function importFromRovodev(projectRoot, options = {}) {
16806
16854
  const scope = options.scope ?? "project";
16807
16855
  const results = [];
16808
- const normalize = await createImportReferenceNormalizer(ROVODEV_TARGET, projectRoot, scope);
16809
- results.push(...await runDescriptorImport(descriptor26, projectRoot, scope, { normalize }));
16856
+ const normalize2 = await createImportReferenceNormalizer(ROVODEV_TARGET, projectRoot, scope);
16857
+ results.push(...await runDescriptorImport(descriptor26, projectRoot, scope, { normalize: normalize2 }));
16810
16858
  const skillsDir = scope === "global" ? ROVODEV_GLOBAL_SKILLS_DIR : ROVODEV_SKILLS_DIR;
16811
- await importEmbeddedSkills(projectRoot, skillsDir, ROVODEV_TARGET, results, normalize);
16859
+ await importEmbeddedSkills(projectRoot, skillsDir, ROVODEV_TARGET, results, normalize2);
16812
16860
  return results;
16813
16861
  }
16814
16862
  var init_importer26 = __esm({
@@ -17066,14 +17114,14 @@ var init_generator30 = __esm({
17066
17114
  init_constants25();
17067
17115
  }
17068
17116
  });
17069
- async function importRoot2(projectRoot, results, normalize, scope) {
17117
+ async function importRoot2(projectRoot, results, normalize2, scope) {
17070
17118
  const candidates = scope === "global" ? [TRAE_GLOBAL_ROOT_RULE, TRAE_PROJECT_RULES] : [TRAE_PROJECT_RULES, TRAE_GLOBAL_ROOT_RULE];
17071
17119
  for (const rel2 of candidates) {
17072
17120
  const srcPath = join(projectRoot, rel2);
17073
17121
  const content = await readFileSafe(srcPath);
17074
17122
  if (content === null) continue;
17075
17123
  const destPath = join(projectRoot, CANONICAL_ROOT_RULE);
17076
- const { frontmatter, body } = parseFrontmatter(normalize(content, srcPath, destPath));
17124
+ const { frontmatter, body } = parseFrontmatter(normalize2(content, srcPath, destPath));
17077
17125
  await mkdirp(join(projectRoot, TRAE_CANONICAL_RULES_DIR));
17078
17126
  await writeFileAtomic(
17079
17127
  destPath,
@@ -17088,7 +17136,7 @@ async function importRoot2(projectRoot, results, normalize, scope) {
17088
17136
  return;
17089
17137
  }
17090
17138
  }
17091
- async function importNonRootRules2(projectRoot, results, normalize, scope) {
17139
+ async function importNonRootRules2(projectRoot, results, normalize2, scope) {
17092
17140
  const srcDir = join(projectRoot, scope === "global" ? TRAE_GLOBAL_RULES_DIR : TRAE_RULES_DIR);
17093
17141
  const destDir = join(projectRoot, TRAE_CANONICAL_RULES_DIR);
17094
17142
  results.push(
@@ -17097,7 +17145,7 @@ async function importNonRootRules2(projectRoot, results, normalize, scope) {
17097
17145
  destDir,
17098
17146
  extensions: [".md"],
17099
17147
  fromTool: TRAE_TARGET,
17100
- normalize,
17148
+ normalize: normalize2,
17101
17149
  mapEntry: async ({ relativePath, normalizeTo }) => {
17102
17150
  const filename = basename(relativePath);
17103
17151
  if (filename === "project_rules.md" || filename === "rules.md") return null;
@@ -17120,16 +17168,16 @@ async function importNonRootRules2(projectRoot, results, normalize, scope) {
17120
17168
  async function importFromTrae(projectRoot, options = {}) {
17121
17169
  const scope = options.scope ?? "project";
17122
17170
  const results = [];
17123
- const normalize = await createImportReferenceNormalizer(TRAE_TARGET, projectRoot, scope);
17124
- await importRoot2(projectRoot, results, normalize, scope);
17125
- await importNonRootRules2(projectRoot, results, normalize, scope);
17126
- results.push(...await runDescriptorImport(descriptor27, projectRoot, scope, { normalize }));
17171
+ const normalize2 = await createImportReferenceNormalizer(TRAE_TARGET, projectRoot, scope);
17172
+ await importRoot2(projectRoot, results, normalize2, scope);
17173
+ await importNonRootRules2(projectRoot, results, normalize2, scope);
17174
+ results.push(...await runDescriptorImport(descriptor27, projectRoot, scope, { normalize: normalize2 }));
17127
17175
  await importEmbeddedSkills(
17128
17176
  projectRoot,
17129
17177
  scope === "global" ? TRAE_GLOBAL_SKILLS_DIR : TRAE_SKILLS_DIR,
17130
17178
  TRAE_TARGET,
17131
17179
  results,
17132
- normalize
17180
+ normalize2
17133
17181
  );
17134
17182
  return results;
17135
17183
  }
@@ -17356,10 +17404,10 @@ var init_generator31 = __esm({
17356
17404
  async function importFromWarp(projectRoot, options = {}) {
17357
17405
  const scope = options.scope ?? "project";
17358
17406
  const results = [];
17359
- const normalize = await createImportReferenceNormalizer(WARP_TARGET, projectRoot, scope);
17360
- results.push(...await runDescriptorImport(descriptor28, projectRoot, scope, { normalize }));
17407
+ const normalize2 = await createImportReferenceNormalizer(WARP_TARGET, projectRoot, scope);
17408
+ results.push(...await runDescriptorImport(descriptor28, projectRoot, scope, { normalize: normalize2 }));
17361
17409
  const skillsDir = scope === "global" ? WARP_GLOBAL_SKILLS_DIR : WARP_SKILLS_DIR;
17362
- await importEmbeddedSkills(projectRoot, skillsDir, WARP_TARGET, results, normalize);
17410
+ await importEmbeddedSkills(projectRoot, skillsDir, WARP_TARGET, results, normalize2);
17363
17411
  return results;
17364
17412
  }
17365
17413
  var init_importer28 = __esm({
@@ -17821,7 +17869,7 @@ function toStringArray8(value) {
17821
17869
  }
17822
17870
  return [];
17823
17871
  }
17824
- async function importWorkflows(projectRoot, results, normalize) {
17872
+ async function importWorkflows(projectRoot, results, normalize2) {
17825
17873
  const workflowsDir = join(projectRoot, WINDSURF_WORKFLOWS_DIR);
17826
17874
  const workflowFiles = await readDirRecursive(workflowsDir);
17827
17875
  const workflowMdFiles = workflowFiles.filter((f) => f.endsWith(".md"));
@@ -17832,7 +17880,7 @@ async function importWorkflows(projectRoot, results, normalize) {
17832
17880
  const relativePath = relative(workflowsDir, srcPath).replace(/\\/g, "/");
17833
17881
  await mkdirp(destCommandsDir);
17834
17882
  const destPath = join(destCommandsDir, relativePath);
17835
- const normalized = normalize(content, srcPath, destPath);
17883
+ const normalized = normalize2(content, srcPath, destPath);
17836
17884
  const { frontmatter, body } = parseFrontmatter(normalized);
17837
17885
  const outContent = await serializeImportedCommandWithFallback(
17838
17886
  destPath,
@@ -17866,12 +17914,12 @@ var init_importer_workflows = __esm({
17866
17914
  });
17867
17915
 
17868
17916
  // src/targets/windsurf/skills-adapter.ts
17869
- async function importSkills4(projectRoot, results, normalize, skillsRelDir = WINDSURF_SKILLS_DIR) {
17917
+ async function importSkills4(projectRoot, results, normalize2, skillsRelDir = WINDSURF_SKILLS_DIR) {
17870
17918
  const options = {
17871
17919
  projectRoot,
17872
17920
  destCanonicalSkillsDir: WINDSURF_CANONICAL_SKILLS_DIR,
17873
17921
  targetName: "windsurf",
17874
- normalize,
17922
+ normalize: normalize2,
17875
17923
  results
17876
17924
  };
17877
17925
  await importSkillsDirectory([skillsRelDir], options, [
@@ -17985,7 +18033,7 @@ var init_importer_hooks_mcp = __esm({
17985
18033
  async function importFromWindsurf(projectRoot, options) {
17986
18034
  const layoutScope = options?.scope ?? "project";
17987
18035
  const results = [];
17988
- const normalize = await createImportReferenceNormalizer(WINDSURF_TARGET, projectRoot);
18036
+ const normalize2 = await createImportReferenceNormalizer(WINDSURF_TARGET, projectRoot);
17989
18037
  const normalizeCodex = await createImportReferenceNormalizer("codex-cli", projectRoot);
17990
18038
  const destRulesDir = join(projectRoot, WINDSURF_CANONICAL_RULES_DIR);
17991
18039
  const rootPath = join(projectRoot, WINDSURF_RULES_ROOT);
@@ -17993,7 +18041,7 @@ async function importFromWindsurf(projectRoot, options) {
17993
18041
  if (rootContent !== null) {
17994
18042
  await mkdirp(destRulesDir);
17995
18043
  const destPath = join(destRulesDir, "_root.md");
17996
- const body = normalize(rootContent, rootPath, destPath).trim();
18044
+ const body = normalize2(rootContent, rootPath, destPath).trim();
17997
18045
  const outContent = await serializeImportedRuleWithFallback(destPath, { root: true }, body);
17998
18046
  await writeFileAtomic(destPath, outContent);
17999
18047
  results.push({
@@ -18009,7 +18057,7 @@ async function importFromWindsurf(projectRoot, options) {
18009
18057
  if (agentsMdContent !== null) {
18010
18058
  await mkdirp(destRulesDir);
18011
18059
  const destPath = join(destRulesDir, "_root.md");
18012
- const body = normalize(
18060
+ const body = normalize2(
18013
18061
  normalizeCodex(agentsMdContent, agentsMdPath, destPath),
18014
18062
  agentsMdPath,
18015
18063
  destPath
@@ -18031,7 +18079,7 @@ async function importFromWindsurf(projectRoot, options) {
18031
18079
  destDir: destRulesDir,
18032
18080
  extensions: ["AGENTS.md"],
18033
18081
  fromTool: "windsurf",
18034
- normalize,
18082
+ normalize: normalize2,
18035
18083
  mapEntry: async ({ srcPath, normalizeTo }) => {
18036
18084
  const relDir = relative(projectRoot, dirname(srcPath)).replace(/\\/g, "/");
18037
18085
  if (!relDir || relDir === "." || basename(srcPath) !== "AGENTS.md") return null;
@@ -18062,7 +18110,7 @@ async function importFromWindsurf(projectRoot, options) {
18062
18110
  destDir: destRulesDir,
18063
18111
  extensions: [".md"],
18064
18112
  fromTool: "windsurf",
18065
- normalize,
18113
+ normalize: normalize2,
18066
18114
  mapEntry: async ({ relativePath, normalizeTo }) => {
18067
18115
  if (relativePath === "_root.md" && rootContent !== null) return null;
18068
18116
  const destPath = join(destRulesDir, relativePath);
@@ -18110,8 +18158,8 @@ async function importFromWindsurf(projectRoot, options) {
18110
18158
  });
18111
18159
  }
18112
18160
  }
18113
- await importWorkflows(projectRoot, results, normalize);
18114
- await importSkills4(projectRoot, results, normalize);
18161
+ await importWorkflows(projectRoot, results, normalize2);
18162
+ await importSkills4(projectRoot, results, normalize2);
18115
18163
  await importWindsurfHooks(projectRoot, results);
18116
18164
  await importWindsurfMcp(projectRoot, results);
18117
18165
  return results;
@@ -18425,8 +18473,8 @@ var init_mcp_import3 = __esm({
18425
18473
  async function importFromZed(projectRoot, options = {}) {
18426
18474
  const scope = options.scope ?? "project";
18427
18475
  const results = [];
18428
- const normalize = await createImportReferenceNormalizer(ZED_TARGET, projectRoot, scope);
18429
- results.push(...await runDescriptorImport(descriptor30, projectRoot, scope, { normalize }));
18476
+ const normalize2 = await createImportReferenceNormalizer(ZED_TARGET, projectRoot, scope);
18477
+ results.push(...await runDescriptorImport(descriptor30, projectRoot, scope, { normalize: normalize2 }));
18430
18478
  const mcpFile = scope === "global" ? ZED_GLOBAL_SETTINGS_FILE : ZED_SETTINGS_FILE;
18431
18479
  await importZedMcp(projectRoot, mcpFile, results);
18432
18480
  return results;
@@ -20147,6 +20195,19 @@ init_fs();
20147
20195
 
20148
20196
  // src/config/remote/git-remote.ts
20149
20197
  init_fs();
20198
+
20199
+ // src/utils/output/redact-url-secrets.ts
20200
+ var URL_WITH_CREDENTIALS = /([a-zA-Z][a-zA-Z0-9+.-]*:\/\/)([^/@\s"'<>]+)@([^\s"'<>]+)/g;
20201
+ function redactUrlSecrets(message) {
20202
+ return message.replace(
20203
+ URL_WITH_CREDENTIALS,
20204
+ (_full, scheme, _userinfo, rest) => {
20205
+ return `${scheme}***@${rest}`;
20206
+ }
20207
+ );
20208
+ }
20209
+
20210
+ // src/config/remote/git-remote.ts
20150
20211
  var execFileAsync = promisify(execFile);
20151
20212
  var REPO_DIRNAME = "repo";
20152
20213
  function ensureNotFlag(value, kind) {
@@ -20180,12 +20241,13 @@ async function fetchGitRemoteExtend(parsed, extendName, options, cacheDir, build
20180
20241
  await rm(stagedRoot, { recursive: true, force: true });
20181
20242
  const allowFallback = options.allowOfflineFallback !== false;
20182
20243
  if (allowFallback && await hasCachedRepo(cacheRepoDir)) {
20244
+ const rawMsg = err instanceof Error ? err.message : String(err);
20183
20245
  console.warn(
20184
- `[agentsmesh] Remote fetch failed for ${extendName}; using cached version. Error: ${err instanceof Error ? err.message : String(err)}`
20246
+ `[agentsmesh] Remote fetch failed for ${extendName}; using cached version. Error: ${redactUrlSecrets(rawMsg)}`
20185
20247
  );
20186
20248
  return readCachedRepo(cacheRepoDir);
20187
20249
  }
20188
- throw err;
20250
+ throw err instanceof Error ? Object.assign(new Error(redactUrlSecrets(err.message)), { cause: err.cause }) : err;
20189
20251
  }
20190
20252
  }
20191
20253
  async function readCachedRepo(repoDir) {
@@ -20346,13 +20408,14 @@ async function fetchGithubRemoteExtend(parsed, extendName, options, cacheDir, bu
20346
20408
  if (allowFallback && await exists(extractDir)) {
20347
20409
  const topDir2 = await findExtractTopDir(extractDir);
20348
20410
  if (topDir2) {
20411
+ const rawMsg = err instanceof Error ? err.message : String(err);
20349
20412
  console.warn(
20350
- `[agentsmesh] Network failed for ${extendName}; using cached version. Error: ${err instanceof Error ? err.message : String(err)}`
20413
+ `[agentsmesh] Network failed for ${extendName}; using cached version. Error: ${redactUrlSecrets(rawMsg)}`
20351
20414
  );
20352
20415
  return { resolvedPath: join(extractDir, topDir2), version: tag };
20353
20416
  }
20354
20417
  }
20355
- throw err;
20418
+ throw err instanceof Error ? Object.assign(new Error(redactUrlSecrets(err.message)), { cause: err.cause }) : err;
20356
20419
  }
20357
20420
  await rm(extractDir, { recursive: true, force: true });
20358
20421
  await mkdir(extractDir, { recursive: true });
@@ -20363,12 +20426,14 @@ async function fetchGithubRemoteExtend(parsed, extendName, options, cacheDir, bu
20363
20426
  file: tarPath,
20364
20427
  cwd: extractDir,
20365
20428
  strict: true,
20429
+ // Allowlist entry types instead of denylist: only `File` and `Directory`
20430
+ // can be extracted. Hardlinks (`Link`), symlinks (`SymbolicLink`), FIFOs,
20431
+ // character/block devices, and any future/exotic tar entry type are
20432
+ // rejected. A denylist would silently let an unknown variant through.
20366
20433
  filter: (entryPath, entry) => {
20367
20434
  if (isZipSlipPath(entryPath)) return false;
20368
- if (entry && "type" in entry && (entry.type === "Link" || entry.type === "SymbolicLink")) {
20369
- return false;
20370
- }
20371
- return true;
20435
+ const type = entry && "type" in entry ? entry.type : void 0;
20436
+ return type === "File" || type === "Directory";
20372
20437
  }
20373
20438
  });
20374
20439
  } finally {
@@ -20466,8 +20531,11 @@ function parseGitSource(source) {
20466
20531
  return null;
20467
20532
  }
20468
20533
  const allowInsecure = process.env.AGENTSMESH_ALLOW_INSECURE_GIT === "1" || process.env.AGENTSMESH_ALLOW_INSECURE_GIT === "true";
20469
- const allowedProtocols = allowInsecure ? ["https:", "http:", "ssh:", "file:"] : ["https:", "ssh:", "file:"];
20470
- if (!allowedProtocols.includes(parsedUrl.protocol)) {
20534
+ const allowLocalGit = process.env.AGENTSMESH_ALLOW_LOCAL_GIT === "1" || process.env.AGENTSMESH_ALLOW_LOCAL_GIT === "true";
20535
+ const allowed = ["https:", "ssh:"];
20536
+ if (allowInsecure) allowed.push("http:");
20537
+ if (allowLocalGit) allowed.push("file:");
20538
+ if (!allowed.includes(parsedUrl.protocol)) {
20471
20539
  return null;
20472
20540
  }
20473
20541
  return { url, ref };
@@ -20926,6 +20994,7 @@ async function parseAgents(agentsDir, opts = {}) {
20926
20994
 
20927
20995
  // src/canonical/features/skills.ts
20928
20996
  init_fs();
20997
+ init_fs_traverse();
20929
20998
  init_markdown();
20930
20999
  init_boilerplate_filter();
20931
21000
  async function readContent(path) {
@@ -20944,7 +21013,7 @@ function sanitizeSkillName(raw) {
20944
21013
  return raw.toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
20945
21014
  }
20946
21015
  async function listSupportingFiles(skillDir) {
20947
- const files = await readDirRecursive(skillDir);
21016
+ const files = await readDirRecursiveNoSymlinks(skillDir);
20948
21017
  const result = [];
20949
21018
  for (const absPath of files) {
20950
21019
  const raw = absPath.slice(skillDir.length + 1);
@@ -22517,6 +22586,135 @@ function lintRuleScopeInversion(input) {
22517
22586
  }
22518
22587
  return out2;
22519
22588
  }
22589
+ var TriggersSchema = z.object({
22590
+ file_globs: z.array(z.string()),
22591
+ command_patterns: z.array(z.string()),
22592
+ keywords: z.array(z.string())
22593
+ }).refine((t) => t.file_globs.length + t.command_patterns.length + t.keywords.length > 0, {
22594
+ message: "cluster must declare at least one trigger of any type"
22595
+ });
22596
+ var ClusterSchema = z.object({
22597
+ topic: z.string().regex(/^[a-z0-9-]+$/, "topic must be kebab-case"),
22598
+ /**
22599
+ * Project-relative path (forward slashes) to the cluster's markdown body.
22600
+ * Conventionally `.agentsmesh/lessons/topics/<topic>.md`, but any project
22601
+ * path is accepted — universal across every agent target.
22602
+ */
22603
+ file: z.string().regex(/\.md$/, "file must be a .md path"),
22604
+ summary: z.string().min(1),
22605
+ triggers: TriggersSchema
22606
+ });
22607
+ var LessonsIndexSchema = z.object({
22608
+ version: z.literal(1),
22609
+ /**
22610
+ * Zero clusters is valid — supports `agentsmesh init --lessons` scaffolding a
22611
+ * fresh project. Topics accumulate via `distill:apply` as failures are
22612
+ * captured.
22613
+ */
22614
+ clusters: z.array(ClusterSchema)
22615
+ });
22616
+ function parseIndex(raw) {
22617
+ return LessonsIndexSchema.parse(raw);
22618
+ }
22619
+ var BASE_REL = ".agentsmesh/lessons";
22620
+ function lessonsPaths(projectRoot) {
22621
+ const base = join(projectRoot, BASE_REL);
22622
+ return {
22623
+ base,
22624
+ journal: join(base, "journal.md"),
22625
+ index: join(base, "index.yaml"),
22626
+ ledger: join(base, "distill-ledger.yaml"),
22627
+ proposal: join(base, "distill-proposal.md"),
22628
+ topicsDir: join(base, "topics")
22629
+ };
22630
+ }
22631
+ function toRelPath(projectRoot, absolute) {
22632
+ return relative(projectRoot, absolute).split(sep).join("/");
22633
+ }
22634
+ var LESSONS_JOURNAL_TEMPLATE = "# Lessons Learned\n\n";
22635
+ var LESSONS_INDEX_TEMPLATE = "version: 1\nclusters: []\n";
22636
+ var LESSONS_PROCEDURAL_RULE = `## Lessons (MUST do \u2014 non-negotiable)
22637
+
22638
+ Two rituals. Universal across every agent harness \u2014 described in tool-agnostic action verbs ("read a file", "edit a file", "run a shell command"); use whatever read / write-patch / shell-exec tool your harness exposes. Skipping either ritual is a process violation; the same paid-for failure recurs next session.
22639
+
22640
+ **Recall \u2014 BEFORE editing any file or running any shell command:**
22641
+
22642
+ 1. Read \`.agentsmesh/lessons/index.yaml\`.
22643
+ 2. For every cluster whose triggers match \u2014 \`file_globs\` against the target file path, \`command_patterns\` (regex) against the shell command, or \`keywords\` (case-insensitive substring) against the active task description \u2014 read its \`file\` (e.g. \`.agentsmesh/lessons/topics/<topic>.md\`).
22644
+ 3. Apply the loaded rules to the action.
22645
+ 4. Then \u2014 and only then \u2014 perform the edit or run the command.
22646
+
22647
+ Rejected excuses: *"the edit is small"* \u2192 apply it. *"I read this earlier in the session"* \u2192 context may have compacted; re-read. *"no trigger fires"* \u2192 proceed; you've done your part.
22648
+
22649
+ **Capture \u2014 IMMEDIATELY after any failure** (test, CI, lint, code review, user correction, regression you spotted yourself, OR any mistake by anyone in the loop):
22650
+
22651
+ 1. Append one bullet to \`.agentsmesh/lessons/journal.md\` in this exact shape:
22652
+ \`- **<short heading>**: <what went wrong>. <root cause>. <imperative rule that prevents recurrence>.\`
22653
+ 2. Read \`.agentsmesh/lessons/index.yaml\` and identify which topic the lesson belongs to (use the \`summary:\` fields).
22654
+ 3. If the lesson teaches a NEW rule: edit that topic's \`## Rules\` section to add it, citing \`(Evidence: L<journal-line>)\`. If it only reinforces an existing rule, the journal entry alone suffices.
22655
+
22656
+ Rejected excuses: *"it wasn't really a failure"* \u2192 if you fixed something, it was. *"I'll capture it later"* \u2192 no; do it now while context is fresh. *"no topic fits"* \u2192 still record in journal; an unrouted bullet is recoverable, a forgotten one is not.
22657
+
22658
+ **These two rituals are load-bearing. Treat them with the same discipline as TDD.**`;
22659
+
22660
+ // src/core/lint/shared/lessons.ts
22661
+ var LESSONS_TARGET = "lessons";
22662
+ var INDEX_REL = ".agentsmesh/lessons/index.yaml";
22663
+ var ROOT_RULE_REL = ".agentsmesh/rules/_root.md";
22664
+ var LESSONS_HEADING = /^## Lessons \(/m;
22665
+ var RULES_HEADING = /^## Rules\b/m;
22666
+ function lintLessonsSubsystem(projectRoot, scope) {
22667
+ if (scope === "global") return [];
22668
+ const paths = lessonsPaths(projectRoot);
22669
+ if (!existsSync(paths.index)) return [];
22670
+ const out2 = [];
22671
+ const parsed = LessonsIndexSchema.safeParse(parse(readFileSync(paths.index, "utf8")));
22672
+ if (!parsed.success) {
22673
+ return [diag("error", INDEX_REL, `index.yaml is invalid: ${parsed.error.issues[0].message}`)];
22674
+ }
22675
+ for (const cluster of parsed.data.clusters) {
22676
+ const topicAbs = join(projectRoot, cluster.file);
22677
+ if (!existsSync(topicAbs)) {
22678
+ out2.push(
22679
+ diag("error", cluster.file, `topic file for cluster "${cluster.topic}" does not exist.`)
22680
+ );
22681
+ continue;
22682
+ }
22683
+ if (!RULES_HEADING.test(readFileSync(topicAbs, "utf8"))) {
22684
+ out2.push(
22685
+ diag("warning", cluster.file, `topic "${cluster.topic}" is missing a "## Rules" section.`)
22686
+ );
22687
+ }
22688
+ for (const pattern of cluster.triggers.command_patterns) {
22689
+ try {
22690
+ new RegExp(pattern);
22691
+ } catch {
22692
+ out2.push(
22693
+ diag(
22694
+ "warning",
22695
+ INDEX_REL,
22696
+ `cluster "${cluster.topic}" command_patterns entry is not a valid regex: ${pattern}`
22697
+ )
22698
+ );
22699
+ }
22700
+ }
22701
+ }
22702
+ const rootRuleAbs = join(projectRoot, ROOT_RULE_REL);
22703
+ const rootRuleBody = existsSync(rootRuleAbs) ? readFileSync(rootRuleAbs, "utf8") : "";
22704
+ if (!LESSONS_HEADING.test(rootRuleBody)) {
22705
+ out2.push(
22706
+ diag(
22707
+ "warning",
22708
+ ROOT_RULE_REL,
22709
+ 'lessons procedural rule ("## Lessons (...)") is missing from _root.md \u2014 recall/capture enforcement will not fire.'
22710
+ )
22711
+ );
22712
+ }
22713
+ return out2;
22714
+ }
22715
+ function diag(level, file, message) {
22716
+ return { level, file, target: LESSONS_TARGET, message };
22717
+ }
22520
22718
 
22521
22719
  // src/core/lint/linter.ts
22522
22720
  var EXCLUDE_DIRS = ["node_modules", ".git", "dist", "coverage", ".agentsmesh"];
@@ -22537,7 +22735,7 @@ async function runLint(config, canonical, projectRoot, targetFilter, options = {
22537
22735
  const hasMcp = config.features.includes("mcp");
22538
22736
  const hasPermissions = config.features.includes("permissions");
22539
22737
  const hasHooks = config.features.includes("hooks");
22540
- const diagnostics = [];
22738
+ const diagnostics = [...lintLessonsSubsystem(projectRoot, scope)];
22541
22739
  const projectFiles = scope === "global" ? [] : await getProjectFiles(projectRoot);
22542
22740
  for (const target31 of targets) {
22543
22741
  const fullDesc = getDescriptor(target31);
@@ -22940,7 +23138,228 @@ function copyTargetDescriptor(descriptor31) {
22940
23138
  function getTargetCatalog() {
22941
23139
  return Object.freeze(BUILTIN_TARGETS.map(copyTargetDescriptor));
22942
23140
  }
23141
+ function normalize(bullet) {
23142
+ return bullet.split("\n").map((line) => line.replace(/\s+$/, "")).join("\n").trim().replace(/^[-*]\s+/, "");
23143
+ }
23144
+ function hashBullet(bullet) {
23145
+ return createHash("sha256").update(normalize(bullet)).digest("hex").slice(0, 16);
23146
+ }
23147
+
23148
+ // src/lessons/bullet-parser.ts
23149
+ function parseBullets(markdown) {
23150
+ const bullets = [];
23151
+ let current = null;
23152
+ let lineNumber = 0;
23153
+ for (const line of markdown.split("\n")) {
23154
+ lineNumber += 1;
23155
+ if (/^[-*]\s+/.test(line)) {
23156
+ if (current !== null) bullets.push(current);
23157
+ current = { text: line, lineNumber };
23158
+ } else if (current !== null) {
23159
+ if (line.length === 0) {
23160
+ bullets.push(current);
23161
+ current = null;
23162
+ } else if (/^\s+\S/.test(line)) {
23163
+ current.text += `
23164
+ ${line}`;
23165
+ } else {
23166
+ bullets.push(current);
23167
+ current = null;
23168
+ }
23169
+ }
23170
+ }
23171
+ if (current !== null) bullets.push(current);
23172
+ return bullets;
23173
+ }
23174
+ function fileMatch(globs, path) {
23175
+ return globs.some((g) => picomatch(g, { dot: true })(path));
23176
+ }
23177
+ function cmdMatch(patterns, cmd) {
23178
+ return patterns.some((p) => {
23179
+ try {
23180
+ return new RegExp(p).test(cmd);
23181
+ } catch {
23182
+ return false;
23183
+ }
23184
+ });
23185
+ }
23186
+ function kwMatch(keywords, text) {
23187
+ const lower = text.toLowerCase();
23188
+ return keywords.some((k) => lower.includes(k.toLowerCase()));
23189
+ }
23190
+ function matchTriggers(clusters, event) {
23191
+ return clusters.filter((c2) => {
23192
+ const t = c2.triggers;
23193
+ switch (event.kind) {
23194
+ case "edit":
23195
+ case "write":
23196
+ return fileMatch(t.file_globs, event.filePath);
23197
+ case "bash":
23198
+ return cmdMatch(t.command_patterns, event.command);
23199
+ case "task":
23200
+ return kwMatch(t.keywords, event.text);
23201
+ }
23202
+ });
23203
+ }
23204
+ var LedgerSchema = z.object({
23205
+ version: z.literal(1),
23206
+ assignments: z.record(z.string(), z.string())
23207
+ });
23208
+ function loadLedger(path) {
23209
+ if (!existsSync(path)) return { version: 1, assignments: {} };
23210
+ return LedgerSchema.parse(parse(readFileSync(path, "utf8")));
23211
+ }
23212
+ function saveLedger(path, ledger) {
23213
+ writeFileSync(path, stringify(ledger), "utf8");
23214
+ }
23215
+
23216
+ // src/lessons/scoring.ts
23217
+ function scoreBullet(bullet, clusters) {
23218
+ const lower = bullet.toLowerCase();
23219
+ return clusters.map((cluster) => {
23220
+ const t = cluster.triggers;
23221
+ const kwHits = t.keywords.filter((k) => lower.includes(k.toLowerCase())).length;
23222
+ const pathHits = t.file_globs.filter((g) => {
23223
+ const stem = g.replace(/[*{}[\]?!]/g, "").replace(/\/+/g, "/").trim();
23224
+ return stem.length > 2 && lower.includes(stem.toLowerCase());
23225
+ }).length;
23226
+ const cmdHits = t.command_patterns.filter((p) => {
23227
+ try {
23228
+ return new RegExp(p, "i").test(bullet);
23229
+ } catch {
23230
+ return false;
23231
+ }
23232
+ }).length;
23233
+ return { cluster, score: kwHits * 2 + pathHits + cmdHits };
23234
+ }).filter((s) => s.score > 0).sort((a, b) => b.score - a.score);
23235
+ }
23236
+ function loadLessonsIndex(projectRoot) {
23237
+ const raw = readFileSync(lessonsPaths(projectRoot).index, "utf8");
23238
+ return parseIndex(parse(raw));
23239
+ }
23240
+ function readTriggeredLessons(projectRoot, event) {
23241
+ const index = loadLessonsIndex(projectRoot);
23242
+ const contentByPath = /* @__PURE__ */ new Map();
23243
+ return matchTriggers(index.clusters, normalizeToolEvent(projectRoot, event)).map(
23244
+ (cluster) => {
23245
+ const filePath = resolveProjectFile(projectRoot, cluster.file);
23246
+ let content = contentByPath.get(cluster.file);
23247
+ if (content === void 0) {
23248
+ content = readFileSync(filePath, "utf8");
23249
+ contentByPath.set(cluster.file, content);
23250
+ }
23251
+ return {
23252
+ cluster,
23253
+ relativePath: cluster.file,
23254
+ filePath,
23255
+ content
23256
+ };
23257
+ }
23258
+ );
23259
+ }
23260
+ function formatLessonBullet(input) {
23261
+ const heading = compact(input.heading);
23262
+ if (heading.length === 0) throw new Error("Lesson heading must not be empty.");
23263
+ return [
23264
+ `- **${heading}**:`,
23265
+ sentence(input.whatWentWrong),
23266
+ sentence(input.rootCause),
23267
+ sentence(input.rule)
23268
+ ].join(" ");
23269
+ }
23270
+ function appendLessonToJournal(projectRoot, input) {
23271
+ const journalPath = lessonsPaths(projectRoot).journal;
23272
+ const bullet = formatLessonBullet(input);
23273
+ const current = existsSync(journalPath) ? readFileSync(journalPath, "utf8") : "";
23274
+ const prefix = current.length === 0 || current.endsWith("\n") ? "" : "\n";
23275
+ const lineNumber = nextLineNumber(current);
23276
+ mkdirSync(dirname(journalPath), { recursive: true });
23277
+ appendFileSync(journalPath, `${prefix}${bullet}
23278
+ `, "utf8");
23279
+ return { journalPath, bullet, lineNumber };
23280
+ }
23281
+ function resolveProjectFile(projectRoot, relPath) {
23282
+ if (isAbsolute(relPath) || /^[A-Za-z]:[\\/]/.test(relPath)) {
23283
+ throw new Error(`Lessons file must be project-relative: ${relPath}`);
23284
+ }
23285
+ const root = resolve(projectRoot);
23286
+ const filePath = resolve(root, relPath);
23287
+ const backToRoot = relative(root, filePath);
23288
+ if (backToRoot === "" || backToRoot.startsWith("..") || isAbsolute(backToRoot)) {
23289
+ throw new Error(`Lessons file escapes the project root: ${relPath}`);
23290
+ }
23291
+ return filePath;
23292
+ }
23293
+ function normalizeToolEvent(projectRoot, event) {
23294
+ if (event.kind !== "edit" && event.kind !== "write") return event;
23295
+ return { ...event, filePath: normalizeEventPath(projectRoot, event.filePath) };
23296
+ }
23297
+ function normalizeEventPath(projectRoot, filePath) {
23298
+ const normalized = filePath.replaceAll("\\", "/");
23299
+ const root = resolve(projectRoot).replaceAll("\\", "/");
23300
+ if (normalized === root) return ".";
23301
+ if (normalized.startsWith(`${root}/`)) return normalized.slice(root.length + 1);
23302
+ return normalized.replace(/^\.\//, "");
23303
+ }
23304
+ function compact(value) {
23305
+ return value.replace(/\s+/g, " ").trim();
23306
+ }
23307
+ function sentence(value) {
23308
+ const compacted = compact(value);
23309
+ if (compacted.length === 0) throw new Error("Lesson sentence must not be empty.");
23310
+ return /[.!?]$/.test(compacted) ? compacted : `${compacted}.`;
23311
+ }
23312
+ function nextLineNumber(current) {
23313
+ if (current.length === 0) return 1;
23314
+ const lineCount = current.split("\n").length;
23315
+ return current.endsWith("\n") ? lineCount : lineCount + 1;
23316
+ }
23317
+ function scaffoldLessons(projectRoot) {
23318
+ const paths = lessonsPaths(projectRoot);
23319
+ const created = [];
23320
+ const skipped = [];
23321
+ mkdirSync(paths.topicsDir, { recursive: true });
23322
+ for (const [path, template] of [
23323
+ [paths.journal, LESSONS_JOURNAL_TEMPLATE],
23324
+ [paths.index, LESSONS_INDEX_TEMPLATE]
23325
+ ]) {
23326
+ if (existsSync(path)) {
23327
+ skipped.push(path);
23328
+ } else {
23329
+ mkdirSync(dirname(path), { recursive: true });
23330
+ writeFileSync(path, template, "utf8");
23331
+ created.push(path);
23332
+ }
23333
+ }
23334
+ const rootRuleUpdated = appendProceduralRule(projectRoot);
23335
+ return { created, skipped, rootRuleUpdated };
23336
+ }
23337
+ function appendProceduralRule(projectRoot) {
23338
+ const rootRule = join(projectRoot, ".agentsmesh/rules/_root.md");
23339
+ if (!existsSync(rootRule)) {
23340
+ mkdirSync(dirname(rootRule), { recursive: true });
23341
+ const seeded = `---
23342
+ root: true
23343
+ description: ""
23344
+ ---
23345
+
23346
+ # Operational Guidelines
23347
+
23348
+ ${LESSONS_PROCEDURAL_RULE}
23349
+ `;
23350
+ writeFileSync(rootRule, seeded, "utf8");
23351
+ return true;
23352
+ }
23353
+ const current = readFileSync(rootRule, "utf8");
23354
+ if (/^## Lessons \(/m.test(current)) return false;
23355
+ const next = current.endsWith("\n") ? current : `${current}
23356
+ `;
23357
+ writeFileSync(rootRule, `${next}
23358
+ ${LESSONS_PROCEDURAL_RULE}
23359
+ `, "utf8");
23360
+ return true;
23361
+ }
22943
23362
 
22944
- export { AgentsMeshError, ConfigNotFoundError, ConfigValidationError, FileSystemError, GenerationError, ImportError, LockAcquisitionError, RemoteFetchError, TargetNotFoundError, check, computeDiff2 as computeDiff, diff, formatDiffSummary, generate, getAllDescriptors, getDescriptor, getTargetCatalog, importFrom, lint, loadCanonical, loadCanonicalFiles, loadConfig2 as loadConfig, loadConfigFromDirectory, loadProjectContext, registerTargetDescriptor, resolveOutputCollisions };
23363
+ export { AgentsMeshError, ConfigNotFoundError, ConfigValidationError, FileSystemError, GenerationError, ImportError, LESSONS_INDEX_TEMPLATE, LESSONS_JOURNAL_TEMPLATE, LESSONS_PROCEDURAL_RULE, LessonsIndexSchema, LockAcquisitionError, RemoteFetchError, TargetNotFoundError, appendLessonToJournal, check, computeDiff2 as computeDiff, diff, formatDiffSummary, formatLessonBullet, generate, getAllDescriptors, getDescriptor, getTargetCatalog, hashBullet, importFrom, lessonsPaths, lint, loadCanonical, loadCanonicalFiles, loadConfig2 as loadConfig, loadConfigFromDirectory, loadLedger, loadLessonsIndex, loadProjectContext, matchTriggers, parseBullets, parseIndex, readTriggeredLessons, registerTargetDescriptor, resolveOutputCollisions, saveLedger, scaffoldLessons, scoreBullet, toRelPath };
22945
23364
  //# sourceMappingURL=index.js.map
22946
23365
  //# sourceMappingURL=index.js.map