rubik 0.7.0 → 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 (57) hide show
  1. checksums.yaml +4 -4
  2. data/ATTRIBUTION.md +1 -1
  3. data/CHANGELOG.md +177 -1
  4. data/lib/rubik/ast/typescript_extractor.rb +2 -2
  5. data/lib/rubik/config/deep_ops.rb +14 -0
  6. data/lib/rubik/config/defaults.rb +6 -4
  7. data/lib/rubik/config/env_loader.rb +88 -0
  8. data/lib/rubik/config/model_catalog.rb +13 -0
  9. data/lib/rubik/config/pruner.rb +34 -0
  10. data/lib/rubik/config/schema.rb +163 -0
  11. data/lib/rubik/config/scoped.rb +108 -0
  12. data/lib/rubik/config/store.rb +19 -8
  13. data/lib/rubik/config.rb +129 -53
  14. data/lib/rubik/diagnostics/collector.rb +8 -2
  15. data/lib/rubik/diagnostics/parser.rb +2 -2
  16. data/lib/rubik/lsp/client.rb +26 -6
  17. data/lib/rubik/lsp/manager.rb +24 -6
  18. data/lib/rubik/orchestrator/lsp_feedback.rb +2 -1
  19. data/lib/rubik/orchestrator/step_executor.rb +12 -59
  20. data/lib/rubik/orchestrator/subagent/scoped_registry.rb +14 -23
  21. data/lib/rubik/orchestrator/subagent/spawn_transaction.rb +12 -2
  22. data/lib/rubik/orchestrator/subagent/tool_dispatch.rb +12 -49
  23. data/lib/rubik/orchestrator/turn_executor.rb +9 -4
  24. data/lib/rubik/repl/commands/lsp.rb +13 -1
  25. data/lib/rubik/repl/commands/workspace.rb +14 -8
  26. data/lib/rubik/repl/lifecycle.rb +11 -0
  27. data/lib/rubik/repl/service_catalog.rb +2 -1
  28. data/lib/rubik/repl/shell.rb +1 -0
  29. data/lib/rubik/runtime/context.rb +12 -14
  30. data/lib/rubik/runtime/discovery.rb +1 -0
  31. data/lib/rubik/sandbox/runner.rb +28 -13
  32. data/lib/rubik/storage/render.rb +1 -1
  33. data/lib/rubik/storage/vakanuvis/distill_gate.rb +3 -3
  34. data/lib/rubik/storage/vakanuvis/harness.rb +4 -65
  35. data/lib/rubik/storage/vakanuvis/orientation.rb +1 -2
  36. data/lib/rubik/storage/vakanuvis/recall.rb +84 -0
  37. data/lib/rubik/storage/vakanuvis.rb +1 -0
  38. data/lib/rubik/tools/base.rb +34 -0
  39. data/lib/rubik/tools/builtins/define_subagent.rb +6 -0
  40. data/lib/rubik/tools/builtins/dmesg.rb +4 -4
  41. data/lib/rubik/tools/builtins/files.rb +18 -24
  42. data/lib/rubik/tools/builtins/goal_ledger.rb +1 -1
  43. data/lib/rubik/tools/builtins/grep.rb +6 -6
  44. data/lib/rubik/tools/builtins/interactive.rb +6 -0
  45. data/lib/rubik/tools/builtins/lifecycle.rb +2 -1
  46. data/lib/rubik/tools/builtins/lsp.rb +127 -110
  47. data/lib/rubik/tools/builtins/pruner.rb +1 -1
  48. data/lib/rubik/tools/builtins/send_message.rb +6 -0
  49. data/lib/rubik/tools/builtins/subagent.rb +12 -0
  50. data/lib/rubik/tools/builtins/vakanuvis.rb +1 -1
  51. data/lib/rubik/tools/catalog.rb +20 -1
  52. data/lib/rubik/tools/declaration.rb +15 -2
  53. data/lib/rubik/tools/registry.rb +6 -5
  54. data/lib/rubik/tools/result_normalizer.rb +115 -0
  55. data/lib/rubik/tools/truncator.rb +3 -3
  56. data/lib/rubik/version.rb +1 -1
  57. metadata +7 -1
@@ -3,12 +3,57 @@
3
3
  require_relative "../base"
4
4
  require_relative "../../coeffects"
5
5
  require_relative "../output"
6
+ require_relative "../../platform"
6
7
 
7
8
  module Rubik
8
9
  module Tools
9
- class LSPDiagnosticsTool < BaseTool
10
- attr_reader :lsp_manager, :buffer_manager
10
+ class BaseLSPTool < BaseTool
11
+ REQUIRES = [Rubik::Coeffects::LSP_MANAGER].freeze
11
12
 
13
+ attr_reader :lsp_manager, :buffer_manager, :runtime_context
14
+
15
+ def initialize(declaration, lsp_manager = nil, buffer_mgr = nil, buffer_manager: nil, runtime_context: nil, context: nil)
16
+ super(declaration)
17
+ @lsp_manager = lsp_manager
18
+ @buffer_manager = buffer_manager || buffer_mgr
19
+ @runtime_context = runtime_context || context
20
+ end
21
+
22
+ def effective_lsp_manager
23
+ Rubik::Coeffects.resolve(@runtime_context, Rubik::Coeffects::LSP_MANAGER, @lsp_manager)
24
+ end
25
+
26
+ def effective_buffer_manager
27
+ @buffer_manager || Rubik::Coeffects.resolve(@runtime_context, Rubik::Coeffects::BUFFER_MANAGER, nil)
28
+ end
29
+
30
+ private
31
+
32
+ def buffer_dirty?(path)
33
+ bm = effective_buffer_manager
34
+ return false unless bm && !path.to_s.empty?
35
+
36
+ if bm.respond_to?(:dirty?)
37
+ begin
38
+ bm.method(:dirty?).arity.zero? ? bm.dirty? : bm.dirty?(path)
39
+ rescue ArgumentError
40
+ bm.dirty?
41
+ end
42
+ else
43
+ false
44
+ end
45
+ end
46
+
47
+ def append_buffer_tip(msg, path)
48
+ return msg unless buffer_dirty?(path)
49
+
50
+ tip = "\n\n💡 Tip: '#{path}' has unapplied in-memory buffer modifications. " \
51
+ "Call 'apply_buffer' to persist changes to disk for language servers requiring disk-based indexing."
52
+ "#{msg}#{tip}"
53
+ end
54
+ end
55
+
56
+ class LSPDiagnosticsTool < BaseLSPTool
12
57
  DECLARATION = Declaration.new(
13
58
  name: "lsp_diagnostics", aliases: ["get_diagnostics", "diagnostics"],
14
59
  description: "Get real-time compiler and linter diagnostics (errors, warnings) for a file or all active project files via LSP",
@@ -20,26 +65,22 @@ module Rubik
20
65
  }
21
66
  }
22
67
  )
23
- def initialize(lsp_manager = nil, buffer_mgr = nil, buffer_manager: nil)
24
- super(DECLARATION)
25
- @lsp_manager = lsp_manager
26
- @buffer_manager = buffer_manager || buffer_mgr
27
- end
28
68
 
29
- def effective_buffer_manager
30
- @buffer_manager || @lsp_manager&.context&.get(Rubik::Coeffects::BUFFER_MANAGER)
69
+ def initialize(lsp_manager = nil, buffer_mgr = nil, buffer_manager: nil, runtime_context: nil, context: nil)
70
+ super(DECLARATION, lsp_manager, buffer_mgr, buffer_manager: buffer_manager, runtime_context: runtime_context, context: context)
31
71
  end
32
72
 
33
73
  def execute(args = {})
34
- return ToolOutput.error("LSP manager is not connected.") unless @lsp_manager
35
- return ToolOutput.error("LSP is currently disabled in configuration (enable via '!lsp on').") unless @lsp_manager.enabled?
74
+ mgr = effective_lsp_manager
75
+ return ToolOutput.error("LSP manager is not connected.") unless mgr
76
+ return ToolOutput.error("LSP is currently disabled in configuration (enable via '!lsp on').") unless mgr.enabled?
36
77
 
37
78
  path = (args["file_path"] || args[:file_path] || "").to_s.strip
38
79
  bm = effective_buffer_manager
39
- @lsp_manager.sync_buffer_file_if_needed(path, bm) if bm && @lsp_manager.respond_to?(:sync_buffer_file_if_needed)
80
+ mgr.sync_buffer_file_if_needed(path, bm) if bm && mgr.respond_to?(:sync_buffer_file_if_needed)
40
81
 
41
82
  if path.empty?
42
- all = @lsp_manager.all_diagnostic_snapshots
83
+ all = mgr.all_diagnostic_snapshots
43
84
  total_issues = all.values.sum { |snapshot| snapshot[:diagnostics].size }
44
85
  pending = all.values.count { |snapshot| snapshot[:state] == :pending }
45
86
  unversioned = all.values.count { |snapshot| snapshot[:state] == :unversioned }
@@ -74,7 +115,11 @@ module Rubik
74
115
  lines.join("\n")
75
116
  end
76
117
  else
77
- snapshot = @lsp_manager.diagnostics_snapshot_for(path)
118
+ snapshot = if mgr.respond_to?(:wait_for_diagnostics)
119
+ mgr.wait_for_diagnostics(path, timeout: 0.5)
120
+ else
121
+ mgr.diagnostics_snapshot_for(path)
122
+ end
78
123
  diags = snapshot[:diagnostics]
79
124
  if diags.empty?
80
125
  message = case snapshot[:state]
@@ -107,36 +152,9 @@ module Rubik
107
152
  end
108
153
  end
109
154
  end
110
-
111
- private
112
-
113
- def buffer_dirty?(path)
114
- bm = effective_buffer_manager
115
- return false unless bm && !path.to_s.empty?
116
-
117
- if bm.respond_to?(:dirty?)
118
- begin
119
- bm.method(:dirty?).arity.zero? ? bm.dirty? : bm.dirty?(path)
120
- rescue ArgumentError
121
- bm.dirty?
122
- end
123
- else
124
- false
125
- end
126
- end
127
-
128
- def append_buffer_tip(msg, path)
129
- return msg unless buffer_dirty?(path)
130
-
131
- tip = "\n\n💡 Tip: '#{path}' has unapplied in-memory buffer modifications. " \
132
- "Call 'apply_buffer' to persist changes to disk for language servers requiring disk-based indexing."
133
- "#{msg}#{tip}"
134
- end
135
155
  end
136
156
 
137
- class LSPHoverTool < BaseTool
138
- attr_reader :lsp_manager, :buffer_manager
139
-
157
+ class LSPHoverTool < BaseLSPTool
140
158
  DECLARATION = Declaration.new(
141
159
  name: "lsp_hover", aliases: ["get_hover", "hover"],
142
160
  description: "Get compiler-level type signature, docstring, and symbol details at a specific line and character position via LSP",
@@ -151,19 +169,15 @@ module Rubik
151
169
  required: ["file_path", "line", "character"]
152
170
  }
153
171
  )
154
- def initialize(lsp_manager = nil, buffer_mgr = nil, buffer_manager: nil)
155
- super(DECLARATION)
156
- @lsp_manager = lsp_manager
157
- @buffer_manager = buffer_manager || buffer_mgr
158
- end
159
172
 
160
- def effective_buffer_manager
161
- @buffer_manager || @lsp_manager&.context&.get(Rubik::Coeffects::BUFFER_MANAGER)
173
+ def initialize(lsp_manager = nil, buffer_mgr = nil, buffer_manager: nil, runtime_context: nil, context: nil)
174
+ super(DECLARATION, lsp_manager, buffer_mgr, buffer_manager: buffer_manager, runtime_context: runtime_context, context: context)
162
175
  end
163
176
 
164
177
  def execute(args = {})
165
- return ToolOutput.error("LSP manager is not connected.") unless @lsp_manager
166
- return ToolOutput.error("LSP is currently disabled in configuration (enable via '!lsp on').") unless @lsp_manager.enabled?
178
+ mgr = effective_lsp_manager
179
+ return ToolOutput.error("LSP manager is not connected.") unless mgr
180
+ return ToolOutput.error("LSP is currently disabled in configuration (enable via '!lsp on').") unless mgr.enabled?
167
181
 
168
182
  path = (args["file_path"] || args[:file_path]).to_s.strip
169
183
  line = (args["line"] || args[:line]).to_i
@@ -173,9 +187,9 @@ module Rubik
173
187
  return ToolOutput.error("Line number must be >= 1.") if line < 1
174
188
 
175
189
  bm = effective_buffer_manager
176
- @lsp_manager.sync_buffer_file_if_needed(path, bm) if bm && @lsp_manager.respond_to?(:sync_buffer_file_if_needed)
190
+ mgr.sync_buffer_file_if_needed(path, bm) if bm && mgr.respond_to?(:sync_buffer_file_if_needed)
177
191
 
178
- res = @lsp_manager.hover(path, [line - 1, 0].max, [char - 1, 0].max)
192
+ res = mgr.hover(path, [line - 1, 0].max, [char - 1, 0].max)
179
193
  if res[:ok]
180
194
  contents = res.dig(:result, "contents")
181
195
  if contents.nil? || contents.empty?
@@ -191,36 +205,9 @@ module Rubik
191
205
  ToolOutput.error("LSP Hover failed: #{res[:error]}")
192
206
  end
193
207
  end
194
-
195
- private
196
-
197
- def buffer_dirty?(path)
198
- bm = effective_buffer_manager
199
- return false unless bm && !path.to_s.empty?
200
-
201
- if bm.respond_to?(:dirty?)
202
- begin
203
- bm.method(:dirty?).arity.zero? ? bm.dirty? : bm.dirty?(path)
204
- rescue ArgumentError
205
- bm.dirty?
206
- end
207
- else
208
- false
209
- end
210
- end
211
-
212
- def append_buffer_tip(msg, path)
213
- return msg unless buffer_dirty?(path)
214
-
215
- tip = "\n\n💡 Tip: '#{path}' has unapplied in-memory buffer modifications. " \
216
- "Call 'apply_buffer' to persist changes to disk for language servers requiring disk-based indexing."
217
- "#{msg}#{tip}"
218
- end
219
208
  end
220
209
 
221
- class LSPDefinitionTool < BaseTool
222
- attr_reader :lsp_manager, :buffer_manager
223
-
210
+ class LSPDefinitionTool < BaseLSPTool
224
211
  DECLARATION = Declaration.new(
225
212
  name: "lsp_definition", aliases: ["goto_definition", "definition"],
226
213
  description: "Jump to exact type-safe declaration and definition location of a symbol at line/character position via LSP",
@@ -235,19 +222,15 @@ module Rubik
235
222
  required: ["file_path", "line", "character"]
236
223
  }
237
224
  )
238
- def initialize(lsp_manager = nil, buffer_mgr = nil, buffer_manager: nil)
239
- super(DECLARATION)
240
- @lsp_manager = lsp_manager
241
- @buffer_manager = buffer_manager || buffer_mgr
242
- end
243
225
 
244
- def effective_buffer_manager
245
- @buffer_manager || @lsp_manager&.context&.get(Rubik::Coeffects::BUFFER_MANAGER)
226
+ def initialize(lsp_manager = nil, buffer_mgr = nil, buffer_manager: nil, runtime_context: nil, context: nil)
227
+ super(DECLARATION, lsp_manager, buffer_mgr, buffer_manager: buffer_manager, runtime_context: runtime_context, context: context)
246
228
  end
247
229
 
248
230
  def execute(args = {})
249
- return ToolOutput.error("LSP manager is not connected.") unless @lsp_manager
250
- return ToolOutput.error("LSP is currently disabled in configuration (enable via '!lsp on').") unless @lsp_manager.enabled?
231
+ mgr = effective_lsp_manager
232
+ return ToolOutput.error("LSP manager is not connected.") unless mgr
233
+ return ToolOutput.error("LSP is currently disabled in configuration (enable via '!lsp on').") unless mgr.enabled?
251
234
 
252
235
  path = (args["file_path"] || args[:file_path]).to_s.strip
253
236
  line = (args["line"] || args[:line]).to_i
@@ -257,9 +240,9 @@ module Rubik
257
240
  return ToolOutput.error("Line number must be >= 1.") if line < 1
258
241
 
259
242
  bm = effective_buffer_manager
260
- @lsp_manager.sync_buffer_file_if_needed(path, bm) if bm && @lsp_manager.respond_to?(:sync_buffer_file_if_needed)
243
+ mgr.sync_buffer_file_if_needed(path, bm) if bm && mgr.respond_to?(:sync_buffer_file_if_needed)
261
244
 
262
- res = @lsp_manager.definition(path, [line - 1, 0].max, [char - 1, 0].max)
245
+ res = mgr.definition(path, [line - 1, 0].max, [char - 1, 0].max)
263
246
  if res[:ok]
264
247
  result = res[:result]
265
248
  if result.nil? || (result.is_a?(Array) && result.empty?)
@@ -269,7 +252,7 @@ module Rubik
269
252
  lines = ["Found #{locs.size} definition location(s):"]
270
253
  locs.each do |loc|
271
254
  uri = loc["uri"] || loc["targetUri"]
272
- clean_file = uri.to_s.sub(%r{^file://}, "")
255
+ clean_file = Rubik::Platform.from_file_uri(uri)
273
256
  range = loc["range"] || loc["targetSelectionRange"] || {}
274
257
  s_line = (range.dig("start", "line") || 0) + 1
275
258
  s_char = (range.dig("start", "character") || 0) + 1
@@ -281,31 +264,65 @@ module Rubik
281
264
  ToolOutput.error("LSP Definition failed: #{res[:error]}")
282
265
  end
283
266
  end
267
+ end
284
268
 
285
- private
269
+ class LSPReferencesTool < BaseLSPTool
270
+ DECLARATION = Declaration.new(
271
+ name: "lsp_references", aliases: ["find_references_lsp", "lsp_refs"],
272
+ description: "Find all compiler-accurate usages, call sites, and references of a symbol across the project via LSP",
273
+ risk: :read, archetypes: [:research],
274
+ params_schema: {
275
+ type: "object",
276
+ properties: {
277
+ file_path: { type: "string", description: "Path to source file containing the symbol" },
278
+ line: { type: "integer", description: "1-based line number" },
279
+ character: { type: "integer", description: "1-based character position" }
280
+ },
281
+ required: ["file_path", "line", "character"]
282
+ }
283
+ )
284
+
285
+ def initialize(lsp_manager = nil, buffer_mgr = nil, buffer_manager: nil, runtime_context: nil, context: nil)
286
+ super(DECLARATION, lsp_manager, buffer_mgr, buffer_manager: buffer_manager, runtime_context: runtime_context, context: context)
287
+ end
288
+
289
+ def execute(args = {})
290
+ mgr = effective_lsp_manager
291
+ return ToolOutput.error("LSP manager is not connected.") unless mgr
292
+ return ToolOutput.error("LSP is currently disabled in configuration (enable via '!lsp on').") unless mgr.enabled?
293
+
294
+ path = (args["file_path"] || args[:file_path]).to_s.strip
295
+ line = (args["line"] || args[:line]).to_i
296
+ char = (args["character"] || args[:character] || args["col"] || args[:col]).to_i
297
+
298
+ return ToolOutput.error("File path is required.") if path.empty?
299
+ return ToolOutput.error("Line number must be >= 1.") if line < 1
286
300
 
287
- def buffer_dirty?(path)
288
301
  bm = effective_buffer_manager
289
- return false unless bm && !path.to_s.empty?
302
+ mgr.sync_buffer_file_if_needed(path, bm) if bm && mgr.respond_to?(:sync_buffer_file_if_needed)
290
303
 
291
- if bm.respond_to?(:dirty?)
292
- begin
293
- bm.method(:dirty?).arity.zero? ? bm.dirty? : bm.dirty?(path)
294
- rescue ArgumentError
295
- bm.dirty?
304
+ res = mgr.references(path, [line - 1, 0].max, [char - 1, 0].max)
305
+ if res[:ok]
306
+ result = res[:result]
307
+ if result.nil? || (result.is_a?(Array) && result.empty?)
308
+ append_buffer_tip("No references found for symbol at #{path}:#{line}:#{char}", path)
309
+ else
310
+ locs = result.is_a?(Array) ? result : [result]
311
+ lines = ["Found #{locs.size} reference location(s):"]
312
+ locs.each do |loc|
313
+ uri = loc["uri"] || loc["targetUri"]
314
+ clean_file = Rubik::Platform.from_file_uri(uri)
315
+ range = loc["range"] || loc["targetSelectionRange"] || {}
316
+ s_line = (range.dig("start", "line") || 0) + 1
317
+ s_char = (range.dig("start", "character") || 0) + 1
318
+ lines << " • #{clean_file}:#{s_line}:#{s_char}"
319
+ end
320
+ lines.join("\n")
296
321
  end
297
322
  else
298
- false
323
+ ToolOutput.error("LSP References failed: #{res[:error]}")
299
324
  end
300
325
  end
301
-
302
- def append_buffer_tip(msg, path)
303
- return msg unless buffer_dirty?(path)
304
-
305
- tip = "\n\n💡 Tip: '#{path}' has unapplied in-memory buffer modifications. " \
306
- "Call 'apply_buffer' to persist changes to disk for language servers requiring disk-based indexing."
307
- "#{msg}#{tip}"
308
- end
309
326
  end
310
327
  end
311
328
  end
@@ -27,7 +27,7 @@ module Rubik
27
27
  "preserved): 'prune' (queue a forced prune now; returns a deterministic receipt, " \
28
28
  "never blocks on the LLM), 'status' (window estimate vs ceiling, staged plan " \
29
29
  "state, last receipt).",
30
- risk: :write, archetypes: [], write_grant: false,
30
+ risk: :write, archetypes: [], write_grant: false, root_only: true,
31
31
  maestro_blocked: false, # vakanüvis emsali: budayıcı düzlemi kökte doğrudan
32
32
  params_schema: {
33
33
  type: "object",
@@ -35,6 +35,12 @@ module Rubik
35
35
  @runtime_context = runtime_context
36
36
  end
37
37
 
38
+ # Subagent-plane rebind (ScopedRegistry delegate): the subagent-plane
39
+ # message must carry its REAL sender id to the maestro.
40
+ def rebind_to(ctx)
41
+ self.class.new(supervisor: resolve_supervisor(nil, ctx), runtime_context: ctx)
42
+ end
43
+
38
44
  def execute(args = {})
39
45
  sup = resolve_supervisor(@supervisor, @runtime_context)
40
46
  return ToolOutput.error("SubagentSupervisor is not available in runtime context.") unless sup
@@ -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",
@@ -20,7 +20,7 @@ module Rubik
20
20
  BUILTINS = [
21
21
  ReadFileTool, ReplaceFileContentTool, WriteFileTool, ListFilesTool, GrepSearchTool,
22
22
  SearchSymbolsTool, GetOutlineTool, FindReferencesTool, GetSymbolTool,
23
- LSPDiagnosticsTool, LSPHoverTool, LSPDefinitionTool, RunTestsTool, RunCommandTool,
23
+ LSPDiagnosticsTool, LSPHoverTool, LSPDefinitionTool, LSPReferencesTool, RunTestsTool, RunCommandTool,
24
24
  ManageTaskTool, ExecReplCommandTool, SynthesizeCommandTool, SynthesizeToolTool,
25
25
  UnsynthesizeTool, InspectRuntimeTool, ProvideServiceTool, RepairRuntimeTool,
26
26
  ApplyBufferTool, AskQuestionTool, InvokeSubagentTool, ManageSubagentsTool,
@@ -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
@@ -125,7 +125,7 @@ module Rubik
125
125
  raw_context_index = service_overrides[:context_index]
126
126
 
127
127
  register_file_and_search_tools(registry, buffer_manager: buffer_manager, svc: svc, root_dir: root_dir, native_switch: native_switch, ctx: ctx)
128
- register_lsp_tools(registry, lsp_manager: lsp_manager, buffer_manager: buffer_manager)
128
+ register_lsp_tools(registry, lsp_manager: lsp_manager, buffer_manager: buffer_manager, ctx: ctx)
129
129
  register_execution_tools(registry, svc: svc, raw_context_index: raw_context_index, root_dir: root_dir, native_switch: native_switch, ctx: ctx)
130
130
  register_repl_and_synthesis_tools(
131
131
  registry,
@@ -161,10 +161,11 @@ module Rubik
161
161
  registry.register(GetSymbolTool.new(svc.ast_graph, runtime_context: ctx))
162
162
  end
163
163
 
164
- def self.register_lsp_tools(registry, lsp_manager:, buffer_manager:)
165
- registry.register(LSPDiagnosticsTool.new(lsp_manager, buffer_manager: buffer_manager))
166
- registry.register(LSPHoverTool.new(lsp_manager, buffer_manager: buffer_manager))
167
- registry.register(LSPDefinitionTool.new(lsp_manager, buffer_manager: buffer_manager))
164
+ def self.register_lsp_tools(registry, lsp_manager:, buffer_manager:, ctx: nil)
165
+ registry.register(LSPDiagnosticsTool.new(lsp_manager, buffer_manager: buffer_manager, runtime_context: ctx))
166
+ registry.register(LSPHoverTool.new(lsp_manager, buffer_manager: buffer_manager, runtime_context: ctx))
167
+ registry.register(LSPDefinitionTool.new(lsp_manager, buffer_manager: buffer_manager, runtime_context: ctx))
168
+ registry.register(LSPReferencesTool.new(lsp_manager, buffer_manager: buffer_manager, runtime_context: ctx))
168
169
  end
169
170
 
170
171
  def self.register_execution_tools(registry, svc:, raw_context_index:, root_dir:, native_switch:, ctx:)
@@ -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.0"
4
+ VERSION = "0.8.0"
5
5
  end