Skip to content

fix(annotate): support @ markdown file references - #488

Merged
backnotprop merged 1 commit into
backnotprop:mainfrom
Exloz:main
Apr 6, 2026
Merged

backnotprop merged 1 commit into
backnotprop:mainfrom
Exloz:main

Conversation

@Exloz

@Exloz Exloz commented Apr 5, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fixes markdown path resolution for annotate when the input uses OpenCode-style file references like @file.md.
  • Adds a safe fallback in the shared resolver: try the original input first, and only if it is not_found, retry after stripping leading @.

Problem

In OpenCode, /plannotator-annotate README.md worked, but /plannotator-annotate @README.md failed to open annotate mode for the file.
The shared resolver treated @README.md as a literal filename and returned not_found when only README.md existed.

Root Cause

resolveMarkdownFile in packages/shared/resolve-file.ts did not support @-prefixed file reference syntax.

Changes

  • Refactored current resolution logic into an internal core function (resolveMarkdownFileCore).
  • Kept resolveMarkdownFile as a wrapper that now:
    • trims input
    • accepts wrapped quotes ("..." / '...')
    • runs primary resolution using the original normalized input
    • if primary result is not_found and input starts with @, retries with leading @ removed
    • preserves the original user input in not_found/ambiguous responses for clearer logs/errors

Why this is safe

  • If a real file named @spec.md (or similar) exists, it is found by the primary lookup and returned directly.
  • @ normalization is only applied after the primary lookup fails.
  • Existing non-@ behavior remains unchanged.
  • The fix lives in shared resolver logic, so it is consistent across surfaces that reuse it (annotate + /api/doc paths).

Tests

Added coverage in packages/server/resolve-file.test.ts:

  • resolves @README.md via fallback when @README.md does not exist
  • prioritizes real @README.md when it exists
  • resolves quoted input "@README.md"
  • returns not_found for @nope.md
  • returns ambiguous for fallback case like @plan.md with multiple plan.md matches

Validation run:

  • bun test packages/server/resolve-file.test.ts (pass)

Scope

  • packages/shared/resolve-file.ts
  • packages/server/resolve-file.test.ts

No command template changes were required.

OpenCode can pass annotate targets as @file references, so resolve markdown paths with an @ fallback only after the primary lookup misses. This preserves real @-prefixed filenames while making @README.md and quoted @ inputs resolve reliably.
@backnotprop
backnotprop merged commit 70b0cfb into backnotprop:main Apr 6, 2026
5 checks passed
backnotprop added a commit that referenced this pull request Apr 23, 2026
parseAnnotateArgs now returns rawFilePath alongside the stripped
filePath so dispatch code can fall back to the literal form when
the stripped form doesn't resolve — the node_modules / scoped-
package case (e.g. @plannotator/ui/README.md).

Wired in every dispatch site:

  apps/hook/server/index.ts          (binary: folder, HTML, markdown)
  apps/opencode-plugin/commands.ts   (OpenCode plugin: HTML, markdown)
  apps/pi-extension/index.ts         (Pi extension: all three)

Folder and HTML branches use resolveAtReference(rawFilePath, existsSync-
style predicate). Markdown branches use a small inline fallback against
resolveMarkdownFile since that resolver has its own fuzzy-match and
ambiguous-case handling we want to preserve.

Reference-mode priority (strip wins when both exist) is preserved end-
to-end — the helper tries stripped first on every call. #488's existing
resolver tests pass unchanged. Full suite: 702/702.

For provenance purposes, this commit was AI assisted.
backnotprop added a commit that referenced this pull request Apr 23, 2026
parseAnnotateArgs now returns rawFilePath alongside the stripped
filePath so dispatch code can fall back to the literal form when
the stripped form doesn't resolve — the node_modules / scoped-
package case (e.g. @plannotator/ui/README.md).

Wired in every dispatch site:

  apps/hook/server/index.ts          (binary: folder, HTML, markdown)
  apps/opencode-plugin/commands.ts   (OpenCode plugin: HTML, markdown)
  apps/pi-extension/index.ts         (Pi extension: all three)

Folder and HTML branches use resolveAtReference(rawFilePath, existsSync-
style predicate). Markdown branches use a small inline fallback against
resolveMarkdownFile since that resolver has its own fuzzy-match and
ambiguous-case handling we want to preserve.

Reference-mode priority (strip wins when both exist) is preserved end-
to-end — the helper tries stripped first on every call. #488's existing
resolver tests pass unchanged. Full suite: 702/702.

For provenance purposes, this commit was AI assisted.
@backnotprop

Copy link
Copy Markdown
Owner

@Exloz

We're building Plannotator Workspaces, where agent plans, specs, and reviews can be collaborated on and distilled into standards and rules. Your annotations and reviews compound into a golden ruleset planning and review agents can use, and CI/CD can verify against.

Joining the waitlist gets you lifetime free access as an early contributor. https://plannotator.ai/workspaces/. Check the OSS contributor box.

The OSS core isn't changing: same free and open source plugin, always.

Thanks for #488.

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