# {{FACTORY_NAME}}

A [jigs](https://salimhamed.github.io/jigs/) factory: workflows and the service that runs them.

## Start

```sh
pnpm install
cp .env.example .env && cp .env.local.example .env.local
pnpm exec jigs up
pnpm exec jigs run hello
```

`.env` holds values every copy of this factory shares; `.env.local` holds this
copy's own, such as its ports. See
[the environment](https://salimhamed.github.io/jigs/guide/configuration#env).

`jigs up` starts Postgres and the service and ends by running `jigs doctor`,
which checks only what this factory's workflows use. `hello` needs no
repository, ticket source, credentials or agent. Rerun `pnpm exec jigs doctor`
any time the service is up.
See [getting started](https://salimhamed.github.io/jigs/guide/getting-started).

Every `jigs` below means `pnpm exec jigs`. The service listens on
`JIGS_SERVICE_PORT`, its dashboard on `JIGS_DASHBOARD_PORT`, and Postgres on
`JIGS_POSTGRES_PORT`. `jigs status` lists runs; `jigs status <run-id>` shows one,
with the resources it recorded. All commands are in the
[CLI reference](https://salimhamed.github.io/jigs/guide/cli).
To run a second copy in a git worktree, see
[Developing in worktrees](https://salimhamed.github.io/jigs/guide/worktrees).

## Layout

- `jigs.config.ts` says what the factory is: its workflows, bindings,
  schedules and triggers, and its hub once it uses one. The environment says
  how this copy runs: its ports, database, hub token, secrets and which
  triggers and schedules are active.
- `workflows/hello/hello.ts` is the starter workflow. Each workflow gets its
  own directory, with any `"use step"` functions of its own beside it. A
  workflow file has a `"use workflow"` function and a default export made with
  `defineWorkflow({ inputs, workflow })`, plus `requires` when it needs
  integrations or agents.
- `jigs.config.test.ts` checks the registered workflows and compiled durable IDs.

Import the library from `@jigs-ai/jigs`, and the steps jigs provides from
`#jigs/steps`, with the routines that run them from `#jigs/routines`. The build
copies both into `.jigs/`, so their durable IDs are paths in this factory and
upgrading jigs never renames them. Import a workflow's own files with
relative paths; the workflow loaders in `jigs.config.ts` stay relative too.
The API reference is also installed at `node_modules/@jigs-ai/jigs/docs/api/`,
one Markdown page per import path.

## Recipes

```sh
pnpm exec jigs recipe list
pnpm exec jigs recipe add linear-ticket-to-pr
```

`recipe add` copies a recipe's workflow, tests and supporting code into this factory,
keeps any file that already exists, and registers the workflow under
`workflows` in `jigs.config.ts`. A recipe started by a trigger, such as
linear-ticket-to-pr, also prints the trigger to add to `triggers`. The copied
code is yours; upgrades never overwrite it. After adding linear-ticket-to-pr, read
`workflows/linear-ticket-to-pr/README.md`. See
[recipes](https://salimhamed.github.io/jigs/guide/recipes).

## Verify and upgrade

```sh
pnpm typecheck
pnpm exec jigs build
pnpm test
```

Tests read the last build, so build first. `jigs up` applies changes to a
running service. To upgrade jigs, set the new `@jigs-ai/jigs` version in
`package.json`, run `pnpm install`, then `pnpm exec jigs up`.

A workflow or step's file path and function name are its durable ID. Finish or
cancel active runs before renaming or moving either.
