# support — Get human help (file and track a support ticket)

Escalate to Shiplight's human support without leaving the agent: draft a
diagnostic ticket from what this session already knows, get the user's approval,
submit it, and read replies later. Support replies also arrive by email; this
subcommand is how the user files and checks from here.

Sub-verbs (match from context; default is filing):

- *(default)* — file a ticket
- `status [SUP-…]` — list the caller's accessible tickets, or show one ticket's thread
- `reply SUP-… <message>` — answer support on an open ticket
- `close SUP-…` — close a ticket

## Read first

- `_shared/secrets.md` — a ticket is outbound content; no raw secrets in it, ever.

## Setup

Same API, token and rules as `cloud`. Take `SHIPLIGHT_API_URL`,
`SHIPLIGHT_API_TOKEN` and `SHIPLIGHT_WEB_URL` from the environment, then from the
test project's `.env`. There is no default host. If `SHIPLIGHT_API_URL` is in
neither, stop and ask the user for their backend's URL; never guess one. Ask the
same way for `SHIPLIGHT_WEB_URL` before you show a link that needs it. With the
user's OK, add what they give you to `.env`.
Shiplight's public service is `https://api.shiplight.ai` (web app `https://app.shiplight.ai`); use it only when the user says it is their backend.

Run this from the test project root, in the shell that runs the calls below.
It reads those keys from `.env` as text. Don't `source` `.env`: that runs the
file as shell code, and it replaces values the shell already has. As a backstop,
it also refuses to send a token without the `shp_` prefix to a `shiplight.ai`
host. The prefix never picks the host.

```bash
dotenv_value() { # value of key $1 in .env; reads the file, never runs it
  [ -f .env ] || return 0
  sed -nE "s/^[[:space:]]*(export[[:space:]]+)?$1[[:space:]]*=//p" .env | tail -n 1 |
    tr -d "\"'\r" | sed -E 's/^[[:space:]]+//; s/[[:space:]].*//'
}
url_host() { # host of URL $1, lowercased, without user, port or trailing dot
  printf '%s\n' "$1" | LC_ALL=C tr '[:upper:]' '[:lower:]' |
    LC_ALL=C sed -E 's|^[a-z][a-z0-9+.-]*://||; s|[/?#].*||; s|.*@||; s|:[0-9]*$||; s|\.+$||'
}
export SHIPLIGHT_API_URL="${SHIPLIGHT_API_URL:-$(dotenv_value SHIPLIGHT_API_URL)}"
SHIPLIGHT_API_TOKEN="${SHIPLIGHT_API_TOKEN:-$(dotenv_value SHIPLIGHT_API_TOKEN)}"
SHIPLIGHT_WEB_URL="${SHIPLIGHT_WEB_URL:-$(dotenv_value SHIPLIGHT_WEB_URL)}"
case "$(url_host "$SHIPLIGHT_API_URL")" in # no default host; only shp_ tokens go to shiplight.ai
  "") echo "SHIPLIGHT_API_URL is not set: stop and ask for the backend URL" >&2; false ;;
  shiplight.ai | *.shiplight.ai)
    case "$SHIPLIGHT_API_TOKEN" in
      "" | shp_*) ;;
      *) unset SHIPLIGHT_API_TOKEN
        echo "Not sending a non-shp_ token to $SHIPLIGHT_API_URL: stop and ask" >&2; false ;;
    esac ;;
esac
```

All calls send `Authorization: Bearer $SHIPLIGHT_API_TOKEN`. If no token is
available, offer to run `npx shiplight setup-api-token` from the test project
root and get approval first because it writes `.env`. The command authenticates
with Shiplight in the browser and owns that write; it does not persist the browser
device-auth session. There is no CLI logout command. Remove the token from `.env`
to stop using it in that project, or revoke it at
`$SHIPLIGHT_WEB_URL/api-tokens` to invalidate it everywhere.

## Filing flow (default)

1. **Self-triage.** Check the stuck state against known failure modes before
   escalating — many "stuck" cases have an in-skill fix:

   | Symptom | Known fix |
   |---------|-----------|
   | Project CLI missing | Use the launcher’s `info` from the project root to restore and check the declared CLI |
   | installed CLI behind latest | `/shiplight update` |
   | login redirect / expired session in a test or verify run | `/shiplight setup-test-auth` |

   Offer the fix if one matches. If the user still wants a human — or nothing
   matches — continue to filing; self-triage never blocks escalation. Record
   what was checked as `doctorChecks` in the diagnostics.

2. **Gather diagnostics** from evidence already in the session plus these cheap
   reads (do not launch new analysis — no fresh browser sessions or test runs):

   - `subcommand` — the `/shiplight` command that was running, if any
   - `errorOutput` — the exact failing output, trimmed to the relevant tail
   - `cliVersion` / `latestCliVersion` — the `version` field of
     the launcher’s `info` and `latest` (collect only; a stale CLI never blocks
     filing)
   - `skillTimestamp` — contents of `.shiplight-agent-skills-last-update`
   - `os` (`uname -sr`), `nodeVersion` (`node -v`)
   - `doctorChecks` — the self-triage results from step 1

   In a Bun project, read the latest version with its Bun form in
   `_shared/package-manager.md`, the launcher’s `latest` command. Omit `nodeVersion`, and name the Bun version
   (`bun --version`) in the ticket `body`, where it says what the user was
   running. The self-triage install fix is `bun install`, and the token command is
   `bun run --bun shiplight setup-api-token`.

3. **Draft the ticket.**

   - `subject` — one line, ≤ 200 chars
   - `body` — markdown: what the user was doing, what happened, what was
     already tried. Written for a human who has not seen this session.
   - `category` — `bug` (Shiplight misbehaved) · `question` (how do I…) ·
     `feature_request` · `billing` · `other`
   - `severity` — `blocking` (Shiplight work cannot proceed) · `degraded`
     (workaround exists) · `minor` (default)
   - `source` — always `skill`

   Scrub the body and diagnostics before showing them: replace anything
   secret-shaped (bearer strings, `sk-`/`ghp_` tokens, AWS keys, values known
   to come from `.env`) with `[redacted]`.

4. **Get approval.** Show the full draft — subject, body, category, severity,
   and the diagnostics verbatim — and state that everything shown goes to
   Shiplight support. Submit only on an explicit yes; apply any edits the user
   asks for first. Never auto-submit.

5. **Submit.**

   ```bash
   curl -X POST -H "Authorization: Bearer $SHIPLIGHT_API_TOKEN" \
     -H "Content-Type: application/json" \
     -d @ticket.json "$SHIPLIGHT_API_URL/v1/support-tickets"
   ```

   Body: `{ subject, body, category, severity, source, diagnostics }`
   (plus `contactEmail` when the API asks for it — see errors). Size caps:
   `body` ≤ 64 KB, `diagnostics` ≤ 128 KB.

   Response `201`: `{ id, ticketNumber, status, createdAt, redactions }`.

6. **Report.** Give the ticket number, note that an acknowledgment email went
   to the user's account address and replies arrive by email, and that
   `/shiplight support status SUP-…` checks from here. If `redactions > 0`,
   say the server scrubbed additional secret-shaped content.

## Status / reply / close

```bash
# List tickets (filter: ?status=open|waiting_on_user|resolved|closed)
# Access is per-caller: a ticket's designated contacts (active org members), or
# the filing token for token-only callers — not the whole org.
curl -H "Authorization: Bearer $SHIPLIGHT_API_TOKEN" \
  "$SHIPLIGHT_API_URL/v1/support-tickets"

# One ticket with its full message thread
curl -H "Authorization: Bearer $SHIPLIGHT_API_TOKEN" \
  "$SHIPLIGHT_API_URL/v1/support-tickets/<id>"

# Reply (also moves the ticket back to support's queue)
curl -X POST -H "Authorization: Bearer $SHIPLIGHT_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"body": "<message>"}' "$SHIPLIGHT_API_URL/v1/support-tickets/<id>/messages"

# Close
curl -X PATCH -H "Authorization: Bearer $SHIPLIGHT_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"status": "closed"}' "$SHIPLIGHT_API_URL/v1/support-tickets/<id>"
```

`status` with no ticket number: list, newest first, as
`SUP-… · status · subject · last activity`. With a number: show the thread and
whether the ball is with support (`open`) or the user (`waiting_on_user`).
Replies go through the same approval rule as filing: show the message, send on
yes.

Statuses: `open` (support's court) → `waiting_on_user` → `resolved` → `closed`.

## Error handling

| Status | Action |
|--------|--------|
| 400 mentioning `contactEmail` | The token has no account attached — ask the user for a contact email, add `contactEmail`, resubmit. |
| 401 | Token missing/invalid — fix Setup, retry. If the token itself is what's broken, fall back to emailing support directly and say so. |
| 413 | Payload over the cap — trim `errorOutput`/`diagnostics` deliberately (keep the failure tail), resubmit. Never silently drop the body text. |
| 429 | Daily ticket limit reached — relay the API's message; the existing ticket thread (`reply`) is not rate-limited the same way, so add to it instead of filing duplicates. |
