# Office Mac (norwich): agent guide

This machine is a shared office Mac. It is reachable through an
[opentunnel](https://opentunnel.xyz) tunnel at `jz6gug4mclfe.opentunnel.xyz`. This file is public;
it holds no secrets. Fetch it again any time from https://jz6gug4mclfe.opentunnel.xyz/AGENTS.md
(or https://jz6gug4mclfe.opentunnel.xyz/llms.txt).

## Endpoints

| Base URL | What | Auth |
| --- | --- | --- |
| https://jz6gug4mclfe.opentunnel.xyz/ | Start page, this file, `/login`, `/logout` | none |
| https://opencode.jz6gug4mclfe.opentunnel.xyz/ | OpenCode server: web chat and REST API. OpenAPI spec at `/doc` | required |
| https://ollama.jz6gug4mclfe.opentunnel.xyz/ | Ollama: native API under `/api/`, OpenAI-compatible under `/v1/` | required |
| https://desktop.jz6gug4mclfe.opentunnel.xyz/ | The Mac's screen in a browser (noVNC), full control. For people | required |
| https://view.jz6gug4mclfe.opentunnel.xyz/ | The same screen, read-only. For people | required |

## Authentication

There is one shared secret. The operator gives it to you; never ask for it
in a public place and never write it into files, logs or commits.

- Preferred: `Authorization: Bearer <secret>`
- Also accepted: HTTP Basic with any username and the secret as the password
- Browsers: sign in once at https://jz6gug4mclfe.opentunnel.xyz/login; the cookie covers every route.

A missing or wrong secret gets `401` with a JSON body. Read the secret from an
environment variable, for example `OFFICE_SECRET`.

## OpenCode REST API

The full contract is the OpenAPI document at `https://opencode.jz6gug4mclfe.opentunnel.xyz/doc`. Read it
before calling anything not listed here.

```bash
export OC=https://opencode.jz6gug4mclfe.opentunnel.xyz
curl -s -H "Authorization: Bearer $OFFICE_SECRET" $OC/session                 # list sessions
curl -s -H "Authorization: Bearer $OFFICE_SECRET" -X POST $OC/session \
     -H 'Content-Type: application/json' -d '{"title":"from an agent"}'      # create one; note its "id"
curl -s -H "Authorization: Bearer $OFFICE_SECRET" -X POST $OC/session/$ID/message \
     -H 'Content-Type: application/json' \
     -d '{"parts":[{"type":"text","text":"Summarise the README in ~/Code/example"}]}'
curl -sN -H "Authorization: Bearer $OFFICE_SECRET" $OC/event                  # server-sent events
```

OpenCode runs commands and edits files **on this Mac** as the `office` user.
Treat every prompt you send as code you are running on someone else's machine.

## Ollama

Native API (`/api/chat`, `/api/generate`, `/api/embed`, `/api/tags`, `/api/show`, `/api/ps`)
and the OpenAI-compatible API (`/v1/chat/completions`, `/v1/completions`,
`/v1/embeddings`, `/v1/models`).

```bash
curl -s -H "Authorization: Bearer $OFFICE_SECRET" https://ollama.jz6gug4mclfe.opentunnel.xyz/api/tags     # which models exist
curl -s https://ollama.jz6gug4mclfe.opentunnel.xyz/v1/chat/completions -H "Authorization: Bearer $OFFICE_SECRET" \
     -H 'Content-Type: application/json' \
     -d '{"model":"<model from /api/tags>","messages":[{"role":"user","content":"Hello"}],"stream":false}'
```

```python
from openai import OpenAI
client = OpenAI(base_url="https://ollama.jz6gug4mclfe.opentunnel.xyz/v1", api_key=os.environ["OFFICE_SECRET"])
```

Model management (`/api/pull`, `/api/push`, `/api/delete`, `/api/create`,
`/api/copy`, `/api/blobs`) is refused with `403` through this gateway. Ask the
operator for a model rather than working around that. The `ollama` CLI cannot
send the secret; use the HTTP API instead.

## Apps

Docker containers on this Mac (Rancher Desktop) can publish themselves as
`https://<name>.jz6gug4mclfe.opentunnel.xyz/`, behind the same login. The list of live apps is
JSON at `https://jz6gug4mclfe.opentunnel.xyz/apps` (send the secret):

```bash
curl -s -H "Authorization: Bearer $OFFICE_SECRET" https://jz6gug4mclfe.opentunnel.xyz/apps
# {"apps":[{"name":"grafana","url":"https://grafana.jz6gug4mclfe.opentunnel.xyz/",...}],"problems":[...],"docker":"ok ..."}
```

To add one, run a container on this Mac (for example through OpenCode) with:

| Label | Meaning |
| --- | --- |
| `ra.name=<name>` | Required. The subdomain: 1-32 of `a-z`, `0-9`, `-` |
| `ra.port=<port>` | The container port to expose (optional if only one is published) |
| `ra.description=<text>` | Optional, shown in the list |

and publish that port **on loopback only**: `-p 127.0.0.1::<port>`. A port
published on all interfaces is refused. It goes live within seconds; stopping
or removing the container takes it down. Reserved names: desktop, view,
opencode, ollama, apps, www, api, login, admin, mail.

```bash
ra-apps deploy hello traefik/whoami 80          # image, container port
ra-apps deploy mytool ./mytool 8080 -e KEY=val  # build a directory with a Dockerfile
ra-apps list                                    # live apps, and refused ones with the reason
ra-apps logs mytool
ra-apps rm mytool
```

```yaml
# Compose
services:
  mytool:
    build: .
    ports: ["127.0.0.1::8080"]
    labels:
      ra.name: mytool
      ra.port: "8080"
    restart: unless-stopped
```

Apps never see the shared secret: the gateway removes it (the `Authorization`
header and its login cookie) before forwarding. An app is always behind the
login; skipping it needs the operator to allow that name on the Mac.

## Rules for agents

- This is a shared machine. Others may be using the desktop, OpenCode and the
  models at the same time; keep requests reasonable and stream long outputs.
- The desktop routes are for people. Do not drive the screen through them.
- Do not try to reach other ports or services on this machine.
- Connections idle for 15 minutes are closed by the tunnel; reconnect.
