rubik 0.14.0 → 0.15.1
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 +109 -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 +31 -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 +112 -7
- 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
|
@@ -6,12 +6,14 @@ require "time"
|
|
|
6
6
|
require_relative "../log"
|
|
7
7
|
require_relative "../platform"
|
|
8
8
|
require_relative "../security/guard" unless defined?(Rubik::Security::Guard)
|
|
9
|
+
require_relative "../security/redactor" unless defined?(Rubik::Security::Redactor)
|
|
9
10
|
|
|
10
11
|
module Rubik
|
|
11
12
|
module Runtime
|
|
12
|
-
# Bounded
|
|
13
|
-
#
|
|
13
|
+
# Bounded ring buffer for child stdout/stderr (Plan 93): bounded by entry
|
|
14
|
+
# count AND per-line bytes; lines are Redactor-redacted at push time (#586).
|
|
14
15
|
class RingBuffer
|
|
16
|
+
MAX_LINE_BYTES = 64 * 1024 # byte cap per line (scrub re-validates cut chars)
|
|
15
17
|
attr_reader :capacity
|
|
16
18
|
|
|
17
19
|
def initialize(capacity = 500)
|
|
@@ -21,8 +23,11 @@ module Rubik
|
|
|
21
23
|
end
|
|
22
24
|
|
|
23
25
|
def push(line)
|
|
26
|
+
text = line.to_s
|
|
27
|
+
text = text.byteslice(0, MAX_LINE_BYTES).scrub if text.bytesize > MAX_LINE_BYTES
|
|
28
|
+
clean = Rubik::Security::Redactor.redact(text)
|
|
24
29
|
@monitor.synchronize do
|
|
25
|
-
@buffer <<
|
|
30
|
+
@buffer << clean
|
|
26
31
|
@buffer.shift while @buffer.size > @capacity
|
|
27
32
|
end
|
|
28
33
|
self
|
|
@@ -76,9 +81,8 @@ module Rubik
|
|
|
76
81
|
end
|
|
77
82
|
end
|
|
78
83
|
|
|
79
|
-
# Manages asynchronous long-running background processes
|
|
80
|
-
#
|
|
81
|
-
# context-mediated LIFO rollback (AGENTS.md §1.A/B, Plan 93).
|
|
84
|
+
# Manages asynchronous long-running background processes with
|
|
85
|
+
# deadlock-immune streaming, AST guard verification and LIFO rollback.
|
|
82
86
|
class TaskManager
|
|
83
87
|
attr_reader :guard, :context, :root_dir, :max_buffer_lines
|
|
84
88
|
attr_accessor :init
|
|
@@ -151,11 +155,10 @@ module Rubik
|
|
|
151
155
|
# #444): that core is the synchronous drain-to-string capture shape
|
|
152
156
|
# (Timeout-wrapped, stdin closed immediately, whole-output strings).
|
|
153
157
|
# This spawn is the async/interactive shape — stdin stays open for
|
|
154
|
-
# send_input,
|
|
155
|
-
# RingBuffer,
|
|
156
|
-
# no Timeout — so parameterizing the sink alone cannot unify them.
|
|
158
|
+
# send_input, readers stream chomped lines into the per-task
|
|
159
|
+
# RingBuffer, completion is watched by a dedicated thread.
|
|
157
160
|
begin
|
|
158
|
-
stdin, stdout, stderr, wait_thr = Open3.popen3(cmd_str, chdir: chdir)
|
|
161
|
+
stdin, stdout, stderr, wait_thr = Open3.popen3(Rubik::Platform.credential_free_env, cmd_str, chdir: chdir)
|
|
159
162
|
rescue StandardError => e
|
|
160
163
|
rollback_failed_start(target_ctx, nil, e)
|
|
161
164
|
raise e
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative "../../security/guard" unless defined?(Rubik::Security::Guard)
|
|
4
|
+
|
|
3
5
|
module Rubik
|
|
4
6
|
module Sandbox
|
|
5
7
|
module Driver
|
|
@@ -31,6 +33,38 @@ module Rubik
|
|
|
31
33
|
def run(cmd, timeout: 15, chdir: Dir.pwd, allow_network: false, memory_limit_mb: 512, cpus: "1.0")
|
|
32
34
|
raise NotImplementedError
|
|
33
35
|
end
|
|
36
|
+
|
|
37
|
+
private
|
|
38
|
+
|
|
39
|
+
# Security guard gating spawns (issue #591). The Runner injects the
|
|
40
|
+
# shared session guard via driver_opts (options[:guard]) so operator
|
|
41
|
+
# policy — the live command allowlist above all — applies to every
|
|
42
|
+
# driver; the lazy local fallback (silent audit, zero policy) serves
|
|
43
|
+
# only standalone / test-constructed drivers. ProcessDriver keeps its
|
|
44
|
+
# own copy with cmd.exe refinements; container drivers re-verify the
|
|
45
|
+
# raw command through this shared helper before spawning.
|
|
46
|
+
def guard
|
|
47
|
+
@options[:guard] || (@guard ||= Rubik::Security::Guard.new(audit_log_path: nil))
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Re-run the security guard's classification before spawning. Blocks
|
|
51
|
+
# a command the operator policy / catastrophic fallback regex rejects.
|
|
52
|
+
def verify_command_safety!(cmd, shell: nil)
|
|
53
|
+
guard.verify_command_safety!(cmd, shell: shell)
|
|
54
|
+
true
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Issue #591: bind-mount every configured allowed dir read-write,
|
|
58
|
+
# mirroring BubblewrapDriver's loop, so commands legitimately touching
|
|
59
|
+
# an allowed external dir work identically across drivers.
|
|
60
|
+
def allowed_dir_mounts
|
|
61
|
+
Array(@options[:allowed_dirs]).filter_map do |dir|
|
|
62
|
+
expanded = File.expand_path(dir.to_s)
|
|
63
|
+
next unless File.directory?(expanded)
|
|
64
|
+
|
|
65
|
+
["-v", "#{expanded}:#{expanded}:rw"]
|
|
66
|
+
end.flatten
|
|
67
|
+
end
|
|
34
68
|
end
|
|
35
69
|
end
|
|
36
70
|
end
|
|
@@ -19,6 +19,11 @@ module Rubik
|
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
def run(cmd, timeout: 15, chdir: Dir.pwd, allow_network: false, memory_limit_mb: 512, cpus: "1.0")
|
|
22
|
+
# Defense-in-depth (issue #591): re-run the shared session guard
|
|
23
|
+
# before spawning, the same way ProcessDriver does, so a caller
|
|
24
|
+
# that forgot its own pre-check is still gated by operator policy.
|
|
25
|
+
verify_command_safety!(cmd)
|
|
26
|
+
|
|
22
27
|
image = @options[:image] || DEFAULT_IMAGE
|
|
23
28
|
workspace = File.expand_path(chdir)
|
|
24
29
|
container_name = "rubik-box-#{SecureRandom.hex(6)}"
|
|
@@ -29,6 +34,7 @@ module Rubik
|
|
|
29
34
|
*CONTAINER_HARDENING_FLAGS,
|
|
30
35
|
"-w", "/workspace",
|
|
31
36
|
"-v", "#{workspace}:/workspace:rw",
|
|
37
|
+
*allowed_dir_mounts,
|
|
32
38
|
"--memory", "#{memory_limit_mb}m",
|
|
33
39
|
"--cpus", cpus.to_s,
|
|
34
40
|
"--pids-limit", "100"
|
|
@@ -55,6 +61,8 @@ module Rubik
|
|
|
55
61
|
{
|
|
56
62
|
ok: res[:ok],
|
|
57
63
|
exit_code: res[:exit_code],
|
|
64
|
+
# Explicit timeout flag plumbed to the tool layer (#597-3).
|
|
65
|
+
timed_out: res[:timed_out] == true,
|
|
58
66
|
stdout: res[:stdout],
|
|
59
67
|
stderr: res[:stderr],
|
|
60
68
|
output: res[:output],
|
|
@@ -16,6 +16,11 @@ module Rubik
|
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def run(cmd, timeout: 15, chdir: Dir.pwd, allow_network: false, memory_limit_mb: 512, cpus: "1.0")
|
|
19
|
+
# Defense-in-depth (issue #591): re-run the shared session guard
|
|
20
|
+
# before spawning, the same way ProcessDriver does, so a caller
|
|
21
|
+
# that forgot its own pre-check is still gated by operator policy.
|
|
22
|
+
verify_command_safety!(cmd)
|
|
23
|
+
|
|
19
24
|
image = @options[:image] || DEFAULT_IMAGE
|
|
20
25
|
workspace = File.expand_path(chdir)
|
|
21
26
|
|
|
@@ -24,6 +29,7 @@ module Rubik
|
|
|
24
29
|
*CONTAINER_HARDENING_FLAGS,
|
|
25
30
|
"-w", "/workspace",
|
|
26
31
|
"-v", "#{workspace}:/workspace:rw",
|
|
32
|
+
*allowed_dir_mounts,
|
|
27
33
|
"--memory", "#{memory_limit_mb}m",
|
|
28
34
|
"--cpus", cpus.to_s,
|
|
29
35
|
"--pids-limit", "100"
|
|
@@ -43,6 +49,8 @@ module Rubik
|
|
|
43
49
|
{
|
|
44
50
|
ok: res[:ok],
|
|
45
51
|
exit_code: res[:exit_code],
|
|
52
|
+
# Explicit timeout flag plumbed to the tool layer (#597-3).
|
|
53
|
+
timed_out: res[:timed_out] == true,
|
|
46
54
|
stdout: res[:stdout],
|
|
47
55
|
stderr: res[:stderr],
|
|
48
56
|
output: res[:output],
|
|
@@ -19,12 +19,9 @@ module Rubik
|
|
|
19
19
|
# AWS_ACCESS_KEY_ID are covered without matching words like "tokenizer".
|
|
20
20
|
# NOTE: this is integrity hygiene, NOT a secret-confinement boundary —
|
|
21
21
|
# the child still inherits non-credential host variables by design.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|_(?:DATABASE|CONNECTION)_URL\z
|
|
26
|
-
/ix
|
|
27
|
-
private_constant :CREDENTIAL_ENV_PATTERN
|
|
22
|
+
# The credential pattern and the env construction live once in
|
|
23
|
+
# Rubik::Platform.credential_free_env (issue #586); this driver is a
|
|
24
|
+
# pure consumer of that shared implementation.
|
|
28
25
|
|
|
29
26
|
def available?
|
|
30
27
|
true
|
|
@@ -49,6 +46,9 @@ module Rubik
|
|
|
49
46
|
{
|
|
50
47
|
ok: res[:ok],
|
|
51
48
|
exit_code: res[:exit_code],
|
|
49
|
+
# Explicit timeout flag plumbed to the tool layer (#597-3): a
|
|
50
|
+
# legitimate timeout(1) exit 124 must not read as a runner kill.
|
|
51
|
+
timed_out: res[:timed_out] == true,
|
|
52
52
|
stdout: clean_stdout,
|
|
53
53
|
stderr: clean_stderr,
|
|
54
54
|
output: [clean_stdout, clean_stderr].reject(&:empty?).join("\n"),
|
|
@@ -66,13 +66,10 @@ module Rubik
|
|
|
66
66
|
# child cannot observe or dump them. Benign variables are left out of
|
|
67
67
|
# the hash entirely and therefore remain normally inheritable, which
|
|
68
68
|
# keeps legitimate command execution (PATH, HOME, locale, proxies…)
|
|
69
|
-
# working. See CREDENTIAL_ENV_PATTERN for the shape
|
|
69
|
+
# working. See Rubik::Platform::CREDENTIAL_ENV_PATTERN for the shape
|
|
70
|
+
# that is stripped.
|
|
70
71
|
def child_env
|
|
71
|
-
|
|
72
|
-
ENV.each_key do |key|
|
|
73
|
-
env[key] = nil if key.match?(CREDENTIAL_ENV_PATTERN)
|
|
74
|
-
end
|
|
75
|
-
env
|
|
72
|
+
Rubik::Platform.credential_free_env
|
|
76
73
|
end
|
|
77
74
|
|
|
78
75
|
# cmd.exe parses its tail with its own quoting rules that standard
|
|
@@ -101,11 +101,36 @@ module Rubik
|
|
|
101
101
|
write_targets.concat(ast.write_paths.to_a) if ast.respond_to?(:write_paths)
|
|
102
102
|
|
|
103
103
|
write_targets.uniq.each do |wp|
|
|
104
|
-
|
|
104
|
+
if critical_path?(wp)
|
|
105
|
+
@audit.log_audit("blocked_command", command: cmd_str, reason: "critical_path_write", path: wp)
|
|
106
|
+
raise BlockedWriteError.new(
|
|
107
|
+
"Command write to critical path blocked: #{wp} in `#{cmd_str}`",
|
|
108
|
+
kind: :critical_path_write,
|
|
109
|
+
blocked_command: cmd_str,
|
|
110
|
+
path: wp
|
|
111
|
+
)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
# Symlink re-check (fail-closed, issue #590): the lexical test above
|
|
115
|
+
# cannot see `evil -> .git/config`, so `echo x > evil` would sail
|
|
116
|
+
# through while naming nothing critical. Resolve each write target
|
|
117
|
+
# exactly like verify_path_write! does and re-check the resolution;
|
|
118
|
+
# a nil resolution (symlink loop / permission wall) fails closed.
|
|
119
|
+
resolved = Rubik::Platform.resolved_path(wp, strict: true)
|
|
120
|
+
if resolved.nil?
|
|
121
|
+
@audit.log_audit("blocked_command", command: cmd_str, reason: "path_resolution_failed", path: wp)
|
|
122
|
+
raise BlockedWriteError.new(
|
|
123
|
+
"Command write blocked: path could not be safely resolved: #{wp} in `#{cmd_str}`",
|
|
124
|
+
kind: :critical_path_write,
|
|
125
|
+
blocked_command: cmd_str,
|
|
126
|
+
path: wp
|
|
127
|
+
)
|
|
128
|
+
end
|
|
129
|
+
next unless critical_path?(resolved)
|
|
105
130
|
|
|
106
|
-
@audit.log_audit("blocked_command", command: cmd_str, reason: "
|
|
131
|
+
@audit.log_audit("blocked_command", command: cmd_str, reason: "critical_path_write_symlink", path: wp, resolved: resolved)
|
|
107
132
|
raise BlockedWriteError.new(
|
|
108
|
-
"Command write to critical path blocked: #{wp} in `#{cmd_str}`",
|
|
133
|
+
"Command write to critical path blocked (symlink-resolved): #{wp} -> #{resolved} in `#{cmd_str}`",
|
|
109
134
|
kind: :critical_path_write,
|
|
110
135
|
blocked_command: cmd_str,
|
|
111
136
|
path: wp
|
|
@@ -78,7 +78,19 @@ module Rubik
|
|
|
78
78
|
record("repl_command", { "command" => cmd, "output" => output })
|
|
79
79
|
end
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
# Durability barrier for copies of the live JSONL (issue #598): records
|
|
82
|
+
# are opened, written and closed per event, so there is no buffered
|
|
83
|
+
# writer to flush — this fsync barrier guarantees a save copy taken
|
|
84
|
+
# afterwards never observes a torn tail.
|
|
85
|
+
def flush
|
|
86
|
+
return unless @session_file && File.exist?(@session_file)
|
|
87
|
+
|
|
88
|
+
File.open(@session_file, "a", &:fsync)
|
|
89
|
+
rescue StandardError
|
|
90
|
+
nil
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def switch_session_file(target_file, cleanup_empty_current: true, parent_session_id: nil)
|
|
82
94
|
if cleanup_empty_current && @session_file && File.exist?(@session_file) && File.expand_path(@session_file) != File.expand_path(target_file)
|
|
83
95
|
begin
|
|
84
96
|
lines = File.readlines(@session_file).reject { |l| l.strip.empty? }
|
|
@@ -111,7 +123,7 @@ module Rubik
|
|
|
111
123
|
end
|
|
112
124
|
|
|
113
125
|
record("session_resumed", {
|
|
114
|
-
"parent_session_id" => File.basename(target_file, ".jsonl"),
|
|
126
|
+
"parent_session_id" => parent_session_id || File.basename(target_file, ".jsonl"),
|
|
115
127
|
"resumed_at" => Time.now.iso8601
|
|
116
128
|
})
|
|
117
129
|
end
|
data/lib/rubik/storage/store.rb
CHANGED
|
@@ -345,6 +345,13 @@ module Rubik
|
|
|
345
345
|
end
|
|
346
346
|
|
|
347
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
|
+
|
|
348
355
|
refs = (meta["refs"] ||= {})
|
|
349
356
|
refs[name] = id
|
|
350
357
|
meta["updated_at"] = Time.now.utc.iso8601
|
|
@@ -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]}"
|
|
@@ -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 }
|
|
@@ -110,8 +110,22 @@ module Rubik
|
|
|
110
110
|
|
|
111
111
|
if path.empty?
|
|
112
112
|
all = mgr.all_diagnostic_snapshots
|
|
113
|
-
total_issues = all.values.sum { |snapshot| snapshot[:diagnostics].size }
|
|
114
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 }
|
|
115
129
|
unversioned = all.values.count { |snapshot| snapshot[:state] == :unversioned }
|
|
116
130
|
if total_issues.zero?
|
|
117
131
|
if pending.positive?
|
|
@@ -145,7 +159,7 @@ module Rubik
|
|
|
145
159
|
end
|
|
146
160
|
else
|
|
147
161
|
snapshot = if mgr.respond_to?(:wait_for_diagnostics)
|
|
148
|
-
mgr.wait_for_diagnostics(path, timeout:
|
|
162
|
+
mgr.wait_for_diagnostics(path, timeout: diagnostic_refresh_timeout)
|
|
149
163
|
else
|
|
150
164
|
mgr.diagnostics_snapshot_for(path)
|
|
151
165
|
end
|
|
@@ -176,6 +190,18 @@ module Rubik
|
|
|
176
190
|
end
|
|
177
191
|
end
|
|
178
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
|
|
179
205
|
end
|
|
180
206
|
|
|
181
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
|
|
@@ -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
|
data/lib/rubik/ui/dialog.rb
CHANGED
|
@@ -83,9 +83,13 @@ module Rubik
|
|
|
83
83
|
def render_card(question, multi: false)
|
|
84
84
|
return unless @shell&.output
|
|
85
85
|
|
|
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)
|
|
86
90
|
subtitle = multi ? "Multi-Select (Space: Select/Deselect · Enter: Confirm)" : "Single-Select (Arrow keys: Navigate · Enter: Confirm)"
|
|
87
91
|
card = Frame.draw(
|
|
88
|
-
[@theme.paint(
|
|
92
|
+
[@theme.paint(safe_question, :bold), @theme.paint(subtitle, :dim)],
|
|
89
93
|
theme: @theme,
|
|
90
94
|
title: @theme.paint("#{@theme.glyph(:action)} AGENT QUESTION", :accent)
|
|
91
95
|
)
|
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
|
data/lib/rubik/version.rb
CHANGED