Lightweight coding agent that runs in your terminal
Rust
feat: add memory citation to agent message (#14821)
jif-oaia265d6043edc
diff --git a/codex-rs/app-server-protocol/schema/json/ServerNotification.json b/codex-rs/app-server-protocol/schema/json/ServerNotification.jsonindex 6cb20abd84..8bb9f25483 100644--- a/codex-rs/app-server-protocol/schema/json/ServerNotification.json+++ b/codex-rs/app-server-protocol/schema/json/ServerNotification.json@@ -1455,6 +1455,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": [@@ -2181,6 +2229,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.jsonindex 037c99e8ad..5ea8fc4189 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@@ -8600,6 +8600,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",@@ -11841,6 +11889,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.jsonindex fcdad2bab2..e5a07c058e 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@@ -5388,6 +5388,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",@@ -9601,6 +9649,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.jsonindex b447fc3397..f165850bf6 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.jsonindex 1b02f44188..811e02c5a1 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.jsonindex b8e83ba34e..aeb4db80ef 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.jsonindex e57c84b463..04765cf484 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.jsonindex f9f9430550..9366304000 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.jsonindex c652c1cb44..57dea225e2 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.jsonindex b0ca838cde..295938ba85 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.jsonindex 6809f9715b..774c3cade3 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.jsonindex 2288caa508..518f560a27 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.jsonindex e994a2b009..a6746e1eb1 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.jsonindex 3eabf9eebc..a2307578d2 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.jsonindex f6738ff216..64c00271fb 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.jsonindex 079a81ad04..163d22b642 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.jsonindex 17f04c51d8..9264d98d29 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.jsonindex 59171e42d0..5ed40f55f9 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.tsnew file mode 100644index 0000000000..7657e29f8b--- /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<MemoryCitationEntry>, threadIds: Array<string>, };diff --git a/codex-rs/app-server-protocol/schema/typescript/v2/MemoryCitationEntry.ts b/codex-rs/app-server-protocol/schema/typescript/v2/MemoryCitationEntry.tsnew file mode 100644index 0000000000..9b9ce17267--- /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.tsindex bcc81c0251..51ab9e8812 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<UserInput>, } | { "type": "agentMessage", id: string, text: string, phase: MessagePhase | null, } | { "type": "plan", id: string, text: string, } | { "type": "reasoning", id: string, summary: Array<string>, content: Array<string>, } | { "type": "commandExecution", id: string,+export type ThreadItem = { "type": "userMessage", id: string, content: Array<UserInput>, } | { "type": "agentMessage", id: string, text: string, phase: MessagePhase | null, memoryCitation: MemoryCitation | null, } | { "type": "plan", id: string, text: string, } | { "type": "reasoning", id: string, summary: Array<string>, content: Array<string>, } | { "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.tsindex 63514ed9b4..09ca046755 100644--- a/codex-rs/app-server-protocol/schema/typescript/v2/index.ts+++ b/codex-rs/app-server-protocol/schema/typescript/v2/index.ts@@ -174,6 +174,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.rsindex 9866459c66..e46cc0307a 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<MessagePhase>) {+ fn handle_agent_message(+ &mut self,+ text: String,+ phase: Option<MessagePhase>,+ memory_citation: Option<crate::protocol::v2::MemoryCitation>,+ ) {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.rsindex 3e209d844d..09d891c295 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;@@ -3568,6 +3570,44 @@ pub struct Turn {pub error: Option<TurnError>,}+#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]+#[serde(rename_all = "camelCase")]+#[ts(export_to = "v2/")]+pub struct MemoryCitation {+ pub entries: Vec<MemoryCitationEntry>,+ pub thread_ids: Vec<String>,+}++impl From<CoreMemoryCitation> 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<CoreMemoryCitationEntry> 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/")]@@ -4068,6 +4108,8 @@ pub enum ThreadItem {text: String,#[serde(default)]phase: Option<MessagePhase>,+ #[serde(default)]+ memory_citation: Option<MemoryCitation>,},#[serde(rename_all = "camelCase")]#[ts(rename_all = "camelCase")]@@ -4317,6 +4359,7 @@ impl From<CoreTurnItem> for ThreadItem {id: agent.id,text,phase: agent.phase,+ memory_citation: agent.memory_citation.map(Into::into),}}CoreTurnItem::Plan(plan) => ThreadItem::Plan {@@ -7393,6 +7436,7 @@ mod tests {},],phase: None,+ memory_citation: None,});assert_eq!(@@ -7401,6 +7445,7 @@ mod tests {id: "agent-1".to_string(),text: "Hello world".to_string(),phase: None,+ memory_citation: None,});@@ -7410,6 +7455,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!(@@ -7418,6 +7472,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.rsindex 27803db42c..5cbcd3b25d 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/src/codex.rs b/codex-rs/core/src/codex.rsindex f38bf6d2fe..efde7d8488 100644--- a/codex-rs/core/src/codex.rs+++ b/codex-rs/core/src/codex.rs@@ -6856,6 +6856,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.rsindex 72372b24cd..7a9cdb3906 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<TurnItem> {diff --git a/codex-rs/core/src/memories/citations.rs b/codex-rs/core/src/memories/citations.rsindex ed620e853b..d8642880f1 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<String>) -> Option<MemoryCitation> {+ 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<String>) -> Vec<ThreadId> {- let mut result = Vec::new();for citation in citations {- let mut ids_block = None;- for (open, close) in [- ("<thread_ids>", "</thread_ids>"),- ("<rollout_ids>", "</rollout_ids>"),- ] {- 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, "<citation_entries>", "</citation_entries>")+ {+ 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<String>) -> Vec<ThreadId> {+ 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<MemoryCitationEntry> {+ 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, "<rollout_ids>", "</rollout_ids>")+ .or_else(|| extract_block(text, "<thread_ids>", "</thread_ids>"))+}+#[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.rsindex b6783dea7c..49d4a67430 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!(+ "<citation_entries>\nMEMORY.md:1-2|note=[summary]\nrollout_summaries/foo.md:10-12|note=[details]\n</citation_entries>\n<rollout_ids>\n{first}\n{second}\n{first}\n</rollout_ids>"+ )];++ 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<_>>(),+ 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.rsindex f6f588574a..dbe11ac9f7 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::ResuAgentMessageEvent {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.rsindex a44bc01f55..084cb4b1a3 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<codex_protocol::memory_citation::MemoryCitation>,+) {+ 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<String> {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::<String>();- 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.rsindex bfebb8902c..389f01ec71 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("hello<oai-mem-citation>doc1</oai-mem-citation> world");+ let item = assistant_output_text(+ "hello<oai-mem-citation><citation_entries>\nMEMORY.md:1-2|note=[x]\n</citation_entries>\n<rollout_ids>\n019cc2ea-1dff-7902-8d40-c8f6e5d83cc4\n</rollout_ids></oai-mem-citation> 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::<String>();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.rsindex 4f292b40dc..934b6ed30a 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,Nonediff --git a/codex-rs/exec/tests/event_processor_with_json_output.rs b/codex-rs/exec/tests/event_processor_with_json_output.rsindex 63e28f222e..e9f295337e 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.rsindex f200fe6f75..08e50b9546 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<MessagePhase>,+ #[serde(default, skip_serializing_if = "Option::is_none")]+ #[ts(optional)]+ pub memory_citation: Option<MemoryCitation>,}#[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.rsindex d6adf2c585..08466ba4ea 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.rsnew file mode 100644index 0000000000..6706aea774--- /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<MemoryCitationEntry>,+ pub rollout_ids: Vec<String>,+}++#[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.rsindex 7feac32954..e5277c16bf 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;@@ -1996,6 +1997,8 @@ pub struct AgentMessageEvent {pub message: String,#[serde(default)]pub phase: Option<MessagePhase>,+ #[serde(default)]+ pub memory_citation: Option<MemoryCitation>,}#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema, TS)]diff --git a/codex-rs/tui/src/chatwidget/tests.rs b/codex-rs/tui/src/chatwidget/tests.rsindex e234c5668f..4f216ba2e0 100644--- a/codex-rs/tui/src/chatwidget/tests.rs+++ b/codex-rs/tui/src/chatwidget/tests.rs@@ -203,6 +203,7 @@ async fn resumed_initial_messages_render_history() {EventMsg::AgentMessage(AgentMessageEvent {message: "assistant reply".to_string(),phase: None,+ memory_citation: None,}),]),network_proxy: None,@@ -251,6 +252,7 @@ async fn thread_snapshot_replay_does_not_duplicate_agent_message_history() {text: "assistant reply".to_string(),}],phase: None,+ memory_citation: None,}),}),});@@ -259,6 +261,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,}),});@@ -1547,6 +1550,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,}),});@@ -1573,6 +1577,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,}),});@@ -3551,6 +3556,7 @@ fn complete_assistant_message(text: text.to_string(),}],phase,+ memory_citation: None,}),}),});@@ -4146,6 +4152,7 @@ async fn live_legacy_agent_message_after_item_completed_does_not_duplicate_assismsg: EventMsg::AgentMessage(AgentMessageEvent {message: "hello".into(),phase: Some(MessagePhase::FinalAnswer),+ memory_citation: None,}),});@@ -6010,6 +6017,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);@@ -10855,6 +10863,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.rsindex 9ce99dba8b..e9ee092663 100644--- a/codex-rs/tui_app_server/src/app.rs+++ b/codex-rs/tui_app_server/src/app.rs@@ -7007,6 +7007,7 @@ guardian_approval = trueid: "assistant-1".to_string(),text: "restored response".to_string(),phase: None,+ memory_citation: None,},],status: TurnStatus::Completed,@@ -7120,6 +7121,7 @@ guardian_approval = trueid: "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.rsindex 5efac9bc0d..e22a18cd94 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@@ -668,13 +668,33 @@ fn thread_item_to_core(item: &ThreadItem) -> Option<TurnItem> {.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(),@@ -897,6 +917,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(),@@ -921,13 +942,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"),}@@ -1111,6 +1138,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.rsindex 514005193b..276777994c 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.rsindex d1271fa1a4..6600c96ec4 100644--- a/codex-rs/tui_app_server/src/chatwidget/tests.rs+++ b/codex-rs/tui_app_server/src/chatwidget/tests.rs@@ -202,6 +202,7 @@ async fn resumed_initial_messages_render_history() {EventMsg::AgentMessage(AgentMessageEvent {message: "assistant reply".to_string(),phase: None,+ memory_citation: None,}),]),network_proxy: None,@@ -250,6 +251,7 @@ async fn thread_snapshot_replay_does_not_duplicate_agent_message_history() {text: "assistant reply".to_string(),}],phase: None,+ memory_citation: None,}),}),});@@ -258,6 +260,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,}),});@@ -1546,6 +1549,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,}),});@@ -1572,6 +1576,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,}),});@@ -3521,6 +3526,7 @@ fn complete_assistant_message(text: text.to_string(),}],phase,+ memory_citation: None,}),}),});@@ -4110,6 +4116,7 @@ async fn live_legacy_agent_message_after_item_completed_does_not_duplicate_assismsg: EventMsg::AgentMessage(AgentMessageEvent {message: "hello".into(),phase: Some(MessagePhase::FinalAnswer),+ memory_citation: None,}),});@@ -5958,6 +5965,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);@@ -8497,11 +8505,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);@@ -10810,6 +10815,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,}),});