Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions docs/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ python -m hmz ...
| | `help` | Show the help of hmz or of one command. |
| | `update` | Update hmz to its newest release. |
| | `internal` | Internal commands used by Humanize; do not run directly. |
| Other commands | `server` | Install and manage this machine's web server service. |

<!-- command list: end -->

Expand Down Expand Up @@ -240,6 +241,24 @@ hmz web [--port PORT] [--origin ORIGIN] [--no-open] [--attached]

A browser opens automatically on macOS, or when `DISPLAY` or `WAYLAND_DISPLAY` is set. SIGINT, SIGTERM or SIGHUP stops the server with exit 0 without stopping any epics. Exits 1 if the page cannot be served. See [The browser page](/user/web).

## hmz server

Install and manage the web interface as a per-user service that starts at login.

```text
hmz server install
hmz server uninstall
hmz server status
```

| Subcommand | What it does |
| --- | --- |
| `install` | Installs and starts at login. Linux uses systemd --user; macOS uses a LaunchAgent. |
| `uninstall` | Stops the service, then removes its unit or plist. |
| `status` | If installed, prints its active and enabled state on Linux or loaded state on macOS, and the log path. Otherwise, prints that it is not installed and the service-file path. |

The service runs `hmz web --no-open`, is kept running, and writes stdout and stderr to a private per-user log. Stopping it lets the web server close cleanly. Exits 1 if the platform is unsupported or service management fails.

## hmz daemon

```text
Expand Down
2 changes: 2 additions & 0 deletions docs/reference/files.md
Original file line number Diff line number Diff line change
Expand Up @@ -369,3 +369,5 @@ Humanize never prunes these paths; delete them manually when you no longer need
Humanize reads `~/.ssh/config` and its included files, and never writes to them.

`hmz daemon install` writes one file outside these places: `~/Library/LaunchAgents/ai.humanfia.hmz.daemon.plist` on macOS, or `$XDG_CONFIG_HOME/systemd/user/hmz-daemon.service` on Linux, with the `XDG_CONFIG_HOME` of your systemd user manager (`~/.config/systemd/user/hmz-daemon.service` when it is unset or relative). `hmz daemon uninstall` removes it. See [Daemon and wire](/reference/daemon).

`hmz server install` writes `~/Library/LaunchAgents/ai.humanfia.hmz.web.plist` on macOS or `$XDG_CONFIG_HOME/systemd/user/hmz-web.service` on Linux, using the systemd user manager's `XDG_CONFIG_HOME` (`~/.config/systemd/user/hmz-web.service` when unset or relative). The web log is `~/Library/Logs/hmz-web.log` on macOS or `~/.local/state/humanize/hmz-web.log` on Linux, mode `0600`. `hmz server uninstall` removes the service file but leaves the log.
20 changes: 20 additions & 0 deletions docs/user/web.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,26 @@ This starts the daemon if none is running, prints the page address, and opens it

The folder where you run `hmz web` is the folder offered first for new chats and epics.

## Run as a login service

To start the web interface when you log in:

```sh
hmz server install
hmz server status
```

Linux uses a systemd user service; macOS uses a LaunchAgent. The service starts at login
and is kept running. Its output is written to a private log in your state directory on Linux
or `~/Library/Logs/hmz-web.log` on macOS. The log contains the keyed page address. Stopping
or uninstalling the service lets the web server close cleanly.

Remove the service with:

```sh
hmz server uninstall
```

### Sign in with the key

The page listens on the local machine only (`127.0.0.1`), at an address ending in a secret key. Open the full address once to set a browser cookie. After that, the plain address, such as `http://127.0.0.1:8420/`, works in that browser until you quit it.
Expand Down
68 changes: 61 additions & 7 deletions protocol/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,14 @@ It is normative. It is cited by the tag [CLI].
- [26.4. `--json`](#264---json)
- [26.5. Completion scripts](#265-completion-scripts)
- [26.6. How a help is set](#266-how-a-help-is-set)
- [27. Security Considerations](#27-security-considerations)
- [28. References](#28-references)
- [28.1. Normative References](#281-normative-references)
- [27. `hmz server`](#27-hmz-server)
- [27.1. Synopsis](#271-synopsis)
- [27.2. Installing and removing the service](#272-installing-and-removing-the-service)
- [27.3. Status](#273-status)
- [27.4. Exit](#274-exit)
- [28. Security Considerations](#28-security-considerations)
- [29. References](#29-references)
- [29.1. Normative References](#291-normative-references)

## 1. Introduction

Expand Down Expand Up @@ -3016,7 +3021,55 @@ usage line and the line of an example MUST NOT be broken.
**26.6.2** Such a help MAY write its headings in bold, and MUST write no other escape. It MUST write
none where Section 4.2.1 says no for standard output, and none where `--no-color` is given.

## 27. Security Considerations
## 27. `hmz server`

### 27.1. Synopsis

```text
hmz server install
hmz server uninstall
hmz server status
```

**27.1.1** `hmz server` MUST take exactly one of `install`, `uninstall` and `status`. Any other
line MUST be a usage error (Section 16.10).

### 27.2. Installing and removing the service

**27.2.1** On macOS, `hmz server install` MUST write a LaunchAgent to
`~/Library/LaunchAgents/ai.humanfia.hmz.web.plist`, using `~/Library/Logs/hmz-web.log` for its
standard output and standard error, and MUST start it immediately and at login. On Linux, it MUST
write a systemd user unit named `hmz-web.service` under `systemd/user` in the absolute
`XDG_CONFIG_HOME` reported by the systemd user manager, or under `~/.config` where none is reported.
It MUST use `~/.local/state/humanize/hmz-web.log` for the unit's standard output and standard error,
and MUST enable and start the unit immediately and at login.

**27.2.2** Each service MUST run `hmz web --no-open`, restart it when it exits, and create its log
with permissions readable and writable by the user alone. On success, `install` MUST write
`hmz server: installed <path>` and a line feed to standard output, `<path>` being the service file.

**27.2.3** `hmz server uninstall` MUST stop the service and remove its LaunchAgent or systemd user
unit. Where Linux's current service path differs from `~/.config/systemd/user/hmz-web.service` and
the latter exists, it MUST remove that older unit too. On success, `uninstall` MUST write
`hmz server: uninstalled <path>` and a line feed to standard output.

### 27.3. Status

**27.3.1** `hmz server status` MUST write
`hmz server: not installed (<path>)` and a line feed to standard output where no service file
exists. Where installed, it MUST report the service state and the log path as
`hmz server: installed, <state> (<path>); log: <log>` and a line feed. On Linux, `<state>` MUST
contain the states reported by `systemctl --user is-active` and `systemctl --user is-enabled`; on
macOS, it MUST be `loaded` or `not loaded` according to `launchctl`.

### 27.4. Exit

**27.4.1** Successful operations MUST exit with status 0. `status` MUST exit with status 0 when
the service is not installed. An unsupported operating system, an uninstall when no service is
installed, or a failure to prepare, start, stop, inspect or remove the service MUST exit with status
1.

## 28. Security Considerations

This section states no requirement; it summarises the security-relevant properties the rest of this
document states.
Expand Down Expand Up @@ -3050,7 +3103,8 @@ document states.
relay serve` listens where it is told, on plain WebSockets, admits anybody, and carries only what
is secured end to end (Section 14.2.1).
- **Services.** `hmz daemon install` makes the daemon start at login and keeps it running with its
listeners (Section 13.2.4). `hmz daemon connect --stdio` gives whoever runs it, as this user, the
listeners (Section 13.2.4). `hmz server install` runs `hmz web --no-open` as a login service for
this user (Section 27.2). `hmz daemon connect --stdio` gives whoever runs it, as this user, the
daemon's socket on its standard streams (Section 13.2.3).
- **`hmz internal`.** These commands are the command lines hmz starts its own processes with and
are not a public interface, yet each runs when a user types it (Section 11.1). `hmz internal
Expand All @@ -3064,9 +3118,9 @@ document states.
(Section 3.8.5.6 of [DAEMON]). `hmz web` opens a browser unless `--no-open` is given (Section
8.2.5).

## 28. References
## 29. References

### 28.1. Normative References
### 29.1. Normative References

- **[RFC2119]** Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC
2119, March 1997, <https://www.rfc-editor.org/info/rfc2119>.
Expand Down
8 changes: 8 additions & 0 deletions src/hmz/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,13 @@ def _internal(argv: list[str]) -> int:
return INTERNAL[argv[0]][0](argv[1:])


def _server(argv: list[str]) -> int:
"""Installs or manages this machine's web server service."""
from .server import server

return server(argv)


def _line(*, plain: bool = False) -> ArgumentParser:
"""The line `hmz` itself takes, which is how the interface is opened.

Expand Down Expand Up @@ -720,6 +727,7 @@ def _closes(app: Humanize) -> int:
"relay": (_relay, "relay daemons and the devices that reach them"),
"update": (_update, "update hmz to its newest release"),
"internal": (_internal, "internal commands used by Humanize; do not run directly"),
"server": (_server, "install and manage this machine's web server service"),
}


Expand Down
Loading
Loading