# Channels - Generator (Step 5 section bodies)

<!-- toc -->
- [Jira body versus PR body](#jira-body-versus-pr-body)
- [Content options](#content-options)
- [Output template](#output-template)
<!-- /toc -->

> Loaded by `channels/SKILL.md` Step 5. The SKILL keeps the Jira-vs-PR body rule, the section-order rule and the target length rule; this file carries the content-option table, the aggregated output template, the store-compliance augmentation, and the work-summary and cost-summary generators. Read it before generating any section body.

## Jira body versus PR body

Jira is read by the person who filed the ticket and by whoever tests it, so its comment carries the four sections `channels/jira.md` fixes - `summary` (`Geliştirme Özeti`), `test_scenarios` (`Test Senaryoları`), `impact` (`Etki Analizi`) and `context_refs` (`Bağlantılar`), plus `test_run` when selected - and nothing else. Technical sections go to the PR and to Confluence, where the reader is a code reviewer. When `jira` is a selected channel, drop the technical sections from its body rather than converting them: the PR link on line 1 is how a Jira reader reaches the detail. No framework-theory paragraphs and no numbered "why this approach" lists in either body.

The report file takes one more body than the channels do. When `pr` is a
selected channel its body is copied there unchanged; when it is not, compose one
`Report` body in the `channels/pr.md` section order, with the PR tone, for the
file alone. The PR shape is the superset, so the summary and the test scenarios
reach disk whatever was ticked. The `Jira comment` block in that file is the
Jira body unchanged - the "never Jira" rule is about the Jira reader and nothing
here converts one body into the other. Contract: `channels/report-file.md`.

`impact` is not a technical section in disguise. It answers four questions - what was wrong, what was changed, which areas must be tested, what else is affected - in the same plain register as the summary, and it is the part a test lead reads before deciding how wide to test.

The content options are sources, not the body's shape. Which sections a PR body carries and in what order is fixed by `channels/pr.md` (`summary` -> `technical` -> `architecture` -> `impact` -> `test_scenarios` -> `test_run` -> `visuals` -> `risk` -> `dependencies` -> `build` -> `related`); the content options choose what gets gathered to fill them. A content option left unselected means a section has no source, not that the section may be reordered or renamed.

## Content options

| Content option | Generated section |
|---|---|
| Normal analiz | `### Analysis`  -  impact summary from Phase 1, risks from Phase 4 (pipeline-log source, high-level only) |
| Teknik analiz | `### Technical Details`  -  Changes (what/why per file group), Architecture (structural decisions, pattern changes), Dependencies (new imports/frameworks/packages). Source: Phase 1 planning + Phase 2 dev log + `git diff --stat`. **PR, Confluence and the local report file only** - never rendered into a Jira comment. |
| Test senaryoları | `### Test Scenarios`  -  precondition / steps / expected table (4-8 rows), user perspective |
| Test Koşumu (Xray) | `### Test Koşumu`  -  Xray Test Execution of the task's UI scenario run (`channels/test-run.md`) |
| Auto-diff | Old enrich Output Template verbatim  -  Root Cause / Solution / Changed Files / Test Scenarios |
| Manuel not | `### Notes`  -  user-provided paragraph, or LLM-split into subsections if `--message` is plain text and long |
| Cost özeti | `### Cost Summary`  -  per-phase token tally + est. USD table. Source: `phase-tracker.sh` phase status + optional OTel spans. See "Cost summary generation" below. |
| Yapılan iş özeti | `### Work Summary`  -  executive one-screen summary: task + branch + base + PR, scope delivered (done/[pending] per Phase 2 task), changed files with +/- counts (capped at 20 rows), review outcome (accepted/deferred/rejected + approved), phase tick strip. Source: `agent-state.json` + `phase-tracker.json` + `git diff --numstat base...HEAD`. See "Work summary generation" below. |

## Output template

**Output template (aggregated across selected content options):**

```markdown
### Analysis                        ← if "Normal analiz" selected
{impact summary, risks  -  from pipeline log, high-level}

### Technical Details               ← if "Teknik analiz" selected
#### Changes
{Per changed-file-group, what changed + why  -  from Phase 2 dev log}
#### Architecture
{Structural decisions, pattern changes, new file layouts  -  from Phase 1 plan}
#### Dependencies
{New imports / frameworks / packages  -  from git diff --stat, or "None"}

### Root Cause                      ← if "Auto-diff" selected
{single paragraph  -  from diff}

- `path/to/File.ext → funcName`: {why it broke}

### Solution                        ← if "Auto-diff" selected
- `path/to/File.ext:LINE-LINE`  -  {change, one line}

### Changed Files                   ← if "Auto-diff" selected
| File | +/- |
|------|-----|
| `path/to/File.ext` | +N / -M |

### Test Scenarios                  ← if "Test senaryoları" OR "Auto-diff" selected
**1. {what this scenario exercises}**
1. {step the tester performs}
2. **Expected:** {what they should see}

**2. {regression scenario}**
1. {step}
2. **Expected:** {what should still behave as before}

### Test Koşumu                     ← if "Test Koşumu (Xray)" selected

### Notes                           ← if "Manuel not" selected
{user message}

### Work Summary                    ← if "Yapılan iş özeti" selected
{executive scope + files + review + phases block  -  see "Work summary generation" below}

### Cost Summary                    ← if "Cost özeti" selected
{per-phase token + USD table  -  see "Cost summary generation" below}

### Store compliance                ← auto-appended if cached compliance report exists
{summary line  -  see below}

Ref: {jiraId}
```

**Store compliance auto-augmentation:**

After the content-selected sections are generated, check for a recent compliance report cached from `/multi-agent:test "store-ready"`:

```bash
# Cache locations (newest wins; expire after 6h to avoid stale cross-branch reports)
find /tmp -maxdepth 1 -name 'archiveguard-*.json' -o -name 'play-compliance-*.json' \
  -newermt "-6 hours" -print 2>/dev/null | head -1
```

If a cached report exists AND any of the selected channels is PR / Jira / Confluence, or a `Report` body is being composed for the report file, append an auto-summary section:

| Blocker count | Appended line |
|---|---|
| `errors > 0` | `### Store compliance` + `{N} blocker(s), {M} warning(s)  -  run /multi-agent:test "store-ready" for the full report.`  -  per-blocker: `- \`{ruleID}\`  -  {Apple ITMS / Play ref}: {message}` (capped at 5 rows, rest collapsed to `+N more`) |
| `errors == 0, warnings > 0` | `### Store compliance` + `[done] No blockers. {M} warning(s)  -  see /multi-agent:test "store-ready" for detail.` |
| `errors == 0, warnings == 0` | Skip section entirely  -  don't pollute PR body |

The section references `ruleID` + policy ref from the compliance skill catalogs (`apple-archive-compliance` / `google-play-compliance`) verbatim. No translation  -  global identifiers stay as-is.

If no cached report exists, skip silently  -  this is augmentation, not a gate.

**Work summary generation:**

Emitted only when `reportContent.workSummary === true` and at least one of (`agent-state.json`, `--branch` flag) is available. The shell adapter is `$HOME/.claude/scripts/render-work-summary.sh <taskId>`, and that script's own header is the spec for what it emits - task header, scope delivered, changed files, review outcome, phase strip - including the caps and the hidden-when-empty rules. Exit 2 means the state was unreadable: skip the section, do not substitute a hand-written one.

**Output template:**

```markdown
### Work Summary
**Task**: `PROJ-1099`  |  **Branch**: `bugfix/PROJ-1099-dark-mode`  |  **Base**: `develop`  |  **PR**: #104

#### Scope delivered
- [done] T1 Add failing dark-mode snapshot test
- [done] T2 Replace Color.white with design token

#### Changed files (3 files · +48 / -12)
- `Sources/Auth/LoginView.swift` (+24 / -8)
- `Sources/Auth/LoginViewTests.swift` (+22 / -4)
- `Sources/DesignSystem/Color+Tokens.swift` (+2 / -0)

#### Review outcome
- 1 accepted · 0 deferred · 0 rejected · approved=true

#### Phases
- 0 Init [done] · 1 Plan [done] · 2 Dev [done] · 3 Review [done] · 4 Commit [done] · 5 Report active
```

**Post-hoc invocation** (task already finished, agent-state.json may be archived): pass `--branch` + `--base-branch` explicitly  -  the script still emits task header + changed-files + phases sections (scope + review outcome are state-dependent and will be absent if state is gone).

**Cost summary generation:**

Emitted only when `reportContent.costSummary === true` and tracker data is available. Source of truth is `phase-tracker.sh`:

1. **Token tallies per phase**  -  `render-cost-summary.sh <taskId>` resolves the tracker JSON itself: worktree candidates (`.worktrees/{taskPath}/phase-tracker.json`) first, then the standard location `$HOME/.claude/logs/multi-agent/{taskId}/tracker-state.json` that `phase-tracker.sh` actually writes. Each phase row carries `{tokens_in, tokens_out}`.
2. **Fallback to OTel spans**  -  if tracker JSON has no token columns but `otel-spans.jsonl` exists (set `MULTI_AGENT_OTEL_SPANS=1` beforehand), aggregate `phase.tokens` spans by phase ID.
3. **USD estimate**  -  uses a static price table in `$HOME/.claude/scripts/cost-table.json` (model → $/Mtok_in, $/Mtok_out). Missing model → show ` - ` for USD, never block.

**Output template:**

```markdown
### Cost Summary
| Phase | Model | Tokens in | Tokens out | Est. USD |
|-------|-------|-----------|------------|----------|
| 1. Plan     | opus   | 31,384 | 8,330 | $1.08 |
| 2. Dev      | sonnet | 42,310 | 9,880 | $0.27 |
| 3. Review   | opus   | 21,050 | 4,720 | $0.66 |
| **Total**   |        | **94,744** | **22,930** | **$2.01** |
```

Generated by `$HOME/.claude/scripts/render-cost-summary.sh <task-id>` using prices from `$HOME/.claude/scripts/cost-table.json`. The channels adapter shells out to this renderer  -  doc table is illustrative only, runtime is authoritative.

**Precision rules:** tokens as thousand-separated integers. USD rounded to 2 dp (`printf '$%.2f'`). Rows with zero tokens dropped. If total USD is ` - ` (no price for any model), replace the total row USD cell with ` - ` and add a one-line footnote: `*USD unavailable  -  add model to cost-table.json*`.
