Metadata-Version: 2.4
Name: fridica
Version: 0.10.7
Classifier: Operating System :: MacOS
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Rust
License-File: LICENSE
Summary: Your Slack presence: a parent agent per person, a session per thread, and Claude Code / Codex workers on your machines
License-Expression: MIT
Requires-Python: >=3.11
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM

# Fridica

Fridica answers Slack threads as you and delegates work to Claude Code or Codex on your machines. One daemon represents one Slack account. Its local parent agent decides when to reply and what to delegate. Each thread keeps its own conversation, decisions and workers, so a follow-up can continue a job on the same machine.

## Set up tokens on macOS or Linux

Install Fridica in a Python 3.11+ virtual environment with `python -m pip install fridica`. As the OS user who will run the daemon, store the Slack tokens and any worker tokens you already have. The same commands use **Keychain on macOS** and **Secret Service on Linux**. On Linux, run them in a user D-Bus session with an unlocked keyring. Each command prompts for the token with input hidden.

| Credential | Store in the OS keyring | Environment variable |
| --- | --- | --- |
| Slack app | `fridica secret set slack/app-token` | `SLACK_APP_TOKEN` |
| Slack user | `fridica secret set slack/user-token` | `SLACK_USER_TOKEN` |
| GitHub daemon reader (optional) | `fridica secret set github/read-prs` | Uses existing `gh` credentials when no reader keyring entry is configured |
| GitHub worker MCP | `fridica secret set github/mcp-token` | `GH_TOKEN` or `GITHUB_TOKEN` |
| alphaXiv MCP | `fridica secret set alphaxiv/token` | `ALPHAXIV_TOKEN` |
| NASA ADS (SciX) MCP | `fridica secret set ads/token` | `ADS_TOKEN` |
| Overleaf MCP | `fridica secret set overleaf/git-token` | `OVERLEAF_GIT_TOKEN` |

Native Overleaf comments and pending Track Changes use one account login:

```sh
fridica overleaf-auth login --expected-email alice@example.com
```

Enter your credentials/MFA in the dedicated browser window. Later, `fridica
overleaf-auth login` reuses the saved account and valid session. Login needs no
project, channel, worker UUID or model client. Wheels built with this integration
include the native resources; Node >=20, Chrome/Chromium and an OS credential
store are still needed on the desktop. Install the same wheel and Node on each
registered worker. Fridica attaches native tools automatically to eligible
workers in allowed channels; no adapter path, manual recipient binding or Git
token is needed for native comments. Git/compile keeps its existing workflow.
Login enables Overleaf in the selected config; it does not start or reload a listener.

Supply the Overleaf editor link in the requesting Slack thread. Each admitted
manuscript job receives a grant for the confirmed project, and every native tool
call must name that same 24-character project ID. A later job can select a
different project using the same account login. Existing project, channel and
recipient restrictions still apply.

See [setup and optional source installation](docs/overleaf-native-source-install.md)
and [native operations and restrictions](integrations/overleaf/README.md).
Source installs require explicit resource preparation; built wheels need no
npm, Rust or manual resource copying. These instructions describe this source
version, not a claim that a new PyPI release has been published.

Slack automatically checks the standard environment variables first and then their keyring entries. You can delete the four standard Slack token assignments from an existing `[slack]` table. Keep any overrides that point to custom names.

To use an environment variable in Bash or Zsh, export it before running `fridica init` and supply it to the daemon at startup. For example, this prompts for an ADS token without putting its value in shell history:

```sh
export ADS_TOKEN="$(python3 -c 'import getpass; print(getpass.getpass("ADS token: "))')"
```

## Initialize Fridica

```sh
fridica init
```

On first setup, `init` enables each MCP with a nonblank environment token or a matching keyring entry. An existing local `gh` login also enables GitHub MCP. Discovery runs on the daemon machine and leaves workspace permissions intact. For credentials available only on an SSH worker, enable the corresponding MCP in `config.toml`. After configuring your workspaces, run `fridica doctor` to validate credentials on eligible workers. For Overleaf Git access, `OVERLEAF_PROJECT_ID` lets doctor check the Git token against one project. It is not a default target for native tools; native comments use the separate account login. With a native account scope, doctor checks installed tools without a Git token or session forwarding; live account validation waits for an admitted task.

For an isolated command-line installation, use `pipx install fridica` in place of the pip command. The wheel includes the native CLI and its credential helper. To install the version in this checkout, run `python -m pip install .` from the repository root with Rust 1.91 or newer.

`fridica init` creates four files under `~/.config/fridica/`:

| File | What to do with it |
| --- | --- |
| `config.toml` | Set the Slack identity, channels, backends and workspaces. |
| `manifest.yaml` | Import it when creating your Slack app. |
| `contract.md` | Customize how Fridica participates, replies and delegates. |
| `secrets.yml` | Use this optional mapping if your deployment uses Summon. |

For an existing installation with legacy state, stop the daemon, back up its configuration and database, and preview the migration with `fridica migrate --dry-run` before running `fridica migrate`.

### Prepare the machines

- **Daemon:** Install and sign in to the parent backend on this machine. The default is Claude Code. To use Codex, set `backend = "codex"` under `[parent]`.
- **Workers:** Install and sign in to every backend listed for that machine. Fridica's helpers use `/usr/bin/python3`. On SSH machines, the account must be reachable without a prompt, and the backend commands must be on its noninteractive `PATH`. Install Fridica there too when using the bundled GitHub, alphaXiv, ADS or Overleaf tools.

Backend installation guides: [Claude Code](https://code.claude.com/docs/en/setup) and [Codex CLI](https://developers.openai.com/codex/cli).

### Linux worker sandbox

Install `bubblewrap` on every Linux worker host, including Codex-only hosts. Install `socat` as well if the host runs Claude. Use `sudo apt install bubblewrap socat` on Debian or Ubuntu, or `sudo dnf install bubblewrap socat` on Fedora.

Run Fridica’s sandbox check on the worker host as the worker user. Success produces no output and exits with status 0.

```sh
bwrap --unshare-user --unshare-net --ro-bind / / --dev /dev --proc /proc --die-with-parent -- /bin/true
```

<details>
<summary>Ubuntu 24.04 and later: AppArmor blocks user namespaces</summary>

If the check fails with a UID map or loopback permission error, run these on the affected host:

```sh
command -v bwrap
sysctl kernel.apparmor_restrict_unprivileged_userns
```

If the path is `/usr/bin/bwrap` and the setting is `1`, check the AppArmor profile for that executable. If the profile is missing, create `/etc/apparmor.d/bwrap` with the following contents. Preserve any existing site-specific rules.

```text
abi <abi/4.0>,
include <tunables/global>

profile bwrap /usr/bin/bwrap flags=(unconfined) {
  userns,
  include if exists <local/bwrap>
}
```

Run `sudo systemctl reload apparmor` and repeat the sandbox check as the worker user. [AppArmor setup for bubblewrap](https://code.claude.com/docs/en/sandboxing#add-an-apparmor-profile-for-bubblewrap)

</details>

## Configure Slack

1. In [Slack app management](https://api.slack.com/apps), choose **Create New App → From an app manifest**, select your workspace and import the generated `manifest.yaml`. Use one app per owner. The manifest enables Socket Mode and subscribes to messages in public channels.
2. Under **Basic Information → App-Level Tokens**, generate an `xapp-` token with `connections:write`. For private channels, also add the `groups:read` and `groups:history` **user token scopes** and the `message.groups` **user event** before installing the app.
3. Under **OAuth & Permissions**, install the app to your workspace as the person Fridica will represent. Copy the `xoxp-` **User OAuth Token**. That account must belong to each channel you configure.
4. As the OS user who will run the daemon, run `fridica doctor` to see which tokens are available and whether Slack accepts them. You can run it before `fridica init`. The starter configuration automatically uses existing environment or keyring tokens. Store only missing tokens, then select your channels:

   ```sh
   fridica secret set slack/app-token
   fridica secret set slack/user-token
   fridica configure --detect
   ```

Detection reads your Slack identity and joined channels. For unattended setup, repeat `--channel-name NAME` with `--detect`. By default, **any member of a configured channel can request work on your machines**. Set `[slack].delegate_channels` to the channel IDs where you want to allow delegation. Fridica supports public and private channels. [Shipped Slack manifest](assets/slack-manifest.yaml)

If your installed CLI lacks the `secret` command, set `SLACK_APP_TOKEN` and `SLACK_USER_TOKEN` in your environment before running `fridica configure --detect`.

The generated configuration uses macOS Keychain or Linux Secret Service. On Linux, the daemon needs a user D-Bus session with an unlocked keyring. When using environment variables, supply them to the daemon process as well. They take precedence over stored entries. To rotate a stored token, repeat its `secret set` command and restart the daemon.

`fridica secret set slack/app-token` stores the token as a generic password in macOS Keychain or as a secret in the default Linux Secret Service collection (such as GNOME Keyring). Both use the current OS username as the account, `fridica:fridica/slack/app-token` as the service, and the token as the password. The entry has no website. Running `secret set` on an older Fridica entry moves it to this format.

`fridica secret get slack/app-token` writes the token to stdout. Both this command and the `fridica-secret` provider check the corresponding environment variable first for Slack credentials (`SLACK_APP_TOKEN` or `SLACK_USER_TOKEN`). For a custom token, use `fridica secret get example/api-token --env EXAMPLE_API_TOKEN`. If the variable is unset, Fridica reads the stored password.

### Copy stored credentials to another machine

macOS and Linux can each send or receive credentials. Install a version of Fridica with `secret copy` on both machines. The destination must accept SSH connections. The sender checks the remote PATH, then common user, Python environment and system install locations, including `~/pyenv/bin/fridica`. For a custom location, pass an absolute path from the source machine, for example `fridica secret copy --remote-bin /opt/fridica/bin/fridica user@linux-host`. Each Linux account involved needs a user D-Bus session with an unlocked Secret Service keyring. When sending to a Mac, enable Remote Login and make sure the SSH account can write to its unlocked Keychain.

#### Set up the Linux keyring

If the Linux machine needs a Secret Service provider, run the command for its distribution on that machine.

| Distribution | Install command |
| --- | --- |
| Red Hat Enterprise Linux 9 or 10 | `sudo dnf install gnome-keyring` |
| Ubuntu | `sudo apt update && sudo apt install gnome-keyring dbus-user-session` |

If Fridica is on the remote PATH, you can run this optional check from the source machine using the same SSH account you will use for the transfer.

```sh
ssh user@linux-host 'fridica secret copy --help && fridica secret list'
```

The first command verifies that SSH can find a compatible Fridica build. The second lists stored names and can succeed with an empty list on a new machine. If it reports a D-Bus error, check that the SSH account has an active user D-Bus session. If it reports a locked keyring, unlock that account's default keyring. An SSH key login can leave it locked on a headless server.

#### Transfer credentials

To copy from Linux to a Mac, run this command on Linux.

```sh
fridica secret copy user@mac-host
```

To send to Linux, run the same command from either macOS or Linux with the Linux destination.

```sh
fridica secret copy user@linux-host
```

With just a destination, Fridica copies all credentials it discovers from standard token environment variables and the source keyring. For each name, a nonempty exported token takes precedence over its keyring value. For GitHub MCP, the order is `GH_TOKEN`, then `GITHUB_TOKEN`, then the keyring. Custom keyring entries are included. If the source keyring is unavailable and exported tokens are present, Fridica reports the keyring issue and continues with the available tokens.

To select a subset, pass exact names or quoted patterns, for example `fridica secret copy user@linux-host 'slack/*' ads/token`. A star matches any sequence of characters in the name, including slashes. Every pattern must match at least one available name. Use `--from-env` to restrict the copy to exported tokens.

The command sends the selected values over SSH standard input. It replaces matching entries in the destination account's keyring and lists each copied credential name after the transfer succeeds. If a keyring write fails partway through, earlier writes may have succeeded. You can rerun the same command. When moving the daemon, run `fridica doctor` on the destination to check its credentials. If the destination only runs SSH workers, select just the worker credentials you need.

## Configure machines

Edit the existing tables in `config.toml`. Choose only the backends installed on each machine and point each workspace at an **existing directory**. The starter lists both Claude and Codex and uses `~/project` as a placeholder. For example, a local Codex installation with one checkout can use:

```toml
[parent]
backend = "codex"

[machines.local]
transport = "local"
backends = ["codex"]

[machines.local.workspaces]
project = { path = "~/repos/my-project", subfolders = false }
```

To add an SSH machine, give it a host alias and at least one workspace. Tags let the parent place a request such as “run this on a CUDA machine.”

```toml
[machines.gpu]
transport = "ssh"
host = "gpu-box"
backends = ["codex"]
tags = ["cuda"]
resources = { gpus = [0] }
max_jobs = 1

[machines.gpu.workspaces]
experiments = "/data/experiments"
```

The generated template documents machine limits, load-aware placement, GPU confinement and policy overrides. Use local or SSH transport for jobs. Slurm entries can be configured, but job execution is unimplemented. [Configuration template](src/config/template.toml)

### Workspaces and permissions

- Writable workspaces normally give each slot its own `worker1/`, `worker2/`, and so on. Set `subfolders = false` for a shared checkout. Jobs there can touch the same files. In managed slot directories, Fridica cleans old scratch files before reuse. Place `.fridica-keep` in a directory to preserve its subtree.
- The default worker mode is `write`. Set `[policy].mode` to `read-only`, `write` or `full` and override it per machine or workspace as needed. For Codex's ordinary sandbox, a nonempty `network` list enables general network access. GPU confinement uses the host network and bounds filesystem writes. Declared GPUs are assigned by job slot.
- `approvals = "auto"` uses the backend reviewer. Choose `on-request` for owner decisions on escalation, `untrusted` for more frequent prompts, or `never` to deny escalation. Pending requests appear in the dashboard and in `fridica approvals`.
- For scoped access to a public GitHub ref, configure `fetch_repos`, `network = []` and `approvals = "on-request"` on a writable workspace without GPU confinement. The worker receives a bare repository and the fetched commit SHA.
- To use an existing Python virtual environment for worker commands and MCP servers, set `python_env = "~/pyenv"` in the machine table. Fridica activates it on the execution machine.

## Run

```sh
fridica doctor
fridica start
```

`doctor` checks configuration, credentials, backend sign-in, workspaces and sandbox prerequisites. `start` runs in the foreground, verifies Slack access and begins answering threads. Use Ctrl-C to stop it.

| To do this | Run |
| --- | --- |
| Check startup prerequisites without connecting to Slack | `fridica start --check-ready` |
| Record Slack intake without calling models, starting workers or posting replies | `fridica start --observe-only` |
| Print a Linux systemd user unit for the configured daemon | `fridica service-print` |

## In Slack

From your configured Slack owner account, send `!f <instruction>` in a configured channel to start a thread, or reply with it to instruct an existing thread. For example, send `!f Use the project workspace to inspect <Overleaf project URL> and identify the main TeX file.`

Other channel members can mention the owner and ask for work in a named workspace. For the example workspace above, ask “Run the tests in the project workspace and summarize the failures.” Reply in the same thread to refine the request. The parent can reuse a worker, delegate to several machines, or ask for clarification. Set `[slack].general_messages = false` to turn off unsolicited participation in general conversation.

The parent reads thread history, selected text attachments and worker summaries. It can pass Slack files to a worker as read-only inputs. Workers report results, progress and requested artifacts back through the daemon. The Slack app needs `files:read` to download attachments and `files:write` to upload reports and figures.

Customize the owner's voice and delegation rules in `contract.md` beside the configuration. Keep the required `## Participation` and `## Replies` headings. Use `## Delegation` for parent instructions and `## Worker reports` for instructions given to workers. [Default contract](assets/contract.md)

## GitHub links

When a thread links a GitHub issue or pull request, the daemon reads up to three links per call through `gh api`. The parent receives the title, state and selected status lines. Pull requests also include the head commit, checks and reviews. Replies may repeat private repository information, so give the reader access only to repositories those channels may see.

The daemon can use its existing GitHub CLI credentials. A new configuration automatically selects an existing `github/read-prs` keyring entry. To add a dedicated read-only credential after initialization, run `fridica secret set github/read-prs` and enable the token line in the existing table:

```toml
[github]
enabled = true
token = "keyring://github/read-prs"
cache_seconds = 60
```

Fridica supplies the resolved secret to its `gh` process as `GH_TOKEN`. No interactive login is required. When upgrading an existing configuration, remove `token_env` from the top-level `[github]` table. Move any dedicated reader token to the keyring. Set `enabled = false` to disable these lookups.

## Worker integrations

**GitHub.** The bundled GitHub MCP server runs on eligible local and SSH workspaces with GitHub network access when enabled. Read-only workspaces expose read tools. Writable workspaces can also publish reviews, comments and task-branch changes. Enabling these tools authorizes their use without a second Fridica approval. GitHub enforces the worker credential's repository permissions and branch protections. Scoped-fetch placements receive no GitHub MCP server.

Authenticate as the worker's execution user with `gh auth login --hostname github.com`, or provide a worker `GH_TOKEN`. The daemon's dedicated GitHub reader secret stays with the daemon. Set `[github.mcp].enabled = false` to disable worker GitHub tools.

**alphaXiv.** Set `[alphaxiv].enabled = true`, allow `api.alphaxiv.org` in the workspace network policy, and provide `ALPHAXIV_TOKEN` to the daemon. On an authenticated worker, `fridica alphaxiv-mcp --probe` checks tool discovery without running a search.

**NASA ADS (SciX).** Set `[scix].enabled = true`, allow `api.adsabs.harvard.edu` in the workspace network policy, and provide `ADS_TOKEN`. Workers can search papers, export citations and manage ADS libraries. Because the bundled server includes library edits, Fridica attaches it to writable placements. Run `fridica scix-mcp --probe` on the worker to verify ADS accepts the token.

**Overleaf.** Set `[overleaf].enabled = true` and provide `OVERLEAF_GIT_TOKEN`. Use `network = ["*"]` because the server accepts general Git remotes. The default `write` mode confines Overleaf, Git and TeX writes to the assigned worker directory. The execution machine needs bubblewrap with user namespaces on Linux or the system sandbox on macOS. Install Git on the worker, plus TeX Live for compilation and PDF review. For Slack manuscript work, supply the project link or 24-character ID in the requesting thread. Fridica carries that selection into later jobs in the same thread and checks the Git destination before pushing. Standalone tools can use `OVERLEAF_PROJECT_ID` as their default. Citation checks use `ADS_TOKEN`. With the token in the worker environment, `fridica overleaf-mcp --probe` checks tool discovery and reads the default project’s Git references when a project ID is set.

Running `fridica doctor` checks each enabled research server on its eligible local and SSH workspaces. Its ADS check verifies authentication with a zero-result query. Its Overleaf check warns when a project ID is missing and verifies remote read access when one is supplied.

**Worker credentials.** Local workers inherit a filtered daemon environment. SSH workers receive integration credentials over encrypted SSH stdin, including variables such as `GH_TOKEN`, `ALPHAXIV_TOKEN` and `AWS_SECRET_ACCESS_KEY`, plus explicitly named MCP credentials. Forwarded values take precedence over target-local values. Fridica filters configured daemon secrets and Slack credentials before launching agents. [Credential forwarding rules](src/exec/credentials.rs)

## Dashboard and CLI

With the daemon running, open a second terminal and run `fridica dashboard`. Open the printed loopback URL on the same machine. The dashboard shows thread conversations, worker relationships and job history. You can send instructions, decide approvals and retry failed posts there.

![Dashboard showing a parent and three workers on two servers](docs/images/dashboard-demo.jpg)

| Task | Command |
| --- | --- |
| Check current activity | `fridica status`, `fridica threads`, `fridica workers`, `fridica machines` |
| Follow the event feed | `fridica events --follow` |
| List outstanding mentions | `fridica obligations` |
| Send a thread an instruction | `fridica instruct THREAD_ID "Run the tests again"` |
| Decide a pending approval | `fridica approvals ID once` (also `session` or `deny`) |
| Retry a failed parent decision | `fridica threads THREAD_ID retry` |
| Inspect failed or ambiguous posts | `fridica outbox` |
| Search archived threads | `fridica archive search "test failures"` |

The CLI and dashboard reach the daemon over its owner-only Unix socket. Use `fridica --help` for all commands. Local integrations can follow the event feed or drive a thread through the control API. [Events](docs/events.md) · [External drivers](docs/external-driver.md)

## State and recovery

Fridica stores messages, thread state, jobs and outgoing posts in SQLite. It records incoming Slack events before acknowledging them and commits each thread turn's effects together. After a restart, catch-up recovers missed messages and interrupted jobs are reported to their threads. Set `[limits].auto_resume = true` to rerun interrupted jobs once.

If delivery to Slack is uncertain, the post becomes `ambiguous`. Check the Slack thread before using `fridica outbox ID` to retry. Finished, quiet threads move to weekly archives beside the database after `state.archive_after_days` (default 7). A new message in an archived thread restores its history.

## Development

The daemon is written in Rust. Its Python distribution packages the executables with Maturin. From a source checkout, run:

```sh
cargo test --locked --all-targets
cargo test --locked --doc
python -m pip install -r requirements-dev.txt
python -m pytest -q
node --test tests/dashboard*.cjs
```

Build a wheel with `maturin build --release --locked --out dist`. The wheel smoke test exercises the installed command-line tools. [Wheel smoke test](scripts/smoke_wheel.sh) · [CI workflow](.github/workflows/ci.yml)

## License

[MIT](LICENSE)

The optional [scoped native Overleaf adapter](integrations/overleaf/README.md)
uses a separate pinned AGPL MCP process alongside Interleaf, with upstream login
and a narrow correction preventing ambiguous OT replay. See the integration
notes for owner setup, native comments, pending Track Changes and readiness limits.

