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