@mumbrane/leto 0.0.0-stage → 0.19.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.
Files changed (56) hide show
  1. package/README.md +395 -2
  2. package/bin/leto.js +8 -0
  3. package/evals/core/suite.json +249 -0
  4. package/index.js +12 -0
  5. package/package.json +43 -4
  6. package/src/agent.js +572 -0
  7. package/src/agents.js +68 -0
  8. package/src/anthropic.js +204 -0
  9. package/src/browser.js +427 -0
  10. package/src/btw.js +56 -0
  11. package/src/checkpoints.js +90 -0
  12. package/src/ci.js +115 -0
  13. package/src/cli.js +1926 -0
  14. package/src/client.js +111 -0
  15. package/src/config.js +205 -0
  16. package/src/documents.js +198 -0
  17. package/src/eval.js +289 -0
  18. package/src/hooks.js +115 -0
  19. package/src/ide.js +231 -0
  20. package/src/input.js +148 -0
  21. package/src/jobs.js +97 -0
  22. package/src/legacy.js +41 -0
  23. package/src/lsp.js +401 -0
  24. package/src/markdown.js +153 -0
  25. package/src/mcp.js +346 -0
  26. package/src/memory.js +136 -0
  27. package/src/orchestrator.js +141 -0
  28. package/src/patching.js +185 -0
  29. package/src/permissions.js +75 -0
  30. package/src/plugins.js +118 -0
  31. package/src/policy.js +74 -0
  32. package/src/pricing.js +67 -0
  33. package/src/processes.js +139 -0
  34. package/src/prompt.js +134 -0
  35. package/src/prompts.js +189 -0
  36. package/src/providers.js +59 -0
  37. package/src/repomap.js +211 -0
  38. package/src/sandbox.js +90 -0
  39. package/src/sdk.js +220 -0
  40. package/src/selftool.js +238 -0
  41. package/src/serve.js +233 -0
  42. package/src/session.js +168 -0
  43. package/src/setup.js +157 -0
  44. package/src/skills.js +125 -0
  45. package/src/theme.js +185 -0
  46. package/src/toolcalls.js +257 -0
  47. package/src/tools.js +976 -0
  48. package/src/tui.js +1179 -0
  49. package/src/ui.js +454 -0
  50. package/src/update.js +33 -0
  51. package/src/usage.js +83 -0
  52. package/src/verify.js +131 -0
  53. package/src/version.js +3 -0
  54. package/src/worktree.js +87 -0
  55. package/vscode/extension.js +132 -0
  56. package/vscode/package.json +21 -0
package/README.md CHANGED
@@ -1,3 +1,396 @@
1
- # Temporary Holding Version
1
+ # leto
2
2
 
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.
3
+ A coding agent for your terminal, built by Mumbrane. It reads your code, edits files and runs commands, asking before anything that changes your machine. It works with Claude, GPT, Gemini, Grok, DeepSeek, Mistral, local models and more.
4
+
5
+ - **Sub-agents:** hands big jobs to parallel agents with their own fresh context
6
+ - **Plan mode:** investigates and proposes a plan before touching anything
7
+ - **Task lists:** tracks multi-step work as it goes
8
+ - **Skills:** packaged know-how the agent loads when a task calls for it
9
+ - **A real browser:** browses, clicks, types and takes screenshots it can look at
10
+ - **Deep research:** `/research` runs parallel web research and writes a cited report
11
+ - **Undo:** every file change is checkpointed; `/undo` puts things back
12
+ - **MCP:** plug in GitHub, databases, Slack and any other MCP server
13
+ - **Images:** attach screenshots and mockups
14
+ - **Background jobs:** hand off a task and close the terminal
15
+ - **Hooks:** run your own scripts before or after the agent's actions
16
+ - **Native Claude support:** prompt caching, visible thinking, effort control and cost tracking
17
+ - **Crash-safe sessions:** every step is logged; pick up exactly where you left off
18
+
19
+ ## Install
20
+
21
+ ```bash
22
+ npm install -g @mumbrane/leto
23
+ ```
24
+
25
+ Requires Node.js 18.17 or later.
26
+
27
+ ## Set up
28
+
29
+ Run `leto`. The first time, it walks you through setup:
30
+
31
+ 1. **Pick a provider** with the arrow keys: Anthropic (Claude), OpenAI, Google Gemini, OpenRouter, xAI, DeepSeek, Mistral, Groq, Together AI, Ollama (local) or any other OpenAI-compatible API.
32
+ 2. **Paste your API key.** It's hidden as you type, checked against the provider, and saved to `~/.leto/config.json` (readable only by you).
33
+ 3. **Pick a model** from the provider's live model list. Type to search.
34
+
35
+ That's it. Switch any time inside a session:
36
+
37
+ - `/model` picks another model from the same provider.
38
+ - `/provider` switches provider or updates your key. Each provider remembers its own key and model.
39
+
40
+ Outside a session: `leto setup` reruns setup, `leto models` lists models, `leto logout` removes saved keys.
41
+
42
+ For CI or scripts, skip setup with environment variables: `LETO_PROVIDER` (e.g. `anthropic`), `LETO_API_KEY`, `LETO_MODEL`, or `LETO_BASE_URL` for any OpenAI-compatible endpoint.
43
+
44
+ ## Use
45
+
46
+ ```bash
47
+ leto # interactive session in the current directory
48
+ leto "fix the failing test" # interactive, starting with a task
49
+ leto -p "explain src/app.ts" # one-shot: prints the answer and exits
50
+ leto -p --json "…" # one-shot with a JSON result (for scripts and CI)
51
+ leto -p --max-cost 0.50 "…" # stop if the estimated cost passes $0.50
52
+ leto -c # continue the last session in this directory
53
+ leto -r <id> # resume a specific session
54
+ leto sessions # list recent sessions
55
+ ```
56
+
57
+ In a session:
58
+
59
+ | Command | What it does |
60
+ |---|---|
61
+ | `/help` | List commands (including your own) |
62
+ | `/plan` | Plan mode: investigate and propose, change nothing; `/plan` again to approve |
63
+ | `/init` | Write `LETO.md` project notes for this folder |
64
+ | `/todos` | Show the current task list |
65
+ | `/cost` | Tokens, cache hits and estimated cost for this session |
66
+ | `/effort [level]` | How hard Claude thinks: `low` to `max` |
67
+ | `/resume` (or `/sessions`) | Pick an earlier session; its conversation is shown and you carry on in it |
68
+ | `/permissions` | See and revoke what is always allowed |
69
+ | `/export [file]` | Save the conversation as Markdown |
70
+ | `/memory` | Show or edit what leto remembers; start any message with `#` to add to it |
71
+ | `/diff` / `/commit` | Show uncommitted changes / have leto write the message and commit |
72
+ | `/rewind` (or Esc Esc) | Go back to before an earlier message: files are restored and your message comes back to edit |
73
+ | `/theme` | Color theme: auto, spice, spice-light, mono |
74
+ | `/budget [$]` | Stop when this session's estimated cost reaches a limit |
75
+ | `/rename [name]` | Name this session (shows in `/resume`) |
76
+ | `/undo [n]` | Revert leto's file changes from the last turn (or pick a turn) |
77
+ | `/paste` | Attach the image on your clipboard (macOS) |
78
+ | `/mcp` | Show connected MCP servers and their tools |
79
+ | `/bg <task>` / `/jobs` | Start a background job / check on jobs |
80
+ | `/status` | Session, model, context usage, permissions |
81
+ | `/compact` | Summarize history to free up context |
82
+ | `/model [name]` | Pick a model from your provider |
83
+ | `/provider` | Switch provider or update your API key |
84
+ | `/clear` | Clear the screen and start a fresh session (the old one stays saved) |
85
+ | `/yolo` | Toggle running tool calls without asking |
86
+ | `/btw <question>` | Quick side question, even while leto works; not added to the conversation |
87
+ | `/ide` | Editor connection: install the VS Code / Cursor extension, diffs on or off |
88
+ | `/orchestrate` | Orchestrator mode: a brain model delegates work to a team of models |
89
+ | `/check [cmd]` | Choose the check (typecheck, lint, tests) that runs after edits |
90
+ | `/sandbox` | Toggle the shell sandbox (`/sandbox network` allows network) |
91
+ | `/agents` | Browse and create custom sub-agents |
92
+ | `/branches` | Review, merge or delete branches from worktree agents |
93
+ | `/continue` | Pick up a turn that was interrupted or crashed |
94
+ | `/exit` | Quit (or Ctrl-D) |
95
+
96
+ Type `@path/to/file` to attach a file (or folder listing) to your message; images (`@screenshot.png`, or drag one into the terminal) are sent to the model too. Tab completes commands and `@` paths, and ↑ recalls earlier messages, even from past sessions. Esc or Ctrl-C interrupts the model mid-response. End a line with `\` to keep typing on the next line.
97
+
98
+ ### Custom commands
99
+
100
+ Put a Markdown file in `.leto/commands/` (per project) or `~/.leto/commands/` (everywhere) and it becomes a slash command. `.leto/commands/review.md` becomes `/review`; `$ARGUMENTS` in the file is replaced with whatever you type after the command.
101
+
102
+ ## Tools
103
+
104
+ | Tool | Asks first |
105
+ |---|---|
106
+ | `read_file` (text, images, PDFs, notebooks), `grep`, `list_files`, `repo_map`, `lsp`, `memory`, `bash_output` | No |
107
+ | `todo_write` (task list), `task` (sub-agents), `ask_user` (questions for you), `web_search`, `skill`, `leto` (itself; see below) | No |
108
+ | `write_file`, `edit_file`, `multi_edit`, `apply_patch`, `notebook_edit`, `bash`, `web_fetch`, `browser` | Yes: answer `y`, `a` (always, for this session) or `n` |
109
+
110
+ Sub-agents of type `explore` (the default) can only read and search. `general` sub-agents can also edit and run commands, and they ask permission the same way.
111
+
112
+ `repo_map` gives the model an outline of the codebase in one call: source files ranked by how central they are (imported by many others, changed recently), each with its classes, functions and line numbers. With a query ("auth session token") it ranks files for that topic. It's how leto finds its way around large repositories without reading everything.
113
+
114
+ `read_file` reads PDFs as text (using `pdftotext` when installed, or a built-in extractor; on Claude the PDF itself is attached too, so scanned pages and charts work) and Jupyter notebooks as numbered cells with their outputs. `notebook_edit` replaces, inserts or deletes cells.
115
+
116
+ ## Side questions: /btw
117
+
118
+ `/btw how does the cache key get built?` asks a quick question about the work so far. It's answered from what leto already knows, without tools, and the exchange is not added to the conversation, so the main task isn't sidetracked. It works while leto is busy: type it in the composer and the answer appears right away while the work continues. On Claude it reuses the prompt cache, so it costs little.
119
+
120
+ ## Code intelligence
121
+
122
+ - **Language servers.** The `lsp` tool asks the language server your project already uses for definitions, references, types and docs (hover), file outlines and workspace symbol search, and errors. It supports TypeScript/JavaScript (`typescript-language-server`), Python (`pyright` or `pylsp`), Go (`gopls`), Rust (`rust-analyzer`) and C/C++ (`clangd`), when they're installed. Add others in config: `"lsp": { ".rb": "ruby-lsp" }`. Once a server is running, every edit reports that file's new type errors straight back to the model.
123
+ - **Edits that tolerate small mistakes.** When `old_string` is off only by indentation, trailing spaces or line endings, the edit still applies to the one place it matches, and the replacement is re-indented to fit. Anything ambiguous is refused.
124
+ - **Patches.** `apply_patch` takes a unified diff for large or multi-file changes: create, modify, rename and delete files, all or nothing. Hunks are found by their context, so approximate line numbers are fine.
125
+
126
+ ## A real shell
127
+
128
+ The working directory and exported variables carry over between commands, like a terminal: `cd` once and stay there. Dev servers, watchers and long builds run in the background (`run_in_background`); leto reads their output when it needs to (`bash_output`), gets told when one exits, and stops them (`kill_process`). Everything still running is stopped when leto exits.
129
+
130
+ ## Memory across sessions
131
+
132
+ As it works, leto saves short facts it learns about a project (a build quirk, a convention, a decision you made) and starts every later session there with them. They're kept privately in `~/.leto/memory/`, never in the repository; `/memory` shows and edits them. It can also search your earlier sessions ("how did we fix the login bug last week?").
133
+
134
+ ## It asks you questions
135
+
136
+ When a request is ambiguous in a way that changes what gets built (scope, language, framework, tradeoffs), leto asks before starting instead of guessing. Questions appear as a card with concrete options, its recommendation first: pick one with ↑↓ and Enter or a number, tick several when it allows more than one (space or numbers), or choose "Type my own answer". Esc skips a question, and leto uses its best judgment and says what it chose. It doesn't ask about things it can find out by reading your code. In `-p` mode nobody can answer, so it states its assumptions and carries on; in the SDK, questions go to your `onQuestion` callback.
137
+
138
+ ## Orchestrator mode
139
+
140
+ One top model is the brain; a team of other models does the work. The brain plans, splits the job into pieces, hands each piece to the team member whose strengths fit it, checks what comes back (asking a second model to review when it matters) and puts it all together. Team members can come from any provider you've set up, each using its own saved key, so a team can mix Claude, GPT, Gemini, your own model and local ones.
141
+
142
+ Set it up with `/orchestrate`:
143
+
144
+ - **✦ Suggest a team** looks at the models your providers offer and picks by strength. With an Anthropic key, for example: Fable 5.2 as the brain, and as workers Opus 5.5 (hard coding and debugging), Sonnet 5.5 (everyday implementation) and Haiku 5.5 (fast, cheap searching and reading).
145
+ - **Brain** and **+ Add a team member** let you choose any model from any provider, name it, and describe what it's good at. The brain reads those descriptions, with each model's price, to decide who gets what.
146
+ - **Turn on / off** switches mid-session. It's remembered, and `leto --orchestrate` turns it on for one run.
147
+
148
+ While it's on, the status line shows `◆ <brain> + <team size>`, each delegated job shows which model ran it and what it cost, and `/cost` breaks spending down by model. Workers use the same permissions, sandbox and worktrees as any sub-agent. In code: `query({ prompt, orchestrate: true })` uses your saved team, or pass `{ brain, team }`.
149
+
150
+ ## It knows itself
151
+
152
+ leto can look itself up and operate itself through its `leto` tool, so you can just ask ("how do I add an MCP server?", "make a reviewer agent for this repo", "turn on the sandbox and run the whole test suite"):
153
+
154
+ - **Its own manual:** questions about leto are answered from this README, not guessed.
155
+ - **Its own state:** model, context use, cost and budget, permission and plan mode, sandbox, check command, task list.
156
+ - **What it has:** skills, custom agents, commands, MCP servers, worktree branches, background jobs, and suggested check commands for the project.
157
+ - **Its own settings, when the work calls for it:** it switches to plan mode before a big or risky change and asks you to approve the plan to leave it; compacts its history before a long new phase; lowers or raises effort; turns the sandbox on; sets the project check; starts background jobs; and reloads skills, agents and commands it just wrote for you, without a restart.
158
+
159
+ Anything that widens what it may do without asking (setting a check command, starting a job, turning the sandbox off, leaving plan mode) asks you first, every time.
160
+
161
+ ## Plugins
162
+
163
+ Share a setup across a team as a plugin: a git repo or folder with any of `skills/`, `agents/`, `commands/` and `mcp.json`, plus a `plugin.json` with its name.
164
+
165
+ ```bash
166
+ leto plugin add acme/leto-kit # GitHub owner/repo, any git URL, or a local folder
167
+ leto plugin list
168
+ leto plugin update # git pull every plugin
169
+ leto plugin remove leto-kit
170
+ ```
171
+
172
+ Installed plugins live in `~/.leto/plugins/` and their skills, agents, commands and MCP servers work everywhere, like your own.
173
+
174
+ ## Editor integration
175
+
176
+ `leto ide install` (or `/ide`) installs the leto extension into VS Code, Cursor or Windsurf. With it, leto sees the file you have open, your selection and the editor's errors, so "explain this" and "fix this function" just work. Each edit it makes opens as a diff in the editor. Press Cmd+Esc (Ctrl+Esc) in the editor to open leto in its terminal. The two talk through small files in `~/.leto/ide`, so no ports or network are involved.
177
+
178
+ ## For organizations
179
+
180
+ **Managed settings.** An administrator can install a policy file (`/Library/Application Support/Leto/policy.json` on macOS, `/etc/leto/policy.json` elsewhere, or `$LETO_POLICY`) that leto enforces over each user's own config:
181
+
182
+ ```json
183
+ {
184
+ "allowedProviders": ["anthropic", "custom"],
185
+ "allowedModels": ["^claude-(sonnet|haiku)-"],
186
+ "providers": { "custom": { "baseUrl": "https://llm.internal.example/v1" } },
187
+ "disableYolo": true,
188
+ "forceSandbox": true,
189
+ "disabledTools": ["browser"],
190
+ "maxCostPerSession": 20,
191
+ "disablePlugins": false,
192
+ "usageEndpoint": "https://usage.internal.example/leto"
193
+ }
194
+ ```
195
+
196
+ **Usage reports.** Every request is recorded in `~/.leto/usage.jsonl`: time, user, project, session, model, tokens and estimated cost. `leto usage` sums it up (`--by day|model|project|user|session`, `--days 30`, `--json`). With `usageEndpoint` in the policy, records are also sent there in batches, for company-wide reporting.
197
+
198
+ ## Self-checking
199
+
200
+ leto checks its own work while it can still fix it:
201
+
202
+ - **Every edit** is parsed straight away (JavaScript, JSON, Python, shell, Ruby, PHP). A syntax error goes back to the model in that edit's result.
203
+ - **A project check** runs before leto finishes a turn that changed files. Pick one with `/check`; it suggests commands from your project (`npm run typecheck`, `cargo check`, `go vet ./...`, `ruff check .`, tests…). If the check fails, the errors go back to the model and it keeps working, up to 3 rounds. The check is stored per project in your own config, never read from the repository, so a cloned repo can't make leto run its commands. For one run: `--check "npm test"`.
204
+
205
+ ## Sandbox
206
+
207
+ `leto --sandbox` (or `/sandbox`, or `leto config set sandbox on`) runs shell commands in an OS sandbox: they can write only inside the project and temp folders, can't read credentials (`~/.ssh`, `~/.aws`, `~/.leto`, keychains…), and have no network except localhost. Because a sandboxed command can't harm anything outside the project, it runs without asking. When a command really needs more (installing packages, pushing), leto asks to run that one outside the sandbox. `/sandbox network` allows network access. macOS uses the built-in `sandbox-exec`; Linux needs bubblewrap (`apt install bubblewrap`).
208
+
209
+ ## Parallel work in worktrees
210
+
211
+ In a git repository, leto can give sub-agents their own worktree (a separate checkout on its own branch), so several can change code at the same time without conflicts. Ask for it ("do these three refactors in parallel, each in its own worktree") or let the model choose it. Each agent's changes are committed to a branch `leto/<task>`; your working copy is untouched. `/branches` lists them with options to view the diff, merge or delete. `leto -w` starts a whole session in a new worktree.
212
+
213
+ ## Custom agents
214
+
215
+ Add specialist sub-agents as Markdown files in `.leto/agents/` (project) or `~/.leto/agents/` (everywhere); `.claude/agents/` works too. `/agents` creates one for you.
216
+
217
+ ```markdown
218
+ ---
219
+ name: reviewer
220
+ description: Reviews changes for bugs and risky edits. Use after finishing a change.
221
+ tools: read_file, grep, list_files, repo_map, bash
222
+ model: claude-haiku-5-5
223
+ ---
224
+ You are a careful code reviewer. Read the diff with `git diff`, then report
225
+ concrete problems with file:line and a suggested fix. Don't edit files.
226
+ ```
227
+
228
+ leto then hands matching work to it (`task` with `agent_type: "reviewer"`). `tools` limits what it can use; `model` runs it on a different (say, cheaper) model.
229
+
230
+ `-p` mode denies tools that need permission unless you pass `--yolo` or `--allow edit_file,write_file,bash`.
231
+
232
+ ## Claude
233
+
234
+ With the Anthropic provider, leto talks to the Claude API directly (through Anthropic's official SDK):
235
+
236
+ - **Prompt caching** is on automatically, so each turn re-reads the conversation from cache at a fraction of the price. `/cost` shows how much was served from cache.
237
+ - **Thinking** summaries appear, dimmed, above Claude's replies.
238
+ - **Effort** (`/effort`, or `leto config set effort high`) trades thoroughness for speed and cost.
239
+ - **Fallbacks:** on models that support it, if Claude declines a request, the API can retry it on another Claude model.
240
+ - Sessions stay append-only: the system prompt is fixed for the session and Claude's responses are replayed exactly, which keeps the cache warm and Claude's earlier reasoning valid.
241
+
242
+ ## Memory and permissions
243
+
244
+ Start a message with `#` to give leto a standing instruction, like `# use pnpm, not npm`. You choose whether it's for this project (`LETO.md`) or every project (`~/.leto/LETO.md`); `/memory` shows and edits both.
245
+
246
+ When leto wants to run a command, you can allow just that command for this project (for example `npm test`, which also covers `npm test -- --watch`). It's remembered in your own config, never in the repository, and a rule never covers chained or redirected commands (`;`, `&&`, `|`, `>`, `$( )`). `/permissions` lists and revokes them.
247
+
248
+ ## Cost and speed
249
+
250
+ Set a faster, cheaper model for sub-agents, which do most of the reading in research and exploration:
251
+
252
+ ```bash
253
+ leto config set subagentModel claude-haiku-5-5
254
+ ```
255
+
256
+ `leto doctor` checks Node, your provider and key, the model, the browser, MCP servers and skills.
257
+
258
+ Shortcuts: Esc Esc rewinds (or clears what you typed), Ctrl+R searches your earlier messages, Ctrl+O shows a tool's full output, Ctrl+V attaches the image on the clipboard (macOS), and a bell (plus a notification after a minute) tells you when a long task finishes.
259
+
260
+ ## Skills
261
+
262
+ A skill is a folder with a `SKILL.md`: a name, a one-line description of when to use it, and the steps to follow. Scripts and templates can sit next to it. leto only puts the descriptions in context and loads a skill's instructions when a task matches, so you can keep many of them.
263
+
264
+ ```markdown
265
+ ---
266
+ name: release
267
+ description: Cut a release: bump the version, update the changelog, tag and publish.
268
+ ---
269
+
270
+ 1. Run the tests.
271
+ 2. Bump the version in package.json …
272
+ ```
273
+
274
+ Skills live in `~/.leto/skills/<name>/` (everywhere) or `.leto/skills/<name>/` (one project). Skills in `~/.claude/skills` and `.claude/skills` work too. Run one directly as `/<name>`, or use `/skills` to browse, run or create them. A project's own skills need the folder to be trusted first.
275
+
276
+ ## Browser, search and research
277
+
278
+ - **`web_search`** finds pages and **`web_fetch`** reads them. Search uses DuckDuckGo with no setup; set `TAVILY_API_KEY` or `BRAVE_SEARCH_API_KEY` to use those APIs instead.
279
+ - **`browser`** drives a real Chrome in its own profile (never your everyday one): open pages, read them, click, type, press keys, scroll, and take screenshots that the model looks at. It asks before clicking, typing or opening pages. It uses Chrome, Edge, Brave or Chromium if one is installed; otherwise run `leto browser install` to download Chrome for Testing (about 150 MB) into `~/.leto/browser`. Set `LETO_BROWSER_HEADFUL=1` to watch it in a window.
280
+ - **Images:** the model can open image files itself (`read_file` on a PNG returns the image), as well as images you attach.
281
+ - **`/research <question>`** plans sub-questions, researches them in parallel with sub-agents, follows up on gaps, and writes a report with numbered citations to `research/<topic>.md`.
282
+
283
+ ## Long sessions
284
+
285
+ Sessions can run for hours. When the history nears the context window, older turns are summarized automatically (at 80%; you get a heads-up at 65%), and `/compact <what to keep>` lets you steer the summary. Context use is measured from the API's own token counts, not guessed. The task list is saved with the session and comes back on resume, and every session can be reopened with `/resume`.
286
+
287
+ On Claude models that support it (Fable, Opus 5.5 and Opus 5), Claude summarizes older context itself on the server once a conversation passes 150K input tokens, which keeps the prompt cache and its earlier reasoning intact. Set `compactTokens` to change the point, or `serverCompaction off` to have leto do it. Other models use leto's own compaction.
288
+
289
+ Rate limits, overloaded servers and dropped connections are retried with backoff (honoring `Retry-After`), and the conversation is only saved once a response is complete, so a retry never leaves a half-written turn. If leto is closed or crashes mid-turn, resuming says so and `/continue` picks the work back up.
290
+
291
+ ## Your own model
292
+
293
+ leto works with any OpenAI-compatible API (`leto setup` → Custom). For models whose function calling is missing or unreliable:
294
+
295
+ - **Text tool calls are understood.** If the model writes a tool call in its reply instead of using the API's tool-call field (`<tool_call>{…}</tool_call>`, `<function=name>{…}</function>`, `<invoke name="…">`, or a JSON block), leto runs it anyway and hides the markup.
296
+ - **Broken arguments are repaired**: trailing commas, single quotes, unquoted keys, Python `True`/`None`, and JSON cut off part-way.
297
+ - **Text tool mode** (`leto config set toolMode text`, or `LETO_TOOL_MODE=text`) doesn't send the API's `tools` field at all: the tools are described in the system prompt, calls are parsed from replies, and results come back as plain messages. Use it for models that were never trained on function calling.
298
+
299
+ ## Evals
300
+
301
+ `leto eval` measures a model on real coding tasks inside this harness: the number to watch while you train and tune.
302
+
303
+ ```bash
304
+ leto eval core -m claude-haiku-5-5 # the bundled suite: 24 real tasks
305
+ leto eval init my-evals # an example suite with 3 tasks
306
+ leto eval my-evals -m your-model -j 8 -n 3 # 8 at a time, 3 runs per task
307
+ leto eval compare before.json after.json
308
+ ```
309
+
310
+ A suite is a JSON file of tasks. Each task gives the starting code (inline `files`, a local folder, or a git `repo` + `commit`), an optional `setup` command, the `prompt`, and a `check` command (exit code 0 = pass). Every run gets a fresh copy, leto works on it with `--yolo`, then the check decides. You get the pass rate, cost, tokens, tool calls and time per task, saved as JSON; `compare` shows which tasks got better or worse between two runs (say, two checkpoints of your model). `--tool-mode text` evaluates text tool calling.
311
+
312
+ ## SDK and scripting
313
+
314
+ Use leto from your own code:
315
+
316
+ ```js
317
+ import { query, run } from '@mumbrane/leto';
318
+
319
+ for await (const ev of query({ prompt: 'fix the failing test', permissionMode: 'acceptEdits', checkCommand: 'npm test' })) {
320
+ if (ev.type === 'text') process.stdout.write(ev.text);
321
+ if (ev.type === 'tool_start') console.log(`\n[${ev.tool}] ${ev.summary}`);
322
+ if (ev.type === 'result') console.log(`\n${ev.ok ? 'done' : ev.error} · $${ev.cost_usd}`);
323
+ }
324
+
325
+ const result = await run('summarize src/', { provider: 'anthropic', apiKey: process.env.ANTHROPIC_API_KEY });
326
+ ```
327
+
328
+ Options include `cwd`, `provider`, `model`, `apiKey`, `baseUrl`, `permissionMode` (`deny`, `ask` with a `canUseTool` callback, `acceptEdits`, `plan`, `yolo`), `allowedTools`, `sandbox`, `checkCommand`, `toolMode`, `maxCost`, `resume` and `signal`. From the shell, `leto -p --stream-json "…"` prints the same events as JSON lines, and `-p --json` prints just the result.
329
+
330
+ For an app that keeps a session open, `leto serve` runs one session driven over stdin and stdout, one JSON object per line each way. Send `{"type":"send","text":"…"}` to start a turn, `interrupt`, `set_mode` (`ask`, `acceptEdits`, `plan`, `yolo`) or `set_model`. Events are the `--stream-json` ones plus `ready`, `permission_request` and `question`; answer those with `{"type":"permission","id":"p1","answer":"yes|always|no"}` or `{"type":"answer","id":"q1","answer":"…"}`. Every turn ends with a `result`, and closing stdin ends the session. `--mode` sets the starting mode and `-r <id>` resumes a session. The Leto desktop app runs its Code sessions this way; the protocol is described at the top of `src/serve.js`.
331
+
332
+ ## GitHub Actions
333
+
334
+ `leto ci init` adds `.github/workflows/leto.yml`. Add an `LETO_API_KEY` repository secret (and optionally `LETO_PROVIDER`, `LETO_MODEL`), push, and comment `@leto fix the flaky login test` on an issue or pull request: leto does the work, pushes a branch, opens a PR (or updates the PR you commented on) and replies with a summary. Only people with write access can trigger it, and the comment is never pasted into a shell command.
335
+
336
+ ## Undo
337
+
338
+ Before leto writes or edits a file, it saves the original. `/undo` reverts the last turn's changes; with several turns it lets you pick how far back to go. Checkpoints are stored with the session, so undo still works after `leto -c`. Changes made by shell commands (`bash`) aren't tracked, so use git for those.
339
+
340
+ ## MCP servers
341
+
342
+ Connect any [Model Context Protocol](https://modelcontextprotocol.io) server, local or remote:
343
+
344
+ ```bash
345
+ leto mcp add github -- npx -y @modelcontextprotocol/server-github
346
+ leto mcp add docs --url https://example.com/mcp
347
+ leto mcp # check they connect and list their tools
348
+ ```
349
+
350
+ Servers live in `~/.leto/mcp.json` using the standard `mcpServers` format, so configs from other tools work as-is. Add API keys under `"env"` (local servers) or `"headers"` (remote ones); `${VAR}` reads from your environment. A project can ship servers in `.mcp.json` or `.leto/mcp.json`; leto asks before trusting a folder's servers the first time. MCP tools ask permission before running unless the server marks them read-only.
351
+
352
+ ## Background jobs
353
+
354
+ ```bash
355
+ leto bg "audit the dependencies for known vulnerabilities and write a report to AUDIT.md" --allow write_file
356
+ leto jobs # list jobs
357
+ leto jobs log job-3fa2c1 -f # follow one
358
+ leto jobs stop job-3fa2c1
359
+ ```
360
+
361
+ Jobs keep running after you close the terminal. With no flags they can read and search but not change anything; `--allow` lets specific tools through and `--yolo` allows everything. Each job has a session, so `leto -r <session>` continues the conversation afterwards. Inside a session, `/bg <task>` starts one with the same permissions you've granted so far.
362
+
363
+ ## Hooks
364
+
365
+ Run your own commands at points in the agent's work, in `~/.leto/config.json` (or `.leto/settings.json` in a project, which asks before first use):
366
+
367
+ ```json
368
+ {
369
+ "hooks": {
370
+ "PreToolUse": [{ "matcher": "bash", "command": "./scripts/check-command.sh" }],
371
+ "PostToolUse": [{ "matcher": "edit_file|write_file", "command": "npx prettier --write \"$LETO_FILE\"" }],
372
+ "UserPromptSubmit": [{ "command": "git status --short" }],
373
+ "Stop": [{ "command": "say done" }]
374
+ }
375
+ }
376
+ ```
377
+
378
+ Each hook gets the event as JSON on stdin and `LETO_EVENT`, `LETO_TOOL` and `LETO_FILE` in its environment. A `PreToolUse` hook that exits with code 2 blocks the tool, and its stderr is shown to the model as the reason. `UserPromptSubmit` output is added to your message as context.
379
+
380
+ ## Project instructions
381
+
382
+ Put a `LETO.md` (or `AGENTS.md`) in your repo to tell the agent how your project works: build commands, conventions, things to avoid. Leto reads these files from the current directory and its parents, plus `~/.leto/LETO.md` for global instructions.
383
+
384
+ ## Sessions
385
+
386
+ Every session is an append-only event log at `~/.leto/sessions/<id>.jsonl`, written to disk as each event happens. If leto crashes or the terminal closes, `leto -c` picks up where you left off. Unfinished tool calls are marked as interrupted, so the conversation stays valid. When the history nears the context window (`contextWindow`, default 128000 tokens), older turns are summarized automatically.
387
+
388
+ ## Development
389
+
390
+ ```bash
391
+ npm test # end-to-end tests against a mock model server
392
+ node test/mock-server.js 8765 # run the mock server locally
393
+ LETO_BASE_URL=http://localhost:8765/v1 node bin/leto.js
394
+ ```
395
+
396
+ Leto is also importable as a library: `import { Agent, Session, TOOLS } from '@mumbrane/leto'`.
package/bin/leto.js ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+ import '../src/legacy.js';
3
+ import { main } from '../src/cli.js';
4
+
5
+ main(process.argv.slice(2)).catch((err) => {
6
+ console.error(`leto: ${err?.message ?? err}`);
7
+ process.exit(1);
8
+ });