Turn and Prompt
$.turn ends the running turn.
$.prompt sends a prompt as a user turn and works with the prompt box.
The events follow a turn from start to end, and they cover the system prompt, the context blocks, and attachments.
Return { drop }, { deny }, or { text: null } from the right hook to stop or remove something.
Official pages: React to Events, Mods Reference. Source: the program (types-2.1.304.d.ts).
In a "Where it can be used" cell, "Run time" means in a hook, in a closure that a hook drew, or in a timer callback. It does not mean inside register.
Example
This hook trims the whitespace of every prompt before the model reads it.
on('prompt.submit', async ($, e, next) => next({ ...e, text: e.text.trim() }))
Members
| Item | Status | What it does | How it works | Where it can be used |
|---|---|---|---|---|
$. | Documented | Cancels the running model turn of the main loop. Running tools stop. No interruption marker appears. | (input) => Promise<void>. Use the id that its turn. gave this plugin. Rejects if turn is not the running turn's id. A hook may end its own turn. | Only for the running turn of the main loop. |
$. | Documented | Submits a prompt. It is the event prompt., the same call the engine makes for a typed prompt. It is a turn of its own, once the session is idle. | (input:. The model reads it as a user turn. Every hook but the calling one sees it. | Run time. |
$. | Documented | Returns the prompt box as it stands: the draft typed so far and the cursor offset. | () => Promise<Prompt. Never rejects. Gives { text: where no box is drawn, such as a - run. | Run time. |
$. | Documented | Returns one image or document of the prompt being submitted, by the id that e. lists. Gives its bytes as base64, 4 MiB a call. | (args:. Works only in a prompt. hook of a mod that managed settings install. Otherwise { deny }. | The prompt. hook of a mod that managed settings install. |
$. | Documented | Puts input. in the prompt box as the draft, by mode: replace (default), append, or insert at the cursor. | (input:. Gives is under a dialog or when headless. | Run time. |
$. | Documented | Proposes input. as the dim suggestion of the prompt box. Tab takes it. | (input:. Gives { is while the box has text or a turn runs. | Run time. |
$. | Documented | Returns the sections of the system prompt. It is the event prompt., the call the engine makes for every prompt it sends. | (input?:. Builds the sections without sending them. Example: (await $.. | Run time. |
Engine Events
| Item | Status | What it does | How it works | Where it can be used |
|---|---|---|---|---|
prompt. | Documented | Fires when a prompt is submitted, before the turn starts. next(e) runs the hooks beneath and the User settings hooks, then enters. | Input Prompt. A hook returns { text, context? } or { drop }, rewrites with next({ ..., or stops the prompt with { drop:. A guard that fails lets the prompt through. | on('prompt.. Also $.. |
prompt. | Documented | Fires when a text is about to go into the prompt box as the draft. next(e) writes it by e.. | Input Prompt. Result { is. mode is replace, append, or insert. Answer { is without next to keep the text out. | on('prompt.. Also $.. |
prompt. | Documented | Fires when a text is proposed as the dim suggestion: the engine's guess after a turn, or a plugin's $.. | Input Prompt. Result { is. Rewrite with next({ ..., or answer { is to drop it. | on('prompt.. Also $.. |
prompt. | Documented | Fires when the person edits the main prompt box: a key the editor took as an edit, or a paste. next(e) resolves the box the editor shows. | Input Prompt. Result { text, cursor }. A burst of keys is one edit. Answering without next consumes the keys. The docs give this hook a 50 millisecond budget. | on('prompt.. |
prompt. | Documented | Fires after the text of the main prompt box changed and no prompt. carried it: a recalled history entry, a clear, a plugin's fill. | Input Prompt. Result { text }. Observe only. One call for each batch of changes. | on('prompt.. |
prompt. | Documented | Fires as the person types in the main prompt box, for the token at the cursor. next(e) resolves to { suggestions }, rows for the typeahead. | Input Prompt. Your rows join below the engine's rows. Nothing waits on them. | on('prompt.. |
prompt. | Differs | Fires when the engine builds some named sections of the system prompt. next(e) resolves to { text } as core computed it. | Input Prompt. Result { text }, or null to leave the section out. The answer is cached until $.. Not every section goes through it: from 2.1.302 to 2.1.304 the engine builds the shared lean_ section without a prompt. call, so this hook does not see it. A prompt. hook sees it. See System Prompt. | on('prompt.. In tests: $. on the test engine (not on a hook's $). |
prompt. | Documented | Fires once for each conversation, when the engine computes the context blocks that its first user message carries. next(e) resolves to { blocks }. | Input Prompt. Append, drop, reorder, or rewrite blocks. The answer stands until $.. | on('prompt.. In tests: $. on the test engine (not on a hook's $). |
prompt. | Documented | Fires when the engine renders a system prompt. next(e) resolves to { sections }, each { id, text, scope }, in the order they are sent. | Input Prompt. Every shared section comes before every session section. A wrong order skips the hook. See System Prompt. | on('prompt.. Also $.. |
prompt. | Documented | Fires once for each message the engine adds for the model on its own (a reminder, a mode change, a mentioned file), as a request carries it. | Input Prompt. Result { text }, or { text: to leave the attachment out. The transcript keeps the engine's record. | on('prompt.. In tests: $. on the test engine (not on a hook's $). |
prompt. | Documented | Fires once for each path a prompt names after an @ (a directory aside), before the engine reads it. next(e) reads it and resolves { type }. | Input Prompt. Result { type, context? } or { deny }. No tool. is raised for this read. A guard that fails is skipped and the file is read. | on('prompt.. In tests: $. on the test engine (not on a hook's $). |
skill. | Documented | Fires when the engine expands a skill's prompt for the model (/, the Skill tool, a preload). next(e) resolves to { text }. | Input Skill. The text replaces what the model reads. A hook that fails passes through. | on('skill.. In tests: $. on the test engine (not on a hook's $). |
attribution. | Documented | Fires when the engine composes a git text that the model writes (kind: commit, pr, exemption, remedy). next(e) resolves to { text }. | Input Attribution. The text replaces what the model reads. A hook that fails passes through. | on('attribution.. In tests: $. on the test engine (not on a hook's $). |
turn. | Documented | Fires when a model turn begins, main's or a subagent's (e.), before its first model call. next(e) resolves to { turn. | Input Turn. Observe only. To act for the main loop alone, return next(e) first when e. is set. | on('turn.. In tests: $. on the test engine (not on a hook's $). |
turn. | Documented | Fires when the engine is about to send a model request of a turn. next(e) resolves to the whole response. | Input Turn. Result: the response (turn, index, answer, tool, stop, usage). It streams. next({ ... sends another model. | on('turn.. A streaming hook (async generator). |
turn. | Documented | Fires when a model turn has ended, where its duration is reported. next(e) resolves to { text }, the answer. e. says why. | Input Turn. A different text shows beneath the answer. The transcript is never rewritten. | on('turn.. In tests: $. on the test engine (not on a hook's $). |
Events Raised by These Calls
For each call, a hook above the caller returns next(e), { deny: reason }, or { value }.
| Item | Status | The argument | Input and value |
|---|---|---|---|
turn. | Documented | $. | Input { turn. Value void. |
prompt. | Documented | $. | Input No. Value Prompt. |
Related Pages
- Mod API Overview
- System Prompt
- Tool, Command, and Config
- Turn and Prompt Types (prompt, attachment, and model step types)