feat(agents): implement blit agents sync --check drift detection#14
Conversation
Replace the agents stub with a real sync --check command. Reads .blit/manifest.json, SHA-256s every kit-owned and shared file on disk, and reports any that differ from the seeded hash or are missing. Exits non-zero on drift, making it safe for CI use. Also integrates the drift check into `blit doctor` (appended as the last health check, no change to doctor's exit code) and updates the help text in cli.ts to remove the "coming soon" note. Two new end-to-end tests cover the clean (exit 0) and drifted (exit 1, file named in output) cases. Assisted-by: Claude Sonnet 4.6 Signed-off-by: Vaclav Vancura <commit@vancura.dev>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughAdds a manifest-driven SHA-256 drift checker (checkSyncDrift), wires it into ChangesSync Drift Detection Feature
Sequence DiagramsequenceDiagram
participant User
participant CLI
participant runAgents
participant checkSyncDrift
participant FileSystem
participant Process
User->>CLI: blit agents sync --check
CLI->>runAgents: sync --check
runAgents->>runAgents: locate project root
runAgents->>checkSyncDrift: checkSyncDrift(root, out)
checkSyncDrift->>FileSystem: read .blit/manifest.json
checkSyncDrift->>FileSystem: read tracked files
checkSyncDrift->>checkSyncDrift: compare SHA-256 hashes
alt Drift detected
checkSyncDrift->>User: report drifted files
runAgents->>Process: set exitCode = 1
else No drift
checkSyncDrift->>User: report "up to date"
end
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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 `@packages/kit/src/commands/agents.ts`:
- Around line 61-71: The code assumes manifest.files is an array and calls
manifest.files.filter; validate the manifest shape after parsing by checking
that manifest && Array.isArray(manifest.files) before using it (the variable
manifest and the subsequent tracked assignment), and if the check fails call
out(ui.error(...)) with a clear message about an invalid/damaged manifest and
return 1 so the command exits gracefully; update the logic that defines tracked
to only run when the check passes (or set tracked = [] when absent) and ensure
downstream code that uses missing/ tracked behaves correctly.
- Around line 75-77: The loop over tracked entries uses join(root, entry.path)
which allows absolute paths or “..” segments to escape the project root; update
the code around join(root, entry.path) (the absPath calculation) to first reject
or normalize unsafe entry.path values: if path.isAbsolute(entry.path) or
path.normalize(entry.path).startsWith('..' + path.sep) then skip or error,
otherwise compute const absPath = path.resolve(root, entry.path) and verify
absPath === root || absPath.startsWith(root + path.sep) before using it; this
ensures manifest paths cannot point outside the repo and prevents hashing
arbitrary files.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 601667b7-395f-4c80-8b4d-57ecfbaa7191
📒 Files selected for processing (4)
packages/create-blit-tech/test/scaffold.test.mjspackages/kit/src/cli.tspackages/kit/src/commands/agents.tspackages/kit/src/commands/doctor.ts
Add an Array.isArray(manifest.files) check after JSON.parse so a damaged or schema-mismatched manifest exits with a clear error instead of throwing at .filter(). Add a path traversal guard to the entry loop: reject absolute paths and ".." escape sequences before computing absPath, use path.resolve() instead of path.join(), and verify the resolved path is contained within the project root. Unsafe entries are skipped with a warning rather than silently hashed. Assisted-by: Claude Sonnet 4.6 Signed-off-by: Vaclav Vancura <commit@vancura.dev>
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
Replace the agents stub with a real sync --check command. Reads .blit/manifest.json, SHA-256s every kit-owned and shared file on disk, and reports any that differ from the seeded hash or are missing. Exits non-zero on drift, making it safe for CI use.
Also integrates the drift check into
blit doctor(appended as the last health check, no change to doctor's exit code) and updates the help text in cli.ts to remove the "coming soon" note.Two new end-to-end tests cover the clean (exit 0) and drifted (exit 1, file named in output) cases.
Overview
This pull request implements the
blit agents sync --checkcommand for drift detection, replacing the previous stub with a real manifest-driven implementation. The command reads.blit/manifest.json, computes SHA-256 hashes for kit-owned and shared files on disk, reports missing or changed files, and is suitable for CI because it sets a non-zero exit code when drift is detected. The drift check is also integrated intoblit doctoras the final health check (no change to doctor's overall exit code).Changes
Core Implementation (
packages/kit/src/commands/agents.ts)checkSyncDrift(root: string, out: (line: string) => void): numberwhich:.blit/manifest.json.kit-ownedandsharedentries.runAgents()to:sync --check.process.exitCode = 1when drift is detected.--checksyncandaddbehavior as informational/coming-soon messages.CLI Updates (
packages/kit/src/cli.ts)agentscommand to "Manage AI-assistant files (sync, add)", removing the "coming soon" note.Doctor Integration (
packages/kit/src/commands/doctor.ts)checkSyncDrift()and prints results as the last doctor health check without changing the doctor's exit behavior.Tests (
packages/create-blit-tech/test/scaffold.test.mjs)blit agents sync --check:Exit Behavior