Skip to content

feat(extension): let Doctor Extensions declare Evidence Sources - #445

Open
onmax wants to merge 3 commits into
feat/origin-in-reportsfrom
feat/evidence-sources
Open

onmax wants to merge 3 commits into
feat/origin-in-reportsfrom
feat/evidence-sources

Conversation

@onmax

@onmax onmax commented Nov 27, 2026

Copy link
Copy Markdown
Member

Step 2 of the evidence sources design. It's stacked on #444.

A Doctor Extension can now declare sources. An Evidence Source reads Runtime Evidence from outside the source tree, such as what a deployed server answers. Doctor reads a source only when the run passes it an input. With no input, collect never runs and no request goes out.

defineDoctorExtension({
  name: "acme/status",
  sources: [{
    name: "status",
    label: "status page",
    options: { url: { help: "…", value: "url", repeatable: true }, token: { help: "…", requires: "url", secret: true } },
    fromOptions: ({ url = [], token }) => ({ urls: url, token: token?.[0] }),
    toOptions: ({ urls, token }) => ({ url: urls, ...(token ? { token: [token] } : {}) }),
    collect: async (input, { fetch, project }) => ({ evidence, targets, gaps }),
  }],
});
  • CLI flags: each option becomes --<source>-<option>. The options are data on the extension, not setup registrations, so Doctor knows the flags without running extension code. The run command parses in two phases. cac now allows unknown options. After --config loads, Doctor matches the remaining flags against every loaded source and rejects the rest with cac's own Unknown option `--x` message. It also enforces requires, single values, and missing values.
  • Run: DoctorRunOptions.sources holds inputs keyed by source name and stays out of config files. Doctor runs every validate before it collects any source, so a bad input fails before a request. Evidence is stored under project.runtimeEvidence[name]. Gaps get source: name and make the report incomplete. fetch comes from the run (DoctorRunOptions.fetch).
  • Names: a source name must be lowercase kebab, because it prefixes flags. It shares the DOC0026 namespace with Runtime Evidence contributors, since both write runtimeEvidence[name].
  • Reports: result.evidenceSources lists name, label, targets, and the rerun args. The JSON report adds sources. The agent rerun commands repeat the source flags, with secret values shown as <redacted>.
  • Docs: a "Read evidence from outside the source" section in 9.extending.md, and the Evidence Source term in CONTEXT.md.

MCP still uses its own --mcp-* path in this PR. The next PR moves it onto this API and removes the MCP-specific code from core.

Tests

tests/core/evidence-sources.test.ts, with a fixture source, covers:

  • no input means no collect
  • evidence, gaps, and targets under the source name
  • JSON sources
  • a redacted agent rerun
  • validation before collection, and an unknown source name
  • a name clash with a contributor
  • CLI flags from a --config extension, including repeatable flags
  • rejection of unknown, unpaired, and empty flags, and of a typo without a config

The CLI, agent rerun, extension catalog, Doctor process, MCP, and origin suites pass locally (212 tests). tsc --noEmit reports no errors in src/ or tests/. I didn't run the full pnpm ready locally because the shared build queue was backed up, so CI's release:check is the full run.

🤖 Generated with Claude Code

@pullfrog pullfrog Bot 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.

Caution

A flag shared by two extensions can expose a credential marked secret in the agent report. The CLI must reject ambiguous flag declarations before it collects evidence.

Approach: Declaring Evidence Sources on extensions and collecting them in the shared Doctor Run is the right split, but the CLI needs one owner per flag and must preserve the original argument values.

Reviewed changes across the extension API, CLI, Doctor Run, and report outputs.

  • Extension API and CLI: Reviewed source declarations, config-based discovery, dynamic flag parsing, and source input construction.
  • Doctor Run: Reviewed registration, validation and collection order, Runtime Evidence, and evidence gaps.
  • Reports and docs: Reviewed JSON source summaries, agent rerun arguments, redaction, and the extension guide and tests.

pnpm build passed. The focused suites passed 204 tests, including all 9 new tests. The one failure in tests/core/origin-reports.test.ts also reproduced on the base commit.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using gpt-6.2-sol(high) | 𝕏

Comment thread src/core/internal/evidence-sources.ts Resolved
Comment thread src/cli-main.ts Resolved
Comment thread src/core/internal/evidence-sources.ts Resolved
An Evidence Source reads Runtime Evidence from outside the source tree
only when the run gets an input for it. It declares its CLI flags as
data, so the CLI reads --<source>-<option> after --config loads and
still rejects flags no source declares. Reports list what each source
read and repeat its flags in the rerun command with secrets redacted.
@onmax
onmax force-pushed the feat/evidence-sources branch from 9f9c226 to d4d1728 Compare November 27, 2026 15:31
@pkg-pr-new

pkg-pr-new Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

pnpm dlx https://pkg.pr.new/vite-doctor@445

commit: 09ab59d

@pullfrog pullfrog Bot 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.

Important

A Doctor Run with --config now invokes configured extension loaders twice, even when no Evidence Source flags are passed.

Reviewed changes in 60022d3 since d4d1728.

  • Isolated source flags from CAC parsing, rejected declaration collisions, and preserved dash-prefixed values in rerun arguments.
  • Moved source validation ahead of Runtime Evidence contributors and awaited asynchronous validators before collection.

pnpm build and all 250 focused tests passed. A separate built CLI check reproduced the loader regression.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using gpt-6.2-sol(high) | 𝕏

Comment thread src/cli-main.ts Resolved

@pullfrog pullfrog Bot 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.

✅ No new issues found; no P0 or P1 findings remain.

Reviewed changes in 09ab59d since the prior review at 60022d3.

  • Reused resolved extensions for flag discovery and execution, so configured loaders run once per Doctor Run.
  • Kept watch reruns fresh by using the prepared invocation for the first run and reloading configuration on subsequent runs.
  • Added regression coverage for configured loaders with and without Evidence Source flags.

pnpm build passed, and all 409 focused tests passed. I also verified with the built CLI that each loader runs once and that --watch picks up a config edit on the next run.

Pullfrog  | View workflow run | Using gpt-6.2-sol(high) | 𝕏

This branch has not been deployed

No deployments
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.

1 participant