Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions config/agent_contracts/agent_output_contracts.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"registry_id": "contextlattice_agent_output_contracts",
"registry_version": 2,
"updated_at": "2026-05-27T00:00:00Z",
"registry_version": 3,
"updated_at": "2026-05-28T00:00:00Z",
"default_validator": "contextlattice.boundary.v1",
"purpose": "Agent-facing ContextLattice payloads must carry explicit contract identifiers and pass boundary validation before being returned or handed to another agent.",
"shared_fragments": {
Expand Down Expand Up @@ -61,6 +61,9 @@
"payload_kind": "agent_policy_context_package",
"required_output_mode": "json_object",
"safe_failure_behavior": "return_json_contract_violation_envelope_without_raw_payload",
"max_total_json_bytes": 60000,
"max_string_bytes": 6000,
"max_list_items": 32,
"required_fields": [
"version",
"agent",
Expand Down Expand Up @@ -160,6 +163,13 @@
"anti_scheming_protocol.red_flags": 4,
"anti_scheming_protocol.delivery": 3
},
"max_bytes_by_path": {
"mission": 2000,
"objective": 2000,
"goal": 2000,
"handoff.handoff_prompt": 4000,
"evidence.mission_pack_error": 1000
},
"forbidden_fields": [
"hookSpecificOutput",
"messages",
Expand All @@ -175,6 +185,9 @@
"contract_version": 1,
"payload_kind": "agent_preflight_response",
"required_output_mode": "json_object",
"max_total_json_bytes": 180000,
"max_string_bytes": 8000,
"max_list_items": 64,
"required_fields": [
"ok",
"service",
Expand Down Expand Up @@ -225,6 +238,9 @@
"contract_version": 1,
"payload_kind": "context_pack_response",
"required_output_mode": "json_object",
"max_total_json_bytes": 120000,
"max_string_bytes": 6000,
"max_list_items": 64,
"required_fields": [
"context_pack",
"source_coverage",
Expand Down Expand Up @@ -274,6 +290,10 @@
"secrets"
],
"forbidden_scope": "root",
"max_bytes_by_path": {
"query": 2000,
"task_summary": 1000
},
"required_string_contains": {
"format_contract.schema_id": "context_pack_response.v1"
}
Expand Down Expand Up @@ -321,6 +341,9 @@
"contract_version": 1,
"payload_kind": "codex_compact_hook_stdout",
"required_output_mode": "json_object",
"max_total_json_bytes": 4096,
"max_string_bytes": 4000,
"max_list_items": 4,
"allowed_fields": [
"continue",
"suppressOutput",
Expand Down Expand Up @@ -597,6 +620,9 @@
"payload_kind": "context_overflow_recovery",
"contract_version": 1,
"required_output_mode": "json_object",
"max_total_json_bytes": 120000,
"max_string_bytes": 8000,
"max_list_items": 16000,
"required_fields": [
"ok",
"status",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { NextResponse } from "next/server";
import { callOrchestrator } from "@/lib/orchestrator";

export async function GET(request: Request) {
const url = new URL(request.url);
const params = new URLSearchParams();
for (const key of ["project", "limit", "include_ephemeral"]) {
const value = url.searchParams.get(key);
if (value) {
params.set(key, value);
}
}
const suffix = params.toString() ? `?${params.toString()}` : "";
const data = await callOrchestrator(`/telemetry/memory/graph${suffix}`);
return NextResponse.json(data);
}
10 changes: 9 additions & 1 deletion contextlattice-dashboard/app/status/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { useEffect, useState } from "react";
import { RetrievalPanel } from "@/components/RetrievalPanel";
import { MemoryGraphPanel, type MemoryGraphPayload } from "@/components/MemoryGraphPanel";

type Service = {
name: string;
Expand Down Expand Up @@ -61,17 +62,19 @@ export default function StatusPage() {
const [preferences, setPreferences] = useState<PreferencesPayload | null>(null);
const [topics, setTopics] = useState<TopicsPayload | null>(null);
const [memoryTelemetry, setMemoryTelemetry] = useState<MemoryTelemetry | null>(null);
const [memoryGraph, setMemoryGraph] = useState<MemoryGraphPayload | null>(null);
const [error, setError] = useState<string | null>(null);
const [updatedAt, setUpdatedAt] = useState<string | null>(null);

async function loadStatus() {
try {
setError(null);
const [statusRes, prefRes, topicRes, memRes] = await Promise.all([
const [statusRes, prefRes, topicRes, memRes, graphRes] = await Promise.all([
fetch("/api/memory/status", { cache: "no-store" }),
fetch("/api/memory/preferences", { cache: "no-store" }),
fetch("/api/memory/topics", { cache: "no-store" }),
fetch("/api/telemetry/memory", { cache: "no-store" }),
fetch("/api/telemetry/memory/graph", { cache: "no-store" }),
]);
const statusData = await statusRes.json();
if (!statusRes.ok) {
Expand All @@ -87,6 +90,9 @@ export default function StatusPage() {
if (memRes.ok) {
setMemoryTelemetry(await memRes.json());
}
if (graphRes.ok) {
setMemoryGraph(await graphRes.json());
}
setUpdatedAt(new Date().toLocaleTimeString());
} catch (err: any) {
setError(err?.message || "Status unavailable");
Expand Down Expand Up @@ -206,6 +212,8 @@ export default function StatusPage() {
</div>
</section>

<MemoryGraphPanel graph={memoryGraph} />

<RetrievalPanel />
</div>
);
Expand Down
211 changes: 211 additions & 0 deletions contextlattice-dashboard/components/MemoryGraphPanel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
"use client";

type CountRow = {
name?: string;
count?: number;
};

type ProjectRow = {
project?: string;
docs?: number;
connected_docs?: number;
isolated_docs?: number;
edges?: number;
inferred_edges?: number;
explicit_edges?: number;
density_edges_per_doc?: number;
top_relations?: CountRow[];
};

type NodeRow = {
memory_id?: string;
degree?: number;
inbound?: number;
outbound?: number;
};

export type MemoryGraphPayload = {
ok?: boolean;
status?: string;
generated_at?: string;
doc_count?: number;
edge_count?: number;
connected_doc_count?: number;
isolated_doc_count?: number;
inferred_edge_count?: number;
explicit_edge_count?: number;
density_edges_per_doc?: number;
projects?: ProjectRow[];
relations?: CountRow[];
top_nodes?: NodeRow[];
recommendations?: string[];
edge_store?: {
bytes?: number;
path?: string;
};
};

function numberValue(value: unknown): number {
return typeof value === "number" && Number.isFinite(value) ? value : 0;
}

function MiniBar({ value, max }: { value: number; max: number }) {
const pct = max > 0 ? Math.max(0, Math.min(100, (value / max) * 100)) : 0;
return (
<div className="h-2 w-full rounded bg-slate-800 overflow-hidden" aria-hidden="true">
<div className="h-full bg-cyan-300" style={{ width: `${pct}%` }} />
</div>
);
}

function Metric({
label,
value,
tone,
}: {
label: string;
value: number | string;
tone?: "warn" | "good";
}) {
const toneClass =
tone === "warn" ? "text-amber-200 border-amber-500/70" : tone === "good" ? "text-emerald-200 border-emerald-500/70" : "text-slate-200 border-slate-600";
return (
<div className={`rounded border px-3 py-2 ${toneClass}`}>
<div className="text-xs uppercase tracking-wide text-slate-400">{label}</div>
<div className="text-lg font-semibold">{typeof value === "number" ? value.toLocaleString() : value}</div>
</div>
);
}

export function MemoryGraphPanel({ graph }: { graph: MemoryGraphPayload | null }) {
if (!graph) {
return (
<section className="card">
<h3 className="text-lg font-semibold">Memory graph</h3>
<p className="text-sm text-slate-400 mt-2">Graph telemetry unavailable.</p>
</section>
);
}

const projects = Array.isArray(graph.projects) ? graph.projects.slice(0, 6) : [];
const relations = Array.isArray(graph.relations) ? graph.relations.slice(0, 8) : [];
const topNodes = Array.isArray(graph.top_nodes) ? graph.top_nodes.slice(0, 6) : [];
const maxProjectEdges = Math.max(1, ...projects.map((item) => numberValue(item.edges)));
const maxRelationCount = Math.max(1, ...relations.map((item) => numberValue(item.count)));
const status = String(graph.status || "unknown");
const sparse = status === "sparse" || status === "no_edges";

return (
<section className="card space-y-5">
<div className="flex flex-wrap items-start justify-between gap-3">
<div>
<h3 className="text-lg font-semibold">Memory graph</h3>
<p className="text-xs text-slate-500 mt-1">
{graph.generated_at ? `Updated ${new Date(graph.generated_at).toLocaleTimeString()}` : "Updated -"}
</p>
</div>
<span
className={`text-xs px-2 py-1 rounded ${
sparse ? "bg-amber-500 text-amber-950" : "bg-emerald-500 text-emerald-950"
}`}
>
{status}
</span>
</div>

<div className="grid md:grid-cols-5 gap-3 text-sm">
<Metric label="Docs" value={numberValue(graph.doc_count)} />
<Metric label="Edges" value={numberValue(graph.edge_count)} tone={numberValue(graph.edge_count) > 0 ? "good" : "warn"} />
<Metric label="Inferred" value={numberValue(graph.inferred_edge_count)} />
<Metric label="Isolated" value={numberValue(graph.isolated_doc_count)} tone={numberValue(graph.isolated_doc_count) > 0 ? "warn" : "good"} />
<Metric label="Density" value={numberValue(graph.density_edges_per_doc).toFixed(2)} />
</div>

<div className="grid lg:grid-cols-2 gap-5">
<div className="space-y-2">
<h4 className="text-sm font-semibold text-slate-200">Projects</h4>
{projects.length ? (
<div className="space-y-2">
{projects.map((item) => {
const edges = numberValue(item.edges);
return (
<div key={item.project || "project"} className="grid grid-cols-[minmax(0,1fr)_4rem] items-center gap-3 text-xs">
<div className="min-w-0">
<div className="flex items-center justify-between gap-2">
<span className="truncate text-slate-300">{item.project || "unknown"}</span>
<span className="text-slate-500">{numberValue(item.docs)} docs</span>
</div>
<MiniBar value={edges} max={maxProjectEdges} />
</div>
<div className="text-right text-slate-300">{edges.toLocaleString()}</div>
</div>
);
})}
</div>
) : (
<p className="text-xs text-slate-500">No project graph rows.</p>
)}
</div>

<div className="space-y-2">
<h4 className="text-sm font-semibold text-slate-200">Relations</h4>
{relations.length ? (
<div className="space-y-2">
{relations.map((item) => {
const count = numberValue(item.count);
return (
<div key={item.name || "relation"} className="grid grid-cols-[minmax(0,1fr)_4rem] items-center gap-3 text-xs">
<div className="min-w-0">
<span className="truncate block text-slate-300">{item.name || "unknown"}</span>
<MiniBar value={count} max={maxRelationCount} />
</div>
<div className="text-right text-slate-300">{count.toLocaleString()}</div>
</div>
);
})}
</div>
) : (
<p className="text-xs text-slate-500">No relation rows.</p>
)}
</div>
</div>

{topNodes.length ? (
<div className="overflow-x-auto text-xs">
<h4 className="text-sm font-semibold text-slate-200 mb-2">Top connected memories</h4>
<table className="w-full border border-slate-700/60 rounded">
<thead className="bg-slate-900/40 text-slate-300">
<tr>
<th className="px-3 py-2 text-left">Memory</th>
<th className="px-3 py-2 text-right">Degree</th>
<th className="px-3 py-2 text-right">In</th>
<th className="px-3 py-2 text-right">Out</th>
</tr>
</thead>
<tbody>
{topNodes.map((node) => (
<tr key={node.memory_id || "node"} className="border-t border-slate-800">
<td className="px-3 py-2 max-w-[32rem] truncate">{node.memory_id || "unknown"}</td>
<td className="px-3 py-2 text-right">{numberValue(node.degree)}</td>
<td className="px-3 py-2 text-right">{numberValue(node.inbound)}</td>
<td className="px-3 py-2 text-right">{numberValue(node.outbound)}</td>
</tr>
))}
</tbody>
</table>
</div>
) : null}

{Array.isArray(graph.recommendations) && graph.recommendations.length ? (
<div className="rounded border border-slate-700/70 p-3 text-xs text-slate-300">
<div className="font-semibold text-slate-100 mb-1">Recommended next action</div>
<ul className="space-y-1">
{graph.recommendations.slice(0, 3).map((item) => (
<li key={item}>{item}</li>
))}
</ul>
</div>
) : null}
</section>
);
}
2 changes: 1 addition & 1 deletion crates/context_codec/src/agent_contracts_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub struct AgentContractRef {
}

pub const AGENT_CONTRACT_REGISTRY_ID: &str = "contextlattice_agent_output_contracts";
pub const AGENT_CONTRACT_REGISTRY_VERSION: u32 = 2;
pub const AGENT_CONTRACT_REGISTRY_VERSION: u32 = 3;

pub const A2A_READINESS_PROFILE_V1: &str = "a2a_readiness_profile.v1";
pub const AGENT_FLIGHT_RECORDER_EVENT_V1: &str = "agent_flight_recorder_event.v1";
Expand Down
Loading
Loading