rubik 0.5.0 → 0.7.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/CHANGELOG.md +126 -1
- data/lib/rubik/benchmark/runner.rb +17 -0
- data/lib/rubik/benchmark/vakanuvis_adoption.rb +439 -0
- data/lib/rubik/config/defaults.rb +8 -0
- data/lib/rubik/context/index.rb +76 -42
- data/lib/rubik/context/root_heuristics.rb +93 -0
- data/lib/rubik/context/scanner.rb +33 -5
- data/lib/rubik/context.rb +1 -0
- data/lib/rubik/log.rb +4 -3
- data/lib/rubik/orchestrator/step_executor.rb +14 -4
- data/lib/rubik/orchestrator/subagent/tool_dispatch.rb +41 -12
- data/lib/rubik/orchestrator/tool_timeout.rb +193 -0
- data/lib/rubik/prompt/emergency_compactor.rb +7 -3
- data/lib/rubik/repl/command_context.rb +6 -0
- data/lib/rubik/repl/commands/agent_context.rb +17 -1
- data/lib/rubik/repl/commands/agent_execution.rb +7 -0
- data/lib/rubik/repl/composition.rb +2 -1
- data/lib/rubik/repl/input_execution.rb +5 -1
- data/lib/rubik/repl/lifecycle.rb +51 -1
- data/lib/rubik/storage/vakanuvis/annal_writer.rb +51 -4
- data/lib/rubik/storage/vakanuvis/distill_gate.rb +14 -2
- data/lib/rubik/storage/vakanuvis/gate.rb +16 -13
- data/lib/rubik/storage/vakanuvis/harness.rb +40 -15
- data/lib/rubik/storage/vakanuvis/job.rb +25 -0
- data/lib/rubik/storage/vakanuvis.rb +12 -0
- data/lib/rubik/tools/builtins/files.rb +24 -5
- data/lib/rubik/tools/builtins/grep.rb +54 -31
- data/lib/rubik/tools/index_messages.rb +38 -0
- data/lib/rubik/tools/native_search.rb +14 -5
- data/lib/rubik/tools/truncator.rb +53 -0
- data/lib/rubik/version.rb +1 -1
- metadata +6 -1
|
@@ -27,6 +27,9 @@ module Rubik
|
|
|
27
27
|
SUBAGENT_EVENT = :subagent_completed
|
|
28
28
|
GOAL_EVENT = :goal_finished
|
|
29
29
|
TURN_EVENT = :turn_finished
|
|
30
|
+
# Askı kroniği (tarama kartı 2, 2026-11-01): GoalState::SUSPEND_EVENT — abonelik
|
|
31
|
+
# :goal akışına yazar; worker status=="suspended" ile ayırt eder.
|
|
32
|
+
SUSPEND_EVENT = :goal_suspended
|
|
30
33
|
|
|
31
34
|
attr_reader :store, :config, :supervisor, :dmesg, :session_slug, :gate
|
|
32
35
|
|
|
@@ -269,6 +272,7 @@ module Rubik
|
|
|
269
272
|
|
|
270
273
|
@event_bus.subscribe(SUBAGENT_EVENT, context: @context) { |p| enqueue_event(:subagent, p) }
|
|
271
274
|
@event_bus.subscribe(GOAL_EVENT, context: @context) { |p| enqueue_event(:goal, p) }
|
|
275
|
+
@event_bus.subscribe(SUSPEND_EVENT, context: @context) { |p| enqueue_event(:goal, p) }
|
|
272
276
|
@event_bus.subscribe(TURN_EVENT, context: @context) { |p| enqueue_event(:turn, p) } if @root_turns
|
|
273
277
|
end
|
|
274
278
|
|
|
@@ -295,13 +299,19 @@ module Rubik
|
|
|
295
299
|
break if kind == STOP
|
|
296
300
|
|
|
297
301
|
handle_event(kind, payload)
|
|
302
|
+
rescue StandardError => e
|
|
303
|
+
# Last-ditch net: a raise escaping handle_event's own rescue
|
|
304
|
+
# would kill the worker with queued events unconsumed — and
|
|
305
|
+
# shutdown's alive?-check stays blind to that loss.
|
|
306
|
+
Vakanuvis.log_via(@dmesg, :warn, "chronicler worker event dispatch failed (#{e.class}: #{e.message}) — worker continues")
|
|
298
307
|
ensure
|
|
299
308
|
@monitor.synchronize { @busy -= 1 }
|
|
300
309
|
end
|
|
301
310
|
end
|
|
302
311
|
|
|
303
312
|
# TranscriptIndexer disiplini: kronikçinin kendi hatası akışı
|
|
304
|
-
# asla bozmaz — uyarı düşer, sonraki olay işlenir.
|
|
313
|
+
# asla bozmaz — uyarı düşer, sonraki olay işlenir. Kimlik eki
|
|
314
|
+
# (F7) AnnalWriter.event_context'te.
|
|
305
315
|
def handle_event(kind, payload)
|
|
306
316
|
case kind
|
|
307
317
|
when :subagent then handle_subagent(payload)
|
|
@@ -309,7 +319,9 @@ module Rubik
|
|
|
309
319
|
when :turn then handle_turn(payload)
|
|
310
320
|
end
|
|
311
321
|
rescue StandardError => e
|
|
312
|
-
|
|
322
|
+
# İlk backtrace karesi (event_loop.rb kuralı): depo hatasını
|
|
323
|
+
# annal/digest hatasından ayırt eder.
|
|
324
|
+
Vakanuvis.log_via(@dmesg, :warn, "event handling failed (#{kind}#{AnnalWriter.event_context(kind, payload)}): #{e.class}: #{e.message} @ #{(e.backtrace || []).first}")
|
|
313
325
|
end
|
|
314
326
|
|
|
315
327
|
def handle_subagent(payload)
|
|
@@ -336,6 +348,10 @@ module Rubik
|
|
|
336
348
|
end
|
|
337
349
|
|
|
338
350
|
def handle_goal(payload)
|
|
351
|
+
if payload[:status].to_s == "suspended" # askı kroniği: satır düşer, mint/upsert/maintain yok (kart 2)
|
|
352
|
+
seq = next_seq # anahtar hedef kimliği — sıra peek'i değil (issue #350)
|
|
353
|
+
return append_session(AnnalWriter.suspend_line(seq, payload))
|
|
354
|
+
end
|
|
339
355
|
ordinal = next_goal_ordinal
|
|
340
356
|
enriched = payload.merge(goal_ordinal: ordinal)
|
|
341
357
|
seq = next_seq
|
|
@@ -344,17 +360,16 @@ module Rubik
|
|
|
344
360
|
title: AnnalWriter.goal_title(ordinal, enriched[:goal]), body: goal_body.join("\n"),
|
|
345
361
|
tags: Vocabulary::ANNAL_TAGS + [Vocabulary::GOAL_TAG], links: { "session" => Vocabulary.session_ref(@session_slug) })
|
|
346
362
|
append_session(AnnalWriter.goal_lines(seq, enriched))
|
|
347
|
-
maintain(goal_end: true)
|
|
363
|
+
maintain(goal_end: true, goal_ordinal: ordinal)
|
|
348
364
|
end
|
|
349
365
|
|
|
350
366
|
# Goal sırası mağazadan türetilir (refs'teki en büyük annal.goal.<n>
|
|
351
|
-
# + 1): süreç yeniden başlasa bile aynı depoda numara çakışmaz
|
|
352
|
-
#
|
|
353
|
-
def next_goal_ordinal
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
end
|
|
367
|
+
# + 1): süreç yeniden başlasa bile aynı depoda numara çakışmaz.
|
|
368
|
+
# Askı artık peek ETMEZ (issue #350) — sıra yalnız bitişte mint edilir.
|
|
369
|
+
def next_goal_ordinal = @goal_ordinal = peek_goal_ordinal
|
|
370
|
+
|
|
371
|
+
def peek_goal_ordinal
|
|
372
|
+
@monitor.synchronize { [@goal_ordinal, @store.refs.keys.filter_map { |k| Vocabulary.goal_ordinal(k) }.max.to_i].max + 1 }
|
|
358
373
|
end
|
|
359
374
|
|
|
360
375
|
# Flush sayacı (R8): subagent ve turn olayları aynı ölçüde sayılır;
|
|
@@ -372,13 +387,13 @@ module Rubik
|
|
|
372
387
|
# yeniden hesap + dokunulan hafıza konularının otomatik damıtımı +
|
|
373
388
|
# damıtıcı doğum kararı. v2 §4-V5: toplu doğum yalnızca kirli işaretle;
|
|
374
389
|
# hedefli damıtım TÜM konuları kuyrukladıysa toplu doğum atlanır — kayıp/red varsa batch telafi eder.
|
|
375
|
-
def maintain(goal_end: false)
|
|
390
|
+
def maintain(goal_end: false, goal_ordinal: nil)
|
|
376
391
|
# Sweep record() ile aynı kilide koşar (tek-yazar disiplini):
|
|
377
392
|
# get-then-put dansı çift satır açamaz.
|
|
378
393
|
swept = @monitor.synchronize { MemorySteward.sweep_rogue_memory(@store) }
|
|
379
394
|
Vakanuvis.log_via(@dmesg, :info, "steward swept #{swept} rogue memory row(s)") if swept.positive?
|
|
380
395
|
WikiSkeleton.rebuild_home(@store)
|
|
381
|
-
digested = auto_digest_touched!(spawn: !stopped
|
|
396
|
+
digested = auto_digest_touched!(spawn: !stopped?, goal_ordinal: goal_ordinal) if goal_end
|
|
382
397
|
@gate.flush_tick unless stopped? || digested
|
|
383
398
|
end
|
|
384
399
|
|
|
@@ -387,7 +402,7 @@ module Rubik
|
|
|
387
402
|
# spawn=false (kapanış) zombi LLM doğumunu engeller. Konu-başı yalıtım
|
|
388
403
|
# (review #346): tek başarısız/red'li submit kalan konuları kaybettirmez —
|
|
389
404
|
# kayıplar @touched_topics'e geri alınır, bir sonraki flush noktası dener.
|
|
390
|
-
def auto_digest_touched!(spawn: true)
|
|
405
|
+
def auto_digest_touched!(spawn: true, goal_ordinal: nil)
|
|
391
406
|
return false unless @auto_digest && @distiller_enabled
|
|
392
407
|
|
|
393
408
|
spawn_allowed = spawn && !stopped?
|
|
@@ -395,10 +410,11 @@ module Rubik
|
|
|
395
410
|
return false if topics.empty?
|
|
396
411
|
|
|
397
412
|
stranded = topics.reject do |topic|
|
|
398
|
-
_receipt, status = @gate.submit_with_status(topic, spawn: spawn_allowed)
|
|
413
|
+
_receipt, status = @gate.submit_with_status(topic, spawn: spawn_allowed, goal_ordinal: goal_ordinal)
|
|
414
|
+
next true if status == :duplicate && Vakanuvis.log_duplicate_digest(@dmesg, topic, goal_ordinal) # F9: sessiz başarı değil
|
|
399
415
|
next true unless status == :full
|
|
400
416
|
|
|
401
|
-
Vakanuvis.log_via(@dmesg, :warn, "auto-digest refused for '#{topic}' (gate capacity full) — kept for the next
|
|
417
|
+
Vakanuvis.log_via(@dmesg, :warn, "auto-digest refused for '#{topic}' (gate capacity full) — kept for the next goal end or shutdown")
|
|
402
418
|
false
|
|
403
419
|
rescue StandardError => e
|
|
404
420
|
Vakanuvis.log_via(@dmesg, :warn, "auto-digest submit failed for '#{topic}' (#{e.class}: #{e.message})")
|
|
@@ -411,6 +427,15 @@ module Rubik
|
|
|
411
427
|
note += "; #{stranded.size} refused/failed topic(s) kept for the next flush point (warnings above)" unless stranded.empty?
|
|
412
428
|
Vakanuvis.log_via(@dmesg, :warn, note)
|
|
413
429
|
end
|
|
430
|
+
# Kapalı doğum: kapı :accepted dedi ama damıtıcı hiç doğamaz —
|
|
431
|
+
# uyarı yoksa topic'ler tüm oturum kuyrukta sessizce birikirdi.
|
|
432
|
+
if spawn_allowed && @gate.respond_to?(:spawn_allowed?) && !@gate.spawn_allowed?
|
|
433
|
+
queued = topics - stranded
|
|
434
|
+
unless queued.empty?
|
|
435
|
+
note = "auto-digest queued #{queued.size} touched topic(s) but no distiller can run (spawn disabled)"
|
|
436
|
+
Vakanuvis.log_via(@dmesg, :warn, "#{note} — they will not compile this session: #{queued.join(', ')}")
|
|
437
|
+
end
|
|
438
|
+
end
|
|
414
439
|
stranded.empty?
|
|
415
440
|
end
|
|
416
441
|
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Rubik
|
|
4
|
+
module Storage
|
|
5
|
+
module Vakanuvis
|
|
6
|
+
module DistillGate
|
|
7
|
+
# Digest iş sözleşmesinin tek evi (tarama kartı 1, 2026-11-01 — defer #9
|
|
8
|
+
# kapanışı): kuyrukta iki ayrı Hash literal mint ediliyor, tüketiciler
|
|
9
|
+
# dört anahtarı [] ile okuyor ve öksüz :goal_id hiçbir mint sitesinde
|
|
10
|
+
# yazılmıyordu. Job bu şekli tiper: Struct#[] sembol okumasını korur
|
|
11
|
+
# (mevcut okuma siteleri değişmez), keyword_init mint sitelerini
|
|
12
|
+
# sözlüğe sabitler, var olmayan anahtar imkânsızlaşır.
|
|
13
|
+
#
|
|
14
|
+
# - query: damıtılacak konu sorgusu (toplu işlerde nil)
|
|
15
|
+
# - target: hedef wiki ref (Vocabulary.wiki_ref) — nil ⇒ toplu derleme;
|
|
16
|
+
# nil-target ayırt etme sözleşmesi değişmez, batch onun açık bayrağıdır
|
|
17
|
+
# - transcript_uris: kaynak disiplinine uyan tamamlanmış transcript URI'leri
|
|
18
|
+
# - goal_ordinal: goal-end auto-digest taşıyıcısı (Q2, 2026-11-01) — brief
|
|
19
|
+
# goal kaydını (annal.goal.<n> note'u) kaynak listesine ekler;
|
|
20
|
+
# kapanış ve toplu işlerde nil, satır brief'e hiç girmez
|
|
21
|
+
Job = Struct.new(:query, :target, :transcript_uris, :batch, :goal_ordinal, keyword_init: true)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -69,6 +69,17 @@ module Rubik
|
|
|
69
69
|
existing["links"] == links.to_h { |k, v| [k.to_s, v.to_s] }.sort.to_h &&
|
|
70
70
|
existing["status"] == status.to_s
|
|
71
71
|
end
|
|
72
|
+
|
|
73
|
+
# Mükerrer otomatik-damıtım kabulü (issue #351 F9): "already queued"
|
|
74
|
+
# sessiz başarı sayılmaz — mevcut iş değişmez, bu goal kaydına
|
|
75
|
+
# bağlanmaz; iz satırı düşer. Dönen true çağrı yerindeki kısa-devre
|
|
76
|
+
# koşuluna hizmet eder (mükerrer stranded DEĞİLDİR, yeniden kuyruğa
|
|
77
|
+
# girmez — var olan iş hedefi zaten derliyor).
|
|
78
|
+
def log_duplicate_digest(dmesg, topic, goal_ordinal)
|
|
79
|
+
note = goal_ordinal ? "goal record ##{goal_ordinal} not attached; " : ""
|
|
80
|
+
log_via(dmesg, :warn, "auto-digest duplicate for '#{topic}' — #{note}existing job keeps its own context")
|
|
81
|
+
true
|
|
82
|
+
end
|
|
72
83
|
end
|
|
73
84
|
end
|
|
74
85
|
end
|
|
@@ -78,6 +89,7 @@ require_relative "vakanuvis/annal_writer"
|
|
|
78
89
|
require_relative "vakanuvis/memory_steward"
|
|
79
90
|
require_relative "vakanuvis/wiki_skeleton"
|
|
80
91
|
require_relative "vakanuvis/distill_gate"
|
|
92
|
+
require_relative "vakanuvis/job"
|
|
81
93
|
require_relative "vakanuvis/gate"
|
|
82
94
|
require_relative "vakanuvis/harness"
|
|
83
95
|
require_relative "vakanuvis/orientation"
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative "../base"
|
|
4
4
|
require_relative "../../coeffects"
|
|
5
|
+
require_relative "../index_messages"
|
|
5
6
|
require_relative "../uri_resolver"
|
|
6
7
|
require_relative "../output"
|
|
7
8
|
require_relative "../diagnostic_reporter"
|
|
@@ -152,6 +153,11 @@ module Rubik
|
|
|
152
153
|
}
|
|
153
154
|
}
|
|
154
155
|
)
|
|
156
|
+
# Honest not-ready answer for the empty-index window: names the cause,
|
|
157
|
+
# the escape hatch, and that ignore-excluded dirs never enter the index.
|
|
158
|
+
INDEX_NOT_READY_MESSAGE = "#{IndexMessages::INDEX_NOT_READY_PREFIX}" \
|
|
159
|
+
"browse with run_command (e.g. `ls`) / read files by absolute path. " \
|
|
160
|
+
"Note: directories excluded by ignore rules (.gitignore / default excludes) never enter the index.".freeze
|
|
155
161
|
def initialize(context_index = nil, root_dir: Dir.pwd, runtime_context: nil, context: nil)
|
|
156
162
|
super(DECLARATION)
|
|
157
163
|
@context_index = context_index
|
|
@@ -167,7 +173,7 @@ module Rubik
|
|
|
167
173
|
path_filter = args["path"] || args[:path]
|
|
168
174
|
ext_filter = args["extension"] || args[:extension]
|
|
169
175
|
idx = context_index
|
|
170
|
-
return ToolOutput.error(
|
|
176
|
+
return ToolOutput.error(IndexMessages::INDEX_UNAVAILABLE_MESSAGE) unless idx
|
|
171
177
|
|
|
172
178
|
filter, error = BaseTool.normalize_path_filter(path_filter, @root_dir)
|
|
173
179
|
if error
|
|
@@ -176,23 +182,36 @@ module Rubik
|
|
|
176
182
|
return ToolOutput.error(DiagnosticReporter.render_traversal_blocked(path_filter, allowed_roots: allowed))
|
|
177
183
|
end
|
|
178
184
|
|
|
179
|
-
|
|
185
|
+
# Tools never scan: an empty index answers honestly instead of
|
|
186
|
+
# triggering a synchronous full_scan inside the tool call.
|
|
187
|
+
return ToolOutput.error(INDEX_NOT_READY_MESSAGE) if idx.files.empty?
|
|
188
|
+
|
|
189
|
+
files = idx.files
|
|
190
|
+
# A no-match/ignored verdict from a PARTIAL index is the dangerous
|
|
191
|
+
# case — the file may exist but the aborted walk never saw it — so
|
|
192
|
+
# every answer below carries the disclosure.
|
|
193
|
+
partial_note = IndexMessages.note_for(idx)
|
|
180
194
|
# Path-filtered list drives the B9 explanation: an extension miss in
|
|
181
195
|
# an INDEXED directory must read "no such files here", not "ignored".
|
|
182
196
|
path_filtered = filter.empty? ? files.keys : files.keys.select { |f| f.start_with?(filter) }
|
|
183
197
|
file_list = ext_filter && !ext_filter.empty? ? path_filtered.select { |f| f.end_with?(ext_filter) } : path_filtered
|
|
184
198
|
|
|
185
|
-
return ignored_directory_message(filter, ext_filter) if path_filtered.empty? && existing_but_unindexed?(@root_dir, filter)
|
|
199
|
+
return with_note(ignored_directory_message(filter, ext_filter), partial_note) if path_filtered.empty? && existing_but_unindexed?(@root_dir, filter)
|
|
186
200
|
|
|
187
|
-
return BaseTool.no_match_message(filter) if file_list.empty?
|
|
201
|
+
return with_note(BaseTool.no_match_message(filter), partial_note) if file_list.empty?
|
|
188
202
|
|
|
189
|
-
"Found #{file_list.size} file(s):\n#{file_list.first(50).map { |f| " - #{f}" }.join("\n")}"
|
|
203
|
+
listing = "Found #{file_list.size} file(s):\n#{file_list.first(50).map { |f| " - #{f}" }.join("\n")}"
|
|
204
|
+
partial_note ? "#{listing}#{partial_note}" : listing
|
|
190
205
|
rescue Errno::EACCES => e
|
|
191
206
|
ToolOutput.error(DiagnosticReporter.render_permission_denied(path_filter || @root_dir, operation: "read", reason: e.message))
|
|
192
207
|
end
|
|
193
208
|
|
|
194
209
|
private
|
|
195
210
|
|
|
211
|
+
def with_note(message, note)
|
|
212
|
+
note ? "#{message}#{note}" : message
|
|
213
|
+
end
|
|
214
|
+
|
|
196
215
|
# Session review B9: `list_files(path: 'lib')` answered "No matching
|
|
197
216
|
# files" for a directory that exists — the context index prunes ignore
|
|
198
217
|
# rules (.gitignore, DEFAULT_IGNORES) silently. Say so and hand the
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative "../base"
|
|
4
4
|
require_relative "../../coeffects"
|
|
5
|
+
require_relative "../index_messages"
|
|
5
6
|
require_relative "../output"
|
|
6
7
|
require_relative "../native_search"
|
|
7
8
|
require_relative "../diagnostic_reporter"
|
|
@@ -30,6 +31,10 @@ module Rubik
|
|
|
30
31
|
required: ["query"]
|
|
31
32
|
}
|
|
32
33
|
)
|
|
34
|
+
# Honest not-ready answer: an empty index means "nothing searched
|
|
35
|
+
# yet", not "no matches".
|
|
36
|
+
INDEX_NOT_READY_MESSAGE = "#{IndexMessages::INDEX_NOT_READY_PREFIX}" \
|
|
37
|
+
"search with run_command (e.g. `rg` / `grep`) directly.".freeze
|
|
33
38
|
def initialize(buffer_manager = nil, context_index = nil, root_dir: Dir.pwd, runtime_context: nil, context: nil, config: nil)
|
|
34
39
|
super(DECLARATION)
|
|
35
40
|
@buffer_manager = buffer_manager
|
|
@@ -72,28 +77,53 @@ module Rubik
|
|
|
72
77
|
regex = regex_for(query, case_sensitive)
|
|
73
78
|
|
|
74
79
|
matches = try_native_search(query, path_filter, ext_filter, case_sensitive, max_results, regex)
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
80
|
+
scope_note = nil
|
|
81
|
+
if matches.nil?
|
|
82
|
+
# Tools never scan: an absent or empty index answers honestly.
|
|
83
|
+
idx = context_index
|
|
84
|
+
return ToolOutput.error(IndexMessages::INDEX_UNAVAILABLE_MESSAGE) if idx.nil?
|
|
85
|
+
|
|
86
|
+
if idx.files.empty?
|
|
87
|
+
buf = buffer_manager
|
|
88
|
+
dirty = buf&.dirty_files ? buf.dirty_files.keys : []
|
|
89
|
+
scoped = dirty.select { |f| pass_path?(f, path_filter) && pass_extension?(f, ext_filter) }
|
|
90
|
+
return ToolOutput.error(INDEX_NOT_READY_MESSAGE) if scoped.empty?
|
|
91
|
+
|
|
92
|
+
# Memory-only search: the disk was not scanned, so hits and
|
|
93
|
+
# no-hits must both disclose that scope.
|
|
94
|
+
hits = ruby_search(path_filter, ext_filter, regex, max_results)
|
|
95
|
+
scope_note = "Searched only the #{scoped.size} in-memory dirty buffer file(s) — the context index is empty, " \
|
|
96
|
+
"the disk was not searched."
|
|
97
|
+
return ToolOutput.error("#{INDEX_NOT_READY_MESSAGE} #{scope_note} No matches there.") if hits.empty?
|
|
98
|
+
|
|
99
|
+
matches = hits
|
|
93
100
|
end
|
|
94
|
-
lines << "... [Grep output capped at #{MAX_OUTPUT_CHARS / 1024}KB to protect context window. Narrow search via 'path' or 'extension']" if capped
|
|
95
|
-
lines.join("\n")
|
|
96
101
|
end
|
|
102
|
+
matches ||= ruby_search(path_filter, ext_filter, regex, max_results)
|
|
103
|
+
|
|
104
|
+
result = if matches.empty?
|
|
105
|
+
"No matching lines found for '#{query}'.#{" (path filter: '#{path_filter}')" unless path_filter.empty?}"
|
|
106
|
+
else
|
|
107
|
+
lines = ["Found #{matches.size} match(es) for '#{query}':"]
|
|
108
|
+
total_chars = 0
|
|
109
|
+
capped = false
|
|
110
|
+
matches.each do |m|
|
|
111
|
+
content = sanitize_line_content(m[:content].to_s)
|
|
112
|
+
entry = "#{m[:file]}:#{m[:line]}: #{content}"
|
|
113
|
+
if (total_chars + entry.length) > MAX_OUTPUT_CHARS
|
|
114
|
+
capped = true
|
|
115
|
+
break
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
lines << entry
|
|
119
|
+
total_chars += entry.length
|
|
120
|
+
end
|
|
121
|
+
lines << "... [Grep output capped at #{MAX_OUTPUT_CHARS / 1024}KB to protect context window. Narrow search via 'path' or 'extension']" if capped
|
|
122
|
+
lines.join("\n")
|
|
123
|
+
end
|
|
124
|
+
note = IndexMessages.note_for(context_index)
|
|
125
|
+
result = "#{result}#{note}" if note
|
|
126
|
+
scope_note ? "#{scope_note}\n#{result}" : result
|
|
97
127
|
rescue Errno::EACCES => e
|
|
98
128
|
ToolOutput.error(DiagnosticReporter.render_permission_denied(path_filter.empty? ? @root_dir : path_filter, operation: "read", reason: e.message))
|
|
99
129
|
rescue Rubik::Buffer::InvalidPathError
|
|
@@ -150,18 +180,11 @@ module Rubik
|
|
|
150
180
|
(native + memory).sort_by { |m| [m[:file], m[:line]] }.first(max_results)
|
|
151
181
|
end
|
|
152
182
|
|
|
153
|
-
# Pure-Ruby search over the context index
|
|
154
|
-
#
|
|
155
|
-
#
|
|
156
|
-
# strings otherwise — while the per-file line iteration avoids
|
|
157
|
-
# materializing a line array.
|
|
183
|
+
# Pure-Ruby search over the context index; buffer.read when a buffer
|
|
184
|
+
# manager exists, streamed lines otherwise. Callers guarantee a
|
|
185
|
+
# non-nil, non-empty index (execute refuses otherwise).
|
|
158
186
|
def ruby_search(path_filter, ext_filter, regex, max_results)
|
|
159
|
-
|
|
160
|
-
files = if idx
|
|
161
|
-
idx.files.empty? ? idx.full_scan : idx.files
|
|
162
|
-
else
|
|
163
|
-
Rubik::Context::Scanner.new(root_dir: @root_dir, native: @config&.fetch("tools.native")).scan
|
|
164
|
-
end
|
|
187
|
+
files = context_index.files
|
|
165
188
|
|
|
166
189
|
all_file_keys = files.keys
|
|
167
190
|
all_file_keys = (all_file_keys + buffer_manager.dirty_files.keys).uniq if buffer_manager&.dirty_files
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Rubik
|
|
4
|
+
module Tools
|
|
5
|
+
# Shared wording for the tools that consume the context index: one
|
|
6
|
+
# prefix keeps the not-ready phrasing consistent across tools.
|
|
7
|
+
module IndexMessages
|
|
8
|
+
# The index exists but holds no files. Tools append their own
|
|
9
|
+
# escape-hatch tail to this prefix.
|
|
10
|
+
INDEX_NOT_READY_PREFIX = "Context index has no files indexed yet (still building, or the scan failed). " \
|
|
11
|
+
"Run '!context scan' to build it, or "
|
|
12
|
+
|
|
13
|
+
# The index coeffect is absent entirely: nothing to search against.
|
|
14
|
+
INDEX_UNAVAILABLE_MESSAGE = "Context index is not available. Run '!context scan' or restart the session to build it."
|
|
15
|
+
|
|
16
|
+
# Suffix for SUCCESS results served from a PARTIAL index: the model
|
|
17
|
+
# must never mistake a truncated index for ground truth. Returns nil
|
|
18
|
+
# for a clean scan so success output stays unchanged.
|
|
19
|
+
module_function
|
|
20
|
+
|
|
21
|
+
# Reads the completeness verdict off an index's status_summary; nil
|
|
22
|
+
# for a clean scan or an object without the summary seam (test doubles).
|
|
23
|
+
def note_for(idx)
|
|
24
|
+
return nil unless idx.respond_to?(:status_summary)
|
|
25
|
+
|
|
26
|
+
summary = idx.status_summary
|
|
27
|
+
partial_index_note(summary[:last_scan_aborted], summary[:last_scan_error])
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def partial_index_note(aborted, error)
|
|
31
|
+
return nil unless aborted
|
|
32
|
+
|
|
33
|
+
" Note: the context index is PARTIAL — the last scan aborted" \
|
|
34
|
+
"#{" (#{error})" if error}. Results may be missing files; '!context scan' rebuilds it."
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -35,12 +35,21 @@ module Rubik
|
|
|
35
35
|
@rg_path = nil
|
|
36
36
|
|
|
37
37
|
class << self
|
|
38
|
-
#
|
|
39
|
-
# may not
|
|
40
|
-
#
|
|
41
|
-
#
|
|
38
|
+
# Keeps the rg-side and Ruby-side file universes identical: the
|
|
39
|
+
# repo's .gitignore may not prune what Rubik prunes. Lazily built
|
|
40
|
+
# (Scanner may be unloaded at require time). DEFAULT_IGNORES needs
|
|
41
|
+
# both glob forms — a middle-slash rg glob is root-anchored while
|
|
42
|
+
# the Ruby side prunes at any depth; HARD_PRUNE_ROOTS is
|
|
43
|
+
# root-anchored on both sides.
|
|
42
44
|
def prune_globs
|
|
43
|
-
@prune_globs ||=
|
|
45
|
+
@prune_globs ||= (
|
|
46
|
+
Rubik::Context::Scanner::DEFAULT_IGNORES.flat_map do |p|
|
|
47
|
+
globs = ["-g", "!#{p}"]
|
|
48
|
+
globs += ["-g", "!**/#{p}"] unless p.start_with?("**/")
|
|
49
|
+
globs
|
|
50
|
+
end +
|
|
51
|
+
Rubik::Context::Scanner::HARD_PRUNE_ROOTS.flat_map { |r| ["-g", "!/#{r}/**"] }
|
|
52
|
+
).freeze
|
|
44
53
|
end
|
|
45
54
|
|
|
46
55
|
# Resolved rg executable, or nil. RUBIK_RG_PATH beats PATH lookup
|
|
@@ -5,6 +5,59 @@ 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.
|
|
11
|
+
DEFAULT_STRATEGY = :head_tail
|
|
12
|
+
# Known-strategy set (issue #349): a typo'd config value used to die
|
|
13
|
+
# silently into the head_tail `else` branch in both planes. This set
|
|
14
|
+
# is the honest frontier — resolve_strategy warns against it, and a
|
|
15
|
+
# new strategy added to #truncate must register here to be reachable.
|
|
16
|
+
STRATEGIES = [:head_tail, :head_only, :tail_only].freeze
|
|
17
|
+
|
|
18
|
+
class << self
|
|
19
|
+
# Configured-value resolver for the strategy fetch sites (root
|
|
20
|
+
# StepExecutor + subagent ToolDispatch + prompt EmergencyCompactor).
|
|
21
|
+
# nil/false/empty/missing fall back to the default SILENTLY (that
|
|
22
|
+
# path is correct today); a non-empty value outside STRATEGIES warns
|
|
23
|
+
# ONCE per distinct knob+value pair, then keeps the default — the
|
|
24
|
+
# operator "tuning" truncation with a typo must not get
|
|
25
|
+
# byte-identical old behavior in silence. `key:` names the config
|
|
26
|
+
# knob in the warn so each caller's message points at its own
|
|
27
|
+
# setting, and the frontier dedups on the pair: the same typo under
|
|
28
|
+
# two different knobs must warn twice, or fixing one knob leaves
|
|
29
|
+
# the other misconfigured in silence.
|
|
30
|
+
def resolve_strategy(value, key: "tools.truncation_strategy")
|
|
31
|
+
return DEFAULT_STRATEGY if value.nil? || value == false || value.to_s.strip.empty?
|
|
32
|
+
|
|
33
|
+
sym = value.to_s.downcase.to_sym
|
|
34
|
+
return sym if STRATEGIES.include?(sym)
|
|
35
|
+
|
|
36
|
+
warn_unknown_strategy(value, key)
|
|
37
|
+
DEFAULT_STRATEGY
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
private
|
|
41
|
+
|
|
42
|
+
# One-time-per-knob-and-value warn (UI::Theme#paint precedent):
|
|
43
|
+
# the first bad value speaks, re-occurrences (every tool result
|
|
44
|
+
# would re-resolve) stay quiet. Warn level, not debug: a config
|
|
45
|
+
# typo is operator-visible in normal operation. The value is
|
|
46
|
+
# forced to UTF-8 and scrubbed BEFORE interpolation — scrub alone
|
|
47
|
+
# is a no-op on BINARY strings — because Log.warn's rescue cannot
|
|
48
|
+
# reach a message that fails to build, and a binary-encoding
|
|
49
|
+
# config value must never turn tool results into errors.
|
|
50
|
+
def warn_unknown_strategy(value, key)
|
|
51
|
+
shown = value.to_s.dup.force_encoding(Encoding::UTF_8).scrub
|
|
52
|
+
return unless unknown_strategies.add?([key, shown])
|
|
53
|
+
|
|
54
|
+
Rubik::Log.warn(:tools, "#{key}='#{shown}' is not a known strategy (#{STRATEGIES.join('/')}) — using #{DEFAULT_STRATEGY}")
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def unknown_strategies
|
|
58
|
+
@unknown_strategies ||= Set.new
|
|
59
|
+
end
|
|
60
|
+
end
|
|
8
61
|
|
|
9
62
|
def self.truncate(text, max_chars: DEFAULT_MAX_CHARS, max_lines: DEFAULT_MAX_LINES, strategy: :head_tail, separator: "\n")
|
|
10
63
|
str = text.to_s
|
data/lib/rubik/version.rb
CHANGED
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.
|
|
4
|
+
version: 0.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Özgür Ulukır
|
|
@@ -267,6 +267,7 @@ files:
|
|
|
267
267
|
- lib/rubik/benchmark.rb
|
|
268
268
|
- lib/rubik/benchmark/runner.rb
|
|
269
269
|
- lib/rubik/benchmark/synth_repo.rb
|
|
270
|
+
- lib/rubik/benchmark/vakanuvis_adoption.rb
|
|
270
271
|
- lib/rubik/buffer.rb
|
|
271
272
|
- lib/rubik/buffer/apply_contract.rb
|
|
272
273
|
- lib/rubik/buffer/diff.rb
|
|
@@ -295,6 +296,7 @@ files:
|
|
|
295
296
|
- lib/rubik/context/git_lister.rb
|
|
296
297
|
- lib/rubik/context/index.rb
|
|
297
298
|
- lib/rubik/context/repo_context_reader.rb
|
|
299
|
+
- lib/rubik/context/root_heuristics.rb
|
|
298
300
|
- lib/rubik/context/scanner.rb
|
|
299
301
|
- lib/rubik/diagnostics.rb
|
|
300
302
|
- lib/rubik/diagnostics/collector.rb
|
|
@@ -403,6 +405,7 @@ files:
|
|
|
403
405
|
- lib/rubik/orchestrator/tool_call_id.rb
|
|
404
406
|
- lib/rubik/orchestrator/tool_circuit_breaker.rb
|
|
405
407
|
- lib/rubik/orchestrator/tool_history.rb
|
|
408
|
+
- lib/rubik/orchestrator/tool_timeout.rb
|
|
406
409
|
- lib/rubik/orchestrator/turn_executor.rb
|
|
407
410
|
- lib/rubik/orchestrator/turn_executor/subagent_channel.rb
|
|
408
411
|
- lib/rubik/orchestrator/turn_executor/user_channel.rb
|
|
@@ -720,6 +723,7 @@ files:
|
|
|
720
723
|
- lib/rubik/storage/vakanuvis/distill_gate.rb
|
|
721
724
|
- lib/rubik/storage/vakanuvis/gate.rb
|
|
722
725
|
- lib/rubik/storage/vakanuvis/harness.rb
|
|
726
|
+
- lib/rubik/storage/vakanuvis/job.rb
|
|
723
727
|
- lib/rubik/storage/vakanuvis/memory_steward.rb
|
|
724
728
|
- lib/rubik/storage/vakanuvis/orientation.rb
|
|
725
729
|
- lib/rubik/storage/vakanuvis/service.rb
|
|
@@ -754,6 +758,7 @@ files:
|
|
|
754
758
|
- lib/rubik/tools/declaration.rb
|
|
755
759
|
- lib/rubik/tools/diagnostic_reporter.rb
|
|
756
760
|
- lib/rubik/tools/fuzzy_matcher.rb
|
|
761
|
+
- lib/rubik/tools/index_messages.rb
|
|
757
762
|
- lib/rubik/tools/native_search.rb
|
|
758
763
|
- lib/rubik/tools/output.rb
|
|
759
764
|
- lib/rubik/tools/preflight_runner.rb
|