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/3140-approve-all-error-list.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The **Approve all** line in a chat's approval dock now reports one entry per person: the same person failing twice is named once, and two people's failures are separated by a dot instead of running together, so a name is never read as the tail of the reason before it ([#3140](https://github.com/ThinkFlowLab/FlyBot/issues/3140)).
2 changes: 1 addition & 1 deletion docs/subsystems/social.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ At phone width (`<= 640 px`, the last block in `client.js's stylesheet`) this pa
| `plugins/social/src/face-rooms.js` | Face-to-face REST client (join/list/get/start/leave/messages, mint/revoke/preview/join invites, `parseInviteLink` / `parseFaceInviteLink`), error mapping, event rendering, peer-string sanitization. Auto-send is MCP in `social.js`. |
| `plugins/social/src/presence.js` | "Name is thinking…" for friends' Bots (#297): sends `set_presence` for my Bots' turns that answer a friend or run in an open face room (`turn.start` / `turn.end`, heartbeat), polls `list_presence` only while a social chat asks (`social/typing`), clears a line when that Bot's message arrives. Gated on the `presence` feature. |
| `plugins/social/src/face-title.js` | Face-to-face room titles (`Face-to-face · Alice, Bob · 482913`). Ships in the plugin so a packaged install can import (#153); core keeps its own copy for hosted rooms. |
| `plugins/social/client.js` | Settings → **Bot Social** (`SocialServerSettings`, slot `flybot.settings.page`): the server form, and once connected a **Friends** list plus one **People with access** link per local Bot (#1074). `PeerThinking` dock line (`social-thinking`, order 60: one `bt-shimmer` line `Name is thinking…`). Social strip: **N to approve** badge, Add friend / Face-to-face panels from +, Past rooms; sidebar + Face-to-face room / Add friend (own handle line, per-Bot **Copy invite link**); in-chat Approve / Reject dock, waiting `flybot.room.overview` tile grid (6-digit code and its QR, then Leave / Enter chat), open room **Invite by link** card (link QR, Copy link, Withdraw link); a local group's Members card **Invite by link** row (`LocalInviteRow`, slot `flybot.room.members`: Create link / New link, the link's QR, Copy link, m:ss countdown, Withdraw link, through the core `room-invite*` endpoints via `__flybot__.host`); the Face-to-face dialog's link field and scan also take a group link of another FlyBot (`/r/@handle/ticket`): `room-invite-preview` → the shared preview card (**Join group**) → `room-invite-ask` with the picked Bots, one sentence per refusal (#876); Bot settings Sharing (Copy invite link) / Share with a friend / People with access (inside the host's titled **Sharing** card, so `BotSocialDetails` draws no title of its own, #406), or Auto-send + Remove this Bot on a friend's Bot. |
| `plugins/social/client.js` | Settings → **Bot Social** (`SocialServerSettings`, slot `flybot.settings.page`): the server form, and once connected a **Friends** list plus one **People with access** link per local Bot (#1074). `PeerThinking` dock line (`social-thinking`, order 60: one `bt-shimmer` line `Name is thinking…`). Social strip: **N to approve** badge, Add friend / Face-to-face panels from +, Past rooms; sidebar + Face-to-face room / Add friend (own handle line, per-Bot **Copy invite link**); in-chat Approve / Reject dock (its **Approve all** reports one failure entry per person, `Eve: the hold is stale · Bob: …`, a repeated reason named once), waiting `flybot.room.overview` tile grid (6-digit code and its QR, then Leave / Enter chat), open room **Invite by link** card (link QR, Copy link, Withdraw link); a local group's Members card **Invite by link** row (`LocalInviteRow`, slot `flybot.room.members`: Create link / New link, the link's QR, Copy link, m:ss countdown, Withdraw link, through the core `room-invite*` endpoints via `__flybot__.host`); the Face-to-face dialog's link field and scan also take a group link of another FlyBot (`/r/@handle/ticket`): `room-invite-preview` → the shared preview card (**Join group**) → `room-invite-ask` with the picked Bots, one sentence per refusal (#876); Bot settings Sharing (Copy invite link) / Share with a friend / People with access (inside the host's titled **Sharing** card, so `BotSocialDetails` draws no title of its own, #406), or Auto-send + Remove this Bot on a friend's Bot. |

## Entry points

Expand Down
14 changes: 11 additions & 3 deletions plugins/social/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@
function qrRsGenerator(degree) {
let poly = [1]
for (let i = 0; i < degree; i += 1) {
const next = new Array(poly.length + 1).fill(0)

Check warning on line 715 in plugins/social/client.js

View workflow job for this annotation

GitHub Actions / plugins (social)

unicorn(no-new-array)

Do not use `new Array(singleArgument)`.
for (let j = 0; j < poly.length; j += 1) {
next[j] ^= poly[j]
next[j + 1] ^= qrMul(poly[j], QR_GF_EXP[i])
Expand All @@ -723,7 +723,7 @@
}
function qrRsRemainder(bytes, degree) {
const gen = qrRsGenerator(degree)
const res = new Array(bytes.length + degree).fill(0)

Check warning on line 726 in plugins/social/client.js

View workflow job for this annotation

GitHub Actions / plugins (social)

unicorn(no-new-array)

Do not use `new Array(singleArgument)`.
for (let i = 0; i < bytes.length; i += 1) res[i] = bytes[i]
for (let i = 0; i < bytes.length; i += 1) {
const factor = res[i]
Expand Down Expand Up @@ -797,8 +797,8 @@
}
function qrSkeleton(version) {
const size = version * 4 + 17
const modules = Array.from({ length: size }, () => new Array(size).fill(0))

Check warning on line 800 in plugins/social/client.js

View workflow job for this annotation

GitHub Actions / plugins (social)

unicorn(no-new-array)

Do not use `new Array(singleArgument)`.
const fixed = Array.from({ length: size }, () => new Array(size).fill(false))

Check warning on line 801 in plugins/social/client.js

View workflow job for this annotation

GitHub Actions / plugins (social)

unicorn(no-new-array)

Do not use `new Array(singleArgument)`.
const set = (x, y, dark) => { modules[y][x] = dark ? 1 : 0; fixed[y][x] = true }
const finder = (cx, cy) => {
for (let dy = -4; dy <= 4; dy += 1) {
Expand Down Expand Up @@ -1062,7 +1062,7 @@
return out
}
const cleanRoomName = (value, fallback = '') => stripUntrustedMarkers(value)
.replace(/[\u0000-\u001f\u007f-\u009f\u2028\u2029]/g, ' ')

Check warning on line 1065 in plugins/social/client.js

View workflow job for this annotation

GitHub Actions / plugins (social)

eslint(no-control-regex)

Unexpected control characters
.replace(/[[\]"<>`@]/g, '')
.replace(/\s+/g, ' ')
.trim()
Expand Down Expand Up @@ -2753,20 +2753,28 @@
// The click is the person acting, so this is where the previous line goes (#3071).
setError('')
const sent = []
const failed = []
// One entry per person, in the order the batch reached them, each reason named once: the same
// person failing twice is one entry, and two people are two entries separated by a dot, so a
// name never reads as the tail of the reason before it (#3093 follow-up).
const failed = new Map()
for (const item of mine.filter(waiting)) {
const outcome = await decide(item, 'approve')
if (outcome === true) sent.push(item)
else if (outcome?.error) {
const name = typeof item.toName === 'string' ? item.toName.trim() : ''
failed.push(name ? `${name}: ${outcome.error}` : outcome.error)
const reasons = failed.get(name) ?? []
if (!reasons.includes(outcome.error)) reasons.push(outcome.error)
failed.set(name, reasons)
}
}
const reached = recipientNames(sent)
if (reached.length) actions?.notify?.(tr('Sent to {to}', { to: reached.join(tr(', ')) }))
// #3071: written once, after the last send, so no send in the batch can clear it again; the
// receipt above still names only the people reached.
if (failed.length) setError(failed.join(' '))
if (failed.size) {
const entries = [...failed].map(([name, reasons]) => (name ? `${name}: ${reasons.join(', ')}` : reasons.join(', ')))
setError(entries.join(' · '))
}
}
// #3011: the button says what it will send and to whom, so the blast radius of a click that
// cannot be undone is readable before it.
Expand Down
44 changes: 42 additions & 2 deletions plugins/social/test/approve-all-failure.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ const localHold = (id, handle, name) => ({
})
const holds = () => [localHold('l1', '@eve.home', 'Eve'), localHold('l2', '@bob.home', 'Bob')]

function harness({ decide }) {
function harness({ decide, holdList = holds() }) {
const state = { calls: [], notes: [], decide }
globalThis.__flybot__ = {
call: (endpoint, payload) => {
state.calls.push([endpoint, payload])
if (endpoint === 'social/status') return Promise.resolve({ approvals: [] })
if (endpoint === 'approvals') return Promise.resolve(holds())
if (endpoint === 'approvals') return Promise.resolve(holdList)
if (endpoint === 'decide') {
const answer = state.decide(payload)
return answer instanceof Error ? Promise.reject(answer) : Promise.resolve(answer)
Expand Down Expand Up @@ -224,3 +224,43 @@ test('#3093: a local reject is a decision, not a failed send', async () => {
assert.deepEqual(state.notes, [], 'a rejected card is not receipted as sent')
} finally { delete globalThis.__flybot__ }
})

// The batch's own line, read where the person reads it: one alert under the button (#3071 keeps it out
// of the cards, whose own reason is #3093's record).
function errorLine(tree) {
const node = find(tree, byFlybot('chat-approval-error'))
return node ? drawn(node) : undefined
}

test('a batch that fails two holds for one person names that person once', async () => {
const app = loadDock()
// The same reason twice is one thing that happened, not two: a line that says it twice reads as a
// stutter, and the person cannot tell it from a second, different failure.
const state = harness({
holdList: [localHold('l1', '@eve.home', 'Eve'), localHold('l2', '@eve.home', 'Eve')],
decide: () => new Error('the hold is stale'),
})
try {
const first = await openChat(app, state)
await find(first.tree, byFlybot('approve-all')).props.onClick()
const after = render(app.ChatApprovalDock, first.inst, state.props)
assert.equal(errorLine(after), 'Eve: the hold is stale', `one entry per person and reason, saw ${JSON.stringify(errorLine(after))}`)
assert.equal(findAll(after, byFlybot('chat-approval')).length, 2, 'both cards are still there to read')
} finally { delete globalThis.__flybot__ }
})

test('a batch that fails two people separates their reasons and keeps each name', async () => {
const app = loadDock()
// Two different failures no longer run together as "Eve: the hold is stale Bob: …", where the second
// person's name looked like part of the first person's reason.
const state = harness({
holdList: [localHold('l1', '@eve.home', 'Eve'), localHold('l2', '@bob.home', 'Bob')],
decide: payload => new Error(payload.id === 'l1' ? 'the hold is stale' : 'Bot Social is unreachable'),
})
try {
const first = await openChat(app, state)
await find(first.tree, byFlybot('approve-all')).props.onClick()
const after = render(app.ChatApprovalDock, first.inst, state.props)
assert.equal(errorLine(after), 'Eve: the hold is stale · Bob: Bot Social is unreachable', `each failure is its own entry, saw ${JSON.stringify(errorLine(after))}`)
} finally { delete globalThis.__flybot__ }
})
Loading