rubik 0.14.0 → 0.15.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 +89 -1
- data/lib/rubik/adapter/node.rb +4 -1
- data/lib/rubik/ast/fallback_cleaner.rb +6 -1
- data/lib/rubik/ast/ruby_extractor.rb +12 -6
- data/lib/rubik/buffer/manager.rb +15 -10
- data/lib/rubik/buffer/snapshot.rb +103 -35
- data/lib/rubik/config/scoped.rb +12 -5
- data/lib/rubik/connect/models_dev.rb +4 -2
- data/lib/rubik/connect/wizard.rb +9 -1
- data/lib/rubik/diagnostics/collector.rb +25 -2
- data/lib/rubik/llm/client.rb +19 -0
- data/lib/rubik/llm/connection_pool.rb +7 -1
- data/lib/rubik/llm/formatter.rb +8 -2
- data/lib/rubik/llm/router.rb +8 -0
- data/lib/rubik/lsp/client.rb +233 -18
- data/lib/rubik/lsp/document_store.rb +6 -0
- data/lib/rubik/lsp/manager.rb +14 -0
- data/lib/rubik/lsp/transport.rb +17 -0
- data/lib/rubik/orchestrator/continuation_manager.rb +54 -2
- data/lib/rubik/orchestrator/goal_session.rb +10 -10
- data/lib/rubik/orchestrator/goal_wait.rb +15 -9
- data/lib/rubik/orchestrator/loop.rb +31 -28
- data/lib/rubik/orchestrator/subagent/instance.rb +22 -4
- data/lib/rubik/orchestrator/subagent/lifecycle.rb +25 -25
- data/lib/rubik/orchestrator/subagent/messaging.rb +5 -1
- data/lib/rubik/orchestrator/subagent/narration.rb +2 -1
- data/lib/rubik/orchestrator/subagent/notices.rb +6 -2
- data/lib/rubik/orchestrator/subagent/questioner.rb +42 -4
- data/lib/rubik/orchestrator/subagent/reaper.rb +50 -19
- data/lib/rubik/orchestrator/subagent/supervisor.rb +11 -0
- data/lib/rubik/orchestrator/tool_call_id.rb +8 -4
- data/lib/rubik/orchestrator/turn_executor/subagent_channel.rb +21 -5
- data/lib/rubik/orchestrator/turn_executor/user_channel.rb +15 -2
- data/lib/rubik/platform/process.rb +32 -7
- data/lib/rubik/platform/sanitize.rb +17 -18
- data/lib/rubik/platform.rb +27 -0
- data/lib/rubik/plugin/storage.rb +17 -11
- data/lib/rubik/prompt/doctrine.rb +3 -2
- data/lib/rubik/repl/commands/base.rb +7 -3
- data/lib/rubik/repl/commands/buffer.rb +6 -2
- data/lib/rubik/repl/commands/session.rb +11 -1
- data/lib/rubik/repl/input_execution.rb +3 -3
- data/lib/rubik/repl/service_catalog.rb +6 -2
- data/lib/rubik/repl/turn_recorder.rb +4 -1
- data/lib/rubik/runtime/manifest_store.rb +7 -2
- data/lib/rubik/runtime/task_manager.rb +13 -10
- data/lib/rubik/sandbox/driver/base.rb +34 -0
- data/lib/rubik/sandbox/driver/bubblewrap.rb +2 -0
- data/lib/rubik/sandbox/driver/docker.rb +8 -0
- data/lib/rubik/sandbox/driver/podman.rb +8 -0
- data/lib/rubik/sandbox/driver/process.rb +9 -12
- data/lib/rubik/security/path_policy.rb +28 -3
- data/lib/rubik/session/recorder.rb +14 -2
- data/lib/rubik/storage/store.rb +7 -0
- data/lib/rubik/tools/builtins/exec.rb +7 -1
- data/lib/rubik/tools/builtins/interactive.rb +5 -2
- data/lib/rubik/tools/builtins/lsp.rb +28 -2
- data/lib/rubik/tools/builtins/send_message.rb +7 -2
- data/lib/rubik/tools/preflight_runner.rb +4 -1
- data/lib/rubik/ui/dialog.rb +5 -1
- data/lib/rubik/ui/renderer.rb +4 -1
- data/lib/rubik/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9a391892bea3be5bbf6d2102c6800ed7c728c253e4f6f003a7765e6b727b51ef
|
|
4
|
+
data.tar.gz: cf65a2aa159ce1c0ce5765a1aeedda43467a46e918ac7bb4e921e812fbd4edf5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 44fc9d447ea49d37e7c6483a61b69755aa882acaf8b446fd660e6a60d973566be865675dd49f555a2795ce2d6f3e09ceb990da67c514a9f4aebff4b28bf86f14
|
|
7
|
+
data.tar.gz: 5c65c0f28f82e7e8feac9cc4b7f849192c48ed81a4a256f17db687d0eb780783593ba00bc25e21e4f3902d7e47e9bed4df56671508ff3e38bfd0a236980c7e16
|
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,
|
|
124
|
+
| **`minitest`** | Ryan Davis & seattlerb | MIT | Fast, modular test suite powering Rubik's 4,950+ 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
|
@@ -8,6 +8,93 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
|
8
8
|
|
|
9
9
|
## [Unreleased]
|
|
10
10
|
|
|
11
|
+
## [0.15.0] - 2026-11-20
|
|
12
|
+
|
|
13
|
+
The diagnostics-and-hardening minor: the LSP client learns pull diagnostics
|
|
14
|
+
and spec-compliant incremental sync, the connect wizard's opencode (Go)
|
|
15
|
+
preset becomes zero-prompt — and a broad fix wave closes credential leaks,
|
|
16
|
+
stream-pool poisoning, orchestrator lifecycle bugs, symlink and ANSI escape
|
|
17
|
+
bypasses, and a long tail of platform, buffer, and storage edge cases.
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
|
|
21
|
+
- **LSP pull diagnostics + incremental sync (#583):** the client captures
|
|
22
|
+
`diagnosticProvider` at initialize and issues `textDocument/diagnostic`
|
|
23
|
+
requests for documents whose snapshot is pending, recording `full` results
|
|
24
|
+
through the same version-guarded path as push diagnostics (stale-version
|
|
25
|
+
responses discarded, `unchanged` short-circuited, in-flight pulls deduped
|
|
26
|
+
per document+version). Pull-only servers such as typeprof — the default
|
|
27
|
+
Ruby server — now surface diagnostics instead of reporting "pending"
|
|
28
|
+
forever. Under the negotiated Incremental sync kind, `didChange` sends one
|
|
29
|
+
full-old-document ranged edit computed in UTF-16 code units; Full sync
|
|
30
|
+
keeps the range-less form. `relatedDocuments` entries are now recorded
|
|
31
|
+
too (#585), and the fallback scanner tracks a scope stack so top-level
|
|
32
|
+
defs after a class body index at top level and nested modules yield
|
|
33
|
+
`M::C` prefixes (#600).
|
|
34
|
+
|
|
35
|
+
- **Zero-prompt session header for the opencode (Go) preset:** the connect
|
|
36
|
+
wizard's preset row pre-answers the session-header question — selecting
|
|
37
|
+
`opencode (Go)` applies `x-opencode-session` automatically (one notice
|
|
38
|
+
line instead of two prompts) and the confirm summary still names it.
|
|
39
|
+
The question remains for custom endpoints and catalog picks.
|
|
40
|
+
|
|
41
|
+
### Changed
|
|
42
|
+
|
|
43
|
+
- Container sandbox drivers (Docker/Podman) now bind-mount each
|
|
44
|
+
`allowed_dirs` entry read-write like Bubblewrap, so commands touching
|
|
45
|
+
allowed external dirs behave identically across drivers (#591).
|
|
46
|
+
- Shared helpers deduplicated: `allowed_dir_mounts` hoisted into
|
|
47
|
+
`Sandbox::Driver::Base`, and process env sanitizing delegates to the single
|
|
48
|
+
`Rubik::Platform.credential_free_env` source (#608).
|
|
49
|
+
|
|
50
|
+
### Fixed
|
|
51
|
+
|
|
52
|
+
- **Security & sandboxing (#586, #590, #592):** task children spawn with
|
|
53
|
+
credential-shaped host vars explicitly unset and task-log lines redacted
|
|
54
|
+
and byte-bounded at `RingBuffer#push`; shell-plane critical-path writes
|
|
55
|
+
re-resolve AST-derived targets with strict `resolved_path` so a committed
|
|
56
|
+
symlink cannot redirect a write into `.git/`; and ANSI/CSI/OSC escapes are
|
|
57
|
+
stripped from model-controlled tool args and dialog questions (both card
|
|
58
|
+
variants) before they reach the raw terminal.
|
|
59
|
+
|
|
60
|
+
- **LLM transport & adapters (#587, #588):** a streaming callback failure
|
|
61
|
+
now re-types as `StreamCallbackError` so a half-read pooled session is
|
|
62
|
+
discarded instead of poisoning the next request; streaming usage keys are
|
|
63
|
+
read with string spellings after `JSON.parse`; `router.mode fast/advanced`
|
|
64
|
+
map to their forced roles instead of silently behaving as auto; and
|
|
65
|
+
`.ts`/`.tsx` without `tsc`/`npx` returns unavailable instead of a false
|
|
66
|
+
syntax error from `node --check`.
|
|
67
|
+
|
|
68
|
+
- **Orchestrator lifecycle (#593, #594, #595):** subagent tool-call ids
|
|
69
|
+
include a per-run sequence so redeploys no longer re-emit ids the preserved
|
|
70
|
+
history already carries, and the finish tool writes its pairing result
|
|
71
|
+
row; `:budget_exhausted` units now count as dispatched work in the
|
|
72
|
+
goal-completion guard so goals are not declared achieved over unfinished
|
|
73
|
+
work; auto-continue absorbs prior partial rows on stitch; `continue_loop`
|
|
74
|
+
disposes its stale per-run sub-context; `ask_question` pairs answers by
|
|
75
|
+
`in_reply_to` question id so steering cannot pose as an answer; and the
|
|
76
|
+
reaper sweep takes transcript probes out from under the supervisor lock.
|
|
77
|
+
|
|
78
|
+
- **Platform & process (#597):** deep path cleanup tracks a path stack so
|
|
79
|
+
shared non-cyclic objects are no longer elided as `[...]`; the
|
|
80
|
+
`popen_capture` watchdog sets `deadline_hit` only when the kill targets a
|
|
81
|
+
still-live child; an explicit `timed_out` flag replaces exit-code-124
|
|
82
|
+
inference; and preflight kills whole process trees.
|
|
83
|
+
|
|
84
|
+
- **LSP robustness (#601, #605, #609):** the reader rejects non-positive
|
|
85
|
+
`Content-Length` and caps frames at 16 MiB, the diagnostic collector is
|
|
86
|
+
keyed by file with an oldest-first eviction cap, the transport clears
|
|
87
|
+
in-flight pulls on start/stop, and the `lsp.feedback_timeout` knob is
|
|
88
|
+
honored for per-file queries.
|
|
89
|
+
|
|
90
|
+
- **Buffer, plugins, config, storage & session (#589, #596, #598, #599,
|
|
91
|
+
#602):** snapshot persistence is debounced with a retention cap while
|
|
92
|
+
in-memory undo granularity is preserved and `!diff` shares one decoding
|
|
93
|
+
path; `add_plugin` guards derived names and refuses to silently heal a
|
|
94
|
+
corrupt manifest; replayed turns no longer re-record into the active
|
|
95
|
+
session; `Scoped#fetch` lets an explicit `nil` shadow a parent value; and
|
|
96
|
+
`put(ref:)` aliases are validated against `REF_PATTERN`.
|
|
97
|
+
|
|
11
98
|
## [0.14.0] - 2026-11-19
|
|
12
99
|
|
|
13
100
|
The session-attribution minor: gateway plumbing that needed a stable
|
|
@@ -1852,7 +1939,8 @@ installation section.
|
|
|
1852
1939
|
- Context: serialized index mutations, snapshot-outside-lock reconcile,
|
|
1853
1940
|
streaming-first truncation.
|
|
1854
1941
|
|
|
1855
|
-
[Unreleased]: https://github.com/ozgurulukir/rubik/compare/v0.
|
|
1942
|
+
[Unreleased]: https://github.com/ozgurulukir/rubik/compare/v0.15.0...HEAD
|
|
1943
|
+
[0.15.0]: https://github.com/ozgurulukir/rubik/compare/v0.14.0...v0.15.0
|
|
1856
1944
|
[0.14.0]: https://github.com/ozgurulukir/rubik/compare/v0.13.0...v0.14.0
|
|
1857
1945
|
[0.13.0]: https://github.com/ozgurulukir/rubik/compare/v0.12.0...v0.13.0
|
|
1858
1946
|
[0.12.0]: https://github.com/ozgurulukir/rubik/compare/v0.11.0...v0.12.0
|
data/lib/rubik/adapter/node.rb
CHANGED
|
@@ -81,7 +81,10 @@ module Rubik
|
|
|
81
81
|
elsif Runtime::Discovery.binary_available?("npx")
|
|
82
82
|
"npx tsc --noEmit #{escaped}"
|
|
83
83
|
else
|
|
84
|
-
|
|
84
|
+
# `node --check` cannot parse TypeScript — falling back to
|
|
85
|
+
# it reported a false syntax error for every TS file
|
|
86
|
+
# (issue #588). Report unavailability like the .vue branch.
|
|
87
|
+
return unavailable_result(reason: "No syntax checker available for TypeScript files. Install tsc or npx.")
|
|
85
88
|
end
|
|
86
89
|
when ".vue"
|
|
87
90
|
if Runtime::Discovery.binary_available?("vue-tsc")
|
|
@@ -117,7 +117,12 @@ module Rubik
|
|
|
117
117
|
|
|
118
118
|
j = start + 1
|
|
119
119
|
while j < raw.length
|
|
120
|
-
|
|
120
|
+
if raw[j] == "\\"
|
|
121
|
+
# Issue #600: skip the escaped pair entirely — an escaped `\/`
|
|
122
|
+
# is content, not the delimiter, and must not end the span.
|
|
123
|
+
j += 2
|
|
124
|
+
next
|
|
125
|
+
end
|
|
121
126
|
break if raw[j] == "/"
|
|
122
127
|
|
|
123
128
|
j += 1
|
|
@@ -172,22 +172,28 @@ module Rubik
|
|
|
172
172
|
end
|
|
173
173
|
|
|
174
174
|
def extract_via_fallback(symbols)
|
|
175
|
-
|
|
175
|
+
# Scope stack of [qualified_name, end_line] pairs (issue #600):
|
|
176
|
+
# entries pop once the scanner moves past their matching `end`, so
|
|
177
|
+
# top-level defs after a class body are no longer misattributed and
|
|
178
|
+
# nested `module M; class C` yields `M::C` prefixes.
|
|
179
|
+
scopes = []
|
|
176
180
|
i = 0
|
|
177
181
|
|
|
178
182
|
while i < code_lines.size
|
|
179
|
-
line = code_lines[i]
|
|
180
183
|
line_num = i + 1
|
|
181
|
-
|
|
184
|
+
scopes.reject! { |(_, end_line)| line_num > end_line }
|
|
185
|
+
|
|
186
|
+
stripped = code_lines[i].strip
|
|
182
187
|
|
|
183
188
|
if stripped.start_with?("class ") || stripped.start_with?("module ")
|
|
184
189
|
kind = stripped.start_with?("class ") ? :class : :module
|
|
185
190
|
name = stripped.split(/\s+/)[1].to_s.split("<").first.to_s.strip
|
|
186
|
-
|
|
191
|
+
qualified_name = scopes.empty? ? name : "#{scopes.last[0]}::#{name}"
|
|
187
192
|
end_line = find_matching_end(i)
|
|
193
|
+
scopes << [qualified_name, end_line]
|
|
188
194
|
|
|
189
195
|
symbols << Symbol.new(
|
|
190
|
-
name:
|
|
196
|
+
name: qualified_name,
|
|
191
197
|
kind: kind,
|
|
192
198
|
file: @file_path,
|
|
193
199
|
line_start: line_num,
|
|
@@ -196,7 +202,7 @@ module Rubik
|
|
|
196
202
|
)
|
|
197
203
|
elsif stripped.start_with?("def ")
|
|
198
204
|
method_name = stripped.sub(/^def\s+/, "").split(/[(\s;]/).first.strip
|
|
199
|
-
full_name =
|
|
205
|
+
full_name = scopes.empty? ? method_name : "#{scopes.last[0]}##{method_name}"
|
|
200
206
|
end_line = find_matching_end(i)
|
|
201
207
|
calls_src = lines[(line_num - 1)..(end_line - 1)]&.join.to_s
|
|
202
208
|
calls = []
|
data/lib/rubik/buffer/manager.rb
CHANGED
|
@@ -231,18 +231,23 @@ module Rubik
|
|
|
231
231
|
@buffer[rel_path] = content
|
|
232
232
|
@dirty_files[rel_path] = true
|
|
233
233
|
@event_bus&.emit(:buffer_changed, path: rel_path)
|
|
234
|
-
|
|
235
|
-
# Give the advertised !undo / !rollback commands a producer in
|
|
236
|
-
# the live write path (issue #544). Snapshotting is auxiliary:
|
|
237
|
-
# a storage failure must not turn a successful edit into a
|
|
238
|
-
# failed write.
|
|
239
|
-
begin
|
|
240
|
-
@snapshot_store&.create_snapshot(self)
|
|
241
|
-
rescue StandardError => e
|
|
242
|
-
warn "[Buffer] snapshot recording failed: #{e.class}: #{e.message}"
|
|
243
|
-
end
|
|
244
234
|
content
|
|
245
235
|
end
|
|
236
|
+
|
|
237
|
+
# Give the advertised !undo / !rollback commands a producer in
|
|
238
|
+
# the live write path (issue #544). Snapshotting is auxiliary:
|
|
239
|
+
# a storage failure must not turn a successful edit into a
|
|
240
|
+
# failed write. The deflate+disk write runs OUTSIDE the monitor
|
|
241
|
+
# (issue #589) so the whole-buffer snapshot no longer serializes
|
|
242
|
+
# concurrent buffer operations behind its IO; the store reads
|
|
243
|
+
# state through the monitor-protected snapshot_state, and its
|
|
244
|
+
# debouncing coalesces bursts into one write per interval.
|
|
245
|
+
begin
|
|
246
|
+
@snapshot_store&.create_snapshot(self)
|
|
247
|
+
rescue StandardError => e
|
|
248
|
+
warn "[Buffer] snapshot recording failed: #{e.class}: #{e.message}"
|
|
249
|
+
end
|
|
250
|
+
content
|
|
246
251
|
end
|
|
247
252
|
|
|
248
253
|
# Returns whether the buffer has any unapplied file modifications,
|
|
@@ -4,6 +4,7 @@ require "zlib"
|
|
|
4
4
|
require "json"
|
|
5
5
|
require "fileutils"
|
|
6
6
|
require "securerandom"
|
|
7
|
+
require "monitor"
|
|
7
8
|
require_relative "../platform"
|
|
8
9
|
|
|
9
10
|
module Rubik
|
|
@@ -46,10 +47,32 @@ module Rubik
|
|
|
46
47
|
class SnapshotStore
|
|
47
48
|
attr_reader :storage_dir, :snapshots
|
|
48
49
|
|
|
49
|
-
|
|
50
|
+
# Issue #589: in-memory snapshots stay per-edit (undo granularity is
|
|
51
|
+
# untouched), but the whole-buffer deflate+disk persist is debounced to
|
|
52
|
+
# at most one write per interval — the IO is the expensive part and the
|
|
53
|
+
# files are durability artifacts, never read back by undo/rollback.
|
|
54
|
+
# 0 disables debouncing (the historical per-write persistence, still
|
|
55
|
+
# the default so standalone/test stores keep exact per-edit durability).
|
|
56
|
+
DEFAULT_MIN_INTERVAL = 0.0
|
|
57
|
+
# On-disk retention cap: once exceeded, the oldest snapshot files are
|
|
58
|
+
# rotated away (their undo reach is lost, same as an expired redo
|
|
59
|
+
# tail). Keeps a long session from accumulating unbounded snapshot
|
|
60
|
+
# files (issue #589).
|
|
61
|
+
DEFAULT_MAX_SNAPSHOTS = 200
|
|
62
|
+
|
|
63
|
+
def initialize(storage_dir: File.join(Rubik::Platform.home_dir, ".rubik", "snapshots", "default"),
|
|
64
|
+
min_interval: DEFAULT_MIN_INTERVAL,
|
|
65
|
+
max_snapshots: DEFAULT_MAX_SNAPSHOTS)
|
|
50
66
|
@storage_dir = storage_dir
|
|
67
|
+
@min_interval = min_interval.to_f
|
|
68
|
+
@max_snapshots = [max_snapshots.to_i, 1].max
|
|
51
69
|
@snapshots = []
|
|
52
70
|
@current_index = -1
|
|
71
|
+
@last_file_write_at = nil
|
|
72
|
+
# The store is written from the manager's write path (outside the
|
|
73
|
+
# manager monitor, issue #589) and read by undo/rollback; guard its
|
|
74
|
+
# own index/file state independently.
|
|
75
|
+
@monitor = Monitor.new
|
|
53
76
|
# The state undo-to-beginning restores. Defaults to a clean
|
|
54
77
|
# buffer; consumers that snapshot a pre-existing dirty buffer
|
|
55
78
|
# (e.g. Repair::Loop) record that state explicitly so an aborted
|
|
@@ -63,56 +86,101 @@ module Rubik
|
|
|
63
86
|
# before the first snapshot, when the buffer already holds edits
|
|
64
87
|
# that must survive an aborted operation.
|
|
65
88
|
def record_baseline(buffer_manager)
|
|
66
|
-
@
|
|
89
|
+
@monitor.synchronize do
|
|
90
|
+
@baseline = buffer_manager.snapshot_state
|
|
91
|
+
end
|
|
67
92
|
end
|
|
68
93
|
|
|
69
94
|
def create_snapshot(buffer_manager)
|
|
70
|
-
|
|
95
|
+
@monitor.synchronize do
|
|
96
|
+
return nil unless buffer_manager.dirty?
|
|
97
|
+
|
|
98
|
+
snapshot = Snapshot.new(files: buffer_manager.snapshot_state)
|
|
99
|
+
|
|
100
|
+
# Persist BEFORE any list mutation (issue #476 tranche 2): a failed
|
|
101
|
+
# disk write must leave the in-memory snapshot list untouched.
|
|
102
|
+
# Persistence is debounced (issue #589) — a skip inside the window
|
|
103
|
+
# costs only crash-durability granularity, never an undo step.
|
|
104
|
+
persist_snapshot(snapshot)
|
|
105
|
+
|
|
106
|
+
# Clamp the redo truncation: with @current_index == -1 the range
|
|
107
|
+
# [0..-1] is the WHOLE array, so a fresh snapshot after undoing
|
|
108
|
+
# to empty would be appended after stale snapshots and a later
|
|
109
|
+
# undo would resurrect the discarded edit (issue #544).
|
|
110
|
+
if @current_index < @snapshots.size - 1
|
|
111
|
+
@snapshots = @current_index.negative? ? [] : @snapshots[0..@current_index]
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
@snapshots << snapshot
|
|
115
|
+
@current_index = @snapshots.size - 1
|
|
116
|
+
|
|
117
|
+
rotate_expired_snapshots
|
|
118
|
+
snapshot
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# Debounced persistence (issue #589): at most one deflate+binwrite per
|
|
123
|
+
# interval. Undo/rollback run from the in-memory snapshot list, so a
|
|
124
|
+
# skipped persist costs only crash-durability granularity, never an
|
|
125
|
+
# undo step.
|
|
126
|
+
def persist_snapshot(snapshot)
|
|
127
|
+
now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
128
|
+
return false if @min_interval.positive? && @last_file_write_at && now - @last_file_write_at < @min_interval
|
|
71
129
|
|
|
72
|
-
snapshot = Snapshot.new(files: buffer_manager.snapshot_state)
|
|
73
130
|
# Naming reflects the actual codec: this is Zlib::Deflate (RFC 1951),
|
|
74
131
|
# NOT Zstandard despite the "z" prefix. "zst" was misleading and could
|
|
75
132
|
# fool a tool into trying a zstd decompressor. Kept short to preserve
|
|
76
133
|
# the existing file layout.
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
# [0..-1] is the WHOLE array, so a fresh snapshot after undoing
|
|
82
|
-
# to empty would be appended after stale snapshots and a later
|
|
83
|
-
# undo would resurrect the discarded edit (issue #544).
|
|
84
|
-
if @current_index < @snapshots.size - 1
|
|
85
|
-
@snapshots = @current_index.negative? ? [] : @snapshots[0..@current_index]
|
|
86
|
-
end
|
|
134
|
+
File.binwrite(File.join(@storage_dir, "#{snapshot.id}.zdeflate"), snapshot.compress)
|
|
135
|
+
@last_file_write_at = now
|
|
136
|
+
true
|
|
137
|
+
end
|
|
87
138
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
139
|
+
# Retention cap (issue #589): drop the oldest snapshots beyond the cap
|
|
140
|
+
# and unlink their files. Only undo-unreachable entries may be dropped:
|
|
141
|
+
# @current_index is shifted so it keeps pointing at the same logical
|
|
142
|
+
# snapshot, and a shift below zero folds into the baseline restore.
|
|
143
|
+
def rotate_expired_snapshots
|
|
144
|
+
excess = @snapshots.size - @max_snapshots
|
|
145
|
+
return if excess <= 0
|
|
146
|
+
|
|
147
|
+
dropped = @snapshots.shift(excess)
|
|
148
|
+
@current_index -= excess
|
|
149
|
+
@current_index = -1 if @current_index.negative?
|
|
150
|
+
dropped.each do |snapshot|
|
|
151
|
+
File.delete(File.join(@storage_dir, "#{snapshot.id}.zdeflate"))
|
|
152
|
+
rescue SystemCallError
|
|
153
|
+
nil
|
|
154
|
+
end
|
|
91
155
|
end
|
|
92
156
|
|
|
93
157
|
def undo(buffer_manager)
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
158
|
+
@monitor.synchronize do
|
|
159
|
+
return false if @current_index.negative?
|
|
160
|
+
|
|
161
|
+
if @current_index.zero?
|
|
162
|
+
buffer_manager.restore_snapshot_state(@baseline)
|
|
163
|
+
@current_index = -1
|
|
164
|
+
return true
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
@current_index -= 1
|
|
168
|
+
prev_snapshot = @snapshots[@current_index]
|
|
169
|
+
buffer_manager.restore_snapshot_state(prev_snapshot.files)
|
|
170
|
+
true
|
|
100
171
|
end
|
|
101
|
-
|
|
102
|
-
@current_index -= 1
|
|
103
|
-
prev_snapshot = @snapshots[@current_index]
|
|
104
|
-
buffer_manager.restore_snapshot_state(prev_snapshot.files)
|
|
105
|
-
true
|
|
106
172
|
end
|
|
107
173
|
|
|
108
174
|
def rollback(snapshot_id, buffer_manager)
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
175
|
+
@monitor.synchronize do
|
|
176
|
+
target_idx = @snapshots.index { |s| s.id == snapshot_id }
|
|
177
|
+
return false unless target_idx
|
|
178
|
+
|
|
179
|
+
target_snapshot = @snapshots[target_idx]
|
|
180
|
+
buffer_manager.restore_snapshot_state(target_snapshot.files)
|
|
181
|
+
@current_index = target_idx
|
|
182
|
+
true
|
|
183
|
+
end
|
|
116
184
|
end
|
|
117
185
|
end
|
|
118
186
|
end
|
data/lib/rubik/config/scoped.rb
CHANGED
|
@@ -40,12 +40,19 @@ module Rubik
|
|
|
40
40
|
def fetch(key, default = nil)
|
|
41
41
|
@monitor.synchronize do
|
|
42
42
|
keys = key.to_s.split(".")
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
# "Key present with nil" is distinct from "key absent" (issue #599):
|
|
44
|
+
# an explicit nil override shadows the parent instead of falling
|
|
45
|
+
# through to it.
|
|
46
|
+
node = @overrides
|
|
47
|
+
present = keys.all? do |k|
|
|
48
|
+
if node.is_a?(Hash) && node.key?(k)
|
|
49
|
+
node = node[k]
|
|
50
|
+
true
|
|
51
|
+
else
|
|
52
|
+
false
|
|
53
|
+
end
|
|
47
54
|
end
|
|
48
|
-
return
|
|
55
|
+
return node if present
|
|
49
56
|
|
|
50
57
|
@parent.fetch(key, default)
|
|
51
58
|
end
|
|
@@ -44,8 +44,10 @@ module Rubik
|
|
|
44
44
|
# /chat/completions to a versioned tail, and a bare /openai tail
|
|
45
45
|
# would spell /openai/chat/completions (a 404 there). POSTs hard-400
|
|
46
46
|
# with MissingSessionID until providers.<key>.session_header carries
|
|
47
|
-
# x-opencode-session
|
|
48
|
-
|
|
47
|
+
# x-opencode-session, so the row PRE-ANSWERS the wizard question:
|
|
48
|
+
# selecting the preset applies the header without prompting (ask_session_header).
|
|
49
|
+
{ id: "opencode", label: "opencode (Go)", type: "openai_compatible", api: "https://opencode.ai/inference/go/openai/v1", catalog_id: "opencode", use_catalog_api: false,
|
|
50
|
+
session_header: "x-opencode-session" },
|
|
49
51
|
{ id: "ollama", label: "Ollama (yerel / local)", type: "ollama", api: "http://localhost:11434", catalog_id: nil }
|
|
50
52
|
].freeze
|
|
51
53
|
|
data/lib/rubik/connect/wizard.rb
CHANGED
|
@@ -118,7 +118,8 @@ module Rubik
|
|
|
118
118
|
label = "#{pin[:label]} · #{host_of(api)}"
|
|
119
119
|
choices << label
|
|
120
120
|
lookup[label] = { id: pin[:id], label: pin[:label], type: pin[:type], base_url: api,
|
|
121
|
-
catalog_id: pin[:catalog_id], catalog_entry: entry
|
|
121
|
+
catalog_id: pin[:catalog_id], catalog_entry: entry,
|
|
122
|
+
session_header: pin[:session_header] }.compact
|
|
122
123
|
end
|
|
123
124
|
choices << CUSTOM_LABEL
|
|
124
125
|
lookup[CUSTOM_LABEL] = :custom
|
|
@@ -220,6 +221,13 @@ module Rubik
|
|
|
220
221
|
def ask_session_header(plan)
|
|
221
222
|
return plan unless plan[:type] == "openai_compatible"
|
|
222
223
|
|
|
224
|
+
# Presets that KNOW the gateway contract (opencode Go) pre-answer the
|
|
225
|
+
# question: zero extra prompts, one honest notice instead.
|
|
226
|
+
if plan[:session_header].is_a?(String) && !plan[:session_header].strip.empty?
|
|
227
|
+
@ui.puts @ui.paint("Session header from preset: #{plan[:session_header]} (applied automatically)", :dim)
|
|
228
|
+
return plan
|
|
229
|
+
end
|
|
230
|
+
|
|
223
231
|
choice = @ui.select(S_SESSION_HEADER, [SESSION_HEADER_NO, SESSION_HEADER_YES], default: SESSION_HEADER_NO)
|
|
224
232
|
return :cancelled unless choice.is_a?(String)
|
|
225
233
|
|
|
@@ -12,6 +12,12 @@ module Rubik
|
|
|
12
12
|
SEVERITY_ORDER = { error: 0, warning: 1, info: 2, hint: 3, unknown: 4 }.freeze
|
|
13
13
|
LSP_SEVERITY_MAP = { 1 => :error, 2 => :warning, 3 => :info, 4 => :hint }.freeze
|
|
14
14
|
|
|
15
|
+
# Issue #601: the collector must not grow without bound. CLI/parsed
|
|
16
|
+
# entries are evicted oldest-first past this cap; LSP entries are keyed
|
|
17
|
+
# by file, so a re-harvest REPLACES that file's slice instead of
|
|
18
|
+
# appending stale duplicates forever.
|
|
19
|
+
MAX_ENTRIES = 2000
|
|
20
|
+
|
|
15
21
|
attr_reader :root_dir, :lsp_manager
|
|
16
22
|
|
|
17
23
|
def initialize(lsp_manager: nil, root_dir: Dir.pwd)
|
|
@@ -34,7 +40,10 @@ module Rubik
|
|
|
34
40
|
def add_entry(entry)
|
|
35
41
|
return unless entry.is_a?(Entry)
|
|
36
42
|
|
|
37
|
-
@mutex.synchronize
|
|
43
|
+
@mutex.synchronize do
|
|
44
|
+
@entries << entry
|
|
45
|
+
evict_oldest_beyond_cap
|
|
46
|
+
end
|
|
38
47
|
end
|
|
39
48
|
|
|
40
49
|
# Parses CLI compiler/linter output and adds entries
|
|
@@ -54,15 +63,20 @@ module Rubik
|
|
|
54
63
|
raw_text: e.raw_text
|
|
55
64
|
)
|
|
56
65
|
end
|
|
66
|
+
evict_oldest_beyond_cap
|
|
57
67
|
end
|
|
58
68
|
end
|
|
59
69
|
|
|
60
|
-
# Ingests raw LSP diagnostics from a file path
|
|
70
|
+
# Ingests raw LSP diagnostics from a file path. Keyed by file: the
|
|
71
|
+
# previous slice for that file is replaced per harvest (issue #601),
|
|
72
|
+
# so repeated collect_lsp! calls stay bounded instead of accreting
|
|
73
|
+
# stale entries.
|
|
61
74
|
def add_lsp_diagnostics(file_path, lsp_diags)
|
|
62
75
|
return if lsp_diags.nil? || lsp_diags.empty?
|
|
63
76
|
|
|
64
77
|
rel_file = normalize_rel_path(file_path)
|
|
65
78
|
@mutex.synchronize do
|
|
79
|
+
@entries.reject! { |e| e.file == rel_file }
|
|
66
80
|
lsp_diags.each do |d|
|
|
67
81
|
start_pos = d.dig("range", "start") || {}
|
|
68
82
|
line = (start_pos["line"] || 0) + 1
|
|
@@ -81,6 +95,7 @@ module Rubik
|
|
|
81
95
|
raw_text: d.to_s
|
|
82
96
|
)
|
|
83
97
|
end
|
|
98
|
+
evict_oldest_beyond_cap
|
|
84
99
|
end
|
|
85
100
|
end
|
|
86
101
|
|
|
@@ -175,6 +190,14 @@ module Rubik
|
|
|
175
190
|
|
|
176
191
|
private
|
|
177
192
|
|
|
193
|
+
# Issue #601: keeps @entries bounded — drops the oldest entries once the
|
|
194
|
+
# cap is exceeded. Called with @mutex held.
|
|
195
|
+
def evict_oldest_beyond_cap
|
|
196
|
+
return if @entries.size <= MAX_ENTRIES
|
|
197
|
+
|
|
198
|
+
@entries.shift(@entries.size - MAX_ENTRIES)
|
|
199
|
+
end
|
|
200
|
+
|
|
178
201
|
def escape_xml(str)
|
|
179
202
|
str.to_s
|
|
180
203
|
.gsub("&", "&")
|
data/lib/rubik/llm/client.rb
CHANGED
|
@@ -44,6 +44,16 @@ module Rubik
|
|
|
44
44
|
end
|
|
45
45
|
end
|
|
46
46
|
|
|
47
|
+
# An error raised from inside the streaming body read (issue #587): the
|
|
48
|
+
# consumer's chunk callback blew up mid-stream. Unlike a status-decided
|
|
49
|
+
# ClientError (raised after a full drain, socket intact), the SSE body
|
|
50
|
+
# here was cut part-way through, so the pooled session's framing state is
|
|
51
|
+
# unknown — the connection pool must discard it or the next request on
|
|
52
|
+
# that socket desynchronizes against the server's remaining stream bytes.
|
|
53
|
+
# Subclass of ClientError so every existing `rescue ClientError` site
|
|
54
|
+
# keeps working.
|
|
55
|
+
class StreamCallbackError < ClientError; end
|
|
56
|
+
|
|
47
57
|
class HTTPClient
|
|
48
58
|
# Errors that are safe to retry with an idempotent bounded backoff:
|
|
49
59
|
# connect-phase failures and transport resets. Net::ReadTimeout is
|
|
@@ -390,7 +400,16 @@ module Rubik
|
|
|
390
400
|
end
|
|
391
401
|
|
|
392
402
|
response.read_body do |chunk|
|
|
403
|
+
# Any exception escaping the consumer's callback (or the SSE
|
|
404
|
+
# parse) cuts the body mid-stream. Re-type it as
|
|
405
|
+
# StreamCallbackError so ConnectionPool#with_connection can
|
|
406
|
+
# tell "socket integrity unknown" apart from a status-decided
|
|
407
|
+
# ClientError raised after a full drain (issue #587).
|
|
393
408
|
parser.feed(chunk).each(&callback)
|
|
409
|
+
rescue Interrupt
|
|
410
|
+
raise
|
|
411
|
+
rescue StandardError => e
|
|
412
|
+
raise Rubik::LLM::StreamCallbackError, "Streaming callback failed: #{e.class}: #{e.message}"
|
|
394
413
|
end
|
|
395
414
|
end
|
|
396
415
|
|
|
@@ -31,9 +31,15 @@ module Rubik
|
|
|
31
31
|
# RETRYABLE_ERRORS lives in client.rb, which requires this file before
|
|
32
32
|
# defining the HTTPClient class.
|
|
33
33
|
def integrity_lost_errors
|
|
34
|
+
# StreamCallbackError (issue #587): a consumer chunk-callback
|
|
35
|
+
# exception escapes mid-body, so the SSE framing state is unknown.
|
|
36
|
+
# It is deliberately narrower than ClientError — a status-decided
|
|
37
|
+
# ClientError is raised after a full body drain and the session is
|
|
38
|
+
# reusable — so pooling is not penalized on ordinary HTTP failures.
|
|
34
39
|
@integrity_lost_errors ||= [
|
|
35
40
|
*HTTPClient::RETRYABLE_ERRORS, Net::ReadTimeout, IOError,
|
|
36
|
-
OpenSSL::SSL::SSLError, Net::HTTPBadResponse, Interrupt
|
|
41
|
+
OpenSSL::SSL::SSLError, Net::HTTPBadResponse, Interrupt,
|
|
42
|
+
Rubik::LLM::StreamCallbackError
|
|
37
43
|
].freeze
|
|
38
44
|
end
|
|
39
45
|
|
data/lib/rubik/llm/formatter.rb
CHANGED
|
@@ -161,8 +161,14 @@ module Rubik
|
|
|
161
161
|
done = false
|
|
162
162
|
if parsed["usage"].is_a?(Hash)
|
|
163
163
|
u = parsed["usage"].dup
|
|
164
|
-
|
|
165
|
-
|
|
164
|
+
# JSON.parse yields string keys only, so both spellings must be
|
|
165
|
+
# looked up by string (issue #588): input_tokens/output_tokens
|
|
166
|
+
# gateways otherwise normalize to 0 and win the last-writer merge
|
|
167
|
+
# in Chunk::Assembler#merge_usage.
|
|
168
|
+
input = u.delete("prompt_tokens") || u.delete("input_tokens") || u[:input_tokens] || 0
|
|
169
|
+
output = u.delete("completion_tokens") || u.delete("output_tokens") || u[:output_tokens] || 0
|
|
170
|
+
u[:input_tokens] = input
|
|
171
|
+
u[:output_tokens] = output
|
|
166
172
|
usage = u
|
|
167
173
|
done = true
|
|
168
174
|
end
|
data/lib/rubik/llm/router.rb
CHANGED
|
@@ -93,6 +93,14 @@ module Rubik
|
|
|
93
93
|
private
|
|
94
94
|
|
|
95
95
|
def determine_role(task_type, prompt, mode)
|
|
96
|
+
# router.mode fast/advanced (issue #588): schema-valid enum values
|
|
97
|
+
# that previously silently degraded to auto classification. A sensible
|
|
98
|
+
# forced mapping exists — each mode maps to the identically named role
|
|
99
|
+
# — so instead of restricting the schema, honor the mode as a forced
|
|
100
|
+
# role, bypassing keyword classification.
|
|
101
|
+
return :fast if mode == "fast"
|
|
102
|
+
return :advanced if mode == "advanced"
|
|
103
|
+
|
|
96
104
|
case task_type.to_sym
|
|
97
105
|
when :fast, :quick, :repair, :diagnose
|
|
98
106
|
:fast
|