Repository navigation
fix(discord): thread workspaceDir into native slash-command reply media - #348
Conversation
Discord's native slash-command reply family (direct /status replies, direct plugin-command replies, and agent-reply dispatch) built outbound media access with the roots-only getAgentScopedMediaLocalRoots helper instead of the complete resolveAgentScopedOutboundMediaAccess, so workspaceDir never reached the terminal loadWebMedia call. A relative attachment path from the message tool resolved against the gateway process cwd instead of the agent workspace and was rejected by the allowed-directory check even though the workspace is an allowed root. Mirrors ENG-21421 / PR #299 (8384739), which fixed the same bug class everywhere except this one surface, which it explicitly deferred. - native-command.ts: swap getAgentScopedMediaLocalRoots for resolveAgentScopedOutboundMediaAccess; thread the result into the direct-status, direct-plugin-command, and agent-reply dispatch branches (the plugin-command branch had no media access threading at all before this change, same as the other fixed channels originally lacked). - native-command-status.ts, native-command-agent-reply.ts: param swap from mediaLocalRoots: readonly string[] to mediaAccess: OutboundMediaAccess. - native-command-reply.ts: deliverDiscordInteractionReply's terminal loadWebMedia call now builds options via buildOutboundMediaLoadOptions with the full mediaAccess, instead of forwarding only localRoots. Tests: mock-based mediaAccess-forwarding assertions for all three branches, plus a real-filesystem test proving a relative in-workspace path resolves and an outside-workspace path is still rejected. Verified: scoped Vitest (extension-discord project) on the four touched source files' test files, 37/37 passing; full discord extension suite, same 78 pre-existing failures as before this change (local Node 24.13.1 vs required 24.15+ SQLite WAL-safety guard, unrelated to this diff); tsgo:extensions and tsgo:extensions:test both clean; oxfmt/oxlint clean on touched files. Blacksmith Testbox warmup failed in this environment (blacksmith binary not on $PATH) so remote CI proof did not run here. Fixes ENG-21758. Co-Authored-By: Claude Sonnet 5 <[email protected]>
There was a problem hiding this comment.
All reported issues were addressed across 7 files
Heads up: you’re close to your included review allowance. Set a flex budget so reviews don’t pause.
Tip: Get a Slack DM when cubic finishes reviewing your PRs. Connect Slack
View guided diff | Turn on auto-fix | Re-trigger cubic
cubic-dev-ai flagged two test comments citing the ENG-21758 ticket ID and PR-specific history, which don't belong in source per repo policy (no Linear ticket references in code/comments/commit messages). Both replaced with the technical rationale alone. Addresses PR review feedback on #348. Co-Authored-By: Claude Sonnet 5 <[email protected]>
There was a problem hiding this comment.
Summary
Threads OutboundMediaAccess (via resolveAgentScopedOutboundMediaAccess) into Discord native slash-command handling instead of using getAgentScopedMediaLocalRoots. This supplies mediaAccess across all three reply branches: direct plugin-command execution, direct /status replies, and agent-reply dispatch. deliverDiscordInteractionReply now uses buildOutboundMediaLoadOptions to pass workspaceDir, localRoots, and readFile into loadWebMedia.
Relative local media paths attached in slash-command replies resolve against workspaceDir instead of falling back to gateway cwd. The allowed-root boundaries remain enforced.
Key Findings
- Correctness: Covers all three native slash-command reply branches, including the direct plugin-command branch which previously lacked media access threading.
- Boundary Safety: Relative path resolution occurs against
workspaceDir, whileassertLocalMediaAllowedcontinues to reject paths outside the allowed roots. - Test Coverage: Verified with targeted tests across all three dispatch branches plus a real-filesystem test covering in-workspace and outside-workspace path resolution.
Local and CI Verification
- Targeted Vitest: 3 files, 37/37 tests passed (
native-command-reply.test.ts,native-command.plugin-dispatch.test.ts,native-command.status-direct.test.ts). - Lint & Format:
oxlintandoxfmt --checkpassed cleanly across all 7 touched files. - Typecheck:
pnpm tsgo:extensionsandpnpm tsgo:extensions:testpassed cleanly. - CI:
ci-gateand all 30 check runs completed with success on commitef866f7af906c66dcbdd35efb0984e3f32d84161. - Commits: Both commits are GPG-signed and cryptographically verified.
Verdict: APPROVE (ready-to-release)
Closes ENG-21758
What Problem This Solves
Fixes an issue where a Discord slash-command reply containing a relative local attachment path (e.g. one the message tool produced) would fail with "Local media path is not under an allowed directory" even though the agent's workspace is an allowed root. This affected
/statusdirect replies, direct plugin-command replies, and agent-reply dispatch — the three reply branches reachable from Discord's native slash-command handler.Why This Change Was Made
loadWebMediaonly resolves a relative local media path against the agent workspace whenworkspaceDirreaches it alongside the allowed roots. Discord's native slash-command reply family built its media access using the roots-onlygetAgentScopedMediaLocalRootshelper instead of the completeresolveAgentScopedOutboundMediaAccess, soworkspaceDirnever reached the terminalloadWebMediacall; a relative path resolved against the gateway process cwd instead.This mirrors ENG-21421 / #299 (
83847399af6), which fixed the identical bug class across telegram, msteams, imessage, whatsapp, mattermost, the gateway, and Discord's other reply paths, but explicitly deferred this one surface. While implementing, an independent review pass also found that Discord's direct plugin-command reply branch (e.g./pair) had never threaded any media access at all, even before this change — the same bug class, in the same function, so it's fixed here too rather than filed as a separate follow-up.The fix threads
OutboundMediaAccess(roots +workspaceDir+ policy-gated host reader) end to end instead of the roots-only shape, matching the already-established pattern inextensions/discord/src/send.shared.tsand the other channels ENG-21421 fixed. No new code path or compat shim was added.User Impact
Discord slash-command replies (status, plugin commands, and agent replies) that attach a relative local file path now resolve it against the agent's workspace, instead of failing with a false "not under an allowed directory" error. Absolute paths were already unaffected. The allowed-directory check itself is unchanged — paths outside the workspace are still rejected.
Evidence
native-command-reply.test.ts: a mock-based assertion that the fullmediaAccess(roots,workspaceDir,readFile) reaches the terminalloadWebMediacall, plus a real-filesystem test (mkdtemp + realpath) proving a relative in-workspace path loads and an outside-workspace path is still rejected.native-command.status-direct.test.ts: assertsworkspaceDirreachesloadWebMediathrough the direct/statusbranch.native-command.plugin-dispatch.test.ts: assertsworkspaceDirreachesloadWebMediathrough both the direct plugin-command branch and the agent-reply dispatcher branch.vitest.extension-discord.config.ts) on the three touched test files: 37/37 passing.tsgo:extensionsandtsgo:extensions:test: both clean.oxfmt --check/run-oxlint.mjs: clean on all touched files.blacksmithbinary not on$PATH), so remote CI proof did not run there; this PR's own CI run is the first remote proof.Summary by cubic
Fixes Discord slash-command replies so relative local attachment paths (like ones the message tool produces) resolve against the agent workspace instead of failing with a false "Local media path is not under an allowed directory" error.
The reply family (direct
/statusreplies, direct plugin-command replies, and agent-reply dispatch) built media access with a roots-only helper, soworkspaceDirnever reached the terminalloadWebMediacall. The fix threads the fullOutboundMediaAccessend to end, matching the pattern used by other channels (ENG-21421). It also fixes the direct plugin-command reply branch, which had no media access threading at all.Written for commit ef866f7. Summary will update on new commits.