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 docs/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ libscope search "deploy process" --context 1 # include neighboring chunks
|--------|-------------|
| `--library <name>` | Filter by library |
| `--topic <name>` | Filter by topic |
| `--source <type>` | Filter by source type (e.g., `library`, `topic`, `manual`, `model-generated`) |
| `--limit <n>` | Max results (default: 10) |
| `--min-rating <n>` | Minimum average rating |
| `--context <n>` | Include N neighboring chunks before/after each result (0-2, default: 0) |
Expand Down
10 changes: 9 additions & 1 deletion src/api/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export async function handleRequest(
return;
}
const topic = url.searchParams.get("topic") ?? undefined;
const source = url.searchParams.get("source") ?? undefined;
const tag = url.searchParams.get("tag") ?? undefined;
const limitRaw = url.searchParams.get("limit");
const limitParsed = limitRaw ? parseInt(limitRaw, 10) : NaN;
Expand All @@ -151,7 +152,14 @@ export async function handleRequest(
const offset = Number.isNaN(offsetParsed) ? undefined : offsetParsed;
const tags = tag ? [tag] : undefined;

const result = await searchDocuments(db, provider, { query: q, topic, tags, limit, offset });
const result = await searchDocuments(db, provider, {
query: q,
topic,
tags,
source,
limit,
offset,
});
Comment on lines 145 to +162
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

source is accepted as an arbitrary string and forwarded to searchDocuments, but the DB constrains documents.source_type to a small set of values (library, topic, manual, model-generated). For invalid values, the API will silently return 0 results, which is hard to diagnose. Consider validating source against the allowed set and returning a 400 VALIDATION_ERROR with a clear message when it’s not recognized.

Copilot uses AI. Check for mistakes.
Comment on lines +155 to +162
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds a new /api/v1/search query parameter (source) but there’s no test coverage asserting it is parsed and applied (there are already tests for limit and offset in tests/unit/api.test.ts). Add a unit test that indexes docs with different sourceType values and verifies ?source=manual / ?source=topic filters results correctly (and covers the invalid-value path if you add validation).

Copilot uses AI. Check for mistakes.
const took = Math.round(performance.now() - start);
sendJson(res, 200, result, took);
return;
Expand Down
6 changes: 6 additions & 0 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@ program
.description("Search indexed documents")
.option("--topic <topicId>", "Filter by topic")
.option("--library <name>", "Filter by library")
.option(
"--source <type>",
"Filter by source type (e.g., 'library', 'topic', 'manual', 'model-generated')",
)
.option("--limit <n>", "Max results", "5")
.option("--offset <n>", "Offset for pagination", "0")
.option("--context <n>", "Include N neighboring chunks before/after each result (0-2)", "0")
Expand All @@ -339,6 +343,7 @@ program
opts: {
topic?: string;
library?: string;
source?: string;
limit: string;
offset: string;
context: string;
Expand All @@ -351,6 +356,7 @@ program
query,
topic: opts.topic,
library: opts.library,
source: opts.source,
limit: parseIntOption(opts.limit, "--limit"),
offset: parseIntOption(opts.offset, "--offset"),
contextChunks: contextChunks > 0 ? contextChunks : undefined,
Expand Down
5 changes: 5 additions & 0 deletions src/mcp/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ async function main(): Promise<void> {
topic: z.string().optional().describe("Filter by topic ID"),
library: z.string().optional().describe("Filter by library name"),
version: z.string().optional().describe("Filter by library version"),
source: z
.string()
.optional()
.describe("Filter by source type (e.g., 'library', 'topic', 'manual', 'model-generated')"),
minRating: z.number().min(1).max(5).optional().describe("Minimum average rating filter"),
offset: z.number().min(0).optional().describe("Offset for pagination (default: 0)"),
limit: z
Expand All @@ -141,6 +145,7 @@ async function main(): Promise<void> {
topic: params.topic,
library: params.library,
version: params.version,
source: params.source,
minRating: params.minRating,
limit: params.limit,
offset: params.offset,
Expand Down
Loading