Логотип Oh Precommit Codecheck

Oh Precommit Codecheck

Організація
openharmonyinsight
oh-precommit-codecheck

Run local code quality checks covering a subset of OpenHarmony gate CI (copyright, CodeArts C/C++) plus additional local checks (pylint/flake8, shellcheck/bashate, gn format). Use before committing to reduce gate failures. Triggers on: /oh-precommit-codecheck, "门禁检查", "门禁预检", "检查代码", "run codecheck", "check code quality", "lint my code", "代码检查", or after completing code implementation. WHEN to use: before git commit, before creating PR, after modifying C/C++/Python/Shell/GN files, when gate CI fails with codecheck defects, or when you want to preview what gate will flag.

Огляд

Видавецьopenharmonyinsight
Репозиторійopenharmony-skills
Назва навичкиoh-precommit-codecheck
Зірки
36
Форки
7
Файли в пакеті
6
Посилання
  • Інструкції у форматі Markdown

    Файл SKILL.md, який модель завантажує за потреби, тож токени витрачаються лише тоді, коли запит справді відповідає навичці.

  • Працює з будь-якою LLM

    Навички ШІ — це звичайний Markdown, а не код для певного постачальника, тому вони працюють із GPT, Claude, Gemini, Grok або локальною моделлю.

  • Файлів у комплекті: 6

    Скрипти, шаблони й довідкові матеріали, які модель може читати під час роботи. Файли доступні лише для читання й ніколи не виконуються.

  • Відкритий вихідний код

    Опубліковано на GitHub користувачем openharmonyinsight. Перегляньте вихідний вміст перед установленням.

Встановлення

Установіть навичку ШІ Oh Precommit Codecheck у TypingMind, щоб використовувати її з будь-якою LLM, або додайте її до іншого агента, що читає SKILL.md.

1

Встановити в TypingMind

TypingMind встановлює навичку безпосередньо з її папки GitHub — читає SKILL.md, збирає файли ресурсів у пакет і зберігає результат локально.

  1. Відкрийте застосунок і перейдіть до Плагіни → Навички.
  2. Виберіть «Встановити з GitHub».
  3. Вставте наведений нижче URL папки навички та підтвердьте встановлення.
    https://github.com/openharmonyinsight/openharmony-skills/tree/main/skills/oh-precommit-codecheck
  4. Увімкніть навичку в кожному чаті, де хочете її використовувати.
Плагіни → Навички → Нова навичка → За URL GitHub, потім вставте URL папки й натисніть «Продовжити».
2

Встановити в іншому агенті

Будь-який агент, що підтримує формат Agent Skills, може використовувати цю навичку — скопіюйте папку до каталогу навичок цього агента.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/openharmonyinsight/openharmony-skills.git /tmp/openharmony-skills
mkdir -p .claude/skills
cp -r /tmp/openharmony-skills/skills/oh-precommit-codecheck .claude/skills/oh-precommit-codecheck
Після копіювання перезапустіть Claude Code, щоб завантажити нову навичку.

Використовуйте навичку в TypingMind

Увімкніть навичку Oh Precommit Codecheck в будь-якому чаті TypingMind, і далі модель усе зробить сама. Назва й опис навички містяться в системному промпті, а щойно надходить відповідний запит, модель самостійно завантажує повні інструкції — вам не потрібно викликати навичку вручну, і до фактичного використання вона не витрачає токенів.

Модель самостійно завантажує навичку Oh Precommit Codecheck, щойно надходить відповідний запит.

Працює з будь-якою моделлю ШІ

Навички ШІ — це звичайні інструкції Markdown, а не код для певного постачальника, тому навичка Oh Precommit Codecheck не прив’язана до моделі, для якої її створено. Установіть її один раз у TypingMind і використовуйте з GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama або локальною моделлю, яку ви запускаєте самостійно, — усе з вашими власними ключами API.

  • Завантажується лише за потреби

    Системний промпт містить лише назву й опис. Інструкції завантажуються за першого відповідного запиту, тож невикористана навичка нічого не коштує.

  • Змінюйте моделі під час чату

    Оскільки навичка — це інструкції, а не код, зміна моделі не порушує її роботу: наступна модель читає той самий файл SKILL.md.

Інструкції навички

Це вміст файлу SKILL.md, який завантажує модель. Прочитайте його перед установленням — навичка містить інструкції, яких дотримуватиметься ваша модель.

OH Precommit Codecheck

Run local code quality checks. Includes gate CI checks and additional local-only checks.

Gate CI checks (same as OpenHarmony gate):

  • Copyright: Header presence, year correctness, comment style (/** for C/C++)
  • C/C++ format: clang-format (clang-format-14 preferred, fallback to clang-format)
  • C/C++ quality: CodeArts Check (codecheck-ide-engine + Huawei clang-tidy: clangtidy + secfinder + fixbot)

Additional local checks (NOT part of gate CI, for extra quality):

  • Python: pylint + flake8
  • Shell: shellcheck + bashate-mod-ds
  • GN: gn format --dry-run

Notes

  • First run downloads ~600MB of CodeArts tools to ~/.codecheck-tools/
  • Python/Shell linters must be pre-installed (pylint, flake8, shellcheck, bashate-mod-ds)
  • C/C++ checks without compile_commands.json may miss some context-dependent issues
  • GN format check requires gn in PATH

Current limitations

This skill covers a subset of the full OpenHarmony gate CI checks:

  • Languages: Only C/C++, Python, Shell, GN are checked. Java, JavaScript, TypeScript, ArkTS are NOT yet wired up (the CodeArts engine has rules for them locally).
  • C++ rules: ~114 of ~163 gate G.* rules are covered (~70%). Missing rules are mainly C-language variants without -CPP suffix.
  • Not covered at all: WordsTool sensitive-word checks (~200+ rules), OAT open-source compliance (~10 rules), security-specific checks (weak crypto, unsafe IPSI), code metrics (oversized functions/files/complexity, redundant/duplicate code).
  • Local pass does NOT guarantee gate pass — this is a best-effort pre-filter.

Quick Reference

InvocationModeBehavior
/oh-precommit-codecheck (standalone)Mode 1Check specified files, report results, ask before fixing
/oh-precommit-codecheck --fixMode 1Check and auto-fix up to 3 rounds
Auto-triggered by oh-pr-workflowMode 2Silent check + auto-fix, report only if defects remain
Pre-commit hookMode 2Same as auto-trigger

Determine trigger mode

Check whether $ARGUMENTS is set.

Mode 1: User-invoked ($ARGUMENTS present or /oh-precommit-codecheck called)

Parse $ARGUMENTS to determine file scope and fix mode:

/oh-precommit-codecheck              → files from: git diff --cached --name-only
/oh-precommit-codecheck <commit>     → files from: git diff-tree --no-commit-id -r <commit> --name-only
/oh-precommit-codecheck <file ...>   → the listed files directly
/oh-precommit-codecheck --fix        → same file resolution + auto-fix mode

Argument parsing rules:

  • --fix flag can appear anywhere in arguments
  • If an argument looks like a git commit (matches git rev-parse --verify <arg>), treat it as a commit
  • Otherwise treat arguments as file paths

Steps:

  1. Resolve the file list using the rules above. Filter to only existing files.
  2. Run checks by calling the check script:
    bash
    bash ~/.claude/skills/oh-precommit-codecheck/scripts/check.sh <file1> <file2> ...
  3. Present results to the user as a concise summary table.
  4. If defects were found and --fix was NOT specified:
    • Suggest: "Run /oh-precommit-codecheck --fix to auto-fix these issues."
  5. If --fix WAS specified and defects were found:
    • For copyright defects: Fix the copyright header directly (add missing header, update year, change comment style).
    • For C/C++ defects: Read each defective file, understand the rule violation, and fix it directly using the Edit tool.
    • For Python defects: Read each defective file, understand the rule violation, and fix it directly using the Edit tool.
    • For Shell defects: Read each defective file, understand the rule violation, and fix it directly using the Edit tool.
    • For GN format defects: Run gn format <file> to auto-format.
    • After fixing, re-run the check script to verify. Repeat up to 3 rounds.
    • Report any remaining unfixable defects.

Mode 2: AI auto-trigger (no $ARGUMENTS, after completing code changes)

When you have just finished writing or modifying code files, automatically check them.

Steps:

  1. Collect the list of files you just modified in this conversation (from your tool call history — look at Edit/Write calls).
  2. Run checks:
    bash
    bash ~/.claude/skills/oh-precommit-codecheck/scripts/check.sh <modified_files...>
  3. If 0 defects: silently pass — do not mention the check to the user unless they ask.
  4. If defects found: a. Auto-fix each defect:
    • For copyright: Add/update copyright header.
    • For C/C++ mechanical fixes (G.FMT.11-CPP braces, G.EXP.35-CPP nullptr, G.FMT.05-CPP line width): Fix directly.
    • For C/C++ judgment-required (G.NAM.03-CPP naming, G.FUN.01-CPP size): Do NOT auto-fix — report to user.
    • For Python / Shell: Fix standard rules directly, report ambiguous ones.
    • For GN format: Run gn format <file>. b. Re-run checks to verify fixes. c. Repeat up to 3 rounds total. d. If defects remain after 3 rounds, report the unfixable ones to the user.

Mode 2 and CLAUDE.md interaction: When triggered as pre-commit hook or by oh-pr-workflow, Mode 2 auto-fixes to streamline the commit flow. This overrides the CLAUDE.md "show report first" convention because the user has already expressed intent to commit. If invoked standalone (/oh-precommit-codecheck without commit context), default to report-only and ask before fixing.


Below: Reference sections — consult when fixing specific defect types. Skip to "Common Mistakes" if you just need guardrails.

Fix guidelines

When auto-fixing defects, match the rule to the fix below. If the rule is not listed, read the defect message and apply best judgment.

Copyright

  • no-copyright: Add the full Apache 2.0 copyright header (see CLAUDE.md for template)
  • wrong-year: Update the year range to include current year (e.g., 2025 → 2025-2026)
  • wrong-comment-style: For .cpp/.c/.h/.hpp files, change first line to /** (block comment style)

C/C++ (CodeArts)

  • G.FMT.11-CPP (braces): Add {} around single-line if/for/while/else bodies
  • G.NAM.03-CPP (naming): Fix variable/function names to match convention
  • G.EXP.35-CPP (nullptr): Replace NULL / 0 (pointer context) with nullptr
  • G.FUN.01-CPP (params): Cannot auto-fix — report to user
  • G.CNS.02-CPP (magic numbers): Extract to named constexpr constant

Python

  • C0304 (final newline): Add trailing newline
  • C0305 (trailing newline): Remove extra trailing blank lines
  • C0321 (multiple statements): Split into separate lines
  • C0410 (multiple imports): One import per line
  • C0411 (import order): Reorder to stdlib → third-party → local
  • Other pylint/flake8 rules: Read the message and fix accordingly

Shell

  • SC2086 (double-quote): Add double quotes around variable expansions
  • SC2164 (cd failure): Add || exit after cd commands
  • SC2148 (shebang): Add #!/usr/bin/env bash at top
  • Other shellcheck rules: Read the message and fix accordingly

GN

  • Run gn format <file> — fully automatic, no manual intervention needed

Common Mistakes — NEVER Do

  • NEVER run gn format on files that fail gn parse — it corrupts the file. Run gn parse first; if it fails, fix syntax manually before formatting.
  • NEVER auto-fix G.FUN.01-CPP (function too long) — requires architectural judgment. Always report to user.
  • NEVER auto-fix G.NAM.03-CPP naming without reading surrounding code — naming conventions depend on context (member variables, global variables, function params have different rules).
  • NEVER trust 0 defects from CodeArts if the engine log shows startup errors — check defects.json is non-empty AND engine exited normally.
  • NEVER assume local tool versions match gate CI — version mismatch causes false negatives. If results differ from gate, check: java -version, clang-tidy --version, pylint --version.
  • NEVER re-run the full check suite if only one checker failed — re-run only the failed checker to save time.

Error Recovery

  • CodeArts engine fails to start: Check java -version (requires 11+). Check download integrity: md5sum codecheck-ide-engine.jar. Re-run setup: bash scripts/setup_codecheck.sh --force.
  • compile_commands.json missing: C++ checks will have ~30% false negative rate. Generate with: gn gen out/default --export-compile-commands or proceed with reduced accuracy.
  • pylint/flake8 version mismatch: Gate uses specific versions. Check with pylint --version and compare with gate CI logs.

Example Output

Typical Mode 1 result:

Codecheck Results (12 defects):
| Rule | Count | File | Auto-fixable |
|------|-------|------|-------------|
| G.FMT.11-CPP | 5 | token_test.cpp | Yes |
| G.NAM.03-CPP | 3 | token_test.cpp | Yes (with context) |
| G.EXP.35-CPP | 2 | token_test.cpp | Yes |
| G.FUN.01-CPP | 1 | token_test.cpp | No — report to user |
| G.FMT.05-CPP | 1 | token_test.cpp | Yes |

发现 12 个告警,其中 11 个可自动修复。是否修复?

Файли в пакеті

Модель читає ці файли за потреби, поки навичку завантажено. Вони доступні для читання й ніколи не виконуються.

Поширені запитання

Що робить навичка ШІ Oh Precommit Codecheck?

Run local code quality checks covering a subset of OpenHarmony gate CI (copyright, CodeArts C/C++) plus additional local checks (pylint/flake8, shellcheck/bashate, gn format). Use before committing to reduce gate failures. Triggers on: /oh-precommit-codecheck, "门禁检查", "门禁预检", "检查代码", "run codecheck", "check code quality", "lint my code", "代码检查", or after completing code implementation. WHEN to use: before git commit, before creating PR, after modifying C/C++/Python/Shell/GN files, when gate CI fails with codecheck defects, or when you want to preview what gate will flag.

Навіщо використовувати Oh Precommit Codecheck у TypingMind?

Тому що ви встановлюєте її один раз і використовуєте з будь-якою моделлю. Oh Precommit Codecheck — це звичайний Markdown, а не код для конкретного постачальника, тому та сама навичка працює з GPT-5, Claude, Gemini, Grok або локальною моделлю. Ви можете змінити модель навіть посеред чату, і навичка продовжить працювати. TypingMind використовує ваші власні ключі API, тож ви платите безпосередньо постачальникам замість передплати за кожне місце користувача, а ваші навички й чати залишаються у вашому сховищі.

Як встановити Oh Precommit Codecheck у TypingMind?

Відкрийте в TypingMind Плагіни → Навички → Встановити з GitHub і вставте https://github.com/openharmonyinsight/openharmony-skills/tree/main/skills/oh-precommit-codecheck. TypingMind прочитає файл SKILL.md, додасть супровідні файли та встановить навичку, яку можна вмикати окремо для кожного чату.

Які моделі ШІ можуть використовувати Oh Precommit Codecheck?

Будь-яка модель, яку ви підключите в TypingMind. Навички ШІ — це звичайні інструкції у форматі Markdown, а не код для конкретного постачальника, тому GPT, Claude, Gemini, Grok і локальні моделі можуть завантажувати цю навичку, коли запит їй відповідає.

Зі скількома моделями ШІ можна використовувати Oh Precommit Codecheck?

Зі скількома забажаєте. Якщо модель підтримує навички, ви можете використовувати з нею Oh Precommit Codecheck — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama та інші — усе в TypingMind із власними ключами API.

Чи безкоштовна навичка ШІ Oh Precommit Codecheck?

Навичку опубліковано на GitHub: openharmonyinsight. Умови ліцензування дивіться в репозиторії. Ви платите лише своєму постачальнику ШІ за використані токени.

Що таке навички ШІ?

Навичка ШІ — це багаторазовий набір інструкцій, який навчає модель ШІ виконувати одне конкретне завдання. Він відповідає відкритому формату Agent Skills: файл SKILL.md із назвою та описом, а також скрипти, шаблони чи довідкові файли, які можуть знадобитися моделі. Модель читає інструкції лише тоді, коли ваш запит відповідає навичці, тому встановлена навичка нічого не коштує, доки її не використано.

Чим навички ШІ відрізняються від плагінів або серверів MCP?

Плагін або сервер MCP надає моделі нові інструменти для виклику — код, який десь виконується й повертає результат. Натомість навичка ШІ надає моделі знання та порядок дій: як підійти до завдання, яких кроків дотримуватися та яким має бути якісний результат. Навички — це звичайний Markdown, тож їм не потрібні ні сервер, ні ключ API, ні середовище виконання, і вони працюють із будь-якою моделлю.

Усі

Створіть власний ШІ-простір уже зараз

Підпишіться на нашу розсилку, щоб дізнаватися про нові функції та майбутні розіграші 👇