@el-j/magic-helix-core 4.0.0-beta.1 → 4.0.0-beta.3

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 (160) hide show
  1. package/dist/index-B88j4AyE.js +13 -0
  2. package/dist/index-B88j4AyE.js.map +1 -0
  3. package/dist/index-CY-pQbuu.cjs +2 -0
  4. package/dist/index-CY-pQbuu.cjs.map +1 -0
  5. package/dist/index.cjs +75 -1
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.ts +0 -1
  8. package/dist/index.mjs +2234 -51
  9. package/dist/index.mjs.map +1 -1
  10. package/dist/pattern-combiner.d.ts +1 -1
  11. package/dist/plugin-loader.d.ts +7 -1
  12. package/package.json +4 -4
  13. package/dist/BasePlugin-6wv0hYJ9.js +0 -98
  14. package/dist/BasePlugin-6wv0hYJ9.js.map +0 -1
  15. package/dist/BasePlugin-odQJAKA-.cjs +0 -2
  16. package/dist/BasePlugin-odQJAKA-.cjs.map +0 -1
  17. package/dist/builtin-plugins/base/BasePlugin.d.ts +0 -69
  18. package/dist/builtin-plugins/csharp/index.d.ts +0 -20
  19. package/dist/builtin-plugins/go/index.d.ts +0 -23
  20. package/dist/builtin-plugins/index.d.ts +0 -15
  21. package/dist/builtin-plugins/java/index.d.ts +0 -22
  22. package/dist/builtin-plugins/nodejs/index.d.ts +0 -44
  23. package/dist/builtin-plugins/php/index.d.ts +0 -20
  24. package/dist/builtin-plugins/python/index.d.ts +0 -27
  25. package/dist/builtin-plugins/ruby/index.d.ts +0 -20
  26. package/dist/builtin-plugins/rust/index.d.ts +0 -53
  27. package/dist/builtin-plugins/swift/index.d.ts +0 -22
  28. package/dist/default_templates/angular/angular-core.md +0 -19
  29. package/dist/default_templates/architecture/codeowners.md +0 -123
  30. package/dist/default_templates/architecture/monorepo.md +0 -146
  31. package/dist/default_templates/architecture/nx.md +0 -122
  32. package/dist/default_templates/architecture/turborepo.md +0 -114
  33. package/dist/default_templates/ci/github-actions.md +0 -268
  34. package/dist/default_templates/ci/gitlab-ci.md +0 -330
  35. package/dist/default_templates/containers/docker-multistage.md +0 -120
  36. package/dist/default_templates/containers/kubernetes-deploy.md +0 -210
  37. package/dist/default_templates/devops/docker-compose.md +0 -111
  38. package/dist/default_templates/devops/docker-dockerfile.md +0 -94
  39. package/dist/default_templates/devops/github-actions.md +0 -160
  40. package/dist/default_templates/devops/gitlab-ci.md +0 -210
  41. package/dist/default_templates/dotnet/framework-aspnetcore.md +0 -205
  42. package/dist/default_templates/dotnet/framework-blazor.md +0 -271
  43. package/dist/default_templates/dotnet/lang-csharp.md +0 -162
  44. package/dist/default_templates/generic/lang-typescript.md +0 -11
  45. package/dist/default_templates/generic/state-redux.md +0 -21
  46. package/dist/default_templates/generic/state-rxjs.md +0 -6
  47. package/dist/default_templates/generic/style-mui.md +0 -23
  48. package/dist/default_templates/generic/style-tailwind.md +0 -6
  49. package/dist/default_templates/generic/test-cypress.md +0 -21
  50. package/dist/default_templates/generic/test-jest.md +0 -20
  51. package/dist/default_templates/generic/test-playwright.md +0 -21
  52. package/dist/default_templates/generic/test-vitest.md +0 -6
  53. package/dist/default_templates/go/lang-go.md +0 -571
  54. package/dist/default_templates/java/build-gradle.md +0 -102
  55. package/dist/default_templates/java/build-maven.md +0 -86
  56. package/dist/default_templates/java/framework-spring-boot.md +0 -179
  57. package/dist/default_templates/java/lang-java.md +0 -78
  58. package/dist/default_templates/java/lang-kotlin.md +0 -88
  59. package/dist/default_templates/meta/magic-helix-meta.md +0 -213
  60. package/dist/default_templates/meta/meta-debug.md +0 -459
  61. package/dist/default_templates/meta/meta-implement.md +0 -450
  62. package/dist/default_templates/meta/meta-roadmap.md +0 -265
  63. package/dist/default_templates/nestjs/nestjs-core.md +0 -7
  64. package/dist/default_templates/patterns/architecture/clean-architecture.md +0 -469
  65. package/dist/default_templates/patterns/architecture/dependency-injection.md +0 -517
  66. package/dist/default_templates/patterns/architecture/domain-driven-design.md +0 -621
  67. package/dist/default_templates/patterns/architecture/layered-architecture.md +0 -382
  68. package/dist/default_templates/patterns/architecture/repository-pattern.md +0 -408
  69. package/dist/default_templates/patterns/domain-expertise/nextjs-rules.md +0 -115
  70. package/dist/default_templates/patterns/domain-expertise/react-patterns.md +0 -181
  71. package/dist/default_templates/patterns/domain-expertise/server-components.md +0 -212
  72. package/dist/default_templates/patterns/domain-expertise/shadcn-ui.md +0 -52
  73. package/dist/default_templates/patterns/domain-expertise/tailwind-patterns.md +0 -52
  74. package/dist/default_templates/patterns/environment/container-awareness.md +0 -17
  75. package/dist/default_templates/patterns/environment/ide-features.md +0 -17
  76. package/dist/default_templates/patterns/environment/os-commands.md +0 -17
  77. package/dist/default_templates/patterns/organization/heading-hierarchy.md +0 -103
  78. package/dist/default_templates/patterns/organization/sequential-workflows.md +0 -102
  79. package/dist/default_templates/patterns/organization/xml-rule-groups.md +0 -64
  80. package/dist/default_templates/patterns/reasoning/agent-loop.md +0 -151
  81. package/dist/default_templates/patterns/reasoning/confirmation-gates.md +0 -141
  82. package/dist/default_templates/patterns/reasoning/dependency-analysis.md +0 -132
  83. package/dist/default_templates/patterns/reasoning/one-tool-per-iteration.md +0 -152
  84. package/dist/default_templates/patterns/reasoning/preview-before-action.md +0 -194
  85. package/dist/default_templates/patterns/reasoning/reflection-checkpoints.md +0 -166
  86. package/dist/default_templates/patterns/reasoning/result-verification.md +0 -157
  87. package/dist/default_templates/patterns/reasoning/subtask-breakdown.md +0 -131
  88. package/dist/default_templates/patterns/reasoning/thinking-tags.md +0 -100
  89. package/dist/default_templates/patterns/role-definition/capability-declarations.md +0 -72
  90. package/dist/default_templates/patterns/role-definition/expert-identity.md +0 -45
  91. package/dist/default_templates/patterns/role-definition/scope-boundaries.md +0 -61
  92. package/dist/default_templates/patterns/safety/code-safety-rules.md +0 -17
  93. package/dist/default_templates/patterns/safety/credential-handling.md +0 -17
  94. package/dist/default_templates/patterns/safety/destructive-warnings.md +0 -17
  95. package/dist/default_templates/patterns/safety/refusal-messages.md +0 -17
  96. package/dist/default_templates/patterns/tone/adaptive-tone.md +0 -17
  97. package/dist/default_templates/patterns/tone/concise-communication.md +0 -17
  98. package/dist/default_templates/patterns/tone/forbidden-phrases.md +0 -17
  99. package/dist/default_templates/patterns/tool-guidelines/function-schemas.md +0 -143
  100. package/dist/default_templates/patterns/tool-guidelines/parameter-examples.md +0 -137
  101. package/dist/default_templates/patterns/tool-guidelines/usage-policies.md +0 -105
  102. package/dist/default_templates/php/framework-laravel.md +0 -112
  103. package/dist/default_templates/php/lang-php.md +0 -94
  104. package/dist/default_templates/python/lang-python.md +0 -508
  105. package/dist/default_templates/react/react-core.md +0 -677
  106. package/dist/default_templates/react/react-zustand.md +0 -7
  107. package/dist/default_templates/ruby/framework-rails.md +0 -309
  108. package/dist/default_templates/ruby/framework-sinatra.md +0 -227
  109. package/dist/default_templates/ruby/lang-ruby.md +0 -216
  110. package/dist/default_templates/rust/lang-rust.md +0 -89
  111. package/dist/default_templates/swift/framework-vapor.md +0 -352
  112. package/dist/default_templates/swift/lang-swift.md +0 -291
  113. package/dist/default_templates/vue/style-primevue.md +0 -6
  114. package/dist/default_templates/vue/style-quasar.md +0 -22
  115. package/dist/default_templates/vue/vue-core.md +0 -28
  116. package/dist/default_templates/vue/vue-pinia.md +0 -5
  117. package/dist/index-AkVwRl-r.js +0 -92
  118. package/dist/index-AkVwRl-r.js.map +0 -1
  119. package/dist/index-B6BeG1yT.cjs +0 -68
  120. package/dist/index-B6BeG1yT.cjs.map +0 -1
  121. package/dist/index-B8pyjKdF.js +0 -94
  122. package/dist/index-B8pyjKdF.js.map +0 -1
  123. package/dist/index-B_6W_RnJ.cjs +0 -76
  124. package/dist/index-B_6W_RnJ.cjs.map +0 -1
  125. package/dist/index-Bg8DD8ku.js +0 -216
  126. package/dist/index-Bg8DD8ku.js.map +0 -1
  127. package/dist/index-BkJhe5Af.js +0 -1748
  128. package/dist/index-BkJhe5Af.js.map +0 -1
  129. package/dist/index-Bv4Q1Pr7.cjs +0 -33
  130. package/dist/index-Bv4Q1Pr7.cjs.map +0 -1
  131. package/dist/index-CN8J45Nc.cjs +0 -24
  132. package/dist/index-CN8J45Nc.cjs.map +0 -1
  133. package/dist/index-CPbv2Od1.js +0 -62
  134. package/dist/index-CPbv2Od1.js.map +0 -1
  135. package/dist/index-Cf-MC6Al.js +0 -63
  136. package/dist/index-Cf-MC6Al.js.map +0 -1
  137. package/dist/index-DDPXXXDy.cjs +0 -19
  138. package/dist/index-DDPXXXDy.cjs.map +0 -1
  139. package/dist/index-DO30AzDe.cjs +0 -19
  140. package/dist/index-DO30AzDe.cjs.map +0 -1
  141. package/dist/index-Dm37u5ut.js +0 -2128
  142. package/dist/index-Dm37u5ut.js.map +0 -1
  143. package/dist/index-DqHvgoXJ.cjs +0 -19
  144. package/dist/index-DqHvgoXJ.cjs.map +0 -1
  145. package/dist/index-J1qAfsnO.cjs +0 -2
  146. package/dist/index-J1qAfsnO.cjs.map +0 -1
  147. package/dist/index-Jz0HYZ7B.js +0 -13
  148. package/dist/index-Jz0HYZ7B.js.map +0 -1
  149. package/dist/index-K39pdw94.cjs +0 -31
  150. package/dist/index-K39pdw94.cjs.map +0 -1
  151. package/dist/index-L3IVvhd1.cjs +0 -89
  152. package/dist/index-L3IVvhd1.cjs.map +0 -1
  153. package/dist/index-OT2XAJkc.js +0 -117
  154. package/dist/index-OT2XAJkc.js.map +0 -1
  155. package/dist/index-TPAX4XKg.cjs +0 -30
  156. package/dist/index-TPAX4XKg.cjs.map +0 -1
  157. package/dist/index-WmVSB57y.js +0 -107
  158. package/dist/index-WmVSB57y.js.map +0 -1
  159. package/dist/index-mYXvc3Fs.js +0 -68
  160. package/dist/index-mYXvc3Fs.js.map +0 -1
@@ -1,2128 +0,0 @@
1
- import * as p from "node:path";
2
- import F, { dirname as O, resolve as R } from "node:path";
3
- import { fileURLToPath as _ } from "node:url";
4
- import * as f from "node:fs";
5
- import E from "node:fs";
6
- import b from "picocolors";
7
- import { glob as A } from "glob";
8
- function W(n) {
9
- if (n === "src/**/*.ts")
10
- return /^src\/.*\.ts$/;
11
- if (n === "src/**/*.vue")
12
- return /^src\/.*\.vue$/;
13
- const e = n.replace(/\*\*/g, ".*").replace(/\*/g, "[^/]*");
14
- return new RegExp(`^${e.replace(/[.+^${}()|[\]\\]/g, "\\$&")}$`);
15
- }
16
- function N(n, e) {
17
- const t = W(e);
18
- return n.some((s) => t.test(s));
19
- }
20
- function Pe(n, e, t, s) {
21
- const i = /* @__PURE__ */ new Set();
22
- for (const [r, o] of Object.entries(n.dependencies))
23
- e[r] && i.add(e[r]);
24
- for (const r of n.configFiles)
25
- t[r] && i.add(t[r]);
26
- for (const r in s) {
27
- const o = s[r];
28
- N(n.projectFiles, r) && i.add(o);
29
- }
30
- return i;
31
- }
32
- const G = {
33
- target: "github-copilot",
34
- templateDirectory: "ai_templates",
35
- // User's custom template dir
36
- outputDirectory: ".github/instructions",
37
- // Default output dir
38
- aiRefinement: {
39
- quality: "standard",
40
- contextLevel: "balanced",
41
- outputFormat: "markdown",
42
- tokenBudget: 4e3,
43
- includeExamples: !0,
44
- includeBestPractices: !0
45
- },
46
- dependencyTagMap: {
47
- // Frameworks
48
- vue: "framework-vue",
49
- react: "framework-react",
50
- "@angular/core": "framework-angular",
51
- "@nestjs/core": "framework-nestjs",
52
- // Styling
53
- tailwindcss: "style-tailwind",
54
- primevue: "style-primevue",
55
- "@mui/material": "style-mui",
56
- quasar: "style-quasar",
57
- // Testing
58
- vitest: "test-vitest",
59
- jest: "test-jest",
60
- cypress: "test-cypress",
61
- playwright: "test-playwright",
62
- // State
63
- rxjs: "state-rxjs",
64
- pinia: "state-pinia",
65
- redux: "state-redux",
66
- zustand: "state-zustand"
67
- },
68
- configFileTagMap: {
69
- // Detect key configs
70
- "tailwind.config.js": "style-tailwind",
71
- "tailwind.config.ts": "style-tailwind",
72
- "vite.config.ts": "build-vite",
73
- "vite.config.js": "build-vite",
74
- "tsconfig.json": "lang-typescript"
75
- },
76
- fileGlobTagMap: {
77
- // Detect file types
78
- "src/**/*.vue": "framework-vue",
79
- "src/**/*.tsx": "framework-react",
80
- "src/**/*.go": "lang-go",
81
- "src/**/*.py": "lang-python"
82
- },
83
- tagTemplateMap: {
84
- // Vue Projects
85
- "framework-vue": [{ template: "vue/vue-core.md", suffix: "vue-core.md" }],
86
- "state-pinia": [{ template: "vue/vue-pinia.md", suffix: "vue-pinia.md" }],
87
- "style-primevue": [
88
- { template: "vue/style-primevue.md", suffix: "vue-style-primevue.md" }
89
- ],
90
- "style-quasar": [
91
- { template: "vue/style-quasar.md", suffix: "vue-style-quasar.md" }
92
- ],
93
- // React Projects
94
- "framework-react": [
95
- { template: "react/react-core.md", suffix: "react-core.md" }
96
- ],
97
- "state-zustand": [
98
- { template: "react/react-zustand.md", suffix: "react-zustand.md" }
99
- ],
100
- // NestJS Projects
101
- "framework-nestjs": [
102
- { template: "nestjs/nestjs-core.md", suffix: "nestjs-core.md" }
103
- ],
104
- // Angular Projects
105
- "framework-angular": [
106
- { template: "angular/angular-core.md", suffix: "angular-core.md" }
107
- ],
108
- // Generic
109
- "style-tailwind": [
110
- { template: "generic/style-tailwind.md", suffix: "style-tailwind.md" }
111
- ],
112
- "style-mui": [{ template: "generic/style-mui.md", suffix: "style-mui.md" }],
113
- "test-vitest": [
114
- { template: "generic/test-vitest.md", suffix: "test-vitest.md" }
115
- ],
116
- "test-jest": [{ template: "generic/test-jest.md", suffix: "test-jest.md" }],
117
- "test-cypress": [
118
- { template: "generic/test-cypress.md", suffix: "test-cypress.md" }
119
- ],
120
- "test-playwright": [
121
- { template: "generic/test-playwright.md", suffix: "test-playwright.md" }
122
- ],
123
- "lang-typescript": [
124
- { template: "generic/lang-typescript.md", suffix: "lang-typescript.md" }
125
- ],
126
- "lang-python": [
127
- { template: "python/lang-python.md", suffix: "lang-python.md" }
128
- ],
129
- "lang-go": [{ template: "go/lang-go.md", suffix: "lang-go.md" }],
130
- "state-rxjs": [
131
- { template: "generic/state-rxjs.md", suffix: "state-rxjs.md" }
132
- ],
133
- "state-redux": [
134
- { template: "generic/state-redux.md", suffix: "state-redux.md" }
135
- ]
136
- }
137
- }, I = {
138
- quality: "standard",
139
- contextLevel: "balanced",
140
- outputFormat: "markdown",
141
- tokenBudget: 4e3,
142
- includeExamples: !0,
143
- includeBestPractices: !0
144
- };
145
- function be(n, e) {
146
- const t = { ...I, ...e };
147
- let s = n;
148
- return s = q(s, t.outputFormat), s = z(s, t.quality), s = B(s, t.contextLevel), t.includeExamples || (s = H(s)), t.includeBestPractices || (s = U(s)), s = J(s, t.tokenBudget), s;
149
- }
150
- function z(n, e) {
151
- switch (e) {
152
- case "basic":
153
- return n.split(/\n(?=##? )/).filter((s) => {
154
- s.toLowerCase();
155
- const i = s.split(`
156
- `)[0].toLowerCase();
157
- return i.includes("# ") || // Keep top-level headers
158
- i.includes("overview") || i.includes("basic") || i.includes("essential");
159
- }).join(`
160
- `);
161
- case "comprehensive":
162
- return n;
163
- default:
164
- return n.split(/\n(?=##? )/).filter((s) => {
165
- const i = s.split(`
166
- `)[0].toLowerCase();
167
- return !i.includes("advanced") && !i.includes("deep dive");
168
- }).join(`
169
- `);
170
- }
171
- }
172
- function B(n, e) {
173
- switch (e) {
174
- case "minimal":
175
- return n.split(/\n(?=##? )/).filter((s) => {
176
- const i = s.split(`
177
- `)[0].toLowerCase();
178
- return !i.includes("background") && !i.includes("why ") && !i.includes("explanation") && !i.includes("deep dive");
179
- }).join(`
180
- `);
181
- case "extensive":
182
- return n;
183
- default:
184
- return n.split(`
185
- `).filter((t) => t.startsWith("#") || t.startsWith("-") || t.startsWith("*") || t.match(/^\d+\./) || // numbered lists
186
- t.startsWith("```") || t.startsWith(" ") || t.trim().length === 0 || t.trim().length < 200).join(`
187
- `);
188
- }
189
- }
190
- function q(n, e) {
191
- switch (e) {
192
- case "structured":
193
- return n.replace(/^### /gm, "#### ").replace(/^## /gm, "### ").replace(/^# /gm, "## ");
194
- // Demote h1 to h2
195
- case "conversational":
196
- return n.replace(/^- (.+)$/gm, (t, s) => `${s}.`).replace(/\n{3,}/g, `
197
-
198
- `);
199
- case "code-focused": {
200
- const t = n.split(`
201
- `);
202
- let s = !1;
203
- return t.filter((i) => i.startsWith("```") ? (s = !s, !0) : s || i.startsWith("#") || i.trim().length === 0 ? !0 : i.match(/^[^.]+\./)).join(`
204
- `);
205
- }
206
- default:
207
- return n;
208
- }
209
- }
210
- function H(n) {
211
- let e = "", t = !1, s = !1;
212
- for (const i of n.split(`
213
- `)) {
214
- if (i.startsWith("```")) {
215
- t = !t;
216
- continue;
217
- }
218
- if (!t) {
219
- if (i.match(/^##+ .*example/i)) {
220
- s = !0;
221
- continue;
222
- }
223
- i.startsWith("##") && (s = !1);
224
- }
225
- !t && !s && (e += `${i}
226
- `);
227
- }
228
- return e;
229
- }
230
- function U(n) {
231
- return n.split(`
232
- `).filter((e) => {
233
- const t = e.toLowerCase();
234
- return !(t.match(/^##+ .*best practice/i) || t.match(/^##+ .*recommendation/i) || t.match(/^##+ .*tip/i));
235
- }).join(`
236
- `);
237
- }
238
- function J(n, e) {
239
- const t = e * 4;
240
- if (n.length <= t) return n;
241
- const s = n.substring(0, t), i = s.lastIndexOf(`
242
- ## `);
243
- return i > t * 0.7 ? `${s.substring(0, i)}
244
-
245
- <!-- Content truncated to fit token budget -->` : `${s}
246
-
247
- <!-- Content truncated to fit token budget -->`;
248
- }
249
- function ke(n) {
250
- return Math.ceil(n.length / 4);
251
- }
252
- const T = "magic-helix.config.json", V = ["ai-aligner.config.json"];
253
- function Ce(n) {
254
- const t = (n ? [p.resolve(process.cwd(), n)] : [
255
- p.resolve(process.cwd(), T),
256
- ...V.map(
257
- (s) => p.resolve(process.cwd(), s)
258
- )
259
- ]).find((s, i) => {
260
- const r = f.existsSync(s);
261
- return !n && r && i > 0 && console.warn(
262
- b.yellow(
263
- ` Detected legacy config file ${p.basename(s)}. Please rename it to ${T}.`
264
- )
265
- ), r;
266
- });
267
- if (!t)
268
- return console.log(
269
- b.gray(" No user config file found. Using built-in conventions only.")
270
- ), {};
271
- try {
272
- return console.log(
273
- b.blue(" User config file found. Merging with built-in conventions.")
274
- ), JSON.parse(f.readFileSync(t, "utf-8"));
275
- } catch (s) {
276
- return console.error(
277
- b.red(`❌ Error parsing config file: ${s.message}`)
278
- ), console.warn(
279
- b.yellow(
280
- " Please fix the JSON or remove the file. Using built-in conventions only."
281
- )
282
- ), {};
283
- }
284
- }
285
- function Fe(n) {
286
- const e = G;
287
- return {
288
- target: n.target || e.target,
289
- templateDirectory: n.templateDirectory ?? e.templateDirectory,
290
- outputDirectory: n.outputDirectory ?? e.outputDirectory,
291
- dependencyTagMap: {
292
- ...e.dependencyTagMap,
293
- ...n.dependencyTagMap || {}
294
- },
295
- configFileTagMap: {
296
- ...e.configFileTagMap,
297
- ...n.configFileTagMap || {}
298
- },
299
- fileGlobTagMap: {
300
- ...e.fileGlobTagMap,
301
- ...n.fileGlobTagMap || {}
302
- },
303
- tagTemplateMap: {
304
- ...e.tagTemplateMap,
305
- ...n.tagTemplateMap || {}
306
- },
307
- aiRefinement: {
308
- ...I,
309
- ...n.aiRefinement || {}
310
- }
311
- };
312
- }
313
- class j {
314
- format(e, t, s) {
315
- return e;
316
- }
317
- getFileExtension() {
318
- return ".md";
319
- }
320
- getFrontmatter(e, t) {
321
- return `---
322
- applyTo: "${e}"
323
- ---
324
-
325
- `;
326
- }
327
- }
328
- class Y {
329
- format(e, t, s) {
330
- return e.replace(/- \*\*([^*]+)\*\*/g, "- **$1** (important)");
331
- }
332
- getFileExtension() {
333
- return ".md";
334
- }
335
- getFrontmatter(e, t) {
336
- return `---
337
- applyTo: "${e}"
338
- assistant: claude
339
- ---
340
-
341
- `;
342
- }
343
- }
344
- class Q {
345
- format(e, t, s) {
346
- return e.replace(/- \*\*ALWAYS\*\*/g, "- 🔴").replace(/- \*\*NEVER\*\*/g, "- ❌");
347
- }
348
- getFileExtension() {
349
- return ".md";
350
- }
351
- getFrontmatter(e, t) {
352
- return `---
353
- applyTo: "${e}"
354
- context: chat
355
- ---
356
-
357
- `;
358
- }
359
- }
360
- class X {
361
- format(e, t, s) {
362
- return e;
363
- }
364
- getFileExtension() {
365
- return ".md";
366
- }
367
- getFrontmatter(e, t) {
368
- return `---
369
- applyTo: "${e}"
370
- ---
371
-
372
- `;
373
- }
374
- }
375
- function Se(n) {
376
- switch (n) {
377
- case "github-copilot":
378
- return new j();
379
- case "claude":
380
- return new Y();
381
- case "copilot-chat":
382
- return new Q();
383
- case "generic":
384
- return new X();
385
- default:
386
- return new j();
387
- }
388
- }
389
- const v = {}, xe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
390
- __proto__: null,
391
- default: v
392
- }, Symbol.toStringTag, { value: "Module" }));
393
- function K() {
394
- const n = v.join(__dirname, "default_templates", "patterns"), e = /* @__PURE__ */ new Map(), t = [
395
- "role-definition",
396
- "organization",
397
- "tool-guidelines",
398
- "reasoning",
399
- "domain-expertise",
400
- "safety",
401
- "tone",
402
- "environment"
403
- ];
404
- for (const s of t) {
405
- const i = v.join(n, s);
406
- if (!v.existsSync(i)) continue;
407
- const r = v.readdirSync(i).filter((o) => o.endsWith(".md"));
408
- for (const o of r) {
409
- const a = o.replace(".md", ""), c = v.readFileSync(v.join(i, o), "utf-8");
410
- e.set(a, {
411
- name: a,
412
- category: s,
413
- content: c,
414
- priority: Z(s)
415
- });
416
- }
417
- }
418
- return e;
419
- }
420
- function Z(n) {
421
- return {
422
- "role-definition": 1,
423
- organization: 2,
424
- "tool-guidelines": 3,
425
- reasoning: 4,
426
- "domain-expertise": 5,
427
- environment: 6,
428
- tone: 7,
429
- safety: 8
430
- // Safety always highest priority (never overridden)
431
- }[n];
432
- }
433
- function ee(n, e) {
434
- const t = [], s = n.get("expert-identity"), i = n.get("scope-boundaries");
435
- s && t.push(s), i && t.push(i);
436
- const r = n.get("heading-hierarchy");
437
- r && t.push(r);
438
- const o = n.get("function-schemas"), a = n.get("usage-policies");
439
- if (o && t.push(o), a && t.push(a), e.framework === "react" || e.framework === "vue") {
440
- const u = n.get("react-patterns");
441
- u && t.push(u);
442
- }
443
- if (e.libraries) {
444
- if (e.libraries.includes("tailwind")) {
445
- const u = n.get("tailwind-patterns");
446
- u && t.push(u);
447
- }
448
- if (e.libraries.includes("shadcn-ui")) {
449
- const u = n.get("shadcn-ui");
450
- u && t.push(u);
451
- }
452
- }
453
- if (e.aiModel === "claude") {
454
- const u = n.get("thinking-tags"), d = n.get("concise-communication");
455
- u && t.push(u), d && t.push(d);
456
- }
457
- if (e.tone === "concise") {
458
- const u = n.get("concise-communication"), d = n.get("forbidden-phrases");
459
- u && t.push(u), d && t.push(d);
460
- }
461
- if (e.environment === "vscode") {
462
- const u = n.get("ide-features");
463
- u && t.push(u);
464
- }
465
- const c = n.get("refusal-messages"), l = n.get("destructive-warnings");
466
- if (c && t.push(c), l && t.push(l), e.includePatterns)
467
- for (const u of e.includePatterns) {
468
- const d = n.get(u);
469
- d && !t.includes(d) && t.push(d);
470
- }
471
- return e.excludePatterns ? t.filter((u) => !e.excludePatterns?.includes(u.name)) : t;
472
- }
473
- function te(n) {
474
- const e = n.sort((g, w) => g.priority - w.priority), t = [], s = /* @__PURE__ */ new Map();
475
- for (const g of e) {
476
- s.has(g.category) || s.set(g.category, []);
477
- const w = s.get(g.category);
478
- w && w.push(g);
479
- }
480
- t.push(`# AI Agent Instructions
481
- `);
482
- const i = s.get("role-definition");
483
- if (i) {
484
- t.push(`## Role & Identity
485
- `);
486
- for (const g of i)
487
- t.push(y(g.content));
488
- }
489
- const r = s.get("organization");
490
- if (r) {
491
- t.push(`## Instruction Structure
492
- `);
493
- for (const g of r)
494
- t.push(y(g.content));
495
- }
496
- const o = s.get("tool-guidelines");
497
- if (o) {
498
- t.push(`## Tool Usage Guidelines
499
- `);
500
- for (const g of o)
501
- t.push(y(g.content));
502
- }
503
- const a = s.get("reasoning");
504
- if (a) {
505
- t.push(`## Reasoning & Execution Patterns
506
- `);
507
- for (const g of a)
508
- t.push(y(g.content));
509
- }
510
- const c = s.get("domain-expertise");
511
- if (c) {
512
- t.push(`## Domain-Specific Guidelines
513
- `);
514
- for (const g of c)
515
- t.push(y(g.content));
516
- }
517
- const l = s.get("environment");
518
- if (l) {
519
- t.push(`## Environment Context
520
- `);
521
- for (const g of l)
522
- t.push(y(g.content));
523
- }
524
- const u = s.get("tone");
525
- if (u) {
526
- t.push(`## Communication Style
527
- `);
528
- for (const g of u)
529
- t.push(y(g.content));
530
- }
531
- const d = s.get("safety");
532
- if (d) {
533
- t.push(`## Safety & Refusal Protocols
534
- `);
535
- for (const g of d)
536
- t.push(y(g.content));
537
- }
538
- return t.join(`
539
-
540
- `);
541
- }
542
- function y(n) {
543
- let e = n.replace(/^# .+ Pattern\n+/, "");
544
- const t = e.match(
545
- /## Examples\n([\s\S]+?)(?=\n## |\n---|Z)/
546
- );
547
- return t ? t[1].trim() : (e = e.replace(/## Purpose\n.+?\n\n/, ""), e = e.replace(/## Template\n[\s\S]+?(?=\n## |$)/, ""), e = e.replace(/## Best Practices\n[\s\S]+$/, ""), e.trim());
548
- }
549
- function se(n) {
550
- const e = K(), t = ee(e, n);
551
- return te(t);
552
- }
553
- const ne = [
554
- // Role Definition (Critical)
555
- {
556
- name: "Expert Identity",
557
- weight: 1,
558
- required: !0,
559
- check: (n) => /you are (an?|the) .+? (expert|specialist|assistant)/i.test(n)
560
- },
561
- {
562
- name: "Capability Declarations",
563
- weight: 0.8,
564
- required: !0,
565
- check: (n) => /you (can|excel at|have expertise in)/i.test(n)
566
- },
567
- {
568
- name: "Scope Boundaries",
569
- weight: 0.7,
570
- required: !1,
571
- check: (n) => /you (will not|won't|cannot|must not)/i.test(n)
572
- },
573
- // Organization Structure (Important)
574
- {
575
- name: "Clear Headings",
576
- weight: 0.9,
577
- required: !0,
578
- check: (n) => (n.match(/^##? /gm) || []).length >= 3
579
- },
580
- {
581
- name: "Structured Sections",
582
- weight: 0.8,
583
- required: !1,
584
- check: (n) => /<rules>|<thinking>|```xml/i.test(n) || (n.match(/^###? /gm) || []).length >= 5
585
- },
586
- // Tool Guidelines (Critical for agentic AI)
587
- {
588
- name: "Tool Documentation",
589
- weight: 1,
590
- required: !0,
591
- check: (n) => /tool|function|command|api/i.test(n) && /parameter|argument|input/i.test(n)
592
- },
593
- {
594
- name: "Tool Usage Policies",
595
- weight: 0.9,
596
- required: !0,
597
- check: (n) => /when to use|when not to use|prefer|avoid/i.test(n)
598
- },
599
- {
600
- name: "Concrete Examples",
601
- weight: 0.8,
602
- required: !0,
603
- check: (n) => (n.match(/```[\s\S]+?```/g) || []).length >= 2
604
- },
605
- // Reasoning Patterns (Important)
606
- {
607
- name: "Step-by-Step Process",
608
- weight: 0.7,
609
- required: !1,
610
- check: (n) => /^\d+\. /gm.test(n) || /first|then|next|finally/i.test(n)
611
- },
612
- {
613
- name: "Thinking/Planning Phase",
614
- weight: 0.6,
615
- required: !1,
616
- check: (n) => /<thinking>|before .+?, (think|plan|analyze)/i.test(n)
617
- },
618
- {
619
- name: "Confirmation Gates",
620
- weight: 0.8,
621
- required: !1,
622
- check: (n) => /confirmation|preview|show .+? before|ask .+? before/i.test(n)
623
- },
624
- // Safety Protocols (Critical)
625
- {
626
- name: "Refusal Guidelines",
627
- weight: 1,
628
- required: !0,
629
- check: (n) => /refuse|decline|cannot (assist|help) with|inappropriate/i.test(n)
630
- },
631
- {
632
- name: "Destructive Action Warnings",
633
- weight: 0.9,
634
- required: !1,
635
- check: (n) => /warning|caution|delete|remove|overwrite/i.test(n)
636
- },
637
- // Tone & Style (Moderate)
638
- {
639
- name: "Communication Style",
640
- weight: 0.5,
641
- required: !1,
642
- check: (n) => /concise|brief|direct|friendly|professional|tone/i.test(n)
643
- },
644
- {
645
- name: "Forbidden Phrases",
646
- weight: 0.4,
647
- required: !1,
648
- check: (n) => /do not (say|use|start with)|avoid (saying|phrases like)/i.test(n)
649
- }
650
- ];
651
- function D(n) {
652
- const e = ne.map((d) => ({
653
- element: d,
654
- passed: d.check(n)
655
- })), t = e.filter(
656
- (d) => ["Clear Headings", "Structured Sections"].includes(d.element.name)
657
- ), s = S(t), i = e.filter(
658
- (d) => ["Concrete Examples", "Communication Style", "Forbidden Phrases"].includes(
659
- d.element.name
660
- )
661
- ), r = S(i), o = e.filter((d) => d.element.required), a = S(o), c = Math.round(
662
- s * 0.3 + r * 0.2 + a * 0.5
663
- ), l = e.filter((d) => d.element.required && !d.passed).map((d) => d.element.name), u = ie(e, n);
664
- return {
665
- overallScore: c,
666
- structureScore: s,
667
- clarityScore: r,
668
- completenessScore: a,
669
- recommendations: u,
670
- missingElements: l
671
- };
672
- }
673
- function S(n) {
674
- if (n.length === 0) return 100;
675
- const e = n.reduce((s, i) => s + i.element.weight, 0), t = n.filter((s) => s.passed).reduce((s, i) => s + i.element.weight, 0);
676
- return Math.round(t / e * 100);
677
- }
678
- function ie(n, e) {
679
- const t = [], s = n.filter(
680
- (a) => a.element.required && !a.passed
681
- );
682
- s.length > 0 && t.push(
683
- `Add ${s.length} critical element(s): ${s.map((a) => a.element.name).join(", ")}`
684
- ), n.find((a) => a.element.name === "Expert Identity")?.passed || t.push(
685
- 'Add expert identity: Start with "You are an expert [domain] specialist..."'
686
- ), n.find((a) => a.element.name === "Tool Documentation")?.passed || t.push(
687
- "Add tool documentation: Include function schemas with parameters and examples"
688
- ), n.find((a) => a.element.name === "Refusal Guidelines")?.passed || t.push(
689
- "Add refusal guidelines: Specify what requests should be declined and how"
690
- );
691
- const i = (e.match(/```[\s\S]+?```/g) || []).length;
692
- i < 3 && t.push(
693
- `Add more code examples: Currently ${i}, aim for at least 5 concrete examples`
694
- ), /✅|❌|good:|bad:/i.test(e) || t.push(
695
- "Add ✅/❌ comparisons: Show good vs bad examples for clarity"
696
- );
697
- const o = e.split(/\s+/).length;
698
- return o < 500 ? t.push(
699
- `Instructions may be too brief (${o} words). Aim for 1000-3000 words for comprehensive guidance.`
700
- ) : o > 5e3 && t.push(
701
- `Instructions may be too long (${o} words). Consider breaking into sections or modules.`
702
- ), n.find((a) => a.element.name === "Confirmation Gates")?.passed || t.push(
703
- "Consider adding confirmation gates for destructive operations (delete, overwrite)"
704
- ), t.length === 0 && t.push(
705
- "Instructions meet quality standards. Consider A/B testing variants for optimization."
706
- ), t;
707
- }
708
- function Ee(n, e = 70) {
709
- return D(n).overallScore >= e;
710
- }
711
- function re(n) {
712
- return n >= 90 ? "A" : n >= 80 ? "B" : n >= 70 ? "C" : n >= 60 ? "D" : "F";
713
- }
714
- function Te(n) {
715
- const e = [];
716
- if (e.push(`=== Instruction Quality Report ===
717
- `), e.push(
718
- `Overall Score: ${n.overallScore}/100 (${re(n.overallScore)})
719
- `
720
- ), e.push(` Structure: ${n.structureScore}/100`), e.push(` Clarity: ${n.clarityScore}/100`), e.push(` Completeness: ${n.completenessScore}/100
721
- `), n.missingElements.length > 0) {
722
- e.push("❌ Missing Critical Elements:");
723
- for (const t of n.missingElements)
724
- e.push(` - ${t}`);
725
- e.push("");
726
- }
727
- if (n.recommendations.length > 0) {
728
- e.push("💡 Recommendations:");
729
- for (const t of n.recommendations)
730
- e.push(` - ${t}`);
731
- e.push("");
732
- }
733
- return e.join(`
734
- `);
735
- }
736
- let oe = class {
737
- constructor() {
738
- this.plugins = /* @__PURE__ */ new Map();
739
- }
740
- /**
741
- * Register a new detection plugin.
742
- * @param plugin The plugin to register
743
- */
744
- register(e) {
745
- this.plugins.has(e.name) && console.warn(
746
- `Plugin "${e.name}" is already registered. Overwriting.`
747
- ), this.plugins.set(e.name, e);
748
- }
749
- /**
750
- * Unregister a plugin by name.
751
- * @param name Plugin name to unregister
752
- */
753
- unregister(e) {
754
- return this.plugins.delete(e);
755
- }
756
- /**
757
- * Get a plugin by name.
758
- * @param name Plugin name
759
- */
760
- get(e) {
761
- return this.plugins.get(e);
762
- }
763
- /**
764
- * Get all registered plugins.
765
- */
766
- getAll() {
767
- return Array.from(this.plugins.values());
768
- }
769
- /**
770
- * Clear all registered plugins.
771
- */
772
- clear() {
773
- this.plugins.clear();
774
- }
775
- /**
776
- * Get the number of registered plugins.
777
- */
778
- get size() {
779
- return this.plugins.size;
780
- }
781
- };
782
- const m = new oe();
783
- class ae {
784
- constructor(e, t = /* @__PURE__ */ new Map()) {
785
- this.analysisData = e, this.fileContentCache = t;
786
- }
787
- get files() {
788
- return this.analysisData.projectFiles;
789
- }
790
- get dependencies() {
791
- return this.analysisData.dependencies;
792
- }
793
- get configFiles() {
794
- return this.analysisData.configFiles;
795
- }
796
- getTextFile(e) {
797
- return this.fileContentCache.has(e) && this.fileContentCache.get(e) || null;
798
- }
799
- hasFile(e) {
800
- return this.analysisData.projectFiles.includes(e) || this.analysisData.configFiles.includes(e);
801
- }
802
- matchesPattern(e) {
803
- const t = this.globToRegex(e);
804
- return this.analysisData.projectFiles.some((s) => t.test(s));
805
- }
806
- globToRegex(e) {
807
- const t = e.replace(/\\/g, "\\\\").replace(/\*\*/g, "§DOUBLESTAR§").replace(/\*/g, "[^/]*").replace(/§DOUBLESTAR§/g, ".*").replace(/\./g, "\\.");
808
- return new RegExp(`^${t}$`);
809
- }
810
- }
811
- async function $e(n, e) {
812
- const t = /* @__PURE__ */ new Set(), s = [], i = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map();
813
- if (e)
814
- for (const c of n.configFiles) {
815
- const l = e(c);
816
- l && r.set(c, l);
817
- }
818
- const o = new ae(n, r);
819
- if (e) {
820
- const c = o.getTextFile.bind(o);
821
- o.getTextFile = (l) => {
822
- const u = c(l);
823
- return u !== null ? u : e(l);
824
- };
825
- }
826
- const a = m.getAll();
827
- for (const c of a)
828
- try {
829
- const l = await Promise.resolve(c.detect(o));
830
- if (l.detected) {
831
- if (l.tags)
832
- for (const d of l.tags)
833
- t.add(d);
834
- l.metadata && i.set(c.name, l.metadata);
835
- const u = await Promise.resolve(
836
- c.generateInstructions(o, l.metadata)
837
- );
838
- s.push(...u);
839
- }
840
- } catch (l) {
841
- console.error(`Error running plugin ${c.name}:`, l);
842
- }
843
- return {
844
- tags: t,
845
- instructions: s,
846
- metadata: i
847
- };
848
- }
849
- function Ie() {
850
- import("./index-Jz0HYZ7B.js").then((n) => {
851
- m.register(new n.GolangPlugin()), m.register(new n.PythonPlugin()), m.register(new n.RustPlugin()), m.register(new n.PHPPlugin()), m.register(new n.DockerPlugin()), m.register(new n.GitHubActionsPlugin()), m.register(new n.GitLabCIPlugin()), m.register(new n.MonorepoPlugin()), m.register(new n.CodeOwnersPlugin());
852
- });
853
- }
854
- class De {
855
- constructor() {
856
- this.name = "codeowners", this.description = "Detects CODEOWNERS file and provides code ownership instructions", this.version = "1.0.0";
857
- }
858
- detect(e) {
859
- if (!(e.hasFile(".github/CODEOWNERS") || e.hasFile("CODEOWNERS") || e.hasFile("docs/CODEOWNERS")))
860
- return { detected: !1 };
861
- const s = {
862
- hasCodeOwners: !0
863
- };
864
- let i = "";
865
- e.hasFile(".github/CODEOWNERS") ? i = ".github/CODEOWNERS" : e.hasFile("CODEOWNERS") ? i = "CODEOWNERS" : i = "docs/CODEOWNERS", s.location = i;
866
- const r = e.getTextFile(i);
867
- if (r) {
868
- const a = r.split(`
869
- `).filter(
870
- (l) => l.trim() && !l.trim().startsWith("#")
871
- );
872
- s.ruleCount = a.length;
873
- const c = /* @__PURE__ */ new Set();
874
- for (const l of a) {
875
- const u = l.trim().split(/\s+/);
876
- if (u.length > 1)
877
- for (const d of u.slice(1))
878
- d.startsWith("@") && c.add(d);
879
- }
880
- s.ownerCount = c.size, s.owners = Array.from(c).slice(0, 10);
881
- }
882
- return {
883
- detected: !0,
884
- tags: ["architecture-codeowners"],
885
- metadata: s
886
- };
887
- }
888
- generateInstructions(e, t) {
889
- return [
890
- {
891
- template: "architecture/codeowners.md",
892
- suffix: "codeowners.md",
893
- targetFiles: [".github/CODEOWNERS", "CODEOWNERS", "docs/CODEOWNERS"]
894
- }
895
- ];
896
- }
897
- }
898
- class Le {
899
- constructor() {
900
- this.name = "docker", this.description = "Detects Docker usage and provides Docker-specific instructions", this.version = "1.0.0";
901
- }
902
- detect(e) {
903
- const t = e.hasFile("Dockerfile") || e.matchesPattern("**/Dockerfile"), s = e.hasFile("docker-compose.yml") || e.hasFile("docker-compose.yaml") || e.hasFile("compose.yml") || e.hasFile("compose.yaml"), i = e.hasFile(".dockerignore");
904
- if (!(t || s))
905
- return { detected: !1 };
906
- const o = {
907
- hasDockerfile: t,
908
- hasDockerCompose: s,
909
- hasDockerignore: i
910
- };
911
- if (t) {
912
- const a = e.getTextFile("Dockerfile");
913
- if (a) {
914
- const c = (a.match(/FROM\s+\S+\s+AS\s+\S+/gi) || []).length;
915
- c > 0 && (o.multiStage = !0, o.stageCount = c);
916
- }
917
- }
918
- return {
919
- detected: !0,
920
- tags: ["devops-docker"],
921
- metadata: o
922
- };
923
- }
924
- generateInstructions(e, t) {
925
- const s = [];
926
- return t?.hasDockerfile && s.push({
927
- template: "devops/docker-dockerfile.md",
928
- suffix: "docker-dockerfile.md",
929
- targetFiles: ["**/Dockerfile"]
930
- }), t?.hasDockerCompose && s.push({
931
- template: "devops/docker-compose.md",
932
- suffix: "docker-compose.md",
933
- targetFiles: [
934
- "**/docker-compose.yml",
935
- "**/docker-compose.yaml",
936
- "**/compose.yml",
937
- "**/compose.yaml"
938
- ]
939
- }), s;
940
- }
941
- }
942
- class Me {
943
- constructor() {
944
- this.name = "github-actions", this.description = "Detects GitHub Actions workflows and provides CI/CD-specific instructions", this.version = "1.0.0";
945
- }
946
- detect(e) {
947
- if (!(e.matchesPattern(".github/workflows/*.yml") || e.matchesPattern(".github/workflows/*.yaml")))
948
- return { detected: !1 };
949
- const s = {
950
- hasWorkflows: !0
951
- }, i = e.files.filter(
952
- (r) => r.startsWith(".github/workflows/") && (r.endsWith(".yml") || r.endsWith(".yaml"))
953
- );
954
- if (i.length > 0) {
955
- s.workflowCount = i.length, s.workflowFiles = i;
956
- const r = e.getTextFile(i[0]);
957
- r && (s.hasMatrixStrategy = r.includes("strategy:") && r.includes("matrix:"), s.hasCaching = r.includes("actions/cache") || r.includes("cache:"), s.hasArtifacts = r.includes("actions/upload-artifact") || r.includes("actions/download-artifact"));
958
- }
959
- return {
960
- detected: !0,
961
- tags: ["devops-github-actions", "ci-cd"],
962
- metadata: s
963
- };
964
- }
965
- generateInstructions(e, t) {
966
- return [
967
- {
968
- template: "devops/github-actions.md",
969
- suffix: "github-actions.md",
970
- targetFiles: [".github/workflows/*.yml", ".github/workflows/*.yaml"]
971
- }
972
- ];
973
- }
974
- }
975
- class Oe {
976
- constructor() {
977
- this.name = "gitlab-ci", this.description = "Detects GitLab CI/CD configuration and provides CI/CD-specific instructions", this.version = "1.0.0";
978
- }
979
- detect(e) {
980
- if (!e.hasFile(".gitlab-ci.yml"))
981
- return { detected: !1 };
982
- const s = {
983
- hasGitLabCI: !0
984
- }, i = e.getTextFile(".gitlab-ci.yml");
985
- if (i) {
986
- i.match(/^stages:\s*$/m) && (s.hasStages = !0), s.hasCache = i.includes("cache:"), s.hasArtifacts = i.includes("artifacts:"), s.hasServices = i.includes("services:"), s.hasIncludes = i.includes("include:");
987
- const o = i.match(
988
- /^stages:\s*\n((?: {2}- .+\n?)+)/m
989
- );
990
- if (o) {
991
- const a = o[1].match(/- (.+)/g)?.map((c) => c.replace(/- /, "").trim());
992
- a && (s.stages = a);
993
- }
994
- }
995
- return {
996
- detected: !0,
997
- tags: ["devops-gitlab-ci", "ci-cd"],
998
- metadata: s
999
- };
1000
- }
1001
- generateInstructions(e, t) {
1002
- return [
1003
- {
1004
- template: "devops/gitlab-ci.md",
1005
- suffix: "gitlab-ci.md",
1006
- targetFiles: [".gitlab-ci.yml"]
1007
- }
1008
- ];
1009
- }
1010
- }
1011
- class Re {
1012
- constructor() {
1013
- this.name = "golang", this.description = "Detects Go (Golang) projects and provides Go-specific instructions", this.version = "1.0.0";
1014
- }
1015
- detect(e) {
1016
- const t = e.hasFile("go.mod"), s = e.matchesPattern("**/*.go");
1017
- if (!(t || s))
1018
- return { detected: !1 };
1019
- const r = e.getTextFile("go.mod"), o = {
1020
- hasGoMod: t,
1021
- hasGoFiles: s
1022
- };
1023
- if (r) {
1024
- const a = r.match(/^module\s+(.+)$/m);
1025
- a && (o.moduleName = a[1].trim());
1026
- const c = r.match(/^go\s+([\d.]+)$/m);
1027
- c && (o.goVersion = c[1]);
1028
- }
1029
- return {
1030
- detected: !0,
1031
- tags: ["lang-go"],
1032
- metadata: o
1033
- };
1034
- }
1035
- generateInstructions(e, t) {
1036
- return [
1037
- {
1038
- template: "go/lang-go.md",
1039
- suffix: "lang-go.md",
1040
- targetFiles: ["**/*.go"]
1041
- }
1042
- ];
1043
- }
1044
- }
1045
- class _e {
1046
- constructor() {
1047
- this.name = "monorepo", this.description = "Detects monorepo structures and provides monorepo-specific instructions", this.version = "1.0.0";
1048
- }
1049
- detect(e) {
1050
- const t = e.hasFile("turbo.json"), s = e.hasFile("nx.json"), i = e.hasFile("pnpm-workspace.yaml"), r = e.hasFile("lerna.json"), o = e.hasFile("package.json") && e.getTextFile("package.json")?.includes('"workspaces"');
1051
- if (e.hasFile("package.json") && e.getTextFile("package.json")?.includes('"workspaces"'), !(t || s || i || r || o))
1052
- return { detected: !1 };
1053
- const c = {
1054
- hasTurbo: t,
1055
- hasNx: s,
1056
- hasPnpmWorkspace: i,
1057
- hasLerna: r,
1058
- hasYarnWorkspaces: o
1059
- };
1060
- if (t) {
1061
- c.tool = "turborepo";
1062
- const d = e.getTextFile("turbo.json");
1063
- d && (c.hasPipeline = d.includes('"pipeline"'));
1064
- } else s ? c.tool = "nx" : i ? c.tool = "pnpm" : r ? c.tool = "lerna" : c.tool = "npm/yarn workspaces";
1065
- const l = ["packages/*/package.json", "apps/*/package.json"], u = e.files.filter(
1066
- (d) => l.some((g) => new RegExp(g.replace(/\*/g, "[^/]+")).test(d))
1067
- );
1068
- return u.length > 0 && (c.packageCount = u.length), {
1069
- detected: !0,
1070
- tags: ["architecture-monorepo"],
1071
- metadata: c
1072
- };
1073
- }
1074
- generateInstructions(e, t) {
1075
- const s = [
1076
- {
1077
- template: "architecture/monorepo.md",
1078
- suffix: "monorepo.md",
1079
- targetFiles: [
1080
- "package.json",
1081
- "turbo.json",
1082
- "nx.json",
1083
- "pnpm-workspace.yaml",
1084
- "lerna.json"
1085
- ]
1086
- }
1087
- ];
1088
- return t?.tool === "turborepo" ? s.push({
1089
- template: "architecture/turborepo.md",
1090
- suffix: "turborepo.md",
1091
- targetFiles: ["turbo.json"]
1092
- }) : t?.tool === "nx" && s.push({
1093
- template: "architecture/nx.md",
1094
- suffix: "nx.md",
1095
- targetFiles: ["nx.json", "workspace.json"]
1096
- }), s;
1097
- }
1098
- }
1099
- class Ae {
1100
- constructor() {
1101
- this.name = "php", this.description = "Detects PHP projects and provides PHP-specific instructions", this.version = "1.0.0";
1102
- }
1103
- detect(e) {
1104
- const t = e.hasFile("composer.json"), s = e.hasFile("composer.lock"), i = e.matchesPattern("**/*.php");
1105
- if (!(t || i))
1106
- return { detected: !1 };
1107
- const o = {
1108
- hasComposerJson: t,
1109
- hasComposerLock: s,
1110
- hasPhpFiles: i
1111
- }, a = e.getTextFile("composer.json");
1112
- if (a) {
1113
- a.includes('"laravel/framework"') ? (o.framework = "laravel", o.hasArtisan = e.hasFile("artisan")) : a.includes('"symfony/') && (o.framework = "symfony");
1114
- const c = a.match(/"name"\s*:\s*"([^"]+)"/);
1115
- c && (o.projectName = c[1]);
1116
- }
1117
- return {
1118
- detected: !0,
1119
- tags: ["lang-php"],
1120
- metadata: o
1121
- };
1122
- }
1123
- generateInstructions(e, t) {
1124
- const s = [
1125
- {
1126
- template: "php/lang-php.md",
1127
- suffix: "lang-php.md",
1128
- targetFiles: ["**/*.php"]
1129
- }
1130
- ];
1131
- return t?.framework === "laravel" && s.push({
1132
- template: "php/framework-laravel.md",
1133
- suffix: "framework-laravel.md",
1134
- targetFiles: ["**/*.php"]
1135
- }), s;
1136
- }
1137
- }
1138
- class We {
1139
- constructor() {
1140
- this.name = "python", this.description = "Detects Python projects and provides Python-specific instructions", this.version = "1.0.0";
1141
- }
1142
- detect(e) {
1143
- const t = e.hasFile("pyproject.toml"), s = e.hasFile("requirements.txt"), i = e.hasFile("setup.py"), r = e.hasFile("Pipfile"), o = e.matchesPattern("**/*.py");
1144
- if (!(t || s || i || r || o))
1145
- return { detected: !1 };
1146
- const c = {
1147
- hasPyprojectToml: t,
1148
- hasRequirementsTxt: s,
1149
- hasSetupPy: i,
1150
- hasPipfile: r,
1151
- hasPyFiles: o
1152
- };
1153
- if (t) {
1154
- const d = e.getTextFile("pyproject.toml");
1155
- d && (d.includes("[tool.poetry]") ? c.packageManager = "poetry" : d.includes("[build-system]") && (c.packageManager = "pip"));
1156
- } else r ? c.packageManager = "pipenv" : s && (c.packageManager = "pip");
1157
- const l = [], u = e.getTextFile("requirements.txt");
1158
- return u && (u.includes("django") && l.push("django"), u.includes("flask") && l.push("flask"), u.includes("fastapi") && l.push("fastapi")), l.length > 0 && (c.frameworks = l), {
1159
- detected: !0,
1160
- tags: ["lang-python"],
1161
- metadata: c
1162
- };
1163
- }
1164
- generateInstructions(e, t) {
1165
- return [
1166
- {
1167
- template: "python/lang-python.md",
1168
- suffix: "lang-python.md",
1169
- targetFiles: ["**/*.py"]
1170
- }
1171
- ];
1172
- }
1173
- }
1174
- class Ne {
1175
- constructor() {
1176
- this.name = "rust", this.description = "Detects Rust projects and provides Rust-specific instructions", this.version = "1.0.0";
1177
- }
1178
- detect(e) {
1179
- const t = e.hasFile("Cargo.toml"), s = e.hasFile("Cargo.lock"), i = e.matchesPattern("**/*.rs");
1180
- if (!(t || i))
1181
- return { detected: !1 };
1182
- const o = e.getTextFile("Cargo.toml"), a = {
1183
- hasCargoToml: t,
1184
- hasCargoLock: s,
1185
- hasRustFiles: i
1186
- };
1187
- if (o) {
1188
- const c = o.match(
1189
- /^\[package\][\s\S]*?^name\s*=\s*"(.+?)"/m
1190
- );
1191
- c && (a.packageName = c[1]);
1192
- const l = o.match(/^edition\s*=\s*"(\d+)"/m);
1193
- l && (a.edition = l[1]), o.includes("[workspace]") && (a.isWorkspace = !0);
1194
- }
1195
- return {
1196
- detected: !0,
1197
- tags: ["lang-rust"],
1198
- metadata: a
1199
- };
1200
- }
1201
- generateInstructions(e, t) {
1202
- return [
1203
- {
1204
- template: "rust/lang-rust.md",
1205
- suffix: "lang-rust.md",
1206
- targetFiles: ["**/*.rs"]
1207
- }
1208
- ];
1209
- }
1210
- }
1211
- class $ {
1212
- constructor(e = {}) {
1213
- this.loadedPlugins = /* @__PURE__ */ new Map(), this.loadErrors = [], this.verbose = e.verbose ?? !1;
1214
- }
1215
- /**
1216
- * Load built-in plugins from the magic-helix-plugins package
1217
- */
1218
- async loadBuiltinPlugins(e) {
1219
- const t = [];
1220
- try {
1221
- const { NodeJSPlugin: s } = await import("./index-Bg8DD8ku.js"), { GoPlugin: i } = await import("./index-B8pyjKdF.js"), { PythonPlugin: r } = await import("./index-OT2XAJkc.js"), { RustPlugin: o } = await import("./index-BkJhe5Af.js"), { JavaPlugin: a } = await import("./index-AkVwRl-r.js"), { RubyPlugin: c } = await import("./index-CPbv2Od1.js"), { PHPPlugin: l } = await import("./index-mYXvc3Fs.js"), { CSharpPlugin: u } = await import("./index-Cf-MC6Al.js"), { SwiftPlugin: d } = await import("./index-WmVSB57y.js"), g = [
1222
- s,
1223
- i,
1224
- r,
1225
- o,
1226
- a,
1227
- c,
1228
- l,
1229
- u,
1230
- d
1231
- ];
1232
- for (const w of g) {
1233
- const P = new w();
1234
- if (e && !e.includes(P.name))
1235
- continue;
1236
- const M = Date.now(), x = {
1237
- plugin: P,
1238
- source: {
1239
- type: "builtin",
1240
- identifier: P.name,
1241
- packageName: "magic-helix-plugins"
1242
- },
1243
- loadTime: Date.now() - M
1244
- };
1245
- this.loadedPlugins.set(P.name, x), t.push(x), this.log(
1246
- `Loaded built-in plugin: ${P.displayName} (${P.name})`
1247
- );
1248
- }
1249
- } catch (s) {
1250
- this.handleLoadError(
1251
- {
1252
- type: "builtin",
1253
- identifier: "magic-helix-plugins"
1254
- },
1255
- s
1256
- );
1257
- }
1258
- return t;
1259
- }
1260
- /**
1261
- * Load a plugin from an npm package
1262
- */
1263
- async loadNpmPlugin(e) {
1264
- try {
1265
- const t = Date.now(), s = await this.tryImport(e);
1266
- if (!s)
1267
- throw new Error(`Package "${e}" not found`);
1268
- const i = s.default || s.Plugin || s;
1269
- if (typeof i != "function")
1270
- throw new Error(
1271
- `Package "${e}" does not export a valid plugin class`
1272
- );
1273
- const r = new i(), o = Date.now() - t;
1274
- this.validatePlugin(r);
1275
- const a = {
1276
- plugin: r,
1277
- source: {
1278
- type: "npm",
1279
- identifier: e,
1280
- packageName: e
1281
- },
1282
- loadTime: o
1283
- };
1284
- return this.loadedPlugins.set(r.name, a), this.log(
1285
- `✓ Loaded npm plugin: ${r.displayName} from ${e} (${o}ms)`
1286
- ), a;
1287
- } catch (t) {
1288
- return this.handleLoadError(
1289
- {
1290
- type: "npm",
1291
- identifier: e,
1292
- packageName: e
1293
- },
1294
- t
1295
- ), null;
1296
- }
1297
- }
1298
- /**
1299
- * Load a plugin from a local file path
1300
- */
1301
- async loadLocalPlugin(e) {
1302
- try {
1303
- const t = p.resolve(e);
1304
- if (!f.existsSync(t))
1305
- throw new Error(`Plugin file not found: ${t}`);
1306
- const s = Date.now(), i = await import(t), r = Date.now() - s, o = i.default || i.Plugin || i;
1307
- if (typeof o != "function")
1308
- throw new Error(
1309
- `File "${e}" does not export a valid plugin class`
1310
- );
1311
- const a = new o();
1312
- this.validatePlugin(a);
1313
- const c = {
1314
- plugin: a,
1315
- source: {
1316
- type: "local",
1317
- identifier: e,
1318
- path: t
1319
- },
1320
- loadTime: r
1321
- };
1322
- return this.loadedPlugins.set(a.name, c), this.log(
1323
- `✓ Loaded local plugin: ${a.displayName} from ${e} (${r}ms)`
1324
- ), c;
1325
- } catch (t) {
1326
- return this.handleLoadError(
1327
- {
1328
- type: "local",
1329
- identifier: e,
1330
- path: e
1331
- },
1332
- t
1333
- ), null;
1334
- }
1335
- }
1336
- /**
1337
- * Load plugins from workspace directory
1338
- */
1339
- async loadWorkspacePlugins(e, t) {
1340
- const s = [], i = t || [
1341
- ".magic-helix/plugins/**/*.js",
1342
- ".magic-helix/plugins/**/*.mjs"
1343
- ];
1344
- try {
1345
- const { glob: r } = await import("glob");
1346
- for (const o of i) {
1347
- const a = await r(o, {
1348
- cwd: e,
1349
- absolute: !0
1350
- });
1351
- for (const c of a) {
1352
- const l = await this.loadLocalPlugin(c);
1353
- l && (l.source.type = "workspace", s.push(l));
1354
- }
1355
- }
1356
- } catch (r) {
1357
- this.logWarning(
1358
- `Error loading workspace plugins: ${r.message}`
1359
- );
1360
- }
1361
- return s;
1362
- }
1363
- /**
1364
- * Get a loaded plugin by name
1365
- */
1366
- getPlugin(e) {
1367
- return this.loadedPlugins.get(e)?.plugin;
1368
- }
1369
- /**
1370
- * Get all loaded plugins sorted by priority (highest first)
1371
- */
1372
- getAllPlugins() {
1373
- return Array.from(this.loadedPlugins.values()).map((e) => e.plugin).sort((e, t) => t.priority - e.priority);
1374
- }
1375
- /**
1376
- * Get plugins filtered by name
1377
- */
1378
- getPluginsByNames(e) {
1379
- return e.map((t) => this.getPlugin(t)).filter((t) => t !== void 0);
1380
- }
1381
- /**
1382
- * Detect project using all loaded plugins
1383
- * Returns the first successful detection from highest priority plugin
1384
- */
1385
- async detectProject(e) {
1386
- const t = this.getAllPlugins();
1387
- for (const s of t)
1388
- try {
1389
- this.log(`Trying plugin: ${s.displayName}`);
1390
- const i = await s.detect(e);
1391
- if (i)
1392
- return this.log(
1393
- `✓ Detected ${i.language} project with ${s.displayName}`
1394
- ), { metadata: i, plugin: s };
1395
- } catch (i) {
1396
- this.logWarning(
1397
- `Plugin ${s.name} detection failed: ${i.message}`
1398
- );
1399
- }
1400
- return null;
1401
- }
1402
- /**
1403
- * Detect all projects in a directory (for monorepo support)
1404
- */
1405
- async detectAllProjects(e) {
1406
- const t = [], s = this.getAllPlugins();
1407
- for (const i of s)
1408
- try {
1409
- const r = await i.detect(e);
1410
- if (r && (t.push({ metadata: r, plugin: i }), r.workspaceMembers && r.workspaceMembers.length > 0))
1411
- for (const o of r.workspaceMembers) {
1412
- const a = p.resolve(e, o), c = await this.detectProject(a);
1413
- c && t.push(c);
1414
- }
1415
- } catch (r) {
1416
- this.logWarning(
1417
- `Plugin ${i.name} failed: ${r.message}`
1418
- );
1419
- }
1420
- return t;
1421
- }
1422
- /**
1423
- * Get load errors
1424
- */
1425
- getLoadErrors() {
1426
- return [...this.loadErrors];
1427
- }
1428
- /**
1429
- * Clear all loaded plugins
1430
- */
1431
- clear() {
1432
- this.loadedPlugins.clear(), this.loadErrors = [];
1433
- }
1434
- /**
1435
- * Get statistics about loaded plugins
1436
- */
1437
- getStats() {
1438
- const e = Array.from(this.loadedPlugins.values()), t = {};
1439
- for (const s of e)
1440
- t[s.source.type] = (t[s.source.type] || 0) + 1;
1441
- return {
1442
- totalLoaded: e.length,
1443
- totalErrors: this.loadErrors.length,
1444
- averageLoadTime: e.length > 0 ? e.reduce((s, i) => s + i.loadTime, 0) / e.length : 0,
1445
- byType: t
1446
- };
1447
- }
1448
- // Private helper methods
1449
- validatePlugin(e) {
1450
- if (!e || typeof e != "object")
1451
- throw new Error("Plugin must be an object");
1452
- const t = e;
1453
- if (!t.name || typeof t.name != "string")
1454
- throw new Error('Plugin must have a "name" property');
1455
- if (!t.displayName || typeof t.displayName != "string")
1456
- throw new Error('Plugin must have a "displayName" property');
1457
- if (!t.version || typeof t.version != "string")
1458
- throw new Error('Plugin must have a "version" property');
1459
- if (typeof t.priority != "number")
1460
- throw new Error('Plugin must have a "priority" property');
1461
- if (typeof t.detect != "function")
1462
- throw new Error('Plugin must implement "detect" method');
1463
- if (typeof t.getTemplates != "function")
1464
- throw new Error('Plugin must implement "getTemplates" method');
1465
- }
1466
- async tryImport(e) {
1467
- try {
1468
- return await import(e);
1469
- } catch {
1470
- return null;
1471
- }
1472
- }
1473
- handleLoadError(e, t) {
1474
- this.loadErrors.push({
1475
- source: e,
1476
- error: t,
1477
- timestamp: /* @__PURE__ */ new Date()
1478
- }), this.logWarning(
1479
- `Failed to load plugin "${e.identifier}": ${t.message}`
1480
- );
1481
- }
1482
- log(e) {
1483
- this.verbose && console.log(`[PluginLoader] ${e}`);
1484
- }
1485
- logWarning(e) {
1486
- this.verbose && console.warn(`[PluginLoader] ⚠️ ${e}`);
1487
- }
1488
- }
1489
- const h = class h {
1490
- constructor() {
1491
- this.initialized = !1, this.loader = new $({ verbose: !1 }), this.config = {};
1492
- }
1493
- /**
1494
- * Get the singleton instance
1495
- */
1496
- static getInstance() {
1497
- return h.instance || (h.instance = new h()), h.instance;
1498
- }
1499
- /**
1500
- * Initialize the registry with configuration
1501
- */
1502
- async initialize(e = {}) {
1503
- if (!this.initialized && (this.config = e, this.loader = new $({ verbose: e.verbose }), await this.loadConfiguredPlugins(e.plugins), this.initialized = !0, e.verbose)) {
1504
- const t = this.loader.getStats();
1505
- console.log(
1506
- `[PluginRegistry] Initialized with ${t.totalLoaded} plugins`
1507
- ), console.log(
1508
- `[PluginRegistry] Load time: ${t.averageLoadTime.toFixed(2)}ms avg`
1509
- );
1510
- }
1511
- }
1512
- /**
1513
- * Reset the registry (useful for testing)
1514
- */
1515
- reset() {
1516
- this.loader.clear(), this.initialized = !1, this.config = {};
1517
- }
1518
- /**
1519
- * Ensure the registry is initialized before use
1520
- */
1521
- async ensureInitialized() {
1522
- this.initialized || await this.initialize();
1523
- }
1524
- /**
1525
- * Get a plugin by name
1526
- */
1527
- async getPlugin(e) {
1528
- return await this.ensureInitialized(), this.loader.getPlugin(e);
1529
- }
1530
- /**
1531
- * Get all loaded plugins
1532
- */
1533
- async getAllPlugins() {
1534
- return await this.ensureInitialized(), this.loader.getAllPlugins();
1535
- }
1536
- /**
1537
- * Detect the project type at the given path
1538
- */
1539
- async detectProject(e) {
1540
- return await this.ensureInitialized(), this.loader.detectProject(e);
1541
- }
1542
- /**
1543
- * Detect all projects in a directory (monorepo support)
1544
- */
1545
- async detectAllProjects(e) {
1546
- return await this.ensureInitialized(), this.loader.detectAllProjects(e);
1547
- }
1548
- /**
1549
- * Get the best plugin for a detected project language
1550
- */
1551
- async getPluginForLanguage(e) {
1552
- await this.ensureInitialized();
1553
- const t = this.loader.getAllPlugins();
1554
- let s = t.find((i) => i.name === e.toLowerCase());
1555
- return s || (s = t.find(
1556
- (i) => i.displayName.toLowerCase() === e.toLowerCase()
1557
- ), s) || (s = t.find(
1558
- (i) => i.displayName.toLowerCase().includes(e.toLowerCase()) || e.toLowerCase().includes(i.name)
1559
- )), s;
1560
- }
1561
- /**
1562
- * Load a custom plugin at runtime
1563
- */
1564
- async loadPlugin(e) {
1565
- return await this.ensureInitialized(), (e.type === "npm" ? await this.loader.loadNpmPlugin(e.path) : await this.loader.loadLocalPlugin(e.path))?.plugin ?? null;
1566
- }
1567
- /**
1568
- * Get registry statistics
1569
- */
1570
- async getStats() {
1571
- await this.ensureInitialized();
1572
- const e = this.loader.getStats();
1573
- return {
1574
- totalPlugins: e.totalLoaded,
1575
- loadErrors: e.totalErrors,
1576
- averageLoadTime: e.averageLoadTime,
1577
- pluginsByType: e.byType
1578
- };
1579
- }
1580
- /**
1581
- * Get load errors
1582
- */
1583
- async getLoadErrors() {
1584
- return await this.ensureInitialized(), this.loader.getLoadErrors().map((e) => ({
1585
- source: e.source.identifier,
1586
- error: e.error.message,
1587
- timestamp: e.timestamp
1588
- }));
1589
- }
1590
- /**
1591
- * Get plugin system statistics
1592
- */
1593
- getStatistics() {
1594
- return this.loader.getStats();
1595
- }
1596
- // Private helper methods
1597
- /**
1598
- * Load plugins based on configuration
1599
- */
1600
- async loadConfiguredPlugins(e = {}) {
1601
- const {
1602
- builtin: t = [],
1603
- npm: s = [],
1604
- local: i = [],
1605
- workspace: r = [],
1606
- disabled: o = []
1607
- } = e;
1608
- if (t.length > 0) {
1609
- const a = t.filter(
1610
- (c) => !o.includes(c)
1611
- );
1612
- await this.loader.loadBuiltinPlugins(a);
1613
- } else
1614
- await this.loader.loadBuiltinPlugins();
1615
- o.includes("@el-j/magic-helix-plugins") || await this.loader.loadNpmPlugin("@el-j/magic-helix-plugins").catch(() => {
1616
- });
1617
- for (const a of s)
1618
- o.includes(a) || await this.loader.loadNpmPlugin(a);
1619
- for (const a of i)
1620
- if (!o.includes(a)) {
1621
- const c = this.resolvePath(a);
1622
- await this.loader.loadLocalPlugin(c);
1623
- }
1624
- this.config.workspacePath && r.length > 0 && await this.loader.loadWorkspacePlugins(
1625
- this.config.workspacePath,
1626
- r
1627
- ), e.priority && this.applyPriorityOverrides(e.priority);
1628
- }
1629
- /**
1630
- * Resolve plugin path (handle ~/ and relative paths)
1631
- */
1632
- resolvePath(e) {
1633
- if (e.startsWith("~/")) {
1634
- const s = process.env.HOME || process.env.USERPROFILE || "";
1635
- return p.join(s, e.slice(2));
1636
- }
1637
- if (p.isAbsolute(e))
1638
- return e;
1639
- const t = this.config.workspacePath || process.cwd();
1640
- return p.resolve(t, e);
1641
- }
1642
- /**
1643
- * Apply priority overrides from configuration
1644
- */
1645
- applyPriorityOverrides(e) {
1646
- for (const [t, s] of Object.entries(e)) {
1647
- const i = this.loader.getPlugin(t);
1648
- i && (i.priority = s);
1649
- }
1650
- }
1651
- /**
1652
- * Load configuration from file
1653
- */
1654
- static async loadConfigFromFile(e) {
1655
- try {
1656
- if (!f.existsSync(e))
1657
- return null;
1658
- const t = f.readFileSync(e, "utf-8");
1659
- return JSON.parse(t);
1660
- } catch (t) {
1661
- return console.warn(
1662
- `Failed to load config from ${e}: ${t.message}`
1663
- ), null;
1664
- }
1665
- }
1666
- /**
1667
- * Load configuration from workspace and global locations
1668
- */
1669
- static async loadConfig(e) {
1670
- const t = [], s = process.env.HOME || process.env.USERPROFILE;
1671
- if (s) {
1672
- const i = p.join(
1673
- s,
1674
- ".magic-helix",
1675
- "config.json"
1676
- ), r = await h.loadConfigFromFile(i);
1677
- r && t.push(r);
1678
- }
1679
- if (e) {
1680
- const i = p.join(e, ".magic-helix.json"), r = await h.loadConfigFromFile(i);
1681
- r && (r.workspacePath = e, t.push(r));
1682
- }
1683
- return t.length === 0 ? { workspacePath: e } : t.reduce(
1684
- (i, r) => {
1685
- const o = {
1686
- ...i.plugins || {},
1687
- ...r.plugins || {}
1688
- }, a = {
1689
- ...i.templates || {},
1690
- ...r.templates || {}
1691
- };
1692
- return Object.assign({}, i, r, {
1693
- plugins: o,
1694
- templates: a
1695
- });
1696
- },
1697
- { workspacePath: e }
1698
- );
1699
- }
1700
- };
1701
- h.instance = null;
1702
- let k = h;
1703
- function Ge() {
1704
- return k.getInstance();
1705
- }
1706
- async function ze(n) {
1707
- const e = k.getInstance();
1708
- return await e.initialize(n), e;
1709
- }
1710
- class Be {
1711
- constructor(e = {}) {
1712
- this.templateCache = /* @__PURE__ */ new Map(), this.config = e.config || {}, this.verbose = e.verbose ?? !1, this.cacheEnabled = e.cacheEnabled ?? !0;
1713
- }
1714
- /**
1715
- * Load a template by name with priority resolution
1716
- */
1717
- async loadTemplate(e, t = []) {
1718
- const s = `${e}:${t.map((i) => i.name).join(",")}`;
1719
- if (this.cacheEnabled && this.templateCache.has(s)) {
1720
- const i = this.templateCache.get(s);
1721
- if (i)
1722
- return {
1723
- content: i,
1724
- source: "plugin",
1725
- path: "(cached)"
1726
- };
1727
- }
1728
- if (this.config.overrides?.[e]) {
1729
- const i = this.config.overrides[e], r = await this.loadFromPath(i, "override");
1730
- if (r)
1731
- return this.cacheTemplate(s, r.content), r;
1732
- }
1733
- if (this.config.searchPaths)
1734
- for (const i of this.config.searchPaths) {
1735
- const r = await this.searchInDirectory(
1736
- i,
1737
- e,
1738
- i.includes(".magic-helix") ? "workspace" : "global"
1739
- );
1740
- if (r)
1741
- return this.cacheTemplate(s, r.content), r;
1742
- }
1743
- for (const i of t) {
1744
- const r = await this.loadFromPlugin(i, e);
1745
- if (r)
1746
- return this.cacheTemplate(s, r.content), r;
1747
- }
1748
- return this.log(`Template "${e}" not found`), null;
1749
- }
1750
- /**
1751
- * Load all templates from a plugin
1752
- */
1753
- async loadPluginTemplates(e) {
1754
- try {
1755
- const t = await Promise.resolve(e.getTemplates());
1756
- return this.log(
1757
- `Loaded ${t.length} templates from ${e.displayName}`
1758
- ), t;
1759
- } catch (t) {
1760
- return this.logWarning(
1761
- `Failed to load templates from ${e.name}: ${t.message}`
1762
- ), [];
1763
- }
1764
- }
1765
- /**
1766
- * Load multiple templates by names
1767
- */
1768
- async loadTemplates(e, t = []) {
1769
- const s = /* @__PURE__ */ new Map();
1770
- for (const i of e) {
1771
- const r = await this.loadTemplate(i, t);
1772
- r && s.set(i, r);
1773
- }
1774
- return s;
1775
- }
1776
- /**
1777
- * Find templates matching specific tags
1778
- */
1779
- async findTemplatesByTags(e, t = []) {
1780
- const s = [];
1781
- for (const i of t) {
1782
- const r = await this.loadPluginTemplates(i);
1783
- s.push(...r);
1784
- }
1785
- return s.filter((i) => i.tags.some((r) => e.includes(r)));
1786
- }
1787
- /**
1788
- * Resolve template content (handle lazy loading)
1789
- */
1790
- async resolveTemplateContent(e) {
1791
- return typeof e.content == "string" ? e.content : await Promise.resolve(e.content());
1792
- }
1793
- /**
1794
- * Clear the template cache
1795
- */
1796
- clearCache() {
1797
- this.templateCache.clear(), this.log("Template cache cleared");
1798
- }
1799
- /**
1800
- * Get cache statistics
1801
- */
1802
- getCacheStats() {
1803
- return {
1804
- size: this.templateCache.size,
1805
- keys: Array.from(this.templateCache.keys())
1806
- };
1807
- }
1808
- // Private helper methods
1809
- /**
1810
- * Load template from a specific file path
1811
- */
1812
- async loadFromPath(e, t) {
1813
- try {
1814
- const s = this.resolvePath(e);
1815
- if (!f.existsSync(s))
1816
- return this.log(`Template not found at: ${s}`), null;
1817
- const i = f.readFileSync(s, "utf-8");
1818
- return this.log(`✓ Loaded template from ${t}: ${s}`), {
1819
- content: i,
1820
- source: t,
1821
- path: s
1822
- };
1823
- } catch (s) {
1824
- return this.logWarning(
1825
- `Failed to load template from ${e}: ${s.message}`
1826
- ), null;
1827
- }
1828
- }
1829
- /**
1830
- * Search for template in a directory
1831
- */
1832
- async searchInDirectory(e, t, s) {
1833
- const i = this.resolvePath(e);
1834
- if (!f.existsSync(i))
1835
- return null;
1836
- const r = this.config.extensions || [".md", ".txt", ""];
1837
- for (const o of r) {
1838
- const a = t.endsWith(o) ? t : `${t}${o}`, c = p.join(i, a);
1839
- if (f.existsSync(c))
1840
- return this.loadFromPath(c, s);
1841
- }
1842
- return null;
1843
- }
1844
- /**
1845
- * Load template from plugin
1846
- */
1847
- async loadFromPlugin(e, t) {
1848
- try {
1849
- const i = (await this.loadPluginTemplates(e)).find((o) => o.name === t);
1850
- if (!i)
1851
- return null;
1852
- const r = await this.resolveTemplateContent(i);
1853
- return this.log(
1854
- `✓ Loaded template "${t}" from plugin: ${e.displayName}`
1855
- ), {
1856
- content: r,
1857
- source: "plugin",
1858
- path: `plugin:${e.name}/${t}`,
1859
- plugin: e.name
1860
- };
1861
- } catch (s) {
1862
- return this.logWarning(
1863
- `Failed to load template "${t}" from plugin ${e.name}: ${s.message}`
1864
- ), null;
1865
- }
1866
- }
1867
- /**
1868
- * Resolve path (handle ~/ and relative paths)
1869
- */
1870
- resolvePath(e) {
1871
- if (e.startsWith("~/")) {
1872
- const t = process.env.HOME || process.env.USERPROFILE || "";
1873
- return p.join(t, e.slice(2));
1874
- }
1875
- return p.isAbsolute(e) ? e : p.resolve(process.cwd(), e);
1876
- }
1877
- /**
1878
- * Cache a template
1879
- */
1880
- cacheTemplate(e, t) {
1881
- this.cacheEnabled && this.templateCache.set(e, t);
1882
- }
1883
- log(e) {
1884
- this.verbose && console.log(`[TemplateLoader] ${e}`);
1885
- }
1886
- logWarning(e) {
1887
- this.verbose && console.warn(`[TemplateLoader] ⚠️ ${e}`);
1888
- }
1889
- }
1890
- const C = ".magic-helix", L = "meta-instructions.json";
1891
- function ce(n) {
1892
- const e = p.join(n, C, L);
1893
- if (!f.existsSync(e))
1894
- return null;
1895
- try {
1896
- const t = f.readFileSync(e, "utf-8");
1897
- return JSON.parse(t);
1898
- } catch (t) {
1899
- return console.warn(
1900
- `Failed to load meta-instruction config: ${t.message}`
1901
- ), null;
1902
- }
1903
- }
1904
- function le(n) {
1905
- const e = p.join(n, C, "overrides"), t = /* @__PURE__ */ new Map();
1906
- if (!f.existsSync(e))
1907
- return t;
1908
- const s = A.sync("**/*.md", { cwd: e, absolute: !0 });
1909
- for (const i of s) {
1910
- const r = p.basename(i, ".md"), o = f.readFileSync(i, "utf-8");
1911
- t.set(r, o);
1912
- }
1913
- return t;
1914
- }
1915
- function ue(n, e, t) {
1916
- const s = new Map(n);
1917
- if (e.ignoreTags)
1918
- for (const r of e.ignoreTags)
1919
- s.delete(r);
1920
- const i = le(t);
1921
- for (const [r, o] of i)
1922
- s.set(r, o);
1923
- if (e.overrides)
1924
- for (const r of e.overrides) {
1925
- const o = s.get(r.tag);
1926
- switch (r.mode) {
1927
- case "replace":
1928
- s.set(r.tag, r.content);
1929
- break;
1930
- case "prepend":
1931
- o ? s.set(r.tag, `${r.content}
1932
-
1933
- ${o}`) : s.set(r.tag, r.content);
1934
- break;
1935
- case "append":
1936
- o ? s.set(r.tag, `${o}
1937
-
1938
- ${r.content}`) : s.set(r.tag, r.content);
1939
- break;
1940
- }
1941
- }
1942
- return s;
1943
- }
1944
- function de(n, e) {
1945
- const t = new Map(n);
1946
- let s = e.template;
1947
- for (const i of e.tags) {
1948
- const r = n.get(i);
1949
- r && (s = s.replace(`{{${i}}}`, r));
1950
- }
1951
- return t.set(e.outputTag, s), t;
1952
- }
1953
- function qe(n, e) {
1954
- const t = ce(e);
1955
- if (!t)
1956
- return n;
1957
- let s = ue(n, t, e);
1958
- if (t.combiners)
1959
- for (const i of t.combiners)
1960
- s = de(s, i);
1961
- return s;
1962
- }
1963
- function He(n) {
1964
- const e = p.join(n, C);
1965
- return f.existsSync(e);
1966
- }
1967
- function Ue(n) {
1968
- const e = p.join(n, C), t = p.join(e, "overrides");
1969
- f.mkdirSync(e, { recursive: !0 }), f.mkdirSync(t, { recursive: !0 });
1970
- const s = {
1971
- overrides: [
1972
- {
1973
- tag: "example-tag",
1974
- content: `# Custom Instruction
1975
-
1976
- Your content here...`,
1977
- mode: "replace"
1978
- }
1979
- ],
1980
- combiners: [
1981
- {
1982
- tags: ["tag1", "tag2"],
1983
- outputTag: "combined-tag",
1984
- template: `# Combined Instructions
1985
-
1986
- {{tag1}}
1987
-
1988
- ---
1989
-
1990
- {{tag2}}`
1991
- }
1992
- ],
1993
- ignoreTags: ["unwanted-tag"]
1994
- }, i = p.join(e, L);
1995
- f.writeFileSync(i, JSON.stringify(s, null, 2)), f.writeFileSync(p.join(t, "example.md"), `# Example Override
1996
-
1997
- This file overrides the default instructions for this tag.
1998
- Create files like:
1999
- - react-core.md → overrides "react-core" tag
2000
- - style-tailwind.md → overrides "style-tailwind" tag
2001
- `), console.log(
2002
- `✅ Initialized .magic-helix/ directory structure at: ${e}`
2003
- );
2004
- }
2005
- class ge {
2006
- constructor(e = {}) {
2007
- this.enabled = !!e.enabled;
2008
- const t = e.dir || F.resolve(process.cwd(), ".magic-helix/telemetry");
2009
- this.filePath = F.join(t, "events.jsonl"), this.sessionId = e.sessionId, this.variant = e.variant, this.projectRoot = e.projectRoot, this.enabled && E.mkdirSync(F.dirname(this.filePath), { recursive: !0 });
2010
- }
2011
- isEnabled() {
2012
- return this.enabled;
2013
- }
2014
- track(e) {
2015
- if (!this.enabled) return;
2016
- const t = {
2017
- ...e,
2018
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
2019
- sessionId: this.sessionId,
2020
- projectRoot: this.projectRoot
2021
- };
2022
- "variant" in e && e.variant ? t.variant = e.variant : t.variant = this.variant;
2023
- const s = `${JSON.stringify(t)}
2024
- `;
2025
- E.appendFileSync(this.filePath, s, "utf-8");
2026
- }
2027
- }
2028
- function Je(n = {}) {
2029
- const e = n.enabled ?? process.env.MAGIC_HELIX_TELEMETRY === "1", t = n.dir || process.env.MAGIC_HELIX_TELEMETRY_DIR, s = n.sessionId || process.env.MAGIC_HELIX_SESSION_ID || `${Date.now()}`, i = n.variant || process.env.MAGIC_HELIX_VARIANT || "default", r = n.projectRoot || process.cwd();
2030
- return new ge({ enabled: e, dir: t, sessionId: s, variant: i, projectRoot: r });
2031
- }
2032
- function Ve(n) {
2033
- return n.map((e) => {
2034
- const t = se(e.context), s = D(t);
2035
- return {
2036
- variant: e.name,
2037
- instructions: t,
2038
- score: s.overallScore,
2039
- structureScore: s.structureScore,
2040
- clarityScore: s.clarityScore,
2041
- completenessScore: s.completenessScore,
2042
- missingCount: s.missingElements.length
2043
- };
2044
- });
2045
- }
2046
- function Ye(n) {
2047
- return n.length === 0 ? {
2048
- variant: "",
2049
- instructions: "",
2050
- score: 0,
2051
- structureScore: 0,
2052
- clarityScore: 0,
2053
- completenessScore: 0,
2054
- missingCount: 0
2055
- } : n.reduce(
2056
- (e, t) => t.score > e.score ? t : e,
2057
- n[0]
2058
- );
2059
- }
2060
- function Qe(n, e) {
2061
- if (e?.isEnabled())
2062
- for (const t of n) {
2063
- const s = {
2064
- type: "instruction_validation",
2065
- file: `ab-test-variant-${t.variant}`,
2066
- score: t.score,
2067
- structureScore: t.structureScore,
2068
- clarityScore: t.clarityScore,
2069
- completenessScore: t.completenessScore,
2070
- missingCount: t.missingCount,
2071
- variant: t.variant
2072
- };
2073
- e.track(s);
2074
- }
2075
- }
2076
- const pe = _(import.meta.url), fe = O(pe), Xe = R(fe, "default_templates");
2077
- export {
2078
- ze as A,
2079
- Xe as B,
2080
- De as C,
2081
- Le as D,
2082
- ce as E,
2083
- le as F,
2084
- Me as G,
2085
- ue as H,
2086
- ne as I,
2087
- de as J,
2088
- qe as K,
2089
- He as L,
2090
- _e as M,
2091
- Ue as N,
2092
- Je as O,
2093
- Ae as P,
2094
- ge as Q,
2095
- Ne as R,
2096
- Ve as S,
2097
- Be as T,
2098
- Ye as U,
2099
- Qe as V,
2100
- xe as _,
2101
- Oe as a,
2102
- Re as b,
2103
- We as c,
2104
- Pe as d,
2105
- G as e,
2106
- ke as f,
2107
- I as g,
2108
- Se as h,
2109
- se as i,
2110
- K as j,
2111
- te as k,
2112
- Ce as l,
2113
- Fe as m,
2114
- Te as n,
2115
- re as o,
2116
- Ee as p,
2117
- $e as q,
2118
- be as r,
2119
- ee as s,
2120
- Ie as t,
2121
- oe as u,
2122
- D as v,
2123
- m as w,
2124
- $ as x,
2125
- k as y,
2126
- Ge as z
2127
- };
2128
- //# sourceMappingURL=index-Dm37u5ut.js.map