-
Notifications
You must be signed in to change notification settings - Fork 1
feat(AI-179): implement /fiona search — browse raw sources without synthesized answer #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Copilot
wants to merge
19
commits into
main
Choose a base branch
from
copilot/ai-179-clone-fiona-search
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
02aa8a4
Initial plan
Copilot 623ce03
feat(AI-179): implement /fiona search — browse raw sources without sy…
Copilot 0d02a67
fix: address code review feedback — rename subCommand param, improve …
Copilot 931ce57
fix: address second round of code review feedback
Copilot 447ec7a
feat(AI-179): switch searchForSources to Perplexity Search API (POST …
Copilot aa24bc1
fix: improve error message and JSDoc based on code review feedback
Copilot 2dca58a
feat(AI-179): env-backed SEARCH_MAX_SOURCES with hard cap; strip mark…
Copilot 9717ea5
fix: env-back SNIPPET_MAX_CHARS; use non-greedy italic regex in trunc…
Copilot efaf681
fix: inline SNIPPET_MAX_CHARS parse; keep parsePositiveIntEnv unexpor…
Copilot 51be89c
fix: use [\s\S]*? in bold regex to handle asterisks inside bold markers
Copilot 3617e51
feat(AI-179): implement review feedback - perplexity SDK, domain filt…
Copilot b720e9c
feat(AI-179): use Perplexity SDK, domain filter, 160-word snippets, B…
Copilot 61620ea
Disable Slack unfurls for search results
Copilot eadc96f
Add search feedback context support
Copilot 2d47bf3
Refine feedback context handling
Copilot 1bf7dd8
Document feedback helpers
Copilot ed96924
Tighten feedback block metadata
Copilot dd62e98
Polish feedback helpers
Copilot 2366d30
fix: resolve biome lint/format errors in feedback files
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // Licensed to the Ed-Fi Alliance under one or more agreements. | ||
| // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. | ||
| // See the LICENSE and NOTICES files in the project root for more information. | ||
|
|
||
| export const FEEDBACK_RESPONSE_TYPES = Object.freeze({ | ||
| SYNTHESIS: 'synthesis', | ||
| SEARCH: 'search', | ||
| ASK: 'ask', | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // Licensed to the Ed-Fi Alliance under one or more agreements. | ||
| // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. | ||
| // See the LICENSE and NOTICES files in the project root for more information. | ||
|
|
||
| /** | ||
| * Search abstraction layer for the `/fiona search` skill. | ||
| * Wraps the LLM-layer search call and provides Slack-specific formatting. | ||
| * Imported by fiona.js so the slash command handler never depends on llm-caller | ||
| * directly (preserving the architectural separation of concerns). | ||
| */ | ||
|
|
||
| import { searchForSources } from './llm-caller.js'; | ||
|
|
||
| export { searchForSources }; | ||
|
|
||
| const SEARCH_NO_RESULTS_TEXT = '🔍 No sources found for _"{{query}}"_. Try rephrasing your query.'; | ||
| // Exported so slash and say()-based handlers can share a single error string. | ||
| export const SEARCH_ERROR_TEXT = ':warning: Search encountered an error. Please try again later.'; | ||
|
|
||
| // Read snippet max word count from SEARCH_SNIPPET_MAX_WORDS env var. | ||
| // Falls back to 160 when the env var is absent, non-numeric, or not a positive integer. | ||
| const _snippetMaxRaw = Number.parseInt(process.env.SEARCH_SNIPPET_MAX_WORDS ?? '', 10); | ||
| const SNIPPET_MAX_WORDS = Number.isFinite(_snippetMaxRaw) && _snippetMaxRaw > 0 ? _snippetMaxRaw : 160; | ||
|
|
||
| /** | ||
| * Strip common markdown syntax from a snippet and truncate to the configured | ||
| * maximum word count (SNIPPET_MAX_WORDS). | ||
| * Perplexity Search API snippets can contain bold markers, headings, and multi- | ||
| * paragraph text; stripping and truncating keeps the Slack source list compact. | ||
| * | ||
| * Only `**bold**` and `### heading` patterns are removed; single-asterisk italic | ||
| * is intentionally left untouched to avoid false positives on maths/code notation | ||
| * (e.g. `a * b`). | ||
| * | ||
| * @param {string} text | ||
| * @returns {string} | ||
| */ | ||
| function truncateSnippet(text) { | ||
| if (!text || typeof text !== 'string') return ''; | ||
| // Collapse newlines and runs of whitespace to a single space | ||
| let cleaned = text | ||
| .replace(/\n+/g, ' ') | ||
| .replace(/\s{2,}/g, ' ') | ||
| .trim(); | ||
| // Strip bold markers (**text**) and heading markers (## …) | ||
| cleaned = cleaned.replace(/\*\*([\s\S]*?)\*\*/g, '$1').replace(/#{1,6}\s+/g, ''); | ||
| const words = cleaned.split(/\s+/); | ||
| if (words.length <= SNIPPET_MAX_WORDS) return cleaned; | ||
| return `${words.slice(0, SNIPPET_MAX_WORDS).join(' ')}…`; | ||
| } | ||
|
|
||
| /** | ||
| * Escape user-supplied text before embedding it in a Slack mrkdwn message. | ||
| * Only `&`, `<`, and `>` need HTML-entity encoding per the Slack API spec. | ||
| * | ||
| * @param {string} text | ||
| * @returns {string} | ||
| */ | ||
| export function escapeMrkdwn(text) { | ||
| if (!text || typeof text !== 'string') return ''; | ||
| return text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>'); | ||
| } | ||
|
|
||
| /** | ||
| * Format a list of normalized sources into a Slack Block Kit message with | ||
| * a mrkdwn plain-text fallback. Each result is rendered as a section block | ||
| * (title link) and an optional context block (snippet), separated by dividers. | ||
| * | ||
| * @param {string} query - The original search query (unsanitized) | ||
| * @param {Array<import('./llm-caller.js').NormalizedSource>} sources - Normalized source list | ||
| * @returns {{ text: string, blocks: Array<object> | null }} Slack message payload | ||
| */ | ||
| export function formatSearchResults(query, sources) { | ||
| const safeQuery = escapeMrkdwn(query); | ||
|
|
||
| if (!Array.isArray(sources) || sources.length === 0) { | ||
| return { text: SEARCH_NO_RESULTS_TEXT.replace('{{query}}', safeQuery), blocks: null }; | ||
| } | ||
|
|
||
| const headerText = `🔍 *Search results for:* _"${safeQuery}"_`; | ||
|
|
||
| // ── Block Kit layout ─────────────────────────────────────────────────────── | ||
| const blocks = [{ type: 'section', text: { type: 'mrkdwn', text: headerText } }, { type: 'divider' }]; | ||
|
|
||
| for (let i = 0; i < sources.length; i++) { | ||
| const source = sources[i]; | ||
| const link = `*<${source.url}|${escapeMrkdwn(source.title || source.hostname)}>*`; | ||
| blocks.push({ type: 'section', text: { type: 'mrkdwn', text: `${i + 1}. ${link}` } }); | ||
|
|
||
| const rawSnippet = truncateSnippet(source.snippet); | ||
| if (rawSnippet) { | ||
| blocks.push({ | ||
| type: 'context', | ||
| elements: [{ type: 'mrkdwn', text: `_"${escapeMrkdwn(rawSnippet)}"_` }], | ||
| }); | ||
| } | ||
|
|
||
| if (i < sources.length - 1) { | ||
| blocks.push({ type: 'divider' }); | ||
| } | ||
| } | ||
|
|
||
| // ── Plain-text fallback (used by Slack notifications / accessibility) ────── | ||
| const items = sources.map((source, i) => { | ||
| const rawSnippet = truncateSnippet(source.snippet); | ||
| const snippet = rawSnippet ? `\n${rawSnippet}` : ''; | ||
| return `${i + 1}. ${source.title || source.hostname} — ${source.url}${snippet}`; | ||
| }); | ||
| const text = `${headerText}\n\n${items.join('\n\n')}`; | ||
|
|
||
| return { text, blocks }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking pretty good. One issue I see is the response items appear as a long, unformatted list, making it difficult to read. Lets improve the readabilitiy, perhaps formatting the snippet and truncating the content more so the total number of sources is easier to see.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a
truncateSnippethelper insearch-caller.jsthat:**bold**markers (using[\s\S]*?to handle asterisks inside bold text) and### headingmarkers…The
SNIPPET_MAX_CHARSlimit is also env-backed viaSEARCH_SNIPPET_MAX_CHARS(default 150) so operators can tune it. Single-asterisk italic is intentionally not stripped to avoid false positives on math/code notation likea * b. Commit:feat(AI-179): env-backed SEARCH_MAX_SOURCES with hard cap; strip markdown and truncate snippets