Merge branch 'main' into dev/stevenlee/mcp-oauth-refresh-transaction

This commit is contained in:
stevenlee-oai
2026-06-18 19:48:12 -04:00
committed by GitHub
129 changed files with 4473 additions and 904 deletions
+1
View File
@@ -2418,6 +2418,7 @@ version = "0.0.0"
dependencies = [
"base64 0.22.1",
"chrono",
"codex-agent-identity",
"codex-backend-client",
"codex-config",
"codex-core",
@@ -4121,6 +4121,7 @@ async fn turn_event_counts_completed_tool_items() {
tool: "search".to_string(),
status,
arguments: json!({}),
app_context: None,
mcp_app_resource_uri: None,
plugin_id: Some("sample@test".to_string()),
result: None,
@@ -2396,6 +2396,29 @@
],
"type": "object"
},
"McpToolCallAppContext": {
"properties": {
"connectorId": {
"type": "string"
},
"linkId": {
"type": [
"string",
"null"
]
},
"resourceUri": {
"type": [
"string",
"null"
]
}
},
"required": [
"connectorId"
],
"type": "object"
},
"McpToolCallError": {
"properties": {
"message": {
@@ -4066,6 +4089,16 @@
},
{
"properties": {
"appContext": {
"anyOf": [
{
"$ref": "#/definitions/McpToolCallAppContext"
},
{
"type": "null"
}
]
},
"arguments": true,
"durationMs": {
"description": "The duration of the MCP tool call in milliseconds.",
@@ -4089,6 +4122,7 @@
"type": "string"
},
"mcpAppResourceUri": {
"description": "Deprecated: use `appContext.resourceUri` instead.",
"type": [
"string",
"null"
@@ -12119,6 +12119,29 @@
"title": "McpServerToolCallResponse",
"type": "object"
},
"McpToolCallAppContext": {
"properties": {
"connectorId": {
"type": "string"
},
"linkId": {
"type": [
"string",
"null"
]
},
"resourceUri": {
"type": [
"string",
"null"
]
}
},
"required": [
"connectorId"
],
"type": "object"
},
"McpToolCallError": {
"properties": {
"message": {
@@ -16950,9 +16973,9 @@
},
"instructionSources": {
"default": [],
"description": "Instruction source files currently loaded for this thread.",
"description": "Environment-native paths to instruction source files currently loaded for this thread.",
"items": {
"$ref": "#/definitions/v2/AbsolutePathBuf"
"$ref": "#/definitions/v2/LegacyAppPathString"
},
"type": "array"
},
@@ -17511,6 +17534,16 @@
},
{
"properties": {
"appContext": {
"anyOf": [
{
"$ref": "#/definitions/v2/McpToolCallAppContext"
},
{
"type": "null"
}
]
},
"arguments": true,
"durationMs": {
"description": "The duration of the MCP tool call in milliseconds.",
@@ -17534,6 +17567,7 @@
"type": "string"
},
"mcpAppResourceUri": {
"description": "Deprecated: use `appContext.resourceUri` instead.",
"type": [
"string",
"null"
@@ -18654,9 +18688,9 @@
},
"instructionSources": {
"default": [],
"description": "Instruction source files currently loaded for this thread.",
"description": "Environment-native paths to instruction source files currently loaded for this thread.",
"items": {
"$ref": "#/definitions/v2/AbsolutePathBuf"
"$ref": "#/definitions/v2/LegacyAppPathString"
},
"type": "array"
},
@@ -19071,9 +19105,9 @@
},
"instructionSources": {
"default": [],
"description": "Instruction source files currently loaded for this thread.",
"description": "Environment-native paths to instruction source files currently loaded for this thread.",
"items": {
"$ref": "#/definitions/v2/AbsolutePathBuf"
"$ref": "#/definitions/v2/LegacyAppPathString"
},
"type": "array"
},
@@ -8543,6 +8543,29 @@
"title": "McpServerToolCallResponse",
"type": "object"
},
"McpToolCallAppContext": {
"properties": {
"connectorId": {
"type": "string"
},
"linkId": {
"type": [
"string",
"null"
]
},
"resourceUri": {
"type": [
"string",
"null"
]
}
},
"required": [
"connectorId"
],
"type": "object"
},
"McpToolCallError": {
"properties": {
"message": {
@@ -14729,9 +14752,9 @@
},
"instructionSources": {
"default": [],
"description": "Instruction source files currently loaded for this thread.",
"description": "Environment-native paths to instruction source files currently loaded for this thread.",
"items": {
"$ref": "#/definitions/AbsolutePathBuf"
"$ref": "#/definitions/LegacyAppPathString"
},
"type": "array"
},
@@ -15290,6 +15313,16 @@
},
{
"properties": {
"appContext": {
"anyOf": [
{
"$ref": "#/definitions/McpToolCallAppContext"
},
{
"type": "null"
}
]
},
"arguments": true,
"durationMs": {
"description": "The duration of the MCP tool call in milliseconds.",
@@ -15313,6 +15346,7 @@
"type": "string"
},
"mcpAppResourceUri": {
"description": "Deprecated: use `appContext.resourceUri` instead.",
"type": [
"string",
"null"
@@ -16433,9 +16467,9 @@
},
"instructionSources": {
"default": [],
"description": "Instruction source files currently loaded for this thread.",
"description": "Environment-native paths to instruction source files currently loaded for this thread.",
"items": {
"$ref": "#/definitions/AbsolutePathBuf"
"$ref": "#/definitions/LegacyAppPathString"
},
"type": "array"
},
@@ -16850,9 +16884,9 @@
},
"instructionSources": {
"default": [],
"description": "Instruction source files currently loaded for this thread.",
"description": "Environment-native paths to instruction source files currently loaded for this thread.",
"items": {
"$ref": "#/definitions/AbsolutePathBuf"
"$ref": "#/definitions/LegacyAppPathString"
},
"type": "array"
},
@@ -297,6 +297,29 @@
"LegacyAppPathString": {
"type": "string"
},
"McpToolCallAppContext": {
"properties": {
"connectorId": {
"type": "string"
},
"linkId": {
"type": [
"string",
"null"
]
},
"resourceUri": {
"type": [
"string",
"null"
]
}
},
"required": [
"connectorId"
],
"type": "object"
},
"McpToolCallError": {
"properties": {
"message": {
@@ -784,6 +807,16 @@
},
{
"properties": {
"appContext": {
"anyOf": [
{
"$ref": "#/definitions/McpToolCallAppContext"
},
{
"type": "null"
}
]
},
"arguments": true,
"durationMs": {
"description": "The duration of the MCP tool call in milliseconds.",
@@ -807,6 +840,7 @@
"type": "string"
},
"mcpAppResourceUri": {
"description": "Deprecated: use `appContext.resourceUri` instead.",
"type": [
"string",
"null"
@@ -297,6 +297,29 @@
"LegacyAppPathString": {
"type": "string"
},
"McpToolCallAppContext": {
"properties": {
"connectorId": {
"type": "string"
},
"linkId": {
"type": [
"string",
"null"
]
},
"resourceUri": {
"type": [
"string",
"null"
]
}
},
"required": [
"connectorId"
],
"type": "object"
},
"McpToolCallError": {
"properties": {
"message": {
@@ -784,6 +807,16 @@
},
{
"properties": {
"appContext": {
"anyOf": [
{
"$ref": "#/definitions/McpToolCallAppContext"
},
{
"type": "null"
}
]
},
"arguments": true,
"durationMs": {
"description": "The duration of the MCP tool call in milliseconds.",
@@ -807,6 +840,7 @@
"type": "string"
},
"mcpAppResourceUri": {
"description": "Deprecated: use `appContext.resourceUri` instead.",
"type": [
"string",
"null"
@@ -434,6 +434,29 @@
"LegacyAppPathString": {
"type": "string"
},
"McpToolCallAppContext": {
"properties": {
"connectorId": {
"type": "string"
},
"linkId": {
"type": [
"string",
"null"
]
},
"resourceUri": {
"type": [
"string",
"null"
]
}
},
"required": [
"connectorId"
],
"type": "object"
},
"McpToolCallError": {
"properties": {
"message": {
@@ -928,6 +951,16 @@
},
{
"properties": {
"appContext": {
"anyOf": [
{
"$ref": "#/definitions/McpToolCallAppContext"
},
{
"type": "null"
}
]
},
"arguments": true,
"durationMs": {
"description": "The duration of the MCP tool call in milliseconds.",
@@ -951,6 +984,7 @@
"type": "string"
},
"mcpAppResourceUri": {
"description": "Deprecated: use `appContext.resourceUri` instead.",
"type": [
"string",
"null"
@@ -539,6 +539,29 @@
"LegacyAppPathString": {
"type": "string"
},
"McpToolCallAppContext": {
"properties": {
"connectorId": {
"type": "string"
},
"linkId": {
"type": [
"string",
"null"
]
},
"resourceUri": {
"type": [
"string",
"null"
]
}
},
"required": [
"connectorId"
],
"type": "object"
},
"McpToolCallError": {
"properties": {
"message": {
@@ -1420,6 +1443,16 @@
},
{
"properties": {
"appContext": {
"anyOf": [
{
"$ref": "#/definitions/McpToolCallAppContext"
},
{
"type": "null"
}
]
},
"arguments": true,
"durationMs": {
"description": "The duration of the MCP tool call in milliseconds.",
@@ -1443,6 +1476,7 @@
"type": "string"
},
"mcpAppResourceUri": {
"description": "Deprecated: use `appContext.resourceUri` instead.",
"type": [
"string",
"null"
@@ -2334,9 +2368,9 @@
},
"instructionSources": {
"default": [],
"description": "Instruction source files currently loaded for this thread.",
"description": "Environment-native paths to instruction source files currently loaded for this thread.",
"items": {
"$ref": "#/definitions/AbsolutePathBuf"
"$ref": "#/definitions/LegacyAppPathString"
},
"type": "array"
},
@@ -460,6 +460,29 @@
"LegacyAppPathString": {
"type": "string"
},
"McpToolCallAppContext": {
"properties": {
"connectorId": {
"type": "string"
},
"linkId": {
"type": [
"string",
"null"
]
},
"resourceUri": {
"type": [
"string",
"null"
]
}
},
"required": [
"connectorId"
],
"type": "object"
},
"McpToolCallError": {
"properties": {
"message": {
@@ -1235,6 +1258,16 @@
},
{
"properties": {
"appContext": {
"anyOf": [
{
"$ref": "#/definitions/McpToolCallAppContext"
},
{
"type": "null"
}
]
},
"arguments": true,
"durationMs": {
"description": "The duration of the MCP tool call in milliseconds.",
@@ -1258,6 +1291,7 @@
"type": "string"
},
"mcpAppResourceUri": {
"description": "Deprecated: use `appContext.resourceUri` instead.",
"type": [
"string",
"null"
@@ -460,6 +460,29 @@
"LegacyAppPathString": {
"type": "string"
},
"McpToolCallAppContext": {
"properties": {
"connectorId": {
"type": "string"
},
"linkId": {
"type": [
"string",
"null"
]
},
"resourceUri": {
"type": [
"string",
"null"
]
}
},
"required": [
"connectorId"
],
"type": "object"
},
"McpToolCallError": {
"properties": {
"message": {
@@ -1235,6 +1258,16 @@
},
{
"properties": {
"appContext": {
"anyOf": [
{
"$ref": "#/definitions/McpToolCallAppContext"
},
{
"type": "null"
}
]
},
"arguments": true,
"durationMs": {
"description": "The duration of the MCP tool call in milliseconds.",
@@ -1258,6 +1291,7 @@
"type": "string"
},
"mcpAppResourceUri": {
"description": "Deprecated: use `appContext.resourceUri` instead.",
"type": [
"string",
"null"
@@ -460,6 +460,29 @@
"LegacyAppPathString": {
"type": "string"
},
"McpToolCallAppContext": {
"properties": {
"connectorId": {
"type": "string"
},
"linkId": {
"type": [
"string",
"null"
]
},
"resourceUri": {
"type": [
"string",
"null"
]
}
},
"required": [
"connectorId"
],
"type": "object"
},
"McpToolCallError": {
"properties": {
"message": {
@@ -1235,6 +1258,16 @@
},
{
"properties": {
"appContext": {
"anyOf": [
{
"$ref": "#/definitions/McpToolCallAppContext"
},
{
"type": "null"
}
]
},
"arguments": true,
"durationMs": {
"description": "The duration of the MCP tool call in milliseconds.",
@@ -1258,6 +1291,7 @@
"type": "string"
},
"mcpAppResourceUri": {
"description": "Deprecated: use `appContext.resourceUri` instead.",
"type": [
"string",
"null"
@@ -539,6 +539,29 @@
"LegacyAppPathString": {
"type": "string"
},
"McpToolCallAppContext": {
"properties": {
"connectorId": {
"type": "string"
},
"linkId": {
"type": [
"string",
"null"
]
},
"resourceUri": {
"type": [
"string",
"null"
]
}
},
"required": [
"connectorId"
],
"type": "object"
},
"McpToolCallError": {
"properties": {
"message": {
@@ -1420,6 +1443,16 @@
},
{
"properties": {
"appContext": {
"anyOf": [
{
"$ref": "#/definitions/McpToolCallAppContext"
},
{
"type": "null"
}
]
},
"arguments": true,
"durationMs": {
"description": "The duration of the MCP tool call in milliseconds.",
@@ -1443,6 +1476,7 @@
"type": "string"
},
"mcpAppResourceUri": {
"description": "Deprecated: use `appContext.resourceUri` instead.",
"type": [
"string",
"null"
@@ -2360,9 +2394,9 @@
},
"instructionSources": {
"default": [],
"description": "Instruction source files currently loaded for this thread.",
"description": "Environment-native paths to instruction source files currently loaded for this thread.",
"items": {
"$ref": "#/definitions/AbsolutePathBuf"
"$ref": "#/definitions/LegacyAppPathString"
},
"type": "array"
},
@@ -460,6 +460,29 @@
"LegacyAppPathString": {
"type": "string"
},
"McpToolCallAppContext": {
"properties": {
"connectorId": {
"type": "string"
},
"linkId": {
"type": [
"string",
"null"
]
},
"resourceUri": {
"type": [
"string",
"null"
]
}
},
"required": [
"connectorId"
],
"type": "object"
},
"McpToolCallError": {
"properties": {
"message": {
@@ -1235,6 +1258,16 @@
},
{
"properties": {
"appContext": {
"anyOf": [
{
"$ref": "#/definitions/McpToolCallAppContext"
},
{
"type": "null"
}
]
},
"arguments": true,
"durationMs": {
"description": "The duration of the MCP tool call in milliseconds.",
@@ -1258,6 +1291,7 @@
"type": "string"
},
"mcpAppResourceUri": {
"description": "Deprecated: use `appContext.resourceUri` instead.",
"type": [
"string",
"null"
@@ -539,6 +539,29 @@
"LegacyAppPathString": {
"type": "string"
},
"McpToolCallAppContext": {
"properties": {
"connectorId": {
"type": "string"
},
"linkId": {
"type": [
"string",
"null"
]
},
"resourceUri": {
"type": [
"string",
"null"
]
}
},
"required": [
"connectorId"
],
"type": "object"
},
"McpToolCallError": {
"properties": {
"message": {
@@ -1420,6 +1443,16 @@
},
{
"properties": {
"appContext": {
"anyOf": [
{
"$ref": "#/definitions/McpToolCallAppContext"
},
{
"type": "null"
}
]
},
"arguments": true,
"durationMs": {
"description": "The duration of the MCP tool call in milliseconds.",
@@ -1443,6 +1476,7 @@
"type": "string"
},
"mcpAppResourceUri": {
"description": "Deprecated: use `appContext.resourceUri` instead.",
"type": [
"string",
"null"
@@ -2334,9 +2368,9 @@
},
"instructionSources": {
"default": [],
"description": "Instruction source files currently loaded for this thread.",
"description": "Environment-native paths to instruction source files currently loaded for this thread.",
"items": {
"$ref": "#/definitions/AbsolutePathBuf"
"$ref": "#/definitions/LegacyAppPathString"
},
"type": "array"
},
@@ -460,6 +460,29 @@
"LegacyAppPathString": {
"type": "string"
},
"McpToolCallAppContext": {
"properties": {
"connectorId": {
"type": "string"
},
"linkId": {
"type": [
"string",
"null"
]
},
"resourceUri": {
"type": [
"string",
"null"
]
}
},
"required": [
"connectorId"
],
"type": "object"
},
"McpToolCallError": {
"properties": {
"message": {
@@ -1235,6 +1258,16 @@
},
{
"properties": {
"appContext": {
"anyOf": [
{
"$ref": "#/definitions/McpToolCallAppContext"
},
{
"type": "null"
}
]
},
"arguments": true,
"durationMs": {
"description": "The duration of the MCP tool call in milliseconds.",
@@ -1258,6 +1291,7 @@
"type": "string"
},
"mcpAppResourceUri": {
"description": "Deprecated: use `appContext.resourceUri` instead.",
"type": [
"string",
"null"
@@ -460,6 +460,29 @@
"LegacyAppPathString": {
"type": "string"
},
"McpToolCallAppContext": {
"properties": {
"connectorId": {
"type": "string"
},
"linkId": {
"type": [
"string",
"null"
]
},
"resourceUri": {
"type": [
"string",
"null"
]
}
},
"required": [
"connectorId"
],
"type": "object"
},
"McpToolCallError": {
"properties": {
"message": {
@@ -1235,6 +1258,16 @@
},
{
"properties": {
"appContext": {
"anyOf": [
{
"$ref": "#/definitions/McpToolCallAppContext"
},
{
"type": "null"
}
]
},
"arguments": true,
"durationMs": {
"description": "The duration of the MCP tool call in milliseconds.",
@@ -1258,6 +1291,7 @@
"type": "string"
},
"mcpAppResourceUri": {
"description": "Deprecated: use `appContext.resourceUri` instead.",
"type": [
"string",
"null"
@@ -434,6 +434,29 @@
"LegacyAppPathString": {
"type": "string"
},
"McpToolCallAppContext": {
"properties": {
"connectorId": {
"type": "string"
},
"linkId": {
"type": [
"string",
"null"
]
},
"resourceUri": {
"type": [
"string",
"null"
]
}
},
"required": [
"connectorId"
],
"type": "object"
},
"McpToolCallError": {
"properties": {
"message": {
@@ -928,6 +951,16 @@
},
{
"properties": {
"appContext": {
"anyOf": [
{
"$ref": "#/definitions/McpToolCallAppContext"
},
{
"type": "null"
}
]
},
"arguments": true,
"durationMs": {
"description": "The duration of the MCP tool call in milliseconds.",
@@ -951,6 +984,7 @@
"type": "string"
},
"mcpAppResourceUri": {
"description": "Deprecated: use `appContext.resourceUri` instead.",
"type": [
"string",
"null"
@@ -434,6 +434,29 @@
"LegacyAppPathString": {
"type": "string"
},
"McpToolCallAppContext": {
"properties": {
"connectorId": {
"type": "string"
},
"linkId": {
"type": [
"string",
"null"
]
},
"resourceUri": {
"type": [
"string",
"null"
]
}
},
"required": [
"connectorId"
],
"type": "object"
},
"McpToolCallError": {
"properties": {
"message": {
@@ -928,6 +951,16 @@
},
{
"properties": {
"appContext": {
"anyOf": [
{
"$ref": "#/definitions/McpToolCallAppContext"
},
{
"type": "null"
}
]
},
"arguments": true,
"durationMs": {
"description": "The duration of the MCP tool call in milliseconds.",
@@ -951,6 +984,7 @@
"type": "string"
},
"mcpAppResourceUri": {
"description": "Deprecated: use `appContext.resourceUri` instead.",
"type": [
"string",
"null"
@@ -434,6 +434,29 @@
"LegacyAppPathString": {
"type": "string"
},
"McpToolCallAppContext": {
"properties": {
"connectorId": {
"type": "string"
},
"linkId": {
"type": [
"string",
"null"
]
},
"resourceUri": {
"type": [
"string",
"null"
]
}
},
"required": [
"connectorId"
],
"type": "object"
},
"McpToolCallError": {
"properties": {
"message": {
@@ -928,6 +951,16 @@
},
{
"properties": {
"appContext": {
"anyOf": [
{
"$ref": "#/definitions/McpToolCallAppContext"
},
{
"type": "null"
}
]
},
"arguments": true,
"durationMs": {
"description": "The duration of the MCP tool call in milliseconds.",
@@ -951,6 +984,7 @@
"type": "string"
},
"mcpAppResourceUri": {
"description": "Deprecated: use `appContext.resourceUri` instead.",
"type": [
"string",
"null"
@@ -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 McpToolCallAppContext = { connectorId: string, linkId: string | null, resourceUri: string | null, };
@@ -2,6 +2,7 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { AbsolutePathBuf } from "../AbsolutePathBuf";
import type { LegacyAppPathString } from "../LegacyAppPathString";
import type { ReasoningEffort } from "../ReasoningEffort";
import type { ApprovalsReviewer } from "./ApprovalsReviewer";
import type { AskForApproval } from "./AskForApproval";
@@ -9,9 +10,9 @@ import type { SandboxPolicy } from "./SandboxPolicy";
import type { Thread } from "./Thread";
export type ThreadForkResponse = {thread: Thread, model: string, modelProvider: string, serviceTier: string | null, cwd: AbsolutePathBuf, /**
* Instruction source files currently loaded for this thread.
* Environment-native paths to instruction source files currently loaded for this thread.
*/
instructionSources: Array<AbsolutePathBuf>, approvalPolicy: AskForApproval, /**
instructionSources: Array<LegacyAppPathString>, approvalPolicy: AskForApproval, /**
* Reviewer currently used for approval requests on this thread.
*/
approvalsReviewer: ApprovalsReviewer, /**
@@ -16,6 +16,7 @@ import type { DynamicToolCallOutputContentItem } from "./DynamicToolCallOutputCo
import type { DynamicToolCallStatus } from "./DynamicToolCallStatus";
import type { FileUpdateChange } from "./FileUpdateChange";
import type { HookPromptFragment } from "./HookPromptFragment";
import type { McpToolCallAppContext } from "./McpToolCallAppContext";
import type { McpToolCallError } from "./McpToolCallError";
import type { McpToolCallResult } from "./McpToolCallResult";
import type { McpToolCallStatus } from "./McpToolCallStatus";
@@ -55,7 +56,11 @@ exitCode: number | null,
/**
* The duration of the command execution in milliseconds.
*/
durationMs: number | null, } | { "type": "fileChange", id: string, changes: Array<FileUpdateChange>, status: PatchApplyStatus, } | { "type": "mcpToolCall", id: string, server: string, tool: string, status: McpToolCallStatus, arguments: JsonValue, mcpAppResourceUri?: string, pluginId: string | null, result: McpToolCallResult | null, error: McpToolCallError | null,
durationMs: number | null, } | { "type": "fileChange", id: string, changes: Array<FileUpdateChange>, status: PatchApplyStatus, } | { "type": "mcpToolCall", id: string, server: string, tool: string, status: McpToolCallStatus, arguments: JsonValue, appContext: McpToolCallAppContext | null,
/**
* Deprecated: use `appContext.resourceUri` instead.
*/
mcpAppResourceUri?: string, pluginId: string | null, result: McpToolCallResult | null, error: McpToolCallError | null,
/**
* The duration of the MCP tool call in milliseconds.
*/
@@ -2,6 +2,7 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { AbsolutePathBuf } from "../AbsolutePathBuf";
import type { LegacyAppPathString } from "../LegacyAppPathString";
import type { ReasoningEffort } from "../ReasoningEffort";
import type { ApprovalsReviewer } from "./ApprovalsReviewer";
import type { AskForApproval } from "./AskForApproval";
@@ -9,9 +10,9 @@ import type { SandboxPolicy } from "./SandboxPolicy";
import type { Thread } from "./Thread";
export type ThreadResumeResponse = {thread: Thread, model: string, modelProvider: string, serviceTier: string | null, cwd: AbsolutePathBuf, /**
* Instruction source files currently loaded for this thread.
* Environment-native paths to instruction source files currently loaded for this thread.
*/
instructionSources: Array<AbsolutePathBuf>, approvalPolicy: AskForApproval, /**
instructionSources: Array<LegacyAppPathString>, approvalPolicy: AskForApproval, /**
* Reviewer currently used for approval requests on this thread.
*/
approvalsReviewer: ApprovalsReviewer, /**
@@ -2,6 +2,7 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { AbsolutePathBuf } from "../AbsolutePathBuf";
import type { LegacyAppPathString } from "../LegacyAppPathString";
import type { ReasoningEffort } from "../ReasoningEffort";
import type { ApprovalsReviewer } from "./ApprovalsReviewer";
import type { AskForApproval } from "./AskForApproval";
@@ -9,9 +10,9 @@ import type { SandboxPolicy } from "./SandboxPolicy";
import type { Thread } from "./Thread";
export type ThreadStartResponse = {thread: Thread, model: string, modelProvider: string, serviceTier: string | null, cwd: AbsolutePathBuf, /**
* Instruction source files currently loaded for this thread.
* Environment-native paths to instruction source files currently loaded for this thread.
*/
instructionSources: Array<AbsolutePathBuf>, approvalPolicy: AskForApproval, /**
instructionSources: Array<LegacyAppPathString>, approvalPolicy: AskForApproval, /**
* Reviewer currently used for approval requests on this thread.
*/
approvalsReviewer: ApprovalsReviewer, /**
@@ -243,6 +243,7 @@ export type { McpServerStatusDetail } from "./McpServerStatusDetail";
export type { McpServerStatusUpdatedNotification } from "./McpServerStatusUpdatedNotification";
export type { McpServerToolCallParams } from "./McpServerToolCallParams";
export type { McpServerToolCallResponse } from "./McpServerToolCallResponse";
export type { McpToolCallAppContext } from "./McpToolCallAppContext";
export type { McpToolCallError } from "./McpToolCallError";
export type { McpToolCallProgressNotification } from "./McpToolCallProgressNotification";
export type { McpToolCallResult } from "./McpToolCallResult";
@@ -2573,7 +2573,11 @@ mod tests {
service_tier: None,
cwd,
runtime_workspace_roots: Vec::new(),
instruction_sources: vec![absolute_path("/tmp/AGENTS.md")],
instruction_sources: vec![
codex_utils_path_uri::LegacyAppPathString::from_abs_path(&absolute_path(
"/tmp/AGENTS.md",
)),
],
approval_policy: v2::AskForApproval::OnFailure,
approvals_reviewer: v2::ApprovalsReviewer::User,
sandbox: v2::SandboxPolicy::DangerFullAccess,
@@ -10,6 +10,7 @@ use crate::protocol::v2::CollabAgentToolCallStatus;
use crate::protocol::v2::CommandExecutionStatus;
use crate::protocol::v2::DynamicToolCallOutputContentItem;
use crate::protocol::v2::DynamicToolCallStatus;
use crate::protocol::v2::McpToolCallAppContext;
use crate::protocol::v2::McpToolCallError;
use crate::protocol::v2::McpToolCallResult;
use crate::protocol::v2::McpToolCallStatus;
@@ -765,6 +766,14 @@ impl ThreadHistoryBuilder {
.arguments
.clone()
.unwrap_or(serde_json::Value::Null),
app_context: payload
.connector_id
.clone()
.map(|connector_id| McpToolCallAppContext {
connector_id,
link_id: payload.link_id.clone(),
resource_uri: payload.mcp_app_resource_uri.clone(),
}),
mcp_app_resource_uri: payload.mcp_app_resource_uri.clone(),
plugin_id: payload.plugin_id.clone(),
result: None,
@@ -807,6 +816,14 @@ impl ThreadHistoryBuilder {
.arguments
.clone()
.unwrap_or(serde_json::Value::Null),
app_context: payload
.connector_id
.clone()
.map(|connector_id| McpToolCallAppContext {
connector_id,
link_id: payload.link_id.clone(),
resource_uri: payload.mcp_app_resource_uri.clone(),
}),
mcp_app_resource_uri: payload.mcp_app_resource_uri.clone(),
plugin_id: payload.plugin_id.clone(),
result,
@@ -1567,7 +1584,6 @@ mod tests {
use codex_protocol::protocol::DynamicToolCallResponseEvent;
use codex_protocol::protocol::ExecCommandEndEvent;
use codex_protocol::protocol::ExecCommandSource;
use codex_protocol::protocol::ItemCompletedEvent;
use codex_protocol::protocol::ItemStartedEvent;
use codex_protocol::protocol::McpInvocation;
use codex_protocol::protocol::McpToolCallEndEvent;
@@ -2397,7 +2413,9 @@ mod tests {
tool: "lookup".into(),
arguments: Some(serde_json::json!({"id":"123"})),
},
connector_id: None,
mcp_app_resource_uri: None,
link_id: None,
plugin_id: None,
duration: Duration::from_millis(8),
result: Err("boom".into()),
@@ -2447,6 +2465,7 @@ mod tests {
tool: "lookup".into(),
status: McpToolCallStatus::Failed,
arguments: serde_json::json!({"id":"123"}),
app_context: None,
mcp_app_resource_uri: None,
plugin_id: None,
result: None,
@@ -2475,7 +2494,9 @@ mod tests {
tool: "lookup".into(),
arguments: Some(serde_json::json!({"id":"123"})),
},
connector_id: Some("calendar".into()),
mcp_app_resource_uri: Some("ui://widget/lookup.html".into()),
link_id: Some("link_calendar".into()),
plugin_id: Some("sample@test".into()),
duration: Duration::from_millis(8),
result: Ok(CallToolResult {
@@ -2506,6 +2527,11 @@ mod tests {
tool: "lookup".into(),
status: McpToolCallStatus::Completed,
arguments: serde_json::json!({"id":"123"}),
app_context: Some(McpToolCallAppContext {
connector_id: "calendar".into(),
link_id: Some("link_calendar".into()),
resource_uri: Some("ui://widget/lookup.html".into()),
}),
mcp_app_resource_uri: Some("ui://widget/lookup.html".into()),
plugin_id: Some("sample@test".into()),
result: Some(Box::new(McpToolCallResult {
@@ -290,8 +290,10 @@ pub enum ThreadItem {
tool: String,
status: McpToolCallStatus,
arguments: JsonValue,
app_context: Option<McpToolCallAppContext>,
#[serde(default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
/// Deprecated: use `appContext.resourceUri` instead.
mcp_app_resource_uri: Option<String>,
plugin_id: Option<String>,
result: Option<Box<McpToolCallResult>>,
@@ -384,6 +386,15 @@ pub enum ThreadItem {
ContextCompaction { id: String },
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(rename_all = "camelCase", export_to = "v2/")]
pub struct McpToolCallAppContext {
pub connector_id: String,
pub link_id: Option<String>,
pub resource_uri: Option<String>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(rename_all = "camelCase", export_to = "v2/")]
@@ -877,6 +888,11 @@ impl From<CoreTurnItem> for ThreadItem {
tool: mcp.tool,
status: McpToolCallStatus::from(mcp.status),
arguments: mcp.arguments,
app_context: mcp.connector_id.map(|connector_id| McpToolCallAppContext {
connector_id,
link_id: mcp.link_id,
resource_uri: mcp.mcp_app_resource_uri.clone(),
}),
mcp_app_resource_uri: mcp.mcp_app_resource_uri,
plugin_id: mcp.plugin_id,
result: mcp.result.map(McpToolCallResult::from).map(Box::new),
@@ -36,6 +36,7 @@ use codex_utils_absolute_path::AbsolutePathBuf;
use codex_utils_absolute_path::test_support::PathBufExt;
use codex_utils_absolute_path::test_support::test_path_buf;
use codex_utils_path_uri::LegacyAppPathString;
use codex_utils_path_uri::PathUri;
use pretty_assertions::assert_eq;
use serde_json::Value as JsonValue;
use serde_json::json;
@@ -2615,7 +2616,9 @@ fn core_turn_item_into_thread_item_converts_supported_variants() {
server: "server".to_string(),
tool: "tool".to_string(),
arguments: json!({"arg": "value"}),
connector_id: Some("calendar".to_string()),
mcp_app_resource_uri: Some("app://connector".to_string()),
link_id: Some("link_calendar".to_string()),
plugin_id: Some("sample@test".to_string()),
status: CoreMcpToolCallStatus::InProgress,
result: None,
@@ -2631,6 +2634,11 @@ fn core_turn_item_into_thread_item_converts_supported_variants() {
tool: "tool".to_string(),
status: McpToolCallStatus::InProgress,
arguments: json!({"arg": "value"}),
app_context: Some(McpToolCallAppContext {
connector_id: "calendar".to_string(),
link_id: Some("link_calendar".to_string()),
resource_uri: Some("app://connector".to_string()),
}),
mcp_app_resource_uri: Some("app://connector".to_string()),
plugin_id: Some("sample@test".to_string()),
result: None,
@@ -2644,7 +2652,9 @@ fn core_turn_item_into_thread_item_converts_supported_variants() {
server: "server".to_string(),
tool: "tool".to_string(),
arguments: JsonValue::Null,
connector_id: None,
mcp_app_resource_uri: None,
link_id: None,
plugin_id: None,
status: CoreMcpToolCallStatus::Completed,
result: Some(CallToolResult {
@@ -2665,6 +2675,7 @@ fn core_turn_item_into_thread_item_converts_supported_variants() {
tool: "tool".to_string(),
status: McpToolCallStatus::Completed,
arguments: JsonValue::Null,
app_context: None,
mcp_app_resource_uri: None,
plugin_id: None,
result: Some(Box::new(McpToolCallResult {
@@ -2678,6 +2689,49 @@ fn core_turn_item_into_thread_item_converts_supported_variants() {
);
}
#[test]
fn mcp_tool_call_app_context_serializes_connector_id() {
let item = ThreadItem::McpToolCall {
id: "mcp-1".to_string(),
server: "codex_apps".to_string(),
tool: "calendar.create_event".to_string(),
status: McpToolCallStatus::InProgress,
arguments: json!({}),
app_context: Some(McpToolCallAppContext {
connector_id: "calendar".to_string(),
link_id: Some("link_calendar".to_string()),
resource_uri: Some("app://connector".to_string()),
}),
mcp_app_resource_uri: Some("app://connector".to_string()),
plugin_id: None,
result: None,
error: None,
duration_ms: None,
};
assert_eq!(
serde_json::to_value(item).expect("MCP tool call should serialize"),
json!({
"type": "mcpToolCall",
"id": "mcp-1",
"server": "codex_apps",
"tool": "calendar.create_event",
"status": "inProgress",
"arguments": {},
"appContext": {
"connectorId": "calendar",
"linkId": "link_calendar",
"resourceUri": "app://connector",
},
"mcpAppResourceUri": "app://connector",
"pluginId": null,
"result": null,
"error": null,
"durationMs": null,
})
);
}
#[test]
fn user_input_into_core_preserves_image_detail() {
assert_eq!(
@@ -3632,17 +3686,49 @@ fn thread_lifecycle_responses_default_missing_optional_fields() {
serde_json::from_value(response.clone()).expect("thread/start response");
let resume: ThreadResumeResponse =
serde_json::from_value(response.clone()).expect("thread/resume response");
let fork: ThreadForkResponse = serde_json::from_value(response).expect("thread/fork response");
let fork: ThreadForkResponse =
serde_json::from_value(response.clone()).expect("thread/fork response");
assert_eq!(start.instruction_sources, Vec::<AbsolutePathBuf>::new());
assert_eq!(start.instruction_sources, Vec::<LegacyAppPathString>::new());
assert_eq!(start.thread.parent_thread_id, None);
assert_eq!(start.thread.recency_at, None);
assert_eq!(resume.instruction_sources, Vec::<AbsolutePathBuf>::new());
assert_eq!(fork.instruction_sources, Vec::<AbsolutePathBuf>::new());
assert_eq!(
resume.instruction_sources,
Vec::<LegacyAppPathString>::new()
);
assert_eq!(fork.instruction_sources, Vec::<LegacyAppPathString>::new());
assert_eq!(start.active_permission_profile, None);
assert_eq!(resume.active_permission_profile, None);
assert_eq!(resume.initial_turns_page, None);
assert_eq!(fork.active_permission_profile, None);
let foreign_source: LegacyAppPathString =
serde_json::from_value(json!(r"C:\workspace\AGENTS.md")).expect("foreign source");
let mut response_with_foreign_source = response;
response_with_foreign_source["instructionSources"] = json!([foreign_source.as_str()]);
let start: ThreadStartResponse = serde_json::from_value(response_with_foreign_source.clone())
.expect("thread/start response with foreign source");
let resume: ThreadResumeResponse = serde_json::from_value(response_with_foreign_source.clone())
.expect("thread/resume response with foreign source");
let fork: ThreadForkResponse = serde_json::from_value(response_with_foreign_source)
.expect("thread/fork response with foreign source");
assert_eq!(start.instruction_sources, vec![foreign_source.clone()]);
assert_eq!(resume.instruction_sources, vec![foreign_source.clone()]);
assert_eq!(fork.instruction_sources, vec![foreign_source]);
let foreign_source_uri =
PathUri::parse("file:///C:/workspace/AGENTS.md").expect("foreign source URI");
assert_eq!(
start.instruction_source_path_uris(),
vec![foreign_source_uri.clone()]
);
assert_eq!(
resume.instruction_source_path_uris(),
vec![foreign_source_uri.clone()]
);
assert_eq!(
fork.instruction_source_path_uris(),
vec![foreign_source_uri]
);
}
#[test]
@@ -26,6 +26,8 @@ use codex_protocol::protocol::ThreadGoalStatus as CoreThreadGoalStatus;
use codex_protocol::protocol::TokenUsage as CoreTokenUsage;
use codex_protocol::protocol::TokenUsageInfo as CoreTokenUsageInfo;
use codex_utils_absolute_path::AbsolutePathBuf;
use codex_utils_path_uri::LegacyAppPathString;
use codex_utils_path_uri::PathUri;
use schemars::JsonSchema;
use serde::Deserialize;
use serde::Serialize;
@@ -161,9 +163,9 @@ pub struct ThreadStartResponse {
#[experimental("thread/start.runtimeWorkspaceRoots")]
#[serde(default)]
pub runtime_workspace_roots: Vec<AbsolutePathBuf>,
/// Instruction source files currently loaded for this thread.
/// Environment-native paths to instruction source files currently loaded for this thread.
#[serde(default)]
pub instruction_sources: Vec<AbsolutePathBuf>,
pub instruction_sources: Vec<LegacyAppPathString>,
#[experimental(nested)]
pub approval_policy: AskForApproval,
/// Reviewer currently used for approval requests on this thread.
@@ -179,6 +181,13 @@ pub struct ThreadStartResponse {
pub reasoning_effort: Option<ReasoningEffort>,
}
impl ThreadStartResponse {
/// Parses valid absolute instruction source paths and omits malformed legacy values.
pub fn instruction_source_path_uris(&self) -> Vec<PathUri> {
instruction_source_path_uris(&self.instruction_sources)
}
}
#[derive(
Serialize, Deserialize, Debug, Default, Clone, PartialEq, JsonSchema, TS, ExperimentalApi,
)]
@@ -375,9 +384,9 @@ pub struct ThreadResumeResponse {
#[experimental("thread/resume.runtimeWorkspaceRoots")]
#[serde(default)]
pub runtime_workspace_roots: Vec<AbsolutePathBuf>,
/// Instruction source files currently loaded for this thread.
/// Environment-native paths to instruction source files currently loaded for this thread.
#[serde(default)]
pub instruction_sources: Vec<AbsolutePathBuf>,
pub instruction_sources: Vec<LegacyAppPathString>,
#[experimental(nested)]
pub approval_policy: AskForApproval,
/// Reviewer currently used for approval requests on this thread.
@@ -397,6 +406,13 @@ pub struct ThreadResumeResponse {
pub initial_turns_page: Option<TurnsPage>,
}
impl ThreadResumeResponse {
/// Parses valid absolute instruction source paths and omits malformed legacy values.
pub fn instruction_source_path_uris(&self) -> Vec<PathUri> {
instruction_source_path_uris(&self.instruction_sources)
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
@@ -523,9 +539,9 @@ pub struct ThreadForkResponse {
#[experimental("thread/fork.runtimeWorkspaceRoots")]
#[serde(default)]
pub runtime_workspace_roots: Vec<AbsolutePathBuf>,
/// Instruction source files currently loaded for this thread.
/// Environment-native paths to instruction source files currently loaded for this thread.
#[serde(default)]
pub instruction_sources: Vec<AbsolutePathBuf>,
pub instruction_sources: Vec<LegacyAppPathString>,
#[experimental(nested)]
pub approval_policy: AskForApproval,
/// Reviewer currently used for approval requests on this thread.
@@ -541,6 +557,30 @@ pub struct ThreadForkResponse {
pub reasoning_effort: Option<ReasoningEffort>,
}
impl ThreadForkResponse {
/// Parses valid absolute instruction source paths and omits malformed legacy values.
pub fn instruction_source_path_uris(&self) -> Vec<PathUri> {
instruction_source_path_uris(&self.instruction_sources)
}
}
fn instruction_source_path_uris(sources: &[LegacyAppPathString]) -> Vec<PathUri> {
// Instruction sources are advisory diagnostics. Warn and fail open so a malformed legacy
// path cannot fail thread start, resume, or fork.
sources
.iter()
.filter_map(|source| {
source.to_inferred_path_uri().or_else(|| {
tracing::warn!(
path = source.as_str(),
"ignoring invalid instruction source path from app-server"
);
None
})
})
.collect()
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
@@ -1038,6 +1038,7 @@ async fn remote_control_start_allows_missing_auth_when_enabled() {
codex_home.path().to_path_buf(),
/*enable_codex_api_key_env*/ false,
AuthCredentialsStoreMode::File,
/*forced_chatgpt_workspace_id*/ None,
/*chatgpt_base_url*/ None,
AuthKeyringBackendKind::default(),
)
@@ -1866,6 +1867,7 @@ async fn remote_control_waits_for_account_id_before_enrolling() {
codex_home.path().to_path_buf(),
/*enable_codex_api_key_env*/ false,
AuthCredentialsStoreMode::File,
/*forced_chatgpt_workspace_id*/ None,
/*chatgpt_base_url*/ None,
AuthKeyringBackendKind::default(),
)
@@ -1961,6 +1963,7 @@ async fn persisted_enable_does_not_follow_auth_to_an_account_without_a_preferenc
codex_home.path().to_path_buf(),
/*enable_codex_api_key_env*/ false,
AuthCredentialsStoreMode::File,
/*forced_chatgpt_workspace_id*/ None,
/*chatgpt_base_url*/ None,
AuthKeyringBackendKind::default(),
)
@@ -182,6 +182,7 @@ async fn list_remote_control_clients_recovers_auth_after_unauthorized() {
codex_home.path().to_path_buf(),
/*enable_codex_api_key_env*/ false,
AuthCredentialsStoreMode::File,
/*forced_chatgpt_workspace_id*/ None,
/*chatgpt_base_url*/ None,
AuthKeyringBackendKind::default(),
)
@@ -266,6 +267,7 @@ async fn list_remote_control_clients_retries_unauthorized_only_once() {
codex_home.path().to_path_buf(),
/*enable_codex_api_key_env*/ false,
AuthCredentialsStoreMode::File,
/*forced_chatgpt_workspace_id*/ None,
/*chatgpt_base_url*/ None,
AuthKeyringBackendKind::default(),
)
@@ -536,6 +536,7 @@ async fn remote_control_handle_recovers_auth_before_refreshing_pairing() {
codex_home.path().to_path_buf(),
/*enable_codex_api_key_env*/ false,
AuthCredentialsStoreMode::File,
/*forced_chatgpt_workspace_id*/ None,
/*chatgpt_base_url*/ None,
AuthKeyringBackendKind::default(),
)
@@ -804,6 +805,7 @@ async fn remote_control_handle_discards_pairing_response_after_auth_change() {
codex_home.path().to_path_buf(),
/*enable_codex_api_key_env*/ false,
AuthCredentialsStoreMode::File,
/*forced_chatgpt_workspace_id*/ None,
/*chatgpt_base_url*/ None,
AuthKeyringBackendKind::default(),
)
@@ -2211,6 +2211,7 @@ mod tests {
codex_home.path().to_path_buf(),
/*enable_codex_api_key_env*/ false,
AuthCredentialsStoreMode::File,
/*forced_chatgpt_workspace_id*/ None,
/*chatgpt_base_url*/ None,
AuthKeyringBackendKind::default(),
)
@@ -2308,6 +2309,7 @@ mod tests {
codex_home.path().to_path_buf(),
/*enable_codex_api_key_env*/ false,
AuthCredentialsStoreMode::File,
/*forced_chatgpt_workspace_id*/ None,
/*chatgpt_base_url*/ None,
AuthKeyringBackendKind::default(),
)
@@ -2430,6 +2432,7 @@ mod tests {
codex_home.path().to_path_buf(),
/*enable_codex_api_key_env*/ false,
AuthCredentialsStoreMode::File,
/*forced_chatgpt_workspace_id*/ None,
/*chatgpt_base_url*/ None,
AuthKeyringBackendKind::default(),
)
+2 -2
View File
@@ -140,7 +140,7 @@ Example with notification opt-out:
- `thread/start` — create a new thread; emits `thread/started` (including the current `thread.status`) and auto-subscribes you to turn/item events for that thread. When the request includes a `cwd` and the resolved sandbox is `workspace-write` or full access, app-server also marks that project as trusted in the user `config.toml`. Pass `sessionStartSource: "clear"` when starting a replacement thread after clearing the current session so `SessionStart` hooks receive `source: "clear"` instead of the default `"startup"`. Experimental `runtimeWorkspaceRoots` replaces the thread-scoped runtime workspace roots used to materialize `:workspace_roots`; paths must be absolute. For permissions, prefer experimental `permissions` profile selection by id; the legacy `sandbox` shorthand is still accepted but cannot be combined with `permissions`. Experimental `environments` selects the sticky execution environments for turns on the thread; omit it to use the server default, pass `[]` to disable environments, or pass explicit environment ids with per-environment `cwd`. Experimental `selectedCapabilityRoots` selects environment-owned plugin or standalone-skill roots. Skills found below those roots are listed and read through the owning environment. Stdio MCP servers declared by selected plugins are also started in that environment; HTTP MCP declarations remain inactive.
- `thread/resume` — reopen an existing thread by id so subsequent `turn/start` calls append to it. Accepts the same permission override rules as `thread/start`.
- `thread/fork` — fork an existing thread into a new thread id by copying the stored history; if the source thread is currently mid-turn, the fork records the same interruption marker as `turn/interrupt` instead of inheriting an unmarked partial turn suffix. The returned `thread.forkedFromId` points at the source thread when known. Accepts `ephemeral: true` for an in-memory temporary fork, emits `thread/started` (including the current `thread.status`), and auto-subscribes you to turn/item events for the new thread. Experimental clients can pass `excludeTurns: true` when they plan to page fork history via `thread/turns/list` instead of receiving the full turn array immediately. Accepts the same permission override rules as `thread/start`.
- `thread/start`, `thread/resume`, and `thread/fork` responses include the legacy `sandbox` compatibility projection. Experimental clients can read `runtimeWorkspaceRoots` for the thread-scoped runtime roots and `activePermissionProfile` for the named or implicit built-in profile identity/provenance when known.
- `thread/start`, `thread/resume`, and `thread/fork` responses include the legacy `sandbox` compatibility projection. `instructionSources` lists loaded instruction files using each source environment's native absolute path syntax, including files loaded from remote environments. Experimental clients can read `runtimeWorkspaceRoots` for the thread-scoped runtime roots and `activePermissionProfile` for the named or implicit built-in profile identity/provenance when known.
- `thread/list` — page through stored threads; supports cursor-based pagination and optional `modelProviders`, `sourceKinds`, `archived`, `cwd`, and `searchTerm` filters. Experimental clients can use `parentThreadId` to filter direct spawned children represented by persisted spawn-edge state. Review and Guardian threads are not included because they do not participate in that spawn-edge lifecycle. Each returned `thread` includes `status` (`ThreadStatus`), defaulting to `notLoaded` when the thread is not currently loaded. Subagent threads also include `parentThreadId` when the immediate parent is known.
- `thread/loaded/list` — list the thread ids currently loaded in memory.
- `thread/read` — read a stored thread by id without resuming it; optionally include turns via `includeTurns`. The returned `thread` includes `status` (`ThreadStatus`), defaulting to `notLoaded` when the thread is not currently loaded.
@@ -1365,7 +1365,7 @@ Today both notifications carry an empty `items` array even when item events were
- `reasoning` — `{id, summary, content}` where `summary` holds streamed reasoning summaries (applicable for most OpenAI models) and `content` holds raw reasoning blocks (applicable for e.g. open source models).
- `commandExecution` — `{id, command, cwd, status, commandActions, aggregatedOutput?, exitCode?, durationMs?}` for sandboxed commands; `status` is `inProgress`, `completed`, `failed`, or `declined`.
- `fileChange` — `{id, changes, status}` describing proposed edits; `changes` list `{path, kind, diff}` and `status` is `inProgress`, `completed`, `failed`, or `declined`.
- `mcpToolCall` — `{id, server, tool, status, arguments, mcpAppResourceUri?, pluginId, result?, error?}` describing MCP calls; `status` is `inProgress`, `completed`, or `failed`.
- `mcpToolCall` — `{id, server, tool, status, arguments, appContext, mcpAppResourceUri?, pluginId, result?, error?}` describing MCP calls; `appContext` is `{connectorId, linkId, resourceUri}` for calls through a trusted MCP app, where `connectorId` identifies the connector that owns the tool, `linkId` identifies the app link, and `resourceUri` points to the widget template. The top-level `mcpAppResourceUri` is deprecated and temporarily duplicated for client migration. `tool` identifies the invoked action. `status` is `inProgress`, `completed`, or `failed`.
- `collabToolCall` — `{id, tool, status, senderThreadId, receiverThreadId?, newThreadId?, prompt?, agentStatus?}` describing collab tool calls (`spawn_agent`, `send_input`, `resume_agent`, `wait`, `close_agent`); `status` is `inProgress`, `completed`, or `failed`.
- `webSearch` — `{id, query, action?}` for a web search request issued by the agent; `action` mirrors the Responses API web_search action payload (`search`, `open_page`, `find_in_page`) and may be omitted until completion.
- `imageView` — `{id, path}` emitted when the agent invokes the image viewer tool.
@@ -1181,7 +1181,7 @@ impl ThreadRequestProcessor {
)
.await?;
let instruction_sources = thread.instruction_sources().await;
let instruction_sources = thread.legacy_instruction_sources().await;
let config_snapshot = thread
.config_snapshot()
.instrument(tracing::info_span!(
@@ -2681,7 +2681,7 @@ impl ThreadRequestProcessor {
self.outgoing.send_error(request_id, err).await;
return Ok(());
}
let instruction_sources = codex_thread.instruction_sources().await;
let instruction_sources = codex_thread.legacy_instruction_sources().await;
let SessionConfiguredEvent { rollout_path, .. } = session_configured;
let Some(rollout_path) = rollout_path else {
let error =
@@ -2989,7 +2989,7 @@ impl ThreadRequestProcessor {
/*include_turns*/ false,
);
thread_summary.session_id = existing_thread.session_configured().session_id.to_string();
let instruction_sources = existing_thread.instruction_sources().await;
let instruction_sources = existing_thread.legacy_instruction_sources().await;
let listener_command_tx = {
let thread_state = thread_state.lock().await;
@@ -3422,7 +3422,7 @@ impl ThreadRequestProcessor {
.map_err(|err| core_thread_write_error("inherit source thread name", err))?;
}
let instruction_sources = forked_thread.instruction_sources().await;
let instruction_sources = forked_thread.legacy_instruction_sources().await;
// Auto-attach a conversation listener when forking a thread.
log_listener_attach_result(
@@ -52,6 +52,7 @@ fn redacted_mcp_tool_call_result() -> McpToolCallResult {
#[cfg(test)]
mod tests {
use super::*;
use codex_app_server_protocol::McpToolCallAppContext;
use codex_app_server_protocol::McpToolCallError;
use codex_app_server_protocol::McpToolCallStatus;
use codex_app_server_protocol::SessionSource;
@@ -78,6 +79,11 @@ mod tests {
tool: "lookup".to_string(),
status: McpToolCallStatus::Completed,
arguments: serde_json::json!({"secret":"argument"}),
app_context: Some(McpToolCallAppContext {
connector_id: "calendar".to_string(),
link_id: Some("link_calendar".to_string()),
resource_uri: Some("ui://widget/lookup.html".to_string()),
}),
mcp_app_resource_uri: Some("ui://widget/lookup.html".to_string()),
plugin_id: Some("sample@test".to_string()),
result: Some(Box::new(McpToolCallResult {
@@ -120,6 +126,11 @@ mod tests {
tool: "lookup".to_string(),
status: McpToolCallStatus::Completed,
arguments: JsonValue::String(REDACTED_PAYLOAD.to_string()),
app_context: Some(McpToolCallAppContext {
connector_id: "calendar".to_string(),
link_id: Some("link_calendar".to_string()),
resource_uri: Some("ui://widget/lookup.html".to_string()),
}),
mcp_app_resource_uri: Some("ui://widget/lookup.html".to_string()),
plugin_id: Some("sample@test".to_string()),
result: Some(Box::new(redacted_mcp_tool_call_result())),
@@ -137,6 +148,7 @@ mod tests {
tool: "lookup".to_string(),
status: McpToolCallStatus::Failed,
arguments: serde_json::json!({"secret":"argument"}),
app_context: None,
mcp_app_resource_uri: None,
plugin_id: None,
result: None,
@@ -156,6 +168,7 @@ mod tests {
tool: "lookup".to_string(),
status: McpToolCallStatus::Failed,
arguments: JsonValue::String(REDACTED_PAYLOAD.to_string()),
app_context: None,
mcp_app_resource_uri: None,
plugin_id: None,
result: None,
@@ -114,6 +114,8 @@ impl SkillsWatcher {
.skill_roots_for_config(&skills_input, Some(environment.get_filesystem()))
.await
.into_iter()
// Plugin roots are invalidated by plugin lifecycle operations.
.filter(|root| root.plugin_id.is_none())
.map(|root| WatchPath {
path: root.path.into_path_buf(),
recursive: true,
+3 -2
View File
@@ -13,7 +13,7 @@ use codex_protocol::ThreadId;
use codex_protocol::protocol::EventMsg;
use codex_protocol::protocol::RolloutItem;
use codex_rollout::state_db::StateDbHandle;
use codex_utils_absolute_path::AbsolutePathBuf;
use codex_utils_path_uri::LegacyAppPathString;
use std::collections::HashMap;
use std::collections::HashSet;
use std::sync::Arc;
@@ -31,7 +31,7 @@ pub(crate) struct PendingThreadResumeRequest {
pub(crate) request_id: ConnectionRequestId,
pub(crate) history_items: Vec<RolloutItem>,
pub(crate) config_snapshot: ThreadConfigSnapshot,
pub(crate) instruction_sources: Vec<AbsolutePathBuf>,
pub(crate) instruction_sources: Vec<LegacyAppPathString>,
pub(crate) thread_summary: codex_app_server_protocol::Thread,
pub(crate) emit_thread_goal_update: bool,
pub(crate) thread_goal_state_db: Option<StateDbHandle>,
@@ -200,6 +200,7 @@ mod tests {
use codex_protocol::config_types::CollaborationMode;
use codex_protocol::config_types::ModeKind;
use codex_protocol::config_types::Settings;
use codex_utils_absolute_path::AbsolutePathBuf;
use pretty_assertions::assert_eq;
#[test]
@@ -513,6 +513,7 @@ url = "{mcp_server_url}/mcp"
tool,
status,
arguments: json!({ "message": LARGE_RESPONSE_MESSAGE }),
app_context: None,
mcp_app_resource_uri: None,
plugin_id: None,
result: Some(result),
@@ -1010,15 +1010,12 @@ async fn plugin_install_tracks_remote_plugin_analytics_event() -> Result<()> {
}
#[tokio::test]
async fn plugin_install_errors_when_remote_bundle_download_fails() -> Result<()> {
async fn plugin_install_preserves_status_when_remote_bundle_error_body_is_too_large() -> Result<()>
{
let codex_home = TempDir::new()?;
let server = MockServer::start().await;
let bundle_url = mount_remote_plugin_bundle(
&server,
/*status_code*/ 503,
b"bundle temporarily unavailable".to_vec(),
)
.await;
let bundle_url =
mount_remote_plugin_bundle(&server, /*status_code*/ 503, vec![b'x'; 8 * 1024 + 1]).await;
configure_remote_plugin_test(codex_home.path(), &server)?;
mount_remote_plugin_detail(&server, REMOTE_PLUGIN_ID, "1.2.3", Some(&bundle_url)).await;
mount_empty_remote_installed_plugins(&server).await;
@@ -1041,6 +1038,20 @@ async fn plugin_install_errors_when_remote_bundle_download_fails() -> Result<()>
assert_eq!(err.error.code, -32603);
assert!(err.error.message.contains("failed with status 503"));
assert!(
err.error
.message
.contains("[response body truncated after 8192 bytes]")
);
assert_eq!(
err.error
.message
.bytes()
.filter(|byte| *byte == b'x')
.count(),
8192
);
assert!(!err.error.message.contains("exceeded maximum size"));
wait_for_remote_plugin_request_count(
&server,
"GET",
@@ -23,6 +23,7 @@ use codex_app_server_protocol::FileChangeRequestApprovalResponse;
use codex_app_server_protocol::ItemStartedNotification;
use codex_app_server_protocol::JSONRPCError;
use codex_app_server_protocol::JSONRPCResponse;
use codex_app_server_protocol::McpToolCallAppContext;
use codex_app_server_protocol::PatchApplyStatus;
use codex_app_server_protocol::PatchChangeKind;
use codex_app_server_protocol::RequestId;
@@ -81,6 +82,7 @@ use codex_rollout::append_rollout_item_to_path;
use codex_rollout::read_session_meta_line;
use codex_state::StateRuntime;
use codex_utils_absolute_path::AbsolutePathBuf;
use codex_utils_path_uri::LegacyAppPathString;
use core_test_support::responses;
use core_test_support::skip_if_no_network;
use pretty_assertions::assert_eq;
@@ -287,7 +289,8 @@ async fn thread_resume_running_thread_uses_cached_instruction_sources() -> Resul
..
} = to_response::<ThreadStartResponse>(start_resp)?;
let project_agents = AbsolutePathBuf::try_from(project_agents)?;
assert_eq!(instruction_sources, vec![project_agents.clone()]);
let project_agents_source = LegacyAppPathString::from_abs_path(&project_agents);
assert_eq!(instruction_sources, vec![project_agents_source.clone()]);
let turn_id = mcp
.send_turn_start_request(TurnStartParams {
@@ -329,7 +332,7 @@ async fn thread_resume_running_thread_uses_cached_instruction_sources() -> Resul
..
} = to_response::<ThreadResumeResponse>(resume_resp)?;
assert_eq!(instruction_sources, vec![project_agents]);
assert_eq!(instruction_sources, vec![project_agents_source]);
Ok(())
}
@@ -729,6 +732,7 @@ async fn thread_resume_redacts_payloads_for_chatgpt_remote_clients() -> Result<(
.expect("remote resume should include redacted MCP item");
let ThreadItem::McpToolCall {
arguments,
app_context,
result,
error,
..
@@ -737,6 +741,14 @@ async fn thread_resume_redacts_payloads_for_chatgpt_remote_clients() -> Result<(
unreachable!("matched MCP item");
};
assert_eq!(arguments, &json!("[redacted]"));
assert_eq!(
app_context,
&Some(McpToolCallAppContext {
connector_id: "calendar".to_string(),
link_id: Some("link_calendar".to_string()),
resource_uri: Some("ui://widget/lookup.html".to_string()),
})
);
let result = result.as_ref().expect("redacted MCP result");
assert_eq!(
result.content,
@@ -770,12 +782,23 @@ async fn thread_resume_redacts_payloads_for_chatgpt_remote_clients() -> Result<(
.find(|item| matches!(item, ThreadItem::McpToolCall { .. }))
.expect("normal resume should include MCP item");
let ThreadItem::McpToolCall {
arguments, result, ..
arguments,
app_context,
result,
..
} = normal_mcp_item
else {
unreachable!("matched MCP item");
};
assert_eq!(arguments, &json!({"secret":"argument"}));
assert_eq!(
app_context,
&Some(McpToolCallAppContext {
connector_id: "calendar".to_string(),
link_id: Some("link_calendar".to_string()),
resource_uri: Some("ui://widget/lookup.html".to_string()),
})
);
let result = result.as_ref().expect("normal MCP result");
assert_eq!(
result.content,
@@ -877,7 +900,9 @@ fn append_resume_redaction_history(
tool: "lookup".to_string(),
arguments: Some(json!({"secret":"argument"})),
},
connector_id: Some("calendar".to_string()),
mcp_app_resource_uri: Some("ui://widget/lookup.html".to_string()),
link_id: Some("link_calendar".to_string()),
plugin_id: None,
duration: Duration::from_millis(8),
result: Ok(CallToolResult {
@@ -381,7 +381,7 @@ async fn thread_start_response_includes_loaded_instruction_sources() -> Result<(
let instruction_sources = instruction_sources
.into_iter()
.map(normalize_path_for_comparison)
.map(|path| normalize_path_for_comparison(path.as_str()))
.collect::<Vec<_>>();
let expected_instruction_sources = vec![
std::fs::canonicalize(global_agents_path)?,
@@ -428,7 +428,7 @@ async fn thread_start_response_excludes_empty_project_instruction_source() -> Re
let instruction_sources = instruction_sources
.into_iter()
.map(normalize_path_for_comparison)
.map(|path| normalize_path_for_comparison(path.as_str()))
.collect::<Vec<_>>();
let expected_instruction_sources = vec![normalize_path_for_comparison(std::fs::canonicalize(
global_agents_path,
@@ -474,7 +474,7 @@ async fn thread_start_without_selected_environment_includes_only_global_instruct
assert_eq!(
instruction_sources
.into_iter()
.map(normalize_path_for_comparison)
.map(|path| normalize_path_for_comparison(path.as_str()))
.collect::<Vec<_>>(),
vec![normalize_path_for_comparison(std::fs::canonicalize(
global_agents_path,
+2 -2
View File
@@ -1399,8 +1399,8 @@ fn stored_auth_issues(
codex_app_server_protocol::AuthMode::AgentIdentity => {
if auth
.agent_identity
.as_deref()
.is_none_or(|token| token.trim().is_empty())
.as_ref()
.is_none_or(|agent_identity| !agent_identity.has_auth_material())
{
issues.push("agent identity auth is missing an agent identity token");
}
+3 -6
View File
@@ -1738,12 +1738,9 @@ async fn load_exec_server_remote_auth_provider(
let agent_identity_jwt = read_codex_access_token_from_env().ok_or_else(|| {
anyhow::anyhow!("CODEX_ACCESS_TOKEN is required when --use-agent-identity-auth is set")
})?;
let auth = CodexAuth::from_agent_identity_jwt(
&agent_identity_jwt,
Some(&config.chatgpt_base_url),
/*agent_identity_authapi_base_url_override*/ None,
)
.await?;
let auth =
CodexAuth::from_agent_identity_jwt(&agent_identity_jwt, Some(&config.chatgpt_base_url))
.await?;
return Ok(codex_model_provider::auth_provider_from_auth(&auth));
}
+1
View File
@@ -25,6 +25,7 @@ tokio = { workspace = true, features = ["fs", "rt", "sync", "time"] }
tracing = { workspace = true }
[dev-dependencies]
codex-agent-identity = { workspace = true }
pretty_assertions = { workspace = true }
tempfile = { workspace = true }
tokio = { workspace = true, features = ["macros", "rt", "test-util", "time"] }
@@ -63,6 +63,7 @@ pub async fn cloud_config_bundle_loader_for_storage(
codex_home.clone(),
enable_codex_api_key_env,
credentials_store_mode,
/*forced_chatgpt_workspace_id*/ None,
Some(chatgpt_base_url.clone()),
keyring_backend_kind,
)
@@ -17,6 +17,8 @@ use codex_config::CloudRequirementsFragment;
use codex_config::CloudRequirementsTomlBundle;
use codex_config::types::AuthCredentialsStoreMode;
use codex_login::AuthKeyringBackendKind;
use codex_login::auth::AgentIdentityAuth;
use codex_login::auth::AgentIdentityAuthRecord;
use pretty_assertions::assert_eq;
use serde_json::json;
use std::collections::VecDeque;
@@ -48,6 +50,7 @@ async fn auth_manager_with_api_key() -> Arc<AuthManager> {
tmp.path().to_path_buf(),
/*enable_codex_api_key_env*/ false,
AuthCredentialsStoreMode::File,
/*forced_chatgpt_workspace_id*/ None,
/*chatgpt_base_url*/ None,
AuthKeyringBackendKind::default(),
)
@@ -77,6 +80,7 @@ async fn auth_manager_with_plan_and_identity(
tmp.path().to_path_buf(),
/*enable_codex_api_key_env*/ false,
AuthCredentialsStoreMode::File,
/*forced_chatgpt_workspace_id*/ None,
/*chatgpt_base_url*/ None,
AuthKeyringBackendKind::default(),
)
@@ -88,6 +92,28 @@ async fn auth_manager_with_plan(plan_type: &str) -> Arc<AuthManager> {
auth_manager_with_plan_and_identity(plan_type, Some("user-12345"), Some("account-12345")).await
}
async fn auth_manager_with_agent_identity_business_plan() -> Arc<AuthManager> {
let key_material =
codex_agent_identity::generate_agent_key_material().expect("generate agent key material");
AuthManager::from_auth_for_testing(CodexAuth::AgentIdentity(
AgentIdentityAuth::from_record(
AgentIdentityAuthRecord {
agent_runtime_id: "agent-runtime-123".to_string(),
agent_private_key: key_material.private_key_pkcs8_base64,
account_id: "account-12345".to_string(),
chatgpt_user_id: "user-12345".to_string(),
email: "user@example.com".to_string(),
plan_type: PlanType::Business,
chatgpt_account_is_fedramp: false,
task_id: Some("task-123".to_string()),
},
"https://auth.openai.com/api/accounts",
)
.await
.expect("agent identity record should be complete"),
))
}
fn chatgpt_auth_json(
plan_type: &str,
chatgpt_user_id: Option<&str>,
@@ -408,6 +434,28 @@ async fn get_bundle_allows_eligible_workspace_plans_and_writes_cache() {
}
}
#[tokio::test]
async fn get_bundle_allows_agent_identity_business_plan() {
let bundle = test_bundle();
let fetcher = Arc::new(StaticBundleClient::new(bundle.clone()));
let codex_home = tempdir().expect("tempdir");
let service = CloudConfigBundleService::new(
auth_manager_with_agent_identity_business_plan().await,
fetcher.clone(),
codex_home.path().to_path_buf(),
CLOUD_CONFIG_BUNDLE_TIMEOUT,
);
assert_eq!(service.load_startup_bundle().await, Ok(Some(bundle)));
assert_eq!(fetcher.request_count.load(Ordering::SeqCst), 1);
assert!(
codex_home
.path()
.join(CLOUD_CONFIG_BUNDLE_CACHE_FILENAME)
.exists()
);
}
#[tokio::test]
async fn get_bundle_skips_team_like_usage_based_plan() {
let fetcher = Arc::new(StaticBundleClient::new(test_bundle()));
@@ -635,6 +683,7 @@ async fn get_bundle_recovers_after_unauthorized_reload() {
auth_home.path().to_path_buf(),
/*enable_codex_api_key_env*/ false,
AuthCredentialsStoreMode::File,
/*forced_chatgpt_workspace_id*/ None,
/*chatgpt_base_url*/ None,
AuthKeyringBackendKind::default(),
)
@@ -690,6 +739,7 @@ async fn get_bundle_recovers_after_unauthorized_reload_updates_cache_identity()
auth_home.path().to_path_buf(),
/*enable_codex_api_key_env*/ false,
AuthCredentialsStoreMode::File,
/*forced_chatgpt_workspace_id*/ None,
/*chatgpt_base_url*/ None,
AuthKeyringBackendKind::default(),
)
@@ -753,6 +803,7 @@ async fn get_bundle_surfaces_auth_recovery_message() {
auth_home.path().to_path_buf(),
/*enable_codex_api_key_env*/ false,
AuthCredentialsStoreMode::File,
/*forced_chatgpt_workspace_id*/ None,
/*chatgpt_base_url*/ None,
AuthKeyringBackendKind::default(),
)
@@ -818,6 +869,7 @@ async fn get_bundle_unauthorized_without_recovery_uses_generic_message() {
auth_home.path().to_path_buf(),
/*enable_codex_api_key_env*/ false,
AuthCredentialsStoreMode::File,
/*forced_chatgpt_workspace_id*/ None,
/*chatgpt_base_url*/ None,
AuthKeyringBackendKind::default(),
)
+1
View File
@@ -49,6 +49,7 @@ pub async fn load_auth_manager(chatgpt_base_url: Option<String>) -> Option<AuthM
config.codex_home.to_path_buf(),
/*enable_codex_api_key_env*/ false,
config.cli_auth_credentials_store_mode,
config.forced_chatgpt_workspace_id.clone(),
chatgpt_base_url.or(Some(config.chatgpt_base_url.clone())),
config.auth_keyring_backend_kind(),
)
+71 -18
View File
@@ -7,18 +7,21 @@ use crate::manifest::PluginManifestMcpServers;
use crate::manifest::PluginManifestPaths;
use crate::manifest::load_plugin_manifest;
use crate::marketplace::MarketplacePluginSource;
use crate::marketplace::find_marketplace_plugin;
use crate::marketplace::list_marketplaces;
use crate::marketplace::load_marketplace;
use crate::remote::REMOTE_GLOBAL_MARKETPLACE_NAME;
use crate::remote::RemoteInstalledPlugin;
use crate::store::PluginStore;
use crate::store::plugin_version_for_source;
use crate::store::plugin_version_for_source_with_fallback_manifest;
use codex_app_server_protocol::AuthMode;
use codex_config::ConfigLayerStack;
use codex_config::HooksFile;
use codex_config::types::McpServerConfig;
use codex_config::types::PluginConfig;
use codex_config::types::PluginMcpServerConfig;
use codex_core_skills::PluginSkillSnapshots;
use codex_core_skills::SkillMetadata;
use codex_core_skills::config_rules::SkillConfigRules;
use codex_core_skills::config_rules::resolve_disabled_skill_paths;
@@ -72,6 +75,7 @@ enum PluginLoadScope<'a> {
AllCapabilities {
restriction_product: Option<Product>,
skill_config_rules: &'a SkillConfigRules,
plugin_skill_snapshots: Option<&'a PluginSkillSnapshots>,
},
HooksOnly,
}
@@ -113,6 +117,7 @@ pub(crate) async fn load_plugins_from_layer_stack(
config_layer_stack: &ConfigLayerStack,
extra_plugins: HashMap<String, PluginConfig>,
store: &PluginStore,
plugin_skill_snapshots: Option<&PluginSkillSnapshots>,
restriction_product: Option<Product>,
prefer_remote_curated_conflicts: bool,
) -> Vec<LoadedPlugin<McpServerConfig>> {
@@ -125,6 +130,7 @@ pub(crate) async fn load_plugins_from_layer_stack(
PluginLoadScope::AllCapabilities {
restriction_product,
skill_config_rules: &skill_config_rules,
plugin_skill_snapshots,
},
)
.await
@@ -460,7 +466,7 @@ fn refresh_non_curated_plugin_cache_with_mode(
let store = PluginStore::try_new(codex_home.to_path_buf()).map_err(|err| err.to_string())?;
let marketplace_outcome = list_marketplaces(additional_roots)
.map_err(|err| format!("failed to discover marketplaces for cache refresh: {err}"))?;
let mut plugin_sources = HashMap::<String, MarketplacePluginSource>::new();
let mut plugin_sources = HashMap::<String, (MarketplacePluginSource, Option<String>)>::new();
for marketplace in marketplace_outcome.marketplaces {
if is_openai_curated_marketplace_name(&marketplace.name) {
@@ -489,14 +495,31 @@ fn refresh_non_curated_plugin_cache_with_mode(
continue;
}
plugin_sources.insert(plugin_key, plugin.source);
let manifest_fallback = find_marketplace_plugin(&marketplace.path, &plugin.name)
.map(|resolved| {
resolved
.manifest_fallback
.contents_if_has_metadata()
.map(str::to_string)
})
.unwrap_or_else(|err| {
warn!(
plugin = plugin.name,
marketplace = marketplace.name,
error = %err,
"failed to resolve marketplace plugin manifest fallback during cache refresh"
);
None
});
plugin_sources.insert(plugin_key, (plugin.source, manifest_fallback));
}
}
let mut cache_refreshed = false;
for plugin_id in configured_non_curated_plugin_ids {
let plugin_key = plugin_id.as_key();
let Some(source) = plugin_sources.get(&plugin_key).cloned() else {
let Some((source, manifest_fallback_contents)) = plugin_sources.get(&plugin_key).cloned()
else {
warn!(
plugin = plugin_id.plugin_name,
marketplace = plugin_id.marketplace_name,
@@ -509,8 +532,14 @@ fn refresh_non_curated_plugin_cache_with_mode(
format!("failed to materialize plugin source for {plugin_key}: {err}")
})?;
let source_path = materialized.path.clone();
let plugin_version = plugin_version_for_source(source_path.as_path())
.map_err(|err| format!("failed to read plugin version for {plugin_key}: {err}"))?;
let plugin_version = match manifest_fallback_contents.as_deref() {
Some(manifest_contents) => plugin_version_for_source_with_fallback_manifest(
source_path.as_path(),
manifest_contents,
),
None => plugin_version_for_source(source_path.as_path()),
}
.map_err(|err| format!("failed to read plugin version for {plugin_key}: {err}"))?;
if mode == NonCuratedCacheRefreshMode::IfVersionChanged
&& store.active_plugin_version(&plugin_id).as_deref() == Some(plugin_version.as_str())
@@ -518,9 +547,16 @@ fn refresh_non_curated_plugin_cache_with_mode(
continue;
}
store
.install_with_version(source_path, plugin_id.clone(), plugin_version)
.map_err(|err| format!("failed to refresh plugin cache for {plugin_key}: {err}"))?;
match manifest_fallback_contents.as_deref() {
Some(manifest_contents) => store.install_with_version_and_fallback_manifest(
source_path,
plugin_id.clone(),
plugin_version,
manifest_contents,
),
None => store.install_with_version(source_path, plugin_id.clone(), plugin_version),
}
.map_err(|err| format!("failed to refresh plugin cache for {plugin_key}: {err}"))?;
cache_refreshed = true;
}
@@ -713,6 +749,7 @@ async fn load_plugin(
PluginLoadScope::AllCapabilities {
restriction_product,
skill_config_rules,
plugin_skill_snapshots,
} => {
loaded_plugin.manifest_name = Some(manifest.display_name().to_string());
loaded_plugin.manifest_description = manifest.description.clone();
@@ -723,6 +760,7 @@ async fn load_plugin(
&manifest,
*restriction_product,
skill_config_rules,
*plugin_skill_snapshots,
)
.await;
let has_enabled_skills = resolved_skills.has_enabled_skills();
@@ -819,10 +857,17 @@ pub async fn load_plugin_skills(
manifest: &PluginManifest,
restriction_product: Option<Product>,
skill_config_rules: &SkillConfigRules,
plugin_skill_snapshots: Option<&PluginSkillSnapshots>,
) -> ResolvedPluginSkills {
load_plugin_skill_inventory(plugin_root, plugin_id, manifest, restriction_product)
.await
.resolve(skill_config_rules)
load_plugin_skill_inventory(
plugin_root,
plugin_id,
manifest,
restriction_product,
plugin_skill_snapshots,
)
.await
.resolve(skill_config_rules)
}
pub(crate) async fn load_plugin_skill_inventory(
@@ -830,6 +875,7 @@ pub(crate) async fn load_plugin_skill_inventory(
plugin_id: &PluginId,
manifest: &PluginManifest,
restriction_product: Option<Product>,
plugin_skill_snapshots: Option<&PluginSkillSnapshots>,
) -> PluginSkillInventory {
let roots = plugin_skill_roots(plugin_root, &manifest.paths)
.into_iter()
@@ -842,7 +888,7 @@ pub(crate) async fn load_plugin_skill_inventory(
plugin_root: Some(plugin_root.clone()),
})
.collect::<Vec<_>>();
let outcome = load_skills_from_roots(roots).await;
let outcome = load_skills_from_roots(roots, plugin_skill_snapshots).await;
let had_errors = !outcome.errors.is_empty();
let skills = outcome
.skills
@@ -901,15 +947,22 @@ fn default_mcp_config_paths(plugin_root: &Path) -> Vec<AbsolutePathBuf> {
pub async fn load_plugin_apps(plugin_root: &Path) -> Vec<AppDeclaration> {
if let Some(manifest) = load_plugin_manifest(plugin_root) {
return load_apps_from_paths(
plugin_root,
plugin_app_config_paths(plugin_root, &manifest.paths),
)
.await;
return load_plugin_apps_from_manifest(plugin_root, &manifest.paths).await;
}
load_apps_from_paths(plugin_root, default_app_config_paths(plugin_root)).await
}
pub(crate) async fn load_plugin_apps_from_manifest(
plugin_root: &Path,
manifest_paths: &PluginManifestPaths,
) -> Vec<AppDeclaration> {
load_apps_from_paths(
plugin_root,
plugin_app_config_paths(plugin_root, manifest_paths),
)
.await
}
pub fn plugin_app_declarations_from_value(value: &JsonValue) -> Vec<AppDeclaration> {
let Ok(parsed) = serde_json::from_value::<PluginAppFile>(value.clone()) else {
return Vec::new();
@@ -1181,7 +1234,7 @@ async fn load_declared_plugin_mcp_servers(plugin_root: &Path) -> HashMap<String,
.await
}
async fn load_plugin_mcp_servers_from_manifest(
pub(crate) async fn load_plugin_mcp_servers_from_manifest(
plugin_root: &Path,
manifest_paths: &PluginManifestPaths,
plugin_policy: Option<&HashMap<String, PluginMcpServerConfig>>,
@@ -160,6 +160,7 @@ enabled = true
&stack,
HashMap::new(),
&store,
/*plugin_skill_snapshots*/ None,
Some(Product::Codex),
/*prefer_remote_curated_conflicts*/ false,
)
+106 -31
View File
@@ -7,10 +7,10 @@ use crate::loader::PluginHookLoadOutcome;
use crate::loader::configured_curated_plugin_ids_from_codex_home;
use crate::loader::curated_plugin_cache_version;
use crate::loader::installed_plugin_telemetry_metadata;
use crate::loader::load_plugin_apps;
use crate::loader::load_plugin_apps_from_manifest;
use crate::loader::load_plugin_hooks;
use crate::loader::load_plugin_hooks_from_layer_stack;
use crate::loader::load_plugin_mcp_servers;
use crate::loader::load_plugin_mcp_servers_from_manifest;
use crate::loader::load_plugin_skills;
use crate::loader::load_plugins_from_layer_stack;
use crate::loader::log_plugin_load_errors;
@@ -27,6 +27,7 @@ use crate::marketplace::MarketplaceInterface;
use crate::marketplace::MarketplaceListError;
use crate::marketplace::MarketplaceListOutcome;
use crate::marketplace::MarketplacePluginAuthPolicy;
use crate::marketplace::MarketplacePluginManifestFallback;
use crate::marketplace::MarketplacePluginPolicy;
use crate::marketplace::MarketplacePluginSource;
use crate::marketplace::ResolvedMarketplacePlugin;
@@ -60,6 +61,7 @@ use codex_config::set_user_plugin_enabled;
use codex_config::types::PluginConfig;
use codex_config::types::ToolSuggestDisabledTool;
use codex_config::types::ToolSuggestDiscoverableType;
use codex_core_skills::PluginSkillSnapshots;
use codex_core_skills::SkillMetadata;
use codex_core_skills::config_rules::SkillConfigRules;
use codex_core_skills::config_rules::skill_config_rules_from_stack;
@@ -315,6 +317,7 @@ pub struct ConfiguredMarketplacePlugin {
pub policy: MarketplacePluginPolicy,
pub interface: Option<PluginManifestInterface>,
pub keywords: Vec<String>,
pub manifest_fallback: Option<MarketplacePluginManifestFallback>,
pub installed: bool,
pub enabled: bool,
}
@@ -368,6 +371,7 @@ pub struct PluginsManager {
struct LoadedPluginsCacheEntry {
key: PluginLoadCacheKey,
plugins: Vec<LoadedPlugin>,
plugin_skill_snapshots: PluginSkillSnapshots,
}
#[derive(Default)]
@@ -383,6 +387,16 @@ struct PluginLoadCacheKey {
remote_plugin_enabled: bool,
}
impl PluginLoadCacheKey {
fn from_config(config: &PluginsConfigInput) -> Self {
Self {
configured_plugins: configured_plugins_from_stack(&config.config_layer_stack),
skill_config_rules: skill_config_rules_from_stack(&config.config_layer_stack),
remote_plugin_enabled: config.remote_plugin_enabled,
}
}
}
impl PluginsManager {
pub fn new(codex_home: PathBuf) -> Self {
Self::new_with_options(codex_home, Some(Product::Codex), /*auth_mode*/ None)
@@ -468,6 +482,24 @@ impl PluginsManager {
.await
}
/// Returns skill snapshots parsed while loading the matching plugin cache entry.
pub fn plugin_skill_snapshots_for_config(
&self,
config: &PluginsConfigInput,
) -> Option<PluginSkillSnapshots> {
if !config.plugins_enabled {
return None;
}
let key = PluginLoadCacheKey::from_config(config);
self.loaded_plugins_cache
.read()
.unwrap_or_else(std::sync::PoisonError::into_inner)
.entry
.as_ref()
.filter(|cached| cached.key == key)
.map(|cached| cached.plugin_skill_snapshots.clone())
}
#[instrument(
name = "plugins_for_config",
level = "info",
@@ -487,11 +519,7 @@ impl PluginsManager {
return PluginLoadOutcome::default();
}
let cache_key = PluginLoadCacheKey {
configured_plugins: configured_plugins_from_stack(&config.config_layer_stack),
skill_config_rules: skill_config_rules_from_stack(&config.config_layer_stack),
remote_plugin_enabled: config.remote_plugin_enabled,
};
let cache_key = PluginLoadCacheKey::from_config(config);
if !force_reload && let Some(plugins) = self.cached_loaded_plugins(&cache_key) {
return self.resolve_loaded_plugins_for_auth(plugins);
}
@@ -504,16 +532,23 @@ impl PluginsManager {
return self.resolve_loaded_plugins_for_auth(plugins);
}
let cache_generation = self.loaded_plugins_cache_generation();
let plugin_skill_snapshots = PluginSkillSnapshots::for_plugin_load();
let plugins = load_plugins_from_layer_stack(
&config.config_layer_stack,
self.remote_installed_plugin_configs(),
&self.store,
Some(&plugin_skill_snapshots),
self.restriction_product,
config.remote_plugin_enabled,
)
.await;
log_plugin_load_errors(&plugins);
self.cache_loaded_plugins_if_current(cache_generation, cache_key, plugins.clone());
self.cache_loaded_plugins_if_current(
cache_generation,
cache_key,
plugins.clone(),
plugin_skill_snapshots,
);
self.resolve_loaded_plugins_for_auth(plugins)
}
@@ -587,6 +622,7 @@ impl PluginsManager {
config_layer_stack,
self.remote_installed_plugin_configs(),
&self.store,
/*plugin_skill_snapshots*/ None,
self.restriction_product,
config.remote_plugin_enabled,
)
@@ -624,19 +660,13 @@ impl PluginsManager {
}
fn cached_loaded_plugins(&self, key: &PluginLoadCacheKey) -> Option<Vec<LoadedPlugin>> {
match self.loaded_plugins_cache.read() {
Ok(cache) => cache
.entry
.as_ref()
.filter(|cached| cached.key == *key)
.map(|cached| cached.plugins.clone()),
Err(err) => err
.into_inner()
.entry
.as_ref()
.filter(|cached| cached.key == *key)
.map(|cached| cached.plugins.clone()),
}
self.loaded_plugins_cache
.read()
.unwrap_or_else(std::sync::PoisonError::into_inner)
.entry
.as_ref()
.filter(|cached| cached.key == *key)
.map(|cached| cached.plugins.clone())
}
fn loaded_plugins_cache_generation(&self) -> u64 {
@@ -651,13 +681,18 @@ impl PluginsManager {
generation: u64,
key: PluginLoadCacheKey,
plugins: Vec<LoadedPlugin>,
plugin_skill_snapshots: PluginSkillSnapshots,
) {
let mut cache = match self.loaded_plugins_cache.write() {
Ok(cache) => cache,
Err(err) => err.into_inner(),
};
if cache.generation == generation {
cache.entry = Some(LoadedPluginsCacheEntry { key, plugins });
cache.entry = Some(LoadedPluginsCacheEntry {
key,
plugins,
plugin_skill_snapshots,
});
}
}
@@ -1256,15 +1291,32 @@ impl PluginsManager {
};
let store = self.store.clone();
let codex_home = self.codex_home.clone();
let manifest_fallback_contents = resolved
.manifest_fallback
.contents_if_has_metadata()
.map(str::to_string);
let result: StorePluginInstallResult = tokio::task::spawn_blocking(move || {
let materialized =
materialize_marketplace_plugin_source(codex_home.as_path(), &resolved.source)
.map_err(PluginStoreError::Invalid)?;
let source_path = materialized.path;
if let Some(plugin_version) = plugin_version {
store.install_with_version(source_path, resolved.plugin_id, plugin_version)
} else {
store.install(source_path, resolved.plugin_id)
match (plugin_version, manifest_fallback_contents.as_deref()) {
(Some(plugin_version), Some(manifest_contents)) => store
.install_with_version_and_fallback_manifest(
source_path,
resolved.plugin_id,
plugin_version,
manifest_contents,
),
(Some(plugin_version), None) => {
store.install_with_version(source_path, resolved.plugin_id, plugin_version)
}
(None, Some(manifest_contents)) => store.install_with_fallback_manifest(
source_path,
resolved.plugin_id,
manifest_contents,
),
(None, None) => store.install(source_path, resolved.plugin_id),
}
})
.await
@@ -1394,6 +1446,7 @@ impl PluginsManager {
let enabled = enabled_plugins.contains(&plugin_key);
let mut interface = plugin.interface;
let mut local_version = plugin.local_version;
let manifest_fallback = plugin.manifest_fallback.clone();
if installed
&& matches!(&plugin.source, MarketplacePluginSource::Git { .. })
&& let Some(plugin_id) = plugin_id.as_ref()
@@ -1424,6 +1477,7 @@ impl PluginsManager {
policy: plugin.policy,
keywords: plugin.keywords,
interface,
manifest_fallback,
})
})
.collect::<Vec<_>>();
@@ -1491,6 +1545,10 @@ impl PluginsManager {
let marketplace_name = plugin.plugin_id.marketplace_name.clone();
let plugin_key = plugin.plugin_id.as_key();
let manifest_fallback = plugin
.manifest_fallback
.contents_if_has_metadata()
.map(|_| plugin.manifest_fallback.clone());
let (installed_plugins, enabled_plugins) = self.configured_plugin_states(config);
let installed = installed_plugins.contains(&plugin_key);
let installed_version = if installed {
@@ -1518,6 +1576,7 @@ impl PluginsManager {
.as_ref()
.map(|manifest| manifest.keywords.clone())
.unwrap_or_default(),
manifest_fallback,
installed,
enabled: enabled_plugins.contains(&plugin_key),
},
@@ -1604,9 +1663,18 @@ impl PluginsManager {
"path does not exist or is not a directory".to_string(),
));
}
let manifest = load_plugin_manifest(source_path.as_path()).ok_or_else(|| {
MarketplaceError::InvalidPlugin("missing or invalid plugin.json".to_string())
})?;
let manifest =
if codex_utils_plugins::find_plugin_manifest_path(source_path.as_path()).is_some() {
load_plugin_manifest(source_path.as_path())
} else {
plugin
.manifest_fallback
.as_ref()
.and_then(|fallback| fallback.parse_for_plugin_root(source_path.as_path()))
}
.ok_or_else(|| {
MarketplaceError::InvalidPlugin("missing or invalid plugin.json".to_string())
})?;
let description = manifest.description.clone();
let marketplace_category = plugin
.interface
@@ -1624,6 +1692,7 @@ impl PluginsManager {
&codex_core_skills::config_rules::skill_config_rules_from_stack(
&config.config_layer_stack,
),
/*plugin_skill_snapshots*/ None,
)
.await;
let plugin_data_root = self.store.plugin_data_root(&plugin_id);
@@ -1637,8 +1706,14 @@ impl PluginsManager {
})
.collect();
let auth_mode = self.auth_mode();
let mut app_declarations = load_plugin_apps(source_path.as_path()).await;
let mut mcp_servers = load_plugin_mcp_servers(source_path.as_path(), auth_mode).await;
let mut app_declarations =
load_plugin_apps_from_manifest(source_path.as_path(), &manifest.paths).await;
let mut mcp_servers = load_plugin_mcp_servers_from_manifest(
source_path.as_path(),
&manifest.paths,
/*plugin_policy*/ None,
)
.await;
if auth_mode.is_some() {
apply_app_mcp_routing_policy(
&mut app_declarations,
+301 -2
View File
@@ -37,6 +37,9 @@ use codex_config::McpServerConfig;
use codex_config::McpServerOAuthConfig;
use codex_config::McpServerToolConfig;
use codex_config::types::McpServerTransportConfig;
use codex_core_skills::PluginSkillSnapshots;
use codex_core_skills::SkillsLoadInput;
use codex_core_skills::SkillsService;
use codex_core_skills::config_rules::SkillConfigRules;
use codex_login::CodexAuth;
use codex_plugin::AppDeclaration;
@@ -1476,6 +1479,7 @@ async fn load_plugin_skills_dedupes_overlapping_manifest_roots() {
&manifest,
/*restriction_product*/ None,
&SkillConfigRules::default(),
/*plugin_skill_snapshots*/ None,
)
.await;
@@ -2039,6 +2043,55 @@ async fn plugin_cache_ignores_unrelated_session_overrides() {
assert_eq!(second.plugins()[0].mcp_servers.len(), 1);
}
#[tokio::test]
async fn skills_service_reuses_skills_parsed_during_plugin_load() {
let codex_home = TempDir::new().unwrap();
let codex_home_abs = codex_home.path().to_path_buf().abs();
let plugin_root = codex_home
.path()
.join("plugins/cache")
.join("test/sample/local");
write_plugin(
codex_home.path().join("plugins/cache/test").as_path(),
"sample/local",
"sample",
);
let skill_path = plugin_root.join("skills/SKILL.md");
write_file(&skill_path, "---\nname: search\ndescription: first\n---\n");
write_file(
&codex_home.path().join(CONFIG_TOML_FILE),
&plugin_config_toml(/*enabled*/ true, /*plugins_feature_enabled*/ true),
);
let config = load_config(codex_home.path(), codex_home.path()).await;
let manager = PluginsManager::new(codex_home.path().to_path_buf());
let plugin_outcome = manager.plugins_for_config(&config).await;
let plugin_skill_snapshots = manager.plugin_skill_snapshots_for_config(&config);
write_file(&skill_path, "---\nname: search\ndescription: second\n---\n");
let skills_input = SkillsLoadInput::new(
codex_home_abs.clone(),
plugin_outcome.effective_plugin_skill_roots(),
config.config_layer_stack.clone(),
/*bundled_skills_enabled*/ false,
)
.with_plugin_skill_snapshots(plugin_skill_snapshots);
let skills_service = SkillsService::new(codex_home_abs, /*bundled_skills_enabled*/ false);
let cached = skills_service
.snapshot_for_config(&skills_input, /*fs*/ None)
.await;
assert_eq!(
cached
.outcome()
.skills
.iter()
.map(|skill| skill.description.as_str())
.collect::<Vec<_>>(),
vec!["first"]
);
}
#[test]
fn loaded_plugins_cache_invalidation_rejects_stale_load_completion() {
let codex_home = TempDir::new().unwrap();
@@ -2051,7 +2104,12 @@ fn loaded_plugins_cache_invalidation_rejects_stale_load_completion() {
let stale_generation = manager.loaded_plugins_cache_generation();
manager.clear_loaded_plugins_cache();
manager.cache_loaded_plugins_if_current(stale_generation, cache_key.clone(), Vec::new());
manager.cache_loaded_plugins_if_current(
stale_generation,
cache_key.clone(),
Vec::new(),
PluginSkillSnapshots::for_plugin_load(),
);
assert_eq!(manager.cached_loaded_plugins(&cache_key), None);
}
@@ -2241,6 +2299,98 @@ async fn install_plugin_uses_manifest_version_for_non_curated_plugins() {
);
}
#[tokio::test]
async fn install_plugin_writes_marketplace_manifest_fallback_when_missing_plugin_json() {
let tmp = tempfile::tempdir().unwrap();
let repo_root = tmp.path().join("repo");
let plugin_root = repo_root.join("plugins/quality-review");
fs::create_dir_all(repo_root.join(".git")).unwrap();
fs::create_dir_all(repo_root.join(".agents/plugins")).unwrap();
fs::create_dir_all(plugin_root.join("skills/thermo-nuclear-code-quality-review")).unwrap();
fs::write(
plugin_root.join("skills/thermo-nuclear-code-quality-review/SKILL.md"),
"review skill",
)
.unwrap();
fs::write(
repo_root.join(".agents/plugins/marketplace.json"),
r#"{
"name": "debug",
"plugins": [
{
"name": "quality-review",
"description": "Strict code quality review focused on maintainability.",
"source": "./plugins/quality-review",
"author": {
"name": "Byron Grogan"
},
"skills": [
"./skills/thermo-nuclear-code-quality-review"
],
"category": "code-review"
}
]
}"#,
)
.unwrap();
let result = PluginsManager::new(tmp.path().to_path_buf())
.install_plugin(PluginInstallRequest {
plugin_name: "quality-review".to_string(),
marketplace_path: AbsolutePathBuf::try_from(
repo_root.join(".agents/plugins/marketplace.json"),
)
.unwrap(),
})
.await
.unwrap();
let installed_path = tmp.path().join("plugins/cache/debug/quality-review/local");
assert_eq!(
result,
PluginInstallOutcome {
plugin_id: PluginId::new("quality-review".to_string(), "debug".to_string()).unwrap(),
plugin_version: "local".to_string(),
installed_path: AbsolutePathBuf::try_from(installed_path.clone()).unwrap(),
auth_policy: MarketplacePluginAuthPolicy::OnInstall,
}
);
assert!(!plugin_root.join(".codex-plugin/plugin.json").exists());
assert!(
!tmp.path()
.join("plugins/.marketplace-plugin-source-staging")
.exists()
);
let manifest = crate::manifest::load_plugin_manifest(&installed_path).unwrap();
assert_eq!(manifest.name, "quality-review");
assert_eq!(
manifest.description.as_deref(),
Some("Strict code quality review focused on maintainability.")
);
assert_eq!(
manifest.paths.skills,
vec![
AbsolutePathBuf::try_from(
installed_path.join("skills/thermo-nuclear-code-quality-review")
)
.unwrap()
]
);
let interface = manifest.interface.expect("fallback interface");
assert_eq!(interface.developer_name.as_deref(), Some("Byron Grogan"));
assert_eq!(interface.category.as_deref(), Some("code-review"));
let fallback_json: serde_json::Value = serde_json::from_str(
&fs::read_to_string(installed_path.join(".codex-plugin/plugin.json")).unwrap(),
)
.unwrap();
assert_eq!(
fallback_json["author"],
serde_json::json!({ "name": "Byron Grogan" })
);
assert_eq!(fallback_json["category"], "code-review");
}
#[tokio::test]
async fn install_plugin_supports_git_subdir_marketplace_sources() {
let tmp = tempfile::tempdir().unwrap();
@@ -2484,6 +2634,7 @@ enabled = false
},
interface: None,
keywords: Vec::new(),
manifest_fallback: None,
installed: true,
enabled: true,
},
@@ -2503,6 +2654,7 @@ enabled = false
},
interface: None,
keywords: Vec::new(),
manifest_fallback: None,
installed: true,
enabled: false,
},
@@ -2632,6 +2784,7 @@ plugins = true
},
interface: None,
keywords: Vec::new(),
manifest_fallback: None,
installed: false,
enabled: false,
}]
@@ -2768,6 +2921,142 @@ plugins = true
assert!(api_key_outcome.plugin.apps.is_empty());
}
#[tokio::test]
async fn read_plugin_for_config_uses_marketplace_manifest_fallback_paths_for_local_source() {
let tmp = tempfile::tempdir().unwrap();
let repo_root = tmp.path().join("repo");
let plugin_root = repo_root.join("sample-plugin");
fs::create_dir_all(repo_root.join(".git")).unwrap();
fs::create_dir_all(repo_root.join(".agents/plugins")).unwrap();
write_file(
&repo_root.join(".agents/plugins/marketplace.json"),
r#"{
"name": "debug",
"plugins": [
{
"name": "sample-plugin",
"source": "./sample-plugin",
"apps": "./config/custom.app.json",
"mcpServers": {
"sample-mcp": {
"command": "sample-mcp"
}
}
}
]
}"#,
);
write_file(
&plugin_root.join("config/custom.app.json"),
r#"{"apps":{"sample-app":{"id":"connector_sample"}}}"#,
);
write_file(
&tmp.path().join(CONFIG_TOML_FILE),
r#"[features]
plugins = true
"#,
);
let config = load_config(tmp.path(), &repo_root).await;
let manager = PluginsManager::new(tmp.path().to_path_buf());
let outcome = manager
.read_plugin_for_config(
&config,
&PluginReadRequest {
plugin_name: "sample-plugin".to_string(),
marketplace_path: AbsolutePathBuf::try_from(
repo_root.join(".agents/plugins/marketplace.json"),
)
.unwrap(),
},
)
.await
.unwrap();
assert_eq!(
outcome.plugin.apps,
vec![AppConnectorId("connector_sample".to_string())]
);
assert_eq!(
outcome.plugin.mcp_server_names,
vec!["sample-mcp".to_string()]
);
let listed_plugin = manager
.list_marketplaces_for_config(
&config,
&[AbsolutePathBuf::try_from(repo_root.clone()).unwrap()],
/*include_openai_curated*/ false,
)
.unwrap()
.marketplaces
.into_iter()
.find(|marketplace| marketplace.name == "debug")
.unwrap()
.plugins
.into_iter()
.find(|plugin| plugin.name == "sample-plugin")
.unwrap();
let listed_detail = manager
.read_plugin_detail_for_marketplace_plugin(&config, "debug", listed_plugin)
.await
.unwrap();
assert_eq!(
listed_detail.apps,
vec![AppConnectorId("connector_sample".to_string())]
);
assert_eq!(
listed_detail.mcp_server_names,
vec!["sample-mcp".to_string()]
);
}
#[tokio::test]
async fn read_plugin_for_config_does_not_fallback_from_invalid_plugin_manifest() {
let tmp = tempfile::tempdir().unwrap();
let repo_root = tmp.path().join("repo");
let plugin_root = repo_root.join("sample-plugin");
fs::create_dir_all(repo_root.join(".git")).unwrap();
fs::create_dir_all(repo_root.join(".agents/plugins")).unwrap();
write_file(
&repo_root.join(".agents/plugins/marketplace.json"),
r#"{
"name": "debug",
"plugins": [
{
"name": "sample-plugin",
"source": "./sample-plugin",
"description": "Fallback metadata"
}
]
}"#,
);
write_file(&plugin_root.join(".codex-plugin/plugin.json"), "{");
write_file(
&tmp.path().join(CONFIG_TOML_FILE),
r#"[features]
plugins = true
"#,
);
let config = load_config(tmp.path(), &repo_root).await;
let err = PluginsManager::new(tmp.path().to_path_buf())
.read_plugin_for_config(
&config,
&PluginReadRequest {
plugin_name: "sample-plugin".to_string(),
marketplace_path: AbsolutePathBuf::try_from(
repo_root.join(".agents/plugins/marketplace.json"),
)
.unwrap(),
},
)
.await
.unwrap_err();
assert_eq!(err.to_string(), "missing or invalid plugin.json");
}
#[tokio::test]
async fn read_plugin_for_config_uses_user_layer_skill_settings_only() {
let tmp = tempfile::tempdir().unwrap();
@@ -3150,8 +3439,11 @@ enabled = true
.find(|marketplace| marketplace.name == "debug")
.expect("debug marketplace should be listed");
let mut plugins = marketplace.plugins;
assert!(plugins[0].manifest_fallback.is_some());
plugins[0].manifest_fallback = None;
assert_eq!(
marketplace.plugins,
plugins,
vec![ConfiguredMarketplacePlugin {
id: "toolkit@debug".to_string(),
name: "toolkit".to_string(),
@@ -3186,6 +3478,7 @@ enabled = true
..Default::default()
}),
keywords: Vec::new(),
manifest_fallback: None,
installed: true,
enabled: true,
}]
@@ -3266,6 +3559,7 @@ plugins = true
},
interface: None,
keywords: Vec::new(),
manifest_fallback: None,
installed: false,
enabled: false,
}],
@@ -3388,6 +3682,7 @@ plugins = true
},
interface: None,
keywords: Vec::new(),
manifest_fallback: None,
installed: false,
enabled: false,
}],
@@ -3815,6 +4110,7 @@ enabled = false
},
interface: None,
keywords: Vec::new(),
manifest_fallback: None,
installed: false,
enabled: true,
}]
@@ -3847,6 +4143,7 @@ enabled = false
},
interface: None,
keywords: Vec::new(),
manifest_fallback: None,
installed: false,
enabled: false,
}]
@@ -3937,6 +4234,7 @@ enabled = true
},
interface: None,
keywords: Vec::new(),
manifest_fallback: None,
installed: false,
enabled: true,
}],
@@ -4924,6 +5222,7 @@ async fn load_plugins_ignores_project_config_files() {
&stack,
std::collections::HashMap::new(),
&PluginStore::new(codex_home.path().to_path_buf()),
/*plugin_skill_snapshots*/ None,
Some(Product::Codex),
/*prefer_remote_curated_conflicts*/ false,
)
+157 -1
View File
@@ -8,6 +8,7 @@ use codex_plugin::PluginIdError;
use codex_protocol::protocol::Product;
use codex_utils_absolute_path::AbsolutePathBuf;
use serde::Deserialize;
use serde_json::Map as JsonMap;
use serde_json::Value as JsonValue;
use std::fs;
use std::io;
@@ -29,6 +30,7 @@ pub struct ResolvedMarketplacePlugin {
pub policy: MarketplacePluginPolicy,
pub interface: Option<PluginManifestInterface>,
pub manifest: Option<crate::manifest::PluginManifest>,
pub manifest_fallback: MarketplacePluginManifestFallback,
}
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -56,6 +58,57 @@ pub struct MarketplaceInterface {
pub display_name: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct MarketplacePluginManifestFallback {
contents: String,
has_metadata: bool,
}
impl MarketplacePluginManifestFallback {
pub fn contents(&self) -> &str {
&self.contents
}
pub(crate) fn contents_if_has_metadata(&self) -> Option<&str> {
self.has_metadata.then_some(self.contents())
}
pub(crate) fn parse_for_plugin_root(
&self,
plugin_root: &Path,
) -> Option<crate::manifest::PluginManifest> {
crate::manifest::parse_plugin_manifest(
plugin_root,
&fallback_plugin_manifest_path(plugin_root),
&self.contents,
)
.ok()
}
pub(crate) fn parse_for_listing(&self) -> Option<crate::manifest::PluginManifest> {
// Git sources have no plugin root before install. Parse against a synthetic absolute root,
// then discard path-bearing fields so listings expose metadata only.
let mut manifest = crate::manifest::parse_plugin_manifest(
Path::new("/"),
Path::new("/.codex-plugin/plugin.json"),
&self.contents,
)
.ok()?;
manifest.paths = crate::manifest::PluginManifestPaths {
skills: Vec::new(),
mcp_servers: None,
apps: None,
hooks: None,
};
if let Some(interface) = manifest.interface.as_mut() {
interface.composer_icon = None;
interface.logo = None;
interface.screenshots.clear();
}
Some(manifest)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct MarketplacePlugin {
pub name: String,
@@ -64,6 +117,7 @@ pub struct MarketplacePlugin {
pub policy: MarketplacePluginPolicy,
pub interface: Option<PluginManifestInterface>,
pub keywords: Vec<String>,
pub manifest_fallback: Option<MarketplacePluginManifestFallback>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -313,6 +367,10 @@ pub fn load_marketplace(path: &AbsolutePathBuf) -> Result<Marketplace, Marketpla
Err(err) => return Err(err),
};
let manifest_fallback = plugin
.manifest_fallback
.contents_if_has_metadata()
.map(|_| plugin.manifest_fallback.clone());
let local_version = plugin
.manifest
.as_ref()
@@ -329,6 +387,7 @@ pub fn load_marketplace(path: &AbsolutePathBuf) -> Result<Marketplace, Marketpla
policy: plugin.policy,
interface: plugin.interface,
keywords,
manifest_fallback,
});
}
@@ -434,13 +493,27 @@ fn resolve_marketplace_plugin_entry(
source,
policy,
category,
manifest_fields,
} = plugin;
let Some(source) = resolve_supported_plugin_source(marketplace_path, &name, source) else {
return Ok(None);
};
let manifest_fallback =
marketplace_plugin_manifest_fallback(&name, category.as_deref(), &manifest_fields);
let manifest = match &source {
MarketplacePluginSource::Local { path } => load_plugin_manifest(path.as_path()),
MarketplacePluginSource::Local { path } => {
if codex_utils_plugins::find_plugin_manifest_path(path.as_path()).is_some() {
load_plugin_manifest(path.as_path())
} else if manifest_fallback.has_metadata {
manifest_fallback.parse_for_plugin_root(path.as_path())
} else {
None
}
}
MarketplacePluginSource::Git { .. } if manifest_fallback.has_metadata => {
manifest_fallback.parse_for_listing()
}
MarketplacePluginSource::Git { .. } => None,
};
let interface = plugin_interface_with_marketplace_category(
@@ -462,6 +535,7 @@ fn resolve_marketplace_plugin_entry(
},
interface,
manifest,
manifest_fallback,
}))
}
@@ -765,6 +839,9 @@ struct RawMarketplaceManifestPlugin {
policy: RawMarketplaceManifestPluginPolicy,
#[serde(default)]
category: Option<String>,
#[serde(default)]
#[serde(flatten)]
manifest_fields: JsonMap<String, JsonValue>,
}
#[derive(Debug, Clone, Default, PartialEq, Eq, Deserialize)]
@@ -822,6 +899,85 @@ fn resolve_marketplace_interface(
}
}
fn fallback_plugin_manifest_path(plugin_root: &Path) -> PathBuf {
plugin_root.join(".codex-plugin/plugin.json")
}
fn marketplace_plugin_manifest_fallback(
name: &str,
category: Option<&str>,
manifest_fields: &JsonMap<String, JsonValue>,
) -> MarketplacePluginManifestFallback {
let mut manifest = manifest_fields.clone();
manifest.insert("name".to_string(), JsonValue::String(name.to_string()));
if let Some(category) = category {
manifest.insert(
"category".to_string(),
JsonValue::String(category.to_string()),
);
}
if let Some(interface) = plugin_manifest_interface(manifest_fields, category) {
manifest.insert("interface".to_string(), interface);
}
let contents = serde_json::to_string_pretty(&JsonValue::Object(manifest))
.unwrap_or_else(|_| format!(r#"{{"name":"{name}"}}"#));
MarketplacePluginManifestFallback {
contents,
has_metadata: !manifest_fields.is_empty() || category.is_some(),
}
}
fn plugin_manifest_interface(
fields: &JsonMap<String, JsonValue>,
category: Option<&str>,
) -> Option<JsonValue> {
let mut interface = fields
.get("interface")
.and_then(JsonValue::as_object)
.cloned()
.unwrap_or_default();
if !interface.contains_key("displayName")
&& let Some(display_name) = fields.get("displayName").and_then(JsonValue::as_str)
{
interface.insert(
"displayName".to_string(),
JsonValue::String(display_name.to_string()),
);
}
if !interface.contains_key("developerName")
&& let Some(author_name) = fields
.get("author")
.and_then(|author| author.get("name"))
.and_then(JsonValue::as_str)
.map(str::trim)
.filter(|value| !value.is_empty())
{
interface.insert(
"developerName".to_string(),
JsonValue::String(author_name.to_string()),
);
}
if !interface.contains_key("websiteUrl")
&& !interface.contains_key("websiteURL")
&& let Some(homepage) = fields.get("homepage").and_then(JsonValue::as_str)
{
interface.insert(
"websiteUrl".to_string(),
JsonValue::String(homepage.to_string()),
);
}
if let Some(category) = category.map(str::trim).filter(|value| !value.is_empty()) {
interface.insert(
"category".to_string(),
JsonValue::String(category.to_string()),
);
}
(!interface.is_empty()).then_some(JsonValue::Object(interface))
}
#[cfg(test)]
#[path = "marketplace_tests.rs"]
mod tests;
+250 -4
View File
@@ -20,6 +20,17 @@ fn write_alternate_plugin_manifest(plugin_root: &Path, contents: &str) {
fs::write(manifest_path, contents).unwrap();
}
fn minimal_manifest_fallback(name: &str) -> MarketplacePluginManifestFallback {
MarketplacePluginManifestFallback {
contents: format!(
r#"{{
"name": "{name}"
}}"#
),
has_metadata: false,
}
}
#[test]
fn find_marketplace_plugin_finds_repo_marketplace_plugin() {
let tmp = tempdir().unwrap();
@@ -65,6 +76,7 @@ fn find_marketplace_plugin_finds_repo_marketplace_plugin() {
},
interface: None,
manifest: None,
manifest_fallback: minimal_manifest_fallback("local-plugin"),
}
);
}
@@ -108,6 +120,7 @@ fn find_marketplace_plugin_supports_alternate_layout_and_string_local_source() {
},
interface: None,
manifest: None,
manifest_fallback: minimal_manifest_fallback("string-source-plugin"),
}
);
}
@@ -162,10 +175,219 @@ fn find_marketplace_plugin_supports_git_subdir_sources() {
},
interface: None,
manifest: None,
manifest_fallback: minimal_manifest_fallback("remote-plugin"),
}
);
}
#[test]
fn find_marketplace_plugin_builds_manifest_fallback_from_entry() {
let tmp = tempdir().unwrap();
let repo_root = tmp.path().join("repo");
let plugin_root = repo_root.join("plugins/quality-review");
fs::create_dir_all(repo_root.join(".git")).unwrap();
fs::create_dir_all(repo_root.join(".agents/plugins")).unwrap();
fs::create_dir_all(plugin_root.join("skills/thermo-nuclear-code-quality-review")).unwrap();
fs::create_dir_all(plugin_root.join("skills/second-review")).unwrap();
fs::write(
repo_root.join(".agents/plugins/marketplace.json"),
r##"{
"name": "team-marketplace",
"plugins": [
{
"name": "quality-review",
"version": "1.2.3",
"description": "Strict code quality review focused on maintainability.",
"displayName": "Quality Review",
"source": "./plugins/quality-review",
"author": {
"name": "Byron Grogan"
},
"homepage": "https://example.com/quality",
"repository": "https://github.com/example/quality-review",
"license": "MIT",
"skills": [
"./skills/thermo-nuclear-code-quality-review",
"./skills/second-review"
],
"commands": ["./commands/review.md"],
"mcpServers": {
"review": {
"type": "stdio",
"command": "review-mcp"
}
},
"apps": "./apps/app.json",
"hooks": ["./hooks/session.json"],
"agents": [
"./agents/thermo-nuclear-code-quality-review.md"
],
"category": "code-review",
"keywords": ["quality", "review"],
"strict": false,
"interface": {
"shortDescription": "Interface short description.",
"longDescription": "Runs strict reviews focused on maintainability and boundaries.",
"category": "interface-category",
"capabilities": ["review", "quality"],
"privacyPolicyURL": "https://example.com/privacy",
"termsOfServiceUrl": "https://example.com/terms",
"defaultPrompt": [
"Review this change",
"Find structural issues"
],
"brandColor": "#00AAFF",
"composerIcon": "./assets/icon.svg",
"logo": "./assets/logo.png",
"screenshots": ["./assets/shot.png"]
}
}
]
}"##,
)
.unwrap();
let resolved = find_marketplace_plugin(
&AbsolutePathBuf::try_from(repo_root.join(".agents/plugins/marketplace.json")).unwrap(),
"quality-review",
)
.unwrap();
let manifest = resolved.manifest.as_ref().expect("fallback manifest");
assert_eq!(manifest.name, "quality-review");
assert_eq!(manifest.version.as_deref(), Some("1.2.3"));
assert_eq!(
manifest.description.as_deref(),
Some("Strict code quality review focused on maintainability.")
);
assert_eq!(
manifest.paths.skills,
vec![
AbsolutePathBuf::try_from(
plugin_root.join("skills/thermo-nuclear-code-quality-review")
)
.unwrap(),
AbsolutePathBuf::try_from(plugin_root.join("skills/second-review")).unwrap(),
]
);
let Some(crate::manifest::PluginManifestMcpServers::Object(mcp_servers)) =
manifest.paths.mcp_servers.as_ref()
else {
panic!("fallback mcpServers should be inline");
};
assert_eq!(
serde_json::from_str::<JsonValue>(mcp_servers).unwrap(),
serde_json::json!({
"review": {
"type": "stdio",
"command": "review-mcp"
}
})
);
assert_eq!(
manifest.paths.apps.as_ref(),
Some(&AbsolutePathBuf::try_from(plugin_root.join("apps/app.json")).unwrap())
);
assert_eq!(
manifest.paths.hooks.as_ref(),
Some(&crate::manifest::PluginManifestHooks::Paths(vec![
AbsolutePathBuf::try_from(plugin_root.join("hooks/session.json")).unwrap()
]))
);
assert_eq!(manifest.keywords, vec!["quality", "review"]);
let interface = manifest.interface.as_ref().expect("fallback interface");
assert_eq!(
interface,
&PluginManifestInterface {
display_name: Some("Quality Review".to_string()),
short_description: Some("Interface short description.".to_string()),
long_description: Some(
"Runs strict reviews focused on maintainability and boundaries.".to_string()
),
developer_name: Some("Byron Grogan".to_string()),
category: Some("code-review".to_string()),
capabilities: vec!["review".to_string(), "quality".to_string()],
website_url: Some("https://example.com/quality".to_string()),
privacy_policy_url: Some("https://example.com/privacy".to_string()),
terms_of_service_url: Some("https://example.com/terms".to_string()),
default_prompt: Some(vec![
"Review this change".to_string(),
"Find structural issues".to_string()
]),
brand_color: Some("#00AAFF".to_string()),
composer_icon: Some(
AbsolutePathBuf::try_from(plugin_root.join("assets/icon.svg")).unwrap()
),
logo: Some(AbsolutePathBuf::try_from(plugin_root.join("assets/logo.png")).unwrap()),
screenshots: vec![
AbsolutePathBuf::try_from(plugin_root.join("assets/shot.png")).unwrap()
],
}
);
let fallback_json: JsonValue =
serde_json::from_str(resolved.manifest_fallback.contents()).unwrap();
assert_eq!(
fallback_json["skills"],
serde_json::json!([
"./skills/thermo-nuclear-code-quality-review",
"./skills/second-review"
])
);
assert_eq!(
fallback_json["mcpServers"],
serde_json::json!({
"review": {
"type": "stdio",
"command": "review-mcp"
}
})
);
assert_eq!(
fallback_json["displayName"],
JsonValue::String("Quality Review".to_string())
);
assert_eq!(
fallback_json["interface"]["websiteUrl"],
JsonValue::String("https://example.com/quality".to_string())
);
assert_eq!(
fallback_json["interface"]["privacyPolicyURL"],
JsonValue::String("https://example.com/privacy".to_string())
);
assert!(fallback_json["interface"].get("privacyPolicyUrl").is_none());
assert_eq!(
fallback_json["author"],
serde_json::json!({ "name": "Byron Grogan" })
);
assert_eq!(
fallback_json["agents"],
serde_json::json!(["./agents/thermo-nuclear-code-quality-review.md"])
);
assert_eq!(
fallback_json["commands"],
serde_json::json!(["./commands/review.md"])
);
assert_eq!(fallback_json["strict"], JsonValue::Bool(false));
assert_eq!(
fallback_json["homepage"],
JsonValue::String("https://example.com/quality".to_string())
);
assert_eq!(
fallback_json["repository"],
JsonValue::String("https://github.com/example/quality-review".to_string())
);
assert_eq!(
fallback_json["license"],
JsonValue::String("MIT".to_string())
);
assert_eq!(
fallback_json["category"],
JsonValue::String("code-review".to_string())
);
assert!(resolved.manifest_fallback.has_metadata);
}
#[test]
fn find_marketplace_plugin_normalizes_github_shorthand_with_dot_git_suffix() {
let tmp = tempdir().unwrap();
@@ -415,6 +637,7 @@ fn list_marketplaces_supports_alternate_manifest_layout() {
screenshots: Vec::new(),
}),
keywords: Vec::new(),
manifest_fallback: None,
}],
}]
);
@@ -500,6 +723,7 @@ fn list_marketplaces_supports_repo_root_local_plugin_sources() {
screenshots: Vec::new(),
}),
keywords: Vec::new(),
manifest_fallback: None,
}],
}]
);
@@ -552,6 +776,7 @@ fn list_marketplaces_includes_plugins_without_discoverable_manifest() {
},
interface: None,
keywords: Vec::new(),
manifest_fallback: None,
}],
}]
);
@@ -659,6 +884,7 @@ fn list_marketplaces_supports_explicit_api_marketplace_manifest_path() {
},
interface: None,
keywords: Vec::new(),
manifest_fallback: None,
}],
}]
);
@@ -750,6 +976,7 @@ fn list_marketplaces_returns_home_and_repo_marketplaces() {
},
interface: None,
keywords: Vec::new(),
manifest_fallback: None,
},
MarketplacePlugin {
name: "home-only".to_string(),
@@ -764,6 +991,7 @@ fn list_marketplaces_returns_home_and_repo_marketplaces() {
},
interface: None,
keywords: Vec::new(),
manifest_fallback: None,
},
],
},
@@ -787,6 +1015,7 @@ fn list_marketplaces_returns_home_and_repo_marketplaces() {
},
interface: None,
keywords: Vec::new(),
manifest_fallback: None,
},
MarketplacePlugin {
name: "repo-only".to_string(),
@@ -801,6 +1030,7 @@ fn list_marketplaces_returns_home_and_repo_marketplaces() {
},
interface: None,
keywords: Vec::new(),
manifest_fallback: None,
},
],
},
@@ -880,6 +1110,7 @@ fn list_marketplaces_keeps_distinct_entries_for_same_name() {
},
interface: None,
keywords: Vec::new(),
manifest_fallback: None,
}],
},
Marketplace {
@@ -899,6 +1130,7 @@ fn list_marketplaces_keeps_distinct_entries_for_same_name() {
},
interface: None,
keywords: Vec::new(),
manifest_fallback: None,
}],
},
]
@@ -974,6 +1206,7 @@ fn list_marketplaces_dedupes_multiple_roots_in_same_repo() {
},
interface: None,
keywords: Vec::new(),
manifest_fallback: None,
}],
}]
);
@@ -1138,6 +1371,7 @@ fn list_marketplaces_skips_plugins_with_invalid_names_but_keeps_marketplace() {
},
interface: None,
keywords: Vec::new(),
manifest_fallback: None,
}],
}]
);
@@ -1220,6 +1454,9 @@ fn list_marketplaces_keeps_remote_and_local_plugin_sources() {
},
{
"name": "git-subdir-plugin",
"version": "1.2.3",
"displayName": "Git Subdir Plugin",
"keywords": ["git", "remote"],
"source": {
"source": "git-subdir",
"url": "owner/repo",
@@ -1240,8 +1477,11 @@ fn list_marketplaces_keeps_remote_and_local_plugin_sources() {
.marketplaces;
assert_eq!(marketplaces.len(), 1);
let mut plugins = marketplaces[0].plugins.clone();
assert!(plugins[2].manifest_fallback.is_some());
plugins[2].manifest_fallback = None;
assert_eq!(
marketplaces[0].plugins,
plugins,
vec![
MarketplacePlugin {
name: "local-plugin".to_string(),
@@ -1257,6 +1497,7 @@ fn list_marketplaces_keeps_remote_and_local_plugin_sources() {
},
interface: None,
keywords: Vec::new(),
manifest_fallback: None,
},
MarketplacePlugin {
name: "url-plugin".to_string(),
@@ -1274,10 +1515,11 @@ fn list_marketplaces_keeps_remote_and_local_plugin_sources() {
},
interface: None,
keywords: Vec::new(),
manifest_fallback: None,
},
MarketplacePlugin {
name: "git-subdir-plugin".to_string(),
local_version: None,
local_version: Some("1.2.3".to_string()),
source: MarketplacePluginSource::Git {
url: "https://github.com/owner/repo.git".to_string(),
path: Some("plugins/example".to_string()),
@@ -1289,8 +1531,12 @@ fn list_marketplaces_keeps_remote_and_local_plugin_sources() {
authentication: MarketplacePluginAuthPolicy::OnInstall,
products: None,
},
interface: None,
keywords: Vec::new(),
interface: Some(PluginManifestInterface {
display_name: Some("Git Subdir Plugin".to_string()),
..Default::default()
}),
keywords: vec!["git".to_string(), "remote".to_string()],
manifest_fallback: None,
},
]
);
+31 -7
View File
@@ -293,13 +293,37 @@ async fn download_remote_plugin_bundle_with_limit(
let url = final_url.to_string();
let status = response.status();
if !status.is_success() {
let body = read_response_body_with_limit(
response,
&url,
/*max_bytes*/ REMOTE_PLUGIN_BUNDLE_ERROR_BODY_MAX_BYTES,
)
.await?;
let body = String::from_utf8_lossy(&body).to_string();
let mut response = response;
let mut body = Vec::new();
let mut body_truncated = false;
let mut body_read_error = None;
loop {
let chunk = match response.chunk().await {
Ok(Some(chunk)) => chunk,
Ok(None) => break,
Err(source) => {
body_read_error = Some(source);
break;
}
};
let remaining = REMOTE_PLUGIN_BUNDLE_ERROR_BODY_MAX_BYTES as usize - body.len();
if chunk.len() > remaining {
body.extend_from_slice(&chunk[..remaining]);
body_truncated = true;
break;
}
body.extend_from_slice(&chunk);
}
let mut body = String::from_utf8_lossy(&body).into_owned();
if body_truncated {
body.push_str(&format!(
"\n[response body truncated after {REMOTE_PLUGIN_BUNDLE_ERROR_BODY_MAX_BYTES} bytes]"
));
}
if let Some(source) = body_read_error {
body.push_str(&format!("\n[failed to read response body: {source}]"));
}
return Err(RemotePluginBundleInstallError::DownloadStatus { url, status, body });
}
+141 -14
View File
@@ -1,5 +1,6 @@
use crate::manifest::PluginManifest;
use crate::manifest::load_plugin_manifest;
use crate::manifest::parse_plugin_manifest;
use codex_plugin::PluginId;
use codex_plugin::validate_plugin_segment;
use codex_utils_absolute_path::AbsolutePathBuf;
@@ -30,6 +31,12 @@ pub struct PluginStore {
data_root: AbsolutePathBuf,
}
#[derive(Clone, Copy)]
enum InstallManifest<'a> {
OnDisk,
Fallback(&'a str),
}
impl PluginStore {
pub fn new(codex_home: PathBuf) -> Self {
Self::try_new(codex_home)
@@ -104,8 +111,20 @@ impl PluginStore {
source_path: AbsolutePathBuf,
plugin_id: PluginId,
) -> Result<PluginInstallResult, PluginStoreError> {
let plugin_version = plugin_version_for_source(source_path.as_path())?;
self.install_with_version(source_path, plugin_id, plugin_version)
self.install_with_manifest(source_path, plugin_id, InstallManifest::OnDisk)
}
pub(crate) fn install_with_fallback_manifest(
&self,
source_path: AbsolutePathBuf,
plugin_id: PluginId,
manifest_contents: &str,
) -> Result<PluginInstallResult, PluginStoreError> {
self.install_with_manifest(
source_path,
plugin_id,
InstallManifest::Fallback(manifest_contents),
)
}
pub fn install_with_version(
@@ -113,6 +132,47 @@ impl PluginStore {
source_path: AbsolutePathBuf,
plugin_id: PluginId,
plugin_version: String,
) -> Result<PluginInstallResult, PluginStoreError> {
self.install_with_version_and_manifest(
source_path,
plugin_id,
plugin_version,
InstallManifest::OnDisk,
)
}
pub(crate) fn install_with_version_and_fallback_manifest(
&self,
source_path: AbsolutePathBuf,
plugin_id: PluginId,
plugin_version: String,
manifest_contents: &str,
) -> Result<PluginInstallResult, PluginStoreError> {
self.install_with_version_and_manifest(
source_path,
plugin_id,
plugin_version,
InstallManifest::Fallback(manifest_contents),
)
}
fn install_with_manifest(
&self,
source_path: AbsolutePathBuf,
plugin_id: PluginId,
manifest: InstallManifest<'_>,
) -> Result<PluginInstallResult, PluginStoreError> {
let manifest = resolve_install_manifest(source_path.as_path(), manifest);
let plugin_version = plugin_version_for_install_manifest(source_path.as_path(), manifest)?;
self.install_with_version_and_manifest(source_path, plugin_id, plugin_version, manifest)
}
fn install_with_version_and_manifest(
&self,
source_path: AbsolutePathBuf,
plugin_id: PluginId,
plugin_version: String,
manifest: InstallManifest<'_>,
) -> Result<PluginInstallResult, PluginStoreError> {
if !source_path.as_path().is_dir() {
return Err(PluginStoreError::Invalid(format!(
@@ -121,7 +181,8 @@ impl PluginStore {
)));
}
let plugin_name = plugin_name_for_source(source_path.as_path())?;
let manifest = resolve_install_manifest(source_path.as_path(), manifest);
let plugin_name = plugin_name_for_source(source_path.as_path(), manifest)?;
if plugin_name != plugin_id.plugin_name {
return Err(PluginStoreError::Invalid(format!(
"plugin.json name `{plugin_name}` does not match marketplace plugin name `{}`",
@@ -134,6 +195,7 @@ impl PluginStore {
source_path.as_path(),
self.plugin_base_root(&plugin_id).as_path(),
&plugin_version,
manifest,
)?;
Ok(PluginInstallResult {
@@ -168,7 +230,37 @@ impl PluginStoreError {
}
pub fn plugin_version_for_source(source_path: &Path) -> Result<String, PluginStoreError> {
let plugin_version = plugin_manifest_version_for_source(source_path)?
plugin_version_for_install_manifest(source_path, InstallManifest::OnDisk)
}
pub(crate) fn plugin_version_for_source_with_fallback_manifest(
source_path: &Path,
manifest_contents: &str,
) -> Result<String, PluginStoreError> {
let manifest =
resolve_install_manifest(source_path, InstallManifest::Fallback(manifest_contents));
plugin_version_for_install_manifest(source_path, manifest)
}
fn resolve_install_manifest<'a>(
source_path: &Path,
manifest: InstallManifest<'a>,
) -> InstallManifest<'a> {
// A real plugin manifest always wins. The fallback only fills the gap for marketplace
// sources that cannot be changed in place because they may be user-owned directories.
match manifest {
InstallManifest::Fallback(_) if find_plugin_manifest_path(source_path).is_some() => {
InstallManifest::OnDisk
}
manifest => manifest,
}
}
fn plugin_version_for_install_manifest(
source_path: &Path,
manifest: InstallManifest<'_>,
) -> Result<String, PluginStoreError> {
let plugin_version = plugin_manifest_version_for_source(source_path, manifest)?
.unwrap_or_else(|| DEFAULT_PLUGIN_VERSION.to_string());
validate_plugin_version_segment(&plugin_version).map_err(PluginStoreError::Invalid)?;
Ok(plugin_version)
@@ -193,9 +285,20 @@ pub fn validate_plugin_version_segment(plugin_version: &str) -> Result<(), Strin
Ok(())
}
fn plugin_manifest_for_source(source_path: &Path) -> Result<PluginManifest, PluginStoreError> {
load_plugin_manifest(source_path)
.ok_or_else(|| PluginStoreError::Invalid("missing or invalid plugin.json".to_string()))
fn plugin_manifest_for_source(
source_path: &Path,
manifest: InstallManifest<'_>,
) -> Result<PluginManifest, PluginStoreError> {
match manifest {
InstallManifest::OnDisk => load_plugin_manifest(source_path)
.ok_or_else(|| PluginStoreError::Invalid("missing or invalid plugin.json".to_string())),
InstallManifest::Fallback(contents) => parse_plugin_manifest(
source_path,
&source_path.join(".codex-plugin/plugin.json"),
contents,
)
.map_err(|err| PluginStoreError::Invalid(format!("failed to parse plugin.json: {err}"))),
}
}
#[derive(Debug, Deserialize)]
@@ -207,12 +310,17 @@ struct RawPluginManifestVersion {
fn plugin_manifest_version_for_source(
source_path: &Path,
manifest: InstallManifest<'_>,
) -> Result<Option<String>, PluginStoreError> {
let manifest_path = find_plugin_manifest_path(source_path)
.ok_or_else(|| PluginStoreError::Invalid("missing plugin.json".to_string()))?;
let contents = fs::read_to_string(&manifest_path)
.map_err(|err| PluginStoreError::io("failed to read plugin.json", err))?;
let contents = match manifest {
InstallManifest::OnDisk => {
let manifest_path = find_plugin_manifest_path(source_path)
.ok_or_else(|| PluginStoreError::Invalid("missing plugin.json".to_string()))?;
fs::read_to_string(&manifest_path)
.map_err(|err| PluginStoreError::io("failed to read plugin.json", err))?
}
InstallManifest::Fallback(contents) => contents.to_string(),
};
let manifest: RawPluginManifestVersion = serde_json::from_str(&contents)
.map_err(|err| PluginStoreError::Invalid(format!("failed to parse plugin.json: {err}")))?;
let Some(version) = manifest.version else {
@@ -232,8 +340,11 @@ fn plugin_manifest_version_for_source(
Ok(Some(version.to_string()))
}
fn plugin_name_for_source(source_path: &Path) -> Result<String, PluginStoreError> {
let manifest = plugin_manifest_for_source(source_path)?;
fn plugin_name_for_source(
source_path: &Path,
manifest: InstallManifest<'_>,
) -> Result<String, PluginStoreError> {
let manifest = plugin_manifest_for_source(source_path, manifest)?;
let plugin_name = manifest.name;
validate_plugin_segment(&plugin_name, "plugin name")
@@ -261,6 +372,7 @@ fn replace_plugin_root_atomically(
source: &Path,
target_root: &Path,
plugin_version: &str,
manifest: InstallManifest<'_>,
) -> Result<(), PluginStoreError> {
let Some(parent) = target_root.parent() else {
return Err(PluginStoreError::Invalid(format!(
@@ -287,6 +399,21 @@ fn replace_plugin_root_atomically(
let staged_root = staged_dir.path().join(plugin_dir_name);
let staged_version_root = staged_root.join(plugin_version);
copy_dir_recursive(source, &staged_version_root)?;
if let InstallManifest::Fallback(contents) = manifest {
// Inject the generated manifest into Store's existing atomic copy so install does not
// mutate the original source or require a second staging directory.
let manifest_path = staged_version_root.join(".codex-plugin/plugin.json");
let Some(manifest_parent) = manifest_path.parent() else {
return Err(PluginStoreError::Invalid(
"plugin manifest path has no parent".to_string(),
));
};
fs::create_dir_all(manifest_parent).map_err(|err| {
PluginStoreError::io("failed to create plugin manifest directory", err)
})?;
fs::write(&manifest_path, contents)
.map_err(|err| PluginStoreError::io("failed to write fallback plugin manifest", err))?;
}
let target_version_root = target_root.join(plugin_version);
if target_root.exists() && !target_version_root.exists() {
+3 -2
View File
@@ -192,7 +192,7 @@ fn install_with_version_uses_requested_cache_version() {
}
#[test]
fn install_uses_manifest_version_when_present() {
fn install_prefers_on_disk_manifest_version_over_fallback() {
let tmp = tempdir().unwrap();
write_plugin_with_version(
tmp.path(),
@@ -203,9 +203,10 @@ fn install_uses_manifest_version_when_present() {
let plugin_id = PluginId::new("sample-plugin".to_string(), "debug".to_string()).unwrap();
let result = PluginStore::new(tmp.path().to_path_buf())
.install(
.install_with_fallback_manifest(
AbsolutePathBuf::try_from(tmp.path().join("sample-plugin")).unwrap(),
plugin_id.clone(),
r#"{"name":"sample-plugin","version":"9.9.9"}"#,
)
.unwrap();
@@ -210,8 +210,14 @@ async fn load_plugin_metadata(
}
let manifest = load_plugin_manifest(plugin_root.as_path())
.ok_or_else(|| "missing or invalid plugin.json".to_string())?;
let skill_inventory =
load_plugin_skill_inventory(plugin_root, &plugin_id, &manifest, restriction_product).await;
let skill_inventory = load_plugin_skill_inventory(
plugin_root,
&plugin_id,
&manifest,
restriction_product,
/*plugin_skill_snapshots*/ None,
)
.await;
let mut mcp_server_names =
load_plugin_mcp_servers(plugin_root.as_path(), /*auth_mode*/ None)
.await
+2
View File
@@ -6,6 +6,7 @@ mod mention_counts;
pub mod model;
pub mod remote;
pub mod render;
mod root_loader;
pub mod service;
mod skill_instructions;
pub mod system;
@@ -29,6 +30,7 @@ pub use render::SkillRenderReport;
pub use render::build_available_skills;
pub use render::default_skill_metadata_budget;
pub use render::render_available_skills_body;
pub use root_loader::PluginSkillSnapshots;
pub use service::SkillsLoadInput;
pub use service::SkillsService;
pub use skill_instructions::SkillInstructions;
+40 -68
View File
@@ -1,6 +1,5 @@
use crate::model::SkillDependencies;
use crate::model::SkillError;
use crate::model::SkillFileSystemsByPath;
use crate::model::SkillInterface;
use crate::model::SkillLoadOutcome;
use crate::model::SkillMetadata;
@@ -24,7 +23,6 @@ use codex_utils_plugins::PluginSkillRoot;
use codex_utils_plugins::plugin_namespace_for_skill_path;
use dirs::home_dir;
use serde::Deserialize;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::error::Error;
@@ -161,77 +159,51 @@ pub struct SkillRoot {
pub plugin_root: Option<AbsolutePathBuf>,
}
pub async fn load_skills_from_roots<I>(roots: I) -> SkillLoadOutcome
pub async fn load_skills_from_roots<I>(
roots: I,
plugin_skill_snapshots: Option<&crate::PluginSkillSnapshots>,
) -> SkillLoadOutcome
where
I: IntoIterator<Item = SkillRoot>,
{
crate::root_loader::load_and_merge_skill_roots(roots, plugin_skill_snapshots).await
}
#[derive(Clone)]
pub(crate) struct SkillRootSnapshot {
pub(crate) root: AbsolutePathBuf,
pub(crate) skills: Vec<SkillMetadata>,
pub(crate) errors: Vec<SkillError>,
pub(crate) file_system: Arc<dyn ExecutorFileSystem>,
}
pub(crate) async fn load_skill_root(root: SkillRoot) -> SkillRootSnapshot {
let SkillRoot {
path,
scope,
file_system,
plugin_id,
plugin_namespace,
plugin_root,
} = root;
let root = canonicalize_for_skill_identity(file_system.as_ref(), &path).await;
let mut outcome = SkillLoadOutcome::default();
let mut skill_roots: Vec<AbsolutePathBuf> = Vec::new();
let mut skill_root_by_path: HashMap<AbsolutePathBuf, AbsolutePathBuf> = HashMap::new();
let mut file_systems_by_skill_path: HashMap<AbsolutePathBuf, Arc<dyn ExecutorFileSystem>> =
HashMap::new();
for root in roots {
let fs = root.file_system;
let root_path = canonicalize_for_skill_identity(fs.as_ref(), &root.path).await;
let skills_before_root = outcome.skills.len();
discover_skills_under_root(
fs.as_ref(),
&root_path,
root.scope,
root.plugin_id.as_deref(),
root.plugin_namespace.as_deref(),
root.plugin_root.as_ref(),
&mut outcome,
)
.await;
for skill in &outcome.skills[skills_before_root..] {
if !skill_roots.contains(&root_path) {
skill_roots.push(root_path.clone());
}
skill_root_by_path
.entry(skill.path_to_skills_md.clone())
.or_insert_with(|| root_path.clone());
file_systems_by_skill_path
.entry(skill.path_to_skills_md.clone())
.or_insert_with(|| Arc::clone(&fs));
}
discover_skills_under_root(
file_system.as_ref(),
&root,
scope,
plugin_id.as_deref(),
plugin_namespace.as_deref(),
plugin_root.as_ref(),
&mut outcome,
)
.await;
SkillRootSnapshot {
root,
skills: outcome.skills,
errors: outcome.errors,
file_system,
}
let mut seen: HashSet<AbsolutePathBuf> = HashSet::new();
outcome
.skills
.retain(|skill| seen.insert(skill.path_to_skills_md.clone()));
let retained_skill_paths: HashSet<AbsolutePathBuf> = outcome
.skills
.iter()
.map(|skill| skill.path_to_skills_md.clone())
.collect();
skill_root_by_path.retain(|path, _| retained_skill_paths.contains(path));
let used_roots: HashSet<AbsolutePathBuf> = skill_root_by_path.values().cloned().collect();
skill_roots.retain(|root| used_roots.contains(root));
file_systems_by_skill_path.retain(|path, _| retained_skill_paths.contains(path));
outcome.skill_roots = skill_roots;
outcome.skill_root_by_path = Arc::new(skill_root_by_path);
outcome.file_systems_by_skill_path = SkillFileSystemsByPath::new(file_systems_by_skill_path);
fn scope_rank(scope: SkillScope) -> u8 {
// Higher-priority scopes first (matches root scan order for dedupe).
match scope {
SkillScope::Repo => 0,
SkillScope::User => 1,
SkillScope::System => 2,
SkillScope::Admin => 3,
}
}
outcome.skills.sort_by(|a, b| {
scope_rank(a.scope)
.cmp(&scope_rank(b.scope))
.then_with(|| a.name.cmp(&b.name))
.then_with(|| a.path_to_skills_md.cmp(&b.path_to_skills_md))
});
outcome
}
pub(crate) async fn skill_roots(
+111 -83
View File
@@ -128,6 +128,7 @@ async fn load_skills_for_test(config: &TestConfig) -> SkillLoadOutcome {
/*home_dir*/ None,
)
.await,
/*plugin_skill_snapshots*/ None,
)
.await
}
@@ -315,7 +316,7 @@ async fn loads_skills_from_home_agents_dir_for_user_scope() -> anyhow::Result<()
Some(&home_folder_abs),
)
.await;
let outcome = load_skills_from_roots(roots).await;
let outcome = load_skills_from_roots(roots, /*plugin_skill_snapshots*/ None).await;
assert!(
outcome.errors.is_empty(),
"unexpected errors: {:?}",
@@ -845,14 +846,17 @@ interface:
);
let plugin_root_abs = plugin_root.abs();
let outcome = load_skills_from_roots([SkillRoot {
path: plugin_root.join("skills").abs(),
scope: SkillScope::User,
file_system: Arc::clone(&LOCAL_FS),
plugin_id: Some("twilio-developer-kit@test".to_string()),
plugin_namespace: None,
plugin_root: Some(plugin_root_abs.clone()),
}])
let outcome = load_skills_from_roots(
[SkillRoot {
path: plugin_root.join("skills").abs(),
scope: SkillScope::User,
file_system: Arc::clone(&LOCAL_FS),
plugin_id: Some("twilio-developer-kit@test".to_string()),
plugin_namespace: None,
plugin_root: Some(plugin_root_abs.clone()),
}],
/*plugin_skill_snapshots*/ None,
)
.await;
assert!(
@@ -903,14 +907,17 @@ interface:
"##,
);
let outcome = load_skills_from_roots([SkillRoot {
path: plugin_root.join("skills").abs(),
scope: SkillScope::User,
file_system: Arc::clone(&LOCAL_FS),
plugin_id: Some("twilio-developer-kit@test".to_string()),
plugin_namespace: None,
plugin_root: Some(plugin_root.abs()),
}])
let outcome = load_skills_from_roots(
[SkillRoot {
path: plugin_root.join("skills").abs(),
scope: SkillScope::User,
file_system: Arc::clone(&LOCAL_FS),
plugin_id: Some("twilio-developer-kit@test".to_string()),
plugin_namespace: None,
plugin_root: Some(plugin_root.abs()),
}],
/*plugin_skill_snapshots*/ None,
)
.await;
assert!(
@@ -1050,14 +1057,17 @@ async fn loads_skills_via_symlinked_subdir_for_admin_scope() {
fs::create_dir_all(admin_root.path()).unwrap();
symlink_dir(shared.path(), &admin_root.path().join("shared"));
let outcome = load_skills_from_roots([SkillRoot {
path: admin_root.path().abs(),
scope: SkillScope::Admin,
file_system: Arc::clone(&LOCAL_FS),
plugin_id: None,
plugin_namespace: None,
plugin_root: None,
}])
let outcome = load_skills_from_roots(
[SkillRoot {
path: admin_root.path().abs(),
scope: SkillScope::Admin,
file_system: Arc::clone(&LOCAL_FS),
plugin_id: None,
plugin_namespace: None,
plugin_root: None,
}],
/*plugin_skill_snapshots*/ None,
)
.await;
assert!(
@@ -1133,14 +1143,17 @@ async fn system_scope_ignores_symlinked_subdir() {
fs::create_dir_all(&system_root).unwrap();
symlink_dir(shared.path(), &system_root.join("shared"));
let outcome = load_skills_from_roots([SkillRoot {
path: system_root.abs(),
scope: SkillScope::System,
file_system: Arc::clone(&LOCAL_FS),
plugin_id: None,
plugin_namespace: None,
plugin_root: None,
}])
let outcome = load_skills_from_roots(
[SkillRoot {
path: system_root.abs(),
scope: SkillScope::System,
file_system: Arc::clone(&LOCAL_FS),
plugin_id: None,
plugin_namespace: None,
plugin_root: None,
}],
/*plugin_skill_snapshots*/ None,
)
.await;
assert!(
outcome.errors.is_empty(),
@@ -1168,14 +1181,17 @@ async fn respects_max_scan_depth_for_user_scope() {
);
let skills_root = codex_home.path().join("skills");
let outcome = load_skills_from_roots([SkillRoot {
path: skills_root.abs(),
scope: SkillScope::User,
file_system: Arc::clone(&LOCAL_FS),
plugin_id: None,
plugin_namespace: None,
plugin_root: None,
}])
let outcome = load_skills_from_roots(
[SkillRoot {
path: skills_root.abs(),
scope: SkillScope::User,
file_system: Arc::clone(&LOCAL_FS),
plugin_id: None,
plugin_namespace: None,
plugin_root: None,
}],
/*plugin_skill_snapshots*/ None,
)
.await;
assert!(
@@ -1276,14 +1292,17 @@ async fn namespaces_plugin_skills_using_provided_namespace() {
)
.unwrap();
let outcome = load_skills_from_roots([SkillRoot {
path: plugin_root.join("skills").abs(),
scope: SkillScope::User,
file_system: Arc::clone(&LOCAL_FS),
plugin_id: Some("sample@test".to_string()),
plugin_namespace: Some("sample".to_string()),
plugin_root: Some(plugin_root.abs()),
}])
let outcome = load_skills_from_roots(
[SkillRoot {
path: plugin_root.join("skills").abs(),
scope: SkillScope::User,
file_system: Arc::clone(&LOCAL_FS),
plugin_id: Some("sample@test".to_string()),
plugin_namespace: Some("sample".to_string()),
plugin_root: Some(plugin_root.abs()),
}],
/*plugin_skill_snapshots*/ None,
)
.await;
assert!(
@@ -1322,14 +1341,17 @@ async fn plugin_skill_name_length_limit_allows_max_qualified_name() {
)
.unwrap();
let outcome = load_skills_from_roots([SkillRoot {
path: plugin_root.join("skills").abs(),
scope: SkillScope::User,
file_system: Arc::clone(&LOCAL_FS),
plugin_id: Some("sample@test".to_string()),
plugin_namespace: Some(plugin_name.clone()),
plugin_root: Some(plugin_root.abs()),
}])
let outcome = load_skills_from_roots(
[SkillRoot {
path: plugin_root.join("skills").abs(),
scope: SkillScope::User,
file_system: Arc::clone(&LOCAL_FS),
plugin_id: Some("sample@test".to_string()),
plugin_namespace: Some(plugin_name.clone()),
plugin_root: Some(plugin_root.abs()),
}],
/*plugin_skill_snapshots*/ None,
)
.await;
assert!(
@@ -1368,14 +1390,17 @@ async fn plugin_skill_name_length_limit_rejects_overlong_qualified_name() {
)
.unwrap();
let outcome = load_skills_from_roots([SkillRoot {
path: plugin_root.join("skills").abs(),
scope: SkillScope::User,
file_system: Arc::clone(&LOCAL_FS),
plugin_id: Some("sample@test".to_string()),
plugin_namespace: Some(plugin_name.clone()),
plugin_root: Some(plugin_root.abs()),
}])
let outcome = load_skills_from_roots(
[SkillRoot {
path: plugin_root.join("skills").abs(),
scope: SkillScope::User,
file_system: Arc::clone(&LOCAL_FS),
plugin_id: Some("sample@test".to_string()),
plugin_namespace: Some(plugin_name.clone()),
plugin_root: Some(plugin_root.abs()),
}],
/*plugin_skill_snapshots*/ None,
)
.await;
assert_eq!(outcome.skills, Vec::new());
@@ -1807,24 +1832,27 @@ async fn deduplicates_by_path_preferring_first_root() {
let skill_path = write_skill_at(root.path(), "dupe", "dupe-skill", "from repo");
let outcome = load_skills_from_roots([
SkillRoot {
path: root.path().abs(),
scope: SkillScope::Repo,
file_system: Arc::clone(&LOCAL_FS),
plugin_id: None,
plugin_namespace: None,
plugin_root: None,
},
SkillRoot {
path: root.path().abs(),
scope: SkillScope::User,
file_system: Arc::clone(&LOCAL_FS),
plugin_id: None,
plugin_namespace: None,
plugin_root: None,
},
])
let outcome = load_skills_from_roots(
[
SkillRoot {
path: root.path().abs(),
scope: SkillScope::Repo,
file_system: Arc::clone(&LOCAL_FS),
plugin_id: None,
plugin_namespace: None,
plugin_root: None,
},
SkillRoot {
path: root.path().abs(),
scope: SkillScope::User,
file_system: Arc::clone(&LOCAL_FS),
plugin_id: None,
plugin_namespace: None,
plugin_root: None,
},
],
/*plugin_skill_snapshots*/ None,
)
.await;
assert!(
+158
View File
@@ -0,0 +1,158 @@
use std::collections::HashMap;
use std::collections::HashSet;
use std::fmt;
use std::sync::Arc;
use std::sync::Mutex;
use codex_utils_plugins::PluginSkillRoot;
use crate::SkillLoadOutcome;
use crate::loader::SkillRoot;
use crate::loader::SkillRootSnapshot;
use crate::loader::load_skill_root;
use crate::model::SkillFileSystemsByPath;
/// Parsed plugin skill-root snapshots produced by one plugin load.
///
/// Clones share the same snapshots. The plugins manager stores them with the corresponding loaded
/// plugins and passes a clone to skill loading as an optional preload.
#[derive(Clone)]
pub struct PluginSkillSnapshots {
snapshots_by_root: Arc<Mutex<HashMap<PluginSkillRoot, SkillRootSnapshot>>>,
}
impl PluginSkillSnapshots {
/// Creates an empty snapshot collection for a plugin load to populate.
pub fn for_plugin_load() -> Self {
Self {
snapshots_by_root: Arc::new(Mutex::new(HashMap::new())),
}
}
}
impl fmt::Debug for PluginSkillSnapshots {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("PluginSkillSnapshots")
.finish_non_exhaustive()
}
}
pub(crate) async fn load_and_merge_skill_roots<I>(
roots: I,
plugin_skill_snapshots: Option<&PluginSkillSnapshots>,
) -> SkillLoadOutcome
where
I: IntoIterator<Item = SkillRoot>,
{
let mut root_snapshots = Vec::new();
for root in roots {
let cache_key = match (
root.plugin_id.clone(),
root.plugin_namespace.clone(),
root.plugin_root.clone(),
) {
(Some(plugin_id), Some(plugin_namespace), Some(plugin_root)) => Some(PluginSkillRoot {
path: root.path.clone(),
plugin_id,
plugin_namespace,
plugin_root,
}),
_ => None,
};
let cached_snapshot = cache_key.as_ref().and_then(|cache_key| {
let plugin_skill_snapshots = plugin_skill_snapshots?;
plugin_skill_snapshots
.snapshots_by_root
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner)
.get(cache_key)
.cloned()
});
let snapshot = match cached_snapshot {
Some(snapshot) => snapshot,
None => {
let snapshot = load_skill_root(root).await;
if let Some(plugin_skill_snapshots) = plugin_skill_snapshots
&& let Some(cache_key) = cache_key
{
plugin_skill_snapshots
.snapshots_by_root
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner)
.insert(cache_key, snapshot.clone());
}
snapshot
}
};
root_snapshots.push(snapshot);
}
merge_skill_root_snapshots(root_snapshots)
}
fn merge_skill_root_snapshots(snapshots: Vec<SkillRootSnapshot>) -> SkillLoadOutcome {
fn scope_rank(scope: codex_protocol::protocol::SkillScope) -> u8 {
use codex_protocol::protocol::SkillScope;
// Higher-priority scopes first (matches root scan order for dedupe).
match scope {
SkillScope::Repo => 0,
SkillScope::User => 1,
SkillScope::System => 2,
SkillScope::Admin => 3,
}
}
let mut outcome = SkillLoadOutcome::default();
let mut skill_roots = Vec::new();
let mut skill_root_by_path = HashMap::new();
let mut file_systems_by_skill_path = HashMap::new();
for snapshot in snapshots {
let SkillRootSnapshot {
root,
skills,
errors,
file_system,
} = snapshot;
if !skills.is_empty() && !skill_roots.contains(&root) {
skill_roots.push(root.clone());
}
for skill in &skills {
skill_root_by_path
.entry(skill.path_to_skills_md.clone())
.or_insert_with(|| root.clone());
file_systems_by_skill_path
.entry(skill.path_to_skills_md.clone())
.or_insert_with(|| Arc::clone(&file_system));
}
outcome.skills.extend(skills);
outcome.errors.extend(errors);
}
let mut seen = HashSet::new();
outcome
.skills
.retain(|skill| seen.insert(skill.path_to_skills_md.clone()));
let retained_skill_paths = outcome
.skills
.iter()
.map(|skill| skill.path_to_skills_md.clone())
.collect::<HashSet<_>>();
skill_root_by_path.retain(|path, _| retained_skill_paths.contains(path));
let used_roots = skill_root_by_path.values().cloned().collect::<HashSet<_>>();
skill_roots.retain(|root| used_roots.contains(root));
file_systems_by_skill_path.retain(|path, _| retained_skill_paths.contains(path));
outcome.skill_roots = skill_roots;
outcome.skill_root_by_path = Arc::new(skill_root_by_path);
outcome.file_systems_by_skill_path = SkillFileSystemsByPath::new(file_systems_by_skill_path);
outcome.skills.sort_by(|a, b| {
scope_rank(a.scope)
.cmp(&scope_rank(b.scope))
.then_with(|| a.name.cmp(&b.name))
.then_with(|| a.path_to_skills_md.cmp(&b.path_to_skills_md))
});
outcome
}
+20 -6
View File
@@ -14,6 +14,7 @@ use tracing::instrument;
use tracing::warn;
use crate::HostSkillsSnapshot;
use crate::PluginSkillSnapshots;
use crate::SkillLoadOutcome;
use crate::build_implicit_skill_path_indexes;
use crate::config_rules::SkillConfigRules;
@@ -32,6 +33,7 @@ pub struct SkillsLoadInput {
pub effective_skill_roots: Vec<PluginSkillRoot>,
pub config_layer_stack: ConfigLayerStack,
pub bundled_skills_enabled: bool,
plugin_skill_snapshots: Option<PluginSkillSnapshots>,
}
impl SkillsLoadInput {
@@ -46,8 +48,18 @@ impl SkillsLoadInput {
effective_skill_roots,
config_layer_stack,
bundled_skills_enabled,
plugin_skill_snapshots: None,
}
}
/// Attaches plugin skill snapshots parsed during plugin loading, when available.
pub fn with_plugin_skill_snapshots(
mut self,
plugin_skill_snapshots: Option<PluginSkillSnapshots>,
) -> Self {
self.plugin_skill_snapshots = plugin_skill_snapshots;
self
}
}
/// Owns host skill discovery, immutable snapshots, cache invalidation, and extra roots.
@@ -124,7 +136,8 @@ impl SkillsService {
}
let snapshot = HostSkillsSnapshot::new(Arc::new(
self.build_skill_outcome(roots, &skill_config_rules).await,
self.build_skill_outcome(input, roots, &skill_config_rules)
.await,
));
let mut cache = self
.cache_by_config
@@ -180,7 +193,8 @@ impl SkillsService {
}
let skill_config_rules = skill_config_rules_from_stack(&input.config_layer_stack);
let snapshot = HostSkillsSnapshot::new(Arc::new(
self.build_skill_outcome(roots, &skill_config_rules).await,
self.build_skill_outcome(input, roots, &skill_config_rules)
.await,
));
if use_cwd_cache {
let mut cache = self
@@ -195,13 +209,13 @@ impl SkillsService {
#[instrument(level = "trace", skip_all)]
async fn build_skill_outcome(
&self,
input: &SkillsLoadInput,
roots: Vec<SkillRoot>,
skill_config_rules: &SkillConfigRules,
) -> SkillLoadOutcome {
let outcome = crate::filter_skill_load_outcome_for_product(
load_skills_from_roots(roots).await,
self.restriction_product,
);
let outcome = load_skills_from_roots(roots, input.plugin_skill_snapshots.as_ref()).await;
let outcome =
crate::filter_skill_load_outcome_for_product(outcome, self.restriction_product);
let disabled_paths = resolve_disabled_skill_paths(&outcome.skills, skill_config_rules);
finalize_skill_outcome(outcome, disabled_paths)
}
+6 -6
View File
@@ -446,9 +446,6 @@
"browser_use_external": {
"type": "boolean"
},
"child_agents_md": {
"type": "boolean"
},
"chronicle": {
"type": "boolean"
},
@@ -692,6 +689,9 @@
"unified_exec_zsh_fork": {
"type": "boolean"
},
"use_agent_identity": {
"type": "boolean"
},
"use_legacy_landlock": {
"type": "boolean"
},
@@ -4686,9 +4686,6 @@
"browser_use_external": {
"type": "boolean"
},
"child_agents_md": {
"type": "boolean"
},
"chronicle": {
"type": "boolean"
},
@@ -4932,6 +4929,9 @@
"unified_exec_zsh_fork": {
"type": "boolean"
},
"use_agent_identity": {
"type": "boolean"
},
"use_legacy_landlock": {
"type": "boolean"
},
+3 -1
View File
@@ -421,7 +421,9 @@ enabled = false
let plugins_input = config.plugins_config_input();
let plugin_outcome = plugins_manager.plugins_for_config(&plugins_input).await;
let effective_skill_roots = plugin_outcome.effective_plugin_skill_roots();
let skills_input = skills_load_input_from_config(&config, effective_skill_roots);
let plugin_skill_snapshots = plugins_manager.plugin_skill_snapshots_for_config(&plugins_input);
let skills_input = skills_load_input_from_config(&config, effective_skill_roots)
.with_plugin_skill_snapshots(plugin_skill_snapshots);
let snapshot = skills_service
.snapshot_for_config(
&skills_input,
+31 -45
View File
@@ -26,8 +26,6 @@ use codex_config::merge_toml_values;
use codex_config::project_root_markers_from_config;
use codex_exec_server::ExecutorFileSystem;
use codex_extension_api::UserInstructions;
use codex_features::Feature;
use codex_prompts::HIERARCHICAL_AGENTS_MESSAGE;
use codex_utils_absolute_path::AbsolutePathBuf;
use codex_utils_path_uri::PathUri;
use std::io;
@@ -53,16 +51,11 @@ pub(crate) async fn load_project_instructions(
let mut loaded = LoadedAgentsMd::from_user_instructions(user_instructions);
for turn_environment in &environments.turn_environments {
let filesystem = turn_environment.environment.get_filesystem();
// TODO(anp): Migrate AGENTS.md discovery to PathUri so instructions can be loaded from
// environment-native foreign working directories.
let Ok(cwd) = turn_environment.cwd().to_abs_path() else {
continue;
};
match read_agents_md(
config,
filesystem.as_ref(),
&turn_environment.environment_id,
&cwd,
turn_environment.cwd(),
)
.await
{
@@ -77,13 +70,6 @@ pub(crate) async fn load_project_instructions(
}
}
if config.features.enabled(Feature::ChildAgentsMd) {
loaded.entries.push(InstructionEntry {
contents: HIERARCHICAL_AGENTS_MESSAGE.to_string(),
provenance: InstructionProvenance::Internal,
});
}
(!loaded.is_empty()).then_some(loaded)
}
@@ -97,7 +83,7 @@ async fn read_agents_md(
config: &Config,
fs: &dyn ExecutorFileSystem,
environment_id: &str,
cwd: &AbsolutePathBuf,
cwd: &PathUri,
) -> io::Result<Option<LoadedAgentsMd>> {
let max_total = config.project_doc_max_bytes;
@@ -118,15 +104,14 @@ async fn read_agents_md(
break;
}
let path_uri = PathUri::from_abs_path(&p);
match fs.get_metadata(&path_uri, /*sandbox*/ None).await {
match fs.get_metadata(&p, /*sandbox*/ None).await {
Ok(metadata) if !metadata.is_file => continue,
Ok(_) => {}
Err(err) if err.kind() == io::ErrorKind::NotFound => continue,
Err(err) => return Err(err),
}
let mut data = match fs.read_file(&path_uri, /*sandbox*/ None).await {
let mut data = match fs.read_file(&p, /*sandbox*/ None).await {
Ok(data) => data,
Err(err) if err.kind() == io::ErrorKind::NotFound => continue,
Err(err) => return Err(err),
@@ -138,9 +123,9 @@ async fn read_agents_md(
if size > remaining {
tracing::warn!(
"Project doc `{}` exceeds remaining budget ({} bytes) - truncating.",
p.display(),
remaining,
path = %p,
remaining_bytes = remaining,
"project doc exceeds remaining budget; truncating"
);
}
@@ -169,9 +154,9 @@ async fn read_agents_md(
/// directory, inclusive. Symlinks are allowed.
async fn agents_md_paths(
config: &Config,
cwd: &AbsolutePathBuf,
cwd: &PathUri,
fs: &dyn ExecutorFileSystem,
) -> io::Result<Vec<AbsolutePathBuf>> {
) -> io::Result<Vec<PathUri>> {
let dir = cwd.clone();
let mut merged = TomlValue::Table(toml::map::Map::new());
@@ -194,18 +179,18 @@ async fn agents_md_paths(
};
let mut project_root = None;
if !project_root_markers.is_empty() {
for ancestor in dir.ancestors() {
for current in dir.ancestors() {
for marker in &project_root_markers {
let marker_path = ancestor.join(marker);
let marker_path_uri = PathUri::from_abs_path(&marker_path);
let marker_exists = match fs.get_metadata(&marker_path_uri, /*sandbox*/ None).await
{
let marker_path = current
.join(marker)
.map_err(|err| io::Error::new(io::ErrorKind::InvalidInput, err))?;
let marker_exists = match fs.get_metadata(&marker_path, /*sandbox*/ None).await {
Ok(_) => true,
Err(err) if err.kind() == io::ErrorKind::NotFound => false,
Err(err) => return Err(err),
};
if marker_exists {
project_root = Some(ancestor.clone());
project_root = Some(current.clone());
break;
}
}
@@ -215,7 +200,7 @@ async fn agents_md_paths(
}
}
let search_dirs: Vec<AbsolutePathBuf> = if let Some(root) = project_root {
let search_dirs: Vec<PathUri> = if let Some(root) = project_root {
let mut dirs = Vec::new();
let mut cursor = dir.clone();
loop {
@@ -234,13 +219,14 @@ async fn agents_md_paths(
vec![dir]
};
let mut found: Vec<AbsolutePathBuf> = Vec::new();
let mut found: Vec<PathUri> = Vec::new();
let candidate_filenames = candidate_filenames(config);
for d in search_dirs {
for name in &candidate_filenames {
let candidate = d.join(name);
let candidate_uri = PathUri::from_abs_path(&candidate);
match fs.get_metadata(&candidate_uri, /*sandbox*/ None).await {
let candidate = d
.join(name)
.map_err(|err| io::Error::new(io::ErrorKind::InvalidInput, err))?;
match fs.get_metadata(&candidate, /*sandbox*/ None).await {
Ok(md) if md.is_file => {
found.push(candidate);
break;
@@ -371,7 +357,7 @@ impl LoadedAgentsMd {
fn environment_labeled_text(&self) -> String {
let mut output = String::new();
let mut has_previous = false;
let mut previous_environment: Option<(&str, &AbsolutePathBuf)> = None;
let mut previous_environment: Option<(&str, &PathUri)> = None;
if let Some(instructions) = &self.user_instructions {
output.push_str(&instructions.text);
has_previous = true;
@@ -394,7 +380,7 @@ impl LoadedAgentsMd {
output.push_str(&format!(
"for `{}` with root {}\n\n",
environment_id,
cwd.display()
cwd.inferred_native_path_string()
));
}
output.push_str(&entry.contents);
@@ -421,7 +407,7 @@ impl LoadedAgentsMd {
None
} else {
self.single_project_cwd()
.map(|cwd| cwd.to_string_lossy().into_owned())
.map(PathUri::inferred_native_path_string)
};
ContextUserInstructions {
directory,
@@ -436,10 +422,10 @@ impl LoadedAgentsMd {
}
/// Returns the AGENTS.md files that supplied instruction entries.
pub fn sources(&self) -> impl Iterator<Item = &AbsolutePathBuf> {
pub fn sources(&self) -> impl Iterator<Item = PathUri> + '_ {
self.user_instructions
.iter()
.map(|instructions| &instructions.source)
.map(|instructions| PathUri::from_abs_path(&instructions.source))
.chain(
self.entries
.iter()
@@ -463,7 +449,7 @@ impl LoadedAgentsMd {
})
}
fn single_project_cwd(&self) -> Option<&AbsolutePathBuf> {
fn single_project_cwd(&self) -> Option<&PathUri> {
self.entries
.iter()
.find_map(|entry| match &entry.provenance {
@@ -488,9 +474,9 @@ enum InstructionProvenance {
/// Workspace instructions discovered from project AGENTS.md files.
Project {
/// Exact AGENTS.md file, distinct from the environment's selected cwd.
source_path: AbsolutePathBuf,
source_path: PathUri,
environment_id: String,
cwd: AbsolutePathBuf,
cwd: PathUri,
},
/// Instructions without a file source, including internally defined guidance.
@@ -498,9 +484,9 @@ enum InstructionProvenance {
}
impl InstructionProvenance {
fn path(&self) -> Option<&AbsolutePathBuf> {
fn path(&self) -> Option<PathUri> {
match self {
Self::Project { source_path, .. } => Some(source_path),
Self::Project { source_path, .. } => Some(source_path.clone()),
Self::Internal => None,
}
}
+137 -132
View File
@@ -250,8 +250,13 @@ async fn load_agents_md(config: &TestConfig) -> Option<LoadedAgentsMd> {
.await
}
async fn agents_md_paths(config: &TestConfig) -> std::io::Result<Vec<AbsolutePathBuf>> {
super::agents_md_paths(&config.config, &config.cwd, LOCAL_FS.as_ref()).await
async fn agents_md_paths(config: &TestConfig) -> std::io::Result<Vec<PathUri>> {
super::agents_md_paths(
&config.config,
&PathUri::from_abs_path(&config.cwd),
LOCAL_FS.as_ref(),
)
.await
}
fn resolved_local_environments<const N: usize>(
@@ -277,12 +282,101 @@ fn resolved_local_environments<const N: usize>(
fn project_provenance(path: AbsolutePathBuf, cwd: AbsolutePathBuf) -> InstructionProvenance {
InstructionProvenance::Project {
source_path: path,
source_path: PathUri::from_abs_path(&path),
environment_id: "local".to_string(),
cwd,
cwd: PathUri::from_abs_path(&cwd),
}
}
#[test]
fn foreign_agents_md_uses_environment_native_paths() {
let (cwd, rendered_cwd) = if cfg!(windows) {
(
PathUri::parse("file:///codex%20runtime").expect("POSIX cwd URI"),
"/codex runtime",
)
} else {
(
PathUri::parse("file:///C:/codex%20runtime").expect("Windows cwd URI"),
r"C:\codex runtime",
)
};
let source_path = cwd.join("AGENTS.md").expect("AGENTS.md URI");
let loaded = LoadedAgentsMd {
user_instructions: None,
entries: vec![InstructionEntry {
contents: "remote instructions".to_string(),
provenance: InstructionProvenance::Project {
source_path: source_path.clone(),
environment_id: "remote".to_string(),
cwd,
},
}],
};
assert_eq!(
loaded.render(),
format!(
"# AGENTS.md instructions for {rendered_cwd}
<INSTRUCTIONS>
remote instructions
</INSTRUCTIONS>"
)
);
assert_eq!(loaded.sources().collect::<Vec<_>>(), vec![source_path]);
}
#[test]
fn multi_environment_agents_md_renders_mixed_path_conventions() {
let posix_cwd = PathUri::parse("file:///srv/project").expect("POSIX cwd URI");
let windows_cwd = PathUri::parse("file:///C:/workspace").expect("Windows cwd URI");
let posix_source = posix_cwd.join("AGENTS.md").expect("POSIX AGENTS.md URI");
let windows_source = windows_cwd
.join("AGENTS.md")
.expect("Windows AGENTS.md URI");
let loaded = LoadedAgentsMd {
user_instructions: None,
entries: vec![
InstructionEntry {
contents: "POSIX instructions".to_string(),
provenance: InstructionProvenance::Project {
source_path: posix_source.clone(),
environment_id: "posix".to_string(),
cwd: posix_cwd,
},
},
InstructionEntry {
contents: "Windows instructions".to_string(),
provenance: InstructionProvenance::Project {
source_path: windows_source.clone(),
environment_id: "windows".to_string(),
cwd: windows_cwd,
},
},
],
};
assert_eq!(
loaded.render(),
r#"# AGENTS.md instructions
<INSTRUCTIONS>
for `posix` with root /srv/project
POSIX instructions
for `windows` with root C:\workspace
Windows instructions
</INSTRUCTIONS>"#
);
assert_eq!(
loaded.sources().collect::<Vec<_>>(),
vec![posix_source, windows_source]
);
}
/// Helper that returns a `Config` pointing at `root` and using `limit` as
/// the maximum number of bytes to embed from AGENTS.md. The caller can
/// optionally specify a custom `instructions` string – when `None` the
@@ -508,7 +602,7 @@ async fn read_agents_md_propagates_metadata_errors() {
};
let cwd = config.cwd.clone();
let err = read_agents_md(&config.config, &fs, "local", &cwd)
let err = read_agents_md(&config.config, &fs, "local", &PathUri::from_abs_path(&cwd))
.await
.expect_err("metadata error");
@@ -526,7 +620,7 @@ async fn read_agents_md_propagates_read_errors() {
};
let cwd = config.cwd.clone();
let err = read_agents_md(&config.config, &fs, "local", &cwd)
let err = read_agents_md(&config.config, &fs, "local", &PathUri::from_abs_path(&cwd))
.await
.expect_err("read error");
@@ -544,7 +638,7 @@ async fn read_agents_md_ignores_files_removed_after_discovery() {
};
let cwd = config.cwd.clone();
let loaded = read_agents_md(&config.config, &fs, "local", &cwd)
let loaded = read_agents_md(&config.config, &fs, "local", &PathUri::from_abs_path(&cwd))
.await
.expect("removed file is recoverable");
@@ -659,17 +753,18 @@ secondary doc"#,
);
assert_eq!(loaded.render(), expected_fragment);
assert_eq!(
loaded.sources().cloned().collect::<Vec<_>>(),
loaded.sources().collect::<Vec<_>>(),
vec![
config
.user_instructions
.as_ref()
.expect("global instructions")
.source
.clone(),
primary.path().join("AGENTS.md").abs(),
primary_nested.join("AGENTS.md").abs(),
secondary.path().join("AGENTS.md").abs(),
PathUri::from_abs_path(
&config
.user_instructions
.as_ref()
.expect("global instructions")
.source,
),
PathUri::from_abs_path(&primary.path().join("AGENTS.md").abs()),
PathUri::from_abs_path(&primary_nested.join("AGENTS.md").abs()),
PathUri::from_abs_path(&secondary.path().join("AGENTS.md").abs()),
]
);
}
@@ -814,32 +909,6 @@ async fn secondary_environment_invalid_utf8_does_not_suppress_other_docs() {
assert!(loaded.text().contains("secondary\u{FFFD}doc"));
}
#[tokio::test]
async fn child_agents_guidance_is_appended_once_after_environment_groups() {
let primary = tempfile::tempdir().expect("primary tempdir");
let secondary = tempfile::tempdir().expect("secondary tempdir");
fs::write(primary.path().join("AGENTS.md"), "primary doc").unwrap();
fs::write(secondary.path().join("AGENTS.md"), "secondary doc").unwrap();
let mut config = make_config(&primary, /*limit*/ 4096, /*instructions*/ None).await;
config.features.enable(Feature::ChildAgentsMd).unwrap();
let environments = resolved_local_environments([
("primary", config.cwd.clone()),
("secondary", secondary.abs()),
]);
let loaded = load_project_instructions(
&config.config,
/*user_instructions*/ None,
&environments,
)
.await
.expect("instructions expected");
let text = loaded.text();
assert_eq!(text.matches(HIERARCHICAL_AGENTS_MESSAGE).count(), 1);
assert!(text.ends_with(HIERARCHICAL_AGENTS_MESSAGE));
}
/// If there are existing system instructions but AGENTS.md docs are
/// missing we expect the original instructions to be returned unchanged.
#[tokio::test]
@@ -898,7 +967,10 @@ async fn concatenates_root_and_cwd_docs() {
assert_eq!(loaded.text(), "root doc\n\ncrate doc");
assert_eq!(
loaded.sources().collect::<Vec<_>>(),
vec![&root_agents, &crate_agents]
vec![
PathUri::from_abs_path(&root_agents),
PathUri::from_abs_path(&crate_agents),
]
);
}
@@ -925,8 +997,8 @@ async fn project_root_markers_are_honored_for_agents_discovery() {
let expected_parent = root.path().join("AGENTS.md").abs();
let expected_child = cfg.cwd.join("AGENTS.md");
assert_eq!(discovery.len(), 2);
assert_eq!(discovery[0], expected_parent);
assert_eq!(discovery[1], expected_child);
assert_eq!(discovery[0], PathUri::from_abs_path(&expected_parent));
assert_eq!(discovery[1], PathUri::from_abs_path(&expected_child));
let res = get_user_instructions(&cfg).await.expect("doc expected");
assert_eq!(res, "parent doc\n\nchild doc");
@@ -971,8 +1043,8 @@ async fn project_layers_do_not_override_project_root_markers() {
assert_eq!(
discovery,
vec![
root.path().join("AGENTS.md").abs(),
config.cwd.join("AGENTS.md"),
PathUri::from_abs_path(&root.path().join("AGENTS.md").abs()),
PathUri::from_abs_path(&config.cwd.join("AGENTS.md")),
]
);
}
@@ -991,38 +1063,15 @@ async fn agents_md_paths_preserve_symlinked_cwd() {
cfg.cwd = linked_cwd.abs();
let discovery = agents_md_paths(&cfg).await.expect("discover paths");
assert_eq!(discovery, vec![cfg.cwd.join("AGENTS.md")]);
assert_eq!(
discovery,
vec![PathUri::from_abs_path(&cfg.cwd.join("AGENTS.md"))]
);
let res = get_user_instructions(&cfg).await.expect("doc expected");
assert_eq!(res, "project doc");
}
#[tokio::test]
async fn child_agents_message_after_global_instructions_uses_plain_separator() {
let tmp = tempfile::tempdir().expect("tempdir");
let mut cfg = make_config(&tmp, /*limit*/ 4096, Some("global doc")).await;
cfg.features.enable(Feature::ChildAgentsMd).unwrap();
let loaded = load_agents_md(&cfg).await.expect("instructions expected");
let global_agents = cfg.codex_home.join(DEFAULT_AGENTS_MD_FILENAME);
let expected = LoadedAgentsMd {
user_instructions: Some(UserInstructions {
text: "global doc".to_string(),
source: global_agents,
}),
entries: vec![InstructionEntry {
contents: HIERARCHICAL_AGENTS_MESSAGE.to_string(),
provenance: InstructionProvenance::Internal,
}],
};
assert_eq!(loaded, expected);
assert_eq!(
loaded.text(),
format!("global doc\n\n{HIERARCHICAL_AGENTS_MESSAGE}")
);
}
#[tokio::test]
async fn instruction_sources_include_global_before_agents_md_docs() {
let tmp = tempfile::tempdir().expect("tempdir");
@@ -1050,7 +1099,10 @@ async fn instruction_sources_include_global_before_agents_md_docs() {
assert_eq!(loaded.user_instructions(), cfg.user_instructions.as_ref());
assert_eq!(
loaded.sources().collect::<Vec<_>>(),
vec![&global_agents, &project_agents]
vec![
PathUri::from_abs_path(&global_agents),
PathUri::from_abs_path(&project_agents),
]
);
assert_eq!(
loaded.text(),
@@ -1058,47 +1110,6 @@ async fn instruction_sources_include_global_before_agents_md_docs() {
);
}
#[tokio::test]
async fn child_agents_message_after_project_docs_is_not_an_instruction_source() {
let tmp = tempfile::tempdir().expect("tempdir");
fs::write(tmp.path().join("AGENTS.md"), "project doc").unwrap();
let mut cfg = make_config(&tmp, /*limit*/ 4096, Some("global doc")).await;
cfg.features.enable(Feature::ChildAgentsMd).unwrap();
let global_agents = cfg.codex_home.join(DEFAULT_AGENTS_MD_FILENAME);
fs::create_dir_all(&cfg.codex_home).unwrap();
fs::write(&global_agents, "global doc").unwrap();
let loaded = load_agents_md(&cfg).await.expect("instructions expected");
let project_agents = cfg.cwd.join("AGENTS.md");
let expected = LoadedAgentsMd {
user_instructions: Some(UserInstructions {
text: "global doc".to_string(),
source: global_agents.clone(),
}),
entries: vec![
InstructionEntry {
contents: "project doc".to_string(),
provenance: project_provenance(project_agents.clone(), cfg.cwd.clone()),
},
InstructionEntry {
contents: HIERARCHICAL_AGENTS_MESSAGE.to_string(),
provenance: InstructionProvenance::Internal,
},
],
};
assert_eq!(loaded, expected);
assert_eq!(
loaded.sources().collect::<Vec<_>>(),
vec![&global_agents, &project_agents]
);
assert_eq!(
loaded.text(),
format!("global doc{AGENTS_MD_SEPARATOR}project doc\n\n{HIERARCHICAL_AGENTS_MESSAGE}")
);
}
/// AGENTS.override.md is preferred over AGENTS.md when both are present.
#[tokio::test]
async fn agents_local_md_preferred() {
@@ -1117,8 +1128,8 @@ async fn agents_local_md_preferred() {
let discovery = agents_md_paths(&cfg).await.expect("discover paths");
assert_eq!(discovery.len(), 1);
assert_eq!(
discovery[0].file_name().unwrap().to_string_lossy(),
LOCAL_AGENTS_MD_FILENAME
discovery[0].basename().as_deref(),
Some(LOCAL_AGENTS_MD_FILENAME)
);
}
@@ -1166,12 +1177,9 @@ async fn agents_md_preferred_over_fallbacks() {
let discovery = agents_md_paths(&cfg).await.expect("discover paths");
assert_eq!(discovery.len(), 1);
assert!(
discovery[0]
.file_name()
.unwrap()
.to_string_lossy()
.eq(DEFAULT_AGENTS_MD_FILENAME)
assert_eq!(
discovery[0].basename().as_deref(),
Some(DEFAULT_AGENTS_MD_FILENAME)
);
}
@@ -1186,7 +1194,7 @@ async fn agents_md_directory_is_ignored() {
assert_eq!(res, None);
let discovery = agents_md_paths(&cfg).await.expect("discover paths");
assert_eq!(discovery, Vec::<AbsolutePathBuf>::new());
assert_eq!(discovery, Vec::<PathUri>::new());
}
#[cfg(unix)]
@@ -1209,7 +1217,7 @@ async fn agents_md_special_file_is_ignored() {
assert_eq!(res, None);
let discovery = agents_md_paths(&cfg).await.expect("discover paths");
assert_eq!(discovery, Vec::<AbsolutePathBuf>::new());
assert_eq!(discovery, Vec::<PathUri>::new());
}
#[tokio::test]
@@ -1228,11 +1236,8 @@ async fn override_directory_falls_back_to_agents_md_file() {
let discovery = agents_md_paths(&cfg).await.expect("discover paths");
assert_eq!(discovery.len(), 1);
assert_eq!(
discovery[0]
.file_name()
.expect("file name")
.to_string_lossy(),
DEFAULT_AGENTS_MD_FILENAME
discovery[0].basename().as_deref(),
Some(DEFAULT_AGENTS_MD_FILENAME)
);
}
+11 -1
View File
@@ -42,6 +42,7 @@ use codex_thread_store::ThreadMetadataPatch;
use codex_thread_store::ThreadStoreError;
use codex_thread_store::ThreadStoreResult;
use codex_utils_absolute_path::AbsolutePathBuf;
use codex_utils_path_uri::LegacyAppPathString;
use codex_utils_path_uri::PathUri;
use rmcp::model::ReadResourceRequestParams;
use std::collections::BTreeMap;
@@ -564,10 +565,19 @@ impl CodexThread {
}
/// Returns the files that supplied the thread's loaded model instructions.
pub async fn instruction_sources(&self) -> Vec<AbsolutePathBuf> {
pub async fn instruction_sources(&self) -> Vec<PathUri> {
self.codex.instruction_sources().await
}
/// Returns loaded instruction sources rendered as legacy app-server path strings.
pub async fn legacy_instruction_sources(&self) -> Vec<LegacyAppPathString> {
self.instruction_sources()
.await
.into_iter()
.map(Into::into)
.collect()
}
pub async fn config(&self) -> Arc<crate::config::Config> {
self.codex.session.get_config().await
}
+24 -3
View File
@@ -32,6 +32,7 @@ use codex_features::Feature;
use codex_login::AuthManager;
use codex_login::CodexAuth;
use codex_mcp::CODEX_APPS_MCP_SERVER_NAME;
use codex_mcp::MCP_TOOL_CODEX_APPS_META_KEY;
use codex_mcp::McpConnectionManager;
use codex_mcp::McpRuntimeContext;
use codex_mcp::ToolInfo;
@@ -154,7 +155,7 @@ pub(crate) fn refresh_accessible_connectors_cache_from_mcp_tools(
}
let cache_key = accessible_connectors_cache_key(config, auth);
let accessible_connectors = accessible_connectors_from_mcp_tools(mcp_tools);
let accessible_connectors = accessible_connectors_for_app_list_from_mcp_tools(mcp_tools);
write_cached_accessible_connectors(cache_key, &accessible_connectors);
}
@@ -339,7 +340,7 @@ pub async fn list_accessible_connectors_from_mcp_tools_with_mcp_manager(
cancel_token.cancel();
}
let accessible_connectors = accessible_connectors_from_mcp_tools(&tools);
let accessible_connectors = accessible_connectors_for_app_list_from_mcp_tools(&tools);
if codex_apps_ready || !accessible_connectors.is_empty() {
write_cached_accessible_connectors(cache_key, &accessible_connectors);
}
@@ -469,9 +470,15 @@ async fn cached_directory_connectors_for_tool_suggest_with_auth(
}
pub(crate) fn accessible_connectors_from_mcp_tools(mcp_tools: &[ToolInfo]) -> Vec<AppInfo> {
collect_accessible_connectors_from_mcp_tools(mcp_tools.iter())
}
fn collect_accessible_connectors_from_mcp_tools<'a>(
mcp_tools: impl Iterator<Item = &'a ToolInfo>,
) -> Vec<AppInfo> {
// ToolInfo already carries plugin provenance, so app-level plugin sources
// can be derived here instead of requiring a separate enrichment pass.
let tools = mcp_tools.iter().filter_map(|tool| {
let tools = mcp_tools.filter_map(|tool| {
if tool.server_name != CODEX_APPS_MCP_SERVER_NAME {
return None;
}
@@ -486,6 +493,20 @@ pub(crate) fn accessible_connectors_from_mcp_tools(mcp_tools: &[ToolInfo]) -> Ve
codex_connectors::accessible::collect_accessible_connectors(tools)
}
fn accessible_connectors_for_app_list_from_mcp_tools(mcp_tools: &[ToolInfo]) -> Vec<AppInfo> {
let non_synthetic_tools = mcp_tools.iter().filter(|tool| {
tool.tool
.meta
.as_deref()
.and_then(|meta| meta.get(MCP_TOOL_CODEX_APPS_META_KEY))
.and_then(serde_json::Value::as_object)
.and_then(|meta| meta.get("synthetic_link"))
.and_then(serde_json::Value::as_bool)
!= Some(true)
});
collect_accessible_connectors_from_mcp_tools(non_synthetic_tools)
}
pub fn with_app_enabled_state(mut connectors: Vec<AppInfo>, config: &Config) -> Vec<AppInfo> {
let user_apps_config = apps_config_from_layer_stack(&config.config_layer_stack);
let requirements_apps_config = config.config_layer_stack.requirements_toml().apps.as_ref();
+64
View File
@@ -17,6 +17,7 @@ use codex_mcp::CODEX_APPS_MCP_SERVER_NAME;
use codex_mcp::ToolInfo;
use pretty_assertions::assert_eq;
use rmcp::model::JsonObject;
use rmcp::model::Meta;
use rmcp::model::Tool;
use std::collections::BTreeMap;
use std::collections::HashSet;
@@ -140,6 +141,69 @@ fn accessible_connectors_from_mcp_tools_carries_plugin_display_names() {
);
}
#[test]
fn synthetic_links_are_exposed_to_the_agent_but_not_accessible_in_app_list() {
let mut synthetic_tool = codex_app_tool("gmail_batch_read_email", "gmail", Some("Gmail"), &[]);
synthetic_tool.tool.meta = Some(Meta(
serde_json::json!({
"resource_name": "gmail.batch_read_email",
"_codex_apps": {
"resource_uri": "/connector/gmail/batch_read_email",
"contains_mcp_source": false,
"synthetic_link": true
}
})
.as_object()
.expect("meta should be an object")
.clone(),
));
let tools = vec![
synthetic_tool,
codex_app_tool("calendar_list_events", "calendar", Some("Calendar"), &[]),
];
let calendar = AppInfo {
id: "calendar".to_string(),
name: "Calendar".to_string(),
description: None,
logo_url: None,
logo_url_dark: None,
distribution_channel: None,
install_url: Some(connector_install_url("Calendar", "calendar")),
branding: None,
app_metadata: None,
labels: None,
is_accessible: true,
is_enabled: true,
plugin_display_names: Vec::new(),
};
assert_eq!(
accessible_connectors_for_app_list_from_mcp_tools(&tools),
vec![calendar.clone()]
);
assert_eq!(
accessible_connectors_from_mcp_tools(&tools),
vec![
calendar,
AppInfo {
id: "gmail".to_string(),
name: "Gmail".to_string(),
description: None,
logo_url: None,
logo_url_dark: None,
distribution_channel: None,
install_url: Some(connector_install_url("Gmail", "gmail")),
branding: None,
app_metadata: None,
labels: None,
is_accessible: true,
is_enabled: true,
plugin_display_names: Vec::new(),
}
]
);
}
#[tokio::test]
async fn refresh_accessible_connectors_cache_from_mcp_tools_writes_latest_installed_apps() {
let codex_home = tempdir().expect("tempdir should succeed");
+35 -9
View File
@@ -143,14 +143,7 @@ pub(crate) async fn handle_mcp_tool_call(
let metadata =
lookup_mcp_tool_metadata(sess.as_ref(), turn_context.as_ref(), &server, &tool_name).await;
let item_metadata = McpToolCallItemMetadata {
mcp_app_resource_uri: metadata
.as_ref()
.and_then(|metadata| metadata.mcp_app_resource_uri.clone()),
plugin_id: metadata
.as_ref()
.and_then(|metadata| metadata.plugin_id.clone()),
};
let item_metadata = McpToolCallItemMetadata::from_tool_metadata(&server, metadata.as_ref());
let app_tool_policy = if server == CODEX_APPS_MCP_SERVER_NAME {
let annotations = metadata
.as_ref()
@@ -312,12 +305,32 @@ pub(crate) struct HandledMcpToolCall {
pub(crate) tool_input: JsonValue,
}
#[derive(Clone)]
#[derive(Clone, Debug, PartialEq, Eq)]
struct McpToolCallItemMetadata {
connector_id: Option<String>,
link_id: Option<String>,
mcp_app_resource_uri: Option<String>,
plugin_id: Option<String>,
}
impl McpToolCallItemMetadata {
fn from_tool_metadata(server: &str, metadata: Option<&McpToolApprovalMetadata>) -> Self {
let trusted_mcp_app_metadata = if server == CODEX_APPS_MCP_SERVER_NAME {
metadata
} else {
None
};
Self {
connector_id: trusted_mcp_app_metadata
.and_then(|metadata| metadata.connector_id.clone()),
link_id: trusted_mcp_app_metadata.and_then(|metadata| metadata.link_id.clone()),
mcp_app_resource_uri: metadata
.and_then(|metadata| metadata.mcp_app_resource_uri.clone()),
plugin_id: metadata.and_then(|metadata| metadata.plugin_id.clone()),
}
}
}
async fn handle_approved_mcp_tool_call(
sess: &Session,
turn_context: &TurnContext,
@@ -892,7 +905,9 @@ async fn notify_mcp_tool_call_started(
server,
tool,
arguments: arguments.unwrap_or(JsonValue::Null),
connector_id: item_metadata.connector_id,
mcp_app_resource_uri: item_metadata.mcp_app_resource_uri,
link_id: item_metadata.link_id,
plugin_id: item_metadata.plugin_id,
status: McpToolCallStatus::InProgress,
result: None,
@@ -932,7 +947,9 @@ async fn notify_mcp_tool_call_completed(
server,
tool,
arguments: arguments.unwrap_or(JsonValue::Null),
connector_id: item_metadata.connector_id,
mcp_app_resource_uri: item_metadata.mcp_app_resource_uri,
link_id: item_metadata.link_id,
plugin_id: item_metadata.plugin_id,
status,
result,
@@ -998,6 +1015,7 @@ enum McpToolApprovalDecision {
pub(crate) struct McpToolApprovalMetadata {
annotations: Option<ToolAnnotations>,
connector_id: Option<String>,
link_id: Option<String>,
connector_name: Option<String>,
connector_description: Option<String>,
plugin_id: Option<String>,
@@ -1010,6 +1028,7 @@ pub(crate) struct McpToolApprovalMetadata {
const MCP_TOOL_OPENAI_OUTPUT_TEMPLATE_META_KEY: &str = "openai/outputTemplate";
const MCP_TOOL_UI_RESOURCE_URI_META_KEY: &str = "ui/resourceUri";
const MCP_TOOL_LINK_ID_META_KEY: &str = "link_id";
const MCP_TOOL_PLUGIN_ID_META_KEY: &str = "plugin_id";
const MCP_TOOL_THREAD_ID_META_KEY: &str = "threadId";
@@ -1493,6 +1512,13 @@ pub(crate) async fn lookup_mcp_tool_metadata(
Some(McpToolApprovalMetadata {
annotations: tool_info.tool.annotations,
connector_id: tool_info.connector_id,
link_id: tool_info
.tool
.meta
.as_ref()
.and_then(|meta| meta.get(MCP_TOOL_LINK_ID_META_KEY))
.and_then(serde_json::Value::as_str)
.map(str::to_string),
connector_name: tool_info.connector_name,
connector_description,
plugin_id,
+54 -2
View File
@@ -78,6 +78,7 @@ fn approval_metadata(
McpToolApprovalMetadata {
annotations: None,
connector_id: connector_id.map(str::to_string),
link_id: None,
connector_name: connector_name.map(str::to_string),
connector_description: connector_description.map(str::to_string),
plugin_id: None,
@@ -1149,8 +1150,39 @@ async fn plugin_mcp_tool_call_request_meta_includes_plugin_id() {
);
}
#[test]
fn mcp_tool_call_item_metadata_only_trusts_codex_apps_identity() {
let mut metadata = approval_metadata(
Some("asdk_app_0123456789abcdef0123456789abcdef"),
/*connector_name*/ None,
/*connector_description*/ None,
/*tool_title*/ None,
/*tool_description*/ None,
);
metadata.link_id = Some("link_fedcba9876543210fedcba9876543210".to_string());
assert_eq!(
McpToolCallItemMetadata::from_tool_metadata(CODEX_APPS_MCP_SERVER_NAME, Some(&metadata),),
McpToolCallItemMetadata {
connector_id: Some("asdk_app_0123456789abcdef0123456789abcdef".to_string()),
link_id: Some("link_fedcba9876543210fedcba9876543210".to_string()),
mcp_app_resource_uri: None,
plugin_id: None,
}
);
assert_eq!(
McpToolCallItemMetadata::from_tool_metadata("custom_server", Some(&metadata)),
McpToolCallItemMetadata {
connector_id: None,
link_id: None,
mcp_app_resource_uri: None,
plugin_id: None,
}
);
}
#[tokio::test]
async fn mcp_tool_call_item_includes_plugin_id() {
async fn mcp_tool_call_item_includes_app_identity() {
let (session, turn_context, rx_event) = make_session_and_context_with_rx().await;
notify_mcp_tool_call_started(
@@ -1158,11 +1190,13 @@ async fn mcp_tool_call_item_includes_plugin_id() {
&turn_context,
"call-plugin",
McpInvocation {
server: "sample".to_string(),
server: CODEX_APPS_MCP_SERVER_NAME.to_string(),
tool: "echo".to_string(),
arguments: None,
},
McpToolCallItemMetadata {
connector_id: Some("asdk_app_0123456789abcdef0123456789abcdef".to_string()),
link_id: Some("link_fedcba9876543210fedcba9876543210".to_string()),
mcp_app_resource_uri: None,
plugin_id: Some("sample@test".to_string()),
},
@@ -1180,6 +1214,14 @@ async fn mcp_tool_call_item_includes_plugin_id() {
panic!("expected MCP tool call item");
};
assert_eq!(
item.connector_id.as_deref(),
Some("asdk_app_0123456789abcdef0123456789abcdef")
);
assert_eq!(
item.link_id.as_deref(),
Some("link_fedcba9876543210fedcba9876543210")
);
assert_eq!(item.plugin_id.as_deref(), Some("sample@test"));
}
@@ -1193,6 +1235,7 @@ async fn codex_apps_tool_call_request_meta_includes_turn_metadata_and_codex_apps
let metadata = McpToolApprovalMetadata {
annotations: None,
connector_id: Some("calendar".to_string()),
link_id: None,
connector_name: Some("Calendar".to_string()),
connector_description: Some("Manage events".to_string()),
plugin_id: None,
@@ -1661,6 +1704,7 @@ fn guardian_mcp_review_request_includes_annotations_when_present() {
let metadata = McpToolApprovalMetadata {
annotations: Some(annotations(Some(false), Some(true), Some(true))),
connector_id: None,
link_id: None,
connector_name: None,
connector_description: None,
plugin_id: None,
@@ -2326,6 +2370,7 @@ async fn approve_mode_skips_when_annotations_do_not_require_approval() {
/*open_world*/ None,
)),
connector_id: None,
link_id: None,
connector_name: None,
connector_description: None,
plugin_id: None,
@@ -2400,6 +2445,7 @@ async fn guardian_mode_skips_auto_when_annotations_do_not_require_approval() {
/*open_world*/ None,
)),
connector_id: None,
link_id: None,
connector_name: None,
connector_description: None,
plugin_id: None,
@@ -2457,6 +2503,7 @@ async fn permission_request_hook_allows_mcp_tool_call() {
/*open_world*/ None,
)),
connector_id: None,
link_id: None,
connector_name: None,
connector_description: None,
plugin_id: None,
@@ -2593,6 +2640,7 @@ async fn permission_request_hook_runs_after_remembered_mcp_approval() {
/*open_world*/ None,
)),
connector_id: None,
link_id: None,
connector_name: None,
connector_description: None,
plugin_id: None,
@@ -2680,6 +2728,7 @@ async fn guardian_mode_mcp_denial_returns_rationale_message() {
let metadata = McpToolApprovalMetadata {
annotations: Some(annotations(Some(false), Some(true), Some(true))),
connector_id: None,
link_id: None,
connector_name: None,
connector_description: None,
plugin_id: None,
@@ -2734,6 +2783,7 @@ async fn prompt_mode_waits_for_approval_when_annotations_do_not_require_approval
/*open_world*/ None,
)),
connector_id: None,
link_id: None,
connector_name: None,
connector_description: None,
plugin_id: None,
@@ -2789,6 +2839,7 @@ async fn full_access_mode_skips_mcp_tool_approval_for_all_approval_modes() {
let metadata = McpToolApprovalMetadata {
annotations: Some(annotations(Some(false), Some(true), Some(true))),
connector_id: Some("calendar".to_string()),
link_id: None,
connector_name: Some("Calendar".to_string()),
connector_description: Some("Manage events".to_string()),
plugin_id: None,
@@ -2842,6 +2893,7 @@ async fn approve_mode_skips_guardian_in_every_permission_mode() {
let metadata = McpToolApprovalMetadata {
annotations: Some(annotations(Some(false), Some(true), Some(true))),
connector_id: Some("calendar".to_string()),
link_id: None,
connector_name: Some("Calendar".to_string()),
connector_description: Some("Manage events".to_string()),
plugin_id: None,
+2 -4
View File
@@ -830,15 +830,13 @@ impl Codex {
state.session_configuration.thread_config_snapshot()
}
pub(crate) async fn instruction_sources(&self) -> Vec<AbsolutePathBuf> {
pub(crate) async fn instruction_sources(&self) -> Vec<PathUri> {
let state = self.session.state.lock().await;
state
.session_configuration
.loaded_agents_md
.as_ref()
.map_or_else(Vec::new, |instructions| {
instructions.sources().cloned().collect()
})
.map_or_else(Vec::new, |instructions| instructions.sources().collect())
}
pub(crate) async fn thread_environment_selections(&self) -> Vec<TurnEnvironmentSelection> {
+3 -1
View File
@@ -445,7 +445,9 @@ async fn warm_plugins_and_skills_for_session_init(
let plugins_input = config.plugins_config_input();
let plugin_outcome = plugins_manager.plugins_for_config(&plugins_input).await;
let effective_skill_roots = plugin_outcome.effective_plugin_skill_roots();
let skills_input = skills_load_input_from_config(config.as_ref(), effective_skill_roots);
let plugin_skill_snapshots = plugins_manager.plugin_skill_snapshots_for_config(&plugins_input);
let skills_input = skills_load_input_from_config(config.as_ref(), effective_skill_roots)
.with_plugin_skill_snapshots(plugin_skill_snapshots);
skills_service
.snapshot_for_config(&skills_input, fs)
.await
+14 -4
View File
@@ -5050,13 +5050,18 @@ pub(crate) async fn make_session_and_context() -> (Session, TurnContext) {
turn_environments: Arc::clone(&turn_environments),
};
let plugins_input = per_turn_config.plugins_config_input();
let plugin_outcome = services
.plugins_manager
.plugins_for_config(&per_turn_config.plugins_config_input())
.plugins_for_config(&plugins_input)
.await;
let effective_skill_roots = plugin_outcome.effective_plugin_skill_roots();
let plugin_skill_snapshots = services
.plugins_manager
.plugin_skill_snapshots_for_config(&plugins_input);
let skills_input =
crate::skills_load_input_from_config(&per_turn_config, effective_skill_roots);
crate::skills_load_input_from_config(&per_turn_config, effective_skill_roots)
.with_plugin_skill_snapshots(plugin_skill_snapshots);
let skill_fs = environment.get_filesystem();
let skills_snapshot = services
.skills_service
@@ -7099,13 +7104,18 @@ where
turn_environments: Arc::clone(&turn_environments),
};
let plugins_input = per_turn_config.plugins_config_input();
let plugin_outcome = services
.plugins_manager
.plugins_for_config(&per_turn_config.plugins_config_input())
.plugins_for_config(&plugins_input)
.await;
let effective_skill_roots = plugin_outcome.effective_plugin_skill_roots();
let plugin_skill_snapshots = services
.plugins_manager
.plugin_skill_snapshots_for_config(&plugins_input);
let skills_input =
crate::skills_load_input_from_config(&per_turn_config, effective_skill_roots);
crate::skills_load_input_from_config(&per_turn_config, effective_skill_roots)
.with_plugin_skill_snapshots(plugin_skill_snapshots);
let skill_fs = environment.get_filesystem();
let skills_snapshot = services
.skills_service
+8 -2
View File
@@ -722,13 +722,19 @@ impl Session {
.or(model_info.multi_agent_version)
.unwrap_or_else(|| per_turn_config.multi_agent_version_from_features()),
};
let plugins_input = per_turn_config.plugins_config_input();
let plugin_outcome = self
.services
.plugins_manager
.plugins_for_config(&per_turn_config.plugins_config_input())
.plugins_for_config(&plugins_input)
.await;
let effective_skill_roots = plugin_outcome.effective_plugin_skill_roots();
let skills_input = skills_load_input_from_config(&per_turn_config, effective_skill_roots);
let plugin_skill_snapshots = self
.services
.plugins_manager
.plugin_skill_snapshots_for_config(&plugins_input);
let skills_input = skills_load_input_from_config(&per_turn_config, effective_skill_roots)
.with_plugin_skill_snapshots(plugin_skill_snapshots);
let fs = primary_turn_environment
.map(|turn_environment| turn_environment.environment.get_filesystem());
let skills_snapshot = self
@@ -203,7 +203,9 @@ async fn emit_tool_call_begin(
server,
tool,
arguments: arguments.unwrap_or(Value::Null),
connector_id: None,
mcp_app_resource_uri: None,
link_id: None,
plugin_id: None,
status: McpToolCallStatus::InProgress,
result: None,
@@ -242,7 +244,9 @@ async fn emit_tool_call_end(
server,
tool,
arguments: arguments.unwrap_or(Value::Null),
connector_id: None,
mcp_app_resource_uri: None,
link_id: None,
plugin_id: None,
status,
result,
@@ -1,3 +1,4 @@
use std::path::Path;
use std::sync::Arc;
use crate::function_tool::FunctionCallError;
@@ -31,6 +32,7 @@ use codex_otel::TOOL_CALL_UNIFIED_EXEC_METRIC;
use codex_sandboxing::SandboxManager;
use codex_sandboxing::SandboxType;
use codex_sandboxing::SandboxablePreference;
use codex_shell_command::shell_detect::detect_shell_type;
use codex_tools::ToolName;
use codex_tools::ToolSpec;
use codex_utils_output_truncation::approx_token_count;
@@ -172,7 +174,7 @@ impl ExecCommandHandler {
)));
}
};
let args: ExecCommandArgs = match native_cwd.as_ref() {
let mut args: ExecCommandArgs = match native_cwd.as_ref() {
Some(native_cwd) => {
// The base path only resolves paths nested in the permissions config types.
parse_arguments_with_base_path(&arguments, native_cwd)?
@@ -195,7 +197,6 @@ impl ExecCommandHandler {
)
.await;
}
let process_id = manager.allocate_process_id().await;
let shell_mode =
shell_mode_for_environment(&turn.unified_exec_shell_mode, environment.as_ref());
// Remote environments may use a different OS and must build commands with their native
@@ -205,6 +206,26 @@ impl ExecCommandHandler {
.clone()
.map(Arc::new)
.unwrap_or_else(|| session.user_shell());
// TODO(anp): Resolve requested shells in remote environments instead of restricting
// commands to the reported default shell.
if environment.is_remote()
&& let Some(requested_shell) = args.shell.take()
{
let Some(remote_shell) = turn_environment.shell.as_ref() else {
return Err(FunctionCallError::RespondToModel(format!(
"environment `{}` does not report a shell",
turn_environment.environment_id
)));
};
if detect_shell_type(Path::new(&requested_shell)) != Some(remote_shell.shell_type) {
return Err(FunctionCallError::RespondToModel(format!(
"environment `{}` only supports `{}`",
turn_environment.environment_id,
remote_shell.name()
)));
}
}
let process_id = manager.allocate_process_id().await;
let resolved_command = get_command(
&args,
shell,
@@ -17,6 +17,7 @@ use wiremock::matchers::path;
use wiremock::matchers::path_regex;
const CONNECTOR_ID: &str = "calendar";
pub const LINK_ID: &str = "link_calendar";
const CONNECTOR_NAME: &str = "Calendar";
const DISCOVERABLE_CALENDAR_ID: &str = "connector_2128aebfecb84f64a069897515042a44";
const DISCOVERABLE_GMAIL_ID: &str = "connector_68df038e0ba48191908c8434991bbac2";
@@ -352,6 +353,7 @@ impl Respond for CodexAppsJsonRpcResponder {
},
"_meta": {
"connector_id": CONNECTOR_ID,
"link_id": LINK_ID,
"connector_name": self.connector_name.clone(),
"connector_description": self.connector_description.clone(),
"openai/outputTemplate": CALENDAR_CREATE_EVENT_MCP_APP_RESOURCE_URI,
@@ -378,6 +380,7 @@ impl Respond for CodexAppsJsonRpcResponder {
},
"_meta": {
"connector_id": CONNECTOR_ID,
"link_id": LINK_ID,
"connector_name": self.connector_name.clone(),
"connector_description": self.connector_description.clone(),
"_codex_apps": {
@@ -410,6 +413,7 @@ impl Respond for CodexAppsJsonRpcResponder {
},
"_meta": {
"connector_id": CONNECTOR_ID,
"link_id": LINK_ID,
"connector_name": self.connector_name.clone(),
"connector_description": self.connector_description.clone(),
"openai/fileParams": ["file"],
+15 -1
View File
@@ -58,6 +58,7 @@ use tempfile::TempDir;
use wiremock::MockServer;
use crate::TempDirExt;
use crate::TestEnvironment;
use crate::get_remote_test_env;
use crate::load_default_config_for_test;
use crate::load_default_config_for_test_with_cloud_config_bundle;
@@ -179,7 +180,20 @@ pub async fn test_env() -> Result<TestEnv> {
/*sandbox*/ None,
)
.await?;
let cwd = cwd_uri.to_abs_path()?;
let cwd = if remote_env == TestEnvironment::WineExec {
// TODO(anp): Convert `Config::cwd` to `LegacyAppPathString` and remove this
// compatibility projection.
// `Config::cwd` still requires `AbsolutePathBuf`. Preserve the test harness's
// Linux-absolute `/C:/...` compatibility spelling so converting it back to a
// `PathUri` recovers the remote Windows convention. Production conversions stay
// strict: `PathUri::to_abs_path` intentionally rejects foreign paths.
let path = cwd_uri.to_url().to_file_path().map_err(|()| {
anyhow!("remote test cwd URI cannot be projected onto the host: {cwd_uri}")
})?;
AbsolutePathBuf::try_from(path)?
} else {
cwd_uri.to_abs_path()?
};
Ok(TestEnv {
environment,
exec_server_url: Some(websocket_url),
@@ -22,7 +22,6 @@ wine_rust_test(
"//codex-rs/protocol",
"//codex-rs/utils/path-uri",
"@crates//:anyhow",
"@crates//:base64",
"@crates//:pretty_assertions",
"@crates//:serde_json",
"@crates//:tempfile",
@@ -36,11 +36,13 @@ use core_test_support::test_codex::test_codex;
use core_test_support::test_codex::turn_permission_fields;
use core_test_support::wait_for_event;
use codex_utils_path_uri::LegacyAppPathString;
use codex_utils_path_uri::PathConvention;
use codex_utils_path_uri::PathUri;
use pretty_assertions::assert_eq;
use serde_json::Value;
use serde_json::json;
use std::collections::BTreeMap;
use std::fs;
use tempfile::TempDir;
use tokio::time::timeout;
use wine_exec_server_test_support::WineExecServer;
@@ -57,7 +59,7 @@ async fn windows_exec_server_runs_with_native_shell_and_cwd() -> Result<()> {
const VERIFY_COMMAND: &str = r#"$path = Join-Path (Get-Location) 'codex-apply-patch-smoke.txt'; if (-not (Test-Path $path)) { exit 1 }; if ([IO.File]::ReadAllText($path) -ne "patched through unified exec`n") { exit 2 }; Remove-Item $path; Write-Output 'PATCH_VERIFIED'"#;
WineExecServer
.scope(|exec_server_url| async move {
.scope(|exec_server_url, _wine_prefix| async move {
let server = start_mock_server().await;
let arguments = serde_json::to_string(&json!({
"cmd": COMMAND,
@@ -245,8 +247,17 @@ async fn windows_exec_server_runs_with_native_shell_and_cwd() -> Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn app_server_starts_thread_with_windows_environment_native_cwd() -> Result<()> {
const AGENTS_INSTRUCTIONS: &str = "remote Windows workspace instructions";
const NATIVE_CWD: &str = r"C:\windows";
WineExecServer
.scope(|exec_server_url| async move {
.scope(|exec_server_url, wine_prefix| async move {
let agents_path = PathUri::parse("file:///C:/windows/AGENTS.md")?;
fs::write(
wine_prefix.join("drive_c").join("windows").join("AGENTS.md"),
AGENTS_INSTRUCTIONS,
)?;
let codex_home = TempDir::new()?;
let server = create_mock_responses_server_repeating_assistant("done").await;
write_mock_responses_config_toml(
@@ -272,7 +283,7 @@ async fn app_server_starts_thread_with_windows_environment_native_cwd() -> Resul
.send_thread_start_request(ThreadStartParams {
environments: Some(vec![TurnEnvironmentParams {
environment_id: REMOTE_ENVIRONMENT_ID.to_string(),
cwd: serde_json::from_value::<LegacyAppPathString>(json!(r"C:\windows"))?,
cwd: serde_json::from_value::<LegacyAppPathString>(json!(NATIVE_CWD))?,
}]),
..Default::default()
})
@@ -289,8 +300,13 @@ async fn app_server_starts_thread_with_windows_environment_native_cwd() -> Resul
assert_eq!(response.cwd, host_cwd);
// TODO(anp): Derive runtime workspace roots from the selected remote environment.
assert_eq!(response.runtime_workspace_roots, vec![host_cwd]);
// TODO(anp): Discover and report instruction sources from the remote filesystem.
assert_eq!(response.instruction_sources, Vec::new());
assert_eq!(
response.instruction_sources,
vec![LegacyAppPathString::from_path_uri(
&agents_path,
PathConvention::Windows,
)?]
);
// TODO(anp): Report the implicit built-in permission profile instead of None.
assert_eq!(response.active_permission_profile, None);
@@ -326,6 +342,17 @@ async fn app_server_starts_thread_with_windows_environment_native_cwd() -> Resul
.find(|request| request.url.path().ends_with("/responses"))
.context("turn should send a Responses request")?;
let body = first_request.body_json::<Value>()?;
let remote_instructions = body["input"]
.as_array()
.into_iter()
.flatten()
.filter(|item| item.get("role").and_then(Value::as_str) == Some("user"))
.filter_map(|item| item.get("content").and_then(Value::as_array))
.flatten()
.filter_map(|content| content.get("text").and_then(Value::as_str))
.find(|text| text.contains(AGENTS_INSTRUCTIONS))
.context("remote workspace instructions should be model visible")?;
assert!(remote_instructions.contains(r"# AGENTS.md instructions for C:\windows"));
let environment_context = body["input"]
.as_array()
.into_iter()
+32 -30
View File
@@ -25,7 +25,6 @@ use core_test_support::responses::mount_sse_once;
use core_test_support::responses::sse;
use core_test_support::responses::start_mock_server;
use core_test_support::skip_if_no_network;
use core_test_support::skip_if_wine_exec;
use core_test_support::test_codex::RecordingUserInstructionsProvider;
use core_test_support::test_codex::TestCodexBuilder;
use core_test_support::test_codex::test_codex;
@@ -88,7 +87,7 @@ fn instruction_fragments(request: &responses::ResponsesRequest) -> Vec<String> {
}
fn expected_instruction_fragment(cwd: &AbsolutePathBuf, contents: &str) -> String {
let cwd = cwd.as_path().display();
let cwd = PathUri::from_abs_path(cwd).inferred_native_path_string();
format!("# AGENTS.md instructions for {cwd}\n\n<INSTRUCTIONS>\n{contents}\n</INSTRUCTIONS>")
}
@@ -138,8 +137,6 @@ fn request_body_contains(request: &wiremock::Request, text: &str) -> bool {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn agents_override_is_preferred_over_agents_md() -> Result<()> {
// TODO(anp): Remove after instruction-source helpers use target-native paths.
skip_if_wine_exec!(Ok(()), "requires native cross-OS instruction-source paths");
let instructions =
agents_instructions(test_codex().with_workspace_setup(|cwd, fs| async move {
let agents_md = cwd.join("AGENTS.md");
@@ -172,8 +169,6 @@ async fn agents_override_is_preferred_over_agents_md() -> Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn configured_fallback_is_used_when_agents_candidate_is_directory() -> Result<()> {
// TODO(anp): Remove after instruction-source helpers use target-native paths.
skip_if_wine_exec!(Ok(()), "requires native cross-OS instruction-source paths");
let instructions = agents_instructions(
test_codex()
.with_config(|config| {
@@ -334,8 +329,8 @@ async fn symlinked_cwd_uses_logical_parent_for_agents_discovery() -> Result<()>
assert_eq!(
test.codex.instruction_sources().await,
vec![
logical_root.join("AGENTS.md"),
test.config.cwd.join("AGENTS.md")
PathUri::from_abs_path(&logical_root.join("AGENTS.md")),
PathUri::from_abs_path(&test.config.cwd.join("AGENTS.md"))
]
);
@@ -355,8 +350,6 @@ async fn symlinked_cwd_uses_logical_parent_for_agents_discovery() -> Result<()>
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn selected_environment_sources_match_model_visible_instructions() -> Result<()> {
// TODO(anp): Remove after instruction-source helpers use target-native paths.
skip_if_wine_exec!(Ok(()), "requires native cross-OS instruction-source paths");
let server = start_mock_server().await;
let resp_mock = mount_sse_once(
&server,
@@ -385,7 +378,10 @@ async fn selected_environment_sources_match_model_visible_instructions() -> Resu
assert_eq!(
test.codex.instruction_sources().await,
vec![global_agents, project_agents]
vec![
PathUri::from_abs_path(&global_agents),
PathUri::from_abs_path(&project_agents),
]
);
test.submit_turn("hello").await?;
@@ -454,7 +450,7 @@ async fn loads_user_instructions_without_a_primary_environment() -> Result<()> {
assert_eq!(provider.load_count(), 2);
assert_eq!(
no_environment_thread.thread.instruction_sources().await,
vec![global_source]
vec![PathUri::from_abs_path(&global_source)]
);
no_environment_thread
@@ -485,8 +481,6 @@ async fn loads_user_instructions_without_a_primary_environment() -> Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn fresh_thread_composes_global_before_project_and_reports_sources() -> Result<()> {
// TODO(anp): Remove after instruction-source helpers use target-native paths.
skip_if_wine_exec!(Ok(()), "requires native cross-OS instruction-source paths");
// Set up one global source, one project source, and two ordinary model turns.
let server = responses::start_mock_server().await;
let response_mock = responses::mount_sse_sequence(
@@ -521,7 +515,10 @@ async fn fresh_thread_composes_global_before_project_and_reports_sources() -> Re
});
let test = builder.build_with_remote_env(&server).await?;
let project_source = test.config.cwd.join(GLOBAL_AGENTS_FILENAME);
let creation_sources = vec![global_source.clone(), project_source.clone()];
let creation_sources = vec![
PathUri::from_abs_path(&global_source),
PathUri::from_abs_path(&project_source),
];
// Confirm the thread records both creation-time sources in composition order.
assert_eq!(test.codex.instruction_sources().await, creation_sources);
@@ -597,8 +594,6 @@ async fn fresh_thread_composes_global_before_project_and_reports_sources() -> Re
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn multi_environment_thread_loads_every_project_and_keeps_creation_snapshot() -> Result<()> {
// TODO(anp): Remove after instruction-source helpers use target-native paths.
skip_if_wine_exec!(Ok(()), "requires native cross-OS instruction-source paths");
skip_if_no_network!(Ok(()));
let Some(_remote_env) = get_remote_test_env() else {
return Ok(());
@@ -672,9 +667,9 @@ async fn multi_environment_thread_loads_every_project_and_keeps_creation_snapsho
assert_eq!(
thread.thread.instruction_sources().await,
vec![
global_source.clone(),
remote_source.clone(),
local_source.clone().try_into()?,
PathUri::from_abs_path(&global_source),
PathUri::from_abs_path(&remote_source),
PathUri::from_path(&local_source)?,
]
);
@@ -700,7 +695,7 @@ async fn multi_environment_thread_loads_every_project_and_keeps_creation_snapsho
let contents = format!(
"{GLOBAL_INSTRUCTIONS}\n\nfor `{REMOTE_ENVIRONMENT_ID}` with root {}\n\nremote project instructions\n\nfor `{LOCAL_ENVIRONMENT_ID}` with root {}\n\nlocal project instructions",
test.config.cwd.display(),
PathUri::from_abs_path(&test.config.cwd).inferred_native_path_string(),
local_root.path().display(),
);
let expected =
@@ -712,7 +707,11 @@ async fn multi_environment_thread_loads_every_project_and_keeps_creation_snapsho
assert_eq!(provider.load_count(), 2);
assert_eq!(
thread.thread.instruction_sources().await,
vec![global_source, remote_source, local_source.try_into()?]
vec![
PathUri::from_abs_path(&global_source),
PathUri::from_abs_path(&remote_source),
PathUri::from_path(&local_source)?,
]
);
Ok(())
@@ -741,7 +740,10 @@ async fn invalid_utf8_global_instructions_are_lossy() -> Result<()> {
test.submit_turn("inspect lossy global instructions")
.await?;
assert_eq!(test.codex.instruction_sources().await, vec![source.clone()]);
assert_eq!(
test.codex.instruction_sources().await,
vec![PathUri::from_abs_path(&source)]
);
let expected_fragment =
expected_provider_only_instruction_fragment("global\u{FFFD}instructions");
assert_single_instruction_fragment(&response_mock.single_request(), &expected_fragment);
@@ -784,7 +786,7 @@ async fn cold_resume_replays_rendered_instructions_but_reports_current_config_so
// Assert the pre-resume thread reports the source used to create its snapshot.
assert_eq!(
initial.codex.instruction_sources().await,
vec![old_source.clone()],
vec![PathUri::from_abs_path(&old_source)],
"initial thread reports the creation-time global source"
);
initial.submit_turn("persist instructions").await?;
@@ -814,7 +816,7 @@ async fn cold_resume_replays_rendered_instructions_but_reports_current_config_so
// Assert the API reports the new source while model history replays the old structured prefix.
assert_eq!(
resumed.codex.instruction_sources().await,
vec![new_source],
vec![PathUri::from_abs_path(&new_source)],
"resume reports sources from the newly loaded config"
);
@@ -868,7 +870,7 @@ async fn fork_replays_rendered_instructions_from_shared_history() -> Result<()>
// Assert the parent reports the source used to create its snapshot.
assert_eq!(
parent.codex.instruction_sources().await,
vec![source.clone()],
vec![PathUri::from_abs_path(&source)],
"parent reports the creation-time global source"
);
parent.submit_turn("persist instructions").await?;
@@ -903,7 +905,7 @@ async fn fork_replays_rendered_instructions_from_shared_history() -> Result<()>
// Assert the fork reports the new source before issuing its first turn.
assert_eq!(
forked.thread.instruction_sources().await,
vec![new_source],
vec![PathUri::from_abs_path(&new_source)],
"fork config should reflect the newly loaded global source"
);
@@ -1033,7 +1035,7 @@ async fn run_subagent_global_instruction_case(fork_context: bool) -> Result<()>
// Assert the parent reports the creation-time source before spawning.
assert_eq!(
test.codex.instruction_sources().await,
vec![source.clone()],
vec![PathUri::from_abs_path(&source)],
"parent reports the creation-time global source before spawning"
);
test.submit_turn(SPAWN_SEED_PROMPT).await?;
@@ -1076,12 +1078,12 @@ async fn run_subagent_global_instruction_case(fork_context: bool) -> Result<()>
assert_single_instruction_fragment(&child_request, &expected_fragment);
assert_eq!(
test.codex.instruction_sources().await,
vec![source.clone()],
vec![PathUri::from_abs_path(&source)],
"running parent retains the creation-time global source after spawning"
);
assert_eq!(
child_thread.instruction_sources().await,
vec![source],
vec![PathUri::from_abs_path(&source)],
"subagent reports the parent's creation-time source"
);
if fork_context {
+7 -6
View File
@@ -25,6 +25,7 @@ use codex_protocol::protocol::RolloutLine;
use codex_protocol::protocol::WarningEvent;
use codex_protocol::user_input::UserInput;
use codex_utils_absolute_path::AbsolutePathBuf;
use codex_utils_path_uri::PathUri;
use core_test_support::PathBufExt;
use core_test_support::context_snapshot;
use core_test_support::context_snapshot::ContextSnapshotOptions;
@@ -4593,7 +4594,7 @@ async fn manual_compaction_keeps_the_creation_time_global_instructions() -> Resu
// Assert the pre-compaction source list points at the creation-time file.
assert_eq!(
test.codex.instruction_sources().await,
vec![source.clone()],
vec![PathUri::from_abs_path(&source)],
"thread reports the creation-time global source before compaction"
);
@@ -4623,7 +4624,7 @@ async fn manual_compaction_keeps_the_creation_time_global_instructions() -> Resu
assert_single_instruction_fragment(&requests[2], &expected_fragment);
assert_eq!(
test.codex.instruction_sources().await,
vec![source],
vec![PathUri::from_abs_path(&source)],
"thread retains the creation-time global source after compaction"
);
@@ -4673,7 +4674,7 @@ async fn mid_turn_compaction_keeps_the_creation_time_global_instructions() -> Re
// Assert the pre-compaction source list points at the creation-time file.
assert_eq!(
test.codex.instruction_sources().await,
vec![source.clone()],
vec![PathUri::from_abs_path(&source)],
"thread reports the creation-time global source before mid-turn compaction"
);
@@ -4695,7 +4696,7 @@ async fn mid_turn_compaction_keeps_the_creation_time_global_instructions() -> Re
assert_single_instruction_fragment(&requests[2], &expected_fragment);
assert_eq!(
test.codex.instruction_sources().await,
vec![source],
vec![PathUri::from_abs_path(&source)],
"thread retains the creation-time global source after mid-turn compaction"
);
@@ -4780,7 +4781,7 @@ async fn remote_v2_compaction_keeps_creation_time_instructions_after_same_path_m
);
assert_eq!(
test.codex.instruction_sources().await,
vec![source.clone()],
vec![PathUri::from_abs_path(&source)],
"running thread retains the selected same-path source"
);
assert_eq!(
@@ -4829,7 +4830,7 @@ async fn remote_v2_compaction_keeps_creation_time_instructions_after_same_path_m
);
assert_eq!(
resumed.codex.instruction_sources().await,
vec![source],
vec![PathUri::from_abs_path(&source)],
"cold-resumed thread reports the same rewritten source path"
);
@@ -1,100 +0,0 @@
use codex_features::Feature;
use codex_utils_path_uri::PathUri;
use core_test_support::responses::ev_completed;
use core_test_support::responses::ev_response_created;
use core_test_support::responses::mount_sse_once;
use core_test_support::responses::sse;
use core_test_support::responses::start_mock_server;
use core_test_support::skip_if_wine_exec;
use core_test_support::test_codex::test_codex;
const HIERARCHICAL_AGENTS_SNIPPET: &str =
"Files called AGENTS.md commonly appear in many places inside a container";
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn hierarchical_agents_appends_to_project_doc_in_user_instructions() {
// TODO(anp): Remove after instruction-source helpers use target-native paths.
skip_if_wine_exec!("requires native cross-OS instruction-source paths");
let server = start_mock_server().await;
let resp_mock = mount_sse_once(
&server,
sse(vec![ev_response_created("resp1"), ev_completed("resp1")]),
)
.await;
let mut builder = test_codex()
.with_config(|config| {
config
.features
.enable(Feature::ChildAgentsMd)
.expect("test config should allow feature update");
})
.with_workspace_setup(|cwd, fs| async move {
let agents_md = cwd.join("AGENTS.md");
let agents_md_uri = PathUri::from_path(&agents_md)?;
fs.write_file(&agents_md_uri, b"be nice".to_vec(), /*sandbox*/ None)
.await?;
Ok::<(), anyhow::Error>(())
});
let test = builder
.build_with_remote_env(&server)
.await
.expect("build test codex");
test.submit_turn("hello").await.expect("submit turn");
let request = resp_mock.single_request();
let user_messages = request.message_input_texts("user");
let instructions = user_messages
.iter()
.find(|text| text.starts_with("# AGENTS.md instructions"))
.expect("instructions message");
assert!(
instructions.contains("be nice"),
"expected AGENTS.md text included: {instructions}"
);
let snippet_pos = instructions
.find(HIERARCHICAL_AGENTS_SNIPPET)
.expect("expected hierarchical agents snippet");
let base_pos = instructions
.find("be nice")
.expect("expected AGENTS.md text");
assert!(
snippet_pos > base_pos,
"expected hierarchical agents message appended after base instructions: {instructions}"
);
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn hierarchical_agents_emits_when_no_project_doc() {
let server = start_mock_server().await;
let resp_mock = mount_sse_once(
&server,
sse(vec![ev_response_created("resp1"), ev_completed("resp1")]),
)
.await;
let mut builder = test_codex().with_config(|config| {
config
.features
.enable(Feature::ChildAgentsMd)
.expect("test config should allow feature update");
});
let test = builder
.build_with_remote_env(&server)
.await
.expect("build test codex");
test.submit_turn("hello").await.expect("submit turn");
let request = resp_mock.single_request();
let user_messages = request.message_input_texts("user");
let instructions = user_messages
.iter()
.find(|text| text.starts_with("# AGENTS.md instructions"))
.expect("instructions message");
assert!(
instructions.contains(HIERARCHICAL_AGENTS_SNIPPET),
"expected hierarchical agents message appended: {instructions}"
);
}
-1
View File
@@ -57,7 +57,6 @@ mod extension_sandbox;
mod fork_thread;
#[cfg(not(target_os = "windows"))]
mod guardian_review;
mod hierarchical_agents;
#[cfg(not(target_os = "windows"))]
mod hooks;
#[cfg(not(target_os = "windows"))]
+71
View File
@@ -228,6 +228,77 @@ async fn remote_test_env_exposes_target_shell_to_model() -> Result<()> {
Ok(())
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn explicit_remote_shell_runs_in_remote_cwd() -> Result<()> {
const CALL_ID: &str = "remote-explicit-shell";
let (shell, command) = match core_test_support::test_environment() {
TestEnvironment::Docker { .. } => (
"bash",
r#"case "$PWD" in /tmp/codex-core-test-cwd-*) ;; *) echo "unexpected cwd: $PWD" >&2; exit 1 ;; esac"#,
),
TestEnvironment::WineExec => (
"powershell",
r#"$cwd = (Get-Location).Path; if ($cwd -notlike 'C:\codex-core-test-cwd-*') { Write-Error "unexpected cwd: $cwd"; exit 1 }"#,
),
TestEnvironment::Local => return Ok(()),
};
let server = start_mock_server().await;
let arguments = serde_json::to_string(&json!({
"cmd": command,
"shell": shell,
"login": false,
"yield_time_ms": 10_000,
}))?;
let mut builder = test_codex().with_config(|config| {
config.use_experimental_unified_exec_tool = true;
config
.features
.enable(Feature::UnifiedExec)
.expect("test config should allow feature update");
});
let test = builder.build_with_remote_env(&server).await?;
let response_mock = mount_sse_sequence(
&server,
vec![
sse(vec![
ev_response_created("resp-1"),
ev_function_call(CALL_ID, "exec_command", &arguments),
ev_completed("resp-1"),
]),
sse(vec![
ev_response_created("resp-2"),
ev_assistant_message("msg-1", "done"),
ev_completed("resp-2"),
]),
],
)
.await;
test.submit_turn_with_environments(
"run the remote shell in the remote cwd",
Some(vec![TurnEnvironmentSelection {
environment_id: REMOTE_ENVIRONMENT_ID.to_string(),
cwd: PathUri::from_abs_path(&test.config.cwd),
}]),
)
.await?;
let request = response_mock
.last_request()
.context("model should receive the command output")?;
let (output, success) = request
.function_call_output_content_and_success(CALL_ID)
.context("remote shell tool result should be present")?;
assert_ne!(success, Some(false));
assert!(
output.is_some_and(|output| output.contains("Process exited with code 0")),
"remote shell command should exit successfully",
);
Ok(())
}
fn absolute_path(path: PathBuf) -> AbsolutePathBuf {
AbsolutePathBuf::try_from(path).expect("path should be absolute")
}
+2
View File
@@ -1337,7 +1337,9 @@ async fn stdio_image_responses_round_trip() -> anyhow::Result<()> {
tool: "image".to_string(),
arguments: Some(json!({})),
},
connector_id: None,
mcp_app_resource_uri: None,
link_id: None,
plugin_id: None,
},
);
+3
View File
@@ -25,6 +25,7 @@ use core_test_support::apps_test_server::CALENDAR_CREATE_EVENT_MCP_APP_RESOURCE_
use core_test_support::apps_test_server::CALENDAR_CREATE_EVENT_RESOURCE_URI;
use core_test_support::apps_test_server::DIRECT_CALENDAR_CREATE_EVENT_TOOL as CALENDAR_CREATE_TOOL;
use core_test_support::apps_test_server::DIRECT_CALENDAR_LIST_EVENTS_TOOL as CALENDAR_LIST_TOOL;
use core_test_support::apps_test_server::LINK_ID;
use core_test_support::apps_test_server::SEARCH_CALENDAR_APP_ONLY_TOOL;
use core_test_support::apps_test_server::SEARCH_CALENDAR_CREATE_TOOL;
use core_test_support::apps_test_server::SEARCH_CALENDAR_LIST_TOOL;
@@ -559,10 +560,12 @@ async fn tool_search_returns_deferred_tools_without_follow_up_tool_injection() -
unreachable!("event guard guarantees McpToolCallEnd");
};
assert_eq!(end.call_id, "calendar-call-1");
assert_eq!(end.connector_id.as_deref(), Some("calendar"));
assert_eq!(
end.mcp_app_resource_uri.as_deref(),
Some(CALENDAR_CREATE_EVENT_MCP_APP_RESOURCE_URI)
);
assert_eq!(end.link_id.as_deref(), Some(LINK_ID));
assert_eq!(
end.invocation,
McpInvocation {
@@ -21,14 +21,14 @@ async fn emits_warning_when_unstable_features_enabled_via_config() {
let mut config = load_default_config_for_test(&home).await;
config
.features
.enable(Feature::ChildAgentsMd)
.enable(Feature::ApplyPatchStreamingEvents)
.expect("test config should allow feature update");
let user_config_path =
AbsolutePathBuf::from_absolute_path(config.codex_home.join(CONFIG_TOML_FILE))
.expect("absolute user config path");
config.config_layer_stack = config.config_layer_stack.with_user_config(
&user_config_path,
toml! { features = { child_agents_md = true } }.into(),
toml! { features = { apply_patch_streaming_events = true } }.into(),
);
let thread_manager = codex_core::test_support::thread_manager_with_models_provider(
@@ -56,7 +56,7 @@ async fn emits_warning_when_unstable_features_enabled_via_config() {
let EventMsg::Warning(WarningEvent { message }) = warning else {
panic!("expected warning event");
};
assert!(message.contains("child_agents_md"));
assert!(message.contains("apply_patch_streaming_events"));
assert!(message.contains("Under-development features enabled"));
assert!(message.contains("suppress_unstable_features_warning = true"));
}
@@ -67,7 +67,7 @@ async fn suppresses_warning_when_configured() {
let mut config = load_default_config_for_test(&home).await;
config
.features
.enable(Feature::ChildAgentsMd)
.enable(Feature::ApplyPatchStreamingEvents)
.expect("test config should allow feature update");
config.suppress_unstable_features_warning = true;
let user_config_path =
@@ -75,7 +75,7 @@ async fn suppresses_warning_when_configured() {
.expect("absolute user config path");
config.config_layer_stack = config.config_layer_stack.with_user_config(
&user_config_path,
toml! { features = { child_agents_md = true } }.into(),
toml! { features = { apply_patch_streaming_events = true } }.into(),
);
let thread_manager = codex_core::test_support::thread_manager_with_models_provider(
@@ -1,6 +1,7 @@
//! Test support for running the Windows exec-server under Wine.
use std::future::Future;
use std::path::PathBuf;
use anyhow::Context;
use anyhow::Result;
@@ -12,16 +13,18 @@ use wine_test_support::WineTestCommand;
pub struct WineExecServer;
impl WineExecServer {
/// Starts the server, passes its WebSocket URL to `operation`, and tears it down afterward.
/// Starts the server, passes its WebSocket URL and Wine prefix to `operation`, and tears it
/// down afterward.
pub async fn scope<T, F, Fut>(self, operation: F) -> Result<T>
where
F: FnOnce(String) -> Fut,
F: FnOnce(String, PathBuf) -> Fut,
Fut: Future<Output = Result<T>>,
{
let executable = codex_utils_cargo_bin::cargo_bin("wine-windows-exec-server")?;
let mut exec_server = WineTestCommand::new(executable)
.env("CODEX_HOME", r"C:\codex-home")
.spawn()?;
let wine_prefix = exec_server.prefix_path().to_path_buf();
let stdout = exec_server.take_stdout();
exec_server
@@ -36,7 +39,7 @@ impl WineExecServer {
break line;
}
};
operation(exec_server_url).await
operation(exec_server_url, wine_prefix).await
})
.await
}
@@ -33,7 +33,7 @@ async fn main() -> Result<()> {
}
WineExecServer
.scope(|exec_server_url| async move {
.scope(|exec_server_url, _wine_prefix| async move {
let mut command = Command::new(test_binary);
command
.env(TEST_ENVIRONMENT_ENV_VAR, "wine-exec")
@@ -98,6 +98,7 @@ fn mcp_tool_call_result_preserves_meta_in_jsonl_event() {
tool: "web_run".to_string(),
status: McpToolCallStatus::Completed,
arguments: json!({"search_query": [{"q": "OpenAI Codex CLI documentation"}]}),
app_context: None,
mcp_app_resource_uri: None,
plugin_id: None,
result: Some(Box::new(codex_app_server_protocol::McpToolCallResult {
-1
View File
@@ -475,7 +475,6 @@ pub async fn run_main(cli: Cli, arg0_paths: Arg0DispatchPaths) -> anyhow::Result
forced_login_method: config.forced_login_method,
forced_chatgpt_workspace_id: config.forced_chatgpt_workspace_id.clone(),
chatgpt_base_url: Some(config.chatgpt_base_url.clone()),
agent_identity_authapi_base_url: None,
})
.await
{
@@ -478,6 +478,7 @@ fn mcp_tool_call_begin_and_end_emit_item_events() {
tool: "tool_x".to_string(),
status: ApiMcpToolCallStatus::InProgress,
arguments: json!({ "key": "value" }),
app_context: None,
mcp_app_resource_uri: None,
plugin_id: None,
result: None,
@@ -496,6 +497,7 @@ fn mcp_tool_call_begin_and_end_emit_item_events() {
tool: "tool_x".to_string(),
status: ApiMcpToolCallStatus::Completed,
arguments: json!({ "key": "value" }),
app_context: None,
mcp_app_resource_uri: None,
plugin_id: None,
result: Some(Box::new(McpToolCallResult {
@@ -568,6 +570,7 @@ fn mcp_tool_call_failure_sets_failed_status() {
tool: "tool_y".to_string(),
status: ApiMcpToolCallStatus::Failed,
arguments: json!({ "param": 42 }),
app_context: None,
mcp_app_resource_uri: None,
plugin_id: None,
result: None,
@@ -617,6 +620,7 @@ fn mcp_tool_call_defaults_arguments_and_preserves_structured_content() {
tool: "tool_z".to_string(),
status: ApiMcpToolCallStatus::InProgress,
arguments: serde_json::Value::Null,
app_context: None,
mcp_app_resource_uri: None,
plugin_id: None,
result: None,
@@ -635,6 +639,7 @@ fn mcp_tool_call_defaults_arguments_and_preserves_structured_content() {
tool: "tool_z".to_string(),
status: ApiMcpToolCallStatus::Completed,
arguments: serde_json::Value::Null,
app_context: None,
mcp_app_resource_uri: None,
plugin_id: None,
result: Some(Box::new(McpToolCallResult {
+11 -8
View File
@@ -76,14 +76,17 @@ impl SkillProvider for ExecutorSkillProvider {
};
let file_system = environment.get_filesystem();
let outcome = filter_skill_load_outcome_for_product(
load_skills_from_roots([SkillRoot {
path: root_path.clone(),
scope: SkillScope::User,
file_system: Arc::clone(&file_system),
plugin_id: None,
plugin_namespace: None,
plugin_root: None,
}])
load_skills_from_roots(
[SkillRoot {
path: root_path.clone(),
scope: SkillScope::User,
file_system: Arc::clone(&file_system),
plugin_id: None,
plugin_namespace: None,
plugin_root: None,
}],
/*plugin_skill_snapshots*/ None,
)
.await,
self.restriction_product,
);
@@ -188,17 +188,20 @@ async fn skill_loading_and_reads_use_the_supplied_executor_file_system() {
assert!(!alias_root.as_path().exists());
assert!(!canonical_root.as_path().exists());
let outcome = load_skills_from_roots([SkillRoot {
path: alias_root.clone(),
scope: SkillScope::User,
file_system: Arc::new(SyntheticFileSystem {
alias_root,
canonical_root: canonical_root.clone(),
}),
plugin_id: None,
plugin_namespace: None,
plugin_root: None,
}])
let outcome = load_skills_from_roots(
[SkillRoot {
path: alias_root.clone(),
scope: SkillScope::User,
file_system: Arc::new(SyntheticFileSystem {
alias_root,
canonical_root: canonical_root.clone(),
}),
plugin_id: None,
plugin_namespace: None,
plugin_root: None,
}],
/*plugin_skill_snapshots*/ None,
)
.await;
assert_eq!(outcome.errors, Vec::new());
assert_eq!(outcome.skills.len(), 1);
+8 -8
View File
@@ -132,8 +132,6 @@ pub enum Feature {
LocalThreadStoreCompression,
/// Enable the Chronicle sidecar for passive screen-context memories.
Chronicle,
/// Append additional AGENTS.md guidance to user instructions.
ChildAgentsMd,
/// Compress request bodies (zstd) when sending streaming requests to codex-backend.
EnableRequestCompression,
/// Start the managed network proxy for sandboxed sessions.
@@ -228,6 +226,8 @@ pub enum Feature {
PreventIdleSleep,
/// Enable remote compaction v2 over the normal Responses API.
RemoteCompactionV2,
/// Use Agent Identity for ChatGPT-authenticated sessions.
UseAgentIdentity,
/// Enable workspace dependency support.
WorkspaceDependencies,
@@ -908,12 +908,6 @@ pub const FEATURES: &[FeatureSpec] = &[
stage: Stage::UnderDevelopment,
default_enabled: false,
},
FeatureSpec {
id: Feature::ChildAgentsMd,
key: "child_agents_md",
stage: Stage::UnderDevelopment,
default_enabled: false,
},
FeatureSpec {
id: Feature::ApplyPatchFreeform,
key: "apply_patch_freeform",
@@ -1314,6 +1308,12 @@ pub const FEATURES: &[FeatureSpec] = &[
stage: Stage::Stable,
default_enabled: true,
},
FeatureSpec {
id: Feature::UseAgentIdentity,
key: "use_agent_identity",
stage: Stage::UnderDevelopment,
default_enabled: false,
},
FeatureSpec {
id: Feature::WorkspaceDependencies,
key: "workspace_dependencies",

Some files were not shown because too many files have changed in this diff Show More