rubik 0.9.0 → 0.9.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 +108 -43
- data/README.md +5 -1
- data/lib/rubik/adapter/base.rb +19 -0
- data/lib/rubik/adapter/generic.rb +0 -14
- data/lib/rubik/adapter/node.rb +2 -0
- data/lib/rubik/ast/treesitter/zig_walker.rb +15 -2
- data/lib/rubik/cli/workspace_trust.rb +16 -0
- data/lib/rubik/config/defaults.rb +23 -0
- data/lib/rubik/config/store.rb +14 -0
- data/lib/rubik/kernel/dispatcher.rb +4 -4
- data/lib/rubik/log.rb +2 -1
- data/lib/rubik/lsp/client.rb +83 -180
- data/lib/rubik/lsp/document_store.rb +209 -0
- data/lib/rubik/mcp/client.rb +4 -3
- data/lib/rubik/mcp/manager.rb +6 -2
- data/lib/rubik/mcp/transport/stdio.rb +51 -9
- data/lib/rubik/orchestrator/goal_session.rb +505 -0
- data/lib/rubik/orchestrator/subagent/instance.rb +4 -0
- data/lib/rubik/orchestrator/subagent/journal.rb +2 -1
- data/lib/rubik/orchestrator/subagent/questioner.rb +21 -6
- data/lib/rubik/orchestrator/subagent/step_runner.rb +1 -1
- data/lib/rubik/orchestrator/subagent/teardown.rb +4 -0
- data/lib/rubik/orchestrator/subagent/transcript_formatter.rb +2 -1
- data/lib/rubik/orchestrator.rb +1 -0
- data/lib/rubik/platform.rb +15 -0
- data/lib/rubik/plugin/storage.rb +20 -29
- data/lib/rubik/repl/commands/agent_context.rb +1 -1
- data/lib/rubik/repl/commands/agent_execution.rb +7 -470
- data/lib/rubik/repl/commands/buffer.rb +1 -1
- data/lib/rubik/repl/commands/lsp.rb +1 -1
- data/lib/rubik/repl/input_loop.rb +1 -1
- data/lib/rubik/repl/lifecycle.rb +28 -0
- data/lib/rubik/runtime/manifest_store.rb +116 -0
- data/lib/rubik/runtime/overlay_storage.rb +247 -196
- data/lib/rubik/runtime/task_manager.rb +7 -2
- data/lib/rubik/runtime.rb +1 -0
- data/lib/rubik/security/allowlist.rb +167 -0
- data/lib/rubik/security/audit_log.rb +72 -0
- data/lib/rubik/security/classifier/classifier.rb +8 -0
- data/lib/rubik/security/command_gate.rb +567 -0
- data/lib/rubik/security/guard.rb +88 -1075
- data/lib/rubik/security/path_policy.rb +117 -0
- data/lib/rubik/security/synthesis_gate.rb +300 -0
- data/lib/rubik/security.rb +5 -0
- data/lib/rubik/storage/ranking.rb +113 -0
- data/lib/rubik/storage/store.rb +2 -92
- data/lib/rubik/storage/transcript_indexer.rb +2 -3
- data/lib/rubik/tools/builtins/grep.rb +2 -3
- data/lib/rubik/tools/builtins/lifecycle.rb +90 -87
- data/lib/rubik/tools/builtins/synthesis.rb +3 -0
- data/lib/rubik/tools/lifecycle_rollbacks.rb +87 -0
- data/lib/rubik/tools/native_search.rb +2 -1
- data/lib/rubik/tools/truncator.rb +25 -0
- data/lib/rubik/version.rb +1 -1
- metadata +11 -1
|
@@ -10,8 +10,10 @@ module Rubik
|
|
|
10
10
|
# inbox for the maestro's send_message reply. The worker thread is the ONLY
|
|
11
11
|
# inbox drainer (drain_inbox_into_history runs between steps) and it is
|
|
12
12
|
# blocked inside the tool here, so the pop cannot race a drain.
|
|
13
|
-
#
|
|
14
|
-
#
|
|
13
|
+
# The answer wait is a ConditionVariable guarded by the same @monitor
|
|
14
|
+
# that guards @inbox (mirroring Supervisor's @wait_cond idiom); the
|
|
15
|
+
# emitter (Instance#post_message) broadcasts OUTSIDE the critical
|
|
16
|
+
# section. Kill hard-kills the thread, so no signal is needed there.
|
|
15
17
|
module Questioner
|
|
16
18
|
DEFAULT_QUESTION_TIMEOUT = 300
|
|
17
19
|
|
|
@@ -37,15 +39,21 @@ module Rubik
|
|
|
37
39
|
answer = nil
|
|
38
40
|
begin
|
|
39
41
|
# Emit OUTSIDE the monitor (budget-pause discipline): synchronous
|
|
40
|
-
# bus dispatch finishes before the
|
|
42
|
+
# bus dispatch finishes before the wait starts, so the answer can
|
|
41
43
|
# never land before we begin waiting for it.
|
|
42
44
|
Notices.emit(@event_bus, Notices::QUESTION_EVENT, payload)
|
|
43
45
|
deadline = Time.now + payload[:timeout]
|
|
46
|
+
@monitor.synchronize { @answer_cond ||= @monitor.new_cond }
|
|
44
47
|
until answer
|
|
45
|
-
@monitor.synchronize
|
|
48
|
+
@monitor.synchronize do
|
|
49
|
+
answer = @inbox.pop(true)&.text unless @inbox.empty?
|
|
50
|
+
# Sleep on the cond var INSIDE the monitor (wait atomically
|
|
51
|
+
# releases it), bounded by the deadline. The emitter's
|
|
52
|
+
# broadcast outside the critical section cannot be lost:
|
|
53
|
+
# a push can only interleave while we are in wait.
|
|
54
|
+
@answer_cond.wait([deadline - Time.now, 0].max) unless answer
|
|
55
|
+
end
|
|
46
56
|
break if Time.now >= deadline || !(awaiting_human? || executing?)
|
|
47
|
-
|
|
48
|
-
sleep 0.1
|
|
49
57
|
end
|
|
50
58
|
ensure
|
|
51
59
|
# Guarded restore (also covers a raise or Thread#kill mid-wait):
|
|
@@ -74,6 +82,13 @@ module Rubik
|
|
|
74
82
|
(@config.respond_to?(:fetch) ? @config.fetch("subagents.question_timeout", DEFAULT_QUESTION_TIMEOUT) : DEFAULT_QUESTION_TIMEOUT) ||
|
|
75
83
|
DEFAULT_QUESTION_TIMEOUT
|
|
76
84
|
end
|
|
85
|
+
|
|
86
|
+
# Emitter-side signal (mirror of Supervisor#notify_wait!): the
|
|
87
|
+
# broadcast happens outside the caller's critical section, and a
|
|
88
|
+
# nil cond just means nobody is waiting on an answer.
|
|
89
|
+
def notify_answer!
|
|
90
|
+
@monitor.synchronize { @answer_cond&.broadcast }
|
|
91
|
+
end
|
|
77
92
|
end
|
|
78
93
|
end
|
|
79
94
|
end
|
|
@@ -180,7 +180,7 @@ module Rubik
|
|
|
180
180
|
# status/wait output, and long payloads are bounded.
|
|
181
181
|
def tool_detail(args)
|
|
182
182
|
json = Rubik::Platform.safe_json_generate(Rubik::Security::Redactor.mask_value(args))
|
|
183
|
-
|
|
183
|
+
Rubik::Tools::Truncator.clip(json, 120, counted: false)
|
|
184
184
|
end
|
|
185
185
|
|
|
186
186
|
# The subagent's own spelling of the shared auto-apply policy (AutoApply
|
|
@@ -54,6 +54,10 @@ module Rubik
|
|
|
54
54
|
@ended_at = Time.now
|
|
55
55
|
@budget_cond.broadcast
|
|
56
56
|
@error_cond.broadcast
|
|
57
|
+
# A questioner waiting on the answer cond must observe the state
|
|
58
|
+
# flip now, not at its deadline (the old 100 ms poll did this
|
|
59
|
+
# implicitly via its state-guard tick).
|
|
60
|
+
notify_answer!
|
|
57
61
|
ensure
|
|
58
62
|
@monitor.exit
|
|
59
63
|
end
|
|
@@ -5,6 +5,7 @@ require "json"
|
|
|
5
5
|
require "digest"
|
|
6
6
|
require_relative "../../security/redactor"
|
|
7
7
|
require_relative "../../storage/layout"
|
|
8
|
+
require_relative "../../tools/truncator"
|
|
8
9
|
|
|
9
10
|
module Rubik
|
|
10
11
|
module Orchestrator
|
|
@@ -139,7 +140,7 @@ module Rubik
|
|
|
139
140
|
when "tool"
|
|
140
141
|
t_name = entry[:tool_name] || entry["tool_name"]
|
|
141
142
|
text = content.to_s
|
|
142
|
-
truncated = text
|
|
143
|
+
truncated = Rubik::Tools::Truncator.clip(text, 2000, separator: "\n")
|
|
143
144
|
"[TOOL RESULT: #{t_name}]\n#{truncated}\n---"
|
|
144
145
|
end
|
|
145
146
|
end
|
data/lib/rubik/orchestrator.rb
CHANGED
|
@@ -4,6 +4,7 @@ require_relative "orchestrator/loop"
|
|
|
4
4
|
require_relative "orchestrator/goal_state"
|
|
5
5
|
require_relative "orchestrator/goal_registry"
|
|
6
6
|
require_relative "orchestrator/goal_ledger"
|
|
7
|
+
require_relative "orchestrator/goal_session"
|
|
7
8
|
require_relative "orchestrator/subagent/supervisor"
|
|
8
9
|
|
|
9
10
|
module Rubik
|
data/lib/rubik/platform.rb
CHANGED
|
@@ -45,6 +45,21 @@ module Rubik
|
|
|
45
45
|
value
|
|
46
46
|
end
|
|
47
47
|
|
|
48
|
+
# Child-process spawn hygiene, single-homed here so every subprocess
|
|
49
|
+
# family shares one scrub list: bundler and Ruby runtime options must
|
|
50
|
+
# never leak into a spawned helper's environment, where a foreign
|
|
51
|
+
# BUNDLE_GEMFILE or RUBYOPT would change what the child loads. Values
|
|
52
|
+
# are nil so Ruby's spawn semantics UNSET each variable instead of
|
|
53
|
+
# setting it; explicit per-server env: configuration merges on top and
|
|
54
|
+
# wins. Consumers: LSP client, MCP stdio transport.
|
|
55
|
+
def sanitized_spawn_env
|
|
56
|
+
env = {}
|
|
57
|
+
ENV.each_key do |key|
|
|
58
|
+
env[key] = nil if key.start_with?("BUNDLE_", "BUNDLER_") || ["RUBYOPT", "RUBYLIB"].include?(key)
|
|
59
|
+
end
|
|
60
|
+
env
|
|
61
|
+
end
|
|
62
|
+
|
|
48
63
|
def host_os
|
|
49
64
|
RbConfig::CONFIG["host_os"] || ""
|
|
50
65
|
end
|
data/lib/rubik/plugin/storage.rb
CHANGED
|
@@ -7,6 +7,7 @@ require "time"
|
|
|
7
7
|
# require edilmesi durumunda da çözümlenebilsin diye açık yüklenir.
|
|
8
8
|
require_relative "../platform"
|
|
9
9
|
require_relative "../log"
|
|
10
|
+
require_relative "../runtime/manifest_store"
|
|
10
11
|
require_relative "package_inventory"
|
|
11
12
|
|
|
12
13
|
module Rubik
|
|
@@ -36,40 +37,32 @@ module Rubik
|
|
|
36
37
|
end
|
|
37
38
|
end
|
|
38
39
|
|
|
40
|
+
# Shared manifest primitives (issue #426) live on Runtime::ManifestStore;
|
|
41
|
+
# the plugin plane delegates path resolution, load/save, hash recording,
|
|
42
|
+
# hash verification (constant-time, one policy) and the trust-mode seam.
|
|
43
|
+
def manifest_store
|
|
44
|
+
@manifest_store ||= Runtime::ManifestStore.new
|
|
45
|
+
end
|
|
46
|
+
|
|
39
47
|
def manifest_path(dir)
|
|
40
|
-
|
|
48
|
+
manifest_store.manifest_path(dir)
|
|
41
49
|
end
|
|
42
50
|
|
|
43
51
|
def load_manifest(dir)
|
|
44
|
-
|
|
45
|
-
return {} unless File.exist?(path)
|
|
46
|
-
|
|
47
|
-
JSON.parse(File.read(path))
|
|
48
|
-
rescue JSON::ParserError
|
|
49
|
-
{}
|
|
52
|
+
manifest_store.load_manifest(dir)
|
|
50
53
|
end
|
|
51
54
|
|
|
52
55
|
def save_manifest(dir, manifest)
|
|
53
|
-
|
|
54
|
-
# engeller — OverlayStorage#save_manifest ile aynı düzen (Platform.atomic_write).
|
|
55
|
-
Platform.atomic_write(manifest_path(dir), JSON.pretty_generate(manifest))
|
|
56
|
+
manifest_store.save_manifest(dir, manifest)
|
|
56
57
|
end
|
|
57
58
|
|
|
58
59
|
def record_hash(path, scope: :project)
|
|
59
60
|
dir = scope.to_sym == :global ? global_plugins_dir : project_plugins_dir
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
manifest = load_manifest(dir)
|
|
63
|
-
manifest[filename] = {
|
|
64
|
-
"sha256" => PackageInventory.file_hash(path),
|
|
65
|
-
"scope" => scope.to_s,
|
|
66
|
-
"created_at" => Time.now.iso8601
|
|
67
|
-
}
|
|
68
|
-
save_manifest(dir, manifest)
|
|
61
|
+
manifest_store.record_hash(dir, File.basename(path), PackageInventory.file_hash(path), scope: scope)
|
|
69
62
|
end
|
|
70
63
|
|
|
71
64
|
def verify_integrity(path, scope: :project, content: nil)
|
|
72
|
-
return :trusted if
|
|
65
|
+
return :trusted if manifest_store.trust_mode?
|
|
73
66
|
|
|
74
67
|
dir = scope.to_sym == :global ? global_plugins_dir : project_plugins_dir
|
|
75
68
|
|
|
@@ -82,15 +75,13 @@ module Rubik
|
|
|
82
75
|
current_content = content || (File.exist?(path) ? File.binread(path) : "")
|
|
83
76
|
current_hash = PackageInventory.content_hash(current_content)
|
|
84
77
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
end
|
|
93
|
-
else
|
|
78
|
+
case manifest_store.verify_entry(manifest, basename, current_hash)
|
|
79
|
+
when :verified
|
|
80
|
+
:verified
|
|
81
|
+
when :drift
|
|
82
|
+
warn "[SECURITY] Integrity check failed for plugin '#{basename}': file modified since adding."
|
|
83
|
+
:rejected
|
|
84
|
+
when :unknown
|
|
94
85
|
warn "[SECURITY] Unknown plugin file '#{basename}' not in manifest. Skipping."
|
|
95
86
|
:rejected
|
|
96
87
|
end
|
|
@@ -69,7 +69,7 @@ module Rubik
|
|
|
69
69
|
rescue Errno::EACCES => e
|
|
70
70
|
root_path = begin
|
|
71
71
|
ctx.buffer_manager.root_dir
|
|
72
|
-
rescue
|
|
72
|
+
rescue StandardError
|
|
73
73
|
Dir.pwd
|
|
74
74
|
end
|
|
75
75
|
ctx.out.puts Rubik::Tools::DiagnosticReporter.render_permission_denied(root_path, operation: "scan", reason: e.message)
|