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.
- checksums.yaml +4 -4
- data/ATTRIBUTION.md +1 -1
- data/CHANGELOG.md +177 -1
- data/lib/rubik/ast/typescript_extractor.rb +2 -2
- data/lib/rubik/config/deep_ops.rb +14 -0
- data/lib/rubik/config/defaults.rb +6 -4
- data/lib/rubik/config/env_loader.rb +88 -0
- data/lib/rubik/config/model_catalog.rb +13 -0
- data/lib/rubik/config/pruner.rb +34 -0
- data/lib/rubik/config/schema.rb +163 -0
- data/lib/rubik/config/scoped.rb +108 -0
- data/lib/rubik/config/store.rb +19 -8
- data/lib/rubik/config.rb +129 -53
- data/lib/rubik/diagnostics/collector.rb +8 -2
- data/lib/rubik/diagnostics/parser.rb +2 -2
- data/lib/rubik/lsp/client.rb +26 -6
- data/lib/rubik/lsp/manager.rb +24 -6
- data/lib/rubik/orchestrator/lsp_feedback.rb +2 -1
- data/lib/rubik/orchestrator/step_executor.rb +12 -59
- data/lib/rubik/orchestrator/subagent/scoped_registry.rb +14 -23
- data/lib/rubik/orchestrator/subagent/spawn_transaction.rb +12 -2
- data/lib/rubik/orchestrator/subagent/tool_dispatch.rb +12 -49
- data/lib/rubik/orchestrator/turn_executor.rb +9 -4
- data/lib/rubik/repl/commands/lsp.rb +13 -1
- data/lib/rubik/repl/commands/workspace.rb +14 -8
- data/lib/rubik/repl/lifecycle.rb +11 -0
- data/lib/rubik/repl/service_catalog.rb +2 -1
- data/lib/rubik/repl/shell.rb +1 -0
- data/lib/rubik/runtime/context.rb +12 -14
- data/lib/rubik/runtime/discovery.rb +1 -0
- data/lib/rubik/sandbox/runner.rb +28 -13
- data/lib/rubik/storage/render.rb +1 -1
- data/lib/rubik/storage/vakanuvis/distill_gate.rb +3 -3
- data/lib/rubik/storage/vakanuvis/harness.rb +4 -65
- data/lib/rubik/storage/vakanuvis/orientation.rb +1 -2
- data/lib/rubik/storage/vakanuvis/recall.rb +84 -0
- data/lib/rubik/storage/vakanuvis.rb +1 -0
- data/lib/rubik/tools/base.rb +34 -0
- data/lib/rubik/tools/builtins/define_subagent.rb +6 -0
- data/lib/rubik/tools/builtins/dmesg.rb +4 -4
- data/lib/rubik/tools/builtins/files.rb +18 -24
- data/lib/rubik/tools/builtins/goal_ledger.rb +1 -1
- data/lib/rubik/tools/builtins/grep.rb +6 -6
- data/lib/rubik/tools/builtins/interactive.rb +6 -0
- data/lib/rubik/tools/builtins/lifecycle.rb +2 -1
- data/lib/rubik/tools/builtins/lsp.rb +127 -110
- data/lib/rubik/tools/builtins/pruner.rb +1 -1
- data/lib/rubik/tools/builtins/send_message.rb +6 -0
- data/lib/rubik/tools/builtins/subagent.rb +12 -0
- data/lib/rubik/tools/builtins/vakanuvis.rb +1 -1
- data/lib/rubik/tools/catalog.rb +20 -1
- data/lib/rubik/tools/declaration.rb +15 -2
- data/lib/rubik/tools/registry.rb +6 -5
- data/lib/rubik/tools/result_normalizer.rb +115 -0
- data/lib/rubik/tools/truncator.rb +3 -3
- data/lib/rubik/version.rb +1 -1
- metadata +7 -1
|
@@ -8,6 +8,7 @@ require_relative "tool_circuit_breaker"
|
|
|
8
8
|
require_relative "tool_timeout"
|
|
9
9
|
require_relative "maestro_gate"
|
|
10
10
|
require_relative "lsp_feedback"
|
|
11
|
+
require_relative "../tools/result_normalizer"
|
|
11
12
|
|
|
12
13
|
module Rubik
|
|
13
14
|
module Orchestrator
|
|
@@ -19,11 +20,10 @@ module Rubik
|
|
|
19
20
|
class StepExecutor
|
|
20
21
|
include MaestroGate
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
].freeze
|
|
23
|
+
# Single home is Tools::ResultNormalizer; this alias keeps the
|
|
24
|
+
# historical constant address (tests reference it) while the lexicon
|
|
25
|
+
# is owned by the shared normalizer both planes delegate to.
|
|
26
|
+
ERROR_PREFIXES = Rubik::Tools::ResultNormalizer::ERROR_PREFIXES
|
|
27
27
|
|
|
28
28
|
# Plan 87 E-1: state is reached through the ShellDeps façade. Accepts a
|
|
29
29
|
# bare loop for compatibility with existing test doubles (wrapped).
|
|
@@ -46,7 +46,9 @@ module Rubik
|
|
|
46
46
|
@deps.on_step&.call(type: :auto_apply, reason: "pre_execution", files: applied, step: @deps.step_count, max_steps: @deps.max_steps)
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
finish_call = (tool_instance.respond_to?(:terminal?) && tool_instance.terminal?) ||
|
|
50
|
+
canonical_name == "finish" # unresolved case variant degrades to the name compare
|
|
51
|
+
return handle_finish_tool(tool_args, text_resp, auto_apply_mode) if finish_call
|
|
50
52
|
|
|
51
53
|
# Maestro gate: maestro'nun doğrudan yürütme araçları reddedilir
|
|
52
54
|
# (detay ve config semantics: maestro_gate.rb).
|
|
@@ -185,60 +187,11 @@ module Rubik
|
|
|
185
187
|
[raw_output, tool_result]
|
|
186
188
|
end
|
|
187
189
|
|
|
190
|
+
# Thin delegator: carrier classification and truncation limits live in
|
|
191
|
+
# Tools::ResultNormalizer (single home for both orchestrator planes).
|
|
188
192
|
def normalize_raw_output(raw_output, tool_name, call_id, dur)
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
trunc_strat = Rubik::Tools::Truncator.resolve_strategy(@deps.shell&.config&.fetch("tools.truncation_strategy", Rubik::Tools::Truncator::DEFAULT_STRATEGY))
|
|
192
|
-
|
|
193
|
-
if raw_output.is_a?(Rubik::Tools::Result)
|
|
194
|
-
trunc_res = Rubik::Tools::Truncator.truncate(raw_output.output, max_chars: max_chars, max_lines: max_lines, strategy: trunc_strat)
|
|
195
|
-
effective_dur = raw_output.duration_ms.positive? ? raw_output.duration_ms : dur
|
|
196
|
-
first_line = raw_output.output.lines.first.to_s.strip
|
|
197
|
-
first_line = nil if first_line.empty?
|
|
198
|
-
Rubik::Tools::Result.new(
|
|
199
|
-
tool_name: raw_output.tool_name.to_s.empty? ? tool_name : raw_output.tool_name,
|
|
200
|
-
call_id: raw_output.call_id.to_s.empty? ? call_id : raw_output.call_id,
|
|
201
|
-
status: raw_output.status, error: raw_output.error || (raw_output.error? ? first_line : nil),
|
|
202
|
-
# Structured fields ride along when the tool provides them
|
|
203
|
-
# (issue #127): the same Result contract for every carrier.
|
|
204
|
-
exit_code: raw_output.exit_code, output: trunc_res[:text], duration_ms: effective_dur,
|
|
205
|
-
truncated: raw_output.truncated || trunc_res[:truncated], metadata: raw_output.metadata
|
|
206
|
-
)
|
|
207
|
-
elsif raw_output.respond_to?(:status) && raw_output.respond_to?(:output)
|
|
208
|
-
out_str = raw_output.output.to_s
|
|
209
|
-
trunc_res = Rubik::Tools::Truncator.truncate(out_str, max_chars: max_chars, max_lines: max_lines, strategy: trunc_strat)
|
|
210
|
-
st = raw_output.status.to_sym
|
|
211
|
-
first_line = out_str.lines.first.to_s.strip
|
|
212
|
-
first_line = nil if first_line.empty?
|
|
213
|
-
err = (raw_output.respond_to?(:error) && raw_output.error) || (st == :error ? first_line : nil)
|
|
214
|
-
Rubik::Tools::Result.new(
|
|
215
|
-
tool_name: tool_name, call_id: call_id, status: st, error: err, output: trunc_res[:text],
|
|
216
|
-
duration_ms: dur, truncated: trunc_res[:truncated],
|
|
217
|
-
exit_code: raw_output.respond_to?(:exit_code) ? raw_output.exit_code : nil,
|
|
218
|
-
metadata: raw_output.respond_to?(:metadata) ? raw_output.metadata : {}
|
|
219
|
-
)
|
|
220
|
-
else
|
|
221
|
-
out_str = raw_output.to_s
|
|
222
|
-
trunc_res = Rubik::Tools::Truncator.truncate(out_str, max_chars: max_chars, max_lines: max_lines, strategy: trunc_strat)
|
|
223
|
-
|
|
224
|
-
is_err = if raw_output.respond_to?(:error?)
|
|
225
|
-
raw_output.error?
|
|
226
|
-
elsif raw_output.respond_to?(:failed?)
|
|
227
|
-
raw_output.failed?
|
|
228
|
-
elsif raw_output.is_a?(String)
|
|
229
|
-
ERROR_PREFIXES.any? { |pfx| raw_output.start_with?(pfx) }
|
|
230
|
-
else
|
|
231
|
-
false
|
|
232
|
-
end
|
|
233
|
-
|
|
234
|
-
first_line = out_str.lines.first.to_s.strip
|
|
235
|
-
first_line = nil if first_line.empty?
|
|
236
|
-
|
|
237
|
-
Rubik::Tools::Result.new(
|
|
238
|
-
tool_name: tool_name, call_id: call_id, status: is_err ? :error : :ok,
|
|
239
|
-
error: is_err ? first_line : nil, output: trunc_res[:text], duration_ms: dur, truncated: trunc_res[:truncated]
|
|
240
|
-
)
|
|
241
|
-
end
|
|
193
|
+
Rubik::Tools::ResultNormalizer.normalize(raw_output, tool_name: tool_name, call_id: call_id,
|
|
194
|
+
duration_ms: dur, config: @deps.shell&.config)
|
|
242
195
|
end
|
|
243
196
|
|
|
244
197
|
def record_circuit_breaker_result(breaker, tool_name, status)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative "../../coeffects"
|
|
4
|
+
require_relative "../../tools/catalog"
|
|
4
5
|
|
|
5
6
|
module Rubik
|
|
6
7
|
module Orchestrator
|
|
@@ -15,8 +16,10 @@ module Rubik
|
|
|
15
16
|
# budayıcının masaları yalnız kök/maestro düzlemine aittir —
|
|
16
17
|
# subagent kayıt defterlerine ('self' klonu dahil, çünkü onun
|
|
17
18
|
# filtresi yalnız spawn setini dışlar) asla kopyalanmaz. Orkestrasyon
|
|
18
|
-
# belleği tek elde kalır.
|
|
19
|
-
|
|
19
|
+
# belleği tek elde kalır. Derived from the Declarations: a tool with
|
|
20
|
+
# no subagent archetype is orchestrator-plane-only by definition, so
|
|
21
|
+
# the projection cannot drift from the allowlists.
|
|
22
|
+
ROOT_ONLY_TOOLS = Rubik::Tools::Catalog.orchestrator_only_tools.freeze
|
|
20
23
|
|
|
21
24
|
def build(source_registry:, type_def:, child_ctx:, buffer:, parent_buffer:)
|
|
22
25
|
return nil unless source_registry
|
|
@@ -35,7 +38,10 @@ module Rubik
|
|
|
35
38
|
|
|
36
39
|
# Buffer-bound tools (rebuilt only when a branch buffer splits them
|
|
37
40
|
# off the parent); everything else is context-rebind territory.
|
|
38
|
-
|
|
41
|
+
# Membership is declared on each tool's Declaration (buffer_bound:)
|
|
42
|
+
# and projected by Catalog; the rebuild itself stays here because
|
|
43
|
+
# branch splitting is an orchestrator concern, not the tool's.
|
|
44
|
+
BUFFER_BOUND_TOOLS = Rubik::Tools::Catalog.buffer_bound_tools.freeze
|
|
39
45
|
|
|
40
46
|
# Buffer rebinding must preserve runtime-context coeffect reads
|
|
41
47
|
# (rubik://goal/state, rubik://storage, subagent transcripts resolve
|
|
@@ -63,29 +69,14 @@ module Rubik
|
|
|
63
69
|
# subagent-plane message carries its REAL sender id to the maestro;
|
|
64
70
|
# invoke/manage swap so a nested spawn resolves the INSTANCE's task
|
|
65
71
|
# token (issue #125) instead of the root turn's.
|
|
66
|
-
#
|
|
67
|
-
#
|
|
72
|
+
# Each tool owns its rebind_to(ctx) (locality of concern); the
|
|
73
|
+
# registry only decides WHEN. Tools without rebind_to (plugins,
|
|
74
|
+
# dynamic tools registered under the same name) keep their own
|
|
75
|
+
# implementation in every plane.
|
|
68
76
|
def rebind_to_context(tool, ctx)
|
|
69
77
|
return tool unless ctx.respond_to?(:get)
|
|
70
78
|
|
|
71
|
-
|
|
72
|
-
when Rubik::Tools::AskQuestionTool
|
|
73
|
-
Rubik::Tools::AskQuestionTool.new(shell: nil, runtime_context: ctx)
|
|
74
|
-
when Rubik::Tools::SendMessageTool
|
|
75
|
-
Rubik::Tools::SendMessageTool.new(runtime_context: ctx)
|
|
76
|
-
when Rubik::Tools::InvokeSubagentTool
|
|
77
|
-
Rubik::Tools::InvokeSubagentTool.new(supervisor: supervisor_for(ctx), runtime_context: ctx)
|
|
78
|
-
when Rubik::Tools::ManageSubagentsTool
|
|
79
|
-
Rubik::Tools::ManageSubagentsTool.new(supervisor: supervisor_for(ctx), runtime_context: ctx)
|
|
80
|
-
when Rubik::Tools::DefineSubagentTool
|
|
81
|
-
Rubik::Tools::DefineSubagentTool.new(supervisor: supervisor_for(ctx), runtime_context: ctx)
|
|
82
|
-
else
|
|
83
|
-
tool
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
def supervisor_for(ctx)
|
|
88
|
-
Rubik::Coeffects.get(ctx, Rubik::Coeffects::SUBAGENT_SUPERVISOR)
|
|
79
|
+
tool.respond_to?(:rebind_to) ? tool.rebind_to(ctx) : tool
|
|
89
80
|
end
|
|
90
81
|
end
|
|
91
82
|
end
|
|
@@ -115,13 +115,23 @@ module Rubik
|
|
|
115
115
|
prov = provider if provider
|
|
116
116
|
|
|
117
117
|
context_limit = @config.respond_to?(:fetch) ? @config.fetch("context.max_tokens", 32_768) : 32_768
|
|
118
|
+
effective_steps = (max_steps || @default_max_steps).to_i
|
|
119
|
+
child_config = if @config.is_a?(Rubik::Config)
|
|
120
|
+
@config.extend(
|
|
121
|
+
"agent.max_steps" => effective_steps,
|
|
122
|
+
"context.max_tokens" => context_limit
|
|
123
|
+
)
|
|
124
|
+
else
|
|
125
|
+
@config
|
|
126
|
+
end
|
|
127
|
+
child_ctx.provide(Rubik::Coeffects::CONFIG, child_config) if child_ctx.respond_to?(:provide) && defined?(Rubik::Coeffects::CONFIG)
|
|
118
128
|
|
|
119
129
|
Instance.new(
|
|
120
130
|
id: subagent_id, parent_id: parent_id, role: role_str, type_name: profile_snapshot.name,
|
|
121
131
|
prompt: prompt_str, system_prompt: profile_snapshot.effective_system_prompt, workspace: workspace,
|
|
122
132
|
model: effective_model, context: child_ctx, tool_registry: scoped_registry,
|
|
123
|
-
provider: prov, buffer_manager: effective_buffer, max_steps:
|
|
124
|
-
provider_gate: @provider_gate, root_dir: @root_dir, config:
|
|
133
|
+
provider: prov, buffer_manager: effective_buffer, max_steps: effective_steps,
|
|
134
|
+
provider_gate: @provider_gate, root_dir: @root_dir, config: child_config,
|
|
125
135
|
context_limit: context_limit, event_bus: @event_bus,
|
|
126
136
|
transcript_storage: absorb_storage, owner_task: owner,
|
|
127
137
|
prompt_reconstructible: prompt_reconstructible, profile_snapshot: profile_snapshot
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative "../../tools/
|
|
4
|
-
require_relative "../../tools/result"
|
|
3
|
+
require_relative "../../tools/result_normalizer"
|
|
5
4
|
require_relative "../tool_timeout"
|
|
6
5
|
|
|
7
6
|
module Rubik
|
|
@@ -11,7 +10,8 @@ module Rubik
|
|
|
11
10
|
# every outcome — Result-backed, status-bearing, plain string, missing
|
|
12
11
|
# tool, or raised error — is normalized into the Result contract so
|
|
13
12
|
# status / exit_code / metadata survive truncation and reach the
|
|
14
|
-
# canonical history row.
|
|
13
|
+
# canonical history row. Classification itself lives in
|
|
14
|
+
# Tools::ResultNormalizer, shared verbatim with the root StepExecutor,
|
|
15
15
|
# so the two channels cannot drift.
|
|
16
16
|
module ToolDispatch
|
|
17
17
|
def dispatch_subagent_tool(tool, name, args)
|
|
@@ -22,10 +22,7 @@ module Rubik
|
|
|
22
22
|
canonical_name: tool.respond_to?(:name) ? tool.name : name) do
|
|
23
23
|
tool.execute(args)
|
|
24
24
|
end
|
|
25
|
-
|
|
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)
|
|
25
|
+
normalize_tool_result(raw, name)
|
|
29
26
|
rescue Rubik::Orchestrator::ToolTimeout::BudgetExceeded => e
|
|
30
27
|
Rubik::Orchestrator::ToolTimeout.emit_timeout_event(tool_name: name, budget_seconds: e.budget_seconds,
|
|
31
28
|
elapsed_seconds: e.elapsed_seconds, context: @context)
|
|
@@ -37,48 +34,14 @@ module Rubik
|
|
|
37
34
|
|
|
38
35
|
private
|
|
39
36
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
error: raw.error || (raw.error? ? first_line : nil), exit_code: raw.exit_code,
|
|
49
|
-
output: trunc[:text], duration_ms: raw.duration_ms,
|
|
50
|
-
truncated: raw.truncated || trunc[:truncated], metadata: raw.metadata)
|
|
51
|
-
elsif raw.respond_to?(:status) && raw.respond_to?(:output)
|
|
52
|
-
out_str = raw.output.to_s
|
|
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],
|
|
59
|
-
exit_code: raw.respond_to?(:exit_code) ? raw.exit_code : nil,
|
|
60
|
-
metadata: raw.respond_to?(:metadata) ? raw.metadata : {})
|
|
61
|
-
else
|
|
62
|
-
out_str = raw.to_s
|
|
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)
|
|
65
|
-
Rubik::Tools::Result.new(tool_name: name, status: status,
|
|
66
|
-
error: status == :error ? out_str.lines.first.to_s.strip : nil,
|
|
67
|
-
output: trunc[:text], truncated: trunc[:truncated])
|
|
68
|
-
end
|
|
69
|
-
end
|
|
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
|
|
37
|
+
# Thin delegator: carrier classification and truncation limits live
|
|
38
|
+
# in Tools::ResultNormalizer — the single home both orchestrator
|
|
39
|
+
# planes share, so the channels cannot drift. The
|
|
40
|
+
# subagent plane passes no call_id/duration_ms (nothing measured
|
|
41
|
+
# here); wrapping stays local so a normalize bug is contained into an
|
|
42
|
+
# error result by dispatch_subagent_tool's rescue.
|
|
43
|
+
def normalize_tool_result(raw, name)
|
|
44
|
+
Rubik::Tools::ResultNormalizer.normalize(raw, tool_name: name, config: @config)
|
|
82
45
|
end
|
|
83
46
|
|
|
84
47
|
def error_result(name, text, error: nil)
|
|
@@ -56,13 +56,18 @@ module Rubik
|
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
# Registry-canonical finish detection: a call is the finish call when
|
|
59
|
-
# the registry resolves it to
|
|
60
|
-
#
|
|
61
|
-
#
|
|
59
|
+
# the registry resolves it to a terminal tool (Declaration terminal:,
|
|
60
|
+
# projected by Catalog). The name compare stays as the duck-typed
|
|
61
|
+
# fallback — fake/dynamic registries can resolve plain objects whose
|
|
62
|
+
# class carries no Declaration (a terminal?-less "finish" must still
|
|
63
|
+
# complete the turn, or the loop waits forever); an unregistered case
|
|
64
|
+
# variant ("Finish") downcases to finish too.
|
|
62
65
|
def finish_call?(tool_registry, tool_call)
|
|
63
66
|
t_name = tool_call["tool"] || tool_call[:tool]
|
|
64
67
|
resolved = tool_registry.respond_to?(:get) ? tool_registry.get(t_name) : nil
|
|
65
|
-
|
|
68
|
+
return true if resolved.respond_to?(:terminal?) && resolved.terminal?
|
|
69
|
+
|
|
70
|
+
(resolved ? resolved.name : t_name).to_s.downcase == "finish"
|
|
66
71
|
end
|
|
67
72
|
end
|
|
68
73
|
|
|
@@ -11,7 +11,7 @@ module Rubik
|
|
|
11
11
|
|
|
12
12
|
# Whole-command synopses: shared by the spine registration (usage:)
|
|
13
13
|
# and the fallback branches that print them, so the two cannot drift.
|
|
14
|
-
USAGE_LSP = "Usage: !lsp <status | on | off | diag [file] | start <lang> | stop [lang] | restart [lang] | servers> [--project|--global]"
|
|
14
|
+
USAGE_LSP = "Usage: !lsp <status | on | off | diag [file] | start <lang> | stop [lang] | restart [lang] | reset [lang] | servers> [--project|--global]"
|
|
15
15
|
USAGE_SYMBOLS = "Usage: !symbols <name>"
|
|
16
16
|
USAGE_OUTLINE = "Usage: !outline <file_path>"
|
|
17
17
|
USAGE_REFS = "Usage: !refs <symbol_name>"
|
|
@@ -113,11 +113,23 @@ module Rubik
|
|
|
113
113
|
handle_lsp_stop(clean_args[1], ctx)
|
|
114
114
|
when "restart"
|
|
115
115
|
handle_lsp_restart(clean_args[1], ctx)
|
|
116
|
+
when "reset"
|
|
117
|
+
handle_lsp_reset(clean_args[1], ctx)
|
|
116
118
|
else
|
|
117
119
|
ctx.out.puts USAGE_LSP
|
|
118
120
|
end
|
|
119
121
|
end
|
|
120
122
|
|
|
123
|
+
private_class_method def self.handle_lsp_reset(lang, ctx)
|
|
124
|
+
if lang.nil? || lang.empty?
|
|
125
|
+
ctx.lsp_manager.crash_stats.clear
|
|
126
|
+
ctx.out.puts "Reset LSP circuit breaker for all languages."
|
|
127
|
+
else
|
|
128
|
+
ctx.lsp_manager.reset_circuit!(lang)
|
|
129
|
+
ctx.out.puts "Reset LSP circuit breaker for '#{lang}'."
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
121
133
|
private_class_method def self.handle_lsp_status(ctx)
|
|
122
134
|
summary = ctx.lsp_manager.status_summary
|
|
123
135
|
ctx.out.puts "=== LSP Integration Status ==="
|
|
@@ -379,6 +379,16 @@ module Rubik
|
|
|
379
379
|
ctx.out.puts "[Rubik::Allow] Added allowed external directory: #{expanded} (Mode: #{mode_str}) [#{Base.scope_label(scope)}]."
|
|
380
380
|
end
|
|
381
381
|
|
|
382
|
+
OPERATOR_ONLY_CONFIG_PREFIXES = [
|
|
383
|
+
"security.",
|
|
384
|
+
"sandbox.",
|
|
385
|
+
"subagents.",
|
|
386
|
+
"plugins.",
|
|
387
|
+
"lsp.servers.",
|
|
388
|
+
"workspace.allow_external_writes",
|
|
389
|
+
"tools.circuit_breaker."
|
|
390
|
+
].freeze
|
|
391
|
+
|
|
382
392
|
private_class_method def self.register_config_command(shell)
|
|
383
393
|
shell.register_command("config", description: "Get, set, or view runtime configuration (set|get|list|path)",
|
|
384
394
|
usage: USAGE_CONFIG, audience: :both) do |args, ctx|
|
|
@@ -407,14 +417,10 @@ module Rubik
|
|
|
407
417
|
val = clean_args[2..]&.join(" ")
|
|
408
418
|
if key.nil? || key.empty? || val.nil? || val.empty?
|
|
409
419
|
ctx.out.puts "Usage: !config set <key> <val> [--project|--global]"
|
|
410
|
-
elsif ctx.agent_caller && key.start_with?(
|
|
411
|
-
#
|
|
412
|
-
#
|
|
413
|
-
#
|
|
414
|
-
# concurrency, reap grace) exec_repl_command ile çözemez —
|
|
415
|
-
# kapı canlı config okur, self-unlock yolu bu yüzden kapalı.
|
|
416
|
-
ctx.out.puts "Security Error: keys under 'security.*' and 'sandbox.*' are operator-only " \
|
|
417
|
-
"(mutated via !allow-cmd / !allow-dir as the human operator)."
|
|
420
|
+
elsif ctx.agent_caller && OPERATOR_ONLY_CONFIG_PREFIXES.any? { |p| key.start_with?(p) }
|
|
421
|
+
# Security boundary: agents cannot alter security, sandbox, subagent governance,
|
|
422
|
+
# plugins (arbitrary code execution), LSP binary commands, or external write policies.
|
|
423
|
+
ctx.out.puts "Security Error: configuration key '#{key}' is operator-only and cannot be altered by autonomous agents."
|
|
418
424
|
else
|
|
419
425
|
res = ctx.config.set(key, val, persist: scope)
|
|
420
426
|
next if Base.report_persist_failure(ctx, res, scope)
|
data/lib/rubik/repl/lifecycle.rb
CHANGED
|
@@ -151,6 +151,17 @@ module Rubik
|
|
|
151
151
|
Rubik.runtime_manager = @runtime_manager
|
|
152
152
|
@overlay_storage.load_all(self, @runtime_manager)
|
|
153
153
|
@config_cleanups = ConfigWiring.wire(self)
|
|
154
|
+
if @runtime_manager&.context.respond_to?(:on_dispose)
|
|
155
|
+
@runtime_manager.context.on_dispose do
|
|
156
|
+
while (cleanup = @config_cleanups&.pop)
|
|
157
|
+
begin
|
|
158
|
+
cleanup.call
|
|
159
|
+
rescue StandardError => e
|
|
160
|
+
warn "[WARN] Config cleanup failed: #{e.message}"
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
end
|
|
154
165
|
# Phase 5 built the tool registry; the skill tool's epoch (its
|
|
155
166
|
# revertible registration + inverse) opens on the manager's own
|
|
156
167
|
# sub-context only after config wiring so enable/disable knobs react.
|
|
@@ -239,7 +239,8 @@ module Rubik
|
|
|
239
239
|
name: :sandbox_runner,
|
|
240
240
|
builder: lambda do |s|
|
|
241
241
|
Rubik::Sandbox::Runner.new(root_dir: s.root_dir, config: s[:config],
|
|
242
|
-
allowed_external_dirs: s[:allowed_ext_dirs], guard: s[:guard]
|
|
242
|
+
allowed_external_dirs: s[:allowed_ext_dirs], guard: s[:guard],
|
|
243
|
+
context: s[:runtime_manager]&.context)
|
|
243
244
|
end,
|
|
244
245
|
provide: Rubik::Coeffects::SANDBOX_RUNNER
|
|
245
246
|
),
|
data/lib/rubik/repl/shell.rb
CHANGED
|
@@ -55,23 +55,21 @@ module Rubik
|
|
|
55
55
|
end
|
|
56
56
|
alias on_dispose register_disposable
|
|
57
57
|
|
|
58
|
-
#
|
|
59
|
-
#
|
|
60
|
-
def
|
|
61
|
-
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def services
|
|
65
|
-
@monitor.synchronize { @services.dup.freeze }
|
|
66
|
-
end
|
|
58
|
+
# Symmetric removal of an inverse from the Omega accumulator before
|
|
59
|
+
# context disposal (AGENTS.md §4).
|
|
60
|
+
def unregister_disposable(inverse)
|
|
61
|
+
return unless inverse
|
|
67
62
|
|
|
68
|
-
|
|
69
|
-
@monitor.synchronize { @services.keys }
|
|
63
|
+
@monitor.synchronize { @disposables.delete(inverse) }
|
|
70
64
|
end
|
|
65
|
+
alias prune_disposable unregister_disposable
|
|
71
66
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
67
|
+
# Number of pending inverse operations in the Omega accumulator.
|
|
68
|
+
# Exposed for runtime visualization (!agents panel, !runtime).
|
|
69
|
+
def disposable_count = @monitor.synchronize { @disposables.size }
|
|
70
|
+
def services = @monitor.synchronize { @services.dup.freeze }
|
|
71
|
+
def service_names = @monitor.synchronize { @services.keys }
|
|
72
|
+
def last_dispose_errors = @monitor.synchronize { @last_dispose_errors.dup }
|
|
75
73
|
|
|
76
74
|
def provide(name, service)
|
|
77
75
|
key = name.to_s.downcase
|
data/lib/rubik/sandbox/runner.rb
CHANGED
|
@@ -8,11 +8,12 @@ require_relative "../platform"
|
|
|
8
8
|
module Rubik
|
|
9
9
|
module Sandbox
|
|
10
10
|
class Runner
|
|
11
|
-
attr_reader :root_dir, :driver, :allowed_external_dirs, :config, :guard
|
|
11
|
+
attr_reader :root_dir, :driver, :allowed_external_dirs, :config, :guard, :context
|
|
12
12
|
|
|
13
|
-
def initialize(root_dir: Dir.pwd, allow_network: false, driver: nil, config: nil, allowed_external_dirs: [], guard: nil)
|
|
13
|
+
def initialize(root_dir: Dir.pwd, allow_network: false, driver: nil, config: nil, allowed_external_dirs: [], guard: nil, context: nil)
|
|
14
14
|
@root_dir = File.expand_path(root_dir)
|
|
15
15
|
@config = config
|
|
16
|
+
@context = context
|
|
16
17
|
@preferred_driver = driver
|
|
17
18
|
# Shared session guard (Composition provides it). Injected into every
|
|
18
19
|
# driver_opts rebuild below so reconfigure! cycles never strand a
|
|
@@ -32,17 +33,31 @@ module Rubik
|
|
|
32
33
|
|
|
33
34
|
reconfigure!
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
36
|
+
@cleanups = []
|
|
37
|
+
if @config.respond_to?(:on_change)
|
|
38
|
+
@cleanups << @config.on_change("sandbox") { reconfigure! }
|
|
39
|
+
# Track explicit edits to the allow-list key itself. Once the user
|
|
40
|
+
# has set this key at any scope, the config becomes authoritative:
|
|
41
|
+
# reconfigure! recomputes config-sourced entries from scratch so
|
|
42
|
+
# REMOVING a dir actually shrinks the live allow-list (the previous
|
|
43
|
+
# union-based merge was monotonic and left stale dirs allowed).
|
|
44
|
+
@cleanups << @config.on_change("workspace.allowed_external_dirs") do
|
|
45
|
+
@allowed_dirs_config_touched = true
|
|
46
|
+
reconfigure!
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
@context.on_dispose { dispose } if @context.respond_to?(:on_dispose)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Unregisters accumulated configuration observers (AGENTS.md Ω Inverses).
|
|
54
|
+
def dispose
|
|
55
|
+
while (cleanup = @cleanups&.pop)
|
|
56
|
+
begin
|
|
57
|
+
cleanup.call
|
|
58
|
+
rescue StandardError => e
|
|
59
|
+
warn "[WARN] Sandbox::Runner cleanup failed: #{e.message}"
|
|
60
|
+
end
|
|
46
61
|
end
|
|
47
62
|
end
|
|
48
63
|
|
data/lib/rubik/storage/render.rb
CHANGED
|
@@ -38,7 +38,7 @@ module Rubik
|
|
|
38
38
|
return header << "_(empty — no #{type} entities yet)_\n" if summaries.empty?
|
|
39
39
|
|
|
40
40
|
summaries.each do |s|
|
|
41
|
-
title = s[:title].to_s.
|
|
41
|
+
title = s[:title].to_s.slice(0, 80).gsub(/[\\|]/) { |ch| "\\#{ch}" }
|
|
42
42
|
header << "| #{s[:row]} | `#{s[:id]}` | #{s[:status]} | #{s[:updated_at]} | #{title} |\n"
|
|
43
43
|
end
|
|
44
44
|
header
|
|
@@ -260,11 +260,11 @@ module Rubik
|
|
|
260
260
|
|
|
261
261
|
gap_ref = Vocabulary.recall_gap_ref(proposal["ref"])
|
|
262
262
|
# Review bulgusu 2: smoke, gerçek recall'ın GÖRÜNÜR penceresiyle
|
|
263
|
-
# koşulmalı — ilk RECALL_LIMIT kayıt. 6. sıradaki sayfa maestro'ya
|
|
263
|
+
# koşulmalı — ilk Recall::RECALL_LIMIT kayıt. 6. sıradaki sayfa maestro'ya
|
|
264
264
|
# görünmüyorsa iska sayılmalı (öz-onarım döngüsü kör kalmasın).
|
|
265
265
|
missed = checks.reject do |check|
|
|
266
|
-
active_recall_hits(gate.store, query: check, type:
|
|
267
|
-
.first(
|
|
266
|
+
active_recall_hits(gate.store, query: check, type: Recall::RECALL_TYPES)
|
|
267
|
+
.first(Recall::RECALL_LIMIT).any? { |r| r["id"] == page_id }
|
|
268
268
|
end
|
|
269
269
|
if missed.empty?
|
|
270
270
|
resolved = gate.store.get(type: "note", id: gap_ref)
|
|
@@ -13,10 +13,6 @@ module Rubik
|
|
|
13
13
|
class Harness
|
|
14
14
|
STOP = :__vakanuvis_stop__
|
|
15
15
|
MAX_QUEUE = 200
|
|
16
|
-
RECALL_LIMIT = 5
|
|
17
|
-
RECALL_FALLBACK_LIMIT = 3
|
|
18
|
-
RECALL_BODY_SLICE = 140
|
|
19
|
-
RECALL_TYPES = ["memory", "wiki"].freeze
|
|
20
16
|
# v2 §4-V4: damıtıcı kaynak disiplini — yalnız TAMAMLANMIŞ transcript'ler,
|
|
21
17
|
# damıtıcının kendisi Hariç (özyineleme kirliliği: canlı depoda transcript satırları 'vakanuvis' etiketi taşır).
|
|
22
18
|
SOURCE_TRANSCRIPT_LIMIT = 8
|
|
@@ -135,23 +131,10 @@ module Rubik
|
|
|
135
131
|
|
|
136
132
|
# ---- talep düzlemi (maestro aracı buraya delege eder; K7) ---------
|
|
137
133
|
|
|
138
|
-
#
|
|
139
|
-
#
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
def recall(query, types: RECALL_TYPES)
|
|
143
|
-
q = query.to_s.strip
|
|
144
|
-
raise ArgumentError, "recall: 'query' is required" if q.empty?
|
|
145
|
-
|
|
146
|
-
allowed = Array(types).map(&:to_s)
|
|
147
|
-
allowed = RECALL_TYPES if allowed.empty?
|
|
148
|
-
hits = DistillGate.active_recall_hits(@store, query: q, type: allowed).first(RECALL_LIMIT)
|
|
149
|
-
unless hits.empty?
|
|
150
|
-
header = "Recalled #{hits.size} entit#{hits.size == 1 ? 'y' : 'ies'} for '#{AnnalWriter.one_line(q, 80)}':"
|
|
151
|
-
return "#{header}\n#{hits.map { |r| recall_line(r) }.join("\n")}\nRead a full record with read_file(path: '<uri above>')."
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
relaxed_digest(q, allowed)
|
|
134
|
+
# Deterministik geri çağırma Recall düzleminde (recall.rb); burada
|
|
135
|
+
# yalnız delege — araç yüzeyi (K7) ve test ikizleri bu imzaya pinli.
|
|
136
|
+
def recall(query, types: Recall::RECALL_TYPES)
|
|
137
|
+
Recall.recall(@store, query, types: types)
|
|
155
138
|
end
|
|
156
139
|
|
|
157
140
|
def auto_digest? = @auto_digest
|
|
@@ -221,50 +204,6 @@ module Rubik
|
|
|
221
204
|
shown.join(", ")
|
|
222
205
|
end
|
|
223
206
|
|
|
224
|
-
# v2 §4-V2 + issue #99 P2: AND boşluğu tek tip körlük değil — en yakın
|
|
225
|
-
# kısmi eşleşmeler dürüstçe "(fallback)" damgasıyla sunulur (gerçek
|
|
226
|
-
# eşleşme değildir), transcript izleri kapsam ipucu olarak sayılır. Ne
|
|
227
|
-
# fallback ne transcript izi varsa bugünkü dil/terim yönlendirmesi birebir
|
|
228
|
-
# döner (keyword-AND'da en sık neden TR sorgu ↔ EN gövde uyuşmazlığıdır;
|
|
229
|
-
# yanlış "hemen yeniden kaydet" yönlendirmesi burada kesilir).
|
|
230
|
-
def relaxed_digest(query, allowed)
|
|
231
|
-
q = query.to_s.strip
|
|
232
|
-
# Süpersede edilmiş sayılar "en yakın kısmi eşleşme" olarak
|
|
233
|
-
# sunulmaz (review M1) — emekli bir sayfayı okumaya davet etmek,
|
|
234
|
-
# issue #100'ün "iki kopya, biri bozuk" bulgusunun aynısıdır.
|
|
235
|
-
relaxed = DistillGate.active_recall_hits(@store, query: q, type: allowed, require_all: false)
|
|
236
|
-
.first(RECALL_FALLBACK_LIMIT)
|
|
237
|
-
transcripts = @store.search(query: q, type: "transcript")
|
|
238
|
-
if relaxed.empty? && transcripts.empty?
|
|
239
|
-
return "No chronicled knowledge matches '#{AnnalWriter.one_line(q, 80)}'. Recall is keyword-AND: retry with fewer or other-language " \
|
|
240
|
-
"terms first (e.g. the TR/EN Keywords: lines). If the knowledge is genuinely missing, record it (vakanuvis action 'record') or queue a digest."
|
|
241
|
-
end
|
|
242
|
-
|
|
243
|
-
parts = []
|
|
244
|
-
# Başlık + read_file ayağı yalnız gerçek fallback izi varken
|
|
245
|
-
# basılır (review CR#1: "yukarıdaki uri" diyecek uri yokken
|
|
246
|
-
# olmayan bir talimat modele verilmesin).
|
|
247
|
-
unless relaxed.empty?
|
|
248
|
-
parts << "No exact keyword-AND match for '#{AnnalWriter.one_line(q, 80)}' — closest partial matches (fallback, not true matches):"
|
|
249
|
-
parts.concat(relaxed.map { |r| "- (fallback) #{recall_line(r)}" })
|
|
250
|
-
end
|
|
251
|
-
unless transcripts.empty?
|
|
252
|
-
parts << "#{transcripts.size} transcript entr#{transcripts.size == 1 ? 'y' : 'ies'} mention these terms — " \
|
|
253
|
-
"the raw session logs may hold it; queue a digest to compile them."
|
|
254
|
-
end
|
|
255
|
-
parts << "If none of these help, retry with fewer or other-language terms (the TR/EN Keywords: lines), " \
|
|
256
|
-
"record the knowledge, or queue a digest."
|
|
257
|
-
parts << "Read a full record with read_file(path: '<uri above>')." unless relaxed.empty?
|
|
258
|
-
parts.join("\n")
|
|
259
|
-
end
|
|
260
|
-
|
|
261
|
-
def first_body_line(record)
|
|
262
|
-
slice = record["body"].to_s.lines.map(&:strip).reject(&:empty?).first.to_s.slice(0, RECALL_BODY_SLICE)
|
|
263
|
-
slice.empty? ? "(no body)" : slice
|
|
264
|
-
end
|
|
265
|
-
|
|
266
|
-
def recall_line(record) = "- #{record['title']} [#{record['id']}] #{first_body_line(record)} — #{@store.uri_for(record['type'], record['id'])}"
|
|
267
|
-
|
|
268
207
|
# Abonelik geri alımı dispatcher'a aittir (§1A: subscribe'a verilen context'e
|
|
269
208
|
# unregister inverse'i kendisi bağlar); TURN aboneliği R7 knob'unun arkasındadır.
|
|
270
209
|
def subscribe_events
|