rubik 0.9.0 → 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.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/ATTRIBUTION.md +1 -1
  3. data/CHANGELOG.md +108 -43
  4. data/README.md +5 -1
  5. data/lib/rubik/adapter/base.rb +19 -0
  6. data/lib/rubik/adapter/generic.rb +0 -14
  7. data/lib/rubik/adapter/node.rb +2 -0
  8. data/lib/rubik/ast/treesitter/zig_walker.rb +15 -2
  9. data/lib/rubik/cli/workspace_trust.rb +16 -0
  10. data/lib/rubik/config/defaults.rb +23 -0
  11. data/lib/rubik/config/store.rb +14 -0
  12. data/lib/rubik/kernel/dispatcher.rb +4 -4
  13. data/lib/rubik/log.rb +2 -1
  14. data/lib/rubik/lsp/client.rb +83 -180
  15. data/lib/rubik/lsp/document_store.rb +209 -0
  16. data/lib/rubik/mcp/client.rb +4 -3
  17. data/lib/rubik/mcp/manager.rb +6 -2
  18. data/lib/rubik/mcp/transport/stdio.rb +51 -9
  19. data/lib/rubik/orchestrator/goal_session.rb +505 -0
  20. data/lib/rubik/orchestrator/subagent/instance.rb +4 -0
  21. data/lib/rubik/orchestrator/subagent/journal.rb +2 -1
  22. data/lib/rubik/orchestrator/subagent/questioner.rb +21 -6
  23. data/lib/rubik/orchestrator/subagent/step_runner.rb +1 -1
  24. data/lib/rubik/orchestrator/subagent/teardown.rb +4 -0
  25. data/lib/rubik/orchestrator/subagent/transcript_formatter.rb +2 -1
  26. data/lib/rubik/orchestrator.rb +1 -0
  27. data/lib/rubik/platform.rb +15 -0
  28. data/lib/rubik/plugin/storage.rb +20 -29
  29. data/lib/rubik/repl/commands/agent_context.rb +1 -1
  30. data/lib/rubik/repl/commands/agent_execution.rb +7 -470
  31. data/lib/rubik/repl/commands/buffer.rb +1 -1
  32. data/lib/rubik/repl/commands/lsp.rb +1 -1
  33. data/lib/rubik/repl/input_loop.rb +1 -1
  34. data/lib/rubik/repl/lifecycle.rb +28 -0
  35. data/lib/rubik/runtime/manifest_store.rb +116 -0
  36. data/lib/rubik/runtime/overlay_storage.rb +247 -196
  37. data/lib/rubik/runtime/task_manager.rb +7 -2
  38. data/lib/rubik/runtime.rb +1 -0
  39. data/lib/rubik/security/allowlist.rb +167 -0
  40. data/lib/rubik/security/audit_log.rb +72 -0
  41. data/lib/rubik/security/classifier/classifier.rb +8 -0
  42. data/lib/rubik/security/command_gate.rb +567 -0
  43. data/lib/rubik/security/guard.rb +88 -1075
  44. data/lib/rubik/security/path_policy.rb +117 -0
  45. data/lib/rubik/security/synthesis_gate.rb +300 -0
  46. data/lib/rubik/security.rb +5 -0
  47. data/lib/rubik/storage/ranking.rb +113 -0
  48. data/lib/rubik/storage/store.rb +2 -92
  49. data/lib/rubik/storage/transcript_indexer.rb +2 -3
  50. data/lib/rubik/tools/builtins/grep.rb +2 -3
  51. data/lib/rubik/tools/builtins/lifecycle.rb +90 -87
  52. data/lib/rubik/tools/builtins/synthesis.rb +3 -0
  53. data/lib/rubik/tools/lifecycle_rollbacks.rb +87 -0
  54. data/lib/rubik/tools/native_search.rb +2 -1
  55. data/lib/rubik/tools/truncator.rb +25 -0
  56. data/lib/rubik/version.rb +1 -1
  57. metadata +11 -1
@@ -0,0 +1,116 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "time"
5
+ # save_manifest atomik yazımı Platform.atomic_write kullanır; dosyanın tek başına
6
+ # require edilmesi durumunda da çözümlenebilsin diye açık yüklenir.
7
+ require_relative "../platform"
8
+ require_relative "../plugin/package_inventory"
9
+
10
+ module Rubik
11
+ module Runtime
12
+ # Single home of the manifest primitives shared by Plugin::Storage and
13
+ # Runtime::OverlayStorage (issue #426): path resolution, load/save (atomic
14
+ # write via Platform.atomic_write), per-basename hash recording, hash
15
+ # verification (ONE comparison policy — constant-time, via
16
+ # Plugin::PackageInventory.secure_compare), the RUBIK_TRUST_OVERLAYS
17
+ # trust-mode seam, and the fail-closed corrupt-manifest contract.
18
+ #
19
+ # A store is directory-agnostic: callers resolve which directory a scope
20
+ # maps to. An optional `validate_path` callable receives (path, dir)
21
+ # before any manifest I/O — OverlayStorage wires its overlay-dir and
22
+ # containment checks here; Plugin::Storage passes nil (its directories
23
+ # are self-created under root/home).
24
+ class ManifestStore
25
+ MANIFEST_NAME = ".manifest.json"
26
+
27
+ def initialize(validate_path: nil)
28
+ @validate_path = validate_path
29
+ end
30
+
31
+ def manifest_path(dir)
32
+ path = File.join(dir, MANIFEST_NAME)
33
+ @validate_path&.call(path, dir)
34
+ path
35
+ end
36
+
37
+ def load_manifest(dir)
38
+ path = manifest_path(dir)
39
+ return {} unless File.exist?(path)
40
+
41
+ JSON.parse(File.read(path))
42
+ rescue JSON::ParserError, ArgumentError
43
+ {}
44
+ end
45
+
46
+ # Atomik yazım (tmp + rename): kilitsiz okuyucuların yarım manifest
47
+ # görmesini engeller (Platform.atomic_write).
48
+ def save_manifest(dir, manifest)
49
+ Platform.atomic_write(manifest_path(dir), JSON.pretty_generate(manifest))
50
+ end
51
+
52
+ # Per-basename hash record: load → merge → save. The caller owns hash
53
+ # computation (file vs normalized content) and pre-write guards; the
54
+ # store owns the entry shape and the manifest mutation.
55
+ def record_hash(dir, filename, hash, scope:)
56
+ manifest = load_manifest(dir)
57
+ manifest[filename] = {
58
+ "sha256" => hash,
59
+ "scope" => scope.to_s,
60
+ "created_at" => Time.now.iso8601
61
+ }
62
+ save_manifest(dir, manifest)
63
+ end
64
+
65
+ # Symmetric retraction: remove a basename and persist. Returns whether
66
+ # the key existed (mirrors Hash#delete's semantics).
67
+ def remove_entry(dir, filename)
68
+ manifest = load_manifest(dir)
69
+ existed = manifest.delete(filename)
70
+ save_manifest(dir, manifest) if existed
71
+ !existed.nil?
72
+ end
73
+
74
+ # The ONE hash-comparison policy. Returns :verified, :drift (recorded
75
+ # hash mismatch) or :unknown (basename not consented). Callers own the
76
+ # user-facing warn wording for :drift/:unknown — both map to :rejected.
77
+ def verify_entry(manifest, basename, current_hash)
78
+ return :unknown unless manifest.key?(basename)
79
+ return :verified if Rubik::Plugin::PackageInventory.secure_compare(current_hash, manifest[basename]["sha256"])
80
+
81
+ :drift
82
+ end
83
+
84
+ # Single trust-mode seam (issue #426): the blanket operator override
85
+ # read exactly once, here. Both storage planes (plugin and overlay)
86
+ # delegate to this predicate.
87
+ def trust_mode?
88
+ ENV["RUBIK_TRUST_OVERLAYS"] == "1"
89
+ end
90
+
91
+ # Three-state manifest probe: :missing / :valid / :corrupt. load_manifest
92
+ # deliberately keeps its {} behavior; the record/delete paths refuse
93
+ # through refuse_corrupt_manifest! instead of silently healing.
94
+ def manifest_state(dir)
95
+ path = manifest_path(dir)
96
+ return :missing unless File.exist?(path)
97
+
98
+ parsed = JSON.parse(File.read(path))
99
+ parsed.is_a?(Hash) ? :valid : :corrupt
100
+ rescue JSON::ParserError
101
+ :corrupt
102
+ end
103
+
104
+ # Single home of the fail-closed corrupt-manifest contract (issue #407):
105
+ # record and delete refuse through this one raise instead of healing a
106
+ # corrupt manifest (which would evict the other consented entries).
107
+ # `verb` reproduces the per-site message ("cannot record '...'" vs
108
+ # "cannot delete '...'"); the rest of the template is verbatim shared.
109
+ def refuse_corrupt_manifest!(dir, verb, filename)
110
+ return unless manifest_state(dir) == :corrupt
111
+
112
+ raise "cannot #{verb} '#{filename}': .manifest.json in #{dir} is corrupt; delete it and re-record overlays"
113
+ end
114
+ end
115
+ end
116
+ end