Rewrite the documentation and the agent instructions

Move the agent instructions from AGENTS.md to CLAUDE.md. AGENTS.md now
points to CLAUDE.md. The UI rules move to docs/ui-design.md. The version
and release policy moves to the new docs/releases.md.

Rewrite the README, the user guides, and the developer references.
Check each claim against the code. Remove old version history and
repeated warnings. Link to Gitea at git.knottywyvern.com instead of the
LAN address. Move the October 13 menu audit to the archive.
This commit is contained in:
Knotty Wyvern
2026-10-27 19:35:43 -07:00
parent d7a87795f5
commit 4240d7dad1
25 changed files with 2041 additions and 2017 deletions
+82 -22
View File
@@ -1,8 +1,22 @@
# Completion plugin API
This source update adds `api.completion`, capability version 1. It is optional in package API version 1.
[Plugin development](plugin-development.md) · [Plugin API](plugin-development.md#plugin-api)
Plugins must feature-detect it. The existing 0.1.7 installer does not contain this source update.
`api.completion` (`version: 1`) lets plugins show autocomplete in RuneStone editors and in their own text fields, and supply the suggestions.
`api.completion` is optional. Older hosts do not have it, and `transport` can be absent. Make sure that a member exists before you call it.
The types are in `src/lib/completion/contracts.ts`.
| Member | Contract |
| --- | --- |
| `registerInput(element, options)` | Add autocomplete to an `<input>` or `<textarea>`. Returns a handle. |
| `registerSurface(surface)` | Add autocomplete to a custom editor. Returns a handle. |
| `registerProvider(provider)` | Supply suggestions. Returns a cleanup function. |
| `invalidate()` | Dismiss all visible suggestions. |
| `transport(request, signal, onLine)` | Optional. Send a request to a local model server. |
The host adds the plugin ID as a prefix to field and provider IDs. Each field ID must be unique among the active fields.
The host disposes all registrations when the plugin stops.
## Register a field
@@ -18,40 +32,86 @@ if (completion?.version === 1) {
}
```
The host prefixes field IDs with the owning plugin ID and disposes registrations when the plugin stops. IDs must be unique per active owner.
`registerInput` options are `id`, `kind` (`"prose"` default, or `"code"`), and `sensitive`.
The host shows the suggestion in a box below the field. It treats inputs of types other than `text` and `search` as sensitive.
Inputs and text areas use a preview below the field. Custom editors use `registerSurface` with snapshot, preview, and insert callbacks.
| Key | Action |
| --- | --- |
| Tab | Accept the suggestion. |
| Escape | Dismiss the suggestion. |
| Ctrl+Alt+Space (Cmd+Alt+Space on macOS) | Request a suggestion now. |
| Ctrl+Alt+Right (Cmd+Alt+Right on macOS) | Accept the next word. |
Snapshots include document identity, revision, caret, selection, focus, composition, sensitivity, read-only state, and prose or code kind.
The RuneStone Markdown editor and code editor are also completion surfaces. They show the suggestion as faded italic text at the caret.
The host validates the snapshot before acceptance. Custom insert callbacks must make one undoable transaction and reject stale expected text.
### Custom editors
`registerSurface({ id, snapshot, preview, insert })` connects a custom editor.
- `snapshot()` returns the current state: `documentId`, `revision`, `text`, `caret`, `selectionEnd`, `focused`, `composing`, `sensitive`, `readOnly`, `kind`, and `language`.
- `preview(text)` shows a suggestion. `null` removes it.
- `insert(text, expected)` inserts the accepted text. Do it as one undoable edit. Return `false` when the editor state no longer matches `expected`.
The returned handle has `changed()`, `request()`, `accept(word?)`, `dismiss()`, and `dispose()`. Call `changed()` after each edit.
### When the host asks for a suggestion
The host asks only when all of these conditions are true:
- The field has focus, and no selection.
- The field is not read-only or sensitive, and no IME composition is in progress.
- The text before the caret contains more than spaces.
- For prose, the caret is not in a table row, a link target, or an HTML tag.
- For prose, the caret is not in inline code, a code fence, or front matter.
## Register a provider
`registerProvider` accepts an ID, delay, deadline, and an asynchronous completion function. Only one provider can be active in a window.
```javascript
const stop = api.completion.registerProvider({
id: "local",
delayMs: 200,
timeoutMs: 1000,
async complete(request, publish) {
const text = await suggest(request.prefix, request.suffix, request.signal);
return text;
}
});
```
The function receives bounded prefix and suffix text, document and surface identity, language, mode, and an abort signal.
Only one provider can be active in a window. A second registration throws an error.
It can publish partial text through its callback and return the final insertion. No candidate enters the document before acceptance.
| Field | Rule |
| --- | --- |
| `delayMs` | Wait after the last edit. Default 200, from 100 to 1,000 milliseconds. |
| `timeoutMs` | Time limit for an automatic request. Default 1,000, from 300 to 5,000 milliseconds. A manual request has 10 seconds. |
| `complete(request, publish)` | Returns the final text, or `null`. Call `publish(text)` to show partial text before the end. |
Call `invalidate()` when settings or reference context changes.
The request contains `surfaceId`, `documentId`, `revision`, `prefix`, `suffix`, `kind`, `language`, `manual`, and an abort `signal`.
`prefix` has at most 3,000 characters before the caret. `suffix` has at most 600 characters after the caret.
The host ignores a suggestion longer than 2,000 characters or one with control characters.
No text goes into the document until the user accepts it. Then the host makes sure that the document revision and the caret did not change.
Call `invalidate()` when the provider settings or its context change.
## Local transport
`transport(request, signal, onLine)` sends a bounded request through the desktop host. Each callback receives one response line.
`transport(request, signal, onLine)` sends one request to a model server on the same computer, through the desktop host.
It calls `onLine` once for each response line. It is not a general HTTP API.
Supported routes are `/v1/models`, `/v1/chat/completions`, `/api/tags`, and `/api/generate`.
| Item | Rule |
| --- | --- |
| `endpoint` | `http` or `https` on `127.0.0.1`, `[::1]`, or `localhost`, with path `/` or `/v1`. No credentials, query, or fragment. |
| `route` | `/v1/models`, `/v1/chat/completions`, `/api/tags`, or `/api/generate`. |
| `body` | Optional JSON text, at most 32 KiB. With a body, the host sends POST. Without one, it sends GET. |
| `timeoutMs` | Default 5,000, from 100 to 15,000 milliseconds. The connection limit is 2 seconds. |
| Response | At most 64 KiB for each line and 256 KiB in total. |
| Concurrent requests | At most 16 across all windows. |
Only explicit loopback addresses are allowed. Redirects and system proxies are disabled. Request bodies and responses have size limits.
The host does not follow redirects and does not use a system proxy. It sends no credentials.
Abort stops the display at once. A blocked network read can continue until the request timeout.
The transport supports no remote credentials in this version. It is not a general HTTP API.
## Trust
The host cancels display immediately. A blocked native read can continue until its bounded timeout.
Plugins keep full application access. This API does not add a permission sandbox.
The API does not include context sources, remote model servers, or credential storage.
## Current boundaries
Surface and provider APIs are available. Automatic context-source registration, remote adapters, and credential storage remain planned.
External plugins retain RuneStone's existing full-application trust level. This API does not add a permission sandbox.
See [the implementation](../src/lib/completion/contracts.ts), [host tests](../scripts/completion.spec.ts), and the [plugin trial guide](../../RuneStone_Local_Autocomplete/docs/trial-guide.md).
For tests, see `scripts/completion.spec.ts`. For a provider plugin, see the [Local Autocomplete trial guide](https://git.knottywyvern.com/kwyvern/RuneStone_LocalModel/src/branch/main/docs/trial-guide.md).