⛰️ LifeOS — The AI-powered Life Operating System that helps you hill climb to wherever you're going.
docs: Update documentation with Observability skill and add validation
Daniel Miessler1e7b717a5b0e
diff --git a/.claude/hooks/pre-commit-with-docs.template b/.claude/hooks/pre-commit-with-docs.templateindex fb95a6da..499fce99 100755--- a/.claude/hooks/pre-commit-with-docs.template+++ b/.claude/hooks/pre-commit-with-docs.template@@ -2,28 +2,50 @@## Pre-commit hook for PAI repository#-# This hook performs TWO critical functions:-# 1. Security scanning - Prevents sensitive content from being committed+# This hook performs THREE critical functions:+# 1. Documentation validation - Checks for broken links and missing files# 2. Documentation updates - Automatically updates docs based on changes+# 3. Security scanning - Prevents sensitive content from being committed## INSTALLATION:-# cp hooks/pre-commit-with-docs.template .git/hooks/pre-commit+# cp .claude/hooks/pre-commit-with-docs.template .git/hooks/pre-commit# chmod +x .git/hooks/pre-commit#-# Or use: bun run setup.sh+# Or use: bun run .claude/setup.sh#+# Get the root of the git repository+REPO_ROOT="$(git rev-parse --show-toplevel)"+cd "$REPO_ROOT" || exit 1++# ============================================================================+# DOCUMENTATION VALIDATION PHASE+# ============================================================================+# Validates all markdown links point to existing files+# This BLOCKS the commit if broken links are found+# ============================================================================++echo -e "\033[1;36m📚 Validating documentation...\033[0m"++if [ -f ".claude/hooks/validate-docs.ts" ]; then+ if ! bun run .claude/hooks/validate-docs.ts; then+ echo -e "\033[1;31m❌ Documentation validation failed!\033[0m"+ echo -e "\033[1;31m Fix broken links before committing.\033[0m"+ exit 1+ fi+else+ echo -e "\033[1;33m⚠️ validate-docs.ts not found, skipping validation\033[0m"+fi+# ============================================================================# DOCUMENTATION UPDATE PHASE# ============================================================================# Automatically updates documentation based on what files were changed+# This is non-blocking - issues are reported but don't fail the commit# ============================================================================-# Check if the documentation updater script exists-if [ -f "hooks/update-documentation.ts" ]; then- # Run the documentation updater- # Note: This runs but doesn't block the commit if it fails- if ! bun run hooks/update-documentation.ts; then+if [ -f ".claude/hooks/update-documentation.ts" ]; then+ if ! bun run .claude/hooks/update-documentation.ts; thenecho -e "\033[1;33m⚠️ Documentation update encountered an issue (non-blocking)\033[0m"echo -e "\033[1;33m The commit will proceed, but you may want to review documentation manually\033[0m"fi@@ -32,8 +54,31 @@ fi# ============================================================================# SECURITY SCANNING PHASE# ============================================================================-# Add your existing security scanning logic here, or integrate with the-# existing .git/hooks/pre-commit security scanner+# Prevent sensitive content from being committed# ============================================================================+echo -e "\033[1;36m🔒 Scanning for sensitive content...\033[0m"++# Check for common sensitive patterns in staged files+SENSITIVE_PATTERNS=(+ "ANTHROPIC_API_KEY="+ "OPENAI_API_KEY="+ "sk-ant-"+ "sk-proj-"+ "password.*=.*['\"]"+ "@danielmiessler.com"+ "@unsupervised-learning.com"+)++STAGED_FILES=$(git diff --cached --name-only --diff-filter=d)++for pattern in "${SENSITIVE_PATTERNS[@]}"; do+ if echo "$STAGED_FILES" | xargs grep -l -E "$pattern" 2>/dev/null; then+ echo -e "\033[1;31m❌ Found sensitive pattern: $pattern\033[0m"+ echo -e "\033[1;31m Remove sensitive content before committing.\033[0m"+ exit 1+ fi+done++echo -e "\033[1;32m✅ Pre-commit checks passed\033[0m"exit 0diff --git a/.claude/hooks/validate-docs.ts b/.claude/hooks/validate-docs.tsnew file mode 100644index 00000000..0373e4c5--- /dev/null+++ b/.claude/hooks/validate-docs.ts@@ -0,0 +1,205 @@+#!/usr/bin/env bun+/**+ * Documentation Link Validator+ *+ * Validates that all internal markdown links point to existing files.+ * Runs as part of the pre-commit hook to prevent broken documentation.+ *+ * Usage:+ * bun run .claude/hooks/validate-docs.ts+ *+ * Exit codes:+ * 0 - All links valid+ * 1 - Broken links found+ */++import { readFileSync, existsSync } from 'fs';+import { join, dirname, resolve } from 'path';+import { globSync } from 'glob';++// ANSI color codes+const colors = {+ reset: '\x1b[0m',+ red: '\x1b[31m',+ green: '\x1b[32m',+ yellow: '\x1b[33m',+ cyan: '\x1b[36m',+};++interface BrokenLink {+ file: string;+ link: string;+ target: string;+ line: number;+}++/**+ * Extract markdown links from content+ */+function extractLinks(content: string): { link: string; line: number }[] {+ const links: { link: string; line: number }[] = [];+ const lines = content.split('\n');++ // Match [text](path) pattern for internal links+ const linkPattern = /\[([^\]]*)\]\(([^)]+)\)/g;++ lines.forEach((line, index) => {+ let match;+ while ((match = linkPattern.exec(line)) !== null) {+ const linkPath = match[2];++ // Only check internal links (not URLs)+ if (!linkPath.startsWith('http://') &&+ !linkPath.startsWith('https://') &&+ !linkPath.startsWith('mailto:') &&+ !linkPath.startsWith('#')) {++ // Remove anchor portion for file existence check+ const pathWithoutAnchor = linkPath.split('#')[0];++ links.push({+ link: linkPath,+ line: index + 1,+ });+ }+ }+ });++ return links;+}++/**+ * Resolve a link path relative to the file containing it+ */+function resolveLink(fromFile: string, linkPath: string, baseDir: string): string {+ // Remove anchor+ const pathWithoutAnchor = linkPath.split('#')[0];++ if (!pathWithoutAnchor) {+ // Link is just an anchor (e.g., #section) - always valid+ return '';+ }++ // Handle absolute paths (relative to repo root)+ if (pathWithoutAnchor.startsWith('/')) {+ return join(baseDir, pathWithoutAnchor);+ }++ // Handle relative paths+ const fileDir = dirname(fromFile);+ return resolve(fileDir, pathWithoutAnchor);+}++/**+ * Validate all markdown files in the repository+ */+function validateDocs(baseDir: string): BrokenLink[] {+ const brokenLinks: BrokenLink[] = [];++ // Find all markdown files+ const mdFiles = globSync('**/*.md', {+ cwd: baseDir,+ ignore: ['**/node_modules/**', '**/fabric-repo/**'],+ });++ console.log(`${colors.cyan}📚 Validating ${mdFiles.length} markdown files...${colors.reset}`);++ for (const file of mdFiles) {+ const fullPath = join(baseDir, file);+ const content = readFileSync(fullPath, 'utf-8');+ const links = extractLinks(content);++ for (const { link, line } of links) {+ const target = resolveLink(fullPath, link, baseDir);++ // Skip anchor-only links+ if (!target) continue;++ // Check if target exists+ if (!existsSync(target)) {+ brokenLinks.push({+ file,+ link,+ target,+ line,+ });+ }+ }+ }++ return brokenLinks;+}++/**+ * Check for common documentation issues+ */+function checkDocIssues(baseDir: string): string[] {+ const issues: string[] = [];++ // Check if SKILL.md exists for each skill+ const skillDirs = globSync('.claude/skills/*/', {+ cwd: baseDir,+ });++ for (const skillDir of skillDirs) {+ const skillMd = join(baseDir, skillDir, 'SKILL.md');+ if (!existsSync(skillMd)) {+ issues.push(`Missing SKILL.md in ${skillDir}`);+ }+ }++ // Check if README exists+ if (!existsSync(join(baseDir, 'README.md'))) {+ issues.push('Missing README.md in repository root');+ }++ return issues;+}++/**+ * Main execution+ */+function main(): number {+ const baseDir = process.cwd();++ console.log(`\n${colors.cyan}🔍 PAI Documentation Validator${colors.reset}`);+ console.log(`${colors.cyan} Base directory: ${baseDir}${colors.reset}\n`);++ // Validate links+ const brokenLinks = validateDocs(baseDir);++ // Check for other issues+ const docIssues = checkDocIssues(baseDir);++ // Report results+ let hasErrors = false;++ if (brokenLinks.length > 0) {+ hasErrors = true;+ console.log(`\n${colors.red}❌ Found ${brokenLinks.length} broken link(s):${colors.reset}\n`);++ for (const { file, link, line } of brokenLinks) {+ console.log(` ${colors.yellow}${file}:${line}${colors.reset}`);+ console.log(` → ${colors.red}${link}${colors.reset} (not found)\n`);+ }+ }++ if (docIssues.length > 0) {+ hasErrors = true;+ console.log(`\n${colors.yellow}⚠️ Found ${docIssues.length} documentation issue(s):${colors.reset}\n`);++ for (const issue of docIssues) {+ console.log(` - ${issue}`);+ }+ }++ if (!hasErrors) {+ console.log(`${colors.green}✅ All documentation links are valid${colors.reset}\n`);+ return 0;+ }++ console.log(`\n${colors.red}Documentation validation failed. Please fix the issues above.${colors.reset}\n`);+ return 1;+}++process.exit(main());diff --git a/README.md b/README.mdindex 09eede6f..ec580f5f 100644--- a/README.md+++ b/README.md@@ -166,6 +166,7 @@ claudeExplore example skills in `.claude/skills/`:+- **`observability/`** - Real-time agent monitoring dashboard with WebSocket streaming, live pulse charts, and event timelines- **`brightdata/`** - Four-tier progressive web scraping with automatic fallback (WebFetch → cURL → Playwright → Bright Data MCP)- **`fabric/`** - Integration with Fabric pattern system (242+ AI patterns)- **`research/`** - Multi-source research workflows@@ -234,6 +235,14 @@ See `SECURITY.md` for complete security protocols.### Recent Updates+**2025-12-01** - Observability Dashboard Skill+- Added complete agent monitoring dashboard at `.claude/skills/observability/`+- Real-time WebSocket streaming of agent activity+- Live pulse charts, event timelines, and agent swim lanes+- Multiple theme support (Tokyo Night, Nord, etc.)+- Security obfuscation for sensitive data in displays+- Run with: `~/.claude/skills/observability/manage.sh start`+**2025-11-25** - Path Standardization (Issue #122)- Replaced all hardcoded `~/.claude/` paths with `${PAI_DIR}/` for location-agnostic installation- Updated 50+ files across skills, hooks, and documentation