Stack Compliance Review
Audit code for @outfitter/* pattern compliance.
Quick Audit
# Critical issues
rg "throw new|catch \(" --type ts -c
# Console usage
rg "console\.(log|error|warn)" --type ts -c
# Handler patterns
rg "Handler<" --type ts -A 2
Checklist
Result Types
Anti-patterns:
// BAD: Throwing
if (!user) throw new Error("Not found");
// GOOD: Result.err
if (!user) return Result.err(NotFoundError.create("user", id));
// BAD: try/catch for control flow
try { await handler(input, ctx); } catch (e) { ... }
// GOOD: Result checking
const result = await handler(input, ctx);
if (result.isErr()) { ... }
Error Taxonomy
| Category |
Use For |
validation |
Invalid input, schema failures |
not_found |
Resource doesn't exist |
conflict |
Already exists, version mismatch |
permission |
Forbidden action |
internal |
Unexpected errors, bugs |
Logging
Anti-patterns:
// BAD
console.log("User " + user.name);
logger.info("Config: " + JSON.stringify(config));
// GOOD
ctx.logger.info("Processing", { userId: user.id });
ctx.logger.debug("Config loaded", { config }); // redaction enabled
Path Safety
Anti-patterns:
// BAD
const configPath = path.join(os.homedir(), ".myapp", "config.json");
const userFile = path.join(baseDir, userInput); // traversal risk!
// GOOD
const configDir = getConfigDir("myapp");
const result = securePath(userInput, workspaceRoot);
await atomicWriteJson(configPath, data);
Context Propagation
Validation
Output
Audit Commands
# Find thrown exceptions
rg "throw new" --type ts
# Find console usage
rg "console\.(log|error|warn)" --type ts
# Find hardcoded paths
rg "(homedir|~\/\.)" --type ts
# Find custom errors
rg "class \w+Error extends Error" --type ts
# Find handlers without context
rg "Handler<.*> = async \(input\)" --type ts
Severity Levels
| Level |
Examples |
| Critical |
Thrown exceptions, unvalidated paths, missing error handling |
| High |
Console logging, hardcoded paths, missing context |
| Medium |
Missing type annotations, non-atomic writes |
| Low |
Style issues, missing documentation |
Report Format
## Stack Compliance: [file/module]
**Status**: PASS | WARNINGS | FAIL
**Issues**: X critical, Y high, Z medium
### Critical
1. [file:line] Issue description
### High
1. [file:line] Issue description
### Recommendations
- Recommendation with fix
Related Skills
stack:patterns — Correct patterns reference
stack:migration — Converting non-compliant code
stack:debug — Troubleshooting issues
1---2name: review3description: Audits code for Outfitter Dev Kit compliance including Result types, error handling, logging patterns, and path safety. Use for pre-commit reviews, code quality checks, migration validation, or when "audit", "check compliance", "review stack", or "stack patterns" are mentioned.4---56# Stack Compliance Review78Audit code for @outfitter/\* pattern compliance.910## Quick Audit1112```bash13# Critical issues14rg "throw new|catch \(" --type ts -c1516# Console usage17rg "console\.(log|error|warn)" --type ts -c1819# Handler patterns20rg "Handler<" --type ts -A 221```2223## Checklist2425### Result Types2627- [ ] Handlers return `Result<T, E>`, not thrown exceptions28- [ ] Errors use taxonomy classes (`ValidationError`, `NotFoundError`, etc.)29- [ ] Result checks use `isOk()` / `isErr()`, not try/catch30- [ ] Combined results use `combine2`, `combine3`, etc.3132**Anti-patterns:**3334```typescript35// BAD: Throwing36if (!user) throw new Error("Not found");3738// GOOD: Result.err39if (!user) return Result.err(NotFoundError.create("user", id));4041// BAD: try/catch for control flow42try { await handler(input, ctx); } catch (e) { ... }4344// GOOD: Result checking45const result = await handler(input, ctx);46if (result.isErr()) { ... }47```4849### Error Taxonomy5051- [ ] Errors from `@outfitter/contracts`52- [ ] `category` matches use case53- [ ] `_tag` used for pattern matching5455| Category | Use For |56| ------------ | -------------------------------- |57| `validation` | Invalid input, schema failures |58| `not_found` | Resource doesn't exist |59| `conflict` | Already exists, version mismatch |60| `permission` | Forbidden action |61| `internal` | Unexpected errors, bugs |6263### Logging6465- [ ] Uses `ctx.logger`, not `console.log`66- [ ] Metadata is object, not string concatenation67- [ ] Sensitive fields redacted6869**Anti-patterns:**7071```typescript72// BAD73console.log("User " + user.name);74logger.info("Config: " + JSON.stringify(config));7576// GOOD77ctx.logger.info("Processing", { userId: user.id });78ctx.logger.debug("Config loaded", { config }); // redaction enabled79```8081### Path Safety8283- [ ] User paths validated with `securePath()`84- [ ] No hardcoded `~/.` paths85- [ ] XDG paths via `@outfitter/config`86- [ ] Atomic writes for file modifications8788**Anti-patterns:**8990```typescript91// BAD92const configPath = path.join(os.homedir(), ".myapp", "config.json");93const userFile = path.join(baseDir, userInput); // traversal risk!9495// GOOD96const configDir = getConfigDir("myapp");97const result = securePath(userInput, workspaceRoot);98await atomicWriteJson(configPath, data);99```100101### Context Propagation102103- [ ] `createContext()` at entry points104- [ ] Context passed through handler chain105- [ ] `requestId` used for tracing106107### Validation108109- [ ] Uses `createValidator()` with Zod110- [ ] Validation at handler entry111- [ ] Validation errors returned, not thrown112113### Output114115- [ ] CLI uses `await output()` with mode detection116- [ ] `exitWithError()` for error exits117- [ ] Exit codes from error categories118119## Audit Commands120121```bash122# Find thrown exceptions123rg "throw new" --type ts124125# Find console usage126rg "console\.(log|error|warn)" --type ts127128# Find hardcoded paths129rg "(homedir|~\/\.)" --type ts130131# Find custom errors132rg "class \w+Error extends Error" --type ts133134# Find handlers without context135rg "Handler<.*> = async \(input\)" --type ts136```137138## Severity Levels139140| Level | Examples |141| ------------ | ------------------------------------------------------------ |142| **Critical** | Thrown exceptions, unvalidated paths, missing error handling |143| **High** | Console logging, hardcoded paths, missing context |144| **Medium** | Missing type annotations, non-atomic writes |145| **Low** | Style issues, missing documentation |146147## Report Format148149```markdown150## Stack Compliance: [file/module]151152**Status**: PASS | WARNINGS | FAIL153**Issues**: X critical, Y high, Z medium154155### Critical1561571. [file:line] Issue description158159### High1601611. [file:line] Issue description162163### Recommendations164165- Recommendation with fix166```167168## Related Skills169170- `stack:patterns` — Correct patterns reference171- `stack:migration` — Converting non-compliant code172- `stack:debug` — Troubleshooting issues