Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/3114-fold-prefs.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Settings → General now has a **Message folding** choice — Compact, Standard or No folding — for how much of a long chat message shows before it folds, and the choice is saved for the whole team ([#3114](https://github.com/ThinkFlowLab/FlyBot/issues/3114)).
33 changes: 33 additions & 0 deletions core/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,12 @@ var ZH = {
About: "简介",
"Show less": "收起",
"Show more": "展开",
"Message folding": "消息折叠",
"Choose how much of a long message to show before it folds.": "选择长消息在对话里折叠前展示多少内容。",
Compact: "紧凑",
Standard: "标准",
"No folding": "不折叠",
"Message folding must be compact, standard or none": "消息折叠必须是紧凑、标准或不折叠",
"Showing {shown} of {count}": "显示 {shown} / {count}",
"Showing all {count}": "显示全部 {count}",
"Admin leads": "管理员主持",
Expand Down Expand Up @@ -20070,6 +20076,8 @@ var NOTIFY_KINDS = [
];
var SEND_KEY_LABELS = [["enter", "Enter to send"], ["shift-enter", "Shift+Enter to send"]];
var sendKeyLabel = (key) => SEND_KEY_LABELS.find(([id]) => id === key)?.[1] ?? SEND_KEY_LABELS[0][1];
var FOLD_MODE_LABELS = [["compact", "Compact"], ["standard", "Standard"], ["none", "No folding"]];
var foldModeLabel = (mode) => FOLD_MODE_LABELS.find(([id]) => id === mode)?.[1] ?? "Standard";
function PluginsView({ answer = null, error = "", onFlip }) {
const plugins = answer?.plugins ?? [];
const profile = typeof answer?.profile === "string" && answer.profile !== "" ? answer.profile : "<profile>";
Expand Down Expand Up @@ -20133,6 +20141,7 @@ function PluginsPage({ call: call4 }) {
}
function GeneralPage({ roster, actions, run }) {
const prefs = roster.prefs ?? {};
const folding = foldingOf(prefs);
const themes = allThemes();
const current = themes[prefs.theme] ? prefs.theme : "deepseek";
const [custom, setCustom] = (0, import_react45.useState)(prefs.accent ?? "#4d6bfe");
Expand Down Expand Up @@ -20161,6 +20170,11 @@ function GeneralPage({ roster, actions, run }) {
{ key: "shortcuts", title: t("Shortcuts") },
(0, import_react45.createElement)(SetRow, { label: t("Send shortcut"), hint: t(sendKeyLabel(sendKey)) })
),
(0, import_react45.createElement)(
SetSection,
{ key: "folding", title: t("Message folding") },
(0, import_react45.createElement)(SetRow, { label: t("Message folding"), hint: t(foldModeLabel(folding.mode)) })
),
(0, import_react45.createElement)(
SetSection,
{ key: "notify", title: t("Notifications") },
Expand Down Expand Up @@ -20224,6 +20238,25 @@ function GeneralPage({ roster, actions, run }) {
}, t(sendKeyLabel(id)))))
)
),
(0, import_react45.createElement)(
SetSection,
{ key: "folding", title: t("Message folding") },
(0, import_react45.createElement)(
SetRow,
{
label: t("Message folding"),
hint: t("Choose how much of a long message to show before it folds.")
},
(0, import_react45.createElement)(Segmented, { label: t("Message folding"), value: folding.mode, className: "bt-appearance-seg" }, FOLD_MODE_LABELS.map(([id, label]) => (0, import_react45.createElement)("button", {
key: id,
type: "button",
"aria-pressed": folding.mode === id,
onClick: () => {
if (folding.mode !== id) run(actions.setPrefs({ folding: { mode: id } }));
}
}, t(label))))
)
),
// One switch for every system notification (#353), then one per kind (#469).
(0, import_react45.createElement)(
SetSection,
Expand Down
6 changes: 6 additions & 0 deletions core/src/client/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,12 @@ const ZH = {
About: '简介',
'Show less': '收起',
'Show more': '展开',
'Message folding': '消息折叠',
'Choose how much of a long message to show before it folds.': '选择长消息在对话里折叠前展示多少内容。',
Compact: '紧凑',
Standard: '标准',
'No folding': '不折叠',
'Message folding must be compact, standard or none': '消息折叠必须是紧凑、标准或不折叠',
'Showing {shown} of {count}': '显示 {shown} / {count}',
'Showing all {count}': '显示全部 {count}',
'Admin leads': '管理员主持',
Expand Down
17 changes: 17 additions & 0 deletions core/src/client/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { FolderMenu } from './folder-menu.js'
import { AboutPage } from './about.js'
import { t } from './i18n.js'
import { readOnlyLine } from './read-only.js'
import { foldingOf } from './message-fold.js'

const capitalize = word => word[0].toUpperCase() + word.slice(1)

Expand Down Expand Up @@ -54,6 +55,10 @@ const NOTIFY_KINDS = [
// (composer.js writes localStorage), so the host stores no send-key field.
const SEND_KEY_LABELS = [['enter', 'Enter to send'], ['shift-enter', 'Shift+Enter to send']]
const sendKeyLabel = key => SEND_KEY_LABELS.find(([id]) => id === key)?.[1] ?? SEND_KEY_LABELS[0][1]
// How much of a long message shows before it folds (#3114). The host keeps the choice, so
// the row writes `set-prefs` and every window folds the same way.
const FOLD_MODE_LABELS = [['compact', 'Compact'], ['standard', 'Standard'], ['none', 'No folding']]
const foldModeLabel = mode => FOLD_MODE_LABELS.find(([id]) => id === mode)?.[1] ?? 'Standard'
// Settings → Plugins (#2564): the four feature plugins, each with one switch. The
// switch writes FlyBot's state.json; the packages stay installed and the next start
// reads the answer, so nothing unloads from the session that flipped it.
Expand Down Expand Up @@ -112,6 +117,7 @@ function PluginsPage({ call }) {
// General is Appearance and Notifications; the switch to classic Agent mode is the account menu's (#393).
function GeneralPage({ roster, actions, run }) {
const prefs = roster.prefs ?? {}
const folding = foldingOf(prefs)
const themes = allThemes()
const current = themes[prefs.theme] ? prefs.theme : 'deepseek'
const [custom, setCustom] = useState(prefs.accent ?? '#4d6bfe')
Expand All @@ -134,6 +140,8 @@ function GeneralPage({ roster, actions, run }) {
h(SetRow, { label: t('Accent'), hint: accent ? t(capitalize(accent)) : prefs.accent ?? t('Default') })),
h(SetSection, { key: 'shortcuts', title: t('Shortcuts') },
h(SetRow, { label: t('Send shortcut'), hint: t(sendKeyLabel(sendKey)) })),
h(SetSection, { key: 'folding', title: t('Message folding') },
h(SetRow, { label: t('Message folding'), hint: t(foldModeLabel(folding.mode)) })),
h(SetSection, { key: 'notify', title: t('Notifications') },
h(SetRow, { label: t('In other chats'), hint: prefs.notifications !== false ? t('On') : t('Off') }),
NOTIFY_KINDS.map(([kind, label]) => h(SetRow, { key: kind, label: t(label), hint: prefs.notifications !== false && prefs.notify?.[kind] !== false ? t('On') : t('Off') }))),
Expand Down Expand Up @@ -162,6 +170,15 @@ function GeneralPage({ roster, actions, run }) {
key: id, type: 'button', 'aria-pressed': sendKey === id,
onClick: () => chooseSendKey(id),
}, t(sendKeyLabel(id))))))),
h(SetSection, { key: 'folding', title: t('Message folding') },
h(SetRow, {
label: t('Message folding'),
hint: t('Choose how much of a long message to show before it folds.'),
},
h(Segmented, { label: t('Message folding'), value: folding.mode, className: 'bt-appearance-seg' }, FOLD_MODE_LABELS.map(([id, label]) => h('button', {
key: id, type: 'button', 'aria-pressed': folding.mode === id,
onClick: () => { if (folding.mode !== id) run(actions.setPrefs({ folding: { mode: id } })) },
}, t(label)))))),
// One switch for every system notification (#353), then one per kind (#469).
h(SetSection, { key: 'notify', title: t('Notifications') },
h(SwitchRow, {
Expand Down
12 changes: 12 additions & 0 deletions core/src/host/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import { visibleText } from '../shared/preview.js'
import { excerpt } from './text.js'

const NOTIFY_KINDS = ['approval', 'finished', 'failed']
// How much of a long message a bubble shows before it folds (#3114); the client reads the
// mode back through `foldingOf`, which treats anything else as the default.
const FOLD_MODES = new Set(['compact', 'standard', 'none'])
const LANGUAGES = { zh: 'Chinese (简体中文)', en: 'English' }
// How long a burst of the user's lines is collected before it opens one turn (#642).
const SETTLE_MS = 1_500
Expand Down Expand Up @@ -310,6 +313,15 @@ export function install(rt) {
if (budget === undefined) delete state.prefs.turnBudget
else state.prefs.turnBudget = budget
}
// Message folding (#3114): a team-wide mode in `{ mode }`; `null` clears it back to the
// default, and a mode no bubble can draw is refused instead of stored.
if (body.folding !== undefined) {
const raw = body.folding
const mode = raw?.mode ?? state.prefs.folding?.mode ?? 'standard'
if (raw === null) delete state.prefs.folding
else if (typeof raw === 'object' && !Array.isArray(raw) && FOLD_MODES.has(mode)) state.prefs.folding = { mode }
else throw invalid('Message folding must be compact, standard or none')
}
return rt.save()
}

Expand Down
17 changes: 17 additions & 0 deletions core/test/install.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,23 @@ const TEAM = {
questions: {},
}

// The message folding mode (#3114) is a team preference: one window writes it, and every window
// reads it back through the roster, where `foldingOf` decides how much of a long message shows.
// `null` clears it to the default, and a mode no bubble can draw is refused rather than stored.
test('set-prefs stores the message folding mode and refuses any other one (#3114)', async (t) => {
const { call, stop } = start(TEAM)
t.after(stop)
assert.deepEqual((await call('set-prefs', { folding: { mode: 'compact' } })).value.folding, { mode: 'compact' })
assert.deepEqual((await call('state')).value.prefs.folding, { mode: 'compact' })
for (const folding of [{ mode: 'wild' }, ['compact'], 'compact']) {
assert.deepEqual((await call('set-prefs', { folding })).error, { code: 'bot/invalid', message: 'Message folding must be compact, standard or none', details: {} })
}
assert.deepEqual((await call('state')).value.prefs.folding, { mode: 'compact' }, 'a refusal stores nothing')
assert.deepEqual((await call('set-prefs', { folding: { mode: 'standard' } })).value.folding, { mode: 'standard' })
assert.equal('folding' in (await call('set-prefs', { folding: null })).value, false)
assert.equal((await call('set-prefs', { folding: { mode: 'none' } })).value.folding.mode, 'none')
})

test('in the Desktop profile read_browser is the last tool and reads through the window', async (t) => {
const { ctx, call, stop } = start(TEAM, { services: { profileContext: { name: 'desktop' } } })
t.after(stop)
Expand Down
26 changes: 23 additions & 3 deletions core/test/settings-readonly-pages.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ const expand = (node, out = [], depth = 0, deep = false) => {
return out
}

const mount = (roster, key, id, name, calls = []) => {
const actions = makeActions(calls)
const mount = (roster, key, id, name, calls = [], override = undefined) => {
const actions = override ?? makeActions(calls)
slots = []
effects = []
index = 0
Expand Down Expand Up @@ -261,7 +261,7 @@ test('a writable window keeps every page as it is today (#2474)', () => {
const general = mount(baseRoster, 'general', null, 'GeneralPage').nodes
assert.equal(general.filter(node => node.type === 'select').length, 1, 'General keeps its theme select')
assert.equal(general.filter(node => node.type === 'input').length, 1, 'General keeps its colour field')
assert.equal(counts(general), 7, 'General keeps its four switches beside the send-key picker')
assert.equal(counts(general), 8, 'General keeps its four switches beside the send-key and folding pickers')
assert.equal(general.filter(node => node.type === Segmented && node.props?.label === 'Send shortcut').length, 1, 'General draws the send-key picker')

const bots = mount(baseRoster, 'bots', null, 'BotsPage').nodes
Expand All @@ -275,6 +275,26 @@ test('a writable window keeps every page as it is today (#2474)', () => {
assert.ok(mount(baseRoster, 'secrets', null, 'SecretsPage').nodes.some(node => nameOf(node) === 'SecretRow'), 'Secrets keeps its rows')
})

// General → Message folding (#3114): the picker writes the mode through `set-prefs`, so the
// host stores one team-wide choice and every window folds by it. The locked page keeps the
// mode in use as text, like every other page here.
test('Settings → General picks the message folding mode and writes it through set-prefs (#3114)', () => {
const roster = { ...baseRoster, prefs: { ...baseRoster.prefs, folding: { mode: 'compact' } } }
const written = []
const { nodes } = mount(roster, 'general', null, 'GeneralPage', [], { setPrefs: payload => { written.push(payload); return Promise.resolve(payload) } })
const pickers = nodes.filter(node => node.type === Segmented && node.props?.label === 'Message folding')
assert.equal(pickers.length, 1, 'General draws the folding picker')
const buttons = all(pickers[0]).filter(node => nameOf(node) === 'button')
assert.deepEqual(buttons.map(text), ['Compact', 'Standard', 'No folding'])
assert.deepEqual(buttons.map(button => button.props['aria-pressed']), [true, false, false], 'the stored mode is the one in use')
buttons[1].props.onClick()
// The page runs inside a vm realm, so its own object is compared by value, not by prototype.
assert.deepEqual(JSON.parse(JSON.stringify(written)), [{ folding: { mode: 'standard' } }], 'Standard asks the host to store standard')
const locked = mount({ ...roster, readOnly: SENTENCE }, 'general', null, 'GeneralPage').nodes
assert.equal(locked.filter(node => node.type === Segmented && node.props?.label === 'Message folding').length, 0, 'a locked page draws no folding picker')
assert.ok(text(locked).includes('Compact'), 'and keeps the mode in use as text')
})

// The window can be unlocked under a page that is already on screen: the other window holding
// the team closes, the host's read-only sentence goes away, and settings.js keeps the same
// dialog instance (its key is the page and the id, not the lock). A page whose locked view
Expand Down
2 changes: 1 addition & 1 deletion docs/subsystems/core-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The browser side of the patched `ds-bot` core (`core/`): sources in `core/src/cl
- A Settings dialog takes focus when it opens (`useDialogFocus` in `core/src/client/overlay-hooks.js`; the `.bt-settings` dialog carries `tabIndex -1` and a ref) and gives it back to the still-connected opener when it closes; it is not a focus trap, so Tab can still leave the dialog for the page behind the scrim (#2251). It is drawn for `DIALOG_EXIT_MS` (160 ms) with `pointer-events: none` on the leaving layer, so the unmount restores focus only while the dialog still holds it (or nothing does) — a click on the page during that window keeps its focus (#2270).
- Settings → Feedback's error list (`feedback.js`) still titles the block with the whole log (`Recent errors · 60`) but lists only the newest eight, so when the report holds more rows one `Show more` control (`aria-expanded`) sits under them beside a count of what is drawn against the whole log the title counts (`Showing 8 of 60` while folded, `Showing 50 of 60` open, and `Showing all 50` only when the payload holds the whole log), and draws every loaded error, folding back to `Show less`; a report of eight or fewer draws neither (#2266, #2884, #2932).
- An error toast keeps the host's code: `reportError` in `index.js` puts `error.code` into the toast payload and `feedback.js` draws it as a `bt-tag bt-toast-code`, so a reader can tell `bot/read-only` from any other refusal. That code is also the one action a toast can take: a `bot/read-only` toast offers **Reload** (`bt-toast-reload`) in place, which dismisses the toast and runs the client's own full-state read (`actions.reloadTeam`), so the window becomes writable once the other holder let go without a page reload that would drop the composer; a failed read goes to `actions.reportError(error, 'reload')` the way the sidebar's Reload does. Every other code, and a toast with no code, draws the sentence and **Details** exactly as before (P-502). That sentence is never blank: `api.js` answers a host refusal that carries no message of its own with `Request failed` (`result.error?.message || 'Request failed'` on the thrown error and on the noted copy alike), so a surface that prints `error.message` shows a refusal rather than nothing, and a memory row whose count sentence tests the failure for truth settles on it instead of `Loading…` (#2411). Tests: `core/test/api-empty-message.test.js`.
- A long chat message folds to a whole-line preview at the standard cap (12 lines, or 800 characters, whichever comes first) with one **Show more** control inside the bubble that opens the whole reply and becomes **Show less** (`message-fold.js` `FoldedContent`, drawn by `cells.js` for a Bot reply and by `user-message.js` for my own line; `foldingOf(roster.prefs)` reads the mode — standard by default, `none` folding nothing). A reply still streaming, and one at or under the cap, are never folded, and the preview never leaves a code block open. The document card and the Settings preference are a later slice. Tests: `core/test/message-fold.test.js`. The draw reaches the bubble as the `draw` property, not as children: a cell component is expanded from its props alone (`core/test/tool-cells.test.js`).
- A long chat message folds to a whole-line preview at the standard cap (12 lines, or 800 characters, whichever comes first) with one **Show more** control inside the bubble that opens the whole reply and becomes **Show less** (`message-fold.js` `FoldedContent`, drawn by `cells.js` for a Bot reply and by `user-message.js` for my own line; `foldingOf(roster.prefs)` reads the mode — standard by default, `none` folding nothing). A reply still streaming, and one at or under the cap, are never folded, and the preview never leaves a code block open. The mode is chosen in Settings → General (`Message folding`, written through `set-prefs`); the document card is a later slice. Tests: `core/test/message-fold.test.js`. The draw reaches the bubble as the `draw` property, not as children: a cell component is expanded from its props alone (`core/test/tool-cells.test.js`).
- A link picked in a chat message opens in FlyBot's own panel: a capture-phase click handler on each bubble and on the person's own line (`bubbleLinkClick` in `cells.js`; a group card's container carries none, so a reply's link opens the tab of the Bot that spoke) takes an `http(s)` anchor before the host's delegate does, puts a tab in the panel's browser view (the globe button's view) with `actions.browserNewTab` and carries the URL with `actions.browserNavigate`; `browserNewTab` answers `null` for a Bot outside the roster, and with no tab — or no Desktop bridge — the page opens in the window itself. A mention, a file link and a modified or middle click are left alone, and the bubble renders bare `MarkdownText` so the host's `openFile`/`fileImages` reach it: a nested `MarkdownDelegateProvider` replaces the host's capabilities, and one that lacked `fileImages` drew every bubble image as its alt text (#2319). Left to the host a click opened a tab in the host's right sidebar, which this panel's fixed layer covers, so the content area looked blank (#2201). Tests: `core/test/chat-link-open.test.js`.

## Does not own
Expand Down
Loading
Loading