diff --git a/ui/package-lock.json b/ui/package-lock.json index cdee66a..346577c 100644 --- a/ui/package-lock.json +++ b/ui/package-lock.json @@ -11,7 +11,8 @@ "gnexus-ui-kit": "file:../../gnexus-ui-kit", "marked": "^18.2.1", "vite": "^6.0.0", - "vue": "^3.4.0" + "vue": "^3.4.0", + "vue-router": "^4.6.5" } }, "../../gnexus-ui-kit": { @@ -948,6 +949,12 @@ "@vue/shared": "3.5.34" } }, + "node_modules/@vue/devtools-api": { + "version": "6.6.4", + "resolved": "https://registry.npmjs.org/@vue/devtools-api/-/devtools-api-6.6.4.tgz", + "integrity": "sha512-sGhTPMuXqZ1rVOk32RylztWkfXTRhuS7vgAKv0zjqk8gbsHkJ7xfFf+jbySxt7tWObEJwyKaHMikV/WGDiQm8g==", + "license": "MIT" + }, "node_modules/@vue/reactivity": { "version": "3.5.34", "resolved": "https://registry.npmjs.org/@vue/reactivity/-/reactivity-3.5.34.tgz", @@ -1355,6 +1362,21 @@ "optional": true } } + }, + "node_modules/vue-router": { + "version": "4.6.5", + "resolved": "https://registry.npmjs.org/vue-router/-/vue-router-4.6.5.tgz", + "integrity": "sha512-HBoGqixpB2ej1kI17NotdOatUdKIsi3yfOQ5vhwAhcoHk90+JtwtIy7MEeOqdPi1+npmQVMEu5F+Hvw+3TU48w==", + "license": "MIT", + "dependencies": { + "@vue/devtools-api": "^6.6.4" + }, + "funding": { + "url": "https://github.com/sponsors/posva" + }, + "peerDependencies": { + "vue": "^3.5.0" + } } } } diff --git a/ui/package.json b/ui/package.json index 2408a7d..a77cdf1 100644 --- a/ui/package.json +++ b/ui/package.json @@ -13,6 +13,7 @@ "gnexus-ui-kit": "file:../../gnexus-ui-kit", "marked": "^18.2.1", "vite": "^6.0.0", - "vue": "^3.4.0" + "vue": "^3.4.0", + "vue-router": "^4.6.5" } } diff --git a/ui/src/App.vue b/ui/src/App.vue new file mode 100644 index 0000000..b43ba17 --- /dev/null +++ b/ui/src/App.vue @@ -0,0 +1,205 @@ + + + diff --git a/ui/src/components/IssueList.vue b/ui/src/components/IssueList.vue new file mode 100644 index 0000000..b08d381 --- /dev/null +++ b/ui/src/components/IssueList.vue @@ -0,0 +1,30 @@ + + + diff --git a/ui/src/lib/api.js b/ui/src/lib/api.js new file mode 100644 index 0000000..8d44371 --- /dev/null +++ b/ui/src/lib/api.js @@ -0,0 +1,41 @@ +export async function request(path, options = {}) { + const response = await fetch(`/api${path}`, { + credentials: "same-origin", + ...options + }); + if (response.status === 401) { + window.dispatchEvent(new CustomEvent("book:unauthenticated")); + throw new Error("unauthorized"); + } + if (response.status === 204) return null; + if (!response.ok) { + const text = await response.text(); + let detail = text; + try { + const data = JSON.parse(text); + detail = data.detail || data.error || text; + } catch { + /* keep text */ + } + throw new Error(`${response.status}: ${detail}`); + } + const contentType = response.headers.get("content-type") || ""; + return contentType.includes("application/json") + ? response.json() + : response.text(); +} + +export const apiGet = path => request(path); + +export const apiSend = (path, method, body) => + request(path, { + method, + headers: body ? { "Content-Type": "application/json" } : undefined, + body: body ? JSON.stringify(body) : undefined + }); + +export const encodePath = path => + String(path || "") + .split("/") + .map(encodeURIComponent) + .join("/"); diff --git a/ui/src/lib/format.js b/ui/src/lib/format.js new file mode 100644 index 0000000..e8da966 --- /dev/null +++ b/ui/src/lib/format.js @@ -0,0 +1,46 @@ +import { marked } from "marked"; +import DOMPurify from "dompurify"; +import { locale, t } from "../i18n/index.js"; + +marked.setOptions({ gfm: true, breaks: false }); + +export const pretty = value => + typeof value === "string" ? value : JSON.stringify(value ?? null, null, 2); + +export const renderMarkdown = value => + DOMPurify.sanitize(marked.parse(String(value || ""))); + +export const readableKey = key => + String(key) + .replace(/[_-]+/g, " ") + .replace(/\b\w/g, char => char.toUpperCase()); + +export const displayValue = value => { + if (value === null || value === undefined || value === "") return "—"; + if (Array.isArray(value)) return value.map(displayValue).join(", "); + if (typeof value === "object") return JSON.stringify(value, null, 2); + if (typeof value === "boolean") return value ? "true" : "false"; + return String(value); +}; + +export const formatDate = value => { + if (!value) return "—"; + const date = new Date(value); + return Number.isNaN(date.getTime()) ? String(value) : date.toLocaleString(locale.value); +}; + +export const statusLabel = status => + ({ + draft: t("changes.draft"), + pending: t("changes.pending"), + applied: t("changes.appliedStatus"), + rejected: t("changes.rejected") + })[status] || status; + +export const changeStatusVariant = status => + status === "applied" ? "success" : status === "rejected" ? "danger" : "secondary"; + +export const defaultDocTemplate = () => { + const today = new Date().toISOString().slice(0, 10); + return `---\nowner: gmikcon\nstatus: draft\nlast_reviewed: ${today}\nreview_interval: 30d\nconfidence: medium\nsource_of_truth: manual\n---\n\n# New document\n\n`; +}; diff --git a/ui/src/lib/session.js b/ui/src/lib/session.js new file mode 100644 index 0000000..3c82c2b --- /dev/null +++ b/ui/src/lib/session.js @@ -0,0 +1,38 @@ +import { computed, reactive } from "vue"; + +export const session = reactive({ + authEnabled: false, + user: null, + storage: "unknown", + healthStatus: "unknown", + localeOverride: null +}); + +export const canWrite = computed( + () => !session.authEnabled || Boolean(session.user) +); + +export const isAdmin = computed( + () => + session.user?.system_role === "admin" || + session.user?.system_role === "superadmin" +); + +export const userDisplayName = computed( + () => + session.user?.display_name || + session.user?.email || + session.user?.user_id || + "" +); + +export const userInitials = computed(() => { + const source = userDisplayName.value || "?"; + return source + .split(/\s+/) + .slice(0, 2) + .map(part => part[0]) + .join("") + .toUpperCase() + .slice(0, 2); +}); diff --git a/ui/src/main.js b/ui/src/main.js index f86a79f..bef07e5 100644 --- a/ui/src/main.js +++ b/ui/src/main.js @@ -1,1608 +1,8 @@ -import { computed, createApp, onMounted, reactive, ref, watch } from "vue"; -import { marked } from "marked"; -import DOMPurify from "dompurify"; +import { createApp } from "vue"; import "gnexus-ui-kit/dist/css/kit.css"; import "gnexus-ui-kit/dist/assets/fonts/phosphor-icons/src/css/icons.css"; -import { - GnAlert, - GnBadge, - GnButton, - GnCard, - GnChip, - GnConfirmDialog, - GnDescriptionList, - GnDrawer, - GnEmptyState, - GnInput, - GnMetricCard, - GnModal, - GnPageHeader, - GnSearchField, - GnTable, - GnTabs, - GnTextarea, - GnToastProvider, - GnToolbar, - GnUserCard, - useToast -} from "gnexus-ui-kit/vue"; -import { - locale, - localeOptions, - savedLocale, - setLocale, - t -} from "./i18n/index.js"; +import App from "./App.vue"; +import { router } from "./router.js"; import "./styles.css"; -const encodePath = path => - String(path || "") - .split("/") - .map(encodeURIComponent) - .join("/"); - -const pretty = value => - typeof value === "string" ? value : JSON.stringify(value ?? null, null, 2); - -const defaultDocTemplate = () => { - const today = new Date().toISOString().slice(0, 10); - return `---\nowner: gmikcon\nstatus: draft\nlast_reviewed: ${today}\nreview_interval: 30d\nconfidence: medium\nsource_of_truth: manual\n---\n\n# New document\n\n`; -}; - -marked.setOptions({ gfm: true, breaks: false }); - -const renderMarkdown = value => - DOMPurify.sanitize(marked.parse(String(value || ""))); - -const readableKey = key => - String(key) - .replace(/[_-]+/g, " ") - .replace(/\b\w/g, char => char.toUpperCase()); - -const displayValue = value => { - if (value === null || value === undefined || value === "") return "—"; - if (Array.isArray(value)) return value.map(displayValue).join(", "); - if (typeof value === "object") return JSON.stringify(value, null, 2); - if (typeof value === "boolean") return value ? "true" : "false"; - return String(value); -}; - -const IssueList = { - components: { GnBadge }, - props: { - issues: { type: Array, default: () => [] } - }, - setup() { - return { t }; - }, - template: ` -
-

{{ t('status.noIssues') }}

-
- {{ issue.severity || 'warning' }} -
-
- {{ issue.path }} - {{ issue.code }} -
-

{{ issue.message }}

-
-
-
- ` -}; - -const AppScreen = { - components: { - GnAlert, - GnBadge, - GnButton, - GnCard, - GnChip, - GnConfirmDialog, - GnDescriptionList, - GnDrawer, - GnEmptyState, - GnInput, - GnMetricCard, - GnModal, - GnPageHeader, - GnSearchField, - GnTable, - GnTabs, - GnTextarea, - GnToolbar, - GnUserCard, - IssueList - }, - setup() { - const toast = useToast(); - - const booting = ref(true); - const authEnabled = ref(false); - const user = ref(null); - const localeOverride = ref(null); - const storage = ref("unknown"); - const healthStatus = ref("unknown"); - const pageError = ref(""); - const activePage = ref("docs"); - const drawerOpen = ref(false); - - const docs = ref([]); - const docQuery = ref(""); - const searchResults = ref([]); - const searching = ref(false); - const selectedDocPath = ref(""); - const selectedDoc = ref(null); - const docLoading = ref(false); - const docError = ref(""); - const docHistory = ref([]); - const historyError = ref(""); - const docDiff = ref(""); - const diffError = ref(""); - const proposal = reactive({ - target: "10-systems/example.md", - summary: "", - reason: "", - content: defaultDocTemplate() - }); - const proposalRunning = ref(false); - const proposalOpen = ref(false); - const historyOpen = ref(false); - const mobileDocView = ref("list"); - - const inventoryTypes = ref([]); - const inventoryType = ref(""); - const inventoryRecords = ref([]); - const inventoryFilter = ref(""); - const selectedInventoryId = ref(""); - const inventoryRaw = ref(false); - const inventoryTab = ref("fields"); - const inventoryRawText = ref(""); - const inventoryLoading = ref(false); - const inventoryError = ref(""); - - const changes = ref([]); - const selectedChangeId = ref(""); - const selectedChange = ref(null); - const changeLoading = ref(false); - const changeError = ref(""); - const applyingChange = ref(false); - - const validation = ref(null); - const freshness = ref(null); - - const keys = ref([]); - const keysShowAll = ref(false); - const keysLoading = ref(false); - const keysError = ref(""); - const issuedToken = ref(""); - const issuedKey = ref(null); - const keyForm = reactive({ consumer: "claude-code", name: "" }); - - const confirmState = reactive({ - open: false, - title: "", - message: "", - confirmText: "", - variant: "warning", - action: null - }); - - let searchTimer = null; - - const userDisplayName = computed( - () => - user.value?.display_name || - user.value?.email || - user.value?.user_id || - "" - ); - const userInitials = computed(() => { - const source = userDisplayName.value || "?"; - return source - .split(/\s+/) - .slice(0, 2) - .map(part => part[0]) - .join("") - .toUpperCase() - .slice(0, 2); - }); - const isAuthenticated = computed( - () => !authEnabled.value || Boolean(user.value) - ); - const canWrite = computed( - () => !authEnabled.value || Boolean(user.value) - ); - const isAdmin = computed(() => user.value?.system_role === "admin"); - const storageIsDb = computed(() => storage.value === "db"); - - const navItems = computed(() => [ - { id: "docs", label: t("nav.docs"), icon: "ph-files" }, - { id: "inventory", label: t("nav.inventory"), icon: "ph-database" }, - { id: "changes", label: t("nav.changes"), icon: "ph-git-pull-request" }, - { id: "status", label: t("nav.status"), icon: "ph-heartbeat" }, - ...(authEnabled.value && user.value - ? [{ id: "keys", label: t("nav.keys"), icon: "ph-key" }] - : []) - ]); - - const pageMeta = computed( - () => - ({ - docs: { title: t("docs.title"), subtitle: t("docs.subtitle") }, - inventory: { - title: t("inventory.title"), - subtitle: t("inventory.subtitle") - }, - changes: { - title: t("changes.title"), - subtitle: t("changes.subtitle") - }, - status: { title: t("status.title"), subtitle: t("status.subtitle") }, - keys: { title: t("keys.title"), subtitle: t("keys.subtitle") }, - settings: { - title: t("settings.title"), - subtitle: t("settings.subtitle") - } - })[activePage.value] || { - title: t("app.title"), - subtitle: t("app.subtitle") - } - ); - const pageTitle = computed(() => pageMeta.value.title); - const pageSubtitle = computed(() => pageMeta.value.subtitle); - const activeLocaleLabel = computed( - () => - (localeOptions.find(option => option.value === locale.value) || localeOptions[0]) - .label - ); - const settingsItems = computed(() => [ - { - key: "storage", - term: t("settings.storage"), - value: storage.value || t("common.unknown") - }, - { - key: "health", - term: t("common.status"), - value: healthStatus.value || t("common.unknown") - }, - { - key: "auth", - term: t("settings.auth"), - value: authEnabled.value ? t("auth.title") : t("settings.authDisabled") - }, - { - key: "account", - term: t("auth.account"), - value: user.value - ? `${userDisplayName.value} · ${user.value.email || user.value.user_id}` - : t("common.none") - }, - { - key: "language", - term: t("settings.language"), - value: activeLocaleLabel.value - } - ]); - - const docFrontmatterItems = computed(() => { - const frontmatter = selectedDoc.value?.frontmatter || {}; - const priority = [ - "owner", - "status", - "last_reviewed", - "review_interval", - "confidence", - "source_of_truth" - ]; - const keys = Object.keys(frontmatter).sort((a, b) => { - const ai = priority.indexOf(a); - const bi = priority.indexOf(b); - if (ai === -1 && bi === -1) return a.localeCompare(b); - if (ai === -1) return 1; - if (bi === -1) return -1; - return ai - bi; - }); - return keys.map(key => ({ - key, - term: readableKey(key), - value: displayValue(frontmatter[key]) - })); - }); - - const renderedDocBody = computed(() => - renderMarkdown(selectedDoc.value?.body || "") - ); - - const filteredInventory = computed(() => { - const query = inventoryFilter.value.trim().toLowerCase(); - if (!query) return inventoryRecords.value; - return inventoryRecords.value.filter(item => - [item.id, item.name, item.fqdn, item.host] - .filter(Boolean) - .some(value => String(value).toLowerCase().includes(query)) - ); - }); - const selectedInventoryRecord = computed( - () => - inventoryRecords.value.find( - item => item.id === selectedInventoryId.value - ) || null - ); - const inventoryFieldItems = computed(() => - Object.entries(selectedInventoryRecord.value || {}).map(([key, value]) => ({ - key, - term: readableKey(key), - value: displayValue(value) - })) - ); - const inventoryColumns = computed(() => [ - { key: "name", label: t("common.name") }, - { key: "id", label: t("inventory.recordId") }, - { key: "host", label: t("inventory.host") } - ]); - const inventoryTabs = computed(() => [ - { id: "fields", label: t("common.fields"), icon: "ph-list-dashes" }, - { id: "json", label: t("common.raw"), icon: "ph-code" } - ]); - const inventoryDisplay = computed(() => { - if (inventoryRaw.value) return inventoryRawText.value; - return selectedInventoryRecord.value - ? pretty(selectedInventoryRecord.value) - : ""; - }); - - const formatDate = value => { - if (!value) return "—"; - const date = new Date(value); - return Number.isNaN(date.getTime()) - ? String(value) - : date.toLocaleString(locale.value); - }; - const statusLabel = status => - ({ - draft: t("changes.draft"), - pending: t("changes.pending"), - applied: t("changes.appliedStatus"), - rejected: t("changes.rejected") - })[status] || status; - const changeStatusVariant = status => - status === "applied" - ? "success" - : status === "rejected" - ? "danger" - : "secondary"; - const isLatestVersion = versionNo => { - if (!docHistory.value.length) return false; - const latest = Math.max( - ...docHistory.value.map(version => version.version_no) - ); - return versionNo === latest; - }; - - const changeDetailItems = computed(() => { - const change = selectedChange.value; - if (!change) return []; - return [ - { key: "summary", term: t("common.summary"), value: change.summary }, - { key: "status", term: t("common.status"), value: statusLabel(change.status) }, - { key: "kind", term: t("common.type"), value: change.kind }, - { key: "target", term: t("common.target"), value: change.target }, - { key: "reason", term: t("common.reason"), value: change.reason || "—" }, - { key: "created", term: t("common.created"), value: formatDate(change.created_at) }, - { - key: "actor", - term: t("auth.account"), - value: [change.actor_name, change.actor_kind, change.via].filter(Boolean).join(" · ") || "—" - } - ]; - }); - - async function request(path, options = {}) { - const response = await fetch(`/api${path}`, { - credentials: "same-origin", - ...options - }); - if (response.status === 401) { - user.value = null; - throw new Error(t("errors.unauthorized")); - } - if (response.status === 204) return null; - if (!response.ok) { - const text = await response.text(); - let detail = text; - try { - const data = JSON.parse(text); - detail = data.detail || data.error || text; - } catch { - /* keep text */ - } - throw new Error(`${response.status}: ${detail}`); - } - const contentType = response.headers.get("content-type") || ""; - return contentType.includes("application/json") - ? response.json() - : response.text(); - } - const apiGet = path => request(path); - const apiSend = (path, method, body) => - request(path, { - method, - headers: body ? { "Content-Type": "application/json" } : undefined, - body: body ? JSON.stringify(body) : undefined - }); - - async function loadMe() { - booting.value = true; - pageError.value = ""; - try { - const response = await fetch("/api/me", { - credentials: "same-origin" - }); - if (!response.ok) { - throw new Error(`/me ${response.status}`); - } - const data = await response.json(); - authEnabled.value = Boolean(data.auth_enabled); - user.value = data.user || null; - localeOverride.value = data.locale || null; - if (data.user && data.locale_effective) { - setLocale(data.locale_effective); - } else if (!data.user) { - setLocale(savedLocale() || data.locale_effective || "en"); - } - - const params = new URLSearchParams(window.location.search); - if (params.get("auth_error")) { - pageError.value = t("auth.denied"); - window.history.replaceState({}, "", window.location.pathname); - } - } catch (error) { - pageError.value = - error instanceof Error ? error.message : t("errors.loadFailed"); - } finally { - booting.value = false; - } - - if (isAuthenticated.value) { - await loadAll(); - } - } - - async function loadAll() { - pageError.value = ""; - const results = await Promise.allSettled([ - apiGet("/health"), - apiGet("/docs"), - apiGet("/inventory"), - apiGet("/changes"), - apiGet("/validate"), - apiGet("/health/freshness"), - authEnabled.value && user.value - ? apiGet("/mcp-keys") - : Promise.resolve(null) - ]); - const [health, docsResult, inventoryResult, changesResult, validationResult, freshnessResult, keysResult] = - results; - - if (health.status === "fulfilled") { - storage.value = health.value?.storage || "unknown"; - healthStatus.value = health.value?.status || "unknown"; - } - if (docsResult.status === "fulfilled") { - docs.value = docsResult.value || []; - if ( - selectedDocPath.value && - docs.value.some(doc => doc.path === selectedDocPath.value) - ) { - await loadDoc(selectedDocPath.value); - } else if (docs.value.length) { - await loadDoc(docs.value[0].path, false); - } - } - if (inventoryResult.status === "fulfilled") { - inventoryTypes.value = inventoryResult.value || []; - if ( - inventoryType.value && - inventoryTypes.value.includes(inventoryType.value) - ) { - await loadInventoryType(inventoryType.value); - } else if (inventoryTypes.value.length) { - await loadInventoryType(inventoryTypes.value[0]); - } - } - if (changesResult.status === "fulfilled") { - changes.value = changesResult.value || []; - if ( - selectedChangeId.value && - changes.value.some(change => change.id === selectedChangeId.value) - ) { - await loadChange(selectedChangeId.value); - } else if (changes.value.length) { - await loadChange(changes.value[0].id); - } else { - selectedChangeId.value = ""; - selectedChange.value = null; - } - } - if (validationResult.status === "fulfilled") { - validation.value = validationResult.value; - } - if (freshnessResult.status === "fulfilled") { - freshness.value = freshnessResult.value; - } - if (keysResult.status === "fulfilled" && keysResult.value) { - keys.value = keysResult.value.items || []; - } - - const failed = results.find(result => result.status === "rejected"); - if (failed) { - pageError.value = - failed.reason?.message || t("errors.loadFailed"); - } - } - - async function loadDoc(path, openDetail = true) { - if (!path) return; - if (docQuery.value) docQuery.value = ""; - selectedDocPath.value = path; - if (openDetail) mobileDocView.value = "detail"; - selectedDoc.value = null; - docLoading.value = true; - docError.value = ""; - docHistory.value = []; - historyError.value = ""; - docDiff.value = ""; - diffError.value = ""; - try { - selectedDoc.value = await apiGet( - `/docs/read?path=${encodeURIComponent(path)}` - ); - if (storageIsDb.value) { - try { - docHistory.value = await apiGet( - `/documents/${encodePath(path)}/history` - ); - } catch { - historyError.value = t("docs.noHistory"); - } - } else { - historyError.value = t("docs.noHistory"); - } - } catch (error) { - docError.value = - error instanceof Error ? error.message : t("errors.loadFailed"); - } finally { - docLoading.value = false; - } - } - - async function requestDiff(fromVersion, toVersion) { - docDiff.value = ""; - diffError.value = ""; - if (!selectedDocPath.value) return; - try { - const data = await apiGet( - `/documents/${encodePath(selectedDocPath.value)}/diff?from=${fromVersion}&to=${toVersion}` - ); - docDiff.value = data.diff || ""; - if (!docDiff.value) diffError.value = t("docs.noDiff"); - } catch (error) { - diffError.value = - error instanceof Error ? error.message : t("errors.loadFailed"); - } - } - - async function loadDiffFrom(versionNo) { - const latest = docHistory.value.length - ? Math.max(...docHistory.value.map(version => version.version_no)) - : versionNo; - await requestDiff(versionNo, latest); - } - - async function loadLatestDiff() { - if (!docHistory.value.length) return; - const latest = Math.max( - ...docHistory.value.map(version => version.version_no) - ); - await requestDiff(Math.max(1, latest - 1), latest); - } - - function openProposal() { - if (!selectedDoc.value) return; - proposal.target = selectedDocPath.value; - proposal.content = - selectedDoc.value.raw || selectedDoc.value.body || defaultDocTemplate(); - proposal.summary = ""; - proposal.reason = ""; - proposalOpen.value = true; - } - - function openHistory() { - historyOpen.value = true; - if (selectedDocPath.value && !docHistory.value.length) { - loadDoc(selectedDocPath.value); - } - } - - function backToDocList() { - mobileDocView.value = "list"; - } - - function switchInventoryTab(tab) { - inventoryTab.value = tab; - if (tab === "json" && !inventoryRawText.value) { - refreshInventoryRaw(); - } - } - - function restoreVersion(versionNo) { - askConfirm({ - title: t("docs.restoreConfirm"), - message: t("docs.restoreConfirmText", { version: versionNo }), - confirmText: t("docs.restore"), - variant: "warning", - action: async () => { - try { - await apiSend( - `/documents/${encodePath(selectedDocPath.value)}/restore/${versionNo}?summary=${encodeURIComponent( - `${t("docs.restoreConfirm")} ${versionNo}` - )}`, - "POST" - ); - toast.success({ title: t("docs.restored") }); - await loadDoc(selectedDocPath.value); - await refreshChanges(); - } catch (error) { - toast.danger({ - title: t("errors.actionFailed"), - text: error instanceof Error ? error.message : t("errors.actionFailed") - }); - } - } - }); - } - - async function submitProposal() { - if ( - !proposal.summary.trim() || - !proposal.target.trim() || - !proposal.content.trim() - ) { - toast.warning({ - title: t("common.error"), - text: t("docs.proposalMeta") - }); - return; - } - proposalRunning.value = true; - try { - const created = await apiSend("/changes", "POST", { - kind: "doc", - target: proposal.target.trim(), - summary: proposal.summary.trim(), - reason: proposal.reason.trim(), - payload: { content: proposal.content } - }); - toast.success({ - title: t("docs.proposalCreated"), - text: created.target || created.id - }); - proposal.summary = ""; - proposal.reason = ""; - proposalOpen.value = false; - activePage.value = "changes"; - drawerOpen.value = false; - await refreshChanges(); - await loadChange(created.id); - } catch (error) { - toast.danger({ - title: t("errors.actionFailed"), - text: error instanceof Error ? error.message : t("errors.actionFailed") - }); - } finally { - proposalRunning.value = false; - } - } - - async function refreshChanges() { - try { - changes.value = await apiGet("/changes"); - if ( - selectedChangeId.value && - changes.value.some(change => change.id === selectedChangeId.value) - ) { - await loadChange(selectedChangeId.value); - } else if (changes.value.length) { - await loadChange(changes.value[0].id); - } else { - selectedChangeId.value = ""; - selectedChange.value = null; - } - } catch (error) { - changeError.value = - error instanceof Error ? error.message : t("errors.loadFailed"); - } - } - - async function loadChange(id) { - selectedChangeId.value = id; - changeLoading.value = true; - changeError.value = ""; - try { - selectedChange.value = await apiGet( - `/changes/${encodeURIComponent(id)}` - ); - } catch (error) { - selectedChange.value = null; - changeError.value = - error instanceof Error ? error.message : t("errors.loadFailed"); - } finally { - changeLoading.value = false; - } - } - - function applyChange(change) { - if (!change) return; - askConfirm({ - title: t("changes.applyConfirm"), - message: t("changes.applyConfirmText"), - confirmText: t("changes.apply"), - variant: "success", - action: async () => { - applyingChange.value = true; - try { - await apiSend( - `/changes/${encodeURIComponent(change.id)}/apply`, - "POST" - ); - toast.success({ title: t("changes.applied") }); - await refreshChanges(); - await refreshStatus(); - } catch (error) { - toast.danger({ - title: t("errors.actionFailed"), - text: error instanceof Error ? error.message : t("errors.actionFailed") - }); - } finally { - applyingChange.value = false; - } - } - }); - } - - async function refreshStatus() { - const results = await Promise.allSettled([ - apiGet("/validate"), - apiGet("/health/freshness") - ]); - if (results[0].status === "fulfilled") validation.value = results[0].value; - if (results[1].status === "fulfilled") freshness.value = results[1].value; - } - - async function loadInventoryType(type) { - if (!type) return; - inventoryType.value = type; - selectedInventoryId.value = ""; - inventoryLoading.value = true; - inventoryError.value = ""; - try { - inventoryRawText.value = ""; - inventoryRecords.value = (await apiGet(`/inventory/${encodeURIComponent(type)}`)) || []; - selectedInventoryId.value = inventoryRecords.value[0]?.id || ""; - if (inventoryTab.value === "json") await refreshInventoryRaw(); - } catch (error) { - inventoryRecords.value = []; - inventoryError.value = - error instanceof Error ? error.message : t("errors.loadFailed"); - } finally { - inventoryLoading.value = false; - } - } - - async function refreshInventoryRaw() { - if (!inventoryType.value) { - inventoryRawText.value = ""; - return; - } - try { - const data = await apiGet( - `/inventory/${encodeURIComponent(inventoryType.value)}?raw=true` - ); - inventoryRawText.value = data.raw || ""; - } catch (error) { - inventoryError.value = - error instanceof Error ? error.message : t("errors.loadFailed"); - inventoryRaw.value = false; - } - } - - async function toggleInventoryRaw() { - inventoryRaw.value = !inventoryRaw.value; - if (inventoryRaw.value) { - await refreshInventoryRaw(); - } - } - - async function loadKeys() { - if (!user.value) return; - keysLoading.value = true; - keysError.value = ""; - try { - const data = await apiGet( - `/mcp-keys${keysShowAll.value ? "?all=true" : ""}` - ); - keys.value = data.items || []; - } catch (error) { - keysError.value = - error instanceof Error ? error.message : t("errors.loadFailed"); - } finally { - keysLoading.value = false; - } - } - - async function createKey() { - if (!keyForm.consumer.trim()) { - toast.warning({ title: t("common.error"), text: t("keys.consumer") }); - return; - } - keysLoading.value = true; - keysError.value = ""; - try { - const data = await apiSend("/mcp-keys", "POST", { - consumer: keyForm.consumer.trim(), - name: keyForm.name.trim() - }); - issuedToken.value = data.token; - issuedKey.value = data; - keyForm.name = ""; - toast.success({ title: t("keys.issuedTitle") }); - await loadKeys(); - } catch (error) { - keysError.value = - error instanceof Error ? error.message : t("errors.actionFailed"); - } finally { - keysLoading.value = false; - } - } - - function rotateKey(key) { - askConfirm({ - title: t("keys.rotate"), - message: t("keys.issuedText"), - confirmText: t("keys.rotate"), - variant: "warning", - action: async () => { - try { - const data = await apiSend( - `/mcp-keys/${encodeURIComponent(key.key_id)}/rotate`, - "POST" - ); - issuedToken.value = data.token; - issuedKey.value = data; - toast.success({ title: t("keys.rotated") }); - await loadKeys(); - } catch (error) { - toast.danger({ - title: t("errors.actionFailed"), - text: error instanceof Error ? error.message : t("errors.actionFailed") - }); - } - } - }); - } - - function revokeKey(key) { - askConfirm({ - title: t("keys.revokeConfirm"), - message: t("keys.revokeConfirmText"), - confirmText: t("keys.revoke"), - variant: "danger", - action: async () => { - try { - await apiSend( - `/mcp-keys/${encodeURIComponent(key.key_id)}`, - "DELETE" - ); - toast.success({ title: t("keys.revoked") }); - await loadKeys(); - } catch (error) { - toast.danger({ - title: t("errors.actionFailed"), - text: error instanceof Error ? error.message : t("errors.actionFailed") - }); - } - } - }); - } - - async function copyToken() { - try { - await navigator.clipboard.writeText(issuedToken.value); - toast.success({ title: t("common.copied") }); - } catch { - toast.danger({ title: t("errors.actionFailed") }); - } - } - - function dismissIssued() { - issuedToken.value = ""; - issuedKey.value = null; - } - - async function toggleAllKeys() { - if (!isAdmin.value) return; - keysShowAll.value = !keysShowAll.value; - await loadKeys(); - } - - async function changeLocale(value) { - if (!authEnabled.value || !user.value) { - setLocale(value); - localeOverride.value = null; - toast.success({ title: t("common.saved") }); - return; - } - try { - if (value === "auto") { - await apiSend("/me", "PATCH", { locale: "" }); - const data = await apiGet("/me"); - user.value = data.user; - localeOverride.value = null; - setLocale(data.locale_effective || "en"); - } else { - await apiSend("/me", "PATCH", { locale: value }); - localeOverride.value = value; - setLocale(value); - } - toast.success({ title: t("common.saved") }); - } catch (error) { - toast.danger({ - title: t("errors.saveFailed"), - text: error instanceof Error ? error.message : t("errors.saveFailed") - }); - } - } - - function login() { - window.location.assign("/api/auth/login"); - } - - function logout() { - askConfirm({ - title: t("auth.logoutConfirm"), - message: t("auth.logoutConfirmText"), - confirmText: t("nav.logout"), - variant: "danger", - action: async () => { - try { - await apiSend("/auth/logout", "POST"); - } catch { - /* the local session is cleared regardless */ - } - user.value = null; - localeOverride.value = null; - activePage.value = "docs"; - toast.info({ title: t("auth.loggedOut") }); - } - }); - } - - function askConfirm({ title, message, confirmText, variant, action }) { - confirmState.title = title || ""; - confirmState.message = message || ""; - confirmState.confirmText = confirmText || ""; - confirmState.variant = variant || "warning"; - confirmState.action = action || null; - confirmState.open = true; - } - - function runConfirm() { - const action = confirmState.action; - confirmState.action = null; - if (action) action(); - } - - function clearConfirm() { - confirmState.action = null; - } - - function go(page) { - activePage.value = page; - if (page === "docs") mobileDocView.value = "list"; - drawerOpen.value = false; - if (page === "keys") loadKeys(); - if (page === "status") refreshStatus(); - } - - async function refreshAll() { - await loadMe(); - } - - watch(docQuery, value => { - window.clearTimeout(searchTimer); - const query = value.trim(); - if (!query) { - searchResults.value = []; - searching.value = false; - return; - } - searching.value = true; - searchTimer = window.setTimeout(async () => { - try { - searchResults.value = await apiGet( - `/search?q=${encodeURIComponent(query)}` - ); - } catch (error) { - toast.danger({ - title: t("errors.loadFailed"), - text: error instanceof Error ? error.message : t("errors.loadFailed") - }); - } finally { - searching.value = false; - } - }, 300); - }); - - onMounted(loadMe); - - return { - activeLocaleLabel, - activePage, - applyingChange, - applyChange, - authEnabled, - backToDocList, - booting, - canWrite, - changeError, - changeDetailItems, - changeLoading, - changes, - changeStatusVariant, - clearConfirm, - confirmState, - copyToken, - createKey, - diffError, - dismissIssued, - docDiff, - docError, - docFrontmatterItems, - docHistory, - docLoading, - docQuery, - docs, - drawerOpen, - filteredInventory, - formatDate, - freshness, - go, - healthStatus, - historyError, - historyOpen, - inventoryColumns, - inventoryDisplay, - inventoryError, - inventoryFieldItems, - inventoryFilter, - inventoryLoading, - inventoryRaw, - inventoryRecords, - inventoryTab, - inventoryTabs, - inventoryType, - inventoryTypes, - isAdmin, - isLatestVersion, - issuedKey, - issuedToken, - keyForm, - keys, - keysError, - keysLoading, - keysShowAll, - loadDiffFrom, - loadDoc, - loadInventoryType, - loadKeys, - loadLatestDiff, - locale, - localeOptions, - localeOverride, - login, - logout, - mobileDocView, - navItems, - openHistory, - openProposal, - pageError, - pageSubtitle, - pageTitle, - pretty, - proposal, - proposalOpen, - proposalRunning, - refreshAll, - renderedDocBody, - restoreVersion, - revokeKey, - rotateKey, - runConfirm, - searchResults, - searching, - selectedChange, - selectedChangeId, - selectedDoc, - selectedDocPath, - selectedInventoryId, - selectedInventoryRecord, - setActiveLocale: changeLocale, - settingsItems, - statusLabel, - storage, - storageIsDb, - submitProposal, - switchInventoryTab, - t, - toast, - toggleAllKeys, - toggleInventoryRaw, - user, - userDisplayName, - userInitials, - validation - }; - }, - template: ` -
-
-

{{ t('common.loading') }}…

-
- -
- - -

{{ t('auth.loginText') }}

- {{ pageError }} -
- {{ t('auth.login') }} - {{ t('auth.recheck') }} -
-
-
- -
- -
- -
- - - - - {{ pageError }} - -
-
- - -
-
- {{ t('common.back') }} -
- {{ t('docs.document') }} -

{{ selectedDoc?.path || t('docs.select') }}

-
-
- {{ t('common.history') }} - {{ t('common.diff') }} - {{ t('docs.newDraft') }} -
-
- - {{ docError }} - -
- - - - -
-
- {{ diffError }} -
-
-
- - -
-

{{ historyError }}

- -
-
- - {{ t('docs.restore') }} -
-
-
-
- {{ t('docs.diffTitle') }} - {{ t('common.close') }} -
-
{{ docDiff }}
-
- {{ diffError }} -
-
- - -

{{ t('docs.proposalMeta') }}

-
- - - - -
- {{ t('docs.submit') }} - {{ t('common.cancel') }} -
-
-
-
- -
-
-
- {{ type }} -
- {{ t('inventory.recordCount', { n: inventoryRecords.length }) }} -
- - {{ inventoryError }} - -
- - - - - - - - - - -
- -
- -
-
- - -
- - - - {{ changeError }} - -
- - - - -

{{ t('changes.noValidation') }}

- -
-
-
-
-
- -
-
- - - -
-
- - - - - - - - -
-
- -
- {{ t('keys.notConfigured') }} -
- -

{{ t('keys.createMeta') }}

-
- - -
- {{ t('keys.create') }} - {{ keysShowAll ? t('keys.own') : t('keys.showAll') }} -
-
- - {{ t('keys.issuedTitle') }} -

{{ t('keys.issuedText') }}

-

{{ issuedKey.consumer }} · …{{ issuedKey.token_hint }}

- {{ issuedToken }} -
- {{ t('keys.copyToken') }} - {{ t('common.close') }} -
-
- {{ keysError }} -
- - - -
-
-
- {{ key.name }} - {{ key.consumer }} · {{ key.role || t('common.unknown') }} · {{ (key.scopes || []).join(', ') }} · …{{ key.token_hint }} - {{ t('common.created') }}: {{ formatDate(key.created_at) }} · {{ t('common.lastUsed') }}: {{ formatDate(key.last_used_at) }} -
- {{ t('common.revoked') }} - {{ t('common.stale') }} -
-
-
- {{ t('keys.rotate') }} - {{ t('keys.revoke') }} -
-
-
-
-
-
- -
-
- -

{{ t('settings.languageMeta') }}

-
- {{ t('auth.localeAuto') }} - {{ option.label }} -
-
- - -
- {{ t('nav.logout') }} -
-
-
-
-
-
- - -
- ` -}; - -const App = { - components: { - AppScreen, - GnToastProvider - }, - template: ` - - - - ` -}; - -createApp(App).mount("#app"); +createApp(App).use(router).mount("#app"); diff --git a/ui/src/pages/ChangesPage.vue b/ui/src/pages/ChangesPage.vue new file mode 100644 index 0000000..bd9dd3a --- /dev/null +++ b/ui/src/pages/ChangesPage.vue @@ -0,0 +1,215 @@ + + + diff --git a/ui/src/pages/DocsPage.vue b/ui/src/pages/DocsPage.vue new file mode 100644 index 0000000..fb09ba1 --- /dev/null +++ b/ui/src/pages/DocsPage.vue @@ -0,0 +1,438 @@ + + + diff --git a/ui/src/pages/InventoryPage.vue b/ui/src/pages/InventoryPage.vue new file mode 100644 index 0000000..45a95fc --- /dev/null +++ b/ui/src/pages/InventoryPage.vue @@ -0,0 +1,190 @@ + + + diff --git a/ui/src/pages/KeysPage.vue b/ui/src/pages/KeysPage.vue new file mode 100644 index 0000000..a3ab9af --- /dev/null +++ b/ui/src/pages/KeysPage.vue @@ -0,0 +1,248 @@ + + + diff --git a/ui/src/pages/SettingsPage.vue b/ui/src/pages/SettingsPage.vue new file mode 100644 index 0000000..13f0dcd --- /dev/null +++ b/ui/src/pages/SettingsPage.vue @@ -0,0 +1,115 @@ + + + diff --git a/ui/src/pages/StatusPage.vue b/ui/src/pages/StatusPage.vue new file mode 100644 index 0000000..85da0dc --- /dev/null +++ b/ui/src/pages/StatusPage.vue @@ -0,0 +1,96 @@ + + + diff --git a/ui/src/router.js b/ui/src/router.js new file mode 100644 index 0000000..2faf062 --- /dev/null +++ b/ui/src/router.js @@ -0,0 +1,44 @@ +import { createRouter, createWebHistory } from "vue-router"; + +export const router = createRouter({ + history: createWebHistory(), + routes: [ + { + path: "/", + name: "docs", + component: () => import("./pages/DocsPage.vue"), + meta: { titleKey: "nav.docs" } + }, + { + path: "/inventory", + name: "inventory", + component: () => import("./pages/InventoryPage.vue"), + meta: { titleKey: "nav.inventory" } + }, + { + path: "/changes", + name: "changes", + component: () => import("./pages/ChangesPage.vue"), + meta: { titleKey: "nav.changes" } + }, + { + path: "/status", + name: "status", + component: () => import("./pages/StatusPage.vue"), + meta: { titleKey: "nav.status" } + }, + { + path: "/mcp-keys", + name: "mcp-keys", + component: () => import("./pages/KeysPage.vue"), + meta: { titleKey: "nav.keys" } + }, + { + path: "/settings", + name: "settings", + component: () => import("./pages/SettingsPage.vue"), + meta: { titleKey: "nav.settings" } + }, + { path: "/:pathMatch(.*)*", redirect: "/" } + ] +}); diff --git a/ui/src/styles.css b/ui/src/styles.css index 22deec8..b4a3b22 100644 --- a/ui/src/styles.css +++ b/ui/src/styles.css @@ -22,6 +22,103 @@ min-height: 100vh; } +/* ---------- Vue navigation shell ---------- */ + +.book-content { + width: 100%; + max-width: 1680px; + margin: 0 auto; + padding: 24px 32px 64px; +} + +.book-splash, +.book-gate { + min-height: 100vh; + display: flex; + align-items: center; + justify-content: center; + padding: 24px; +} + +.book-splash { + color: var(--gn-color-text-medium); +} + +.book-gate-card { + width: 100%; + max-width: 520px; + padding: 8px; +} + +.book-gate-card .card-content { + display: flex; + flex-direction: column; + gap: 14px; + padding: 28px; +} + +.book-gate-mark { + width: 44px; + height: 44px; + display: grid; + place-items: center; + background: var(--gn-color-accent); + color: var(--gn-color-black); + font-weight: var(--gn-font-weight-bold); +} + +.book-gate-kicker { + margin: 0; + color: var(--gn-color-text-medium); + font-size: var(--gn-font-size-xs); + font-weight: var(--gn-font-weight-bold); + letter-spacing: 0.08em; + text-transform: uppercase; +} + +.book-gate-card h1 { + margin: 0; + font-size: var(--gn-font-size-xl); +} + +.book-shell-footer { + display: flex; + width: 100%; + min-width: 0; + align-items: center; + gap: 10px; +} + +.book-shell-footer > .identity { + flex: 1; + min-width: 0; +} + +.book-shell-footer .identity-meta { + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.book-shell-footer-actions { + display: flex; + flex: 0 0 auto; + align-items: center; + gap: 4px; +} + +.book-shell-footer-actions .list.list-nav { + max-width: none; +} + +.book-shell-footer-actions .list-action { + padding: 8px; +} + +.book-shell-footer-actions .list-label { + gap: 6px; +} + /* ---------- auth gate ---------- */ .gnb-boot, @@ -818,6 +915,10 @@ padding: 16px 16px 48px; } + .book-content { + padding: 16px 16px 48px; + } + .gnb-mobile-menu, .gnb-mobile-back { display: inline-flex;