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でも利用可能

    AIスキルはプロバイダー固有のコードではなく、通常のMarkdownなので、GPT、Claude、Gemini、Grok、ローカルモデルで利用できます。

  • 6個の同梱ファイル

    モデルが作業中に読み取れるスクリプト、テンプレート、参考資料です。ファイルは読み取り専用で、実行されることはありません。

  • オープンソース

    openharmonyinsightがGitHubで公開しています。インストールする前にソースを確認してください。

インストール

AIスキルOh Precommit CodecheckをTypingMindにインストールすれば、どのLLMでも利用できます。SKILL.mdを読み取れる別のAIエージェントに追加することもできます。

1

TypingMindにインストール

TypingMindはGitHubフォルダから直接スキルをインストールします。SKILL.mdを読み取り、リソースファイルをまとめてローカルに保存します。

  1. アプリを開き、「プラグイン」→「スキル」に移動します。
  2. 「GitHubからインストール」を選択します。
  3. 以下のスキルフォルダのURLを貼り付けて確定します。
    https://github.com/openharmonyinsight/openharmony-skills/tree/main/skills/oh-precommit-codecheck
  4. スキルを利用したいチャットごとに、そのスキルを有効にしてください。
「プラグイン」→「スキル」→「スキルを追加」→「GitHubのURLから」を選択し、フォルダのURLを貼り付けて「続行」を押します。
2

別のAIエージェントにインストール

Agent Skills形式を読み取れるAIエージェントなら、このスキルを利用できます。フォルダをそのAIエージェントのスキルディレクトリにコピーしてください。

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で使用

TypingMindのチャットでOh Precommit Codecheckを有効にするだけで、あとはモデルが対応します。名前と説明がシステムプロンプトに含まれ、関連するリクエストがあると、モデルが指示の全文を自動で読み込みます。手動で呼び出す必要はなく、実際に使用されるまでトークンを消費しません。

関連するリクエストがあると、モデルが自動的にOh Precommit Codecheckを読み込みます。

どのAIモデルでも利用可能

AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、Oh Precommit Codecheckは作成時に想定されたモデルに縛られません。TypingMindに一度インストールすれば、ご自身のAPIキーを使って、GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama、またはご自身で実行するローカルモデルで利用できます。

  • 必要なときだけ読み込み

    システムプロンプトには名前と説明だけが含まれます。関連するリクエストが初めてあったときに指示を取得するため、未使用のスキルにはコストがかかりません。

  • チャットの途中でモデルを切り替え

    スキルはコードではなく指示なので、モデルを切り替えてもそのまま使えます。次のモデルも同じ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 个可自动修复。是否修复?

同梱ファイル

スキルが読み込まれている間、モデルは必要に応じてこれらを読み取ります。読み取り可能なファイルとして提供され、実行されることはありません。

よくある質問

AIスキル「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.

TypingMindでOh Precommit Codecheckを使うメリットは何ですか?

一度インストールすれば、どのモデルでも使えるからです。Oh Precommit Codecheckはプロバイダー固有のコードではなく、通常のMarkdownで記述されているため、同じスキルをGPT-5、Claude、Gemini、Grok、ローカルモデルで利用できます。チャットの途中でモデルを切り替えても、そのまま使い続けられます。TypingMindは自分のAPIキーで動作するため、シート単位のサブスクリプションではなく、プロバイダーに直接料金を支払います。スキルとチャットは自分のストレージに保持されます。

TypingMindにOh Precommit Codecheckをインストールするにはどうすればよいですか?

TypingMindで「プラグイン」→「スキル」→「GitHubからインストール」を開き、https://github.com/openharmonyinsight/openharmony-skills/tree/main/skills/oh-precommit-codecheckを貼り付けてください。TypingMindがSKILL.mdを読み込み、関連ファイルをまとめて、チャットごとに有効にできるスキルとしてインストールします。

Oh Precommit Codecheckを使えるAIモデルはどれですか?

TypingMindに接続したどのモデルでも利用できます。AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、GPT、Claude、Gemini、Grok、ローカルモデルのいずれも、リクエストが合致したときにこのスキルを読み込めます。

Oh Precommit Codecheckは何個のAIモデルで使えますか?

数に制限はありません。スキルに対応したモデルであれば、GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llamaなど、どのモデルでもOh Precommit Codecheckを利用できます。すべてTypingMind上で、自分のAPIキーを使って利用できます。

AIスキル「Oh Precommit Codecheck」は無料ですか?

openharmonyinsightがGitHubで公開しています。ライセンス条件はリポジトリでご確認ください。支払いが必要なのは、利用したトークンに対する、ご自身が契約するAIプロバイダーへの料金だけです。

AIスキルとは何ですか?

AIスキルは、特定のタスクの実行方法をAIモデルに教える、再利用可能な指示のセットです。オープンなAgent Skills形式に従い、名前と説明を含むSKILL.mdファイルに加え、モデルが必要とするスクリプト、テンプレート、参照ファイルで構成されます。モデルはリクエストがスキルに合致したときだけ指示を読み込むため、インストール済みのスキルも、使うまでは費用がかかりません。

AIスキルは、プラグインやMCPサーバーとどう違いますか?

プラグインやMCPサーバーは、モデルが呼び出せる新しいツールを提供します。ツールとは、どこかで実行され、結果を返すコードです。一方、AIスキルは、タスクへの取り組み方、従うべき手順、望ましい出力の例といった知識や進め方をモデルに伝えます。スキルは通常のMarkdownで記述されているため、サーバー、APIキー、実行環境は不要で、どのモデルでも利用できます。

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇