Add Phase 6 context shard reflection

This commit is contained in:
Meta Vens 2026-04-26 03:00:06 +01:00
commit aab3ae3334
21 changed files with 1459 additions and 47 deletions

View file

@ -346,6 +346,11 @@ client_request_definitions! {
params: v2::ThreadEpiphanyJobsParams,
response: v2::ThreadEpiphanyJobsResponse,
},
#[experimental("thread/epiphany/context")]
ThreadEpiphanyContext => "thread/epiphany/context" {
params: v2::ThreadEpiphanyContextParams,
response: v2::ThreadEpiphanyContextResponse,
},
#[experimental("thread/epiphany/index")]
ThreadEpiphanyIndex => "thread/epiphany/index" {
params: v2::ThreadEpiphanyIndexParams,
@ -1808,6 +1813,120 @@ mod tests {
Ok(())
}
#[test]
fn serialize_thread_epiphany_context_response() -> Result<()> {
let response = ClientResponse::ThreadEpiphanyContext {
request_id: RequestId::Integer(8),
response: v2::ThreadEpiphanyContextResponse {
thread_id: "thr_123".to_string(),
source: v2::ThreadEpiphanyContextSource::Live,
state_status: v2::ThreadEpiphanyContextStateStatus::Ready,
state_revision: Some(3),
context: v2::ThreadEpiphanyContext {
graph: v2::ThreadEpiphanyGraphContext {
architecture_nodes: vec![codex_protocol::protocol::EpiphanyGraphNode {
id: "state-spine".to_string(),
title: "State spine".to_string(),
purpose: "Keep understanding typed".to_string(),
..Default::default()
}],
architecture_edges: vec![codex_protocol::protocol::EpiphanyGraphEdge {
id: Some("edge-state-read".to_string()),
source_id: "state-spine".to_string(),
target_id: "client-read".to_string(),
kind: "projects".to_string(),
..Default::default()
}],
..Default::default()
},
frontier: Some(codex_protocol::protocol::EpiphanyGraphFrontier {
active_node_ids: vec!["state-spine".to_string()],
..Default::default()
}),
checkpoint: None,
observations: vec![codex_protocol::protocol::EpiphanyObservation {
id: "obs-1".to_string(),
summary: "Context shard is read-only.".to_string(),
source_kind: "smoke".to_string(),
status: "ok".to_string(),
evidence_ids: vec!["ev-1".to_string()],
..Default::default()
}],
evidence: vec![codex_protocol::protocol::EpiphanyEvidenceRecord {
id: "ev-1".to_string(),
kind: "test".to_string(),
status: "ok".to_string(),
summary: "Context shard serialized.".to_string(),
..Default::default()
}],
},
missing: v2::ThreadEpiphanyContextMissing {
graph_node_ids: vec!["missing-node".to_string()],
..Default::default()
},
},
};
assert_eq!(response.id(), &RequestId::Integer(8));
assert_eq!(response.method(), "thread/epiphany/context");
assert_eq!(
json!({
"method": "thread/epiphany/context",
"id": 8,
"response": {
"threadId": "thr_123",
"source": "live",
"stateStatus": "ready",
"stateRevision": 3,
"context": {
"graph": {
"architectureNodes": [
{
"id": "state-spine",
"title": "State spine",
"purpose": "Keep understanding typed"
}
],
"architectureEdges": [
{
"source_id": "state-spine",
"target_id": "client-read",
"kind": "projects",
"id": "edge-state-read"
}
]
},
"frontier": {
"active_node_ids": ["state-spine"]
},
"observations": [
{
"id": "obs-1",
"summary": "Context shard is read-only.",
"source_kind": "smoke",
"status": "ok",
"evidence_ids": ["ev-1"]
}
],
"evidence": [
{
"id": "ev-1",
"kind": "test",
"status": "ok",
"summary": "Context shard serialized."
}
]
},
"missing": {
"graphNodeIds": ["missing-node"]
}
}
}),
serde_json::to_value(&response)?,
);
Ok(())
}
#[test]
fn serialize_thread_epiphany_retrieve_response() -> Result<()> {
let response = ClientResponse::ThreadEpiphanyRetrieve {
@ -2690,6 +2809,24 @@ mod tests {
assert_eq!(reason, Some("thread/epiphany/jobs"));
}
#[test]
fn thread_epiphany_context_is_marked_experimental() {
let request = ClientRequest::ThreadEpiphanyContext {
request_id: RequestId::Integer(1),
params: v2::ThreadEpiphanyContextParams {
thread_id: "thr_123".to_string(),
graph_node_ids: vec!["state-spine".to_string()],
graph_edge_ids: Vec::new(),
observation_ids: Vec::new(),
evidence_ids: Vec::new(),
include_active_frontier: Some(true),
include_linked_evidence: Some(true),
},
};
let reason = crate::experimental_api::ExperimentalApi::experimental_reason(&request);
assert_eq!(reason, Some("thread/epiphany/context"));
}
#[test]
fn thread_epiphany_index_is_marked_experimental() {
let request = ClientRequest::ThreadEpiphanyIndex {

View file

@ -61,7 +61,10 @@ use codex_protocol::protocol::EpiphanyChurnState as CoreEpiphanyChurnState;
use codex_protocol::protocol::EpiphanyCodeRef as CoreEpiphanyCodeRef;
use codex_protocol::protocol::EpiphanyEvidenceRecord as CoreEpiphanyEvidenceRecord;
use codex_protocol::protocol::EpiphanyGraphCheckpoint as CoreEpiphanyGraphCheckpoint;
use codex_protocol::protocol::EpiphanyGraphEdge as CoreEpiphanyGraphEdge;
use codex_protocol::protocol::EpiphanyGraphFrontier as CoreEpiphanyGraphFrontier;
use codex_protocol::protocol::EpiphanyGraphLink as CoreEpiphanyGraphLink;
use codex_protocol::protocol::EpiphanyGraphNode as CoreEpiphanyGraphNode;
use codex_protocol::protocol::EpiphanyGraphs as CoreEpiphanyGraphs;
use codex_protocol::protocol::EpiphanyInvariant as CoreEpiphanyInvariant;
use codex_protocol::protocol::EpiphanyModeState as CoreEpiphanyModeState;
@ -3985,6 +3988,7 @@ pub enum ThreadEpiphanySceneAction {
Index,
Retrieve,
Distill,
Context,
Jobs,
Propose,
Promote,
@ -4172,6 +4176,107 @@ pub struct ThreadEpiphanyJob {
pub linked_graph_node_ids: Vec<String>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub struct ThreadEpiphanyContextParams {
pub thread_id: String,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub graph_node_ids: Vec<String>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub graph_edge_ids: Vec<String>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub observation_ids: Vec<String>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub evidence_ids: Vec<String>,
/// Defaults to true so clients can request the current working slice with
/// only a thread id.
#[serde(default, skip_serializing_if = "Option::is_none")]
#[ts(optional = nullable)]
pub include_active_frontier: Option<bool>,
/// Defaults to true so selected observations bring their evidence anchors.
#[serde(default, skip_serializing_if = "Option::is_none")]
#[ts(optional = nullable)]
pub include_linked_evidence: Option<bool>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub struct ThreadEpiphanyContextResponse {
pub thread_id: String,
pub source: ThreadEpiphanyContextSource,
pub state_status: ThreadEpiphanyContextStateStatus,
#[serde(default, skip_serializing_if = "Option::is_none")]
#[ts(optional = nullable)]
pub state_revision: Option<u64>,
pub context: ThreadEpiphanyContext,
pub missing: ThreadEpiphanyContextMissing,
}
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub enum ThreadEpiphanyContextSource {
Stored,
Live,
}
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub enum ThreadEpiphanyContextStateStatus {
Missing,
Ready,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS, Default)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub struct ThreadEpiphanyContext {
pub graph: ThreadEpiphanyGraphContext,
#[serde(default, skip_serializing_if = "Option::is_none")]
#[ts(optional = nullable)]
pub frontier: Option<CoreEpiphanyGraphFrontier>,
#[serde(default, skip_serializing_if = "Option::is_none")]
#[ts(optional = nullable)]
pub checkpoint: Option<CoreEpiphanyGraphCheckpoint>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub observations: Vec<CoreEpiphanyObservation>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub evidence: Vec<CoreEpiphanyEvidenceRecord>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS, Default)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub struct ThreadEpiphanyGraphContext {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub architecture_nodes: Vec<CoreEpiphanyGraphNode>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub architecture_edges: Vec<CoreEpiphanyGraphEdge>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub dataflow_nodes: Vec<CoreEpiphanyGraphNode>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub dataflow_edges: Vec<CoreEpiphanyGraphEdge>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub links: Vec<CoreEpiphanyGraphLink>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS, Default)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub struct ThreadEpiphanyContextMissing {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub graph_node_ids: Vec<String>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub graph_edge_ids: Vec<String>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub observation_ids: Vec<String>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub evidence_ids: Vec<String>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]