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
@@ -202,8 +202,7 @@ module Rubik
202
202
  end
203
203
 
204
204
  def first_body_line(record)
205
- slice = record["body"].to_s.lines.map(&:strip).reject(&:empty?).first.to_s.slice(0, Harness::RECALL_BODY_SLICE)
206
- slice.empty? ? "(no body)" : slice
205
+ Recall.first_body_line(record)
207
206
  end
208
207
 
209
208
  # Aktif mem.* kartlarından deterministik [ref, row] sırasıyla en fazla
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubik
4
+ module Storage
5
+ module Vakanuvis
6
+ # Deterministik geri çağırma düzlemi: sorgu → digest dizgisi. LLM'siz,
7
+ # iş parçacığı içermeyen saf politika + üslup — Harness'in iş parçacığı
8
+ # çekirdeğinden (kuyruk + worker + olay dağıtımı) ayrı evi. Tüm
9
+ # RECALL_* sabitlerinin SSOT'u: Orientation ve DistillGate buradan
10
+ # okur, Harness'e geri dokunmaz.
11
+ module Recall
12
+ RECALL_LIMIT = 5
13
+ RECALL_FALLBACK_LIMIT = 3
14
+ RECALL_BODY_SLICE = 140
15
+ RECALL_TYPES = ["memory", "wiki"].freeze
16
+
17
+ module_function
18
+
19
+ # Tam deterministik, LLM'siz: Store#search_ranked BM25-lite sırası +
20
+ # RECALL_TYPES kısıtı + ilk RECALL_LIMIT kayıt ⇒ aynı depo ⇒ aynı digest.
21
+ # type: dizisi (v2 §4-V8) transcript/note gibi arama dışı tipleri hiç parse
22
+ # etmez; sıralama politika kararına aittir — Store#search'in [type,row] sözleşmesi değişmez.
23
+ def recall(store, query, types: RECALL_TYPES)
24
+ q = query.to_s.strip
25
+ raise ArgumentError, "recall: 'query' is required" if q.empty?
26
+
27
+ allowed = Array(types).map(&:to_s)
28
+ allowed = RECALL_TYPES if allowed.empty?
29
+ hits = DistillGate.active_recall_hits(store, query: q, type: allowed).first(RECALL_LIMIT)
30
+ unless hits.empty?
31
+ header = "Recalled #{hits.size} entit#{hits.size == 1 ? 'y' : 'ies'} for '#{AnnalWriter.one_line(q, 80)}':"
32
+ return "#{header}\n#{hits.map { |r| recall_line(store, r) }.join("\n")}\nRead a full record with read_file(path: '<uri above>')."
33
+ end
34
+
35
+ relaxed_digest(store, q, allowed)
36
+ end
37
+
38
+ # v2 §4-V2 + issue #99 P2: AND boşluğu tek tip körlük değil — en yakın
39
+ # kısmi eşleşmeler dürüstçe "(fallback)" damgasıyla sunulur (gerçek
40
+ # eşleşme değildir), transcript izleri kapsam ipucu olarak sayılır. Ne
41
+ # fallback ne transcript izi varsa bugünkü dil/terim yönlendirmesi birebir
42
+ # döner (keyword-AND'da en sık neden TR sorgu ↔ EN gövde uyuşmazlığıdır;
43
+ # yanlış "hemen yeniden kaydet" yönlendirmesi burada kesilir).
44
+ def relaxed_digest(store, query, allowed)
45
+ q = query.to_s.strip
46
+ # Süpersede edilmiş sayılar "en yakın kısmi eşleşme" olarak
47
+ # sunulmaz (review M1) — emekli bir sayfayı okumaya davet etmek,
48
+ # issue #100'ün "iki kopya, biri bozuk" bulgusunun aynısıdır.
49
+ relaxed = DistillGate.active_recall_hits(store, query: q, type: allowed, require_all: false)
50
+ .first(RECALL_FALLBACK_LIMIT)
51
+ transcripts = store.search(query: q, type: "transcript")
52
+ if relaxed.empty? && transcripts.empty?
53
+ return "No chronicled knowledge matches '#{AnnalWriter.one_line(q, 80)}'. Recall is keyword-AND: retry with fewer or other-language " \
54
+ "terms first (e.g. the TR/EN Keywords: lines). If the knowledge is genuinely missing, record it (vakanuvis action 'record') or queue a digest."
55
+ end
56
+
57
+ parts = []
58
+ # Başlık + read_file ayağı yalnız gerçek fallback izi varken
59
+ # basılır (review CR#1: "yukarıdaki uri" diyecek uri yokken
60
+ # olmayan bir talimat modele verilmesin).
61
+ unless relaxed.empty?
62
+ parts << "No exact keyword-AND match for '#{AnnalWriter.one_line(q, 80)}' — closest partial matches (fallback, not true matches):"
63
+ parts.concat(relaxed.map { |r| "- (fallback) #{recall_line(store, r)}" })
64
+ end
65
+ unless transcripts.empty?
66
+ parts << "#{transcripts.size} transcript entr#{transcripts.size == 1 ? 'y' : 'ies'} mention these terms — " \
67
+ "the raw session logs may hold it; queue a digest to compile them."
68
+ end
69
+ parts << "If none of these help, retry with fewer or other-language terms (the TR/EN Keywords: lines), " \
70
+ "record the knowledge, or queue a digest."
71
+ parts << "Read a full record with read_file(path: '<uri above>')." unless relaxed.empty?
72
+ parts.join("\n")
73
+ end
74
+
75
+ def first_body_line(record)
76
+ slice = record["body"].to_s.lines.map(&:strip).reject(&:empty?).first.to_s.slice(0, RECALL_BODY_SLICE)
77
+ slice.empty? ? "(no body)" : slice
78
+ end
79
+
80
+ def recall_line(store, record) = "- #{record['title']} [#{record['id']}] #{first_body_line(record)} — #{store.uri_for(record['type'], record['id'])}"
81
+ end
82
+ end
83
+ end
84
+ end
@@ -89,6 +89,7 @@ require_relative "vakanuvis/annal_writer"
89
89
  require_relative "vakanuvis/memory_steward"
90
90
  require_relative "vakanuvis/wiki_skeleton"
91
91
  require_relative "vakanuvis/distill_gate"
92
+ require_relative "vakanuvis/recall"
92
93
  require_relative "vakanuvis/job"
93
94
  require_relative "vakanuvis/gate"
94
95
  require_relative "vakanuvis/harness"
@@ -42,6 +42,40 @@ module Rubik
42
42
  raise NotImplementedError
43
43
  end
44
44
 
45
+ # One home for model-supplied argument access: every builtin used to
46
+ # re-roll the string/symbol key
47
+ # normalization (and its coercion) by hand — ~110 sites. Lookup
48
+ # semantics, kept byte-compatible with the old hand-rolled chains:
49
+ # keys are tried in order, string key before symbol key per key;
50
+ # first non-nil wins (false falls through like nil, matching the
51
+ # ||-chains). When `type:`
52
+ # is given the coercion applies to the resolved value AND to
53
+ # `default:` (so `type: :integer` on an absent key still yields 0,
54
+ # matching the old `(args[k] || args[sk]).to_i` idiom).
55
+ #
56
+ # param(args, :path, type: :stripped_string, default: "")
57
+ # param(args, :offset, type: :integer)
58
+ # param(args, :target_content, :old_content, :old_str, :target) # alias chain
59
+ # param(args, :reload, type: :flag) # == true
60
+ def param(args, *keys, type: nil, default: nil)
61
+ raw = nil
62
+ if args
63
+ keys.each do |key|
64
+ str = key.to_s
65
+ raw = args[str] || args[str.to_sym]
66
+ break unless raw.nil?
67
+ end
68
+ end
69
+ value = raw.nil? ? default : raw
70
+ case type
71
+ when :integer then value.to_i
72
+ when :string then value.to_s
73
+ when :stripped_string then value.to_s.strip
74
+ when :flag then value == true
75
+ else value
76
+ end
77
+ end
78
+
45
79
  # Normalizes a model-supplied path filter against the tool's root
46
80
  # directory: backslashes become slashes, "./" is stripped, and ABSOLUTE
47
81
  # paths (C:/…, /…) are relativized when they sit inside the root.
@@ -42,6 +42,12 @@ module Rubik
42
42
  @runtime_context = runtime_context
43
43
  end
44
44
 
45
+ # Subagent-plane rebind (ScopedRegistry delegate): definitions register
46
+ # against the INSTANCE's supervisor, not the root turn's.
47
+ def rebind_to(ctx)
48
+ self.class.new(supervisor: resolve_supervisor(nil, ctx), runtime_context: ctx)
49
+ end
50
+
45
51
  def execute(args = {})
46
52
  sup = resolve_supervisor(@supervisor, @runtime_context)
47
53
  return ToolOutput.error("SubagentSupervisor is not available in runtime context.") unless sup
@@ -51,10 +51,10 @@ module Rubik
51
51
  ring = resolve_dmesg
52
52
  return ToolOutput.error("Dmesg ring buffer is not available in runtime context.") unless ring
53
53
 
54
- limit = (args["limit"] || args[:limit] || 30).to_i
55
- level = args["level"] || args[:level]
56
- subsystem = args["subsystem"] || args[:subsystem]
57
- since_seq = args["since_seq"] || args[:since_seq]
54
+ limit = param(args, :limit, type: :integer, default: 30)
55
+ level = param(args, :level)
56
+ subsystem = param(args, :subsystem)
57
+ since_seq = param(args, :since_seq)
58
58
 
59
59
  records = ring.tail(limit, level: level, subsystem: subsystem, since_seq: since_seq)
60
60
  return "No kernel events found matching criteria." if records.empty?
@@ -15,7 +15,7 @@ module Rubik
15
15
  DECLARATION = Declaration.new(
16
16
  name: "read_file", aliases: ["view_file", "read"],
17
17
  description: "Read content of a file from buffer or disk with 1-based line numbers (optional 1-based offset and line limit for paging)",
18
- risk: :read, archetypes: [:research, :coder],
18
+ risk: :read, archetypes: [:research, :coder], buffer_bound: true,
19
19
  params_schema: {
20
20
  type: "object",
21
21
  properties: {
@@ -41,7 +41,7 @@ module Rubik
41
41
  end
42
42
 
43
43
  def execute(args = {})
44
- path = (args["path"] || args[:path]).to_s.strip
44
+ path = param(args, :path, type: :stripped_string)
45
45
  # rubik:// sevk tek yerde: UriResolver (bilinmeyen şema/gramer reddi
46
46
  # nil döndürür ve buffer düzlemine düşer — bugünkü düşüş sözleşmesi).
47
47
  virt = UriResolver.resolve(path, ctx: @runtime_context, buffer_manager: @buffer_manager)
@@ -52,9 +52,9 @@ module Rubik
52
52
  path = clean.sub(%r{\A/([A-Za-z]:)}, '\1')
53
53
  end
54
54
 
55
- content = if args["reload"] == true || args[:reload] == true
55
+ content = if param(args, :reload, type: :flag)
56
56
  @buffer_manager.read(path, reload: true)
57
- elsif args["from_disk"] == true || args[:from_disk] == true
57
+ elsif param(args, :from_disk, type: :flag)
58
58
  @buffer_manager.read(path, from_disk: true)
59
59
  else
60
60
  @buffer_manager.read(path)
@@ -66,8 +66,8 @@ module Rubik
66
66
  return ToolOutput.error(DiagnosticReporter.render_file_not_found(path, candidates: candidates))
67
67
  end
68
68
 
69
- offset = (args["offset"] || args[:offset]).to_i
70
- limit = (args["limit"] || args[:limit]).to_i
69
+ offset = param(args, :offset, type: :integer)
70
+ limit = param(args, :limit, type: :integer)
71
71
  lines = content.lines
72
72
  return "[empty file (0 lines)]" if lines.empty?
73
73
 
@@ -90,7 +90,7 @@ module Rubik
90
90
  description: "Write full content to the in-memory buffer (does not write to disk until apply_buffer is called). " \
91
91
  "For surgical edits to existing files, use replace_file_content instead. " \
92
92
  "Use apply_buffer to persist the buffer to disk before running tests or tests will not see your changes.",
93
- risk: :write, archetypes: [:coder], write_grant: true, maestro_blocked: true,
93
+ risk: :write, archetypes: [:coder], write_grant: true, maestro_blocked: true, buffer_bound: true,
94
94
  params_schema: {
95
95
  type: "object",
96
96
  properties: {
@@ -106,8 +106,8 @@ module Rubik
106
106
  end
107
107
 
108
108
  def execute(args = {})
109
- path = (args["path"] || args[:path]).to_s.strip
110
- content = args["content"] || args[:content]
109
+ path = param(args, :path, type: :stripped_string)
110
+ content = param(args, :content)
111
111
 
112
112
  return ToolOutput.error("Error: `path` parameter is required.") if path.empty?
113
113
  unless Rubik::Buffer::PathValidator.valid?(path)
@@ -170,8 +170,8 @@ module Rubik
170
170
  end
171
171
 
172
172
  def execute(args = {})
173
- path_filter = args["path"] || args[:path]
174
- ext_filter = args["extension"] || args[:extension]
173
+ path_filter = param(args, :path)
174
+ ext_filter = param(args, :extension)
175
175
  idx = context_index
176
176
  return ToolOutput.error(IndexMessages::INDEX_UNAVAILABLE_MESSAGE) unless idx
177
177
 
@@ -236,7 +236,7 @@ module Rubik
236
236
  name: "replace_file_content", aliases: ["edit_file", "edit_chunk", "str_replace", "patch_file"],
237
237
  description: "Replace an exact chunk of code within an existing file. Requires exact verbatim matching of target_content " \
238
238
  "(including whitespace and indentation). Optional start_line and end_line narrow the search range.",
239
- risk: :write, archetypes: [:coder], write_grant: true, maestro_blocked: true,
239
+ risk: :write, archetypes: [:coder], write_grant: true, maestro_blocked: true, buffer_bound: true,
240
240
  params_schema: {
241
241
  type: "object",
242
242
  properties: {
@@ -258,18 +258,12 @@ module Rubik
258
258
  end
259
259
 
260
260
  def execute(args = {})
261
- path = (args["path"] || args[:path]).to_s.strip
262
- target = args["target_content"] || args[:target_content] ||
263
- args["old_content"] || args[:old_content] ||
264
- args["old_str"] || args[:old_str] ||
265
- args["target"] || args[:target]
266
- replacement = args["replacement_content"] || args[:replacement_content] ||
267
- args["new_content"] || args[:new_content] ||
268
- args["new_str"] || args[:new_str] ||
269
- args["replacement"] || args[:replacement]
270
- start_line = args["start_line"] || args[:start_line]
271
- end_line = args["end_line"] || args[:end_line]
272
- allow_multiple = args["allow_multiple"] == true || args[:allow_multiple] == true
261
+ path = param(args, :path, type: :stripped_string)
262
+ target = param(args, :target_content, :old_content, :old_str, :target)
263
+ replacement = param(args, :replacement_content, :new_content, :new_str, :replacement)
264
+ start_line = param(args, :start_line)
265
+ end_line = param(args, :end_line)
266
+ allow_multiple = param(args, :allow_multiple, type: :flag)
273
267
 
274
268
  return ToolOutput.error("Error: `path` parameter is required.") if path.empty?
275
269
  return ToolOutput.error("Error: `target_content` parameter is required.") if target.nil?
@@ -27,7 +27,7 @@ module Rubik
27
27
  "filesystem and it FAILED (the world drifted): re-inspect reality, then update the " \
28
28
  "entry (including status) with a normal patch — a stale rev also means the ledger " \
29
29
  "moved under you.",
30
- risk: :write, archetypes: [], write_grant: false,
30
+ risk: :write, archetypes: [], write_grant: false, root_only: true,
31
31
  maestro_blocked: false, # vakanüvis/pruner emsali: kök düzlem aracı
32
32
  params_schema: {
33
33
  type: "object",
@@ -56,22 +56,22 @@ module Rubik
56
56
  # Scrub before strip-driven string ops and result interpolation: an
57
57
  # invalid-UTF-8 query (model transcription artifact) must not raise
58
58
  # or leak broken bytes into the rendered tool output.
59
- query = Rubik::Platform.safe_utf8((args["query"] || args[:query]).to_s).strip
59
+ query = Rubik::Platform.safe_utf8(param(args, :query, type: :string)).strip
60
60
  return ToolOutput.error("Query parameter is required.") if query.empty?
61
61
 
62
- path_filter = (args["path"] || args[:path]).to_s.strip
63
- ext_filter = (args["extension"] || args[:extension]).to_s.strip
62
+ path_filter = param(args, :path, type: :stripped_string)
63
+ ext_filter = param(args, :extension, type: :stripped_string)
64
64
 
65
65
  path_filter, outside_error = BaseTool.normalize_path_filter(path_filter, @root_dir)
66
66
  if outside_error
67
67
  allowed = [{ path: @root_dir, primary: true }]
68
68
  idx = context_index
69
69
  idx.additional_roots.each { |r| allowed << { path: r, primary: false } } if idx.respond_to?(:additional_roots)
70
- return ToolOutput.error(DiagnosticReporter.render_traversal_blocked(args["path"] || args[:path], allowed_roots: allowed))
70
+ return ToolOutput.error(DiagnosticReporter.render_traversal_blocked(param(args, :path), allowed_roots: allowed))
71
71
  end
72
72
 
73
- case_sensitive = args["case_sensitive"] || args[:case_sensitive] || false
74
- max_results = (args["max_results"] || args[:max_results] || 50).to_i
73
+ case_sensitive = param(args, :case_sensitive, default: false)
74
+ max_results = param(args, :max_results, type: :integer, default: 50)
75
75
  max_results = 50 if max_results <= 0
76
76
 
77
77
  regex = regex_for(query, case_sensitive)
@@ -54,6 +54,12 @@ module Rubik
54
54
  @runtime_context = runtime_context
55
55
  end
56
56
 
57
+ # Subagent-plane rebind (ScopedRegistry delegate): a worker never pops a
58
+ # HUMAN dialog — it asks the maestro supervisor through the child ctx.
59
+ def rebind_to(ctx)
60
+ self.class.new(shell: nil, runtime_context: ctx)
61
+ end
62
+
57
63
  def execute(args = {})
58
64
  raw_questions = args["questions"] || args[:questions]
59
65
  raw_questions = [args] if raw_questions.nil? && (args["question"] || args[:question])
@@ -16,7 +16,7 @@ module Rubik
16
16
  DECLARATION = Declaration.new(
17
17
  name: "apply_buffer", aliases: ["save_buffer", "commit_changes", "save"],
18
18
  description: "Persist all pending in-memory file buffer modifications to disk immediately (skips files with external conflicts unless force: true)",
19
- risk: :write, archetypes: [:coder], write_grant: true, maestro_blocked: false,
19
+ risk: :write, archetypes: [:coder], write_grant: true, maestro_blocked: false, buffer_bound: true,
20
20
  params_schema: {
21
21
  type: "object",
22
22
  properties: {
@@ -357,6 +357,7 @@ module Rubik
357
357
  "(file lists, counts, command outcomes) against your raw command output — context " \
358
358
  "compaction can blur report details, and the final report must match observed evidence.",
359
359
  risk: :execute, maestro_blocked: false, # the completion signal — handled before the gate; must stay direct
360
+ terminal: true, # dispatch planes route it before gates/malformed-args handling (Catalog.terminal?)
360
361
  params_schema: { type: "object",
361
362
  properties: { message: { type: "string",
362
363
  description: "Final summary message for the user describing what was accomplished (optional)" } } }