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
|
@@ -60,21 +60,23 @@ module Rubik
|
|
|
60
60
|
end
|
|
61
61
|
|
|
62
62
|
# PERF: Fast-path deep UTF-8 cleaner. Performs zero-allocation Symbol
|
|
63
|
-
# validation via Symbol#name and tracks cycle object IDs in a
|
|
64
|
-
#
|
|
63
|
+
# validation via Symbol#name and tracks cycle object IDs in a path
|
|
64
|
+
# stack: ids are added on descent and removed after the children are
|
|
65
|
+
# visited, so only objects currently on the traversal path (genuine
|
|
66
|
+
# cycles) are cut — a shared object referenced from two sibling places
|
|
67
|
+
# is emitted in full both times (issue #597).
|
|
65
68
|
def clean_utf8_deep(obj, seen = nil)
|
|
69
|
+
stack = seen.is_a?(Array) ? seen : []
|
|
66
70
|
case obj
|
|
67
71
|
when String
|
|
68
72
|
clean_utf8(obj)
|
|
69
73
|
when Symbol
|
|
70
74
|
fast_clean_symbol(obj)
|
|
71
75
|
when Hash
|
|
72
|
-
seen ||= {}
|
|
73
76
|
obj_id = obj.object_id
|
|
74
|
-
return "{...}" if
|
|
75
|
-
|
|
76
|
-
seen.is_a?(Hash) ? (seen[obj_id] = true) : seen.add(obj_id)
|
|
77
|
+
return "{...}" if stack.include?(obj_id)
|
|
77
78
|
|
|
79
|
+
stack << obj_id
|
|
78
80
|
res = {}
|
|
79
81
|
obj.each do |k, v|
|
|
80
82
|
cleaned_k = if k.is_a?(Symbol)
|
|
@@ -82,27 +84,24 @@ module Rubik
|
|
|
82
84
|
elsif k.is_a?(String)
|
|
83
85
|
clean_utf8(k)
|
|
84
86
|
else
|
|
85
|
-
clean_utf8_deep(k,
|
|
87
|
+
clean_utf8_deep(k, stack)
|
|
86
88
|
end
|
|
87
|
-
res[cleaned_k] = clean_utf8_deep(v,
|
|
89
|
+
res[cleaned_k] = clean_utf8_deep(v, stack)
|
|
88
90
|
end
|
|
91
|
+
stack.pop
|
|
89
92
|
res
|
|
90
93
|
when Array
|
|
91
|
-
seen ||= {}
|
|
92
94
|
obj_id = obj.object_id
|
|
93
|
-
return "[...]" if
|
|
94
|
-
|
|
95
|
-
seen.is_a?(Hash) ? (seen[obj_id] = true) : seen.add(obj_id)
|
|
95
|
+
return "[...]" if stack.include?(obj_id)
|
|
96
96
|
|
|
97
|
-
|
|
97
|
+
stack << obj_id
|
|
98
|
+
obj.map { |item| clean_utf8_deep(item, stack) }.tap { stack.pop }
|
|
98
99
|
when Set
|
|
99
|
-
seen ||= {}
|
|
100
100
|
obj_id = obj.object_id
|
|
101
|
-
return Set.new(["[...]"]) if
|
|
102
|
-
|
|
103
|
-
seen.is_a?(Hash) ? (seen[obj_id] = true) : seen.add(obj_id)
|
|
101
|
+
return Set.new(["[...]"]) if stack.include?(obj_id)
|
|
104
102
|
|
|
105
|
-
|
|
103
|
+
stack << obj_id
|
|
104
|
+
obj.to_set { |item| clean_utf8_deep(item, stack) }.tap { stack.pop }
|
|
106
105
|
else
|
|
107
106
|
obj
|
|
108
107
|
end
|
data/lib/rubik/platform.rb
CHANGED
|
@@ -61,6 +61,33 @@ module Rubik
|
|
|
61
61
|
env
|
|
62
62
|
end
|
|
63
63
|
|
|
64
|
+
# Credential-shaped variable names stripped from child-process
|
|
65
|
+
# environments (issue #586). Matching is by underscore-delimited
|
|
66
|
+
# segment (case-insensitive) so OPENAI_API_KEY, MY_SECRET and
|
|
67
|
+
# AWS_ACCESS_KEY_ID are covered without matching words like
|
|
68
|
+
# "tokenizer". NOTE: integrity hygiene, NOT a confinement boundary.
|
|
69
|
+
CREDENTIAL_ENV_PATTERN = /
|
|
70
|
+
(?:_|\A)(?:KEY|TOKEN|SECRET|PASSWORD|PASSWD|PAT|CREDENTIALS?)(?:_|\z)
|
|
71
|
+
|\A(?:DATABASE|REDIS|MONGO|POSTGRES|MYSQL|AMQP)_URL\z
|
|
72
|
+
|_(?:DATABASE|CONNECTION)_URL\z
|
|
73
|
+
/ix
|
|
74
|
+
|
|
75
|
+
# sanitized_spawn_env plus an explicit nil for every credential-shaped
|
|
76
|
+
# host variable (spawn semantics: nil UNSETs it; benign variables stay
|
|
77
|
+
# out of the hash and remain normally inheritable). Consumers:
|
|
78
|
+
# TaskManager#start (issue #586) and Driver::ProcessDriver#child_env
|
|
79
|
+
# (both now delegate here — single shared CREDENTIAL_ENV_PATTERN).
|
|
80
|
+
# The MCP stdio transport keeps its own narrower pattern on purpose:
|
|
81
|
+
# it matches _REDIS_URL, which this pattern's underscore-URL branch
|
|
82
|
+
# does not, so this pattern is not a safe superset for that path.
|
|
83
|
+
def credential_free_env
|
|
84
|
+
env = sanitized_spawn_env
|
|
85
|
+
ENV.each_key do |key|
|
|
86
|
+
env[key] = nil if key.match?(CREDENTIAL_ENV_PATTERN)
|
|
87
|
+
end
|
|
88
|
+
env
|
|
89
|
+
end
|
|
90
|
+
|
|
64
91
|
def host_os
|
|
65
92
|
RbConfig::CONFIG["host_os"] || ""
|
|
66
93
|
end
|
data/lib/rubik/plugin/storage.rb
CHANGED
|
@@ -92,6 +92,8 @@ module Rubik
|
|
|
92
92
|
# against. Keyed by plugin name (the package root's basename).
|
|
93
93
|
def record_package(plugin_dir, name, scope: :project)
|
|
94
94
|
target_dir = scope.to_sym == :global ? global_plugins_dir : project_plugins_dir
|
|
95
|
+
# Fail-closed on a corrupt manifest (issue #596, cf. record_hash).
|
|
96
|
+
manifest_store.refuse_corrupt_manifest!(target_dir, :record, name.to_s)
|
|
95
97
|
manifest = load_manifest(target_dir)
|
|
96
98
|
manifest[name.to_s] = {
|
|
97
99
|
"type" => "directory",
|
|
@@ -143,6 +145,9 @@ module Rubik
|
|
|
143
145
|
|
|
144
146
|
if File.directory?(source_path)
|
|
145
147
|
plugin_name = File.basename(source_path)
|
|
148
|
+
# Same guard as remove_plugin (issues #554/#596).
|
|
149
|
+
return { ok: false, error: "Invalid plugin name: #{plugin_name.inspect}." } unless safe_plugin_name?(plugin_name, target_dir)
|
|
150
|
+
|
|
146
151
|
dest_path = File.join(target_dir, plugin_name)
|
|
147
152
|
|
|
148
153
|
if (violation = PackageInventory.violation(source_path))
|
|
@@ -159,9 +164,8 @@ module Rubik
|
|
|
159
164
|
return { ok: true, name: plugin_name, path: dest_path, type: :directory }
|
|
160
165
|
end
|
|
161
166
|
|
|
162
|
-
# Deterministic re-add (also the legacy
|
|
163
|
-
#
|
|
164
|
-
# the newly consented package.
|
|
167
|
+
# Deterministic re-add (also the legacy re-consent path): replace
|
|
168
|
+
# any previous copy so stale helpers cannot survive the re-consent.
|
|
165
169
|
FileUtils.rm_rf(dest_path)
|
|
166
170
|
FileUtils.cp_r(source_path, dest_path)
|
|
167
171
|
|
|
@@ -176,8 +180,12 @@ module Rubik
|
|
|
176
180
|
|
|
177
181
|
{ ok: true, name: plugin_name, path: dest_path, type: :directory }
|
|
178
182
|
else
|
|
183
|
+
source_name = File.basename(source_path)
|
|
179
184
|
plugin_name = File.basename(source_path, ".rb")
|
|
180
|
-
|
|
185
|
+
# Same guard as remove_plugin (issue #554) before the cp (issue #596).
|
|
186
|
+
return { ok: false, error: "Invalid plugin name: #{plugin_name.inspect}." } unless safe_plugin_name?(source_name, target_dir)
|
|
187
|
+
|
|
188
|
+
dest_path = File.join(target_dir, source_name)
|
|
181
189
|
FileUtils.cp(source_path, dest_path)
|
|
182
190
|
record_hash(dest_path, scope: scope)
|
|
183
191
|
|
|
@@ -189,6 +197,9 @@ module Rubik
|
|
|
189
197
|
|
|
190
198
|
def remove_plugin(name, scope: :project)
|
|
191
199
|
target_dir = scope.to_sym == :global ? global_plugins_dir : project_plugins_dir
|
|
200
|
+
|
|
201
|
+
return { ok: false, error: "Invalid plugin name: #{name.to_s.inspect}." } unless safe_plugin_name?(name, target_dir)
|
|
202
|
+
|
|
192
203
|
file_path = File.join(target_dir, "#{name}.rb")
|
|
193
204
|
dir_path = File.join(target_dir, name.to_s)
|
|
194
205
|
|
|
@@ -219,9 +230,25 @@ module Rubik
|
|
|
219
230
|
|
|
220
231
|
private
|
|
221
232
|
|
|
233
|
+
# A plugin name must resolve to a single path component directly under
|
|
234
|
+
# target_dir. Reject separators, traversal components (`.`/`..`),
|
|
235
|
+
# absolute paths and NUL bytes before any rm_f/rm_rf (issue #554).
|
|
236
|
+
# Any ordinary single-component name is allowed, so plugins keep working.
|
|
237
|
+
def safe_plugin_name?(name, target_dir)
|
|
238
|
+
component = name.to_s
|
|
239
|
+
return false if component.empty? || component == "." || component == ".."
|
|
240
|
+
return false if component.match?(%r{[/\\\0]})
|
|
241
|
+
|
|
242
|
+
base = File.expand_path(target_dir)
|
|
243
|
+
candidate = File.expand_path(component, base)
|
|
244
|
+
candidate.start_with?("#{base}#{File::SEPARATOR}") && File.dirname(candidate) == base
|
|
245
|
+
rescue ArgumentError
|
|
246
|
+
false
|
|
247
|
+
end
|
|
248
|
+
|
|
222
249
|
# The package root for a path inside the plugins dir: plugins/<first
|
|
223
|
-
# segment> when that segment is a DIRECTORY
|
|
224
|
-
#
|
|
250
|
+
# segment> when that segment is a DIRECTORY; nil for a single-file
|
|
251
|
+
# plugin or a path outside the plugins dir.
|
|
225
252
|
def package_root_for(path, plugins_dir)
|
|
226
253
|
base = File.expand_path(plugins_dir)
|
|
227
254
|
prefix = "#{base}#{File::SEPARATOR}"
|
|
@@ -239,8 +266,7 @@ module Rubik
|
|
|
239
266
|
|
|
240
267
|
# Whole-package verification. A legacy (entry-file-only) manifest cannot
|
|
241
268
|
# vouch for helpers that were never consented to, so it is rejected with
|
|
242
|
-
# an explicit re-consent path
|
|
243
|
-
# RUBIK_TRUST_OVERLAYS=1.
|
|
269
|
+
# an explicit re-consent path (re-add, or RUBIK_TRUST_OVERLAYS=1).
|
|
244
270
|
def verify_package_integrity(package_dir, scope: :project)
|
|
245
271
|
dir = scope.to_sym == :global ? global_plugins_dir : project_plugins_dir
|
|
246
272
|
name = File.basename(package_dir)
|
|
@@ -7,6 +7,7 @@ require_relative "../context/repo_context_reader"
|
|
|
7
7
|
# this module is the assembler: structure + service data only.
|
|
8
8
|
require_relative "doctrine"
|
|
9
9
|
require_relative "services"
|
|
10
|
+
require_relative "../tools/builtins/lsp"
|
|
10
11
|
|
|
11
12
|
module Rubik
|
|
12
13
|
module Prompt
|
|
@@ -250,7 +251,7 @@ module Rubik
|
|
|
250
251
|
|
|
251
252
|
all_diags.each do |fpath, diags|
|
|
252
253
|
diags.each do |d|
|
|
253
|
-
sev = d["severity"]
|
|
254
|
+
sev = Rubik::Tools::LSPSeverity.label(d["severity"])
|
|
254
255
|
total_errors += 1 if sev == "error"
|
|
255
256
|
start_line = (d.dig("range", "start", "line") || 0) + 1
|
|
256
257
|
msg = Rubik::Platform.xml_escape(d["message"])
|
|
@@ -201,8 +201,9 @@ module Rubik
|
|
|
201
201
|
"dedicated notification-evaluation turn — evaluate the pending notifications, act (extend budget, steer with " \
|
|
202
202
|
"send_message, retrieve results, wrap up, or report to the user), and conclude your turn again. Subagents can " \
|
|
203
203
|
"ask YOU questions mid-flight via `ask_question` — a question notification means that subagent is BLOCKED until " \
|
|
204
|
-
"you reply: answer it promptly with `send_message(recipient: '<id>', message: '<your answer>'
|
|
205
|
-
"
|
|
204
|
+
"you reply: answer it promptly with `send_message(recipient: '<id>', message: '<your answer>', " \
|
|
205
|
+
"in_reply_to: '<question_id>')` — echo the question_id from the notification, it times out otherwise. " \
|
|
206
|
+
"Call `#{Rubik::Orchestrator::Subagent::Notices.wait_hint_template}` only when synchronous waiting " \
|
|
206
207
|
"is strictly required. Never poll 'status' repeatedly in a loop."
|
|
207
208
|
end
|
|
208
209
|
end
|
data/lib/rubik/repair/loop.rb
CHANGED
|
@@ -2,18 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
require "json"
|
|
4
4
|
require "tempfile"
|
|
5
|
+
require_relative "../llm/session_header"
|
|
6
|
+
require_relative "../orchestrator/provider_resolver"
|
|
5
7
|
|
|
6
8
|
module Rubik
|
|
7
9
|
module Repair
|
|
8
10
|
class Loop
|
|
9
11
|
attr_reader :max_attempts, :attempts_made, :config
|
|
10
12
|
|
|
11
|
-
def initialize(provider:, buffer_manager:, snapshot_store:, adapter_registry:, max_attempts: nil, config: nil
|
|
13
|
+
def initialize(provider:, buffer_manager:, snapshot_store:, adapter_registry:, max_attempts: nil, config: nil,
|
|
14
|
+
session_key: nil)
|
|
12
15
|
@provider = provider
|
|
13
16
|
@buffer_manager = buffer_manager
|
|
14
17
|
@snapshot_store = snapshot_store
|
|
15
18
|
@adapter_registry = adapter_registry
|
|
16
19
|
@config = config
|
|
20
|
+
@session_key = session_key
|
|
17
21
|
@max_attempts = (max_attempts || config&.fetch("repair.max_attempts", 3) || 3).to_i
|
|
18
22
|
@attempts_made = 0
|
|
19
23
|
end
|
|
@@ -21,15 +25,31 @@ module Rubik
|
|
|
21
25
|
def repair(diagnostics, target_file, lang = :ruby)
|
|
22
26
|
@attempts_made = 0
|
|
23
27
|
current_diag = diagnostics
|
|
28
|
+
baseline_recorded = false
|
|
24
29
|
|
|
25
30
|
while @attempts_made < @max_attempts
|
|
26
31
|
@attempts_made += 1
|
|
27
32
|
|
|
33
|
+
# Capture the pre-repair state once so an aborted attempt restores
|
|
34
|
+
# pending edits instead of an empty buffer (issue #544).
|
|
35
|
+
unless baseline_recorded
|
|
36
|
+
@snapshot_store.record_baseline(@buffer_manager)
|
|
37
|
+
baseline_recorded = true
|
|
38
|
+
end
|
|
39
|
+
|
|
28
40
|
@snapshot_store.create_snapshot(@buffer_manager)
|
|
29
41
|
|
|
30
42
|
begin
|
|
31
43
|
prompt = build_repair_prompt(current_diag, target_file, @attempts_made)
|
|
32
|
-
|
|
44
|
+
# Same per-provider session header as every other lane — repair is
|
|
45
|
+
# auxiliary traffic on the SAME conversation for the gateway.
|
|
46
|
+
header_opts = Rubik::LLM::SessionHeader.apply!(
|
|
47
|
+
{},
|
|
48
|
+
provider_key: Rubik::Orchestrator::ProviderResolver.new(provider: @provider, config: @config).registry_key,
|
|
49
|
+
config: @config,
|
|
50
|
+
session_key: @session_key
|
|
51
|
+
)
|
|
52
|
+
res = @provider.complete([{ role: "user", content: prompt }], header_opts)
|
|
33
53
|
proposed_code = extract_code(res.text)
|
|
34
54
|
|
|
35
55
|
if proposed_code.empty?
|
|
@@ -202,7 +202,7 @@ module Rubik
|
|
|
202
202
|
ctx.out.puts " • Default Task Max Steps : #{cur_max}"
|
|
203
203
|
ctx.out.puts " • Goal Mode Max Steps : #{goal_max}"
|
|
204
204
|
ctx.out.puts " • Plan Mode Max Steps : #{plan_max}"
|
|
205
|
-
ctx.out.puts " • Warning Threshold : #{(warn_r.to_f * 100).to_i}% (#{(cur_max.to_i * warn_r.to_f).ceil}
|
|
205
|
+
ctx.out.puts " • Warning Threshold : #{(warn_r.to_f * 100).to_i}% (step #{(cur_max.to_i * warn_r.to_f).ceil})"
|
|
206
206
|
ctx.out.puts " • Ask Continue on Limit : #{ask_c}"
|
|
207
207
|
elsif clean_args.first.downcase == "default"
|
|
208
208
|
num = clean_args[1].to_i
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "shellwords"
|
|
3
4
|
require_relative "base"
|
|
4
5
|
require_relative "../../storage/layout"
|
|
5
6
|
require_relative "../../runtime"
|
|
@@ -15,8 +16,8 @@ module Rubik
|
|
|
15
16
|
|
|
16
17
|
# Whole-command synopses: shared by the spine registration (usage:)
|
|
17
18
|
# and the empty-args branches that print them, so the two cannot drift.
|
|
18
|
-
USAGE_PLAN = "
|
|
19
|
-
USAGE_GOAL = "
|
|
19
|
+
USAGE_PLAN = "Usage: !plan <task description>"
|
|
20
|
+
USAGE_GOAL = "Usage: !goal [--steps N|-s N] <goal description> | !goal resume | !goal list"
|
|
20
21
|
|
|
21
22
|
# The !goal run lifecycle (start/suspend/resume/terminal mapping) is
|
|
22
23
|
# the Orchestrator::GoalSession domain (issue #404); this module keeps
|
|
@@ -59,15 +60,15 @@ module Rubik
|
|
|
59
60
|
ctx.out.puts "\n=== Proposed Plan ==="
|
|
60
61
|
ctx.out.puts res[:output]
|
|
61
62
|
ctx.out.puts "=====================\n"
|
|
62
|
-
ans = ctx.ask_yes_no("[Rubik::Plan]
|
|
63
|
+
ans = ctx.ask_yes_no("[Rubik::Plan] Should the plan be applied?", default: "y")
|
|
63
64
|
if ["y", "yes", "evet"].include?(ans)
|
|
64
65
|
ctx.out.puts "[Rubik::Act] Executing approved plan..."
|
|
65
66
|
ctx.execute_free_text("Execute the following approved plan step by step:\n#{res[:output]}")
|
|
66
67
|
else
|
|
67
|
-
ctx.out.puts "[Rubik] Plan
|
|
68
|
+
ctx.out.puts "[Rubik] Plan cancelled."
|
|
68
69
|
end
|
|
69
70
|
else
|
|
70
|
-
ctx.out.puts "Plan
|
|
71
|
+
ctx.out.puts "Plan could not be generated: #{res[:error]}"
|
|
71
72
|
end
|
|
72
73
|
end
|
|
73
74
|
end
|
|
@@ -85,7 +86,7 @@ module Rubik
|
|
|
85
86
|
parsed = parse_goal_args(args)
|
|
86
87
|
if !parsed[:valid]
|
|
87
88
|
ctx.out.puts USAGE_GOAL
|
|
88
|
-
ctx.out.puts "⚠️ [Rubik::Goal] --steps
|
|
89
|
+
ctx.out.puts "⚠️ [Rubik::Goal] --steps expects a positive integer (e.g. !goal --steps 200 <goal>)"
|
|
89
90
|
next
|
|
90
91
|
elsif parsed[:goal_text].empty?
|
|
91
92
|
ctx.out.puts USAGE_GOAL
|
|
@@ -172,7 +173,11 @@ module Rubik
|
|
|
172
173
|
shell.register_command("sh", description: "Execute shell command via sandbox runner") do |args, ctx|
|
|
173
174
|
Base.pre_execution_apply(ctx, "command execution", "Commands")
|
|
174
175
|
|
|
175
|
-
|
|
176
|
+
# CommandParser already consumed the quotes via Shellwords.split;
|
|
177
|
+
# rebuild a shell-safe command so `!sh grep "foo bar" file` keeps
|
|
178
|
+
# its single argument — both for execution and for the safety
|
|
179
|
+
# gate (issue #557).
|
|
180
|
+
cmd = Shellwords.shelljoin(args)
|
|
176
181
|
ctx.guard.verify_command_safety!(cmd)
|
|
177
182
|
runner = ctx.sandbox_runner || Rubik::Sandbox::Runner.new(root_dir: Dir.pwd, config: ctx.config, guard: ctx.guard)
|
|
178
183
|
res = runner.run(cmd)
|
|
@@ -190,15 +195,15 @@ module Rubik
|
|
|
190
195
|
|
|
191
196
|
if clean_args.empty? || subcmd == "status"
|
|
192
197
|
enabled = Rubik::Storage::Layout.config_get(ctx.config, "sandbox.enabled", false)
|
|
193
|
-
state_str = enabled ? "
|
|
198
|
+
state_str = enabled ? "Enabled" : "Disabled - direct safe execution"
|
|
194
199
|
driver_name = ctx.sandbox_runner&.driver&.name || Rubik::Storage::Layout.config_get(ctx.config, "sandbox.driver", "bwrap")
|
|
195
200
|
net_str = Rubik::Storage::Layout.config_get(ctx.config, "sandbox.allow_network", false) ? "allowed" : "blocked"
|
|
196
201
|
|
|
197
|
-
ctx.out.puts "=== Sandbox
|
|
198
|
-
ctx.out.puts "
|
|
199
|
-
ctx.out.puts "
|
|
200
|
-
ctx.out.puts "
|
|
201
|
-
ctx.out.puts "
|
|
202
|
+
ctx.out.puts "=== Sandbox Status ==="
|
|
203
|
+
ctx.out.puts "Status: #{state_str}"
|
|
204
|
+
ctx.out.puts "Active Driver: #{driver_name}"
|
|
205
|
+
ctx.out.puts "Network: #{net_str}"
|
|
206
|
+
ctx.out.puts "Registered: #{registered_keys.join(', ')}"
|
|
202
207
|
elsif subcmd == "on"
|
|
203
208
|
res = ctx.config.set("sandbox.enabled", true, persist: scope)
|
|
204
209
|
driver_res = ctx.config.set("sandbox.driver", "bwrap", persist: scope) if Rubik::Platform.linux?
|
|
@@ -212,7 +217,7 @@ module Rubik
|
|
|
212
217
|
|
|
213
218
|
ctx.out.puts "[Sandbox] Disabled (direct safe execution active)."
|
|
214
219
|
elsif registered_map.key?(subcmd)
|
|
215
|
-
ctx.out.puts "⚠️ [Sandbox] 'bwrap'
|
|
220
|
+
ctx.out.puts "⚠️ [Sandbox] 'bwrap' is only supported on Linux." if ["bwrap", "bubblewrap"].include?(subcmd) && !Rubik::Platform.linux?
|
|
216
221
|
res = ctx.config.set("sandbox.enabled", true, persist: scope)
|
|
217
222
|
driver_res = ctx.config.set("sandbox.driver", subcmd, persist: scope)
|
|
218
223
|
next if Base.report_persist_failure(ctx, res, scope)
|
|
@@ -220,7 +225,7 @@ module Rubik
|
|
|
220
225
|
|
|
221
226
|
ctx.out.puts "[Sandbox] Driver set to '#{subcmd}' (enabled)."
|
|
222
227
|
else
|
|
223
|
-
ctx.out.puts "[Sandbox]
|
|
228
|
+
ctx.out.puts "[Sandbox] Unknown subcommand or driver: '#{subcmd}'. Registered drivers: #{registered_keys.join(', ')}"
|
|
224
229
|
end
|
|
225
230
|
end
|
|
226
231
|
end
|
|
@@ -29,12 +29,16 @@ module Rubik
|
|
|
29
29
|
|
|
30
30
|
# One honest line for a failed disk write; returns true when it fired
|
|
31
31
|
# so callers can step past their success report. The in-memory change
|
|
32
|
-
# stands — only persistence failed.
|
|
32
|
+
# stands — only persistence failed. `ctx` is the REPL context, but an
|
|
33
|
+
# IO/output stream is also accepted (workspace_approval passes @out
|
|
34
|
+
# directly — issue #598): anything responding to #out is unwrapped,
|
|
35
|
+
# anything else is written to via #puts.
|
|
33
36
|
def self.report_persist_failure(ctx, res, scope)
|
|
34
37
|
return false if res.nil? || res[:ok]
|
|
35
38
|
|
|
36
|
-
ctx.out
|
|
37
|
-
|
|
39
|
+
out = ctx.respond_to?(:out) ? ctx.out : ctx
|
|
40
|
+
out.puts "Error: could not save to #{scope_label(scope)}: #{res[:error]} " \
|
|
41
|
+
"(change kept for this session only)."
|
|
38
42
|
true
|
|
39
43
|
end
|
|
40
44
|
|
|
@@ -17,6 +17,7 @@ module Rubik
|
|
|
17
17
|
USAGE_AUTOAPPLY = "Usage: !autoapply <manual | on_test | on_finish | always | status> [--project|--global]"
|
|
18
18
|
|
|
19
19
|
def self.register(shell)
|
|
20
|
+
register_snapshot_recording(shell)
|
|
20
21
|
register_diff_command(shell)
|
|
21
22
|
register_apply_command(shell)
|
|
22
23
|
register_undo_command(shell)
|
|
@@ -24,6 +25,20 @@ module Rubik
|
|
|
24
25
|
register_autoapply_command(shell)
|
|
25
26
|
end
|
|
26
27
|
|
|
28
|
+
private_class_method def self.register_snapshot_recording(shell)
|
|
29
|
+
return unless shell.respond_to?(:buffer_manager) && shell.respond_to?(:snapshot_store)
|
|
30
|
+
|
|
31
|
+
manager = shell.buffer_manager
|
|
32
|
+
store = shell.snapshot_store
|
|
33
|
+
return unless manager.respond_to?(:snapshot_store=) && store
|
|
34
|
+
|
|
35
|
+
# The manager snapshots the post-write buffer state, so the
|
|
36
|
+
# !undo / !rollback commands registered below always have a
|
|
37
|
+
# producer (issue #544). Kept here so the dependency lives with
|
|
38
|
+
# the command module that advertises them.
|
|
39
|
+
manager.snapshot_store = store
|
|
40
|
+
end
|
|
41
|
+
|
|
27
42
|
private_class_method def self.register_diff_command(shell)
|
|
28
43
|
shell.register_command(
|
|
29
44
|
"diff",
|
|
@@ -71,8 +86,12 @@ module Rubik
|
|
|
71
86
|
target_path
|
|
72
87
|
end
|
|
73
88
|
if ctx.buffer_manager.dirty_files.key?(rel)
|
|
74
|
-
|
|
75
|
-
|
|
89
|
+
# Route through Manager.read(from_disk: true) so the disk side
|
|
90
|
+
# gets the same read_bytes_as_utf8 encoding as the buffer side
|
|
91
|
+
# (issue #589) — a plain File.read can raise
|
|
92
|
+
# Encoding::CompatibilityError in unified_diff for files with
|
|
93
|
+
# invalid-UTF-8 bytes.
|
|
94
|
+
orig_content = ctx.buffer_manager.read(rel, from_disk: true) || ""
|
|
76
95
|
new_content = ctx.buffer_manager.read(rel) || ""
|
|
77
96
|
Rubik::UI::DiffViewer.render(ctx, theme, Rubik::Buffer::Diff.unified_diff(rel, orig_content, new_content))
|
|
78
97
|
else
|
|
@@ -27,7 +27,6 @@ module Rubik
|
|
|
27
27
|
# the wizard can make. Honest refusal beats silent escalation.
|
|
28
28
|
if args.intersect?(["--session", "-s"])
|
|
29
29
|
ctx.out.puts USAGE_CONNECT
|
|
30
|
-
ctx.out.puts " !connect yalnızca kalıcı kapsamlara yazar; oturum-kapsamı için !provider add kullanın."
|
|
31
30
|
ctx.out.puts " !connect writes persistent scopes only; use !provider add for a session-scoped provider."
|
|
32
31
|
else
|
|
33
32
|
scope, _clean = Base.parse_scope(args)
|
|
@@ -80,7 +80,7 @@ module Rubik
|
|
|
80
80
|
|
|
81
81
|
private_class_method def self.render_diagnostics(ctx, diags)
|
|
82
82
|
diags.each do |d|
|
|
83
|
-
sev = d["severity"]
|
|
83
|
+
sev = Rubik::Tools::LSPSeverity.display(d["severity"])
|
|
84
84
|
line = (d.dig("range", "start", "line") || 0) + 1
|
|
85
85
|
ctx.out.puts " • [#{sev}] Line #{line}: #{d['message']}"
|
|
86
86
|
end
|