fix: harden session-scoped permissions and remove root temp scope#25
Open
ideas24h wants to merge 7 commits into
Open
fix: harden session-scoped permissions and remove root temp scope#25ideas24h wants to merge 7 commits into
ideas24h wants to merge 7 commits into
Conversation
- isolate permission state by session/channel - keep Allow All restricted by shell blocklist and filesystem scoping - remove vestigial addRootTempScope contract/runtime path - align CLI/Telegram/manual/docs with the hardened model - add regression tests for permission mode and scheduled/system behavior
There was a problem hiding this comment.
Pull request overview
This PR hardens Mercury’s permission model by scoping “Allow All” and related permission state to the active session/channel, removing the previous “root temp scope” behavior, and aligning CLI/Telegram UX + docs/tests with the new model.
Changes:
- Introduce session/channel-scoped permission state in
PermissionManagerand plumb channel context into approval prompts. - Remove the implicit
addTempScope('/')behavior for “Allow All” and for system/scheduled runs, while keeping shell blocklist + filesystem scoping enforced. - Add regression tests plus sandbox smoke docs/scripts to validate the permission wiring and CLI streaming behavior.
Reviewed changes
Copilot reviewed 19 out of 20 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/utils/manual.ts | Updates user-facing manual text to reflect session/channel-scoped “Allow All” and restricted scoping. |
| src/index.ts | Wires permission prompting with context + applies session permission mode for CLI/Telegram sessions. |
| src/core/permission-mode.ts | Adds helper to apply permission mode scoped to a specific session/channel. |
| src/core/permission-mode.test.ts | Tests that applying “Allow All” does not grant filesystem root scope and stays channel-scoped. |
| src/core/agent.ts | Ensures per-message permission context is set via setCurrentChannel and system/scheduled auto-approval doesn’t imply root scope. |
| src/core/agent-permissions.test.ts | Adds tests for system/scheduled permission policy contract. |
| src/channels/telegram.ts | Updates Telegram permission mode copy to match the hardened model. |
| src/channels/telegram.test.ts | Verifies permission prompts are sent to the targeted Telegram chat. |
| src/channels/cli.ts | Adjusts CLI copy for permission modes and removes duplicate final streamed output behavior. |
| src/channels/cli.test.ts | Adds regression test ensuring streamed content isn’t printed twice in TTY mode. |
| src/capabilities/permissions.ts | Implements session/channel isolation (auto-approve, pending approvals, temp scopes) and passes context into ask handler. |
| src/capabilities/permissions.test.ts | Adds tests for session isolation + enforcement of blocklist/cwdOnly even under allow-all. |
| scripts/run_mercury_sandbox_smoke.sh | Adds a smoke runner script for sandbox verification. |
| scripts/mercury_sandbox_smoke.py | Adds a PTY/pexpect-based smoke test driver capturing transcripts and validating a minimal response. |
| docs/permissions-model.md | Documents the live session/channel permission model and supporting evidence/tests. |
| docs/mercury-sandbox-smoke.md | Documents how to run the sandbox smoke test. |
| README.md | Updates permission model description + adds a “Permission modes” section and links to detailed docs. |
| DECISIONS.md | Updates scheduler ADR to reflect system messages preserving source channel context. |
| CHANGELOG.md | Aligns changelog entries with restricted allow-all + scheduled task behavior. |
| .gitignore | Ignores additional generated dirs/files (e.g., tmp/ used by smoke transcripts). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+164
to
+166
| private askHandler?: (prompt: string, context: PermissionAskContext) => Promise<string>; | ||
| private readonly sessionStates: Map<string, SessionPermissionsState> = new Map(); | ||
| private currentChannelId = 'cli:default'; |
Comment on lines
+4
to
+7
| REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" | ||
| SANDBOX_HOME="${MERCURY_SANDBOX_HOME:-/home/raul/dev/mercury-test/sandbox/mercury-home}" | ||
| WORKSPACE="${MERCURY_SANDBOX_WORKSPACE:-/home/raul/dev/mercury-test/sandbox/workspace}" | ||
| TRANSCRIPTS_DIR="${MERCURY_SMOKE_TRANSCRIPTS_DIR:-$REPO_ROOT/tmp/mercury-smoke}" |
Comment on lines
+98
to
+101
| def parse_args() -> argparse.Namespace: | ||
| parser = argparse.ArgumentParser(description="Smoke test reproducible para Mercury sandbox (glm-5.1).") | ||
| parser.add_argument("--workspace", required=True, type=Path) | ||
| parser.add_argument("--mercury-home", required=True, type=Path) |
Comment on lines
+1
to
+4
| # Mercury sandbox smoke test | ||
|
|
||
| Smoke test reproducible para validar Mercury dentro del sandbox con `glm-5.1`, sin tocar la lógica del agente. | ||
|
|
Comment on lines
+20
to
+22
| - sandbox existente en: | ||
| - `MERCURY_SANDBOX_HOME=/home/raul/dev/mercury-test/sandbox/mercury-home` | ||
| - `MERCURY_SANDBOX_WORKSPACE=/home/raul/dev/mercury-test/sandbox/workspace` |
Author
|
Addressed the Copilot review items.
Verification run:
The full end-to-end smoke path is currently blocked by an external |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Test Plan