Skip to content

fix(docs): async install docs generation + home-repo guard#314

Merged
efenocchi merged 2 commits into
mainfrom
fix/docs-install-async
Jul 15, 2026
Merged

fix(docs): async install docs generation + home-repo guard#314
efenocchi merged 2 commits into
mainfrom
fix/docs-install-async

Conversation

@efenocchi

@efenocchi efenocchi commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Fix the install-time docs footgun (async + home guard)

Follow-up to #305. A real from-0 install surfaced two problems; this fixes both without reverting the feature.

1. Install no longer blocks on the LLM

hivemind install in a repo delegated to an inline docs sync, which generated the wiki in the foreground — minutes of per-page claude -p calls hung install. Now it mirrors the async half of hivemind graph init:

  1. build the graph inline (fast, no LLM),
  2. run the onboarding (generate? → which agent? → auto?),
  3. on consent, spawn docs wiki detached → install returns immediately with "Generating wiki docs in the background — check with: hivemind docs list".

The detached-spawn block is the same shape graph init already ships (spawnDetachedNodeWorker(["docs","wiki",…])).

2. Home-repo guard

If the resolved git root is $HOME (a dotfiles repo makes git rev-parse --show-toplevel resolve to ~ from any subdirectory), install no longer offers to document the whole home — it falls back to the hint. The guard lives in shouldPromptDocsSetup(atHome), unit-tested.

Verification

  • tsc clean; shouldPromptDocsSetup unit tests cover the home guard (7 pass).
  • Built bundle confirmed: install path spawns detached docs wiki, prints the background message, and no longer runs inline docs sync.
  • Live run: install resolves the correct repo root (not ~) and reaches the onboarding; interactive multi-prompt click-through over a piped pty is flaky in CI harnesses, so the async generation is verified via graph-init parity + bundle-level checks.

Files

  • src/cli/index.ts — async delegation (build inline + onboarding + detached wiki)
  • src/docs/install-hint.tsshouldPromptDocsSetup home guard
  • tests/shared/docs-install-hint.test.ts — home-guard tests

Session Context

Session transcript

Summary by CodeRabbit

  • New Features
    • Added installation-time docs onboarding with interactive consent, one-time install hints, and automatic background “docs wiki” generation when already enabled.
  • Bug Fixes
    • Suppressed docs setup prompts when the repository corresponds to the user’s home directory, with safer cross-platform path matching.
    • Installation now continues gracefully when docs onboarding/setup encounters failures.
  • Tests
    • Added automated test coverage for the docs onboarding decision flow, including prompt suppression, spawn behavior, already-enabled, hint/no-repo, and failure handling.

`hivemind install` inside a git repo used to delegate to an inline `docs
sync`, which generated the wiki in the FOREGROUND — minutes of per-page
`claude -p` calls hung install on any non-trivial repo. Mirror the async half
of `hivemind graph init` instead: build the graph inline (fast, no LLM), run
the onboarding, then spawn `docs wiki` DETACHED so install returns immediately
("Generating wiki docs in the background — check with: hivemind docs list").

Also add a home-repo guard: when the resolved git root is $HOME (a dotfiles
repo makes `git rev-parse --show-toplevel` resolve to ~ from any subdir), do
not offer to document the whole home — fall back to the hint. The guard lives
in shouldPromptDocsSetup (unit-tested).
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@efenocchi, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 13 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: bbc98994-c858-45a9-b53b-25b72d165eba

📥 Commits

Reviewing files that changed from the base of the PR and between 9e19a29 and 5e62f8d.

📒 Files selected for processing (5)
  • src/cli/index.ts
  • src/docs/install-docs.ts
  • src/docs/install-hint.ts
  • tests/shared/docs-install-hint.test.ts
  • tests/shared/install-docs.test.ts
📝 Walkthrough

Walkthrough

Install-time docs onboarding now delegates to an injected workflow, suppresses prompts for home-directory repositories, handles configuration and consent outcomes, builds documentation state, and can launch a detached wiki worker.

Changes

Docs install onboarding

Layer / File(s) Summary
Home-repository prompt guard
src/docs/install-hint.ts, tests/shared/docs-install-hint.test.ts
shouldPromptDocsSetup accepts atHome, blocks prompting when true, and tests normalized home-root matching plus guarded and normal behavior.
Docs onboarding workflow
src/docs/install-docs.ts, tests/shared/install-docs.test.ts
Adds dependency-injected onboarding orchestration with repository and configuration guards, graph building, consent handling, detached worker spawning, explicit outcomes, and failure isolation.
CLI onboarding integration
src/cli/index.ts
Install delegates docs setup to runInstallDocsOnboarding and supplies graph, configuration, snapshot, worker, hint, and logging capabilities.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant runInstallAll
  participant runInstallDocsOnboarding
  participant GitRootProbe
  participant DocsOnboarding
  participant DetachedWorker
  runInstallAll->>runInstallDocsOnboarding: pass injected install capabilities
  runInstallDocsOnboarding->>GitRootProbe: resolve repository top-level
  GitRootProbe-->>runInstallDocsOnboarding: return repository root
  runInstallDocsOnboarding->>DocsOnboarding: build graph and run consent flow
  DocsOnboarding-->>runInstallDocsOnboarding: return onboarding result
  runInstallDocsOnboarding->>DetachedWorker: spawn detached docs wiki
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the change and verification, but it omits the template's Version Bump section and the required test-plan checklist. Add the required ## Summary, ## Version Bump, and ## Test plan sections, including whether a package.json version bump is needed.
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: async install-time docs generation plus the home-repo guard.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/docs-install-async

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Coverage Report

Scope: files changed in this PR. Enforced threshold: 90% per metric (per file via vitest.config.ts).

Status Category Percentage Covered / Total
🔴 Lines 85.57% (🎯 90%) 249 / 291
🔴 Statements 86.46% (🎯 90%) 300 / 347
🔴 Functions 85.29% (🎯 90%) 29 / 34
🔴 Branches 85.65% (🎯 90%) 191 / 223
File Coverage — 3 files changed
File Stmts Branches Functions Lines
src/cli/index.ts 🔴 84.7% 🔴 84.6% 🔴 81.5% 🔴 83.4%
src/docs/install-docs.ts 🟢 100.0% 🟢 92.8% 🟢 100.0% 🟢 100.0%
src/docs/install-hint.ts 🟢 100.0% 🟢 100.0% 🟢 100.0% 🟢 100.0%

Generated for commit c0c8a23.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/cli/index.ts`:
- Around line 418-424: Update the home-directory comparison in the
shouldPromptDocsSetup configuration to normalize both repoRoot and homedir()
with node:path resolve() before checking equality, while preserving the existing
atHome behavior on non-Windows platforms.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 34960e57-fd4d-4930-949f-f1b79fbfc6ac

📥 Commits

Reviewing files that changed from the base of the PR and between c01029a and a7b8c78.

📒 Files selected for processing (3)
  • src/cli/index.ts
  • src/docs/install-hint.ts
  • tests/shared/docs-install-hint.test.ts

Comment thread src/cli/index.ts

@coderabbitai coderabbitai 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.

Actionable comments posted: 3

🧹 Nitpick comments (2)
src/cli/index.ts (1)

423-432: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Redundant re-import of deriveProjectKey inside the nested onboard closure.

It's already imported and in scope at Line 407 for autoEnabled; the closure can reuse that binding instead of dynamically importing it again.

♻️ Proposed simplification
     onboard: async ({ root, orgId, orgName }) => {
       const { runDocsOnboarding } = await import("../docs/onboarding.js");
-      const { deriveProjectKey } = await import("../utils/repo-identity.js");
       const { loadCurrentSnapshot } = await import("../graph/load-current.js");
       return runDocsOnboarding({
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/cli/index.ts` around lines 423 - 432, Remove the nested dynamic import of
deriveProjectKey from the onboard closure and reuse the existing in-scope
binding already imported for autoEnabled. Keep the remaining onboarding imports
and project key derivation behavior unchanged.
src/docs/install-docs.ts (1)

8-10: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Docstring is stale: only mentions spawning docs wiki, not the second docs refresh --full worker.

Lines 91-93 now spawn both tiers detached (per PR objectives), but the file-level comment still describes only one.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/docs/install-docs.ts` around lines 8 - 10, Update the file-level
installation flow docstring to document both detached workers spawned after
consent: docs wiki and docs refresh --full. Keep the existing graph-building and
onboarding description, and ensure the comment reflects that LLM generation
remains non-blocking.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/docs/install-docs.ts`:
- Line 18: Resolve the stale isHomeRoot import in install-docs.ts by either
exporting a matching helper from install-hint.ts or replacing the import and its
usages with the existing intended home-directory check. Ensure the resulting
symbols compile and preserve the current documentation setup prompt behavior.

In `@tests/shared/install-docs.test.ts`:
- Line 121: Update the warning assertion in the install-docs test to compare
against the exact deterministic message “docs setup skipped: graph boom” instead
of using expect.stringContaining, while preserving the existing warn mock
verification.
- Around line 74-81: Update the “home-repo guard is slash-insensitive” test to
assert the deterministic POSIX result: expect action.kind to be "spawned" rather
than accepting both "hint" and "spawned". Keep the existing harness setup and
onboarding call unchanged.

---

Nitpick comments:
In `@src/cli/index.ts`:
- Around line 423-432: Remove the nested dynamic import of deriveProjectKey from
the onboard closure and reuse the existing in-scope binding already imported for
autoEnabled. Keep the remaining onboarding imports and project key derivation
behavior unchanged.

In `@src/docs/install-docs.ts`:
- Around line 8-10: Update the file-level installation flow docstring to
document both detached workers spawned after consent: docs wiki and docs refresh
--full. Keep the existing graph-building and onboarding description, and ensure
the comment reflects that LLM generation remains non-blocking.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 2f85f49a-4c47-424b-8777-67deec45ff7e

📥 Commits

Reviewing files that changed from the base of the PR and between a7b8c78 and 9ab9700.

📒 Files selected for processing (3)
  • src/cli/index.ts
  • src/docs/install-docs.ts
  • tests/shared/install-docs.test.ts

Comment thread src/docs/install-docs.ts
Comment thread tests/shared/install-docs.test.ts Outdated
Comment thread tests/shared/install-docs.test.ts Outdated
@efenocchi
efenocchi force-pushed the fix/docs-install-async branch from 9ab9700 to 6c9c791 Compare July 15, 2026 01:00

@coderabbitai coderabbitai 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.

♻️ Duplicate comments (1)
src/docs/install-docs.ts (1)

18-18: 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

Fix the stale isHomeRoot import.

The file imports isHomeRoot, but src/docs/install-hint.ts does not export it, which will cause a build failure. Either export the helper from install-hint.ts or replace this import and its usage with the intended home-directory check.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/docs/install-docs.ts` at line 18, Fix the stale isHomeRoot import in
install-docs.ts by either exporting isHomeRoot from install-hint.ts or replacing
the import and all usages with the intended home-directory check. Ensure the
resulting symbols match the actual exports and the build succeeds.

Source: Linters/SAST tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@src/docs/install-docs.ts`:
- Line 18: Fix the stale isHomeRoot import in install-docs.ts by either
exporting isHomeRoot from install-hint.ts or replacing the import and all usages
with the intended home-directory check. Ensure the resulting symbols match the
actual exports and the build succeeds.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 2455e782-bc9f-441a-a615-f0d5c32b4a71

📥 Commits

Reviewing files that changed from the base of the PR and between 9ab9700 and 6c9c791.

📒 Files selected for processing (3)
  • src/cli/index.ts
  • src/docs/install-docs.ts
  • tests/shared/install-docs.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/shared/install-docs.test.ts
  • src/cli/index.ts

@efenocchi
efenocchi force-pushed the fix/docs-install-async branch from 6c9c791 to 9e19a29 Compare July 15, 2026 01:07
Refinements on the install docs step (last pass guided by codex review):
- Skip the redundant "Generate docs?" prompt when auto-sync is already enabled;
  still run the graph build so its post-build auto-refresh fills an
  auto-enabled-but-EMPTY corpus (codex: a bare short-circuit never generates).
- On consent, spawn only `docs wiki` DETACHED — same as `hivemind graph init`.
  (An earlier attempt also spawned `docs refresh --full` for per-file docs, but
  codex correctly noted refresh only updates existing rows and never generates
  missing per-file docs — that's the heavy `docs generate`, left to auto-sync.)
All via the injected seams, unit-tested.
@efenocchi
efenocchi force-pushed the fix/docs-install-async branch from 9e19a29 to 5e62f8d Compare July 15, 2026 01:09

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (2)
src/docs/install-hint.ts (1)

39-48: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low value

Consider case-insensitive path comparison on Windows.

While path.resolve normalizes slashes and resolves .. segments, it does not normalize the casing of drive letters or directory names on Windows. Git tools (like MSYS2 or Git Bash) sometimes return paths with lowercase drive letters (e.g., c:/Users/x), while os.homedir() might return C:\Users\x. A strict === will fail to match these equivalent paths.

Consider comparing the paths case-insensitively on Windows, or at least normalizing the case before comparison.

♻️ Proposed refactor for case-insensitive comparison
 export function isHomeRoot(gitRoot: string, home: string): boolean {
-  return resolve(gitRoot) === resolve(home);
+  const resGit = resolve(gitRoot);
+  const resHome = resolve(home);
+  return process.platform === "win32"
+    ? resGit.toLowerCase() === resHome.toLowerCase()
+    : resGit === resHome;
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/docs/install-hint.ts` around lines 39 - 48, Update isHomeRoot to compare
resolved paths case-insensitively when running on Windows, while preserving the
existing case-sensitive comparison on other platforms. Normalize both
resolve(gitRoot) and resolve(home) consistently before equality checking.
src/cli/index.ts (1)

425-425: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Remove redundant import.

deriveProjectKey is already dynamically imported in the outer scope at line 407. You can safely remove this duplicate inner import.

♻️ Proposed refactor
-      const { deriveProjectKey } = await import("../utils/repo-identity.js");
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/cli/index.ts` at line 425, Remove the redundant inner dynamic import of
deriveProjectKey in the shown CLI flow, and reuse the existing outer-scope
import declared earlier. Keep the deriveProjectKey usage unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/cli/index.ts`:
- Line 425: Remove the redundant inner dynamic import of deriveProjectKey in the
shown CLI flow, and reuse the existing outer-scope import declared earlier. Keep
the deriveProjectKey usage unchanged.

In `@src/docs/install-hint.ts`:
- Around line 39-48: Update isHomeRoot to compare resolved paths
case-insensitively when running on Windows, while preserving the existing
case-sensitive comparison on other platforms. Normalize both resolve(gitRoot)
and resolve(home) consistently before equality checking.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 56d13eb2-3720-4891-ba8c-0bc37def6c84

📥 Commits

Reviewing files that changed from the base of the PR and between 6c9c791 and 9e19a29.

📒 Files selected for processing (5)
  • src/cli/index.ts
  • src/docs/install-docs.ts
  • src/docs/install-hint.ts
  • tests/shared/docs-install-hint.test.ts
  • tests/shared/install-docs.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/docs/install-docs.ts
  • tests/shared/install-docs.test.ts

@efenocchi
efenocchi merged commit f62a922 into main Jul 15, 2026
10 checks passed
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