Skip to content

bug(citation-manager): path duplication in extractFile causes file not found errors #62

@WesleyMFrederick

Description

@WesleyMFrederick

Problem

The citation-manager extract file command fails with "File not found" errors even when the file exists. The validator attempts to find the file in a duplicated path (e.g., .claude/agents/.claude/agents/component-expert.md instead of .claude/agents/component-expert.md).

Reproduction Steps

  1. Run command from repo root:
citation-manager extract file .claude/agents/component-expert.md
  1. Observe error output:
Validation failed: File not found: .claude/agents/component-expert.md
Suggestion: File "component-expert.md" not found in scope folder. Source via symlink: .claude/agents/component-expert.md → /Users/wesleyfrederick/Documents/ObsidianVault/0_SoftwareDevelopment/cc-workflows/.claude/agents/component-expert.md; Tried: /Users/wesleyfrederick/Documents/ObsidianVault/0_SoftwareDevelopment/cc-workflows/.claude/agents/.claude/agents/component-expert.md
  1. Note the duplicated path component in "Tried:" section

Root Cause

In tools/citation-manager/src/citation-manager.ts at lines 599-602, the extractFile() method passes targetFile as both the link target AND the sourceFile parameter to validateSingleCitation():

const enrichedLink = await this.validator.validateSingleCitation(
  syntheticLink,
  targetFile,  // ❌ BUG: targetFile used as sourceFile parameter
);

The validator's path resolution logic uses sourceFile to construct the base path for resolving relative links. When sourceFile is set to the target file path itself, it creates path duplication:

  • sourceFile = ".claude/agents/component-expert.md"
  • dirname(sourceFile) = ".claude/agents"
  • Final attempted path = .claude/agents/.claude/agents/component-expert.md

Expected Behavior

  • extractFile() should pass the actual source file context (or working directory) as sourceFile
  • Validator should resolve the target file path correctly without duplication
  • Command should successfully extract file content when file exists

Related

Note

The bug only manifests in extractFile() command path. The validate command works correctly because it passes the actual source markdown file being validated. This is a parameter passing bug specific to the file extraction workflow.


Acceptance Criteria

  • citation-manager extract file .claude/agents/component-expert.md succeeds without path duplication
  • extractFile() passes correct sourceFile context to validateSingleCitation()
  • Error messages show correct attempted paths (no duplication)
  • Command works for files in nested directories (e.g., tools/citation-manager/README.md)
  • Command works for symlinked files

Definition of Done

  • Failing test written: extractFile() with nested path file (RED phase)
  • Fix implemented: correct sourceFile parameter passed to validator (GREEN phase)
  • All existing citation-manager tests pass
  • Build succeeds: npm run build -w tools/citation-manager && npm link -w tools/citation-manager
  • Manual verification: both test commands above execute successfully
  • Committed with conventional commit message referencing this issue

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions