# Stdext Overview
stdext (`deft/stdext`) is the canonical Deft extension library — the
Deft-language counterpart to the native stdlib. Everything in stdext
is written in Deft and shipped as a versioned package, so a freshly
downloaded binary bootstraps itself with `deft init` (which fetches the
stdext build matching the compiled-in version).
The vocabulary is worth pinning down:
- stdlib — native, Zig-implemented functions compiled into the
binary (`fs/*`, `sqlite/*`, `tui/*`, `draw/*`, …).
- stdext — the Deft extension package: HTML/SQL templating blocks,
markdown rendering, syntax highlighters, themes, the plugin host, the
launcher, debug/REPL plumbing, the AI stack, and more.
TUI host and widget material lives in
Platform → TUI — this chapter documents the
stdext modules themselves and links back to the TUI pages where a module
is the Deft-language half of a host feature.
## Importing
Packages found under the prelude `:pkgs` roots are auto-mounted as
`owner/name`, so the canonical import is:
import "deft/stdext/html" as html import "deft/stdext/markdown" as md from "deft/stdext/async" import @{ await-all map-concurrently }
The bootstrap mount `stdext/...` (bare name) is still honoured in
preludes that predate the owner-prefixed mounts, and a bare package
import resolves to the default module — `import "deft/stdext/ai"` loads
`ai/ai.dft`.
## Package Layout
```
packages/stdext/
├── package.dft
└── src/
├── html.dft sql.dft markdown.dft meta.dft semantic.dft
├── async.dft crypto.dft logging.dft testing.dft types.dft
├── launcher.dft terminal.dft menu.dft deftlet.dft
├── theme.dft themes/ # theme files
├── syntax/ # deft / markdown / zig highlighters + registry
├── debug-client.dft debug-host.dft repl.dft repl-host.dft
├── mcp_tools.dft rpc_tools.dft plugin.dft
├── ai/ # provider protocol, registry, config, budget, subagents
├── kv/ # nested package → deft/kv
├── smtp/ # nested package → deft/smtp
├── imap/ # nested package → deft/imap
├── ffmpeg/ # nested package → deft/ffmpeg
└── package/ # nested package → deft/package (package-manager TUI)
````
The `src/` tree is the mount target: `deft/stdext/html` →
`<pkg>/src/html.dft`. Directories inside `src/` that carry both a
`package.dft` and their own `src/` are discovered by the runtime scanner
one level deep and mounted as their own top-level packages:
| Directory | Mount | Import |
|---|---|---|
| `src/kv/` | `deft/kv` | `import "deft/kv"` |
| `src/smtp/` | `deft/smtp` | `import "deft/smtp"` |
| `src/imap/` | `deft/imap` | `import "deft/imap"` |
| `src/ffmpeg/` | `deft/ffmpeg` | `import "deft/ffmpeg"` |
| `src/package/` | `deft/package` | `import "deft/package"` |
Dev checkouts shadow installed copies, and explicit prelude `:mounts`
entries always win. See
Packages for the manifest contract and
Prelude for `:pkgs` / `:mounts`.
## Modules
| Module | Import | What it does |
|---|---|---|
| HTML | `deft/stdext/html` | `[html …]` / `[codeblock …]` block handlers, escaping |
| SQL | `deft/stdext/sql` | `[sql …]` block handler, value escaping |
| Markdown | `deft/stdext/markdown` | Markdown renderer + layout engine for TUI viewers |
| Syntax | `deft/stdext/syntax/*` | Language highlighters + dispatch registry |
| Themes | `deft/stdext/theme` | Active-theme cache helpers, shipped theme files |
| Types | `deft/stdext/types` | `%Package`, capability, AI-provider, editor-extension schemas |
| Meta | `deft/stdext/meta` | Project metadata DB (`.deft/meta.db`) |
| Semantic | `deft/stdext/semantic` | Symbol index cache over the metadata DB |
| Async | `deft/stdext/async` | Future fan-out helpers |
| Crypto | `deft/stdext/crypto` | Package-pinned `crypto/*` aliases + key generators |
| Logging | `deft/stdext/logging` | Compile-time filtered log macros |
| Testing | `deft/stdext/testing` | Test discovery, skeletons, in-process runners |
| KV | `deft/kv` | Valkey/Redis client |
| Launcher | `deft/stdext/launcher` | App icon grid + launch/adopt |
| Deftlet | `deft/stdext/deftlet` | Panel-app module contract |
| Menu | `deft/stdext/menu` | `%MenuItem` shared type |
| Terminal | `deft/stdext/terminal` | PTY session wrapper + `Terminal` protocol |
| Find | `deft/stdext/find/find` | Project search library + panel helpers |
| Debugging | `deft/stdext/debug-*`, `repl*` | Debug client/host, isolated REPL runtimes |
| AI | `deft/stdext/ai*` | Provider protocol, registry, config, budget |
| AI Tools | `deft/stdext/{mcp,rpc}_tools`, `ai/subagent` | Tool surface exposed to LLMs |
| Plugin | `deft/stdext/plugin` | Generic tagged-package discovery + loading |
| Package Manager | `deft/package` | Package-manager TUI over native `pkg/*` |
| SMTP | `deft/smtp` | SMTP client + RFC 5322 message construction |
| IMAP | `deft/imap` | IMAP4rev1 client + MIME decoding |
| FFmpeg | `deft/ffmpeg` | Runtime-FFI video/audio playback for panels |
## Conventions
All modules follow the same Deft style rules used across the tree:
`X?` predicate suffixes, bracket calls, type-hinted parameters, and
`@doc` on public defs. Errors come back as `%Err{:message}` values from
I/O-facing calls rather than exceptions; `nil` is the common "not
available" signal (for example `meta/db-open` returning nil when SQLite
is unavailable).
## See Also
- TUI Overview — panels, hosts, apps
- Widgets and Protocols — the widget layer stdext apps build on
- App Platform — workspaces, `pub/*`, `@rpc`, config
- Packages — manifests, installs, mounts