rubik 0.13.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 +122 -1
- data/lib/rubik/adapter/node.rb +4 -1
- data/lib/rubik/ast/c_extractor.rb +1 -1
- data/lib/rubik/ast/fallback_cleaner.rb +6 -1
- data/lib/rubik/ast/graph.rb +38 -57
- data/lib/rubik/ast/graph_extensions.rb +57 -15
- data/lib/rubik/ast/ruby_extractor.rb +16 -6
- data/lib/rubik/ast/treesitter/c_walker.rb +11 -3
- data/lib/rubik/buffer/manager.rb +38 -11
- data/lib/rubik/buffer/snapshot.rb +116 -28
- data/lib/rubik/cli/connect.rb +3 -5
- data/lib/rubik/config/defaults.rb +3 -7
- data/lib/rubik/config/env_guard.rb +43 -0
- data/lib/rubik/config/schema.rb +7 -1
- data/lib/rubik/config/scoped.rb +12 -5
- data/lib/rubik/config/secret_policy.rb +6 -5
- data/lib/rubik/config.rb +1 -1
- data/lib/rubik/connect/models_dev.rb +11 -0
- data/lib/rubik/connect/probes.rb +9 -2
- data/lib/rubik/connect/wizard.rb +117 -57
- data/lib/rubik/context/repo_context_reader.rb +8 -4
- data/lib/rubik/diagnostics/collector.rb +25 -2
- data/lib/rubik/llm/chunk_assembler.rb +12 -1
- data/lib/rubik/llm/client.rb +19 -0
- data/lib/rubik/llm/connection_pool.rb +7 -1
- data/lib/rubik/llm/formatter.rb +22 -2
- data/lib/rubik/llm/provider_key.rb +32 -0
- data/lib/rubik/llm/registry.rb +18 -2
- data/lib/rubik/llm/router.rb +27 -1
- data/lib/rubik/llm/session_header.rb +128 -0
- data/lib/rubik/llm/sse_parser.rb +57 -10
- data/lib/rubik/lsp/client.rb +244 -23
- data/lib/rubik/lsp/document_store.rb +6 -0
- data/lib/rubik/lsp/manager.rb +14 -0
- data/lib/rubik/lsp/transport.rb +34 -7
- data/lib/rubik/mcp/transport/stdio.rb +42 -4
- data/lib/rubik/orchestrator/continuation_manager.rb +68 -7
- data/lib/rubik/orchestrator/goal_ledger/ledger.rb +18 -2
- data/lib/rubik/orchestrator/goal_ledger/observation_projection.rb +13 -4
- data/lib/rubik/orchestrator/goal_ledger/validator.rb +46 -7
- data/lib/rubik/orchestrator/goal_ledger/verifier.rb +8 -1
- data/lib/rubik/orchestrator/goal_session.rb +14 -14
- data/lib/rubik/orchestrator/goal_wait.rb +15 -9
- data/lib/rubik/orchestrator/loop.rb +39 -39
- data/lib/rubik/orchestrator/provider_resolver.rb +29 -6
- data/lib/rubik/orchestrator/step_executor.rb +17 -2
- data/lib/rubik/orchestrator/subagent/instance.rb +46 -5
- 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 +7 -3
- data/lib/rubik/orchestrator/subagent/questioner.rb +42 -4
- data/lib/rubik/orchestrator/subagent/reaper.rb +70 -20
- data/lib/rubik/orchestrator/subagent/start_gate.rb +1 -1
- data/lib/rubik/orchestrator/subagent/step_runner.rb +7 -7
- data/lib/rubik/orchestrator/subagent/supervisor.rb +21 -3
- 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 +40 -5
- data/lib/rubik/orchestrator/turn_executor.rb +24 -8
- data/lib/rubik/platform/filesystem.rb +52 -24
- 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 +34 -8
- data/lib/rubik/prompt/context_builder.rb +2 -1
- data/lib/rubik/prompt/doctrine.rb +3 -2
- data/lib/rubik/repair/loop.rb +22 -2
- data/lib/rubik/repl/commands/agent_context.rb +1 -1
- data/lib/rubik/repl/commands/agent_execution.rb +20 -15
- data/lib/rubik/repl/commands/base.rb +7 -3
- data/lib/rubik/repl/commands/buffer.rb +21 -2
- data/lib/rubik/repl/commands/connect.rb +0 -1
- data/lib/rubik/repl/commands/lsp.rb +1 -1
- data/lib/rubik/repl/commands/plugins.rb +31 -31
- data/lib/rubik/repl/commands/session.rb +16 -6
- data/lib/rubik/repl/commands/workspace.rb +4 -4
- data/lib/rubik/repl/input_execution.rb +33 -32
- data/lib/rubik/repl/input_loop.rb +9 -4
- data/lib/rubik/repl/lifecycle.rb +1 -2
- data/lib/rubik/repl/notice_router.rb +11 -5
- data/lib/rubik/repl/paste_support.rb +1 -1
- data/lib/rubik/repl/prompt_grace.rb +3 -3
- data/lib/rubik/repl/service_catalog.rb +6 -2
- data/lib/rubik/repl/shell.rb +10 -2
- data/lib/rubik/repl/turn_recorder.rb +18 -4
- data/lib/rubik/runtime/context.rb +33 -27
- data/lib/rubik/runtime/manager.rb +23 -15
- 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 +60 -8
- 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 +29 -1
- data/lib/rubik/sandbox/runner.rb +9 -1
- data/lib/rubik/security/classifier/classifier.rb +147 -13
- data/lib/rubik/security/classifier/commands/docker.yaml +1 -1
- data/lib/rubik/security/classifier/commands/git.yaml +27 -1
- data/lib/rubik/security/classifier/commands/sed.yaml +3 -3
- data/lib/rubik/security/classifier/database.rb +2 -2
- data/lib/rubik/security/command_gate.rb +8 -1
- data/lib/rubik/security/path_policy.rb +28 -3
- data/lib/rubik/security/redactor.rb +62 -19
- data/lib/rubik/session/recorder.rb +27 -20
- data/lib/rubik/session/replayer.rb +29 -7
- data/lib/rubik/storage/store.rb +26 -5
- data/lib/rubik/tools/builtins/exec.rb +8 -2
- data/lib/rubik/tools/builtins/files.rb +8 -12
- data/lib/rubik/tools/builtins/grep.rb +3 -2
- data/lib/rubik/tools/builtins/interactive.rb +5 -2
- data/lib/rubik/tools/builtins/lsp.rb +59 -9
- data/lib/rubik/tools/builtins/send_message.rb +7 -2
- data/lib/rubik/tools/builtins/show_file.rb +1 -1
- data/lib/rubik/tools/builtins/synthesis.rb +4 -4
- data/lib/rubik/tools/preflight_runner.rb +4 -1
- data/lib/rubik/tools/result_normalizer.rb +1 -1
- data/lib/rubik/ui/banner.rb +3 -3
- data/lib/rubik/ui/dialog.rb +15 -8
- data/lib/rubik/ui/diff_viewer.rb +4 -4
- data/lib/rubik/ui/frame.rb +13 -3
- data/lib/rubik/ui/markdown_stream.rb +8 -2
- data/lib/rubik/ui/panel.rb +11 -11
- data/lib/rubik/ui/renderer.rb +10 -7
- data/lib/rubik/ui/spinner.rb +1 -1
- data/lib/rubik/ui/statusline.rb +3 -3
- data/lib/rubik/ui/theme.rb +1 -1
- data/lib/rubik/version.rb +1 -1
- metadata +4 -1
data/lib/rubik/storage/store.rb
CHANGED
|
@@ -84,7 +84,7 @@ module Rubik
|
|
|
84
84
|
"version" => existing["version"].to_i + 1, "updated_at" => now
|
|
85
85
|
)
|
|
86
86
|
else
|
|
87
|
-
row =
|
|
87
|
+
row = allocate_row(meta, records, type)
|
|
88
88
|
hash = content_hash(type, title, body, tags, links)
|
|
89
89
|
{ "id" => "#{type}.#{row}.#{hash[0, 16]}", "type" => type, "project" => @project,
|
|
90
90
|
"row" => row, "hash" => hash, "title" => title.to_s, "body" => body.to_s,
|
|
@@ -94,10 +94,14 @@ module Rubik
|
|
|
94
94
|
|
|
95
95
|
records = records.reject { |r| r["row"] == record["row"] } << record
|
|
96
96
|
ensure_project_dirs
|
|
97
|
-
write_records(type, records.sort_by { |r| r["row"].to_i })
|
|
98
97
|
meta_bump_counts(meta, type) unless existing
|
|
99
98
|
meta_set_ref(meta, ref, record["id"]) if ref
|
|
99
|
+
# Journal order (issue #562): commit the allocator state BEFORE the
|
|
100
|
+
# entity row. A crash between the two writes then costs a row number
|
|
101
|
+
# (harmless gap) instead of leaving a row on disk with a stale
|
|
102
|
+
# next_row — which the next put would reallocate and silently evict.
|
|
100
103
|
save_meta(meta)
|
|
104
|
+
write_records(type, records.sort_by { |r| r["row"].to_i })
|
|
101
105
|
touch_index(meta)
|
|
102
106
|
record.dup
|
|
103
107
|
end
|
|
@@ -318,11 +322,21 @@ module Rubik
|
|
|
318
322
|
links.to_h { |k, v| [k.to_s, v.to_s] }.sort.to_h
|
|
319
323
|
end
|
|
320
324
|
|
|
321
|
-
|
|
325
|
+
# Row allocation reads BOTH the meta cursor and the on-disk rows.
|
|
326
|
+
# load_meta deliberately degrades to {} on corrupt/missing meta.json;
|
|
327
|
+
# deriving the next row from meta alone then reused row 1 and evicted
|
|
328
|
+
# the record already stored there (issue #562). A create is refused if
|
|
329
|
+
# the computed row is somehow already occupied — eviction is never an
|
|
330
|
+
# acceptable allocation strategy.
|
|
331
|
+
def allocate_row(meta, records, type)
|
|
322
332
|
rows = (meta["next_row"] ||= {})
|
|
323
|
-
|
|
333
|
+
disk_max = records.map { |r| r["row"].to_i }.max || 0
|
|
334
|
+
row = [rows[type].to_i, disk_max].max + 1
|
|
335
|
+
raise ArgumentError, "row #{row} already exists in #{type}; refusing to overwrite" if records.any? { |r| r["row"].to_i == row }
|
|
336
|
+
|
|
337
|
+
rows[type] = row
|
|
324
338
|
meta["updated_at"] = Time.now.utc.iso8601
|
|
325
|
-
|
|
339
|
+
row
|
|
326
340
|
end
|
|
327
341
|
|
|
328
342
|
def meta_bump_counts(meta, type)
|
|
@@ -331,6 +345,13 @@ module Rubik
|
|
|
331
345
|
end
|
|
332
346
|
|
|
333
347
|
def meta_set_ref(meta, name, id)
|
|
348
|
+
# One ref-name guard for BOTH alias-creation paths (issue #602):
|
|
349
|
+
# put(ref:) previously skipped the validation set_ref enforces, so
|
|
350
|
+
# an alias with separators/unicode could reach meta.json and yield a
|
|
351
|
+
# permanently unreadable refs route.
|
|
352
|
+
name = name.to_s
|
|
353
|
+
raise ArgumentError, "invalid ref name '#{name}'" unless name.match?(REF_PATTERN)
|
|
354
|
+
|
|
334
355
|
refs = (meta["refs"] ||= {})
|
|
335
356
|
refs[name] = id
|
|
336
357
|
meta["updated_at"] = Time.now.utc.iso8601
|
|
@@ -62,7 +62,7 @@ module Rubik
|
|
|
62
62
|
|
|
63
63
|
clean_path = path.to_s.strip
|
|
64
64
|
clean_path = nil if clean_path.empty?
|
|
65
|
-
eff_timeout = timeout.to_i if timeout&.to_i&.positive?
|
|
65
|
+
eff_timeout = timeout.to_i.clamp(1, 600) if timeout&.to_i&.positive?
|
|
66
66
|
|
|
67
67
|
res = if clean_path || eff_timeout
|
|
68
68
|
begin
|
|
@@ -219,7 +219,13 @@ module Rubik
|
|
|
219
219
|
# contract through BOTH dispatch paths — no display-text parsing.
|
|
220
220
|
def command_result(cmd, res, duration_ms:)
|
|
221
221
|
exit_code = res[:exit_code]
|
|
222
|
-
|
|
222
|
+
# Explicit timeout flag plumbed through the whole chain
|
|
223
|
+
# (popen_capture → sandbox drivers → runner, issue #597-3), so a
|
|
224
|
+
# legitimate timeout(1) exit 124 no longer reads as a runner kill.
|
|
225
|
+
# The legacy exit-code inference remains ONLY for result hashes that
|
|
226
|
+
# genuinely do not carry the flag (pre-plumbing producers outside the
|
|
227
|
+
# sandbox driver chain).
|
|
228
|
+
timed_out = res.key?(:timed_out) ? res[:timed_out] == true : exit_code.to_i == 124
|
|
223
229
|
status_text = res[:ok] ? "OK" : "EXIT #{exit_code}"
|
|
224
230
|
shell_tag = res[:shell] ? " (#{res[:shell]})" : ""
|
|
225
231
|
out = "[#{status_text}]#{shell_tag} #{res[:output]}"
|
|
@@ -112,17 +112,13 @@ module Rubik
|
|
|
112
112
|
"relative to the project root (e.g. 'lib/app.rb', 'src/main.go', 'Gemfile').")
|
|
113
113
|
end
|
|
114
114
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
@buffer_manager.write(path, content)
|
|
123
|
-
rescue ArgumentError
|
|
124
|
-
@buffer_manager.write(path, content)
|
|
125
|
-
end
|
|
115
|
+
# NB: reset_baseline defaults to false on purpose. The buffer only
|
|
116
|
+
# replaces the tracked baseline for files that have no baseline yet
|
|
117
|
+
# (new files). Passing reset_baseline: true here would overwrite the
|
|
118
|
+
# original baseline of an ALREADY-loaded file, defeating undo and
|
|
119
|
+
# conflict restoration — the buffer could never restore the file's
|
|
120
|
+
# true original state after a full overwrite.
|
|
121
|
+
@buffer_manager.write(path, content)
|
|
126
122
|
"Successfully wrote to in-memory buffer: #{path}"
|
|
127
123
|
rescue Errno::EACCES => e
|
|
128
124
|
ToolOutput.error(DiagnosticReporter.render_permission_denied(path, operation: "write", reason: e.message))
|
|
@@ -186,7 +182,7 @@ module Rubik
|
|
|
186
182
|
partial_note = IndexMessages.note_for(idx)
|
|
187
183
|
# Path-filtered list drives the B9 explanation: an extension miss in
|
|
188
184
|
# an INDEXED directory must read "no such files here", not "ignored".
|
|
189
|
-
path_filtered = filter.empty? ? files.keys : files.keys.select { |f| f.start_with?(filter) }
|
|
185
|
+
path_filtered = filter.empty? ? files.keys : files.keys.select { |f| f == filter || f.start_with?("#{filter}/") }
|
|
190
186
|
file_list = ext_filter && !ext_filter.empty? ? path_filtered.select { |f| f.end_with?(ext_filter) } : path_filtered
|
|
191
187
|
|
|
192
188
|
return with_note(ignored_directory_message(filter, ext_filter), partial_note) if path_filtered.empty? && existing_but_unindexed?(@root_dir, filter)
|
|
@@ -66,7 +66,7 @@ module Rubik
|
|
|
66
66
|
path_filter, outside_error = BaseTool.normalize_path_filter(path_filter, @root_dir)
|
|
67
67
|
return ToolOutput.error(BaseTool.traversal_blocked_message(param(args, :path), @root_dir, context_index)) if outside_error
|
|
68
68
|
|
|
69
|
-
case_sensitive = param(args, :case_sensitive, default: false)
|
|
69
|
+
case_sensitive = param(args, :case_sensitive, type: :flag, default: false)
|
|
70
70
|
max_results = param(args, :max_results, type: :integer, default: 50)
|
|
71
71
|
max_results = 50 if max_results <= 0
|
|
72
72
|
|
|
@@ -270,7 +270,8 @@ module Rubik
|
|
|
270
270
|
def pass_path?(file_key, path_filter)
|
|
271
271
|
return true if path_filter.empty?
|
|
272
272
|
|
|
273
|
-
|
|
273
|
+
filter = path_filter.sub(%r{^\./}, "")
|
|
274
|
+
file_key == filter || file_key.start_with?("#{filter}/")
|
|
274
275
|
end
|
|
275
276
|
|
|
276
277
|
def pass_extension?(file_key, ext_filter)
|
|
@@ -131,14 +131,17 @@ module Rubik
|
|
|
131
131
|
def validate_question(q_data, index:)
|
|
132
132
|
return ToolOutput.error("Invalid question #{index}: item must be an object with 'question' and 'options' properties.") unless q_data.is_a?(Hash)
|
|
133
133
|
|
|
134
|
-
|
|
134
|
+
# Question text and options are model-controlled; strip CSI/OSC
|
|
135
|
+
# escapes (issue #592) so prompt-injected sequences cannot reach the
|
|
136
|
+
# raw terminal through the dialog card or the echoed response.
|
|
137
|
+
q_text = Rubik::UI::Capability.strip_ansi((q_data["question"] || q_data[:question]).to_s.strip)
|
|
135
138
|
raw_options = q_data["options"] || q_data[:options]
|
|
136
139
|
is_multi = q_data["is_multi_select"] || q_data[:is_multi_select] || false
|
|
137
140
|
|
|
138
141
|
return ToolOutput.error("Invalid question #{index}: question text cannot be blank.") if q_text.empty?
|
|
139
142
|
return ToolOutput.error("Invalid question #{index}: must provide an array of selectable options.") unless raw_options.is_a?(Array)
|
|
140
143
|
|
|
141
|
-
options = raw_options.map(
|
|
144
|
+
options = raw_options.map { |o| Rubik::UI::Capability.strip_ansi(o.to_s.strip) }.reject(&:empty?).uniq
|
|
142
145
|
return ToolOutput.error("Invalid question #{index}: must provide at least 2 distinct non-empty selectable options.") if options.size < 2
|
|
143
146
|
|
|
144
147
|
{ question: q_text, options: options, is_multi: is_multi }
|
|
@@ -7,6 +7,35 @@ require_relative "../../platform"
|
|
|
7
7
|
|
|
8
8
|
module Rubik
|
|
9
9
|
module Tools
|
|
10
|
+
# Single source of truth for LSP DiagnosticSeverity (spec 3.17:
|
|
11
|
+
# 1=Error, 2=Warning, 3=Information, 4=Hint). Both the tool's human-facing
|
|
12
|
+
# output and the prompt builder's <diagnostic> tags map through here so a
|
|
13
|
+
# style hint can never be overstated as an error/warning (issue #546).
|
|
14
|
+
module LSPSeverity
|
|
15
|
+
# severity => [canonical label (prompt), display label (tool output)]
|
|
16
|
+
SEVERITIES = {
|
|
17
|
+
1 => ["error", "ERROR"].freeze,
|
|
18
|
+
2 => ["warning", "WARN"].freeze,
|
|
19
|
+
3 => ["info", "INFO"].freeze,
|
|
20
|
+
4 => ["hint", "HINT"].freeze
|
|
21
|
+
}.freeze
|
|
22
|
+
DEFAULT = SEVERITIES[4]
|
|
23
|
+
|
|
24
|
+
module_function
|
|
25
|
+
|
|
26
|
+
def entry(severity)
|
|
27
|
+
SEVERITIES.fetch(severity.to_s.to_i, DEFAULT)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def label(severity)
|
|
31
|
+
entry(severity)[0]
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def display(severity)
|
|
35
|
+
entry(severity)[1]
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
10
39
|
class BaseLSPTool < BaseTool
|
|
11
40
|
REQUIRES = [Rubik::Coeffects::LSP_MANAGER].freeze
|
|
12
41
|
|
|
@@ -81,8 +110,22 @@ module Rubik
|
|
|
81
110
|
|
|
82
111
|
if path.empty?
|
|
83
112
|
all = mgr.all_diagnostic_snapshots
|
|
84
|
-
total_issues = all.values.sum { |snapshot| snapshot[:diagnostics].size }
|
|
85
113
|
pending = all.values.count { |snapshot| snapshot[:state] == :pending }
|
|
114
|
+
# Pull-capable servers (diagnosticProvider) never push
|
|
115
|
+
# publishDiagnostics; pending-heavy workspaces trigger a bounded
|
|
116
|
+
# pull refresh (issue #583) instead of reporting "pending" forever.
|
|
117
|
+
if pending.positive? && mgr.respond_to?(:refresh_pending_diagnostic_snapshots)
|
|
118
|
+
mgr.refresh_pending_diagnostic_snapshots
|
|
119
|
+
deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + diagnostic_refresh_timeout
|
|
120
|
+
loop do
|
|
121
|
+
all = mgr.all_diagnostic_snapshots
|
|
122
|
+
pending = all.values.count { |snapshot| snapshot[:state] == :pending }
|
|
123
|
+
break if pending.zero? || Process.clock_gettime(Process::CLOCK_MONOTONIC) >= deadline
|
|
124
|
+
|
|
125
|
+
sleep 0.05
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
total_issues = all.values.sum { |snapshot| snapshot[:diagnostics].size }
|
|
86
129
|
unversioned = all.values.count { |snapshot| snapshot[:state] == :unversioned }
|
|
87
130
|
if total_issues.zero?
|
|
88
131
|
if pending.positive?
|
|
@@ -107,7 +150,7 @@ module Rubik
|
|
|
107
150
|
end
|
|
108
151
|
lines << "\nFile: #{fpath} (#{diags.size}; #{freshness}):"
|
|
109
152
|
diags.each do |d|
|
|
110
|
-
sev = d["severity"]
|
|
153
|
+
sev = LSPSeverity.display(d["severity"])
|
|
111
154
|
start_line = (d.dig("range", "start", "line") || 0) + 1
|
|
112
155
|
lines << " • [#{sev}] Line #{start_line}: #{d['message']}"
|
|
113
156
|
end
|
|
@@ -116,7 +159,7 @@ module Rubik
|
|
|
116
159
|
end
|
|
117
160
|
else
|
|
118
161
|
snapshot = if mgr.respond_to?(:wait_for_diagnostics)
|
|
119
|
-
mgr.wait_for_diagnostics(path, timeout:
|
|
162
|
+
mgr.wait_for_diagnostics(path, timeout: diagnostic_refresh_timeout)
|
|
120
163
|
else
|
|
121
164
|
mgr.diagnostics_snapshot_for(path)
|
|
122
165
|
end
|
|
@@ -137,12 +180,7 @@ module Rubik
|
|
|
137
180
|
end
|
|
138
181
|
lines = ["=== LSP Diagnostics for #{path} (#{diags.size} issue(s); #{freshness}) ==="]
|
|
139
182
|
diags.each do |d|
|
|
140
|
-
sev =
|
|
141
|
-
when 1 then "ERROR"
|
|
142
|
-
when 2 then "WARN"
|
|
143
|
-
when 3 then "INFO"
|
|
144
|
-
else "HINT"
|
|
145
|
-
end
|
|
183
|
+
sev = LSPSeverity.display(d["severity"])
|
|
146
184
|
range = d["range"] || {}
|
|
147
185
|
start_line = (range.dig("start", "line") || 0) + 1
|
|
148
186
|
start_char = (range.dig("start", "character") || 0) + 1
|
|
@@ -152,6 +190,18 @@ module Rubik
|
|
|
152
190
|
end
|
|
153
191
|
end
|
|
154
192
|
end
|
|
193
|
+
|
|
194
|
+
private
|
|
195
|
+
|
|
196
|
+
# Bounded wait after workspace-wide diagnostic pulls (issue #583);
|
|
197
|
+
# reuses lsp.feedback_timeout (config/defaults.rb) so the tool never
|
|
198
|
+
# hangs on a wedged server.
|
|
199
|
+
def diagnostic_refresh_timeout
|
|
200
|
+
timeout = effective_lsp_manager&.config&.fetch("lsp.feedback_timeout", nil)
|
|
201
|
+
timeout.is_a?(Numeric) && timeout.positive? ? timeout.to_f : 0.5
|
|
202
|
+
rescue StandardError
|
|
203
|
+
0.5
|
|
204
|
+
end
|
|
155
205
|
end
|
|
156
206
|
|
|
157
207
|
class LSPHoverTool < BaseLSPTool
|
|
@@ -24,6 +24,10 @@ module Rubik
|
|
|
24
24
|
properties: {
|
|
25
25
|
recipient: { type: "string", description: "The recipient subagent conversation ID (e.g. 'subagent-1')" },
|
|
26
26
|
message: { type: "string", description: "The message content to deliver" },
|
|
27
|
+
in_reply_to: { type: "string",
|
|
28
|
+
description: "Question id this message answers — REQUIRED when replying to a subagent " \
|
|
29
|
+
"ask_question notification (echo the question_id from the notification); " \
|
|
30
|
+
"omit for ordinary steering" },
|
|
27
31
|
steps: { type: "integer", description: "Optional additional step budget to grant alongside message" }
|
|
28
32
|
},
|
|
29
33
|
required: ["recipient", "message"]
|
|
@@ -63,11 +67,12 @@ module Rubik
|
|
|
63
67
|
return ToolOutput.error("Missing required parameter 'message'.") if msg.empty?
|
|
64
68
|
|
|
65
69
|
steps = args["steps"] || args[:steps]
|
|
70
|
+
in_reply_to = args["in_reply_to"] || args[:in_reply_to]
|
|
66
71
|
sender = subagent_sender_id
|
|
67
72
|
delivered = if sender
|
|
68
|
-
sup.send_message(recipient, msg, additional_steps: steps, _sender_id: sender)
|
|
73
|
+
sup.send_message(recipient, msg, additional_steps: steps, _sender_id: sender, in_reply_to: in_reply_to)
|
|
69
74
|
else
|
|
70
|
-
sup.send_message(recipient, msg, additional_steps: steps)
|
|
75
|
+
sup.send_message(recipient, msg, additional_steps: steps, in_reply_to: in_reply_to)
|
|
71
76
|
end
|
|
72
77
|
return delivery_text(recipient) if delivered == true
|
|
73
78
|
return queued_text(recipient, steps) if delivered == :queued
|
|
@@ -36,7 +36,7 @@ module Rubik
|
|
|
36
36
|
name: "show_file", aliases: ["show"],
|
|
37
37
|
description: "Read a stored entity (review report, plan, goal snapshot, note...) from the central " \
|
|
38
38
|
"storage database. As the ROOT agent, the full content renders DIRECTLY to the user's " \
|
|
39
|
-
"terminal and you only get a one-line stub — use it for 'show
|
|
39
|
+
"terminal and you only get a one-line stub — use it for 'show' requests instead of " \
|
|
40
40
|
"read_file + re-echoing. In a subagent context the full content loads into YOUR context " \
|
|
41
41
|
"like read_file (terminal rendering is the root agent's job). Accepts rubik://storage " \
|
|
42
42
|
"URIs only, including refs form 'rubik://storage/<project>/refs/<alias>'.",
|
|
@@ -332,13 +332,13 @@ module Rubik
|
|
|
332
332
|
previous_origin = previous_tool ? @tool_registry.origin(name) : nil
|
|
333
333
|
@tool_registry.register(tool_instance, origin: :synthesis)
|
|
334
334
|
|
|
335
|
-
#
|
|
336
|
-
# overlay/MCP/synthesized tool, the inverse restores the previous
|
|
337
|
-
# instance instead of leaving a hole in the toolbelt.
|
|
335
|
+
# One keyed inverse restores the previous instance on hot-update.
|
|
338
336
|
ctx = active_context
|
|
339
337
|
if ctx.respond_to?(:on_dispose) || ctx.respond_to?(:register_disposable)
|
|
340
338
|
hook = ctx.respond_to?(:on_dispose) ? :on_dispose : :register_disposable
|
|
341
|
-
|
|
339
|
+
prior = (@synthesis_inverses ||= {})[name]
|
|
340
|
+
ctx.unregister_disposable(prior) if prior && ctx.respond_to?(:unregister_disposable)
|
|
341
|
+
@synthesis_inverses[name] = ctx.send(hook) do
|
|
342
342
|
if previous_tool && @tool_registry.respond_to?(:swap)
|
|
343
343
|
@tool_registry.swap(name, previous_tool, origin: previous_origin || :overlay)
|
|
344
344
|
else
|
|
@@ -247,7 +247,10 @@ module Rubik
|
|
|
247
247
|
end
|
|
248
248
|
|
|
249
249
|
def kill_child(pid)
|
|
250
|
-
|
|
250
|
+
# kill_tree (not a bare KILL): handler code under verification may
|
|
251
|
+
# have spawned subprocesses that a direct-child-only kill would
|
|
252
|
+
# orphan (issue #597).
|
|
253
|
+
Rubik::Platform.kill_tree(pid)
|
|
251
254
|
Process.wait(pid)
|
|
252
255
|
rescue StandardError
|
|
253
256
|
nil
|
|
@@ -20,7 +20,7 @@ module Rubik
|
|
|
20
20
|
# StepExecutor::ERROR_PREFIXES (kept as an alias there).
|
|
21
21
|
ERROR_PREFIXES = [
|
|
22
22
|
"-- ", "Error:", "Error ", "Usage:", "Pre-flight verification failed",
|
|
23
|
-
"Bilinmeyen komut", "Failed", "Security blocked", "Command error",
|
|
23
|
+
"Unknown command", "Bilinmeyen komut", "Failed", "Security blocked", "Command error",
|
|
24
24
|
"[EXIT ", "Test run [FAILED]", "Lint [FAILED]", "[CONFLICT]", "[CONFLICT "
|
|
25
25
|
].freeze
|
|
26
26
|
|
data/lib/rubik/ui/banner.rb
CHANGED
|
@@ -16,7 +16,7 @@ module Rubik
|
|
|
16
16
|
return nil unless Capability.interactive?(input: shell.input, output: shell.output)
|
|
17
17
|
|
|
18
18
|
routed = Statusline.current_route(shell)
|
|
19
|
-
model = routed ? Statusline.model_label(routed) : "model
|
|
19
|
+
model = routed ? Statusline.model_label(routed) : "model not configured"
|
|
20
20
|
project = File.basename(shell.buffer_manager&.root_dir || Dir.pwd)
|
|
21
21
|
branch = shell.detect_git_branch || "no-git"
|
|
22
22
|
|
|
@@ -24,13 +24,13 @@ module Rubik
|
|
|
24
24
|
"🎲 Rubik v#{Rubik::VERSION}",
|
|
25
25
|
theme.paint(model, :info),
|
|
26
26
|
theme.paint("#{project} · #{branch}", :dim),
|
|
27
|
-
theme.paint("!help
|
|
27
|
+
theme.paint("!help commands · ctrl+c interrupt · !config settings", :dim)
|
|
28
28
|
]
|
|
29
29
|
|
|
30
30
|
if Rubik::Platform.linux? && Rubik::Platform.which("bwrap") &&
|
|
31
31
|
!Rubik::Storage::Layout.config_get(shell.config, "sandbox.enabled", false) &&
|
|
32
32
|
Rubik::Storage::Layout.config_get(shell.config, "sandbox.prompt_on_startup", true)
|
|
33
|
-
lines << theme.paint("💡 Linux & bwrap
|
|
33
|
+
lines << theme.paint("💡 Linux & bwrap detected: hardware OS isolation can be enabled with '!sandbox on'", :warn)
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
Frame.draw(
|
data/lib/rubik/ui/dialog.rb
CHANGED
|
@@ -34,10 +34,12 @@ module Rubik
|
|
|
34
34
|
choices = options.uniq.dup
|
|
35
35
|
choices << "Other (write-in response)" if allow_custom
|
|
36
36
|
|
|
37
|
-
answer = p.select("
|
|
37
|
+
answer = p.select("Select an option:", choices, filter: true, per_page: 10)
|
|
38
38
|
if answer == "Other (write-in response)"
|
|
39
|
-
custom = p.ask("
|
|
40
|
-
|
|
39
|
+
custom = p.ask("Your answer:")
|
|
40
|
+
# An empty write-in is "no selection" — never bind the
|
|
41
|
+
# model-authored first option as the user's choice (#559).
|
|
42
|
+
custom.to_s.strip.empty? ? nil : "Other (write-in): #{custom.strip}"
|
|
41
43
|
else
|
|
42
44
|
answer
|
|
43
45
|
end
|
|
@@ -57,9 +59,10 @@ module Rubik
|
|
|
57
59
|
|
|
58
60
|
render_card(question, multi: true)
|
|
59
61
|
p = build_prompt
|
|
60
|
-
answers = p.multi_select("
|
|
62
|
+
answers = p.multi_select("Select options (Space: toggle, Enter: confirm):",
|
|
61
63
|
options.uniq, filter: true, per_page: 10)
|
|
62
|
-
|
|
64
|
+
# An empty confirmation means no selection, not the first option (#559).
|
|
65
|
+
answers
|
|
63
66
|
rescue Interrupt, StandardError
|
|
64
67
|
:cancelled
|
|
65
68
|
ensure
|
|
@@ -80,11 +83,15 @@ module Rubik
|
|
|
80
83
|
def render_card(question, multi: false)
|
|
81
84
|
return unless @shell&.output
|
|
82
85
|
|
|
83
|
-
|
|
86
|
+
# The question is model-authored; strip CSI/OSC escapes before they
|
|
87
|
+
# are painted (issue #592) — Frame.draw strips only for width
|
|
88
|
+
# measurement, so raw sequences would reach the terminal.
|
|
89
|
+
safe_question = Capability.strip_ansi(question.to_s)
|
|
90
|
+
subtitle = multi ? "Multi-Select (Space: Select/Deselect · Enter: Confirm)" : "Single-Select (Arrow keys: Navigate · Enter: Confirm)"
|
|
84
91
|
card = Frame.draw(
|
|
85
|
-
[@theme.paint(
|
|
92
|
+
[@theme.paint(safe_question, :bold), @theme.paint(subtitle, :dim)],
|
|
86
93
|
theme: @theme,
|
|
87
|
-
title: @theme.paint("#{@theme.glyph(:action)}
|
|
94
|
+
title: @theme.paint("#{@theme.glyph(:action)} AGENT QUESTION", :accent)
|
|
88
95
|
)
|
|
89
96
|
@shell.output.puts(card)
|
|
90
97
|
end
|
data/lib/rubik/ui/diff_viewer.rb
CHANGED
|
@@ -50,23 +50,23 @@ module Rubik
|
|
|
50
50
|
# keypress uses the same raw-mode path as every other UI surface.
|
|
51
51
|
def offer_actions(shell, theme)
|
|
52
52
|
prompt = Approvals.build_prompt(shell)
|
|
53
|
-
key = prompt.keypress(theme.paint(" a:
|
|
53
|
+
key = prompt.keypress(theme.paint(" a: apply (!apply) · q or enter: exit ", :dim))
|
|
54
54
|
apply_all(shell) if key.to_s.strip.downcase == "a"
|
|
55
55
|
rescue Interrupt
|
|
56
56
|
Rubik::REPL::InterruptHandler.restore_console_after_interrupt
|
|
57
57
|
rescue StandardError => e
|
|
58
58
|
# apply! fails loud on containment breaks and IO errors — the user
|
|
59
59
|
# pressed "a", so the verdict must reach them, not vanish here.
|
|
60
|
-
shell.output.puts "\n[
|
|
60
|
+
shell.output.puts "\n[Error] Apply failed: #{e.message}"
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
def apply_all(shell)
|
|
64
64
|
applied = shell.buffer_manager.apply!
|
|
65
65
|
if applied.empty?
|
|
66
|
-
shell.output.puts "
|
|
66
|
+
shell.output.puts "No changes left to apply."
|
|
67
67
|
else
|
|
68
68
|
shell.sync_context_and_ast(applied)
|
|
69
|
-
shell.output.puts "
|
|
69
|
+
shell.output.puts "Applied: #{applied.join(', ')}"
|
|
70
70
|
end
|
|
71
71
|
end
|
|
72
72
|
|
data/lib/rubik/ui/frame.rb
CHANGED
|
@@ -69,9 +69,19 @@ module Rubik
|
|
|
69
69
|
ellipsis = theme.glyph(:ellipsis)
|
|
70
70
|
return str if display_width(str) <= max
|
|
71
71
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
# Slice by accumulated display cells, not characters: a CJK/emoji run
|
|
73
|
+
# sliced by character count can still overrun the frame (#559).
|
|
74
|
+
budget = [max - display_width(ellipsis), 0].max
|
|
75
|
+
kept = +""
|
|
76
|
+
used = 0
|
|
77
|
+
str.each_char do |chr|
|
|
78
|
+
width = display_width(chr)
|
|
79
|
+
break if used + width > budget
|
|
80
|
+
|
|
81
|
+
kept << chr
|
|
82
|
+
used += width
|
|
83
|
+
end
|
|
84
|
+
"#{kept}#{ellipsis}"
|
|
75
85
|
end
|
|
76
86
|
|
|
77
87
|
# East-Asian wide + common emoji blocks that render two columns wide
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "tty-markdown"
|
|
4
|
+
require_relative "capability"
|
|
4
5
|
|
|
5
6
|
module Rubik
|
|
6
7
|
module UI
|
|
@@ -56,9 +57,14 @@ module Rubik
|
|
|
56
57
|
# command output). Falls back to the raw text when styling is off.
|
|
57
58
|
def self.render_document(text, theme, enabled: true)
|
|
58
59
|
return text if text.nil? || text.empty?
|
|
59
|
-
return text unless enabled && theme.color?
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
# Strip OSC/CSI from model text before it reaches the terminal (or
|
|
62
|
+
# TTY::Markdown, which preserves those sequences). The streaming
|
|
63
|
+
# instance path already strips per line; batch must match (#559).
|
|
64
|
+
safe_text = Rubik::UI::Capability.strip_ansi(text)
|
|
65
|
+
return safe_text unless enabled && theme.color?
|
|
66
|
+
|
|
67
|
+
TTY::Markdown.parse(safe_text, color: :always)
|
|
62
68
|
end
|
|
63
69
|
|
|
64
70
|
private
|
data/lib/rubik/ui/panel.rb
CHANGED
|
@@ -23,11 +23,11 @@ module Rubik
|
|
|
23
23
|
def render(shell, theme)
|
|
24
24
|
fibers = shell.runtime_manager&.fibers || {}
|
|
25
25
|
if fibers.empty?
|
|
26
|
-
shell.output.puts "
|
|
26
|
+
shell.output.puts "No registered fiber/agent."
|
|
27
27
|
return
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
-
shell.output.puts "===
|
|
30
|
+
shell.output.puts "=== Agent / Fiber Panel ==="
|
|
31
31
|
rows = fibers.values.sort_by { |f| STATE_ORDER[f.state] || 99 }
|
|
32
32
|
rows.each do |fiber|
|
|
33
33
|
shell.output.puts detail_line(fiber, theme)
|
|
@@ -50,9 +50,9 @@ module Rubik
|
|
|
50
50
|
inst = fiber.instance
|
|
51
51
|
if inst.respond_to?(:step_count)
|
|
52
52
|
depth = fiber.sub_context ? " · Ω#{fiber.sub_context.disposable_count}" : ""
|
|
53
|
-
"
|
|
53
|
+
"step #{inst.step_count}/#{inst.max_steps}#{depth}"
|
|
54
54
|
elsif fiber.state == :failed
|
|
55
|
-
"
|
|
55
|
+
"error: #{fiber.last_error&.message.to_s[0, 50]}"
|
|
56
56
|
else
|
|
57
57
|
deps = fiber.inject
|
|
58
58
|
deps.empty? ? "-" : "coeffects: #{deps.join(', ')}"
|
|
@@ -62,8 +62,8 @@ module Rubik
|
|
|
62
62
|
def select_fiber(shell, rows, _theme)
|
|
63
63
|
prompt = Approvals.build_prompt(shell)
|
|
64
64
|
choices = rows.map { |f| { name: "#{STATE_GLYPHS[f.state]} #{f.name}", value: f } }
|
|
65
|
-
choices << { name: "←
|
|
66
|
-
prompt.select("
|
|
65
|
+
choices << { name: "← exit", value: nil }
|
|
66
|
+
prompt.select("Select a fiber for details:") do |menu|
|
|
67
67
|
choices.each { |c| menu.choice c[:name], c[:value] }
|
|
68
68
|
end
|
|
69
69
|
rescue Interrupt
|
|
@@ -77,15 +77,15 @@ module Rubik
|
|
|
77
77
|
inst = fiber.instance
|
|
78
78
|
shell.output.puts
|
|
79
79
|
shell.output.puts theme.paint("── #{fiber.name} ──", :bold)
|
|
80
|
-
shell.output.puts "
|
|
80
|
+
shell.output.puts " State : #{STATE_GLYPHS[fiber.state]} #{fiber.state}"
|
|
81
81
|
shell.output.puts " Coeffects : #{fiber.inject.join(', ')}"
|
|
82
|
-
shell.output.puts " Ω
|
|
82
|
+
shell.output.puts " Ω depth : #{fiber.sub_context ? fiber.sub_context.disposable_count : 0}"
|
|
83
83
|
if inst.respond_to?(:step_count)
|
|
84
|
-
shell.output.puts "
|
|
84
|
+
shell.output.puts " Step : #{inst.step_count}/#{inst.max_steps}"
|
|
85
85
|
shell.output.puts " Token : #{inst.total_tokens.inspect}" if inst.respond_to?(:total_tokens)
|
|
86
86
|
end
|
|
87
|
-
shell.output.puts "
|
|
88
|
-
shell.output.puts theme.paint(" (enter
|
|
87
|
+
shell.output.puts " Last error : #{fiber.last_error&.message}" if fiber.last_error
|
|
88
|
+
shell.output.puts theme.paint(" (press enter to return to the panel)", :dim)
|
|
89
89
|
end
|
|
90
90
|
|
|
91
91
|
def interactive?(shell)
|
data/lib/rubik/ui/renderer.rb
CHANGED
|
@@ -105,7 +105,10 @@ module Rubik
|
|
|
105
105
|
if level >= Rubik::REPL::StepFormatter::LEVEL_VERBOSE
|
|
106
106
|
"#{header} #{@theme.paint(Rubik::Platform.safe_json_generate(args), :dim)}"
|
|
107
107
|
else
|
|
108
|
-
|
|
108
|
+
# Tool args are model-controlled; strip CSI/OSC escapes the same way
|
|
109
|
+
# the sibling render paths do (issue #592) so prompt-injected
|
|
110
|
+
# sequences cannot reach the raw terminal.
|
|
111
|
+
summary = pretty_storage_arg(Rubik::UI::Capability.strip_ansi(@legacy.primary_arg_value(args).to_s))
|
|
109
112
|
summary.empty? ? header : "#{header} #{theme_dim_dash(summary)}"
|
|
110
113
|
end
|
|
111
114
|
end
|
|
@@ -142,13 +145,13 @@ module Rubik
|
|
|
142
145
|
|
|
143
146
|
status = (step_info[:status] || :ok).to_sym
|
|
144
147
|
duration = step_info[:duration_ms] || 0.0
|
|
145
|
-
output = step_info[:output].to_s
|
|
148
|
+
output = Rubik::UI::Capability.strip_ansi(step_info[:output].to_s)
|
|
146
149
|
branch = "#{@theme.glyph(:branch)} "
|
|
147
150
|
|
|
148
151
|
if status != :ok
|
|
149
|
-
err = step_info[:error]
|
|
150
|
-
err = output.lines.first.to_s.strip if err.
|
|
151
|
-
err = "Command failed" if err.
|
|
152
|
+
err = Rubik::UI::Capability.strip_ansi(step_info[:error].to_s)
|
|
153
|
+
err = output.lines.first.to_s.strip if err.empty?
|
|
154
|
+
err = "Command failed" if err.empty?
|
|
152
155
|
if err.start_with?("Security blocked:") || output.start_with?("Security blocked:")
|
|
153
156
|
sec_line = output.lines.first.to_s.strip
|
|
154
157
|
hint = output[/!(?:allow-cmd|allow-dir)\s+[^\n]+/]&.strip
|
|
@@ -176,8 +179,8 @@ module Rubik
|
|
|
176
179
|
return nil if level < Rubik::REPL::StepFormatter::LEVEL_VERBOSE
|
|
177
180
|
return nil if step_info[:streamed] == true
|
|
178
181
|
|
|
179
|
-
first_line = @legacy.thought_first_line(step_info[:content])
|
|
180
|
-
return nil if first_line.
|
|
182
|
+
first_line = Rubik::UI::Capability.strip_ansi(@legacy.thought_first_line(step_info[:content]).to_s)
|
|
183
|
+
return nil if first_line.empty?
|
|
181
184
|
|
|
182
185
|
" #{@theme.paint("#{@theme.glyph(:thought)} #{first_line}", :thought)}"
|
|
183
186
|
end
|
data/lib/rubik/ui/spinner.rb
CHANGED
|
@@ -110,7 +110,7 @@ module Rubik
|
|
|
110
110
|
def current_message(verb, step_part, elapsed)
|
|
111
111
|
seconds = elapsed.to_i
|
|
112
112
|
suffix = seconds.positive? ? " · #{seconds}s" : ""
|
|
113
|
-
"#{@theme.paint(verb, :accent)}#{step_part}#{suffix} (ctrl+c:
|
|
113
|
+
"#{@theme.paint(verb, :accent)}#{step_part}#{suffix} (ctrl+c: interrupt)"
|
|
114
114
|
end
|
|
115
115
|
|
|
116
116
|
def next_verb
|
data/lib/rubik/ui/statusline.rb
CHANGED
|
@@ -76,15 +76,15 @@ module Rubik
|
|
|
76
76
|
|
|
77
77
|
def dirty_segment(shell, theme)
|
|
78
78
|
count = shell.buffer_manager&.dirty? ? (shell.buffer_manager.dirty_files&.size || 0) : 0
|
|
79
|
-
count.zero? ? "
|
|
79
|
+
count.zero? ? "clean" : "#{count} #{theme.glyph(:dirty)}"
|
|
80
80
|
end
|
|
81
81
|
|
|
82
82
|
def sandbox_segment(shell)
|
|
83
83
|
if Rubik::Storage::Layout.config_get(shell.config, "sandbox.enabled", false)
|
|
84
|
-
net_str = Rubik::Storage::Layout.config_get(shell.config, "sandbox.allow_network", false) ? "
|
|
84
|
+
net_str = Rubik::Storage::Layout.config_get(shell.config, "sandbox.allow_network", false) ? "network-open" : "isolated"
|
|
85
85
|
"#{shell.sandbox_runner&.driver&.name || 'sandbox'}:#{net_str}"
|
|
86
86
|
else
|
|
87
|
-
"
|
|
87
|
+
"off"
|
|
88
88
|
end
|
|
89
89
|
end
|
|
90
90
|
|