Skip to content

feat: hash based state flag for agent docs#135

Open
Kinfe123 wants to merge 4 commits intomainfrom
feat/hash-base-stale-fixture-for-agent-cs
Open

feat: hash based state flag for agent docs#135
Kinfe123 wants to merge 4 commits intomainfrom
feat/hash-base-stale-fixture-for-agent-cs

Conversation

@Kinfe123
Copy link
Copy Markdown
Member

@Kinfe123 Kinfe123 commented Apr 27, 2026

  • feat: hash based stale fixture for agent docs
  • chore: update
  • chore: fmt
  • chore: review

Summary by cubic

Add hash-based provenance to generated agent.md and a stale-only compaction flow to refresh only drifted pages. docs doctor --agent reports freshness, and servers strip the header before parsing.

  • New Features
    • Generated files include a hidden, versioned header with sourceHash, settingsHash, outputHash, and generatedAt; helpers export from packages/docs (parseGeneratedAgentDocument, serializeGeneratedAgentDocument, stripGeneratedAgentProvenance).
    • CLI docs agent compact adds --stale and --include-missing:
      • Detects page state as fresh, stale, modified, unknown, or missing via hashes.
      • Refreshes only stale files; skips modified/unknown; with --include-missing, creates files for explicit pages or pages with agent.tokenBudget.
      • Writes provenance to agent.md and prints concise skip/create/overwrite summaries.
    • docs doctor --agent reports compaction freshness counts and gives targeted recommendations (e.g., --stale, --include-missing).
    • Framework servers and MCP (astro, nuxt, svelte, tanstack-start) strip the provenance header before gray-matter parsing.
    • Docs updated (README, skill docs, website), plus example generated page; comprehensive tests added.

Written for commit 74cd46b. Summary will update on new commits. Review in cubic

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 27, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs-website Ready Ready Preview, Comment Apr 27, 2026 7:13pm

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 27, 2026

Open in StackBlitz

@farming-labs/astro

pnpm add https://pkg.pr.new/farming-labs/docs/@farming-labs/astro@135

@farming-labs/astro-theme

pnpm add https://pkg.pr.new/farming-labs/docs/@farming-labs/astro-theme@135

@farming-labs/docs

pnpm add https://pkg.pr.new/farming-labs/docs/@farming-labs/docs@135

@farming-labs/theme

pnpm add https://pkg.pr.new/farming-labs/docs/@farming-labs/theme@135

@farming-labs/next

pnpm add https://pkg.pr.new/farming-labs/docs/@farming-labs/next@135

@farming-labs/nuxt

pnpm add https://pkg.pr.new/farming-labs/docs/@farming-labs/nuxt@135

@farming-labs/nuxt-theme

pnpm add https://pkg.pr.new/farming-labs/docs/@farming-labs/nuxt-theme@135

@farming-labs/svelte

pnpm add https://pkg.pr.new/farming-labs/docs/@farming-labs/svelte@135

@farming-labs/svelte-theme

pnpm add https://pkg.pr.new/farming-labs/docs/@farming-labs/svelte-theme@135

@farming-labs/tanstack-start

pnpm add https://pkg.pr.new/farming-labs/docs/@farming-labs/tanstack-start@135

commit: 74cd46b

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 19 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/docs/src/cli/doctor.ts">

<violation number="1" location="packages/docs/src/cli/doctor.ts:1076">
P2: Compaction freshness can be misreported when docs config falls back to static parsing, because compaction defaults are discarded as `{}` before state inspection.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

});
const pages = await Promise.resolve(source.getPages());
const coverage = buildCoverage(pages);
const compactionCoverage = buildCompactionCoverage(
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot Apr 27, 2026

Choose a reason for hiding this comment

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

P2: Compaction freshness can be misreported when docs config falls back to static parsing, because compaction defaults are discarded as {} before state inspection.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/docs/src/cli/doctor.ts, line 1076:

<comment>Compaction freshness can be misreported when docs config falls back to static parsing, because compaction defaults are discarded as `{}` before state inspection.</comment>

<file context>
@@ -933,11 +1073,20 @@ export async function inspectAgentReadiness(
   });
   const pages = await Promise.resolve(source.getPages());
   const coverage = buildCoverage(pages);
+  const compactionCoverage = buildCompactionCoverage(
+    rootDir,
+    contentDir,
</file context>
Fix with Cubic

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 27, 2026

Greptile Summary

This PR implements a hash-based provenance system for generated agent.md files, embedding a hidden HTML comment header with FNV-1a 64-bit hashes of the source content, compaction settings, and output. This allows the CLI to detect and classify file drift into five states (fresh, stale, modified, unknown, missing) and exposes two new flags — --stale to refresh only outdated files and --include-missing to create missing ones for opted-in pages. The docs doctor --agent check is upgraded from a binary "compact configured yes/no" to a full freshness report, and all framework server adapters are updated to strip the provenance header before serving agent content.

Confidence Score: 5/5

Safe to merge; all remaining findings are P2 style/UX suggestions with no correctness or data-integrity impact.

The implementation is thorough and well-tested: the FNV-1a hash is cross-verified in tests, all five compaction states have integration test coverage, and all four framework server adapters are consistently updated to strip provenance. No P0/P1 defects were found. The two P2 observations (persistent 'warn' for intentionally modified files, and version-0 slipping past the guard) do not affect correctness under normal usage.

packages/docs/src/cli/doctor.ts (compactionFreshnessScore modified-pages logic) and packages/docs/src/agent-provenance.ts (version validation guard).

Important Files Changed

Filename Overview
packages/docs/src/agent-provenance.ts New module: FNV-1a 64-bit hashing, provenance serialization/parsing/stripping for generated agent.md headers.
packages/docs/src/cli/agent.ts Core logic changes: --stale/--include-missing flags, inspectAgentCompactionState, provenance embedding on write; persistent "warn" for modified pages may block CI forever.
packages/docs/src/cli/agent.test.ts Comprehensive integration tests for all new stale/missing/modified scenarios; helper expectGeneratedAgentFile validates provenance fields.
packages/docs/src/cli/doctor.ts Doctor check upgraded from binary compact-configured test to full compaction freshness coverage report; score logic is correct but "warn" on modified pages has no resolution path for intentionally hand-edited files.
packages/docs/src/cli/doctor.test.ts New integration test validates all five compaction states in a single doctor run; coverage assertions are thorough.
packages/docs/src/mcp.ts Now strips provenance header via stripGeneratedAgentProvenance before parsing agent.md in MCP reads.
website/app/docs/installation/agent.md New generated file demonstrating the provenance header format in the wild.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["docs agent compact --stale"] --> B{selectAll or explicit pages}
    B --> C["scanDocsPageTargets()"]
    C --> D["For each page: inspectAgentCompactionState()"]
    D --> E{agent.md exists?}
    E -- No --> F["status: missing"]
    E -- Yes --> G{provenance present?}
    G -- No --> H["status: unknown"]
    G -- Yes --> I{sourceKind?}
    I -- agent-md --> J{outputModified?}
    J -- Yes --> K["status: modified"]
    J -- No --> L["status: unknown"]
    I -- resolved-page --> M{sourceChanged or settingsChanged?}
    M -- No, output matches --> N["status: fresh ✓"]
    M -- Yes, output also changed --> O["status: stale-modified"]
    M -- Yes, output unchanged --> P["status: stale"]
    P --> Q["compressDocument()"]
    O --> R["skip — manual edit wins"]
    K --> R
    H --> R
    N --> S["skip — already fresh"]
    F --> T{includeMissing + tokenBudget?}
    T -- Yes --> Q
    T -- No --> U["skip — otherMissing"]
    Q --> V["serializeGeneratedAgentDocument()"]
    V --> W["Write agent.md with provenance header"]
Loading

Comments Outside Diff (1)

  1. packages/docs/src/cli/doctor.ts, line 1480-1484 (link)

    P2 Permanent CI warning for intentionally hand-edited files

    modifiedGeneratedPages > 0 is included in hasActionableIssues, which drives the "warn" status. For projects that deliberately maintain hand-edited agent.md files, docs doctor --agent will produce a permanent warning since --stale intentionally skips modified files — there is no command the user can run to satisfy the check while preserving their edits. Consider removing modifiedGeneratedPages from hasActionableIssues and instead surfacing modified pages as an informational note in the detail string, reserving "warn" for states that are actually actionable (staleGeneratedPages and tokenBudgetMissingPages).

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Reviews (1): Last reviewed commit: "chore: review" | Re-trigger Greptile

Comment on lines +64 to +65
if (
!Number.isFinite(version) ||
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Version 0 passes validation

Number.isFinite(0) returns true, so a provenance block with version=0 would be accepted as valid. Since GENERATED_AGENT_PROVENANCE_VERSION = 1, this means a manually crafted or corrupted block with version 0 silently passes. Consider adding version > 0 (or version === GENERATED_AGENT_PROVENANCE_VERSION) to the guard so any out-of-range version falls through to undefined.

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