プロジェクトを検査して修正する
fastkit doctor は、生成済みのプロジェクトに、新しい fastkit のテンプレートでは修正済みの問題が残っていないかを検査します。たとえば、コミットされた .env、使われたままのサンプルのシークレット、CRLF の改行コードを持つシェルスクリプトなどです。安全に直せる問題は求めに応じて修正し、シークレットの値は決して表示しません。fastkit をアップグレードしても既存のプロジェクトは変わらないので、アップグレードしたあとは各プロジェクトで doctor を実行してください。
実行する
プロジェクトのフォルダーで fastkit doctor を実行するか、フォルダーを引数として渡します。チェックの結果が表で表示されます。作成したばかりのプロジェクトでは、すべてのチェックが合格するかスキップされます。
$ fastkit init --level layered --name shop --no-venv -y
...
$ cd shop
$ fastkit doctor
fastkit doctor
template fastapi-default, preset classic-layered, generated with fastkit 2.0.0
...
╭────────────── Success ───────────────╮
│ ✨ No problems found. │
╰──────────────────────────────────────╯
チェックは、対象外の場合にスキップされます。たとえば、fastapi-mcp 以外のプロジェクトでは MCP のチェックがスキップされます。すべてのチェックとその重大度は CLI リファレンスに一覧があります。
検出結果を読む
次のプロジェクトは git リポジトリに入れたもので、誤って .env がコミットされ(git add -f .env)、scripts/test.sh が CRLF の改行コードで保存されています。doctor は問題ごとに、関係するファイルと修正方法を報告し、続いてチェックの表とまとめを表示します。
$ fastkit doctor
fastkit doctor
template fastapi-default, preset classic-layered, generated with fastkit 2.0.0
HIGH (1) ───────────────────────────────────────────────────────────────────────
[env-tracked] .env is committed to git
- .env is in the git index and is pushed with every commit.
How to fix:
Run `git rm --cached <file>` for each file listed and commit; the file stays
...
MEDIUM (1) ─────────────────────────────────────────────────────────────────────
[crlf-scripts] Shell scripts or Dockerfiles have CRLF line endings
- scripts/test.sh has CRLF line endings.
How to fix:
Convert the files to LF (the fix does) and add .gitattributes so Git keeps
them that way. With CRLF, `bash` fails with `$'\r': command not found` and
containers with `env: 'bash\r': No such file or directory`.
Fixable with `fastkit doctor --fix`.
...
╭──────────────────────────────── Warning ─────────────────────────────────╮
│ ⚠️ 2 problem(s) found (1 high, 1 medium). 1 can be fixed automatically: │
│ run `fastkit doctor --fix` to review and apply the changes. │
╰──────────────────────────────────────────────────────────────────────────╯
安全に直せる問題を修正する
--fix は、行う予定の変更を一覧表示してから、一度だけ確認を求めます。--dry-run(または --diff)は変更を一覧表示するだけで、何も書き込みません。修正のあと、doctor はもう一度検査し、残っている問題を一覧表示します。コミットされた .env のように、対処方法の助言にとどまる問題は自動修正されません。
$ fastkit doctor --fix
...
Planned changes ────────────────────────────────────────────────────────────────
modify scripts/test.sh (convert scripts/test.sh from CRLF to LF line endings)
Apply these 1 file change(s)? [y/N]: y
updated scripts/test.sh
...
╭────────────── Warning ───────────────╮
│ ⚠️ 1 problem(s) found (1 high). │
╰──────────────────────────────────────╯
対処手順(git rm --cached .env、コミット、シークレットのローテーション)を手作業で行うと、次の fastkit doctor は No problems found. で終わります。
CI で使う
ターミナルがない場合、--fix で書き込むには --yes が、プレビューするには --dry-run が必要です。どちらもないと何も変更せず、終了ステータス 2 で終了します。--format json は、スクリプト向けに JSON ドキュメントを 1 つ出力します。各フィールドの説明は fastkit doctor --help にあります。次の例は、.env がコミットされたプロジェクトでの出力のうち、まとめの部分です。
$ fastkit doctor --format json
{
"schema_version": 1,
"fastkit_version": "2.0.0",
...
"summary": {
"problems": 1,
"fixable": 0,
...
CI ジョブは終了ステータスで結果を判断できます。問題が見つからなかった場合(またはすべて修正された場合)は 0、問題が残っている場合は 1、doctor を実行できなかった場合は 2 です。
fastkit のメタデータがないプロジェクト
doctor は、fastkit が pyproject.toml に書き込む [tool.fastapi-fastkit] テーブルを読み取ります。fastkit 1.4.0 より前に生成されたプロジェクトや、fastkit 以外で作られたプロジェクトでは、終了ステータス 2 で停止し、--force を使うよう提案します。fastkit doctor --force はそのようなプロジェクトも検査し、メタデータが必要なチェックはスキップします。