rubik 0.9.0 → 0.9.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.
- checksums.yaml +4 -4
- data/ATTRIBUTION.md +1 -1
- data/CHANGELOG.md +108 -43
- data/README.md +5 -1
- data/lib/rubik/adapter/base.rb +19 -0
- data/lib/rubik/adapter/generic.rb +0 -14
- data/lib/rubik/adapter/node.rb +2 -0
- data/lib/rubik/ast/treesitter/zig_walker.rb +15 -2
- data/lib/rubik/cli/workspace_trust.rb +16 -0
- data/lib/rubik/config/defaults.rb +23 -0
- data/lib/rubik/config/store.rb +14 -0
- data/lib/rubik/kernel/dispatcher.rb +4 -4
- data/lib/rubik/log.rb +2 -1
- data/lib/rubik/lsp/client.rb +83 -180
- data/lib/rubik/lsp/document_store.rb +209 -0
- data/lib/rubik/mcp/client.rb +4 -3
- data/lib/rubik/mcp/manager.rb +6 -2
- data/lib/rubik/mcp/transport/stdio.rb +51 -9
- data/lib/rubik/orchestrator/goal_session.rb +505 -0
- data/lib/rubik/orchestrator/subagent/instance.rb +4 -0
- data/lib/rubik/orchestrator/subagent/journal.rb +2 -1
- data/lib/rubik/orchestrator/subagent/questioner.rb +21 -6
- data/lib/rubik/orchestrator/subagent/step_runner.rb +1 -1
- data/lib/rubik/orchestrator/subagent/teardown.rb +4 -0
- data/lib/rubik/orchestrator/subagent/transcript_formatter.rb +2 -1
- data/lib/rubik/orchestrator.rb +1 -0
- data/lib/rubik/platform.rb +15 -0
- data/lib/rubik/plugin/storage.rb +20 -29
- data/lib/rubik/repl/commands/agent_context.rb +1 -1
- data/lib/rubik/repl/commands/agent_execution.rb +7 -470
- data/lib/rubik/repl/commands/buffer.rb +1 -1
- data/lib/rubik/repl/commands/lsp.rb +1 -1
- data/lib/rubik/repl/input_loop.rb +1 -1
- data/lib/rubik/repl/lifecycle.rb +28 -0
- data/lib/rubik/runtime/manifest_store.rb +116 -0
- data/lib/rubik/runtime/overlay_storage.rb +247 -196
- data/lib/rubik/runtime/task_manager.rb +7 -2
- data/lib/rubik/runtime.rb +1 -0
- data/lib/rubik/security/allowlist.rb +167 -0
- data/lib/rubik/security/audit_log.rb +72 -0
- data/lib/rubik/security/classifier/classifier.rb +8 -0
- data/lib/rubik/security/command_gate.rb +567 -0
- data/lib/rubik/security/guard.rb +88 -1075
- data/lib/rubik/security/path_policy.rb +117 -0
- data/lib/rubik/security/synthesis_gate.rb +300 -0
- data/lib/rubik/security.rb +5 -0
- data/lib/rubik/storage/ranking.rb +113 -0
- data/lib/rubik/storage/store.rb +2 -92
- data/lib/rubik/storage/transcript_indexer.rb +2 -3
- data/lib/rubik/tools/builtins/grep.rb +2 -3
- data/lib/rubik/tools/builtins/lifecycle.rb +90 -87
- data/lib/rubik/tools/builtins/synthesis.rb +3 -0
- data/lib/rubik/tools/lifecycle_rollbacks.rb +87 -0
- data/lib/rubik/tools/native_search.rb +2 -1
- data/lib/rubik/tools/truncator.rb +25 -0
- data/lib/rubik/version.rb +1 -1
- metadata +11 -1
|
@@ -5,6 +5,7 @@ require_relative "../../coeffects"
|
|
|
5
5
|
require_relative "../index_messages"
|
|
6
6
|
require_relative "../output"
|
|
7
7
|
require_relative "../native_search"
|
|
8
|
+
require_relative "../truncator"
|
|
8
9
|
require_relative "../diagnostic_reporter"
|
|
9
10
|
|
|
10
11
|
module Rubik
|
|
@@ -245,9 +246,7 @@ module Rubik
|
|
|
245
246
|
end
|
|
246
247
|
|
|
247
248
|
def sanitize_line_content(content)
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
"#{content[0..MAX_LINE_CHARS]}... [line truncated, #{content.length} chars total]"
|
|
249
|
+
Rubik::Tools::Truncator.clip_line(content, MAX_LINE_CHARS)
|
|
251
250
|
end
|
|
252
251
|
|
|
253
252
|
def collect_disk_matches(matches, file_key, regex, max_results)
|
|
@@ -151,24 +151,14 @@ module Rubik
|
|
|
151
151
|
|
|
152
152
|
return ToolOutput.error("Target and language_or_type must be provided.") if target.empty? || lang.empty?
|
|
153
153
|
|
|
154
|
-
# 1
|
|
154
|
+
# Phase 1: discovery (automatic probing when no command was provided)
|
|
155
155
|
if !command_provided?(proposed_cmd) && auto_probe
|
|
156
|
-
candidate =
|
|
157
|
-
when "lsp" then Rubik::Runtime::Discovery.probe_lsp(lang, root_dir: @root_dir)
|
|
158
|
-
when "test_runner" then Rubik::Runtime::Discovery.discover_test_runners(root_dir: @root_dir, lang: lang).first
|
|
159
|
-
when "linter" then Rubik::Runtime::Discovery.discover_formatters(root_dir: @root_dir, lang: lang).first
|
|
160
|
-
when "command" then Rubik::Runtime::Discovery.binary_available?(lang) ? lang : nil
|
|
161
|
-
end
|
|
156
|
+
candidate = discover_target(target, lang)
|
|
162
157
|
|
|
163
158
|
if candidate
|
|
164
159
|
proposed_cmd = candidate
|
|
165
160
|
else
|
|
166
|
-
candidates =
|
|
167
|
-
when "lsp" then Rubik::Runtime::Discovery.lsp_candidates(lang)
|
|
168
|
-
when "test_runner" then Rubik::Runtime::Discovery.test_runner_candidates(lang, root_dir: @root_dir)
|
|
169
|
-
when "linter" then Rubik::Runtime::Discovery::FORMATTER_CANDIDATES[lang] || []
|
|
170
|
-
else []
|
|
171
|
-
end
|
|
161
|
+
candidates = discovery_candidates(target, lang)
|
|
172
162
|
cand_str = candidates.empty? ? "none" : candidates.join(", ")
|
|
173
163
|
return ToolOutput.error("Auto-probe failed to discover any installed candidate for #{target} (#{lang}). " \
|
|
174
164
|
"Candidates checked: [#{cand_str}]. Please provide a specific `proposed_command`.")
|
|
@@ -177,15 +167,66 @@ module Rubik
|
|
|
177
167
|
|
|
178
168
|
return ToolOutput.error("No command provided or discovered for #{target} (#{lang}).") unless command_provided?(proposed_cmd)
|
|
179
169
|
|
|
180
|
-
# 2
|
|
170
|
+
# Phase 2: pre-flight verification in an isolated sub-context (ctx.extend())
|
|
181
171
|
root_ctx = @runtime_manager&.context || Rubik::Runtime::Context.new
|
|
182
|
-
|
|
172
|
+
verified, error_diagnostic = verify_in_sandbox(target, lang, proposed_cmd, root_ctx,
|
|
173
|
+
probe_args: args["probe_args"] || args[:probe_args])
|
|
174
|
+
return ToolOutput.error("Verification failed for #{target} (#{lang}):\n#{error_diagnostic&.format_for_llm}") unless verified
|
|
175
|
+
|
|
176
|
+
# Phase 3: promotion into a disposable transaction sub-context
|
|
177
|
+
result = promote(target, lang, proposed_cmd, root_ctx)
|
|
178
|
+
return result if result.is_a?(ToolOutput)
|
|
179
|
+
|
|
180
|
+
# Keep one lifetime inverse per repaired key, preserving the original
|
|
181
|
+
# baseline across repeated repairs without retaining every transaction.
|
|
182
|
+
promotion_ctx = result.promotion_ctx
|
|
183
|
+
scope_key = [root_ctx, result.service_key]
|
|
184
|
+
if @repair_scopes.key?(scope_key)
|
|
185
|
+
result.state.released = true
|
|
186
|
+
promotion_ctx.dispose
|
|
187
|
+
else
|
|
188
|
+
@repair_scopes[scope_key] = promotion_ctx
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
if @config.nil? && ["lsp", "test_runner", "linter"].include?(target)
|
|
192
|
+
return "⚠️ Promoted '#{display_command(proposed_cmd)}' for #{target} (#{lang}) — no config is attached, " \
|
|
193
|
+
"so the command is active for this session only and was not saved."
|
|
194
|
+
end
|
|
183
195
|
|
|
196
|
+
"✨ Successfully verified and promoted runtime service for #{target} (#{lang}): '#{display_command(proposed_cmd)}'. " \
|
|
197
|
+
"Service is now active in the live context."
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
private
|
|
201
|
+
|
|
202
|
+
# Phase 1: automatic probing of an installed candidate for the target.
|
|
203
|
+
def discover_target(target, lang)
|
|
204
|
+
case target
|
|
205
|
+
when "lsp" then Rubik::Runtime::Discovery.probe_lsp(lang, root_dir: @root_dir)
|
|
206
|
+
when "test_runner" then Rubik::Runtime::Discovery.discover_test_runners(root_dir: @root_dir, lang: lang).first
|
|
207
|
+
when "linter" then Rubik::Runtime::Discovery.discover_formatters(root_dir: @root_dir, lang: lang).first
|
|
208
|
+
when "command" then Rubik::Runtime::Discovery.binary_available?(lang) ? lang : nil
|
|
209
|
+
end
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
# Candidates surfaced in the error message when discovery finds nothing.
|
|
213
|
+
def discovery_candidates(target, lang)
|
|
214
|
+
case target
|
|
215
|
+
when "lsp" then Rubik::Runtime::Discovery.lsp_candidates(lang)
|
|
216
|
+
when "test_runner" then Rubik::Runtime::Discovery.test_runner_candidates(lang, root_dir: @root_dir)
|
|
217
|
+
when "linter" then Rubik::Runtime::Discovery::FORMATTER_CANDIDATES[lang] || []
|
|
218
|
+
else []
|
|
219
|
+
end
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
# Phase 2: pre-flight verification in an isolated sub-context. The probe
|
|
223
|
+
# sub-context is always disposed, even when verification raises.
|
|
224
|
+
def verify_in_sandbox(target, lang, proposed_cmd, root_ctx, probe_args: nil)
|
|
225
|
+
sub_ctx = root_ctx.extend
|
|
184
226
|
verified = false
|
|
185
227
|
error_diagnostic = nil
|
|
186
|
-
|
|
187
228
|
begin
|
|
188
|
-
verified, error_diagnostic = verify_binary(target, lang, proposed_cmd, sub_ctx, probe_args:
|
|
229
|
+
verified, error_diagnostic = verify_binary(target, lang, proposed_cmd, sub_ctx, probe_args: probe_args)
|
|
189
230
|
rescue StandardError => e
|
|
190
231
|
error_diagnostic = Rubik::Runtime::DiagnosticEngine.diagnose(
|
|
191
232
|
cmd: proposed_cmd,
|
|
@@ -195,13 +236,19 @@ module Rubik
|
|
|
195
236
|
ensure
|
|
196
237
|
sub_ctx.dispose
|
|
197
238
|
end
|
|
239
|
+
[verified, error_diagnostic]
|
|
240
|
+
end
|
|
198
241
|
|
|
199
|
-
|
|
200
|
-
|
|
242
|
+
# Phase 3: apply the promoted command inside a disposable transaction
|
|
243
|
+
# sub-context. Returns a Promotion on success or a ToolOutput error with
|
|
244
|
+
# the rollback report; the `phase` marker distinguishes Promotion from
|
|
245
|
+
# Persistence failures. Rollbacks are named objects (see RollbackState)
|
|
246
|
+
# registered in LIFO order into the promotion sub-context.
|
|
247
|
+
def promote(target, lang, proposed_cmd, root_ctx)
|
|
201
248
|
# Live changes belong to a disposable transaction. Successful project
|
|
202
249
|
# persistence is an operator decision and outlives lifecycle cleanup.
|
|
203
250
|
promotion_ctx = root_ctx.extend
|
|
204
|
-
|
|
251
|
+
state = RollbackState.new
|
|
205
252
|
@repair_scopes ||= {}
|
|
206
253
|
cfg_key = { "lsp" => "lsp.servers", "test_runner" => "test.runners",
|
|
207
254
|
"linter" => "linter.commands" }[target]
|
|
@@ -211,35 +258,13 @@ module Rubik
|
|
|
211
258
|
previous_services = root_ctx.services
|
|
212
259
|
phase = "Promotion"
|
|
213
260
|
begin
|
|
214
|
-
promotion_ctx.on_dispose
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
if previous_services.key?(service_key)
|
|
220
|
-
if target == "lsp"
|
|
221
|
-
restored = @lsp_manager&.clients&.[](lang)
|
|
222
|
-
active = restored && (!restored.respond_to?(:alive?) || restored.alive?) &&
|
|
223
|
-
(!restored.respond_to?(:running?) || restored.running?)
|
|
224
|
-
if active
|
|
225
|
-
root_ctx.provide(service_key, restored)
|
|
226
|
-
else
|
|
227
|
-
root_ctx.unprovide(service_key)
|
|
228
|
-
end
|
|
229
|
-
else
|
|
230
|
-
root_ctx.provide(service_key, previous_services[service_key])
|
|
231
|
-
end
|
|
232
|
-
else
|
|
233
|
-
root_ctx.unprovide(service_key)
|
|
234
|
-
end
|
|
235
|
-
end
|
|
236
|
-
end
|
|
261
|
+
promotion_ctx.on_dispose(ServiceRollback.new(
|
|
262
|
+
root_ctx: root_ctx, promotion_ctx: promotion_ctx, service_key: service_key,
|
|
263
|
+
previous_services: previous_services, target: target, lang: lang,
|
|
264
|
+
lsp_manager: @lsp_manager, repair_scopes: @repair_scopes, state: state
|
|
265
|
+
))
|
|
237
266
|
if cfg_key && @config
|
|
238
|
-
promotion_ctx.on_dispose
|
|
239
|
-
next if released
|
|
240
|
-
|
|
241
|
-
prev_cmd.nil? ? @config.delete(cfg_key) : @config.set(cfg_key, prev_cmd)
|
|
242
|
-
end
|
|
267
|
+
promotion_ctx.on_dispose(ConfigRollback.new(config: @config, cfg_key: cfg_key, prev_cmd: prev_cmd, state: state))
|
|
243
268
|
@config.set(cfg_key, proposed_cmd)
|
|
244
269
|
end
|
|
245
270
|
|
|
@@ -250,16 +275,10 @@ module Rubik
|
|
|
250
275
|
had_client = !@lsp_manager.clients[lang].nil?
|
|
251
276
|
# The manager owns its client table. Restore the old configured
|
|
252
277
|
# client on rollback; probe clients never enter that table.
|
|
253
|
-
promotion_ctx.on_dispose
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
prev_cmd.nil? ? @config.delete(cfg_key) : @config.set(cfg_key, prev_cmd)
|
|
258
|
-
if had_client && !root_ctx.disposed?
|
|
259
|
-
restored = @lsp_manager.start_client(lang)
|
|
260
|
-
raise "Previous LSP client could not be restarted: #{restored}" unless restored[:ok]
|
|
261
|
-
end
|
|
262
|
-
end
|
|
278
|
+
promotion_ctx.on_dispose(LspClientRollback.new(
|
|
279
|
+
lsp_manager: @lsp_manager, lang: lang, config: @config, cfg_key: cfg_key,
|
|
280
|
+
prev_cmd: prev_cmd, root_ctx: root_ctx, had_client: had_client, state: state
|
|
281
|
+
))
|
|
263
282
|
@lsp_manager.stop_client(lang)
|
|
264
283
|
start_res = @lsp_manager.start_client(lang)
|
|
265
284
|
raise "Failed to start LSP server: #{start_res}" unless start_res.is_a?(Hash) && start_res[:ok]
|
|
@@ -273,12 +292,11 @@ module Rubik
|
|
|
273
292
|
field = target == "test_runner" ? :custom_test_cmd : :custom_format_cmd
|
|
274
293
|
old_value = adapter.public_send(field)
|
|
275
294
|
old_config = adapter.config
|
|
276
|
-
promotion_ctx.on_dispose
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
end
|
|
295
|
+
promotion_ctx.on_dispose(AdapterFieldRollback.new(adapter: adapter, field: field,
|
|
296
|
+
old_value: old_value, old_config: old_config, state: state))
|
|
297
|
+
# Execution-time gate (TOCTOU closure): the probe ran once but the
|
|
298
|
+
# sink is unguarded; failure raises into the rescue below.
|
|
299
|
+
adapter.send(:validate_custom_command!, proposed_cmd)
|
|
282
300
|
adapter.config ||= @config
|
|
283
301
|
adapter.public_send("#{field}=", proposed_cmd)
|
|
284
302
|
else
|
|
@@ -286,9 +304,9 @@ module Rubik
|
|
|
286
304
|
options = target == "test_runner" ? { test_cmd: proposed_cmd } : { format_cmd: proposed_cmd }
|
|
287
305
|
adapter = Rubik::Adapter::GenericAdapter.new(lang, **options, guard: @guard)
|
|
288
306
|
adapter.config = @config
|
|
289
|
-
promotion_ctx.on_dispose
|
|
290
|
-
|
|
291
|
-
|
|
307
|
+
promotion_ctx.on_dispose(AdapterUnregisterRollback.new(
|
|
308
|
+
adapter_registry: @adapter_registry, lang: lang, adapter: adapter, state: state
|
|
309
|
+
))
|
|
292
310
|
@adapter_registry.register(lang, adapter)
|
|
293
311
|
end
|
|
294
312
|
end
|
|
@@ -307,28 +325,9 @@ module Rubik
|
|
|
307
325
|
detail = rollback_errors.empty? ? "previous session state restored" : "rollback incomplete: #{rollback_errors}"
|
|
308
326
|
return ToolOutput.error("#{phase} failed for #{target} (#{lang}): #{e.message}; #{detail}")
|
|
309
327
|
end
|
|
310
|
-
|
|
311
|
-
# Keep one lifetime inverse per repaired key, preserving the original
|
|
312
|
-
# baseline across repeated repairs without retaining every transaction.
|
|
313
|
-
scope_key = [root_ctx, service_key]
|
|
314
|
-
if @repair_scopes.key?(scope_key)
|
|
315
|
-
released = true
|
|
316
|
-
promotion_ctx.dispose
|
|
317
|
-
else
|
|
318
|
-
@repair_scopes[scope_key] = promotion_ctx
|
|
319
|
-
end
|
|
320
|
-
|
|
321
|
-
if @config.nil? && ["lsp", "test_runner", "linter"].include?(target)
|
|
322
|
-
return "⚠️ Promoted '#{display_command(proposed_cmd)}' for #{target} (#{lang}) — no config is attached, " \
|
|
323
|
-
"so the command is active for this session only and was not saved."
|
|
324
|
-
end
|
|
325
|
-
|
|
326
|
-
"✨ Successfully verified and promoted runtime service for #{target} (#{lang}): '#{display_command(proposed_cmd)}'. " \
|
|
327
|
-
"Service is now active in the live context."
|
|
328
|
+
Promotion.new(promotion_ctx: promotion_ctx, service_key: service_key, state: state)
|
|
328
329
|
end
|
|
329
330
|
|
|
330
|
-
private
|
|
331
|
-
|
|
332
331
|
def verify_binary(target, lang, proposed_cmd, sub_ctx, probe_args: nil)
|
|
333
332
|
Rubik::Runtime::RepairProbe.new(root_dir: @root_dir, guard: @guard).verify(target, lang, proposed_cmd, sub_ctx, probe_args: probe_args)
|
|
334
333
|
end
|
|
@@ -373,3 +372,7 @@ module Rubik
|
|
|
373
372
|
end
|
|
374
373
|
end
|
|
375
374
|
end
|
|
375
|
+
|
|
376
|
+
# Named rollback objects for RepairRuntimeTool are kept in a companion file
|
|
377
|
+
# (required after the class definition so it reopens it safely).
|
|
378
|
+
require_relative "../lifecycle_rollbacks"
|
|
@@ -112,6 +112,9 @@ module Rubik
|
|
|
112
112
|
sealed_ctx = Rubik::Runtime::SynthesizedCommandContext.wrap(ctx, shell: @shell, runtime_manager: @runtime_manager)
|
|
113
113
|
proc_handler.call(cmd_args, sealed_ctx)
|
|
114
114
|
else
|
|
115
|
+
# Trust model (issue #398): this raw else-branch serves EXPLICITLY authored 3-arity handlers only — bare bodies are rejected upstream by the callable check, so default saves never land here.
|
|
116
|
+
# A 3-arity handler receives the RAW interactive shell (and its dispatch CommandContext via out_ctx) with `guard`, `config`, `buffer_manager`, etc. reachable — the SealedCoeffects deny-list does NOT apply.
|
|
117
|
+
# That is the operator-trusted bootstrap contract, anchored to the synthesis-gate vocabulary above: the code passed run_synthesis_gate here AND, when persisted, its disk hash is verified against the manifest on load (verify_integrity; RUBIK_TRUST_OVERLAYS=1 is the blanket operator override). Authoring a 3-arity proc is the deliberate escape hatch; 2-arity handlers and bare-body overlay saves are sealed.
|
|
115
118
|
out_ctx = if ctx
|
|
116
119
|
ctx
|
|
117
120
|
elsif @shell.respond_to?(:command_context)
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Named rollback objects for RepairRuntimeTool's promotion transaction
|
|
4
|
+
# (issue #427). Each replaces a former inline `on_dispose` closure, responds
|
|
5
|
+
# to #call and is executed in LIFO order by Context#dispose, keeping the
|
|
6
|
+
# rollback contract explicit and the promotion phase unit-testable.
|
|
7
|
+
module Rubik
|
|
8
|
+
module Tools
|
|
9
|
+
class RepairRuntimeTool
|
|
10
|
+
# Shared flag for the rollbacks of one promotion transaction: when a
|
|
11
|
+
# previous repair scope already owns the lifetime inverses for this key,
|
|
12
|
+
# execute marks the transaction released so these rollbacks stay inert.
|
|
13
|
+
RollbackState = Struct.new(:released)
|
|
14
|
+
|
|
15
|
+
# Result of a successful promotion phase.
|
|
16
|
+
Promotion = Struct.new(:promotion_ctx, :service_key, :state, keyword_init: true)
|
|
17
|
+
|
|
18
|
+
ServiceRollback = Struct.new(:root_ctx, :promotion_ctx, :service_key, :previous_services, :target, :lang,
|
|
19
|
+
:lsp_manager, :repair_scopes, :state, keyword_init: true) do
|
|
20
|
+
def call
|
|
21
|
+
return if state.released
|
|
22
|
+
|
|
23
|
+
repair_scopes.delete([root_ctx, service_key]) if repair_scopes[[root_ctx, service_key]].equal?(promotion_ctx)
|
|
24
|
+
restore_service unless root_ctx.disposed?
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
def restore_service
|
|
30
|
+
if previous_services.key?(service_key)
|
|
31
|
+
if target == "lsp"
|
|
32
|
+
restored = lsp_manager&.clients&.[](lang)
|
|
33
|
+
active = restored && (!restored.respond_to?(:alive?) || restored.alive?) &&
|
|
34
|
+
(!restored.respond_to?(:running?) || restored.running?)
|
|
35
|
+
if active
|
|
36
|
+
root_ctx.provide(service_key, restored)
|
|
37
|
+
else
|
|
38
|
+
root_ctx.unprovide(service_key)
|
|
39
|
+
end
|
|
40
|
+
else
|
|
41
|
+
root_ctx.provide(service_key, previous_services[service_key])
|
|
42
|
+
end
|
|
43
|
+
else
|
|
44
|
+
root_ctx.unprovide(service_key)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
ConfigRollback = Struct.new(:config, :cfg_key, :prev_cmd, :state, keyword_init: true) do
|
|
50
|
+
def call
|
|
51
|
+
return if state.released
|
|
52
|
+
|
|
53
|
+
prev_cmd.nil? ? config.delete(cfg_key) : config.set(cfg_key, prev_cmd)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
LspClientRollback = Struct.new(:lsp_manager, :lang, :config, :cfg_key, :prev_cmd, :root_ctx, :had_client,
|
|
58
|
+
:state, keyword_init: true) do
|
|
59
|
+
def call
|
|
60
|
+
return if state.released
|
|
61
|
+
|
|
62
|
+
lsp_manager.stop_client(lang)
|
|
63
|
+
prev_cmd.nil? ? config.delete(cfg_key) : config.set(cfg_key, prev_cmd)
|
|
64
|
+
return unless had_client && !root_ctx.disposed?
|
|
65
|
+
|
|
66
|
+
restored = lsp_manager.start_client(lang)
|
|
67
|
+
raise "Previous LSP client could not be restarted: #{restored}" unless restored[:ok]
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
AdapterFieldRollback = Struct.new(:adapter, :field, :old_value, :old_config, :state, keyword_init: true) do
|
|
72
|
+
def call
|
|
73
|
+
return if state.released
|
|
74
|
+
|
|
75
|
+
adapter.public_send("#{field}=", old_value)
|
|
76
|
+
adapter.config = old_config
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
AdapterUnregisterRollback = Struct.new(:adapter_registry, :lang, :adapter, :state, keyword_init: true) do
|
|
81
|
+
def call
|
|
82
|
+
adapter_registry.unregister(lang) if !state.released && adapter_registry.get(lang).equal?(adapter)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "open3"
|
|
4
|
+
require_relative "truncator"
|
|
4
5
|
|
|
5
6
|
begin
|
|
6
7
|
require "tty/which"
|
|
@@ -132,7 +133,7 @@ module Rubik
|
|
|
132
133
|
end
|
|
133
134
|
|
|
134
135
|
content = scrub_utf8(match[3])
|
|
135
|
-
content =
|
|
136
|
+
content = Rubik::Tools::Truncator.clip_line(content, 500) if content.length > 500
|
|
136
137
|
|
|
137
138
|
{
|
|
138
139
|
file: file.tr("\\", "/").sub(%r{\A\./}, ""),
|
|
@@ -189,6 +189,31 @@ module Rubik
|
|
|
189
189
|
str = str.scrub("") unless str.valid_encoding?
|
|
190
190
|
prefix ? "#{str}#{notice}" : "#{notice}#{str}"
|
|
191
191
|
end
|
|
192
|
+
|
|
193
|
+
# Canonical short-preview truncation for human/model-readable
|
|
194
|
+
# fragments: keep at most `limit` characters, then append one of the
|
|
195
|
+
# repo's two elision markers. `counted:` selects the spelling —
|
|
196
|
+
# "... [truncated N chars]" (default) or "... [truncated]". These two
|
|
197
|
+
# spellings, plus clip_line below, are the ONLY sanctioned preview
|
|
198
|
+
# markers; inline reimplementations feed downstream string matches
|
|
199
|
+
# that silently miss any other format.
|
|
200
|
+
def self.clip(text, limit, counted: true, separator: "")
|
|
201
|
+
str = text.to_s
|
|
202
|
+
return str if str.length <= limit
|
|
203
|
+
|
|
204
|
+
count = counted ? " #{str.length - limit} chars" : ""
|
|
205
|
+
"#{str[0, limit]}#{separator}... [truncated#{count}]"
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
# Line-fragment truncation for the search tools (native_search,
|
|
209
|
+
# builtins/grep): the kept window is INCLUSIVE (limit+1 characters)
|
|
210
|
+
# and the marker names the original total — pin both properties.
|
|
211
|
+
def self.clip_line(line, limit)
|
|
212
|
+
str = line.to_s
|
|
213
|
+
return str if str.length <= limit
|
|
214
|
+
|
|
215
|
+
"#{str[0..limit]}... [line truncated, #{str.length} chars total]"
|
|
216
|
+
end
|
|
192
217
|
end
|
|
193
218
|
end
|
|
194
219
|
end
|
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.9.
|
|
4
|
+
version: 0.9.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Özgür Ulukır
|
|
@@ -329,6 +329,7 @@ files:
|
|
|
329
329
|
- lib/rubik/log.rb
|
|
330
330
|
- lib/rubik/lsp.rb
|
|
331
331
|
- lib/rubik/lsp/client.rb
|
|
332
|
+
- lib/rubik/lsp/document_store.rb
|
|
332
333
|
- lib/rubik/lsp/manager.rb
|
|
333
334
|
- lib/rubik/lsp/server_command.rb
|
|
334
335
|
- lib/rubik/mcp.rb
|
|
@@ -357,6 +358,7 @@ files:
|
|
|
357
358
|
- lib/rubik/orchestrator/goal_ledger/verify_spec.rb
|
|
358
359
|
- lib/rubik/orchestrator/goal_ledger/xml_render.rb
|
|
359
360
|
- lib/rubik/orchestrator/goal_registry.rb
|
|
361
|
+
- lib/rubik/orchestrator/goal_session.rb
|
|
360
362
|
- lib/rubik/orchestrator/goal_state.rb
|
|
361
363
|
- lib/rubik/orchestrator/goal_wait.rb
|
|
362
364
|
- lib/rubik/orchestrator/loop.rb
|
|
@@ -503,6 +505,7 @@ files:
|
|
|
503
505
|
- lib/rubik/runtime/index_service.rb
|
|
504
506
|
- lib/rubik/runtime/loop_service.rb
|
|
505
507
|
- lib/rubik/runtime/manager.rb
|
|
508
|
+
- lib/rubik/runtime/manifest_store.rb
|
|
506
509
|
- lib/rubik/runtime/overlay_storage.rb
|
|
507
510
|
- lib/rubik/runtime/repair_probe.rb
|
|
508
511
|
- lib/rubik/runtime/sealed_coeffects.rb
|
|
@@ -521,6 +524,8 @@ files:
|
|
|
521
524
|
- lib/rubik/sandbox/runner.rb
|
|
522
525
|
- lib/rubik/sandbox/shell_resolver.rb
|
|
523
526
|
- lib/rubik/security.rb
|
|
527
|
+
- lib/rubik/security/allowlist.rb
|
|
528
|
+
- lib/rubik/security/audit_log.rb
|
|
524
529
|
- lib/rubik/security/blocked_guidance.rb
|
|
525
530
|
- lib/rubik/security/classifier.rb
|
|
526
531
|
- lib/rubik/security/classifier/classifier.rb
|
|
@@ -726,9 +731,12 @@ files:
|
|
|
726
731
|
- lib/rubik/security/classifier/parsers/bash_extractors.rb
|
|
727
732
|
- lib/rubik/security/classifier/parsers/powershell.rb
|
|
728
733
|
- lib/rubik/security/classifier/pwsh_rules.rb
|
|
734
|
+
- lib/rubik/security/command_gate.rb
|
|
729
735
|
- lib/rubik/security/errors.rb
|
|
730
736
|
- lib/rubik/security/guard.rb
|
|
737
|
+
- lib/rubik/security/path_policy.rb
|
|
731
738
|
- lib/rubik/security/redactor.rb
|
|
739
|
+
- lib/rubik/security/synthesis_gate.rb
|
|
732
740
|
- lib/rubik/session.rb
|
|
733
741
|
- lib/rubik/session/manager.rb
|
|
734
742
|
- lib/rubik/session/recorder.rb
|
|
@@ -743,6 +751,7 @@ files:
|
|
|
743
751
|
- lib/rubik/storage.rb
|
|
744
752
|
- lib/rubik/storage/folding.rb
|
|
745
753
|
- lib/rubik/storage/layout.rb
|
|
754
|
+
- lib/rubik/storage/ranking.rb
|
|
746
755
|
- lib/rubik/storage/render.rb
|
|
747
756
|
- lib/rubik/storage/service.rb
|
|
748
757
|
- lib/rubik/storage/store.rb
|
|
@@ -790,6 +799,7 @@ files:
|
|
|
790
799
|
- lib/rubik/tools/diagnostic_reporter.rb
|
|
791
800
|
- lib/rubik/tools/fuzzy_matcher.rb
|
|
792
801
|
- lib/rubik/tools/index_messages.rb
|
|
802
|
+
- lib/rubik/tools/lifecycle_rollbacks.rb
|
|
793
803
|
- lib/rubik/tools/native_search.rb
|
|
794
804
|
- lib/rubik/tools/output.rb
|
|
795
805
|
- lib/rubik/tools/preflight_runner.rb
|