-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
198 lines (166 loc) · 6.4 KB
/
cli.py
File metadata and controls
198 lines (166 loc) · 6.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
"""
CLI entry point for recon-magic framework.
Use this when using recon-magic framework locally.
"""
import argparse
import json
import os
import sys
import tempfile
from pathlib import Path
from dotenv import load_dotenv
from main import run_workflow, DEFAULT_LOOP_HARDCAP
# Load environment variables from .env file
load_dotenv()
def main():
"""
Main CLI entry point.
Usage:
recon --workflow <workflow_file> [options]
recon --prompt "your prompt" [options]
"""
parser = argparse.ArgumentParser(
description='Execute a recon-magic workflow or direct prompt',
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
# Run a workflow by name
recon-magic-framework --workflow audit # Uses framework's workflows/audit.json
recon-magic-framework --workflow workflow-loop # Uses framework's workflows/workflow-loop.json
recon-magic-framework --workflow ./my-workflow.json --dangerous --cap 10
recon-magic-framework --workflow /absolute/path/to/workflow.json --logs ./custom-logs
# Run a direct prompt
recon-magic-framework --prompt "Analyze this code for security issues" --dangerous
recon-magic-framework --prompt "Add tests" --model-type CLAUDE_CODE --repo ./my-repo
recon-magic-framework --prompt "npm run build" --model-type PROGRAM
# Resume from a specific step by ID
recon-magic-framework --workflow audit --resume-from-step-id "audit:3"
Workflows can be run from any directory.
"""
)
# Mutually exclusive group for workflow vs prompt
mode_group = parser.add_mutually_exclusive_group(required=True)
mode_group.add_argument(
'--workflow',
type=str,
help='Workflow name (e.g. "audit") or path to workflow JSON file (relative or absolute)'
)
mode_group.add_argument(
'--prompt',
type=str,
help='Direct prompt to execute (creates a single-step workflow)'
)
parser.add_argument(
'--model-type',
type=str,
default='CLAUDE_CODE',
choices=['CLAUDE_CODE', 'OPENCODE', 'PROGRAM'],
help='Model type for direct prompt mode (default: CLAUDE_CODE)'
)
parser.add_argument(
'--dangerous',
action='store_true',
help='Enable dangerous mode (skip permissions)'
)
parser.add_argument(
'--cap',
type=int,
default=DEFAULT_LOOP_HARDCAP,
help=f'Maximum number of times a decision step can loop (default: {DEFAULT_LOOP_HARDCAP})'
)
parser.add_argument(
'--logs',
type=str,
default=None,
help='Directory to store logs (default: framework logs/)'
)
parser.add_argument(
'--repo',
type=str,
default=None,
help='Path to repository directory (default: current directory)'
)
parser.add_argument(
'--resume-from-step-id',
type=str,
default=None,
metavar='ID',
help='Resume workflow from step with internal ID (e.g., "audit:2", "workflow-fuzzing:3")'
)
args = parser.parse_args()
# Store the repository root (use --repo if provided, otherwise current dir)
repo_root = args.repo if args.repo else os.getcwd()
if args.repo:
repo_root = os.path.abspath(args.repo)
# Get framework root (where this cli.py is installed)
framework_root = Path(__file__).parent.resolve()
# Set environment variable for framework root so other modules can resolve paths
os.environ['RECON_FRAMEWORK_ROOT'] = str(framework_root)
# Set prompts directory (where agent reference documents live)
os.environ['PROMPTS_DIR'] = str(framework_root / 'prompts')
# Determine workflow file
if args.prompt:
# Direct prompt mode - create dynamic workflow
workflow = {
"name": "Direct Prompt Execution",
"steps": [{
"type": "task",
"name": "Execute Direct Prompt",
"description": f"Direct prompt execution with {args.model_type}",
"prompt": args.prompt,
"model": {
"type": args.model_type,
"model": "inherit"
},
"shouldCreateSummary": False,
"shouldCommitChanges": True
}]
}
# Write to temp file
with tempfile.NamedTemporaryFile(mode='w', suffix='.json', delete=False) as f:
json.dump(workflow, f, indent=2)
workflow_file = f.name
print(f"🎯 Target repo: {repo_root}")
print(f"💬 Direct Prompt Mode - Model: {args.model_type}")
print(f"📝 Prompt: {args.prompt[:100]}..." if len(args.prompt) > 100 else f"📝 Prompt: {args.prompt}")
else:
# Workflow mode - resolve workflow file
workflow_file = args.workflow
# If it's just a name (no path separators), look in framework workflows/
if os.sep not in workflow_file and '/' not in workflow_file:
# Look in framework's workflows directory
framework_workflow = framework_root / 'workflows' / f"{workflow_file}.json"
if framework_workflow.exists():
workflow_file = str(framework_workflow)
else:
print(f"❌ Error: Workflow '{workflow_file}.json' not found in framework workflows/")
sys.exit(1)
else:
# If relative path, resolve it relative to current directory (not framework)
if not os.path.isabs(workflow_file):
workflow_file = os.path.abspath(workflow_file)
# Check if workflow file exists
if not os.path.exists(workflow_file):
print(f"❌ Error: Workflow file not found: {workflow_file}")
sys.exit(1)
print(f"🎯 Target repo: {repo_root}")
print(f"📋 Workflow: {workflow_file}")
if args.dangerous:
print(f"⚠️ Dangerous mode: ENABLED")
if args.logs:
print(f"📝 Logs directory: {args.logs}")
if args.resume_from_step_id:
print(f"🔄 Resume mode: Starting from step ID '{args.resume_from_step_id}'")
print()
# Run the workflow
exit_code = run_workflow(
workflow_file=workflow_file,
dangerous=args.dangerous,
loop_hardcap=args.cap,
logs_dir=args.logs,
repo_path=repo_root,
resume_from_step_id=args.resume_from_step_id
)
sys.exit(exit_code)
if __name__ == "__main__":
main()