pwn 0.5.802 → 0.5.804

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 80052ce5d8a763fc4bc6909d6335b59c7a3aaf5cbb201a60ac10d637c7138bb5
4
- data.tar.gz: 679d21109b6baead7be731bc85e9cc89ac9227af20f5caa61ef49c6ec92494cc
3
+ metadata.gz: 4e61218b09e4d32bf5d481b3d4786acd8876e1a125af191b3b6eb767f63a6a23
4
+ data.tar.gz: dd662b30064a1ed70bf7abb444f2f76d0e67a913ccc56bd220782dd54806032b
5
5
  SHA512:
6
- metadata.gz: 5761d5ab7b986ce9790d840426620470e5b5f72711c3f12df210c85edac5e63725f456770e96af6d27a39ae6be895f3b63c53640c7088d770e39aea93a728b97
7
- data.tar.gz: 7fb6b534ca7f69574ec430d5b85ae99cafee9dd1f3045b6e18657cd8855e68c0aea0e473936feff1951e15ee9d9796ed33ff3a8110bb5773503744482b8167b1
6
+ metadata.gz: b747be32f0773d25e0d46cf6428dd75ddd3811c5b0d6bad5a671d89b900c4c3c79eb9b44dd1a52734fdacaddb5dd983d426a02f9265ddf980d0ea3ee619c935f
7
+ data.tar.gz: c790fee5e8820c0e78dc9541f10a6ed8cc43ba87333e70f2b485bd8c64f011f697211cf03f2fe5deab846a985ad3a444c0db9c0ed2256221c8c5366ebd9eb1ef
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 4.0.9
1
+ 4.0.10
data/Gemfile CHANGED
@@ -50,7 +50,7 @@ gem 'libusb', '0.8.0'
50
50
  gem 'luhn', '3.0.0'
51
51
  gem 'mail', '2.9.1'
52
52
  gem 'mcp', '1.11.0'
53
- gem 'meshtastic', '0.0.193'
53
+ gem 'meshtastic', '0.0.194'
54
54
  gem 'metasm', '1.0.6'
55
55
  gem 'mongo', '2.26.2'
56
56
  gem 'msfrpc-client', '1.1.2'
@@ -77,7 +77,7 @@ gem 'rbvmomi2', '3.11.0'
77
77
  gem 'rdoc', '7.0.4'
78
78
  gem 'rest-client', '2.1.0'
79
79
  gem 'rex', '2.0.13'
80
- gem 'rmagick', '7.2.0'
80
+ gem 'rmagick', '7.3.1'
81
81
  gem 'rqrcode', '3.2.0'
82
82
  gem 'rspec', '3.13.2'
83
83
  gem 'rtesseract', '3.1.4'
@@ -89,8 +89,8 @@ gem 'ruby-nmap', '1.0.3'
89
89
  gem 'ruby-saml', '1.18.1'
90
90
  gem 'rvm', '1.11.3.9'
91
91
  gem 'savon', '2.18.1'
92
- gem 'selenium-devtools', '0.157.0'
93
- gem 'selenium-webdriver', '4.53.0'
92
+ gem 'selenium-devtools', '0.158.0'
93
+ gem 'selenium-webdriver', '4.54.0'
94
94
  gem 'slack-ruby-client', '3.3.0'
95
95
  gem 'socksify', '1.8.1'
96
96
  gem 'spreadsheet', '1.3.5'
data/lib/pwn/ai/ollama.rb CHANGED
@@ -4,6 +4,7 @@ require 'json'
4
4
  require 'base64'
5
5
  require 'securerandom'
6
6
  require 'uri'
7
+ require 'pwn/ai'
7
8
 
8
9
  module PWN
9
10
  module AI
@@ -269,13 +270,14 @@ module PWN
269
270
  # SSE on /v1/chat/completions) into a single JSON string matching the
270
271
  # non-stream response shape used by #chat / #chat_with_tools.
271
272
  private_class_method def self.assemble_ollama_stream(opts = {})
272
- body = opts[:body].to_s
273
+ preview = StreamPreview.new(body: opts[:body].to_s, provider: 'Ollama')
273
274
  rest_call = opts[:rest_call].to_s
274
275
 
275
- records = stream_records(body: body, rest_call: rest_call)
276
+ records = stream_records(body: preview.body, rest_call: rest_call)
276
277
  done = false
277
278
  payloads = records.filter_map do |record|
278
279
  raise "ERROR: Ollama incomplete SSE stream for #{rest_call}: unterminated event" if record[:incomplete]
280
+ raise "ERROR: Ollama stream error for #{rest_call}" if preview.required? && record[:event] == 'error'
279
281
 
280
282
  data = record[:data]
281
283
  if data == '[DONE]'
@@ -287,6 +289,8 @@ module PWN
287
289
  payload = parse_stream_payload(data: data, rest_call: rest_call)
288
290
  error = payload[:error] || (payload if record[:event] == 'error')
289
291
  if error
292
+ raise "ERROR: Ollama stream error for #{rest_call}" if preview.required?
293
+
290
294
  detail = error.is_a?(Hash) ? (error[:message] || error) : error
291
295
  raise "ERROR: Ollama stream error for #{rest_call}: #{detail}"
292
296
  end
@@ -299,11 +303,15 @@ module PWN
299
303
  finished = payloads.any? { |p| Array(p[:choices]).any? { |ch| ch[:finish_reason] } }
300
304
  raise "ERROR: Ollama incomplete stream for #{rest_call}: missing terminal event" unless done || finished
301
305
 
306
+ return preview.display!(payloads: payloads, sse: true, done: done) if preview.required?
307
+
302
308
  assemble_openai_compat_stream(payloads: payloads)
303
309
  else
304
310
  raise "ERROR: Ollama malformed native stream for #{rest_call}: expected message object" unless payloads.any? { |p| p[:message].is_a?(Hash) } && payloads.all? { |p| !p.key?(:message) || p[:message].is_a?(Hash) }
305
311
  raise "ERROR: Ollama incomplete native stream for #{rest_call}: missing terminal done frame" unless payloads.last[:done] == true && payloads[0...-1].all? { |p| p[:done] == false }
306
312
 
313
+ return preview.display!(payloads: payloads, sse: false) if preview.required?
314
+
307
315
  assemble_native_chat_stream(payloads: payloads)
308
316
  end
309
317
  end
@@ -4,6 +4,7 @@ require 'json'
4
4
  require 'base64'
5
5
  require 'securerandom'
6
6
  require 'uri'
7
+ require 'pwn/ai'
7
8
 
8
9
  module PWN
9
10
  module AI
@@ -282,13 +283,14 @@ module PWN
282
283
  # OpenAI-compat SSE on /api/v1/chat/completions) into a single JSON string
283
284
  # matching the non-stream response shape used by #chat / #chat_with_tools.
284
285
  private_class_method def self.assemble_openwebui_stream(opts = {})
285
- body = opts[:body].to_s
286
+ preview = StreamPreview.new(body: opts[:body].to_s, provider: 'Open WebUI')
286
287
  rest_call = opts[:rest_call].to_s
287
288
 
288
- records = stream_records(body: body, rest_call: rest_call)
289
+ records = stream_records(body: preview.body, rest_call: rest_call)
289
290
  done = false
290
291
  payloads = records.filter_map do |record|
291
292
  raise "ERROR: Open WebUI incomplete SSE stream for #{rest_call}: unterminated event" if record[:incomplete]
293
+ raise "ERROR: Open WebUI stream error for #{rest_call}" if preview.required? && record[:event] == 'error'
292
294
 
293
295
  data = record[:data]
294
296
  if data == '[DONE]'
@@ -300,6 +302,8 @@ module PWN
300
302
  payload = parse_stream_payload(data: data, rest_call: rest_call)
301
303
  error = payload[:error] || (payload if record[:event] == 'error')
302
304
  if error
305
+ raise "ERROR: Open WebUI stream error for #{rest_call}" if preview.required?
306
+
303
307
  detail = error.is_a?(Hash) ? (error[:message] || error) : error
304
308
  raise "ERROR: Open WebUI stream error for #{rest_call}: #{detail}"
305
309
  end
@@ -312,11 +316,15 @@ module PWN
312
316
  finished = payloads.any? { |p| Array(p[:choices]).any? { |ch| ch[:finish_reason] } }
313
317
  raise "ERROR: Open WebUI incomplete stream for #{rest_call}: missing terminal event" unless done || finished
314
318
 
319
+ return preview.display!(payloads: payloads, sse: true, done: done) if preview.required?
320
+
315
321
  assemble_openai_compat_stream(payloads: payloads)
316
322
  else
317
323
  raise "ERROR: Open WebUI malformed native stream for #{rest_call}: expected message object" unless payloads.any? { |p| p[:message].is_a?(Hash) } && payloads.all? { |p| !p.key?(:message) || p[:message].is_a?(Hash) }
318
324
  raise "ERROR: Open WebUI incomplete native stream for #{rest_call}: missing terminal done frame" unless payloads.last[:done] == true && payloads[0...-1].all? { |p| p[:done] == false }
319
325
 
326
+ return preview.display!(payloads: payloads, sse: false) if preview.required?
327
+
320
328
  assemble_native_chat_stream(payloads: payloads)
321
329
  end
322
330
  end
data/lib/pwn/ai.rb CHANGED
@@ -21,6 +21,50 @@ module PWN
21
21
  autoload :Router, 'pwn/ai/router'
22
22
  autoload :ServerTools, 'pwn/ai/server_tools'
23
23
 
24
+ # Ollama and Open WebUI share a wire format. A binary-tagged non-ASCII reply
25
+ # that previously failed framing may be recovered for display, not replayed.
26
+ class StreamPreview
27
+ attr_reader :body
28
+
29
+ def initialize(body:, provider:)
30
+ @provider = provider
31
+ @required = body.encoding == Encoding::BINARY && !body.ascii_only?
32
+ @body = required? ? body.dup.force_encoding(Encoding::UTF_8) : body
33
+ raise "ERROR: #{@provider} response contains invalid UTF-8" if required? && !@body.valid_encoding?
34
+ end
35
+
36
+ def required?
37
+ @required
38
+ end
39
+
40
+ # Only choice 0 is displayed. Another choice cannot finish its text.
41
+ # Never return actions, arguments or reasoning, even without a console.
42
+ def display!(payloads:, sse:, done: false)
43
+ text = +''
44
+ role = 'assistant'
45
+ pending = false
46
+ finish_reason = nil
47
+ payloads.each do |payload|
48
+ choices = sse ? Array(payload[:choices]) : [{ message: payload[:message], finish_reason: payload[:done_reason] }]
49
+ choices.each_with_index do |choice, index|
50
+ msg = choice[:delta] || choice[:message] || {}
51
+ pending ||= %w[tool_calls function_call].include?(choice[:finish_reason]) || !Array(msg[:tool_calls]).empty? || !msg[:function_call].nil?
52
+ next unless 0.eql?(choice.fetch(:index, index))
53
+
54
+ finish_reason = choice[:finish_reason]
55
+ role = msg[:role] || role
56
+ text << msg[:content] if role == 'assistant' && msg[:content].is_a?(String)
57
+ end
58
+ end
59
+ choice_finished = finish_reason.is_a?(String) && !finish_reason.empty?
60
+ raise "ERROR: #{@provider} incomplete SSE preview: missing finish reason for choice 0" if sse && !done && !choice_finished
61
+
62
+ Thread.current[:pwn_stream_preview]&.call(@provider, text, pending)
63
+ raise "#{@provider} reply is display-only; no actions from this reply were submitted."
64
+ end
65
+ end
66
+ private_constant :StreamPreview
67
+
24
68
  # Display a List of Every PWN::AI Module
25
69
 
26
70
  # Author(s):: 0day Inc. <support@0dayinc.com>
@@ -273,6 +273,7 @@ module PWN
273
273
  # Cancellation never raises asynchronously into a tool.
274
274
  class Control < PWN::AI::Agent::Loop::Steering
275
275
  class Stopped < Exception; end # rubocop:disable Lint/InheritException
276
+ class PreviewShown < Stopped; end
276
277
 
277
278
  def stopping?
278
279
  @stopping == true
@@ -769,6 +770,19 @@ module PWN
769
770
  %i[pwn_ai_session_id pwn_ai_debug pwn_ai_trace pwn_ai_speak pwn_ai_agent].to_h { |key| [key, @pry.config.public_send(key)] }
770
771
  end
771
772
 
773
+ def with_stream_preview(events)
774
+ previous = Thread.current[:pwn_stream_preview]
775
+ Thread.current[:pwn_stream_preview] = lambda do |provider, text, pending|
776
+ visible = text.gsub(/[\x00-\x08\x0B-\x1F\x7F-\u009F]/, '')
777
+ events << [:assistant, visible] unless visible.empty?
778
+ status = pending ? 'A requested action was not processed.' : 'No actions from this reply were processed.'
779
+ raise Control::PreviewShown, "#{provider} reply recovered for display only. #{status} This turn has ended."
780
+ end
781
+ yield
782
+ ensure
783
+ Thread.current[:pwn_stream_preview] = previous
784
+ end
785
+
772
786
  def mission_request_child(data, writer, commands)
773
787
  request, generation, session_id, title_config = data.values_at(:request, :generation, :session_id, :title_config)
774
788
  events = MissionEvents.new(writer, generation)
@@ -797,14 +811,18 @@ module PWN
797
811
  events << [:result, result.to_s]
798
812
  end
799
813
  end
800
- final = PWN::AI::Agent::Loop.run(request: request, session_id: session_id,
801
- enabled_toolsets: PWN::Env.dig(:ai, :agent, :toolsets),
802
- on_tool: on_tool, steering: control, debug: @pry.config.pwn_ai_debug,
803
- trace: @pry.config.pwn_ai_trace, debug_tee: output)
814
+ final = with_stream_preview(events) do
815
+ PWN::AI::Agent::Loop.run(request: request, session_id: session_id,
816
+ enabled_toolsets: PWN::Env.dig(:ai, :agent, :toolsets),
817
+ on_tool: on_tool, steering: control, debug: @pry.config.pwn_ai_debug,
818
+ trace: @pry.config.pwn_ai_trace, debug_tee: output)
819
+ end
804
820
  promoted = Thread.current[:pwn_thinking_promoted] && final.to_s.strip == Thread.current[:pwn_last_thinking].to_s.strip
805
821
  events << [:assistant, final.to_s] unless promoted
806
822
  events << [:session_title, PWN::Sessions.refresh_title(session_id: session_id, ai_config: title_config, on_error: ->(kind) { events << [:warning, "Session title refresh unavailable (#{kind}); previous title retained."] })]
807
823
  end
824
+ rescue Control::PreviewShown => e
825
+ events << [:warning, e.message]
808
826
  rescue StandardError, Interrupt, Control::Stopped => e
809
827
  warning = if e.respond_to?(:http_code) && e.http_code == 403
810
828
  'Access denied (HTTP 403). Check that your account can use the selected model and endpoint.'
data/lib/pwn/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PWN
4
- VERSION = '0.5.802'
4
+ VERSION = '0.5.804'
5
5
  end
@@ -338,3 +338,30 @@ describe PWN::AI::Ollama do
338
338
  expect(described_class).not_to respond_to(:get_plan_usage)
339
339
  end
340
340
  end
341
+
342
+ describe PWN::AI::Ollama, 'binary stream display recovery' do
343
+ it 'previews complete UTF-8 SSE without returning a provider response or changing the wire bytes' do
344
+ event = JSON.generate(choices: [{ delta: { role: 'assistant', content: 'Café', reasoning_content: 'not for display' } }])
345
+ wire = "\uFEFFdata: #{event}\r\n\r\ndata: [DONE]\r\n\r\n".b.freeze
346
+ previews = []
347
+ previous = Thread.current[:pwn_stream_preview]
348
+ Thread.current[:pwn_stream_preview] = ->(*args) { previews << args }
349
+ expect { described_class.send(:assemble_ollama_stream, body: wire, rest_call: 'v1/chat/completions') }.to raise_error(RuntimeError, /Ollama.*display-only/)
350
+ expect(previews).to eq([['Ollama', 'Café', false]])
351
+ expect(wire.encoding).to eq(Encoding::BINARY)
352
+ ensure
353
+ Thread.current[:pwn_stream_preview] = previous
354
+ end
355
+
356
+ it 'rejects invalid bytes, incomplete native frames and provider errors before showing any text' do
357
+ wire = JSON.generate(message: { role: 'assistant', content: 'Café' }, done: false).b
358
+ parse = ->(body) { described_class.send(:assemble_ollama_stream, body: body, rest_call: 'api/chat') }
359
+ previous = Thread.current[:pwn_stream_preview]
360
+ Thread.current[:pwn_stream_preview] = ->(*) { raise 'Unexpected preview' }
361
+ expect { parse.call(wire + "\xFF".b) }.to raise_error(RuntimeError, /Ollama.*invalid UTF-8/)
362
+ expect { parse.call(wire) }.to raise_error(RuntimeError, /incomplete native stream/)
363
+ expect { parse.call("#{wire}\n{\"error\":\"private detail\"}".b) }.to raise_error(RuntimeError, 'ERROR: Ollama stream error for api/chat')
364
+ ensure
365
+ Thread.current[:pwn_stream_preview] = previous
366
+ end
367
+ end
@@ -344,3 +344,38 @@ describe PWN::AI::OpenWebUI do
344
344
  expect(described_class).not_to respond_to(:get_plan_usage)
345
345
  end
346
346
  end
347
+
348
+ describe PWN::AI::OpenWebUI, 'binary stream display recovery' do
349
+ let(:previews) { [] }
350
+
351
+ around do |example|
352
+ previous = Thread.current[:pwn_stream_preview]
353
+ Thread.current[:pwn_stream_preview] = ->(*args) { previews << args }
354
+ example.run
355
+ ensure
356
+ Thread.current[:pwn_stream_preview] = previous
357
+ end
358
+
359
+ it 'recovers only visible assistant text, without returning a provider response' do
360
+ event = JSON.generate(message: { role: 'assistant', thinking: 'private', content: 'Café' }, done: true)
361
+ wire = "\uFEFF#{event}".b.freeze
362
+ expect { described_class.send(:assemble_openwebui_stream, body: wire, rest_call: 'ollama/api/chat') }.to raise_error(RuntimeError, /display.only/i)
363
+ expect(previews).to eq([['Open WebUI', 'Café', false]])
364
+ expect(wire.encoding).to eq(Encoding::BINARY)
365
+ end
366
+
367
+ it 'reports an SSE action without displaying its arguments or returning it to the caller' do
368
+ delta = { role: 'assistant', content: 'Résumé', function_call: { name: 'fixture', arguments: 'private' } }
369
+ event = JSON.generate(choices: [{ delta: delta, finish_reason: 'function_call' }])
370
+ wire = "data: #{event}\r\n\r\ndata: [DONE]\r\n\r\n".b
371
+ expect { described_class.send(:assemble_openwebui_stream, body: wire, rest_call: 'api/v1/chat/completions') }.to raise_error(RuntimeError, /display.only/i)
372
+ expect(previews).to eq([['Open WebUI', 'Résumé', true]])
373
+ end
374
+
375
+ it 'does not preview invalid bytes or an incomplete reply' do
376
+ wire = JSON.generate(message: { content: 'Café' }, done: false).b
377
+ expect { described_class.send(:assemble_openwebui_stream, body: wire + "\xFF".b, rest_call: 'ollama/api/chat') }.to raise_error(RuntimeError, /invalid UTF-8/)
378
+ expect { described_class.send(:assemble_openwebui_stream, body: wire, rest_call: 'ollama/api/chat') }.to raise_error(RuntimeError, /incomplete/)
379
+ expect(previews).to be_empty
380
+ end
381
+ end
@@ -100,6 +100,38 @@ end
100
100
  end
101
101
  end
102
102
 
103
+ RSpec.describe provider, 'display-only SSE completeness' do
104
+ let(:assemble) { key == :ollama ? :assemble_ollama_stream : :assemble_openwebui_stream }
105
+ let(:previews) { [] }
106
+ let(:partial) { "data: #{JSON.generate(choices: [{ index: 0, delta: { content: 'Café' } }])}\n\n" }
107
+
108
+ around do |example|
109
+ previous = Thread.current[:pwn_stream_preview]
110
+ Thread.current[:pwn_stream_preview] = ->(*args) { previews << args }
111
+ example.run
112
+ ensure
113
+ Thread.current[:pwn_stream_preview] = previous
114
+ end
115
+
116
+ it 'does not use another choice to finish the displayed text' do
117
+ other = "data: #{JSON.generate(choices: [{ index: 1, delta: {}, finish_reason: 'stop' }])}\n\n"
118
+ expect { described_class.send(assemble, body: (partial + other).b, rest_call: 'v1/chat/completions') }.to raise_error(RuntimeError, /incomplete/i)
119
+ expect(previews).to be_empty
120
+ end
121
+
122
+ it 'honors an error event even when its data is the normal end marker' do
123
+ wire = "#{partial}event: error\ndata: [DONE]\n\n".b
124
+ expect { described_class.send(assemble, body: wire, rest_call: 'v1/chat/completions') }.to raise_error(RuntimeError, /stream error/i)
125
+ expect(previews).to be_empty
126
+ end
127
+
128
+ it 'accepts the displayed choice finishing without a global end marker' do
129
+ finish = "data: #{JSON.generate(choices: [{ index: 0, delta: {}, finish_reason: 'stop' }])}\n\n"
130
+ expect { described_class.send(assemble, body: (partial + finish).b, rest_call: 'v1/chat/completions') }.to raise_error(RuntimeError, /display-only/)
131
+ expect(previews.map { |_, text, pending| [text, pending] }).to eq([['Café', false]])
132
+ end
133
+ end
134
+
103
135
  RSpec.describe provider, 'PR-LOG-01 strict-template history' do
104
136
  include_context 'provider review synthetic stream transport', key
105
137
 
@@ -16,24 +16,7 @@ describe PWN::Cron do
16
16
  expect(help_response).to respond_to :help
17
17
  end
18
18
 
19
- describe 'in-process scheduler' do
20
- before do
21
- @tmp = Dir.mktmpdir('pwn-cron-spec-')
22
- stub_const('PWN::Cron::CRON_DIR', @tmp)
23
- stub_const('PWN::Cron::JOBS_FILE', File.join(@tmp, 'jobs.yml'))
24
- stub_const('PWN::Cron::PID_FILE', File.join(@tmp, 'worker.pid'))
25
- stub_const('PWN::Cron::WORKER_LOG', File.join(@tmp, 'worker.log'))
26
- end
27
-
28
- after do
29
- begin
30
- PWN::Cron.stop_worker
31
- rescue StandardError
32
- nil
33
- end
34
- FileUtils.remove_entry(@tmp) if @tmp && Dir.exist?(@tmp)
35
- end
36
-
19
+ describe 'in-process scheduler', :isolated_cron_store do
37
20
  it 'removes only a schedule without native effects when explicitly requested' do
38
21
  target = described_class.create(name: 'curriculum_practice_nightly', enabled: false, sync_native: false)
39
22
  other = described_class.create(name: 'custom', enabled: false, sync_native: false)
@@ -160,7 +143,6 @@ describe PWN::Cron do
160
143
  schedule: 'every 1s',
161
144
  ruby: "File.write(#{marker.inspect}, Time.now.utc.iso8601)"
162
145
  )
163
- ENV['PWN_CRON_DIR'] = @tmp
164
146
  begin
165
147
  res = PWN::Cron.start_worker(interval: 1, restart: true)
166
148
  expect(res[:started]).to be(true), "worker did not start: #{res.inspect} log=#{begin
@@ -180,7 +162,6 @@ describe PWN::Cron do
180
162
  expect(last).not_to be_nil
181
163
  expect(File).to exist(marker)
182
164
  ensure
183
- ENV.delete('PWN_CRON_DIR')
184
165
  PWN::Cron.stop_worker
185
166
  expect(PWN::Cron.worker_status[:running]).to be false
186
167
  end
@@ -200,25 +181,7 @@ describe PWN::Cron do
200
181
  end
201
182
 
202
183
  describe PWN::Cron do
203
- describe 'OS-agnostic scheduler' do
204
- before do
205
- # install_defaults owns siblings of cron_dir (maintenance/cache/tmp).
206
- # Give it a complete private root, never the shared Dir.tmpdir parent.
207
- @root = Dir.mktmpdir('pwn-cron-os-spec-')
208
- @tmp = File.join(@root, 'cron')
209
- FileUtils.mkdir_p(@tmp)
210
- stub_const('PWN::Cron::CRON_DIR', @tmp)
211
- stub_const('PWN::Cron::JOBS_FILE', File.join(@tmp, 'jobs.yml'))
212
- stub_const('PWN::Cron::PID_FILE', File.join(@tmp, 'worker.pid'))
213
- stub_const('PWN::Cron::WORKER_LOG', File.join(@tmp, 'worker.log'))
214
- ENV['PWN_CRON_DIR'] = @tmp
215
- end
216
-
217
- after do
218
- ENV.delete('PWN_CRON_DIR')
219
- FileUtils.remove_entry(@root) if @root && Dir.exist?(@root)
220
- end
221
-
184
+ describe 'OS-agnostic scheduler', :isolated_cron_store do
222
185
  it 'keeps default housekeeping off every native installer' do
223
186
  allow(described_class).to receive(:scheduler_backend).and_return(:systemd_user)
224
187
  expect(described_class).not_to receive(:systemd_user)
@@ -2766,24 +2766,36 @@ describe 'pwn-ai curses launch' do # rubocop:disable Metrics/BlockLength -- publ
2766
2766
  PWN::Env[:ai][:openai] = { model: 'old', reasoning_effort: 'medium' }
2767
2767
  allow(PWN::Plugins::REPL).to receive(:persist_ai_selection).and_return(false)
2768
2768
  allow(PWN::AI::OpenAI).to receive(:get_models).and_return(data: [{ id: 'gpt-6-astra', supported_reasoning_levels: [{ effort: 'low' }, { effort: 'medium' }, { effort: 'high' }] }])
2769
- allow(PWN::AI::OpenAI).to receive(:chat_with_tools).with(hash_including(reasoning_effort: 'high')) do
2769
+ calls = File.join(@tmp, 'provider-efforts')
2770
+ allow(PWN::AI::OpenAI).to receive(:chat_with_tools) do |opts|
2771
+ File.open(calls, 'a') { |file| file.puts(opts[:reasoning_effort]) }
2770
2772
  { choices: [{ message: { role: 'assistant', content: 'Effort accepted.', tool_calls: [] } }] }
2771
2773
  end
2772
2774
  keys = "/model openai gpt-6-astra\n".chars
2773
- accepted = false
2775
+ @launch_phase = :select_effort
2774
2776
  launch(keys) do
2775
- if !accepted && @paint.any? { |row| row.include?('REASONING EFFORT · SELECT') }
2776
- accepted = true
2777
- keys.concat([:down, "\n"] + "what color is a lemon?\n".chars)
2777
+ case @launch_phase
2778
+ when :select_effort
2779
+ next unless @rendered.any? { |row| row.last.include?('REASONING EFFORT · SELECT') }
2780
+
2781
+ keys.push(:down, "\n")
2782
+ @launch_phase = :wait_for_model
2778
2783
  nil
2779
- elsif @paint.any? { |row| row.include?('Effort accepted.') }
2780
- "\u0004"
2781
- else
2782
- Thread.pass
2784
+ when :wait_for_model
2785
+ # Accepting the prompt does not mean the /model worker has finished.
2786
+ next if @console.send(:busy?)
2787
+
2788
+ expect(PWN::Env.dig(:ai, :openai, :reasoning_effort)).to eq('high')
2789
+ keys.concat("what color is a lemon?\n".chars)
2790
+ @launch_phase = :await_reply
2783
2791
  nil
2792
+ when :await_reply
2793
+ "\u0004" unless @console.send(:busy?)
2784
2794
  end
2785
2795
  end
2786
- expect(PWN::Env.dig(:ai, :openai, :reasoning_effort)).to eq('high')
2796
+ expect(File).to exist(calls), 'The follow-up question did not reach the provider'
2797
+ expect(File.readlines(calls, chomp: true)).to eq(['high'])
2798
+ expect(@paint.join).to include('Effort accepted.')
2787
2799
  end
2788
2800
 
2789
2801
  it 'stops after a forbidden planning request and displays one access warning' do
@@ -2812,6 +2824,62 @@ describe 'pwn-ai curses launch' do # rubocop:disable Metrics/BlockLength -- publ
2812
2824
  expect(events.none? { |type, *| type == :assistant }).to be(true)
2813
2825
  end
2814
2826
 
2827
+ def check_split_stream_preview(engine, adapter, label)
2828
+ require 'rest-client'
2829
+ PWN::Env[:ai] = { active: engine, engine => { model: 'fixture', base_uri: 'https://example.invalid', key: 'fixture-key' }, agent: { toolsets: [], plan_first: false } }
2830
+ calls = File.join(@tmp, 'preview-calls')
2831
+ answer = 'Café — ready.'
2832
+ msg = { role: 'assistant', content: answer, tool_calls: [{ function: { name: 'fixture', arguments: { value: 'private-fixture' } } }] }
2833
+ wire = JSON.generate(message: msg, done: true).b
2834
+ cut = wire.index('é'.b) + 1
2835
+ allow(PWN::AI::Router).to receive(:summarize).and_return('{"title":"Preview","summary":"A text preview."}')
2836
+ allow(adapter).to receive(:chat_with_tools).and_wrap_original do |chat, opts|
2837
+ chat.call(opts.merge(tools: [{ type: 'function', function: { name: 'fixture', parameters: { type: 'object' } } }]))
2838
+ File.open(calls, 'a') { |file| file.puts 'returned to caller' }
2839
+ raise 'Unexpected normal return'
2840
+ end
2841
+ allow(PWN::Plugins::TransparentBrowser).to receive(:open).and_return(browser: RestClient)
2842
+ allow(RestClient::Request).to receive(:execute) do |args|
2843
+ next '{}' if args.fetch(:url).end_with?('/show')
2844
+
2845
+ File.open(calls, 'a') { |file| file.puts 'read' }
2846
+ response = double('offline stream', code: '200')
2847
+ allow(response).to receive(:read_body).and_yield(wire.byteslice(0, cut)).and_yield(wire.byteslice(cut..))
2848
+ args.fetch(:block_response).call(response)
2849
+ end
2850
+ allow(PWN::AI::Agent::Dispatch).to receive(:call) do
2851
+ File.open(calls, 'a') { |file| file.puts 'unexpected dispatch' }
2852
+ raise 'Action must not be dispatched'
2853
+ end
2854
+ launch("what color is a lemon?\n".chars) { "\u0004" unless @console.send(:busy?) }
2855
+ events = @console.instance_variable_get(:@timeline)
2856
+ expect(events.filter_map { |type, text, *| text if type == :assistant }).to contain_exactly(answer)
2857
+ expect(events.filter_map { |type, text, *| text if type == :warning }).to contain_exactly(a_string_matching(/#{Regexp.escape(label)}.*action.*not processed/i))
2858
+ expect(events.to_s).not_to include('private-fixture')
2859
+ expect(File.readlines(calls, chomp: true)).to eq(['read'])
2860
+ end
2861
+
2862
+ it 'shows a split UTF-8 Open WebUI preview once without returning actions to the worker' do
2863
+ check_split_stream_preview(:openwebui, PWN::AI::OpenWebUI, 'Open WebUI')
2864
+ end
2865
+
2866
+ it 'shows a split UTF-8 Ollama preview once without returning actions to the worker' do
2867
+ check_split_stream_preview(:ollama, PWN::AI::Ollama, 'Ollama')
2868
+ end
2869
+
2870
+ it 'states that instructions in preview text were not run even without structured actions' do
2871
+ console = PWN::Plugins::REPL::AIConsole::Console.new(pry: Pry.new, input: StringIO.new, curses: nil, getch: nil)
2872
+ events = []
2873
+ text = 'Please highlight the word café.'
2874
+ wire = JSON.generate(message: { role: 'assistant', content: text }, done: true).b
2875
+ expect do
2876
+ console.send(:with_stream_preview, events) do
2877
+ PWN::AI::OpenWebUI.send(:assemble_openwebui_stream, body: wire, rest_call: 'ollama/api/chat')
2878
+ end
2879
+ end.to raise_error(PWN::Plugins::REPL::AIConsole::Control::PreviewShown, /No actions from this reply were processed/)
2880
+ expect(events).to eq([[:assistant, text]])
2881
+ end
2882
+
2815
2883
  it 'delivers and saves a split UTF-8 text reply in a session with debugging off' do
2816
2884
  require 'rest-client'
2817
2885
  PWN::Env[:ai] = { active: :ollama, ollama: { model: 'fixture', base_uri: 'https://example.invalid' }, agent: { toolsets: [], plan_first: false } }
@@ -30,18 +30,13 @@ describe PWN::Setup do
30
30
  expect(PWN::Setup).to respond_to(:ensure_cron)
31
31
  end
32
32
 
33
- it 'ensure_cron seeds defaults and starts (or reuses) the worker' do
34
- tmp = Dir.mktmpdir('pwn-setup-cron-')
35
- stub_const('PWN::Cron::CRON_DIR', tmp)
36
- stub_const('PWN::Cron::JOBS_FILE', File.join(tmp, 'jobs.yml'))
37
- stub_const('PWN::Cron::PID_FILE', File.join(tmp, 'worker.pid'))
38
- stub_const('PWN::Cron::WORKER_LOG', File.join(tmp, 'worker.log'))
39
- ENV['PWN_CRON_DIR'] = tmp
33
+ it 'ensure_cron seeds defaults and starts (or reuses) the worker', :isolated_cron_store do
40
34
  allow(PWN::Cron).to receive(:install_worker_crontab).and_return('stubbed')
41
35
  io = StringIO.new
42
36
  first = PWN::Setup.ensure_cron(restart: false, io: io)
43
37
  expect(first[:ok]).to be true
44
38
  expect(first[:worker][:running]).to be true
39
+ expect(File).to exist(File.join(Dir.home, '.pwn', 'maintenance', 'background.json'))
45
40
  pid = first[:worker][:pid]
46
41
  expect(pid).to be_a(Integer)
47
42
  second = PWN::Setup.ensure_cron(restart: false, io: StringIO.new)
@@ -55,11 +50,9 @@ describe PWN::Setup do
55
50
  rescue StandardError
56
51
  nil
57
52
  end
58
- ENV.delete('PWN_CRON_DIR')
59
- FileUtils.remove_entry(tmp) if tmp && Dir.exist?(tmp)
60
53
  end
61
54
 
62
- it 'ensure_cron dry_run does not spawn' do
55
+ it 'ensure_cron dry_run does not spawn', :isolated_cron_store do
63
56
  io = StringIO.new
64
57
  allow(PWN::Cron).to receive(:worker_status).and_return(
65
58
  running: false, pid: nil, pid_file: '/tmp/x', log: '/tmp/y'
@@ -68,13 +61,7 @@ describe PWN::Setup do
68
61
  expect(res[:dry_run]).to be true
69
62
  expect(res[:ok]).to be true
70
63
  end
71
- it 'ensure_cron enabled:false disables only the internal worker without native changes' do
72
- tmp = Dir.mktmpdir('pwn-setup-nocron-')
73
- stub_const('PWN::Cron::CRON_DIR', tmp)
74
- stub_const('PWN::Cron::JOBS_FILE', File.join(tmp, 'jobs.yml'))
75
- stub_const('PWN::Cron::PID_FILE', File.join(tmp, 'worker.pid'))
76
- stub_const('PWN::Cron::WORKER_LOG', File.join(tmp, 'worker.log'))
77
- ENV['PWN_CRON_DIR'] = tmp
64
+ it 'ensure_cron enabled:false disables only the internal worker without native changes', :isolated_cron_store do
78
65
  io = StringIO.new
79
66
  expect(PWN::Cron).not_to receive(:install_scheduler)
80
67
  expect(PWN::Cron).not_to receive(:uninstall_scheduler)
@@ -92,8 +79,6 @@ describe PWN::Setup do
92
79
  rescue StandardError
93
80
  nil
94
81
  end
95
- ENV.delete('PWN_CRON_DIR')
96
- FileUtils.remove_entry(tmp) if tmp && Dir.exist?(tmp)
97
82
  end
98
83
 
99
84
  it 'bin/pwn_setup exposes --[no-]cron' do
@@ -3,6 +3,33 @@
3
3
  require 'tmpdir'
4
4
  require 'fileutils'
5
5
 
6
+ # Cron installs and polls maintenance state beside cron/, not inside it.
7
+ RSpec.shared_context 'isolated cron store' do
8
+ around do |example|
9
+ previous_home, previous_cron = ENV.values_at('HOME', 'PWN_CRON_DIR')
10
+ Dir.mktmpdir('pwn-cron-spec-') do |home|
11
+ @root = File.join(home, '.pwn')
12
+ @tmp = File.join(@root, 'cron')
13
+ FileUtils.mkdir_p(@tmp)
14
+ example.run
15
+ ensure
16
+ ENV['PWN_CRON_DIR'] = previous_cron
17
+ ENV['HOME'] = previous_home
18
+ end
19
+ end
20
+
21
+ before do
22
+ stub_const('PWN::Cron::CRON_DIR', @tmp)
23
+ stub_const('PWN::Cron::JOBS_FILE', File.join(@tmp, 'jobs.yml'))
24
+ stub_const('PWN::Cron::PID_FILE', File.join(@tmp, 'worker.pid'))
25
+ stub_const('PWN::Cron::WORKER_LOG', File.join(@tmp, 'worker.log'))
26
+ ENV['HOME'] = File.dirname(@root)
27
+ ENV['PWN_CRON_DIR'] = @tmp
28
+ end
29
+ end
30
+
31
+ RSpec.configure { |config| config.include_context 'isolated cron store', :isolated_cron_store }
32
+
6
33
  # ─────────────────────────────────────────────────────────────────────────────
7
34
  # shared_context 'pwn tmp sandbox'
8
35
  #
@@ -1552,6 +1552,9 @@
1552
1552
  {"messages":[{"role":"user","content":"PWN::AI::ServerTools.route Usage"},{"role":"assistant","content":"`PWN::AI::ServerTools.route`: "}]}
1553
1553
  {"messages":[{"role":"user","content":"PWN::AI::ServerTools.selected Usage"},{"role":"assistant","content":"`PWN::AI::ServerTools.selected`: "}]}
1554
1554
  {"messages":[{"role":"user","content":"PWN::AI::ServerTools.wire Usage"},{"role":"assistant","content":"`PWN::AI::ServerTools.wire`: Supported Method Parameters\n\nobjects = PWN::AI::ServerTools.wire(\n\nengine: 'required - provider name',\nnames: 'required - hosted tool names such as web_search or google_search'\n\n)\n"}]}
1555
+ {"messages":[{"role":"user","content":"PWN::AI::StreamPreview.new Usage"},{"role":"assistant","content":"`PWN::AI::StreamPreview.new`: "}]}
1556
+ {"messages":[{"role":"user","content":"PWN::AI::StreamPreview.display! Usage"},{"role":"assistant","content":"`PWN::AI::StreamPreview.display!`: "}]}
1557
+ {"messages":[{"role":"user","content":"PWN::AI::StreamPreview.required? Usage"},{"role":"assistant","content":"`PWN::AI::StreamPreview.required?`: "}]}
1555
1558
  {"messages":[{"role":"user","content":"PWN::AWS.authors Usage"},{"role":"assistant","content":"`PWN::AWS.authors`: Author(s)\n\n0day Inc. <support@0dayinc.com>\n"}]}
1556
1559
  {"messages":[{"role":"user","content":"PWN::AWS.help Usage"},{"role":"assistant","content":"`PWN::AWS.help`: "}]}
1557
1560
  {"messages":[{"role":"user","content":"PWN::AWS::ACM.authors Usage"},{"role":"assistant","content":"`PWN::AWS::ACM.authors`: Author(s)\n\n0day Inc. <support@0dayinc.com>\n"}]}
@@ -3712,6 +3715,7 @@
3712
3715
  {"messages":[{"role":"user","content":"PWN::Plugins::REPL::AIConsole::Console.toggle_verbose Usage"},{"role":"assistant","content":"`PWN::Plugins::REPL::AIConsole::Console.toggle_verbose`: "}]}
3713
3716
  {"messages":[{"role":"user","content":"PWN::Plugins::REPL::AIConsole::Console.tone Usage"},{"role":"assistant","content":"`PWN::Plugins::REPL::AIConsole::Console.tone`: "}]}
3714
3717
  {"messages":[{"role":"user","content":"PWN::Plugins::REPL::AIConsole::Console.width Usage"},{"role":"assistant","content":"`PWN::Plugins::REPL::AIConsole::Console.width`: "}]}
3718
+ {"messages":[{"role":"user","content":"PWN::Plugins::REPL::AIConsole::Console.with_stream_preview Usage"},{"role":"assistant","content":"`PWN::Plugins::REPL::AIConsole::Console.with_stream_preview`: "}]}
3715
3719
  {"messages":[{"role":"user","content":"PWN::Plugins::REPL::AIConsole::Console.wrap Usage"},{"role":"assistant","content":"`PWN::Plugins::REPL::AIConsole::Console.wrap`: "}]}
3716
3720
  {"messages":[{"role":"user","content":"PWN::Plugins::REPL::AIConsole::Console.wrap_command Usage"},{"role":"assistant","content":"`PWN::Plugins::REPL::AIConsole::Console.wrap_command`: "}]}
3717
3721
  {"messages":[{"role":"user","content":"PWN::Plugins::REPL::AIConsole::Control.checkpoint Usage"},{"role":"assistant","content":"`PWN::Plugins::REPL::AIConsole::Control.checkpoint`: "}]}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pwn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.802
4
+ version: 0.5.804
5
5
  platform: ruby
6
6
  authors:
7
7
  - 0day Inc.
@@ -592,7 +592,7 @@ dependencies:
592
592
  -
593
593
  - "="
594
594
  - !ruby/object:Gem::Version
595
- version: 0.0.193
595
+ version: 0.0.194
596
596
  type: :development
597
597
  prerelease: false
598
598
  version_requirements: !ruby/object:Gem::Requirement
@@ -600,7 +600,7 @@ dependencies:
600
600
  -
601
601
  - "="
602
602
  - !ruby/object:Gem::Version
603
- version: 0.0.193
603
+ version: 0.0.194
604
604
  - !ruby/object:Gem::Dependency
605
605
  name: metasm
606
606
  requirement: !ruby/object:Gem::Requirement
@@ -1024,7 +1024,7 @@ dependencies:
1024
1024
  -
1025
1025
  - "="
1026
1026
  - !ruby/object:Gem::Version
1027
- version: 7.2.0
1027
+ version: 7.3.1
1028
1028
  type: :development
1029
1029
  prerelease: false
1030
1030
  version_requirements: !ruby/object:Gem::Requirement
@@ -1032,7 +1032,7 @@ dependencies:
1032
1032
  -
1033
1033
  - "="
1034
1034
  - !ruby/object:Gem::Version
1035
- version: 7.2.0
1035
+ version: 7.3.1
1036
1036
  - !ruby/object:Gem::Dependency
1037
1037
  name: rqrcode
1038
1038
  requirement: !ruby/object:Gem::Requirement
@@ -1200,7 +1200,7 @@ dependencies:
1200
1200
  -
1201
1201
  - "="
1202
1202
  - !ruby/object:Gem::Version
1203
- version: 0.157.0
1203
+ version: 0.158.0
1204
1204
  type: :runtime
1205
1205
  prerelease: false
1206
1206
  version_requirements: !ruby/object:Gem::Requirement
@@ -1208,7 +1208,7 @@ dependencies:
1208
1208
  -
1209
1209
  - "="
1210
1210
  - !ruby/object:Gem::Version
1211
- version: 0.157.0
1211
+ version: 0.158.0
1212
1212
  - !ruby/object:Gem::Dependency
1213
1213
  name: selenium-webdriver
1214
1214
  requirement: !ruby/object:Gem::Requirement
@@ -1216,7 +1216,7 @@ dependencies:
1216
1216
  -
1217
1217
  - "="
1218
1218
  - !ruby/object:Gem::Version
1219
- version: 4.53.0
1219
+ version: 4.54.0
1220
1220
  type: :runtime
1221
1221
  prerelease: false
1222
1222
  version_requirements: !ruby/object:Gem::Requirement
@@ -1224,7 +1224,7 @@ dependencies:
1224
1224
  -
1225
1225
  - "="
1226
1226
  - !ruby/object:Gem::Version
1227
- version: 4.53.0
1227
+ version: 4.54.0
1228
1228
  - !ruby/object:Gem::Dependency
1229
1229
  name: slack-ruby-client
1230
1230
  requirement: !ruby/object:Gem::Requirement