rubik 0.9.1 → 0.10.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 +143 -1
- data/lib/rubik/adapter/base.rb +2 -1
- data/lib/rubik/adapter/process.rb +28 -67
- data/lib/rubik/benchmark/vakanuvis_adoption.rb +10 -3
- data/lib/rubik/buffer/apply_contract.rb +3 -3
- data/lib/rubik/buffer/apply_transaction.rb +165 -0
- data/lib/rubik/buffer/manager.rb +26 -120
- data/lib/rubik/config/deep_ops.rb +4 -1
- data/lib/rubik/config/defaults.rb +6 -3
- data/lib/rubik/config/schema.rb +8 -0
- data/lib/rubik/config/secret_policy.rb +197 -0
- data/lib/rubik/config.rb +11 -0
- data/lib/rubik/diagnostics/collector.rb +0 -9
- data/lib/rubik/errors.rb +15 -0
- data/lib/rubik/event_bus.rb +2 -1
- data/lib/rubik/kernel/dispatcher.rb +12 -7
- data/lib/rubik/kernel/unit.rb +4 -1
- data/lib/rubik/llm/registry.rb +12 -9
- data/lib/rubik/llm/router.rb +2 -5
- data/lib/rubik/log.rb +21 -0
- data/lib/rubik/lsp/client.rb +77 -273
- data/lib/rubik/lsp/manager.rb +14 -10
- data/lib/rubik/lsp/transport.rb +365 -0
- data/lib/rubik/mcp/boot_lifecycle.rb +6 -2
- data/lib/rubik/mcp/boot_run.rb +190 -0
- data/lib/rubik/mcp/manager.rb +40 -163
- data/lib/rubik/mcp/transport/stdio.rb +4 -1
- data/lib/rubik/orchestrator/auto_apply.rb +4 -3
- data/lib/rubik/orchestrator/continuation_manager.rb +3 -22
- data/lib/rubik/orchestrator/goal_session.rb +53 -39
- data/lib/rubik/orchestrator/loop.rb +28 -47
- data/lib/rubik/orchestrator/maestro_gate.rb +5 -7
- data/lib/rubik/orchestrator/provider_recovery.rb +4 -2
- data/lib/rubik/orchestrator/provider_resolver.rb +4 -2
- data/lib/rubik/orchestrator/resume_window.rb +96 -0
- data/lib/rubik/orchestrator/shell_deps.rb +16 -0
- data/lib/rubik/orchestrator/stream_manager.rb +2 -1
- data/lib/rubik/orchestrator/subagent/deferred_spec.rb +4 -1
- data/lib/rubik/orchestrator/subagent/instance.rb +7 -12
- data/lib/rubik/orchestrator/subagent/lifecycle.rb +3 -1
- data/lib/rubik/orchestrator/subagent/questioner.rb +3 -1
- data/lib/rubik/orchestrator/subagent/reaper.rb +3 -5
- data/lib/rubik/orchestrator/subagent/resilience.rb +4 -2
- data/lib/rubik/orchestrator/subagent/result_archive.rb +0 -4
- data/lib/rubik/orchestrator/subagent/run_cycle.rb +2 -7
- data/lib/rubik/orchestrator/subagent/spawn_transaction.rb +11 -2
- data/lib/rubik/orchestrator/subagent/step_runner.rb +10 -2
- data/lib/rubik/orchestrator/subagent/type_definition.rb +0 -4
- data/lib/rubik/orchestrator/tool_timeout.rb +121 -1
- data/lib/rubik/platform/io_drain.rb +2 -1
- data/lib/rubik/platform/process.rb +144 -54
- data/lib/rubik/platform.rb +2 -1
- data/lib/rubik/plugin/manager.rb +2 -1
- data/lib/rubik/repl/commands/agent_context.rb +8 -7
- data/lib/rubik/repl/commands/agent_execution.rb +13 -32
- data/lib/rubik/repl/commands/agent_models.rb +4 -3
- data/lib/rubik/repl/commands/agent_providers.rb +43 -2
- data/lib/rubik/repl/commands/base.rb +47 -2
- data/lib/rubik/repl/commands/buffer.rb +5 -4
- data/lib/rubik/repl/commands/lsp.rb +2 -1
- data/lib/rubik/repl/commands/pruner.rb +2 -1
- data/lib/rubik/repl/commands/secrets.rb +151 -0
- data/lib/rubik/repl/commands/workspace.rb +60 -150
- data/lib/rubik/repl/commands/workspace_approval.rb +209 -0
- data/lib/rubik/repl/config_wiring.rb +3 -3
- data/lib/rubik/repl/hooks.rb +2 -1
- data/lib/rubik/repl/input_execution.rb +158 -76
- data/lib/rubik/repl/input_loop.rb +2 -1
- data/lib/rubik/repl/lifecycle.rb +59 -209
- data/lib/rubik/repl/notice_router.rb +319 -0
- data/lib/rubik/repl/paste_support.rb +3 -1
- data/lib/rubik/repl/presentation.rb +5 -3
- data/lib/rubik/repl/pruner/gate.rb +3 -1
- data/lib/rubik/repl/pruner/harness.rb +2 -1
- data/lib/rubik/repl/shell.rb +4 -3
- data/lib/rubik/repl/turn_recorder.rb +6 -5
- data/lib/rubik/runtime/discovery.rb +3 -2
- data/lib/rubik/runtime/loop_service.rb +4 -3
- data/lib/rubik/runtime/manifest_store.rb +9 -1
- data/lib/rubik/runtime/overlay_guard.rb +127 -0
- data/lib/rubik/runtime/overlay_storage.rb +92 -146
- data/lib/rubik/runtime/task_manager.rb +64 -25
- data/lib/rubik/sandbox/driver/docker.rb +5 -1
- data/lib/rubik/sandbox/runner.rb +16 -15
- data/lib/rubik/security/command_gate.rb +117 -93
- data/lib/rubik/security/guard.rb +6 -2
- data/lib/rubik/security/secret_store.rb +463 -0
- data/lib/rubik/security/synthesis_gate.rb +8 -11
- data/lib/rubik/session/manager.rb +7 -1
- data/lib/rubik/skills/manager.rb +2 -3
- data/lib/rubik/storage/search.rb +49 -0
- data/lib/rubik/storage/store.rb +13 -20
- data/lib/rubik/storage/vakanuvis/harness.rb +2 -3
- data/lib/rubik/tools/base.rb +22 -0
- data/lib/rubik/tools/builtins/files.rb +3 -15
- data/lib/rubik/tools/builtins/grep.rb +1 -6
- data/lib/rubik/tools/builtins/lifecycle.rb +6 -5
- data/lib/rubik/tools/lifecycle_rollbacks.rb +14 -1
- data/lib/rubik/tools/truncator.rb +48 -36
- data/lib/rubik/ui/banner.rb +4 -3
- data/lib/rubik/ui/spinner.rb +3 -1
- data/lib/rubik/ui/statusline.rb +6 -5
- data/lib/rubik/version.rb +1 -1
- data/lib/rubik.rb +1 -2
- metadata +13 -1
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative "base"
|
|
4
4
|
require_relative "../../llm"
|
|
5
|
+
require_relative "secrets"
|
|
5
6
|
|
|
6
7
|
module Rubik
|
|
7
8
|
module REPL
|
|
@@ -19,6 +20,7 @@ module Rubik
|
|
|
19
20
|
def self.register(shell)
|
|
20
21
|
register_provider_command(shell)
|
|
21
22
|
register_providers_command(shell)
|
|
23
|
+
register_secrets_command(shell)
|
|
22
24
|
end
|
|
23
25
|
|
|
24
26
|
private_class_method def self.register_provider_command(shell)
|
|
@@ -111,6 +113,7 @@ module Rubik
|
|
|
111
113
|
|
|
112
114
|
ctx.out.puts "Successfully added provider '#{p_name}' (#{p_type} -> #{normalized_endpoint}) " \
|
|
113
115
|
"with model '#{m_name}' [#{Base.scope_label(scope)}]."
|
|
116
|
+
render_secret_stored_line(res, ctx) if api_key
|
|
114
117
|
end
|
|
115
118
|
|
|
116
119
|
private_class_method def self.handle_add_provider_model(clean_args, ctx, scope)
|
|
@@ -163,7 +166,11 @@ module Rubik
|
|
|
163
166
|
return
|
|
164
167
|
end
|
|
165
168
|
|
|
166
|
-
|
|
169
|
+
# provider_spec returns the @data-resident Hash: dup before
|
|
170
|
+
# mutating, so a refused write (e.g. :project plaintext secret)
|
|
171
|
+
# never leaves plaintext behind in runtime memory or poisons the
|
|
172
|
+
# next whole-Hash write of an unrelated field.
|
|
173
|
+
p_spec = ctx.config.provider_spec(p_name)&.dup
|
|
167
174
|
if p_spec.nil?
|
|
168
175
|
ctx.out.puts "Provider '#{p_name}' not found."
|
|
169
176
|
return
|
|
@@ -194,7 +201,22 @@ module Rubik
|
|
|
194
201
|
ctx.refresh_llm_registry!
|
|
195
202
|
return if Base.report_persist_failure(ctx, res, scope)
|
|
196
203
|
|
|
197
|
-
|
|
204
|
+
shown_val = ["key", "api_key"].include?(field) ? Rubik::Security::Redactor::MASK_STRING : val
|
|
205
|
+
ctx.out.puts "Updated provider '#{p_name}' field '#{field}' to '#{shown_val}' [#{Base.scope_label(scope)}]."
|
|
206
|
+
render_secret_stored_line(res, ctx) if ["key", "api_key", "key-env", "key_env", "api_key_env"].include?(field)
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
# One honest line about where the credential went: the config file
|
|
210
|
+
# holds only a rubik-secret: pointer when the store took the value.
|
|
211
|
+
private_class_method def self.render_secret_stored_line(res, ctx)
|
|
212
|
+
info = res[:secret]
|
|
213
|
+
return if info.nil?
|
|
214
|
+
|
|
215
|
+
if info[:stored]
|
|
216
|
+
ctx.out.puts " API key stored via #{info[:backend]} secret store; the config file holds only a reference."
|
|
217
|
+
elsif info[:warning]
|
|
218
|
+
ctx.out.puts " Warning: #{info[:warning]}"
|
|
219
|
+
end
|
|
198
220
|
end
|
|
199
221
|
|
|
200
222
|
private_class_method def self.handle_remove_provider(clean_args, ctx, scope)
|
|
@@ -207,6 +229,14 @@ module Rubik
|
|
|
207
229
|
res = ctx.config.remove_provider(p_name, persist: scope)
|
|
208
230
|
ctx.refresh_llm_registry!
|
|
209
231
|
if res[:ok]
|
|
232
|
+
# Best-effort hygiene: drop the provider's stored secret in both
|
|
233
|
+
# scope slots (the write guard suffixes project-scope names).
|
|
234
|
+
begin
|
|
235
|
+
Rubik::Security::SecretStore.delete("providers.#{p_name}.api_key")
|
|
236
|
+
Rubik::Security::SecretStore.delete("providers.#{p_name}.api_key.project")
|
|
237
|
+
rescue Rubik::Security::SecretStore::Error
|
|
238
|
+
nil
|
|
239
|
+
end
|
|
210
240
|
ctx.out.puts "Removed provider '#{p_name}' [#{Base.scope_label(scope)}]."
|
|
211
241
|
elsif res[:reason] == :unknown_provider
|
|
212
242
|
ctx.out.puts "Provider '#{p_name}' not found."
|
|
@@ -241,6 +271,17 @@ module Rubik
|
|
|
241
271
|
end
|
|
242
272
|
end
|
|
243
273
|
|
|
274
|
+
# !secrets rides this module's registration plumbing (the command
|
|
275
|
+
# domain is provider credentials); its handlers live in Secrets.
|
|
276
|
+
private_class_method def self.register_secrets_command(shell)
|
|
277
|
+
shell.register_command("secrets",
|
|
278
|
+
description: "Manage stored provider credentials " \
|
|
279
|
+
"(backend | list | has <name> | delete <name> | migrate)",
|
|
280
|
+
usage: Rubik::REPL::Commands::Secrets::USAGE_SECRETS) do |args, ctx|
|
|
281
|
+
Secrets.dispatch(args, ctx)
|
|
282
|
+
end
|
|
283
|
+
end
|
|
284
|
+
|
|
244
285
|
# Shared rendering for !provider list (human) and !providers (agent):
|
|
245
286
|
# same catalog, same pixels — only the audience differs. Pinned
|
|
246
287
|
# byte-for-byte by TestProviderCatalogRender.
|
|
@@ -46,8 +46,53 @@ module Rubik
|
|
|
46
46
|
Base.report_persist_failure(ctx, res, scope)
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
# Pre-execution buffer auto-apply choreography shared by the !test
|
|
50
|
+
# and !sh commands: when the buffer is dirty, apply-and-sync if the
|
|
51
|
+
# buffer.auto_apply policy allows, else print the honest unapplied
|
|
52
|
+
# warning. label/subject parameterize the two message spellings so
|
|
53
|
+
# each command keeps its pinned wording. Orchestrator::AutoApply
|
|
54
|
+
# stays the policy's single home — this only mediates the REPL ctx
|
|
55
|
+
# wiring.
|
|
56
|
+
def self.pre_execution_apply(ctx, label, subject)
|
|
57
|
+
return unless ctx.buffer_manager&.dirty?
|
|
58
|
+
|
|
59
|
+
if Rubik::Orchestrator::AutoApply.apply?(ctx.config, trigger: :pre_execution)
|
|
60
|
+
applied = Rubik::Orchestrator::AutoApply.apply_and_sync(ctx.buffer_manager, ctx)
|
|
61
|
+
ctx.out.puts Rubik::Orchestrator::AutoApply.applied_line(applied.size, label)
|
|
62
|
+
else
|
|
63
|
+
ctx.out.puts Rubik::Orchestrator::AutoApply.unapplied_warning(subject)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Adapter resolution shared by the adapter-backed commands
|
|
68
|
+
# (!test/!lint/!format): the command argument names the language
|
|
69
|
+
# when given, else the project's primary language is detected;
|
|
70
|
+
# "ruby" is the honest fallback when neither resolves.
|
|
71
|
+
def self.adapter_for(ctx, lang_arg = nil)
|
|
72
|
+
lang = lang_arg || Rubik::Runtime::Discovery.detect_primary_language(Dir.pwd) || "ruby"
|
|
73
|
+
ctx.adapter_registry.get(lang) || ctx.adapter_registry.get("ruby")
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Shared failure-diagnostic line for the adapter-backed commands:
|
|
77
|
+
# prints the category + suggestion when the run failed with a
|
|
78
|
+
# diagnostic. `tip` appends an optional command-specific hint line.
|
|
79
|
+
def self.render_diagnostic(ctx, res, tip: nil)
|
|
80
|
+
return unless !res[:ok] && res[:diagnostic]
|
|
81
|
+
|
|
82
|
+
ctx.out.puts "\n🔍 [Diagnostic] #{res[:diagnostic].category.to_s.upcase}: #{res[:diagnostic].suggestion}"
|
|
83
|
+
ctx.out.puts tip if tip
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def pre_execution_apply(ctx, label, subject)
|
|
87
|
+
Base.pre_execution_apply(ctx, label, subject)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def adapter_for(ctx, lang_arg = nil)
|
|
91
|
+
Base.adapter_for(ctx, lang_arg)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def render_diagnostic(ctx, res, tip: nil)
|
|
95
|
+
Base.render_diagnostic(ctx, res, tip: tip)
|
|
51
96
|
end
|
|
52
97
|
end
|
|
53
98
|
end
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative "base"
|
|
4
|
+
require_relative "../../storage/layout"
|
|
4
5
|
require_relative "../../buffer/apply_contract"
|
|
5
6
|
|
|
6
7
|
module Rubik
|
|
@@ -146,13 +147,13 @@ module Rubik
|
|
|
146
147
|
sub = clean_args.first&.downcase
|
|
147
148
|
|
|
148
149
|
if sub.nil? || sub == "status"
|
|
149
|
-
cur = ctx.config
|
|
150
|
-
can_m = ctx.config
|
|
150
|
+
cur = Rubik::Storage::Layout.config_get(ctx.config, "buffer.auto_apply", "manual")
|
|
151
|
+
can_m = Rubik::Storage::Layout.config_get(ctx.config, "buffer.model_can_apply", true)
|
|
151
152
|
ctx.out.puts "Buffer Auto-Apply Policy:"
|
|
152
153
|
ctx.out.puts " • Mode : #{cur} (manual | on_test | on_finish | always)"
|
|
153
154
|
ctx.out.puts " • Model Can Apply : #{can_m}"
|
|
154
|
-
ctx.out.puts " • Prompt Indicator : #{ctx.config
|
|
155
|
-
ctx.out.puts " • Reminder Interval: #{ctx.config
|
|
155
|
+
ctx.out.puts " • Prompt Indicator : #{Rubik::Storage::Layout.config_get(ctx.config, 'buffer.prompt_indicator', true)}"
|
|
156
|
+
ctx.out.puts " • Reminder Interval: #{Rubik::Storage::Layout.config_get(ctx.config, 'buffer.reminder_interval', 3)} turns"
|
|
156
157
|
elsif ["manual", "on_test", "on_finish", "always"].include?(sub)
|
|
157
158
|
if ctx.agent_caller
|
|
158
159
|
ctx.out.puts "Security Error: buffer autoapply policy is operator-only and cannot be altered by autonomous agents."
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative "base"
|
|
4
4
|
require_relative "../../tools"
|
|
5
|
+
require_relative "../../storage/layout"
|
|
5
6
|
|
|
6
7
|
module Rubik
|
|
7
8
|
module REPL
|
|
@@ -162,7 +163,7 @@ module Rubik
|
|
|
162
163
|
|
|
163
164
|
private_class_method def self.handle_lsp_start(lang, ctx)
|
|
164
165
|
if lang.nil? || lang.empty?
|
|
165
|
-
supported = (Rubik::LSP::Client::SERVERS.keys + (ctx.config
|
|
166
|
+
supported = (Rubik::LSP::Client::SERVERS.keys + (Rubik::Storage::Layout.config_get(ctx.config, "lsp.servers", {})&.keys || [])).map(&:to_s).uniq.sort
|
|
166
167
|
ctx.out.puts "Usage: !lsp start <#{supported.join('|')}>"
|
|
167
168
|
else
|
|
168
169
|
res = ctx.lsp_manager.start_client(lang)
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative "base"
|
|
4
4
|
require_relative "../../coeffects"
|
|
5
|
+
require_relative "../../storage/layout"
|
|
5
6
|
|
|
6
7
|
module Rubik
|
|
7
8
|
module REPL
|
|
@@ -53,7 +54,7 @@ module Rubik
|
|
|
53
54
|
# sokardı — teşhis (boot warn + dmesg) adı adına söylenir.
|
|
54
55
|
def self.unbound_message(ctx)
|
|
55
56
|
knob = begin
|
|
56
|
-
ctx.config
|
|
57
|
+
Rubik::Storage::Layout.config_get(ctx.config, "subagents.pruner.enabled", true)
|
|
57
58
|
rescue StandardError
|
|
58
59
|
true
|
|
59
60
|
end
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "base"
|
|
4
|
+
require_relative "../../security/secret_store"
|
|
5
|
+
|
|
6
|
+
module Rubik
|
|
7
|
+
module REPL
|
|
8
|
+
module Commands
|
|
9
|
+
# Domain handler for credential storage hygiene (!secrets).
|
|
10
|
+
#
|
|
11
|
+
# The REPL never displays or accepts raw secret values here: `list`
|
|
12
|
+
# shows only statuses, migration reads plaintext only to hand it to
|
|
13
|
+
# SecretStore and rewrite references, and delete/has operate on names.
|
|
14
|
+
module Secrets
|
|
15
|
+
extend Base
|
|
16
|
+
|
|
17
|
+
# Whole-command synopsis: shared by the spine registration in
|
|
18
|
+
# AgentProviders (register_secrets_command) and the unknown-
|
|
19
|
+
# subcommand fallback branch, so the two cannot drift.
|
|
20
|
+
USAGE_SECRETS = "Usage: !secrets <backend | list | has <name> | delete <name> | migrate>"
|
|
21
|
+
|
|
22
|
+
def self.dispatch(args, ctx)
|
|
23
|
+
sub = args.first&.downcase
|
|
24
|
+
case sub
|
|
25
|
+
when nil, "", "backend"
|
|
26
|
+
render_backend(ctx)
|
|
27
|
+
when "list"
|
|
28
|
+
render_inventory(ctx)
|
|
29
|
+
when "has"
|
|
30
|
+
render_has(args[1], ctx)
|
|
31
|
+
when "delete"
|
|
32
|
+
handle_delete(args[1], ctx)
|
|
33
|
+
when "migrate"
|
|
34
|
+
handle_migrate(ctx)
|
|
35
|
+
else
|
|
36
|
+
ctx.out.puts USAGE_SECRETS
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
private_class_method def self.render_backend(ctx)
|
|
41
|
+
ctx.out.puts "Secret store backend: #{Rubik::Security::SecretStore.backend_name}"
|
|
42
|
+
return unless Rubik::Security::SecretStore.backend_name == :file
|
|
43
|
+
|
|
44
|
+
ctx.out.puts " (no OS keyring available — secrets live in ~/.rubik/secrets.yml, owner-only 0600)"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Inventory over the merged config: every provider's api_key leaf
|
|
48
|
+
# reported by kind. Values are never printed.
|
|
49
|
+
private_class_method def self.render_inventory(ctx)
|
|
50
|
+
providers = ctx.config.fetch("providers")
|
|
51
|
+
unless providers.is_a?(Hash) && providers.any?
|
|
52
|
+
ctx.out.puts "No providers configured."
|
|
53
|
+
return
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
ctx.out.puts "=== Stored provider credentials (#{Rubik::Security::SecretStore.backend_name}) ==="
|
|
57
|
+
providers.each do |p_name, spec|
|
|
58
|
+
next unless spec.is_a?(Hash)
|
|
59
|
+
|
|
60
|
+
key_path = "providers.#{p_name}.api_key"
|
|
61
|
+
status =
|
|
62
|
+
if Rubik::Security::SecretStore.reference?(spec["api_key"])
|
|
63
|
+
"stored in secret store (reference)"
|
|
64
|
+
elsif spec["api_key"].is_a?(String) && !spec["api_key"].empty?
|
|
65
|
+
"PLAINTEXT — migrate this key: !secrets migrate"
|
|
66
|
+
elsif spec["api_key_env"].is_a?(String) && !spec["api_key_env"].empty?
|
|
67
|
+
"read from environment variable #{spec['api_key_env']}"
|
|
68
|
+
else
|
|
69
|
+
"not set"
|
|
70
|
+
end
|
|
71
|
+
ctx.out.puts " • #{key_path}: #{status}"
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
private_class_method def self.render_has(name, ctx)
|
|
76
|
+
if name.nil? || name.to_s.empty?
|
|
77
|
+
ctx.out.puts "Usage: !secrets has <name> (a dot-path like providers.openai.api_key)"
|
|
78
|
+
return
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
stored = begin
|
|
82
|
+
!Rubik::Security::SecretStore.fetch(name.to_s).nil?
|
|
83
|
+
rescue Rubik::Security::SecretStore::Error
|
|
84
|
+
false
|
|
85
|
+
end
|
|
86
|
+
ctx.out.puts stored ? "#{name}: stored" : "#{name}: not stored"
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
private_class_method def self.handle_delete(name, ctx)
|
|
90
|
+
if name.nil? || name.to_s.empty?
|
|
91
|
+
ctx.out.puts "Usage: !secrets delete <name> (a dot-path like providers.openai.api_key)"
|
|
92
|
+
return
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
begin
|
|
96
|
+
Rubik::Security::SecretStore.delete(name.to_s)
|
|
97
|
+
ctx.out.puts "Deleted stored secret '#{name}'."
|
|
98
|
+
rescue Rubik::Security::SecretStore::Error => e
|
|
99
|
+
ctx.out.puts "Error: #{e.message}"
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# Moves every plaintext provider api_key into the secret store and
|
|
104
|
+
# rewrites its config entry as a rubik-secret: reference, in the
|
|
105
|
+
# scope where the plaintext lived. Walks both persisted layers so
|
|
106
|
+
# a provider keyed in global AND project is migrated in both.
|
|
107
|
+
# Session-only values are left alone (they die with the process).
|
|
108
|
+
private_class_method def self.handle_migrate(ctx)
|
|
109
|
+
migrated = 0
|
|
110
|
+
failed = 0
|
|
111
|
+
skipped = 0
|
|
112
|
+
[:project, :global].each do |scope|
|
|
113
|
+
layer = scope == :project ? ctx.config.project_layer : ctx.config.global_layer
|
|
114
|
+
providers = layer["providers"].to_h
|
|
115
|
+
providers.each do |p_name, spec|
|
|
116
|
+
next unless spec.is_a?(Hash)
|
|
117
|
+
|
|
118
|
+
key_path = "providers.#{p_name}.api_key"
|
|
119
|
+
raw = spec["api_key"]
|
|
120
|
+
unless raw.is_a?(String) && !raw.empty? && !Rubik::Security::SecretStore.reference?(raw)
|
|
121
|
+
skipped += 1
|
|
122
|
+
next
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# Same name convention as the write guard: project-scoped
|
|
126
|
+
# secrets carry a ".project"-suffixed store name so the two
|
|
127
|
+
# scopes never swap each other's credential.
|
|
128
|
+
store_name = Rubik::Config::SecretPolicy.secret_name(key_path, scope)
|
|
129
|
+
ref = Rubik::Security::SecretStore.set(store_name, raw)
|
|
130
|
+
res = ctx.config.set(key_path, ref, persist: scope)
|
|
131
|
+
unless res[:ok]
|
|
132
|
+
failed += 1
|
|
133
|
+
ctx.out.puts " - #{key_path} [#{scope}]: FAILED — #{res[:error]}"
|
|
134
|
+
next
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
migrated += 1
|
|
138
|
+
backend = res.dig(:secret, :backend) || Rubik::Security::SecretStore.backend_name
|
|
139
|
+
ctx.out.puts " + #{key_path}: migrated to #{backend} [#{scope}]"
|
|
140
|
+
rescue Rubik::Security::SecretStore::Error => e
|
|
141
|
+
failed += 1
|
|
142
|
+
ctx.out.puts " - #{key_path} [#{scope}]: FAILED — #{e.message}"
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
ctx.refresh_llm_registry!
|
|
146
|
+
ctx.out.puts "Migration complete: #{migrated} migrated, #{failed} failed, #{skipped} skipped."
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
end
|