@yeshwanthyk/coding-agent 0.2.2

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 (79) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/README.md +372 -0
  3. package/package.json +42 -0
  4. package/src/adapters/acp/index.ts +305 -0
  5. package/src/adapters/acp/protocol.ts +191 -0
  6. package/src/adapters/acp/session.ts +289 -0
  7. package/src/adapters/acp/updates.ts +96 -0
  8. package/src/adapters/cli/headless.ts +112 -0
  9. package/src/adapters/cli/validate.ts +50 -0
  10. package/src/adapters/tui/app.tsx +39 -0
  11. package/src/agent-events.ts +671 -0
  12. package/src/args.ts +102 -0
  13. package/src/autocomplete-commands.ts +102 -0
  14. package/src/commands.ts +23 -0
  15. package/src/compact-handler.ts +272 -0
  16. package/src/components/Footer.tsx +49 -0
  17. package/src/components/Header.tsx +218 -0
  18. package/src/components/MessageList.tsx +380 -0
  19. package/src/config.ts +1 -0
  20. package/src/domain/commands/builtin/clear.ts +14 -0
  21. package/src/domain/commands/builtin/compact.ts +96 -0
  22. package/src/domain/commands/builtin/conceal.ts +9 -0
  23. package/src/domain/commands/builtin/diffwrap.ts +9 -0
  24. package/src/domain/commands/builtin/editor.ts +24 -0
  25. package/src/domain/commands/builtin/exit.ts +14 -0
  26. package/src/domain/commands/builtin/followup.ts +24 -0
  27. package/src/domain/commands/builtin/index.ts +29 -0
  28. package/src/domain/commands/builtin/login.ts +118 -0
  29. package/src/domain/commands/builtin/model.ts +66 -0
  30. package/src/domain/commands/builtin/status.ts +32 -0
  31. package/src/domain/commands/builtin/steer.ts +24 -0
  32. package/src/domain/commands/builtin/theme.ts +23 -0
  33. package/src/domain/commands/builtin/thinking.ts +16 -0
  34. package/src/domain/commands/helpers.ts +41 -0
  35. package/src/domain/commands/registry.ts +42 -0
  36. package/src/domain/commands/types.ts +69 -0
  37. package/src/domain/messaging/content.ts +117 -0
  38. package/src/editor.ts +103 -0
  39. package/src/extensibility/schema.ts +1 -0
  40. package/src/extensibility/validation.ts +1 -0
  41. package/src/hooks/index.ts +1 -0
  42. package/src/hooks/useAgentEvents.ts +28 -0
  43. package/src/hooks/useEditorBridge.ts +101 -0
  44. package/src/hooks/useGitStatus.ts +28 -0
  45. package/src/hooks/usePromptQueue.ts +7 -0
  46. package/src/hooks/useSessionController.ts +5 -0
  47. package/src/hooks/useSpinner.ts +28 -0
  48. package/src/hooks/useToastManager.ts +26 -0
  49. package/src/index.ts +188 -0
  50. package/src/keyboard-handler.ts +134 -0
  51. package/src/profiler.ts +40 -0
  52. package/src/runtime/context.tsx +16 -0
  53. package/src/runtime/factory.ts +63 -0
  54. package/src/runtime/git/git-info.ts +25 -0
  55. package/src/runtime/session/session-controller.ts +208 -0
  56. package/src/session-manager.ts +1 -0
  57. package/src/session-picker.tsx +134 -0
  58. package/src/shell-runner.ts +134 -0
  59. package/src/syntax-highlighting.ts +114 -0
  60. package/src/theme-names.ts +37 -0
  61. package/src/tool-ui-contracts.ts +77 -0
  62. package/src/tui-open-rendering.tsx +565 -0
  63. package/src/types.ts +89 -0
  64. package/src/ui/app-shell/TuiApp.tsx +586 -0
  65. package/src/ui/clipboard/osc52.ts +18 -0
  66. package/src/ui/components/modals/ConfirmModal.tsx +52 -0
  67. package/src/ui/components/modals/EditorModal.tsx +39 -0
  68. package/src/ui/components/modals/InputModal.tsx +30 -0
  69. package/src/ui/components/modals/ModalContainer.tsx +67 -0
  70. package/src/ui/components/modals/SelectModal.tsx +48 -0
  71. package/src/ui/components/modals/index.ts +4 -0
  72. package/src/ui/features/composer/Composer.tsx +73 -0
  73. package/src/ui/features/composer/SlashCommandHandler.ts +58 -0
  74. package/src/ui/features/composer/keyboard.ts +3 -0
  75. package/src/ui/features/main-view/MainView.tsx +367 -0
  76. package/src/ui/features/message-pane/MessagePane.tsx +34 -0
  77. package/src/ui/hooks/useModals.ts +74 -0
  78. package/src/ui/state/app-store.ts +67 -0
  79. package/src/utils.ts +14 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,40 @@
1
+ # Changelog
2
+
3
+ ## [0.2.0] - 2024-12-31
4
+
5
+ ### Added
6
+
7
+ - **Shell mode**: `!` prefix for quick shell commands, `!!` injects output into context
8
+ - **`/status` command**: Show agent/session status with autocomplete
9
+ - **`/conceal` command**: Toggle markdown syntax hiding
10
+ - **`/editor` command**: Open external editor for composing messages
11
+ - **`ask_user_question` tool**: Structured user prompts dialog in TUI
12
+ - **ACP server mode**: `--acp` flag for Zed integration
13
+ - **`send()` API for custom tools**: Queue user input programmatically
14
+ - **Snapshot hook**: OpenCode-style working tree snapshots
15
+ - **Usage data in `turn.end` event**: Enables auto-compact hooks
16
+ - **LSP status in footer**: Server status, diagnostic counts, pulse animation on activity
17
+ - **LSP managed binaries**: Auto-downloads rust-analyzer, biome, ruff, ty
18
+ - **Cache efficiency indicator**: Shows compacting state in footer
19
+ - **Queue indicator in header**: Replaced cache indicator
20
+ - **Image attachments in read tool**: Render images inline
21
+ - **Tree-sitter markdown parser**: For syntax highlighting
22
+
23
+ ### Changed
24
+
25
+ - **MESSAGE_CAP increased to 75**: Up from 30 for longer conversations
26
+ - **Ctrl+C clears input**: Esc now aborts (behavior swap)
27
+ - **Thinking block styling**: Colorized labels by level, markdown conceal support
28
+ - **SelectList autocomplete picker**: Replaced custom picker implementation
29
+
30
+ ### Performance
31
+
32
+ - **Adaptive throttle + text tail**: Streaming optimization
33
+ - **Skip tree-sitter during streaming**: Defer highlighting until complete
34
+ - **Structured compaction format**: File tracking for smarter context management
35
+ - **Iterative summary updates**: More efficient compaction
36
+
37
+ ### Fixed
38
+
39
+ - Markdown concealment in compiled binary
40
+ - Path shortening improvements
package/README.md ADDED
@@ -0,0 +1,372 @@
1
+ # Marvin
2
+
3
+ Terminal-native coding agent with multi-provider support, extensible tooling, and LSP integration.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ # Build binary
9
+ cd apps/coding-agent && bun run build
10
+
11
+ # Add to PATH (e.g., in ~/.zshrc)
12
+ export PATH="$PATH:/path/to/marvin-agent/apps/coding-agent/dist"
13
+
14
+ # Or symlink to a bin directory
15
+ ln -s /path/to/marvin-agent/apps/coding-agent/dist/marvin ~/.local/bin/marvin
16
+ ```
17
+
18
+ ## Quick Start
19
+
20
+ ```bash
21
+ # Run with TUI
22
+ marvin
23
+
24
+ # Or with prompt
25
+ marvin "explain this codebase"
26
+
27
+ # Headless mode (JSON output)
28
+ marvin --headless "fix the types"
29
+ ```
30
+
31
+ ## Providers
32
+
33
+ | Provider | Auth | Notes |
34
+ |----------|------|-------|
35
+ | Anthropic | `ANTHROPIC_API_KEY` or OAuth | Pro/Max plans via OAuth flow |
36
+ | OpenAI | `OPENAI_API_KEY` | GPT-4o, o1, o3 |
37
+ | Google | `GOOGLE_API_KEY` | Gemini models |
38
+ | Codex | OAuth | `bun run codex-auth` |
39
+ | OpenRouter | `OPENROUTER_API_KEY` | Multi-provider gateway |
40
+ | Groq | `GROQ_API_KEY` | Fast inference |
41
+ | xAI | `XAI_API_KEY` | Grok models |
42
+ | Mistral | `MISTRAL_API_KEY` | Mistral models |
43
+ | Cerebras | `CEREBRAS_API_KEY` | Quick inference |
44
+
45
+ ## Configuration
46
+
47
+ Config lives in `~/.config/marvin/`:
48
+
49
+ ```
50
+ ~/.config/marvin/
51
+ ├── config.json # provider, model, theme, thinking, lsp settings
52
+ ├── agents.md # global AGENTS.md instructions
53
+ ├── agents/ # subagent definitions
54
+ ├── commands/ # custom slash commands
55
+ ├── hooks/ # lifecycle hooks
56
+ ├── tools/ # custom tools
57
+ ├── sessions/ # session persistence (per cwd)
58
+ └── codex-tokens.json # codex OAuth tokens
59
+ ```
60
+
61
+ ### config.json
62
+
63
+ ```json
64
+ {
65
+ "provider": "anthropic",
66
+ "model": "claude-sonnet-4-20250514",
67
+ "thinking": "high",
68
+ "theme": "catppuccin",
69
+ "editor": "code --wait",
70
+ "lsp": { "enabled": true, "autoInstall": true }
71
+ }
72
+ ```
73
+
74
+ Editor config (used by `/editor`):
75
+
76
+ ```json
77
+ "editor": "code --wait"
78
+ ```
79
+
80
+ ```json
81
+ "editor": { "command": "wezterm", "args": ["start", "--cwd", "{cwd}", "--", "nvim"] }
82
+ ```
83
+
84
+ Use the object form when command/args include spaces. Defaults to `nvim` when unset. `/editor` writes a temp file, suspends the TUI, then restores the prompt with the edited contents when the editor exits. The editor runs with `cwd` set to the current working directory; include `{cwd}` if your editor needs it. For GUI editors, add `--wait` so `/editor` blocks until the file closes.
85
+
86
+ ### AGENTS.md
87
+
88
+ Loaded from (first found):
89
+ - `~/.config/marvin/agents.md`
90
+ - `~/.codex/agents.md`
91
+ - `~/.claude/CLAUDE.md`
92
+
93
+ Project-level (merged with global):
94
+ - `./AGENTS.md`
95
+ - `./CLAUDE.md`
96
+
97
+ ## CLI Options
98
+
99
+ ```
100
+ marvin [prompt]
101
+
102
+ Options:
103
+ --provider <name> Provider (anthropic, openai, google, codex, openrouter, groq, xai, mistral, cerebras)
104
+ --model <id> Model id or comma-separated list (Ctrl+P to cycle)
105
+ --thinking <level> off | minimal | low | medium | high | xhigh
106
+ --continue, -c Continue most recent session
107
+ --resume, -r Pick session to resume
108
+ --headless JSON output, no TUI
109
+ --config <path> Custom config.json path
110
+ --config-dir <path> Custom config directory
111
+ ```
112
+
113
+ ## Keybindings
114
+
115
+ | Key | Action |
116
+ |-----|--------|
117
+ | `Enter` | Send message |
118
+ | `Ctrl+C` | Clear input / double to exit |
119
+ | `Esc` | Abort current request / dismiss autocomplete |
120
+ | `Ctrl+P` | Cycle through model list |
121
+ | `Ctrl+L` | Clear screen |
122
+ | `Ctrl+N/P` | Autocomplete navigation |
123
+ | `Tab` | Accept autocomplete |
124
+
125
+ ### Shell Mode
126
+
127
+ Prefix input with `!` for quick shell commands:
128
+ - `! ls -la` — Run command, show output
129
+ - `!! git status` — Run command and inject output into context
130
+
131
+ ## Slash Commands
132
+
133
+ | Command | Description |
134
+ |---------|-------------|
135
+ | `/model [provider] <id>` | Switch model |
136
+ | `/thinking <level>` | Set thinking level |
137
+ | `/theme [name]` | Switch theme (30+ built-in) |
138
+ | `/editor` | Open configured editor |
139
+ | `/compact [instructions]` | Compress context |
140
+ | `/status` | Show session status |
141
+ | `/steer <text>` | Interrupt current run with steering instructions |
142
+ | `/followup <text>` | Queue follow-up text for delivery once idle |
143
+ | `/conceal` | Toggle markdown syntax hiding |
144
+ | `/diffwrap` | Toggle diff word-wrap |
145
+ | `/abort` | Abort in-flight request |
146
+ | `/clear` | Clear chat + reset agent |
147
+ | `/exit`, `/quit` | Exit |
148
+
149
+ Custom commands: `~/.config/marvin/commands/*.md`
150
+
151
+ ```markdown
152
+ # ~/.config/marvin/commands/review.md
153
+ Review the following code for bugs, security issues, and improvements.
154
+
155
+ $ARGUMENTS
156
+ ```
157
+
158
+ Usage: `/review src/index.ts`
159
+
160
+ ## Tools
161
+
162
+ ### Built-in (base-tools)
163
+
164
+ - **read** — Read files (text + images)
165
+ - **write** — Write/create files
166
+ - **edit** — Surgical text replacement
167
+ - **bash** — Execute shell commands
168
+
169
+ ### Subagent
170
+
171
+ Delegate tasks to specialized agents with isolated context.
172
+
173
+ ```bash
174
+ # Define agents in ~/.config/marvin/agents/*.md
175
+ # Or project-level: .marvin/agents/*.md
176
+ ```
177
+
178
+ Agent definition:
179
+ ```markdown
180
+ ---
181
+ name: reviewer
182
+ description: Code review specialist
183
+ model: claude-sonnet-4-20250514
184
+ ---
185
+
186
+ You are a code reviewer. Focus on correctness, security, and maintainability.
187
+ ```
188
+
189
+ Modes:
190
+ - **Single**: `{ agent: "name", task: "..." }`
191
+ - **Parallel**: `{ tasks: [{ agent, task }, ...] }`
192
+ - **Chain**: `{ chain: [{ agent, task: "... {previous} ..." }, ...] }`
193
+
194
+ ### Custom Tools
195
+
196
+ ```typescript
197
+ // ~/.config/marvin/tools/my-tool.ts
198
+ import { Type } from "@sinclair/typebox"
199
+
200
+ export default function(api: { cwd: string; exec: Function }) {
201
+ return {
202
+ name: "my_tool",
203
+ description: "Does something useful",
204
+ parameters: Type.Object({
205
+ input: Type.String({ description: "Input value" })
206
+ }),
207
+ async execute(toolCallId: string, params: { input: string }) {
208
+ return {
209
+ content: [{ type: "text", text: `Result: ${params.input}` }],
210
+ details: { /* structured data for UI */ }
211
+ }
212
+ }
213
+ }
214
+ }
215
+ ```
216
+
217
+ Custom tools can include:
218
+ - `renderCall(args, theme)` — Custom call rendering
219
+ - `renderResult(result, opts, theme)` — Custom result rendering
220
+ - `onSession(event)` — Session lifecycle hook
221
+ - `dispose()` — Cleanup on exit
222
+
223
+ ## Hooks
224
+
225
+ Lifecycle hooks for automation and integrations.
226
+
227
+ ```typescript
228
+ // ~/.config/marvin/hooks/my-hook.ts
229
+ import type { HookAPI } from "@yeshwanthyk/coding-agent"
230
+
231
+ export default function(marvin: HookAPI) {
232
+ marvin.on("app.start", async (event, ctx) => {
233
+ // App initialized
234
+ })
235
+
236
+ marvin.on("tool.execute.before", async (event, ctx) => {
237
+ // Block or modify tool execution
238
+ if (event.toolName === "bash" && event.input.command?.includes("rm -rf")) {
239
+ return { block: true, reason: "Dangerous command blocked" }
240
+ }
241
+ })
242
+
243
+ marvin.on("tool.execute.after", async (event, ctx) => {
244
+ // Modify tool results
245
+ return { content: event.content }
246
+ })
247
+
248
+ marvin.on("agent.end", async (event, ctx) => {
249
+ // Agent loop completed
250
+ })
251
+ }
252
+ ```
253
+
254
+ Available events:
255
+ - `app.start` — Config loaded, before agent starts
256
+ - `session.start`, `session.resume`, `session.clear`
257
+ - `agent.start`, `agent.end`
258
+ - `turn.start`, `turn.end`
259
+ - `tool.execute.before`, `tool.execute.after`
260
+
261
+ Helpers:
262
+ - `marvin.steer(text)` / `marvin.followUp(text)` — delivery-aware sugar (interrupt vs queue automatically)
263
+ - `marvin.sendUserMessage(text, { deliverAs })` — explicit steering vs follow-up control
264
+ - `ctx.isIdle()` — true when the agent is not currently streaming or running tools
265
+
266
+ See `examples/hooks/steer-followup.ts` for a reference hook that exposes `/focus` and `/queue` commands.
267
+
268
+ Hook context provides:
269
+ - `ctx.exec(command, args, options)` — Run shell commands
270
+ - `ctx.cwd` — Current working directory
271
+ - `ctx.configDir` — Config directory path
272
+
273
+ ## LSP Integration
274
+
275
+ Language servers spawn automatically per file type. Diagnostics are injected into tool results after edit/write/bash operations.
276
+
277
+ ```json
278
+ // config.json
279
+ {
280
+ "lsp": {
281
+ "enabled": true,
282
+ "autoInstall": true
283
+ }
284
+ }
285
+ ```
286
+
287
+ Supported: TypeScript/JavaScript (auto-installed), with registry for more.
288
+
289
+ Custom LSP config: `~/.config/marvin/lsp/`
290
+
291
+ ## Themes
292
+
293
+ 30+ built-in themes:
294
+
295
+ ```
296
+ marvin (default), aura, ayu, catppuccin, catppuccin-macchiato, cobalt2,
297
+ dracula, everforest, flexoki, github, gruvbox, kanagawa, lucent-orng,
298
+ material, matrix, mercury, monokai, nightowl, nord, one-dark, opencode,
299
+ orng, palenight, rosepine, solarized, synthwave84, tokyonight, vercel,
300
+ vesper, zenburn
301
+ ```
302
+
303
+ Switch: `/theme <name>` or set in config.json.
304
+
305
+ ## Sessions
306
+
307
+ Sessions persist per working directory in `~/.config/marvin/sessions/`.
308
+
309
+ - `-c, --continue` — Resume most recent session
310
+ - `-r, --resume` — Pick from session list
311
+
312
+ Sessions store: metadata, messages, tool results (JSONL format).
313
+
314
+ ## Headless Mode
315
+
316
+ For scripting and subagent invocations:
317
+
318
+ ```bash
319
+ marvin --headless "fix the types" | jq .
320
+ ```
321
+
322
+ Output:
323
+ ```json
324
+ {
325
+ "ok": true,
326
+ "provider": "anthropic",
327
+ "model": "claude-sonnet-4-20250514",
328
+ "prompt": "fix the types",
329
+ "assistant": "I've fixed the type errors..."
330
+ }
331
+ ```
332
+
333
+ ## What's NOT Included
334
+
335
+ Intentionally omitted for simplicity:
336
+
337
+ - **MCP** — No Model Context Protocol
338
+ - **Permission gating** — No approval prompts for tool use
339
+ - **Plan mode** — No separate planning phase
340
+ - **Built-in todos** — No task tracking
341
+ - **Background tasks** — No async task queue
342
+
343
+ ## Development
344
+
345
+ ```bash
346
+ # Install deps
347
+ bun install
348
+
349
+ # Run dev
350
+ bun run marvin
351
+
352
+ # Typecheck
353
+ bun run typecheck
354
+
355
+ # Test
356
+ bun run test
357
+
358
+ # Build binary
359
+ cd apps/coding-agent && bun run build
360
+ ```
361
+
362
+ ## Architecture
363
+
364
+ ```
365
+ apps/coding-agent/ # Main CLI app
366
+ packages/
367
+ ├── ai/ # LLM provider abstraction
368
+ ├── agent/ # Agent-core state management
369
+ ├── base-tools/ # read, write, edit, bash
370
+ ├── lsp/ # Language server integration
371
+ └── open-tui/ # Terminal UI framework (SolidJS + OpenTUI)
372
+ ```
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@yeshwanthyk/coding-agent",
3
+ "version": "0.2.2",
4
+ "type": "module",
5
+ "bin": {
6
+ "marvin": "./src/index.ts"
7
+ },
8
+ "files": [
9
+ "src",
10
+ "README.md",
11
+ "CHANGELOG.md",
12
+ "package.json"
13
+ ],
14
+ "scripts": {
15
+ "test": "bun test tests",
16
+ "build": "bun scripts/build.ts"
17
+ },
18
+ "engines": {
19
+ "node": ">=20.0.0",
20
+ "bun": ">=1.3.0"
21
+ },
22
+ "dependencies": {
23
+ "@yeshwanthyk/agent-core": "^0.1.0",
24
+ "@yeshwanthyk/ai": "^0.1.0",
25
+ "@yeshwanthyk/base-tools": "^0.1.0",
26
+ "@yeshwanthyk/lsp": "^0.1.0",
27
+ "@yeshwanthyk/runtime-effect": "^0.1.0",
28
+ "@yeshwanthyk/open-tui": "^0.1.0",
29
+ "@opentui/core": "0.1.63",
30
+ "@opentui/solid": "0.1.63",
31
+ "chalk": "^5.6.2",
32
+ "cli-highlight": "^2.1.11",
33
+ "diff": "^8.0.2",
34
+ "solid-js": "1.9.9"
35
+ },
36
+ "devDependencies": {
37
+ "@babel/core": "^7.28.5",
38
+ "@babel/preset-typescript": "^7.28.5",
39
+ "@types/bun": "^1.3.5",
40
+ "babel-preset-solid": "1.9.9"
41
+ }
42
+ }