Every named declaration in the file, 833 of them, verbatim and in the order Claude Code wrote them, 50 to a page. This is the page to land on from a signature: a verb that returns ToolCallResult links here, at whichever page it is on, and what you get is the declaration itself rather than a description of it.
The source is 22,468 lines of TypeScript mined from build 2.1.330. Anything longer than 12 lines is folded; click the line count to open it. To find a name on another page, search every symbol.
Names on this page, 151 to 200 of 833
HookInput type
#
line 6798
Added in 2.1.265
type HookInput = PreToolUseHookInput | PostToolUseHookInput | PostToolUseFailureHookInput | PostToolBatchHookInput | PermissionDeniedHookInput | NotificationHookInput | UserPromptSubmitHookInput | UserPromptExpansionHookInput | SessionStartHookInput | SessionEndHookInput | StopHookInput | StopFailureHookInput | SubagentStartHookInput | SubagentStopHookInput | PreCompactHookInput | PostCompactHookInput | PreModelSwitchHookInput | PostModelSwitchHookInput | PermissionRequestHookInput | SetupHookInput | TeammateIdleHookInput | TaskCreatedHookInput | TaskCompletedHookInput | ElicitationHookInput | ElicitationResultHookInput | ConfigChangeHookInput | InstructionsLoadedHookInput | WorktreeCreateHookInput | WorktreeRemoveHookInput | CwdChangedHookInput | FileChangedHookInput | DirectoryAddedHookInput | MessageDisplayHookInput;
HookOf type
#
line 6804
Added in 2.1.269
The hook event E takes: an async generator over its chunks for a streaming event (StreamingEventName), ($, e, next) => result otherwise.
export type HookOf<E extends EventName> = Events[E];
HooksModule type
#
line 6814
In the first published surface (2.1.259)
What a hooks module exports: register, and nothing the loader reads besides.
Each file of the module is at most 1 MiB, and the entry with every file it imports 8 MiB in all; past either it does not load. Splitting a file across static import declarations is the way past the first.
export type HooksModule = {
register: Register;
};
HookStream type
#
line 6826
Added in 2.1.269
What next(e) returns on a streaming event: the stream of everything beneath, chunk by chunk, whose return value is the result from beneath.
yield* next(e) forwards the chunks and evaluates to that result; a transforming hook reads for await (const chunk of stream) and then await stream.result. Each call runs what is beneath afresh.
export type HookStream<C, R> = AsyncGenerator<C, R> & {
/**
* Settles with what beneath returned once the stream has been read to
* its end; rejects if the stream is closed before that.
*/
readonly result: Promise<R>;
};
HttpBody type
#
line 6837
Added in 2.1.321
A request body: text, or bytes that are not valid UTF-8 as { base64 }.
type HttpBody = string | {
base64: string;
};
HttpCompress type
#
line 6844
Added in 2.1.321
The encoding the engine gives a request body beneath the hooks.
type HttpCompress = boolean | 'gzip' | 'deflate' | 'br' | 'zstd' | {
encoding: 'gzip' | 'deflate' | 'br' | 'zstd';
level?: number;
};
HttpInit type
#
line 6852
In the first published surface (2.1.259) · changed in 2.1.268, 2.1.277, 2.1.321
Options of $.http.fetch.
51 lines
export type HttpInit = {
/**
* `GET` (default), `POST`, ...
*/
method?: string;
/**
* Request headers.
*
* While `CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC` is set, a model request a
* hook edits keeps the credential behind a "[redacted]" value at its own URL
* and method; moved on its origin and still asking for it, it is refused.
*/
headers?: Record<string, string>;
/**
* The request body: text, or `{ base64 }` for bytes that are not UTF-8,
* which only an engine request carries.
*/
body?: HttpBody;
/**
* What the engine does to the body beneath the hooks, on an engine request
* alone.
*
* `body` is the plain body. Delete this and it leaves as written; set this
* and the engine gzips it. For exact bytes, delete this and write them with
* your own `content-encoding` header.
*
* @example
* next({ ...e, init: { ...e.init, compress: undefined } })
*/
compress?: HttpCompress;
/**
* The handle `$.session.authorize()` answered: the engine sets the
* session's credential header itself, only for a first-party host.
*
* It rides https only. While `CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC`
* is set, a request that carries it is refused, whichever plugin asks.
*/
auth?: string;
/**
* The absolute path of a Unix domain socket the request goes over instead
* of TCP (near 100 B at most): one per session, in a private directory.
*
* The URL still gives path, query and Host; redirects stay on it; no proxy;
* `https:` is TLS verified against the URL's host (always, once `auth`
* rides), so a credential reaches only its host. No relative path, no NUL.
*
* @example
* await $.http.fetch(url, { socketPath: `${runDirectory}/bridge.sock` })
*/
socketPath?: string;
};
HttpResponse type
#
line 6907
In the first published surface (2.1.259) · changed in 2.1.321
What $.http.fetch resolves with.
31 lines
export type HttpResponse = {
/**
* The HTTP status code.
*/
status: number;
/**
* True for a 2xx status.
*/
ok: boolean;
/**
* Response headers, lower-cased names.
*/
headers: Record<string, string>;
/**
* The body, as text: empty while `isStreaming` is set.
*/
text: string;
/**
* Set on what `next(e)` gives for an engine request: the body stays the
* engine's, streaming to its reader, and hooks read the status and headers.
*
* Pass it on, with other headers or status if you like, and the body goes
* on under them; answer without it and `text` is the body instead.
*/
isStreaming?: true;
/**
* Set beside `isStreaming`: which of the request's sends gave this answer.
* Pass it on, and that send's body is the one that goes on.
*/
sendIndex?: number;
};
ImageBlitArgs type
#
line 6950
Added in 2.1.277
A $.ui.blit argument swapping one of the caller's mounted keyed Images to its next picture; every call sends it, so a stream needs no generation.
The surface writes them with its frames, some sixty a second: byte and file sources fold to the last per frame; every shm source reaches the terminal (it unlinks each), and is denied while frames are not written.
await $.ui.blit({ requestId: 'browser', key: 'view',
source: { shm: '/tb-4', format: 'rgb', width: 1280, height: 720 } })
23 lines
export type ImageBlitArgs = {
/**
* The site the Image is drawn in, by the `requestId` this plugin draws it
* under.
*/
requestId: string;
/**
* The Image's `key` in that drawing.
*/
key: string;
/**
* The next picture (ImageSource): bytes, or a name the terminal reads.
*/
source: ImageSource;
/**
* Refused unless it is the mounted Image's width in cells. Absent, that.
*/
columns?: number;
/**
* Refused unless it is the mounted Image's height in cells. Absent, that.
*/
rows?: number;
};
ImageProps type
#
line 6990
Added in 2.1.275 · changed in 2.1.277
The props of Image, the terminal surface's picture leaf: pixels over a box of cells where the terminal can (kitty and Ghostty, or iTerm2 3.5 and later for png and rgba bytes under fullscreen rendering; inside tmux too, for bytes only, with tmux's allow-passthrough and focus-events on), the alt elsewhere.
A leaf: no children, hover or onPress; the cells are text, so the picture scrolls and clips as a word does. Drawn again with another source it is replaced in place; keyed, $.ui.blit swaps it at the frame rate.
const { bytes } = await $.fs.read('chart.png', { as: 'bytes' })
<Image source={{ png: bytes.toBase64() }} columns={40} rows={12} alt="p95" />
<Image key="view" source={{ shm: '/tb-7', format: 'rgb', width: 960,
height: 600 }} columns={80} rows={25} alt="the page" />
25 lines
export type ImageProps = {
/**
* The element's address within the drawing: what `$.ui.blit` names to swap.
*
* Unique among the Images of one tree; absent, only a redraw changes it.
*/
key?: string;
/**
* The picture (ImageSource): `{ png }` or `{ rgba, width, height }` bytes,
* or `{ file, format }` / `{ shm, format, width, height }` read here.
*/
source: ImageSource;
/** How many terminal columns wide, 1 to 255; the picture is scaled to fill
* the box and the site clips what its body cannot show. */
columns: number;
/**
* How many terminal rows tall, 1 to 255.
*/
rows: number;
/**
* What the picture says, drawn dim in its place where the picture cannot
* be (and read by a screen reader); required, may be a single space.
*/
alt: string;
};
ImageSource type
#
line 7033
Added in 2.1.275 · changed in 2.1.277
The picture an Image shows: base64 bytes the plugin holds (at most 2 MiB decoded), or the name of a file or POSIX shared-memory object it does not.
A name is one another process on this machine wrote; the terminal, running as the person, opens, reads and decodes it itself, so no pixel crosses $ and the engine never touches it. One it will not read (not a regular file, under /proc, /sys or /dev, gone, across ssh) draws a blank box, its words in the debug log; it unlinks a shared-memory object once read, so each frame is a fresh one. A source equal to the last drawn sends nothing; generation makes new content under an unchanged name a new source.
{ rgba: pixels.toBase64(), width: 64, height: 32 }
{ file: '/dev/shm/frame-3.rgba', format: 'rgba', width: 640,
height: 400 }
{ shm: '/tb-view-2', format: 'rgb', width: 1280, height: 720 }
85 lines
export type ImageSource = {
/**
* A whole PNG file, base64.
*/
png: string;
} | {
/**
* `width * height` RGBA pixels, 4 bytes each, base64.
*/
rgba: string;
/**
* Pixels per row, 1 to 2048.
*/
width: number;
/**
* Rows of pixels, 1 to 2048.
*/
height: number;
} | {
/**
* The absolute path of a regular file holding a whole PNG, at most
* 3072 bytes of path; read by the terminal, left in place.
*/
file: string;
/**
* The file is a whole PNG; the terminal decodes it and sizes it itself.
*/
format: 'png';
/**
* A whole number that changes when the file's content does under the
* same path, so a redraw reads it again; absent, the path alone tells.
*/
generation?: number;
} | {
/**
* The absolute path of a regular file of `width * height` raw pixels, at
* most 3072 bytes of path; read by the terminal, left in place.
*
* On Linux a file under `/dev/shm` is memory.
*/
file: string;
/**
* `rgba`, 4 bytes a pixel, or `rgb`, 3.
*/
format: 'rgba' | 'rgb';
/**
* Pixels per row, 1 to 4096.
*/
width: number;
/**
* Rows of pixels, 1 to 4096.
*/
height: number;
/**
* A whole number that changes when the file's content does under the
* same path, so a redraw reads it again; absent, the path alone tells.
*/
generation?: number;
} | {
/**
* The name of a POSIX shared-memory object of `width * height` raw
* pixels: `/` then up to 254 of `A-Z a-z 0-9 . _ -` (macOS takes 30).
*
* The terminal unlinks it after reading, so a name feeds one Image
* drawn once and is never sent again on a redraw; POSIX terminals only.
*/
shm: string;
/**
* `rgba`, 4 bytes a pixel, or `rgb`, 3.
*/
format: 'rgba' | 'rgb';
/**
* Pixels per row, 1 to 4096.
*/
width: number;
/**
* Rows of pixels, 1 to 4096.
*/
height: number;
/**
* A whole number that changes when a fresh object reuses a name, so a
* redraw reads it again; absent, the name alone tells.
*/
generation?: number;
};
ImpossibleKeys type
#
line 7126
In the first published surface (2.1.259)
The keys of object pattern P that object member E cannot satisfy, D levels down; never when there is none, which is what keeps the member.
A key E does not have (an open record has every string key), or one whose value P narrows to nothing.
type ImpossibleKeys<E, P, D extends readonly unknown[]> = {
[K in keyof P]-?: K extends keyof E ? [NarrowedValue<Exclude<E[K], undefined>, P[K], D>] extends [never] ? K : never : K;
}[keyof P];
IndexFree type
#
line 7134
Added in 2.1.287
An object with the declared keys of T and no other: its string and number index signatures are left out. What KnownKeys reads the keys of.
type IndexFree<T> = {
[K in keyof T as string extends K ? never : number extends K ? never : K]: 0;
};
InputProps type
#
line 7146
Added in 2.1.260 · changed in 2.1.271, 2.1.301
The props of Input, every surface's text field: an address, optional texts, and the closures a change and a submit run. A leaf.
One line, or with rows several. Focused through the same ring as Button (abovePrompt:focus); while it has focus every printable key reaches it alone and Esc returns them. A change and Enter raise ui.input.
56 lines
export type InputProps = {
/**
* The element's address: `e.element` at `ui.input`, what a matcher names.
*/
key: string;
/**
* Text drawn before the field.
*/
label?: string;
/**
* Text drawn dim in an empty field.
*/
placeholder?: string;
/**
* The text the field holds when drawn; the person's typing replaces it
* until the hook draws another.
*/
value?: string;
/**
* What Enter does, in a word or two, drawn beside the field while it has
* focus (`send`). Defaults to `submit`.
*/
submitLabel?: string;
/**
* How many lines tall the field is, a whole number of at least 1; from 2
* it holds several lines, as the DOM's `<textarea rows>`. Defaults to 1.
*
* Drawn that tall whatever it holds, its site's window at most; a longer
* text scrolls within. Enter submits; a newline is typed as in the prompt
* box. Up and Down walk its rows, then go to the element before or after.
*/
rows?: number;
/**
* The site's focus ring starts here when the site takes the keyboard,
* instead of on nothing, as the DOM's `autofocus`: Enter acts on it at once.
*
* A pane opened with `focus`, or the person's focus chord or click, is the
* take. Of several in one site the first drawn wins; it raises `ui.focus`,
* origin this plugin. A ring the person has moved stays where it was put.
*/
autoFocus?: true;
/**
* Runs on every change of the text, in the plugin's own environment: the
* bottom of a `ui.input` chain of kind `change`.
*
* The text is whole, its lines joined by `\n`.
*/
onInput?: (value: string, e: UiInputArgument) => void;
/**
* Runs on Enter with the text, in the plugin's own environment: the bottom
* of a `ui.input` chain of kind `submit`. No model turn unless it asks one.
*
* The text is whole, newlines kept and nothing trimmed.
*/
onSubmit: (value: string, e: UiInputArgument) => void;
};
INSTRUCTION_FILE_KINDS const
#
line 7207
Added in 2.1.275
Every tier an instruction file can belong to, for checking a hook's answer; the kind type is derived from this list.
const INSTRUCTION_FILE_KINDS: readonly ["managed", "user", "project", "local", "memory"];
InstructionFile type
#
line 7213
Added in 2.1.275 · changed in 2.1.304
One instruction file behind the claudeMd block: where it was read, its tier, its text as loaded, and the file that @-imported it if one did.
27 lines
export type InstructionFile = {
/**
* The file's path, absolute.
*/
path: string;
/**
* Its tier.
*/
kind: InstructionFileKind;
/**
* The text as loaded (comments and frontmatter already stripped).
*/
content: string;
/**
* The path of the file whose `@` import brought this one, when one did.
*/
parent?: string;
/**
* Present where this session's own account could have written the file,
* or where a person's own plugin or one in the `builtin` tier added or
* rewrote a `managed` file.
*
* It is then not told as the organization's. The host stamps it; a hook's
* own value for it is ignored.
*/
isUnverified?: true;
};
InstructionFileKind type
#
line 7245
Added in 2.1.275
What tier an instruction file belongs to: the organization's managed policy, the person's own, the project's checked-in or private ones, memory.
export type InstructionFileKind = (typeof INSTRUCTION_FILE_KINDS)[number];
InstructionsLoadedHookInput type
#
line 7247
Added in 2.1.265
type InstructionsLoadedHookInput = BaseHookInput & {
hook_event_name: 'InstructionsLoaded';
file_path: string;
memory_type: 'User' | 'Project' | 'Local' | 'Managed';
load_reason: 'session_start' | 'nested_traversal' | 'path_glob_match' | 'include' | 'compact';
globs?: string[];
trigger_file_path?: string;
parent_file_path?: string;
};
InvalidatableEventName type
#
line 7265
In the first published surface (2.1.259) · changed in 2.1.265, 2.1.269, 2.1.277, 2.1.323
What $.ui.invalidate takes: a render event, or one of the seven events whose answers the engine caches for the session.
For ui.render, the instances this plugin's matchers on it may select: one naming no requestId, every instance of its component. For a thread resumed in a new process the recorded prompt.section text stands, asked or not.
export type InvalidatableEventName = RenderEventName | 'prompt.section' | 'prompt.context' | 'prompt.attachment' | 'tool.describe' | 'tool.list' | 'command.describe' | 'config.describe';
IsDiscriminant type
#
line 7275
In the first published surface (2.1.259) · changed in 2.1.287
Whether tag key K selects members of I: it does when each member gives it ONE literal (component: "ToolUse" on the ToolUse variant).
A key that is the same union on every member is a filter at runtime; it is left out of the selection so that it cannot defeat the narrowing the other keys give.
type IsDiscriminant<I, K> = I extends unknown ? K extends KnownKeys<I> ? IsSingleLiteral<I[K & keyof I]> : true : never;
IsLiteralValued type
#
line 7280
In the first published surface (2.1.259)
Whether V is made of literals only: "a" | "b" is, string is not.
type IsLiteralValued<V> = string extends V ? false : number extends V ? false : boolean extends V ? false : [V] extends [string | number | boolean] ? true : false;
IsSingleLiteral type
#
line 7285
In the first published surface (2.1.259)
Whether V is exactly one string, number or boolean literal.
type IsSingleLiteral<V> = [V] extends [string | number | boolean] ? IsUnion<V> extends true ? false : true : false;
IsUnion type
#
line 7290
In the first published surface (2.1.259)
Whether T is a union of two or more members.
type IsUnion<T, U = T> = T extends unknown ? [U] extends [T] ? false : true : never;
JsonValue type
#
line 7300
Added in 2.1.267
Plain data: what JSON holds, and what crosses between a plugin's hooks module and its surface module whole (a Client's props, a post's data).
A function, a class instance, undefined, a cycle, a named key on a list or a key named __proto__, constructor or prototype is not plain data; the engine refuses one where it checks, and drops it where it clones.
export type JsonValue = string | number | boolean | null | readonly JsonValue[] | {
readonly [key: string]: JsonValue;
};
KeptEvent type
#
line 7308
In the first published surface (2.1.259) · changed in 2.1.265
What next takes in a matched hook: the variants of e the matcher can match (KeptMembers), as declared, so a rewrite of a pinned field passes.
type KeptEvent<P extends Pattern, M> = MatchedNames<P, M> extends infer N extends EventName ? N extends unknown ? KeptMembers<Args<N>, M> : never : never;
KeptMembers type
#
line 7317
In the first published surface (2.1.259)
The members of the argument union E matcher P can match, as declared; what next takes, so a rewrite may change a field the matcher pinned.
A member is dropped when P names a key it lacks, or gives a key, at any depth, a value none of that key's values can equal (ImpossibleKeys).
type KeptMembers<E, P> = E extends unknown ? [ImpossibleKeys<E, P, []>] extends [never] ? E : never : never;
KnownKeys type
#
line 7326
In the first published surface (2.1.259) · changed in 2.1.287
The declared keys of T, the string and number index signatures left out.
A type with an index signature is mapped to be rid of it (IndexFree); any other is read as it stands, which costs nothing per key. A key of these indexes T as T[K & keyof T].
type KnownKeys<T> = keyof (string extends keyof T ? IndexFree<T> : number extends keyof T ? IndexFree<T> : T);
LateOverload type
#
line 7334
Added in 2.1.265
The events whose overload must come after the rest, lest it shadow them.
classic.PreToolUse shares tool.call's envelope, turn.abort every turn event's turnId, and an object of any shape is assignable to NoArgs.
type LateOverload = 'classic.PreToolUse' | 'turn.abort' | NoArgsEvent;
LinkProps type
#
line 7344
Added in 2.1.260
The props of Link, a hyperlink every surface draws: an OSC 8 span on the terminal (else its text then the URL in dim), an anchor on desktop.
An inline element: its children are the text, strings and inline elements; absent children the label, absent both the URL. What href spells is the plugin's own; what a click opens is the surface's.
16 lines
export type LinkProps = {
/**
* Where the link goes, as written: any scheme, host and port; at most
* 2048 characters once what a terminal acts on is percent-encoded.
*
* A blank or no string, and on a remote surface anything but the
* `https:` URL its wire promises: the text is drawn plain, and said so;
* the tree stands. A click opens what the terminal, or the surface, opens.
*/
href: string;
/**
* The text drawn when the element has no children; absent both, the URL
* itself is the text.
*/
label?: string;
};
Literal type
#
line 7365
In the first published surface (2.1.259)
What a matcher value selects by: itself, or unknown for a RegExp, which selects nothing.
type Literal<X> = X extends RegExp ? unknown : X;
MarkdownLeafProps type
#
line 7371
Added in 2.1.274
What a Markdown carries across the boundary: its address, text, dimness and which links it answers; onLinkPress stays behind, a press instead.
20 lines
export type MarkdownLeafProps = {
/**
* The element's address: what `e.element` carries and what a matcher
* names; present whenever the element carries a `press`.
*/
key?: string;
/**
* The markdown drawn, checked as a Text's string is.
*/
text: string;
/**
* The whole block dim, as `Text`'s `dimColor`; absent draws as false.
*/
dimColor?: boolean;
/**
* Which links a press belongs to, by `href` as written; absent, with a
* `press`, every link drawn. Compared with the pressed target only.
*/
pressableLinks?: readonly string[];
};
MarkdownProps type
#
line 7400
Added in 2.1.274 · changed in 2.1.330
The props of Markdown, a block of markdown every surface draws as it draws an assistant reply's text: its own renderer, links, tables, fences.
A leaf: no children. text is the element's data as a Text's string is, checked the same way. With onLinkPress the links it draws are the plugin's to answer: a press on one raises ui.press addressed to key.
39 lines
export type MarkdownProps = {
/**
* The element's address: `e.element` at `ui.press`, what a matcher names.
* Required with `onLinkPress`, since a press needs one; else optional.
*/
key?: string;
/**
* The markdown drawn, as an assistant reply would write it; a `<context>`
* block, hidden in a reply's own text, is drawn here as written.
*
* Of any length (one drawing draws 100000 characters in all), tab and
* newline its only control characters; a link not `https:`, `http:` or
* `file:` draws as text. The terminal refuses it by the question dialog.
*/
text: string;
/**
* The whole block dim, as `Text`'s `dimColor`: a thought, an aside.
*/
dimColor?: boolean;
/**
* What a press on a link in `text` runs, in the plugin's own environment:
* the bottom of a `ui.press` chain whose `e.link` names the link.
*
* A press is a plain single click where the surface reports clicks (the
* fullscreen terminal): it opens nothing and lands once no double-click
* followed; a ctrl, alt or terminal-kept cmd click opens it as before.
* Where it does async work, returning the promise is best, as for `onPress`.
*/
onLinkPress?: ((link: PressedLink, e: UiPressArgument) => void) | ((link: PressedLink, e: UiPressArgument) => Promise<unknown>);
/**
* Which links in `text` a press belongs to, by `href` as the markdown
* writes it; absent, every link drawn. Only with `onLinkPress`.
*
* A link left out keeps the surface's own behaviour. At most 256 entries
* of at most 2048 characters, compared with the pressed link's target;
* none where the drawing has no room left for them.
*/
pressableLinks?: readonly string[];
};
MatchedEvent type
#
line 7444
In the first published surface (2.1.259) · changed in 2.1.265
The argument a matched hook receives: e narrowed by M (Narrowed), per event the registration covers.
export type MatchedEvent<P extends Pattern, M> = MatchedNames<P, M> extends infer N extends EventName ? N extends unknown ? Narrowed<Args<N>, M> : never : never;
MatchedHook type
#
line 7454
In the first published surface (2.1.259) · changed in 2.1.265, 2.1.268, 2.1.269
The hook on(pattern, matcher, hook) takes: ($, e, next) with e narrowed by the matcher (MatchedEvent), and a tagged result the same way.
On a streaming event it is the generator form (MatchedStreamHook). next takes the variants the matcher keeps, as declared (KeptEvent); next.is names the events the registration covers and narrows as the matcher does.
export type MatchedHook<P extends Pattern, M> = P extends StreamingEventName ? MatchedStreamHook<P, M> : ($: EngineInterface, e: Frozen<MatchedEvent<P, M>>, next: Next<MatchedNames<P, M>, KeptEvent<P, M>, MatchedResult<P, M>, {
[K in MatchedNames<P, M>]: Narrowed<Args<K>, M>;
}>) => MatchedResult<P, M> | Promise<MatchedResult<P, M>>;
MatchedNames type
#
line 7466
In the first published surface (2.1.259) · changed in 2.1.265, 2.1.287
The events a matched registration on P covers: the event named, or for a glob every selected event whose input has each key the matcher names.
Settled by infer: while P is open the compiler reads them as EventName and selects nothing; a type keyed by them is worked out once, for the P a registration gives.
type MatchedNames<P, M = never> = (P extends EventName ? P : {
[N in Selected<P & string>]: [M] extends [never] ? N : keyof M extends AnyKeyOf<Args<N>> ? N : never;
}[Selected<P & string>]) extends infer Names extends EventName ? Names : never;
MatchedResult type
#
line 7474
In the first published surface (2.1.259) · changed in 2.1.265
What a matched hook returns: the event's result, narrowed by M where the result is a union tagged by the matcher's tag keys.
export type MatchedResult<P extends Pattern, M> = MatchedNames<P, M> extends infer N extends EventName ? N extends unknown ? Select<EventResult<N>, Selection<Args<N>, M>> : never : never;
MatchedStreamHook type
#
line 7480
Added in 2.1.269
The hook on(event, matcher, hook) takes on a streaming event: the generator form, e narrowed by the matcher, next(e) the stream beneath.
export type MatchedStreamHook<P extends StreamingEventName, M> = ($: EngineInterface, e: Frozen<MatchedEvent<P, M>>, next: MatchedStreamNext<P, M>) => StreamHookBody<Chunk<P>, MatchedResult<P, M>>;
MatchedStreamNarrowings type
#
line 7486
Added in 2.1.269
What a matched streaming hook's next.is(pattern, e) narrows e to: the streaming event's argument narrowed by the matcher.
type MatchedStreamNarrowings<P extends StreamingEventName, M> = {
[K in P]: Narrowed<Args<K>, M>;
};
MatchedStreamNext type
#
line 7494
Added in 2.1.269
A matched streaming hook's next: the variants the matcher keeps, the result tagged the same way, next.is narrowing as the matcher does.
type MatchedStreamNext<P extends StreamingEventName, M> = StreamNext<P, KeptEvent<P, M>, MatchedResult<P, M>, MatchedStreamNarrowings<P, M>>;
Matcher type
#
line 7510
In the first published surface (2.1.259) · changed in 2.1.287
What on(event, matcher, hook) takes for an argument of type I: the shape of the e the hook wants, a partial of it at any depth.
A leaf is === or a RegExp ({ command: /^p4 / }); an array is any-of; an object is a partial of an OBJECT, so { command: { startsWith } } is a type error where e is typed and free where it is unknown.
plugin is a default matcher key: where the engine sets it on e (ui.press, a band row), a matcher leaving it out is read as naming the hook's own plugin; "*" names every one, and hears an e without the key. claude plugin validate notes such a hook: (default matcher key: plugin); a component there keeps the hook off AbovePromptList.
export type Matcher<I, All = I> = I extends unknown ? {
readonly [K in KnownKeys<I>]?: MatcherValue<I[K & keyof I], MatcherValueOf<All, K>>;
} & (string extends keyof I ? OpenMatcher<I, All> : unknown) : never;
MatcherData type
#
line 7522
In the first published surface (2.1.259)
Any matcher at all, for a field typed unknown (a tool's input, a result's output): the kinds the engine accepts, unchecked there.
The four kinds: a scalar is ===; a RegExp tests the value as a string ({ command: /^p4 / }); an array matches if any element does; an object is a partial of an object. { startsWith: 'p4' } never matches a string.
type MatcherData = string | number | boolean | null | RegExp | readonly MatcherData[] | {
readonly [key: string]: MatcherData;
};
MatcherFor type
#
line 7534
Added in 2.1.287
The matcher type per pattern: a Matcher of the e of the event named, or of each event a glob or a negation selects.
Settled by infer: while P is open the bound reads as unknown; once P is known it is that Matcher exactly. A mistake on a name is refused where it is written; a pattern takes what any event it selects takes.
type MatcherFor<P extends Pattern> = Matcher<Args<MatchedNames<P>>> extends infer Settled ? Settled : never;
MatcherKeys type
#
line 7539
In the first published surface (2.1.259)
The declared keys of every variant of I (index signatures aside).
type MatcherKeys<I> = I extends unknown ? KnownKeys<I> : never;
MatcherOne type
#
line 7549
In the first published surface (2.1.259) · changed in 2.1.267
What matches one value of type V, by the runtime's kinds: a scalar leaf takes the value or a RegExp; an object, a partial of it.
For an array, what matches one ELEMENT of it, since a pattern against an array value holds when some element matches; for unknown, any matcher. A scalar matches by ===, a RegExp tests the value as a string.
type MatcherOne<V> = unknown extends V ? MatcherData : V extends readonly (infer Item)[] ? MatcherOne<Item> : V extends string | number | boolean | null ? V | RegExp : V extends object ? Matcher<V> : V extends undefined ? never : unknown;
MatcherValue type
#
line 7559
In the first published surface (2.1.259)
What a matcher gives a key whose value is V on this variant and Across over every variant: one MatcherOne, or an array of them matched as one-of.
The one-of is typed over every variant, so { tool: ['Bash', 'Read'] } types on the Bash variant; with a nested pattern beside it, the pattern is checked against a variant the one-of names, not against each of them.
type MatcherValue<V, Across = V> = MatcherOne<V> | readonly MatcherOne<Across>[];
MatcherValueAcross type
#
line 7565
Added in 2.1.287
The type of key K across the variants of I that declare it, read variant by variant: what MatcherValueOf reads for a key as wide as symbol.
type MatcherValueAcross<I, K> = I extends unknown ? K extends KnownKeys<I> ? I[K & keyof I] : never : never;
MatcherValueOf type
#
line 7575
In the first published surface (2.1.259) · changed in 2.1.287
The type of key K across the variants of I that declare it: one read of their table by key (MatcherValues), for a key some variant declares.
A key as wide as symbol is an index signature's, which the table's own would meet with never: it is read variant by variant. While I is open the table is left unmade, since the variants of I are what it is made of.
type MatcherValueOf<I, K> = [I] extends [unknown] ? symbol extends K ? MatcherValueAcross<I, K> : MatcherValues<I>[K & PropertyKey] : never;
MatcherValues type
#
line 7585
Added in 2.1.287
The type of each declared key of I across the variants that declare it, as one table by key: made once per I, then read at a key.
Each variant gives an entry per key it declares; the entries of one key fall into one property, their values a union. Read at a key some variant declares.
type MatcherValues<I> = {
[Entry in I extends unknown ? {
[K in KnownKeys<I>]-?: [key: K, value: I[K & keyof I]];
}[KnownKeys<I>] : never as Entry[0]]: Entry[1];
} & Record<PropertyKey, never>;
McpConnectRefusal type
#
line 7600
Added in 2.1.285
Why $.mcp.connect left a server unconnected, in one word; unlisted too where the session's host runs the plugin's servers itself.
unlisted: neither in the caller's own manifest nor a server /mcp lists. unapproved: a repository server not approved. disabled: turned off. policy: enterprise MCP policy. auth: needs sign-in. failed: not resolved, did not connect, or another provider's than its hooks were shown.
type McpConnectRefusal = 'unlisted' | 'unapproved' | 'disabled' | 'policy' | 'auth' | 'failed';
McpConnectResult type
#
line 7609
Added in 2.1.285
What $.mcp.connect resolves to and what an mcp.connect hook's { value } holds: the server connected, or why not.
const browser = await $.mcp.connect("browser")
26 lines
type McpConnectResult = {
/**
* True: the server is connected and its tools are the session's.
*/
isConnected: true;
/**
* The name /mcp lists it under and `$.mcp.call` takes: usually
* `plugin:<plugin>:<server>`.
*
* Or the name the session already runs the same server under.
*/
server: string;
} | {
/**
* False: the server is not connected.
*/
isConnected: false;
/**
* Why, in one word.
*/
reason: McpConnectRefusal;
/**
* The same as one plain sentence, to log or toast.
*/
message: string;
};