# 7. The AI tab

The right panel is **Properties | Block | AI**. In the AI tab you describe a change in plain language and the AI makes it with **tools** — the editor's own operations: reading the outline, changing text, attributes, classes and styles, inserting blocks and fragments, moving and deleting, validating, measuring layout, searching media. The result goes through the normal save and validation and is indistinguishable in the document from a manual edit.

## 7.1 Availability and settings

| | |
|---|---|
| Needs | WordPress 7.0+ (the core AI Client), an AI provider connected under Settings → Connectors (OpenAI, Anthropic… with the provider plugin active), and **AI editing** switched on under Appearance → Jikji → AI. Otherwise the tab shows the reason and a link |
| Model | Appearance → Jikji → AI → **AI model**: a function-calling model of a connected provider. *Automatic* takes the first one. If the chosen model disappears, nothing is substituted — the tab says so |
| Limits | Output tokens per turn (4096), requests per minute per user (60 — one request in the builder is several model calls), tokens per day per user (500,000). The **Recent AI turns** table on the AI tab keeps model, tokens, duration and result per call — never the prompt text |
| Privacy | What you type and the parts of the page the AI reads are sent to the connected provider (a notice says so the first time) |
| Cost (indicative) | On the development site with Anthropic Claude Sonnet: one request = 3–6 calls, 15,000–55,000 tokens, 5–18 s; a Generate-mode section was 9 calls, ~126,000 tokens, 52 s |

## 7.2 Using it

- Type an instruction (Enter sends, Shift+Enter is a new line). The selected element goes along as a chip (✕ removes it). Quick actions: polish copy, accessibility check, add a section. Modes: **Edit** (default) and **Generate** (designs and builds sections or a page from a brief: plan → self-review → implement → verify).
- **Attachments**: 📎, or drop/paste a file into the input (screenshots). Images (png, jpeg, gif, webp) and PDFs are sent as files the model sees; text files (.txt, .md, .html, .css, .json, .csv…) go into the message. 2 MB per file (large images are scaled down), 4 files per message, 5 MB per request. If the model's own info does not list image or PDF input you get a warning but can still send; a model that really refuses returns a provider error. Attachments go only with that message; later turns keep their names.
- **Applying**: edits appear on the canvas as they happen; a finished turn becomes **one history entry** (`AI: <summary>`). Undo/Redo work as usual; the answer's *Undo this turn* is enabled only while that turn's result is the current state. During a turn the canvas, panels and save are locked; **Stop** cancels without committing.
- **Caps**: 24 model calls per turn; running out of output tokens, a content filter or an oversized conversation stop the turn — if it changed something you are asked *Apply / Discard* the changes so far. (With the Anthropic ≥ 1.0.5 and OpenAI ≥ 1.2.0 provider plugins a turn that hits the output-token cap returns an error and nothing of that call is applied; raise the cap or ask for a smaller change.)
- **History**: the conversation stays in the browser tab per post (the last 20 finished turns) and survives a reload, though *Undo this turn* is then disabled; **Clear chat** empties it. A save records the summaries of the AI turns in that version as the revision note ("AI: …" in the History panel).

By default the AI **never creates or changes server-code constructs** — `j:` bindings, Code, Shortcode, SVG and block-island markup — it can only move or delete such nodes. Three settings open that up.

## 7.3 Code and blocks, external resources, limits

Appearance → Jikji → AI has three options; their defaults keep the behaviour described above (code off, fetch off, limits on).

**AI may write code and blocks** (`ai.code`). Adds eleven tools: Code blocks (`insert_code`, `set_code` — HTML/CSS/JS the server outputs as written, **never PHP**: anything containing `<?` is refused), WordPress block islands (`list_wp_blocks`, `get_wp_block_schema`, `insert_wp_block`, `set_wp_block` — only blocks registered on this site, markup parsed and re-serialized by the block editor, blocks that cannot render from attributes alone need markup), Shortcode blocks (`list_shortcodes`, `insert_shortcode`, `set_shortcode` — exactly one registered tag) and SVG blocks (`insert_svg`, `set_svg` — the sanitizer's output). `get_source` reads any of them. **A turn that wrote code is never applied automatically**: when it ends, *Review the code this turn wrote* lists every item (tool, node, preview, *Show* for the full source) and asks **Apply / Discard**. Nothing runs on the server before Apply — a WordPress block the AI wrote is a canvas placeholder ("rendered after the AI turn is applied") until then, and Apply re-checks that the setting is still on. Applied turns are labelled `AI (code): …` in history and revision notes and get a "wrote code" chip. Blocks and shortcodes execute their registered PHP when rendered, like ones you add yourself — check in Preview before publishing.

**AI may fetch external resources** (`ai.fetch`). Declares `fetch_url` (GET or POST) and tells the model it may fetch. The **server** fetches with `wp_safe_remote_get/post` — no cookies or credentials (like an anonymous visitor), 1 MB and 15 s limits, up to 3 redirects followed by Jikji itself and checked **per hop**: `http`/`https`, ports 80/443, the site's policy filter, and **every A/AAAA address of the host must be public** (private, loopback, link-local, CGNAT and reserved ranges are refused; redirects to another host are refused), with the connection pinned to the checked address. Responses are reduced to text (HTML → title, description, body text, links, image URLs; JSON validated; other types → kind and size) and read 4 KB at a time. **Approval rule**: a GET to a URL **you typed in the chat** runs directly; anything else — a URL the AI composed, an added query, every POST — shows *Allow this request?* with the method, the full URL and the body and asks **Allow once / Deny** (one request only). 8 fetches per turn, 30 per user per minute while limits apply; the turns table records `fetch` rows (host only). Fetched content is marked untrusted data and is never followed as instructions — the only effective actions, writing code and sending requests, go through the review and approval prompts above.

*Proxy environments.* If the site sends HTTP through a proxy (`WP_PROXY_HOST` or `http_proxy`/`https_proxy`/`ALL_PROXY`), the proxy would resolve the destination itself and defeat the address pinning, so fetching is refused before transport (`jikji_ai_fetch_unavailable`; the settings screen explains). An operator can opt in with the `jikji_ai_fetch_transport` filter returning `'direct'` (AI fetches bypass the proxy, environment proxies included) or `'tunnel'` (the proxy is asked to CONNECT to the checked address; a proxy that blocks port-80 CONNECT fails). A site allowlist is the `jikji_ai_fetch_allowed( $allowed, $url, $method, $user_id )` filter — it can only refuse.

**Apply usage limits** (`ai.limits`). Switched off, the per-minute, per-day and per-minute-fetch limits apply to nobody; usage is still counted and logged and the tab's usage line reads "Used today: N tokens · no limit". The output-token cap goes to its maximum (65,536): on the settings screen the three inputs lock and unlock as soon as the checkbox changes, and the value entered while off is kept and comes back when limits are switched on. The 24-calls-per-turn cap stays.

Indicative cost of the opened tools (development site, Anthropic Claude Opus, 2026-10-01): reading an external page and writing a Text block 4 calls / 33,000 tokens / 13 s; a Latest Posts block 4 / 46,000 / 19 s; a Code block 2 / 22,000 / 9 s; a shortcode 4 / 44,000 / 18 s; an SVG 4 / 45,000 / 18 s; a denied approval 2 / 22,000 / 9 s — about 212,000 tokens for the six turns.

## 7.4 For scripts and agents

`POST /jikji/v1/ai/turn` is the gateway of the editor conversation, not a general model proxy: tool execution lives in the browser, it spends the user's call and token limits, and there is no reason for a coding agent to call it. `POST /jikji/v1/ai/fetch` is likewise the `fetch_url` tool's endpoint and is closed by the site setting. Agents use `wp jikji` and the content REST routes ([For AI coding agents](11-agents.md)).
