o4 -p) or evals. In o4 0.4.23, a session that runs in
the o4 daemon gets the lsp tool, with language servers of
its own that start from its window’s environment and stop with the session,
but it doesn’t get the format tool.
Language servers
Language servers work without setup for four languages, as long as the server is installed and on yourPATH:
o4 starts a server the first time the model asks about a file with one of its
extensions, and keeps it running for the rest of the session. It starts a
separate copy of the server for each extension, so
.ts and .tsx files get
two typescript-language-server processes. The server runs in the directory
you started o4 in. If a server isn’t installed, the model’s request fails
with an error and the session carries on.
What the model can do
The model uses thelsp tool, which takes an operation, a file path
(filePath), and a 1-based line and character position:
incomingCalls and outgoingCalls send a file position, but the protocol
expects the item that prepareCallHierarchy returns, so servers can reject
them.
In the default ask permission mode, the first lsp call in a session asks
for your approval. After you approve, o4 doesn’t ask again for the rest of the
session. See Permissions.
For text and symbol search that doesn’t need a language server, see
Code intelligence.
Configure language servers
To use other servers, or change the command for a built-in one, addlsp_servers to ~/.o4/settings.json. Each entry has a name you choose, the
command, optional arguments, and the file extensions it handles (without the
dot):
command and at least one extension. o4 ignores
entries without them. Extensions match without regard to case, and an
extension written with a leading dot, such as ".rs", never matches. If two
entries claim the same extension, the entry whose name sorts first
alphabetically wins. If every entry is invalid, the model gets no working
servers; o4 doesn’t fall back to the built-in list.
o4 reads these settings when it starts. Restart o4 after you change them.
Formatters
o4 has no built-in formatters. When you configure at least one, the model gets aformat tool that formats one file at a time with the formatter set for
that file’s extension.
Add formatters to ~/.o4/settings.json:
args and then the file path, so the
formatter must rewrite the file in place. That’s why the prettier example
passes --write. Like language servers, an entry needs a non-empty command
and at least one extension, and when two entries claim the same extension,
the name that sorts first wins.
How a formatter runs:
- The file must already exist inside the folders o4 may access, and the tool formats one file per call.
- It runs through the same sandbox as the model’s shell commands. See Sandbox.
- It has 2 minutes to finish unless the model sets a shorter or longer
timeout, in milliseconds. Its standard input is empty, so a formatter that waits for input ends instead of hanging. - If it exits with a non-zero code, the model gets the formatter’s output as
the error. On success the model gets
Formatted <file> with <name>, not the formatter’s output. - In the default
askpermission mode, the firstformatcall in a session asks for your approval. After you approve, o4 doesn’t ask again for the rest of the session.
Project settings
You can also putlsp_servers and formatters in .o4/settings.json in a
project, so everyone who works on it gets the same setup. o4 reads that file
from the directory you start o4 in. Project entries are added to your user
entries, and a project entry replaces a user entry with the same name. A
project lsp_servers entry also replaces the built-in list, as it does in
your own file.
Because these settings choose programs to run, o4 reads a project’s
.o4/settings.json only after you trust the workspace. See
Workspace trust.
See your setup
Run/config tools to open the Tools tab of the settings. It has three
rows: Open tools browser, Open LSP browser and Formatters.
Open LSP browser opens the LSP browser; /lsp opens it directly. It
lists the servers named in lsp_servers, or the four built-in servers when
you haven’t configured any, each with its file extensions. A server running
in this session is marked ● and running. A ○ server is ready and starts
when the model asks about a matching file. A ✗ server can’t run, and the
row says why: no command configured, no file extensions configured, or
that its command is not on PATH. The browser also lists the entries o4
ignores, so you can find them. Type to filter by name, command or extension.
In o4 0.4.23, the browser marks only the servers the window started itself
as running, so in a session that runs in the daemon, its servers show as
ready even while they run.
Press Enter on a server to see its command, file types, and whether it
comes from your settings or o4’s defaults. Show settings snippet shows
the lsp_servers entry for that server, ready to copy into
~/.o4/settings.json. Esc goes back one screen, and from the list returns
to the Tools tab, or closes the browser when you opened it with /lsp.
Formatters shows the first three formatters by name as
name: command args [extensions], then +N more, and N invalid for
entries o4 ignores because they have no command or no extensions, or
not configured. Press Enter on the row to see the full value.
The browser and the row are read-only. Edit settings.json to change them.
See Configuration files for where settings live.