# Contributing

Thanks for your interest in contributing. Guisu is pre-1.0; expect breaking API changes in the library crates.

## Documentation

> \[!WARNING\] **Update docs in the same PR** Every PR that adds or changes a user-facing command, flag, config key, file-attribute convention, template function, or hook mode must update the relevant page under `docs/{user-guide,reference}/` in the same PR. The PR template (below) has a matching checklist.

Checklist before opening a PR:

- \[ \] If the PR adds a new subcommand, update [Reference — Commands](<https://yvanyo.github.io/guisu/reference/commands/index.md>) and add a "Common usage" example to the relevant user-guide page.
- \[ \] If the PR adds a template function or filter, update [Reference — Template Functions](<https://yvanyo.github.io/guisu/reference/template-functions/index.md>) with the function's name, signature, and a one-line description. Mark the row as a function or filter explicitly.
- \[ \] If the PR adds a config key, update [Reference — Configuration](<https://yvanyo.github.io/guisu/reference/configuration/index.md>) with type, default, and notes.
- \[ \] If the PR changes file-attribute behaviour, update [User Guide — File Attributes](<https://yvanyo.github.io/guisu/user-guide/file-attributes/index.md>).
- \[ \] If the PR changes hook semantics, update [User Guide — Hooks](<https://yvanyo.github.io/guisu/user-guide/hooks/index.md>).
- \[ \] If the PR changes the CLI global flags (`--source`, `--dest`, `--config`, `--log-file`, `--verbose`), update [Reference — Commands](<https://yvanyo.github.io/guisu/reference/commands/index.md>).
- \[ \] If the PR adds a new shell or installer integration (e.g. extending `guisu completion`), update [README — Shell completion](<https://github.com/YvanY0/guisu/blob/main/README.md#shell-completion>) with install instructions for the new shell.
- \[ \] If the PR fixes a user-visible bug that previously diverged between commands (e.g. `diff` and `apply` reporting different file sets, or non-deterministic output order), document the corrected behaviour in the relevant getting-started / user-guide page so users can trust the docs again. Bug-fix PRs are not exempt from the "update docs in the same PR" rule above.

The site is English-only. A Chinese translation is not in scope; if one is added later, it is a separate effort and tracked elsewhere.

## Development setup

```bash
git clone https://github.com/YvanY0/guisu.git
cd guisu
cargo build
cargo test --workspace
cargo clippy --workspace -- -D warnings
cargo fmt -- --check
```

Recommended tools:

- `pre-commit` (or `prek`) — see `.pre-commit-config.yaml`. Install once with `pre-commit install`.
- `nixfmt` — provided by the official NixOS/nixfmt hook in `.pre-commit-config.yaml` (skipped on pre-commit.ci, whose runner image lacks cabal). Locally the hook needs `cabal`/`ghc`; otherwise skip it with `SKIP=nixfmt git commit`.
- `cargo-shear` — installed by `rust.yml`; also runs locally via `cargo install cargo-shear --locked`.
- `cargo-llvm-cov` — installed by `rust.yml`; produces `lcov.info` for Codecov uploads.
- `cargo-dist` — installed by `release.yml`; `dist plan` / `dist build` simulate the release pipeline locally without pushing a tag.

## CI & local hooks

- `.github/workflows/rust.yml` runs `cargo fmt` / `check` / `clippy --all-features --locked` / `test --all-features` / `deny check` / `outdated` / `shear`. It auto-skips on PRs that don't touch Rust files. Cache uses `Swatinem/rust-cache@v2` with a `save-if` so PR forks don't write back to the shared cache namespace.
- `.github/workflows/zizmor.yml` audits every `.github/workflows/*.yml` for unsafe GH Actions patterns (unpinned actions, script-injection sinks, excessive permissions). It only runs when the workflow directory itself changes.
- `.pre-commit-config.yaml` runs lint hooks (nixfmt, taplo, betterleaks, typos, commitlint) on the `pre-commit` stage and cargo `fmt` / `clippy` / `check` / `test` / `deny` on the `pre-push` stage. Run from a terminal via `prek` or `pre-commit`.

## Signing commits

`git commit` must include both `-s` (DCO `Signed-off-by:`) and `-S` (GPG or SSH signature). Don't commit without them; don't bypass with `--no-gpg-sign`/`--no-verify`. If signing fails, stop and ask the user to commit for you.

Tip: in `~/.gitconfig`, set `[commit] gpgsign = true` and `signoff = true` so git injects `-s` and `-S` automatically on every commit.

## Pull request process

1. Branch from `main`. Use a short descriptive prefix: `feat/...`, `fix/...`, `docs/...`, `refactor/...`.
2. Commit with `-s` and `-S` (DCO + GPG/SSH signature). The repo enforces both — see [Signing commits](<#signing-commits>) above.
3. Run the build & verify commands above. They must all pass.
4. Open a PR with a clear title and a short description of the change. Reference any related issues.
5. Address review feedback. Squash-merge is preferred for a linear history.

## PR template

```markdown
## Description
Brief description of changes.

## Motivation
Why is this change needed?

## Changes
- List of changes
- Another change

## Documentation
- [ ] Updated the relevant docs page (which one: ...)
- [ ] No docs update needed (reason: ...)

## Testing
How was this tested?

## Checklist
- [ ] Tests added/updated
- [ ] `cargo fmt --all -- --check` passes
- [ ] `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings` passes
- [ ] `cargo test --workspace --all-features --locked` passes
- [ ] Commit signed (`-s -S`)
```

## Architecture guidelines

- Follow the existing layered architecture — see [Architecture](<https://yvanyo.github.io/guisu/developer-guide/architecture/index.md>). Lower layers never depend on higher layers.
- Use newtype paths (`AbsPath`, `RelPath`), not raw `PathBuf`.
- Use `?` with `.context(...)` in the CLI, not bare `unwrap()`. Library errors use `thiserror`; see [Error Handling](<https://yvanyo.github.io/guisu/developer-guide/error-handling/index.md>).
- For new template functions, follow the existing per-category layout in `crates/template/src/functions/`. One file per category; one function per `pub fn` with a doctest.
- For new vault providers, implement `SecretProvider` in `crates/vault/src/`. See [vault/AGENTS.md](<https://github.com/YvanY0/guisu/blob/main/crates/vault/AGENTS.md>) for the full checklist.

## Adding a new subcommand

1. Create `crates/cli/src/cmd/<name>.rs` with a `#[derive(Args)]` struct and a `Command` impl.
2. Add a variant to `Commands` in `crates/cli/src/lib.rs` with a docstring.
3. Add a row to [Reference — Commands](<https://yvanyo.github.io/guisu/reference/commands/index.md>).
4. Add tests under `crates/cli/src/cmd/<name>_test.rs` (or inline with `#[cfg(test)]`).

## See also

- [Architecture](<https://yvanyo.github.io/guisu/developer-guide/architecture/index.md>)
- [Three-State Model](<https://yvanyo.github.io/guisu/developer-guide/three-state-model/index.md>)
- [Crates](<https://yvanyo.github.io/guisu/developer-guide/crates/index.md>)
- [Error Handling](<https://yvanyo.github.io/guisu/developer-guide/error-handling/index.md>)
- [AGENTS.md](<https://github.com/YvanY0/guisu/blob/main/AGENTS.md>) — the project rules every agent follows.
