# Working with your team

Fleetlayer works for a team as well as for one person. This guide sets up the three things a team does together:
agents everyone can chat with, pages shared with a teammate, and tagging a teammate so a question reaches them.

You need the [sign-in service](https://fleetlayer.ai/docs/guides/sign-in.md) with your people in it (an invite each, or your company's Google Workspace or
other OpenID Connect provider), and a team for them:

```bash
fleetlayer-control team add engineering
fleetlayer-control team member engineering david
```

## Agents the whole team can chat with

A session on a machine your team owns is the team's: anyone the policy lets `attach` can chat with it from the
[dashboard](https://fleetlayer.ai/docs/dashboard.md) or [their phone](https://fleetlayer.ai/docs/guides/phone.md), and close, resume or stop it if you let them.

1. Make the machine the team's. Enrol its node with `--owner team:engineering`, or for one already enrolled:

   ```bash
   fleetlayer-control node owner team-server team:engineering
   ```

2. Let the team chat with its sessions, in the [access policy](https://fleetlayer.ai/docs/access-control.md):

   ```yaml
   allow:
     - who: team:engineering
       can: [read, attach]
       to: "*@team-server"
   ```

3. Start the session there as usual (`fleetlayer session start` on that node, or from the dashboard).

**The agent knows who is speaking.** On a machine that isn't the speaker's own, every message a person sends through
Fleetlayer starts with a line naming them: `From David (the Fleetlayer app): can you rerun the flaky spec?`. Nobody
can leave it out, so one teammate's words never pass for another's, and the agent's Fleetlayer skill tells it to treat
each message as that person's, with that person's authority. The phone and the dashboard show the name over the
message. On your own machine your messages go in as you typed them.

## Share a page with a teammate

The pages your agents write are private: a space is read by the person or team that owns it. To show one page to a
teammate, open it, choose **Share**, and add them under **People**. They sign in and see that page, and nothing else in
the space. With the Slack plugin set up ([below](#tell-people-by-slack)), the bot sends them a message with the
page's link; otherwise send them the address the pane shows.

- **Can ask this page's agent for changes.** Tick it, and they can chat with the agent that wrote the page, from the
  page's chat only, to ask for changes. It does the work with your agent's tools, so tick it for someone you'd let ask
  your agent for that. Their messages reach the agent named, as above.
- **Agents can share too:** `fleetlayer pages share <space>/<folder> --with david [--chat]`. Fleetlayer's default
  approvals ask you first. To let each person's own agents share that person's pages, and no one else's, add to the
  policy:

  ```yaml
  only:
    - who: "*"
      can: share
      to: [owner]
  ```

- **It ends** when you remove it, when its time runs out, when the page's folder is deleted, or as soon as you may no
  longer share the page. A rule about the person (a `deny`) always wins over a share.

[Sharing a page with people](https://fleetlayer.ai/docs/plugins/pages.md#sharing-a-page-with-people) has the details; for someone outside your
team, [share a link](https://fleetlayer.ai/docs/guides/pages.md) instead.

## Tag a teammate

In a page's chat, start a message with `@handle` to send it to that person instead of the agent: `@nathan can you check
this line?`. It stays in the page's chat, and the agent never sees it (its history shows that there was a message
between people, not what it said). Only someone who may read the page can be tagged; for anyone else the chat offers
**Share it with …**. A mention further into a message (`ask @nathan before merging`) goes to the agent as usual, and
tells Nathan too. An agent can tag its person in a reply when it needs them.

## Tell people by Slack

To have people told by a Slack direct message when they're tagged or a page is shared with them, set up the [Slack
plugin](https://fleetlayer.ai/docs/plugins/slack.md) and add, on its node:

```yaml
plugins:
  - name: slack
    command: fleetlayer-slack
    grants: [event.subscribe, event.subscribe.people, event.publish]
    config:
      tell_people: true
      # … the rest of its config
```

and a rule naming it in the policy, since these carry people's addresses and nothing else may hear them:

```yaml
allow:
  - who: plugin:slack@team-server
    can: subscribe
    to: channel:people
```

The bot finds each person by their Slack user in `people:`, or by the email address they signed in with (an app made
before v0.4.25 needs the scopes `im:write` and `users:read.email`). Each delivery shows in `fleetlayer events notices`,
so a notice nobody received doesn't go unnoticed. Email and phone notifications come later.

## What each person sees

- Each person reads their own pages and their teams' pages, and the pages shared with them, under **Shared with you**.
- Someone who may read a page but not ask its agent sees, in its chat, only what they wrote and what was addressed to
  them.
- Every share, every mention and every message typed into a session is in the control plane's audit log, with who did
  it.
