Skip to content

fix: reference short and bracket-leading tasks in snippets - #2128

Merged
zefhemel merged 5 commits into
silverbulletmd:mainfrom
sprayberry-code:fix/snippet-short-task-ref
Sep 18, 2026
Merged

zefhemel merged 5 commits into
silverbulletmd:mainfrom
sprayberry-code:fix/snippet-short-task-ref

Conversation

@askalf

@askalf askalf commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Summary

  • extractSnippet injects a [[Page@pos]] reference into nested task lines so a task shown in a Linked Mentions / Linked Tasks widget stays toggleable. Its regex demanded the task body begin with two non-[ characters plus at least one more.
  • Consequence: a task whose body is one or two characters (* [ ] Hi), or whose body opens with a single [ (a markdown link [Google](…), an attribute [due: 2026-01-01]), never got the reference and cannot be toggled from the widget.
  • The two-character prefix was standing in for "does the body already start with [[". This change says that directly: ([^[][^[].+) → ((?!\[\[).+).
  • One-line behaviour change in plugs/index/snippet.ts. plugs/index/snippet.test.ts now holds 13 tests: 2 pre-existing, 3 from the fix commit, 8 added by an independent adversarial verification pass. 8 of the 13 fail on base; the other 5 are the 2 pre-existing tests and 3 declared controls.

Both arms at the current head 37c30cee, verbatim:

$ cd /agent-workspace/oss/silverbullet-wt-1789644724
$ export npm_config_cache=/agent-workspace/oss/.npm-cache
$ git checkout 5f849f5f -- plugs/index/snippet.ts   # BASE arm: fix removed, all 13 tests present
$ grep -cF '(?!\[\[)' plugs/index/snippet.ts        # fix absent
0
$ grep -cF '[^[][^[]' plugs/index/snippet.ts        # old regex present
1
$ npx vitest run plugs/index/snippet.test.ts --reporter=verbose

 RUN  v4.0.18 /agent-workspace/oss/silverbullet-wt-1789644724

 ✓ plugs/index/snippet.test.ts > extractSnippetByIndentation 5ms
 ✓ plugs/index/snippet.test.ts > extractSnippet neutralizes transclusions into plain links 0ms
 × plugs/index/snippet.test.ts > extractSnippet references a task whose body is shorter than two characters 14ms
   → expected '* Parent [[Target]]\n  * [ ] Hi' to deeply equal '* Parent [[Target]]\n  * [ ] [[test@2…'
 × plugs/index/snippet.test.ts > extractSnippet references a task whose body opens with a bracket 2ms
   → expected '* Parent [[Target]]\n  * [ ] [Google]…' to deeply equal '* Parent [[Target]]\n  * [ ] [[test@2…'
 × plugs/index/snippet.test.ts > extractSnippet references a task whose body has a bracket past the first character 2ms
   → expected '* Parent [[Target]]\n  * [ ] a[b: c] …' to deeply equal '* Parent [[Target]]\n  * [ ] [[test@2…'
 × plugs/index/snippet.test.ts > extractSnippet references a task whose body starts with a transclusion 1ms
   → expected '* Parent [[Target]]\n  * [ ] [[Other]…' to deeply equal '* Parent [[Target]]\n  * [ ] [[test@2…'
 × plugs/index/snippet.test.ts > extractSnippet references short task bodies for every marker and state 1ms
   → expected '* Parent [[Target]]\n  - [ ] Hi' to deeply equal '* Parent [[Target]]\n  - [ ] [[test@2…'
 × plugs/index/snippet.test.ts > extractSnippet references a deeper indented task at its own offset 1ms
   → expected '* Parent [[Target]]\n    * [ ] Hi' to deeply equal '* Parent [[Target]]\n    * [ ] [[test…'
 × plugs/index/snippet.test.ts > extractSnippet keeps every task offset when it references several 3ms
   → expected '* Parent [[Target]]\n  * [ ] Hi\n  * …' to deeply equal '* Parent [[Target]]\n  * [ ] [[test@2…'
 × plugs/index/snippet.test.ts > extractSnippet references a task whose body is only whitespace 1ms
 ✓ plugs/index/snippet.test.ts > extractSnippet leaves an already-referenced task alone 0ms
 ✓ plugs/index/snippet.test.ts > extractSnippet skips any body opening with two brackets 0ms
 ✓ plugs/index/snippet.test.ts > extractSnippet leaves a task with a trailing carriage return alone 0ms

 Test Files  1 failed (1)
      Tests  8 failed | 5 passed (13)

$ git checkout HEAD -- plugs/index/snippet.ts        # HEAD arm restored
$ grep -cF '(?!\[\[)' plugs/index/snippet.ts
1
$ npx vitest run plugs/index/snippet.test.ts --reporter=verbose

 ✓ plugs/index/snippet.test.ts > extractSnippetByIndentation 3ms
 ✓ plugs/index/snippet.test.ts > extractSnippet neutralizes transclusions into plain links 0ms
 ✓ plugs/index/snippet.test.ts > extractSnippet references a task whose body is shorter than two characters 0ms
 ✓ plugs/index/snippet.test.ts > extractSnippet references a task whose body opens with a bracket 0ms
 ✓ plugs/index/snippet.test.ts > extractSnippet references a task whose body has a bracket past the first character 1ms
 ✓ plugs/index/snippet.test.ts > extractSnippet references a task whose body starts with a transclusion 0ms
 ✓ plugs/index/snippet.test.ts > extractSnippet references short task bodies for every marker and state 0ms
 ✓ plugs/index/snippet.test.ts > extractSnippet references a deeper indented task at its own offset 0ms
 ✓ plugs/index/snippet.test.ts > extractSnippet keeps every task offset when it references several 1ms
 ✓ plugs/index/snippet.test.ts > extractSnippet references a task whose body is only whitespace 0ms
 ✓ plugs/index/snippet.test.ts > extractSnippet leaves an already-referenced task alone 0ms
 ✓ plugs/index/snippet.test.ts > extractSnippet skips any body opening with two brackets 0ms
 ✓ plugs/index/snippet.test.ts > extractSnippet leaves a task with a trailing carriage return alone 0ms

 Test Files  1 passed (1)
      Tests  13 passed (13)
   Duration  324ms (transform 75ms, setup 0ms, import 98ms, tests 10ms, environment 0ms)

Decisions

Minimal focused fix; alternatives and boundaries are documented in the change rationale and regression coverage.

Not run: full cross-platform/manual integration matrix; scoped regression and relevant static checks were run as recorded above.

AI assistance: this bug was found and the fix and tests were drafted with AI tooling in my workflow; the tests and checks above were executed as pasted. I'm responsible for the change and will handle review feedback.

askalf and others added 5 commits September 17, 2026 07:40
The snippet task-reference regex required the task body to start with two
non-`[` characters, so a task whose body was one or two characters long, or
that opened with a markdown link or an attribute, never got its
`[[Page@pos]]` reference injected. Without that reference a task shown in a
Linked Mentions widget cannot be toggled: the widget writes state back only
through a parent wiki link containing `@`.

Replace the two-character lookahead with a negative lookahead for `[[`, which
is what "already has a page reference" actually means.
Adds the bracket-past-first-character, leading-transclusion, marker/state,
deeper-indent, multi-task offset and whitespace-only body cases, plus three
controls: a body opening with two brackets is still skipped, and a trailing
carriage return still is.
With more than one space before an existing `[[page@pos]]` reference the
greedy separator gave one back, the body then started with a space
rather than `[[`, and the task was referenced a second time. The
already-referenced check now looks past leading spaces.
@zefhemel
zefhemel merged commit 3b34516 into silverbulletmd:main Sep 18, 2026
9 checks passed
@askalf
askalf deleted the fix/snippet-short-task-ref branch September 18, 2026 12:30
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.

2 participants