Skip to content

feat: allow session permission updates#22070

Merged
rekram1-node merged 7 commits intoanomalyco:devfrom
remorses:fix-session-update-permission
Apr 11, 2026
Merged

feat: allow session permission updates#22070
rekram1-node merged 7 commits intoanomalyco:devfrom
remorses:fix-session-update-permission

Conversation

@remorses
Copy link
Copy Markdown
Contributor

@remorses remorses commented Apr 11, 2026

Issue for this PR

Closes #15116
Closes #15118

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

PATCH /session/{sessionID} now accepts permission and merges the new rules into the existing session ruleset.

This makes session permission updates possible without replacing previously stored rules.

How did you verify your code works?

  • bun test test/permission/next.test.ts
  • bun run typecheck in packages/opencode
  • bun run typecheck in packages/sdk/js
  • Started a local server with pnpm dev serve --hostname 127.0.0.1 --port 4097
  • Created a blank session, then confirmed pnpm dev run --attach http://127.0.0.1:4097 --session <id> -m anthropic/claude-sonnet-4-20250514 'Read /Users/morse/.zshrc and tell me only how many lines it has. Do not quote or summarize the file contents.' failed with permission requested: external_directory (/Users/morse/*); auto-rejecting
  • Patched that same session with permission: [{ permission: \"external_directory\", pattern: \"/Users/morse/*\", action: \"allow\" }, { permission: \"read\", pattern: \"/Users/morse/.zshrc\", action: \"allow\" }]
  • Re-ran the same pnpm dev run --attach ... --session ... command and confirmed it succeeded by reading /Users/morse/.zshrc and returning the line count

Screenshots / recordings

N/A - no UI changes

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Expose `permission` on `PATCH /session/:sessionID` and normalize API-provided rulesets before storing them.

This keeps session create and update behavior aligned, so `~/` and `$HOME` patterns sent through the API are expanded the same way config-based permissions already are.

- export `Permission.expandRuleset()` for API ruleset normalization
- expand permission rules on session create and update routes
- expose `Session.setPermission()` through the public session helpers
- regenerate the v2 SDK so update requests accept `permission`
- add focused permission expansion tests
@github-actions
Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on my search results, I found a potentially related PR:

Related PR:

This PR #15118 may be a predecessor or related attempt to implement similar functionality. You may want to check if it was closed or merged, and if there are any insights from that PR that could inform the current implementation.

Preserve existing session permission rules when `PATCH /session/:sessionID` receives additional rules.

This keeps API updates additive instead of replacing the stored ruleset, while still normalizing `~/` and `$HOME` patterns before they are persisted.
Drop the extra permission normalization work from this branch and keep the change focused on session updates.

The remaining behavior change is limited to allowing `PATCH /session/:sessionID` to accept `permission` and merge the new rules into the existing session ruleset.
Simplify the session update route by always loading the current session up front.

This keeps the permission merge path straightforward and avoids the extra conditional state handling around `Session.get()`.
EOF && git push
Add a Bun script that starts the local server, updates a session through the HTTP route, and verifies an attached `opencode run` can read an external file after the permission patch.

The script uses a local fake OpenAI-compatible server so the full serve -> session.update -> run flow can be exercised without external credentials.
EOF && git push
Drop the temporary Bun script used to validate the route manually.

Keep the branch focused on the session permission update itself without carrying the extra verification script.
EOF && git push
@remorses remorses marked this pull request as ready for review April 11, 2026 20:12
@rekram1-node
Copy link
Copy Markdown
Collaborator

/review

@github-actions
Copy link
Copy Markdown
Contributor

lgtm

@rekram1-node rekram1-node changed the title fix(opencode): allow session permission updates feat: allow session permission updates Apr 11, 2026
@rekram1-node rekram1-node merged commit d62ec77 into anomalyco:dev Apr 11, 2026
10 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Allow updating session permissions

2 participants