hmos-runtime-fix-skill
Load for ArkTS/JavaScript jscrash, runtime crash, uncaught exception, stack trace, faultlog, or hilog diagnosis. Also load when the app 闪退/崩溃/白屏, exits after 点击/启动/launch, or build succeeds but runtime fails (no compile error). Use before broad Read/Glob on crash-only tasks.
- License 许可
- GPL-3.0
- 最近更新
- 2026-10-08
- Stars
- ★ 3
- Forks
- 0
01 前言 Front Matter
- name
- hmos-runtime-fix-skill
- description
- Load for ArkTS/JavaScript jscrash, runtime crash, uncaught exception, stack trace, faultlog, or hilog diagnosis. Also load when the app 闪退/崩溃/白屏, exits after 点击/启动/launch, or build succeeds but runtime fails (no compile error). Use before broad Read/Glob on crash-only tasks.
02 资源文件 15
- 参考文档reference/businesserror_patterns.md1.4 KB
- 参考文档reference/error_patterns.md3.4 KB
- 参考文档reference/fault-mode-library.md4.1 KB
- 参考文档reference/outofmemoryerror_patterns.md1.3 KB
- 参考文档reference/rangeerror_patterns.md712 B
- 参考文档reference/referenceerror_patterns.md1.3 KB
- 参考文档reference/syntaxerror_patterns.md693 B
- 参考文档reference/typeerror_patterns.md1.6 KB
- 参考文档reference/urierror_patterns.md756 B
- 脚本scripts/collect-hilog.mjs3.2 KB
- 脚本scripts/jscrash-report.mjs3.8 KB
- 脚本scripts/parse-jscrash-log.mjs3.4 KB
- 脚本scripts/shared/deveco-cli.mjs2.4 KB
- 脚本scripts/shared/jscrash-parse.mjs10.0 KB
- 脚本scripts/shared/utils.mjs890 B
03 SKILL.md 正文
Harmony JSCrash Fixes
Use this skill to diagnose and fix ArkTS or JavaScript runtime crashes with minimal edits.
Use devecocli for device discovery and log acquisition. Use this skill's private Node scripts under skills/arkts-runtime-fix/scripts/ only to parse evidence or save a hilog snapshot.
If node is unavailable, stop and explain that the private scripts cannot run.
When To Load
Load this skill when the issue looks like one of these:
- Runtime logs show
TypeError,ReferenceError,RangeError,SyntaxError,BusinessError, or similar exceptions. - The app exits, flashes back, or white-screens during launch or after a tap.
- The user provides a
jscrashlog, stack trace, or a temporary log file with@file. - Build succeeds, but runtime behavior fails immediately.
Core Approach
Prefer a concrete crash anchor before broad code exploration. A good anchor can come from:
- a provided crash log
- a stack trace
- a clear page or module named by the user
- a recent device-side faultlog or hilog when no better evidence is available
Avoid broad Read / Glob / Explore across the whole project until you have at least one concrete anchor such as:
error_typeerror_messagesuspected_filetop_stack- or a clearly named crash entry point from the user
Do not over-collect logs. If the user already gave enough crash evidence, parse that evidence first and move into focused reading and minimal fixes.
CLI And Script Contract
Run devecocli through Shell. Do not call hdc, read DEVECO_HOME, or use DevEco Code-specific device/log tools directly.
Private Node scripts
Run the private scripts through Shell like this:
node "{SKILL_DIR}/scripts/<script>.mjs" ...
{SKILL_DIR} is the absolute path of this skill directory at runtime.
Scripts print stable key: value text to stdout. A non-zero exit code means the current step could not continue and the agent should report the reason instead of guessing.
Preferred Flows
Case A: The user already provided raw crash text
node "{SKILL_DIR}/scripts/jscrash-report.mjs" --log-text "{crashLog}" --bundle-name "{bundleName}" --include-text
Case B: The user provided @file or a local log path
node "{SKILL_DIR}/scripts/parse-jscrash-log.mjs" --log-file "{logFilePath}" --bundle-name "{bundleName}" --include-text
Case C: The user only described symptoms and did not provide logs
Log collection is optional here. Use it when you still need a concrete runtime anchor.
Before collecting device evidence:
- Read
AppScope/app.json5and take the exactapp.bundleNamevalue (for examplecom.example.hmos.sample). Use that string as{bundleName}in every script below. - Do not guess
bundleNamefromvendor, module folder names, or prefixes such ascom.example. - Resolve the target device:
- If the user provided a
deviceId, use it for every device-side command. - If no
deviceIdis provided, rundevecocli device listfirst. - If exactly one device is connected, use that device.
- If multiple devices are connected, ask the user which device to inspect. Do not collect logs until the user selects a device.
- If no devices are connected, report that device-side evidence cannot be collected and ask for a connected device or a local crash log.
- If the user provided a
After the user reproduces the crash on the selected device, fetch and parse the latest matching crash log:
node "{SKILL_DIR}/scripts/jscrash-report.mjs" --bundle-name "{bundleName}" --device-id "{deviceId}" --include-text
With no --log-text or --log-file, jscrash-report.mjs runs devecocli log --crash --device ... --bundle-name ... and parses its output. If no matching crash is returned, ask the user to reproduce and retry immediately; do not guess from symptoms alone.
If the crash log is unavailable or insufficient, fall back to hilog. The collector runs devecocli log --device ... --tail ... and only handles the local snapshot file itself:
node "{SKILL_DIR}/scripts/collect-hilog.mjs" --device-id "{deviceId}" --lines "4000" --output-dir "{tempDir}"
node "{SKILL_DIR}/scripts/parse-jscrash-log.mjs" --log-file "{hilogPathFromCollect}" --bundle-name "{bundleName}" --source hilog --include-text
Output Contract
The leading key: value block from jscrash-report.mjs and parse-jscrash-log.mjs includes:
status:detected|no_crash_signature|parse_failedsource:file|text|hilogand similar sourceserror_typeerror_messagesuspected_filetop_stack:|-joined frameskeywords: comma-separatednext_action
--include-text appends a human-readable summary after the structured block.
If status: no_crash_signature, explain that the evidence is weak and ask for a better log, clearer repro, or an additional runtime clue before broad code reading.
JSCrash Fix Knowledge Base
Knowledge source (synced): hmos-jscrash-analysis.
After parsing crash evidence and obtaining error_type, match patterns from the knowledge base and apply the corresponding fix. Do not invent root causes or fixes outside these references.
Using the Fix Knowledge Base
- Parse crash evidence with scripts to obtain
error_type,error_message, andtop_stack. - Read reference/fault-mode-library.md first. Match
JSError→ secondary cause → tertiary cause usingReason/Error name/Error message. - Based on
error_type, read only the corresponding patterns file:ReferenceError→ reference/referenceerror_patterns.mdTypeError→ reference/typeerror_patterns.mdError→ reference/error_patterns.mdBusinessError→ reference/businesserror_patterns.mdSyntaxError→ reference/syntaxerror_patterns.mdRangeError→ reference/rangeerror_patterns.mdOutOfMemoryError→ reference/outofmemoryerror_patterns.mdURIError→ reference/urierror_patterns.md
- When multiple patterns match, prefer the one supported by
Error message+Error code+ top application stack frame simultaneously (see credibility rules in each reference file). - Apply a minimal fix to the suspected file from the stack. Do not refactor broadly.
Quick Reference
| Error type / message keyword | Root cause | Reference |
|---|---|---|
ReferenceError + @Provide / @Consume |
Missing or duplicate @Provide/@Consume | referenceerror_patterns.md |
ReferenceError + is not initialized |
Variable used before assignment | referenceerror_patterns.md |
ReferenceError + <name> is not defined |
Variable scope or import missing | fault-mode-library.md |
ReferenceError + super() before this |
super() not called before this | fault-mode-library.md |
TypeError + Cannot read property / null or undefined |
Accessing property on undefined/null | typeerror_patterns.md |
TypeError + is not callable |
Calling a non-function value | typeerror_patterns.md |
TypeError + circular structure |
Circular reference in JSON.stringify | typeerror_patterns.md |
TypeError + Receiver is not a JSObject / N-API scope |
N-API receiver type mismatch | typeerror_patterns.md |
SyntaxError + Unexpected Text in JSON / Invalid Token |
Malformed JSON.parse input | syntaxerror_patterns.md |
RangeError + Invalid array length |
Negative or non-integer array length | rangeerror_patterns.md |
RangeError + Stack overflow |
Unbounded recursion | rangeerror_patterns.md |
URIError + DecodeURI: invalid character |
Malformed URI in decodeURI | urierror_patterns.md |
Error + UI execution context not found / 100001 |
UI context not bound to router | error_patterns.md |
Error + WebviewController must be associated / 17100001 |
WebviewController not linked to Web component | error_patterns.md |
Error + ForEach id / id generator |
ForEach keyGenerator missing or invalid | error_patterns.md |
Error + ArrayBuffer is null or detached |
Using detached ArrayBuffer | fault-mode-library.md |
Error + Map's constructor cannot be directly invoked |
ArkTS Map constructor misuse | fault-mode-library.md |
| Error + SQLite / RDB / resource ID / window state | DB handle, resource ID, or window API misuse | error_patterns.md |
BusinessError + Parameter error / URL / JSON / XML |
Invalid API parameter type or value | businesserror_patterns.md |
| OutOfMemoryError + allocate / leak | Heap allocation failure or memory leak | outofmemoryerror_patterns.md |
TerminationError + Terminate execution! |
Forced termination by runtime | fault-mode-library.md |
AggregateError + Promise.any() all rejected |
All promises in Promise.any() rejected | fault-mode-library.md |
Interpretation Rules
- Prefer application frames over framework noise.
- Treat the first concrete
.ets,.ts, or.jspath as the starting point, not the final truth. - If the user gave repro steps, trust them over a simplistic stack-only guess.
- If the stack points to a non-entry page, assume an interaction-triggered path unless evidence proves a cold-start crash.
- Do not refactor broadly. Fix the crash path first.
Conversational Shape
- Say what evidence you already have.
- If logs are missing, say whether you are using a crash log or hilog to get a better anchor.
- Once you have an anchor, switch into focused code reading and minimal fixing.
Constraints
- Never claim a crash fix from prompt reasoning alone.
- Never replace a root-cause fix with retries, arbitrary delays, or broad defensive rewrites.
- If unfamiliar
@ohos.*or@kit.*APIs are involved, check their constraints before editing. - This skill does not decide the final compile / run / verification order; the primary agent owns that.
04 同仓库更多 Skills
writing-for-agents
为 agent 撰写文档。当创建或编辑 skill、修改 AGENTS.md 或 CLAUDE.md 时使用。
wait-what
停。上一条消息没讲明白:换个说法再讲一遍。
to-questionnaire
把你无法独自回答的决策转化成一份问卷,交给别人填写。
teach
在当前工作区内,教会用户一项新 skill 或概念。
handoff
把当前对话压缩成一份交接(handoff)文档,供另一个代理接手。
grilling
就一个计划、决策或想法对用户进行无情的访谈。当用户想压力测试自己的思路,或使用任何 'grill' 触发短语时使用。