---
phase: 23-diff-and-show-flags
plan: 01
type: execute
wave: 1
depends_on: []
files_modified: [cmd_diff.py, cmd_show.py]
autonomous: true

must_haves:
  truths:
    - "User running git diff --stat sees diffstat summary"
    - "User running git diff -w ignores whitespace differences"
    - "User running git diff --staged receives warning about no staging area"
    - "User running git diff --name-only sees only file names"
    - "User running git show --stat sees diffstat for commit"
    - "User running git show -s sees commit info without diff"
    - "User running git show --oneline sees short format"
  artifacts:
    - path: "cmd_diff.py"
      provides: "Diff flag translation with warnings"
      min_lines: 80
    - path: "cmd_show.py"
      provides: "Show flag translation with templates"
      min_lines: 80
  key_links:
    - from: "cmd_diff.py"
      to: "common.run_sl"
      via: "Translated args passed to sl diff"
      pattern: "run_sl.*diff"
    - from: "cmd_show.py"
      to: "common.run_sl"
      via: "Translated args passed to sl show"
      pattern: "run_sl.*show"
---

<objective>
Implement comprehensive flag support for git diff and git show commands.

Purpose: Users can customize diff and show output using standard git flags for context, formatting, and filtering. This extends the minimal pass-through implementations to support the full range of commonly-used flags.

Output: Extended cmd_diff.py and cmd_show.py with flag translation, template generation, and clear warnings for unsupported features.
</objective>

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

<context>
@.planning/PROJECT.md
@.planning/ROADMAP.md
@.planning/STATE.md
@.planning/phases/23-diff-and-show-flags/23-RESEARCH.md
@.planning/phases/22-log-flags/22-01-SUMMARY.md

# Reference for established patterns
@cmd_log.py
</context>

<tasks>

<task type="auto">
  <name>Task 1: Extend cmd_diff.py with flag translation</name>
  <files>cmd_diff.py</files>
  <action>
Extend the minimal cmd_diff.py pass-through implementation to handle 12 diff flags following the cmd_log.py pattern.

**Direct pass-through flags:**
- DIFF-01: `--stat` passes through to `sl diff --stat`
- DIFF-02: `-w/--ignore-all-space` passes through to `sl diff -w`
- DIFF-03: `-b/--ignore-space-change` passes through to `sl diff -b`

**Value parsing:**
- DIFF-04: `-U<n>/--unified=<n>` - handle attached format (-U5), separate format (-U 5), and equals format (--unified=5). Translate to `sl diff -U <n>`

**Output format flags (use sl status for name output):**
- DIFF-05: `--name-only` - for working directory diff, use `sl status -mard` and output only filenames. This is a semantic equivalent since sl diff lacks --name-only.
- DIFF-06: `--name-status` - for working directory diff, use `sl status -mard` which already shows status codes (M, A, R, !). Map sl status codes to git format (M->M, A->A, R->R, !->D).

**Warning flags (print warning to stderr, do NOT pass flag to sl):**
- DIFF-07: `--staged/--cached` - warn "Sapling has no staging area. Use 'sl diff' to see all uncommitted changes."
- DIFF-08: `--raw` - warn "Warning: --raw format not supported. Use 'sl status' for file status information."
- DIFF-09: `-M/--find-renames` - warn "Sapling doesn't support automatic rename detection (-M). Use 'sl mv' to track renames before committing."
- DIFF-10: `-C/--find-copies` - warn "Sapling doesn't support automatic copy detection (-C). Use 'sl copy' to track copies before committing."
- DIFF-11: `--word-diff` - warn "Sapling doesn't support word-level diff (--word-diff). Consider using external tools like 'diff-so-fancy' or 'delta'."
- DIFF-12: `--color-moved` - warn "Sapling doesn't support --color-moved highlighting."

**Important implementation notes:**
- Use `import sys` for stderr output
- For --name-only and --name-status, detect if positional args (file paths or commits) are present. If comparing commits, pass through to sl diff and note limitation.
- All other arguments should pass through as remaining_args
- Handle -M and -C with optional attached percentage: -M50, -C90, etc.
  </action>
  <verify>
1. `python -c "import cmd_diff; print('OK')"` - imports without error
2. File has 80+ lines (was 13 lines, adding significant logic)
3. Manual check: Code handles all 12 DIFF-* requirements
  </verify>
  <done>
- cmd_diff.py translates --stat, -w, -b, -U flags correctly
- cmd_diff.py uses sl status for --name-only/--name-status
- cmd_diff.py prints warning for --staged/--cached, --raw, -M, -C, --word-diff, --color-moved
- All warnings go to stderr, execution continues with exit 0
  </done>
</task>

<task type="auto">
  <name>Task 2: Extend cmd_show.py with flag translation and templates</name>
  <files>cmd_show.py</files>
  <action>
Extend the minimal cmd_show.py pass-through implementation to handle 8 show flags, reusing template patterns from cmd_log.py.

**Direct pass-through flags:**
- SHOW-01: `--stat` passes through to `sl show --stat`
- SHOW-02: `-U<n>` - handle attached format (-U5), separate format (-U 5). Translate to `sl show -U <n>`
- SHOW-03: `-w/--ignore-all-space` passes through to `sl show -w`

**Template-based output formatting:**
Define templates similar to cmd_log.py:

```python
# Template for --oneline format
SHOW_ONELINE_TEMPLATE = "{node|short} {desc|firstline}\\n"

# Template for --name-only format
SHOW_NAME_ONLY_TEMPLATE = "{node|short} {desc|firstline}\\n{files}\\n"

# Template for --name-status format
SHOW_NAME_STATUS_TEMPLATE = ("{node|short} {desc|firstline}\\n"
                              "{file_adds % 'A\\t{file}\\n'}"
                              "{file_dels % 'D\\t{file}\\n'}"
                              "{file_mods % 'M\\t{file}\\n'}\\n")

# Template for -s/--no-patch (commit info only, no diff)
SHOW_NO_PATCH_TEMPLATE = "commit {node|short}\\nAuthor: {author}\\nDate:   {date|isodate}\\n\\n    {desc}\\n"
```

**Template flags:**
- SHOW-04: `--name-only` - use SHOW_NAME_ONLY_TEMPLATE
- SHOW-05: `--name-status` - use SHOW_NAME_STATUS_TEMPLATE
- SHOW-06: `--pretty/--format` - reuse PRETTY_PRESETS and translate_format_placeholders from cmd_log.py pattern. Copy the preset formats (oneline, short, medium, full) and GIT_TO_SL_PLACEHOLDERS mapping.
- SHOW-07: `-s/--no-patch` - use SHOW_NO_PATCH_TEMPLATE (suppresses diff output)
- SHOW-08: `--oneline` - use SHOW_ONELINE_TEMPLATE

**Template priority (same as log):**
custom_template > name_status > name_only > no_patch > oneline

**Important implementation notes:**
- Copy PRETTY_PRESETS and GIT_TO_SL_PLACEHOLDERS from cmd_log.py logic (or define locally)
- Implement translate_format_placeholders function locally (same as cmd_log.py)
- When template is used, add `-T template` to sl_args
- All other arguments (commit refs) pass through as remaining_args
  </action>
  <verify>
1. `python -c "import cmd_show; print('OK')"` - imports without error
2. File has 80+ lines (was 17 lines, adding significant logic)
3. Manual check: Code handles all 8 SHOW-* requirements
  </verify>
  <done>
- cmd_show.py translates --stat, -w, -U flags correctly
- cmd_show.py uses templates for --name-only, --name-status, --oneline, -s
- cmd_show.py handles --pretty/--format with preset and custom formats
- Template priority applied correctly: custom > name_status > name_only > no_patch > oneline
  </done>
</task>

</tasks>

<verification>
After completing both tasks:

1. **Diff verification:**
   ```bash
   cd /Users/vmakaev/NonWork/gitsl
   python -c "import cmd_diff; print('Import OK')"
   python -c "
   from cmd_diff import handle
   from common import ParsedCommand
   # Verify function signature exists
   print('handle function exists:', callable(handle))
   "
   ```

2. **Show verification:**
   ```bash
   python -c "import cmd_show; print('Import OK')"
   python -c "
   from cmd_show import handle
   from common import ParsedCommand
   # Verify function signature exists
   print('handle function exists:', callable(handle))
   "
   ```

3. **File size check:**
   ```bash
   wc -l cmd_diff.py cmd_show.py
   # cmd_diff.py should be 80+ lines
   # cmd_show.py should be 80+ lines
   ```

4. **Warning output check (manual):**
   - Verify --staged/--cached warning text is present in cmd_diff.py
   - Verify SHOW_ONELINE_TEMPLATE is defined in cmd_show.py
</verification>

<success_criteria>
1. cmd_diff.py handles all 12 DIFF-* requirements (DIFF-01 through DIFF-12)
2. cmd_show.py handles all 8 SHOW-* requirements (SHOW-01 through SHOW-08)
3. Both files import without errors
4. Flag translation follows established cmd_log.py patterns
5. Warnings for unsupported flags go to stderr with helpful messages
6. All remaining arguments pass through correctly
</success_criteria>

<output>
After completion, create `.planning/phases/23-diff-and-show-flags/23-01-SUMMARY.md`
</output>
