# Connection & bootstrap troubleshooting

Load this when a connect (bootstrap) run or an `awesomate_*` call is failing.
Wrong-account / profile / pin problems → `references/multi-account.md`.
No `awesomate_*` tools registered in the session at all →
`references/rest-fallback.md`.

## How the bootstrap runs

`scripts/bootstrap.mjs` is what the hub's Connect-Claude-Code prompt executes,
via `npx -y --package=@awesomate/hosting-mcp awesomate-hosting-bootstrap`.
Always the `--package=` form: a bare `-p` breaks the claude CLI's argv
pre-scan if the command is ever wrapped in `claude mcp add`. It redeems the
hub setup code for a scoped access token, stores it locally (chmod 600),
installs this skill into `~/.claude/skills`, registers the MCP server, and
(Support Plus+, best-effort) generates an SSH keypair and registers the public
key. If the SSH step fails (e.g. hosting not fully provisioned), the token +
skill + MCP are still set up.

## Reading the connect result

The bootstrap prints an `AWESOMATE CONNECT: SUCCESS account=<slug>` (or
`PARTIAL … issues=…` / `FAILED reason=…`) result line. When a connect ran as a
`!` bang command, look for that line instead of assuming success from
silence. It is the last line, and the line just before it is `Active Awesomate
account here: <slug> (why). Also saved on this computer: …`. A `--update`, which
has no result line, ends with that account line. `PARTIAL` means the token and pin are stored but a step (listed in
`issues=`) needs the printed manual fix. The issues added with Muse:

- `verify-hub`: the closing check could not read the account back from the hub
  with the saved key. Run `awesomate_whoami`; if it fails too, connect again.
- `muse-agents-md` (a warning, never in `issues=`): Muse was found but there is
  no `~/AGENTS.md` for the Awesomate rule. The connect never creates that file on
  its own: run it again with `--muse`. The run still ends `SUCCESS`.
- `muse-router`: the router skill (`~/workspace/custom-skills/awesomate/`) does
  not list every installed area skill. Run the connect or `--update` again.
- `muse-files`: the router, `skill.yaml` or the connector guide could not be
  written, or a connector guide that is there could not be read (it is then
  left as it is). The lines marked ✗ above name the file.
- `muse-no-skills`: no `awesomate-*` area skills were found to list.
- `verify-muse-router`, `verify-muse-connector`, `verify-muse-agents-md`: the
  closing check read the router, the connector guide or the `~/AGENTS.md` rule
  back from disk and did not find it. `verify-muse-agents-md` appears only when
  `~/AGENTS.md` exists but has no rule; a missing file is the warning above.

`--switch <slug>` ends with `AWESOMATE SWITCH: SUCCESS account=<slug>` (or
`PARTIAL`/`FAILED reason=…`), read the same way. `issues=overridden` means the
switch is written but `AWESOMATE_ACCOUNT`, `AWESOMATE_PAT` or a pin file still
chooses another account here; the line marked ! names which. On `--update`, every
Muse issue above fails the run (exit 1) except `muse-agents-md`, which is a
warning.

`FAILED reason=profile-belongs-to-someone-else` means this computer is already
connected to the same account as a different person (an owner and a team member
sharing a computer). Nothing was saved. Ask the person at the computer which key
should stay; re-run with `--replace` only on their clear yes, never on your own.
Otherwise they connect from their own user account on the computer. The key made
by the refused run is unused: they can remove it in the hub at Settings,
Account, Your Claude Code.

## Sandboxed / ephemeral environments (cloud agent containers)

- **Egress proxy**: if `HTTPS_PROXY`/`HTTP_PROXY` is set, the environment
  forces traffic through a proxy that Node's built-in fetch ignores, so requests
  bypass it and the gateway answers 403, which looks like a bad code/token but
  is a transport failure. The bootstrap and MCP server handle this themselves
  (undici env-proxy agent); if an older version is in play, prefix commands
  with `NODE_USE_ENV_PROXY=1`. Diagnostic: `curl` works but `node -e "fetch(…)"`
  403s → proxy bypass, not credentials.
- **Interrupted connect?** Setup codes are re-runnable for their whole
  10-minute life (each run mints a fresh token). After that, copy a fresh
  Connect command from the hub and run it; never put a token on a command
  line, where it lands in the chat and the shell history. Never tell the user
  their code is spent unless the API literally said so.
- **`ENOTEMPTY` from npx**: a half-written npx cache, not an Awesomate
  problem. Clear it with `rm -rf ~/.npm/_npx`, then run the same command
  again. The bootstrap can't catch this itself: npx fails before it starts.
- **Nothing persists**: `~/.awesomate`, the skill copy, and the MCP
  registration all vanish with the container. Treat a container connect as a
  diagnosis/test, and tell the user a real workstation is needed for a lasting
  install.
- **No ssh client**: containers usually lack `ssh-keygen`/`ssh`, so deploy and
  shell are unavailable; reads and management calls still work. The bootstrap
  skips SSH with a note rather than failing.
- Never probe connectivity with a POST to `/redeem`: it's state-changing. Use
  `GET {apiBase}/api/hosting-access/context` (401 without a token still proves
  reachability).

## When you're stuck: generate a support report

If a connect or tool failure survives the documented fixes (wrong account,
proxy, resume, restart, legacy registrations), don't keep guessing: hand
Awesomate a diagnostic they can act on:

1. Run `node ~/.claude/skills/awesomate-hosting/scripts/support-report.mjs
   --note "<one line: what the user was doing and what happened>"`.
   It writes a **fully redacted** report to
   `~/.awesomate/support-report-<timestamp>.md`, tokens reduced to
   prefix+last4, no key material, proxy credentials stripped. It includes
   versions, profiles/pin/registration state, live connectivity probes, and
   the last bootstrap log automatically.
2. Show the user the file path and the headline findings (the ACTIVE line,
   any ⚠ LEGACY registration flags, and the probe results).
3. **Ask the user before submitting.** With their OK, re-run with `--submit`
   (it POSTs the report to Awesomate and returns a reference like
   `ASR-XXXXXXXX`). Tell the user to quote that reference to
   support@awesomate.ai or their Awesomate contact; the report is already
   attached to it server-side. Submission works even when the token is
   broken (that's usually why you're here).
4. If `--submit` fails too (fully offline), the user emails the file itself:
   it's safe to send as-is.

Never edit the report to add raw tokens, codes, or keys, and never submit
without the user's explicit go-ahead.
