rubik 0.8.1 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ATTRIBUTION.md +2 -2
- data/CHANGELOG.md +207 -43
- data/README.md +5 -1
- data/bin/rubik +15 -10
- data/lib/rubik/adapter/base.rb +19 -0
- data/lib/rubik/adapter/generic.rb +0 -14
- data/lib/rubik/adapter/node.rb +2 -0
- data/lib/rubik/ast/treesitter/zig_walker.rb +15 -2
- data/lib/rubik/cli/workspace_trust.rb +17 -0
- data/lib/rubik/concurrency/worker.rb +143 -0
- data/lib/rubik/concurrency.rb +1 -0
- data/lib/rubik/config/deep_ops.rb +17 -0
- data/lib/rubik/config/defaults.rb +23 -1
- data/lib/rubik/config/schema.rb +0 -1
- data/lib/rubik/config/store.rb +14 -0
- data/lib/rubik/config.rb +7 -3
- data/lib/rubik/context/repo_context_reader.rb +27 -8
- data/lib/rubik/events.rb +18 -0
- data/lib/rubik/kernel/dispatcher.rb +4 -4
- data/lib/rubik/kernel/unit.rb +4 -3
- data/lib/rubik/log.rb +2 -1
- data/lib/rubik/lsp/client.rb +83 -180
- data/lib/rubik/lsp/document_store.rb +209 -0
- data/lib/rubik/mcp/client.rb +4 -3
- data/lib/rubik/mcp/manager.rb +6 -2
- data/lib/rubik/mcp/transport/stdio.rb +51 -9
- data/lib/rubik/orchestrator/auto_apply.rb +2 -0
- data/lib/rubik/orchestrator/budget_manager.rb +18 -2
- data/lib/rubik/orchestrator/goal_ledger/deep_ops.rb +41 -0
- data/lib/rubik/orchestrator/goal_ledger/drift.rb +2 -1
- data/lib/rubik/orchestrator/goal_ledger/ledger.rb +56 -50
- data/lib/rubik/orchestrator/goal_ledger/observation_projection.rb +26 -0
- data/lib/rubik/orchestrator/goal_ledger/patch.rb +10 -17
- data/lib/rubik/orchestrator/goal_ledger/suspend_lifecycle.rb +9 -41
- data/lib/rubik/orchestrator/goal_ledger/validator.rb +6 -20
- data/lib/rubik/orchestrator/goal_ledger/verifier.rb +3 -14
- data/lib/rubik/orchestrator/goal_ledger/xml_render.rb +21 -14
- data/lib/rubik/orchestrator/goal_session.rb +505 -0
- data/lib/rubik/orchestrator/goal_state.rb +15 -15
- data/lib/rubik/orchestrator/loop.rb +62 -63
- data/lib/rubik/orchestrator/lsp_feedback.rb +7 -1
- data/lib/rubik/orchestrator/subagent/admission_policy.rb +161 -0
- data/lib/rubik/orchestrator/subagent/builtin_types.rb +3 -2
- data/lib/rubik/orchestrator/subagent/instance.rb +4 -0
- data/lib/rubik/orchestrator/subagent/journal.rb +2 -1
- data/lib/rubik/orchestrator/subagent/notices.rb +5 -4
- data/lib/rubik/orchestrator/subagent/profile_contract.rb +4 -10
- data/lib/rubik/orchestrator/subagent/questioner.rb +21 -6
- data/lib/rubik/orchestrator/subagent/run_cycle.rb +22 -1
- data/lib/rubik/orchestrator/subagent/scoped_registry.rb +34 -2
- data/lib/rubik/orchestrator/subagent/step_runner.rb +1 -1
- data/lib/rubik/orchestrator/subagent/teardown.rb +4 -0
- data/lib/rubik/orchestrator/subagent/transcript_formatter.rb +2 -1
- data/lib/rubik/orchestrator/subagent/type_registry.rb +19 -1
- data/lib/rubik/orchestrator/turn_executor/subagent_channel.rb +6 -1
- data/lib/rubik/orchestrator/turn_executor/user_channel.rb +6 -1
- data/lib/rubik/orchestrator/turn_executor.rb +2 -1
- data/lib/rubik/orchestrator.rb +1 -0
- data/lib/rubik/platform/path.rb +0 -1
- data/lib/rubik/platform.rb +15 -0
- data/lib/rubik/plugin/storage.rb +20 -29
- data/lib/rubik/prompt/context_builder.rb +24 -18
- data/lib/rubik/prompt/context_compactor.rb +31 -8
- data/lib/rubik/prompt/conversation_rows.rb +33 -0
- data/lib/rubik/prompt/doctrine.rb +4 -2
- data/lib/rubik/prompt/emergency_compactor.rb +5 -4
- data/lib/rubik/repl/commands/agent_context.rb +1 -1
- data/lib/rubik/repl/commands/agent_execution.rb +15 -467
- data/lib/rubik/repl/commands/buffer.rb +5 -1
- data/lib/rubik/repl/commands/lsp.rb +1 -1
- data/lib/rubik/repl/commands/mcp.rb +5 -0
- data/lib/rubik/repl/commands/subagents.rb +4 -4
- data/lib/rubik/repl/commands/workspace.rb +22 -2
- data/lib/rubik/repl/config_wiring.rb +24 -7
- data/lib/rubik/repl/input_execution.rb +1 -1
- data/lib/rubik/repl/input_loop.rb +1 -1
- data/lib/rubik/repl/lifecycle.rb +31 -2
- data/lib/rubik/repl/pruner/harness.rb +52 -67
- data/lib/rubik/repl/pruner/rules.rb +3 -1
- data/lib/rubik/repl/service_catalog.rb +1 -1
- data/lib/rubik/repl/synthesized_command_context.rb +3 -0
- data/lib/rubik/repl/turn_recorder.rb +5 -4
- data/lib/rubik/repl.rb +1 -0
- data/lib/rubik/runtime/context.rb +5 -0
- data/lib/rubik/runtime/discovery.rb +55 -0
- data/lib/rubik/runtime/manifest_store.rb +116 -0
- data/lib/rubik/runtime/overlay_storage.rb +300 -218
- data/lib/rubik/runtime/repair_probe.rb +20 -2
- data/lib/rubik/runtime/sealed_coeffects.rb +58 -0
- data/lib/rubik/runtime/synthesized_command_context.rb +80 -0
- data/lib/rubik/runtime/synthesized_tool_context.rb +123 -0
- data/lib/rubik/runtime/task_manager.rb +7 -2
- data/lib/rubik/runtime.rb +3 -0
- data/lib/rubik/security/allowlist.rb +167 -0
- data/lib/rubik/security/audit_log.rb +72 -0
- data/lib/rubik/security/classifier/classifier.rb +24 -8
- data/lib/rubik/security/classifier/commands/biome.yaml +49 -0
- data/lib/rubik/security/classifier/commands/bun.yaml +91 -0
- data/lib/rubik/security/classifier/commands/bundle.yaml +107 -0
- data/lib/rubik/security/classifier/commands/clang-format.yaml +21 -0
- data/lib/rubik/security/classifier/commands/clang.yaml +37 -0
- data/lib/rubik/security/classifier/commands/cmake.yaml +37 -0
- data/lib/rubik/security/classifier/commands/ctest.yaml +30 -0
- data/lib/rubik/security/classifier/commands/gcc.yaml +36 -0
- data/lib/rubik/security/classifier/commands/gem.yaml +104 -0
- data/lib/rubik/security/classifier/commands/gofmt.yaml +15 -0
- data/lib/rubik/security/classifier/commands/pnpm.yaml +8 -8
- data/lib/rubik/security/classifier/commands/python.yaml +18 -1
- data/lib/rubik/security/classifier/commands/python3.yaml +18 -1
- data/lib/rubik/security/classifier/commands/rake.yaml +60 -0
- data/lib/rubik/security/classifier/commands/rspec.yaml +42 -0
- data/lib/rubik/security/classifier/commands/rubocop.yaml +38 -0
- data/lib/rubik/security/classifier/commands/ruby.yaml +25 -0
- data/lib/rubik/security/classifier/commands/rustc.yaml +34 -0
- data/lib/rubik/security/classifier/commands/zig.yaml +77 -0
- data/lib/rubik/security/classifier/database.rb +12 -1
- data/lib/rubik/security/classifier/matcher.rb +17 -2
- data/lib/rubik/security/classifier/models.rb +3 -2
- data/lib/rubik/security/classifier.rb +5 -0
- data/lib/rubik/security/command_gate.rb +567 -0
- data/lib/rubik/security/guard.rb +96 -989
- data/lib/rubik/security/path_policy.rb +117 -0
- data/lib/rubik/security/synthesis_gate.rb +300 -0
- data/lib/rubik/security.rb +5 -0
- data/lib/rubik/storage/ranking.rb +113 -0
- data/lib/rubik/storage/store.rb +2 -92
- data/lib/rubik/storage/transcript_indexer.rb +2 -3
- data/lib/rubik/storage/vakanuvis/harness.rb +49 -89
- data/lib/rubik/tools/base.rb +24 -7
- data/lib/rubik/tools/builtins/files.rb +2 -0
- data/lib/rubik/tools/builtins/goal_ledger.rb +9 -9
- data/lib/rubik/tools/builtins/grep.rb +2 -3
- data/lib/rubik/tools/builtins/lifecycle.rb +91 -88
- data/lib/rubik/tools/builtins/synthesis.rb +124 -64
- data/lib/rubik/tools/builtins/unsynthesize.rb +38 -0
- data/lib/rubik/tools/catalog.rb +3 -0
- data/lib/rubik/tools/declaration.rb +6 -2
- data/lib/rubik/tools/lifecycle_rollbacks.rb +87 -0
- data/lib/rubik/tools/native_search.rb +2 -1
- data/lib/rubik/tools/preflight_runner.rb +107 -14
- data/lib/rubik/tools/registry.rb +2 -0
- data/lib/rubik/tools/truncator.rb +25 -0
- data/lib/rubik/tools/uri_resolver.rb +3 -1
- data/lib/rubik/uris.rb +5 -1
- data/lib/rubik/version.rb +1 -1
- data/lib/rubik.rb +1 -0
- metadata +35 -1
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "securerandom"
|
|
4
|
-
require "time"
|
|
5
|
-
|
|
6
3
|
require_relative "base"
|
|
7
4
|
require_relative "../../runtime"
|
|
8
5
|
require_relative "../../sandbox"
|
|
9
6
|
require_relative "../../orchestrator/auto_apply"
|
|
7
|
+
require_relative "../../orchestrator/goal_session"
|
|
10
8
|
|
|
11
9
|
module Rubik
|
|
12
10
|
module REPL
|
|
@@ -19,6 +17,9 @@ module Rubik
|
|
|
19
17
|
USAGE_PLAN = "Kullanım: !plan <görev açıklaması>"
|
|
20
18
|
USAGE_GOAL = "Kullanım: !goal [--steps N|-s N] <hedef açıklaması> | !goal resume | !goal list"
|
|
21
19
|
|
|
20
|
+
# The !goal run lifecycle (start/suspend/resume/terminal mapping) is
|
|
21
|
+
# the Orchestrator::GoalSession domain (issue #404); this module keeps
|
|
22
|
+
# only command registration, argument parsing and usage rendering.
|
|
22
23
|
def self.register(shell)
|
|
23
24
|
register_plan_command(shell)
|
|
24
25
|
register_goal_command(shell)
|
|
@@ -77,8 +78,8 @@ module Rubik
|
|
|
77
78
|
# Tek-argüman şartı: "Resume the deployment" gibi hedef metinleri
|
|
78
79
|
# alt-komut olarak yakalanamaz.
|
|
79
80
|
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"
|
|
81
|
+
next Rubik::Orchestrator::GoalSession.resume_suspended_goal(ctx) if args.length == 1 && sub == "resume"
|
|
82
|
+
next Rubik::Orchestrator::GoalSession.list_suspended_goals(ctx) if args.length == 1 && sub == "list"
|
|
82
83
|
|
|
83
84
|
parsed = parse_goal_args(args)
|
|
84
85
|
if !parsed[:valid]
|
|
@@ -90,7 +91,7 @@ module Rubik
|
|
|
90
91
|
next
|
|
91
92
|
end
|
|
92
93
|
|
|
93
|
-
execute_goal(ctx, parsed[:goal_text], parsed[:custom_steps])
|
|
94
|
+
Rubik::Orchestrator::GoalSession.execute_goal(ctx, parsed[:goal_text], parsed[:custom_steps])
|
|
94
95
|
end
|
|
95
96
|
end
|
|
96
97
|
|
|
@@ -126,467 +127,6 @@ module Rubik
|
|
|
126
127
|
{ custom_steps: custom_steps, goal_text: goal_text, valid: valid }
|
|
127
128
|
end
|
|
128
129
|
|
|
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
|
-
else
|
|
236
|
-
fail_goal_turn(ctx, goal_state: goal_state, goal_ledger: goal_ledger, goal_id: goal_id,
|
|
237
|
-
record_pair: record_pair, reason: e.message)
|
|
238
|
-
end
|
|
239
|
-
return
|
|
240
|
-
rescue StandardError => e
|
|
241
|
-
fail_goal_turn(ctx, goal_state: goal_state, goal_ledger: goal_ledger, goal_id: goal_id,
|
|
242
|
-
record_pair: record_pair, reason: "#{e.class}: #{e.message}")
|
|
243
|
-
return
|
|
244
|
-
ensure
|
|
245
|
-
ctx.active_loop = nil
|
|
246
|
-
end
|
|
247
|
-
|
|
248
|
-
handle_goal_completion(ctx, res: res, goal_state: goal_state, goal_ledger: goal_ledger,
|
|
249
|
-
goal_id: goal_id, record_pair: record_pair)
|
|
250
|
-
end
|
|
251
|
-
|
|
252
|
-
private_class_method def self.finalize_goal_ledger(goal_ledger, goal_state, status)
|
|
253
|
-
return unless goal_ledger
|
|
254
|
-
|
|
255
|
-
goal_ledger.finalize!(status)
|
|
256
|
-
goal_state.ledger_id = goal_ledger.snapshot[:storage_id]
|
|
257
|
-
end
|
|
258
|
-
|
|
259
|
-
private_class_method def self.fail_goal_turn(ctx, goal_state:, goal_ledger:, goal_id:, record_pair:,
|
|
260
|
-
reason:, tokens: nil, steps: nil)
|
|
261
|
-
sanitized = Rubik::Platform.safe_utf8(reason.to_s)
|
|
262
|
-
steps_used = steps || goal_state.step_count
|
|
263
|
-
goal_state.fail!(sanitized, tokens: tokens)
|
|
264
|
-
finalize_goal_ledger(goal_ledger, goal_state, :failed)
|
|
265
|
-
forget_suspended_goal(ctx, goal_id)
|
|
266
|
-
ctx.out.puts "\n❌ Goal could not be completed: #{sanitized}"
|
|
267
|
-
record_pair.call("[Goal attempt ended after #{steps_used} steps: #{sanitized}]", tokens: tokens)
|
|
268
|
-
end
|
|
269
|
-
|
|
270
|
-
private_class_method def self.suspend_goal_turn(ctx, orchestrator:, goal_state:, goal_ledger:,
|
|
271
|
-
goal_text:, goal_id:, record_pair:, reason:, tokens: nil)
|
|
272
|
-
attempt = suspended_attempt(ctx, goal_id) + 1
|
|
273
|
-
# Ledger kimliği askıdan ÖNCE okunur: suspend! → ledger.suspend!
|
|
274
|
-
# sırası metanın bu turun token'larını içermesi için zorunlu,
|
|
275
|
-
# ama o damga storage_id'yi değiştirdiği için sonradan atanan id
|
|
276
|
-
# SUSPEND_EVENT'e geç kalırdı — ilk askıda kronik satırı slug
|
|
277
|
-
# kimliğine düşer, ledger= bağlantısı kaybolurdu.
|
|
278
|
-
# resume_cross_process ile aynı uçuş-içi atama önceliği.
|
|
279
|
-
goal_state.ledger_id = goal_ledger.snapshot[:storage_id] if goal_ledger
|
|
280
|
-
goal_state.suspend!(reason, tokens: tokens)
|
|
281
|
-
goal_ledger&.suspend!(suspend_stamp_meta(goal_state, goal_id, reason, attempt))
|
|
282
|
-
registry = goal_registry_for(ctx)
|
|
283
|
-
registry.register(Rubik::Orchestrator::GoalRegistry::Entry.new(
|
|
284
|
-
goal_id: goal_id, goal_text: goal_text, loop: orchestrator,
|
|
285
|
-
goal_state: goal_state, ledger: goal_ledger, reason: reason.to_s,
|
|
286
|
-
suspended_at: Time.now, attempt: attempt
|
|
287
|
-
))
|
|
288
|
-
ctx.out.puts "\n⏸️ [Rubik::Goal] Suspended after #{goal_state.step_count} steps (transient provider error): #{reason}"
|
|
289
|
-
ctx.out.puts " Loop, counters and Σ ledger are preserved — resume with `!goal resume`."
|
|
290
|
-
record_pair.call("[Goal suspended after #{goal_state.step_count} steps: #{reason}]", tokens: tokens)
|
|
291
|
-
end
|
|
292
|
-
|
|
293
|
-
private_class_method def self.handle_goal_budget_extensions(ctx, orchestrator:, goal_state:, res:)
|
|
294
|
-
# Bütçe tükenince sor (execute_free_text simetrisi; aynı knob,
|
|
295
|
-
# aynı +20). continue_loop boyunca active_loop DOLU kalmalı:
|
|
296
|
-
# notice yönlendirmesi aktif döngüye bakar (lifecycle.rb
|
|
297
|
-
# route_subagent_notice) — soruya beklerken gelen subagent
|
|
298
|
-
# olayları loop inbox'a girer ve devam adımında boşaltılır.
|
|
299
|
-
auto_extensions = 0
|
|
300
|
-
max_auto = ctx.config.fetch("agent.goal_auto_continue_limit", 0).to_i
|
|
301
|
-
while !res[:ok] && res[:error]&.include?("Max steps budget exceeded")
|
|
302
|
-
if auto_extensions < max_auto
|
|
303
|
-
auto_extensions += 1
|
|
304
|
-
ctx.out.puts "\n🤖 [Rubik::Goal] Adım bütçesi doldu (#{res[:error]}). " \
|
|
305
|
-
"Otonom devam hakkı (#{auto_extensions}/#{max_auto}) kullanılarak +20 adım ekleniyor..."
|
|
306
|
-
goal_state.extend!(goal_state.max_steps + 20)
|
|
307
|
-
res = orchestrator.continue_loop(20, auto: true)
|
|
308
|
-
next
|
|
309
|
-
end
|
|
310
|
-
|
|
311
|
-
break unless ctx.config.fetch("agent.ask_continue_on_limit", true)
|
|
312
|
-
|
|
313
|
-
ctx.out.puts "\n⚠️ [Rubik::Goal] #{res[:error]}"
|
|
314
|
-
ans = ctx.ask_yes_no(" [Rubik::Goal] +20 adım ile devam edilsin mi?", default: "n")
|
|
315
|
-
break unless ["y", "yes", "evet"].include?(ans)
|
|
316
|
-
|
|
317
|
-
ctx.out.puts " [Rubik::Goal] Adım bütçesi +20 artırılıyor ve hedef sürdürülüyor..."
|
|
318
|
-
goal_state.extend!(goal_state.max_steps + 20)
|
|
319
|
-
res = orchestrator.continue_loop(20)
|
|
320
|
-
end
|
|
321
|
-
res
|
|
322
|
-
end
|
|
323
|
-
|
|
324
|
-
private_class_method def self.handle_goal_completion(ctx, res:, goal_state:, goal_ledger:,
|
|
325
|
-
goal_id:, record_pair:)
|
|
326
|
-
if res[:ok]
|
|
327
|
-
active = goal_active_subagent_count(ctx)
|
|
328
|
-
if active.positive?
|
|
329
|
-
# Defense behind the loop-level goal guard (GoalWait): a
|
|
330
|
-
# success terminal escaping with live subagents means the
|
|
331
|
-
# pipeline is mid-flight — an honest stop beats a false
|
|
332
|
-
# "Goal Achieved" (field incident 2026-10-05).
|
|
333
|
-
reason = "Goal loop concluded with #{active} active subagent(s) still running — not marked complete"
|
|
334
|
-
goal_state.stop!(reason)
|
|
335
|
-
finalize_goal_ledger(goal_ledger, goal_state, :stopped)
|
|
336
|
-
ctx.out.puts "\n⚠️ [Rubik::Goal] #{reason}."
|
|
337
|
-
record_pair.call("[Goal attempt ended after #{goal_state.step_count} steps: #{reason}]", tokens: res[:tokens])
|
|
338
|
-
else
|
|
339
|
-
goal_state.complete!(res[:output].to_s, tokens: res[:tokens])
|
|
340
|
-
finalize_goal_ledger(goal_ledger, goal_state, :completed)
|
|
341
|
-
forget_suspended_goal(ctx, goal_id)
|
|
342
|
-
ctx.out.puts "\n🎉 Goal Achieved in #{res[:steps]} steps!"
|
|
343
|
-
ctx.out.puts res[:output]
|
|
344
|
-
# Keep the bang syntax out of the LLM context (Plan 53 D-8): the
|
|
345
|
-
# session recorder already stores the literal "!goal ..." for replay.
|
|
346
|
-
record_pair.call(res[:output].to_s, streamed: res[:streamed] == true, tokens: res[:tokens])
|
|
347
|
-
|
|
348
|
-
ctx.out.puts "\nTip: Use `!diff` to review changes and `!apply` to commit to disk." if ctx.buffer_manager.dirty?
|
|
349
|
-
end
|
|
350
|
-
else
|
|
351
|
-
# Başarısızlık eşlemesi yukarıdaki tek hata kanalından akar:
|
|
352
|
-
# GoalState → ledger finalize → kayıtçı çifti, istisna yoluyla
|
|
353
|
-
# aynı sırayla.
|
|
354
|
-
fail_goal_turn(ctx, goal_state: goal_state, goal_ledger: goal_ledger, goal_id: goal_id,
|
|
355
|
-
record_pair: record_pair, reason: res[:error], tokens: res[:tokens], steps: res[:steps])
|
|
356
|
-
end
|
|
357
|
-
end
|
|
358
|
-
# ------------------------------------------------------------------
|
|
359
|
-
# !goal resume (issue #106). İki yol, dönüşüm sırasına göre:
|
|
360
|
-
# 1) Oturum kaydında canlı girdi varsa süreç-içi resume — hayatta
|
|
361
|
-
# kalan Loop örneği canlandırılır (subagent konuşmaları gerçekten
|
|
362
|
-
# süreklidir; süpervizör sürecin yaşıyor).
|
|
363
|
-
# 2) Yoksa çapraz-süreç Σ-only resume — storage'daki "suspended"
|
|
364
|
-
# satırından rehidrasyon. Alt ajan konuşmaları süreçle ölür;
|
|
365
|
-
# çıktı bunu tek cümleyle dürüstçe söyler.
|
|
366
|
-
private_class_method def self.resume_suspended_goal(ctx)
|
|
367
|
-
registry = Rubik::Coeffects.get(ctx.runtime_manager&.context, Rubik::Coeffects::GOAL_REGISTRY)
|
|
368
|
-
entry = registry.latest if registry.is_a?(Rubik::Orchestrator::GoalRegistry)
|
|
369
|
-
entry ? resume_in_process(ctx, entry) : resume_cross_process(ctx)
|
|
370
|
-
end
|
|
371
|
-
|
|
372
|
-
private_class_method def self.resume_in_process(ctx, entry)
|
|
373
|
-
ctx.recorder&.record_user_turn("!goal resume")
|
|
374
|
-
goal_state = entry.goal_state
|
|
375
|
-
goal_ledger = entry.ledger
|
|
376
|
-
ctx.runtime_manager.provide(Rubik::Coeffects::GOAL_STATE, goal_state)
|
|
377
|
-
ctx.runtime_manager.provide(Rubik::Coeffects::GOAL_LEDGER, goal_ledger) if goal_ledger
|
|
378
|
-
goal_ledger&.unsuspend!
|
|
379
|
-
goal_state.resume!
|
|
380
|
-
ctx.out.puts "[Rubik::Goal] Resuming '#{entry.goal_text}' (attempt #{entry.attempt + 1}, " \
|
|
381
|
-
"suspended: #{entry.reason})"
|
|
382
|
-
# Dürüst süreklilik cümlesi: alt ajan konuşmaları süreç-içi
|
|
383
|
-
# resume'da yaşar — çapraz-süreç yoldaki tek cümlelik uyarı burada
|
|
384
|
-
# YOKTUR (gerçek süreklilik).
|
|
385
|
-
record_pair = build_goal_record_pair(ctx, entry.goal_text)
|
|
386
|
-
ctx.apply_staged_prune_plan!
|
|
387
|
-
drive_goal_turn(ctx, orchestrator: entry.loop, goal_state: goal_state,
|
|
388
|
-
goal_ledger: goal_ledger, goal_text: entry.goal_text,
|
|
389
|
-
goal_id: entry.goal_id, record_pair: record_pair,
|
|
390
|
-
start: lambda { |loop_inst|
|
|
391
|
-
loop_inst.resume!(reason: entry.reason,
|
|
392
|
-
suspended_at: entry.suspended_at,
|
|
393
|
-
attempt: entry.attempt)
|
|
394
|
-
})
|
|
395
|
-
end
|
|
396
|
-
|
|
397
|
-
private_class_method def self.resume_cross_process(ctx)
|
|
398
|
-
ctx.recorder&.record_user_turn("!goal resume")
|
|
399
|
-
store = Rubik::Coeffects.get(ctx.runtime_manager&.context, Rubik::Coeffects::STORAGE_STORE)
|
|
400
|
-
unless store
|
|
401
|
-
ctx.out.puts "ℹ️ [Rubik::Goal] No suspended goal in this session; storage unavailable — " \
|
|
402
|
-
"cross-process resume honestly refused."
|
|
403
|
-
return
|
|
404
|
-
end
|
|
405
|
-
|
|
406
|
-
row = suspended_rows(store).last
|
|
407
|
-
unless row
|
|
408
|
-
ctx.out.puts "ℹ️ [Rubik::Goal] No suspended goal found (session registry empty, no 'suspended' Σ rows)."
|
|
409
|
-
return
|
|
410
|
-
end
|
|
411
|
-
|
|
412
|
-
dmesg = Rubik::Coeffects.get(ctx.runtime_manager&.context, Rubik::Coeffects::DMESG)
|
|
413
|
-
ledger = Rubik::Orchestrator::GoalLedger::Ledger.load(store: store, storage_id: row.id,
|
|
414
|
-
config: ctx.config, dmesg: dmesg,
|
|
415
|
-
event_bus: ctx.event_bus)
|
|
416
|
-
unless ledger
|
|
417
|
-
ctx.out.puts "⚠️ [Rubik::Goal] Suspended goal row #{row.id} could not be rehydrated — " \
|
|
418
|
-
"cross-process resume refused (corrupt or non-suspended stamp)."
|
|
419
|
-
return
|
|
420
|
-
end
|
|
421
|
-
|
|
422
|
-
meta = ledger.suspend_meta || {}
|
|
423
|
-
goal_text = ledger.snapshot[:objective].to_s
|
|
424
|
-
goal_steps = meta["max_steps"].to_i.positive? ? meta["max_steps"].to_i : ctx.config.fetch("agent.goal_max_steps", 100).to_i
|
|
425
|
-
warn_ratio = ctx.config.fetch("agent.warn_at_ratio", 0.75).to_f
|
|
426
|
-
goal_state = Rubik::Orchestrator::GoalState.new(event_bus: ctx.event_bus)
|
|
427
|
-
goal_state.start!(goal_text, goal_steps)
|
|
428
|
-
goal_state.restore_counters!(steps: meta["steps"], max_steps: goal_steps,
|
|
429
|
-
extensions: meta["extensions"], tokens: meta["tokens"])
|
|
430
|
-
goal_state.ledger_id = ledger.snapshot[:storage_id]
|
|
431
|
-
ctx.runtime_manager.provide(Rubik::Coeffects::GOAL_STATE, goal_state)
|
|
432
|
-
ctx.runtime_manager.provide(Rubik::Coeffects::GOAL_LEDGER, ledger)
|
|
433
|
-
|
|
434
|
-
routed = ctx.router.route(task_type: :goal, prompt: goal_text)
|
|
435
|
-
ctx.runtime_manager.provide(:llm_client, routed[:provider]) if routed[:provider]
|
|
436
|
-
orchestrator = ctx.orchestrator_loop(
|
|
437
|
-
provider: routed[:provider],
|
|
438
|
-
model: routed[:model],
|
|
439
|
-
max_steps: goal_steps,
|
|
440
|
-
warn_at_ratio: warn_ratio,
|
|
441
|
-
context_limit: routed[:context_limit],
|
|
442
|
-
max_output_tokens: routed[:max_output_tokens],
|
|
443
|
-
on_step: build_goal_on_step(ctx, goal_state)
|
|
444
|
-
)
|
|
445
|
-
|
|
446
|
-
ctx.out.puts "[Rubik::Goal] Cross-process resume of '#{goal_text}' (attempt #{meta['attempt'].to_i})..."
|
|
447
|
-
# Dürüst süreklilik cümlesi (tasarım sözleşmesi): alt ajan
|
|
448
|
-
# konuşmaları süreçle öldü; disk etkileri ve session kaydı yaşar.
|
|
449
|
-
ctx.out.puts " Subagent conversations did not survive the process restart — their disk " \
|
|
450
|
-
"effects and the session record have."
|
|
451
|
-
ledger.unsuspend!
|
|
452
|
-
record_pair = build_goal_record_pair(ctx, goal_text)
|
|
453
|
-
ctx.apply_staged_prune_plan!
|
|
454
|
-
drive_goal_turn(ctx, orchestrator: orchestrator, goal_state: goal_state,
|
|
455
|
-
goal_ledger: ledger, goal_text: goal_text,
|
|
456
|
-
goal_id: meta["goal_id"].to_s.empty? ? row.id : meta["goal_id"],
|
|
457
|
-
record_pair: record_pair,
|
|
458
|
-
start: lambda { |loop_inst|
|
|
459
|
-
loop_inst.resume_from(goal_text: goal_text, ledger: ledger,
|
|
460
|
-
reason: meta["reason"].to_s,
|
|
461
|
-
suspended_at: parse_suspended_at(meta["suspended_at"]),
|
|
462
|
-
attempt: meta["attempt"].to_i,
|
|
463
|
-
counters: { steps: meta["steps"], max_steps: goal_steps,
|
|
464
|
-
tokens: meta["tokens"] })
|
|
465
|
-
})
|
|
466
|
-
end
|
|
467
|
-
|
|
468
|
-
# !goal list (issue #106 Faz 2a): store'daki status == "suspended"
|
|
469
|
-
# Σ satırları — özetler zaten status taşıyor (Store::Summary).
|
|
470
|
-
private_class_method def self.list_suspended_goals(ctx)
|
|
471
|
-
ctx.recorder&.record_user_turn("!goal list")
|
|
472
|
-
store = Rubik::Coeffects.get(ctx.runtime_manager&.context, Rubik::Coeffects::STORAGE_STORE)
|
|
473
|
-
unless store
|
|
474
|
-
ctx.out.puts "ℹ️ [Rubik::Goal] Storage unavailable — the suspended-goal list needs goal.ledger storage."
|
|
475
|
-
return
|
|
476
|
-
end
|
|
477
|
-
|
|
478
|
-
rows = suspended_rows(store)
|
|
479
|
-
if rows.empty?
|
|
480
|
-
ctx.out.puts "ℹ️ [Rubik::Goal] No suspended goals."
|
|
481
|
-
return
|
|
482
|
-
end
|
|
483
|
-
|
|
484
|
-
ctx.out.puts "=== Suspended goals ==="
|
|
485
|
-
rows.each do |s|
|
|
486
|
-
ctx.out.puts " #{s.id} #{s.updated_at} #{s.title}"
|
|
487
|
-
end
|
|
488
|
-
ctx.out.puts "Resume the latest with: !goal resume"
|
|
489
|
-
end
|
|
490
|
-
|
|
491
|
-
# Askı satırları: en eski → en yeni sıralı (updated_at; kuiratör
|
|
492
|
-
# list yüzeyiyle aynı alan). Sort anahtarı eşitse row sırası.
|
|
493
|
-
private_class_method def self.suspended_rows(store)
|
|
494
|
-
store.list(type: "goal").select { |s| s.status == "suspended" }.sort_by(&:updated_at)
|
|
495
|
-
end
|
|
496
|
-
|
|
497
|
-
# Σ damgası meta'sı (issue #106): {goal_id, steps, max_steps,
|
|
498
|
-
# extensions, tokens, reason, suspended_at, attempt}. Sembol
|
|
499
|
-
# anahtarlar Ledger#suspend! içinde dizgeleştirilir.
|
|
500
|
-
private_class_method def self.suspend_stamp_meta(goal_state, goal_id, reason, attempt)
|
|
501
|
-
{ goal_id: goal_id, steps: goal_state.step_count, max_steps: goal_state.max_steps,
|
|
502
|
-
extensions: goal_state.extensions, tokens: goal_state.tokens.dup,
|
|
503
|
-
reason: reason.to_s.slice(0, 300), suspended_at: Time.now.utc.iso8601, attempt: attempt }
|
|
504
|
-
end
|
|
505
|
-
|
|
506
|
-
private_class_method def self.suspended_attempt(ctx, goal_id)
|
|
507
|
-
registry = Rubik::Coeffects.get(ctx.runtime_manager&.context, Rubik::Coeffects::GOAL_REGISTRY)
|
|
508
|
-
registry&.fetch(goal_id)&.attempt.to_i
|
|
509
|
-
end
|
|
510
|
-
|
|
511
|
-
# Oturum kaydı coeffect'i: ilk askıda provide edilir (provide-swap
|
|
512
|
-
# semantiği — Context#provide anahtar başına TEK delete-inverse
|
|
513
|
-
# tutar; tekrarlanan suspend/resume Ω'yı büyütmez).
|
|
514
|
-
private_class_method def self.goal_registry_for(ctx)
|
|
515
|
-
registry = Rubik::Coeffects.get(ctx.runtime_manager&.context, Rubik::Coeffects::GOAL_REGISTRY)
|
|
516
|
-
return registry if registry.is_a?(Rubik::Orchestrator::GoalRegistry)
|
|
517
|
-
|
|
518
|
-
registry = Rubik::Orchestrator::GoalRegistry.new
|
|
519
|
-
ctx.runtime_manager&.provide(Rubik::Coeffects::GOAL_REGISTRY, registry)
|
|
520
|
-
registry
|
|
521
|
-
end
|
|
522
|
-
|
|
523
|
-
# Terminal yollarda girdi temizliği: kayıt SADECE sağlanmışsa —
|
|
524
|
-
# askı hiç yaşanmamış bir koşunun terminali boş registry provide
|
|
525
|
-
# ETMEMELİ (Ω disiplini).
|
|
526
|
-
private_class_method def self.forget_suspended_goal(ctx, goal_id)
|
|
527
|
-
registry = Rubik::Coeffects.get(ctx.runtime_manager&.context, Rubik::Coeffects::GOAL_REGISTRY)
|
|
528
|
-
registry.delete(goal_id) if registry.is_a?(Rubik::Orchestrator::GoalRegistry)
|
|
529
|
-
end
|
|
530
|
-
|
|
531
|
-
# Adım olayı lambda'sı (start + cross-process resume ortak): sayaç
|
|
532
|
-
# akışı, kayıtçı tool çiftleri, render — start yolundaki satır içi
|
|
533
|
-
# gövdenin birebir taşınması.
|
|
534
|
-
private_class_method def self.build_goal_on_step(ctx, goal_state)
|
|
535
|
-
lambda { |step_info|
|
|
536
|
-
# Adım sayacı rubik://goal/state'e aksın: olaylar bir adım
|
|
537
|
-
# içinde tekrarlanabilir, GoalState monotoniktir (zararsız).
|
|
538
|
-
goal_state.update_steps(step_info[:step], step_info[:max_steps]) if step_info[:step].is_a?(Integer)
|
|
539
|
-
# Session teşhis edilebilirliği (field incident 2026-10-12):
|
|
540
|
-
# saatler süren !goal koşuları session dosyasına tek satır
|
|
541
|
-
# düşürüyordu — free-text turn simetrisinde tool adımları
|
|
542
|
-
# kayıtçıya akar; render ve LLM geçmişi değişmez.
|
|
543
|
-
case step_info[:type]&.to_sym
|
|
544
|
-
when :tool_call
|
|
545
|
-
ctx.recorder&.record_tool_call(step_info[:tool], step_info[:args], call_id: step_info[:call_id])
|
|
546
|
-
when :tool_result
|
|
547
|
-
ctx.recorder&.record_tool_result(step_info[:tool], step_info[:output], status: step_info[:status] || :ok, call_id: step_info[:call_id])
|
|
548
|
-
end
|
|
549
|
-
ctx.render_step_event(step_info)
|
|
550
|
-
}
|
|
551
|
-
end
|
|
552
|
-
|
|
553
|
-
# Plan 53 D-8 yardımcısı: nötr çift + kayıtçı eşlemesi tek yerde.
|
|
554
|
-
# Session restore kayıtçı OLAYLARINDAN hidrate eder — eşlenmiş
|
|
555
|
-
# restore için conversation_history VE record_assistant_response
|
|
556
|
-
# birlikte yazılmalı (başarısızlıkta da).
|
|
557
|
-
private_class_method def self.build_goal_record_pair(ctx, goal_text)
|
|
558
|
-
lambda do |assistant_content, streamed: nil, tokens: nil|
|
|
559
|
-
ctx.conversation_history << { role: "user", content: "Goal: #{goal_text}" }
|
|
560
|
-
ctx.conversation_history << { role: "assistant", content: assistant_content }
|
|
561
|
-
ctx.recorder&.record_assistant_response(assistant_content, tokens: tokens, streamed: streamed)
|
|
562
|
-
ctx.trim_conversation_window!
|
|
563
|
-
end
|
|
564
|
-
end
|
|
565
|
-
|
|
566
|
-
# Damga meta'sındaki suspended_at (iso8601) → Time; bozuk değer
|
|
567
|
-
# nil — Loop#append_resume_marker! "unknown" downtime basar.
|
|
568
|
-
private_class_method def self.parse_suspended_at(value)
|
|
569
|
-
Time.iso8601(value.to_s)
|
|
570
|
-
rescue ArgumentError, TypeError
|
|
571
|
-
nil
|
|
572
|
-
end
|
|
573
|
-
|
|
574
|
-
# Defense-in-depth behind the loop-level goal guard: if a success
|
|
575
|
-
# terminal escapes GoalWait with live subagent units, the goal must
|
|
576
|
-
# stop honestly instead of celebrating a false completion. Fails
|
|
577
|
-
# CONSERVATIVE: coeffect absence is nil-safe (Coeffects.get never
|
|
578
|
-
# raises for a missing subsystem), so a raise here is real breakage
|
|
579
|
-
# — reporting zero would launder it into exactly the false
|
|
580
|
-
# "Goal Achieved" this backstop exists to refuse.
|
|
581
|
-
private_class_method def self.goal_active_subagent_count(ctx)
|
|
582
|
-
supervisor = Rubik::Coeffects.get(ctx.runtime_manager&.context, Rubik::Coeffects::SUBAGENT_SUPERVISOR)
|
|
583
|
-
supervisor&.active_count.to_i
|
|
584
|
-
rescue StandardError => e
|
|
585
|
-
Rubik::Log.warn(:orchestrator, "goal completion defense could not inspect subagents " \
|
|
586
|
-
"(#{e.class}: #{e.message}); refusing completion")
|
|
587
|
-
1
|
|
588
|
-
end
|
|
589
|
-
|
|
590
130
|
private_class_method def self.register_test_command(shell)
|
|
591
131
|
shell.register_command("test", description: "Run test suite via active language adapter") do |args, ctx|
|
|
592
132
|
if ctx.buffer_manager&.dirty?
|
|
@@ -623,6 +163,14 @@ module Rubik
|
|
|
623
163
|
shell.register_command("format", description: "Format target file", audience: :both) do |args, ctx|
|
|
624
164
|
target = args.first
|
|
625
165
|
if target
|
|
166
|
+
if ctx.agent_caller
|
|
167
|
+
begin
|
|
168
|
+
ctx.guard.verify_path_write!(target)
|
|
169
|
+
rescue Rubik::Security::BlockedWriteError => e
|
|
170
|
+
ctx.out.puts "Security Error: formatting critical path blocked: #{e.message}"
|
|
171
|
+
next
|
|
172
|
+
end
|
|
173
|
+
end
|
|
626
174
|
lang = Rubik::Runtime::Discovery.detect_primary_language(Dir.pwd) || "ruby"
|
|
627
175
|
adapter = ctx.adapter_registry.get(lang) || ctx.adapter_registry.get("ruby")
|
|
628
176
|
res = adapter.format_code(target)
|
|
@@ -66,7 +66,7 @@ module Rubik
|
|
|
66
66
|
if target_path && !target_path.empty?
|
|
67
67
|
rel = begin
|
|
68
68
|
ctx.buffer_manager.sanitize_path(target_path)
|
|
69
|
-
rescue
|
|
69
|
+
rescue Rubik::Buffer::InvalidPathError
|
|
70
70
|
target_path
|
|
71
71
|
end
|
|
72
72
|
if ctx.buffer_manager.dirty_files.key?(rel)
|
|
@@ -154,6 +154,10 @@ module Rubik
|
|
|
154
154
|
ctx.out.puts " • Prompt Indicator : #{ctx.config.fetch('buffer.prompt_indicator', true)}"
|
|
155
155
|
ctx.out.puts " • Reminder Interval: #{ctx.config.fetch('buffer.reminder_interval', 3)} turns"
|
|
156
156
|
elsif ["manual", "on_test", "on_finish", "always"].include?(sub)
|
|
157
|
+
if ctx.agent_caller
|
|
158
|
+
ctx.out.puts "Security Error: buffer autoapply policy is operator-only and cannot be altered by autonomous agents."
|
|
159
|
+
return
|
|
160
|
+
end
|
|
157
161
|
res = ctx.config.set("buffer.auto_apply", sub, persist: scope)
|
|
158
162
|
return if Base.report_persist_failure(ctx, res, scope)
|
|
159
163
|
|
|
@@ -21,6 +21,11 @@ module Rubik
|
|
|
21
21
|
scope, clean_args = Base.parse_scope(args)
|
|
22
22
|
sub = clean_args.first&.downcase || "status"
|
|
23
23
|
|
|
24
|
+
if ctx.agent_caller && !["status", "list", "ping", "tools"].include?(sub)
|
|
25
|
+
ctx.out.puts "Security Error: MCP server management ('#{sub}') is operator-only and cannot be altered by autonomous agents."
|
|
26
|
+
next
|
|
27
|
+
end
|
|
28
|
+
|
|
24
29
|
case sub
|
|
25
30
|
when "status"
|
|
26
31
|
status_servers(ctx, manager)
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
require_relative "base"
|
|
4
4
|
require_relative "../../orchestrator/subagent/budget"
|
|
5
5
|
require_relative "../../orchestrator/subagent/notices"
|
|
6
|
+
require_relative "../../orchestrator/subagent/admission_policy"
|
|
6
7
|
|
|
7
8
|
module Rubik
|
|
8
9
|
module REPL
|
|
@@ -105,10 +106,9 @@ module Rubik
|
|
|
105
106
|
types = sup.type_registry.list
|
|
106
107
|
ctx.out.puts "=== Available Subagent Archetypes (#{types.size}) ==="
|
|
107
108
|
types.each do |t|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
flag_str = flags.empty? ? "read-only" : flags.join(", ")
|
|
109
|
+
label = Rubik::Orchestrator::Subagent::AdmissionPolicy.capability_label(t)
|
|
110
|
+
# Same capability vocabulary the prompt's tools= attribute uses.
|
|
111
|
+
flag_str = t.enable_subagent_tools ? "#{label}, nesting" : label
|
|
112
112
|
ctx.out.puts " • #{t.name.ljust(12)} [#{flag_str}]: #{t.description}"
|
|
113
113
|
end
|
|
114
114
|
end
|
|
@@ -384,11 +384,31 @@ module Rubik
|
|
|
384
384
|
"sandbox.",
|
|
385
385
|
"subagents.",
|
|
386
386
|
"plugins.",
|
|
387
|
-
"lsp.
|
|
387
|
+
"lsp.",
|
|
388
|
+
"network.",
|
|
389
|
+
"mcp.",
|
|
390
|
+
"test.",
|
|
391
|
+
"linter.",
|
|
392
|
+
"project.test_command",
|
|
393
|
+
"adapter.",
|
|
394
|
+
"skills.paths",
|
|
395
|
+
"storage.root",
|
|
396
|
+
"buffer.model_can_apply",
|
|
397
|
+
"buffer.auto_apply",
|
|
388
398
|
"workspace.allow_external_writes",
|
|
399
|
+
"workspace.allowed_external_dirs",
|
|
400
|
+
"workspace.additional_roots",
|
|
389
401
|
"tools.circuit_breaker."
|
|
390
402
|
].freeze
|
|
391
403
|
|
|
404
|
+
def self.operator_only_config_key?(key)
|
|
405
|
+
k = key.to_s.strip
|
|
406
|
+
OPERATOR_ONLY_CONFIG_PREFIXES.any? do |p|
|
|
407
|
+
prefix = p.chomp(".")
|
|
408
|
+
k == prefix || k.start_with?("#{prefix}.")
|
|
409
|
+
end
|
|
410
|
+
end
|
|
411
|
+
|
|
392
412
|
private_class_method def self.register_config_command(shell)
|
|
393
413
|
shell.register_command("config", description: "Get, set, or view runtime configuration (set|get|list|path)",
|
|
394
414
|
usage: USAGE_CONFIG, audience: :both) do |args, ctx|
|
|
@@ -417,7 +437,7 @@ module Rubik
|
|
|
417
437
|
val = clean_args[2..]&.join(" ")
|
|
418
438
|
if key.nil? || key.empty? || val.nil? || val.empty?
|
|
419
439
|
ctx.out.puts "Usage: !config set <key> <val> [--project|--global]"
|
|
420
|
-
elsif ctx.agent_caller &&
|
|
440
|
+
elsif ctx.agent_caller && operator_only_config_key?(key)
|
|
421
441
|
# Security boundary: agents cannot alter security, sandbox, subagent governance,
|
|
422
442
|
# plugins (arbitrary code execution), LSP binary commands, or external write policies.
|
|
423
443
|
ctx.out.puts "Security Error: configuration key '#{key}' is operator-only and cannot be altered by autonomous agents."
|