samagotchi 0.166.0 → 0.167.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 (83) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +63 -1
  3. data/docs/architecture.md +1 -0
  4. data/docs/cli.md +10 -5
  5. data/docs/configuration.md +1 -0
  6. data/docs/guardrails.md +6 -5
  7. data/docs/hooks.md +4 -6
  8. data/docs/internals/bundles.md +2 -4
  9. data/docs/internals/engine.md +4 -5
  10. data/docs/internals/objectives.md +141 -9
  11. data/docs/internals/remote-sessions.md +5 -6
  12. data/docs/internals/web-frontend.md +30 -25
  13. data/docs/memory.md +1 -2
  14. data/docs/sessions.md +20 -2
  15. data/docs/testing.md +4 -3
  16. data/lib/samagotchi/bridge.rb +1 -1
  17. data/lib/samagotchi/bundle_command/installed_check.rb +2 -14
  18. data/lib/samagotchi/bundle_command.rb +19 -11
  19. data/lib/samagotchi/bundles/system/manifest.yml +1 -1
  20. data/lib/samagotchi/cli/command.rb +10 -0
  21. data/lib/samagotchi/compat.rb +3 -11
  22. data/lib/samagotchi/config.rb +3 -0
  23. data/lib/samagotchi/context_command.rb +2 -1
  24. data/lib/samagotchi/engine/objectives.rb +20 -1
  25. data/lib/samagotchi/engine/side_requests.rb +3 -2
  26. data/lib/samagotchi/engine/turn_end.rb +4 -1
  27. data/lib/samagotchi/engine.rb +3 -0
  28. data/lib/samagotchi/extension_load.rb +2 -26
  29. data/lib/samagotchi/guardrails/approvals.rb +36 -13
  30. data/lib/samagotchi/jsonl_store.rb +61 -0
  31. data/lib/samagotchi/memory_bundle/status.rb +3 -15
  32. data/lib/samagotchi/memory_bundle/system_bundle.rb +16 -10
  33. data/lib/samagotchi/memory_command.rb +4 -2
  34. data/lib/samagotchi/objectives.rb +43 -14
  35. data/lib/samagotchi/objectives_backing.rb +124 -0
  36. data/lib/samagotchi/objectives_check.rb +19 -126
  37. data/lib/samagotchi/objectives_command.rb +14 -7
  38. data/lib/samagotchi/objectives_record.rb +104 -0
  39. data/lib/samagotchi/objectives_track.rb +353 -0
  40. data/lib/samagotchi/push_command.rb +2 -1
  41. data/lib/samagotchi/remote_command.rb +2 -1
  42. data/lib/samagotchi/reply_wait/poll.rb +6 -6
  43. data/lib/samagotchi/reply_wait.rb +4 -24
  44. data/lib/samagotchi/schedule_command.rb +6 -0
  45. data/lib/samagotchi/schedules.rb +1 -1
  46. data/lib/samagotchi/session_access/remote.rb +3 -5
  47. data/lib/samagotchi/session_commands.rb +1 -1
  48. data/lib/samagotchi/sessions_command.rb +12 -6
  49. data/lib/samagotchi/share_command.rb +2 -1
  50. data/lib/samagotchi/tool_activity.rb +11 -1
  51. data/lib/samagotchi/tool_declarations.rb +5 -1
  52. data/lib/samagotchi/tools/objectives_tool.rb +19 -2
  53. data/lib/samagotchi/turn_stages/objectives.rb +46 -3
  54. data/lib/samagotchi/version.rb +1 -1
  55. data/lib/samagotchi/web/participant_access.rb +1 -1
  56. data/lib/samagotchi/web/public/app.js +52 -424
  57. data/lib/samagotchi/web/public/copy.js +2 -1
  58. data/lib/samagotchi/web/public/index.html +35 -9
  59. data/lib/samagotchi/web/public/info_bar_model.js +3 -1
  60. data/lib/samagotchi/web/public/no_contact_fill.js +29 -0
  61. data/lib/samagotchi/web/public/objectives.css +14 -0
  62. data/lib/samagotchi/web/public/objectives_moves.js +82 -9
  63. data/lib/samagotchi/web/public/objectives_state.js +42 -0
  64. data/lib/samagotchi/web/public/objectives_strip.js +33 -9
  65. data/lib/samagotchi/web/public/objectives_track.js +52 -0
  66. data/lib/samagotchi/web/public/objectives_wiring.js +16 -1
  67. data/lib/samagotchi/web/public/participant.html +1 -1
  68. data/lib/samagotchi/web/public/participants_panel.js +14 -7
  69. data/lib/samagotchi/web/public/question_cards.js +7 -12
  70. data/lib/samagotchi/web/public/resync_reach.js +10 -6
  71. data/lib/samagotchi/web/public/scope.js +3 -3
  72. data/lib/samagotchi/web/public/session_rename.js +6 -2
  73. data/lib/samagotchi/web/public/session_state.js +1 -1
  74. data/lib/samagotchi/web/public/session_sync.js +249 -0
  75. data/lib/samagotchi/web/public/session_view.js +279 -0
  76. data/lib/samagotchi/web/public/stream_handlers.js +1 -1
  77. data/lib/samagotchi/web/public/tokens.css +2 -2
  78. data/lib/samagotchi/web/public/turn_block.js +8 -0
  79. data/lib/samagotchi/web/public/turn_html.js +1 -1
  80. data/lib/samagotchi/web/public/widget_picks.js +3 -0
  81. data/lib/samagotchi/web/public/working_set_view.js +1 -1
  82. data/lib/samagotchi/web/session_access_routes.rb +4 -15
  83. metadata +10 -1
@@ -0,0 +1,279 @@
1
+ // The open session's view (split out of app.js): forgetSession() starts the
2
+ // page over for another session, renderSessionView() draws a read of it (the
3
+ // history, the replayed turn in progress, the cards, a pending question),
4
+ // readTurnEnd() re-reads a turn's end, endTurnView() closes a turn's
5
+ // rendering. Kept in app.js's order: their DOM placements depend on it.
6
+ //
7
+ // Everything that changes while the page runs is read through deps at the
8
+ // call, never captured at creation (as stream_handlers.js): the open session
9
+ // (store.selected), its fields (store.current), the page's capabilities
10
+ // (capabilities()), the views made after this one (the getters in +later+).
11
+ //
12
+ // deps:
13
+ // store the page's session store (session_store.js)
14
+ // historyEl the history element
15
+ // getSession(id, opts) data.js
16
+ // liveTurn, turnDom, questionCards, shownTexts, objectives, featureGates, markdownTip
17
+ // the page's views
18
+ // workingSet the stage view's working set (web.working_set), null when off
19
+ // gapClock the page's last activity (time_gaps.js createGapClock)
20
+ // bubbles, cards bubbles.js, cards_place.js
21
+ // markdown markdown_place.js (linkTextRefs, applyFinalMarkdown)
22
+ // capabilities() the page's capabilities (card.js shownElsewhere, the history's cards)
23
+ // page: {setReviseAnchor(anchor), renderInitRow(), setMarkdownWarning(warning),
24
+ // setCapabilities(capabilities, editorUrl), findInTurnRoots(selector), appendToHistory(el),
25
+ // setTurnRunning(running), mergeTurnTiming(id, timing), applySessionPayload(data, opts),
26
+ // turnEndStatus(data), replaceSelectedCard(change)} the page's hooks
27
+ // later: {handlers(), composer(), ownerVerify(), commandList(), initTasks(), resetTurnView()}
28
+ // the views made after this one, and session_sync.js's resetTurnView
29
+ //
30
+ // @return {forgetSession, renderSessionView, historyOpts, readTurnEnd, endTurnView}
31
+ // Its own module: new exports go in new modules (web-frontend.md).
32
+
33
+ import { emptySessionState, sessionStateFrom } from "./session_state.js";
34
+ import { seedInitTasks } from "./init_row.js";
35
+ import { restoreCommandBubbles } from "./commands.js";
36
+ import { failedTurnText, normalize } from "./format.js";
37
+ import { splitSnapshotCards } from "./card.js";
38
+ import { turnGroups } from "./timing.js";
39
+ import { groupItems } from "./working_set_view.js";
40
+ import { thumbsTemplate } from "./images.js";
41
+ import { hintEl, outputBubbleTemplate } from "./bubbles.js";
42
+ import { turnHistoryNodes } from "./turn_block.js";
43
+ import { lastActivity } from "./time_gaps.js";
44
+ import { elementOf, emptyAnswerTemplate } from "./turn_html.js";
45
+ import { stillOn } from "./latest.js";
46
+
47
+ export function createSessionView(deps) {
48
+ const {
49
+ store, historyEl, getSession,
50
+ liveTurn, turnDom, questionCards, shownTexts, objectives, featureGates, markdownTip, workingSet = null, gapClock,
51
+ bubbles, cards, markdown, capabilities, page, later,
52
+ } = deps;
53
+ const { makeUserBubble, addEndBubble, showGuardrailWarning, showRecap } = bubbles;
54
+ const { placeSnapshotCards, upsertCard } = cards;
55
+ const { linkTextRefs, applyFinalMarkdown } = markdown;
56
+ const {
57
+ setReviseAnchor, renderInitRow, setMarkdownWarning, setCapabilities, findInTurnRoots, appendToHistory,
58
+ setTurnRunning, mergeTurnTiming, applySessionPayload, turnEndStatus, replaceSelectedCard,
59
+ } = page;
60
+ // The open session's id, for the stale-answer guards (latest.js stillOn).
61
+ const openId = () => store.selected;
62
+
63
+ // Forget everything the page knew about the open session: its fields (the
64
+ // info bar, composer, command list), the turn on view, its stream and
65
+ // question cards, its init row, the payload's markdown warning and tip and
66
+ // capabilities, and the composer's Verify claim and Revise (+keepVerify+:
67
+ // the same session opened again keeps them). The one reset list select() and
68
+ // clearSelection() share, so a field the previous session set (its
69
+ // "delegated by" parent, its commands, its card actions) never shows for
70
+ // the next one, also when the next one's read fails.
71
+ function forgetSession({ keepVerify = false } = {}) {
72
+ if (!keepVerify) later.ownerVerify().clear();
73
+ if (!keepVerify) setReviseAnchor(null);
74
+ store.batch(() => {
75
+ store.replaceCurrent(emptySessionState());
76
+ featureGates.prime(store.current);
77
+ });
78
+ later.commandList().close();
79
+ later.resetTurnView();
80
+ objectives.reset();
81
+ seedInitTasks(later.initTasks(), []);
82
+ renderInitRow();
83
+ setMarkdownWarning(null);
84
+ markdownTip.show(null);
85
+ setCapabilities(null, null);
86
+ later.composer().newVisit();
87
+ }
88
+
89
+ // A session view: its messages, then the turn in progress and the queued
90
+ // prompts (a live worker's snapshot) replayed through the stream handlers,
91
+ // then a pending question.
92
+ function renderSessionView(data, { kept = [] } = {}) {
93
+ setMarkdownWarning(data.markdown_warning);
94
+ markdownTip.show(data.markdown_tip);
95
+ setCapabilities(data.capabilities, data.editor_url);
96
+ // The saved fill (when there is one) goes in here too, so a reloaded or
97
+ // stopped session shows it before its next turn (a running turn's replay
98
+ // below streams over it).
99
+ const { status, ...fields } = sessionStateFrom(data);
100
+ // The fields in one batch (their chips' popovers, the bar); the replay's
101
+ // own redraws below stay where they run.
102
+ store.batch(() => {
103
+ store.update({ current: fields });
104
+ store.setStatus(status, "payload");
105
+ featureGates.prime(store.current);
106
+ });
107
+ liveTurn.timing.ended = store.current.timing.turnRecords.length;
108
+ const activeTurnId = store.current.timing.activeTurn?.id || null;
109
+ if (data.messages && data.messages.length) renderHistory(data.messages, data);
110
+ else renderHistory(data.history || []);
111
+ seedWorkingSet(data);
112
+ objectives.seed(data.objectives);
113
+ restoreCommandBubbles(historyEl, kept);
114
+ // A failed turn's prompt went back to the user: shown after the
115
+ // conversation, marked failed, as it was live (prompt_restored).
116
+ const failedPrompt = data.failed_turn ? makeUserBubble(data.failed_turn.prompt, { state: "failed" }) : null;
117
+ if (failedPrompt) {
118
+ failedPrompt.dataset.failedTurn = "1";
119
+ addEndBubble(failedTurnText(data.failed_turn));
120
+ }
121
+ seedSeenFromDom();
122
+ seedInitTasks(later.initTasks(), data.init_tasks);
123
+ renderInitRow();
124
+ // A guardrail file that failed to load, announced before this page
125
+ // joined: where it came (the snapshot's cards), else at the end.
126
+ const loadWarned = (label) => (data.cards || []).some((c) => c?.type === "guardrail_warning" && (c.label || "guardrails") === label);
127
+ if (!loadWarned("guardrails")) showGuardrailWarning(data.guardrail_warning);
128
+ if (!loadWarned("plugins")) showGuardrailWarning(data.plugin_warning, "plugins");
129
+ // A live worker's last cards and between-turns notices, where they
130
+ // arrived; the running turn's go into its step once it is drawn.
131
+ const snapshotCards = splitSnapshotCards(data.cards, capabilities());
132
+ // Above a failed turn's prompt: it came after them, and it is no turn.
133
+ placeSnapshotCards(snapshotCards.placed, { before: failedPrompt });
134
+ // The recap saved with the session (also a stopped one's), else a live
135
+ // worker's from before saved_recap existed. After the cards: the last
136
+ // turn's check-in notice goes to the end, and the recap closes the page.
137
+ const saved = data.saved_recap;
138
+ if (saved) showRecap(saved.text, saved.turns_since, saved.created_at || null, saved.opening_id || null);
139
+ else showRecap(data.recap);
140
+ // chi web's unfold of the join (TurnAccumulator.join_events): the turn in
141
+ // progress and the queue behind it as the live events that draw them.
142
+ const replay = data.replay ?? [];
143
+ // Marked replayed: a call's duration isn't timed from the replay's clock.
144
+ replay.forEach((event) => later.handlers()[event.type]?.({ ...event, replayed: true }));
145
+ // A join mid-generation: the worker's word on it clocks the delivery line.
146
+ const gen = data.current_turn?.generation;
147
+ liveTurn.serverGen = gen ? { ...gen, at: Date.now() } : null;
148
+ if (!data.current_turn) {
149
+ setTurnRunning(store.current.status === "running");
150
+ // Running with no turn to draw: the stage's status row still holds Stop turn.
151
+ turnDom.runningWithoutTurn?.(liveTurn.running);
152
+ if (liveTurn.running && store.current.timing.activeTurn?.started_at) liveTurn.timing.start(store.current.timing.activeTurn.started_at, activeTurnId);
153
+ } else if (liveTurn.running) {
154
+ // The live line's turn: the running turn's record's (the replayed
155
+ // turn_started carries the same id, on both unfolds).
156
+ liveTurn.timing.turnId = activeTurnId;
157
+ }
158
+ turnDom.flush();
159
+ snapshotCards.current.forEach((card) => upsertCard(card));
160
+ snapshotCards.during.forEach((card) => upsertCard(card));
161
+ // A question the worker is blocked on (also after a reload).
162
+ if (data.pending_question && data.pending_question.id && data.pending_question.status === "pending") {
163
+ // Its refs on the asking step, as question_requested puts them.
164
+ if (data.pending_question.refs) turnDom.questionRefs(data.pending_question.refs);
165
+ questionCards.renderQuestion(data.pending_question);
166
+ // The turn's replay drew it as asked; the snapshot knows whether it is
167
+ // relayed to the parent now.
168
+ questionCards.markRelayed(data.pending_question.id, data.pending_question.relayed_to || null);
169
+ }
170
+ // A turn ran out of iterations and waits for a yes or no.
171
+ if (data.continue_offer) questionCards.renderContinue(data.continue_offer);
172
+ // A whole view drawn: the composer and the bar once more (the working
173
+ // set's seed may change the bar's chip).
174
+ store.batch(() => {
175
+ store.touch("composer");
176
+ store.touch("infoBar");
177
+ });
178
+ }
179
+
180
+ // The working set's turns from a session's messages, as turnHistoryNodes
181
+ // numbers them: the drawn ones (the running turn, which the replay draws
182
+ // in the stage, has no drawing yet).
183
+ function seedWorkingSet(data) {
184
+ if (!workingSet) return;
185
+ const items = data.messages || [];
186
+ const groups = typeof items[0] === "object" && items[0]?.role ? turnGroups(items, store.current.timing, { drawings: data.turn_drawings }).filter((g) => g.kind === "turn") : [];
187
+ workingSet.seed(groups.map((g, i) => {
188
+ const text = String(items[g.user]?.content ?? "").replace(/\s+/g, " ").trim();
189
+ return { items: groupItems(g, i), prompt: text.length > 60 ? `${text.slice(0, 59)}\u2026` : text };
190
+ }));
191
+ }
192
+
193
+ // turnHistoryNodes' options for a read's +data+: its turns' drawings
194
+ // (turn_drawing.js), cards (a drawn card's body) and the running turn's id
195
+ // (its prompt has no drawing yet: a plain row, no miss).
196
+ const historyOpts = (data = {}) => ({ thumbs: (images) => thumbsTemplate(store.selected, images), workingSet: !!workingSet,
197
+ drawings: data.turn_drawings || null, cards: data.cards || null, capabilities: capabilities(),
198
+ runningTurnId: data.current_turn?.turn_id || null });
199
+
200
+ function renderHistory(items, data = {}) {
201
+ gapClock.seed(null);
202
+ if (!items.length) {
203
+ historyEl.replaceChildren(hintEl("No output yet. Send a message."));
204
+ return;
205
+ }
206
+ if (typeof items[0] === "object" && items[0].role) {
207
+ historyEl.replaceChildren(turnHistoryNodes(items, store.current.timing, historyOpts(data)));
208
+ later.ownerVerify().renderSaved();
209
+ // The live dividers count from the history's last activity.
210
+ gapClock.seed(lastActivity(turnGroups(items, store.current.timing, { drawings: data.turn_drawings }), items));
211
+ linkTextRefs();
212
+ } else {
213
+ historyEl.replaceChildren(...items.map((c) => elementOf(outputBubbleTemplate(c))));
214
+ }
215
+ historyEl.scrollTop = historyEl.scrollHeight;
216
+ }
217
+
218
+ async function readTurnEnd() {
219
+ if (!store.selected) return;
220
+ const id = store.selected;
221
+ // The line and the turn this read is for, before the await: a turn
222
+ // queued behind this one may start (a new live line) before it lands.
223
+ const line = liveTurn.timing.capture();
224
+ const still = stillOn(openId);
225
+ try {
226
+ const d = await getSession(id, { tail: true, recent: true, turnId: line.turnId });
227
+ if (!still()) return;
228
+ if (d.session) {
229
+ if (!(await mergeTurnTiming(id, d.timing))) return;
230
+ liveTurn.timing.finishLine(line);
231
+ // The rest in one batch: the bar and the lists redraw once, after the
232
+ // answer's markdown.
233
+ store.batch(() => {
234
+ // The notes chip: the first turn's build (or a /model) records them.
235
+ applySessionPayload(d, { fields: ["usedMemories", "promptNotes"] });
236
+ turnEndStatus(d);
237
+ setMarkdownWarning(d.markdown_warning);
238
+ markdownTip.show(d.markdown_tip);
239
+ setCapabilities(d.capabilities, d.editor_url);
240
+ if (Array.isArray(d.messages)) applyFinalMarkdown(d.messages);
241
+ // Its card, replaced (replaceSelectedCard).
242
+ replaceSelectedCard((sess) => ({ ...sess, used_memory_names: store.current.usedMemories.slice(), status: store.current.status }));
243
+ });
244
+ }
245
+ } catch (_) {
246
+ // A failed read (the server or worker gone a moment) leaves the answer
247
+ // as the stream drew it, plain text: the session's next load renders it.
248
+ }
249
+ }
250
+
251
+ function seedSeenFromDom() {
252
+ shownTexts.seed(findInTurnRoots(".bubble").map((b) => normalize(b.textContent)));
253
+ }
254
+
255
+ // Everything a turn's end (completed, canceled, failed) closes: then its
256
+ // end line (+endText+, the cancel or failed line), then the step cards that
257
+ // left the collapsed block (card.js leavesBlock), where a reload puts them.
258
+ function endTurnView(kind, endText = null, { emptyAnswer = null, stopped = false } = {}) {
259
+ setTurnRunning(false);
260
+ // Every ended turn has a record (completed, canceled, failed); a worker
261
+ // gone mid-turn is re-rendered (resync), which counts again.
262
+ if (kind !== "gone") liveTurn.timing.ended += 1;
263
+ // A completed turn with no answer: its notice where the answer goes
264
+ // (the turn block places it), else after the turn; before the timing.
265
+ const endNote = emptyAnswer ? elementOf(emptyAnswerTemplate(emptyAnswer)) : null;
266
+ const kept = turnDom.turnEnded({ kind, endNote, emptyAnswer: !!emptyAnswer, turnId: liveTurn.timing.turnId }) || [];
267
+ if (endNote && !endNote.isConnected) appendToHistory(endNote);
268
+ liveTurn.timing.finish({ canceled: kind === "canceled" });
269
+ if (endText) addEndBubble(endText, { stopped });
270
+ if (kept.length) {
271
+ kept.forEach((el) => appendToHistory(el));
272
+ if (!turnDom.holds()) historyEl.scrollTop = historyEl.scrollHeight;
273
+ }
274
+ // The question dies with its turn (the worker stopped waiting).
275
+ if (questionCards.pendingQuestion()) questionCards.resolveQuestion(questionCards.pendingQuestion().id, { cancelled: true, reason: "turn ended" });
276
+ }
277
+
278
+ return { forgetSession, renderSessionView, historyOpts, readTurnEnd, endTurnView };
279
+ }
@@ -4,7 +4,7 @@
4
4
  //
5
5
  // Everything that changes while the page runs is read through deps at the
6
6
  // event, never captured at creation: the open session (selected()), its
7
- // fields (store.current: app.js forgetSession replaces the object), the page's
7
+ // fields (store.current: session_view.js forgetSession replaces the object), the page's
8
8
  // capabilities, the composer's text. A session switch mid-stream is handled
9
9
  // as before: the handlers act on whatever is open when the event comes.
10
10
  //
@@ -1,12 +1,12 @@
1
1
  /* The web UI's colour tokens, shared by the owner's page (index.html) and the participant page (participant.html): the dark :root (the default) and the light set under prefers-color-scheme: light. Everything else reads them through var(). */
2
- :root{color-scheme:dark;--bg:#0b0d11;--bg-panel:#151821;--bg-inset:#0f1115;--bg-raised:#22262f;--bg-hover:#1b1f27;--border:#1f232b;--border-strong:#2d333f;--text:#e6e8eb;--text-bright:#f0f3f6;--text-2:#c9d1d9;--text-3:#9aa4b2;--text-muted:#8b949e;--text-faint:#6e7681;--accent:#5aa9ff;--accent-strong:#0071e3;--accent-bg:#0f2340;--accent-ring:rgba(90,169,255,.18);--primary:#0071e3;--ok:#3fb950;--ok-text:#7ee787;--ok-bg:#1a2e1a;--warn:#d29922;--warn-text:#e3b341;--warn-bright:#f2cc60;--warn-bg:#2b2108;--warn-border:#6b5416;--danger:#f85149;--danger-bg:#da3633;--danger-text:#ff7b72;--danger-bg-dim:#3d1f1f;--think:#8957e5;--think-text:#d2a8ff;--accent-border:#1a3458;--pick-border:#79c0ff;--accent-tint:color-mix(in srgb,var(--accent) 7%,transparent);--narr:color-mix(in srgb,var(--accent) 38%,var(--text-muted));
2
+ :root{color-scheme:dark;--bg:#0b0d11;--bg-top:#131d29;--bg-panel:#151821;--bg-inset:#0f1115;--bg-raised:#22262f;--bg-hover:#1b1f27;--border:#1f232b;--border-strong:#2d333f;--text:#e6e8eb;--text-bright:#f0f3f6;--text-2:#c9d1d9;--text-3:#9aa4b2;--text-muted:#8b949e;--text-faint:#6e7681;--accent:#5aa9ff;--accent-strong:#0071e3;--accent-bg:#0f2340;--accent-ring:rgba(90,169,255,.18);--primary:#0071e3;--ok:#3fb950;--ok-text:#7ee787;--ok-bg:#1a2e1a;--warn:#d29922;--warn-text:#e3b341;--warn-bright:#f2cc60;--warn-bg:#2b2108;--warn-border:#6b5416;--danger:#f85149;--danger-bg:#da3633;--danger-text:#ff7b72;--danger-bg-dim:#3d1f1f;--think:#8957e5;--think-text:#d2a8ff;--accent-border:#1a3458;--pick-border:#79c0ff;--accent-tint:color-mix(in srgb,var(--accent) 7%,transparent);--narr:color-mix(in srgb,var(--accent) 38%,var(--text-muted));
3
3
  --glass-bg:color-mix(in srgb,var(--bg-panel) 70%,transparent);--glass-border:rgba(255,255,255,.08);--glass-highlight:rgba(255,255,255,.05);--glass-shadow:0 8px 30px rgba(0,0,0,.35);
4
4
  --diff-add-bg:rgba(63,185,80,.14);--diff-add-text:#aff5b4;--diff-del-bg:rgba(248,81,73,.14);--diff-del-text:#ffc1bc;
5
5
  --code-text:#c9d1d9;--code-keyword:#ff7b72;--code-string:#a5d6ff;--code-comment:#8b949e;--code-constant:#79c0ff;--code-func:#d2a8ff;--code-type:#ffa657;
6
6
  --card-hover-border:rgba(255,255,255,.14);--on-solid:#fff;--on-warn:#fff;--text-hover:#fff;--badge-bg:rgba(255,255,255,.08);--badge-ring:rgba(255,255,255,.18);--shadow-strong:rgba(0,0,0,.5);--backdrop:rgba(0,0,0,.85);--toast-shadow:0 6px 24px rgba(0,0,0,.25);--ws-stale-opacity:.4;--ws-rule:var(--border-strong);--ws-muted:var(--text-3);--ws-faint:var(--text-muted);--ws-act-border:#444c56;--author-1:#79c0ff;--author-2:#d2a8ff;--author-3:#7ee787;--author-4:#ffa657;--author-5:#ff7b72;--author-6:#f2cc60;--author-owner:var(--text-3);--time-gap:var(--text-faint);
7
7
  --claim-mark:color-mix(in srgb,var(--warn-bright) 32%,transparent);--claim-ring:var(--warn)}
8
8
  /* Light palette: follows the system setting. :not([data-theme="dark"]) leaves room for a later in-page toggle (data-theme on <html>); there is none yet. Each palette sets color-scheme, so native radios, inputs and scrollbars follow it. */
9
- @media (prefers-color-scheme:light){:root:not([data-theme="dark"]){color-scheme:light;--bg:#f5f6f8;--bg-panel:#ffffff;--bg-inset:#f1f3f6;--bg-raised:#e8ebf0;--bg-hover:#eceff4;--border:#dde1e7;--border-strong:#c3c9d2;--text:#1f2328;--text-bright:#0d1117;--text-2:#2f363d;--text-3:#475160;--text-muted:#57606a;--text-faint:#636c76;--accent:#0066cc;--accent-strong:#0058b0;--accent-bg:#e3f0ff;--accent-ring:rgba(0,102,204,.2);--primary:#0071e3;--ok:#1a7f37;--ok-text:#116329;--ok-bg:#dafbe1;--warn:#9a6700;--warn-text:#7d4e00;--warn-bright:#875c00;--warn-bg:#fff6cc;--warn-border:#d4a72c;--danger:#cf222e;--danger-bg:#cf222e;--danger-text:#a40e26;--danger-bg-dim:#ffebe9;--think:#8250df;--think-text:#6639ba;--accent-border:#b3d4f7;--pick-border:#0969da;
9
+ @media (prefers-color-scheme:light){:root:not([data-theme="dark"]){color-scheme:light;--bg:#f5f6f8;--bg-top:#dde8f4;--bg-panel:#ffffff;--bg-inset:#f1f3f6;--bg-raised:#e8ebf0;--bg-hover:#eceff4;--border:#dde1e7;--border-strong:#c3c9d2;--text:#1f2328;--text-bright:#0d1117;--text-2:#2f363d;--text-3:#475160;--text-muted:#57606a;--text-faint:#636c76;--accent:#0066cc;--accent-strong:#0058b0;--accent-bg:#e3f0ff;--accent-ring:rgba(0,102,204,.2);--primary:#0071e3;--ok:#1a7f37;--ok-text:#116329;--ok-bg:#dafbe1;--warn:#9a6700;--warn-text:#7d4e00;--warn-bright:#875c00;--warn-bg:#fff6cc;--warn-border:#d4a72c;--danger:#cf222e;--danger-bg:#cf222e;--danger-text:#a40e26;--danger-bg-dim:#ffebe9;--think:#8250df;--think-text:#6639ba;--accent-border:#b3d4f7;--pick-border:#0969da;
10
10
  --glass-border:rgba(31,35,40,.10);--glass-highlight:rgba(255,255,255,.7);--glass-shadow:0 8px 30px rgba(31,35,40,.10);
11
11
  --diff-add-bg:rgba(26,127,55,.12);--diff-add-text:#116329;--diff-del-bg:rgba(207,34,46,.10);--diff-del-text:#82071e;
12
12
  --code-text:#1f2328;--code-keyword:#cf222e;--code-string:#0a3069;--code-comment:#57606a;--code-constant:#0550ae;--code-func:#8250df;--code-type:#953800;
@@ -23,6 +23,7 @@
23
23
  // closed with text keeps its chrome: a line steered in after it left it alone
24
24
  // in the block when the answer went, and its summary is the way to its text.
25
25
  import { authorBadge, PAIR } from "./participant_names.js";
26
+ import { isParticipantAuthor } from "./participant_model.js";
26
27
  import { applyRowTemplate } from "./review_apply.js";
27
28
  import { html, nothing, render } from "./vendor/lit-html.js";
28
29
  import { answerRefsOf, setAnswerRefs } from "./answer_refs.js";
@@ -502,6 +503,8 @@ export function createTurnBlock({
502
503
  el = document.createElement("div");
503
504
  el.className = "activity-row";
504
505
  el.dataset.key = r.row.key;
506
+ // What the row ran, for what reads a finished block (objectives_moves.js).
507
+ if (r.row.tool) el.dataset.tool = r.row.tool;
505
508
  entry.rows.set(r.row.key, el);
506
509
  drawRow(el, r.row);
507
510
  addItem(entry, el);
@@ -653,6 +656,8 @@ export function createTurnBlock({
653
656
  if (blockEl) {
654
657
  updateBlockSummary();
655
658
  blockEl.classList.add("done");
659
+ // How it ended (completed, canceled, failed), live and reloaded alike.
660
+ blockEl.dataset.end = kind;
656
661
  // The outline (turn_model.js outlineRuns), for when it is opened. Closed
657
662
  // as a reload draws it, unless the turn was cut short (block_open.js).
658
663
  // The stage decides again as the block reaches the history.
@@ -701,6 +706,8 @@ export function createTurnBlock({
701
706
  reset();
702
707
  turn = model.newTurn();
703
708
  createBlock();
709
+ // A participant's turn says so on its block (a reload's: drawnGroupPieces).
710
+ if (isParticipantAuthor(data.author || data.origin?.author)) blockEl.dataset.participant = "1";
704
711
  const r = model.turnStarted(turn);
705
712
  apply(r);
706
713
  if (data.prompt) {
@@ -1002,6 +1009,7 @@ export function turnHistoryNodes(items, timing, { thumbs, workingSet = false, no
1002
1009
  const prompt = group.user != null ? items[group.user] : null;
1003
1010
  const drawn = drawnTurnNodes(group, items, { thumbs, capabilities, cards });
1004
1011
  if (drawn.block) {
1012
+ if (isParticipantAuthor(prompt?.author)) drawn.block.dataset.participant = "1";
1005
1013
  if (workingSet) drawn.block.querySelector(":scope > summary > .tw-sum")?.prepend(nodesOf(footprintTemplate(groupItems(group, ordinal), ordinal)));
1006
1014
  blockTurns.push(ordinal);
1007
1015
  }
@@ -149,7 +149,7 @@ function tailClip(text) {
149
149
  // +stop+: the live row's stop-task button (a node), after the title.
150
150
  export function toolRowTemplate(row, opts = {}) {
151
151
  const wrong = row.guardrail?.should_have_asked ? " guardrail-wrong" : "";
152
- return html`<div class=${`activity-row${wrong}`} data-key=${row.key}>${toolRowInnerTemplate(row, opts)}</div>`;
152
+ return html`<div class=${`activity-row${wrong}`} data-key=${row.key} data-tool=${row.tool || nothing}>${toolRowInnerTemplate(row, opts)}</div>`;
153
153
  }
154
154
 
155
155
  export function toolRowInnerTemplate(row, { thumbs = () => nothing, stop = nothing } = {}) {
@@ -11,6 +11,8 @@
11
11
  //
12
12
  // A module of its own: static JS is cached at unversioned URLs.
13
13
 
14
+ import { noContactFill } from "./no_contact_fill.js";
15
+
14
16
  // What a row starts with: its recommended option picked, no note.
15
17
  export function initialPicks(rows) {
16
18
  return (rows || []).map((r) => ({ pick: r.recommended != null ? String(r.recommended) : null, note: "" }));
@@ -91,6 +93,7 @@ export function drawPicks(picks, { fill, doc = document }) {
91
93
  add.addEventListener("click", () => {
92
94
  const input = el(doc, "input", "wp-note");
93
95
  input.type = "text";
96
+ noContactFill(input, "chi-pick-note", { prose: true });
94
97
  input.placeholder = "a word for this row";
95
98
  input.setAttribute("aria-label", `Note for ${id}`);
96
99
  input.addEventListener("input", () => { state[k].note = input.value; });
@@ -344,7 +344,7 @@ export function createWorkingSet({ historyEl, stageRoot = () => null, state, ses
344
344
  ${urls.length ? html`<div class="ctx-pop-meta">urls · ${urls.length}</div>${labelsTemplate(fold(urls, POP_BUDGET).labels, opts)}` : nothing}
345
345
  ${added.length ? html`<div class="ctx-pop-meta">adding · ${added.length}</div>${added.map((it) => rowTemplate(it, opts))}` : nothing}
346
346
  ${pend.size ? html`<div class="ws-pending" role="status"><span class="ws-pending-t">${pend.size} change${pend.size === 1 ? "" : "s"} pending<span class="ws-pending-when"> · apply at the next turn's start</span></span><button type="button" class="ws-act-b" data-ws="undo-all">undo all</button></div>` : nothing}
347
- ${sendLine ? html`<form class="ws-add" data-ws="add-form"><input class="ws-add-in" type="text" name="key" placeholder="+ path, memory:NAME or URL" aria-label="Add to the working set: a path, memory:NAME or a URL" autocomplete="off" autocapitalize="off" spellcheck="false" enterkeyhint="go"><button type="submit" class="ws-act-b">add</button></form>` : nothing}
347
+ ${sendLine ? html`<form class="ws-add" data-ws="add-form"><input class="ws-add-in" type="text" name="key" placeholder="+ path, memory:ENTRY or URL" aria-label="Add to the working set: a path, memory:ENTRY or a URL" autocomplete="off" autocapitalize="off" spellcheck="false" enterkeyhint="go"><button type="submit" class="ws-act-b">add</button></form>` : nothing}
348
348
  <div class="ctx-pop-meta ws-hint">A file opens its ref; a step tag goes to the call.${sendLine ? " Drop sends stubs instead of an item's reads from the next turn; add asks the model to read one first." : ""}${sendLine && forget ? " Pin keeps an item from the model's forget." : ""} Esc closes.</div>`;
349
349
  render(tpl, popover.pop);
350
350
  }
@@ -188,16 +188,13 @@ module Samagotchi
188
188
  # (SessionAccess::Local#wait_reply). Body: cursor, baseline
189
189
  # ({messages, question_id, last_turn}, as the prepare route gave it),
190
190
  # turn, queued, ended_before, owner_grace (seconds, null: wait for
191
- # whatever wakes a worker), timeout (seconds, capped), running_look
192
- # (the last timeout's, as it came). 200: the ReplyWait::Result's
191
+ # whatever wakes a worker), timeout (seconds, capped); a 0.165
192
+ # client's running_look is ignored. 200: the ReplyWait::Result's
193
193
  # fields (status: done, waiting_for_answer, no_reply, error, stopped,
194
194
  # timeout or worker_gone; text, file, question, outcome, …; never the
195
195
  # Session) and parent_strategy, what a parent may pick on the
196
196
  # session's questions here (ParentReport.strategy_for). A timeout
197
- # status: ask again, with its running_look ({last_end, claimed}, or
198
- # null: the running turn this slice saw, so a settle between two
199
- # slices still ends the wait). 503 server_stopping when chi web stops
200
- # mid-wait.
197
+ # status: ask again. 503 server_stopping when chi web stops mid-wait.
201
198
  def handle_wait(req, id)
202
199
  body = body_hash(req) or return error_response(400, "invalid_json", "invalid JSON body")
203
200
  options, error = wait_options(body)
@@ -229,15 +226,8 @@ module Samagotchi
229
226
  end
230
227
 
231
228
  timeout = [numbers["timeout"] || WAIT_MAX_SECONDS, WAIT_MAX_SECONDS].min
232
- look = body["running_look"]
233
- running_look = look.nil? ? nil : ReplyWait::RunningLook.from_h(look)
234
- if !look.nil? && running_look.nil?
235
- return [nil, error_response(400, "invalid_wait", "running_look is {last_end, claimed: [file names]}")]
236
- end
237
-
238
229
  [{ cursor: strings["cursor"], turn: strings["turn"], baseline: baseline, timeout: timeout,
239
- owner_grace: numbers["owner_grace"], queued: body["queued"] == true, ended_before: body["ended_before"] == true,
240
- running_look: running_look }, nil]
230
+ owner_grace: numbers["owner_grace"], queued: body["queued"] == true, ended_before: body["ended_before"] == true }, nil]
241
231
  end
242
232
 
243
233
  def wait_baseline(raw)
@@ -258,7 +248,6 @@ module Samagotchi
258
248
  RESULT_FIELDS.each { |key| json[key] = result[key] }
259
249
  json[:text] = json[:text]&.dup&.force_encoding(Encoding::UTF_8)&.scrub
260
250
  json[:question] = result.question&.to_file
261
- json[:running_look] = result.running_look&.to_h
262
251
  json[:parent_strategy] = strategy_json(strategy)
263
252
  json
264
253
  end
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.166.0
4
+ version: 0.167.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Dedov
@@ -460,6 +460,7 @@ files:
460
460
  - lib/samagotchi/installed_versions.rb
461
461
  - lib/samagotchi/interrupted_turn.rb
462
462
  - lib/samagotchi/iteration_limit.rb
463
+ - lib/samagotchi/jsonl_store.rb
463
464
  - lib/samagotchi/judgments_command.rb
464
465
  - lib/samagotchi/kernel_loop.rb
465
466
  - lib/samagotchi/last_turn.rb
@@ -563,9 +564,12 @@ files:
563
564
  - lib/samagotchi/note_move.rb
564
565
  - lib/samagotchi/objectives.rb
565
566
  - lib/samagotchi/objectives_audit.rb
567
+ - lib/samagotchi/objectives_backing.rb
566
568
  - lib/samagotchi/objectives_check.rb
567
569
  - lib/samagotchi/objectives_command.rb
568
570
  - lib/samagotchi/objectives_edit.rb
571
+ - lib/samagotchi/objectives_record.rb
572
+ - lib/samagotchi/objectives_track.rb
569
573
  - lib/samagotchi/output_formatter.rb
570
574
  - lib/samagotchi/owner_lock.rb
571
575
  - lib/samagotchi/owner_prompt.rb
@@ -978,6 +982,7 @@ files:
978
982
  - lib/samagotchi/web/public/model_pick.js
979
983
  - lib/samagotchi/web/public/model_picker.js
980
984
  - lib/samagotchi/web/public/more_sheet.js
985
+ - lib/samagotchi/web/public/no_contact_fill.js
981
986
  - lib/samagotchi/web/public/notice_links.js
982
987
  - lib/samagotchi/web/public/notifications.js
983
988
  - lib/samagotchi/web/public/notify.js
@@ -985,7 +990,9 @@ files:
985
990
  - lib/samagotchi/web/public/objectives_entry.js
986
991
  - lib/samagotchi/web/public/objectives_model.js
987
992
  - lib/samagotchi/web/public/objectives_moves.js
993
+ - lib/samagotchi/web/public/objectives_state.js
988
994
  - lib/samagotchi/web/public/objectives_strip.js
995
+ - lib/samagotchi/web/public/objectives_track.js
989
996
  - lib/samagotchi/web/public/objectives_wiring.js
990
997
  - lib/samagotchi/web/public/owner_claim.js
991
998
  - lib/samagotchi/web/public/owner_verify.js
@@ -1028,7 +1035,9 @@ files:
1028
1035
  - lib/samagotchi/web/public/session_rename.js
1029
1036
  - lib/samagotchi/web/public/session_state.js
1030
1037
  - lib/samagotchi/web/public/session_store.js
1038
+ - lib/samagotchi/web/public/session_sync.js
1031
1039
  - lib/samagotchi/web/public/session_title.js
1040
+ - lib/samagotchi/web/public/session_view.js
1032
1041
  - lib/samagotchi/web/public/sessions_list.js
1033
1042
  - lib/samagotchi/web/public/settings_chip.js
1034
1043
  - lib/samagotchi/web/public/settings_panel.js