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.
Files changed (369) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/bin/pwn_autoinc_version +4 -5
  4. data/bin/pwn_web_cache_deception +40 -29
  5. data/documentation/AWS.md +15 -5
  6. data/documentation/Diagrams.md +1 -1
  7. data/documentation/Home.md +2 -2
  8. data/documentation/How-PWN-Works.md +1 -1
  9. data/documentation/What-is-PWN.md +1 -1
  10. data/documentation/diagrams/aws-cloud-security.svg +1 -1
  11. data/documentation/diagrams/dot/aws-cloud-security.dot +1 -1
  12. data/documentation/diagrams/dot/network-infra-testing.dot +1 -1
  13. data/documentation/diagrams/network-infra-testing.svg +1 -1
  14. data/etc/default_cron/session_cleanup.rb +84 -51
  15. data/lib/pwn/ai/agent/assembly.rb +0 -2
  16. data/lib/pwn/ai/agent/btc.rb +0 -2
  17. data/lib/pwn/ai/agent/burp_suite.rb +0 -2
  18. data/lib/pwn/ai/agent/curriculum.rb +2 -2
  19. data/lib/pwn/ai/agent/dispatch.rb +3 -0
  20. data/lib/pwn/ai/agent/engagement.rb +96 -41
  21. data/lib/pwn/ai/agent/extrospection/osint/bridges.rb +2 -0
  22. data/lib/pwn/ai/agent/extrospection.rb +50 -13
  23. data/lib/pwn/ai/agent/gqrx.rb +0 -2
  24. data/lib/pwn/ai/agent/hacker_one.rb +0 -2
  25. data/lib/pwn/ai/agent/learning.rb +45 -13
  26. data/lib/pwn/ai/agent/loop.rb +12 -11
  27. data/lib/pwn/ai/agent/metrics.rb +1 -1
  28. data/lib/pwn/ai/agent/mission.rb +6 -3
  29. data/lib/pwn/ai/agent/policy.rb +1 -1
  30. data/lib/pwn/ai/agent/policy_evaluation.rb +2 -2
  31. data/lib/pwn/ai/agent/reflect.rb +1 -0
  32. data/lib/pwn/ai/agent/request_runtime.rb +1 -1
  33. data/lib/pwn/ai/agent/reward.rb +155 -53
  34. data/lib/pwn/ai/agent/sast.rb +0 -2
  35. data/lib/pwn/ai/agent/task_dag.rb +5 -3
  36. data/lib/pwn/ai/agent/task_summarizer.rb +21 -11
  37. data/lib/pwn/ai/agent/tool_guard.rb +19 -0
  38. data/lib/pwn/ai/agent/tools/ruby_eval.rb +1 -1
  39. data/lib/pwn/ai/agent/tools/verify.rb +7 -3
  40. data/lib/pwn/ai/agent/transparent_browser.rb +0 -2
  41. data/lib/pwn/ai/agent/turn_finalizer.rb +3 -0
  42. data/lib/pwn/ai/anthropic.rb +3 -3
  43. data/lib/pwn/ai/context.rb +2 -1
  44. data/lib/pwn/ai/gemini.rb +7 -5
  45. data/lib/pwn/ai/grok.rb +37 -18
  46. data/lib/pwn/ai/mcp.rb +17 -5
  47. data/lib/pwn/ai/ollama.rb +76 -35
  48. data/lib/pwn/ai/open_ai.rb +7 -19
  49. data/lib/pwn/ai/open_web_ui.rb +76 -40
  50. data/lib/pwn/aws/cloud_search_domain.rb +6 -0
  51. data/lib/pwn/aws/iam.rb +2 -2
  52. data/lib/pwn/aws/workspaces.rb +2 -2
  53. data/lib/pwn/aws.rb +0 -5
  54. data/lib/pwn/bounty/lifecycle_authz_replay.rb +1 -1
  55. data/lib/pwn/config.rb +17 -10
  56. data/lib/pwn/corpus.rb +33 -5
  57. data/lib/pwn/cron.rb +60 -17
  58. data/lib/pwn/driver.rb +2 -3
  59. data/lib/pwn/engagement.rb +28 -10
  60. data/lib/pwn/ffi/capstone.rb +3 -2
  61. data/lib/pwn/ffi/fftw.rb +8 -6
  62. data/lib/pwn/ffi/keystone.rb +3 -2
  63. data/lib/pwn/ffi/soapy_sdr.rb +10 -6
  64. data/lib/pwn/json_text.rb +25 -13
  65. data/lib/pwn/memory_index.rb +6 -4
  66. data/lib/pwn/module_skills.rb +3 -1
  67. data/lib/pwn/plugins/aflplusplus.rb +1 -0
  68. data/lib/pwn/plugins/ai_sandbox.rb +42 -10
  69. data/lib/pwn/plugins/android.rb +429 -466
  70. data/lib/pwn/plugins/artifact_registry.rb +12 -2
  71. data/lib/pwn/plugins/assembly.rb +9 -42
  72. data/lib/pwn/plugins/authentication_helper.rb +4 -3
  73. data/lib/pwn/plugins/baresip.rb +70 -28
  74. data/lib/pwn/plugins/binary_analysis.rb +14 -5
  75. data/lib/pwn/plugins/binary_parser.rb +42 -7
  76. data/lib/pwn/plugins/black_duck_binary_analysis.rb +3 -3
  77. data/lib/pwn/plugins/burp_suite.rb +15 -12
  78. data/lib/pwn/plugins/bus_pirate.rb +3 -7
  79. data/lib/pwn/plugins/char.rb +9 -3
  80. data/lib/pwn/plugins/credit_card.rb +7 -0
  81. data/lib/pwn/plugins/dao_ldap.rb +2 -2
  82. data/lib/pwn/plugins/dao_mongo.rb +1 -1
  83. data/lib/pwn/plugins/debugger.rb +1 -1
  84. data/lib/pwn/plugins/defect_dojo.rb +7 -3
  85. data/lib/pwn/plugins/detect_os.rb +1 -1
  86. data/lib/pwn/plugins/detonate.rb +9 -19
  87. data/lib/pwn/plugins/exploit_db.rb +1 -1
  88. data/lib/pwn/plugins/file_fu.rb +4 -1
  89. data/lib/pwn/plugins/findings.rb +76 -2
  90. data/lib/pwn/plugins/fuzz.rb +12 -3
  91. data/lib/pwn/plugins/gdb.rb +7 -2
  92. data/lib/pwn/plugins/gdbmi.rb +10 -6
  93. data/lib/pwn/plugins/git.rb +18 -13
  94. data/lib/pwn/plugins/github.rb +11 -6
  95. data/lib/pwn/plugins/google_workspace.rb +11 -3
  96. data/lib/pwn/plugins/hacker_one.rb +5 -1
  97. data/lib/pwn/plugins/httpx.rb +24 -8
  98. data/lib/pwn/plugins/ip_info.rb +11 -8
  99. data/lib/pwn/plugins/irc.rb +73 -45
  100. data/lib/pwn/plugins/jenkins.rb +2 -2
  101. data/lib/pwn/plugins/jira_data_center.rb +13 -6
  102. data/lib/pwn/plugins/jobs.rb +62 -4
  103. data/lib/pwn/plugins/log.rb +1 -1
  104. data/lib/pwn/plugins/monkey_patch.rb +1 -1
  105. data/lib/pwn/plugins/msr206.rb +157 -182
  106. data/lib/pwn/plugins/nessus_cloud.rb +2 -2
  107. data/lib/pwn/plugins/nexpose_vuln_scan.rb +44 -33
  108. data/lib/pwn/plugins/nuclei.rb +24 -8
  109. data/lib/pwn/plugins/ocr.rb +3 -1
  110. data/lib/pwn/plugins/open_api.rb +0 -4
  111. data/lib/pwn/plugins/openvas.rb +31 -43
  112. data/lib/pwn/plugins/packet.rb +40 -25
  113. data/lib/pwn/plugins/pony.rb +2 -2
  114. data/lib/pwn/plugins/preflight_checker.rb +1 -1
  115. data/lib/pwn/plugins/process_tube.rb +17 -2
  116. data/lib/pwn/plugins/ps.rb +6 -1
  117. data/lib/pwn/plugins/repl/ai.rb +1 -0
  118. data/lib/pwn/plugins/repl/ai_console.rb +12 -5
  119. data/lib/pwn/plugins/repl/mesh.rb +10 -2
  120. data/lib/pwn/plugins/sbom.rb +59 -27
  121. data/lib/pwn/plugins/scannable_codes.rb +3 -1
  122. data/lib/pwn/plugins/serial.rb +102 -44
  123. data/lib/pwn/plugins/shodan.rb +4 -10
  124. data/lib/pwn/plugins/sock.rb +16 -11
  125. data/lib/pwn/plugins/ssn.rb +3 -1
  126. data/lib/pwn/plugins/transparent_browser.rb +43 -3
  127. data/lib/pwn/plugins/vault.rb +92 -30
  128. data/lib/pwn/plugins/vin.rb +2 -1
  129. data/lib/pwn/plugins/vsphere.rb +2 -1
  130. data/lib/pwn/plugins/xxd.rb +3 -5
  131. data/lib/pwn/plugins/yubikey/security_domain/scp.rb +4 -0
  132. data/lib/pwn/plugins/yubikey/transport.rb +42 -11
  133. data/lib/pwn/plugins/yubikey.rb +21 -6
  134. data/lib/pwn/plugins/zaproxy.rb +3 -4
  135. data/lib/pwn/reports/ai_red_team.rb +4 -4
  136. data/lib/pwn/reports/pdf.rb +9 -5
  137. data/lib/pwn/reports/sast.rb +4 -4
  138. data/lib/pwn/sast/keystore.rb +2 -2
  139. data/lib/pwn/sast/logger.rb +1 -1
  140. data/lib/pwn/sast/php_type_juggling.rb +3 -6
  141. data/lib/pwn/sast/pom_version.rb +12 -6
  142. data/lib/pwn/sast/port.rb +1 -1
  143. data/lib/pwn/sast/sql.rb +3 -7
  144. data/lib/pwn/sast/test_case_engine.rb +62 -16
  145. data/lib/pwn/sast/type_script_type_juggling.rb +3 -6
  146. data/lib/pwn/sdr/decoder/base.rb +8 -0
  147. data/lib/pwn/sdr/decoder/lora.rb +1 -1
  148. data/lib/pwn/sdr/flipper_zero.rb +4 -7
  149. data/lib/pwn/sdr/gqrx.rb +35 -16
  150. data/lib/pwn/sdr/son_micro_rfid.rb +44 -26
  151. data/lib/pwn/sdr.rb +1 -1
  152. data/lib/pwn/session_trace.rb +7 -2
  153. data/lib/pwn/sessions.rb +307 -39
  154. data/lib/pwn/setup.rb +4 -3
  155. data/lib/pwn/version.rb +1 -1
  156. data/lib/pwn/www/app_cobalt_io.rb +14 -2
  157. data/lib/pwn/www/bing.rb +13 -1
  158. data/lib/pwn/www/bug_crowd.rb +14 -2
  159. data/lib/pwn/www/checkip.rb +13 -1
  160. data/lib/pwn/www/coinbase_pro.rb +14 -2
  161. data/lib/pwn/www/duckduckgo.rb +13 -1
  162. data/lib/pwn/www/facebook.rb +14 -2
  163. data/lib/pwn/www/github.rb +14 -2
  164. data/lib/pwn/www/google.rb +13 -1
  165. data/lib/pwn/www/hacker_one.rb +117 -33
  166. data/lib/pwn/www/linkedin.rb +14 -2
  167. data/lib/pwn/www/pandora.rb +14 -2
  168. data/lib/pwn/www/pastebin.rb +13 -1
  169. data/lib/pwn/www/paypal.rb +16 -4
  170. data/lib/pwn/www/synack.rb +14 -2
  171. data/lib/pwn/www/torch.rb +17 -3
  172. data/lib/pwn/www/trading_view.rb +14 -2
  173. data/lib/pwn/www/twitter.rb +14 -2
  174. data/lib/pwn/www/uber.rb +14 -2
  175. data/lib/pwn/www/upwork.rb +14 -2
  176. data/lib/pwn/www/wayback_machine.rb +16 -2
  177. data/lib/pwn/www/youtube.rb +13 -1
  178. data/pwn.gemspec +4 -0
  179. data/spec/integration/authentication_helper_oath_spec.rb +1 -1
  180. data/spec/integration/autoinc_lifecycle_supplement_spec.rb +47 -0
  181. data/spec/integration/gemspec_deleted_files_spec.rb +43 -0
  182. data/spec/integration/spec_curriculum_isolation_spec.rb +41 -0
  183. data/spec/integration/verify_acceptance_eui_regression_spec.rb +162 -0
  184. data/spec/integration/web_cache_lifecycle_closure_spec.rb +89 -0
  185. data/spec/integration/web_cache_lifecycle_supplement_spec.rb +70 -0
  186. data/spec/lib/pwn/ai/agent/analysis_errors_regression_spec.rb +33 -0
  187. data/spec/lib/pwn/ai/agent/curriculum_cooldown_regression_spec.rb +19 -0
  188. data/spec/lib/pwn/ai/agent/curriculum_spec.rb +2 -0
  189. data/spec/lib/pwn/ai/agent/engagement_boundary_regression_spec.rb +42 -0
  190. data/spec/lib/pwn/ai/agent/engagement_dispatch_review_spec.rb +82 -0
  191. data/spec/lib/pwn/ai/agent/engagement_roe_regression_spec.rb +25 -0
  192. data/spec/lib/pwn/ai/agent/engagement_scope_regression_spec.rb +37 -0
  193. data/spec/lib/pwn/ai/agent/extrospection/osint/bridges_spec.rb +4 -0
  194. data/spec/lib/pwn/ai/agent/extrospection_input_regression_spec.rb +31 -0
  195. data/spec/lib/pwn/ai/agent/extrospection_review_spec.rb +61 -0
  196. data/spec/lib/pwn/ai/agent/extrospection_serial_review_spec.rb +42 -0
  197. data/spec/lib/pwn/ai/agent/extrospection_spec.rb +9 -0
  198. data/spec/lib/pwn/ai/agent/extrospection_verification_regression_spec.rb +39 -0
  199. data/spec/lib/pwn/ai/agent/learning_last_answer_regression_spec.rb +32 -0
  200. data/spec/lib/pwn/ai/agent/learning_lifecycle_closure_spec.rb +84 -0
  201. data/spec/lib/pwn/ai/agent/learning_prune_regression_spec.rb +17 -0
  202. data/spec/lib/pwn/ai/agent/learning_spec.rb +2 -1
  203. data/spec/lib/pwn/ai/agent/loop_execution_audit_spec.rb +30 -0
  204. data/spec/lib/pwn/ai/agent/metrics_usage_regression_spec.rb +20 -0
  205. data/spec/lib/pwn/ai/agent/mission_execution_audit_spec.rb +27 -0
  206. data/spec/lib/pwn/ai/agent/mission_namespace_spec.rb +210 -18
  207. data/spec/lib/pwn/ai/agent/policy_confidence_regression_spec.rb +16 -0
  208. data/spec/lib/pwn/ai/agent/policy_evaluation_spec.rb +1 -1
  209. data/spec/lib/pwn/ai/agent/policy_evaluation_tmp_regression_spec.rb +36 -0
  210. data/spec/lib/pwn/ai/agent/reflect_model_regression_spec.rb +15 -0
  211. data/spec/lib/pwn/ai/agent/request_runtime_execution_audit_spec.rb +43 -0
  212. data/spec/lib/pwn/ai/agent/reward_binding_review_spec.rb +129 -0
  213. data/spec/lib/pwn/ai/agent/reward_dispatch_review_spec.rb +154 -0
  214. data/spec/lib/pwn/ai/agent/reward_envelope_regression_spec.rb +45 -0
  215. data/spec/lib/pwn/ai/agent/reward_turn_regression_spec.rb +40 -0
  216. data/spec/lib/pwn/ai/agent/swarm_spec.rb +2 -2
  217. data/spec/lib/pwn/ai/agent/task_dag_execution_audit_spec.rb +45 -0
  218. data/spec/lib/pwn/ai/agent/task_summarizer_failure_regression_spec.rb +26 -0
  219. data/spec/lib/pwn/ai/agent/tools/verify_execution_audit_spec.rb +33 -0
  220. data/spec/lib/pwn/ai/context_range_audit_spec.rb +24 -0
  221. data/spec/lib/pwn/ai/gemini_roundtrip_audit_spec.rb +33 -0
  222. data/spec/lib/pwn/ai/grok_reasoning_effort_spec.rb +43 -0
  223. data/spec/lib/pwn/ai/mcp_session_audit_spec.rb +36 -0
  224. data/spec/lib/pwn/ai/ollama_spec.rb +6 -11
  225. data/spec/lib/pwn/ai/open_web_ui_spec.rb +6 -11
  226. data/spec/lib/pwn/ai/provider_history_audit_spec.rb +44 -0
  227. data/spec/lib/pwn/ai/provider_operations_audit_spec.rb +53 -0
  228. data/spec/lib/pwn/ai/provider_review_history_stream_regression_spec.rb +143 -0
  229. data/spec/lib/pwn/ai/provider_review_tls_regression_spec.rb +62 -0
  230. data/spec/lib/pwn/ai/provider_stream_audit_spec.rb +49 -0
  231. data/spec/lib/pwn/aws/iam_decoding_regression_spec.rb +23 -0
  232. data/spec/lib/pwn/aws/services_runtime_regression_spec.rb +51 -0
  233. data/spec/lib/pwn/aws_spec.rb +6 -0
  234. data/spec/lib/pwn/banner_operational_audit_spec.rb +105 -0
  235. data/spec/lib/pwn/bounty/lifecycle_authz_replay_spec.rb +17 -0
  236. data/spec/lib/pwn/config_redaction_regression_spec.rb +24 -0
  237. data/spec/lib/pwn/config_skills_regression_spec.rb +38 -0
  238. data/spec/lib/pwn/corpus_core_review_regression_spec.rb +96 -0
  239. data/spec/lib/pwn/corpus_spec.rb +13 -0
  240. data/spec/lib/pwn/cron_core_review_regression_spec.rb +95 -0
  241. data/spec/lib/pwn/cron_execution_spec.rb +75 -0
  242. data/spec/lib/pwn/driver_core_review_regression_spec.rb +38 -0
  243. data/spec/lib/pwn/driver_spec.rb +13 -0
  244. data/spec/lib/pwn/engagement_core_review_regression_spec.rb +88 -0
  245. data/spec/lib/pwn/engagement_storage_regression_spec.rb +44 -0
  246. data/spec/lib/pwn/ffi/capstone_spec.rb +19 -0
  247. data/spec/lib/pwn/ffi/fftw_spec.rb +19 -0
  248. data/spec/lib/pwn/ffi/keystone_spec.rb +13 -0
  249. data/spec/lib/pwn/ffi/soapy_sdr_spec.rb +13 -0
  250. data/spec/lib/pwn/json_text_spec.rb +25 -0
  251. data/spec/lib/pwn/memory_index_spec.rb +23 -0
  252. data/spec/lib/pwn/module_skills_parsing_regression_spec.rb +34 -0
  253. data/spec/lib/pwn/plugins/ai_sandbox_boundary_review_spec.rb +57 -0
  254. data/spec/lib/pwn/plugins/ai_sandbox_spec.rb +10 -18
  255. data/spec/lib/pwn/plugins/android_review_fixes_spec.rb +121 -0
  256. data/spec/lib/pwn/plugins/android_transport_audit_spec.rb +64 -0
  257. data/spec/lib/pwn/plugins/api_import_namespace_audit_spec.rb +49 -0
  258. data/spec/lib/pwn/plugins/artifact_registry_namespace_audit_spec.rb +20 -0
  259. data/spec/lib/pwn/plugins/artifact_registry_review_fixes_spec.rb +63 -0
  260. data/spec/lib/pwn/plugins/assembly_namespace_audit_spec.rb +16 -0
  261. data/spec/lib/pwn/plugins/assembly_review_fixes_spec.rb +33 -0
  262. data/spec/lib/pwn/plugins/authentication_helper_spec.rb +14 -0
  263. data/spec/lib/pwn/plugins/baresip_review_fixes_spec.rb +127 -0
  264. data/spec/lib/pwn/plugins/baresip_transport_audit_spec.rb +59 -0
  265. data/spec/lib/pwn/plugins/binary_analysis_process_review_spec.rb +57 -0
  266. data/spec/lib/pwn/plugins/black_duck_namespace_audit_spec.rb +25 -0
  267. data/spec/lib/pwn/plugins/burp_suite_har_review_fixes_spec.rb +60 -0
  268. data/spec/lib/pwn/plugins/burp_suite_import_review_fixes_spec.rb +62 -0
  269. data/spec/lib/pwn/plugins/burp_suite_namespace_audit_spec.rb +37 -0
  270. data/spec/lib/pwn/plugins/bus_pirate_transport_audit_spec.rb +19 -0
  271. data/spec/lib/pwn/plugins/file_fu_namespace_audit_spec.rb +17 -0
  272. data/spec/lib/pwn/plugins/findings_structured_spec.rb +1 -1
  273. data/spec/lib/pwn/plugins/gdbmi_namespace_audit_spec.rb +28 -0
  274. data/spec/lib/pwn/plugins/gdbmi_review_fixes_spec.rb +73 -0
  275. data/spec/lib/pwn/plugins/github_argv_review_spec.rb +49 -0
  276. data/spec/lib/pwn/plugins/google_workspace_provider_review_oauth_spec.rb +80 -0
  277. data/spec/lib/pwn/plugins/irc_review_fixes_spec.rb +92 -0
  278. data/spec/lib/pwn/plugins/irc_transport_audit_spec.rb +37 -0
  279. data/spec/lib/pwn/plugins/jenkins_namespace_audit_spec.rb +12 -0
  280. data/spec/lib/pwn/plugins/jira_data_center_namespace_audit_spec.rb +44 -0
  281. data/spec/lib/pwn/plugins/jira_data_center_review_fixes_spec.rb +81 -0
  282. data/spec/lib/pwn/plugins/jsonl_elf_review_fixes_spec.rb +59 -0
  283. data/spec/lib/pwn/plugins/log_spec.rb +36 -20
  284. data/spec/lib/pwn/plugins/monkey_patch_spec.rb +16 -0
  285. data/spec/lib/pwn/plugins/msr206_readback_review_fixes_spec.rb +119 -0
  286. data/spec/lib/pwn/plugins/msr206_review_fixes_spec.rb +50 -0
  287. data/spec/lib/pwn/plugins/msr206_transport_audit_spec.rb +64 -0
  288. data/spec/lib/pwn/plugins/nessus_cloud_namespace_audit_spec.rb +14 -0
  289. data/spec/lib/pwn/plugins/nexpose_review_fixes_spec.rb +55 -0
  290. data/spec/lib/pwn/plugins/open_api_namespace_audit_spec.rb +22 -0
  291. data/spec/lib/pwn/plugins/packet_transport_audit_spec.rb +47 -0
  292. data/spec/lib/pwn/plugins/plugins_b_operational_regression_spec.rb +600 -0
  293. data/spec/lib/pwn/plugins/pony_namespace_audit_spec.rb +17 -0
  294. data/spec/lib/pwn/plugins/pony_review_fixes_spec.rb +33 -0
  295. data/spec/lib/pwn/plugins/process_tube_namespace_audit_spec.rb +19 -0
  296. data/spec/lib/pwn/plugins/ps_namespace_audit_spec.rb +12 -0
  297. data/spec/lib/pwn/plugins/repl/ai_console_spec.rb +111 -0
  298. data/spec/lib/pwn/plugins/repl/ai_spec.rb +38 -0
  299. data/spec/lib/pwn/plugins/repl/mesh_spec.rb +52 -0
  300. data/spec/lib/pwn/plugins/sandbox_spec.rb +9 -7
  301. data/spec/lib/pwn/plugins/sbom_review_fixes_spec.rb +43 -0
  302. data/spec/lib/pwn/plugins/scannable_codes_namespace_audit_spec.rb +15 -0
  303. data/spec/lib/pwn/plugins/serial_review_fixes_spec.rb +76 -0
  304. data/spec/lib/pwn/plugins/serial_transport_audit_spec.rb +102 -0
  305. data/spec/lib/pwn/plugins/shodan_namespace_audit_spec.rb +10 -0
  306. data/spec/lib/pwn/plugins/sock_transport_audit_spec.rb +55 -0
  307. data/spec/lib/pwn/plugins/transparent_browser_navigation_review_spec.rb +21 -0
  308. data/spec/lib/pwn/plugins/vault_master_key_eui_regression_spec.rb +242 -0
  309. data/spec/lib/pwn/plugins/vault_spec.rb +58 -0
  310. data/spec/lib/pwn/plugins/vault_store_safety_spec.rb +1 -1
  311. data/spec/lib/pwn/plugins/xxd_namespace_audit_spec.rb +34 -0
  312. data/spec/lib/pwn/plugins/yubikey_hid_cleanup_review_fixes_spec.rb +52 -0
  313. data/spec/lib/pwn/plugins/yubikey_lifecycle_audit_spec.rb +65 -0
  314. data/spec/lib/pwn/plugins/yubikey_options_audit_spec.rb +30 -0
  315. data/spec/lib/pwn/plugins/yubikey_selector_audit_spec.rb +26 -0
  316. data/spec/lib/pwn/plugins/yubikey_spec.rb +1 -1
  317. data/spec/lib/pwn/plugins/zaproxy_namespace_audit_spec.rb +30 -0
  318. data/spec/lib/pwn/reports/empty_report_audit_spec.rb +18 -0
  319. data/spec/lib/pwn/reports/pdf_spec.rb +25 -0
  320. data/spec/lib/pwn/reports/provider_review_encoding_regression_spec.rb +45 -0
  321. data/spec/lib/pwn/sast/engine_runtime_regression_spec.rb +91 -0
  322. data/spec/lib/pwn/sast/filter_edge_regression_spec.rb +39 -0
  323. data/spec/lib/pwn/sast/formatter_review_fixes_spec.rb +178 -0
  324. data/spec/lib/pwn/sast/path_review_fixes_spec.rb +60 -0
  325. data/spec/lib/pwn/sast/pom_runtime_regression_spec.rb +37 -0
  326. data/spec/lib/pwn/sast/rules_runtime_regression_spec.rb +78 -0
  327. data/spec/lib/pwn/sast/sql_review_fixes_spec.rb +38 -0
  328. data/spec/lib/pwn/sdr/decoder/base_iq_spec.rb +21 -18
  329. data/spec/lib/pwn/sdr/decoder/base_review_fixes_spec.rb +49 -0
  330. data/spec/lib/pwn/sdr/decoder/base_validation_spec.rb +78 -0
  331. data/spec/lib/pwn/sdr/decoder/lora_spec.rb +9 -0
  332. data/spec/lib/pwn/sdr/flipper_zero_review_fixes_spec.rb +34 -0
  333. data/spec/lib/pwn/sdr/gqrx_operational_spec.rb +83 -0
  334. data/spec/lib/pwn/sdr/gqrx_review_fixes_spec.rb +22 -0
  335. data/spec/lib/pwn/sdr/son_micro_rfid_review_fixes_spec.rb +113 -0
  336. data/spec/lib/pwn/sdr/son_micro_rfid_serial_review_fixes_spec.rb +76 -0
  337. data/spec/lib/pwn/sdr/son_micro_rfid_spec.rb +39 -0
  338. data/spec/lib/pwn/sdr_spec.rb +5 -0
  339. data/spec/lib/pwn/session_cleanup_default_spec.rb +1 -1
  340. data/spec/lib/pwn/session_cleanup_lifecycle_supplement_spec.rb +39 -0
  341. data/spec/lib/pwn/session_cleanup_payload_spec.rb +3 -2
  342. data/spec/lib/pwn/session_trace_lifecycle_supplement_spec.rb +39 -0
  343. data/spec/lib/pwn/sessions_archive_closure_spec.rb +126 -0
  344. data/spec/lib/pwn/sessions_lifecycle_closure_spec.rb +373 -0
  345. data/spec/lib/pwn/sessions_lifecycle_supplement_spec.rb +204 -0
  346. data/spec/lib/pwn/setup_operational_regression_spec.rb +36 -0
  347. data/spec/lib/pwn/www/browser_review_fixes_spec.rb +70 -0
  348. data/spec/lib/pwn/www/browser_runtime_regression_spec.rb +100 -0
  349. data/spec/lib/pwn/www/hacker_one_runtime_regression_spec.rb +146 -0
  350. data/spec/lib/pwn/www/pagination_review_fixes_spec.rb +84 -0
  351. data/spec/support/namespace_controller_observability_fixture.rb +141 -0
  352. data/spec/support/sandbox.rb +8 -5
  353. data/third_party/pwn_rdoc.jsonl +73 -31
  354. metadata +137 -18
  355. data/etc/default_skills/pwn/aws/elastic_transcoder/SKILL.md +0 -48
  356. data/etc/default_skills/pwn/aws/lambda_preview/SKILL.md +0 -48
  357. data/etc/default_skills/pwn/aws/ops_works/SKILL.md +0 -48
  358. data/etc/default_skills/pwn/aws/ops_works_cm/SKILL.md +0 -48
  359. data/etc/default_skills/pwn/aws/sms/SKILL.md +0 -48
  360. data/lib/pwn/aws/elastic_transcoder.rb +0 -95
  361. data/lib/pwn/aws/lambda_preview.rb +0 -95
  362. data/lib/pwn/aws/ops_works.rb +0 -95
  363. data/lib/pwn/aws/ops_works_cm.rb +0 -95
  364. data/lib/pwn/aws/sms.rb +0 -95
  365. data/spec/lib/pwn/aws/elastic_transcoder_spec.rb +0 -15
  366. data/spec/lib/pwn/aws/lambda_preview_spec.rb +0 -15
  367. data/spec/lib/pwn/aws/ops_works_cm_spec.rb +0 -15
  368. data/spec/lib/pwn/aws/ops_works_spec.rb +0 -15
  369. data/spec/lib/pwn/aws/sms_spec.rb +0 -15
@@ -223,7 +223,7 @@ module PWN
223
223
  private_class_method def self.spawn_worker(opts = {})
224
224
  args = opts.fetch(:args)
225
225
  input = opts[:input]
226
- Dir.mktmpdir('pwn-policy-evaluator-', '/tmp') do |root|
226
+ Dir.mktmpdir('pwn-policy-evaluator-') do |root|
227
227
  Open3.popen3(
228
228
  { 'HOME' => root, 'TMPDIR' => root, 'LANG' => 'C.UTF-8' },
229
229
  RbConfig.ruby, RUNNER, *args,
@@ -261,7 +261,7 @@ module PWN
261
261
  private_class_method def self.with_isolated
262
262
  refuse_live_agent
263
263
  original = ENV.to_h
264
- Dir.mktmpdir('pwn-policy-heldout-', '/tmp') do |root|
264
+ Dir.mktmpdir('pwn-policy-heldout-') do |root|
265
265
  ENV.replace('HOME' => root, 'TMPDIR' => root, 'LANG' => 'C.UTF-8')
266
266
  PWN.const_set(:Env, { ai: { agent: { policy: false } } }) unless PWN.const_defined?(:Env)
267
267
  require_relative 'policy'
@@ -93,6 +93,7 @@ module PWN
93
93
  response = with_engine(engine: override, model: model) do
94
94
  engine_chat(
95
95
  engine: engine,
96
+ model: model,
96
97
  request: request.chomp,
97
98
  system_role_content: system_role_content,
98
99
  spinner: spinner,
@@ -393,7 +393,7 @@ module PWN
393
393
  before = TurnFinalizer.artifact_snapshot(paths: @contract[:required_artifacts])
394
394
  begin
395
395
  result = provider_attempt(&)
396
- failed = result.is_a?(Hash) && (result[:error] || result['error'] || result[:success] == false || result['success'] == false || result[:ok] == false || (result.key?(:exit) && result[:exit] != 0))
396
+ failed = result.is_a?(Hash) && (result[:error] || result['error'] || result[:success] == false || result['success'] == false || result[:ok] == false || result['ok'] == false || (result.key?(:exit) && result[:exit] != 0) || (result.key?('exit') && result['exit'] != 0))
397
397
  timed_out = result.is_a?(Hash) && (result[:error] || result['error']).to_s.match?(/timeout/i)
398
398
  # A returned timeout still may have applied. Only a finished
399
399
  # command (exit/stdout, no timeout) is an observation.
@@ -405,24 +405,34 @@ module PWN
405
405
  # trace: 'optional - Array of {name:, args:, result:} or Strings'
406
406
  # )
407
407
  #
408
- # Returns [{idx:, step:, reward: -1|0|1}, ...] and, when session_id
409
- # is given, rewrites each tool line in the transcript with a
410
- # `[step_reward=N]` prefix so exemplars_for / distill_skill can
411
- # keep only reward>0 steps (C4 minimal sufficient trace).
408
+ # Returns [{idx:, step:, reward: -1|0|1|nil}, ...]. Unknown evidence
409
+ # stays nil. With session_id, persist step_reward only on the captured
410
+ # action rows; retained evidence is copy-on-write under its writer protocol.
412
411
 
413
412
  public_class_method def self.prm(opts = {})
414
413
  request = opts[:request].to_s
415
414
  trace = Array(opts[:trace])
416
415
  sid = opts[:session_id]
417
- trace = load_trace(session_id: sid) if trace.empty? && sid
416
+ snapshot = opts[:snapshot] || Thread.current[:pwn_prm_snapshot]
417
+ snapshot = nil unless snapshot.is_a?(Hash) && snapshot[:session_id] == sid && snapshot[:request] == request
418
+ snapshot ||= prm_snapshot(session_id: sid, request: request) if sid
419
+ trace = snapshot[:trace] if trace.empty? && snapshot
420
+ # A caller-supplied trace may be scored, but cannot annotate unrelated rows.
421
+ snapshot = nil unless snapshot && trace == snapshot[:trace]
418
422
 
419
423
  rewards = llm_prm(request: request, trace: trace)
420
424
  rewards ||= heuristic_prm(trace: trace)
425
+ # A judge cannot recover execution status from incomplete display bytes.
426
+ trace.each_with_index do |step, index|
427
+ semantic = semantic_ok(name: 'shell', raw: step.to_s)[:semantic_ok]
428
+ rewards[index] = nil if semantic.nil?
429
+ rewards[index] = [rewards[index], 0].min if semantic == false && rewards[index]
430
+ end
421
431
 
422
432
  out = trace.each_with_index.map do |s, i|
423
- { idx: i + 1, step: s.to_s[0, 200], reward: rewards[i] || 0 }
433
+ { idx: i + 1, step: s.to_s[0, 200], reward: rewards[i] }
424
434
  end
425
- annotate_session(session_id: sid, rewards: rewards) if sid
435
+ annotate_session(session_id: sid, rewards: rewards, binding: snapshot[:binding]) if snapshot
426
436
  out
427
437
  rescue StandardError
428
438
  []
@@ -708,46 +718,51 @@ module PWN
708
718
  public_class_method def self.semantic_ok(opts = {})
709
719
  name = opts[:name].to_s
710
720
  raw = opts[:raw].to_s
711
- ok = raw.include?('"success":true')
712
- err = raw[/"error":"([^"]{1,300})"/, 1]
713
- exit_code = raw[/"exit":(\d+)/, 1]&.to_i
714
- stderr = raw[/"stderr":"([^"]{0,400})"/, 1].to_s
715
-
721
+ envelope = begin
722
+ JSON.parse(raw.sub(/\A\s*[a-z_][a-z0-9_]*\s*(?:→|->)\s*/i, ''), symbolize_names: true)
723
+ rescue JSON::ParserError
724
+ {}
725
+ end
726
+ envelope = {} unless envelope.is_a?(Hash)
727
+ return { ok: nil, semantic_ok: nil, exit: nil, err: nil, benign: false, shape: :unknown } unless [true, false].include?(envelope[:success]) || envelope[:error]
728
+
729
+ result = envelope[:result].is_a?(Hash) ? envelope[:result] : envelope
730
+ ok = envelope[:success] == true
731
+ err = envelope[:error] || result[:error]
732
+ exit_code = Integer(result[:exit], exception: false)
733
+ stderr = result[:stderr].to_s
734
+ status_text = [err, envelope[:code], result[:code]].compact.join(' ')
716
735
  benign = false
717
736
  shape = nil
718
- if name == 'shell' && ok && exit_code && exit_code != 0
737
+ if name == 'shell' && exit_code && exit_code != 0
719
738
  cmd = extract_cmd(args: opts[:args])
720
- # 2.1 — ONLY BENIGN_EXIT regex × allowed codes. The old global
721
- # `stderr.empty? && exit==1 ⇒ benign` laundered real failures
722
- # (pipelines without pipefail, bare false, etc.) into "success".
723
- # For pipelines, match the LAST stage (post-pipe) first, then any.
724
- stages = cmd.split('|').map(&:strip)
725
- last = stages.last.to_s
726
- benign = BENIGN_EXIT.any? { |rx, codes| last.match?(rx) && codes.include?(exit_code) }
727
- benign ||= stages.length > 1 && BENIGN_EXIT.any? { |rx, codes| stages.any? { |s| s.match?(rx) } && codes.include?(exit_code) && stderr.strip.empty? }
728
- shape = recoverable_shape(exit_code: exit_code, stderr: stderr, err: err)
739
+ # Only a completed informational command with an allowed exit is
740
+ # benign. An earlier grep cannot launder a failed final pipeline stage.
741
+ last = cmd.split('|').last.to_s.strip
742
+ benign = err.to_s.empty? && stderr.strip.empty? && result[:success] != false && result[:ok] != false &&
743
+ (envelope[:informational_exit] == true || BENIGN_EXIT.any? { |rx, codes| last.match?(rx) && codes.include?(exit_code) })
744
+ shape = recoverable_shape(exit_code: exit_code, stderr: stderr, err: err) unless benign
729
745
  elsif !ok
730
- shape = recoverable_shape(exit_code: exit_code, stderr: stderr, err: err || raw[0, 200])
746
+ shape = recoverable_shape(exit_code: exit_code, stderr: stderr, err: err)
731
747
  end
732
748
 
733
- if raw.include?('invalid_payload') || err.to_s.include?('invalid_payload')
749
+ if status_text.include?('invalid_payload')
734
750
  semantic = false
735
751
  shape = :invalid_payload
736
752
  err ||= 'invalid_payload'
737
- elsif timeout_result?(err: err, raw: raw)
753
+ elsif timeout_result?(err: err)
738
754
  semantic = false
739
755
  shape = :timeout
740
- err ||= raw[/timeout after \d+s/i] || 'timeout'
756
+ err ||= 'timeout'
741
757
  else
742
- semantic = ok && (exit_code.nil? || exit_code.zero? || benign)
758
+ semantic = (ok || benign) && result[:success] != false && result[:ok] != false && err.to_s.empty? && (exit_code.nil? || exit_code.zero? || benign)
743
759
  end
744
- err ||= raw[/"stderr":"([^"]{4,300})"/, 1] unless semantic
760
+ err ||= stderr[0, 300] unless semantic || stderr.empty?
745
761
  { ok: ok, semantic_ok: semantic, exit: exit_code, err: err, benign: benign, shape: shape }
746
762
  end
747
763
 
748
764
  private_class_method def self.timeout_result?(opts = {})
749
- blob = "#{opts[:err]} #{opts[:raw]}"
750
- blob.match?(/timeout after \d+s/i) || blob.match?(/"error"\s*:\s*"timeout/i)
765
+ opts[:err].to_s.match?(/\Atimeout|timeout after \d+s/i)
751
766
  end
752
767
 
753
768
  # 2.2 — coarse recoverable shape beside the fingerprint. Paths are
@@ -1579,8 +1594,9 @@ module PWN
1579
1594
  private_class_method def self.heuristic_prm(opts = {})
1580
1595
  opts[:trace].map do |t|
1581
1596
  s = semantic_ok(name: 'shell', raw: t.to_s)
1582
- if s[:semantic_ok] then 1
1597
+ if s[:semantic_ok].nil? then nil
1583
1598
  elsif s[:benign] then 0
1599
+ elsif s[:semantic_ok] then 1
1584
1600
  else -1
1585
1601
  end
1586
1602
  end
@@ -1655,46 +1671,118 @@ module PWN
1655
1671
  []
1656
1672
  end
1657
1673
 
1674
+ # Capture before any judge/provider/background work. Row indexes alone
1675
+ # are not identity: bind the exact prefix and each action's original bytes.
1676
+ public_class_method def self.prm_snapshot(opts = {})
1677
+ sid = opts[:session_id]
1678
+ request = opts[:request].to_s
1679
+ rows = PWN::Sessions.load(session_id: sid)
1680
+ user_at = rows.rindex { |row| row[:role].to_s == 'user' && row[:content].to_s == request }
1681
+ return nil unless user_at
1682
+
1683
+ stop = ((user_at + 1)...rows.length).find { |index| rows[index][:role].to_s == 'user' } || rows.length
1684
+ actions = (user_at...stop).filter_map do |index|
1685
+ next unless rows[index][:role].to_s == 'tool'
1686
+
1687
+ { row_index: index, sha256: prm_rows_digest(rows: [rows[index]]).freeze }.freeze
1688
+ end.freeze
1689
+ binding = {
1690
+ version: 1, session_id: sid.to_s.dup.freeze, turn_index: user_at,
1691
+ request_sha256: Digest::SHA256.hexdigest(request).freeze,
1692
+ prefix_length: stop, prefix_sha256: prm_rows_digest(rows: rows.first(stop)).freeze,
1693
+ actions: actions
1694
+ }.freeze
1695
+ { session_id: sid.to_s.dup.freeze, request: request.dup.freeze, binding: binding,
1696
+ trace: actions.map { |action| rows[action[:row_index]][:content].to_s.dup.freeze }.freeze }.freeze
1697
+ rescue StandardError
1698
+ nil
1699
+ end
1700
+
1701
+ # Also used by retained-evidence writers while holding their publication lock.
1702
+ public_class_method def self.prm_binding_valid?(opts = {})
1703
+ binding = opts[:binding]
1704
+ rows = opts[:transcript]
1705
+ return false unless binding.is_a?(Hash) && binding[:version] == 1 && binding[:session_id] == opts[:session_id] && rows.is_a?(Array)
1706
+
1707
+ length = binding[:prefix_length]
1708
+ index = binding[:turn_index]
1709
+ return false unless length.is_a?(Integer) && index.is_a?(Integer) && index >= 0 && length > index && rows.length >= length
1710
+ return false unless rows[index][:role].to_s == 'user' && Digest::SHA256.hexdigest(rows[index][:content].to_s) == binding[:request_sha256]
1711
+ return false unless prm_rows_digest(rows: rows.first(length)) == binding[:prefix_sha256]
1712
+
1713
+ expected = (index...length).select { |at| rows[at][:role].to_s == 'tool' }
1714
+ actions = binding[:actions]
1715
+ return false unless actions.is_a?(Array) && actions.map { |action| action[:row_index] } == expected
1716
+
1717
+ actions.all? { |action| prm_rows_digest(rows: [rows[action[:row_index]]]) == action[:sha256] }
1718
+ rescue StandardError
1719
+ false
1720
+ end
1721
+
1722
+ private_class_method def self.prm_rows_digest(opts = {})
1723
+ Digest::SHA256.hexdigest(JSON.generate(opts[:rows].map { |row| row.except(:step_reward) }))
1724
+ end
1725
+
1658
1726
  private_class_method def self.annotate_session(opts = {})
1659
1727
  sid = opts[:session_id]
1660
1728
  rewards = opts[:rewards]
1661
- return unless sid && defined?(PWN::Sessions)
1729
+ binding = opts[:binding]
1730
+ return unless sid && binding && defined?(PWN::Sessions)
1731
+ return unless rewards.is_a?(Array) && rewards.length == binding[:actions].length && rewards.all? { |reward| reward.nil? || [-1, 0, 1].include?(reward) }
1662
1732
 
1663
1733
  path = File.join(PWN::Sessions.sessions_dir, "#{sid}.jsonl")
1664
1734
  unless File.exist?(path)
1665
- result = Learning.annotate_evidence(session_id: sid, rewards: rewards)
1666
- if result[:annotated]
1667
- PWN::Sessions.load(session_id: sid).select { |row| row[:role].to_s == 'tool' }.each_with_index do |row, index|
1668
- fold_step_reward_to_metrics(content: row[:content], reward: rewards[index]) unless rewards[index].nil?
1669
- end
1735
+ # Older writers ignore unknown options; never invoke one with a bound
1736
+ # annotation, since it could publish credit onto a different turn.
1737
+ return { annotated: false, reason: :binding_unsupported } unless Learning.const_defined?(:EVIDENCE_ANNOTATION_VERSION, false) && Learning::EVIDENCE_ANNOTATION_VERSION >= 2
1738
+
1739
+ result = Learning.annotate_evidence(session_id: sid, rewards: rewards, binding: binding)
1740
+ if result[:annotated] && result[:binding_sha256] == Digest::SHA256.hexdigest(JSON.generate(binding))
1741
+ rows = PWN::Sessions.load(session_id: sid)
1742
+ fold_bound_rewards(binding: binding, transcript: rows, rewards: rewards, session_id: sid)
1670
1743
  end
1671
1744
  return result
1672
1745
  end
1673
1746
 
1674
1747
  lease = PWN::Sessions.activate(session_id: sid)
1675
- lines = File.readlines(path)
1676
- ti = -1
1677
- lines.map! do |l|
1678
- j = JSON.parse(l, symbolize_names: true)
1679
- if j[:role].to_s == 'tool'
1680
- ti += 1
1681
- if rewards[ti]
1682
- j[:step_reward] = rewards[ti]
1683
- # P18 — fold step_reward into Metrics so Registry.rank can bias
1684
- fold_step_reward_to_metrics(content: j[:content], reward: rewards[ti])
1748
+ File.open("#{path}.write.lock", File::RDWR | File::CREAT | File::NOFOLLOW, 0o600) do |writer|
1749
+ writer.flock(File::LOCK_EX)
1750
+ File.open(path, File::RDWR | File::NOFOLLOW) do |file|
1751
+ lines = file.readlines
1752
+ rows = lines.map { |line| JSON.parse(line, symbolize_names: true) }
1753
+ return { annotated: false, reason: :stale_binding } unless prm_binding_valid?(binding: binding, transcript: rows, session_id: sid)
1754
+
1755
+ binding[:actions].each_with_index do |action, index|
1756
+ next if rewards[index].nil?
1757
+
1758
+ at = action[:row_index]
1759
+ rows[at][:step_reward] = rewards[index]
1760
+ lines[at] = "#{JSON.generate(rows[at])}\n"
1685
1761
  end
1762
+ file.rewind
1763
+ file.write(lines.join)
1764
+ file.truncate(file.pos)
1765
+ file.flush
1766
+ file.fsync
1767
+ fold_bound_rewards(binding: binding, transcript: rows, rewards: rewards, session_id: sid)
1686
1768
  end
1687
- "#{JSON.generate(j)}\n"
1688
- rescue StandardError
1689
- l
1690
1769
  end
1691
- File.write(path, lines.join)
1770
+ { annotated: true }
1692
1771
  rescue StandardError
1693
1772
  nil
1694
1773
  ensure
1695
1774
  PWN::Sessions.deactivate(lease: lease)
1696
1775
  end
1697
1776
 
1777
+ private_class_method def self.fold_bound_rewards(opts = {})
1778
+ return unless prm_binding_valid?(opts)
1779
+
1780
+ opts[:binding][:actions].each_with_index do |action, index|
1781
+ reward = opts[:rewards][index]
1782
+ fold_step_reward_to_metrics(content: opts[:transcript][action[:row_index]][:content], reward: reward) unless reward.nil?
1783
+ end
1784
+ end
1785
+
1698
1786
  # Extract tool name from "name → …" session content and record PRM.
1699
1787
  private_class_method def self.fold_step_reward_to_metrics(opts = {})
1700
1788
  return unless defined?(Metrics) && Metrics.respond_to?(:record_step_reward)
@@ -1899,7 +1987,7 @@ module PWN
1899
1987
  a = opts[:args]
1900
1988
  h = a.is_a?(String) ? JSON.parse(a, symbolize_names: true) : a
1901
1989
  # Leading env-vars / sudo / pipes: match any segment.
1902
- h.is_a?(Hash) ? h[:command].to_s.strip : a.to_s
1990
+ h.is_a?(Hash) ? (h[:command] || h['command']).to_s.strip : a.to_s
1903
1991
  rescue StandardError
1904
1992
  opts[:args].to_s
1905
1993
  end
@@ -2033,7 +2121,21 @@ module PWN
2033
2121
  #{self}.prm(
2034
2122
  request: 'required - user goal',
2035
2123
  session_id: 'optional - session to score in place',
2036
- trace: 'optional - Array of {name:, args:, result:} or Strings'
2124
+ trace: 'optional - Array of {name:, args:, result:} or Strings',
2125
+ snapshot: 'optional - immutable host snapshot from prm_snapshot, captured before background work'
2126
+ )
2127
+
2128
+ # Capture original request and exact action identities before scoring.
2129
+ #{self}.prm_snapshot(
2130
+ session_id: 'required - session with the original user turn',
2131
+ request: 'required - original user request'
2132
+ )
2133
+
2134
+ # Validate a captured binding under the transcript writer lock.
2135
+ #{self}.prm_binding_valid?(
2136
+ binding: 'required - binding from prm_snapshot',
2137
+ transcript: 'required - current parsed transcript rows',
2138
+ session_id: 'required - exact captured session identity'
2037
2139
  )
2038
2140
 
2039
2141
  # Plan-quality soft signal (W3 feature / Learning tag)
@@ -21,8 +21,6 @@ module PWN
21
21
  request: request,
22
22
  suppress_pii_warning: true
23
23
  )
24
- rescue StandardError => e
25
- raise e.backtrace
26
24
  end
27
25
 
28
26
  # Author(s):: 0day Inc. <support@0dayinc.com>
@@ -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
- state[:events] << { name: name.to_s, preview: preview, ok: ok, t: Time.now }
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 unless name.to_s.match?(/^(memory|session|skills)_recall$/)
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
- chunk = "#{name} #{preview} #{rs.to_s[0, 800]}"
1694
- state[:evidence_blob] = "#{state[:evidence_blob]} #{chunk}"
1695
- state[:evidence_blob] = state[:evidence_blob][-16_000..] if state[:evidence_blob].to_s.length > 20_000
1696
- te = (state[:task_evidence] ||= {})
1697
- idx = state[:plan_idx].to_i
1698
- te[idx] = "#{te[idx]} #{chunk}"
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
- else
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
- { stdout: buf.string, value: val.inspect, timeout: timeout }
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.file?(path) ? File.read(path) : ''
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
- { passed: results.all? { |r| r[:passed] }, results: results }
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
  )
@@ -25,8 +25,6 @@ module PWN
25
25
  request: request,
26
26
  suppress_pii_warning: true
27
27
  )
28
- rescue StandardError => e
29
- raise e.backtrace
30
28
  end
31
29
 
32
30
  # Author(s):: 0day Inc. <support@0dayinc.com>
@@ -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(
@@ -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: false,
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: false,
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: false,
430
+ verify_ssl: true,
431
431
  timeout: timeout
432
432
  )
433
433
  end
@@ -21,7 +21,8 @@ module PWN
21
21
 
22
22
  range = opts[:range]
23
23
  data = if range.is_a?(Range)
24
- File.binread(path, range.end - range.begin, range.begin).to_s
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: false,
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: false,
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
- if p[:functionCall]
280
- tool_name_by_id[p.dig(:functionCall, :_id).to_s] = p.dig(:functionCall, :name)
281
- { functionCall: p[:functionCall].except(:_id) }
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