@alexsun-top/opencode-chat-room 0.6.4 → 0.6.5

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.6.5 — 2026-11-15
4
+
5
+ - Keep a room at the bottom while the reader is following it: any growth of the message list pins the view, instead of deciding from scroll events that arrive in an unpredictable order. Only the reader's own wheel, touch, key, or scrollbar drag ends following, and the view stays still while a pointer gesture or a text selection is in progress. Opening a room, jumping to the latest message, and landing after a resize still end at the bottom.
6
+
3
7
  ## 0.6.4 — 2026-11-15
4
8
 
5
9
  - Forbid the host's built-in question, confirmation, and approval dialogs for any agent that belongs to a room: every question and every manual step goes into the room, even when the person who must answer is the operator of the current session. Native dialogs leave no room record and only reach one human.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alexsun-top/opencode-chat-room",
3
- "version": "0.6.4",
3
+ "version": "0.6.5",
4
4
  "description": "A chat-room plugin and central server for OpenCode.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -27,15 +27,19 @@ export function initEvents(app) {
27
27
  const thread = $("#thread");
28
28
  app.state.listMetrics = { height: messageList.offsetHeight, top: thread.scrollTop, client: thread.clientHeight };
29
29
  };
30
- const wasAtBottom = () => {
31
- const previous = app.state.listMetrics;
32
- return previous.height - previous.top - previous.client <= 80;
33
- };
34
30
  new ResizeObserver(() => {
35
- const thread = $("#thread"), growth = messageList.offsetHeight - app.state.listMetrics.height;
36
- // Judge the position before this growth: a reader who was at the bottom stays there,
37
- // a reader in history is left alone, and a viewport resize keeps following the anchor.
38
- if (growth > 0 && wasAtBottom()) thread.scrollTop = thread.scrollHeight;
31
+ const thread = $("#thread"), previous = app.state.listMetrics;
32
+ const grew = messageList.offsetHeight > previous.height, sameBox = thread.clientHeight === previous.client;
33
+ // Rows arrive in bursts, so judging each burst on its own loses the reader after the
34
+ // first one. Follow while the reader has not scrolled away: then every growth pins.
35
+ // A changed viewport height (composer, window) is not list growth and keeps its anchor.
36
+ const selection = getSelection(), selecting = Boolean(selection && !selection.isCollapsed && messageList.contains(selection.anchorNode));
37
+ // A pointer held over the list is mid-gesture: dragging a selection or a click that
38
+ // must land where it started. Moving the content under it loses both.
39
+ if (grew && sameBox && app.state.followBottom && !selecting && !app.state.threadPointerDown
40
+ && thread.scrollHeight - thread.scrollTop - thread.clientHeight > 1) {
41
+ thread.scrollTop = thread.scrollHeight;
42
+ }
39
43
  rememberListMetrics();
40
44
  }).observe(messageList);
41
45
  app.showRestoreFailure = (message) => {
@@ -95,6 +99,7 @@ export function initEvents(app) {
95
99
  // Entering a room always shows the newest messages. Restoring an old anchor
96
100
  // leaves the reader above messages that already arrived or grew afterwards.
97
101
  thread.scrollTop = thread.scrollHeight;
102
+ app.state.followBottom = true;
98
103
  captureReadingPosition();
99
104
  return { messageId: readingPosition?.messageId, atBottom: true };
100
105
  };
@@ -247,11 +252,24 @@ export function initEvents(app) {
247
252
  });
248
253
  thread.addEventListener("pointerdown", (event) => {
249
254
  if (event.clientX >= thread.getBoundingClientRect().right - 18) markScrollIntent();
255
+ app.state.threadPointerDown = true;
250
256
  });
257
+ const releasePointer = () => { app.state.threadPointerDown = false; };
258
+ window.addEventListener("pointerup", releasePointer);
259
+ window.addEventListener("pointercancel", releasePointer);
260
+ window.addEventListener("blur", releasePointer);
251
261
  thread.addEventListener("scroll", () => {
252
262
  const adjusting = (app.state.resizeScrollAdjusting || app.state.layoutScrollAdjusting)
253
263
  && performance.now() > app.state.userScrollIntentUntil;
254
- if (!adjusting) rememberListMetrics();
264
+ if (!adjusting) {
265
+ // The growth baseline belongs to the observer alone. A scroll caused by the growth
266
+ // itself arrives before the observer sees the new height, and refreshing the
267
+ // baseline here would make that growth look like no growth at all.
268
+ // Only a scroll the reader started ends following; layout shifts do not.
269
+ const gap = thread.scrollHeight - thread.scrollTop - thread.clientHeight;
270
+ if (gap <= 80) app.state.followBottom = true;
271
+ else if (performance.now() <= app.state.userScrollIntentUntil) app.state.followBottom = false;
272
+ }
255
273
  if (!adjusting || performance.now() <= app.state.userScrollIntentUntil) captureReadingPosition();
256
274
  if (!adjusting && thread.scrollHeight - thread.scrollTop - thread.clientHeight < 80) void app.markActiveRoomRead(performance.now() <= app.state.userScrollIntentUntil);
257
275
  app.queueReceiptRefresh();
@@ -98,6 +98,7 @@ export function initMessages(app) {
98
98
  };
99
99
  app.jumpToBottom = () => {
100
100
  app.state.readAnchorGuard = null;
101
+ app.state.followBottom = true;
101
102
  $("#thread").scrollTop = $("#thread").scrollHeight;
102
103
  const entry = app.state.room && app.state.rooms.get(app.state.room.id);
103
104
  app.state.unread = entry ? entry.unreadIds.size + (entry.unreadOverflow ? 100 : 0) : 0;
@@ -134,6 +134,8 @@ async function jumpToOriginal(roomId, messageId, app) {
134
134
  } catch { return; }
135
135
  if (!original) return markUnavailable(messageId, roomId, app);
136
136
  app.state.positions.set(roomId, { messageId, offset: 0, atBottom: false }); app.savePosition(roomId, { messageId, offset: 0, atBottom: false });
137
+ // Jumping to an older message is the reader choosing history.
138
+ app.state.followBottom = false;
137
139
  if (app.state.room?.id === roomId && app.state.navigationGeneration === generation) {
138
140
  app.state.room = app.state.rooms.get(roomId)?.room || room; app.rerenderMessages();
139
141
  const row = document.querySelector(`[data-msg-id="${CSS.escape(messageId)}"]`), thread = app.$("#thread");
@@ -11,7 +11,7 @@ export const app = {
11
11
  memberApiUnavailable: new Set(), receiptApiUnavailable: new Set(),
12
12
  receipts: new Map(), acknowledgedMessages: new Map(), pendingAcknowledgements: new Map(),
13
13
  pendingAction: null, watcherTimer: 0, restored: false, resizeScrollAdjusting: false, layoutScrollAdjusting: false,
14
- readAnchorGuard: null, userScrollIntentUntil: 0, listMetrics: { height: 0, top: 0, client: 0 },
14
+ readAnchorGuard: null, userScrollIntentUntil: 0, listMetrics: { height: 0, top: 0, client: 0 }, followBottom: true, threadPointerDown: false,
15
15
  },
16
16
  rendered: 0,
17
17
  firstMessageId: null,