claude-dev-cli 0.1.0__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of claude-dev-cli might be problematic. Click here for more details.
- {claude_dev_cli-0.1.0/src/claude_dev_cli.egg-info → claude_dev_cli-0.3.0}/PKG-INFO +41 -1
- {claude_dev_cli-0.1.0 → claude_dev_cli-0.3.0}/README.md +37 -0
- {claude_dev_cli-0.1.0 → claude_dev_cli-0.3.0}/pyproject.toml +5 -1
- {claude_dev_cli-0.1.0 → claude_dev_cli-0.3.0}/src/claude_dev_cli/__init__.py +1 -1
- {claude_dev_cli-0.1.0 → claude_dev_cli-0.3.0}/src/claude_dev_cli/cli.py +132 -0
- claude_dev_cli-0.3.0/src/claude_dev_cli/plugins/__init__.py +42 -0
- claude_dev_cli-0.3.0/src/claude_dev_cli/plugins/base.py +53 -0
- claude_dev_cli-0.3.0/src/claude_dev_cli/plugins/diff_editor/__init__.py +3 -0
- claude_dev_cli-0.3.0/src/claude_dev_cli/plugins/diff_editor/plugin.py +98 -0
- claude_dev_cli-0.3.0/src/claude_dev_cli/plugins/diff_editor/viewer.py +314 -0
- claude_dev_cli-0.3.0/src/claude_dev_cli/toon_utils.py +117 -0
- {claude_dev_cli-0.1.0 → claude_dev_cli-0.3.0/src/claude_dev_cli.egg-info}/PKG-INFO +41 -1
- {claude_dev_cli-0.1.0 → claude_dev_cli-0.3.0}/src/claude_dev_cli.egg-info/SOURCES.txt +13 -1
- {claude_dev_cli-0.1.0 → claude_dev_cli-0.3.0}/src/claude_dev_cli.egg-info/requires.txt +4 -0
- claude_dev_cli-0.3.0/tests/test_cli.py +262 -0
- claude_dev_cli-0.3.0/tests/test_commands.py +314 -0
- claude_dev_cli-0.3.0/tests/test_config.py +255 -0
- claude_dev_cli-0.3.0/tests/test_core.py +240 -0
- claude_dev_cli-0.3.0/tests/test_toon_utils.py +119 -0
- claude_dev_cli-0.3.0/tests/test_usage.py +222 -0
- {claude_dev_cli-0.1.0 → claude_dev_cli-0.3.0}/LICENSE +0 -0
- {claude_dev_cli-0.1.0 → claude_dev_cli-0.3.0}/MANIFEST.in +0 -0
- {claude_dev_cli-0.1.0 → claude_dev_cli-0.3.0}/setup.cfg +0 -0
- {claude_dev_cli-0.1.0 → claude_dev_cli-0.3.0}/src/claude_dev_cli/commands.py +0 -0
- {claude_dev_cli-0.1.0 → claude_dev_cli-0.3.0}/src/claude_dev_cli/config.py +0 -0
- {claude_dev_cli-0.1.0 → claude_dev_cli-0.3.0}/src/claude_dev_cli/core.py +0 -0
- {claude_dev_cli-0.1.0 → claude_dev_cli-0.3.0}/src/claude_dev_cli/templates.py +0 -0
- {claude_dev_cli-0.1.0 → claude_dev_cli-0.3.0}/src/claude_dev_cli/usage.py +0 -0
- {claude_dev_cli-0.1.0 → claude_dev_cli-0.3.0}/src/claude_dev_cli.egg-info/dependency_links.txt +0 -0
- {claude_dev_cli-0.1.0 → claude_dev_cli-0.3.0}/src/claude_dev_cli.egg-info/entry_points.txt +0 -0
- {claude_dev_cli-0.1.0 → claude_dev_cli-0.3.0}/src/claude_dev_cli.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: claude-dev-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: A powerful CLI tool for developers using Claude AI with multi-API routing, test generation, code review, and usage tracking
|
|
5
5
|
Author-email: Julio <thinmanj@users.noreply.github.com>
|
|
6
6
|
License: MIT
|
|
@@ -26,11 +26,14 @@ Requires-Dist: anthropic>=0.18.0
|
|
|
26
26
|
Requires-Dist: click>=8.1.0
|
|
27
27
|
Requires-Dist: rich>=13.0.0
|
|
28
28
|
Requires-Dist: pydantic>=2.0.0
|
|
29
|
+
Provides-Extra: toon
|
|
30
|
+
Requires-Dist: toon-format>=0.9.0; extra == "toon"
|
|
29
31
|
Provides-Extra: dev
|
|
30
32
|
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
31
33
|
Requires-Dist: black>=23.0.0; extra == "dev"
|
|
32
34
|
Requires-Dist: ruff>=0.1.0; extra == "dev"
|
|
33
35
|
Requires-Dist: mypy>=1.0.0; extra == "dev"
|
|
36
|
+
Requires-Dist: toon-format>=0.9.0; extra == "dev"
|
|
34
37
|
Dynamic: license-file
|
|
35
38
|
|
|
36
39
|
# Claude Dev CLI
|
|
@@ -63,12 +66,27 @@ A powerful command-line tool for developers using Claude AI with multi-API routi
|
|
|
63
66
|
- **Interactive**: Chat mode with conversation history
|
|
64
67
|
- **Streaming**: Real-time responses
|
|
65
68
|
|
|
69
|
+
### 🎒 TOON Format Support (Optional)
|
|
70
|
+
- **Token Reduction**: 30-60% fewer tokens than JSON
|
|
71
|
+
- **Cost Savings**: Reduce API costs significantly
|
|
72
|
+
- **Format Conversion**: JSON ↔ TOON with CLI tools
|
|
73
|
+
- **Auto-fallback**: Works without TOON installed
|
|
74
|
+
|
|
66
75
|
## Installation
|
|
67
76
|
|
|
77
|
+
### Basic Installation
|
|
78
|
+
|
|
68
79
|
```bash
|
|
69
80
|
pip install claude-dev-cli
|
|
70
81
|
```
|
|
71
82
|
|
|
83
|
+
### With TOON Support (Recommended for Cost Savings)
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
# Install with TOON format support for 30-60% token reduction
|
|
87
|
+
pip install claude-dev-cli[toon]
|
|
88
|
+
```
|
|
89
|
+
|
|
72
90
|
## Quick Start
|
|
73
91
|
|
|
74
92
|
### 1. Set Up API Keys
|
|
@@ -141,6 +159,28 @@ cdc usage --days 7
|
|
|
141
159
|
cdc usage --api client
|
|
142
160
|
```
|
|
143
161
|
|
|
162
|
+
### 5. TOON Format (Optional - Reduces Tokens by 30-60%)
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
# Check if TOON is installed
|
|
166
|
+
cdc toon info
|
|
167
|
+
|
|
168
|
+
# Convert JSON to TOON
|
|
169
|
+
echo '{"users": [{"id": 1, "name": "Alice"}]}' | cdc toon encode
|
|
170
|
+
# Output:
|
|
171
|
+
# users[1]{id,name}:
|
|
172
|
+
# 1,Alice
|
|
173
|
+
|
|
174
|
+
# Convert file
|
|
175
|
+
cdc toon encode data.json -o data.toon
|
|
176
|
+
|
|
177
|
+
# Convert TOON back to JSON
|
|
178
|
+
cdc toon decode data.toon -o data.json
|
|
179
|
+
|
|
180
|
+
# Use in workflows
|
|
181
|
+
cat large_data.json | cdc toon encode | cdc ask "analyze this data"
|
|
182
|
+
```
|
|
183
|
+
|
|
144
184
|
## Configuration
|
|
145
185
|
|
|
146
186
|
### Global Configuration
|
|
@@ -28,12 +28,27 @@ A powerful command-line tool for developers using Claude AI with multi-API routi
|
|
|
28
28
|
- **Interactive**: Chat mode with conversation history
|
|
29
29
|
- **Streaming**: Real-time responses
|
|
30
30
|
|
|
31
|
+
### 🎒 TOON Format Support (Optional)
|
|
32
|
+
- **Token Reduction**: 30-60% fewer tokens than JSON
|
|
33
|
+
- **Cost Savings**: Reduce API costs significantly
|
|
34
|
+
- **Format Conversion**: JSON ↔ TOON with CLI tools
|
|
35
|
+
- **Auto-fallback**: Works without TOON installed
|
|
36
|
+
|
|
31
37
|
## Installation
|
|
32
38
|
|
|
39
|
+
### Basic Installation
|
|
40
|
+
|
|
33
41
|
```bash
|
|
34
42
|
pip install claude-dev-cli
|
|
35
43
|
```
|
|
36
44
|
|
|
45
|
+
### With TOON Support (Recommended for Cost Savings)
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
# Install with TOON format support for 30-60% token reduction
|
|
49
|
+
pip install claude-dev-cli[toon]
|
|
50
|
+
```
|
|
51
|
+
|
|
37
52
|
## Quick Start
|
|
38
53
|
|
|
39
54
|
### 1. Set Up API Keys
|
|
@@ -106,6 +121,28 @@ cdc usage --days 7
|
|
|
106
121
|
cdc usage --api client
|
|
107
122
|
```
|
|
108
123
|
|
|
124
|
+
### 5. TOON Format (Optional - Reduces Tokens by 30-60%)
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
# Check if TOON is installed
|
|
128
|
+
cdc toon info
|
|
129
|
+
|
|
130
|
+
# Convert JSON to TOON
|
|
131
|
+
echo '{"users": [{"id": 1, "name": "Alice"}]}' | cdc toon encode
|
|
132
|
+
# Output:
|
|
133
|
+
# users[1]{id,name}:
|
|
134
|
+
# 1,Alice
|
|
135
|
+
|
|
136
|
+
# Convert file
|
|
137
|
+
cdc toon encode data.json -o data.toon
|
|
138
|
+
|
|
139
|
+
# Convert TOON back to JSON
|
|
140
|
+
cdc toon decode data.toon -o data.json
|
|
141
|
+
|
|
142
|
+
# Use in workflows
|
|
143
|
+
cat large_data.json | cdc toon encode | cdc ask "analyze this data"
|
|
144
|
+
```
|
|
145
|
+
|
|
109
146
|
## Configuration
|
|
110
147
|
|
|
111
148
|
### Global Configuration
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "claude-dev-cli"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.3.0"
|
|
8
8
|
description = "A powerful CLI tool for developers using Claude AI with multi-API routing, test generation, code review, and usage tracking"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.9"
|
|
@@ -35,11 +35,15 @@ dependencies = [
|
|
|
35
35
|
]
|
|
36
36
|
|
|
37
37
|
[project.optional-dependencies]
|
|
38
|
+
toon = [
|
|
39
|
+
"toon-format>=0.9.0",
|
|
40
|
+
]
|
|
38
41
|
dev = [
|
|
39
42
|
"pytest>=7.0.0",
|
|
40
43
|
"black>=23.0.0",
|
|
41
44
|
"ruff>=0.1.0",
|
|
42
45
|
"mypy>=1.0.0",
|
|
46
|
+
"toon-format>=0.9.0",
|
|
43
47
|
]
|
|
44
48
|
|
|
45
49
|
[project.urls]
|
|
@@ -21,6 +21,8 @@ from claude_dev_cli.commands import (
|
|
|
21
21
|
git_commit_message,
|
|
22
22
|
)
|
|
23
23
|
from claude_dev_cli.usage import UsageTracker
|
|
24
|
+
from claude_dev_cli import toon_utils
|
|
25
|
+
from claude_dev_cli.plugins import load_plugins
|
|
24
26
|
|
|
25
27
|
console = Console()
|
|
26
28
|
|
|
@@ -34,6 +36,17 @@ def main(ctx: click.Context) -> None:
|
|
|
34
36
|
ctx.obj['console'] = console
|
|
35
37
|
|
|
36
38
|
|
|
39
|
+
# Load plugins after main group is defined
|
|
40
|
+
# Silently load plugins - they'll register their commands
|
|
41
|
+
try:
|
|
42
|
+
plugins = load_plugins()
|
|
43
|
+
for plugin in plugins:
|
|
44
|
+
plugin.register_commands(main)
|
|
45
|
+
except Exception:
|
|
46
|
+
# Don't fail if plugins can't load - continue without them
|
|
47
|
+
pass
|
|
48
|
+
|
|
49
|
+
|
|
37
50
|
@main.command()
|
|
38
51
|
@click.argument('prompt', required=False)
|
|
39
52
|
@click.option('-f', '--file', type=click.Path(exists=True), help='Include file content in prompt')
|
|
@@ -394,5 +407,124 @@ def usage(ctx: click.Context, days: Optional[int], api: Optional[str]) -> None:
|
|
|
394
407
|
sys.exit(1)
|
|
395
408
|
|
|
396
409
|
|
|
410
|
+
@main.group()
|
|
411
|
+
def toon() -> None:
|
|
412
|
+
"""TOON format conversion tools."""
|
|
413
|
+
pass
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
@toon.command('encode')
|
|
417
|
+
@click.argument('input_file', type=click.Path(exists=True), required=False)
|
|
418
|
+
@click.option('-o', '--output', type=click.Path(), help='Output file')
|
|
419
|
+
@click.pass_context
|
|
420
|
+
def toon_encode(ctx: click.Context, input_file: Optional[str], output: Optional[str]) -> None:
|
|
421
|
+
"""Convert JSON to TOON format."""
|
|
422
|
+
console = ctx.obj['console']
|
|
423
|
+
|
|
424
|
+
if not toon_utils.is_toon_available():
|
|
425
|
+
console.print("[red]TOON support not installed.[/red]")
|
|
426
|
+
console.print("Install with: [cyan]pip install claude-dev-cli[toon][/cyan]")
|
|
427
|
+
sys.exit(1)
|
|
428
|
+
|
|
429
|
+
try:
|
|
430
|
+
import json
|
|
431
|
+
|
|
432
|
+
# Read input
|
|
433
|
+
if input_file:
|
|
434
|
+
with open(input_file, 'r') as f:
|
|
435
|
+
data = json.load(f)
|
|
436
|
+
elif not sys.stdin.isatty():
|
|
437
|
+
data = json.load(sys.stdin)
|
|
438
|
+
else:
|
|
439
|
+
console.print("[red]Error: No input provided[/red]")
|
|
440
|
+
console.print("Usage: cdc toon encode [FILE] or pipe JSON via stdin")
|
|
441
|
+
sys.exit(1)
|
|
442
|
+
|
|
443
|
+
# Convert to TOON
|
|
444
|
+
toon_str = toon_utils.to_toon(data)
|
|
445
|
+
|
|
446
|
+
# Output
|
|
447
|
+
if output:
|
|
448
|
+
with open(output, 'w') as f:
|
|
449
|
+
f.write(toon_str)
|
|
450
|
+
console.print(f"[green]✓[/green] Converted to TOON: {output}")
|
|
451
|
+
else:
|
|
452
|
+
console.print(toon_str)
|
|
453
|
+
|
|
454
|
+
except Exception as e:
|
|
455
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
456
|
+
sys.exit(1)
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
@toon.command('decode')
|
|
460
|
+
@click.argument('input_file', type=click.Path(exists=True), required=False)
|
|
461
|
+
@click.option('-o', '--output', type=click.Path(), help='Output file')
|
|
462
|
+
@click.pass_context
|
|
463
|
+
def toon_decode(ctx: click.Context, input_file: Optional[str], output: Optional[str]) -> None:
|
|
464
|
+
"""Convert TOON format to JSON."""
|
|
465
|
+
console = ctx.obj['console']
|
|
466
|
+
|
|
467
|
+
if not toon_utils.is_toon_available():
|
|
468
|
+
console.print("[red]TOON support not installed.[/red]")
|
|
469
|
+
console.print("Install with: [cyan]pip install claude-dev-cli[toon][/cyan]")
|
|
470
|
+
sys.exit(1)
|
|
471
|
+
|
|
472
|
+
try:
|
|
473
|
+
import json
|
|
474
|
+
|
|
475
|
+
# Read input
|
|
476
|
+
if input_file:
|
|
477
|
+
with open(input_file, 'r') as f:
|
|
478
|
+
toon_str = f.read()
|
|
479
|
+
elif not sys.stdin.isatty():
|
|
480
|
+
toon_str = sys.stdin.read()
|
|
481
|
+
else:
|
|
482
|
+
console.print("[red]Error: No input provided[/red]")
|
|
483
|
+
console.print("Usage: cdc toon decode [FILE] or pipe TOON via stdin")
|
|
484
|
+
sys.exit(1)
|
|
485
|
+
|
|
486
|
+
# Convert from TOON
|
|
487
|
+
data = toon_utils.from_toon(toon_str)
|
|
488
|
+
|
|
489
|
+
# Output
|
|
490
|
+
json_str = json.dumps(data, indent=2)
|
|
491
|
+
if output:
|
|
492
|
+
with open(output, 'w') as f:
|
|
493
|
+
f.write(json_str)
|
|
494
|
+
console.print(f"[green]✓[/green] Converted to JSON: {output}")
|
|
495
|
+
else:
|
|
496
|
+
console.print(json_str)
|
|
497
|
+
|
|
498
|
+
except Exception as e:
|
|
499
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
500
|
+
sys.exit(1)
|
|
501
|
+
|
|
502
|
+
|
|
503
|
+
@toon.command('info')
|
|
504
|
+
@click.pass_context
|
|
505
|
+
def toon_info(ctx: click.Context) -> None:
|
|
506
|
+
"""Show TOON format installation status and token savings info."""
|
|
507
|
+
console = ctx.obj['console']
|
|
508
|
+
|
|
509
|
+
if toon_utils.is_toon_available():
|
|
510
|
+
console.print("[green]✓[/green] TOON format support is installed")
|
|
511
|
+
console.print("\n[bold]About TOON:[/bold]")
|
|
512
|
+
console.print("• Token-Oriented Object Notation")
|
|
513
|
+
console.print("• 30-60% fewer tokens than JSON")
|
|
514
|
+
console.print("• Optimized for LLM prompts")
|
|
515
|
+
console.print("• Human-readable and lossless")
|
|
516
|
+
console.print("\n[bold]Usage:[/bold]")
|
|
517
|
+
console.print(" cdc toon encode data.json -o data.toon")
|
|
518
|
+
console.print(" cdc toon decode data.toon -o data.json")
|
|
519
|
+
console.print(" cat data.json | cdc toon encode")
|
|
520
|
+
else:
|
|
521
|
+
console.print("[yellow]TOON format support not installed[/yellow]")
|
|
522
|
+
console.print("\nInstall with: [cyan]pip install claude-dev-cli[toon][/cyan]")
|
|
523
|
+
console.print("\n[bold]Benefits:[/bold]")
|
|
524
|
+
console.print("• Reduce API costs by 30-60%")
|
|
525
|
+
console.print("• Faster LLM response times")
|
|
526
|
+
console.print("• Same data, fewer tokens")
|
|
527
|
+
|
|
528
|
+
|
|
397
529
|
if __name__ == '__main__':
|
|
398
530
|
main(obj={})
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""Plugin system for Claude Dev CLI."""
|
|
2
|
+
|
|
3
|
+
from typing import List
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
import importlib
|
|
6
|
+
import importlib.util
|
|
7
|
+
|
|
8
|
+
from .base import Plugin
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def discover_plugins() -> List[Plugin]:
|
|
12
|
+
"""Discover and load all plugins from the plugins directory.
|
|
13
|
+
|
|
14
|
+
Returns:
|
|
15
|
+
List of loaded plugin instances
|
|
16
|
+
"""
|
|
17
|
+
plugins = []
|
|
18
|
+
plugin_dir = Path(__file__).parent
|
|
19
|
+
|
|
20
|
+
# Look for plugin directories (those with plugin.py)
|
|
21
|
+
for item in plugin_dir.iterdir():
|
|
22
|
+
if item.is_dir() and (item / "plugin.py").exists() and item.name != "__pycache__":
|
|
23
|
+
try:
|
|
24
|
+
# Use proper import instead of spec loading to handle relative imports
|
|
25
|
+
plugin_module_name = f"claude_dev_cli.plugins.{item.name}.plugin"
|
|
26
|
+
module = importlib.import_module(plugin_module_name)
|
|
27
|
+
|
|
28
|
+
# Look for plugin registration function
|
|
29
|
+
if hasattr(module, "register_plugin"):
|
|
30
|
+
plugin = module.register_plugin()
|
|
31
|
+
plugins.append(plugin)
|
|
32
|
+
except Exception as e:
|
|
33
|
+
# Silently skip plugins that fail to load
|
|
34
|
+
pass
|
|
35
|
+
|
|
36
|
+
return plugins
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
# Alias for backwards compatibility and clearer intent
|
|
40
|
+
load_plugins = discover_plugins
|
|
41
|
+
|
|
42
|
+
__all__ = ["Plugin", "discover_plugins", "load_plugins"]
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"""Base plugin interface for Claude Dev CLI."""
|
|
2
|
+
|
|
3
|
+
from abc import ABC, abstractmethod
|
|
4
|
+
from typing import Optional
|
|
5
|
+
import click
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Plugin(ABC):
|
|
9
|
+
"""Base class for all plugins."""
|
|
10
|
+
|
|
11
|
+
def __init__(self, name: str, version: str, description: str = ""):
|
|
12
|
+
"""Initialize plugin.
|
|
13
|
+
|
|
14
|
+
Args:
|
|
15
|
+
name: Plugin name
|
|
16
|
+
version: Plugin version
|
|
17
|
+
description: Plugin description
|
|
18
|
+
"""
|
|
19
|
+
self.name = name
|
|
20
|
+
self.version = version
|
|
21
|
+
self.description = description
|
|
22
|
+
|
|
23
|
+
@abstractmethod
|
|
24
|
+
def register_commands(self, cli: click.Group) -> None:
|
|
25
|
+
"""Register plugin commands with the CLI.
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
cli: Click group to register commands to
|
|
29
|
+
"""
|
|
30
|
+
pass
|
|
31
|
+
|
|
32
|
+
def before_apply(self, original: str, proposed: str) -> Optional[str]:
|
|
33
|
+
"""Hook called before applying changes.
|
|
34
|
+
|
|
35
|
+
Args:
|
|
36
|
+
original: Original content
|
|
37
|
+
proposed: Proposed changes
|
|
38
|
+
|
|
39
|
+
Returns:
|
|
40
|
+
Modified proposed content or None to keep original
|
|
41
|
+
"""
|
|
42
|
+
return None
|
|
43
|
+
|
|
44
|
+
def after_apply(self, result: str) -> Optional[str]:
|
|
45
|
+
"""Hook called after applying changes.
|
|
46
|
+
|
|
47
|
+
Args:
|
|
48
|
+
result: Result after changes applied
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
Modified result or None to keep original
|
|
52
|
+
"""
|
|
53
|
+
return None
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"""Diff editor plugin registration."""
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
import click
|
|
7
|
+
from rich.console import Console
|
|
8
|
+
from rich.panel import Panel
|
|
9
|
+
from rich.syntax import Syntax
|
|
10
|
+
|
|
11
|
+
from claude_dev_cli.plugins.base import Plugin
|
|
12
|
+
from .viewer import DiffViewer
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class DiffEditorPlugin(Plugin):
|
|
16
|
+
"""Interactive diff editor plugin."""
|
|
17
|
+
|
|
18
|
+
def __init__(self):
|
|
19
|
+
super().__init__(
|
|
20
|
+
name="diff-editor",
|
|
21
|
+
version="0.1.0",
|
|
22
|
+
description="Interactive diff viewer for reviewing code changes"
|
|
23
|
+
)
|
|
24
|
+
self.console = Console()
|
|
25
|
+
|
|
26
|
+
def register_commands(self, cli: click.Group) -> None:
|
|
27
|
+
"""Register diff editor commands."""
|
|
28
|
+
|
|
29
|
+
@cli.command("diff")
|
|
30
|
+
@click.argument("original", type=click.Path(exists=True))
|
|
31
|
+
@click.argument("proposed", type=click.Path(exists=True))
|
|
32
|
+
@click.option(
|
|
33
|
+
"--keybindings",
|
|
34
|
+
"-k",
|
|
35
|
+
type=click.Choice(["nvim", "fresh", "auto"]),
|
|
36
|
+
default="auto",
|
|
37
|
+
help="Keybinding mode (nvim, fresh, or auto-detect)"
|
|
38
|
+
)
|
|
39
|
+
@click.option(
|
|
40
|
+
"--output",
|
|
41
|
+
"-o",
|
|
42
|
+
type=click.Path(),
|
|
43
|
+
help="Output file path for accepted changes"
|
|
44
|
+
)
|
|
45
|
+
def diff_command(
|
|
46
|
+
original: str,
|
|
47
|
+
proposed: str,
|
|
48
|
+
keybindings: str,
|
|
49
|
+
output: Optional[str]
|
|
50
|
+
) -> None:
|
|
51
|
+
"""Interactively review differences between two files."""
|
|
52
|
+
viewer = DiffViewer(
|
|
53
|
+
original_path=Path(original),
|
|
54
|
+
proposed_path=Path(proposed),
|
|
55
|
+
keybinding_mode=keybindings,
|
|
56
|
+
console=self.console
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
result = viewer.run()
|
|
60
|
+
|
|
61
|
+
if result and output:
|
|
62
|
+
with open(output, "w") as f:
|
|
63
|
+
f.write(result)
|
|
64
|
+
self.console.print(f"\n[green]✓[/green] Changes saved to: {output}")
|
|
65
|
+
elif result:
|
|
66
|
+
self.console.print("\n[bold]Final result:[/bold]")
|
|
67
|
+
self.console.print(result)
|
|
68
|
+
|
|
69
|
+
@cli.command("apply-diff")
|
|
70
|
+
@click.argument("file_path", type=click.Path(exists=True))
|
|
71
|
+
@click.option(
|
|
72
|
+
"--keybindings",
|
|
73
|
+
"-k",
|
|
74
|
+
type=click.Choice(["nvim", "fresh", "auto"]),
|
|
75
|
+
default="auto",
|
|
76
|
+
help="Keybinding mode"
|
|
77
|
+
)
|
|
78
|
+
@click.option(
|
|
79
|
+
"--in-place",
|
|
80
|
+
"-i",
|
|
81
|
+
is_flag=True,
|
|
82
|
+
help="Edit file in place"
|
|
83
|
+
)
|
|
84
|
+
def apply_diff_command(
|
|
85
|
+
file_path: str,
|
|
86
|
+
keybindings: str,
|
|
87
|
+
in_place: bool
|
|
88
|
+
) -> None:
|
|
89
|
+
"""Apply AI-suggested changes to a file interactively."""
|
|
90
|
+
self.console.print(
|
|
91
|
+
f"[yellow]This would apply changes to {file_path} interactively[/yellow]"
|
|
92
|
+
)
|
|
93
|
+
self.console.print("Feature coming soon!")
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def register_plugin() -> Plugin:
|
|
97
|
+
"""Register the diff editor plugin."""
|
|
98
|
+
return DiffEditorPlugin()
|