Skip to content

Commit 1db99d1

Browse files
committed
feat: support device selector for runtime url
1 parent 1fd569d commit 1db99d1

13 files changed

Lines changed: 92 additions & 26 deletions

File tree

.agents/tritonkit-skills/public/tritonkit-dev-feedback/SKILL.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ Repository: `NeptuneKit/TritonKit` (`https://github.com/NeptuneKit/TritonKit`)
103103
- host-side layout and screenshot artifacts may contain private UI data; inspect or summarize instead of attaching raw files when redaction is uncertain.
104104
- when a disposable HarmonyOS NEXT smoke app is needed, use the local `harmony-next` skill's `references/quickStart/ets/minimal-project-scaffold.md` and copy `references/templates/empty-ability-app/` instead of hand-rolling `oh-package.json5` / `module.json5` / `hvigorfile.ts`.
105105
- Harmony embedded SDK feedback should distinguish generic HAR capability from app-provided semantics:
106-
- run `triton device runtime-url --platform harmony --target <hdc-target> --probe-manifest --json` first when the runtime is on a Harmony emulator/device and the host needs an HDC fport base URL;
106+
- run `triton device runtime-url --device harmony-a --probe-manifest --json` first when the runtime is on a Harmony emulator/device and the host needs an HDC fport base URL; `--platform harmony --target <hdc-target>` remains available as a compatibility path;
107107
- Harmony demo host-access embedded runtime defaults to `http://127.0.0.1:28767`; `18765` is the demo device-to-host gateway fallback port and should not be treated as the host direct runtime default;
108108
- if an HDC fport already exists, use `docs-linhay/scripts/verify-harmony-runtime-emulator-smoke.sh --target <hdc-target> --no-forward` to verify the live endpoint without re-registering the same port mapping;
109109
- use `triton runtime manifest --runtime-base-url http://127.0.0.1:<port> --json`, `triton state route --runtime-base-url ... --json`, `triton snapshot --runtime-base-url ... --json`, `triton ledger --runtime-base-url ... --jsonl`, and `triton set-text "密码" "$TRITON_PASSWORD" --secure --runtime-base-url ... --json` when validating a standalone embedded HTTP runtime before it is connected through `triton serve`;
@@ -401,7 +401,8 @@ Business semantics must be app-provided. A generic HAR should return `unsupporte
401401
When validating a standalone embedded HTTP runtime before it is connected through `triton serve`, first ask Triton to prepare or discover the HDC fport URL, then use direct runtime commands:
402402

403403
```bash
404-
triton device runtime-url --platform harmony --target 127.0.0.1:10100 --probe-manifest --json
404+
triton device alias set harmony-a --platform harmony --target 127.0.0.1:10100 --json
405+
triton device runtime-url --device harmony-a --probe-manifest --json
405406
triton runtime manifest --runtime-base-url http://127.0.0.1:28767 --json
406407
triton state route --runtime-base-url http://127.0.0.1:28767 --json
407408
triton snapshot --runtime-base-url http://127.0.0.1:28767 --json

.agents/tritonkit-skills/public/tritonkit-emulator-cli-takeover/SKILL.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ triton device screenshot --device iphone15 --output /tmp/<case>-sim.png --json
8282
triton device screenshot --device harmony-a --output /tmp/<case>.jpeg --json
8383
```
8484

85-
Use `--device <selector>` as the default agent-facing target selector for common host-side commands. Selectors can be aliases, full ids such as `sim:<udid>` / `harmony:<target>`, raw platform ids, `booted`, or `current`. `--platform`, `--name`, `--runtime`, `--state`, and `--ready` are filters; they may auto-select only when the filtered candidate set is unique. Keep `sim` for iOS-only advanced maintenance and `device runtime-url` for Harmony embedded runtime port-forward setup.
85+
Use `--device <selector>` as the default agent-facing target selector for common host-side commands. Selectors can be aliases, full ids such as `sim:<udid>` / `harmony:<target>`, raw platform ids, `booted`, or `current`. `--platform`, `--name`, `--runtime`, `--state`, and `--ready` are filters; they may auto-select only when the filtered candidate set is unique. Keep `sim` for iOS-only advanced maintenance; `device runtime-url --device <selector>` is the Harmony embedded runtime port-forward setup path, with `--platform harmony --target <target>` retained for compatibility.
8686

8787
iOS Simulator:
8888

@@ -160,6 +160,8 @@ triton node resolve --device harmony-a --text "登录" --json
160160
Standalone Harmony embedded HTTP runtime:
161161

162162
```bash
163+
triton device runtime-url --device harmony-a --probe-manifest --json
164+
# Compatibility path:
163165
triton device runtime-url --platform harmony --target <hdc-target> --probe-manifest --json
164166
triton runtime manifest --runtime-base-url http://127.0.0.1:28767 --json
165167
triton state route --runtime-base-url http://127.0.0.1:28767 --json

.agents/tritonkit-skills/public/tritonkit-real-project-regression/SKILL.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ Real-project validation is not the same as demo smoke. Treat the business app as
101101
- stable UI signals: `Harmony Smoke Ready`, `smoke-title`, `smoke-counter`, `smoke-increment`;
102102
- validation path: `ohpm install`, `hvigorw --mode module -p module=entry@default assembleHap`, HDC install/start, `uitest dumpLayout`, and `uitest screenCap`.
103103
- when validating a standalone Harmony embedded HTTP runtime before it is connected through `triton serve`, use direct runtime checks:
104-
- `triton device runtime-url --platform harmony --target <hdc-target> --probe-manifest --json` to prepare HDC fport and get the `baseURL`;
104+
- `triton device runtime-url --device harmony-a --probe-manifest --json` to prepare HDC fport and get the `baseURL`; `--platform harmony --target <hdc-target>` remains available as a compatibility path;
105105
- the Harmony demo host-access embedded runtime default is `http://127.0.0.1:28767`; `18765` is reserved for the demo device-to-host gateway fallback path;
106106
- `triton runtime manifest --runtime-base-url http://127.0.0.1:<port> --json`;
107107
- `triton state route --runtime-base-url http://127.0.0.1:<port> --json`;
@@ -299,7 +299,7 @@ Business semantics are not generic HAR capabilities. Route, responder, and seman
299299
For a standalone Harmony embedded runtime before it is connected through `triton serve`, use direct runtime checks:
300300

301301
```bash
302-
triton device runtime-url --platform harmony --target <hdc-target> --probe-manifest --json
302+
triton device runtime-url --device harmony-a --probe-manifest --json
303303
triton runtime manifest --runtime-base-url http://127.0.0.1:28767 --json
304304
triton state route --runtime-base-url http://127.0.0.1:28767 --json
305305
triton snapshot --runtime-base-url http://127.0.0.1:28767 --json

CLI/Tests/TritonKitCLITests/DeviceCrossPlatformTests.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ struct DeviceCrossPlatformTests {
1818
#expect(optionNames.contains("resolve <selector>"))
1919
#expect(optionNames.contains("wait-ready --device <selector>"))
2020
#expect(optionNames.contains("screenshot --device <selector> --output <path>"))
21+
#expect(optionNames.contains("runtime-url --device <selector>"))
2122
#expect(optionNames.contains("--device"))
2223
#expect(optionNames.contains("--name"))
2324
#expect(optionNames.contains("--runtime"))
2425
#expect(optionNames.contains("runtime-url --platform harmony --target <target>"))
26+
#expect(device.examples.contains("triton device runtime-url --device harmony-a --probe-manifest --json"))
2527
#expect(device.providedCapabilities.contains("host-device"))
2628
#expect(device.providedCapabilities.contains("device-alias"))
2729
#expect(device.providedCapabilities.contains("host-device-selector"))
@@ -96,6 +98,28 @@ struct DeviceCrossPlatformTests {
9698
#expect(harmony.transport == "TCP")
9799
}
98100

101+
@Test("host device target can round-trip into Harmony runtime target")
102+
func hostDeviceTargetCanRoundTripIntoHarmonyRuntimeTarget() {
103+
let target = HostDeviceTarget(
104+
platform: "harmony",
105+
id: "harmony:127.0.0.1:10100",
106+
target: "127.0.0.1:10100",
107+
state: "Connected",
108+
ready: true,
109+
source: "hdc",
110+
name: nil,
111+
runtime: nil,
112+
transport: "TCP"
113+
)
114+
115+
let harmony = harmonyTarget(from: target)
116+
117+
#expect(harmony.target == "127.0.0.1:10100")
118+
#expect(harmony.state == "Connected")
119+
#expect(harmony.transport == "TCP")
120+
#expect(harmony.source == "hdc")
121+
}
122+
99123
@Test("host device selector prefers explicit matches and unique ready candidates")
100124
func hostDeviceSelectorPrefersExplicitMatchesAndUniqueReadyCandidates() {
101125
let first = HostDeviceTarget(

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,14 +299,17 @@ When multiple iOS Simulator apps are connected to the same `triton serve`, `trit
299299
When validating a standalone embedded runtime HTTP endpoint before it is connected through `triton serve`, bypass the local control server with `--runtime-base-url`:
300300

301301
```bash
302-
triton device runtime-url --platform harmony --target 127.0.0.1:10100 --probe-manifest --json
302+
triton device alias set harmony-a --platform harmony --target 127.0.0.1:10100 --json
303+
triton device runtime-url --device harmony-a --probe-manifest --json
303304
triton runtime manifest --runtime-base-url http://127.0.0.1:28767 --json
304305
triton state route --runtime-base-url http://127.0.0.1:28767 --json
305306
triton snapshot --runtime-base-url http://127.0.0.1:28767 --json
306307
triton ledger --runtime-base-url http://127.0.0.1:28767 --jsonl
307308
triton set-text "密码" "$TRITON_PASSWORD" --secure --runtime-base-url http://127.0.0.1:28767 --json
308309
```
309310

311+
`triton device runtime-url --platform harmony --target 127.0.0.1:10100 --probe-manifest --json` remains available as a compatibility path.
312+
310313
For the Harmony demo, `28767` is the host-access embedded runtime port exposed through HDC `fport`; `18765` remains the device-to-host gateway fallback port used by the demo UI.
311314

312315
Host-side simulator helpers are available without a running TritonKit runtime. They wrap `xcrun simctl` but keep JSON output and stable Triton error envelopes:
@@ -511,14 +514,17 @@ Business semantics are opt-in provider hooks. A generic HAR must not pretend it
511514
When the Harmony embedded runtime is reachable through HDC `fport` but has not been connected through `triton serve`, use direct runtime checks:
512515

513516
```bash
514-
triton device runtime-url --platform harmony --target 127.0.0.1:10100 --probe-manifest --json
517+
triton device alias set harmony-a --platform harmony --target 127.0.0.1:10100 --json
518+
triton device runtime-url --device harmony-a --probe-manifest --json
515519
triton runtime manifest --runtime-base-url http://127.0.0.1:28767 --json
516520
triton state route --runtime-base-url http://127.0.0.1:28767 --json
517521
triton snapshot --runtime-base-url http://127.0.0.1:28767 --json
518522
triton ledger --runtime-base-url http://127.0.0.1:28767 --jsonl
519523
triton set-text "密码" "$TRITON_PASSWORD" --secure --runtime-base-url http://127.0.0.1:28767 --json
520524
```
521525

526+
`triton device runtime-url --platform harmony --target 127.0.0.1:10100 --probe-manifest --json` remains available as a compatibility path.
527+
522528
For the Harmony demo, `28767` is the host-access embedded runtime port exposed through HDC `fport`; `18765` remains the device-to-host gateway fallback port used by the demo UI.
523529

524530
## Release Assets

Sources/TritonKitCLI/CLIHostCommands.swift

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,7 +2062,12 @@ struct DeviceRuntimeURL: AsyncParsableCommand {
20622062
static let configuration = CommandConfiguration(commandName: "runtime-url", abstract: "Prepare and print a Harmony embedded runtime base URL")
20632063

20642064
@Option(help: "Platform adapter: harmony") var platform: HostDevicePlatform = .harmony
2065-
@Option(help: "Target id, for example 127.0.0.1:10100") var target: String?
2065+
@Option(help: "Unified host device selector: alias, harmony:<target>, raw id, or current") var device: String?
2066+
@Option(help: "Target id, for example 127.0.0.1:10100; compatibility path") var target: String?
2067+
@Option(help: "Device name filter when available") var name: String?
2068+
@Option(help: "Runtime filter when available") var runtime: String?
2069+
@Option(help: "Target state filter, for example connected") var state: String?
2070+
@Flag(help: "Only match ready targets") var ready = false
20662071
@Option(help: "Path to hdc executable") var hdc: String = "hdc"
20672072
@Option(help: "Local TCP port for host-side runtime access") var localPort: Int = TKHarmonyRuntimeDefaults.hostAccessPort
20682073
@Option(help: "Remote TCP port where the Harmony embedded runtime listens") var remotePort: Int = TKHarmonyRuntimeDefaults.hostAccessPort
@@ -2077,9 +2082,23 @@ struct DeviceRuntimeURL: AsyncParsableCommand {
20772082
guard platform == .harmony else {
20782083
throw RuntimeError("device runtime-url only supports Harmony targets")
20792084
}
2085+
if device != nil && target != nil {
2086+
throw HostDeviceSelectionError.parameterConflict("--device cannot be combined with --target.")
2087+
}
20802088
try validateTCPPort(localPort, name: "--local-port")
20812089
try validateTCPPort(remotePort, name: "--remote-port")
2082-
let selected = try resolveHarmonyTarget(target: target, hdc: hdc)
2090+
let selection = try resolveHostDeviceSelection(
2091+
request: HostDeviceSelectionRequest(
2092+
device: device ?? target,
2093+
platform: .harmony,
2094+
name: name,
2095+
runtime: runtime,
2096+
state: state,
2097+
ready: ready
2098+
),
2099+
hdc: hdc
2100+
)
2101+
let selected = harmonyTarget(from: selection.target)
20832102
let baseURL = "http://127.0.0.1:\(localPort)"
20842103
var sourceCommand: String?
20852104
var forwarded = false

Sources/TritonKitCLI/CLIHostRuntime.swift

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,15 @@ func hostDeviceTarget(from target: TKHarmonyTarget) -> HostDeviceTarget {
538538
)
539539
}
540540

541+
func harmonyTarget(from target: HostDeviceTarget) -> TKHarmonyTarget {
542+
TKHarmonyTarget(
543+
target: target.target,
544+
state: target.state,
545+
transport: target.transport ?? "hdc",
546+
source: target.source
547+
)
548+
}
549+
541550
func ensureParentDirectory(for path: String) throws {
542551
let directory = URL(fileURLWithPath: path).deletingLastPathComponent()
543552
try FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true)
@@ -614,13 +623,7 @@ func captureHostDeviceScreenshot(platform: HostDevicePlatform, target: HostDevic
614623
note: "Host-side iOS simulator screenshot was written."
615624
)
616625
case .harmony:
617-
let harmonyTarget = TKHarmonyTarget(
618-
target: target.target,
619-
state: target.state,
620-
transport: target.transport ?? "hdc",
621-
source: target.source
622-
)
623-
let capture = try captureHarmonyScreenshot(selected: harmonyTarget, hdc: hdc, output: output)
626+
let capture = try captureHarmonyScreenshot(selected: harmonyTarget(from: target), hdc: hdc, output: output)
624627
return HostDeviceArtifactOutput(
625628
ok: true,
626629
action: "screenshot",
@@ -667,12 +670,7 @@ func waitForHostDeviceReady(
667670
return event
668671
}
669672
case .harmony:
670-
let harmonyTarget = TKHarmonyTarget(
671-
target: selected.target,
672-
state: selected.state,
673-
transport: selected.transport ?? "hdc",
674-
source: selected.source
675-
)
673+
let harmonyTarget = harmonyTarget(from: selected)
676674
let command = TKHarmonyHDCCommand.bootCompleted(target: harmonyTarget.target, executable: hdc)
677675
let result = try runHostCommand(command)
678676
let ready = TKHarmonyBootCompletedParser.isReady(result.stdout)

Sources/TritonKitCLI/CLISchemaRuntime.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,8 @@ func commandSchemas() -> [TKCommandSchema] {
815815
TKCommandSchemaOption(name: "resolve <selector>", type: "Subcommand", description: "Resolve a target selector without executing an action"),
816816
TKCommandSchemaOption(name: "wait-ready --device <selector>", type: "Subcommand", description: "Wait for iOS Booted or Harmony bootevent.boot.completed"),
817817
TKCommandSchemaOption(name: "screenshot --device <selector> --output <path>", type: "Subcommand", description: "Capture a host-side iOS or Harmony screenshot artifact"),
818-
TKCommandSchemaOption(name: "runtime-url --platform harmony --target <target>", type: "Subcommand", description: "Prepare HDC fport and print a direct embedded runtime base URL"),
818+
TKCommandSchemaOption(name: "runtime-url --device <selector>", type: "Subcommand", description: "Prepare HDC fport and print a direct Harmony embedded runtime base URL"),
819+
TKCommandSchemaOption(name: "runtime-url --platform harmony --target <target>", type: "Subcommand", description: "Compatibility path for preparing a direct Harmony embedded runtime base URL"),
819820
TKCommandSchemaOption(name: "--platform", type: "ios|harmony", defaultValue: "harmony", description: "Host device platform adapter"),
820821
TKCommandSchemaOption(name: "--device", type: "String", description: "Unified target selector: alias, sim:<udid>, harmony:<target>, raw id, booted, or current"),
821822
TKCommandSchemaOption(name: "--name", type: "String", description: "Device name filter, for example iPhone 15"),
@@ -847,6 +848,7 @@ func commandSchemas() -> [TKCommandSchema] {
847848
"triton device alias set harmony-a --platform harmony --target 127.0.0.1:10100 --json",
848849
"triton device wait-ready --device harmony-a --json",
849850
"triton device screenshot --device harmony-a --output /tmp/smoke.jpeg --json",
851+
"triton device runtime-url --device harmony-a --probe-manifest --json",
850852
"triton device runtime-url --platform harmony --target 127.0.0.1:10100 --probe-manifest --json",
851853
],
852854
successShape: "{ ok, platform, tools[]?, targets[]?, defaultTarget?, target?, defaultsPath?, ready?, artifact?, baseURL?, manifest?, sourceCommand?, sourceCommands?[] }",

0 commit comments

Comments
 (0)