coridoc 3.0.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 +7 -0
- data/.rspec +3 -0
- data/Rakefile +8 -0
- data/exe/coridoc +24 -0
- data/lib/coridoc/binding_inflater.rb +118 -0
- data/lib/coridoc/cli.rb +311 -0
- data/lib/coridoc/configurable.rb +530 -0
- data/lib/coridoc/core_model/abstract_block.rb +11 -0
- data/lib/coridoc/core_model/annotation_block.rb +57 -0
- data/lib/coridoc/core_model/attribute_reference_resolver.rb +155 -0
- data/lib/coridoc/core_model/base.rb +281 -0
- data/lib/coridoc/core_model/bibliography.rb +41 -0
- data/lib/coridoc/core_model/bibliography_entry.rb +48 -0
- data/lib/coridoc/core_model/block.rb +69 -0
- data/lib/coridoc/core_model/callout.rb +32 -0
- data/lib/coridoc/core_model/callout_text.rb +35 -0
- data/lib/coridoc/core_model/children_content.rb +72 -0
- data/lib/coridoc/core_model/comment_block.rb +16 -0
- data/lib/coridoc/core_model/comment_line.rb +23 -0
- data/lib/coridoc/core_model/definition_item.rb +68 -0
- data/lib/coridoc/core_model/definition_list.rb +28 -0
- data/lib/coridoc/core_model/element_attribute.rb +14 -0
- data/lib/coridoc/core_model/example_block.rb +12 -0
- data/lib/coridoc/core_model/footnote.rb +92 -0
- data/lib/coridoc/core_model/frontmatter/codec.rb +151 -0
- data/lib/coridoc/core_model/frontmatter/field_transform.rb +75 -0
- data/lib/coridoc/core_model/frontmatter/frontmatter_entry.rb +22 -0
- data/lib/coridoc/core_model/frontmatter/frontmatter_value.rb +78 -0
- data/lib/coridoc/core_model/frontmatter/schema_resolver.rb +57 -0
- data/lib/coridoc/core_model/frontmatter/text_splitter.rb +75 -0
- data/lib/coridoc/core_model/frontmatter.rb +72 -0
- data/lib/coridoc/core_model/has_children.rb +23 -0
- data/lib/coridoc/core_model/horizontal_rule_block.rb +16 -0
- data/lib/coridoc/core_model/id_generator.rb +23 -0
- data/lib/coridoc/core_model/image.rb +69 -0
- data/lib/coridoc/core_model/include.rb +43 -0
- data/lib/coridoc/core_model/include_level_offset.rb +71 -0
- data/lib/coridoc/core_model/include_options.rb +101 -0
- data/lib/coridoc/core_model/inline_content.rb +78 -0
- data/lib/coridoc/core_model/inline_element.rb +198 -0
- data/lib/coridoc/core_model/list_block.rb +137 -0
- data/lib/coridoc/core_model/list_item.rb +129 -0
- data/lib/coridoc/core_model/listing_block.rb +19 -0
- data/lib/coridoc/core_model/literal_block.rb +16 -0
- data/lib/coridoc/core_model/metadata.rb +71 -0
- data/lib/coridoc/core_model/open_block.rb +12 -0
- data/lib/coridoc/core_model/output_artifact.rb +48 -0
- data/lib/coridoc/core_model/paragraph_block.rb +16 -0
- data/lib/coridoc/core_model/partintro_block.rb +11 -0
- data/lib/coridoc/core_model/pass_block.rb +16 -0
- data/lib/coridoc/core_model/quote_block.rb +14 -0
- data/lib/coridoc/core_model/raw_inline_element.rb +16 -0
- data/lib/coridoc/core_model/reviewer_block.rb +12 -0
- data/lib/coridoc/core_model/sidebar_block.rb +12 -0
- data/lib/coridoc/core_model/source_block.rb +16 -0
- data/lib/coridoc/core_model/stem_block.rb +25 -0
- data/lib/coridoc/core_model/structural_element.rb +157 -0
- data/lib/coridoc/core_model/table.rb +148 -0
- data/lib/coridoc/core_model/term.rb +53 -0
- data/lib/coridoc/core_model/text_content.rb +26 -0
- data/lib/coridoc/core_model/toc.rb +99 -0
- data/lib/coridoc/core_model/toc_generator.rb +151 -0
- data/lib/coridoc/core_model/verse_block.rb +14 -0
- data/lib/coridoc/core_model.rb +92 -0
- data/lib/coridoc/coridoc.rb +164 -0
- data/lib/coridoc/dispatch.rb +96 -0
- data/lib/coridoc/errors.rb +387 -0
- data/lib/coridoc/format_catalog.rb +102 -0
- data/lib/coridoc/format_module.rb +78 -0
- data/lib/coridoc/hooks.rb +176 -0
- data/lib/coridoc/include_resolver/filesystem.rb +84 -0
- data/lib/coridoc/include_resolver.rb +67 -0
- data/lib/coridoc/include_selectors/indent.rb +54 -0
- data/lib/coridoc/include_selectors/level_offset.rb +84 -0
- data/lib/coridoc/include_selectors/lines.rb +60 -0
- data/lib/coridoc/include_selectors/tags.rb +136 -0
- data/lib/coridoc/include_selectors.rb +26 -0
- data/lib/coridoc/introspection/element_counter.rb +48 -0
- data/lib/coridoc/introspection.rb +72 -0
- data/lib/coridoc/link_rewriter/identity.rb +13 -0
- data/lib/coridoc/link_rewriter/visitor.rb +148 -0
- data/lib/coridoc/link_rewriter.rb +37 -0
- data/lib/coridoc/lint/registry.rb +33 -0
- data/lib/coridoc/lint/rule.rb +41 -0
- data/lib/coridoc/lint/runner.rb +67 -0
- data/lib/coridoc/lint/template.rb +190 -0
- data/lib/coridoc/lint/violation.rb +16 -0
- data/lib/coridoc/lint.rb +44 -0
- data/lib/coridoc/logger.rb +54 -0
- data/lib/coridoc/performance_regression.rb +121 -0
- data/lib/coridoc/pipeline.rb +169 -0
- data/lib/coridoc/query.rb +486 -0
- data/lib/coridoc/reference/address/anchor.rb +48 -0
- data/lib/coridoc/reference/address/doi.rb +40 -0
- data/lib/coridoc/reference/address/isbn.rb +39 -0
- data/lib/coridoc/reference/address/path.rb +66 -0
- data/lib/coridoc/reference/address/scoped_path.rb +47 -0
- data/lib/coridoc/reference/address/url.rb +41 -0
- data/lib/coridoc/reference/address.rb +153 -0
- data/lib/coridoc/reference/catalog/composite.rb +59 -0
- data/lib/coridoc/reference/catalog/local.rb +97 -0
- data/lib/coridoc/reference/catalog/memory_index.rb +59 -0
- data/lib/coridoc/reference/catalog.rb +33 -0
- data/lib/coridoc/reference/edge/citation_options.rb +16 -0
- data/lib/coridoc/reference/edge/footnote_ref_options.rb +13 -0
- data/lib/coridoc/reference/edge/image_ref_options.rb +15 -0
- data/lib/coridoc/reference/edge/include_options.rb +15 -0
- data/lib/coridoc/reference/edge/kind.rb +72 -0
- data/lib/coridoc/reference/edge/link_options.rb +12 -0
- data/lib/coridoc/reference/edge/navigation_options.rb +12 -0
- data/lib/coridoc/reference/edge/options.rb +13 -0
- data/lib/coridoc/reference/edge.rb +80 -0
- data/lib/coridoc/reference/edge_search.rb +128 -0
- data/lib/coridoc/reference/materializer/base.rb +44 -0
- data/lib/coridoc/reference/materializer/passthrough.rb +31 -0
- data/lib/coridoc/reference/materializer/registry.rb +116 -0
- data/lib/coridoc/reference/materializer.rb +14 -0
- data/lib/coridoc/reference/presentation/base.rb +47 -0
- data/lib/coridoc/reference/presentation/custom_hierarchy.rb +104 -0
- data/lib/coridoc/reference/presentation/page.rb +20 -0
- data/lib/coridoc/reference/presentation/single_document.rb +35 -0
- data/lib/coridoc/reference/presentation/split_pages.rb +118 -0
- data/lib/coridoc/reference/presentation.rb +16 -0
- data/lib/coridoc/reference/resolution.rb +184 -0
- data/lib/coridoc/reference/resolver/base.rb +15 -0
- data/lib/coridoc/reference/resolver/caching.rb +37 -0
- data/lib/coridoc/reference/resolver/catalog.rb +69 -0
- data/lib/coridoc/reference/resolver/chain.rb +33 -0
- data/lib/coridoc/reference/resolver.rb +20 -0
- data/lib/coridoc/reference/result/ambiguous.rb +23 -0
- data/lib/coridoc/reference/result/base.rb +46 -0
- data/lib/coridoc/reference/result/missing.rb +14 -0
- data/lib/coridoc/reference/result/resolved.rb +22 -0
- data/lib/coridoc/reference/result.rb +20 -0
- data/lib/coridoc/reference.rb +65 -0
- data/lib/coridoc/registry.rb +156 -0
- data/lib/coridoc/relative_path.rb +32 -0
- data/lib/coridoc/resolve_includes.rb +202 -0
- data/lib/coridoc/source_graph/file_node.rb +147 -0
- data/lib/coridoc/source_graph/graph.rb +165 -0
- data/lib/coridoc/source_graph/include_edges.rb +33 -0
- data/lib/coridoc/source_graph/sidecar.rb +97 -0
- data/lib/coridoc/source_graph.rb +36 -0
- data/lib/coridoc/validation.rb +686 -0
- data/lib/coridoc/version.rb +5 -0
- data/lib/coridoc/visitor.rb +283 -0
- data/lib/coridoc.rb +41 -0
- metadata +221 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Coridoc
|
|
4
|
+
module SourceGraph
|
|
5
|
+
# Extracts include edges from a materialized CoreModel: every
|
|
6
|
+
# {CoreModel::Include} link node contributes one edge. Targets
|
|
7
|
+
# resolve relative to the including file's directory, matching
|
|
8
|
+
# ResolveIncludes semantics (SPEC 7.2).
|
|
9
|
+
module IncludeEdges
|
|
10
|
+
module_function
|
|
11
|
+
|
|
12
|
+
# @param core [CoreModel::Base] materialized CoreModel of the
|
|
13
|
+
# including document
|
|
14
|
+
# @param base_dir [String] directory of the including file
|
|
15
|
+
# @return [Array<String>] absolute, expanded target paths
|
|
16
|
+
def targets(core, base_dir:)
|
|
17
|
+
collect([core], []).map { |target| File.expand_path(target, base_dir) }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def collect(nodes, acc)
|
|
21
|
+
Array(nodes).flatten.each do |node|
|
|
22
|
+
case node
|
|
23
|
+
when CoreModel::Include
|
|
24
|
+
acc << node.target if node.target
|
|
25
|
+
when CoreModel::Base
|
|
26
|
+
collect(node.children, acc) if node.is_a?(CoreModel::HasChildren)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
acc
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'json'
|
|
4
|
+
require 'fileutils'
|
|
5
|
+
|
|
6
|
+
module Coridoc
|
|
7
|
+
module SourceGraph
|
|
8
|
+
# Persistence for the twin in the XDG cache dir. A single JSON
|
|
9
|
+
# map: realpath → { id, digest, edges }. Node ids are minted
|
|
10
|
+
# lazily and live ONLY here — never inside source files. The
|
|
11
|
+
# store is a cache in the strict sense: regenerable, LRU-capped,
|
|
12
|
+
# and safe to delete at any time.
|
|
13
|
+
#
|
|
14
|
+
# Location precedence:
|
|
15
|
+
# CORIDOC_CACHE_DIR explicit override (CI, containers)
|
|
16
|
+
# XDG_CACHE_HOME XDG base directory
|
|
17
|
+
# ~/.cache default
|
|
18
|
+
class Sidecar
|
|
19
|
+
MAX_ENTRIES = 4096
|
|
20
|
+
FILENAME = 'source_graph.json'
|
|
21
|
+
|
|
22
|
+
attr_reader :dir
|
|
23
|
+
|
|
24
|
+
def self.default
|
|
25
|
+
new(default_dir)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def self.default_dir
|
|
29
|
+
ENV['CORIDOC_CACHE_DIR'] ||
|
|
30
|
+
File.join(ENV['XDG_CACHE_HOME'] || File.join(Dir.home, '.cache'),
|
|
31
|
+
'coridoc')
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def initialize(dir)
|
|
35
|
+
@dir = File.expand_path(dir)
|
|
36
|
+
@entries = nil
|
|
37
|
+
@next_id = nil
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def path
|
|
41
|
+
File.join(@dir, FILENAME)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# All persisted records: path => { id:, digest:, edges: }.
|
|
45
|
+
def entries
|
|
46
|
+
@entries ||= read_entries
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def record_for(path)
|
|
50
|
+
entries[File.expand_path(path)]
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Persist +records+ (hashes with path/digest/edges). Mints ids
|
|
54
|
+
# for records that lack one, keeps the most recently written
|
|
55
|
+
# MAX_ENTRIES records. Returns the records with ids assigned.
|
|
56
|
+
def write(records)
|
|
57
|
+
records = records.map(&:dup)
|
|
58
|
+
records.each { |rec| rec[:id] ||= mint_id }
|
|
59
|
+
merged = entries.merge(build_records(records))
|
|
60
|
+
@entries = evict(merged)
|
|
61
|
+
@next_id = nil
|
|
62
|
+
FileUtils.mkdir_p(@dir)
|
|
63
|
+
File.write(path, JSON.pretty_generate(@entries))
|
|
64
|
+
records
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
private
|
|
68
|
+
|
|
69
|
+
def read_entries
|
|
70
|
+
return {} unless File.exist?(path)
|
|
71
|
+
|
|
72
|
+
JSON.parse(File.read(path))
|
|
73
|
+
rescue JSON::ParserError, Errno::ENOENT
|
|
74
|
+
{}
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def build_records(records)
|
|
78
|
+
records.each_with_object({}) do |rec, out|
|
|
79
|
+
out[rec[:path]] = { 'id' => rec[:id] || mint_id,
|
|
80
|
+
'digest' => rec[:digest],
|
|
81
|
+
'edges' => rec[:edges] }
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# Insertion order is recency: dropping the oldest MAX_ENTRIES
|
|
86
|
+
# records is an LRU approximation for a JSON map.
|
|
87
|
+
def evict(merged)
|
|
88
|
+
merged.to_a.last(MAX_ENTRIES).to_h
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def mint_id
|
|
92
|
+
@next_id = ((@next_id || entries.values.map { |r| r['id'].to_i }.max || 0) + 1)
|
|
93
|
+
format('n%08d', @next_id)
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Coridoc
|
|
4
|
+
# Digital twin of a corpus of source files (#137).
|
|
5
|
+
#
|
|
6
|
+
# A graph of FileNodes mirroring files on disk. Each node materializes
|
|
7
|
+
# lazily in levels — stat (Level 0), digest (Level 1), parsed format
|
|
8
|
+
# tree (Level 2) — and demotes automatically when a lower level goes
|
|
9
|
+
# stale. Staleness is two-part: a node is fresh only if BOTH its
|
|
10
|
+
# content digest AND its include-graph digest (the shape of the files
|
|
11
|
+
# it pulls in) are unchanged. A changed file invalidates its own
|
|
12
|
+
# parsed level and propagates up the include edges to every includer,
|
|
13
|
+
# cycle-safe.
|
|
14
|
+
#
|
|
15
|
+
# The files always win: the twin is read-only derived state, and
|
|
16
|
+
# consumers can never pin a stale level.
|
|
17
|
+
#
|
|
18
|
+
# graph = Coridoc::SourceGraph.build("doc.adoc")
|
|
19
|
+
# node = graph.node("doc.adoc")
|
|
20
|
+
# node.parsed # => format tree (parsed on first call)
|
|
21
|
+
# node.core # => CoreModel (cached)
|
|
22
|
+
# graph.stale_nodes # => nodes whose disk state drifted
|
|
23
|
+
# graph.persist # => sidecar for O(changed) warm rebuilds
|
|
24
|
+
module SourceGraph
|
|
25
|
+
autoload :FileNode, "#{__dir__}/source_graph/file_node"
|
|
26
|
+
autoload :Graph, "#{__dir__}/source_graph/graph"
|
|
27
|
+
autoload :Sidecar, "#{__dir__}/source_graph/sidecar"
|
|
28
|
+
autoload :IncludeEdges, "#{__dir__}/source_graph/include_edges"
|
|
29
|
+
|
|
30
|
+
class << self
|
|
31
|
+
def build(paths, sidecar: Sidecar.default)
|
|
32
|
+
Graph.build(paths, sidecar: sidecar)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|