pwn 0.5.795 → 0.5.796
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 +1 -1
- 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/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/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 +12 -11
- data/lib/pwn/ai/agent/metrics.rb +1 -1
- data/lib/pwn/ai/agent/mission.rb +6 -3
- 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/repl/ai.rb +1 -0
- data/lib/pwn/plugins/repl/ai_console.rb +12 -5
- data/lib/pwn/plugins/repl/mesh.rb +10 -2
- 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 +307 -39
- 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/pwn.gemspec +4 -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/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 +210 -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_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/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/repl/ai_console_spec.rb +111 -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/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 +45 -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_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/support/namespace_controller_observability_fixture.rb +141 -0
- data/spec/support/sandbox.rb +8 -5
- data/third_party/pwn_rdoc.jsonl +73 -31
- metadata +137 -18
- 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
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)
|
data/lib/pwn/ai/open_ai.rb
CHANGED
|
@@ -471,7 +471,7 @@ module PWN
|
|
|
471
471
|
method: http_method,
|
|
472
472
|
url: "#{base_uri}/#{rest_call}",
|
|
473
473
|
headers: headers,
|
|
474
|
-
verify_ssl:
|
|
474
|
+
verify_ssl: true,
|
|
475
475
|
max_redirects: oauth_selected ? 0 : 10,
|
|
476
476
|
timeout: timeout
|
|
477
477
|
)
|
|
@@ -485,7 +485,7 @@ module PWN
|
|
|
485
485
|
url: "#{base_uri}/#{rest_call}",
|
|
486
486
|
headers: headers,
|
|
487
487
|
payload: http_body,
|
|
488
|
-
verify_ssl:
|
|
488
|
+
verify_ssl: true,
|
|
489
489
|
max_redirects: oauth_selected ? 0 : 10,
|
|
490
490
|
timeout: timeout
|
|
491
491
|
)
|
|
@@ -495,7 +495,7 @@ module PWN
|
|
|
495
495
|
url: "#{base_uri}/#{rest_call}",
|
|
496
496
|
headers: headers,
|
|
497
497
|
payload: http_body.to_json,
|
|
498
|
-
verify_ssl:
|
|
498
|
+
verify_ssl: true,
|
|
499
499
|
max_redirects: oauth_selected ? 0 : 10,
|
|
500
500
|
timeout: timeout
|
|
501
501
|
)
|
|
@@ -545,20 +545,8 @@ module PWN
|
|
|
545
545
|
rescue RestClient::ExceptionWithResponse => e
|
|
546
546
|
raise e if oauth_selected || e.is_a?(RestClient::TooManyRequests) || Thread.current[:pwn_provider_attempt_owner]
|
|
547
547
|
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
rescue StandardError => e
|
|
551
|
-
raise e if oauth_selected
|
|
552
|
-
raise e if Thread.current[:pwn_provider_attempt_owner]
|
|
553
|
-
|
|
554
|
-
case e.message
|
|
555
|
-
when '400 Bad Request', '404 Resource Not Found'
|
|
556
|
-
nil
|
|
557
|
-
else
|
|
558
|
-
raise e unless opts[:quiet]
|
|
559
|
-
|
|
560
|
-
end
|
|
561
|
-
"#{e.message}: #{e.response}"
|
|
548
|
+
e.message = "OpenAI HTTP #{e.http_code} (#{http_method.to_s.upcase} #{rest_call}): #{e.response&.body}"
|
|
549
|
+
raise
|
|
562
550
|
ensure
|
|
563
551
|
PWN::Plugins::TTYSpinner.stop(spin: spin)
|
|
564
552
|
end
|
|
@@ -1440,7 +1428,7 @@ module PWN
|
|
|
1440
1428
|
file = opts[:file]
|
|
1441
1429
|
timeout = opts[:timeout]
|
|
1442
1430
|
|
|
1443
|
-
response = list_files(
|
|
1431
|
+
response = list_files(timeout: timeout)
|
|
1444
1432
|
file_id = response[:data].select { |f| f if f[:filename] == File.basename(file) }.first[:id]
|
|
1445
1433
|
|
|
1446
1434
|
rest_call = "files/#{file_id}"
|
|
@@ -1468,7 +1456,7 @@ module PWN
|
|
|
1468
1456
|
|
|
1469
1457
|
timeout = opts[:timeout]
|
|
1470
1458
|
|
|
1471
|
-
response = list_files(
|
|
1459
|
+
response = list_files(timeout: timeout)
|
|
1472
1460
|
file_id = response[:data].select { |f| f if f[:filename] == File.basename(file) }.first[:id]
|
|
1473
1461
|
|
|
1474
1462
|
rest_call = "files/#{file_id}"
|
data/lib/pwn/ai/open_web_ui.rb
CHANGED
|
@@ -98,7 +98,7 @@ module PWN
|
|
|
98
98
|
method: http_method,
|
|
99
99
|
url: "#{base_uri}/#{rest_call}",
|
|
100
100
|
headers: headers,
|
|
101
|
-
verify_ssl:
|
|
101
|
+
verify_ssl: true,
|
|
102
102
|
timeout: timeout
|
|
103
103
|
)
|
|
104
104
|
|
|
@@ -111,7 +111,7 @@ module PWN
|
|
|
111
111
|
url: "#{base_uri}/#{rest_call}",
|
|
112
112
|
headers: headers,
|
|
113
113
|
payload: http_body,
|
|
114
|
-
verify_ssl:
|
|
114
|
+
verify_ssl: true,
|
|
115
115
|
timeout: timeout
|
|
116
116
|
)
|
|
117
117
|
elsif stream
|
|
@@ -138,7 +138,7 @@ module PWN
|
|
|
138
138
|
url: "#{base_uri}/#{rest_call}",
|
|
139
139
|
headers: headers,
|
|
140
140
|
payload: http_body.to_json,
|
|
141
|
-
verify_ssl:
|
|
141
|
+
verify_ssl: true,
|
|
142
142
|
open_timeout: [timeout.to_f, 30.0].min,
|
|
143
143
|
read_timeout: idle_timeout,
|
|
144
144
|
block_response: lambda do |http_resp|
|
|
@@ -180,7 +180,7 @@ module PWN
|
|
|
180
180
|
url: "#{base_uri}/#{rest_call}",
|
|
181
181
|
headers: headers,
|
|
182
182
|
payload: http_body.to_json,
|
|
183
|
-
verify_ssl:
|
|
183
|
+
verify_ssl: true,
|
|
184
184
|
timeout: timeout
|
|
185
185
|
)
|
|
186
186
|
end
|
|
@@ -280,46 +280,84 @@ module PWN
|
|
|
280
280
|
body = opts[:body].to_s
|
|
281
281
|
rest_call = opts[:rest_call].to_s
|
|
282
282
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
payloads =
|
|
286
|
-
|
|
287
|
-
next if line.empty? || line == '[DONE]'
|
|
283
|
+
records = stream_records(body: body, rest_call: rest_call)
|
|
284
|
+
done = false
|
|
285
|
+
payloads = records.filter_map do |record|
|
|
286
|
+
raise "ERROR: Open WebUI incomplete SSE stream for #{rest_call}: unterminated event" if record[:incomplete]
|
|
288
287
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
288
|
+
data = record[:data]
|
|
289
|
+
if data == '[DONE]'
|
|
290
|
+
done = true
|
|
291
|
+
next
|
|
293
292
|
end
|
|
294
|
-
|
|
295
|
-
if payloads.empty?
|
|
296
|
-
return {
|
|
297
|
-
message: {
|
|
298
|
-
role: 'assistant',
|
|
299
|
-
content: '',
|
|
300
|
-
error: 'empty_stream_payloads'
|
|
301
|
-
},
|
|
302
|
-
done: true,
|
|
303
|
-
done_reason: 'error'
|
|
304
|
-
}.to_json
|
|
305
|
-
end
|
|
293
|
+
raise "ERROR: Open WebUI malformed stream after [DONE] for #{rest_call}" if done
|
|
306
294
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
295
|
+
payload = parse_stream_payload(data: data, rest_call: rest_call)
|
|
296
|
+
error = payload[:error] || (payload if record[:event] == 'error')
|
|
297
|
+
if error
|
|
298
|
+
detail = error.is_a?(Hash) ? (error[:message] || error) : error
|
|
299
|
+
raise "ERROR: Open WebUI stream error for #{rest_call}: #{detail}"
|
|
300
|
+
end
|
|
301
|
+
payload
|
|
302
|
+
end
|
|
303
|
+
raise "ERROR: Open WebUI incomplete stream for #{rest_call}: no payloads" if payloads.empty?
|
|
311
304
|
|
|
305
|
+
openai_compat = rest_call.include?('chat/completions') || payloads.any? { |p| p.key?(:choices) }
|
|
312
306
|
if openai_compat
|
|
307
|
+
finished = payloads.any? { |p| Array(p[:choices]).any? { |ch| ch[:finish_reason] } }
|
|
308
|
+
raise "ERROR: Open WebUI incomplete stream for #{rest_call}: missing terminal event" unless done || finished
|
|
309
|
+
|
|
313
310
|
assemble_openai_compat_stream(payloads: payloads)
|
|
314
311
|
else
|
|
312
|
+
raise "ERROR: Open WebUI 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) }
|
|
313
|
+
raise "ERROR: Open WebUI incomplete native stream for #{rest_call}: missing terminal done frame" unless payloads.last[:done] == true && payloads[0...-1].all? { |p| p[:done] == false }
|
|
314
|
+
|
|
315
315
|
assemble_native_chat_stream(payloads: payloads)
|
|
316
316
|
end
|
|
317
317
|
end
|
|
318
318
|
|
|
319
|
+
# SSE dispatches at blank lines, joining every data field with a newline.
|
|
320
|
+
# Native NDJSON accepts a complete last record without a trailing newline.
|
|
321
|
+
private_class_method def self.stream_records(opts = {})
|
|
322
|
+
lines = opts[:body].sub(/\A\uFEFF/, '').split(/\r\n|\r|\n/, -1)
|
|
323
|
+
lines.pop if lines.last == ''
|
|
324
|
+
sse = lines.any? { |line| line.match?(/\A(?:data|event|id|retry)(?::|\z)|\A:/) }
|
|
325
|
+
return lines.reject { |line| line.strip.empty? }.map { |line| { data: line } } unless sse
|
|
326
|
+
|
|
327
|
+
records = []
|
|
328
|
+
data = []
|
|
329
|
+
event = nil
|
|
330
|
+
lines.each do |line|
|
|
331
|
+
if line.empty?
|
|
332
|
+
records << { data: data.join("\n"), event: event } unless data.empty?
|
|
333
|
+
data = []
|
|
334
|
+
event = nil
|
|
335
|
+
else
|
|
336
|
+
field, value = line.split(':', 2)
|
|
337
|
+
value = value.to_s.delete_prefix(' ')
|
|
338
|
+
data << value if field == 'data'
|
|
339
|
+
event = value if field == 'event'
|
|
340
|
+
end
|
|
341
|
+
end
|
|
342
|
+
# Keep framing failures ordered after any earlier provider error event.
|
|
343
|
+
records.reject! { |record| record[:data].empty? }
|
|
344
|
+
records << { incomplete: true } unless data.empty?
|
|
345
|
+
records
|
|
346
|
+
end
|
|
347
|
+
|
|
348
|
+
private_class_method def self.parse_stream_payload(opts = {})
|
|
349
|
+
payload = JSON.parse(opts[:data], symbolize_names: true)
|
|
350
|
+
raise "ERROR: Open WebUI malformed stream for #{opts[:rest_call]}: expected object" unless payload.is_a?(Hash)
|
|
351
|
+
|
|
352
|
+
payload
|
|
353
|
+
rescue JSON::ParserError
|
|
354
|
+
raise "ERROR: Open WebUI malformed stream JSON for #{opts[:rest_call]}"
|
|
355
|
+
end
|
|
356
|
+
|
|
319
357
|
# Proxied Ollama /ollama/api/chat NDJSON → single-object JSON string.
|
|
320
358
|
private_class_method def self.assemble_native_chat_stream(opts = {})
|
|
321
359
|
payloads = opts[:payloads]
|
|
322
|
-
final = payloads.
|
|
360
|
+
final = payloads.last
|
|
323
361
|
content = +''
|
|
324
362
|
thinking = +''
|
|
325
363
|
tool_calls = []
|
|
@@ -346,7 +384,7 @@ module PWN
|
|
|
346
384
|
model: final[:model],
|
|
347
385
|
created_at: final[:created_at],
|
|
348
386
|
message: message,
|
|
349
|
-
done:
|
|
387
|
+
done: final[:done],
|
|
350
388
|
done_reason: final[:done_reason],
|
|
351
389
|
total_duration: final[:total_duration],
|
|
352
390
|
load_duration: final[:load_duration],
|
|
@@ -565,7 +603,7 @@ module PWN
|
|
|
565
603
|
text = (row.key?(:content) ? row[:content] : row['content']).to_s
|
|
566
604
|
parts << text unless text.strip.empty?
|
|
567
605
|
else
|
|
568
|
-
rest << row
|
|
606
|
+
rest << row.dup
|
|
569
607
|
end
|
|
570
608
|
end
|
|
571
609
|
return rest if parts.empty?
|
|
@@ -576,7 +614,8 @@ module PWN
|
|
|
576
614
|
user = rest.find { |row| (row[:role] || row['role']).to_s == 'user' }
|
|
577
615
|
if user
|
|
578
616
|
body = (user.key?(:content) ? user[:content] : user['content']).to_s
|
|
579
|
-
|
|
617
|
+
# Returned history may already contain this strict-template prefix.
|
|
618
|
+
user[:content] = body == text || body.start_with?("#{text}\n\n") ? body : "#{text}\n\n#{body}"
|
|
580
619
|
user.delete('content')
|
|
581
620
|
rest
|
|
582
621
|
else
|
|
@@ -804,8 +843,6 @@ module PWN
|
|
|
804
843
|
|
|
805
844
|
response_history = opts[:response_history]
|
|
806
845
|
|
|
807
|
-
max_tokens = response_history[:usage][:total_tokens] unless response_history.nil?
|
|
808
|
-
|
|
809
846
|
system_role_content = opts[:system_role_content] ||= engine[:system_role_content]
|
|
810
847
|
|
|
811
848
|
system_role = {
|
|
@@ -819,7 +856,6 @@ module PWN
|
|
|
819
856
|
}
|
|
820
857
|
|
|
821
858
|
response_history ||= { choices: [system_role] }
|
|
822
|
-
choices_len = response_history[:choices].length
|
|
823
859
|
|
|
824
860
|
http_body = {
|
|
825
861
|
model: model,
|
|
@@ -828,10 +864,10 @@ module PWN
|
|
|
828
864
|
stream: true
|
|
829
865
|
}
|
|
830
866
|
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
867
|
+
Array(response_history[:choices] || response_history['choices']).each_with_index do |message, index|
|
|
868
|
+
next if index.zero? && %w[system developer].include?((message[:role] || message['role']).to_s)
|
|
869
|
+
|
|
870
|
+
http_body[:messages].push(message)
|
|
835
871
|
end
|
|
836
872
|
|
|
837
873
|
http_body[:messages].push(user_role)
|
|
@@ -10,6 +10,7 @@ module PWN
|
|
|
10
10
|
|
|
11
11
|
# Supported Method Parameters::
|
|
12
12
|
# PWN::AWS::CloudSearchDomain.connect(
|
|
13
|
+
# endpoint: 'required - CloudSearch domain search or document endpoint URL unless configured in the AWS SDK',
|
|
13
14
|
# region: 'required - region name to connect (eu-west-1, ap-southeast-1, ap-southeast-2, eu-central-1, ap-northeast-2, ap-northeast-1, us-east-1, sa-east-1, us-west-1, us-west-2)',
|
|
14
15
|
# access_key_id: 'required - Use AWS STS for best privacy (i.e. temporary access key id)',
|
|
15
16
|
# secret_access_key: 'required - Use AWS STS for best privacy (i.e. temporary secret access key',
|
|
@@ -18,6 +19,8 @@ module PWN
|
|
|
18
19
|
|
|
19
20
|
public_class_method def self.connect(opts = {})
|
|
20
21
|
region = opts[:region].to_s.scrub.chomp.strip
|
|
22
|
+
endpoint = opts[:endpoint]
|
|
23
|
+
endpoint_options = endpoint.nil? ? {} : { endpoint: endpoint }
|
|
21
24
|
access_key_id = opts[:access_key_id].to_s.scrub.chomp.strip
|
|
22
25
|
secret_access_key = opts[:secret_access_key].to_s.scrub.chomp.strip
|
|
23
26
|
sts_session_token = opts[:sts_session_token].to_s.scrub.chomp.strip
|
|
@@ -25,12 +28,14 @@ module PWN
|
|
|
25
28
|
@@logger.info('Connecting to AWS CloudSearchDomain...')
|
|
26
29
|
if sts_session_token == ''
|
|
27
30
|
cloud_search_domain_obj = Aws::CloudSearchDomain::Client.new(
|
|
31
|
+
**endpoint_options,
|
|
28
32
|
region: region,
|
|
29
33
|
access_key_id: access_key_id,
|
|
30
34
|
secret_access_key: secret_access_key
|
|
31
35
|
)
|
|
32
36
|
else
|
|
33
37
|
cloud_search_domain_obj = Aws::CloudSearchDomain::Client.new(
|
|
38
|
+
**endpoint_options,
|
|
34
39
|
region: region,
|
|
35
40
|
access_key_id: access_key_id,
|
|
36
41
|
secret_access_key: secret_access_key,
|
|
@@ -74,6 +79,7 @@ module PWN
|
|
|
74
79
|
puts "USAGE:
|
|
75
80
|
# Run connect and return its result
|
|
76
81
|
#{self}.connect(
|
|
82
|
+
endpoint: 'required - CloudSearch domain search or document endpoint URL unless configured in the AWS SDK',
|
|
77
83
|
region: 'required - region name to connect (eu-west-1, ap-southeast-1, ap-southeast-2, eu-central-1, ap-northeast-2, ap-northeast-1, us-east-1, sa-east-1, us-west-1, us-west-2)',
|
|
78
84
|
access_key_id: 'required - Use AWS STS for best privacy (i.e. temporary access key id)',
|
|
79
85
|
secret_access_key: 'required - Use AWS STS for best privacy (i.e. temporary secret access key',
|