Follow Discord
Sweep 20 Nov 2026 · 19:55Z Build v2.1.330 547 read Stable v2.1.323 Latest v2.1.330 Next v2.1.330 Feeds RSS JSON llms.txt llms-full.txt Unofficial
Mods API · 03 of 03

Types

Every declaration in the file, verbatim, with the doc comment above it.

Declarations833over 17 pages
Mined from2.1.330the shipped binary

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, 301 to 350 of 833

PostCompactHookInput type # line 10596

Added in 2.1.265

  type PostCompactHookInput = BaseHookInput & {
      hook_event_name: 'PostCompact';
      trigger: 'manual' | 'auto';
      /**
       * The conversation summary produced by compaction
       */
      compact_summary: string;
  };

PostModelSwitchHookInput type # line 10605

Added in 2.1.265

37 lines
  type PostModelSwitchHookInput = (BaseHookInput & {
      hook_event_name: 'PostModelSwitch';
  }) & {
      /**
       * Resolved model id the session was running before the switch
       */
      from_model: string;
      /**
       * Resolved model id the session runs after the switch
       */
      to_model: string;
      /**
       * What was asked for (alias such as "opus", a full id, or null for "default")
       */
      requested_model: string | null;
      /**
       * command: /model <name>, the /config Model row, or enabling fast mode when that promotes the model; picker: an interactive model picker; sdk: headless set_model (SDK, Remote Control, IDE); auto: automatic fallback or other programmatic change; resume: model restored while resuming a session
       */
      source: 'command' | 'picker' | 'sdk' | 'auto' | 'resume';
      /**
       * Prompt tokens the next request re-sends: the last main-thread response's input + cache_read + cache_creation + output tokens (0 before the first response; for a server-side tool loop, its last iteration's window, not the summed totals)
       */
      context_tokens: number;
      /**
       * Whether the current model's prompt cache is likely still warm (a switch then forfeits it)
       */
      prompt_cache_warm: boolean;
      cache_ttl: '5m' | '1h';
      /**
       * Estimated cost of re-caching context_tokens on to_model at its cache-write rate - the managed modelPricing when set, otherwise list price; excludes the response
       */
      estimated_cache_write_usd: number;
      /**
       * configured: priced at the managed modelPricing setting; catalog: list price; default: to_model unknown, the default tier was assumed
       */
      pricing: 'configured' | 'catalog' | 'default';
  };

PostToolBatchHookInput type # line 10646

Added in 2.1.265

Hook input for the PostToolBatch event. Fired once after every tool call in a batch has resolved, before the next model request. PostToolUse fires per-tool and may run concurrently for parallel tool calls; PostToolBatch fires exactly once with the full batch.

  type PostToolBatchHookInput = BaseHookInput & {
      hook_event_name: 'PostToolBatch';
      tool_calls: PostToolBatchToolCall[];
  };

PostToolBatchToolCall type # line 10651

Added in 2.1.265

  type PostToolBatchToolCall = {
      tool_name: string;
      tool_input: unknown;
      tool_use_id: string;
      tool_response?: unknown;
  };

PostToolUseFailureHookInput type # line 10658

Added in 2.1.265 · changed in 2.1.274

13 lines
  type PostToolUseFailureHookInput = BaseHookInput & {
      hook_event_name: 'PostToolUseFailure';
      tool_name: string;
      tool_input: unknown;
      tool_use_id: string;
      error: string;
      is_interrupt?: boolean;
      /**
       * Tool execution time in milliseconds. Excludes permission-prompt and hook time.
       */
      duration_ms?: number;
      mcp_server?: McpServerProvenance;
  };

PostToolUseHookInput type # line 10672

Added in 2.1.265 · changed in 2.1.274

  type PostToolUseHookInput = BaseHookInput & {
      hook_event_name: 'PostToolUse';
      tool_name: string;
      tool_input: unknown;
      tool_response: unknown;
      tool_use_id: string;
      /**
       * Tool execution time in milliseconds. Excludes permission-prompt and hook time.
       */
      duration_ms?: number;
      mcp_server?: McpServerProvenance;
  };

PreCompactHookInput type # line 10685

Added in 2.1.265

  type PreCompactHookInput = BaseHookInput & {
      hook_event_name: 'PreCompact';
      trigger: 'manual' | 'auto';
      custom_instructions: string | null;
  };

PreModelSwitchHookInput type # line 10691

Added in 2.1.265

37 lines
  type PreModelSwitchHookInput = (BaseHookInput & {
      hook_event_name: 'PreModelSwitch';
  }) & {
      /**
       * Resolved model id the session was running before the switch
       */
      from_model: string;
      /**
       * Resolved model id the session runs after the switch
       */
      to_model: string;
      /**
       * What was asked for (alias such as "opus", a full id, or null for "default")
       */
      requested_model: string | null;
      /**
       * command: /model <name>, the /config Model row, or enabling fast mode when that promotes the model; picker: an interactive model picker; sdk: headless set_model (SDK, Remote Control, IDE)
       */
      source: 'command' | 'picker' | 'sdk';
      /**
       * Prompt tokens the next request re-sends: the last main-thread response's input + cache_read + cache_creation + output tokens (0 before the first response; for a server-side tool loop, its last iteration's window, not the summed totals)
       */
      context_tokens: number;
      /**
       * Whether the current model's prompt cache is likely still warm (a switch then forfeits it)
       */
      prompt_cache_warm: boolean;
      cache_ttl: '5m' | '1h';
      /**
       * Estimated cost of re-caching context_tokens on to_model at its cache-write rate - the managed modelPricing when set, otherwise list price; excludes the response
       */
      estimated_cache_write_usd: number;
      /**
       * configured: priced at the managed modelPricing setting; catalog: list price; default: to_model unknown, the default tier was assumed
       */
      pricing: 'configured' | 'catalog' | 'default';
  };

PreToolUseDecision type # line 10748

In the first published surface (2.1.259)

The decision of a classic.PreToolUse result: allow, ask, deny, or none.

27 lines
  export type PreToolUseDecision = {
      /**
       * Lets the call run without a permission prompt (the managed-settings
       * hooks ran first; a deny from them ended the chain above).
       */
      allow: true;
      ask?: undefined;
      deny?: undefined;
  } | {
      /**
       * Asks the user before the call runs; the text is shown as the reason.
       */
      ask: string;
      allow?: undefined;
      deny?: undefined;
  } | {
      /**
       * Refuses the call; the model receives the text as the reason.
       */
      deny: string;
      allow?: undefined;
      ask?: undefined;
  } | {
      allow?: undefined;
      ask?: undefined;
      deny?: undefined;
  };

PreToolUseHookInput type # line 10776

Added in 2.1.265 · changed in 2.1.274

  type PreToolUseHookInput = BaseHookInput & {
      hook_event_name: 'PreToolUse';
      tool_name: string;
      tool_input: unknown;
      tool_use_id: string;
      mcp_server?: McpServerProvenance;
  };

PreToolUseResult type # line 10791

In the first published surface (2.1.259)

What a classic.PreToolUse hook returns: one of allow, ask, deny, or none of them, which passes the call on to the normal permission flow.

The event fires inside tool.call, beneath every plugin's tool.call hook (a test raises it by calling $.tool.call).

  export type PreToolUseResult = PreToolUseDecision & {
      /**
       * Replaces the tool's arguments; validated against the tool's schema before
       * the tool runs.
       */
      updatedInput?: Record<string, unknown>;
      /**
       * Extra context handed to the model with the call, one entry per note.
       */
      additionalContext?: string[];
  };

ProcessRunInit type # line 10806

Added in 2.1.260 · changed in 2.1.268

Options of $.process.run.

20 lines
  export type ProcessRunInit = {
      /**
       * The child's working directory, relative to the session's or absolute;
       * absent, the session's working directory.
       */
      cwd?: string;
      /**
       * Variables set over the host process's own environment.
       */
      env?: Record<string, string>;
      /**
       * Text written to the child's standard input, then closed.
       */
      stdin?: string;
      /**
       * How long the child may run before it is killed and the call rejects,
       * in milliseconds; 30 seconds when absent, ten minutes at most.
       */
      timeoutMs?: number;
  };

ProcessRunResult type # line 10833

Added in 2.1.260 · changed in 2.1.268, 2.1.284

What $.process.run resolves with once the child has exited.

const { stdout, isStdoutTruncated } = await $.process.run(["git", "log"])
30 lines
  export type ProcessRunResult = {
      /**
       * The child's exit status; a child ended by a signal reads as 1.
       */
      exitCode: number;
      /**
       * What the child wrote to standard output, as text: its first 4194304
       * bytes (4 MiB), the rest read and dropped (`isStdoutTruncated`).
       *
       * The limit counts bytes, not characters, and is standard output's own:
       * standard error has the same limit again. A cut inside a multi-byte
       * character drops that character.
       */
      stdout: string;
      /**
       * What the child wrote to standard error, as text: its first 4194304
       * bytes (4 MiB), the rest read and dropped (`isStderrTruncated`).
       */
      stderr: string;
      /**
       * True when the child wrote more than 4194304 bytes to standard output
       * and `stdout` is only the first of them; false when `stdout` is whole.
       */
      isStdoutTruncated: boolean;
      /**
       * True when the child wrote more than 4194304 bytes to standard error
       * and `stderr` is only the first of them; false when `stderr` is whole.
       */
      isStderrTruncated: boolean;
  };

ProcessSpawnChunk type # line 10872

Added in 2.1.280

One piece of a spawned child's output as $.process.spawn streams it: which pipe it came from, and the text.

The text is UTF-8 decoded as it arrived, in order per pipe: a piece ends wherever the child's write did, so a line may span two pieces and one piece may hold several lines; a multi-byte character is never split.

13 lines
  export type ProcessSpawnChunk = {
      /**
       * The pipe the text came from.
       */
      stream: 'stdout' | 'stderr';
      /**
       * What the child wrote, decoded; never empty, and never cut.
       *
       * Nothing of the stream is dropped: once 1048576 characters wait unread,
       * the child blocks on its next write until the loop pulls.
       */
      text: string;
  };

ProcessSpawnRequest type # line 10893

Added in 2.1.280

The argument of $.process.spawn(request), and the e its hooks see: the command by its argument vector and how the child is started.

The same rules as $.process.run: no shell, the session's working directory unless one is named, the host's environment with env over it.

22 lines
  export type ProcessSpawnRequest = {
      /**
       * The command and its arguments, `argv[0]` the executable.
       */
      argv: readonly string[];
      /**
       * The child's working directory, relative to the session's or absolute;
       * absent, the session's working directory.
       */
      cwd?: string;
      /**
       * Variables set over the host process's own environment.
       */
      env?: Record<string, string>;
      /**
       * Text written to the child's standard input, which is then closed;
       * absent, standard input is closed from the start.
       *
       * A string today; a later form may take the text in pieces.
       */
      input?: string;
  };

ProcessSpawnResult type # line 10920

Added in 2.1.280

How a spawned child ended, as the stream of $.process.spawn returns it once every piece has been read: its exit code, or the signal that did it.

  export type ProcessSpawnResult = {
      /**
       * The child's exit status; null when a signal ended it.
       */
      code: number | null;
      /**
       * What ended the child from outside (`SIGTERM`); null when it exited on
       * its own. On Windows a killed child reads as an exit code, this null.
       */
      signal: string | null;
  };

ProgressProps type # line 10939

Added in 2.1.323

The props of Progress, how far along a task is. A leaf: no children.

Use it for a task moving toward done. For a level that is not heading anywhere, such as usage against a limit, draw a bar of Boxes instead. The ToolProgress render site is unrelated.

25 lines
  export type ProgressProps = {
      /**
       * What is being done, drawn and read out by a screen reader. Not blank.
       */
      label: string;
      /**
       * From 0 to `max`. Absent or not finite, the task is running with no known
       * end. Past either end it draws as that end.
       */
      value?: number;
      /**
       * Where `value` ends. Absent, 1. Zero or less, or not finite, makes no
       * fraction, so the task draws as running.
       */
      max?: number;
      /**
       * The figure as a person reads it, such as `412 of 900`. Absent, a surface
       * draws the whole percent, or says the task is running.
       */
      valueText?: string;
      /**
       * The fill, as Box's `backgroundColor` takes it. Absent, the surface's own.
       */
      color?: Color;
  };

PromptAttachmentDetailOf type # line 10973

Added in 2.1.287

The facts prompt.attachment pins under e.detail, by attachment type: what the engine computed for the row, as it rendered the row's text.

A type named here carries them on every row the engine made for a session whose plan goes in a file; a type not named carries no detail at all. Read off the row, never computed again: sent again, it says what it was made with.

26 lines
  export type PromptAttachmentDetailOf = {
      /**
       * The reminder a request carries while plan mode is on: `full` the first
       * of a planning session and after a compaction, `sparse` most others.
       *
       * @example
       * const isSparse = e.detail?.reminder === "sparse"
       */
      plan_mode: PlanModeDetail;
      /**
       * The note made when plan mode is entered again, the earlier plan still in
       * its file; it precedes the reminder.
       *
       * @example
       * const planFilePath = e.detail?.planFilePath
       */
      plan_mode_reentry: PlanModeReentryDetail;
      /**
       * The note made once when plan mode has ended: the model may act again,
       * and is told where its plan is when there is one.
       *
       * @example
       * const hasPlan = e.detail?.hasPlan === true
       */
      plan_mode_exit: PlanModeExitDetail;
  };

PromptAttachmentInput type # line 11008

Added in 2.1.277 · changed in 2.1.287

The input of prompt.attachment: one message the engine injects into the conversation for the model on its own, as a request is about to carry it.

A reminder, a mode transition, a listing, a mentioned file, a hook's context: only one that carries text for the model is raised. A union on type: a name PromptAttachmentDetailOf declares carries its detail.

  export type PromptAttachmentInput = {
      [K in keyof PromptAttachmentDetailOf]: DeclaredAttachmentInput<K>;
  }[keyof PromptAttachmentDetailOf] | UndeclaredAttachmentInput;

PromptAttachmentOrigin type # line 11020

Added in 2.1.277

Who authored the text an injected attachment carries, as the engine knows it from the attachment itself; a closed set, pinned on the event.

A hooks module reads e.origin.kind to tell the engine's own prose from a settings hook's output or another plugin's context. next(e) passes it on as received; one left out is put back; no hook sets one.

34 lines
  export type PromptAttachmentOrigin = {
      /**
       * The engine's own prose or framing: a reminder, a mode transition, a
       * listing, a notice, an announced context block.
       *
       * A file the person mentioned, as the engine presents it, and a prompt
       * or notification delivered into a running turn are the engine's too.
       */
      kind: 'engine';
  } | {
      /**
       * A settings hook's output the engine injects for the model: its
       * additional context, a blocking error's note, a stopped continuation.
       */
      kind: 'hook';
      /**
       * The settings hook event that produced it (`SessionStart`,
       * `UserPromptSubmit`, `PostToolUse`, ...).
       */
      event: string;
  } | {
      /**
       * Text a plugin's hook attached through a chain's `context`, as the
       * model reads it.
       *
       * The chains that carry one: `prompt.submit`, `prompt.mention`,
       * `tool.call`.
       */
      kind: 'plugin';
      /**
       * The chain's event that attached it.
       */
      event: string;
  };

PromptAttachmentResult type # line 11059

Added in 2.1.277

What a prompt.attachment hook returns: the text the model reads for that attachment, or null to leave the attachment out of the request.

  export type PromptAttachmentResult = {
      text: string | null;
  };

PromptAutocompleteInput type # line 11070

Added in 2.1.292

The input of prompt.autocomplete: the prompt box as the person left it and the token at its cursor, which a taken suggestion replaces.

All four are pinned, facts of the box: a rewrite that changes one is refused, one left out is kept. Offsets count UTF-16 code units.

24 lines
  export type PromptAutocompleteInput = {
      /**
       * The whole draft in the prompt box.
       */
      text: string;
      /**
       * Where the person's caret stands in `text`, 0 to `text.length`.
       */
      cursor: number;
      /**
       * The run of characters that are not whitespace and that ends at the
       * cursor: `text.slice(start, cursor)`, never empty.
       *
       * What a matcher names to answer one lead character only.
       *
       * @example
       * on("prompt.autocomplete", { token: /^#/ }, hook)
       */
      token: string;
      /**
       * Where `token` begins in `text`.
       */
      start: number;
  };

PromptAutocompleteResult type # line 11099

Added in 2.1.292

What a prompt.autocomplete hook returns and what next(e) resolves to: the rows the plugins add to the typeahead for the token.

  export type PromptAutocompleteResult = {
      /**
       * The rows, in the order drawn beneath the engine's own; from core, none.
       *
       * A hook puts its rows before or after what `next(e)` gave; the engine's
       * own rows are not on this event and stay where they were drawn.
       *
       * @example
       * return { suggestions: [...(await next(e)).suggestions, mine] }
       */
      suggestions: readonly PromptAutocompleteSuggestion[];
  };

PromptAutocompleteSuggestion type # line 11116

Added in 2.1.292

One row a prompt.autocomplete hook adds to the prompt box's typeahead: what taking it writes, what the row shows, and a dim line beside it.

15 lines
  export type PromptAutocompleteSuggestion = {
      /**
       * What taking the row writes in place of the token, the cursor after it;
       * never empty. The box's new token is then asked again.
       */
      text: string;
      /**
       * What the row shows, on one line; the `text` when absent.
       */
      label?: string;
      /**
       * The dim line drawn beside the label, cut to the row by the surface.
       */
      description?: string;
  };

PromptBox type # line 11139

Added in 2.1.275

The person's prompt box as it stands: the draft and where the cursor is in it; what $.prompt.read() resolves and $.prompt.fill hands back.

No selection: the terminal's box has none of its own, and a surface that binds one adds it here.

  export type PromptBox = {
      /**
       * The draft as typed so far; `''` where the session draws no box.
       */
      text: string;
      /**
       * Where the next typed character lands: an offset into `text` in UTF-16
       * code units, 0 at the start, `text.length` at the end.
       */
      cursor: number;
  };

PromptChangeInput type # line 11158

Added in 2.1.300

The input of prompt.change (prompt-change/): the prompt box after a change of its text that no prompt.edit carried, and who made it.

The change is already in the box. Every field is the engine's: a hook observes, and next(e) passes them on as received.

19 lines
  export type PromptChangeInput = {
      /**
       * The draft as it stands when the event is raised; what `$.prompt.read()`
       * answers then.
       */
      text: string;
      /**
       * Where the caret stands in `text` then, 0 to `text.length`.
       */
      cursor: number;
      /**
       * Who changed the box (PromptChangeOrigin), set by the engine: the act
       * that left the box as it stands.
       *
       * @example on('prompt.change', { origin: { kind: 'history' } },
       *   ($, e, next) => next(e))
       */
      origin: PromptChangeOrigin;
  };

PromptChangeOrigin type # line 11185

Added in 2.1.300

Who changed the prompt box at prompt.change, as the engine stamps it where the text is written; a matcher narrows on its kind.

The set of kinds may grow: treat a kind you do not know as engine. next(e) passes it on as received; no hook sets one.

46 lines
  export type PromptChangeOrigin = {
      /**
       * A recalled entry of the prompt history was put in the box: the up
       * and down arrows, the history search, the history picker.
       *
       * Stepping back out of a recall is `history` too: the newest entry
       * passed, the search cancelled, the person's own draft put back.
       */
      kind: 'history';
  } | {
      /**
       * The box was emptied by something other than an edit or an undo: a
       * submit took the draft, a clear, a stash.
       *
       * `text` is the box when raised: a key typed since is in it.
       */
      kind: 'clear';
  } | {
      /**
       * The person took an edit back (`chat:undo`): the box holds an
       * earlier text of theirs, which may be empty.
       */
      kind: 'undo';
  } | {
      /**
       * A plugin's `$.prompt.fill` landed, as its `prompt.fill` chain left it
       * and as the engine finished it (an over-long text collapsed).
       */
      kind: 'plugin';
      /**
       * The filling plugin's name; a hook that fills tells its own fill by it.
       */
      name: string;
  } | {
      /**
       * A remote surface's own Composer changed by the app's hand; reserved,
       * nothing raises it as shipped.
       */
      kind: 'app';
  } | {
      /**
       * Every other write: a draft put back, an accepted completion,
       * dictation, a prefill, and an edit `prompt.edit` does not carry.
       */
      kind: 'engine';
  };

PromptChangeResult type # line 11236

Added in 2.1.300

What a prompt.change hook returns and what next(e) resolves to: { text }, echoed by core; a hook's own value changes nothing.

  export type PromptChangeResult = {
      text: string;
  };

PromptComposeArgs type # line 11244

Added in 2.1.286

What a plugin passes $.prompt.compose: the facts it wants composed for, each one it leaves out read off the session (its model, its tools).

  export type PromptComposeArgs = Partial<PromptComposeInput>;

PromptComposeInput type # line 11250

Added in 2.1.286

The input of prompt.compose: the facts a system prompt is composed from, each already resolved by the engine, at the moment it renders one.

31 lines
  export type PromptComposeInput = {
      /**
       * The id of the model the request is for; pinned, the field a matcher
       * narrows on.
       */
      model: string;
      /**
       * The model whose prompt is rendered: `model`, unless the engine renders
       * another model's prompt for it (a model it holds no prompt of its own for).
       */
      promptModel: string;
      /**
       * Where the session draws at this render, as `$.session.surfaces()`
       * answers: `terminal` first under the REPL; empty where nothing draws.
       */
      surfaces: readonly RenderSurface[];
      /**
       * The names of the tools the request offers the model; the engine's own
       * composition reads them against the session's, an unknown name ignored.
       */
      tools: readonly string[];
      /**
       * What the person chose in place of the default way of answering, and
       * whether it keeps the coding instructions; null for the default style.
       */
      outputStyle: {
          name: string;
          isKeepingCodingInstructions: boolean;
      } | null;
      traits: readonly PromptComposeTrait[];
  };

PromptComposeResult type # line 11290

Added in 2.1.286

What a prompt.compose hook returns: the sections of the system prompt, in order, every shared one ahead of every session one.

A section left out is not sent; a hook that never calls next answers the whole list. The engine joins each side, places the cache boundary between them and every cache marker itself.

  export type PromptComposeResult = {
      sections: readonly PromptComposeSection[];
  };

PromptComposeScope type # line 11302

Added in 2.1.286

Which side of the prompt cache's boundary a section of the system prompt sits on: shared before it, session after it.

shared text reads the same for everyone on this build and model: the API may cache it across organizations, and text that varies hits that cache for nobody. session text varies. In a list every shared section comes first.

  export type PromptComposeScope = 'shared' | 'session';

PromptComposeSection type # line 11311

Added in 2.1.286

One section of the system prompt as prompt.compose answers it: a stable id, the text the model reads, and the side of the cache boundary it is on.

const POLICY = { id: "acme:policy", text: "...", scope: "session" } as const
23 lines
  export type PromptComposeSection = {
      /**
       * What a hook above finds the section by, to replace, move or drop it;
       * never empty, and unique in one list.
       *
       * A plugin's own is `<plugin>:<name>`; a bare name is the engine's. The full
       * prompt opens `intro`, `system`, `doing_tasks`, `actions`, `tools`, `tone`;
       * the short one opens `lean_body` instead; `--bare`'s one section is `bare`.
       */
      id: string;
      /**
       * The section's text, sent as written; sections on one side of the
       * boundary are joined by a blank line, in the list's order.
       */
      text: string;
      /**
       * The side of the cache boundary the section is sent on; in one list
       * every `shared` section comes before every `session` one.
       *
       * A section added at the end of what `next(e)` answered is `session`.
       */
      scope: PromptComposeScope;
  };

PromptComposeTrait type # line 11362

Added in 2.1.286

One branch the engine's own composition of the system prompt takes on the request or the session before it computes any section: a closed set.

bare: the session runs with the one-line prompt (--bare). lean: the prompt model takes the short body. sdk-preset: the SDK's claude_code preset, whose per-person sections ride the first user message instead.

teammate: an in-process teammate's render of its lead's prompt. analysis: a render that measures the prompt (/context) and sends nothing. print: a session with no terminal behind it (-p, the SDK).

skills: the Skill tool has commands to list. send-user-message: the session speaks to the person through a message tool.

Rewritten going down, sdk-preset, teammate and analysis steer the engine's composition; the rest it derives itself, so they tell a hook what it will do. What one section's own text turns on (a flag) is not here.

bare and lean say which sections come back. With bare: one, bare. With lean: lean_body, where the full prompt opens intro, system, doing_tasks, actions, tools, tone.

Past that opening the full and the short prompt hold the session's sections (communication, pronouns, memory, ...), each left out when it has no text.

  export type PromptComposeTrait = 'bare' | 'lean' | 'sdk-preset' | 'teammate' | 'analysis' | 'print' | 'skills' | 'send-user-message';

PromptContextBlock type # line 11368

In the first published surface (2.1.259)

One block of the context the first user message carries: a name the engine keys it by and the text under it.

14 lines
  export type PromptContextBlock = {
      /**
       * The key the block renders under (`# name`): `claudeMd`, `userEmail`,
       * `attachedProject`, `currentDate`, or a plugin's own.
       *
       * The field a matcher narrows on; unique among one context's blocks.
       */
      name: string;
      /**
       * The block's text; `claudeMd`'s is the instruction files framed as the
       * engine frames them, empty when it announces none.
       */
      text: string;
  };

PromptContextBlocks type # line 11387

In the first published surface (2.1.259)

The context blocks of a conversation's first user message, in the order the engine renders them: what prompt.context takes and answers alike.

  export type PromptContextBlocks = {
      /**
       * From core: `claudeMd` (when instruction files are loaded), `userEmail`,
       * `attachedProject`, `currentDate`, each only when present.
       */
      blocks: readonly PromptContextBlock[];
  };

PromptContextInput type # line 11399

In the first published surface (2.1.259) · changed in 2.1.275

The input of prompt.context: the context blocks the engine prepends to a conversation's first user message, and the files behind claudeMd.

15 lines
  export type PromptContextInput = {
      /**
       * From core: `claudeMd` (when instruction files are loaded), `userEmail`,
       * `attachedProject`, `currentDate`, each only when present.
       */
      blocks: readonly PromptContextBlock[];
      /**
       * The files behind `claudeMd`, in the order it renders them, `@` imports
       * included; empty when it renders none.
       *
       * Undefined when a hook above rewrote the `claudeMd` text: the files
       * behind that text are then unknown, and a hook adds none of its own.
       */
      instructionFiles?: readonly InstructionFile[];
  };

PromptContextResult type # line 11426

In the first published surface (2.1.259) · changed in 2.1.275

What a prompt.context hook returns: the blocks the conversation carries, in order; one left out is not sent.

By name: userEmail, attachedProject and perforceMode are sent again when the text differs, workerToolsContext too where the session's mode announces it; for gitStatus and currentDate the engine sends its own.

23 lines
  export type PromptContextResult = {
      /**
       * What the conversation carries, in order.
       *
       * A block whose name the engine does not route reaches the model in one copy,
       * made when the conversation holds none (first request, after a compaction).
       * While it stands, a later answer adds, changes and takes back none.
       *
       * @remarks Text that changes goes in `instructionFiles`, sent again when
       *   a file differs, or in a `prompt.submit` hook's `context`.
       */
      blocks: readonly PromptContextBlock[];
      /**
       * The files now behind `claudeMd`; left out, the ones from below stand.
       *
       * Kept in step with the `claudeMd` text at every link: a changed list
       * renders the text the next reader gets, a rewritten text makes the files
       * unknown from there on. Every kind is the hook's to add, drop or rewrite;
       * a `managed` file a person's own plugin or one in the `builtin` tier added
       * or rewrote keeps its text and is marked `isUnverified`.
       */
      instructionFiles?: readonly InstructionFile[];
  };

PromptDecoration type # line 11461

Added in 2.1.285 · changed in 2.1.299, 2.1.300

One styled run a surface paints over the prompt draft: [start, end) of a text, in UTF-16 code units like PromptBox cursor. Paint only.

Clamped into the text, an empty range with no virtualText dropped, and a boundary moved back to its grapheme's start. Later entries win per key. The caret's cell keeps its run's style, less a color that would hide the caret: color matching its background, or an end matching the terminal's other one.

{ start: 4, end: 8, color: 'warning', bold: true }
27 lines
  export type PromptDecoration = {
      /**
       * The first code unit painted: an integer offset into the text the list
       * travels beside, clamped into it.
       */
      start: number;
      /**
       * The code unit past the last one painted; a run with `end <= start`,
       * once clamped, paints nothing.
       */
      end: number;
      /**
       * Drawn in bold; a decoration takes no `weight`.
       */
      bold?: boolean;
      /**
       * A text drawn before the character at `start`, in this entry's own style
       * keys: never in the draft, counted by no offset, never holding the cursor.
       *
       * Typed text at `start` lands before it. A tab is drawn as four spaces, and
       * control characters but a newline are dropped. Not drawn in the empty box,
       * by a remote host, or in screen-reader mode, where it is heard as typed.
       *
       * @example { start: 7, end: 7, virtualText: ' bug', dimColor: true }
       */
      virtualText?: string;
  } & Pick<TextProps, 'color' | 'backgroundColor' | 'dimColor' | 'italic' | 'underline' | 'strikethrough'>;

PromptEditInput type # line 11493

Added in 2.1.277

The input of prompt.edit (prompt-edit/): one edit the person makes in the prompt box, as the draft before it and the splice the editor made of it.

41 lines
  export type PromptEditInput = {
      /**
       * Who edits (PromptEditOrigin): the person at the composer. Pinned:
       * `next(e)` passes it on as received.
       */
      origin: PromptEditOrigin;
      /**
       * The one key that made the edit, in `Client` `onKey`'s shape; absent for
       * a paste, a keybinding's newline and a burst of keys folded into one edit.
       *
       * Pinned: which key the person pressed is a fact, not the hook's to change.
       */
      key?: ClientKeyEvent;
      /**
       * The draft before the edit. `next({ ...e, text })` applies the edit to
       * another draft instead.
       */
      text: string;
      /**
       * Where the person's caret stood in `text` before the edit, 0 to
       * `text.length`.
       */
      cursor: number;
      /**
       * Where in `text` the edit begins: the start of the span it replaces, or
       * where what was typed goes in; a bare cursor move begins where it lands.
       */
      start: number;
      /**
       * Where the replaced span of `text` ends: `start` for an insertion or a
       * move, past it for a deletion (Backspace, a kill).
       */
      end: number;
      /**
       * What goes in between `start` and `end`: the typed or pasted text, `''` for
       * a deletion or a move.
       *
       * `next({ ...e, inputText })` puts in another; the cursor lands after it.
       */
      inputText: string;
  };

PromptEditOrigin type # line 11541

Added in 2.1.277

Who edits the prompt box at prompt.edit, as the engine stamps it where the edit starts; a closed set a matcher narrows on.

next(e) passes it on as received; no hook sets one.

  export type PromptEditOrigin = {
      /**
       * The person, typing or pasting into the main prompt box.
       */
      kind: 'composer';
  };

PromptEditResult type # line 11556

Added in 2.1.277 · changed in 2.1.285

What a prompt.edit hook returns and what next(e) resolves to: the box after the edit (PromptBox), which the editor then shows.

From core, e.text with the splice applied and the cursor after what went in. Rewrite it ({ ...r, text, cursor }) to change what lands; answer { text: e.text, cursor: e.cursor } without next to consume the key.

13 lines
  export type PromptEditResult = PromptBox & {
      /**
       * Runs to paint over this answer's own `text` (PromptDecoration); none
       * when absent.
       *
       * Kept on the same characters while the next edit's answer is pending,
       * then replaced by that answer's list (or by none).
       *
       * @example const r = await next(e)
       * return { ...r, decorations: [...(r.decorations ?? []), mine] }
       */
      decorations?: PromptDecoration[];
  };

PromptFillArgs type # line 11574

Added in 2.1.268 · changed in 2.1.275, 2.1.285, 2.1.309

prompt.fill's input as a plugin's $.prompt.fill(args) takes it: no origin (the engine sets the calling plugin's), mode optional.

33 lines
  export type PromptFillArgs = {
      /**
       * What the box is to take (PromptFillInput `text`).
       */
      text: string;
      /**
       * Where it goes (PromptFillMode); `replace` when left out.
       */
      mode?: PromptFillMode;
      /**
       * Runs to paint over `text` (PromptDecoration), offsets into `text` as
       * given; the engine moves them to where it lands. None when absent.
       *
       * Replaced by the next edit's `prompt.edit` answer; with no hook on it,
       * gone at the draft's next change.
       *
       * @example $.prompt.fill({ text: ' next', mode: 'append',
       *   decorations: [{ start: 1, end: 5, italic: true }] })
       */
      decorations?: PromptDecoration[];
      /**
       * Where the caret stands after the write, counted as PromptFilled `cursor`
       * is: an offset into the whole draft the box then holds.
       *
       * In every `mode`, hidden code points gone, accents counted as NFC; clamped
       * to the draft, moved to the start of a character or chip it falls inside;
       * not an integer is refused. Left out: past an `insert`, else at the end.
       *
       * @example const box = await $.prompt.read()
       *   await $.prompt.fill({ text: box.text.toUpperCase(), cursor: box.cursor })
       */
      cursor?: number;
  };

PromptFilled type # line 11615

Added in 2.1.275 · changed in 2.1.282, 2.1.329

What $.prompt.fill resolves to: whether the box took the text, and the box afterwards (PromptBox) as the caller's own $.prompt.read() reads it.

The box goes to a plugin whose module calls $.prompt.read, through the hooks on it; one that never does, or is refused there, gets the empty box.

27 lines
  export type PromptFilled = {
      /**
       * True once the box holds the text; false where no box could take it, a
       * hook kept it out or no app answered (PromptFillResult).
       */
      isFilled: boolean;
      /**
       * Why the box did not take the text, when the engine itself refused
       * (PromptFillResult): `no_composer` where the session binds no box,
       * `dialog` while one holds the keys, `unanswered` where an app was asked
       * and none answered, so the text may have landed. A hook's refusal carries
       * none, so a caller choosing a fallback treats an absent cause as unknown
       * and does not act as if no box existed.
       */
      refusal?: 'no_composer' | 'dialog' | 'unanswered';
      /**
       * The draft after the fill; unchanged when the fill was refused; `''` where
       * no box is drawn or the caller may not read it (see above).
       */
      text: string;
      /**
       * Where the person types next: an offset into `text`, where the call's
       * `cursor` stood it, else past the fill's text for `insert`, at the end
       * for `replace` and `append`.
       */
      cursor: number;
  };

PromptFillInput type # line 11647

Added in 2.1.268 · changed in 2.1.275, 2.1.285, 2.1.309

The input of prompt.fill (prompt-fill/): a text about to be put in the prompt box as the person's draft, over it, after it, or at the cursor.

40 lines
  export type PromptFillInput = {
      /**
       * What the box takes; the person edits it or presses Enter.
       * `next({ ...e, text })` writes another.
       *
       * The box takes it without the code points a terminal draws as nothing, as
       * the composer removes them when a person sends; all else lands as written.
       */
      text: string;
      /**
       * Where the text goes (PromptFillMode): over the draft, after it, or in at
       * the cursor. `next({ ...e, mode })` moves it; left out of a rewrite, kept.
       */
      mode: PromptFillMode;
      /**
       * Who writes (PromptFillOrigin), set by the engine where the write
       * starts. Pinned: `next(e)` passes it on as received.
       */
      origin: PromptFillOrigin;
      /**
       * Runs to paint over `text` once it lands (PromptDecoration), offsets
       * into `text`; absent when the call named none.
       *
       * What the chain passes down is what paints: a hook strips them so.
       *
       * @example on('prompt.fill', ($, e, next) =>
       *   next({ ...e, decorations: [] }))
       */
      decorations?: PromptDecoration[];
      /**
       * Where the caret stands after the write (PromptFillArgs `cursor`), an
       * offset into the whole draft; absent when the call named none.
       *
       * What the chain passes down is what moves it: left out of a rewrite, the
       * box stands the caret by `mode`.
       *
       * @example on('prompt.fill', ($, e, next) => next({ ...e, cursor: 0 }))
       */
      cursor?: number;
  };

PromptFillMode type # line 11697

Added in 2.1.275

Where a prompt.fill puts its text: over the whole draft, after it, or into it at the cursor.

replace empties the box first and leaves the cursor at the text's end; append keeps the draft and adds the text after it, cursor at the end; insert splices the text in at the cursor and moves the cursor past it, so what the person had typed stays on either side.

  export type PromptFillMode = 'replace' | 'append' | 'insert';

PromptFillOrigin type # line 11705

Added in 2.1.268

Who writes the prompt box at prompt.fill, as the engine stamps it where the write starts; a closed set a matcher narrows on.

next(e) passes it on as received; no hook sets one.

16 lines
  export type PromptFillOrigin = {
      /**
       * The engine writing the box on its own account; reserved for its own
       * sites, none of which raises `prompt.fill` as shipped.
       */
      kind: 'engine';
  } | {
      /**
       * A plugin's `$.prompt.fill`.
       */
      kind: 'plugin';
      /**
       * The filling plugin's name.
       */
      name: string;
  };

PromptFillResult type # line 11726

Added in 2.1.268 · changed in 2.1.282, 2.1.329

What a prompt.fill hook returns and what next(e) resolves to: whether the text went into the prompt box.

23 lines
  export type PromptFillResult = {
      /**
       * True once the box holds the text; false where no box can take it (a
       * dialog holds the keys, a headless session has none) or no app answered.
       *
       * A hook answering `{ isFilled: false }` without `next` keeps the text
       * out.
       */
      isFilled: boolean;
      /**
       * Why `isFilled` is false, on the three causes the engine itself
       * answers: the session binds no prompt box (`no_composer`: headless, or a
       * surface that draws its own composer), a dialog holds the keys
       * (`dialog`), so the write would land under it, unseen, or an app was
       * asked and none answered (`unanswered`), so the text may have landed. A
       * hook's own refusal carries none: the site strips a cause a hook writes
       * itself, keeping only one its `next` gave it, passed up as it was. A caller
       * branching on the cause treats an absent one as unknown and takes its
       * refusing arm; `no_composer` is the only value that says no box exists
       * to protect.
       */
      refusal?: 'no_composer' | 'dialog' | 'unanswered';
  };

PromptMedia type # line 11758

Added in 2.1.299

What $.prompt.media({ id }) answers: one attached item's bytes as the engine would send them now, or why there are none to read.

An image is read after the engine's own resize, a document as held. One call answers at most 4 MiB: size is the whole item's, next goes on. Only a hook on the prompt.submit that lists the item is answered.

50 lines
  export type PromptMedia = {
      /**
       * The item's kind.
       */
      type: 'image' | 'document';
      /**
       * The MIME type of the bytes answered (`image/png`), after the resize.
       */
      mediaType: string;
      /**
       * This call's slice of the item, base64. The slices' strings, joined in
       * order, are the whole item's base64.
       */
      base64: string;
      /**
       * How many bytes the whole item holds, decoded.
       */
      size: number;
      /**
       * The offset the following slice starts at; absent on the last one.
       */
      next?: number;
      unreadable?: undefined;
      deny?: undefined;
  } | {
      /**
       * Why the model will not receive the item as media: the engine could
       * not process it, and sends a line of text in its place.
       */
      unreadable: string;
      type?: undefined;
      mediaType?: undefined;
      base64?: undefined;
      size?: undefined;
      next?: undefined;
      deny?: undefined;
  } | {
      /**
       * Why this read is refused: no submission in flight carries the id
       * for this caller, the item is not held as inline bytes, or the offset
       * is past its end.
       */
      deny: string;
      type?: undefined;
      mediaType?: undefined;
      base64?: undefined;
      size?: undefined;
      next?: undefined;
      unreadable?: undefined;
  };
Feedback