Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ ecosystem.config.cjs
/config.yml
coverage/

/data/lab.dev-backup-20260127.db
239 changes: 239 additions & 0 deletions QUICK_REFERENCE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
# 🦊 HPL CLI - Quick Reference Checklist

> **TL;DR** of the full STYLE_GUIDE.md - print this and keep it handy!

---

## Before You Start πŸš€

```bash
β–‘ npm install
β–‘ npm run build
β–‘ npm test
β–‘ Read STYLE_GUIDE.md (at least the Import Rules section!)
```

---

## The #1 Rule ⚠️

**ALL relative imports MUST end in `.js`** (even for `.ts` files)

```typescript
βœ… import { foo } from "./bar.js"
❌ import { foo } from "./bar"
```

---

## Before Every Commit βœ…

```bash
β–‘ npm run build # Succeeds?
β–‘ npm test # Passes?
β–‘ Check .js extensions # All imports have them?
β–‘ Commit message # Emoji prefix + format?
```

---

## Commit Format πŸ“

```
<emoji> <scope>: <subject>
```

Common prefixes:
- `βš™οΈ feat:` - New features
- `πŸ› fix:` - Bug fixes
- `πŸ“š docs:` - Documentation
- `πŸ”§ refactor:` - Code restructuring
- `βœ… test:` - Tests
- `πŸŒ‰ bridge:` - Relay system

---

## Quick Commands πŸ’»

```bash
# Development
npm run dev <command> # Run with tsx (no build)
npm run build # Compile TypeScript
npm start <command> # Run built version

# Testing
npm test # All tests
npm test:watch # Watch mode

# Local Install
npm install -g . # Install globally
hpl version # Test it works

# Emergency Reset
rm -rf dist/ node_modules/
npm install && npm run build
```

---

## Debugging Imports πŸ”

```bash
# Find imports missing .js
grep -r "from ['\"]\.\.*/[^'\"]*[^s]['\"]" src/ --include="*.ts" | grep -v "\.js['\"]"

# Or just look at the error:
# "Cannot find module '.../XXX' imported from YYY.js"
# ^^^ ^^^
# Missing .js Check this source file
```

---

## Command Structure Pattern πŸ“‹

```typescript
import { Command } from "commander";
import { writeHuman, writeJson } from "../io.js";
import { EXIT } from "../contract/exitCodes.js";
import { getAlphaIntent } from "../contract/intents.js";
import { ok } from "../contract/envelope.js";

type GlobalOpts = { json?: boolean };

export function myCommand(): Command {
return new Command("mycommand")
.description("...")
.action((...args: any[]) => {
const cmd = args[args.length - 1] as Command;
const opts = (cmd.parent?.opts?.() ?? {}) as GlobalOpts;

const result = runMyCommand();

if (opts.json) writeJson(result);
else writeHuman("...");

process.exitCode = EXIT.OK;
});
}

export function runMyCommand() {
const intent = getAlphaIntent("my_intent");
return ok("mycommand", intent, { /* data */ });
}
```

---

## Common Gotchas πŸ›

| Problem | Cause | Fix |
|---------|-------|-----|
| `ERR_MODULE_NOT_FOUND` | Missing `.js` | Add `.js` to import |
| Type passes, runtime fails | No validation | Use Zod schemas |
| JSON has extra output | Logs to stdout | Use `console.error()` |
| Wrong exit code | Not set | Set `process.exitCode` |
| Old version runs | npm cache | `npm uninstall -g && npm cache clean --force` |

---

## Contract Rules πŸ“œ

**Breaking Changes** (DON'T DO in v0.x):
- ❌ Change envelope structure
- ❌ Remove JSON fields
- ❌ Change exit codes
- ❌ Rename commands
- ❌ Change intent IDs

**Safe Changes**:
- βœ… Add new commands
- βœ… Add new JSON fields
- βœ… Add new intents
- βœ… Improve error messages
- βœ… Internal refactoring

---

## VS Code Setup πŸ› οΈ

Add to `.vscode/settings.json`:

```json
{
"typescript.preferences.importModuleSpecifierEnding": "js",
"typescript.preferences.importModuleSpecifier": "relative"
}
```

This auto-adds `.js` to imports!

---

## Files to Know πŸ“

```
src/
β”œβ”€β”€ contract/ # Output contracts - STABLE
β”‚ β”œβ”€β”€ schema.ts # Zod schemas
β”‚ β”œβ”€β”€ envelope.ts # Success/error wrappers
β”‚ β”œβ”€β”€ intents.ts # Intent registry
β”‚ └── exitCodes.ts # Exit code constants
β”œβ”€β”€ commands/ # CLI commands
β”‚ └── notes/ # Domain commands
β”œβ”€β”€ lib/ # Shared utilities
└── io.ts # stdout/stderr helpers

bin/
└── hpl.ts # Entrypoint
```

---

## Need More Info? πŸ“–

See **STYLE_GUIDE.md** for:
- Detailed explanations
- More code examples
- Architecture decisions
- Full gotcha list
- Contract details

---

## Emergency Contact πŸ†˜

**Totally Stuck?**

1. Check error message carefully (it tells you which file!)
2. Look at similar existing code
3. Run `npm test` to see examples
4. Full reset: `rm -rf dist/ node_modules/ && npm install && npm run build`
5. Ask for help (with error message + what you tried)

---

## Status Checks βœ“

**Healthy Repo**:
```bash
$ npm run build
βœ“ Compiled successfully

$ npm test
βœ“ All tests passing

$ npm start version
βœ“ Shows version

$ hpl version
βœ“ Shows version (global install works)
```

---

**Print this page and tape it to your monitor!** 🦊

---

*Quick ref for STYLE_GUIDE.md - Last updated: 2025-01-27*
Loading