feat: add gbrain relink — rebuild DB link graph from markdown#117
Closed
EagleEyez1 wants to merge 2 commits intogarrytan:masterfrom
Closed
feat: add gbrain relink — rebuild DB link graph from markdown#117EagleEyez1 wants to merge 2 commits intogarrytan:masterfrom
EagleEyez1 wants to merge 2 commits intogarrytan:masterfrom
Conversation
… links - New gbrain relink [--dir <brain-dir>] CLI command - extractInternalMarkdownLinks / resolveInternalMarkdownLink in core/markdown - reconcilePageLinks in core/import-file — syncs DB links to markdown links on every import, even for unchanged content - Body splitter now falls back to ## Timeline heading when delimiter is absent - Docs: cron-schedule.md and README.md updated to reference relink in weekly + dream-cycle flows - Tests: import-file and markdown test coverage for link extraction and reconciliation Work-in-progress local feature, preserved here before fast-forwarding master to origin/master. Rebase onto master once main checkout is updated.
Previously `gbrain relink --help` would try to relink because argument parsing didn't recognize --help as a help request and fell through to the normal execution path. Add an explicit short-circuit at the top of runRelink and document the command surface.
Author
|
Closing — the functionality this PR was adding is now fully covered by upstream:
No reason to carry a separate |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
gbrain relink [--dir <brain-dir>] [--dry-run]: walks every syncable markdown file under<brain-dir>and reconciles the Postgreslinkstable against what the markdown actually says. Fixes the drift case where edits add or remove links without changing the page content hash (sync skips those pages, DB never sees the new links).reconcilePageLinksintoimportFromContentso fresh imports stay consistent without a separate pass. Covers both code paths: the hash-match skip branch and the main import branch.## Timelineheading insplitBodywhen the serialized---delimiter is missing. Pages written by hand now split correctly intocompiled_truthandtimelineinstead of dumping everything intocompiled_truth.--help/-hongbrain relink. No other command does this today — happy to drop that commit and match the existing convention, or split it into a follow-up PR that standardizes help across commands. Your call.0.9.4and document the change inCHANGELOG.md.Test Coverage
Tests: 716 → 722 (+6 new tests across 2 existing files)
Pre-Landing Review
bun teston a fresh clone: 596 pass / 0 fail / 126 skip.reconcilePageLinksis called insideengine.transaction(...)in both code paths, so a mid-reconcile crash cannot leak partial link state.addLinkerrors are logged viaconsole.warnand swallowed. This matches the soft-warning pattern for dangling link targets (common in real brains mid-sync). Real infrastructure failures would still bubble up via the enclosing transaction rollback.gbrain relink --dry-run --dir ~/brainreports4236 syncable markdown file(s)on a real 4755-page brain without mutating state.gbrain relink --dir ~/brain(live) reconciles the full brain with per-slug warnings only for unresolved targets;gbrain doctor --jsonreports healthy afterward.Design Review
No frontend files changed — design review skipped.
Eval Results
No prompt-related files changed — evals skipped.
TODOS
No TODO items completed in this PR.
Test plan
bun test test/markdown.test.ts— 19 pass, 0 failbun test test/import-file.test.ts— 18 pass, 0 failbun test— 596 pass, 0 fail, 126 skipgbrain relink --help— prints usage, does not executegbrain relink -h— samegbrain relink --dry-run --dir ~/brain— reports file count, no writesgbrain relink --dir ~/brain— reconciles on a 4755-page brain, warns only on unresolved targetsgbrain doctor --json— returns healthy after a live relink runDATABASE_URLnot set in this environment.Documentation
CHANGELOG.md: added the0.9.4release note.VERSIONandpackage.json: bumped to0.9.4.README.md: addedgbrain relinkto the LINKS + GRAPH section.docs/guides/cron-schedule.md: referencedgbrain relinkin the weekly maintenance and dream-cycle flows.