glyphcode 0.0.0-stage → 0.1.1

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.
Files changed (3) hide show
  1. package/README.md +306 -2
  2. package/dist/index.js +497955 -0
  3. package/package.json +36 -4
package/README.md CHANGED
@@ -1,3 +1,307 @@
1
- # Temporary Holding Version
1
+ <p align="center">
2
+ <img src="docs/glyphcode-icon.png" alt="glyph icon" width="150" height="150">
3
+ </p>
2
4
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
5
+ <h1 align="center">glyphcode</h1>
6
+
7
+ <p align="center">
8
+ <strong>An AI coding agent for the terminal.</strong><br>
9
+ Talk to LLMs, run tools, and get work done without leaving your shell.
10
+ </p>
11
+
12
+ ## Features
13
+
14
+ - **Multiple providers** — Anthropic, OpenAI, Google Gemini, OpenRouter
15
+ - **Interactive TUI** — Full-screen terminal UI built with Ink/React
16
+ - **Tool calling** — Models can run tools (weather, file ops, shell, etc.)
17
+ - **Markdown rendering** — Responses render with syntax highlighting
18
+ - **Scrollable history** — Arrow keys / PgUp / PgDn to browse conversation
19
+ - **One-shot mode** — `glyph chat "question"` for quick queries
20
+ - **Config wizard** — `glyph setup` walks you through provider/model/key
21
+
22
+ ## Screenshots
23
+
24
+ ### Interactive TUI
25
+ ![glyph TUI](docs/snapshots/01.png)
26
+ *The main interface showing conversation history, markdown rendering, and input area.*
27
+
28
+ ![glyph setup](docs/snapshots/02.png)
29
+ *Tool usage*
30
+
31
+ ### One-shot Chat
32
+ ![glyph chat](docs/snapshots/cli-setup.png)
33
+ *Interactive configuration wizard — select provider, model, and enter API key.*
34
+
35
+ > **Add your screenshots:** Place PNG files in `docs/snapshots/` and reference them above.
36
+ > Recommended size: 800–1200px wide for GitHub README display.
37
+
38
+ ## Quick Start
39
+
40
+ ```bash
41
+ # Install globally
42
+ npm i -g glyph
43
+
44
+ # Or run locally
45
+ npx glyph setup
46
+ ```
47
+
48
+ ```bash
49
+ # First run: configure your provider and API key
50
+ glyph setup
51
+
52
+ # Start the interactive TUI
53
+ glyph
54
+
55
+ # Quick one-off question
56
+ glyph chat "explain async/await in JavaScript"
57
+ ```
58
+
59
+ ## Installation
60
+
61
+ ### From npm (recommended)
62
+ ```bash
63
+ npm i -g glyph
64
+ # or
65
+ pnpm add -g glyph
66
+ # or
67
+ yarn global add glyph
68
+ ```
69
+
70
+ ### From source
71
+ ```bash
72
+ git clone https://github.com/yourusername/glyph.git
73
+ cd glyph
74
+ npm install
75
+ npm run build
76
+ npm link # makes `glyph` available globally
77
+ ```
78
+
79
+ ### Requirements
80
+ - **Node.js 18+** (for built-in fetch, ESM support)
81
+ - A terminal with TTY support (for the interactive TUI)
82
+
83
+ ## Configuration
84
+
85
+ Run the setup wizard:
86
+ ```bash
87
+ glyph setup
88
+ ```
89
+
90
+ It will ask:
91
+ 1. **Provider** — Anthropic, OpenAI, Google, or OpenRouter
92
+ 2. **Model** — Pick from the provider's model list
93
+ 3. **API Key** — Paste your key (hidden input)
94
+
95
+ Config is saved to:
96
+ - **Windows:** `%APPDATA%\.glyph\config.json`
97
+ - **macOS/Linux:** `~/.config/glyph/config.json` (or `~/.glyph/config.json`)
98
+
99
+ The file is created with **owner-only permissions (600)**.
100
+
101
+ ### Non-interactive setup (CI/scripts)
102
+ ```bash
103
+ # Not yet implemented — run `glyph setup` interactively
104
+ ```
105
+
106
+ ## Commands
107
+
108
+ | Command | Description |
109
+ |---------|-------------|
110
+ | `glyph` | Start the interactive TUI (default) |
111
+ | `glyph setup` | Interactive configuration wizard |
112
+ | `glyph config show` | Display current config (key masked) |
113
+ | `glyph config set-key` | Update just the API key |
114
+ | `glyph chat "prompt"` | One-shot query, prints response and exits |
115
+ | `glyph version` | Show version number |
116
+ | `glyph --help` | Show all commands |
117
+ | `glyph -d setup` | Enable debug logging |
118
+
119
+ ### Examples
120
+
121
+ ```bash
122
+ # Interactive coding session
123
+ glyph
124
+
125
+ # Quick question without TUI
126
+ glyph chat "how do I center a div in CSS?"
127
+
128
+ # Override model for one query
129
+ glyph chat "write a quicksort in Python" --model gpt-4o --provider openai
130
+
131
+ # View config
132
+ glyph config show
133
+
134
+ # Rotate API key
135
+ glyph config set-key
136
+ ```
137
+
138
+ ## TUI Controls
139
+
140
+ | Key | Action |
141
+ |-----|--------|
142
+ | `↑` / `↓` | Scroll history by 1 message |
143
+ | `PgUp` / `PgDn` | Scroll by page |
144
+ | `Home` / `End` | Jump to top/bottom |
145
+ | `Esc` | Interrupt current agent turn |
146
+ | `Ctrl+C` | Interrupt / quit (when idle) |
147
+ | `/exit` | Quit the app |
148
+
149
+ **Auto-scroll:** New messages auto-scroll to bottom. Scroll up to pin and read history — scroll to bottom to resume auto-scroll.
150
+
151
+ ## Supported Providers
152
+
153
+ | Provider | Models | API Key Env Var |
154
+ |----------|--------|-----------------|
155
+ | **OpenAI** | GPT-4o, 4o-mini, 4-turbo, 3.5-turbo | `OPENAI_API_KEY` |
156
+ | **Google Gemini** | 1.5 Pro, 1.5 Flash | `GEMINI_API_KEY` |
157
+ | **OpenRouter** | Auto, Claude via OR, GPT via OR | `OPENROUTER_API_KEY` |
158
+
159
+ Get keys from:
160
+ - Anthropic: <https://console.anthropic.com/>
161
+ - OpenAI: <https://platform.openai.com/api-keys>
162
+ - Google: <https://aistudio.google.com/apikey>
163
+ - OpenRouter: <https://openrouter.ai/keys>
164
+
165
+ ## Tools
166
+
167
+ Tools let the agent take actions. Currently built-in:
168
+
169
+ | Tool | Description |
170
+ |------|-------------|
171
+ | `weather` | Live weather lookup via OpenWeatherMap |
172
+
173
+ More tools coming (file read/write, shell, web search, etc.).
174
+
175
+ ## Project Structure
176
+
177
+ ```
178
+ glyph/
179
+ ├── package.json
180
+ ├── tsconfig.json
181
+ ├── dist/ # Built output (gitignored)
182
+ ├── commands/ # CLI commands (Commander)
183
+ │ ├── index.ts # Entry point, command registry
184
+ │ ├── setup.ts # Interactive setup wizard
185
+ │ ├── config.ts # config show / set-key
186
+ │ ├── chat.ts # One-shot chat command
187
+ │ ├── verify.ts # API key verification
188
+ │ ├── config/ # Config file layer
189
+ │ │ ├── path.ts # Cross-platform config paths
190
+ │ │ ├── schema.ts # Zod schema + types
191
+ │ │ ├── read.ts # Load & validate config
192
+ │ │ └── write.ts # Atomic write (tmp→rename, chmod 600)
193
+ │ └── catalogue/
194
+ │ └── provider.ts # Provider catalog (models, endpoints)
195
+ ├── provider/ # LLM provider runtime
196
+ │ ├── index.ts # Lazy OpenAI client from config
197
+ │ ├── model_selector.ts # Model resolution (async + sync)
198
+ │ └── context.ts # Conversation context/history
199
+ ├── core/
200
+ │ ├── agent.ts # Agent loop (streaming, tools)
201
+ │ └── events.ts # Event types
202
+ ├── tools/ # Tool definitions
203
+ │ ├── index.ts # Registry
204
+ │ ├── types.ts # Tool types
205
+ │ └── weather.ts # Weather tool
206
+ ├── ui/ # Ink TUI
207
+ │ ├── App.tsx # Root component
208
+ │ ├── useAgent.ts # Agent ↔ React bridge
209
+ │ ├── theme.ts # Color palette
210
+ │ ├── format.ts # Text formatting helpers
211
+ │ ├── types.ts # UI types
212
+ │ └── components/ # React components (Header, History, Input, etc.)
213
+ └── simple-cli/ # Legacy CLI (being phased out)
214
+ ```
215
+
216
+ ## Development
217
+
218
+ ```bash
219
+ # Install deps
220
+ npm install
221
+
222
+ # Dev mode (runs with Bun, hot reload)
223
+ npm run dev
224
+
225
+ # Build for distribution
226
+ npm run build
227
+
228
+ # Run built version
229
+ node dist/index.js
230
+
231
+ # Type check
232
+ npx tsc --noEmit
233
+ ```
234
+
235
+ ### Adding a Tool
236
+
237
+ 1. Create `tools/mytool.ts`:
238
+ ```ts
239
+ import type { Tool } from "./types";
240
+
241
+ export const myTool: Tool = {
242
+ name: "my_tool",
243
+ description: "Does something useful",
244
+ needsPermission: false,
245
+ schema: { /* Zod schema */ },
246
+ async run(args, signal) {
247
+ // implementation
248
+ return { result: "ok" };
249
+ },
250
+ };
251
+ ```
252
+
253
+ 2. Register in `tools/index.ts`:
254
+ ```ts
255
+ export const registry = { ..., my_tool: myTool };
256
+ export const toolDefinitions = [..., myTool.schema];
257
+ ```
258
+
259
+ ### Adding a Provider
260
+
261
+ Edit `commands/catalogue/provider.ts`:
262
+ ```ts
263
+ export const PROVIDERS = {
264
+ ...existing,
265
+ myprovider: {
266
+ label: "My Provider",
267
+ envVar: "MYPROVIDER_API_KEY",
268
+ models: ["model-1", "model-2"],
269
+ baseURL: "https://api.myprovider.com/v1",
270
+ },
271
+ } as const;
272
+ ```
273
+
274
+ ## Security
275
+
276
+ - **API keys** stored in `config.json` with `chmod 600` (owner read/write only)
277
+ - **Never logged** — keys are masked in all output (`••••••••a1b2`)
278
+ - **No telemetry** — nothing leaves your machine except LLM API calls
279
+ - **Verification** — `glyph setup` tests the key before saving
280
+
281
+ ## Troubleshooting
282
+
283
+ | Issue | Fix |
284
+ |-------|-----|
285
+ | `Raw mode is not supported` | Run in a real terminal (not VS Code output pane, not CI) |
286
+ | `glyph: command not found` | Reinstall: `npm i -g glyph` or add `~/.npm-global/bin` to PATH |
287
+ | `No configuration found` | Run `glyph setup` first |
288
+ | `Could not verify key` | Check key is valid; try `glyph config set-key` |
289
+ | Permission denied on config | `chmod 600 ~/.config/glyph/config.json` |
290
+
291
+ ## Roadmap
292
+
293
+ - [ ] File read/write tools
294
+ - [ ] Shell command execution
295
+ - [ ] Web search tool
296
+ - [ ] Multiple config profiles (`glyph setup --profile work`)
297
+ - [ ] OS keychain storage (optional)
298
+ - [ ] Plugin system for custom tools
299
+ - [ ] Session persistence / export
300
+
301
+ ## License
302
+
303
+ MIT — see [LICENSE](LICENSE) for details.
304
+
305
+ ---
306
+
307
+ **Built with:** TypeScript, Node.js, Ink, Commander, @clack/prompts, Zod, OpenAI SDK, Opencode