@ohos-perf/cli 0.20.0 → 0.21.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/dist/index.js +92 -0
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "fs
|
|
|
5
5
|
import { join } from "path";
|
|
6
6
|
import {
|
|
7
7
|
discoverCases,
|
|
8
|
+
describeDecision,
|
|
8
9
|
loadCases,
|
|
9
10
|
OhosPerfError as OhosPerfError2,
|
|
10
11
|
parseScenario
|
|
@@ -371,6 +372,45 @@ stopped ${stopped}
|
|
|
371
372
|
`, exitCode: 1 };
|
|
372
373
|
}
|
|
373
374
|
}
|
|
375
|
+
async function runAgentCommand(deps2, req, opts) {
|
|
376
|
+
if (req.task.trim() === "") {
|
|
377
|
+
return {
|
|
378
|
+
stdout: "",
|
|
379
|
+
stderr: "agent: the task must not be empty\n",
|
|
380
|
+
exitCode: 1
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
try {
|
|
384
|
+
const result = await deps2.agent(req);
|
|
385
|
+
if (opts.json) return { stdout: json(result), stderr: "", exitCode: 0 };
|
|
386
|
+
const { transcript, device } = result;
|
|
387
|
+
const outcome = transcript.status === "completed" ? "completed (the screen confirmed it)" : transcript.status === "unverified" ? "unverified (the screen did not confirm it)" : transcript.status === "refused" ? "refused (an irreversible action was stopped)" : `exhausted (the step cap, ${req.maxSteps}, was reached)`;
|
|
388
|
+
const lines = transcript.steps.map((step) => {
|
|
389
|
+
const did = step.action === void 0 ? step.status : `${describeStep(step)} \u2014 ${step.status}`;
|
|
390
|
+
const moved = step.navigated ? "moved" : "no change";
|
|
391
|
+
const detail = step.detail === void 0 ? "" : `
|
|
392
|
+
${step.detail}`;
|
|
393
|
+
return ` ${String(step.index + 1).padStart(2)}. ${did} (${moved}): ${step.reason}${detail}`;
|
|
394
|
+
});
|
|
395
|
+
return {
|
|
396
|
+
stdout: `agent ${transcript.app} on ${device.id} (${device.kind})
|
|
397
|
+
task ${transcript.task}
|
|
398
|
+
result ${outcome}
|
|
399
|
+
walk ${transcript.steps.length} steps, ${transcript.statesReached} states reached
|
|
400
|
+
` + lines.map((line) => `${line}
|
|
401
|
+
`).join(""),
|
|
402
|
+
stderr: "",
|
|
403
|
+
exitCode: transcript.status === "completed" ? 0 : 1
|
|
404
|
+
};
|
|
405
|
+
} catch (err) {
|
|
406
|
+
return { stdout: "", stderr: `${failureLine(err)}
|
|
407
|
+
`, exitCode: 1 };
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
function describeStep(step) {
|
|
411
|
+
if (step.action === void 0) return step.status;
|
|
412
|
+
return describeDecision({ action: step.action, reason: step.reason });
|
|
413
|
+
}
|
|
374
414
|
async function runRender(deps2, req, opts) {
|
|
375
415
|
try {
|
|
376
416
|
const result = await deps2.render(req);
|
|
@@ -799,6 +839,9 @@ import {
|
|
|
799
839
|
hapSection,
|
|
800
840
|
analyzeBinaries,
|
|
801
841
|
extractBinaries,
|
|
842
|
+
httpAgentModel,
|
|
843
|
+
readAgentConfig,
|
|
844
|
+
runAgent,
|
|
802
845
|
readSceneMetadata,
|
|
803
846
|
readUiTree,
|
|
804
847
|
resolveAppIdentity,
|
|
@@ -1023,6 +1066,21 @@ function realDeps(version = packageVersion(), overrides = {}) {
|
|
|
1023
1066
|
const collectDevice = overrides.collectDevice ?? ((target) => connect(target === void 0 ? {} : { target }));
|
|
1024
1067
|
const gestureDevice = overrides.gestureDevice ?? ((target) => connect(target === void 0 ? {} : { target }));
|
|
1025
1068
|
const exploreDevice = overrides.exploreDevice ?? ((target) => connect(target === void 0 ? {} : { target }));
|
|
1069
|
+
const agentDevice = overrides.agentDevice ?? exploreDevice;
|
|
1070
|
+
const agentModel = overrides.agentModel ?? ((name) => {
|
|
1071
|
+
const config = readAgentConfig(process.env);
|
|
1072
|
+
if (config === void 0) {
|
|
1073
|
+
throw new OhosPerfError3(
|
|
1074
|
+
"no model endpoint is configured; set OHOS_PERF_AGENT_BASE_URL and OHOS_PERF_AGENT_API_KEY (or GLM_BASE_URL and GLM_API_KEY), and optionally OHOS_PERF_AGENT_MODEL (or GLM_MODEL)",
|
|
1075
|
+
{ code: "AGENT_BAD_CONFIG" }
|
|
1076
|
+
);
|
|
1077
|
+
}
|
|
1078
|
+
return httpAgentModel({
|
|
1079
|
+
...config,
|
|
1080
|
+
...name === void 0 ? {} : { model: name },
|
|
1081
|
+
fetch: (url, init) => fetch(url, init)
|
|
1082
|
+
});
|
|
1083
|
+
});
|
|
1026
1084
|
const doctor = {
|
|
1027
1085
|
resolveHdc,
|
|
1028
1086
|
async resolveStreamer() {
|
|
@@ -1439,6 +1497,17 @@ function realDeps(version = packageVersion(), overrides = {}) {
|
|
|
1439
1497
|
])]
|
|
1440
1498
|
};
|
|
1441
1499
|
},
|
|
1500
|
+
async agent(req) {
|
|
1501
|
+
const model = agentModel(req.model);
|
|
1502
|
+
const device = await agentDevice(req.target);
|
|
1503
|
+
const transcript = await runAgent(device, model, {
|
|
1504
|
+
task: req.task,
|
|
1505
|
+
app: req.app,
|
|
1506
|
+
maxSteps: req.maxSteps,
|
|
1507
|
+
...req.allowIrreversible === true ? { allowIrreversible: true } : {}
|
|
1508
|
+
});
|
|
1509
|
+
return { transcript, device: { id: device.id, kind: device.kind } };
|
|
1510
|
+
},
|
|
1442
1511
|
async run(req) {
|
|
1443
1512
|
const device = await connect(req.target === void 0 ? {} : { target: req.target });
|
|
1444
1513
|
const runner = new ScenarioRunner(device, {
|
|
@@ -1903,6 +1972,29 @@ function buildProgram(deps2, io, opts = {}) {
|
|
|
1903
1972
|
)
|
|
1904
1973
|
);
|
|
1905
1974
|
});
|
|
1975
|
+
program2.command("agent").description("drive an app toward a task with a model, and verify the screen reached").argument("<app>", "bundle name to drive, e.g. com.example.app").argument("<task>", "what the model should accomplish, in your words").option("--max-steps <n>", "stop after this many model turns", "50").option("--model <name>", "model name to send; defaults to the configured one").option("--allow-irreversible", "let the guard's refusals through (payment, ordering, ...)").option("--target <id>", "drive this hdc target instead of the first connected one").option("--json", "print the transcript as JSON").action(async (app, task, opts2) => {
|
|
1976
|
+
let maxSteps;
|
|
1977
|
+
try {
|
|
1978
|
+
maxSteps = parseMaxSteps(opts2.maxSteps);
|
|
1979
|
+
} catch (err) {
|
|
1980
|
+
io.emit({ stdout: "", stderr: `${failureLine(err)}\\n`, exitCode: 1 });
|
|
1981
|
+
return;
|
|
1982
|
+
}
|
|
1983
|
+
io.emit(
|
|
1984
|
+
await runAgentCommand(
|
|
1985
|
+
deps2,
|
|
1986
|
+
{
|
|
1987
|
+
app,
|
|
1988
|
+
task,
|
|
1989
|
+
maxSteps,
|
|
1990
|
+
...opts2.model === void 0 ? {} : { model: opts2.model },
|
|
1991
|
+
...opts2.allowIrreversible === true ? { allowIrreversible: true } : {},
|
|
1992
|
+
...opts2.target === void 0 ? {} : { target: opts2.target }
|
|
1993
|
+
},
|
|
1994
|
+
{ json: opts2.json }
|
|
1995
|
+
)
|
|
1996
|
+
);
|
|
1997
|
+
});
|
|
1906
1998
|
program2.command("tools").description("list the named drill-down queries an agent can call").option("--json", "print the query definitions as JSON").action((opts2) => {
|
|
1907
1999
|
io.emit(runTools(deps2, opts2));
|
|
1908
2000
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ohos-perf/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"description": "Command-line interface for HarmonyOS performance analysis: doctor, caps, collect, analyze, query, tools, compare, report, gesture, emulator and selector-driven scenarios",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"harmonyos",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"access": "public"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@ohos-perf/core": "0.
|
|
39
|
+
"@ohos-perf/core": "0.21.0",
|
|
40
40
|
"commander": "^12.1.0"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|