Skip to content

fix(scraper): measure exclude globs from the scrape root and warn on empty jobs - #649

Merged
arabold merged 18 commits into
mainfrom
fix/624-exclude-pattern-scope
Dec 5, 2026
Merged

arabold merged 18 commits into
mainfrom
fix/624-exclude-pattern-scope

Conversation

@arabold

@arabold arabold commented Dec 5, 2026

Copy link
Copy Markdown
Owner

Closes #624. Builds on #645, so it targets that branch; it can go to main once #645 is merged.

Problem

Scraping a folder named test indexed nothing, and nothing said why. The default exclude pattern **/test/** was matched against the whole path, so it also matched the scrape root itself (file:///docs-inbox/test) and every link was dropped. The same happens with any root under a default-excluded folder, like https://example.com/legacy/docs/. The debug log called each of these links "out-of-scope", and the job reported a plain success.

What changes

  • Patterns starting with **/ match only below the scrape root. This covers all default folder exclusions and user patterns of the same form. Folders like test/ or archive/ inside the root are still excluded. Anchored globs (/docs/v3/**, https://example.com/docs/**) and regex patterns match the full URL and the absolute path as before.
  • Patterns are applied in one place. The admission hook from feat(scraper): delete stored pages the scrape options no longer admit on refresh #645 is now the only pattern check, renamed getExclusion because it returns why a link was rejected. Before, links went through the patterns twice, and the second pass matched GitHub files by blob URL, so GitHub include patterns like docs/** dropped every file. They work now.
  • Skipped links say why in the debug log: outside the scope (naming the mode), excluded by a named pattern, matching no include pattern, hidden, or a symlink.
  • A job that stores nothing completes with a warning naming the most common reason, e.g. 1 link was skipped as excluded by pattern `**/test/**`; default exclude patterns apply unless excludePatterns is set. get_job_info, list_jobs and the CLI scrape output show it. A refresh where every page is unchanged gets no warning.
  • The scrape_docs description says that default exclude patterns apply unless excludePatterns is set, and that any value replaces them.

The spec is in openspec/changes/fix-exclude-pattern-scope/.

Behaviour users will notice

  • Scrapes rooted in folders named test, old, build, legacy and similar now index content.
  • GitHub includePatterns now work, and GitHub repo-path exclude patterns apply when links are queued.
  • An empty scrape prints a warning instead of "Successfully scraped".

Tests

  • test/scrape-patterns-e2e.test.ts: the /docs-inbox/test reproduction, a web root under /legacy/docs/, links outside the root, the warning through get_job_info, and no warning on an unchanged refresh.
  • test/github-scrape-e2e.test.ts: includePatterns: ["docs/**"] indexes docs/ files; a tree/main/test root keeps its files.
  • test/cli-e2e.test.ts: the CLI prints the warning instead of success.
  • Unit tests for the matcher, the root folder, and the debug log naming the pattern.

npm run lint, a cold npm run typecheck, npm run build and npm test pass.

Not in this PR

  • The web UI job list doesn't show the warning yet.
  • The warning is held only in memory with the job, so it is gone after a restart.

… on refresh

Adds an async isExcluded admission hook to BaseScraperStrategy. It filters discovered links at enqueue and judges refresh items before they are fetched. A stored page that is excluded is reported as the new PageOutcome.Excluded, and the worker deletes it instead of strategies faking a 404.

The base applies include and exclude patterns. LocalFileStrategy adds the includeHidden and followSymlinks rules, which move out of its directory and archive listings.
…e scope

A stored page whose content came from a Markdown variant is excluded only when neither its retrieval URL nor its identity is admitted. GitHub repository files are matched by their path in the repository, as discovery does. The local listing keeps its scope check, so members of an HTTP(S) root archive stay out of a web crawl that cannot read them.
WebScraperStrategy decides itself that an HTTP(S) root archive queues no members, so LocalFileStrategy's listings drop their duplicate scope check. Symlink lookups are cached per crawl, GitHub shares one repository-path pattern check, and the E2E tests change stored options through a harness helper.
…empty jobs

Match-anywhere exclude globs such as the default `**/test/**` matched the
folders at and above the scrape root, so scraping `file:///docs-inbox/test`
or `https://example.com/legacy/docs/` indexed nothing. They now match only
the path below the root. Anchored globs and regex patterns still match the
full URL and absolute path.

Patterns are applied in one place, the `getExclusion` admission hook, which
returns why a link was rejected. Each rejected link is logged with its
reason, and a job that leaves its version without searchable content
completes with a warning naming the most common reason. get_job_info,
list_jobs and the CLI scrape output show it. The scrape_docs description
now explains the default exclude patterns.

Applying patterns once also fixes GitHub include patterns, which were
re-matched against blob URLs and dropped every file.

Closes #624
… in github paths

A start URL that redirects is stored under its target. The root now runs first and depth-0 stored pages wait for it, so the patterns never judge the redirected start page. GitHub repository paths whose percent signs are not escapes no longer abort the scrape.
…-mcp-server into fix/624-exclude-pattern-scope

# Conflicts:
#	src/scraper/strategies/GitHubScraperStrategy.ts
Return the rejection straight from evaluateUrlPatterns, share one file-root containment helper, tally rejections in a map, and compute the GitHub tree root once per scrape.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Redirected paths are lost during pattern matching, incorrectly excluding descendants, and refresh exclusions omit rejection reasons, producing misleading warnings.

2 open issues
What changed in this PR

Addresses #624 using the admission hook from #645: scrape-root folder names no longer trigger default exclusions, and empty jobs report warnings.

Changes:

  • Centralizes pattern checks and adds root-relative exclusions.
  • Reports rejection reasons and exposes empty-job warnings through MCP and CLI.
  • Adds regression tests, documentation, and OpenSpec artifacts.
File Description
test/​scrape-patterns-e2e.test.ts Tests root exclusions and empty-job warnings.
test/​github-scrape-e2e.test.ts Tests repository patterns and tree roots.
test/​cli-e2e.test.ts Tests CLI warning output.
src/​tools/​ScrapeTool.ts Returns completion warnings.
src/​tools/​ListJobsTool.ts Includes job warnings.
src/​tools/​GetJobInfoTool.ts Exposes warning details.
src/​store/​DocumentStore.ts Counts stored chunks by version.
src/​store/​DocumentManagementService.ts Exposes chunk counting.
src/​scraper/​utils/​scope.ts Calculates pattern root directories.
src/​scraper/​utils/​scope.test.ts Tests pattern roots.
src/​scraper/​utils/​patternMatcher.ts Implements reasoned, root-relative matching.
src/​scraper/​utils/​patternMatcher.test.ts Tests matching and rejection reasons.
src/​scraper/​utils/​linkRejection.ts Formats rejection reasons.
src/​scraper/​types.ts Defines rejection summaries.
src/​scraper/​strategies/​WebScraperStrategy.ts Routes pattern checks through admission.
src/​scraper/​strategies/​PyPiScraperStrategy.ts Returns scrape summaries.
src/​scraper/​strategies/​NpmScraperStrategy.ts Returns scrape summaries.
src/​scraper/​strategies/​LocalFileStrategy.ts Reports hidden-file and symlink exclusions.
src/​scraper/​strategies/​GitHubWikiProcessor.ts Removes unused pattern checking.
src/​scraper/​strategies/​GitHubScraperStrategy.ts Matches repository paths through admission.
src/​scraper/​strategies/​GitHubScraperStrategy.test.ts Moves pattern coverage to E2E tests.
src/​scraper/​strategies/​BaseScraperStrategy.ts Centralizes admission and tallies rejections.
src/​scraper/​strategies/​BaseScraperStrategy.test.ts Tests rejection logs and counts.
src/​scraper/​ScraperService.ts Returns strategy summaries.
src/​pipeline/​types.ts Adds the job warning field.
src/​pipeline/​PipelineWorker.ts Generates empty-version warnings.
src/​pipeline/​PipelineManager.ts Publishes warnings before completion.
src/​pipeline/​PipelineManager.test.ts Updates scrape-summary mocks.
src/​mcp/​mcpServer.ts Describes defaults and displays warnings.
src/​mcp/​mcpServer.test.ts Tests default-exclusion descriptions.
src/​cli/​commands/​scrape.ts Prints warnings instead of success.
openspec/​changes/​fix-exclude-pattern-scope/​tasks.md Records implementation tasks.
openspec/​changes/​fix-exclude-pattern-scope/​specs/​scrape-url-patterns/​spec.md Specifies pattern behavior.
openspec/​changes/​fix-exclude-pattern-scope/​specs/​scrape-job-warnings/​spec.md Specifies warning behavior.
openspec/​changes/​fix-exclude-pattern-scope/​proposal.md Defines purpose and scope.
openspec/​changes/​fix-exclude-pattern-scope/​design.md Documents implementation decisions.
openspec/​changes/​fix-exclude-pattern-scope/​.openspec.yaml Adds change metadata.
docs/​guides/​basic-usage.md Explains exclusions and warnings.
docs/​concepts/​refresh-architecture.md Documents the updated admission hook.

Review effort: Balanced

…t refresh exclusions

A depth-0 redirect into a folder such as /docs/test/ no longer lets **/test/** drop its pages. A stored page that a refresh removes is now logged and counted with its reason, so the empty-job warning names it.
…same pages

A crawl now judges the URL a redirected page is stored under by the rule a refresh applies, so the next refresh no longer deletes it. Pages about to be excluded wait for the root, at any depth, so a start page that redirects onto a stored child page is kept. Also drops a dead internal-root branch, reattaches the GitHub class doc and tests default discovery of hidden files, symlinks and hidden archive entries.
… on refresh

A refresh queued every stored page without running the filters a crawl
applies to discovered links, so pages the current options would not admit
stayed indexed. An async isExcluded admission hook on BaseScraperStrategy
now judges discovered links at enqueue and stored pages before they are
fetched, and an excluded stored page is reported as PageOutcome.Excluded
and deleted.

- The base hook applies include and exclude patterns. A stored page with a
  Markdown source is excluded only when neither URL is admitted, and the
  start page is never excluded, including where its URL redirected.
- A crawl judges redirect targets by the same rule, so a scrape and a
  refresh store the same pages.
- LocalFileStrategy excludes hidden paths and symlinks below the crawl root
  per includeHidden and followSymlinks, cached per crawl.
- GitHubScraperStrategy matches repository files by their repository path.
- An HTTP(S) root archive queues no file:// members.
…-mcp-server into fix/624-exclude-pattern-scope

# Conflicts:
#	src/scraper/strategies/BaseScraperStrategy.ts
#	src/scraper/strategies/LocalFileStrategy.ts
@arabold
arabold added this pull request to stack #650 December 5, 2026 20:26
…-mcp-server into fix/624-exclude-pattern-scope

# Conflicts:
#	docs/concepts/refresh-architecture.md
#	src/scraper/strategies/BaseScraperStrategy.ts
#	src/scraper/strategies/GitHubScraperStrategy.ts
#	src/scraper/strategies/LocalFileStrategy.ts
…-mcp-server into fix/624-exclude-pattern-scope

# Conflicts:
#	docs/concepts/refresh-architecture.md
#	src/scraper/strategies/BaseScraperStrategy.ts
#	src/scraper/strategies/GitHubScraperStrategy.ts
#	src/scraper/strategies/LocalFileStrategy.ts
#	test/github-scrape-e2e.test.ts
#	test/local-file-refresh-e2e.test.ts
#	test/refresh-pipeline-e2e.test.ts
…do not name

Include patterns name files, so a local crawl with includePatterns such as **/*.md never entered sub/. Folders and archives are now judged by the exclude patterns only, during a scrape and a refresh alike.
Base automatically changed from feat/refresh-excluded-pages to main December 5, 2026 21:35

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Root-relative pattern matching can delete valid pages during concurrent redirected refreshes and incorrectly reject Markdown siblings after URL identity normalization.

2 open issues
2 resolved since last review

Review effort: Balanced

…from the fetched start url

A concurrent refresh judged stored pages before the root's redirect was known and could delete pages a fresh scrape keeps. A Markdown start page measured patterns from its identity rather than its own folder.
@arabold
arabold merged commit 47fd9b7 into main Dec 5, 2026
5 checks passed
@arabold
arabold deleted the fix/624-exclude-pattern-scope branch December 5, 2026 23:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A default exclude pattern is logged as "out-of-scope", and the job completes with no documents

2 participants