samagotchi 0.175.0 → 0.177.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 +50 -1
- data/bin/chi +1 -0
- data/docs/architecture.md +1 -1
- data/docs/cli.md +11 -4
- data/docs/configuration.md +1 -0
- data/docs/internals/bridge.md +2 -2
- data/docs/internals/engine.md +2 -2
- data/docs/internals/participants.md +13 -6
- data/docs/internals/prompt-caching.md +3 -0
- data/docs/internals/web-frontend.md +38 -11
- data/docs/internals/working-set.md +77 -6
- data/docs/sessions.md +3 -2
- data/lib/samagotchi/bridge.rb +11 -4
- data/lib/samagotchi/bundles/system/manifest.yml +1 -1
- data/lib/samagotchi/config.rb +3 -0
- data/lib/samagotchi/engine/models.rb +11 -0
- data/lib/samagotchi/engine/session.rb +9 -0
- data/lib/samagotchi/engine.rb +1 -0
- data/lib/samagotchi/engine_snapshots.rb +3 -0
- data/lib/samagotchi/participant_uploads.rb +14 -1
- data/lib/samagotchi/prompt_part.rb +66 -0
- data/lib/samagotchi/session.rb +10 -1
- data/lib/samagotchi/system_prompt.rb +191 -12
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/app.rb +15 -2
- data/lib/samagotchi/web/participant_images.rb +16 -12
- data/lib/samagotchi/web/participant_show.rb +1 -1
- data/lib/samagotchi/web/participant_view.rb +27 -1
- data/lib/samagotchi/web/public/app.js +7 -2
- data/lib/samagotchi/web/public/composer_fold.js +3 -1
- data/lib/samagotchi/web/public/composer_grip.js +18 -10
- data/lib/samagotchi/web/public/composer_mount.js +17 -6
- data/lib/samagotchi/web/public/ctx_tokens.js +33 -0
- data/lib/samagotchi/web/public/index.html +43 -9
- data/lib/samagotchi/web/public/restore.js +3 -1
- data/lib/samagotchi/web/public/session_fields.js +10 -4
- data/lib/samagotchi/web/public/session_prefs.js +92 -0
- data/lib/samagotchi/web/public/session_state.js +14 -1
- data/lib/samagotchi/web/public/session_store.js +1 -1
- data/lib/samagotchi/web/public/session_sync.js +3 -0
- data/lib/samagotchi/web/public/session_view.js +33 -3
- data/lib/samagotchi/web/public/stage_asking.js +20 -11
- data/lib/samagotchi/web/public/stage_cloud.js +3 -2
- data/lib/samagotchi/web/public/stage_missing.js +3 -5
- data/lib/samagotchi/web/public/stage_model.js +2 -1
- data/lib/samagotchi/web/public/stage_view.js +6 -1
- data/lib/samagotchi/web/public/stage_view_memory.js +76 -0
- data/lib/samagotchi/web/public/stream_handlers.js +10 -5
- data/lib/samagotchi/web/public/tokens.css +2 -2
- data/lib/samagotchi/web/public/turn_events.js +1 -1
- data/lib/samagotchi/web/public/working_set.js +51 -7
- data/lib/samagotchi/web/public/working_set_rail.js +22 -7
- data/lib/samagotchi/web/public/working_set_view.js +188 -58
- data/lib/samagotchi/web/public/ws_reader.js +2 -0
- data/lib/samagotchi/web/public/ws_sections.js +251 -0
- data/lib/samagotchi/web/server.rb +6 -2
- data/lib/samagotchi/web/session_show.rb +13 -2
- data/lib/samagotchi/worker/child_side.rb +123 -0
- data/lib/samagotchi/worker/command_queue.rb +350 -0
- data/lib/samagotchi/worker/leave.rb +286 -0
- data/lib/samagotchi/worker/scratch.rb +99 -0
- data/lib/samagotchi/worker/signal_grace.rb +96 -0
- data/lib/samagotchi/worker/startup.rb +92 -0
- data/lib/samagotchi/worker/wake_turns.rb +190 -0
- data/lib/samagotchi/worker.rb +25 -1065
- data/lib/samagotchi/worker_exit_claim.rb +12 -0
- data/lib/samagotchi/working_set.rb +32 -4
- data/lib/samagotchi/working_set_command.rb +3 -2
- data/lib/samagotchi/working_set_steer.rb +21 -3
- metadata +13 -1
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// What the user had opened of a running turn, per session, for this tab
|
|
2
|
+
// only: the cloud open, the steps opened in it, the working set's reader on
|
|
3
|
+
// an item. A switch rebuilds the stage from the server's read (session_sync.js
|
|
4
|
+
// select → resync → session_view.js renderSessionView); this puts back what
|
|
5
|
+
// was opened, when the page comes back to the same turn.
|
|
6
|
+
//
|
|
7
|
+
// Saved when the page leaves a session (select, and forgetSession for the
|
|
8
|
+
// session it drew last, e.g. the start page: before the reset of the stage
|
|
9
|
+
// and the reader), taken when renderSessionView has drawn
|
|
10
|
+
// the read: applied only when the read's running turn is the one saved, and
|
|
11
|
+
// dropped either way (a different or ended turn has nothing to put back). A
|
|
12
|
+
// turn that ends on the page drops its session's entry (endTurnView).
|
|
13
|
+
//
|
|
14
|
+
// A plain Map keyed by session id, the oldest going past +cap+: nothing
|
|
15
|
+
// written to storage, nothing sent. The working set's peek isn't kept: it
|
|
16
|
+
// closes with its popover, which the tap that leaves the session closes.
|
|
17
|
+
//
|
|
18
|
+
// A module of its own: static JS is cached at unversioned URLs, and a new
|
|
19
|
+
// export on an old module would blank the page.
|
|
20
|
+
|
|
21
|
+
export const VIEW_MEMORY_CAP = 20;
|
|
22
|
+
|
|
23
|
+
// What the page shows now of its running turn ({turnId, cloud, steps,
|
|
24
|
+
// reader}), or null: no turn held, or nothing opened. +stage+: the stage
|
|
25
|
+
// view (stage_view.js: holds, current, cloud, step); +turnId+ the running
|
|
26
|
+
// turn's id; +reader+: the working set's reader (ws_reader.js), or null.
|
|
27
|
+
export function captureView({ stage, turnId, reader = null }) {
|
|
28
|
+
if (!turnId || !stage?.holds?.() || !stage.cloud || !stage.step) return null;
|
|
29
|
+
const count = stage.current?.()?.turn?.gens?.length || 0;
|
|
30
|
+
const steps = [];
|
|
31
|
+
for (let i = 0; i < count; i++) if (stage.step(i)?.el?.open) steps.push(i);
|
|
32
|
+
const cloud = !!stage.cloud.isOpen?.();
|
|
33
|
+
const item = reader?.isOpen?.() ? reader.openItem?.() || null : null;
|
|
34
|
+
if (!cloud && !item) return null;
|
|
35
|
+
return { turnId, cloud, steps: cloud ? steps : [], reader: item };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Puts +view+ back on the page (captureView's shape): the cloud, then each
|
|
39
|
+
// step it had open that the replay drew closed (a hand toggle, as a click on
|
|
40
|
+
// its row), then the reader's item.
|
|
41
|
+
export function applyView(view, { stage, reader = null }) {
|
|
42
|
+
if (!view) return;
|
|
43
|
+
if (view.cloud && stage?.holds?.() && stage.cloud) {
|
|
44
|
+
stage.cloud.setCloud(true);
|
|
45
|
+
for (const i of view.steps) {
|
|
46
|
+
const step = stage.step(i);
|
|
47
|
+
if (step?.el && !step.el.open) step.summary?.click();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (view.reader && reader?.open) reader.open(view.reader);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// The memory: +leave(session, now)+ keeps what +now+ (captureView) says for
|
|
54
|
+
// +session+ (null: forgets it); +take(session, turnId)+ the entry for that
|
|
55
|
+
// turn, else null, and the entry goes; +drop(session)+.
|
|
56
|
+
export function createStageViewMemory({ cap = VIEW_MEMORY_CAP } = {}) {
|
|
57
|
+
const entries = new Map();
|
|
58
|
+
return {
|
|
59
|
+
leave(session, now) {
|
|
60
|
+
if (!session) return;
|
|
61
|
+
entries.delete(session);
|
|
62
|
+
if (!now) return;
|
|
63
|
+
entries.set(session, now);
|
|
64
|
+
while (entries.size > cap) entries.delete(entries.keys().next().value);
|
|
65
|
+
},
|
|
66
|
+
take(session, turnId) {
|
|
67
|
+
const entry = entries.get(session) || null;
|
|
68
|
+
entries.delete(session);
|
|
69
|
+
return entry && turnId && entry.turnId === turnId ? entry : null;
|
|
70
|
+
},
|
|
71
|
+
drop(session) {
|
|
72
|
+
entries.delete(session);
|
|
73
|
+
},
|
|
74
|
+
size: () => entries.size,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
|
|
48
48
|
import { routeChunk } from "./chunk_router.js";
|
|
49
49
|
import { extractCtxPct, generationTokens } from "./ctx.js";
|
|
50
|
+
import { ctxTokensOf } from "./ctx_tokens.js";
|
|
50
51
|
import { failedTurnText, fullTime } from "./format.js";
|
|
51
52
|
import { cancelLineText } from "./timing.js";
|
|
52
53
|
import { keepFollowing } from "./scroll.js";
|
|
@@ -92,8 +93,9 @@ export function createStreamHandlers(deps) {
|
|
|
92
93
|
turnDom.chunk({ text, thinking, iteration: data.iteration ?? null, now: data.replayed ? null : Date.now() });
|
|
93
94
|
const current = store.current;
|
|
94
95
|
const pct = extractCtxPct(data, current.ctxWindow, current.llmContext?.budget_tokens);
|
|
95
|
-
// A chunk with the same % redraws nothing (the store compares)
|
|
96
|
-
|
|
96
|
+
// A chunk with the same % redraws nothing (the store compares); its
|
|
97
|
+
// tokens go with it (the working set's head line).
|
|
98
|
+
if (pct !== null && !Number.isNaN(pct)) store.update({ current: { ctxPct: pct, ctxTokens: ctxTokensOf(data) ?? current.ctxTokens } });
|
|
97
99
|
},
|
|
98
100
|
generation_started: (data) => {
|
|
99
101
|
// The request after a /model's unresolved window started: whatever it
|
|
@@ -264,7 +266,7 @@ export function createStreamHandlers(deps) {
|
|
|
264
266
|
prompt_restored: async (data) => {
|
|
265
267
|
const id = selected();
|
|
266
268
|
keepEarlyRestore(data, earlyRestores, { myId: clientId, sentIds });
|
|
267
|
-
const { refill, label, images: restoredImages, verify, revises } = restoreAction(data, { myId: clientId, sentIds, composerEmpty: composer.empty() });
|
|
269
|
+
const { refill, label, own, author, images: restoredImages, verify, revises } = restoreAction(data, { myId: clientId, sentIds, composerEmpty: composer.empty() });
|
|
268
270
|
if (refill) composer.refill(refill);
|
|
269
271
|
if (refill && verify) deps.restoreVerify?.(verify);
|
|
270
272
|
// A Revise turn's draft too: its chip comes back with the text.
|
|
@@ -285,7 +287,8 @@ export function createStreamHandlers(deps) {
|
|
|
285
287
|
}
|
|
286
288
|
// Not an echo waiting for its turn_enqueued: it keeps its enqueued_id, so
|
|
287
289
|
// a resend's echo isn't matched to it.
|
|
288
|
-
|
|
290
|
+
// A participant's own failed bubble takes their badge from the viewer (own), anyone else's from the event.
|
|
291
|
+
makeUserBubble(data.prompt || "", { state: "failed", label, author: own ? null : author, own: own && !!author, enqueuedId: data.origin?.enqueued_id || `failed:${Date.now()}`, images: data.images });
|
|
289
292
|
if (failedText) addEndBubble(failedText);
|
|
290
293
|
},
|
|
291
294
|
// A session command ran in the worker (any client's). One that changed
|
|
@@ -398,12 +401,14 @@ export function createStreamHandlers(deps) {
|
|
|
398
401
|
patch.ctxUnknownAfterSwitch = !data.context_window_tokens;
|
|
399
402
|
}
|
|
400
403
|
if (data && "usage" in data && data.usage === null) {
|
|
401
|
-
store.update({ current: { ...patch, ctxPct: null } });
|
|
404
|
+
store.update({ current: { ...patch, ctxPct: null, ctxTokens: null } });
|
|
402
405
|
return;
|
|
403
406
|
}
|
|
404
407
|
const ctxWindow = "ctxWindow" in patch ? patch.ctxWindow : current.ctxWindow;
|
|
405
408
|
const pct = extractCtxPct(data, ctxWindow, current.llmContext?.budget_tokens);
|
|
406
409
|
if (pct !== null) patch.ctxPct = pct;
|
|
410
|
+
const tokens = ctxTokensOf(data);
|
|
411
|
+
if (tokens !== null) patch.ctxTokens = tokens;
|
|
407
412
|
store.update({ current: patch });
|
|
408
413
|
},
|
|
409
414
|
question_requested: (data) => {
|
|
@@ -3,11 +3,11 @@
|
|
|
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
|
-
--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);
|
|
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-lens-dim:.38;--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
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;
|
|
13
|
-
--card-hover-border:rgba(31,35,40,.18);--on-solid:#fff;--on-warn:#1f2328;--text-hover:#0d1117;--badge-bg:rgba(31,35,40,.06);--badge-ring:rgba(31,35,40,.15);--shadow-strong:rgba(31,35,40,.18);--backdrop:rgba(13,17,23,.85);--toast-shadow:0 6px 24px rgba(31,35,40,.14);--ws-stale-opacity:.55;--ws-rule:var(--border);--ws-muted:var(--text-muted);--ws-faint:var(--text-faint);--ws-act-border:var(--border-strong);--author-1:#0550ae;--author-2:#8250df;--author-3:#116329;--author-4:#953800;--author-5:#a40e26;--author-6:#7d4e00;--author-owner:var(--text-3);--time-gap:var(--text-faint)}}
|
|
13
|
+
--card-hover-border:rgba(31,35,40,.18);--on-solid:#fff;--on-warn:#1f2328;--text-hover:#0d1117;--badge-bg:rgba(31,35,40,.06);--badge-ring:rgba(31,35,40,.15);--shadow-strong:rgba(31,35,40,.18);--backdrop:rgba(13,17,23,.85);--toast-shadow:0 6px 24px rgba(31,35,40,.14);--ws-stale-opacity:.55;--ws-lens-dim:.38;--ws-rule:var(--border);--ws-muted:var(--text-muted);--ws-faint:var(--text-faint);--ws-act-border:var(--border-strong);--author-1:#0550ae;--author-2:#8250df;--author-3:#116329;--author-4:#953800;--author-5:#a40e26;--author-6:#7d4e00;--author-owner:var(--text-3);--time-gap:var(--text-faint)}}
|
|
@@ -304,7 +304,7 @@ export function initWaitLine({ tasks } = {}) {
|
|
|
304
304
|
// no "steered" badge, as a reload shows it).
|
|
305
305
|
// A participant's prompt's badge, as an op's field ({author}); {} for the
|
|
306
306
|
// owner's, so their ops stay as they were.
|
|
307
|
-
function authorOf(author, name = null, mode = null) {
|
|
307
|
+
export function authorOf(author, name = null, mode = null) {
|
|
308
308
|
const badge = authorBadge(author, name, mode);
|
|
309
309
|
return badge ? { author: badge } : {};
|
|
310
310
|
}
|
|
@@ -160,10 +160,10 @@ export function itemsOfTurn(turn, turnOrdinal) {
|
|
|
160
160
|
// rows) after them; the muted memories listed apart, never counted.
|
|
161
161
|
// @param turns the finished turns' item lists, in order
|
|
162
162
|
// @param live the running turn's items (or none)
|
|
163
|
-
export function sessionItems({ turns = [], live = [], preloaded = [], muted = [], used = [] } = {}) {
|
|
163
|
+
export function sessionItems({ turns = [], live = [], preloaded = [], notes = [], muted = [], used = [] } = {}) {
|
|
164
164
|
const items = [];
|
|
165
165
|
const byKey = new Map();
|
|
166
|
-
for (const name of preloaded || []) {
|
|
166
|
+
for (const name of [...(preloaded || []), ...(notes || []).map((note) => note.name)]) {
|
|
167
167
|
if (byKey.has(`memory:${name}`)) continue;
|
|
168
168
|
const item = { kind: "memory", key: name, label: name, ops: [], at: null, count: 0, state: "live", preloaded: true };
|
|
169
169
|
byKey.set(`memory:${name}`, item);
|
|
@@ -226,8 +226,9 @@ function serverItem(index, item) {
|
|
|
226
226
|
return index.urls.find((it) => String(it.key).startsWith(head)) || null;
|
|
227
227
|
}
|
|
228
228
|
|
|
229
|
-
// +items+ with the server's state, tokens, pinned
|
|
230
|
-
// has_drop: some output holds the user's drop)
|
|
229
|
+
// +items+ with the server's state, tokens, pinned, hasDrop (its
|
|
230
|
+
// has_drop: some output holds the user's drop) and a memory's scope (the
|
|
231
|
+
// one its latest read answered from; none from an older worker) (+server+: a snapshot
|
|
231
232
|
// {items, at}, or null); an item it doesn't know stays live, without
|
|
232
233
|
// tokens, unpinned. New objects only where something changed; never
|
|
233
234
|
// touches at, ops or count.
|
|
@@ -242,8 +243,13 @@ export function overlay(items, server) {
|
|
|
242
243
|
const serverKey = found && found.key !== item.key ? found.key : undefined;
|
|
243
244
|
const pinned = found?.pinned === true ? true : undefined;
|
|
244
245
|
const hasDrop = found?.has_drop === true ? true : undefined;
|
|
245
|
-
|
|
246
|
+
// A memory's scope (the one its latest read answered from): the head
|
|
247
|
+
// view matches it with the prompt's parts (ws_sections.js same).
|
|
248
|
+
const scope = item.kind === "memory" && typeof found?.scope === "string" ? found.scope : undefined;
|
|
249
|
+
if (item.state === state && item.tokens === tokens && item.serverKey === serverKey && item.pinned === pinned && item.hasDrop === hasDrop && item.scope === scope) return item;
|
|
246
250
|
const next = { ...item, state };
|
|
251
|
+
if (scope) next.scope = scope;
|
|
252
|
+
else delete next.scope;
|
|
247
253
|
if (pinned) next.pinned = true;
|
|
248
254
|
else delete next.pinned;
|
|
249
255
|
if (hasDrop) next.hasDrop = true;
|
|
@@ -435,6 +441,44 @@ export function fold(items, budget, { kept = [], lastResort: useLast = true } =
|
|
|
435
441
|
return { labels, groups };
|
|
436
442
|
}
|
|
437
443
|
|
|
444
|
+
// The popover's sections, in display order; muted memories follow its labels.
|
|
445
|
+
export function bodySections(set, budget) {
|
|
446
|
+
const files = set.items.filter((item) => item.kind === "file");
|
|
447
|
+
const memories = set.items.filter((item) => item.kind === "memory");
|
|
448
|
+
const urls = set.items.filter((item) => item.kind === "url");
|
|
449
|
+
const preloaded = memories.filter((item) => item.preloaded).length;
|
|
450
|
+
const memMeta = [`${memories.length - preloaded} used`, preloaded ? `${preloaded} in the prompt` : "", set.muted.length ? `${set.muted.length} muted` : ""].filter(Boolean).join(" · ");
|
|
451
|
+
const sections = [];
|
|
452
|
+
if (files.length) sections.push({ key: "files", title: "files", meta: String(files.length), labels: fold(files, budget).labels, muted: [] });
|
|
453
|
+
if (memories.length || set.muted.length) sections.push({
|
|
454
|
+
key: "memories", title: "memories", meta: memMeta,
|
|
455
|
+
labels: fold(memories, memories.length > budget ? 1 : Infinity).labels, muted: set.muted,
|
|
456
|
+
});
|
|
457
|
+
if (urls.length) sections.push({ key: "urls", title: "urls", meta: String(urls.length), labels: fold(urls, budget).labels, muted: [] });
|
|
458
|
+
return sections;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
// An item's key in the page's maps: the kind and the key, as the session's
|
|
462
|
+
// set and a turn's items both carry them.
|
|
463
|
+
export const itemKey = (item) => `${item.kind}:${item.key}`;
|
|
464
|
+
|
|
465
|
+
// A turn's lens on the session's list: +touched+ (the turn's items by key),
|
|
466
|
+
// their +count+ and how many are +fresh+ (new to the session: its first
|
|
467
|
+
// entry, in the session set, is this turn's, and not a prompt memory).
|
|
468
|
+
export function turnLens(sessionList, turnList, turn) {
|
|
469
|
+
const touched = new Map(turnList.map((item) => [itemKey(item), item]));
|
|
470
|
+
const fresh = sessionList.filter((item) => touched.has(itemKey(item)) && !item.preloaded && item.at?.turn === turn).length;
|
|
471
|
+
return { touched, count: touched.size, fresh };
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// The session's +item+ as a lens draws it: its state, tokens and the rest
|
|
475
|
+
// of the session's, with the turn's `at`, ops and count when the turn
|
|
476
|
+
// touched it. The session's item itself is not changed.
|
|
477
|
+
export function lensItem(item, touched) {
|
|
478
|
+
const turnItem = touched.get(itemKey(item));
|
|
479
|
+
return turnItem ? { ...item, at: turnItem.at, ops: turnItem.ops, count: turnItem.count } : item;
|
|
480
|
+
}
|
|
481
|
+
|
|
438
482
|
// The labels a form shows for +budget+: all of them when they fit, else
|
|
439
483
|
// the first budget − 1 and how many members the rest hold (its "+ n more").
|
|
440
484
|
export function shown(labels, budget) {
|
|
@@ -451,7 +495,7 @@ export function labelTitle(label) {
|
|
|
451
495
|
// ── tags, texts ───────────────────────────────────────────────────────────
|
|
452
496
|
|
|
453
497
|
// Where an item entered: "s3" (step 3 of its turn), "t2·s3" in the
|
|
454
|
-
// session
|
|
498
|
+
// session lens, "prompt" for a preloaded memory, "" when unknown.
|
|
455
499
|
export function stepTag(item, { session = false } = {}) {
|
|
456
500
|
if (item?.preloaded) return "prompt";
|
|
457
501
|
const at = item?.at;
|
|
@@ -666,7 +710,7 @@ export function pendingSteers(lines, dir = "", adds = []) {
|
|
|
666
710
|
// unpin first (WorkingSetSteer::Refused's words).
|
|
667
711
|
export function dropRefusal(item) {
|
|
668
712
|
if (item.muted || item.state === "dropped") return null;
|
|
669
|
-
if (item.preloaded && !item.ops.includes("read")) return "
|
|
713
|
+
if (item.preloaded && !item.ops.includes("read")) return "in the system prompt: not dropped from here";
|
|
670
714
|
if (!Number.isFinite(item.tokens)) return null;
|
|
671
715
|
if (item.pinned) return "pinned by the user: unpin it first";
|
|
672
716
|
if (!item.ops.includes("read")) return "only edited or written: nothing of it to drop";
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// keyed by their label's id and patched only when what they show changes,
|
|
7
7
|
// so nothing restarts; a fold fades the absorbed lines out in place and the
|
|
8
8
|
// lines below slide up once (each line sits at its slot by a transform).
|
|
9
|
-
// Collapsed (kept per browser), it is its head line only, with the newest
|
|
9
|
+
// Collapsed (kept per session, per browser: session_prefs.js), it is its head line only, with the newest
|
|
10
10
|
// entry ticking through it. Read-only: steering is the expanded view's; a
|
|
11
11
|
// line with a pending op (a /working-set line queued for the turn's end) is
|
|
12
12
|
// dashed, its title saying what applies next turn; an item added that the
|
|
@@ -32,9 +32,11 @@ export function addLabels(items, pending) {
|
|
|
32
32
|
n: 1, edited: 0, cut: 0, state: "live", members: [], added: true,
|
|
33
33
|
}));
|
|
34
34
|
}
|
|
35
|
-
import {
|
|
35
|
+
import { WS_RAIL_FOLD, read as readPref, write as writePref } from "./session_prefs.js";
|
|
36
36
|
import { reducedMotion } from "./stage_frame.js";
|
|
37
37
|
|
|
38
|
+
// session_prefs.js WS_RAIL_FOLD's name (chi_working_set_collapsed:<session>),
|
|
39
|
+
// kept for an older importer.
|
|
38
40
|
export const COLLAPSE_KEY = "chi_working_set_collapsed";
|
|
39
41
|
// The stage width (px) under which the rail is a row; the phone's
|
|
40
42
|
// (index.html, under 600 px of window) shows neither.
|
|
@@ -96,8 +98,9 @@ export function createRing(parent) {
|
|
|
96
98
|
// +live+: the stage's live block (the rail goes last in it); +stage+: the
|
|
97
99
|
// stage (its width picks the form); +onOpen(railEl)+: the expanded view;
|
|
98
100
|
// +onChange()+: redraw (the stage's scheduleRefresh), for the fresh cue's
|
|
99
|
-
// end and a form change.
|
|
100
|
-
|
|
101
|
+
// end and a form change. +sessionId()+: the open session's id, whose fold is
|
|
102
|
+
// kept (null: in memory only).
|
|
103
|
+
export function createWorkingSetRail({ live, stage, onOpen, onChange, sessionId = () => null }) {
|
|
101
104
|
const rail = el("div", "ts-ws", live);
|
|
102
105
|
rail.setAttribute("role", "button");
|
|
103
106
|
rail.setAttribute("aria-haspopup", "dialog");
|
|
@@ -112,7 +115,8 @@ export function createWorkingSetRail({ live, stage, onOpen, onChange }) {
|
|
|
112
115
|
foldBtn.type = "button";
|
|
113
116
|
const list = el("div", "ws-list", rail);
|
|
114
117
|
|
|
115
|
-
|
|
118
|
+
const savedCollapsed = () => readPref(WS_RAIL_FOLD, sessionId(), "0") === "1";
|
|
119
|
+
let collapsed = savedCollapsed();
|
|
116
120
|
let width = 0;
|
|
117
121
|
// The turn's fold so far (its groups stay), each line's node by label id
|
|
118
122
|
// and what it shows, the items' first sight (the fresh cue), and when the
|
|
@@ -146,7 +150,7 @@ export function createWorkingSetRail({ live, stage, onOpen, onChange }) {
|
|
|
146
150
|
|
|
147
151
|
function setCollapsed(value) {
|
|
148
152
|
collapsed = value;
|
|
149
|
-
|
|
153
|
+
writePref(WS_RAIL_FOLD, sessionId(), value ? "1" : "0");
|
|
150
154
|
applyCollapsed();
|
|
151
155
|
shownHead = null;
|
|
152
156
|
onChange?.();
|
|
@@ -303,5 +307,16 @@ export function createWorkingSetRail({ live, stage, onOpen, onChange }) {
|
|
|
303
307
|
// For the expanded view: when an item was first seen (its fresh cue).
|
|
304
308
|
const seenAt = (item) => seen.get(`${item.kind}:${item.key}`);
|
|
305
309
|
|
|
306
|
-
|
|
310
|
+
// The open session's own fold, read again as its view is drawn
|
|
311
|
+
// (stage_view.js applyPrefs); redrawn only when it changed.
|
|
312
|
+
function applyPrefs() {
|
|
313
|
+
const next = savedCollapsed();
|
|
314
|
+
if (next === collapsed) return;
|
|
315
|
+
collapsed = next;
|
|
316
|
+
applyCollapsed();
|
|
317
|
+
shownHead = null;
|
|
318
|
+
onChange?.();
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
return { el: rail, draw, reset, seenAt, form, applyPrefs, isCollapsed: () => collapsed };
|
|
307
322
|
}
|