rubik 0.9.1 → 0.11.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.
Files changed (138) hide show
  1. checksums.yaml +4 -4
  2. data/ATTRIBUTION.md +1 -1
  3. data/CHANGELOG.md +203 -1
  4. data/lib/rubik/adapter/base.rb +2 -1
  5. data/lib/rubik/adapter/process.rb +28 -67
  6. data/lib/rubik/ast/extractor.rb +2 -1
  7. data/lib/rubik/ast/treesitter_extractor.rb +2 -1
  8. data/lib/rubik/benchmark/vakanuvis_adoption.rb +12 -4
  9. data/lib/rubik/buffer/apply_contract.rb +3 -3
  10. data/lib/rubik/buffer/apply_transaction.rb +165 -0
  11. data/lib/rubik/buffer/manager.rb +26 -120
  12. data/lib/rubik/config/deep_ops.rb +4 -1
  13. data/lib/rubik/config/defaults.rb +6 -3
  14. data/lib/rubik/config/schema.rb +8 -0
  15. data/lib/rubik/config/secret_policy.rb +198 -0
  16. data/lib/rubik/config/store.rb +2 -1
  17. data/lib/rubik/config.rb +13 -2
  18. data/lib/rubik/context/ignore_rules.rb +193 -0
  19. data/lib/rubik/context/scanner.rb +46 -161
  20. data/lib/rubik/diagnostics/collector.rb +0 -9
  21. data/lib/rubik/errors.rb +15 -0
  22. data/lib/rubik/event_bus.rb +2 -1
  23. data/lib/rubik/kernel/dispatcher.rb +12 -7
  24. data/lib/rubik/kernel/unit.rb +4 -1
  25. data/lib/rubik/llm/client.rb +6 -200
  26. data/lib/rubik/llm/connection_pool.rb +104 -0
  27. data/lib/rubik/llm/registry.rb +13 -9
  28. data/lib/rubik/llm/router.rb +2 -5
  29. data/lib/rubik/llm/sse_parser.rb +110 -0
  30. data/lib/rubik/log.rb +21 -0
  31. data/lib/rubik/lsp/circuit_breaker.rb +98 -0
  32. data/lib/rubik/lsp/client.rb +77 -273
  33. data/lib/rubik/lsp/client_provisioner.rb +49 -0
  34. data/lib/rubik/lsp/manager.rb +67 -96
  35. data/lib/rubik/lsp/transport.rb +365 -0
  36. data/lib/rubik/mcp/boot_lifecycle.rb +6 -2
  37. data/lib/rubik/mcp/boot_run.rb +190 -0
  38. data/lib/rubik/mcp/manager.rb +55 -166
  39. data/lib/rubik/mcp/transport/stdio.rb +4 -1
  40. data/lib/rubik/orchestrator/auto_apply.rb +8 -6
  41. data/lib/rubik/orchestrator/continuation_manager.rb +3 -22
  42. data/lib/rubik/orchestrator/goal_ledger/ledger.rb +12 -1
  43. data/lib/rubik/orchestrator/goal_ledger/schema_vocabulary.rb +38 -0
  44. data/lib/rubik/orchestrator/goal_ledger/xml_render.rb +6 -1
  45. data/lib/rubik/orchestrator/goal_ledger.rb +1 -0
  46. data/lib/rubik/orchestrator/goal_session.rb +53 -39
  47. data/lib/rubik/orchestrator/loop.rb +28 -47
  48. data/lib/rubik/orchestrator/lsp_feedback.rb +1 -1
  49. data/lib/rubik/orchestrator/maestro_gate.rb +5 -7
  50. data/lib/rubik/orchestrator/provider_recovery.rb +4 -2
  51. data/lib/rubik/orchestrator/provider_resolver.rb +4 -2
  52. data/lib/rubik/orchestrator/resume_window.rb +96 -0
  53. data/lib/rubik/orchestrator/shell_deps.rb +16 -0
  54. data/lib/rubik/orchestrator/step_executor.rb +2 -1
  55. data/lib/rubik/orchestrator/stream_manager.rb +2 -1
  56. data/lib/rubik/orchestrator/subagent/deferred_spec.rb +4 -1
  57. data/lib/rubik/orchestrator/subagent/instance.rb +7 -12
  58. data/lib/rubik/orchestrator/subagent/lifecycle.rb +3 -1
  59. data/lib/rubik/orchestrator/subagent/notices.rb +2 -2
  60. data/lib/rubik/orchestrator/subagent/questioner.rb +3 -1
  61. data/lib/rubik/orchestrator/subagent/reaper.rb +3 -5
  62. data/lib/rubik/orchestrator/subagent/resilience.rb +4 -2
  63. data/lib/rubik/orchestrator/subagent/result_archive.rb +0 -4
  64. data/lib/rubik/orchestrator/subagent/run_cycle.rb +2 -7
  65. data/lib/rubik/orchestrator/subagent/spawn_transaction.rb +11 -2
  66. data/lib/rubik/orchestrator/subagent/step_runner.rb +10 -2
  67. data/lib/rubik/orchestrator/subagent/transcript_formatter.rb +2 -1
  68. data/lib/rubik/orchestrator/subagent/type_definition.rb +0 -4
  69. data/lib/rubik/orchestrator/tool_timeout.rb +121 -1
  70. data/lib/rubik/platform/io_drain.rb +5 -2
  71. data/lib/rubik/platform/process.rb +144 -54
  72. data/lib/rubik/platform.rb +2 -1
  73. data/lib/rubik/plugin/manager.rb +2 -1
  74. data/lib/rubik/plugin/storage.rb +8 -8
  75. data/lib/rubik/repl/commands/agent_context.rb +8 -7
  76. data/lib/rubik/repl/commands/agent_execution.rb +13 -32
  77. data/lib/rubik/repl/commands/agent_models.rb +4 -3
  78. data/lib/rubik/repl/commands/agent_providers.rb +43 -2
  79. data/lib/rubik/repl/commands/base.rb +47 -2
  80. data/lib/rubik/repl/commands/buffer.rb +5 -4
  81. data/lib/rubik/repl/commands/lsp.rb +2 -1
  82. data/lib/rubik/repl/commands/pruner.rb +2 -1
  83. data/lib/rubik/repl/commands/secrets.rb +151 -0
  84. data/lib/rubik/repl/commands/workspace.rb +60 -150
  85. data/lib/rubik/repl/commands/workspace_approval.rb +209 -0
  86. data/lib/rubik/repl/config_wiring.rb +8 -6
  87. data/lib/rubik/repl/hooks.rb +2 -1
  88. data/lib/rubik/repl/input_execution.rb +162 -79
  89. data/lib/rubik/repl/input_loop.rb +2 -1
  90. data/lib/rubik/repl/lifecycle.rb +60 -210
  91. data/lib/rubik/repl/notice_router.rb +319 -0
  92. data/lib/rubik/repl/paste_support.rb +3 -1
  93. data/lib/rubik/repl/presentation.rb +5 -3
  94. data/lib/rubik/repl/pruner/gate.rb +3 -1
  95. data/lib/rubik/repl/pruner/harness.rb +2 -1
  96. data/lib/rubik/repl/shell.rb +4 -3
  97. data/lib/rubik/repl/tee_io.rb +2 -1
  98. data/lib/rubik/repl/turn_recorder.rb +6 -5
  99. data/lib/rubik/runtime/ast_service.rb +2 -1
  100. data/lib/rubik/runtime/discovery.rb +3 -2
  101. data/lib/rubik/runtime/loop_service.rb +4 -3
  102. data/lib/rubik/runtime/manifest_store.rb +9 -1
  103. data/lib/rubik/runtime/overlay_guard.rb +127 -0
  104. data/lib/rubik/runtime/overlay_storage.rb +109 -163
  105. data/lib/rubik/runtime/task_manager.rb +64 -25
  106. data/lib/rubik/sandbox/driver/docker.rb +5 -1
  107. data/lib/rubik/sandbox/runner.rb +21 -19
  108. data/lib/rubik/security/audit_log.rb +2 -1
  109. data/lib/rubik/security/command_gate.rb +126 -243
  110. data/lib/rubik/security/guard.rb +7 -3
  111. data/lib/rubik/security/secret_store.rb +492 -0
  112. data/lib/rubik/security/segment_report.rb +161 -0
  113. data/lib/rubik/security/synthesis_gate.rb +8 -11
  114. data/lib/rubik/session/manager.rb +7 -1
  115. data/lib/rubik/session/recorder.rb +2 -1
  116. data/lib/rubik/skills/manager.rb +4 -4
  117. data/lib/rubik/storage/search.rb +49 -0
  118. data/lib/rubik/storage/store.rb +13 -20
  119. data/lib/rubik/storage/transcript_indexer.rb +3 -2
  120. data/lib/rubik/storage/vakanuvis/harness.rb +2 -3
  121. data/lib/rubik/storage/vakanuvis.rb +2 -1
  122. data/lib/rubik/tools/base.rb +22 -0
  123. data/lib/rubik/tools/builtins/files.rb +3 -15
  124. data/lib/rubik/tools/builtins/goal_ledger.rb +12 -1
  125. data/lib/rubik/tools/builtins/grep.rb +1 -6
  126. data/lib/rubik/tools/builtins/lifecycle.rb +6 -5
  127. data/lib/rubik/tools/builtins/synthesis.rb +3 -3
  128. data/lib/rubik/tools/lifecycle_rollbacks.rb +14 -1
  129. data/lib/rubik/tools/preflight_runner.rb +2 -1
  130. data/lib/rubik/tools/truncator.rb +48 -36
  131. data/lib/rubik/tools/uri_resolver.rb +3 -2
  132. data/lib/rubik/ui/banner.rb +4 -3
  133. data/lib/rubik/ui/capability.rb +1 -0
  134. data/lib/rubik/ui/spinner.rb +3 -1
  135. data/lib/rubik/ui/statusline.rb +6 -5
  136. data/lib/rubik/version.rb +1 -1
  137. data/lib/rubik.rb +4 -5
  138. metadata +20 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4978b3f5f55209ac3558f5d2a82651b0e9f2d56571ebb33cb65a8b488f2689b0
4
- data.tar.gz: 4b430b94ecdc22c7f5b75756f9bd23f0eadf544a0ecf760c8fa5a8c14c99bcc0
3
+ metadata.gz: c51c73960cae7dc1fc2f89745c3261cc1d4693bbde7c449175f5c16b8f076bbd
4
+ data.tar.gz: 7f570e596aafd7ad9b82d634ef9a38d739e027eb2a7c50b613c2b97be5850c6b
5
5
  SHA512:
6
- metadata.gz: acf9faccdcfdb6a344bfc3e1aa8b7f3c316d42a14b6c65766bf2d9b9c728378a312022c7b4195542abeb62fd7319af72d17cd207ec3b69435cbaa8d807bac94b
7
- data.tar.gz: 88b8c7bd853a932860ad009a06e9f3e1b505e72049d4b09ac911f07fa0ecdaf6320b145dd1f67e2b48488c02fff4dae2b3562806e1b0601bf2e59c3c74233924
6
+ metadata.gz: ab509129d3f7f20498535c0b51f48e1a902af9484108eb0c12f3f8c13cc5010e1a359f6474aca6742dd09a16e4dded9645ab41b844afbea5eb01b41e7a09725e
7
+ data.tar.gz: 40430100af1ca2a9049ace43864ea82d3dcfad72e005ac1698fe71c5b0a7585e56b32f59a22aea1e7339ea689dd569e346f2f540273ac633e5cfd409c9c1386c
data/ATTRIBUTION.md CHANGED
@@ -121,7 +121,7 @@ SOFTWARE.
121
121
  | **`strings-ansi`** | Piotr Murach | MIT | ANSI-aware string truncation and alignment for REPL formatters. |
122
122
  | **`reline`** | Hiroshi SHIBATA & Ruby Team | Ruby License / BSD-2-Clause | Line-editing, history navigation, autocompletion hooks, and headless terminal adaptation. |
123
123
  | **`prism`** | Kevin Newton & Ruby Core Team | MIT | High-performance Ruby parsing and AST extraction ([`Rubik::AST::RubyExtractor`](lib/rubik/ast/ruby_extractor.rb)). |
124
- | **`minitest`** | Ryan Davis & seattlerb | MIT | Fast, modular test suite powering Rubik's 4,400+ unit, integration, and contract tests. |
124
+ | **`minitest`** | Ryan Davis & seattlerb | MIT | Fast, modular test suite powering Rubik's 4,600+ unit, integration, and contract tests. |
125
125
  | **`rubocop`** | Bozhidar Batsov & contributors | MIT | Static code analysis, style enforcement, and architectural hygiene gates. |
126
126
  | **`benchmark`, `logger`, `pstore`, `reline`, `fiddle`** | Ruby core / rubygems teams | Ruby License / BSD-2-Clause | Ruby stdlib gems pinned explicitly in `rubik.gemspec` as they are unbundled from the default set in Ruby 3.4/3.5. |
127
127
 
data/CHANGELOG.md CHANGED
@@ -6,6 +6,206 @@ commits, 2026-08-23 → 2026-10-09, see `git log`).
6
6
 
7
7
  The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
8
8
 
9
+ ## [0.11.0] - 2026-11-16
10
+
11
+ The schema-grammar minor: the goal-ledger stops teaching its schema through
12
+ failure — the bounded-retry protocol's rejection hints no longer carry the
13
+ only copy of the grammar, which is now derived from `Ledger::PRODUCTION_SCHEMA`
14
+ and surfaced on every static model-facing surface — while the extraction wave
15
+ keeps sweeping (an SSE parser and connection pool out of the LLM client, a
16
+ segment report out of the command gate, a circuit breaker out of the LSP
17
+ manager, an ignore-rules value object out of the context scanner), duplicated
18
+ invariants collapse onto single homes, the remaining `Kernel#warn` sites move
19
+ onto `Rubik::Log`, and the secret-store backends get hardened against IO
20
+ failures.
21
+
22
+ ### Added
23
+
24
+ - **Goal-ledger schema grammar on static surfaces (#494):** a single-line
25
+ grammar summary derived from `Ledger::PRODUCTION_SCHEMA` (schema SSOT, never
26
+ hand-written) now appears in the `update_goal_ledger` tool description, as a
27
+ state-independent `<vocabulary>` element on the Sigma XML page, and in the
28
+ patch-budget-exhausted feedback — so a model no longer has to burn its
29
+ rejection budget to learn the status enum, the required id, or the
30
+ section-append rule. The exhaustion contract stays verbatim and rejection
31
+ reasons are deliberately not cached.
32
+
33
+ ### Changed
34
+
35
+ - **Remaining `Kernel#warn` call sites migrate onto `Rubik::Log` (#510):**
36
+ all user-facing diagnostic emissions route through the sanctioned
37
+ `Log.warn(:subsystem, message)` seam with message content (including
38
+ `[WARN]`/`[SECURITY]`/`[DEPRECATION]`/`[BOOTSTRAP]` prefixes) preserved
39
+ verbatim; only the two sanctioned `$stderr` sites remain.
40
+ - **SegmentReport extracted from CommandGate (#508).**
41
+ - **SSEParser and ConnectionPool split out of the LLM client (#505).**
42
+ - **IgnoreRules value object extracted from the context Scanner (#498).**
43
+ - **LSP circuit breaker and client provisioning extracted from Manager
44
+ (#497).**
45
+ - **Duplicated invariants single-homed (#502):** SSEParser's two drain loops
46
+ collapse into `drain_complete_events(final:)`, `post_stream_json` reuses
47
+ `parse_and_validate_uri`, the MCP D5 boot gate resolves through one
48
+ `boot_gate_open?` predicate, the Scanner's reserved-root rejections back
49
+ onto one `reserved_root?`, and the two EXTENSION_MAPs get cross-reference
50
+ comments so their deliberate divergence stays explicit.
51
+
52
+ ### Fixed
53
+
54
+ - **Isolated `capability.rb` loads require `repl/tee_io` (#509):** an isolated
55
+ load no longer NameErrors.
56
+ - **Three small goal-ledger and secret-policy defects (#496):** XmlRender
57
+ escapes the finding `source_step` attribute (a corrupted suspend row could
58
+ inject raw text into the conversation-history XML), `Ledger#update`
59
+ validates patches inside the monitor, and SecretPolicy drops an unreachable
60
+ store-failure guard.
61
+ - **SecretStore command backends hardened against IO failures (#495):**
62
+ `IOError`/`SystemCallError` convert to `SecretStore::Error`, the stdin
63
+ payload travels through `Platform.write_until` with a 5s deadline instead of
64
+ parking `Config#set` on a full pipe buffer, the Linux backend clears prior
65
+ items before storing (a re-set secret previously resolved to a corrupted
66
+ concatenation), and the macOS reader keeps significant whitespace.
67
+
68
+ ## [0.10.0] - 2026-11-15
69
+
70
+ The secret-store minor: provider credentials leave the config files for the
71
+ OS secret store (Keychain, Credential Manager, secret-service) behind
72
+ `rubik-secret:` pointers with a project-scope plaintext guard and a `!secrets`
73
+ command, abandoned tool workers get an opt-in grace-then-kill reaper — while
74
+ the extraction wave continues its sweep across the config dialects, the buffer
75
+ apply transaction, the storage search pipeline, the LSP JSON-RPC transport,
76
+ the MCP boot choreography, and the REPL lifecycle, and a robustness round
77
+ closes silent failures and unbounded pipe writes.
78
+
79
+ ### Added
80
+
81
+ - **Secret store for provider credentials (#493):** plaintext
82
+ `providers.<name>.api_key` values are no longer written to config files.
83
+ Writes are routed to the OS secret store (macOS Keychain via `security`,
84
+ Windows Credential Manager via PowerShell PasswordVault, Linux secret-service
85
+ via `secret-tool`) and the config file keeps only a `rubik-secret:` pointer
86
+ that resolves lazily at provider build time; an owner-only (0600)
87
+ `~/.rubik/secrets.yml` file store is the honest fallback when no OS keyring
88
+ is available. The `!secrets` command (`backend | list | has | delete |
89
+ migrate`) reports statuses without printing values and migrates legacy
90
+ plaintext keys in place.
91
+ - **`tools.timeout_kill_after` grace-then-kill reaper (#458):** an abandoned
92
+ tool-call worker (its join budget expired, the result discarded) can now be
93
+ reaped: when the knob is set, the worker is registered with a reaper thread
94
+ and `Thread#kill`ed after the grace period, with the kill logged under
95
+ `:tools`; workers that finish during grace are left to the existing
96
+ late-completion log. Default nil = OFF, byte-identical to the current
97
+ pure-abandonment behavior; invalid values warn and stay off.
98
+
99
+ ### Changed
100
+
101
+ - **Nil-safe config-fetch dialects converge on `Layout.config_get`
102
+ (#438, #489, #490, #491):** three hand-rolled dialects (respond_to? ternaries,
103
+ private fetch_cfg/safe_config copies) collapse onto the existing single home,
104
+ so a dotted knob resolves identically whichever file reads it; the two
105
+ deliberate nil/false-preserving fetches stay untouched per their ruling
106
+ comments.
107
+ - **Project-scoped secrets refused by default (#493):** `!config set
108
+ providers.x.api_key … --project` and project-scoped provider writes holding
109
+ plaintext keys fail with guidance (`--global`, `api_key_env`, or
110
+ `!secrets migrate`) — project config files live inside the repository and
111
+ leak through commits. The schema-backed `security.allow_project_secrets`
112
+ flag restores the legacy behavior, resolved from operator trust only (a
113
+ project config cannot enable it for itself). Project-scope store names carry
114
+ a `.project` suffix so the two scopes can never swap each other's credential;
115
+ `!config get/list`, the `!config set` echo, and `!provider set` no longer
116
+ display secret values; untrusted-workspace filtering now also drops the
117
+ `providers` section.
118
+ - **Truncator kept-window accounting single-homed (#439):** the four copies
119
+ of the six-step byte-budget cut + scrub + omitted-accounting block collapse
120
+ behind `clamp_head`/`clamp_tail`/`window_result` with the two sanctioned
121
+ notice spellings pinned byte-identical.
122
+ - **Traversal and file-not-found disclosures single-homed on BaseTool
123
+ (#440):** `traversal_blocked_message` and `file_not_found_message` own the
124
+ allowed-roots construction and the twin fuzzy-matching blocks that
125
+ list_files/grep_search/read_file/replace_file_content each hand-copied.
126
+ - **Adapter-command execution helpers single-homed on Commands::Base (#441):**
127
+ the pre-execution auto-apply choreography, the adapter fallback selection,
128
+ and the failure-diagnostic rendering that !test/!lint/!format/!sh each
129
+ carried move behind `pre_execution_apply`/`adapter_for`/`render_diagnostic`
130
+ with the pinned message wording byte-identical.
131
+ - **Guard/trust plane split out of OverlayStorage (#465):** path containment
132
+ and trust/bootstrap screening move verbatim into `Runtime::OverlayGuard`
133
+ (127 LOC) with the injected-guard kwarg seam preserved and the Kind adapter
134
+ merged into the single class body; OverlayStorage drops 623 → 558 LOC.
135
+ - **REPL lifecycle's notice routing extracted into NoticeRouter (#469, #485):**
136
+ the MCP boot notices, subagent event routing, and reactive-wakeup half of
137
+ lifecycle.rb move into `REPL::NoticeRouter` with the queue/mutex/token state
138
+ owned there and the safe-notice-print fallback single-homed; the Shell
139
+ public surface is unchanged.
140
+ - **LSP JSON-RPC transport extracted from Client (#470, #484):** process
141
+ spawn/teardown, the framing reader thread, request/response correlation, and
142
+ the sanitized spawn environment move into `LSP::Transport` (~700-LOC Client
143
+ split), with `shutdown` the exact LIFO inverse of spawn; the typed LSP
144
+ protocol API stays on Client.
145
+ - **Buffer apply transaction extracted (#472, #483):** the two-phase apply
146
+ (atomic writes, external-conflict detection, TOCTOU containment re-check,
147
+ structured `ApplyFailedError`) moves into `Buffer::ApplyTransaction`; the
148
+ Manager public API and last_* recording contracts are unchanged.
149
+ - **Storage search pipeline's pure text layer extracted (#473, #482):**
150
+ `Storage::Search` owns tokenization, haystack construction, and the
151
+ token-AND candidate gate; `Store#search`/`#search_ranked` delegate with
152
+ identical scoring, ordering, and tie-breaking.
153
+ - **WorkspaceApproval value object extracted (#474, #487)** and the Loop-side
154
+ goal-resume window concentrated into `Orchestrator::ResumeWindow` (#475,
155
+ #486) — ctx.extend lifecycle, the cross-process history prefix, and the
156
+ goal_resumed marker discipline become testable without running a turn.
157
+ - **MCP boot choreography threaded through a BootRun object (#460):** entries /
158
+ connected / outcomes / boot_epoch stop travelling as mutable side-channel
159
+ parameters; the absence-owes-stop rule becomes the named `owes_stop?`
160
+ predicate; monitor-hold boundaries and epoch gates are verbatim, manager.rb
161
+ drops 639 → 515 lines.
162
+ - **The dual popen3 + reader-thread implementations single-homed (#461)** and
163
+ `execute_free_text` split into named phases on InputExecution (#462) with
164
+ statement order, messages, and history mutation preserved verbatim.
165
+ - **The four unrelated StateError classes unified under `Rubik::StateError`
166
+ (#463):** one rescue target for state-machine violations while keeping the
167
+ module-qualified names, and six bare `raise "string"` sites on public APIs
168
+ typed under `Rubik::Error` with one small class per module.
169
+ - **Direct `$stderr` writes routed through Rubik::Log (#455, #467):** only the
170
+ two sanctioned sites write $stderr directly; overlay bootstrap refusals and
171
+ the synthesis-gate downgrade warn emit via `Log.warn(:security)`, and the
172
+ constructor-default loggers gain `Rubik::Log.forwarder(subsystem)` so they
173
+ respect `RUBIK_LOG_LEVEL` and the single-line format.
174
+ - **`verify_command_safety!` split into named phases (#457):** the 165-LOC
175
+ orchestrator reads as the AST fast-path condition, the fail-closed allowlist
176
+ valve, the three block sites, and the interactive-approval step; decisions,
177
+ messages, and audit events unchanged.
178
+ - **The shared goal-resume choreography extracted from GoalSession (#459)**,
179
+ white-box test coupling reduced across the worst offenders (#464, #476,
180
+ #488, #492), direct unit coverage added for OverlayGuard, BootRun, and
181
+ Platform::Process (#478) and the input_execution phases (#477, #481), and
182
+ raw-sleep cooldown assertions replaced with bounded polling (#456).
183
+
184
+ ### Fixed
185
+
186
+ - **send_input pipe write bounded and the start registration window closed
187
+ (#466):** a child that stops reading stdin can no longer deadlock kill,
188
+ status, logs, and process shutdown — the write happens outside the manager
189
+ monitor with a deadline-bounded `Platform.write_until` loop, and a failure
190
+ between spawn and task registration now rolls back by killing the child.
191
+ - **Review-sweep robustness gaps closed (#468):** the kernel dispatcher's
192
+ stopped-check + queue-push is atomic under the lock (no more stranded events
193
+ wedging sync_drain), the LSP did_* rescues log instead of silently returning
194
+ false, the MCP stdio child-died diagnostic captures the pid before teardown,
195
+ and kill_tree gives TERM a bounded 200ms grace window before KILL escalates.
196
+ - **popen_capture wall clock bounded by a deadline watchdog (#479, #480):**
197
+ the kill now always lands before the join — a deadline breach kills the
198
+ child tree first and raises `Timeout::Error` only after the popen3 block
199
+ returns, instead of racing the unwind.
200
+ - **Silent-failure health sweep closed (#443):** corrupt JSON lines dropped
201
+ during session restore are logged with their line number, the at_exit sweep
202
+ is error-isolated per manager, a failed `docker rm -f` in the ensure warns
203
+ instead of vanishing, and five grep-verified dead methods are deleted.
204
+ - **Late completion of an abandoned tool worker logged (#442):** the worker's
205
+ ensure records an honest warn — which tool, how long the call took, and
206
+ whether it finished with a raise or a discarded result — closing the
207
+ observability gap while the budget still bounds turn latency.
208
+
9
209
  ## [0.9.1] - 2026-11-14
10
210
 
11
211
  The hardening-and-single-homing patch: overlay commands seal their default
@@ -1529,7 +1729,9 @@ installation section.
1529
1729
  - Context: serialized index mutations, snapshot-outside-lock reconcile,
1530
1730
  streaming-first truncation.
1531
1731
 
1532
- [Unreleased]: https://github.com/ozgurulukir/rubik/compare/v0.9.1...HEAD
1732
+ [Unreleased]: https://github.com/ozgurulukir/rubik/compare/v0.11.0...HEAD
1733
+ [0.11.0]: https://github.com/ozgurulukir/rubik/compare/v0.10.0...v0.11.0
1734
+ [0.10.0]: https://github.com/ozgurulukir/rubik/compare/v0.9.1...v0.10.0
1533
1735
  [0.9.1]: https://github.com/ozgurulukir/rubik/compare/v0.9.0...v0.9.1
1534
1736
  [0.9.0]: https://github.com/ozgurulukir/rubik/compare/v0.8.1...v0.9.0
1535
1737
  [0.8.1]: https://github.com/ozgurulukir/rubik/compare/v0.8.0...v0.8.1
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "shellwords"
4
4
  require_relative "process"
5
+ require_relative "../storage/layout"
5
6
  require_relative "../platform"
6
7
  require_relative "../runtime/discovery"
7
8
  require_relative "../runtime/diagnostic_engine"
@@ -62,7 +63,7 @@ module Rubik
62
63
  return unavailable_result(reason: reason)
63
64
  end
64
65
 
65
- eff_timeout = (timeout || (@config.respond_to?(:fetch) ? @config.fetch("test.timeout", 30) : 30) || 30).to_i
66
+ eff_timeout = (timeout || Rubik::Storage::Layout.config_get(@config, "test.timeout", 30) || 30).to_i
66
67
  work_dir = test_working_dir(root_dir, path)
67
68
  res = ProcessRunner.run(cmd, timeout: eff_timeout, chdir: work_dir)
68
69
 
@@ -1,79 +1,40 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "open3"
4
- require "timeout"
5
- require_relative "../log"
3
+ require_relative "../platform"
6
4
 
7
5
  module Rubik
8
6
  module Adapter
7
+ # Adapter-facing wrapper over the single-homed popen3 + drain core,
8
+ # Rubik::Platform::Process#popen_capture (issue #444). Preserves the
9
+ # legacy result contract exactly: no :pid key, and every swallowed IO
10
+ # error keeps its historical Log.debug(:adapter) trace via the observer
11
+ # below (event names mirror the platform core's swallow points).
9
12
  class ProcessRunner
10
- def self.run(cmd, timeout: 15, chdir: Dir.pwd)
11
- start_time = Time.now
12
- stdout_str = ""
13
- stderr_str = ""
14
- exit_code = 127
15
-
16
- pid = nil
17
- begin
18
- Timeout.timeout(timeout) do
19
- Open3.popen3(cmd, chdir: chdir) do |stdin, stdout, stderr, wait_thr|
20
- pid = wait_thr.pid
21
- begin
22
- stdin.close
23
- rescue StandardError => e
24
- Rubik::Log.debug(:adapter, "stdin close failed during process execution: #{e.class}: #{e.message}")
25
- end
26
- t_out = Thread.new do
27
- stdout.read
28
- rescue StandardError => e
29
- Rubik::Log.debug(:adapter, "stdout read failed during process execution: #{e.class}: #{e.message}")
30
- ""
31
- end
32
- t_err = Thread.new do
33
- stderr.read
34
- rescue StandardError => e
35
- Rubik::Log.debug(:adapter, "stderr read failed during process execution: #{e.class}: #{e.message}")
36
- ""
37
- end
38
- begin
39
- stdout_str = t_out.value.to_s
40
- stderr_str = t_err.value.to_s
41
- status = wait_thr.value
42
- exit_code = status.exitstatus || (status.signaled? ? (128 + (status.termsig || 1)) : 1)
43
- ensure
44
- begin
45
- t_out.kill
46
- rescue StandardError => e
47
- Rubik::Log.debug(:adapter, "t_out kill failed: #{e.class}: #{e.message}")
48
- end
49
- begin
50
- t_err.kill
51
- rescue StandardError => e
52
- Rubik::Log.debug(:adapter, "t_err kill failed: #{e.class}: #{e.message}")
53
- end
54
- end
55
- end
56
- end
57
- rescue Timeout::Error
58
- Rubik::Platform.kill_tree(pid) if pid
59
- stderr_str = "Execution timed out after #{timeout} seconds"
60
- exit_code = 124
61
- rescue Errno::ENOENT => e
62
- stderr_str = "Binary not found: #{e.message}"
63
- exit_code = 127
64
- rescue StandardError => e
65
- stderr_str = "Execution error: #{e.message}"
66
- exit_code = 1
13
+ ON_IO_ERROR = lambda do |event, error|
14
+ case event
15
+ when :stdin_close
16
+ Rubik::Log.debug(:adapter, "stdin close failed during process execution: #{error.class}: #{error.message}")
17
+ when :stdout_read
18
+ Rubik::Log.debug(:adapter, "stdout read failed during process execution: #{error.class}: #{error.message}")
19
+ when :stderr_read
20
+ Rubik::Log.debug(:adapter, "stderr read failed during process execution: #{error.class}: #{error.message}")
21
+ when :stdout_kill
22
+ Rubik::Log.debug(:adapter, "t_out kill failed: #{error.class}: #{error.message}")
23
+ when :stderr_kill
24
+ Rubik::Log.debug(:adapter, "t_err kill failed: #{error.class}: #{error.message}")
67
25
  end
26
+ end
27
+
28
+ def self.run(cmd, timeout: 15, chdir: Dir.pwd)
29
+ result = Rubik::Platform.popen_capture(cmd, timeout: timeout, chdir: chdir, on_io_error: ON_IO_ERROR)
68
30
 
69
- duration = Time.now - start_time
70
31
  {
71
- ok: exit_code.zero?,
72
- exit_code: exit_code,
73
- stdout: stdout_str,
74
- stderr: stderr_str,
75
- output: [stdout_str, stderr_str].reject(&:empty?).join("\n"),
76
- duration: duration.round(4)
32
+ ok: result[:ok],
33
+ exit_code: result[:exit_code],
34
+ stdout: result[:stdout],
35
+ stderr: result[:stderr],
36
+ output: result[:output],
37
+ duration: result[:duration]
77
38
  }
78
39
  end
79
40
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "../log"
3
4
  require_relative "extraction_result"
4
5
  require_relative "ruby_extractor"
5
6
  require_relative "go_extractor"
@@ -66,7 +67,7 @@ module Rubik
66
67
  # language extractor claims (:unavailable, legacy Ruby parse).
67
68
  fallback_result(file_path, content, ext)
68
69
  rescue StandardError, ScriptError => e
69
- warn "[WARN] Extraction failed for #{file_path}: #{e.class}: #{e.message}" if ENV["RUBIK_DEBUG"]
70
+ Rubik::Log.warn(:ast, "[WARN] Extraction failed for #{file_path}: #{e.class}: #{e.message}") if ENV["RUBIK_DEBUG"]
70
71
  ExtractionResult.new(symbols: [], status: :failed, source: :none, detail: "#{e.class}: #{e.message}")
71
72
  end
72
73
 
@@ -7,6 +7,7 @@ rescue LoadError
7
7
  TREE_SITTER_AVAILABLE = false
8
8
  end
9
9
 
10
+ require_relative "../log"
10
11
  require_relative "extraction_result"
11
12
  require_relative "treesitter/base_walker"
12
13
  require_relative "treesitter/python_walker"
@@ -94,7 +95,7 @@ module Rubik
94
95
 
95
96
  ExtractionResult.new(symbols: symbols, status: :ok, source: :tree_sitter)
96
97
  rescue StandardError, SystemStackError, ScriptError => e
97
- warn "[WARN] TreeSitter extraction failed for #{file_path}: #{e.message}" if ENV["RUBIK_DEBUG"]
98
+ Rubik::Log.warn(:ast, "[WARN] TreeSitter extraction failed for #{file_path}: #{e.message}") if ENV["RUBIK_DEBUG"]
98
99
  failed_result("#{e.class}: #{e.message}")
99
100
  end
100
101
 
@@ -2,6 +2,8 @@
2
2
 
3
3
  require "tmpdir"
4
4
  require "fileutils"
5
+ require_relative "../log"
6
+ require_relative "../errors"
5
7
  require_relative "../storage/vakanuvis"
6
8
  require_relative "../tools/builtins/storage"
7
9
  require_relative "../tools/builtins/vakanuvis"
@@ -82,6 +84,12 @@ module Rubik
82
84
  MAX_TURNS = 8
83
85
  REPLAY_PROFILES = ["adopter", "wrong-path", "struggler"].freeze
84
86
 
87
+ # Bench-integrity contract (issue #448): a driver returning a
88
+ # non-Response, or toolbelt errors leaking into the measurement plane,
89
+ # is a broken harness — never model behavior. Typed so callers (and
90
+ # rake bench) can distinguish it from ordinary StandardError noise.
91
+ class BenchError < Rubik::Error; end
92
+
85
93
  module_function
86
94
 
87
95
  # ---- mağaza + araç masası ---------------------------------------------
@@ -198,7 +206,7 @@ module Rubik
198
206
  # dönüş, respond_to? zincirlerine girip sahte "araç
199
207
  # benimsemedi / tur sınırına vurdu" veri noktası üretmesin —
200
208
  # dürüstçe patla.
201
- raise "provider returned #{res.inspect}, expected Rubik::LLM::Response" unless res.is_a?(Rubik::LLM::Response)
209
+ raise BenchError, "provider returned #{res.inspect}, expected Rubik::LLM::Response" unless res.is_a?(Rubik::LLM::Response)
202
210
 
203
211
  tool_calls = res.respond_to?(:tool_calls?) && res.tool_calls? ? res.tool_calls : []
204
212
  if tool_calls.empty?
@@ -315,8 +323,8 @@ module Rubik
315
323
  tool_errors = runs.sum { |r| r[:calls].count { |_n, _a, res| TOOL_ERROR_MARKERS.any? { |m| res.to_s.start_with?(m) } } }
316
324
  if tool_errors.positive?
317
325
  first_bad = runs.flat_map { |r| r[:calls] }.find { |_n, _a, res| TOOL_ERROR_MARKERS.any? { |m| res.to_s.start_with?(m) } }
318
- raise "#{driver.label}: #{tool_errors} tool error(s) — the bench toolbelt itself failed; " \
319
- "these numbers would read as model behavior. first: #{first_bad[2].to_s[0, 160]}"
326
+ raise BenchError, "#{driver.label}: #{tool_errors} tool error(s) — the bench toolbelt itself failed; " \
327
+ "these numbers would read as model behavior. first: #{first_bad[2].to_s[0, 160]}"
320
328
  end
321
329
  harness.shutdown
322
330
  metrics_for(driver.label, runs).tap { |m| io&.puts(" [vakanuvis-adoption] #{m.label}: #{m.summary}") }
@@ -340,7 +348,7 @@ module Rubik
340
348
  # Windows EBUSY/ENOTEMPTY (AV tarayıcı, indeksleyici) cleanup'ı
341
349
  # patlatabilir — cleanup hatası tabloyu ve işlenen hatayı
342
350
  # MaskeleMEsin; tüm benchmark'ı da abort etmesin.
343
- warn " [vakanuvis-adoption] cleanup failed for #{root}: #{e.class}: #{e.message}"
351
+ Rubik::Log.warn(:benchmark, " [vakanuvis-adoption] cleanup failed for #{root}: #{e.class}: #{e.message}")
344
352
  end
345
353
  end
346
354
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "../storage/layout"
4
+
3
5
  module Rubik
4
6
  module Buffer
5
7
  # The one home for the apply CONTRACT vocabulary (issue #146):
@@ -19,9 +21,7 @@ module Rubik
19
21
  # documented default (true).
20
22
  def model_can_apply?(shell_config:, manager_config:)
21
23
  cfg = shell_config || manager_config
22
- return true if cfg.nil? || !cfg.respond_to?(:fetch)
23
-
24
- cfg.fetch("buffer.model_can_apply", true) != false
24
+ Rubik::Storage::Layout.config_get(cfg, "buffer.model_can_apply", true) != false
25
25
  end
26
26
 
27
27
  # Partial-apply report lines. `sync` (when given) receives the applied
@@ -0,0 +1,165 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "digest"
4
+ require_relative "path_validator"
5
+ require_relative "../platform"
6
+
7
+ module Rubik
8
+ module Buffer
9
+ # The two-phase apply transaction, extracted from Manager (issue #472):
10
+ # per-file atomic writes with external-conflict detection — NOT a
11
+ # multi-file transaction. On a mid-run failure the partial progress is
12
+ # carried by ApplyFailedError: applied entries ARE on disk, the failed
13
+ # entry stays dirty, and pending entries keep their buffer content, so
14
+ # a retry writes only the remainder. External-modification conflicts
15
+ # are skipped (recorded in the run report) unless policy is "overwrite".
16
+ #
17
+ # The transaction owns the loop and its failure semantics; workspace
18
+ # path policy (containment, disk hashes, external-modification config)
19
+ # is delegated to the `disk_policy` adapter, and the overlay hashes are
20
+ # mutated in place so Manager state and the transaction stay the same
21
+ # objects. This makes conflict/failure paths testable without the full
22
+ # Manager dictionary API.
23
+ class ApplyTransaction
24
+ # A single run's outcome: paths that reached disk, externally-modified
25
+ # paths that were skipped, and entries rejected by the path validator.
26
+ Result = Struct.new(:applied, :conflicts, :skipped)
27
+
28
+ # The mutable overlay state (issue #472): the Manager's live
29
+ # buffer / dirty_files / original_hashes hashes, mutated in place.
30
+ Overlay = Struct.new(:buffer, :dirty_files, :original_hashes)
31
+
32
+ attr_reader :overlay
33
+
34
+ # @param overlay [Overlay] live buffer state, mutated in place
35
+ # @param disk_policy [#root_dir, #containment_root, #disk_hash,
36
+ # #external_modification_policy] workspace path policy adapter
37
+ # @param event_bus [Rubik::EventBus, nil] apply lifecycle events
38
+ def initialize(overlay:, disk_policy:, event_bus: nil)
39
+ @overlay = overlay
40
+ @disk_policy = disk_policy
41
+ @event_bus = event_bus
42
+ end
43
+
44
+ # Runs the apply loop over keys already sanitized by the caller (the
45
+ # path policy is Manager's concern). `on_finish` runs in an ensure so
46
+ # the caller records the run report (conflicts/skipped/applied) even
47
+ # when a mid-loop failure raises — Manager's last_conflicts /
48
+ # last_skipped / last_applied depend on it.
49
+ #
50
+ # @return [Result] applied/conflicts/skipped for a completed run
51
+ # @raise [ApplyFailedError] on the first failed write, with the
52
+ # structured partial-progress report attached
53
+ def run(keys_to_apply, effective_policy, &on_finish)
54
+ applied_paths = []
55
+ conflicts = []
56
+ skipped = []
57
+
58
+ begin
59
+ keys_to_apply.each_with_index do |rel_path, index|
60
+ next unless overlay.dirty_files.key?(rel_path)
61
+
62
+ unless validate_and_clean_garbage(rel_path)
63
+ skipped << { path: rel_path, reason: :path_validator_rejected }
64
+ next
65
+ end
66
+
67
+ if external_conflict?(rel_path) && effective_policy != "overwrite"
68
+ conflicts << rel_path
69
+ @event_bus&.emit(:buffer_apply_conflict, paths: conflicts.dup.freeze, path: rel_path)
70
+ next
71
+ end
72
+
73
+ apply_single_entry(rel_path, index: index, keys_to_apply: keys_to_apply,
74
+ applied_paths: applied_paths, conflicts: conflicts, skipped: skipped)
75
+ end
76
+ ensure
77
+ on_finish.call(applied_paths, conflicts, skipped)
78
+ end
79
+
80
+ Result.new(applied_paths, conflicts, skipped)
81
+ end
82
+
83
+ private
84
+
85
+ def validate_and_clean_garbage(rel_path)
86
+ return true if PathValidator.valid?(rel_path)
87
+
88
+ overlay.dirty_files.delete(rel_path)
89
+ overlay.buffer.delete(rel_path)
90
+ overlay.original_hashes.delete(rel_path)
91
+ @event_bus&.emit(:buffer_garbage_skipped, path: rel_path)
92
+ false
93
+ end
94
+
95
+ def external_conflict?(rel_path)
96
+ baseline = overlay.original_hashes[rel_path]
97
+ current_disk = @disk_policy.disk_hash(rel_path)
98
+
99
+ if baseline
100
+ current_disk != baseline
101
+ else
102
+ !current_disk.nil?
103
+ end
104
+ end
105
+
106
+ def apply_single_entry(rel_path, index:, keys_to_apply:, applied_paths:, conflicts:, skipped:)
107
+ full_path = File.expand_path(rel_path, @disk_policy.root_dir)
108
+
109
+ # TOCTOU close: re-verify containment immediately before the
110
+ # atomic write — a symlink planted between write-time sanitize
111
+ # and apply! must not redirect the write outside the workspace.
112
+ # Fail loud: an untrustworthy path is an attack signal or a
113
+ # mid-flight root misconfiguration, not a content problem; the
114
+ # entry stays dirty for a retry after remediation.
115
+ containment_kind, = @disk_policy.containment_root(full_path)
116
+ unless containment_kind
117
+ @event_bus&.emit(:buffer_containment_blocked, path: rel_path)
118
+ raise apply_failure(
119
+ "Write blocked: '#{rel_path}' resolves outside all allowed roots at apply time " \
120
+ "(possible symlink swap since buffering). Re-verify the workspace and retry.",
121
+ kind: :containment_blocked, applied: applied_paths, failed: rel_path,
122
+ pending: pending_after(keys_to_apply, index), conflicts: conflicts, skipped: skipped
123
+ )
124
+ end
125
+
126
+ content = overlay.buffer[rel_path]
127
+
128
+ begin
129
+ Rubik::Platform.atomic_write(full_path, content)
130
+ rescue StandardError => e
131
+ raise apply_failure(
132
+ "Apply failed for '#{rel_path}': #{e.class}: #{e.message}; " \
133
+ "#{applied_paths.empty? ? 'no file was written' : "already written: #{applied_paths.join(', ')}"}; " \
134
+ "#{pending_after(keys_to_apply, index).size} file(s) still dirty",
135
+ kind: :write_failed, applied: applied_paths, failed: rel_path,
136
+ pending: pending_after(keys_to_apply, index), conflicts: conflicts, skipped: skipped
137
+ ), cause: e
138
+ end
139
+
140
+ overlay.original_hashes[rel_path] = Digest::SHA256.hexdigest(content)
141
+ overlay.dirty_files.delete(rel_path)
142
+ overlay.buffer.delete(rel_path)
143
+ applied_paths << rel_path
144
+ end
145
+
146
+ # Build the structured partial-apply error with frozen report copies —
147
+ # a reader must see the state at raise time, not later mutations.
148
+ def apply_failure(message, kind:, applied:, failed:, pending:, conflicts:, skipped: [])
149
+ ApplyFailedError.new(
150
+ message, kind: kind,
151
+ applied: applied.dup.freeze, failed: failed,
152
+ pending: pending.dup.freeze, conflicts: conflicts.dup.freeze,
153
+ skipped: skipped.dup.freeze
154
+ )
155
+ end
156
+
157
+ # This run's remaining dirty entries after the failed index — exactly
158
+ # what a retry will still have to write (garbage-skipped entries are
159
+ # already out of dirty_files when this runs).
160
+ def pending_after(keys, index)
161
+ keys[(index + 1)..].to_a.select { |k| overlay.dirty_files.key?(k) }
162
+ end
163
+ end
164
+ end
165
+ end