deveco-harness 0.1.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.
Files changed (135) hide show
  1. package/README.en.md +71 -0
  2. package/README.md +71 -0
  3. package/deveco-harness.example.jsonc +32 -0
  4. package/dist/index.js +758 -0
  5. package/package.json +48 -0
  6. package/prompts/build.txt +164 -0
  7. package/prompts/plan.txt +118 -0
  8. package/skills/arkts-error-fixes/README.md +151 -0
  9. package/skills/arkts-error-fixes/SKILL.md +150 -0
  10. package/skills/arkts-error-fixes/assets/AnyTypeError.ets +269 -0
  11. package/skills/arkts-error-fixes/assets/AppStorageError.ets +22 -0
  12. package/skills/arkts-error-fixes/assets/ArrowFunctionConversionError.ets +42 -0
  13. package/skills/arkts-error-fixes/assets/AvoidAreaTypeError.ets +43 -0
  14. package/skills/arkts-error-fixes/assets/BreakpointTypeError.ets +71 -0
  15. package/skills/arkts-error-fixes/assets/CatchClauseTypeError.ets +54 -0
  16. package/skills/arkts-error-fixes/assets/ColorConsistencyError.ets +88 -0
  17. package/skills/arkts-error-fixes/assets/ColorPropertyError.ets +39 -0
  18. package/skills/arkts-error-fixes/assets/ContextTypeError.ets +105 -0
  19. package/skills/arkts-error-fixes/assets/DecoratorStateError.ets +64 -0
  20. package/skills/arkts-error-fixes/assets/DisplayListenerTypeError.ets +129 -0
  21. package/skills/arkts-error-fixes/assets/DuplicateEntryError.ets +35 -0
  22. package/skills/arkts-error-fixes/assets/ESObjectTypeError.ets +137 -0
  23. package/skills/arkts-error-fixes/assets/FontColorPropertyError.ets +42 -0
  24. package/skills/arkts-error-fixes/assets/FunctionReturnTypeError.ets +41 -0
  25. package/skills/arkts-error-fixes/assets/IDataSourceError.ets +79 -0
  26. package/skills/arkts-error-fixes/assets/ImplementationNotAllowedError.ets +38 -0
  27. package/skills/arkts-error-fixes/assets/InterfaceMethodSignatureError.ets +43 -0
  28. package/skills/arkts-error-fixes/assets/NotificationError.ets +34 -0
  29. package/skills/arkts-error-fixes/assets/ObjectLiteralInterfaceError.ets +49 -0
  30. package/skills/arkts-error-fixes/assets/ObjectLiteralTypeError.ets +54 -0
  31. package/skills/arkts-error-fixes/assets/ObjectSpreadError.ets +29 -0
  32. package/skills/arkts-error-fixes/assets/PossiblyNullError.ets +32 -0
  33. package/skills/arkts-error-fixes/assets/ResourceConversionError.ets +159 -0
  34. package/skills/arkts-error-fixes/assets/StandaloneFunctionContext.ets +116 -0
  35. package/skills/arkts-error-fixes/assets/StandaloneFunctionError.ets +85 -0
  36. package/skills/arkts-error-fixes/assets/StorageLinkDefaultError.ets +41 -0
  37. package/skills/arkts-error-fixes/assets/TitleButtonRectTypeError.ets +86 -0
  38. package/skills/arkts-error-fixes/assets/UnusedVariableWarning.ets +102 -0
  39. package/skills/arkts-error-fixes/assets/UtilityTypeError.ets +176 -0
  40. package/skills/arkts-error-fixes/assets/WindowRectSizeError.ets +65 -0
  41. package/skills/arkts-error-fixes/assets/WindowTypeError.ets +37 -0
  42. package/skills/arkts-error-fixes/reference/any_type_errors.md +433 -0
  43. package/skills/arkts-error-fixes/reference/appstorage_errors.md +95 -0
  44. package/skills/arkts-error-fixes/reference/arrow_function_conversion_errors.md +163 -0
  45. package/skills/arkts-error-fixes/reference/avoid_area_type_errors.md +59 -0
  46. package/skills/arkts-error-fixes/reference/breakpoint_type_errors.md +122 -0
  47. package/skills/arkts-error-fixes/reference/catch_clause_type_errors.md +89 -0
  48. package/skills/arkts-error-fixes/reference/color_consistency_errors.md +209 -0
  49. package/skills/arkts-error-fixes/reference/color_property_errors.md +136 -0
  50. package/skills/arkts-error-fixes/reference/context_type_errors.md +260 -0
  51. package/skills/arkts-error-fixes/reference/decorator_state_errors.md +109 -0
  52. package/skills/arkts-error-fixes/reference/display_listener_type_errors.md +149 -0
  53. package/skills/arkts-error-fixes/reference/duplicate_entry_errors.md +193 -0
  54. package/skills/arkts-error-fixes/reference/esobject_type_errors.md +110 -0
  55. package/skills/arkts-error-fixes/reference/fontcolor_property_errors.md +104 -0
  56. package/skills/arkts-error-fixes/reference/function_return_type_errors.md +194 -0
  57. package/skills/arkts-error-fixes/reference/idata_source_errors.md +77 -0
  58. package/skills/arkts-error-fixes/reference/implementation_not_allowed_errors.md +191 -0
  59. package/skills/arkts-error-fixes/reference/interface_method_signature_errors.md +143 -0
  60. package/skills/arkts-error-fixes/reference/notification_errors.md +110 -0
  61. package/skills/arkts-error-fixes/reference/object_literal_interface_errors.md +156 -0
  62. package/skills/arkts-error-fixes/reference/object_literal_type_errors.md +110 -0
  63. package/skills/arkts-error-fixes/reference/object_spread_errors.md +105 -0
  64. package/skills/arkts-error-fixes/reference/possibly_null_errors.md +156 -0
  65. package/skills/arkts-error-fixes/reference/resource_conversion_errors.md +154 -0
  66. package/skills/arkts-error-fixes/reference/standalone_function_errors.md +68 -0
  67. package/skills/arkts-error-fixes/reference/storage_link_default_errors.md +124 -0
  68. package/skills/arkts-error-fixes/reference/title_button_rect_type_errors.md +167 -0
  69. package/skills/arkts-error-fixes/reference/unused_variable_warnings.md +295 -0
  70. package/skills/arkts-error-fixes/reference/utility_type_errors.md +290 -0
  71. package/skills/arkts-error-fixes/reference/window_rect_size_errors.md +70 -0
  72. package/skills/arkts-error-fixes/reference/window_type_errors.md +95 -0
  73. package/skills/arkts-grammar-standards/SKILL.md +71 -0
  74. package/skills/arkts-grammar-standards/references/basic-syntax.md +103 -0
  75. package/skills/arkts-grammar-standards/references/restrictions.md +100 -0
  76. package/skills/arkts-grammar-standards/references/topic-aliases.json +93 -0
  77. package/skills/arkts-grammar-standards/references/ts-diff.md +108 -0
  78. package/skills/arkts-runtime-fix/SKILL.md +152 -0
  79. package/skills/arkts-runtime-fix/SKILL_CN.md +123 -0
  80. package/skills/arkts-runtime-fix/evals/evals.json +17 -0
  81. package/skills/arkts-runtime-fix/scripts/collect-hilog.mjs +116 -0
  82. package/skills/arkts-runtime-fix/scripts/collect-hilog.ts +115 -0
  83. package/skills/arkts-runtime-fix/scripts/fetch-faultlog.mjs +117 -0
  84. package/skills/arkts-runtime-fix/scripts/fetch-faultlog.ts +116 -0
  85. package/skills/arkts-runtime-fix/scripts/jscrash-report.mjs +149 -0
  86. package/skills/arkts-runtime-fix/scripts/parse-jscrash-log.mjs +126 -0
  87. package/skills/arkts-runtime-fix/scripts/parse-jscrash-log.ts +126 -0
  88. package/skills/arkts-runtime-fix/scripts/probe-faultlogger.mjs +160 -0
  89. package/skills/arkts-runtime-fix/scripts/probe-faultlogger.ts +160 -0
  90. package/skills/arkts-runtime-fix/scripts/shared/hdc.mjs +107 -0
  91. package/skills/arkts-runtime-fix/scripts/shared/hdc.ts +58 -0
  92. package/skills/arkts-runtime-fix/scripts/shared/jscrash-faultlogger.mjs +143 -0
  93. package/skills/arkts-runtime-fix/scripts/shared/jscrash-faultlogger.ts +148 -0
  94. package/skills/arkts-runtime-fix/scripts/shared/jscrash-parse.mjs +389 -0
  95. package/skills/arkts-runtime-fix/scripts/shared/jscrash-parse.ts +409 -0
  96. package/skills/arkts-runtime-fix/scripts/shared/utils.mjs +27 -0
  97. package/skills/arkts-runtime-fix/scripts/shared/utils.ts +27 -0
  98. package/skills/arkui-knowledge/SKILL.md +90 -0
  99. package/skills/arkui-knowledge/references/api-guardrails.md +60 -0
  100. package/skills/arkui-knowledge/references/common-mistakes.md +119 -0
  101. package/skills/arkui-knowledge/references/component-cookbook.md +135 -0
  102. package/skills/arkui-knowledge/references/ui-quality-checklist.md +36 -0
  103. package/skills/deveco-create-project/SKILL.md +144 -0
  104. package/skills/deveco-create-project/application/AppScope/app.json5 +10 -0
  105. package/skills/deveco-create-project/application/AppScope/resources/base/element/string.json +8 -0
  106. package/skills/deveco-create-project/application/AppScope/resources/base/media/background.png +0 -0
  107. package/skills/deveco-create-project/application/AppScope/resources/base/media/foreground.png +0 -0
  108. package/skills/deveco-create-project/application/AppScope/resources/base/media/layered_image.json +7 -0
  109. package/skills/deveco-create-project/application/build-profile.json5 +42 -0
  110. package/skills/deveco-create-project/application/code-linter.json5 +32 -0
  111. package/skills/deveco-create-project/application/entry/build-profile.json5 +33 -0
  112. package/skills/deveco-create-project/application/entry/hvigorfile.ts +7 -0
  113. package/skills/deveco-create-project/application/entry/obfuscation-rules.txt +23 -0
  114. package/skills/deveco-create-project/application/entry/oh-package.json5 +10 -0
  115. package/skills/deveco-create-project/application/entry/src/main/ets/entryability/EntryAbility.ets +63 -0
  116. package/skills/deveco-create-project/application/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +31 -0
  117. package/skills/deveco-create-project/application/entry/src/main/ets/pages/Index.ets +38 -0
  118. package/skills/deveco-create-project/application/entry/src/main/module.json5 +50 -0
  119. package/skills/deveco-create-project/application/entry/src/main/resources/base/element/color.json +8 -0
  120. package/skills/deveco-create-project/application/entry/src/main/resources/base/element/float.json +8 -0
  121. package/skills/deveco-create-project/application/entry/src/main/resources/base/element/string.json +16 -0
  122. package/skills/deveco-create-project/application/entry/src/main/resources/base/media/background.png +0 -0
  123. package/skills/deveco-create-project/application/entry/src/main/resources/base/media/foreground.png +0 -0
  124. package/skills/deveco-create-project/application/entry/src/main/resources/base/media/layered_image.json +7 -0
  125. package/skills/deveco-create-project/application/entry/src/main/resources/base/media/startIcon.png +0 -0
  126. package/skills/deveco-create-project/application/entry/src/main/resources/base/profile/backup_config.json +3 -0
  127. package/skills/deveco-create-project/application/entry/src/main/resources/base/profile/main_pages.json +5 -0
  128. package/skills/deveco-create-project/application/entry/src/main/resources/dark/element/color.json +8 -0
  129. package/skills/deveco-create-project/application/hvigor/hvigor-config.json5 +23 -0
  130. package/skills/deveco-create-project/application/hvigorfile.ts +7 -0
  131. package/skills/deveco-create-project/application/oh-package.json5 +10 -0
  132. package/skills/deveco-create-project/scripts/copy-template.mjs +216 -0
  133. package/skills/deveco-create-project/scripts/copy-template.ts +214 -0
  134. package/skills/deveco-create-project/scripts/detect-sdk.mjs +82 -0
  135. package/skills/deveco-create-project/scripts/detect-sdk.ts +95 -0
@@ -0,0 +1,116 @@
1
+ /*
2
+ * Copyright (c) 2026 Huawei Device Co., Ltd.
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+
16
+ import fs from 'node:fs';
17
+ import path from 'node:path';
18
+ import process from 'node:process';
19
+ import { resolveHdcOrThrow, runHdc, targetArgs } from './shared/hdc';
20
+ import { printKv, toErrorMessage } from './shared/utils';
21
+
22
+ function parseArgs(argv: string[]) {
23
+ const map = new Map<string, string>();
24
+ const optionalKeys = new Set(['device-id']);
25
+
26
+ for (let i = 0; i < argv.length; i += 1) {
27
+ const t = argv[i];
28
+ if (!t.startsWith('--')) {
29
+ continue;
30
+ }
31
+ const key = t.slice(2);
32
+ const val = argv[i + 1];
33
+ if (!val || val.startsWith('--')) {
34
+ if (optionalKeys.has(key)) {
35
+ map.set(key, '');
36
+ continue;
37
+ }
38
+
39
+ throw new Error(`Missing value for --${key}`);
40
+ }
41
+ map.set(key, val);
42
+ i += 1;
43
+ }
44
+
45
+ const faultlogName = map.get('faultlog-name');
46
+ const outputDir = map.get('output-dir');
47
+ if (!faultlogName || !outputDir) {
48
+ throw new Error('Required: --faultlog-name and --output-dir');
49
+ }
50
+
51
+ return {
52
+ faultlogName,
53
+ outputDir,
54
+ deviceId: map.get('device-id') ?? '',
55
+ };
56
+ }
57
+
58
+ function normalizeRemoteName(name: string) {
59
+ return name.endsWith('.log') ? name : `${name}.log`;
60
+ }
61
+
62
+ function printFetchFailed(faultlogName: string, remotePath: string, nextAction: string) {
63
+ printKv({
64
+ status: 'fetch_failed',
65
+ faultlog_name: faultlogName,
66
+ remote_path: remotePath,
67
+ local_path: '',
68
+ next_action: nextAction,
69
+ });
70
+ }
71
+
72
+ async function recvFaultlog(hdc: string, deviceId: string, remotePath: string, localPath: string) {
73
+ const args = [hdc, ...targetArgs(deviceId), 'file', 'recv', remotePath, localPath];
74
+ const out = await runHdc(args);
75
+ if (out.exitCode !== 0) {
76
+ throw new Error(out.stderr || out.stdout || `hdc file recv failed (code=${out.exitCode})`);
77
+ }
78
+
79
+ if (!(await Bun.file(localPath).exists())) {
80
+ throw new Error('Local file missing after recv.');
81
+ }
82
+ }
83
+
84
+ function printFetched(faultlogName: string, remotePath: string, localPath: string) {
85
+ printKv({
86
+ status: 'fetched',
87
+ faultlog_name: faultlogName,
88
+ remote_path: remotePath,
89
+ local_path: localPath,
90
+ next_action: `parse-jscrash-log.ts --log-file "${localPath}"`,
91
+ });
92
+ }
93
+
94
+ async function main() {
95
+ let faultlogName = '';
96
+ let remotePath = '';
97
+
98
+ try {
99
+ const args = parseArgs(process.argv.slice(2));
100
+ const base = normalizeRemoteName(path.basename(args.faultlogName.trim()));
101
+ faultlogName = base;
102
+ remotePath = `/data/log/faultlog/faultlogger/${base}`;
103
+ const hdc = await resolveHdcOrThrow();
104
+
105
+ fs.mkdirSync(args.outputDir, { recursive: true });
106
+ const localPath = path.join(args.outputDir, base);
107
+ await recvFaultlog(hdc, args.deviceId, remotePath, localPath);
108
+ printFetched(base, remotePath, localPath);
109
+ process.exit(0);
110
+ } catch (err) {
111
+ printFetchFailed(faultlogName, remotePath, toErrorMessage(err));
112
+ process.exit(1);
113
+ }
114
+ }
115
+
116
+ await main();
@@ -0,0 +1,149 @@
1
+ /*
2
+ * Copyright (c) 2026 Huawei Device Co., Ltd.
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+
16
+ import fs from 'node:fs/promises';
17
+ import process from 'node:process';
18
+ import {
19
+ buildCrashReport,
20
+ buildNextActionText,
21
+ formatCrashReportText,
22
+ } from './shared/jscrash-parse.mjs';
23
+ import { resolveHdcOrThrow, runHdc, targetArgs } from './shared/hdc.mjs';
24
+ import { printKv, toErrorMessage } from './shared/utils.mjs';
25
+
26
+ function parseArgs(argv) {
27
+ const map = new Map();
28
+ const flags = new Set();
29
+ const optionalKeys = new Set(['log-text', 'log-file', 'bundle-name', 'process-hint', 'device-id']);
30
+
31
+ for (let i = 0; i < argv.length; i += 1) {
32
+ const token = argv[i];
33
+ if (token === '--include-text') {
34
+ flags.add('include-text');
35
+ continue;
36
+ }
37
+ if (!token.startsWith('--')) {
38
+ continue;
39
+ }
40
+ const key = token.slice(2);
41
+ const value = argv[i + 1];
42
+ if (!value || value.startsWith('--')) {
43
+ if (optionalKeys.has(key)) {
44
+ map.set(key, '');
45
+ continue;
46
+ }
47
+ throw new Error(`Missing value for --${key}`);
48
+ }
49
+ map.set(key, value);
50
+ i += 1;
51
+ }
52
+
53
+ const logText = map.get('log-text');
54
+ const logFile = map.get('log-file');
55
+ if (logText && logFile) {
56
+ throw new Error('Provide at most one of --log-text or --log-file');
57
+ }
58
+
59
+ const lines = Number(map.get('lines') ?? '4000');
60
+ if (!Number.isInteger(lines) || lines < 200 || lines > 10000) {
61
+ throw new Error('--lines must be an integer between 200 and 10000');
62
+ }
63
+
64
+ return {
65
+ logText,
66
+ logFile,
67
+ bundleName: map.get('bundle-name') ?? '',
68
+ processHint: map.get('process-hint') ?? '',
69
+ deviceId: map.get('device-id') ?? '',
70
+ lines,
71
+ includeText: flags.has('include-text'),
72
+ };
73
+ }
74
+
75
+ function cleanLines(input) {
76
+ return input
77
+ .split(/\r?\n/)
78
+ .map((line) => line.trimEnd())
79
+ .filter((line) => line.trim().length > 0);
80
+ }
81
+
82
+ async function collectHilogText(deviceId, lines) {
83
+ const hdc = await resolveHdcOrThrow();
84
+ const out = await runHdc([hdc, ...targetArgs(deviceId), 'shell', 'hilog', '-x']);
85
+ if (out.exitCode !== 0) {
86
+ throw new Error(out.stderr || out.stdout || `hdc hilog -x failed (code=${out.exitCode})`);
87
+ }
88
+
89
+ const all = cleanLines(out.stdout);
90
+ return all.slice(Math.max(0, all.length - lines)).join('\n');
91
+ }
92
+
93
+ async function loadInput(args) {
94
+ if (args.logText) {
95
+ return { text: args.logText, source: 'text' };
96
+ }
97
+ if (args.logFile) {
98
+ return { text: await fs.readFile(args.logFile, 'utf8'), source: 'file' };
99
+ }
100
+ return { text: await collectHilogText(args.deviceId, args.lines), source: 'device_hilog' };
101
+ }
102
+
103
+ function printReport(report, source, includeText) {
104
+ printKv({
105
+ status: report.status === 'detected' ? 'detected' : 'no_crash_signature',
106
+ source,
107
+ error_type: report.errorType,
108
+ error_message: report.errorMessage,
109
+ suspected_file: report.suspectedFile,
110
+ top_stack: report.topStack.join('|'),
111
+ keywords: report.keywords.join(','),
112
+ next_action: buildNextActionText(report),
113
+ });
114
+
115
+ if (includeText) {
116
+ console.log('');
117
+ console.log(formatCrashReportText(report));
118
+ }
119
+ }
120
+
121
+ async function main() {
122
+ try {
123
+ const args = parseArgs(process.argv.slice(2));
124
+ const input = await loadInput(args);
125
+ const report = buildCrashReport(
126
+ input.text,
127
+ input.source,
128
+ args.deviceId || 'default',
129
+ args.bundleName,
130
+ args.processHint,
131
+ );
132
+ printReport(report, input.source, args.includeText);
133
+ process.exit(0);
134
+ } catch (err) {
135
+ printKv({
136
+ status: 'parse_failed',
137
+ source: 'text',
138
+ error_type: '',
139
+ error_message: '',
140
+ suspected_file: '',
141
+ top_stack: '',
142
+ keywords: '',
143
+ next_action: toErrorMessage(err),
144
+ });
145
+ process.exit(1);
146
+ }
147
+ }
148
+
149
+ await main();
@@ -0,0 +1,126 @@
1
+ /*
2
+ * Copyright (c) 2026 Huawei Device Co., Ltd.
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+
16
+ import process from 'node:process';
17
+ import fs from 'node:fs/promises';
18
+ import {
19
+ buildCrashReport,
20
+ buildNextActionText,
21
+ formatCrashReportText,
22
+ } from './shared/jscrash-parse.mjs';
23
+ import { printKv, toErrorMessage } from './shared/utils.mjs';
24
+
25
+ function parseArgs(argv) {
26
+ const map = new Map();
27
+ const flags = new Set();
28
+ const optionalKeys = new Set(['bundle-name', 'process-hint', 'device', 'source']);
29
+
30
+ for (let i = 0; i < argv.length; i += 1) {
31
+ const t = argv[i];
32
+ if (t === '--include-text') {
33
+ flags.add('include-text');
34
+ continue;
35
+ }
36
+ if (!t.startsWith('--')) {
37
+ continue;
38
+ }
39
+ const key = t.slice(2);
40
+ const val = argv[i + 1];
41
+ if (!val || val.startsWith('--')) {
42
+ if (optionalKeys.has(key)) {
43
+ map.set(key, '');
44
+ continue;
45
+ }
46
+
47
+ throw new Error(`Missing value for --${key}`);
48
+ }
49
+ map.set(key, val);
50
+ i += 1;
51
+ }
52
+
53
+ const logFile = map.get('log-file');
54
+ const logText = map.get('log-text');
55
+ if ((logFile && logText) || (!logFile && !logText)) {
56
+ throw new Error('Provide exactly one of --log-file or --log-text');
57
+ }
58
+
59
+ return {
60
+ logFile,
61
+ logText,
62
+ bundleName: map.get('bundle-name') ?? '',
63
+ processHint: map.get('process-hint') ?? '',
64
+ source: map.get('source') ?? (logFile ? 'file' : 'text'),
65
+ device: map.get('device') ?? 'default',
66
+ includeText: flags.has('include-text'),
67
+ };
68
+ }
69
+
70
+ async function readLogText(logFile) {
71
+ try {
72
+ return await fs.readFile(logFile, 'utf8');
73
+ } catch {
74
+ throw new Error(`log file not found: ${logFile}`);
75
+ }
76
+ }
77
+
78
+ async function main() {
79
+ try {
80
+ const args = parseArgs(process.argv.slice(2));
81
+ let raw = '';
82
+ if (args.logFile) {
83
+ raw = await readLogText(args.logFile);
84
+ } else if (args.logText) {
85
+ raw = args.logText;
86
+ }
87
+
88
+ const report = buildCrashReport(raw, args.source, args.device, args.bundleName, args.processHint);
89
+ const nextAction = buildNextActionText(report);
90
+
91
+ const topStackJoined = report.topStack.join('|');
92
+ const keywordsJoined = report.keywords.join(',');
93
+
94
+ printKv({
95
+ status: report.status === 'detected' ? 'detected' : 'no_crash_signature',
96
+ source: args.source,
97
+ error_type: report.errorType,
98
+ error_message: report.errorMessage,
99
+ suspected_file: report.suspectedFile,
100
+ top_stack: topStackJoined,
101
+ keywords: keywordsJoined,
102
+ next_action: nextAction,
103
+ });
104
+
105
+ if (args.includeText) {
106
+ console.log('');
107
+ console.log(formatCrashReportText(report));
108
+ }
109
+
110
+ process.exit(0);
111
+ } catch (err) {
112
+ printKv({
113
+ status: 'parse_failed',
114
+ source: 'text',
115
+ error_type: '',
116
+ error_message: '',
117
+ suspected_file: '',
118
+ top_stack: '',
119
+ keywords: '',
120
+ next_action: toErrorMessage(err),
121
+ });
122
+ process.exit(1);
123
+ }
124
+ }
125
+
126
+ await main();
@@ -0,0 +1,126 @@
1
+ /*
2
+ * Copyright (c) 2026 Huawei Device Co., Ltd.
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+
16
+ import process from 'node:process';
17
+ import {
18
+ buildCrashReport,
19
+ buildNextActionText,
20
+ formatCrashReportText,
21
+ } from './shared/jscrash-parse';
22
+ import { printKv, toErrorMessage } from './shared/utils';
23
+
24
+ function parseArgs(argv: string[]) {
25
+ const map = new Map<string, string>();
26
+ const flags = new Set<string>();
27
+ const optionalKeys = new Set(['bundle-name', 'process-hint', 'device', 'source']);
28
+
29
+ for (let i = 0; i < argv.length; i += 1) {
30
+ const t = argv[i];
31
+ if (t === '--include-text') {
32
+ flags.add('include-text');
33
+ continue;
34
+ }
35
+ if (!t.startsWith('--')) {
36
+ continue;
37
+ }
38
+ const key = t.slice(2);
39
+ const val = argv[i + 1];
40
+ if (!val || val.startsWith('--')) {
41
+ if (optionalKeys.has(key)) {
42
+ map.set(key, '');
43
+ continue;
44
+ }
45
+
46
+ throw new Error(`Missing value for --${key}`);
47
+ }
48
+ map.set(key, val);
49
+ i += 1;
50
+ }
51
+
52
+ const logFile = map.get('log-file');
53
+ const logText = map.get('log-text');
54
+ if ((logFile && logText) || (!logFile && !logText)) {
55
+ throw new Error('Provide exactly one of --log-file or --log-text');
56
+ }
57
+
58
+ return {
59
+ logFile,
60
+ logText,
61
+ bundleName: map.get('bundle-name') ?? '',
62
+ processHint: map.get('process-hint') ?? '',
63
+ source: map.get('source') ?? (logFile ? 'file' : 'text'),
64
+ device: map.get('device') ?? 'default',
65
+ includeText: flags.has('include-text'),
66
+ };
67
+ }
68
+
69
+ async function readLogText(logFile: string) {
70
+ const file = Bun.file(logFile);
71
+ if (!(await file.exists())) {
72
+ throw new Error(`log file not found: ${logFile}`);
73
+ }
74
+
75
+ return file.text();
76
+ }
77
+
78
+ async function main() {
79
+ try {
80
+ const args = parseArgs(process.argv.slice(2));
81
+ let raw = '';
82
+ if (args.logFile) {
83
+ raw = await readLogText(args.logFile);
84
+ } else if (args.logText) {
85
+ raw = args.logText;
86
+ }
87
+
88
+ const report = buildCrashReport(raw, args.source, args.device, args.bundleName, args.processHint);
89
+ const nextAction = buildNextActionText(report);
90
+
91
+ const topStackJoined = report.topStack.join('|');
92
+ const keywordsJoined = report.keywords.join(',');
93
+
94
+ printKv({
95
+ status: report.status === 'detected' ? 'detected' : 'no_crash_signature',
96
+ source: args.source,
97
+ error_type: report.errorType,
98
+ error_message: report.errorMessage,
99
+ suspected_file: report.suspectedFile,
100
+ top_stack: topStackJoined,
101
+ keywords: keywordsJoined,
102
+ next_action: nextAction,
103
+ });
104
+
105
+ if (args.includeText) {
106
+ console.log('');
107
+ console.log(formatCrashReportText(report));
108
+ }
109
+
110
+ process.exit(0);
111
+ } catch (err) {
112
+ printKv({
113
+ status: 'parse_failed',
114
+ source: 'text',
115
+ error_type: '',
116
+ error_message: '',
117
+ suspected_file: '',
118
+ top_stack: '',
119
+ keywords: '',
120
+ next_action: toErrorMessage(err),
121
+ });
122
+ process.exit(1);
123
+ }
124
+ }
125
+
126
+ await main();
@@ -0,0 +1,160 @@
1
+ /*
2
+ * Copyright (c) 2026 Huawei Device Co., Ltd.
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+
16
+ import process from 'node:process';
17
+ import {
18
+ extractJscrashFaultlogNames,
19
+ filterFaultlogsByBundle,
20
+ parseFaultlogEntry,
21
+ selectWithinMaxAge,
22
+ sortFaultlogsByRecency,
23
+ } from './shared/jscrash-faultlogger.mjs';
24
+ import { resolveHdcOrThrow, runHdc, targetArgs } from './shared/hdc.mjs';
25
+ import { printKv, toErrorMessage } from './shared/utils.mjs';
26
+
27
+ function parseArgs(argv) {
28
+ const map = new Map();
29
+ const optionalKeys = new Set(['bundle-name', 'device-id']);
30
+
31
+ for (let i = 0; i < argv.length; i += 1) {
32
+ const t = argv[i];
33
+ if (!t.startsWith('--')) {
34
+ continue;
35
+ }
36
+ const key = t.slice(2);
37
+ const val = argv[i + 1];
38
+ if (!val || val.startsWith('--')) {
39
+ if (optionalKeys.has(key)) {
40
+ map.set(key, '');
41
+ continue;
42
+ }
43
+
44
+ throw new Error(`Missing value for --${key}`);
45
+ }
46
+ map.set(key, val);
47
+ i += 1;
48
+ }
49
+
50
+ return {
51
+ bundleName: map.get('bundle-name') ?? '',
52
+ deviceId: map.get('device-id') ?? '',
53
+ maxAgeMinutes: Number(map.get('max-age-minutes') ?? '30'),
54
+ limit: Number(map.get('limit') ?? '10'),
55
+ };
56
+ }
57
+
58
+ async function readFaultloggerViaHidumper(hdc, deviceId) {
59
+ const args = [
60
+ hdc,
61
+ ...targetArgs(deviceId),
62
+ 'shell',
63
+ 'hidumper',
64
+ '-s',
65
+ '1201',
66
+ '-a',
67
+ '-p Faultlogger LogSuffixWithMs',
68
+ ];
69
+
70
+ return runHdc(args);
71
+ }
72
+
73
+ async function readFaultloggerViaLs(hdc, deviceId) {
74
+ const remote = '/data/log/faultlog/faultlogger';
75
+ const args = [hdc, ...targetArgs(deviceId), 'shell', 'ls', '-1', remote];
76
+
77
+ return runHdc(args);
78
+ }
79
+
80
+ function formatCandidates(names, limit) {
81
+ return names.slice(0, limit).join('|');
82
+ }
83
+
84
+ function printProbeFailed(bundleName, nextAction) {
85
+ printKv({
86
+ status: 'probe_failed',
87
+ bundle_name: bundleName,
88
+ latest_faultlog: '',
89
+ latest_timestamp: '',
90
+ matched_count: '0',
91
+ candidates: '',
92
+ next_action: nextAction,
93
+ });
94
+ }
95
+
96
+ function printProbeNotFound(bundleName) {
97
+ printKv({
98
+ status: 'not_found',
99
+ bundle_name: bundleName,
100
+ latest_faultlog: '',
101
+ latest_timestamp: '',
102
+ matched_count: '0',
103
+ candidates: '',
104
+ next_action: 'No recent matching faultlog was found. You may collect hilog if you still need more runtime evidence, or reproduce and retry.',
105
+ });
106
+ }
107
+
108
+ function printProbeFound(bundleName, names, limit) {
109
+ const latest = names[0];
110
+ const ts = parseFaultlogEntry(latest).timestampMs;
111
+ printKv({
112
+ status: 'found',
113
+ bundle_name: bundleName,
114
+ latest_faultlog: latest,
115
+ latest_timestamp: ts === null ? '' : String(ts),
116
+ matched_count: String(names.length),
117
+ candidates: formatCandidates(names, limit),
118
+ next_action: `A recent faultlog is available. Fetch it with fetch-faultlog.mjs --faultlog-name "${latest}" if you want a cleaner crash anchor.`,
119
+ });
120
+ }
121
+
122
+ async function loadCandidateNames(hdc, deviceId, bundleName, maxAgeMinutes) {
123
+ const hidumper = await readFaultloggerViaHidumper(hdc, deviceId);
124
+ let combined = hidumper.exitCode === 0 ? hidumper.stdout : '';
125
+
126
+ const ls = await readFaultloggerViaLs(hdc, deviceId);
127
+ if (ls.exitCode === 0) {
128
+ combined = `${combined}\n${ls.stdout}`;
129
+ }
130
+
131
+ let names = extractJscrashFaultlogNames(combined);
132
+ names = filterFaultlogsByBundle(names, bundleName);
133
+ names = selectWithinMaxAge(names, maxAgeMinutes, Date.now());
134
+ return sortFaultlogsByRecency(names);
135
+ }
136
+
137
+ async function main() {
138
+ let bundleName = '';
139
+
140
+ try {
141
+ const args = parseArgs(process.argv.slice(2));
142
+ bundleName = args.bundleName;
143
+ const hdc = await resolveHdcOrThrow();
144
+ const names = await loadCandidateNames(hdc, args.deviceId, args.bundleName, args.maxAgeMinutes);
145
+
146
+ if (!names.length) {
147
+ printProbeNotFound(args.bundleName);
148
+ process.exit(0);
149
+ return;
150
+ }
151
+
152
+ printProbeFound(args.bundleName, names, args.limit);
153
+ process.exit(0);
154
+ } catch (err) {
155
+ printProbeFailed(bundleName, toErrorMessage(err));
156
+ process.exit(1);
157
+ }
158
+ }
159
+
160
+ await main();