textus 0.20.2 → 0.26.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.
Files changed (175) hide show
  1. checksums.yaml +4 -4
  2. data/ARCHITECTURE.md +148 -45
  3. data/CHANGELOG.md +194 -0
  4. data/README.md +8 -5
  5. data/SPEC.md +54 -15
  6. data/docs/conventions.md +10 -0
  7. data/lib/textus/application/caps.rb +49 -0
  8. data/lib/textus/application/context.rb +2 -2
  9. data/lib/textus/application/envelope/reader.rb +44 -0
  10. data/lib/textus/application/{writes/envelope_io.rb → envelope/writer.rb} +24 -50
  11. data/lib/textus/application/maintenance/key_delete_prefix.rb +44 -0
  12. data/lib/textus/application/maintenance/key_mv_prefix.rb +57 -0
  13. data/lib/textus/application/maintenance/migrate.rb +59 -0
  14. data/lib/textus/application/maintenance/rule_lint.rb +65 -0
  15. data/lib/textus/application/maintenance/zone_mv.rb +60 -0
  16. data/lib/textus/application/maintenance.rb +17 -0
  17. data/lib/textus/application/projection.rb +12 -10
  18. data/lib/textus/application/read/audit.rb +106 -0
  19. data/lib/textus/application/read/blame.rb +91 -0
  20. data/lib/textus/application/read/deps.rb +34 -0
  21. data/lib/textus/application/read/freshness.rb +110 -0
  22. data/lib/textus/application/read/get.rb +75 -0
  23. data/lib/textus/application/read/get_or_refresh.rb +63 -0
  24. data/lib/textus/application/read/list.rb +25 -0
  25. data/lib/textus/application/read/policy_explain.rb +47 -0
  26. data/lib/textus/application/read/published.rb +25 -0
  27. data/lib/textus/application/read/pulse.rb +101 -0
  28. data/lib/textus/application/read/rdeps.rb +35 -0
  29. data/lib/textus/application/read/schema_envelope.rb +26 -0
  30. data/lib/textus/application/read/stale.rb +23 -0
  31. data/lib/textus/application/read/uid.rb +30 -0
  32. data/lib/textus/application/read/validate_all.rb +32 -0
  33. data/lib/textus/application/{reads → read}/validator.rb +2 -2
  34. data/lib/textus/application/read/where.rb +26 -0
  35. data/lib/textus/application/use_case.rb +22 -0
  36. data/lib/textus/application/write/accept.rb +102 -0
  37. data/lib/textus/application/{writes → write}/authority_gate.rb +3 -3
  38. data/lib/textus/application/write/delete.rb +45 -0
  39. data/lib/textus/application/{writes → write}/materializer.rb +14 -15
  40. data/lib/textus/application/write/mv.rb +118 -0
  41. data/lib/textus/application/write/publish.rb +96 -0
  42. data/lib/textus/application/write/put.rb +49 -0
  43. data/lib/textus/application/write/refresh_all.rb +63 -0
  44. data/lib/textus/application/{refresh/orchestrator.rb → write/refresh_orchestrator.rb} +32 -8
  45. data/lib/textus/application/write/refresh_worker.rb +134 -0
  46. data/lib/textus/application/write/reject.rb +62 -0
  47. data/lib/textus/{intro.rb → boot.rb} +49 -29
  48. data/lib/textus/builder/pipeline.rb +5 -5
  49. data/lib/textus/cli/group/mcp.rb +9 -0
  50. data/lib/textus/cli/group/zone.rb +9 -0
  51. data/lib/textus/cli/verb/accept.rb +1 -1
  52. data/lib/textus/cli/verb/audit.rb +4 -2
  53. data/lib/textus/cli/verb/blame.rb +1 -1
  54. data/lib/textus/cli/verb/boot.rb +13 -0
  55. data/lib/textus/cli/verb/build.rb +2 -2
  56. data/lib/textus/cli/verb/delete.rb +1 -1
  57. data/lib/textus/cli/verb/deps.rb +1 -1
  58. data/lib/textus/cli/verb/doctor.rb +1 -1
  59. data/lib/textus/cli/verb/freshness.rb +1 -1
  60. data/lib/textus/cli/verb/get.rb +1 -1
  61. data/lib/textus/cli/verb/hook_run.rb +3 -4
  62. data/lib/textus/cli/verb/hooks.rb +11 -14
  63. data/lib/textus/cli/verb/key_delete.rb +24 -0
  64. data/lib/textus/cli/verb/list.rb +1 -1
  65. data/lib/textus/cli/verb/mcp_serve.rb +17 -0
  66. data/lib/textus/cli/verb/migrate.rb +18 -0
  67. data/lib/textus/cli/verb/mv.rb +11 -3
  68. data/lib/textus/cli/verb/published.rb +1 -1
  69. data/lib/textus/cli/verb/pulse.rb +17 -0
  70. data/lib/textus/cli/verb/put.rb +8 -6
  71. data/lib/textus/cli/verb/rdeps.rb +1 -1
  72. data/lib/textus/cli/verb/refresh.rb +1 -1
  73. data/lib/textus/cli/verb/refresh_stale.rb +1 -1
  74. data/lib/textus/cli/verb/reject.rb +1 -1
  75. data/lib/textus/cli/verb/rule_explain.rb +1 -1
  76. data/lib/textus/cli/verb/rule_lint.rb +18 -0
  77. data/lib/textus/cli/verb/schema.rb +1 -1
  78. data/lib/textus/cli/verb/uid.rb +1 -1
  79. data/lib/textus/cli/verb/where.rb +1 -1
  80. data/lib/textus/cli/verb/zone_mv.rb +19 -0
  81. data/lib/textus/cli/verb.rb +4 -4
  82. data/lib/textus/cli.rb +1 -1
  83. data/lib/textus/doctor/check/audit_log.rb +2 -2
  84. data/lib/textus/doctor/check/handler_allowlist.rb +2 -2
  85. data/lib/textus/doctor/check/hooks.rb +4 -3
  86. data/lib/textus/doctor/check/illegal_keys.rb +2 -2
  87. data/lib/textus/doctor/check/intake_registration.rb +2 -2
  88. data/lib/textus/doctor/check/manifest_files.rb +2 -2
  89. data/lib/textus/doctor/check/protocol_version.rb +2 -2
  90. data/lib/textus/doctor/check/refresh_locks.rb +2 -2
  91. data/lib/textus/doctor/check/rule_ambiguity.rb +2 -2
  92. data/lib/textus/doctor/check/schema_parse_error.rb +1 -1
  93. data/lib/textus/doctor/check/schema_violations.rb +1 -1
  94. data/lib/textus/doctor/check/schemas.rb +2 -2
  95. data/lib/textus/doctor/check/sentinels.rb +2 -2
  96. data/lib/textus/doctor/check/templates.rb +2 -2
  97. data/lib/textus/doctor/check/unowned_schema_fields.rb +1 -1
  98. data/lib/textus/doctor/check.rb +5 -3
  99. data/lib/textus/doctor.rb +24 -27
  100. data/lib/textus/domain/authorizer.rb +4 -4
  101. data/lib/textus/{application → domain}/policy/predicates/accept_authority_signed.rb +2 -2
  102. data/lib/textus/{application → domain}/policy/predicates/schema_valid.rb +1 -1
  103. data/lib/textus/{application → domain}/policy/promotion.rb +1 -1
  104. data/lib/textus/domain/staleness/generator_check.rb +2 -2
  105. data/lib/textus/domain/staleness/intake_check.rb +2 -2
  106. data/lib/textus/domain/staleness.rb +1 -1
  107. data/lib/textus/errors.rb +16 -0
  108. data/lib/textus/hooks/builtin.rb +14 -14
  109. data/lib/textus/hooks/context.rb +13 -13
  110. data/lib/textus/hooks/error_log.rb +32 -0
  111. data/lib/textus/hooks/{bus.rb → event_bus.rb} +41 -53
  112. data/lib/textus/hooks/loader.rb +29 -3
  113. data/lib/textus/hooks/rpc_registry.rb +77 -0
  114. data/lib/textus/infra/audit_log.rb +126 -16
  115. data/lib/textus/infra/audit_subscriber.rb +6 -7
  116. data/lib/textus/infra/refresh/detached.rb +1 -1
  117. data/lib/textus/key/path.rb +7 -3
  118. data/lib/textus/manifest/data.rb +78 -0
  119. data/lib/textus/manifest/entry/base.rb +44 -7
  120. data/lib/textus/manifest/entry/derived.rb +41 -6
  121. data/lib/textus/manifest/entry/intake.rb +15 -3
  122. data/lib/textus/manifest/entry/leaf.rb +6 -5
  123. data/lib/textus/manifest/entry/nested.rb +42 -3
  124. data/lib/textus/manifest/entry/parser.rb +8 -44
  125. data/lib/textus/manifest/entry/validators/events.rb +2 -2
  126. data/lib/textus/manifest/entry/validators/format_matrix.rb +5 -4
  127. data/lib/textus/manifest/entry/validators/index_filename.rb +2 -1
  128. data/lib/textus/manifest/entry/validators/inject_boot.rb +19 -0
  129. data/lib/textus/manifest/entry/validators/publish_each.rb +4 -3
  130. data/lib/textus/manifest/entry/validators.rb +1 -1
  131. data/lib/textus/manifest/entry.rb +3 -0
  132. data/lib/textus/manifest/policy.rb +48 -0
  133. data/lib/textus/manifest/resolver.rb +18 -18
  134. data/lib/textus/manifest/rules.rb +1 -1
  135. data/lib/textus/manifest/schema.rb +20 -6
  136. data/lib/textus/manifest.rb +53 -101
  137. data/lib/textus/mcp/errors.rb +32 -0
  138. data/lib/textus/mcp/server.rb +127 -0
  139. data/lib/textus/mcp/session.rb +31 -0
  140. data/lib/textus/mcp/tool_schemas.rb +71 -0
  141. data/lib/textus/mcp/tools.rb +129 -0
  142. data/lib/textus/mcp.rb +6 -0
  143. data/lib/textus/schema/tools.rb +14 -10
  144. data/lib/textus/session.rb +84 -0
  145. data/lib/textus/store.rb +17 -8
  146. data/lib/textus/version.rb +1 -1
  147. data/lib/textus.rb +8 -1
  148. metadata +65 -38
  149. data/lib/textus/application/reads/audit.rb +0 -69
  150. data/lib/textus/application/reads/blame.rb +0 -82
  151. data/lib/textus/application/reads/deps.rb +0 -26
  152. data/lib/textus/application/reads/freshness.rb +0 -88
  153. data/lib/textus/application/reads/get.rb +0 -67
  154. data/lib/textus/application/reads/get_or_refresh.rb +0 -51
  155. data/lib/textus/application/reads/list.rb +0 -17
  156. data/lib/textus/application/reads/policy_explain.rb +0 -39
  157. data/lib/textus/application/reads/published.rb +0 -17
  158. data/lib/textus/application/reads/rdeps.rb +0 -27
  159. data/lib/textus/application/reads/schema_envelope.rb +0 -18
  160. data/lib/textus/application/reads/stale.rb +0 -15
  161. data/lib/textus/application/reads/uid.rb +0 -23
  162. data/lib/textus/application/reads/validate_all.rb +0 -24
  163. data/lib/textus/application/reads/where.rb +0 -18
  164. data/lib/textus/application/refresh/all.rb +0 -52
  165. data/lib/textus/application/refresh/worker.rb +0 -116
  166. data/lib/textus/application/writes/accept.rb +0 -89
  167. data/lib/textus/application/writes/delete.rb +0 -33
  168. data/lib/textus/application/writes/mv.rb +0 -105
  169. data/lib/textus/application/writes/publish.rb +0 -162
  170. data/lib/textus/application/writes/put.rb +0 -37
  171. data/lib/textus/application/writes/reject.rb +0 -50
  172. data/lib/textus/cli/verb/intro.rb +0 -13
  173. data/lib/textus/infra/event_bus.rb +0 -27
  174. data/lib/textus/manifest/entry/validators/inject_intro.rb +0 -21
  175. data/lib/textus/operations.rb +0 -169
@@ -0,0 +1,35 @@
1
+ module Textus
2
+ module Application
3
+ module Read
4
+ module Rdeps
5
+ def self.call(*, session:, ctx:, caps:, **) # rubocop:disable Lint/UnusedMethodArgument
6
+ Impl.new(caps: caps).call(*, **)
7
+ end
8
+
9
+ class Impl
10
+ def initialize(caps:)
11
+ @manifest = caps.manifest
12
+ end
13
+
14
+ def call(key)
15
+ @manifest.data.entries.each_with_object([]) do |e, acc|
16
+ next unless e.is_a?(Textus::Manifest::Entry::Derived)
17
+
18
+ src = e.source
19
+ sources = if src.is_a?(Textus::Manifest::Entry::Derived::Projection)
20
+ Array(src.select).compact
21
+ elsif src.is_a?(Textus::Manifest::Entry::Derived::External)
22
+ Array(src.sources).compact
23
+ else
24
+ []
25
+ end
26
+ acc << e.key if sources.any? { |s| s == key || key.start_with?("#{s}.") }
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ Textus::Application::UseCase.register(:rdeps, Textus::Application::Read::Rdeps, caps: :read)
@@ -0,0 +1,26 @@
1
+ module Textus
2
+ module Application
3
+ module Read
4
+ module SchemaEnvelope
5
+ def self.call(*, session:, ctx:, caps:, **) # rubocop:disable Lint/UnusedMethodArgument
6
+ Impl.new(caps: caps).call(*, **)
7
+ end
8
+
9
+ class Impl
10
+ def initialize(caps:)
11
+ @manifest = caps.manifest
12
+ @schemas = caps.schemas
13
+ end
14
+
15
+ def call(key)
16
+ mentry = @manifest.resolver.resolve(key).entry
17
+ schema = @schemas.fetch_or_nil(mentry.schema)
18
+ { "protocol" => PROTOCOL, "key" => key, "schema_ref" => mentry.schema, "schema" => schema&.to_h }
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ Textus::Application::UseCase.register(:schema_envelope, Textus::Application::Read::SchemaEnvelope, caps: :read)
@@ -0,0 +1,23 @@
1
+ module Textus
2
+ module Application
3
+ module Read
4
+ module Stale
5
+ def self.call(*, session:, ctx:, caps:, **) # rubocop:disable Lint/UnusedMethodArgument
6
+ Impl.new(caps: caps).call(*, **)
7
+ end
8
+
9
+ class Impl
10
+ def initialize(caps:)
11
+ @manifest = caps.manifest
12
+ end
13
+
14
+ def call(prefix: nil, zone: nil)
15
+ Textus::Domain::Staleness.new(manifest: @manifest).call(prefix: prefix, zone: zone)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ Textus::Application::UseCase.register(:stale, Textus::Application::Read::Stale, caps: :read)
@@ -0,0 +1,30 @@
1
+ module Textus
2
+ module Application
3
+ module Read
4
+ module Uid
5
+ def self.call(*, session:, ctx:, caps:, **) # rubocop:disable Lint/UnusedMethodArgument
6
+ Impl.new(ctx: ctx, caps: caps).call(*, **)
7
+ end
8
+
9
+ class Impl
10
+ def initialize(ctx:, caps:)
11
+ @ctx = ctx
12
+ @caps = caps
13
+ end
14
+
15
+ def call(key)
16
+ get.get(key).uid
17
+ end
18
+
19
+ private
20
+
21
+ def get
22
+ @get ||= Get::Impl.new(ctx: @ctx, caps: @caps)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ Textus::Application::UseCase.register(:uid, Textus::Application::Read::Uid, caps: :read)
@@ -0,0 +1,32 @@
1
+ module Textus
2
+ module Application
3
+ module Read
4
+ module ValidateAll
5
+ def self.call(*, session:, ctx:, caps:, **) # rubocop:disable Lint/UnusedMethodArgument
6
+ Impl.new(ctx: ctx, caps: caps).call(*, **)
7
+ end
8
+
9
+ class Impl
10
+ def initialize(ctx:, caps:)
11
+ @ctx = ctx
12
+ @caps = caps
13
+ @manifest = caps.manifest
14
+ @schemas = caps.schemas
15
+ @audit_log = caps.audit_log
16
+ end
17
+
18
+ def call
19
+ Validator.new(
20
+ reader: Get::Impl.new(ctx: @ctx, caps: @caps),
21
+ manifest: @manifest,
22
+ audit_log: @audit_log,
23
+ schema_for: ->(name) { @schemas.fetch_or_nil(name) },
24
+ ).call
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ Textus::Application::UseCase.register(:validate_all, Textus::Application::Read::ValidateAll, caps: :read)
@@ -1,6 +1,6 @@
1
1
  module Textus
2
2
  module Application
3
- module Reads
3
+ module Read
4
4
  class Validator
5
5
  def initialize(reader:, manifest:, audit_log:, schema_for:)
6
6
  @reader = reader
@@ -55,7 +55,7 @@ module Textus
55
55
  last_writer = @audit_log.last_writer_for(key)
56
56
  return if last_writer.nil?
57
57
 
58
- last_writer_is_authority = @manifest.role_kind(last_writer) == :accept_authority
58
+ last_writer_is_authority = @manifest.policy.role_kind(last_writer) == :accept_authority
59
59
 
60
60
  env.meta.each_key do |field|
61
61
  owner = schema.maintained_by(field)
@@ -0,0 +1,26 @@
1
+ module Textus
2
+ module Application
3
+ module Read
4
+ module Where
5
+ def self.call(*, session:, ctx:, caps:, **) # rubocop:disable Lint/UnusedMethodArgument
6
+ Impl.new(caps: caps).call(*, **)
7
+ end
8
+
9
+ class Impl
10
+ def initialize(caps:)
11
+ @manifest = caps.manifest
12
+ end
13
+
14
+ def call(key)
15
+ res = @manifest.resolver.resolve(key)
16
+ mentry = res.entry
17
+ path = res.path
18
+ { "protocol" => PROTOCOL, "key" => key, "zone" => mentry.zone, "owner" => mentry.owner, "path" => path }
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ Textus::Application::UseCase.register(:where, Textus::Application::Read::Where, caps: :read)
@@ -0,0 +1,22 @@
1
+ module Textus
2
+ module Application
3
+ # Registry mapping verb symbols to use-case modules. Each entry says
4
+ # which caps slice the use case needs (:read or :write); Session
5
+ # uses this to define one method per verb.
6
+ module UseCase
7
+ Entry = Data.define(:verb, :mod, :caps_kind)
8
+
9
+ @entries = []
10
+
11
+ class << self
12
+ attr_reader :entries
13
+
14
+ def register(verb, mod, caps:)
15
+ @entries << Entry.new(verb: verb.to_sym, mod: mod, caps_kind: caps.to_sym)
16
+ end
17
+
18
+ def each(&) = @entries.each(&)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,102 @@
1
+ require_relative "authority_gate"
2
+
3
+ module Textus
4
+ module Application
5
+ module Write
6
+ module Accept
7
+ def self.call(*, session:, ctx:, caps:, **)
8
+ Impl.new(
9
+ ctx: ctx, caps: caps,
10
+ writer: session.envelope_writer,
11
+ hook_context: session.hook_context
12
+ ).call(*, **)
13
+ end
14
+
15
+ class Impl
16
+ include AuthorityGate
17
+
18
+ def initialize(ctx:, caps:, writer:, hook_context:)
19
+ @ctx = ctx
20
+ @caps = caps
21
+ @manifest = caps.manifest
22
+ @file_store = caps.file_store
23
+ @schemas = caps.schemas
24
+ @writer = writer
25
+ @events = caps.events
26
+ @authorizer = caps.authorizer
27
+ @hook_context = hook_context
28
+ end
29
+
30
+ def call(pending_key)
31
+ assert_accept_authority!("accept")
32
+
33
+ env = Textus::Application::Read::Get::Impl.new(
34
+ ctx: @ctx, caps: @caps,
35
+ ).call(pending_key)
36
+ proposal = env.meta["proposal"] or raise ProposalError.new("entry has no proposal block: #{pending_key}")
37
+ target = proposal["target_key"] or raise ProposalError.new("proposal missing target_key")
38
+ action = proposal["action"] || "put"
39
+
40
+ evaluate_promotion!(env, target)
41
+
42
+ case action
43
+ when "put"
44
+ # Nested proposal "frontmatter" — the meta to write to the accepted
45
+ # target. Not related to the removed intake-handler legacy bridge.
46
+ target_meta = env.meta["frontmatter"] || {}
47
+ target_body = env.body
48
+ put_op.call(target, meta: target_meta, body: target_body)
49
+ when "delete"
50
+ delete_op.call(target)
51
+ else
52
+ raise ProposalError.new("unknown action: #{action}")
53
+ end
54
+
55
+ delete_op.call(pending_key)
56
+
57
+ @events.publish(:proposal_accepted,
58
+ ctx: @hook_context,
59
+ key: pending_key,
60
+ target_key: target)
61
+
62
+ { "protocol" => PROTOCOL, "accepted" => pending_key, "target_key" => target, "action" => action }
63
+ end
64
+
65
+ private
66
+
67
+ def put_op
68
+ @put_op ||= Textus::Application::Write::Put::Impl.new(
69
+ ctx: @ctx, caps: @caps, writer: @writer,
70
+ hook_context: @hook_context
71
+ )
72
+ end
73
+
74
+ def delete_op
75
+ @delete_op ||= Textus::Application::Write::Delete::Impl.new(
76
+ ctx: @ctx, caps: @caps, writer: @writer,
77
+ hook_context: @hook_context
78
+ )
79
+ end
80
+
81
+ def evaluate_promotion!(env, target_key)
82
+ rules = @manifest.rules.for(target_key)
83
+ promote = rules.promote
84
+ return if promote.nil? || promote.requires.empty?
85
+
86
+ policy = Textus::Domain::Policy::Promotion.from_names(promote.requires)
87
+ result = policy.evaluate(
88
+ entry: env, schemas: @schemas, manifest: @manifest, role: @ctx.role,
89
+ )
90
+ return if result.ok?
91
+
92
+ raise ProposalError.new(
93
+ "promotion gate failed: #{result.reasons.join("; ")}",
94
+ )
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
101
+
102
+ Textus::Application::UseCase.register(:accept, Textus::Application::Write::Accept, caps: :write)
@@ -1,15 +1,15 @@
1
1
  module Textus
2
2
  module Application
3
- module Writes
3
+ module Write
4
4
  # Shared gate for write verbs that require the caller to hold the
5
5
  # manifest's accept_authority role. Provides one method, expressed
6
6
  # as two early-returns rather than a ternary, so each failure mode
7
7
  # reads on its own line.
8
8
  module AuthorityGate
9
9
  def assert_accept_authority!(verb)
10
- return if @manifest.role_kind(@ctx.role) == :accept_authority
10
+ return if @manifest.policy.role_kind(@ctx.role) == :accept_authority
11
11
 
12
- authority = @manifest.roles_with_kind(:accept_authority).first
12
+ authority = @manifest.policy.roles_with_kind(:accept_authority).first
13
13
  if authority.nil?
14
14
  raise ProposalError.new(
15
15
  "no role with accept_authority kind is declared in this manifest; #{verb} is disabled",
@@ -0,0 +1,45 @@
1
+ module Textus
2
+ module Application
3
+ module Write
4
+ module Delete
5
+ def self.call(*, session:, ctx:, caps:, **)
6
+ Impl.new(
7
+ ctx: ctx, caps: caps,
8
+ writer: session.envelope_writer,
9
+ hook_context: session.hook_context
10
+ ).call(*, **)
11
+ end
12
+
13
+ class Impl
14
+ def initialize(ctx:, caps:, writer:, hook_context:)
15
+ @ctx = ctx
16
+ @manifest = caps.manifest
17
+ @events = caps.events
18
+ @authorizer = caps.authorizer
19
+ @writer = writer
20
+ @hook_context = hook_context
21
+ end
22
+
23
+ def call(key, if_etag: nil, suppress_events: false)
24
+ Textus::Manifest::Data.validate_key!(key)
25
+ mentry = @manifest.resolver.resolve(key).entry
26
+
27
+ @authorizer.authorize_write!(mentry, role: @ctx.role)
28
+
29
+ @writer.delete(key, mentry: mentry, if_etag: if_etag)
30
+
31
+ unless suppress_events
32
+ @events.publish(:entry_deleted,
33
+ ctx: @hook_context,
34
+ key: key)
35
+ end
36
+
37
+ { "protocol" => Textus::PROTOCOL, "ok" => true, "key" => key, "deleted" => true }
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ Textus::Application::UseCase.register(:delete, Textus::Application::Write::Delete, caps: :write)
@@ -2,37 +2,36 @@ require "fileutils"
2
2
 
3
3
  module Textus
4
4
  module Application
5
- module Writes
5
+ module Write
6
6
  # Materializes a single Derived manifest entry onto disk by running
7
7
  # the builder pipeline (template + projection + external runner).
8
- # Extracted from Application::Writes::Build so that Publish can reuse
8
+ # Extracted from Application::Write::Build so that Publish can reuse
9
9
  # it without creating a Build dependency.
10
10
  class Materializer
11
- def initialize(ctx:, manifest:, file_store:, bus:, root:, store:)
11
+ def initialize(ctx:, caps:, rpc:, session:)
12
12
  @ctx = ctx
13
- @manifest = manifest
14
- @file_store = file_store
15
- @bus = bus
16
- @root = root
17
- @store = store
13
+ @caps = caps
14
+ @manifest = caps.manifest
15
+ @file_store = caps.file_store
16
+ @rpc = rpc
17
+ @root = caps.root
18
+ @session = session
18
19
  end
19
20
 
20
21
  # Runs the builder pipeline for `mentry` and returns the on-disk
21
22
  # target_path string.
22
23
  def run(mentry)
23
- reader = Textus::Application::Reads::Get.new(
24
- ctx: @ctx, manifest: @manifest, file_store: @file_store,
25
- )
26
- lister = Textus::Application::Reads::List.new(manifest: @manifest)
24
+ reader = Textus::Application::Read::Get::Impl.new(ctx: @ctx, caps: @caps)
25
+ lister = Textus::Application::Read::List::Impl.new(caps: @caps)
27
26
  Builder::Pipeline.run(
28
27
  mentry: mentry,
29
28
  manifest: @manifest,
30
29
  reader: reader.method(:call),
31
30
  lister: lister.method(:call),
32
- transform_resolver: ->(name) { @bus.rpc_callable(:transform_rows, name) },
31
+ rpc: @rpc,
33
32
  template_loader: ->(name) { read_template(name) },
34
- transform_context: @store,
35
- inject_intro: -> { Textus::Intro.run(@store) },
33
+ transform_context: @caps,
34
+ inject_boot: -> { Textus::Boot.run(@session) },
36
35
  )
37
36
  end
38
37
 
@@ -0,0 +1,118 @@
1
+ module Textus
2
+ module Application
3
+ module Write
4
+ module Mv
5
+ def self.call(*, session:, ctx:, caps:, **)
6
+ Impl.new(
7
+ ctx: ctx, caps: caps,
8
+ reader: session.envelope_reader,
9
+ writer: session.envelope_writer,
10
+ hook_context: session.hook_context
11
+ ).call(*, **)
12
+ end
13
+
14
+ class Impl
15
+ def initialize(ctx:, caps:, reader:, writer:, hook_context:)
16
+ @ctx = ctx
17
+ @manifest = caps.manifest
18
+ @events = caps.events
19
+ @authorizer = caps.authorizer
20
+ @reader = reader
21
+ @writer = writer
22
+ @hook_context = hook_context
23
+ end
24
+
25
+ def call(old_key, new_key, dry_run: false)
26
+ old_res, new_res = prepare(old_key, new_key)
27
+ return dry_run_result(old_key, new_key, old_res, new_res) if dry_run
28
+
29
+ ensure_uid!(old_key, old_res.entry)
30
+ envelope = @writer.move(
31
+ from_key: old_key, to_key: new_key,
32
+ new_mentry: new_res.entry
33
+ )
34
+ publish_renamed(old_key, new_key, envelope)
35
+ success_result(old_key, new_key, old_res, new_res, envelope)
36
+ end
37
+
38
+ private
39
+
40
+ def prepare(old_key, new_key)
41
+ Textus::Manifest::Data.validate_key!(old_key)
42
+ Textus::Manifest::Data.validate_key!(new_key)
43
+ raise UsageError.new("mv: old and new keys are identical") if old_key == new_key
44
+
45
+ old_res = @manifest.resolver.resolve(old_key)
46
+ new_res = @manifest.resolver.resolve(new_key)
47
+ raise UnknownKey.new(old_key) unless @reader.exists?(old_key)
48
+
49
+ validate_zone_and_format!(old_res.entry, new_res.entry)
50
+ @authorizer.authorize_write!(old_res.entry, role: @ctx.role)
51
+ @authorizer.authorize_write!(new_res.entry, role: @ctx.role)
52
+ raise UsageError.new("mv: target '#{new_key}' already exists at #{new_res.path}") if @reader.exists?(new_key)
53
+
54
+ [old_res, new_res]
55
+ end
56
+
57
+ def validate_zone_and_format!(old_mentry, new_mentry)
58
+ if old_mentry.zone != new_mentry.zone
59
+ raise UsageError.new(
60
+ "mv: cross-zone move refused (#{old_mentry.zone} → #{new_mentry.zone}). " \
61
+ "Use put+delete for cross-zone moves.",
62
+ )
63
+ end
64
+ return if old_mentry.format == new_mentry.format
65
+
66
+ raise UsageError.new("mv: format mismatch (#{old_mentry.format} → #{new_mentry.format}); refusing.")
67
+ end
68
+
69
+ # If the source file lacks a UID, rewrite it in-place via the writer
70
+ # so a UID gets injected before the move. This produces one "put"
71
+ # audit row, then the "mv" row from Writer#move.
72
+ def ensure_uid!(old_key, old_mentry)
73
+ pre_env = @reader.read(old_key)
74
+ return if pre_env.uid
75
+
76
+ @writer.put(
77
+ old_key, mentry: old_mentry,
78
+ payload: Textus::Application::Envelope::Writer::Payload.new(
79
+ meta: pre_env.meta, body: pre_env.body, content: pre_env.content,
80
+ )
81
+ )
82
+ end
83
+
84
+ def publish_renamed(old_key, new_key, envelope)
85
+ @events.publish(:entry_renamed,
86
+ ctx: @hook_context,
87
+ key: new_key,
88
+ from_key: old_key,
89
+ to_key: new_key,
90
+ envelope: envelope)
91
+ end
92
+
93
+ def dry_run_result(old_key, new_key, old_res, new_res)
94
+ pre_env = @reader.read(old_key)
95
+ {
96
+ "protocol" => PROTOCOL, "ok" => true, "dry_run" => true,
97
+ "from_key" => old_key, "to_key" => new_key,
98
+ "from_path" => old_res.path, "to_path" => new_res.path,
99
+ "uid" => pre_env.uid
100
+ }
101
+ end
102
+
103
+ def success_result(old_key, new_key, old_res, new_res, envelope)
104
+ {
105
+ "protocol" => PROTOCOL, "ok" => true,
106
+ "from_key" => old_key, "to_key" => new_key,
107
+ "from_path" => old_res.path, "to_path" => new_res.path,
108
+ "uid" => envelope.uid,
109
+ "envelope" => envelope.to_h_for_wire
110
+ }
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end
117
+
118
+ Textus::Application::UseCase.register(:mv, Textus::Application::Write::Mv, caps: :write)
@@ -0,0 +1,96 @@
1
+ module Textus
2
+ module Application
3
+ module Write
4
+ # Single-pass publish use case: dispatches polymorphically to each
5
+ # entry's `publish_via` method. Derived entries materialize their body
6
+ # via Materializer; Nested entries fan out via publish_each; Leaf and
7
+ # Intake entries copy their stored body to publish_to targets. The
8
+ # Publish layer owns wiring (context, accumulation) but not per-kind
9
+ # logic.
10
+ #
11
+ # Return shape: { "protocol", "built", "published_leaves" }
12
+ module Publish
13
+ def self.call(*, session:, ctx:, caps:, **)
14
+ Impl.new(
15
+ ctx: ctx, caps: caps,
16
+ rpc: session.rpc,
17
+ session: session,
18
+ hook_context: session.hook_context
19
+ ).call(*, **)
20
+ end
21
+
22
+ class Impl
23
+ def initialize(ctx:, caps:, rpc:, session:, hook_context:)
24
+ @ctx = ctx
25
+ @caps = caps
26
+ @manifest = caps.manifest
27
+ @file_store = caps.file_store
28
+ @events = caps.events
29
+ @root = caps.root
30
+ @rpc = rpc
31
+ @session = session
32
+ @hook_context = hook_context
33
+ end
34
+
35
+ def call(prefix: nil)
36
+ built = []
37
+ leaves = []
38
+ context = build_context
39
+
40
+ @manifest.data.entries.each do |mentry|
41
+ next if prefix && !entry_matches_prefix?(mentry, prefix)
42
+
43
+ result = mentry.publish_via(context, prefix: prefix)
44
+ next if result.nil?
45
+
46
+ case result[:kind]
47
+ when :built then built << result[:value]
48
+ when :leaves then leaves.concat(result[:value])
49
+ end
50
+ end
51
+
52
+ { "protocol" => Textus::PROTOCOL, "built" => built, "published_leaves" => leaves }
53
+ end
54
+
55
+ private
56
+
57
+ def build_context
58
+ Textus::Manifest::Entry::Base::PublishContext.new(
59
+ repo_root: File.dirname(@root),
60
+ manifest: @manifest,
61
+ file_store: @file_store,
62
+ root: @root,
63
+ caps: @caps,
64
+ rpc: @rpc,
65
+ session: @session,
66
+ ctx: @ctx,
67
+ bus: @events,
68
+ hook_context: @hook_context,
69
+ reader: reader,
70
+ emit: ->(event, **payload) { @events.publish(event, ctx: @hook_context, **payload) },
71
+ )
72
+ end
73
+
74
+ # Whether the entry should be processed for the given prefix filter.
75
+ def entry_matches_prefix?(mentry, prefix)
76
+ return true unless prefix
77
+
78
+ case mentry
79
+ when Textus::Manifest::Entry::Nested
80
+ mentry.key.start_with?(prefix) ||
81
+ prefix.start_with?("#{mentry.key}.")
82
+ else
83
+ mentry.key.start_with?(prefix)
84
+ end
85
+ end
86
+
87
+ def reader
88
+ @reader ||= Textus::Application::Read::Get::Impl.new(ctx: @ctx, caps: @caps)
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
95
+
96
+ Textus::Application::UseCase.register(:publish, Textus::Application::Write::Publish, caps: :write)