pwn 0.5.639 → 0.5.643

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 (38) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -3
  3. data/README.md +1 -1
  4. data/documentation/Cron.md +10 -8
  5. data/documentation/Reinforcement-Learning.md +43 -21
  6. data/documentation/diagrams/cron-scheduling.svg +134 -93
  7. data/documentation/diagrams/dot/cron-scheduling.dot +9 -3
  8. data/documentation/diagrams/dot/pwn-ai-feedback-learning-loop.dot +2 -2
  9. data/documentation/diagrams/dot/reinforcement-learning.dot +9 -3
  10. data/documentation/diagrams/pwn-ai-feedback-learning-loop.svg +103 -101
  11. data/documentation/diagrams/reinforcement-learning.svg +211 -166
  12. data/documentation/pwn-ai-Agent.md +12 -0
  13. data/lib/pwn/ai/agent/curriculum.rb +647 -56
  14. data/lib/pwn/ai/agent/learning.rb +87 -15
  15. data/lib/pwn/ai/agent/loop.rb +164 -13
  16. data/lib/pwn/ai/agent/metrics.rb +32 -13
  17. data/lib/pwn/ai/agent/mistakes.rb +139 -8
  18. data/lib/pwn/ai/agent/prompt_builder.rb +2 -2
  19. data/lib/pwn/ai/agent/registry.rb +13 -3
  20. data/lib/pwn/ai/agent/result.rb +19 -2
  21. data/lib/pwn/ai/agent/reward.rb +415 -42
  22. data/lib/pwn/ai/agent/tools/curriculum.rb +51 -0
  23. data/lib/pwn/ai/agent/tools/reward.rb +15 -4
  24. data/lib/pwn/ai/anthropic.rb +265 -4
  25. data/lib/pwn/ai/ollama.rb +274 -10
  26. data/lib/pwn/ai/open_ai.rb +307 -4
  27. data/lib/pwn/config.rb +137 -12
  28. data/lib/pwn/cron.rb +24 -2
  29. data/lib/pwn/memory.rb +13 -1
  30. data/lib/pwn/version.rb +1 -1
  31. data/spec/integration/persistence_roundtrip_spec.rb +6 -1
  32. data/spec/integration/reinforced_feedback_loop_spec.rb +144 -8
  33. data/spec/lib/pwn/ai/agent/mistakes_spec.rb +27 -0
  34. data/spec/lib/pwn/ai/agent/result_spec.rb +11 -0
  35. data/spec/lib/pwn/ai/agent/reward_spec.rb +89 -0
  36. data/spec/lib/pwn/ai/ollama_spec.rb +251 -0
  37. data/third_party/pwn_rdoc.jsonl +58 -7
  38. metadata +8 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 729dee0799d356e7a109e5ed3e5ac6cf07d322e9c136e3fc55477581e6457953
4
- data.tar.gz: 398f30816941076c3ca6320526aa630875ebdae12a6274f3c0419e37db55f271
3
+ metadata.gz: 065c569478e763c0cc10c1dbb19f017dc06dcca1baa66c448be8f35b0572cf8e
4
+ data.tar.gz: 35974c5ba9ca144cc4f033a96d77b432ef8d81958ba5abb556324314af00c539
5
5
  SHA512:
6
- metadata.gz: 390144f0551778087a3621784b56cadbedffcad2635811ef6141425a6879b555363254b1ed3e6047e6df7256f81d3e781681b9cfa10f3e8274ed3876b2058329
7
- data.tar.gz: 4b653649d86a5669480dad3051b38f055955680f1882e746bacfc1624a6128bf47d5990c7fe9904c9f3d6879a473a86bf58f845deb360992962571a968579645
6
+ metadata.gz: 66cb4b9f2c195607cb300c03885d961be5c918048c4f511f55af609014a6245edb50111776fd357d35c26ca258baabc5dc061e9c229b7d16956d05a11ff6b585
7
+ data.tar.gz: 9a1e152a5a23441c22476bb5410db47efcdf3caee3f1029568538a15798a69905da6e0c77fd24969c08bfcadecbd009b2f6d424a720d3e98b0f2a123697cdd62
data/Gemfile CHANGED
@@ -20,7 +20,7 @@ gem 'base32', '0.3.4'
20
20
  gem 'bitcoin-ruby', '0.0.20'
21
21
  gem 'brakeman', '8.0.5'
22
22
  gem 'bson', '5.2.0'
23
- gem 'bundler', '>=4.0.16'
23
+ gem 'bundler', '>=4.0.17'
24
24
  gem 'bundler-audit', '>=0.9.3'
25
25
  gem 'bunny', '3.1.0'
26
26
  gem 'colorize', '1.1.0'
@@ -49,10 +49,10 @@ gem 'jwt', '3.2.0'
49
49
  gem 'libusb', '0.7.2'
50
50
  gem 'luhn', '3.0.0'
51
51
  gem 'mail', '2.9.1'
52
- gem 'mcp', '0.24.0'
52
+ gem 'mcp', '1.0.0'
53
53
  gem 'meshtastic', '0.0.172'
54
54
  gem 'metasm', '1.0.6'
55
- gem 'mongo', '2.24.1'
55
+ gem 'mongo', '2.25.0'
56
56
  gem 'msfrpc-client', '1.1.2'
57
57
  gem 'netaddr', '2.0.6'
58
58
  gem 'net-ldap', '0.20.0'
data/README.md CHANGED
@@ -128,7 +128,7 @@ $ pwn setup --profile net --dry-run
128
128
  Also available as `pwn_setup` (standalone driver) and `pwn --setup[=PROFILE]`.
129
129
  The doctor exits non-zero when capabilities are degraded, so CI can gate on it.
130
130
 
131
- [![Installing the pwn Security Automation Framework](https://raw.githubusercontent.com/0dayInc/pwn/master/documentation/pwn_install.png)](https://youtu.be/G7iLUY4FzsI)
131
+ <!--[![Installing the pwn Security Automation Framework](https://raw.githubusercontent.com/0dayInc/pwn/master/documentation/pwn_install.png)](https://youtu.be/G7iLUY4FzsI)-->
132
132
 
133
133
  Full page: [Installation](documentation/Installation.md) ·
134
134
  [Configuration](documentation/Configuration.md)
@@ -26,20 +26,22 @@ invokes `PWN::Cron.run(<id>)` on schedule.
26
26
 
27
27
  ## Seeded self-improvement jobs (`PWN::Cron.install_defaults`)
28
28
 
29
- `pwn setup --migrate` (schema `v1`) seeds two jobs into every fresh
30
- `~/.pwn/cron/jobs.yml`:
29
+ `pwn setup --migrate` (schema `v1`) seeds four jobs into every fresh
30
+ `~/.pwn/cron/jobs.yml` via `PWN::Cron.install_defaults`:
31
31
 
32
32
  | Name | Schedule | Ruby |
33
33
  |---|---|---|
34
34
  | `curriculum_practice_nightly` | `0 3 * * *` | `PWN::AI::Agent::Curriculum.practice(limit: 3)` |
35
+ | `curriculum_offline_judge` | `30 3 * * *` | `PWN::AI::Agent::Curriculum.offline_judge(since_hours: 24, limit: 40)` |
35
36
  | `curriculum_train_weekly` | `0 4 * * 0` | `PWN::AI::Agent::Curriculum.train_and_gate(dry_run: true)` |
37
+ | `learning_consolidate_nightly` | `0 5 * * *` | `PWN::AI::Agent::Learning.consolidate` |
36
38
 
37
- The first practises the top unresolved `Mistakes` under `Reward.judge` and
38
- auto-`resolve`s any it now solves; the second exports SFT + DPO datasets to
39
- `~/.pwn/finetune/`, LoRA-trains a `pwn-vN+1` local model, replays the
40
- `Mistakes.top` set on both, and only promotes the new adapter when it wins.
41
- Set `dry_run: false` (via `pwn-ai-cron` or `cron_create`) once a local
42
- trainer is installed. See [Reinforcement Learning](Reinforcement-Learning.md).
39
+ - **practice** top unresolved `Mistakes` under `Reward.judge`; auto-`resolve` with ≥2 holdouts
40
+ - **offline_judge** P3 backfill of ORM/PRM labels + W3 calibration from PLAN `p(success)=` so `:failure_only` local introspect does not starve the corpus
41
+ - **train** — export SFT + balanced DPO, LoRA-train `pwn-vN+1`, replay Mistakes.top, promote only on win. `dry_run: false` only with a trainer+GPU
42
+ - **consolidate** M1/M3 memory GC so the injected MEMORY block stays high-signal
43
+
44
+ See [Reinforcement Learning](Reinforcement-Learning.md).
43
45
 
44
46
  `cron_disable(id:)` turns either off; `install_defaults` is idempotent and
45
47
  never overwrites a job you already have with the same name.
@@ -1,10 +1,12 @@
1
1
  # Reinforcement Learning in pwn-ai
2
2
 
3
- pwn-ai implements a **six-tier** in-context → weight-level RL loop that
4
- surpasses every published LLM-agent harness (Reflexion, Voyager, ExpeL,
5
- LATS, Generative Agents, PRM, RLAIF, DPO, Self-Refine, Toolformer, DSPy)
6
- on at least one axis, and on **five axes simultaneously** for the full
7
- `Curriculum.practice → Reward.export_dpo → Curriculum.train_and_gate` path.
3
+ pwn-ai implements a **six-tier** in-context → weight-export RL loop that
4
+ combines ORM/PRM, preference ledger, mistake curriculum, env-drift blame,
5
+ balanced DPO export, and regression-gated LoRA promotion. On hosts **with a
6
+ trainer + GPU**, the full
7
+ `Curriculum.practice → Reward.export_dpo → Curriculum.train_and_gate`
8
+ path closes the weight loop; without a trainer the path is **export-ready**
9
+ (datasets + manual CLI) and the live learning is in-context only.
8
10
 
9
11
  ![Reinforcement-learning loop](diagrams/reinforcement-learning.svg)
10
12
 
@@ -50,7 +52,7 @@ on at least one axis, and on **five axes simultaneously** for the full
50
52
  |----|-------|------|
51
53
  | **C1** | `Registry.rank` + `Metrics.{ucb,thompson,advantage}` | score = α·keyword_sim + β·advantage + γ·UCB1. Untried tools get exploration bonus. |
52
54
  | **C2** | `Learning.exemplars_for` | priority = judge_score × e^(−Δt/30d) × keyword_sim. |
53
- | **C3** | `Curriculum.hindsight` | HER — relabel failed trajectory with achieved-goal as `success:true`. |
55
+ | **C3** | `Curriculum.hindsight` | HER — relabel failed trajectory with achieved-goal as `success: 'soft'` + tags `hindsight/her/soft`. Soft rows are excluded from SFT and 0.35×-weighted in C2 exemplars. |
54
56
  | **C4** | `Learning.{compress_exemplar,build_skill_from_session}` | keep only `step_reward > 0` — minimal sufficient trace. |
55
57
 
56
58
  ## Tier 3 — Memory that stays high-signal
@@ -75,8 +77,8 @@ on at least one axis, and on **five axes simultaneously** for the full
75
77
 
76
78
  | ID | Where | What |
77
79
  |----|-------|------|
78
- | **W1** | `Reward.{record_preference,export_dpo}` | 5 free preference sources: user_correction, mistakes_resolve, counterfactual, curriculum, critic. |
79
- | **W2** | `Curriculum.train_and_gate` | SFT+DPO → unsloth/axolotl LoRA → `ollama create pwn-vN+1` → replay `Mistakes.top` on vN vs vN+1 → promote iff `resolved(N+1) > resolved(N)`. |
80
+ | **W1** | `Reward.{record_preference,export_dpo}` | 5 free preference sources: user_correction, mistakes_resolve, counterfactual, curriculum, critic. `export_dpo` enforces ≤40% per-source (`DPO_SOURCE_CAP`); pass `balance: false` for a raw dump. |
81
+ | **W2** | `Curriculum.train_and_gate` | SFT+DPO → unsloth/axolotl LoRA → `ollama create pwn-vN+1` → replay `Mistakes.top` on vN vs vN+1 → promote iff `resolved(N+1) > resolved(N)`. **Without a trainer: export-only** (`weight_loop: :export_ready`). |
80
82
  | **W3** | `Curriculum.calibrate` + `Metrics.{record_calibration,calibration}` | plan_first `p(success)` vs actual → per-engine Brier/overconfidence. |
81
83
 
82
84
  ## Tier 6 — Deepen the intro↔extro join
@@ -91,32 +93,37 @@ on at least one axis, and on **five axes simultaneously** for the full
91
93
 
92
94
  ```yaml
93
95
  :ai:
96
+ :module_reflection: false # gates Reflect lesson writing (not ORM alone)
94
97
  :agent:
95
- :critic: true # S3
96
- :red_team_plan: true # S4
97
- :counterfactual: true # S2
98
- :hindsight: true # C3 (default true)
99
- :verify_as_reward: true # E3
98
+ :critic: null # S3 — nil = ON for remote engines, OFF for ollama
99
+ :red_team_plan: null # S4 — same auto policy
100
+ :counterfactual: null # S2 — same auto policy
101
+ :hindsight: true # C3 (default true; soft-success, 0.35× in C2)
102
+ :verify_as_reward: null # E3 — nil = auto (~10% local / always remote on CLAIM_RX)
103
+ :reward_llm: null # nil = ORM/PRM use LLM teacher on remote even if module_reflection is false
104
+ :local_introspect: :failure_only # ollama cost policy; remote always introspects
105
+ :introspect_every_n: 3
100
106
  ```
101
107
 
102
108
  ## Cron self-improvement
103
109
 
104
110
  ```ruby
105
- PWN::Cron.create(name: 'self_play', schedule: '0 3 * * *',
106
- ruby: 'PWN::AI::Agent::Curriculum.practice(limit: 5)')
107
- PWN::Cron.create(name: 'weight_loop', schedule: '0 4 * * 0',
108
- ruby: 'PWN::AI::Agent::Curriculum.train_and_gate(dry_run: false)')
109
- PWN::Cron.create(name: 'mem_gc', schedule: '0 5 * * *',
110
- ruby: 'PWN::AI::Agent::Learning.consolidate')
111
+ # Seeded idempotently by PWN::Cron.install_defaults (pwn setup --migrate):
112
+ PWN::Cron.install_defaults
113
+ # curriculum_practice_nightly 0 3 * * * Curriculum.practice(limit: 3)
114
+ # → curriculum_offline_judge 30 3 * * * Curriculum.offline_judge(since_hours: 24, limit: 40)
115
+ # → curriculum_train_weekly 0 4 * * 0 Curriculum.train_and_gate(dry_run: true) # false only with trainer+GPU
116
+ # → learning_consolidate_nightly 0 5 * * * Learning.consolidate
111
117
  ```
112
118
 
113
119
  ## Tools exposed to the model
114
120
 
115
121
  `reward_judge` · `reward_prm` · `reward_sentinel` · `reward_preferences` ·
116
122
  `reward_export_dpo` · `curriculum_practice` · `curriculum_train` ·
117
- `curriculum_hindsight` · `learning_purge_noise`
123
+ `curriculum_hindsight` · `curriculum_offline_judge` ·
124
+ `curriculum_preference_balance` · `learning_purge_noise`
118
125
 
119
- ## What no other harness does simultaneously
126
+ ## Design claims (architecture weight promotion requires a trainer)
120
127
 
121
128
  1. **Process reward on real security tool traces** (R2)
122
129
  2. **Automatic blame attribution** self vs env-drift via CUSUM×correlate (E1+E2)
@@ -124,6 +131,21 @@ PWN::Cron.create(name: 'mem_gc', schedule: '0 5 * * *',
124
131
  4. **Mistake-driven curriculum with regression-gated LoRA promotion** (S1+W2)
125
132
  5. **Five naturally-generated DPO sources** with zero human labelling (W1)
126
133
 
134
+
135
+ ## Operational controls (priority fixes)
136
+
137
+ | ID | Control | What |
138
+ |----|---------|------|
139
+ | **P1** | `Curriculum.practice` cooldown + natural prompts | Hard-skips `reward_signal` / parked / `needs_code_change`; N-night zero-score cooldown parks thrash; reproducers are natural user tasks, never signature dumps. |
140
+ | **P2** | R4 `semantic_ok` + structured resolve | `31f1871b8a15`-class exit≠0 phantoms stay closed via structured holdouts. |
141
+ | **P3** | `Curriculum.offline_judge` | Scores last-24h sessions under ORM/PRM so local `:failure_only` introspect does not starve labels. Cron nightly. |
142
+ | **P4** | `Reward.proxy_distrust` | When sentinel fires, Metrics.to_context / Registry.rank haircut proxy rates — actionable, not just another Mistakes row. |
143
+ | **R3** | `Reward.sentinel` ring buffer | Fixed-N (`SENTINEL_WINDOW=40`) `{judge,proxy}` window replaces decaying `proxy_sum`/`proxy_n`. Means are always ∈[0,1]; `set_proxy_distrust` refuses proxy∉[0,1]; `reset_sentinel` wipes corrupt state without touching prefs. Legacy decay×`to_i` files auto-clear stuck distrust on load. |
144
+ | **P5** | `Curriculum.preference_balance` + `export_dpo` source-cap | Surfaces W1 monoculture **and enforces** ≤40% per source at export (`DPO_SOURCE_CAP`); critic/counterfactual auto-ON for remote engines so the diet rebalances online. |
145
+ | **P6** | W2 honesty | Docs + `train_and_gate` return `weight_loop: :export_ready` when `trainer: null`. |
146
+ | **P7** | W3 as controller | Engine Brier > 0.35 or overconfidence > 0.25 (n≥8) → force plan_first + critic, cap max_iters at 12. `offline_judge` also records calibration from PLAN `p(success)=` so the controller can fire under `:failure_only`. |
147
+ | **P8** | Remote reward teacher | `agent.reward_llm` nil → ORM/PRM use the LLM teacher on remote engines even when `module_reflection` is false. Local ollama stays heuristic unless explicitly enabled. PRM prompts carry R4 tags so benign recon exits score 0 not −1. |
148
+
127
149
  **See also:** [Skills, Memory & Learning](Skills-Memory-Learning.md) ·
128
150
  [Mistakes](Mistakes.md) · [Cron](Cron.md) · [pwn-ai Agent](pwn-ai-Agent.md)
129
151