Apps
Chat
# AI Chat — AI Chat Panel
A draw-based AI chat panel with markdown rendering, multi-provider support (Anthropic, DeepSeek, OpenAI, Ollama), MCP tool integration, and project-aware system prompts.
## Key Bindings
### Input Line
| Key | Action |
|-----|--------|
| `Enter` | Send message (queues it while a turn is running) |
| `Backspace` | Delete character before cursor (or delete selection) |
| `Delete` | Delete character after cursor (or delete selection) |
| `Ctrl+Backspace` / `Alt+Backspace` | Delete word backward |
| `Left` / `Right` | Move cursor left/right (clears selection) |
| `Home` | Move cursor to start of line |
| `End` | Move cursor to end of line |
| `Ctrl+Left` | Move to previous word boundary |
| `Ctrl+Right` | Move to next word boundary |
| `Shift+Left` / `Shift+Right` | Extend selection left/right by character |
| `Shift+Home` | Extend selection to line start |
| `Ctrl+A` | Select all |
| `Ctrl+C` | Copy selection, or the whole input when nothing is selected |
| `Ctrl+V` | Paste from clipboard |
| `Ctrl+X` | Stop the running turn |
| `Escape` | Stop the running turn, close dropdowns, or clear selection |
| `Shift+Tab` | Cycle operation modes (Build → Plan → Speculate) |
### Chat dock (Sessions tab)
| Key / input | Action |
|-----|--------|
| Click a row | Load that session's transcript into the chat area |
| Wheel over the list | Walk the list (one session per notch) and show it |
| `Up` / `Down` / `PgUp` / `PgDn` / `Home` / `End` | Same, while the dock holds keyboard focus |
| `j` / `k` | Same (vim style) |
| `Escape` | Hand keyboard focus back to the chat input |
| `Ctrl+B d` | Toggle the dock (workspace prefix command) |
## Operation Modes
Every session runs in one of three modes, shown as a colored badge in the
status bar and selectable from the Mode menu, the app pie
(Mode sub-pie), `Shift+Tab`, or slash commands:
| Mode | Behavior | Tools |
|------|----------|-------|
| Build | Normal operation — investigate and implement changes. | All tools. |
| Plan | Read-only investigation; the assistant produces a concrete, actionable plan (steps, files, risks) and tells you to switch to Build to execute it. | Read/search/grep/git/web tools. Mutating tools, shell, subagents, and `@rpc` app tools are blocked (read-only exceptions such as the editor context readers stay available). |
| Speculate | Read-only brainstorm — explores ideas, hypotheses, and alternatives, clearly separating verified facts (`file:line`) from conjecture. | Same read-only tool set as Plan. |
Slash commands: `/build`, `/plan`, `/speculate`, and `/mode [name]`
(no argument shows the current mode). The mode is per session:
switching sessions restores that session's mode, and new sessions start
in the mode you were using. Switching is refused while a turn is running
(stop it first with Escape/`/cancel`) so the in-flight prompt and tools
can't disagree with the badge. In Plan/Speculate the assistant's tool
roster (Actions → Tool Roster) shows exactly the reduced set it is sent.
## Chat dock (Projects / Sessions / Config)
The panel's dock on the right edge has three tabs, Projects first:
- Projects — the project list and project management actions.
- Sessions — the saved-session list for the active project.
- Config — context policy, platform notes, context files, skill
actions, and chat options.
Click `Projects`, `Sessions`, or `Config` in the tab bar to switch. The dock
title is Chat. The dock opens on the Projects tab.
The Projects tab lists every project with its session count and marks the
active one. Clicking a project switches to it and opens its Sessions tab.
Below the list are New project, Rename project, Delete project, Set Deft
root, and Project Context to Editor. The top Project menu is gone; project
switching and management live here.
The Sessions tab shows the active project plus the session count
(`ui-refactor · Sessions (12)`; a `◆` marks dock keyboard focus) and a list
with one row per session, newest first.
Interacting with the Sessions list switches the chat area:
- Click a row — that session's transcript loads into the chat area and
keyboard focus returns to the chat input.
- Scroll over the list — one session per wheel notch (a 3-row terminal
notch must not skip conversations), same as clicking the neighbouring
row.
- Arrow keys / PgUp / PgDn / Home / End / `j` / `k` — while the dock
holds keyboard focus (click it once; `Escape` hands focus back).
The highlighted row always mirrors the session the chat area is showing, so
a refused switch (that session is open in another chat instance) leaves the
list pointing at the conversation actually on screen.
The dock opens with the panel unless `chat/sessions-dock` is `false`.
Toggle it at runtime with Actions → Chat Dock (`[on]` shows the current
state), open the Config tab directly with Actions → Chat Config, or use
the workspace prefix command Ctrl+B d; the config app edits the same key
and the dock follows immediately.
The Config tab is the canonical project-configuration surface:
- context mode (`Deft reference only`, `Selected files only`,
`Legacy auto docs`)
- platform notes checkboxes (`Linux` is on by default; Windows and macOS
can be added per project)
- context-file checkboxes (preload on/off), Add file/docs/Remove file,
and Set file note
- skill implement/reflection/export/delete actions
- session git-commit permission plus branch/latest-commit info
- auto-reflect toggle
Click a checkbox row to toggle it, or use arrows plus Enter/Space while the
dock has keyboard focus. Wheel scrolls the tab.
## Chat projects
A chat project is a logical work area inside one Deft workspace. It owns
many sessions plus a set of context files selected for the task at hand.
Chat projects live in `.deft/meta.db` alongside sessions and the semantic
index. Every session belongs to exactly one project; the Chat dock's
Sessions tab shows only the active project's sessions.
Project switching and management live in the dock's Projects tab.
Project context configuration lives in the Config tab (context mode,
platforms, files, notes). The separate Skills menu holds reflection and
skill-library actions (see Learned project skills below).
Projects also expose slash commands:
```text
/project show the active project
/project list list projects and session counts
/project use <name|id> switch projects
/project new <name> create a project rooted at the current workspace
/project add <path> register a context file
/project remove <path> unregister a context file
/project files list registered files and preload state
/project docs <mode> set language / custom / inherit
/project platforms list selected platform notes
/project platform <name> toggle linux / windows / macos
/reflect learn project skills from this session
/skills show the learned-skill index
/implement <skill> create a Build session that implements a skill
````
### Context modes
The point of a chat project is to make automatic context selective. The
default mode is `language`:
| Mode | Automatic context |
|------|-------------------|
| `language` (default) | The Deft language/semantics reference (`:chat/deft-reference-path`, default `deft/AGENTS.md`) plus selected platform notes. Workspace and component AGENTS.md docs are not loaded unless selected. |
| `custom` | No automatic AGENTS.md context; selected platform notes and registered files only. |
| `inherit` | Legacy `:chat/project-docs` behavior (`core` / `all` / `off`). |
Registered files have two roles:
- preloaded — contents are appended to every request, under
`:chat/project-context-max-chars` (default 120000, shared with the Deft
reference).
- reference — listed in the prompt manifest and readable through the
project tools, but not sent automatically.
Selected platform notes are preloaded from `deft/platform/<platform>.md`
before general files. Linux is the default; Windows and macOS can be toggled
in the Config tab. This keeps the basic Deft language reference free of
host-specific build/port details.
Use the Config tab's Add docs… action to include only the component docs
relevant to the current host/task (for example `ui/AGENTS.md`) instead of
every workspace component's build instructions. The full Deft reference
stays available for syntax and semantics; lower-frequency guidance remains
discoverable through `list-project-docs` / `read-project-doc`.
### Prior sessions as context
When a session belongs to a project, its system prompt lists a small index of
recent sibling sessions (titles only, cap `:chat/project-session-index`,
default 8). Their transcripts are not sent automatically. The model can
look them up when earlier project discussion is relevant:
- `list-chat-project-sessions` — recent sessions with message counts and a
short first-question preview
- `search-chat-project-sessions` — search user/assistant messages across the
project
- `read-chat-project-session` — page through one session's transcript
The prompt explicitly tells the model not to read earlier sessions unless the
current request needs that history.
### Learned project skills
Skills are the project's procedural memory: reusable playbooks learned
from earlier sessions (when to use, ordered procedure, pitfalls, verification).
They are on-demand — the system prompt carries only a name + description index;
the model calls `read-chat-project-skill` before starting a task one covers.
- Skills → Implement Skill… or `/implement <skill>` turns a learned
skill into a new Build-mode session. After confirmation, the session gets
the full skill body plus an implementation brief and starts working.
`:chat/skill-implement-autostart false` creates the session with the prompt
in the input instead of starting it immediately.
- Implementation sessions are titled `Implement: <skill>` and linked back to
the skill; skill lists/tools show the latest implementation session.
- `/reflect` and Skills → Reflect on Session review the current
conversation and save durable lessons.
- With `:chat/skill-review true` (default), the chat automatically reflects
every `:chat/skill-review-turns` completed turns (default 6). Set it to
`false` to keep reflection manual.
- Skills → Project Skills to Editor exports the full library;
Skills → Delete Skill… removes one.
- The model can also create/update skills with `write-chat-project-skill`
and remove obsolete ones with `delete-chat-project-skill` (blocked in
Plan/Speculate modes).
The reviewer follows Hermes-style skill discipline: lessons, not logs. It
skips narration, dates, issue/PR numbers, secrets, ephemeral paths, and
anything already covered by project context files. A skill body is capped by
`:chat/skill-max-chars` (default 24000).
## Session git commits
Each session has an Allow git commits toggle in the Config tab's
Session section. It is off by default and does not affect other sessions.
When enabled, the model gets a `git-commit` tool. Commits are never automatic:
the model must call the tool, ordinarily because the user asked it to commit.
- The first commit lazily creates a branch named
`chat/<session-id>-<title-slug>` from the current `HEAD`.
- The prefix is configurable with `:chat/git-branch-prefix` (default `chat`).
- `git_base_branch` / `git_base_sha` record where the session branch started.
- If the session branch exists but another branch is checked out and the
worktree is clean, the tool switches to the session branch automatically.
- If the worktree has uncommitted changes, it refuses rather than moving
unrelated changes between branches.
- Commits are recorded in `chat_session_commits` with SHA, branch, message,
and file/line counts. The Config tab shows the latest commit, the session
export includes the history, and `list-session-commits` exposes it to the
model.
- The tool never pushes, amends, forces, or bypasses hooks. It stages only
explicit paths or tracked modifications (`git add -u`); it never uses
`git add -A`.
- Toggling commits off does not delete the branch or its history.
The per-session setting starts from `:chat/git-commits` (default `false`).
## Multiple Instances
Chat sessions are project history (stored in `.deft/meta.db`), so every
instance sees the same projects and sessions. Each running instance owns the
session it is showing: when a second instance starts while the newest session
in the active project is already in use, it opens a fresh session instead of
attaching to that conversation (two views writing the same session would
silently interleave their turns). Selecting a session that another live
instance has open is refused with a status-bar message. Ownership is released
on exit and expires automatically after a crash, so a single instance still
resumes the last session normally.
## Stopping & Queueing Turns
While the assistant is working (status bar shows `Thinking…`, `Waiting…`, or
`Using tools…`), the input stays usable:
- Enter queues the message instead of sending it. The status bar shows
the queue depth (`N queued`); queued messages are sent in order, one per
turn, as soon as the current turn ends.
- Stop (the status-bar button), Escape, or Ctrl+X terminates
the running turn and returns control to the input. The in-flight request
still completes in the background, but its reply is discarded; the
partial reasoning and a `[stopped by user]` note are saved with the turn,
and queued messages are sent next.
- `/cancel` (or `/c`) is the command-line equivalent of Stop.
- `/clear-queue` (or `/cq`) drops every queued message without
stopping the turn.
## Inline Thinking
Reasoning and tool traces render directly in the transcript, above the
answer, in a dimmed colour (line prefix `▎ `). While a turn runs you see
the model's reasoning, each `🔧 tool(...)` call, and status notes such as
`Wrapping up…`.
When the turn completes, the block collapses to one dimmed line:
```
▎ Thinking · 1234 chars · Ctrl+T to expand
````
Ctrl+T expands or collapses the last assistant turn's reasoning inline.
The full reasoning is also saved with the session, so reopening the session
keeps the summary line. Themes can override the colour with
`:chat :thinking-fg`.
## Images
Attach local images to the next message (DeepSeek Flash / OpenAI-compatible
vision models):
- `/image <path>` (or `/img <path>`) stages an image. Repeat to attach
more than one.
- `/images` lists staged images.
- `/clear-images` (or `/ci`) drops them.
Press Enter to send the message with the image(s). Images render inline in
the transcript and are sent as OpenAI `image_url` content blocks. DeepSeek
Pro/reasoner do not accept images; use `deepseek-flash`.
The model also has a `view-image` tool for inspecting an image file on
disk (screenshots, diagrams, OCR, chart reading) without attaching it to
the user message.
## Transcript
Your questions render as a highlighted band (`**You►** …`), so each one is
easy to spot in a long conversation. The band is a tint of the theme's chat
`:user-fg`; set `:chat :question-bg` in a theme to override the color, or
use markdown `:line-rules` to style other line prefixes the same way.
## Transcript Selection
Select conversation text in the transcript viewer, then copy it:
- Mouse drag across lines selects a range; Shift+click extends
from the last anchor (click a line, Shift+click another — or the same
line twice — to select it alone). A plain click just repositions.
- Shift+Up / Shift+Down extend the selection by a line,
Shift+PgUp / Shift+PgDn by a page, Shift+Home / Shift+End to
the edges. These work even while typing in the input; the view scrolls
to follow the selection.
- Ctrl+C copies the active transcript selection (falls back to the
input's own Ctrl+C behaviour when nothing is selected).
- Escape clears the selection.
## Providers
Configure via `state~cfg` or set `ANTHROPIC_API_KEY`, `DEEPSEEK_API_KEY`, `OPENAI_API_KEY` environment variables. Supports Anthropic, DeepSeek, OpenAI, and Ollama.
## Pie menu
Hold the pie trigger (Super by default; `ui/pie-trigger` selects `:f1`,
`:ctrl-space`, or `:off`) to open the workspace pie, then move into the hub
to descend into chat's ring. Providers, Models, and Mode are
sub-pies: selecting one drills in (Enter, or release the trigger and press
it again), so switching provider + model — or mode — takes two flicks from
the hub. Sub-pie slices
show a `>` next to their key hint, the hub (`Back`) walks back up, and the
remaining slices run the session and action commands from the menu bar.
## Timeouts
`:chat/timeout-ms` (default `900000` = 15 minutes, clamped 5s..1h) is the
per-request AI HTTP timeout — generous enough for thinking/reasoning
models to finish a long answer. Each AI request uses its own HTTP client,
so stale keep-alive connections can't hang a call until the deadline; if a
request does hit the timeout, the error message reports the elapsed time
and the configured limit.
Long turns are also bounded only when configured so a normal task can
keep going like an opencode session:
- `:chat/max-steps` (default 0 = unlimited) limits model requests in
one turn. Set a positive value to force a wrap-up summary after that
many steps.
- `:chat/turn-timeout-ms` (default 0 = unlimited) limits wall-clock
time for one turn. Individual requests still use `:chat/timeout-ms`.
- `:chat/max-continues` (default 8) limits auto-continuations when the
model hits its output cap.
- `:chat/max-answer-chars` (default 262144) caps the visible answer size.
- `:chat/context-tokens` (default 262144) caps prompt history; compaction
preserves the current request and the active tool loop.
- `:chat/tool-result-max-chars` (default 16000) caps a single tool result.
If a positive step/time budget is reached, the chat injects a wrap-up
instruction and makes one final no-tools request, so you get a summary of
what was done and what remains instead of an endless loop.
`:chat/request-retries` (default 2) retries transient timeouts/429/5xx
responses.
## Project instructions
A chat project's context mode decides what is preloaded automatically:
| Mode | Preloaded |
|------|-----------|
| `language` (default) | the Deft language/semantics reference only (`:chat/deft-reference-path`, default `deft/AGENTS.md`) |
| `custom` | nothing automatic; only the project's registered files |
| `inherit` | the legacy `:chat/project-docs` scan (below) |
For `language` and `custom`, use the dock Config tab's Add docs… to
register just the component or package `AGENTS.md` files relevant to the
task, and its file checkboxes to toggle preload/reference state. The Config
tab also controls the selected platform notes. `:chat/project-context-max-chars`
(default 120000) caps the Deft reference plus platform notes and all
preloaded files.
The legacy `:chat/project-docs` values apply only in `inherit` mode (or when
no project is attached):
| Value | Preloaded |
|-------|-----------|
| `"core"` | cwd instructions + root + `deft/AGENTS.md` + the containing component |
| `"all"` | every workspace component (`deft`, `ui`, `wasi`, `app-server`, `pldeft`, `control`, `distro`) |
| `"off"` | only the cwd `AGENTS.md` / copilot instructions |
`:chat/project-docs-max-chars` (default 400000) caps the legacy total.
Additional guidance is available on demand through the `list-project-docs`
and `read-project-doc` tools — use them before editing `ui/`, `wasi/`,
`app-server/`, a package, or a component whose `AGENTS.md` is not part of the
selected set. The Automate menu additionally appends the `AGENTS.md` of each
running app whose @rpc tools are enabled.
## Tools
The assistant sees three tool sources, merged per request (in Plan and
Speculate modes this set is reduced — see Operation Modes above):
- MCP tools (`deft/stdext/mcp_tools`) — the curated built-in set
(help lookup, source reading, file writing, …). Always available
in-process. The HTTP MCP server for external clients (VS Code,
Copilot, Goose) is opt-in via `:chat/mcp-server` (default `false`).
App control tools (editor, sheet, …) are deliberately not part of
this always-on set.
- @rpc tools (`deft/stdext/rpc_tools`) — methods of the apps you opt
in, addressed as `runtime__method` (e.g. `editor__cmd-open-file`).
Nothing is exposed by default; enable apps in `:chat/rpc-tools`:
:chat/rpc-tools %{ :include @{"editor" "diff"} :exclude @{} }
An app that marks methods `@ai true` (next to `@rpc true`) exposes only
that curated subset — the editor marks open/save/edit/context commands
and hides cursor motion, selection, and clipboard commands from the
model. Apps without marks expose every `@rpc` method.
- Project tools (`deft/chat/project_tools`) — access to the active chat
project: `list-chat-project-files`, `read-chat-project-file`,
`list-chat-project-sessions`, `search-chat-project-sessions`,
`read-chat-project-session`, `list-chat-project-skills`,
`read-chat-project-skill`, `write-chat-project-skill`,
`delete-chat-project-skill`, `list-session-commits`, and — only when the
session allows commits — `git-commit`. File reads are restricted to
registered files under the project's Deft root and capped by
`:chat/project-file-max-bytes` (default 2 MiB). Session tools never include
private reasoning or tool-call internals. Skill writes and `git-commit` are
blocked in Plan/Speculate modes.
### Web and images
- `web-search` — DeepSeek's live Search API. Supports operators such as
`site:`, `-site:`, `"exact phrase"`, `lang:`, `after:` and `before:`;
returns ranked title/URL/summary results (and page content on request).
- `web-fetch` — DeepSeek's Fetch API first (clean Markdown), falling back
to a direct HTTP GET and the native HTML parser.
- `view-image` — ask DeepSeek Flash to inspect a local image (screenshot,
diagram, photo, OCR) and answer a prompt. Images attached with `/image`
go directly in the user message instead.
### Shell commands and background jobs
- `run-command` runs a command with a bounded timeout
(`:chat/command-timeout-ms`, default 300s, max 600s) and returns its
output. It must not be used for servers or long builds.
- `start-command` launches a command in the background and returns a job
id. `job-status <id>`, `job-output <id> [lines]`, and `job-kill <id>`
let the assistant poll output and stop it. Jobs are the recommended path
for long-running work, matching the async tool model in agent harnesses.
- `run-tests` runs a `.dft` test file with the standalone `deft` CLI and a
5-minute timeout.
- `read-source` pages large files: call it with `offset`/`limit` instead of
dumping a whole file into context.
- `search-codebase`, `grep-codebase`, and `find-files` return at most a few
hundred matches and add a `showing first N of M` note. That is normal:
narrow the pattern or path for the rest rather than re-running the same
query.
Tool failures are returned to the model as `Tool error: …` strings, so it
can correct the arguments or report a blocker instead of ending the turn.
Control characters are stripped and results are head+tail truncated to
`:chat/tool-result-max-chars` before they enter the conversation.
Both keys live in the config registry (`packages/chat/config.dft` defaults)
and can be edited from the config app.
## Automate menu
The Automate menu lists every currently-instanced app that exposes
`@rpc` methods. Selecting an app toggles its automation:
- enables/disables that app in `:chat/rpc-tools` (the `[on]` marker shows
the current state) — only the app's `@ai`-marked methods are exposed, so
the editor contributes a focused open/save/edit/context surface rather
than all of its commands, and
- appends the app package's `AGENTS.md` (or legacy `agent.md`) to the
assistant's system prompt, so it knows how to drive the app (e.g.
`editor/AGENTS.md` documents the editor tools and their coordinate
conventions; `sheet/AGENTS.md` documents cell formulas, ranges and the
`prog.dft` program file). Guidance is injected only while the app is
actually running (it has live `@rpc` methods), so the prompt never
advertises tools that aren't in the request.
"Refresh app list" rescans for apps launched since the menu was built.
See `packages/editor/AGENTS.md` and `packages/sheet/AGENTS.md` for
reference guidance files; add an `AGENTS.md` to any package to give the
assistant app-specific instructions.
## Tool Roster
Actions → Tool Roster opens a filterable list of every tool available
to the current session — the MCP registry entries plus the `@rpc` tools
of the apps enabled in the Automate menu — each shown as
`[source] name — description` (`[mcp]` / `[rpc]` prefixes mark where the
tool comes from). Type to filter (space-separated terms, case-insensitive),
arrow keys / PgUp / PgDn to scroll, Esc to close. The list is built from
the same merged schema the next request sends, so it always reflects the
live Automate toggles.
## Initial context
Actions → Initial Context to Editor writes the context a new chat
context starts with and opens it in the editor. Nothing in the transcript
shows this, because it is assembled per request rather than stored:
- the assembled system prompt — base instructions, the chat project's
context (selected files, preloaded bodies, and recent session index), the
Deft reference or legacy project docs depending on the project's context
mode, the `AGENTS.md` of every Automate-enabled app that is running, and
the operation-mode guidance,
- the project's context mode, Deft root, selected platforms/files,
learned-skill index, and sibling-session index, with character counts, and
- the tool roster sent with every request — each tool as
`` `name` (mcp|project|rpc) — description ``.
The prompt is rendered inside a code fence that outgrows any backtick run
in its own text, so preloaded `AGENTS.md` content keeps its formatting. The
document is written to `.deft/local/exports/<session>-context.md` (the same
folder as Actions → Open in Editor's conversation export) and opened
through the workspace `file-open` topic, so re-running the action overwrites
the previous dump. Use it to check what the model was actually told before
blaming an answer on the wrong instructions.