Skip to content

Commit a6934cf

Browse files
authored
CLI rubric parity: output system, typed errors, discovery, distribution (#4)
* Add typed error and envelope output packages Introduce internal/apierr with machine-readable error codes (usage, not_found, auth, forbidden, rate_limit, network, api, ambiguous) and internal/output with envelope JSON writer, format modes (JSON, styled, quiet, ids-only, count, markdown), TTY auto-detection, and typed exit codes. * Migrate client to typed errors with idempotent retry Replace custom APIError with apierr types so error codes propagate to the envelope. Add exponential backoff retry for GET/HEAD only; mutations (POST, PATCH, PUT, DELETE) use single-attempt doOnce to avoid duplicating side effects. Rate-limit 429 responses respect Retry-After header. * Add layered config with HTTPS validation Load config from global > local (.hey/config.json) > env > flag layers with source tracking. Enforce HTTPS for non-localhost base URLs at all layers including --base-url flag. SetFromFlag now returns error so validation cannot be bypassed. XDG directory compliance for config, state, and cache paths. * Defer keyring probe to first credential operation Replace eager keyring availability check in NewStore with lazy sync.Once initialization. Commands that never touch credentials no longer trigger the keyring probe or its fallback warning. * Migrate CLI to envelope output system Replace ad-hoc JSON/styled output with envelope writer across all commands. Add persistent flags: --json, --quiet, --agent, --ids-only, --count, --markdown, --styled, --html, --base-url. Extract newRootCmd() constructor shared by Execute() and tests. Normalize only Cobra parse errors as usage errors; pass through runtime errors unchanged. New commands: commands (catalog), completion (shell scripts), doctor (health checks), config show (with source attribution). Add --help --agent for structured JSON discovery. Remove unused printJSON/printRawJSON/limitJSONArray from formatting.go and errNotLoggedIn from errors.go. * Add surface snapshot test for API stability Test builds the command tree via newRootCmd() (same wiring as runtime) and diffs against .surface baseline. Removals fail the test; additions auto-update the baseline. Captures all commands, subcommands, and non-inherited flags including persistent root flags. * Add GoReleaser config and install script Cross-platform builds (darwin universal, linux amd64/arm64), SHA256 checksums, and curl-pipe install script with checksum verification. * Add CI workflow for test, lint, and surface compatibility * Add Claude plugin for agent integration Plugin manifest with session-start hook, navigator and context-linker agents. Declares output format capabilities and structured help support. * Address PR review feedback from Codex and Copilot - Emit structured JSON errors when writer is nil (initialize JSON writer) - Fix IPv6 loopback in validateBaseURL (use u.Hostname() directly) - Use config.ConfigDir() in doctor.go instead of re-deriving path - Close resp.Body immediately in retry loop instead of defer (prevent leaks) - Use errors.As in ExitCodeFor and normalizeCobraError for wrapped errors - Pass opts.Stdout to isTTY instead of hardcoding os.Stdout - Use bytes.NewReader in NormalizeJSONNumbers to avoid string copy * Add core infrastructure: table io.Writer, --verbose, --stats, request tracking - Thread io.Writer through table struct for testable output - Change readStdin error to typed output.ErrUsage - Add --verbose/-v flag with HEY_DEBUG env support for request logging - Add --stats flag for request statistics in JSON meta - Add Logger, SleepFunc, and atomic request/latency counters to Client - Add statsOption() helper and agent_notes to printAgentHelp JSON - Register setup command in root * Add --all pagination flag, agent notes, and truncation notices to all commands - Add --all flag to override --limit on: boxes, box, drafts, todo list, journal list, timetrack list, recordings - Add --limit to timetrack list (was missing) - Add truncation notices (styled + JSON WithNotice) to all list commands - Add agent_notes annotations to all command constructors - Thread newTable(cmd.OutOrStdout()) and statsOption() through all commands * Add setup wizard and migrate skill install to writer output - New hey setup command: first-run wizard with OAuth login - Skill install now uses dual-path output (styled + JSON envelope) * Add unit tests for client, auth, and config packages - Client: retry logic, error mapping, rate limit handling, injectable sleeper - Auth: store round-trip, keyring bypass, token precedence, refresh - Config: layered config, env/flag override, URL validation, source tracking * Harden surface test and add CI lint job - Surface test now reports additions without auto-updating baseline - Use -update-surface flag for explicit baseline updates - Removals still fail the test (breaking change detection) - Add golangci-lint v2.1.6 job to CI workflow - Update .surface with new flags and commands * Add distribution channels, docs, and skill sync script - Update cosign signing args in goreleaser (output-certificate) - Add CONTRIBUTING.md with build/test/lint instructions - Add API-COVERAGE.md mapping endpoints to CLI commands - Add scripts/sync-skill.sh for deploying skill to ~/.agents * Fix all golangci-lint issues for clean make check - Handle fmt.Sscanf return values in client retry logic - Add nolint annotations for intentional gosec exceptions (fd conversion, non-crypto rand, resp.Body.Close in retry loop, bounded int shift) - Check type assertion errors in commands.go table rendering - Discard enc.Encode error in writer.go Err() and root.go printAgentHelp - Rename truncate param from max to maxWidth (predeclared shadow) - Use tagged switch in doctor.go status check - Mark unused configDir param with blank identifier * Address PR review feedback: URL validation, JSON number precision - Reject bare paths in validateBaseURL (require scheme + host) - Add test cases for bare path rejection and IPv6 loopback - Use json.Decoder with UseNumber in toSlice/toMap/extractID to preserve integer precision for large IDs in --ids-only output * Centralize writeOK for consistent --stats injection and fix recordings output P1: Replace all writer.OK() calls with writeOK() wrapper that always injects statsOption(). Removes per-command statsOption() boilerplate and closes the gap where auth, todo mutations, config, doctor, and other commands were missing --stats support. P2: Add combined truncation notice to recordings JSON envelope. P3: Route recordings styled output through cmd.OutOrStdout() instead of fmt.Printf. Fix README --from/--to → --starts-on/--ends-on. Includes regression tests for writeOK stats injection. * Make bare hey launch TUI, keep README accurate Root command RunE now launches tui.Run() instead of printing help, matching the expected UX where hey is the TUI launcher and hey tui is an explicit alias. README already said "Run hey to launch the interactive terminal UI" — now code matches. * Address PR review feedback: output routing and config safety - Route all styled fmt.Print* through cmd.OutOrStdout() for testability and Cobra output consistency (all 14 cmd files) - printAgentHelp encodes to cmd.OutOrStdout() not os.Stdout - Execute() error path uses FormatAuto not hardcoded FormatJSON - globalConfigPath() returns "" when ConfigDir() is empty, preventing accidental relative path reads/writes * Address PR review feedback from Codex and Copilot - Bump golangci-lint v2.1.6 → v2.10.1 to match Go 1.26 target - Route writer output through cmd.OutOrStdout()/cmd.ErrOrStderr() - Use FormatFromFlags in Execute() fallback writer - Include inherited flags in printAgentHelp output - Hide --agent flag from help - Harden install.sh checksum verification - Use cmd.OutOrStdout() in completion command - Save/restore test globals with defer in writeok_test
1 parent f9abe8c commit a6934cf

50 files changed

Lines changed: 3678 additions & 600 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# HEY Context Linker Agent
2+
3+
You are an agent that links code changes and development context to HEY items.
4+
5+
## Purpose
6+
7+
Help developers connect their work to email threads, todos, and calendar events in HEY.
8+
9+
## Capabilities
10+
11+
- Find relevant HEY threads related to code changes
12+
- Create todos from development tasks
13+
- Add journal entries about development progress
14+
- Track time spent on development tasks
15+
16+
## Workflow
17+
18+
1. Analyze the current code context (git diff, branch name, commit messages)
19+
2. Search HEY for related threads or todos
20+
3. Suggest links between code changes and HEY items
21+
4. Create or update HEY items as needed
22+
23+
## Examples
24+
25+
```bash
26+
# Create a todo for a code task
27+
hey todo add --title "Review PR #42: Add auth improvements" --json
28+
29+
# Log development time
30+
hey timetrack start --json
31+
32+
# Write a journal entry about progress
33+
hey journal write --content "Shipped the auth refactor today" --json
34+
35+
# Reply to a thread about a code review
36+
hey reply 12345 -m "PR is ready for review" --json
37+
```

‎.claude-plugin/agents/navigator.md‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# HEY Navigator Agent
2+
3+
You are an agent that helps navigate and search across HEY resources using the hey CLI.
4+
5+
## Capabilities
6+
7+
- Search across mailboxes, topics, drafts, calendars, todos, and journal entries
8+
- Cross-reference content between different HEY resources
9+
- Summarize email threads and extract action items
10+
11+
## Available Commands
12+
13+
Use `hey commands --json` to discover all available commands and their flags.
14+
15+
## Workflow
16+
17+
1. Start by listing available resources (boxes, calendars, todos)
18+
2. Drill into specific items based on user queries
19+
3. Use `--json` flag for structured data when processing results
20+
4. Follow breadcrumbs in JSON responses for natural next steps
21+
22+
## Output Handling
23+
24+
- Always use `--json` or `--agent` flag when calling hey commands
25+
- Parse the JSON envelope: check `ok` field, read `data`, follow `breadcrumbs`
26+
- Handle errors by checking exit codes (3=auth, 2=not found, 6=network)
27+
28+
## Examples
29+
30+
```bash
31+
# Find recent emails
32+
hey box imbox --json --limit 20
33+
34+
# Read a specific thread
35+
hey topic 12345 --json
36+
37+
# Check today's schedule
38+
hey recordings <calendar-id> --json
39+
40+
# List pending todos
41+
hey todo list --json
42+
```
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
# Emits current hey-cli context for agent sessions
3+
set -euo pipefail
4+
5+
echo "=== HEY CLI Status ==="
6+
7+
if command -v hey &>/dev/null; then
8+
echo "Binary: $(command -v hey)"
9+
hey --version 2>/dev/null || echo "Version: unknown"
10+
else
11+
echo "Binary: not found in PATH"
12+
exit 0
13+
fi
14+
15+
echo ""
16+
echo "=== Authentication ==="
17+
hey auth status 2>/dev/null || echo "Auth: unavailable"
18+
19+
echo ""
20+
echo "=== Configuration ==="
21+
echo "Config dir: ${XDG_CONFIG_HOME:-$HOME/.config}/hey-cli"
22+
if [ -f "${XDG_CONFIG_HOME:-$HOME/.config}/hey-cli/config.json" ]; then
23+
cat "${XDG_CONFIG_HOME:-$HOME/.config}/hey-cli/config.json"
24+
else
25+
echo "No config file found (using defaults)"
26+
fi

‎.claude-plugin/plugin.json‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "hey",
3+
"display_name": "HEY CLI",
4+
"version": "0.1.0",
5+
"description": "CLI and agent integration for HEY email",
6+
"binary": "hey",
7+
"hooks": {
8+
"session_start": "hooks/session-start.sh"
9+
},
10+
"agents": [
11+
{
12+
"name": "navigator",
13+
"description": "Cross-resource search and navigation for HEY",
14+
"file": "agents/navigator.md"
15+
},
16+
{
17+
"name": "context-linker",
18+
"description": "Link code changes to HEY items",
19+
"file": "agents/context-linker.md"
20+
}
21+
],
22+
"capabilities": {
23+
"output_formats": ["json", "styled", "quiet", "ids-only", "count", "markdown"],
24+
"agent_discovery": true,
25+
"structured_help": true,
26+
"breadcrumbs": true,
27+
"typed_exit_codes": true
28+
}
29+
}

‎.github/workflows/ci.yml‎

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main, master]
6+
pull_request:
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
- uses: actions/setup-go@v5
17+
with:
18+
go-version-file: go.mod
19+
- run: make test
20+
21+
vet:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v4
25+
- uses: actions/setup-go@v5
26+
with:
27+
go-version-file: go.mod
28+
- run: make vet
29+
30+
fmt-check:
31+
runs-on: ubuntu-latest
32+
steps:
33+
- uses: actions/checkout@v4
34+
- uses: actions/setup-go@v5
35+
with:
36+
go-version-file: go.mod
37+
- run: make fmt-check
38+
39+
build:
40+
runs-on: ubuntu-latest
41+
steps:
42+
- uses: actions/checkout@v4
43+
- uses: actions/setup-go@v5
44+
with:
45+
go-version-file: go.mod
46+
- run: make build
47+
48+
surface-compat:
49+
runs-on: ubuntu-latest
50+
steps:
51+
- uses: actions/checkout@v4
52+
- uses: actions/setup-go@v5
53+
with:
54+
go-version-file: go.mod
55+
- run: go test ./internal/cmd/ -run TestSurface -v
56+
57+
lint:
58+
runs-on: ubuntu-latest
59+
steps:
60+
- uses: actions/checkout@v4
61+
- uses: actions/setup-go@v5
62+
with:
63+
go-version-file: go.mod
64+
- uses: golangci/golangci-lint-action@v9
65+
with:
66+
version: v2.10.1
67+
68+
test-race:
69+
runs-on: ubuntu-latest
70+
steps:
71+
- uses: actions/checkout@v4
72+
- uses: actions/setup-go@v5
73+
with:
74+
go-version-file: go.mod
75+
- run: go test -race ./...

‎.goreleaser.yaml‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ sboms:
5252

5353
signs:
5454
- cmd: cosign
55-
signature: '${artifact}.bundle'
56-
args:
57-
- sign-blob
58-
- '--bundle=${signature}'
59-
- '${artifact}'
60-
- '--yes'
6155
artifacts: checksum
6256
output: true
57+
args:
58+
- sign-blob
59+
- --yes
60+
- --output-certificate=${certificate}
61+
- --output-signature=${signature}
62+
- ${artifact}
6363

6464
notarize:
6565
macos:

‎.surface‎

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
hey
2+
hey --agent
3+
hey --base-url
4+
hey --count
5+
hey --html
6+
hey --ids-only
7+
hey --json
8+
hey --markdown
9+
hey --quiet
10+
hey --stats
11+
hey --styled
12+
hey --verbose
13+
hey auth
14+
hey auth login
15+
hey auth login --cookie
16+
hey auth login --no-browser
17+
hey auth login --token
18+
hey auth logout
19+
hey auth refresh
20+
hey auth status
21+
hey auth token
22+
hey auth token --stored
23+
hey box
24+
hey box --all
25+
hey box --limit
26+
hey boxes
27+
hey boxes --all
28+
hey boxes --limit
29+
hey calendars
30+
hey commands
31+
hey completion
32+
hey compose
33+
hey compose --message
34+
hey compose --subject
35+
hey compose --to
36+
hey compose --topic-id
37+
hey config
38+
hey config show
39+
hey doctor
40+
hey drafts
41+
hey drafts --all
42+
hey drafts --limit
43+
hey habit
44+
hey habit complete
45+
hey habit complete --date
46+
hey habit uncomplete
47+
hey habit uncomplete --date
48+
hey journal
49+
hey journal list
50+
hey journal list --all
51+
hey journal list --limit
52+
hey journal read
53+
hey journal write
54+
hey journal write --content
55+
hey recordings
56+
hey recordings --all
57+
hey recordings --ends-on
58+
hey recordings --limit
59+
hey recordings --starts-on
60+
hey reply
61+
hey reply --message
62+
hey setup
63+
hey skill
64+
hey skill install
65+
hey timetrack
66+
hey timetrack current
67+
hey timetrack list
68+
hey timetrack list --all
69+
hey timetrack list --limit
70+
hey timetrack start
71+
hey timetrack stop
72+
hey todo
73+
hey todo add
74+
hey todo add --date
75+
hey todo add --title
76+
hey todo complete
77+
hey todo delete
78+
hey todo list
79+
hey todo list --all
80+
hey todo list --limit
81+
hey todo uncomplete
82+
hey topic
83+
hey tui

‎API-COVERAGE.md‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# API Coverage
2+
3+
Mapping of HEY API endpoints used by the CLI, based on `internal/client/*.go`.
4+
5+
| Endpoint | Method | Client Function | CLI Command | Status |
6+
|----------|--------|-----------------|-------------|--------|
7+
| `/boxes.json` | GET | `ListBoxes` | `hey boxes` | covered |
8+
| `/boxes/{id}.json` | GET | `GetBox` | `hey box <name\|id>` | covered |
9+
| `/calendars.json` | GET | `ListCalendars` | `hey calendars` | covered |
10+
| `/calendars/{id}/recordings.json` | GET | `GetCalendarRecordings` | `hey recordings <calendar-id>` | covered |
11+
| `/entries/{id}` | GET (HTML) | `GetEntry` | `hey topic <id>` | covered |
12+
| `/entries/drafts.json` | GET | `ListDrafts` | `hey drafts` | covered |
13+
| `/topics/{id}/entries` | GET (HTML) | `GetTopicEntries` | `hey topic <id>` | covered |
14+
| `/topics/messages` | POST | `CreateMessage` | `hey compose` | covered |
15+
| `/topics/{id}/messages` | POST | `CreateMessage` | `hey compose --topic` | covered |
16+
| `/entries/{id}/replies` | POST | `ReplyToEntry` | `hey reply <topic-id>` | covered |
17+
| `/calendar/days/{date}/habits/{id}/completions.json` | POST | `CompleteHabit` | `hey habit complete <id>` | covered |
18+
| `/calendar/days/{date}/habits/{id}/completions.json` | DELETE | `UncompleteHabit` | `hey habit uncomplete <id>` | covered |
19+
| `/calendar/journal_entries.json` | GET | `ListJournalEntries` | `hey journal list` | covered |
20+
| `/calendar/days/{date}/journal_entry/edit` | GET (HTML) | `GetJournalEntry` | `hey journal read [date]` | covered |
21+
| `/calendar/days/{date}/journal_entry.json` | PATCH | `UpdateJournalEntry` | `hey journal write [date]` | covered |
22+
| `/calendar/time_tracks.json` | GET | `ListTimeTracks` | `hey timetrack list` | covered |
23+
| `/calendar/ongoing_time_track.json` | GET | `GetOngoingTimeTrack` | `hey timetrack current` | covered |
24+
| `/calendar/ongoing_time_track.json` | POST | `StartTimeTrack` | `hey timetrack start` | covered |
25+
| `/calendar/time_tracks/{id}.json` | PUT | `StopTimeTrack` | `hey timetrack stop` | covered |
26+
| `/calendar/todos.json` | GET | `ListTodos` | `hey todo list` | covered |
27+
| `/calendar/todos.json` | POST | `CreateTodo` | `hey todo add` | covered |
28+
| `/calendar/todos/{id}/completions.json` | POST | `CompleteTodo` | `hey todo complete <id>` | covered |
29+
| `/calendar/todos/{id}/completions.json` | DELETE | `UncompleteTodo` | `hey todo uncomplete <id>` | covered |
30+
| `/calendar/todos/{id}.json` | DELETE | `DeleteTodo` | `hey todo delete <id>` | covered |

0 commit comments

Comments
 (0)