samagotchi 0.92.0 → 0.94.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 (75) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +53 -1
  3. data/README.md +1 -1
  4. data/bin/chi +4 -4
  5. data/docs/architecture.md +4 -4
  6. data/docs/cli.md +1 -1
  7. data/docs/guardrails.md +4 -5
  8. data/docs/hooks.md +1 -1
  9. data/docs/internals/bundles.md +1 -1
  10. data/docs/internals/engine.md +6 -0
  11. data/docs/memory.md +26 -1
  12. data/docs/plugins.md +37 -0
  13. data/docs/releasing.md +2 -2
  14. data/docs/sessions.md +1 -1
  15. data/docs/testing.md +11 -2
  16. data/lib/samagotchi/bootstrap/probe.rb +2 -2
  17. data/lib/samagotchi/bootstrap_command.rb +1 -0
  18. data/lib/samagotchi/bundle_command.rb +1 -0
  19. data/lib/samagotchi/bundles/dev/manifest.yml +2 -1
  20. data/lib/samagotchi/bundles/model-notes/manifest.yml +11 -0
  21. data/lib/samagotchi/bundles/model-notes/model_notes_deepseek.md +7 -0
  22. data/lib/samagotchi/bundles/model-notes/notes/README.md +37 -0
  23. data/lib/samagotchi/bundles/system/manifest.yml +1 -1
  24. data/lib/samagotchi/child_reports.rb +12 -14
  25. data/lib/samagotchi/client_id.rb +18 -0
  26. data/lib/samagotchi/config/restart_watch.rb +112 -0
  27. data/lib/samagotchi/config.rb +18 -59
  28. data/lib/samagotchi/engine.rb +4 -14
  29. data/lib/samagotchi/guardrails/data_readers.rb +34 -30
  30. data/lib/samagotchi/guardrails/parent_levels.rb +31 -0
  31. data/lib/samagotchi/guardrails/parent_policy.rb +9 -20
  32. data/lib/samagotchi/guardrails/shell_lex.rb +28 -7
  33. data/lib/samagotchi/hook_question.rb +21 -0
  34. data/lib/samagotchi/hook_routes.rb +6 -6
  35. data/lib/samagotchi/hooks/registry.rb +5 -5
  36. data/lib/samagotchi/host_registry.rb +1 -1
  37. data/lib/samagotchi/llm/anthropic_messages.rb +5 -0
  38. data/lib/samagotchi/memory_bundle/profile.rb +22 -4
  39. data/lib/samagotchi/memory_bundle/shipped_update.rb +5 -1
  40. data/lib/samagotchi/parent_answers_command.rb +6 -6
  41. data/lib/samagotchi/plugin/context.rb +6 -5
  42. data/lib/samagotchi/plugin/http_transport.rb +14 -3
  43. data/lib/samagotchi/plugin/sessions.rb +2 -3
  44. data/lib/samagotchi/question_desk.rb +12 -9
  45. data/lib/samagotchi/reply_wait/poll.rb +267 -0
  46. data/lib/samagotchi/reply_wait.rb +47 -190
  47. data/lib/samagotchi/send_command/parent_gate.rb +83 -0
  48. data/lib/samagotchi/send_command/wait_target.rb +55 -0
  49. data/lib/samagotchi/send_command.rb +31 -100
  50. data/lib/samagotchi/session.rb +10 -9
  51. data/lib/samagotchi/session_inbox.rb +31 -8
  52. data/lib/samagotchi/session_manager.rb +48 -15
  53. data/lib/samagotchi/session_metrics.rb +22 -3
  54. data/lib/samagotchi/sessions_command.rb +4 -4
  55. data/lib/samagotchi/terminal_ui/attached_loop.rb +3 -3
  56. data/lib/samagotchi/terminal_ui/formatting.rb +8 -5
  57. data/lib/samagotchi/testing/bundle.rb +1 -1
  58. data/lib/samagotchi/testing/host.rb +2 -8
  59. data/lib/samagotchi/testing/recorder.rb +6 -9
  60. data/lib/samagotchi/testing/sandbox.rb +26 -0
  61. data/lib/samagotchi/tools/delegate.rb +10 -10
  62. data/lib/samagotchi/tools/delegate_cursor.rb +32 -8
  63. data/lib/samagotchi/tools/delegate_relay.rb +31 -16
  64. data/lib/samagotchi/tools/delegate_wait.rb +4 -4
  65. data/lib/samagotchi/update_command.rb +1 -1
  66. data/lib/samagotchi/version.rb +1 -1
  67. data/lib/samagotchi/web/app.rb +46 -63
  68. data/lib/samagotchi/web/public/app.js +137 -638
  69. data/lib/samagotchi/web/public/dock_reserve.js +103 -0
  70. data/lib/samagotchi/web/public/index.html +4 -4
  71. data/lib/samagotchi/web/public/send_turn.js +173 -0
  72. data/lib/samagotchi/web/public/session_actions.js +203 -0
  73. data/lib/samagotchi/web/public/start_page.js +236 -0
  74. data/lib/samagotchi/web/public/toast_place.js +1 -1
  75. metadata +14 -1
@@ -0,0 +1,236 @@
1
+ import {
2
+ chipModel as llmContextChipModel, choiceWords, createLlmContextControl, NEW_SESSION, withChoice,
3
+ } from "./llm_context_chip.js";
4
+ import { chipModel as thinkingChipModel, createThinkingControl, withChoice as withThinkingChoice } from "./thinking_chip.js";
5
+ import { MODEL_KEY, modelsFailedText } from "./model_pick.js";
6
+ import { createModelPicker } from "./model_picker.js";
7
+ import { chainNeighbours, freshLink } from "./chains.js";
8
+ import { readStored } from "./storage.js";
9
+
10
+ // ── The start page's model picker ──────────────────────────────────────────
11
+ // The hosts' models from GET /api/models, the choice this browser made last
12
+ // preselected while it is still offered (else the server's default). Hidden
13
+ // until the list is in, and in a session (its model is in the info bar),
14
+ // but a fresh chain link's (chains.js freshLink): there it shows the link's
15
+ // model and a pick runs /model in the link, remembered neither as this
16
+ // browser's choice nor in Recent. A host that failed is the picker's
17
+ // tooltip; a route that fails leaves the picker hidden and the server's
18
+ // default in charge. The search list itself is model_picker.js'; a pick
19
+ // sends the focus to the message box.
20
+ //
21
+ // Beside it, the start page's LLM context and thinking chips: the picked
22
+ // model's values, and a choice for the next new session only (sent with its
23
+ // create, then dropped; never remembered: a reload or opening a session
24
+ // drops it too, a failed create keeps it).
25
+ export const START_PICK_TITLE = "The model the new session starts on";
26
+
27
+ // Used by app.js. Elements: +pickEl+ (the picker's button), +panelEl+,
28
+ // +searchEl+, +listEl+, +composerEl+, +centerEl+ (model_picker.js'),
29
+ // +llmContextEl+ / +thinkingEl+ (the two chips).
30
+ // Hooks: +selected()+ the open session's id or null; +state()+ the open
31
+ // session's fields (session_state.js: model, continues…); +running()+ a turn
32
+ // runs; +sessions()+ the list; +run(line)+ a session command from a control
33
+ // (resolves true once the worker took it); +focusPrompt()+; +toast(text)+;
34
+ // +listModels()+ GET /api/models (data.js). +win+: the page's unload events.
35
+ export function createStartPage({
36
+ pickEl, panelEl, searchEl, listEl, composerEl, centerEl, llmContextEl, thinkingEl,
37
+ selected, state, running, sessions, run, focusPrompt, toast, listModels,
38
+ doc = globalThis.document, win = globalThis.window,
39
+ }) {
40
+ // The new session's own choices (null: follow the picked model's).
41
+ let newChatLlmContext = null;
42
+ let newChatThinking = null;
43
+ let startPickTitle = START_PICK_TITLE;
44
+ // The fresh link the picker shows (null: the start page, or a session it
45
+ // is hidden in), and a link pick's /model still in flight (a send waits).
46
+ let pickLinkId = null;
47
+ let pickSelected = null;
48
+ let pendingPick = null;
49
+ let pendingPickId = null;
50
+ // A command_ran came while the pick was in flight (its sync was skipped):
51
+ // the ack syncs then.
52
+ let pickRanEarly = false;
53
+ // A reload cuts the fetch: its error is no news (modelsFailedText).
54
+ let pageLeaving = false;
55
+
56
+ const newChatLlmSummary = () => (selected() || pickEl.hidden ? null : modelPicker.chosenRow()?.llm_context || null);
57
+ const llmContextNewControl = createLlmContextControl({
58
+ el: llmContextEl,
59
+ summary: newChatLlmSummary,
60
+ kind: NEW_SESSION,
61
+ choice: () => newChatLlmContext,
62
+ choose: (next) => {
63
+ newChatLlmContext = next;
64
+ renderNewChatLlmContext();
65
+ focusPrompt();
66
+ },
67
+ id: "llmContextNewPopover",
68
+ anchor: "#llmContextNew",
69
+ });
70
+ const newChatThinkingSummary = () => (selected() || pickEl.hidden ? null : modelPicker.chosenRow()?.thinking || null);
71
+ const thinkingNewControl = createThinkingControl({
72
+ el: thinkingEl,
73
+ summary: newChatThinkingSummary,
74
+ kind: NEW_SESSION,
75
+ choice: () => newChatThinking,
76
+ choose: (next) => {
77
+ newChatThinking = next;
78
+ renderNewChatThinking();
79
+ focusPrompt();
80
+ },
81
+ id: "thinkingNewPopover",
82
+ anchor: "#thinkingNew",
83
+ });
84
+ function renderNewChatThinking() {
85
+ const chip = thinkingChipModel(withThinkingChoice(newChatThinkingSummary(), newChatThinking), { kind: NEW_SESSION });
86
+ thinkingEl.hidden = !chip;
87
+ if (!chip) return thinkingNewControl.close();
88
+ thinkingEl.textContent = chip.text;
89
+ thinkingEl.title = chip.title;
90
+ thinkingEl.classList.toggle("own", chip.own);
91
+ }
92
+ // Hidden without the model's values (the list not in, an older server).
93
+ function renderNewChatLlmContext() {
94
+ const chip = llmContextChipModel(withChoice(newChatLlmSummary(), newChatLlmContext), { kind: NEW_SESSION });
95
+ llmContextEl.hidden = !chip;
96
+ if (!chip) return llmContextNewControl.close();
97
+ llmContextEl.textContent = chip.text;
98
+ llmContextEl.title = chip.title;
99
+ llmContextEl.classList.toggle("own", chip.own);
100
+ }
101
+
102
+ const modelPicker = createModelPicker({
103
+ button: pickEl,
104
+ panel: panelEl,
105
+ input: searchEl,
106
+ list: listEl,
107
+ composer: composerEl,
108
+ center: centerEl,
109
+ remember: () => !selected(),
110
+ onPick: (name) => {
111
+ if (selected()) pickForLink(name);
112
+ else {
113
+ renderNewChatLlmContext();
114
+ renderNewChatThinking();
115
+ }
116
+ focusPrompt();
117
+ },
118
+ });
119
+ // A pick on a fresh link: /model in its worker (its command bubble and the
120
+ // info bar follow from command_ran); refused, the button goes back to the
121
+ // link's model, if the page is still on that link.
122
+ function pickForLink(name) {
123
+ const id = selected();
124
+ const ran = run(`/model ${name}`).then((ok) => {
125
+ const ranEarly = pendingPick === ran && pickRanEarly;
126
+ if (pendingPick === ran) {
127
+ pendingPick = null;
128
+ pendingPickId = null;
129
+ pickRanEarly = false;
130
+ }
131
+ if ((!ok || ranEarly) && selected() === id) syncModelPick();
132
+ return ok;
133
+ });
134
+ pendingPick = ran;
135
+ pendingPickId = id;
136
+ pickRanEarly = false;
137
+ }
138
+ // The button's name, tooltip and label for what the page shows: a fresh
139
+ // link's model, else the start page's (whose choice stays as it is).
140
+ // Toggles the fresh-link class (the CSS shows the button in a session
141
+ // only with it); the panel closes when the link changes or stops being fresh.
142
+ function syncModelPick() {
143
+ const open = selected();
144
+ const current = state();
145
+ // The list walk only for a link that is fresh otherwise (the info bar
146
+ // calls this every second while a turn runs).
147
+ const fresh = !!open && freshLink(current, { running: running() })
148
+ && !chainNeighbours(sessions(), open, { continues: current.continues }).next;
149
+ doc.body.classList.toggle("fresh-link", fresh);
150
+ const linkId = fresh ? open : null;
151
+ // Another session (or the start page), or the link stopped being fresh:
152
+ // a panel left open would come back open where it no longer belongs.
153
+ if (open !== pickSelected || linkId !== pickLinkId) modelPicker.close();
154
+ pickSelected = open;
155
+ pickLinkId = linkId;
156
+ if (fresh) {
157
+ // A pick in flight keeps its name until its /model is taken (its
158
+ // command_ran syncs again then).
159
+ if (!(pendingPick && pendingPickId === open)) modelPicker.show(current.model);
160
+ pickEl.title = "The model this link starts on";
161
+ pickEl.setAttribute("aria-label", "Model this link starts on");
162
+ } else {
163
+ pickEl.title = startPickTitle;
164
+ pickEl.setAttribute("aria-label", "Model for the new session");
165
+ }
166
+ }
167
+ // A command_ran with a model (stream_handlers.js): while a pick is in
168
+ // flight its ack syncs again.
169
+ function commandRan() {
170
+ if (pendingPick) pickRanEarly = true;
171
+ syncModelPick();
172
+ }
173
+ // Leaving a session: the start page's remembered model again (no fetch).
174
+ function restoreStartPick() {
175
+ modelPicker.restore(readStored(MODEL_KEY));
176
+ renderNewChatLlmContext();
177
+ renderNewChatThinking();
178
+ }
179
+ win.addEventListener("beforeunload", () => { pageLeaving = true; });
180
+ win.addEventListener("pagehide", () => { pageLeaving = true; });
181
+ win.addEventListener("pageshow", () => { pageLeaving = false; }); // back from the bfcache
182
+ // +asked+: + new session's load, for the start page it opens.
183
+ async function loadModels({ asked = false } = {}) {
184
+ let payload;
185
+ try {
186
+ payload = await listModels();
187
+ } catch (e) {
188
+ const text = modelsFailedText(e, { startPage: !selected(), asked, leaving: pageLeaving });
189
+ if (text) toast(text);
190
+ return;
191
+ }
192
+ const stored = readStored(MODEL_KEY);
193
+ if (!modelPicker.setModels(payload, stored)) return;
194
+ startPickTitle = payload.warning ? `${START_PICK_TITLE} · ${payload.warning}` : START_PICK_TITLE;
195
+ pickEl.hidden = false;
196
+ // A fresh link open meanwhile shows its own model again, not the stored one.
197
+ syncModelPick();
198
+ renderNewChatLlmContext();
199
+ renderNewChatThinking();
200
+ }
201
+ // The picker's choice for a create request; nothing (the server's default)
202
+ // while the list is not in.
203
+ function chosenModel() {
204
+ return pickEl.hidden ? undefined : modelPicker.chosen() || undefined;
205
+ }
206
+ // The create request's own choices (the chips').
207
+ function newChoices() {
208
+ return { llm_context: choiceWords(newChatLlmContext), thinking: newChatThinking || undefined };
209
+ }
210
+ // The choices were for that new session only: a create took them.
211
+ function clearChoices() {
212
+ newChatLlmContext = null;
213
+ renderNewChatLlmContext();
214
+ newChatThinking = null;
215
+ renderNewChatThinking();
216
+ }
217
+ // A session opened: the start page's choices were for a new session, they go.
218
+ function dropChoices() {
219
+ llmContextNewControl.close();
220
+ if (newChatLlmContext) {
221
+ newChatLlmContext = null;
222
+ renderNewChatLlmContext();
223
+ }
224
+ thinkingNewControl.close();
225
+ if (newChatThinking) {
226
+ newChatThinking = null;
227
+ renderNewChatThinking();
228
+ }
229
+ }
230
+
231
+ return {
232
+ syncModelPick, commandRan, restoreStartPick, loadModels, chosenModel, newChoices, clearChoices, dropChoices,
233
+ // A fresh link's /model still in flight (a send waits for it), or null.
234
+ pendingPick: () => pendingPick,
235
+ };
236
+ }
@@ -1,4 +1,4 @@
1
- // Where the toast sits (app.js placeToast measures, this decides): in a
1
+ // Where the toast sits (dock_reserve.js placeToast measures, this decides): in a
2
2
  // session, +gap+ above the highest of the composer card and what opens
3
3
  // over it (the stage while it shows, a fresh link's open model panel), so
4
4
  // it covers none of them; null elsewhere (the CSS's 24 px from the bottom).
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: samagotchi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.92.0
4
+ version: 0.94.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Dedov
@@ -248,6 +248,9 @@ files:
248
248
  - lib/samagotchi/bundles/loop-guard/plugin.rb
249
249
  - lib/samagotchi/bundles/mcp/manifest.yml
250
250
  - lib/samagotchi/bundles/mcp/plugin.rb
251
+ - lib/samagotchi/bundles/model-notes/manifest.yml
252
+ - lib/samagotchi/bundles/model-notes/model_notes_deepseek.md
253
+ - lib/samagotchi/bundles/model-notes/notes/README.md
251
254
  - lib/samagotchi/bundles/ruby/manifest.yml
252
255
  - lib/samagotchi/bundles/ruby/plugin.rb
253
256
  - lib/samagotchi/bundles/skills/manifest.yml
@@ -279,6 +282,7 @@ files:
279
282
  - lib/samagotchi/commands/registry.rb
280
283
  - lib/samagotchi/composer_route.rb
281
284
  - lib/samagotchi/config.rb
285
+ - lib/samagotchi/config/restart_watch.rb
282
286
  - lib/samagotchi/config_text_edit.rb
283
287
  - lib/samagotchi/context_absorber.rb
284
288
  - lib/samagotchi/context_command.rb
@@ -334,6 +338,7 @@ files:
334
338
  - lib/samagotchi/guardrails/model_size.rb
335
339
  - lib/samagotchi/guardrails/outside.rb
336
340
  - lib/samagotchi/guardrails/parent_approvals.rb
341
+ - lib/samagotchi/guardrails/parent_levels.rb
337
342
  - lib/samagotchi/guardrails/parent_policy.rb
338
343
  - lib/samagotchi/guardrails/protected_paths.rb
339
344
  - lib/samagotchi/guardrails/read_only_shell.rb
@@ -346,6 +351,7 @@ files:
346
351
  - lib/samagotchi/guardrails/shell_paths.rb
347
352
  - lib/samagotchi/guardrails/targets.rb
348
353
  - lib/samagotchi/guardrails/verdict.rb
354
+ - lib/samagotchi/hook_question.rb
349
355
  - lib/samagotchi/hook_routes.rb
350
356
  - lib/samagotchi/hooks.rb
351
357
  - lib/samagotchi/hooks/bundle_loader.rb
@@ -493,11 +499,14 @@ files:
493
499
  - lib/samagotchi/reminder_queue.rb
494
500
  - lib/samagotchi/reminder_store.rb
495
501
  - lib/samagotchi/reply_wait.rb
502
+ - lib/samagotchi/reply_wait/poll.rb
496
503
  - lib/samagotchi/row_refs.rb
497
504
  - lib/samagotchi/sampling_settings.rb
498
505
  - lib/samagotchi/sandbox_layout.rb
499
506
  - lib/samagotchi/self_report.rb
500
507
  - lib/samagotchi/send_command.rb
508
+ - lib/samagotchi/send_command/parent_gate.rb
509
+ - lib/samagotchi/send_command/wait_target.rb
501
510
  - lib/samagotchi/served_model.rb
502
511
  - lib/samagotchi/session.rb
503
512
  - lib/samagotchi/session_archive_command.rb
@@ -669,6 +678,7 @@ files:
669
678
  - lib/samagotchi/web/public/data.js
670
679
  - lib/samagotchi/web/public/delivery_line.js
671
680
  - lib/samagotchi/web/public/diff_view.js
681
+ - lib/samagotchi/web/public/dock_reserve.js
672
682
  - lib/samagotchi/web/public/families_view.js
673
683
  - lib/samagotchi/web/public/favicon.svg
674
684
  - lib/samagotchi/web/public/format.js
@@ -704,7 +714,9 @@ files:
704
714
  - lib/samagotchi/web/public/route.js
705
715
  - lib/samagotchi/web/public/scope.js
706
716
  - lib/samagotchi/web/public/scroll.js
717
+ - lib/samagotchi/web/public/send_turn.js
707
718
  - lib/samagotchi/web/public/sentences.js
719
+ - lib/samagotchi/web/public/session_actions.js
708
720
  - lib/samagotchi/web/public/session_state.js
709
721
  - lib/samagotchi/web/public/session_title.js
710
722
  - lib/samagotchi/web/public/sessions_list.js
@@ -714,6 +726,7 @@ files:
714
726
  - lib/samagotchi/web/public/stage_slots.js
715
727
  - lib/samagotchi/web/public/stage_view.js
716
728
  - lib/samagotchi/web/public/stage_watch.js
729
+ - lib/samagotchi/web/public/start_page.js
717
730
  - lib/samagotchi/web/public/storage.js
718
731
  - lib/samagotchi/web/public/stream_handlers.js
719
732
  - lib/samagotchi/web/public/strip.js