# Channels - Input forms, flags, summary format, error handling, cross-CLI parity, examples

<!-- toc -->
- [Input forms](#input-forms)
- [Flags](#flags)
- [Step 1 target resolution](#step-1-target-resolution)
- [Step 4 mode short-circuit](#step-4-mode-short-circuit)
- [Step 8 summary format](#step-8-summary-format)
- [Error handling](#error-handling)
- [Cross-CLI parity](#cross-cli-parity)
- [Examples](#examples)
- [Phase 5 delegation contract](#phase-5-delegation-contract)
<!-- /toc -->

> Loaded by `channels/SKILL.md`. Read the flag table and the error-handling table before Step 1 and whenever a target, a token or a precondition fails; the parity notes and examples are for orientation.

## Input forms

```
/multi-agent:channels                                         # cwd + current branch
/multi-agent:channels PROJ-12345                            # Jira ID
/multi-agent:channels #42                                     # GitHub issue/PR number
/multi-agent:channels https://github.com/<org>/<repo>/pull/N
/multi-agent:channels https://<bitbucket-host>/projects/.../pull-requests/N
/multi-agent:channels https://<jira-host>/browse/PROJ-12345

/multi-agent:channels PROJ-12345 --channels jira,confluence # non-interactive channel
/multi-agent:channels PROJ-12345 --content auto-diff        # non-interactive content
/multi-agent:channels PROJ-12345 --message "root: ..."      # manual source
/multi-agent:channels PROJ-12345 --message-file notes.md    # manual, long
/multi-agent:channels PROJ-12345 --dry-run                  # preview, no POST
```

## Flags

| Flag | Effect |
|------|--------|
| `--channels pr,jira,confluence,wiki` | Non-interactive channel selection (comma list). Skips channel menu. |
| `--content normal,technical,test,auto-diff,note,test-run` | Non-interactive content selection. Skips content menu. |
| `--flow-run <runId>[,<runId>...]` | Runs for the test run block (`channels/test-run.md`). |
| `--message "..."` | Manual mode  -  use user text as source, no diff read. Forces `content=note`. |
| `--message-file path` | Manual mode, long message from file. |
| `--append` | PR description: append instead of replace. |
| `--dry-run` | Generate, print to stdout, do not POST. Does not write the report file; prints the path it would write. |
| `--file-only` | No menu, no approval gate, no dispatch: compose the `Report` body and write the report file only. Content from `--content`, else from prefs. Used by the Phase 5 offline short-circuit, unattended Phase 5, the autopilot timeout, and a menu resolved with zero channels. |
| `--lang=tr\|en\|both` | Output language override (default: `en`; `promptLanguage` is locked to `en`). |
| `--ready` | If PR draft, promote to READY after channels dispatch. |

## Step 1 target resolution

1. Parse the argument and classify it: Jira-id, Jira-url, PR-url (GitHub or Bitbucket), GitHub-issue-number, or empty (cwd + branch).
2. Resolve linked entities:
   - Jira ID: linked PR via the dev-status API (`/rest/dev-status/latest/issue/detail`).
   - PR URL: Jira ID extracted from branch name / title / body using the `{JIRA_KEY}-XXXXX` pattern.
   - GitHub `#N`: resolved against the repo in cwd.
   - Empty: read the git branch, extract the Jira ID, find the linked PR.
3. Detect the remote type: `github` (gh CLI) or `bitbucket` (REST).
4. Store in runtime state: `{jiraId, targets: [{prUrl, prNumber, remoteType, repoPath, baseBranch, headBranch, repoName, isPrimary}]}`.

## Step 4 mode short-circuit

Non-interactive in three cases; the menu is skipped and flag values or prefs are used directly:

| Mode | Behavior |
|---|---|
| `--channels X,Y` + `--content A,B` flags | Exact flag values, no menu. |
| `autopilot` (Phase 5 delegate) | Reads `prefs.global.reportChannels` + `prefs.global.reportContent`. Per the Phase 5 autopilot-pause contract, Phase 5 still pauses before calling channels but pre-fills the menu from prefs. A post-hoc call in autopilot mode uses prefs directly. |
| `--dry-run` | Runs the menu, generates output, prints to stdout, does not post. |
| `--file-only` | Skips the menu, the gate and the dispatch; composes one body and writes the report file. |

## Step 8 summary format

```
channels dispatch complete
  PR description  ✓   version 3→4, reviewers 23 preserved
  Jira comment    ✓   posted → <jira-url>?focusedCommentId=2484780
  Confluence      -   skipped: user declined
  Wiki            ✓   3 files via github-wiki adapter
  Board           ✓   In Develop → In Review (project #4)
  Report file     ✓   $HOME/.claude/logs/multi-agent/app/PROJ-12/task-report.md
```

The `Report file` row is always last and always present: `✓` with the absolute
path (and `(previous kept in report-history/)` when a previous run's file was
rotated), `-` for a dry run or when there was no content source at all, `✗` with
the reason when the writer refused.

## Error handling

| Condition | Behavior |
|-----------|----------|
| No target resolvable | Error, exit 1 |
| PR not found + Jira selected | Proceed Jira-only, log reason |
| PR merged/closed | Warn, confirm continue |
| Author bot / dependabot | Skip entire run |
| Diff > 2 MB | Ask: skip / top-20-files / cancel |
| No pipeline log + "Normal analiz" selected | Greyed out at menu; if forced via `--content`, error |
| Bitbucket PR version mismatch | Refetch once, retry; fail on second mismatch |
| Jira token missing/expired | Token Save Flow inline; skip on user-skip |
| Wiki preconditions not met | Case B menu per `$HOME/.claude/multi-agent-refs/wiki-capture.md` |
| No external channel available or selected | Not an error: file-only. Bodies are composed and written to disk, nothing is posted |
| Report file refused (writer exit 7 or 2) | The `Report file` row carries the reason; dispatch continues unaffected |
| No content source at all | Nothing is written and Step 8 says so. A pipeline run always has a log, so this is the post-hoc case |

## Cross-CLI parity

| CLI | Command name | Invocation |
|---|---|---|
| Claude Code | `/multi-agent:channels` | Slash namespace (colon) |
| Copilot CLI | `multi-agent-channels` | Top-level command (dash-separated, no namespace support) |

Both installations read the same source file (`$HOME/.claude/commands/multi-agent/channels/SKILL.md`)  -  `install.js --all` copies to:
- `~/.claude/commands/multi-agent/channels/SKILL.md`
- `~/.copilot/commands/multi-agent-channels.md`

Prompts MUST be byte-identical. `smoke-cross-cli-behavior.sh` asserts this  -  spacing, brackets, numbering, log-line format.

Progress emission on Copilot (no native TaskCreate UI): `bash ~/.copilot/scripts/phase-tracker.sh sub 5 <N> "<step>" <status>`  -  same shape as Phase 5.

## Examples

```
/multi-agent:channels
  → resolves from cwd+branch → PROJ-12345 + PR #3433
  → menu: PR ✓ Jira ✓ / Normal analiz ✓ Test senaryoları ✓
  → PR description replaced (v3→4, 23 reviewers preserved)
  → Jira comment posted (id 2484780)
  → Confluence -  Wiki -

/multi-agent:channels PROJ-12345 --channels confluence --content note --message-file notes.md
  → non-interactive: only Confluence, content from notes.md
  → asks: parent page URL (or recent [1] / [2])
  → page created → https://<host>/pages/12345

/multi-agent:channels https://<bitbucket>/.../pull-requests/42 --dry-run
/multi-agent:channels PROJ-12345 --file-only                 # local-only repo: compose and write, post nothing
  → resolves → PROJ-67890
  → prints Jira + PR body preview to stdout, no POST

/multi-agent:channels --message "root: order id empty, UI silent. fix: length>0 guard in HomeVC.m"
  → auto-diff from cwd+branch PR + user note combined
  → posts to default channels (PR + Jira)
```

## Phase 5 delegation contract

Phase 5 invokes channels internally instead of running its own Jira / Confluence / Wiki logic:

| Who | What |
|---|---|
| Phase 5 | Progress tracker (sub-steps 1-3), agent-log finalization (step 4), knowledge + memory capture (step 5), telemetry emission |
| `channels` | All external delivery: PR description update, Jira comment, Confluence page, Wiki pages. Plus the local report file, which is not delivery and is written whatever the channels do |

Phase 5 passes a runtime state bundle: `{jiraId, prUrl, remoteType, taskType, figmaConfig, agentState, pipelineLogPath, flowRuns}`. Channels reads these directly and skips Step 1 target resolution.

On the three paths where nothing is posted - the offline short-circuit, an unattended run, and the autopilot timeout - Phase 5 calls channels with `--file-only` rather than skipping it. That is the whole reason the report file exists: those are the paths that used to end with the summary composed and then dropped. The channels return carries `reportFile: {status, path}`, which is not written to `channelResults`: that object records what was posted, and this was not.

Autopilot: Phase 5 always pauses at the channels menu, the one exception to the autopilot zero-interaction contract. A 30-min timeout ends the session cleanly and the task stays resumable via `/multi-agent:resume`; full contract in `$HOME/.claude/multi-agent-refs/phases/modes.md`. The Step 6 approval gate follows the same split: interactive runs approve the composed bodies before dispatch, autopilot posts directly after the menu resolves.
