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.
@@ -17,6 +17,12 @@ module Rubik
17
17
  # 17006) and can corrupt it. Scanning itself is not changed — only the
18
18
  # shared-state mutation is made thread-safe.
19
19
  @mutex = Mutex.new
20
+ # Serializes whole scan runs (full_scan / incremental_scan) so the
21
+ # files hash and the completeness verdict pair atomically — two
22
+ # concurrent scans would otherwise let one publish the other's
23
+ # clean verdict with its own aborted files. Held only by scanners,
24
+ # never by readers (status_summary stays lock-cheap).
25
+ @scan_mutex = Mutex.new
20
26
  @scanner = scanner || Scanner.new(
21
27
  root_dir: @root_dir,
22
28
  additional_roots: additional_roots,
@@ -27,6 +33,8 @@ module Rubik
27
33
  @files = {}
28
34
  @languages = []
29
35
  @last_scan_time = nil
36
+ @last_scan_aborted = false
37
+ @last_scan_error = nil
30
38
  end
31
39
 
32
40
  def update_file_filters(includes: nil, excludes: nil)
@@ -44,58 +52,66 @@ module Rubik
44
52
  end
45
53
 
46
54
  def full_scan
47
- start_time = Time.now
48
- files = @scanner.scan
49
- languages = @scanner.detect_languages(files)
50
- @mutex.synchronize do
51
- @files = files
52
- @languages = languages
53
- @last_scan_time = Time.now - start_time
55
+ @scan_mutex.synchronize do
56
+ start_time = Time.now
57
+ files = @scanner.scan
58
+ languages = @scanner.detect_languages(files)
59
+ report = scanner_report
60
+ @mutex.synchronize do
61
+ @files = files
62
+ @languages = languages
63
+ @last_scan_time = Time.now - start_time
64
+ store_scan_outcome!(report)
65
+ end
54
66
  end
55
67
  @files
56
68
  end
57
69
 
58
70
  def incremental_scan
59
- start_time = Time.now
60
- snapshot = @mutex.synchronize { @files }
61
- new_scan = @scanner.scan(snapshot)
62
- old_files = snapshot
63
-
64
- added = []
65
- modified = []
66
- deleted = []
67
- unchanged = []
68
-
69
- new_scan.each do |rel_path, info|
70
- if old_files.key?(rel_path)
71
- old_info = old_files[rel_path]
72
- if old_info[:mtime] != info[:mtime] || old_info[:size] != info[:size] || old_info[:hash] != info[:hash]
73
- modified << rel_path
71
+ @scan_mutex.synchronize do
72
+ start_time = Time.now
73
+ snapshot = @mutex.synchronize { @files }
74
+ new_scan = @scanner.scan(snapshot)
75
+ old_files = snapshot
76
+
77
+ added = []
78
+ modified = []
79
+ deleted = []
80
+ unchanged = []
81
+
82
+ new_scan.each do |rel_path, info|
83
+ if old_files.key?(rel_path)
84
+ old_info = old_files[rel_path]
85
+ if old_info[:mtime] != info[:mtime] || old_info[:size] != info[:size] || old_info[:hash] != info[:hash]
86
+ modified << rel_path
87
+ else
88
+ unchanged << rel_path
89
+ end
74
90
  else
75
- unchanged << rel_path
91
+ added << rel_path
76
92
  end
77
- else
78
- added << rel_path
79
93
  end
80
- end
81
94
 
82
- old_files.each_key do |rel_path|
83
- deleted << rel_path unless new_scan.key?(rel_path)
84
- end
95
+ old_files.each_key do |rel_path|
96
+ deleted << rel_path unless new_scan.key?(rel_path)
97
+ end
85
98
 
86
- languages = @scanner.detect_languages(new_scan)
87
- @mutex.synchronize do
88
- @files = new_scan
89
- @languages = languages
90
- @last_scan_time = Time.now - start_time
91
- end
99
+ languages = @scanner.detect_languages(new_scan)
100
+ report = scanner_report
101
+ @mutex.synchronize do
102
+ @files = new_scan
103
+ @languages = languages
104
+ @last_scan_time = Time.now - start_time
105
+ store_scan_outcome!(report)
106
+ end
92
107
 
93
- {
94
- added: added,
95
- modified: modified,
96
- deleted: deleted,
97
- unchanged: unchanged
98
- }
108
+ {
109
+ added: added,
110
+ modified: modified,
111
+ deleted: deleted,
112
+ unchanged: unchanged
113
+ }
114
+ end
99
115
  end
100
116
 
101
117
  def update_file(rel_path)
@@ -125,10 +141,28 @@ module Rubik
125
141
  {
126
142
  file_count: @files.size,
127
143
  languages: @languages,
128
- last_scan_time_sec: @last_scan_time&.round(4)
144
+ last_scan_time_sec: @last_scan_time&.round(4),
145
+ last_scan_aborted: @last_scan_aborted,
146
+ last_scan_error: @last_scan_error
129
147
  }
130
148
  end
131
149
  end
150
+
151
+ private
152
+
153
+ # Test doubles may not carry last_scan_report; a nil report means a
154
+ # clean scan.
155
+ def scanner_report
156
+ @scanner.respond_to?(:last_scan_report) ? @scanner.last_scan_report : nil
157
+ end
158
+
159
+ # Copies the scanner's completeness verdict under the same lock that
160
+ # publishes the files, so a reader never sees files from an aborted
161
+ # scan without also seeing the flag.
162
+ def store_scan_outcome!(report)
163
+ @last_scan_aborted = report ? report.aborted : false
164
+ @last_scan_error = report&.reasons&.any? ? report.reasons.join("; ") : nil
165
+ end
132
166
  end
133
167
  end
134
168
  end
@@ -0,0 +1,93 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "open3"
4
+
5
+ module Rubik
6
+ module Context
7
+ # Cheap classifiers for a session root that is likely a huge tree (a
8
+ # home directory, a filesystem root, or OS user-data). Equality and
9
+ # presence probes only — never size probing — so a normal-repo boot
10
+ # pays nothing and prints nothing.
11
+ module RootHeuristics
12
+ # strong: true when a signal reliably implies a full walk can stall
13
+ # the REPL (boot skips the warm scan); gitless alone is a weak
14
+ # aggravator reported in the guidance but never skips the scan.
15
+ Assessment = Struct.new(:reasons, :strong, keyword_init: true)
16
+
17
+ OS_DATA_DIRS = ["AppData", "Library"].freeze
18
+
19
+ module_function
20
+
21
+ def assess(root_dir, home_dir: nil, git_probe: nil)
22
+ root = File.expand_path(root_dir.to_s)
23
+ reasons = []
24
+
25
+ reasons << "root is the user home directory" if home_dir && File.expand_path(home_dir) == root
26
+ reasons << "root is a filesystem root" if filesystem_root?(root)
27
+ os_reason = os_data_dir_reason(root)
28
+ reasons << os_reason if os_reason
29
+
30
+ strong = reasons.any?
31
+
32
+ unless git_work_tree?(root, git_probe)
33
+ reasons << (if strong
34
+ "and is not a git repository (the fallback walker is slow)"
35
+ else
36
+ "root is not a git repository"
37
+ end)
38
+ end
39
+
40
+ Assessment.new(reasons: reasons, strong: strong)
41
+ end
42
+
43
+ # Single home for the guidance wording; reused by boot and !context
44
+ # scan. Empty string when nothing was flagged. A strong verdict also
45
+ # discloses the skipped boot scan so the empty index reads as
46
+ # deliberate, not as a stuck build.
47
+ def guidance(assessment, boot_scan_skipped: false)
48
+ return "" if !assessment || assessment.reasons.empty?
49
+
50
+ tail = boot_scan_skipped ? " The boot-time scan was skipped for this root; run '!context scan' to build the index now." : ""
51
+ "Warning: the session root looks like a huge tree (#{assessment.reasons.join('; ')}). " \
52
+ "Scanning it can be very slow. Consider starting rubik in a project root, " \
53
+ "adding 'context.exclude' entries, or running '!context scan' explicitly to opt in.#{tail}"
54
+ end
55
+
56
+ def filesystem_root?(dir)
57
+ File.dirname(dir) == dir
58
+ end
59
+
60
+ def os_data_dir_reason(root)
61
+ present = begin
62
+ Dir.children(root).any? { |name| OS_DATA_DIRS.include?(name) }
63
+ rescue SystemCallError
64
+ false
65
+ end
66
+ return nil unless present
67
+
68
+ "root contains OS data directories (#{OS_DATA_DIRS.join('/')})"
69
+ end
70
+
71
+ # The .git presence fast path keeps normal repos spawn-free; the probe
72
+ # (one `git rev-parse` spawn) only runs for gitless-looking roots. A
73
+ # failed probe (missing binary, ...) reads as gitless — over-warning
74
+ # by design — but stays discoverable in the log.
75
+ def git_work_tree?(dir, probe)
76
+ return true if File.exist?(File.join(dir, ".git"))
77
+
78
+ probe ||= ->(d) { system_git_probe(d) }
79
+ probe.call(dir)
80
+ rescue StandardError => e
81
+ Rubik::Log.debug(:context, "git probe failed for #{dir} (#{e.class}: #{e.message}); treating as not a repository")
82
+ false
83
+ end
84
+
85
+ def system_git_probe(dir)
86
+ out, _err, status = Open3.capture3("git", "-C", dir, "rev-parse", "--is-inside-work-tree")
87
+ # A bare repo also exits 0 but answers "false" — the verdict is the
88
+ # output, not the exit status.
89
+ status.success? && out.to_s.strip == "true"
90
+ end
91
+ end
92
+ end
93
+ end
@@ -65,7 +65,11 @@ module Rubik
65
65
  "dist/**",
66
66
  "build/**",
67
67
  ".cache/**",
68
- "coverage/**"
68
+ "coverage/**",
69
+ # Multi-GB local model blobs; never project sources.
70
+ ".ollama/**",
71
+ # Agent-harness state: transcripts, sessions, caches.
72
+ ".zcode/**"
69
73
  ].freeze
70
74
 
71
75
  # Subtrees whose ignore pattern is "<path>/**" (optionally with a
@@ -77,10 +81,17 @@ module Rubik
77
81
  # leaked into the index. The walker applies the pattern's plain meaning
78
82
  # (whole subtree ignored), matching real gitignore semantics.
79
83
  PRUNABLE_PATTERN = %r{\A(?:\*\*/)?(.+)/\*\*\z}
80
- # Also hard-rejected inside `ignored?`; pruned here before descending.
81
- HARD_PRUNE_ROOTS = [".git", ".rubik", ".ua", ".turbo", ".sst", ".next", ".nuxt"].freeze
84
+ # Also hard-rejected inside `ignored?`; pruned before descending.
85
+ # ROOT-anchored only (comps.first) to match the rg-side `!/X/**`
86
+ # globs — a nested `src/AppData` stays indexed.
87
+ HARD_PRUNE_ROOTS = [".git", ".rubik", ".ua", ".turbo", ".sst", ".next", ".nuxt", "AppData"].freeze
82
88
 
83
- attr_reader :root_dir, :additional_roots
89
+ # Outcome of the most recent scan. A partial index served as ground
90
+ # truth is worse than an honest flag: every rescue boundary that drops
91
+ # data marks the report so Index can surface the truncation.
92
+ ScanReport = Struct.new(:aborted, :reasons, keyword_init: true)
93
+
94
+ attr_reader :root_dir, :additional_roots, :last_scan_report
84
95
  attr_accessor :custom_includes, :custom_excludes
85
96
 
86
97
  def initialize(root_dir: Dir.pwd, additional_roots: [], includes: [], excludes: [], native: nil)
@@ -106,6 +117,7 @@ module Rubik
106
117
  # may itself be nil — content never hashed), only stat-changed files
107
118
  # are read and re-hashed. Cold entries start hash-less.
108
119
  def scan(previous = {})
120
+ @last_scan_report = ScanReport.new(aborted: false, reasons: [])
109
121
  files = {}
110
122
 
111
123
  # 1. Scan primary root
@@ -123,6 +135,7 @@ module Rubik
123
135
  files
124
136
  rescue StandardError => e
125
137
  Rubik::Log.warn(:context, "context scan aborted partway (#{e.class}: #{e.message}); returning partial index")
138
+ mark_scan_aborted!("scan aborted partway: #{e.class}: #{e.message}")
126
139
  files || {}
127
140
  end
128
141
 
@@ -155,6 +168,16 @@ module Rubik
155
168
 
156
169
  private
157
170
 
171
+ # Records one dropped-data event. The first few reasons suffice for
172
+ # display; the log keeps the full detail.
173
+ def mark_scan_aborted!(reason)
174
+ @last_scan_report ||= ScanReport.new(aborted: false, reasons: [])
175
+ @last_scan_report.aborted = true
176
+ return if @last_scan_report.reasons.length >= 5
177
+
178
+ @last_scan_report.reasons << reason.to_s[0, 160]
179
+ end
180
+
158
181
  # Stat-dirty model (à la git): a previous entry whose size and mtime
159
182
  # (microsecond precision) both match is NEVER read from disk — its
160
183
  # content hash is reused verbatim, including when it is nil (content
@@ -210,7 +233,9 @@ module Rubik
210
233
  # workspace_xml entry_points listing) stays deterministic.
211
234
  entries = begin
212
235
  Dir.foreach(current).sort - [".", ".."]
213
- rescue SystemCallError
236
+ rescue SystemCallError => e
237
+ Rubik::Log.warn(:context, "directory unreadable: #{current} (#{e.class}: #{e.message})")
238
+ mark_scan_aborted!("directory unreadable: #{current}")
214
239
  []
215
240
  end
216
241
 
@@ -250,6 +275,7 @@ module Rubik
250
275
  out
251
276
  rescue StandardError => e
252
277
  Rubik::Log.warn(:context, "directory walk failed under #{base_dir} (#{e.class}: #{e.message}); keeping partial results")
278
+ mark_scan_aborted!("directory walk failed under #{base_dir}: #{e.class}: #{e.message}")
253
279
  out
254
280
  end
255
281
 
@@ -306,6 +332,7 @@ module Rubik
306
332
  walk_dir(base_dir, "", prefix, ignore_patterns, previous, needles)
307
333
  rescue StandardError => e
308
334
  Rubik::Log.warn(:context, "root scan failed for #{base_dir} (#{e.class}: #{e.message}); root omitted from index")
335
+ mark_scan_aborted!("root scan failed for #{base_dir}: #{e.class}: #{e.message}")
309
336
  {}
310
337
  end
311
338
 
@@ -365,6 +392,7 @@ module Rubik
365
392
  out
366
393
  rescue StandardError => e
367
394
  Rubik::Log.warn(:context, "git ls-files fast path failed for #{base_dir} (#{e.class}: #{e.message}); keeping partial index")
395
+ mark_scan_aborted!("git ls-files fast path failed for #{base_dir}: #{e.class}: #{e.message}")
368
396
  out
369
397
  end
370
398
 
data/lib/rubik/context.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative "context/scanner"
4
4
  require_relative "context/index"
5
+ require_relative "context/root_heuristics"
5
6
  require_relative "context/git_info"
6
7
  require_relative "context/repo_context_reader"
7
8
 
data/lib/rubik/log.rb CHANGED
@@ -6,9 +6,10 @@
6
6
  # follows the repo's [rubik] prefix convention. Emit is error-isolated: a
7
7
  # logger must never raise, least of all from inside a rescue body.
8
8
  #
9
- # warn/error always print (current behavior). debug/info are filtered by
10
- # RUBIK_LOG_LEVEL (default "warn"); the RUBIK_DEBUG-gated debug_warn stays a
11
- # separate mechanism and is NOT migrated by this slice.
9
+ # warn/error always print at the DEFAULT level. debug/info/warn are all
10
+ # filtered by RUBIK_LOG_LEVEL (default "warn") — an operator running at
11
+ # "error" also silences :warn, by design. The RUBIK_DEBUG-gated debug_warn
12
+ # stays a separate mechanism and is NOT migrated by this slice.
12
13
  module Rubik
13
14
  module Log
14
15
  LEVELS = { debug: 0, info: 1, warn: 2, error: 3 }.freeze
@@ -5,6 +5,7 @@ require_relative "auto_apply"
5
5
  require_relative "tool_call_id"
6
6
  require_relative "tool_history"
7
7
  require_relative "tool_circuit_breaker"
8
+ require_relative "tool_timeout"
8
9
  require_relative "maestro_gate"
9
10
  require_relative "lsp_feedback"
10
11
 
@@ -160,11 +161,20 @@ module Rubik
160
161
  "circuit open for '#{tool_instance.name}' — repeated failures; waiting out the cooldown before retrying"
161
162
  end
162
163
 
163
- raw_output = tool_instance.execute(tool_args)
164
+ raw_output = ToolTimeout.call(tool_instance, config: @deps.shell&.config,
165
+ canonical_name: tool_instance.name) do
166
+ tool_instance.execute(tool_args)
167
+ end
164
168
  t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
165
169
  dur = ((t1 - t0) * 1000).round(1)
166
170
 
167
171
  normalize_raw_output(raw_output, tool_name, call_id, dur)
172
+ rescue ToolTimeout::BudgetExceeded => e
173
+ t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
174
+ dur = ((t1 - t0) * 1000).round(1)
175
+ ToolTimeout.emit_timeout_event(tool_name: tool_instance.name, budget_seconds: e.budget_seconds,
176
+ elapsed_seconds: e.elapsed_seconds, context: @deps.runtime_manager&.context)
177
+ ToolTimeout.timeout_result(tool_name: tool_name, call_id: call_id, exceeded: e, duration_ms: dur)
168
178
  rescue StandardError => e
169
179
  t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
170
180
  dur = ((t1 - t0) * 1000).round(1)
@@ -176,9 +186,9 @@ module Rubik
176
186
  end
177
187
 
178
188
  def normalize_raw_output(raw_output, tool_name, call_id, dur)
179
- max_chars = @deps.shell&.config&.fetch("tools.max_output_chars", 12_000) || 12_000
180
- max_lines = @deps.shell&.config&.fetch("tools.max_output_lines", 300) || 300
181
- trunc_strat = @deps.shell&.config&.fetch("tools.truncation_strategy", "head_tail") || "head_tail"
189
+ max_chars = @deps.shell&.config&.fetch("tools.max_output_chars", Rubik::Tools::Truncator::DEFAULT_MAX_CHARS) || Rubik::Tools::Truncator::DEFAULT_MAX_CHARS
190
+ max_lines = @deps.shell&.config&.fetch("tools.max_output_lines", Rubik::Tools::Truncator::DEFAULT_MAX_LINES) || Rubik::Tools::Truncator::DEFAULT_MAX_LINES
191
+ trunc_strat = Rubik::Tools::Truncator.resolve_strategy(@deps.shell&.config&.fetch("tools.truncation_strategy", Rubik::Tools::Truncator::DEFAULT_STRATEGY))
182
192
 
183
193
  if raw_output.is_a?(Rubik::Tools::Result)
184
194
  trunc_res = Rubik::Tools::Truncator.truncate(raw_output.output, max_chars: max_chars, max_lines: max_lines, strategy: trunc_strat)
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative "../../tools/truncator"
4
4
  require_relative "../../tools/result"
5
+ require_relative "../tool_timeout"
5
6
 
6
7
  module Rubik
7
8
  module Orchestrator
@@ -16,42 +17,70 @@ module Rubik
16
17
  def dispatch_subagent_tool(tool, name, args)
17
18
  return error_result(name, "Tool '#{name}' is not available in subagent toolset.") unless tool
18
19
 
19
- raw = tool.execute(args)
20
- max_chars = (@config.respond_to?(:fetch) ? @config.fetch("tools.max_output_chars", 12_000) : 12_000) || 12_000
21
- max_lines = (@config.respond_to?(:fetch) ? @config.fetch("tools.max_output_lines", 300) : 300) || 300
22
- normalize_tool_result(raw, name, max_chars: max_chars.to_i, max_lines: max_lines.to_i)
20
+ cfg = @config.respond_to?(:fetch) ? @config : nil
21
+ raw = Rubik::Orchestrator::ToolTimeout.call(tool, config: cfg,
22
+ canonical_name: tool.respond_to?(:name) ? tool.name : name) do
23
+ tool.execute(args)
24
+ end
25
+ max_chars = (cfg&.fetch("tools.max_output_chars", Rubik::Tools::Truncator::DEFAULT_MAX_CHARS) || Rubik::Tools::Truncator::DEFAULT_MAX_CHARS).to_i
26
+ max_lines = (cfg&.fetch("tools.max_output_lines", Rubik::Tools::Truncator::DEFAULT_MAX_LINES) || Rubik::Tools::Truncator::DEFAULT_MAX_LINES).to_i
27
+ strategy = Rubik::Tools::Truncator.resolve_strategy(cfg&.fetch("tools.truncation_strategy", Rubik::Tools::Truncator::DEFAULT_STRATEGY))
28
+ normalize_tool_result(raw, name, max_chars: max_chars, max_lines: max_lines, strategy: strategy)
29
+ rescue Rubik::Orchestrator::ToolTimeout::BudgetExceeded => e
30
+ Rubik::Orchestrator::ToolTimeout.emit_timeout_event(tool_name: name, budget_seconds: e.budget_seconds,
31
+ elapsed_seconds: e.elapsed_seconds, context: @context)
32
+ Rubik::Orchestrator::ToolTimeout.timeout_result(tool_name: name, call_id: nil, exceeded: e,
33
+ duration_ms: (e.elapsed_seconds * 1000).round(1))
23
34
  rescue StandardError => e
24
35
  error_result(name, "Tool execution error: #{e.class}: #{e.message}", error: e.message)
25
36
  end
26
37
 
27
38
  private
28
39
 
29
- def normalize_tool_result(raw, name, max_chars:, max_lines:)
40
+ def normalize_tool_result(raw, name, max_chars:, max_lines:, strategy: Rubik::Tools::Truncator::DEFAULT_STRATEGY)
30
41
  if raw.is_a?(Rubik::Tools::Result)
31
- trunc = Rubik::Tools::Truncator.truncate(raw.output, max_chars: max_chars, max_lines: max_lines)
42
+ trunc = Rubik::Tools::Truncator.truncate(raw.output, max_chars: max_chars, max_lines: max_lines, strategy: strategy)
32
43
  # Truncation only shortens the display text — status, exit code,
33
44
  # metadata and the original truncation flag all survive it.
45
+ first_line = raw.output.to_s.lines.first.to_s.strip
34
46
  Rubik::Tools::Result.new(tool_name: raw.tool_name.to_s.empty? ? name : raw.tool_name,
35
- status: raw.status, error: raw.error, exit_code: raw.exit_code,
47
+ status: raw.status,
48
+ error: raw.error || (raw.error? ? first_line : nil), exit_code: raw.exit_code,
36
49
  output: trunc[:text], duration_ms: raw.duration_ms,
37
50
  truncated: raw.truncated || trunc[:truncated], metadata: raw.metadata)
38
51
  elsif raw.respond_to?(:status) && raw.respond_to?(:output)
39
52
  out_str = raw.output.to_s
40
- trunc = Rubik::Tools::Truncator.truncate(out_str, max_chars: max_chars, max_lines: max_lines)
41
- Rubik::Tools::Result.new(tool_name: name, status: raw.status.to_sym, output: trunc[:text],
42
- truncated: trunc[:truncated],
53
+ trunc = Rubik::Tools::Truncator.truncate(out_str, max_chars: max_chars, max_lines: max_lines, strategy: strategy)
54
+ first_line = out_str.lines.first.to_s.strip
55
+ status = raw.status.to_sym
56
+ Rubik::Tools::Result.new(tool_name: name, status: status,
57
+ error: (raw.respond_to?(:error) && raw.error) || (status == :error ? first_line : nil),
58
+ output: trunc[:text], truncated: trunc[:truncated],
43
59
  exit_code: raw.respond_to?(:exit_code) ? raw.exit_code : nil,
44
60
  metadata: raw.respond_to?(:metadata) ? raw.metadata : {})
45
61
  else
46
62
  out_str = raw.to_s
47
- trunc = Rubik::Tools::Truncator.truncate(out_str, max_chars: max_chars, max_lines: max_lines)
48
- status = raw.respond_to?(:error?) && raw.error? ? :error : :ok
63
+ trunc = Rubik::Tools::Truncator.truncate(out_str, max_chars: max_chars, max_lines: max_lines, strategy: strategy)
64
+ status = classify_raw_string(raw, out_str)
49
65
  Rubik::Tools::Result.new(tool_name: name, status: status,
50
66
  error: status == :error ? out_str.lines.first.to_s.strip : nil,
51
67
  output: trunc[:text], truncated: trunc[:truncated])
52
68
  end
53
69
  end
54
70
 
71
+ # Root-parity string classification (arch scan card 5, review F1): the
72
+ # same lexicon as StepExecutor#normalize_raw_output's else branch —
73
+ # error?/failed? predicates, then the shared ERROR_PREFIXES table.
74
+ # Without this, a bare "Error: ..." string reads status=ok in subagent
75
+ # history while the root plane honestly reports :error.
76
+ def classify_raw_string(raw, out_str)
77
+ return :error if raw.respond_to?(:error?) && raw.error?
78
+ return :error if raw.respond_to?(:failed?) && raw.failed?
79
+ return :error if raw.is_a?(String) && Rubik::Orchestrator::StepExecutor::ERROR_PREFIXES.any? { |pfx| out_str.start_with?(pfx) }
80
+
81
+ :ok
82
+ end
83
+
55
84
  def error_result(name, text, error: nil)
56
85
  Rubik::Tools::Result.new(tool_name: name, status: :error, output: text, error: error || text)
57
86
  end