# Development

---

# Running Acta Locally

_Acta / Development_

> Build Acta with pekit's pinned toolchains and run a development server on port 8081.

The development setup runs a Go server with embedded web assets and a separate
PostgreSQL database. [pekit](https://learn.peios.org/pekit/) supplies the Go
and frontend toolchains.

## Before you start

Use an x86_64 Linux build host with these prerequisites:

- pekit, with bubblewrap 0.11 or later
- Python 3, curl, OpenSSL, and Git
- A C compiler for the race-detector integration tests
- Docker and Docker Compose for the supplied development database
- Network access for the first dependency fetch

The build pins Go 1.26.8 and Node 22.22.1 with npm 10.9.4, and `pekit.lock`
pins the gcslib libraries that provide them. Host Go, Node, and npm
installations are not required. Each build step runs in a sandbox that holds
only its declared inputs.

## Start the application

1. From the repository root, run `tools/db`.
2. Run `tools/run`.
3. Open [the local Acta server](http://localhost:8081).
4. For an empty installation, use the setup code printed in the server
  terminal to create its first administrator. Keep that terminal private.
5. Sign in and check that the application loads.

The development database listens on `127.0.0.1:5433` and keeps a persistent
named volume. Its credentials are development-only. The server runs on port
8081; keep this port for interactive review. Starting the server applies
embedded migrations. Stopping it with <kbd>Ctrl</kbd>+<kbd>C</kbd> leaves
PostgreSQL running.

`tools/run` builds the programs into `bin/`. It supplies the development
database URL and permits the local Vite origin. Override `ACTA_DATABASE_URL`
or `ACTA_DEV_ORIGIN` when using another setup. The server executable itself
requires a database URL and has no default password.

## Use frontend hot reload

Keep the Go server running, then run `tools/dev` in another terminal.
Open [the Vite development server](http://localhost:5173) using that hostname.
Vite proxies API and WebSocket requests to Go. Restart Go after backend
changes.

This command installs locked dependencies in `web/node_modules` using the
pinned Node.js. Ordinary builds and tests run in pekit's sandboxes and keep
generated frontend output out of the checkout.

## Preserve development data

Stopping Compose preserves its database volume. Removing the volume deletes
Acta data; it is not an upgrade procedure. Test fixtures use isolated schemas
and do not initialize the operator's development account.

---

# Building and Checking Acta

_Acta / Development_

> Run builds, formatting, frontend checks, and database integration tests with pekit.

[pekit](https://learn.peios.org/pekit/) tracks Go packages, generated frontend
assets, embedded migrations, and documentation inputs. Use it for builds so
the server cannot embed stale assets from a previous checkout build.

## Build and check

From the repository root, run the checks needed for the change:

```sh
pekit build programs
pekit build frontend
tools/export
pekit test
pekit run style
```

`tools/check` runs the style check and then the tests. The `programs` target
holds `acta-server`, `acta`, `acta-backup`, and `acta-update`; pekit prints
where it is, under `pekit-out/`. `tools/export` copies them to `bin/`. Set
`ACTA_OUTPUT_DIR` to choose another destination. The `frontend` target holds
the built web assets.

The test suite includes Go unit tests, standard Go vet checks, the Go race
detector, Go formatting, frontend formatting, ESLint, Svelte/TypeScript
checks, Node interaction tests, and the application entrypoint regression
test. Each test runs in a sandbox without network access. A test whose inputs
did not change is found in pekit's store and not run again.
Database-backed cases skip without their database configuration. Browser
workflows remain explicit checks; a passing default suite does not establish
browser coverage.

GitHub runs the style check, the tests, and the build on every push and pull
request. A second job runs the database integration tests against a
PostgreSQL service.

## Follow Peios coding style

Acta follows
[Peios coding style](https://learn.peios.org/psc/common-coding-rules/scope-and-precedence/).
Go uses `gofmt`. The frontend uses four spaces, a 100-column formatting
target, double quotes, and semicolons. Svelte-aware lint checks preserve the
semantics of reactive props and derived values. Braces follow the common Peios
rule; short single-line clauses can omit them.

`pekit run style` checks maintained Python and shell sources with pinned Ruff,
shfmt, and ShellCheck. It also checks maintained JSON, YAML, and web manifests
with the frontend's pinned Prettier. The repository formatter settings are
shared with the frontend; npm's generated lockfile is excluded. Keep workflow
Python in `scripts/` to include it in these checks. The `gofmt` test checks
Go. Frontend formatting and lint run as part of `pekit test`. With the locked
frontend dependencies installed, `npm run format` in `web/` applies frontend
formatting and `npm run lint` checks the result.

These checks do not enforce hard function-length or complexity limits. Review
names, units, error handling, ownership, import initialization order, and
functions beyond the Peios soft thresholds separately. Preserve published
field names and protocol contracts during style changes.

Generated outputs and dependencies are outside the style rewrite scope. Do not
reformat applied SQL migrations: Acta verifies their checksums on startup.

## Test database behavior

Use an expendable database and a role allowed to create schemas. With the
supplied development database running, execute:

```sh
ACTA_TEST_DATABASE_URL='postgres://acta:acta-development-only@127.0.0.1:5433/acta?sslmode=disable' pekit run integration
```

The integration command refuses a missing database URL and runs every
package's tests with the Go race detector, outside pekit's sandboxes, so that
they reach the database. It runs them every time. Each test creates a randomly
named schema, applies migrations, exercises real transactions, and drops its
own schema. It does not wipe the database's `public` schema.

Backup recovery, update recovery, and device passkeys need their own
qualification. Do not infer those results from ordinary unit tests.

## Check the result

Inspect failures and skipped cases, including which database configuration was
used. Record the tests actually run on the work's Acta task. Keep local
validation, remote CI, release publication, and deployment as separate claims.

---

# Maintaining Build Inputs

_Acta / Development_

> Update Go modules, locked frontend dependencies, pinned toolchains, and versioned exports.

Dependency and toolchain changes update both the declared inputs and the files
that lock their resolution. Build actions do not install dependencies.

## Update Go modules

1. Change the Go source or dependency declarations.
2. Run `go mod tidy` to update `go.mod` and `go.sum`.
3. Run `pekit run pin_modules` to write `go.pins` again.
4. Review the changes to `go.sum` and `go.pins` together, then run relevant
  checks.

pekit plans each package's build from the Go sources, so new packages and
imports need no build file changes. A new package with tests joins the test
suite through `test_packages` in `build.gcsl`.

## Update frontend dependencies

1. Update `web/package.json` and `web/package-lock.json` together.
2. Run `pekit run pin_packages` to write `web/npm.pins` again.
3. Review the changes to the lockfile and the pins together.

The pins record the SHA-256 of each package tarball. pekit fetches each
tarball by its pin and checks it against the lockfile's integrity. Package
install scripts never run; verify that a changed dependency does not require
an unprovided lifecycle step.

Toolchain pins live in the gcslib libraries that `workspace.gcsl` imports.
`pekit.lock` pins those libraries' commits. Run `pekit lock` to update them.

## Export a versioned build

For a build labeled `0.1.0`, run:

```sh
printf '0.1.0\n' > build/release-version
tools/export
```

The version reaches the Go executables and the frontend's `package.json`.
Without `build/release-version`, both report `0.0.0`. Every build is pure
Go, with CGO off, so the executables are static. The container images copy
the programs from `bin/`, so run `tools/export` before a Docker build. A
versioned build does not sign, publish, or deploy a release.

The frontend's version is a hash of its sources, so two builds of the same
sources produce the same assets.

## Maintain documentation

Edit the Trail product in
`docs/learn/site/2--developer-tools.shelf/acta.product`. Keep user concepts
and procedures in topics and implementation details in the technical manual.
The agent guide is embedded from its canonical Learn file. Changes to those
files also change the application inputs.

Run the documentation checks from the repository root:

```sh
trail lint docs/learn/site
trail build docs/learn/site --strict
```

Use a Trail build with attachment support. Inspect the rendered pages and
links as well as the diagnostics. Historical documentation remains available
in Git history.
Work-specific validation and decisions belong on the corresponding Acta task.
