textus 0.50.0 → 0.51.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/CHANGELOG.md +26 -0
- data/README.md +41 -43
- data/SPEC.md +174 -176
- data/docs/architecture/README.md +46 -42
- data/docs/reference/conventions.md +31 -26
- data/lib/textus/boot.rb +13 -17
- data/lib/textus/call.rb +1 -1
- data/lib/textus/cli/runner.rb +15 -10
- data/lib/textus/cli/verb/get.rb +1 -3
- data/lib/textus/cli/verb/hook_run.rb +1 -1
- data/lib/textus/cli/verb/put.rb +4 -20
- data/lib/textus/cli.rb +1 -3
- data/lib/textus/dispatcher.rb +1 -3
- data/lib/textus/doctor/check/generator_drift.rb +4 -3
- data/lib/textus/doctor/check/handler_allowlist.rb +1 -1
- data/lib/textus/doctor/check/intake_registration.rb +5 -5
- data/lib/textus/doctor/check/rule_ambiguity.rb +3 -3
- data/lib/textus/doctor/check/sentinels.rb +2 -2
- data/lib/textus/doctor/check/templates.rb +13 -11
- data/lib/textus/doctor.rb +0 -2
- data/lib/textus/domain/freshness/evaluator.rb +150 -14
- data/lib/textus/domain/freshness/verdict.rb +28 -6
- data/lib/textus/domain/freshness.rb +4 -33
- data/lib/textus/domain/policy/base_guards.rb +1 -1
- data/lib/textus/domain/policy/predicates/fresh_within.rb +1 -1
- data/lib/textus/domain/policy/publish_target.rb +34 -0
- data/lib/textus/domain/policy/retention.rb +29 -0
- data/lib/textus/domain/policy/source.rb +79 -0
- data/lib/textus/domain/retention/sweep.rb +57 -0
- data/lib/textus/domain/retention.rb +11 -0
- data/lib/textus/errors.rb +4 -4
- data/lib/textus/hooks/builtin.rb +5 -5
- data/lib/textus/hooks/catalog.rb +8 -7
- data/lib/textus/hooks/context.rb +5 -10
- data/lib/textus/init/templates/machine_intake.rb +4 -4
- data/lib/textus/init.rb +47 -47
- data/lib/textus/key/matching.rb +24 -0
- data/lib/textus/maintenance/reconcile.rb +160 -0
- data/lib/textus/manifest/capabilities.rb +1 -1
- data/lib/textus/manifest/data.rb +2 -2
- data/lib/textus/manifest/entry/base.rb +28 -9
- data/lib/textus/manifest/entry/nested.rb +3 -4
- data/lib/textus/manifest/entry/parser.rb +25 -21
- data/lib/textus/manifest/entry/produced.rb +56 -0
- data/lib/textus/manifest/entry/publish/subtree_mirror.rb +7 -6
- data/lib/textus/manifest/entry/publish/to_paths.rb +62 -11
- data/lib/textus/manifest/entry/validators/format_matrix.rb +3 -11
- data/lib/textus/manifest/entry/validators/publish.rb +3 -1
- data/lib/textus/manifest/entry/validators.rb +0 -1
- data/lib/textus/manifest/policy.rb +16 -4
- data/lib/textus/manifest/resolver.rb +10 -4
- data/lib/textus/manifest/rules.rb +37 -36
- data/lib/textus/manifest/schema/keys.rb +98 -0
- data/lib/textus/manifest/schema/validator.rb +324 -0
- data/lib/textus/manifest/schema/vocabulary.rb +24 -0
- data/lib/textus/manifest/schema.rb +27 -247
- data/lib/textus/manifest.rb +5 -3
- data/lib/textus/mcp/server.rb +1 -1
- data/lib/textus/ports/audit_log.rb +6 -0
- data/lib/textus/ports/build_lock.rb +6 -0
- data/lib/textus/ports/clock.rb +4 -3
- data/lib/textus/ports/produce_on_write_subscriber.rb +69 -0
- data/lib/textus/ports/publisher.rb +11 -7
- data/lib/textus/produce/acquire/handler.rb +29 -0
- data/lib/textus/produce/acquire/intake.rb +130 -0
- data/lib/textus/produce/acquire/projection.rb +127 -0
- data/lib/textus/produce/acquire/serializer/json.rb +31 -0
- data/lib/textus/produce/acquire/serializer/text.rb +16 -0
- data/lib/textus/produce/acquire/serializer/yaml.rb +31 -0
- data/lib/textus/produce/acquire/serializer.rb +17 -0
- data/lib/textus/produce/engine.rb +143 -0
- data/lib/textus/produce/events.rb +36 -0
- data/lib/textus/produce/render.rb +23 -0
- data/lib/textus/projection.rb +17 -6
- data/lib/textus/read/deps.rb +3 -3
- data/lib/textus/read/freshness.rb +61 -31
- data/lib/textus/read/get.rb +20 -102
- data/lib/textus/read/rdeps.rb +3 -3
- data/lib/textus/read/rule_explain.rb +41 -23
- data/lib/textus/read/rule_list.rb +25 -8
- data/lib/textus/read/validate_all.rb +14 -0
- data/lib/textus/role.rb +2 -1
- data/lib/textus/schemas.rb +8 -0
- data/lib/textus/store.rb +1 -0
- data/lib/textus/version.rb +1 -1
- data/lib/textus/write/put.rb +1 -1
- metadata +23 -30
- data/lib/textus/builder/pipeline.rb +0 -88
- data/lib/textus/builder/renderer/json.rb +0 -45
- data/lib/textus/builder/renderer/markdown.rb +0 -24
- data/lib/textus/builder/renderer/text.rb +0 -14
- data/lib/textus/builder/renderer/yaml.rb +0 -45
- data/lib/textus/builder/renderer.rb +0 -17
- data/lib/textus/cli/verb/boot.rb +0 -14
- data/lib/textus/cli/verb/build.rb +0 -15
- data/lib/textus/doctor/check/fetch_locks.rb +0 -49
- data/lib/textus/doctor/check/lifecycle_action_invalid.rb +0 -39
- data/lib/textus/domain/freshness/policy.rb +0 -18
- data/lib/textus/domain/lifecycle.rb +0 -83
- data/lib/textus/domain/outcome.rb +0 -10
- data/lib/textus/domain/policy/lifecycle.rb +0 -35
- data/lib/textus/domain/staleness/generator_check.rb +0 -109
- data/lib/textus/domain/staleness.rb +0 -29
- data/lib/textus/maintenance/tend.rb +0 -110
- data/lib/textus/manifest/entry/derived.rb +0 -67
- data/lib/textus/manifest/entry/intake.rb +0 -31
- data/lib/textus/manifest/entry/validators/inject_boot.rb +0 -21
- data/lib/textus/mcp/tools.rb +0 -14
- data/lib/textus/ports/fetch/detached.rb +0 -52
- data/lib/textus/ports/fetch/lock.rb +0 -44
- data/lib/textus/write/build.rb +0 -90
- data/lib/textus/write/fetch_events.rb +0 -42
- data/lib/textus/write/fetch_orchestrator.rb +0 -101
- data/lib/textus/write/fetch_worker.rb +0 -127
- data/lib/textus/write/intake_fetch.rb +0 -25
- data/lib/textus/write/materializer.rb +0 -51
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
module Textus
|
|
2
|
+
class Manifest
|
|
3
|
+
module Schema
|
|
4
|
+
# The manifest validation walk. Extracted from Schema (ADR 0107); the
|
|
5
|
+
# schema data now lives in Schema::Vocabulary (coordination vocabulary,
|
|
6
|
+
# LANES + derived) and Schema::Keys (key whitelists / FIELD_REGISTRY),
|
|
7
|
+
# re-exported on Schema — while the validation *logic* lives here.
|
|
8
|
+
# Lexically nested under Schema, so bare constant references
|
|
9
|
+
# (ROOT_KEYS, LANES, FIELD_REGISTRY, …) resolve to Schema's constants.
|
|
10
|
+
module Validator
|
|
11
|
+
module_function
|
|
12
|
+
|
|
13
|
+
def validate!(raw)
|
|
14
|
+
raise BadManifest.new("manifest must be a hash") unless raw.is_a?(Hash)
|
|
15
|
+
|
|
16
|
+
walk(raw, ROOT_KEYS, "$")
|
|
17
|
+
validate_roles!(raw["roles"])
|
|
18
|
+
validate_zones!(raw["zones"])
|
|
19
|
+
validate_entries!(raw["entries"])
|
|
20
|
+
validate_owners!(raw["zones"], raw["entries"])
|
|
21
|
+
validate_rules!(raw["rules"])
|
|
22
|
+
walk(raw["audit"], AUDIT_KEYS, "$.audit") if raw["audit"].is_a?(Hash)
|
|
23
|
+
validate_single_queue!(raw)
|
|
24
|
+
validate_single_machine!(raw)
|
|
25
|
+
validate_zone_kind_consistency!(raw)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def validate_zones!(zones)
|
|
29
|
+
Array(zones).each_with_index do |z, i|
|
|
30
|
+
walk(z, ZONE_KEYS, "$.zones[#{i}]")
|
|
31
|
+
if z["kind"].nil?
|
|
32
|
+
raise BadManifest.new("zone '#{z["name"]}' at '$.zones[#{i}]' must declare a kind (one of: #{ZONE_KINDS.join(", ")})")
|
|
33
|
+
end
|
|
34
|
+
next if ZONE_KINDS.include?(z["kind"])
|
|
35
|
+
|
|
36
|
+
if %w[quarantine derived].include?(z["kind"])
|
|
37
|
+
raise BadManifest.new(
|
|
38
|
+
"zone kind '#{z["kind"]}' at '$.zones[#{i}]' was folded into 'machine' (ADR 0091) — " \
|
|
39
|
+
"use `kind: machine`",
|
|
40
|
+
)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
raise BadManifest.new(
|
|
44
|
+
"unknown zone kind '#{z["kind"]}' at '$.zones[#{i}]' (known: #{ZONE_KINDS.join(", ")})",
|
|
45
|
+
)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def validate_entries!(entries)
|
|
50
|
+
Array(entries).each_with_index do |e, i|
|
|
51
|
+
path = "$.entries[#{i}]"
|
|
52
|
+
reject_retired_publish_keys!(e, path)
|
|
53
|
+
reject_retired_render_keys!(e, path)
|
|
54
|
+
walk(e, ENTRY_KEYS, path)
|
|
55
|
+
validate_publish_block!(e, path)
|
|
56
|
+
walk(e["source"], SOURCE_KEYS, "#{path}.source") if e["source"]
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Retired keys are no longer allowed, so `walk` would reject them as merely
|
|
61
|
+
# "unknown"; intercept first with the migration path so a pre-0.43 manifest
|
|
62
|
+
# gets a useful error. `publish_each` was removed (ADR 0051); `publish_to`/
|
|
63
|
+
# `publish_tree` were folded into the `publish:` block (ADR 0052);
|
|
64
|
+
# `index_filename` was removed (ADR 0053).
|
|
65
|
+
def reject_retired_publish_keys!(entry, path)
|
|
66
|
+
return unless entry.is_a?(Hash)
|
|
67
|
+
|
|
68
|
+
if entry.key?("publish_each")
|
|
69
|
+
raise BadManifest.new(
|
|
70
|
+
"publish_each was removed in 0.42.0 (ADR 0051) at '#{path}' — " \
|
|
71
|
+
"mirror the subtree with `publish: { tree: \"...\" }`.",
|
|
72
|
+
)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
if entry.key?("publish_to")
|
|
76
|
+
raise BadManifest.new(
|
|
77
|
+
"publish_to was replaced by the publish: block in 0.43.0 (ADR 0052) at '#{path}' — " \
|
|
78
|
+
"use `publish: { to: [...] }`.",
|
|
79
|
+
)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
if entry.key?("publish_tree")
|
|
83
|
+
raise BadManifest.new(
|
|
84
|
+
"publish_tree was replaced by the publish: block in 0.43.0 (ADR 0052) at '#{path}' — " \
|
|
85
|
+
"use `publish: { tree: \"...\" }`.",
|
|
86
|
+
)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
return unless entry.key?("index_filename")
|
|
90
|
+
|
|
91
|
+
raise BadManifest.new(
|
|
92
|
+
"index_filename was removed in 0.43.0 (ADR 0053) at '#{path}' — a nested entry now enumerates " \
|
|
93
|
+
"each file as a key; to mirror a directory of files to a consumer path use `publish: { tree: \"...\" }`.",
|
|
94
|
+
)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# ADR 0094: rendering is a publish concern. An entry no longer
|
|
98
|
+
# declares a build-time template or render flags — they move onto publish
|
|
99
|
+
# targets. Provenance lives in the data's `_meta`, not a flag.
|
|
100
|
+
def reject_retired_render_keys!(entry, path)
|
|
101
|
+
return unless entry.is_a?(Hash)
|
|
102
|
+
|
|
103
|
+
if entry.key?("template")
|
|
104
|
+
raise BadManifest.new(
|
|
105
|
+
"entry-level `template:` was removed at '#{path}' (ADR 0094): rendering is a " \
|
|
106
|
+
"publish concern — `publish: [{ to:, template: }]`.",
|
|
107
|
+
)
|
|
108
|
+
end
|
|
109
|
+
if entry.key?("inject_boot")
|
|
110
|
+
raise BadManifest.new(
|
|
111
|
+
"entry-level `inject_boot:` was removed at '#{path}' (ADR 0094): it is a render " \
|
|
112
|
+
"flag — `publish: [{ to:, inject_boot: }]`.",
|
|
113
|
+
)
|
|
114
|
+
end
|
|
115
|
+
return unless entry.key?("provenance")
|
|
116
|
+
|
|
117
|
+
raise BadManifest.new("entry-level `provenance:` was removed at '#{path}' (ADR 0094): provenance lives in the data's `_meta`.")
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
# ADR 0094: publish is a LIST of target objects. The old
|
|
121
|
+
# `{ to: [...] }` / `{ tree: … }` map forms are retired (fold hint).
|
|
122
|
+
def validate_publish_block!(entry, path)
|
|
123
|
+
return unless entry.is_a?(Hash) && entry.key?("publish")
|
|
124
|
+
|
|
125
|
+
block = entry["publish"]
|
|
126
|
+
if block.is_a?(Hash)
|
|
127
|
+
raise BadManifest.new(
|
|
128
|
+
"publish: at '#{path}.publish' must be a list of targets " \
|
|
129
|
+
"[{ to:, template:? } | { tree: }] (ADR 0094); the map form was retired.",
|
|
130
|
+
)
|
|
131
|
+
end
|
|
132
|
+
raise BadManifest.new("publish: must be a list of targets at '#{path}.publish'") unless block.is_a?(Array)
|
|
133
|
+
|
|
134
|
+
block.each_with_index do |t, i|
|
|
135
|
+
raise BadManifest.new("publish target ##{i} must be a mapping at '#{path}.publish'") unless t.is_a?(Hash)
|
|
136
|
+
|
|
137
|
+
walk(t, %w[to tree template inject_boot], "#{path}.publish[#{i}]")
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def validate_rules!(rules)
|
|
142
|
+
Array(rules).each_with_index do |r, i|
|
|
143
|
+
path = "$.rules[#{i}]"
|
|
144
|
+
reject_retired_rule_keys!(r, path)
|
|
145
|
+
if r.is_a?(Hash) && r.key?("upkeep")
|
|
146
|
+
raise BadManifest.new(
|
|
147
|
+
"rule key `upkeep:` was removed (ADR 0093): move age-GC to `retention:` " \
|
|
148
|
+
"and production (handler/template) to the entry's `source:`",
|
|
149
|
+
)
|
|
150
|
+
end
|
|
151
|
+
walk(r, RULE_KEYS, path)
|
|
152
|
+
FIELD_REGISTRY.each_value do |meta|
|
|
153
|
+
next unless meta[:sub_keys]
|
|
154
|
+
|
|
155
|
+
value = r[meta[:yaml_key]]
|
|
156
|
+
walk(value, meta[:sub_keys], "#{path}.#{meta[:yaml_key]}") if value.is_a?(Hash)
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
# ADR 0093 split production from age-GC: age-GC moved to the `retention:`
|
|
162
|
+
# rule; intake cadence + production (handler/template) moved to the
|
|
163
|
+
# entry's `source:` block. Legacy `lifecycle:`/`materialize:` rule keys
|
|
164
|
+
# are rejected with a migration hint toward the new shape.
|
|
165
|
+
def reject_retired_rule_keys!(rule, path)
|
|
166
|
+
return unless rule.is_a?(Hash)
|
|
167
|
+
|
|
168
|
+
hints = {
|
|
169
|
+
"lifecycle" => "age GC moved to the `retention:` rule ({ ttl, action: drop|archive }); " \
|
|
170
|
+
"intake cadence to the entry's `source: { ttl }`",
|
|
171
|
+
"materialize" => "moved to the entry's `source: { on_write: sync|async }`",
|
|
172
|
+
}
|
|
173
|
+
hints.each do |old, hint|
|
|
174
|
+
next unless rule.key?(old)
|
|
175
|
+
|
|
176
|
+
raise BadManifest.new("`#{old}:` was removed at '#{path}' (ADR 0093) — #{hint}.")
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
def validate_roles!(roles)
|
|
181
|
+
return if roles.nil?
|
|
182
|
+
raise BadManifest.new("roles: must be a list") unless roles.is_a?(Array)
|
|
183
|
+
|
|
184
|
+
roles.each_with_index do |r, i|
|
|
185
|
+
path = "$.roles[#{i}]"
|
|
186
|
+
walk(r, ROLE_KEYS, path)
|
|
187
|
+
name = r["name"] or raise BadManifest.new("role at '#{path}' missing name")
|
|
188
|
+
unless Textus::Role::NAMES.include?(name)
|
|
189
|
+
raise BadManifest.new(
|
|
190
|
+
"unknown role name '#{name}' at '#{path}' " \
|
|
191
|
+
"(allowed: #{Textus::Role::NAMES.join(", ")})",
|
|
192
|
+
)
|
|
193
|
+
end
|
|
194
|
+
Array(r["can"]).each do |verb|
|
|
195
|
+
next if CAPABILITIES.include?(verb)
|
|
196
|
+
|
|
197
|
+
# The quarantine capability folded into reconcile (ADR 0090); a
|
|
198
|
+
# manifest still naming the old quarantine capability (`ingest`, or
|
|
199
|
+
# legacy `fetch`) gets a pointed hint rather than a bare error.
|
|
200
|
+
hint = %w[ingest fetch].include?(verb) ? " — the quarantine capability folded into 'reconcile' (ADR 0090)" : ""
|
|
201
|
+
raise BadManifest.new(
|
|
202
|
+
"unknown capability '#{verb}' for role '#{name}' at '#{path}' " \
|
|
203
|
+
"(known: #{CAPABILITIES.join(", ")})#{hint}",
|
|
204
|
+
)
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
author_holders = roles.count { |r| Array(r["can"]).include?("author") }
|
|
209
|
+
return if author_holders <= 1
|
|
210
|
+
|
|
211
|
+
raise BadManifest.new(
|
|
212
|
+
"manifest declares #{author_holders} roles with the author capability; at most one is allowed",
|
|
213
|
+
)
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
# Owners are validated against the SAME closed archetype set as role names
|
|
217
|
+
# (ADR 0045 D1) so attribution can't bypass the closed-name guarantee.
|
|
218
|
+
# Applies to both zone owners and entry owners; owner is optional, so a
|
|
219
|
+
# nil owner is not an error.
|
|
220
|
+
def validate_owners!(zones, entries)
|
|
221
|
+
Array(zones).each_with_index do |z, i|
|
|
222
|
+
check_owner!(z["owner"], "$.zones[#{i}]")
|
|
223
|
+
end
|
|
224
|
+
Array(entries).each_with_index do |e, i|
|
|
225
|
+
check_owner!(e["owner"], "$.entries[#{i}]")
|
|
226
|
+
end
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
def check_owner!(owner, path)
|
|
230
|
+
return if owner.nil?
|
|
231
|
+
return if valid_owner?(owner)
|
|
232
|
+
|
|
233
|
+
raise BadManifest.new(
|
|
234
|
+
"invalid owner '#{owner}' at '#{path}' " \
|
|
235
|
+
"(expected <archetype> or <archetype>:<subject>, " \
|
|
236
|
+
"archetype one of: #{Textus::Role::NAMES.join(", ")})",
|
|
237
|
+
)
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
# The owner-validation rule: an `owner:` token is either a bare archetype
|
|
241
|
+
# (`agent`) or `<archetype>:<subject>` (`human:patrick`). The archetype is
|
|
242
|
+
# gated against the closed Role::NAMES set (so attribution can't smuggle in
|
|
243
|
+
# a name the role side rejects, ADR 0045 D1); the subject is the free-form
|
|
244
|
+
# principal, validated by OWNER_SUBJECT_PATTERN. Split on the FIRST ':'
|
|
245
|
+
# only — a subject may not itself contain ':' (the pattern excludes it), so
|
|
246
|
+
# `human:a:b` is rejected.
|
|
247
|
+
def valid_owner?(token)
|
|
248
|
+
return false unless token.is_a?(String) && !token.empty?
|
|
249
|
+
|
|
250
|
+
archetype, subject = token.split(":", 2)
|
|
251
|
+
return false unless Textus::Role::NAMES.include?(archetype)
|
|
252
|
+
return true if subject.nil?
|
|
253
|
+
|
|
254
|
+
OWNER_SUBJECT_PATTERN.match?(subject)
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
def walk(hash, allowed, path)
|
|
258
|
+
return unless hash.is_a?(Hash)
|
|
259
|
+
|
|
260
|
+
hash.each_key do |k|
|
|
261
|
+
next if allowed.include?(k)
|
|
262
|
+
|
|
263
|
+
raise BadManifest.new("unknown key '#{k}' at '#{path}'")
|
|
264
|
+
end
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
def validate_single_queue!(raw)
|
|
268
|
+
queues = Array(raw["zones"]).select { |z| z["kind"] == "queue" }.map { |z| z["name"] }
|
|
269
|
+
return if queues.size <= 1
|
|
270
|
+
|
|
271
|
+
raise BadManifest.new(
|
|
272
|
+
"at most one zone may declare kind: queue (found: #{queues.join(", ")})",
|
|
273
|
+
)
|
|
274
|
+
end
|
|
275
|
+
|
|
276
|
+
def validate_single_machine!(raw)
|
|
277
|
+
machines = Array(raw["zones"]).select { |z| z["kind"] == "machine" }.map { |z| z["name"] }
|
|
278
|
+
return if machines.size <= 1
|
|
279
|
+
|
|
280
|
+
raise BadManifest.new(
|
|
281
|
+
"at most one zone may declare kind: machine (found: #{machines.join(", ")})",
|
|
282
|
+
)
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
# ADR 0093: retention (drop/archive) is age-based GC; it is invalid on a
|
|
286
|
+
# derived entry (a derived entry regenerates from its source, it isn't aged
|
|
287
|
+
# out). Per ADR 0095 the produce-method is read from source.from on the one
|
|
288
|
+
# Produced kind, so there is no longer a kind to agree against the source.
|
|
289
|
+
# (Replaces validate_upkeep_kinds!.)
|
|
290
|
+
def validate_source_and_retention!(manifest)
|
|
291
|
+
manifest.data.entries.each do |entry|
|
|
292
|
+
retention = manifest.rules.for(entry.key).retention
|
|
293
|
+
next if retention.nil?
|
|
294
|
+
next unless entry.derived?
|
|
295
|
+
|
|
296
|
+
raise BadManifest.new(
|
|
297
|
+
"entry '#{entry.key}': a derived entry regenerates from its source; " \
|
|
298
|
+
"retention (drop/archive) is invalid",
|
|
299
|
+
)
|
|
300
|
+
end
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
# Write authority is derived from capabilities (ADR 0030): a zone of a
|
|
304
|
+
# given kind can only be written by a role that holds the kind's required
|
|
305
|
+
# verb. Reject a manifest declaring a zone whose required verb is held by
|
|
306
|
+
# no role. Capabilities.resolve returns the defaults when `roles:` is nil,
|
|
307
|
+
# so the capability union is all four verbs and every kind is satisfied.
|
|
308
|
+
def validate_zone_kind_consistency!(raw)
|
|
309
|
+
held = Capabilities.resolve(raw["roles"]).values.flatten.uniq
|
|
310
|
+
|
|
311
|
+
Array(raw["zones"]).each_with_index do |z, i|
|
|
312
|
+
verb = KIND_REQUIRES_VERB[z["kind"]]
|
|
313
|
+
next if verb.nil? || held.include?(verb)
|
|
314
|
+
|
|
315
|
+
raise BadManifest.new(
|
|
316
|
+
"zone '#{z["name"]}' (#{z["kind"]}) at '$.zones[#{i}]' " \
|
|
317
|
+
"needs a role with capability '#{verb}'; none declared",
|
|
318
|
+
)
|
|
319
|
+
end
|
|
320
|
+
end
|
|
321
|
+
end
|
|
322
|
+
end
|
|
323
|
+
end
|
|
324
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module Textus
|
|
2
|
+
class Manifest
|
|
3
|
+
module Schema
|
|
4
|
+
# The closed coordination vocabulary (ADR 0028; five in 0033; unified in
|
|
5
|
+
# 0034; the quarantine + derived ZONE-KINDS folded into one `machine` kind
|
|
6
|
+
# in ADR 0091). Each kind pairs with the capability that authorizes
|
|
7
|
+
# originating bytes in it. ONE source of truth; the derived constants below
|
|
8
|
+
# cannot drift. A BIJECTION again (0090 had two kinds → reconcile; 0091
|
|
9
|
+
# collapses them, so kind ↔ capability is 1:1).
|
|
10
|
+
module Vocabulary
|
|
11
|
+
LANES = {
|
|
12
|
+
"canon" => "author",
|
|
13
|
+
"workspace" => "keep",
|
|
14
|
+
"machine" => "reconcile",
|
|
15
|
+
"queue" => "propose",
|
|
16
|
+
}.freeze
|
|
17
|
+
|
|
18
|
+
ZONE_KINDS = LANES.keys.freeze
|
|
19
|
+
CAPABILITIES = LANES.values.uniq.freeze
|
|
20
|
+
KIND_REQUIRES_VERB = LANES
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -1,253 +1,33 @@
|
|
|
1
1
|
module Textus
|
|
2
2
|
class Manifest
|
|
3
|
+
# The manifest schema. Its data is split across Schema::Vocabulary (the
|
|
4
|
+
# coordination vocabulary) and Schema::Keys (key whitelists + FIELD_REGISTRY)
|
|
5
|
+
# as of ADR 0109; the validation walk lives in Schema::Validator (ADR 0107).
|
|
6
|
+
# The constants are re-exported here so callers keep saying `Schema::LANES`.
|
|
3
7
|
module Schema
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
#
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
compute template publish
|
|
28
|
-
intake events inject_boot provenance ignore tracked
|
|
29
|
-
].freeze
|
|
30
|
-
# ADR 0052: the typed publish block — `publish: { to: [...] }` (file
|
|
31
|
-
# fan-out) xor `publish: { tree: "dir" }` (subtree mirror).
|
|
32
|
-
PUBLISH_KEYS = %w[to tree].freeze
|
|
33
|
-
COMPUTE_KEYS = %w[kind select pluck sort_by limit transform command sources].freeze
|
|
34
|
-
INTAKE_KEYS = %w[handler config].freeze
|
|
35
|
-
RULE_KEYS = %w[match intake_handler_allowlist guard lifecycle].freeze
|
|
36
|
-
LIFECYCLE_KEYS = %w[ttl on_expire budget_ms].freeze
|
|
37
|
-
AUDIT_KEYS = %w[max_size keep].freeze
|
|
38
|
-
|
|
39
|
-
# Syntactic shape of an `owner:` subject token (the `patrick` in
|
|
40
|
-
# `human:patrick`) — the subject half of the owner-validation rule below.
|
|
41
|
-
# Role supplies the archetype set (Role::NAMES); this pattern is the
|
|
42
|
-
# owner-specific part, so it lives with the rule that composes them
|
|
43
|
-
# (ADR 0045 D1). Acting-role *names* are gated by Role::NAMES, not a regex.
|
|
44
|
-
OWNER_SUBJECT_PATTERN = /\A[a-z][a-z0-9_-]*\z/
|
|
45
|
-
|
|
46
|
-
def self.validate!(raw)
|
|
47
|
-
raise BadManifest.new("manifest must be a hash") unless raw.is_a?(Hash)
|
|
48
|
-
|
|
49
|
-
walk(raw, ROOT_KEYS, "$")
|
|
50
|
-
validate_roles!(raw["roles"])
|
|
51
|
-
validate_zones!(raw["zones"])
|
|
52
|
-
validate_entries!(raw["entries"])
|
|
53
|
-
validate_owners!(raw["zones"], raw["entries"])
|
|
54
|
-
validate_rules!(raw["rules"])
|
|
55
|
-
walk(raw["audit"], AUDIT_KEYS, "$.audit") if raw["audit"].is_a?(Hash)
|
|
56
|
-
validate_single_queue!(raw)
|
|
57
|
-
validate_zone_kind_consistency!(raw)
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def self.validate_zones!(zones)
|
|
61
|
-
Array(zones).each_with_index do |z, i|
|
|
62
|
-
walk(z, ZONE_KEYS, "$.zones[#{i}]")
|
|
63
|
-
if z["kind"].nil?
|
|
64
|
-
raise BadManifest.new("zone '#{z["name"]}' at '$.zones[#{i}]' must declare a kind (one of: #{ZONE_KINDS.join(", ")})")
|
|
65
|
-
end
|
|
66
|
-
next if ZONE_KINDS.include?(z["kind"])
|
|
67
|
-
|
|
68
|
-
raise BadManifest.new(
|
|
69
|
-
"unknown zone kind '#{z["kind"]}' at '$.zones[#{i}]' (known: #{ZONE_KINDS.join(", ")})",
|
|
70
|
-
)
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
def self.validate_entries!(entries)
|
|
75
|
-
Array(entries).each_with_index do |e, i|
|
|
76
|
-
path = "$.entries[#{i}]"
|
|
77
|
-
reject_retired_publish_keys!(e, path)
|
|
78
|
-
walk(e, ENTRY_KEYS, path)
|
|
79
|
-
validate_publish_block!(e, path)
|
|
80
|
-
walk(e["compute"], COMPUTE_KEYS, "#{path}.compute") if e["compute"].is_a?(Hash)
|
|
81
|
-
walk(e["intake"], INTAKE_KEYS, "#{path}.intake") if e["intake"].is_a?(Hash)
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
# Retired keys are no longer allowed, so `walk` would reject them as merely
|
|
86
|
-
# "unknown"; intercept first with the migration path so a pre-0.43 manifest
|
|
87
|
-
# gets a useful error. `publish_each` was removed (ADR 0051); `publish_to`/
|
|
88
|
-
# `publish_tree` were folded into the `publish:` block (ADR 0052);
|
|
89
|
-
# `index_filename` was removed (ADR 0053).
|
|
90
|
-
def self.reject_retired_publish_keys!(entry, path)
|
|
91
|
-
return unless entry.is_a?(Hash)
|
|
92
|
-
|
|
93
|
-
if entry.key?("publish_each")
|
|
94
|
-
raise BadManifest.new(
|
|
95
|
-
"publish_each was removed in 0.42.0 (ADR 0051) at '#{path}' — " \
|
|
96
|
-
"mirror the subtree with `publish: { tree: \"...\" }`.",
|
|
97
|
-
)
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
if entry.key?("publish_to")
|
|
101
|
-
raise BadManifest.new(
|
|
102
|
-
"publish_to was replaced by the publish: block in 0.43.0 (ADR 0052) at '#{path}' — " \
|
|
103
|
-
"use `publish: { to: [...] }`.",
|
|
104
|
-
)
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
if entry.key?("publish_tree")
|
|
108
|
-
raise BadManifest.new(
|
|
109
|
-
"publish_tree was replaced by the publish: block in 0.43.0 (ADR 0052) at '#{path}' — " \
|
|
110
|
-
"use `publish: { tree: \"...\" }`.",
|
|
111
|
-
)
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
return unless entry.key?("index_filename")
|
|
115
|
-
|
|
116
|
-
raise BadManifest.new(
|
|
117
|
-
"index_filename was removed in 0.43.0 (ADR 0053) at '#{path}' — a nested entry now enumerates " \
|
|
118
|
-
"each file as a key; to mirror a directory of files to a consumer path use `publish: { tree: \"...\" }`.",
|
|
119
|
-
)
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
# Shape of the ADR 0052 publish block: a Hash whose only keys are to/tree.
|
|
123
|
-
# Exclusivity (both set) and per-mode rules stay in Publish.resolve (ADR 0049).
|
|
124
|
-
def self.validate_publish_block!(entry, path)
|
|
125
|
-
return unless entry.is_a?(Hash) && entry.key?("publish")
|
|
126
|
-
|
|
127
|
-
block = entry["publish"]
|
|
128
|
-
raise BadManifest.new("publish: must be a mapping with `to:` or `tree:` at '#{path}.publish'") unless block.is_a?(Hash)
|
|
129
|
-
|
|
130
|
-
walk(block, PUBLISH_KEYS, "#{path}.publish")
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
def self.validate_rules!(rules)
|
|
134
|
-
Array(rules).each_with_index do |r, i|
|
|
135
|
-
path = "$.rules[#{i}]"
|
|
136
|
-
walk(r, RULE_KEYS, path)
|
|
137
|
-
walk(r["lifecycle"], LIFECYCLE_KEYS, "#{path}.lifecycle") if r["lifecycle"].is_a?(Hash)
|
|
138
|
-
end
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
def self.validate_roles!(roles)
|
|
142
|
-
return if roles.nil?
|
|
143
|
-
raise BadManifest.new("roles: must be a list") unless roles.is_a?(Array)
|
|
144
|
-
|
|
145
|
-
roles.each_with_index do |r, i|
|
|
146
|
-
path = "$.roles[#{i}]"
|
|
147
|
-
walk(r, ROLE_KEYS, path)
|
|
148
|
-
name = r["name"] or raise BadManifest.new("role at '#{path}' missing name")
|
|
149
|
-
unless Textus::Role::NAMES.include?(name)
|
|
150
|
-
raise BadManifest.new(
|
|
151
|
-
"unknown role name '#{name}' at '#{path}' " \
|
|
152
|
-
"(allowed: #{Textus::Role::NAMES.join(", ")})",
|
|
153
|
-
)
|
|
154
|
-
end
|
|
155
|
-
Array(r["can"]).each do |verb|
|
|
156
|
-
next if CAPABILITIES.include?(verb)
|
|
157
|
-
|
|
158
|
-
raise BadManifest.new(
|
|
159
|
-
"unknown capability '#{verb}' for role '#{name}' at '#{path}' " \
|
|
160
|
-
"(known: #{CAPABILITIES.join(", ")})",
|
|
161
|
-
)
|
|
162
|
-
end
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
author_holders = roles.count { |r| Array(r["can"]).include?("author") }
|
|
166
|
-
return if author_holders <= 1
|
|
167
|
-
|
|
168
|
-
raise BadManifest.new(
|
|
169
|
-
"manifest declares #{author_holders} roles with the author capability; at most one is allowed",
|
|
170
|
-
)
|
|
171
|
-
end
|
|
172
|
-
|
|
173
|
-
# Owners are validated against the SAME closed archetype set as role names
|
|
174
|
-
# (ADR 0045 D1) so attribution can't bypass the closed-name guarantee.
|
|
175
|
-
# Applies to both zone owners and entry owners; owner is optional, so a
|
|
176
|
-
# nil owner is not an error.
|
|
177
|
-
def self.validate_owners!(zones, entries)
|
|
178
|
-
Array(zones).each_with_index do |z, i|
|
|
179
|
-
check_owner!(z["owner"], "$.zones[#{i}]")
|
|
180
|
-
end
|
|
181
|
-
Array(entries).each_with_index do |e, i|
|
|
182
|
-
check_owner!(e["owner"], "$.entries[#{i}]")
|
|
183
|
-
end
|
|
184
|
-
end
|
|
185
|
-
|
|
186
|
-
def self.check_owner!(owner, path)
|
|
187
|
-
return if owner.nil?
|
|
188
|
-
return if valid_owner?(owner)
|
|
189
|
-
|
|
190
|
-
raise BadManifest.new(
|
|
191
|
-
"invalid owner '#{owner}' at '#{path}' " \
|
|
192
|
-
"(expected <archetype> or <archetype>:<subject>, " \
|
|
193
|
-
"archetype one of: #{Textus::Role::NAMES.join(", ")})",
|
|
194
|
-
)
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
# The owner-validation rule: an `owner:` token is either a bare archetype
|
|
198
|
-
# (`agent`) or `<archetype>:<subject>` (`human:patrick`). The archetype is
|
|
199
|
-
# gated against the closed Role::NAMES set (so attribution can't smuggle in
|
|
200
|
-
# a name the role side rejects, ADR 0045 D1); the subject is the free-form
|
|
201
|
-
# principal, validated by OWNER_SUBJECT_PATTERN. Split on the FIRST ':'
|
|
202
|
-
# only — a subject may not itself contain ':' (the pattern excludes it), so
|
|
203
|
-
# `human:a:b` is rejected.
|
|
204
|
-
def self.valid_owner?(token)
|
|
205
|
-
return false unless token.is_a?(String) && !token.empty?
|
|
206
|
-
|
|
207
|
-
archetype, subject = token.split(":", 2)
|
|
208
|
-
return false unless Textus::Role::NAMES.include?(archetype)
|
|
209
|
-
return true if subject.nil?
|
|
210
|
-
|
|
211
|
-
OWNER_SUBJECT_PATTERN.match?(subject)
|
|
212
|
-
end
|
|
213
|
-
|
|
214
|
-
def self.walk(hash, allowed, path)
|
|
215
|
-
return unless hash.is_a?(Hash)
|
|
216
|
-
|
|
217
|
-
hash.each_key do |k|
|
|
218
|
-
next if allowed.include?(k)
|
|
219
|
-
|
|
220
|
-
raise BadManifest.new("unknown key '#{k}' at '#{path}'")
|
|
221
|
-
end
|
|
222
|
-
end
|
|
223
|
-
|
|
224
|
-
def self.validate_single_queue!(raw)
|
|
225
|
-
queues = Array(raw["zones"]).select { |z| z["kind"] == "queue" }.map { |z| z["name"] }
|
|
226
|
-
return if queues.size <= 1
|
|
227
|
-
|
|
228
|
-
raise BadManifest.new(
|
|
229
|
-
"at most one zone may declare kind: queue (found: #{queues.join(", ")})",
|
|
230
|
-
)
|
|
231
|
-
end
|
|
232
|
-
|
|
233
|
-
# Write authority is derived from capabilities (ADR 0030): a zone of a
|
|
234
|
-
# given kind can only be written by a role that holds the kind's required
|
|
235
|
-
# verb. Reject a manifest declaring a zone whose required verb is held by
|
|
236
|
-
# no role. Capabilities.resolve returns the defaults when `roles:` is nil,
|
|
237
|
-
# so the capability union is all four verbs and every kind is satisfied.
|
|
238
|
-
def self.validate_zone_kind_consistency!(raw)
|
|
239
|
-
held = Capabilities.resolve(raw["roles"]).values.flatten.uniq
|
|
240
|
-
|
|
241
|
-
Array(raw["zones"]).each_with_index do |z, i|
|
|
242
|
-
verb = KIND_REQUIRES_VERB[z["kind"]]
|
|
243
|
-
next if verb.nil? || held.include?(verb)
|
|
244
|
-
|
|
245
|
-
raise BadManifest.new(
|
|
246
|
-
"zone '#{z["name"]}' (#{z["kind"]}) at '$.zones[#{i}]' " \
|
|
247
|
-
"needs a role with capability '#{verb}'; none declared",
|
|
248
|
-
)
|
|
249
|
-
end
|
|
250
|
-
end
|
|
8
|
+
# Re-export the vocabulary.
|
|
9
|
+
LANES = Vocabulary::LANES
|
|
10
|
+
ZONE_KINDS = Vocabulary::ZONE_KINDS
|
|
11
|
+
CAPABILITIES = Vocabulary::CAPABILITIES
|
|
12
|
+
KIND_REQUIRES_VERB = Vocabulary::KIND_REQUIRES_VERB
|
|
13
|
+
# Re-export the keys + registry.
|
|
14
|
+
ROOT_KEYS = Keys::ROOT_KEYS
|
|
15
|
+
ROLE_KEYS = Keys::ROLE_KEYS
|
|
16
|
+
ZONE_KEYS = Keys::ZONE_KEYS
|
|
17
|
+
ENTRY_KEYS = Keys::ENTRY_KEYS
|
|
18
|
+
PUBLISH_KEYS = Keys::PUBLISH_KEYS
|
|
19
|
+
SOURCE_KEYS = Keys::SOURCE_KEYS
|
|
20
|
+
RETENTION_KEYS = Keys::RETENTION_KEYS
|
|
21
|
+
AUDIT_KEYS = Keys::AUDIT_KEYS
|
|
22
|
+
FIELD_REGISTRY = Keys::FIELD_REGISTRY
|
|
23
|
+
RULE_KEYS = Keys::RULE_KEYS
|
|
24
|
+
OWNER_SUBJECT_PATTERN = Keys::OWNER_SUBJECT_PATTERN
|
|
25
|
+
|
|
26
|
+
# Public entry points — the validation walk lives in Schema::Validator
|
|
27
|
+
# (ADR 0107). Kept here so callers keep speaking to `Schema`.
|
|
28
|
+
def self.validate!(raw) = Validator.validate!(raw)
|
|
29
|
+
|
|
30
|
+
def self.validate_source_and_retention!(manifest) = Validator.validate_source_and_retention!(manifest)
|
|
251
31
|
end
|
|
252
32
|
end
|
|
253
33
|
end
|
data/lib/textus/manifest.rb
CHANGED
|
@@ -6,9 +6,9 @@ module Textus
|
|
|
6
6
|
#
|
|
7
7
|
# * data — frozen value: raw, root, zones, entries, audit_config, role_caps
|
|
8
8
|
# * resolver — resolves keys → entry + path
|
|
9
|
-
# * policy — zone/role authority (zone_writers, declared_kind
|
|
9
|
+
# * policy — zone/role authority (zone_writers, declared_kind, derived_entry?,
|
|
10
10
|
# queue_zone?, permission_for, …)
|
|
11
|
-
# * rules — match-block rule engine (
|
|
11
|
+
# * rules — match-block rule engine (lifecycle, handler allowlist, materialize, …)
|
|
12
12
|
#
|
|
13
13
|
# Use `manifest.data.entries`, `manifest.policy.declared_kind(z)`, etc.
|
|
14
14
|
Manifest = Data.define(:data, :resolver, :policy, :rules)
|
|
@@ -44,12 +44,14 @@ module Textus # rubocop:disable Style/OneClassPerFile
|
|
|
44
44
|
|
|
45
45
|
def build(raw, root)
|
|
46
46
|
data = Manifest::Data.parse(raw, root: root)
|
|
47
|
-
new(
|
|
47
|
+
manifest = new(
|
|
48
48
|
data: data,
|
|
49
49
|
resolver: Manifest::Resolver.new(data),
|
|
50
50
|
policy: data.policy,
|
|
51
51
|
rules: Manifest::Rules.parse(raw["rules"] || []),
|
|
52
52
|
)
|
|
53
|
+
Manifest::Schema.validate_source_and_retention!(manifest) # ADR 0093
|
|
54
|
+
manifest
|
|
53
55
|
end
|
|
54
56
|
|
|
55
57
|
def check_version!(raw, source)
|
data/lib/textus/mcp/server.rb
CHANGED
|
@@ -94,7 +94,7 @@ module Textus
|
|
|
94
94
|
|
|
95
95
|
# ADR 0083: the contract-drift guard gates mutating verbs — every MCP
|
|
96
96
|
# verb that is NOT a pure read (Write:: + the destructive Maintenance::
|
|
97
|
-
# verbs
|
|
97
|
+
# verbs reconcile/zone_mv/key_*_prefix). Reads and boot bypass it (a stale
|
|
98
98
|
# read returns on-disk truth; boot re-orients). Keying on read_verbs
|
|
99
99
|
# (not write_verbs) keeps the destructive Maintenance:: verbs gated.
|
|
100
100
|
@session.check_etag!(contract_etag) unless Catalog.read_verbs.include?(name)
|
|
@@ -4,6 +4,12 @@ require "time"
|
|
|
4
4
|
|
|
5
5
|
module Textus
|
|
6
6
|
module Ports
|
|
7
|
+
# Append-only audit log adapter: writes and rotates the on-disk audit JSONL
|
|
8
|
+
# under the store root. An instantiable class — it holds collaborators (the
|
|
9
|
+
# root path + size/keep config), so each store binds its own instance. It
|
|
10
|
+
# already satisfied ADR 0109's single-shape rule (every port is an
|
|
11
|
+
# instantiable class) before that ADR's Clock/Publisher conversions, so it
|
|
12
|
+
# was unchanged by them.
|
|
7
13
|
class AuditLog
|
|
8
14
|
DEFAULT_MAX_SIZE = 10_485_760
|
|
9
15
|
DEFAULT_KEEP = 5
|