samagotchi 0.188.0 → 0.189.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 +42 -1
- data/docs/architecture.md +5 -3
- data/docs/bundle-authoring.md +1 -1
- data/docs/bundles.md +15 -0
- data/docs/cli.md +23 -5
- data/docs/guardrails.md +3 -2
- data/docs/internals/bundles.md +3 -3
- data/docs/internals/pages.md +65 -18
- data/docs/internals/session-lifecycle.md +19 -6
- data/docs/internals/web-frontend.md +3 -3
- data/docs/internals/web-push.md +11 -5
- data/docs/pages.md +68 -15
- data/docs/peers.md +3 -0
- data/docs/plugins.md +25 -1
- data/docs/releasing.md +1 -1
- data/docs/scheduling.md +71 -8
- data/docs/sessions.md +4 -4
- data/docs/testing.md +1 -1
- data/lib/samagotchi/bundle_manifest.rb +34 -5
- data/lib/samagotchi/bundles/schedules/manifest.yml +11 -0
- data/lib/samagotchi/bundles/schedules/scripts/schedules.rb +159 -0
- data/lib/samagotchi/bundles/system/manifest.yml +3 -3
- data/lib/samagotchi/bundles/system/self_map.md +2 -2
- data/lib/samagotchi/bundles/system/skill_pages.md +9 -4
- data/lib/samagotchi/installed_bundles/manifest.rb +8 -1
- data/lib/samagotchi/memory_bundle/asset_installer.rb +3 -2
- data/lib/samagotchi/memory_bundle/builder.rb +1 -0
- data/lib/samagotchi/memory_bundle/installed_copy.rb +1 -1
- data/lib/samagotchi/page_command.rb +9 -6
- data/lib/samagotchi/pages/bundled.rb +83 -0
- data/lib/samagotchi/pages/launch.rb +14 -2
- data/lib/samagotchi/pages/runner.rb +7 -2
- data/lib/samagotchi/pages/runtime.rb +83 -0
- data/lib/samagotchi/pages/store.rb +18 -5
- data/lib/samagotchi/pages.rb +47 -3
- data/lib/samagotchi/peer_continue.rb +14 -8
- data/lib/samagotchi/run_options.rb +1 -1
- data/lib/samagotchi/schedule_command.rb +79 -37
- data/lib/samagotchi/schedule_display.rb +69 -0
- data/lib/samagotchi/schedules/busy_part.rb +146 -0
- data/lib/samagotchi/schedules/edit_part.rb +120 -0
- data/lib/samagotchi/schedules/history_part.rb +51 -0
- data/lib/samagotchi/schedules/listing_part.rb +52 -0
- data/lib/samagotchi/schedules/notices_part.rb +116 -0
- data/lib/samagotchi/schedules/protection_part.rb +103 -0
- data/lib/samagotchi/schedules/recurrence.rb +103 -0
- data/lib/samagotchi/schedules.rb +134 -330
- data/lib/samagotchi/session_access/local.rb +9 -1
- data/lib/samagotchi/session_access/remote.rb +2 -1
- data/lib/samagotchi/session_chain/delete.rb +7 -5
- data/lib/samagotchi/session_lifecycle/allowed.rb +2 -1
- data/lib/samagotchi/session_lifecycle.rb +3 -2
- data/lib/samagotchi/session_manager/removal.rb +16 -9
- data/lib/samagotchi/session_protection.rb +99 -0
- data/lib/samagotchi/session_retention.rb +21 -6
- data/lib/samagotchi/sessions_command.rb +4 -0
- data/lib/samagotchi/testing/boundary.rb +13 -0
- data/lib/samagotchi/tools/cancel_schedule.rb +5 -2
- data/lib/samagotchi/turn_outcome.rb +41 -0
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/page_routes.rb +13 -8
- data/lib/samagotchi/web/public/app.js +12 -18
- data/lib/samagotchi/web/public/index.html +11 -2
- data/lib/samagotchi/web/public/owner_claim.js +7 -5
- data/lib/samagotchi/web/public/page_links.js +1 -1
- data/lib/samagotchi/web/public/page_view.js +8 -5
- data/lib/samagotchi/web/public/pages.css +9 -2
- data/lib/samagotchi/web/public/pages_group.js +21 -19
- data/lib/samagotchi/web/public/pages_list.js +73 -0
- data/lib/samagotchi/web/public/pages_model.js +54 -0
- data/lib/samagotchi/web/public/pages_wiring.js +66 -0
- data/lib/samagotchi/web/public/views.js +77 -23
- data/lib/samagotchi/web/push/notifier.rb +4 -3
- data/lib/samagotchi/web/server.rb +3 -1
- data/lib/samagotchi/web/session_hub.rb +64 -19
- metadata +17 -1
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "date"
|
|
4
|
+
require "time"
|
|
5
|
+
|
|
6
|
+
module Samagotchi
|
|
7
|
+
class Schedules
|
|
8
|
+
# The recurrence parsing (docs/scheduling.md, Recurrence): the class
|
|
9
|
+
# methods `chi schedule add` and the schedule tools build a
|
|
10
|
+
# recurrence with, and the local-clock helpers the next-due math uses.
|
|
11
|
+
# They raise Schedules::Usage (schedules.rb).
|
|
12
|
+
|
|
13
|
+
# A recurrence from the CLI's flags or the tool's arguments. Blank strings
|
|
14
|
+
# (what a model sends for the fields it did not use) count as absent.
|
|
15
|
+
# @return [Hash] {kind:, ...}
|
|
16
|
+
# @raise [Usage] none or more than one kind given, or an interval that is
|
|
17
|
+
# not a positive amount of time
|
|
18
|
+
def self.recurrence(every: nil, weekday: nil, time: nil, date: nil)
|
|
19
|
+
every = nil if every.to_s.strip.empty?
|
|
20
|
+
weekday = nil if weekday.to_s.strip.empty?
|
|
21
|
+
time = nil if time.to_s.strip.empty?
|
|
22
|
+
date = nil if date.to_s.strip.empty?
|
|
23
|
+
|
|
24
|
+
kinds = [every, weekday, date].compact
|
|
25
|
+
raise Usage, "a schedule needs one of every, weekday or date" if kinds.empty?
|
|
26
|
+
raise Usage, "give one of every, weekday or date, not more" if kinds.size > 1
|
|
27
|
+
|
|
28
|
+
if every
|
|
29
|
+
raise Usage, "time is only for a weekday schedule" if time && !weekday
|
|
30
|
+
|
|
31
|
+
interval = every.to_s.strip
|
|
32
|
+
raise Usage, "every needs an interval like 30m, 2h or 1d, got #{every}" unless interval.match?(/\A\d+[smhd]?\z/)
|
|
33
|
+
|
|
34
|
+
seconds = interval_seconds(interval)
|
|
35
|
+
raise Usage, "every must be at least 1s, got #{every}" if seconds.nil? || seconds.zero?
|
|
36
|
+
|
|
37
|
+
{ kind: "every", interval: interval }
|
|
38
|
+
elsif weekday
|
|
39
|
+
raise Usage, "weekday needs time HH:MM" if time.nil?
|
|
40
|
+
|
|
41
|
+
day = weekday.to_s.strip
|
|
42
|
+
raise Usage, "weekday must be 1 (Mon) to 7 (Sun), got #{weekday}" unless day.match?(/\A[1-7]\z/)
|
|
43
|
+
|
|
44
|
+
{ kind: "weekday", weekday: day.to_i, time: time.to_s.strip }
|
|
45
|
+
else
|
|
46
|
+
{ kind: "date", at: local_moment(*parse_local(date)).utc.iso8601 }
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# The length of an interval in seconds; nil for something that is not an
|
|
51
|
+
# interval, and nil for zero so a `0m` schedule can never fire every tick.
|
|
52
|
+
def self.interval_seconds(interval)
|
|
53
|
+
match = interval.to_s.strip.match(/\A(\d+)(s|m|h|d)?\z/)
|
|
54
|
+
return nil unless match
|
|
55
|
+
|
|
56
|
+
seconds = { "s" => 1, "m" => 60, "h" => 3600, "d" => 86_400, nil => 60 }[match[2]] * match[1].to_i
|
|
57
|
+
seconds.positive? ? seconds : nil
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def self.parse_clock(time)
|
|
61
|
+
match = time.to_s.strip.match(/\A(\d{1,2}):(\d{1,2})\z/)
|
|
62
|
+
raise Usage, "time must be HH:MM, got #{time}" unless match
|
|
63
|
+
|
|
64
|
+
hour = match[1].to_i
|
|
65
|
+
minute = match[2].to_i
|
|
66
|
+
raise Usage, "time must be HH:MM, got #{time}" unless (0..23).cover?(hour) && (0..59).cover?(minute)
|
|
67
|
+
|
|
68
|
+
[hour, minute]
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def self.parse_local(text)
|
|
72
|
+
match = text.to_s.strip.match(/\A(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{1,2}):(\d{2}))?\z/)
|
|
73
|
+
raise Usage, "date must be YYYY-MM-DD or YYYY-MM-DDTHH:MM, got #{text}" unless match
|
|
74
|
+
|
|
75
|
+
year = match[1].to_i
|
|
76
|
+
month = match[2].to_i
|
|
77
|
+
day = match[3].to_i
|
|
78
|
+
hour = match[4] ? match[4].to_i : 0
|
|
79
|
+
minute = match[5] ? match[5].to_i : 0
|
|
80
|
+
unless Date.valid_date?(year, month, day) && (0..23).cover?(hour) && (0..59).cover?(minute)
|
|
81
|
+
raise Usage, "date must be a real date, got #{text}"
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
[year, month, day, hour, minute]
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# A local moment that exists. When the requested minute falls in a
|
|
88
|
+
# spring-forward gap, the first valid minute whose wall clock is at or
|
|
89
|
+
# after it.
|
|
90
|
+
def self.local_moment(year, month, day, hour, minute)
|
|
91
|
+
moment = Time.local(year, month, day, hour, minute)
|
|
92
|
+
return moment if moment.hour == hour && moment.min == minute
|
|
93
|
+
|
|
94
|
+
wanted = (hour * 60) + minute
|
|
95
|
+
day_start = Time.local(year, month, day, 0, 0)
|
|
96
|
+
1440.times do |step|
|
|
97
|
+
probe = day_start + (step * 60)
|
|
98
|
+
return probe if (probe.hour * 60) + probe.min >= wanted
|
|
99
|
+
end
|
|
100
|
+
moment
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|