rails_tool_views 0.2.0 → 0.3.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 +8 -0
- data/app/helpers/rails_tool_views/surfaces_helper.rb +3 -0
- data/app/models/rails_tool_views/agent_interaction.rb +2 -0
- data/app/models/rails_tool_views/surface.rb +17 -1
- data/app/views/rails_tool_views/surfaces/_closed.html.erb +2 -0
- data/app/views/rails_tool_views/surfaces/_surface.html.erb +1 -1
- data/db/migrate/20261019000000_add_rails_tool_views_lifecycle.rb +23 -0
- data/lib/generators/rails_tool_views/install/install_generator.rb +1 -0
- data/lib/generators/rails_tool_views/install/templates/add_rails_tool_views_lifecycle.rb +23 -0
- data/lib/rails_tool_views/core.rb +6 -1
- data/lib/rails_tool_views/lifecycle.rb +92 -0
- data/lib/rails_tool_views/runtime.rb +33 -17
- data/lib/rails_tool_views/version.rb +1 -1
- data/lib/rails_tool_views.rb +1 -0
- metadata +6 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5f0b45e8093744ab3053cb621e1b8118ef6c618b98f907e8e88b9b16f5b36fba
|
|
4
|
+
data.tar.gz: '05959be24f98969c883260f0b06cef6815d812393bf7c250d0d1dea1cc552e7b'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 57ab0c782013453cc510f47402fcdae2b934a06fe69760b45411466b543c851d7b8b84e653bcef7824f3267f97319783e712754b7c321b9bd844826645f94afe
|
|
7
|
+
data.tar.gz: 2d741cf1b44e389bb3cc7a00bcf1de0da70ef3377077950fed1c4a166d9a62d7ac3ae339550779616b2c414ed23b8612531b2d2fda01f10e462cbc40d7ba6b5b
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.3.0] - 2026-10-19
|
|
4
|
+
|
|
5
|
+
- Opt-in scoped `purge_closed` preview/apply with deadlines, bounded batches, atomic receipt cleanup and durable correlation tombstones. Host business records stay intact.
|
|
6
|
+
|
|
7
|
+
- Add explicit host-authorized `close` and `abandon`, with read-only closed rendering, preserved exact action replay and first-termination retention deadlines.
|
|
8
|
+
- Add lifecycle snapshot metadata and an additive migration. Stop old workers before upgrading; rollback refuses once a Surface was closed.
|
|
9
|
+
- Coordinate delivery claims and lifecycle changes through the Surface lock while keeping callbacks outside transactions. Quarantine ambiguous lease takeovers and legacy multiple-attempt histories from cleanup.
|
|
10
|
+
|
|
3
11
|
## [0.2.0] - 2026-10-18
|
|
4
12
|
|
|
5
13
|
- Add `rails_tool_views:component NAME` for a Partial, closed registration schemas and a Minitest scaffold. Component and action policies deny by default. Existing paths, unsafe names and symlink escapes are refused before writing.
|
|
@@ -5,6 +5,8 @@ module RailsToolViews
|
|
|
5
5
|
# Engine-owned copy. Translate or reword any of it under rails_tool_views.surface.<key>.
|
|
6
6
|
TEXT = {
|
|
7
7
|
page_title: "Interactive view", page_error_title: "Unable to complete this request", reload: "Reload saved view",
|
|
8
|
+
closed_title: "View closed.", abandoned_title: "View abandoned.", closed_help: "Saved actions are read-only. Start a new view to continue.",
|
|
9
|
+
agent_abandoned: "AI follow-up abandoned by the application.",
|
|
8
10
|
ready: "View ready.", saved: "Changes saved.", revision: "Saved revision %{revision}",
|
|
9
11
|
saving: "Saving changes…", save_failed: "Changes could not be saved. Review the message and try again.",
|
|
10
12
|
agent_pending: "AI follow-up pending.", agent_completed: "AI follow-up completed.",
|
|
@@ -56,6 +58,7 @@ module RailsToolViews
|
|
|
56
58
|
end
|
|
57
59
|
|
|
58
60
|
def rails_tool_views_body(surface, definition, error: nil) # :nodoc:
|
|
61
|
+
return render(partial: "rails_tool_views/surfaces/closed", formats: [:html], locals: { surface: surface }) if surface.closed?
|
|
59
62
|
html = if definition.partial
|
|
60
63
|
render(partial: definition.partial, locals: { props: surface.props, state: surface.state, surface: surface, error: error })
|
|
61
64
|
else
|
|
@@ -6,6 +6,8 @@ module RailsToolViews
|
|
|
6
6
|
belongs_to :surface
|
|
7
7
|
belongs_to :action_execution
|
|
8
8
|
self.filter_attributes += %i[payload]
|
|
9
|
+
# Rails 7.2 cannot infer a SQLite boolean default written by Rails 8.1.
|
|
10
|
+
attribute :delivery_uncertain, :boolean, default: false
|
|
9
11
|
attribute :payload, RedactedJson.new
|
|
10
12
|
# Returns the stable host deduplication key across delivery retries.
|
|
11
13
|
def delivery_key
|
|
@@ -15,9 +15,25 @@ module RailsToolViews
|
|
|
15
15
|
def dom_id
|
|
16
16
|
"rails_tool_views_surface_#{id}"
|
|
17
17
|
end
|
|
18
|
+
# True once the host closes or abandons the view. Closed views cannot reopen.
|
|
19
|
+
def closed?
|
|
20
|
+
closed_at.present?
|
|
21
|
+
end
|
|
22
|
+
# True when payload cleanup has retained only the durable tombstone.
|
|
23
|
+
def purged?
|
|
24
|
+
purged_at.present?
|
|
25
|
+
end
|
|
26
|
+
# Returns the lifecycle independently of domain record or delivery status.
|
|
27
|
+
def lifecycle_status
|
|
28
|
+
return "purged" if purged?
|
|
29
|
+
return "abandoned" if abandoned_at
|
|
30
|
+
closed? ? "closed" : "active"
|
|
31
|
+
end
|
|
18
32
|
# Returns the UI projection; it is not a permission grant.
|
|
19
33
|
def snapshot
|
|
20
|
-
{ id: id, component: component_key, component_digest: component_digest, props: props, state: state, revision: revision
|
|
34
|
+
{ id: id, component: component_key, component_digest: component_digest, props: props, state: state, revision: revision,
|
|
35
|
+
lifecycle: { status: lifecycle_status, closed_at: closed_at&.iso8601(6),
|
|
36
|
+
retain_until: retain_until&.iso8601(6), purged_at: purged_at&.iso8601(6) } }
|
|
21
37
|
end
|
|
22
38
|
end
|
|
23
39
|
end
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
</p>
|
|
9
9
|
<% interaction = surface.agent_interactions.order(:id).last %>
|
|
10
10
|
<% if interaction && interaction.status != "skipped" %>
|
|
11
|
-
<p role="status"><%= rails_tool_views_text({ "pending" => :agent_pending, "delivering" => :agent_pending, "completed" => :agent_completed, "failed" => :agent_failed }.fetch(interaction.status, :agent_unavailable)) %></p>
|
|
11
|
+
<p role="status"><%= rails_tool_views_text({ "pending" => :agent_pending, "delivering" => :agent_pending, "completed" => :agent_completed, "failed" => :agent_failed, "abandoned" => :agent_abandoned }.fetch(interaction.status, :agent_unavailable)) %></p>
|
|
12
12
|
<% if interaction.status == "failed" %>
|
|
13
13
|
<%= form_with url: rails_tool_views_routes.surface_continuation_path(surface, interaction_id: interaction.id), method: :post do %>
|
|
14
14
|
<button type="submit"><%= rails_tool_views_text(:agent_retry) %></button>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
class AddRailsToolViewsLifecycle < ActiveRecord::Migration[7.2]
|
|
3
|
+
def up
|
|
4
|
+
add_column :rails_tool_views_surfaces, :closed_at, :datetime
|
|
5
|
+
add_column :rails_tool_views_surfaces, :abandoned_at, :datetime
|
|
6
|
+
add_column :rails_tool_views_surfaces, :retain_until, :datetime
|
|
7
|
+
add_column :rails_tool_views_surfaces, :purged_at, :datetime
|
|
8
|
+
add_index :rails_tool_views_surfaces, [:tenant_ref, :actor_ref, :closed_at], name: "index_rails_tool_views_retention_scope"
|
|
9
|
+
add_column :rails_tool_views_agent_interactions, :delivery_uncertain, :boolean, default: false, null: false
|
|
10
|
+
# Old rows do not distinguish explicit failed retries from lease takeovers.
|
|
11
|
+
# Preserve uncertainty instead of assuming an old callback has stopped.
|
|
12
|
+
execute "UPDATE rails_tool_views_agent_interactions SET delivery_uncertain = #{connection.quote(true)} WHERE attempts > 1 OR status = 'delivering'"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def down
|
|
16
|
+
if select_value("SELECT COUNT(*) FROM rails_tool_views_surfaces WHERE closed_at IS NOT NULL").to_i.positive?
|
|
17
|
+
raise ActiveRecord::IrreversibleMigration, "Closed or purged Surfaces cannot be safely reopened by an older runtime. Restore a pre-upgrade backup instead."
|
|
18
|
+
end
|
|
19
|
+
remove_column :rails_tool_views_agent_interactions, :delivery_uncertain
|
|
20
|
+
remove_index :rails_tool_views_surfaces, name: "index_rails_tool_views_retention_scope"
|
|
21
|
+
%i[closed_at abandoned_at retain_until purged_at].each { |column| remove_column :rails_tool_views_surfaces, column }
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -12,6 +12,7 @@ module RailsToolViews
|
|
|
12
12
|
end
|
|
13
13
|
def install
|
|
14
14
|
migration_template "create_rails_tool_views.rb", "db/migrate/create_rails_tool_views.rb"
|
|
15
|
+
migration_template "add_rails_tool_views_lifecycle.rb", "db/migrate/add_rails_tool_views_lifecycle.rb"
|
|
15
16
|
template "rails_tool_views.rb", "config/initializers/rails_tool_views.rb"
|
|
16
17
|
route 'mount RailsToolViews::Engine => "/rails_tool_views", as: :rails_tool_views'
|
|
17
18
|
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
class AddRailsToolViewsLifecycle < ActiveRecord::Migration[7.2]
|
|
3
|
+
def up
|
|
4
|
+
add_column :rails_tool_views_surfaces, :closed_at, :datetime
|
|
5
|
+
add_column :rails_tool_views_surfaces, :abandoned_at, :datetime
|
|
6
|
+
add_column :rails_tool_views_surfaces, :retain_until, :datetime
|
|
7
|
+
add_column :rails_tool_views_surfaces, :purged_at, :datetime
|
|
8
|
+
add_index :rails_tool_views_surfaces, [:tenant_ref, :actor_ref, :closed_at], name: "index_rails_tool_views_retention_scope"
|
|
9
|
+
add_column :rails_tool_views_agent_interactions, :delivery_uncertain, :boolean, default: false, null: false
|
|
10
|
+
# Old rows do not distinguish explicit failed retries from lease takeovers.
|
|
11
|
+
# Preserve uncertainty instead of assuming an old callback has stopped.
|
|
12
|
+
execute "UPDATE rails_tool_views_agent_interactions SET delivery_uncertain = #{connection.quote(true)} WHERE attempts > 1 OR status = 'delivering'"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def down
|
|
16
|
+
if select_value("SELECT COUNT(*) FROM rails_tool_views_surfaces WHERE closed_at IS NOT NULL").to_i.positive?
|
|
17
|
+
raise ActiveRecord::IrreversibleMigration, "Closed or purged Surfaces cannot be safely reopened by an older runtime. Restore a pre-upgrade backup instead."
|
|
18
|
+
end
|
|
19
|
+
remove_column :rails_tool_views_agent_interactions, :delivery_uncertain
|
|
20
|
+
remove_index :rails_tool_views_surfaces, name: "index_rails_tool_views_retention_scope"
|
|
21
|
+
%i[closed_at abandoned_at retain_until purged_at].each { |column| remove_column :rails_tool_views_surfaces, column }
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -13,6 +13,11 @@ module RailsToolViews
|
|
|
13
13
|
MESSAGES = {
|
|
14
14
|
"NOT_FOUND" => "This view is unavailable.", "NOT_ALLOWED" => "You do not have permission to use this view.",
|
|
15
15
|
"CONFLICT" => "This view changed. Refresh to continue.", "INVALID_ARGUMENTS" => "Check the submitted values and try again.",
|
|
16
|
+
"SURFACE_CLOSED" => "This view is closed. Its saved actions cannot be changed.",
|
|
17
|
+
"SURFACE_PURGED" => "This view has been cleaned up and cannot be restored.",
|
|
18
|
+
"LIFECYCLE_BUSY" => "This view has unfinished or uncertain delivery. Resolve it before closing.",
|
|
19
|
+
"INVALID_RETENTION_REQUEST" => "Choose an explicit past cutoff and a batch size from 1 to 1000.",
|
|
20
|
+
"INVALID_RETENTION_WINDOW" => "Choose a future retention deadline or keep this view indefinitely.",
|
|
16
21
|
"VALIDATION_FAILED" => "Check the highlighted fields and try again.",
|
|
17
22
|
"INCOMPATIBLE_COMPONENT" => "This view's contract changed. Ask the application owner to migrate or recreate it.",
|
|
18
23
|
"RENDER_FAILED" => "This view cannot be rendered. Your saved state is preserved.",
|
|
@@ -249,7 +254,7 @@ module RailsToolViews
|
|
|
249
254
|
# Process-local host hooks, request limits, and delivery settings.
|
|
250
255
|
class Configuration
|
|
251
256
|
attr_accessor :scope_resolver, :agent_adapter, :max_payload_bytes, :max_depth, :max_catalog_components, :max_actions_per_minute, :auto_deliver,
|
|
252
|
-
:parent_controller, :delivery_lease
|
|
257
|
+
:parent_controller, :delivery_lease, :retention_policy
|
|
253
258
|
# Initializes conservative request limits with no host identity or agent adapter.
|
|
254
259
|
def initialize
|
|
255
260
|
@max_payload_bytes, @max_depth, @max_catalog_components, @max_actions_per_minute = 32_768, 16, 20, 60
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module RailsToolViews
|
|
3
|
+
class << self
|
|
4
|
+
# Closes a view after host authorization. Outstanding continuation work blocks
|
|
5
|
+
# closure. nil retain_until keeps data indefinitely; the first closure wins.
|
|
6
|
+
def close(id, scope:, retain_until: nil)
|
|
7
|
+
finish_surface(id, scope: scope, retain_until: retain_until, abandon: false)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
# Explicitly abandons pending/failed continuation work before closing a view.
|
|
11
|
+
# In-flight or historically uncertain delivery is never abandoned implicitly.
|
|
12
|
+
def abandon(id, scope:, retain_until: nil)
|
|
13
|
+
finish_surface(id, scope: scope, retain_until: retain_until, abandon: true)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Scrubs eligible closed payloads in one bounded batch, preserving replay
|
|
17
|
+
# tombstones. Requires an explicit scope, cutoff and host retention policy.
|
|
18
|
+
# Defaults to a read-only preview. Each applied Surface commits atomically.
|
|
19
|
+
def purge_closed(scope:, closed_before:, batch_size: 100, dry_run: true)
|
|
20
|
+
check_scope!(scope)
|
|
21
|
+
valid_time = closed_before.is_a?(Time) || closed_before.is_a?(ActiveSupport::TimeWithZone)
|
|
22
|
+
unless valid_time && closed_before <= Time.current && batch_size.is_a?(Integer) && batch_size.between?(1, 1000) && [true, false].any? { |v| dry_run.equal?(v) }
|
|
23
|
+
raise Error.new("INVALID_RETENTION_REQUEST")
|
|
24
|
+
end
|
|
25
|
+
policy = configuration.retention_policy
|
|
26
|
+
raise Error.new("NOT_ALLOWED", status: 403) unless policy.respond_to?(:call)
|
|
27
|
+
now = Time.current
|
|
28
|
+
candidates = Surface.where(actor_ref: scope.actor, tenant_ref: scope.tenant, purged_at: nil)
|
|
29
|
+
.where("closed_at < ? AND retain_until <= ?", closed_before, now).order(:closed_at, :id).limit(batch_size).pluck(:id)
|
|
30
|
+
counts = { examined: 0, eligible: 0, purged: 0, protected: 0, dry_run: dry_run }
|
|
31
|
+
candidates.each do |id|
|
|
32
|
+
surface = Surface.find_by(id: id)
|
|
33
|
+
next unless surface
|
|
34
|
+
surface.with_lock do
|
|
35
|
+
counts[:examined] += 1
|
|
36
|
+
eligible = exact_match?(surface, actor_ref: scope.actor, tenant_ref: scope.tenant) &&
|
|
37
|
+
!surface.purged? && surface.closed? && surface.closed_at < closed_before &&
|
|
38
|
+
surface.retain_until && surface.retain_until <= now
|
|
39
|
+
if eligible
|
|
40
|
+
request = access(scope, :purge, surface: surface, props: surface.props, context_ref: surface.context_ref)
|
|
41
|
+
eligible = policy.call(request) == true && !protected_interactions?(surface, abandon: false)
|
|
42
|
+
end
|
|
43
|
+
unless eligible
|
|
44
|
+
counts[:protected] += 1
|
|
45
|
+
next
|
|
46
|
+
end
|
|
47
|
+
counts[:eligible] += 1
|
|
48
|
+
next if dry_run
|
|
49
|
+
# The Surface lock excludes action commits, delivery claims and other
|
|
50
|
+
# cleanup workers. Only known terminal children are removed together.
|
|
51
|
+
surface.agent_interactions.delete_all
|
|
52
|
+
surface.action_executions.delete_all
|
|
53
|
+
surface.update!(props: {}, state: {}, context_ref: nil, purged_at: now)
|
|
54
|
+
counts[:purged] += 1
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
counts
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
private
|
|
61
|
+
def finish_surface(id, scope:, retain_until:, abandon:)
|
|
62
|
+
validate_retention_deadline!(retain_until, future: false)
|
|
63
|
+
surface = restore(id, scope: scope)
|
|
64
|
+
surface.with_lock do
|
|
65
|
+
ensure_not_purged!(surface)
|
|
66
|
+
component = compatible_component!(surface)
|
|
67
|
+
component.authorize!(access(scope, :read, surface: surface, props: surface.props, context_ref: surface.context_ref))
|
|
68
|
+
component.authorize!(access(scope, abandon ? :abandon : :close, surface: surface, props: surface.props, context_ref: surface.context_ref))
|
|
69
|
+
next if surface.closed?
|
|
70
|
+
validate_retention_deadline!(retain_until, future: true)
|
|
71
|
+
interactions = surface.agent_interactions
|
|
72
|
+
raise Error.new("LIFECYCLE_BUSY", status: 409) if protected_interactions?(surface, abandon: abandon)
|
|
73
|
+
if abandon
|
|
74
|
+
interactions.where(status: %w[pending failed]).update_all(status: "abandoned", claimed_at: nil, error_code: nil, updated_at: Time.current)
|
|
75
|
+
end
|
|
76
|
+
now = Time.current
|
|
77
|
+
surface.update!(closed_at: now, abandoned_at: abandon ? now : nil, retain_until: retain_until, revision: surface.revision + 1)
|
|
78
|
+
end
|
|
79
|
+
surface
|
|
80
|
+
end
|
|
81
|
+
def protected_interactions?(surface, abandon:)
|
|
82
|
+
interactions = surface.agent_interactions
|
|
83
|
+
allowed = abandon ? %w[completed skipped pending failed abandoned] : %w[completed skipped abandoned]
|
|
84
|
+
interactions.where(delivery_uncertain: true).exists? || interactions.where.not(status: allowed).exists?
|
|
85
|
+
end
|
|
86
|
+
def validate_retention_deadline!(deadline, future:)
|
|
87
|
+
return if deadline.nil?
|
|
88
|
+
valid_type = deadline.is_a?(Time) || deadline.is_a?(ActiveSupport::TimeWithZone)
|
|
89
|
+
raise Error.new("INVALID_RETENTION_WINDOW") unless valid_type && (!future || deadline > Time.current)
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
@@ -44,6 +44,7 @@ module RailsToolViews
|
|
|
44
44
|
# match may stand in for this scope's Surface, or a lookup could disclose
|
|
45
45
|
# another actor's or tenant's record.
|
|
46
46
|
raise Error.new("NOT_FOUND", status: 404) unless surface && exact_match?(surface, id: id.to_s, actor_ref: scope.actor, tenant_ref: scope.tenant)
|
|
47
|
+
ensure_not_purged!(surface)
|
|
47
48
|
component = compatible_component!(surface)
|
|
48
49
|
component.authorize!(access(scope, :read, surface: surface, props: surface.props, context_ref: surface.context_ref))
|
|
49
50
|
surface
|
|
@@ -62,6 +63,7 @@ module RailsToolViews
|
|
|
62
63
|
request_digest = Data.digest(action: definition.key, arguments: arguments, base_revision: base_revision)
|
|
63
64
|
result = nil
|
|
64
65
|
surface.with_lock do
|
|
66
|
+
ensure_not_purged!(surface)
|
|
65
67
|
compatible_component!(surface).authorize!(access(scope, :read, surface: surface, props: surface.props, context_ref: surface.context_ref))
|
|
66
68
|
request = access(scope, :action, surface: surface, props: surface.props, action: definition.key,
|
|
67
69
|
arguments: arguments, context_ref: surface.context_ref)
|
|
@@ -74,6 +76,7 @@ module RailsToolViews
|
|
|
74
76
|
result = prior.result.symbolize_keys
|
|
75
77
|
next
|
|
76
78
|
end
|
|
79
|
+
raise Error.new("SURFACE_CLOSED", status: 410) if surface.closed?
|
|
77
80
|
raise Error.new("CONFLICT", status: 409) unless surface.revision == base_revision
|
|
78
81
|
if surface.action_executions.where("created_at >= ?", 1.minute.ago).count >= configuration.max_actions_per_minute
|
|
79
82
|
raise Error.new("RATE_LIMITED", status: 429)
|
|
@@ -114,25 +117,35 @@ module RailsToolViews
|
|
|
114
117
|
interaction = AgentInteraction.find_by(id: id)
|
|
115
118
|
raise Error.new("NOT_FOUND", status: 404) unless interaction
|
|
116
119
|
surface = restore(interaction.surface_id, scope: scope)
|
|
117
|
-
definition = compatible_component!(surface).actions.fetch(interaction.payload.fetch("action")) { raise Error.new("INCOMPATIBLE_COMPONENT", status: 422) }
|
|
118
|
-
arguments = definition.schema.validate!(interaction.payload.fetch("values"), code: "INVALID_ARGUMENTS")
|
|
119
|
-
request = access(scope, :action, surface: surface, props: surface.props, action: definition.key, arguments: arguments, context_ref: surface.context_ref)
|
|
120
|
-
raise Error.new("NOT_ALLOWED", status: 403) unless definition.policy&.call(request) == true
|
|
121
120
|
claimed = false
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
121
|
+
# Coordinate the claim with close/abandon/purge, using the same lock order
|
|
122
|
+
# as actions. Never hold a database transaction during the adapter call.
|
|
123
|
+
surface.with_lock do
|
|
124
|
+
ensure_not_purged!(surface)
|
|
125
|
+
component = compatible_component!(surface)
|
|
126
|
+
component.authorize!(access(scope, :read, surface: surface, props: surface.props, context_ref: surface.context_ref))
|
|
127
|
+
interaction.with_lock do
|
|
128
|
+
definition = component.actions.fetch(interaction.payload.fetch("action")) { raise Error.new("INCOMPATIBLE_COMPONENT", status: 422) }
|
|
129
|
+
arguments = definition.schema.validate!(interaction.payload.fetch("values"), code: "INVALID_ARGUMENTS")
|
|
130
|
+
request = access(scope, :action, surface: surface, props: surface.props, action: definition.key, arguments: arguments, context_ref: surface.context_ref)
|
|
131
|
+
raise Error.new("NOT_ALLOWED", status: 403) unless definition.policy&.call(request) == true
|
|
132
|
+
next if %w[completed skipped abandoned].include?(interaction.status)
|
|
133
|
+
raise Error.new("SURFACE_CLOSED", status: 410) if surface.closed?
|
|
134
|
+
if interaction.status == "delivering" && interaction.claimed_at && interaction.claimed_at > Time.current - configuration.delivery_lease
|
|
135
|
+
next
|
|
136
|
+
end
|
|
137
|
+
next if interaction.status == "failed" && !retry_failed
|
|
138
|
+
# Reclaiming a lease does not prove that the previous callback ended.
|
|
139
|
+
# This durable flag cannot be cleared by a stale worker's completion.
|
|
140
|
+
uncertain = interaction.delivery_uncertain? || interaction.status == "delivering"
|
|
141
|
+
if adapter.nil?
|
|
142
|
+
interaction.update!(status: "skipped", claimed_at: nil, delivery_uncertain: uncertain)
|
|
143
|
+
next
|
|
144
|
+
end
|
|
145
|
+
interaction.update!(status: "delivering", claimed_at: Time.current, attempts: interaction.attempts + 1,
|
|
146
|
+
error_code: nil, delivery_uncertain: uncertain)
|
|
147
|
+
claimed = true
|
|
133
148
|
end
|
|
134
|
-
interaction.update!(status: "delivering", claimed_at: Time.current, attempts: interaction.attempts + 1, error_code: nil)
|
|
135
|
-
claimed = true
|
|
136
149
|
end
|
|
137
150
|
return interaction.reload unless claimed
|
|
138
151
|
begin
|
|
@@ -190,6 +203,9 @@ module RailsToolViews
|
|
|
190
203
|
end
|
|
191
204
|
|
|
192
205
|
private
|
|
206
|
+
def ensure_not_purged!(surface)
|
|
207
|
+
raise Error.new("SURFACE_PURGED", status: 410) if surface.purged?
|
|
208
|
+
end
|
|
193
209
|
def check_scope!(scope)
|
|
194
210
|
raise Error.new("INVALID_SCOPE", status: 403) unless scope.is_a?(Scope)
|
|
195
211
|
end
|
data/lib/rails_tool_views.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rails_tool_views
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andy Wang
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-10-
|
|
11
|
+
date: 2026-10-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|
|
@@ -179,22 +179,26 @@ files:
|
|
|
179
179
|
- app/models/rails_tool_views/redacted_json.rb
|
|
180
180
|
- app/models/rails_tool_views/surface.rb
|
|
181
181
|
- app/views/layouts/rails_tool_views/application.html.erb
|
|
182
|
+
- app/views/rails_tool_views/surfaces/_closed.html.erb
|
|
182
183
|
- app/views/rails_tool_views/surfaces/_error.html.erb
|
|
183
184
|
- app/views/rails_tool_views/surfaces/_surface.html.erb
|
|
184
185
|
- app/views/rails_tool_views/surfaces/page.html.erb
|
|
185
186
|
- config/routes.rb
|
|
186
187
|
- db/migrate/20261010000000_create_rails_tool_views.rb
|
|
188
|
+
- db/migrate/20261019000000_add_rails_tool_views_lifecycle.rb
|
|
187
189
|
- lib/generators/rails_tool_views/component/component_generator.rb
|
|
188
190
|
- lib/generators/rails_tool_views/component/templates/component_test.rb
|
|
189
191
|
- lib/generators/rails_tool_views/component/templates/partial.html.erb
|
|
190
192
|
- lib/generators/rails_tool_views/component/templates/registration.rb
|
|
191
193
|
- lib/generators/rails_tool_views/install/install_generator.rb
|
|
194
|
+
- lib/generators/rails_tool_views/install/templates/add_rails_tool_views_lifecycle.rb
|
|
192
195
|
- lib/generators/rails_tool_views/install/templates/create_rails_tool_views.rb
|
|
193
196
|
- lib/generators/rails_tool_views/install/templates/rails_tool_views.rb
|
|
194
197
|
- lib/rails_tool_views.rb
|
|
195
198
|
- lib/rails_tool_views/adapters/ruby_llm.rb
|
|
196
199
|
- lib/rails_tool_views/core.rb
|
|
197
200
|
- lib/rails_tool_views/engine.rb
|
|
201
|
+
- lib/rails_tool_views/lifecycle.rb
|
|
198
202
|
- lib/rails_tool_views/runtime.rb
|
|
199
203
|
- lib/rails_tool_views/version.rb
|
|
200
204
|
homepage: https://github.com/yorzi/rails_tool_views
|