@fungi.computer/whistle 0.0.0-stage → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,253 @@
1
+ import type { WhistleAction, WhistleAvailability, WhistleCommandProjections, WhistleFailure, WhistleJsonValue, WhistleNotice, WhistlePrompt, WhistlePromptOf, WhistlePromptAnswers, WhistleSlashArguments } from "./wire.js";
2
+ export type { WhistleAction, WhistleActionPresentation, WhistleActionSchema, WhistleAvailability, WhistleCommandProjections, WhistleCommandDefinition, WhistleFailure, WhistleJsonObject, WhistleJsonValue, WhistleNotice, WhistleNoticeLink, WhistlePrompt, WhistlePromptOption, WhistleSlashArguments, WhistleSlashWord, } from "./wire.js";
3
+ /** The trusted host origin entering the single execution door. */
4
+ export type WhistleExecutionOrigin = "agent" | "browser" | "keyboard" | "menu" | "palette" | "programmatic" | "slash" | "terminal";
5
+ /** A source-owned command's execution callback, invoked only through the execution door. */
6
+ export type WhistleCommandHandler<Arguments, Result> = {
7
+ /** Runs the command for one execution input and returns its result. */
8
+ bivarianceHack(input: WhistleExecutionInput<Arguments>): Result | undefined | Promise<Result | undefined>;
9
+ }["bivarianceHack"];
10
+ /** The answer type for one prompt kind. */
11
+ export type WhistlePromptAnswer<Prompt extends WhistlePrompt> = WhistlePromptAnswers[Prompt["type"]];
12
+ /**
13
+ * A human conversation attached to one execution. `prompt` rejects when the
14
+ * human cancels; `signal` aborts when the whole interaction is dismissed.
15
+ */
16
+ export type WhistleInteraction = Readonly<{
17
+ /** Aborted when the human dismisses the interaction. */
18
+ signal: AbortSignal;
19
+ /**
20
+ * Ask one question and wait for its answer. `signal` withdraws just this
21
+ * question, e.g. when an out-of-band callback answers it first.
22
+ */
23
+ prompt: <Kind extends WhistlePrompt["type"]>(prompt: WhistlePromptOf<Kind>, options?: Readonly<{
24
+ signal?: AbortSignal;
25
+ }>) => Promise<WhistlePromptAnswers[Kind]>;
26
+ /** Show one status update. */
27
+ notify: (notice: WhistleNotice) => void;
28
+ }>;
29
+ /** How an execution with an attached interaction ended. */
30
+ export type WhistleInteractionEnd = Readonly<{
31
+ /** The handler finished. */
32
+ status: "handled";
33
+ }> | Readonly<{
34
+ /** The human dismissed the interaction. */
35
+ status: "cancelled";
36
+ }> | Readonly<{
37
+ /** The handler failed. */
38
+ status: "failed";
39
+ /** Portable failure message for the human. */
40
+ message: string;
41
+ }>;
42
+ /** One interaction a presenter opened for one execution. */
43
+ export type WhistleInteractionSession = Readonly<{
44
+ /** The interaction handed to the command handler. */
45
+ interaction: WhistleInteraction;
46
+ /** Called exactly once when the handler settles. */
47
+ settle: (end: WhistleInteractionEnd) => void;
48
+ }>;
49
+ /**
50
+ * A mounted client that can render interactions. Whistle opens one session per
51
+ * human execution that has no caller-supplied interaction.
52
+ */
53
+ export type WhistlePresenter = (request: Readonly<{
54
+ /** Canonical namespace-local command identity. */
55
+ commandId: string;
56
+ /** Human-facing command title. */
57
+ title: string;
58
+ /** Execute the same command again with the same input. */
59
+ retry: () => void;
60
+ }>) => WhistleInteractionSession;
61
+ /** The already-typed input supplied to a command handler. */
62
+ export type WhistleExecutionInput<Arguments = unknown> = Readonly<{
63
+ /** The host origin requesting execution. */
64
+ origin: WhistleExecutionOrigin;
65
+ /** Typed action arguments, when this execution carries user input. */
66
+ arguments?: Arguments;
67
+ /** Host-owned cancellation for this invocation; never part of projections. */
68
+ signal?: AbortSignal;
69
+ /**
70
+ * Human conversation for this invocation. Supplied by the caller, or by the
71
+ * runtime's registered presenter for human origins; absent for agents.
72
+ */
73
+ interaction?: WhistleInteraction;
74
+ }>;
75
+ /** An owning handler's explicit failure code and optional structured details. */
76
+ export declare class WhistleActionError extends Error {
77
+ /** Stable failure identity supplied by the handler owner. */
78
+ readonly code: string;
79
+ /** Optional JSON context safe to return to the caller. */
80
+ readonly details?: WhistleJsonValue | undefined;
81
+ constructor(
82
+ /** Stable failure identity supplied by the handler owner. */
83
+ code: string, message: string,
84
+ /** Optional JSON context safe to return to the caller. */
85
+ details?: WhistleJsonValue | undefined);
86
+ }
87
+ /** The normalized result of one command execution request. */
88
+ export type WhistleExecutionOutcome<Result = unknown> = Extract<WhistleAvailability, {
89
+ /** Current host facts prevented dispatch to the handler. */
90
+ status: "unavailable";
91
+ }> | Readonly<{
92
+ /** The admitted handler completed synchronously or asynchronously. */
93
+ status: "handled";
94
+ /** The typed handler result, when it produced one. */
95
+ result?: Result;
96
+ }> | Readonly<{
97
+ /** The runtime was closed before this execution began. */
98
+ status: "closed";
99
+ }> | Readonly<{
100
+ /** No currently admitted command has the requested identity. */
101
+ status: "missing";
102
+ }> | Readonly<{
103
+ /** The requested command identity is blank. */
104
+ status: "invalid";
105
+ }> | Readonly<{
106
+ /** The normalized error raised by the admitted handler. */
107
+ error: WhistleFailure;
108
+ /** The admitted handler failed. */
109
+ status: "failed";
110
+ }>;
111
+ /** A valid contribution was attempted after the runtime closed. */
112
+ export declare class WhistleClosedError extends Error {
113
+ /** Construct the provisional error for a valid post-close contribution. */
114
+ constructor();
115
+ }
116
+ /** One semantic command definition. */
117
+ export type WhistleCommand<Arguments = unknown, Result = unknown> = Readonly<{
118
+ /** The source-local command identity segment. */
119
+ id: string;
120
+ /** Human-facing command title. */
121
+ title: string;
122
+ /** Human-facing command category. */
123
+ category: string;
124
+ /** Optional human-facing command description. */
125
+ description?: string | undefined;
126
+ /** Explicit projection membership and per-surface metadata. */
127
+ projections?: WhistleCommandProjections;
128
+ /** Typed action contract and renderer-neutral presentation hint. */
129
+ action?: WhistleAction;
130
+ /** Read current host facts on discovery and immediately before dispatch. */
131
+ availability?: () => WhistleAvailability;
132
+ /** Host-owned callback invoked only through the execution door. */
133
+ handler: WhistleCommandHandler<Arguments, Result>;
134
+ }>;
135
+ /** One contribution of source-owned commands to a namespace. */
136
+ export type WhistleContribution = Readonly<{
137
+ /** Source authority identity for this contribution. */
138
+ sourceId: string;
139
+ /** Namespace receiving this contribution. */
140
+ namespace: string;
141
+ /**
142
+ * Focus scope, e.g. one mounted App window. Omitted means global. Slash
143
+ * aliases are unique within one scope; {@link scopeSnapshot} lets a focused
144
+ * scope's alias or binding shadow the same global one.
145
+ */
146
+ scope?: string;
147
+ /** Ordered command definitions in this contribution. */
148
+ commands: readonly WhistleCommand<never>[];
149
+ }>;
150
+ /** Shared immutable metadata carried by each projection row. */
151
+ export type WhistleProjectionRow = Readonly<{
152
+ /** Canonical namespace-local command identity. */
153
+ commandId: string;
154
+ /** Source authority identity. */
155
+ sourceId: string;
156
+ /** Focus scope of the contribution; omitted for global rows. */
157
+ scope?: string;
158
+ /** Human-facing command title. */
159
+ title: string;
160
+ /** Human-facing command category. */
161
+ category: string;
162
+ /** Optional human-facing command description. */
163
+ description?: string | undefined;
164
+ /** Explicit order within the containing surface. */
165
+ order: number;
166
+ /** Typed action contract and renderer-neutral presentation hint. */
167
+ action?: WhistleAction;
168
+ /** An unavailable command stays discoverable with its explanation. */
169
+ availability: WhistleAvailability;
170
+ }>;
171
+ /** Immutable agent snapshot row composed from the schema-owned action data. */
172
+ export type WhistleAgentProjection = Omit<WhistleProjectionRow, "action"> & Readonly<{
173
+ /** Semantic inputs and outputs; client presentation stays local. */
174
+ action?: Pick<WhistleAction, "inputSchema" | "outputSchema">;
175
+ /** Optional host-owned key label. */
176
+ keybind?: string;
177
+ }>;
178
+ /** One binding value projected from a command. */
179
+ export type WhistleBindingProjection = WhistleProjectionRow & Readonly<{
180
+ /** One binding value exposed for the command. */
181
+ binding: string;
182
+ }>;
183
+ /** One palette value projected from a command. */
184
+ export type WhistlePaletteProjection = WhistleProjectionRow;
185
+ /** One slash alias projected from a command. */
186
+ export type WhistleSlashProjection = WhistleProjectionRow & Readonly<{
187
+ /** One slash alias exposed for the command. */
188
+ alias: string;
189
+ /** How text after the alias becomes arguments, when the command takes any. */
190
+ arguments?: WhistleSlashArguments;
191
+ }>;
192
+ /** One help value projected from a command. */
193
+ export type WhistleHelpProjection = WhistleProjectionRow;
194
+ /** One menu value projected from a command. */
195
+ export type WhistleMenuProjection = WhistleProjectionRow;
196
+ /** The six immutable views of one semantic command graph. */
197
+ export type WhistleSnapshot = Readonly<{
198
+ /** Binding rows derived from the semantic graph. */
199
+ bindings: readonly WhistleBindingProjection[];
200
+ /** Palette rows derived from the semantic graph. */
201
+ palette: readonly WhistlePaletteProjection[];
202
+ /** Slash rows derived from the semantic graph. */
203
+ slash: readonly WhistleSlashProjection[];
204
+ /** Help rows derived from the semantic graph. */
205
+ help: readonly WhistleHelpProjection[];
206
+ /** Menu rows derived from the semantic graph. */
207
+ menu: readonly WhistleMenuProjection[];
208
+ /** Agent rows derived from the semantic graph. */
209
+ agent: readonly WhistleAgentProjection[];
210
+ }>;
211
+ /** An idempotent lease for one contribution generation. */
212
+ export type WhistleContributionLease = Readonly<{
213
+ /** Atomically replace this generation's commands without changing ownership. */
214
+ update: (commands: WhistleContribution["commands"]) => void;
215
+ /** Dispose this contribution generation. */
216
+ dispose: () => void;
217
+ }>;
218
+ /** The provisional Whistle semantic runtime seam. */
219
+ export type WhistleRuntime = Readonly<{
220
+ /** Admit one source-owned contribution. */
221
+ contribute: (contribution: WhistleContribution) => WhistleContributionLease;
222
+ /**
223
+ * Synchronously release the live graph into the shared empty closed snapshot.
224
+ * Repeated calls are no-ops.
225
+ *
226
+ * @returns `undefined`; close produces no value.
227
+ */
228
+ close: () => undefined;
229
+ /** Execute one currently admitted command through the shared door. */
230
+ execute: (commandId: string, input: WhistleExecutionInput) => Promise<WhistleExecutionOutcome>;
231
+ /** Pull the current immutable semantic snapshot. */
232
+ snapshot: () => WhistleSnapshot;
233
+ /** Observe coherent semantic graph changes. */
234
+ subscribe: (listener: () => void) => () => void;
235
+ /**
236
+ * Register the mounted client that renders interactions for human
237
+ * executions. The newest registration wins until its disposer runs.
238
+ */
239
+ present: (presenter: WhistlePresenter) => () => void;
240
+ }>;
241
+ export { createWhistleKeymapAdapter, type WhistleKeymapAdapter, type WhistleKeymapBinding, type WhistleKeymapCommand, type WhistleKeymapHost, type WhistleKeymapLayer, } from "./keymap.js";
242
+ /**
243
+ * The projection for one focused scope: global rows plus the focused
244
+ * scope's rows. A focused slash alias or binding shadows the same global one.
245
+ * Agent rows follow the same scope filter; the complete runtime remains whole.
246
+ *
247
+ * @param snapshot - A complete runtime snapshot.
248
+ * @param scope - The focused scope, or `null` when nothing scoped is focused.
249
+ * @returns A frozen snapshot of globals plus the selected scope.
250
+ */
251
+ export declare function scopeSnapshot(snapshot: WhistleSnapshot, scope: string | null): WhistleSnapshot;
252
+ /** Construct the provisional semantic runtime shell. */
253
+ export declare function createWhistle(): WhistleRuntime;