---
phase: 23-caption-history-panel
plan: 02
type: execute
wave: 2
depends_on: [23-01]
files_modified:
  - ~/Library/Application Support/SwiftBar/Plugins/claude-hq.10s.sh
  - ~/Library/Application Support/SwiftBar/Plugins/nc-action.sh
autonomous: false
requirements: [CAPT-04]

must_haves:
  truths:
    - "SwiftBar menu has a Caption History button that toggles the panel"
    - "Clicking the button calls POST /captions/panel/show or /hide via nc-action.sh"
  artifacts:
    - path: "~/Library/Application Support/SwiftBar/Plugins/claude-hq.10s.sh"
      provides: "Caption History menu item"
      contains: "Caption History"
    - path: "~/Library/Application Support/SwiftBar/Plugins/nc-action.sh"
      provides: "toggle-captions action handler"
      contains: "toggle-captions"
  key_links:
    - from: "nc-action.sh"
      to: "HTTPControlServer"
      via: "curl POST /captions/panel/show and /hide"
      pattern: "/captions/panel"
---

<objective>
Add Caption History toggle button to SwiftBar menu so users can open/close the caption history panel from the menu bar.

Purpose: Completes CAPT-04 (accessible via SwiftBar button) by adding a menu entry that triggers the HTTP API panel endpoints.
Output: Updated SwiftBar plugin files (local-only, not repo-tracked).
</objective>

<execution_context>
@$HOME/.claude/get-shit-done/workflows/execute-plan.md
@$HOME/.claude/get-shit-done/templates/summary.md
</execution_context>

<context>
@.planning/PROJECT.md
@.planning/ROADMAP.md
@.planning/phases/23-caption-history-panel/23-01-SUMMARY.md

<interfaces>
<!-- SwiftBar pattern from Phase 22 -->

claude-hq.10s.sh action helper:

```bash
act() { echo "bash=\"$ACTION\" param1=$1 param2=$2 param3=$3 terminal=false refresh=true"; }
```

nc-action.sh case pattern:

```bash
case "$1" in
  toggle-captions)
    # new handler here
    ;;
esac
```

HTTP endpoints (from Plan 01):

- POST /captions/panel/show -- opens the caption history panel
- POST /captions/panel/hide -- closes the panel
  </interfaces>

</context>

<tasks>

<task type="auto">
  <name>Task 1: SwiftBar Caption History button + nc-action.sh handler</name>
  <files>
    ~/Library/Application Support/SwiftBar/Plugins/claude-hq.10s.sh
    ~/Library/Application Support/SwiftBar/Plugins/nc-action.sh
  </files>
  <read_first>
    ~/Library/Application Support/SwiftBar/Plugins/claude-hq.10s.sh
    ~/Library/Application Support/SwiftBar/Plugins/nc-action.sh
  </read_first>
  <action>
**claude-hq.10s.sh changes:**

Add a "Caption History" button in the Subtitle section, after the Bionic Reading toggle and before the Screen section. Insert around line 106 (after the Bionic Reading line):

```bash
echo ":text.bubble: Caption History | $(act toggle-captions "" "")"
```

Use the `:text.bubble:` SF Symbol for the caption history icon.

**nc-action.sh changes:**

Add a new case `toggle-captions` before the `*)` fallback case (around line 113). The handler should toggle the panel: show if not visible, hide if visible. Since there is no API to query panel visibility state, always POST to /captions/panel/show (the panel can handle being shown when already visible -- it just refreshes). Alternatively, implement a simple toggle:

```bash
toggle-captions)
  # Toggle caption history panel via HTTP API
  if curl -sf --max-time 3 -X POST "$API_BASE/captions/panel/show" >/dev/null 2>&1; then
    log_event "toggle-captions" "ok" "show"
  else
    log_event "toggle-captions" "FAIL" "api_unreachable"
  fi ;;
```

Note: User can close the panel via its title bar close button (standard NSPanel behavior with `.closable` style mask). The SwiftBar button always opens/shows it.
</action>
<verify>
<automated>grep -q "Caption History" ~/Library/Application\ Support/SwiftBar/Plugins/claude-hq.10s.sh && grep -q "toggle-captions" ~/Library/Application\ Support/SwiftBar/Plugins/nc-action.sh && echo "PASS"</automated>
</verify>
<acceptance_criteria> - grep -q "Caption History" ~/Library/Application\ Support/SwiftBar/Plugins/claude-hq.10s.sh - grep -q "toggle-captions" ~/Library/Application\ Support/SwiftBar/Plugins/claude-hq.10s.sh - grep -q "toggle-captions" ~/Library/Application\ Support/SwiftBar/Plugins/nc-action.sh - grep -q "/captions/panel" ~/Library/Application\ Support/SwiftBar/Plugins/nc-action.sh
</acceptance_criteria>
<done>SwiftBar menu shows Caption History button. nc-action.sh handler calls POST /captions/panel/show to open the panel.</done>
</task>

<task type="checkpoint:human-verify" gate="blocking">
  <name>Task 2: Visual verification of caption history panel</name>
  <files>none</files>
  <action>
Human verifies the full caption history feature end-to-end: SwiftBar button, panel UI, scroll behavior, and click-to-copy.
  </action>
  <verify>
    <automated>curl -sf --max-time 3 -X POST http://localhost:8780/captions/panel/show && echo "PASS"</automated>
  </verify>
  <done>User confirms panel opens from SwiftBar, shows HH:MM timestamps, scrolls correctly, and click-to-copy works.</done>
  <what-built>Caption history panel accessible from SwiftBar menu with scrollable captions, timestamps, and click-to-copy</what-built>
  <how-to-verify>
    1. Ensure claude-tts-companion service is running: `launchctl list | grep claude-tts`
    2. If not running, rebuild and restart: `cd plugins/claude-tts-companion && swift build -c release && launchctl kickstart -k gui/$(id -u)/com.terryli.claude-tts-companion`
    3. Trigger a TTS test to populate caption history: `curl -X POST http://localhost:8780/tts/test`
    4. Wait 5 seconds for TTS to complete
    5. Click SwiftBar gear icon -- verify "Caption History" button appears in Subtitle section
    6. Click "Caption History" -- verify a floating panel appears with past captions showing HH:MM timestamps
    7. Verify the panel is scrollable (if enough entries exist)
    8. Click a caption row -- verify text is copied to clipboard (Cmd+V to confirm)
    9. Close panel via title bar X button -- verify it closes cleanly
    10. Alternatively test via API: `curl -X POST http://localhost:8780/captions/panel/show` and `curl -X POST http://localhost:8780/captions/panel/hide`
  </how-to-verify>
  <resume-signal>Type "approved" or describe issues</resume-signal>
</task>

</tasks>

<verification>
1. grep "Caption History" in claude-hq.10s.sh -- PASS
2. grep "toggle-captions" in nc-action.sh -- PASS
3. Visual: panel opens from SwiftBar, shows timestamps, click-to-copy works
</verification>

<success_criteria>

- SwiftBar menu has Caption History button that opens the panel
- Panel shows past captions with HH:MM timestamps
- Click-to-copy works
- Panel closable via title bar
- User approves visual verification
  </success_criteria>

<output>
After completion, create `.planning/phases/23-caption-history-panel/23-02-SUMMARY.md`
</output>
