OpenWriterControle/scripts/registry/validate-component.sh
Darren Hinde 013682c499
fix: resolve installer failures and add comprehensive validation (#189)
* fix: ContextScout falls back to global core/ when local core/ missing

Users who install OAC globally have core standards at
~/.config/opencode/context/core/ but no local core/ directory.
ContextScout now does a one-time check on startup: if local
core/navigation.md doesn't exist, it checks the global path
from paths.json. This resolves the ENOENT errors when agents
try to read core/standards/ files that only exist globally.

- paths.json: enabled global path (~/.config/opencode/context)
- contextscout.md: added global_fallback rule with 2-glob cap
- Fallback is ONLY for core/ files, never project-intelligence

* docs: add context resolution explanation to README

Explains how ContextScout resolves context files: local-first,
global fallback only for core/ files, project-intelligence always
local. Includes flow diagram, key rules, and common setup table.

* fix: resolve installer failures and add comprehensive validation

## Summary
Fixes critical installer failures where ContextScout and other components couldn't find their configuration files after installation. Adds comprehensive validation system to prevent future issues.

## Problems Fixed

### 1. Missing Critical Files (13 dead registry references)
Files were referenced in registry but didn't exist on disk:
- workflows-delegation (split into 3 files)
- design-iteration (split into 8 files)
- animation-patterns (split into 6 files)
- adding-agent (split into 2 files)
- adding-skill (split into 3 files)
- navigation-design (split into 2 files)
- external-libraries (split into 3 files)
- claude-code-docs/* (directory removed)

### 2. Missing Infrastructure Files
ContextScout failed after installation because 2 critical files weren't in registry:
- paths.json - Context root configuration
- navigation.md - Root navigation for discovery

### 3. Profile Inconsistencies
Profiles referenced components that don't exist:
- context:adding-skill → context:adding-skill-basics
- context:animation-patterns → animation-basics/components/advanced
- context:design-assets (removed - doesn't exist)
- context:to-be-consumed/* (removed - directory doesn't exist)
- skill:context-manager → subagent:context-manager

## Changes Made

### Registry (registry.json)
- Removed 13 dead references
- Added 27 new split-file entries
- Added 2 critical infrastructure entries
- Fixed all 5 profile configurations
- Updated ContextScout dependencies
- Updated agent-metadata.json dependencies

### New Validation Scripts
- scripts/registry/check-dependencies.ts - Comprehensive dependency checker
- scripts/tests/test-installer-files.sh - Installer simulation test
- scripts/registry/fix-registry.py - Automated registry fixer
- scripts/hooks/pre-commit - Git pre-commit hook

### Documentation
- docs/maintenance/REGISTRY_FIXES_SUMMARY.md
- docs/maintenance/CONTEXTSCOUT_FIX.md
- docs/maintenance/REGISTRY_VALIDATION.md

## Validation Results

Before:
- 13 missing files in registry
- 78 orphaned files on disk
- 3 missing dependencies
- Installer would fail

After:
- 244 total paths, 0 missing
- 262 dependency checks, 0 failures
- 0 orphaned dependencies
- All profiles consistent
- Installer works correctly

## Testing

```bash
# Registry validation
bun run scripts/registry/validate-registry.ts
# ✓ All 244 paths valid

# Dependency checking
bun run scripts/registry/check-dependencies.ts
# ✓ All 262 checks passed

# Installer test
./scripts/tests/test-installer-files.sh --local --profile=essential
# ✓ All files accessible
```

## Usage

### Run validation before commits:
```bash
bun run scripts/registry/check-dependencies.ts
```

### Install pre-commit hook:
```bash
cp scripts/hooks/pre-commit .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
```

### Test installer:
```bash
./scripts/tests/test-installer-files.sh --local --profile=essential
```

## Impact

This fix ensures:
- ✓ Installer downloads all required files
- ✓ ContextScout works immediately after install
- ✓ No broken dependencies
- ✓ No missing profile components
- ✓ Future issues caught by validation

## Breaking Changes

None - all changes are additive or fix broken references.

## Related

- Fixes: ContextScout failing after installation
- Prevents: Missing file errors during install
- Adds: Comprehensive validation system

* fix: resolve shellcheck warnings in test scripts

- Remove unused REPO_URL variable from test-installer-files.sh
- Add shellcheck disable comments for cleanup functions used via trap
- Fixes CI failures in ShellCheck Analysis workflow

* fix: resolve shellcheck errors across all scripts

Fixed arithmetic expansion issues and code quality warnings:
- Changed ((var++)) to POSIX-compliant 1 syntax
- Fixed unquoted variables and grep pipe issues (SC2002, SC2143)
- Added shellcheck disable comments for intentional patterns
- Fixed variable initialization and return statement placement

Scripts fixed:
- scripts/tests/*.sh (5 files)
- scripts/registry/*.sh (4 files)
- scripts/validation/*.sh (2 files)
- scripts/*.sh (2 files)
- evals/framework/scripts/*.sh (2 files)

All scripts now pass shellcheck --severity=warning

* chore: trigger CI shellcheck validation
2026-02-06 17:07:42 +00:00

199 lines
5.9 KiB
Bash
Executable file
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
#############################################################################
# Component Validation Script
# Validates component structure and metadata for PRs
#############################################################################
set -e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
ERRORS=0
WARNINGS=0
print_success() { echo -e "${GREEN}✓${NC} $1"; }
print_error() { echo -e "${RED}✗${NC} $1"; ERRORS=$((ERRORS + 1)); }
print_warning() { echo -e "${YELLOW}⚠${NC} $1"; WARNINGS=$((WARNINGS + 1)); }
print_info() { echo -e "${BLUE}ℹ${NC} $1"; }
validate_markdown_frontmatter() {
local file=$1
print_info "Validating $file"
# Check if file has frontmatter
if ! head -n 1 "$file" | grep -q "^---$"; then
print_warning "Missing frontmatter in $file"
return
fi
# Extract frontmatter
local frontmatter
frontmatter=$(awk '/^---$/{if(++n==2)exit;next}n==1' "$file")
# Check for description
if ! echo "$frontmatter" | grep -q "^description:"; then
print_warning "Missing 'description' in frontmatter of $file"
else
print_success "Has description"
fi
# For agents, check for mode
if [[ "$file" == *"/agent/"* ]] && [[ "$file" != *"/subagents/"* ]]; then
if ! echo "$frontmatter" | grep -q "^mode:"; then
print_warning "Missing 'mode' in agent frontmatter of $file"
fi
fi
}
validate_typescript_file() {
local file=$1
print_info "Validating $file"
# Check for basic TypeScript syntax (very basic check)
if ! grep -q "export" "$file"; then
print_warning "No exports found in $file"
else
print_success "Has exports"
fi
# Check for comments/documentation
if ! grep -q "^\s*\*" "$file"; then
print_warning "No JSDoc comments found in $file"
else
print_success "Has documentation"
fi
}
validate_directory_structure() {
print_info "Validating directory structure"
local required_dirs=(
".opencode"
".opencode/agent"
".opencode/command"
".opencode/tool"
)
for dir in "${required_dirs[@]}"; do
if [ ! -d "$dir" ]; then
print_error "Missing required directory: $dir"
else
print_success "Directory exists: $dir"
fi
done
# Check for category subdirectories (optional but recommended)
local category_dirs=(
".opencode/agent/core"
".opencode/agent/development"
".opencode/agent/content"
".opencode/agent/data"
".opencode/agent/learning"
".opencode/agent/product"
)
local found_categories=0
for dir in "${category_dirs[@]}"; do
if [ -d "$dir" ]; then
found_categories=$((found_categories + 1))
fi
done
if [ $found_categories -gt 0 ]; then
print_success "Found $found_categories category subdirectories"
else
print_warning "No category subdirectories found (optional)"
fi
}
validate_registry() {
print_info "Validating registry.json"
if [ ! -f "registry.json" ]; then
print_error "registry.json not found"
return
fi
# Check if valid JSON
if ! jq empty registry.json 2>/dev/null; then
print_error "registry.json is not valid JSON"
return
fi
print_success "registry.json is valid JSON"
# Check required fields
local required_fields=("version" "repository" "components" "profiles" "metadata")
for field in "${required_fields[@]}"; do
if ! jq -e ".$field" registry.json > /dev/null 2>&1; then
print_error "Missing required field in registry.json: $field"
else
print_success "Has field: $field"
fi
done
}
main() {
echo "╔════════════════════════════════════════════════════════════════╗"
echo "║ Component Validation ║"
echo "╚════════════════════════════════════════════════════════════════╝"
echo ""
# Validate directory structure
validate_directory_structure
echo ""
# Validate registry
validate_registry
echo ""
# Validate all markdown files (excluding symlinks)
echo "Validating markdown files..."
while IFS= read -r -d '' file; do
# Skip symlinks
if [ -L "$file" ]; then
continue
fi
validate_markdown_frontmatter "$file"
done < <(find .opencode -name "*.md" -type f -print0 2>/dev/null)
echo ""
# Validate TypeScript files
echo "Validating TypeScript files..."
while IFS= read -r -d '' file; do
validate_typescript_file "$file"
done < <(find .opencode -name "*.ts" -type f -not -path "*/node_modules/*" -print0 2>/dev/null)
echo ""
# Summary
echo "════════════════════════════════════════════════════════════════"
echo "Validation Summary:"
echo " Errors: $ERRORS"
echo " Warnings: $WARNINGS"
echo "════════════════════════════════════════════════════════════════"
if [ $ERRORS -gt 0 ]; then
echo ""
print_error "Validation failed with $ERRORS error(s)"
exit 1
elif [ $WARNINGS -gt 0 ]; then
echo ""
print_warning "Validation passed with $WARNINGS warning(s)"
exit 0
else
echo ""
print_success "All validations passed!"
exit 0
fi
}
main "$@"