samagotchi 0.176.0 → 0.177.1
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 +47 -1
- data/docs/architecture.md +5 -4
- data/docs/cli.md +12 -5
- data/docs/internals/bundles.md +4 -3
- data/docs/internals/participants.md +10 -6
- data/docs/internals/prompt-caching.md +3 -0
- data/docs/internals/session-lifecycle.md +167 -0
- data/docs/internals/web-frontend.md +25 -8
- data/docs/internals/working-set.md +78 -6
- data/docs/plugins.md +1 -1
- data/docs/releasing.md +3 -2
- data/docs/sessions.md +8 -5
- data/docs/testing.md +4 -2
- data/lib/samagotchi/bridge.rb +3 -3
- data/lib/samagotchi/bundle_command/check.rb +1 -1
- data/lib/samagotchi/bundles/system/manifest.yml +1 -1
- data/lib/samagotchi/compat.rb +1 -1
- data/lib/samagotchi/engine/models.rb +11 -0
- data/lib/samagotchi/engine/session.rb +16 -0
- data/lib/samagotchi/engine.rb +1 -0
- data/lib/samagotchi/engine_snapshots.rb +3 -0
- data/lib/samagotchi/memory_bundle/shipped_update.rb +1 -1
- data/lib/samagotchi/note_delivery.rb +9 -4
- data/lib/samagotchi/plugin/sessions.rb +2 -1
- data/lib/samagotchi/prompt_part.rb +66 -0
- data/lib/samagotchi/revise_anchor.rb +2 -0
- data/lib/samagotchi/schedules.rb +3 -1
- data/lib/samagotchi/session.rb +10 -1
- data/lib/samagotchi/session_chain/delete.rb +28 -5
- data/lib/samagotchi/session_chain/delete_preview.rb +2 -2
- data/lib/samagotchi/session_inbox.rb +29 -0
- data/lib/samagotchi/session_inbox_delivery.rb +13 -5
- data/lib/samagotchi/session_lifecycle/allowed.rb +66 -0
- data/lib/samagotchi/session_lifecycle/canonical.rb +49 -0
- data/lib/samagotchi/session_lifecycle/reading.rb +65 -0
- data/lib/samagotchi/session_lifecycle.rb +59 -0
- data/lib/samagotchi/session_manager/delivery.rb +29 -6
- data/lib/samagotchi/session_manager/lifecycle.rb +22 -14
- data/lib/samagotchi/session_manager/removal.rb +16 -8
- data/lib/samagotchi/session_manager/spawn.rb +2 -2
- data/lib/samagotchi/sessions_command.rb +1 -1
- data/lib/samagotchi/system_prompt.rb +211 -12
- data/lib/samagotchi/tool_names.rb +1 -1
- data/lib/samagotchi/tools/memory.rb +29 -0
- data/lib/samagotchi/turn_anchors.rb +5 -0
- data/lib/samagotchi/verify_anchor.rb +2 -0
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/participant_show.rb +4 -5
- data/lib/samagotchi/web/participant_view.rb +4 -6
- data/lib/samagotchi/web/public/app.js +3 -0
- data/lib/samagotchi/web/public/ctx_tokens.js +33 -0
- data/lib/samagotchi/web/public/data.js +6 -2
- data/lib/samagotchi/web/public/delete_sheet.js +42 -5
- data/lib/samagotchi/web/public/index.html +43 -9
- data/lib/samagotchi/web/public/session_fields.js +10 -4
- data/lib/samagotchi/web/public/session_prefs.js +5 -2
- 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_view.js +1 -1
- data/lib/samagotchi/web/public/stream_handlers.js +7 -3
- data/lib/samagotchi/web/public/tokens.css +2 -2
- data/lib/samagotchi/web/public/working_set.js +51 -7
- data/lib/samagotchi/web/public/working_set_view.js +188 -58
- data/lib/samagotchi/web/public/ws_sections.js +252 -0
- data/lib/samagotchi/web/session_control.rb +4 -3
- data/lib/samagotchi/web/session_show.rb +13 -2
- data/lib/samagotchi/web/session_summary.rb +7 -0
- data/lib/samagotchi/worker/command_queue.rb +5 -1
- data/lib/samagotchi/worker/startup.rb +1 -1
- data/lib/samagotchi/worker.rb +1 -0
- data/lib/samagotchi/worker_boot.rb +9 -6
- data/lib/samagotchi/worker_presence.rb +4 -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 +14 -3
- metadata +9 -1
|
@@ -7,8 +7,9 @@
|
|
|
7
7
|
// The sheet's words come from GET /api/sessions/:id/delete_plan, the plan
|
|
8
8
|
// and refusals the server's delete itself runs (SessionChain::Delete::
|
|
9
9
|
// Preview), fetched as the sheet opens and only for a chained session: a
|
|
10
|
-
// session in no chain keeps today's confirm (session_actions.js).
|
|
11
|
-
//
|
|
10
|
+
// session in no chain keeps today's confirm (session_actions.js). The
|
|
11
|
+
// confirmed digest is checked by the delete; a changed plan is re-read and
|
|
12
|
+
// shown for a fresh confirmation.
|
|
12
13
|
//
|
|
13
14
|
// Where it is drawn (a host): the ⋯ More panel turns into it, with ‹ More to
|
|
14
15
|
// go back (more_sheet.js' subview); a card's ✕ opens it at the card, on
|
|
@@ -111,6 +112,19 @@ export function deleteChoices(session, plan) {
|
|
|
111
112
|
};
|
|
112
113
|
}
|
|
113
114
|
|
|
115
|
+
function unchainedChoices(session, plan) {
|
|
116
|
+
const id = session?.id ?? plan?.session_id;
|
|
117
|
+
const name = sessionName(session);
|
|
118
|
+
return {
|
|
119
|
+
title: `Delete ${short(id)}${name ? ` — "${name}"` : ""}?`,
|
|
120
|
+
sub: "This session is no longer in a chain. This can't be undone.",
|
|
121
|
+
banner: null,
|
|
122
|
+
choices: [{ act: "this", label: "Delete this session", lines: ["Its turns and session data will be permanently deleted."],
|
|
123
|
+
primary: true }],
|
|
124
|
+
foot: "This can't be undone.",
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
114
128
|
function choiceTemplate(choice) {
|
|
115
129
|
const cls = `ds-choice${choice.primary ? " primary" : ""}`;
|
|
116
130
|
if (choice.disabled) {
|
|
@@ -132,11 +146,12 @@ function headTemplate(back) {
|
|
|
132
146
|
|
|
133
147
|
// The choices (a lit-html template). +busy+: a delete under way (every
|
|
134
148
|
// button off); +back+: drawn in the More panel.
|
|
135
|
-
export function deleteSheetTemplate(model, { back = false, busy = false } = {}) {
|
|
149
|
+
export function deleteSheetTemplate(model, { back = false, busy = false, notice = null } = {}) {
|
|
136
150
|
const allOff = model.choices.every((c) => c.disabled);
|
|
137
151
|
return html`<div class=${`delete-sheet${busy ? " busy" : ""}`}>${headTemplate(back)}
|
|
138
152
|
<div class="ds-title">${model.title}</div>
|
|
139
153
|
<div class="ds-sub">${model.sub}</div>
|
|
154
|
+
${notice ? html`<div class="ds-banner">${notice}</div>` : nothing}
|
|
140
155
|
${model.banner ? html`<div class="ds-banner">${model.banner}</div>` : nothing}
|
|
141
156
|
<div class="ds-choices" ?inert=${busy}>${model.choices.map(choiceTemplate)}</div>
|
|
142
157
|
<div class="ds-foot">${allOff ? html`<span></span>` : html`<span class="ds-note">${busy ? "Deleting…" : model.foot}</span>`}
|
|
@@ -224,6 +239,7 @@ export function listAfterDelete(list, result) {
|
|
|
224
239
|
export function runDeleteFlow({ id, session, host, api, done, plain, failed }) {
|
|
225
240
|
let plan = null;
|
|
226
241
|
let model = null;
|
|
242
|
+
let notice = null;
|
|
227
243
|
let refusal = null;
|
|
228
244
|
let busy = false;
|
|
229
245
|
const back = !!host.back;
|
|
@@ -233,7 +249,7 @@ export function runDeleteFlow({ id, session, host, api, done, plain, failed }) {
|
|
|
233
249
|
const live = () => (host.live ? host.live() : true);
|
|
234
250
|
const show = (tpl) => { if (live()) host.show(tpl); };
|
|
235
251
|
|
|
236
|
-
const showChoices = () => show(deleteSheetTemplate(model, { back, busy }));
|
|
252
|
+
const showChoices = () => show(deleteSheetTemplate(model, { back, busy, notice }));
|
|
237
253
|
const showRefusal = () => show(refusalTemplate(refusalModel(refusal, plan?.link?.previous_id), { back }));
|
|
238
254
|
|
|
239
255
|
show(loadingTemplate({ back }));
|
|
@@ -258,14 +274,35 @@ export function runDeleteFlow({ id, session, host, api, done, plain, failed }) {
|
|
|
258
274
|
busy = true;
|
|
259
275
|
showChoices();
|
|
260
276
|
try {
|
|
261
|
-
const
|
|
277
|
+
const digest = which === "chain" ? plan?.chain?.digest : plan?.link?.digest;
|
|
278
|
+
const result = which === "chain" ? await api.deleteChain(id, { expect: digest }) : await api.deleteSession(id, { expect: digest });
|
|
262
279
|
if (live()) host.close();
|
|
263
280
|
done(which, result, plan);
|
|
264
281
|
} catch (error) {
|
|
282
|
+
if (error.code === "plan_changed") {
|
|
283
|
+
await refreshPlan();
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
265
286
|
refused(error);
|
|
266
287
|
}
|
|
267
288
|
}
|
|
268
289
|
|
|
290
|
+
async function refreshPlan() {
|
|
291
|
+
show(loadingTemplate({ back }));
|
|
292
|
+
try {
|
|
293
|
+
const read = await api.deletePlan(id);
|
|
294
|
+
if (!live()) return;
|
|
295
|
+
plan = read;
|
|
296
|
+
model = read?.chained ? deleteChoices(session, plan) : unchainedChoices(session, plan);
|
|
297
|
+
notice = "What this deletes changed; check again";
|
|
298
|
+
busy = false;
|
|
299
|
+
showChoices();
|
|
300
|
+
} catch (error) {
|
|
301
|
+
busy = false;
|
|
302
|
+
if (live()) { host.close(); failed(error); }
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
269
306
|
// "Stop its worker, then delete": the delete again only once each worker
|
|
270
307
|
// reads stopped (the stop route's released, after its bounded wait);
|
|
271
308
|
// still running, the refusal says so, and nothing loops.
|
|
@@ -1123,12 +1123,41 @@ button.ws-step:hover:not(:disabled){filter:none}@media(hover:hover){button.ws-st
|
|
|
1123
1123
|
/* The expanded view (a chip popover; a bottom sheet on a phone). */
|
|
1124
1124
|
.ws-popover{gap:0}
|
|
1125
1125
|
.ws-popover .ctx-pop-head{align-items:center;flex-wrap:wrap;margin-bottom:4px}
|
|
1126
|
-
.
|
|
1127
|
-
.ws-
|
|
1128
|
-
.ws-
|
|
1129
|
-
.ws-
|
|
1126
|
+
/* The ring sits by ×, at the header's end (no size text between them now). */
|
|
1127
|
+
.ws-popover .ctx-pop-head>.ws-ring{margin-left:auto}
|
|
1128
|
+
.ws-popover .ctx-pop-head>.ws-ring~.ctx-pop-close{margin-left:0}
|
|
1129
|
+
.ws-lens{display:inline-flex;gap:2px;align-items:center}
|
|
1130
|
+
.ws-lens button{padding:1px 8px;border:1px solid transparent;border-radius:999px;background:transparent;color:var(--text-muted);font-size:11px;line-height:16px}
|
|
1131
|
+
.ws-lens button.arrow{padding:1px 5px}
|
|
1132
|
+
.ws-lens button.on{color:var(--text-2);border-color:var(--border-strong);background:var(--bg-raised)}
|
|
1133
|
+
.ws-lens button:disabled{opacity:.4}
|
|
1134
|
+
.ws-lens button:hover:not(:disabled){filter:none}@media(hover:hover){.ws-lens button:hover:not(:disabled){color:var(--text)}}
|
|
1135
|
+
/* A turn lens (--ws-lens-dim): the rows the turn touched lit, the rest dimmed; the line under the header says how many. */
|
|
1136
|
+
.ws-row.dim{opacity:var(--ws-lens-dim)}
|
|
1137
|
+
.ws-row.lit{background:var(--accent-tint)}
|
|
1130
1138
|
.ws-popover .ctx-pop-meta{margin-top:6px;color:var(--ws-muted)}
|
|
1139
|
+
.ws-popover .ws-lens-line{color:var(--accent)}
|
|
1131
1140
|
.ws-popover .ws-hint{margin-top:10px;color:var(--ws-faint)}
|
|
1141
|
+
/* The head view (ws_sections.js): From the start · Read in this session · Conversation, each header folding (per session); prompt parts read-only rows; a prompt memory read again "held twice" in the warn tokens. */
|
|
1142
|
+
.ws-sec-head{display:flex;align-items:center;gap:8px;width:100%;min-height:30px;box-sizing:border-box;margin-top:6px;padding:0 6px;border:0;border-top:1px solid var(--border);border-radius:0;background:transparent;font-family:ui-sans-serif,system-ui,sans-serif;font-size:12px;color:var(--ws-muted);text-align:left;cursor:pointer}
|
|
1143
|
+
.ws-sec-head:hover:not(:disabled){filter:none}@media(hover:hover){.ws-sec-head:hover{background:var(--bg-hover)}}
|
|
1144
|
+
.ws-sec-head .k{flex:none;width:12px;text-align:center;color:var(--ws-faint)}
|
|
1145
|
+
.ws-sec-head .t{font-weight:600;color:var(--text-2)}
|
|
1146
|
+
.ws-sec-head .n{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--ws-faint)}
|
|
1147
|
+
.ws-sec-head .tk{flex:none;margin-left:auto;font-size:11px;color:var(--ws-faint);font-variant-numeric:tabular-nums}
|
|
1148
|
+
.ws-sec .ws-sub{margin-top:2px;padding-left:6px}
|
|
1149
|
+
.ws-row.part .t{margin-right:auto;font-family:ui-sans-serif,system-ui,sans-serif}
|
|
1150
|
+
/* Conversation: one row at section level (a section header's look, nothing to fold). */
|
|
1151
|
+
.ws-row.ws-sec-row{height:30px;margin-top:6px;border-top:1px solid var(--border);border-radius:0;font-family:ui-sans-serif,system-ui,sans-serif;font-size:12px}
|
|
1152
|
+
.ws-row.ws-sec-row .t{flex:none;font-weight:600;color:var(--text-2)}
|
|
1153
|
+
.ws-row.ws-sec-row .n{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--ws-faint)}
|
|
1154
|
+
.ws-row.ws-sec-row .tk{margin-left:auto}
|
|
1155
|
+
.ws-popover.sheet .ws-row.ws-sec-row{font-size:13px}
|
|
1156
|
+
.ws-twice{flex:none;padding:0 6px;border:1px solid var(--warn-border);border-radius:999px;background:var(--warn-bg);color:var(--warn-text);font-family:ui-sans-serif,system-ui,sans-serif;font-size:10.5px;line-height:15px;white-space:nowrap}
|
|
1157
|
+
.ws-step.twice{color:var(--warn-text);background:var(--warn-bg)}
|
|
1158
|
+
.ws-row.twice.lit{background:var(--warn-bg)}
|
|
1159
|
+
.ws-note{padding:0 6px 4px 26px;font-size:11px;line-height:15px}
|
|
1160
|
+
.ws-note.twice{color:var(--warn-text);background:var(--warn-bg);border-radius:0 0 6px 6px}
|
|
1132
1161
|
.ws-row{display:flex;align-items:center;gap:8px;width:100%;min-width:0;height:28px;box-sizing:border-box;padding:0 6px;border:0;border-radius:6px;background:transparent;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12.5px;line-height:28px;color:var(--text-2);text-align:left}
|
|
1133
1162
|
@media(hover:hover){.ws-row:hover{background:var(--bg-hover)}}
|
|
1134
1163
|
button.ws-row:hover:not(:disabled){filter:none}@media(hover:hover){button.ws-row:hover:not(:disabled){background:var(--bg-hover)}}
|
|
@@ -1172,11 +1201,16 @@ button.ws-row:hover:not(:disabled){filter:none}@media(hover:hover){button.ws-row
|
|
|
1172
1201
|
.ws-strip{display:flex;gap:8px;padding:2px 6px 6px 26px}
|
|
1173
1202
|
.ws-strip .ws-act-b{padding:0 14px;font-size:12.5px;line-height:28px;border-radius:6px}
|
|
1174
1203
|
.ws-popover.sheet{border-radius:14px}
|
|
1175
|
-
/* A phone's sheet: the name, the
|
|
1176
|
-
.ws-popover.sheet .ctx-pop-
|
|
1177
|
-
.ws-popover.sheet .
|
|
1178
|
-
.
|
|
1179
|
-
.ws-popover.sheet .
|
|
1204
|
+
/* A phone's sheet: one line, the name, the lens, the ring and ×; the size is the line under it. */
|
|
1205
|
+
.ws-popover.sheet .ctx-pop-head{flex-wrap:nowrap;gap:4px}
|
|
1206
|
+
.ws-popover.sheet .ws-lens{flex:none;white-space:nowrap}
|
|
1207
|
+
/* A long turn number (turn 100) shortens the name, never wraps the line. */
|
|
1208
|
+
.ws-popover.sheet .ctx-pop-head strong{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
1209
|
+
/* A phone's sheet: rows and lens buttons 44 px targets; a part row drops its sub text. */
|
|
1210
|
+
.ws-popover.sheet .ws-row{height:44px;line-height:44px}
|
|
1211
|
+
.ws-popover.sheet .ws-sec-head{min-height:44px;font-size:13px}
|
|
1212
|
+
.ws-popover.sheet .ws-lens button{min-height:44px;min-width:44px;padding:1px 4px;font-size:12.5px;white-space:nowrap}
|
|
1213
|
+
.ws-popover.sheet .ws-row.part .st{display:none}
|
|
1180
1214
|
/* + add: the list's foot (a sheet's last row), one KEY typed; an added item the set doesn't hold yet is a pending row of its own. */
|
|
1181
1215
|
.ws-add{display:flex;align-items:center;gap:6px;margin-top:8px}
|
|
1182
1216
|
.ws-add-in{flex:1;min-width:0;height:26px;box-sizing:border-box;padding:0 8px;border:1px dashed var(--border-strong);border-radius:6px;background:transparent;color:var(--text);font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px}
|
|
@@ -34,12 +34,15 @@ export const FIELDS = {
|
|
|
34
34
|
firstPreview: { redraws: ["infoBar"], writers: "send_turn.js (the first prompt)" },
|
|
35
35
|
usedMemories: {
|
|
36
36
|
source: (d) => list(d.session?.used_memory_names),
|
|
37
|
-
redraws: ["infoBar"],
|
|
37
|
+
redraws: ["workingSet", "infoBar"],
|
|
38
38
|
writers: "setUsedMemories (stream), readTurnEnd; both replace the card too",
|
|
39
39
|
},
|
|
40
|
-
preloadedMemories: { source: (d) => list(d.session?.preloaded_memory_names), redraws: ["infoBar"], writers: "the payload" },
|
|
40
|
+
preloadedMemories: { source: (d) => list(d.session?.preloaded_memory_names), redraws: ["workingSet", "infoBar"], writers: "the payload" },
|
|
41
41
|
mutedMemories: { source: (d) => list(d.session?.muted_memory_names), redraws: ["infoBar"], writers: "the payload" },
|
|
42
|
-
promptNotes: { source: (d) => list(d.session?.prompt_notes), redraws: ["infoBar"], writers: "readTurnEnd" },
|
|
42
|
+
promptNotes: { source: (d) => list(d.session?.prompt_notes), redraws: ["workingSet", "infoBar"], writers: "readTurnEnd" },
|
|
43
|
+
// A tail without the key (an older live worker) keeps the parts the page
|
|
44
|
+
// has: unknown is not none; only a list replaces them.
|
|
45
|
+
promptParts: { source: (d) => list(d.session?.prompt_parts), redraws: ["workingSet"], writers: "readTurnEnd" },
|
|
43
46
|
parentId: { redraws: ["infoBar"], writers: "the payload" },
|
|
44
47
|
continues: { redraws: ["infoBar"], writers: "the payload" },
|
|
45
48
|
verdicts: {
|
|
@@ -54,7 +57,10 @@ export const FIELDS = {
|
|
|
54
57
|
},
|
|
55
58
|
createdAt: { redraws: ["infoBar"], writers: "the payload" },
|
|
56
59
|
ctxPct: { redraws: ["infoBar"], writers: "session_state.js sessionStateFrom (the payload's context_status, else the saved fill), stream_handlers.js (generation_chunk, context_status)" },
|
|
57
|
-
|
|
60
|
+
// Changes with almost every chunk: its redraw draws the open list only
|
|
61
|
+
// when the text it shows changes (working_set_view.js tokensChanged).
|
|
62
|
+
ctxTokens: { redraws: ["workingSetTokens"], writers: "session_state.js sessionStateFrom (ctx_tokens.js loadedCtxTokens), stream_handlers.js (generation_chunk, context_status; cleared with ctxPct)" },
|
|
63
|
+
ctxWindow: { redraws: ["workingSetTokens", "infoBar"], writers: "stream_handlers.js (generation_started, context_status)" },
|
|
58
64
|
ctxWindowSource: { redraws: ["infoBar"], writers: "stream_handlers.js (generation_started, context_status)" },
|
|
59
65
|
ctxUnknownAfterSwitch: { redraws: ["infoBar"], writers: "stream_handlers.js (generation_started, context_status)" },
|
|
60
66
|
status: {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// A session's own view settings (per browser, localStorage through
|
|
2
2
|
// storage.js): the stage's fold, the composer's dragged height and its fold,
|
|
3
|
-
// the working-set rail's fold
|
|
3
|
+
// the working-set rail's fold, the working-set list's folded sections
|
|
4
|
+
// (ws_sections.js WS_SECTION_FOLD, defined there: a new export here would
|
|
5
|
+
// blank a page holding this module cached). Each is kept under `<key>:<session>`, so what
|
|
4
6
|
// you do to one session's window never shows in another, and a session never
|
|
5
7
|
// set by hand follows the default: the page's own (the stage fold's comes
|
|
6
8
|
// from config, web.stage_collapsed, as <body data-stage-collapsed="1">), else
|
|
@@ -20,12 +22,13 @@
|
|
|
20
22
|
// A module of its own: static JS is cached at unversioned URLs, and a new
|
|
21
23
|
// export on an old module would blank the page.
|
|
22
24
|
import { readStored, removeStored, storedKeys, writeStored } from "./storage.js";
|
|
25
|
+
import { WS_SECTION_FOLD } from "./ws_sections.js";
|
|
23
26
|
|
|
24
27
|
export const STAGE_FOLD = "chi_stage_collapsed";
|
|
25
28
|
export const COMPOSER_FLOOR = "chi_composer_floor";
|
|
26
29
|
export const COMPOSER_FOLD = "chi_composer_collapsed";
|
|
27
30
|
export const WS_RAIL_FOLD = "chi_working_set_collapsed";
|
|
28
|
-
export const PREF_KEYS = [STAGE_FOLD, COMPOSER_FLOOR, COMPOSER_FOLD, WS_RAIL_FOLD];
|
|
31
|
+
export const PREF_KEYS = [STAGE_FOLD, COMPOSER_FLOOR, COMPOSER_FOLD, WS_RAIL_FOLD, WS_SECTION_FOLD];
|
|
29
32
|
|
|
30
33
|
// The page's defaults: <body>'s data attribute that turns a key on ("1").
|
|
31
34
|
const PAGE_DEFAULTS = { [STAGE_FOLD]: "stageCollapsed" };
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
// shows for the next one).
|
|
6
6
|
|
|
7
7
|
import { savedCtxPct } from "./ctx.js";
|
|
8
|
+
import { loadedCtxTokens } from "./ctx_tokens.js";
|
|
8
9
|
import { firstPreview, previewForCard } from "./format.js";
|
|
9
10
|
import { normalizeTiming } from "./timing.js";
|
|
10
11
|
|
|
@@ -19,6 +20,10 @@ export function emptySessionState() {
|
|
|
19
20
|
// The model notes the session's prompt carried (its prompt_notes: name,
|
|
20
21
|
// scope, chars, digest; the info bar's notes chip).
|
|
21
22
|
promptNotes: [],
|
|
23
|
+
// The parts of its system prompt as sizes (its prompt_parts: kind, label,
|
|
24
|
+
// chars, tokens, ref; the working set's "From the start"). [] from an
|
|
25
|
+
// older worker or file: no head-view sections.
|
|
26
|
+
promptParts: [],
|
|
22
27
|
// A delegated session's parent (the info bar's "delegated by" chip).
|
|
23
28
|
parentId: null,
|
|
24
29
|
// The previous link of its chain (its `continues`), or null.
|
|
@@ -30,6 +35,9 @@ export function emptySessionState() {
|
|
|
30
35
|
// times on its day), or null.
|
|
31
36
|
createdAt: null,
|
|
32
37
|
ctxPct: null,
|
|
38
|
+
// The tokens in context now (ctx_tokens.js: the count ctxPct is of; the
|
|
39
|
+
// working set's "in chi's head now"), or null.
|
|
40
|
+
ctxTokens: null,
|
|
33
41
|
// Window the kernel resolved for the running generation (:generation_started).
|
|
34
42
|
ctxWindow: null,
|
|
35
43
|
// Where it came from ("server", "config", … "default": chi's guess).
|
|
@@ -111,7 +119,8 @@ export function sessionStateFrom(data) {
|
|
|
111
119
|
// JSON as context_status, kept per request by the Engine) beats the saved
|
|
112
120
|
// fill, which is only the last counted turn's; without it, the saved fill.
|
|
113
121
|
const livePct = s.context_status?.est_pct;
|
|
114
|
-
|
|
122
|
+
const live = typeof livePct === "number" && Number.isFinite(livePct);
|
|
123
|
+
if (live) {
|
|
115
124
|
state.ctxPct = livePct;
|
|
116
125
|
} else {
|
|
117
126
|
// The saved fill, so a reloaded or stopped session shows it before its
|
|
@@ -119,6 +128,9 @@ export function sessionStateFrom(data) {
|
|
|
119
128
|
const savedPct = savedCtxPct(data.timing?.context, s.llm_context?.budget_tokens);
|
|
120
129
|
if (savedPct !== null) state.ctxPct = savedPct;
|
|
121
130
|
}
|
|
131
|
+
// Its tokens, from the same source; left out (kept) when neither says.
|
|
132
|
+
const tokens = loadedCtxTokens({ pct: live ? livePct : null, context: data.timing?.context, budgetTokens: s.llm_context?.budget_tokens });
|
|
133
|
+
if (tokens !== null) state.ctxTokens = tokens;
|
|
122
134
|
if (data.timing?.context?.window_tokens) {
|
|
123
135
|
state.ctxWindow = data.timing.context.window_tokens;
|
|
124
136
|
state.ctxWindowSource = data.timing.context.window_source || null;
|
|
@@ -128,6 +140,7 @@ export function sessionStateFrom(data) {
|
|
|
128
140
|
state.preloadedMemories = s.preloaded_memory_names || [];
|
|
129
141
|
state.mutedMemories = s.muted_memory_names || [];
|
|
130
142
|
state.promptNotes = Array.isArray(s.prompt_notes) ? s.prompt_notes : [];
|
|
143
|
+
state.promptParts = Array.isArray(s.prompt_parts) ? s.prompt_parts : [];
|
|
131
144
|
state.llmContext = s.llm_context || null;
|
|
132
145
|
state.thinking = s.thinking || null;
|
|
133
146
|
// null on a native host (it ignores the level) and from an older worker.
|
|
@@ -17,7 +17,7 @@ import { FIELDS, statusWrite } from "./session_fields.js";
|
|
|
17
17
|
export const ORDER = [
|
|
18
18
|
"lists",
|
|
19
19
|
"paintActive",
|
|
20
|
-
"settingsPanel", "workingSetStrategy",
|
|
20
|
+
"settingsPanel", "workingSetStrategy", "workingSet", "workingSetTokens",
|
|
21
21
|
"featureGates",
|
|
22
22
|
"composer",
|
|
23
23
|
"infoBar",
|
|
@@ -283,7 +283,7 @@ export function createSessionView(deps) {
|
|
|
283
283
|
// answer's markdown.
|
|
284
284
|
store.batch(() => {
|
|
285
285
|
// The notes chip: the first turn's build (or a /model) records them.
|
|
286
|
-
applySessionPayload(d, { fields: ["usedMemories", "promptNotes"] });
|
|
286
|
+
applySessionPayload(d, { fields: ["usedMemories", "promptNotes", "promptParts"] });
|
|
287
287
|
turnEndStatus(d);
|
|
288
288
|
setMarkdownWarning(d.markdown_warning);
|
|
289
289
|
markdownTip.show(d.markdown_tip);
|
|
@@ -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
|
|
@@ -399,12 +401,14 @@ export function createStreamHandlers(deps) {
|
|
|
399
401
|
patch.ctxUnknownAfterSwitch = !data.context_window_tokens;
|
|
400
402
|
}
|
|
401
403
|
if (data && "usage" in data && data.usage === null) {
|
|
402
|
-
store.update({ current: { ...patch, ctxPct: null } });
|
|
404
|
+
store.update({ current: { ...patch, ctxPct: null, ctxTokens: null } });
|
|
403
405
|
return;
|
|
404
406
|
}
|
|
405
407
|
const ctxWindow = "ctxWindow" in patch ? patch.ctxWindow : current.ctxWindow;
|
|
406
408
|
const pct = extractCtxPct(data, ctxWindow, current.llmContext?.budget_tokens);
|
|
407
409
|
if (pct !== null) patch.ctxPct = pct;
|
|
410
|
+
const tokens = ctxTokensOf(data);
|
|
411
|
+
if (tokens !== null) patch.ctxTokens = tokens;
|
|
408
412
|
store.update({ current: patch });
|
|
409
413
|
},
|
|
410
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)}}
|
|
@@ -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";
|