Build the CLI core
Agent assistance is allowed only after prediction; inspect and test every generated diff.
Prerequisites
Days 01–12: strings, dictionaries, files, exceptions, tests, and terminal use.
Learning Objective
Implement or inspect projects/text_tools/core.py and cli.py for statistics, deterministic splits, a provenance manifest, and explicit encoding errors.
Instructions
Required work: create a private workspace for this exercise (WORKDIR=$(mktemp -d)), write a small corpus to $WORKDIR/corpus.txt, record a prediction, then run the complete invocation python3 projects/text_tools/cli.py --input "$WORKDIR/corpus.txt" --stats --json --split --output-dir "$WORKDIR/artifacts"; inspect the diff, and exercise --input, --stats, --split, --output-dir, --seed, --encoding, and --errors. Optional work: compare the Python documentation links.
Practice and prediction
Use a small corpus containing repeated tokens, CJK, accents, and an emoji. Predict character/token counts, then verify stats.json and manifest.json -- including that source_sha256 equals the SHA256 of the original input bytes (e.g. sha256sum "$WORKDIR/corpus.txt") and that input_decoding records the encoding, error handling, and newline policy.
Keep calculation in core.py and presentation in cli.py. Use random.Random(seed), ordered indices, SHA256, and a zero-token guard.
A sound solution uses Counter for tokens/chars, len(text) for Unicode code points, random.Random(seed) over list(range(n)), disjoint index sets, and manifest fields for source/split hashes, ratios, counts, environment, and no_leakage_verified. The manifest also records source_sha256 over the original bytes, decoded_text_sha256, the input_decoding policy, normalized_ratios, and rejects input/output path collisions before any artifact write.
Learning Project Submission & Evidence
The learner can explain and run the real text_tools CLI, with prediction/evidence recorded and no claim that an agent-written diff proves independent understanding.
Source resources and provenance
Python Standard Library: Built-in Types
Relevant Section / Range: str methods and Unicode semantics used by analyze_text (split, join, isalpha, isdigit)
Verified Version & Date: 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.
Compared Candidate Sources & Selection Analysis (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
Relevant Section / Range: add_argument flags, choices, and type conversion used by cli.py
Verified Version & Date: 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.
Compared Candidate Sources & Selection Analysis (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.