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
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "securerandom"
|
|
4
|
-
require "time"
|
|
5
|
-
|
|
6
3
|
require_relative "base"
|
|
4
|
+
require_relative "../../storage/layout"
|
|
7
5
|
require_relative "../../runtime"
|
|
8
6
|
require_relative "../../sandbox"
|
|
9
7
|
require_relative "../../orchestrator/auto_apply"
|
|
8
|
+
require_relative "../../orchestrator/goal_session"
|
|
10
9
|
|
|
11
10
|
module Rubik
|
|
12
11
|
module REPL
|
|
@@ -19,6 +18,9 @@ module Rubik
|
|
|
19
18
|
USAGE_PLAN = "Kullanım: !plan <görev açıklaması>"
|
|
20
19
|
USAGE_GOAL = "Kullanım: !goal [--steps N|-s N] <hedef açıklaması> | !goal resume | !goal list"
|
|
21
20
|
|
|
21
|
+
# The !goal run lifecycle (start/suspend/resume/terminal mapping) is
|
|
22
|
+
# the Orchestrator::GoalSession domain (issue #404); this module keeps
|
|
23
|
+
# only command registration, argument parsing and usage rendering.
|
|
22
24
|
def self.register(shell)
|
|
23
25
|
register_plan_command(shell)
|
|
24
26
|
register_goal_command(shell)
|
|
@@ -38,7 +40,7 @@ module Rubik
|
|
|
38
40
|
next
|
|
39
41
|
end
|
|
40
42
|
|
|
41
|
-
plan_steps = ctx.config
|
|
43
|
+
plan_steps = Rubik::Storage::Layout.config_get(ctx.config, "agent.plan_max_steps", 15).to_i
|
|
42
44
|
routed = ctx.router.route(task_type: :plan, prompt: task)
|
|
43
45
|
ctx.runtime_manager.provide(:llm_client, routed[:provider]) if routed[:provider]
|
|
44
46
|
orchestrator = ctx.orchestrator_loop(
|
|
@@ -77,8 +79,8 @@ module Rubik
|
|
|
77
79
|
# Tek-argüman şartı: "Resume the deployment" gibi hedef metinleri
|
|
78
80
|
# alt-komut olarak yakalanamaz.
|
|
79
81
|
sub = args.first.to_s.downcase
|
|
80
|
-
next resume_suspended_goal(ctx) if args.length == 1 && sub == "resume"
|
|
81
|
-
next list_suspended_goals(ctx) if args.length == 1 && sub == "list"
|
|
82
|
+
next Rubik::Orchestrator::GoalSession.resume_suspended_goal(ctx) if args.length == 1 && sub == "resume"
|
|
83
|
+
next Rubik::Orchestrator::GoalSession.list_suspended_goals(ctx) if args.length == 1 && sub == "list"
|
|
82
84
|
|
|
83
85
|
parsed = parse_goal_args(args)
|
|
84
86
|
if !parsed[:valid]
|
|
@@ -90,7 +92,7 @@ module Rubik
|
|
|
90
92
|
next
|
|
91
93
|
end
|
|
92
94
|
|
|
93
|
-
execute_goal(ctx, parsed[:goal_text], parsed[:custom_steps])
|
|
95
|
+
Rubik::Orchestrator::GoalSession.execute_goal(ctx, parsed[:goal_text], parsed[:custom_steps])
|
|
94
96
|
end
|
|
95
97
|
end
|
|
96
98
|
|
|
@@ -126,499 +128,23 @@ module Rubik
|
|
|
126
128
|
{ custom_steps: custom_steps, goal_text: goal_text, valid: valid }
|
|
127
129
|
end
|
|
128
130
|
|
|
129
|
-
private_class_method def self.initialize_goal_ledger(ctx, goal_text)
|
|
130
|
-
return nil unless Rubik::Orchestrator::GoalLedger::Ledger.enabled?(ctx.config)
|
|
131
|
-
|
|
132
|
-
store = Rubik::Coeffects.get(ctx.runtime_manager&.context, Rubik::Coeffects::STORAGE_STORE)
|
|
133
|
-
dmesg = Rubik::Coeffects.get(ctx.runtime_manager&.context, Rubik::Coeffects::DMESG)
|
|
134
|
-
goal_ledger = Rubik::Orchestrator::GoalLedger::Ledger.create!(
|
|
135
|
-
goal_text: goal_text, config: ctx.config, store: store, dmesg: dmesg,
|
|
136
|
-
event_bus: ctx.event_bus
|
|
137
|
-
)
|
|
138
|
-
ctx.runtime_manager.provide(Rubik::Coeffects::GOAL_LEDGER, goal_ledger)
|
|
139
|
-
goal_ledger
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
private_class_method def self.execute_goal(ctx, goal_text, custom_steps)
|
|
143
|
-
ctx.recorder&.record_user_turn("!goal #{goal_text}")
|
|
144
|
-
goal_steps = custom_steps || ctx.config.fetch("agent.goal_max_steps", 100).to_i
|
|
145
|
-
warn_ratio = ctx.config.fetch("agent.warn_at_ratio", 0.75).to_f
|
|
146
|
-
routed = ctx.router.route(task_type: :goal, prompt: goal_text)
|
|
147
|
-
ctx.runtime_manager.provide(:llm_client, routed[:provider]) if routed[:provider]
|
|
148
|
-
|
|
149
|
-
# Canlı hedef durumu: maestro ve alt ajanlar read_file
|
|
150
|
-
# rubik://goal/state ile aynı anlık görüntüyü okur. Provide swap
|
|
151
|
-
# semantiğine sahiptir — tekrarlanan !goal koşuları Ω'ya inverse
|
|
152
|
-
# yığmaz; session dispose'u tek delete-inverse ile temizler.
|
|
153
|
-
# event_bus: bitiş olayı (GoalState::FINISH_EVENT) Vakanüvis
|
|
154
|
-
# kronikçisinin goal kancasına akar (K3) — notice/wake yok.
|
|
155
|
-
goal_state = Rubik::Orchestrator::GoalState.new(event_bus: ctx.event_bus)
|
|
156
|
-
goal_state.start!(goal_text, goal_steps)
|
|
157
|
-
ctx.runtime_manager.provide(Rubik::Coeffects::GOAL_STATE, goal_state)
|
|
158
|
-
|
|
159
|
-
# Yapılandırılmış Σ defteri (goal-ledger planı A): knob ON iken
|
|
160
|
-
# koşuyla doğar, terminal dallarda finalize olur, provide swap
|
|
161
|
-
# semantiğiyle tekrarlanan !goal koşuları Ω'ya inverse yığmaz.
|
|
162
|
-
# OFF iken hiçbir yüz kurulmaz (araç/URI/prompt bayt-özdeş).
|
|
163
|
-
goal_ledger = initialize_goal_ledger(ctx, goal_text)
|
|
164
|
-
|
|
165
|
-
# Askı kimliği (issue #106): koşu boyunca SABİT — registry
|
|
166
|
-
# girdisinin anahtarı ve Σ damgası meta'sının goal_id'si.
|
|
167
|
-
# (Σ satır id'si her kabulde değişir; kimlik olarak kullanılamaz.)
|
|
168
|
-
goal_id = "goal-#{Process.pid}-#{SecureRandom.hex(4)}"
|
|
169
|
-
|
|
170
|
-
ctx.out.puts "[Rubik::Goal] Starting autonomous goal loop (Budget: #{goal_steps} steps) with #{routed[:role]} model (#{routed[:model]})..."
|
|
171
|
-
ctx.out.puts "[Rubik::Goal] Target: #{goal_text}\n"
|
|
172
|
-
|
|
173
|
-
orchestrator = ctx.orchestrator_loop(
|
|
174
|
-
provider: routed[:provider],
|
|
175
|
-
model: routed[:model],
|
|
176
|
-
max_steps: goal_steps,
|
|
177
|
-
warn_at_ratio: warn_ratio,
|
|
178
|
-
context_limit: routed[:context_limit],
|
|
179
|
-
max_output_tokens: routed[:max_output_tokens],
|
|
180
|
-
on_step: build_goal_on_step(ctx, goal_state)
|
|
181
|
-
)
|
|
182
|
-
|
|
183
|
-
# Plan 53 D-8 yardımcısı: nötr çift + kayıtçı eşlemesi tek yerde.
|
|
184
|
-
# Session restore kayıtçı OLAYLARINDAN hidrate eder — eşlenmiş
|
|
185
|
-
# restore için conversation_history VE record_assistant_response
|
|
186
|
-
# birlikte yazılmalı (başarısızlıkta da).
|
|
187
|
-
record_goal_pair = build_goal_record_pair(ctx, goal_text)
|
|
188
|
-
|
|
189
|
-
# Pruner apply seam: hedef döngüsü de aynı sınırda tohumlanır —
|
|
190
|
-
# aşamalı budama planı varsa goal promptundan ÖNCE uygulanır.
|
|
191
|
-
ctx.apply_staged_prune_plan!
|
|
192
|
-
|
|
193
|
-
drive_goal_turn(ctx, orchestrator: orchestrator, goal_state: goal_state,
|
|
194
|
-
goal_ledger: goal_ledger, goal_text: goal_text, goal_id: goal_id,
|
|
195
|
-
record_pair: record_goal_pair,
|
|
196
|
-
start: ->(loop_inst) { loop_inst.run(goal_text, goal_mode: true, conversation_history: ctx.conversation_history) })
|
|
197
|
-
end
|
|
198
|
-
|
|
199
|
-
# ------------------------------------------------------------------
|
|
200
|
-
# !goal sürücüsü (issue #106): koşu girişi + bütçe-soru döngüsü +
|
|
201
|
-
# tek hata kanalı + terminal eşlemesi — start ve resume yollarının
|
|
202
|
-
# ORTAK gövdesi. start callable'ı yolu seçer:
|
|
203
|
-
# başlangıç → loop.run (taze koşu)
|
|
204
|
-
# süreç-içi resume → loop.resume! (history prefix nesne-özdeş)
|
|
205
|
-
# çapraz-süreç resume → loop.resume_from (Σ penceresi)
|
|
206
|
-
# Askı dalı (#106): SADECE transient ClientError SUSPENDED'a gider;
|
|
207
|
-
# kalıcı hatalar (moderasyon/401/read-timeout) bugünkü fail_goal
|
|
208
|
-
# çıktısını bayt-baytına korur.
|
|
209
|
-
private_class_method def self.drive_goal_turn(ctx, orchestrator:, goal_state:, goal_ledger:,
|
|
210
|
-
goal_text:, goal_id:, record_pair:, start:)
|
|
211
|
-
ctx.active_loop = orchestrator
|
|
212
|
-
begin
|
|
213
|
-
res = start.call(orchestrator)
|
|
214
|
-
res = handle_goal_budget_extensions(ctx, orchestrator: orchestrator, goal_state: goal_state, res: res)
|
|
215
|
-
rescue Interrupt
|
|
216
|
-
# ^C hedefi 'running' bırakmasın; eşlenmiş kayıt otursun. Interrupt
|
|
217
|
-
# yeniden yükselir — kullanıcı mesajını execute_command basar.
|
|
218
|
-
# Resume üstüne ^C = askıyı terk (terminal :stopped damgası).
|
|
219
|
-
goal_state.stop!("Interrupted by user (^C)")
|
|
220
|
-
finalize_goal_ledger(goal_ledger, goal_state, :stopped)
|
|
221
|
-
forget_suspended_goal(ctx, goal_id)
|
|
222
|
-
record_pair.call("[Goal attempt interrupted after #{goal_state.step_count} steps]")
|
|
223
|
-
raise
|
|
224
|
-
rescue Rubik::LLM::ClientError => e
|
|
225
|
-
# Tek hata kanalı (#106 uzantısı): transient transport hatası
|
|
226
|
-
# (RETRYABLE tükenmesi, tükenmiş 5xx, 429) goal'u SUSPENDED'a
|
|
227
|
-
# götürür — loop/counters/Σ korunur, REPL yaşar. Kalıcı hata
|
|
228
|
-
# (#105 çıktısı değişmeden) terminal fail. Yeniden yükseltmez —
|
|
229
|
-
# spinner temizliği dispatch katmanına (execute_command) aittir.
|
|
230
|
-
# next yerine return: rescue sonrası res'siz terminal
|
|
231
|
-
# eşlemesine düşülmesin.
|
|
232
|
-
if e.respond_to?(:transient?) && e.transient?
|
|
233
|
-
suspend_goal_turn(ctx, orchestrator: orchestrator, goal_state: goal_state, goal_ledger: goal_ledger,
|
|
234
|
-
goal_text: goal_text, goal_id: goal_id, record_pair: record_pair, reason: e.message,
|
|
235
|
-
tokens: orchestrator.total_tokens)
|
|
236
|
-
else
|
|
237
|
-
fail_goal_turn(ctx, goal_state: goal_state, goal_ledger: goal_ledger, goal_id: goal_id,
|
|
238
|
-
record_pair: record_pair, reason: e.message)
|
|
239
|
-
end
|
|
240
|
-
return
|
|
241
|
-
rescue StandardError => e
|
|
242
|
-
fail_goal_turn(ctx, goal_state: goal_state, goal_ledger: goal_ledger, goal_id: goal_id,
|
|
243
|
-
record_pair: record_pair, reason: "#{e.class}: #{e.message}")
|
|
244
|
-
return
|
|
245
|
-
ensure
|
|
246
|
-
ctx.active_loop = nil
|
|
247
|
-
end
|
|
248
|
-
|
|
249
|
-
handle_goal_completion(ctx, res: res, goal_state: goal_state, goal_ledger: goal_ledger,
|
|
250
|
-
goal_id: goal_id, record_pair: record_pair)
|
|
251
|
-
end
|
|
252
|
-
|
|
253
|
-
private_class_method def self.finalize_goal_ledger(goal_ledger, goal_state, status)
|
|
254
|
-
return unless goal_ledger
|
|
255
|
-
|
|
256
|
-
goal_ledger.finalize!(status)
|
|
257
|
-
goal_state.ledger_id = goal_ledger.snapshot[:storage_id]
|
|
258
|
-
end
|
|
259
|
-
|
|
260
|
-
private_class_method def self.fail_goal_turn(ctx, goal_state:, goal_ledger:, goal_id:, record_pair:,
|
|
261
|
-
reason:, tokens: nil, steps: nil)
|
|
262
|
-
sanitized = Rubik::Platform.safe_utf8(reason.to_s)
|
|
263
|
-
steps_used = steps || goal_state.step_count
|
|
264
|
-
goal_state.fail!(sanitized, tokens: tokens)
|
|
265
|
-
finalize_goal_ledger(goal_ledger, goal_state, :failed)
|
|
266
|
-
forget_suspended_goal(ctx, goal_id)
|
|
267
|
-
ctx.out.puts "\n❌ Goal could not be completed: #{sanitized}"
|
|
268
|
-
record_pair.call("[Goal attempt ended after #{steps_used} steps: #{sanitized}]", tokens: tokens)
|
|
269
|
-
end
|
|
270
|
-
|
|
271
|
-
private_class_method def self.suspend_goal_turn(ctx, orchestrator:, goal_state:, goal_ledger:,
|
|
272
|
-
goal_text:, goal_id:, record_pair:, reason:, tokens: nil)
|
|
273
|
-
attempt = suspended_attempt(ctx, goal_id) + 1
|
|
274
|
-
# Ledger kimliği askıdan ÖNCE okunur: suspend! → ledger.suspend!
|
|
275
|
-
# sırası metanın bu turun token'larını içermesi için zorunlu,
|
|
276
|
-
# ama o damga storage_id'yi değiştirdiği için sonradan atanan id
|
|
277
|
-
# SUSPEND_EVENT'e geç kalırdı — ilk askıda kronik satırı slug
|
|
278
|
-
# kimliğine düşer, ledger= bağlantısı kaybolurdu.
|
|
279
|
-
# resume_cross_process ile aynı uçuş-içi atama önceliği.
|
|
280
|
-
goal_state.ledger_id = goal_ledger.snapshot[:storage_id] if goal_ledger
|
|
281
|
-
goal_state.suspend!(reason, tokens: tokens)
|
|
282
|
-
goal_ledger&.suspend!(suspend_stamp_meta(goal_state, goal_id, reason, attempt))
|
|
283
|
-
registry = goal_registry_for(ctx)
|
|
284
|
-
registry.register(Rubik::Orchestrator::GoalRegistry::Entry.new(
|
|
285
|
-
goal_id: goal_id, goal_text: goal_text, loop: orchestrator,
|
|
286
|
-
goal_state: goal_state, ledger: goal_ledger, reason: reason.to_s,
|
|
287
|
-
suspended_at: Time.now, attempt: attempt
|
|
288
|
-
))
|
|
289
|
-
ctx.out.puts "\n⏸️ [Rubik::Goal] Suspended after #{goal_state.step_count} steps (transient provider error): #{reason}"
|
|
290
|
-
ctx.out.puts " Loop, counters and Σ ledger are preserved — resume with `!goal resume`."
|
|
291
|
-
record_pair.call("[Goal suspended after #{goal_state.step_count} steps: #{reason}]", tokens: tokens)
|
|
292
|
-
end
|
|
293
|
-
|
|
294
|
-
private_class_method def self.handle_goal_budget_extensions(ctx, orchestrator:, goal_state:, res:)
|
|
295
|
-
# Bütçe tükenince sor (execute_free_text simetrisi; aynı knob,
|
|
296
|
-
# aynı +20). continue_loop boyunca active_loop DOLU kalmalı:
|
|
297
|
-
# notice yönlendirmesi aktif döngüye bakar (lifecycle.rb
|
|
298
|
-
# route_subagent_notice) — soruya beklerken gelen subagent
|
|
299
|
-
# olayları loop inbox'a girer ve devam adımında boşaltılır.
|
|
300
|
-
auto_extensions = 0
|
|
301
|
-
max_auto = ctx.config.fetch("agent.goal_auto_continue_limit", 0).to_i
|
|
302
|
-
# Yapılandırılmış neden (loop.rb terminali): insan-okur string
|
|
303
|
-
# yalnız gösterim içindir — otomasyon prozu parse etmesin.
|
|
304
|
-
while !res[:ok] && res[:reason] == :budget_exhausted
|
|
305
|
-
if auto_extensions < max_auto
|
|
306
|
-
auto_extensions += 1
|
|
307
|
-
ctx.out.puts "\n🤖 [Rubik::Goal] Adım bütçesi doldu (#{res[:error]}). " \
|
|
308
|
-
"Otonom devam hakkı (#{auto_extensions}/#{max_auto}) kullanılarak +20 adım ekleniyor..."
|
|
309
|
-
goal_state.extend!(goal_state.max_steps + 20)
|
|
310
|
-
res = orchestrator.continue_loop(20, auto: true)
|
|
311
|
-
next
|
|
312
|
-
end
|
|
313
|
-
|
|
314
|
-
break unless ctx.config.fetch("agent.ask_continue_on_limit", true)
|
|
315
|
-
|
|
316
|
-
ctx.out.puts "\n⚠️ [Rubik::Goal] #{res[:error]}"
|
|
317
|
-
ans = ctx.ask_yes_no(" [Rubik::Goal] +20 adım ile devam edilsin mi?", default: "n")
|
|
318
|
-
break unless ["y", "yes", "evet"].include?(ans)
|
|
319
|
-
|
|
320
|
-
ctx.out.puts " [Rubik::Goal] Adım bütçesi +20 artırılıyor ve hedef sürdürülüyor..."
|
|
321
|
-
goal_state.extend!(goal_state.max_steps + 20)
|
|
322
|
-
res = orchestrator.continue_loop(20)
|
|
323
|
-
end
|
|
324
|
-
res
|
|
325
|
-
end
|
|
326
|
-
|
|
327
|
-
private_class_method def self.handle_goal_completion(ctx, res:, goal_state:, goal_ledger:,
|
|
328
|
-
goal_id:, record_pair:)
|
|
329
|
-
if res[:ok]
|
|
330
|
-
active = goal_active_subagent_count(ctx)
|
|
331
|
-
if active.positive?
|
|
332
|
-
# Defense behind the loop-level goal guard (GoalWait): a
|
|
333
|
-
# success terminal escaping with live subagents means the
|
|
334
|
-
# pipeline is mid-flight — an honest stop beats a false
|
|
335
|
-
# "Goal Achieved" (field incident 2026-10-05).
|
|
336
|
-
reason = "Goal loop concluded with #{active} active subagent(s) still running — not marked complete"
|
|
337
|
-
goal_state.stop!(reason)
|
|
338
|
-
finalize_goal_ledger(goal_ledger, goal_state, :stopped)
|
|
339
|
-
ctx.out.puts "\n⚠️ [Rubik::Goal] #{reason}."
|
|
340
|
-
record_pair.call("[Goal attempt ended after #{goal_state.step_count} steps: #{reason}]", tokens: res[:tokens])
|
|
341
|
-
else
|
|
342
|
-
goal_state.complete!(res[:output].to_s, tokens: res[:tokens])
|
|
343
|
-
finalize_goal_ledger(goal_ledger, goal_state, :completed)
|
|
344
|
-
forget_suspended_goal(ctx, goal_id)
|
|
345
|
-
ctx.out.puts "\n🎉 Goal Achieved in #{res[:steps]} steps!"
|
|
346
|
-
ctx.out.puts res[:output]
|
|
347
|
-
# Keep the bang syntax out of the LLM context (Plan 53 D-8): the
|
|
348
|
-
# session recorder already stores the literal "!goal ..." for replay.
|
|
349
|
-
record_pair.call(res[:output].to_s, streamed: res[:streamed] == true, tokens: res[:tokens])
|
|
350
|
-
|
|
351
|
-
ctx.out.puts "\nTip: Use `!diff` to review changes and `!apply` to commit to disk." if ctx.buffer_manager.dirty?
|
|
352
|
-
end
|
|
353
|
-
else
|
|
354
|
-
# Başarısızlık eşlemesi yukarıdaki tek hata kanalından akar:
|
|
355
|
-
# GoalState → ledger finalize → kayıtçı çifti, istisna yoluyla
|
|
356
|
-
# aynı sırayla.
|
|
357
|
-
fail_goal_turn(ctx, goal_state: goal_state, goal_ledger: goal_ledger, goal_id: goal_id,
|
|
358
|
-
record_pair: record_pair, reason: res[:error], tokens: res[:tokens], steps: res[:steps])
|
|
359
|
-
end
|
|
360
|
-
end
|
|
361
|
-
# ------------------------------------------------------------------
|
|
362
|
-
# !goal resume (issue #106). İki yol, dönüşüm sırasına göre:
|
|
363
|
-
# 1) Oturum kaydında canlı girdi varsa süreç-içi resume — hayatta
|
|
364
|
-
# kalan Loop örneği canlandırılır (subagent konuşmaları gerçekten
|
|
365
|
-
# süreklidir; süpervizör sürecin yaşıyor).
|
|
366
|
-
# 2) Yoksa çapraz-süreç Σ-only resume — storage'daki "suspended"
|
|
367
|
-
# satırından rehidrasyon. Alt ajan konuşmaları süreçle ölür;
|
|
368
|
-
# çıktı bunu tek cümleyle dürüstçe söyler.
|
|
369
|
-
private_class_method def self.resume_suspended_goal(ctx)
|
|
370
|
-
registry = Rubik::Coeffects.get(ctx.runtime_manager&.context, Rubik::Coeffects::GOAL_REGISTRY)
|
|
371
|
-
entry = registry.latest if registry.is_a?(Rubik::Orchestrator::GoalRegistry)
|
|
372
|
-
entry ? resume_in_process(ctx, entry) : resume_cross_process(ctx)
|
|
373
|
-
end
|
|
374
|
-
|
|
375
|
-
private_class_method def self.resume_in_process(ctx, entry)
|
|
376
|
-
ctx.recorder&.record_user_turn("!goal resume")
|
|
377
|
-
goal_state = entry.goal_state
|
|
378
|
-
goal_ledger = entry.ledger
|
|
379
|
-
ctx.runtime_manager.provide(Rubik::Coeffects::GOAL_STATE, goal_state)
|
|
380
|
-
ctx.runtime_manager.provide(Rubik::Coeffects::GOAL_LEDGER, goal_ledger) if goal_ledger
|
|
381
|
-
goal_ledger&.unsuspend!
|
|
382
|
-
goal_state.resume!
|
|
383
|
-
ctx.out.puts "[Rubik::Goal] Resuming '#{entry.goal_text}' (attempt #{entry.attempt + 1}, " \
|
|
384
|
-
"suspended: #{entry.reason})"
|
|
385
|
-
# Dürüst süreklilik cümlesi: alt ajan konuşmaları süreç-içi
|
|
386
|
-
# resume'da yaşar — çapraz-süreç yoldaki tek cümlelik uyarı burada
|
|
387
|
-
# YOKTUR (gerçek süreklilik).
|
|
388
|
-
record_pair = build_goal_record_pair(ctx, entry.goal_text)
|
|
389
|
-
ctx.apply_staged_prune_plan!
|
|
390
|
-
drive_goal_turn(ctx, orchestrator: entry.loop, goal_state: goal_state,
|
|
391
|
-
goal_ledger: goal_ledger, goal_text: entry.goal_text,
|
|
392
|
-
goal_id: entry.goal_id, record_pair: record_pair,
|
|
393
|
-
start: lambda { |loop_inst|
|
|
394
|
-
loop_inst.resume!(reason: entry.reason,
|
|
395
|
-
suspended_at: entry.suspended_at,
|
|
396
|
-
attempt: entry.attempt)
|
|
397
|
-
})
|
|
398
|
-
end
|
|
399
|
-
|
|
400
|
-
private_class_method def self.resume_cross_process(ctx)
|
|
401
|
-
ctx.recorder&.record_user_turn("!goal resume")
|
|
402
|
-
store = Rubik::Coeffects.get(ctx.runtime_manager&.context, Rubik::Coeffects::STORAGE_STORE)
|
|
403
|
-
unless store
|
|
404
|
-
ctx.out.puts "ℹ️ [Rubik::Goal] No suspended goal in this session; storage unavailable — " \
|
|
405
|
-
"cross-process resume honestly refused."
|
|
406
|
-
return
|
|
407
|
-
end
|
|
408
|
-
|
|
409
|
-
row = suspended_rows(store).last
|
|
410
|
-
unless row
|
|
411
|
-
ctx.out.puts "ℹ️ [Rubik::Goal] No suspended goal found (session registry empty, no 'suspended' Σ rows)."
|
|
412
|
-
return
|
|
413
|
-
end
|
|
414
|
-
|
|
415
|
-
dmesg = Rubik::Coeffects.get(ctx.runtime_manager&.context, Rubik::Coeffects::DMESG)
|
|
416
|
-
ledger = Rubik::Orchestrator::GoalLedger::Ledger.load(store: store, storage_id: row.id,
|
|
417
|
-
config: ctx.config, dmesg: dmesg,
|
|
418
|
-
event_bus: ctx.event_bus)
|
|
419
|
-
unless ledger
|
|
420
|
-
ctx.out.puts "⚠️ [Rubik::Goal] Suspended goal row #{row.id} could not be rehydrated — " \
|
|
421
|
-
"cross-process resume refused (corrupt or non-suspended stamp)."
|
|
422
|
-
return
|
|
423
|
-
end
|
|
424
|
-
|
|
425
|
-
meta = ledger.suspend_meta || {}
|
|
426
|
-
goal_text = ledger.snapshot[:objective].to_s
|
|
427
|
-
goal_steps = meta["max_steps"].to_i.positive? ? meta["max_steps"].to_i : ctx.config.fetch("agent.goal_max_steps", 100).to_i
|
|
428
|
-
warn_ratio = ctx.config.fetch("agent.warn_at_ratio", 0.75).to_f
|
|
429
|
-
goal_state = Rubik::Orchestrator::GoalState.new(event_bus: ctx.event_bus)
|
|
430
|
-
goal_state.start!(goal_text, goal_steps)
|
|
431
|
-
goal_state.restore_counters!(steps: meta["steps"], max_steps: goal_steps,
|
|
432
|
-
extensions: meta["extensions"], tokens: meta["tokens"])
|
|
433
|
-
goal_state.ledger_id = ledger.snapshot[:storage_id]
|
|
434
|
-
ctx.runtime_manager.provide(Rubik::Coeffects::GOAL_STATE, goal_state)
|
|
435
|
-
ctx.runtime_manager.provide(Rubik::Coeffects::GOAL_LEDGER, ledger)
|
|
436
|
-
|
|
437
|
-
routed = ctx.router.route(task_type: :goal, prompt: goal_text)
|
|
438
|
-
ctx.runtime_manager.provide(:llm_client, routed[:provider]) if routed[:provider]
|
|
439
|
-
orchestrator = ctx.orchestrator_loop(
|
|
440
|
-
provider: routed[:provider],
|
|
441
|
-
model: routed[:model],
|
|
442
|
-
max_steps: goal_steps,
|
|
443
|
-
warn_at_ratio: warn_ratio,
|
|
444
|
-
context_limit: routed[:context_limit],
|
|
445
|
-
max_output_tokens: routed[:max_output_tokens],
|
|
446
|
-
on_step: build_goal_on_step(ctx, goal_state)
|
|
447
|
-
)
|
|
448
|
-
|
|
449
|
-
ctx.out.puts "[Rubik::Goal] Cross-process resume of '#{goal_text}' (attempt #{meta['attempt'].to_i})..."
|
|
450
|
-
# Dürüst süreklilik cümlesi (tasarım sözleşmesi): alt ajan
|
|
451
|
-
# konuşmaları süreçle öldü; disk etkileri ve session kaydı yaşar.
|
|
452
|
-
ctx.out.puts " Subagent conversations did not survive the process restart — their disk " \
|
|
453
|
-
"effects and the session record have."
|
|
454
|
-
ledger.unsuspend!
|
|
455
|
-
record_pair = build_goal_record_pair(ctx, goal_text)
|
|
456
|
-
ctx.apply_staged_prune_plan!
|
|
457
|
-
drive_goal_turn(ctx, orchestrator: orchestrator, goal_state: goal_state,
|
|
458
|
-
goal_ledger: ledger, goal_text: goal_text,
|
|
459
|
-
goal_id: meta["goal_id"].to_s.empty? ? row.id : meta["goal_id"],
|
|
460
|
-
record_pair: record_pair,
|
|
461
|
-
start: lambda { |loop_inst|
|
|
462
|
-
loop_inst.resume_from(goal_text: goal_text, ledger: ledger,
|
|
463
|
-
reason: meta["reason"].to_s,
|
|
464
|
-
suspended_at: parse_suspended_at(meta["suspended_at"]),
|
|
465
|
-
attempt: meta["attempt"].to_i,
|
|
466
|
-
counters: { steps: meta["steps"], max_steps: goal_steps,
|
|
467
|
-
tokens: meta["tokens"] })
|
|
468
|
-
})
|
|
469
|
-
end
|
|
470
|
-
|
|
471
|
-
# !goal list (issue #106 Faz 2a): store'daki status == "suspended"
|
|
472
|
-
# Σ satırları — özetler zaten status taşıyor (Store::Summary).
|
|
473
|
-
private_class_method def self.list_suspended_goals(ctx)
|
|
474
|
-
ctx.recorder&.record_user_turn("!goal list")
|
|
475
|
-
store = Rubik::Coeffects.get(ctx.runtime_manager&.context, Rubik::Coeffects::STORAGE_STORE)
|
|
476
|
-
unless store
|
|
477
|
-
ctx.out.puts "ℹ️ [Rubik::Goal] Storage unavailable — the suspended-goal list needs goal.ledger storage."
|
|
478
|
-
return
|
|
479
|
-
end
|
|
480
|
-
|
|
481
|
-
rows = suspended_rows(store)
|
|
482
|
-
if rows.empty?
|
|
483
|
-
ctx.out.puts "ℹ️ [Rubik::Goal] No suspended goals."
|
|
484
|
-
return
|
|
485
|
-
end
|
|
486
|
-
|
|
487
|
-
ctx.out.puts "=== Suspended goals ==="
|
|
488
|
-
rows.each do |s|
|
|
489
|
-
ctx.out.puts " #{s.id} #{s.updated_at} #{s.title}"
|
|
490
|
-
end
|
|
491
|
-
ctx.out.puts "Resume the latest with: !goal resume"
|
|
492
|
-
end
|
|
493
|
-
|
|
494
|
-
# Askı satırları: en eski → en yeni sıralı (updated_at; kuiratör
|
|
495
|
-
# list yüzeyiyle aynı alan). Sort anahtarı eşitse row sırası.
|
|
496
|
-
private_class_method def self.suspended_rows(store)
|
|
497
|
-
store.list(type: "goal").select { |s| s.status == "suspended" }.sort_by(&:updated_at)
|
|
498
|
-
end
|
|
499
|
-
|
|
500
|
-
# Σ damgası meta'sı (issue #106): {goal_id, steps, max_steps,
|
|
501
|
-
# extensions, tokens, reason, suspended_at, attempt}. Sembol
|
|
502
|
-
# anahtarlar Ledger#suspend! içinde dizgeleştirilir.
|
|
503
|
-
private_class_method def self.suspend_stamp_meta(goal_state, goal_id, reason, attempt)
|
|
504
|
-
{ goal_id: goal_id, steps: goal_state.step_count, max_steps: goal_state.max_steps,
|
|
505
|
-
extensions: goal_state.extensions, tokens: goal_state.tokens.dup,
|
|
506
|
-
reason: reason.to_s.slice(0, 300), suspended_at: Time.now.utc.iso8601, attempt: attempt }
|
|
507
|
-
end
|
|
508
|
-
|
|
509
|
-
private_class_method def self.suspended_attempt(ctx, goal_id)
|
|
510
|
-
registry = Rubik::Coeffects.get(ctx.runtime_manager&.context, Rubik::Coeffects::GOAL_REGISTRY)
|
|
511
|
-
registry&.fetch(goal_id)&.attempt.to_i
|
|
512
|
-
end
|
|
513
|
-
|
|
514
|
-
# Oturum kaydı coeffect'i: ilk askıda provide edilir (provide-swap
|
|
515
|
-
# semantiği — Context#provide anahtar başına TEK delete-inverse
|
|
516
|
-
# tutar; tekrarlanan suspend/resume Ω'yı büyütmez).
|
|
517
|
-
private_class_method def self.goal_registry_for(ctx)
|
|
518
|
-
registry = Rubik::Coeffects.get(ctx.runtime_manager&.context, Rubik::Coeffects::GOAL_REGISTRY)
|
|
519
|
-
return registry if registry.is_a?(Rubik::Orchestrator::GoalRegistry)
|
|
520
|
-
|
|
521
|
-
registry = Rubik::Orchestrator::GoalRegistry.new
|
|
522
|
-
ctx.runtime_manager&.provide(Rubik::Coeffects::GOAL_REGISTRY, registry)
|
|
523
|
-
registry
|
|
524
|
-
end
|
|
525
|
-
|
|
526
|
-
# Terminal yollarda girdi temizliği: kayıt SADECE sağlanmışsa —
|
|
527
|
-
# askı hiç yaşanmamış bir koşunun terminali boş registry provide
|
|
528
|
-
# ETMEMELİ (Ω disiplini).
|
|
529
|
-
private_class_method def self.forget_suspended_goal(ctx, goal_id)
|
|
530
|
-
registry = Rubik::Coeffects.get(ctx.runtime_manager&.context, Rubik::Coeffects::GOAL_REGISTRY)
|
|
531
|
-
registry.delete(goal_id) if registry.is_a?(Rubik::Orchestrator::GoalRegistry)
|
|
532
|
-
end
|
|
533
|
-
|
|
534
|
-
# Adım olayı lambda'sı (start + cross-process resume ortak): sayaç
|
|
535
|
-
# akışı, kayıtçı tool çiftleri, render — start yolundaki satır içi
|
|
536
|
-
# gövdenin birebir taşınması.
|
|
537
|
-
private_class_method def self.build_goal_on_step(ctx, goal_state)
|
|
538
|
-
lambda { |step_info|
|
|
539
|
-
# Adım sayacı rubik://goal/state'e aksın: olaylar bir adım
|
|
540
|
-
# içinde tekrarlanabilir, GoalState monotoniktir (zararsız).
|
|
541
|
-
goal_state.update_steps(step_info[:step], step_info[:max_steps]) if step_info[:step].is_a?(Integer)
|
|
542
|
-
# Session teşhis edilebilirliği (field incident 2026-10-12):
|
|
543
|
-
# saatler süren !goal koşuları session dosyasına tek satır
|
|
544
|
-
# düşürüyordu — free-text turn simetrisinde tool adımları
|
|
545
|
-
# kayıtçıya akar; render ve LLM geçmişi değişmez.
|
|
546
|
-
case step_info[:type]&.to_sym
|
|
547
|
-
when :tool_call
|
|
548
|
-
ctx.recorder&.record_tool_call(step_info[:tool], step_info[:args], call_id: step_info[:call_id])
|
|
549
|
-
when :tool_result
|
|
550
|
-
ctx.recorder&.record_tool_result(step_info[:tool], step_info[:output], status: step_info[:status] || :ok, call_id: step_info[:call_id])
|
|
551
|
-
end
|
|
552
|
-
ctx.render_step_event(step_info)
|
|
553
|
-
}
|
|
554
|
-
end
|
|
555
|
-
|
|
556
|
-
# Plan 53 D-8 yardımcısı: nötr çift + kayıtçı eşlemesi tek yerde.
|
|
557
|
-
# Session restore kayıtçı OLAYLARINDAN hidrate eder — eşlenmiş
|
|
558
|
-
# restore için conversation_history VE record_assistant_response
|
|
559
|
-
# birlikte yazılmalı (başarısızlıkta da).
|
|
560
|
-
private_class_method def self.build_goal_record_pair(ctx, goal_text)
|
|
561
|
-
lambda do |assistant_content, streamed: nil, tokens: nil|
|
|
562
|
-
ctx.conversation_history << { role: "user", content: "Goal: #{goal_text}" }
|
|
563
|
-
ctx.conversation_history << { role: "assistant", content: assistant_content }
|
|
564
|
-
ctx.recorder&.record_assistant_response(assistant_content, tokens: tokens, streamed: streamed)
|
|
565
|
-
ctx.trim_conversation_window!
|
|
566
|
-
end
|
|
567
|
-
end
|
|
568
|
-
|
|
569
|
-
# Damga meta'sındaki suspended_at (iso8601) → Time; bozuk değer
|
|
570
|
-
# nil — Loop#append_resume_marker! "unknown" downtime basar.
|
|
571
|
-
private_class_method def self.parse_suspended_at(value)
|
|
572
|
-
Time.iso8601(value.to_s)
|
|
573
|
-
rescue ArgumentError, TypeError
|
|
574
|
-
nil
|
|
575
|
-
end
|
|
576
|
-
|
|
577
|
-
# Defense-in-depth behind the loop-level goal guard: if a success
|
|
578
|
-
# terminal escapes GoalWait with live subagent units, the goal must
|
|
579
|
-
# stop honestly instead of celebrating a false completion. Fails
|
|
580
|
-
# CONSERVATIVE: coeffect absence is nil-safe (Coeffects.get never
|
|
581
|
-
# raises for a missing subsystem), so a raise here is real breakage
|
|
582
|
-
# — reporting zero would launder it into exactly the false
|
|
583
|
-
# "Goal Achieved" this backstop exists to refuse.
|
|
584
|
-
private_class_method def self.goal_active_subagent_count(ctx)
|
|
585
|
-
supervisor = Rubik::Coeffects.get(ctx.runtime_manager&.context, Rubik::Coeffects::SUBAGENT_SUPERVISOR)
|
|
586
|
-
supervisor&.active_count.to_i
|
|
587
|
-
rescue StandardError => e
|
|
588
|
-
Rubik::Log.warn(:orchestrator, "goal completion defense could not inspect subagents " \
|
|
589
|
-
"(#{e.class}: #{e.message}); refusing completion")
|
|
590
|
-
1
|
|
591
|
-
end
|
|
592
|
-
|
|
593
131
|
private_class_method def self.register_test_command(shell)
|
|
594
132
|
shell.register_command("test", description: "Run test suite via active language adapter") do |args, ctx|
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
applied = Rubik::Orchestrator::AutoApply.apply_and_sync(ctx.buffer_manager, ctx)
|
|
598
|
-
ctx.out.puts Rubik::Orchestrator::AutoApply.applied_line(applied.size, "test run")
|
|
599
|
-
else
|
|
600
|
-
ctx.out.puts Rubik::Orchestrator::AutoApply.unapplied_warning("Tests")
|
|
601
|
-
end
|
|
602
|
-
end
|
|
603
|
-
lang = args.first || Rubik::Runtime::Discovery.detect_primary_language(Dir.pwd) || "ruby"
|
|
604
|
-
adapter = ctx.adapter_registry.get(lang) || ctx.adapter_registry.get("ruby")
|
|
133
|
+
Base.pre_execution_apply(ctx, "test run", "Tests")
|
|
134
|
+
adapter = Base.adapter_for(ctx, args.first)
|
|
605
135
|
res = adapter.run_tests(Dir.pwd)
|
|
606
136
|
ctx.out.puts res[:output]
|
|
607
|
-
|
|
608
|
-
ctx.out.puts "\n🔍 [Diagnostic] #{res[:diagnostic].category.to_s.upcase}: #{res[:diagnostic].suggestion}"
|
|
609
|
-
ctx.out.puts "Tip: Use `repair_runtime_service` (or `fix_service`) to adapt test runners dynamically."
|
|
610
|
-
end
|
|
137
|
+
Base.render_diagnostic(ctx, res, tip: "Tip: Use `repair_runtime_service` (or `fix_service`) to adapt test runners dynamically.")
|
|
611
138
|
end
|
|
612
139
|
end
|
|
613
140
|
|
|
614
141
|
private_class_method def self.register_lint_command(shell)
|
|
615
142
|
shell.register_command("lint", description: "Run linter/syntax check", audience: :both) do |args, ctx|
|
|
616
143
|
target = args.first || "lib/rubik.rb"
|
|
617
|
-
|
|
618
|
-
adapter = ctx.adapter_registry.get(lang) || ctx.adapter_registry.get("ruby")
|
|
144
|
+
adapter = Base.adapter_for(ctx)
|
|
619
145
|
res = adapter.check_syntax(target)
|
|
620
146
|
ctx.out.puts res[:output]
|
|
621
|
-
ctx
|
|
147
|
+
Base.render_diagnostic(ctx, res)
|
|
622
148
|
end
|
|
623
149
|
end
|
|
624
150
|
|
|
@@ -634,25 +160,17 @@ module Rubik
|
|
|
634
160
|
next
|
|
635
161
|
end
|
|
636
162
|
end
|
|
637
|
-
|
|
638
|
-
adapter = ctx.adapter_registry.get(lang) || ctx.adapter_registry.get("ruby")
|
|
163
|
+
adapter = Base.adapter_for(ctx)
|
|
639
164
|
res = adapter.format_code(target)
|
|
640
165
|
ctx.out.puts res[:output]
|
|
641
|
-
ctx
|
|
166
|
+
Base.render_diagnostic(ctx, res)
|
|
642
167
|
end
|
|
643
168
|
end
|
|
644
169
|
end
|
|
645
170
|
|
|
646
171
|
private_class_method def self.register_sh_command(shell)
|
|
647
172
|
shell.register_command("sh", description: "Execute shell command via sandbox runner") do |args, ctx|
|
|
648
|
-
|
|
649
|
-
if Rubik::Orchestrator::AutoApply.apply?(ctx.config, trigger: :pre_execution)
|
|
650
|
-
applied = Rubik::Orchestrator::AutoApply.apply_and_sync(ctx.buffer_manager, ctx)
|
|
651
|
-
ctx.out.puts Rubik::Orchestrator::AutoApply.applied_line(applied.size, "command execution")
|
|
652
|
-
else
|
|
653
|
-
ctx.out.puts Rubik::Orchestrator::AutoApply.unapplied_warning("Commands")
|
|
654
|
-
end
|
|
655
|
-
end
|
|
173
|
+
Base.pre_execution_apply(ctx, "command execution", "Commands")
|
|
656
174
|
|
|
657
175
|
cmd = args.join(" ")
|
|
658
176
|
ctx.guard.verify_command_safety!(cmd)
|
|
@@ -671,10 +189,10 @@ module Rubik
|
|
|
671
189
|
registered_keys = registered_map.keys.uniq
|
|
672
190
|
|
|
673
191
|
if clean_args.empty? || subcmd == "status"
|
|
674
|
-
enabled = ctx.config
|
|
192
|
+
enabled = Rubik::Storage::Layout.config_get(ctx.config, "sandbox.enabled", false)
|
|
675
193
|
state_str = enabled ? "Açık (enabled)" : "Kapalı (disabled - direct safe execution)"
|
|
676
|
-
driver_name = ctx.sandbox_runner&.driver&.name || ctx.config
|
|
677
|
-
net_str = ctx.config
|
|
194
|
+
driver_name = ctx.sandbox_runner&.driver&.name || Rubik::Storage::Layout.config_get(ctx.config, "sandbox.driver", "bwrap")
|
|
195
|
+
net_str = Rubik::Storage::Layout.config_get(ctx.config, "sandbox.allow_network", false) ? "allowed" : "blocked"
|
|
678
196
|
|
|
679
197
|
ctx.out.puts "=== Sandbox Durumu ==="
|
|
680
198
|
ctx.out.puts "Durum: #{state_str}"
|
|
@@ -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 "../../llm"
|
|
5
6
|
|
|
6
7
|
module Rubik
|
|
@@ -17,7 +18,7 @@ module Rubik
|
|
|
17
18
|
# Extract registered providers from registry and config
|
|
18
19
|
registered_providers = []
|
|
19
20
|
registered_providers += ctx.llm_registry.list if ctx.llm_registry
|
|
20
|
-
registered_providers += ctx.config
|
|
21
|
+
registered_providers += Rubik::Storage::Layout.config_get(ctx.config, "providers", {}).keys if ctx.config
|
|
21
22
|
registered_providers = registered_providers.map { |p| p.to_s.downcase }.uniq
|
|
22
23
|
|
|
23
24
|
# 1. Explicit provider prefix with colon: e.g. "openrouter:anthropic/claude-3.5-sonnet"
|
|
@@ -73,7 +74,7 @@ module Rubik
|
|
|
73
74
|
|
|
74
75
|
registered_providers = []
|
|
75
76
|
registered_providers += ctx.llm_registry.list if ctx.llm_registry
|
|
76
|
-
registered_providers += ctx.config
|
|
77
|
+
registered_providers += Rubik::Storage::Layout.config_get(ctx.config, "providers", {}).keys if ctx.config
|
|
77
78
|
registered_providers = registered_providers.map { |p| p.to_s.downcase }.uniq
|
|
78
79
|
|
|
79
80
|
# 1. If 2 or more space-separated arguments: e.g. ["openrouter", "deepseek/deepseek-v4-flash"]
|
|
@@ -111,7 +112,7 @@ module Rubik
|
|
|
111
112
|
end
|
|
112
113
|
|
|
113
114
|
private_class_method def self.handle_list_models(ctx)
|
|
114
|
-
mode = ctx.config
|
|
115
|
+
mode = Rubik::Storage::Layout.config_get(ctx.config, "router.mode", "auto")
|
|
115
116
|
def_spec = ctx.config.model_spec(:default)
|
|
116
117
|
fast_spec = ctx.config.model_spec(:fast)
|
|
117
118
|
adv_spec = ctx.config.model_spec(:advanced)
|