Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.
The Shell and AI — Talk to the Whole System
The shell (/shell) is one input that reaches everything: instant record commands, global search, and an AI that operates the server through the same MCP tools any agent uses — with your key, your model choice, and your permissions.
flowchart TD
U["You type"] --> D{"prefix?"}
D -->|"$ . ^"| REC["Create note / task / link<br/>(records API, your session)"]
D -->|"~"| SRCH["GET /api/search"]
D -->|"/"| CMD["Built-ins: /help /key /model /tools /voice"]
D -->|"anything else"| CHAT["POST /api/ai/chat"]
CHAT --> PROV["AI provider<br/>(your stored key)"]
PROV -->|"tool calls"| MCP["MCP tool subset<br/>dispatched with YOUR credentials"]
MCP --> PERM["Permission engine + audit"]
PERM --> PROV
PROV --> REPLY["Reply + tool log + token usage + cost"]
Setup: Your Key, Your Model
AI features use each user's own provider key — the server stores it write-only and calls providers on your behalf. Key material never appears in any response, record, or backup. Two providers are supported today (object_ai.SUPPORTED_SERVICES): anthropic and openai — no Gemini, no local/on-device inference. An openai key, once stored, also covers the cloud voice paths above (POST /api/tts with engine: "openai", POST /api/stt) — one key, no separate signup for voice.
In the shell:
/key anthropic sk-ant-... store a key (masked, never logged)
/keys which services have keys
/model anthropic:claude-haiku-5-5 pick a model (service:model)
/model openai:gpt-5-mini or the other provider
Or over HTTP: PUT /identity/users/{you}/service-keys with your session (see the HTTP API contract).
Tool Subsets: Small Context, Configurable Power
The AI is offered a named subset of the MCP tool catalog, not the whole thing. Small subsets keep the context small enough for fast, inexpensive models — and the subset is your safety dial:
/tools global_search,list_records,get_record,create_record conversation mode
/tools global_search,list_objects,get_object_source,create_object,update_object_source,execute_object builder mode
Every tool call the model makes is dispatched through the server's own routing with your credentials: the AI can do exactly what you could do yourself — row filters, field redaction, and the audit trail apply. An AI acting for a user is never more powerful than the user.
Output Budget and Effort Per Mode
A subset that includes create_object or update_object_source is builder mode; anything else is conversation mode. The mode picks two defaults:
| Conversation | Builder | |
|---|---|---|
max_tokens | 4096 | 8192 (16384 when streaming) |
| effort | low (DBBASIC_AI_EFFORT) | high (DBBASIC_AI_BUILDER_EFFORT) |
A request may ask for its own max_tokens (capped at 8192, or 16384 when streaming, since a streamed answer starts arriving at once instead of holding one response open) and its own effort (low, medium, high, xhigh, max). DBBASIC_AI_MAX_TOKENS_CAP sets an operator cap that bounds both paths. Output tokens include the model's thinking, so the old default of 1024 left little room for an answer, and none for a builder answer that writes a whole object.
Effort is sent as output_config: {"effort": ...} only to models that accept it: current Claude ids from 4.6 on (claude-haiku-5-5, claude-sonnet-5, claude-opus-4-8, ...). claude-haiku-4-5, any id the server cannot read as a current Claude id (including dated snapshot ids), and OpenAI models get no effort field; they use their own default. The server never sends temperature, top_p, top_k or a thinking budget: Claude Haiku 5.5 thinks adaptively by default and refuses those.
Strict Tool Schemas
On the same models (Claude 4.6+), every offered tool whose input schema can be closed is sent with "strict": true, so the provider guarantees the call's input matches the schema. Closing means every object lists its properties, sets additionalProperties: false and has a required list; the server makes that copy (the MCP catalog is not changed), moving any default into the description because the server's tool routing applies defaults itself.
Five tools take a free-form object and so stay non-strict: create_record (record), update_record (changes), list_records (where), execute_object (payload) and update_schema (schema). Closing those would refuse the very fields the tools exist to carry. Every other tool in the catalog -- including create_object, update_object_source, global_search, get_record and read_page -- can be strict. OpenAI tool definitions are unchanged.
The provider accepts at most 20 strict tools in one request (a live call with 25 was refused with HTTP 400). A tool subset with more closable tools than that keeps strict on the ones that change something (create_*, update_*, delete_*, rollback_*, setup_*, start_*, stop_*) first, then the others in the order offered; the rest are sent unmarked. The shell's usual subsets are far below the limit.
Conversation Memory
The shell logs every exchange to the shell_commands collection (your history is just records — searchable and owner-scoped). A new browser session replays recent history and sends prior AI turns back with each message, so conversations resume. The server stays stateless about chats: POST /api/ai/chat accepts a history list, and what to remember is the client's choice.
Streaming
POST /api/ai/chat with "stream": true answers in server-sent events, so the shell and Talk show the reply as it is written instead of after the whole turn. It is the same turn, not a second implementation:
- Every refusal that can happen before the provider is called (flag,
session, origin, body, model, tool names, attachments, missing key) runs first and stays a plain JSON error with its real status.
- The turn runs in a worker thread through the same
object_ai.run_chat
loop. Anthropic is asked for stream: true; its events are parsed as they arrive and each text delta is forwarded to the browser as a text event.
- When a round asks for tools, each tool's input is assembled from its
streamed fragments and parsed only once its block has stopped. Input that does not parse into a JSON object is never dispatched: the model gets an error result (is_error) and may retry. Valid calls dispatch through the server's own routing with the caller's credentials, exactly as on the JSON path, and each is reported as a tool_call event. Then the next round streams.
- When the turn ends, it is priced and recorded by the same code as a JSON
turn, and the final done event carries the same object the JSON endpoint returns. A failure mid-turn ends with an error event instead (and, as on the JSON path, records nothing).
Text events are a preview; done.reply is the answer (a refusal can arrive after some words streamed). A browser that disconnects mid-turn does not stop the turn: the provider is being paid either way, so it finishes, runs its tools and is recorded; only the writes to the closed connection are dropped. OpenAI turns are not streamed from OpenAI: each round's text arrives as one text event when the round finishes.
The shell and Talk pages ask for a stream: the shell fills the pending line and Talk fills the caption as the words arrive, then both render the final done reply exactly as before (Talk speaks only that final reply, never a partial one). A response that is not text/event-stream -- a refusal made before the provider call, or a proxy that answers JSON -- is read as the JSON reply it always was.
When a Turn Stops Early
The server reads each response's stop_reason before its content, and the chat response carries it (stop_reason) so a surface can tell the cases apart:
refusal: the model declined. Whatever content came with it is
not an answer and is not shown; reply says the model declined and names the provider's category and explanation, which also come back as refusal: {category, explanation}. No tool from that response runs.
max_tokens: the answer hit the output limit.replyis the
partial text followed by a note that it was cut off, and cut_off is true. A tool call in the same response is not run: its input may stop mid-argument. (OpenAI's length is treated the same way.)
pause_turn: the provider paused a long turn. The paused content
is sent back unchanged and the turn resumes, counting as a round. If the round limit comes first, reply says so and truncated is true.
A refused or cut-off turn still spent tokens, so its usage and cost are recorded like any other.
Prompt Caching
Anthropic requests mark their stable prefix for prompt caching. A request renders as tools, then system, then messages, and a cached entry is a prefix of that, so the breakpoints (cache_control: {"type": "ephemeral"}) go on the parts that are identical turn after turn: the last tool definition and the system text. Text that changes every turn -- the local time, the last web page read -- goes in the request's context field instead, which is sent as a second system block after the cached one. A timestamp inside system would make every request's prefix unique: each turn would pay to write a cache entry nobody reads.
The simpler top-level cache_control (cache up to the last block) is not used on purpose: a turn's last block is the new user message, and the next turn's history carries that message without its context, so what one turn wrote is not what the next turn sends.
A prefix shorter than the model's minimum cacheable length is not cached (no error; the cache token counts are 0). OpenAI requests are unchanged: system and context are joined into its one system message, and OpenAI caches on its own.
Cost Recording
Every chat turn is priced server-side, not by the caller. POST /api/ai/chat reads token counts straight from the provider's own response, looks up the model's price in the ai_prices collection (editable records, never a hardcoded table -- so a price change is a data edit, not a deploy), and computes the cost in integer cents: tokens * per_million_cents // 1_000_000, input and output added separately, no float division on money. The result -- tokens_in, tokens_out, tokens_cache_read, tokens_cache_write, cost_cents, model, provider -- lands in the ai_usage collection, written by the chat handler itself with the caller's user id as actor, so the record can't be skipped or forged the way a client-written log could be. The same numbers come back in the chat response's usage object (input_tokens, output_tokens, cache_read_input_tokens, cache_creation_input_tokens, largest_prompt_tokens, cost_cents) so a surface can show them immediately.
Cached prompt tokens (see Prompt Caching above) are reported by Anthropic beside input_tokens, not inside it, and are billed at their own rates: ai_prices has cache_read_per_million_cents and cache_write_per_million_cents for them. A blank cache rate means unknown, not free.
The cost is null -- tokens still recorded -- when the turn cannot be priced honestly:
- no
ai_pricesrow matches the model; - the turn read or wrote prompt cache and the matching cache rate is blank;
- the row sets
price_max_prompt_tokensand one request's whole prompt
(uncached + cache read + cache write) went over it.
The last rule exists for models whose rate rises above a prompt size. Claude Haiku 5.5 costs $0.10 in / $0.50 out per million tokens for prompts up to 100K tokens and $0.50 / $2.50 beyond. A price row holds one rate, so the seeded Haiku 5.5 row covers prompts up to 100,000 tokens and a turn with a bigger request is left unpriced rather than recorded at a fifth of its real cost. Pricing the higher tier would need a second rate on the row and per-request (not per-turn) cost math; it is not implemented.
Seeded rates (cents per million tokens):
| Model | In | Out | Cache read | Cache write | Priced up to |
|---|---|---|---|---|---|
claude-haiku-5-5 | 10 | 50 | 1* | 13* | 100,000 |
claude-sonnet-5-5 | 200 | 1000 | 10 | 250* | |
claude-opus-5-5 | 400 | 2000 | 20 | 500* |
The cache-read rates for Sonnet 5.5 and Opus 5.5 are published prices. The starred rates are derived, not published: Anthropic prices cache reads at 0.05x the input rate and 5-minute cache writes at 1.25x, so Haiku 5.5 reads come to 0.5 cents per million and writes to 12.5, and the seed rounds every derived rate UP to a whole cent (1 and 13). The recorded cost is informational -- these turns run on the user's own key -- and must never under-report, so a slightly high number beats a missing one. An operator who has the exact published rate edits the row; the most recent effective_date wins.
The older rows (claude-haiku-4-5, claude-sonnet-5, claude-opus-4-8, gpt-5-mini, gpt-5) stay, with blank cache rates: for them a turn that touches the cache is recorded with a null cost. Upgrading app-settings on an existing server merges the new rows by id and leaves rows already there untouched.
Coding Without Coding
With builder-mode tools, the AI can create and edit live objects:
make an object called site_dice that renders a page rolling two dice
The model writes the source, calls create_object, and the page is live at /dice immediately — objects load per execution, so there is no deploy step between the AI writing code and the code serving traffic. Edits use update_object_source; every version lands in source history with rollback; and create/update responses report the methods the code actually exposes, so the model can self-correct.
Object writes ride the admin gate (an admin-role session today), and source writes require DBBASIC_ENABLE_SOURCE_WRITES=true — the same boundaries that govern humans.
Voice
The shell doubles as a push-to-talk terminal. Speech in and speech out each have two paths: browser-native (free, on-device, always available if the browser supports it) and cloud (a real per-user OpenAI key, real cost, but "not on device" — works on browsers/hardware the native APIs don't cover, and sounds noticeably better than the local synthesis engines).
- Speech in, browser path: the mic button uses
window.SpeechRecognition
(or the webkit prefix); interim words show live in the input, and the final transcript submits through the same form-submit path a typed line does — no separate send code. Neither Chrome nor Safari expose the API outside a secure context (https:// or localhost), and without it the button simply stays hidden. This is the default (talk_stt_engine: "browser").
- Speech in, cloud path: when
talk_stt_engineis"openai", the mic
becomes push-to-talk instead of continuous listening — tap to start a real MediaRecorder capture, tap again to stop and upload the clip to POST /api/stt, which transcribes it via the caller's own stored OpenAI key and returns text. No wake word, no VAD silence endpoint: raw audio has no equivalent to SpeechRecognition's live partial-result signal, so there is no live signal to drive one. See POST /api/stt below.
- Speech out, browser path:
speechSynthesis.speak— free, on-device,
no server round-trip.
- Speech out, cloud path: when
talk_tts_engineis"openai", assistant
replies (markdown and code fences stripped first — only prose is spoken, never tool-call noise) POST to POST /api/tts with "engine": "openai" and play the returned audio/mpeg, via the caller's own stored OpenAI key. If the request fails for any reason, the browser's own speechSynthesis says the line instead, so voice mode never goes silent because of a server-side gap.
/voice, /voice on, /voice off toggle voice mode inline (mirrors /model); the setting persists on shell_preferences.voice_enabled and is honored on page load like ai_model and tools. talk_tts_engine and talk_stt_engine (both default to the free/local path) live on the same shell_preferences record — the Talk page (/talk) additionally has a single in-page toggle that flips both together, since "cloud voice" is one combined mode to remember, not two settings.
POST /api/tts
POST /api/tts
Authorization: Bearer <session-token> (or the session cookie)
{"text": "one note matches", "voice": "en-us", "engine": "local"}
Response: audio bytes (audio/wav for engine: "local", audio/mpeg for engine: "openai"), or the usual {"status": "error", "error"} JSON shape on failure. Requires DBBASIC_ENABLE_TTS=true (off by default) and a signed-in session — same posture as /api/ai/chat. text is capped at 800 characters (413 beyond that). engine is optional, "local" or "openai", defaulting to "local" — the two paths never silently fall back to each other; a caller who asked for cloud quality and hits a provider error sees that error.
engine: "local" (default): discovered at call time, first match wins: espeak-ng, espeak, then macOS say (development convenience — say writes AIFF and the also-stock afconvert turns it into WAV; if afconvert isn't present the endpoint returns 501 rather than growing a bespoke audio pipeline). No engine on PATH at all is a 503 with a clear message.
engine: "openai": calls OpenAI's TTS API (gpt-4o-mini-tts by default) using the caller's own key, stored via PUT /identity/users/{user_id}/service-keys (service: "openai") — no key stored is a 400 with the exact PUT to fix it. A provider-side failure (bad key, rate limit) is a 502. DBBASIC_TTS_CLOUD_TIMEOUT_SECONDS bounds the outbound call (default 30s).
Successful audio is cached at data/tts-cache/{sha256(engine|voice|text[|model])}.wav regardless of engine — a repeat of the same line is a cache read, not a re-synthesis. There's no eviction in v1; operators who want a bound should prune that directory on their own schedule.
POST /api/stt
POST /api/stt
Authorization: Bearer <session-token> (or the session cookie)
Content-Type: audio/webm
<raw audio bytes>
Response: {"status": "ok", "text": "..."}, or the usual {"status": "error", "error"} shape. The request body is the raw audio bytes themselves (whatever MediaRecorder produced client-side — typically audio/webm on Chrome/Firefox, audio/mp4-ish on Safari), not JSON; the Content-Type header says what format it is. Requires DBBASIC_ENABLE_STT=true (off by default, unlike TTS which many operators turn on immediately — STT costs money on every utterance, not just the occasional reply) and a signed-in session. Capped at 10MB per clip (413 beyond that).
Unlike TTS, there is no local-engine path here at all — every call goes to OpenAI's transcription API (gpt-4o-mini-transcribe by default), using the caller's own stored key exactly like the TTS cloud path. No key stored is a 400; a provider-side failure is a 502. DBBASIC_STT_TIMEOUT_SECONDS bounds the outbound call (default 30s). Nothing is persisted server-side beyond the ordinary ai_usage/cost accounting every provider call gets — the audio itself is uploaded, transcribed, and discarded within the request.
Reading the Web
The AI can fetch and read a real web page — the lynx/w3m move for an AI + voice consumer: strip a URL down to {title, text, links}, links numbered in document order so they double as speakable navigation targets ("open link three"). It is a real, tested loop: read a page, get a short spoken summary with numbered links, say "open link one," and it resolves against the previous turn's link list, fetches that page, and summarizes it too — follow a chain of pages by voice alone.
The read_page tool is offered like any other MCP tool (add it to a /tools subset to use it) and calls object_reader.py server-side, gated behind DBBASIC_ENABLE_READER (off by default). Fetching is SSRF-hardened: every hostname — the original and every redirect hop — is resolved and checked before the socket opens, refusing loopback/link-local/private ranges and failing closed on any resolution ambiguity; http/https only, a small redirect cap, and hard timeout/size limits. HTML is stripped with html.parser (no regex scraping), never a headless browser — JS-rendered pages, images, and login-walled pages are out of scope by design.
A fetched page can also be shown on screen as a {"kind": "reader", "url": ...} view block (title + body text + the numbered link list), fetched client-side through POST /api/read — the same flag and SSRF posture apply.
The Instant Commands
| Input | Effect |
|---|---|
$ pay the hosting bill | quick note |
. fix the header | quick task |
^https://example.com docs | save a link |
~flywheel | global search across collections |
/help | list commands |
These never touch the AI — they are one permission-checked record write each, which is why they feel instant.
For Agents
Everything above is equally available to AI agents connecting over MCP (POST /api/mcp) with their own identities and labeled sessions, and to headless callers hitting POST /api/ai/chat directly. One surface, many kinds of operator.