@brianlovin/hn-cli 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Brian Lovin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,135 @@
1
+ # hn-cli
2
+
3
+ A terminal UI for browsing Hacker News, modeled after the HN reader on my [personal website](https://brianlovin.com/hn).
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ # Install Bun if you haven't already
9
+ curl -fsSL https://bun.sh/install | bash
10
+
11
+ # Run directly with bunx
12
+ bunx @brianlovin/hn-cli
13
+
14
+ # Or install globally
15
+ bun install -g @brianlovin/hn-cli
16
+ hn-cli
17
+ ```
18
+
19
+ ### From source
20
+
21
+ ```bash
22
+ # Clone the repository
23
+ git clone https://github.com/brianlovin/hn-cli.git
24
+ cd hn-cli
25
+
26
+ # Install dependencies
27
+ bun install
28
+
29
+ # Run the app
30
+ bun run start
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ ### Navigation
36
+
37
+ | Key | Action |
38
+ | ----------- | ------------------------------------ |
39
+ | `j` / `k` | Navigate between stories |
40
+ | `⌘j` / `⌘k` | Navigate between root-level comments |
41
+ | `o` | Open story URL in browser |
42
+ | `c` | Chat with AI about the story |
43
+ | `r` | Refresh stories |
44
+ | `q` | Quit |
45
+
46
+ ### Mouse Support
47
+
48
+ - Click on stories in the sidebar to select them
49
+ - Click story title/URL to open in browser
50
+
51
+ ### AI Chat
52
+
53
+ Press `c` on any story to start a conversation with an AI about the story and its comments. The AI has full context of the story content and all comments.
54
+
55
+ #### Bring Your Own API Key
56
+
57
+ The chat feature requires an API key from either Anthropic or OpenAI. On first use, you'll be prompted to choose a provider and enter your key.
58
+
59
+ **Option 1: Environment variables**
60
+
61
+ ```bash
62
+ # For Anthropic
63
+ export ANTHROPIC_API_KEY=sk-ant-...
64
+
65
+ # For OpenAI
66
+ export OPENAI_API_KEY=sk-...
67
+ ```
68
+
69
+ **Option 2: In-app setup**
70
+
71
+ Press `c` to start a chat, and you'll be guided through the setup. Your key is stored locally at `~/.config/hn-cli/config.json`.
72
+
73
+ **Settings**
74
+
75
+ While in chat mode, press `,` to access settings where you can:
76
+
77
+ - Switch between Anthropic and OpenAI
78
+ - Change the model
79
+ - Add additional API keys
80
+ - Clear stored keys
81
+
82
+ ---
83
+
84
+ ## Development
85
+
86
+ ### Running locally
87
+
88
+ ```bash
89
+ bun install # Install dependencies
90
+ bun run start # Run the app
91
+ bun run dev # Run with hot reload
92
+ ```
93
+
94
+ ### Testing
95
+
96
+ ```bash
97
+ bun run test # Run tests
98
+ bun run typecheck # Check types
99
+ ```
100
+
101
+ ### Debug modes
102
+
103
+ ```bash
104
+ bun run debug # Test long comment wrapping
105
+ bun run debug story-list # Test story list view
106
+ bun run debug highlighted-comment # Test comment highlighting
107
+ ```
108
+
109
+ ### Architecture
110
+
111
+ - `src/index.ts` - Entry point
112
+ - `src/app.ts` - Main app class with UI and keyboard handling
113
+ - `src/api.ts` - API client for fetching from HNPWA API
114
+ - `src/config.ts` - Configuration and API key management
115
+ - `src/types.ts` - TypeScript types for HN data structures
116
+ - `src/test/` - Test suite
117
+
118
+ ## Design decisions
119
+
120
+ This CLI matches the implementation of my HN reader on my [personal website](https://brianlovin.com/hn):
121
+
122
+ - Only shows posts from the last 24 hours
123
+ - Only shows "link" type posts (excludes jobs, polls)
124
+ - Requires minimum story engagement: 50+ points OR 20+ comments
125
+ - Ranked by: points + (comments × 0.75) + recency bonus
126
+ - Maximum 24 posts displayed
127
+ - Comments: max 12 root comments, max 8 children per parent, max 3 levels deep
128
+
129
+ I made these choices so that it's easier for me to keep up with the most interesting stories throughout the day without getting sucked too deep into long comment threads or the flood of new submissions.
130
+
131
+ If you want your version of this tool to work differently, feel free to clone or consider opening a PR with more advanced settings to let people customize the default experience.
132
+
133
+ ## Credits
134
+
135
+ Built with [OpenTUI](https://github.com/anthropics/opentui)