diff --git a/codex-rs/app-server-protocol/schema/json/ServerNotification.json b/codex-rs/app-server-protocol/schema/json/ServerNotification.json index 14908dbb1f7..8af79020342 100644 --- a/codex-rs/app-server-protocol/schema/json/ServerNotification.json +++ b/codex-rs/app-server-protocol/schema/json/ServerNotification.json @@ -1454,6 +1454,54 @@ ], "type": "string" }, + "MemoryCitation": { + "properties": { + "entries": { + "items": { + "$ref": "#/definitions/MemoryCitationEntry" + }, + "type": "array" + }, + "threadIds": { + "items": { + "type": "string" + }, + "type": "array" + } + }, + "required": [ + "entries", + "threadIds" + ], + "type": "object" + }, + "MemoryCitationEntry": { + "properties": { + "lineEnd": { + "format": "uint32", + "minimum": 0.0, + "type": "integer" + }, + "lineStart": { + "format": "uint32", + "minimum": 0.0, + "type": "integer" + }, + "note": { + "type": "string" + }, + "path": { + "type": "string" + } + }, + "required": [ + "lineEnd", + "lineStart", + "note", + "path" + ], + "type": "object" + }, "MessagePhase": { "description": "Classifies an assistant message as interim commentary or final answer text.\n\nProviders do not emit this consistently, so callers must treat `None` as \"phase unknown\" and keep compatibility behavior for legacy models.", "oneOf": [ @@ -2173,6 +2221,17 @@ "id": { "type": "string" }, + "memoryCitation": { + "anyOf": [ + { + "$ref": "#/definitions/MemoryCitation" + }, + { + "type": "null" + } + ], + "default": null + }, "phase": { "anyOf": [ { diff --git a/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json b/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json index 4709bae11c4..59e909bb36f 100644 --- a/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json +++ b/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json @@ -8674,6 +8674,54 @@ ], "type": "string" }, + "MemoryCitation": { + "properties": { + "entries": { + "items": { + "$ref": "#/definitions/v2/MemoryCitationEntry" + }, + "type": "array" + }, + "threadIds": { + "items": { + "type": "string" + }, + "type": "array" + } + }, + "required": [ + "entries", + "threadIds" + ], + "type": "object" + }, + "MemoryCitationEntry": { + "properties": { + "lineEnd": { + "format": "uint32", + "minimum": 0.0, + "type": "integer" + }, + "lineStart": { + "format": "uint32", + "minimum": 0.0, + "type": "integer" + }, + "note": { + "type": "string" + }, + "path": { + "type": "string" + } + }, + "required": [ + "lineEnd", + "lineStart", + "note", + "path" + ], + "type": "object" + }, "MergeStrategy": { "enum": [ "replace", @@ -12014,6 +12062,17 @@ "id": { "type": "string" }, + "memoryCitation": { + "anyOf": [ + { + "$ref": "#/definitions/v2/MemoryCitation" + }, + { + "type": "null" + } + ], + "default": null + }, "phase": { "anyOf": [ { diff --git a/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.json b/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.json index 601306fe143..7b19330ab86 100644 --- a/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.json +++ b/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.json @@ -5462,6 +5462,54 @@ ], "type": "string" }, + "MemoryCitation": { + "properties": { + "entries": { + "items": { + "$ref": "#/definitions/MemoryCitationEntry" + }, + "type": "array" + }, + "threadIds": { + "items": { + "type": "string" + }, + "type": "array" + } + }, + "required": [ + "entries", + "threadIds" + ], + "type": "object" + }, + "MemoryCitationEntry": { + "properties": { + "lineEnd": { + "format": "uint32", + "minimum": 0.0, + "type": "integer" + }, + "lineStart": { + "format": "uint32", + "minimum": 0.0, + "type": "integer" + }, + "note": { + "type": "string" + }, + "path": { + "type": "string" + } + }, + "required": [ + "lineEnd", + "lineStart", + "note", + "path" + ], + "type": "object" + }, "MergeStrategy": { "enum": [ "replace", @@ -9774,6 +9822,17 @@ "id": { "type": "string" }, + "memoryCitation": { + "anyOf": [ + { + "$ref": "#/definitions/MemoryCitation" + }, + { + "type": "null" + } + ], + "default": null + }, "phase": { "anyOf": [ { diff --git a/codex-rs/app-server-protocol/schema/json/v2/ItemCompletedNotification.json b/codex-rs/app-server-protocol/schema/json/v2/ItemCompletedNotification.json index b447fc3397a..f165850bf67 100644 --- a/codex-rs/app-server-protocol/schema/json/v2/ItemCompletedNotification.json +++ b/codex-rs/app-server-protocol/schema/json/v2/ItemCompletedNotification.json @@ -289,6 +289,54 @@ ], "type": "string" }, + "MemoryCitation": { + "properties": { + "entries": { + "items": { + "$ref": "#/definitions/MemoryCitationEntry" + }, + "type": "array" + }, + "threadIds": { + "items": { + "type": "string" + }, + "type": "array" + } + }, + "required": [ + "entries", + "threadIds" + ], + "type": "object" + }, + "MemoryCitationEntry": { + "properties": { + "lineEnd": { + "format": "uint32", + "minimum": 0.0, + "type": "integer" + }, + "lineStart": { + "format": "uint32", + "minimum": 0.0, + "type": "integer" + }, + "note": { + "type": "string" + }, + "path": { + "type": "string" + } + }, + "required": [ + "lineEnd", + "lineStart", + "note", + "path" + ], + "type": "object" + }, "MessagePhase": { "description": "Classifies an assistant message as interim commentary or final answer text.\n\nProviders do not emit this consistently, so callers must treat `None` as \"phase unknown\" and keep compatibility behavior for legacy models.", "oneOf": [ @@ -444,6 +492,17 @@ "id": { "type": "string" }, + "memoryCitation": { + "anyOf": [ + { + "$ref": "#/definitions/MemoryCitation" + }, + { + "type": "null" + } + ], + "default": null + }, "phase": { "anyOf": [ { diff --git a/codex-rs/app-server-protocol/schema/json/v2/ItemStartedNotification.json b/codex-rs/app-server-protocol/schema/json/v2/ItemStartedNotification.json index 1b02f44188e..811e02c5a1c 100644 --- a/codex-rs/app-server-protocol/schema/json/v2/ItemStartedNotification.json +++ b/codex-rs/app-server-protocol/schema/json/v2/ItemStartedNotification.json @@ -289,6 +289,54 @@ ], "type": "string" }, + "MemoryCitation": { + "properties": { + "entries": { + "items": { + "$ref": "#/definitions/MemoryCitationEntry" + }, + "type": "array" + }, + "threadIds": { + "items": { + "type": "string" + }, + "type": "array" + } + }, + "required": [ + "entries", + "threadIds" + ], + "type": "object" + }, + "MemoryCitationEntry": { + "properties": { + "lineEnd": { + "format": "uint32", + "minimum": 0.0, + "type": "integer" + }, + "lineStart": { + "format": "uint32", + "minimum": 0.0, + "type": "integer" + }, + "note": { + "type": "string" + }, + "path": { + "type": "string" + } + }, + "required": [ + "lineEnd", + "lineStart", + "note", + "path" + ], + "type": "object" + }, "MessagePhase": { "description": "Classifies an assistant message as interim commentary or final answer text.\n\nProviders do not emit this consistently, so callers must treat `None` as \"phase unknown\" and keep compatibility behavior for legacy models.", "oneOf": [ @@ -444,6 +492,17 @@ "id": { "type": "string" }, + "memoryCitation": { + "anyOf": [ + { + "$ref": "#/definitions/MemoryCitation" + }, + { + "type": "null" + } + ], + "default": null + }, "phase": { "anyOf": [ { diff --git a/codex-rs/app-server-protocol/schema/json/v2/ReviewStartResponse.json b/codex-rs/app-server-protocol/schema/json/v2/ReviewStartResponse.json index b8e83ba34e5..aeb4db80ef9 100644 --- a/codex-rs/app-server-protocol/schema/json/v2/ReviewStartResponse.json +++ b/codex-rs/app-server-protocol/schema/json/v2/ReviewStartResponse.json @@ -403,6 +403,54 @@ ], "type": "string" }, + "MemoryCitation": { + "properties": { + "entries": { + "items": { + "$ref": "#/definitions/MemoryCitationEntry" + }, + "type": "array" + }, + "threadIds": { + "items": { + "type": "string" + }, + "type": "array" + } + }, + "required": [ + "entries", + "threadIds" + ], + "type": "object" + }, + "MemoryCitationEntry": { + "properties": { + "lineEnd": { + "format": "uint32", + "minimum": 0.0, + "type": "integer" + }, + "lineStart": { + "format": "uint32", + "minimum": 0.0, + "type": "integer" + }, + "note": { + "type": "string" + }, + "path": { + "type": "string" + } + }, + "required": [ + "lineEnd", + "lineStart", + "note", + "path" + ], + "type": "object" + }, "MessagePhase": { "description": "Classifies an assistant message as interim commentary or final answer text.\n\nProviders do not emit this consistently, so callers must treat `None` as \"phase unknown\" and keep compatibility behavior for legacy models.", "oneOf": [ @@ -558,6 +606,17 @@ "id": { "type": "string" }, + "memoryCitation": { + "anyOf": [ + { + "$ref": "#/definitions/MemoryCitation" + }, + { + "type": "null" + } + ], + "default": null + }, "phase": { "anyOf": [ { diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadForkResponse.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadForkResponse.json index e57c84b4639..04765cf484a 100644 --- a/codex-rs/app-server-protocol/schema/json/v2/ThreadForkResponse.json +++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadForkResponse.json @@ -488,6 +488,54 @@ ], "type": "string" }, + "MemoryCitation": { + "properties": { + "entries": { + "items": { + "$ref": "#/definitions/MemoryCitationEntry" + }, + "type": "array" + }, + "threadIds": { + "items": { + "type": "string" + }, + "type": "array" + } + }, + "required": [ + "entries", + "threadIds" + ], + "type": "object" + }, + "MemoryCitationEntry": { + "properties": { + "lineEnd": { + "format": "uint32", + "minimum": 0.0, + "type": "integer" + }, + "lineStart": { + "format": "uint32", + "minimum": 0.0, + "type": "integer" + }, + "note": { + "type": "string" + }, + "path": { + "type": "string" + } + }, + "required": [ + "lineEnd", + "lineStart", + "note", + "path" + ], + "type": "object" + }, "MessagePhase": { "description": "Classifies an assistant message as interim commentary or final answer text.\n\nProviders do not emit this consistently, so callers must treat `None` as \"phase unknown\" and keep compatibility behavior for legacy models.", "oneOf": [ @@ -1038,6 +1086,17 @@ "id": { "type": "string" }, + "memoryCitation": { + "anyOf": [ + { + "$ref": "#/definitions/MemoryCitation" + }, + { + "type": "null" + } + ], + "default": null + }, "phase": { "anyOf": [ { diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadListResponse.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadListResponse.json index f9f94305501..9366304000c 100644 --- a/codex-rs/app-server-protocol/schema/json/v2/ThreadListResponse.json +++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadListResponse.json @@ -426,6 +426,54 @@ ], "type": "string" }, + "MemoryCitation": { + "properties": { + "entries": { + "items": { + "$ref": "#/definitions/MemoryCitationEntry" + }, + "type": "array" + }, + "threadIds": { + "items": { + "type": "string" + }, + "type": "array" + } + }, + "required": [ + "entries", + "threadIds" + ], + "type": "object" + }, + "MemoryCitationEntry": { + "properties": { + "lineEnd": { + "format": "uint32", + "minimum": 0.0, + "type": "integer" + }, + "lineStart": { + "format": "uint32", + "minimum": 0.0, + "type": "integer" + }, + "note": { + "type": "string" + }, + "path": { + "type": "string" + } + }, + "required": [ + "lineEnd", + "lineStart", + "note", + "path" + ], + "type": "object" + }, "MessagePhase": { "description": "Classifies an assistant message as interim commentary or final answer text.\n\nProviders do not emit this consistently, so callers must treat `None` as \"phase unknown\" and keep compatibility behavior for legacy models.", "oneOf": [ @@ -796,6 +844,17 @@ "id": { "type": "string" }, + "memoryCitation": { + "anyOf": [ + { + "$ref": "#/definitions/MemoryCitation" + }, + { + "type": "null" + } + ], + "default": null + }, "phase": { "anyOf": [ { diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadMetadataUpdateResponse.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadMetadataUpdateResponse.json index c652c1cb447..57dea225e25 100644 --- a/codex-rs/app-server-protocol/schema/json/v2/ThreadMetadataUpdateResponse.json +++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadMetadataUpdateResponse.json @@ -426,6 +426,54 @@ ], "type": "string" }, + "MemoryCitation": { + "properties": { + "entries": { + "items": { + "$ref": "#/definitions/MemoryCitationEntry" + }, + "type": "array" + }, + "threadIds": { + "items": { + "type": "string" + }, + "type": "array" + } + }, + "required": [ + "entries", + "threadIds" + ], + "type": "object" + }, + "MemoryCitationEntry": { + "properties": { + "lineEnd": { + "format": "uint32", + "minimum": 0.0, + "type": "integer" + }, + "lineStart": { + "format": "uint32", + "minimum": 0.0, + "type": "integer" + }, + "note": { + "type": "string" + }, + "path": { + "type": "string" + } + }, + "required": [ + "lineEnd", + "lineStart", + "note", + "path" + ], + "type": "object" + }, "MessagePhase": { "description": "Classifies an assistant message as interim commentary or final answer text.\n\nProviders do not emit this consistently, so callers must treat `None` as \"phase unknown\" and keep compatibility behavior for legacy models.", "oneOf": [ @@ -796,6 +844,17 @@ "id": { "type": "string" }, + "memoryCitation": { + "anyOf": [ + { + "$ref": "#/definitions/MemoryCitation" + }, + { + "type": "null" + } + ], + "default": null + }, "phase": { "anyOf": [ { diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadReadResponse.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadReadResponse.json index b0ca838cdec..295938ba855 100644 --- a/codex-rs/app-server-protocol/schema/json/v2/ThreadReadResponse.json +++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadReadResponse.json @@ -426,6 +426,54 @@ ], "type": "string" }, + "MemoryCitation": { + "properties": { + "entries": { + "items": { + "$ref": "#/definitions/MemoryCitationEntry" + }, + "type": "array" + }, + "threadIds": { + "items": { + "type": "string" + }, + "type": "array" + } + }, + "required": [ + "entries", + "threadIds" + ], + "type": "object" + }, + "MemoryCitationEntry": { + "properties": { + "lineEnd": { + "format": "uint32", + "minimum": 0.0, + "type": "integer" + }, + "lineStart": { + "format": "uint32", + "minimum": 0.0, + "type": "integer" + }, + "note": { + "type": "string" + }, + "path": { + "type": "string" + } + }, + "required": [ + "lineEnd", + "lineStart", + "note", + "path" + ], + "type": "object" + }, "MessagePhase": { "description": "Classifies an assistant message as interim commentary or final answer text.\n\nProviders do not emit this consistently, so callers must treat `None` as \"phase unknown\" and keep compatibility behavior for legacy models.", "oneOf": [ @@ -796,6 +844,17 @@ "id": { "type": "string" }, + "memoryCitation": { + "anyOf": [ + { + "$ref": "#/definitions/MemoryCitation" + }, + { + "type": "null" + } + ], + "default": null + }, "phase": { "anyOf": [ { diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadResumeResponse.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadResumeResponse.json index 6809f9715bc..774c3cade36 100644 --- a/codex-rs/app-server-protocol/schema/json/v2/ThreadResumeResponse.json +++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadResumeResponse.json @@ -488,6 +488,54 @@ ], "type": "string" }, + "MemoryCitation": { + "properties": { + "entries": { + "items": { + "$ref": "#/definitions/MemoryCitationEntry" + }, + "type": "array" + }, + "threadIds": { + "items": { + "type": "string" + }, + "type": "array" + } + }, + "required": [ + "entries", + "threadIds" + ], + "type": "object" + }, + "MemoryCitationEntry": { + "properties": { + "lineEnd": { + "format": "uint32", + "minimum": 0.0, + "type": "integer" + }, + "lineStart": { + "format": "uint32", + "minimum": 0.0, + "type": "integer" + }, + "note": { + "type": "string" + }, + "path": { + "type": "string" + } + }, + "required": [ + "lineEnd", + "lineStart", + "note", + "path" + ], + "type": "object" + }, "MessagePhase": { "description": "Classifies an assistant message as interim commentary or final answer text.\n\nProviders do not emit this consistently, so callers must treat `None` as \"phase unknown\" and keep compatibility behavior for legacy models.", "oneOf": [ @@ -1038,6 +1086,17 @@ "id": { "type": "string" }, + "memoryCitation": { + "anyOf": [ + { + "$ref": "#/definitions/MemoryCitation" + }, + { + "type": "null" + } + ], + "default": null + }, "phase": { "anyOf": [ { diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadRollbackResponse.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadRollbackResponse.json index 2288caa5081..518f560a278 100644 --- a/codex-rs/app-server-protocol/schema/json/v2/ThreadRollbackResponse.json +++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadRollbackResponse.json @@ -426,6 +426,54 @@ ], "type": "string" }, + "MemoryCitation": { + "properties": { + "entries": { + "items": { + "$ref": "#/definitions/MemoryCitationEntry" + }, + "type": "array" + }, + "threadIds": { + "items": { + "type": "string" + }, + "type": "array" + } + }, + "required": [ + "entries", + "threadIds" + ], + "type": "object" + }, + "MemoryCitationEntry": { + "properties": { + "lineEnd": { + "format": "uint32", + "minimum": 0.0, + "type": "integer" + }, + "lineStart": { + "format": "uint32", + "minimum": 0.0, + "type": "integer" + }, + "note": { + "type": "string" + }, + "path": { + "type": "string" + } + }, + "required": [ + "lineEnd", + "lineStart", + "note", + "path" + ], + "type": "object" + }, "MessagePhase": { "description": "Classifies an assistant message as interim commentary or final answer text.\n\nProviders do not emit this consistently, so callers must treat `None` as \"phase unknown\" and keep compatibility behavior for legacy models.", "oneOf": [ @@ -796,6 +844,17 @@ "id": { "type": "string" }, + "memoryCitation": { + "anyOf": [ + { + "$ref": "#/definitions/MemoryCitation" + }, + { + "type": "null" + } + ], + "default": null + }, "phase": { "anyOf": [ { diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadStartResponse.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadStartResponse.json index e994a2b009a..a6746e1eb18 100644 --- a/codex-rs/app-server-protocol/schema/json/v2/ThreadStartResponse.json +++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadStartResponse.json @@ -488,6 +488,54 @@ ], "type": "string" }, + "MemoryCitation": { + "properties": { + "entries": { + "items": { + "$ref": "#/definitions/MemoryCitationEntry" + }, + "type": "array" + }, + "threadIds": { + "items": { + "type": "string" + }, + "type": "array" + } + }, + "required": [ + "entries", + "threadIds" + ], + "type": "object" + }, + "MemoryCitationEntry": { + "properties": { + "lineEnd": { + "format": "uint32", + "minimum": 0.0, + "type": "integer" + }, + "lineStart": { + "format": "uint32", + "minimum": 0.0, + "type": "integer" + }, + "note": { + "type": "string" + }, + "path": { + "type": "string" + } + }, + "required": [ + "lineEnd", + "lineStart", + "note", + "path" + ], + "type": "object" + }, "MessagePhase": { "description": "Classifies an assistant message as interim commentary or final answer text.\n\nProviders do not emit this consistently, so callers must treat `None` as \"phase unknown\" and keep compatibility behavior for legacy models.", "oneOf": [ @@ -1038,6 +1086,17 @@ "id": { "type": "string" }, + "memoryCitation": { + "anyOf": [ + { + "$ref": "#/definitions/MemoryCitation" + }, + { + "type": "null" + } + ], + "default": null + }, "phase": { "anyOf": [ { diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadStartedNotification.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadStartedNotification.json index 3eabf9eebc8..a2307578d2d 100644 --- a/codex-rs/app-server-protocol/schema/json/v2/ThreadStartedNotification.json +++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadStartedNotification.json @@ -426,6 +426,54 @@ ], "type": "string" }, + "MemoryCitation": { + "properties": { + "entries": { + "items": { + "$ref": "#/definitions/MemoryCitationEntry" + }, + "type": "array" + }, + "threadIds": { + "items": { + "type": "string" + }, + "type": "array" + } + }, + "required": [ + "entries", + "threadIds" + ], + "type": "object" + }, + "MemoryCitationEntry": { + "properties": { + "lineEnd": { + "format": "uint32", + "minimum": 0.0, + "type": "integer" + }, + "lineStart": { + "format": "uint32", + "minimum": 0.0, + "type": "integer" + }, + "note": { + "type": "string" + }, + "path": { + "type": "string" + } + }, + "required": [ + "lineEnd", + "lineStart", + "note", + "path" + ], + "type": "object" + }, "MessagePhase": { "description": "Classifies an assistant message as interim commentary or final answer text.\n\nProviders do not emit this consistently, so callers must treat `None` as \"phase unknown\" and keep compatibility behavior for legacy models.", "oneOf": [ @@ -796,6 +844,17 @@ "id": { "type": "string" }, + "memoryCitation": { + "anyOf": [ + { + "$ref": "#/definitions/MemoryCitation" + }, + { + "type": "null" + } + ], + "default": null + }, "phase": { "anyOf": [ { diff --git a/codex-rs/app-server-protocol/schema/json/v2/ThreadUnarchiveResponse.json b/codex-rs/app-server-protocol/schema/json/v2/ThreadUnarchiveResponse.json index f6738ff216d..64c00271fb8 100644 --- a/codex-rs/app-server-protocol/schema/json/v2/ThreadUnarchiveResponse.json +++ b/codex-rs/app-server-protocol/schema/json/v2/ThreadUnarchiveResponse.json @@ -426,6 +426,54 @@ ], "type": "string" }, + "MemoryCitation": { + "properties": { + "entries": { + "items": { + "$ref": "#/definitions/MemoryCitationEntry" + }, + "type": "array" + }, + "threadIds": { + "items": { + "type": "string" + }, + "type": "array" + } + }, + "required": [ + "entries", + "threadIds" + ], + "type": "object" + }, + "MemoryCitationEntry": { + "properties": { + "lineEnd": { + "format": "uint32", + "minimum": 0.0, + "type": "integer" + }, + "lineStart": { + "format": "uint32", + "minimum": 0.0, + "type": "integer" + }, + "note": { + "type": "string" + }, + "path": { + "type": "string" + } + }, + "required": [ + "lineEnd", + "lineStart", + "note", + "path" + ], + "type": "object" + }, "MessagePhase": { "description": "Classifies an assistant message as interim commentary or final answer text.\n\nProviders do not emit this consistently, so callers must treat `None` as \"phase unknown\" and keep compatibility behavior for legacy models.", "oneOf": [ @@ -796,6 +844,17 @@ "id": { "type": "string" }, + "memoryCitation": { + "anyOf": [ + { + "$ref": "#/definitions/MemoryCitation" + }, + { + "type": "null" + } + ], + "default": null + }, "phase": { "anyOf": [ { diff --git a/codex-rs/app-server-protocol/schema/json/v2/TurnCompletedNotification.json b/codex-rs/app-server-protocol/schema/json/v2/TurnCompletedNotification.json index 079a81ad047..163d22b6426 100644 --- a/codex-rs/app-server-protocol/schema/json/v2/TurnCompletedNotification.json +++ b/codex-rs/app-server-protocol/schema/json/v2/TurnCompletedNotification.json @@ -403,6 +403,54 @@ ], "type": "string" }, + "MemoryCitation": { + "properties": { + "entries": { + "items": { + "$ref": "#/definitions/MemoryCitationEntry" + }, + "type": "array" + }, + "threadIds": { + "items": { + "type": "string" + }, + "type": "array" + } + }, + "required": [ + "entries", + "threadIds" + ], + "type": "object" + }, + "MemoryCitationEntry": { + "properties": { + "lineEnd": { + "format": "uint32", + "minimum": 0.0, + "type": "integer" + }, + "lineStart": { + "format": "uint32", + "minimum": 0.0, + "type": "integer" + }, + "note": { + "type": "string" + }, + "path": { + "type": "string" + } + }, + "required": [ + "lineEnd", + "lineStart", + "note", + "path" + ], + "type": "object" + }, "MessagePhase": { "description": "Classifies an assistant message as interim commentary or final answer text.\n\nProviders do not emit this consistently, so callers must treat `None` as \"phase unknown\" and keep compatibility behavior for legacy models.", "oneOf": [ @@ -558,6 +606,17 @@ "id": { "type": "string" }, + "memoryCitation": { + "anyOf": [ + { + "$ref": "#/definitions/MemoryCitation" + }, + { + "type": "null" + } + ], + "default": null + }, "phase": { "anyOf": [ { diff --git a/codex-rs/app-server-protocol/schema/json/v2/TurnStartResponse.json b/codex-rs/app-server-protocol/schema/json/v2/TurnStartResponse.json index 17f04c51d8a..9264d98d29c 100644 --- a/codex-rs/app-server-protocol/schema/json/v2/TurnStartResponse.json +++ b/codex-rs/app-server-protocol/schema/json/v2/TurnStartResponse.json @@ -403,6 +403,54 @@ ], "type": "string" }, + "MemoryCitation": { + "properties": { + "entries": { + "items": { + "$ref": "#/definitions/MemoryCitationEntry" + }, + "type": "array" + }, + "threadIds": { + "items": { + "type": "string" + }, + "type": "array" + } + }, + "required": [ + "entries", + "threadIds" + ], + "type": "object" + }, + "MemoryCitationEntry": { + "properties": { + "lineEnd": { + "format": "uint32", + "minimum": 0.0, + "type": "integer" + }, + "lineStart": { + "format": "uint32", + "minimum": 0.0, + "type": "integer" + }, + "note": { + "type": "string" + }, + "path": { + "type": "string" + } + }, + "required": [ + "lineEnd", + "lineStart", + "note", + "path" + ], + "type": "object" + }, "MessagePhase": { "description": "Classifies an assistant message as interim commentary or final answer text.\n\nProviders do not emit this consistently, so callers must treat `None` as \"phase unknown\" and keep compatibility behavior for legacy models.", "oneOf": [ @@ -558,6 +606,17 @@ "id": { "type": "string" }, + "memoryCitation": { + "anyOf": [ + { + "$ref": "#/definitions/MemoryCitation" + }, + { + "type": "null" + } + ], + "default": null + }, "phase": { "anyOf": [ { diff --git a/codex-rs/app-server-protocol/schema/json/v2/TurnStartedNotification.json b/codex-rs/app-server-protocol/schema/json/v2/TurnStartedNotification.json index 59171e42d06..5ed40f55f9b 100644 --- a/codex-rs/app-server-protocol/schema/json/v2/TurnStartedNotification.json +++ b/codex-rs/app-server-protocol/schema/json/v2/TurnStartedNotification.json @@ -403,6 +403,54 @@ ], "type": "string" }, + "MemoryCitation": { + "properties": { + "entries": { + "items": { + "$ref": "#/definitions/MemoryCitationEntry" + }, + "type": "array" + }, + "threadIds": { + "items": { + "type": "string" + }, + "type": "array" + } + }, + "required": [ + "entries", + "threadIds" + ], + "type": "object" + }, + "MemoryCitationEntry": { + "properties": { + "lineEnd": { + "format": "uint32", + "minimum": 0.0, + "type": "integer" + }, + "lineStart": { + "format": "uint32", + "minimum": 0.0, + "type": "integer" + }, + "note": { + "type": "string" + }, + "path": { + "type": "string" + } + }, + "required": [ + "lineEnd", + "lineStart", + "note", + "path" + ], + "type": "object" + }, "MessagePhase": { "description": "Classifies an assistant message as interim commentary or final answer text.\n\nProviders do not emit this consistently, so callers must treat `None` as \"phase unknown\" and keep compatibility behavior for legacy models.", "oneOf": [ @@ -558,6 +606,17 @@ "id": { "type": "string" }, + "memoryCitation": { + "anyOf": [ + { + "$ref": "#/definitions/MemoryCitation" + }, + { + "type": "null" + } + ], + "default": null + }, "phase": { "anyOf": [ { diff --git a/codex-rs/app-server-protocol/schema/typescript/v2/MemoryCitation.ts b/codex-rs/app-server-protocol/schema/typescript/v2/MemoryCitation.ts new file mode 100644 index 00000000000..7657e29f8bf --- /dev/null +++ b/codex-rs/app-server-protocol/schema/typescript/v2/MemoryCitation.ts @@ -0,0 +1,6 @@ +// GENERATED CODE! DO NOT MODIFY BY HAND! + +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { MemoryCitationEntry } from "./MemoryCitationEntry"; + +export type MemoryCitation = { entries: Array, threadIds: Array, }; diff --git a/codex-rs/app-server-protocol/schema/typescript/v2/MemoryCitationEntry.ts b/codex-rs/app-server-protocol/schema/typescript/v2/MemoryCitationEntry.ts new file mode 100644 index 00000000000..9b9ce17267f --- /dev/null +++ b/codex-rs/app-server-protocol/schema/typescript/v2/MemoryCitationEntry.ts @@ -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 MemoryCitationEntry = { path: string, lineStart: number, lineEnd: number, note: string, }; diff --git a/codex-rs/app-server-protocol/schema/typescript/v2/ThreadItem.ts b/codex-rs/app-server-protocol/schema/typescript/v2/ThreadItem.ts index bcc81c02515..51ab9e88122 100644 --- a/codex-rs/app-server-protocol/schema/typescript/v2/ThreadItem.ts +++ b/codex-rs/app-server-protocol/schema/typescript/v2/ThreadItem.ts @@ -15,11 +15,12 @@ import type { FileUpdateChange } from "./FileUpdateChange"; import type { McpToolCallError } from "./McpToolCallError"; import type { McpToolCallResult } from "./McpToolCallResult"; import type { McpToolCallStatus } from "./McpToolCallStatus"; +import type { MemoryCitation } from "./MemoryCitation"; import type { PatchApplyStatus } from "./PatchApplyStatus"; import type { UserInput } from "./UserInput"; import type { WebSearchAction } from "./WebSearchAction"; -export type ThreadItem = { "type": "userMessage", id: string, content: Array, } | { "type": "agentMessage", id: string, text: string, phase: MessagePhase | null, } | { "type": "plan", id: string, text: string, } | { "type": "reasoning", id: string, summary: Array, content: Array, } | { "type": "commandExecution", id: string, +export type ThreadItem = { "type": "userMessage", id: string, content: Array, } | { "type": "agentMessage", id: string, text: string, phase: MessagePhase | null, memoryCitation: MemoryCitation | null, } | { "type": "plan", id: string, text: string, } | { "type": "reasoning", id: string, summary: Array, content: Array, } | { "type": "commandExecution", id: string, /** * The command to be executed. */ diff --git a/codex-rs/app-server-protocol/schema/typescript/v2/index.ts b/codex-rs/app-server-protocol/schema/typescript/v2/index.ts index 1529bbea881..c5ebe10103d 100644 --- a/codex-rs/app-server-protocol/schema/typescript/v2/index.ts +++ b/codex-rs/app-server-protocol/schema/typescript/v2/index.ts @@ -175,6 +175,8 @@ export type { McpToolCallError } from "./McpToolCallError"; export type { McpToolCallProgressNotification } from "./McpToolCallProgressNotification"; export type { McpToolCallResult } from "./McpToolCallResult"; export type { McpToolCallStatus } from "./McpToolCallStatus"; +export type { MemoryCitation } from "./MemoryCitation"; +export type { MemoryCitationEntry } from "./MemoryCitationEntry"; export type { MergeStrategy } from "./MergeStrategy"; export type { Model } from "./Model"; export type { ModelAvailabilityNux } from "./ModelAvailabilityNux"; diff --git a/codex-rs/app-server-protocol/src/protocol/thread_history.rs b/codex-rs/app-server-protocol/src/protocol/thread_history.rs index 9866459c664..e46cc0307ae 100644 --- a/codex-rs/app-server-protocol/src/protocol/thread_history.rs +++ b/codex-rs/app-server-protocol/src/protocol/thread_history.rs @@ -118,9 +118,11 @@ impl ThreadHistoryBuilder { pub fn handle_event(&mut self, event: &EventMsg) { match event { EventMsg::UserMessage(payload) => self.handle_user_message(payload), - EventMsg::AgentMessage(payload) => { - self.handle_agent_message(payload.message.clone(), payload.phase.clone()) - } + EventMsg::AgentMessage(payload) => self.handle_agent_message( + payload.message.clone(), + payload.phase.clone(), + payload.memory_citation.clone().map(Into::into), + ), EventMsg::AgentReasoning(payload) => self.handle_agent_reasoning(payload), EventMsg::AgentReasoningRawContent(payload) => { self.handle_agent_reasoning_raw_content(payload) @@ -208,15 +210,23 @@ impl ThreadHistoryBuilder { self.current_turn = Some(turn); } - fn handle_agent_message(&mut self, text: String, phase: Option) { + fn handle_agent_message( + &mut self, + text: String, + phase: Option, + memory_citation: Option, + ) { if text.is_empty() { return; } let id = self.next_item_id(); - self.ensure_turn() - .items - .push(ThreadItem::AgentMessage { id, text, phase }); + self.ensure_turn().items.push(ThreadItem::AgentMessage { + id, + text, + phase, + memory_citation, + }); } fn handle_agent_reasoning(&mut self, payload: &AgentReasoningEvent) { @@ -1178,6 +1188,7 @@ mod tests { EventMsg::AgentMessage(AgentMessageEvent { message: "Hi there".into(), phase: None, + memory_citation: None, }), EventMsg::AgentReasoning(AgentReasoningEvent { text: "thinking".into(), @@ -1194,6 +1205,7 @@ mod tests { EventMsg::AgentMessage(AgentMessageEvent { message: "Reply two".into(), phase: None, + memory_citation: None, }), ]; @@ -1229,6 +1241,7 @@ mod tests { id: "item-2".into(), text: "Hi there".into(), phase: None, + memory_citation: None, } ); assert_eq!( @@ -1260,6 +1273,7 @@ mod tests { id: "item-5".into(), text: "Reply two".into(), phase: None, + memory_citation: None, } ); } @@ -1318,6 +1332,7 @@ mod tests { let events = vec![EventMsg::AgentMessage(AgentMessageEvent { message: "Final reply".into(), phase: Some(CoreMessagePhase::FinalAnswer), + memory_citation: None, })]; let items = events @@ -1332,6 +1347,7 @@ mod tests { id: "item-1".into(), text: "Final reply".into(), phase: Some(MessagePhase::FinalAnswer), + memory_citation: None, } ); } @@ -1354,6 +1370,7 @@ mod tests { EventMsg::AgentMessage(AgentMessageEvent { message: "interlude".into(), phase: None, + memory_citation: None, }), EventMsg::AgentReasoning(AgentReasoningEvent { text: "second summary".into(), @@ -1399,6 +1416,7 @@ mod tests { EventMsg::AgentMessage(AgentMessageEvent { message: "Working...".into(), phase: None, + memory_citation: None, }), EventMsg::TurnAborted(TurnAbortedEvent { turn_id: Some("turn-1".into()), @@ -1413,6 +1431,7 @@ mod tests { EventMsg::AgentMessage(AgentMessageEvent { message: "Second attempt complete.".into(), phase: None, + memory_citation: None, }), ]; @@ -1442,6 +1461,7 @@ mod tests { id: "item-2".into(), text: "Working...".into(), phase: None, + memory_citation: None, } ); @@ -1464,6 +1484,7 @@ mod tests { id: "item-4".into(), text: "Second attempt complete.".into(), phase: None, + memory_citation: None, } ); } @@ -1480,6 +1501,7 @@ mod tests { EventMsg::AgentMessage(AgentMessageEvent { message: "A1".into(), phase: None, + memory_citation: None, }), EventMsg::UserMessage(UserMessageEvent { message: "Second".into(), @@ -1490,6 +1512,7 @@ mod tests { EventMsg::AgentMessage(AgentMessageEvent { message: "A2".into(), phase: None, + memory_citation: None, }), EventMsg::ThreadRolledBack(ThreadRolledBackEvent { num_turns: 1 }), EventMsg::UserMessage(UserMessageEvent { @@ -1501,6 +1524,7 @@ mod tests { EventMsg::AgentMessage(AgentMessageEvent { message: "A3".into(), phase: None, + memory_citation: None, }), ]; @@ -1529,6 +1553,7 @@ mod tests { id: "item-2".into(), text: "A1".into(), phase: None, + memory_citation: None, }, ] ); @@ -1546,6 +1571,7 @@ mod tests { id: "item-4".into(), text: "A3".into(), phase: None, + memory_citation: None, }, ] ); @@ -1563,6 +1589,7 @@ mod tests { EventMsg::AgentMessage(AgentMessageEvent { message: "A1".into(), phase: None, + memory_citation: None, }), EventMsg::UserMessage(UserMessageEvent { message: "Two".into(), @@ -1573,6 +1600,7 @@ mod tests { EventMsg::AgentMessage(AgentMessageEvent { message: "A2".into(), phase: None, + memory_citation: None, }), EventMsg::ThreadRolledBack(ThreadRolledBackEvent { num_turns: 99 }), ]; @@ -2209,6 +2237,7 @@ mod tests { EventMsg::AgentMessage(AgentMessageEvent { message: "still in b".into(), phase: None, + memory_citation: None, }), EventMsg::TurnComplete(TurnCompleteEvent { turn_id: "turn-b".into(), @@ -2263,6 +2292,7 @@ mod tests { EventMsg::AgentMessage(AgentMessageEvent { message: "still in b".into(), phase: None, + memory_citation: None, }), ]; @@ -2497,6 +2527,7 @@ mod tests { EventMsg::AgentMessage(AgentMessageEvent { message: "done".into(), phase: None, + memory_citation: None, }), EventMsg::Error(ErrorEvent { message: "rollback failed".into(), diff --git a/codex-rs/app-server-protocol/src/protocol/v2.rs b/codex-rs/app-server-protocol/src/protocol/v2.rs index e2316d8e788..afbbda2caee 100644 --- a/codex-rs/app-server-protocol/src/protocol/v2.rs +++ b/codex-rs/app-server-protocol/src/protocol/v2.rs @@ -30,6 +30,8 @@ use codex_protocol::items::TurnItem as CoreTurnItem; use codex_protocol::mcp::Resource as McpResource; use codex_protocol::mcp::ResourceTemplate as McpResourceTemplate; use codex_protocol::mcp::Tool as McpTool; +use codex_protocol::memory_citation::MemoryCitation as CoreMemoryCitation; +use codex_protocol::memory_citation::MemoryCitationEntry as CoreMemoryCitationEntry; use codex_protocol::models::FileSystemPermissions as CoreFileSystemPermissions; use codex_protocol::models::MacOsAutomationPermission as CoreMacOsAutomationPermission; use codex_protocol::models::MacOsContactsPermission as CoreMacOsContactsPermission; @@ -3634,6 +3636,44 @@ pub struct Turn { pub error: Option, } +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export_to = "v2/")] +pub struct MemoryCitation { + pub entries: Vec, + pub thread_ids: Vec, +} + +impl From for MemoryCitation { + fn from(value: CoreMemoryCitation) -> Self { + Self { + entries: value.entries.into_iter().map(Into::into).collect(), + thread_ids: value.rollout_ids, + } + } +} + +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export_to = "v2/")] +pub struct MemoryCitationEntry { + pub path: String, + pub line_start: u32, + pub line_end: u32, + pub note: String, +} + +impl From for MemoryCitationEntry { + fn from(value: CoreMemoryCitationEntry) -> Self { + Self { + path: value.path, + line_start: value.line_start, + line_end: value.line_end, + note: value.note, + } + } +} + #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS, Error)] #[serde(rename_all = "camelCase")] #[ts(export_to = "v2/")] @@ -4133,6 +4173,8 @@ pub enum ThreadItem { text: String, #[serde(default)] phase: Option, + #[serde(default)] + memory_citation: Option, }, #[serde(rename_all = "camelCase")] #[ts(rename_all = "camelCase")] @@ -4382,6 +4424,7 @@ impl From for ThreadItem { id: agent.id, text, phase: agent.phase, + memory_citation: agent.memory_citation.map(Into::into), } } CoreTurnItem::Plan(plan) => ThreadItem::Plan { @@ -7458,6 +7501,7 @@ mod tests { }, ], phase: None, + memory_citation: None, }); assert_eq!( @@ -7466,6 +7510,7 @@ mod tests { id: "agent-1".to_string(), text: "Hello world".to_string(), phase: None, + memory_citation: None, } ); @@ -7475,6 +7520,15 @@ mod tests { text: "final".to_string(), }], phase: Some(MessagePhase::FinalAnswer), + memory_citation: Some(CoreMemoryCitation { + entries: vec![CoreMemoryCitationEntry { + path: "MEMORY.md".to_string(), + line_start: 1, + line_end: 2, + note: "summary".to_string(), + }], + rollout_ids: vec!["rollout-1".to_string()], + }), }); assert_eq!( @@ -7483,6 +7537,15 @@ mod tests { id: "agent-2".to_string(), text: "final".to_string(), phase: Some(MessagePhase::FinalAnswer), + memory_citation: Some(MemoryCitation { + entries: vec![MemoryCitationEntry { + path: "MEMORY.md".to_string(), + line_start: 1, + line_end: 2, + note: "summary".to_string(), + }], + thread_ids: vec!["rollout-1".to_string()], + }), } ); diff --git a/codex-rs/app-server/tests/suite/v2/thread_resume.rs b/codex-rs/app-server/tests/suite/v2/thread_resume.rs index 27803db42cc..5cbcd3b25d2 100644 --- a/codex-rs/app-server/tests/suite/v2/thread_resume.rs +++ b/codex-rs/app-server/tests/suite/v2/thread_resume.rs @@ -450,6 +450,7 @@ async fn thread_resume_and_read_interrupt_incomplete_rollout_turn_when_thread_is "payload": serde_json::to_value(EventMsg::AgentMessage(AgentMessageEvent { message: "Still running".to_string(), phase: None, + memory_citation: None, }))?, }) .to_string(), diff --git a/codex-rs/core/config.schema.json b/codex-rs/core/config.schema.json index 7d3ecdaa012..654e9039ac1 100644 --- a/codex-rs/core/config.schema.json +++ b/codex-rs/core/config.schema.json @@ -2479,4 +2479,4 @@ }, "title": "ConfigToml", "type": "object" -} +} \ No newline at end of file diff --git a/codex-rs/core/src/codex.rs b/codex-rs/core/src/codex.rs index 8ffe1d3bd1e..6e3b6bf76e5 100644 --- a/codex-rs/core/src/codex.rs +++ b/codex-rs/core/src/codex.rs @@ -6939,6 +6939,7 @@ async fn emit_agent_message_in_plan_mode( id: agent_message_id.clone(), content: Vec::new(), phase: None, + memory_citation: None, }) }); sess.emit_turn_item_started(turn_context, &start_item).await; diff --git a/codex-rs/core/src/event_mapping.rs b/codex-rs/core/src/event_mapping.rs index 72372b24cd8..7a9cdb39063 100644 --- a/codex-rs/core/src/event_mapping.rs +++ b/codex-rs/core/src/event_mapping.rs @@ -83,7 +83,12 @@ fn parse_agent_message( } } let id = id.cloned().unwrap_or_else(|| Uuid::new_v4().to_string()); - AgentMessageItem { id, content, phase } + AgentMessageItem { + id, + content, + phase, + memory_citation: None, + } } pub fn parse_turn_item(item: &ResponseItem) -> Option { diff --git a/codex-rs/core/src/memories/citations.rs b/codex-rs/core/src/memories/citations.rs index ed620e853b5..d8642880f1b 100644 --- a/codex-rs/core/src/memories/citations.rs +++ b/codex-rs/core/src/memories/citations.rs @@ -1,36 +1,89 @@ use codex_protocol::ThreadId; +use codex_protocol::memory_citation::MemoryCitation; +use codex_protocol::memory_citation::MemoryCitationEntry; +use std::collections::HashSet; + +pub fn parse_memory_citation(citations: Vec) -> Option { + let mut entries = Vec::new(); + let mut rollout_ids = Vec::new(); + let mut seen_rollout_ids = HashSet::new(); -pub fn get_thread_id_from_citations(citations: Vec) -> Vec { - let mut result = Vec::new(); for citation in citations { - let mut ids_block = None; - for (open, close) in [ - ("", ""), - ("", ""), - ] { - if let Some((_, rest)) = citation.split_once(open) - && let Some((ids, _)) = rest.split_once(close) - { - ids_block = Some(ids); - break; - } + if let Some(entries_block) = + extract_block(&citation, "", "") + { + entries.extend( + entries_block + .lines() + .filter_map(parse_memory_citation_entry), + ); } - if let Some(ids_block) = ids_block { + if let Some(ids_block) = extract_ids_block(&citation) { for id in ids_block .lines() .map(str::trim) .filter(|line| !line.is_empty()) { - if let Ok(thread_id) = ThreadId::try_from(id) { - result.push(thread_id); + if seen_rollout_ids.insert(id.to_string()) { + rollout_ids.push(id.to_string()); } } } } + + if entries.is_empty() && rollout_ids.is_empty() { + None + } else { + Some(MemoryCitation { + entries, + rollout_ids, + }) + } +} + +pub fn get_thread_id_from_citations(citations: Vec) -> Vec { + let mut result = Vec::new(); + if let Some(memory_citation) = parse_memory_citation(citations) { + for rollout_id in memory_citation.rollout_ids { + if let Ok(thread_id) = ThreadId::try_from(rollout_id.as_str()) { + result.push(thread_id); + } + } + } result } +fn parse_memory_citation_entry(line: &str) -> Option { + let line = line.trim(); + if line.is_empty() { + return None; + } + + let (location, note) = line.rsplit_once("|note=[")?; + let note = note.strip_suffix(']')?.trim().to_string(); + let (path, line_range) = location.rsplit_once(':')?; + let (line_start, line_end) = line_range.split_once('-')?; + + Some(MemoryCitationEntry { + path: path.trim().to_string(), + line_start: line_start.trim().parse().ok()?, + line_end: line_end.trim().parse().ok()?, + note, + }) +} + +fn extract_block<'a>(text: &'a str, open: &str, close: &str) -> Option<&'a str> { + let (_, rest) = text.split_once(open)?; + let (body, _) = rest.split_once(close)?; + Some(body) +} + +fn extract_ids_block(text: &str) -> Option<&str> { + extract_block(text, "", "") + .or_else(|| extract_block(text, "", "")) +} + #[cfg(test)] #[path = "citations_tests.rs"] mod tests; diff --git a/codex-rs/core/src/memories/citations_tests.rs b/codex-rs/core/src/memories/citations_tests.rs index b6783dea7cf..49d4a674307 100644 --- a/codex-rs/core/src/memories/citations_tests.rs +++ b/codex-rs/core/src/memories/citations_tests.rs @@ -1,4 +1,5 @@ use super::get_thread_id_from_citations; +use super::parse_memory_citation; use codex_protocol::ThreadId; use pretty_assertions::assert_eq; @@ -24,3 +25,40 @@ fn get_thread_id_from_citations_supports_legacy_rollout_ids() { assert_eq!(get_thread_id_from_citations(citations), vec![thread_id]); } + +#[test] +fn parse_memory_citation_extracts_entries_and_rollout_ids() { + let first = ThreadId::new(); + let second = ThreadId::new(); + let citations = vec![format!( + "\nMEMORY.md:1-2|note=[summary]\nrollout_summaries/foo.md:10-12|note=[details]\n\n\n{first}\n{second}\n{first}\n" + )]; + + let parsed = parse_memory_citation(citations).expect("memory citation should parse"); + + assert_eq!( + parsed + .entries + .iter() + .map(|entry| ( + entry.path.clone(), + entry.line_start, + entry.line_end, + entry.note.clone(), + )) + .collect::>(), + vec![ + ("MEMORY.md".to_string(), 1, 2, "summary".to_string()), + ( + "rollout_summaries/foo.md".to_string(), + 10, + 12, + "details".to_string() + ), + ] + ); + assert_eq!( + parsed.rollout_ids, + vec![first.to_string(), second.to_string()] + ); +} diff --git a/codex-rs/core/src/rollout/recorder_tests.rs b/codex-rs/core/src/rollout/recorder_tests.rs index f6f588574a7..dbe11ac9f79 100644 --- a/codex-rs/core/src/rollout/recorder_tests.rs +++ b/codex-rs/core/src/rollout/recorder_tests.rs @@ -85,6 +85,7 @@ async fn recorder_materializes_only_after_explicit_persist() -> std::io::Result< AgentMessageEvent { message: "buffered-event".to_string(), phase: None, + memory_citation: None, }, ))]) .await?; @@ -201,6 +202,7 @@ async fn metadata_irrelevant_events_touch_state_db_updated_at() -> std::io::Resu AgentMessageEvent { message: "assistant text".to_string(), phase: None, + memory_citation: None, }, ))]) .await?; @@ -251,6 +253,7 @@ async fn metadata_irrelevant_events_fall_back_to_upsert_when_thread_missing() -> AgentMessageEvent { message: "assistant text".to_string(), phase: None, + memory_citation: None, }, ))]; diff --git a/codex-rs/core/src/stream_events_utils.rs b/codex-rs/core/src/stream_events_utils.rs index a44bc01f55d..084cb4b1a36 100644 --- a/codex-rs/core/src/stream_events_utils.rs +++ b/codex-rs/core/src/stream_events_utils.rs @@ -15,6 +15,7 @@ use crate::error::CodexErr; use crate::error::Result; use crate::function_tool::FunctionCallError; use crate::memories::citations::get_thread_id_from_citations; +use crate::memories::citations::parse_memory_citation; use crate::parse_turn_item; use crate::state_db; use crate::tools::parallel::ToolCallRuntime; @@ -38,6 +39,22 @@ fn strip_hidden_assistant_markup(text: &str, plan_mode: bool) -> String { } } +fn strip_hidden_assistant_markup_and_parse_memory_citation( + text: &str, + plan_mode: bool, +) -> ( + String, + Option, +) { + let (without_citations, citations) = strip_citations(text); + let visible_text = if plan_mode { + strip_proposed_plan_blocks(&without_citations) + } else { + without_citations + }; + (visible_text, parse_memory_citation(citations)) +} + pub(crate) fn raw_assistant_output_text_from_item(item: &ResponseItem) -> Option { if let ResponseItem::Message { role, content, .. } = item && role == "assistant" @@ -297,9 +314,11 @@ pub(crate) async fn handle_non_tool_response_item( codex_protocol::items::AgentMessageContent::Text { text } => text.as_str(), }) .collect::(); - let stripped = strip_hidden_assistant_markup(&combined, plan_mode); + let (stripped, memory_citation) = + strip_hidden_assistant_markup_and_parse_memory_citation(&combined, plan_mode); agent_message.content = vec![codex_protocol::items::AgentMessageContent::Text { text: stripped }]; + agent_message.memory_citation = memory_citation; } if let TurnItem::ImageGeneration(image_item) = &mut turn_item { match save_image_generation_result(&image_item.id, &image_item.result).await { diff --git a/codex-rs/core/src/stream_events_utils_tests.rs b/codex-rs/core/src/stream_events_utils_tests.rs index bfebb8902c5..389f01ec716 100644 --- a/codex-rs/core/src/stream_events_utils_tests.rs +++ b/codex-rs/core/src/stream_events_utils_tests.rs @@ -23,7 +23,9 @@ fn assistant_output_text(text: &str) -> ResponseItem { #[tokio::test] async fn handle_non_tool_response_item_strips_citations_from_assistant_message() { let (session, turn_context) = make_session_and_context().await; - let item = assistant_output_text("hellodoc1 world"); + let item = assistant_output_text( + "hello\nMEMORY.md:1-2|note=[x]\n\n\n019cc2ea-1dff-7902-8d40-c8f6e5d83cc4\n world", + ); let turn_item = handle_non_tool_response_item(&session, &turn_context, &item, false) .await @@ -40,6 +42,15 @@ async fn handle_non_tool_response_item_strips_citations_from_assistant_message() }) .collect::(); assert_eq!(text, "hello world"); + let memory_citation = agent_message + .memory_citation + .expect("memory citation should be parsed"); + assert_eq!(memory_citation.entries.len(), 1); + assert_eq!(memory_citation.entries[0].path, "MEMORY.md"); + assert_eq!( + memory_citation.rollout_ids, + vec!["019cc2ea-1dff-7902-8d40-c8f6e5d83cc4".to_string()] + ); } #[test] diff --git a/codex-rs/core/src/turn_timing_tests.rs b/codex-rs/core/src/turn_timing_tests.rs index 4f292b40dc6..934b6ed30a3 100644 --- a/codex-rs/core/src/turn_timing_tests.rs +++ b/codex-rs/core/src/turn_timing_tests.rs @@ -58,6 +58,7 @@ async fn turn_timing_state_records_ttfm_independently_of_ttft() { id: "msg-1".to_string(), content: Vec::new(), phase: None, + memory_citation: None, })) .await .is_some() @@ -68,6 +69,7 @@ async fn turn_timing_state_records_ttfm_independently_of_ttft() { id: "msg-2".to_string(), content: Vec::new(), phase: None, + memory_citation: None, })) .await, None diff --git a/codex-rs/exec/tests/event_processor_with_json_output.rs b/codex-rs/exec/tests/event_processor_with_json_output.rs index 63e28f222e1..e9f295337e3 100644 --- a/codex-rs/exec/tests/event_processor_with_json_output.rs +++ b/codex-rs/exec/tests/event_processor_with_json_output.rs @@ -749,6 +749,7 @@ fn agent_message_produces_item_completed_agent_message() { EventMsg::AgentMessage(AgentMessageEvent { message: "hello".to_string(), phase: None, + memory_citation: None, }), ); let out = ep.collect_thread_events(&ev); diff --git a/codex-rs/protocol/src/items.rs b/codex-rs/protocol/src/items.rs index f200fe6f752..08e50b9546a 100644 --- a/codex-rs/protocol/src/items.rs +++ b/codex-rs/protocol/src/items.rs @@ -1,3 +1,4 @@ +use crate::memory_citation::MemoryCitation; use crate::models::MessagePhase; use crate::models::WebSearchAction; use crate::protocol::AgentMessageEvent; @@ -58,6 +59,9 @@ pub struct AgentMessageItem { #[serde(default, skip_serializing_if = "Option::is_none")] #[ts(optional)] pub phase: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + #[ts(optional)] + pub memory_citation: Option, } #[derive(Debug, Clone, Deserialize, Serialize, TS, JsonSchema)] @@ -201,6 +205,7 @@ impl AgentMessageItem { id: uuid::Uuid::new_v4().to_string(), content: content.to_vec(), phase: None, + memory_citation: None, } } @@ -211,6 +216,7 @@ impl AgentMessageItem { AgentMessageContent::Text { text } => EventMsg::AgentMessage(AgentMessageEvent { message: text.clone(), phase: self.phase.clone(), + memory_citation: self.memory_citation.clone(), }), }) .collect() diff --git a/codex-rs/protocol/src/lib.rs b/codex-rs/protocol/src/lib.rs index d6adf2c5858..08466ba4ea7 100644 --- a/codex-rs/protocol/src/lib.rs +++ b/codex-rs/protocol/src/lib.rs @@ -7,6 +7,7 @@ pub mod custom_prompts; pub mod dynamic_tools; pub mod items; pub mod mcp; +pub mod memory_citation; pub mod message_history; pub mod models; pub mod num_format; diff --git a/codex-rs/protocol/src/memory_citation.rs b/codex-rs/protocol/src/memory_citation.rs new file mode 100644 index 00000000000..6706aea774a --- /dev/null +++ b/codex-rs/protocol/src/memory_citation.rs @@ -0,0 +1,20 @@ +use schemars::JsonSchema; +use serde::Deserialize; +use serde::Serialize; +use ts_rs::TS; + +#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq, JsonSchema, TS)] +#[serde(rename_all = "camelCase")] +pub struct MemoryCitation { + pub entries: Vec, + pub rollout_ids: Vec, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, JsonSchema, TS)] +#[serde(rename_all = "camelCase")] +pub struct MemoryCitationEntry { + pub path: String, + pub line_start: u32, + pub line_end: u32, + pub note: String, +} diff --git a/codex-rs/protocol/src/protocol.rs b/codex-rs/protocol/src/protocol.rs index daf3b7d74a3..f1e9eac0d22 100644 --- a/codex-rs/protocol/src/protocol.rs +++ b/codex-rs/protocol/src/protocol.rs @@ -32,6 +32,7 @@ use crate::mcp::RequestId; use crate::mcp::Resource as McpResource; use crate::mcp::ResourceTemplate as McpResourceTemplate; use crate::mcp::Tool as McpTool; +use crate::memory_citation::MemoryCitation; use crate::message_history::HistoryEntry; use crate::models::BaseInstructions; use crate::models::ContentItem; @@ -2004,6 +2005,8 @@ pub struct AgentMessageEvent { pub message: String, #[serde(default)] pub phase: Option, + #[serde(default)] + pub memory_citation: Option, } #[derive(Debug, Clone, Deserialize, Serialize, JsonSchema, TS)] diff --git a/codex-rs/tui/src/chatwidget/tests.rs b/codex-rs/tui/src/chatwidget/tests.rs index ffc571288a3..b7c5486b1fe 100644 --- a/codex-rs/tui/src/chatwidget/tests.rs +++ b/codex-rs/tui/src/chatwidget/tests.rs @@ -199,6 +199,7 @@ async fn resumed_initial_messages_render_history() { EventMsg::AgentMessage(AgentMessageEvent { message: "assistant reply".to_string(), phase: None, + memory_citation: None, }), ]), network_proxy: None, @@ -247,6 +248,7 @@ async fn thread_snapshot_replay_does_not_duplicate_agent_message_history() { text: "assistant reply".to_string(), }], phase: None, + memory_citation: None, }), }), }); @@ -255,6 +257,7 @@ async fn thread_snapshot_replay_does_not_duplicate_agent_message_history() { msg: EventMsg::AgentMessage(AgentMessageEvent { message: "assistant reply".to_string(), phase: None, + memory_citation: None, }), }); @@ -1543,6 +1546,7 @@ async fn live_agent_message_renders_during_review_mode() { msg: EventMsg::AgentMessage(AgentMessageEvent { message: "Review progress update".to_string(), phase: None, + memory_citation: None, }), }); @@ -1569,6 +1573,7 @@ async fn thread_snapshot_replay_preserves_agent_message_during_review_mode() { msg: EventMsg::AgentMessage(AgentMessageEvent { message: "Review progress update".to_string(), phase: None, + memory_citation: None, }), }); @@ -3532,6 +3537,7 @@ fn complete_assistant_message( text: text.to_string(), }], phase, + memory_citation: None, }), }), }); @@ -4127,6 +4133,7 @@ async fn live_legacy_agent_message_after_item_completed_does_not_duplicate_assis msg: EventMsg::AgentMessage(AgentMessageEvent { message: "hello".into(), phase: Some(MessagePhase::FinalAnswer), + memory_citation: None, }), }); @@ -5933,6 +5940,7 @@ async fn slash_copy_is_unavailable_when_legacy_agent_message_is_not_repeated_on_ msg: EventMsg::AgentMessage(AgentMessageEvent { message: "Legacy final message".into(), phase: None, + memory_citation: None, }), }); let _ = drain_insert_history(&mut rx); @@ -10684,6 +10692,7 @@ async fn deltas_then_same_final_message_are_rendered_snapshot() { msg: EventMsg::AgentMessage(AgentMessageEvent { message: "Here is the result.".into(), phase: None, + memory_citation: None, }), }); diff --git a/codex-rs/tui_app_server/src/app.rs b/codex-rs/tui_app_server/src/app.rs index c08e74c3374..077a04e4d09 100644 --- a/codex-rs/tui_app_server/src/app.rs +++ b/codex-rs/tui_app_server/src/app.rs @@ -6770,6 +6770,7 @@ guardian_approval = true id: "assistant-1".to_string(), text: "restored response".to_string(), phase: None, + memory_citation: None, }, ], status: TurnStatus::Completed, @@ -6883,6 +6884,7 @@ guardian_approval = true id: "assistant-1".to_string(), text: "restored response".to_string(), phase: None, + memory_citation: None, }, ], status: TurnStatus::Completed, diff --git a/codex-rs/tui_app_server/src/app/app_server_adapter.rs b/codex-rs/tui_app_server/src/app/app_server_adapter.rs index 0fff49fd20c..3fef2eda8f6 100644 --- a/codex-rs/tui_app_server/src/app/app_server_adapter.rs +++ b/codex-rs/tui_app_server/src/app/app_server_adapter.rs @@ -568,13 +568,33 @@ fn thread_item_to_core(item: &ThreadItem) -> Option { .map(codex_app_server_protocol::UserInput::into_core) .collect(), })), - ThreadItem::AgentMessage { id, text, phase } => { - Some(TurnItem::AgentMessage(AgentMessageItem { - id: id.clone(), - content: vec![AgentMessageContent::Text { text: text.clone() }], - phase: phase.clone(), - })) - } + ThreadItem::AgentMessage { + id, + text, + phase, + memory_citation, + } => Some(TurnItem::AgentMessage(AgentMessageItem { + id: id.clone(), + content: vec![AgentMessageContent::Text { text: text.clone() }], + phase: phase.clone(), + memory_citation: memory_citation.clone().map(|citation| { + codex_protocol::memory_citation::MemoryCitation { + entries: citation + .entries + .into_iter() + .map( + |entry| codex_protocol::memory_citation::MemoryCitationEntry { + path: entry.path, + line_start: entry.line_start, + line_end: entry.line_end, + note: entry.note, + }, + ) + .collect(), + rollout_ids: citation.thread_ids, + } + }), + })), ThreadItem::Plan { id, text } => Some(TurnItem::Plan(PlanItem { id: id.clone(), text: text.clone(), @@ -690,6 +710,7 @@ mod tests { id: item_id, text: "Hello from your coding assistant.".to_string(), phase: Some(MessagePhase::FinalAnswer), + memory_citation: None, }, thread_id: thread_id.clone(), turn_id: turn_id.clone(), @@ -714,13 +735,19 @@ mod tests { ); assert_eq!(completed.turn_id, turn_id); match &completed.item { - TurnItem::AgentMessage(AgentMessageItem { id, content, phase }) => { + TurnItem::AgentMessage(AgentMessageItem { + id, + content, + phase, + memory_citation, + }) => { assert_eq!(id, "msg_123"); let [AgentMessageContent::Text { text }] = content.as_slice() else { panic!("expected a single text content item"); }; assert_eq!(text, "Hello from your coding assistant."); assert_eq!(*phase, Some(MessagePhase::FinalAnswer)); + assert_eq!(*memory_citation, None); } _ => panic!("expected bridged agent message item"), } @@ -904,6 +931,7 @@ mod tests { id: "assistant-1".to_string(), text: "hi".to_string(), phase: Some(MessagePhase::FinalAnswer), + memory_citation: None, }, ], status: TurnStatus::Completed, diff --git a/codex-rs/tui_app_server/src/app_server_session.rs b/codex-rs/tui_app_server/src/app_server_session.rs index 514005193be..276777994c1 100644 --- a/codex-rs/tui_app_server/src/app_server_session.rs +++ b/codex-rs/tui_app_server/src/app_server_session.rs @@ -1117,6 +1117,7 @@ mod tests { id: "assistant-1".to_string(), text: "assistant reply".to_string(), phase: None, + memory_citation: None, }, ], status: TurnStatus::Completed, diff --git a/codex-rs/tui_app_server/src/chatwidget/tests.rs b/codex-rs/tui_app_server/src/chatwidget/tests.rs index 6468e3de477..ceab56434d7 100644 --- a/codex-rs/tui_app_server/src/chatwidget/tests.rs +++ b/codex-rs/tui_app_server/src/chatwidget/tests.rs @@ -198,6 +198,7 @@ async fn resumed_initial_messages_render_history() { EventMsg::AgentMessage(AgentMessageEvent { message: "assistant reply".to_string(), phase: None, + memory_citation: None, }), ]), network_proxy: None, @@ -246,6 +247,7 @@ async fn thread_snapshot_replay_does_not_duplicate_agent_message_history() { text: "assistant reply".to_string(), }], phase: None, + memory_citation: None, }), }), }); @@ -254,6 +256,7 @@ async fn thread_snapshot_replay_does_not_duplicate_agent_message_history() { msg: EventMsg::AgentMessage(AgentMessageEvent { message: "assistant reply".to_string(), phase: None, + memory_citation: None, }), }); @@ -1542,6 +1545,7 @@ async fn live_agent_message_renders_during_review_mode() { msg: EventMsg::AgentMessage(AgentMessageEvent { message: "Review progress update".to_string(), phase: None, + memory_citation: None, }), }); @@ -1568,6 +1572,7 @@ async fn thread_snapshot_replay_preserves_agent_message_during_review_mode() { msg: EventMsg::AgentMessage(AgentMessageEvent { message: "Review progress update".to_string(), phase: None, + memory_citation: None, }), }); @@ -3502,6 +3507,7 @@ fn complete_assistant_message( text: text.to_string(), }], phase, + memory_citation: None, }), }), }); @@ -4091,6 +4097,7 @@ async fn live_legacy_agent_message_after_item_completed_does_not_duplicate_assis msg: EventMsg::AgentMessage(AgentMessageEvent { message: "hello".into(), phase: Some(MessagePhase::FinalAnswer), + memory_citation: None, }), }); @@ -5881,6 +5888,7 @@ async fn slash_copy_is_unavailable_when_legacy_agent_message_is_not_repeated_on_ msg: EventMsg::AgentMessage(AgentMessageEvent { message: "Legacy final message".into(), phase: None, + memory_citation: None, }), }); let _ = drain_insert_history(&mut rx); @@ -8409,11 +8417,8 @@ async fn permissions_selection_history_snapshot_full_access_to_default() { .approval_policy .set(AskForApproval::Never) .expect("set approval policy"); - chat.config - .permissions - .sandbox_policy - .set(SandboxPolicy::DangerFullAccess) - .expect("set sandbox policy"); + chat.config.permissions.sandbox_policy = + Constrained::allow_any(SandboxPolicy::DangerFullAccess); chat.open_permissions_popup(); let popup = render_bottom_popup(&chat, 120); @@ -10722,6 +10727,7 @@ async fn deltas_then_same_final_message_are_rendered_snapshot() { msg: EventMsg::AgentMessage(AgentMessageEvent { message: "Here is the result.".into(), phase: None, + memory_citation: None, }), });