PM Agent: opencode external_directory permission fails for subdirectory paths #36
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
PM Agent delegation fails with permission errors when trying to access any directory outside the session root, even with broad permission patterns.
Bug Description
When delegating tasks to the PM Agent (via kugetsu-helper delegate-to-pm), the agent attempts to clone/access /home/shoko/repositories/kugetsu and gets rejected with:
! permission requested: external_directory (/home/shoko/repositories/kugetsu/*); auto-rejecting
Error: The user rejected permission to use this specific tool call.
What We Tried
Set session directory to /home/shoko/repositories/kugetsu — still rejected
Set session directory to /home/shoko — still rejected
Tried permission patterns:
All were rejected
Told PM agent NOT to clone (repo already exists at /home/shoko/repositories/kugetsu) — still blocked because agent tries to do git operations
Root Cause
The opencode external_directory permission system appears to have a bug where it cannot match subdirectory paths. The session directory is set correctly but opencode treats all subdirectory access as external and the permission glob patterns do not match.
Session Details
Impact
PM Agent delegation is broken. All work must be done directly instead of via PM Agent.
Reproduction
Workaround
Do tasks directly (git checkout, add file, commit, push, create PR via API) instead of via PM Agent delegation.
Options Analysis
Option B — opencode allowlist flag
Add a session creation flag (e.g.,
external_directory: "allow") that bypasses glob pattern matching for external directory access.Option C — kugetsu workaround
kugetsu init sets session workdir to a directory that covers all needed paths (e.g.,
/home/shoko), OR kugetsu pre-clones repos into the session workdir before delegating./opt,/root), it failsRecommendation
Option B in opencode + Option C in kugetsu as a fallback.
/home/shokoso most common paths are covered, or document that PM agent tasks must stay within the workdirImmediate Workaround (Option C in practice)
PoC Confirmation
Bug confirmed. Tested patterns
*,/tmp/*,/tmp/**,/tmp/perm-test/*— all stored correctly in SQLite but still auto-rejected by opencode. The workdir-relative operations work fine.New Bug: PM trying to access /tmp/kugetsu/* instead of ~/.kugetsu/
When delegating "Merge PR #55" to PM, PM session tried to access:
But kugetsu stores data at ~/.kugetsu/, not /tmp/kugetsu/.
PM should use ~/.kugetsu/ for all operations. This might be:
Questions:
Need investigation.
Fix Found
The PM agent session in SQLite has
permission: NULL- no permissions stored at all. Adding external_directory permission via SQLite update fixes the issue.Verified working: PM agent can now access /home/shoko/repositories/kugetsu/*
Root Cause
The PM agent session was created without proper permissions - the permission column was NULL instead of containing the permission JSON array.
Recommendation
Update kugetsu to ensure new PM agents get proper permissions when created. The base session should also be updated with external_directory permission so new forks inherit it.