structured-context-map-views 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ParameterControls-BsdG5GDk.js +1047 -0
- package/dist/ParameterControls-BsdG5GDk.js.map +1 -0
- package/dist/artifact.html +601 -0
- package/dist/artifact.js +237 -0
- package/dist/artifact.js.map +1 -0
- package/dist/cli.js +114 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.js +2 -1044
- package/dist/node-BceB0Wzc.js +106 -0
- package/dist/node-BceB0Wzc.js.map +1 -0
- package/dist/node.js +1 -105
- package/dist/types/artifact/load.d.ts +13 -0
- package/dist/types/artifact/main.d.ts +1 -0
- package/dist/types/node/cli.d.ts +2 -0
- package/dist/types/node/snapshot.d.ts +20 -0
- package/package.json +8 -4
- package/dist/index.js.map +0 -1
- package/dist/node.js.map +0 -1
package/dist/artifact.js
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { c as annotationsFrom, s as MapView, t as ParameterControls } from "./ParameterControls-BsdG5GDk.js";
|
|
2
|
+
import { useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
import { createRoot } from "react-dom/client";
|
|
5
|
+
import { spaceGraphFrom } from "structured-context/browser";
|
|
6
|
+
//#region src/artifact/load.ts
|
|
7
|
+
var SPACES = "spaces";
|
|
8
|
+
var TIMEOUT_MS = 1e4;
|
|
9
|
+
/** Every space written to the artifact's `spaces` collection. Rejects with a message fit to show the viewer. */
|
|
10
|
+
async function loadSpaces() {
|
|
11
|
+
const claude = window.claude;
|
|
12
|
+
const db = claude ? await claude.use("db") : null;
|
|
13
|
+
if (!db) throw new Error("This page needs the artifact database, which is not available to this viewer.");
|
|
14
|
+
let timer;
|
|
15
|
+
const timeout = new Promise((_, reject) => {
|
|
16
|
+
timer = setTimeout(() => reject(/* @__PURE__ */ new Error("Reading the artifact database timed out.")), TIMEOUT_MS);
|
|
17
|
+
});
|
|
18
|
+
const spaces = (await Promise.race([db.collection(SPACES).get(), timeout]).finally(() => clearTimeout(timer))).docs.flatMap((doc) => {
|
|
19
|
+
const data = doc.data();
|
|
20
|
+
return data ? [toSpace(doc.id, data)] : [];
|
|
21
|
+
});
|
|
22
|
+
if (spaces.length === 0) throw new Error(`Nothing to show yet: no space has been written to "${SPACES}" in the artifact database.`);
|
|
23
|
+
return spaces;
|
|
24
|
+
}
|
|
25
|
+
function toSpace(name, data) {
|
|
26
|
+
const json = (field) => {
|
|
27
|
+
const value = data[field];
|
|
28
|
+
if (typeof value !== "string") throw new Error(`Space "${name}": missing "${field}" in the artifact database.`);
|
|
29
|
+
return JSON.parse(value);
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
name,
|
|
33
|
+
schemaId: typeof data.schemaId === "string" ? data.schemaId : void 0,
|
|
34
|
+
graph: json("graph"),
|
|
35
|
+
validation: json("validation"),
|
|
36
|
+
definitions: json("definitions")
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/artifact/main.tsx
|
|
41
|
+
function App() {
|
|
42
|
+
const [state, setState] = useState({ status: "loading" });
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
loadSpaces().then((spaces) => setState({
|
|
45
|
+
status: "ready",
|
|
46
|
+
spaces
|
|
47
|
+
}), (err) => setState({
|
|
48
|
+
status: "error",
|
|
49
|
+
message: err instanceof Error ? err.message : String(err)
|
|
50
|
+
}));
|
|
51
|
+
}, []);
|
|
52
|
+
if (state.status === "loading") return /* @__PURE__ */ jsx("p", {
|
|
53
|
+
className: "art-message",
|
|
54
|
+
children: "Loading from the artifact database…"
|
|
55
|
+
});
|
|
56
|
+
if (state.status === "error") return /* @__PURE__ */ jsx("p", {
|
|
57
|
+
className: "art-message",
|
|
58
|
+
children: state.message
|
|
59
|
+
});
|
|
60
|
+
return /* @__PURE__ */ jsx(Viewer, { spaces: state.spaces });
|
|
61
|
+
}
|
|
62
|
+
function Viewer({ spaces }) {
|
|
63
|
+
const [spaceName, setSpaceName] = useState(spaces[0].name);
|
|
64
|
+
const space = spaces.find((s) => s.name === spaceName);
|
|
65
|
+
const [viewId, setViewId] = useState(space.definitions[0]?.id);
|
|
66
|
+
const definition = space.definitions.find((d) => d.id === viewId) ?? space.definitions[0];
|
|
67
|
+
const [values, setValues] = useState({});
|
|
68
|
+
const [selectedId, setSelectedId] = useState();
|
|
69
|
+
const graph = useMemo(() => spaceGraphFrom(space.graph), [space]);
|
|
70
|
+
const annotated = useMemo(() => annotationsFrom(space.validation, graph), [space, graph]);
|
|
71
|
+
const mapRef = useNodeLabels(graph, definition);
|
|
72
|
+
if (!definition) return /* @__PURE__ */ jsxs("p", {
|
|
73
|
+
className: "art-message",
|
|
74
|
+
children: [
|
|
75
|
+
"No map views apply to the schema of \"",
|
|
76
|
+
space.name,
|
|
77
|
+
"\"."
|
|
78
|
+
]
|
|
79
|
+
});
|
|
80
|
+
const selected = selectedId ? graph.nodes.get(selectedId) : void 0;
|
|
81
|
+
const results = selected ? annotated.annotations.get(selected.id) ?? [] : [];
|
|
82
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
83
|
+
className: "art-root",
|
|
84
|
+
children: [/* @__PURE__ */ jsxs("header", {
|
|
85
|
+
className: "art-bar",
|
|
86
|
+
children: [
|
|
87
|
+
spaces.length > 1 && /* @__PURE__ */ jsx("select", {
|
|
88
|
+
"aria-label": "Space",
|
|
89
|
+
value: spaceName,
|
|
90
|
+
onChange: (e) => {
|
|
91
|
+
const next = spaces.find((s) => s.name === e.target.value);
|
|
92
|
+
setSpaceName(next.name);
|
|
93
|
+
setViewId(next.definitions[0]?.id);
|
|
94
|
+
setValues({});
|
|
95
|
+
setSelectedId(void 0);
|
|
96
|
+
},
|
|
97
|
+
children: spaces.map((s) => /* @__PURE__ */ jsx("option", {
|
|
98
|
+
value: s.name,
|
|
99
|
+
children: s.name
|
|
100
|
+
}, s.name))
|
|
101
|
+
}),
|
|
102
|
+
space.definitions.length > 1 && /* @__PURE__ */ jsx("select", {
|
|
103
|
+
"aria-label": "Map view",
|
|
104
|
+
value: definition.id,
|
|
105
|
+
onChange: (e) => {
|
|
106
|
+
setViewId(e.target.value);
|
|
107
|
+
setValues({});
|
|
108
|
+
},
|
|
109
|
+
children: space.definitions.map((d) => /* @__PURE__ */ jsx("option", {
|
|
110
|
+
value: d.id,
|
|
111
|
+
children: d.title
|
|
112
|
+
}, d.id))
|
|
113
|
+
}),
|
|
114
|
+
/* @__PURE__ */ jsx(ParameterControls, {
|
|
115
|
+
definition,
|
|
116
|
+
values,
|
|
117
|
+
onChange: (name, value) => setValues((prev) => ({
|
|
118
|
+
...prev,
|
|
119
|
+
[name]: value
|
|
120
|
+
}))
|
|
121
|
+
})
|
|
122
|
+
]
|
|
123
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
124
|
+
className: "art-body",
|
|
125
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
126
|
+
className: "art-map",
|
|
127
|
+
ref: mapRef,
|
|
128
|
+
children: /* @__PURE__ */ jsx(MapView, {
|
|
129
|
+
definition,
|
|
130
|
+
graph,
|
|
131
|
+
values,
|
|
132
|
+
annotations: annotated.annotations,
|
|
133
|
+
onNodeSelect: (node) => setSelectedId(node.id)
|
|
134
|
+
})
|
|
135
|
+
}), (selected || annotated.unattached.length > 0) && /* @__PURE__ */ jsxs("aside", {
|
|
136
|
+
className: "art-panel",
|
|
137
|
+
"aria-label": "Validation results",
|
|
138
|
+
children: [selected && /* @__PURE__ */ jsxs("section", { children: [
|
|
139
|
+
/* @__PURE__ */ jsx("button", {
|
|
140
|
+
type: "button",
|
|
141
|
+
className: "art-close",
|
|
142
|
+
"aria-label": "Close",
|
|
143
|
+
onClick: () => setSelectedId(void 0),
|
|
144
|
+
children: "×"
|
|
145
|
+
}),
|
|
146
|
+
/* @__PURE__ */ jsx("p", {
|
|
147
|
+
className: "art-type",
|
|
148
|
+
children: selected.resolvedType
|
|
149
|
+
}),
|
|
150
|
+
/* @__PURE__ */ jsx("h2", { children: selected.title }),
|
|
151
|
+
results.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("h3", { children: "Validation" }), /* @__PURE__ */ jsx(Results, { items: results })] }),
|
|
152
|
+
/* @__PURE__ */ jsx(Fields, { data: selected.schemaData }),
|
|
153
|
+
selected.content && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("h3", { children: "Content" }), /* @__PURE__ */ jsx("p", {
|
|
154
|
+
className: "art-content",
|
|
155
|
+
children: selected.content
|
|
156
|
+
})] }),
|
|
157
|
+
selected.source && /* @__PURE__ */ jsx("p", {
|
|
158
|
+
className: "art-muted",
|
|
159
|
+
children: selected.source.file
|
|
160
|
+
})
|
|
161
|
+
] }), annotated.unattached.length > 0 && /* @__PURE__ */ jsxs("section", { children: [/* @__PURE__ */ jsxs("h3", { children: [
|
|
162
|
+
"Not on a node (",
|
|
163
|
+
annotated.unattached.length,
|
|
164
|
+
")"
|
|
165
|
+
] }), /* @__PURE__ */ jsx(Results, { items: annotated.unattached })] })]
|
|
166
|
+
})]
|
|
167
|
+
})]
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
var SKIPPED_FIELDS = /* @__PURE__ */ new Set([
|
|
171
|
+
"title",
|
|
172
|
+
"type",
|
|
173
|
+
"content"
|
|
174
|
+
]);
|
|
175
|
+
var isEmpty = (v) => v === void 0 || v === null || v === "" || Array.isArray(v) && v.length === 0;
|
|
176
|
+
var asText = (v) => Array.isArray(v) ? v.map(asText).join(", ") : v !== null && typeof v === "object" ? JSON.stringify(v) : String(v);
|
|
177
|
+
/** The node's fields as a list; the title, type and body are shown elsewhere. */
|
|
178
|
+
function Fields({ data }) {
|
|
179
|
+
const fields = Object.entries(data).filter(([name, value]) => !SKIPPED_FIELDS.has(name) && !isEmpty(value));
|
|
180
|
+
if (fields.length === 0) return null;
|
|
181
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("h3", { children: "Fields" }), /* @__PURE__ */ jsx("dl", {
|
|
182
|
+
className: "art-fields",
|
|
183
|
+
children: fields.map(([name, value]) => /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", { children: name }), /* @__PURE__ */ jsx("dd", { children: asText(value) })] }, name))
|
|
184
|
+
})] });
|
|
185
|
+
}
|
|
186
|
+
function Results({ items }) {
|
|
187
|
+
return /* @__PURE__ */ jsx("ul", {
|
|
188
|
+
className: "art-results",
|
|
189
|
+
children: items.map((a, i) => /* @__PURE__ */ jsxs("li", { children: [
|
|
190
|
+
/* @__PURE__ */ jsx("span", {
|
|
191
|
+
className: `art-severity art-${a.severity}`,
|
|
192
|
+
children: a.severity
|
|
193
|
+
}),
|
|
194
|
+
" ",
|
|
195
|
+
/* @__PURE__ */ jsx("span", {
|
|
196
|
+
className: "art-muted",
|
|
197
|
+
children: a.ruleId ? `${a.source} · ${a.ruleId}` : a.source
|
|
198
|
+
}),
|
|
199
|
+
a.nodeId && /* @__PURE__ */ jsxs("span", {
|
|
200
|
+
className: "art-muted",
|
|
201
|
+
children: [" · ", a.nodeId]
|
|
202
|
+
}),
|
|
203
|
+
/* @__PURE__ */ jsx("div", { children: a.message })
|
|
204
|
+
] }, i))
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Names each card for the viewer's comment mode, which reads the location of a comment from the
|
|
209
|
+
* element's accessible name. The name leads with the map view and node id so it survives the
|
|
210
|
+
* viewer's truncation, then gives the type and title: `<view>/<nodeId>: <type> <title>`. An agent
|
|
211
|
+
* reading the comment resolves the id back to the node from the db.
|
|
212
|
+
*/
|
|
213
|
+
function useNodeLabels(graph, definition) {
|
|
214
|
+
const ref = useRef(null);
|
|
215
|
+
useEffect(() => {
|
|
216
|
+
const root = ref.current;
|
|
217
|
+
if (!root || !definition) return;
|
|
218
|
+
const stamp = () => {
|
|
219
|
+
for (const card of root.querySelectorAll("[data-node-id]")) {
|
|
220
|
+
const node = graph.nodes.get(card.dataset.nodeId);
|
|
221
|
+
if (node) card.setAttribute("aria-label", `${definition.id}/${node.id}: ${node.resolvedType} ${node.title}`);
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
stamp();
|
|
225
|
+
const observer = new MutationObserver(stamp);
|
|
226
|
+
observer.observe(root, {
|
|
227
|
+
childList: true,
|
|
228
|
+
subtree: true
|
|
229
|
+
});
|
|
230
|
+
return () => observer.disconnect();
|
|
231
|
+
}, [graph, definition]);
|
|
232
|
+
return ref;
|
|
233
|
+
}
|
|
234
|
+
createRoot(document.getElementById("root")).render(/* @__PURE__ */ jsx(App, {}));
|
|
235
|
+
//#endregion
|
|
236
|
+
|
|
237
|
+
//# sourceMappingURL=artifact.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"artifact.js","names":["_Fragment"],"sources":["../src/artifact/load.ts","../src/artifact/main.tsx"],"sourcesContent":["import type { spaceGraphFrom } from 'structured-context/browser';\nimport type { ValidationInput } from '../core/annotations';\nimport type { MapViewDefinition } from '../core/definition';\n\n/** A space as the artifact's db holds it: the `export` command's document with its parts as JSON strings. */\nexport type LoadedSpace = {\n name: string;\n schemaId: string | undefined;\n graph: Parameters<typeof spaceGraphFrom>[0];\n validation: ValidationInput;\n definitions: MapViewDefinition[];\n};\n\nconst SPACES = 'spaces';\nconst TIMEOUT_MS = 10_000;\n\ntype Db = {\n collection(path: string): { get(): Promise<{ docs: { id: string; data(): Record<string, unknown> | undefined }[] }> };\n};\n\n/** Every space written to the artifact's `spaces` collection. Rejects with a message fit to show the viewer. */\nexport async function loadSpaces(): Promise<LoadedSpace[]> {\n const claude = (window as unknown as { claude?: { use(name: string): Promise<unknown> } }).claude;\n const db = (claude ? await claude.use('db') : null) as Db | null;\n if (!db) throw new Error('This page needs the artifact database, which is not available to this viewer.');\n\n let timer: ReturnType<typeof setTimeout> | undefined;\n const timeout = new Promise<never>((_, reject) => {\n timer = setTimeout(() => reject(new Error('Reading the artifact database timed out.')), TIMEOUT_MS);\n });\n const snapshot = await Promise.race([db.collection(SPACES).get(), timeout]).finally(() => clearTimeout(timer));\n const spaces = snapshot.docs.flatMap((doc) => {\n const data = doc.data();\n return data ? [toSpace(doc.id, data)] : [];\n });\n if (spaces.length === 0)\n throw new Error(`Nothing to show yet: no space has been written to \"${SPACES}\" in the artifact database.`);\n return spaces;\n}\n\nfunction toSpace(name: string, data: Record<string, unknown>): LoadedSpace {\n const json = (field: string) => {\n const value = data[field];\n if (typeof value !== 'string') throw new Error(`Space \"${name}\": missing \"${field}\" in the artifact database.`);\n return JSON.parse(value);\n };\n return {\n name,\n schemaId: typeof data.schemaId === 'string' ? data.schemaId : undefined,\n graph: json('graph'),\n validation: json('validation'),\n definitions: json('definitions'),\n };\n}\n","import { useEffect, useMemo, useRef, useState } from 'react';\nimport { createRoot } from 'react-dom/client';\nimport { spaceGraphFrom } from 'structured-context/browser';\nimport { annotationsFrom } from '../core/annotations';\nimport type { MapViewDefinition, ParameterValues } from '../core/definition';\nimport { MapView } from '../layouts/MapView';\nimport { ParameterControls } from '../layouts/ParameterControls';\nimport { type LoadedSpace, loadSpaces } from './load';\n\n/**\n * The host for a Claude artifact: renders the spaces the publishing agent wrote to the artifact's\n * db (the `export` command's document, one per space) with the parameter controls and a panel of\n * validation messages. It reads nothing else and ships as `dist/artifact.js`; `dist/artifact.html`\n * is the page that loads it. See docs/architecture.md.\n */\n\ntype State = { status: 'loading' } | { status: 'error'; message: string } | { status: 'ready'; spaces: LoadedSpace[] };\n\nfunction App() {\n const [state, setState] = useState<State>({ status: 'loading' });\n useEffect(() => {\n loadSpaces().then(\n (spaces) => setState({ status: 'ready', spaces }),\n (err) => setState({ status: 'error', message: err instanceof Error ? err.message : String(err) }),\n );\n }, []);\n if (state.status === 'loading') return <p className=\"art-message\">Loading from the artifact database…</p>;\n if (state.status === 'error') return <p className=\"art-message\">{state.message}</p>;\n return <Viewer spaces={state.spaces} />;\n}\n\nfunction Viewer({ spaces }: { spaces: LoadedSpace[] }) {\n const [spaceName, setSpaceName] = useState(spaces[0]!.name);\n const space = spaces.find((s) => s.name === spaceName)!;\n const [viewId, setViewId] = useState(space.definitions[0]?.id);\n const definition = space.definitions.find((d) => d.id === viewId) ?? space.definitions[0];\n const [values, setValues] = useState<ParameterValues>({});\n const [selectedId, setSelectedId] = useState<string>();\n\n const graph = useMemo(() => spaceGraphFrom(space.graph), [space]);\n const annotated = useMemo(() => annotationsFrom(space.validation, graph), [space, graph]);\n const mapRef = useNodeLabels(graph, definition);\n\n if (!definition) return <p className=\"art-message\">No map views apply to the schema of \"{space.name}\".</p>;\n const selected = selectedId ? graph.nodes.get(selectedId as never) : undefined;\n const results = selected ? (annotated.annotations.get(selected.id as never) ?? []) : [];\n\n return (\n <div className=\"art-root\">\n <header className=\"art-bar\">\n {spaces.length > 1 && (\n <select\n aria-label=\"Space\"\n value={spaceName}\n onChange={(e) => {\n const next = spaces.find((s) => s.name === e.target.value)!;\n setSpaceName(next.name);\n setViewId(next.definitions[0]?.id);\n setValues({});\n setSelectedId(undefined);\n }}\n >\n {spaces.map((s) => (\n <option key={s.name} value={s.name}>\n {s.name}\n </option>\n ))}\n </select>\n )}\n {space.definitions.length > 1 && (\n <select\n aria-label=\"Map view\"\n value={definition.id}\n onChange={(e) => {\n setViewId(e.target.value);\n setValues({});\n }}\n >\n {space.definitions.map((d) => (\n <option key={d.id} value={d.id}>\n {d.title}\n </option>\n ))}\n </select>\n )}\n <ParameterControls\n definition={definition}\n values={values}\n onChange={(name, value) => setValues((prev) => ({ ...prev, [name]: value }))}\n />\n </header>\n <div className=\"art-body\">\n <div className=\"art-map\" ref={mapRef}>\n <MapView\n definition={definition}\n graph={graph}\n values={values}\n annotations={annotated.annotations}\n onNodeSelect={(node) => setSelectedId(node.id)}\n />\n </div>\n {(selected || annotated.unattached.length > 0) && (\n <aside className=\"art-panel\" aria-label=\"Validation results\">\n {selected && (\n <section>\n <button type=\"button\" className=\"art-close\" aria-label=\"Close\" onClick={() => setSelectedId(undefined)}>\n ×\n </button>\n <p className=\"art-type\">{selected.resolvedType}</p>\n <h2>{selected.title}</h2>\n {results.length > 0 && (\n <>\n <h3>Validation</h3>\n <Results items={results} />\n </>\n )}\n <Fields data={selected.schemaData} />\n {selected.content && (\n <>\n <h3>Content</h3>\n <p className=\"art-content\">{selected.content}</p>\n </>\n )}\n {selected.source && <p className=\"art-muted\">{selected.source.file}</p>}\n </section>\n )}\n {annotated.unattached.length > 0 && (\n <section>\n <h3>Not on a node ({annotated.unattached.length})</h3>\n <Results items={annotated.unattached} />\n </section>\n )}\n </aside>\n )}\n </div>\n </div>\n );\n}\n\nconst SKIPPED_FIELDS = new Set(['title', 'type', 'content']);\nconst isEmpty = (v: unknown) => v === undefined || v === null || v === '' || (Array.isArray(v) && v.length === 0);\nconst asText = (v: unknown): string =>\n Array.isArray(v) ? v.map(asText).join(', ') : v !== null && typeof v === 'object' ? JSON.stringify(v) : String(v);\n\n/** The node's fields as a list; the title, type and body are shown elsewhere. */\nfunction Fields({ data }: { data: Record<string, unknown> }) {\n const fields = Object.entries(data).filter(([name, value]) => !SKIPPED_FIELDS.has(name) && !isEmpty(value));\n if (fields.length === 0) return null;\n return (\n <>\n <h3>Fields</h3>\n <dl className=\"art-fields\">\n {fields.map(([name, value]) => (\n <div key={name}>\n <dt>{name}</dt>\n <dd>{asText(value)}</dd>\n </div>\n ))}\n </dl>\n </>\n );\n}\n\nfunction Results({\n items,\n}: {\n items: readonly { severity: string; source: string; ruleId?: string; message: string; nodeId?: string }[];\n}) {\n return (\n <ul className=\"art-results\">\n {items.map((a, i) => (\n // biome-ignore lint/suspicious/noArrayIndexKey: a static list with no stable identity beyond position.\n <li key={i}>\n <span className={`art-severity art-${a.severity}`}>{a.severity}</span>{' '}\n <span className=\"art-muted\">{a.ruleId ? `${a.source} · ${a.ruleId}` : a.source}</span>\n {a.nodeId && <span className=\"art-muted\"> · {a.nodeId}</span>}\n <div>{a.message}</div>\n </li>\n ))}\n </ul>\n );\n}\n\n/**\n * Names each card for the viewer's comment mode, which reads the location of a comment from the\n * element's accessible name. The name leads with the map view and node id so it survives the\n * viewer's truncation, then gives the type and title: `<view>/<nodeId>: <type> <title>`. An agent\n * reading the comment resolves the id back to the node from the db.\n */\nfunction useNodeLabels(graph: ReturnType<typeof spaceGraphFrom>, definition: MapViewDefinition | undefined) {\n const ref = useRef<HTMLDivElement>(null);\n useEffect(() => {\n const root = ref.current;\n if (!root || !definition) return;\n const stamp = () => {\n for (const card of root.querySelectorAll<HTMLElement>('[data-node-id]')) {\n const node = graph.nodes.get(card.dataset.nodeId as never);\n if (node) card.setAttribute('aria-label', `${definition.id}/${node.id}: ${node.resolvedType} ${node.title}`);\n }\n };\n stamp();\n const observer = new MutationObserver(stamp);\n observer.observe(root, { childList: true, subtree: true });\n return () => observer.disconnect();\n }, [graph, definition]);\n return ref;\n}\n\ncreateRoot(document.getElementById('root')!).render(<App />);\n"],"mappings":";;;;;;AAaA,IAAM,SAAS;AACf,IAAM,aAAa;;AAOnB,eAAsB,aAAqC;CACzD,MAAM,SAAU,OAA2E;CAC3F,MAAM,KAAM,SAAS,MAAM,OAAO,IAAI,IAAI,IAAI;CAC9C,IAAI,CAAC,IAAI,MAAM,IAAI,MAAM,+EAA+E;CAExG,IAAI;CACJ,MAAM,UAAU,IAAI,SAAgB,GAAG,WAAW;EAChD,QAAQ,iBAAiB,uBAAO,IAAI,MAAM,0CAA0C,CAAC,GAAG,UAAU;CACpG,CAAC;CAED,MAAM,UAAS,MADQ,QAAQ,KAAK,CAAC,GAAG,WAAW,MAAM,CAAC,CAAC,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,cAAc,aAAa,KAAK,CAAC,EAAA,CACrF,KAAK,SAAS,QAAQ;EAC5C,MAAM,OAAO,IAAI,KAAK;EACtB,OAAO,OAAO,CAAC,QAAQ,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC;CAC3C,CAAC;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UAAA;GACE,oBAAC,QAAD;IAAM,WAAW,oBAAoB,EAAE;IAAa,UAAA,EAAE;GAAe,CAAA;GAAE;GACvE,oBAAC,QAAD;IAAM,WAAU;IAAa,UAAA,EAAE,SAAS,GAAG,EAAE,OAAO,KAAK,EAAE,WAAW,EAAE;GAAa,CAAA;GACpF,EAAE,UAAU,qBAAC,QAAD;IAAM,WAAU;IAAhB,UAAA,CAA4B,OAAI,EAAE,MAAa;;GAC5D,oBAAC,OAAD,EAAA,UAAM,EAAE,QAAa,CAAA;EACnB,EAAA,GALK,CAKL,CACL;CACC,CAAA;AAER;;;;;;;AAQA,SAAS,cAAc,OAA0C,YAA2C;CAC1G,MAAM,MAAM,OAAuB,IAAI;CACvC,gBAAgB;EACd,MAAM,OAAO,IAAI;EACjB,IAAI,CAAC,QAAQ,CAAC,YAAY;EAC1B,MAAM,cAAc;GAClB,KAAK,MAAM,QAAQ,KAAK,iBAA8B,gBAAgB,GAAG;IACvE,MAAM,OAAO,MAAM,MAAM,IAAI,KAAK,QAAQ,MAAe;IACzD,IAAI,MAAM,KAAK,aAAa,cAAc,GAAG,WAAW,GAAG,GAAG,KAAK,GAAG,IAAI,KAAK,aAAa,GAAG,KAAK,OAAO;GAC7G;EACF;EACA,MAAM;EACN,MAAM,WAAW,IAAI,iBAAiB,KAAK;EAC3C,SAAS,QAAQ,MAAM;GAAE,WAAW;GAAM,SAAS;EAAK,CAAC;EACzD,aAAa,SAAS,WAAW;CACnC,GAAG,CAAC,OAAO,UAAU,CAAC;CACtB,OAAO;AACT;AAEA,WAAW,SAAS,eAAe,MAAM,CAAE,CAAC,CAAC,OAAO,oBAAC,KAAD,CAAM,CAAA,CAAC"}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { n as mapViewsForSchema } from "./definition-Cft28YUA.js";
|
|
3
|
+
import { t as loadMapViewDefinitions } from "./node-BceB0Wzc.js";
|
|
4
|
+
import { dirname, resolve } from "node:path";
|
|
5
|
+
import { SctxError, assembleSpaceGraph, createSpaceContext, exportSpaceGraph, loadConfig, resolveConfigPath, setConfigPath, validateSpace } from "structured-context/api";
|
|
6
|
+
import { Command } from "commander";
|
|
7
|
+
var package_default = {
|
|
8
|
+
name: "structured-context-map-views",
|
|
9
|
+
version: "0.3.0",
|
|
10
|
+
description: "Declarative map views of structured-context spaces: render a space as a tree, nested containers or an XY plot from a short definition.",
|
|
11
|
+
license: "MIT",
|
|
12
|
+
type: "module",
|
|
13
|
+
repository: {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/mindsocket/structured-context-map-views.git",
|
|
16
|
+
"directory": "packages/map-views"
|
|
17
|
+
},
|
|
18
|
+
homepage: "https://github.com/mindsocket/structured-context-map-views#readme",
|
|
19
|
+
bugs: "https://github.com/mindsocket/structured-context-map-views/issues",
|
|
20
|
+
keywords: [
|
|
21
|
+
"structured-context",
|
|
22
|
+
"visualisation",
|
|
23
|
+
"map-view",
|
|
24
|
+
"react"
|
|
25
|
+
],
|
|
26
|
+
files: ["dist/"],
|
|
27
|
+
sideEffects: false,
|
|
28
|
+
bin: { "structured-context-map-views": "dist/cli.js" },
|
|
29
|
+
exports: {
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./dist/types/index.d.ts",
|
|
32
|
+
"default": "./dist/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./node": {
|
|
35
|
+
"types": "./dist/types/node/index.d.ts",
|
|
36
|
+
"default": "./dist/node.js"
|
|
37
|
+
},
|
|
38
|
+
"./styles.css": "./dist/styles.css"
|
|
39
|
+
},
|
|
40
|
+
scripts: {
|
|
41
|
+
"clean": "rm -rf dist",
|
|
42
|
+
"generate": "bun run generate:schemas && bun run generate:definitions",
|
|
43
|
+
"generate:schemas": "bun scripts/generate-schemas.ts",
|
|
44
|
+
"generate:definitions": "bun scripts/generate-definitions.ts",
|
|
45
|
+
"build": "bun run clean && bun run generate && bun --bun vite build && tsc -p tsconfig.build.json && tailwindcss -i src/layouts/styles.css -o dist/styles.css && bun scripts/build-artifact-page.ts",
|
|
46
|
+
"typecheck": "tsc --noEmit",
|
|
47
|
+
"capture-fixtures": "bun scripts/capture-fixtures.ts",
|
|
48
|
+
"test": "bun test",
|
|
49
|
+
"test:package": "bash scripts/test-package.sh",
|
|
50
|
+
"prepublishOnly": "bun run build",
|
|
51
|
+
"preversion": "bun run generate && bun run --cwd ../.. lint:fix && bun run --cwd ../.. test && bun run test:package",
|
|
52
|
+
"version": "bun run generate:schemas --release && git add -A"
|
|
53
|
+
},
|
|
54
|
+
peerDependencies: {
|
|
55
|
+
"react": "^19.3.0",
|
|
56
|
+
"react-dom": "^19.3.0",
|
|
57
|
+
"structured-context": "^0.21.0"
|
|
58
|
+
},
|
|
59
|
+
dependencies: {
|
|
60
|
+
"ajv": "^8.20.0",
|
|
61
|
+
"commander": "^15.0.0",
|
|
62
|
+
"json-schema-to-ts": "^3.1.1",
|
|
63
|
+
"json5": "^2.2.3"
|
|
64
|
+
},
|
|
65
|
+
devDependencies: {
|
|
66
|
+
"@tailwindcss/cli": "^4.3.3",
|
|
67
|
+
"@types/node": "^22.20.5",
|
|
68
|
+
"@types/react": "^19.3.0",
|
|
69
|
+
"@types/react-dom": "^19.3.0",
|
|
70
|
+
"@vitejs/plugin-react": "^6.1.1",
|
|
71
|
+
"react": "^19.3.0",
|
|
72
|
+
"react-dom": "^19.3.0",
|
|
73
|
+
"structured-context": "^0.21.0",
|
|
74
|
+
"tailwindcss": "^4.3.3",
|
|
75
|
+
"vite": "^8.3.2"
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region src/node/snapshot.ts
|
|
80
|
+
/**
|
|
81
|
+
* Node-only: snapshot a space for a browser-only host. Validation is structured-context's own
|
|
82
|
+
* `validateSpace`, which also decides whether a judge runs.
|
|
83
|
+
*/
|
|
84
|
+
async function exportSnapshot(spaceName, config, configDir, validateOptions = {}) {
|
|
85
|
+
const context = createSpaceContext(spaceName, config);
|
|
86
|
+
const graph = await assembleSpaceGraph(context, {});
|
|
87
|
+
const schemaId = context.schema.$id;
|
|
88
|
+
return {
|
|
89
|
+
space: spaceName,
|
|
90
|
+
schemaId,
|
|
91
|
+
graph: exportSpaceGraph(graph.nodes.values(), context.schema.metadata),
|
|
92
|
+
validation: await validateSpace(context, validateOptions),
|
|
93
|
+
definitions: mapViewsForSchema(loadMapViewDefinitions(config, { configDir }), schemaId)
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
//#endregion
|
|
97
|
+
//#region src/node/cli.ts
|
|
98
|
+
var program = new Command();
|
|
99
|
+
program.name("structured-context-map-views").description("Map view tools for structured-context spaces").version(package_default.version).option("--config <path>", "Path to config file (overrides config discovery)");
|
|
100
|
+
program.command("export").description("Print a JSON snapshot of a space: its graph, validation results and map view definitions").argument("<space-name>", "Space name").option("--depth <n>", "Validate only hierarchy nodes within N levels from the top", (v) => parseInt(v, 10)).option("--include-gated", "Evaluate rules even on nodes gated by an upstream failure").option("--rule-filter <dimension=values>", "Evaluate only matching rules; dimensions: category, severity, type, id (repeatable, e.g. severity=error)", (v, prev = []) => [...prev, v]).option("--semantic [provider]", "Evaluate semantic rules, with the configured model provider or the one named").action(async (spaceName, options) => {
|
|
101
|
+
setConfigPath(program.opts().config);
|
|
102
|
+
try {
|
|
103
|
+
const result = await exportSnapshot(spaceName, loadConfig(), dirname(resolve(resolveConfigPath().path)), options);
|
|
104
|
+
process.stdout.write(`${JSON.stringify(result)}\n`);
|
|
105
|
+
} catch (err) {
|
|
106
|
+
if (!(err instanceof SctxError)) throw err;
|
|
107
|
+
console.error(`${err.code}: ${err.message}`);
|
|
108
|
+
process.exitCode = 1;
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
await program.parseAsync();
|
|
112
|
+
//#endregion
|
|
113
|
+
|
|
114
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","names":["packageJson"],"sources":["../package.json","../src/node/snapshot.ts","../src/node/cli.ts"],"sourcesContent":["{\n \"name\": \"structured-context-map-views\",\n \"version\": \"0.3.0\",\n \"description\": \"Declarative map views of structured-context spaces: render a space as a tree, nested containers or an XY plot from a short definition.\",\n \"license\": \"MIT\",\n \"type\": \"module\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/mindsocket/structured-context-map-views.git\",\n \"directory\": \"packages/map-views\"\n },\n \"homepage\": \"https://github.com/mindsocket/structured-context-map-views#readme\",\n \"bugs\": \"https://github.com/mindsocket/structured-context-map-views/issues\",\n \"keywords\": [\n \"structured-context\",\n \"visualisation\",\n \"map-view\",\n \"react\"\n ],\n \"files\": [\n \"dist/\"\n ],\n \"sideEffects\": false,\n \"bin\": {\n \"structured-context-map-views\": \"dist/cli.js\"\n },\n \"exports\": {\n \".\": {\n \"types\": \"./dist/types/index.d.ts\",\n \"default\": \"./dist/index.js\"\n },\n \"./node\": {\n \"types\": \"./dist/types/node/index.d.ts\",\n \"default\": \"./dist/node.js\"\n },\n \"./styles.css\": \"./dist/styles.css\"\n },\n \"scripts\": {\n \"clean\": \"rm -rf dist\",\n \"generate\": \"bun run generate:schemas && bun run generate:definitions\",\n \"generate:schemas\": \"bun scripts/generate-schemas.ts\",\n \"generate:definitions\": \"bun scripts/generate-definitions.ts\",\n \"build\": \"bun run clean && bun run generate && bun --bun vite build && tsc -p tsconfig.build.json && tailwindcss -i src/layouts/styles.css -o dist/styles.css && bun scripts/build-artifact-page.ts\",\n \"typecheck\": \"tsc --noEmit\",\n \"capture-fixtures\": \"bun scripts/capture-fixtures.ts\",\n \"test\": \"bun test\",\n \"test:package\": \"bash scripts/test-package.sh\",\n \"prepublishOnly\": \"bun run build\",\n \"preversion\": \"bun run generate && bun run --cwd ../.. lint:fix && bun run --cwd ../.. test && bun run test:package\",\n \"version\": \"bun run generate:schemas --release && git add -A\"\n },\n \"peerDependencies\": {\n \"react\": \"^19.3.0\",\n \"react-dom\": \"^19.3.0\",\n \"structured-context\": \"^0.21.0\"\n },\n \"dependencies\": {\n \"ajv\": \"^8.20.0\",\n \"commander\": \"^15.0.0\",\n \"json-schema-to-ts\": \"^3.1.1\",\n \"json5\": \"^2.2.3\"\n },\n \"devDependencies\": {\n \"@tailwindcss/cli\": \"^4.3.3\",\n \"@types/node\": \"^22.20.5\",\n \"@types/react\": \"^19.3.0\",\n \"@types/react-dom\": \"^19.3.0\",\n \"@vitejs/plugin-react\": \"^6.1.1\",\n \"react\": \"^19.3.0\",\n \"react-dom\": \"^19.3.0\",\n \"structured-context\": \"^0.21.0\",\n \"tailwindcss\": \"^4.3.3\",\n \"vite\": \"^8.3.2\"\n }\n}\n","import {\n assembleSpaceGraph,\n type Config,\n createSpaceContext,\n exportSpaceGraph,\n validateSpace,\n} from 'structured-context/api';\nimport { type MapViewDefinition, mapViewsForSchema } from '../core/definition';\nimport { loadMapViewDefinitions } from './index';\n\n/**\n * Everything a host without filesystem access needs to render a space: its graph, the validation\n * results that attach to nodes, and the map view definitions that apply to its schema. Plain JSON.\n */\nexport type SpaceSnapshot = {\n space: string;\n schemaId: string | undefined;\n graph: ReturnType<typeof exportSpaceGraph>;\n validation: Awaited<ReturnType<typeof validateSpace>>;\n definitions: MapViewDefinition[];\n};\n\n/** The `validateSpace` options `export` passes through unchanged. */\nexport type ExportValidateOptions = Pick<\n NonNullable<Parameters<typeof validateSpace>[1]>,\n 'depth' | 'includeGated' | 'semantic' | 'ruleFilter'\n>;\n\n/**\n * Node-only: snapshot a space for a browser-only host. Validation is structured-context's own\n * `validateSpace`, which also decides whether a judge runs.\n */\nexport async function exportSnapshot(\n spaceName: string,\n config: Config,\n configDir?: string,\n validateOptions: ExportValidateOptions = {},\n): Promise<SpaceSnapshot> {\n const context = createSpaceContext(spaceName, config);\n const graph = await assembleSpaceGraph(context, {});\n const schemaId = context.schema.$id;\n return {\n space: spaceName,\n schemaId,\n graph: exportSpaceGraph(graph.nodes.values(), context.schema.metadata),\n validation: await validateSpace(context, validateOptions),\n definitions: mapViewsForSchema(loadMapViewDefinitions(config, { configDir }), schemaId),\n };\n}\n","#!/usr/bin/env bun\nimport { dirname, resolve } from 'node:path';\nimport { Command } from 'commander';\nimport { loadConfig, resolveConfigPath, SctxError, setConfigPath } from 'structured-context/api';\nimport packageJson from '../../package.json' with { type: 'json' };\nimport { type ExportValidateOptions, exportSnapshot } from './snapshot';\n\nconst program = new Command();\n\nprogram\n .name('structured-context-map-views')\n .description('Map view tools for structured-context spaces')\n .version(packageJson.version)\n .option('--config <path>', 'Path to config file (overrides config discovery)');\n\nprogram\n .command('export')\n .description('Print a JSON snapshot of a space: its graph, validation results and map view definitions')\n .argument('<space-name>', 'Space name')\n .option('--depth <n>', 'Validate only hierarchy nodes within N levels from the top', (v) => parseInt(v, 10))\n .option('--include-gated', 'Evaluate rules even on nodes gated by an upstream failure')\n .option(\n '--rule-filter <dimension=values>',\n 'Evaluate only matching rules; dimensions: category, severity, type, id (repeatable, e.g. severity=error)',\n (v: string, prev: string[] = []) => [...prev, v],\n )\n .option('--semantic [provider]', 'Evaluate semantic rules, with the configured model provider or the one named')\n .action(async (spaceName: string, options: ExportValidateOptions) => {\n setConfigPath(program.opts().config);\n try {\n const config = loadConfig();\n const configDir = dirname(resolve(resolveConfigPath().path));\n const result = await exportSnapshot(spaceName, config, configDir, options);\n process.stdout.write(`${JSON.stringify(result)}\\n`);\n } catch (err) {\n if (!(err instanceof SctxError)) throw err;\n console.error(`${err.code}: ${err.message}`);\n process.exitCode = 1;\n }\n });\n\nawait program.parseAsync();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACgCA,eAAsB,eACpB,WACA,QACA,WACA,kBAAyC,CAAC,GAClB;CACxB,MAAM,UAAU,mBAAmB,WAAW,MAAM;CACpD,MAAM,QAAQ,MAAM,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