lonkero 3.7.0

Web scanner built for actual pentests. Fast, modular, Rust.
Documentation
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
// Copyright (c) 2026 Bountyy Oy. All rights reserved.
// This software is proprietary and confidential.

//! Tool definitions that expose Lonkero capabilities to the LLM.
//!
//! Each tool maps to a specific lonkero CLI invocation.
//! The AI agent calls these tools to perform surgical security testing.

use serde::{Deserialize, Serialize};
use serde_json::json;

/// A tool definition the LLM can invoke.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ToolDefinition {
    pub name: String,
    pub description: String,
    pub input_schema: serde_json::Value,
}

/// Get all tool definitions for the LLM.
/// These give the AI surgical control over lonkero's scanners.
pub fn get_tool_definitions() -> Vec<ToolDefinition> {
    vec![
        // ===================================================================
        // RECONNAISSANCE
        // ===================================================================
        ToolDefinition {
            name: "recon".into(),
            description: "Quick reconnaissance scan. Checks HTTP headers, SSL/TLS, security headers, \
                and basic info disclosure. Does NOT run injection tests. Use this first on a new target \
                to understand the tech stack and attack surface before deeper testing."
                .into(),
            input_schema: json!({
                "type": "object",
                "properties": {
                    "url": {
                        "type": "string",
                        "description": "Target URL to scan (e.g. https://example.com)"
                    }
                },
                "required": ["url"]
            }),
        },
        ToolDefinition {
            name: "crawl".into(),
            description: "Crawl the target to discover endpoints, forms, parameters, and API routes. \
                Returns a list of discovered URLs with their parameters. Use this to map the attack \
                surface before running targeted scans. Does NOT run any vulnerability tests."
                .into(),
            input_schema: json!({
                "type": "object",
                "properties": {
                    "url": {
                        "type": "string",
                        "description": "Target URL to crawl"
                    },
                    "max_depth": {
                        "type": "integer",
                        "description": "Maximum crawl depth (default: 3)",
                        "default": 3
                    }
                },
                "required": ["url"]
            }),
        },
        ToolDefinition {
            name: "subdomain_enum".into(),
            description: "Enumerate subdomains for a domain. Discovers additional attack surface \
                like staging, admin, api subdomains. Use when you want to expand the scope."
                .into(),
            input_schema: json!({
                "type": "object",
                "properties": {
                    "domain": {
                        "type": "string",
                        "description": "Domain to enumerate subdomains for (e.g. example.com)"
                    }
                },
                "required": ["domain"]
            }),
        },

        // ===================================================================
        // SINGLE-MODULE TARGETED SCANS
        // ===================================================================
        ToolDefinition {
            name: "scan_xss".into(),
            description: "Test a specific URL/endpoint for Cross-Site Scripting (XSS). \
                Uses proof-based detection: identifies reflection context, tests escape handling, \
                and confirms exploitability without a browser. Fast and accurate."
                .into(),
            input_schema: json!({
                "type": "object",
                "properties": {
                    "url": {
                        "type": "string",
                        "description": "URL with parameters to test (e.g. https://example.com/search?q=test)"
                    },
                    "intensity": {
                        "type": "string",
                        "enum": ["minimal", "standard", "extended", "maximum"],
                        "description": "Payload intensity. Use 'minimal' for quick check, 'maximum' for WAF bypass attempts.",
                        "default": "standard"
                    }
                },
                "required": ["url"]
            }),
        },
        ToolDefinition {
            name: "scan_sqli".into(),
            description: "Test a specific URL/endpoint for SQL Injection. \
                Uses OOBZero engine: boolean differential, arithmetic evaluation, quote cancellation, \
                and time-based correlation. No external callback server needed."
                .into(),
            input_schema: json!({
                "type": "object",
                "properties": {
                    "url": {
                        "type": "string",
                        "description": "URL with parameters to test"
                    },
                    "intensity": {
                        "type": "string",
                        "enum": ["minimal", "standard", "extended", "maximum"],
                        "default": "standard"
                    }
                },
                "required": ["url"]
            }),
        },
        ToolDefinition {
            name: "scan_ssrf".into(),
            description: "Test for Server-Side Request Forgery (SSRF). \
                Checks if the server can be tricked into making requests to internal services. \
                Tests both direct and blind SSRF."
                .into(),
            input_schema: json!({
                "type": "object",
                "properties": {
                    "url": {
                        "type": "string",
                        "description": "URL with parameters to test"
                    },
                    "intensity": {
                        "type": "string",
                        "enum": ["minimal", "standard", "extended", "maximum"],
                        "default": "standard"
                    }
                },
                "required": ["url"]
            }),
        },
        ToolDefinition {
            name: "scan_idor".into(),
            description: "Test for Insecure Direct Object Reference (IDOR) and Broken Object Level \
                Authorization (BOLA). Checks if resources belonging to other users can be accessed. \
                Works best with multi-role credentials."
                .into(),
            input_schema: json!({
                "type": "object",
                "properties": {
                    "url": {
                        "type": "string",
                        "description": "URL with object reference to test (e.g. /api/user/123)"
                    },
                    "intensity": {
                        "type": "string",
                        "enum": ["minimal", "standard", "extended", "maximum"],
                        "default": "standard"
                    }
                },
                "required": ["url"]
            }),
        },
        ToolDefinition {
            name: "scan_auth".into(),
            description: "Test authentication mechanisms: JWT vulnerabilities (alg:none, key confusion), \
                OAuth misconfigurations, session management issues, auth bypass techniques. \
                Use on login pages, token endpoints, and authenticated routes."
                .into(),
            input_schema: json!({
                "type": "object",
                "properties": {
                    "url": {
                        "type": "string",
                        "description": "URL to test (login page, token endpoint, or authenticated route)"
                    },
                    "intensity": {
                        "type": "string",
                        "enum": ["minimal", "standard", "extended", "maximum"],
                        "default": "standard"
                    }
                },
                "required": ["url"]
            }),
        },
        ToolDefinition {
            name: "scan_injection".into(),
            description: "Test for various injection vulnerabilities: command injection, SSTI, \
                NoSQL injection, XXE, LDAP injection, code injection. Use when a parameter \
                might flow into server-side processing."
                .into(),
            input_schema: json!({
                "type": "object",
                "properties": {
                    "url": {
                        "type": "string",
                        "description": "URL with parameters to test"
                    },
                    "intensity": {
                        "type": "string",
                        "enum": ["minimal", "standard", "extended", "maximum"],
                        "default": "standard"
                    }
                },
                "required": ["url"]
            }),
        },
        ToolDefinition {
            name: "scan_graphql".into(),
            description: "Test GraphQL endpoints: introspection enabled, batching attacks, \
                query depth/cost abuse, field suggestion exploitation. Use when you detect \
                a GraphQL endpoint (typically /graphql)."
                .into(),
            input_schema: json!({
                "type": "object",
                "properties": {
                    "url": {
                        "type": "string",
                        "description": "GraphQL endpoint URL"
                    },
                    "intensity": {
                        "type": "string",
                        "enum": ["minimal", "standard", "extended", "maximum"],
                        "default": "standard"
                    }
                },
                "required": ["url"]
            }),
        },
        ToolDefinition {
            name: "scan_api".into(),
            description: "Test API security: broken function level auth (BFLA), API versioning attacks, \
                mass assignment, OpenAPI spec analysis. Use on REST API endpoints."
                .into(),
            input_schema: json!({
                "type": "object",
                "properties": {
                    "url": {
                        "type": "string",
                        "description": "API endpoint URL"
                    },
                    "intensity": {
                        "type": "string",
                        "enum": ["minimal", "standard", "extended", "maximum"],
                        "default": "standard"
                    }
                },
                "required": ["url"]
            }),
        },
        ToolDefinition {
            name: "scan_framework".into(),
            description: "Run framework-specific security checks for a detected technology. \
                Tests known vulnerabilities, misconfigurations, and default credentials \
                specific to the framework."
                .into(),
            input_schema: json!({
                "type": "object",
                "properties": {
                    "url": {
                        "type": "string",
                        "description": "Target URL"
                    },
                    "framework": {
                        "type": "string",
                        "enum": ["wordpress", "drupal", "joomla", "laravel", "django",
                                 "rails", "nextjs", "sveltekit", "react", "express",
                                 "spring", "fastapi", "go_frameworks"],
                        "description": "Framework to test for"
                    }
                },
                "required": ["url", "framework"]
            }),
        },
        ToolDefinition {
            name: "scan_waf_bypass".into(),
            description: "Attempt WAF bypass techniques. Use after discovering a WAF is blocking \
                your payloads. Tests encoding tricks, HTTP method switching, header manipulation, \
                and payload mutation. Use 'maximum' intensity for thorough bypass testing."
                .into(),
            input_schema: json!({
                "type": "object",
                "properties": {
                    "url": {
                        "type": "string",
                        "description": "URL where WAF is blocking payloads"
                    }
                },
                "required": ["url"]
            }),
        },
        ToolDefinition {
            name: "scan_business_logic".into(),
            description: "Test for business logic vulnerabilities: race conditions, price manipulation, \
                workflow bypass, privilege escalation. Use on e-commerce, payment, and state-changing \
                endpoints."
                .into(),
            input_schema: json!({
                "type": "object",
                "properties": {
                    "url": {
                        "type": "string",
                        "description": "URL to test for business logic issues"
                    },
                    "intensity": {
                        "type": "string",
                        "enum": ["minimal", "standard", "extended", "maximum"],
                        "default": "standard"
                    }
                },
                "required": ["url"]
            }),
        },

        // ===================================================================
        // ADVANCED / SPECIFIC SCANNERS
        // ===================================================================
        ToolDefinition {
            name: "scan_custom".into(),
            description: "Run one or more specific scanner modules by ID. Use this when you need \
                a specific scanner not covered by the other tools, or when you want to combine \
                multiple specific scanners. Available module IDs include: \
                cors_misconfig, cache_poisoning, crlf_injection, open_redirect, file_upload, \
                prototype_pollution, deserialization, host_header_injection, http_smuggling, \
                websocket_scanner, timing_attacks, csp_bypass, postmessage_vulns, \
                web_cache_deception, dom_clobbering, dom_xss_scanner, subdomain_takeover, \
                account_takeover, password_reset_poisoning, twofa_bypass, oidc_scanner, \
                second_order_injection, readme_prompt_injection, and more."
                .into(),
            input_schema: json!({
                "type": "object",
                "properties": {
                    "url": {
                        "type": "string",
                        "description": "Target URL"
                    },
                    "modules": {
                        "type": "array",
                        "items": { "type": "string" },
                        "description": "List of scanner module IDs to run"
                    },
                    "intensity": {
                        "type": "string",
                        "enum": ["minimal", "standard", "extended", "maximum"],
                        "default": "standard"
                    }
                },
                "required": ["url", "modules"]
            }),
        },

        // ===================================================================
        // FULL SCAN
        // ===================================================================
        ToolDefinition {
            name: "full_scan".into(),
            description: "Run a full intelligent scan with all modules. This runs tech detection, \
                crawling, endpoint deduplication, per-parameter risk scoring, and ALL applicable \
                scanners. Only use when explicitly asked for a full scan — prefer targeted scans \
                for interactive testing."
                .into(),
            input_schema: json!({
                "type": "object",
                "properties": {
                    "url": {
                        "type": "string",
                        "description": "Target URL"
                    },
                    "intensity": {
                        "type": "string",
                        "enum": ["minimal", "standard", "extended", "maximum"],
                        "description": "Global payload intensity override (default: auto/intelligent)",
                        "default": "auto"
                    },
                    "max_depth": {
                        "type": "integer",
                        "description": "Maximum crawl depth",
                        "default": 3
                    }
                },
                "required": ["url"]
            }),
        },

        // ===================================================================
        // RESULTS & REPORTING
        // ===================================================================
        ToolDefinition {
            name: "list_findings".into(),
            description: "List all vulnerabilities found in this session so far. \
                Returns findings grouped by severity with details. Use to review progress \
                and decide what to investigate next."
                .into(),
            input_schema: json!({
                "type": "object",
                "properties": {},
                "required": []
            }),
        },
        ToolDefinition {
            name: "generate_report".into(),
            description: "Generate a formatted report of all findings from this session. \
                Available formats: json, html, pdf, sarif, markdown, csv, xlsx."
                .into(),
            input_schema: json!({
                "type": "object",
                "properties": {
                    "format": {
                        "type": "string",
                        "enum": ["json", "html", "pdf", "sarif", "markdown", "csv", "xlsx"],
                        "description": "Output format",
                        "default": "json"
                    },
                    "output_path": {
                        "type": "string",
                        "description": "File path to write the report to (optional, prints to stdout if omitted)"
                    }
                },
                "required": ["format"]
            }),
        },
        ToolDefinition {
            name: "list_modules".into(),
            description: "List all available scanner modules with their IDs and descriptions. \
                Use when you need to check what scanners are available or find the right module \
                ID for a specific test."
                .into(),
            input_schema: json!({
                "type": "object",
                "properties": {},
                "required": []
            }),
        },

        // ===================================================================
        // CAT 1: MEMORY & SESSION MANAGEMENT
        // ===================================================================
        ToolDefinition {
            name: "save_session".into(),
            description: "Save the current session state to a JSON file. Persists all findings, \
                hypotheses, attack plans, knowledge graph, and audit log. Use to checkpoint \
                progress or before ending a session that may be resumed later."
                .into(),
            input_schema: json!({
                "type": "object",
                "properties": {
                    "path": {
                        "type": "string",
                        "description": "File path to save the session to (e.g. session-example.com.json)"
                    }
                },
                "required": ["path"]
            }),
        },
        ToolDefinition {
            name: "load_session".into(),
            description: "Load a previously saved session from a JSON file. Restores all findings, \
                hypotheses, knowledge graph, and attack patterns. Use to resume a previous assessment."
                .into(),
            input_schema: json!({
                "type": "object",
                "properties": {
                    "path": {
                        "type": "string",
                        "description": "File path to load the session from"
                    }
                },
                "required": ["path"]
            }),
        },

        // ===================================================================
        // CAT 2: REASONING & PLANNING
        // ===================================================================
        ToolDefinition {
            name: "add_hypothesis".into(),
            description: "Record a hypothesis about the target. Use to track your reasoning — \
                e.g. 'The API likely uses JWT with a weak secret based on the x-powered-by header'. \
                Hypotheses can be confirmed or refuted with evidence as testing proceeds."
                .into(),
            input_schema: json!({
                "type": "object",
                "properties": {
                    "description": {
                        "type": "string",
                        "description": "The hypothesis (e.g. 'JWT tokens use HS256 with a weak/default secret')"
                    },
                    "basis": {
                        "type": "string",
                        "description": "What evidence or reasoning led to this hypothesis"
                    }
                },
                "required": ["description", "basis"]
            }),
        },
        ToolDefinition {
            name: "update_hypothesis".into(),
            description: "Update a hypothesis with new evidence. Mark it as confirmed or refuted \
                based on scan results. This maintains the reasoning chain for the audit log."
                .into(),
            input_schema: json!({
                "type": "object",
                "properties": {
                    "hypothesis_id": {
                        "type": "string",
                        "description": "Hypothesis ID to update (e.g. H-1)"
                    },
                    "confirmed": {
                        "type": "boolean",
                        "description": "true if evidence supports the hypothesis, false if it refutes it"
                    },
                    "evidence": {
                        "type": "string",
                        "description": "The evidence that confirms or refutes the hypothesis"
                    }
                },
                "required": ["hypothesis_id", "confirmed", "evidence"]
            }),
        },
        ToolDefinition {
            name: "list_hypotheses".into(),
            description: "List all hypotheses with their current status (proposed, testing, \
                confirmed, refuted). Shows confidence scores and evidence for/against."
                .into(),
            input_schema: json!({
                "type": "object",
                "properties": {},
                "required": []
            }),
        },
        ToolDefinition {
            name: "log_reasoning".into(),
            description: "Record a reasoning step in the audit log. Use to document WHY you \
                chose a particular scan or approach. Creates an audit trail of decision-making."
                .into(),
            input_schema: json!({
                "type": "object",
                "properties": {
                    "action": {
                        "type": "string",
                        "description": "What you are about to do"
                    },
                    "reasoning": {
                        "type": "string",
                        "description": "Why you chose this action over alternatives"
                    }
                },
                "required": ["action", "reasoning"]
            }),
        },

        // ===================================================================
        // CAT 3: CUSTOM HTTP REQUESTS
        // ===================================================================
        ToolDefinition {
            name: "send_http".into(),
            description: "Send a custom HTTP request. Use for manual probing when the scanner \
                tools don't cover your exact need — e.g. testing a specific header injection, \
                sending a crafted JWT, or checking a specific API endpoint behavior. \
                Returns status code, headers, and body."
                .into(),
            input_schema: json!({
                "type": "object",
                "properties": {
                    "url": {
                        "type": "string",
                        "description": "Target URL"
                    },
                    "method": {
                        "type": "string",
                        "enum": ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"],
                        "description": "HTTP method",
                        "default": "GET"
                    },
                    "headers": {
                        "type": "object",
                        "description": "Custom headers to include (key-value pairs)",
                        "additionalProperties": { "type": "string" }
                    },
                    "body": {
                        "type": "string",
                        "description": "Request body (for POST/PUT/PATCH)"
                    }
                },
                "required": ["url"]
            }),
        },

        // ===================================================================
        // CAT 4: ANALYSIS & POST-PROCESSING
        // ===================================================================
        ToolDefinition {
            name: "analyze_findings".into(),
            description: "Run analysis on current findings: false-positive triage, exploit chain \
                synthesis, and severity re-assessment. Call this after a batch of scans to get \
                a refined view of results. Returns FP-flagged findings, identified chains, and \
                any severity adjustments."
                .into(),
            input_schema: json!({
                "type": "object",
                "properties": {
                    "actions": {
                        "type": "array",
                        "items": {
                            "type": "string",
                            "enum": ["triage_fp", "synthesize_chains", "reassess_severity", "all"]
                        },
                        "description": "Which analyses to run. Use 'all' to run everything.",
                        "default": ["all"]
                    }
                },
                "required": []
            }),
        },

        // ===================================================================
        // CAT 6: SCOPE & GUARDRAILS
        // ===================================================================
        ToolDefinition {
            name: "check_scope".into(),
            description: "Check if a URL is within the configured scope before scanning. \
                Returns whether the URL is allowed. Use this before scanning third-party \
                resources or URLs outside the original target domain."
                .into(),
            input_schema: json!({
                "type": "object",
                "properties": {
                    "url": {
                        "type": "string",
                        "description": "URL to check"
                    }
                },
                "required": ["url"]
            }),
        },
        ToolDefinition {
            name: "configure_scope".into(),
            description: "Modify the scope configuration. Add or remove allowed/excluded patterns, \
                set rate limits, or adjust maximum intensity. Use when the user expands or restricts \
                the testing scope."
                .into(),
            input_schema: json!({
                "type": "object",
                "properties": {
                    "add_allowed": {
                        "type": "array",
                        "items": { "type": "string" },
                        "description": "URL patterns to add to the allowed list"
                    },
                    "add_excluded": {
                        "type": "array",
                        "items": { "type": "string" },
                        "description": "URL patterns to add to the exclusion list"
                    },
                    "max_intensity": {
                        "type": "string",
                        "enum": ["minimal", "standard", "extended", "maximum"],
                        "description": "Maximum allowed scan intensity"
                    },
                    "rate_limit_rpm": {
                        "type": "integer",
                        "description": "Maximum requests per minute (0 = unlimited)"
                    },
                    "allow_third_party": {
                        "type": "boolean",
                        "description": "Whether to allow scanning third-party services"
                    }
                },
                "required": []
            }),
        },

        // ===================================================================
        // CAT 7: USER EXPERIENCE
        // ===================================================================
        ToolDefinition {
            name: "show_progress".into(),
            description: "Show current assessment progress: phase, completion percentage, \
                scan count, finding count, and knowledge graph size. Use to give the user \
                a clear picture of where the assessment stands."
                .into(),
            input_schema: json!({
                "type": "object",
                "properties": {},
                "required": []
            }),
        },
        ToolDefinition {
            name: "export_session".into(),
            description: "Export the full session as a markdown document including conversation \
                history, findings, exploit chains, and audit log. Useful for generating a \
                comprehensive assessment record. Sensitive data is automatically redacted."
                .into(),
            input_schema: json!({
                "type": "object",
                "properties": {
                    "output_path": {
                        "type": "string",
                        "description": "File path to write the export (optional, returns content if omitted)"
                    }
                },
                "required": []
            }),
        },
        ToolDefinition {
            name: "get_audit_log".into(),
            description: "Retrieve the full audit log of all reasoning decisions and actions \
                taken during this session. Shows the decision chain: what was done, why, and \
                what resulted."
                .into(),
            input_schema: json!({
                "type": "object",
                "properties": {},
                "required": []
            }),
        },
    ]
}

// ---------------------------------------------------------------------------
// Tool-to-CLI mapping: translates a tool call to lonkero CLI arguments
// ---------------------------------------------------------------------------

/// Maps a tool call name + input to the corresponding lonkero CLI arguments.
pub fn tool_to_cli_args(tool_name: &str, input: &serde_json::Value) -> Option<Vec<String>> {
    let url = input["url"].as_str().unwrap_or("").to_string();
    let intensity = input["intensity"].as_str().unwrap_or("standard");

    match tool_name {
        "recon" => Some(vec![
            "scan".into(),
            url,
            "--only".into(), "http_headers".into(),
            "--only".into(), "ssl_checker".into(),
            "--only".into(), "security_headers".into(),
            "--only".into(), "info_disclosure_basic".into(),
            "--only".into(), "cors_basic".into(),
            "--only".into(), "clickjacking".into(),
            "--crawl".into(), "false".into(),
            "--format".into(), "json".into(),
        ]),

        "crawl" => {
            let depth = input["max_depth"].as_u64().unwrap_or(3).to_string();
            Some(vec![
                "scan".into(),
                url,
                "--only".into(), "endpoint_discovery".into(),
                "--crawl".into(), "true".into(),
                "--max-depth".into(), depth,
                "--format".into(), "json".into(),
            ])
        }

        "subdomain_enum" => {
            let domain = input["domain"].as_str().unwrap_or("").to_string();
            Some(vec![
                "scan".into(),
                format!("https://{}", domain),
                "--subdomains".into(),
                "--only".into(), "dns_enum".into(),
                "--crawl".into(), "false".into(),
                "--format".into(), "json".into(),
            ])
        }

        "scan_xss" => Some(vec![
            "scan".into(),
            url,
            "--only".into(), "proof_xss_scanner".into(),
            "--only".into(), "reflection_xss_scanner".into(),
            "--only".into(), "xss_scanner".into(),
            "--only".into(), "dom_xss_scanner".into(),
            "--payload-intensity".into(), intensity.into(),
            "--crawl".into(), "false".into(),
            "--format".into(), "json".into(),
        ]),

        "scan_sqli" => Some(vec![
            "scan".into(),
            url,
            "--only".into(), "sqli_scanner".into(),
            "--payload-intensity".into(), intensity.into(),
            "--crawl".into(), "false".into(),
            "--format".into(), "json".into(),
        ]),

        "scan_ssrf" => Some(vec![
            "scan".into(),
            url,
            "--only".into(), "ssrf_scanner".into(),
            "--only".into(), "ssrf_blind".into(),
            "--payload-intensity".into(), intensity.into(),
            "--crawl".into(), "false".into(),
            "--format".into(), "json".into(),
        ]),

        "scan_idor" => Some(vec![
            "scan".into(),
            url,
            "--only".into(), "idor_scanner".into(),
            "--only".into(), "idor_analyzer".into(),
            "--only".into(), "bola_scanner".into(),
            "--payload-intensity".into(), intensity.into(),
            "--crawl".into(), "false".into(),
            "--format".into(), "json".into(),
        ]),

        "scan_auth" => Some(vec![
            "scan".into(),
            url,
            "--only".into(), "jwt_scanner".into(),
            "--only".into(), "jwt_analyzer".into(),
            "--only".into(), "oauth_scanner".into(),
            "--only".into(), "saml_scanner".into(),
            "--only".into(), "auth_bypass".into(),
            "--only".into(), "session_management".into(),
            "--only".into(), "session_analyzer".into(),
            "--only".into(), "mfa_scanner".into(),
            "--only".into(), "oidc_scanner".into(),
            "--only".into(), "advanced_auth".into(),
            "--only".into(), "auth_flow_tester".into(),
            "--payload-intensity".into(), intensity.into(),
            "--crawl".into(), "false".into(),
            "--format".into(), "json".into(),
        ]),

        "scan_injection" => Some(vec![
            "scan".into(),
            url,
            "--only".into(), "command_injection".into(),
            "--only".into(), "ssti_scanner".into(),
            "--only".into(), "ssti_advanced".into(),
            "--only".into(), "nosql_scanner".into(),
            "--only".into(), "xxe_scanner".into(),
            "--only".into(), "ldap_injection".into(),
            "--only".into(), "code_injection".into(),
            "--only".into(), "path_traversal".into(),
            "--only".into(), "xml_injection".into(),
            "--only".into(), "xpath_injection".into(),
            "--only".into(), "ssi_injection".into(),
            "--payload-intensity".into(), intensity.into(),
            "--crawl".into(), "false".into(),
            "--format".into(), "json".into(),
        ]),

        "scan_graphql" => Some(vec![
            "scan".into(),
            url,
            "--only".into(), "graphql_scanner".into(),
            "--only".into(), "graphql_batching".into(),
            "--payload-intensity".into(), intensity.into(),
            "--crawl".into(), "false".into(),
            "--format".into(), "json".into(),
        ]),

        "scan_api" => Some(vec![
            "scan".into(),
            url,
            "--only".into(), "api_security".into(),
            "--only".into(), "api_gateway".into(),
            "--only".into(), "api_versioning".into(),
            "--only".into(), "api_fuzzer".into(),
            "--only".into(), "broken_function_auth".into(),
            "--only".into(), "mass_assignment".into(),
            "--only".into(), "mass_assignment_advanced".into(),
            "--only".into(), "openapi_analyzer".into(),
            "--payload-intensity".into(), intensity.into(),
            "--crawl".into(), "false".into(),
            "--format".into(), "json".into(),
        ]),

        "scan_framework" => {
            let framework = input["framework"].as_str().unwrap_or("nextjs");
            let module = format!("{}_scanner", framework);
            Some(vec![
                "scan".into(),
                url,
                "--only".into(), module,
                "--only".into(), "framework_vulns".into(),
                "--crawl".into(), "false".into(),
                "--format".into(), "json".into(),
            ])
        }

        "scan_waf_bypass" => Some(vec![
            "scan".into(),
            url,
            "--only".into(), "waf_bypass".into(),
            "--payload-intensity".into(), "maximum".into(),
            "--crawl".into(), "false".into(),
            "--format".into(), "json".into(),
        ]),

        "scan_business_logic" => Some(vec![
            "scan".into(),
            url,
            "--only".into(), "business_logic".into(),
            "--only".into(), "race_condition".into(),
            "--only".into(), "mass_assignment".into(),
            "--only".into(), "mass_assignment_advanced".into(),
            "--only".into(), "timing_attacks".into(),
            "--payload-intensity".into(), intensity.into(),
            "--crawl".into(), "false".into(),
            "--format".into(), "json".into(),
        ]),

        "scan_custom" => {
            let mut args = vec!["scan".into(), url];
            if let Some(modules) = input["modules"].as_array() {
                for module in modules {
                    if let Some(m) = module.as_str() {
                        args.push("--only".into());
                        args.push(m.to_string());
                    }
                }
            }
            args.extend_from_slice(&[
                "--payload-intensity".into(), intensity.into(),
                "--crawl".into(), "false".into(),
                "--format".into(), "json".into(),
            ]);
            Some(args)
        }

        "full_scan" => {
            let depth = input["max_depth"].as_u64().unwrap_or(3).to_string();
            let mut args = vec![
                "scan".into(),
                url,
                "--crawl".into(), "true".into(),
                "--max-depth".into(), depth,
                "--format".into(), "json".into(),
            ];
            if intensity != "auto" {
                args.extend_from_slice(&[
                    "--payload-intensity".into(), intensity.into(),
                ]);
            }
            Some(args)
        }

        // Non-CLI tools handled in agent.rs (instant, no subprocess)
        "list_findings" | "generate_report" | "list_modules" => None,
        // Cat 1: Session persistence
        "save_session" | "load_session" => None,
        // Cat 2: Reasoning & planning
        "add_hypothesis" | "update_hypothesis" | "list_hypotheses" | "log_reasoning" => None,
        // Cat 3: Custom HTTP (handled as instant tool in agent.rs)
        "send_http" => None,
        // Cat 4: Analysis
        "analyze_findings" => None,
        // Cat 6: Scope
        "check_scope" | "configure_scope" => None,
        // Cat 7: UX
        "show_progress" | "export_session" | "get_audit_log" => None,

        // Server-side tool — Anthropic handles execution, not us
        "web_search" => None,

        _ => None,
    }
}