Repository navigation
fix(cli): name --udid when a device identity is passed to --device - #2065
Conversation
`--device <udid>` failed with "No device named <udid>" and the generic booted/connected hint, and `help commands` listed no device selector at all, so `--udid` — the only flag that pins one simulator among several sharing a name — was reachable only from `help device`'s usage line. Two changes, both discoverability: - `resolveDeviceByName` now answers the flag mistake instead of the literal lookup. When the `--device` value is the id of a listed device it names that device and the flag the value belongs to (`--udid` for Apple, `--serial` for serial-addressable platforms); when it merely has UDID shape it names `--udid`. An ordinary unknown name keeps the generic hint. This mirrors the answer `assertSelectorFlagMatchesPlatform` already gives for a mismatched identity flag. - `help commands` renders a `Device Selection` section for the selectors every command accepts (`--platform`, `--device`, `--udid`, `--serial`, `--session`). They stay in `COMMON_COMMAND_SUPPORTED_FLAG_KEYS`, not `GLOBAL_FLAG_KEYS`, so the option schema and `explain` output are unchanged. Closes callstack#2064
|
[P1] Remove the partial UDID-shape heuristic and keep the hint grounded in observed device identity. The exact |
The UDID-shape fallback reconstructed Apple identity syntax with a UUID-only regex: it missed modern physical-device UDIDs (00008150-001849640CF8401C), could misclassify a UUID-shaped device name, and justified itself with an inventory state (a shut-down device) the exact-candidate match already covers wherever inventory lists it. Only a listed candidate's actual id now earns the hint; an unlisted value keeps the generic device-not-found answer. Also corrects help physical-device, which claimed --device accepts a UDID (it never did): it now names --udid/--serial for name collisions. Addresses the P1 review on callstack#2065.
- The hint is emitted only for platforms that HAVE an identity flag: web and linux device ids got 'Did you mean --udid <id>?' even though --udid resolves only Apple devices — a specific, provably dead instruction where the generic hint at least did no harm. - The section header no longer claims every device command accepts all five selectors (connect has no --udid/--serial, device no --session); it points at help <command> for each command's own flags. - The MCP/JSON input schema carries the same discoverability fix the CLI help got: 'Device name selector (a UDID belongs in udid, a serial in serial)' and the sharpened udid description, instead of the bare 'iOS device UDID selector.' the issue was filed about. - --serial's description names HarmonyOS, which the resolver has always accepted alongside Android and Vega.
|
Addressed the P1 in 6ebda34 and 830a577 (maintainer commits on this branch):
One correction to this PR's description: Live-verified on this branch (three booted targets): Follow-up worth its own issue: Validation: unit-core green (incl. kernel + cli-schema), |
|
The original P1 is resolved at |
|
Re-reviewed exact head P2: |
…in the selector descriptions The structured/MCP input schema still described serial as Android or Vega only while the resolver and the CLI guidance accept HarmonyOS. A metadata test now pins the three device-selector descriptions on every emitted command schema, so a cross-surface drift fails instead of shipping. Addresses the P2 review on callstack#2065.
|
P2 addressed in 919fab3: |
… in selector errors (#4861) * fix(kernel): name the other identity flag and the closest device name in selector errors A `--udid` that resolves nothing while the same value identifies an observed Android/HarmonyOS/Vega device answered "No Apple device with UDID emulator-5580" with no hint when the request carried no explicit --platform (the explicit case was already rejected by assertSelectorFlagMatchesPlatform). The failure now reads the flag the value belongs to through deviceIdentityFlag — no third inline pairing — and says "Did you mean --serial <value>?"; --serial answers the reverse the same way. Only an observed identity earns the hint, and a platform with no identity flag (web, linux) earns none, matching the #2065 precedent for --device. A --device name that survives the matcher but sits one punctuation character away from exactly one candidate (curly quotes on renamed simulators) is now answered with that candidate's name; more than one candidate under the quote fold earns no hint. The id-mistaken-for-name answer still wins when it applies. device.ts carried this work past the 1000-line lint cap, so the host-scoped id grammar (app devices, web sessions) moved verbatim into device-identity.ts, which every closure through device.ts already evaluates; @agent-device/kernel /device re-exports keep every import path stable. The moved web-session refusal now reads its wire reason from a declared table. Co-Authored-By: Claude Code <noreply@anthropic.com> * fix(kernel): point the id-grammar test imports at the owning module The barrel re-export of hostAppDeviceId and hostDeviceIdPrefix had no production consumer after the move, so the production-unused-exports gate refused it; both are used only by tests. The barrel keeps the symbols with production call sites, the tests import the two from @agent-device/kernel/device-identity (new exports-map entry), and the gate passes again. Co-Authored-By: Claude Code <noreply@anthropic.com> * fix(kernel): rebuild the ambiguous-close fixture and drop the unreachable spacing claim The two-candidate quote-fold case requested a quote-less name, which folds onto neither quoted candidate, so the close list stayed empty and the no-hint assertion passed without exercising the branch. The request now keeps its straight quotes while the two candidates spell theirs with U+2018 and U+2019, so both land under the fold and the answer names neither; flipping the single-candidate guard to >= 1 fails exactly this test. The closest-name hint said "punctuation or spacing", but the shared name matcher already folds whitespace, so a spacing-only difference resolves before any hint and the spacing claim was unreachable copy. Co-Authored-By: Claude Code <noreply@anthropic.com> * fix(kernel): keep the selector hints in device.ts and serve all three not-found sites with one helper The review asked for the smallest structural footprint: the ./device-identity package export made device-identity.ts a package entry whose eager closure grew from one module to three (errors.ts via the moved web-session refusal, plus redaction.ts), which the eager-closure budget gate refuses on no-growth, and the export had no production consumer. This drops the move and the export entirely: the host-scoped id grammar returns to device.ts, device-identity.ts returns to its merge-base content, and the three test files that had been pointed at the new entry go back to @agent-device/kernel/device. The two hints this branch added and the pre-existing mistaken-name answer now collapse into one helper: deviceNotFoundHint(candidates, value, flag?) reads the flag the request used, answers with the flag an observed device carries the value under, and for --device names the single candidate one quote fold away (quoteFoldDeviceName). device.ts absorbs the consolidation with no net line growth (989 at base, 989 here) against the 1000-line oxlint cap, so no module move and no new entry are needed. Co-Authored-By: Claude Code <noreply@anthropic.com> * fix(kernel): leave the merged device.ts under the 1000-line cap The merge preview joins this branch with main, where dd7d81c (#4853) grew device.ts by ten lines, so the branch's own zero-growth accounting does not hold on the tree CI actually checks: 994 head lines plus those ten crossed the 1000 limit and failed oxlint there. Compress the helper's one-line docblock, put its signature back on one line, and pass an empty value for a serial-less selector (an empty string matches no id, so that miss stays hint-free): 987 lines at head, 997 on the merge preview. Co-Authored-By: Claude Code <noreply@anthropic.com> --------- Co-authored-by: Claude Code <noreply@anthropic.com>
Closes #2064
Summary
--udidis the only selector that pins one simulator when several share a name, and it waseffectively undiscoverable:
help commandslisted no device selector at all, and passing a UDID to--deviceanswered with a literal lookup failure that neither named--udidnor hinted that aUDID-taking flag exists.
Before:
After:
Two changes:
resolveDeviceByNameanswers the flag mistake. When the--devicevalue is the id of alisted candidate it names that device and the flag the value belongs to —
--udidfor Apple,--serialfor serial-addressable platforms. When it merely has UDID shape (8-4-4-4-12 hex) butmatches no listed device, it names
--udidanyway, because a shut-down simulator is still awrong-flag answer. An ordinary unknown name keeps the generic hint untouched.
This mirrors, rather than invents, the answer
assertSelectorFlagMatchesPlatformalready givesa few lines above for a mismatched identity flag (
--udidon--platform android).help commandsrenders aDevice Selectionsection for the selectors every commandaccepts:
--platform,--device,--udid,--serial,--session.Deliberately a new help section rather than a
GLOBAL_FLAG_KEYSaddition: those keys mark aflag as supported by
*inbuildOptionSpecsand move it fromsupportedFlagstoglobalFlagsin
explain. These selectors reach device resolution, not the CLI envelope; they stay inCOMMON_COMMAND_SUPPORTED_FLAG_KEYS, so the option schema,explainoutput and MCP surface arebyte-identical.
--udidand--devicealso get sharper one-line descriptions, which is where an agent reading thenew section actually learns the distinction.
Tests
packages/kernel/src/device-selector-flags.test.ts— the existing home for selector-flagmistakes — gains four cases: a UDID and a serial passed to
--device(each naming the rightflag and the device it identifies), a UDID-shaped value no listed device carries, and an ordinary
unknown name keeping the generic hint. All four were observed red against the pre-fix code.
src/cli-schema/cli-help-topics.test.tsgains aDevice Selectionsection assertion. Theexisting "only global flags in its global flags section" test slices from
Global Flags:toConfiguration:; the new section sits aboveGlobal Flags:, so that slice is unaffected.pnpm check:quick,pnpm test:unit(8092 passed),pnpm check:command-docsandpnpm check:agent-guidanceare green.Live check
Run from the built clone against a local simulator set with two simulators named "iPhone 17":
--device <udid>→ the new identity hint naming--udidand"iPhone 17".--device 11111111-2222-3333-4444-555555555555(no such device) → the shape hint naming--udid.--device "iPhone 99"→ unchanged generic hint.help commandsrenders the new section.What a maintainer might push back on
against the candidate set, which needs no shape knowledge and gets
--serialright for Android.The regex only covers a device the current inventory does not list. Dropping it would still fix
the reported case; keeping it covers the shut-down-simulator variant the issue's workaround
section implies.
--deviceaccepting a UDID outright was the issue's other suggested fix. Not taken: it wouldmake
--devicea two-meaning flag and quietly duplicate--udid/--serial's platform routing,including the
assertSelectorFlagMatchesPlatformcross-check. Naming the right flag is smallerand keeps one meaning per selector.
Device Selection (accepted by every device command)is long;a shorter title works if it does not read as "global", which is exactly the distinction that
keeps the option schema unchanged.
--targetis also a common selector and was left out to match the issue's list.Adding it is a one-line change to
DEVICE_SELECTION_FLAG_KEYS.