Skip to content

Commit 347decd

Browse files
authored
History search rows: land on the hit, say what the cap hid (#3114) (#3187)
Written-by: Dev Fixes #3186 Part of #3114 Owner: Dev Reviewer: Reviewer Tier: T1 ## Checkpoint <!-- flybot:checkpoint --> { "pr": 3187, "claim": "Dev", "issue": 3186, "summary": "History search rows now say what they are and land where they point. An outline message row opens the chat at its own turn, two hits in one turn are two rows, and a hit the current part does not hold is marked Earlier part and opens the chat without a turn. A capped whole-text answer says how many matches the host left out and asks for one more word, and a Bot whose current part is a Session of its own no longer shows the same message twice.", "files": [ "core/src/client/palette.js", "core/src/client/index.js", "core/src/client/i18n.js", "core/src/client/styles.js", "core/test/palette-preview.test.js", "docs/subsystems/core-client.md" ], "checks": { "ran": "npm run verify (exit 0); palette-preview 22/22; regression 51/51; ds-bot-patches check + canonical; arch-docs; changelog check", "result": "green", "at": "f7179a2581350f02d28e71ef823c9139afbd0618" }, "next": "none — ready for review (T1: green tests-ok at the tip is the gate, no PASS)" } <!-- /flybot:checkpoint --> ## Verification at the tip Ran at `f7179a2581350f02d28e71ef823c9139afbd0618` (client and host suites with `DSH_HARNESS=/opt/flybot`, `TZ=UTC`, `TMPDIR=/data/flybot-tmp`): - `npm --prefix core run build && node core/scripts/build-client.mjs --check` → OK, and the branch tree equals the tree built here. - `node --import ./test/harness-resolve.mjs --test test/palette-preview.test.js` → `# tests 22 / # pass 22 / # fail 0`. - Red first, both stages recorded: the 22 cases with the implementation untouched → `# pass 5 / # fail 17`; with the behaviour-neutral contract migration (`{hits, turns}` + the short-query branch + `{rows, more}` in `searchChats`) → `# pass 17 / # fail 5`, the five reds being B1–B5. Then 22/22. - Regression: `client-bundle`, `chat-index-writers`, `earlier-message-actions`, `at-menu`, `empty-message-cell`, `i18n`, `i18n-missing-entries` → 51/51 (2/9/6/11/3/20). - `node scripts/ds-bot-patches.mjs check` → `ds-bot/ = Fei2411/DeepSeek-Bot@2b10c70`, `10 patches apply cleanly in order`, `core/ equals ds-bot/ + patches/ds-bot/`; `canonical` → "generate is a no-op". - `npm --prefix core run arch-docs` → `arch-docs: OK (12 changed file(s))`. - `node .github/scripts/changelog.mjs check` → 6 fragments well formed. - `node .github/scripts/check-mojibake.mjs --check` → ok, 0 occurrences of U+FFFD. - `TZ=UTC TMPDIR=/data/flybot-tmp npm run verify` → exit 0 (686 + 538 + 172 + 151 + 37 + 34 and the rest, `# fail 0` in every suite). Not run: - The smoke test (`core/dev/bench.sh`) — no test bench was started here. No host file is touched by this change, so nothing on the host side moved. - No PASS: this is a T1 client-only change; nothing is enqueued from this pull request. - Boundaries this change does not cover (they are the spec's §11): a hit in an older part is marked only and opens the current part at its newest view, since jumping to that part needs a host `part` field (T3, left to the owner); `turns[chat]` has a value only while the current part's outline is loaded, and until then the row behaves exactly as before; a hidden exchange turn keeps its turn because its position is in the flow, though its reply text is not drawn; `more` is the host's `total − shown` and can count rows this client does not hold; a `more > 0` answer whose every row is deduped draws no group and so no note; and the same part's same turn is still one message, because telling its hits apart needs `seq` on the row (host side). ## Keyword scan (§7) ``` git diff -U0 origin/main...HEAD | grep '^+' | grep -v '^+++' | grep -nE 'child_process|process\.env\.[A-Za-z_]*(TOKEN|KEY|SECRET)|DSH_HOME|\.(only|skip)\(|(eslint|oxlint)-disable|eval\(|new Function\(|untrusted-(message|file)' ``` → empty output: no new line carries a gate keyword, a skipped test, or a marker word. The full §7 expression (with its URL allow-list) also printed nothing. Files are the spec's 12: 7 handwritten (`palette.js`, `index.js`, `i18n.js`, `styles.js`, the palette test, `docs/subsystems/core-client.md`, the changelog fragment) and 5 generated (`core/client.js`, three patches, the `files/` mirror), `+135/−22` handwritten.
1 parent e5e0311 commit 347decd

12 files changed

Lines changed: 3158 additions & 2080 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
History search in the command palette now lands on what each row names: a message row opens the chat at its own turn, two hits in one turn are two rows, and a hit the current part does not hold is marked `Earlier part` instead of trying to scroll somewhere it cannot reach. When the 20-row cap hides more matches the group says how many and asks for one more word, and a Bot whose current part is a Session of its own no longer lists the same message twice ([#3114](https://github.com/ThinkFlowLab/FlyBot/issues/3114)).

‎core/client.js‎

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,8 @@ var ZH = {
914914
Results: "结果",
915915
"No results": "没有结果",
916916
"Try a Bot name or words from a message": "试试 Bot 名字或消息里的词",
917+
"Earlier part": "更早的 part",
918+
"{count} more matches · add a word to narrow it": "还有 {count} 条 · 加一个词缩小范围",
917919
// Bot exchange
918920
"Bot exchange": "Bot 间对话",
919921
"Bot exchange transcript": "Bot 间对话记录",
@@ -5813,6 +5815,7 @@ button:hover .bt-you{background:color-mix(in srgb,var(--bt-ink) 9%,var(--bt-side
58135815
:is(.bt-palette-row,.bt-palette-section,.bt-drop-list>.bt-option){position:relative;z-index:1}
58145816
.bt-palette-section{padding:8px 8px 4px;font-size:12px;line-height:16px;color:var(--bt-ink-3);flex:none}
58155817
.bt-palette-section:first-of-type{padding-top:0}
5818+
.bt-palette-note{padding:2px 8px 8px;font-size:12px;line-height:16px;color:var(--bt-ink-3);flex:none}
58165819
.bt-palette-row{flex:none;display:flex;align-items:center;gap:8px;height:49px;padding:6px 10px 6px 8px;border:0;border-radius:8px;background:none;color:inherit;font:inherit;text-align:left;cursor:pointer;box-sizing:border-box;width:100%}
58175820
.bt-palette-row[aria-selected=true]{background:var(--bt-active)}
58185821
.bt-palette-lead{flex:none;width:24px;height:24px;display:inline-flex;align-items:center;justify-content:center}
@@ -16553,16 +16556,19 @@ function CommandPalette({ start, token, roster, actions, useSessions }) {
1655316556
useEscape(close);
1655416557
const ids = [...roster.bots.map(currentPart), ...roster.rooms.map((item) => item.id)];
1655516558
const names = botNames(roster);
16559+
const chatOf2 = (id) => roster.byId[id]?.id ?? id;
1655616560
const found = useSessions((list) => {
16557-
if (wanted.length < 2) return "[]";
16561+
if (wanted.length < 2) return '{"hits":[],"turns":{}}';
1655816562
const hits = [];
16563+
const turns = {};
1655916564
for (const id of ids) {
1656016565
const outline = list.projectionsBySession?.[id]?.values?.turnOutline ?? list.byId[id]?.projectionValues?.turnOutline;
1656116566
if (!Array.isArray(outline)) continue;
16562-
const hidden = roster.exchangeTurns[id] ?? [];
16567+
turns[chatOf2(id)] ??= outline.map((entry) => entry.turn);
16568+
const hidden2 = roster.exchangeTurns[id] ?? [];
1656316569
for (let index2 = outline.length - 1; index2 >= 0 && hits.length < 30; index2 -= 1) {
1656416570
const entry = outline[index2];
16565-
if (hidden.includes(entry.turn)) continue;
16571+
if (hidden2.includes(entry.turn)) continue;
1656616572
for (const raw of [entry.response, entry.prompt]) {
1656716573
const text2 = paletteText(raw, names);
1656816574
const at = text2.toLowerCase().indexOf(wanted);
@@ -16573,7 +16579,7 @@ function CommandPalette({ start, token, roster, actions, useSessions }) {
1657316579
}
1657416580
}
1657516581
}
16576-
return JSON.stringify(hits);
16582+
return JSON.stringify({ hits, turns });
1657716583
});
1657816584
const searchChats = actions.searchChats;
1657916585
(0, import_react35.useEffect)(() => {
@@ -16585,8 +16591,8 @@ function CommandPalette({ start, token, roster, actions, useSessions }) {
1658516591
const controller = new AbortController();
1658616592
const timer = setTimeout(() => {
1658716593
void searchChats(wanted, controller.signal).then(
16588-
(rows2) => {
16589-
if (current) setWholeText(Array.isArray(rows2) ? rows2 : []);
16594+
(value) => {
16595+
if (current) setWholeText({ rows: value?.rows ?? [], more: value?.more ?? 0 });
1659016596
},
1659116597
() => {
1659216598
}
@@ -16633,31 +16639,44 @@ function CommandPalette({ start, token, roster, actions, useSessions }) {
1663316639
run: () => actions.openAgent(agent.id)
1663416640
}));
1663516641
if (agents.length) sections.push(["DSH Agent", agents]);
16636-
const messages = JSON.parse(found).map(([id, turn, snippet]) => {
16642+
const outlineRead = JSON.parse(found);
16643+
const messages = outlineRead.hits.map(([id, turn, snippet]) => {
1663716644
const bot = roster.byId[id];
1663816645
const room2 = roster.roomsById[id];
1663916646
return {
16640-
key: `${id}:${turn}`,
16647+
key: `${chatOf2(id)}:${turn}`,
1664116648
title: bot?.name ?? room2?.name ?? t("Bot"),
1664216649
subtitle: snippet,
1664316650
avatar: bot ? (0, import_react35.createElement)(BotAvatar, { bot, size: 24, badge: false, live: false }) : (0, import_react35.createElement)(RoomAvatar, { room: room2, roster, size: 24 }),
16644-
run: () => actions.openSession(id)
16651+
run: () => actions.openSession(id, { turn })
1664516652
};
1664616653
});
1664716654
if (messages.length) sections.push([t("Messages"), messages]);
1664816655
const outlined = new Set(messages.map((row) => row.key));
16649-
const fullText = (wholeText ?? []).filter((row) => row?.chat !== void 0 && (roster.byId[row.chat] || roster.roomsById[row.chat]) && !outlined.has(`${row.chat}:${row.turn}`)).map((row) => {
16656+
const inPart = (chat, turn) => {
16657+
const held = outlineRead.turns?.[chat];
16658+
return Array.isArray(held) && held.length > 0 ? held.includes(turn) : void 0;
16659+
};
16660+
const keyCounts = /* @__PURE__ */ new Map();
16661+
const fullText = (wholeText?.rows ?? []).filter((row) => row?.chat !== void 0 && (roster.byId[row.chat] || roster.roomsById[row.chat]) && !outlined.has(`${row.chat}:${row.turn}`)).map((row) => {
1665016662
const bot = roster.byId[row.chat];
1665116663
const room2 = roster.roomsById[row.chat];
16664+
const here = inPart(row.chat, row.turn);
16665+
const at = `${row.chat}:${row.turn}`;
16666+
const count = (keyCounts.get(at) ?? 0) + 1;
16667+
keyCounts.set(at, count);
1665216668
return {
16653-
key: `${row.chat}:${row.turn}`,
16669+
key: count > 1 ? `${at}:${count}` : at,
1665416670
title: bot?.name ?? room2?.name ?? t("Bot"),
1665516671
subtitle: row.text,
1665616672
avatar: bot ? (0, import_react35.createElement)(BotAvatar, { bot, size: 24, badge: false, live: false }) : (0, import_react35.createElement)(RoomAvatar, { room: room2, roster, size: 24 }),
16657-
run: () => actions.openSession(row.chat, { turn: row.turn })
16673+
badge: here === false ? t("Earlier part") : void 0,
16674+
run: here === false ? () => actions.openSession(row.chat) : () => actions.openSession(row.chat, { turn: row.turn })
1665816675
};
1665916676
});
16660-
if (fullText.length) sections.push([t("Messages (full text)"), fullText]);
16677+
const hidden = wholeText?.more ?? 0;
16678+
const note = hidden > 0 ? t("{count} more matches · add a word to narrow it", { count: hidden }) : null;
16679+
if (fullText.length) sections.push([t("Messages (full text)"), fullText, note]);
1666116680
const commands = [
1666216681
{ key: "cmd:new", icon: (0, import_react35.createElement)(PlusIcon), title: t("New chat"), run: () => actions.openNewChat("new") },
1666316682
{ key: "cmd:bot", icon: (0, import_react35.createElement)(PlusIcon), title: t("Create Bot"), run: () => actions.openNewChat("create") },
@@ -16733,7 +16752,7 @@ ${shown}`, { axis: "y", ...QUICK_EDGES });
1673316752
(0, import_react35.createElement)("span", { className: "bt-palette-empty-icon", "aria-hidden": true }, (0, import_react35.createElement)(SearchIcon)),
1673416753
(0, import_react35.createElement)("span", { className: "bt-palette-empty-label" }, t("No results")),
1673516754
(0, import_react35.createElement)("span", { className: "bt-palette-empty-hint" }, t("Try a Bot name or words from a message"))
16736-
) : sections.map(([title, items]) => (0, import_react35.createElement)(
16755+
) : sections.map(([title, items, note2]) => (0, import_react35.createElement)(
1673716756
import_react35.Fragment,
1673816757
{ key: title },
1673916758
(0, import_react35.createElement)("div", { className: "bt-palette-section", role: "presentation", "data-flip": `section:${title}` }, title),
@@ -16763,7 +16782,8 @@ ${shown}`, { axis: "y", ...QUICK_EDGES });
1676316782
),
1676416783
row.badge ? (0, import_react35.createElement)("span", { className: "bt-palette-badge" }, row.badge) : null
1676516784
);
16766-
})
16785+
}),
16786+
note2 ? (0, import_react35.createElement)("div", { className: "bt-palette-note", role: "status" }, note2) : null
1676716787
))
1676816788
)
1676916789
)
@@ -24014,7 +24034,7 @@ function apply(ctx) {
2401424034
},
2401524035
// The palette's whole-text message search (P-820): the host answers with the
2401624036
// caller's own chats, whole lines with the turn they belong to.
24017-
searchChats: (query, signal) => call("chats.search", { query }, signal).then((value) => value?.rows ?? []),
24037+
searchChats: (query, signal) => call("chats.search", { query }, signal).then((value) => ({ rows: value?.rows ?? [], more: value?.more ?? 0 })),
2401824038
// The conversation replacements withdraw for a plain Session; set the surface
2401924039
// before the navigation so the Bot skin never flashes.
2402024040
openAgentSession: (sessionId) => {

‎core/src/client/i18n.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,8 @@ const ZH = {
858858
Results: '结果',
859859
'No results': '没有结果',
860860
'Try a Bot name or words from a message': '试试 Bot 名字或消息里的词',
861+
'Earlier part': '更早的 part',
862+
'{count} more matches · add a word to narrow it': '还有 {count} 条 · 加一个词缩小范围',
861863

862864
// Bot exchange
863865
'Bot exchange': 'Bot 间对话',

‎core/src/client/index.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ export function apply(ctx) {
446446
},
447447
// The palette's whole-text message search (P-820): the host answers with the
448448
// caller's own chats, whole lines with the turn they belong to.
449-
searchChats: (query, signal) => call('chats.search', { query }, signal).then(value => value?.rows ?? []),
449+
searchChats: (query, signal) => call('chats.search', { query }, signal).then(value => ({ rows: value?.rows ?? [], more: value?.more ?? 0 })),
450450
// The conversation replacements withdraw for a plain Session; set the surface
451451
// before the navigation so the Bot skin never flashes.
452452
openAgentSession: (sessionId) => {

‎core/src/client/palette.js‎

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,15 @@ export function CommandPalette({ start, token, roster, actions, useSessions }) {
3333
useEscape(close)
3434
const ids = [...roster.bots.map(currentPart), ...roster.rooms.map(item => item.id)]
3535
const names = botNames(roster)
36+
const chatOf = (id) => roster.byId[id]?.id ?? id
3637
const found = useSessions((list) => {
37-
if (wanted.length < 2) return '[]'
38+
if (wanted.length < 2) return '{"hits":[],"turns":{}}'
3839
const hits = []
40+
const turns = {}
3941
for (const id of ids) {
4042
const outline = list.projectionsBySession?.[id]?.values?.turnOutline ?? list.byId[id]?.projectionValues?.turnOutline
4143
if (!Array.isArray(outline)) continue
44+
turns[chatOf(id)] ??= outline.map(entry => entry.turn)
4245
const hidden = roster.exchangeTurns[id] ?? []
4346
for (let index = outline.length - 1; index >= 0 && hits.length < 30; index -= 1) {
4447
const entry = outline[index]
@@ -53,7 +56,7 @@ export function CommandPalette({ start, token, roster, actions, useSessions }) {
5356
}
5457
}
5558
}
56-
return JSON.stringify(hits)
59+
return JSON.stringify({ hits, turns })
5760
})
5861
// The outline previews stop at 50/120 characters, so any hit past that budget is
5962
// invisible to the read above (P-820). The host searches the whole text over the
@@ -69,7 +72,7 @@ export function CommandPalette({ start, token, roster, actions, useSessions }) {
6972
const controller = new AbortController()
7073
const timer = setTimeout(() => {
7174
void searchChats(wanted, controller.signal).then(
72-
rows => { if (current) setWholeText(Array.isArray(rows) ? rows : []) },
75+
value => { if (current) setWholeText({ rows: value?.rows ?? [], more: value?.more ?? 0 }) },
7376
() => {},
7477
)
7578
}, SEARCH_DEBOUNCE_MS)
@@ -96,30 +99,45 @@ export function CommandPalette({ start, token, roster, actions, useSessions }) {
9699
run: () => actions.openAgent(agent.id),
97100
}))
98101
if (agents.length) sections.push(['DSH Agent', agents])
99-
const messages = JSON.parse(found).map(([id, turn, snippet]) => {
102+
const outlineRead = JSON.parse(found)
103+
const messages = outlineRead.hits.map(([id, turn, snippet]) => {
100104
const bot = roster.byId[id]
101105
const room = roster.roomsById[id]
102106
return {
103-
key: `${id}:${turn}`, title: bot?.name ?? room?.name ?? t('Bot'), subtitle: snippet,
107+
key: `${chatOf(id)}:${turn}`, title: bot?.name ?? room?.name ?? t('Bot'), subtitle: snippet,
104108
avatar: bot ? h(BotAvatar, { bot, size: 24, badge: false, live: false }) : h(RoomAvatar, { room, roster, size: 24 }),
105-
run: () => actions.openSession(id),
109+
run: () => actions.openSession(id, { turn }),
106110
}
107111
})
108112
if (messages.length) sections.push([t('Messages'), messages])
109113
// The host's whole-text rows, newest first (P-820). A row the outline already found for
110114
// the same chat and turn is the same message, so it is not shown twice; a row whose chat
111115
// the roster does not hold is not the caller's to open.
112116
const outlined = new Set(messages.map(row => row.key))
113-
const fullText = (wholeText ?? []).filter(row => row?.chat !== undefined && (roster.byId[row.chat] || roster.roomsById[row.chat]) && !outlined.has(`${row.chat}:${row.turn}`)).map(row => {
117+
// The current part's own turn numbers are the only proof the client has of what it holds; a
118+
// chat whose outline has not loaded proves nothing, and is left unmarked.
119+
const inPart = (chat, turn) => {
120+
const held = outlineRead.turns?.[chat]
121+
return Array.isArray(held) && held.length > 0 ? held.includes(turn) : undefined
122+
}
123+
const keyCounts = new Map()
124+
const fullText = (wholeText?.rows ?? []).filter(row => row?.chat !== undefined && (roster.byId[row.chat] || roster.roomsById[row.chat]) && !outlined.has(`${row.chat}:${row.turn}`)).map(row => {
114125
const bot = roster.byId[row.chat]
115126
const room = roster.roomsById[row.chat]
127+
const here = inPart(row.chat, row.turn)
128+
const at = `${row.chat}:${row.turn}`
129+
const count = (keyCounts.get(at) ?? 0) + 1
130+
keyCounts.set(at, count)
116131
return {
117-
key: `${row.chat}:${row.turn}`, title: bot?.name ?? room?.name ?? t('Bot'), subtitle: row.text,
132+
key: count > 1 ? `${at}:${count}` : at, title: bot?.name ?? room?.name ?? t('Bot'), subtitle: row.text,
118133
avatar: bot ? h(BotAvatar, { bot, size: 24, badge: false, live: false }) : h(RoomAvatar, { room, roster, size: 24 }),
119-
run: () => actions.openSession(row.chat, { turn: row.turn }),
134+
badge: here === false ? t('Earlier part') : undefined,
135+
run: here === false ? () => actions.openSession(row.chat) : () => actions.openSession(row.chat, { turn: row.turn }),
120136
}
121137
})
122-
if (fullText.length) sections.push([t('Messages (full text)'), fullText])
138+
const hidden = wholeText?.more ?? 0
139+
const note = hidden > 0 ? t('{count} more matches · add a word to narrow it', { count: hidden }) : null
140+
if (fullText.length) sections.push([t('Messages (full text)'), fullText, note])
123141
const commands = [
124142
{ key: 'cmd:new', icon: h(PlusIcon), title: t('New chat'), run: () => actions.openNewChat('new') },
125143
{ key: 'cmd:bot', icon: h(PlusIcon), title: t('Create Bot'), run: () => actions.openNewChat('create') },
@@ -166,7 +184,7 @@ export function CommandPalette({ start, token, roster, actions, useSessions }) {
166184
h('span', { className: 'bt-palette-empty-icon', 'aria-hidden': true }, h(SearchIcon)),
167185
h('span', { className: 'bt-palette-empty-label' }, t('No results')),
168186
h('span', { className: 'bt-palette-empty-hint' }, t('Try a Bot name or words from a message')))
169-
: sections.map(([title, items]) => h(Fragment, { key: title },
187+
: sections.map(([title, items, note]) => h(Fragment, { key: title },
170188
h('div', { className: 'bt-palette-section', role: 'presentation', 'data-flip': `section:${title}` }, title),
171189
items.map((row) => {
172190
index += 1
@@ -180,5 +198,6 @@ export function CommandPalette({ start, token, roster, actions, useSessions }) {
180198
h('span', { className: 'bt-palette-title' }, row.title),
181199
row.subtitle ? h('span', { className: 'bt-palette-sub' }, row.subtitle) : null),
182200
row.badge ? h('span', { className: 'bt-palette-badge' }, row.badge) : null)
183-
}))))))
201+
}),
202+
note ? h('div', { className: 'bt-palette-note', role: 'status' }, note) : null)))))
184203
}

‎core/src/client/styles.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,7 @@ button:hover .bt-you{background:color-mix(in srgb,var(--bt-ink) 9%,var(--bt-side
731731
:is(.bt-palette-row,.bt-palette-section,.bt-drop-list>.bt-option){position:relative;z-index:1}
732732
.bt-palette-section{padding:8px 8px 4px;font-size:12px;line-height:16px;color:var(--bt-ink-3);flex:none}
733733
.bt-palette-section:first-of-type{padding-top:0}
734+
.bt-palette-note{padding:2px 8px 8px;font-size:12px;line-height:16px;color:var(--bt-ink-3);flex:none}
734735
.bt-palette-row{flex:none;display:flex;align-items:center;gap:8px;height:49px;padding:6px 10px 6px 8px;border:0;border-radius:8px;background:none;color:inherit;font:inherit;text-align:left;cursor:pointer;box-sizing:border-box;width:100%}
735736
.bt-palette-row[aria-selected=true]{background:var(--bt-active)}
736737
.bt-palette-lead{flex:none;width:24px;height:24px;display:inline-flex;align-items:center;justify-content:center}

0 commit comments

Comments
 (0)