aios-core 4.0.2 → 4.0.4

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 (145) hide show
  1. package/.aios-core/.session/current-session.json +14 -0
  2. package/.aios-core/core/registry/registry-schema.json +166 -166
  3. package/.aios-core/core/registry/service-registry.json +6585 -6585
  4. package/.aios-core/data/registry-update-log.jsonl +113 -0
  5. package/.aios-core/development/scripts/approval-workflow.js +642 -642
  6. package/.aios-core/development/scripts/backup-manager.js +606 -606
  7. package/.aios-core/development/scripts/branch-manager.js +389 -389
  8. package/.aios-core/development/scripts/code-quality-improver.js +1311 -1311
  9. package/.aios-core/development/scripts/commit-message-generator.js +849 -849
  10. package/.aios-core/development/scripts/conflict-resolver.js +674 -674
  11. package/.aios-core/development/scripts/dependency-analyzer.js +637 -637
  12. package/.aios-core/development/scripts/diff-generator.js +351 -351
  13. package/.aios-core/development/scripts/elicitation-engine.js +384 -384
  14. package/.aios-core/development/scripts/elicitation-session-manager.js +299 -299
  15. package/.aios-core/development/scripts/git-wrapper.js +461 -461
  16. package/.aios-core/development/scripts/manifest-preview.js +244 -244
  17. package/.aios-core/development/scripts/metrics-tracker.js +775 -775
  18. package/.aios-core/development/scripts/modification-validator.js +554 -554
  19. package/.aios-core/development/scripts/pattern-learner.js +1224 -1224
  20. package/.aios-core/development/scripts/performance-analyzer.js +757 -757
  21. package/.aios-core/development/scripts/refactoring-suggester.js +1138 -1138
  22. package/.aios-core/development/scripts/rollback-handler.js +530 -530
  23. package/.aios-core/development/scripts/security-checker.js +358 -358
  24. package/.aios-core/development/scripts/template-engine.js +239 -239
  25. package/.aios-core/development/scripts/template-validator.js +278 -278
  26. package/.aios-core/development/scripts/test-generator.js +843 -843
  27. package/.aios-core/development/scripts/transaction-manager.js +589 -589
  28. package/.aios-core/development/scripts/usage-tracker.js +673 -673
  29. package/.aios-core/development/scripts/validate-filenames.js +226 -226
  30. package/.aios-core/development/scripts/version-tracker.js +526 -526
  31. package/.aios-core/development/scripts/yaml-validator.js +396 -396
  32. package/.aios-core/development/templates/service-template/README.md.hbs +158 -158
  33. package/.aios-core/development/templates/service-template/__tests__/index.test.ts.hbs +237 -237
  34. package/.aios-core/development/templates/service-template/client.ts.hbs +403 -403
  35. package/.aios-core/development/templates/service-template/errors.ts.hbs +182 -182
  36. package/.aios-core/development/templates/service-template/index.ts.hbs +120 -120
  37. package/.aios-core/development/templates/service-template/package.json.hbs +87 -87
  38. package/.aios-core/development/templates/service-template/types.ts.hbs +145 -145
  39. package/.aios-core/development/templates/squad-template/LICENSE +21 -21
  40. package/.aios-core/docs/SHARD-TRANSLATION-GUIDE.md +335 -0
  41. package/.aios-core/docs/component-creation-guide.md +458 -0
  42. package/.aios-core/docs/session-update-pattern.md +307 -0
  43. package/.aios-core/docs/standards/AIOS-FRAMEWORK-MASTER.md +1963 -0
  44. package/.aios-core/docs/standards/AIOS-LIVRO-DE-OURO-V2.1-SUMMARY.md +1190 -0
  45. package/.aios-core/docs/standards/AIOS-LIVRO-DE-OURO-V2.1.md +439 -0
  46. package/.aios-core/docs/standards/AIOS-LIVRO-DE-OURO.md +5398 -0
  47. package/.aios-core/docs/standards/V3-ARCHITECTURAL-DECISIONS.md +523 -0
  48. package/.aios-core/docs/template-syntax.md +267 -0
  49. package/.aios-core/docs/troubleshooting-guide.md +625 -0
  50. package/.aios-core/infrastructure/templates/aios-sync.yaml.template +193 -193
  51. package/.aios-core/infrastructure/templates/coderabbit.yaml.template +279 -279
  52. package/.aios-core/infrastructure/templates/github-workflows/ci.yml.template +169 -169
  53. package/.aios-core/infrastructure/templates/github-workflows/pr-automation.yml.template +330 -330
  54. package/.aios-core/infrastructure/templates/github-workflows/release.yml.template +196 -196
  55. package/.aios-core/infrastructure/templates/gitignore/gitignore-aios-base.tmpl +63 -63
  56. package/.aios-core/infrastructure/templates/gitignore/gitignore-brownfield-merge.tmpl +18 -18
  57. package/.aios-core/infrastructure/templates/gitignore/gitignore-node.tmpl +85 -85
  58. package/.aios-core/infrastructure/templates/gitignore/gitignore-python.tmpl +145 -145
  59. package/.aios-core/infrastructure/tests/utilities-audit-results.json +501 -0
  60. package/.aios-core/install-manifest.yaml +97 -97
  61. package/.aios-core/local-config.yaml.template +68 -68
  62. package/.aios-core/manifests/agents.csv +1 -0
  63. package/.aios-core/manifests/schema/manifest-schema.json +190 -190
  64. package/.aios-core/manifests/tasks.csv +121 -0
  65. package/.aios-core/manifests/workers.csv +204 -0
  66. package/.aios-core/monitor/hooks/lib/__init__.py +1 -1
  67. package/.aios-core/monitor/hooks/lib/enrich.py +58 -58
  68. package/.aios-core/monitor/hooks/lib/send_event.py +47 -47
  69. package/.aios-core/monitor/hooks/notification.py +29 -29
  70. package/.aios-core/monitor/hooks/post_tool_use.py +45 -45
  71. package/.aios-core/monitor/hooks/pre_compact.py +29 -29
  72. package/.aios-core/monitor/hooks/pre_tool_use.py +40 -40
  73. package/.aios-core/monitor/hooks/stop.py +29 -29
  74. package/.aios-core/monitor/hooks/subagent_stop.py +29 -29
  75. package/.aios-core/monitor/hooks/user_prompt_submit.py +38 -38
  76. package/.aios-core/product/templates/adr.hbs +125 -125
  77. package/.aios-core/product/templates/component-react-tmpl.tsx +98 -98
  78. package/.aios-core/product/templates/dbdr.hbs +241 -241
  79. package/.aios-core/product/templates/engine/schemas/adr.schema.json +102 -102
  80. package/.aios-core/product/templates/engine/schemas/dbdr.schema.json +205 -205
  81. package/.aios-core/product/templates/engine/schemas/epic.schema.json +175 -175
  82. package/.aios-core/product/templates/engine/schemas/pmdr.schema.json +175 -175
  83. package/.aios-core/product/templates/engine/schemas/prd-v2.schema.json +300 -300
  84. package/.aios-core/product/templates/engine/schemas/prd.schema.json +152 -152
  85. package/.aios-core/product/templates/engine/schemas/story.schema.json +222 -222
  86. package/.aios-core/product/templates/engine/schemas/task.schema.json +154 -154
  87. package/.aios-core/product/templates/epic.hbs +212 -212
  88. package/.aios-core/product/templates/eslintrc-security.json +32 -32
  89. package/.aios-core/product/templates/github-actions-cd.yml +212 -212
  90. package/.aios-core/product/templates/github-actions-ci.yml +172 -172
  91. package/.aios-core/product/templates/pmdr.hbs +186 -186
  92. package/.aios-core/product/templates/prd-v2.0.hbs +216 -216
  93. package/.aios-core/product/templates/prd.hbs +201 -201
  94. package/.aios-core/product/templates/shock-report-tmpl.html +502 -502
  95. package/.aios-core/product/templates/story.hbs +263 -263
  96. package/.aios-core/product/templates/task.hbs +170 -170
  97. package/.aios-core/product/templates/tmpl-comment-on-examples.sql +158 -158
  98. package/.aios-core/product/templates/tmpl-migration-script.sql +91 -91
  99. package/.aios-core/product/templates/tmpl-rls-granular-policies.sql +104 -104
  100. package/.aios-core/product/templates/tmpl-rls-kiss-policy.sql +10 -10
  101. package/.aios-core/product/templates/tmpl-rls-roles.sql +135 -135
  102. package/.aios-core/product/templates/tmpl-rls-simple.sql +77 -77
  103. package/.aios-core/product/templates/tmpl-rls-tenant.sql +152 -152
  104. package/.aios-core/product/templates/tmpl-rollback-script.sql +77 -77
  105. package/.aios-core/product/templates/tmpl-seed-data.sql +140 -140
  106. package/.aios-core/product/templates/tmpl-smoke-test.sql +16 -16
  107. package/.aios-core/product/templates/tmpl-staging-copy-merge.sql +139 -139
  108. package/.aios-core/product/templates/tmpl-stored-proc.sql +140 -140
  109. package/.aios-core/product/templates/tmpl-trigger.sql +152 -152
  110. package/.aios-core/product/templates/tmpl-view-materialized.sql +133 -133
  111. package/.aios-core/product/templates/tmpl-view.sql +177 -177
  112. package/.aios-core/product/templates/token-exports-css-tmpl.css +240 -240
  113. package/.aios-core/quality/schemas/quality-metrics.schema.json +233 -233
  114. package/.aios-core/scripts/migrate-framework-docs.sh +300 -300
  115. package/.aios-core/scripts/pm.sh +0 -0
  116. package/.claude/hooks/enforce-architecture-first.py +196 -0
  117. package/.claude/hooks/install-hooks.sh +41 -0
  118. package/.claude/hooks/mind-clone-governance.py +192 -0
  119. package/.claude/hooks/pre-commit-mmos-guard.sh +99 -0
  120. package/.claude/hooks/pre-commit-version-check.sh +156 -0
  121. package/.claude/hooks/read-protection.py +151 -0
  122. package/.claude/hooks/slug-validation.py +176 -0
  123. package/.claude/hooks/sql-governance.py +182 -0
  124. package/.claude/hooks/write-path-validation.py +194 -0
  125. package/.claude/rules/agent-authority.md +105 -0
  126. package/.claude/rules/coderabbit-integration.md +93 -0
  127. package/.claude/rules/ids-principles.md +112 -0
  128. package/.claude/rules/story-lifecycle.md +139 -0
  129. package/.claude/rules/workflow-execution.md +150 -0
  130. package/LICENSE +48 -48
  131. package/README.md +30 -7
  132. package/bin/aios-minimal.js +0 -0
  133. package/bin/aios.js +15 -15
  134. package/package.json +2 -4
  135. package/packages/aios-install/bin/aios-install.js +0 -0
  136. package/packages/aios-install/bin/edmcp.js +0 -0
  137. package/packages/aios-pro-cli/bin/aios-pro.js +0 -0
  138. package/scripts/check-markdown-links.py +352 -352
  139. package/scripts/dashboard-parallel-dev.sh +0 -0
  140. package/scripts/dashboard-parallel-phase3.sh +0 -0
  141. package/scripts/dashboard-parallel-phase4.sh +0 -0
  142. package/scripts/glue/README.md +355 -0
  143. package/scripts/glue/compose-agent-prompt.cjs +362 -0
  144. package/scripts/install-monitor-hooks.sh +0 -0
  145. package/.aios-core/lib/build.json +0 -1
@@ -1,397 +1,397 @@
1
- /**
2
- * YAML Validator for AIOS Developer Meta-Agent
3
- * Ensures YAML files maintain proper structure and syntax
4
- */
5
-
6
- const yaml = require('js-yaml');
7
- const fs = require('fs-extra');
8
-
9
- class YAMLValidator {
10
- constructor() {
11
- this.validationRules = {
12
- agent: {
13
- required: ['agent', 'persona', 'commands'],
14
- optional: ['dependencies', 'security', 'customization'],
15
- structure: {
16
- agent: {
17
- required: ['name', 'id', 'title', 'icon', 'whenToUse'],
18
- optional: ['customization']
19
- },
20
- persona: {
21
- required: ['role', 'style', 'identity', 'focus'],
22
- optional: []
23
- }
24
- }
25
- },
26
- manifest: {
27
- required: ['bundle', 'agents'],
28
- optional: ['workflows'],
29
- structure: {
30
- bundle: {
31
- required: ['name', 'icon', 'description'],
32
- optional: []
33
- }
34
- }
35
- },
36
- workflow: {
37
- required: ['workflow', 'stages'],
38
- optional: ['transitions', 'resources', 'validation'],
39
- structure: {
40
- workflow: {
41
- required: ['id', 'name', 'description', 'type', 'scope'],
42
- optional: []
43
- }
44
- }
45
- }
46
- };
47
- }
48
-
49
- /**
50
- * Validate YAML content
51
- */
52
- async validate(content, type = 'general') {
53
- const results = {
54
- valid: true,
55
- errors: [],
56
- warnings: [],
57
- parsed: null
58
- };
59
-
60
- try {
61
- // Parse YAML
62
- results.parsed = yaml.load(content, {
63
- schema: yaml.SAFE_SCHEMA,
64
- onWarning: (warning) => {
65
- results.warnings.push({
66
- type: 'yaml_warning',
67
- message: warning.toString()
68
- });
69
- }
70
- });
71
-
72
- // Type-specific validation
73
- if (type !== 'general' && this.validationRules[type]) {
74
- this.validateStructure(results.parsed, type, results);
75
- }
76
-
77
- // General validations
78
- this.validateGeneral(results.parsed, results);
79
-
80
- } catch (error) {
81
- results.valid = false;
82
- results.errors.push({
83
- type: 'parse_error',
84
- message: error.message,
85
- line: error.mark ? error.mark.line : null,
86
- column: error.mark ? error.mark.column : null
87
- });
88
- }
89
-
90
- return results;
91
- }
92
-
93
- /**
94
- * Validate YAML file
95
- */
96
- async validateFile(filePath, type = 'general') {
97
- try {
98
- const content = await fs.readFile(filePath, 'utf8');
99
- const results = await this.validate(content, type);
100
- results.filePath = filePath;
101
- return results;
102
- } catch (error) {
103
- return {
104
- valid: false,
105
- filePath,
106
- errors: [{
107
- type: 'file_error',
108
- message: `Could not read file: ${error.message}`
109
- }]
110
- };
111
- }
112
- }
113
-
114
- /**
115
- * Validate structure based on type
116
- */
117
- validateStructure(data, type, results) {
118
- const rules = this.validationRules[type];
119
-
120
- // Check required top-level fields
121
- for (const field of rules.required) {
122
- if (!data.hasOwnProperty(field)) {
123
- results.valid = false;
124
- results.errors.push({
125
- type: 'missing_required',
126
- field,
127
- message: `Missing required field: ${field}`
128
- });
129
- }
130
- }
131
-
132
- // Check structure of specific fields
133
- if (rules.structure) {
134
- for (const [field, fieldRules] of Object.entries(rules.structure)) {
135
- if (data[field]) {
136
- this.validateFieldStructure(
137
- data[field],
138
- field,
139
- fieldRules,
140
- results
141
- );
142
- }
143
- }
144
- }
145
-
146
- // Warn about unknown fields
147
- const allKnownFields = [
148
- ...(rules.required || []),
149
- ...(rules.optional || [])
150
- ];
151
-
152
- for (const field of Object.keys(data)) {
153
- if (!allKnownFields.includes(field)) {
154
- results.warnings.push({
155
- type: 'unknown_field',
156
- field,
157
- message: `Unknown field: ${field}`
158
- });
159
- }
160
- }
161
- }
162
-
163
- /**
164
- * Validate field structure
165
- */
166
- validateFieldStructure(data, fieldName, rules, results) {
167
- // Check required subfields
168
- for (const subfield of rules.required || []) {
169
- if (!data.hasOwnProperty(subfield)) {
170
- results.valid = false;
171
- results.errors.push({
172
- type: 'missing_required',
173
- field: `${fieldName}.${subfield}`,
174
- message: `Missing required field: ${fieldName}.${subfield}`
175
- });
176
- }
177
- }
178
-
179
- // Check field types
180
- this.validateFieldTypes(data, fieldName, results);
181
- }
182
-
183
- /**
184
- * Validate field types
185
- */
186
- validateFieldTypes(data, fieldName, results) {
187
- for (const [key, value] of Object.entries(data)) {
188
- const fullPath = `${fieldName}.${key}`;
189
-
190
- // Check for null/undefined
191
- if (value === null || value === undefined) {
192
- results.warnings.push({
193
- type: 'null_value',
194
- field: fullPath,
195
- message: `Null or undefined value at ${fullPath}`
196
- });
197
- }
198
-
199
- // Type-specific checks
200
- if (key === 'id' || key === 'name') {
201
- if (typeof value !== 'string' || value.trim() === '') {
202
- results.errors.push({
203
- type: 'invalid_type',
204
- field: fullPath,
205
- message: `${fullPath} must be a non-empty string`
206
- });
207
- }
208
- }
209
-
210
- if (key === 'icon' && typeof value === 'string') {
211
- // Check if it's a valid emoji or icon string
212
- if (value.length === 0) {
213
- results.warnings.push({
214
- type: 'empty_icon',
215
- field: fullPath,
216
- message: 'Icon field is empty'
217
- });
218
- }
219
- }
220
- }
221
- }
222
-
223
- /**
224
- * General validations for all YAML
225
- */
226
- validateGeneral(data, results) {
227
- // Check for circular references
228
- try {
229
- JSON.stringify(data);
230
- } catch (error) {
231
- if (error.message.includes('circular')) {
232
- results.valid = false;
233
- results.errors.push({
234
- type: 'circular_reference',
235
- message: 'Circular reference detected in YAML structure'
236
- });
237
- }
238
- }
239
-
240
- // Check for excessively deep nesting
241
- const maxDepth = this.getMaxDepth(data);
242
- if (maxDepth > 10) {
243
- results.warnings.push({
244
- type: 'deep_nesting',
245
- depth: maxDepth,
246
- message: `Deep nesting detected (${maxDepth} levels)`
247
- });
248
- }
249
- }
250
-
251
- /**
252
- * Get maximum depth of object
253
- */
254
- getMaxDepth(obj, currentDepth = 0) {
255
- if (typeof obj !== 'object' || obj === null) {
256
- return currentDepth;
257
- }
258
-
259
- let maxDepth = currentDepth;
260
- for (const value of Object.values(obj)) {
261
- if (typeof value === 'object') {
262
- const depth = this.getMaxDepth(value, currentDepth + 1);
263
- maxDepth = Math.max(maxDepth, depth);
264
- }
265
- }
266
-
267
- return maxDepth;
268
- }
269
-
270
- /**
271
- * Fix common YAML issues
272
- */
273
- async autoFix(content, type = 'general') {
274
- let fixed = content;
275
-
276
- // Fix common indentation issues
277
- fixed = this.fixIndentation(fixed);
278
-
279
- // Fix quote issues
280
- fixed = this.fixQuotes(fixed);
281
-
282
- // Validate the fixed content
283
- const validation = await this.validate(fixed, type);
284
-
285
- return {
286
- content: fixed,
287
- validation,
288
- changed: content !== fixed
289
- };
290
- }
291
-
292
- /**
293
- * Fix indentation issues
294
- * @param {string} content - YAML content to fix
295
- * @returns {string} Fixed YAML content
296
- */
297
- fixIndentation(content) {
298
- const lines = content.split('\n');
299
- const fixedLines = [];
300
- const indentStack = [0];
301
- let currentLevel = 0;
302
-
303
- for (let i = 0; i < lines.length; i++) {
304
- const line = lines[i];
305
- const trimmed = line.trim();
306
-
307
- // Skip empty lines and comments
308
- if (!trimmed || trimmed.startsWith('#')) {
309
- fixedLines.push(line);
310
- continue;
311
- }
312
-
313
- // Handle list items
314
- if (trimmed.startsWith('-')) {
315
- const baseIndent = indentStack[indentStack.length - 1];
316
- fixedLines.push(' '.repeat(baseIndent) + trimmed);
317
-
318
- // If list item has a key-value pair, prepare for nested content
319
- if (trimmed.includes(':') && !trimmed.endsWith(':')) {
320
- const afterDash = trimmed.substring(1).trim();
321
- if (afterDash.includes(':')) {
322
- currentLevel = baseIndent + 2;
323
- }
324
- }
325
- }
326
- // Handle key-value pairs
327
- else if (trimmed.includes(':')) {
328
- // Find appropriate indent level
329
- const colonIndex = trimmed.indexOf(':');
330
- const _key = trimmed.substring(0, colonIndex);
331
-
332
- // Pop stack until we find the right level
333
- while (indentStack.length > 1 &&
334
- line.length - line.trimStart().length < indentStack[indentStack.length - 1]) {
335
- indentStack.pop();
336
- }
337
-
338
- currentLevel = indentStack[indentStack.length - 1];
339
- fixedLines.push(' '.repeat(currentLevel) + trimmed);
340
-
341
- // If this opens a new block, push new indent level
342
- if (trimmed.endsWith(':') || (i + 1 < lines.length && lines[i + 1].trim() &&
343
- lines[i + 1].length - lines[i + 1].trimStart().length > currentLevel)) {
344
- indentStack.push(currentLevel + 2);
345
- }
346
- } else {
347
- // Regular content line
348
- fixedLines.push(' '.repeat(currentLevel) + trimmed);
349
- }
350
- }
351
-
352
- return fixedLines.join('\n');
353
- }
354
-
355
- /**
356
- * Fix quote issues
357
- */
358
- fixQuotes(content) {
359
- // Fix unquoted strings that need quotes
360
- return content.replace(
361
- /^(\s*\w+):\s*([^"'\n]*[:{}\[\]|>&*!%@`][^"'\n]*)$/gm,
362
- '$1: "$2"'
363
- );
364
- }
365
-
366
- /**
367
- * Generate validation report
368
- */
369
- generateReport(validation) {
370
- const report = [];
371
-
372
- report.push(`YAML Validation Report`);
373
- report.push(`=====================`);
374
- report.push(`Valid: ${validation.valid ? '✅ Yes' : '❌ No'}`);
375
-
376
- if (validation.errors.length > 0) {
377
- report.push(`\nErrors (${validation.errors.length}):`);
378
- for (const error of validation.errors) {
379
- report.push(` - ${error.message}`);
380
- if (error.line) {
381
- report.push(` Line: ${error.line}, Column: ${error.column}`);
382
- }
383
- }
384
- }
385
-
386
- if (validation.warnings.length > 0) {
387
- report.push(`\nWarnings (${validation.warnings.length}):`);
388
- for (const warning of validation.warnings) {
389
- report.push(` - ${warning.message}`);
390
- }
391
- }
392
-
393
- return report.join('\n');
394
- }
395
- }
396
-
1
+ /**
2
+ * YAML Validator for AIOS Developer Meta-Agent
3
+ * Ensures YAML files maintain proper structure and syntax
4
+ */
5
+
6
+ const yaml = require('js-yaml');
7
+ const fs = require('fs-extra');
8
+
9
+ class YAMLValidator {
10
+ constructor() {
11
+ this.validationRules = {
12
+ agent: {
13
+ required: ['agent', 'persona', 'commands'],
14
+ optional: ['dependencies', 'security', 'customization'],
15
+ structure: {
16
+ agent: {
17
+ required: ['name', 'id', 'title', 'icon', 'whenToUse'],
18
+ optional: ['customization']
19
+ },
20
+ persona: {
21
+ required: ['role', 'style', 'identity', 'focus'],
22
+ optional: []
23
+ }
24
+ }
25
+ },
26
+ manifest: {
27
+ required: ['bundle', 'agents'],
28
+ optional: ['workflows'],
29
+ structure: {
30
+ bundle: {
31
+ required: ['name', 'icon', 'description'],
32
+ optional: []
33
+ }
34
+ }
35
+ },
36
+ workflow: {
37
+ required: ['workflow', 'stages'],
38
+ optional: ['transitions', 'resources', 'validation'],
39
+ structure: {
40
+ workflow: {
41
+ required: ['id', 'name', 'description', 'type', 'scope'],
42
+ optional: []
43
+ }
44
+ }
45
+ }
46
+ };
47
+ }
48
+
49
+ /**
50
+ * Validate YAML content
51
+ */
52
+ async validate(content, type = 'general') {
53
+ const results = {
54
+ valid: true,
55
+ errors: [],
56
+ warnings: [],
57
+ parsed: null
58
+ };
59
+
60
+ try {
61
+ // Parse YAML
62
+ results.parsed = yaml.load(content, {
63
+ schema: yaml.SAFE_SCHEMA,
64
+ onWarning: (warning) => {
65
+ results.warnings.push({
66
+ type: 'yaml_warning',
67
+ message: warning.toString()
68
+ });
69
+ }
70
+ });
71
+
72
+ // Type-specific validation
73
+ if (type !== 'general' && this.validationRules[type]) {
74
+ this.validateStructure(results.parsed, type, results);
75
+ }
76
+
77
+ // General validations
78
+ this.validateGeneral(results.parsed, results);
79
+
80
+ } catch (error) {
81
+ results.valid = false;
82
+ results.errors.push({
83
+ type: 'parse_error',
84
+ message: error.message,
85
+ line: error.mark ? error.mark.line : null,
86
+ column: error.mark ? error.mark.column : null
87
+ });
88
+ }
89
+
90
+ return results;
91
+ }
92
+
93
+ /**
94
+ * Validate YAML file
95
+ */
96
+ async validateFile(filePath, type = 'general') {
97
+ try {
98
+ const content = await fs.readFile(filePath, 'utf8');
99
+ const results = await this.validate(content, type);
100
+ results.filePath = filePath;
101
+ return results;
102
+ } catch (error) {
103
+ return {
104
+ valid: false,
105
+ filePath,
106
+ errors: [{
107
+ type: 'file_error',
108
+ message: `Could not read file: ${error.message}`
109
+ }]
110
+ };
111
+ }
112
+ }
113
+
114
+ /**
115
+ * Validate structure based on type
116
+ */
117
+ validateStructure(data, type, results) {
118
+ const rules = this.validationRules[type];
119
+
120
+ // Check required top-level fields
121
+ for (const field of rules.required) {
122
+ if (!data.hasOwnProperty(field)) {
123
+ results.valid = false;
124
+ results.errors.push({
125
+ type: 'missing_required',
126
+ field,
127
+ message: `Missing required field: ${field}`
128
+ });
129
+ }
130
+ }
131
+
132
+ // Check structure of specific fields
133
+ if (rules.structure) {
134
+ for (const [field, fieldRules] of Object.entries(rules.structure)) {
135
+ if (data[field]) {
136
+ this.validateFieldStructure(
137
+ data[field],
138
+ field,
139
+ fieldRules,
140
+ results
141
+ );
142
+ }
143
+ }
144
+ }
145
+
146
+ // Warn about unknown fields
147
+ const allKnownFields = [
148
+ ...(rules.required || []),
149
+ ...(rules.optional || [])
150
+ ];
151
+
152
+ for (const field of Object.keys(data)) {
153
+ if (!allKnownFields.includes(field)) {
154
+ results.warnings.push({
155
+ type: 'unknown_field',
156
+ field,
157
+ message: `Unknown field: ${field}`
158
+ });
159
+ }
160
+ }
161
+ }
162
+
163
+ /**
164
+ * Validate field structure
165
+ */
166
+ validateFieldStructure(data, fieldName, rules, results) {
167
+ // Check required subfields
168
+ for (const subfield of rules.required || []) {
169
+ if (!data.hasOwnProperty(subfield)) {
170
+ results.valid = false;
171
+ results.errors.push({
172
+ type: 'missing_required',
173
+ field: `${fieldName}.${subfield}`,
174
+ message: `Missing required field: ${fieldName}.${subfield}`
175
+ });
176
+ }
177
+ }
178
+
179
+ // Check field types
180
+ this.validateFieldTypes(data, fieldName, results);
181
+ }
182
+
183
+ /**
184
+ * Validate field types
185
+ */
186
+ validateFieldTypes(data, fieldName, results) {
187
+ for (const [key, value] of Object.entries(data)) {
188
+ const fullPath = `${fieldName}.${key}`;
189
+
190
+ // Check for null/undefined
191
+ if (value === null || value === undefined) {
192
+ results.warnings.push({
193
+ type: 'null_value',
194
+ field: fullPath,
195
+ message: `Null or undefined value at ${fullPath}`
196
+ });
197
+ }
198
+
199
+ // Type-specific checks
200
+ if (key === 'id' || key === 'name') {
201
+ if (typeof value !== 'string' || value.trim() === '') {
202
+ results.errors.push({
203
+ type: 'invalid_type',
204
+ field: fullPath,
205
+ message: `${fullPath} must be a non-empty string`
206
+ });
207
+ }
208
+ }
209
+
210
+ if (key === 'icon' && typeof value === 'string') {
211
+ // Check if it's a valid emoji or icon string
212
+ if (value.length === 0) {
213
+ results.warnings.push({
214
+ type: 'empty_icon',
215
+ field: fullPath,
216
+ message: 'Icon field is empty'
217
+ });
218
+ }
219
+ }
220
+ }
221
+ }
222
+
223
+ /**
224
+ * General validations for all YAML
225
+ */
226
+ validateGeneral(data, results) {
227
+ // Check for circular references
228
+ try {
229
+ JSON.stringify(data);
230
+ } catch (error) {
231
+ if (error.message.includes('circular')) {
232
+ results.valid = false;
233
+ results.errors.push({
234
+ type: 'circular_reference',
235
+ message: 'Circular reference detected in YAML structure'
236
+ });
237
+ }
238
+ }
239
+
240
+ // Check for excessively deep nesting
241
+ const maxDepth = this.getMaxDepth(data);
242
+ if (maxDepth > 10) {
243
+ results.warnings.push({
244
+ type: 'deep_nesting',
245
+ depth: maxDepth,
246
+ message: `Deep nesting detected (${maxDepth} levels)`
247
+ });
248
+ }
249
+ }
250
+
251
+ /**
252
+ * Get maximum depth of object
253
+ */
254
+ getMaxDepth(obj, currentDepth = 0) {
255
+ if (typeof obj !== 'object' || obj === null) {
256
+ return currentDepth;
257
+ }
258
+
259
+ let maxDepth = currentDepth;
260
+ for (const value of Object.values(obj)) {
261
+ if (typeof value === 'object') {
262
+ const depth = this.getMaxDepth(value, currentDepth + 1);
263
+ maxDepth = Math.max(maxDepth, depth);
264
+ }
265
+ }
266
+
267
+ return maxDepth;
268
+ }
269
+
270
+ /**
271
+ * Fix common YAML issues
272
+ */
273
+ async autoFix(content, type = 'general') {
274
+ let fixed = content;
275
+
276
+ // Fix common indentation issues
277
+ fixed = this.fixIndentation(fixed);
278
+
279
+ // Fix quote issues
280
+ fixed = this.fixQuotes(fixed);
281
+
282
+ // Validate the fixed content
283
+ const validation = await this.validate(fixed, type);
284
+
285
+ return {
286
+ content: fixed,
287
+ validation,
288
+ changed: content !== fixed
289
+ };
290
+ }
291
+
292
+ /**
293
+ * Fix indentation issues
294
+ * @param {string} content - YAML content to fix
295
+ * @returns {string} Fixed YAML content
296
+ */
297
+ fixIndentation(content) {
298
+ const lines = content.split('\n');
299
+ const fixedLines = [];
300
+ const indentStack = [0];
301
+ let currentLevel = 0;
302
+
303
+ for (let i = 0; i < lines.length; i++) {
304
+ const line = lines[i];
305
+ const trimmed = line.trim();
306
+
307
+ // Skip empty lines and comments
308
+ if (!trimmed || trimmed.startsWith('#')) {
309
+ fixedLines.push(line);
310
+ continue;
311
+ }
312
+
313
+ // Handle list items
314
+ if (trimmed.startsWith('-')) {
315
+ const baseIndent = indentStack[indentStack.length - 1];
316
+ fixedLines.push(' '.repeat(baseIndent) + trimmed);
317
+
318
+ // If list item has a key-value pair, prepare for nested content
319
+ if (trimmed.includes(':') && !trimmed.endsWith(':')) {
320
+ const afterDash = trimmed.substring(1).trim();
321
+ if (afterDash.includes(':')) {
322
+ currentLevel = baseIndent + 2;
323
+ }
324
+ }
325
+ }
326
+ // Handle key-value pairs
327
+ else if (trimmed.includes(':')) {
328
+ // Find appropriate indent level
329
+ const colonIndex = trimmed.indexOf(':');
330
+ const _key = trimmed.substring(0, colonIndex);
331
+
332
+ // Pop stack until we find the right level
333
+ while (indentStack.length > 1 &&
334
+ line.length - line.trimStart().length < indentStack[indentStack.length - 1]) {
335
+ indentStack.pop();
336
+ }
337
+
338
+ currentLevel = indentStack[indentStack.length - 1];
339
+ fixedLines.push(' '.repeat(currentLevel) + trimmed);
340
+
341
+ // If this opens a new block, push new indent level
342
+ if (trimmed.endsWith(':') || (i + 1 < lines.length && lines[i + 1].trim() &&
343
+ lines[i + 1].length - lines[i + 1].trimStart().length > currentLevel)) {
344
+ indentStack.push(currentLevel + 2);
345
+ }
346
+ } else {
347
+ // Regular content line
348
+ fixedLines.push(' '.repeat(currentLevel) + trimmed);
349
+ }
350
+ }
351
+
352
+ return fixedLines.join('\n');
353
+ }
354
+
355
+ /**
356
+ * Fix quote issues
357
+ */
358
+ fixQuotes(content) {
359
+ // Fix unquoted strings that need quotes
360
+ return content.replace(
361
+ /^(\s*\w+):\s*([^"'\n]*[:{}\[\]|>&*!%@`][^"'\n]*)$/gm,
362
+ '$1: "$2"'
363
+ );
364
+ }
365
+
366
+ /**
367
+ * Generate validation report
368
+ */
369
+ generateReport(validation) {
370
+ const report = [];
371
+
372
+ report.push(`YAML Validation Report`);
373
+ report.push(`=====================`);
374
+ report.push(`Valid: ${validation.valid ? '✅ Yes' : '❌ No'}`);
375
+
376
+ if (validation.errors.length > 0) {
377
+ report.push(`\nErrors (${validation.errors.length}):`);
378
+ for (const error of validation.errors) {
379
+ report.push(` - ${error.message}`);
380
+ if (error.line) {
381
+ report.push(` Line: ${error.line}, Column: ${error.column}`);
382
+ }
383
+ }
384
+ }
385
+
386
+ if (validation.warnings.length > 0) {
387
+ report.push(`\nWarnings (${validation.warnings.length}):`);
388
+ for (const warning of validation.warnings) {
389
+ report.push(` - ${warning.message}`);
390
+ }
391
+ }
392
+
393
+ return report.join('\n');
394
+ }
395
+ }
396
+
397
397
  module.exports = YAMLValidator;