samagotchi 0.133.0 → 0.135.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 +116 -1
- data/bin/chi +2 -3
- data/docs/architecture.md +6 -3
- data/docs/cli.md +50 -34
- data/docs/configuration.md +9 -6
- data/docs/guardrails.md +146 -13
- data/docs/internals/background-tasks.md +1 -0
- data/docs/internals/engine.md +6 -3
- data/docs/internals/participants.md +7 -6
- data/docs/internals/tool-guardrails.md +2 -0
- data/docs/internals/web-frontend.md +262 -0
- data/docs/plugins.md +2 -1
- data/docs/sessions.md +5 -2
- data/docs/testing.md +34 -4
- data/lib/samagotchi/bridge.rb +11 -6
- data/lib/samagotchi/bridge_client.rb +8 -5
- data/lib/samagotchi/bundles/system/manifest.yml +1 -1
- data/lib/samagotchi/chi_home.rb +12 -2
- data/lib/samagotchi/config.rb +0 -2
- data/lib/samagotchi/desktop/macos.rb +19 -4
- data/lib/samagotchi/engine.rb +82 -12
- data/lib/samagotchi/guardrail_wiring.rb +8 -6
- data/lib/samagotchi/guardrails/approval.rb +41 -5
- data/lib/samagotchi/guardrails/implicit_writers.rb +158 -0
- data/lib/samagotchi/guardrails/pair_boundary.rb +11 -5
- data/lib/samagotchi/guardrails/pair_command.rb +828 -86
- data/lib/samagotchi/guardrails/parent_approvals.rb +13 -16
- data/lib/samagotchi/guardrails/read_only_shell.rb +58 -4
- data/lib/samagotchi/guardrails/shared_git.rb +1 -1
- data/lib/samagotchi/guardrails/shell_git_dirs.rb +7 -2
- data/lib/samagotchi/guardrails/shell_lex.rb +45 -0
- data/lib/samagotchi/guardrails/shell_paths.rb +3 -2
- data/lib/samagotchi/guardrails/targets.rb +8 -3
- data/lib/samagotchi/guardrails_command.rb +13 -10
- data/lib/samagotchi/home_command.rb +22 -6
- data/lib/samagotchi/home_doctor.rb +36 -3
- data/lib/samagotchi/home_notice.rb +8 -1
- data/lib/samagotchi/hooks/loader.rb +5 -0
- data/lib/samagotchi/llm/chat_loop.rb +4 -3
- data/lib/samagotchi/log_line.rb +12 -0
- data/lib/samagotchi/message_parts.rb +1 -1
- data/lib/samagotchi/project_env.rb +3 -11
- data/lib/samagotchi/revise_anchor.rb +33 -0
- data/lib/samagotchi/self_report.rb +3 -1
- data/lib/samagotchi/session_inbox.rb +20 -12
- data/lib/samagotchi/session_manager.rb +13 -11
- data/lib/samagotchi/system_one/approval_question.rb +21 -16
- data/lib/samagotchi/system_one/self_protect.rb +70 -16
- data/lib/samagotchi/testing/waiting.rb +13 -0
- data/lib/samagotchi/toolkit_binding.rb +16 -0
- data/lib/samagotchi/tools/delegate_relay.rb +6 -5
- data/lib/samagotchi/tools/delegate_wait.rb +5 -5
- data/lib/samagotchi/tools/execute.rb +6 -6
- data/lib/samagotchi/tools/output_guardrails.rb +9 -2
- data/lib/samagotchi/tools/read.rb +5 -5
- data/lib/samagotchi/turn_anchors.rb +49 -0
- data/lib/samagotchi/update_command.rb +7 -3
- data/lib/samagotchi/update_hint.rb +6 -1
- data/lib/samagotchi/verify_anchor.rb +5 -5
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/app.rb +2 -14
- data/lib/samagotchi/web/message_display.rb +17 -1
- data/lib/samagotchi/web/participant_access.rb +2 -2
- data/lib/samagotchi/web/participant_view.rb +8 -0
- data/lib/samagotchi/web/public/activity.js +1 -1
- data/lib/samagotchi/web/public/annotations.js +1 -1
- data/lib/samagotchi/web/public/answer_fold.js +262 -0
- data/lib/samagotchi/web/public/answer_refs.js +2 -0
- data/lib/samagotchi/web/public/app.js +462 -338
- data/lib/samagotchi/web/public/bubbles.js +3 -3
- data/lib/samagotchi/web/public/cards_place.js +9 -4
- data/lib/samagotchi/web/public/chip_popover.js +73 -11
- data/lib/samagotchi/web/public/claim_link.js +4 -2
- data/lib/samagotchi/web/public/composer.css +11 -1
- data/lib/samagotchi/web/public/context_chips.js +9 -6
- data/lib/samagotchi/web/public/data.js +4 -2
- data/lib/samagotchi/web/public/dock_reserve.js +13 -15
- data/lib/samagotchi/web/public/feature_gates.js +33 -0
- data/lib/samagotchi/web/public/history_reveal.js +27 -0
- data/lib/samagotchi/web/public/index.html +82 -37
- data/lib/samagotchi/web/public/latest.js +46 -0
- data/lib/samagotchi/web/public/lists_view.js +15 -13
- data/lib/samagotchi/web/public/live_timing.js +2 -0
- data/lib/samagotchi/web/public/llm_context_chip.js +5 -13
- data/lib/samagotchi/web/public/markdown_place.js +1 -1
- data/lib/samagotchi/web/public/method_api.js +14 -0
- data/lib/samagotchi/web/public/notifications.js +4 -11
- data/lib/samagotchi/web/public/participant.js +11 -6
- data/lib/samagotchi/web/public/participant_names.js +1 -1
- data/lib/samagotchi/web/public/participants_panel.js +4 -2
- data/lib/samagotchi/web/public/project_picker.js +18 -22
- data/lib/samagotchi/web/public/question_cards.js +2 -2
- data/lib/samagotchi/web/public/refs.js +6 -7
- data/lib/samagotchi/web/public/restore.js +2 -0
- data/lib/samagotchi/web/public/review_start.js +1 -1
- data/lib/samagotchi/web/public/revise_stack.js +372 -0
- data/lib/samagotchi/web/public/scope.js +12 -20
- data/lib/samagotchi/web/public/send_turn.js +29 -16
- data/lib/samagotchi/web/public/session_actions.js +15 -14
- data/lib/samagotchi/web/public/session_fields.js +152 -0
- data/lib/samagotchi/web/public/session_payload.js +35 -0
- data/lib/samagotchi/web/public/session_state.js +2 -0
- data/lib/samagotchi/web/public/session_store.js +191 -0
- data/lib/samagotchi/web/public/stage_model.js +4 -4
- data/lib/samagotchi/web/public/stage_view.js +11 -16
- data/lib/samagotchi/web/public/start_page.js +4 -4
- data/lib/samagotchi/web/public/start_settings.js +29 -18
- data/lib/samagotchi/web/public/start_toolkit.js +5 -4
- data/lib/samagotchi/web/public/stream_handlers.js +88 -90
- data/lib/samagotchi/web/public/task_stop.js +1 -1
- data/lib/samagotchi/web/public/timing.js +7 -3
- data/lib/samagotchi/web/public/{turn_view.js → turn_block.js} +46 -101
- data/lib/samagotchi/web/public/turn_events.js +2 -2
- data/lib/samagotchi/web/public/turn_html.js +17 -9
- data/lib/samagotchi/web/public/turn_model.js +6 -6
- data/lib/samagotchi/web/public/turn_range.js +32 -0
- data/lib/samagotchi/web/public/verdict_card.js +5 -13
- data/lib/samagotchi/web/public/verdict_fresh.js +2 -0
- data/lib/samagotchi/web/public/verify_target.js +7 -10
- data/lib/samagotchi/web/public/working_set_view.js +3 -1
- data/lib/samagotchi/web/server.rb +4 -4
- data/lib/samagotchi/web/session_control.rb +2 -2
- data/lib/samagotchi/worker.rb +9 -9
- data/lib/samagotchi/worker_inbound.rb +6 -5
- metadata +16 -3
- data/lib/samagotchi/web/public/hold.js +0 -78
|
@@ -105,7 +105,7 @@ export function setBubbleDelivery(bubble, delivery) {
|
|
|
105
105
|
// @param appendToHistory (el) puts +el+ at the history's end (or the stage's,
|
|
106
106
|
// while it holds a turn), above the live timing line
|
|
107
107
|
// @param isNearBottom () => whether the history follows its end
|
|
108
|
-
// @param turnDom the running turn's
|
|
108
|
+
// @param turnDom the running turn's DOM (stage_view.js)
|
|
109
109
|
// @param findInTurnRoots (selector) => the matching elements in the history
|
|
110
110
|
// and the stage
|
|
111
111
|
// @param shownTexts the running turn's texts on the page (shown_texts.js)
|
|
@@ -149,7 +149,7 @@ export function createBubbles({
|
|
|
149
149
|
|
|
150
150
|
function addEndBubble(text, { stopped = false } = {}) {
|
|
151
151
|
appendToHistory(elementOf(endBubbleTemplate(text, { stopped })));
|
|
152
|
-
if (!turnDom.holds
|
|
152
|
+
if (!turnDom.holds()) historyEl.scrollTop = historyEl.scrollHeight;
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
// ── Prompt bubbles ───────────────────────────────────────────────────────
|
|
@@ -239,7 +239,7 @@ export function createBubbles({
|
|
|
239
239
|
const details = elementOf(recapTemplate(text, turnsSince, createdAt));
|
|
240
240
|
// A stale one sits where it was written, above the turns it doesn't cover.
|
|
241
241
|
// Never in the stage: a recap is between turns.
|
|
242
|
-
turnDom.settleFold
|
|
242
|
+
turnDom.settleFold();
|
|
243
243
|
const prompt = recapPlace(turnPromptBubbles(historyEl), turnsSince);
|
|
244
244
|
// Above that turn's gap divider too: the recap was written before the quiet stretch ended.
|
|
245
245
|
const before = prompt?.previousElementSibling?.matches(`.${TIME_GAP_CLASS}`) ? prompt.previousElementSibling : prompt;
|
|
@@ -10,9 +10,10 @@
|
|
|
10
10
|
import { getSession, sendCommand } from "./data.js";
|
|
11
11
|
import { cardPlace, drawCard, isCard, isNoticeCard, refreshCardBody, turnNoticePlace } from "./card.js";
|
|
12
12
|
import { elementOf } from "./turn_html.js";
|
|
13
|
-
import { stepText } from "./
|
|
13
|
+
import { stepText } from "./turn_block.js";
|
|
14
14
|
import { llmContextNotice, noticeLine } from "./turn_events.js";
|
|
15
15
|
import { hookNoticeTemplate, TURN_PROMPT, turnPromptBubbles } from "./bubbles.js";
|
|
16
|
+
import { stillOn } from "./latest.js";
|
|
16
17
|
|
|
17
18
|
// The elements of the reloaded turn that ends before +before+ (the next
|
|
18
19
|
// turn's prompt, or null for the last turn), its prompt first.
|
|
@@ -25,10 +26,13 @@ export function reloadedTurnEls(historyEl, before) {
|
|
|
25
26
|
return turnEls;
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
// What goes after a reloaded turn's own rows and cards: its answer
|
|
29
|
+
// What goes after a reloaded turn's own rows and cards: its answer (its
|
|
30
|
+
// fold row, answer_fold.js, when it has one: the two stay together), else
|
|
29
31
|
// its timing line; null when it has neither.
|
|
30
32
|
export function turnAnswerEl(turnEls) {
|
|
31
|
-
|
|
33
|
+
const answer = turnEls.filter((el) => el.matches(".bubble.output, .empty-answer")).pop();
|
|
34
|
+
if (answer) return answer.previousElementSibling?.matches(".answer-fold") ? answer.previousElementSibling : answer;
|
|
35
|
+
return turnEls.find((el) => el.matches(".turn-timing")) || null;
|
|
32
36
|
}
|
|
33
37
|
|
|
34
38
|
// @param historyEl the history
|
|
@@ -142,10 +146,11 @@ export function createCardsPlace({
|
|
|
142
146
|
function refreshCardBodies() {
|
|
143
147
|
clearTimeout(cardBodiesTimer);
|
|
144
148
|
const id = selected();
|
|
149
|
+
const still = stillOn(selected, id);
|
|
145
150
|
cardBodiesTimer = setTimeout(async () => {
|
|
146
151
|
try {
|
|
147
152
|
const data = await api.getSession(id, { cards: true });
|
|
148
|
-
if (
|
|
153
|
+
if (!still()) return;
|
|
149
154
|
for (const card of data.cards || []) {
|
|
150
155
|
const el = card.type === "card" && cardElement(card.id);
|
|
151
156
|
if (el) refreshCardBody(el, card);
|
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
// click, its × (data-act="close"), a click outside or Esc; focus goes back
|
|
6
6
|
// to the opener. Another session's summary (refresh) closes it. What it
|
|
7
7
|
// draws, and what a Set or another data-act does, is the caller's. With
|
|
8
|
-
// +sheet+, a window narrower than SHEET_MAX gets it as a bottom sheet.
|
|
8
|
+
// +sheet+, a window narrower than SHEET_MAX gets it as a bottom sheet. An
|
|
9
|
+
// open one is placed again when the window (or a phone's visual viewport:
|
|
10
|
+
// its keyboard) resizes.
|
|
9
11
|
|
|
10
12
|
import { nothing, render } from "./vendor/lit-html.js";
|
|
11
13
|
|
|
@@ -29,11 +31,28 @@ export function popoverPlace(rect, { width, height, innerWidth, innerHeight }) {
|
|
|
29
31
|
return height > room ? { ...place, maxHeight: room } : place;
|
|
30
32
|
}
|
|
31
33
|
|
|
34
|
+
// The share of a phone's window a bottom sheet takes at most (the rest
|
|
35
|
+
// scrolls); a caller's taller view asks for SHEET_TALL.
|
|
36
|
+
export const SHEET_SHARE = 0.6;
|
|
37
|
+
export const SHEET_TALL = 0.85;
|
|
38
|
+
|
|
32
39
|
// A bottom sheet's place in a phone's window: the window's width less its
|
|
33
|
-
// edges, at its bottom, at most
|
|
40
|
+
// edges, at its bottom, at most +share+ of its height. +viewport+: the
|
|
41
|
+
// visual viewport ({height, offsetTop}) when it is shorter than the window
|
|
42
|
+
// (a phone's keyboard over the page): the sheet sits on it, sized to it.
|
|
34
43
|
// @return {left, bottom, width, maxHeight}
|
|
35
|
-
export function sheetPlace({ innerWidth, innerHeight }) {
|
|
36
|
-
|
|
44
|
+
export function sheetPlace({ innerWidth, innerHeight }, { share = SHEET_SHARE, viewport = null } = {}) {
|
|
45
|
+
const height = viewport ? Math.min(innerHeight, viewport.height) : innerHeight;
|
|
46
|
+
const below = viewport ? Math.max(0, innerHeight - viewport.offsetTop - viewport.height) : 0;
|
|
47
|
+
return { left: SHEET_EDGE, bottom: SHEET_EDGE + Math.round(below), width: innerWidth - 2 * SHEET_EDGE,
|
|
48
|
+
maxHeight: Math.round(height * share) };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const FOCUSABLE = "button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])";
|
|
52
|
+
|
|
53
|
+
// The elements Tab reaches in +root+, in order (none hidden or disabled).
|
|
54
|
+
export function tabStops(root) {
|
|
55
|
+
return [...root.querySelectorAll(FOCUSABLE)].filter((e) => !e.disabled && !e.closest("[hidden]") && e.tabIndex >= 0);
|
|
37
56
|
}
|
|
38
57
|
|
|
39
58
|
// id, className: the popover's; width: its widest (px); el: where the chip
|
|
@@ -47,27 +66,42 @@ export function sheetPlace({ innerWidth, innerHeight }) {
|
|
|
47
66
|
// sheet: a bottom sheet in a narrow window (sheetPlace). label: the
|
|
48
67
|
// dialog's accessible name (aria-label), none by default. onOpen(): after
|
|
49
68
|
// an open has shown and placed it (where focus can go into it: show runs
|
|
50
|
-
// while it is still hidden).
|
|
69
|
+
// while it is still hidden). expands: every opener carries aria-expanded
|
|
70
|
+
// ("true" while open, "false" once closed; set "false" in the markup too),
|
|
71
|
+
// for openers that are fixed buttons (a lit-drawn chip owns its own).
|
|
72
|
+
// modal: a dialog that holds the focus while open (aria-modal; Tab and
|
|
73
|
+
// Shift+Tab wrap inside it, a Tab from outside goes in). sheetShare: the
|
|
74
|
+
// share of a phone's window the sheet takes at most (SHEET_SHARE).
|
|
51
75
|
// @return {pop, open, close, refresh, isOpen, opener}
|
|
52
76
|
export function createChipPopover({ id, className, width: widest, el, anchor: anchorSel, openers = anchorSel, summary,
|
|
53
77
|
session = () => null, show, onClose = () => {}, onSubmit, onAct = () => {}, onOpen = () => {},
|
|
54
|
-
sheet = false, label = null,
|
|
78
|
+
sheet = false, label = null, expands = false, modal = false, sheetShare = SHEET_SHARE,
|
|
79
|
+
doc = document, win = window }) {
|
|
55
80
|
const pop = doc.createElement("div");
|
|
56
81
|
pop.id = id;
|
|
57
82
|
pop.className = className;
|
|
58
83
|
pop.setAttribute("role", "dialog");
|
|
59
84
|
if (label) pop.setAttribute("aria-label", label);
|
|
85
|
+
if (modal) pop.setAttribute("aria-modal", "true");
|
|
60
86
|
pop.hidden = true;
|
|
61
87
|
doc.body.appendChild(pop);
|
|
62
|
-
// The session the open form is for,
|
|
88
|
+
// The session the open form is for, the element it is placed at, and the
|
|
89
|
+
// one focus goes back to (the opener clicked).
|
|
63
90
|
let openFor = null;
|
|
64
91
|
let opener = null;
|
|
92
|
+
let returnTo = null;
|
|
93
|
+
|
|
94
|
+
const expanded = (value) => {
|
|
95
|
+
if (expands) doc.querySelectorAll(openers).forEach((e) => e.setAttribute("aria-expanded", value));
|
|
96
|
+
};
|
|
65
97
|
|
|
66
98
|
function place(anchor) {
|
|
67
99
|
const narrow = sheet && win.innerWidth < SHEET_MAX;
|
|
68
100
|
pop.classList.toggle("sheet", narrow);
|
|
69
101
|
if (narrow) {
|
|
70
|
-
const
|
|
102
|
+
const vv = win.visualViewport;
|
|
103
|
+
const at = sheetPlace({ innerWidth: win.innerWidth, innerHeight: win.innerHeight },
|
|
104
|
+
{ share: sheetShare, viewport: vv ? { height: vv.height, offsetTop: vv.offsetTop } : null });
|
|
71
105
|
pop.style.width = `${at.width}px`;
|
|
72
106
|
pop.style.left = `${at.left}px`;
|
|
73
107
|
pop.style.top = "";
|
|
@@ -86,12 +120,16 @@ export function createChipPopover({ id, className, width: widest, el, anchor: an
|
|
|
86
120
|
if (at.maxHeight !== undefined) pop.style.maxHeight = `${at.maxHeight}px`;
|
|
87
121
|
}
|
|
88
122
|
|
|
89
|
-
// Opens at +anchor+ (open already: drawn anew there)
|
|
90
|
-
|
|
123
|
+
// Opens at +anchor+ (open already: drawn anew there); focus goes back to
|
|
124
|
+
// +from+ on close (an opener that isn't the anchor; the anchor when +from+
|
|
125
|
+
// is gone or hidden by then).
|
|
126
|
+
function open(anchor, { from = anchor } = {}) {
|
|
91
127
|
const data = summary(anchor);
|
|
92
128
|
if (!data) return;
|
|
93
129
|
openFor = session();
|
|
94
130
|
opener = anchor;
|
|
131
|
+
returnTo = from;
|
|
132
|
+
expanded("true");
|
|
95
133
|
show(data, true);
|
|
96
134
|
pop.hidden = false;
|
|
97
135
|
place(anchor);
|
|
@@ -103,10 +141,12 @@ export function createChipPopover({ id, className, width: widest, el, anchor: an
|
|
|
103
141
|
// its opener.
|
|
104
142
|
function close({ refocus = false } = {}) {
|
|
105
143
|
const had = refocus || pop.contains(doc.activeElement);
|
|
106
|
-
const back = opener;
|
|
144
|
+
const back = returnTo?.isConnected && !returnTo.hidden ? returnTo : opener;
|
|
145
|
+
expanded("false");
|
|
107
146
|
pop.hidden = true;
|
|
108
147
|
openFor = null;
|
|
109
148
|
opener = null;
|
|
149
|
+
returnTo = null;
|
|
110
150
|
onClose();
|
|
111
151
|
render(nothing, pop);
|
|
112
152
|
if (had && back?.isConnected) back.focus?.();
|
|
@@ -156,7 +196,29 @@ export function createChipPopover({ id, className, width: widest, el, anchor: an
|
|
|
156
196
|
});
|
|
157
197
|
doc.addEventListener("keydown", (e) => {
|
|
158
198
|
if (e.key === "Escape" && isOpen()) close({ refocus: true });
|
|
199
|
+
else if (e.key === "Tab" && modal && isOpen()) holdFocus(e);
|
|
159
200
|
});
|
|
201
|
+
// A resize (a rotation, a phone's keyboard) places an open one again: a
|
|
202
|
+
// sheet's height follows the window, a popover its chip.
|
|
203
|
+
win.addEventListener?.("resize", replace);
|
|
204
|
+
win.visualViewport?.addEventListener?.("resize", replace);
|
|
205
|
+
|
|
206
|
+
// Tab past the last stop goes to the first, Shift+Tab before the first to
|
|
207
|
+
// the last; a Tab from outside (focus lost to a redraw) goes in.
|
|
208
|
+
function holdFocus(e) {
|
|
209
|
+
const stops = tabStops(pop);
|
|
210
|
+
if (!stops.length) return;
|
|
211
|
+
const first = stops[0];
|
|
212
|
+
const last = stops[stops.length - 1];
|
|
213
|
+
const at = doc.activeElement;
|
|
214
|
+
let to = null;
|
|
215
|
+
if (!pop.contains(at)) to = e.shiftKey ? last : first;
|
|
216
|
+
else if (e.shiftKey && at === first) to = last;
|
|
217
|
+
else if (!e.shiftKey && at === last) to = first;
|
|
218
|
+
if (!to) return;
|
|
219
|
+
e.preventDefault();
|
|
220
|
+
to.focus();
|
|
221
|
+
}
|
|
160
222
|
|
|
161
223
|
return { pop, open, close, refresh, isOpen, replace, opener: () => opener };
|
|
162
224
|
}
|
|
@@ -28,6 +28,8 @@
|
|
|
28
28
|
// static JS is cached at unversioned URLs, and a new export on an old
|
|
29
29
|
// module would blank the page.
|
|
30
30
|
|
|
31
|
+
import { revealInHistory } from "./history_reveal.js";
|
|
32
|
+
|
|
31
33
|
export const QUOTE_MAX = 200;
|
|
32
34
|
export const PREFIX_MAX = 32;
|
|
33
35
|
export const TURN_CHARS = 8;
|
|
@@ -311,7 +313,7 @@ export function selectionClaim(root, range, opts = {}, doc = globalThis.document
|
|
|
311
313
|
|
|
312
314
|
// Finds the claim +claim+ ({turn, q, p}) in +container+ and shows it: the
|
|
313
315
|
// match's root (or the turn's opening) scrolled to the middle and marked
|
|
314
|
-
// HIT_CLASS,
|
|
316
|
+
// HIT_CLASS, what hides it unfolded (history_reveal.js), the quote highlighted (CSS
|
|
315
317
|
// Highlight API). Without the turn (no opening carries its id: a
|
|
316
318
|
// non-person turn), the quote in any root of the page. @return "quote",
|
|
317
319
|
// "turn" or null (neither the turn nor the quote).
|
|
@@ -323,7 +325,7 @@ export function showClaim(container, claim, { roots: rootSelector, opts = {}, do
|
|
|
323
325
|
const hit = findClaim(texts.map((t) => t.text), claim, opts);
|
|
324
326
|
if (!hit && !turn) return null;
|
|
325
327
|
const el = hit ? roots[hit.at] : turn.anchor;
|
|
326
|
-
|
|
328
|
+
revealInHistory(el);
|
|
327
329
|
el.classList.add(HIT_CLASS);
|
|
328
330
|
el.scrollIntoView?.({ block: "center" });
|
|
329
331
|
if (hit) {
|
|
@@ -24,6 +24,14 @@ body.no-glass .composer-card{background:var(--bg-panel);-webkit-backdrop-filter:
|
|
|
24
24
|
body.has-session #composer{flex-wrap:wrap;row-gap:6px}
|
|
25
25
|
#chips{display:flex;flex-wrap:wrap;gap:6px}
|
|
26
26
|
#chips[hidden]{display:none}
|
|
27
|
+
/* The armed Revise (revise_stack.js reviseChipTemplate): "Revising: ‹first line› ✕". */
|
|
28
|
+
#reviseChip{display:flex;min-width:0}
|
|
29
|
+
#reviseChip[hidden]{display:none}
|
|
30
|
+
.revise-chip{display:inline-flex;align-items:center;gap:6px;max-width:100%;min-width:0;padding:2px 4px 2px 10px;border-radius:999px;border:1px solid var(--accent-border);background:var(--accent-bg);color:var(--text-2);font-size:12px;line-height:18px}
|
|
31
|
+
.revise-chip.refused{border-color:var(--warn-border);background:var(--warn-bg);color:var(--warn-text)}
|
|
32
|
+
.revise-chip-text{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
33
|
+
.revise-chip-clear{flex:none;display:inline-flex;align-items:center;justify-content:center;width:20px;height:20px;min-height:0;padding:0;border:0;border-radius:999px;background:transparent;color:var(--text-muted);font-size:11px;cursor:pointer}
|
|
34
|
+
.revise-chip-clear:hover{background:var(--bg-raised);color:var(--text-bright);filter:none}
|
|
27
35
|
.chip{display:inline-flex;align-items:center;gap:6px;background:var(--accent-bg);border:1px solid var(--border-strong);border-radius:8px;padding:3px 4px 3px 3px;font-size:12px;max-width:220px}
|
|
28
36
|
.chip img{width:32px;height:32px;object-fit:cover;border-radius:5px}
|
|
29
37
|
.chip .chip-name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
@@ -77,7 +85,9 @@ body.has-session.composer-folded #composeGrip::after{opacity:1;width:48px;margin
|
|
|
77
85
|
.set: something under it is set, an accent dot on a phone (the override chips say it on a wider row). */
|
|
78
86
|
#composer .actions-col .icon-btn{order:2;position:relative;flex:none;width:28px;padding:0;border:1px solid transparent;border-radius:8px;background:transparent;color:var(--text-muted)}
|
|
79
87
|
#composer .actions-col .icon-btn::before{content:"";display:block;width:16px;height:16px;margin:auto;background:currentColor;-webkit-mask:var(--icon) center/contain no-repeat;mask:var(--icon) center/contain no-repeat}
|
|
80
|
-
#composer .actions-col .icon-btn:hover
|
|
88
|
+
#composer .actions-col .icon-btn:hover{filter:none}
|
|
89
|
+
#composer .actions-col .icon-btn[aria-expanded="true"]{color:var(--text);background:color-mix(in srgb,var(--bg-hover) 75%,transparent)}
|
|
90
|
+
@media(hover:hover){#composer .actions-col .icon-btn:hover{color:var(--text);background:color-mix(in srgb,var(--bg-hover) 75%,transparent)}}
|
|
81
91
|
#composer .actions-col .icon-btn[hidden],body.has-session #composer .actions-col .icon-btn{display:none}
|
|
82
92
|
#composer .actions-col .settings-btn{--icon:var(--icon-settings)}
|
|
83
93
|
#composer .actions-col .toolkit-btn{--icon:var(--icon-toolkit)}
|
|
@@ -11,6 +11,7 @@ import { html, nothing, render } from "./vendor/lit-html.js";
|
|
|
11
11
|
import { keepFocus } from "./keep_focus.js";
|
|
12
12
|
import { popoverPlace } from "./chip_popover.js";
|
|
13
13
|
import { cantText } from "./format.js";
|
|
14
|
+
import { createLatest, stillOn } from "./latest.js";
|
|
14
15
|
|
|
15
16
|
// "now", "3m", "2h", "4d" since an ISO time; "" for none.
|
|
16
17
|
export function ageText(iso, now = Date.now()) {
|
|
@@ -106,7 +107,8 @@ export function createContextChips({ el, api, toast = () => {}, doc = document,
|
|
|
106
107
|
let rows = [];
|
|
107
108
|
let canAdd = false;
|
|
108
109
|
let openName = null;
|
|
109
|
-
|
|
110
|
+
// Only the newest list read for the open session is drawn (latest.js).
|
|
111
|
+
const latest = createLatest(() => sessionId);
|
|
110
112
|
// The open row's text once read (view text), and the "+ URL" form's
|
|
111
113
|
// state ({error, busy}).
|
|
112
114
|
let text = null;
|
|
@@ -140,15 +142,15 @@ export function createContextChips({ el, api, toast = () => {}, doc = document,
|
|
|
140
142
|
async function refresh() {
|
|
141
143
|
const id = sessionId;
|
|
142
144
|
if (!id) return;
|
|
143
|
-
const
|
|
145
|
+
const fresh = latest.begin();
|
|
144
146
|
try {
|
|
145
147
|
const data = await api.list(id);
|
|
146
|
-
if (
|
|
148
|
+
if (!fresh()) return;
|
|
147
149
|
rows = data.sources || [];
|
|
148
150
|
canAdd = data.can_add_url === true;
|
|
149
151
|
} catch {
|
|
150
152
|
// A session the server doesn't know (gone, or an older chi web): no chips.
|
|
151
|
-
if (
|
|
153
|
+
if (!fresh()) return;
|
|
152
154
|
rows = [];
|
|
153
155
|
canAdd = false;
|
|
154
156
|
}
|
|
@@ -234,15 +236,16 @@ export function createContextChips({ el, api, toast = () => {}, doc = document,
|
|
|
234
236
|
const url = form.elements.url.value.trim();
|
|
235
237
|
const why = form.elements.why.value.trim();
|
|
236
238
|
if (!id || !url) return;
|
|
239
|
+
const still = stillOn(() => sessionId);
|
|
237
240
|
drawAdd({ busy: true });
|
|
238
241
|
try {
|
|
239
242
|
const data = await api.add(id, { url, why: why || undefined });
|
|
240
|
-
if (
|
|
243
|
+
if (!still()) return;
|
|
241
244
|
close();
|
|
242
245
|
await refresh();
|
|
243
246
|
toast(`Attached ${data.name}: the agent gets a note before your next message`);
|
|
244
247
|
} catch (e) {
|
|
245
|
-
if (
|
|
248
|
+
if (!still() || openName !== ADD) return;
|
|
246
249
|
// The same form again: what the user typed stays; the URL gets focus.
|
|
247
250
|
drawAdd({ busy: false, error: e.message });
|
|
248
251
|
pop.querySelector('input[name="url"]')?.focus();
|
|
@@ -130,7 +130,7 @@ export function uploadImage(id, file, name, opts = {}) {
|
|
|
130
130
|
// (mergeTiming), and opts.turnId asks for that turn's answer.
|
|
131
131
|
// opts.timing: the whole timing alone (when the merge came up short).
|
|
132
132
|
// opts.parts: each saved message with what it did (thinking, tool calls
|
|
133
|
-
// and their output), for the turn
|
|
133
|
+
// and their output), for the turn block's reload.
|
|
134
134
|
export function getSession(id, { tail, recent, turnId, timing, parts, cards, ...opts } = {}) {
|
|
135
135
|
let query = cards ? "?cards=1" : tail ? "?tail=1" : timing ? "?timing=1" : parts ? "?parts=1" : "";
|
|
136
136
|
if (tail && recent) query += "&recent=1";
|
|
@@ -144,12 +144,14 @@ export function getSession(id, { tail, recent, turnId, timing, parts, cards, ...
|
|
|
144
144
|
// image-only send, whose text is only its [image: …] placeholders).
|
|
145
145
|
// delivery: what the message does to a running turn ("cut": /cut TEXT);
|
|
146
146
|
// none = the server's default (the next step).
|
|
147
|
-
export function sendTurn(id, prompt, { clientId, images, history = true, delivery = null, verify = null, ...opts } = {}) {
|
|
147
|
+
export function sendTurn(id, prompt, { clientId, images, history = true, delivery = null, verify = null, revises = null, ...opts } = {}) {
|
|
148
148
|
const body = clientId ? { prompt, client_id: clientId } : { prompt };
|
|
149
149
|
if (images?.length) body.images = images;
|
|
150
150
|
if (delivery) body.delivery = delivery;
|
|
151
151
|
if (history === false) body.history = false;
|
|
152
152
|
if (verify) body.verify = verify;
|
|
153
|
+
// A Revise turn's draft: {turn_id} of the answer it rewrites.
|
|
154
|
+
if (revises) body.revises = revises;
|
|
153
155
|
return api(`/api/sessions/${id}/turn`, {
|
|
154
156
|
method: "POST",
|
|
155
157
|
body: JSON.stringify(body),
|
|
@@ -21,7 +21,7 @@ import { toastBottom } from "./toast_place.js";
|
|
|
21
21
|
// model panel (toast_place.js); with no card in sight (the start page, all
|
|
22
22
|
// sessions) the CSS's 24 px from the bottom (--toast-bottom unset).
|
|
23
23
|
//
|
|
24
|
-
// +stageEl+: the stage (
|
|
24
|
+
// +stageEl+: the stage (stage_view.js). +atHistoryEnd()+:
|
|
25
25
|
// the reader is at the history's end (app.js, scroll.js's threshold).
|
|
26
26
|
// +reduce()+ / +ease+: prefers-reduced-motion and the eased follow
|
|
27
27
|
// (scroll.js), defaults the page's.
|
|
@@ -37,7 +37,7 @@ export function createDockReserve({
|
|
|
37
37
|
const win = doc.defaultView;
|
|
38
38
|
|
|
39
39
|
function dockReserve() {
|
|
40
|
-
const shown =
|
|
40
|
+
const shown = !stageEl.hidden && !stageEl.classList.contains("leaving");
|
|
41
41
|
return dockEl.offsetHeight + (shown ? stageEl.offsetHeight + STAGE_GAP : 0);
|
|
42
42
|
}
|
|
43
43
|
const historyEnd = () => historyEl.scrollHeight - historyEl.clientHeight;
|
|
@@ -48,7 +48,7 @@ export function createDockReserve({
|
|
|
48
48
|
// counts as at the end.
|
|
49
49
|
function updateReserve({ fromStage = false } = {}) {
|
|
50
50
|
const follow = atHistoryEnd() || historyEl.dataset.following !== undefined;
|
|
51
|
-
const leaving =
|
|
51
|
+
const leaving = stageEl.classList.contains("leaving");
|
|
52
52
|
centerEl.classList.toggle("reserve-easing", leaving);
|
|
53
53
|
const reserve = `${dockReserve()}px`;
|
|
54
54
|
const changed = centerEl.style.getPropertyValue("--dock-h") !== reserve;
|
|
@@ -83,18 +83,16 @@ export function createDockReserve({
|
|
|
83
83
|
|
|
84
84
|
const dockObserver = new win.ResizeObserver((entries) => updateReserve({ fromStage: entries.some((e) => e.target === stageEl) }));
|
|
85
85
|
dockObserver.observe(dockEl);
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}).observe(stageEl, { attributes: true, attributeFilter: ["class", "hidden"] });
|
|
97
|
-
}
|
|
86
|
+
dockObserver.observe(stageEl);
|
|
87
|
+
// Only showing, hiding and leaving change the reserve (not the stage's
|
|
88
|
+
// other classes: waiting, in-use…).
|
|
89
|
+
let stageShown = "";
|
|
90
|
+
new win.MutationObserver(() => {
|
|
91
|
+
const shown = `${stageEl.hidden}|${stageEl.classList.contains("leaving")}`;
|
|
92
|
+
if (shown === stageShown) return;
|
|
93
|
+
stageShown = shown;
|
|
94
|
+
updateReserve({ fromStage: true });
|
|
95
|
+
}).observe(stageEl, { attributes: true, attributeFilter: ["class", "hidden"] });
|
|
98
96
|
win.addEventListener("resize", () => placeToast());
|
|
99
97
|
// The model panel opening, closing or changing height (its list filters).
|
|
100
98
|
new win.ResizeObserver(() => placeToast()).observe(modelPanelEl);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// The open session's feature gates: a page action that its worker must
|
|
2
|
+
// support (its sidecar features, a live bridge), and the redraw that
|
|
3
|
+
// follows when that flips. Registered with the session store as its
|
|
4
|
+
// `featureGates` redraw (session_store.js ORDER): it runs whenever a field
|
|
5
|
+
// it reads changes, and a gate's own redraw only when its answer flipped.
|
|
6
|
+
//
|
|
7
|
+
// A session switch (forgetSession) and a full load (renderSessionView) draw
|
|
8
|
+
// every card with the gate's answer already: they prime() the gates, so the
|
|
9
|
+
// redraw that follows their write sees no flip. A write anywhere else (a
|
|
10
|
+
// restart's hub event bringing the feature, the worker going) fires it.
|
|
11
|
+
//
|
|
12
|
+
// A new module: the page's modules are cached at unversioned URLs, and a
|
|
13
|
+
// new export of an old module would leave a cached copy without it.
|
|
14
|
+
|
|
15
|
+
// @param entries [{name, unavailable(current) → bool, redraw()}]
|
|
16
|
+
// @return {prime(current), check(current)}: prime takes each gate's answer
|
|
17
|
+
// without redrawing; check redraws the gates whose answer flipped since
|
|
18
|
+
export function createFeatureGates(entries) {
|
|
19
|
+
const last = new Map();
|
|
20
|
+
return {
|
|
21
|
+
prime(current) {
|
|
22
|
+
for (const gate of entries) last.set(gate.name, !!gate.unavailable(current));
|
|
23
|
+
},
|
|
24
|
+
check(current) {
|
|
25
|
+
for (const gate of entries) {
|
|
26
|
+
const now = !!gate.unavailable(current);
|
|
27
|
+
const flipped = last.has(gate.name) && last.get(gate.name) !== now;
|
|
28
|
+
last.set(gate.name, now);
|
|
29
|
+
if (flipped) gate.redraw();
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// The one way a jump into the history shows what it lands on: whatever
|
|
2
|
+
// hides +el+ unfolds: a closed <details> around it (a turn's steps block, a
|
|
3
|
+
// step, a diff), an answer folded by hand (answer_fold.js: its row follows
|
|
4
|
+
// the bubble's class; the jump's unfold isn't saved), a superseded version
|
|
5
|
+
// of a Revise stack (revise_stack.js: its stub opens, not saved). Every
|
|
6
|
+
// jump goes through it (claim_link.js showClaim, refs.js showRow and so the
|
|
7
|
+
// working set's step tags, verdict_card.js "View check"), so a new way to
|
|
8
|
+
// hide history is opened in one place.
|
|
9
|
+
//
|
|
10
|
+
// Pure DOM, so it runs under `node --test` with happy-dom. A module of its
|
|
11
|
+
// own: static JS is cached at unversioned URLs, and a new export on an old
|
|
12
|
+
// module would blank the page.
|
|
13
|
+
|
|
14
|
+
import { openStubOver } from "./revise_stack.js";
|
|
15
|
+
|
|
16
|
+
// Opens each closed <details> that holds +el+ (not +el+ itself: a fold the
|
|
17
|
+
// caller means to open it opens itself) and unfolds the folded answer that
|
|
18
|
+
// is or holds it. +el+, or null.
|
|
19
|
+
export function revealInHistory(el) {
|
|
20
|
+
if (!el) return null;
|
|
21
|
+
openStubOver(el);
|
|
22
|
+
el.closest?.(".bubble.output.folded")?.classList.remove("folded");
|
|
23
|
+
for (let details = el.parentElement?.closest("details"); details; details = details.parentElement?.closest("details")) {
|
|
24
|
+
details.open = true;
|
|
25
|
+
}
|
|
26
|
+
return el;
|
|
27
|
+
}
|