# Source

## Source: connect the code Cofactor will build and test

Check first: `cofactor setup status --json`. If `progress.sourceConnected` is true, skip to `first-sandbox`.

Ask the human, one question: "Should Cofactor build from your GitHub repository, or will you push a built image?" If the repository is on GitHub, recommend GitHub.

### GitHub

The human needs to be an organization admin (the account that signed up is). One browser step, GitHub's approval:

```bash
cofactor github connect
```

It opens Settings -> GitHub through a single-use signed-in link (5 minutes) and waits until the connection validates. On a headless machine, or with `--no-open`, it prints the link: give it to the human, and keep it private. Ask: "Open this link and approve the installation on GitHub."

Already connected: it prints the installation straight away.

If the link expired, run the command again for a new one.

### Image (no GitHub)

Read `cofactor sandbox guide upload`, then push the built image in the next step (`first-sandbox`), once its plan is approved (the `first-sandbox` plan records the choice made here). Do not create an API key or write secrets into files.

An image push needs three things, so check them now and put them in the plan:

- Docker with buildx: `docker buildx version` prints a version. If it does not, tell the human what to install.
- The build context: the directory holding the Dockerfile (normally the repository root), with `cofactor.sandbox.yaml` at the image's WORKDIR (`COPY . .` puts it there).
- The exact build command, for `linux/amd64` whatever the machine is:

  ```bash
  docker buildx build --platform linux/amd64 -t <name>:sandbox --load <context>
  ```

Re-read:

```bash
cofactor setup status --json
```

GitHub: `progress.sourceConnected` becomes true once connected. Image: a ready or upgraded upload counts as Source connected, so it becomes true after the push.

Do not ask for a GitHub token or password.

What local Docker may and may not do:

- Image: the one `docker buildx build` above, to produce the image, then `cofactor sandbox push`. Both wait for the approved plan.
- Image: do not run the app in containers (`docker run`, compose) to test the definition before pushing. The claim is the test. `cofactor sandbox guide upload`, "Troubleshooting", names the few `docker run` checks for after a push or claim has failed.
- GitHub: no local Docker at all. Do not build or run the app locally; the sandbox is built from the definition, and a local build proves nothing about it.

Next: `cofactor setup guide first-sandbox`
