Skip to content

Commit fab9e0d

Browse files
committed
revert: drop cross-surface rotate compatibility, keep the lean rename
The rotate->orientation change is a bug fix (name collision with the `gesture rotate` two-finger gesture), not a compatibility feature. The cross-surface command-data compatibility added disproportionate weight (~480 B, dominated by the alias module inlined into the batch bundle) for a command that was only canonical for two minor versions, so shipped batch/ replay/MCP data carrying `rotate` is a rare, documentable break. Removed: - daemon request-boundary command normalization (`request-router.ts`) - batch step alias resolution (`batch-policy.ts`, `cli/batch-steps.ts`) - MCP tool-runner alias/legacy-result handling (`mcp/command-tools.ts`) - the `command-aliases.ts` module rename and cross-surface machinery (reverted to `cli-command-aliases.ts`) - the cross-surface tests Kept (cheap, high value — prevents build breaks for typed consumers): - CLI `rotate` alias (one line, same mechanism as `tap`/`launch`) - deprecated `RotateCommand*` / `SystemRotate*` type aliases and the `client.command.rotate` / `device.system.rotate` wrappers that delegate to `orientation` and restore the legacy response contract Net bundle vs main is now +473 B (was +952 B), almost all the kept SDK wrappers plus the unavoidable longer command name.
1 parent e072fbc commit fab9e0d

11 files changed

Lines changed: 57 additions & 308 deletions

src/__tests__/batch-command-alias.test.ts

Lines changed: 0 additions & 47 deletions
This file was deleted.

src/batch-policy.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { deriveStructuredBatchCommandNames } from './core/command-descriptor/derive.ts';
22
import { commandDescriptors } from './core/command-descriptor/registry.ts';
3-
import { normalizeCrossSurfaceCommandAlias } from './command-aliases.ts';
43
import { AppError } from './kernel/errors.ts';
54

65
/**
@@ -58,11 +57,7 @@ function isStructuredBatchCommandName(command: string): command is StructuredBat
5857
}
5958

6059
export function normalizeBatchCommandName(command: unknown): string {
61-
// Resolve command-name aliases (e.g. `rotate` -> `orientation`) from the shared
62-
// map so structured batch data carrying a renamed command validates and runs
63-
// against the canonical descriptor instead of failing as unavailable.
64-
const raw = typeof command === 'string' ? command.trim().toLowerCase() : '';
65-
return raw ? normalizeCrossSurfaceCommandAlias(raw) : '';
60+
return typeof command === 'string' ? command.trim().toLowerCase() : '';
6661
}
6762

6863
export function readStructuredBatchCommandName(

src/cli-command-aliases.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import type { CliFlags } from './commands/cli-grammar/flag-types.ts';
2+
3+
type BooleanCliFlagKey = {
4+
[Key in keyof CliFlags]-?: Exclude<CliFlags[Key], undefined> extends boolean ? Key : never;
5+
}[keyof CliFlags];
6+
7+
export type CliCommandAlias = {
8+
alias: string;
9+
command: string;
10+
impliedFlags?: readonly BooleanCliFlagKey[];
11+
};
12+
13+
const CLI_COMMAND_ALIASES: readonly CliCommandAlias[] = [
14+
{ alias: 'long-press', command: 'longpress' },
15+
{ alias: 'metrics', command: 'perf' },
16+
{ alias: 'tap', command: 'press' },
17+
{ alias: 'launch', command: 'open' },
18+
{ alias: 'relaunch', command: 'open', impliedFlags: ['relaunch'] },
19+
// Deprecated: `rotate` was renamed to `orientation` (it collided with the
20+
// `gesture rotate` two-finger gesture). Kept working at the CLI for a few versions.
21+
{ alias: 'rotate', command: 'orientation' },
22+
];
23+
24+
const aliasByToken: ReadonlyMap<string, CliCommandAlias> = new Map(
25+
CLI_COMMAND_ALIASES.map((entry) => [entry.alias, entry]),
26+
);
27+
28+
export function normalizeCliCommandAlias(command: string): string {
29+
return aliasByToken.get(command.toLowerCase())?.command ?? command;
30+
}
31+
32+
export function cliCommandAlias(rawCommand: string): CliCommandAlias | undefined {
33+
return aliasByToken.get(rawCommand.toLowerCase());
34+
}
35+
36+
export function cliAliasesForCommand(command: string): CliCommandAlias[] {
37+
return CLI_COMMAND_ALIASES.filter((entry) => entry.command === command);
38+
}

src/cli/batch-steps.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { type SessionRuntimeHints } from '../kernel/contracts.ts';
33
import { parseBatchStepRuntime } from '../batch-contract.ts';
44
import { readInputFromCli } from '../commands/cli-grammar.ts';
55
import { isCommandName, type CommandName } from '../commands/command-metadata.ts';
6-
import { normalizeCrossSurfaceCommandAlias } from '../command-aliases.ts';
76
import type { CliFlags } from '../commands/cli-grammar/flag-types.ts';
87
import { AppError } from '../kernel/errors.ts';
98
import { isRecord } from '../utils/parsing.ts';
@@ -69,8 +68,6 @@ function readStructuredBatchStep(
6968
const { runtime: _runtime, ...rest } = step;
7069
return {
7170
...rest,
72-
// Resolve command-name aliases (e.g. `rotate` -> `orientation`) from the shared map.
73-
command: normalizeCrossSurfaceCommandAlias(rest.command),
7471
...(runtime === undefined ? {} : { runtime }),
7572
};
7673
}
@@ -93,10 +90,8 @@ function readLegacyCliBatchStep(step: unknown, stepNumber: number): LegacyCliBat
9390
}
9491

9592
function readLegacyCommand(value: unknown, stepNumber: number): CommandName {
96-
const raw = typeof value === 'string' ? value.trim().toLowerCase() : '';
97-
if (!raw) throw new AppError('INVALID_ARGS', `Batch step ${stepNumber} requires command.`);
98-
// Resolve command-name aliases (e.g. `rotate` -> `orientation`) from the shared map.
99-
const command = normalizeCrossSurfaceCommandAlias(raw);
93+
const command = typeof value === 'string' ? value.trim().toLowerCase() : '';
94+
if (!command) throw new AppError('INVALID_ARGS', `Batch step ${stepNumber} requires command.`);
10095
if (isCommandName(command)) return command;
10196
throw new AppError(
10297
'INVALID_ARGS',

src/cli/parser/args.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
} from '../../cli-schema/command-schema.ts';
1212
import { isFlagSupportedForCommand } from '../../cli-schema/option-schema.ts';
1313
import { isKnownCliCommandName } from '../../command-catalog.ts';
14-
import { commandAlias, normalizeCommandAlias } from '../../command-aliases.ts';
14+
import { cliCommandAlias, normalizeCliCommandAlias } from '../../cli-command-aliases.ts';
1515
import { formatUnknownFlagMessage, suggestCommandFor } from './command-suggestions.ts';
1616

1717
type ParsedArgs = {
@@ -118,7 +118,7 @@ export function parseRawArgs(argv: string[]): RawParsedArgs {
118118

119119
function applyAliasImpliedFlags(rawCommand: string | null, flags: CliFlags): void {
120120
if (!rawCommand) return;
121-
for (const key of commandAlias(rawCommand)?.impliedFlags ?? []) {
121+
for (const key of cliCommandAlias(rawCommand)?.impliedFlags ?? []) {
122122
flags[key] = true;
123123
}
124124
}
@@ -382,3 +382,7 @@ export async function usageForCommand(command: string): Promise<string | null> {
382382
const { buildCommandUsageText } = await import('./cli-help.ts');
383383
return buildCommandUsageText(normalizeCommandAlias(command));
384384
}
385+
386+
function normalizeCommandAlias(command: string): string {
387+
return normalizeCliCommandAlias(command);
388+
}

src/command-aliases.ts

Lines changed: 0 additions & 55 deletions
This file was deleted.

src/commands/command-explain.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { listCliCommandNames } from '../command-catalog.ts';
2-
import { aliasesForCommand, normalizeCommandAlias } from '../command-aliases.ts';
2+
import { cliAliasesForCommand, normalizeCliCommandAlias } from '../cli-command-aliases.ts';
33
import { buildCommandUsage } from '../cli-schema/usage.ts';
44
import type { DaemonCommandRoute } from '../daemon/daemon-command-registry.ts';
55
import { commandDescriptors, type Command } from '../core/command-descriptor/registry.ts';
@@ -165,13 +165,13 @@ export function formatCommandExplanation(
165165
}
166166

167167
function resolveDescriptor(query: string): CommandDescriptor | undefined {
168-
const direct = descriptorByName.get(normalizeCommandAlias(query));
168+
const direct = descriptorByName.get(normalizeCliCommandAlias(query));
169169
if (direct) return direct;
170170
return commandDescriptors.find((descriptor) => readCatalogKey(descriptor) === query);
171171
}
172172

173173
function describeCliAliases(command: string): CommandAliasExplanation[] {
174-
return aliasesForCommand(command).map((entry) => ({
174+
return cliAliasesForCommand(command).map((entry) => ({
175175
alias: entry.alias,
176176
...(entry.impliedFlags && entry.impliedFlags.length > 0
177177
? { impliedFlags: [...entry.impliedFlags] }
@@ -240,7 +240,7 @@ function suggestCommands(query: string): string[] {
240240
const candidates = commandDescriptors.flatMap((descriptor) => [
241241
descriptor.name,
242242
readCatalogKey(descriptor),
243-
...aliasesForCommand(descriptor.name).map((alias) => alias.alias),
243+
...cliAliasesForCommand(descriptor.name).map((alias) => alias.alias),
244244
]);
245245
return [...new Set(candidates)]
246246
.map((candidate) => ({ candidate, distance: levenshtein(query, candidate) }))

src/daemon/__tests__/request-router-command-alias.test.ts

Lines changed: 0 additions & 112 deletions
This file was deleted.

0 commit comments

Comments
 (0)