rubik 0.10.0 → 0.11.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 +61 -1
- data/lib/rubik/ast/extractor.rb +2 -1
- data/lib/rubik/ast/treesitter_extractor.rb +2 -1
- data/lib/rubik/benchmark/vakanuvis_adoption.rb +2 -1
- data/lib/rubik/config/secret_policy.rb +6 -5
- data/lib/rubik/config/store.rb +2 -1
- data/lib/rubik/config.rb +2 -2
- data/lib/rubik/context/ignore_rules.rb +193 -0
- data/lib/rubik/context/scanner.rb +46 -161
- data/lib/rubik/llm/client.rb +6 -200
- data/lib/rubik/llm/connection_pool.rb +104 -0
- data/lib/rubik/llm/registry.rb +3 -2
- data/lib/rubik/llm/sse_parser.rb +110 -0
- data/lib/rubik/lsp/circuit_breaker.rb +98 -0
- data/lib/rubik/lsp/client_provisioner.rb +49 -0
- data/lib/rubik/lsp/manager.rb +55 -88
- data/lib/rubik/mcp/manager.rb +25 -13
- data/lib/rubik/orchestrator/auto_apply.rb +4 -3
- data/lib/rubik/orchestrator/goal_ledger/ledger.rb +12 -1
- data/lib/rubik/orchestrator/goal_ledger/schema_vocabulary.rb +38 -0
- data/lib/rubik/orchestrator/goal_ledger/xml_render.rb +6 -1
- data/lib/rubik/orchestrator/goal_ledger.rb +1 -0
- data/lib/rubik/orchestrator/lsp_feedback.rb +1 -1
- data/lib/rubik/orchestrator/step_executor.rb +2 -1
- data/lib/rubik/orchestrator/subagent/notices.rb +2 -2
- data/lib/rubik/orchestrator/subagent/transcript_formatter.rb +2 -1
- data/lib/rubik/platform/io_drain.rb +3 -1
- data/lib/rubik/plugin/storage.rb +8 -8
- data/lib/rubik/repl/config_wiring.rb +5 -3
- data/lib/rubik/repl/input_execution.rb +4 -3
- data/lib/rubik/repl/lifecycle.rb +1 -1
- data/lib/rubik/repl/tee_io.rb +2 -1
- data/lib/rubik/runtime/ast_service.rb +2 -1
- data/lib/rubik/runtime/overlay_storage.rb +17 -17
- data/lib/rubik/runtime/task_manager.rb +1 -1
- data/lib/rubik/sandbox/runner.rb +5 -4
- data/lib/rubik/security/audit_log.rb +2 -1
- data/lib/rubik/security/command_gate.rb +11 -152
- data/lib/rubik/security/guard.rb +1 -1
- data/lib/rubik/security/secret_store.rb +32 -3
- data/lib/rubik/security/segment_report.rb +161 -0
- data/lib/rubik/session/recorder.rb +2 -1
- data/lib/rubik/skills/manager.rb +2 -1
- data/lib/rubik/storage/transcript_indexer.rb +3 -2
- data/lib/rubik/storage/vakanuvis.rb +2 -1
- data/lib/rubik/tools/builtins/goal_ledger.rb +12 -1
- data/lib/rubik/tools/builtins/synthesis.rb +3 -3
- data/lib/rubik/tools/preflight_runner.rb +2 -1
- data/lib/rubik/tools/uri_resolver.rb +3 -2
- data/lib/rubik/ui/capability.rb +1 -0
- data/lib/rubik/version.rb +1 -1
- data/lib/rubik.rb +3 -3
- metadata +8 -1
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "shellwords"
|
|
4
|
+
require_relative "../log"
|
|
4
5
|
require_relative "allowlist"
|
|
5
6
|
require_relative "classifier"
|
|
6
7
|
require_relative "errors"
|
|
8
|
+
require_relative "segment_report"
|
|
7
9
|
|
|
8
10
|
module Rubik
|
|
9
11
|
module Security
|
|
@@ -57,12 +59,6 @@ module Rubik
|
|
|
57
59
|
/%0\|%0/
|
|
58
60
|
].freeze
|
|
59
61
|
|
|
60
|
-
# Display caps for the blocked-segment report (guidance rendering, not
|
|
61
|
-
# gate semantics): one segment's argv rendering and the one-line
|
|
62
|
-
# wrapper preview never exceed these.
|
|
63
|
-
SEGMENT_DISPLAY_CAP = 120
|
|
64
|
-
WRAPPER_PREVIEW_CAP = 60
|
|
65
|
-
|
|
66
62
|
# Salt version/help probe'ları (Plan: safe-probe muafiyeti): a command
|
|
67
63
|
# whose ONLY arguments are these flags is read-only by construction.
|
|
68
64
|
SAFE_PROBE_FLAGS = ["--version", "-v", "--help", "-h"].freeze
|
|
@@ -213,11 +209,11 @@ module Rubik
|
|
|
213
209
|
# today) keeps flowing into its own deny layers
|
|
214
210
|
# (DANGEROUS_SYNTHESIS_PATTERNS + RubyVM walk) after this gate.
|
|
215
211
|
if allow_unknown
|
|
216
|
-
warn "[WARN] AST classification error on non-shell input, continuing to synthesis deny layers: #{e.message}"
|
|
212
|
+
Rubik::Log.warn(:security, "[WARN] AST classification error on non-shell input, continuing to synthesis deny layers: #{e.message}")
|
|
217
213
|
@audit.log_audit("classifier_error", command: cmd_str, reason: "#{e.class}: #{e.message}",
|
|
218
214
|
decision: "synthesis_layers")
|
|
219
215
|
else
|
|
220
|
-
warn "[WARN] AST classification error, failing closed: #{e.class}: #{e.message}"
|
|
216
|
+
Rubik::Log.warn(:security, "[WARN] AST classification error, failing closed: #{e.class}: #{e.message}")
|
|
221
217
|
block_on_classifier_failure!(cmd_str, e)
|
|
222
218
|
end
|
|
223
219
|
end
|
|
@@ -263,7 +259,7 @@ module Rubik
|
|
|
263
259
|
@allowlist.command_allowlisted?(ast, cmd_str: cmd_str)
|
|
264
260
|
end
|
|
265
261
|
rescue StandardError => e
|
|
266
|
-
warn "[Guard] #{'raw ' if raw}allowlist evaluation failed, failing closed: #{e.class}: #{e.message}"
|
|
262
|
+
Rubik::Log.warn(:security, "[Guard] #{'raw ' if raw}allowlist evaluation failed, failing closed: #{e.class}: #{e.message}")
|
|
267
263
|
false
|
|
268
264
|
end
|
|
269
265
|
|
|
@@ -294,10 +290,14 @@ module Rubik
|
|
|
294
290
|
# to nil: enrichment must never be able to un-block, so a bug in the
|
|
295
291
|
# report walk downgrades to nil here and the raise in
|
|
296
292
|
# block_dangerous_command! still fires.
|
|
293
|
+
# Report assembly delegates to Security::SegmentReport (#500), fail-soft
|
|
294
|
+
# to nil: enrichment must never be able to un-block, so a bug in the
|
|
295
|
+
# report walk downgrades to nil here and the raise in
|
|
296
|
+
# block_dangerous_command! still fires.
|
|
297
297
|
def dangerous_segment_report_or_nil(commands)
|
|
298
|
-
|
|
298
|
+
SegmentReport.build(commands)
|
|
299
299
|
rescue StandardError => e
|
|
300
|
-
warn "[Guard] segment report failed: #{e.class}: #{e.message}"
|
|
300
|
+
Rubik::Log.warn(:security, "[Guard] segment report failed: #{e.class}: #{e.message}")
|
|
301
301
|
nil
|
|
302
302
|
end
|
|
303
303
|
|
|
@@ -413,147 +413,6 @@ module Rubik
|
|
|
413
413
|
reason.empty? ? nil : reason
|
|
414
414
|
end
|
|
415
415
|
|
|
416
|
-
# Structured report for wrapper/multi-segment blocked-command guidance:
|
|
417
|
-
# every innermost dangerous segment with its trigger, the sibling
|
|
418
|
-
# commands that passed, a one-line wrapper preview, and the allowlist
|
|
419
|
-
# entries that would actually open the gate. Plain data only —
|
|
420
|
-
# BlockedWriteError must stay loadable without the classifier stack.
|
|
421
|
-
# nil when no single command is dangerous (expression-level elevations
|
|
422
|
-
# keep the scalar rule_name guidance path).
|
|
423
|
-
def dangerous_segment_report(commands)
|
|
424
|
-
segments = []
|
|
425
|
-
safe = []
|
|
426
|
-
safe_top_argv = []
|
|
427
|
-
wrappers = []
|
|
428
|
-
collect_dangerous_units(commands, 0, segments, safe, safe_top_argv, wrappers)
|
|
429
|
-
return nil if segments.empty?
|
|
430
|
-
|
|
431
|
-
# The gate (command_allowlisted?) matches EVERY top-level command,
|
|
432
|
-
# safe ones included — the entry set must cover them all to be
|
|
433
|
-
# honest: wrapper prefix + top-level dangerous segments + top-level
|
|
434
|
-
# safe units.
|
|
435
|
-
entries = wrappers.map { |w| wrapper_allowlist_entry(w) }
|
|
436
|
-
entries += segments.select { |s| s[:depth].zero? }.map { |s| allowlist_entry_for_argv(s[:argv]) }
|
|
437
|
-
entries += safe_top_argv.map { |argv| allowlist_entry_for_argv(argv) }
|
|
438
|
-
|
|
439
|
-
{
|
|
440
|
-
segments: segments,
|
|
441
|
-
safe: safe.uniq,
|
|
442
|
-
wrapper_preview: wrappers.empty? ? nil : wrapper_preview(wrappers.first),
|
|
443
|
-
allowlist_entries: entries.uniq
|
|
444
|
-
}.freeze
|
|
445
|
-
end
|
|
446
|
-
|
|
447
|
-
# Depth-first walk over the classified command tree. A dangerous
|
|
448
|
-
# command whose danger comes from dangerous inners contributes those
|
|
449
|
-
# inner leaves instead of itself (bash -c "rm -rf /" reports the inner
|
|
450
|
-
# rm, not the wrapper); a dangerous leaf is a segment; non-dangerous
|
|
451
|
-
# leaves join the passed roll call. Top-level wrappers (dangerous only
|
|
452
|
-
# through their inners) are tracked separately for preview + hint;
|
|
453
|
-
# top-level safe units keep their argv for the gate-honest entry set.
|
|
454
|
-
def collect_dangerous_units(commands, depth, segments, safe, safe_top_argv, wrappers)
|
|
455
|
-
Array(commands).each do |c|
|
|
456
|
-
inners = Array(c.inner_commands)
|
|
457
|
-
before = segments.size
|
|
458
|
-
collect_dangerous_units(inners, depth + 1, segments, safe, safe_top_argv, wrappers)
|
|
459
|
-
added = segments.size - before
|
|
460
|
-
|
|
461
|
-
if c.classification == :dangerous
|
|
462
|
-
if added.positive?
|
|
463
|
-
wrappers << c if depth.zero?
|
|
464
|
-
else
|
|
465
|
-
segments << dangerous_segment_data(c, depth)
|
|
466
|
-
end
|
|
467
|
-
elsif inners.empty?
|
|
468
|
-
safe << safe_segment_name(c)
|
|
469
|
-
safe_top_argv << c.argv.dup if depth.zero?
|
|
470
|
-
end
|
|
471
|
-
end
|
|
472
|
-
end
|
|
473
|
-
|
|
474
|
-
def dangerous_segment_data(result, depth)
|
|
475
|
-
argv = Array(result.argv)
|
|
476
|
-
{
|
|
477
|
-
display: segment_display(display_tokens(argv, result)),
|
|
478
|
-
argv: argv.dup.freeze,
|
|
479
|
-
rule: result.matched_rule,
|
|
480
|
-
option: result.overriding_option,
|
|
481
|
-
reason: result.classification_reason,
|
|
482
|
-
depth: depth
|
|
483
|
-
}
|
|
484
|
-
end
|
|
485
|
-
|
|
486
|
-
# Redirect-bearing segments (delegated inners) render their effects,
|
|
487
|
-
# not just their argv: `echo pwned > /etc/shadow`, not `echo pwned`.
|
|
488
|
-
# Flat operator/target tokens keep segment_display's quoting correct;
|
|
489
|
-
# argv itself stays pure — allowlist entries derive from it.
|
|
490
|
-
def display_tokens(argv, result)
|
|
491
|
-
reds = result.respond_to?(:redirects) ? Array(result.redirects) : []
|
|
492
|
-
reds.empty? ? argv : argv + reds.flat_map { |r| [r.operator, r.target] }
|
|
493
|
-
end
|
|
494
|
-
|
|
495
|
-
# Subcommand-aware roll call of the units that passed ("git checkout",
|
|
496
|
-
# not just "git") — matches the operator's mental model of the script.
|
|
497
|
-
def safe_segment_name(result)
|
|
498
|
-
result.command.join(" ")
|
|
499
|
-
end
|
|
500
|
-
|
|
501
|
-
# One-line wrapper preview for the guidance first line. The delegated
|
|
502
|
-
# payload (the whole -c script) is the argv token that contains
|
|
503
|
-
# whitespace — elide it so the full script is never re-embedded in the
|
|
504
|
-
# message (the defect this report exists to fix).
|
|
505
|
-
def wrapper_preview(result)
|
|
506
|
-
argv = Array(result.argv)
|
|
507
|
-
tokens = argv.dup
|
|
508
|
-
tokens[-1] = "'...'" if tokens.size > 1 && tokens[-1].to_s.match?(/\s/)
|
|
509
|
-
preview = segment_display(tokens)
|
|
510
|
-
preview.length > WRAPPER_PREVIEW_CAP ? "#{preview[0, WRAPPER_PREVIEW_CAP - 1]}..." : preview
|
|
511
|
-
end
|
|
512
|
-
|
|
513
|
-
# Shortest top-level argv prefix that actually satisfies the gate's
|
|
514
|
-
# token-prefix match (command_allowlisted?): the wrapper binary up to
|
|
515
|
-
# and including its delegation flag for flag-value payloads
|
|
516
|
-
# ("bash -c", "bash -e -c"), the bare binary for rest-argv wrappers
|
|
517
|
-
# ("sudo", "xargs"). Deriving it from delegation_source keeps the hint
|
|
518
|
-
# gate-honest for flag permutations a naive first-two-tokens guess
|
|
519
|
-
# would miss.
|
|
520
|
-
def wrapper_allowlist_entry(wrapper)
|
|
521
|
-
argv = Array(wrapper.argv)
|
|
522
|
-
return argv.first.to_s if argv.size <= 1
|
|
523
|
-
|
|
524
|
-
first_inner = Array(wrapper.inner_commands).first
|
|
525
|
-
if first_inner&.delegation_mode.to_s == "flag_value_is_expression"
|
|
526
|
-
idx = argv.index(first_inner.delegation_source)
|
|
527
|
-
return argv[0..idx].join(" ") if idx&.positive?
|
|
528
|
-
end
|
|
529
|
-
argv.first.to_s
|
|
530
|
-
end
|
|
531
|
-
|
|
532
|
-
# An allowlist entry can only carry whitespace-free tokens:
|
|
533
|
-
# normalize_allowlist splits entries on whitespace, so an argv token
|
|
534
|
-
# containing spaces ("feature x") can never be matched by an entry.
|
|
535
|
-
# Prefix up to (excluding) the first such token.
|
|
536
|
-
def allowlist_entry_for_argv(argv)
|
|
537
|
-
prefix = []
|
|
538
|
-
Array(argv).each do |token|
|
|
539
|
-
break if token.to_s.match?(/\s/)
|
|
540
|
-
|
|
541
|
-
prefix << token
|
|
542
|
-
end
|
|
543
|
-
prefix.empty? ? Array(argv).first.to_s : prefix.join(" ")
|
|
544
|
-
end
|
|
545
|
-
|
|
546
|
-
# Display-only rendering: collapse newlines, single-quote tokens that
|
|
547
|
-
# contain whitespace, hard-cap length. Shellwords.escape would
|
|
548
|
-
# backslash-quote every token (noise on Windows paths) — quote
|
|
549
|
-
# conditionally instead.
|
|
550
|
-
def segment_display(argv)
|
|
551
|
-
text = argv.map { |t| t.to_s.tr("\r\n", " ") }
|
|
552
|
-
.map { |t| t.match?(/\s/) ? "'#{t}'" : t }
|
|
553
|
-
.join(" ")
|
|
554
|
-
text.length > SEGMENT_DISPLAY_CAP ? "#{text[0, SEGMENT_DISPLAY_CAP - 1]}..." : text
|
|
555
|
-
end
|
|
556
|
-
|
|
557
416
|
def segment_count(report)
|
|
558
417
|
report ? report[:segments].size : 0
|
|
559
418
|
end
|
data/lib/rubik/security/guard.rb
CHANGED
|
@@ -63,7 +63,7 @@ module Rubik
|
|
|
63
63
|
# turns "!config set security.audit_log_path false" into boolean
|
|
64
64
|
# false, which would otherwise reach log_audit and die in a
|
|
65
65
|
# swallowed TypeError — silently dropping every audit event.
|
|
66
|
-
warn "[Guard] security.audit_log_path has non-path value #{raw_audit.inspect}; auditing disabled"
|
|
66
|
+
Rubik::Log.warn(:security, "[Guard] security.audit_log_path has non-path value #{raw_audit.inspect}; auditing disabled")
|
|
67
67
|
nil
|
|
68
68
|
end
|
|
69
69
|
|
|
@@ -127,18 +127,39 @@ module Rubik
|
|
|
127
127
|
# Shared command plumbing. Backends are the internal seam; tests may
|
|
128
128
|
# subclass and override #run to avoid touching a host keyring.
|
|
129
129
|
class CommandBackend
|
|
130
|
+
# Deadline for the stdin payload write (see #run).
|
|
131
|
+
STDIN_WRITE_TIMEOUT = 5.0
|
|
132
|
+
|
|
130
133
|
private
|
|
131
134
|
|
|
132
135
|
# Single spawn point for every backend: receives a fully-formed
|
|
133
136
|
# argument vector (never a shell string) plus optional stdin payload.
|
|
137
|
+
#
|
|
138
|
+
# The stdin payload travels through Platform.write_until so a backend
|
|
139
|
+
# that never reads its stdin (headless keychain denial, crashed
|
|
140
|
+
# secret service) fails with a deadline instead of parking the
|
|
141
|
+
# caller forever on a full OS pipe buffer. Every IO failure — a
|
|
142
|
+
# backend that died before reading stdin raising EPIPE, a spawn
|
|
143
|
+
# failure — is converted to Error, because every caller (resolve,
|
|
144
|
+
# set, delete, SecretPolicy, the !secrets commands) rescues only
|
|
145
|
+
# that class.
|
|
134
146
|
def run(argv, input: nil, env: nil)
|
|
135
147
|
env_hash = env.is_a?(Hash) ? env : {}
|
|
136
148
|
merged = ENV.to_h.merge(env_hash)
|
|
137
149
|
Open3.popen3(merged, *argv) do |pin, pout, perr, waiter|
|
|
138
|
-
|
|
139
|
-
|
|
150
|
+
begin
|
|
151
|
+
Rubik::Platform.write_until(pin, input.to_s, timeout: STDIN_WRITE_TIMEOUT)
|
|
152
|
+
ensure
|
|
153
|
+
begin
|
|
154
|
+
pin.close
|
|
155
|
+
rescue IOError, SystemCallError
|
|
156
|
+
nil
|
|
157
|
+
end
|
|
158
|
+
end
|
|
140
159
|
[pout.read, perr.read, waiter.value]
|
|
141
160
|
end
|
|
161
|
+
rescue IOError, SystemCallError => e
|
|
162
|
+
raise Error, "secret backend command failed: #{e.class}: #{e.message}"
|
|
142
163
|
end
|
|
143
164
|
end
|
|
144
165
|
|
|
@@ -162,7 +183,9 @@ module Rubik
|
|
|
162
183
|
# a denied/failed lookup and must not surface as an empty key.
|
|
163
184
|
return nil unless st.success? || st.exitstatus == 44
|
|
164
185
|
|
|
165
|
-
|
|
186
|
+
# The CLI appends exactly one newline; chomp (not strip) so
|
|
187
|
+
# legitimate leading/trailing whitespace in the secret survives.
|
|
188
|
+
val = out.chomp
|
|
166
189
|
val.empty? ? nil : val
|
|
167
190
|
end
|
|
168
191
|
|
|
@@ -299,6 +322,12 @@ module Rubik
|
|
|
299
322
|
end
|
|
300
323
|
|
|
301
324
|
def write(name, value)
|
|
325
|
+
# secret-tool store ADDS a new item; it does not upsert, and
|
|
326
|
+
# lookup concatenates the payloads of every matching item — a
|
|
327
|
+
# re-set secret would silently resolve to "key1key2". Clear any
|
|
328
|
+
# prior items first so set is idempotent (mirroring the -U flag
|
|
329
|
+
# the macOS backend passes to add-generic-password).
|
|
330
|
+
run(clear_argv(name))
|
|
302
331
|
_out, err, st = run(store_argv(name), input: value)
|
|
303
332
|
return true if st.success?
|
|
304
333
|
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Rubik
|
|
4
|
+
module Security
|
|
5
|
+
# Structured guidance-evidence builder for blocked dangerous commands
|
|
6
|
+
# (#500): every innermost dangerous segment with its trigger, the sibling
|
|
7
|
+
# commands that passed, a one-line wrapper preview, and the allowlist
|
|
8
|
+
# entries that would actually open the gate. A pure function from the
|
|
9
|
+
# classified command tree to a frozen plain-data hash — deliberately
|
|
10
|
+
# loadable WITHOUT the classifier stack, so BlockedWriteError guidance
|
|
11
|
+
# never drags the classifier in. nil when no single command is dangerous
|
|
12
|
+
# (expression-level elevations keep the scalar rule_name guidance path).
|
|
13
|
+
module SegmentReport
|
|
14
|
+
# Display caps for the blocked-segment report (guidance rendering, not
|
|
15
|
+
# gate semantics): one segment's argv rendering and the one-line
|
|
16
|
+
# wrapper preview never exceed these.
|
|
17
|
+
SEGMENT_DISPLAY_CAP = 120
|
|
18
|
+
WRAPPER_PREVIEW_CAP = 60
|
|
19
|
+
|
|
20
|
+
# Build the report for the given classified command tree; see the
|
|
21
|
+
# module comment for shape and the nil contract.
|
|
22
|
+
def build(commands)
|
|
23
|
+
segments = []
|
|
24
|
+
safe = []
|
|
25
|
+
safe_top_argv = []
|
|
26
|
+
wrappers = []
|
|
27
|
+
collect_dangerous_units(commands, 0, segments, safe, safe_top_argv, wrappers)
|
|
28
|
+
return nil if segments.empty?
|
|
29
|
+
|
|
30
|
+
# The gate (command_allowlisted?) matches EVERY top-level command,
|
|
31
|
+
# safe ones included — the entry set must cover them all to be
|
|
32
|
+
# honest: wrapper prefix + top-level dangerous segments + top-level
|
|
33
|
+
# safe units.
|
|
34
|
+
entries = wrappers.map { |w| wrapper_allowlist_entry(w) }
|
|
35
|
+
entries += segments.select { |s| s[:depth].zero? }.map { |s| allowlist_entry_for_argv(s[:argv]) }
|
|
36
|
+
entries += safe_top_argv.map { |argv| allowlist_entry_for_argv(argv) }
|
|
37
|
+
|
|
38
|
+
{
|
|
39
|
+
segments: segments,
|
|
40
|
+
safe: safe.uniq,
|
|
41
|
+
wrapper_preview: wrappers.empty? ? nil : wrapper_preview(wrappers.first),
|
|
42
|
+
allowlist_entries: entries.uniq
|
|
43
|
+
}.freeze
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Depth-first walk over the classified command tree. A dangerous
|
|
47
|
+
# command whose danger comes from dangerous inners contributes those
|
|
48
|
+
# inner leaves instead of itself (bash -c "rm -rf /" reports the inner
|
|
49
|
+
# rm, not the wrapper); a dangerous leaf is a segment; non-dangerous
|
|
50
|
+
# leaves join the passed roll call. Top-level wrappers (dangerous only
|
|
51
|
+
# through their inners) are tracked separately for preview + hint;
|
|
52
|
+
# top-level safe units keep their argv for the gate-honest entry set.
|
|
53
|
+
def collect_dangerous_units(commands, depth, segments, safe, safe_top_argv, wrappers)
|
|
54
|
+
Array(commands).each do |c|
|
|
55
|
+
inners = Array(c.inner_commands)
|
|
56
|
+
before = segments.size
|
|
57
|
+
collect_dangerous_units(inners, depth + 1, segments, safe, safe_top_argv, wrappers)
|
|
58
|
+
added = segments.size - before
|
|
59
|
+
|
|
60
|
+
if c.classification == :dangerous
|
|
61
|
+
if added.positive?
|
|
62
|
+
wrappers << c if depth.zero?
|
|
63
|
+
else
|
|
64
|
+
segments << dangerous_segment_data(c, depth)
|
|
65
|
+
end
|
|
66
|
+
elsif inners.empty?
|
|
67
|
+
safe << safe_segment_name(c)
|
|
68
|
+
safe_top_argv << c.argv.dup if depth.zero?
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def dangerous_segment_data(result, depth)
|
|
74
|
+
argv = Array(result.argv)
|
|
75
|
+
{
|
|
76
|
+
display: segment_display(display_tokens(argv, result)),
|
|
77
|
+
argv: argv.dup.freeze,
|
|
78
|
+
rule: result.matched_rule,
|
|
79
|
+
option: result.overriding_option,
|
|
80
|
+
reason: result.classification_reason,
|
|
81
|
+
depth: depth
|
|
82
|
+
}
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# Redirect-bearing segments (delegated inners) render their effects,
|
|
86
|
+
# not just their argv: `echo pwned > /etc/shadow`, not `echo pwned`.
|
|
87
|
+
# Flat operator/target tokens keep segment_display's quoting correct;
|
|
88
|
+
# argv itself stays pure — allowlist entries derive from it.
|
|
89
|
+
def display_tokens(argv, result)
|
|
90
|
+
reds = result.respond_to?(:redirects) ? Array(result.redirects) : []
|
|
91
|
+
reds.empty? ? argv : argv + reds.flat_map { |r| [r.operator, r.target] }
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Subcommand-aware roll call of the units that passed ("git checkout",
|
|
95
|
+
# not just "git") — matches the operator's mental model of the script.
|
|
96
|
+
def safe_segment_name(result)
|
|
97
|
+
result.command.join(" ")
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# One-line wrapper preview for the guidance first line. The delegated
|
|
101
|
+
# payload (the whole -c script) is the argv token that contains
|
|
102
|
+
# whitespace — elide it so the full script is never re-embedded in the
|
|
103
|
+
# message (the defect this report exists to fix).
|
|
104
|
+
def wrapper_preview(result)
|
|
105
|
+
argv = Array(result.argv)
|
|
106
|
+
tokens = argv.dup
|
|
107
|
+
tokens[-1] = "'...'" if tokens.size > 1 && tokens[-1].to_s.match?(/\s/)
|
|
108
|
+
preview = segment_display(tokens)
|
|
109
|
+
preview.length > WRAPPER_PREVIEW_CAP ? "#{preview[0, WRAPPER_PREVIEW_CAP - 1]}..." : preview
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# Shortest top-level argv prefix that actually satisfies the gate's
|
|
113
|
+
# token-prefix match (command_allowlisted?): the wrapper binary up to
|
|
114
|
+
# and including its delegation flag for flag-value payloads
|
|
115
|
+
# ("bash -c", "bash -e -c"), the bare binary for rest-argv wrappers
|
|
116
|
+
# ("sudo", "xargs"). Deriving it from delegation_source keeps the hint
|
|
117
|
+
# gate-honest for flag permutations a naive first-two-tokens guess
|
|
118
|
+
# would miss.
|
|
119
|
+
def wrapper_allowlist_entry(wrapper)
|
|
120
|
+
argv = Array(wrapper.argv)
|
|
121
|
+
return argv.first.to_s if argv.size <= 1
|
|
122
|
+
|
|
123
|
+
first_inner = Array(wrapper.inner_commands).first
|
|
124
|
+
if first_inner&.delegation_mode.to_s == "flag_value_is_expression"
|
|
125
|
+
idx = argv.index(first_inner.delegation_source)
|
|
126
|
+
return argv[0..idx].join(" ") if idx&.positive?
|
|
127
|
+
end
|
|
128
|
+
argv.first.to_s
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# An allowlist entry can only carry whitespace-free tokens:
|
|
132
|
+
# normalize_allowlist splits entries on whitespace, so an argv token
|
|
133
|
+
# containing spaces ("feature x") can never be matched by an entry.
|
|
134
|
+
# Prefix up to (excluding) the first such token.
|
|
135
|
+
def allowlist_entry_for_argv(argv)
|
|
136
|
+
prefix = []
|
|
137
|
+
Array(argv).each do |token|
|
|
138
|
+
break if token.to_s.match?(/\s/)
|
|
139
|
+
|
|
140
|
+
prefix << token
|
|
141
|
+
end
|
|
142
|
+
prefix.empty? ? Array(argv).first.to_s : prefix.join(" ")
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# Display-only rendering: collapse newlines, single-quote tokens that
|
|
146
|
+
# contain whitespace, hard-cap length. Shellwords.escape would
|
|
147
|
+
# backslash-quote every token (noise on Windows paths) — quote
|
|
148
|
+
# conditionally instead.
|
|
149
|
+
def segment_display(argv)
|
|
150
|
+
text = argv.map { |t| t.to_s.tr("\r\n", " ") }
|
|
151
|
+
.map { |t| t.match?(/\s/) ? "'#{t}'" : t }
|
|
152
|
+
.join(" ")
|
|
153
|
+
text.length > SEGMENT_DISPLAY_CAP ? "#{text[0, SEGMENT_DISPLAY_CAP - 1]}..." : text
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
module_function :build, :collect_dangerous_units, :dangerous_segment_data, :display_tokens,
|
|
157
|
+
:safe_segment_name, :wrapper_preview, :wrapper_allowlist_entry,
|
|
158
|
+
:allowlist_entry_for_argv, :segment_display
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
end
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
require "json"
|
|
4
4
|
require "fileutils"
|
|
5
5
|
require "time"
|
|
6
|
+
require_relative "../log"
|
|
6
7
|
require_relative "../platform"
|
|
7
8
|
require_relative "../security/redactor"
|
|
8
9
|
|
|
@@ -20,7 +21,7 @@ module Rubik
|
|
|
20
21
|
begin
|
|
21
22
|
FileUtils.mkdir_p(@sessions_dir)
|
|
22
23
|
rescue SystemCallError => e
|
|
23
|
-
warn "[WARN] Failed to create sessions directory #{@sessions_dir}: #{e.message}" if ENV["RUBIK_DEBUG"]
|
|
24
|
+
Rubik::Log.warn(:session, "[WARN] Failed to create sessions directory #{@sessions_dir}: #{e.message}") if ENV["RUBIK_DEBUG"]
|
|
24
25
|
end
|
|
25
26
|
|
|
26
27
|
filename = session_name || "session_#{Time.now.strftime('%Y%m%d_%H%M%S')}_#{Process.pid}_#{(Time.now.to_f * 1000).to_i % 1000}.jsonl"
|
data/lib/rubik/skills/manager.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "monitor"
|
|
4
|
+
require_relative "../log"
|
|
4
5
|
require_relative "frontmatter"
|
|
5
6
|
require_relative "../storage/layout"
|
|
6
7
|
require_relative "storage"
|
|
@@ -118,7 +119,7 @@ module Rubik
|
|
|
118
119
|
result.issues.each { |issue| Rubik::Platform.debug_warn("skill #{issue.path}: #{issue.field} #{issue.message}") }
|
|
119
120
|
true
|
|
120
121
|
rescue StandardError => e
|
|
121
|
-
warn "[rubik] skills reload failed (previous snapshot kept): #{e.class}: #{e.message}"
|
|
122
|
+
Rubik::Log.warn(:skills, "[rubik] skills reload failed (previous snapshot kept): #{e.class}: #{e.message}")
|
|
122
123
|
false
|
|
123
124
|
end
|
|
124
125
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "json"
|
|
4
|
+
require_relative "../log"
|
|
4
5
|
require_relative "../security/redactor"
|
|
5
6
|
require_relative "../tools/truncator"
|
|
6
7
|
require_relative "../uris"
|
|
@@ -57,7 +58,7 @@ module Rubik
|
|
|
57
58
|
)
|
|
58
59
|
rescue StandardError => e
|
|
59
60
|
label = inst.respond_to?(:id) ? inst.id : inst.class
|
|
60
|
-
warn "[Storage] transcript index failed for #{label}: #{e.class}: #{e.message}"
|
|
61
|
+
Rubik::Log.warn(:storage, "[Storage] transcript index failed for #{label}: #{e.class}: #{e.message}")
|
|
61
62
|
end
|
|
62
63
|
|
|
63
64
|
# Task: transcript dosyasındaki İLK user satırı (seed'deki brif);
|
|
@@ -106,7 +107,7 @@ module Rubik
|
|
|
106
107
|
end
|
|
107
108
|
nil
|
|
108
109
|
rescue StandardError => e
|
|
109
|
-
warn "[Storage] transcript task read failed for #{file}: #{e.class}: #{e.message}"
|
|
110
|
+
Rubik::Log.warn(:storage, "[Storage] transcript task read failed for #{file}: #{e.class}: #{e.message}")
|
|
110
111
|
nil
|
|
111
112
|
end
|
|
112
113
|
|
|
@@ -58,7 +58,7 @@ module Rubik
|
|
|
58
58
|
begin
|
|
59
59
|
Rubik::Log.warn(SUBSYSTEM, message)
|
|
60
60
|
rescue StandardError
|
|
61
|
-
warn(
|
|
61
|
+
Rubik::Log.warn(:vakanuvis, message.to_s)
|
|
62
62
|
end
|
|
63
63
|
end
|
|
64
64
|
|
|
@@ -84,6 +84,7 @@ module Rubik
|
|
|
84
84
|
end
|
|
85
85
|
end
|
|
86
86
|
|
|
87
|
+
require_relative "../log"
|
|
87
88
|
require_relative "vakanuvis/vocabulary"
|
|
88
89
|
require_relative "vakanuvis/annal_writer"
|
|
89
90
|
require_relative "vakanuvis/memory_steward"
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
require_relative "../base"
|
|
4
4
|
require_relative "../output"
|
|
5
5
|
require_relative "../../coeffects"
|
|
6
|
+
require_relative "../../orchestrator/goal_ledger"
|
|
6
7
|
|
|
7
8
|
module Rubik
|
|
8
9
|
module Tools
|
|
@@ -16,12 +17,19 @@ module Rubik
|
|
|
16
17
|
class UpdateGoalLedgerTool < BaseTool
|
|
17
18
|
REQUIRES = [Rubik::Coeffects::GOAL_LEDGER].freeze
|
|
18
19
|
|
|
20
|
+
# Model-yüzü öğretim (SSOT türetme): item-grammar sözlüğü yüklenme
|
|
21
|
+
# anında Ledger::PRODUCTION_SCHEMA'dan türetilir — elle yazılan
|
|
22
|
+
# enum/required kopyası YOKTUR; şema değişirse description da değişir.
|
|
23
|
+
# Tükenme feedback'i de aynı sabiti paylaşır (schema_vocabulary).
|
|
24
|
+
GRAMMAR = Rubik::Orchestrator::GoalLedger::Ledger.schema_vocabulary
|
|
25
|
+
|
|
19
26
|
DECLARATION = Declaration.new(
|
|
20
27
|
name: "update_goal_ledger", aliases: ["ledger"],
|
|
21
28
|
description: "Update the structured goal ledger of the RUNNING !goal loop with an RFC 6902 " \
|
|
22
29
|
"JSON patch ({\"rev\": N, \"ops\": [{\"op\": \"add\"|\"replace\"|\"remove\", \"path\": \"/tasks/0/status\", \"value\": ...}]}). " \
|
|
23
30
|
"Read current state via read_file(path: 'rubik://goal/ledger') (or 'rubik://goal/ledger.json') and issue " \
|
|
24
31
|
"the patch against the rev it reports. Items carry 0-based indices (/tasks/0); append via /tasks/-. " \
|
|
32
|
+
"Item grammar: #{GRAMMAR}. " \
|
|
25
33
|
"Tasks and environment notes may carry declarative verify specs: {\"type\": \"file_exists\", \"path\": ...}, " \
|
|
26
34
|
"{\"type\": \"file_contains\", \"path\": ..., \"pattern\": ...}, or {\"type\": \"marker\", \"path\": ..., \"marker\": ...}. " \
|
|
27
35
|
"Rejections carry per-op fix hints; after the retry budget the ledger stays unchanged. A task status of " \
|
|
@@ -73,8 +81,11 @@ module Rubik
|
|
|
73
81
|
row = %(<goal_ledger_applied rev="#{result.rev}" uri="#{result.uri}" />)
|
|
74
82
|
ToolOutput.ok(result.uri ? row : %(<goal_ledger_applied rev="#{result.rev}" storage="unavailable (memory-only)" />))
|
|
75
83
|
when :exhausted
|
|
84
|
+
# Durum-bağımsız gramer hatırlatması (GRAMMAR): tükenme anında
|
|
85
|
+
# öğretmen susmasın — ama cache'lenmiş ret reason'ları DEĞİL
|
|
86
|
+
# (bayat teşhis bilgi zehridir; iyileşme yolu re-read'tir).
|
|
76
87
|
ToolOutput.error("patch budget exhausted (consecutive rejections); the ledger is unchanged at rev " \
|
|
77
|
-
"#{result.rev}. Goal work may continue — read rubik://goal/ledger when you next " \
|
|
88
|
+
"#{result.rev}. #{GRAMMAR} Goal work may continue — read rubik://goal/ledger when you next " \
|
|
78
89
|
"update state, and issue a valid patch against that rev.")
|
|
79
90
|
else
|
|
80
91
|
lines = result.reasons.map do |reason|
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
require "json"
|
|
4
4
|
require "stringio"
|
|
5
5
|
require "timeout"
|
|
6
|
+
require_relative "../../log"
|
|
6
7
|
require_relative "../base"
|
|
7
8
|
require_relative "../output"
|
|
8
9
|
require_relative "../preflight_runner"
|
|
9
10
|
require_relative "../../runtime"
|
|
10
|
-
|
|
11
11
|
module Rubik
|
|
12
12
|
module Tools
|
|
13
13
|
class SynthesizeCommandTool < BaseTool
|
|
@@ -118,7 +118,7 @@ module Rubik
|
|
|
118
118
|
out_ctx = if ctx
|
|
119
119
|
ctx
|
|
120
120
|
elsif @shell.respond_to?(:command_context)
|
|
121
|
-
warn "[rubik] custom command invoked without a dispatch CommandContext" unless ENV["RUBIK_TEST"]
|
|
121
|
+
Rubik::Log.warn(:tools, "[rubik] custom command invoked without a dispatch CommandContext") unless ENV["RUBIK_TEST"]
|
|
122
122
|
@shell.command_context
|
|
123
123
|
else
|
|
124
124
|
@shell.output
|
|
@@ -142,7 +142,7 @@ module Rubik
|
|
|
142
142
|
end
|
|
143
143
|
end
|
|
144
144
|
else
|
|
145
|
-
warn "[Synthesize] no runtime context; dispose inverse not registered for '!#{clean_name}'"
|
|
145
|
+
Rubik::Log.warn(:tools, "[Synthesize] no runtime context; dispose inverse not registered for '!#{clean_name}'")
|
|
146
146
|
end
|
|
147
147
|
end
|
|
148
148
|
|
|
@@ -5,6 +5,7 @@ require "rbconfig"
|
|
|
5
5
|
require "stringio"
|
|
6
6
|
require "timeout"
|
|
7
7
|
|
|
8
|
+
require_relative "../log"
|
|
8
9
|
require_relative "../security/errors"
|
|
9
10
|
require_relative "../runtime/synthesized_tool_context"
|
|
10
11
|
|
|
@@ -234,7 +235,7 @@ module Rubik
|
|
|
234
235
|
# The spawn→in-process downgrade is a weaker isolation level (the
|
|
235
236
|
# caller re-executes the same code in this process), so the
|
|
236
237
|
# infrastructure failure must never vanish without a trace.
|
|
237
|
-
warn "[Preflight] subprocess verification failed (#{e.class}: #{e.message}); falling back to in-process"
|
|
238
|
+
Rubik::Log.warn(:tools, "[Preflight] subprocess verification failed (#{e.class}: #{e.message}); falling back to in-process")
|
|
238
239
|
kill_child(pid) if defined?(pid) && pid
|
|
239
240
|
:spawn_failed
|
|
240
241
|
ensure
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "monitor"
|
|
4
|
+
require_relative "../log"
|
|
4
5
|
require_relative "../uris"
|
|
5
6
|
require_relative "../coeffects"
|
|
6
7
|
require_relative "../orchestrator/subagent/transcript_formatter"
|
|
@@ -77,8 +78,8 @@ module Rubik
|
|
|
77
78
|
# Sözleşme ihlali (adapter read ASLA nil döndürmez) — gramer
|
|
78
79
|
# reddinden AYRT edilir: nil'i dosya düzlemine düşürmek yanlış
|
|
79
80
|
# yönlendiren bir dosya-not-found üretirdi; dürüst hata basılır.
|
|
80
|
-
warn "[UriResolver] '#{scheme}' adapter violated the read contract (returned nil); " \
|
|
81
|
-
|
|
81
|
+
Rubik::Log.warn(:tools, "[UriResolver] '#{scheme}' adapter violated the read contract (returned nil); " \
|
|
82
|
+
"refusing to fall through to the file plane")
|
|
82
83
|
ToolOutput.error("rubik://#{scheme} read failed: the '#{scheme}' adapter returned no content " \
|
|
83
84
|
"(contract violation — see runtime log).")
|
|
84
85
|
end
|
data/lib/rubik/ui/capability.rb
CHANGED
data/lib/rubik/version.rb
CHANGED
data/lib/rubik.rb
CHANGED
|
@@ -57,9 +57,9 @@ module Rubik
|
|
|
57
57
|
return if defined?(@ambient_warned) && @ambient_warned
|
|
58
58
|
|
|
59
59
|
@ambient_warned = true
|
|
60
|
-
warn "[DEPRECATION] Rubik.runtime is deprecated (sunset). Inject the " \
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
Rubik::Log.warn(:core, "[DEPRECATION] Rubik.runtime is deprecated (sunset). Inject the " \
|
|
61
|
+
"'shell' coeffect (Rubik::Coeffects::SHELL) or read the manager " \
|
|
62
|
+
"from the owning Shell instead.")
|
|
63
63
|
end
|
|
64
64
|
end
|
|
65
65
|
end
|