Metadata-Version: 2.4
Name: bofile
Version: 0.1.0
Summary: Standard-library CLI for the local BoFileX HTTP API
License-Expression: LicenseRef-Proprietary
Project-URL: Homepage, https://bofile.com/
Project-URL: Documentation, https://bofile.com/install.html
Keywords: bofile,bofilex,cli,file-transfer
Classifier: Environment :: Console
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Communications :: File Sharing
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# bofile — Python CLI for BoFileX

Control a **running local BoFileX** using its existing HTTP API. The PyPI
distribution, Python module and console command are all named `bofile`.
Python 3.10+; **no runtime dependencies**. This package does not include the
BoFileX daemon or implement libp2p, start services, or create machine state.

## Install and run

After publication:

```sh
python -m pip install bofile
bofile --help
python -m bofile --version
```

From this directory during development:

```sh
python -m pip install -e .
python -m bofile --help
```

The default API origin is `http://127.0.0.1:34120`, set by
`client/bofilex_main.go`. BoFileX can choose another free port if that port is
busy: use the actual HTTP UI origin explicitly. A native-only Wails window may
not expose this HTTP API. The old dialer API on port 34115 is a different API
and is not supported here.

```sh
bofile --base-url http://127.0.0.1:34120 info
bofile peers --json
bofile message send PEER_ID "你好，文件已经准备好了"
bofile files list PEER_ID . --json
bofile transfer upload PEER_ID ./report.pdf /shared
bofile transfer download PEER_ID /shared/report.pdf ./downloads --size 12345 --mtime 1700000000
bofile transfer list --json
bofile transfer cancel 42
bofile transfer resume 42
bofile channels list PEER_ID
bofile channels select nat --direction up
bofile channels select auto
bofile channels mode direct
bofile channels mode auto
```

Replace `PEER_ID` with a full peer ID from `peers`. Global flags (`--base-url`,
`--token-file`, `--timeout`, `--json`) work before or after subcommands.
Each command supports `--help`. This CLI defaults to a 30-second HTTP timeout.
There is no automatic retry, since resubmitting a mutation could duplicate work.

## Authentication and connection safety

`core/modules/admin/guard.go` allows non-browser scripts that omit Origin,
Referer and Sec-Fetch-Site. The CLI uses that contract by default and **does not
read any token, configuration, identity or state file automatically**.
It never fetches the UI page to harvest a session cookie.

When a persisted UI token is needed, explicitly select the existing file:

```sh
bofile --token-file /path/to/ui-session.token info
```

The file must contain the 32-character hex UI token. It is sent as the cookie
`bofile_ui_<API-port>`, not as a Bearer token or query parameter. No token option
accepts the raw secret on the command line. The file is read only and is never
created or refreshed. Invalid/missing explicit files fail rather than falling
back silently. A 401/403 is an error; remote management password login is not
implemented.

BoFileX resolves its own state using `BOFILE_STATE_DIR`, or on Windows usually
`%ProgramData%\bofilex`, otherwise the platform user config directory with the
`bofilex` namespace (and native fallback rules). Choose the file used by your
instance explicitly; this CLI does not reproduce the daemon's state migration
or executable-directory fallback logic.

Only **numeric loopback origins** are accepted (`127.0.0.1`, `[::1]`); DNS names,
including `localhost`, non-loopback IPs, URL credentials, base paths, queries and
fragments are rejected before reading a token. Environment HTTP proxies are
disabled. All redirects are refused, even to another loopback port. This keeps
cookies and local data from being forwarded to a different endpoint or through
a proxy. HTTPS uses Python's normal certificate verification. For another
machine use a trusted SSH tunnel to a local numeric loopback port; remote file
paths and metadata then belong to that daemon, so upload/download local path
checks assume the CLI and BoFileX share the same filesystem.

## Transfer and channel semantics

- Upload/download **queue a server-side single-file job**. File bytes do not
  pass through Python. A successful command returns a job ID, not a completed
  transfer. Inspect `transfer list` for queued/active/done/error/canceled states.
  Exiting or interrupting the CLI does not cancel submitted work.
- Upload source paths are resolved to absolute paths and must be regular local
  files. Size comes from the file stat. The destination is a remote directory;
  `--name` changes the destination basename. Directory recursion is not included.
- Download targets are existing local directories, resolved to absolute paths.
  Use `files list` to obtain the remote `path`, `size` and `mtime` (Unix seconds).
  `--size` is required, including `--size 0` for an empty file. No metadata lookup
  happens implicitly. `--mtime` defaults to zero (unknown). `--overwrite` opts
  into replacing a local destination; otherwise BoFileX chooses a free name.
  Remote upload conflict handling remains the daemon's behavior.
- Cancel is the daemon's idempotent operation: it may return `status: ok` even
  for an unknown ID. Resume acts on the **same existing job** and its `.part`
  data; the daemon rejects jobs it cannot continue. Queue durability across a
  daemon restart is not promised by this CLI.
- A message response `sent: true` means **accepted for asynchronous delivery**.
  The daemon may subsequently queue/retry delivery or record a refusal.
- `channels list PEER_ID` can focus the engine on that peer when no UI socket
  holds focus. An open UI socket may retain focus instead; check the response's
  `peer`. `channels select` and `channels mode` change the **shared currently
  focused engine**, not a per-command or per-peer isolated session. Selecting
  `auto` sends an empty pin; selecting all directions clears directional pins.
  A pin may fall back to another ready path. `direct`/`relay` modes clear pins.
- `files list` can update the daemon's remembered remote pane directory.
  `peers` may refresh discovery. These are existing API side effects.

## Output, errors and API mapping

`--json` prints the API response as one JSON value on stdout. Human output is
pretty JSON except for explicit message submission/transfer queue acknowledgments.
Operational errors use stderr (a JSON `{"error": "..."}` object with `--json`),
with no traceback or HTTP response body dump. API `error` fields fail even when
HTTP status is 200. HTTP responses are limited to 8 MiB.

Exit codes: `0` success, `1` operational/API error, `2` argparse usage error,
`130` interrupted. Argparse usage errors remain standard text, including with
`--json`. A timeout or lost connection does not prove that a mutation failed;
check daemon state before submitting it again.

| Command | Local route | Method / query |
| --- | --- | --- |
| `info` | `/api/info` | GET |
| `peers` | `/api/peers` | GET |
| `message send` | `/api/peers/chat/send` | POST; peer, text |
| `files list` | `/api/remote/listdir` | GET; peer, path |
| `transfer list` | `/api/transfers` | GET |
| `transfer upload/download` | `/api/transfer/add` | POST; peer, peername, dir=up/down, src, target, name, size; download: mtime, overwrite |
| `transfer cancel/resume` | `/api/transfer/cancel`, `/api/transfer/resume` | POST; id |
| `channels list` | `/api/peers/channels` | GET; peer |
| `channels select` | `/api/peers/channels/select` | POST; name, dir=empty/up/down |
| `channels mode` | `/api/peers/channels/mode` | POST; mode=auto/direct/relay |

Mutations use POST with **URL query parameters and an empty body**, matching
the Go handlers' `r.URL.Query()` implementation. Do not log full request URLs
if message content or filesystem paths are sensitive. Peer IDs and paths are
encoded query values and can never change the HTTP destination.

## Test, build and release handoff

From this directory (PowerShell):

```powershell
$env:PYTHONPATH = "$PWD/src"
python -m unittest discover -s tests -v
python -m build
```

Tests use only ephemeral loopback mock HTTP servers and temporary files. No
test contacts a running BoFileX, reads real tokens, starts/stops services, or
publishes anything. Coverage includes route/query contracts, file metadata,
Unicode escaping, cookie auth, redirects, proxy isolation, URL restrictions,
JSON/API errors, and validation before any mutation.

`python -m build` creates `dist/bofile-0.1.0-py3-none-any.whl` and
`dist/bofile-0.1.0.tar.gz`. Setuptools is a build dependency only. The sdist
includes the tests. Review package metadata, ownership/licensing and release
version before publication; PyPI name availability does not reserve a name.
The release owner handles PyPI credentials, final validation and publishing.
This implementation deliberately does not upload to PyPI or TestPyPI.
