---
name: multi-agent-create-jira
description: "Create a standards-compliant Jira issue (Task / Bug / Story): asks the type, mines project conventions, drafts from a standard template with auto-sizing sections, full preview + explicit approval before create. Use when a Jira Task, Bug or Story has to be written to the project's own conventions."
user-invocable: true
argument-hint: "[\"<free-text description>\"] [figma-url] [swagger-url]  -  all optional, asked interactively when missing"
metadata:
  language: en
---

# multi-agent create-jira  -  Standards-Compliant Jira Issue Creator

**Input**: $ARGUMENTS

Creates exactly one Jira issue, and only after explicit approval. The issue type (Task / Bug / Story) is asked at the start of every run. No branches, no commits, no worktrees. The description comes from the type's standard template (baseline, not a mined heading set); sections auto-size  -  a conditional section renders only when its trigger is present, otherwise the heading is omitted.

> **Language**: issue content (summary + description) and user-facing questions follow `prefs.global.outputLanguage`, like every other user-facing payload body (`rules.md` matrix). Code identifiers and URLs stay verbatim.

## Standard templates (A = always, C = conditional)

- **Task**: Detailed Description (A), Scope (A), Acceptance Criteria (A), Test Scenarios (A); API Contract/Swagger (C), Design Reference (C), Screenshots (C), Notes (C).
- **Bug**: Detailed Description (A), Steps to Reproduce (A), Expected Result (A), Actual Result (A), Environment (A); Screenshots/Logs (C), Regression/Test Scenario (C), API Contract (C), Design Reference (C), Notes (C).
- **Story**: User Story (A), Detailed Description (A), Scope (A), Acceptance Criteria (A), Test Scenarios (A); API Contract/Swagger (C), Design Reference (C), Screenshots (C), Dependencies/Notes (C).

A `C` section fires on: Design Reference → Figma URL; Screenshots → pasted image or fetched Figma render; API Contract → Swagger URL / contract / endpoint mention; Notes → real content. No empty placeholder headings; never invent content.

## Steps

1. **Account + token**  -  pick the Jira account (auto-select when single), then:
   ```bash
   TOKEN=$(~/.copilot/lib/credential-store.sh get "$ACCOUNT_JIRA_TOKEN_KEY")
   ```
   Missing/expired (401) → Token Save Flow; user skips → abort, nothing created.
2. **Project key**  -  `figmaConfig.jira.projectKey` → `prefs.global.defaultJiraKey` → fetch `GET /rest/api/2/project`, ask, cache the choice.
3. **Pick issue type**  -  ask (Task / Bug / Story), never inferred silently → `ISSUE_TYPE`. Drives the mining JQL, field discovery, and section skeleton.
4. **Parse input**  -  `figma.com` URL → `FIGMA_URL` (node-id `-` → `:`); OpenAPI/Swagger URL (`swagger`/`openapi`/`api-docs`/`.json`/`.yaml`) → `SWAGGER_URL`; pasted images → screenshots; log/stack-trace text stays with `FREE_TEXT`; the rest is `FREE_TEXT`. All empty → ask for a description. Figma/Swagger/screenshots are always optional.
5. **Convention mining + field discovery + sprint** (read-only GETs):
   - Sample: `GET /rest/api/2/search?jql=project={KEY} AND issuetype={TYPE} ORDER BY created DESC&fields=summary,description,labels,components,priority,fixVersions,issuelinks&maxResults=30`. Extract summary prefix pattern (>= 40% threshold), top-5 labels/components, modal priority, epic usage rate, and **test-scenario style**: linked Test-family issues (Xray/Zephyr) → reference them; else a dominant test-scenario heading/checklist style (>= 40%) → reuse it; else inline a skeleton derived from Acceptance Criteria (user edits, never fabricated).
   - `GET /rest/api/2/issue/createmeta?projectKeys={KEY}&issuetypeNames={TYPE}&expand=projects.issuetypes.fields` (404/empty → paged DC endpoint fallback). Required custom fields → step 7 questions with allowedValues options. Detect Sprint/Epic/Team fields generically via `schema.custom` ids.
   - `GET /rest/agile/1.0/board?projectKeyOrId={KEY}` → (ask when multiple) → `GET /rest/agile/1.0/board/{id}/sprint?state=active`. No board/Agile 404 → sprint option silently omitted.
6. **External context** (only for provided sources, each failure-isolated, never blocks create):
   - **Figma** (`FIGMA_URL` set)  -  3-tier chain (MCP → REST `figma` PAT → user screenshot); standalone command, MCP allowed here.
   - **Swagger** (`SWAGGER_URL` set or contract pasted)  -  fetch the spec, extract ONLY the referenced endpoints (paths/operationIds/tags named in `FREE_TEXT`, else the pointed-at group): method + path + one-line summary + key request/response fields. Never crawl the whole spec. Fetch failure → link-only or omit.
   - **Screenshots**  -  staged for the step 8 attachment opt-in, referenced inline with `!file|thumbnail!`.
7. **Draft + clarifying questions**  -  compose summary (`{minedPrefix} {title}`, 255 trunc) + description from the type's **standard template** in Jira wiki markup (`h3.`), auto-sizing conditional sections, humanizer pass, in `outputLanguage`; body to a file for `jq -n --rawfile` (UTF-8 verbatim, `--data-binary @file`, no re-encode), passed through `node "$HOME/.claude/scripts/jira-wiki-escape.mjs"` first  -  the description field expands `:)` `(x)` `(!)` `(/)` into emoticon images. Ask ONLY genuinely unknown fields: component, epic (when usage rate is high), priority (when norm ambiguous), labels, assignee, sprint vs backlog, required customs, and any always-present section still empty (Bug Steps/Environment, or a Task/Story with no derivable Scope/AC). Never invent content the user did not supply.
8. **Full preview + approval gate (never skipped)**  -  render the complete issue (all fields + full description + attachment plan, uploads default off). Ask: `Approve` / `Edit` (apply → re-render → re-ask, loop) / `Cancel` (nothing created). No flag or mode bypasses this gate.
9. **Create**  -  `POST /rest/api/2/issue` with `jq -n --rawfile` payload + `curl --data-binary @file`. 400 field errors → show verbatim, re-ask those fields, re-preview.
10. **Post-create** (each failure-isolated: warn + continue): sprint chosen → `POST /rest/agile/1.0/sprint/{id}/issue` `{"issues":["KEY"]}`; Figma → `POST /rest/api/2/issue/{KEY}/remotelink`; Swagger → `remotelink` with title "API contract"; screenshots opt-in → `POST /rest/api/2/issue/{KEY}/attachments` with `X-Atlassian-Token: no-check`.
11. **Report**  -  `Created {KEY}: https://{host}/browse/{KEY}` + which post-steps ran.

## Error paths

401 token → Save Flow or abort (nothing created); mining/createmeta 403 → standard-template defaults + reactive 400 handling; zero sampled issues → skip mining, AC-derived test-scenario skeleton, note in preview; no board/active sprint → backlog implied, say so; Figma/Swagger failure → degrade (link-only or omit), never block; create 5xx → one retry then abort keeping the draft file; post-create failure → warn + continue.
