rubik 0.8.1 → 0.9.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 +2 -2
- data/CHANGELOG.md +100 -1
- data/bin/rubik +15 -10
- data/lib/rubik/cli/workspace_trust.rb +1 -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 +0 -1
- data/lib/rubik/config/schema.rb +0 -1
- 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/unit.rb +4 -3
- 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_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/notices.rb +5 -4
- data/lib/rubik/orchestrator/subagent/profile_contract.rb +4 -10
- 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/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/platform/path.rb +0 -1
- 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_execution.rb +13 -2
- data/lib/rubik/repl/commands/buffer.rb +4 -0
- 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/lifecycle.rb +3 -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/overlay_storage.rb +54 -23
- 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.rb +2 -0
- data/lib/rubik/security/classifier/classifier.rb +16 -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/guard.rb +133 -39
- 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/lifecycle.rb +1 -1
- data/lib/rubik/tools/builtins/synthesis.rb +121 -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/preflight_runner.rb +107 -14
- data/lib/rubik/tools/registry.rb +2 -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 +25 -1
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
require "time"
|
|
4
4
|
require "json"
|
|
5
5
|
require_relative "../../prompt/context_compactor"
|
|
6
|
-
require_relative "../../prompt/conversation_rows"
|
|
7
6
|
require_relative "../../storage/layout"
|
|
8
7
|
require_relative "../../uris"
|
|
8
|
+
require_relative "deep_ops"
|
|
9
9
|
require_relative "suspend_lifecycle"
|
|
10
10
|
require_relative "xml_render"
|
|
11
11
|
|
|
@@ -36,6 +36,7 @@ module Rubik
|
|
|
36
36
|
# log, degrade) doğal erişir. Σ XML render yüzeyi XmlRender'da.
|
|
37
37
|
include SuspendLifecycle
|
|
38
38
|
include XmlRender
|
|
39
|
+
include DeepOps
|
|
39
40
|
|
|
40
41
|
# A planı üretim şemasını SAHİPLENİR: goal skeleton örnek örneği
|
|
41
42
|
# üretim yüzeyi olur (frozen; verify alanları optional+allow_null —
|
|
@@ -93,10 +94,35 @@ module Rubik
|
|
|
93
94
|
ledger
|
|
94
95
|
end
|
|
95
96
|
|
|
96
|
-
# Çapraz-süreç resume
|
|
97
|
-
# (
|
|
97
|
+
# Çapraz-süreç resume fabrikası: askı damgası taşıyan Σ satırından
|
|
98
|
+
# defteri yeniden kurar (gövde JSON'u → @doc, links → @last_links,
|
|
99
|
+
# damga meta'sı → suspend_meta). YAZMA YOKTUR — load saf kurulumdur;
|
|
100
|
+
# ilk kabul yeni satır açar. Dürüst red: store / storage_id yok,
|
|
101
|
+
# satır yok, status "suspended" değil ya da gövde bozuksa / Σ
|
|
102
|
+
# şeması eksikse nil — resume handler'ı tek cümlelik ret basar.
|
|
103
|
+
# Şema red'i SAHİLENDİĞİNDE olmalı: eksik koleksiyonlu bir gövde
|
|
104
|
+
# geçse resume render'da NoMethodError ile ölür, oysa unsuspend!
|
|
105
|
+
# damgayı çoktan tüketmiş olurdu. Konum: Ledger üzerinde — kurulum
|
|
106
|
+
# fabrikası host'un kendi işidir; mixin yalnız askı durumunu taşır.
|
|
98
107
|
def load(store:, storage_id:, config: nil, dmesg: nil, event_bus: nil)
|
|
99
|
-
|
|
108
|
+
return nil unless store && storage_id
|
|
109
|
+
|
|
110
|
+
row = store.get(type: "goal", id: storage_id.to_s)
|
|
111
|
+
return nil unless row.is_a?(Hash) && row["status"] == "suspended"
|
|
112
|
+
|
|
113
|
+
doc = JSON.parse(row["body"].to_s)
|
|
114
|
+
return nil unless doc.is_a?(Hash) && doc["rev"].is_a?(Integer) &&
|
|
115
|
+
doc["objective"] && SuspendLifecycle::SIGMA_COLLECTIONS.all? { |key| doc[key].is_a?(Array) }
|
|
116
|
+
|
|
117
|
+
ledger = new(goal_text: doc["objective"].to_s,
|
|
118
|
+
max_retries: max_patch_retries(config),
|
|
119
|
+
store: store, dmesg: dmesg, event_bus: event_bus)
|
|
120
|
+
ledger.restore_from_row!(row: row, doc: doc)
|
|
121
|
+
ledger
|
|
122
|
+
rescue StandardError => e
|
|
123
|
+
Rubik::Log.warn(:goal_ledger, "goal ledger load from suspend stamp failed " \
|
|
124
|
+
"(#{e.class}: #{e.message}); cross-process resume refused")
|
|
125
|
+
nil
|
|
100
126
|
end
|
|
101
127
|
|
|
102
128
|
def config_get(config, key, default = nil)
|
|
@@ -143,7 +169,9 @@ module Rubik
|
|
|
143
169
|
return if history.nil? || !history.respond_to?(:reject!)
|
|
144
170
|
|
|
145
171
|
@monitor.synchronize do
|
|
146
|
-
|
|
172
|
+
# Σ satırı tanıması gramer tek evinden (ContextCompactor):
|
|
173
|
+
# render ve tanıma aynı sabitleri tüketir.
|
|
174
|
+
history.reject! { |msg| Prompt::ContextCompactor.ledger_message?(msg) || Prompt::ContextCompactor.drift_message?(msg) }
|
|
147
175
|
anchor = history.rindex { |msg| Prompt::ContextCompactor.goal_message?(msg) }
|
|
148
176
|
if anchor
|
|
149
177
|
history.insert(anchor + 1, { role: "user", content: render_xml })
|
|
@@ -163,10 +191,8 @@ module Rubik
|
|
|
163
191
|
|
|
164
192
|
@finalized = true
|
|
165
193
|
if @store && @storage_id
|
|
166
|
-
links
|
|
167
|
-
|
|
168
|
-
tags: ["goal-ledger", "final"], links: links, status: status.to_s)
|
|
169
|
-
@storage_id = row["id"]
|
|
194
|
+
stamp_row!(links: @last_links.merge("finish_status" => status.to_s),
|
|
195
|
+
tags: ["goal-ledger", "final"], status: status.to_s)
|
|
170
196
|
else
|
|
171
197
|
degrade_storage_once
|
|
172
198
|
end
|
|
@@ -231,19 +257,20 @@ module Rubik
|
|
|
231
257
|
{ rev: @doc["rev"], objective: @doc["objective"], storage_id: @storage_id,
|
|
232
258
|
updated_at: @updated_at, finalized: @finalized,
|
|
233
259
|
suspended: @suspend_meta.is_a?(Hash) && !@finalized,
|
|
234
|
-
suspend_meta: @suspend_meta ? deep_dup(@suspend_meta) : nil
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
open_questions: @doc["open_questions"].size, environment_notes: @doc["environment_notes"].size }
|
|
260
|
+
suspend_meta: @suspend_meta ? deep_dup(@suspend_meta) : nil }.merge(
|
|
261
|
+
PRODUCTION_SCHEMA.sections.keys.to_h { |name| [name.to_sym, @doc[name].size] }
|
|
262
|
+
)
|
|
238
263
|
end
|
|
239
264
|
end
|
|
240
265
|
|
|
241
266
|
private
|
|
242
267
|
|
|
243
268
|
def seed_doc(goal_text)
|
|
244
|
-
{ "rev" => 0, "objective" => Rubik::Platform.safe_utf8(goal_text.to_s.slice(0, 400))
|
|
245
|
-
|
|
246
|
-
|
|
269
|
+
doc = { "rev" => 0, "objective" => Rubik::Platform.safe_utf8(goal_text.to_s.slice(0, 400)) }
|
|
270
|
+
# Σ koleksiyonlarının doğum yeri şemadır (SuspendLifecycle::
|
|
271
|
+
# SIGMA_COLLECTIONS ve snapshot boyutları aynı kaynaktan türetilir).
|
|
272
|
+
PRODUCTION_SCHEMA.sections.each_key { |name| doc[name] = [] }
|
|
273
|
+
doc
|
|
247
274
|
end
|
|
248
275
|
|
|
249
276
|
def apply!(new_doc)
|
|
@@ -285,6 +312,19 @@ module Rubik
|
|
|
285
312
|
@store.put(type: "goal", title: title, body: body, tags: tags, links: links, ref: ref)
|
|
286
313
|
end
|
|
287
314
|
|
|
315
|
+
# Satır-adresli damganın tek sahibi (finalize!/suspend!/unsuspend!):
|
|
316
|
+
# id korunur, version++ — put + kimlik takası. Gerisi ÇAĞRI
|
|
317
|
+
# TARAFINDA kalır: idempotence guard'ları, links/tags/status
|
|
318
|
+
# merge'leri, degrade epilogları ve bellek-içi durum sıralaması
|
|
319
|
+
# (@finalized damgadan ÖNCE, @suspend_meta askıda ÖNCE/temizlik
|
|
320
|
+
# başarıdan SONRA) bilinçli olarak bu sıraya bağımlıdır.
|
|
321
|
+
def stamp_row!(links:, tags:, status:)
|
|
322
|
+
row = @store.put(type: "goal", id: @storage_id, title: row_title, body: canonical_json,
|
|
323
|
+
tags: tags, links: links, status: status)
|
|
324
|
+
@storage_id = row["id"]
|
|
325
|
+
row
|
|
326
|
+
end
|
|
327
|
+
|
|
288
328
|
def canonical_json
|
|
289
329
|
Rubik::Platform.safe_json_generate(@doc)
|
|
290
330
|
end
|
|
@@ -297,40 +337,6 @@ module Rubik
|
|
|
297
337
|
@storage_id ? Rubik::Uris.storage_entity(project: @store.project, type: "goal", id: @storage_id) : nil
|
|
298
338
|
end
|
|
299
339
|
|
|
300
|
-
def ledger_row?(msg)
|
|
301
|
-
return false unless Prompt::ConversationRows.row?(msg)
|
|
302
|
-
|
|
303
|
-
content = Prompt::ConversationRows.content_of(msg).to_s
|
|
304
|
-
Prompt::ConversationRows.role_of(msg) == "user" && content.start_with?("<goal_ledger ") && content.include?("</goal_ledger>")
|
|
305
|
-
end
|
|
306
|
-
|
|
307
|
-
def drift_row?(msg)
|
|
308
|
-
return false unless Prompt::ConversationRows.row?(msg)
|
|
309
|
-
|
|
310
|
-
content = Prompt::ConversationRows.content_of(msg).to_s
|
|
311
|
-
Prompt::ConversationRows.role_of(msg) == "user" && content.start_with?("<ledger_drift ") && content.include?("</ledger_drift>")
|
|
312
|
-
end
|
|
313
|
-
|
|
314
|
-
def deep_dup(value)
|
|
315
|
-
case value
|
|
316
|
-
when Hash then value.to_a.to_h { |key, val| [key.dup, deep_dup(val)] }
|
|
317
|
-
when Array then value.map { |val| deep_dup(val) }
|
|
318
|
-
else value
|
|
319
|
-
end
|
|
320
|
-
end
|
|
321
|
-
|
|
322
|
-
def deep_freeze(value)
|
|
323
|
-
case value
|
|
324
|
-
when Hash then value.each do |key, val|
|
|
325
|
-
deep_freeze(key)
|
|
326
|
-
deep_freeze(val)
|
|
327
|
-
end.freeze
|
|
328
|
-
when Array then value.each { |val| deep_freeze(val) }.freeze
|
|
329
|
-
when String then value.dup.freeze
|
|
330
|
-
else value
|
|
331
|
-
end
|
|
332
|
-
end
|
|
333
|
-
|
|
334
340
|
def log(event, message)
|
|
335
341
|
unless @dmesg.respond_to?(:log)
|
|
336
342
|
# Dürüst degradasyon (review 2026-10-10): dmesg yokken telemetri
|
|
@@ -85,6 +85,7 @@ module Rubik
|
|
|
85
85
|
|
|
86
86
|
unit.each do |row|
|
|
87
87
|
count += 1 if tombstone!(row, rev_now)
|
|
88
|
+
prune_banked_assistant!(row)
|
|
88
89
|
end
|
|
89
90
|
end
|
|
90
91
|
return { count: 0, rev: rev_now, reclaimed_tokens: 0 } if count.zero?
|
|
@@ -147,6 +148,31 @@ module Rubik
|
|
|
147
148
|
true
|
|
148
149
|
end
|
|
149
150
|
|
|
151
|
+
def prune_banked_assistant!(row)
|
|
152
|
+
return false unless Prompt::ConversationRows.row?(row)
|
|
153
|
+
return false unless Prompt::ConversationRows.role_of(row) == "assistant"
|
|
154
|
+
|
|
155
|
+
tcs = row[:tool_calls] || row["tool_calls"]
|
|
156
|
+
return false unless tcs.is_a?(Array) && !tcs.empty?
|
|
157
|
+
|
|
158
|
+
key = Prompt::ConversationRows.content_key_of(row)
|
|
159
|
+
content = row[key].to_s
|
|
160
|
+
return false if content.include?("<user_task>") || content.include?("<goal_ledger>")
|
|
161
|
+
|
|
162
|
+
modified = false
|
|
163
|
+
if row.key?(:thought) || row.key?("thought")
|
|
164
|
+
row.delete(:thought)
|
|
165
|
+
row.delete("thought")
|
|
166
|
+
modified = true
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
if row.key?(key) && !content.empty?
|
|
170
|
+
row[key] = nil
|
|
171
|
+
modified = true
|
|
172
|
+
end
|
|
173
|
+
modified
|
|
174
|
+
end
|
|
175
|
+
|
|
150
176
|
def tool_name_of(row)
|
|
151
177
|
(row[:tool_name] || row["tool_name"]).to_s
|
|
152
178
|
end
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
require "json"
|
|
4
4
|
|
|
5
|
+
require_relative "deep_ops"
|
|
6
|
+
|
|
5
7
|
module Rubik
|
|
6
8
|
module Orchestrator
|
|
7
9
|
module GoalLedger
|
|
@@ -15,16 +17,19 @@ module Rubik
|
|
|
15
17
|
# (storage round-trip'inde drift olmaz); yalnızca op'un kendi kontrol
|
|
16
18
|
# alanları (:op, :path, :tokens, :index) semboldür.
|
|
17
19
|
class Patch
|
|
20
|
+
# Derin donma disiplini tek sahibi DeepOps'tan gelir; private kalır
|
|
21
|
+
# ve sınıf yordamları içinde implicit self ile erişilir.
|
|
22
|
+
extend DeepOps
|
|
23
|
+
|
|
18
24
|
OP_VERBS = ["add", "replace", "remove"].freeze
|
|
19
25
|
OP_KEYS = ["op", "path", "value"].freeze
|
|
20
26
|
HEADER_KEYS = ["rev", "ops"].freeze
|
|
21
27
|
|
|
22
|
-
attr_reader :rev, :ops
|
|
28
|
+
attr_reader :rev, :ops
|
|
23
29
|
|
|
24
|
-
def initialize(rev, ops
|
|
30
|
+
def initialize(rev, ops)
|
|
25
31
|
@rev = rev
|
|
26
32
|
@ops = ops
|
|
27
|
-
@raw_bytesize = raw_bytesize
|
|
28
33
|
freeze
|
|
29
34
|
end
|
|
30
35
|
|
|
@@ -86,7 +91,7 @@ module Rubik
|
|
|
86
91
|
end
|
|
87
92
|
return [:rejected, reasons] unless reasons.empty?
|
|
88
93
|
|
|
89
|
-
[:ok, new(rev, ops.freeze
|
|
94
|
+
[:ok, new(rev, ops.freeze)]
|
|
90
95
|
end
|
|
91
96
|
|
|
92
97
|
# ---- sınıf-içi (private semantik; module_function köprüsü şart değil)
|
|
@@ -265,21 +270,9 @@ module Rubik
|
|
|
265
270
|
nil
|
|
266
271
|
end
|
|
267
272
|
|
|
268
|
-
def self.deep_freeze(value)
|
|
269
|
-
case value
|
|
270
|
-
when Hash then value.each do |k, v|
|
|
271
|
-
deep_freeze(k)
|
|
272
|
-
deep_freeze(v)
|
|
273
|
-
end.freeze
|
|
274
|
-
when Array then value.each { |v| deep_freeze(v) }.freeze
|
|
275
|
-
when String then value.dup.freeze
|
|
276
|
-
else value # nil / true / false / Integer / Float zaten immutable
|
|
277
|
-
end
|
|
278
|
-
end
|
|
279
|
-
|
|
280
273
|
private_class_method :header_reasons, :normalize_op, :op_shape_reason, :verb_inspect,
|
|
281
274
|
:validate_op_keys, :validate_op_verb_and_path, :validate_op_value_and_hyphen,
|
|
282
|
-
:tokenize, :hyphen_violation
|
|
275
|
+
:tokenize, :hyphen_violation
|
|
283
276
|
end
|
|
284
277
|
end
|
|
285
278
|
end
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
require "json"
|
|
4
4
|
|
|
5
|
+
require_relative "schema"
|
|
6
|
+
|
|
5
7
|
module Rubik
|
|
6
8
|
module Orchestrator
|
|
7
9
|
module GoalLedger
|
|
@@ -19,8 +21,10 @@ module Rubik
|
|
|
19
21
|
# degrade sözleşmesi: tek dürüst warn, bellek-içi resume çalışır,
|
|
20
22
|
# çapraz-süreç resume dürüstçe reddedilir — asla çökmez.
|
|
21
23
|
module SuspendLifecycle
|
|
22
|
-
# Σ çalışma gövdesinin zorunlu koleksiyonları
|
|
23
|
-
|
|
24
|
+
# Σ çalışma gövdesinin zorunlu koleksiyonları — şemadan TÜRETİLİR
|
|
25
|
+
# (tek doğum yeri Schema.goal_skeleton; Ledger.seed_doc/snapshot da
|
|
26
|
+
# aynı kaynaktan dolar. Yeni koleksiyon = tek şema düzenmesi).
|
|
27
|
+
SIGMA_COLLECTIONS = Schema.goal_skeleton.sections.keys.freeze
|
|
24
28
|
|
|
25
29
|
# Askı damgası meta'sı (load yolunda satırdan, suspend! yolunda
|
|
26
30
|
# parametreden): yukarıdaki şema; yoksa nil.
|
|
@@ -32,10 +36,8 @@ module Rubik
|
|
|
32
36
|
|
|
33
37
|
@suspend_meta = deep_dup(meta.to_h.transform_keys(&:to_s))
|
|
34
38
|
if @store && @storage_id
|
|
35
|
-
links
|
|
36
|
-
|
|
37
|
-
tags: ["goal-ledger"], links: links, status: "suspended")
|
|
38
|
-
@storage_id = row["id"]
|
|
39
|
+
stamp_row!(links: @last_links.merge("suspended" => Rubik::Platform.safe_json_generate(@suspend_meta)),
|
|
40
|
+
tags: ["goal-ledger"], status: "suspended")
|
|
39
41
|
else
|
|
40
42
|
degrade_storage_once
|
|
41
43
|
end
|
|
@@ -56,9 +58,7 @@ module Rubik
|
|
|
56
58
|
return nil if @finalized
|
|
57
59
|
return nil unless @store && @storage_id
|
|
58
60
|
|
|
59
|
-
|
|
60
|
-
tags: ["goal-ledger"], links: @last_links, status: "active")
|
|
61
|
-
@storage_id = row["id"]
|
|
61
|
+
stamp_row!(links: @last_links, tags: ["goal-ledger"], status: "active")
|
|
62
62
|
@suspend_meta = nil
|
|
63
63
|
log(:unsuspended, "goal ledger resume at rev #{@doc['rev']}")
|
|
64
64
|
final_result
|
|
@@ -87,38 +87,6 @@ module Rubik
|
|
|
87
87
|
self
|
|
88
88
|
end
|
|
89
89
|
|
|
90
|
-
class << self
|
|
91
|
-
# Çapraz-süreç resume fabrikası: askı damgası taşıyan Σ satırından
|
|
92
|
-
# defteri yeniden kurar (gövde JSON'u → @doc, links → @last_links,
|
|
93
|
-
# damga meta'sı → suspend_meta). YAZMA YOKTUR — load saf
|
|
94
|
-
# kurulumdur; ilk kabul yeni satır açar. Dürüst red: store /
|
|
95
|
-
# storage_id yok, satır yok, status "suspended" değil ya da gövde
|
|
96
|
-
# bozuksa / Σ şeması eksikse nil — resume handler'ı tek cümlelik
|
|
97
|
-
# ret basar. Şema red'i SAHİLENDİĞİNDE olmalı: eksik koleksiyonlu
|
|
98
|
-
# bir gövde geçse resume render'da NoMethodError ile ölür, oysa
|
|
99
|
-
# unsuspend! damgayı çoktan tüketmiş olurdu.
|
|
100
|
-
def load(store:, storage_id:, config: nil, dmesg: nil, event_bus: nil)
|
|
101
|
-
return nil unless store && storage_id
|
|
102
|
-
|
|
103
|
-
row = store.get(type: "goal", id: storage_id.to_s)
|
|
104
|
-
return nil unless row.is_a?(Hash) && row["status"] == "suspended"
|
|
105
|
-
|
|
106
|
-
doc = JSON.parse(row["body"].to_s)
|
|
107
|
-
return nil unless doc.is_a?(Hash) && doc["rev"].is_a?(Integer) &&
|
|
108
|
-
doc["objective"] && SIGMA_COLLECTIONS.all? { |key| doc[key].is_a?(Array) }
|
|
109
|
-
|
|
110
|
-
ledger = Ledger.new(goal_text: doc["objective"].to_s,
|
|
111
|
-
max_retries: Ledger.max_patch_retries(config),
|
|
112
|
-
store: store, dmesg: dmesg, event_bus: event_bus)
|
|
113
|
-
ledger.restore_from_row!(row: row, doc: doc)
|
|
114
|
-
ledger
|
|
115
|
-
rescue StandardError => e
|
|
116
|
-
Rubik::Log.warn(:goal_ledger, "goal ledger load from suspend stamp failed " \
|
|
117
|
-
"(#{e.class}: #{e.message}); cross-process resume refused")
|
|
118
|
-
nil
|
|
119
|
-
end
|
|
120
|
-
end
|
|
121
|
-
|
|
122
90
|
private
|
|
123
91
|
|
|
124
92
|
# Satır links'indeki askı damgası meta'sını çözer (bozuk JSON →
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative "deep_ops"
|
|
4
|
+
|
|
3
5
|
module Rubik
|
|
4
6
|
module Orchestrator
|
|
5
7
|
module GoalLedger
|
|
@@ -14,6 +16,10 @@ module Rubik
|
|
|
14
16
|
# cap'lidir; validator'u dökümanı sınırsız büyütecek şekilde çağırmak
|
|
15
17
|
# sözleşme dışıdır).
|
|
16
18
|
module Validator
|
|
19
|
+
# Derin kopya/donma disiplini tek sahibi DeepOps'tan gelir; private
|
|
20
|
+
# kalır ve validate içinde implicit self ile erişilir.
|
|
21
|
+
extend DeepOps
|
|
22
|
+
|
|
17
23
|
module_function
|
|
18
24
|
|
|
19
25
|
# patch_or_text: String (önce parse edilir) | GoalLedger::Patch
|
|
@@ -335,26 +341,6 @@ module Rubik
|
|
|
335
341
|
def rejection(kind, op_index, path, message, hint)
|
|
336
342
|
GoalLedger.reason(kind, op_index: op_index, path: path, message: message, hint: hint)
|
|
337
343
|
end
|
|
338
|
-
|
|
339
|
-
def deep_dup(value)
|
|
340
|
-
case value
|
|
341
|
-
when Hash then value.to_a.to_h { |key, val| [key.dup, deep_dup(val)] }
|
|
342
|
-
when Array then value.map { |val| deep_dup(val) }
|
|
343
|
-
else value
|
|
344
|
-
end
|
|
345
|
-
end
|
|
346
|
-
|
|
347
|
-
def deep_freeze(value)
|
|
348
|
-
case value
|
|
349
|
-
when Hash then value.each do |key, val|
|
|
350
|
-
deep_freeze(key)
|
|
351
|
-
deep_freeze(val)
|
|
352
|
-
end.freeze
|
|
353
|
-
when Array then value.each { |val| deep_freeze(val) }.freeze
|
|
354
|
-
when String then value.dup.freeze
|
|
355
|
-
else value
|
|
356
|
-
end
|
|
357
|
-
end
|
|
358
344
|
end
|
|
359
345
|
end
|
|
360
346
|
end
|
|
@@ -17,17 +17,10 @@ module Rubik
|
|
|
17
17
|
module Verifier
|
|
18
18
|
module_function
|
|
19
19
|
|
|
20
|
-
# Adım sınırı girişi (loop.rb execute_steps hook'u): knob FIRST —
|
|
21
|
-
# kapalıysa hiç dokunma. goal_mode? guard'ı çağıran taraftadır.
|
|
22
|
-
def at_step_boundary!(loop_inst)
|
|
23
|
-
ledger = Rubik::Coeffects.get(loop_inst.runtime_manager&.context, Rubik::Coeffects::GOAL_LEDGER)
|
|
24
|
-
return nil unless ledger
|
|
25
|
-
|
|
26
|
-
verify!(ledger, trigger: :step, root_dir: loop_inst.buffer_manager&.root_dir || Dir.pwd,
|
|
27
|
-
config: loop_inst.config)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
20
|
# -> nil (knob off / boş) | {rev:, flipped:, unknowns:, note:}
|
|
21
|
+
# Giriş çözümü çağıranındır (loop.rb verify_goal_ledger!): Verifier
|
|
22
|
+
# yalnız değerlerle konuşur (ledger, root_dir, config) — Loop'un iç
|
|
23
|
+
# yüzünü tanımaz. goal_mode? guard'ı da çağıran taraftadır.
|
|
31
24
|
def verify!(ledger, trigger:, root_dir:, config: nil)
|
|
32
25
|
return nil unless Ledger.verify_enabled?(config)
|
|
33
26
|
|
|
@@ -111,10 +104,6 @@ module Rubik
|
|
|
111
104
|
[:failed, "file_contains #{spec[:path]}: needle absent"]
|
|
112
105
|
end
|
|
113
106
|
|
|
114
|
-
def stale?(item)
|
|
115
|
-
item["status"] == "stale"
|
|
116
|
-
end
|
|
117
|
-
|
|
118
107
|
def entry(collection, idx, item, state, reason)
|
|
119
108
|
{ collection: collection, index: idx, id: item_id(item), state: state, reason: reason,
|
|
120
109
|
from: item["status"], at: Time.now.utc.iso8601 }
|
|
@@ -12,10 +12,15 @@ module Rubik
|
|
|
12
12
|
@monitor.synchronize { render_xml }
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
+
def to_json(*_args)
|
|
16
|
+
@monitor.synchronize { Rubik::Platform.safe_json_generate(@doc) }
|
|
17
|
+
end
|
|
18
|
+
|
|
15
19
|
# §4.1 render: GoalState#to_xml mold'u — tüm metin xml_escape'ten
|
|
16
20
|
# geçer; boş koleksiyonların etiketi HİÇ basılmaz ("yokluk, boşluk
|
|
17
21
|
# değil" kuralı); optional attribute'lar (storage_id, verify) yalnız
|
|
18
|
-
# set iken basılır
|
|
22
|
+
# set iken basılır; koleksiyon öğeleri RFC 6902 JSON-pointer adresi
|
|
23
|
+
# için açık `index` taşır.
|
|
19
24
|
def render_xml
|
|
20
25
|
esc = Rubik::Platform.method(:xml_escape)
|
|
21
26
|
attrs = %(rev="#{@doc['rev']}")
|
|
@@ -23,36 +28,38 @@ module Rubik
|
|
|
23
28
|
attrs += %( updated_at="#{@updated_at.utc.iso8601}") if @updated_at
|
|
24
29
|
body = []
|
|
25
30
|
body << %( <objective>#{esc.call(@doc['objective'].to_s)}</objective>)
|
|
26
|
-
tasks = @doc["tasks"].map do |task|
|
|
31
|
+
tasks = @doc["tasks"].each_with_index.map do |task, idx|
|
|
27
32
|
text = task["title"].to_s
|
|
28
33
|
text += " — notes: #{task['notes']}" if task["notes"]
|
|
29
|
-
attrs_t = %(id="#{esc.call(task['id'].to_s)}" status="#{esc.call(task['status'].to_s)}")
|
|
30
|
-
|
|
34
|
+
attrs_t = %(id="#{esc.call(task['id'].to_s)}" status="#{esc.call(task['status'].to_s)}" index="#{idx}")
|
|
35
|
+
verify_val = task["verify"].is_a?(Hash) ? Rubik::Platform.safe_json_generate(task["verify"]) : task["verify"].to_s
|
|
36
|
+
attrs_t += %( verify="#{esc.call(verify_val)}") if task["verify"]
|
|
31
37
|
task["title"] || task["notes"] ? %( <task #{attrs_t}>#{esc.call(text)}</task>) : %( <task #{attrs_t} />)
|
|
32
38
|
end
|
|
33
39
|
body << "<tasks>\n#{tasks.join("\n")}\n </tasks>" unless tasks.empty?
|
|
34
|
-
findings = @doc["findings"].map do |f|
|
|
35
|
-
%( <finding id="#{esc.call(f['id'].to_s)}" source_step="#{f['source_step']}">#{esc.call(f['text'].to_s)}</finding>)
|
|
40
|
+
findings = @doc["findings"].each_with_index.map do |f, idx|
|
|
41
|
+
%( <finding id="#{esc.call(f['id'].to_s)}" source_step="#{f['source_step']}" index="#{idx}">#{esc.call(f['text'].to_s)}</finding>)
|
|
36
42
|
end
|
|
37
43
|
body << "<findings>\n#{findings.join("\n")}\n </findings>" unless findings.empty?
|
|
38
|
-
decisions = @doc["decisions"].map do |dec|
|
|
39
|
-
attrs_d = %(id="#{esc.call(dec['id'].to_s)}")
|
|
44
|
+
decisions = @doc["decisions"].each_with_index.map do |dec, idx|
|
|
45
|
+
attrs_d = %(id="#{esc.call(dec['id'].to_s)}" index="#{idx}")
|
|
40
46
|
attrs_d += %( rationale="#{esc.call(dec['rationale'].to_s)}") if dec["rationale"]
|
|
41
47
|
%( <decision #{attrs_d}>#{esc.call(dec['text'].to_s)}</decision>)
|
|
42
48
|
end
|
|
43
49
|
body << "<decisions>\n#{decisions.join("\n")}\n </decisions>" unless decisions.empty?
|
|
44
|
-
questions = @doc["open_questions"].map { |q| %( <question>#{esc.call(q.to_s)}</question>) }
|
|
50
|
+
questions = @doc["open_questions"].each_with_index.map { |q, idx| %( <question index="#{idx}">#{esc.call(q.to_s)}</question>) }
|
|
45
51
|
body << "<open_questions>\n#{questions.join("\n")}\n </open_questions>" unless questions.empty?
|
|
46
|
-
notes = @doc["environment_notes"].map do |note|
|
|
47
|
-
attrs_n = %(id="#{esc.call(note['id'].to_s)}")
|
|
48
|
-
|
|
52
|
+
notes = @doc["environment_notes"].each_with_index.map do |note, idx|
|
|
53
|
+
attrs_n = %(id="#{esc.call(note['id'].to_s)}" index="#{idx}")
|
|
54
|
+
verify_val = note["verify"].is_a?(Hash) ? Rubik::Platform.safe_json_generate(note["verify"]) : note["verify"].to_s
|
|
55
|
+
attrs_n += %( verify="#{esc.call(verify_val)}") if note["verify"]
|
|
49
56
|
%( <note #{attrs_n}>#{esc.call(note['text'].to_s)}</note>)
|
|
50
57
|
end
|
|
51
58
|
body << "<environment_notes>\n#{notes.join("\n")}\n </environment_notes>" unless notes.empty?
|
|
52
59
|
<<~XML.strip
|
|
53
|
-
|
|
60
|
+
<#{Prompt::ContextCompactor::GOAL_LEDGER_TAG} #{attrs}>
|
|
54
61
|
#{body.join("\n")}
|
|
55
|
-
|
|
62
|
+
</#{Prompt::ContextCompactor::GOAL_LEDGER_TAG}>
|
|
56
63
|
XML
|
|
57
64
|
end
|
|
58
65
|
end
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require "monitor"
|
|
4
4
|
require "time"
|
|
5
|
+
require_relative "../events"
|
|
5
6
|
require_relative "../platform"
|
|
6
7
|
|
|
7
8
|
module Rubik
|
|
@@ -12,12 +13,13 @@ module Rubik
|
|
|
12
13
|
# — okuma (read_file) her an güvenli olmalıdır.
|
|
13
14
|
class GoalState
|
|
14
15
|
# Bitiş olayının bus adı (Vakanüvis kronikçisinin goal kancası — K3;
|
|
15
|
-
# REPL bu olaya abone değildir, notice/wake üretilmez).
|
|
16
|
-
|
|
16
|
+
# REPL bu olaya abone değildir, notice/wake üretilmez). İsim tek
|
|
17
|
+
# yaprakta: Rubik::Events (bağımlılıksız söz dağarcığı).
|
|
18
|
+
FINISH_EVENT = Rubik::Events::GOAL_FINISHED
|
|
17
19
|
# Askı olayının bus adı (issue #106): transient transport hatası
|
|
18
20
|
# goal'u terminal değil SUSPENDED'a götürür — kronikçi askıyı da
|
|
19
21
|
# görsün; REPL yine abone değildir.
|
|
20
|
-
SUSPEND_EVENT =
|
|
22
|
+
SUSPEND_EVENT = Rubik::Events::GOAL_SUSPENDED
|
|
21
23
|
|
|
22
24
|
def initialize(event_bus: nil)
|
|
23
25
|
@monitor = Monitor.new
|
|
@@ -87,15 +89,6 @@ module Rubik
|
|
|
87
89
|
self
|
|
88
90
|
end
|
|
89
91
|
|
|
90
|
-
def record_tokens!(usage)
|
|
91
|
-
@monitor.synchronize do
|
|
92
|
-
u = usage.to_h
|
|
93
|
-
@tokens[:input] += u[:input].to_i
|
|
94
|
-
@tokens[:output] += u[:output].to_i
|
|
95
|
-
end
|
|
96
|
-
self
|
|
97
|
-
end
|
|
98
|
-
|
|
99
92
|
def complete!(output_summary = nil, tokens: nil)
|
|
100
93
|
@monitor.synchronize do
|
|
101
94
|
return self unless @status == :running
|
|
@@ -138,9 +131,16 @@ module Rubik
|
|
|
138
131
|
return self unless @status == :running
|
|
139
132
|
|
|
140
133
|
@last_error = Rubik::Platform.safe_utf8(reason.to_s).slice(0, 300)
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
134
|
+
if tokens
|
|
135
|
+
# Mutlak atama (restore_counters! moldu): Loop'un kümülatif
|
|
136
|
+
# token sayacı SSOT'tur. += askı→resume→askı döngüsünde ilk
|
|
137
|
+
# askının kullanımını iki kez sayardı — mutlak atama idempotent
|
|
138
|
+
# kalır ve Σ damgasıyla hep aynı değeri taşır. tokens: nil
|
|
139
|
+
# mevcut değerleri korur (sayaç korunumu sözleşmesi).
|
|
140
|
+
t = tokens.to_h
|
|
141
|
+
@tokens = { input: (t[:input] || t["input"]).to_i,
|
|
142
|
+
output: (t[:output] || t["output"]).to_i }
|
|
143
|
+
end
|
|
144
144
|
@status = :suspended
|
|
145
145
|
end
|
|
146
146
|
notify_suspend
|