feat(capture): ordered create-if-not-found location for reverse-chrono logs (#481)#1365
Conversation
When an insert-after target heading (e.g. "## {{DATE:YYYY-MM-DD}}") is missing,
the new "Ordered" create location inserts it at its sorted position among
same-level sibling headings instead of at the top/bottom of the note. Enables
reverse-chronological daily logs (newest day on top, newest entry under each
day), semver changelogs, year-grouped lists, etc. from one composable mechanism.
- New SectionOrdering (by: insertion/lexical/numeric/date/semver, direction,
dateFormat, unparseable) read only when createIfNotFoundLocation === "ordered".
- Pure, frontmatter- and fence-aware placement helper (orderedSectionPlacement.ts).
- Byte-preserving splice (existing line endings untouched; minimal diff).
- Idempotent: never duplicates a heading; later captures take the found-path.
- Builder UI: 4th create-location option + ordered sub-panel; inline is mutually
exclusive with ordered.
Closes #481
Add an 'Ordered section placement' subsection to the Capture choice docs: the daily-log (newest-first) recipe, the sort options (insertion/text/number/ date/semver x asc/desc), worked changelog and books-by-year examples, and the notes/limits (idempotent stable-token requirement, global same-level scoping, no re-sort of existing sections, mutually exclusive with inline).
|
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 (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughImplements an "Ordered" create-if-not-found placement mode for Capture choices. A new ChangesOrdered Section Placement Feature
Sequence Diagram(s)sequenceDiagram
participant User
participant InsertAfterFields as InsertAfterFields.svelte
participant CaptureChoiceEngine
participant CaptureChoiceFormatter
participant computeOrderedSectionInsertIndex
User->>InsertAfterFields: selects "Ordered" placement + sort config
InsertAfterFields->>InsertAfterFields: sets orderBy on insertAfter, forces inline=false
User->>CaptureChoiceEngine: triggers capture run()
CaptureChoiceEngine->>CaptureChoiceFormatter: formatContent(choice, fileContent)
CaptureChoiceFormatter->>CaptureChoiceFormatter: createInsertAfterOrdered: mask fenced headings, get bodyStart
CaptureChoiceFormatter->>computeOrderedSectionInsertIndex: lines, newHeaderFirstLine, level, SectionOrdering, moment
computeOrderedSectionInsertIndex-->>CaptureChoiceFormatter: OrderedSlot
CaptureChoiceFormatter->>CaptureChoiceFormatter: spliceOrderedSection (EOL-preserving)
CaptureChoiceFormatter->>CaptureChoiceFormatter: store lastResolvedInsertAfterHeading
CaptureChoiceFormatter-->>CaptureChoiceEngine: formatted content
CaptureChoiceEngine->>CaptureChoiceEngine: captureResolvedOrderedHeading() → resolvedInsertAfterHeading
CaptureChoiceEngine->>User: success notice with real heading name
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Poem
🚥 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)
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. Comment |
Deploying quickadd with
|
| Latest commit: |
8d18ee7
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://6a609e31.quickadd.pages.dev |
| Branch Preview URL: | https://chhoumann-481-reverse-chrono.quickadd.pages.dev |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fb84c07dbc
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
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/types/choices/CaptureChoice.ts`:
- Around line 159-175: The orderBy backfill is currently happening whenever
createIfNotFoundLocation is "ordered", even if the createIfNotFound feature is
disabled, which causes unnecessary mutations of inert configs. Add an additional
condition to check that loaded.createIfNotFound is true before backfilling the
orderBy property within the CREATE_IF_NOT_FOUND_ORDERED block. Keep the inline
safety normalization (loaded.insertAfter.inline = false;) unchanged, but gate
only the orderBy backfill logic behind both the createIfNotFound and
createIfNotFoundLocation checks.
🪄 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: 6259c380-5795-4200-8fb6-5e4535b40fe4
📒 Files selected for processing (11)
docs/docs/Choices/CaptureChoice.mdsrc/constants.tssrc/engine/CaptureChoiceEngine.tssrc/formatters/captureChoiceFormatter-481-ordered.test.tssrc/formatters/captureChoiceFormatter.tssrc/formatters/helpers/orderedSectionPlacement.test.tssrc/formatters/helpers/orderedSectionPlacement.tssrc/gui/ChoiceBuilder/components/InsertAfterFields.sveltesrc/types/choices/CaptureChoice.test.tssrc/types/choices/CaptureChoice.tssrc/types/choices/ICaptureChoice.ts
…e; gate orderBy backfill Address PR #1365 review feedback: - Ordered target search now ignores headings inside YAML frontmatter or fenced code blocks (Codex P2): a single-line target like "## 2026-06-16" that only appears in a ```markdown example or a frontmatter value no longer matches as "found" and gets the capture inserted there — it creates the real sorted section instead. Masking preserves line indices so the found-path math is intact. - CaptureChoice.Load only backfills orderBy when createIfNotFound is on, so an inert ordered config isn't mutated on load (CodeRabbit).
Summary
Adds a fourth "Create line if not found" location to Capture's Insert after — Ordered — that creates a missing target heading at its sorted position among same-level sibling headings, instead of only at the top/bottom/cursor.
This is the generic primitive behind the long-standing request in #481 ("combining multiple insert-afters"): a reverse-chronological daily log where a fixed title/intro stays pinned, each new day's
## YYYY-MM-DDheading is auto-created below the intro and above older days, and the newest entry sits at the top of each day. The same one mechanism also covers semver changelogs, year-grouped lists, alphabetical/numeric section logs, etc. via configuration.Closes #481.
How it works
When the insert-after heading (e.g.
## {{DATE:YYYY-MM-DD}}) is missing, the newOrderedlocation sorts it into place among its same-level siblings:SectionOrdering(by: insertion / lexical / numeric / date / semver,direction: asc/desc,dateFormat,unparseable) — read only whencreateIfNotFoundLocation === "ordered". Fully additive: no migration, no version bump; existing choices are byte-identical.orderedSectionPlacement.ts).Insert at end of sectiontoggle.Orderedis mutually exclusive withInline insertion.Requirement structure falls out of the design: the title/intro stays pinned because it's a different heading level (and frontmatter is excluded entirely); the day heading is the ordered create; within-day order is the existing
insertAtEnd.Example (#481)
Testing
tsc,svelte-check, andeslintclean; docs site builds.[1.10.0]bracket form, frontmatter-preserving captures, mixed/CRLF EOL preservation, and idempotent repeat captures.Review
Iterated through multiple review rounds (multi-lens + cross-model adversarial). Fixes that came out of review include: frontmatter-aware placement (prevented a YAML-corruption path), byte-preserving mixed-EOL/EOF splice, multi-line-anchor de-duplication (idempotency), fence-aware heading detection, builder reactivity that never clobbers a saved sort config, and the documented requirement that the capture format end in a newline.
Deferred (documented limitations)
scopeToParentis a future extension.Docs
New "Ordered section placement" subsection in
docs/docs/Choices/CaptureChoice.md(Next/unreleased) with the daily-log recipe, sort options, changelog & books-by-year examples, and the limits.Summary by CodeRabbit