Metadata-Version: 2.5
Name: totp-authenticator-cli
Version: 0.1.2
Summary: Generate the TOTP two-factor codes an autonomous agent needs: accounts imported once from Google Authenticator, stored encrypted, each code handed over with the seconds it has left.
Project-URL: Homepage, https://github.com/applica-software-guru/totp-cli
Author: Bruno Fortunato
License: MIT License
        
        Copyright (c) 2026 Bruno Fortunato
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: 2fa,agent,google-authenticator,otp,totp,two-factor
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: cryptography>=42
Requires-Dist: pydantic>=2.7
Requires-Dist: rich>=13
Requires-Dist: tomli>=2.0; python_version < '3.11'
Requires-Dist: typer>=0.16
Provides-Extra: dev
Requires-Dist: mypy>=1.11; extra == 'dev'
Requires-Dist: pytest>=8; extra == 'dev'
Requires-Dist: ruff>=0.6; extra == 'dev'
Description-Content-Type: text/markdown

# totp

The two-factor half of a login, for autonomous agents. Accounts are imported once from Google
Authenticator and stored encrypted; each call hands an agent the code it needs, with a
guaranteed minimum of the step still ahead of it — so the code it types is never one that
expires under its fingers.

It is the second half of a pair with
[use-computer](https://github.com/applica-software-guru/use-computer), which types the password
from its secret store. The two compose in one line, and the digits go from the store to the
keystrokes without passing through the agent's context:

```bash
use-computer type --text "$(totp code github)"
```

## Install

```bash
pip install totp-authenticator-cli
```

The distribution is `totp-authenticator-cli` because `totp-cli` and `totp` are both taken on
PyPI by unrelated projects. The command it installs is `totp`, and the package it imports is
`totp_cli`. There are no optional extras: the whole tool is pure Python over the standard
library plus five wheels-everywhere dependencies.

## Use

```bash
totp add github --issuer GitHub        # the seed, pasted or typed on stdin — never an argument
totp code github                       # six digits on stdout, with ≥5s of validity guaranteed
totp github                            # `code` is the default command
totp import                            # the Google Authenticator export, pasted on stdin
totp list                              # names and parameters; never a seed
totp skill install                     # the agent skill, into this project's skills directory
```

`add` prints the current code as it stores the account — the one moment the phone is open next
to the terminal, and the only verification the enrollment has.

`code` refuses to hand over a code with under `--min-validity` seconds left (default 5): it
waits for the next step and says so on stderr. `--no-wait` takes whatever is left. A wait of up
to one step is normal; killing it and retrying is the one way to make the tool wrong.

stdout is the digits and nothing else — no trailing newline, so a pipe receives the exact
bytes. Diagnostics go to stderr. Exit codes: `0` success, `1` failure, `2` bad usage.
`--format json` exists on `code` and `list` for programs.

## Importing from Google Authenticator

The phone's *Settings → Transfer accounts → Export accounts* shows QR codes whose payload is an
`otpauth-migration://offline?data=…` URI — every account in one string. Read it with any QR
reader that shows text (the camera app on a Mac, an online decoder, a phone that displays what
it scanned) and paste the URI into `totp import`. Single accounts arrive the same way, as the
`otpauth://totp/…` URI behind the "can't scan?" screen most services offer.

HOTP accounts are skipped: an exported counter desyncs from the phone the moment it is used,
which would break the login the import was meant to complete.

## Where the seeds live

- `~/.config/totp-cli/accounts.toml` — the store, Fernet-encrypted, mode 0600.
- `~/.local/share/totp-cli/account.key` — the key, mode 0600, deliberately **not** beside the
  ciphertext: a `~/.config` that gets synced, committed or pasted carries nothing usable.

The key file location is overridable with `TOTP_CLI_KEY_FILE`; an account can be supplied
directly with `TOTP_CLI_ACCOUNT_<NAME>` for a headless machine (plaintext, by design — the
environment is what the environment is; what it buys is a machine where the seed never touches
disk).

**The seed never enters the agent's context.** It is read from stdin, encrypted at rest, and
no command prints it — `list` shows names, errors show remedies. A *code* is fine to print: it
is worth one login and thirty seconds, which is the whole product.

## The agent skill

The instructions the calling agent reads ship inside the package and match the installed
version:

```bash
totp skill install --scope project    # .agents/skills/totp/ (or .claude/skills/, if that is there)
totp skill install --scope user       # the home directory
totp skill status
```

Nothing is ever written to or removed from a directory that does not carry this skill's
frontmatter marker.

## Development

```bash
cd code
uv venv && uv pip install -e ".[dev]"
uv run pytest          # the RFC 6238 vectors, a fake clock, an isolated XDG home
uv run ruff check .
uv run mypy
```

Tests never wait a real thirty seconds and never read a real store: the clock is a fixture and
the XDG home is a temporary directory.

## License

MIT.
