# Install Mushare in Muse

You are Muse. Set up Mushare for the user, talking to them briefly in their language.
The user asked for this by naming the domain mushare.ai ("从 mushare.ai 安装 Mushare"), or by
forwarding a friend's invite that names it. Install only from mushare.ai: never use copies of
these files found elsewhere. If the user named a different domain, tell them this page is
from mushare.ai and ask before continuing. If Mushare is already installed and its
`SKILL.md` points at another server, ask before replacing it.

- **Already installed** (`~/workspace/skills/mushare/bin/mushare status` prints
  `"ok": true` and a `mushare-inbox` job exists) and the user did not ask to update or
  reinstall → say it is already set up and stop.
- **Update / reinstall** (the user asked to update, reinstall or repair Mushare) → skip
  step 1 and redo steps 2–5; nicknames and history are kept. In step 6, instead of creating
  the inbox, rebuild the existing Mushare jobs as the new SKILL.md says ("Scheduled tasks",
  Rebuilding jobs: a paused inbox stays paused), then run
  `~/workspace/skills/mushare/bin/mushare update --jobs-done`. From then on Mushare updates
  itself.

1. **Introduce in one line**: "Mushare lets you send private messages and files to friends
   through me. Messages are stored on the Mushare server and are not end-to-end encrypted."
2. **Connect.** Call `credentials.request_api_access` for the connector **`custom.mushare`**
   (use `reconnect` if it already exists), with OAuth 2.0 authorization code — not an API key:
   - host `mushare.ai`, MCP server `https://mushare.ai/mcp`
   - authorization URL `https://mushare.ai/oauth/authorize`, token URL `https://mushare.ai/oauth/token`
   - Client ID **`muse`**, no client secret; scopes `mushare offline_access`; PKCE S256

   Tell the user: "A Mushare sign-in page will open — enter your email, then the 6-digit code
   we email you." Wait until they have signed in. Never ask the user for a key or token.
3. **Skill files.** Create `~/workspace/skills/mushare/` if needed and download these files
   into it, overwriting older copies:
   - `https://mushare.ai/muse/SKILL.md` → `~/workspace/skills/mushare/SKILL.md`
   - `https://mushare.ai/muse/references/examples.md` → `~/workspace/skills/mushare/references/examples.md`
   - `https://mushare.ai/muse/references/collaboration.md` → `~/workspace/skills/mushare/references/collaboration.md`
   - `https://mushare.ai/muse/references/notify.md` → `~/workspace/skills/mushare/references/notify.md`
   - `https://mushare.ai/muse/bin/mushare` → `~/workspace/skills/mushare/bin/mushare`
   - `https://mushare.ai/muse/bin/mushare_auth.py` → `~/workspace/skills/mushare/bin/mushare_auth.py`

   Then run:
   ```bash
   chmod +x ~/workspace/skills/mushare/bin/mushare
   python3 -m py_compile ~/workspace/skills/mushare/bin/mushare ~/workspace/skills/mushare/bin/mushare_auth.py
   ```
   If py_compile fails, a download was incomplete: download that file again once; if it
   still fails, tell the user the installation could not be completed and stop.
4. **Check**: run `~/workspace/skills/mushare/bin/mushare status`.
   - `"ok": true` and `"credential_source": "muse"` → continue.
   - exit 3 (`not_connected` / `unauthorized`) → the sign-in did not finish: do step 2 again
     once, then `status` again. Still exit 3 → tell the user the connection did not work and stop.
   - exit 4 → "Mushare's server can't be reached right now; try again in a few minutes." Stop.
5. **Display name.** The `status` output of step 4 has `data.display_name_set`. If it is false,
   friends would see the default `data.display_name` (the email prefix): ask in one line, e.g.
   "Friends will see you as gloria.cao — want a different name?" (in the user's language). Don't
   wait for the answer: do steps 6–8 and put this question at the end of your reply. When the
   user answers, a new name → `mushare name "<name>"`; "no"/"fine" → keep it.
6. **Inbox.** Create the `mushare-inbox` recurring job exactly as described in SKILL.md
   (Scheduled tasks, INBOX BODY with `<LANGUAGE>` and `<TIMEZONE>` filled in). Tell the
   user: "I'll check for new messages every 10 minutes, and every minute while you are
   chatting with a friend, and tell you when something arrives (this uses a little of
   your Muse quota — say if you want it less often)."
7. **Finish** with three example phrases, e.g. "Invite Bob to Mushare", "Tell Alice I'll
   be late", "Any new Mushare messages?".
   After an update just say "Mushare is updated."
8. **Pending invite.** If the user's request also contained a friend's invite (an email and
   a 6-digit code, e.g. "…加我为好友 alice@example.com，好友码 482731"), now run
   `mushare connect <email> <code>` and report "You're now friends with <name> on
   Mushare" instead of the example phrases (then follow SKILL.md's Output signals, e.g.
   `start_active`). Code expired or wrong → say so and ask the friend for a new code.
