Context, tools, approval, and feedback: the machinery that lets an AI assistant work inside a LaTeX
project.
Inside the AI harness
One illustrative request
YOUR WORKSPACE
Y
Fix the error in this paragraph.
.tex
Active document
main.tex · selected paragraph
✓
≡
Allowed context
Editor + project file access
✓
✳
AI harness
Context · controls · feedback
LocalOllamaCloud
PROJECT TOOLS
01
get_active_document
Read the source
✓
02
edit_selection
Apply an approved edit
✓
03
compile
Return build diagnostics
✓
Ask mode · approval before editing
Tool results return to the model
↳
Available tools follow your access settings.
Source read. The model can inspect the error.
Proposed change:
\sectoin
\section
Example edit accepted. Compile result:
success
.
“The command is corrected and the document compiles.”
05 / 05
The model can answer—or continue.
Your request brings the context.
The model asks to read.
An edit goes through approval.
Tools act and return evidence.
The model can answer—or continue.
The harness supplies allowed context, checks tool availability, and returns tool results to the model.
This example shows an accepted edit in Ask mode. Actual tool sequences vary; a final answer, error,
cancellation, or step limit ends the loop.
01 / Context and capabilities
Start with the access you allow.
Settings control access to chat history, the current editor, project files, the bibliography, and
researcher profile. Available tools also depend on the selected workspace tab and whether a document
or selection is open.
02 / Model routing
One loop, several runtimes.
Local GGUF and Ollama requests use the desktop bridge. Cloud requests use the configured provider.
Local GGUF inference runs through node-llama-cpp; cloud mode supports Anthropic and OpenAI-compatible
endpoints. With a cloud provider, supplied context is sent to that provider.
03 / Actions and feedback
Tools return evidence to the conversation.
A tool call becomes a real read, edit, check, or compile action. Ask mode pauses proposed text edits
for approval. Each tool result goes back to the model, which can continue or answer. Cancellation and
the configured step budget bound the loop.
Inside the implementation
Based on the desktop source reviewed at revision
4059a3d
. File paths are relative to the application repository.
src/features/ai/aiAgent.tsRuns the tool loop and stopping rules
src/features/ai/aiTools.tsDefines tools, capabilities, and edit proposals
src/features/ai/useAiAgent.tsBuilds context and handles approval
src/features/ai/aiClient.tsRoutes local, Ollama, and cloud requests
AI source package and model catalog
Public source
The retired AI subdomain now lives here.
The retired AI source package is now served inside this route, so desktop builds can read the
manifest, catalog, source files, scripts, and package metadata from
latexdo.org/research/ai/
.
Source root:
/research/ai/
Sync manifest
Maps the public AI files into the desktop app before builds.