nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] `isDirectoryTrusted` docstring claims the TUI shares it, but `useDirectoryTrust` still has its own copy of the check

Open addyCooks opened this issue 2 months ago • 3 comments

Description

Follow-up to #1259 (raised by @will-lamerton in review and by nc-review).

isDirectoryTrusted in source/config/preferences.ts is documented as:

Shared by every trust-gated entry point, the interactive TUI's useDirectoryTrust, --plain's runPlainShell, and the daemon boot path, so the resolution rule can't drift between them.

That holds for runPlainShell and the daemon, but not for the TUI. source/hooks/useDirectoryTrust.tsx still has its own inline path.resolve and trustedDirectories.some(...) comparison in two places:

  • checkTrustSync (lines 26-29)
  • handleConfirmTrust (lines 66-78)

The whole point of extracting the helper was to keep the resolution rule in one place. As it stands, anyone who hardens isDirectoryTrusted, case-insensitive matching on Windows, say, or realpath comparison to defeat symlink tricks, will leave the interactive path on the old rule without any signal that they have.

Expected Behavior

Every trust-gated entry point resolves trust through one function, and the docstring is accurate.

Actual Behavior

Two implementations of the same rule, and a docstring asserting there is one.

Proposed Fix

  1. Have checkTrustSync and handleConfirmTrust call isDirectoryTrusted for the check. useDirectoryTrust is the only caller that also persists trust, so only the write side stays local.
  2. While in the area, two nc-review nits from #1259 that were never picked up:
    • source/daemon/cli.spec.ts:215 asserts (loadPreferences().trustedDirectories ?? []).includes(root). Comparing against path.resolve(root) instead would survive a future hardening of the check.
    • source/cli.tsx:422 warns that --trust-directory "only applies to non-interactive mode (nanocoder run ...)", which is now stale: daemon start accepts it too. The daemon fast path exits before this line, so it never misfires today, but it will mislead whoever reads it next.

Additional Context

  • Review thread: #1259
  • Original bug: #1245

addyCooks avatar Sep 16 '26 06:09 addyCooks

Hey @will-lamerton, this is the other follow-up from your review on #1259 the isDirectoryTrusted docstring you flagged happy to take this one too if you assign it to me. cc @akramcodez

addyCooks avatar Sep 16 '26 06:09 addyCooks

Hi @addyCooks! While prototyping #1287, I accidentally carried an unrelated local implementation of #1339 into a now-closed draft PR. I later noticed that #1339 is assigned to you and already covered by this PR. The trust change is not required for my /review work, so I’ll exclude it from all replacement PRs and won’t pursue it separately. Sorry for the confusion!

puri-adityakumar avatar Sep 23 '26 11:09 puri-adityakumar

Hey @puri-adityakumar..
No worries at all, thanks for flagging it and stepping back. Appreciate you double-checking before it turned into overlapping PRs : )

addyCooks avatar Sep 23 '26 11:09 addyCooks