Add Epiphany typed graph web viewer
This commit is contained in:
parent
7122e01c5e
commit
3e1e04934a
17 changed files with 4728 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -6,3 +6,4 @@ nupkg/
|
|||
.vs/
|
||||
.vscode/
|
||||
node_modules/
|
||||
dist/
|
||||
|
|
|
|||
26
README.md
26
README.md
|
|
@ -172,6 +172,32 @@ That keeps structurally separated note graphs from vanishing just because they n
|
|||
|
||||
There is also a small web-side `elkjs` probe under `web/elk-probe/`. It inspects which algorithms and options are actually present in the installed `elkjs` build and can relayout existing `source-tree.json` / `control-flow.json` outputs without crossing the C# boundary.
|
||||
|
||||
## Epiphany Graph Viewer
|
||||
|
||||
There is now also a real web-side viewer package under `web/epiphany-graph-viewer/`.
|
||||
|
||||
It consumes the typed Epiphany graph state shape directly:
|
||||
|
||||
- `graphs.architecture`
|
||||
- `graphs.dataflow`
|
||||
- `graphs.links`
|
||||
|
||||
and packages:
|
||||
|
||||
- `elkjs` layout
|
||||
- zoom and pan
|
||||
- zoom-gated label and detail pop-in
|
||||
- node, edge, and code-ref inspection
|
||||
- typed cross-link browsing between architecture and dataflow
|
||||
|
||||
Run it locally with:
|
||||
|
||||
```powershell
|
||||
cd E:\Projects\EpiphanyGraph\web\epiphany-graph-viewer
|
||||
npm install
|
||||
npm run dev
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
- unresolved and ambiguous links are written to `warnings.txt`
|
||||
|
|
|
|||
65
web/epiphany-graph-viewer/README.md
Normal file
65
web/epiphany-graph-viewer/README.md
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
# Epiphany Graph Viewer
|
||||
|
||||
Small React component package for browsing Epiphany's durable typed graph state with `elkjs`.
|
||||
|
||||
This is the part where the graphs stop being dead export artifacts and start acting like UI:
|
||||
|
||||
- `graphs.architecture` and `graphs.dataflow` render as first-class views
|
||||
- `graphs.links` show cross-graph correspondences instead of vanishing into a sidecar file
|
||||
- zoom reveals more node detail instead of trying to print the whole phone book at once
|
||||
- selection opens purpose, mechanism, metaphor, status, and code references in a detail pane
|
||||
|
||||
## Install
|
||||
|
||||
```powershell
|
||||
cd E:\Projects\EpiphanyGraph\web\epiphany-graph-viewer
|
||||
npm install
|
||||
```
|
||||
|
||||
## Run The Demo
|
||||
|
||||
```powershell
|
||||
npm run dev
|
||||
```
|
||||
|
||||
The demo uses mocked JSON shaped like the current Epiphany typed state contract.
|
||||
|
||||
## Build
|
||||
|
||||
```powershell
|
||||
npm run build
|
||||
```
|
||||
|
||||
This writes:
|
||||
|
||||
- `dist/index.js`
|
||||
- `dist/index.cjs`
|
||||
- `dist/index.d.ts`
|
||||
- `dist/demo/`
|
||||
|
||||
## Use In Another App
|
||||
|
||||
```tsx
|
||||
import { EpiphanyGraphViewer } from "@epiphanygraph/epiphany-graph-viewer";
|
||||
import type { EpiphanyGraphsState } from "@epiphanygraph/epiphany-graph-viewer";
|
||||
|
||||
const state: EpiphanyGraphsState = {
|
||||
architecture: { nodes: [], edges: [] },
|
||||
dataflow: { nodes: [], edges: [] },
|
||||
links: [],
|
||||
};
|
||||
|
||||
export function Screen() {
|
||||
return <EpiphanyGraphViewer state={state} />;
|
||||
}
|
||||
```
|
||||
|
||||
## Current Shape
|
||||
|
||||
- the viewer lays out each graph with `elkjs` on the client
|
||||
- `architecture` defaults to layered layout
|
||||
- `dataflow` defaults to stress layout
|
||||
- links are exposed in the detail pane and through node badges
|
||||
- zoom gates title, purpose, and metadata visibility
|
||||
|
||||
This is a prototype seam for EpiphanyAgent, not a final cathedral. The point is to package the behavior, the contract, and the rendering policy in one place so the upcoming GUI can steal it without ceremony.
|
||||
12
web/epiphany-graph-viewer/index.html
Normal file
12
web/epiphany-graph-viewer/index.html
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Epiphany Graph Viewer</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
2296
web/epiphany-graph-viewer/package-lock.json
generated
Normal file
2296
web/epiphany-graph-viewer/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
44
web/epiphany-graph-viewer/package.json
Normal file
44
web/epiphany-graph-viewer/package.json
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
{
|
||||
"name": "@epiphanygraph/epiphany-graph-viewer",
|
||||
"version": "0.1.0",
|
||||
"type": "module",
|
||||
"description": "React ELK graph viewer for Epiphany typed graph state.",
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./dist/index.js",
|
||||
"require": "./dist/index.cjs"
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "npm run build:lib && npm run build:demo",
|
||||
"build:lib": "tsup src/index.ts --format esm,cjs --dts --external react --external react-dom --clean",
|
||||
"build:demo": "vite build --outDir dist/demo",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^19.0.0",
|
||||
"react-dom": "^19.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"elkjs": "^0.11.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react": "^19.2.2",
|
||||
"@types/react-dom": "^19.2.2",
|
||||
"@vitejs/plugin-react": "^5.1.1",
|
||||
"react": "^19.2.0",
|
||||
"react-dom": "^19.2.0",
|
||||
"tsup": "^8.5.0",
|
||||
"typescript": "^5.9.3",
|
||||
"vite": "^7.2.4"
|
||||
}
|
||||
}
|
||||
73
web/epiphany-graph-viewer/src/App.tsx
Normal file
73
web/epiphany-graph-viewer/src/App.tsx
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
import { EpiphanyGraphViewer } from "./lib/EpiphanyGraphViewer";
|
||||
import { mockEpiphanyGraphState } from "./lib/mock-state";
|
||||
|
||||
export function App() {
|
||||
return (
|
||||
<main
|
||||
style={{
|
||||
minHeight: "100vh",
|
||||
margin: 0,
|
||||
background:
|
||||
"radial-gradient(circle at top left, rgba(30, 58, 138, 0.32), transparent 38%), radial-gradient(circle at top right, rgba(190, 24, 93, 0.24), transparent 34%), linear-gradient(180deg, #071019 0%, #0c1726 52%, #10131c 100%)",
|
||||
color: "#e5eef8",
|
||||
fontFamily: '"Aptos", "Segoe UI Variable Text", "Bahnschrift", sans-serif',
|
||||
}}
|
||||
>
|
||||
<section
|
||||
style={{
|
||||
padding: "28px 28px 18px",
|
||||
display: "grid",
|
||||
gap: 10,
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
display: "inline-flex",
|
||||
alignItems: "center",
|
||||
gap: 10,
|
||||
width: "fit-content",
|
||||
padding: "7px 12px",
|
||||
borderRadius: 999,
|
||||
background: "rgba(12, 19, 35, 0.72)",
|
||||
border: "1px solid rgba(103, 232, 249, 0.28)",
|
||||
color: "#9dd7ea",
|
||||
fontSize: 12,
|
||||
letterSpacing: "0.14em",
|
||||
textTransform: "uppercase",
|
||||
}}
|
||||
>
|
||||
EpiphanyAgent Graph Mock
|
||||
</div>
|
||||
<div style={{ maxWidth: 960, display: "grid", gap: 8 }}>
|
||||
<h1
|
||||
style={{
|
||||
margin: 0,
|
||||
fontSize: "clamp(2rem, 3vw, 3.2rem)",
|
||||
lineHeight: 1.02,
|
||||
fontWeight: 800,
|
||||
letterSpacing: "-0.04em",
|
||||
}}
|
||||
>
|
||||
Typed graphs, now with less ceremonial SVG corpse handling.
|
||||
</h1>
|
||||
<p
|
||||
style={{
|
||||
margin: 0,
|
||||
color: "rgba(229, 238, 248, 0.72)",
|
||||
maxWidth: 900,
|
||||
fontSize: "1rem",
|
||||
lineHeight: 1.55,
|
||||
}}
|
||||
>
|
||||
This demo uses mocked Epiphany state shaped like the current protocol:
|
||||
architecture graph, dataflow graph, and typed cross-links between them.
|
||||
Zoom in and the details stop hiding under the floorboards.
|
||||
</p>
|
||||
</div>
|
||||
</section>
|
||||
<section style={{ padding: "0 20px 20px" }}>
|
||||
<EpiphanyGraphViewer state={mockEpiphanyGraphState} />
|
||||
</section>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
15
web/epiphany-graph-viewer/src/index.ts
Normal file
15
web/epiphany-graph-viewer/src/index.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
export { EpiphanyGraphViewer } from "./lib/EpiphanyGraphViewer";
|
||||
export { mockEpiphanyGraphState } from "./lib/mock-state";
|
||||
export { validateEpiphanyGraphsState } from "./lib/validation";
|
||||
export type {
|
||||
EpiphanyCodeRef,
|
||||
EpiphanyGraph,
|
||||
EpiphanyGraphEdge,
|
||||
EpiphanyGraphLink,
|
||||
EpiphanyGraphNode,
|
||||
EpiphanyGraphsState,
|
||||
EpiphanyGraphViewerProps,
|
||||
EpiphanyValidationIssue,
|
||||
GraphKey,
|
||||
ViewerSelection,
|
||||
} from "./lib/types";
|
||||
1314
web/epiphany-graph-viewer/src/lib/EpiphanyGraphViewer.tsx
Normal file
1314
web/epiphany-graph-viewer/src/lib/EpiphanyGraphViewer.tsx
Normal file
File diff suppressed because it is too large
Load diff
287
web/epiphany-graph-viewer/src/lib/layout.ts
Normal file
287
web/epiphany-graph-viewer/src/lib/layout.ts
Normal file
|
|
@ -0,0 +1,287 @@
|
|||
import ELK from "elkjs/lib/elk.bundled.js";
|
||||
import type {
|
||||
EpiphanyGraph,
|
||||
EpiphanyGraphEdge,
|
||||
EpiphanyGraphLink,
|
||||
EpiphanyGraphsState,
|
||||
GraphKey,
|
||||
GraphLayout,
|
||||
PositionedEdge,
|
||||
PositionedNode,
|
||||
PositionedPoint,
|
||||
} from "./types";
|
||||
|
||||
const elk = new ELK();
|
||||
|
||||
type ElkSection = {
|
||||
startPoint?: { x: number; y: number };
|
||||
endPoint?: { x: number; y: number };
|
||||
bendPoints?: Array<{ x: number; y: number }>;
|
||||
};
|
||||
|
||||
type ElkLayoutNode = {
|
||||
id: string;
|
||||
x?: number;
|
||||
y?: number;
|
||||
width?: number;
|
||||
height?: number;
|
||||
};
|
||||
|
||||
type ElkLayoutEdge = {
|
||||
id?: string;
|
||||
sections?: ElkSection[];
|
||||
};
|
||||
|
||||
type ElkLayoutGraph = {
|
||||
width?: number;
|
||||
height?: number;
|
||||
children?: ElkLayoutNode[];
|
||||
edges?: ElkLayoutEdge[];
|
||||
};
|
||||
|
||||
export async function layoutEpiphanyGraphs(
|
||||
state: EpiphanyGraphsState,
|
||||
): Promise<Record<GraphKey, GraphLayout>> {
|
||||
const [architecture, dataflow] = await Promise.all([
|
||||
layoutGraph("architecture", state.architecture, state.links),
|
||||
layoutGraph("dataflow", state.dataflow, state.links),
|
||||
]);
|
||||
|
||||
return { architecture, dataflow };
|
||||
}
|
||||
|
||||
async function layoutGraph(
|
||||
graphKey: GraphKey,
|
||||
graph: EpiphanyGraph,
|
||||
links: EpiphanyGraphLink[],
|
||||
): Promise<GraphLayout> {
|
||||
const nodeDegrees = buildNodeDegrees(graph);
|
||||
const linkCounts = buildLinkCounts(graphKey, links);
|
||||
const nodes = graph.nodes.map((node) => {
|
||||
const size = estimateNodeSize(node, graphKey);
|
||||
return {
|
||||
id: node.id,
|
||||
width: size.width,
|
||||
height: size.height,
|
||||
labels: [{ text: node.title }],
|
||||
};
|
||||
});
|
||||
const edges = graph.edges.map((edge, index) => ({
|
||||
id: resolveEdgeId(edge, index),
|
||||
sources: [edge.source_id],
|
||||
targets: [edge.target_id],
|
||||
}));
|
||||
|
||||
const elkGraph = {
|
||||
id: graphKey,
|
||||
layoutOptions: {
|
||||
"elk.algorithm":
|
||||
graphKey === "architecture" ? "org.eclipse.elk.layered" : "org.eclipse.elk.stress",
|
||||
...(graphKey === "architecture"
|
||||
? {
|
||||
"elk.direction": "DOWN",
|
||||
"elk.edgeRouting": "SPLINES",
|
||||
"elk.spacing.nodeNode": "48",
|
||||
"elk.layered.spacing.nodeNodeBetweenLayers": "88",
|
||||
"elk.layered.nodePlacement.strategy": "NETWORK_SIMPLEX",
|
||||
"elk.padding": "[top=40,left=40,bottom=40,right=40]",
|
||||
}
|
||||
: {
|
||||
"elk.spacing.nodeNode": "80",
|
||||
"elk.edgeRouting": "SPLINES",
|
||||
"elk.padding": "[top=60,left=60,bottom=60,right=60]",
|
||||
"elk.stress.desiredEdgeLength": "128",
|
||||
}),
|
||||
},
|
||||
children: nodes,
|
||||
edges,
|
||||
};
|
||||
|
||||
const layout = (await elk.layout(elkGraph)) as ElkLayoutGraph;
|
||||
const childLookup = new Map((layout.children ?? []).map((child) => [child.id, child]));
|
||||
|
||||
const positionedNodes: PositionedNode[] = graph.nodes.map((node) => {
|
||||
const child = childLookup.get(node.id);
|
||||
const degree = nodeDegrees.get(node.id) ?? 0;
|
||||
const linkCount = linkCounts.get(node.id) ?? 0;
|
||||
return {
|
||||
...node,
|
||||
code_refs: node.code_refs ?? [],
|
||||
graphKey,
|
||||
x: child?.x ?? 0,
|
||||
y: child?.y ?? 0,
|
||||
width: child?.width ?? estimateNodeSize(node, graphKey).width,
|
||||
height: child?.height ?? estimateNodeSize(node, graphKey).height,
|
||||
degree,
|
||||
linkCount,
|
||||
badgeText: nodeBadgeText(node.title),
|
||||
fill: nodeFill(graphKey, node.status),
|
||||
stroke: nodeStroke(graphKey, node.status),
|
||||
};
|
||||
});
|
||||
|
||||
const edgeLookup = new Map(graph.edges.map((edge, index) => [resolveEdgeId(edge, index), edge]));
|
||||
const positionedEdges: PositionedEdge[] = (layout.edges ?? []).map((edge, index) => {
|
||||
const resolvedId = edge.id ?? `edge-${graphKey}-${index}`;
|
||||
const source = edgeLookup.get(resolvedId) ?? graph.edges[index];
|
||||
const points = edgeSectionsToPoints(edge.sections ?? []);
|
||||
return {
|
||||
...source,
|
||||
id: source.id ?? null,
|
||||
label: source.label ?? null,
|
||||
mechanism: source.mechanism ?? null,
|
||||
code_refs: source.code_refs ?? [],
|
||||
graphKey,
|
||||
resolvedId,
|
||||
points,
|
||||
path: pointsToPath(points),
|
||||
midpoint: edgeMidpoint(points),
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
graphKey,
|
||||
width: Math.max(720, layout.width ?? 720),
|
||||
height: Math.max(520, layout.height ?? 520),
|
||||
nodes: positionedNodes,
|
||||
edges: positionedEdges,
|
||||
};
|
||||
}
|
||||
|
||||
function buildNodeDegrees(graph: EpiphanyGraph) {
|
||||
const degrees = new Map<string, number>();
|
||||
for (const node of graph.nodes ?? []) {
|
||||
degrees.set(node.id, 0);
|
||||
}
|
||||
for (const edge of graph.edges ?? []) {
|
||||
degrees.set(edge.source_id, (degrees.get(edge.source_id) ?? 0) + 1);
|
||||
degrees.set(edge.target_id, (degrees.get(edge.target_id) ?? 0) + 1);
|
||||
}
|
||||
return degrees;
|
||||
}
|
||||
|
||||
function buildLinkCounts(graphKey: GraphKey, links: EpiphanyGraphLink[]) {
|
||||
const counts = new Map<string, number>();
|
||||
for (const link of links ?? []) {
|
||||
const nodeId =
|
||||
graphKey === "architecture" ? link.architecture_node_id : link.dataflow_node_id;
|
||||
counts.set(nodeId, (counts.get(nodeId) ?? 0) + 1);
|
||||
}
|
||||
return counts;
|
||||
}
|
||||
|
||||
function resolveEdgeId(edge: EpiphanyGraphEdge, index: number) {
|
||||
return edge.id?.trim() ? edge.id : `${edge.source_id}->${edge.target_id}:${edge.kind}:${index}`;
|
||||
}
|
||||
|
||||
function estimateNodeSize(
|
||||
node: { title: string; purpose: string; mechanism?: string | null; metaphor?: string | null },
|
||||
graphKey: GraphKey,
|
||||
) {
|
||||
const titleWeight = Math.min(node.title.length, 36);
|
||||
const purposeWeight = Math.min(node.purpose.length, 110);
|
||||
const widthFloor = graphKey === "architecture" ? 232 : 248;
|
||||
const width = clamp(widthFloor + titleWeight * 2.3 + purposeWeight * 0.22, widthFloor, 360);
|
||||
const detailLines =
|
||||
2 +
|
||||
(node.mechanism?.trim() ? 1 : 0) +
|
||||
(node.metaphor?.trim() ? 1 : 0);
|
||||
const height = clamp(100 + detailLines * 16, 108, 168);
|
||||
return { width, height };
|
||||
}
|
||||
|
||||
function edgeSectionsToPoints(sections: ElkSection[]) {
|
||||
const points: PositionedPoint[] = [];
|
||||
for (const section of sections) {
|
||||
if (section.startPoint) {
|
||||
points.push(section.startPoint);
|
||||
}
|
||||
for (const bendPoint of section.bendPoints ?? []) {
|
||||
points.push(bendPoint);
|
||||
}
|
||||
if (section.endPoint) {
|
||||
points.push(section.endPoint);
|
||||
}
|
||||
}
|
||||
return dedupeSequentialPoints(points);
|
||||
}
|
||||
|
||||
function pointsToPath(points: PositionedPoint[]) {
|
||||
if (points.length === 0) {
|
||||
return "";
|
||||
}
|
||||
const [first, ...rest] = points;
|
||||
return `M ${fmt(first.x)} ${fmt(first.y)} ${rest
|
||||
.map((point) => `L ${fmt(point.x)} ${fmt(point.y)}`)
|
||||
.join(" ")}`;
|
||||
}
|
||||
|
||||
function edgeMidpoint(points: PositionedPoint[]) {
|
||||
if (points.length === 0) {
|
||||
return { x: 0, y: 0 };
|
||||
}
|
||||
const midIndex = Math.floor(points.length / 2);
|
||||
return points[midIndex];
|
||||
}
|
||||
|
||||
function dedupeSequentialPoints(points: PositionedPoint[]) {
|
||||
const deduped: PositionedPoint[] = [];
|
||||
for (const point of points) {
|
||||
const previous = deduped[deduped.length - 1];
|
||||
if (!previous || previous.x !== point.x || previous.y !== point.y) {
|
||||
deduped.push(point);
|
||||
}
|
||||
}
|
||||
return deduped;
|
||||
}
|
||||
|
||||
function nodeBadgeText(title: string) {
|
||||
const words = title.split(/[\s/_-]+/).filter(Boolean);
|
||||
if (words.length === 0) {
|
||||
return "??";
|
||||
}
|
||||
if (words.length === 1) {
|
||||
return words[0].slice(0, 2).toUpperCase();
|
||||
}
|
||||
return `${words[0][0] ?? ""}${words[1][0] ?? ""}`.toUpperCase();
|
||||
}
|
||||
|
||||
function nodeFill(graphKey: GraphKey, status?: string | null) {
|
||||
if (status === "verified") {
|
||||
return graphKey === "architecture" ? "rgba(15, 118, 110, 0.28)" : "rgba(120, 53, 15, 0.3)";
|
||||
}
|
||||
if (status === "active") {
|
||||
return "rgba(67, 56, 202, 0.3)";
|
||||
}
|
||||
if (status === "prototype") {
|
||||
return "rgba(91, 33, 182, 0.28)";
|
||||
}
|
||||
return graphKey === "architecture" ? "rgba(8, 47, 73, 0.66)" : "rgba(58, 12, 33, 0.68)";
|
||||
}
|
||||
|
||||
function nodeStroke(graphKey: GraphKey, status?: string | null) {
|
||||
if (status === "verified") {
|
||||
return "#5eead4";
|
||||
}
|
||||
if (status === "in_progress") {
|
||||
return "#fbbf24";
|
||||
}
|
||||
if (status === "active") {
|
||||
return "#93c5fd";
|
||||
}
|
||||
if (status === "prototype") {
|
||||
return "#c084fc";
|
||||
}
|
||||
if (status === "proposed") {
|
||||
return "#f9a8d4";
|
||||
}
|
||||
return graphKey === "architecture" ? "#67e8f9" : "#fb7185";
|
||||
}
|
||||
|
||||
function clamp(value: number, min: number, max: number) {
|
||||
return Math.min(max, Math.max(min, value));
|
||||
}
|
||||
|
||||
function fmt(value: number) {
|
||||
return Number(value).toFixed(2).replace(/\.00$/, "");
|
||||
}
|
||||
295
web/epiphany-graph-viewer/src/lib/mock-state.json
Normal file
295
web/epiphany-graph-viewer/src/lib/mock-state.json
Normal file
|
|
@ -0,0 +1,295 @@
|
|||
{
|
||||
"architecture": {
|
||||
"nodes": [
|
||||
{
|
||||
"id": "arch-session-state",
|
||||
"title": "Session state store",
|
||||
"purpose": "Carry durable objective, graph, evidence, and churn state across turns.",
|
||||
"mechanism": "Lives on the session and gets rehydrated when the thread wakes back up.",
|
||||
"metaphor": "The map pinned to the workshop wall so nobody wanders off whistling.",
|
||||
"status": "verified",
|
||||
"code_refs": [
|
||||
{
|
||||
"path": "core/src/state/session.rs",
|
||||
"start_line": 36,
|
||||
"end_line": 121,
|
||||
"symbol": "SessionState::epiphany_state",
|
||||
"note": "Stored thread state"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "arch-prompt-renderer",
|
||||
"title": "Prompt renderer",
|
||||
"purpose": "Turn durable Epiphany state into a bounded instruction block for the agent.",
|
||||
"mechanism": "Summarizes the frontier, recent evidence, and live constraints into a compact prompt fragment.",
|
||||
"metaphor": "A folded field guide, not the whole filing cabinet.",
|
||||
"status": "in_progress",
|
||||
"code_refs": [
|
||||
{
|
||||
"path": "core/src/context/epiphany_state_instructions.rs",
|
||||
"start_line": 1,
|
||||
"end_line": 220,
|
||||
"symbol": "render_epiphany_state",
|
||||
"note": "Prompt shaping"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "arch-graph-promoter",
|
||||
"title": "Graph promoter",
|
||||
"purpose": "Promote observations and map updates into durable typed graph state.",
|
||||
"mechanism": "Validates graph patches before they enter the session state.",
|
||||
"metaphor": "The customs desk that stops counterfeit structure at the border.",
|
||||
"status": "verified",
|
||||
"code_refs": [
|
||||
{
|
||||
"path": "epiphany-core/src/promotion.rs",
|
||||
"start_line": 268,
|
||||
"end_line": 352,
|
||||
"symbol": "validate_graphs",
|
||||
"note": "Patch validation"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "arch-tool-bridge",
|
||||
"title": "Tool bridge",
|
||||
"purpose": "Translate model intent into tool calls without letting the prompt turn into soup.",
|
||||
"mechanism": "Binds the runtime tool surface to the working context and execution policy.",
|
||||
"metaphor": "The gearbox between intention and actual machinery.",
|
||||
"status": "proposed",
|
||||
"code_refs": [
|
||||
{
|
||||
"path": "vendor/codex/codex-rs/core/src/tools/mod.rs",
|
||||
"symbol": "ToolRuntime",
|
||||
"note": "Tool execution seam"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "arch-gui-shell",
|
||||
"title": "Graph GUI shell",
|
||||
"purpose": "Expose architecture, dataflow, and cross-links in a browsable visual surface.",
|
||||
"mechanism": "Embeds the web viewer and routes clicks back into the rest of the application.",
|
||||
"metaphor": "The dashboard where the workshop lights stop flickering and start admitting what they power.",
|
||||
"status": "prototype",
|
||||
"code_refs": [
|
||||
{
|
||||
"path": "gui/src/routes/graphs.tsx",
|
||||
"symbol": "GraphRoute",
|
||||
"note": "Planned viewer slot"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"edges": [
|
||||
{
|
||||
"id": "edge-session-renderer",
|
||||
"source_id": "arch-session-state",
|
||||
"target_id": "arch-prompt-renderer",
|
||||
"kind": "renders-into",
|
||||
"label": "bounded fragment",
|
||||
"mechanism": "Session state is summarized into prompt context.",
|
||||
"code_refs": [
|
||||
{
|
||||
"path": "vendor/codex/codex-rs/core/src/session/mod.rs",
|
||||
"symbol": "build_initial_context",
|
||||
"note": "Prompt assembly slot"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "edge-promoter-session",
|
||||
"source_id": "arch-graph-promoter",
|
||||
"target_id": "arch-session-state",
|
||||
"kind": "writes",
|
||||
"label": "validated updates",
|
||||
"mechanism": "Promotion mutates durable state only after structural checks pass."
|
||||
},
|
||||
{
|
||||
"id": "edge-tool-renderer",
|
||||
"source_id": "arch-tool-bridge",
|
||||
"target_id": "arch-prompt-renderer",
|
||||
"kind": "feeds",
|
||||
"label": "tool surface",
|
||||
"mechanism": "The prompt renderer reflects which tools the agent can actually use."
|
||||
},
|
||||
{
|
||||
"id": "edge-gui-session",
|
||||
"source_id": "arch-gui-shell",
|
||||
"target_id": "arch-session-state",
|
||||
"kind": "reads",
|
||||
"label": "typed state",
|
||||
"mechanism": "The GUI consumes the same durable graph state the agent sees."
|
||||
},
|
||||
{
|
||||
"id": "edge-gui-promoter",
|
||||
"source_id": "arch-gui-shell",
|
||||
"target_id": "arch-graph-promoter",
|
||||
"kind": "inspects",
|
||||
"label": "validation status",
|
||||
"mechanism": "Viewer health should expose whether the underlying graph is coherent."
|
||||
}
|
||||
]
|
||||
},
|
||||
"dataflow": {
|
||||
"nodes": [
|
||||
{
|
||||
"id": "flow-observations",
|
||||
"title": "Observations stream",
|
||||
"purpose": "Capture recent findings and raw signals before they harden into durable structure.",
|
||||
"mechanism": "Tool results and textual observations get queued as evidence inputs.",
|
||||
"metaphor": "Shavings on the floor before you decide what piece of furniture you were making.",
|
||||
"status": "verified",
|
||||
"code_refs": [
|
||||
{
|
||||
"path": "epiphany-core/src/evidence.rs",
|
||||
"symbol": "EpiphanyObservation",
|
||||
"note": "Evidence capture"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "flow-proposal",
|
||||
"title": "Graph proposal",
|
||||
"purpose": "Stage candidate graph edits before promotion.",
|
||||
"mechanism": "Proposals carry candidate nodes, edges, and cross-links for validation.",
|
||||
"metaphor": "Wet concrete in the formwork, not the finished slab.",
|
||||
"status": "verified",
|
||||
"code_refs": [
|
||||
{
|
||||
"path": "epiphany-core/src/proposal.rs",
|
||||
"symbol": "EpiphanyProposal",
|
||||
"note": "Proposal assembly"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "flow-validated-graph",
|
||||
"title": "Validated graph patch",
|
||||
"purpose": "Produce a structurally safe graph update that can survive contact with persistence.",
|
||||
"mechanism": "Checks required fields, reference integrity, and duplicate IDs before promotion.",
|
||||
"metaphor": "A passport stamped by someone who actually looked at the face.",
|
||||
"status": "verified",
|
||||
"code_refs": [
|
||||
{
|
||||
"path": "epiphany-core/src/promotion.rs",
|
||||
"start_line": 268,
|
||||
"end_line": 352,
|
||||
"symbol": "validate_graph",
|
||||
"note": "Graph validation"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "flow-state-fragment",
|
||||
"title": "Epiphany state fragment",
|
||||
"purpose": "Expose the live graph frontier to the prompt without dumping the whole machine room into context.",
|
||||
"mechanism": "Summarizes only the active map and recent changes.",
|
||||
"metaphor": "A flashlight beam, not the sun.",
|
||||
"status": "prototype",
|
||||
"code_refs": [
|
||||
{
|
||||
"path": "core/src/context/epiphany_state_instructions.rs",
|
||||
"symbol": "render_epiphany_state",
|
||||
"note": "Prompt fragment"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "flow-agent-turn",
|
||||
"title": "Agent turn",
|
||||
"purpose": "Consume the bounded state and produce the next action, hypothesis, or patch.",
|
||||
"mechanism": "The model uses the rendered map as one constraint surface among several.",
|
||||
"metaphor": "The monkey at the lathe, but hopefully with a checklist.",
|
||||
"status": "active",
|
||||
"code_refs": [
|
||||
{
|
||||
"path": "vendor/codex/codex-rs/core/src/session/mod.rs",
|
||||
"symbol": "run_turn",
|
||||
"note": "Turn execution"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"edges": [
|
||||
{
|
||||
"id": "edge-observations-proposal",
|
||||
"source_id": "flow-observations",
|
||||
"target_id": "flow-proposal",
|
||||
"kind": "feeds",
|
||||
"label": "candidate structure",
|
||||
"mechanism": "Raw observations feed proposal generation."
|
||||
},
|
||||
{
|
||||
"id": "edge-proposal-validation",
|
||||
"source_id": "flow-proposal",
|
||||
"target_id": "flow-validated-graph",
|
||||
"kind": "validated-as",
|
||||
"label": "structural checks",
|
||||
"mechanism": "Only well-formed graph edits get promoted."
|
||||
},
|
||||
{
|
||||
"id": "edge-validated-fragment",
|
||||
"source_id": "flow-validated-graph",
|
||||
"target_id": "flow-state-fragment",
|
||||
"kind": "rendered-as",
|
||||
"label": "bounded summary",
|
||||
"mechanism": "Validated graph state is summarized into promptable form."
|
||||
},
|
||||
{
|
||||
"id": "edge-fragment-turn",
|
||||
"source_id": "flow-state-fragment",
|
||||
"target_id": "flow-agent-turn",
|
||||
"kind": "feeds",
|
||||
"label": "active map",
|
||||
"mechanism": "The current state fragment shapes the next turn."
|
||||
},
|
||||
{
|
||||
"id": "edge-turn-observations",
|
||||
"source_id": "flow-agent-turn",
|
||||
"target_id": "flow-observations",
|
||||
"kind": "produces",
|
||||
"label": "new evidence",
|
||||
"mechanism": "Actions create more observations, because life is a wheel."
|
||||
}
|
||||
]
|
||||
},
|
||||
"links": [
|
||||
{
|
||||
"dataflow_node_id": "flow-state-fragment",
|
||||
"architecture_node_id": "arch-prompt-renderer",
|
||||
"relationship": "rendered-by",
|
||||
"code_refs": [
|
||||
{
|
||||
"path": "core/src/context/epiphany_state_instructions.rs",
|
||||
"symbol": "render_epiphany_state",
|
||||
"note": "Renderer implementation"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"dataflow_node_id": "flow-validated-graph",
|
||||
"architecture_node_id": "arch-graph-promoter",
|
||||
"relationship": "promoted-by",
|
||||
"code_refs": [
|
||||
{
|
||||
"path": "epiphany-core/src/promotion.rs",
|
||||
"symbol": "validate_graphs",
|
||||
"note": "Promotion validation"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"dataflow_node_id": "flow-agent-turn",
|
||||
"architecture_node_id": "arch-tool-bridge",
|
||||
"relationship": "executes-through"
|
||||
},
|
||||
{
|
||||
"dataflow_node_id": "flow-agent-turn",
|
||||
"architecture_node_id": "arch-gui-shell",
|
||||
"relationship": "inspected-in"
|
||||
}
|
||||
]
|
||||
}
|
||||
4
web/epiphany-graph-viewer/src/lib/mock-state.ts
Normal file
4
web/epiphany-graph-viewer/src/lib/mock-state.ts
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
import rawState from "./mock-state.json";
|
||||
import type { EpiphanyGraphsState } from "./types";
|
||||
|
||||
export const mockEpiphanyGraphState = rawState as EpiphanyGraphsState;
|
||||
115
web/epiphany-graph-viewer/src/lib/types.ts
Normal file
115
web/epiphany-graph-viewer/src/lib/types.ts
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
import type { CSSProperties } from "react";
|
||||
|
||||
export type GraphKey = "architecture" | "dataflow";
|
||||
|
||||
export interface EpiphanyCodeRef {
|
||||
path: string;
|
||||
start_line?: number | null;
|
||||
end_line?: number | null;
|
||||
symbol?: string | null;
|
||||
note?: string | null;
|
||||
}
|
||||
|
||||
export interface EpiphanyGraphNode {
|
||||
id: string;
|
||||
title: string;
|
||||
purpose: string;
|
||||
mechanism?: string | null;
|
||||
metaphor?: string | null;
|
||||
status?: string | null;
|
||||
code_refs?: EpiphanyCodeRef[];
|
||||
}
|
||||
|
||||
export interface EpiphanyGraphEdge {
|
||||
source_id: string;
|
||||
target_id: string;
|
||||
kind: string;
|
||||
id?: string | null;
|
||||
label?: string | null;
|
||||
mechanism?: string | null;
|
||||
code_refs?: EpiphanyCodeRef[];
|
||||
}
|
||||
|
||||
export interface EpiphanyGraph {
|
||||
nodes: EpiphanyGraphNode[];
|
||||
edges: EpiphanyGraphEdge[];
|
||||
}
|
||||
|
||||
export interface EpiphanyGraphLink {
|
||||
dataflow_node_id: string;
|
||||
architecture_node_id: string;
|
||||
relationship?: string | null;
|
||||
code_refs?: EpiphanyCodeRef[];
|
||||
}
|
||||
|
||||
export interface EpiphanyGraphsState {
|
||||
architecture: EpiphanyGraph;
|
||||
dataflow: EpiphanyGraph;
|
||||
links: EpiphanyGraphLink[];
|
||||
}
|
||||
|
||||
export interface EpiphanyValidationIssue {
|
||||
scope: string;
|
||||
message: string;
|
||||
}
|
||||
|
||||
export type ViewerSelection =
|
||||
| {
|
||||
kind: "node";
|
||||
graphKey: GraphKey;
|
||||
nodeId: string;
|
||||
}
|
||||
| {
|
||||
kind: "edge";
|
||||
graphKey: GraphKey;
|
||||
edgeId: string;
|
||||
};
|
||||
|
||||
export interface EpiphanyGraphViewerProps {
|
||||
state: EpiphanyGraphsState;
|
||||
initialGraph?: GraphKey;
|
||||
style?: CSSProperties;
|
||||
className?: string;
|
||||
title?: string;
|
||||
onCodeRefSelect?: (
|
||||
codeRef: EpiphanyCodeRef,
|
||||
context: {
|
||||
graphKey: GraphKey;
|
||||
selection: ViewerSelection | null;
|
||||
},
|
||||
) => void;
|
||||
}
|
||||
|
||||
export interface PositionedPoint {
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
|
||||
export interface PositionedNode extends EpiphanyGraphNode {
|
||||
graphKey: GraphKey;
|
||||
x: number;
|
||||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
degree: number;
|
||||
linkCount: number;
|
||||
badgeText: string;
|
||||
fill: string;
|
||||
stroke: string;
|
||||
}
|
||||
|
||||
export interface PositionedEdge extends EpiphanyGraphEdge {
|
||||
resolvedId: string;
|
||||
graphKey: GraphKey;
|
||||
points: PositionedPoint[];
|
||||
path: string;
|
||||
midpoint: PositionedPoint;
|
||||
}
|
||||
|
||||
export interface GraphLayout {
|
||||
graphKey: GraphKey;
|
||||
width: number;
|
||||
height: number;
|
||||
nodes: PositionedNode[];
|
||||
edges: PositionedEdge[];
|
||||
}
|
||||
135
web/epiphany-graph-viewer/src/lib/validation.ts
Normal file
135
web/epiphany-graph-viewer/src/lib/validation.ts
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
import type {
|
||||
EpiphanyGraph,
|
||||
EpiphanyGraphsState,
|
||||
EpiphanyValidationIssue,
|
||||
GraphKey,
|
||||
} from "./types";
|
||||
|
||||
export function validateEpiphanyGraphsState(state: EpiphanyGraphsState): EpiphanyValidationIssue[] {
|
||||
const issues: EpiphanyValidationIssue[] = [];
|
||||
const architectureIds = validateGraph("architecture", state.architecture, issues);
|
||||
const dataflowIds = validateGraph("dataflow", state.dataflow, issues);
|
||||
const linkPairs = new Set<string>();
|
||||
|
||||
for (const link of state.links ?? []) {
|
||||
if (!link.dataflow_node_id?.trim()) {
|
||||
issues.push({
|
||||
scope: "links",
|
||||
message: "Link is missing a nonempty dataflow_node_id.",
|
||||
});
|
||||
}
|
||||
if (!link.architecture_node_id?.trim()) {
|
||||
issues.push({
|
||||
scope: "links",
|
||||
message: "Link is missing a nonempty architecture_node_id.",
|
||||
});
|
||||
}
|
||||
if (link.dataflow_node_id?.trim() && !dataflowIds.has(link.dataflow_node_id)) {
|
||||
issues.push({
|
||||
scope: "links",
|
||||
message: `Link references missing dataflow node '${link.dataflow_node_id}'.`,
|
||||
});
|
||||
}
|
||||
if (link.architecture_node_id?.trim() && !architectureIds.has(link.architecture_node_id)) {
|
||||
issues.push({
|
||||
scope: "links",
|
||||
message: `Link references missing architecture node '${link.architecture_node_id}'.`,
|
||||
});
|
||||
}
|
||||
const pairKey = `${link.dataflow_node_id}::${link.architecture_node_id}`;
|
||||
if (linkPairs.has(pairKey)) {
|
||||
issues.push({
|
||||
scope: "links",
|
||||
message: `Duplicate cross-link '${pairKey}'.`,
|
||||
});
|
||||
}
|
||||
linkPairs.add(pairKey);
|
||||
}
|
||||
|
||||
return issues;
|
||||
}
|
||||
|
||||
function validateGraph(
|
||||
graphKey: GraphKey,
|
||||
graph: EpiphanyGraph,
|
||||
issues: EpiphanyValidationIssue[],
|
||||
): Set<string> {
|
||||
const nodeIds = new Set<string>();
|
||||
const edgeIds = new Set<string>();
|
||||
|
||||
for (const node of graph.nodes ?? []) {
|
||||
if (!node.id?.trim()) {
|
||||
issues.push({
|
||||
scope: graphKey,
|
||||
message: "Node is missing a nonempty id.",
|
||||
});
|
||||
}
|
||||
if (!node.title?.trim()) {
|
||||
issues.push({
|
||||
scope: graphKey,
|
||||
message: `Node '${node.id || "<unknown>"}' is missing a nonempty title.`,
|
||||
});
|
||||
}
|
||||
if (!node.purpose?.trim()) {
|
||||
issues.push({
|
||||
scope: graphKey,
|
||||
message: `Node '${node.id || "<unknown>"}' is missing a nonempty purpose.`,
|
||||
});
|
||||
}
|
||||
if (nodeIds.has(node.id)) {
|
||||
issues.push({
|
||||
scope: graphKey,
|
||||
message: `Duplicate node id '${node.id}'.`,
|
||||
});
|
||||
}
|
||||
nodeIds.add(node.id);
|
||||
}
|
||||
|
||||
for (const edge of graph.edges ?? []) {
|
||||
if (!edge.source_id?.trim()) {
|
||||
issues.push({
|
||||
scope: graphKey,
|
||||
message: "Edge is missing a nonempty source_id.",
|
||||
});
|
||||
}
|
||||
if (!edge.target_id?.trim()) {
|
||||
issues.push({
|
||||
scope: graphKey,
|
||||
message: "Edge is missing a nonempty target_id.",
|
||||
});
|
||||
}
|
||||
if (!edge.kind?.trim()) {
|
||||
issues.push({
|
||||
scope: graphKey,
|
||||
message: "Edge is missing a nonempty kind.",
|
||||
});
|
||||
}
|
||||
if (edge.source_id?.trim() && !nodeIds.has(edge.source_id)) {
|
||||
issues.push({
|
||||
scope: graphKey,
|
||||
message: `Edge '${edge.id || fallbackEdgeId(edge)}' references missing source node '${edge.source_id}'.`,
|
||||
});
|
||||
}
|
||||
if (edge.target_id?.trim() && !nodeIds.has(edge.target_id)) {
|
||||
issues.push({
|
||||
scope: graphKey,
|
||||
message: `Edge '${edge.id || fallbackEdgeId(edge)}' references missing target node '${edge.target_id}'.`,
|
||||
});
|
||||
}
|
||||
if (edge.id?.trim()) {
|
||||
if (edgeIds.has(edge.id)) {
|
||||
issues.push({
|
||||
scope: graphKey,
|
||||
message: `Duplicate edge id '${edge.id}'.`,
|
||||
});
|
||||
}
|
||||
edgeIds.add(edge.id);
|
||||
}
|
||||
}
|
||||
|
||||
return nodeIds;
|
||||
}
|
||||
|
||||
function fallbackEdgeId(edge: { source_id: string; target_id: string; kind: string }) {
|
||||
return `${edge.source_id}->${edge.target_id}:${edge.kind}`;
|
||||
}
|
||||
9
web/epiphany-graph-viewer/src/main.tsx
Normal file
9
web/epiphany-graph-viewer/src/main.tsx
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import React from "react";
|
||||
import ReactDOM from "react-dom/client";
|
||||
import { App } from "./App";
|
||||
|
||||
ReactDOM.createRoot(document.getElementById("root")!).render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>,
|
||||
);
|
||||
17
web/epiphany-graph-viewer/tsconfig.json
Normal file
17
web/epiphany-graph-viewer/tsconfig.json
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2022",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Bundler",
|
||||
"lib": ["DOM", "DOM.Iterable", "ES2022"],
|
||||
"jsx": "react-jsx",
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"noEmit": true,
|
||||
"types": ["vite/client"]
|
||||
},
|
||||
"include": ["src", "vite.config.ts"]
|
||||
}
|
||||
20
web/epiphany-graph-viewer/vite.config.ts
Normal file
20
web/epiphany-graph-viewer/vite.config.ts
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import react from "@vitejs/plugin-react";
|
||||
import { defineConfig } from "vite";
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
build: {
|
||||
rollupOptions: {
|
||||
output: {
|
||||
manualChunks: {
|
||||
react: ["react", "react-dom"],
|
||||
elk: ["elkjs/lib/elk.bundled.js"],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
server: {
|
||||
host: "127.0.0.1",
|
||||
port: 4177,
|
||||
},
|
||||
});
|
||||
Loading…
Reference in a new issue