# Contributing

Thanks for taking a look at `pi-file-viewer`.

## Setup

```bash
git clone https://github.com/elyor-sh/pi-file-viewer.git
cd pi-file-viewer
npm install
```

The package has no runtime dependencies. Pi supplies `@earendil-works/pi-coding-agent`
and `@earendil-works/pi-tui` at runtime; they are dev dependencies here, only for types and
tests.

## Run it locally

```bash
pi -e ./index.ts          # load the extension for one Pi run
pi --no-session --tui-mode fullscreen -e ./index.ts
```

Inside Pi, run `/view src/viewer.ts` and press `?` for the key map. `/reload` picks up
code changes without restarting the session.

## Checks

```bash
npm run typecheck   # tsc --noEmit
npm test            # node --test test/*.test.ts
```

Node 24 or newer is required for the test runner (it executes TypeScript directly). The
extension itself runs inside Pi, which loads TypeScript through jiti.

## Pull requests

- Keep the viewer dependency-free unless a dependency clearly earns its weight.
- Add tests for pure logic in `src/` (layout math, search columns, link resolution, layout
  mode selection). UI changes should include a short description of what you verified in a
  real terminal.
- Match the existing style: tabs for indentation, explicit return types on public helpers,
  no global mutable state.
- Update `README.md` and `CHANGELOG.md` when behavior or keybindings change.

## Releasing

The first publish is manual: npm only allows configuring a trusted publisher for a
package that already exists on the registry.

1. Bump `version` in `package.json` and add a `CHANGELOG.md` entry.
2. Run `npm run typecheck && npm test` (the `prepublishOnly` script repeats both).
3. Enable 2FA on your npm account (Account settings → Two-Factor Authentication). The
   registry requires it for publishing and npm does not prompt without it. Then, for the
   first release only: `npm login`, then `npm publish`, and enter the OTP when asked.
   Known registry issue: granular tokens with "bypass 2FA" can still return 403
   ([npm/cli#9268](https://github.com/npm/cli/issues/9268)), so enabling 2FA is the
   reliable path.
4. Enable trusted publishing for CI. On npmjs.com open the package, then **Settings →
   Trusted publishing → GitHub Actions** and enter repository `elyor-sh/pi-file-viewer`
   and workflow `publish.yml`. The CLI equivalent needs npm 11.15+, the package to
   exist, and account-level 2FA:

   ```bash
   npm trust github pi-file-viewer \
     --repo elyor-sh/pi-file-viewer \
     --file publish.yml \
     --allow-publish
   ```

5. Subsequent releases: publish a GitHub release. `.github/workflows/publish.yml` runs
   the checks and publishes with OIDC and provenance. The job requires npm 11.5+ (Node
   24 ships it) and no `NPM_TOKEN` secret once trusted publishing is configured.

The workflow keeps an optional `NPM_TOKEN` bootstrap path for the very first CI publish
before a trusted publisher exists. If you use it, create an npm **Automation** token that is
scoped to `pi-file-viewer`, set a short expiry, store it as the `NPM_TOKEN` secret, and
revoke it after configuring trusted publishing.

Do not commit `.npmrc` or tokens. `publishConfig.access` is `public`; the `pi-package`
keyword makes the package eligible for the Pi package gallery.

## License

By contributing, you agree that your contributions are licensed under the MIT License.
