# Channels - the report file

<!-- toc -->
- [Why it is not a channel](#why-it-is-not-a-channel)
- [Path](#path)
- [The file](#the-file)
- [When it is written](#when-it-is-written)
- [Rotation](#rotation)
- [Writer](#writer)
- [Step 8 row](#step-8-row)
<!-- /toc -->

> Loaded by `channels/SKILL.md` Step 5. The SKILL keeps the one-line rule; this
> file carries the path, the envelope, the write moments, `--file-only`,
> rotation and the writer's interface.

## Why it is not a channel

Every channel is an external write, and three ordinary paths end with nothing
written at all:

- a local-only repo short-circuits Phase 5 before the menu (`phases/phase-5-report.md`);
- an unattended run defers delivery to the runner and posts nothing;
- a cancelled menu, the autopilot timeout, and a menu with every row unticked
  all end after Step 5.

On a machine with no tracker the development summary and the test scenarios were
composed, shown once in the preview, and lost.

A fifth channel would not fix that. A channel is selectable, waits for the Step 6
gate, and is skipped unattended and offline - each of which reintroduces one of
the three losses. So the report file is internal capture, like `agent-log.md`:
unconditional, local, and with no preference to get wrong. It is not a post, and
no rule about posting applies to it.

## Path

```
${LOGS_ROOT:-$HOME/.claude/logs/multi-agent}/<project>/<task-id>/task-report.md
```

Beside `agent-log.md`. Not the repo or the worktree, which Phase 4 removes and
where a stray file invites an accidental commit; not the Desktop, which is
presumptuous on a shipped product and outside the unattended write scope. The
log directory survives the worktree, `/multi-agent:log` already looks there,
`prune-logs` already owns its lifetime, and an unattended run may write to it.

`task-report.md`, not `report.md`: store-ready, bug-bash and complaint-analysis
already write a `report.md` and mean something else by it.

The task directory is `dirname` of the pipeline log when there is one. For a
post-hoc call on a task that never ran through the pipeline, it is
`<LOGS_ROOT>/<project>/<key>/` with the key being the Jira id, else `GH<n>`,
else `PR<n>`.

How someone who never read this finds it: the Step 8 row prints the absolute
path, the Phase 5 closing block carries `Report file:`, the Step 3 menu says in
one line that it is always written, `/multi-agent:log` prints it, and the `Logs:`
line of `/multi-agent:help` names it.

## The file

```markdown
# {taskKey} - {title}

- Branch: `{head}` -> `{base}`
- PR: {url | none}
- Tracker: {jira id or issue url | none}
- Written: {YYYY-MM-DD HH:mm} by /multi-agent:channels (run {runId})
- Delivery: {not sent | pr posted · jira skipped: declined | ...}

---

# Report

{body}

---

# Jira comment

{body}
```

Envelope labels are fixed English so the file stays parseable; the bodies are in
`outputLanguage`. Block headings are `Report`, `PR description (<repo>#<n>)`,
`Jira comment` and `Confluence page`, in that order whatever order they were
handed over in.

**The file always carries one PR-shaped body.** When `pr` is selected that block
is the PR body, copied. When it is not, the generator composes one body in the
`channels/pr.md` section order, with the PR tone, labelled `Report`. The PR shape
is the superset, so `Geliştirme Özeti` and `Test Senaryoları` are on disk in
every case. The cost is one extra composition when `pr` is not selected.

`technicalAnalysis` renders in the PR-shaped block, always, and never in the
`Jira comment` block, which is a copy of the Jira body. The "never Jira" rule is
about the Jira reader and is untouched.

Bodies are copied byte for byte. Nothing is merged, converted or run through the
humanizer a second time: a second pass would break byte-identity with what the
adapters post.

## When it is written

Whenever Step 5 composed at least one body.

- **Right after the humanizer, before Step 6.** Cancel, the timeout and a crash
  therefore all leave it behind.
- Rewritten after each `Edit` re-render, and once more at Step 8 with
  `--delivery` to stamp the outcomes.
- **No approval gate.** The gate protects an audience from unreviewed text. This
  file has no audience but the machine's owner, is replaceable, and holds less
  than `agent-log.md` already does.
- `--dry-run` writes nothing and prints the path it would write.
- If the access check stops channels inside Phase 5, Phase 5 records
  `report file not written` and continues its internal capture. It never halts
  on it.
- No content source at all - no log, no PR diff, no `--message`, no state - and
  nothing is written. Step 8 says so. A pipeline run always has a log.

### `--file-only`

No menu, no Step 6, no Step 7. Content comes from `--content`, else from
`prefs.global.reportContent` filtered by the availability rules. Only the
`Report` body is composed.

Used by the Phase 5 offline short-circuit, unattended Phase 5, the autopilot
30-minute timeout, and a menu resolved with zero channels, which is a valid
selection meaning file-only.

## Rotation

- `task-report.md` is always the latest.
- Same `runId` as the file already there (the Edit loop, the delivery stamp):
  replaced in place.
- A different `runId`: the previous file moves to
  `report-history/task-report-<stamp>-<runId>.md` first. The newest 5 are kept.
- The run id is in the name because the stamp is minute-resolution: two runs
  inside one minute would otherwise share a name, the second quietly replacing
  the first in the very place that exists to not lose it.
- Not appended, because one unreadable file is not a report. Not
  timestamp-only-named, because then nobody can tell which one is current.

## Writer

`$HOME/.claude/scripts/report-file.mjs`. Zero dependencies beyond the outbound gate.

```
report-file.mjs write --dir <task-dir> --run <id> --meta <meta.json>
                      --body <name>=<file> [--body ...] [--delivery <json>]
report-file.mjs path  --dir <task-dir>
```

`meta.json` carries `{taskKey, title, branch, base, prUrl, tracker}`; a missing
value renders as `none`. `--delivery` takes the dispatch result object. stdout is
the absolute path.

| Exit | Meaning |
|---|---|
| 0 | written |
| 2 | usage, no body, an empty body, or a path that is not inside the logs root |
| 7 | a body carries credential-shaped text |

What it refuses, and why each one is a refusal rather than a repair:

- a `--dir` whose realpath is outside `LOGS_ROOT`, including one reached through
  a symlink or `..`;
- a symlink at `task-report.md` or at `report-history/`, which would point the
  write somewhere else;
- a body that the outbound gate matches with certainty. Nothing is written, the
  existing file and its history are untouched, and the message names the rule
  and the line but never the matched value.

It writes to a temp file in the same directory and renames, mode 0600, so a
reader never sees a half-written report and a crash leaves the previous one
intact.

## Step 8 row

Always present, last row of the block.

```
  Report file     ✓   /Users/me/.claude/logs/multi-agent/app/PROJ-12/task-report.md  (previous kept in report-history/)
  Report file     -   dry run: would write <path>
  Report file     -   nothing to write: no content source
  Report file     ✗   not written: credential-shaped text in the Jira comment body
```
