Skip to content
API reference

whistle

Import
import * as api from "@fungi.computer/whistle";
Kind Export Description
class WhistleActionError An owning handler’s explicit failure code and optional structured details.
class WhistleClosedError A valid contribution was attempted after the runtime closed.
type alias WhistleExecutionOrigin The trusted host origin entering the single execution door.
type alias WhistleCommandHandler A source-owned command’s execution callback, invoked only through the execution door.
type alias WhistlePromptAnswer The answer type for one prompt kind.
type alias WhistleInteraction A human conversation attached to one execution. prompt rejects when the human cancels; signal aborts when the whole interaction is dismissed.
type alias WhistleInteractionEnd How an execution with an attached interaction ended.
type alias WhistleInteractionSession One interaction a presenter opened for one execution.
type alias WhistlePresenter A mounted client that can render interactions. Whistle opens one session per human execution that has no caller-supplied interaction.
type alias WhistleExecutionInput The already-typed input supplied to a command handler.
type alias WhistleExecutionOutcome The normalized result of one command execution request.
type alias WhistleCommand One semantic command definition.
type alias WhistleContribution One contribution of source-owned commands to a namespace.
type alias WhistleProjectionRow Shared immutable metadata carried by each projection row.
type alias WhistleAgentProjection Immutable agent snapshot row composed from the schema-owned action data.
type alias WhistleBindingProjection One binding value projected from a command.
type alias WhistlePaletteProjection One palette value projected from a command.
type alias WhistleSlashProjection One slash alias projected from a command.
type alias WhistleHelpProjection One help value projected from a command.
type alias WhistleMenuProjection One menu value projected from a command.
type alias WhistleSnapshot The six immutable views of one semantic command graph.
type alias WhistleContributionLease An idempotent lease for one contribution generation.
type alias WhistleRuntime The provisional Whistle semantic runtime seam.
type alias WhistleKeymapAdapter Lifecycle operations for a projection into a maintained host keymap.
type alias WhistleKeymapBinding One physical key string mapped to a Whistle command identifier.
type alias WhistleKeymapCommand Host callback that executes one semantic Whistle command.
type alias WhistleKeymapLayer Binding and command records accepted by a maintained keymap host.
type alias WhistleKeymapHost Minimal registration surface implemented by a maintained host keymap.
function scopeSnapshot() The projection for one focused scope: global rows plus the focused scope’s rows. A focused slash alias or binding shadows the same global one. Agent rows follow the same scope filter; the complete runtime remains whole.
function createWhistle() Construct the provisional semantic runtime shell.
function createWhistleKeymapAdapter() Project Whistle bindings into a host-created maintained OpenTUI keymap.

An owning handler’s explicit failure code and optional structured details.

  • Error
Signature
new WhistleActionError(
code,
message,
details?
): WhistleActionError;
Parameter Type Description
code string Stable failure identity supplied by the handler owner.
message string -
details? WhistleJsonValue Optional JSON context safe to return to the caller.

WhistleActionError

Signature
Error.constructor;
Signature
readonly code: string;

Stable failure identity supplied by the handler owner.

Signature
readonly optional details?: WhistleJsonValue;

Optional JSON context safe to return to the caller.


A valid contribution was attempted after the runtime closed.

  • Error
Signature
new WhistleClosedError(): WhistleClosedError;

Construct the provisional error for a valid post-close contribution.

WhistleClosedError

Signature
Error.constructor;

WhistleExecutionOrigintype alias

Section titled “WhistleExecutionOrigin”
Signature
type WhistleExecutionOrigin =
| "agent"
| "browser"
| "keyboard"
| "menu"
| "palette"
| "programmatic"
| "slash"
| "terminal";

The trusted host origin entering the single execution door.


WhistleCommandHandlertype alias

Section titled “WhistleCommandHandler”
Signature
type WhistleCommandHandler<Arguments, Result> = object["bivarianceHack"];

A source-owned command’s execution callback, invoked only through the execution door.

Type Parameter
Arguments
Result

WhistlePromptAnswertype alias

Section titled “WhistlePromptAnswer”
Signature
type WhistlePromptAnswer<Prompt> = WhistlePromptAnswers[Prompt["type"]];

The answer type for one prompt kind.

Type Parameter
Prompt extends WhistlePrompt

WhistleInteractiontype alias

Section titled “WhistleInteraction”
Signature
type WhistleInteraction = Readonly<{
signal: AbortSignal;
prompt: <Kind>(prompt, options?) => Promise<WhistlePromptAnswers[Kind]>;
notify: (notice) => void;
run: <Result>(operation) => Promise<Result>;
}>;

A human conversation attached to one execution. prompt rejects when the human cancels; signal aborts when the whole interaction is dismissed.


WhistleInteractionEndtype alias

Section titled “WhistleInteractionEnd”
Signature
type WhistleInteractionEnd =
| Readonly<{
status: "handled";
}>
| Readonly<{
status: "cancelled";
}>
| Readonly<{
status: "failed";
message: string;
}>;

How an execution with an attached interaction ended.


WhistleInteractionSessiontype alias

Section titled “WhistleInteractionSession”
Signature
type WhistleInteractionSession = Readonly<{
interaction: WhistleInteraction;
settle: (end) => void;
}>;

One interaction a presenter opened for one execution.


WhistlePresentertype alias

Section titled “WhistlePresenter”
Signature
type WhistlePresenter = (request) => WhistleInteractionSession;

A mounted client that can render interactions. Whistle opens one session per human execution that has no caller-supplied interaction.

Parameter Type
request Readonly<{ commandId: string; title: string; }>

WhistleInteractionSession


WhistleExecutionInputtype alias

Section titled “WhistleExecutionInput”
Signature
type WhistleExecutionInput<Arguments> = Readonly<{
origin: WhistleExecutionOrigin;
arguments?: Arguments;
signal?: AbortSignal;
interaction?: WhistleInteraction;
}>;

The already-typed input supplied to a command handler.

Type Parameter Default type
Arguments unknown

WhistleExecutionOutcometype alias

Section titled “WhistleExecutionOutcome”
Signature
type WhistleExecutionOutcome<Result> =
| Extract<
WhistleAvailability,
{
status: "unavailable";
}
>
| Readonly<{
status: "handled";
result?: Result;
}>
| Readonly<{
status: "closed";
}>
| Readonly<{
status: "missing";
}>
| Readonly<{
status: "invalid";
}>
| Readonly<{
error: WhistleFailure;
status: "failed";
}>;

The normalized result of one command execution request.

Type Parameter Default type
Result unknown

WhistleCommandtype alias

Section titled “WhistleCommand”
Signature
type WhistleCommand<Arguments, Result> = Readonly<{
id: string;
title: string;
category: string;
description?: string;
projections?: WhistleCommandProjections;
action?: WhistleAction;
availability?: () => WhistleAvailability;
handler: WhistleCommandHandler<Arguments, Result>;
}>;

One semantic command definition.

Type Parameter Default type
Arguments unknown
Result unknown

WhistleContributiontype alias

Section titled “WhistleContribution”
Signature
type WhistleContribution = Readonly<{
sourceId: string;
namespace: string;
scope?: string;
commands: readonly WhistleCommand<never>[];
}>;

One contribution of source-owned commands to a namespace.


WhistleProjectionRowtype alias

Section titled “WhistleProjectionRow”
Signature
type WhistleProjectionRow = Readonly<{
commandId: string;
sourceId: string;
scope?: string;
title: string;
category: string;
description?: string;
order: number;
action?: WhistleAction;
availability: WhistleAvailability;
}>;

Shared immutable metadata carried by each projection row.


WhistleAgentProjectiontype alias

Section titled “WhistleAgentProjection”
Signature
type WhistleAgentProjection = Omit<WhistleProjectionRow, "action"> &
Readonly<{
action?: Pick<WhistleAction, "inputSchema" | "outputSchema">;
keybind?: string;
}>;

Immutable agent snapshot row composed from the schema-owned action data.


WhistleBindingProjectiontype alias

Section titled “WhistleBindingProjection”
Signature
type WhistleBindingProjection = WhistleProjectionRow &
Readonly<{
binding: string;
}>;

One binding value projected from a command.


WhistlePaletteProjectiontype alias

Section titled “WhistlePaletteProjection”
Signature
type WhistlePaletteProjection = WhistleProjectionRow;

One palette value projected from a command.


WhistleSlashProjectiontype alias

Section titled “WhistleSlashProjection”
Signature
type WhistleSlashProjection = WhistleProjectionRow &
Readonly<{
alias: string;
consumesDraft?: boolean;
arguments?: WhistleSlashArguments;
}>;

One slash alias projected from a command.


WhistleHelpProjectiontype alias

Section titled “WhistleHelpProjection”
Signature
type WhistleHelpProjection = WhistleProjectionRow;

One help value projected from a command.


WhistleMenuProjectiontype alias

Section titled “WhistleMenuProjection”
Signature
type WhistleMenuProjection = WhistleProjectionRow;

One menu value projected from a command.


WhistleSnapshottype alias

Section titled “WhistleSnapshot”
Signature
type WhistleSnapshot = Readonly<{
bindings: readonly WhistleBindingProjection[];
palette: readonly WhistlePaletteProjection[];
slash: readonly WhistleSlashProjection[];
help: readonly WhistleHelpProjection[];
menu: readonly WhistleMenuProjection[];
agent: readonly WhistleAgentProjection[];
}>;

The six immutable views of one semantic command graph.


WhistleContributionLeasetype alias

Section titled “WhistleContributionLease”
Signature
type WhistleContributionLease = Readonly<{
update: (commands) => void;
dispose: () => void;
}>;

An idempotent lease for one contribution generation.


WhistleRuntimetype alias

Section titled “WhistleRuntime”
Signature
type WhistleRuntime = Readonly<{
contribute: (contribution) => WhistleContributionLease;
close: () => undefined;
execute: (commandId, input) => Promise<WhistleExecutionOutcome>;
snapshot: () => WhistleSnapshot;
subscribe: (listener) => () => void;
present: (presenter) => () => void;
}>;

The provisional Whistle semantic runtime seam.


WhistleKeymapAdaptertype alias

Section titled “WhistleKeymapAdapter”
Signature
type WhistleKeymapAdapter = Readonly<{
cleanup: () => void;
}>;

Lifecycle operations for a projection into a maintained host keymap.


WhistleKeymapBindingtype alias

Section titled “WhistleKeymapBinding”
Signature
type WhistleKeymapBinding = Readonly<{
cmd: string;
key: string;
}>;

One physical key string mapped to a Whistle command identifier.


WhistleKeymapCommandtype alias

Section titled “WhistleKeymapCommand”
Signature
type WhistleKeymapCommand = Readonly<{
name: string;
run: () => Promise<boolean>;
}>;

Host callback that executes one semantic Whistle command.


WhistleKeymapLayertype alias

Section titled “WhistleKeymapLayer”
Signature
type WhistleKeymapLayer = Readonly<{
bindings: readonly WhistleKeymapBinding[];
commands: readonly WhistleKeymapCommand[];
}>;

Binding and command records accepted by a maintained keymap host.


WhistleKeymapHosttype alias

Section titled “WhistleKeymapHost”
Signature
type WhistleKeymapHost = Readonly<{
registerLayer: (layer) => () => void;
}>;

Minimal registration surface implemented by a maintained host keymap.

scopeSnapshot()function

Section titled “scopeSnapshot()”
Signature
function scopeSnapshot(snapshot, scope): WhistleSnapshot;

The projection for one focused scope: global rows plus the focused scope’s rows. A focused slash alias or binding shadows the same global one. Agent rows follow the same scope filter; the complete runtime remains whole.

Parameter Type Description
snapshot WhistleSnapshot A complete runtime snapshot.
scope string | null The focused scope, or null when nothing scoped is focused.

WhistleSnapshot

A frozen snapshot of globals plus the selected scope.


createWhistle()function

Section titled “createWhistle()”
Signature
function createWhistle(): WhistleRuntime;

Construct the provisional semantic runtime shell.

WhistleRuntime


createWhistleKeymapAdapter()function

Section titled “createWhistleKeymapAdapter()”
Signature
function createWhistleKeymapAdapter(
keymap,
whistle,
origin,
): WhistleKeymapAdapter;

Project Whistle bindings into a host-created maintained OpenTUI keymap.

Parameter Type
keymap WhistleKeymapHost
whistle Pick<WhistleRuntime, "snapshot" | "subscribe" | "execute">
origin WhistleExecutionOrigin

WhistleKeymapAdapter

Re-exports WhistleAction


Re-exports WhistleActionPresentation


Re-exports WhistleActionSchema


Re-exports WhistleAnswerValue


Re-exports WhistleAvailability


Re-exports WhistleCommandProjections


Re-exports WhistleCommandDefinition


Re-exports WhistleDecisionAnswer


Re-exports WhistleFailure


Re-exports WhistleJsonObject


Re-exports WhistleJsonValue


Re-exports WhistleNotice


Re-exports WhistleNoticeLink


Re-exports WhistlePrompt


Re-exports WhistlePromptOption


Re-exports WhistleSlashArguments


Re-exports WhistleSlashWord