feat(tui): preselect suggested permission scope

Thread `suggestedScope` through the app-server permission approval
request and use it when constructing TUI approval requests. This
keeps the protocol backward compatible by defaulting the field to
`turn` when older clients omit it.

Add focused app-server and TUI coverage, plus a snapshot for the
session-suggested approval overlay so reviewers can see the
preselected session row.
This commit is contained in:
Felipe Coury
2026-04-13 13:15:18 -03:00
parent 097f431a88
commit bbf656dcf3
15 changed files with 171 additions and 9 deletions
@@ -39,6 +39,13 @@
},
"type": "object"
},
"PermissionGrantScope": {
"enum": [
"turn",
"session"
],
"type": "string"
},
"RequestPermissionProfile": {
"additionalProperties": false,
"properties": {
@@ -79,6 +86,14 @@
"null"
]
},
"suggestedScope": {
"allOf": [
{
"$ref": "#/definitions/PermissionGrantScope"
}
],
"default": "turn"
},
"threadId": {
"type": "string"
},
@@ -1344,6 +1344,13 @@
}
]
},
"PermissionGrantScope": {
"enum": [
"turn",
"session"
],
"type": "string"
},
"PermissionsRequestApprovalParams": {
"properties": {
"itemId": {
@@ -1358,6 +1365,14 @@
"null"
]
},
"suggestedScope": {
"allOf": [
{
"$ref": "#/definitions/PermissionGrantScope"
}
],
"default": "turn"
},
"threadId": {
"type": "string"
},
@@ -3285,6 +3285,14 @@
"null"
]
},
"suggestedScope": {
"allOf": [
{
"$ref": "#/definitions/PermissionGrantScope"
}
],
"default": "turn"
},
"threadId": {
"type": "string"
},
@@ -1,6 +1,7 @@
// GENERATED CODE! DO NOT MODIFY BY HAND!
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { PermissionGrantScope } from "./PermissionGrantScope";
import type { RequestPermissionProfile } from "./RequestPermissionProfile";
export type PermissionsRequestApprovalParams = { threadId: string, turnId: string, itemId: string, reason: string | null, permissions: RequestPermissionProfile, };
export type PermissionsRequestApprovalParams = { threadId: string, turnId: string, itemId: string, reason: string | null, permissions: RequestPermissionProfile, suggestedScope: PermissionGrantScope, };
@@ -6219,6 +6219,8 @@ pub struct PermissionsRequestApprovalParams {
pub item_id: String,
pub reason: Option<String>,
pub permissions: RequestPermissionProfile,
#[serde(default)]
pub suggested_scope: PermissionGrantScope,
}
v2_enum_from_core!(
@@ -6604,6 +6606,25 @@ mod tests {
}),
}
);
assert_eq!(params.suggested_scope, PermissionGrantScope::Turn);
}
#[test]
fn permissions_request_approval_preserves_suggested_scope() {
let params = serde_json::from_value::<PermissionsRequestApprovalParams>(json!({
"threadId": "thr_123",
"turnId": "turn_123",
"itemId": "call_123",
"reason": "Select a workspace root",
"permissions": {
"network": null,
"fileSystem": null,
},
"suggestedScope": "session",
}))
.expect("permissions request should deserialize");
assert_eq!(params.suggested_scope, PermissionGrantScope::Session);
}
#[test]