rubik 0.9.0 → 0.10.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 +250 -43
- data/README.md +5 -1
- data/lib/rubik/adapter/base.rb +21 -1
- data/lib/rubik/adapter/generic.rb +0 -14
- data/lib/rubik/adapter/node.rb +2 -0
- data/lib/rubik/adapter/process.rb +28 -67
- data/lib/rubik/ast/treesitter/zig_walker.rb +15 -2
- data/lib/rubik/benchmark/vakanuvis_adoption.rb +10 -3
- data/lib/rubik/buffer/apply_contract.rb +3 -3
- data/lib/rubik/buffer/apply_transaction.rb +165 -0
- data/lib/rubik/buffer/manager.rb +26 -120
- data/lib/rubik/cli/workspace_trust.rb +16 -0
- data/lib/rubik/config/deep_ops.rb +4 -1
- data/lib/rubik/config/defaults.rb +29 -3
- data/lib/rubik/config/schema.rb +8 -0
- data/lib/rubik/config/secret_policy.rb +197 -0
- data/lib/rubik/config/store.rb +14 -0
- data/lib/rubik/config.rb +11 -0
- data/lib/rubik/diagnostics/collector.rb +0 -9
- data/lib/rubik/errors.rb +15 -0
- data/lib/rubik/event_bus.rb +2 -1
- data/lib/rubik/kernel/dispatcher.rb +16 -11
- data/lib/rubik/kernel/unit.rb +4 -1
- data/lib/rubik/llm/registry.rb +12 -9
- data/lib/rubik/llm/router.rb +2 -5
- data/lib/rubik/log.rb +23 -1
- data/lib/rubik/lsp/client.rb +152 -445
- data/lib/rubik/lsp/document_store.rb +209 -0
- data/lib/rubik/lsp/manager.rb +14 -10
- data/lib/rubik/lsp/transport.rb +365 -0
- data/lib/rubik/mcp/boot_lifecycle.rb +6 -2
- data/lib/rubik/mcp/boot_run.rb +190 -0
- data/lib/rubik/mcp/client.rb +4 -3
- data/lib/rubik/mcp/manager.rb +46 -165
- data/lib/rubik/mcp/transport/stdio.rb +55 -10
- data/lib/rubik/orchestrator/auto_apply.rb +4 -3
- data/lib/rubik/orchestrator/continuation_manager.rb +3 -22
- data/lib/rubik/orchestrator/goal_session.rb +519 -0
- data/lib/rubik/orchestrator/loop.rb +28 -47
- data/lib/rubik/orchestrator/maestro_gate.rb +5 -7
- data/lib/rubik/orchestrator/provider_recovery.rb +4 -2
- data/lib/rubik/orchestrator/provider_resolver.rb +4 -2
- data/lib/rubik/orchestrator/resume_window.rb +96 -0
- data/lib/rubik/orchestrator/shell_deps.rb +16 -0
- data/lib/rubik/orchestrator/stream_manager.rb +2 -1
- data/lib/rubik/orchestrator/subagent/deferred_spec.rb +4 -1
- data/lib/rubik/orchestrator/subagent/instance.rb +11 -12
- data/lib/rubik/orchestrator/subagent/journal.rb +2 -1
- data/lib/rubik/orchestrator/subagent/lifecycle.rb +3 -1
- data/lib/rubik/orchestrator/subagent/questioner.rb +24 -7
- data/lib/rubik/orchestrator/subagent/reaper.rb +3 -5
- data/lib/rubik/orchestrator/subagent/resilience.rb +4 -2
- data/lib/rubik/orchestrator/subagent/result_archive.rb +0 -4
- data/lib/rubik/orchestrator/subagent/run_cycle.rb +2 -7
- data/lib/rubik/orchestrator/subagent/spawn_transaction.rb +11 -2
- data/lib/rubik/orchestrator/subagent/step_runner.rb +11 -3
- data/lib/rubik/orchestrator/subagent/teardown.rb +4 -0
- data/lib/rubik/orchestrator/subagent/transcript_formatter.rb +2 -1
- data/lib/rubik/orchestrator/subagent/type_definition.rb +0 -4
- data/lib/rubik/orchestrator/tool_timeout.rb +121 -1
- data/lib/rubik/orchestrator.rb +1 -0
- data/lib/rubik/platform/io_drain.rb +2 -1
- data/lib/rubik/platform/process.rb +144 -54
- data/lib/rubik/platform.rb +17 -1
- data/lib/rubik/plugin/manager.rb +2 -1
- data/lib/rubik/plugin/storage.rb +20 -29
- data/lib/rubik/repl/commands/agent_context.rb +9 -8
- data/lib/rubik/repl/commands/agent_execution.rb +20 -502
- data/lib/rubik/repl/commands/agent_models.rb +4 -3
- data/lib/rubik/repl/commands/agent_providers.rb +43 -2
- data/lib/rubik/repl/commands/base.rb +47 -2
- data/lib/rubik/repl/commands/buffer.rb +6 -5
- data/lib/rubik/repl/commands/lsp.rb +3 -2
- data/lib/rubik/repl/commands/pruner.rb +2 -1
- data/lib/rubik/repl/commands/secrets.rb +151 -0
- data/lib/rubik/repl/commands/workspace.rb +60 -150
- data/lib/rubik/repl/commands/workspace_approval.rb +209 -0
- data/lib/rubik/repl/config_wiring.rb +3 -3
- data/lib/rubik/repl/hooks.rb +2 -1
- data/lib/rubik/repl/input_execution.rb +158 -76
- data/lib/rubik/repl/input_loop.rb +3 -2
- data/lib/rubik/repl/lifecycle.rb +82 -204
- data/lib/rubik/repl/notice_router.rb +319 -0
- data/lib/rubik/repl/paste_support.rb +3 -1
- data/lib/rubik/repl/presentation.rb +5 -3
- data/lib/rubik/repl/pruner/gate.rb +3 -1
- data/lib/rubik/repl/pruner/harness.rb +2 -1
- data/lib/rubik/repl/shell.rb +4 -3
- data/lib/rubik/repl/turn_recorder.rb +6 -5
- data/lib/rubik/runtime/discovery.rb +3 -2
- data/lib/rubik/runtime/loop_service.rb +4 -3
- data/lib/rubik/runtime/manifest_store.rb +124 -0
- data/lib/rubik/runtime/overlay_guard.rb +127 -0
- data/lib/rubik/runtime/overlay_storage.rb +269 -272
- data/lib/rubik/runtime/task_manager.rb +71 -27
- data/lib/rubik/runtime.rb +1 -0
- data/lib/rubik/sandbox/driver/docker.rb +5 -1
- data/lib/rubik/sandbox/runner.rb +16 -15
- 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 +591 -0
- data/lib/rubik/security/guard.rb +94 -1077
- data/lib/rubik/security/path_policy.rb +117 -0
- data/lib/rubik/security/secret_store.rb +463 -0
- data/lib/rubik/security/synthesis_gate.rb +297 -0
- data/lib/rubik/security.rb +5 -0
- data/lib/rubik/session/manager.rb +7 -1
- data/lib/rubik/skills/manager.rb +2 -3
- data/lib/rubik/storage/ranking.rb +113 -0
- data/lib/rubik/storage/search.rb +49 -0
- data/lib/rubik/storage/store.rb +15 -112
- data/lib/rubik/storage/transcript_indexer.rb +2 -3
- data/lib/rubik/storage/vakanuvis/harness.rb +2 -3
- data/lib/rubik/tools/base.rb +22 -0
- data/lib/rubik/tools/builtins/files.rb +3 -15
- data/lib/rubik/tools/builtins/grep.rb +3 -9
- data/lib/rubik/tools/builtins/lifecycle.rb +96 -92
- data/lib/rubik/tools/builtins/synthesis.rb +3 -0
- data/lib/rubik/tools/lifecycle_rollbacks.rb +100 -0
- data/lib/rubik/tools/native_search.rb +2 -1
- data/lib/rubik/tools/truncator.rb +73 -36
- data/lib/rubik/ui/banner.rb +4 -3
- data/lib/rubik/ui/spinner.rb +3 -1
- data/lib/rubik/ui/statusline.rb +6 -5
- data/lib/rubik/version.rb +1 -1
- data/lib/rubik.rb +1 -2
- metadata +23 -1
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "digest"
|
|
4
|
+
require_relative "path_validator"
|
|
5
|
+
require_relative "../platform"
|
|
6
|
+
|
|
7
|
+
module Rubik
|
|
8
|
+
module Buffer
|
|
9
|
+
# The two-phase apply transaction, extracted from Manager (issue #472):
|
|
10
|
+
# per-file atomic writes with external-conflict detection — NOT a
|
|
11
|
+
# multi-file transaction. On a mid-run failure the partial progress is
|
|
12
|
+
# carried by ApplyFailedError: applied entries ARE on disk, the failed
|
|
13
|
+
# entry stays dirty, and pending entries keep their buffer content, so
|
|
14
|
+
# a retry writes only the remainder. External-modification conflicts
|
|
15
|
+
# are skipped (recorded in the run report) unless policy is "overwrite".
|
|
16
|
+
#
|
|
17
|
+
# The transaction owns the loop and its failure semantics; workspace
|
|
18
|
+
# path policy (containment, disk hashes, external-modification config)
|
|
19
|
+
# is delegated to the `disk_policy` adapter, and the overlay hashes are
|
|
20
|
+
# mutated in place so Manager state and the transaction stay the same
|
|
21
|
+
# objects. This makes conflict/failure paths testable without the full
|
|
22
|
+
# Manager dictionary API.
|
|
23
|
+
class ApplyTransaction
|
|
24
|
+
# A single run's outcome: paths that reached disk, externally-modified
|
|
25
|
+
# paths that were skipped, and entries rejected by the path validator.
|
|
26
|
+
Result = Struct.new(:applied, :conflicts, :skipped)
|
|
27
|
+
|
|
28
|
+
# The mutable overlay state (issue #472): the Manager's live
|
|
29
|
+
# buffer / dirty_files / original_hashes hashes, mutated in place.
|
|
30
|
+
Overlay = Struct.new(:buffer, :dirty_files, :original_hashes)
|
|
31
|
+
|
|
32
|
+
attr_reader :overlay
|
|
33
|
+
|
|
34
|
+
# @param overlay [Overlay] live buffer state, mutated in place
|
|
35
|
+
# @param disk_policy [#root_dir, #containment_root, #disk_hash,
|
|
36
|
+
# #external_modification_policy] workspace path policy adapter
|
|
37
|
+
# @param event_bus [Rubik::EventBus, nil] apply lifecycle events
|
|
38
|
+
def initialize(overlay:, disk_policy:, event_bus: nil)
|
|
39
|
+
@overlay = overlay
|
|
40
|
+
@disk_policy = disk_policy
|
|
41
|
+
@event_bus = event_bus
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Runs the apply loop over keys already sanitized by the caller (the
|
|
45
|
+
# path policy is Manager's concern). `on_finish` runs in an ensure so
|
|
46
|
+
# the caller records the run report (conflicts/skipped/applied) even
|
|
47
|
+
# when a mid-loop failure raises — Manager's last_conflicts /
|
|
48
|
+
# last_skipped / last_applied depend on it.
|
|
49
|
+
#
|
|
50
|
+
# @return [Result] applied/conflicts/skipped for a completed run
|
|
51
|
+
# @raise [ApplyFailedError] on the first failed write, with the
|
|
52
|
+
# structured partial-progress report attached
|
|
53
|
+
def run(keys_to_apply, effective_policy, &on_finish)
|
|
54
|
+
applied_paths = []
|
|
55
|
+
conflicts = []
|
|
56
|
+
skipped = []
|
|
57
|
+
|
|
58
|
+
begin
|
|
59
|
+
keys_to_apply.each_with_index do |rel_path, index|
|
|
60
|
+
next unless overlay.dirty_files.key?(rel_path)
|
|
61
|
+
|
|
62
|
+
unless validate_and_clean_garbage(rel_path)
|
|
63
|
+
skipped << { path: rel_path, reason: :path_validator_rejected }
|
|
64
|
+
next
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
if external_conflict?(rel_path) && effective_policy != "overwrite"
|
|
68
|
+
conflicts << rel_path
|
|
69
|
+
@event_bus&.emit(:buffer_apply_conflict, paths: conflicts.dup.freeze, path: rel_path)
|
|
70
|
+
next
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
apply_single_entry(rel_path, index: index, keys_to_apply: keys_to_apply,
|
|
74
|
+
applied_paths: applied_paths, conflicts: conflicts, skipped: skipped)
|
|
75
|
+
end
|
|
76
|
+
ensure
|
|
77
|
+
on_finish.call(applied_paths, conflicts, skipped)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
Result.new(applied_paths, conflicts, skipped)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
private
|
|
84
|
+
|
|
85
|
+
def validate_and_clean_garbage(rel_path)
|
|
86
|
+
return true if PathValidator.valid?(rel_path)
|
|
87
|
+
|
|
88
|
+
overlay.dirty_files.delete(rel_path)
|
|
89
|
+
overlay.buffer.delete(rel_path)
|
|
90
|
+
overlay.original_hashes.delete(rel_path)
|
|
91
|
+
@event_bus&.emit(:buffer_garbage_skipped, path: rel_path)
|
|
92
|
+
false
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def external_conflict?(rel_path)
|
|
96
|
+
baseline = overlay.original_hashes[rel_path]
|
|
97
|
+
current_disk = @disk_policy.disk_hash(rel_path)
|
|
98
|
+
|
|
99
|
+
if baseline
|
|
100
|
+
current_disk != baseline
|
|
101
|
+
else
|
|
102
|
+
!current_disk.nil?
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def apply_single_entry(rel_path, index:, keys_to_apply:, applied_paths:, conflicts:, skipped:)
|
|
107
|
+
full_path = File.expand_path(rel_path, @disk_policy.root_dir)
|
|
108
|
+
|
|
109
|
+
# TOCTOU close: re-verify containment immediately before the
|
|
110
|
+
# atomic write — a symlink planted between write-time sanitize
|
|
111
|
+
# and apply! must not redirect the write outside the workspace.
|
|
112
|
+
# Fail loud: an untrustworthy path is an attack signal or a
|
|
113
|
+
# mid-flight root misconfiguration, not a content problem; the
|
|
114
|
+
# entry stays dirty for a retry after remediation.
|
|
115
|
+
containment_kind, = @disk_policy.containment_root(full_path)
|
|
116
|
+
unless containment_kind
|
|
117
|
+
@event_bus&.emit(:buffer_containment_blocked, path: rel_path)
|
|
118
|
+
raise apply_failure(
|
|
119
|
+
"Write blocked: '#{rel_path}' resolves outside all allowed roots at apply time " \
|
|
120
|
+
"(possible symlink swap since buffering). Re-verify the workspace and retry.",
|
|
121
|
+
kind: :containment_blocked, applied: applied_paths, failed: rel_path,
|
|
122
|
+
pending: pending_after(keys_to_apply, index), conflicts: conflicts, skipped: skipped
|
|
123
|
+
)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
content = overlay.buffer[rel_path]
|
|
127
|
+
|
|
128
|
+
begin
|
|
129
|
+
Rubik::Platform.atomic_write(full_path, content)
|
|
130
|
+
rescue StandardError => e
|
|
131
|
+
raise apply_failure(
|
|
132
|
+
"Apply failed for '#{rel_path}': #{e.class}: #{e.message}; " \
|
|
133
|
+
"#{applied_paths.empty? ? 'no file was written' : "already written: #{applied_paths.join(', ')}"}; " \
|
|
134
|
+
"#{pending_after(keys_to_apply, index).size} file(s) still dirty",
|
|
135
|
+
kind: :write_failed, applied: applied_paths, failed: rel_path,
|
|
136
|
+
pending: pending_after(keys_to_apply, index), conflicts: conflicts, skipped: skipped
|
|
137
|
+
), cause: e
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
overlay.original_hashes[rel_path] = Digest::SHA256.hexdigest(content)
|
|
141
|
+
overlay.dirty_files.delete(rel_path)
|
|
142
|
+
overlay.buffer.delete(rel_path)
|
|
143
|
+
applied_paths << rel_path
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# Build the structured partial-apply error with frozen report copies —
|
|
147
|
+
# a reader must see the state at raise time, not later mutations.
|
|
148
|
+
def apply_failure(message, kind:, applied:, failed:, pending:, conflicts:, skipped: [])
|
|
149
|
+
ApplyFailedError.new(
|
|
150
|
+
message, kind: kind,
|
|
151
|
+
applied: applied.dup.freeze, failed: failed,
|
|
152
|
+
pending: pending.dup.freeze, conflicts: conflicts.dup.freeze,
|
|
153
|
+
skipped: skipped.dup.freeze
|
|
154
|
+
)
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
# This run's remaining dirty entries after the failed index — exactly
|
|
158
|
+
# what a retry will still have to write (garbage-skipped entries are
|
|
159
|
+
# already out of dirty_files when this runs).
|
|
160
|
+
def pending_after(keys, index)
|
|
161
|
+
keys[(index + 1)..].to_a.select { |k| overlay.dirty_files.key?(k) }
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
end
|
data/lib/rubik/buffer/manager.rb
CHANGED
|
@@ -5,8 +5,9 @@ require "find"
|
|
|
5
5
|
require "digest"
|
|
6
6
|
require "pathname"
|
|
7
7
|
require "monitor"
|
|
8
|
+
require_relative "apply_transaction"
|
|
9
|
+
require_relative "../storage/layout"
|
|
8
10
|
require_relative "diff"
|
|
9
|
-
require_relative "path_validator"
|
|
10
11
|
require_relative "../platform"
|
|
11
12
|
require_relative "../security/guard"
|
|
12
13
|
|
|
@@ -57,6 +58,11 @@ module Rubik
|
|
|
57
58
|
@last_conflicts = [].freeze
|
|
58
59
|
@last_skipped = [].freeze
|
|
59
60
|
@last_applied = nil
|
|
61
|
+
@apply_transaction = ApplyTransaction.new(
|
|
62
|
+
overlay: ApplyTransaction::Overlay.new(@buffer, @dirty_files, @original_hashes),
|
|
63
|
+
disk_policy: self,
|
|
64
|
+
event_bus: event_bus
|
|
65
|
+
)
|
|
60
66
|
end
|
|
61
67
|
|
|
62
68
|
def add_root(path, rw: false) # rubocop:disable Naming/MethodParameterName -- rw: bilinçli kisa kwarg
|
|
@@ -311,45 +317,28 @@ module Rubik
|
|
|
311
317
|
end
|
|
312
318
|
|
|
313
319
|
# Applies dirty buffer entries to disk (per-file atomic writes — NOT a
|
|
314
|
-
# multi-file transaction).
|
|
315
|
-
#
|
|
316
|
-
#
|
|
317
|
-
#
|
|
318
|
-
#
|
|
320
|
+
# multi-file transaction). Delegates the loop to the extracted
|
|
321
|
+
# ApplyTransaction (issue #472); see that class for the failure and
|
|
322
|
+
# conflict semantics. `on_finish` runs even on a mid-run failure, so
|
|
323
|
+
# the run report (last_conflicts / last_skipped / last_applied) is
|
|
324
|
+
# recorded exactly as before.
|
|
319
325
|
def apply!(target_paths = nil, policy: nil)
|
|
320
326
|
@monitor.synchronize do
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
327
|
+
keys_to_apply = if target_paths
|
|
328
|
+
Array(target_paths).map { |p| sanitize_path(p, for_write: true) }
|
|
329
|
+
else
|
|
330
|
+
@dirty_files.keys.dup
|
|
331
|
+
end
|
|
325
332
|
effective_policy = (policy || external_modification_policy).to_s.downcase
|
|
326
333
|
|
|
327
|
-
|
|
328
|
-
keys_to_apply.each_with_index do |rel_path, index|
|
|
329
|
-
next unless @dirty_files.key?(rel_path)
|
|
330
|
-
|
|
331
|
-
unless validate_and_clean_garbage(rel_path)
|
|
332
|
-
skipped << { path: rel_path, reason: :path_validator_rejected }
|
|
333
|
-
next
|
|
334
|
-
end
|
|
335
|
-
|
|
336
|
-
if external_conflict?(rel_path) && effective_policy != "overwrite"
|
|
337
|
-
conflicts << rel_path
|
|
338
|
-
@event_bus&.emit(:buffer_apply_conflict, paths: conflicts.dup.freeze, path: rel_path)
|
|
339
|
-
next
|
|
340
|
-
end
|
|
341
|
-
|
|
342
|
-
apply_single_entry(rel_path, index: index, keys_to_apply: keys_to_apply,
|
|
343
|
-
applied_paths: applied_paths, conflicts: conflicts, skipped: skipped)
|
|
344
|
-
end
|
|
345
|
-
ensure
|
|
334
|
+
result = @apply_transaction.run(keys_to_apply, effective_policy) do |applied_paths, conflicts, skipped|
|
|
346
335
|
@last_conflicts = conflicts.dup.freeze
|
|
347
336
|
@last_skipped = skipped.dup.freeze
|
|
348
337
|
@last_applied = { at: Time.now.utc, paths: applied_paths.dup.freeze } unless applied_paths.empty?
|
|
349
338
|
end
|
|
350
339
|
|
|
351
|
-
@event_bus&.emit(:buffer_applied, paths:
|
|
352
|
-
|
|
340
|
+
@event_bus&.emit(:buffer_applied, paths: result.applied.dup.freeze) unless result.applied.empty?
|
|
341
|
+
result.applied
|
|
353
342
|
end
|
|
354
343
|
end
|
|
355
344
|
|
|
@@ -393,76 +382,11 @@ module Rubik
|
|
|
393
382
|
end
|
|
394
383
|
end
|
|
395
384
|
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
else
|
|
402
|
-
@dirty_files.keys.dup
|
|
403
|
-
end
|
|
404
|
-
end
|
|
405
|
-
|
|
406
|
-
def validate_and_clean_garbage(rel_path)
|
|
407
|
-
return true if PathValidator.valid?(rel_path)
|
|
408
|
-
|
|
409
|
-
@dirty_files.delete(rel_path)
|
|
410
|
-
@buffer.delete(rel_path)
|
|
411
|
-
@original_hashes.delete(rel_path)
|
|
412
|
-
@event_bus&.emit(:buffer_garbage_skipped, path: rel_path)
|
|
413
|
-
false
|
|
414
|
-
end
|
|
415
|
-
|
|
416
|
-
def external_conflict?(rel_path)
|
|
417
|
-
baseline = @original_hashes[rel_path]
|
|
418
|
-
current_disk = disk_hash(rel_path)
|
|
419
|
-
|
|
420
|
-
if baseline
|
|
421
|
-
current_disk != baseline
|
|
422
|
-
else
|
|
423
|
-
!current_disk.nil?
|
|
424
|
-
end
|
|
425
|
-
end
|
|
426
|
-
|
|
427
|
-
def apply_single_entry(rel_path, index:, keys_to_apply:, applied_paths:, conflicts:, skipped:)
|
|
428
|
-
full_path = File.expand_path(rel_path, @root_dir)
|
|
429
|
-
|
|
430
|
-
# TOCTOU close: re-verify containment immediately before the
|
|
431
|
-
# atomic write — a symlink planted between write-time sanitize
|
|
432
|
-
# and apply! must not redirect the write outside the workspace.
|
|
433
|
-
# Fail loud: an untrustworthy path is an attack signal or a
|
|
434
|
-
# mid-flight root misconfiguration, not a content problem; the
|
|
435
|
-
# entry stays dirty for a retry after remediation.
|
|
436
|
-
containment_kind, = containment_root(full_path)
|
|
437
|
-
unless containment_kind
|
|
438
|
-
@event_bus&.emit(:buffer_containment_blocked, path: rel_path)
|
|
439
|
-
raise apply_failure(
|
|
440
|
-
"Write blocked: '#{rel_path}' resolves outside all allowed roots at apply time " \
|
|
441
|
-
"(possible symlink swap since buffering). Re-verify the workspace and retry.",
|
|
442
|
-
kind: :containment_blocked, applied: applied_paths, failed: rel_path,
|
|
443
|
-
pending: pending_after(keys_to_apply, index), conflicts: conflicts, skipped: skipped
|
|
444
|
-
)
|
|
445
|
-
end
|
|
446
|
-
|
|
447
|
-
content = @buffer[rel_path]
|
|
448
|
-
|
|
449
|
-
begin
|
|
450
|
-
Rubik::Platform.atomic_write(full_path, content)
|
|
451
|
-
rescue StandardError => e
|
|
452
|
-
raise apply_failure(
|
|
453
|
-
"Apply failed for '#{rel_path}': #{e.class}: #{e.message}; " \
|
|
454
|
-
"#{applied_paths.empty? ? 'no file was written' : "already written: #{applied_paths.join(', ')}"}; " \
|
|
455
|
-
"#{pending_after(keys_to_apply, index).size} file(s) still dirty",
|
|
456
|
-
kind: :write_failed, applied: applied_paths, failed: rel_path,
|
|
457
|
-
pending: pending_after(keys_to_apply, index), conflicts: conflicts, skipped: skipped
|
|
458
|
-
), cause: e
|
|
459
|
-
end
|
|
460
|
-
|
|
461
|
-
@original_hashes[rel_path] = Digest::SHA256.hexdigest(content)
|
|
462
|
-
@dirty_files.delete(rel_path)
|
|
463
|
-
@buffer.delete(rel_path)
|
|
464
|
-
applied_paths << rel_path
|
|
465
|
-
end
|
|
385
|
+
# -- Disk policy adapter for ApplyTransaction (issue #472) ------------
|
|
386
|
+
# Manager serves as the transaction's `disk_policy`: these three are
|
|
387
|
+
# the workspace path policy the apply loop consults. Public because
|
|
388
|
+
# the transaction calls them across the object boundary; not part of
|
|
389
|
+
# the dictionary-facing Manager API.
|
|
466
390
|
|
|
467
391
|
# Single source of boundary containment for both the sanitize_path
|
|
468
392
|
# entry check and the apply! re-verification. Returns [kind, dir] with
|
|
@@ -481,7 +405,7 @@ module Rubik
|
|
|
481
405
|
|
|
482
406
|
def external_modification_policy
|
|
483
407
|
raw = if @config.is_a?(Rubik::Config)
|
|
484
|
-
@config
|
|
408
|
+
Rubik::Storage::Layout.config_get(@config, "buffer.on_external_modification", "skip")
|
|
485
409
|
elsif @config.respond_to?(:dig)
|
|
486
410
|
@config.dig("buffer", "on_external_modification") ||
|
|
487
411
|
(@config["buffer.on_external_modification"] if @config.respond_to?(:[])) ||
|
|
@@ -500,24 +424,6 @@ module Rubik
|
|
|
500
424
|
rescue Errno::ENOENT, Errno::EACCES
|
|
501
425
|
nil
|
|
502
426
|
end
|
|
503
|
-
|
|
504
|
-
# Build the structured partial-apply error with frozen report copies —
|
|
505
|
-
# a reader must see the state at raise time, not later mutations.
|
|
506
|
-
def apply_failure(message, kind:, applied:, failed:, pending:, conflicts:, skipped: [])
|
|
507
|
-
ApplyFailedError.new(
|
|
508
|
-
message, kind: kind,
|
|
509
|
-
applied: applied.dup.freeze, failed: failed,
|
|
510
|
-
pending: pending.dup.freeze, conflicts: conflicts.dup.freeze,
|
|
511
|
-
skipped: skipped.dup.freeze
|
|
512
|
-
)
|
|
513
|
-
end
|
|
514
|
-
|
|
515
|
-
# This run's remaining dirty entries after the failed index — exactly
|
|
516
|
-
# what a retry will still have to write (garbage-skipped entries are
|
|
517
|
-
# already out of dirty_files when this runs).
|
|
518
|
-
def pending_after(keys, index)
|
|
519
|
-
keys[(index + 1)..].to_a.select { |k| @dirty_files.key?(k) }
|
|
520
|
-
end
|
|
521
427
|
end
|
|
522
428
|
end
|
|
523
429
|
end
|
|
@@ -25,6 +25,10 @@ module Rubik
|
|
|
25
25
|
Rubik can read and modify workspace files and run foreground and background commands.
|
|
26
26
|
Some commands may run without a separate approval. OS sandboxing is disabled by default.
|
|
27
27
|
|
|
28
|
+
MCP stdio servers spawned here inherit this environment (minus bundler/Ruby runtime
|
|
29
|
+
variables), including credential-shaped variables, unless a server configures
|
|
30
|
+
`inherit_env: false`. Treat each server's env block as a credential-flow decision.
|
|
31
|
+
|
|
28
32
|
`buffer.model_can_apply: false` only restricts applying staged buffer changes; it does
|
|
29
33
|
not restrict shell commands.
|
|
30
34
|
NOTICE
|
|
@@ -60,6 +64,7 @@ module Rubik
|
|
|
60
64
|
def trust!(workspace, store_path: default_store_path)
|
|
61
65
|
FileUtils.mkdir_p(File.dirname(store_path), mode: 0o700)
|
|
62
66
|
workspace_path = File.realpath(workspace)
|
|
67
|
+
ensure_owner_only_store!(store_path)
|
|
63
68
|
store = YAML::Store.new(store_path, true)
|
|
64
69
|
store.transaction do
|
|
65
70
|
paths = Array(store[TRUSTED_WORKSPACES_KEY])
|
|
@@ -70,6 +75,17 @@ module Rubik
|
|
|
70
75
|
|
|
71
76
|
private
|
|
72
77
|
|
|
78
|
+
# YAML::Store creates a missing file with the process umask
|
|
79
|
+
# (typically 0644); the trust store must be owner-only from the first
|
|
80
|
+
# byte on disk, so it is pre-created at 0600 before the transaction
|
|
81
|
+
# opens it. Failure keeps the legacy best-effort chmod behavior.
|
|
82
|
+
def ensure_owner_only_store!(path)
|
|
83
|
+
FileUtils.touch(path) unless File.exist?(path)
|
|
84
|
+
File.chmod(0o600, path)
|
|
85
|
+
rescue SystemCallError
|
|
86
|
+
nil
|
|
87
|
+
end
|
|
88
|
+
|
|
73
89
|
def default_store_path
|
|
74
90
|
File.join(Platform.home_dir, ".rubik", "trusted_workspaces.yml")
|
|
75
91
|
end
|
|
@@ -4,7 +4,10 @@ module Rubik
|
|
|
4
4
|
class Config
|
|
5
5
|
module DeepOps
|
|
6
6
|
SENSITIVE_PROJECT_CONFIG_KEYS = [
|
|
7
|
-
"security", "sandbox", "plugins", "mcp", "lsp", "project", "test", "linter", "adapter"
|
|
7
|
+
"security", "sandbox", "plugins", "mcp", "lsp", "project", "test", "linter", "adapter",
|
|
8
|
+
# Provider specs carry credentials and endpoints; an untrusted
|
|
9
|
+
# project must not be able to inject either.
|
|
10
|
+
"providers"
|
|
8
11
|
].freeze
|
|
9
12
|
|
|
10
13
|
private
|
|
@@ -49,6 +49,9 @@ module Rubik
|
|
|
49
49
|
# current behavior). RUBIK_TOOLS_CALL_TIMEOUT env overrides the file.
|
|
50
50
|
# A timed-out call is abandoned, not killed — bounds turn latency.
|
|
51
51
|
"call_timeout" => nil,
|
|
52
|
+
# Grace-then-kill reaper (issue #449): seconds an abandoned worker may
|
|
53
|
+
# run past call_timeout before the reaper kills it; the value IS the grace. nil = off.
|
|
54
|
+
"timeout_kill_after" => nil,
|
|
52
55
|
# Canonical tool name => seconds; 0/false disables for that tool.
|
|
53
56
|
"call_timeout_overrides" => {},
|
|
54
57
|
"native" => "auto"
|
|
@@ -67,10 +70,10 @@ module Rubik
|
|
|
67
70
|
"prompt_on_startup" => true, "isolation_note" => true # append the 🔍 isolation line to run_command output (sandbox/runner.rb)
|
|
68
71
|
},
|
|
69
72
|
"security" => {
|
|
70
|
-
# NOTE: no audit_log_path default — Guard.default_audit_log_path
|
|
71
|
-
# single source so the value resolves at call time; a load-time snapshot would pin require-time HOME.
|
|
73
|
+
# NOTE: no audit_log_path default — Guard.default_audit_log_path is the single source; call-time resolution avoids pinning require-time HOME.
|
|
72
74
|
"command_allowlist" => [], # operator-managed token-prefix entries (e.g. "node .gitnexus/run.cjs")
|
|
73
|
-
"allow_safe_probes" => true # `bash --version`-style version/help probes bypass the blocklist
|
|
75
|
+
"allow_safe_probes" => true, # `bash --version`-style version/help probes bypass the blocklist
|
|
76
|
+
"allow_project_secrets" => false # SecretPolicy: project plaintext refused by default; true = legacy
|
|
74
77
|
},
|
|
75
78
|
"buffer" => {
|
|
76
79
|
"auto_apply" => "manual",
|
|
@@ -219,6 +222,12 @@ module Rubik
|
|
|
219
222
|
"adapter" => {}
|
|
220
223
|
}.freeze
|
|
221
224
|
|
|
225
|
+
# Retired config keys (dotted key => guidance): validate_schema emits the
|
|
226
|
+
# tailored deprecation at boot; runtime set() keeps its own warn (config_wiring.rb).
|
|
227
|
+
RETIRED_KEYS = {
|
|
228
|
+
"network.allow" => "[DEPRECATION] Config key 'network.allow' is deprecated and has no effect. Use 'sandbox.allow_network' instead."
|
|
229
|
+
}.freeze
|
|
230
|
+
|
|
222
231
|
private
|
|
223
232
|
|
|
224
233
|
# Schema-backed keys must satisfy their spec wherever the merged tree is validated.
|
|
@@ -244,6 +253,8 @@ module Rubik
|
|
|
244
253
|
else
|
|
245
254
|
"Unknown config key '#{current_key}'."
|
|
246
255
|
end
|
|
256
|
+
# A retired key wins over the generic/fuzzy unknown-key line.
|
|
257
|
+
suggestion_msg = retired_key_warning(current_key, val) || suggestion_msg
|
|
247
258
|
|
|
248
259
|
raise ArgumentError, suggestion_msg if strict
|
|
249
260
|
|
|
@@ -253,6 +264,21 @@ module Rubik
|
|
|
253
264
|
end
|
|
254
265
|
end
|
|
255
266
|
end
|
|
267
|
+
|
|
268
|
+
# Tailored deprecation for a retired key (RETIRED_KEYS): an exact dotted
|
|
269
|
+
# hit, or a config-file section whose subtree carries a retired leaf
|
|
270
|
+
# ("network: {allow: true}" lands on unknown top-level 'network').
|
|
271
|
+
# nil falls through to the generic unknown-key line.
|
|
272
|
+
def retired_key_warning(current_key, val)
|
|
273
|
+
return RETIRED_KEYS[current_key] if RETIRED_KEYS.key?(current_key)
|
|
274
|
+
|
|
275
|
+
return nil unless val.is_a?(Hash)
|
|
276
|
+
|
|
277
|
+
retired_leaves = val.keys.filter_map { |child| RETIRED_KEYS["#{current_key}.#{child}"] }
|
|
278
|
+
return nil if retired_leaves.empty?
|
|
279
|
+
|
|
280
|
+
retired_leaves.join(" ")
|
|
281
|
+
end
|
|
256
282
|
end
|
|
257
283
|
end
|
|
258
284
|
end
|
data/lib/rubik/config/schema.rb
CHANGED
|
@@ -27,6 +27,10 @@ module Rubik
|
|
|
27
27
|
"tools.truncation_strategy" => { type: :enum, allowed: ["head_tail", "head_only", "tail_only"] },
|
|
28
28
|
# min 0: 0 is a documented disable value (tool_timeout treats <=0 as off).
|
|
29
29
|
"tools.call_timeout" => { type: :integer, min: 0, nullable: true },
|
|
30
|
+
# Grace-then-kill reaper (issue #449): seconds an abandoned tool worker
|
|
31
|
+
# may keep running past its call_timeout budget before the reaper kills
|
|
32
|
+
# it. nil = off (pure abandonment). Non-positive is treated as off.
|
|
33
|
+
"tools.timeout_kill_after" => { type: :integer, min: 0, nullable: true },
|
|
30
34
|
"tools.native" => { type: :enum, allowed: ["auto", "on", "off"] },
|
|
31
35
|
"router.mode" => { type: :enum, allowed: ["auto", "manual", "fast", "advanced"] },
|
|
32
36
|
"router.sticky" => { type: :boolean },
|
|
@@ -41,6 +45,10 @@ module Rubik
|
|
|
41
45
|
"sandbox.shell" => { type: :enum, allowed: ["auto", "bash", "powershell"] },
|
|
42
46
|
"security.allow_safe_probes" => { type: :boolean },
|
|
43
47
|
"security.command_allowlist" => { type: :array },
|
|
48
|
+
# Escape hatch for SecretPolicy: plaintext provider secrets in the
|
|
49
|
+
# PROJECT config are refused by default (leak vector via commits);
|
|
50
|
+
# this opt-in restores the legacy behavior per workspace.
|
|
51
|
+
"security.allow_project_secrets" => { type: :boolean },
|
|
44
52
|
"buffer.auto_apply" => { type: :enum, allowed: ["manual", "on_test", "on_finish", "always"] },
|
|
45
53
|
"buffer.model_can_apply" => { type: :boolean },
|
|
46
54
|
"buffer.prompt_indicator" => { type: :boolean },
|