2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

複数のAI(Claude/ChatGPT/Codex/Gemini)の「いまどこまで」を、Python標準ライブラリだけで1枚のNOW.mdにまとめる

2
Posted at

困りごと

Claude、ChatGPT、Codex、Geminiなど複数のAIを使い分けていると、AIを替えるたびに「いまどこまで進んだか」「何が止まっているか」を説明し直すことになります。

AIに任せて HANDOFF.md のようなファイルを書かせる手もありますが、書くAIごとに書式が変わり、読む側も長いファイルを毎回読むことになります。

そこで、「書く」のは小さなJSON、「まとめる」のはスクリプトに分けました。まとめ役にAIを使わないので、書式はぶれず、ネット接続もいりません。

仕組み

  1. 各AI(または自分)が、やること1件につき小さなJSONを tasks/ に1つ書く
  2. スクリプトが全部を集めて NOW.md を1枚作る(手では直さない)
  3. 次のAIは、最初にこの1枚だけ読む

NOW.md の中身は4つだけです。

  • Running(動いている作業)
  • Stuck(止まっている作業と、戻し方)
  • Done in the last 24h(直近24時間に終わった作業)
  • Latest notes / decisions(最新のメモ・決定)

最大120行で、超えたときは最後の行に …(N行省略 / lines omitted) と出ます。

出力はこんな形です。

# NOW (written by a script — do not edit by hand)
- built: 2026-11-22 18:44   / read this one page first; details live in each task's result file

## Running
- Fix login bug (claude) since 11/22 18:44

## Stuck (and how to unblock)
- [blocked] Write tests (codex) — why: needs API key / how to unblock: ask the owner for a test key

## Done in the last 24h
- none

## Latest notes / decisions
- 11/22 18:44 Decision: use SQLite

tasks/ に置かれる1件分のJSONはこれだけです。

{
 "id": "20261122_184412_codex",
 "who": "codex",
 "title": "Write tests",
 "status": "blocked",
 "started": "2026-11-22T18:44:12+09:00",
 "updated": "2026-11-22T18:44:12+09:00",
 "why": "needs API key",
 "fix": "ask the owner for a test key"
}

status は running / waiting / blocked / failed / done のいずれかです。

使ってみる

標準ライブラリだけの1ファイル(nowmd.py、Python 3.11以上)なので、コピーするだけで動きます。付属の examples/ を汚さないよう、コピーしたフォルダで試します。

cp -r examples /tmp/nowmd-try
python3 nowmd.py --dir /tmp/nowmd-try add --who claude --title "Fix login bug" --status running
python3 nowmd.py --dir /tmp/nowmd-try add --who codex --title "Write tests" --status blocked \
  --why "needs API key" --fix "ask the owner for a test key"
python3 nowmd.py --dir /tmp/nowmd-try note "Decision: use SQLite"
cat /tmp/nowmd-try/NOW.md

状況が変わったとき、終わったとき、記録が壊れていないか確かめたいとき、IDを忘れたときは次のとおりです。

python3 nowmd.py --dir /tmp/nowmd-try update --id <id> --status blocked --why "..." --fix "..."
python3 nowmd.py --dir /tmp/nowmd-try done --id <id> --result result.md
python3 nowmd.py --dir /tmp/nowmd-try check
python3 nowmd.py --dir /tmp/nowmd-try list

pipx install でコマンドとして入れることもできます(入れたあとは python3 nowmd.py を nowmd に読み替え)。

pipx install git+https://github.com/kanazawateppei2020-spec/now-md
nowmd --version

AIに使わせる

各AIの指示書(CLAUDE.md / AGENTS.md / GEMINI.md など)に、次の数行を足します。リポジトリの templates/ に、Claude・Codex・Gemini・ChatGPT向けの雛形があります。

## Hand-off (now-md)
- At the start of every session, read `NOW.md` (one page: running / stuck / done / notes). Do not edit it by hand.
- At each milestone leave one line:
  - start:   `python3 nowmd.py add --who claude --title "<what you are doing>"`
  - change:  `python3 nowmd.py update --id <id> --status blocked --why "<reason>" --fix "<how to unblock>"`
  - finish:  `python3 nowmd.py done --id <id> --result <path-to-result-file>`
  - decision: `python3 nowmd.py note "<decision in one line>"`
- Keep titles short. Put details in a result file, not in NOW.md.

詳細は結果ファイル(--result)に置き、NOW.md には1行だけ残すのがコツです。

python3 nowmd.py build をcronなどで数分おきに回すと、running のまま60分以上更新がない作業に ⚠ が付きます。

複数のAIが同時に書いても壊れないようにしたこと

複数のAIが同時に書く場面を想定して、次の対策を入れています。

  • IDが重ならない: 日時+AI名+ランダムな4桁の16進数。ファイルを排他的に作成して確保する(同じIDなら作り直し)
  • ロックファイル: 書き込み中は .nowmd.lock を取る。持ち主のプロセスが終わっているときだけ奪う(NOWMD_LOCK_WAIT / NOWMD_LOCK_STALE 環境変数で調整)
  • 原子的な置き換え: 一時ファイルに書いて fsync してから os.replace で置き換えるので、途中の状態を読まれない
  • 入力の検査: --id に ../ のような文字列を入れてもtasks外を触れない。--who と result は1行に短縮され、見出しを偽造して NOW.md を壊せない。不正なJSONや範囲外の日付は check で見つかる

テストは標準ライブラリの unittest です。別々のプロセス10個が同時に書いても記録が失われないことを確かめるテストも入れています。

python3 -m unittest discover -s tests

向いていないこと

  • 会話を保存する「メモリ」ではありません。AIも呼びません。
  • AGENTS.md / CLAUDE.md のような「いつも守る指示」の代わりではありません。併用して、NOW.md を「1時間ごとに変わるページ」にします。
  • 書き手を信頼する前提です。タスクに書かれた文字は、次のAIが読むページにそのまま入ります。信頼できない人やツールが書き込める場所に tasks/ を置かないでください。
  • 同期フォルダやネットワーク共有ではなく、1台のマシンの普通のフォルダで使う前提です。

リポジトリ

MITライセンスです。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?