rubik 0.9.1 → 0.11.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.
Files changed (138) hide show
  1. checksums.yaml +4 -4
  2. data/ATTRIBUTION.md +1 -1
  3. data/CHANGELOG.md +203 -1
  4. data/lib/rubik/adapter/base.rb +2 -1
  5. data/lib/rubik/adapter/process.rb +28 -67
  6. data/lib/rubik/ast/extractor.rb +2 -1
  7. data/lib/rubik/ast/treesitter_extractor.rb +2 -1
  8. data/lib/rubik/benchmark/vakanuvis_adoption.rb +12 -4
  9. data/lib/rubik/buffer/apply_contract.rb +3 -3
  10. data/lib/rubik/buffer/apply_transaction.rb +165 -0
  11. data/lib/rubik/buffer/manager.rb +26 -120
  12. data/lib/rubik/config/deep_ops.rb +4 -1
  13. data/lib/rubik/config/defaults.rb +6 -3
  14. data/lib/rubik/config/schema.rb +8 -0
  15. data/lib/rubik/config/secret_policy.rb +198 -0
  16. data/lib/rubik/config/store.rb +2 -1
  17. data/lib/rubik/config.rb +13 -2
  18. data/lib/rubik/context/ignore_rules.rb +193 -0
  19. data/lib/rubik/context/scanner.rb +46 -161
  20. data/lib/rubik/diagnostics/collector.rb +0 -9
  21. data/lib/rubik/errors.rb +15 -0
  22. data/lib/rubik/event_bus.rb +2 -1
  23. data/lib/rubik/kernel/dispatcher.rb +12 -7
  24. data/lib/rubik/kernel/unit.rb +4 -1
  25. data/lib/rubik/llm/client.rb +6 -200
  26. data/lib/rubik/llm/connection_pool.rb +104 -0
  27. data/lib/rubik/llm/registry.rb +13 -9
  28. data/lib/rubik/llm/router.rb +2 -5
  29. data/lib/rubik/llm/sse_parser.rb +110 -0
  30. data/lib/rubik/log.rb +21 -0
  31. data/lib/rubik/lsp/circuit_breaker.rb +98 -0
  32. data/lib/rubik/lsp/client.rb +77 -273
  33. data/lib/rubik/lsp/client_provisioner.rb +49 -0
  34. data/lib/rubik/lsp/manager.rb +67 -96
  35. data/lib/rubik/lsp/transport.rb +365 -0
  36. data/lib/rubik/mcp/boot_lifecycle.rb +6 -2
  37. data/lib/rubik/mcp/boot_run.rb +190 -0
  38. data/lib/rubik/mcp/manager.rb +55 -166
  39. data/lib/rubik/mcp/transport/stdio.rb +4 -1
  40. data/lib/rubik/orchestrator/auto_apply.rb +8 -6
  41. data/lib/rubik/orchestrator/continuation_manager.rb +3 -22
  42. data/lib/rubik/orchestrator/goal_ledger/ledger.rb +12 -1
  43. data/lib/rubik/orchestrator/goal_ledger/schema_vocabulary.rb +38 -0
  44. data/lib/rubik/orchestrator/goal_ledger/xml_render.rb +6 -1
  45. data/lib/rubik/orchestrator/goal_ledger.rb +1 -0
  46. data/lib/rubik/orchestrator/goal_session.rb +53 -39
  47. data/lib/rubik/orchestrator/loop.rb +28 -47
  48. data/lib/rubik/orchestrator/lsp_feedback.rb +1 -1
  49. data/lib/rubik/orchestrator/maestro_gate.rb +5 -7
  50. data/lib/rubik/orchestrator/provider_recovery.rb +4 -2
  51. data/lib/rubik/orchestrator/provider_resolver.rb +4 -2
  52. data/lib/rubik/orchestrator/resume_window.rb +96 -0
  53. data/lib/rubik/orchestrator/shell_deps.rb +16 -0
  54. data/lib/rubik/orchestrator/step_executor.rb +2 -1
  55. data/lib/rubik/orchestrator/stream_manager.rb +2 -1
  56. data/lib/rubik/orchestrator/subagent/deferred_spec.rb +4 -1
  57. data/lib/rubik/orchestrator/subagent/instance.rb +7 -12
  58. data/lib/rubik/orchestrator/subagent/lifecycle.rb +3 -1
  59. data/lib/rubik/orchestrator/subagent/notices.rb +2 -2
  60. data/lib/rubik/orchestrator/subagent/questioner.rb +3 -1
  61. data/lib/rubik/orchestrator/subagent/reaper.rb +3 -5
  62. data/lib/rubik/orchestrator/subagent/resilience.rb +4 -2
  63. data/lib/rubik/orchestrator/subagent/result_archive.rb +0 -4
  64. data/lib/rubik/orchestrator/subagent/run_cycle.rb +2 -7
  65. data/lib/rubik/orchestrator/subagent/spawn_transaction.rb +11 -2
  66. data/lib/rubik/orchestrator/subagent/step_runner.rb +10 -2
  67. data/lib/rubik/orchestrator/subagent/transcript_formatter.rb +2 -1
  68. data/lib/rubik/orchestrator/subagent/type_definition.rb +0 -4
  69. data/lib/rubik/orchestrator/tool_timeout.rb +121 -1
  70. data/lib/rubik/platform/io_drain.rb +5 -2
  71. data/lib/rubik/platform/process.rb +144 -54
  72. data/lib/rubik/platform.rb +2 -1
  73. data/lib/rubik/plugin/manager.rb +2 -1
  74. data/lib/rubik/plugin/storage.rb +8 -8
  75. data/lib/rubik/repl/commands/agent_context.rb +8 -7
  76. data/lib/rubik/repl/commands/agent_execution.rb +13 -32
  77. data/lib/rubik/repl/commands/agent_models.rb +4 -3
  78. data/lib/rubik/repl/commands/agent_providers.rb +43 -2
  79. data/lib/rubik/repl/commands/base.rb +47 -2
  80. data/lib/rubik/repl/commands/buffer.rb +5 -4
  81. data/lib/rubik/repl/commands/lsp.rb +2 -1
  82. data/lib/rubik/repl/commands/pruner.rb +2 -1
  83. data/lib/rubik/repl/commands/secrets.rb +151 -0
  84. data/lib/rubik/repl/commands/workspace.rb +60 -150
  85. data/lib/rubik/repl/commands/workspace_approval.rb +209 -0
  86. data/lib/rubik/repl/config_wiring.rb +8 -6
  87. data/lib/rubik/repl/hooks.rb +2 -1
  88. data/lib/rubik/repl/input_execution.rb +162 -79
  89. data/lib/rubik/repl/input_loop.rb +2 -1
  90. data/lib/rubik/repl/lifecycle.rb +60 -210
  91. data/lib/rubik/repl/notice_router.rb +319 -0
  92. data/lib/rubik/repl/paste_support.rb +3 -1
  93. data/lib/rubik/repl/presentation.rb +5 -3
  94. data/lib/rubik/repl/pruner/gate.rb +3 -1
  95. data/lib/rubik/repl/pruner/harness.rb +2 -1
  96. data/lib/rubik/repl/shell.rb +4 -3
  97. data/lib/rubik/repl/tee_io.rb +2 -1
  98. data/lib/rubik/repl/turn_recorder.rb +6 -5
  99. data/lib/rubik/runtime/ast_service.rb +2 -1
  100. data/lib/rubik/runtime/discovery.rb +3 -2
  101. data/lib/rubik/runtime/loop_service.rb +4 -3
  102. data/lib/rubik/runtime/manifest_store.rb +9 -1
  103. data/lib/rubik/runtime/overlay_guard.rb +127 -0
  104. data/lib/rubik/runtime/overlay_storage.rb +109 -163
  105. data/lib/rubik/runtime/task_manager.rb +64 -25
  106. data/lib/rubik/sandbox/driver/docker.rb +5 -1
  107. data/lib/rubik/sandbox/runner.rb +21 -19
  108. data/lib/rubik/security/audit_log.rb +2 -1
  109. data/lib/rubik/security/command_gate.rb +126 -243
  110. data/lib/rubik/security/guard.rb +7 -3
  111. data/lib/rubik/security/secret_store.rb +492 -0
  112. data/lib/rubik/security/segment_report.rb +161 -0
  113. data/lib/rubik/security/synthesis_gate.rb +8 -11
  114. data/lib/rubik/session/manager.rb +7 -1
  115. data/lib/rubik/session/recorder.rb +2 -1
  116. data/lib/rubik/skills/manager.rb +4 -4
  117. data/lib/rubik/storage/search.rb +49 -0
  118. data/lib/rubik/storage/store.rb +13 -20
  119. data/lib/rubik/storage/transcript_indexer.rb +3 -2
  120. data/lib/rubik/storage/vakanuvis/harness.rb +2 -3
  121. data/lib/rubik/storage/vakanuvis.rb +2 -1
  122. data/lib/rubik/tools/base.rb +22 -0
  123. data/lib/rubik/tools/builtins/files.rb +3 -15
  124. data/lib/rubik/tools/builtins/goal_ledger.rb +12 -1
  125. data/lib/rubik/tools/builtins/grep.rb +1 -6
  126. data/lib/rubik/tools/builtins/lifecycle.rb +6 -5
  127. data/lib/rubik/tools/builtins/synthesis.rb +3 -3
  128. data/lib/rubik/tools/lifecycle_rollbacks.rb +14 -1
  129. data/lib/rubik/tools/preflight_runner.rb +2 -1
  130. data/lib/rubik/tools/truncator.rb +48 -36
  131. data/lib/rubik/tools/uri_resolver.rb +3 -2
  132. data/lib/rubik/ui/banner.rb +4 -3
  133. data/lib/rubik/ui/capability.rb +1 -0
  134. data/lib/rubik/ui/spinner.rb +3 -1
  135. data/lib/rubik/ui/statusline.rb +6 -5
  136. data/lib/rubik/version.rb +1 -1
  137. data/lib/rubik.rb +4 -5
  138. metadata +20 -1
@@ -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.fetch("buffer.auto_apply", "manual")
150
- can_m = ctx.config.fetch("buffer.model_can_apply", true)
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.fetch('buffer.prompt_indicator', true)}"
155
- ctx.out.puts " • Reminder Interval: #{ctx.config.fetch('buffer.reminder_interval', 3)} turns"
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.fetch("lsp.servers", {})&.keys || [])).map(&:to_s).uniq.sort
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.fetch("subagents.pruner.enabled", true)
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
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "base"
4
+ require_relative "../../storage/layout"
5
+ require_relative "workspace_approval"
4
6
 
5
7
  module Rubik
6
8
  module REPL
@@ -50,7 +52,7 @@ module Rubik
50
52
  end
51
53
 
52
54
  private_class_method def self.handle_allow_cmd_list(ctx)
53
- entries = Array(ctx.config.fetch("security.command_allowlist", []))
55
+ entries = Array(Rubik::Storage::Layout.config_get(ctx.config, "security.command_allowlist", []))
54
56
  ctx.out.puts "=== Allowed Command Prefixes (operator allowlist) ==="
55
57
  if entries.empty?
56
58
  ctx.out.puts " (No command prefixes allowlisted — unknown/dangerous commands stay blocked)"
@@ -59,64 +61,13 @@ module Rubik
59
61
  end
60
62
  end
61
63
 
64
+ # Thin adapter: approval/trust logic lives in CommandPrefixApproval.
62
65
  private_class_method def self.handle_allow_cmd_add(ctx, tokens_to_add, scope)
63
- entry_tokens = tokens_to_add.reject { |a| a == "--force" }
64
- entry = entry_tokens.join(" ").strip
65
- if entry.empty?
66
- ctx.out.puts 'Usage: !allow-cmd add "<command prefix>" [--project|--global] [--force]'
67
- return
68
- end
69
-
70
- tokens = entry.split(/\s+/)
71
- # Fail closed (G3 triage, Priority-1 site): a classifier crash
72
- # must not silently skip the broad-token RCE check — treat the
73
- # token as broad and let the operator pass a narrow prefix.
74
- broad = begin
75
- base = Rubik::Security::Classifier.classify(tokens.first)
76
- base.classification == :dangerous && tokens.size == 1
77
- rescue StandardError => e
78
- Rubik::Log.warn(:security, "classifier failed for '#{tokens.first}' (#{e.class}: #{e.message}); treating as broad")
79
- true
80
- end
81
-
82
- # Fail-closed against unbounded execution: a broad, single-token
83
- # dangerous entry (e.g. "node", "python", "bash") grants
84
- # command execution for EVERY invocation of that binary, so
85
- # `node` → `node -e 'malicious()'` RCE. Such broad tokens are
86
- # blocked with or without --force — the operator should use a
87
- # narrow prefix (e.g. "node .gitnexus/run.cjs").
88
- if broad
89
- ctx.out.puts "Blocked: '#{entry}' is a broad, single-token dangerous command. Even with --force it grants " \
90
- "unbounded command execution (e.g. `#{tokens.first} -e 'malicious(...)'` RCE). " \
91
- "Use a narrow prefix instead (e.g. \"#{tokens.first} <script>\")."
92
- return
93
- end
94
-
95
- # The catastrophic destructive-pattern fallback always runs:
96
- # a dangerous multi-token entry may never add `rm -rf /`-style
97
- # chains to the allowlist, with or without --force.
98
- catastrophic = false
99
- begin
100
- ctx.guard.verify_command_fallback_regex!(entry)
101
- rescue Rubik::Security::BlockedWriteError => e
102
- ctx.out.puts "Blocked: '#{entry}' matches a catastrophic destructive pattern and cannot be allowlisted: #{e.message}"
103
- catastrophic = true
104
- end
105
- return if catastrophic
106
-
107
- current = Array(ctx.config.fetch("security.command_allowlist", [])).dup
108
- if current.include?(entry)
109
- ctx.out.puts "[Rubik::AllowCmd] '#{entry}' is already allowlisted."
110
- return
111
- end
112
- current << entry
113
- res = ctx.config.set("security.command_allowlist", current, persist: scope)
114
- ctx.guard&.log_audit("allowlist_add", command: entry, scope: scope)
115
- return if Base.report_persist_failure(ctx, res, scope)
116
-
117
- ctx.out.puts "[Rubik::AllowCmd] Added command prefix: #{entry} [#{Base.scope_label(scope)}]."
66
+ approval = CommandPrefixApproval.new(config: ctx.config, out: ctx.out, guard: ctx.guard)
67
+ approval.add(tokens_to_add, scope)
118
68
  end
119
69
 
70
+ # Thin adapter: allowlist mutation lives in CommandPrefixApproval.
120
71
  private_class_method def self.handle_allow_cmd_remove(ctx, clean_args, scope)
121
72
  entry = clean_args[1..].join(" ").strip
122
73
  if entry.empty?
@@ -124,17 +75,8 @@ module Rubik
124
75
  return
125
76
  end
126
77
 
127
- current = Array(ctx.config.fetch("security.command_allowlist", [])).dup
128
- unless current.include?(entry)
129
- ctx.out.puts "[Rubik::AllowCmd] '#{entry}' is not in the allowlist."
130
- return
131
- end
132
- current.delete(entry)
133
- res = ctx.config.set("security.command_allowlist", current, persist: scope)
134
- ctx.guard&.log_audit("allowlist_remove", command: entry, scope: scope)
135
- return if Base.report_persist_failure(ctx, res, scope)
136
-
137
- ctx.out.puts "[Rubik::AllowCmd] Removed command prefix: #{entry} [#{Base.scope_label(scope)}]."
78
+ approval = CommandPrefixApproval.new(config: ctx.config, out: ctx.out, guard: ctx.guard)
79
+ approval.remove(entry, scope)
138
80
  end
139
81
 
140
82
  private_class_method def self.register_workspace_command(shell)
@@ -172,7 +114,7 @@ module Rubik
172
114
  allowed_ext = ctx.buffer_manager&.allowed_external_dirs || []
173
115
  rw_allowed_set = ctx.buffer_manager&.rw_allowed_dirs || Set.new
174
116
  glob_rw = ctx.buffer_manager&.allow_external_writes || false
175
- auto_idx = ctx.config.fetch("workspace.auto_index_additional", true)
117
+ auto_idx = Rubik::Storage::Layout.config_get(ctx.config, "workspace.auto_index_additional", true)
176
118
 
177
119
  ctx.out.puts "=== Configured Workspace Roots ==="
178
120
  ctx.out.puts " • [PRIMARY] #{effective_root} (Read-Write)"
@@ -199,80 +141,52 @@ module Rubik
199
141
  ctx.out.puts "Auto-Index Additional Roots : #{auto_idx}"
200
142
  end
201
143
 
144
+ # Thin adapter: trust + mutation + persistence live in
145
+ # WorkspaceApproval (allow external dir, mode flipped from --ro).
202
146
  private_class_method def self.handle_workspace_allow(target_path, ctx, is_ro, scope)
203
147
  if target_path.nil? || target_path.empty?
204
148
  ctx.out.puts "Usage: !workspace allow <path> [--rw|--ro] [--project|--global]"
205
149
  return
206
150
  end
207
151
 
208
- begin
209
- ctx.guard.verify_root_safety!(target_path)
210
- rescue Rubik::Security::BlockedWriteError => e
211
- ctx.out.puts "Security Error: #{e.message}"
212
- return
213
- end
214
-
215
- mode_rw = !is_ro
216
- expanded = ctx.buffer_manager.add_allowed_dir(target_path, rw: mode_rw)
217
- ctx.sandbox_runner&.add_allowed_dir(target_path)
218
-
219
- current_dirs = Array(ctx.config.fetch("workspace.allowed_external_dirs", [])).dup
220
- current_dirs << target_path unless current_dirs.include?(target_path)
221
- res = ctx.config.set("workspace.allowed_external_dirs", current_dirs, persist: scope)
222
- return if Base.report_persist_failure(ctx, res, scope)
223
-
224
- mode_str = mode_rw ? "Read-Write" : "Read-Only"
225
- ctx.out.puts "[Rubik::Allow] Added allowed external directory: #{expanded} (Mode: #{mode_str}) [#{Base.scope_label(scope)}]."
152
+ approval = build_workspace_approval(target_path, ctx, read_write: !is_ro, scope: scope)
153
+ approval.allow_dir! if approval.trusted?
226
154
  end
227
155
 
156
+ # Thin adapter: trust + mutation + persistence live in
157
+ # WorkspaceApproval (additional root).
228
158
  private_class_method def self.handle_workspace_add(target_path, ctx, is_rw, scope)
229
159
  if target_path.nil? || target_path.empty?
230
160
  ctx.out.puts "Usage: !workspace add <path> [--rw] [--project|--global]"
231
161
  return
232
162
  end
233
163
 
234
- begin
235
- ctx.guard.verify_root_safety!(target_path)
236
- rescue Rubik::Security::BlockedWriteError => e
237
- ctx.out.puts "Security Error: #{e.message}"
238
- return
239
- end
240
-
241
- expanded = ctx.buffer_manager.add_root(target_path, rw: is_rw)
242
-
243
- # Sync context index & AST coeffects
244
- auto_idx = ctx.config.fetch("workspace.auto_index_additional", true)
245
- ctx.sync_workspace_index! if auto_idx
246
-
247
- # Persist to config
248
- current_roots = Array(ctx.config.fetch("workspace.additional_roots", [])).dup
249
- current_roots << target_path unless current_roots.include?(target_path)
250
- res = ctx.config.set("workspace.additional_roots", current_roots, persist: scope)
251
- return if Base.report_persist_failure(ctx, res, scope)
252
-
253
- mode_str = is_rw ? "Read-Write" : "Read-Only"
254
- ctx.out.puts "[Rubik::Workspace] Added additional root: #{expanded} (Mode: #{mode_str}) [#{Base.scope_label(scope)}]."
164
+ approval = build_workspace_approval(target_path, ctx, read_write: is_rw, scope: scope)
165
+ approval.add_root! if approval.trusted?
255
166
  end
256
167
 
168
+ # Thin adapter: mutation + persistence live in WorkspaceApproval.
257
169
  private_class_method def self.handle_workspace_remove(target_path, ctx, scope, effective_root)
258
170
  if target_path.nil? || target_path.empty?
259
171
  ctx.out.puts "Usage: !workspace remove <path> [--project|--global]"
260
172
  return
261
173
  end
262
174
 
263
- expanded = ctx.buffer_manager.remove_root(target_path)
264
-
265
- # Sync context index & AST coeffects
266
- auto_idx = ctx.config.fetch("workspace.auto_index_additional", true)
267
- ctx.sync_workspace_index! if auto_idx
268
-
269
- # Persist to config
270
- current_roots = Array(ctx.config.fetch("workspace.additional_roots", [])).dup
271
- current_roots.reject! { |r| File.expand_path(r, effective_root) == expanded || r == target_path }
272
- res = ctx.config.set("workspace.additional_roots", current_roots, persist: scope)
273
- return if Base.report_persist_failure(ctx, res, scope)
175
+ approval = build_workspace_approval(target_path, ctx, read_write: false, scope: scope, effective_root: effective_root)
176
+ approval.remove_root!
177
+ end
274
178
 
275
- ctx.out.puts "[Rubik::Workspace] Removed additional root: #{expanded} [#{Base.scope_label(scope)}]."
179
+ # Explicit dependency wiring (AGENTS.md §5): the value object gets
180
+ # every collaborator injected from ctx — no ambient lookups.
181
+ private_class_method def self.build_workspace_approval(path, ctx, read_write:, scope:, effective_root: nil)
182
+ WorkspaceApproval.new(path: path, read_write: read_write, scope: scope,
183
+ config: ctx.config,
184
+ buffer_manager: ctx.buffer_manager,
185
+ out: ctx.out,
186
+ guard: ctx.guard,
187
+ sandbox_runner: ctx.sandbox_runner,
188
+ index_sync: -> { ctx.sync_workspace_index! },
189
+ effective_root: effective_root)
276
190
  end
277
191
 
278
192
  private_class_method def self.register_allow_command(shell)
@@ -335,48 +249,27 @@ module Rubik
335
249
  end
336
250
  end
337
251
 
252
+ # Thin adapter: mutation + persistence live in WorkspaceApproval.
338
253
  private_class_method def self.handle_allow_remove(target_path, ctx, scope, effective_root)
339
254
  if target_path.nil? || target_path.empty?
340
255
  ctx.out.puts "Usage: !allow remove <path> [--project|--global]"
341
256
  return
342
257
  end
343
258
 
344
- expanded = ctx.buffer_manager&.remove_allowed_dir(target_path)
345
- ctx.sandbox_runner&.remove_allowed_dir(target_path)
346
-
347
- # Persist to config
348
- current_dirs = Array(ctx.config.fetch("workspace.allowed_external_dirs", [])).dup
349
- current_dirs.reject! { |d| File.expand_path(d, effective_root) == expanded || d == target_path }
350
- res = ctx.config.set("workspace.allowed_external_dirs", current_dirs, persist: scope)
351
- return if Base.report_persist_failure(ctx, res, scope)
352
-
353
- ctx.out.puts "[Rubik::Allow] Removed allowed external directory: #{expanded} [#{Base.scope_label(scope)}]."
259
+ approval = build_workspace_approval(target_path, ctx, read_write: false, scope: scope, effective_root: effective_root)
260
+ approval.remove_allowed_dir!
354
261
  end
355
262
 
263
+ # Thin adapter: trust + mutation + persistence live in
264
+ # WorkspaceApproval (allow external dir).
356
265
  private_class_method def self.handle_allow_add(target_path, ctx, scope, mode_rw)
357
266
  if target_path.nil? || target_path.empty?
358
267
  ctx.out.puts "Usage: !allow add <path> [--rw|--ro] [--project|--global]"
359
268
  return
360
269
  end
361
270
 
362
- begin
363
- ctx.guard.verify_root_safety!(target_path)
364
- rescue Rubik::Security::BlockedWriteError => e
365
- ctx.out.puts "Security Error: #{e.message}"
366
- return
367
- end
368
-
369
- expanded = ctx.buffer_manager.add_allowed_dir(target_path, rw: mode_rw)
370
- ctx.sandbox_runner&.add_allowed_dir(target_path)
371
-
372
- # Persist to config (Zero-AST / Zero-Scanner: No IndexService or AST warm)
373
- current_dirs = Array(ctx.config.fetch("workspace.allowed_external_dirs", [])).dup
374
- current_dirs << target_path unless current_dirs.include?(target_path)
375
- res = ctx.config.set("workspace.allowed_external_dirs", current_dirs, persist: scope)
376
- return if Base.report_persist_failure(ctx, res, scope)
377
-
378
- mode_str = mode_rw ? "Read-Write" : "Read-Only"
379
- ctx.out.puts "[Rubik::Allow] Added allowed external directory: #{expanded} (Mode: #{mode_str}) [#{Base.scope_label(scope)}]."
271
+ approval = build_workspace_approval(target_path, ctx, read_write: mode_rw, scope: scope)
272
+ approval.allow_dir! if approval.trusted?
380
273
  end
381
274
 
382
275
  OPERATOR_ONLY_CONFIG_PREFIXES = [
@@ -409,6 +302,18 @@ module Rubik
409
302
  end
410
303
  end
411
304
 
305
+ # Secrets never render: plaintext shows as the redaction mask, while
306
+ # a rubik-secret: pointer prints as-is (it names a location, not a
307
+ # credential). Shared by get/set-echo/list so the three surfaces
308
+ # cannot drift.
309
+ private_class_method def self.display_value(key, val)
310
+ if Rubik::Config::SecretPolicy.secret_key?(key) && !Rubik::Security::SecretStore.reference?(val)
311
+ Rubik::Security::Redactor::MASK_STRING
312
+ else
313
+ val
314
+ end
315
+ end
316
+
412
317
  private_class_method def self.register_config_command(shell)
413
318
  shell.register_command("config", description: "Get, set, or view runtime configuration (set|get|list|path)",
414
319
  usage: USAGE_CONFIG, audience: :both) do |args, ctx|
@@ -429,7 +334,7 @@ module Rubik
429
334
  if val.nil?
430
335
  ctx.out.puts "Config '#{key}' is not set or empty."
431
336
  else
432
- ctx.out.puts "#{key} = #{val}"
337
+ ctx.out.puts "#{key} = #{display_value(key, val)}"
433
338
  end
434
339
  end
435
340
  elsif sub == "set"
@@ -445,7 +350,12 @@ module Rubik
445
350
  res = ctx.config.set(key, val, persist: scope)
446
351
  next if Base.report_persist_failure(ctx, res, scope)
447
352
 
448
- ctx.out.puts "Config '#{key}' updated to '#{val}' [#{Base.scope_label(scope)}]."
353
+ ctx.out.puts "Config '#{key}' updated to '#{display_value(key, val)}' [#{Base.scope_label(scope)}]."
354
+ if (info = res[:secret]) && info[:stored]
355
+ ctx.out.puts " Secret stored via #{info[:backend]} secret store; the config file holds only a reference."
356
+ elsif (info = res[:secret]) && info[:warning]
357
+ ctx.out.puts " Warning: #{info[:warning]}"
358
+ end
449
359
  end
450
360
  elsif sub == "list"
451
361
  filter = clean_args[1]&.downcase
@@ -468,7 +378,7 @@ module Rubik
468
378
  else
469
379
  ctx.out.puts "=== Rubik Configuration (#{matched.size} entries) ==="
470
380
  matched.sort.each do |k, v|
471
- ctx.out.puts " • #{k.ljust(35)} = #{v.inspect}"
381
+ ctx.out.puts " • #{k.ljust(35)} = #{display_value(k, v).inspect}"
472
382
  end
473
383
  end
474
384
  else