pwn 0.5.795 → 0.5.798
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.
- checksums.yaml +4 -4
- data/Gemfile +8 -8
- data/bin/pwn_autoinc_version +4 -5
- data/bin/pwn_web_cache_deception +40 -29
- data/documentation/AWS.md +15 -5
- data/documentation/Diagrams.md +1 -1
- data/documentation/Home.md +2 -2
- data/documentation/How-PWN-Works.md +1 -1
- data/documentation/Mission-Cancellation.md +6 -4
- data/documentation/Operability.md +1 -1
- data/documentation/What-is-PWN.md +1 -1
- data/documentation/diagrams/aws-cloud-security.svg +1 -1
- data/documentation/diagrams/dot/aws-cloud-security.dot +1 -1
- data/documentation/diagrams/dot/network-infra-testing.dot +1 -1
- data/documentation/diagrams/network-infra-testing.svg +1 -1
- data/etc/default_cron/session_cleanup.rb +84 -51
- data/etc/default_skills/pwn/ai/agent/mission_namespace/SKILL.md +6 -4
- data/lib/pwn/ai/agent/assembly.rb +0 -2
- data/lib/pwn/ai/agent/btc.rb +0 -2
- data/lib/pwn/ai/agent/burp_suite.rb +0 -2
- data/lib/pwn/ai/agent/curriculum.rb +2 -2
- data/lib/pwn/ai/agent/dispatch.rb +3 -0
- data/lib/pwn/ai/agent/engagement.rb +96 -41
- data/lib/pwn/ai/agent/extrospection/osint/bridges.rb +2 -0
- data/lib/pwn/ai/agent/extrospection.rb +50 -13
- data/lib/pwn/ai/agent/gqrx.rb +0 -2
- data/lib/pwn/ai/agent/hacker_one.rb +0 -2
- data/lib/pwn/ai/agent/learning.rb +45 -13
- data/lib/pwn/ai/agent/loop.rb +16 -11
- data/lib/pwn/ai/agent/metrics.rb +1 -1
- data/lib/pwn/ai/agent/mission.rb +6 -3
- data/lib/pwn/ai/agent/mission_namespace.rb +70 -14
- data/lib/pwn/ai/agent/policy.rb +1 -1
- data/lib/pwn/ai/agent/policy_evaluation.rb +2 -2
- data/lib/pwn/ai/agent/reflect.rb +1 -0
- data/lib/pwn/ai/agent/request_runtime.rb +1 -1
- data/lib/pwn/ai/agent/reward.rb +155 -53
- data/lib/pwn/ai/agent/sast.rb +0 -2
- data/lib/pwn/ai/agent/task_dag.rb +5 -3
- data/lib/pwn/ai/agent/task_summarizer.rb +21 -11
- data/lib/pwn/ai/agent/tool_guard.rb +19 -0
- data/lib/pwn/ai/agent/tools/ruby_eval.rb +1 -1
- data/lib/pwn/ai/agent/tools/verify.rb +7 -3
- data/lib/pwn/ai/agent/transparent_browser.rb +0 -2
- data/lib/pwn/ai/agent/turn_finalizer.rb +3 -0
- data/lib/pwn/ai/anthropic.rb +3 -3
- data/lib/pwn/ai/context.rb +2 -1
- data/lib/pwn/ai/gemini.rb +7 -5
- data/lib/pwn/ai/grok.rb +37 -18
- data/lib/pwn/ai/mcp.rb +17 -5
- data/lib/pwn/ai/ollama.rb +76 -35
- data/lib/pwn/ai/open_ai.rb +7 -19
- data/lib/pwn/ai/open_web_ui.rb +76 -40
- data/lib/pwn/aws/cloud_search_domain.rb +6 -0
- data/lib/pwn/aws/iam.rb +2 -2
- data/lib/pwn/aws/workspaces.rb +2 -2
- data/lib/pwn/aws.rb +0 -5
- data/lib/pwn/bounty/lifecycle_authz_replay.rb +1 -1
- data/lib/pwn/config.rb +17 -10
- data/lib/pwn/corpus.rb +33 -5
- data/lib/pwn/cron.rb +60 -17
- data/lib/pwn/driver.rb +2 -3
- data/lib/pwn/engagement.rb +28 -10
- data/lib/pwn/ffi/capstone.rb +3 -2
- data/lib/pwn/ffi/fftw.rb +8 -6
- data/lib/pwn/ffi/keystone.rb +3 -2
- data/lib/pwn/ffi/soapy_sdr.rb +10 -6
- data/lib/pwn/json_text.rb +25 -13
- data/lib/pwn/memory_index.rb +6 -4
- data/lib/pwn/module_skills.rb +3 -1
- data/lib/pwn/plugins/aflplusplus.rb +1 -0
- data/lib/pwn/plugins/ai_sandbox.rb +42 -10
- data/lib/pwn/plugins/android.rb +429 -466
- data/lib/pwn/plugins/artifact_registry.rb +12 -2
- data/lib/pwn/plugins/assembly.rb +9 -42
- data/lib/pwn/plugins/authentication_helper.rb +4 -3
- data/lib/pwn/plugins/baresip.rb +70 -28
- data/lib/pwn/plugins/binary_analysis.rb +14 -5
- data/lib/pwn/plugins/binary_parser.rb +42 -7
- data/lib/pwn/plugins/black_duck_binary_analysis.rb +3 -3
- data/lib/pwn/plugins/burp_suite.rb +15 -12
- data/lib/pwn/plugins/bus_pirate.rb +3 -7
- data/lib/pwn/plugins/char.rb +9 -3
- data/lib/pwn/plugins/credit_card.rb +7 -0
- data/lib/pwn/plugins/dao_ldap.rb +2 -2
- data/lib/pwn/plugins/dao_mongo.rb +1 -1
- data/lib/pwn/plugins/debugger.rb +1 -1
- data/lib/pwn/plugins/defect_dojo.rb +7 -3
- data/lib/pwn/plugins/detect_os.rb +1 -1
- data/lib/pwn/plugins/detonate.rb +9 -19
- data/lib/pwn/plugins/exploit_db.rb +1 -1
- data/lib/pwn/plugins/file_fu.rb +4 -1
- data/lib/pwn/plugins/findings.rb +76 -2
- data/lib/pwn/plugins/fuzz.rb +12 -3
- data/lib/pwn/plugins/gdb.rb +7 -2
- data/lib/pwn/plugins/gdbmi.rb +10 -6
- data/lib/pwn/plugins/git.rb +18 -13
- data/lib/pwn/plugins/github.rb +11 -6
- data/lib/pwn/plugins/google_workspace.rb +11 -3
- data/lib/pwn/plugins/hacker_one.rb +5 -1
- data/lib/pwn/plugins/httpx.rb +24 -8
- data/lib/pwn/plugins/ip_info.rb +11 -8
- data/lib/pwn/plugins/irc.rb +73 -45
- data/lib/pwn/plugins/jenkins.rb +2 -2
- data/lib/pwn/plugins/jira_data_center.rb +13 -6
- data/lib/pwn/plugins/jobs.rb +62 -4
- data/lib/pwn/plugins/log.rb +1 -1
- data/lib/pwn/plugins/monkey_patch.rb +1 -1
- data/lib/pwn/plugins/msr206.rb +157 -182
- data/lib/pwn/plugins/nessus_cloud.rb +2 -2
- data/lib/pwn/plugins/nexpose_vuln_scan.rb +44 -33
- data/lib/pwn/plugins/nuclei.rb +24 -8
- data/lib/pwn/plugins/ocr.rb +3 -1
- data/lib/pwn/plugins/open_api.rb +0 -4
- data/lib/pwn/plugins/openvas.rb +31 -43
- data/lib/pwn/plugins/packet.rb +40 -25
- data/lib/pwn/plugins/pony.rb +2 -2
- data/lib/pwn/plugins/preflight_checker.rb +1 -1
- data/lib/pwn/plugins/process_tube.rb +17 -2
- data/lib/pwn/plugins/ps.rb +6 -1
- data/lib/pwn/plugins/pwn_logger.rb +37 -1
- data/lib/pwn/plugins/repl/ai.rb +1 -0
- data/lib/pwn/plugins/repl/ai_console.rb +18 -6
- data/lib/pwn/plugins/repl/mesh.rb +51 -28
- data/lib/pwn/plugins/sbom.rb +59 -27
- data/lib/pwn/plugins/scannable_codes.rb +3 -1
- data/lib/pwn/plugins/serial.rb +102 -44
- data/lib/pwn/plugins/shodan.rb +4 -10
- data/lib/pwn/plugins/sock.rb +16 -11
- data/lib/pwn/plugins/ssn.rb +3 -1
- data/lib/pwn/plugins/transparent_browser.rb +43 -3
- data/lib/pwn/plugins/vault.rb +92 -30
- data/lib/pwn/plugins/vin.rb +2 -1
- data/lib/pwn/plugins/vsphere.rb +2 -1
- data/lib/pwn/plugins/xxd.rb +3 -5
- data/lib/pwn/plugins/yubikey/security_domain/scp.rb +4 -0
- data/lib/pwn/plugins/yubikey/transport.rb +42 -11
- data/lib/pwn/plugins/yubikey.rb +21 -6
- data/lib/pwn/plugins/zaproxy.rb +3 -4
- data/lib/pwn/reports/ai_red_team.rb +4 -4
- data/lib/pwn/reports/pdf.rb +9 -5
- data/lib/pwn/reports/sast.rb +4 -4
- data/lib/pwn/sast/keystore.rb +2 -2
- data/lib/pwn/sast/logger.rb +1 -1
- data/lib/pwn/sast/php_type_juggling.rb +3 -6
- data/lib/pwn/sast/pom_version.rb +12 -6
- data/lib/pwn/sast/port.rb +1 -1
- data/lib/pwn/sast/sql.rb +3 -7
- data/lib/pwn/sast/test_case_engine.rb +62 -16
- data/lib/pwn/sast/type_script_type_juggling.rb +3 -6
- data/lib/pwn/sdr/decoder/base.rb +8 -0
- data/lib/pwn/sdr/decoder/lora.rb +1 -1
- data/lib/pwn/sdr/flipper_zero.rb +4 -7
- data/lib/pwn/sdr/gqrx.rb +35 -16
- data/lib/pwn/sdr/son_micro_rfid.rb +44 -26
- data/lib/pwn/sdr.rb +1 -1
- data/lib/pwn/session_trace.rb +7 -2
- data/lib/pwn/sessions.rb +310 -41
- data/lib/pwn/setup.rb +4 -3
- data/lib/pwn/version.rb +1 -1
- data/lib/pwn/www/app_cobalt_io.rb +14 -2
- data/lib/pwn/www/bing.rb +13 -1
- data/lib/pwn/www/bug_crowd.rb +14 -2
- data/lib/pwn/www/checkip.rb +13 -1
- data/lib/pwn/www/coinbase_pro.rb +14 -2
- data/lib/pwn/www/duckduckgo.rb +13 -1
- data/lib/pwn/www/facebook.rb +14 -2
- data/lib/pwn/www/github.rb +14 -2
- data/lib/pwn/www/google.rb +13 -1
- data/lib/pwn/www/hacker_one.rb +117 -33
- data/lib/pwn/www/linkedin.rb +14 -2
- data/lib/pwn/www/pandora.rb +14 -2
- data/lib/pwn/www/pastebin.rb +13 -1
- data/lib/pwn/www/paypal.rb +16 -4
- data/lib/pwn/www/synack.rb +14 -2
- data/lib/pwn/www/torch.rb +17 -3
- data/lib/pwn/www/trading_view.rb +14 -2
- data/lib/pwn/www/twitter.rb +14 -2
- data/lib/pwn/www/uber.rb +14 -2
- data/lib/pwn/www/upwork.rb +14 -2
- data/lib/pwn/www/wayback_machine.rb +16 -2
- data/lib/pwn/www/youtube.rb +13 -1
- data/lib/pwn.rb +11 -0
- data/pwn.gemspec +4 -0
- data/spec/conventions_spec.rb +43 -0
- data/spec/integration/authentication_helper_oath_spec.rb +1 -1
- data/spec/integration/autoinc_lifecycle_supplement_spec.rb +47 -0
- data/spec/integration/gemspec_deleted_files_spec.rb +43 -0
- data/spec/integration/harness_evaluation_spec.rb +22 -31
- data/spec/integration/harness_live_spec.rb +8 -18
- data/spec/integration/spec_curriculum_isolation_spec.rb +41 -0
- data/spec/integration/verify_acceptance_eui_regression_spec.rb +162 -0
- data/spec/integration/web_cache_lifecycle_closure_spec.rb +89 -0
- data/spec/integration/web_cache_lifecycle_supplement_spec.rb +70 -0
- data/spec/lib/pwn/ai/agent/analysis_errors_regression_spec.rb +33 -0
- data/spec/lib/pwn/ai/agent/curriculum_cooldown_regression_spec.rb +19 -0
- data/spec/lib/pwn/ai/agent/curriculum_spec.rb +2 -0
- data/spec/lib/pwn/ai/agent/engagement_boundary_regression_spec.rb +42 -0
- data/spec/lib/pwn/ai/agent/engagement_dispatch_review_spec.rb +82 -0
- data/spec/lib/pwn/ai/agent/engagement_roe_regression_spec.rb +25 -0
- data/spec/lib/pwn/ai/agent/engagement_scope_regression_spec.rb +37 -0
- data/spec/lib/pwn/ai/agent/extrospection/osint/bridges_spec.rb +4 -0
- data/spec/lib/pwn/ai/agent/extrospection_input_regression_spec.rb +31 -0
- data/spec/lib/pwn/ai/agent/extrospection_review_spec.rb +61 -0
- data/spec/lib/pwn/ai/agent/extrospection_serial_review_spec.rb +42 -0
- data/spec/lib/pwn/ai/agent/extrospection_spec.rb +9 -0
- data/spec/lib/pwn/ai/agent/extrospection_verification_regression_spec.rb +39 -0
- data/spec/lib/pwn/ai/agent/learning_last_answer_regression_spec.rb +32 -0
- data/spec/lib/pwn/ai/agent/learning_lifecycle_closure_spec.rb +84 -0
- data/spec/lib/pwn/ai/agent/learning_prune_regression_spec.rb +17 -0
- data/spec/lib/pwn/ai/agent/learning_spec.rb +2 -1
- data/spec/lib/pwn/ai/agent/loop_execution_audit_spec.rb +30 -0
- data/spec/lib/pwn/ai/agent/metrics_usage_regression_spec.rb +20 -0
- data/spec/lib/pwn/ai/agent/mission_execution_audit_spec.rb +27 -0
- data/spec/lib/pwn/ai/agent/mission_namespace_spec.rb +218 -18
- data/spec/lib/pwn/ai/agent/policy_confidence_regression_spec.rb +16 -0
- data/spec/lib/pwn/ai/agent/policy_evaluation_spec.rb +1 -1
- data/spec/lib/pwn/ai/agent/policy_evaluation_tmp_regression_spec.rb +36 -0
- data/spec/lib/pwn/ai/agent/reflect_model_regression_spec.rb +15 -0
- data/spec/lib/pwn/ai/agent/request_runtime_execution_audit_spec.rb +43 -0
- data/spec/lib/pwn/ai/agent/reward_binding_review_spec.rb +129 -0
- data/spec/lib/pwn/ai/agent/reward_dispatch_review_spec.rb +154 -0
- data/spec/lib/pwn/ai/agent/reward_envelope_regression_spec.rb +45 -0
- data/spec/lib/pwn/ai/agent/reward_turn_regression_spec.rb +40 -0
- data/spec/lib/pwn/ai/agent/swarm_spec.rb +2 -2
- data/spec/lib/pwn/ai/agent/task_dag_execution_audit_spec.rb +45 -0
- data/spec/lib/pwn/ai/agent/task_summarizer_failure_regression_spec.rb +26 -0
- data/spec/lib/pwn/ai/agent/tools/verify_execution_audit_spec.rb +33 -0
- data/spec/lib/pwn/ai/context_range_audit_spec.rb +24 -0
- data/spec/lib/pwn/ai/gemini_roundtrip_audit_spec.rb +33 -0
- data/spec/lib/pwn/ai/grok_reasoning_effort_spec.rb +43 -0
- data/spec/lib/pwn/ai/mcp_session_audit_spec.rb +36 -0
- data/spec/lib/pwn/ai/ollama_spec.rb +6 -11
- data/spec/lib/pwn/ai/open_web_ui_spec.rb +6 -11
- data/spec/lib/pwn/ai/provider_history_audit_spec.rb +44 -0
- data/spec/lib/pwn/ai/provider_operations_audit_spec.rb +53 -0
- data/spec/lib/pwn/ai/provider_review_history_stream_regression_spec.rb +143 -0
- data/spec/lib/pwn/ai/provider_review_tls_regression_spec.rb +62 -0
- data/spec/lib/pwn/ai/provider_stream_audit_spec.rb +49 -0
- data/spec/lib/pwn/aws/iam_decoding_regression_spec.rb +23 -0
- data/spec/lib/pwn/aws/services_runtime_regression_spec.rb +51 -0
- data/spec/lib/pwn/aws_spec.rb +6 -0
- data/spec/lib/pwn/banner_operational_audit_spec.rb +105 -0
- data/spec/lib/pwn/bounty/lifecycle_authz_replay_spec.rb +17 -0
- data/spec/lib/pwn/config_redaction_regression_spec.rb +24 -0
- data/spec/lib/pwn/config_skills_regression_spec.rb +38 -0
- data/spec/lib/pwn/corpus_core_review_regression_spec.rb +96 -0
- data/spec/lib/pwn/corpus_spec.rb +13 -0
- data/spec/lib/pwn/cron_core_review_regression_spec.rb +95 -0
- data/spec/lib/pwn/cron_execution_spec.rb +75 -0
- data/spec/lib/pwn/driver_core_review_regression_spec.rb +38 -0
- data/spec/lib/pwn/driver_spec.rb +13 -0
- data/spec/lib/pwn/engagement_core_review_regression_spec.rb +88 -0
- data/spec/lib/pwn/engagement_storage_regression_spec.rb +44 -0
- data/spec/lib/pwn/ffi/capstone_spec.rb +19 -0
- data/spec/lib/pwn/ffi/fftw_spec.rb +19 -0
- data/spec/lib/pwn/ffi/keystone_spec.rb +13 -0
- data/spec/lib/pwn/ffi/soapy_sdr_spec.rb +13 -0
- data/spec/lib/pwn/json_schemer_regexp_parser_spec.rb +12 -0
- data/spec/lib/pwn/json_text_spec.rb +25 -0
- data/spec/lib/pwn/memory_index_spec.rb +23 -0
- data/spec/lib/pwn/module_skills_parsing_regression_spec.rb +34 -0
- data/spec/lib/pwn/module_skills_spec.rb +11 -1
- data/spec/lib/pwn/plugins/ai_sandbox_boundary_review_spec.rb +57 -0
- data/spec/lib/pwn/plugins/ai_sandbox_spec.rb +10 -18
- data/spec/lib/pwn/plugins/android_review_fixes_spec.rb +121 -0
- data/spec/lib/pwn/plugins/android_transport_audit_spec.rb +64 -0
- data/spec/lib/pwn/plugins/api_import_namespace_audit_spec.rb +49 -0
- data/spec/lib/pwn/plugins/artifact_registry_namespace_audit_spec.rb +20 -0
- data/spec/lib/pwn/plugins/artifact_registry_review_fixes_spec.rb +63 -0
- data/spec/lib/pwn/plugins/assembly_namespace_audit_spec.rb +16 -0
- data/spec/lib/pwn/plugins/assembly_review_fixes_spec.rb +33 -0
- data/spec/lib/pwn/plugins/authentication_helper_spec.rb +14 -0
- data/spec/lib/pwn/plugins/baresip_review_fixes_spec.rb +127 -0
- data/spec/lib/pwn/plugins/baresip_transport_audit_spec.rb +59 -0
- data/spec/lib/pwn/plugins/binary_analysis_process_review_spec.rb +57 -0
- data/spec/lib/pwn/plugins/black_duck_namespace_audit_spec.rb +25 -0
- data/spec/lib/pwn/plugins/burp_suite_har_review_fixes_spec.rb +60 -0
- data/spec/lib/pwn/plugins/burp_suite_import_review_fixes_spec.rb +62 -0
- data/spec/lib/pwn/plugins/burp_suite_namespace_audit_spec.rb +37 -0
- data/spec/lib/pwn/plugins/bus_pirate_transport_audit_spec.rb +19 -0
- data/spec/lib/pwn/plugins/file_fu_namespace_audit_spec.rb +17 -0
- data/spec/lib/pwn/plugins/findings_structured_spec.rb +1 -1
- data/spec/lib/pwn/plugins/gdbmi_namespace_audit_spec.rb +28 -0
- data/spec/lib/pwn/plugins/gdbmi_review_fixes_spec.rb +73 -0
- data/spec/lib/pwn/plugins/github_argv_review_spec.rb +49 -0
- data/spec/lib/pwn/plugins/google_workspace_provider_review_oauth_spec.rb +80 -0
- data/spec/lib/pwn/plugins/irc_review_fixes_spec.rb +92 -0
- data/spec/lib/pwn/plugins/irc_transport_audit_spec.rb +37 -0
- data/spec/lib/pwn/plugins/jenkins_namespace_audit_spec.rb +12 -0
- data/spec/lib/pwn/plugins/jira_data_center_namespace_audit_spec.rb +44 -0
- data/spec/lib/pwn/plugins/jira_data_center_review_fixes_spec.rb +81 -0
- data/spec/lib/pwn/plugins/jsonl_elf_review_fixes_spec.rb +59 -0
- data/spec/lib/pwn/plugins/log_spec.rb +36 -20
- data/spec/lib/pwn/plugins/monkey_patch_spec.rb +16 -0
- data/spec/lib/pwn/plugins/msr206_readback_review_fixes_spec.rb +119 -0
- data/spec/lib/pwn/plugins/msr206_review_fixes_spec.rb +50 -0
- data/spec/lib/pwn/plugins/msr206_transport_audit_spec.rb +64 -0
- data/spec/lib/pwn/plugins/nessus_cloud_namespace_audit_spec.rb +14 -0
- data/spec/lib/pwn/plugins/nexpose_review_fixes_spec.rb +55 -0
- data/spec/lib/pwn/plugins/open_api_namespace_audit_spec.rb +22 -0
- data/spec/lib/pwn/plugins/packet_transport_audit_spec.rb +47 -0
- data/spec/lib/pwn/plugins/plugins_b_operational_regression_spec.rb +600 -0
- data/spec/lib/pwn/plugins/pony_namespace_audit_spec.rb +17 -0
- data/spec/lib/pwn/plugins/pony_review_fixes_spec.rb +33 -0
- data/spec/lib/pwn/plugins/process_tube_namespace_audit_spec.rb +19 -0
- data/spec/lib/pwn/plugins/ps_namespace_audit_spec.rb +12 -0
- data/spec/lib/pwn/plugins/pwn_logger_spec.rb +30 -0
- data/spec/lib/pwn/plugins/repl/ai_console_spec.rb +127 -0
- data/spec/lib/pwn/plugins/repl/ai_spec.rb +38 -0
- data/spec/lib/pwn/plugins/repl/mesh_spec.rb +52 -0
- data/spec/lib/pwn/plugins/repl_mesh_rx_errors_spec.rb +18 -0
- data/spec/lib/pwn/plugins/sandbox_spec.rb +9 -7
- data/spec/lib/pwn/plugins/sbom_review_fixes_spec.rb +43 -0
- data/spec/lib/pwn/plugins/scannable_codes_namespace_audit_spec.rb +15 -0
- data/spec/lib/pwn/plugins/serial_review_fixes_spec.rb +76 -0
- data/spec/lib/pwn/plugins/serial_transport_audit_spec.rb +102 -0
- data/spec/lib/pwn/plugins/shodan_namespace_audit_spec.rb +10 -0
- data/spec/lib/pwn/plugins/sock_transport_audit_spec.rb +55 -0
- data/spec/lib/pwn/plugins/transparent_browser_navigation_review_spec.rb +21 -0
- data/spec/lib/pwn/plugins/vault_master_key_eui_regression_spec.rb +242 -0
- data/spec/lib/pwn/plugins/vault_spec.rb +58 -0
- data/spec/lib/pwn/plugins/vault_store_safety_spec.rb +1 -1
- data/spec/lib/pwn/plugins/xxd_namespace_audit_spec.rb +34 -0
- data/spec/lib/pwn/plugins/yubikey_hid_cleanup_review_fixes_spec.rb +52 -0
- data/spec/lib/pwn/plugins/yubikey_lifecycle_audit_spec.rb +65 -0
- data/spec/lib/pwn/plugins/yubikey_options_audit_spec.rb +30 -0
- data/spec/lib/pwn/plugins/yubikey_selector_audit_spec.rb +26 -0
- data/spec/lib/pwn/plugins/yubikey_spec.rb +1 -1
- data/spec/lib/pwn/plugins/zaproxy_namespace_audit_spec.rb +30 -0
- data/spec/lib/pwn/reports/empty_report_audit_spec.rb +18 -0
- data/spec/lib/pwn/reports/pdf_spec.rb +25 -0
- data/spec/lib/pwn/reports/provider_review_encoding_regression_spec.rb +35 -0
- data/spec/lib/pwn/sast/engine_runtime_regression_spec.rb +91 -0
- data/spec/lib/pwn/sast/filter_edge_regression_spec.rb +39 -0
- data/spec/lib/pwn/sast/formatter_review_fixes_spec.rb +178 -0
- data/spec/lib/pwn/sast/path_review_fixes_spec.rb +60 -0
- data/spec/lib/pwn/sast/pom_runtime_regression_spec.rb +37 -0
- data/spec/lib/pwn/sast/rules_runtime_regression_spec.rb +78 -0
- data/spec/lib/pwn/sast/sql_review_fixes_spec.rb +38 -0
- data/spec/lib/pwn/sdr/decoder/base_iq_spec.rb +21 -18
- data/spec/lib/pwn/sdr/decoder/base_review_fixes_spec.rb +49 -0
- data/spec/lib/pwn/sdr/decoder/base_validation_spec.rb +78 -0
- data/spec/lib/pwn/sdr/decoder/lora_spec.rb +9 -0
- data/spec/lib/pwn/sdr/flipper_zero_review_fixes_spec.rb +34 -0
- data/spec/lib/pwn/sdr/gqrx_operational_spec.rb +83 -0
- data/spec/lib/pwn/sdr/gqrx_review_fixes_spec.rb +22 -0
- data/spec/lib/pwn/sdr/son_micro_rfid_review_fixes_spec.rb +113 -0
- data/spec/lib/pwn/sdr/son_micro_rfid_serial_review_fixes_spec.rb +76 -0
- data/spec/lib/pwn/sdr/son_micro_rfid_spec.rb +39 -0
- data/spec/lib/pwn/sdr_spec.rb +5 -0
- data/spec/lib/pwn/session_cleanup_concurrency_spec.rb +21 -0
- data/spec/lib/pwn/session_cleanup_default_spec.rb +1 -1
- data/spec/lib/pwn/session_cleanup_lifecycle_supplement_spec.rb +39 -0
- data/spec/lib/pwn/session_cleanup_payload_spec.rb +3 -2
- data/spec/lib/pwn/session_trace_lifecycle_supplement_spec.rb +39 -0
- data/spec/lib/pwn/sessions_archive_closure_spec.rb +126 -0
- data/spec/lib/pwn/sessions_lifecycle_closure_spec.rb +373 -0
- data/spec/lib/pwn/sessions_lifecycle_supplement_spec.rb +204 -0
- data/spec/lib/pwn/setup_operational_regression_spec.rb +36 -0
- data/spec/lib/pwn/www/browser_review_fixes_spec.rb +70 -0
- data/spec/lib/pwn/www/browser_runtime_regression_spec.rb +100 -0
- data/spec/lib/pwn/www/hacker_one_runtime_regression_spec.rb +146 -0
- data/spec/lib/pwn/www/pagination_review_fixes_spec.rb +84 -0
- data/spec/spec_helper.rb +34 -5
- data/spec/support/namespace_controller_observability_fixture.rb +141 -0
- data/spec/support/sandbox.rb +8 -5
- data/third_party/pwn_rdoc.jsonl +83 -32
- metadata +7690 -7386
- data/etc/default_skills/pwn/aws/elastic_transcoder/SKILL.md +0 -48
- data/etc/default_skills/pwn/aws/lambda_preview/SKILL.md +0 -48
- data/etc/default_skills/pwn/aws/ops_works/SKILL.md +0 -48
- data/etc/default_skills/pwn/aws/ops_works_cm/SKILL.md +0 -48
- data/etc/default_skills/pwn/aws/sms/SKILL.md +0 -48
- data/lib/pwn/aws/elastic_transcoder.rb +0 -95
- data/lib/pwn/aws/lambda_preview.rb +0 -95
- data/lib/pwn/aws/ops_works.rb +0 -95
- data/lib/pwn/aws/ops_works_cm.rb +0 -95
- data/lib/pwn/aws/sms.rb +0 -95
- data/spec/lib/pwn/aws/elastic_transcoder_spec.rb +0 -15
- data/spec/lib/pwn/aws/lambda_preview_spec.rb +0 -15
- data/spec/lib/pwn/aws/ops_works_cm_spec.rb +0 -15
- data/spec/lib/pwn/aws/ops_works_spec.rb +0 -15
- data/spec/lib/pwn/aws/sms_spec.rb +0 -15
|
@@ -53,9 +53,11 @@ module PWN
|
|
|
53
53
|
ready.each do |step|
|
|
54
54
|
remaining.delete(step)
|
|
55
55
|
row = run_step(step: step, dir: dir)
|
|
56
|
-
done[step['id']] = true
|
|
57
56
|
results << row
|
|
58
57
|
persist_checkpoint(dir: dir, step: step, row: row)
|
|
58
|
+
return { run_id: run_id, dir: dir, results: results, ok: false, halted: step['id'] } unless row[:ok]
|
|
59
|
+
|
|
60
|
+
done[step['id']] = true
|
|
59
61
|
return { run_id: run_id, dir: dir, results: results, halted: step['id'] } if opts[:halt_after].to_s == step['id']
|
|
60
62
|
end
|
|
61
63
|
end
|
|
@@ -227,7 +229,7 @@ module PWN
|
|
|
227
229
|
|
|
228
230
|
private_class_method def self.persist_checkpoint(opts = {})
|
|
229
231
|
path = File.join(opts[:dir], 'checkpoints.jsonl')
|
|
230
|
-
rec = { id: opts[:step]['id'], status: 'completed', at: Time.now.utc.iso8601, result: opts[:row] }
|
|
232
|
+
rec = { id: opts[:step]['id'], status: opts[:row][:ok] ? 'completed' : 'failed', at: Time.now.utc.iso8601, result: opts[:row] }
|
|
231
233
|
File.open(path, 'a') do |file|
|
|
232
234
|
file.flock(File::LOCK_EX)
|
|
233
235
|
file.puts(JSON.generate(rec))
|
|
@@ -245,7 +247,7 @@ module PWN
|
|
|
245
247
|
)
|
|
246
248
|
body = JSON.parse(raw, symbolize_names: true)
|
|
247
249
|
result = body[:result] || body
|
|
248
|
-
ok = !result.is_a?(Hash) || result[:error].nil?
|
|
250
|
+
ok = body[:success] == true && (!result.is_a?(Hash) || result[:error].nil?)
|
|
249
251
|
PWN::AI::Agent::Mission.note_technique!(technique: step['tool']) if ok && defined?(PWN::AI::Agent::Mission) && PWN::AI::Agent::Mission.active_id
|
|
250
252
|
{ id: step['id'], ok: ok, result: result }
|
|
251
253
|
rescue StandardError => e
|
|
@@ -923,7 +923,7 @@ module PWN
|
|
|
923
923
|
plan.each_with_index.filter_map do |item, i|
|
|
924
924
|
slice = state[:task_evidence].is_a?(Hash) ? state[:task_evidence][i].to_s : ''
|
|
925
925
|
use = host_shaped_task?(item: item) && !slice.empty? ? slice : blob
|
|
926
|
-
next if item.empty? || item_covered?(item: item, blob: use)
|
|
926
|
+
next if item.empty? || item_covered?(item: item, blob: use, state: state)
|
|
927
927
|
|
|
928
928
|
{ idx: i, item: item, label: "task #{i + 1}/#{n}: #{item}" }
|
|
929
929
|
end
|
|
@@ -1476,6 +1476,9 @@ module PWN
|
|
|
1476
1476
|
phase = task_phase(item: item)
|
|
1477
1477
|
case phase
|
|
1478
1478
|
when :mutate
|
|
1479
|
+
state = opts[:state]
|
|
1480
|
+
return state[:mutation_evidence].value?(true) if state.is_a?(Hash) && state.key?(:mutation_evidence)
|
|
1481
|
+
|
|
1479
1482
|
blob.match?(MUTATION_DONE_RX)
|
|
1480
1483
|
when :verify
|
|
1481
1484
|
blob.match?(VERIFY_DONE_RX) || blob.match?(VERIFY_RAN_RX)
|
|
@@ -1501,7 +1504,7 @@ module PWN
|
|
|
1501
1504
|
|
|
1502
1505
|
case phase
|
|
1503
1506
|
when :mutate, :verify
|
|
1504
|
-
item_covered?(item: opts[:item], blob: joined)
|
|
1507
|
+
item_covered?(item: opts[:item], blob: joined, state: opts[:state])
|
|
1505
1508
|
when :discover, :generic, :present
|
|
1506
1509
|
browse_hit = joined.match?(/effect["\s:=]+browse|transparentbrowser|\.goto\b|\bbrowse\b/i)
|
|
1507
1510
|
min_tools = browse_hit ? 1 : DISCOVER_MIN_TOOLS
|
|
@@ -1683,19 +1686,26 @@ module PWN
|
|
|
1683
1686
|
rs = result.to_s
|
|
1684
1687
|
ok = !rs.match?(/\A\s*\{?\s*"?(success|ok)"?\s*=>\s*false/i) &&
|
|
1685
1688
|
!rs.match?(/ERROR:|Traceback|NoMethodError|StandardError/i)
|
|
1686
|
-
|
|
1689
|
+
ok = Reward.semantic_ok(name: name, raw: rs, args: args)[:semantic_ok] if rs.lstrip.start_with?('{')
|
|
1690
|
+
state[:events] << { name: name.to_s, preview: preview, ok: ok, result: rs[0, 800], t: Time.now }
|
|
1687
1691
|
state[:events].shift while state[:events].size > MAX_BUFFER
|
|
1688
1692
|
state[:counts][name.to_s] += 1
|
|
1689
1693
|
state[:total] += 1
|
|
1690
1694
|
state[:since_emit] += 1
|
|
1691
|
-
state[:tools_on_task] = state[:tools_on_task].to_i + 1
|
|
1695
|
+
state[:tools_on_task] = state[:tools_on_task].to_i + 1 if ok && !name.to_s.match?(/^(memory|session|skills)_recall$/)
|
|
1692
1696
|
state[:emitted_for_batch] = false
|
|
1693
|
-
|
|
1694
|
-
state[:
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1697
|
+
mutations = (state[:mutation_evidence] ||= {})
|
|
1698
|
+
mutations[state[:plan_idx].to_i] = true if ok && Dispatch.effect(name: name, args: args) == :write
|
|
1699
|
+
# Failed/unknown observations stay in events for diagnostics, never
|
|
1700
|
+
# in the successful evidence later actions consult for plan coverage.
|
|
1701
|
+
if ok
|
|
1702
|
+
chunk = "#{name} #{preview} #{rs[0, 800]}"
|
|
1703
|
+
state[:evidence_blob] = "#{state[:evidence_blob]} #{chunk}"
|
|
1704
|
+
state[:evidence_blob] = state[:evidence_blob][-16_000..] if state[:evidence_blob].to_s.length > 20_000
|
|
1705
|
+
te = (state[:task_evidence] ||= {})
|
|
1706
|
+
idx = state[:plan_idx].to_i
|
|
1707
|
+
te[idx] = "#{te[idx]} #{chunk}"
|
|
1708
|
+
end
|
|
1699
1709
|
intent = intent_phrase(tools: [{ name: name.to_s, args: args }])
|
|
1700
1710
|
# Live R2-local signal from tool outcome (executive idx only).
|
|
1701
1711
|
# Full ORM/PRM credit stays in Reward during auto_introspect.
|
|
@@ -1717,7 +1727,7 @@ module PWN
|
|
|
1717
1727
|
# Heuristic phase-shift remains as a backstop when PRM streak has not fired.
|
|
1718
1728
|
if state[:last_prm_signal].to_s.start_with?('advance')
|
|
1719
1729
|
# already moved this record
|
|
1720
|
-
|
|
1730
|
+
elsif ok && !mistake_hit
|
|
1721
1731
|
maybe_advance_plan!(
|
|
1722
1732
|
state: state,
|
|
1723
1733
|
names: [name.to_s],
|
|
@@ -662,6 +662,20 @@ module PWN
|
|
|
662
662
|
nil
|
|
663
663
|
end
|
|
664
664
|
|
|
665
|
+
# Called while the actual Ruby value still exists, never on inspected
|
|
666
|
+
# text or stdout. Execution and application outcomes are distinct.
|
|
667
|
+
public_class_method def self.eval_outcome(opts = {})
|
|
668
|
+
value = opts[:value]
|
|
669
|
+
status = :unknown
|
|
670
|
+
if value.is_a?(Hash)
|
|
671
|
+
flags = %i[success ok].flat_map { |key| [value[key], value[key.to_s]] }
|
|
672
|
+
error = value[:error] || value['error']
|
|
673
|
+
status = :succeeded if flags.include?(true)
|
|
674
|
+
status = :failed if flags.include?(false) || (error && !error.to_s.empty?)
|
|
675
|
+
end
|
|
676
|
+
{ execution_success: true, application_status: status, success: status != :failed }
|
|
677
|
+
end
|
|
678
|
+
|
|
665
679
|
public_class_method def self.scope_check!(opts = {})
|
|
666
680
|
return nil unless defined?(Engagement)
|
|
667
681
|
|
|
@@ -953,6 +967,11 @@ module PWN
|
|
|
953
967
|
args: 'required - Hash of tool arguments'
|
|
954
968
|
)
|
|
955
969
|
|
|
970
|
+
# Classify the actual Ruby return value before string rendering.
|
|
971
|
+
#{self}.eval_outcome(
|
|
972
|
+
value: 'required - original typed Ruby value, never stdout or inspected text'
|
|
973
|
+
)
|
|
974
|
+
|
|
956
975
|
# Block network args outside the active engagement scope.
|
|
957
976
|
#{self}.scope_check!(
|
|
958
977
|
args: 'optional - Hash of tool arguments',
|
|
@@ -105,7 +105,7 @@ PWN::AI::Agent::Registry.register(
|
|
|
105
105
|
)
|
|
106
106
|
end
|
|
107
107
|
# rubocop:enable Security/Eval
|
|
108
|
-
|
|
108
|
+
PWN::AI::Agent::ToolGuard.eval_outcome(value: val).merge(stdout: buf.string, value: val.inspect, timeout: timeout)
|
|
109
109
|
rescue Timeout::Error
|
|
110
110
|
PWN::AI::Agent::ToolGuard.timeout_result(
|
|
111
111
|
tool: 'pwn_eval',
|
|
@@ -37,8 +37,8 @@ PWN::AI::Agent::Registry.register(
|
|
|
37
37
|
when 'file_grep'
|
|
38
38
|
path = (a[:path] || a['path']).to_s
|
|
39
39
|
rx = (a[:pattern] || a['pattern']).to_s
|
|
40
|
-
body = File.
|
|
41
|
-
{ type: type, passed: !rx.empty? && body.match?(Regexp.new(rx)), path: path }
|
|
40
|
+
body = File.read(path) if File.file?(path)
|
|
41
|
+
{ type: type, passed: !body.nil? && !rx.empty? && body.match?(Regexp.new(rx)), path: path }
|
|
42
42
|
when 'port_open'
|
|
43
43
|
host = (a[:host] || a['host'] || '127.0.0.1').to_s
|
|
44
44
|
port = (a[:port] || a['port']).to_i
|
|
@@ -58,6 +58,10 @@ PWN::AI::Agent::Registry.register(
|
|
|
58
58
|
{ type: type, passed: false, error: 'unknown check type' }
|
|
59
59
|
end
|
|
60
60
|
end
|
|
61
|
-
|
|
61
|
+
# Acceptance is the operation's success, not merely handler completion.
|
|
62
|
+
# Use the shared execution field retained by Dispatch and result paging;
|
|
63
|
+
# passed remains the detailed verifier API, not a rule for arbitrary tools.
|
|
64
|
+
passed = results.all? { |result| result[:passed] }
|
|
65
|
+
{ success: passed, passed: passed, results: results }
|
|
62
66
|
}
|
|
63
67
|
)
|
|
@@ -82,6 +82,7 @@ module PWN
|
|
|
82
82
|
return { skipped: :no_session } if session_id.to_s.strip.empty?
|
|
83
83
|
return { skipped: :no_learning } unless defined?(Learning)
|
|
84
84
|
|
|
85
|
+
snapshot = Reward.prm_snapshot(session_id: session_id, request: opts[:request]) if defined?(Reward)
|
|
85
86
|
episode = nil
|
|
86
87
|
episode = Policy.detach_episode! if defined?(Policy) && Policy.respond_to?(:detach_episode!)
|
|
87
88
|
|
|
@@ -96,6 +97,7 @@ module PWN
|
|
|
96
97
|
|
|
97
98
|
worker = Thread.new do
|
|
98
99
|
Thread.current[INLINE_KEY] = true
|
|
100
|
+
Thread.current[:pwn_prm_snapshot] = snapshot
|
|
99
101
|
begin
|
|
100
102
|
Policy.attach_episode!(episode: episode) if defined?(Policy) && Policy.respond_to?(:attach_episode!)
|
|
101
103
|
Learning.auto_introspect(payload)
|
|
@@ -103,6 +105,7 @@ module PWN
|
|
|
103
105
|
warn "[pwn-ai/turn_finalizer] background review swallowed: #{e.class}: #{e.message}"
|
|
104
106
|
nil
|
|
105
107
|
ensure
|
|
108
|
+
Thread.current[:pwn_prm_snapshot] = nil
|
|
106
109
|
leftover = defined?(Policy) && Policy.respond_to?(:current_episode) && Policy.current_episode
|
|
107
110
|
if leftover && Policy.respond_to?(:finish)
|
|
108
111
|
Policy.finish(
|
data/lib/pwn/ai/anthropic.rb
CHANGED
|
@@ -405,7 +405,7 @@ module PWN
|
|
|
405
405
|
method: http_method,
|
|
406
406
|
url: "#{base_uri}/#{rest_call}",
|
|
407
407
|
headers: headers,
|
|
408
|
-
verify_ssl:
|
|
408
|
+
verify_ssl: true,
|
|
409
409
|
timeout: timeout
|
|
410
410
|
)
|
|
411
411
|
|
|
@@ -418,7 +418,7 @@ module PWN
|
|
|
418
418
|
url: "#{base_uri}/#{rest_call}",
|
|
419
419
|
headers: headers,
|
|
420
420
|
payload: http_body,
|
|
421
|
-
verify_ssl:
|
|
421
|
+
verify_ssl: true,
|
|
422
422
|
timeout: timeout
|
|
423
423
|
)
|
|
424
424
|
else
|
|
@@ -427,7 +427,7 @@ module PWN
|
|
|
427
427
|
url: "#{base_uri}/#{rest_call}",
|
|
428
428
|
headers: headers,
|
|
429
429
|
payload: http_body.to_json,
|
|
430
|
-
verify_ssl:
|
|
430
|
+
verify_ssl: true,
|
|
431
431
|
timeout: timeout
|
|
432
432
|
)
|
|
433
433
|
end
|
data/lib/pwn/ai/context.rb
CHANGED
|
@@ -21,7 +21,8 @@ module PWN
|
|
|
21
21
|
|
|
22
22
|
range = opts[:range]
|
|
23
23
|
data = if range.is_a?(Range)
|
|
24
|
-
|
|
24
|
+
length = range.end - range.begin + (range.exclude_end? ? 0 : 1)
|
|
25
|
+
File.binread(path, length, range.begin).to_s
|
|
25
26
|
else
|
|
26
27
|
File.binread(path)
|
|
27
28
|
end
|
data/lib/pwn/ai/gemini.rb
CHANGED
|
@@ -66,7 +66,7 @@ module PWN
|
|
|
66
66
|
method: http_method,
|
|
67
67
|
url: "#{base_uri}/#{rest_call}",
|
|
68
68
|
headers: headers,
|
|
69
|
-
verify_ssl:
|
|
69
|
+
verify_ssl: true,
|
|
70
70
|
timeout: timeout
|
|
71
71
|
)
|
|
72
72
|
|
|
@@ -76,7 +76,7 @@ module PWN
|
|
|
76
76
|
url: "#{base_uri}/#{rest_call}",
|
|
77
77
|
headers: headers,
|
|
78
78
|
payload: http_body.to_json,
|
|
79
|
-
verify_ssl:
|
|
79
|
+
verify_ssl: true,
|
|
80
80
|
timeout: timeout
|
|
81
81
|
)
|
|
82
82
|
else
|
|
@@ -276,9 +276,11 @@ module PWN
|
|
|
276
276
|
raw = m[:_native_content] || m['_native_content']
|
|
277
277
|
if raw.is_a?(Array) && !raw.empty?
|
|
278
278
|
parts = raw.map do |p|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
279
|
+
key = p.key?(:functionCall) ? :functionCall : 'functionCall'
|
|
280
|
+
if p[key]
|
|
281
|
+
call = p[key]
|
|
282
|
+
tool_name_by_id[(call[:_id] || call['_id']).to_s] = call[:name] || call['name']
|
|
283
|
+
p.merge(key => call.except(:_id, '_id'))
|
|
282
284
|
else
|
|
283
285
|
p
|
|
284
286
|
end
|
data/lib/pwn/ai/grok.rb
CHANGED
|
@@ -415,7 +415,7 @@ module PWN
|
|
|
415
415
|
method: http_method,
|
|
416
416
|
url: "#{base_uri}/#{rest_call}",
|
|
417
417
|
headers: headers,
|
|
418
|
-
verify_ssl:
|
|
418
|
+
verify_ssl: true,
|
|
419
419
|
timeout: timeout
|
|
420
420
|
)
|
|
421
421
|
|
|
@@ -428,7 +428,7 @@ module PWN
|
|
|
428
428
|
url: "#{base_uri}/#{rest_call}",
|
|
429
429
|
headers: headers,
|
|
430
430
|
payload: http_body,
|
|
431
|
-
verify_ssl:
|
|
431
|
+
verify_ssl: true,
|
|
432
432
|
timeout: timeout
|
|
433
433
|
)
|
|
434
434
|
else
|
|
@@ -437,7 +437,7 @@ module PWN
|
|
|
437
437
|
url: "#{base_uri}/#{rest_call}",
|
|
438
438
|
headers: headers,
|
|
439
439
|
payload: http_body.to_json,
|
|
440
|
-
verify_ssl:
|
|
440
|
+
verify_ssl: true,
|
|
441
441
|
timeout: timeout
|
|
442
442
|
)
|
|
443
443
|
end
|
|
@@ -484,15 +484,6 @@ module PWN
|
|
|
484
484
|
# Keep the HTTP type/response and actionable provider diagnostics.
|
|
485
485
|
e.message = "Grok HTTP #{e.http_code} (#{http_method.to_s.upcase} #{rest_call}): #{e.response&.body}"
|
|
486
486
|
raise
|
|
487
|
-
rescue StandardError => e
|
|
488
|
-
case e.message
|
|
489
|
-
when '400 Bad Request', '404 Resource Not Found'
|
|
490
|
-
nil
|
|
491
|
-
else
|
|
492
|
-
raise e unless opts[:quiet]
|
|
493
|
-
|
|
494
|
-
end
|
|
495
|
-
"#{e.message}: #{e.response}"
|
|
496
487
|
ensure
|
|
497
488
|
PWN::Plugins::TTYSpinner.stop(spin: spin)
|
|
498
489
|
end
|
|
@@ -611,8 +602,8 @@ module PWN
|
|
|
611
602
|
}
|
|
612
603
|
http_body[:tools] = opts[:tools] if opts[:tools] && !opts[:tools].empty?
|
|
613
604
|
http_body[:tool_choice] = opts[:tool_choice] if opts[:tool_choice]
|
|
614
|
-
effort = opts[:reasoning_effort]
|
|
615
|
-
http_body[:reasoning_effort] = effort
|
|
605
|
+
effort = wire_reasoning_effort(model: model, effort: opts[:reasoning_effort])
|
|
606
|
+
http_body[:reasoning_effort] = effort if effort
|
|
616
607
|
hosted = Array(opts[:server_tools]).map(&:to_s).reject(&:empty?)
|
|
617
608
|
if hosted.any?
|
|
618
609
|
raise ArgumentError, 'xAI hosted tools use the Responses API and are not mixed into chat/completions client tools' if opts[:tools] && !opts[:tools].empty?
|
|
@@ -698,8 +689,8 @@ module PWN
|
|
|
698
689
|
temperature: temp,
|
|
699
690
|
stream: false
|
|
700
691
|
}
|
|
701
|
-
effort = opts[:reasoning_effort]
|
|
702
|
-
http_body[:reasoning_effort] = effort
|
|
692
|
+
effort = wire_reasoning_effort(model: model, effort: opts[:reasoning_effort])
|
|
693
|
+
http_body[:reasoning_effort] = effort if effort
|
|
703
694
|
|
|
704
695
|
if response_history[:choices].length > 1
|
|
705
696
|
response_history[:choices][1..-1].each do |message|
|
|
@@ -744,6 +735,33 @@ module PWN
|
|
|
744
735
|
raise e
|
|
745
736
|
end
|
|
746
737
|
|
|
738
|
+
# grok-4.5 and later reject reasoning_effort none. Map it to the lowest
|
|
739
|
+
# documented level; omit it when the model has no effort menu.
|
|
740
|
+
private_class_method def self.reasoning_efforts(opts = {})
|
|
741
|
+
model = opts[:model].to_s
|
|
742
|
+
efforts = if %w[grok-4.6 grok-4.7].include?(model)
|
|
743
|
+
%w[low medium high xhigh]
|
|
744
|
+
elsif model == 'grok-4.5'
|
|
745
|
+
%w[low medium high]
|
|
746
|
+
elsif %w[grok-3-mini grok-3-mini-fast].include?(model)
|
|
747
|
+
%w[low high]
|
|
748
|
+
else
|
|
749
|
+
[]
|
|
750
|
+
end
|
|
751
|
+
{ efforts: efforts }
|
|
752
|
+
end
|
|
753
|
+
|
|
754
|
+
private_class_method def self.wire_reasoning_effort(opts = {})
|
|
755
|
+
effort = opts[:effort].to_s
|
|
756
|
+
return nil if effort.empty?
|
|
757
|
+
|
|
758
|
+
known = reasoning_efforts(model: opts[:model])[:efforts]
|
|
759
|
+
return known.first if effort == 'none' && known.any? && !known.include?('none')
|
|
760
|
+
return nil if effort == 'none'
|
|
761
|
+
|
|
762
|
+
effort
|
|
763
|
+
end
|
|
764
|
+
|
|
747
765
|
# Author(s):: 0day Inc. <support@0dayinc.com>
|
|
748
766
|
|
|
749
767
|
public_class_method def self.authors
|
|
@@ -797,7 +815,7 @@ module PWN
|
|
|
797
815
|
timeout: 'optional - seconds (default 180)',
|
|
798
816
|
spinner: 'optional - display spinner (default false)',
|
|
799
817
|
quiet: 'optional - quiet value consumed by #chat_with_tools',
|
|
800
|
-
reasoning_effort: 'optional - Grok reasoning effort
|
|
818
|
+
reasoning_effort: 'optional - Grok reasoning effort; none is omitted or mapped to the lowest supported level',
|
|
801
819
|
server_tools: 'optional - hosted tool names such as web_search; sent on the Responses API only when client tools are omitted'
|
|
802
820
|
)
|
|
803
821
|
|
|
@@ -811,7 +829,8 @@ module PWN
|
|
|
811
829
|
speak_answer: 'optional - optional speak answer using PWN::Plugins::Voice.text_to_speech (Default: nil)',
|
|
812
830
|
timeout: 'optional - optional timeout in seconds (defaults to 900)',
|
|
813
831
|
spinner: 'optional - display spinner (defaults to false)',
|
|
814
|
-
quiet: 'optional - quiet value consumed by #chat'
|
|
832
|
+
quiet: 'optional - quiet value consumed by #chat',
|
|
833
|
+
reasoning_effort: 'optional - Grok reasoning effort; none is omitted or mapped to the lowest supported level'
|
|
815
834
|
)
|
|
816
835
|
|
|
817
836
|
# Print the AUTHOR(S) string for this module.
|
data/lib/pwn/ai/mcp.rb
CHANGED
|
@@ -68,7 +68,7 @@ module PWN
|
|
|
68
68
|
public_class_method def self.connect(opts = {})
|
|
69
69
|
backend = resolve(opts)
|
|
70
70
|
ident = (opts[:session_id] || backend[:name]).to_s
|
|
71
|
-
existing = @mutex.synchronize { @sessions[ident] }
|
|
71
|
+
existing = @mutex.synchronize { check_backend!(row: @sessions[ident], backend: opts[:force] ? nil : backend[:name]) }
|
|
72
72
|
return summarize(row: existing) if existing && !opts[:force]
|
|
73
73
|
|
|
74
74
|
connect_opts = {
|
|
@@ -100,6 +100,7 @@ module PWN
|
|
|
100
100
|
end
|
|
101
101
|
end
|
|
102
102
|
backend[:module].disconnect(session: extra) if extra
|
|
103
|
+
check_backend!(row: row, backend: backend[:name])
|
|
103
104
|
@mutex.synchronize { @current = row[:backend] }
|
|
104
105
|
summarize(row: row)
|
|
105
106
|
end
|
|
@@ -108,7 +109,10 @@ module PWN
|
|
|
108
109
|
|
|
109
110
|
public_class_method def self.disconnect(opts = {})
|
|
110
111
|
ident = session_id(opts)
|
|
111
|
-
row = @mutex.synchronize
|
|
112
|
+
row = @mutex.synchronize do
|
|
113
|
+
check_backend!(row: @sessions[ident], backend: opts[:backend])
|
|
114
|
+
@sessions.delete(ident)
|
|
115
|
+
end
|
|
112
116
|
return { disconnected: false, session_id: ident } unless row
|
|
113
117
|
|
|
114
118
|
row[:module].disconnect(session: row[:session])
|
|
@@ -189,7 +193,7 @@ module PWN
|
|
|
189
193
|
when 'poll_until', 'poll' then poll_until(args)
|
|
190
194
|
when 'status'
|
|
191
195
|
ident = session_id(args)
|
|
192
|
-
row = @mutex.synchronize { @sessions[ident] }
|
|
196
|
+
row = @mutex.synchronize { check_backend!(row: @sessions[ident], backend: args[:backend]) }
|
|
193
197
|
return { connected: false, session_id: ident } unless row
|
|
194
198
|
|
|
195
199
|
summarize(row: row).merge(connected: true)
|
|
@@ -344,11 +348,19 @@ module PWN
|
|
|
344
348
|
|
|
345
349
|
private_class_method def self.ensure_session(opts = {})
|
|
346
350
|
ident = session_id(opts)
|
|
347
|
-
row = @mutex.synchronize { @sessions[ident] }
|
|
351
|
+
row = @mutex.synchronize { check_backend!(row: @sessions[ident], backend: opts[:backend]) }
|
|
348
352
|
return row if row
|
|
349
353
|
|
|
350
354
|
connect(opts)
|
|
351
|
-
@mutex.synchronize { @sessions[ident] }
|
|
355
|
+
@mutex.synchronize { check_backend!(row: @sessions[ident], backend: opts[:backend]) }
|
|
356
|
+
end
|
|
357
|
+
|
|
358
|
+
private_class_method def self.check_backend!(opts = {})
|
|
359
|
+
row = opts[:row]
|
|
360
|
+
backend = opts[:backend].to_s
|
|
361
|
+
raise ArgumentError, "MCP session #{row[:session_id]} belongs to #{row[:backend]}, not #{backend}" if row && !backend.empty? && row[:backend] != backend
|
|
362
|
+
|
|
363
|
+
row
|
|
352
364
|
end
|
|
353
365
|
|
|
354
366
|
private_class_method def self.summarize(opts = {})
|
data/lib/pwn/ai/ollama.rb
CHANGED
|
@@ -86,7 +86,7 @@ module PWN
|
|
|
86
86
|
method: http_method,
|
|
87
87
|
url: "#{base_uri}/#{rest_call}",
|
|
88
88
|
headers: headers,
|
|
89
|
-
verify_ssl:
|
|
89
|
+
verify_ssl: true,
|
|
90
90
|
timeout: timeout
|
|
91
91
|
)
|
|
92
92
|
|
|
@@ -99,7 +99,7 @@ module PWN
|
|
|
99
99
|
url: "#{base_uri}/#{rest_call}",
|
|
100
100
|
headers: headers,
|
|
101
101
|
payload: http_body,
|
|
102
|
-
verify_ssl:
|
|
102
|
+
verify_ssl: true,
|
|
103
103
|
timeout: timeout
|
|
104
104
|
)
|
|
105
105
|
elsif stream
|
|
@@ -127,7 +127,7 @@ module PWN
|
|
|
127
127
|
url: "#{base_uri}/#{rest_call}",
|
|
128
128
|
headers: headers,
|
|
129
129
|
payload: http_body.to_json,
|
|
130
|
-
verify_ssl:
|
|
130
|
+
verify_ssl: true,
|
|
131
131
|
open_timeout: [timeout.to_f, 30.0].min,
|
|
132
132
|
read_timeout: idle_timeout,
|
|
133
133
|
block_response: lambda do |http_resp|
|
|
@@ -164,7 +164,7 @@ module PWN
|
|
|
164
164
|
url: "#{base_uri}/#{rest_call}",
|
|
165
165
|
headers: headers,
|
|
166
166
|
payload: http_body.to_json,
|
|
167
|
-
verify_ssl:
|
|
167
|
+
verify_ssl: true,
|
|
168
168
|
timeout: timeout
|
|
169
169
|
)
|
|
170
170
|
end
|
|
@@ -267,44 +267,84 @@ module PWN
|
|
|
267
267
|
body = opts[:body].to_s
|
|
268
268
|
rest_call = opts[:rest_call].to_s
|
|
269
269
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
270
|
+
records = stream_records(body: body, rest_call: rest_call)
|
|
271
|
+
done = false
|
|
272
|
+
payloads = records.filter_map do |record|
|
|
273
|
+
raise "ERROR: Ollama incomplete SSE stream for #{rest_call}: unterminated event" if record[:incomplete]
|
|
274
274
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
275
|
+
data = record[:data]
|
|
276
|
+
if data == '[DONE]'
|
|
277
|
+
done = true
|
|
278
|
+
next
|
|
279
279
|
end
|
|
280
|
-
|
|
281
|
-
if payloads.empty?
|
|
282
|
-
return {
|
|
283
|
-
message: {
|
|
284
|
-
role: 'assistant',
|
|
285
|
-
content: '',
|
|
286
|
-
error: 'empty_stream_payloads'
|
|
287
|
-
},
|
|
288
|
-
done: true,
|
|
289
|
-
done_reason: 'error'
|
|
290
|
-
}.to_json
|
|
291
|
-
end
|
|
280
|
+
raise "ERROR: Ollama malformed stream after [DONE] for #{rest_call}" if done
|
|
292
281
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
282
|
+
payload = parse_stream_payload(data: data, rest_call: rest_call)
|
|
283
|
+
error = payload[:error] || (payload if record[:event] == 'error')
|
|
284
|
+
if error
|
|
285
|
+
detail = error.is_a?(Hash) ? (error[:message] || error) : error
|
|
286
|
+
raise "ERROR: Ollama stream error for #{rest_call}: #{detail}"
|
|
287
|
+
end
|
|
288
|
+
payload
|
|
289
|
+
end
|
|
290
|
+
raise "ERROR: Ollama incomplete stream for #{rest_call}: no payloads" if payloads.empty?
|
|
296
291
|
|
|
292
|
+
openai_compat = rest_call.include?('chat/completions') || payloads.any? { |p| p.key?(:choices) }
|
|
297
293
|
if openai_compat
|
|
294
|
+
finished = payloads.any? { |p| Array(p[:choices]).any? { |ch| ch[:finish_reason] } }
|
|
295
|
+
raise "ERROR: Ollama incomplete stream for #{rest_call}: missing terminal event" unless done || finished
|
|
296
|
+
|
|
298
297
|
assemble_openai_compat_stream(payloads: payloads)
|
|
299
298
|
else
|
|
299
|
+
raise "ERROR: Ollama malformed native stream for #{rest_call}: expected message object" unless payloads.any? { |p| p[:message].is_a?(Hash) } && payloads.all? { |p| !p.key?(:message) || p[:message].is_a?(Hash) }
|
|
300
|
+
raise "ERROR: Ollama incomplete native stream for #{rest_call}: missing terminal done frame" unless payloads.last[:done] == true && payloads[0...-1].all? { |p| p[:done] == false }
|
|
301
|
+
|
|
300
302
|
assemble_native_chat_stream(payloads: payloads)
|
|
301
303
|
end
|
|
302
304
|
end
|
|
303
305
|
|
|
306
|
+
# SSE dispatches at blank lines, joining every data field with a newline.
|
|
307
|
+
# Native NDJSON accepts a complete last record without a trailing newline.
|
|
308
|
+
private_class_method def self.stream_records(opts = {})
|
|
309
|
+
lines = opts[:body].sub(/\A\uFEFF/, '').split(/\r\n|\r|\n/, -1)
|
|
310
|
+
lines.pop if lines.last == ''
|
|
311
|
+
sse = lines.any? { |line| line.match?(/\A(?:data|event|id|retry)(?::|\z)|\A:/) }
|
|
312
|
+
return lines.reject { |line| line.strip.empty? }.map { |line| { data: line } } unless sse
|
|
313
|
+
|
|
314
|
+
records = []
|
|
315
|
+
data = []
|
|
316
|
+
event = nil
|
|
317
|
+
lines.each do |line|
|
|
318
|
+
if line.empty?
|
|
319
|
+
records << { data: data.join("\n"), event: event } unless data.empty?
|
|
320
|
+
data = []
|
|
321
|
+
event = nil
|
|
322
|
+
else
|
|
323
|
+
field, value = line.split(':', 2)
|
|
324
|
+
value = value.to_s.delete_prefix(' ')
|
|
325
|
+
data << value if field == 'data'
|
|
326
|
+
event = value if field == 'event'
|
|
327
|
+
end
|
|
328
|
+
end
|
|
329
|
+
# Keep framing failures ordered after any earlier provider error event.
|
|
330
|
+
records.reject! { |record| record[:data].empty? }
|
|
331
|
+
records << { incomplete: true } unless data.empty?
|
|
332
|
+
records
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
private_class_method def self.parse_stream_payload(opts = {})
|
|
336
|
+
payload = JSON.parse(opts[:data], symbolize_names: true)
|
|
337
|
+
raise "ERROR: Ollama malformed stream for #{opts[:rest_call]}: expected object" unless payload.is_a?(Hash)
|
|
338
|
+
|
|
339
|
+
payload
|
|
340
|
+
rescue JSON::ParserError
|
|
341
|
+
raise "ERROR: Ollama malformed stream JSON for #{opts[:rest_call]}"
|
|
342
|
+
end
|
|
343
|
+
|
|
304
344
|
# Native Ollama /api/chat NDJSON → single-object JSON string.
|
|
305
345
|
private_class_method def self.assemble_native_chat_stream(opts = {})
|
|
306
346
|
payloads = opts[:payloads]
|
|
307
|
-
final = payloads.
|
|
347
|
+
final = payloads.last
|
|
308
348
|
content = +''
|
|
309
349
|
thinking = +''
|
|
310
350
|
tool_calls = []
|
|
@@ -330,7 +370,7 @@ module PWN
|
|
|
330
370
|
model: final[:model],
|
|
331
371
|
created_at: final[:created_at],
|
|
332
372
|
message: message,
|
|
333
|
-
done:
|
|
373
|
+
done: final[:done],
|
|
334
374
|
done_reason: final[:done_reason],
|
|
335
375
|
total_duration: final[:total_duration],
|
|
336
376
|
load_duration: final[:load_duration],
|
|
@@ -533,7 +573,7 @@ module PWN
|
|
|
533
573
|
text = (row.key?(:content) ? row[:content] : row['content']).to_s
|
|
534
574
|
parts << text unless text.strip.empty?
|
|
535
575
|
else
|
|
536
|
-
rest << row
|
|
576
|
+
rest << row.dup
|
|
537
577
|
end
|
|
538
578
|
end
|
|
539
579
|
return rest if parts.empty?
|
|
@@ -544,7 +584,8 @@ module PWN
|
|
|
544
584
|
user = rest.find { |row| (row[:role] || row['role']).to_s == 'user' }
|
|
545
585
|
if user
|
|
546
586
|
body = (user.key?(:content) ? user[:content] : user['content']).to_s
|
|
547
|
-
|
|
587
|
+
# Returned history may already contain this strict-template prefix.
|
|
588
|
+
user[:content] = body == text || body.start_with?("#{text}\n\n") ? body : "#{text}\n\n#{body}"
|
|
548
589
|
user.delete('content')
|
|
549
590
|
rest
|
|
550
591
|
else
|
|
@@ -761,10 +802,10 @@ module PWN
|
|
|
761
802
|
}
|
|
762
803
|
}
|
|
763
804
|
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
805
|
+
Array(response_history[:choices] || response_history['choices']).each_with_index do |message, index|
|
|
806
|
+
next if index.zero? && %w[system developer].include?((message[:role] || message['role']).to_s)
|
|
807
|
+
|
|
808
|
+
http_body[:messages].push(message)
|
|
768
809
|
end
|
|
769
810
|
|
|
770
811
|
http_body[:messages].push(user_role)
|