rubik 0.7.1 → 0.8.1

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 (78) hide show
  1. checksums.yaml +4 -4
  2. data/ATTRIBUTION.md +1 -1
  3. data/CHANGELOG.md +205 -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 +5 -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/parser.rb +2 -2
  15. data/lib/rubik/kernel/dispatcher.rb +19 -23
  16. data/lib/rubik/kernel/init.rb +22 -18
  17. data/lib/rubik/orchestrator/goal_ledger/ledger.rb +3 -9
  18. data/lib/rubik/orchestrator/goal_ledger/observation_projection.rb +3 -9
  19. data/lib/rubik/orchestrator/step_executor.rb +12 -59
  20. data/lib/rubik/orchestrator/subagent/deferred_spec.rb +51 -2
  21. data/lib/rubik/orchestrator/subagent/dependency.rb +20 -20
  22. data/lib/rubik/orchestrator/subagent/execution_reads.rb +1 -1
  23. data/lib/rubik/orchestrator/subagent/journal.rb +3 -9
  24. data/lib/rubik/orchestrator/subagent/lifecycle.rb +10 -1
  25. data/lib/rubik/orchestrator/subagent/paging.rb +49 -0
  26. data/lib/rubik/orchestrator/subagent/reaper.rb +1 -3
  27. data/lib/rubik/orchestrator/subagent/redeploy_transaction.rb +99 -0
  28. data/lib/rubik/orchestrator/subagent/result_archive.rb +12 -22
  29. data/lib/rubik/orchestrator/subagent/reuse.rb +37 -31
  30. data/lib/rubik/orchestrator/subagent/scoped_registry.rb +14 -23
  31. data/lib/rubik/orchestrator/subagent/spawn_transaction.rb +13 -3
  32. data/lib/rubik/orchestrator/subagent/supervisor.rb +6 -2
  33. data/lib/rubik/orchestrator/subagent/task_ownership.rb +2 -2
  34. data/lib/rubik/orchestrator/subagent/tool_dispatch.rb +12 -49
  35. data/lib/rubik/orchestrator/subagent/transcript_reader.rb +14 -13
  36. data/lib/rubik/orchestrator/turn_executor.rb +9 -4
  37. data/lib/rubik/repl/commands/subagents.rb +3 -2
  38. data/lib/rubik/repl/commands/workspace.rb +14 -8
  39. data/lib/rubik/repl/lifecycle.rb +11 -0
  40. data/lib/rubik/repl/pruner/service.rb +4 -9
  41. data/lib/rubik/repl/service_catalog.rb +2 -1
  42. data/lib/rubik/runtime/context.rb +6 -1
  43. data/lib/rubik/runtime/fiber.rb +17 -5
  44. data/lib/rubik/runtime/manager.rb +19 -12
  45. data/lib/rubik/sandbox/runner.rb +28 -13
  46. data/lib/rubik/storage/layout.rb +14 -3
  47. data/lib/rubik/storage/render.rb +1 -1
  48. data/lib/rubik/storage/vakanuvis/distill_gate.rb +3 -3
  49. data/lib/rubik/storage/vakanuvis/harness.rb +4 -65
  50. data/lib/rubik/storage/vakanuvis/orientation.rb +1 -2
  51. data/lib/rubik/storage/vakanuvis/recall.rb +84 -0
  52. data/lib/rubik/storage/vakanuvis.rb +1 -0
  53. data/lib/rubik/tools/base.rb +65 -0
  54. data/lib/rubik/tools/builtins/define_subagent.rb +6 -0
  55. data/lib/rubik/tools/builtins/dmesg.rb +5 -5
  56. data/lib/rubik/tools/builtins/exec.rb +1 -2
  57. data/lib/rubik/tools/builtins/files.rb +19 -25
  58. data/lib/rubik/tools/builtins/goal_ledger.rb +2 -2
  59. data/lib/rubik/tools/builtins/grep.rb +8 -8
  60. data/lib/rubik/tools/builtins/interactive.rb +7 -3
  61. data/lib/rubik/tools/builtins/lifecycle.rb +2 -1
  62. data/lib/rubik/tools/builtins/lsp.rb +2 -2
  63. data/lib/rubik/tools/builtins/pruner.rb +2 -2
  64. data/lib/rubik/tools/builtins/runtime.rb +1 -1
  65. data/lib/rubik/tools/builtins/send_message.rb +20 -3
  66. data/lib/rubik/tools/builtins/skill.rb +1 -1
  67. data/lib/rubik/tools/builtins/storage.rb +1 -1
  68. data/lib/rubik/tools/builtins/subagent.rb +14 -1
  69. data/lib/rubik/tools/builtins/subagent_lifecycle.rb +5 -3
  70. data/lib/rubik/tools/builtins/symbols.rb +4 -4
  71. data/lib/rubik/tools/builtins/task.rb +1 -1
  72. data/lib/rubik/tools/builtins/vakanuvis.rb +2 -2
  73. data/lib/rubik/tools/catalog.rb +19 -0
  74. data/lib/rubik/tools/declaration.rb +15 -2
  75. data/lib/rubik/tools/result_normalizer.rb +115 -0
  76. data/lib/rubik/tools/truncator.rb +3 -3
  77. data/lib/rubik/version.rb +1 -1
  78. metadata +9 -1
@@ -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)" } } }
@@ -20,11 +20,11 @@ module Rubik
20
20
  end
21
21
 
22
22
  def effective_lsp_manager
23
- Rubik::Coeffects.resolve(@runtime_context, Rubik::Coeffects::LSP_MANAGER, @lsp_manager)
23
+ service(:lsp_manager, @lsp_manager)
24
24
  end
25
25
 
26
26
  def effective_buffer_manager
27
- @buffer_manager || Rubik::Coeffects.resolve(@runtime_context, Rubik::Coeffects::BUFFER_MANAGER, nil)
27
+ service(:buffer_manager, @buffer_manager)
28
28
  end
29
29
 
30
30
  private
@@ -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",
@@ -49,7 +49,7 @@ module Rubik
49
49
 
50
50
  def execute(args = {})
51
51
  action = (args["action"] || args[:action] || "status").to_s
52
- harness = Rubik::Coeffects.resolve(@runtime_context, Rubik::Coeffects::PRUNER, @harness)
52
+ harness = service(:pruner, @harness)
53
53
  unless harness
54
54
  return ToolOutput.error("Context pruner is not available: disabled by config " \
55
55
  "(subagents.pruner.enabled=false) or the harness is not wired " \
@@ -63,7 +63,7 @@ module Rubik
63
63
  cmds.sort.each { |name, meta| lines << " !#{name.ljust(16)} : #{meta[:description]}" }
64
64
  end
65
65
 
66
- task_mgr = (Rubik::Coeffects.get(@runtime_manager.context, Rubik::Coeffects::TASK_MANAGER) if @runtime_manager&.context.respond_to?(:get))
66
+ task_mgr = service(:task_manager)
67
67
  task_mgr ||= @shell.task_manager if @shell.respond_to?(:task_manager)
68
68
 
69
69
  if ["all", "tasks"].include?(target) && task_mgr
@@ -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
@@ -66,6 +72,19 @@ module Rubik
66
72
  return delivery_text(recipient) if delivered == true
67
73
  return queued_text(recipient, steps) if delivered == :queued
68
74
 
75
+ # A dependency-queued (or launching) spec exists but has never run:
76
+ # "not found" is false, and the redeploy suggestion below would
77
+ # refuse the same id — the model needs the truthful next action.
78
+ if sup.respond_to?(:get) && (spec = sup.get(recipient)) && spec.respond_to?(:queued?) &&
79
+ (spec.queued? || spec.spawning?)
80
+ return ToolOutput.error(
81
+ "Subagent '#{recipient}' is dependency-queued (deps: #{spec.depends_on.join(', ')}) and will " \
82
+ "launch automatically when its predecessors settle. Messages cannot be buffered on an unborn " \
83
+ "spec — re-send after it launches, or kill it with manage_subagents(action: 'kill', " \
84
+ "conversation_id: '#{recipient}') if the wait is no longer worth it."
85
+ )
86
+ end
87
+
69
88
  ToolOutput.error(
70
89
  "Subagent '#{recipient}' not found or no longer active. If it recently finished, redeploy it with its " \
71
90
  "context intact: manage_subagents(action: 'redeploy', conversation_id: '#{recipient}', prompt: '<task>') " \
@@ -78,9 +97,7 @@ module Rubik
78
97
  # Subagent düzlemi (rebound araç): gönderen coeffect'i GERÇEK subagent
79
98
  # id'sidir. Kök düzleminde sağlanmaz → Supervisor default'u kalır.
80
99
  def subagent_sender_id
81
- return nil unless @runtime_context.respond_to?(:get)
82
-
83
- Rubik::Coeffects.get(@runtime_context, Rubik::Coeffects::SUBAGENT_SENDER_ID)
100
+ service(:subagent_sender_id)
84
101
  end
85
102
 
86
103
  # Kök alias'ına giden mesajın yanıtı kök kişisiyle konuşur ("the
@@ -45,7 +45,7 @@ module Rubik
45
45
  end
46
46
 
47
47
  def execute(args = {})
48
- manager = Rubik::Coeffects.resolve(@runtime_context, Rubik::Coeffects::SKILL_MANAGER, @manager)
48
+ manager = service(:skill_manager, @manager)
49
49
  return ToolOutput.error("Error: skills manager is not available.") unless manager
50
50
  return ToolOutput.error("Error: skills are disabled (skills.enabled = false).") unless manager.enabled?
51
51
 
@@ -102,7 +102,7 @@ module Rubik
102
102
  # STORAGE_STORE coeffect'i (parent chain — subagent'lar buradan çözer)
103
103
  # → config'e dayalı tembel fresh default (storage kapalıysa nil).
104
104
  def resolve_store
105
- resolved = Rubik::Coeffects.resolve(@runtime_context, Rubik::Coeffects::STORAGE_STORE, @store)
105
+ resolved = service(:storage_store, @store)
106
106
  return resolved if resolved
107
107
 
108
108
  @resolve_store ||= Rubik::Storage::Service.build(config: @config, root_dir: @root_dir)
@@ -16,6 +16,7 @@ module Rubik
16
16
  module SubagentToolHelpers
17
17
  def resolve_supervisor(supervisor, runtime_context)
18
18
  return supervisor if supervisor
19
+ return service(:subagent_supervisor, ctx: runtime_context) if respond_to?(:service)
19
20
  return nil unless runtime_context.respond_to?(:get)
20
21
 
21
22
  Rubik::Coeffects.get(runtime_context, Rubik::Coeffects::SUBAGENT_SUPERVISOR)
@@ -83,6 +84,12 @@ module Rubik
83
84
  @runtime_context = runtime_context
84
85
  end
85
86
 
87
+ # Subagent-plane rebind (ScopedRegistry delegate): a nested spawn must
88
+ # resolve the INSTANCE's task token (issue #125), not the root turn's.
89
+ def rebind_to(ctx)
90
+ self.class.new(supervisor: resolve_supervisor(nil, ctx), runtime_context: ctx)
91
+ end
92
+
86
93
  def execute(args = {})
87
94
  sup = resolve_supervisor(@supervisor, @runtime_context)
88
95
  return ToolOutput.error("SubagentSupervisor is not available in runtime context.") unless sup
@@ -93,7 +100,7 @@ module Rubik
93
100
  # Task ownership (issue #125): the spawning context's token owns the new
94
101
  # work (detached specs opt out per spec). Resolved at call time, so a
95
102
  # nested subagent inherits its ancestor's task through its child ctx.
96
- owner = Rubik::Coeffects.get(@runtime_context, Rubik::Coeffects::TASK_CANCELLATION)
103
+ owner = service(:task_cancellation)
97
104
 
98
105
  begin
99
106
  results = sup.spawn_batch(specs, owner: owner)
@@ -203,6 +210,12 @@ module Rubik
203
210
  @runtime_context = runtime_context
204
211
  end
205
212
 
213
+ # Subagent-plane rebind (ScopedRegistry delegate): manage actions target
214
+ # the INSTANCE's supervisor, not the root turn's (issue #125).
215
+ def rebind_to(ctx)
216
+ self.class.new(supervisor: resolve_supervisor(nil, ctx), runtime_context: ctx)
217
+ end
218
+
206
219
  def execute(args = {})
207
220
  sup = resolve_supervisor(@supervisor, @runtime_context)
208
221
  return ToolOutput.error("SubagentSupervisor is not available in runtime context.") unless sup
@@ -113,8 +113,10 @@ module Rubik
113
113
 
114
114
  # Blocked states that need maestro action before their chain proceeds
115
115
  # (bug-llm-timeout-observability ④): a bare JSON list made a stalled
116
- # subagent indistinguishable from a healthy one at a glance.
117
- ATTENTION_STATES = [:paused_error, :waiting_budget, :budget_exhausted, :waiting_input].freeze
116
+ # subagent indistinguishable from a healthy one at a glance. The set
117
+ # itself is owned by Lifecycle (ATTENTION_STATES beside TRANSITIONS) —
118
+ # this file used to hand-copy it.
119
+ def attention_states = Rubik::Orchestrator::Subagent::Lifecycle::ATTENTION_STATES
118
120
 
119
121
  # List with a prominent attention block: any blocked subagent is called
120
122
  # out ABOVE the JSON with its state, last error, and the exact recovery
@@ -124,7 +126,7 @@ module Rubik
124
126
  return "No active or tracked subagents." if instances.empty?
125
127
 
126
128
  lines = []
127
- attention = instances.select { |i| ATTENTION_STATES.include?(i.state.to_sym) }
129
+ attention = instances.select { |i| attention_states.include?(i.state.to_sym) }
128
130
  if attention.any?
129
131
  lines << "⚠ #{attention.size} subagent(s) need attention:"
130
132
  attention.each do |i|
@@ -30,7 +30,7 @@ module Rubik
30
30
  end
31
31
 
32
32
  def ast_graph
33
- Rubik::Coeffects.resolve(@runtime_context, Rubik::Coeffects::AST_GRAPH, @ast_graph)
33
+ service(:ast_graph, @ast_graph)
34
34
  end
35
35
 
36
36
  def execute(args = {})
@@ -96,7 +96,7 @@ module Rubik
96
96
  end
97
97
 
98
98
  def ast_graph
99
- Rubik::Coeffects.resolve(@runtime_context, Rubik::Coeffects::AST_GRAPH, @ast_graph)
99
+ service(:ast_graph, @ast_graph)
100
100
  end
101
101
 
102
102
  def execute(args = {})
@@ -146,7 +146,7 @@ module Rubik
146
146
  end
147
147
 
148
148
  def ast_graph
149
- Rubik::Coeffects.resolve(@runtime_context, Rubik::Coeffects::AST_GRAPH, @ast_graph)
149
+ service(:ast_graph, @ast_graph)
150
150
  end
151
151
 
152
152
  def execute(args = {})
@@ -201,7 +201,7 @@ module Rubik
201
201
  end
202
202
 
203
203
  def ast_graph
204
- Rubik::Coeffects.resolve(@runtime_context, Rubik::Coeffects::AST_GRAPH, @ast_graph)
204
+ service(:ast_graph, @ast_graph)
205
205
  end
206
206
 
207
207
  def execute(args = {})
@@ -72,7 +72,7 @@ module Rubik
72
72
  private
73
73
 
74
74
  def resolve_task_manager
75
- @task_manager || (@runtime_context.respond_to?(:get) ? Rubik::Coeffects.get(@runtime_context, Rubik::Coeffects::TASK_MANAGER) : nil)
75
+ service(:task_manager)
76
76
  end
77
77
 
78
78
  def extract_task_id(args)
@@ -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",
@@ -75,7 +75,7 @@ module Rubik
75
75
 
76
76
  def execute(args = {})
77
77
  action = (args["action"] || args[:action] || "recall").to_s
78
- harness = Rubik::Coeffects.resolve(@runtime_context, Rubik::Coeffects::VAKANUIS, @harness)
78
+ harness = service(:vakanuvis, @harness)
79
79
  unless harness
80
80
  return ToolOutput.error("Vakanüvis chronicler is not available: disabled by config " \
81
81
  "(subagents.vakanuvis.enabled=false) or no store wired.")
@@ -43,6 +43,15 @@ module Rubik
43
43
  SPAWN_TOOLS = DECLARATIONS.select(&:spawn?).map(&:name).sort.freeze
44
44
  WRITE_GRANT_TOOLS = DECLARATIONS.select(&:write_grant?).map(&:name).sort.freeze
45
45
  MAESTRO_BLOCKED_TOOLS = DECLARATIONS.select(&:maestro_blocked?).map(&:name).sort.freeze
46
+ # Orchestrator-plane-only membership, declared per tool (root_only:)
47
+ # and projected here — never restated as a remote hand-list. The set
48
+ # is NOT derivable from archetypes/risk: archetype-less writers also
49
+ # include the synthesis family, which subagent registries legitimately
50
+ # carry; only orchestration-memory writers (goal ledger, session
51
+ # chronicle, pruner queue) are root-locked.
52
+ ORCHESTRATOR_ONLY_TOOLS = DECLARATIONS.select(&:root_only?).map(&:name).sort.freeze
53
+ BUFFER_BOUND_TOOLS = DECLARATIONS.select(&:buffer_bound?).map(&:name).sort.freeze
54
+ TERMINAL_TOOLS = DECLARATIONS.select(&:terminal?).map(&:name).sort.freeze
46
55
 
47
56
  module_function
48
57
 
@@ -65,6 +74,16 @@ module Rubik
65
74
  def maestro_blocked_tools = MAESTRO_BLOCKED_TOOLS
66
75
 
67
76
  def maestro_blocked?(name) = MAESTRO_BLOCKED_TOOLS.include?(name.to_s)
77
+
78
+ def orchestrator_only_tools = ORCHESTRATOR_ONLY_TOOLS
79
+
80
+ def buffer_bound_tools = BUFFER_BOUND_TOOLS
81
+
82
+ def buffer_bound?(name) = BUFFER_BOUND_TOOLS.include?(name.to_s)
83
+
84
+ def terminal_tools = TERMINAL_TOOLS
85
+
86
+ def terminal?(name) = TERMINAL_TOOLS.include?(name.to_s)
68
87
  end
69
88
  end
70
89
  end
@@ -19,11 +19,15 @@ module Rubik
19
19
  :subagent_spawn, # bool — member of the spawn set (self-archetype recursion guard)
20
20
  :write_grant, # bool — denied to custom types lacking enable_write_tools
21
21
  :maestro_blocked, # true | false | nil — gate class; MUST be explicit for :write/:execute
22
+ :buffer_bound, # bool — instance reads a branch buffer; rebuilt when a plane split rebinds it
23
+ :root_only, # bool — orchestration-memory writer; never copied into a subagent registry
24
+ :terminal, # bool — turn completion signal; dispatchers route it before gates/malformed handling
22
25
  keyword_init: true
23
26
  ) do
24
27
  def initialize(name:, description:, risk: :read, params_schema: {}, aliases: [],
25
28
  allow_additional_properties: true, archetypes: [], subagent_spawn: false,
26
- write_grant: false, maestro_blocked: nil)
29
+ write_grant: false, maestro_blocked: nil, buffer_bound: false, root_only: false,
30
+ terminal: false)
27
31
  clean_name = name.to_s
28
32
  # Leading digits are tolerated (not required) for legacy dynamic
29
33
  # tools: synthesis/overlay normalize to lowercase snake but do not
@@ -69,7 +73,10 @@ module Rubik
69
73
  nil
70
74
  else
71
75
  (maestro_blocked ? true : false)
72
- end
76
+ end,
77
+ buffer_bound: buffer_bound ? true : false,
78
+ root_only: root_only ? true : false,
79
+ terminal: terminal ? true : false
73
80
  )
74
81
  freeze
75
82
  end
@@ -85,6 +92,12 @@ module Rubik
85
92
  def spawn? = subagent_spawn == true
86
93
 
87
94
  def write_grant? = write_grant == true
95
+
96
+ def buffer_bound? = buffer_bound == true
97
+
98
+ def root_only? = root_only == true
99
+
100
+ def terminal? = terminal == true
88
101
  end
89
102
  end
90
103
  end
@@ -0,0 +1,115 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "truncator"
4
+ require_relative "result"
5
+
6
+ module Rubik
7
+ module Tools
8
+ # Single home for tool-output carrier normalization: every tool outcome —
9
+ # Result-backed, status-bearing duck object, or plain string — is
10
+ # normalized into the Result contract here, and both orchestrator planes
11
+ # (StepExecutor root, Subagent ToolDispatch) delegate to this one
12
+ # implementation instead of maintaining parallel copies.
13
+ #
14
+ # Plane differences are caller-supplied parameters, not divergent logic:
15
+ # the root plane passes its measured wall time and the tool-call id; the
16
+ # subagent plane leaves both nil.
17
+ module ResultNormalizer
18
+ # Carrier strings whose first-line presence marks an otherwise opaque
19
+ # string result as an error. Shared lexicon; referenced by tests via
20
+ # StepExecutor::ERROR_PREFIXES (kept as an alias there).
21
+ ERROR_PREFIXES = [
22
+ "-- ", "Error:", "Error ", "Usage:", "Pre-flight verification failed",
23
+ "Bilinmeyen komut", "Failed", "Security blocked", "Command error",
24
+ "[EXIT ", "Test run [FAILED]", "Lint [FAILED]", "[CONFLICT]", "[CONFLICT "
25
+ ].freeze
26
+
27
+ # Truncation knob trio (chars, lines, strategy) from a config object;
28
+ # nil / non-fetchable configs fall back to Truncator defaults. A
29
+ # non-nil config that cannot fetch warns once before falling back —
30
+ # operator-set limits must never be dropped in silence.
31
+ def self.limits(config)
32
+ cfg = config.respond_to?(:fetch) ? config : nil
33
+ warn_once(config.class) if cfg.nil? && !config.nil?
34
+ max_chars = cfg&.fetch("tools.max_output_chars", Truncator::DEFAULT_MAX_CHARS) || Truncator::DEFAULT_MAX_CHARS
35
+ max_lines = cfg&.fetch("tools.max_output_lines", Truncator::DEFAULT_MAX_LINES) || Truncator::DEFAULT_MAX_LINES
36
+ strategy = Truncator.resolve_strategy(cfg&.fetch("tools.truncation_strategy", Truncator::DEFAULT_STRATEGY))
37
+ [max_chars, max_lines, strategy]
38
+ end
39
+
40
+ # One warning per process per config class; a warn per tool result
41
+ # would be exactly the stderr storm the truncation warn doctrine bans.
42
+ def self.warn_once(klass)
43
+ @warned ||= {}
44
+ return if @warned[klass]
45
+
46
+ @warned[klass] = true
47
+ Rubik::Log.warn(:tools, "tools truncation knobs skipped: config object of class #{klass} does not respond to fetch; using Truncator defaults")
48
+ end
49
+
50
+ # duration_ms: caller-measured wall time (nil on the subagent plane).
51
+ # call_id: caller's tool-call id (nil on the subagent plane).
52
+ def self.normalize(raw, tool_name:, call_id: nil, duration_ms: nil, config: nil)
53
+ max_chars, max_lines, strategy = limits(config)
54
+
55
+ if raw.is_a?(Result)
56
+ trunc = Truncator.truncate(raw.output, max_chars: max_chars, max_lines: max_lines, strategy: strategy)
57
+ # Truncation only shortens the display text — status, exit code,
58
+ # metadata and the original truncation flag all survive it.
59
+ effective_dur = raw.duration_ms.positive? ? raw.duration_ms : duration_ms.to_f
60
+ first_line = first_line_of(raw.output)
61
+ Result.new(
62
+ tool_name: raw.tool_name.to_s.empty? ? tool_name : raw.tool_name,
63
+ call_id: raw.call_id.to_s.empty? ? call_id : raw.call_id,
64
+ status: raw.status, error: raw.error || (raw.error? ? first_line : nil),
65
+ # Structured fields ride along when the tool provides them
66
+ # (issue #127): the same Result contract for every carrier.
67
+ exit_code: raw.exit_code, output: trunc[:text], duration_ms: effective_dur,
68
+ truncated: raw.truncated || trunc[:truncated], metadata: raw.metadata
69
+ )
70
+ elsif raw.respond_to?(:status) && raw.respond_to?(:output)
71
+ out_str = raw.output.to_s
72
+ trunc = Truncator.truncate(out_str, max_chars: max_chars, max_lines: max_lines, strategy: strategy)
73
+ status = raw.status.to_sym
74
+ first_line = first_line_of(out_str)
75
+ err = (raw.respond_to?(:error) && raw.error) || (status == :error ? first_line : nil)
76
+ Result.new(
77
+ tool_name: tool_name, call_id: call_id, status: status, error: err, output: trunc[:text],
78
+ duration_ms: duration_ms.to_f, truncated: trunc[:truncated],
79
+ exit_code: raw.respond_to?(:exit_code) ? raw.exit_code : nil,
80
+ metadata: raw.respond_to?(:metadata) ? raw.metadata : {}
81
+ )
82
+ else
83
+ out_str = raw.to_s
84
+ trunc = Truncator.truncate(out_str, max_chars: max_chars, max_lines: max_lines, strategy: strategy)
85
+ # elsif chain (not two independent checks): a carrier answering
86
+ # error? takes that verdict even when failed? would disagree —
87
+ # root-plane precedence, pinned by the hardening tests.
88
+ is_err = if raw.respond_to?(:error?)
89
+ raw.error?
90
+ elsif raw.respond_to?(:failed?)
91
+ raw.failed?
92
+ elsif raw.is_a?(String)
93
+ ERROR_PREFIXES.any? { |pfx| out_str.start_with?(pfx) }
94
+ else
95
+ false
96
+ end
97
+
98
+ first_line = first_line_of(out_str)
99
+ Result.new(
100
+ tool_name: tool_name, call_id: call_id, status: is_err ? :error : :ok,
101
+ error: is_err ? first_line : nil, output: trunc[:text],
102
+ duration_ms: duration_ms.to_f, truncated: trunc[:truncated]
103
+ )
104
+ end
105
+ end
106
+
107
+ # A blank first line carries no diagnostic value: nil it so error
108
+ # fields never hold "" (pinned by the empty-output hardening test).
109
+ def self.first_line_of(text)
110
+ line = text.lines.first.to_s.strip
111
+ line.empty? ? nil : line
112
+ end
113
+ end
114
+ end
115
+ end
@@ -5,9 +5,9 @@ module Rubik
5
5
  module Truncator
6
6
  DEFAULT_MAX_CHARS = 12_000
7
7
  DEFAULT_MAX_LINES = 300
8
- # The strategy knob's default lives here (arch scan card 5, 2026-11-01):
9
- # both orchestrator planes read tools.truncation_strategy with this
10
- # fallback — one literal for the whole repo instead of restated copies.
8
+ # The strategy knob's default lives here: both orchestrator planes read
9
+ # tools.truncation_strategy with this fallback — one literal for the
10
+ # whole repo instead of restated copies.
11
11
  DEFAULT_STRATEGY = :head_tail
12
12
  # Known-strategy set (issue #349): a typo'd config value used to die
13
13
  # silently into the head_tail `else` branch in both planes. This set
data/lib/rubik/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rubik
4
- VERSION = "0.7.1"
4
+ VERSION = "0.8.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubik
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Özgür Ulukır
@@ -289,7 +289,11 @@ files:
289
289
  - lib/rubik/config.rb
290
290
  - lib/rubik/config/deep_ops.rb
291
291
  - lib/rubik/config/defaults.rb
292
+ - lib/rubik/config/env_loader.rb
292
293
  - lib/rubik/config/model_catalog.rb
294
+ - lib/rubik/config/pruner.rb
295
+ - lib/rubik/config/schema.rb
296
+ - lib/rubik/config/scoped.rb
293
297
  - lib/rubik/config/store.rb
294
298
  - lib/rubik/context.rb
295
299
  - lib/rubik/context/git_info.rb
@@ -378,10 +382,12 @@ files:
378
382
  - lib/rubik/orchestrator/subagent/narration.rb
379
383
  - lib/rubik/orchestrator/subagent/notices.rb
380
384
  - lib/rubik/orchestrator/subagent/operation_tracker.rb
385
+ - lib/rubik/orchestrator/subagent/paging.rb
381
386
  - lib/rubik/orchestrator/subagent/profile_contract.rb
382
387
  - lib/rubik/orchestrator/subagent/profile_snapshot.rb
383
388
  - lib/rubik/orchestrator/subagent/questioner.rb
384
389
  - lib/rubik/orchestrator/subagent/reaper.rb
390
+ - lib/rubik/orchestrator/subagent/redeploy_transaction.rb
385
391
  - lib/rubik/orchestrator/subagent/resilience.rb
386
392
  - lib/rubik/orchestrator/subagent/result_archive.rb
387
393
  - lib/rubik/orchestrator/subagent/reuse.rb
@@ -726,6 +732,7 @@ files:
726
732
  - lib/rubik/storage/vakanuvis/job.rb
727
733
  - lib/rubik/storage/vakanuvis/memory_steward.rb
728
734
  - lib/rubik/storage/vakanuvis/orientation.rb
735
+ - lib/rubik/storage/vakanuvis/recall.rb
729
736
  - lib/rubik/storage/vakanuvis/service.rb
730
737
  - lib/rubik/storage/vakanuvis/vocabulary.rb
731
738
  - lib/rubik/storage/vakanuvis/wiki_skeleton.rb
@@ -764,6 +771,7 @@ files:
764
771
  - lib/rubik/tools/preflight_runner.rb
765
772
  - lib/rubik/tools/registry.rb
766
773
  - lib/rubik/tools/result.rb
774
+ - lib/rubik/tools/result_normalizer.rb
767
775
  - lib/rubik/tools/services.rb
768
776
  - lib/rubik/tools/symbol_tool_support.rb
769
777
  - lib/rubik/tools/truncator.rb