pwn 0.5.669 → 0.5.673

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 (69) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/Gemfile +1 -1
  4. data/README.md +13 -9
  5. data/documentation/AI-Integration.md +1 -1
  6. data/documentation/Agent-Tool-Registry.md +17 -5
  7. data/documentation/Configuration.md +19 -8
  8. data/documentation/Diagrams.md +2 -2
  9. data/documentation/Home.md +2 -2
  10. data/documentation/How-PWN-Works.md +12 -10
  11. data/documentation/Installation.md +3 -1
  12. data/documentation/Mistakes.md +3 -0
  13. data/documentation/Persistence.md +4 -1
  14. data/documentation/Reinforcement-Learning.md +90 -73
  15. data/documentation/Skills-Memory-Learning.md +28 -4
  16. data/documentation/What-is-PWN.md +8 -7
  17. data/documentation/Why-PWN.md +3 -2
  18. data/documentation/diagrams/agent-tool-registry.svg +188 -160
  19. data/documentation/diagrams/dot/agent-tool-registry.dot +7 -4
  20. data/documentation/diagrams/dot/memory-skills-detailed.dot +12 -5
  21. data/documentation/diagrams/dot/overall-pwn-architecture.dot +4 -3
  22. data/documentation/diagrams/dot/persistence-filesystem.dot +2 -1
  23. data/documentation/diagrams/dot/pwn-ai-feedback-learning-loop.dot +11 -4
  24. data/documentation/diagrams/dot/reinforcement-learning.dot +8 -3
  25. data/documentation/diagrams/dot/task-summarizer.dot +24 -12
  26. data/documentation/diagrams/memory-skills-detailed.svg +252 -210
  27. data/documentation/diagrams/overall-pwn-architecture.svg +21 -12
  28. data/documentation/diagrams/persistence-filesystem.svg +127 -113
  29. data/documentation/diagrams/pwn-ai-feedback-learning-loop.svg +449 -397
  30. data/documentation/diagrams/reinforcement-learning.svg +276 -239
  31. data/documentation/diagrams/task-summarizer.svg +178 -126
  32. data/documentation/pwn-ai-Agent.md +66 -32
  33. data/lib/pwn/ai/agent/curriculum.rb +13 -4
  34. data/lib/pwn/ai/agent/dispatch.rb +3 -0
  35. data/lib/pwn/ai/agent/learning.rb +100 -14
  36. data/lib/pwn/ai/agent/loop.rb +692 -25
  37. data/lib/pwn/ai/agent/metrics.rb +52 -4
  38. data/lib/pwn/ai/agent/mistakes.rb +158 -1
  39. data/lib/pwn/ai/agent/policy.rb +935 -0
  40. data/lib/pwn/ai/agent/prompt_builder.rb +82 -6
  41. data/lib/pwn/ai/agent/reflect.rb +11 -3
  42. data/lib/pwn/ai/agent/registry.rb +18 -3
  43. data/lib/pwn/ai/agent/reward.rb +360 -48
  44. data/lib/pwn/ai/agent/task_summarizer.rb +415 -33
  45. data/lib/pwn/ai/agent/tool_guard.rb +157 -0
  46. data/lib/pwn/ai/agent/tools/policy.rb +76 -0
  47. data/lib/pwn/ai/agent/tools/ruby_eval.rb +27 -1
  48. data/lib/pwn/ai/agent/tools/shell.rb +28 -32
  49. data/lib/pwn/ai/agent.rb +2 -0
  50. data/lib/pwn/config.rb +14 -2
  51. data/lib/pwn/memory.rb +188 -0
  52. data/lib/pwn/sessions.rb +9 -4
  53. data/lib/pwn/version.rb +1 -1
  54. data/spec/integration/reinforced_feedback_loop_spec.rb +35 -9
  55. data/spec/lib/pwn/ai/agent/learning_spec.rb +119 -3
  56. data/spec/lib/pwn/ai/agent/loop_spec.rb +215 -3
  57. data/spec/lib/pwn/ai/agent/metrics_spec.rb +10 -0
  58. data/spec/lib/pwn/ai/agent/mistakes_spec.rb +33 -0
  59. data/spec/lib/pwn/ai/agent/policy_spec.rb +165 -0
  60. data/spec/lib/pwn/ai/agent/prompt_builder_spec.rb +51 -0
  61. data/spec/lib/pwn/ai/agent/reward_spec.rb +75 -0
  62. data/spec/lib/pwn/ai/agent/signal_hygiene_spec.rb +118 -0
  63. data/spec/lib/pwn/ai/agent/task_summarizer_spec.rb +111 -6
  64. data/spec/lib/pwn/ai/agent/tool_guard_spec.rb +61 -0
  65. data/spec/lib/pwn/ai/agent/tools/policy_spec.rb +18 -0
  66. data/spec/lib/pwn/memory_spec.rb +62 -0
  67. data/spec/support/sandbox.rb +2 -0
  68. data/third_party/pwn_rdoc.jsonl +108 -4
  69. metadata +10 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 746a770eb9c9d4d410cd3fff4deb631ac67476a8d4f01ba7cf17c8414d4930d9
4
- data.tar.gz: 0aa9628ff2b8f80ed5b06fe682d8c252d4609c3545c96b68dd3890897de3d402
3
+ metadata.gz: 9640ee1c83ff54dc1e10246d519a448d648806e30b35b579284b23708b5b9924
4
+ data.tar.gz: 2cbd3b2296d32ad6d068d276c3badbfa599065c668bbec7ac58fa2baf84651d7
5
5
  SHA512:
6
- metadata.gz: adee5114bbd4a83820b12f591d334aeec378f5bf47d7b51d10e3ee9d14497e08207ee532eb2eab7881cb8bb2a1f8910ef6a83712b8b3cb1f7ed7d25cc14f0312
7
- data.tar.gz: 5343e693c473baf4112b47b1c8a932a22b6ec46ddf1998c34e828aa79483d7c350bce500ed502f015944960b8e8ec867028f4261f11ddd57360853286778a829
6
+ metadata.gz: fa11ac68afcc6cde52bc207526a50cf53283ac59dd89340f25f303329562e7d34c7a02cbd286ca6fe34fffcaa307a9b0e3f9c03c03c89dca3788f9150f702f0a
7
+ data.tar.gz: c9bd66494f36503ba864a7c97af7d7a77b2d9502a502ed04c897ce08e2e693982efe79a43abc4c12d95e1d4b4b97ea3a1ec6fba61b0711599e025bcc2b19618d
data/.rubocop.yml CHANGED
@@ -9,7 +9,7 @@ Lint/UselessRescue:
9
9
  Metrics/AbcSize:
10
10
  Max: 720
11
11
  Metrics/BlockLength:
12
- Max: 292
12
+ Max: 320
13
13
  Metrics/BlockNesting:
14
14
  Max: 6
15
15
  Metrics/ClassLength:
data/Gemfile CHANGED
@@ -18,7 +18,7 @@ gem 'aws-sdk', '3.3.0'
18
18
  gem 'barby', '0.7.0'
19
19
  gem 'base32', '0.3.4'
20
20
  gem 'bitcoin-ruby', '0.0.20'
21
- gem 'brakeman', '8.0.5'
21
+ gem 'brakeman', '8.0.6'
22
22
  gem 'bson', '5.2.0'
23
23
  gem 'bundler', '>=4.0.18'
24
24
  gem 'bundler-audit', '>=0.9.3'
data/README.md CHANGED
@@ -35,7 +35,7 @@ and automate instead of gluing together a pile of separate CLIs.
35
35
 
36
36
  **In numbers:** 66 `PWN::Plugins` · 48 `PWN::SAST` rules · 90 `PWN::AWS`
37
37
  service wrappers · 21 `PWN::WWW` site drivers · 53 `bin/pwn_*` CLI drivers ·
38
- 6 LLM engines · 12 agent toolsets · 82 LLM-callable tools.
38
+ 6 LLM engines · 13 agent toolsets · 85 LLM-callable tools.
39
39
 
40
40
  Full page: [What is PWN](documentation/What-is-PWN.md)
41
41
 
@@ -66,7 +66,7 @@ My take: pwn-ai implements a **closed-loop, dual-horizon, self-and-world-aware r
66
66
 
67
67
  - fast aversive conditioning (Mistakes),
68
68
  - value estimates for actions (Metrics),
69
- - episode scoring and replay (Learning/Reward),
69
+ - episode scoring and replay (Learning/Reward, cheap LLM ORM with overlap last),
70
70
  - deliberate practice (Curriculum),
71
71
  - and an external reality check (Extrospection),
72
72
  - with a slower supervised/DPO hatch only when the diet and gates look sane.
@@ -96,12 +96,13 @@ small and easy to swap:
96
96
  ![PWN Overall Architecture](documentation/diagrams/overall-pwn-architecture.svg)
97
97
 
98
98
  On every turn the AI layer runs a **feedback loop**. It checks inward
99
- (Metrics, Learning, and **Mistakes**: what failed last time) and outward
99
+ (Metrics, Learning, **Mistakes**, and **Policy**: what failed last time, and
100
+ which tool the live Q / REINFORCE table currently prefers) and outward
100
101
  (Snapshot, Drift, Intel, RF, and **Web**: did the host or network change?).
101
102
  Live checks use browser-backed **`extro_verify`** / **`extro_watch`** and RF
102
103
  **`extro_rf_tune`**. `extro_correlate` joins those views so the agent can tell
103
104
  *"I messed up"* from *"the world moved"*, and **does not repeat the same
104
- mistake**:
105
+ mistake**. Policy is advice only. Planning still owns the task list:
105
106
 
106
107
  ![pwn-ai Feedback Learning Loop](documentation/diagrams/pwn-ai-feedback-learning-loop.svg)
107
108
 
@@ -118,8 +119,10 @@ message bus:
118
119
  ![Swarm Multi-Agent](documentation/diagrams/swarm-multi-agent.svg)
119
120
 
120
121
  Long-running turns also show **executive task briefs** (not raw commands) via
121
- `TaskSummarizer`: one full plan on submit (`emit_plan!`), then per-batch
122
- `about_to` lines keyed by `tool_counts_phrase` + `intent_phrase` with
122
+ `TaskSummarizer`. Every request is first classified as a **general statement**,
123
+ a **question**, or an **autonomous goal**. Only autonomous goals get a multi-step
124
+ breakdown on submit (`emit_plan!`); statements and questions stay single-turn.
125
+ Per-batch `about_to` lines use `tool_counts_phrase` + `intent_phrase` with
123
126
  `last_brief_fp` duplicate suppression. When recent turns keep hitting the iteration ceiling, the Loop tightens the remaining runway (lower `max_iters` on local engines, text-only tail, no counterfactual fork) so the agent still finishes instead of thrashing.
124
127
 
125
128
  Full pages: [How PWN Works](documentation/How-PWN-Works.md) ·
@@ -137,9 +140,10 @@ The complete wiki lives in this repo at **[`documentation/Home.md`](documentatio
137
140
  | [Why PWN](documentation/Why-PWN.md) | [`pwn-ai` Agent](documentation/pwn-ai-Agent.md) | [Agent Tool Registry](documentation/Agent-Tool-Registry.md) | [SAST (48)](documentation/SAST.md) |
138
141
  | [How PWN Works](documentation/How-PWN-Works.md) | [CLI Drivers (53)](documentation/CLI-Drivers.md) | [Memory · Skills · Learning](documentation/Skills-Memory-Learning.md) | [AWS (90)](documentation/AWS.md) |
139
142
  | [Installation](documentation/Installation.md) | [Build a Driver](documentation/Drivers.md) | [Mistakes (neg-feedback)](documentation/Mistakes.md) | [WWW (21)](documentation/WWW.md) |
140
- | [General Usage](documentation/General-PWN-Usage.md) | | [Extrospection](documentation/Extrospection.md) | [SDR / Radio](documentation/SDR.md) |
141
- | [Configuration](documentation/Configuration.md) | | [Swarm (multi-agent)](documentation/Swarm.md) | [Hardware](documentation/Hardware.md) |
142
- | [`~/.pwn/` Persistence](documentation/Persistence.md) | | [Sessions](documentation/Sessions.md) · [Cron](documentation/Cron.md) | [Reports](documentation/Reporting.md) |
143
+ | [General Usage](documentation/General-PWN-Usage.md) | | [Reinforcement Learning](documentation/Reinforcement-Learning.md) | [SDR / Radio](documentation/SDR.md) |
144
+ | [Configuration](documentation/Configuration.md) | | [Extrospection](documentation/Extrospection.md) | [Hardware](documentation/Hardware.md) |
145
+ | [`~/.pwn/` Persistence](documentation/Persistence.md) | | [Swarm (multi-agent)](documentation/Swarm.md) | [Reports](documentation/Reporting.md) |
146
+ | | | [Sessions](documentation/Sessions.md) · [Cron](documentation/Cron.md) | |
143
147
  | **[All Diagrams](documentation/Diagrams.md)** (29) | | | [BurpSuite](documentation/BurpSuite.md) · [NmapIt](documentation/NmapIt.md) |
144
148
  | [Troubleshooting](documentation/Troubleshooting.md) | | | [Metasploit](documentation/Metasploit.md) · [Fuzzing](documentation/Fuzzing.md) |
145
149
  | [Contributing](documentation/Contributing.md) | | | [Blockchain](documentation/Blockchain.md) · [Bounty](documentation/Bounty.md) |
@@ -48,7 +48,7 @@ The harness adapts to the *class* of engine, not the model name:
48
48
  | **MEMORY ranking** | relevance-ranked when a local Ollama `embed_model` is reachable, else newest-first | relevance-ranked via `PWN::MemoryIndex` (`~/.pwn/memory.idx`) |
49
49
  | **Tool schemas shipped** | all toolsets | `CORE_TOOLS` + top-K keyword matches when `ai.agent.tool_router` is on |
50
50
  | **Pre-pass** | none | `plan_first` numbered tool plan before first dispatch |
51
- | **Intent route** | always | `request_intent` short-circuits how-to (text only) and unauthorized recon (refuse) on all engines; critical for ollama/openwebui |
51
+ | **Intent route** | always | `request_intent` + LLM/heuristic `request_kind` (statement \| question \| autonomous_goal). Short-circuits how-to/questions (text only), greetings/statements (fixed ack), pure recall, and unauthorized recon on all engines; host-evidence Qs (hostname/cwd/whoami) and only true autonomous goals get multi-step TaskSummarizer plans. Critical for ollama/openwebui |
52
52
  | **Few-shot** | none | `Learning.exemplars_for(request)` splices a prior successful trace |
53
53
  | **Dispatch parsing** | strict | tolerant - Levenshtein tool-name repair + JSON5-ish arg cleanup, each repair fingerprinted into `Mistakes` |
54
54
  | **Post-answer** | `auto_introspect` | `auto_introspect` **+** `fact_check_local_final` (auto `extro_verify` on CVE/version-shaped claims) |
@@ -6,12 +6,12 @@ toolsets; the JSON-Schema for each tool is what the model actually sees.
6
6
 
7
7
  ![Tool registry](diagrams/agent-tool-registry.svg)
8
8
 
9
- ## Toolsets to tools (12 toolsets · 82 tools)
9
+ ## Toolsets to tools (13 toolsets · 85 tools)
10
10
 
11
11
  | Toolset | Tools | Backed by |
12
12
  |---|---|---|
13
- | `terminal` | `shell` | `Open3.capture3` on the host |
14
- | `pwn` | `pwn_eval` | `TOPLEVEL_BINDING.eval` in the live REPL process |
13
+ | `terminal` | `shell` | `Open3.capture3` on the host, after `PWN::AI::Agent::ToolGuard` |
14
+ | `pwn` | `pwn_eval` | `TOPLEVEL_BINDING.eval` in the live REPL process, after `ToolGuard` |
15
15
  | `memory` | `memory_remember` · `memory_recall` · `memory_forget` · `memory_clear` · **`memory_lean`** | `PWN::Memory` → `~/.pwn/memory.json` |
16
16
  | `skills` | `skill_list` · `skill_view` · `skill_create` · `skill_add_reference` · `skill_delete` · `skill_migrate_legacy` | `~/.pwn/skills/<name>/SKILL.md` (**[agentskills.io](https://agentskills.io) spec**; legacy flat `*.md` auto-migrated) |
17
17
  | `sessions` | `sessions_list` · `sessions_view` · `sessions_current` · `sessions_delete` · `sessions_stats` · **`sessions_lean`** | `PWN::Sessions` → `~/.pwn/sessions/` |
@@ -19,6 +19,7 @@ toolsets; the JSON-Schema for each tool is what the model actually sees.
19
19
  | `reward` | **`reward_generator_mix`** | `PWN::AI::Agent::Reward.generator_mix` → online preference source-mix controller (`preferences.jsonl`) |
20
20
  | `curriculum` | **`curriculum_practice_kpi`** | `PWN::AI::Agent::Curriculum.practice_kpi` → `~/.pwn/curriculum_kpi.jsonl` |
21
21
  | `metrics` | `metrics_summary` · `metrics_reset` | `PWN::AI::Agent::Metrics` → `~/.pwn/metrics.json` |
22
+ | `policy` | **`policy_stats`** · **`policy_evaluate`** · **`policy_recommend`** | `PWN::AI::Agent::Policy` → `~/.pwn/policy.json` + `~/.pwn/policy_traj.jsonl` |
22
23
  | `extrospection` | `extro_snapshot` · `extro_drift` · `extro_observe` · `extro_observations` · `extro_intel` · **`extro_watch`** · **`extro_verify`** · **`extro_rf_tune`** · **`extro_osint`** · **`extro_serial`** · **`extro_telecomm`** · **`extro_packet`** · **`extro_vision`** · **`extro_voice`** · `extro_correlate` · `extro_stats` · `extro_reset` · `extro_auto_toggle` | `PWN::AI::Agent::Extrospection` (+ Serial/Packet/OCR/Voice/BareSIP/TransparentBrowser/GQRX) → `~/.pwn/extrospection.json` |
23
24
  | `cron` | `cron_list` · `cron_create` · `cron_run` · `cron_enable` · `cron_disable` · `cron_remove` | `PWN::Cron` → `~/.pwn/cron/jobs.yml` |
24
25
  | `swarm` | `agent_list` · `agent_spawn` · `agent_ask` · `agent_debate` · `agent_broadcast` · `swarm_bus` · `swarm_list` | `PWN::AI::Agent::Swarm` → `~/.pwn/agents.yml` + `~/.pwn/swarm/` |
@@ -30,6 +31,17 @@ the same self-improvement loop - see [Reinforcement Learning](Reinforcement-Lear
30
31
  The thin `reward` and `curriculum` toolsets expose controller and KPI surfaces
31
32
  (`reward_generator_mix`, `curriculum_practice_kpi`) so personas can grant just
32
33
  those without the full learning surface.
34
+ `shell` and `pwn_eval` share `PWN::AI::Agent::ToolGuard`
35
+ (`lib/pwn/ai/agent/tool_guard.rb`) before they run. The guard remaps common
36
+ wrong keys, rejects ellipsis placeholders, refuses bash-only syntax unless
37
+ `ai.agent.shell_bash` is true (default runner is `/bin/sh`), and blocks live
38
+ host-discovery unless the request is in-scope or `ai.agent.recon_authorized`
39
+ is true.
40
+
41
+ The `policy` toolset is inspect-only. `policy_stats`, `policy_evaluate`, and
42
+ `policy_recommend` read the live Q / REINFORCE table. Reset is Ruby-only, so a
43
+ tool call cannot wipe the weights. `Registry.rank` may add a small Q-advantage
44
+ after a pair has been visited at least twice. Planning still owns the work.
33
45
 
34
46
  **Store hygiene tools** (`memory_lean`, `sessions_lean`, `mistakes_lean`,
35
47
  `learning_gc_stores`) trim ephemeral or oversized state without dropping
@@ -54,8 +66,8 @@ CORE_TOOLS = shell · pwn_eval · memory_remember · memory_recall
54
66
  ```ruby
55
67
  PWN::AI::Agent::Registry.definitions(relevance: 'nmap sweep 10.0.0.0/8', top_k: 10)
56
68
  PWN::AI::Agent::Registry.rank(query: 'run a shell command') # inspect ranking
57
- PWN::AI::Agent::Registry.toolsets # → the 12 names above
58
- PWN::AI::Agent::Registry.all.count # → 82
69
+ PWN::AI::Agent::Registry.toolsets # → the 13 names above
70
+ PWN::AI::Agent::Registry.all.count # → 85
59
71
  ```
60
72
 
61
73
  Frontier engines leave `tool_router` off and receive the full set.
@@ -103,14 +103,18 @@ ai:
103
103
  task_summary_every: 5 # When task_summary_verbose: emit Progress every N completed tools.
104
104
  task_summary_interval_s: 8.0 # When verbose: also emit when this many seconds elapsed.
105
105
  task_summary_verbose: false # Mid-flight Progress/Finished lines (default: only plan + about_to).
106
+ task_summary_llm: true # LLM tangible-task decompose for autonomous goals (default on). false = offline fallback.
107
+ request_kind_llm: ~ # LLM request_kind classifier (statement|question|autonomous_goal). nil = follow task_summary_llm.
106
108
  max_depth: 3 # Recursion guard: how many levels deep agent_ask/agent_debate sub-agents may spawn sub-agents.
107
109
  auto_introspect: true # Run Learning.auto_introspect (outcome logging + lesson mining) after every final answer.
108
110
  auto_extrospect: false # Optional ambient baseline (host/repo/env ONLY - never launches burpsuite/zaproxy/msf/gqrx). Sense tools (intel/verify/watch/rf_tune/observe) stay on-demand.
109
111
  recon_authorized: false # Allow live subnet sweeps / raw-socket discovery tools this session
112
+ shell_bash: false # true → run shell via bash -lc (PIPESTATUS, [[ ]], process substitution). Default is /bin/sh.
110
113
  plan_first: ~ # Plan-then-act pre-pass: force the model to externalize a numbered tool plan BEFORE its first dispatch. nil = auto (true when ai.active == ollama).
111
114
  tool_router: false # Dynamic tool-set slimming: ship only Registry::CORE_TOOLS + top-K keyword-relevant schemas per turn (helps small models route correctly).
112
115
  escalation_persona: ~ # Swarm persona name to ask for a 3-line corrective hint once a local model burns ≥ Loop::ESCALATE_AFTER_FAILS in-turn failures. nil = disabled.
113
- toolsets: ~ # Allow-list of toolsets exposed to the agent. nil = all. Valid: cron, curriculum, extrospection, learning, memory, metrics, pwn, reward, sessions, skills, swarm, terminal.
116
+ policy: true # Live tabular Q / REINFORCE. Advisory only; never replaces TaskSummarizer / plan_first. false disables.
117
+ toolsets: ~ # Allow-list of toolsets exposed to the agent. nil = all. Valid: cron, curriculum, extrospection, learning, memory, metrics, policy, pwn, reward, sessions, skills, swarm, terminal.
114
118
  extrospection:
115
119
  web:
116
120
  anchors: # URLs the headless browser fingerprints on extro_snapshot(sections:[:web]). Alias: web_anchors.
@@ -268,19 +272,26 @@ PWN::Config.refresh_env
268
272
  | `ai.agent.task_summary_every` | Integer | `5` | `TaskSummarizer.every_n` | Verbose progress cadence (tools). |
269
273
  | `ai.agent.task_summary_interval_s` | Float | `8.0` | `TaskSummarizer.interval_s` | Verbose progress cadence (seconds). |
270
274
  | `ai.agent.task_summary_verbose` | Boolean | `false` | `TaskSummarizer.verbose?` | Emit mid-flight `Progress:` / `Finished:` lines; default keeps only plan + about_to. |
275
+ | `ai.agent.task_summary_llm` | Boolean \| `nil` | `nil` (on) | `TaskSummarizer.llm_plan_enabled?` | LLM tangible-task decomposition for autonomous goals. `false` forces offline generic fallback (tests / air-gap). |
276
+ | `ai.agent.request_kind_llm` | Boolean \| `nil` | `nil` (follow `task_summary_llm`) | `TaskSummarizer.llm_kind_enabled?` / `request_kind` | LLM classifier for `statement` \| `question` \| `autonomous_goal`. Cheap intents and host-evidence heuristics still win first; `false` is heuristic-only. |
271
277
  | `ai.agent.max_depth` | Integer | `3` | `PWN::AI::Agent::Swarm` | Recursion guard for `agent_ask` / `agent_debate` sub-agents spawning sub-agents. |
272
278
  | `ai.agent.auto_introspect` | Boolean | `true` | `PWN::AI::Agent::Learning.auto_introspect` | Run outcome logging + lesson mining after every final answer. Toggle live via `learning_auto_introspect_toggle`. |
273
279
  | `ai.agent.auto_extrospect` | Boolean | `false` | `PWN::AI::Agent::Extrospection.auto_extrospect` | Optional ambient baseline after every final answer (`AUTO_SECTIONS` = host/repo/env only; never spawns GUI/JVM tools). Prefer on-demand sense tools (`intel`/`verify`/`watch`/`rf_tune`/`observe`). Toggle live via `extro_auto_toggle`. |
274
- | `ai.agent.toolsets` | Array\<String\> \| `nil` | `nil` (all) | `bin/pwn`, `PWN::Plugins::REPL`, `PWN::AI::Agent::Registry` | Allow-list of toolsets exposed to the agent. Valid: `cron`, `curriculum`, `extrospection`, `learning`, `memory`, `metrics`, `pwn`, `reward`, `sessions`, `skills`, `swarm`, `terminal`. |
275
- | `ai.agent.recon_authorized` | Boolean | `false` | `PWN::AI::Agent::Loop.recon_authorized?` / shell guard | When true (or the user request contains in-scope / engagement language), live host-discovery tools may run. Default refuses unauthorized sweeps. |
280
+ | `ai.agent.toolsets` | Array\<String\> \| `nil` | `nil` (all) | `bin/pwn`, `PWN::Plugins::REPL`, `PWN::AI::Agent::Registry` | Allow-list of toolsets exposed to the agent. Valid: `cron`, `curriculum`, `extrospection`, `learning`, `memory`, `metrics`, `policy`, `pwn`, `reward`, `sessions`, `skills`, `swarm`, `terminal`. |
281
+ | `ai.agent.recon_authorized` | Boolean | `false` | `PWN::AI::Agent::ToolGuard.recon_authorized?` / `Loop.recon_authorized?` | When true (or the user request contains in-scope / engagement language), live host-discovery tools may run. Default refuses unauthorized sweeps. |
282
+ | `ai.agent.shell_bash` | Boolean | `false` | `PWN::AI::Agent::ToolGuard.shell_bash?` | When true, `shell` runs via `bash -lc` so bash-only syntax is allowed. Default is POSIX `/bin/sh` and bashisms are rejected with a rewrite hint. |
276
283
  | `ai.agent.plan_first` | Boolean \| `nil` | `nil` (auto: `true` when `ai.active == ollama`) | `PWN::AI::Agent::Loop.plan_first` | Plan-then-act pre-pass: the model must emit a numbered tool plan (as an assistant message) *before* it may dispatch anything. Cheap chain-of-thought scaffolding for local models. |
277
284
  | `ai.agent.tool_router` | Boolean | `false` | `PWN::AI::Agent::Registry.definitions` | Dynamic tool-set slimming: expose only `Registry::CORE_TOOLS` + the top-K keyword-relevant schemas for *this* request. Ties break on historical `Metrics` success rate so the router itself is a learned component. |
278
285
  | `ai.agent.escalation_persona` | String \| `nil` | `nil` | `PWN::AI::Agent::Loop.escalate` → `Swarm.ask` | Circuit-breaker: once a local model accumulates ≥ `Loop::ESCALATE_AFTER_FAILS` in-turn failures, ask this Swarm persona for a 3-line corrective hint (injected as a synthetic tool result). The local model still authors the final answer so Learning/Metrics stay attributed. |
279
- | `ai.agent.critic` | Boolean | `false` | `PWN::AI::Agent::Curriculum.critic` (S3) | Tool-armed constitutional self-critic reviews (and may `shell`/`extro_verify`) every final answer before it is returned. |
280
- | `ai.agent.red_team_plan` | Boolean | `false` | `PWN::AI::Agent::Curriculum.red_team_plan` (S4) | Adversarial review of the `plan_first` numbered plan, grounded in Metrics/Mistakes/`extro_drift` telemetry, before the first dispatch. |
281
- | `ai.agent.counterfactual` | Boolean | `false` | `PWN::AI::Agent::Curriculum.counterfactual` (S2) | On `[REPEATING]`, fork an alt-persona branch, judge both, and record the `(loser, winner)` DPO preference pair. |
282
- | `ai.agent.hindsight` | Boolean | `true` | `PWN::AI::Agent::Curriculum.hindsight` (C3) | Hindsight Experience Replay - relabel a failed trajectory as `success:true` for whatever it *did* accomplish. Free positive samples from failures. |
283
- | `ai.agent.verify_as_reward` | Boolean | `false` | `PWN::AI::Agent::Reward.verify_as_reward` (E3) | Ground the LLM judge score by browser-verifying any checkable claim in the final via `extro_verify`; verdict caps/floors `Reward.judge`. |
286
+ | `ai.agent.critic` | Boolean | `false` | `PWN::AI::Agent::Curriculum.critic` | Tool-armed constitutional self-critic reviews (and may `shell`/`extro_verify`) every final answer before it is returned. |
287
+ | `ai.agent.red_team_plan` | Boolean | `false` | `PWN::AI::Agent::Curriculum.red_team_plan` | Adversarial review of the `plan_first` numbered plan, grounded in Metrics/Mistakes/`extro_drift` telemetry, before the first dispatch. |
288
+ | `ai.agent.counterfactual` | Boolean | `false` | `PWN::AI::Agent::Curriculum.counterfactual` | On `[REPEATING]`, fork an alt-persona branch, judge both, and record the `(loser, winner)` DPO preference pair. |
289
+ | `ai.agent.hindsight` | Boolean | `true` | `PWN::AI::Agent::Curriculum.hindsight` | Hindsight Experience Replay - relabel a failed trajectory as `success:true` for whatever it *did* accomplish. Free positive samples from failures. |
290
+ | `ai.agent.policy` | Boolean | `true` | `PWN::AI::Agent::Policy` | Live tabular Q-learning + REINFORCE. Records `(s,a,r,s')` per tool step, trains on `Reward.judge` at episode end, and adds a small Q-advantage term to `Registry.rank`. Advisory only: never replaces TaskSummarizer or plan_first. |
291
+ | `ai.agent.reward_llm` | Boolean \| `nil` | `nil` (auto: on for remote, off for ollama) | `PWN::AI::Agent::Reward.judge` / `.prm` | Use a cheap LLM teacher for outcome/process judges even when `module_reflection` is false. Local ollama stays heuristic unless this is `true`. |
292
+ | `ai.agent.reward_model` | String \| `nil` | `nil` | `Reward.judge` / `.prm` | Optional cheaper model id for the ORM/PRM chat. Falls back to `ai.reflect_model`, then the active engine default. |
293
+ | `ai.agent.reward_llm_timeout` | Integer | `12` | `Reward.judge` / `.prm` | Seconds for the cheap ORM chat (clamped 2..30). Fail fast to the overlap heuristic rather than a 900s hang. |
294
+ | `ai.agent.verify_as_reward` | Boolean | `false` | `PWN::AI::Agent::Reward.verify_as_reward` | Ground the LLM judge score by browser-verifying any checkable claim in the final via `extro_verify`; verdict caps/floors `Reward.judge`. |
284
295
  | `ai.agent.extrospection.web.anchors` | Array\<String\> | `DEFAULT_WEB_ANCHORS` | `PWN::AI::Agent::Extrospection.probe_web` | URLs the headless browser fingerprints on `extro_snapshot(sections:[:web])`. Alias: `web_anchors`. |
285
296
  | `ai.agent.extrospection.web.proxy` | String | - | `Extrospection.probe_web` / `.verify` / `.watch` | Upstream proxy for `PWN::Plugins::TransparentBrowser` (e.g. `tor`, `http://127.0.0.1:8080`). |
286
297
  | `ai.agent.extrospection.web.max_anchors` | Integer | `8` | `Extrospection.probe_web` | Cap on anchors rendered per snapshot. |
@@ -60,7 +60,7 @@ groups) so lines never criss-cross.
60
60
  [source](diagrams/dot/mistakes-negative-feedback.dot) · doc: [Mistakes](Mistakes.md)
61
61
  ![mistakes-negative-feedback](diagrams/mistakes-negative-feedback.svg)
62
62
 
63
- ### Reinforcement Learning - Reward + Curriculum
63
+ ### Reinforcement Learning - Reward + Curriculum + Policy
64
64
  [source](diagrams/dot/reinforcement-learning.dot) · doc: [Reinforcement Learning](Reinforcement-Learning.md)
65
65
  ![reinforcement-learning](diagrams/reinforcement-learning.svg)
66
66
 
@@ -68,7 +68,7 @@ groups) so lines never criss-cross.
68
68
  [source](diagrams/dot/ai-integration-tool-calling.dot) · doc: [AI Integration](AI-Integration.md)
69
69
  ![ai-integration-tool-calling](diagrams/ai-integration-tool-calling.svg)
70
70
 
71
- ### Agent Tool Registry (12 toolsets · 82 tools)
71
+ ### Agent Tool Registry (13 toolsets · 85 tools)
72
72
  [source](diagrams/dot/agent-tool-registry.dot) · doc: [Agent Tool Registry](Agent-Tool-Registry.md)
73
73
  ![agent-tool-registry](diagrams/agent-tool-registry.svg)
74
74
 
@@ -36,10 +36,10 @@
36
36
  | | |
37
37
  |---|---|
38
38
  | [AI / LLM Integration](AI-Integration.md) | OpenAI · Anthropic · Grok (OAuth) · Gemini · Ollama · Open WebUI |
39
- | [Agent Tool Registry](Agent-Tool-Registry.md) | 12 toolsets · **82** LLM-callable tools |
39
+ | [Agent Tool Registry](Agent-Tool-Registry.md) | 13 toolsets · **85** LLM-callable tools |
40
40
  | [Memory · Skills · Learning](Skills-Memory-Learning.md) | Introspection - the self-improvement loop |
41
41
  | [Mistakes](Mistakes.md) | **Negative feedback** - fingerprint failures · do-NOT-repeat · `[REPEATING]`/`[REGRESSED]` · inline self-correction |
42
- | [Reinforcement Learning](Reinforcement-Learning.md) | **`Reward` + `Curriculum`** - outcome/process judges · preference ledger · self-play practice · export-ready LoRA gate |
42
+ | [Reinforcement Learning](Reinforcement-Learning.md) | **`Reward` + `Curriculum` + `Policy`** - outcome/process judges · preference ledger · self-play practice · live Q / REINFORCE (advisory) · export-ready LoRA gate |
43
43
  | [Extrospection](Extrospection.md) | World-awareness - snapshot · drift · intel · **watch** · **verify** · **rf_tune** · **osint** · serial · telecomm · packet · vision · voice · correlate |
44
44
  | [Swarm (Multi-Agent)](Swarm.md) | Personas · ask · debate · broadcast · shared bus |
45
45
  | [Sessions](Sessions.md) | Transcript persistence + reflection |
@@ -28,20 +28,20 @@ hardware).
28
28
  | Module | Role |
29
29
  |---|---|
30
30
  | `Loop` | plan → **TaskSummarizer** briefs → dispatch tool_calls → observe → repeat until final answer; tightens runway when recent turns exhausted the budget |
31
- | **`TaskSummarizer`** | Executive UX: English tasks primary - `emit_plan!` · `about_to` as `task k/n` + via tools · Loop `plan_context` injection · clearer `plan_idx` advance |
32
- | `Registry` | JSON-Schema function definitions grouped into 12 **toolsets** · **82 tools** |
31
+ | **`TaskSummarizer`** | Executive UX: LLM/heuristic `request_kind` gates plans (only autonomous goals, including host-evidence Qs) - English tasks primary - `emit_plan!` · `about_to` as `task k/n` + via tools · Loop `plan_context` injection · clearer `plan_idx` advance |
32
+ | `Registry` | JSON-Schema function definitions grouped into 13 **toolsets** · **85 tools** |
33
33
  | `Dispatch` / `Result` | execute a tool, capture stdout/value/error/duration |
34
- | `PromptBuilder` | inject MEMORY / SKILLS / LEARNING / **KNOWN MISTAKES + FIXES** / METRICS / EXTROSPECTION blocks |
35
- | `Metrics` · `Learning` · `Reflect` | **introspection** - how well am I doing? |
34
+ | `PromptBuilder` | inject MEMORY / SKILLS / LEARNING / **KNOWN MISTAKES + FIXES** / METRICS / **POLICY** / EXTROSPECTION / RECENT TURNS |
35
+ | `Metrics` · `Learning` · `Reflect` · **`Policy`** | **introspection** - how well am I doing? (Policy is live Q / REINFORCE, advisory rank only) |
36
36
  | `Mistakes` | **negative feedback** - fingerprint failures, do NOT repeat, `[REPEATING]`/`[REGRESSED]`, inline `correction_hint` |
37
- | **`Reward`** | outcome `judge` · per-step process credit · `sentinel` (proxy vs judge drift) · `semantic_ok` · DPO `preferences.jsonl` |
37
+ | **`Reward`** | cheap LLM outcome `judge` (heuristic overlap last) · per-step process credit · `sentinel` (proxy vs ORM-weighted judge) · `semantic_ok` · DPO `preferences.jsonl` |
38
38
  | **`Curriculum`** | mistake-driven self-play `practice` · `counterfactual` A/B · tool-armed `critic` · `red_team_plan` · `hindsight` (HER) · `train_and_gate` regression-gated LoRA |
39
39
  | `Extrospection` | **extrospection** - on-demand world sensing (`intel` · **`verify`** · **`watch`** · **`rf_tune`** · **`osint`** · `serial` · `telecomm` · `packet` · `vision` · `voice`) + ambient baseline (host · net · toolchain · repo · env · **rf** · **web**) joined to introspection via `correlate` |
40
40
  | `Swarm` | multi-agent personas over a shared JSONL bus |
41
41
 
42
42
  See [Agent Tool Registry](Agent-Tool-Registry.md) for every tool the LLM can
43
43
  call, and [Reinforcement Learning](Reinforcement-Learning.md) for how
44
- `Reward` + `Curriculum` close the weight-level loop.
44
+ `Reward` + `Curriculum` + `Policy` close the learning loop.
45
45
 
46
46
  ## L3 - Capability namespaces (`lib/pwn/*`)
47
47
 
@@ -69,10 +69,12 @@ lessons, **failures become fingerprinted mistakes with fixes**, **world state
69
69
  is sensed on demand** (`extro_verify` / `extro_watch` / `extro_rf_tune` /
70
70
  `extro_osint` / `extro_serial` / `extro_telecomm` / `extro_packet` /
71
71
  `extro_vision` / `extro_voice` / `extro_intel`) and correlated against those
72
- failures, an **LLM judge scores the final answer** and a **process reward
73
- model tags each tool step**, and **all six prompt blocks** (MEMORY · SKILLS ·
74
- LEARNING · KNOWN MISTAKES/FIXES · TOOL EFFECTIVENESS · EXTROSPECTION) are
75
- re-injected into the next system prompt.
72
+ failures, a **cheap LLM judge scores the final answer** (token overlap only if the engine is unavailable) and a **process reward
73
+ model tags each tool step**, **Policy records the live MDP step** and updates
74
+ Q / REINFORCE when the judge scores the turn, and **the prompt blocks**
75
+ (MEMORY · SKILLS · LEARNING · KNOWN MISTAKES/FIXES · TOOL EFFECTIVENESS ·
76
+ POLICY · EXTROSPECTION · RECENT TURNS) are re-injected into the next system
77
+ prompt.
76
78
  Nightly cron practices the top unresolved Mistakes; weekly cron builds a
77
79
  LoRA and only promotes it if it beats the previous adapter on that same
78
80
  mistake set:
@@ -187,7 +187,9 @@ predates the running gem (`PWN::Migrate.needed?`).
187
187
 
188
188
  Schema `v1` also seeds `PWN::Cron.install_defaults` - the nightly
189
189
  `curriculum_practice` and weekly `curriculum_train` self-improvement jobs
190
- (see [Reinforcement Learning](Reinforcement-Learning.md)).
190
+ (see [Reinforcement Learning](Reinforcement-Learning.md)). Live Policy
191
+ files (`policy.json`, `policy_traj.jsonl`) are created on first agent turn
192
+ when `ai.agent.policy` is on.
191
193
 
192
194
  From a checkout:
193
195
 
@@ -38,10 +38,13 @@ Loop.run --(same sig, count≥3)----> guard_repeated_failure (uses PERSISTENT c
38
38
  Loop.run --(failure w/ known fix)-> inline correction_hint ("seen 5×, sig=..., KNOWN FIX: ..."
39
39
  → self-corrects NEXT iteration)
40
40
  Loop.run --(user says "wrong")----> check_user_correction (flip last outcome + record)
41
+ Loop.run --(start of turn)--------> extinguish_parked! (close inbox scars that already have a known recipe)
41
42
  PromptBuilder <-------------------- Mistakes.to_context (KNOWN MISTAKES + KNOWN FIXES)
42
43
  model --(tool call)---------------> mistakes_record / mistakes_resolve
43
44
  ```
44
45
 
46
+ Repeating shell failures with a known recipe (`command is required`, missing path, not-found junk, syntax, raw-socket deny) are resolved in place instead of parked as "needs human". Only scars the loop cannot close stay in the operator inbox.
47
+
45
48
  ## Five ingest paths - nothing slips through
46
49
 
47
50
  | Source | Trigger | What is recorded |
@@ -16,6 +16,8 @@ Every byte PWN remembers between processes lives here.
16
16
  | **`preferences.jsonl`** | **`PWN::AI::Agent::Reward`** | JSON-per-line `{prompt,rejected,chosen,source}` | `rm` | **DPO/KTO/ORPO preference-pair ledger - user_correction · mistakes_resolve · counterfactual · critic · curriculum** |
17
17
  | **`mistakes.json`** | **`PWN::AI::Agent::Mistakes`** | **JSON `{sig → entry}`** | **`mistakes_reset`** | **failure fingerprints · cross-session count · fix · `[REPEATING]` · `[REGRESSED]`** |
18
18
  | `metrics.json` | `PWN::AI::Agent::Metrics` | JSON | `metrics_reset` | per-tool calls · success · avg_duration · last_error · **per-engine** sub-buckets · calibration |
19
+ | **`policy.json`** | **`PWN::AI::Agent::Policy`** | JSON `{q,h,visits,returns}` | `PWN::AI::Agent::Policy.reset` | Live Q table + REINFORCE logits. Advisory rank only. |
20
+ | **`policy_traj.jsonl`** | **`PWN::AI::Agent::Policy`** | JSON-per-line episodes | `PWN::AI::Agent::Policy.reset` | MDP trajectories `(s,a,r,s')` from each Loop turn |
19
21
  | `reward_sentinel.json` | `PWN::AI::Agent::Reward` | JSON | `rm` | proxy vs judge vs user-correction gap history |
20
22
  | `extrospection.json` | `PWN::AI::Agent::Extrospection` | JSON | `extro_reset` | host/net/toolchain/repo/env/**rf**/**web**/osint/serial/telecomm/packet/vision/voice snapshot + previous baseline + observations[] |
21
23
  | `extrospection/web/*.png` | `Extrospection` | PNG | `rm -rf` | headless-browser screenshots from `probe_web` / `extro_watch` (opt-in) |
@@ -76,6 +78,7 @@ extro_reset(confirm: true) # host snapshot + observations
76
78
  mistakes_reset(confirm: true) # failure fingerprints (host-specific errors)
77
79
  learning_reset(confirm: true) # task outcomes (optional)
78
80
  metrics_reset(confirm: true) # tool telemetry (optional)
81
+ PWN::AI::Agent::Policy.reset # live Q table + trajectory log (optional)
79
82
  ```
80
83
 
81
84
  [← Home](Home.md) · [Configuration](Configuration.md) · [Installation](Installation.md)
@@ -90,7 +93,7 @@ protected operator preferences:
90
93
  | `memory_lean` | expired `session_*` keys and overlong values (`VALUE_MAX_CHARS`) |
91
94
  | `sessions_lean` | stub/aged transcripts not pinned by gold outcomes or open mistakes |
92
95
  | `mistakes_lean` | compact fields; age out resolved-once signatures whose fix already lives in Memory |
93
- | `learning_gc_stores` | coordinated lean pass across memory, learning, mistakes, and sessions |
96
+ | `learning_gc_stores` | coordinated lean pass across memory, learning, mistakes, sessions, and Policy trajectories |
94
97
 
95
98
  All four support `dry_run: true` (plan only). Protected `operator_pref_*`,
96
99
  `process_sop_*`, and `mistake_fix_*` memory keys are never removed by lean.