mewkit 1.13.0 → 1.14.1

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.
Files changed (223) hide show
  1. package/README.md +37 -0
  2. package/dist/commands/migrate.d.ts +2 -0
  3. package/dist/commands/migrate.d.ts.map +1 -1
  4. package/dist/commands/migrate.js +2 -0
  5. package/dist/commands/migrate.js.map +1 -1
  6. package/dist/commands/validate.js +14 -7
  7. package/dist/commands/validate.js.map +1 -1
  8. package/dist/index.js +11 -0
  9. package/dist/index.js.map +1 -1
  10. package/dist/migrate/apply-env-var-rewrites.d.ts +15 -0
  11. package/dist/migrate/apply-env-var-rewrites.d.ts.map +1 -0
  12. package/dist/migrate/apply-env-var-rewrites.js +26 -0
  13. package/dist/migrate/apply-env-var-rewrites.js.map +1 -0
  14. package/dist/migrate/config-merger/merge-single-sections.d.ts.map +1 -1
  15. package/dist/migrate/config-merger/merge-single-sections.js +4 -2
  16. package/dist/migrate/config-merger/merge-single-sections.js.map +1 -1
  17. package/dist/migrate/converters/command-to-codex-skill.d.ts +10 -0
  18. package/dist/migrate/converters/command-to-codex-skill.d.ts.map +1 -0
  19. package/dist/migrate/converters/command-to-codex-skill.js +88 -0
  20. package/dist/migrate/converters/command-to-codex-skill.js.map +1 -0
  21. package/dist/migrate/converters/direct-copy.d.ts +4 -1
  22. package/dist/migrate/converters/direct-copy.d.ts.map +1 -1
  23. package/dist/migrate/converters/direct-copy.js +19 -22
  24. package/dist/migrate/converters/direct-copy.js.map +1 -1
  25. package/dist/migrate/converters/fm-strip.d.ts.map +1 -1
  26. package/dist/migrate/converters/fm-strip.js +5 -1
  27. package/dist/migrate/converters/fm-strip.js.map +1 -1
  28. package/dist/migrate/converters/fm-to-codex-toml.d.ts +4 -1
  29. package/dist/migrate/converters/fm-to-codex-toml.d.ts.map +1 -1
  30. package/dist/migrate/converters/fm-to-codex-toml.js +8 -3
  31. package/dist/migrate/converters/fm-to-codex-toml.js.map +1 -1
  32. package/dist/migrate/converters/fm-to-fm.js +4 -4
  33. package/dist/migrate/converters/fm-to-fm.js.map +1 -1
  34. package/dist/migrate/converters/fm-to-json.d.ts.map +1 -1
  35. package/dist/migrate/converters/fm-to-json.js +2 -1
  36. package/dist/migrate/converters/fm-to-json.js.map +1 -1
  37. package/dist/migrate/converters/fm-to-yaml.js +1 -1
  38. package/dist/migrate/converters/fm-to-yaml.js.map +1 -1
  39. package/dist/migrate/converters/index.d.ts +7 -2
  40. package/dist/migrate/converters/index.d.ts.map +1 -1
  41. package/dist/migrate/converters/index.js +8 -8
  42. package/dist/migrate/converters/index.js.map +1 -1
  43. package/dist/migrate/converters/mcp-json-to-codex-toml.d.ts +8 -0
  44. package/dist/migrate/converters/mcp-json-to-codex-toml.d.ts.map +1 -0
  45. package/dist/migrate/converters/mcp-json-to-codex-toml.js +65 -0
  46. package/dist/migrate/converters/mcp-json-to-codex-toml.js.map +1 -0
  47. package/dist/migrate/converters/md-strip.d.ts +10 -1
  48. package/dist/migrate/converters/md-strip.d.ts.map +1 -1
  49. package/dist/migrate/converters/md-strip.js +27 -70
  50. package/dist/migrate/converters/md-strip.js.map +1 -1
  51. package/dist/migrate/converters/md-to-kiro-steering.js +1 -1
  52. package/dist/migrate/converters/md-to-kiro-steering.js.map +1 -1
  53. package/dist/migrate/converters/md-to-mdc.js +1 -1
  54. package/dist/migrate/converters/md-to-mdc.js.map +1 -1
  55. package/dist/migrate/converters/md-to-toml.js +1 -1
  56. package/dist/migrate/converters/md-to-toml.js.map +1 -1
  57. package/dist/migrate/discovery/config-discovery.d.ts +29 -0
  58. package/dist/migrate/discovery/config-discovery.d.ts.map +1 -1
  59. package/dist/migrate/discovery/config-discovery.js +45 -0
  60. package/dist/migrate/discovery/config-discovery.js.map +1 -1
  61. package/dist/migrate/discovery/handlers-json-filter.d.ts.map +1 -1
  62. package/dist/migrate/discovery/handlers-json-filter.js +4 -2
  63. package/dist/migrate/discovery/handlers-json-filter.js.map +1 -1
  64. package/dist/migrate/discovery/hooks-discovery.d.ts +5 -0
  65. package/dist/migrate/discovery/hooks-discovery.d.ts.map +1 -1
  66. package/dist/migrate/discovery/hooks-discovery.js +21 -5
  67. package/dist/migrate/discovery/hooks-discovery.js.map +1 -1
  68. package/dist/migrate/hooks/codex-features-flag.d.ts.map +1 -1
  69. package/dist/migrate/hooks/codex-features-flag.js +21 -6
  70. package/dist/migrate/hooks/codex-features-flag.js.map +1 -1
  71. package/dist/migrate/hooks/codex-hook-wrapper.d.ts +15 -1
  72. package/dist/migrate/hooks/codex-hook-wrapper.d.ts.map +1 -1
  73. package/dist/migrate/hooks/codex-hook-wrapper.js +79 -8
  74. package/dist/migrate/hooks/codex-hook-wrapper.js.map +1 -1
  75. package/dist/migrate/hooks/codex-mcp-installer.d.ts +9 -0
  76. package/dist/migrate/hooks/codex-mcp-installer.d.ts.map +1 -0
  77. package/dist/migrate/hooks/codex-mcp-installer.js +65 -0
  78. package/dist/migrate/hooks/codex-mcp-installer.js.map +1 -0
  79. package/dist/migrate/hooks/codex-path-safety.d.ts +29 -0
  80. package/dist/migrate/hooks/codex-path-safety.d.ts.map +1 -1
  81. package/dist/migrate/hooks/codex-path-safety.js +36 -1
  82. package/dist/migrate/hooks/codex-path-safety.js.map +1 -1
  83. package/dist/migrate/hooks/codex-sh-wrapper-script.d.ts +8 -0
  84. package/dist/migrate/hooks/codex-sh-wrapper-script.d.ts.map +1 -0
  85. package/dist/migrate/hooks/codex-sh-wrapper-script.js +118 -0
  86. package/dist/migrate/hooks/codex-sh-wrapper-script.js.map +1 -0
  87. package/dist/migrate/hooks/codex-shell-env-installer.d.ts +14 -0
  88. package/dist/migrate/hooks/codex-shell-env-installer.d.ts.map +1 -0
  89. package/dist/migrate/hooks/codex-shell-env-installer.js +82 -0
  90. package/dist/migrate/hooks/codex-shell-env-installer.js.map +1 -0
  91. package/dist/migrate/hooks/codex-toml-installer.d.ts +2 -0
  92. package/dist/migrate/hooks/codex-toml-installer.d.ts.map +1 -1
  93. package/dist/migrate/hooks/codex-toml-installer.js +18 -7
  94. package/dist/migrate/hooks/codex-toml-installer.js.map +1 -1
  95. package/dist/migrate/hooks/hooks-settings-merger.d.ts +3 -0
  96. package/dist/migrate/hooks/hooks-settings-merger.d.ts.map +1 -1
  97. package/dist/migrate/hooks/hooks-settings-merger.js +157 -21
  98. package/dist/migrate/hooks/hooks-settings-merger.js.map +1 -1
  99. package/dist/migrate/migrate-orchestrator.d.ts +19 -0
  100. package/dist/migrate/migrate-orchestrator.d.ts.map +1 -1
  101. package/dist/migrate/migrate-orchestrator.js +233 -26
  102. package/dist/migrate/migrate-orchestrator.js.map +1 -1
  103. package/dist/migrate/migrate-ui-summary.d.ts +25 -0
  104. package/dist/migrate/migrate-ui-summary.d.ts.map +1 -1
  105. package/dist/migrate/migrate-ui-summary.js +50 -0
  106. package/dist/migrate/migrate-ui-summary.js.map +1 -1
  107. package/dist/migrate/model-routing-config.d.ts +3 -1
  108. package/dist/migrate/model-routing-config.d.ts.map +1 -1
  109. package/dist/migrate/model-routing-config.js +28 -0
  110. package/dist/migrate/model-routing-config.js.map +1 -1
  111. package/dist/migrate/portability-policy.d.ts +3 -1
  112. package/dist/migrate/portability-policy.d.ts.map +1 -1
  113. package/dist/migrate/portability-policy.js +5 -31
  114. package/dist/migrate/portability-policy.js.map +1 -1
  115. package/dist/migrate/portable-installer.d.ts +17 -1
  116. package/dist/migrate/portable-installer.d.ts.map +1 -1
  117. package/dist/migrate/portable-installer.js +171 -9
  118. package/dist/migrate/portable-installer.js.map +1 -1
  119. package/dist/migrate/provider-registry-utils.d.ts.map +1 -1
  120. package/dist/migrate/provider-registry-utils.js +5 -0
  121. package/dist/migrate/provider-registry-utils.js.map +1 -1
  122. package/dist/migrate/providers/codex/capabilities.d.ts +6 -1
  123. package/dist/migrate/providers/codex/capabilities.d.ts.map +1 -1
  124. package/dist/migrate/providers/codex/capabilities.js +87 -0
  125. package/dist/migrate/providers/codex/capabilities.js.map +1 -1
  126. package/dist/migrate/providers/codex/config.d.ts.map +1 -1
  127. package/dist/migrate/providers/codex/config.js +27 -8
  128. package/dist/migrate/providers/codex/config.js.map +1 -1
  129. package/dist/migrate/providers/codex/contract.d.ts.map +1 -1
  130. package/dist/migrate/providers/codex/contract.js +4 -3
  131. package/dist/migrate/providers/codex/contract.js.map +1 -1
  132. package/dist/migrate/providers/codex/shell-env-policy-emitter.d.ts +27 -0
  133. package/dist/migrate/providers/codex/shell-env-policy-emitter.d.ts.map +1 -0
  134. package/dist/migrate/providers/codex/shell-env-policy-emitter.js +86 -0
  135. package/dist/migrate/providers/codex/shell-env-policy-emitter.js.map +1 -0
  136. package/dist/migrate/providers/provider-config-types.d.ts +1 -1
  137. package/dist/migrate/providers/provider-config-types.d.ts.map +1 -1
  138. package/dist/migrate/reconcile/index.d.ts +1 -1
  139. package/dist/migrate/reconcile/index.d.ts.map +1 -1
  140. package/dist/migrate/reconcile/index.js +1 -1
  141. package/dist/migrate/reconcile/index.js.map +1 -1
  142. package/dist/migrate/reconcile/portable-manifest.d.ts +18 -12
  143. package/dist/migrate/reconcile/portable-manifest.d.ts.map +1 -1
  144. package/dist/migrate/reconcile/portable-manifest.js +23 -0
  145. package/dist/migrate/reconcile/portable-manifest.js.map +1 -1
  146. package/dist/migrate/reconcile/portable-registry.d.ts +30 -30
  147. package/dist/migrate/reconcile/process-lock.d.ts.map +1 -1
  148. package/dist/migrate/reconcile/process-lock.js +10 -1
  149. package/dist/migrate/reconcile/process-lock.js.map +1 -1
  150. package/dist/migrate/reconcile/reconcile-state-builders.d.ts +12 -5
  151. package/dist/migrate/reconcile/reconcile-state-builders.d.ts.map +1 -1
  152. package/dist/migrate/reconcile/reconcile-state-builders.js +2 -2
  153. package/dist/migrate/reconcile/reconcile-state-builders.js.map +1 -1
  154. package/dist/migrate/references/codex-command-skill-path.d.ts +12 -0
  155. package/dist/migrate/references/codex-command-skill-path.d.ts.map +1 -0
  156. package/dist/migrate/references/codex-command-skill-path.js +27 -0
  157. package/dist/migrate/references/codex-command-skill-path.js.map +1 -0
  158. package/dist/migrate/references/env-var-rewrite-table.d.ts +36 -0
  159. package/dist/migrate/references/env-var-rewrite-table.d.ts.map +1 -0
  160. package/dist/migrate/references/env-var-rewrite-table.js +97 -0
  161. package/dist/migrate/references/env-var-rewrite-table.js.map +1 -0
  162. package/dist/migrate/references/fence-aware-reference-rewriter.d.ts +30 -0
  163. package/dist/migrate/references/fence-aware-reference-rewriter.d.ts.map +1 -0
  164. package/dist/migrate/references/fence-aware-reference-rewriter.js +182 -0
  165. package/dist/migrate/references/fence-aware-reference-rewriter.js.map +1 -0
  166. package/dist/migrate/references/reference-classifier.d.ts +27 -0
  167. package/dist/migrate/references/reference-classifier.d.ts.map +1 -0
  168. package/dist/migrate/references/reference-classifier.js +177 -0
  169. package/dist/migrate/references/reference-classifier.js.map +1 -0
  170. package/dist/migrate/references/reference-target-registry.d.ts +42 -0
  171. package/dist/migrate/references/reference-target-registry.d.ts.map +1 -0
  172. package/dist/migrate/references/reference-target-registry.js +100 -0
  173. package/dist/migrate/references/reference-target-registry.js.map +1 -0
  174. package/dist/migrate/references/reference-types.d.ts +23 -0
  175. package/dist/migrate/references/reference-types.d.ts.map +1 -0
  176. package/dist/migrate/references/reference-types.js +5 -0
  177. package/dist/migrate/references/reference-types.js.map +1 -0
  178. package/dist/migrate/runtime-compat-audit.d.ts +3 -1
  179. package/dist/migrate/runtime-compat-audit.d.ts.map +1 -1
  180. package/dist/migrate/runtime-compat-audit.js +10 -5
  181. package/dist/migrate/runtime-compat-audit.js.map +1 -1
  182. package/dist/migrate/runtime-coupling-patterns.d.ts +32 -3
  183. package/dist/migrate/runtime-coupling-patterns.d.ts.map +1 -1
  184. package/dist/migrate/runtime-coupling-patterns.js +51 -8
  185. package/dist/migrate/runtime-coupling-patterns.js.map +1 -1
  186. package/dist/migrate/skill-directory-audit.d.ts +17 -0
  187. package/dist/migrate/skill-directory-audit.d.ts.map +1 -1
  188. package/dist/migrate/skill-directory-audit.js +70 -11
  189. package/dist/migrate/skill-directory-audit.js.map +1 -1
  190. package/dist/migrate/skill-directory-installer.d.ts +5 -0
  191. package/dist/migrate/skill-directory-installer.d.ts.map +1 -1
  192. package/dist/migrate/skill-directory-installer.js +115 -9
  193. package/dist/migrate/skill-directory-installer.js.map +1 -1
  194. package/dist/migrate/state-changing-script-detector.d.ts +16 -0
  195. package/dist/migrate/state-changing-script-detector.d.ts.map +1 -0
  196. package/dist/migrate/state-changing-script-detector.js +144 -0
  197. package/dist/migrate/state-changing-script-detector.js.map +1 -0
  198. package/dist/migrate/types.d.ts +20 -10
  199. package/dist/migrate/types.d.ts.map +1 -1
  200. package/dist/migrate/types.js +4 -0
  201. package/dist/migrate/types.js.map +1 -1
  202. package/dist/migrate/validation/migrate-conversion-report.d.ts +48 -0
  203. package/dist/migrate/validation/migrate-conversion-report.d.ts.map +1 -0
  204. package/dist/migrate/validation/migrate-conversion-report.js +146 -0
  205. package/dist/migrate/validation/migrate-conversion-report.js.map +1 -0
  206. package/dist/migrate/validation/migration-ledger-inputs.d.ts +56 -0
  207. package/dist/migrate/validation/migration-ledger-inputs.d.ts.map +1 -0
  208. package/dist/migrate/validation/migration-ledger-inputs.js +160 -0
  209. package/dist/migrate/validation/migration-ledger-inputs.js.map +1 -0
  210. package/dist/migrate/validation/migration-record-types.d.ts +38 -0
  211. package/dist/migrate/validation/migration-record-types.d.ts.map +1 -0
  212. package/dist/migrate/validation/migration-record-types.js +12 -0
  213. package/dist/migrate/validation/migration-record-types.js.map +1 -0
  214. package/dist/migrate/validation/migration-report-writer.d.ts +98 -0
  215. package/dist/migrate/validation/migration-report-writer.d.ts.map +1 -0
  216. package/dist/migrate/validation/migration-report-writer.js +0 -0
  217. package/dist/migrate/validation/migration-report-writer.js.map +1 -0
  218. package/dist/migrate/validation/unresolved-reference-scanner.d.ts +18 -0
  219. package/dist/migrate/validation/unresolved-reference-scanner.d.ts.map +1 -0
  220. package/dist/migrate/validation/unresolved-reference-scanner.js +47 -0
  221. package/dist/migrate/validation/unresolved-reference-scanner.js.map +1 -0
  222. package/package.json +1 -1
  223. package/portable-manifest.json +10 -2
@@ -0,0 +1,182 @@
1
+ // Fence-aware source-reference rewriter. Replaces the old binary rule
2
+ // ("fence = preserve everything" / "direct-copy = replace everything") with a
3
+ // span-based decision matrix:
4
+ //
5
+ // span mapped asset unmapped runtime citation
6
+ // prose/inline rewrite to target neutralize + record preserve
7
+ // frontmatter rewrite to target neutralize + record preserve
8
+ // fenced/code rewrite ONLY when the asset preserve + warn preserve
9
+ // is in the migration set,
10
+ // else preserve + warn
11
+ //
12
+ // Runnable content is never given a fabricated path: a fenced reference is only
13
+ // rewritten when the referenced asset is provably part of the migration set.
14
+ import { buildMarkdownSpanMap } from "./reference-classifier.js";
15
+ import { SOURCE_ROOT, buildReferenceRewriteTable, resolveReferenceTarget, sourceConfigTokenPattern, sourceReferencePattern, } from "./reference-target-registry.js";
16
+ /**
17
+ * Build an integrity index from source-relative entries. Entries ending with
18
+ * "/" match as directory prefixes (e.g. ".claude/skills/demo-skill/").
19
+ */
20
+ export function createReferenceIntegrityIndex(entries) {
21
+ const files = new Set();
22
+ const prefixes = [];
23
+ for (const entry of entries) {
24
+ const normalized = entry.replace(/\\/g, "/");
25
+ if (normalized.endsWith("/"))
26
+ prefixes.push(normalized.toLowerCase());
27
+ else
28
+ files.add(normalized.toLowerCase());
29
+ }
30
+ return {
31
+ has(sourceRelativePath) {
32
+ const normalized = sourceRelativePath.replace(/\\/g, "/").toLowerCase();
33
+ if (files.has(normalized))
34
+ return true;
35
+ return prefixes.some((prefix) => normalized.startsWith(prefix));
36
+ },
37
+ };
38
+ }
39
+ export function combineIntegrityIndexes(...indexes) {
40
+ const present = indexes.filter((index) => Boolean(index));
41
+ return { has: (path) => present.some((index) => index.has(path)) };
42
+ }
43
+ const TYPE_DIRS = ["agents", "commands", "skills", "rules", "hooks"];
44
+ // Provider-neutral phrases used when a reference has no provider target.
45
+ const NEUTRAL_TYPE_PHRASE = {
46
+ rules: "project rules directory/",
47
+ agents: "project subagents directory/",
48
+ commands: "project commands directory/",
49
+ skills: "project skills directory/",
50
+ hooks: "project hooks directory/",
51
+ };
52
+ const NEUTRAL_ROOT_PHRASE = "project runtime data/";
53
+ const NEUTRAL_CONFIG_PHRASE = "project configuration file";
54
+ function classifySourcePath(path, table) {
55
+ const suffix = path.slice(SOURCE_ROOT.length);
56
+ const typeDir = TYPE_DIRS.find((dir) => suffix.toLowerCase().startsWith(`${dir}/`));
57
+ const target = resolveReferenceTarget(table, path);
58
+ if (target !== null) {
59
+ const rule = table.find((r) => path.toLowerCase().startsWith(r.sourcePrefix.toLowerCase()));
60
+ return {
61
+ kind: "mapped-asset",
62
+ target,
63
+ preservesSuffix: rule?.target?.isDirectory ?? false,
64
+ neutral: "",
65
+ reason: "",
66
+ };
67
+ }
68
+ if (typeDir) {
69
+ return {
70
+ kind: "unmapped-runtime",
71
+ target: null,
72
+ preservesSuffix: false,
73
+ neutral: `${NEUTRAL_TYPE_PHRASE[typeDir]}${suffix.slice(typeDir.length + 1)}`,
74
+ reason: `provider has no ${typeDir} surface`,
75
+ };
76
+ }
77
+ return {
78
+ kind: "unmapped-runtime",
79
+ target: null,
80
+ preservesSuffix: false,
81
+ neutral: `${NEUTRAL_ROOT_PHRASE}${suffix}`,
82
+ reason: "no provider equivalent for this source runtime path",
83
+ };
84
+ }
85
+ export function rewriteSourceReferences(content, options) {
86
+ const table = buildReferenceRewriteTable(options.provider, options.scope ?? "project");
87
+ const occurrences = [];
88
+ const warnings = [];
89
+ const file = options.file ?? "";
90
+ const record = (occurrence) => {
91
+ occurrences.push(occurrence);
92
+ if (occurrence.decision === "preserve-warn") {
93
+ warnings.push(`Unresolved reference preserved (line ${occurrence.line}): "${occurrence.original}" — ${occurrence.reason}`);
94
+ }
95
+ };
96
+ // Each replace pass shifts byte offsets, so the span map is rebuilt per pass.
97
+ const buildSpanHelpers = (input) => {
98
+ const spanMap = options.contentKind === "code" ? null : buildMarkdownSpanMap(input);
99
+ return {
100
+ spanAt: (offset) => spanMap?.spanAt(offset) ?? "fenced",
101
+ lineAt: (offset) => {
102
+ if (spanMap)
103
+ return spanMap.lineNumberAt(offset);
104
+ let line = 1;
105
+ for (let i = 0; i < offset && i < input.length; i++)
106
+ if (input[i] === "\n")
107
+ line++;
108
+ return line;
109
+ },
110
+ isCitationAt: (offset) => spanMap?.isCitationAt(offset) ?? false,
111
+ };
112
+ };
113
+ let { spanAt, lineAt, isCitationAt } = buildSpanHelpers(content);
114
+ let result = content.replace(sourceReferencePattern(), (matched, ...args) => {
115
+ const offset = args[args.length - 2];
116
+ const span = spanAt(offset);
117
+ const line = lineAt(offset);
118
+ const base = { file, line, span, original: matched };
119
+ if (isCitationAt(offset)) {
120
+ record({ ...base, kind: "citation", decision: "preserve" });
121
+ return matched;
122
+ }
123
+ const classified = classifySourcePath(matched, table);
124
+ const runnable = span === "fenced";
125
+ if (!runnable) {
126
+ if (classified.kind === "mapped-asset" && classified.target !== null) {
127
+ record({ ...base, kind: "mapped-asset", decision: "rewrite", rewrittenTo: classified.target });
128
+ return classified.target;
129
+ }
130
+ record({
131
+ ...base,
132
+ kind: "unmapped-runtime",
133
+ decision: "rewrite",
134
+ rewrittenTo: classified.neutral,
135
+ reason: `${classified.reason}; neutralized`,
136
+ });
137
+ return classified.neutral;
138
+ }
139
+ // Runnable content: rewrite only with proof the referenced asset migrates
140
+ // too AND the target keeps the file suffix — a merged/non-directory target
141
+ // cannot express the file's real location, so rewriting would fabricate.
142
+ if (classified.kind === "mapped-asset" && classified.target !== null) {
143
+ if (classified.preservesSuffix && options.migratedRefs?.has(matched)) {
144
+ record({ ...base, kind: "mapped-asset", decision: "rewrite", rewrittenTo: classified.target });
145
+ return classified.target;
146
+ }
147
+ record({
148
+ ...base,
149
+ kind: "mapped-asset",
150
+ decision: "preserve-warn",
151
+ reason: classified.preservesSuffix
152
+ ? "referenced asset is not part of this migration; left unchanged instead of guessing a target path"
153
+ : "target surface is merged/non-directory; original path preserved to avoid a fabricated location",
154
+ });
155
+ return matched;
156
+ }
157
+ record({ ...base, kind: "unmapped-runtime", decision: "preserve-warn", reason: classified.reason });
158
+ return matched;
159
+ });
160
+ ({ spanAt, lineAt, isCitationAt } = buildSpanHelpers(result));
161
+ const configTarget = resolveReferenceTarget(table, "CLAUDE.md");
162
+ const configReplacement = configTarget ?? NEUTRAL_CONFIG_PHRASE;
163
+ result = result.replace(sourceConfigTokenPattern(), (matched, ...args) => {
164
+ const offset = args[args.length - 2];
165
+ const span = spanAt(offset);
166
+ const line = lineAt(offset);
167
+ const base = { file, line, span, original: matched };
168
+ if (isCitationAt(offset)) {
169
+ record({ ...base, kind: "citation", decision: "preserve" });
170
+ return matched;
171
+ }
172
+ if (span === "fenced") {
173
+ // Command examples keep the literal token — a rename would break the example.
174
+ record({ ...base, kind: "mapped-asset", decision: "preserve" });
175
+ return matched;
176
+ }
177
+ record({ ...base, kind: "mapped-asset", decision: "rewrite", rewrittenTo: configReplacement });
178
+ return configReplacement;
179
+ });
180
+ return { content: result, occurrences, warnings };
181
+ }
182
+ //# sourceMappingURL=fence-aware-reference-rewriter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fence-aware-reference-rewriter.js","sourceRoot":"","sources":["../../../src/migrate/references/fence-aware-reference-rewriter.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,8EAA8E;AAC9E,8BAA8B;AAC9B,EAAE;AACF,iFAAiF;AACjF,iFAAiF;AACjF,iFAAiF;AACjF,iFAAiF;AACjF,6CAA6C;AAC7C,yCAAyC;AACzC,EAAE;AACF,gFAAgF;AAChF,6EAA6E;AAE7E,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EACN,WAAW,EACX,0BAA0B,EAC1B,sBAAsB,EACtB,wBAAwB,EACxB,sBAAsB,GAGtB,MAAM,gCAAgC,CAAC;AASxC;;;GAGG;AACH,MAAM,UAAU,6BAA6B,CAAC,OAAyB;IACtE,MAAM,KAAK,GAAG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SAAS,EAAE,WAAW,EAAE,iBAAiB,EAAE,CAAC,CAAC;QAC/F,OAAO,iBAAiB,CAAC;IAC1B,CAAC,CAAC,CAAC;IAEH,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC;AACnD,CAAC"}
@@ -0,0 +1,27 @@
1
+ import type { ReferenceSpan } from "./reference-types.js";
2
+ export interface EnvReferenceClassification {
3
+ /** Provider-neutral replacement phrase pointing at the emitted policy scaffold. */
4
+ neutral: string;
5
+ /** Human-readable reason for the migration report (supersedes "no equivalent"). */
6
+ reason: string;
7
+ }
8
+ /** True when `path` is a `.claude/.env` (or `.env.*`) source reference. */
9
+ export declare function isEnvReference(path: string): boolean;
10
+ /**
11
+ * Classify a `.claude/.env` reference to point at the emitted Codex
12
+ * `[shell_environment_policy]` scaffold, replacing the old "no provider
13
+ * equivalent" classification. Returns null for any non-`.env` path so callers
14
+ * can fall through to their existing classification.
15
+ */
16
+ export declare function classifyEnvReference(path: string): EnvReferenceClassification | null;
17
+ export declare function isCitationLine(line: string): boolean;
18
+ export interface MarkdownSpanMap {
19
+ /** Span type at a byte offset in the original content */
20
+ spanAt(offset: number): ReferenceSpan;
21
+ /** 1-based line number at a byte offset */
22
+ lineNumberAt(offset: number): number;
23
+ /** Whether the line containing the offset is a citation/attribution line */
24
+ isCitationAt(offset: number): boolean;
25
+ }
26
+ export declare function buildMarkdownSpanMap(content: string): MarkdownSpanMap;
27
+ //# sourceMappingURL=reference-classifier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reference-classifier.d.ts","sourceRoot":"","sources":["../../../src/migrate/references/reference-classifier.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAkB1D,MAAM,WAAW,0BAA0B;IAC1C,mFAAmF;IACnF,OAAO,EAAE,MAAM,CAAC;IAChB,mFAAmF;IACnF,MAAM,EAAE,MAAM,CAAC;CACf;AAED,2EAA2E;AAC3E,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEpD;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,0BAA0B,GAAG,IAAI,CAQpF;AAcD,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAKpD;AAID,MAAM,WAAW,eAAe;IAC/B,yDAAyD;IACzD,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IACtC,2CAA2C;IAC3C,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IACrC,4EAA4E;IAC5E,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;CACtC;AAuFD,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,CAkCrE"}
@@ -0,0 +1,177 @@
1
+ // Markdown span tokenizer + citation detection for source-reference rewriting.
2
+ // Span resolution is line-based (frontmatter / fenced) with per-line inline-code
3
+ // detection. Ambiguous structures (unclosed fences) resolve to "fenced" so the
4
+ // rewriter stays conservative — never rewrite on uncertainty.
5
+ // --- .claude/.env reference classification --------------------------------
6
+ //
7
+ // A `.claude/.env` reference used to fall into the generic "no provider
8
+ // equivalent for this source runtime path" bucket. That is now outdated at the
9
+ // CONFIG level: Codex's documented `[shell_environment_policy]` is the analogue
10
+ // for passing environment into shell subprocesses, and the migration emits a
11
+ // keys-only scaffold for it (see shell-env-policy-emitter). This helper lets the
12
+ // reference rewriter reclassify `.claude/.env` occurrences to POINT AT that
13
+ // scaffold instead of the dead-end "no equivalent" phrase.
14
+ //
15
+ // SECURITY: this helper deals only with the reference PATH text (e.g. the string
16
+ // ".claude/.env"), never with env values.
17
+ /** Matches a source `.claude/.env` (optionally `.env.<suffix>`) path reference. */
18
+ const ENV_REFERENCE = /^\.claude\/\.env(\.[A-Za-z0-9_.-]+)?$/i;
19
+ /** True when `path` is a `.claude/.env` (or `.env.*`) source reference. */
20
+ export function isEnvReference(path) {
21
+ return ENV_REFERENCE.test(path.replace(/\\/g, "/").trim());
22
+ }
23
+ /**
24
+ * Classify a `.claude/.env` reference to point at the emitted Codex
25
+ * `[shell_environment_policy]` scaffold, replacing the old "no provider
26
+ * equivalent" classification. Returns null for any non-`.env` path so callers
27
+ * can fall through to their existing classification.
28
+ */
29
+ export function classifyEnvReference(path) {
30
+ if (!isEnvReference(path))
31
+ return null;
32
+ return {
33
+ neutral: "the generated [shell_environment_policy] scaffold in config.toml",
34
+ reason: "environment variables now map to the Codex [shell_environment_policy] scaffold " +
35
+ "(keys-only, placeholder values); fill values from your environment — do not paste secrets",
36
+ };
37
+ }
38
+ const FENCE_OPEN = /^ {0,3}(`{3,}|~{3,})/;
39
+ const FRONTMATTER_DELIMITER = /^---\s*$/;
40
+ // A line is a citation when it leads with an attribution verb, or is a
41
+ // blockquote carrying an external URL or a repo slug next to an attribution dash.
42
+ const CITATION_LEAD = /^(?:>\s*)*(?:source|from|ported\s+from)\b/i;
43
+ const BLOCKQUOTE = /^\s*>/;
44
+ const EXTERNAL_URL = /https?:\/\//i;
45
+ // Repo slug like "org/repo"; the lookbehind rejects path segments (".claude/rules", "a/b/c").
46
+ const REPO_SLUG = /(?<![\w./])[a-z0-9][\w.-]*\/[a-z0-9][\w.-]*(?![\w/])/i;
47
+ const ATTRIBUTION_DASH = /[—–]/;
48
+ export function isCitationLine(line) {
49
+ const trimmed = line.trim();
50
+ if (CITATION_LEAD.test(trimmed))
51
+ return true;
52
+ if (!BLOCKQUOTE.test(trimmed))
53
+ return false;
54
+ return EXTERNAL_URL.test(trimmed) || (REPO_SLUG.test(trimmed) && ATTRIBUTION_DASH.test(trimmed));
55
+ }
56
+ function buildLineStarts(content) {
57
+ const starts = [0];
58
+ for (let i = 0; i < content.length; i++) {
59
+ if (content[i] === "\n")
60
+ starts.push(i + 1);
61
+ }
62
+ return starts;
63
+ }
64
+ function lineIndexAt(lineStarts, offset) {
65
+ let lo = 0;
66
+ let hi = lineStarts.length - 1;
67
+ while (lo < hi) {
68
+ const mid = (lo + hi + 1) >> 1;
69
+ if (lineStarts[mid] <= offset)
70
+ lo = mid;
71
+ else
72
+ hi = mid - 1;
73
+ }
74
+ return lo;
75
+ }
76
+ function classifyLines(lines) {
77
+ const kinds = new Array(lines.length).fill("other");
78
+ let i = 0;
79
+ if (lines.length > 0 && FRONTMATTER_DELIMITER.test(lines[0])) {
80
+ const close = lines.findIndex((line, idx) => idx > 0 && FRONTMATTER_DELIMITER.test(line));
81
+ if (close > 0) {
82
+ for (let j = 0; j <= close; j++)
83
+ kinds[j] = "frontmatter";
84
+ i = close + 1;
85
+ }
86
+ }
87
+ let fenceMarker = null;
88
+ for (; i < lines.length; i++) {
89
+ const line = lines[i];
90
+ if (fenceMarker) {
91
+ kinds[i] = "fenced";
92
+ const close = line.match(FENCE_OPEN);
93
+ if (close && close[1][0] === fenceMarker.char && close[1].length >= fenceMarker.length && !line.trim().slice(close[1].length)) {
94
+ fenceMarker = null;
95
+ }
96
+ continue;
97
+ }
98
+ const open = line.match(FENCE_OPEN);
99
+ if (open) {
100
+ kinds[i] = "fenced";
101
+ fenceMarker = { char: open[1][0], length: open[1].length };
102
+ }
103
+ }
104
+ // An unclosed fence leaves fenceMarker set — remaining lines were already
105
+ // marked fenced inside the loop, which is the conservative resolution.
106
+ return kinds;
107
+ }
108
+ /** Inline code span ranges (column offsets, delimiters included) for one line. */
109
+ function inlineCodeRanges(line) {
110
+ const ranges = [];
111
+ let i = 0;
112
+ while (i < line.length) {
113
+ if (line[i] !== "`") {
114
+ i++;
115
+ continue;
116
+ }
117
+ let openLen = 0;
118
+ while (line[i + openLen] === "`")
119
+ openLen++;
120
+ const openEnd = i + openLen;
121
+ // Find a closing run of the same length.
122
+ let j = openEnd;
123
+ while (j < line.length) {
124
+ if (line[j] !== "`") {
125
+ j++;
126
+ continue;
127
+ }
128
+ let runLen = 0;
129
+ while (line[j + runLen] === "`")
130
+ runLen++;
131
+ if (runLen === openLen) {
132
+ ranges.push([i, j + runLen]);
133
+ break;
134
+ }
135
+ j += runLen;
136
+ }
137
+ i = j < line.length ? j + openLen : openEnd;
138
+ }
139
+ return ranges;
140
+ }
141
+ export function buildMarkdownSpanMap(content) {
142
+ const lines = content.split("\n");
143
+ const lineStarts = buildLineStarts(content);
144
+ const lineKinds = classifyLines(lines);
145
+ const citationCache = new Map();
146
+ const inlineCache = new Map();
147
+ return {
148
+ spanAt(offset) {
149
+ const lineIdx = lineIndexAt(lineStarts, offset);
150
+ const kind = lineKinds[lineIdx];
151
+ if (kind === "frontmatter")
152
+ return "frontmatter";
153
+ if (kind === "fenced")
154
+ return "fenced";
155
+ let ranges = inlineCache.get(lineIdx);
156
+ if (!ranges) {
157
+ ranges = inlineCodeRanges(lines[lineIdx]);
158
+ inlineCache.set(lineIdx, ranges);
159
+ }
160
+ const column = offset - lineStarts[lineIdx];
161
+ return ranges.some(([start, end]) => column >= start && column < end) ? "inline-code" : "prose";
162
+ },
163
+ lineNumberAt(offset) {
164
+ return lineIndexAt(lineStarts, offset) + 1;
165
+ },
166
+ isCitationAt(offset) {
167
+ const lineIdx = lineIndexAt(lineStarts, offset);
168
+ let cached = citationCache.get(lineIdx);
169
+ if (cached === undefined) {
170
+ cached = isCitationLine(lines[lineIdx]);
171
+ citationCache.set(lineIdx, cached);
172
+ }
173
+ return cached;
174
+ },
175
+ };
176
+ }
177
+ //# sourceMappingURL=reference-classifier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reference-classifier.js","sourceRoot":"","sources":["../../../src/migrate/references/reference-classifier.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,iFAAiF;AACjF,+EAA+E;AAC/E,8DAA8D;AAI9D,6EAA6E;AAC7E,EAAE;AACF,wEAAwE;AACxE,+EAA+E;AAC/E,gFAAgF;AAChF,6EAA6E;AAC7E,iFAAiF;AACjF,4EAA4E;AAC5E,2DAA2D;AAC3D,EAAE;AACF,iFAAiF;AACjF,0CA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,MAAM,KAAK,SAAS,EAAE,CAAC;gBAC1B,MAAM,GAAG,cAAc,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;gBACxC,aAAa,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;YACpC,CAAC;YACD,OAAO,MAAM,CAAC;QACf,CAAC;KACD,CAAC;AACH,CAAC"}
@@ -0,0 +1,42 @@
1
+ import type { ProviderType } from "../types.js";
2
+ /** Portable-type keys that have a per-provider target path */
3
+ export type ReferenceTargetType = "agents" | "commands" | "skills" | "rules" | "config" | "hooks";
4
+ export type ReferenceScope = "project" | "global";
5
+ export interface ReferenceTarget {
6
+ /** Normalized target path; ends with "/" when it is a directory */
7
+ path: string;
8
+ isDirectory: boolean;
9
+ }
10
+ export interface ReferenceRewriteRule {
11
+ type: ReferenceTargetType;
12
+ /** Source path prefix this rule matches (e.g. ".claude/agents/") */
13
+ sourcePrefix: string;
14
+ /** Resolved provider target, or null when the provider has no such surface */
15
+ target: ReferenceTarget | null;
16
+ /** Special-case suffix mapping (e.g. Codex command → skill directory filename) */
17
+ resolveSuffix?: (suffix: string) => string;
18
+ }
19
+ /** Root of the source runtime tree. The only place this literal may appear. */
20
+ export declare const SOURCE_ROOT = ".claude/";
21
+ /** Source config filename token */
22
+ export declare const SOURCE_CONFIG_TOKEN = "CLAUDE.md";
23
+ export declare function sourcePrefixForType(type: ReferenceTargetType): string;
24
+ /**
25
+ * Resolve the provider target for one portable type. Mirrors the historical
26
+ * md-strip resolution exactly: prefer the scope's path, fall back to the other.
27
+ */
28
+ export declare function getReferenceTarget(provider: ProviderType | undefined, type: ReferenceTargetType, scope?: ReferenceScope): ReferenceTarget | null;
29
+ /** Build the full rewrite table for one provider (one rule per portable type). */
30
+ export declare function buildReferenceRewriteTable(provider: ProviderType | undefined, scope?: ReferenceScope): ReferenceRewriteRule[];
31
+ /**
32
+ * Resolve one source path (e.g. ".claude/skills/x/run.py") against a rewrite
33
+ * table. Returns the rewritten target path, or null when unmapped.
34
+ */
35
+ export declare function resolveReferenceTarget(table: ReferenceRewriteRule[], sourcePath: string): string | null;
36
+ /** Any `.claude/<path>` reference, longest path-like run captured */
37
+ export declare function sourceReferencePattern(): RegExp;
38
+ /** Line filter used when the provider has no hooks surface */
39
+ export declare function sourceHooksLinePattern(): RegExp;
40
+ /** The `CLAUDE.md` token in prose */
41
+ export declare function sourceConfigTokenPattern(): RegExp;
42
+ //# sourceMappingURL=reference-target-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reference-target-registry.d.ts","sourceRoot":"","sources":["../../../src/migrate/references/reference-target-registry.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,8DAA8D;AAC9D,MAAM,MAAM,mBAAmB,GAAG,QAAQ,GAAG,UAAU,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;AAElG,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,QAAQ,CAAC;AAElD,MAAM,WAAW,eAAe;IAC/B,mEAAmE;IACnE,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,oBAAoB;IACpC,IAAI,EAAE,mBAAmB,CAAC;IAC1B,oEAAoE;IACpE,YAAY,EAAE,MAAM,CAAC;IACrB,8EAA8E;IAC9E,MAAM,EAAE,eAAe,GAAG,IAAI,CAAC;IAC/B,kFAAkF;IAClF,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC;CAC3C;AAED,+EAA+E;AAC/E,eAAO,MAAM,WAAW,aAAa,CAAC;AAEtC,mCAAmC;AACnC,eAAO,MAAM,mBAAmB,cAAc,CAAC;AAI/C,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,mBAAmB,GAAG,MAAM,CAErE;AAQD;;;GAGG;AACH,wBAAgB,kBAAkB,CACjC,QAAQ,EAAE,YAAY,GAAG,SAAS,EAClC,IAAI,EAAE,mBAAmB,EACzB,KAAK,GAAE,cAA0B,GAC/B,eAAe,GAAG,IAAI,CAoBxB;AAED,kFAAkF;AAClF,wBAAgB,0BAA0B,CACzC,QAAQ,EAAE,YAAY,GAAG,SAAS,EAClC,KAAK,GAAE,cAA0B,GAC/B,oBAAoB,EAAE,CAcxB;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,oBAAoB,EAAE,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAgBvG;AAMD,qEAAqE;AACrE,wBAAgB,sBAAsB,IAAI,MAAM,CAE/C;AAED,8DAA8D;AAC9D,wBAAgB,sBAAsB,IAAI,MAAM,CAE/C;AAED,qCAAqC;AACrC,wBAAgB,wBAAwB,IAAI,MAAM,CAEjD"}
@@ -0,0 +1,100 @@
1
+ // Single source of truth for rewriting source-runtime references
2
+ // (`.claude/<type>/...`, `CLAUDE.md`) to provider target paths. All mapping
3
+ // strings and source patterns live HERE — converters must consume this module
4
+ // instead of holding their own literals (guarded by a unit test).
5
+ import { homedir } from "node:os";
6
+ import { providers } from "../provider-registry.js";
7
+ import { codexCommandSkillRelativePath } from "./codex-command-skill-path.js";
8
+ /** Root of the source runtime tree. The only place this literal may appear. */
9
+ export const SOURCE_ROOT = ".claude/";
10
+ /** Source config filename token */
11
+ export const SOURCE_CONFIG_TOKEN = "CLAUDE.md";
12
+ const DIRECTORY_TYPES = ["agents", "commands", "skills", "rules", "hooks"];
13
+ export function sourcePrefixForType(type) {
14
+ return type === "config" ? SOURCE_CONFIG_TOKEN : `${SOURCE_ROOT}${type}/`;
15
+ }
16
+ function normalizeTargetPath(path) {
17
+ const normalized = path.replace(/\\/g, "/").replace(/^\.\//, "");
18
+ const home = homedir().replace(/\\/g, "/");
19
+ return normalized.startsWith(home) ? normalized.replace(home, "~") : normalized;
20
+ }
21
+ /**
22
+ * Resolve the provider target for one portable type. Mirrors the historical
23
+ * md-strip resolution exactly: prefer the scope's path, fall back to the other.
24
+ */
25
+ export function getReferenceTarget(provider, type, scope = "project") {
26
+ if (!provider)
27
+ return null;
28
+ const pathConfig = providers[provider][type];
29
+ if (!pathConfig)
30
+ return null;
31
+ const resolvedPath = scope === "global"
32
+ ? (pathConfig.globalPath ?? pathConfig.projectPath)
33
+ : (pathConfig.projectPath ?? pathConfig.globalPath);
34
+ if (!resolvedPath)
35
+ return null;
36
+ const normalized = normalizeTargetPath(resolvedPath);
37
+ const isDirectory = pathConfig.writeStrategy === "per-file" ||
38
+ pathConfig.writeStrategy === "yaml-merge" ||
39
+ pathConfig.writeStrategy === "json-merge";
40
+ return {
41
+ path: isDirectory && !normalized.endsWith("/") ? `${normalized}/` : normalized,
42
+ isDirectory,
43
+ };
44
+ }
45
+ /** Build the full rewrite table for one provider (one rule per portable type). */
46
+ export function buildReferenceRewriteTable(provider, scope = "project") {
47
+ const types = [...DIRECTORY_TYPES, "config"];
48
+ return types.map((type) => {
49
+ const rule = {
50
+ type,
51
+ sourcePrefix: sourcePrefixForType(type),
52
+ target: getReferenceTarget(provider, type, scope),
53
+ };
54
+ // Commands that install as Agent Skills live in one directory per command.
55
+ if (type === "commands" && provider && providers[provider].commands?.format === "command-to-codex-skill") {
56
+ rule.resolveSuffix = (suffix) => codexCommandSkillRelativePath(suffix);
57
+ }
58
+ return rule;
59
+ });
60
+ }
61
+ /**
62
+ * Resolve one source path (e.g. ".claude/skills/x/run.py") against a rewrite
63
+ * table. Returns the rewritten target path, or null when unmapped.
64
+ */
65
+ export function resolveReferenceTarget(table, sourcePath) {
66
+ const normalized = sourcePath.replace(/\\/g, "/");
67
+ for (const rule of table) {
68
+ if (rule.type === "config") {
69
+ if (normalized === rule.sourcePrefix)
70
+ return rule.target?.path ?? null;
71
+ continue;
72
+ }
73
+ if (!normalized.toLowerCase().startsWith(rule.sourcePrefix.toLowerCase()))
74
+ continue;
75
+ if (!rule.target)
76
+ return null;
77
+ const suffix = normalized.slice(rule.sourcePrefix.length);
78
+ if (rule.resolveSuffix && rule.target.isDirectory && suffix) {
79
+ return `${rule.target.path}${rule.resolveSuffix(suffix)}`;
80
+ }
81
+ return rule.target.isDirectory ? `${rule.target.path}${suffix}` : rule.target.path;
82
+ }
83
+ return null;
84
+ }
85
+ // --- Source patterns ------------------------------------------------------
86
+ // Regexes matching source references. Kept as factory functions so every
87
+ // caller gets fresh lastIndex state for the global flags.
88
+ /** Any `.claude/<path>` reference, longest path-like run captured */
89
+ export function sourceReferencePattern() {
90
+ return /\.claude\/[a-zA-Z0-9_./-]*/gi;
91
+ }
92
+ /** Line filter used when the provider has no hooks surface */
93
+ export function sourceHooksLinePattern() {
94
+ return /\.claude\/hooks\//i;
95
+ }
96
+ /** The `CLAUDE.md` token in prose */
97
+ export function sourceConfigTokenPattern() {
98
+ return /\bCLAUDE\.md\b/g;
99
+ }
100
+ //# sourceMappingURL=reference-target-registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reference-target-registry.js","sourceRoot":"","sources":["../../../src/migrate/references/reference-target-registry.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,4EAA4E;AAC5E,8EAA8E;AAC9E,kEAAkE;AAElE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,6BAA6B,EAAE,MAAM,+BAA+B,CAAC;AAwB9E,+EAA+E;AAC/E,MAAM,CAAC,MAAM,WAAW,GAAG,UAAU,CAAC;AAEtC,mCAAmC;AACnC,MAAM,CAAC,MAAM,mBAAmB,GAAG,WAAW,CAAC;AAE/C,MAAM,eAAe,GAA0B,CAAC,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AAElG,MAAM,UAAU,mBAAmB,CAAC,IAAyB;IAC5D,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,GAAG,WA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;QACpF,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,OAAO,IAAI,CAAC;QAC9B,MAAM,MAAM,GAAG,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QAC1D,IAAI,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,MAAM,CAAC,WAAW,IAAI,MAAM,EAAE,CAAC;YAC7D,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC;QAC3D,CAAC;QACD,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,GAAG,MAAM,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;IACpF,CAAC;IACD,OAAO,IAAI,CAAC;AACb,CAAC;AAED,6EAA6E;AAC7E,yEAAyE;AACzE,0DAA0D;AAE1D,qEAAqE;AACrE,MAAM,UAAU,sBAAsB;IACrC,OAAO,8BAA8B,CAAC;AACvC,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,sBAAsB;IACrC,OAAO,oBAAoB,CAAC;AAC7B,CAAC;AAED,qCAAqC;AACrC,MAAM,UAAU,wBAAwB;IACvC,OAAO,iBAAiB,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,23 @@
1
+ /** Markdown span the occurrence was found in */
2
+ export type ReferenceSpan = "frontmatter" | "fenced" | "inline-code" | "prose";
3
+ /** What the reference points at */
4
+ export type ReferenceKind = "mapped-asset" | "unmapped-runtime" | "citation" | "brand" | "env" | "slash-command";
5
+ /** What the rewriter decided to do with the occurrence */
6
+ export type RewriteDecision = "rewrite" | "preserve" | "preserve-warn";
7
+ /** One classified occurrence, emitted so the report layer can surface every decision */
8
+ export interface ReferenceOccurrence {
9
+ /** File the occurrence belongs to (target-relative filename or source path) */
10
+ file: string;
11
+ /** 1-based line number in the scanned content */
12
+ line: number;
13
+ span: ReferenceSpan;
14
+ kind: ReferenceKind;
15
+ decision: RewriteDecision;
16
+ /** The matched source text */
17
+ original: string;
18
+ /** Present when decision === "rewrite" */
19
+ rewrittenTo?: string;
20
+ /** Human-readable reason for preserve-warn decisions */
21
+ reason?: string;
22
+ }
23
+ //# sourceMappingURL=reference-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reference-types.d.ts","sourceRoot":"","sources":["../../../src/migrate/references/reference-types.ts"],"names":[],"mappings":"AAIA,gDAAgD;AAChD,MAAM,MAAM,aAAa,GAAG,aAAa,GAAG,QAAQ,GAAG,aAAa,GAAG,OAAO,CAAC;AAE/E,mCAAmC;AACnC,MAAM,MAAM,aAAa,GACtB,cAAc,GACd,kBAAkB,GAClB,UAAU,GACV,OAAO,GACP,KAAK,GACL,eAAe,CAAC;AAEnB,0DAA0D;AAC1D,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,UAAU,GAAG,eAAe,CAAC;AAEvE,wFAAwF;AACxF,MAAM,WAAW,mBAAmB;IACnC,+EAA+E;IAC/E,IAAI,EAAE,MAAM,CAAC;IACb,iDAAiD;IACjD,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,aAAa,CAAC;IACpB,IAAI,EAAE,aAAa,CAAC;IACpB,QAAQ,EAAE,eAAe,CAAC;IAC1B,8BAA8B;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,0CAA0C;IAC1C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wDAAwD;IACxD,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB"}
@@ -0,0 +1,5 @@
1
+ // Shared types for source-reference classification and rewriting.
2
+ // A "reference" is any occurrence of a source-runtime path (`.claude/...`) or
3
+ // the source config token (`CLAUDE.md`) inside migrated content.
4
+ export {};
5
+ //# sourceMappingURL=reference-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reference-types.js","sourceRoot":"","sources":["../../../src/migrate/references/reference-types.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,8EAA8E;AAC9E,iEAAiE"}
@@ -1,6 +1,8 @@
1
1
  import type { PortableItem, ProviderType } from "./types.js";
2
+ import type { ReferenceOccurrence } from "./references/reference-types.js";
2
3
  export interface RuntimeCompatAuditResult {
3
4
  errors: string[];
5
+ warnings: string[];
4
6
  }
5
- export declare function auditRuntimeCompatibility(content: string, item: Pick<PortableItem, "name" | "type">, targetProvider: ProviderType): RuntimeCompatAuditResult;
7
+ export declare function auditRuntimeCompatibility(content: string, item: Pick<PortableItem, "name" | "type">, targetProvider: ProviderType, occurrences?: ReferenceOccurrence[]): RuntimeCompatAuditResult;
6
8
  //# sourceMappingURL=runtime-compat-audit.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"runtime-compat-audit.d.ts","sourceRoot":"","sources":["../../src/migrate/runtime-compat-audit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAgB,YAAY,EAAE,MAAM,YAAY,CAAC;AAG3E,MAAM,WAAW,wBAAwB;IACxC,MAAM,EAAE,MAAM,EAAE,CAAC;CACjB;AAID,wBAAgB,yBAAyB,CACxC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,IAAI,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAAC,EACzC,cAAc,EAAE,YAAY,GAC1B,wBAAwB,CAU1B"}
1
+ {"version":3,"file":"runtime-compat-audit.d.ts","sourceRoot":"","sources":["../../src/migrate/runtime-compat-audit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAgB,YAAY,EAAE,MAAM,YAAY,CAAC;AAC3E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAG3E,MAAM,WAAW,wBAAwB;IACxC,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACnB;AAID,wBAAgB,yBAAyB,CACxC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,IAAI,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAAC,EACzC,cAAc,EAAE,YAAY,EAC5B,WAAW,GAAE,mBAAmB,EAAO,GACrC,wBAAwB,CAe1B"}