|
| 1 | +# v0.3.0 plan — three new tools (`ports`, `hosts`, `ssh`) |
| 2 | + |
| 3 | +> Scope per maintainer (2026-05-14): "add all of the above: |
| 4 | +> shimkit {ssh, hosts, ports, etc}". Charter is the host-machine |
| 5 | +> dev-workflow envelope; each of these fits. |
| 6 | +
|
| 7 | +## Ordering |
| 8 | + |
| 9 | +Build in increasing complexity so the architecture decisions get |
| 10 | +exercised by the simplest tool first: |
| 11 | + |
| 12 | +1. **`shimkit ports`** (smallest, ~150 LOC manager + ~30 tests) |
| 13 | +2. **`shimkit hosts`** (medium, ~250 LOC manager + ~40 tests; reuses |
| 14 | + atomic-write + backup from `adguard`) |
| 15 | +3. **`shimkit ssh`** (largest, ~400 LOC manager + ~60 tests; pulls |
| 16 | + together everything from both) |
| 17 | + |
| 18 | +Each tool lands as its own commit on `main`; ship v0.3.0 once all |
| 19 | +three are in. |
| 20 | + |
| 21 | +## Architecture rules — same five from CONTRIBUTING.md |
| 22 | + |
| 23 | +1. All subprocess via `CommandRunner.run(...)` (argv-list, no `shell=True`). |
| 24 | +2. All output via `UI.*` — no `print`, no `typer.echo`. |
| 25 | +3. Config-driven values (defaults.json) for anything user-tunable. |
| 26 | +4. Builder pattern: `Manager.create().boot().run()`. |
| 27 | +5. Fluent `self` returns from builders. |
| 28 | + |
| 29 | +## Per-tool surface |
| 30 | + |
| 31 | +### `shimkit ports` — port owner inspector + killer |
| 32 | + |
| 33 | +```text |
| 34 | +shimkit ports # interactive menu (Manager.run) |
| 35 | +shimkit ports show [PORT] # cross-platform: lsof on macOS, ss on Linux |
| 36 | +shimkit ports kill PORT # MODERATE prompt; --yes/--force; --signal=TERM|KILL |
| 37 | +``` |
| 38 | + |
| 39 | +- **Cross-platform**: `lsof -nP -iTCP -sTCP:LISTEN` on macOS, |
| 40 | + `ss -tulnp` on Linux. Output normalised to a `PortOwner` model. |
| 41 | +- **JSON output**: `--json` emits `{status, data: [{port, proto, pid, name, user}]}`. |
| 42 | +- **MODERATE prompt** on `kill`. SEVERE prompt only if `pid == 1` or |
| 43 | + `name == "systemd"` (refuse with `--confirm KILL-INIT`). |
| 44 | +- **No extra deps** — uses `CommandRunner.run` only. No `psutil`. |
| 45 | + |
| 46 | +### `shimkit hosts` — `/etc/hosts` editor with backup |
| 47 | + |
| 48 | +```text |
| 49 | +shimkit hosts # interactive menu |
| 50 | +shimkit hosts show [--json] |
| 51 | +shimkit hosts add IP NAME # MODERATE prompt; atomic write |
| 52 | +shimkit hosts remove NAME # MODERATE prompt |
| 53 | +shimkit hosts block DOMAIN # add 127.0.0.1 entry |
| 54 | +shimkit hosts unblock DOMAIN |
| 55 | +shimkit hosts apply-list URL_OR_PATH # SEVERE; --confirm APPLY-LIST |
| 56 | +shimkit hosts rollback # restore latest /etc/hosts.bak-* |
| 57 | +``` |
| 58 | + |
| 59 | +- **Atomic write**: parse → mutate in-memory → `install -m 644` to a |
| 60 | + temp file → atomic move (reuse pattern from |
| 61 | + `adguard/resolv.py::write_resolv_static`). |
| 62 | +- **Backup pattern**: `/etc/hosts.bak-YYYYMMDD-HHMMSS` (same as |
| 63 | + `adguard`). |
| 64 | +- **Block list parser**: tolerant of comment lines + the StevenBlack |
| 65 | + format (`0.0.0.0 example.com`). Caps applied entries per call |
| 66 | + (configurable; default 5000). |
| 67 | +- **Needs root** for any mutator; exits 77 with the |
| 68 | + `sudo shimkit hosts ...` hint matching `adguard`. |
| 69 | + |
| 70 | +### `shimkit ssh` — key + agent + perms hygiene |
| 71 | + |
| 72 | +```text |
| 73 | +shimkit ssh # interactive menu |
| 74 | +shimkit ssh keys list [--json] |
| 75 | +shimkit ssh keys generate NAME # ed25519; MODERATE prompt; passphrase via stdin |
| 76 | +shimkit ssh keys rotate NAME # generate new + load agent + print update steps |
| 77 | +shimkit ssh agent status [--json] |
| 78 | +shimkit ssh agent start # idempotent ssh-agent boot |
| 79 | +shimkit ssh agent add KEY_PATH # ssh-add wrapper |
| 80 | +shimkit ssh known-hosts audit [--json] # find duplicates + stale entries |
| 81 | +shimkit ssh known-hosts prune # MODERATE prompt; remove duplicates |
| 82 | +shimkit ssh perms audit [--json] # check ~/.ssh and key file modes |
| 83 | +shimkit ssh perms fix # MODERATE prompt; chmod 700/600/644 |
| 84 | +shimkit ssh config show [HOST] # parse ~/.ssh/config and show Host blocks |
| 85 | +``` |
| 86 | + |
| 87 | +- **No extra deps** — `ssh-keygen`, `ssh-add`, `ssh-agent`, and |
| 88 | + `ssh-keyscan` are all baseline. |
| 89 | +- **Passphrase handling**: prompt via Typer's `hide_input=True`; never |
| 90 | + log; ssh-keygen consumes via `-N` (validated by length, not |
| 91 | + content-pattern, so the value never hits the redaction layer). |
| 92 | +- **Perm matrix** lives in config (`tools.ssh.perms`): |
| 93 | + - `~/.ssh` → 700 |
| 94 | + - `~/.ssh/config`, `known_hosts`, `authorized_keys` → 644 |
| 95 | + - Private keys (no `.pub` suffix) → 600 |
| 96 | + - Public keys (`.pub` suffix) → 644 |
| 97 | +- **Agent state** parsed from `ssh-add -L` output; refusing-no-agent |
| 98 | + exits 69 with a hint to run `shimkit ssh agent start`. |
| 99 | + |
| 100 | +## Test minimums per tool (CONTRIBUTING.md baseline) |
| 101 | + |
| 102 | +For each: `boot()` smoke, `boot()` 69 on wrong platform (if |
| 103 | +applicable), `boot()` 69 on missing extra (n/a — no extras), every |
| 104 | +non-interactive subcommand one happy + one sad path, `--json` parses, |
| 105 | +`--dry-run` makes zero `CommandRunner.run` calls (assert via |
| 106 | +monkeypatch), MODERATE prompts blocked under `--no-input`. Severe |
| 107 | +prompts abort without the right token. |
| 108 | + |
| 109 | +Mock at `CommandRunner.run`, `Platform.detect`, and Path-level |
| 110 | +filesystem fixtures via `tmp_path`. Never touch real `~/.ssh` or |
| 111 | +`/etc/hosts`. |
| 112 | + |
| 113 | +## Config additions to `defaults.json` |
| 114 | + |
| 115 | +```json |
| 116 | +{ |
| 117 | + "tools": { |
| 118 | + "ports": { |
| 119 | + "default_signal": "TERM", |
| 120 | + "init_pid_severe_token": "KILL-INIT" |
| 121 | + }, |
| 122 | + "hosts": { |
| 123 | + "hosts_path": "/etc/hosts", |
| 124 | + "apply_list_severe_token": "APPLY-LIST", |
| 125 | + "max_entries_per_apply": 5000 |
| 126 | + }, |
| 127 | + "ssh": { |
| 128 | + "ssh_dir": "~/.ssh", |
| 129 | + "default_key_type": "ed25519", |
| 130 | + "perms": { |
| 131 | + "dir": "700", |
| 132 | + "private_key": "600", |
| 133 | + "public_key": "644", |
| 134 | + "config": "644", |
| 135 | + "known_hosts": "644", |
| 136 | + "authorized_keys": "644" |
| 137 | + } |
| 138 | + } |
| 139 | + } |
| 140 | +} |
| 141 | +``` |
| 142 | + |
| 143 | +## Out of scope this cycle |
| 144 | + |
| 145 | +- **YubiKey / hardware-token SSH keys** — adds vendor SDKs; revisit |
| 146 | + if there's demand. |
| 147 | +- **GPG keys** for git signing — separate `shimkit gpg` tool, not |
| 148 | + bundled. |
| 149 | +- **Cloud DNS / hosts** (Route53 + Cloudflare etc.) — out of charter |
| 150 | + (not host-machine). |
| 151 | +- **NetworkManager / nmcli wrappers beyond what `adguard` already |
| 152 | + does** — would need its own tool. |
| 153 | +- **Windows support** — explicit charter exclusion. |
| 154 | + |
| 155 | +## Acceptance gates for v0.3.0 |
| 156 | + |
| 157 | +- All five core architecture rules upheld in each new tool. |
| 158 | +- 233 → ~370 tests (the +130 baseline test floor across three tools). |
| 159 | +- Coverage stays above the 65% floor; aim to nudge toward 70%. |
| 160 | +- ruff + mypy strict still clean. |
| 161 | +- `shimkit --help` shows the three new sub-apps. |
| 162 | +- `docs/tools/{ports,hosts,ssh}.md` present, following the |
| 163 | + established template. |
| 164 | +- README's tool list extended. |
| 165 | +- CHANGELOG `[0.3.0]` entry written. |
0 commit comments