Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

All notable user-visible changes will be documented here. The project follows Semantic Versioning after the v0.6 evidence baseline is released.

## Unreleased

### Added

- Added `audit-build` for local HTML directories with cross-page title/canonical review, syntax checks and optional `--expect-indexable --fail-on-error` CI gates.
- Added an evidence-backed `audit` command for one URL or HTML/Markdown file, with versioned `PASS`, `WARNING`, `FAIL`, and `N/A` checks.
- Added structured observations, remediation, validation guidance, and explicit limitations for HTTP, metadata, headings, canonical, robots directives, links, images, and JSON-LD.
- Added a bounded, same-origin `audit-site` command for robots-aware page discovery, sitemap comparison, HTTP failures, redirect chains, internal-link targets, canonical conflicts, orphan candidates, and duplicate titles.

### Compatibility

- Kept the v0.6 readiness score and existing `scan --json` contract unchanged.

## 0.6.2

### Fixed
Expand Down
71 changes: 71 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ npm install --save-dev aeoptimize
npx aeoptimize scan https://example.com
npx aeoptimize scan ./dist --dir
npx aeoptimize scan ./dist --dir --json
npx aeoptimize audit https://example.com --json
npx aeoptimize audit-site https://example.com --max-pages 20 --json
```

Example output:
Expand Down Expand Up @@ -58,6 +60,38 @@ Two often-promoted AEO signals are deliberately excluded from the score:

Every rule, its evidence class, and known false-positive boundary is documented in [docs/methodology.md](docs/methodology.md) and exercised by the [versioned public fixture corpus](fixtures/v0.6/rule-corpus.ts).

## Evidence-backed page audit

`audit` inspects one public URL or one local HTML/Markdown file. It is a separate, versioned contract and does not change the v0.6 readiness score or `scan --json` output.

```bash
npx aeoptimize audit https://example.com
npx aeoptimize audit ./dist/index.html --json
```

The first audit contract checks:

- HTTP status, final URL, and redirect evidence for URL targets;
- document title, meta description, headings, language, canonical, and page-level robots directives;
- discovered links, image alt attributes, and JSON-LD structural validity.

Each check returns `PASS`, `WARNING`, `FAIL`, or `N/A`, the observed evidence, an explanation, an optional remediation, and a validation step. `PASS` is bounded to the inspected evidence. It does not establish ranking, indexing, rich-result display, traffic, conversion, or AI citation.

The command intentionally reports unavailable site-wide and external measurements as limitations. It does not infer robots.txt policy, sitemap membership, hreflang reciprocity, broken-link status, Core Web Vitals, analytics, or actual search-engine index state from one page.

## Bounded site audit

`audit-site` follows same-origin links in deterministic order and stops at an explicit page limit. It reads robots.txt before subsequent page requests, discovers same-origin sitemap files, and uses response HTML without browser rendering.

```bash
npx aeoptimize audit-site https://example.com
npx aeoptimize audit-site https://example.com --max-pages 50 --json
```

The site contract reports bounded crawl coverage, robots policy, page status, redirect chains, internal link targets, canonical consistency, sitemap discrepancies, sitemap-only orphan candidates, and duplicate titles. Sitemap-only pages remain candidates until a sufficiently complete crawl or server-log evidence confirms their discovery state.

The default limit is 20 page requests and the accepted range is 1–200. Cross-origin page links are recorded only as counts, and subsequent redirects outside the audited origin are not followed. JavaScript-inserted links, actual search-engine crawl/index state, rankings, traffic, and conversions remain outside this contract.

## How it compares

| | aeoptimize | Lighthouse-style SEO audits | Hosted AEO/GEO platforms |
Expand Down Expand Up @@ -101,6 +135,43 @@ The Action exposes `score` and `report` outputs in both modes. Its release is re

A copyable advisory workflow and controlled input are available in the [end-to-end Action sample](examples/github-action-sample/README.md).

## Audit built HTML before deployment

The `audit-build` command checks a local HTML file or build directory and reports evidence,
remediation and validation for each finding. It leaves the existing `scan` score and
JSON contract unchanged.

```bash
npx aeoptimize audit-build ./dist --json
npx aeoptimize audit-build ./dist --base-url https://example.com/ --expect-indexable --fail-on-error --json > audit.json
```

Malformed JSON-LD and invalid or multiple canonical declarations produce `FAIL`.
HTML `noindex` and `none` are warnings unless `--expect-indexable` is supplied.
Missing or repeated titles/descriptions and cross-page title/canonical reuse are
advisory. Shared canonicals can be intentional; they are never automatically rewritten.

`--fail-on-error` exits with code 1 when a `FAIL` is present, while still writing the
complete report. Input errors also exit 1. Without it, a completed audit is advisory.
Use `--expect-indexable` only for pages intended for standalone search indexing.

This command reads source HTML without fetching URLs or launching a browser.
HTTP headers, robots.txt and actual indexing are explicitly unassessed. JSON-LD
checks cover JSON syntax and root shape; schema semantics and visible-content
consistency require separate validation. Missing JSON-LD is `N/A`.

For a file, `--base-url` is its deployed page URL. For a directory, it is the
deployment root; relative file paths are appended without inferring hosting rewrites.
An HTML `base` element is respected. Relative canonicals without a resolvable base
are `N/A`. Hidden entries, `node_modules` and symlinks are excluded from traversal;
an explicit symlink input is rejected. Unreadable files and files over 5 MB stop
the audit instead of silently dropping pages.

Rules follow the [robots meta specification](https://developers.google.com/search/docs/crawling-indexing/robots-meta-tag)
and [canonical URL guidance](https://developers.google.com/search/docs/crawling-indexing/consolidate-duplicate-urls).
A syntax pass does not establish eligibility under the
[structured-data policies](https://developers.google.com/search/docs/appearance/structured-data/sd-policies).

## Optional generators

```bash
Expand Down
21 changes: 21 additions & 0 deletions docs/methodology.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,27 @@ A scoring-rule change must include:

The v0.6 fixture corpus is published in [`fixtures/v0.6/rule-corpus.ts`](../fixtures/v0.6/rule-corpus.ts) and is enforced by the release-contract tests. Outcome research, if added later, will be reported separately from the readiness score.

## Evidence-backed audit contract

The `audit` command is separate from the v0.6 score contract. It reports one of four statuses for each bounded check:

| Status | Meaning |
| --- | --- |
| `PASS` | The inspected evidence satisfies the check's documented condition. This is not an external-outcome guarantee. |
| `WARNING` | A deterministic observation needs contextual review or may be intentional. |
| `FAIL` | The inspected evidence confirms a structural or retrieval failure within the check's scope. |
| `N/A` | The required evidence is unavailable or the check does not apply to this source type. |

Each check includes observed evidence, an explanation, optional remediation, and a validation step. The contract does not derive robots.txt policy, sitemap membership, hreflang reciprocity, site-wide duplication, orphan status, Core Web Vitals, analytics, or search-engine index state from a single document.

### Bounded site audit

The `audit-site` contract uses a same-origin, sequential queue with an explicit 1–200 page limit. It processes links in discovery order before sitemap-only seeds, reads applicable `aeoptimize` or wildcard robots rules, and does not follow subsequent redirects outside the audited origin.

The crawler uses response HTML without browser rendering. A Sitemap-only URL with no internal inlink is reported as an orphan candidate because JavaScript navigation, pages beyond the configured limit, and other discovery sources may still link to it. Broken-link findings require an observed failed response; queued but unfetched links remain warnings.

robots.txt matching covers applicable user-agent groups, `Allow`, `Disallow`, `*` wildcards, and `$` endings. Unusual policies need manual review. An unavailable robots.txt response that is not an ordinary 404 causes conservative skipping of subsequent matching URLs.

## Primary sources

- [Google Search: AI features and your website](https://developers.google.com/search/docs/appearance/ai-features)
Expand Down
169 changes: 168 additions & 1 deletion src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import chalk from 'chalk';
import { readFile, writeFile, mkdir, stat } from 'node:fs/promises';
import { join, extname } from 'node:path';
import { scan, scanDirectory, parseHtml, parseMarkdown, scanUrl } from '../core/scanner.js';
import { audit } from '../core/audit.js';
import { auditSite } from '../core/site-audit.js';
import { generate } from '../core/generator.js';
import { detectAvailableCLIs, scoreWithAllAvailable } from '../core/external-scorers.js';
import { mergeScores } from '../core/merger.js';
import type { ScanReport, MultiAiReport, DimensionScores, ScanTarget, SiteInfo, AiScorerResult } from '../core/types.js';
import { auditPath } from '../core/static-audit.js';
import type { AuditReport, AuditStatus, SiteAuditReport, ScanReport, MultiAiReport, DimensionScores, ScanTarget, SiteInfo, AiScorerResult } from '../core/types.js';

const HOOK_BEGIN_MARKER = '# BEGIN aeoptimize';
const HOOK_END_MARKER = '# END aeoptimize';
Expand Down Expand Up @@ -61,6 +64,90 @@ program
}
});

// ── audit command ─────────────────────────────────────────────────

program
.command('audit <target>')
.description('Audit one URL or HTML/Markdown file with evidence-backed checks')
.option('--json', 'Output the versioned audit JSON contract')
.action(async (target: string, options: { json?: boolean }) => {
try {
if (!target || target.trim().length === 0) {
console.error(chalk.red('Error: Please provide a URL or HTML/Markdown file.'));
process.exit(1);
}

const auditTarget = resolveTarget(target);
const report = await audit(auditTarget);
if (options.json) {
console.log(JSON.stringify(report, null, 2));
} else {
printAuditReport(report);
}
} catch (err) {
console.error(chalk.red(`Error: ${(err as Error).message}`));
process.exit(1);
}
});

program
.command('audit-site <target>')
.description('Crawl one origin with bounded evidence-backed site checks')
.option('--max-pages <count>', 'Maximum page requests from 1 to 200', '20')
.option('--json', 'Output the versioned site-audit JSON contract')
.action(async (target: string, options: { maxPages: string; json?: boolean }) => {
try {
const resolved = resolveTarget(target);
if (resolved.type !== 'url') {
throw new Error('Site audit requires an http or https URL.');
}
const report = await auditSite(resolved.path, { maxPages: Number(options.maxPages) });
if (options.json) {
console.log(JSON.stringify(report, null, 2));
} else {
printSiteAuditReport(report);
}
} catch (err) {
console.error(chalk.red(`Error: ${(err as Error).message}`));
process.exit(1);
}
});

program
.command('audit-build <path>')
.description('Audit local built HTML with evidence and optional CI failure on errors')
.option('--json', 'Output the versioned static audit report as JSON')
.option('--base-url <url>', 'Deployed page URL, or deployment root for a directory')
.option('--expect-indexable', 'Treat HTML noindex/none as a failure for this target')
.option('--fail-on-error', 'Exit 1 when the audit contains FAIL checks; warnings remain advisory')
.action(async (path: string, options: {
json?: boolean; baseUrl?: string; expectIndexable?: boolean; failOnError?: boolean;
}) => {
try {
const report = await auditPath(path, options);
if (options.json) {
console.log(JSON.stringify(report, null, 2));
} else {
console.log('Static HTML Audit');
console.log(`${report.pages.length} pages | ${report.summary.FAIL} failed | ${report.summary.WARNING} warnings | ${report.summary.PASS} passed | ${report.summary['N/A']} not assessed`);
for (const page of report.pages) {
console.log(`\n${page.target}`);
for (const check of page.checks) {
console.log(` [${check.status}] ${check.id}: ${check.message}`);
for (const evidence of check.evidence) console.log(` Evidence: ${evidence}`);
if (check.remediation) console.log(` Fix: ${check.remediation}`);
console.log(` Verify: ${check.validation}`);
}
}
console.log(`\nScope: ${report.limitations.join(' ')}`);
}
if (options.failOnError && report.summary.FAIL > 0) process.exitCode = 1;
} catch (error) {
console.error(`Error: ${(error as Error).message}`);
process.exitCode = 1;
}
});

// ── generate command ───────────────────────────────────────────────

program
Expand Down Expand Up @@ -441,6 +528,86 @@ function printReport(report: ScanReport): void {
}
}

function auditStatusColor(status: AuditStatus): (value: string) => string {
switch (status) {
case 'PASS': return chalk.green;
case 'WARNING': return chalk.yellow;
case 'FAIL': return chalk.red;
case 'N/A': return chalk.gray;
}
}

function printAuditReport(report: AuditReport): void {
console.log('');
console.log(chalk.bold(' Evidence-backed Page Audit'));
console.log(chalk.dim(` Contract ${report.contractVersion} | ${report.timestamp}`));
console.log(chalk.dim(` ${report.target.finalUrl ?? report.target.input}`));
console.log('');
console.log(
` ${chalk.green(`PASS ${report.summary.PASS}`)} ` +
`${chalk.yellow(`WARNING ${report.summary.WARNING}`)} ` +
`${chalk.red(`FAIL ${report.summary.FAIL}`)} ` +
`${chalk.gray(`N/A ${report.summary['N/A']}`)}`,
);
console.log('');

for (const check of report.checks) {
const color = auditStatusColor(check.status);
console.log(` ${color(`[${check.status}]`)} ${chalk.bold(check.label)} ${chalk.dim(`(${check.id})`)}`);
console.log(` ${check.explanation}`);
for (const item of check.evidence) {
const observed = JSON.stringify(item.observed);
console.log(chalk.dim(` Evidence ${item.source}: ${observed}`));
}
if (check.remediation) console.log(` ${chalk.cyan('Fix:')} ${check.remediation}`);
console.log(chalk.dim(` Validate: ${check.validation}`));
console.log('');
}

console.log(chalk.bold(' Limits'));
for (const limitation of report.limitations) {
console.log(chalk.dim(` - ${limitation}`));
}
console.log('');
}

function printSiteAuditReport(report: SiteAuditReport): void {
console.log('');
console.log(chalk.bold(' Bounded Site Audit'));
console.log(chalk.dim(` Contract ${report.contractVersion} | ${report.timestamp}`));
console.log(chalk.dim(` ${report.startUrl} | ${report.crawledPages}/${report.maxPages} pages`));
console.log('');
console.log(
` ${chalk.green(`PASS ${report.summary.PASS}`)} ` +
`${chalk.yellow(`WARNING ${report.summary.WARNING}`)} ` +
`${chalk.red(`FAIL ${report.summary.FAIL}`)} ` +
`${chalk.gray(`N/A ${report.summary['N/A']}`)}`,
);
console.log('');

for (const item of report.checks) {
const color = auditStatusColor(item.status);
console.log(` ${color(`[${item.status}]`)} ${chalk.bold(item.label)} ${chalk.dim(`(${item.id})`)}`);
console.log(` ${item.explanation}`);
for (const itemEvidence of item.evidence) {
console.log(chalk.dim(` Evidence ${itemEvidence.source}: ${JSON.stringify(itemEvidence.observed)}`));
}
if (item.remediation) console.log(` ${chalk.cyan('Fix:')} ${item.remediation}`);
console.log(chalk.dim(` Validate: ${item.validation}`));
console.log('');
}

console.log(chalk.bold(' Pages'));
for (const page of report.pages) {
const status = page.status >= 200 && page.status < 300 ? chalk.green(String(page.status)) : chalk.red(String(page.status));
console.log(` ${status} ${page.requestedUrl}${page.finalUrl !== page.requestedUrl ? ` -> ${page.finalUrl}` : ''}`);
}
console.log('');
console.log(chalk.bold(' Limits'));
for (const limitation of report.limitations) console.log(chalk.dim(` - ${limitation}`));
console.log('');
}

function printDimensionBar(label: string, score: number, max: number): void {
const pct = score / max;
const barWidth = 20;
Expand Down
Loading
Loading