rubik 0.9.0 → 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 +250 -43
- data/README.md +5 -1
- data/lib/rubik/adapter/base.rb +21 -1
- data/lib/rubik/adapter/generic.rb +0 -14
- data/lib/rubik/adapter/node.rb +2 -0
- data/lib/rubik/adapter/process.rb +28 -67
- data/lib/rubik/ast/treesitter/zig_walker.rb +15 -2
- 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/cli/workspace_trust.rb +16 -0
- data/lib/rubik/config/deep_ops.rb +4 -1
- data/lib/rubik/config/defaults.rb +29 -3
- data/lib/rubik/config/schema.rb +8 -0
- data/lib/rubik/config/secret_policy.rb +197 -0
- data/lib/rubik/config/store.rb +14 -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 +16 -11
- 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 +23 -1
- data/lib/rubik/lsp/client.rb +152 -445
- data/lib/rubik/lsp/document_store.rb +209 -0
- 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/client.rb +4 -3
- data/lib/rubik/mcp/manager.rb +46 -165
- data/lib/rubik/mcp/transport/stdio.rb +55 -10
- 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 +519 -0
- 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 +11 -12
- data/lib/rubik/orchestrator/subagent/journal.rb +2 -1
- data/lib/rubik/orchestrator/subagent/lifecycle.rb +3 -1
- data/lib/rubik/orchestrator/subagent/questioner.rb +24 -7
- 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 +11 -3
- data/lib/rubik/orchestrator/subagent/teardown.rb +4 -0
- data/lib/rubik/orchestrator/subagent/transcript_formatter.rb +2 -1
- data/lib/rubik/orchestrator/subagent/type_definition.rb +0 -4
- data/lib/rubik/orchestrator/tool_timeout.rb +121 -1
- data/lib/rubik/orchestrator.rb +1 -0
- data/lib/rubik/platform/io_drain.rb +2 -1
- data/lib/rubik/platform/process.rb +144 -54
- data/lib/rubik/platform.rb +17 -1
- data/lib/rubik/plugin/manager.rb +2 -1
- data/lib/rubik/plugin/storage.rb +20 -29
- data/lib/rubik/repl/commands/agent_context.rb +9 -8
- data/lib/rubik/repl/commands/agent_execution.rb +20 -502
- 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 +6 -5
- data/lib/rubik/repl/commands/lsp.rb +3 -2
- 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 +3 -2
- data/lib/rubik/repl/lifecycle.rb +82 -204
- 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 +124 -0
- data/lib/rubik/runtime/overlay_guard.rb +127 -0
- data/lib/rubik/runtime/overlay_storage.rb +269 -272
- data/lib/rubik/runtime/task_manager.rb +71 -27
- data/lib/rubik/runtime.rb +1 -0
- data/lib/rubik/sandbox/driver/docker.rb +5 -1
- data/lib/rubik/sandbox/runner.rb +16 -15
- 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 +591 -0
- data/lib/rubik/security/guard.rb +94 -1077
- data/lib/rubik/security/path_policy.rb +117 -0
- data/lib/rubik/security/secret_store.rb +463 -0
- data/lib/rubik/security/synthesis_gate.rb +297 -0
- data/lib/rubik/security.rb +5 -0
- data/lib/rubik/session/manager.rb +7 -1
- data/lib/rubik/skills/manager.rb +2 -3
- data/lib/rubik/storage/ranking.rb +113 -0
- data/lib/rubik/storage/search.rb +49 -0
- data/lib/rubik/storage/store.rb +15 -112
- data/lib/rubik/storage/transcript_indexer.rb +2 -3
- 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 +3 -9
- data/lib/rubik/tools/builtins/lifecycle.rb +96 -92
- data/lib/rubik/tools/builtins/synthesis.rb +3 -0
- data/lib/rubik/tools/lifecycle_rollbacks.rb +100 -0
- data/lib/rubik/tools/native_search.rb +2 -1
- data/lib/rubik/tools/truncator.rb +73 -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 +23 -1
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../security/secret_store"
|
|
4
|
+
|
|
5
|
+
module Rubik
|
|
6
|
+
class Config
|
|
7
|
+
# Secret-write policy — the single choke point over Config#set/#delete.
|
|
8
|
+
#
|
|
9
|
+
# Two rules, enforced where every write funnels:
|
|
10
|
+
# 1. Route: a plaintext value at a secret-looking path is stored in
|
|
11
|
+
# the OS keyring (SecretStore) and the config file only ever
|
|
12
|
+
# receives the "rubik-secret:<name>" pointer. Works for both
|
|
13
|
+
# direct paths (providers.x.api_key) and whole-provider Hash
|
|
14
|
+
# writes (!provider set/add rewrite providers.<n> as a Hash).
|
|
15
|
+
# 2. Guard: plaintext secrets are refused for the :project scope —
|
|
16
|
+
# project files sit inside a git worktree and leak through
|
|
17
|
+
# commits, copies, and shares. Escape hatch:
|
|
18
|
+
# security.allow_project_secrets (schema-backed boolean, default
|
|
19
|
+
# false). Secrets already stored as references are pointers, not
|
|
20
|
+
# credentials, and may live anywhere.
|
|
21
|
+
#
|
|
22
|
+
# Interface used by callers:
|
|
23
|
+
# - Config includes the instance helpers (guard_secret_write,
|
|
24
|
+
# warn_plaintext_project_secrets, secret_key?).
|
|
25
|
+
# - REPL surfaces use Rubik::Config::SecretPolicy.secret_key? to
|
|
26
|
+
# mask secret values in display output.
|
|
27
|
+
module SecretPolicy
|
|
28
|
+
# Dot-paths that end in an api_key leaf, e.g.
|
|
29
|
+
# "providers.openai.api_key" or a bare "api_key".
|
|
30
|
+
SECRET_LEAF_PATTERN = /\A(?:[\w-]+\.)*api_key\z/
|
|
31
|
+
|
|
32
|
+
module_function
|
|
33
|
+
|
|
34
|
+
def secret_key?(key)
|
|
35
|
+
key.to_s.match?(SECRET_LEAF_PATTERN)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Store-name convention shared by the write guard and `!secrets
|
|
39
|
+
# migrate`: project-scope secrets get a ".project"-suffixed name so a
|
|
40
|
+
# project-scoped credential can never silently overwrite (or be
|
|
41
|
+
# overwritten by) the global one under a shared pointer.
|
|
42
|
+
def secret_name(path, scope)
|
|
43
|
+
scope.to_s.downcase.to_sym == :project ? "#{path}.project" : path.to_s
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Instance-side helpers (included into Config, private there).
|
|
47
|
+
|
|
48
|
+
# Returns nil when the write needs no secret handling; otherwise
|
|
49
|
+
# { block: "<error message>" } -> refuse the write outright
|
|
50
|
+
# { info: {...} } -> write proceeds as-is
|
|
51
|
+
# { typed_val:, info: {...} } -> write proceeds with the
|
|
52
|
+
# Hash rewritten to hold
|
|
53
|
+
# references
|
|
54
|
+
# persist follows Config#set's scope vocabulary (nil/"session" keep
|
|
55
|
+
# the value in memory only — in-process plaintext is out of scope).
|
|
56
|
+
def guard_secret_write(key, typed_val, persist)
|
|
57
|
+
return nil unless persisting?(persist)
|
|
58
|
+
|
|
59
|
+
leaves = collect_secret_leaves(key, typed_val)
|
|
60
|
+
raw = leaves.select { |path, val| secret_leaf?(path, val) }
|
|
61
|
+
return nil if raw.empty?
|
|
62
|
+
|
|
63
|
+
scope = persist.to_s.downcase.to_sym == :project ? :project : :global
|
|
64
|
+
# security.allow_project_secrets=true restores the legacy behavior:
|
|
65
|
+
# project writes act like global ones — the store is still
|
|
66
|
+
# preferred, but a store failure degrades to plaintext + warning
|
|
67
|
+
# instead of refusing the write. The override resolves ONLY from
|
|
68
|
+
# operator domains (global layer / env): a project config can never
|
|
69
|
+
# enable it for itself, or the guard would be self-serve bypassable
|
|
70
|
+
# by any repo-shipped .rubik/config.yml.
|
|
71
|
+
legacy_plaintext_ok = project_secrets_override
|
|
72
|
+
return { block: project_secret_error(leaves) } if scope == :project && !legacy_plaintext_ok
|
|
73
|
+
|
|
74
|
+
rewritten = deep_dup(typed_val)
|
|
75
|
+
stored = []
|
|
76
|
+
raw.each do |path, val|
|
|
77
|
+
store_error = nil
|
|
78
|
+
ref = nil
|
|
79
|
+
begin
|
|
80
|
+
ref = Rubik::Security::SecretStore.set(secret_name(path, scope), val)
|
|
81
|
+
rescue Rubik::Security::SecretStore::Error => e
|
|
82
|
+
store_error = e
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
if store_error
|
|
86
|
+
# gh-style degradation: the write proceeds with plaintext plus a
|
|
87
|
+
# loud warning — except for :project, which refuses unless the
|
|
88
|
+
# operator explicitly accepted the risk.
|
|
89
|
+
return { block: "#{project_secret_error(leaves)} (secret store failed: #{store_error.message})" } if scope == :project && !legacy_plaintext_ok
|
|
90
|
+
|
|
91
|
+
warn_secret_store_fallback(store_error, scope)
|
|
92
|
+
return { info: plaintext_fallback_info }
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# Leaf paths are full config dot-paths; the rewrite target is the
|
|
96
|
+
# typed_val subtree, so strip the write root ("providers.<n>."
|
|
97
|
+
# for whole-Hash writes). A direct leaf write carries no subtree,
|
|
98
|
+
# so the value itself becomes the pointer.
|
|
99
|
+
if rewritten.is_a?(Hash)
|
|
100
|
+
deep_set_key(rewritten, path.delete_prefix("#{key}."), ref)
|
|
101
|
+
else
|
|
102
|
+
rewritten = ref
|
|
103
|
+
end
|
|
104
|
+
stored << path
|
|
105
|
+
end
|
|
106
|
+
{ typed_val: rewritten, info: { stored: true, backend: Rubik::Security::SecretStore.backend_name, names: stored } }
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# Boot-time honesty: surface plaintext keys already sitting in the
|
|
110
|
+
# project layer (legacy configs, hand-edited files).
|
|
111
|
+
def warn_plaintext_project_secrets
|
|
112
|
+
leaves = collect_secret_leaves("", @project_layer.to_h)
|
|
113
|
+
raw = leaves.select { |path, val| secret_leaf?(path, val) }
|
|
114
|
+
return if raw.empty?
|
|
115
|
+
|
|
116
|
+
@warnings << "Project config #{project_config_path} holds plaintext API key(s) at " \
|
|
117
|
+
"#{raw.map(&:first).join(', ')}. They can leak through commits or shared copies — " \
|
|
118
|
+
"run `!secrets migrate`, move them to --global, or set api_key_env instead."
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
# Keyring hygiene for Config#delete: a successfully persisted delete
|
|
122
|
+
# of an api_key path also drops its stored secret(s) — both scopes'
|
|
123
|
+
# names, so neither keyring entry outlives its reference. Best-effort
|
|
124
|
+
# — never masks res.
|
|
125
|
+
def cleanup_stored_secret(key, res, persist)
|
|
126
|
+
return unless secret_key?(key) && res[:ok] && persisting?(persist)
|
|
127
|
+
|
|
128
|
+
Rubik::Security::SecretStore.delete(key.to_s)
|
|
129
|
+
Rubik::Security::SecretStore.delete("#{key}.project")
|
|
130
|
+
rescue Rubik::Security::SecretStore::Error
|
|
131
|
+
nil
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
private
|
|
135
|
+
|
|
136
|
+
# Operator-trust domains only (env layer, then global layer). The
|
|
137
|
+
# merged fetch is deliberately NOT used: the project layer could
|
|
138
|
+
# otherwise re-enable plaintext-in-project from inside the repo.
|
|
139
|
+
def project_secrets_override
|
|
140
|
+
[@env_layer, @global_layer].any? do |layer|
|
|
141
|
+
layer.is_a?(Hash) && layer.dig("security", "allow_project_secrets") == true
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# Depth-first walk collecting [dot-path, value] pairs for every
|
|
146
|
+
# api_key leaf inside a whole-Hash write (e.g. providers.<n>).
|
|
147
|
+
def collect_secret_leaves(prefix, obj)
|
|
148
|
+
leaves = []
|
|
149
|
+
case obj
|
|
150
|
+
when Hash
|
|
151
|
+
obj.each do |k, v|
|
|
152
|
+
full = prefix.to_s.empty? ? k.to_s : "#{prefix}.#{k}"
|
|
153
|
+
leaves.concat(collect_secret_leaves(full, v))
|
|
154
|
+
end
|
|
155
|
+
when Array
|
|
156
|
+
obj.each_with_index do |v, i|
|
|
157
|
+
leaves.concat(collect_secret_leaves(prefix.empty? ? i.to_s : "#{prefix}.#{i}", v))
|
|
158
|
+
end
|
|
159
|
+
else
|
|
160
|
+
leaves << [prefix.to_s, obj] if secret_key?(prefix)
|
|
161
|
+
end
|
|
162
|
+
leaves
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
# A raw secret at a secret path: a non-empty plaintext String, or a
|
|
166
|
+
# Numeric (parse_scalar_value coerces "12345" to an Integer before the
|
|
167
|
+
# guard runs — a digit-only api_key must not slip past). References
|
|
168
|
+
# and nils are pointers / clears and always allowed.
|
|
169
|
+
def secret_leaf?(path, val)
|
|
170
|
+
return false unless secret_key?(path)
|
|
171
|
+
return false if val.nil? || Rubik::Security::SecretStore.reference?(val)
|
|
172
|
+
|
|
173
|
+
(val.is_a?(String) && !val.empty?) || val.is_a?(Numeric)
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
def project_secret_error(leaves)
|
|
177
|
+
paths = leaves.map(&:first).join(", ")
|
|
178
|
+
"refusing to store plaintext secret(s) at #{paths} in the project config " \
|
|
179
|
+
"(#{project_config_path}): project files live inside the repository and leak through " \
|
|
180
|
+
"commits or shared copies. Use --global, set providers.<name>.api_key_env to read the key " \
|
|
181
|
+
"from the environment, or run `!secrets migrate`. Override only if you accept the risk: " \
|
|
182
|
+
"security.allow_project_secrets = true."
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
def warn_secret_store_fallback(error, scope)
|
|
186
|
+
msg = "OS secret store unavailable (#{error.message}); plaintext kept in #{scope} config"
|
|
187
|
+
@warnings << msg
|
|
188
|
+
warn "[WARN] #{msg}" if ENV["RUBIK_DEBUG"]
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
def plaintext_fallback_info
|
|
192
|
+
{ stored: false, backend: Rubik::Security::SecretStore.backend_name,
|
|
193
|
+
warning: "secret store unavailable; plaintext kept in config" }
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
end
|
|
197
|
+
end
|
data/lib/rubik/config/store.rb
CHANGED
|
@@ -67,6 +67,7 @@ module Rubik
|
|
|
67
67
|
nil
|
|
68
68
|
end
|
|
69
69
|
store = store_for(scope_sym)
|
|
70
|
+
ensure_owner_only!(target_path)
|
|
70
71
|
|
|
71
72
|
validation_error = nil
|
|
72
73
|
store.transaction do
|
|
@@ -136,6 +137,19 @@ module Rubik
|
|
|
136
137
|
|
|
137
138
|
private
|
|
138
139
|
|
|
140
|
+
# Provider api_key values persist in these stores, so the file must be
|
|
141
|
+
# owner-only from the first byte on disk. YAML::Store creates a missing
|
|
142
|
+
# file with the process umask (typically 0644); pre-creating at 0600
|
|
143
|
+
# closes the window before the first transaction opens it. A chmod
|
|
144
|
+
# failure keeps the legacy best-effort behavior instead of failing the
|
|
145
|
+
# save.
|
|
146
|
+
def ensure_owner_only!(path)
|
|
147
|
+
FileUtils.touch(path) unless File.exist?(path)
|
|
148
|
+
File.chmod(0o600, path)
|
|
149
|
+
rescue SystemCallError
|
|
150
|
+
nil
|
|
151
|
+
end
|
|
152
|
+
|
|
139
153
|
def ensure_rubik_directories
|
|
140
154
|
rubik_home = File.join(@home_dir, ".rubik")
|
|
141
155
|
["snapshots", "sessions", "commands", "tools"].each do |sub|
|
data/lib/rubik/config.rb
CHANGED
|
@@ -8,6 +8,7 @@ require_relative "config/model_catalog"
|
|
|
8
8
|
require_relative "config/pruner"
|
|
9
9
|
require_relative "config/schema"
|
|
10
10
|
require_relative "config/env_loader"
|
|
11
|
+
require_relative "config/secret_policy"
|
|
11
12
|
require_relative "config/scoped"
|
|
12
13
|
|
|
13
14
|
module Rubik
|
|
@@ -16,6 +17,7 @@ module Rubik
|
|
|
16
17
|
include DeepOps
|
|
17
18
|
include Store
|
|
18
19
|
include ModelCatalog
|
|
20
|
+
include SecretPolicy
|
|
19
21
|
|
|
20
22
|
DEFAULT_CONFIG = Defaults::DEFAULT_CONFIG
|
|
21
23
|
SENSITIVE_PROJECT_CONFIG_KEYS = DeepOps::SENSITIVE_PROJECT_CONFIG_KEYS
|
|
@@ -89,6 +91,11 @@ module Rubik
|
|
|
89
91
|
validate_schema(typed_val, section, key.to_s) if section.is_a?(Hash) && !section.empty?
|
|
90
92
|
end
|
|
91
93
|
|
|
94
|
+
policy = guard_secret_write(key, typed_val, persist)
|
|
95
|
+
return { ok: false, error: policy[:block] } if policy&.key?(:block)
|
|
96
|
+
|
|
97
|
+
typed_val = policy[:typed_val] if policy&.key?(:typed_val)
|
|
98
|
+
|
|
92
99
|
deep_set_key(@data, key, typed_val)
|
|
93
100
|
|
|
94
101
|
if persisting?(persist)
|
|
@@ -102,6 +109,7 @@ module Rubik
|
|
|
102
109
|
|
|
103
110
|
res = persisting?(persist) ? persist_result(save!(persist)) : { ok: true }
|
|
104
111
|
res[:reason] = :persist_failed unless res[:ok]
|
|
112
|
+
res[:secret] = policy[:info] if policy&.key?(:info)
|
|
105
113
|
notify_change(key, typed_val, old_val) if old_val != typed_val
|
|
106
114
|
res
|
|
107
115
|
end
|
|
@@ -159,6 +167,7 @@ module Rubik
|
|
|
159
167
|
notify_change(key, new_val, old_val)
|
|
160
168
|
@event_bus&.emit(:config_deleted, key: key.to_s, old_val: old_val)
|
|
161
169
|
end
|
|
170
|
+
cleanup_stored_secret(key, res, persist)
|
|
162
171
|
res
|
|
163
172
|
end
|
|
164
173
|
end
|
|
@@ -290,6 +299,8 @@ module Rubik
|
|
|
290
299
|
@env_layer = EnvLoader.load_env(ENV, DEFAULT_CONFIG, @warnings)
|
|
291
300
|
@session_layer = {}
|
|
292
301
|
|
|
302
|
+
warn_plaintext_project_secrets
|
|
303
|
+
|
|
293
304
|
recompute_data!
|
|
294
305
|
validate_schema(@data)
|
|
295
306
|
@data
|
|
@@ -37,15 +37,6 @@ module Rubik
|
|
|
37
37
|
@mutex.synchronize { @entries << entry }
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
-
# Adds multiple Entry objects
|
|
41
|
-
def add_entries(entries)
|
|
42
|
-
return unless entries.is_a?(Array)
|
|
43
|
-
|
|
44
|
-
@mutex.synchronize do
|
|
45
|
-
entries.each { |e| @entries << e if e.is_a?(Entry) }
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
40
|
# Parses CLI compiler/linter output and adds entries
|
|
50
41
|
def add_parsed(output, lang: :unknown, source: :compiler) # rubocop:disable Lint/UnusedMethodArgument -- cagiran arayüzüyle uyum için source kwarg'i korunuyor
|
|
51
42
|
parsed = Parser.parse(output, lang)
|
data/lib/rubik/errors.rb
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Rubik
|
|
4
|
+
# Root of the unified error taxonomy (issue #448): every module-level
|
|
5
|
+
# error class hangs off Rubik::Error so callers can rescue one class.
|
|
6
|
+
# Standalone-requireable — submodule files that define errors require
|
|
7
|
+
# this file instead of the full lib/rubik.rb entry point.
|
|
8
|
+
class Error < StandardError; end
|
|
9
|
+
|
|
10
|
+
# Shared state-machine violation vocabulary (issue #448): the per-module
|
|
11
|
+
# StateError classes (subagent Lifecycle, DeferredSpec, MCP BootLifecycle,
|
|
12
|
+
# kernel Unit) subclass this, so rescuing Rubik::StateError catches any
|
|
13
|
+
# guarded-transition tripwire without knowing the module.
|
|
14
|
+
class StateError < Error; end
|
|
15
|
+
end
|
data/lib/rubik/event_bus.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "logger"
|
|
4
|
+
require_relative "log"
|
|
4
5
|
require_relative "kernel/dispatcher"
|
|
5
6
|
|
|
6
7
|
module Rubik
|
|
@@ -10,7 +11,7 @@ module Rubik
|
|
|
10
11
|
class EventBus
|
|
11
12
|
attr_reader :dispatcher
|
|
12
13
|
|
|
13
|
-
def initialize(dispatcher: nil, logger:
|
|
14
|
+
def initialize(dispatcher: nil, logger: Rubik::Log.forwarder(:event_bus))
|
|
14
15
|
@logger = logger
|
|
15
16
|
@dispatcher = dispatcher || Rubik::Kernel::Dispatcher.new(logger: @logger)
|
|
16
17
|
end
|
|
@@ -29,8 +29,6 @@ module Rubik
|
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
def post(event_name, payload = {}, subsystem: :kernel, level: :info, facility_id: nil, **kwargs)
|
|
32
|
-
return false if stopped?
|
|
33
|
-
|
|
34
32
|
eff_payload = if kwargs.empty?
|
|
35
33
|
payload || {}
|
|
36
34
|
elsif payload.is_a?(Hash)
|
|
@@ -39,12 +37,19 @@ module Rubik
|
|
|
39
37
|
kwargs
|
|
40
38
|
end
|
|
41
39
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
# The stopped check and the queue push must be atomic: an unlocked
|
|
41
|
+
# check-then-push let an event land after the worker consumed
|
|
42
|
+
# STOP_MARKER during shutdown, stranding it forever.
|
|
43
|
+
@lock.synchronize do
|
|
44
|
+
return false if @stopped
|
|
45
|
+
|
|
46
|
+
@queue.push(
|
|
47
|
+
Event.new(
|
|
48
|
+
name: event_name.to_sym, payload: eff_payload,
|
|
49
|
+
subsystem: subsystem.to_sym, level: level, facility_id: facility_id
|
|
50
|
+
)
|
|
46
51
|
)
|
|
47
|
-
|
|
52
|
+
end
|
|
48
53
|
|
|
49
54
|
q_size = @queue.size
|
|
50
55
|
if q_size >= DEFAULT_WARN_QUEUE_DEPTH && (q_size % 500).zero?
|
|
@@ -126,7 +131,7 @@ module Rubik
|
|
|
126
131
|
|
|
127
132
|
dispatch_event(item)
|
|
128
133
|
rescue StandardError => e
|
|
129
|
-
@logger&.error("Dispatcher worker error: #{e.message}")
|
|
134
|
+
@logger&.error("Dispatcher worker error: #{e.class}: #{e.message}")
|
|
130
135
|
end
|
|
131
136
|
end
|
|
132
137
|
|
|
@@ -140,11 +145,11 @@ module Rubik
|
|
|
140
145
|
listener.arity.zero? ? listener.call : listener.call(event.payload)
|
|
141
146
|
rescue StandardError => e
|
|
142
147
|
begin
|
|
143
|
-
@dmesg&.log(:kernel, :err, "Subscriber error on #{event.name}: #{e.message}")
|
|
148
|
+
@dmesg&.log(:kernel, :err, "Subscriber error on #{event.name}: #{e.class}: #{e.message}")
|
|
144
149
|
rescue StandardError
|
|
145
150
|
nil
|
|
146
151
|
end
|
|
147
|
-
@logger&.error("EventBus subscriber error on event '#{event.name}': #{e.message}")
|
|
152
|
+
@logger&.error("EventBus subscriber error on event '#{event.name}': #{e.class}: #{e.message}")
|
|
148
153
|
end
|
|
149
154
|
|
|
150
155
|
def log_to_dmesg(event)
|
|
@@ -160,7 +165,7 @@ module Rubik
|
|
|
160
165
|
end
|
|
161
166
|
@dmesg.log(event.subsystem, event.level, "event:#{event.name}", facility_id: fac_id, **safe_data)
|
|
162
167
|
rescue StandardError => e
|
|
163
|
-
@logger&.error("Dispatcher dmesg logging error: #{e.message}")
|
|
168
|
+
@logger&.error("Dispatcher dmesg logging error: #{e.class}: #{e.message}")
|
|
164
169
|
end
|
|
165
170
|
end
|
|
166
171
|
end
|
data/lib/rubik/kernel/unit.rb
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "monitor"
|
|
4
|
+
require_relative "../errors"
|
|
4
5
|
require_relative "../events"
|
|
5
6
|
|
|
6
7
|
module Rubik
|
|
7
8
|
module Kernel
|
|
8
9
|
# Kernel execution unit representing an asynchronous computation (Plan 104).
|
|
9
10
|
class Unit
|
|
10
|
-
|
|
11
|
+
# Unified taxonomy (issue #448): subclasses Rubik::StateError so a
|
|
12
|
+
# caller can rescue any guarded-transition tripwire with one class.
|
|
13
|
+
class StateError < Rubik::StateError; end
|
|
11
14
|
|
|
12
15
|
VALID_TYPES = [:subagent, :process, :task, :service].freeze
|
|
13
16
|
VALID_STATES = [:pending, :active, :paused_error, :waiting_budget, :budget_exhausted, :completed, :failed, :reaped].freeze
|
data/lib/rubik/llm/registry.rb
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative "openai_compatible"
|
|
4
|
+
require_relative "../security/secret_store"
|
|
5
|
+
require_relative "../storage/layout"
|
|
4
6
|
require_relative "ollama"
|
|
5
7
|
require_relative "openai"
|
|
6
8
|
require_relative "anthropic"
|
|
@@ -87,7 +89,7 @@ module Rubik
|
|
|
87
89
|
)
|
|
88
90
|
end
|
|
89
91
|
|
|
90
|
-
custom_providers =
|
|
92
|
+
custom_providers = Rubik::Storage::Layout.config_get(config, "providers", {})
|
|
91
93
|
return unless custom_providers.is_a?(Hash)
|
|
92
94
|
|
|
93
95
|
custom_providers.each do |p_name, p_spec|
|
|
@@ -131,13 +133,7 @@ module Rubik
|
|
|
131
133
|
def configured_default_max_output_tokens
|
|
132
134
|
return nil unless @config
|
|
133
135
|
|
|
134
|
-
val =
|
|
135
|
-
begin
|
|
136
|
-
@config.fetch("llm.default_max_output_tokens", nil)
|
|
137
|
-
rescue KeyError, TypeError, NoMethodError
|
|
138
|
-
nil
|
|
139
|
-
end
|
|
140
|
-
end
|
|
136
|
+
val = Rubik::Storage::Layout.config_get(@config, "llm.default_max_output_tokens", nil)
|
|
141
137
|
val = @config.dig("llm", "default_max_output_tokens") || @config["llm.default_max_output_tokens"] if val.nil? && @config.is_a?(Hash)
|
|
142
138
|
val&.to_i if val.to_i.positive?
|
|
143
139
|
end
|
|
@@ -265,7 +261,14 @@ module Rubik
|
|
|
265
261
|
def build_provider_instance(p_name, p_spec, headers, default_model, endpoint)
|
|
266
262
|
type = p_spec["type"].to_s.downcase
|
|
267
263
|
api_key_env = p_spec["api_key_env"]
|
|
268
|
-
|
|
264
|
+
# Config holds at most a "rubik-secret:" pointer at this point
|
|
265
|
+
# (SecretPolicy routed the plaintext into SecretStore on write);
|
|
266
|
+
# resolve it lazily per build so keyring updates apply on refresh.
|
|
267
|
+
api_key = Rubik::Security::SecretStore.resolve(p_spec["api_key"])
|
|
268
|
+
if api_key.nil? && Rubik::Security::SecretStore.reference?(p_spec["api_key"].to_s)
|
|
269
|
+
warn "[WARN] stored secret '#{p_spec['api_key'].delete_prefix(Rubik::Security::SecretStore::REFERENCE_PREFIX)}' " \
|
|
270
|
+
"could not be retrieved via #{Rubik::Security::SecretStore.backend_name}"
|
|
271
|
+
end
|
|
269
272
|
|
|
270
273
|
case type
|
|
271
274
|
when "openai_compatible", "openai"
|
data/lib/rubik/llm/router.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative "registry"
|
|
4
|
+
require_relative "../storage/layout"
|
|
4
5
|
|
|
5
6
|
module Rubik
|
|
6
7
|
module LLM
|
|
@@ -16,7 +17,7 @@ module Rubik
|
|
|
16
17
|
end
|
|
17
18
|
|
|
18
19
|
def route(task_type: :auto, prompt: "")
|
|
19
|
-
mode = @config
|
|
20
|
+
mode = Rubik::Storage::Layout.config_get(@config, "router.mode", "auto").to_s.downcase
|
|
20
21
|
role = determine_role(task_type, prompt, mode)
|
|
21
22
|
spec = @config.model_spec(role)
|
|
22
23
|
|
|
@@ -66,10 +67,6 @@ module Rubik
|
|
|
66
67
|
chosen.stream_chat(messages, opts, &block)
|
|
67
68
|
end
|
|
68
69
|
|
|
69
|
-
def available_roles
|
|
70
|
-
[:default, :fast, :advanced]
|
|
71
|
-
end
|
|
72
|
-
|
|
73
70
|
private
|
|
74
71
|
|
|
75
72
|
def determine_role(task_type, prompt, mode)
|
data/lib/rubik/log.rb
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
# Central leveled logging core (G6 early slice): one seam for runtime
|
|
4
4
|
# diagnostics, replacing ad-hoc Kernel#warn call sites as they are triaged
|
|
5
|
-
# (
|
|
5
|
+
# (bare-rescue/warn migration tracked in _plan/59-cekirdek-guvenligi-sentez-
|
|
6
|
+
# sandbox-bare-rescue-ve-moduler-testler.md and future audits). Single-line format
|
|
6
7
|
# follows the repo's [rubik] prefix convention. Emit is error-isolated: a
|
|
7
8
|
# logger must never raise, least of all from inside a rescue body.
|
|
8
9
|
#
|
|
@@ -35,5 +36,26 @@ module Rubik
|
|
|
35
36
|
rescue StandardError
|
|
36
37
|
nil
|
|
37
38
|
end
|
|
39
|
+
|
|
40
|
+
# Logger-object shim for classes whose dependency-injected logger kwarg
|
|
41
|
+
# historically defaulted to Logger.new($stderr) built at require time.
|
|
42
|
+
# The forwarder routes through Rubik::Log instead, so the configured
|
|
43
|
+
# RUBIK_LOG_LEVEL filter and the single-line format apply to those
|
|
44
|
+
# defaults too. Injecting a real ::Logger instance still works.
|
|
45
|
+
class Forwarder
|
|
46
|
+
def initialize(subsystem)
|
|
47
|
+
@subsystem = subsystem
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
[:debug, :info, :warn, :error].each do |level_name|
|
|
51
|
+
define_method(level_name) do |message|
|
|
52
|
+
Rubik::Log.emit(level_name, @subsystem, message.to_s)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def self.forwarder(subsystem)
|
|
58
|
+
Forwarder.new(subsystem)
|
|
59
|
+
end
|
|
38
60
|
end
|
|
39
61
|
end
|