moai-adk 0.8.3__py3-none-any.whl → 0.9.0__py3-none-any.whl
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.
Potentially problematic release.
This version of moai-adk might be problematic. Click here for more details.
- moai_adk/templates/.claude/hooks/alfred/core/project.py +750 -0
- moai_adk/templates/.claude/hooks/alfred/shared/core/project.py +77 -10
- moai_adk/templates/.moai/memory/gitflow-protection-policy.md +140 -30
- moai_adk/templates/README.md +256 -0
- {moai_adk-0.8.3.dist-info → moai_adk-0.9.0.dist-info}/METADATA +333 -35
- {moai_adk-0.8.3.dist-info → moai_adk-0.9.0.dist-info}/RECORD +9 -25
- moai_adk/templates/.claude/hooks/alfred/.moai/cache/version-check.json +0 -9
- moai_adk/templates/.claude/hooks/alfred/README.md +0 -343
- moai_adk/templates/.claude/hooks/alfred/TROUBLESHOOTING.md +0 -471
- moai_adk/templates/.github/workflows/tag-report.yml +0 -261
- moai_adk/templates/.github/workflows/tag-validation.yml +0 -176
- moai_adk/templates/.moai/docs/quick-issue-creation-guide.md +0 -219
- moai_adk/templates/.moai/hooks/install.sh +0 -79
- moai_adk/templates/.moai/hooks/pre-commit.sh +0 -66
- moai_adk/templates/.moai/memory/CONFIG-SCHEMA.md +0 -444
- moai_adk/templates/.moai/memory/GITFLOW-PROTECTION-POLICY.md +0 -220
- moai_adk/templates/.moai/memory/spec-metadata.md +0 -356
- moai_adk/templates/src/moai_adk/core/__init__.py +0 -5
- moai_adk/templates/src/moai_adk/core/tags/__init__.py +0 -86
- moai_adk/templates/src/moai_adk/core/tags/ci_validator.py +0 -433
- moai_adk/templates/src/moai_adk/core/tags/cli.py +0 -283
- moai_adk/templates/src/moai_adk/core/tags/pre_commit_validator.py +0 -355
- moai_adk/templates/src/moai_adk/core/tags/reporter.py +0 -957
- moai_adk/templates/src/moai_adk/core/tags/validator.py +0 -897
- {moai_adk-0.8.3.dist-info → moai_adk-0.9.0.dist-info}/WHEEL +0 -0
- {moai_adk-0.8.3.dist-info → moai_adk-0.9.0.dist-info}/entry_points.txt +0 -0
- {moai_adk-0.8.3.dist-info → moai_adk-0.9.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,433 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
# @CODE:DOC-TAG-004 | Component 2: CI/CD pipeline TAG validator
|
|
3
|
-
"""CI/CD TAG validation module for GitHub Actions
|
|
4
|
-
|
|
5
|
-
This module extends PreCommitValidator for CI/CD environments:
|
|
6
|
-
- Fetches PR changed files via GitHub API
|
|
7
|
-
- Generates structured validation reports (JSON/markdown)
|
|
8
|
-
- Posts validation results as PR comments
|
|
9
|
-
- Supports strict mode (block merge on warnings) and info mode
|
|
10
|
-
|
|
11
|
-
Used by GitHub Actions workflow to validate TAGs on every PR.
|
|
12
|
-
"""
|
|
13
|
-
|
|
14
|
-
import json
|
|
15
|
-
import os
|
|
16
|
-
from typing import Any, Dict, List, Optional
|
|
17
|
-
|
|
18
|
-
import requests
|
|
19
|
-
|
|
20
|
-
from .pre_commit_validator import (
|
|
21
|
-
PreCommitValidator,
|
|
22
|
-
ValidationResult,
|
|
23
|
-
)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
class CIValidator(PreCommitValidator):
|
|
27
|
-
"""CI/CD TAG validator for GitHub Actions
|
|
28
|
-
|
|
29
|
-
Extends PreCommitValidator with CI/CD-specific features:
|
|
30
|
-
- GitHub API integration for PR file detection
|
|
31
|
-
- Structured report generation for automation
|
|
32
|
-
- Markdown comment formatting for PR feedback
|
|
33
|
-
- Environment variable support for GitHub Actions
|
|
34
|
-
|
|
35
|
-
Args:
|
|
36
|
-
github_token: GitHub API token (default: from GITHUB_TOKEN env)
|
|
37
|
-
repo_owner: Repository owner (default: from GITHUB_REPOSITORY env)
|
|
38
|
-
repo_name: Repository name (default: from GITHUB_REPOSITORY env)
|
|
39
|
-
strict_mode: Treat warnings as errors
|
|
40
|
-
check_orphans: Enable orphan TAG detection
|
|
41
|
-
tag_pattern: Custom TAG regex pattern
|
|
42
|
-
"""
|
|
43
|
-
|
|
44
|
-
def __init__(
|
|
45
|
-
self,
|
|
46
|
-
github_token: Optional[str] = None,
|
|
47
|
-
repo_owner: Optional[str] = None,
|
|
48
|
-
repo_name: Optional[str] = None,
|
|
49
|
-
strict_mode: bool = False,
|
|
50
|
-
check_orphans: bool = True,
|
|
51
|
-
tag_pattern: Optional[str] = None
|
|
52
|
-
):
|
|
53
|
-
super().__init__(strict_mode, check_orphans, tag_pattern)
|
|
54
|
-
|
|
55
|
-
# GitHub configuration from environment or parameters
|
|
56
|
-
self.github_token = github_token or os.environ.get('GITHUB_TOKEN', '')
|
|
57
|
-
|
|
58
|
-
# Parse repo info from GITHUB_REPOSITORY (format: "owner/repo")
|
|
59
|
-
repo_full = os.environ.get('GITHUB_REPOSITORY', '')
|
|
60
|
-
if '/' in repo_full and not repo_owner and not repo_name:
|
|
61
|
-
parts = repo_full.split('/', 1)
|
|
62
|
-
self.repo_owner = parts[0]
|
|
63
|
-
self.repo_name = parts[1]
|
|
64
|
-
else:
|
|
65
|
-
self.repo_owner = repo_owner or ''
|
|
66
|
-
self.repo_name = repo_name or ''
|
|
67
|
-
|
|
68
|
-
def get_pr_changed_files(self, pr_number: int) -> List[str]:
|
|
69
|
-
"""Fetch list of changed files in a PR via GitHub API
|
|
70
|
-
|
|
71
|
-
Args:
|
|
72
|
-
pr_number: Pull request number
|
|
73
|
-
|
|
74
|
-
Returns:
|
|
75
|
-
List of relative file paths changed in the PR
|
|
76
|
-
"""
|
|
77
|
-
if not self.github_token or not self.repo_owner or not self.repo_name:
|
|
78
|
-
return []
|
|
79
|
-
|
|
80
|
-
url = (
|
|
81
|
-
f"https://api.github.com/repos/"
|
|
82
|
-
f"{self.repo_owner}/{self.repo_name}/pulls/{pr_number}/files"
|
|
83
|
-
)
|
|
84
|
-
|
|
85
|
-
headers = {
|
|
86
|
-
'Authorization': f'Bearer {self.github_token}',
|
|
87
|
-
'Accept': 'application/vnd.github.v3+json'
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
try:
|
|
91
|
-
response = requests.get(url, headers=headers, timeout=10)
|
|
92
|
-
response.raise_for_status()
|
|
93
|
-
|
|
94
|
-
files_data = response.json()
|
|
95
|
-
return [file_info['filename'] for file_info in files_data]
|
|
96
|
-
|
|
97
|
-
except Exception:
|
|
98
|
-
# Return empty list on any error (network, auth, etc.)
|
|
99
|
-
return []
|
|
100
|
-
|
|
101
|
-
def validate_pr_changes(
|
|
102
|
-
self,
|
|
103
|
-
pr_number: int,
|
|
104
|
-
base_branch: str = "main"
|
|
105
|
-
) -> ValidationResult:
|
|
106
|
-
"""Validate TAG annotations in PR changed files
|
|
107
|
-
|
|
108
|
-
Main CI/CD validation method:
|
|
109
|
-
1. Fetch changed files from GitHub API
|
|
110
|
-
2. Run validation checks on those files
|
|
111
|
-
3. Return structured validation result
|
|
112
|
-
|
|
113
|
-
Args:
|
|
114
|
-
pr_number: Pull request number
|
|
115
|
-
base_branch: Base branch name (not used currently)
|
|
116
|
-
|
|
117
|
-
Returns:
|
|
118
|
-
ValidationResult with errors and warnings
|
|
119
|
-
"""
|
|
120
|
-
# Get PR changed files
|
|
121
|
-
files = self.get_pr_changed_files(pr_number)
|
|
122
|
-
|
|
123
|
-
if not files:
|
|
124
|
-
return ValidationResult(is_valid=True)
|
|
125
|
-
|
|
126
|
-
# Validate the changed files
|
|
127
|
-
return self.validate_files(files)
|
|
128
|
-
|
|
129
|
-
def generate_report(self, result: ValidationResult) -> Dict[str, Any]:
|
|
130
|
-
"""Generate structured validation report
|
|
131
|
-
|
|
132
|
-
Creates JSON-serializable report with:
|
|
133
|
-
- Status (success/failure/success_with_warnings)
|
|
134
|
-
- Error details (message, tag, locations)
|
|
135
|
-
- Warning details (message, tag, location)
|
|
136
|
-
- Statistics (counts)
|
|
137
|
-
- Configuration (strict_mode)
|
|
138
|
-
|
|
139
|
-
Args:
|
|
140
|
-
result: ValidationResult from validation
|
|
141
|
-
|
|
142
|
-
Returns:
|
|
143
|
-
Dictionary with structured report data
|
|
144
|
-
"""
|
|
145
|
-
# Determine status
|
|
146
|
-
if not result.is_valid:
|
|
147
|
-
status = 'failure'
|
|
148
|
-
elif result.warnings:
|
|
149
|
-
status = 'success_with_warnings'
|
|
150
|
-
else:
|
|
151
|
-
status = 'success'
|
|
152
|
-
|
|
153
|
-
# Build error list
|
|
154
|
-
errors = []
|
|
155
|
-
for error in result.errors:
|
|
156
|
-
errors.append({
|
|
157
|
-
'message': error.message,
|
|
158
|
-
'tag': error.tag,
|
|
159
|
-
'locations': [
|
|
160
|
-
{'file': filepath, 'line': line_num}
|
|
161
|
-
for filepath, line_num in error.locations
|
|
162
|
-
]
|
|
163
|
-
})
|
|
164
|
-
|
|
165
|
-
# Build warning list
|
|
166
|
-
warnings = []
|
|
167
|
-
for warning in result.warnings:
|
|
168
|
-
warnings.append({
|
|
169
|
-
'message': warning.message,
|
|
170
|
-
'tag': warning.tag,
|
|
171
|
-
'location': {
|
|
172
|
-
'file': warning.location[0],
|
|
173
|
-
'line': warning.location[1]
|
|
174
|
-
}
|
|
175
|
-
})
|
|
176
|
-
|
|
177
|
-
# Calculate statistics
|
|
178
|
-
statistics = {
|
|
179
|
-
'total_errors': len(result.errors),
|
|
180
|
-
'total_warnings': len(result.warnings),
|
|
181
|
-
'total_issues': len(result.errors) + len(result.warnings)
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
# Build complete report
|
|
185
|
-
report = {
|
|
186
|
-
'status': status,
|
|
187
|
-
'is_valid': result.is_valid,
|
|
188
|
-
'strict_mode': self.strict_mode,
|
|
189
|
-
'summary': self._generate_summary(result),
|
|
190
|
-
'errors': errors,
|
|
191
|
-
'warnings': warnings,
|
|
192
|
-
'statistics': statistics
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
return report
|
|
196
|
-
|
|
197
|
-
def _generate_summary(self, result: ValidationResult) -> str:
|
|
198
|
-
"""Generate human-readable summary text
|
|
199
|
-
|
|
200
|
-
Args:
|
|
201
|
-
result: ValidationResult
|
|
202
|
-
|
|
203
|
-
Returns:
|
|
204
|
-
Summary string
|
|
205
|
-
"""
|
|
206
|
-
if result.is_valid and not result.warnings:
|
|
207
|
-
return "All TAG validations passed. No issues found."
|
|
208
|
-
elif result.is_valid and result.warnings:
|
|
209
|
-
return f"Validation passed with {len(result.warnings)} warning(s)."
|
|
210
|
-
else:
|
|
211
|
-
return f"Validation failed with {len(result.errors)} error(s)."
|
|
212
|
-
|
|
213
|
-
def format_pr_comment(
|
|
214
|
-
self,
|
|
215
|
-
result: ValidationResult,
|
|
216
|
-
pr_url: str
|
|
217
|
-
) -> str:
|
|
218
|
-
"""Format validation result as markdown PR comment
|
|
219
|
-
|
|
220
|
-
Creates formatted markdown comment with:
|
|
221
|
-
- Status indicator (emoji)
|
|
222
|
-
- Summary message
|
|
223
|
-
- Error/warning table
|
|
224
|
-
- Action items
|
|
225
|
-
- Documentation links
|
|
226
|
-
|
|
227
|
-
Args:
|
|
228
|
-
result: ValidationResult from validation
|
|
229
|
-
pr_url: URL of the pull request
|
|
230
|
-
|
|
231
|
-
Returns:
|
|
232
|
-
Markdown-formatted comment string
|
|
233
|
-
"""
|
|
234
|
-
lines = []
|
|
235
|
-
|
|
236
|
-
# Header with status indicator
|
|
237
|
-
if result.is_valid and not result.warnings:
|
|
238
|
-
lines.append("## ✅ TAG Validation Passed")
|
|
239
|
-
lines.append("")
|
|
240
|
-
lines.append("All TAG annotations are valid. No issues found.")
|
|
241
|
-
elif result.is_valid and result.warnings:
|
|
242
|
-
lines.append("## ⚠️ TAG Validation Passed with Warnings")
|
|
243
|
-
lines.append("")
|
|
244
|
-
lines.append(f"Validation passed but found {len(result.warnings)} warning(s).")
|
|
245
|
-
else:
|
|
246
|
-
lines.append("## ❌ TAG Validation Failed")
|
|
247
|
-
lines.append("")
|
|
248
|
-
lines.append(f"Found {len(result.errors)} error(s) that must be fixed.")
|
|
249
|
-
|
|
250
|
-
lines.append("")
|
|
251
|
-
|
|
252
|
-
# Error table
|
|
253
|
-
if result.errors:
|
|
254
|
-
lines.append("### Errors")
|
|
255
|
-
lines.append("")
|
|
256
|
-
lines.append("| TAG | Issue | Location |")
|
|
257
|
-
lines.append("|-----|-------|----------|")
|
|
258
|
-
|
|
259
|
-
for error in result.errors:
|
|
260
|
-
tag = error.tag
|
|
261
|
-
message = error.message
|
|
262
|
-
locations = ', '.join([
|
|
263
|
-
f"`{f}:{l}`" for f, l in error.locations[:3]
|
|
264
|
-
])
|
|
265
|
-
if len(error.locations) > 3:
|
|
266
|
-
locations += f" (+{len(error.locations) - 3} more)"
|
|
267
|
-
|
|
268
|
-
lines.append(f"| `{tag}` | {message} | {locations} |")
|
|
269
|
-
|
|
270
|
-
lines.append("")
|
|
271
|
-
|
|
272
|
-
# Warning table
|
|
273
|
-
if result.warnings:
|
|
274
|
-
lines.append("### Warnings")
|
|
275
|
-
lines.append("")
|
|
276
|
-
lines.append("| TAG | Issue | Location |")
|
|
277
|
-
lines.append("|-----|-------|----------|")
|
|
278
|
-
|
|
279
|
-
for warning in result.warnings:
|
|
280
|
-
tag = warning.tag
|
|
281
|
-
message = warning.message
|
|
282
|
-
location = f"`{warning.location[0]}:{warning.location[1]}`"
|
|
283
|
-
|
|
284
|
-
lines.append(f"| `{tag}` | {message} | {location} |")
|
|
285
|
-
|
|
286
|
-
lines.append("")
|
|
287
|
-
|
|
288
|
-
# Action items
|
|
289
|
-
if result.errors or result.warnings:
|
|
290
|
-
lines.append("### How to Fix")
|
|
291
|
-
lines.append("")
|
|
292
|
-
|
|
293
|
-
if result.errors:
|
|
294
|
-
lines.append("**Errors (must fix):**")
|
|
295
|
-
lines.append("- Remove duplicate TAG declarations")
|
|
296
|
-
lines.append("- Ensure TAGs follow format: `@PREFIX:DOMAIN-TYPE-NNN`")
|
|
297
|
-
lines.append("")
|
|
298
|
-
|
|
299
|
-
if result.warnings:
|
|
300
|
-
lines.append("**Warnings (recommended):**")
|
|
301
|
-
lines.append("- Add corresponding TEST tags for CODE tags")
|
|
302
|
-
lines.append("- Add corresponding CODE tags for TEST tags")
|
|
303
|
-
lines.append("- Complete TAG chain: SPEC → CODE → TEST → DOC")
|
|
304
|
-
lines.append("")
|
|
305
|
-
|
|
306
|
-
# Documentation link
|
|
307
|
-
lines.append("---")
|
|
308
|
-
lines.append("")
|
|
309
|
-
lines.append("📚 **Documentation:** [TAG System Guide](.moai/memory/tag-system-guide.md)")
|
|
310
|
-
lines.append("")
|
|
311
|
-
lines.append(f"🔗 **PR:** {pr_url}")
|
|
312
|
-
|
|
313
|
-
return "\n".join(lines)
|
|
314
|
-
|
|
315
|
-
def get_pr_number_from_event(self) -> Optional[int]:
|
|
316
|
-
"""Extract PR number from GitHub Actions event file
|
|
317
|
-
|
|
318
|
-
Reads GITHUB_EVENT_PATH to get PR number from event payload.
|
|
319
|
-
|
|
320
|
-
Returns:
|
|
321
|
-
PR number or None if not found
|
|
322
|
-
"""
|
|
323
|
-
event_path = os.environ.get('GITHUB_EVENT_PATH')
|
|
324
|
-
if not event_path:
|
|
325
|
-
return None
|
|
326
|
-
|
|
327
|
-
try:
|
|
328
|
-
with open(event_path, 'r') as f:
|
|
329
|
-
event_data = json.load(f)
|
|
330
|
-
return event_data.get('pull_request', {}).get('number')
|
|
331
|
-
except Exception:
|
|
332
|
-
return None
|
|
333
|
-
|
|
334
|
-
def generate_tag_report_link(self, pr_number: int) -> str:
|
|
335
|
-
"""Generate link to TAG reports for this PR
|
|
336
|
-
|
|
337
|
-
Integration point with Component 4 (Reporting).
|
|
338
|
-
Provides link to automated TAG reports generated by GitHub Actions.
|
|
339
|
-
|
|
340
|
-
Args:
|
|
341
|
-
pr_number: Pull request number
|
|
342
|
-
|
|
343
|
-
Returns:
|
|
344
|
-
Markdown link to TAG reports
|
|
345
|
-
"""
|
|
346
|
-
# Link to GitHub Actions artifacts or docs directory
|
|
347
|
-
if self.repo_owner and self.repo_name:
|
|
348
|
-
docs_url = (
|
|
349
|
-
f"https://github.com/{self.repo_owner}/{self.repo_name}/tree/main/docs"
|
|
350
|
-
)
|
|
351
|
-
return f"📊 [View TAG Reports]({docs_url})"
|
|
352
|
-
else:
|
|
353
|
-
return "📊 TAG Reports: See docs/ directory"
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
def main():
|
|
357
|
-
"""CLI entry point for CI/CD validation"""
|
|
358
|
-
import argparse
|
|
359
|
-
import sys
|
|
360
|
-
|
|
361
|
-
parser = argparse.ArgumentParser(
|
|
362
|
-
description="Validate TAG annotations in GitHub PR"
|
|
363
|
-
)
|
|
364
|
-
parser.add_argument(
|
|
365
|
-
"--pr-number",
|
|
366
|
-
type=int,
|
|
367
|
-
help="Pull request number (default: from GitHub Actions event)"
|
|
368
|
-
)
|
|
369
|
-
parser.add_argument(
|
|
370
|
-
"--strict",
|
|
371
|
-
action="store_true",
|
|
372
|
-
help="Treat warnings as errors"
|
|
373
|
-
)
|
|
374
|
-
parser.add_argument(
|
|
375
|
-
"--no-orphan-check",
|
|
376
|
-
action="store_true",
|
|
377
|
-
help="Disable orphan TAG checking"
|
|
378
|
-
)
|
|
379
|
-
parser.add_argument(
|
|
380
|
-
"--output-json",
|
|
381
|
-
help="Output report to JSON file"
|
|
382
|
-
)
|
|
383
|
-
parser.add_argument(
|
|
384
|
-
"--output-comment",
|
|
385
|
-
help="Output PR comment to file"
|
|
386
|
-
)
|
|
387
|
-
|
|
388
|
-
args = parser.parse_args()
|
|
389
|
-
|
|
390
|
-
validator = CIValidator(
|
|
391
|
-
strict_mode=args.strict,
|
|
392
|
-
check_orphans=not args.no_orphan_check
|
|
393
|
-
)
|
|
394
|
-
|
|
395
|
-
# Get PR number
|
|
396
|
-
pr_number = args.pr_number
|
|
397
|
-
if not pr_number:
|
|
398
|
-
pr_number = validator.get_pr_number_from_event()
|
|
399
|
-
|
|
400
|
-
if not pr_number:
|
|
401
|
-
print("Error: Could not determine PR number", file=sys.stderr)
|
|
402
|
-
sys.exit(1)
|
|
403
|
-
|
|
404
|
-
# Run validation
|
|
405
|
-
result = validator.validate_pr_changes(pr_number)
|
|
406
|
-
|
|
407
|
-
# Generate report
|
|
408
|
-
report = validator.generate_report(result)
|
|
409
|
-
|
|
410
|
-
# Output JSON report if requested
|
|
411
|
-
if args.output_json:
|
|
412
|
-
with open(args.output_json, 'w') as f:
|
|
413
|
-
json.dump(report, f, indent=2)
|
|
414
|
-
|
|
415
|
-
# Output PR comment if requested
|
|
416
|
-
if args.output_comment:
|
|
417
|
-
pr_url = (
|
|
418
|
-
f"https://github.com/{validator.repo_owner}/"
|
|
419
|
-
f"{validator.repo_name}/pull/{pr_number}"
|
|
420
|
-
)
|
|
421
|
-
comment = validator.format_pr_comment(result, pr_url)
|
|
422
|
-
with open(args.output_comment, 'w') as f:
|
|
423
|
-
f.write(comment)
|
|
424
|
-
|
|
425
|
-
# Print summary
|
|
426
|
-
print(result.format())
|
|
427
|
-
|
|
428
|
-
# Exit with error code if validation failed
|
|
429
|
-
sys.exit(0 if result.is_valid else 1)
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
if __name__ == "__main__":
|
|
433
|
-
main()
|
|
@@ -1,283 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
# @CODE:DOC-TAG-004 | Component 3: CLI utility for TAG validation
|
|
3
|
-
"""CLI utility for moai-adk validate-tags command
|
|
4
|
-
|
|
5
|
-
This module provides a command-line interface to the central TAG validator:
|
|
6
|
-
- Validate files or directories
|
|
7
|
-
- Generate reports in multiple formats (detailed, summary, JSON)
|
|
8
|
-
- Support various validation modes (strict, custom patterns)
|
|
9
|
-
- Save reports to files
|
|
10
|
-
|
|
11
|
-
Usage:
|
|
12
|
-
moai-adk validate-tags .
|
|
13
|
-
moai-adk validate-tags --strict src/
|
|
14
|
-
moai-adk validate-tags --format json --output report.json
|
|
15
|
-
moai-adk validate-tags --no-duplicates --no-orphans
|
|
16
|
-
"""
|
|
17
|
-
|
|
18
|
-
import argparse
|
|
19
|
-
import sys
|
|
20
|
-
from pathlib import Path
|
|
21
|
-
from typing import Optional
|
|
22
|
-
|
|
23
|
-
from .validator import (
|
|
24
|
-
CentralValidationResult,
|
|
25
|
-
CentralValidator,
|
|
26
|
-
ValidationConfig,
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
def create_parser() -> argparse.ArgumentParser:
|
|
31
|
-
"""Create argument parser for CLI
|
|
32
|
-
|
|
33
|
-
Returns:
|
|
34
|
-
ArgumentParser with all CLI options
|
|
35
|
-
"""
|
|
36
|
-
parser = argparse.ArgumentParser(
|
|
37
|
-
prog="moai-adk validate-tags",
|
|
38
|
-
description="Validate TAG annotations in MoAI-ADK projects",
|
|
39
|
-
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
40
|
-
epilog="""
|
|
41
|
-
Examples:
|
|
42
|
-
moai-adk validate-tags . # Validate entire project
|
|
43
|
-
moai-adk validate-tags --strict src/ # Strict validation of src/
|
|
44
|
-
moai-adk validate-tags --format json # JSON report output
|
|
45
|
-
moai-adk validate-tags --output report.json # Save report to file
|
|
46
|
-
moai-adk validate-tags --no-orphans # Disable orphan checking
|
|
47
|
-
moai-adk validate-tags --file-types py,js,md # Validate specific file types
|
|
48
|
-
|
|
49
|
-
Report Formats:
|
|
50
|
-
detailed - Full report with all issues, locations, and suggestions (default)
|
|
51
|
-
summary - Concise summary with statistics only
|
|
52
|
-
json - Machine-readable JSON format
|
|
53
|
-
|
|
54
|
-
Validation Modes:
|
|
55
|
-
Normal - Errors block, warnings reported but pass
|
|
56
|
-
Strict - Both errors and warnings block (use --strict flag)
|
|
57
|
-
"""
|
|
58
|
-
)
|
|
59
|
-
|
|
60
|
-
# Positional argument
|
|
61
|
-
parser.add_argument(
|
|
62
|
-
"path",
|
|
63
|
-
nargs="?",
|
|
64
|
-
default=".",
|
|
65
|
-
help="Path to file or directory to validate (default: current directory)"
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
# Validation options
|
|
69
|
-
parser.add_argument(
|
|
70
|
-
"--strict",
|
|
71
|
-
action="store_true",
|
|
72
|
-
help="Treat warnings as errors (block on warnings)"
|
|
73
|
-
)
|
|
74
|
-
|
|
75
|
-
parser.add_argument(
|
|
76
|
-
"--no-duplicates",
|
|
77
|
-
action="store_true",
|
|
78
|
-
help="Disable duplicate TAG checking"
|
|
79
|
-
)
|
|
80
|
-
|
|
81
|
-
parser.add_argument(
|
|
82
|
-
"--no-orphans",
|
|
83
|
-
action="store_true",
|
|
84
|
-
help="Disable orphan TAG checking"
|
|
85
|
-
)
|
|
86
|
-
|
|
87
|
-
parser.add_argument(
|
|
88
|
-
"--no-chain-check",
|
|
89
|
-
action="store_true",
|
|
90
|
-
help="Disable TAG chain integrity checking"
|
|
91
|
-
)
|
|
92
|
-
|
|
93
|
-
# File filtering options
|
|
94
|
-
parser.add_argument(
|
|
95
|
-
"--file-types",
|
|
96
|
-
help="Comma-separated file types to validate (e.g., py,js,ts)"
|
|
97
|
-
)
|
|
98
|
-
|
|
99
|
-
parser.add_argument(
|
|
100
|
-
"--ignore-patterns",
|
|
101
|
-
help="Comma-separated glob patterns to ignore (e.g., .git/*,*.pyc)"
|
|
102
|
-
)
|
|
103
|
-
|
|
104
|
-
# Report options
|
|
105
|
-
parser.add_argument(
|
|
106
|
-
"--format",
|
|
107
|
-
choices=["detailed", "summary", "json"],
|
|
108
|
-
default="detailed",
|
|
109
|
-
help="Report format (default: detailed)"
|
|
110
|
-
)
|
|
111
|
-
|
|
112
|
-
parser.add_argument(
|
|
113
|
-
"--output",
|
|
114
|
-
"-o",
|
|
115
|
-
help="Output file path (default: stdout)"
|
|
116
|
-
)
|
|
117
|
-
|
|
118
|
-
# Quiet mode
|
|
119
|
-
parser.add_argument(
|
|
120
|
-
"--quiet",
|
|
121
|
-
"-q",
|
|
122
|
-
action="store_true",
|
|
123
|
-
help="Suppress output, only return exit code"
|
|
124
|
-
)
|
|
125
|
-
|
|
126
|
-
# Version
|
|
127
|
-
parser.add_argument(
|
|
128
|
-
"--version",
|
|
129
|
-
action="version",
|
|
130
|
-
version="moai-adk 0.7.0"
|
|
131
|
-
)
|
|
132
|
-
|
|
133
|
-
return parser
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
def validate_path(path_str: str) -> Optional[Path]:
|
|
137
|
-
"""Validate that path exists
|
|
138
|
-
|
|
139
|
-
Args:
|
|
140
|
-
path_str: Path string to validate
|
|
141
|
-
|
|
142
|
-
Returns:
|
|
143
|
-
Path object if valid, None otherwise
|
|
144
|
-
"""
|
|
145
|
-
path = Path(path_str)
|
|
146
|
-
if not path.exists():
|
|
147
|
-
print(f"Error: Path does not exist: {path_str}", file=sys.stderr)
|
|
148
|
-
return None
|
|
149
|
-
return path
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
def create_config_from_args(args: argparse.Namespace) -> ValidationConfig:
|
|
153
|
-
"""Create ValidationConfig from CLI arguments
|
|
154
|
-
|
|
155
|
-
Args:
|
|
156
|
-
args: Parsed command-line arguments
|
|
157
|
-
|
|
158
|
-
Returns:
|
|
159
|
-
ValidationConfig object
|
|
160
|
-
"""
|
|
161
|
-
config = ValidationConfig(
|
|
162
|
-
strict_mode=args.strict,
|
|
163
|
-
check_duplicates=not args.no_duplicates,
|
|
164
|
-
check_orphans=not args.no_orphans,
|
|
165
|
-
check_chain_integrity=not args.no_chain_check,
|
|
166
|
-
report_format=args.format
|
|
167
|
-
)
|
|
168
|
-
|
|
169
|
-
# Parse file types if provided
|
|
170
|
-
if args.file_types:
|
|
171
|
-
config.allowed_file_types = [
|
|
172
|
-
ft.strip() for ft in args.file_types.split(",")
|
|
173
|
-
]
|
|
174
|
-
|
|
175
|
-
# Parse ignore patterns if provided
|
|
176
|
-
if args.ignore_patterns:
|
|
177
|
-
config.ignore_patterns = [
|
|
178
|
-
pattern.strip() for pattern in args.ignore_patterns.split(",")
|
|
179
|
-
]
|
|
180
|
-
|
|
181
|
-
return config
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
def run_validation(path: Path, config: ValidationConfig) -> CentralValidationResult:
|
|
185
|
-
"""Run validation on path
|
|
186
|
-
|
|
187
|
-
Args:
|
|
188
|
-
path: Path to validate (file or directory)
|
|
189
|
-
config: ValidationConfig object
|
|
190
|
-
|
|
191
|
-
Returns:
|
|
192
|
-
CentralValidationResult
|
|
193
|
-
"""
|
|
194
|
-
validator = CentralValidator(config=config)
|
|
195
|
-
|
|
196
|
-
if path.is_file():
|
|
197
|
-
result = validator.validate_files([str(path)])
|
|
198
|
-
else:
|
|
199
|
-
result = validator.validate_directory(str(path))
|
|
200
|
-
|
|
201
|
-
return result
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
def output_report(
|
|
205
|
-
result: CentralValidationResult,
|
|
206
|
-
validator: CentralValidator,
|
|
207
|
-
format: str,
|
|
208
|
-
output_file: Optional[str],
|
|
209
|
-
quiet: bool
|
|
210
|
-
) -> None:
|
|
211
|
-
"""Output validation report
|
|
212
|
-
|
|
213
|
-
Args:
|
|
214
|
-
result: CentralValidationResult
|
|
215
|
-
validator: CentralValidator instance
|
|
216
|
-
format: Report format (detailed|summary|json)
|
|
217
|
-
output_file: Output file path (None for stdout)
|
|
218
|
-
quiet: Suppress output if True
|
|
219
|
-
"""
|
|
220
|
-
if quiet:
|
|
221
|
-
return
|
|
222
|
-
|
|
223
|
-
# Generate report
|
|
224
|
-
report = validator.create_report(result, format=format)
|
|
225
|
-
|
|
226
|
-
# Output to file or stdout
|
|
227
|
-
if output_file:
|
|
228
|
-
try:
|
|
229
|
-
with open(output_file, 'w') as f:
|
|
230
|
-
f.write(report)
|
|
231
|
-
print(f"Report saved to: {output_file}", file=sys.stderr)
|
|
232
|
-
except Exception as e:
|
|
233
|
-
print(f"Error writing report: {e}", file=sys.stderr)
|
|
234
|
-
sys.exit(1)
|
|
235
|
-
else:
|
|
236
|
-
print(report)
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
def main(argv: Optional[list] = None) -> int:
|
|
240
|
-
"""Main CLI entry point
|
|
241
|
-
|
|
242
|
-
Args:
|
|
243
|
-
argv: Command-line arguments (default: sys.argv[1:])
|
|
244
|
-
|
|
245
|
-
Returns:
|
|
246
|
-
Exit code (0 for success, 1 for failure)
|
|
247
|
-
"""
|
|
248
|
-
parser = create_parser()
|
|
249
|
-
args = parser.parse_args(argv)
|
|
250
|
-
|
|
251
|
-
# Validate path
|
|
252
|
-
path = validate_path(args.path)
|
|
253
|
-
if path is None:
|
|
254
|
-
return 1
|
|
255
|
-
|
|
256
|
-
# Create configuration from args
|
|
257
|
-
config = create_config_from_args(args)
|
|
258
|
-
|
|
259
|
-
# Run validation
|
|
260
|
-
try:
|
|
261
|
-
result = run_validation(path, config)
|
|
262
|
-
except Exception as e:
|
|
263
|
-
print(f"Validation error: {e}", file=sys.stderr)
|
|
264
|
-
return 1
|
|
265
|
-
|
|
266
|
-
# Create validator for report generation
|
|
267
|
-
validator = CentralValidator(config=config)
|
|
268
|
-
|
|
269
|
-
# Output report
|
|
270
|
-
output_report(
|
|
271
|
-
result=result,
|
|
272
|
-
validator=validator,
|
|
273
|
-
format=args.format,
|
|
274
|
-
output_file=args.output,
|
|
275
|
-
quiet=args.quiet
|
|
276
|
-
)
|
|
277
|
-
|
|
278
|
-
# Return exit code
|
|
279
|
-
return 0 if result.is_valid else 1
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
if __name__ == "__main__":
|
|
283
|
-
sys.exit(main())
|