@inflatable-cookie/longhorn 0.6.0 → 0.7.0
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.
- package/README.md +2 -2
- package/package.json +1 -7
- package/src/agent-control/generated/protocol.ts +228 -0
- package/src/agent-control/index.ts +1 -5
- package/src/agent-control/selection.ts +10 -8
- package/src/agent-control/shim.ts +149 -77
- package/src/bridge/generated/fields.ts +1 -1
- package/src/bridge/generated/protocol.ts +55 -4
- package/src/bridge/generated/variant-fields.ts +1 -1
- package/src/bridge/job.ts +49 -2
- package/src/bridge/runtime/connection.ts +11 -14
- package/src/bridge/stream/connection.ts +14 -23
- package/src/bridge/stream/tracker.ts +5 -0
- package/src/bridge/supervision.ts +102 -80
- package/src/bridge/validation/base.ts +7 -27
- package/src/bridge/validation/negotiation.ts +1 -6
- package/src/bridge/validation/operations.ts +2 -14
- package/src/commands/client.ts +16 -2
- package/src/commands/controller.ts +96 -58
- package/src/commands/generated/fields.ts +4 -4
- package/src/commands/generated/protocol.ts +24 -1
- package/src/commands/generated/variant-fields.ts +1 -1
- package/src/commands/keyboard.ts +4 -13
- package/src/commands/physical-code.ts +11 -0
- package/src/commands/ports.ts +2 -1
- package/src/commands/projectors.ts +52 -29
- package/src/commands/validation.ts +408 -188
- package/src/config/client.ts +3 -3
- package/src/config/generated/base.ts +22 -6
- package/src/config/generated/fields.ts +2 -1
- package/src/config/generated/label-template.ts +1 -1
- package/src/config/generated/labels.ts +1 -1
- package/src/config/generated/protocol.ts +1 -1
- package/src/config/generated/restore.ts +35 -12
- package/src/config/generated/variant-fields.ts +1 -1
- package/src/config/validation/commands.ts +11 -13
- package/src/config/validation/outcomes.ts +147 -46
- package/src/config/validation/primitives.ts +11 -39
- package/src/config/validation/projection.ts +44 -44
- package/src/core/connection.ts +124 -29
- package/src/core/controller-lifecycle.ts +144 -0
- package/src/core/generated/identifiers.ts +4 -0
- package/src/core/identifiers.ts +40 -0
- package/src/core/index.ts +10 -1
- package/src/core/json-value.ts +58 -0
- package/src/core/listeners.ts +35 -0
- package/src/core/record.ts +76 -0
- package/src/core/transport.ts +10 -1
- package/src/core/wire-copy.ts +1 -0
- package/src/history/client.ts +11 -7
- package/src/history/controller.ts +72 -74
- package/src/history/generated/fields.ts +2 -1
- package/src/history/generated/protocol.ts +8 -5
- package/src/history/generated/variant-fields.ts +1 -1
- package/src/history/ports.ts +7 -2
- package/src/history/validation.ts +15 -37
- package/src/history-tree/client.ts +15 -13
- package/src/history-tree/controller.ts +131 -90
- package/src/history-tree/generated/fields.ts +3 -1
- package/src/history-tree/generated/protocol.ts +43 -7
- package/src/history-tree/generated/variant-fields.ts +7 -1
- package/src/history-tree/ports.ts +9 -4
- package/src/history-tree/validation.ts +44 -35
- package/src/layout/generated/protocol.ts +2 -1
- package/src/layout/generated/variant-fields.ts +47 -0
- package/src/layout/index.ts +1 -1
- package/src/layout/ratio.ts +9 -2
- package/src/layout/validation.ts +88 -13
- package/src/licence/client.ts +11 -7
- package/src/licence/controller.ts +64 -43
- package/src/licence/generated/fields.ts +2 -1
- package/src/licence/generated/protocol.ts +8 -4
- package/src/licence/generated/variant-fields.ts +1 -1
- package/src/licence/key.ts +2 -6
- package/src/licence/ports.ts +7 -2
- package/src/licence/validation.ts +27 -20
- package/src/native-content/client.ts +32 -1
- package/src/native-content/generated/fields.ts +4 -4
- package/src/native-content/generated/protocol.ts +16 -5
- package/src/native-content/generated/variant-fields.ts +1 -1
- package/src/native-content/ports.ts +2 -1
- package/src/native-content/validation/base.ts +16 -46
- package/src/native-content/validation/messages.ts +3 -0
- package/src/notifications/client.ts +17 -39
- package/src/notifications/controller.ts +266 -165
- package/src/notifications/generated/fields.ts +2 -1
- package/src/notifications/generated/labels.ts +1 -1
- package/src/notifications/generated/protocol.ts +5 -1
- package/src/notifications/generated/variant-fields.ts +1 -1
- package/src/notifications/ports.ts +2 -1
- package/src/notifications/tone.ts +1 -1
- package/src/notifications/validation.ts +41 -51
- package/src/operation/bridge.ts +79 -19
- package/src/operation/client.ts +17 -45
- package/src/operation/controller.ts +38 -59
- package/src/operation/generated/fields.ts +2 -1
- package/src/operation/generated/labels.ts +1 -1
- package/src/operation/generated/protocol.ts +5 -1
- package/src/operation/generated/variant-fields.ts +1 -1
- package/src/operation/ports.ts +2 -1
- package/src/operation/validation.ts +48 -50
- package/src/settings/connection.ts +10 -14
- package/src/settings/generated/fields.ts +2 -1
- package/src/settings/generated/protocol.ts +5 -1
- package/src/settings/generated/variant-fields.ts +1 -1
- package/src/settings/validation/authority.ts +2 -2
- package/src/settings/validation/command.ts +5 -4
- package/src/settings/validation/primitives.ts +32 -67
- package/src/settings/validation/registry.ts +13 -11
- package/src/surface-transfer/generated/fields.ts +1 -1
- package/src/surface-transfer/generated/protocol.ts +3 -3
- package/src/surface-transfer/generated/variant-fields.ts +1 -1
- package/src/surface-transfer/validation.ts +76 -53
- package/src/surfaces/client.ts +26 -38
- package/src/surfaces/generated/fields.ts +1 -1
- package/src/surfaces/generated/protocol.ts +1 -1
- package/src/surfaces/generated/variant-fields.ts +1 -1
- package/src/surfaces/validation.ts +198 -61
- package/src/transfer/connection.ts +25 -39
- package/src/transfer/generated/fields.ts +2 -1
- package/src/transfer/generated/protocol.ts +9 -1
- package/src/transfer/generated/variant-fields.ts +1 -1
- package/src/transfer/index.ts +8 -1
- package/src/transfer/payload.ts +12 -9
- package/src/transfer/validation.ts +146 -60
- package/src/update/client.ts +43 -16
- package/src/update/controller.ts +187 -104
- package/src/update/generated/fields.ts +2 -1
- package/src/update/generated/protocol.ts +19 -7
- package/src/update/generated/variant-fields.ts +3 -2
- package/src/update/ports.ts +11 -7
- package/src/update/serialized.ts +8 -6
- package/src/update/validation.ts +18 -28
package/src/commands/client.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { attempt, disposeAll } from "../core/listeners.ts";
|
|
1
2
|
import {
|
|
2
3
|
assertValidCommandAvailabilitySnapshot,
|
|
3
4
|
assertValidCommandCatalogue,
|
|
@@ -22,6 +23,7 @@ import type {
|
|
|
22
23
|
CommandExecutionIntent,
|
|
23
24
|
CommandExecutionOutcome,
|
|
24
25
|
CommandPorts,
|
|
26
|
+
CommandSnapshotPort,
|
|
25
27
|
CommandUnlisten,
|
|
26
28
|
} from "./ports.ts";
|
|
27
29
|
|
|
@@ -57,7 +59,7 @@ export class CommandClient {
|
|
|
57
59
|
async listen(invalidate: () => void): Promise<ReadonlyArray<CommandUnlisten>> {
|
|
58
60
|
const results = await Promise.allSettled(
|
|
59
61
|
[this.#ports.catalogue, this.#ports.keymap, this.#ports.availability].flatMap((port) =>
|
|
60
|
-
port
|
|
62
|
+
registrationOf(port, invalidate),
|
|
61
63
|
),
|
|
62
64
|
);
|
|
63
65
|
const unlisten = results.flatMap((result) =>
|
|
@@ -67,7 +69,7 @@ export class CommandClient {
|
|
|
67
69
|
(result): result is PromiseRejectedResult => result.status === "rejected",
|
|
68
70
|
);
|
|
69
71
|
if (failure !== undefined) {
|
|
70
|
-
await
|
|
72
|
+
await disposeAll(unlisten);
|
|
71
73
|
throw failure.reason;
|
|
72
74
|
}
|
|
73
75
|
return unlisten;
|
|
@@ -111,6 +113,18 @@ export class CommandClient {
|
|
|
111
113
|
}
|
|
112
114
|
}
|
|
113
115
|
|
|
116
|
+
/**
|
|
117
|
+
* Starts one port's listener inside a promise, so its registration joins the
|
|
118
|
+
* settled set whether it returns, resolves or throws synchronously.
|
|
119
|
+
*/
|
|
120
|
+
function registrationOf(
|
|
121
|
+
port: CommandSnapshotPort<unknown>,
|
|
122
|
+
invalidate: () => void,
|
|
123
|
+
): Array<Promise<CommandUnlisten>> {
|
|
124
|
+
const listen = port.listen?.bind(port);
|
|
125
|
+
return listen === undefined ? [] : [attempt(() => listen(invalidate))];
|
|
126
|
+
}
|
|
127
|
+
|
|
114
128
|
export class CommandKeymapReadOnlyError extends Error {
|
|
115
129
|
constructor() {
|
|
116
130
|
super("command keymap mutation is not composed");
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { ControllerLifecycle } from "../core/controller-lifecycle.ts";
|
|
1
2
|
import { CommandClient } from "./client.ts";
|
|
3
|
+
import { COMMAND_KEYMAP_PROTOCOL_VERSION } from "./generated/protocol.ts";
|
|
2
4
|
import type {
|
|
3
5
|
CommandInvocation,
|
|
4
6
|
CommandKeymapMutationResult,
|
|
@@ -12,7 +14,6 @@ import type {
|
|
|
12
14
|
CommandExecutionOutcome,
|
|
13
15
|
CommandExecutionSource,
|
|
14
16
|
CommandPorts,
|
|
15
|
-
CommandUnlisten,
|
|
16
17
|
} from "./ports.ts";
|
|
17
18
|
import { joinCommandState, projectCommandSurfaces, searchCommands } from "./projectors.ts";
|
|
18
19
|
import type { CommandJoinedState, CommandSurfaceProjection } from "./projectors.ts";
|
|
@@ -41,6 +42,11 @@ export type CommandMutationStatus =
|
|
|
41
42
|
| { readonly kind: "conflict"; readonly detail: string }
|
|
42
43
|
| { readonly kind: "failed"; readonly error: unknown };
|
|
43
44
|
|
|
45
|
+
/** The newest search failed. The loaded commands stay authoritative. */
|
|
46
|
+
export interface CommandSearchFailure {
|
|
47
|
+
readonly error: unknown;
|
|
48
|
+
}
|
|
49
|
+
|
|
44
50
|
export interface CommandControllerOptions {
|
|
45
51
|
readonly ports: CommandPorts;
|
|
46
52
|
readonly platform: CommandPlatform;
|
|
@@ -60,13 +66,13 @@ export class CommandController {
|
|
|
60
66
|
#model: CommandJoinedState | undefined;
|
|
61
67
|
#projection: CommandSurfaceProjection | undefined;
|
|
62
68
|
#searchHits: ReadonlyArray<CommandSearchHit> = [];
|
|
69
|
+
#searchFailure: CommandSearchFailure | undefined;
|
|
63
70
|
#query = "";
|
|
64
71
|
#draft: CommandKeymapPatch | undefined;
|
|
65
|
-
#unlisten: Array<CommandUnlisten> = [];
|
|
66
|
-
#lifecycleRevision = 0;
|
|
67
72
|
#loadRevision = 0;
|
|
73
|
+
#mutationRevision = 0;
|
|
68
74
|
#searchRevision = 0;
|
|
69
|
-
#
|
|
75
|
+
readonly #lifecycle = new ControllerLifecycle();
|
|
70
76
|
|
|
71
77
|
constructor(options: CommandControllerOptions) {
|
|
72
78
|
this.#client = new CommandClient(options.ports);
|
|
@@ -98,6 +104,10 @@ export class CommandController {
|
|
|
98
104
|
return this.#searchHits;
|
|
99
105
|
}
|
|
100
106
|
|
|
107
|
+
get searchFailure(): CommandSearchFailure | undefined {
|
|
108
|
+
return this.#searchFailure;
|
|
109
|
+
}
|
|
110
|
+
|
|
101
111
|
get draft(): CommandKeymapPatch | undefined {
|
|
102
112
|
return this.#draft;
|
|
103
113
|
}
|
|
@@ -111,51 +121,54 @@ export class CommandController {
|
|
|
111
121
|
return () => this.#observers.delete(observer);
|
|
112
122
|
}
|
|
113
123
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
await this.refresh();
|
|
131
|
-
} catch (error) {
|
|
132
|
-
if (this.#started && lifecycleRevision === this.#lifecycleRevision) {
|
|
133
|
-
this.#setStatus({ kind: "failed", error });
|
|
134
|
-
}
|
|
135
|
-
}
|
|
124
|
+
start(): Promise<void> {
|
|
125
|
+
return this.#lifecycle.start({
|
|
126
|
+
loading: () => this.#setStatus({ kind: "loading" }),
|
|
127
|
+
connect: async ({ isCurrent, own }) => {
|
|
128
|
+
const unlisten = await this.#client.listen(() => {
|
|
129
|
+
if (isCurrent()) {
|
|
130
|
+
void this.refresh();
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
await own(...unlisten);
|
|
134
|
+
if (isCurrent()) {
|
|
135
|
+
await this.refresh();
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
failed: (error) => this.#setStatus({ kind: "failed", error }),
|
|
139
|
+
});
|
|
136
140
|
}
|
|
137
141
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
this.#
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
this.#
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
142
|
+
/** Replaces the current subscription, including after a reported failure. */
|
|
143
|
+
restart(): Promise<void> {
|
|
144
|
+
return this.#lifecycle.restart(
|
|
145
|
+
this.status,
|
|
146
|
+
() => this.stop(),
|
|
147
|
+
() => this.start(),
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
stop(): Promise<void> {
|
|
152
|
+
return this.#lifecycle.stop(() => {
|
|
153
|
+
this.#loadRevision += 1;
|
|
154
|
+
this.#searchRevision += 1;
|
|
155
|
+
this.#mutationRevision += 1;
|
|
156
|
+
this.#model = undefined;
|
|
157
|
+
this.#projection = undefined;
|
|
158
|
+
this.#searchHits = [];
|
|
159
|
+
this.#searchFailure = undefined;
|
|
160
|
+
this.#query = "";
|
|
161
|
+
this.#draft = undefined;
|
|
162
|
+
this.#mutation = { kind: "idle" };
|
|
163
|
+
this.#setStatus({ kind: "idle" });
|
|
164
|
+
});
|
|
152
165
|
}
|
|
153
166
|
|
|
154
167
|
async refresh(): Promise<void> {
|
|
155
168
|
const revision = ++this.#loadRevision;
|
|
156
169
|
try {
|
|
157
170
|
const loaded = await this.#client.load();
|
|
158
|
-
if (!this.#
|
|
171
|
+
if (!this.#lifecycle.active || revision !== this.#loadRevision) {
|
|
159
172
|
return;
|
|
160
173
|
}
|
|
161
174
|
if (loaded.keymap.status === "recovery") {
|
|
@@ -180,12 +193,15 @@ export class CommandController {
|
|
|
180
193
|
joinCommandState(loaded.catalogue, loaded.keymap.snapshot, loaded.availability),
|
|
181
194
|
);
|
|
182
195
|
this.#setStatus({ kind: "ready" });
|
|
183
|
-
await this.search(this.#query);
|
|
184
196
|
} catch (error) {
|
|
185
|
-
if (this.#
|
|
197
|
+
if (this.#lifecycle.active && revision === this.#loadRevision) {
|
|
186
198
|
this.#setStatus({ kind: "failed", error });
|
|
187
199
|
}
|
|
200
|
+
return;
|
|
188
201
|
}
|
|
202
|
+
// A consumer search is not part of the load. `search` records its failure
|
|
203
|
+
// in `searchFailure`, so the rejection has nowhere further to go here.
|
|
204
|
+
await this.search(this.#query).catch(() => {});
|
|
189
205
|
}
|
|
190
206
|
|
|
191
207
|
async search(query: string): Promise<ReadonlyArray<CommandSearchHit>> {
|
|
@@ -194,13 +210,25 @@ export class CommandController {
|
|
|
194
210
|
const revision = ++this.#searchRevision;
|
|
195
211
|
if (model === undefined) {
|
|
196
212
|
this.#searchHits = [];
|
|
213
|
+
this.#searchFailure = undefined;
|
|
197
214
|
this.#notify();
|
|
198
215
|
return [];
|
|
199
216
|
}
|
|
200
|
-
|
|
217
|
+
let hits: ReadonlyArray<CommandSearchHit>;
|
|
218
|
+
try {
|
|
219
|
+
hits = await this.#search(model.catalogue.commands, query);
|
|
220
|
+
} catch (error) {
|
|
221
|
+
if (revision === this.#searchRevision && model === this.#model) {
|
|
222
|
+
this.#searchHits = [];
|
|
223
|
+
this.#searchFailure = { error };
|
|
224
|
+
this.#notify();
|
|
225
|
+
}
|
|
226
|
+
throw error;
|
|
227
|
+
}
|
|
201
228
|
if (revision !== this.#searchRevision || model !== this.#model) {
|
|
202
229
|
return hits;
|
|
203
230
|
}
|
|
231
|
+
this.#searchFailure = undefined;
|
|
204
232
|
const visible = new Set(this.#projection?.palette.map(({ id }) => id));
|
|
205
233
|
this.#searchHits = hits.filter(({ record }) => visible.has(record.id));
|
|
206
234
|
this.#notify();
|
|
@@ -232,12 +260,14 @@ export class CommandController {
|
|
|
232
260
|
}
|
|
233
261
|
|
|
234
262
|
stageKeymapPatch(patch: CommandKeymapPatch): void {
|
|
263
|
+
this.#mutationRevision += 1;
|
|
235
264
|
this.#draft = patch;
|
|
236
265
|
this.#mutation = { kind: "dirty" };
|
|
237
266
|
this.#notify();
|
|
238
267
|
}
|
|
239
268
|
|
|
240
269
|
cancelKeymapDraft(): void {
|
|
270
|
+
this.#mutationRevision += 1;
|
|
241
271
|
this.#draft = undefined;
|
|
242
272
|
this.#mutation = { kind: "idle" };
|
|
243
273
|
this.#notify();
|
|
@@ -250,18 +280,19 @@ export class CommandController {
|
|
|
250
280
|
return true;
|
|
251
281
|
}
|
|
252
282
|
const base = model.keymap;
|
|
253
|
-
const operationRevision = ++this.#
|
|
283
|
+
const operationRevision = ++this.#mutationRevision;
|
|
254
284
|
this.#mutation = { kind: "previewing" };
|
|
255
285
|
this.#notify();
|
|
256
286
|
try {
|
|
257
287
|
const preview = await this.#client.preview({
|
|
288
|
+
protocolVersion: COMMAND_KEYMAP_PROTOCOL_VERSION,
|
|
258
289
|
registryGeneration: model.catalogue.registryGeneration,
|
|
259
290
|
keymapRevision: base.state.revision,
|
|
260
291
|
activePresetId: base.state.activePresetId,
|
|
261
292
|
activePresetVersion: base.activePresetVersion,
|
|
262
293
|
patch,
|
|
263
294
|
});
|
|
264
|
-
if (operationRevision !== this.#
|
|
295
|
+
if (operationRevision !== this.#mutationRevision) {
|
|
265
296
|
return false;
|
|
266
297
|
}
|
|
267
298
|
if (preview.status !== "accepted") {
|
|
@@ -278,17 +309,21 @@ export class CommandController {
|
|
|
278
309
|
}
|
|
279
310
|
this.#mutation = { kind: "committing" };
|
|
280
311
|
this.#notify();
|
|
312
|
+
if (operationRevision !== this.#mutationRevision) {
|
|
313
|
+
return false;
|
|
314
|
+
}
|
|
281
315
|
const result = await this.#client.commit({
|
|
316
|
+
protocolVersion: COMMAND_KEYMAP_PROTOCOL_VERSION,
|
|
282
317
|
requestId: this.#client.nextRequestId(),
|
|
283
318
|
evidence: preview.evidence,
|
|
284
319
|
patch,
|
|
285
320
|
});
|
|
286
|
-
if (operationRevision !== this.#
|
|
321
|
+
if (operationRevision !== this.#mutationRevision) {
|
|
287
322
|
return false;
|
|
288
323
|
}
|
|
289
324
|
return this.#finishMutation(result);
|
|
290
325
|
} catch (error) {
|
|
291
|
-
if (operationRevision === this.#
|
|
326
|
+
if (operationRevision === this.#mutationRevision) {
|
|
292
327
|
this.#mutation = { kind: "failed", error };
|
|
293
328
|
this.#notify();
|
|
294
329
|
}
|
|
@@ -299,23 +334,27 @@ export class CommandController {
|
|
|
299
334
|
async resetKeymap(): Promise<boolean> {
|
|
300
335
|
const model = this.#requiredModel();
|
|
301
336
|
const base = model.keymap;
|
|
302
|
-
const operationRevision = ++this.#
|
|
337
|
+
const operationRevision = ++this.#mutationRevision;
|
|
303
338
|
this.#mutation = { kind: "committing" };
|
|
304
339
|
this.#notify();
|
|
340
|
+
if (operationRevision !== this.#mutationRevision) {
|
|
341
|
+
return false;
|
|
342
|
+
}
|
|
305
343
|
try {
|
|
306
344
|
const result = await this.#client.reset({
|
|
345
|
+
protocolVersion: COMMAND_KEYMAP_PROTOCOL_VERSION,
|
|
307
346
|
requestId: this.#client.nextRequestId(),
|
|
308
347
|
registryGeneration: model.catalogue.registryGeneration,
|
|
309
348
|
keymapRevision: base.state.revision,
|
|
310
349
|
activePresetId: base.state.activePresetId,
|
|
311
350
|
activePresetVersion: base.activePresetVersion,
|
|
312
351
|
});
|
|
313
|
-
if (operationRevision !== this.#
|
|
352
|
+
if (operationRevision !== this.#mutationRevision) {
|
|
314
353
|
return false;
|
|
315
354
|
}
|
|
316
355
|
return this.#finishMutation(result);
|
|
317
356
|
} catch (error) {
|
|
318
|
-
if (operationRevision === this.#
|
|
357
|
+
if (operationRevision === this.#mutationRevision) {
|
|
319
358
|
this.#mutation = { kind: "failed", error };
|
|
320
359
|
this.#notify();
|
|
321
360
|
}
|
|
@@ -341,7 +380,10 @@ export class CommandController {
|
|
|
341
380
|
}
|
|
342
381
|
|
|
343
382
|
#applyMutationSnapshot(snapshot: CommandKeymapSnapshot): void {
|
|
344
|
-
const model = this.#
|
|
383
|
+
const model = this.#model;
|
|
384
|
+
if (model === undefined) {
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
345
387
|
if (snapshot.registryGeneration !== model.catalogue.registryGeneration) {
|
|
346
388
|
void this.refresh();
|
|
347
389
|
return;
|
|
@@ -360,9 +402,9 @@ export class CommandController {
|
|
|
360
402
|
) {
|
|
361
403
|
return;
|
|
362
404
|
}
|
|
405
|
+
const projection = projectCommandSurfaces(model, this.#platform);
|
|
363
406
|
this.#model = model;
|
|
364
|
-
this.#projection =
|
|
365
|
-
this.#notify();
|
|
407
|
+
this.#projection = projection;
|
|
366
408
|
}
|
|
367
409
|
|
|
368
410
|
#requiredModel(): CommandJoinedState {
|
|
@@ -390,7 +432,3 @@ export class CommandControllerUnavailableError extends Error {
|
|
|
390
432
|
this.name = "CommandControllerUnavailableError";
|
|
391
433
|
}
|
|
392
434
|
}
|
|
393
|
-
|
|
394
|
-
async function disposeAll(unlisten: ReadonlyArray<CommandUnlisten>): Promise<void> {
|
|
395
|
-
await Promise.allSettled(unlisten.map((dispose) => dispose()));
|
|
396
|
-
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @generated by `effigy generate:
|
|
1
|
+
// @generated by `effigy generate:bindings`; do not edit.
|
|
2
2
|
// Allowed field names per protocol type, from the Rust structs.
|
|
3
3
|
// A `record()` given one of these rejects unknown and missing keys —
|
|
4
4
|
// contract 010's Boundary Validation Target.
|
|
@@ -31,9 +31,9 @@ export const COMMANDS_FIELDS = {
|
|
|
31
31
|
"CommandKeymapState": ["revision", "activePresetId", "overrides"],
|
|
32
32
|
"CommandKeymapPatch": ["activePresetId", "clearOverrides", "removeBindingIds", "upsertOverrides"],
|
|
33
33
|
"CommandKeymapCommitEvidence": ["registryGeneration", "keymapRevision", "activePresetId", "activePresetVersion", "patchDigest"],
|
|
34
|
-
"CommandKeymapPreview": ["registryGeneration", "keymapRevision", "activePresetId", "activePresetVersion", "patch"],
|
|
35
|
-
"CommandKeymapCommit": ["requestId", "evidence", "patch"],
|
|
36
|
-
"CommandKeymapReset": ["requestId", "registryGeneration", "keymapRevision", "activePresetId", "activePresetVersion"],
|
|
34
|
+
"CommandKeymapPreview": ["protocolVersion", "registryGeneration", "keymapRevision", "activePresetId", "activePresetVersion", "patch"],
|
|
35
|
+
"CommandKeymapCommit": ["protocolVersion", "requestId", "evidence", "patch"],
|
|
36
|
+
"CommandKeymapReset": ["protocolVersion", "requestId", "registryGeneration", "keymapRevision", "activePresetId", "activePresetVersion"],
|
|
37
37
|
"CommandKeymapDiagnostic": ["code", "detail"],
|
|
38
38
|
"CommandKeymapSnapshot": ["protocolVersion", "registryGeneration", "registryDigest", "state", "activePresetVersion", "bindings", "conflicts", "origin", "diagnostics"],
|
|
39
39
|
"CommandKeymapChangedEvent": ["protocolVersion", "registryGeneration", "keymapRevision"],
|
|
@@ -1,8 +1,19 @@
|
|
|
1
|
-
// @generated by `effigy generate:
|
|
1
|
+
// @generated by `effigy generate:bindings`; do not edit.
|
|
2
2
|
// Rust serde types are the wire authority.
|
|
3
3
|
|
|
4
4
|
export const COMMAND_KEYMAP_PROTOCOL_VERSION = 1 as const;
|
|
5
5
|
export const COMMAND_MAXIMUM_PHYSICAL_CODE_BYTES = 64 as const;
|
|
6
|
+
export const COMMAND_MAXIMUM_DIAGNOSTIC_BYTES = 4096 as const;
|
|
7
|
+
export const COMMAND_MAXIMUM_KEYWORD_BYTES = 65536 as const;
|
|
8
|
+
export const COMMAND_MAXIMUM_AVAILABILITY_RECORDS = 65536 as const;
|
|
9
|
+
export const COMMAND_MAXIMUM_ARGUMENT_DEPTH = 121 as const;
|
|
10
|
+
export const COMMAND_PLATFORMS = ["macOs","windows","linux"] as const;
|
|
11
|
+
export const COMMAND_PLATFORM_SCOPES = ["any","macOs","windows","linux"] as const;
|
|
12
|
+
export const COMMAND_TEXT_INPUT_POLICIES = ["blocked","allowed"] as const;
|
|
13
|
+
export const COMMAND_AVAILABILITY_STATES = ["available","unavailable","hidden","unsupported"] as const;
|
|
14
|
+
export const COMMAND_AVAILABILITY_REASON_KINDS = ["contextNotAllowed","missingCapability","consumer"] as const;
|
|
15
|
+
export const COMMAND_BINDING_SOURCE_KINDS = ["preset","replacement","addedOverride"] as const;
|
|
16
|
+
export const COMMAND_ARGUMENT_SCHEMA_SHAPES = ["none","object"] as const;
|
|
6
17
|
export const COMMAND_KEYMAP_LOAD_STATUSES = ["loaded","recovery","unavailable"] as const;
|
|
7
18
|
export const COMMAND_KEYMAP_PREVIEW_STATUSES = ["accepted","stale","rejected"] as const;
|
|
8
19
|
export const COMMAND_KEYMAP_MUTATION_STATUSES = ["applied","stale","rejected"] as const;
|
|
@@ -622,6 +633,10 @@ activePresetVersion: SchemaVersion,
|
|
|
622
633
|
patchDigest: CommandKeymapPatchDigest, };
|
|
623
634
|
|
|
624
635
|
export type CommandKeymapPreview = {
|
|
636
|
+
/**
|
|
637
|
+
* Exact protocol line.
|
|
638
|
+
*/
|
|
639
|
+
protocolVersion: CommandKeymapProtocolVersion,
|
|
625
640
|
/**
|
|
626
641
|
* Expected sealed registry generation.
|
|
627
642
|
*/
|
|
@@ -644,6 +659,10 @@ activePresetVersion: SchemaVersion,
|
|
|
644
659
|
patch: CommandKeymapPatch, };
|
|
645
660
|
|
|
646
661
|
export type CommandKeymapCommit = {
|
|
662
|
+
/**
|
|
663
|
+
* Exact protocol line.
|
|
664
|
+
*/
|
|
665
|
+
protocolVersion: CommandKeymapProtocolVersion,
|
|
647
666
|
/**
|
|
648
667
|
* Correlation identity.
|
|
649
668
|
*/
|
|
@@ -658,6 +677,10 @@ evidence: CommandKeymapCommitEvidence,
|
|
|
658
677
|
patch: CommandKeymapPatch, };
|
|
659
678
|
|
|
660
679
|
export type CommandKeymapReset = {
|
|
680
|
+
/**
|
|
681
|
+
* Exact protocol line.
|
|
682
|
+
*/
|
|
683
|
+
protocolVersion: CommandKeymapProtocolVersion,
|
|
661
684
|
/**
|
|
662
685
|
* Correlation identity.
|
|
663
686
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @generated by `effigy generate:
|
|
1
|
+
// @generated by `effigy generate:bindings`; do not edit.
|
|
2
2
|
// Allowed field names per tagged-union variant, from the Rust enums.
|
|
3
3
|
// Keyed by type, then by discriminant. The discriminant itself is in
|
|
4
4
|
// each list, because `exact()` compares every key.
|
package/src/commands/keyboard.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { COMMAND_MAXIMUM_PHYSICAL_CODE_BYTES } from "./generated/protocol.ts";
|
|
2
1
|
import type {
|
|
3
2
|
CommandBindingCandidate,
|
|
4
3
|
CommandDiscoveryRecord,
|
|
@@ -11,6 +10,7 @@ import type {
|
|
|
11
10
|
CommandKeymapConflict,
|
|
12
11
|
CommandPlatform,
|
|
13
12
|
} from "./generated/protocol.ts";
|
|
13
|
+
import { isPhysicalCode } from "./physical-code.ts";
|
|
14
14
|
import { shortcutLabel } from "./projectors.ts";
|
|
15
15
|
import type { CommandExecutionOutcome, CommandExecutionSource } from "./ports.ts";
|
|
16
16
|
|
|
@@ -80,7 +80,7 @@ export function resolveCommandKeyboard(
|
|
|
80
80
|
options: CommandKeyboardResolutionOptions,
|
|
81
81
|
): CommandKeyResolution {
|
|
82
82
|
const { input } = options;
|
|
83
|
-
if (!
|
|
83
|
+
if (!isPhysicalCode(input.chord.code)) {
|
|
84
84
|
return { kind: "unbound" };
|
|
85
85
|
}
|
|
86
86
|
if (input.repeat) {
|
|
@@ -115,7 +115,7 @@ export function resolveCommandKeyboard(
|
|
|
115
115
|
})
|
|
116
116
|
.sort(
|
|
117
117
|
(left, right) =>
|
|
118
|
-
right.specificity - left.specificity || left.binding.id
|
|
118
|
+
right.specificity - left.specificity || compareText(left.binding.id, right.binding.id),
|
|
119
119
|
);
|
|
120
120
|
const [firstMatch] = matches;
|
|
121
121
|
if (firstMatch === undefined) {
|
|
@@ -276,7 +276,7 @@ function uniqueInvocations(
|
|
|
276
276
|
|
|
277
277
|
function invocationKey(invocation: CommandInvocation): string {
|
|
278
278
|
const argumentsKey = Object.entries(invocation.arguments)
|
|
279
|
-
.sort(([left], [right]) => left
|
|
279
|
+
.sort(([left], [right]) => compareText(left, right))
|
|
280
280
|
.map(([key, value]) => [key, value]);
|
|
281
281
|
return JSON.stringify([invocation.commandId, argumentsKey]);
|
|
282
282
|
}
|
|
@@ -353,12 +353,3 @@ function compareText(left: string, right: string): number {
|
|
|
353
353
|
}
|
|
354
354
|
return leftValues.length - rightValues.length;
|
|
355
355
|
}
|
|
356
|
-
|
|
357
|
-
function validPhysicalCode(code: string): boolean {
|
|
358
|
-
return (
|
|
359
|
-
code !== "Unidentified" &&
|
|
360
|
-
code.length > 0 &&
|
|
361
|
-
code.length <= COMMAND_MAXIMUM_PHYSICAL_CODE_BYTES &&
|
|
362
|
-
/^[A-Z][A-Za-z0-9]*$/u.test(code)
|
|
363
|
-
);
|
|
364
|
-
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { COMMAND_MAXIMUM_PHYSICAL_CODE_BYTES } from "./generated/protocol.ts";
|
|
2
|
+
|
|
3
|
+
/** Whether Rust's `CommandPhysicalCode` would admit `value`. */
|
|
4
|
+
export function isPhysicalCode(value: unknown): value is string {
|
|
5
|
+
return (
|
|
6
|
+
typeof value === "string" &&
|
|
7
|
+
value !== "Unidentified" &&
|
|
8
|
+
value.length <= COMMAND_MAXIMUM_PHYSICAL_CODE_BYTES &&
|
|
9
|
+
/^[A-Z][A-Za-z0-9]*$/u.test(value)
|
|
10
|
+
);
|
|
11
|
+
}
|
package/src/commands/ports.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Unlisten } from "../core/transport.ts";
|
|
1
2
|
import type {
|
|
2
3
|
CommandArguments,
|
|
3
4
|
CommandAvailabilitySnapshot,
|
|
@@ -12,7 +13,7 @@ import type {
|
|
|
12
13
|
CommandRequestId,
|
|
13
14
|
} from "./generated/protocol.ts";
|
|
14
15
|
|
|
15
|
-
export type CommandUnlisten =
|
|
16
|
+
export type CommandUnlisten = Unlisten;
|
|
16
17
|
|
|
17
18
|
export interface CommandSnapshotPort<Snapshot> {
|
|
18
19
|
load(): Promise<Snapshot>;
|
|
@@ -44,11 +44,6 @@ export interface CommandSurfaceProjection {
|
|
|
44
44
|
readonly conflicts: ReadonlyArray<CommandKeymapConflict>;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
const AVAILABLE: CommandAvailability = {
|
|
48
|
-
state: "available",
|
|
49
|
-
reason: null,
|
|
50
|
-
};
|
|
51
|
-
|
|
52
47
|
export function joinCommandState(
|
|
53
48
|
catalogue: CommandCatalogueSnapshot,
|
|
54
49
|
keymap: CommandKeymapSnapshot,
|
|
@@ -92,39 +87,47 @@ export function projectCommandSurfaces(
|
|
|
92
87
|
);
|
|
93
88
|
const reverseLookup = new Map<CommandId, ReadonlyArray<CommandShortcutRecord>>();
|
|
94
89
|
const shortcuts: Array<CommandShortcutRecord> = [];
|
|
95
|
-
|
|
96
|
-
const
|
|
97
|
-
|
|
90
|
+
const rows = state.catalogue.commands.map((command) => {
|
|
91
|
+
const { id, label, description, categoryPath, keywords, icon, visibility } = command;
|
|
92
|
+
const value = availability.get(id);
|
|
93
|
+
if (value === undefined) {
|
|
94
|
+
throw new CommandProjectionConsistencyError(`availability is missing command ${id}`);
|
|
95
|
+
}
|
|
96
|
+
const records = shortcutsForCommand(state.keymap, id, platform);
|
|
97
|
+
reverseLookup.set(id, records);
|
|
98
98
|
shortcuts.push(...records);
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
99
|
+
return {
|
|
100
|
+
record: {
|
|
101
|
+
id,
|
|
102
|
+
label,
|
|
103
|
+
description,
|
|
104
|
+
categoryPath,
|
|
105
|
+
keywords,
|
|
106
|
+
icon,
|
|
107
|
+
availability: value,
|
|
108
|
+
shortcuts: records,
|
|
109
|
+
},
|
|
110
|
+
visibility,
|
|
111
|
+
};
|
|
109
112
|
});
|
|
110
|
-
const visible =
|
|
113
|
+
const visible = rows.filter(({ visibility }) => !visibility.hidden);
|
|
111
114
|
return {
|
|
112
115
|
palette: visible
|
|
113
116
|
.filter(({ visibility }) => visibility.palette)
|
|
114
|
-
.map(
|
|
117
|
+
.map(({ record }) => record)
|
|
115
118
|
.filter(({ availability }) => availability.state !== "hidden"),
|
|
116
119
|
menu: visible
|
|
117
120
|
.filter(({ visibility }) => visibility.menu)
|
|
118
|
-
.map(
|
|
121
|
+
.map(({ record }) => record)
|
|
119
122
|
.filter(({ availability }) => availability.state !== "hidden"),
|
|
120
123
|
help: visible
|
|
121
124
|
.filter(({ visibility }) => visibility.help)
|
|
122
|
-
.map(
|
|
125
|
+
.map(({ record }) => record)
|
|
123
126
|
.filter(({ availability }) => availability.state !== "hidden"),
|
|
124
127
|
settings: visible
|
|
125
128
|
.filter(({ visibility }) => visibility.settings)
|
|
126
|
-
.map((record) => ({
|
|
127
|
-
...
|
|
129
|
+
.map(({ record }) => ({
|
|
130
|
+
...record,
|
|
128
131
|
bindings: state.keymap.bindings.filter(
|
|
129
132
|
({ invocation }) => invocation.commandId === record.id,
|
|
130
133
|
),
|
|
@@ -139,6 +142,28 @@ export function searchCommands(
|
|
|
139
142
|
records: ReadonlyArray<CommandDiscoveryRecord>,
|
|
140
143
|
query: string,
|
|
141
144
|
): ReadonlyArray<CommandSearchHit> {
|
|
145
|
+
return searchCommandRecords(records, query);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export function searchCommandSettings(
|
|
149
|
+
records: ReadonlyArray<CommandSettingsRecord>,
|
|
150
|
+
query: string,
|
|
151
|
+
): ReadonlyArray<CommandSettingsRecord> {
|
|
152
|
+
if (query.trim().length === 0) {
|
|
153
|
+
return records;
|
|
154
|
+
}
|
|
155
|
+
return searchCommandRecords(records, query).map(({ record }) => record);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
type SearchableCommand = Pick<
|
|
159
|
+
CommandProjectionRecord,
|
|
160
|
+
"id" | "label" | "description" | "categoryPath" | "keywords"
|
|
161
|
+
>;
|
|
162
|
+
|
|
163
|
+
function searchCommandRecords<Record extends SearchableCommand>(
|
|
164
|
+
records: ReadonlyArray<Record>,
|
|
165
|
+
query: string,
|
|
166
|
+
): ReadonlyArray<{ record: Record; score: number }> {
|
|
142
167
|
const terms = query
|
|
143
168
|
.split(/\s+/u)
|
|
144
169
|
.filter(Boolean)
|
|
@@ -207,13 +232,11 @@ export class CommandProjectionConsistencyError extends Error {
|
|
|
207
232
|
}
|
|
208
233
|
}
|
|
209
234
|
|
|
210
|
-
function scoreRecord(
|
|
211
|
-
record: CommandDiscoveryRecord,
|
|
212
|
-
terms: ReadonlyArray<string>,
|
|
213
|
-
): number | undefined {
|
|
235
|
+
function scoreRecord(record: SearchableCommand, terms: ReadonlyArray<string>): number | undefined {
|
|
214
236
|
if (terms.length === 0) {
|
|
215
237
|
return 0;
|
|
216
238
|
}
|
|
239
|
+
const id = record.id.toLowerCase();
|
|
217
240
|
const label = record.label.toLowerCase();
|
|
218
241
|
const description = record.description?.toLowerCase() ?? "";
|
|
219
242
|
const keywords = record.keywords.map((keyword) => keyword.toLowerCase());
|
|
@@ -234,7 +257,7 @@ function scoreRecord(
|
|
|
234
257
|
? 50
|
|
235
258
|
: record.categoryPath.some((category) => category.includes(term))
|
|
236
259
|
? 60
|
|
237
|
-
:
|
|
260
|
+
: id.includes(term)
|
|
238
261
|
? 70
|
|
239
262
|
: description.includes(term)
|
|
240
263
|
? 80
|