@hmharness/domain-harmony 0.13.4 → 0.13.5

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/apikg.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @hmharness/domain-harmony - apikg (API knowledge graph, the codelin api_kg gap)
3
3
  * The agent guesses HarmonyOS APIs because it cannot SEE the SDK. The
4
- * declarations are right there on disk (ets/api/*.d.ts, 927 files) - this
4
+ * declarations are right there on disk (ets/api/*.d.ts, several hundred files) - this
5
5
  * module indexes them ONCE into HMH_HOME/apikg and answers lookups with
6
6
  * EVIDENCE: the declaration snippet + file:line + kit membership, so a
7
7
  * wrong API name is caught by "not in the SDK" instead of hallucinated.
@@ -13,6 +13,7 @@
13
13
  */
14
14
  import { mkdir, readdir, readFile, stat, writeFile } from 'node:fs/promises';
15
15
  import { join } from 'node:path';
16
+ import { resolveDevecoHome } from "./resolve.js";
16
17
  export function sdkApiDir(devecoHome) {
17
18
  return join(devecoHome, 'sdk', 'default', 'openharmony', 'ets', 'api');
18
19
  }
@@ -136,7 +137,7 @@ export function lookupSymbol(index, query, limit = 4) {
136
137
  /* ---------------- tool ---------------- */
137
138
  export const harmonyApiLookup = {
138
139
  name: 'harmony_api_lookup',
139
- description: 'Look up a HarmonyOS/ArkTS API symbol in the ACTUAL local SDK declarations (927 d.ts files indexed) - returns the declaration snippet with file:line evidence and kit membership. Use BEFORE writing code that calls any @ohos API: confirms the symbol exists, its exact signature context, and which kit it belongs to. A miss means "not in this SDK" - do not guess, reconsider the name or check the docs.',
140
+ description: 'Look up a HarmonyOS/ArkTS API symbol in the ACTUAL local SDK declarations (the SDK d.ts tree, indexed on first use) - returns the declaration snippet with file:line evidence and kit membership. Use BEFORE writing code that calls any @ohos API: confirms the symbol exists, its exact signature context, and which kit it belongs to. A miss means "not in this SDK" - do not guess, reconsider the name or check the docs.',
140
141
  parameters: {
141
142
  type: 'object',
142
143
  properties: {
@@ -147,7 +148,7 @@ export const harmonyApiLookup = {
147
148
  needsApproval: () => false, // read-only; first call builds the local index
148
149
  async execute(args) {
149
150
  const { homedir } = await import('node:os');
150
- const deveco = process.env.HM_DEVECO_HOME ?? 'C:\\DevEco-Studio';
151
+ const deveco = resolveDevecoHome();
151
152
  const home = process.env.HMH_HOME ?? join(homedir(), '.hmharness');
152
153
  const index = await loadApiIndex(deveco, home);
153
154
  if (!index || index.symbolCount === 0) {
package/dist/emulator.js CHANGED
@@ -15,6 +15,7 @@ import { mkdir, readdir, readFile, rm, writeFile } from 'node:fs/promises';
15
15
  import { accessSync } from 'node:fs';
16
16
  import { join } from 'node:path';
17
17
  import { promisify } from 'node:util';
18
+ import { resolveEmulatorExe } from "./resolve.js";
18
19
  const exec = promisify(execFile);
19
20
  function localAppData() {
20
21
  return process.env.LOCALAPPDATA ?? join(process.env.USERPROFILE ?? '.', 'AppData', 'Local');
@@ -26,21 +27,7 @@ export function imageRoot() {
26
27
  return join(localAppData(), 'Huawei', 'Sdk');
27
28
  }
28
29
  function emulatorExe() {
29
- // same discoverability contract as findHdc: honor HM_DEVECO_HOME, then
30
- // probe the standard install locations. The bare-drive default missed the
31
- // common "Program Files" install and broke every emulator tool on stock
32
- // DevEco setups (day-18 SELFFEED: the agent had to fake a junction).
33
- if (process.env.HM_DEVECO_HOME)
34
- return join(process.env.HM_DEVECO_HOME, 'tools', 'emulator', 'Emulator.exe');
35
- for (const home of ['C:\\Program Files\\Huawei\\DevEco Studio', 'D:\\Program Files\\Huawei\\DevEco Studio', 'C:\\DevEco-Studio']) {
36
- const cand = join(home, 'tools', 'emulator', 'Emulator.exe');
37
- try {
38
- accessSync(cand);
39
- return cand;
40
- }
41
- catch { /* next */ }
42
- }
43
- return join('C:\\DevEco-Studio', 'tools', 'emulator', 'Emulator.exe');
30
+ return resolveEmulatorExe();
44
31
  }
45
32
  async function readLists() {
46
33
  try {
package/dist/index.js CHANGED
@@ -21,21 +21,10 @@ import { harmonySign } from "./signing.js";
21
21
  import { harmonyDeviceTest } from "./ondevice.js";
22
22
  import { harmonyApiLookup } from "./apikg.js";
23
23
  import { harmonyUiRegression } from "./uiregress.js";
24
+ import { resolveDevecoHome } from "./resolve.js";
24
25
  const exec = promisify(execFile);
25
26
  function devecoHome() {
26
- if (process.env.HM_DEVECO_HOME)
27
- return process.env.HM_DEVECO_HOME;
28
- // standard install locations probed in order: the old bare-drive default
29
- // missed the common "Program Files" install and broke every device tool
30
- // on stock DevEco setups (mcp-serve round-trip test caught it)
31
- for (const home of ['C:\\Program Files\\Huawei\\DevEco Studio', 'D:\\Program Files\\Huawei\\DevEco Studio', 'C:\\DevEco-Studio']) {
32
- try {
33
- accessSync(join(home, 'sdk', 'default', 'openharmony', 'toolchains', 'hdc.exe'));
34
- return home;
35
- }
36
- catch { /* next */ }
37
- }
38
- return 'C:\\DevEco-Studio';
27
+ return resolveDevecoHome();
39
28
  }
40
29
  async function run(cmd, args, timeoutMs = 20_000, cwd, extraEnv) {
41
30
  try {
package/dist/lint.js CHANGED
@@ -8,9 +8,10 @@ import { execFile } from 'node:child_process';
8
8
  import { access } from 'node:fs/promises';
9
9
  import { isAbsolute, join, resolve } from 'node:path';
10
10
  import { promisify } from 'node:util';
11
+ import { resolveDevecoHome } from "./resolve.js";
11
12
  const exec = promisify(execFile);
12
13
  function devecoHome() {
13
- return process.env.HM_DEVECO_HOME ?? 'C:\\DevEco-Studio';
14
+ return resolveDevecoHome();
14
15
  }
15
16
  /** Returns a launcher: either the bare command or [node, <run/index.js>]. */
16
17
  async function findCodelinter() {
package/dist/ondevice.js CHANGED
@@ -15,6 +15,7 @@ import { execFile } from 'node:child_process';
15
15
  import { access } from 'node:fs/promises';
16
16
  import { join, resolve } from 'node:path';
17
17
  import { promisify } from 'node:util';
18
+ import { resolveDevecoHome } from "./resolve.js";
18
19
  const execCb = promisify(execFile);
19
20
  async function exists(p) {
20
21
  try {
@@ -86,7 +87,7 @@ export const harmonyDeviceTest = {
86
87
  needsApproval: () => true, // installs+launches+uninstalls on the device
87
88
  async execute(args, ctx) {
88
89
  // resolve hdc
89
- const deveco = process.env.HM_DEVECO_HOME ?? 'C:\\DevEco-Studio';
90
+ const deveco = resolveDevecoHome();
90
91
  let hdc = 'hdc';
91
92
  try {
92
93
  await execCb(hdc, ['--version'], { timeout: 8000, windowsHide: true });
@@ -0,0 +1,14 @@
1
+ /** Standard DevEco install locations, probed in order. */
2
+ export declare const DEVECO_CANDIDATES: string[];
3
+ /** Resolve the DevEco Studio home: explicit env wins, then probe standard
4
+ * installs by a known child (hdc.exe), finally fall back to the legacy bare
5
+ * path (callers surface a clear not-found error from there). */
6
+ export declare function resolveDevecoHome(): string;
7
+ /** Resolve the Emulator.exe path with the same contract (its probe child is
8
+ * Emulator.exe itself, so a bare home without the emulator component still
9
+ * resolves to a path whose absence callers report clearly). */
10
+ export declare function resolveEmulatorExe(): string;
11
+ /** Resolve hdc: PATH first, then the SDK layout under the resolved home. */
12
+ export declare function resolveHdc(run: (args: string[]) => Promise<{
13
+ ok: boolean;
14
+ }>): Promise<string>;
@@ -0,0 +1,64 @@
1
+ /**
2
+ * @hmharness/domain-harmony - resolve (single implementation)
3
+ * ONE place for DevEco home discovery. The 2026-09-11 audit lesson (security
4
+ * gates must have a single shared implementation) applies to path resolution
5
+ * too: seven callers each carried their own `HM_DEVECO_HOME ?? 'C:\\DevEco-Studio'`,
6
+ * so the standard "Program Files" install kept breaking different tools one
7
+ * patch at a time (hdc 0.11.0, emulator 0.13.1, then five more found by the
8
+ * day-29 SELFFEED sweep). Every tool imports from here now.
9
+ */
10
+ import { accessSync } from 'node:fs';
11
+ import { join } from 'node:path';
12
+ /** Standard DevEco install locations, probed in order. */
13
+ export const DEVECO_CANDIDATES = [
14
+ 'C:\\Program Files\\Huawei\\DevEco Studio',
15
+ 'D:\\Program Files\\Huawei\\DevEco Studio',
16
+ 'C:\\DevEco-Studio',
17
+ ];
18
+ /** Sibling of the resolved home that must exist for a probe to count. */
19
+ const hdcRel = ['sdk', 'default', 'openharmony', 'toolchains', 'hdc.exe'];
20
+ /** Resolve the DevEco Studio home: explicit env wins, then probe standard
21
+ * installs by a known child (hdc.exe), finally fall back to the legacy bare
22
+ * path (callers surface a clear not-found error from there). */
23
+ export function resolveDevecoHome() {
24
+ if (process.env.HM_DEVECO_HOME)
25
+ return process.env.HM_DEVECO_HOME;
26
+ for (const home of DEVECO_CANDIDATES) {
27
+ try {
28
+ accessSync(join(home, ...hdcRel));
29
+ return home;
30
+ }
31
+ catch { /* next */ }
32
+ }
33
+ return DEVECO_CANDIDATES[DEVECO_CANDIDATES.length - 1];
34
+ }
35
+ /** Resolve the Emulator.exe path with the same contract (its probe child is
36
+ * Emulator.exe itself, so a bare home without the emulator component still
37
+ * resolves to a path whose absence callers report clearly). */
38
+ export function resolveEmulatorExe() {
39
+ if (process.env.HM_DEVECO_HOME)
40
+ return join(process.env.HM_DEVECO_HOME, 'tools', 'emulator', 'Emulator.exe');
41
+ for (const home of DEVECO_CANDIDATES) {
42
+ const cand = join(home, 'tools', 'emulator', 'Emulator.exe');
43
+ try {
44
+ accessSync(cand);
45
+ return cand;
46
+ }
47
+ catch { /* next */ }
48
+ }
49
+ return join(DEVECO_CANDIDATES[DEVECO_CANDIDATES.length - 1], 'tools', 'emulator', 'Emulator.exe');
50
+ }
51
+ /** Resolve hdc: PATH first, then the SDK layout under the resolved home. */
52
+ export async function resolveHdc(run) {
53
+ const p = await run(['--version']);
54
+ if (p.ok)
55
+ return 'hdc';
56
+ const candidate = join(resolveDevecoHome(), ...hdcRel);
57
+ try {
58
+ accessSync(candidate);
59
+ return candidate;
60
+ }
61
+ catch {
62
+ return '';
63
+ }
64
+ }
package/dist/signing.js CHANGED
@@ -26,6 +26,7 @@ import { execFile } from 'node:child_process';
26
26
  import { access, mkdir, readdir, writeFile } from 'node:fs/promises';
27
27
  import { join, resolve } from 'node:path';
28
28
  import { promisify } from 'node:util';
29
+ import { resolveDevecoHome } from "./resolve.js";
29
30
  const execCb = promisify(execFile);
30
31
  async function exists(p) {
31
32
  try {
@@ -125,7 +126,7 @@ export const harmonySign = {
125
126
  },
126
127
  needsApproval: () => true,
127
128
  async execute(args, ctx) {
128
- const deveco = process.env.HM_DEVECO_HOME ?? 'C:\\DevEco-Studio';
129
+ const deveco = resolveDevecoHome();
129
130
  const p = hapsignToolPaths(deveco);
130
131
  if (!(await exists(p.jar)))
131
132
  return { output: `hap-sign-tool.jar not found at ${p.jar}. Set HM_DEVECO_HOME.`, isError: true };
package/dist/uiregress.js CHANGED
@@ -20,6 +20,7 @@ import { mkdir, readFile, rm } from 'node:fs/promises';
20
20
  import { join } from 'node:path';
21
21
  import { promisify } from 'node:util';
22
22
  import { chatVision, foundNothing, isVisionRefusal } from '@hmharness/kernel';
23
+ import { resolveDevecoHome } from "./resolve.js";
23
24
  const execCb = promisify(execFile);
24
25
  /**
25
26
  * Walk the vision chain until a provider truly LOOKS at the image. A reply
@@ -164,7 +165,7 @@ export const harmonyUiRegression = {
164
165
  }
165
166
  const chainNames = vision.map((p) => `${p.model}${p.supportsVision === false ? ' (marked text-only!)' : ''}`);
166
167
  // hdc
167
- const deveco = process.env.HM_DEVECO_HOME ?? 'C:\\DevEco-Studio';
168
+ const deveco = resolveDevecoHome();
168
169
  let hdc = 'hdc';
169
170
  try {
170
171
  await execCb(hdc, ['--version'], { timeout: 8000, windowsHide: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hmharness/domain-harmony",
3
- "version": "0.13.4",
3
+ "version": "0.13.5",
4
4
  "description": "hmharness HarmonyOS domain core: device, toolchain, build, and project lifecycle capabilities. HarmonyOS is the framework's native domain, not an add-on.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",