This repository is the official repository of "HapRepair: Learn to Repair OpenHarmony Apps".
This is an automated ArkTS code defect repair system based on large language models. The system uses Retrieval-Augmented Generation (RAG) technology combined with multiple large language models to detect and fix performance defects in ArkTS code.
Here's the framework of the system:

The system consists of the following main modules:
fix.py, fix_projects.py)save_defects_to_database.py)get_prompt.py)output_handler.py)get_surrounding_context.py)The control flow graph is generated by ArkAnalyzer.
You can get the CFG of the projects by running the script arkanalyzer/tests/CFGTest.ts.
OPENAI_API_KEY=<your_key>
OPENAI_API_BASE=<api_base>
DEEPSEEK_API_KEY=<your_key>
DEEPSEEK_API_BASE=<api_base>
PINECONE_API_KEY=<your_key>
pip install -r requirements.txt
python RQ1.py
python fix.py
Besides, you can use CodeLinter in Huawei DevEco Studio to detect code defects.
And use ArkAnalyzer to obtain the CFG of the code to check the functionality of the code.
We evaluate HapRepair on a curated benchmark of real-world OpenHarmony apps:
revision/target_projects_haprepair.json.summary/gpt-5.1_rq2_rule_type_context_ratio.md).get_surrounding_context.py extracts the surrounding context for every finding, (3) save_defects_to_database.py indexes curated fix exemplars into a Pinecone vector store, (4) get_prompt.py retrieves the top-k nearest exemplars via RAG and assembles a repair prompt, and (5) fix.py / fix_projects.py drive an iterative multi-round repair loop with output_handler.py validating each patch.Reproduce the main table with:
python3 revision/code/delta_check_summarize.py --allow-missing-final-logs
Main result across LLMs. All five models converge within five repair iterations. GPT-5.1 / GPT-5-mini / DeepSeek-Chat / Qwen3-Coder-Plus drop from 8,664 initial defects to 236 / 166 / 247 / 353 respectively (97–98% resolution); Qwen3-30B-A3B plateaus higher at 1,348 (84%), underscoring that model capacity still matters for hard, context-heavy rules.

Category-level resolution (gpt-5.1). Performance rules drop from 8,150 → 234 (97%) and security rules from 514 → 2 (100%) after five iterations.

Per-project progression (sampled). HapRepair wipes out all 36 defects in PullLinking on round 1, takes flutter_embedding from 123 → 1, and drives the overall 35-project benchmark from 8,664 → 236 (97%).

Delta-check against "fix-by-deletion". A conservative audit filtering every resolved finding plausibly attributable to large-scale code deletion still leaves a net fix rate of 96.11% (8,327/8,664) — confirming the gains come from real repairs, not code removal (summary/gpt-5.1_delta_check.md).
Ablation study (gpt-5.1, round 1). RAG is the dominant factor; Top-3 retrieval is the sweet spot; surrounding context beats full-file; and providing a structural diff is essential.

Full breakdown: summary/ablation/ablation_summary_gpt-5.1_round1.md. The auto-generated per-project bars and top-10 rule charts (scripts/plot_readme_figures.py) provide an additional view of the same data.
Issues and Pull Requests are welcome to help improve the project.
This project is licensed under the MIT License - see the LICENSE file for details.
16 commits
Python
71.4%
TypeScript
18.0%
C++
5.4%
Cython
2.6%
JavaScript
1.2%
This repository is the official repository of "HapRepair: Learn to Repair OpenHarmony Apps".
This is an automated ArkTS code defect repair system based on large language models. The system uses Retrieval-Augmented Generation (RAG) technology combined with multiple large language models to detect and fix performance defects in ArkTS code.
Here's the framework of the system:

The system consists of the following main modules:
fix.py, fix_projects.py)save_defects_to_database.py)get_prompt.py)output_handler.py)get_surrounding_context.py)The control flow graph is generated by ArkAnalyzer.
You can get the CFG of the projects by running the script arkanalyzer/tests/CFGTest.ts.
OPENAI_API_KEY=<your_key>
OPENAI_API_BASE=<api_base>
DEEPSEEK_API_KEY=<your_key>
DEEPSEEK_API_BASE=<api_base>
PINECONE_API_KEY=<your_key>
pip install -r requirements.txt
python RQ1.py
python fix.py
Besides, you can use CodeLinter in Huawei DevEco Studio to detect code defects.
And use ArkAnalyzer to obtain the CFG of the code to check the functionality of the code.
We evaluate HapRepair on a curated benchmark of real-world OpenHarmony apps:
revision/target_projects_haprepair.json.summary/gpt-5.1_rq2_rule_type_context_ratio.md).get_surrounding_context.py extracts the surrounding context for every finding, (3) save_defects_to_database.py indexes curated fix exemplars into a Pinecone vector store, (4) get_prompt.py retrieves the top-k nearest exemplars via RAG and assembles a repair prompt, and (5) fix.py / fix_projects.py drive an iterative multi-round repair loop with output_handler.py validating each patch.Reproduce the main table with:
python3 revision/code/delta_check_summarize.py --allow-missing-final-logs
Main result across LLMs. All five models converge within five repair iterations. GPT-5.1 / GPT-5-mini / DeepSeek-Chat / Qwen3-Coder-Plus drop from 8,664 initial defects to 236 / 166 / 247 / 353 respectively (97–98% resolution); Qwen3-30B-A3B plateaus higher at 1,348 (84%), underscoring that model capacity still matters for hard, context-heavy rules.

Category-level resolution (gpt-5.1). Performance rules drop from 8,150 → 234 (97%) and security rules from 514 → 2 (100%) after five iterations.

Per-project progression (sampled). HapRepair wipes out all 36 defects in PullLinking on round 1, takes flutter_embedding from 123 → 1, and drives the overall 35-project benchmark from 8,664 → 236 (97%).

Delta-check against "fix-by-deletion". A conservative audit filtering every resolved finding plausibly attributable to large-scale code deletion still leaves a net fix rate of 96.11% (8,327/8,664) — confirming the gains come from real repairs, not code removal (summary/gpt-5.1_delta_check.md).
Ablation study (gpt-5.1, round 1). RAG is the dominant factor; Top-3 retrieval is the sweet spot; surrounding context beats full-file; and providing a structural diff is essential.

Full breakdown: summary/ablation/ablation_summary_gpt-5.1_round1.md. The auto-generated per-project bars and top-10 rule charts (scripts/plot_readme_figures.py) provide an additional view of the same data.
Issues and Pull Requests are welcome to help improve the project.
This project is licensed under the MIT License - see the LICENSE file for details.
16 commits
Python
71.4%
TypeScript
18.0%
C++
5.4%
Cython
2.6%
JavaScript
1.2%