# latent-systemic-debt

## AUDIT (2026-02-04)

### Issues Found

| Category | Count | Priority | Action |
|----------|-------|----------|--------|
| print() statements | 142 | LOW | **Intentional** - CLI tools need user output |
| Hardcoded localhost | 2 | HIGH | Fix - breaks in production |
| Broad exceptions | 8 | MEDIUM | Acceptable for CLI error handling |

### Detailed Findings

**HIGH - Hardcoded URLs (must fix):**
1. `dashboard/app/page.tsx:13` - `http://localhost:3000/data.json` - NO env fallback
2. `ingest-reddit/macros/reddit-app-setup/main.py:25` - `http://localhost:8080` - OAuth redirect

**MEDIUM - Broad exceptions (acceptable):**
- 8 instances of `except Exception as e:` - all log the error, acceptable for CLI tools

**LOW - print() statements (intentional):**
- 142 instances across CLI tools
- Decision: These are user-facing CLI scripts, not libraries
- print() is the correct pattern for CLI output
- No remediation needed

## FIX

### 2026-02-04 - Hardcoded URLs

- [x] `dashboard/app/page.tsx:13` - Added `LATENT_API_URL` env var with localhost fallback
- [x] `ingest-reddit/macros/reddit-app-setup/main.py:25` - Added `REDDIT_REDIRECT_URI` env var

### Verification

```bash
$ grep -n "http://localhost" latent/**/*.py latent/**/*.tsx | grep -v "getenv\|process.env"
# Returns 0 results - PASS
```

## ENFORCE

### 2026-02-04 - CLAUDE.md Rules

Added `## Latent Signal (latent/)` section to CLAUDE.md:
- Documented that `print()` is allowed for CLI tools
- Documented that `except Exception` is acceptable for CLI error handling
- **Required:** Environment variables for URLs (no hardcoded localhost)
- **Required:** New ingestors use `StemeDBClient` pattern

## COMPLETE

### Summary

| Issue | Before | After | Action |
|-------|--------|-------|--------|
| Hardcoded localhost URLs | 2 | 0 | **FIXED** - Added env fallbacks |
| print() statements | 142 | 142 | **INTENTIONAL** - CLI tools |
| Broad exceptions | 8 | 8 | **ACCEPTABLE** - CLI error handling |

### Enforcement Added

- CLAUDE.md `## Latent Signal (latent/)` section with:
  - Explicit rules for what's allowed (print, broad exceptions)
  - Required patterns (env vars for URLs, StemeDBClient for new ingestors)

### Files Changed

1. `latent/dashboard/app/page.tsx` - Added `LATENT_API_URL` env var
2. `latent/ingest-reddit/macros/reddit-app-setup/main.py` - Added `REDDIT_REDIRECT_URI` env var
3. `CLAUDE.md` - Added latent/ section with enforcement rules
