rubik 0.10.0 → 0.11.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 +61 -1
- data/lib/rubik/ast/extractor.rb +2 -1
- data/lib/rubik/ast/treesitter_extractor.rb +2 -1
- data/lib/rubik/benchmark/vakanuvis_adoption.rb +2 -1
- data/lib/rubik/config/secret_policy.rb +6 -5
- data/lib/rubik/config/store.rb +2 -1
- data/lib/rubik/config.rb +2 -2
- data/lib/rubik/context/ignore_rules.rb +193 -0
- data/lib/rubik/context/scanner.rb +46 -161
- data/lib/rubik/llm/client.rb +6 -200
- data/lib/rubik/llm/connection_pool.rb +104 -0
- data/lib/rubik/llm/registry.rb +3 -2
- data/lib/rubik/llm/sse_parser.rb +110 -0
- data/lib/rubik/lsp/circuit_breaker.rb +98 -0
- data/lib/rubik/lsp/client_provisioner.rb +49 -0
- data/lib/rubik/lsp/manager.rb +55 -88
- data/lib/rubik/mcp/manager.rb +25 -13
- data/lib/rubik/orchestrator/auto_apply.rb +4 -3
- data/lib/rubik/orchestrator/goal_ledger/ledger.rb +12 -1
- data/lib/rubik/orchestrator/goal_ledger/schema_vocabulary.rb +38 -0
- data/lib/rubik/orchestrator/goal_ledger/xml_render.rb +6 -1
- data/lib/rubik/orchestrator/goal_ledger.rb +1 -0
- data/lib/rubik/orchestrator/lsp_feedback.rb +1 -1
- data/lib/rubik/orchestrator/step_executor.rb +2 -1
- data/lib/rubik/orchestrator/subagent/notices.rb +2 -2
- data/lib/rubik/orchestrator/subagent/transcript_formatter.rb +2 -1
- data/lib/rubik/platform/io_drain.rb +3 -1
- data/lib/rubik/plugin/storage.rb +8 -8
- data/lib/rubik/repl/config_wiring.rb +5 -3
- data/lib/rubik/repl/input_execution.rb +4 -3
- data/lib/rubik/repl/lifecycle.rb +1 -1
- data/lib/rubik/repl/tee_io.rb +2 -1
- data/lib/rubik/runtime/ast_service.rb +2 -1
- data/lib/rubik/runtime/overlay_storage.rb +17 -17
- data/lib/rubik/runtime/task_manager.rb +1 -1
- data/lib/rubik/sandbox/runner.rb +5 -4
- data/lib/rubik/security/audit_log.rb +2 -1
- data/lib/rubik/security/command_gate.rb +11 -152
- data/lib/rubik/security/guard.rb +1 -1
- data/lib/rubik/security/secret_store.rb +32 -3
- data/lib/rubik/security/segment_report.rb +161 -0
- data/lib/rubik/session/recorder.rb +2 -1
- data/lib/rubik/skills/manager.rb +2 -1
- data/lib/rubik/storage/transcript_indexer.rb +3 -2
- data/lib/rubik/storage/vakanuvis.rb +2 -1
- data/lib/rubik/tools/builtins/goal_ledger.rb +12 -1
- data/lib/rubik/tools/builtins/synthesis.rb +3 -3
- data/lib/rubik/tools/preflight_runner.rb +2 -1
- data/lib/rubik/tools/uri_resolver.rb +3 -2
- data/lib/rubik/ui/capability.rb +1 -0
- data/lib/rubik/version.rb +1 -1
- data/lib/rubik.rb +3 -3
- metadata +8 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c51c73960cae7dc1fc2f89745c3261cc1d4693bbde7c449175f5c16b8f076bbd
|
|
4
|
+
data.tar.gz: 7f570e596aafd7ad9b82d634ef9a38d739e027eb2a7c50b613c2b97be5850c6b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ab509129d3f7f20498535c0b51f48e1a902af9484108eb0c12f3f8c13cc5010e1a359f6474aca6742dd09a16e4dded9645ab41b844afbea5eb01b41e7a09725e
|
|
7
|
+
data.tar.gz: 40430100af1ca2a9049ace43864ea82d3dcfad72e005ac1698fe71c5b0a7585e56b32f59a22aea1e7339ea689dd569e346f2f540273ac633e5cfd409c9c1386c
|
data/ATTRIBUTION.md
CHANGED
|
@@ -121,7 +121,7 @@ SOFTWARE.
|
|
|
121
121
|
| **`strings-ansi`** | Piotr Murach | MIT | ANSI-aware string truncation and alignment for REPL formatters. |
|
|
122
122
|
| **`reline`** | Hiroshi SHIBATA & Ruby Team | Ruby License / BSD-2-Clause | Line-editing, history navigation, autocompletion hooks, and headless terminal adaptation. |
|
|
123
123
|
| **`prism`** | Kevin Newton & Ruby Core Team | MIT | High-performance Ruby parsing and AST extraction ([`Rubik::AST::RubyExtractor`](lib/rubik/ast/ruby_extractor.rb)). |
|
|
124
|
-
| **`minitest`** | Ryan Davis & seattlerb | MIT | Fast, modular test suite powering Rubik's 4,
|
|
124
|
+
| **`minitest`** | Ryan Davis & seattlerb | MIT | Fast, modular test suite powering Rubik's 4,600+ unit, integration, and contract tests. |
|
|
125
125
|
| **`rubocop`** | Bozhidar Batsov & contributors | MIT | Static code analysis, style enforcement, and architectural hygiene gates. |
|
|
126
126
|
| **`benchmark`, `logger`, `pstore`, `reline`, `fiddle`** | Ruby core / rubygems teams | Ruby License / BSD-2-Clause | Ruby stdlib gems pinned explicitly in `rubik.gemspec` as they are unbundled from the default set in Ruby 3.4/3.5. |
|
|
127
127
|
|
data/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,65 @@ commits, 2026-08-23 → 2026-10-09, see `git log`).
|
|
|
6
6
|
|
|
7
7
|
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
8
8
|
|
|
9
|
+
## [0.11.0] - 2026-11-16
|
|
10
|
+
|
|
11
|
+
The schema-grammar minor: the goal-ledger stops teaching its schema through
|
|
12
|
+
failure — the bounded-retry protocol's rejection hints no longer carry the
|
|
13
|
+
only copy of the grammar, which is now derived from `Ledger::PRODUCTION_SCHEMA`
|
|
14
|
+
and surfaced on every static model-facing surface — while the extraction wave
|
|
15
|
+
keeps sweeping (an SSE parser and connection pool out of the LLM client, a
|
|
16
|
+
segment report out of the command gate, a circuit breaker out of the LSP
|
|
17
|
+
manager, an ignore-rules value object out of the context scanner), duplicated
|
|
18
|
+
invariants collapse onto single homes, the remaining `Kernel#warn` sites move
|
|
19
|
+
onto `Rubik::Log`, and the secret-store backends get hardened against IO
|
|
20
|
+
failures.
|
|
21
|
+
|
|
22
|
+
### Added
|
|
23
|
+
|
|
24
|
+
- **Goal-ledger schema grammar on static surfaces (#494):** a single-line
|
|
25
|
+
grammar summary derived from `Ledger::PRODUCTION_SCHEMA` (schema SSOT, never
|
|
26
|
+
hand-written) now appears in the `update_goal_ledger` tool description, as a
|
|
27
|
+
state-independent `<vocabulary>` element on the Sigma XML page, and in the
|
|
28
|
+
patch-budget-exhausted feedback — so a model no longer has to burn its
|
|
29
|
+
rejection budget to learn the status enum, the required id, or the
|
|
30
|
+
section-append rule. The exhaustion contract stays verbatim and rejection
|
|
31
|
+
reasons are deliberately not cached.
|
|
32
|
+
|
|
33
|
+
### Changed
|
|
34
|
+
|
|
35
|
+
- **Remaining `Kernel#warn` call sites migrate onto `Rubik::Log` (#510):**
|
|
36
|
+
all user-facing diagnostic emissions route through the sanctioned
|
|
37
|
+
`Log.warn(:subsystem, message)` seam with message content (including
|
|
38
|
+
`[WARN]`/`[SECURITY]`/`[DEPRECATION]`/`[BOOTSTRAP]` prefixes) preserved
|
|
39
|
+
verbatim; only the two sanctioned `$stderr` sites remain.
|
|
40
|
+
- **SegmentReport extracted from CommandGate (#508).**
|
|
41
|
+
- **SSEParser and ConnectionPool split out of the LLM client (#505).**
|
|
42
|
+
- **IgnoreRules value object extracted from the context Scanner (#498).**
|
|
43
|
+
- **LSP circuit breaker and client provisioning extracted from Manager
|
|
44
|
+
(#497).**
|
|
45
|
+
- **Duplicated invariants single-homed (#502):** SSEParser's two drain loops
|
|
46
|
+
collapse into `drain_complete_events(final:)`, `post_stream_json` reuses
|
|
47
|
+
`parse_and_validate_uri`, the MCP D5 boot gate resolves through one
|
|
48
|
+
`boot_gate_open?` predicate, the Scanner's reserved-root rejections back
|
|
49
|
+
onto one `reserved_root?`, and the two EXTENSION_MAPs get cross-reference
|
|
50
|
+
comments so their deliberate divergence stays explicit.
|
|
51
|
+
|
|
52
|
+
### Fixed
|
|
53
|
+
|
|
54
|
+
- **Isolated `capability.rb` loads require `repl/tee_io` (#509):** an isolated
|
|
55
|
+
load no longer NameErrors.
|
|
56
|
+
- **Three small goal-ledger and secret-policy defects (#496):** XmlRender
|
|
57
|
+
escapes the finding `source_step` attribute (a corrupted suspend row could
|
|
58
|
+
inject raw text into the conversation-history XML), `Ledger#update`
|
|
59
|
+
validates patches inside the monitor, and SecretPolicy drops an unreachable
|
|
60
|
+
store-failure guard.
|
|
61
|
+
- **SecretStore command backends hardened against IO failures (#495):**
|
|
62
|
+
`IOError`/`SystemCallError` convert to `SecretStore::Error`, the stdin
|
|
63
|
+
payload travels through `Platform.write_until` with a 5s deadline instead of
|
|
64
|
+
parking `Config#set` on a full pipe buffer, the Linux backend clears prior
|
|
65
|
+
items before storing (a re-set secret previously resolved to a corrupted
|
|
66
|
+
concatenation), and the macOS reader keeps significant whitespace.
|
|
67
|
+
|
|
9
68
|
## [0.10.0] - 2026-11-15
|
|
10
69
|
|
|
11
70
|
The secret-store minor: provider credentials leave the config files for the
|
|
@@ -1670,7 +1729,8 @@ installation section.
|
|
|
1670
1729
|
- Context: serialized index mutations, snapshot-outside-lock reconcile,
|
|
1671
1730
|
streaming-first truncation.
|
|
1672
1731
|
|
|
1673
|
-
[Unreleased]: https://github.com/ozgurulukir/rubik/compare/v0.
|
|
1732
|
+
[Unreleased]: https://github.com/ozgurulukir/rubik/compare/v0.11.0...HEAD
|
|
1733
|
+
[0.11.0]: https://github.com/ozgurulukir/rubik/compare/v0.10.0...v0.11.0
|
|
1674
1734
|
[0.10.0]: https://github.com/ozgurulukir/rubik/compare/v0.9.1...v0.10.0
|
|
1675
1735
|
[0.9.1]: https://github.com/ozgurulukir/rubik/compare/v0.9.0...v0.9.1
|
|
1676
1736
|
[0.9.0]: https://github.com/ozgurulukir/rubik/compare/v0.8.1...v0.9.0
|
data/lib/rubik/ast/extractor.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative "../log"
|
|
3
4
|
require_relative "extraction_result"
|
|
4
5
|
require_relative "ruby_extractor"
|
|
5
6
|
require_relative "go_extractor"
|
|
@@ -66,7 +67,7 @@ module Rubik
|
|
|
66
67
|
# language extractor claims (:unavailable, legacy Ruby parse).
|
|
67
68
|
fallback_result(file_path, content, ext)
|
|
68
69
|
rescue StandardError, ScriptError => e
|
|
69
|
-
warn "[WARN] Extraction failed for #{file_path}: #{e.class}: #{e.message}" if ENV["RUBIK_DEBUG"]
|
|
70
|
+
Rubik::Log.warn(:ast, "[WARN] Extraction failed for #{file_path}: #{e.class}: #{e.message}") if ENV["RUBIK_DEBUG"]
|
|
70
71
|
ExtractionResult.new(symbols: [], status: :failed, source: :none, detail: "#{e.class}: #{e.message}")
|
|
71
72
|
end
|
|
72
73
|
|
|
@@ -7,6 +7,7 @@ rescue LoadError
|
|
|
7
7
|
TREE_SITTER_AVAILABLE = false
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
+
require_relative "../log"
|
|
10
11
|
require_relative "extraction_result"
|
|
11
12
|
require_relative "treesitter/base_walker"
|
|
12
13
|
require_relative "treesitter/python_walker"
|
|
@@ -94,7 +95,7 @@ module Rubik
|
|
|
94
95
|
|
|
95
96
|
ExtractionResult.new(symbols: symbols, status: :ok, source: :tree_sitter)
|
|
96
97
|
rescue StandardError, SystemStackError, ScriptError => e
|
|
97
|
-
warn "[WARN] TreeSitter extraction failed for #{file_path}: #{e.message}" if ENV["RUBIK_DEBUG"]
|
|
98
|
+
Rubik::Log.warn(:ast, "[WARN] TreeSitter extraction failed for #{file_path}: #{e.message}") if ENV["RUBIK_DEBUG"]
|
|
98
99
|
failed_result("#{e.class}: #{e.message}")
|
|
99
100
|
end
|
|
100
101
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require "tmpdir"
|
|
4
4
|
require "fileutils"
|
|
5
|
+
require_relative "../log"
|
|
5
6
|
require_relative "../errors"
|
|
6
7
|
require_relative "../storage/vakanuvis"
|
|
7
8
|
require_relative "../tools/builtins/storage"
|
|
@@ -347,7 +348,7 @@ module Rubik
|
|
|
347
348
|
# Windows EBUSY/ENOTEMPTY (AV tarayıcı, indeksleyici) cleanup'ı
|
|
348
349
|
# patlatabilir — cleanup hatası tabloyu ve işlenen hatayı
|
|
349
350
|
# MaskeleMEsin; tüm benchmark'ı da abort etmesin.
|
|
350
|
-
warn " [vakanuvis-adoption] cleanup failed for #{root}: #{e.class}: #{e.message}"
|
|
351
|
+
Rubik::Log.warn(:benchmark, " [vakanuvis-adoption] cleanup failed for #{root}: #{e.class}: #{e.message}")
|
|
351
352
|
end
|
|
352
353
|
end
|
|
353
354
|
end
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative "../log"
|
|
3
4
|
require_relative "../security/secret_store"
|
|
4
5
|
|
|
5
6
|
module Rubik
|
|
@@ -84,10 +85,10 @@ module Rubik
|
|
|
84
85
|
|
|
85
86
|
if store_error
|
|
86
87
|
# gh-style degradation: the write proceeds with plaintext plus a
|
|
87
|
-
# loud warning
|
|
88
|
-
#
|
|
89
|
-
|
|
90
|
-
|
|
88
|
+
# loud warning. Project scope never reaches this fallback with
|
|
89
|
+
# the plaintext guard closed — that refusal happens up front,
|
|
90
|
+
# before the store loop, so a store failure here can only mean
|
|
91
|
+
# the override was open.
|
|
91
92
|
warn_secret_store_fallback(store_error, scope)
|
|
92
93
|
return { info: plaintext_fallback_info }
|
|
93
94
|
end
|
|
@@ -185,7 +186,7 @@ module Rubik
|
|
|
185
186
|
def warn_secret_store_fallback(error, scope)
|
|
186
187
|
msg = "OS secret store unavailable (#{error.message}); plaintext kept in #{scope} config"
|
|
187
188
|
@warnings << msg
|
|
188
|
-
warn "[WARN] #{msg}" if ENV["RUBIK_DEBUG"]
|
|
189
|
+
Rubik::Log.warn(:config, "[WARN] #{msg}") if ENV["RUBIK_DEBUG"]
|
|
189
190
|
end
|
|
190
191
|
|
|
191
192
|
def plaintext_fallback_info
|
data/lib/rubik/config/store.rb
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
require "yaml"
|
|
4
4
|
require "yaml/store"
|
|
5
5
|
require "fileutils"
|
|
6
|
+
require_relative "../log"
|
|
6
7
|
require_relative "pruner"
|
|
7
8
|
|
|
8
9
|
module Rubik
|
|
@@ -38,7 +39,7 @@ module Rubik
|
|
|
38
39
|
begin
|
|
39
40
|
FileUtils.mkdir_p(File.dirname(path))
|
|
40
41
|
rescue SystemCallError => e
|
|
41
|
-
warn "[WARN] Failed to create config directory #{File.dirname(path)}: #{e.message}" if ENV["RUBIK_DEBUG"]
|
|
42
|
+
Rubik::Log.warn(:config, "[WARN] Failed to create config directory #{File.dirname(path)}: #{e.message}") if ENV["RUBIK_DEBUG"]
|
|
42
43
|
end
|
|
43
44
|
YAML::Store.new(path, true)
|
|
44
45
|
end
|
data/lib/rubik/config.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "monitor"
|
|
4
|
+
require_relative "log"
|
|
4
5
|
require_relative "config/defaults"
|
|
5
6
|
require_relative "config/deep_ops"
|
|
6
7
|
require_relative "config/store"
|
|
@@ -21,7 +22,6 @@ module Rubik
|
|
|
21
22
|
|
|
22
23
|
DEFAULT_CONFIG = Defaults::DEFAULT_CONFIG
|
|
23
24
|
SENSITIVE_PROJECT_CONFIG_KEYS = DeepOps::SENSITIVE_PROJECT_CONFIG_KEYS
|
|
24
|
-
|
|
25
25
|
attr_reader :data, :warnings, :root_dir, :home_dir,
|
|
26
26
|
:defaults_layer, :global_layer, :project_layer, :env_layer, :session_layer
|
|
27
27
|
attr_accessor :event_bus
|
|
@@ -254,7 +254,7 @@ module Rubik
|
|
|
254
254
|
begin
|
|
255
255
|
entry[:callback].call(key_str, new_val, old_val)
|
|
256
256
|
rescue StandardError => e
|
|
257
|
-
warn "[WARN] Config listener failed for '#{key_str}': #{e.message}"
|
|
257
|
+
Rubik::Log.warn(:config, "[WARN] Config listener failed for '#{key_str}': #{e.message}")
|
|
258
258
|
@event_bus&.emit(:config_listener_error, key: key_str, error: e.message)
|
|
259
259
|
end
|
|
260
260
|
end
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Rubik
|
|
4
|
+
module Context
|
|
5
|
+
# Frozen value object owning the entire "is this path in scope?" dialect
|
|
6
|
+
# of the context index: default ignore globs, the repo's own .gitignore,
|
|
7
|
+
# user excludes/includes, whole-subtree pruning, and the reserved runtime
|
|
8
|
+
# roots. Built once per scan root via .build, it answers three predicates
|
|
9
|
+
# — prune_dir?, ignore_file? / listed_file_ignored?, include_file? — so
|
|
10
|
+
# both listing strategies (Scanner#walk_dir and the git ls-files fast
|
|
11
|
+
# path) stay symmetric by consuming the same rules instead of each
|
|
12
|
+
# re-implementing the filter sequence.
|
|
13
|
+
class IgnoreRules
|
|
14
|
+
DEFAULT_IGNORES = [
|
|
15
|
+
".rubik/**",
|
|
16
|
+
".git/**",
|
|
17
|
+
# GitNexus parse cache: thousands of binary index files; indexing
|
|
18
|
+
# them is pure cost and their non-UTF-8 bytes are a grep hazard.
|
|
19
|
+
".gitnexus/**",
|
|
20
|
+
".ua/**",
|
|
21
|
+
".trash*/**",
|
|
22
|
+
"**/.trash*/**",
|
|
23
|
+
".turbo/**",
|
|
24
|
+
".sst/**",
|
|
25
|
+
".next/**",
|
|
26
|
+
".nuxt/**",
|
|
27
|
+
"node_modules/**",
|
|
28
|
+
"vendor/**",
|
|
29
|
+
"tmp/**",
|
|
30
|
+
"dist/**",
|
|
31
|
+
"build/**",
|
|
32
|
+
".cache/**",
|
|
33
|
+
"coverage/**",
|
|
34
|
+
# Multi-GB local model blobs; never project sources.
|
|
35
|
+
".ollama/**",
|
|
36
|
+
# Agent-harness state: transcripts, sessions, caches.
|
|
37
|
+
".zcode/**"
|
|
38
|
+
].freeze
|
|
39
|
+
|
|
40
|
+
# Subtrees whose ignore pattern is "<path>/**" (optionally with a
|
|
41
|
+
# "**/" prefix) are pruned whole when the stem's components occur
|
|
42
|
+
# contiguously in a directory's path. NOTE: this is intentionally
|
|
43
|
+
# STRONGER than the legacy per-file filter — Ruby's fnmatch treats a
|
|
44
|
+
# trailing `**` as a single segment, so patterns like "node_modules/**"
|
|
45
|
+
# historically rejected only first-level entries while deeper files
|
|
46
|
+
# leaked into the index. The walker applies the pattern's plain meaning
|
|
47
|
+
# (whole subtree ignored), matching real gitignore semantics.
|
|
48
|
+
PRUNABLE_PATTERN = %r{\A(?:\*\*/)?(.+)/\*\*\z}
|
|
49
|
+
# Also hard-rejected inside ignore_file?; pruned before descending.
|
|
50
|
+
# ROOT-anchored only (comps.first) to match the rg-side `!/X/**`
|
|
51
|
+
# globs — a nested `src/AppData` stays indexed.
|
|
52
|
+
HARD_PRUNE_ROOTS = [".git", ".rubik", ".ua", ".turbo", ".sst", ".next", ".nuxt", "AppData"].freeze
|
|
53
|
+
|
|
54
|
+
attr_reader :custom_includes
|
|
55
|
+
|
|
56
|
+
# `dir` is the scan root whose top-level .gitignore contributes
|
|
57
|
+
# patterns; excludes/includes come from the Scanner's accessors.
|
|
58
|
+
def self.build(dir:, custom_excludes: [], custom_includes: [])
|
|
59
|
+
new(DEFAULT_IGNORES + parse_gitignore(dir) + custom_excludes, custom_includes)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Reads one root's .gitignore: comments and blanks dropped, directory
|
|
63
|
+
# entries ("tmp/") widened to whole-subtree globs ("tmp/**").
|
|
64
|
+
def self.parse_gitignore(dir)
|
|
65
|
+
gitignore_path = File.join(dir, ".gitignore")
|
|
66
|
+
return [] unless File.exist?(gitignore_path)
|
|
67
|
+
|
|
68
|
+
patterns = File.readlines(gitignore_path, chomp: true).map(&:strip).reject do |line|
|
|
69
|
+
line.empty? || line.start_with?("#")
|
|
70
|
+
end
|
|
71
|
+
patterns.map do |pattern|
|
|
72
|
+
pattern.end_with?("/") ? "#{pattern}**" : pattern
|
|
73
|
+
end
|
|
74
|
+
rescue Errno::ENOENT, Errno::EACCES
|
|
75
|
+
[]
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# `patterns` is the merged ignore table; `custom_includes` the user's
|
|
79
|
+
# allow-list. Compilation happens eagerly here so the predicates are
|
|
80
|
+
# allocation-free lookups afterwards.
|
|
81
|
+
def initialize(patterns, custom_includes)
|
|
82
|
+
@patterns = patterns.freeze
|
|
83
|
+
@custom_includes = (custom_includes || []).freeze
|
|
84
|
+
# "<dir>/**" patterns pre-split into needle component arrays.
|
|
85
|
+
# Matching a directory then costs plain array compares — no
|
|
86
|
+
# per-ancestor regex evaluation and no re-splitting of the pattern's
|
|
87
|
+
# stem for every file visited.
|
|
88
|
+
@prunable_needles = @patterns.filter_map do |pattern|
|
|
89
|
+
next unless (m = PRUNABLE_PATTERN.match(pattern))
|
|
90
|
+
|
|
91
|
+
m[1].split("/")
|
|
92
|
+
end.freeze
|
|
93
|
+
@file_regexes = compile(@patterns).freeze
|
|
94
|
+
# The git fast path skips prunable subtree patterns with literal
|
|
95
|
+
# stems: its ancestor loop already pruned every directory segment
|
|
96
|
+
# through prune_dir?, so re-testing those globs per file is pure
|
|
97
|
+
# redundancy. Exotic stems (wildcards) stay in the per-file set.
|
|
98
|
+
@listed_file_regexes = compile(listed_file_patterns).freeze
|
|
99
|
+
freeze
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# Should descent into a directory stop? `rel_comps` is the directory's
|
|
103
|
+
# path split on "/". Applies the hard-prune roots (root-anchored) and
|
|
104
|
+
# the whole-subtree globs (contiguous component match). The one
|
|
105
|
+
# predicate behind the walker's early pruning and the fast path's
|
|
106
|
+
# ancestor check.
|
|
107
|
+
def prune_dir?(rel_comps)
|
|
108
|
+
return true if HARD_PRUNE_ROOTS.include?(rel_comps.first)
|
|
109
|
+
|
|
110
|
+
@prunable_needles.any? { |needle| contiguous_components?(rel_comps, needle) }
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# Walker-dialect file filter: reserved roots plus every ignore pattern
|
|
114
|
+
# (prunable ones included, with the documented legacy fnmatch drift).
|
|
115
|
+
def ignore_file?(rel)
|
|
116
|
+
reserved_root?(rel) || @file_regexes.any? { |r| pattern_match?(r, rel) }
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# Fast-path-dialect file filter: same reserved roots, but prunable
|
|
120
|
+
# literal-stem subtree patterns are withheld because prune_dir? already
|
|
121
|
+
# covered their ancestors (see initialize).
|
|
122
|
+
def listed_file_ignored?(rel)
|
|
123
|
+
reserved_root?(rel) || @listed_file_regexes.any? { |r| pattern_match?(r, rel) }
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# Include dialect: no include patterns means "everything is included";
|
|
127
|
+
# otherwise a file must match at least one pattern.
|
|
128
|
+
def include_file?(rel)
|
|
129
|
+
return true if @custom_includes.empty?
|
|
130
|
+
|
|
131
|
+
@custom_includes.any? { |pattern| pattern_match?(pattern, rel) }
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
private
|
|
135
|
+
|
|
136
|
+
def listed_file_patterns
|
|
137
|
+
@patterns.reject do |pat|
|
|
138
|
+
m = PRUNABLE_PATTERN.match(pat)
|
|
139
|
+
m && !m[1].include?("*") && !m[1].include?("?") && !m[1].include?("[")
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def contiguous_components?(haystack, needle)
|
|
144
|
+
return true if haystack == needle
|
|
145
|
+
return false if haystack.size < needle.size
|
|
146
|
+
|
|
147
|
+
(0..(haystack.size - needle.size)).any? do |offset|
|
|
148
|
+
haystack[offset, needle.size] == needle
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
# Runtime-owned roots are never indexed, whatever the ignore tables
|
|
153
|
+
# say — the one predicate behind both listing strategies (the git
|
|
154
|
+
# fast path and the generic walk).
|
|
155
|
+
def reserved_root?(rel)
|
|
156
|
+
rel == ".rubik" || rel.start_with?(".rubik/") || rel == ".git" || rel.start_with?(".git/")
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
# Translates a glob into a Regexp only where the mapping is exact: no
|
|
160
|
+
# character classes, no leading-slash anchoring, and `**` only ever a
|
|
161
|
+
# whole path segment (leading "**/", mid "/**/", trailing "/**").
|
|
162
|
+
# Anything else keeps the pattern string and pattern_match? falls back
|
|
163
|
+
# to File.fnmatch?, whose segment rules the Regexp form cannot express
|
|
164
|
+
# (fnmatch "a**b" never crosses "/" and "**/x" also matches bare "x").
|
|
165
|
+
def compile(ignore_patterns)
|
|
166
|
+
ignore_patterns.map do |pat|
|
|
167
|
+
simple_glob_regex(pat) || pat
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
def simple_glob_regex(pat)
|
|
172
|
+
return nil if pat.empty? || pat.start_with?("/") || pat.include?("[")
|
|
173
|
+
return nil unless pat.split("/").all? { |seg| !seg.include?("*") || seg == "**" || !seg.include?("**") }
|
|
174
|
+
|
|
175
|
+
src = Regexp.escape(pat)
|
|
176
|
+
src = src.sub(%r{\A\\\*\\\*/}, "") # leading "**/": the (?:.*/)? wrapper matches zero dirs too
|
|
177
|
+
src = src.gsub("/\\*\\*/", "/(?:.*/)?") # mid "/**/": zero or more directories
|
|
178
|
+
src = src.gsub("\\*\\*", ".*") # trailing "/**" or lone "**"
|
|
179
|
+
src = src.gsub("\\*", "[^/]*").gsub("\\?", "[^/]")
|
|
180
|
+
Regexp.new("\\A(?:.*/)?#{src}\\z")
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def pattern_match?(pattern_or_regex, path)
|
|
184
|
+
if pattern_or_regex.is_a?(Regexp)
|
|
185
|
+
pattern_or_regex.match?(path)
|
|
186
|
+
else
|
|
187
|
+
File.fnmatch?(pattern_or_regex, path, File::FNM_PATHNAME | File::FNM_DOTMATCH) ||
|
|
188
|
+
File.fnmatch?("**/#{pattern_or_regex}", path, File::FNM_PATHNAME | File::FNM_DOTMATCH)
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
end
|