mirror of
https://github.com/openai/codex.git
synced 2026-11-19 22:30:42 +00:00
feat(app-server): transport permission preset requests
Add the v2 `item/permissionPreset/requestApproval` server request and thread it through app-server delivery for clients that opt into the matching `supportedServerRequests` capability. Keep the flow backward compatible by failing closed when a connection does not advertise support, reject it explicitly in `codex exec`, and update the docs, schemas, and request transport tests.
This commit is contained in:
@@ -0,0 +1,299 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"definitions": {
|
||||
"AbsolutePathBuf": {
|
||||
"description": "A path that is guaranteed to be absolute and normalized (though it is not guaranteed to be canonicalized or exist on the filesystem).\n\nIMPORTANT: When deserializing an `AbsolutePathBuf`, a base path must be set using [AbsolutePathBufGuard::new]. If no base path is set, the deserialization will fail unless the path being deserialized is already absolute.",
|
||||
"type": "string"
|
||||
},
|
||||
"ApprovalsReviewer": {
|
||||
"description": "Configures who approval requests are routed to for review. Examples include sandbox escapes, blocked network access, MCP approval prompts, and ARC escalations. Defaults to `user`. `guardian_subagent` uses a carefully prompted subagent to gather relevant context and apply a risk-based decision framework before approving or denying the request.",
|
||||
"enum": [
|
||||
"user",
|
||||
"guardian_subagent"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"AskForApproval": {
|
||||
"oneOf": [
|
||||
{
|
||||
"enum": [
|
||||
"untrusted",
|
||||
"on-failure",
|
||||
"on-request",
|
||||
"never"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"granular": {
|
||||
"properties": {
|
||||
"mcp_elicitations": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"request_permissions": {
|
||||
"default": false,
|
||||
"type": "boolean"
|
||||
},
|
||||
"rules": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"sandbox_approval": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"skill_approval": {
|
||||
"default": false,
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"mcp_elicitations",
|
||||
"rules",
|
||||
"sandbox_approval"
|
||||
],
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"granular"
|
||||
],
|
||||
"title": "GranularAskForApproval",
|
||||
"type": "object"
|
||||
}
|
||||
]
|
||||
},
|
||||
"NetworkAccess": {
|
||||
"enum": [
|
||||
"restricted",
|
||||
"enabled"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"PermissionPresetId": {
|
||||
"description": "A built-in permission-mode preset that app clients can confirm.",
|
||||
"enum": [
|
||||
"auto",
|
||||
"full-access",
|
||||
"read-only",
|
||||
"guardian-approvals"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"ReadOnlyAccess": {
|
||||
"oneOf": [
|
||||
{
|
||||
"properties": {
|
||||
"includePlatformDefaults": {
|
||||
"default": true,
|
||||
"type": "boolean"
|
||||
},
|
||||
"readableRoots": {
|
||||
"default": [],
|
||||
"items": {
|
||||
"$ref": "#/definitions/AbsolutePathBuf"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"type": {
|
||||
"enum": [
|
||||
"restricted"
|
||||
],
|
||||
"title": "RestrictedReadOnlyAccessType",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"type"
|
||||
],
|
||||
"title": "RestrictedReadOnlyAccess",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"type": {
|
||||
"enum": [
|
||||
"fullAccess"
|
||||
],
|
||||
"title": "FullAccessReadOnlyAccessType",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"type"
|
||||
],
|
||||
"title": "FullAccessReadOnlyAccess",
|
||||
"type": "object"
|
||||
}
|
||||
]
|
||||
},
|
||||
"SandboxPolicy": {
|
||||
"oneOf": [
|
||||
{
|
||||
"properties": {
|
||||
"type": {
|
||||
"enum": [
|
||||
"dangerFullAccess"
|
||||
],
|
||||
"title": "DangerFullAccessSandboxPolicyType",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"type"
|
||||
],
|
||||
"title": "DangerFullAccessSandboxPolicy",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"access": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/ReadOnlyAccess"
|
||||
}
|
||||
],
|
||||
"default": {
|
||||
"type": "fullAccess"
|
||||
}
|
||||
},
|
||||
"networkAccess": {
|
||||
"default": false,
|
||||
"type": "boolean"
|
||||
},
|
||||
"type": {
|
||||
"enum": [
|
||||
"readOnly"
|
||||
],
|
||||
"title": "ReadOnlySandboxPolicyType",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"type"
|
||||
],
|
||||
"title": "ReadOnlySandboxPolicy",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"networkAccess": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/NetworkAccess"
|
||||
}
|
||||
],
|
||||
"default": "restricted"
|
||||
},
|
||||
"type": {
|
||||
"enum": [
|
||||
"externalSandbox"
|
||||
],
|
||||
"title": "ExternalSandboxSandboxPolicyType",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"type"
|
||||
],
|
||||
"title": "ExternalSandboxSandboxPolicy",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"excludeSlashTmp": {
|
||||
"default": false,
|
||||
"type": "boolean"
|
||||
},
|
||||
"excludeTmpdirEnvVar": {
|
||||
"default": false,
|
||||
"type": "boolean"
|
||||
},
|
||||
"networkAccess": {
|
||||
"default": false,
|
||||
"type": "boolean"
|
||||
},
|
||||
"readOnlyAccess": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/ReadOnlyAccess"
|
||||
}
|
||||
],
|
||||
"default": {
|
||||
"type": "fullAccess"
|
||||
}
|
||||
},
|
||||
"type": {
|
||||
"enum": [
|
||||
"workspaceWrite"
|
||||
],
|
||||
"title": "WorkspaceWriteSandboxPolicyType",
|
||||
"type": "string"
|
||||
},
|
||||
"writableRoots": {
|
||||
"default": [],
|
||||
"items": {
|
||||
"$ref": "#/definitions/AbsolutePathBuf"
|
||||
},
|
||||
"type": "array"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"type"
|
||||
],
|
||||
"title": "WorkspaceWriteSandboxPolicy",
|
||||
"type": "object"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"description": "Request sent to app clients when a model asks to switch permission modes.\n\nCore resolves the requested preset before emitting this payload, so clients should render the provided settings and label rather than recomputing policy choices from the preset id.",
|
||||
"properties": {
|
||||
"approvalPolicy": {
|
||||
"$ref": "#/definitions/AskForApproval"
|
||||
},
|
||||
"approvalsReviewer": {
|
||||
"$ref": "#/definitions/ApprovalsReviewer"
|
||||
},
|
||||
"description": {
|
||||
"type": "string"
|
||||
},
|
||||
"itemId": {
|
||||
"type": "string"
|
||||
},
|
||||
"label": {
|
||||
"type": "string"
|
||||
},
|
||||
"preset": {
|
||||
"$ref": "#/definitions/PermissionPresetId"
|
||||
},
|
||||
"reason": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"sandboxPolicy": {
|
||||
"$ref": "#/definitions/SandboxPolicy"
|
||||
},
|
||||
"threadId": {
|
||||
"type": "string"
|
||||
},
|
||||
"turnId": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"approvalPolicy",
|
||||
"approvalsReviewer",
|
||||
"description",
|
||||
"itemId",
|
||||
"label",
|
||||
"preset",
|
||||
"sandboxPolicy",
|
||||
"threadId",
|
||||
"turnId"
|
||||
],
|
||||
"title": "PermissionPresetRequestApprovalParams",
|
||||
"type": "object"
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"definitions": {
|
||||
"PermissionPresetApprovalDecision": {
|
||||
"enum": [
|
||||
"accepted",
|
||||
"declined"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"PermissionPresetId": {
|
||||
"description": "A built-in permission-mode preset that app clients can confirm.",
|
||||
"enum": [
|
||||
"auto",
|
||||
"full-access",
|
||||
"read-only",
|
||||
"guardian-approvals"
|
||||
],
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"description": "Response from an app client after the permission preset picker resolves.",
|
||||
"properties": {
|
||||
"decision": {
|
||||
"$ref": "#/definitions/PermissionPresetApprovalDecision"
|
||||
},
|
||||
"preset": {
|
||||
"$ref": "#/definitions/PermissionPresetId"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"decision",
|
||||
"preset"
|
||||
],
|
||||
"title": "PermissionPresetRequestApprovalResponse",
|
||||
"type": "object"
|
||||
}
|
||||
@@ -101,6 +101,64 @@
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"ApprovalsReviewer": {
|
||||
"description": "Configures who approval requests are routed to for review. Examples include sandbox escapes, blocked network access, MCP approval prompts, and ARC escalations. Defaults to `user`. `guardian_subagent` uses a carefully prompted subagent to gather relevant context and apply a risk-based decision framework before approving or denying the request.",
|
||||
"enum": [
|
||||
"user",
|
||||
"guardian_subagent"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"AskForApproval": {
|
||||
"oneOf": [
|
||||
{
|
||||
"enum": [
|
||||
"untrusted",
|
||||
"on-failure",
|
||||
"on-request",
|
||||
"never"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"granular": {
|
||||
"properties": {
|
||||
"mcp_elicitations": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"request_permissions": {
|
||||
"default": false,
|
||||
"type": "boolean"
|
||||
},
|
||||
"rules": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"sandbox_approval": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"skill_approval": {
|
||||
"default": false,
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"mcp_elicitations",
|
||||
"rules",
|
||||
"sandbox_approval"
|
||||
],
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"granular"
|
||||
],
|
||||
"title": "GranularAskForApproval",
|
||||
"type": "object"
|
||||
}
|
||||
]
|
||||
},
|
||||
"ChatgptAuthTokensRefreshParams": {
|
||||
"properties": {
|
||||
"previousAccountId": {
|
||||
@@ -1187,6 +1245,13 @@
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"NetworkAccess": {
|
||||
"enum": [
|
||||
"restricted",
|
||||
"enabled"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"NetworkApprovalContext": {
|
||||
"properties": {
|
||||
"host": {
|
||||
@@ -1351,6 +1416,66 @@
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"PermissionPresetId": {
|
||||
"description": "A built-in permission-mode preset that app clients can confirm.",
|
||||
"enum": [
|
||||
"auto",
|
||||
"full-access",
|
||||
"read-only",
|
||||
"guardian-approvals"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"PermissionPresetRequestApprovalParams": {
|
||||
"description": "Request sent to app clients when a model asks to switch permission modes.\n\nCore resolves the requested preset before emitting this payload, so clients should render the provided settings and label rather than recomputing policy choices from the preset id.",
|
||||
"properties": {
|
||||
"approvalPolicy": {
|
||||
"$ref": "#/definitions/AskForApproval"
|
||||
},
|
||||
"approvalsReviewer": {
|
||||
"$ref": "#/definitions/ApprovalsReviewer"
|
||||
},
|
||||
"description": {
|
||||
"type": "string"
|
||||
},
|
||||
"itemId": {
|
||||
"type": "string"
|
||||
},
|
||||
"label": {
|
||||
"type": "string"
|
||||
},
|
||||
"preset": {
|
||||
"$ref": "#/definitions/PermissionPresetId"
|
||||
},
|
||||
"reason": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"sandboxPolicy": {
|
||||
"$ref": "#/definitions/SandboxPolicy"
|
||||
},
|
||||
"threadId": {
|
||||
"type": "string"
|
||||
},
|
||||
"turnId": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"approvalPolicy",
|
||||
"approvalsReviewer",
|
||||
"description",
|
||||
"itemId",
|
||||
"label",
|
||||
"preset",
|
||||
"sandboxPolicy",
|
||||
"threadId",
|
||||
"turnId"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"PermissionsRequestApprovalParams": {
|
||||
"properties": {
|
||||
"itemId": {
|
||||
@@ -1388,6 +1513,53 @@
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"ReadOnlyAccess": {
|
||||
"oneOf": [
|
||||
{
|
||||
"properties": {
|
||||
"includePlatformDefaults": {
|
||||
"default": true,
|
||||
"type": "boolean"
|
||||
},
|
||||
"readableRoots": {
|
||||
"default": [],
|
||||
"items": {
|
||||
"$ref": "#/definitions/AbsolutePathBuf"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"type": {
|
||||
"enum": [
|
||||
"restricted"
|
||||
],
|
||||
"title": "RestrictedReadOnlyAccessType",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"type"
|
||||
],
|
||||
"title": "RestrictedReadOnlyAccess",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"type": {
|
||||
"enum": [
|
||||
"fullAccess"
|
||||
],
|
||||
"title": "FullAccessReadOnlyAccessType",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"type"
|
||||
],
|
||||
"title": "FullAccessReadOnlyAccess",
|
||||
"type": "object"
|
||||
}
|
||||
]
|
||||
},
|
||||
"RequestId": {
|
||||
"anyOf": [
|
||||
{
|
||||
@@ -1425,6 +1597,125 @@
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"SandboxPolicy": {
|
||||
"oneOf": [
|
||||
{
|
||||
"properties": {
|
||||
"type": {
|
||||
"enum": [
|
||||
"dangerFullAccess"
|
||||
],
|
||||
"title": "DangerFullAccessSandboxPolicyType",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"type"
|
||||
],
|
||||
"title": "DangerFullAccessSandboxPolicy",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"access": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/ReadOnlyAccess"
|
||||
}
|
||||
],
|
||||
"default": {
|
||||
"type": "fullAccess"
|
||||
}
|
||||
},
|
||||
"networkAccess": {
|
||||
"default": false,
|
||||
"type": "boolean"
|
||||
},
|
||||
"type": {
|
||||
"enum": [
|
||||
"readOnly"
|
||||
],
|
||||
"title": "ReadOnlySandboxPolicyType",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"type"
|
||||
],
|
||||
"title": "ReadOnlySandboxPolicy",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"networkAccess": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/NetworkAccess"
|
||||
}
|
||||
],
|
||||
"default": "restricted"
|
||||
},
|
||||
"type": {
|
||||
"enum": [
|
||||
"externalSandbox"
|
||||
],
|
||||
"title": "ExternalSandboxSandboxPolicyType",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"type"
|
||||
],
|
||||
"title": "ExternalSandboxSandboxPolicy",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"excludeSlashTmp": {
|
||||
"default": false,
|
||||
"type": "boolean"
|
||||
},
|
||||
"excludeTmpdirEnvVar": {
|
||||
"default": false,
|
||||
"type": "boolean"
|
||||
},
|
||||
"networkAccess": {
|
||||
"default": false,
|
||||
"type": "boolean"
|
||||
},
|
||||
"readOnlyAccess": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/ReadOnlyAccess"
|
||||
}
|
||||
],
|
||||
"default": {
|
||||
"type": "fullAccess"
|
||||
}
|
||||
},
|
||||
"type": {
|
||||
"enum": [
|
||||
"workspaceWrite"
|
||||
],
|
||||
"title": "WorkspaceWriteSandboxPolicyType",
|
||||
"type": "string"
|
||||
},
|
||||
"writableRoots": {
|
||||
"default": [],
|
||||
"items": {
|
||||
"$ref": "#/definitions/AbsolutePathBuf"
|
||||
},
|
||||
"type": "array"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"type"
|
||||
],
|
||||
"title": "WorkspaceWriteSandboxPolicy",
|
||||
"type": "object"
|
||||
}
|
||||
]
|
||||
},
|
||||
"ThreadId": {
|
||||
"type": "string"
|
||||
},
|
||||
@@ -1636,6 +1927,31 @@
|
||||
"title": "Item/permissions/requestApprovalRequest",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"description": "Request the client to open its permission preset picker.",
|
||||
"properties": {
|
||||
"id": {
|
||||
"$ref": "#/definitions/RequestId"
|
||||
},
|
||||
"method": {
|
||||
"enum": [
|
||||
"item/permissionPreset/requestApproval"
|
||||
],
|
||||
"title": "Item/permissionPreset/requestApprovalRequestMethod",
|
||||
"type": "string"
|
||||
},
|
||||
"params": {
|
||||
"$ref": "#/definitions/PermissionPresetRequestApprovalParams"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"id",
|
||||
"method",
|
||||
"params"
|
||||
],
|
||||
"title": "Item/permissionPreset/requestApprovalRequest",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"description": "Execute a dynamic tool call on the client.",
|
||||
"properties": {
|
||||
|
||||
@@ -3270,6 +3270,93 @@
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"PermissionPresetApprovalDecision": {
|
||||
"enum": [
|
||||
"accepted",
|
||||
"declined"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"PermissionPresetId": {
|
||||
"description": "A built-in permission-mode preset that app clients can confirm.",
|
||||
"enum": [
|
||||
"auto",
|
||||
"full-access",
|
||||
"read-only",
|
||||
"guardian-approvals"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"PermissionPresetRequestApprovalParams": {
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"description": "Request sent to app clients when a model asks to switch permission modes.\n\nCore resolves the requested preset before emitting this payload, so clients should render the provided settings and label rather than recomputing policy choices from the preset id.",
|
||||
"properties": {
|
||||
"approvalPolicy": {
|
||||
"$ref": "#/definitions/v2/AskForApproval"
|
||||
},
|
||||
"approvalsReviewer": {
|
||||
"$ref": "#/definitions/v2/ApprovalsReviewer"
|
||||
},
|
||||
"description": {
|
||||
"type": "string"
|
||||
},
|
||||
"itemId": {
|
||||
"type": "string"
|
||||
},
|
||||
"label": {
|
||||
"type": "string"
|
||||
},
|
||||
"preset": {
|
||||
"$ref": "#/definitions/PermissionPresetId"
|
||||
},
|
||||
"reason": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"sandboxPolicy": {
|
||||
"$ref": "#/definitions/v2/SandboxPolicy"
|
||||
},
|
||||
"threadId": {
|
||||
"type": "string"
|
||||
},
|
||||
"turnId": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"approvalPolicy",
|
||||
"approvalsReviewer",
|
||||
"description",
|
||||
"itemId",
|
||||
"label",
|
||||
"preset",
|
||||
"sandboxPolicy",
|
||||
"threadId",
|
||||
"turnId"
|
||||
],
|
||||
"title": "PermissionPresetRequestApprovalParams",
|
||||
"type": "object"
|
||||
},
|
||||
"PermissionPresetRequestApprovalResponse": {
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"description": "Response from an app client after the permission preset picker resolves.",
|
||||
"properties": {
|
||||
"decision": {
|
||||
"$ref": "#/definitions/PermissionPresetApprovalDecision"
|
||||
},
|
||||
"preset": {
|
||||
"$ref": "#/definitions/PermissionPresetId"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"decision",
|
||||
"preset"
|
||||
],
|
||||
"title": "PermissionPresetRequestApprovalResponse",
|
||||
"type": "object"
|
||||
},
|
||||
"PermissionsRequestApprovalParams": {
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"properties": {
|
||||
@@ -4637,6 +4724,31 @@
|
||||
"title": "Item/permissions/requestApprovalRequest",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"description": "Request the client to open its permission preset picker.",
|
||||
"properties": {
|
||||
"id": {
|
||||
"$ref": "#/definitions/v2/RequestId"
|
||||
},
|
||||
"method": {
|
||||
"enum": [
|
||||
"item/permissionPreset/requestApproval"
|
||||
],
|
||||
"title": "Item/permissionPreset/requestApprovalRequestMethod",
|
||||
"type": "string"
|
||||
},
|
||||
"params": {
|
||||
"$ref": "#/definitions/PermissionPresetRequestApprovalParams"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"id",
|
||||
"method",
|
||||
"params"
|
||||
],
|
||||
"title": "Item/permissionPreset/requestApprovalRequest",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"description": "Execute a dynamic tool call on the client.",
|
||||
"properties": {
|
||||
|
||||
@@ -9,10 +9,11 @@ import type { CommandExecutionRequestApprovalParams } from "./v2/CommandExecutio
|
||||
import type { DynamicToolCallParams } from "./v2/DynamicToolCallParams";
|
||||
import type { FileChangeRequestApprovalParams } from "./v2/FileChangeRequestApprovalParams";
|
||||
import type { McpServerElicitationRequestParams } from "./v2/McpServerElicitationRequestParams";
|
||||
import type { PermissionPresetRequestApprovalParams } from "./v2/PermissionPresetRequestApprovalParams";
|
||||
import type { PermissionsRequestApprovalParams } from "./v2/PermissionsRequestApprovalParams";
|
||||
import type { ToolRequestUserInputParams } from "./v2/ToolRequestUserInputParams";
|
||||
|
||||
/**
|
||||
* Request initiated from the server and sent to the client.
|
||||
*/
|
||||
export type ServerRequest = { "method": "item/commandExecution/requestApproval", id: RequestId, params: CommandExecutionRequestApprovalParams, } | { "method": "item/fileChange/requestApproval", id: RequestId, params: FileChangeRequestApprovalParams, } | { "method": "item/tool/requestUserInput", id: RequestId, params: ToolRequestUserInputParams, } | { "method": "mcpServer/elicitation/request", id: RequestId, params: McpServerElicitationRequestParams, } | { "method": "item/permissions/requestApproval", id: RequestId, params: PermissionsRequestApprovalParams, } | { "method": "item/tool/call", id: RequestId, params: DynamicToolCallParams, } | { "method": "account/chatgptAuthTokens/refresh", id: RequestId, params: ChatgptAuthTokensRefreshParams, } | { "method": "applyPatchApproval", id: RequestId, params: ApplyPatchApprovalParams, } | { "method": "execCommandApproval", id: RequestId, params: ExecCommandApprovalParams, };
|
||||
export type ServerRequest = { "method": "item/commandExecution/requestApproval", id: RequestId, params: CommandExecutionRequestApprovalParams, } | { "method": "item/fileChange/requestApproval", id: RequestId, params: FileChangeRequestApprovalParams, } | { "method": "item/tool/requestUserInput", id: RequestId, params: ToolRequestUserInputParams, } | { "method": "mcpServer/elicitation/request", id: RequestId, params: McpServerElicitationRequestParams, } | { "method": "item/permissions/requestApproval", id: RequestId, params: PermissionsRequestApprovalParams, } | { "method": "item/permissionPreset/requestApproval", id: RequestId, params: PermissionPresetRequestApprovalParams, } | { "method": "item/tool/call", id: RequestId, params: DynamicToolCallParams, } | { "method": "account/chatgptAuthTokens/refresh", id: RequestId, params: ChatgptAuthTokensRefreshParams, } | { "method": "applyPatchApproval", id: RequestId, params: ApplyPatchApprovalParams, } | { "method": "execCommandApproval", id: RequestId, params: ExecCommandApprovalParams, };
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
// 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.
|
||||
|
||||
export type PermissionPresetApprovalDecision = "accepted" | "declined";
|
||||
@@ -0,0 +1,8 @@
|
||||
// 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.
|
||||
|
||||
/**
|
||||
* A built-in permission-mode preset that app clients can confirm.
|
||||
*/
|
||||
export type PermissionPresetId = "auto" | "full-access" | "read-only" | "guardian-approvals";
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// 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 { ApprovalsReviewer } from "./ApprovalsReviewer";
|
||||
import type { AskForApproval } from "./AskForApproval";
|
||||
import type { PermissionPresetId } from "./PermissionPresetId";
|
||||
import type { SandboxPolicy } from "./SandboxPolicy";
|
||||
|
||||
/**
|
||||
* Request sent to app clients when a model asks to switch permission modes.
|
||||
*
|
||||
* Core resolves the requested preset before emitting this payload, so clients
|
||||
* should render the provided settings and label rather than recomputing policy
|
||||
* choices from the preset id.
|
||||
*/
|
||||
export type PermissionPresetRequestApprovalParams = { threadId: string, turnId: string, itemId: string, preset: PermissionPresetId, label: string, description: string, approvalPolicy: AskForApproval, approvalsReviewer: ApprovalsReviewer, sandboxPolicy: SandboxPolicy, reason: string | null, };
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// 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 { PermissionPresetApprovalDecision } from "./PermissionPresetApprovalDecision";
|
||||
import type { PermissionPresetId } from "./PermissionPresetId";
|
||||
|
||||
/**
|
||||
* Response from an app client after the permission preset picker resolves.
|
||||
*/
|
||||
export type PermissionPresetRequestApprovalResponse = { decision: PermissionPresetApprovalDecision, preset: PermissionPresetId, };
|
||||
@@ -216,6 +216,10 @@ export type { OverriddenMetadata } from "./OverriddenMetadata";
|
||||
export type { PatchApplyStatus } from "./PatchApplyStatus";
|
||||
export type { PatchChangeKind } from "./PatchChangeKind";
|
||||
export type { PermissionGrantScope } from "./PermissionGrantScope";
|
||||
export type { PermissionPresetApprovalDecision } from "./PermissionPresetApprovalDecision";
|
||||
export type { PermissionPresetId } from "./PermissionPresetId";
|
||||
export type { PermissionPresetRequestApprovalParams } from "./PermissionPresetRequestApprovalParams";
|
||||
export type { PermissionPresetRequestApprovalResponse } from "./PermissionPresetRequestApprovalResponse";
|
||||
export type { PermissionsRequestApprovalParams } from "./PermissionsRequestApprovalParams";
|
||||
export type { PermissionsRequestApprovalResponse } from "./PermissionsRequestApprovalResponse";
|
||||
export type { PlanDeltaNotification } from "./PlanDeltaNotification";
|
||||
|
||||
@@ -851,6 +851,12 @@ server_request_definitions! {
|
||||
response: v2::PermissionsRequestApprovalResponse,
|
||||
},
|
||||
|
||||
/// Request the client to open its permission preset picker.
|
||||
PermissionPresetRequestApproval => "item/permissionPreset/requestApproval" {
|
||||
params: v2::PermissionPresetRequestApprovalParams,
|
||||
response: v2::PermissionPresetRequestApprovalResponse,
|
||||
},
|
||||
|
||||
/// Execute a dynamic tool call on the client.
|
||||
DynamicToolCall => "item/tool/call" {
|
||||
params: v2::DynamicToolCallParams,
|
||||
|
||||
@@ -87,6 +87,8 @@ use codex_protocol::protocol::SkillToolDependency as CoreSkillToolDependency;
|
||||
use codex_protocol::protocol::SubAgentSource as CoreSubAgentSource;
|
||||
use codex_protocol::protocol::TokenUsage as CoreTokenUsage;
|
||||
use codex_protocol::protocol::TokenUsageInfo as CoreTokenUsageInfo;
|
||||
use codex_protocol::request_permission_preset::PermissionPresetId as CorePermissionPresetId;
|
||||
use codex_protocol::request_permission_preset::RequestPermissionPresetDecision as CoreRequestPermissionPresetDecision;
|
||||
use codex_protocol::request_permissions::PermissionGrantScope as CorePermissionGrantScope;
|
||||
use codex_protocol::request_permissions::RequestPermissionProfile as CoreRequestPermissionProfile;
|
||||
use codex_protocol::user_input::ByteRange as CoreByteRange;
|
||||
@@ -6241,6 +6243,77 @@ pub struct PermissionsRequestApprovalResponse {
|
||||
pub scope: PermissionGrantScope,
|
||||
}
|
||||
|
||||
/// A built-in permission-mode preset that app clients can confirm.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
#[ts(rename_all = "kebab-case", export_to = "v2/")]
|
||||
pub enum PermissionPresetId {
|
||||
Auto,
|
||||
FullAccess,
|
||||
ReadOnly,
|
||||
GuardianApprovals,
|
||||
}
|
||||
|
||||
impl PermissionPresetId {
|
||||
/// Converts the app-server preset identifier into the core protocol type.
|
||||
pub fn to_core(self) -> CorePermissionPresetId {
|
||||
match self {
|
||||
Self::Auto => CorePermissionPresetId::Auto,
|
||||
Self::FullAccess => CorePermissionPresetId::FullAccess,
|
||||
Self::ReadOnly => CorePermissionPresetId::ReadOnly,
|
||||
Self::GuardianApprovals => CorePermissionPresetId::GuardianApprovals,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CorePermissionPresetId> for PermissionPresetId {
|
||||
fn from(value: CorePermissionPresetId) -> Self {
|
||||
match value {
|
||||
CorePermissionPresetId::Auto => Self::Auto,
|
||||
CorePermissionPresetId::FullAccess => Self::FullAccess,
|
||||
CorePermissionPresetId::ReadOnly => Self::ReadOnly,
|
||||
CorePermissionPresetId::GuardianApprovals => Self::GuardianApprovals,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Request sent to app clients when a model asks to switch permission modes.
|
||||
///
|
||||
/// Core resolves the requested preset before emitting this payload, so clients
|
||||
/// should render the provided settings and label rather than recomputing policy
|
||||
/// choices from the preset id.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export_to = "v2/")]
|
||||
pub struct PermissionPresetRequestApprovalParams {
|
||||
pub thread_id: String,
|
||||
pub turn_id: String,
|
||||
pub item_id: String,
|
||||
pub preset: PermissionPresetId,
|
||||
pub label: String,
|
||||
pub description: String,
|
||||
pub approval_policy: AskForApproval,
|
||||
pub approvals_reviewer: ApprovalsReviewer,
|
||||
pub sandbox_policy: SandboxPolicy,
|
||||
pub reason: Option<String>,
|
||||
}
|
||||
|
||||
v2_enum_from_core!(
|
||||
pub enum PermissionPresetApprovalDecision from CoreRequestPermissionPresetDecision {
|
||||
Accepted,
|
||||
Declined
|
||||
}
|
||||
);
|
||||
|
||||
/// Response from an app client after the permission preset picker resolves.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export_to = "v2/")]
|
||||
pub struct PermissionPresetRequestApprovalResponse {
|
||||
pub decision: PermissionPresetApprovalDecision,
|
||||
pub preset: PermissionPresetId,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[ts(export_to = "v2/")]
|
||||
@@ -6627,6 +6700,31 @@ mod tests {
|
||||
assert_eq!(params.suggested_scope, PermissionGrantScope::Session);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn permission_preset_request_approval_response_round_trips() {
|
||||
let response = serde_json::from_value::<PermissionPresetRequestApprovalResponse>(json!({
|
||||
"decision": "accepted",
|
||||
"preset": "full-access",
|
||||
}))
|
||||
.expect("permission preset response should deserialize");
|
||||
|
||||
assert_eq!(
|
||||
response,
|
||||
PermissionPresetRequestApprovalResponse {
|
||||
decision: PermissionPresetApprovalDecision::Accepted,
|
||||
preset: PermissionPresetId::FullAccess,
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
response.decision.to_core(),
|
||||
CoreRequestPermissionPresetDecision::Accepted
|
||||
);
|
||||
assert_eq!(
|
||||
response.preset.to_core(),
|
||||
CorePermissionPresetId::FullAccess
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn permissions_request_approval_rejects_macos_permissions() {
|
||||
let err = serde_json::from_value::<PermissionsRequestApprovalParams>(json!({
|
||||
|
||||
@@ -89,7 +89,7 @@ Clients must send a single `initialize` request per transport connection before
|
||||
|
||||
`initialize.params.capabilities` also supports per-connection notification opt-out via `optOutNotificationMethods`, which is a list of exact method names to suppress for that connection. Matching is exact (no wildcards/prefixes). Unknown method names are accepted and ignored.
|
||||
|
||||
Clients can also advertise `supportedServerRequests` during initialize. This is a per-connection opt-in list of server-initiated request methods the surface knows how to render and answer. App-server uses it for conversational permission confirmation flows so existing clients keep their current behavior until they explicitly opt in.
|
||||
Clients can also opt into specific server-initiated request methods through `supportedServerRequests`. This is required for conversational permission confirmations such as `item/permissions/requestApproval` and `item/permissionPreset/requestApproval`: if a connection omits the matching method, app-server does not send that request to the client and the permission change is rejected without changing the session.
|
||||
|
||||
Applications building on top of `codex app-server` should identify themselves via the `clientInfo` parameter.
|
||||
|
||||
@@ -113,7 +113,7 @@ Example (from OpenAI's official VSCode extension):
|
||||
}
|
||||
```
|
||||
|
||||
Example with notification opt-out and explicit server-request support:
|
||||
Example with notification opt-out and permission request support:
|
||||
|
||||
```json
|
||||
{
|
||||
@@ -1077,7 +1077,7 @@ the client can offer session-scoped and/or persistent approval choices.
|
||||
|
||||
### Permission requests
|
||||
|
||||
Clients must opt into conversational permission confirmation request methods by listing them in `initialize.params.capabilities.supportedServerRequests`. The opt-in is per connection and per method, which lets older clients continue to initialize without promising UI they do not implement.
|
||||
Clients must opt into each conversational permission request method by listing it in `initialize.params.capabilities.supportedServerRequests`. The opt-in is per connection and per method. App-server uses this capability before starting a thread so unsupported clients do not expose the model-facing tools that trigger these request methods. Existing clients that do not advertise support keep their current behavior: app-server does not ask the model to use an unsupported approval UI, no permissions are changed, and delivery-time denials are only a fallback if a request is still produced.
|
||||
|
||||
The built-in `request_permissions` tool sends an `item/permissions/requestApproval` JSON-RPC request to the client with the requested permission profile. This v2 payload mirrors the command-execution `additionalPermissions` shape: it can request network access and additional filesystem access, and it includes `suggestedScope` so clients can preselect the model's requested lifetime while still requiring explicit confirmation.
|
||||
|
||||
@@ -1122,6 +1122,8 @@ Within the same turn, granted permissions are sticky: later shell-like tool call
|
||||
|
||||
If the session approval policy uses `Granular` with `request_permissions: false`, standalone `request_permissions` tool calls are auto-denied and no `item/permissions/requestApproval` prompt is sent. Inline `with_additional_permissions` command requests remain controlled by `sandbox_approval`, and any previously granted permissions remain sticky for later shell-like calls in the same turn.
|
||||
|
||||
The built-in `request_permission_preset` tool sends an `item/permissionPreset/requestApproval` JSON-RPC request when a model asks the client to open the permission preset picker. The request includes the resolved preset id, label, description, approval policy, approvals reviewer, sandbox policy, and optional reason so clients can show their native picker with the requested option already selected. Clients respond with `{ "decision": "accepted", "preset": "full-access" }` or `{ "decision": "declined", "preset": "full-access" }`. When the client omits `item/permissionPreset/requestApproval` from `supportedServerRequests`, app-server hides the preset tool for new threads; if a request is still produced, app-server declines it and leaves the active permissions unchanged.
|
||||
|
||||
### Dynamic tool calls (experimental)
|
||||
|
||||
`dynamicTools` on `thread/start` and the corresponding `item/tool/call` request/response flow are experimental APIs. To enable them, set `initialize.params.capabilities.experimentalApi = true`.
|
||||
|
||||
@@ -62,6 +62,9 @@ use codex_app_server_protocol::NetworkApprovalContext as V2NetworkApprovalContex
|
||||
use codex_app_server_protocol::NetworkPolicyAmendment as V2NetworkPolicyAmendment;
|
||||
use codex_app_server_protocol::NetworkPolicyRuleAction as V2NetworkPolicyRuleAction;
|
||||
use codex_app_server_protocol::PatchApplyStatus;
|
||||
use codex_app_server_protocol::PermissionPresetApprovalDecision;
|
||||
use codex_app_server_protocol::PermissionPresetRequestApprovalParams;
|
||||
use codex_app_server_protocol::PermissionPresetRequestApprovalResponse;
|
||||
use codex_app_server_protocol::PermissionsRequestApprovalParams;
|
||||
use codex_app_server_protocol::PermissionsRequestApprovalResponse;
|
||||
use codex_app_server_protocol::PlanDeltaNotification;
|
||||
@@ -131,6 +134,9 @@ use codex_protocol::protocol::TokenCountEvent;
|
||||
use codex_protocol::protocol::TurnAbortedEvent;
|
||||
use codex_protocol::protocol::TurnCompleteEvent;
|
||||
use codex_protocol::protocol::TurnDiffEvent;
|
||||
use codex_protocol::request_permission_preset::PermissionPresetId;
|
||||
use codex_protocol::request_permission_preset::RequestPermissionPresetDecision as CoreRequestPermissionPresetDecision;
|
||||
use codex_protocol::request_permission_preset::RequestPermissionPresetResponse as CoreRequestPermissionPresetResponse;
|
||||
use codex_protocol::request_permissions::PermissionGrantScope as CorePermissionGrantScope;
|
||||
use codex_protocol::request_permissions::RequestPermissionProfile as CoreRequestPermissionProfile;
|
||||
use codex_protocol::request_permissions::RequestPermissionsResponse as CoreRequestPermissionsResponse;
|
||||
@@ -169,6 +175,7 @@ pub(crate) async fn apply_bespoke_event_handling(
|
||||
thread_manager: Arc<ThreadManager>,
|
||||
outgoing: ThreadScopedOutgoingMessageSender,
|
||||
request_permissions_outgoing: ThreadScopedOutgoingMessageSender,
|
||||
request_permission_preset_outgoing: ThreadScopedOutgoingMessageSender,
|
||||
thread_state: Arc<tokio::sync::Mutex<ThreadState>>,
|
||||
thread_watch_manager: ThreadWatchManager,
|
||||
api_version: ApiVersion,
|
||||
@@ -906,6 +913,59 @@ pub(crate) async fn apply_bespoke_event_handling(
|
||||
}
|
||||
}
|
||||
}
|
||||
EventMsg::RequestPermissionPreset(request) => {
|
||||
if matches!(api_version, ApiVersion::V2)
|
||||
&& !request_permission_preset_outgoing.is_empty()
|
||||
{
|
||||
let params = PermissionPresetRequestApprovalParams {
|
||||
thread_id: conversation_id.to_string(),
|
||||
turn_id: request.turn_id.clone(),
|
||||
item_id: request.call_id.clone(),
|
||||
preset: request.preset.into(),
|
||||
label: request.label.clone(),
|
||||
description: request.description,
|
||||
approval_policy: request.approval_policy.into(),
|
||||
approvals_reviewer: request.approvals_reviewer.into(),
|
||||
sandbox_policy: request.sandbox_policy.into(),
|
||||
reason: request.reason,
|
||||
};
|
||||
let (pending_request_id, rx) = request_permission_preset_outgoing
|
||||
.send_request(ServerRequestPayload::PermissionPresetRequestApproval(
|
||||
params,
|
||||
))
|
||||
.await;
|
||||
tokio::spawn(async move {
|
||||
on_request_permission_preset_response(
|
||||
request.call_id,
|
||||
request.preset,
|
||||
pending_request_id,
|
||||
rx,
|
||||
conversation,
|
||||
thread_state,
|
||||
)
|
||||
.await;
|
||||
});
|
||||
} else {
|
||||
warn!(
|
||||
"request_permission_preset is not supported by this app-server client (call_id: {})",
|
||||
request.call_id
|
||||
);
|
||||
let declined = CoreRequestPermissionPresetResponse {
|
||||
decision: CoreRequestPermissionPresetDecision::Declined,
|
||||
preset: request.preset,
|
||||
message: "permission confirmation UI is not available in this client; no permissions were changed".to_string(),
|
||||
};
|
||||
if let Err(err) = conversation
|
||||
.submit(Op::RequestPermissionPresetResponse {
|
||||
id: request.call_id,
|
||||
response: declined,
|
||||
})
|
||||
.await
|
||||
{
|
||||
error!("failed to submit RequestPermissionPresetResponse: {err}");
|
||||
}
|
||||
}
|
||||
}
|
||||
EventMsg::DynamicToolCallRequest(request) => {
|
||||
if matches!(api_version, ApiVersion::V2) {
|
||||
let call_id = request.call_id;
|
||||
@@ -2518,6 +2578,85 @@ async fn on_request_permissions_response(
|
||||
}
|
||||
}
|
||||
|
||||
async fn on_request_permission_preset_response(
|
||||
call_id: String,
|
||||
preset: PermissionPresetId,
|
||||
pending_request_id: RequestId,
|
||||
receiver: oneshot::Receiver<ClientRequestResult>,
|
||||
conversation: Arc<CodexThread>,
|
||||
thread_state: Arc<Mutex<ThreadState>>,
|
||||
) {
|
||||
let response = receiver.await;
|
||||
resolve_server_request_on_thread_listener(&thread_state, pending_request_id).await;
|
||||
let response = request_permission_preset_response_from_client_result(preset, response);
|
||||
|
||||
if let Err(err) = conversation
|
||||
.submit(Op::RequestPermissionPresetResponse {
|
||||
id: call_id,
|
||||
response,
|
||||
})
|
||||
.await
|
||||
{
|
||||
error!("failed to submit RequestPermissionPresetResponse: {err}");
|
||||
}
|
||||
}
|
||||
|
||||
fn request_permission_preset_response_from_client_result(
|
||||
preset: PermissionPresetId,
|
||||
response: std::result::Result<ClientRequestResult, oneshot::error::RecvError>,
|
||||
) -> CoreRequestPermissionPresetResponse {
|
||||
let value = match response {
|
||||
Ok(Ok(value)) => value,
|
||||
Ok(Err(err)) if is_turn_transition_server_request_error(&err) => {
|
||||
return CoreRequestPermissionPresetResponse {
|
||||
decision: CoreRequestPermissionPresetDecision::Declined,
|
||||
preset,
|
||||
message: "turn transitioned before the permission preset request was resolved"
|
||||
.to_string(),
|
||||
};
|
||||
}
|
||||
Ok(Err(err)) => {
|
||||
error!("request failed with client error: {err:?}");
|
||||
return CoreRequestPermissionPresetResponse {
|
||||
decision: CoreRequestPermissionPresetDecision::Declined,
|
||||
preset,
|
||||
message: "permission preset request failed".to_string(),
|
||||
};
|
||||
}
|
||||
Err(err) => {
|
||||
error!("request failed: {err:?}");
|
||||
return CoreRequestPermissionPresetResponse {
|
||||
decision: CoreRequestPermissionPresetDecision::Declined,
|
||||
preset,
|
||||
message: "permission preset request failed".to_string(),
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
let response = serde_json::from_value::<PermissionPresetRequestApprovalResponse>(value)
|
||||
.unwrap_or_else(|err| {
|
||||
error!("failed to deserialize PermissionPresetRequestApprovalResponse: {err}");
|
||||
PermissionPresetRequestApprovalResponse {
|
||||
decision: PermissionPresetApprovalDecision::Declined,
|
||||
preset: preset.into(),
|
||||
}
|
||||
});
|
||||
let decision = response.decision.to_core();
|
||||
let selected_preset = response.preset.to_core();
|
||||
CoreRequestPermissionPresetResponse {
|
||||
decision,
|
||||
preset: selected_preset,
|
||||
message: match decision {
|
||||
CoreRequestPermissionPresetDecision::Accepted => {
|
||||
"permission preset request accepted".to_string()
|
||||
}
|
||||
CoreRequestPermissionPresetDecision::Declined => {
|
||||
"permission preset request declined".to_string()
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn request_permissions_response_from_client_result(
|
||||
requested_permissions: CoreRequestPermissionProfile,
|
||||
response: std::result::Result<ClientRequestResult, oneshot::error::RecvError>,
|
||||
@@ -3064,6 +3203,7 @@ mod tests {
|
||||
self.thread_manager.clone(),
|
||||
self.outgoing.clone(),
|
||||
self.outgoing.clone(),
|
||||
self.outgoing.clone(),
|
||||
self.thread_state.clone(),
|
||||
self.thread_watch_manager.clone(),
|
||||
ApiVersion::V2,
|
||||
|
||||
@@ -7564,6 +7564,12 @@ impl CodexMessageProcessor {
|
||||
SupportedServerRequestMethod::PermissionsRequestApproval,
|
||||
)
|
||||
.await;
|
||||
let request_permission_preset_connection_ids = thread_state_manager
|
||||
.subscribed_connection_ids_supporting(
|
||||
conversation_id,
|
||||
SupportedServerRequestMethod::PermissionPresetRequestApproval,
|
||||
)
|
||||
.await;
|
||||
let thread_outgoing = ThreadScopedOutgoingMessageSender::new(
|
||||
outgoing_for_task.clone(),
|
||||
subscribed_connection_ids,
|
||||
@@ -7571,6 +7577,8 @@ impl CodexMessageProcessor {
|
||||
);
|
||||
let request_permissions_outgoing = thread_outgoing
|
||||
.with_connection_ids(request_permissions_connection_ids);
|
||||
let request_permission_preset_outgoing = thread_outgoing
|
||||
.with_connection_ids(request_permission_preset_connection_ids);
|
||||
|
||||
if let EventMsg::RawResponseItem(raw_response_item_event) = &event.msg
|
||||
&& !raw_events_enabled
|
||||
@@ -7593,6 +7601,7 @@ impl CodexMessageProcessor {
|
||||
thread_manager.clone(),
|
||||
thread_outgoing,
|
||||
request_permissions_outgoing,
|
||||
request_permission_preset_outgoing,
|
||||
thread_state.clone(),
|
||||
thread_watch_manager.clone(),
|
||||
api_version,
|
||||
@@ -8731,7 +8740,8 @@ async fn apply_surface_capability_feature_gates(
|
||||
gate_permission_tool_feature(
|
||||
config,
|
||||
Feature::RequestPermissionPresetTool,
|
||||
/*surface_supports_tool*/ false,
|
||||
supported_server_requests
|
||||
.contains(&SupportedServerRequestMethod::PermissionPresetRequestApproval),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ pub use models_cache::write_models_cache_with_models;
|
||||
pub use responses::create_apply_patch_sse_response;
|
||||
pub use responses::create_exec_command_sse_response;
|
||||
pub use responses::create_final_assistant_message_sse_response;
|
||||
pub use responses::create_request_permission_preset_sse_response;
|
||||
pub use responses::create_request_permissions_sse_response;
|
||||
pub use responses::create_request_user_input_sse_response;
|
||||
pub use responses::create_shell_command_sse_response;
|
||||
|
||||
@@ -108,3 +108,16 @@ pub fn create_request_permissions_sse_response(
|
||||
responses::ev_completed("resp-1"),
|
||||
]))
|
||||
}
|
||||
|
||||
pub fn create_request_permission_preset_sse_response(call_id: &str) -> anyhow::Result<String> {
|
||||
let tool_call_arguments = serde_json::to_string(&json!({
|
||||
"preset": "full-access",
|
||||
"reason": "User asked for full access"
|
||||
}))?;
|
||||
|
||||
Ok(responses::sse(vec![
|
||||
responses::ev_response_created("resp-1"),
|
||||
responses::ev_function_call(call_id, "request_permission_preset", &tool_call_arguments),
|
||||
responses::ev_completed("resp-1"),
|
||||
]))
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ use anyhow::bail;
|
||||
use app_test_support::McpProcess;
|
||||
use app_test_support::create_final_assistant_message_sse_response;
|
||||
use app_test_support::create_mock_responses_server_sequence;
|
||||
use app_test_support::create_request_permission_preset_sse_response;
|
||||
use app_test_support::create_request_permissions_sse_response;
|
||||
use app_test_support::to_response;
|
||||
use codex_app_server_protocol::ClientInfo;
|
||||
@@ -48,26 +49,26 @@ async fn permission_tools_expose_only_narrow_permission_capability() -> Result<(
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
|
||||
async fn permission_tools_keep_preset_hidden_without_delivery_support() -> Result<()> {
|
||||
async fn permission_tools_expose_only_preset_capability() -> Result<()> {
|
||||
let body = first_responses_request_body_for_supported_server_requests(vec![
|
||||
SupportedServerRequestMethod::PermissionPresetRequestApproval,
|
||||
])
|
||||
.await?;
|
||||
assert_permission_tool_exposure(
|
||||
&body, /*expect_permissions*/ false, /*expect_preset*/ false,
|
||||
&body, /*expect_permissions*/ false, /*expect_preset*/ true,
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
|
||||
async fn permission_tools_expose_only_the_narrow_flow_for_now() -> Result<()> {
|
||||
async fn permission_tools_expose_both_supported_capabilities() -> Result<()> {
|
||||
let body = first_responses_request_body_for_supported_server_requests(vec![
|
||||
SupportedServerRequestMethod::PermissionsRequestApproval,
|
||||
SupportedServerRequestMethod::PermissionPresetRequestApproval,
|
||||
])
|
||||
.await?;
|
||||
assert_permission_tool_exposure(
|
||||
&body, /*expect_permissions*/ true, /*expect_preset*/ false,
|
||||
&body, /*expect_permissions*/ true, /*expect_preset*/ true,
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
@@ -185,6 +186,93 @@ async fn request_permissions_auto_declines_without_app_request() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
|
||||
async fn request_permission_preset_round_trips_when_client_supports_app_request() -> Result<()> {
|
||||
let codex_home = tempfile::TempDir::new()?;
|
||||
let responses = vec![
|
||||
create_request_permission_preset_sse_response("call1")?,
|
||||
create_final_assistant_message_sse_response("done")?,
|
||||
];
|
||||
let server = create_mock_responses_server_sequence(responses).await;
|
||||
create_config_toml(codex_home.path(), &server.uri())?;
|
||||
|
||||
let mut mcp = McpProcess::new(codex_home.path()).await?;
|
||||
initialize_with_supported_server_requests(
|
||||
&mut mcp,
|
||||
vec![SupportedServerRequestMethod::PermissionPresetRequestApproval],
|
||||
)
|
||||
.await?;
|
||||
|
||||
let thread_id = start_thread_and_turn(&mut mcp, "make this session full access").await?;
|
||||
|
||||
let server_request = timeout(
|
||||
DEFAULT_READ_TIMEOUT,
|
||||
mcp.read_stream_until_request_message(),
|
||||
)
|
||||
.await??;
|
||||
let ServerRequest::PermissionPresetRequestApproval { request_id, params } = server_request
|
||||
else {
|
||||
bail!("expected PermissionPresetRequestApproval request");
|
||||
};
|
||||
assert_eq!(params.thread_id, thread_id);
|
||||
assert_eq!(params.item_id, "call1");
|
||||
assert_eq!(params.label, "Full Access");
|
||||
let resolved_request_id = request_id.clone();
|
||||
|
||||
mcp.send_response(
|
||||
request_id,
|
||||
json!({
|
||||
"decision": "accepted",
|
||||
"preset": "full-access",
|
||||
}),
|
||||
)
|
||||
.await?;
|
||||
|
||||
wait_for_server_request_resolved_then_turn_completed(&mut mcp, &thread_id, resolved_request_id)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
|
||||
async fn request_permission_preset_auto_declines_without_app_request() -> Result<()> {
|
||||
let codex_home = tempfile::TempDir::new()?;
|
||||
let responses = vec![
|
||||
create_request_permission_preset_sse_response("call1")?,
|
||||
create_final_assistant_message_sse_response("done")?,
|
||||
];
|
||||
let server = create_mock_responses_server_sequence(responses).await;
|
||||
create_config_toml(codex_home.path(), &server.uri())?;
|
||||
|
||||
let mut mcp = McpProcess::new(codex_home.path()).await?;
|
||||
timeout(DEFAULT_READ_TIMEOUT, mcp.initialize()).await??;
|
||||
|
||||
start_thread_and_turn(&mut mcp, "make this session full access").await?;
|
||||
wait_for_turn_completed_without_server_request(&mut mcp).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
|
||||
async fn request_permission_preset_auto_declines_with_only_permissions_capability() -> Result<()> {
|
||||
let codex_home = tempfile::TempDir::new()?;
|
||||
let responses = vec![
|
||||
create_request_permission_preset_sse_response("call1")?,
|
||||
create_final_assistant_message_sse_response("done")?,
|
||||
];
|
||||
let server = create_mock_responses_server_sequence(responses).await;
|
||||
create_config_toml(codex_home.path(), &server.uri())?;
|
||||
|
||||
let mut mcp = McpProcess::new(codex_home.path()).await?;
|
||||
initialize_with_supported_server_requests(
|
||||
&mut mcp,
|
||||
vec![SupportedServerRequestMethod::PermissionsRequestApproval],
|
||||
)
|
||||
.await?;
|
||||
|
||||
start_thread_and_turn(&mut mcp, "make this session full access").await?;
|
||||
wait_for_turn_completed_without_server_request(&mut mcp).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn initialize_with_supported_server_requests(
|
||||
mcp: &mut McpProcess,
|
||||
supported_server_requests: Vec<SupportedServerRequestMethod>,
|
||||
|
||||
@@ -1510,6 +1510,18 @@ async fn handle_server_request(
|
||||
)
|
||||
.await
|
||||
}
|
||||
ServerRequest::PermissionPresetRequestApproval { request_id, params } => {
|
||||
reject_server_request(
|
||||
client,
|
||||
request_id,
|
||||
&method,
|
||||
format!(
|
||||
"permission preset approval is not supported in exec mode for thread `{}`",
|
||||
params.thread_id
|
||||
),
|
||||
)
|
||||
.await
|
||||
}
|
||||
};
|
||||
|
||||
if let Err(err) = handle_result {
|
||||
|
||||
Reference in New Issue
Block a user