# 追加のCode Contextを追加する

Code Contextは、チーム独自のコーディング慣行や例外をAikidoが理解するのに役立ちます。コードベースに関するコンテキストを提供することで、Code Qualityによるプルリクエストの分析方法を微調整でき、ノイズを減らし、チームの基準に沿った、より的確なレビューを実現できます。

同じガイダンスをリポジトリ内に置くこともできます。すべてのレビューに適用したい場合は、ルートに`AGENTS.md`をコミットしてください。[リポジトリファイルでエージェントをガイドする](https://help.aikido.dev/docs/docs-ja/ai-and-dev-tools/guide-an-audit-with-repository-files)を参照してください。

### Code Contextとは？

Code Contextを使うと、チーム固有のコーディング規約、アーキテクチャ上の決定、一般的なベストプラクティスに対する許容される例外をAikidoに教えることができます。これにより、Code Qualityのコメントが汎用的なものではなく、的確で実行可能なものになります。

Code Contextは、チームの「暗黙知」、つまりチームメンバー全員が知っているものの従来のリンティングルールでは捉えられない、明文化されていないルールや例外を文書化する手段と考えてください。

### Code Contextの一般的な例

#### パフォーマンスとアーキテクチャに関する決定

{% code overflow="wrap" %}
```
Our data-export-service repository is our nightly batch processor for archived data. We intentionally avoid database indexes here because the tables are append-only and indexes would slow down our bulk insert operations.
```
{% endcode %}

#### ツール固有の例外

{% code overflow="wrap" %}
```
Debug logging and console.log statements are acceptable in our troubleshooting-utils repository as these are CLI tools designed for debugging production issues.
```
{% endcode %}

#### 社内ツール向けの緩和された基準

{% code overflow="wrap" %}
```
For data migration scripts in the migrations/ folder, we exceed line count limits multiple times. This is acceptable as these are one-time scripts. We also don't enforce strict error handling in internal-facing scripts because our team knows how to use them.
```
{% endcode %}

#### インポートの規約

{% code overflow="wrap" %}
```
Wildcard imports (import * as) are acceptable when importing from our @company/ui-components library as we intentionally export all components as a single namespace.
```
{% endcode %}

#### ドキュメントの要件

{% code overflow="wrap" %}
```
Relaxed JSDoc requirements apply to internal helper functions in the utils/ folder. Full documentation is only required for exported public APIs.
```
{% endcode %}

#### パフォーマンスの最適化

{% code overflow="wrap" %}
```
Performance-critical functions in our real-time-processing module can skip certain TypeScript strict checks when properly commented with @performance-critical.
```
{% endcode %}

### 追加のCode Contextを追加する方法

**ステップ1.** [Code Quality Checks](https://app.aikido.dev/code-quality/checks)ページに移動し、Code Contextをクリックします

<figure><img src="https://help.aikido.dev/_assets/7e1b25ee33e7/image-57.png" alt=""><figcaption></figcaption></figure>

**ステップ2.** **Add Code Context**をクリックして、新しいコードコンテキストを追加します。

**ステップ3.** Code Contextを定義します

* チームの慣行や例外を説明する明確な説明を記述します
* スコープを選択します：
  * **All repositories** - 組織全体に適用されます
  * **Selected repositories** - 特定のリポジトリにのみ適用されます

<figure><img src="https://help.aikido.dev/_assets/1802a4dbd1c4/image-58.png" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
**効果的なコンテキストを書くためのヒント**

**推奨：**

* 例外がいつ、なぜ適用されるのかを具体的に記述する
* 特定のフォルダ、ファイルパターン、またはリポジトリを参照する
* アーキテクチャ上の決定の背景にある理由を説明する
* 明確で簡潔な言葉を使う

**非推奨：**

* 品質チェックの目的を損なうような、広すぎる例外を作成する
* チェックのオン／オフ切り替えですでに対応できる内容を重複して記述する
* スコープが明確でない曖昧な記述をする
{% endhint %}

### Code ContextとCustom Code Rulesの比較

どちらの機能をいつ使うべきかを理解するための簡単なガイドラインを以下に示します

#### Code Contextを使用する場合：

* 特定の領域でベストプラクティスに対する**許容される例外**がある場合
* 特定の状況に合わせて**既存のルールを調整**する必要がある場合
* アーキテクチャ上の決定について**説明を提供**したい場合

#### Custom Code Rulesを使用する場合：

* デフォルトのチェックでカバーされていない**新しい基準を適用**する必要がある場合
* コードベース固有の**特定のパターンを検出**したい場合
* 一貫した検出による**厳格な適用**が必要な場合
* 特定の違反に対して**PRをブロック**したい場合

## フィードバックを使ってCode Contextを生成する

プルリクエストから直接、追加のコードコンテキストを追加できます。フィードバックや説明を添えて@AikidoSec宛てにコメントを投稿するだけで、Aikidoが自動的にそれを処理し、今後のレビューのインサイトを改善します。
