CLI コアの構築
エージェント支援は予測の記録後にのみ許可。生成された差分はすべて確認しテストすること。
前提条件
Day 01〜12: 文字列、辞書、ファイル、例外、テスト、ターミナル操作。
学習目標
projects/text_tools/core.py と cli.py を実装または精査し、統計、決定的な分割、出所マニフェスト、明示的なエンコーディングエラーを確認する。
手順
必須作業: この演習専用の private ワークスペースを作成し(WORKDIR=$(mktemp -d))、小さなコーパスを $WORKDIR/corpus.txt に書き込み、予測を記録してから、完全な呼び出し python3 projects/text_tools/cli.py --input "$WORKDIR/corpus.txt" --stats --json --split --output-dir "$WORKDIR/artifacts" を実行する。差分を確認し、--input、--stats、--split、--output-dir、--seed、--encoding、--errors を試す。任意作業: Python ドキュメントのリンクを比較する。
演習と予測
繰り返しトークン、CJK、発音記号付き文字、絵文字を含む小さなコーパスを使う。文字数とトークン数を予測してから stats.json と manifest.json を検証する — source_sha256 が元の入力バイト列の SHA256(例: sha256sum "$WORKDIR/corpus.txt")と一致し、input_decoding がエンコーディング・エラー処理・改行方針を記録していることも確認する。
計算は core.py、表示は cli.py に分離する。random.Random(seed)、順序付きインデックス、SHA256、ゼロトークン時のガードを使う。
妥当な解法は、トークンと文字に Counter、Unicode コードポイント数に len(text)、list(range(n)) 上の random.Random(seed)、互いに素なインデックス集合、および source/split ハッシュ、比率、件数、環境、no_leakage_verified を含むマニフェスト項目を用いる。 マニフェストには元バイト列の source_sha256、decoded_text_sha256、input_decoding 方針、normalized_ratios も記録され、入出力パスの衝突は書き込み前に拒否される。
Learning Project Submission & Evidence
学習者は実際の text_tools CLI を説明し実行でき、予測と証拠を記録しており、エージェントが書いた差分を独立した理解の証明とは主張しない。
ソースリソースと出所
Python Standard Library: Built-in Types
該当セクション・タイムスタンプ: str methods and Unicode semantics used by analyze_text (split, join, isalpha, isdigit)
検証バージョンと日付: Python 3.12 documentation; verified 2026-10-30
Primary reference for the string methods and Unicode semantics behind corpus statistics.
Study Days 01–12 Python fundamentals
The lesson explains all required behavior locally and the reference implementation ships in the repository; pydoc mirrors the same documentation offline.
比較対象候補リソースと選定評価 (2)
Powerful system tools, but the learning target is implementing and testing the behavior in Python, not delegating to platform-specific utilities.
Deeper Unicode background for the encoding edge cases; str method reference remains the primary doc.
argparse — Parser for command-line options, arguments and subcommands
該当セクション・タイムスタンプ: add_argument flags, choices, and type conversion used by cli.py
検証バージョンと日付: Python 3.12 documentation; verified 2026-10-30
Primary reference for the CLI flags the learner exercises on the real project.
Study Days 01–12 Python fundamentals
argparse is part of the standard library; python3 -c "import argparse; help(argparse)" works fully offline.
比較対象候補リソースと選定評価 (2)
Strong third-party CLI framework, but the project intentionally uses only the standard library so the exercise needs no extra dependency.
Usage-string DSL for CLIs, but an external dependency is unjustified when argparse covers the project.