rubik 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ATTRIBUTION.md +1 -1
- data/CHANGELOG.md +250 -43
- data/README.md +5 -1
- data/lib/rubik/adapter/base.rb +21 -1
- data/lib/rubik/adapter/generic.rb +0 -14
- data/lib/rubik/adapter/node.rb +2 -0
- data/lib/rubik/adapter/process.rb +28 -67
- data/lib/rubik/ast/treesitter/zig_walker.rb +15 -2
- data/lib/rubik/benchmark/vakanuvis_adoption.rb +10 -3
- data/lib/rubik/buffer/apply_contract.rb +3 -3
- data/lib/rubik/buffer/apply_transaction.rb +165 -0
- data/lib/rubik/buffer/manager.rb +26 -120
- data/lib/rubik/cli/workspace_trust.rb +16 -0
- data/lib/rubik/config/deep_ops.rb +4 -1
- data/lib/rubik/config/defaults.rb +29 -3
- data/lib/rubik/config/schema.rb +8 -0
- data/lib/rubik/config/secret_policy.rb +197 -0
- data/lib/rubik/config/store.rb +14 -0
- data/lib/rubik/config.rb +11 -0
- data/lib/rubik/diagnostics/collector.rb +0 -9
- data/lib/rubik/errors.rb +15 -0
- data/lib/rubik/event_bus.rb +2 -1
- data/lib/rubik/kernel/dispatcher.rb +16 -11
- data/lib/rubik/kernel/unit.rb +4 -1
- data/lib/rubik/llm/registry.rb +12 -9
- data/lib/rubik/llm/router.rb +2 -5
- data/lib/rubik/log.rb +23 -1
- data/lib/rubik/lsp/client.rb +152 -445
- data/lib/rubik/lsp/document_store.rb +209 -0
- data/lib/rubik/lsp/manager.rb +14 -10
- data/lib/rubik/lsp/transport.rb +365 -0
- data/lib/rubik/mcp/boot_lifecycle.rb +6 -2
- data/lib/rubik/mcp/boot_run.rb +190 -0
- data/lib/rubik/mcp/client.rb +4 -3
- data/lib/rubik/mcp/manager.rb +46 -165
- data/lib/rubik/mcp/transport/stdio.rb +55 -10
- data/lib/rubik/orchestrator/auto_apply.rb +4 -3
- data/lib/rubik/orchestrator/continuation_manager.rb +3 -22
- data/lib/rubik/orchestrator/goal_session.rb +519 -0
- data/lib/rubik/orchestrator/loop.rb +28 -47
- data/lib/rubik/orchestrator/maestro_gate.rb +5 -7
- data/lib/rubik/orchestrator/provider_recovery.rb +4 -2
- data/lib/rubik/orchestrator/provider_resolver.rb +4 -2
- data/lib/rubik/orchestrator/resume_window.rb +96 -0
- data/lib/rubik/orchestrator/shell_deps.rb +16 -0
- data/lib/rubik/orchestrator/stream_manager.rb +2 -1
- data/lib/rubik/orchestrator/subagent/deferred_spec.rb +4 -1
- data/lib/rubik/orchestrator/subagent/instance.rb +11 -12
- data/lib/rubik/orchestrator/subagent/journal.rb +2 -1
- data/lib/rubik/orchestrator/subagent/lifecycle.rb +3 -1
- data/lib/rubik/orchestrator/subagent/questioner.rb +24 -7
- data/lib/rubik/orchestrator/subagent/reaper.rb +3 -5
- data/lib/rubik/orchestrator/subagent/resilience.rb +4 -2
- data/lib/rubik/orchestrator/subagent/result_archive.rb +0 -4
- data/lib/rubik/orchestrator/subagent/run_cycle.rb +2 -7
- data/lib/rubik/orchestrator/subagent/spawn_transaction.rb +11 -2
- data/lib/rubik/orchestrator/subagent/step_runner.rb +11 -3
- data/lib/rubik/orchestrator/subagent/teardown.rb +4 -0
- data/lib/rubik/orchestrator/subagent/transcript_formatter.rb +2 -1
- data/lib/rubik/orchestrator/subagent/type_definition.rb +0 -4
- data/lib/rubik/orchestrator/tool_timeout.rb +121 -1
- data/lib/rubik/orchestrator.rb +1 -0
- data/lib/rubik/platform/io_drain.rb +2 -1
- data/lib/rubik/platform/process.rb +144 -54
- data/lib/rubik/platform.rb +17 -1
- data/lib/rubik/plugin/manager.rb +2 -1
- data/lib/rubik/plugin/storage.rb +20 -29
- data/lib/rubik/repl/commands/agent_context.rb +9 -8
- data/lib/rubik/repl/commands/agent_execution.rb +20 -502
- data/lib/rubik/repl/commands/agent_models.rb +4 -3
- data/lib/rubik/repl/commands/agent_providers.rb +43 -2
- data/lib/rubik/repl/commands/base.rb +47 -2
- data/lib/rubik/repl/commands/buffer.rb +6 -5
- data/lib/rubik/repl/commands/lsp.rb +3 -2
- data/lib/rubik/repl/commands/pruner.rb +2 -1
- data/lib/rubik/repl/commands/secrets.rb +151 -0
- data/lib/rubik/repl/commands/workspace.rb +60 -150
- data/lib/rubik/repl/commands/workspace_approval.rb +209 -0
- data/lib/rubik/repl/config_wiring.rb +3 -3
- data/lib/rubik/repl/hooks.rb +2 -1
- data/lib/rubik/repl/input_execution.rb +158 -76
- data/lib/rubik/repl/input_loop.rb +3 -2
- data/lib/rubik/repl/lifecycle.rb +82 -204
- data/lib/rubik/repl/notice_router.rb +319 -0
- data/lib/rubik/repl/paste_support.rb +3 -1
- data/lib/rubik/repl/presentation.rb +5 -3
- data/lib/rubik/repl/pruner/gate.rb +3 -1
- data/lib/rubik/repl/pruner/harness.rb +2 -1
- data/lib/rubik/repl/shell.rb +4 -3
- data/lib/rubik/repl/turn_recorder.rb +6 -5
- data/lib/rubik/runtime/discovery.rb +3 -2
- data/lib/rubik/runtime/loop_service.rb +4 -3
- data/lib/rubik/runtime/manifest_store.rb +124 -0
- data/lib/rubik/runtime/overlay_guard.rb +127 -0
- data/lib/rubik/runtime/overlay_storage.rb +269 -272
- data/lib/rubik/runtime/task_manager.rb +71 -27
- data/lib/rubik/runtime.rb +1 -0
- data/lib/rubik/sandbox/driver/docker.rb +5 -1
- data/lib/rubik/sandbox/runner.rb +16 -15
- data/lib/rubik/security/allowlist.rb +167 -0
- data/lib/rubik/security/audit_log.rb +72 -0
- data/lib/rubik/security/classifier/classifier.rb +8 -0
- data/lib/rubik/security/command_gate.rb +591 -0
- data/lib/rubik/security/guard.rb +94 -1077
- data/lib/rubik/security/path_policy.rb +117 -0
- data/lib/rubik/security/secret_store.rb +463 -0
- data/lib/rubik/security/synthesis_gate.rb +297 -0
- data/lib/rubik/security.rb +5 -0
- data/lib/rubik/session/manager.rb +7 -1
- data/lib/rubik/skills/manager.rb +2 -3
- data/lib/rubik/storage/ranking.rb +113 -0
- data/lib/rubik/storage/search.rb +49 -0
- data/lib/rubik/storage/store.rb +15 -112
- data/lib/rubik/storage/transcript_indexer.rb +2 -3
- data/lib/rubik/storage/vakanuvis/harness.rb +2 -3
- data/lib/rubik/tools/base.rb +22 -0
- data/lib/rubik/tools/builtins/files.rb +3 -15
- data/lib/rubik/tools/builtins/grep.rb +3 -9
- data/lib/rubik/tools/builtins/lifecycle.rb +96 -92
- data/lib/rubik/tools/builtins/synthesis.rb +3 -0
- data/lib/rubik/tools/lifecycle_rollbacks.rb +100 -0
- data/lib/rubik/tools/native_search.rb +2 -1
- data/lib/rubik/tools/truncator.rb +73 -36
- data/lib/rubik/ui/banner.rb +4 -3
- data/lib/rubik/ui/spinner.rb +3 -1
- data/lib/rubik/ui/statusline.rb +6 -5
- data/lib/rubik/version.rb +1 -1
- data/lib/rubik.rb +1 -2
- metadata +23 -1
data/lib/rubik/repl/lifecycle.rb
CHANGED
|
@@ -2,9 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative "../events"
|
|
4
4
|
require_relative "../log"
|
|
5
|
+
require_relative "../platform"
|
|
6
|
+
require_relative "../storage/layout"
|
|
5
7
|
require_relative "../orchestrator/subagent/notices"
|
|
6
8
|
require_relative "../prompt/conversation_rows"
|
|
7
9
|
require_relative "pending_notice_queue"
|
|
10
|
+
require_relative "notice_router"
|
|
8
11
|
|
|
9
12
|
module Rubik
|
|
10
13
|
module REPL
|
|
@@ -12,14 +15,27 @@ module Rubik
|
|
|
12
15
|
# (keeps shell.rb under the decoupling line-count gate). The Shell remains
|
|
13
16
|
# the coordinator: these methods depend on shell identity, so they live in
|
|
14
17
|
# an included module rather than in Composition (the pure builder).
|
|
18
|
+
#
|
|
19
|
+
# Issue #469: the notice-routing half (MCP boot notices, subagent event
|
|
20
|
+
# routing, reactive wakeup state) now lives in NoticeRouter; the methods
|
|
21
|
+
# below delegate to a lazily-created router so the public Shell surface
|
|
22
|
+
# (and the bare-Lifecycle test-double harnesses) stay unchanged. The
|
|
23
|
+
# router owns the queue/mutex/token concurrency state.
|
|
15
24
|
module Lifecycle
|
|
16
|
-
# Plan 109 Faz B: notice kinds worth interrupting the idle prompt
|
|
17
|
-
#
|
|
18
|
-
# (
|
|
19
|
-
#
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
#
|
|
25
|
+
# Plan 109 Faz B: notice kinds worth interrupting the idle prompt —
|
|
26
|
+
# vocabulary now owned by NoticeRouter; re-exported here because
|
|
27
|
+
# callers (and silence-contract tests) pin Rubik::REPL::Lifecycle::
|
|
28
|
+
# WAKE_KINDS.
|
|
29
|
+
WAKE_KINDS = NoticeRouter::WAKE_KINDS
|
|
30
|
+
|
|
31
|
+
# The notice-routing collaborator (issue #469): lazily created so bare
|
|
32
|
+
# Lifecycle test doubles (which set plain ivars, no constructor) keep
|
|
33
|
+
# working; the router reads host state live via instance_variable_get.
|
|
34
|
+
def notice_router
|
|
35
|
+
@notice_router ||= NoticeRouter.new(self)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Plan 1, Phase 1: assign built subsystems. Entries derive from the
|
|
23
39
|
# ServiceCatalog (the single declaration point): one loop assigns every
|
|
24
40
|
# injectable entry's ivar, then a second pass runs the per-entry
|
|
25
41
|
# after_inject hooks (injected-buffer post-wiring — which runs only on
|
|
@@ -56,11 +72,11 @@ module Rubik
|
|
|
56
72
|
def load_plugins(parts)
|
|
57
73
|
return unless @plugin_manager
|
|
58
74
|
|
|
59
|
-
Array(@config
|
|
60
|
-
if @config
|
|
75
|
+
Array(Rubik::Storage::Layout.config_get(@config, "plugins.load", [])).each { |g| @plugin_manager.load_plugin_gem(g, runtime_manager: @runtime_manager) }
|
|
76
|
+
if Rubik::Storage::Layout.config_get(@config, "plugins.autoload_dropin", true) && parts.respond_to?(:plugin_storage) && parts.plugin_storage
|
|
61
77
|
@plugin_manager.load_dropin_plugins(runtime_manager: @runtime_manager, storage: parts.plugin_storage)
|
|
62
78
|
end
|
|
63
|
-
aliases_cfg = @config
|
|
79
|
+
aliases_cfg = Rubik::Storage::Layout.config_get(@config, "plugins.aliases", {})
|
|
64
80
|
aliases_cfg.each { |s, f| @plugin_manager.register_alias(s, f) } if aliases_cfg.is_a?(Hash)
|
|
65
81
|
end
|
|
66
82
|
|
|
@@ -143,6 +159,9 @@ module Rubik
|
|
|
143
159
|
# never forces async warm in tests.
|
|
144
160
|
warm_async = Platform.async_knob(@config, "ast.async_warm")
|
|
145
161
|
maybe_warn_huge_root!
|
|
162
|
+
# Boot accumulated config problems (unknown keys, corrupt YAML, legacy
|
|
163
|
+
# env vars) surface here — same notices seam, still before the banner.
|
|
164
|
+
maybe_emit_config_warnings!
|
|
146
165
|
# A strong huge-root signal skips the boot warm walk: the index
|
|
147
166
|
# stays empty and tools answer the honest not-ready message until
|
|
148
167
|
# an explicit '!context scan' opts in. Warning only — never a block.
|
|
@@ -183,7 +202,7 @@ module Rubik
|
|
|
183
202
|
# '!context scan' (strong_only: false). Memoized so the scan reuses
|
|
184
203
|
# the assessment without a second git spawn.
|
|
185
204
|
def maybe_warn_huge_root!(strong_only: true)
|
|
186
|
-
return unless @config.nil? || @config
|
|
205
|
+
return unless @config.nil? || Rubik::Storage::Layout.config_get(@config, "context.huge_root_notice", true)
|
|
187
206
|
return if @huge_root_notice_shown
|
|
188
207
|
|
|
189
208
|
assessment = huge_root_assessment
|
|
@@ -193,11 +212,7 @@ module Rubik
|
|
|
193
212
|
return if guidance.empty?
|
|
194
213
|
|
|
195
214
|
@huge_root_notice_shown = true
|
|
196
|
-
|
|
197
|
-
@terminal_guard.print_safe_notice(guidance)
|
|
198
|
-
else
|
|
199
|
-
@output&.puts guidance
|
|
200
|
-
end
|
|
215
|
+
NoticeRouter.print_safe_notice_line(@terminal_guard, @output, guidance)
|
|
201
216
|
end
|
|
202
217
|
|
|
203
218
|
def huge_root_assessment
|
|
@@ -216,238 +231,100 @@ module Rubik
|
|
|
216
231
|
|
|
217
232
|
def huge_root_boot_scan_skipped?
|
|
218
233
|
return false unless huge_root_assessment.strong
|
|
219
|
-
return false unless @config.respond_to?(:fetch)
|
|
220
234
|
|
|
221
|
-
|
|
235
|
+
!Rubik::Storage::Layout.config_get(@config, "context.boot_scan_on_huge_root", false)
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
# Boot-time config observability (issue #399): Config#warnings
|
|
239
|
+
# accumulates unknown-key, corrupt-YAML, ~/.rubik and env-deprecation
|
|
240
|
+
# problems during load with no reader; this surfaces them through the
|
|
241
|
+
# notices seam right after the huge-root check, before the banner.
|
|
242
|
+
# Once per REPL process boot — warnings appended later in the session
|
|
243
|
+
# (runtime set()) stay in the array for !config/tests without printing.
|
|
244
|
+
# Rubik::Log.warn mirrors each notice so headless/scripted boots see
|
|
245
|
+
# them on stderr too.
|
|
246
|
+
def maybe_emit_config_warnings!
|
|
247
|
+
warnings = @config&.warnings
|
|
248
|
+
return if warnings.nil? || warnings.empty?
|
|
249
|
+
return if @config_warnings_shown
|
|
250
|
+
|
|
251
|
+
@config_warnings_shown = true
|
|
252
|
+
warnings.each do |w|
|
|
253
|
+
line = "⚠ Config: #{w}"
|
|
254
|
+
Rubik::Log.warn(:config, line)
|
|
255
|
+
NoticeRouter.print_safe_notice_line(@terminal_guard, @output, line)
|
|
256
|
+
end
|
|
222
257
|
end
|
|
223
258
|
|
|
224
|
-
#
|
|
225
|
-
#
|
|
226
|
-
#
|
|
227
|
-
#
|
|
228
|
-
|
|
259
|
+
# --- Notice routing (issue #469): thin delegation to NoticeRouter ----
|
|
260
|
+
# The router owns the queue/mutex/token concurrency state; these
|
|
261
|
+
# delegators keep the historical Shell surface (and the bare-Lifecycle
|
|
262
|
+
# test-double harnesses that include this module) unchanged.
|
|
263
|
+
|
|
264
|
+
# Async MCP boot progress notices (mcp-async-boot D8). See
|
|
265
|
+
# NoticeRouter#wire_mcp_boot_notices!.
|
|
229
266
|
def wire_mcp_boot_notices!(async:)
|
|
230
|
-
|
|
231
|
-
return if @mcp_notice_tokens # idempotent re-wire
|
|
232
|
-
|
|
233
|
-
ctx = @runtime_manager&.context
|
|
234
|
-
return unless ctx.respond_to?(:on_dispose)
|
|
235
|
-
|
|
236
|
-
@mcp_notice_tokens = [
|
|
237
|
-
[:mcp_server_loaded, @event_bus.subscribe(:mcp_server_loaded) { |payload| print_mcp_boot_notice(:loaded, payload) }],
|
|
238
|
-
[:mcp_server_failed, @event_bus.subscribe(:mcp_server_failed) { |payload| print_mcp_boot_notice(:failed, payload) }]
|
|
239
|
-
]
|
|
240
|
-
ctx.on_dispose do
|
|
241
|
-
@mcp_notice_tokens&.each { |(event, token)| @event_bus.unsubscribe(event, token) }
|
|
242
|
-
@mcp_notice_tokens = nil
|
|
243
|
-
end
|
|
267
|
+
notice_router.wire_mcp_boot_notices!(async: async)
|
|
244
268
|
end
|
|
245
269
|
|
|
246
|
-
# Same kworker-thread contract as handle_subagent_event: no shell locks,
|
|
247
|
-
# drop silently when the UI is not up yet (an instant boot failure is
|
|
248
|
-
# still on stderr and in dmesg). Pure display line — never enters the
|
|
249
|
-
# conversation history and never wakes an idle turn.
|
|
250
270
|
def print_mcp_boot_notice(state, payload)
|
|
251
|
-
|
|
252
|
-
return unless payload.is_a?(Hash)
|
|
253
|
-
|
|
254
|
-
name = payload[:server]
|
|
255
|
-
line = if state == :loaded
|
|
256
|
-
"mcp: server '#{name}' ready (#{payload[:tools] || 0} tools)"
|
|
257
|
-
else
|
|
258
|
-
"mcp: server '#{name}' failed (#{payload[:error]})"
|
|
259
|
-
end
|
|
260
|
-
@terminal_guard&.print_safe_notice(line)
|
|
271
|
+
notice_router.print_mcp_boot_notice(state, payload)
|
|
261
272
|
end
|
|
262
273
|
|
|
263
274
|
def wire_subagent_events!
|
|
264
|
-
|
|
265
|
-
return if @subagent_event_tokens # idempotent re-wire (RenderService precedent)
|
|
266
|
-
|
|
267
|
-
# Inverse-by-construction: subscribe only where the unsubscribe
|
|
268
|
-
# inverse can be registered in the same breath (AGENTS.md §1A).
|
|
269
|
-
ctx = @runtime_manager&.context
|
|
270
|
-
return unless ctx.respond_to?(:on_dispose)
|
|
271
|
-
|
|
272
|
-
@subagent_notices_mutex = Mutex.new
|
|
273
|
-
@subagent_notices = []
|
|
274
|
-
# Plan 109: the idle-turn wake flag, eagerly initialized BEFORE any
|
|
275
|
-
# subscription exists so handlers never race its construction.
|
|
276
|
-
@pending_notice_queue = PendingNoticeQueue.new
|
|
277
|
-
tokens = Rubik::Orchestrator::Subagent::Notices::EVENTS.keys.map do |event|
|
|
278
|
-
[event, @event_bus.subscribe(event) { |payload| handle_subagent_event(event, payload) }]
|
|
279
|
-
end
|
|
280
|
-
tokens << [Rubik::Events::UNIT_STATE_CHANGED, @event_bus.subscribe(Rubik::Events::UNIT_STATE_CHANGED) { |payload| handle_unit_event(payload) }]
|
|
281
|
-
tokens << [Rubik::Events::SUBAGENT_MESSAGE_TO_PARENT, @event_bus.subscribe(Rubik::Events::SUBAGENT_MESSAGE_TO_PARENT) { |payload| handle_parent_message(payload) }]
|
|
282
|
-
@subagent_event_tokens = tokens
|
|
283
|
-
ctx.on_dispose do
|
|
284
|
-
@subagent_event_tokens&.each { |(event, token)| @event_bus.unsubscribe(event, token) }
|
|
285
|
-
@subagent_event_tokens = nil
|
|
286
|
-
end
|
|
275
|
+
notice_router.wire_subagent_events!
|
|
287
276
|
end
|
|
288
277
|
|
|
289
|
-
# ONE routing seam for subagent notices (Candidate 02, unified for
|
|
290
|
-
# Plan 109): bus event -> normalized notice -> channel-split
|
|
291
|
-
# delivery. Called on the kworker thread (bus dispatch is
|
|
292
|
-
# synchronous): Queue pushes, the standby Mutex, and the guard
|
|
293
|
-
# monitor only — no shell locks. Model channel (structured hash)
|
|
294
|
-
# enters the active loop queue and is rendered to XML at drain
|
|
295
|
-
# time; user channel (terminal line) is buffered to stdout while a
|
|
296
|
-
# loop is active and flushed at turn end. Between turns the notice
|
|
297
|
-
# is injected into @conversation_history, printed, and — when
|
|
298
|
-
# wake-worthy — queued to owe agent-0 an autonomous notice turn.
|
|
299
278
|
def handle_subagent_event(event_name, payload)
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
notice = Rubik::Orchestrator::Subagent::Notices.normalize(event_name, payload)
|
|
303
|
-
route_subagent_notice(notice) if notice
|
|
279
|
+
notice_router.handle_subagent_event(event_name, payload)
|
|
304
280
|
end
|
|
305
281
|
|
|
306
282
|
def handle_unit_event(payload)
|
|
307
|
-
|
|
308
|
-
return unless payload.is_a?(Hash)
|
|
309
|
-
|
|
310
|
-
type = payload[:type]&.to_sym
|
|
311
|
-
return unless [:process, :task].include?(type)
|
|
312
|
-
|
|
313
|
-
to_state = payload[:to_state]&.to_sym
|
|
314
|
-
return unless [:completed, :failed].include?(to_state)
|
|
315
|
-
|
|
316
|
-
route_subagent_notice({ kind: :task, id: payload[:unit_id], role: "Background Task", state: to_state.to_s, reason: payload[:reason] })
|
|
283
|
+
notice_router.handle_unit_event(payload)
|
|
317
284
|
end
|
|
318
285
|
|
|
319
286
|
def handle_parent_message(payload)
|
|
320
|
-
|
|
321
|
-
return unless payload.is_a?(Hash)
|
|
322
|
-
|
|
323
|
-
route_subagent_notice({ kind: :message, id: payload[:sender_id] || "subagent",
|
|
324
|
-
role: "Subagent", state: "message", reason: payload[:message].to_s })
|
|
287
|
+
notice_router.handle_parent_message(payload)
|
|
325
288
|
end
|
|
326
289
|
|
|
327
290
|
def route_subagent_notice(notice)
|
|
328
|
-
|
|
329
|
-
if @active_loop
|
|
330
|
-
@active_loop.enqueue_subagent_notice(notice) if @active_loop.respond_to?(:enqueue_subagent_notice)
|
|
331
|
-
@subagent_notices_mutex&.synchronize { @subagent_notices << line }
|
|
332
|
-
else
|
|
333
|
-
inject_subagent_notice_into_conversation_history!(notice)
|
|
334
|
-
if @terminal_guard
|
|
335
|
-
@terminal_guard.print_safe_notice(line)
|
|
336
|
-
else
|
|
337
|
-
@output.puts "\n#{line}"
|
|
338
|
-
end
|
|
339
|
-
# Wakeloop fix 2026-10-09: an event landing inside an AUTONOMOUS
|
|
340
|
-
# turn's idle-path windows (before @active_loop is set, or in the
|
|
341
|
-
# ensure tail after it is cleared) must not arm a follow-up wake —
|
|
342
|
-
# that is the probabilistic residue of the chained-auto-turn bug.
|
|
343
|
-
# History injection and the printed line above still happen (no
|
|
344
|
-
# loss); only the synthetic Enter is withheld. A fresh event at a
|
|
345
|
-
# genuinely idle prompt (@autonomous_turn false) wakes as designed.
|
|
346
|
-
request_reactive_wakeup!(notice) unless @autonomous_turn
|
|
347
|
-
end
|
|
291
|
+
notice_router.route_subagent_notice(notice)
|
|
348
292
|
end
|
|
349
293
|
|
|
350
|
-
# Plan 109 Faz B: the reactive wake composition — vocabulary policy
|
|
351
|
-
# (WAKE_KINDS), kill-switch (subagents.reactive_wakeup config),
|
|
352
|
-
# state (PendingNoticeQueue), mechanism (TerminalGuard#safe_wakeup!).
|
|
353
|
-
# Every wake-worthy enqueue attempts the kick (no empty->non-empty
|
|
354
|
-
# coalescing): a kick refused earlier (user typing / paste
|
|
355
|
-
# collection) must retry on the next event, or the wake would wait
|
|
356
|
-
# for a manual Enter. TerminalGuard re-verifies emptiness under its
|
|
357
|
-
# monitor, so a typing user is never disturbed, and a surplus
|
|
358
|
-
# injected Enter degrades to the :empty noop. Runs on the kworker
|
|
359
|
-
# thread: queue push and the guard monitor only.
|
|
360
294
|
def request_reactive_wakeup!(notice)
|
|
361
|
-
|
|
362
|
-
return unless notice.is_a?(Hash) && WAKE_KINDS.include?(notice[:kind])
|
|
363
|
-
|
|
364
|
-
pending_notice_queue.enqueue(notice)
|
|
365
|
-
@terminal_guard&.safe_wakeup!
|
|
295
|
+
notice_router.request_reactive_wakeup!(notice)
|
|
366
296
|
end
|
|
367
297
|
|
|
368
298
|
def reactive_wakeup_enabled?
|
|
369
|
-
|
|
299
|
+
notice_router.reactive_wakeup_enabled?
|
|
370
300
|
end
|
|
371
301
|
|
|
372
|
-
# Eager init happens in wire_subagent_events! (before any
|
|
373
|
-
# subscription exists); the lazy fallback keeps bare Lifecycle test
|
|
374
|
-
# doubles working (SubagentNoticeInbox mold).
|
|
375
302
|
def pending_notice_queue
|
|
376
|
-
|
|
303
|
+
notice_router.pending_notice_queue
|
|
377
304
|
end
|
|
378
305
|
|
|
379
306
|
def pending_wake_notices?
|
|
380
|
-
|
|
307
|
+
notice_router.pending_wake_notices?
|
|
381
308
|
end
|
|
382
309
|
|
|
383
310
|
def drain_pending_wake_notices!
|
|
384
|
-
|
|
311
|
+
notice_router.drain_pending_wake_notices!
|
|
385
312
|
end
|
|
386
313
|
|
|
387
|
-
# Staleness rule: any real turn's context already includes the
|
|
388
|
-
# idle-injected notices in @conversation_history — a surviving
|
|
389
|
-
# pending wake would turn the next stray Enter into a redundant
|
|
390
|
-
# notice turn.
|
|
391
314
|
def clear_pending_wake_notices!
|
|
392
|
-
|
|
315
|
+
notice_router.clear_pending_wake_notices!
|
|
393
316
|
end
|
|
394
317
|
|
|
395
318
|
def inject_subagent_notice_into_conversation_history!(notice)
|
|
396
|
-
|
|
397
|
-
@conversation_history ||= []
|
|
398
|
-
Rubik::Prompt::ConversationRows.append_notice!(@conversation_history, xml_payload)
|
|
319
|
+
notice_router.inject_subagent_notice_into_conversation_history!(notice)
|
|
399
320
|
end
|
|
400
321
|
|
|
401
322
|
def flush_subagent_notices!
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
notices = @subagent_notices_mutex.synchronize do
|
|
405
|
-
list = @subagent_notices.dup
|
|
406
|
-
@subagent_notices.clear
|
|
407
|
-
list
|
|
408
|
-
end
|
|
409
|
-
return if notices.empty?
|
|
410
|
-
|
|
411
|
-
if @terminal_guard
|
|
412
|
-
notices.each { |m| @terminal_guard.print_safe_notice(m) }
|
|
413
|
-
else
|
|
414
|
-
@output.puts ""
|
|
415
|
-
notices.each { |m| @output.puts m }
|
|
416
|
-
end
|
|
323
|
+
notice_router.flush_subagent_notices!
|
|
417
324
|
end
|
|
418
325
|
|
|
419
|
-
# Session review B3 (turn-loss fix): Loop's drain runs at the TOP of each
|
|
420
|
-
# step, so notices landing during the final step stranded in the loop
|
|
421
|
-
# inbox at turn end — the user channel flushed a line, but the model
|
|
422
|
-
# channel never entered history and no wake was owed (Plan 109's
|
|
423
|
-
# documented "late-notice asymmetry" accepted the loss; a live session
|
|
424
|
-
# showed it costs a whole turn). Called from execute_free_text's ensure
|
|
425
|
-
# AFTER @active_loop = nil: the notices are injected into
|
|
426
|
-
# @conversation_history (visible to the next turn) and wake-worthy kinds
|
|
427
|
-
# arm the reactive wake, exactly like the idle-path branch of
|
|
428
|
-
# route_subagent_notice. Runs on the turn thread. Per-notice rescue is
|
|
429
|
-
# the ensure block's own contract ("cleanup must never mask the
|
|
430
|
-
# in-flight exception") — and a raising notice must not strand its
|
|
431
|
-
# queue-mates that drain_all already popped.
|
|
432
|
-
#
|
|
433
|
-
# arm_wake: false keeps the model-channel delivery but does NOT fire a
|
|
434
|
-
# synthetic Enter (wakeloop fix 2026-10-09): an INTERRUPTED turn and an
|
|
435
|
-
# AUTONOMOUS notice turn settle instead of re-arming — otherwise every
|
|
436
|
-
# stranded notice chains another auto-turn (the prompt never returns)
|
|
437
|
-
# and the cycle survives Ctrl+C.
|
|
438
326
|
def deliver_stranded_loop_notices!(loop_instance, arm_wake: true)
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
loop_instance.subagent_notice_inbox.drain_all.each do |notice|
|
|
442
|
-
inject_subagent_notice_into_conversation_history!(notice)
|
|
443
|
-
request_reactive_wakeup!(notice) if arm_wake
|
|
444
|
-
rescue StandardError => e
|
|
445
|
-
# Load-bearing visibility (wakeloop fix 2026-10-09): this delivery
|
|
446
|
-
# is the fix's "no loss" guarantee, so a dropped notice may not
|
|
447
|
-
# vanish behind the ENV-gated debug_warn. Unconditional, non-raising.
|
|
448
|
-
Rubik::Log.warn(:repl, "stranded notice delivery failed (#{notice[:kind].inspect}): " \
|
|
449
|
-
"#{e.class}: #{e.message}")
|
|
450
|
-
end
|
|
327
|
+
notice_router.deliver_stranded_loop_notices!(loop_instance, arm_wake: arm_wake)
|
|
451
328
|
end
|
|
452
329
|
|
|
453
330
|
def reap_dead_kernel_units!
|
|
@@ -460,12 +337,13 @@ module Rubik
|
|
|
460
337
|
# Audit 1: ENV["RUBIK_DEBUG"]-gated logging for intentionally swallowed
|
|
461
338
|
# exceptions (convention from config/store.rb). Never raises.
|
|
462
339
|
#
|
|
463
|
-
#
|
|
464
|
-
#
|
|
340
|
+
# Delegates to Platform.debug_warn (issue #452): the platform channel is
|
|
341
|
+
# the ONE home of RUBIK_DEBUG-gated debug warnings — Log.debug is gated
|
|
342
|
+
# by RUBIK_LOG_LEVEL instead, so reusing the sanctioned platform sink
|
|
343
|
+
# keeps this channel's exact semantics ([WARN] prefix, audible under
|
|
344
|
+
# $VERBOSE=nil, silent unless RUBIK_DEBUG is set, error-isolated).
|
|
465
345
|
def debug_warn(msg)
|
|
466
|
-
|
|
467
|
-
rescue StandardError
|
|
468
|
-
nil
|
|
346
|
+
Rubik::Platform.debug_warn(msg)
|
|
469
347
|
end
|
|
470
348
|
end
|
|
471
349
|
end
|