[Bug] `isDirectoryTrusted` docstring claims the TUI shares it, but `useDirectoryTrust` still has its own copy of the check
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'srunPlainShell, 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
- Have
checkTrustSyncandhandleConfirmTrustcallisDirectoryTrustedfor the check.useDirectoryTrustis the only caller that also persists trust, so only the write side stays local. - While in the area, two nc-review nits from #1259 that were never picked up:
source/daemon/cli.spec.ts:215asserts(loadPreferences().trustedDirectories ?? []).includes(root). Comparing againstpath.resolve(root)instead would survive a future hardening of the check.source/cli.tsx:422warns that--trust-directory"only applies to non-interactive mode (nanocoder run ...)", which is now stale:daemon startaccepts 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
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
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!
Hey @puri-adityakumar..
No worries at all,
thanks for flagging it and stepping back.
Appreciate you double-checking before it turned into overlapping PRs : )