# Phase 0 — Agent-Ready Trigger Rules

Events are accepted only when they match these rules. Adjust labels/statuses to match the client Jira workflow.

## Qualifying events

- `jira:issue_created`
- `jira:issue_updated` (status or label change that newly qualifies the issue)
- `comment_created` (to **resume** a run in `NEEDS_CLARIFICATION` or `DESIGN_REVIEW`)

## Start a new run when all are true

1. Issue project is in `JIRA_PROJECT_KEYS` (default: `SALES`).
2. Issue has label `agent-nova` **or** status name equals `Ready for Agent`.
3. Issue type is `Story` or `Task` (configurable).
4. No other **active** run exists for the same Jira key (one active workflow per issue).

## Resume (clarification) when all are true

1. Existing run for the issue is in `NEEDS_CLARIFICATION`.
2. Event is `comment_created` on that issue.
3. Comment is not authored by the Agent Nova bot account.
4. Comment body is non-empty.

## Resume (duplicate review) when all are true

1. Existing run for the issue is in `DUPLICATE_REVIEW`.
2. Event is `comment_created` on that issue.
3. Comment is not authored by the Agent Nova bot account.
4. Comment body contains `continue` (proceed) **or** `duplicate` / `close as duplicate` (stop).

## Resume (Confluence doc review) when all are true

1. Existing run for the issue is in `DOC_REVIEW`.
2. Event is `comment_created` on that issue.
3. Comment is not authored by the Agent Nova bot account.
4. Comment body contains `continue` (proceed anyway) **or** `already done` / `close` (stop).

## Resume (design review) when all are true

1. Existing run for the issue is in `DESIGN_REVIEW`.
2. Event is `comment_created` on that issue.
3. Comment is not authored by the Agent Nova bot account.
4. Comment body is non-empty and is not the bot's design-review post.
5. Comment starting with `reject` / `rejected` asks for clarification (moves to `NEEDS_CLARIFICATION`); after the human replies, Agent Nova regenerates the design and pauses in `DESIGN_REVIEW` again. Any other human comment **approves** and moves to `IMPLEMENTING`.

## Ignore

- Issues without the agent-ready label/status.
- Bot comments (to avoid loops).
- Duplicate delivery of the same webhook `delivery` / event id (idempotency).
- Updates that do not change readiness while a run is already active.

## Environment overrides

| Variable | Default | Purpose |
|----------|---------|---------|
| `JIRA_PROJECT_KEYS` | `SALES` | Comma-separated project keys |
| `JIRA_AGENT_LABEL` | `agent-nova` | Ready label |
| `JIRA_AGENT_STATUS` | `Ready for Agent` | Ready status name |
| `JIRA_ISSUE_TYPES` | `Story,Task` | Allowed types |
| `JIRA_BOT_ACCOUNT_ID` | _(empty)_ | Ignore comments from this account |
