samagotchi 0.201.0 → 0.202.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 +57 -1
- data/docs/architecture.md +47 -7
- data/docs/cli.md +20 -1
- data/docs/configuration.md +2 -1
- data/docs/internals/bridge.md +4 -4
- data/docs/internals/engine.md +9 -6
- data/docs/internals/knowledge.md +26 -6
- data/docs/internals/objectives.md +2 -2
- data/docs/internals/pages.md +4 -2
- data/docs/internals/participants.md +1 -1
- data/docs/internals/peers.md +9 -7
- data/docs/internals/remote-sessions.md +6 -6
- data/docs/internals/session-lifecycle.md +37 -15
- data/docs/internals/web-frontend.md +18 -7
- data/docs/pages.md +6 -3
- data/docs/plugins.md +2 -2
- data/docs/scheduling.md +40 -12
- data/docs/sessions.md +48 -6
- data/docs/sub-agent.md +1 -2
- data/docs/testing.md +92 -8
- data/lib/samagotchi/answer_display.rb +3 -2
- data/lib/samagotchi/answer_tail.rb +4 -4
- data/lib/samagotchi/bridge/card_places.rb +5 -5
- data/lib/samagotchi/bridge/turn_accumulator.rb +5 -5
- data/lib/samagotchi/bridge/turn_drawings/synth.rb +5 -5
- data/lib/samagotchi/bridge/turn_drawings.rb +2 -2
- data/lib/samagotchi/bridge/turn_ranges.rb +15 -8
- data/lib/samagotchi/bridge.rb +5 -5
- data/lib/samagotchi/broadcast_command.rb +3 -3
- data/lib/samagotchi/bundle_command/try/trace.rb +18 -6
- data/lib/samagotchi/bundles/knowledge/embedder.rb +2 -0
- data/lib/samagotchi/bundles/knowledge/github.rb +19 -0
- data/lib/samagotchi/bundles/knowledge/manifest.yml +6 -6
- data/lib/samagotchi/bundles/knowledge/plugin.rb +26 -54
- data/lib/samagotchi/bundles/knowledge/refresh.rb +89 -14
- data/lib/samagotchi/bundles/knowledge/store.rb +36 -2
- data/lib/samagotchi/bundles/schedules/manifest.yml +2 -2
- data/lib/samagotchi/bundles/schedules/scripts/schedules.rb +24 -3
- data/lib/samagotchi/bundles/system/config_modification_protocol.md +1 -1
- data/lib/samagotchi/bundles/system/manifest.yml +3 -3
- data/lib/samagotchi/bundles/system/skill_pages.md +1 -1
- data/lib/samagotchi/chi_invocation.rb +1 -1
- data/lib/samagotchi/child_move.rb +6 -3
- data/lib/samagotchi/child_reports.rb +3 -3
- data/lib/samagotchi/children_status.rb +4 -2
- data/lib/samagotchi/client_id.rb +2 -2
- data/lib/samagotchi/compat.rb +4 -6
- data/lib/samagotchi/config.rb +3 -0
- data/lib/samagotchi/context_note.rb +1 -1
- data/lib/samagotchi/continue_intent.rb +1 -1
- data/lib/samagotchi/continue_offer.rb +2 -2
- data/lib/samagotchi/continue_repair_backoff.rb +71 -0
- data/lib/samagotchi/delivery.rb +1 -4
- data/lib/samagotchi/engine/participants.rb +1 -1
- data/lib/samagotchi/engine/recap.rb +1 -1
- data/lib/samagotchi/engine/turn_end.rb +1 -1
- data/lib/samagotchi/grants.rb +2 -2
- data/lib/samagotchi/guardrail_wiring.rb +1 -1
- data/lib/samagotchi/guardrails/approval.rb +3 -3
- data/lib/samagotchi/guardrails/pair_boundary.rb +3 -3
- data/lib/samagotchi/guardrails/participant_refusal.rb +2 -2
- data/lib/samagotchi/idle_recap.rb +6 -6
- data/lib/samagotchi/kernel_loop.rb +1 -1
- data/lib/samagotchi/last_turn.rb +9 -6
- data/lib/samagotchi/llm/chat_loop.rb +5 -2
- data/lib/samagotchi/mcp_command.rb +2 -2
- data/lib/samagotchi/memory_usage.rb +7 -6
- data/lib/samagotchi/note_command.rb +1 -1
- data/lib/samagotchi/note_delivery.rb +5 -5
- data/lib/samagotchi/objectives_backing.rb +3 -3
- data/lib/samagotchi/objectives_record.rb +2 -2
- data/lib/samagotchi/objectives_track.rb +2 -2
- data/lib/samagotchi/owner_lock.rb +28 -2
- data/lib/samagotchi/owner_prompt.rb +3 -3
- data/lib/samagotchi/pages/runtime.rb +9 -4
- data/lib/samagotchi/participant_revise.rb +6 -6
- data/lib/samagotchi/peer_receipts.rb +11 -4
- data/lib/samagotchi/plugin/side_question.rb +1 -1
- data/lib/samagotchi/recap_place.rb +5 -5
- data/lib/samagotchi/reply_for.rb +3 -3
- data/lib/samagotchi/reply_wait/liveness.rb +2 -2
- data/lib/samagotchi/reply_wait/poll.rb +3 -3
- data/lib/samagotchi/schedule_command.rb +1 -1
- data/lib/samagotchi/schedule_display.rb +4 -3
- data/lib/samagotchi/schedules/busy_part.rb +29 -5
- data/lib/samagotchi/schedules/history_part.rb +47 -7
- data/lib/samagotchi/schedules/marks_part.rb +52 -29
- data/lib/samagotchi/schedules/notices_part.rb +31 -4
- data/lib/samagotchi/schedules/protection_part.rb +69 -11
- data/lib/samagotchi/schedules/prune_part.rb +3 -2
- data/lib/samagotchi/schedules.rb +37 -47
- data/lib/samagotchi/send_command.rb +12 -12
- data/lib/samagotchi/session.rb +71 -59
- data/lib/samagotchi/session_access/contract.rb +7 -0
- data/lib/samagotchi/session_access/exchange.rb +1 -1
- data/lib/samagotchi/session_access/local.rb +9 -9
- data/lib/samagotchi/session_access/remote.rb +20 -24
- data/lib/samagotchi/session_access.rb +1 -1
- data/lib/samagotchi/session_chain/delete.rb +15 -8
- data/lib/samagotchi/session_chain/delete_preview.rb +3 -3
- data/lib/samagotchi/session_chain/links.rb +18 -4
- data/lib/samagotchi/session_chain/successor.rb +1 -1
- data/lib/samagotchi/session_chain.rb +3 -3
- data/lib/samagotchi/session_continue.rb +83 -32
- data/lib/samagotchi/session_inbox.rb +6 -17
- data/lib/samagotchi/session_inbox_delivery.rb +36 -13
- data/lib/samagotchi/session_lifecycle/allowed.rb +5 -5
- data/lib/samagotchi/session_manager/delegate_rule.rb +2 -2
- data/lib/samagotchi/session_manager/delivery.rb +13 -38
- data/lib/samagotchi/session_manager/emptiness.rb +35 -15
- data/lib/samagotchi/session_manager/lifecycle.rb +3 -2
- data/lib/samagotchi/session_manager/listing.rb +35 -10
- data/lib/samagotchi/session_manager/removal.rb +16 -0
- data/lib/samagotchi/session_manager/spawn.rb +9 -6
- data/lib/samagotchi/session_manager.rb +6 -4
- data/lib/samagotchi/session_messages.rb +602 -0
- data/lib/samagotchi/session_metrics.rb +7 -4
- data/lib/samagotchi/session_participants.rb +4 -4
- data/lib/samagotchi/session_protection.rb +16 -2
- data/lib/samagotchi/session_retention.rb +26 -12
- data/lib/samagotchi/session_row.rb +1 -1
- data/lib/samagotchi/session_stats.rb +17 -8
- data/lib/samagotchi/session_stores.rb +5 -0
- data/lib/samagotchi/session_transition.rb +3 -2
- data/lib/samagotchi/sessions_command.rb +55 -3
- data/lib/samagotchi/steer.rb +16 -50
- data/lib/samagotchi/storage_migration.rb +234 -0
- data/lib/samagotchi/terminal_ui/attached_loop.rb +3 -3
- data/lib/samagotchi/terminal_ui/formatting.rb +5 -5
- data/lib/samagotchi/terminal_ui/join_replay.rb +3 -3
- data/lib/samagotchi/terminal_ui/question_prompt.rb +2 -2
- data/lib/samagotchi/toolkit_report_command.rb +1 -1
- data/lib/samagotchi/tools/ask_session.rb +2 -2
- data/lib/samagotchi/tools/send_note.rb +1 -1
- data/lib/samagotchi/turn_context.rb +3 -3
- data/lib/samagotchi/turn_endings.rb +17 -0
- data/lib/samagotchi/turn_excerpts.rb +7 -4
- data/lib/samagotchi/turn_flow.rb +1 -1
- data/lib/samagotchi/turn_note.rb +30 -2
- data/lib/samagotchi/turn_origin.rb +7 -7
- data/lib/samagotchi/turn_outcome.rb +11 -0
- data/lib/samagotchi/turn_stages/verify_anchors.rb +4 -4
- data/lib/samagotchi/verify_fresh.rb +6 -6
- data/lib/samagotchi/verify_fresh_origin.rb +4 -4
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/app.rb +4 -3
- data/lib/samagotchi/web/last_ask.rb +2 -2
- data/lib/samagotchi/web/message_display.rb +12 -12
- data/lib/samagotchi/web/page_routes.rb +9 -3
- data/lib/samagotchi/web/participant_view.rb +4 -4
- data/lib/samagotchi/web/participants_admin.rb +1 -1
- data/lib/samagotchi/web/public/bubbles.js +1 -1
- data/lib/samagotchi/web/public/composer_fold.js +0 -3
- data/lib/samagotchi/web/public/composer_grip.js +0 -2
- data/lib/samagotchi/web/public/page_view.js +29 -4
- data/lib/samagotchi/web/public/participant_model.js +1 -1
- data/lib/samagotchi/web/public/peer_wait.js +2 -4
- data/lib/samagotchi/web/public/schedule_marks.js +2 -5
- data/lib/samagotchi/web/public/schedule_name.js +14 -0
- data/lib/samagotchi/web/public/session_actions.js +5 -0
- data/lib/samagotchi/web/public/start_page.js +1 -1
- data/lib/samagotchi/web/public/stop_sheet.js +2 -4
- data/lib/samagotchi/web/public/working_set_rail.js +0 -3
- data/lib/samagotchi/web/push/attention.rb +1 -1
- data/lib/samagotchi/web/session_create.rb +1 -1
- data/lib/samagotchi/web/session_hub.rb +68 -20
- data/lib/samagotchi/web/session_summary.rb +18 -14
- data/lib/samagotchi/web/verify_fresh_routes.rb +4 -4
- data/lib/samagotchi/worker/turn_drain.rb +158 -0
- data/lib/samagotchi/worker.rb +8 -144
- data/lib/samagotchi/worker_boot.rb +21 -5
- data/lib/samagotchi/worker_participant_gate.rb +5 -5
- data/lib/samagotchi/worker_presence.rb +24 -1
- metadata +6 -1
|
@@ -42,16 +42,33 @@ end
|
|
|
42
42
|
|
|
43
43
|
def plural(count, word) = "#{count} #{word}#{"s" unless count == 1}"
|
|
44
44
|
|
|
45
|
-
# A failure that turned it off before its budget ran out: a one-off's
|
|
45
|
+
# A failure that turned it off before its budget ran out: a one-off's, or
|
|
46
|
+
# one no retry fixes (#needs_fix?).
|
|
46
47
|
def failed_once?(schedule) = schedule.failures < schedule.max_failures
|
|
47
48
|
|
|
49
|
+
# The codes of a failed run no retry fixes (chi's Schedules::HistoryPart::CONFIG_FAILURES):
|
|
50
|
+
# the host refused the key, or doesn't serve the session's model. chi turns
|
|
51
|
+
# the schedule off at its first such failure; the run's words say the fix.
|
|
52
|
+
NEEDS_FIX = %w[auth model_not_served].freeze
|
|
53
|
+
|
|
54
|
+
# Its newest outcome is a failure NEEDS_FIX names (an older chi's runs have
|
|
55
|
+
# no code: never).
|
|
56
|
+
def needs_fix?(schedule)
|
|
57
|
+
run = schedule.history.reverse.find { |row| %w[fired skipped failed missed].include?(row.status) }
|
|
58
|
+
run&.status == "failed" && run.respond_to?(:code) && NEEDS_FIX.include?(run.code)
|
|
59
|
+
end
|
|
60
|
+
|
|
48
61
|
# The State column: on, firing, or off with why (off_reason).
|
|
49
62
|
def state_words(schedule)
|
|
50
63
|
case schedule.off_reason
|
|
51
64
|
when nil then schedule.state
|
|
52
65
|
when "owner" then "off: you"
|
|
53
66
|
when "skips" then "off: #{plural(schedule.skips, "skip")}"
|
|
54
|
-
when "failures"
|
|
67
|
+
when "failures"
|
|
68
|
+
if needs_fix?(schedule) then "off: needs a fix"
|
|
69
|
+
elsif failed_once?(schedule) then "off: failed"
|
|
70
|
+
else "off: #{plural(schedule.failures, "failure")}"
|
|
71
|
+
end
|
|
55
72
|
when "done" then "done"
|
|
56
73
|
when "missed" then "missed"
|
|
57
74
|
else "off"
|
|
@@ -63,7 +80,11 @@ def why_off(schedule)
|
|
|
63
80
|
case schedule.off_reason
|
|
64
81
|
when "owner" then "turned off by you"
|
|
65
82
|
when "skips" then "skipped #{plural(schedule.skips, "time")} (#{schedule.skip_window})"
|
|
66
|
-
when "failures"
|
|
83
|
+
when "failures"
|
|
84
|
+
if needs_fix?(schedule) then "failed, and no retry fixes it"
|
|
85
|
+
elsif failed_once?(schedule) then "one-off, failed"
|
|
86
|
+
else "failed #{plural(schedule.failures, "time")}"
|
|
87
|
+
end
|
|
67
88
|
when "done" then "one-off, done"
|
|
68
89
|
when "missed" then "one-off, missed"
|
|
69
90
|
else "off"
|
|
@@ -18,7 +18,7 @@ Single registry `Samagotchi::Config` (`Config::ENTRIES` in `lib/samagotchi/confi
|
|
|
18
18
|
|
|
19
19
|
Sections forbid `_`/`-` (`SECTION_RE` `/\A[a-z0-9]+\z/`), since an env or CLI name is derived from them; a config-only section (`system_one`: `expose: [:config]`, no derived name) may carry `_`. Leaves keep `snake_case` in YAML (`base_url`) and become kebab in CLI (`base-url`) via registry derivation — no generic string split, registry lookup avoids flat vs nested collision.
|
|
20
20
|
|
|
21
|
-
**Universal entries** (`expose: [:env,:config,:cli]`): `default.model`, `server.host/port/open_timeout/read_timeout`, `server.first_token_timeout`, `server.stream_idle_timeout` (env and config only), `recap.model/base_url/host_ref/inactivity/timeout/min_user_turns/sentences`, `session.retention_days/max_count/keep_status/sweep_interval_hours/idle_exit_minutes`, `session.keep_empty/max_children` (env and config only), `log.file/disable`, `status.line`, `context.status/window_tokens/chars_per_token/status_thresholds`, `memory.index_warn_tokens/entry_warn_tokens/read_max_chars`, `default.max_tokens`, `max_tool_output_chars`, `retry.max/base_delay/max_delay`, `read.*`, `execute.*`, `web.port/host`, `no_interrupt`, `no_default_input` etc. (`Config::ENTRIES`; `expose` says which of env/config/cli each takes). Precedence is `CLI > ENV > file > default`.
|
|
21
|
+
**Universal entries** (`expose: [:env,:config,:cli]`): `default.model`, `server.host/port/open_timeout/read_timeout`, `server.first_token_timeout`, `server.stream_idle_timeout` (env and config only), `recap.model/base_url/host_ref/inactivity/timeout/min_user_turns/sentences`, `session.retention_days/max_count/keep_status/sweep_interval_hours/idle_exit_minutes`, `session.keep_empty/split_messages/max_children` (env and config only), `log.file/disable`, `status.line`, `context.status/window_tokens/chars_per_token/status_thresholds`, `memory.index_warn_tokens/entry_warn_tokens/read_max_chars`, `default.max_tokens`, `max_tool_output_chars`, `retry.max/base_delay/max_delay`, `read.*`, `execute.*`, `web.port/host`, `no_interrupt`, `no_default_input` etc. (`Config::ENTRIES`; `expose` says which of env/config/cli each takes). Precedence is `CLI > ENV > file > default`.
|
|
22
22
|
|
|
23
23
|
Example `config.yml` (new nested form, preferred):
|
|
24
24
|
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: samagotchi-system
|
|
3
|
-
version: 0.
|
|
3
|
+
version: 0.202.0
|
|
4
4
|
scope: system
|
|
5
5
|
description: Default system memories — identity, self map, config modification protocol, memory guide and the delegated-session rules
|
|
6
6
|
files:
|
|
7
7
|
identity.md: sha256:29c2f7df9f6c5acbc5ec17000a4490741e55e426af15ca0d81c8706edd9bd027
|
|
8
8
|
self_map.md: sha256:5c5b4414f91daa74b436fde4afc77200d3629327f5b465fac40181ebcda7cc01
|
|
9
|
-
config_modification_protocol.md: sha256:
|
|
9
|
+
config_modification_protocol.md: sha256:fdd5988b601519a7f74baaf4b7b543143014f208fc398819564dce7e4666d6e4
|
|
10
10
|
memory_guide.md: sha256:272443ff8292631b28239cb8431d6e8dd19aa23fc53d05e1a10c11696a0a5d8d
|
|
11
11
|
delegated.md: sha256:a0d6ddcd4a8be06526d964898611775fd251cfd9d145a9d16afaccaa503597bd
|
|
12
12
|
skill_pages.md:
|
|
13
|
-
sha256: sha256:
|
|
13
|
+
sha256: sha256:5d7a5089a732eaf21ce9f04d00c75530e90679c5d479a8c267b8cd22bb2141e9
|
|
14
14
|
description: "Make, change or remove a page in chi web (a table, text or a walk the user reopens at #/p/NAME): write the script, chi page run, check, link"
|
|
@@ -88,7 +88,7 @@ and use the value inside `page`. The page shows the choices as buttons and a tap
|
|
|
88
88
|
names the sessions dir. `json` is loaded; `require` anything else.
|
|
89
89
|
- Schedules: `runtime.schedules` in the script reads them in chi itself (no command): each has `id`, `name`,
|
|
90
90
|
`state` (on, firing, off), `off_reason`, `next_due`, `last_fired`, `last_result`, `skips`, `failures` and
|
|
91
|
-
`history` (runs: `at`, `status`, `detail`, `session_id`), the keys of `chi schedule list --all --format json`;
|
|
91
|
+
`history` (runs: `at`, `status`, `detail`, `session_id`, `code`), the keys of `chi schedule list --all --format json`;
|
|
92
92
|
`ui.table runtime.schedules.rows, columns: …` takes them as rows, and `.warning` says when nothing ticks.
|
|
93
93
|
For a ready page: `chi bundle install schedules`. To make it your own, copy its script (`chi page list
|
|
94
94
|
--format json` names it as `script`) to `<the pages folder>/schedules.rb` and change that.
|
|
@@ -26,7 +26,7 @@ module Samagotchi
|
|
|
26
26
|
# ("start it yourself: …", "ask your user to start it: …"): its resume,
|
|
27
27
|
# or a message from a terminal or the web. Only its owner's does: an
|
|
28
28
|
# agent's, a peer's or a schedule's never un-stops it
|
|
29
|
-
# (
|
|
29
|
+
# (InboxDelivery::WakePolicy).
|
|
30
30
|
def start_stopped(id) = "`#{resume(id)}`, or a message from a terminal or #{remote? ? web : "the web"}"
|
|
31
31
|
|
|
32
32
|
# What shows the session ("… shows it"): its attach.
|
|
@@ -54,13 +54,16 @@ module Samagotchi
|
|
|
54
54
|
|
|
55
55
|
# @param open [Array<SessionContinue::OpenChild>] the previous link's open
|
|
56
56
|
# nodes, at any depth (SessionContinue.open_children)
|
|
57
|
+
# @param rows [Array<SessionRow>, nil] a SessionManager.fleet_rows to
|
|
58
|
+
# plan from (nil lists once)
|
|
57
59
|
# @return [Plan]
|
|
58
|
-
def plan(prev_id, open:, state_dir:)
|
|
60
|
+
def plan(prev_id, open:, state_dir:, rows: nil)
|
|
61
|
+
rows ||= SessionManager.fleet_rows(state_dir: state_dir)
|
|
59
62
|
open_ids = open.map(&:id)
|
|
60
63
|
move = []
|
|
61
64
|
refuse = []
|
|
62
|
-
SessionManager.children_of(prev_id, state_dir: state_dir).each do |row|
|
|
63
|
-
subtree = [row.id, *SessionManager.descendant_ids(row.id, state_dir)]
|
|
65
|
+
SessionManager.children_of(prev_id, state_dir: state_dir, rows: rows).each do |row|
|
|
66
|
+
subtree = [row.id, *SessionManager.descendant_ids(row.id, state_dir, rows: rows)]
|
|
64
67
|
next if (subtree & open_ids).empty?
|
|
65
68
|
|
|
66
69
|
if row.archived
|
|
@@ -52,7 +52,7 @@ module Samagotchi
|
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
# Ring +child+'s parent; best effort (a failure is logged, never
|
|
55
|
-
# raised): a ring delivery (
|
|
55
|
+
# raised): a ring delivery (InboxDelivery.deliver :ring). The ring file
|
|
56
56
|
# goes to the parent parent.json names; its WakePolicy decides whether
|
|
57
57
|
# a worker starts (a parent with none, idle, in wake mode), and for an
|
|
58
58
|
# archived parent with a later link, that link (the one whose
|
|
@@ -76,7 +76,7 @@ module Samagotchi
|
|
|
76
76
|
|
|
77
77
|
# A deleted parent gets no orphan dir: the delivery refuses it (:gone).
|
|
78
78
|
path = nil
|
|
79
|
-
|
|
79
|
+
InboxDelivery.deliver(:ring, parent_id, state_dir: state_dir, wake: mode == "wake",
|
|
80
80
|
start: starter(state_dir, wake)) do |at|
|
|
81
81
|
path = SessionInbox.write_ring(Session.session_dir(at, state_dir: state_dir), child_id: child.id, why: why)
|
|
82
82
|
Log.info(:worker, "delegate_rang", parent: at[0, 8], why: why)
|
|
@@ -134,7 +134,7 @@ module Samagotchi
|
|
|
134
134
|
# again. So the model gets each report once (a later !rollback that
|
|
135
135
|
# erases a kept turn drops what it read, as before).
|
|
136
136
|
class ChildReports
|
|
137
|
-
SOURCE =
|
|
137
|
+
SOURCE = Speaker::DELEGATE_REPORT
|
|
138
138
|
|
|
139
139
|
# A report for the model: the text delegate_result would return
|
|
140
140
|
# (DelegateWait.finish, its report variant), the cursor it moves the child to,
|
|
@@ -47,10 +47,12 @@ module Samagotchi
|
|
|
47
47
|
# Every child of +parent_id+, newest first: delegates and forks (a fork
|
|
48
48
|
# is delegate: false), archived ones only with +include_archived+. Scans
|
|
49
49
|
# every session (SessionManager.children_of): for on-demand use.
|
|
50
|
+
# @param rows [Array<SessionRow>, nil] a SessionManager.fleet_rows to
|
|
51
|
+
# reuse (a walk over many parents); nil lists
|
|
50
52
|
# @return [Array<Child>]
|
|
51
|
-
def of(parent_id, state_dir:, include_archived: false)
|
|
53
|
+
def of(parent_id, state_dir:, include_archived: false, rows: nil)
|
|
52
54
|
cursors = Tools::DelegateCursors.read(parent_id, state_dir: state_dir)
|
|
53
|
-
SessionManager.children_of(parent_id, state_dir: state_dir).filter_map do |row|
|
|
55
|
+
SessionManager.children_of(parent_id, state_dir: state_dir, rows: rows).filter_map do |row|
|
|
54
56
|
next if row.archived && !include_archived
|
|
55
57
|
|
|
56
58
|
session = load(row.id, state_dir: state_dir)
|
data/lib/samagotchi/client_id.rb
CHANGED
|
@@ -59,7 +59,7 @@ module Samagotchi
|
|
|
59
59
|
RELAY_PREFIX = "relay:"
|
|
60
60
|
# A participant's turn: participant:<participant id> (chi web stamps it
|
|
61
61
|
# from the participant's token, never from the request's body). Not
|
|
62
|
-
# their author (
|
|
62
|
+
# their author (Speaker::PARTICIPANT_PREFIX, "p:<id>"), which says who
|
|
63
63
|
# wrote a turn: this says which sender delivered it.
|
|
64
64
|
PARTICIPANT_PREFIX = "participant:"
|
|
65
65
|
# A worker's own first prompt (spawn_session's) when no sender was
|
|
@@ -81,7 +81,7 @@ module Samagotchi
|
|
|
81
81
|
# un-archive and wake resets (Worker#user_input);
|
|
82
82
|
# interactive — a screen that shows a command's reply and can answer
|
|
83
83
|
# it (CacheConfirm, /parent-answers);
|
|
84
|
-
# wake — the
|
|
84
|
+
# wake — the InboxDelivery::WakePolicy row a delivery reads
|
|
85
85
|
# (only :send un-stops and un-archives);
|
|
86
86
|
# origin — LastTurn#origin / TurnOrigin#source;
|
|
87
87
|
# source — a merged line's Steer source: a String, nil (the
|
data/lib/samagotchi/compat.rb
CHANGED
|
@@ -18,12 +18,10 @@ module Samagotchi
|
|
|
18
18
|
MIN_AGE_DAYS = 14
|
|
19
19
|
|
|
20
20
|
SHIMS = [
|
|
21
|
-
Shim.new(id: :
|
|
22
|
-
files: %w[lib/samagotchi/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
what: "an agent's client id (agent:<name>) sent as chi send's to a worker or chi web " \
|
|
26
|
-
"from before agent: senders (Delivery::AGENT_FEATURE)")
|
|
21
|
+
Shim.new(id: :messages_inline_beside_log, added_in: "0.202.0", added_on: "2026-12-05", remove_after: nil,
|
|
22
|
+
files: %w[lib/samagotchi/session_messages.rb spec/session_messages_split_spec.rb],
|
|
23
|
+
what: "a split session's file that chi 0.201.0 or older saved: its messages inline beside the " \
|
|
24
|
+
"messages_log it kept, read after the log's (SessionMessages.reconcile)")
|
|
27
25
|
].freeze
|
|
28
26
|
|
|
29
27
|
module_function
|
data/lib/samagotchi/config.rb
CHANGED
|
@@ -158,6 +158,9 @@ module Samagotchi
|
|
|
158
158
|
Entry.new(key: "session.carry_last_answer", yaml_path: %w[session carry_last_answer], type: :bool, default: true, expose: %i[env config], lifecycle: :next_lifecycle_decision),
|
|
159
159
|
# false: a session nothing happened in is deleted when it is left (SessionManager.discardable?).
|
|
160
160
|
Entry.new(key: "session.keep_empty", yaml_path: %w[session keep_empty], type: :bool, default: false, expose: %i[env config], lifecycle: :next_lifecycle_decision),
|
|
161
|
+
# A session's messages in their own file beside <id>.json (SessionMessages, split): a save appends instead of
|
|
162
|
+
# rewriting the whole session. A session read split stays split whatever this says.
|
|
163
|
+
Entry.new(key: "session.split_messages", yaml_path: %w[session split_messages], type: :bool, default: false, expose: %i[env config], lifecycle: :next_lifecycle_decision),
|
|
161
164
|
# The most sessions one session may have delegated and still running (the delegate tool); a guard against a runaway model.
|
|
162
165
|
Entry.new(key: "session.max_children", yaml_path: %w[session max_children], type: :integer, default: 4, expose: %i[env config], lifecycle: :next_lifecycle_decision),
|
|
163
166
|
# A delegate child's turn end reaches its parent (ChildReports): wake runs an idle parent's turn for it, queue waits
|
|
@@ -38,7 +38,7 @@ module Samagotchi
|
|
|
38
38
|
|
|
39
39
|
# Takes SessionInbox.read_note's keys. +turn_start+ / +turn_id+: the
|
|
40
40
|
# note starts a turn chi runs for it (a context wake), as a wake turn's
|
|
41
|
-
# delegate report does (
|
|
41
|
+
# delegate report does (Speaker.turn_prompt?). +header+: the frame's
|
|
42
42
|
# (HEADERS), not kept as a key: the content carries it. Its wall time
|
|
43
43
|
# (MessageTime::KEY) is +created_at+'s, else now. +objectives+: an
|
|
44
44
|
# objectives note's payload (Objectives::List#to_payload); +peer+: a
|
|
@@ -12,7 +12,7 @@ module Samagotchi
|
|
|
12
12
|
# new link's own is held with it), and FILE, its
|
|
13
13
|
# intent (the successor's id), written before the link is archived and
|
|
14
14
|
# removed once the successor is saved or the continue is undone. A send
|
|
15
|
-
# (
|
|
15
|
+
# (InboxDelivery::Head) and a schedule tick (Schedules#continuing_reason)
|
|
16
16
|
# read them to tell a continue in flight from a link nobody continues.
|
|
17
17
|
module ContinueIntent
|
|
18
18
|
# One continue of a session at a time (SessionTransition::LOCK).
|
|
@@ -4,7 +4,7 @@ require "time"
|
|
|
4
4
|
require_relative "last_turn"
|
|
5
5
|
require_relative "log"
|
|
6
6
|
require_relative "participant_messages"
|
|
7
|
-
require_relative "
|
|
7
|
+
require_relative "speaker"
|
|
8
8
|
require_relative "turn_origin"
|
|
9
9
|
require_relative "client_id"
|
|
10
10
|
|
|
@@ -222,7 +222,7 @@ module Samagotchi
|
|
|
222
222
|
enqueued_id = offer_turn_id
|
|
223
223
|
@event_log.announce(type: :continue_resolved, decision: "refused", reason: reason.to_s, client_id: command.client_id)
|
|
224
224
|
@event_log.announce(type: :hook_notice, hook: "participants", level: :warn, between_turns: true,
|
|
225
|
-
text: format(REFUSED_NOTICE, who:
|
|
225
|
+
text: format(REFUSED_NOTICE, who: Speaker.participant_id(author), reason: REFUSED_WHY.fetch(reason.to_s, reason.to_s)))
|
|
226
226
|
@turn_flow.abort_continue!
|
|
227
227
|
session = @engine.session
|
|
228
228
|
session.last_turn = LastTurn.new(outcome: NOT_CONTINUED, ended_at: Time.now.iso8601(3), enqueued_id: enqueued_id) if session
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "log"
|
|
4
|
+
|
|
5
|
+
module Samagotchi
|
|
6
|
+
# How long a repair pass (SessionContinue.repair_interrupted) leaves an
|
|
7
|
+
# intent alone after its repair failed on a system error (a full disk, a
|
|
8
|
+
# permission): 60 s after the first failure, doubling to 600 s. In this
|
|
9
|
+
# process's memory, keyed by the intent's path: a CLI run starts fresh,
|
|
10
|
+
# chi web's hub (a pass each second) stops hammering. A skipped intent
|
|
11
|
+
# costs no read. One continue_repair_deferred WARN per intent and error
|
|
12
|
+
# class (DEBUG while it repeats); a success, or an intent gone from the
|
|
13
|
+
# pass, forgets it.
|
|
14
|
+
module ContinueRepairBackoff
|
|
15
|
+
FIRST = 60
|
|
16
|
+
CAP = 600
|
|
17
|
+
|
|
18
|
+
Entry = Data.define(:at, :delay, :error)
|
|
19
|
+
|
|
20
|
+
@entries = {}
|
|
21
|
+
@mutex = Mutex.new
|
|
22
|
+
@clock = -> { Process.clock_gettime(Process::CLOCK_MONOTONIC) }
|
|
23
|
+
|
|
24
|
+
class << self
|
|
25
|
+
# Specs: a lambda returning seconds.
|
|
26
|
+
attr_accessor :clock
|
|
27
|
+
|
|
28
|
+
# @return [Boolean] whether +path+ waits out its backoff
|
|
29
|
+
def waiting?(path)
|
|
30
|
+
now = clock.call
|
|
31
|
+
entry = @mutex.synchronize { @entries[path] }
|
|
32
|
+
!entry.nil? && now < entry.at
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Record a failed repair and log it.
|
|
36
|
+
# @return nil
|
|
37
|
+
def failed(path, session_id, error)
|
|
38
|
+
now = clock.call
|
|
39
|
+
entry, logged = @mutex.synchronize do
|
|
40
|
+
last = @entries[path]
|
|
41
|
+
delay = last ? [last.delay * 2, CAP].min : FIRST
|
|
42
|
+
@entries[path] = Entry.new(at: now + delay, delay: delay, error: error.class.name)
|
|
43
|
+
[@entries[path], last&.error == error.class.name]
|
|
44
|
+
end
|
|
45
|
+
fields = { sid: session_id, error: entry.error, msg: error.message.to_s[0, 200], retry_in: entry.delay }
|
|
46
|
+
logged ? Log.debug(:worker, "continue_repair_deferred", **fields) : Log.warn(:worker, "continue_repair_deferred", **fields)
|
|
47
|
+
nil
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# @return [String, nil] the error class +path+'s repair last failed on
|
|
51
|
+
def error_of(path) = @mutex.synchronize { @entries[path]&.error }
|
|
52
|
+
|
|
53
|
+
def succeeded(path)
|
|
54
|
+
@mutex.synchronize { @entries.delete(path) } unless @entries.empty?
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Forget the intents under +state_dir+ that a pass no longer finds.
|
|
58
|
+
def keep_only(paths, state_dir)
|
|
59
|
+
return if @entries.empty?
|
|
60
|
+
|
|
61
|
+
prefix = File.join(state_dir, "")
|
|
62
|
+
@mutex.synchronize { @entries.delete_if { |path, _| path.start_with?(prefix) && !paths.include?(path) } }
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def reset!
|
|
66
|
+
@mutex.synchronize { @entries.clear }
|
|
67
|
+
@clock = -> { Process.clock_gettime(Process::CLOCK_MONOTONIC) }
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
data/lib/samagotchi/delivery.rb
CHANGED
|
@@ -65,10 +65,7 @@ module Samagotchi
|
|
|
65
65
|
# The previous release's chi web checks this before sending participant:<id>.
|
|
66
66
|
PARTICIPANT_ID_FEATURE = "participant_client_id"
|
|
67
67
|
# A worker (Bridge::FEATURES) or a chi web (Web::App::INFO_FEATURES)
|
|
68
|
-
# that reads an agent's client id (ClientId::AGENT_PREFIX).
|
|
69
|
-
# it would read agent:<name> as an unknown sender (automatic), so it is
|
|
70
|
-
# sent chi send's id instead: today's owner row.
|
|
71
|
-
# compat shim agent_client_id
|
|
68
|
+
# that reads an agent's client id (ClientId::AGENT_PREFIX).
|
|
72
69
|
AGENT_FEATURE = "agent_sender"
|
|
73
70
|
# A worker (Bridge::FEATURES) that runs another session's question
|
|
74
71
|
# (ClientId::SESSION_PREFIX, ask_session) as a visitor's turn. One
|
|
@@ -76,7 +76,7 @@ module Samagotchi
|
|
|
76
76
|
# @param author [String, nil] a turn's or a line's author (TurnOrigin#author)
|
|
77
77
|
# @param session [Session, nil] the session it is for (the turn's)
|
|
78
78
|
def author_fields(author, session: @session)
|
|
79
|
-
return {} unless
|
|
79
|
+
return {} unless Speaker.participant_author?(author)
|
|
80
80
|
|
|
81
81
|
Steer.author_fields(author, @participants.name_for(author, session: session))
|
|
82
82
|
end
|
|
@@ -109,7 +109,7 @@ module Samagotchi
|
|
|
109
109
|
|
|
110
110
|
messages = @session&.messages || []
|
|
111
111
|
covered = state[:covered].to_i
|
|
112
|
-
turns_since = Array(messages).drop(covered).count { |m|
|
|
112
|
+
turns_since = Array(messages).drop(covered).count { |m| Speaker.turn_opening?(m) }
|
|
113
113
|
{ text: state[:text], covered: covered, turns_since: turns_since, opening_id: RecapPlace.opening_id(messages, covered),
|
|
114
114
|
created_at: state[:created_at] }
|
|
115
115
|
end
|
|
@@ -29,7 +29,7 @@ module Samagotchi
|
|
|
29
29
|
origin: origin.source, exhausted: limit ? true : nil, limit: limit,
|
|
30
30
|
enqueued_id: enqueued_id.to_s.empty? ? nil : enqueued_id.to_s,
|
|
31
31
|
author: origin.participant_author,
|
|
32
|
-
**stop_facts(event))
|
|
32
|
+
**stop_facts(event), **@turn_endings.failure_facts(event))
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
# A turn that failed before the Engine's began (the Worker's steps
|
data/lib/samagotchi/grants.rb
CHANGED
|
@@ -4,7 +4,7 @@ require "digest"
|
|
|
4
4
|
require "fileutils"
|
|
5
5
|
require "json"
|
|
6
6
|
require "openssl"
|
|
7
|
-
require_relative "
|
|
7
|
+
require_relative "speaker"
|
|
8
8
|
require "securerandom"
|
|
9
9
|
require "time"
|
|
10
10
|
require_relative "atomic_file"
|
|
@@ -174,7 +174,7 @@ module Samagotchi
|
|
|
174
174
|
def queue_limit = queue.is_a?(Integer) ? queue : Grants.default_queue
|
|
175
175
|
|
|
176
176
|
# The author a participant's turn carries (Principal#author).
|
|
177
|
-
def author =
|
|
177
|
+
def author = Speaker.author_for(id)
|
|
178
178
|
|
|
179
179
|
# :active, :revoked, :expired or :outdated (an older chi's grant
|
|
180
180
|
# for read-only turns: no PAIR_MODE) at +now+ (a Time). Derived, never
|
|
@@ -382,7 +382,7 @@ module Samagotchi
|
|
|
382
382
|
# +author+ is the turn's (TurnContext#author).
|
|
383
383
|
# @return [Hash, nil] {id:, p:, auto:}, nil when nothing was written
|
|
384
384
|
def system_one_judge(payload, author: nil, targets: nil, ask_user: false, other_rules: nil)
|
|
385
|
-
return nil if
|
|
385
|
+
return nil if Speaker.participant_author?(author)
|
|
386
386
|
|
|
387
387
|
client = @system_one.call
|
|
388
388
|
log = system_one_log
|
|
@@ -130,11 +130,11 @@ module Samagotchi
|
|
|
130
130
|
# How a participant's ask names them: their cleaned name, else their
|
|
131
131
|
# id; nil for the owner's turns.
|
|
132
132
|
def asker(author, author_name)
|
|
133
|
-
require_relative "../
|
|
134
|
-
return nil unless
|
|
133
|
+
require_relative "../speaker"
|
|
134
|
+
return nil unless Speaker.participant_author?(author)
|
|
135
135
|
|
|
136
136
|
name = author_name_for(author_name)
|
|
137
|
-
name ||
|
|
137
|
+
name || Speaker.participant_id(author.to_s)
|
|
138
138
|
end
|
|
139
139
|
|
|
140
140
|
def author_name_for(author_name)
|
|
@@ -6,7 +6,7 @@ require_relative "shell_paths"
|
|
|
6
6
|
require_relative "shell_lex"
|
|
7
7
|
require_relative "pair_command"
|
|
8
8
|
require_relative "parent_approvals"
|
|
9
|
-
require_relative "../
|
|
9
|
+
require_relative "../speaker"
|
|
10
10
|
|
|
11
11
|
module Samagotchi
|
|
12
12
|
module Guardrails
|
|
@@ -188,7 +188,7 @@ module Samagotchi
|
|
|
188
188
|
# @param author [#call] → String, nil: the running turn's author
|
|
189
189
|
# (the call's TurnContext#author, GuardrailWiring#pair_boundary);
|
|
190
190
|
# the check is off unless it is a
|
|
191
|
-
# participant's (
|
|
191
|
+
# participant's (Speaker.participant_author?)
|
|
192
192
|
# @param denied_dirs [#call] → Array<String>: chi's own dirs
|
|
193
193
|
# @param home [#call] → String, nil
|
|
194
194
|
# @param root [#call] → String, nil: the session's project root (the
|
|
@@ -207,7 +207,7 @@ module Samagotchi
|
|
|
207
207
|
|
|
208
208
|
# Vote on +verdict+ (its call and targets).
|
|
209
209
|
def check(verdict)
|
|
210
|
-
return verdict unless
|
|
210
|
+
return verdict unless Speaker.participant_author?(@author.call)
|
|
211
211
|
|
|
212
212
|
if (reason = refusal(verdict))
|
|
213
213
|
return verdict.deny!(reason, rule: RULE, source: SOURCE, decided_by: "core", advice: ADVICE)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative "../
|
|
3
|
+
require_relative "../speaker"
|
|
4
4
|
|
|
5
5
|
module Samagotchi
|
|
6
6
|
module Guardrails
|
|
@@ -24,7 +24,7 @@ module Samagotchi
|
|
|
24
24
|
|
|
25
25
|
# Vote on +verdict+.
|
|
26
26
|
def check(verdict)
|
|
27
|
-
return verdict unless
|
|
27
|
+
return verdict unless Speaker.participant_author?(@author.call)
|
|
28
28
|
|
|
29
29
|
verdict.deny!(REASON, rule: RULE, source: SOURCE, decided_by: "core", advice: ADVICE)
|
|
30
30
|
end
|
|
@@ -9,7 +9,7 @@ require_relative "idle_client"
|
|
|
9
9
|
require_relative "idle_target"
|
|
10
10
|
require_relative "image_store"
|
|
11
11
|
require_relative "output_formatter"
|
|
12
|
-
require_relative "
|
|
12
|
+
require_relative "speaker"
|
|
13
13
|
require_relative "recap_store"
|
|
14
14
|
require_relative "recap_title"
|
|
15
15
|
require_relative "log"
|
|
@@ -71,16 +71,16 @@ module Samagotchi
|
|
|
71
71
|
# A plugin's steer is a prod to the model, not what the user said;
|
|
72
72
|
# a continue steer from the user or the parent agent is an
|
|
73
73
|
# instruction, kept.
|
|
74
|
-
next nil if
|
|
74
|
+
next nil if Speaker.steer?(message) && !Speaker.person?(message)
|
|
75
75
|
|
|
76
76
|
# An image is a line naming it (refs only, never its bytes), unless
|
|
77
77
|
# the text is only the web's placeholder naming it already.
|
|
78
78
|
content = message["content"].to_s
|
|
79
79
|
# A delegate child's report (ChildReports) is chi's news, not
|
|
80
80
|
# what the user said.
|
|
81
|
-
content = "#{DELEGATE_REPORT_LINE}\n#{content}" if message["source"].to_s ==
|
|
81
|
+
content = "#{DELEGATE_REPORT_LINE}\n#{content}" if message["source"].to_s == Speaker::DELEGATE_REPORT
|
|
82
82
|
# A participant's is theirs, by the name it was saved with.
|
|
83
|
-
content = "#{participant_line(message)}\n#{content}" if
|
|
83
|
+
content = "#{participant_line(message)}\n#{content}" if Speaker.participant_message?(message)
|
|
84
84
|
images = ImageRef.placeholder_only?(content) ? [] : image_lines(message["images"])
|
|
85
85
|
[content, *images].reject(&:empty?).join("\n")
|
|
86
86
|
when "model", "assistant"
|
|
@@ -490,9 +490,9 @@ module Samagotchi
|
|
|
490
490
|
parsed = safe_parse(@messages_json.call)
|
|
491
491
|
return :too_short if parsed.nil?
|
|
492
492
|
|
|
493
|
-
# The turns as the page counts them (
|
|
493
|
+
# The turns as the page counts them (Speaker.turn_opening?): not Qwen's
|
|
494
494
|
# recovery line, nor input merged into a running turn.
|
|
495
|
-
user_turns = parsed.count { |message|
|
|
495
|
+
user_turns = parsed.count { |message| Speaker.turn_opening?(message) }
|
|
496
496
|
if parsed.empty? || user_turns < @min_user_turns
|
|
497
497
|
drop_stale(parsed)
|
|
498
498
|
return :too_short
|
|
@@ -743,7 +743,7 @@ module Samagotchi
|
|
|
743
743
|
turn.pending_tool_calls = false
|
|
744
744
|
if turn.qwen_partial && turn.qwen_attempts < QWEN_INCOMPLETE_TOOL_CALL_RECOVERY_LIMIT
|
|
745
745
|
turn.qwen_attempts += 1
|
|
746
|
-
turn.conversation << { role: "user", kind:
|
|
746
|
+
turn.conversation << { role: "user", kind: Speaker::RECOVERY_KIND, content: QWEN_INCOMPLETE_TOOL_CALL_RECOVERY_PROMPT,
|
|
747
747
|
preserve_literals: true }
|
|
748
748
|
return :next
|
|
749
749
|
end
|
data/lib/samagotchi/last_turn.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative "
|
|
3
|
+
require_relative "speaker"
|
|
4
4
|
|
|
5
5
|
module Samagotchi
|
|
6
6
|
# How a session's last turn ended (Session#last_turn), saved as
|
|
@@ -19,11 +19,14 @@ module Samagotchi
|
|
|
19
19
|
# ack's, an input file's), so a wait for a queued message (`chi send
|
|
20
20
|
# --queue --wait`, ReplyWait's turn:) tells its own turn's end from
|
|
21
21
|
# another's. author: who wrote the turn when it wasn't the owner ("p:<id>",
|
|
22
|
-
# a participant; origin stays the category), nil for the owner.
|
|
23
|
-
#
|
|
22
|
+
# a participant; origin stays the category), nil for the owner.
|
|
23
|
+
# error_reason / error_host: a failed turn's finer code beside its
|
|
24
|
+
# error_kind (model_not_served) and the host that failed it
|
|
25
|
+
# (TurnEndings#failure_facts). A field may be nil (unset; left out of the
|
|
26
|
+
# file; an older chi drops the newer ones).
|
|
24
27
|
LastTurn = Data.define(:outcome, :ended_at, :seconds, :origin, :exhausted, :limit,
|
|
25
28
|
:error_kind, :retryable, :kept_steps, :cancel_reason, :stopped_by, :enqueued_id,
|
|
26
|
-
:author) do
|
|
29
|
+
:author, :error_reason, :error_host) do
|
|
27
30
|
def initialize(**fields)
|
|
28
31
|
super(**members.to_h { |m| [m, nil] }, **fields)
|
|
29
32
|
end
|
|
@@ -47,10 +50,10 @@ module Samagotchi
|
|
|
47
50
|
# @return [Hash{Symbol => Object}]
|
|
48
51
|
def stop_facts = to_h.slice(*self.class::STOP_FACTS).compact
|
|
49
52
|
|
|
50
|
-
# The turn's author when a participant's (
|
|
53
|
+
# The turn's author when a participant's (Speaker.sender_author, as
|
|
51
54
|
# TurnOrigin#participant_author reads a running turn's), else nil.
|
|
52
55
|
# @return [String, nil]
|
|
53
|
-
def participant_author =
|
|
56
|
+
def participant_author = Speaker.sender_author(author)
|
|
54
57
|
end
|
|
55
58
|
|
|
56
59
|
# Why a turn stopped, for a parent agent's wait (ReplyWait::Result takes
|
|
@@ -483,7 +483,7 @@ module Samagotchi
|
|
|
483
483
|
#
|
|
484
484
|
# The rule: a saved message field the wire needs must be listed here
|
|
485
485
|
# (a key below, or one of the lists it reads: ContextNote::KEYS,
|
|
486
|
-
#
|
|
486
|
+
# Speaker::AUTHOR_KEYS, ToolResponse::SAVED_KEYS). This rebuilds every
|
|
487
487
|
# kept message, earlier turns' included, from these keys alone: an
|
|
488
488
|
# unlisted field is gone from the saved history once its turn ends,
|
|
489
489
|
# so the next request reads that message without it and the chat
|
|
@@ -512,11 +512,14 @@ module Samagotchi
|
|
|
512
512
|
message[TurnNote::RETRY_NUDGE] = true if TurnNote.retry_nudge?(entry)
|
|
513
513
|
marker = TurnNote.empty_answer(entry)
|
|
514
514
|
message[TurnNote::EMPTY_ANSWER] = marker if marker
|
|
515
|
+
failure = TurnNote.failure(entry)
|
|
516
|
+
message[TurnNote::FAILED_KEY] = failure[:summary] if failure
|
|
517
|
+
message[TurnNote::KEPT_KEY] = failure[:kept] if failure&.dig(:kept)
|
|
515
518
|
message[AnswerDisplay::KEY] = entry[AnswerDisplay::KEY] if entry[AnswerDisplay::KEY]
|
|
516
519
|
message[AnswerRefs::KEY] = entry[AnswerRefs::KEY] if entry[AnswerRefs::KEY]
|
|
517
520
|
message[BlockFix::STAMP] = entry[BlockFix::STAMP] if entry[BlockFix::STAMP]
|
|
518
521
|
ContextNote::KEYS.each { |key| message[key] = entry[key] if entry.key?(key) }
|
|
519
|
-
|
|
522
|
+
Speaker::AUTHOR_KEYS.each { |key| message[key] = entry[key] if entry[key] }
|
|
520
523
|
message[ToolResponse::LOADED] = entry[ToolResponse::LOADED] if entry[ToolResponse::LOADED].is_a?(Array)
|
|
521
524
|
message[TOOL_CHANGE] = entry[TOOL_CHANGE] if entry[TOOL_CHANGE].is_a?(Hash)
|
|
522
525
|
message[MessageTime::KEY] = entry[MessageTime::KEY] if entry[MessageTime::KEY]
|
|
@@ -27,7 +27,7 @@ module Samagotchi
|
|
|
27
27
|
|
|
28
28
|
# One load of what the tools' calls autoload (SessionManager, and what
|
|
29
29
|
# a probe of their paths loaded on a first call: SessionContinue,
|
|
30
|
-
#
|
|
30
|
+
# InboxDelivery; about 6 ms) before the first call's thread:
|
|
31
31
|
# two threads must not trigger them at once.
|
|
32
32
|
LOAD_LOCK = Mutex.new
|
|
33
33
|
|
|
@@ -90,7 +90,7 @@ module Samagotchi
|
|
|
90
90
|
LOAD_LOCK.synchronize do
|
|
91
91
|
Samagotchi.const_get(:SessionManager)
|
|
92
92
|
Samagotchi.const_get(:SessionContinue)
|
|
93
|
-
|
|
93
|
+
Samagotchi.const_get(:InboxDelivery)
|
|
94
94
|
end
|
|
95
95
|
end
|
|
96
96
|
|
|
@@ -91,13 +91,14 @@ module Samagotchi
|
|
|
91
91
|
sessions = []
|
|
92
92
|
unreadable = 0
|
|
93
93
|
Dir.glob(File.join(state_dir, "*#{SessionPaths::FILE_EXT}")).sort.each do |path|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
94
|
+
sessions << SessionMessages.parse(path) do |data|
|
|
95
|
+
# A project_root that is not a path (a hand-edited file) makes every
|
|
96
|
+
# later step raise, so the file counts as unreadable rather than
|
|
97
|
+
# taking the whole report down.
|
|
98
|
+
raise ArgumentError, "project_root is not a path" unless data["project_root"].nil? || data["project_root"].is_a?(String)
|
|
99
99
|
|
|
100
|
-
|
|
100
|
+
Session.from_file(data, path: path)
|
|
101
|
+
end
|
|
101
102
|
rescue StandardError
|
|
102
103
|
unreadable += 1
|
|
103
104
|
end
|
|
@@ -123,7 +123,7 @@ module Samagotchi
|
|
|
123
123
|
|
|
124
124
|
# The id, or for a session that was continued the link that took it
|
|
125
125
|
# (chi send's wording too).
|
|
126
|
-
def where(id, result) =
|
|
126
|
+
def where(id, result) = InboxDelivery::Resolved.label(id, result.id)
|
|
127
127
|
|
|
128
128
|
def outcome(result)
|
|
129
129
|
case result.status
|