rubik 0.7.1 → 0.8.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.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +141 -1
  3. data/lib/rubik/ast/typescript_extractor.rb +2 -2
  4. data/lib/rubik/config/deep_ops.rb +14 -0
  5. data/lib/rubik/config/defaults.rb +5 -4
  6. data/lib/rubik/config/env_loader.rb +88 -0
  7. data/lib/rubik/config/model_catalog.rb +13 -0
  8. data/lib/rubik/config/pruner.rb +34 -0
  9. data/lib/rubik/config/schema.rb +163 -0
  10. data/lib/rubik/config/scoped.rb +108 -0
  11. data/lib/rubik/config/store.rb +19 -8
  12. data/lib/rubik/config.rb +129 -53
  13. data/lib/rubik/diagnostics/parser.rb +2 -2
  14. data/lib/rubik/orchestrator/step_executor.rb +12 -59
  15. data/lib/rubik/orchestrator/subagent/scoped_registry.rb +14 -23
  16. data/lib/rubik/orchestrator/subagent/spawn_transaction.rb +12 -2
  17. data/lib/rubik/orchestrator/subagent/tool_dispatch.rb +12 -49
  18. data/lib/rubik/orchestrator/turn_executor.rb +9 -4
  19. data/lib/rubik/repl/commands/workspace.rb +14 -8
  20. data/lib/rubik/repl/lifecycle.rb +11 -0
  21. data/lib/rubik/repl/service_catalog.rb +2 -1
  22. data/lib/rubik/sandbox/runner.rb +28 -13
  23. data/lib/rubik/storage/render.rb +1 -1
  24. data/lib/rubik/storage/vakanuvis/distill_gate.rb +3 -3
  25. data/lib/rubik/storage/vakanuvis/harness.rb +4 -65
  26. data/lib/rubik/storage/vakanuvis/orientation.rb +1 -2
  27. data/lib/rubik/storage/vakanuvis/recall.rb +84 -0
  28. data/lib/rubik/storage/vakanuvis.rb +1 -0
  29. data/lib/rubik/tools/base.rb +34 -0
  30. data/lib/rubik/tools/builtins/define_subagent.rb +6 -0
  31. data/lib/rubik/tools/builtins/dmesg.rb +4 -4
  32. data/lib/rubik/tools/builtins/files.rb +18 -24
  33. data/lib/rubik/tools/builtins/goal_ledger.rb +1 -1
  34. data/lib/rubik/tools/builtins/grep.rb +6 -6
  35. data/lib/rubik/tools/builtins/interactive.rb +6 -0
  36. data/lib/rubik/tools/builtins/lifecycle.rb +2 -1
  37. data/lib/rubik/tools/builtins/pruner.rb +1 -1
  38. data/lib/rubik/tools/builtins/send_message.rb +6 -0
  39. data/lib/rubik/tools/builtins/subagent.rb +12 -0
  40. data/lib/rubik/tools/builtins/vakanuvis.rb +1 -1
  41. data/lib/rubik/tools/catalog.rb +19 -0
  42. data/lib/rubik/tools/declaration.rb +15 -2
  43. data/lib/rubik/tools/result_normalizer.rb +115 -0
  44. data/lib/rubik/tools/truncator.rb +3 -3
  45. data/lib/rubik/version.rb +1 -1
  46. metadata +7 -1
@@ -83,6 +83,12 @@ module Rubik
83
83
  @runtime_context = runtime_context
84
84
  end
85
85
 
86
+ # Subagent-plane rebind (ScopedRegistry delegate): a nested spawn must
87
+ # resolve the INSTANCE's task token (issue #125), not the root turn's.
88
+ def rebind_to(ctx)
89
+ self.class.new(supervisor: resolve_supervisor(nil, ctx), runtime_context: ctx)
90
+ end
91
+
86
92
  def execute(args = {})
87
93
  sup = resolve_supervisor(@supervisor, @runtime_context)
88
94
  return ToolOutput.error("SubagentSupervisor is not available in runtime context.") unless sup
@@ -203,6 +209,12 @@ module Rubik
203
209
  @runtime_context = runtime_context
204
210
  end
205
211
 
212
+ # Subagent-plane rebind (ScopedRegistry delegate): manage actions target
213
+ # the INSTANCE's supervisor, not the root turn's (issue #125).
214
+ def rebind_to(ctx)
215
+ self.class.new(supervisor: resolve_supervisor(nil, ctx), runtime_context: ctx)
216
+ end
217
+
206
218
  def execute(args = {})
207
219
  sup = resolve_supervisor(@supervisor, @runtime_context)
208
220
  return ToolOutput.error("SubagentSupervisor is not available in runtime context.") unless sup
@@ -30,7 +30,7 @@ module Rubik
30
30
  "returns a deterministic receipt, never blocks on the LLM), 'topics' (list recorded memory topics " \
31
31
  "— orient before the first query), 'digest_status' (is my queued digest pending, in flight, or done?). " \
32
32
  "Notes (annal.*) are the chronicler's evidence layer; memory cards are the durable conclusions you want recalled by default.",
33
- risk: :write, archetypes: [], write_grant: false,
33
+ risk: :write, archetypes: [], write_grant: false, root_only: true,
34
34
  maestro_blocked: false, # storage emsali: kronikçi düzlemi kökte doğrudan
35
35
  params_schema: {
36
36
  type: "object",
@@ -43,6 +43,15 @@ module Rubik
43
43
  SPAWN_TOOLS = DECLARATIONS.select(&:spawn?).map(&:name).sort.freeze
44
44
  WRITE_GRANT_TOOLS = DECLARATIONS.select(&:write_grant?).map(&:name).sort.freeze
45
45
  MAESTRO_BLOCKED_TOOLS = DECLARATIONS.select(&:maestro_blocked?).map(&:name).sort.freeze
46
+ # Orchestrator-plane-only membership, declared per tool (root_only:)
47
+ # and projected here — never restated as a remote hand-list. The set
48
+ # is NOT derivable from archetypes/risk: archetype-less writers also
49
+ # include the synthesis family, which subagent registries legitimately
50
+ # carry; only orchestration-memory writers (goal ledger, session
51
+ # chronicle, pruner queue) are root-locked.
52
+ ORCHESTRATOR_ONLY_TOOLS = DECLARATIONS.select(&:root_only?).map(&:name).sort.freeze
53
+ BUFFER_BOUND_TOOLS = DECLARATIONS.select(&:buffer_bound?).map(&:name).sort.freeze
54
+ TERMINAL_TOOLS = DECLARATIONS.select(&:terminal?).map(&:name).sort.freeze
46
55
 
47
56
  module_function
48
57
 
@@ -65,6 +74,16 @@ module Rubik
65
74
  def maestro_blocked_tools = MAESTRO_BLOCKED_TOOLS
66
75
 
67
76
  def maestro_blocked?(name) = MAESTRO_BLOCKED_TOOLS.include?(name.to_s)
77
+
78
+ def orchestrator_only_tools = ORCHESTRATOR_ONLY_TOOLS
79
+
80
+ def buffer_bound_tools = BUFFER_BOUND_TOOLS
81
+
82
+ def buffer_bound?(name) = BUFFER_BOUND_TOOLS.include?(name.to_s)
83
+
84
+ def terminal_tools = TERMINAL_TOOLS
85
+
86
+ def terminal?(name) = TERMINAL_TOOLS.include?(name.to_s)
68
87
  end
69
88
  end
70
89
  end
@@ -19,11 +19,15 @@ module Rubik
19
19
  :subagent_spawn, # bool — member of the spawn set (self-archetype recursion guard)
20
20
  :write_grant, # bool — denied to custom types lacking enable_write_tools
21
21
  :maestro_blocked, # true | false | nil — gate class; MUST be explicit for :write/:execute
22
+ :buffer_bound, # bool — instance reads a branch buffer; rebuilt when a plane split rebinds it
23
+ :root_only, # bool — orchestration-memory writer; never copied into a subagent registry
24
+ :terminal, # bool — turn completion signal; dispatchers route it before gates/malformed handling
22
25
  keyword_init: true
23
26
  ) do
24
27
  def initialize(name:, description:, risk: :read, params_schema: {}, aliases: [],
25
28
  allow_additional_properties: true, archetypes: [], subagent_spawn: false,
26
- write_grant: false, maestro_blocked: nil)
29
+ write_grant: false, maestro_blocked: nil, buffer_bound: false, root_only: false,
30
+ terminal: false)
27
31
  clean_name = name.to_s
28
32
  # Leading digits are tolerated (not required) for legacy dynamic
29
33
  # tools: synthesis/overlay normalize to lowercase snake but do not
@@ -69,7 +73,10 @@ module Rubik
69
73
  nil
70
74
  else
71
75
  (maestro_blocked ? true : false)
72
- end
76
+ end,
77
+ buffer_bound: buffer_bound ? true : false,
78
+ root_only: root_only ? true : false,
79
+ terminal: terminal ? true : false
73
80
  )
74
81
  freeze
75
82
  end
@@ -85,6 +92,12 @@ module Rubik
85
92
  def spawn? = subagent_spawn == true
86
93
 
87
94
  def write_grant? = write_grant == true
95
+
96
+ def buffer_bound? = buffer_bound == true
97
+
98
+ def root_only? = root_only == true
99
+
100
+ def terminal? = terminal == true
88
101
  end
89
102
  end
90
103
  end
@@ -0,0 +1,115 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "truncator"
4
+ require_relative "result"
5
+
6
+ module Rubik
7
+ module Tools
8
+ # Single home for tool-output carrier normalization: every tool outcome —
9
+ # Result-backed, status-bearing duck object, or plain string — is
10
+ # normalized into the Result contract here, and both orchestrator planes
11
+ # (StepExecutor root, Subagent ToolDispatch) delegate to this one
12
+ # implementation instead of maintaining parallel copies.
13
+ #
14
+ # Plane differences are caller-supplied parameters, not divergent logic:
15
+ # the root plane passes its measured wall time and the tool-call id; the
16
+ # subagent plane leaves both nil.
17
+ module ResultNormalizer
18
+ # Carrier strings whose first-line presence marks an otherwise opaque
19
+ # string result as an error. Shared lexicon; referenced by tests via
20
+ # StepExecutor::ERROR_PREFIXES (kept as an alias there).
21
+ ERROR_PREFIXES = [
22
+ "-- ", "Error:", "Error ", "Usage:", "Pre-flight verification failed",
23
+ "Bilinmeyen komut", "Failed", "Security blocked", "Command error",
24
+ "[EXIT ", "Test run [FAILED]", "Lint [FAILED]", "[CONFLICT]", "[CONFLICT "
25
+ ].freeze
26
+
27
+ # Truncation knob trio (chars, lines, strategy) from a config object;
28
+ # nil / non-fetchable configs fall back to Truncator defaults. A
29
+ # non-nil config that cannot fetch warns once before falling back —
30
+ # operator-set limits must never be dropped in silence.
31
+ def self.limits(config)
32
+ cfg = config.respond_to?(:fetch) ? config : nil
33
+ warn_once(config.class) if cfg.nil? && !config.nil?
34
+ max_chars = cfg&.fetch("tools.max_output_chars", Truncator::DEFAULT_MAX_CHARS) || Truncator::DEFAULT_MAX_CHARS
35
+ max_lines = cfg&.fetch("tools.max_output_lines", Truncator::DEFAULT_MAX_LINES) || Truncator::DEFAULT_MAX_LINES
36
+ strategy = Truncator.resolve_strategy(cfg&.fetch("tools.truncation_strategy", Truncator::DEFAULT_STRATEGY))
37
+ [max_chars, max_lines, strategy]
38
+ end
39
+
40
+ # One warning per process per config class; a warn per tool result
41
+ # would be exactly the stderr storm the truncation warn doctrine bans.
42
+ def self.warn_once(klass)
43
+ @warned ||= {}
44
+ return if @warned[klass]
45
+
46
+ @warned[klass] = true
47
+ Rubik::Log.warn(:tools, "tools truncation knobs skipped: config object of class #{klass} does not respond to fetch; using Truncator defaults")
48
+ end
49
+
50
+ # duration_ms: caller-measured wall time (nil on the subagent plane).
51
+ # call_id: caller's tool-call id (nil on the subagent plane).
52
+ def self.normalize(raw, tool_name:, call_id: nil, duration_ms: nil, config: nil)
53
+ max_chars, max_lines, strategy = limits(config)
54
+
55
+ if raw.is_a?(Result)
56
+ trunc = Truncator.truncate(raw.output, max_chars: max_chars, max_lines: max_lines, strategy: strategy)
57
+ # Truncation only shortens the display text — status, exit code,
58
+ # metadata and the original truncation flag all survive it.
59
+ effective_dur = raw.duration_ms.positive? ? raw.duration_ms : duration_ms.to_f
60
+ first_line = first_line_of(raw.output)
61
+ Result.new(
62
+ tool_name: raw.tool_name.to_s.empty? ? tool_name : raw.tool_name,
63
+ call_id: raw.call_id.to_s.empty? ? call_id : raw.call_id,
64
+ status: raw.status, error: raw.error || (raw.error? ? first_line : nil),
65
+ # Structured fields ride along when the tool provides them
66
+ # (issue #127): the same Result contract for every carrier.
67
+ exit_code: raw.exit_code, output: trunc[:text], duration_ms: effective_dur,
68
+ truncated: raw.truncated || trunc[:truncated], metadata: raw.metadata
69
+ )
70
+ elsif raw.respond_to?(:status) && raw.respond_to?(:output)
71
+ out_str = raw.output.to_s
72
+ trunc = Truncator.truncate(out_str, max_chars: max_chars, max_lines: max_lines, strategy: strategy)
73
+ status = raw.status.to_sym
74
+ first_line = first_line_of(out_str)
75
+ err = (raw.respond_to?(:error) && raw.error) || (status == :error ? first_line : nil)
76
+ Result.new(
77
+ tool_name: tool_name, call_id: call_id, status: status, error: err, output: trunc[:text],
78
+ duration_ms: duration_ms.to_f, truncated: trunc[:truncated],
79
+ exit_code: raw.respond_to?(:exit_code) ? raw.exit_code : nil,
80
+ metadata: raw.respond_to?(:metadata) ? raw.metadata : {}
81
+ )
82
+ else
83
+ out_str = raw.to_s
84
+ trunc = Truncator.truncate(out_str, max_chars: max_chars, max_lines: max_lines, strategy: strategy)
85
+ # elsif chain (not two independent checks): a carrier answering
86
+ # error? takes that verdict even when failed? would disagree —
87
+ # root-plane precedence, pinned by the hardening tests.
88
+ is_err = if raw.respond_to?(:error?)
89
+ raw.error?
90
+ elsif raw.respond_to?(:failed?)
91
+ raw.failed?
92
+ elsif raw.is_a?(String)
93
+ ERROR_PREFIXES.any? { |pfx| out_str.start_with?(pfx) }
94
+ else
95
+ false
96
+ end
97
+
98
+ first_line = first_line_of(out_str)
99
+ Result.new(
100
+ tool_name: tool_name, call_id: call_id, status: is_err ? :error : :ok,
101
+ error: is_err ? first_line : nil, output: trunc[:text],
102
+ duration_ms: duration_ms.to_f, truncated: trunc[:truncated]
103
+ )
104
+ end
105
+ end
106
+
107
+ # A blank first line carries no diagnostic value: nil it so error
108
+ # fields never hold "" (pinned by the empty-output hardening test).
109
+ def self.first_line_of(text)
110
+ line = text.lines.first.to_s.strip
111
+ line.empty? ? nil : line
112
+ end
113
+ end
114
+ end
115
+ end
@@ -5,9 +5,9 @@ module Rubik
5
5
  module Truncator
6
6
  DEFAULT_MAX_CHARS = 12_000
7
7
  DEFAULT_MAX_LINES = 300
8
- # The strategy knob's default lives here (arch scan card 5, 2026-11-01):
9
- # both orchestrator planes read tools.truncation_strategy with this
10
- # fallback — one literal for the whole repo instead of restated copies.
8
+ # The strategy knob's default lives here: both orchestrator planes read
9
+ # tools.truncation_strategy with this fallback — one literal for the
10
+ # whole repo instead of restated copies.
11
11
  DEFAULT_STRATEGY = :head_tail
12
12
  # Known-strategy set (issue #349): a typo'd config value used to die
13
13
  # silently into the head_tail `else` branch in both planes. This set
data/lib/rubik/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rubik
4
- VERSION = "0.7.1"
4
+ VERSION = "0.8.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubik
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Özgür Ulukır
@@ -289,7 +289,11 @@ files:
289
289
  - lib/rubik/config.rb
290
290
  - lib/rubik/config/deep_ops.rb
291
291
  - lib/rubik/config/defaults.rb
292
+ - lib/rubik/config/env_loader.rb
292
293
  - lib/rubik/config/model_catalog.rb
294
+ - lib/rubik/config/pruner.rb
295
+ - lib/rubik/config/schema.rb
296
+ - lib/rubik/config/scoped.rb
293
297
  - lib/rubik/config/store.rb
294
298
  - lib/rubik/context.rb
295
299
  - lib/rubik/context/git_info.rb
@@ -726,6 +730,7 @@ files:
726
730
  - lib/rubik/storage/vakanuvis/job.rb
727
731
  - lib/rubik/storage/vakanuvis/memory_steward.rb
728
732
  - lib/rubik/storage/vakanuvis/orientation.rb
733
+ - lib/rubik/storage/vakanuvis/recall.rb
729
734
  - lib/rubik/storage/vakanuvis/service.rb
730
735
  - lib/rubik/storage/vakanuvis/vocabulary.rb
731
736
  - lib/rubik/storage/vakanuvis/wiki_skeleton.rb
@@ -764,6 +769,7 @@ files:
764
769
  - lib/rubik/tools/preflight_runner.rb
765
770
  - lib/rubik/tools/registry.rb
766
771
  - lib/rubik/tools/result.rb
772
+ - lib/rubik/tools/result_normalizer.rb
767
773
  - lib/rubik/tools/services.rb
768
774
  - lib/rubik/tools/symbol_tool_support.rb
769
775
  - lib/rubik/tools/truncator.rb