arcrun — AI workflow execution engine (clean history)
Self-hosted 開源:WASM 零件 + recipe + cypher-executor,跑在你自己的 Cloudflare。 此為重建的乾淨歷史起點(移除曾誤 commit 的 GCP SA 金鑰,舊歷史保留在 richblack/arcrun 與本地 backup 分支)。含: - acr init --self-hosted installer(建 KV/R2 + codeload 拉預編譯 wasm + wrangler deploy + seed recipe) - recipe push 把關(資料外流提醒 + 打通檢查) - 19 個正當零件預編譯 wasm(claude_api/km_writer/kbdb_upsert_block 排除:違反 DECISIONS §1) - CLI / cypher-executor / registry / 完整 SDD Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
'use client';
|
||||
|
||||
// Mira 共用 Markdown 渲染器(河道 + Wiki 共用)
|
||||
// SDD: polaris/mira/.agents/specs/mira-app/design.md §3.5.7
|
||||
|
||||
import { useMemo } from 'react';
|
||||
import ReactMarkdown from 'react-markdown';
|
||||
import remarkGfm from 'remark-gfm';
|
||||
|
||||
export function MarkdownView({ text }: { text: string }) {
|
||||
// 兩階段預處理:1. strip Logseq metadata;2. [[entity]] 轉成 markdown link
|
||||
const cleaned = useMemo(() => expandWikilinks(stripLogseqMeta(text)), [text]);
|
||||
return (
|
||||
<div className="mira-md">
|
||||
<ReactMarkdown
|
||||
remarkPlugins={[remarkGfm]}
|
||||
components={{
|
||||
a: ({ href, children, ...rest }) => {
|
||||
const isWikiLink = typeof href === 'string' && href.startsWith('/mira/wiki/');
|
||||
return (
|
||||
<a
|
||||
href={href}
|
||||
{...(isWikiLink ? {} : { target: '_blank', rel: 'noopener noreferrer' })}
|
||||
className="wiki-link"
|
||||
{...rest}
|
||||
>
|
||||
{children}
|
||||
</a>
|
||||
);
|
||||
},
|
||||
// 圖片不直接 inline 顯示(避免大圖打亂 feed),改成連結
|
||||
img: ({ src, alt }) => {
|
||||
const href = typeof src === 'string' ? src : '';
|
||||
return href ? (
|
||||
<a
|
||||
href={href}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="wiki-link"
|
||||
style={{ fontStyle: 'italic' }}
|
||||
>
|
||||
🖼 {alt || 'image'}
|
||||
</a>
|
||||
) : null;
|
||||
},
|
||||
}}
|
||||
>
|
||||
{cleaned}
|
||||
</ReactMarkdown>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// Strip Logseq 專屬語法
|
||||
// - 屬性行:`xxx:: yyy`、`collapsed:: true`、`id:: ...`、`logseq.order-list-type:: ...`
|
||||
// - block ref:`((uuid))` 暫時保留為純文字
|
||||
export function stripLogseqMeta(text: string): string {
|
||||
return text
|
||||
.split('\n')
|
||||
.filter((line) => {
|
||||
const trimmed = line.trimStart();
|
||||
if (/^[a-zA-Z][a-zA-Z0-9_.-]*::\s/.test(trimmed)) return false;
|
||||
return true;
|
||||
})
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
// 把 [[entity]] 轉成 markdown link 指向 /mira/wiki/wiki-{entity}
|
||||
// 對應 mira-app design.md §3.6.2 + tasks.md backlog #12
|
||||
export function expandWikilinks(text: string): string {
|
||||
return text.replace(/\[\[([^\[\]\n]+?)\]\]/g, (_, entity: string) => {
|
||||
const e = entity.trim();
|
||||
if (!e) return '[[]]';
|
||||
const url = `/mira/wiki/${encodeURIComponent('wiki-' + e)}`;
|
||||
return `[${e}](${url})`;
|
||||
});
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,87 @@
|
||||
'use client';
|
||||
|
||||
// Mira 子應用 layout
|
||||
// SDD: polaris/mira/.agents/specs/mira-app/design.md §5.5
|
||||
// 規範:白名單 user 進得去;非白名單 user 看到「即將開放」頁
|
||||
// middleware 已做未登入跳 /login?redirect=/mira 檢查(不在這裡重做)
|
||||
|
||||
import { useEffect, useState } from 'react';
|
||||
import SiteNav from '../components/SiteNav';
|
||||
import { MATRIX_APPS } from '../components/apps';
|
||||
|
||||
const API_BASE = process.env.NEXT_PUBLIC_API_BASE ?? 'https://cypher.arcrun.dev';
|
||||
|
||||
type Me = { email: string; display_name: string; api_key: string };
|
||||
|
||||
const MIRA = MATRIX_APPS.find(a => a.id === 'mira');
|
||||
const ALLOWED = new Set(MIRA?.allowlist_emails ?? []);
|
||||
|
||||
export default function MiraLayout({ children }: { children: React.ReactNode }) {
|
||||
const [me, setMe] = useState<Me | null | undefined>(undefined);
|
||||
|
||||
useEffect(() => {
|
||||
fetch(`${API_BASE}/me`, { credentials: 'include' })
|
||||
.then(r => r.ok ? r.json() as Promise<Me> : null)
|
||||
.then(u => setMe(u))
|
||||
.catch(() => setMe(null));
|
||||
}, []);
|
||||
|
||||
if (me === undefined) {
|
||||
return (
|
||||
<>
|
||||
<SiteNav currentPath="/mira" />
|
||||
<div className="flex-1 flex items-center justify-center text-[#666]">載入中…</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
if (me === null) {
|
||||
// 理論上 middleware 已擋住,但保險
|
||||
if (typeof window !== 'undefined') {
|
||||
window.location.href = '/login?redirect=/mira';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!ALLOWED.has(me.email)) {
|
||||
return (
|
||||
<>
|
||||
<SiteNav currentPath="/mira" />
|
||||
<BetaBlocked email={me.email} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<SiteNav currentPath="/mira" />
|
||||
{children}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function BetaBlocked({ email }: { email: string }) {
|
||||
return (
|
||||
<main className="flex-1 flex items-center justify-center px-6">
|
||||
<div className="max-w-md text-center space-y-4">
|
||||
<div className="text-6xl mb-2">🌊</div>
|
||||
<h1 className="text-3xl font-bold text-white">Mira 仍封測中</h1>
|
||||
<p className="text-[#888] leading-relaxed">
|
||||
Mira 是 arcrun 的個人化 KM 河道,目前僅開放給少數測試用戶。
|
||||
</p>
|
||||
<p className="text-sm text-[#555]">
|
||||
你登入的帳號是 <span className="font-mono text-[#888]">{email}</span>,
|
||||
不在白名單內。準備好對外開放時會公告。
|
||||
</p>
|
||||
<div className="pt-4">
|
||||
<a
|
||||
href="/dashboard"
|
||||
className="inline-block bg-indigo-600 hover:bg-indigo-500 text-white px-5 py-2 rounded-md text-sm font-medium transition-colors"
|
||||
>
|
||||
回 Dashboard
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,861 @@
|
||||
/* Mira — 社群貼文式 KM 河道
|
||||
* 視覺參考:Facebook / X / LinkedIn
|
||||
* Scope 在 .mira-app 容器內,避免汙染 landing 的 Tailwind 樣式
|
||||
*/
|
||||
|
||||
.mira-app {
|
||||
/* Surfaces */
|
||||
--mira-bg-0: #0e0e0d;
|
||||
--mira-bg-1: #1a1a18;
|
||||
--mira-bg-2: #252320;
|
||||
--mira-bg-3: #302d28;
|
||||
|
||||
--mira-line: #2e2c27;
|
||||
--mira-line-soft: #1f1d1a;
|
||||
|
||||
/* Text — 高對比 */
|
||||
--mira-text-1: #f0eee8;
|
||||
--mira-text-2: #c9c4b8;
|
||||
--mira-text-3: #9c968a;
|
||||
--mira-text-4: #6c685e;
|
||||
|
||||
--mira-accent: oklch(0.78 0.13 75);
|
||||
--mira-accent-soft: oklch(0.78 0.13 75 / 0.16);
|
||||
--mira-accent-line: oklch(0.78 0.13 75 / 0.4);
|
||||
|
||||
--mira-conflict: oklch(0.72 0.14 30);
|
||||
--mira-conflict-soft: oklch(0.72 0.14 30 / 0.13);
|
||||
|
||||
--mira-src-logseq: oklch(0.75 0.08 250);
|
||||
--mira-src-mobile: oklch(0.78 0.07 160);
|
||||
--mira-src-tg: oklch(0.78 0.08 220);
|
||||
--mira-src-rss: oklch(0.78 0.08 30);
|
||||
--mira-src-ai: oklch(0.82 0.10 95);
|
||||
|
||||
--mira-radius-sm: 6px;
|
||||
--mira-radius: 10px;
|
||||
--mira-radius-lg: 14px;
|
||||
|
||||
--mira-font-zh: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
|
||||
--mira-font-en: "Inter Tight", "Helvetica Neue", Helvetica, Arial, sans-serif;
|
||||
--mira-font-mono: "JetBrains Mono", "SF Mono", Menlo, monospace;
|
||||
|
||||
background: var(--mira-bg-0);
|
||||
color: var(--mira-text-1);
|
||||
font-family: var(--mira-font-zh);
|
||||
/* 不啟用 palt:保留中文標點全寬,避免標點看起來只有半寬 */
|
||||
-webkit-font-smoothing: antialiased;
|
||||
text-rendering: optimizeLegibility;
|
||||
letter-spacing: 0.01em;
|
||||
line-height: 1.65;
|
||||
min-height: calc(100vh - 73px);
|
||||
}
|
||||
|
||||
.mira-app .mira-num,
|
||||
.mira-app .mira-en {
|
||||
font-family: var(--mira-font-en);
|
||||
letter-spacing: 0;
|
||||
}
|
||||
|
||||
.mira-app .mira-content {
|
||||
max-width: 920px;
|
||||
margin: 0 auto;
|
||||
padding: 24px 16px 80px;
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.mira-app .mira-content {
|
||||
padding: 12px 0 60px;
|
||||
}
|
||||
}
|
||||
|
||||
/* ── card 卡片 ── */
|
||||
.mira-app .mira-card {
|
||||
background: var(--mira-bg-1);
|
||||
border: 1px solid var(--mira-line);
|
||||
border-radius: var(--mira-radius);
|
||||
margin-bottom: 12px;
|
||||
/* 不要 overflow: hidden — 會 clip ⋮ menu dropdown */
|
||||
position: relative;
|
||||
}
|
||||
@media (max-width: 640px) {
|
||||
.mira-app .mira-card {
|
||||
border-radius: 0;
|
||||
border-left: none;
|
||||
border-right: none;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
/* ── composer 寫貼文 ── */
|
||||
.mira-app .mira-composer-card {
|
||||
padding: 14px 16px;
|
||||
}
|
||||
.mira-app .mira-composer-row {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
align-items: flex-start;
|
||||
}
|
||||
.mira-app .mira-composer-textarea {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
background: transparent;
|
||||
border: none;
|
||||
outline: none;
|
||||
resize: none;
|
||||
font-family: inherit;
|
||||
font-size: 16px;
|
||||
line-height: 1.65;
|
||||
color: var(--mira-text-1);
|
||||
padding: 8px 0;
|
||||
}
|
||||
.mira-app .mira-composer-textarea::placeholder {
|
||||
color: var(--mira-text-3);
|
||||
}
|
||||
.mira-app .mira-composer-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding-top: 10px;
|
||||
margin-top: 8px;
|
||||
border-top: 1px solid var(--mira-line-soft);
|
||||
margin-left: 52px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
/* ── avatar ── */
|
||||
.mira-app .mira-avatar {
|
||||
border-radius: 50%;
|
||||
flex-shrink: 0;
|
||||
background: var(--mira-bg-2);
|
||||
object-fit: cover;
|
||||
}
|
||||
.mira-app .mira-avatar-fallback {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
background: linear-gradient(135deg, var(--mira-bg-2), var(--mira-bg-3));
|
||||
color: var(--mira-text-1);
|
||||
font-weight: 600;
|
||||
font-family: var(--mira-font-en);
|
||||
}
|
||||
|
||||
/* Mira 自有頭像 — 跟 leo 區分(紫色漸層 + 機器人 emoji) */
|
||||
.mira-app .mira-avatar-mira {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
background: linear-gradient(135deg, oklch(0.45 0.15 280), oklch(0.55 0.18 300));
|
||||
color: #fff;
|
||||
border-radius: 50%;
|
||||
flex-shrink: 0;
|
||||
/* emoji 本身有色彩,背景僅當邊框襯托 */
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
/* ── post 貼文 ── */
|
||||
.mira-app .mira-post {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.mira-app .mira-post-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 14px 16px 10px;
|
||||
}
|
||||
.mira-app .mira-post-author {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
.mira-app .mira-post-name {
|
||||
font-size: 14.5px;
|
||||
font-weight: 600;
|
||||
color: var(--mira-text-1);
|
||||
line-height: 1.3;
|
||||
}
|
||||
.mira-app .mira-post-time {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-size: 12px;
|
||||
color: var(--mira-text-3);
|
||||
font-family: var(--mira-font-en);
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
/* ── post body 內文 ── */
|
||||
.mira-app .mira-post-body {
|
||||
padding: 0 16px 12px;
|
||||
}
|
||||
.mira-app .mira-post-content {
|
||||
font-size: 15px;
|
||||
line-height: 1.7;
|
||||
color: var(--mira-text-1);
|
||||
word-break: break-word;
|
||||
white-space: normal;
|
||||
}
|
||||
.mira-app .mira-post-content-full {
|
||||
/* 展開模式:顯示每個 sub-block 為獨立行,可編輯 */
|
||||
font-size: 14.5px;
|
||||
}
|
||||
|
||||
/* react-markdown render 樣式 */
|
||||
.mira-app .mira-md > *:first-child { margin-top: 0; }
|
||||
.mira-app .mira-md > *:last-child { margin-bottom: 0; }
|
||||
|
||||
.mira-app .mira-md p {
|
||||
margin: 0 0 8px;
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.mira-app .mira-md h1,
|
||||
.mira-app .mira-md h2,
|
||||
.mira-app .mira-md h3,
|
||||
.mira-app .mira-md h4,
|
||||
.mira-app .mira-md h5,
|
||||
.mira-app .mira-md h6 {
|
||||
margin: 14px 0 6px;
|
||||
font-weight: 700;
|
||||
color: var(--mira-text-1);
|
||||
line-height: 1.3;
|
||||
}
|
||||
.mira-app .mira-md h1 { font-size: 1.5em; }
|
||||
.mira-app .mira-md h2 { font-size: 1.3em; }
|
||||
.mira-app .mira-md h3 { font-size: 1.15em; font-weight: 600; }
|
||||
.mira-app .mira-md h4,
|
||||
.mira-app .mira-md h5,
|
||||
.mira-app .mira-md h6 { font-size: 1em; font-weight: 600; }
|
||||
|
||||
.mira-app .mira-md ul,
|
||||
.mira-app .mira-md ol {
|
||||
margin: 4px 0 8px;
|
||||
padding-left: 22px;
|
||||
}
|
||||
.mira-app .mira-md ul {
|
||||
list-style: disc;
|
||||
}
|
||||
.mira-app .mira-md ul ul {
|
||||
list-style: circle;
|
||||
}
|
||||
.mira-app .mira-md ul ul ul {
|
||||
list-style: square;
|
||||
}
|
||||
.mira-app .mira-md ol {
|
||||
list-style: decimal;
|
||||
}
|
||||
.mira-app .mira-md ul ul,
|
||||
.mira-app .mira-md ul ol,
|
||||
.mira-app .mira-md ol ul,
|
||||
.mira-app .mira-md ol ol {
|
||||
margin: 4px 0;
|
||||
}
|
||||
.mira-app .mira-md li {
|
||||
margin: 2px 0;
|
||||
line-height: 1.7;
|
||||
}
|
||||
/* GFM task list 的 li 不顯示 bullet(checkbox 取代)*/
|
||||
.mira-app .mira-md li:has(> input[type="checkbox"]) {
|
||||
list-style: none;
|
||||
margin-left: -22px;
|
||||
}
|
||||
.mira-app .mira-md li > p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.mira-app .mira-md blockquote {
|
||||
margin: 8px 0;
|
||||
padding: 4px 12px;
|
||||
border-left: 3px solid var(--mira-line);
|
||||
color: var(--mira-text-2);
|
||||
background: var(--mira-bg-2);
|
||||
border-radius: 0 4px 4px 0;
|
||||
}
|
||||
.mira-app .mira-md blockquote p:last-child { margin-bottom: 0; }
|
||||
|
||||
.mira-app .mira-md hr {
|
||||
border: none;
|
||||
border-top: 1px solid var(--mira-line);
|
||||
margin: 16px 0;
|
||||
}
|
||||
|
||||
.mira-app .mira-md code {
|
||||
font-family: var(--mira-font-mono);
|
||||
font-size: 0.9em;
|
||||
background: var(--mira-bg-2);
|
||||
padding: 1px 5px;
|
||||
border-radius: 4px;
|
||||
border: 1px solid var(--mira-line-soft);
|
||||
}
|
||||
.mira-app .mira-md pre {
|
||||
margin: 8px 0;
|
||||
padding: 12px;
|
||||
background: var(--mira-bg-2);
|
||||
border: 1px solid var(--mira-line-soft);
|
||||
border-radius: 6px;
|
||||
overflow-x: auto;
|
||||
}
|
||||
.mira-app .mira-md pre code {
|
||||
background: transparent;
|
||||
border: none;
|
||||
padding: 0;
|
||||
font-size: 0.85em;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.mira-app .mira-md table {
|
||||
border-collapse: collapse;
|
||||
margin: 8px 0;
|
||||
width: 100%;
|
||||
font-size: 0.95em;
|
||||
}
|
||||
.mira-app .mira-md th,
|
||||
.mira-app .mira-md td {
|
||||
border: 1px solid var(--mira-line);
|
||||
padding: 6px 10px;
|
||||
text-align: left;
|
||||
}
|
||||
.mira-app .mira-md th {
|
||||
background: var(--mira-bg-2);
|
||||
color: var(--mira-text-1);
|
||||
font-weight: 600;
|
||||
}
|
||||
.mira-app .mira-md tr:nth-child(even) {
|
||||
background: rgba(255, 255, 255, 0.02);
|
||||
}
|
||||
|
||||
.mira-app .mira-md strong { color: var(--mira-text-1); font-weight: 700; }
|
||||
.mira-app .mira-md em { font-style: italic; }
|
||||
.mira-app .mira-md del { color: var(--mira-text-3); }
|
||||
|
||||
/* GFM task list */
|
||||
.mira-app .mira-md input[type="checkbox"] {
|
||||
margin-right: 6px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
/* ── show more ── */
|
||||
.mira-app .mira-show-more {
|
||||
background: transparent;
|
||||
border: none;
|
||||
color: var(--mira-accent);
|
||||
font-size: 14px;
|
||||
cursor: pointer;
|
||||
padding: 4px 0;
|
||||
margin-top: 4px;
|
||||
font-family: inherit;
|
||||
}
|
||||
.mira-app .mira-show-more:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/* ── footer 互動列 ── */
|
||||
.mira-app .mira-post-footer {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
border-top: 1px solid var(--mira-line-soft);
|
||||
padding: 4px 8px;
|
||||
margin: 0 8px;
|
||||
}
|
||||
.mira-app .mira-action-btn {
|
||||
background: transparent;
|
||||
border: none;
|
||||
color: var(--mira-text-2);
|
||||
font-size: 13.5px;
|
||||
font-family: inherit;
|
||||
padding: 8px 14px;
|
||||
cursor: pointer;
|
||||
border-radius: 6px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
transition: background 0.12s, color 0.12s;
|
||||
}
|
||||
.mira-app .mira-action-btn:hover,
|
||||
.mira-app .mira-action-btn:active {
|
||||
background: var(--mira-bg-2);
|
||||
color: var(--mira-text-1);
|
||||
}
|
||||
.mira-app .mira-action-count {
|
||||
font-size: 12px;
|
||||
color: var(--mira-text-3);
|
||||
font-family: var(--mira-font-en);
|
||||
}
|
||||
|
||||
/* ── replies 對整篇的留言 ── */
|
||||
.mira-app .mira-post-replies {
|
||||
background: var(--mira-bg-0);
|
||||
padding: 8px 16px;
|
||||
border-top: 1px solid var(--mira-line-soft);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
.mira-app .mira-show-replies {
|
||||
background: transparent;
|
||||
border: none;
|
||||
color: var(--mira-text-2);
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
padding: 6px 4px;
|
||||
text-align: left;
|
||||
font-family: inherit;
|
||||
font-weight: 500;
|
||||
}
|
||||
.mira-app .mira-show-replies:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
.mira-app .mira-reply-composer {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
padding: 10px 16px;
|
||||
border-top: 1px solid var(--mira-line-soft);
|
||||
background: var(--mira-bg-0);
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
/* ── reply line ── */
|
||||
.mira-app .mira-reply-line {
|
||||
margin-bottom: 6px;
|
||||
padding: 8px 10px;
|
||||
background: var(--mira-bg-1);
|
||||
border-radius: 16px;
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 8px;
|
||||
position: relative;
|
||||
}
|
||||
.mira-app .mira-reply-line.is-ai {
|
||||
background: var(--mira-accent-soft);
|
||||
}
|
||||
/* reply line 內的 ⋮ 永遠顯示(取代 hover only)*/
|
||||
.mira-app .mira-reply-line .mira-menu-wrap {
|
||||
opacity: 1;
|
||||
}
|
||||
.mira-app .mira-reply-icon {
|
||||
font-size: 13px;
|
||||
color: var(--mira-text-2);
|
||||
flex-shrink: 0;
|
||||
margin-top: 2px;
|
||||
}
|
||||
.mira-app .mira-reply-line.is-ai .mira-reply-icon {
|
||||
color: var(--mira-accent);
|
||||
}
|
||||
.mira-app .mira-reply-content {
|
||||
font-size: 13.5px;
|
||||
line-height: 1.6;
|
||||
color: var(--mira-text-1);
|
||||
word-break: break-word;
|
||||
white-space: normal;
|
||||
}
|
||||
.mira-app .mira-reply-nested {
|
||||
margin-left: 20px;
|
||||
margin-top: 4px;
|
||||
padding-left: 8px;
|
||||
border-left: 2px solid var(--mira-line-soft);
|
||||
}
|
||||
|
||||
/* ── source tag ── */
|
||||
.mira-app .src-tag {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
padding: 1px 7px;
|
||||
border-radius: 999px;
|
||||
font-size: 11px;
|
||||
font-family: var(--mira-font-en);
|
||||
letter-spacing: 0.04em;
|
||||
background: var(--mira-bg-2);
|
||||
color: var(--mira-text-2);
|
||||
border: 1px solid var(--mira-line);
|
||||
}
|
||||
.mira-app .src-dot {
|
||||
width: 5px;
|
||||
height: 5px;
|
||||
border-radius: 50%;
|
||||
background: var(--mira-text-3);
|
||||
}
|
||||
.mira-app .src-tag.logseq .src-dot { background: var(--mira-src-logseq); }
|
||||
.mira-app .src-tag.mobile .src-dot { background: var(--mira-src-mobile); }
|
||||
.mira-app .src-tag.tg .src-dot { background: var(--mira-src-tg); }
|
||||
.mira-app .src-tag.rss .src-dot { background: var(--mira-src-rss); }
|
||||
.mira-app .src-tag.ai .src-dot { background: var(--mira-src-ai); }
|
||||
|
||||
/* ── wiki link ── */
|
||||
.mira-app .wiki-link {
|
||||
color: var(--mira-accent);
|
||||
cursor: pointer;
|
||||
text-decoration: none;
|
||||
border-bottom: 1px dashed var(--mira-accent-line);
|
||||
padding-bottom: 1px;
|
||||
}
|
||||
.mira-app .wiki-link:hover {
|
||||
background: var(--mira-accent-soft);
|
||||
}
|
||||
|
||||
/* ── empty state ── */
|
||||
.mira-app .empty-state {
|
||||
text-align: center;
|
||||
padding: 80px 20px;
|
||||
color: var(--mira-text-2);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
/* ── icon button ── */
|
||||
.mira-app .mira-icon-btn {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
border-radius: 50%;
|
||||
cursor: pointer;
|
||||
color: var(--mira-text-2);
|
||||
background: transparent;
|
||||
border: none;
|
||||
font-size: 14px;
|
||||
line-height: 1;
|
||||
padding: 0;
|
||||
transition: background 0.12s, color 0.12s;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.mira-app .mira-icon-btn:hover,
|
||||
.mira-app .mira-icon-btn:active {
|
||||
background: var(--mira-bg-2);
|
||||
color: var(--mira-text-1);
|
||||
}
|
||||
.mira-app .mira-icon-btn-vertical {
|
||||
font-size: 20px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0;
|
||||
}
|
||||
|
||||
/* ── ⋮ menu (dropdown) ── */
|
||||
.mira-app .mira-menu-wrap {
|
||||
position: relative;
|
||||
}
|
||||
.mira-app .mira-menu {
|
||||
position: absolute;
|
||||
right: 0;
|
||||
top: calc(100% + 4px);
|
||||
min-width: 160px;
|
||||
background: var(--mira-bg-1);
|
||||
border: 1px solid var(--mira-line);
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
|
||||
padding: 4px;
|
||||
z-index: 10;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1px;
|
||||
}
|
||||
.mira-app .mira-menu-item {
|
||||
background: transparent;
|
||||
border: none;
|
||||
text-align: left;
|
||||
padding: 10px 14px;
|
||||
border-radius: 5px;
|
||||
color: var(--mira-text-1);
|
||||
font-size: 14px;
|
||||
cursor: pointer;
|
||||
font-family: inherit;
|
||||
transition: background 0.12s;
|
||||
}
|
||||
.mira-app .mira-menu-item:hover,
|
||||
.mira-app .mira-menu-item:active {
|
||||
background: var(--mira-bg-2);
|
||||
}
|
||||
.mira-app .mira-menu-item.danger {
|
||||
color: var(--mira-conflict);
|
||||
}
|
||||
.mira-app .mira-menu-item.danger:hover {
|
||||
background: var(--mira-conflict-soft);
|
||||
}
|
||||
|
||||
/* ── block-line(FullContent 模式)── */
|
||||
.mira-app .mira-block-line {
|
||||
position: relative;
|
||||
}
|
||||
.mira-app .mira-block-line .mira-menu-wrap {
|
||||
opacity: 0;
|
||||
transition: opacity 0.12s;
|
||||
}
|
||||
.mira-app .mira-block-line:hover .mira-menu-wrap {
|
||||
opacity: 1;
|
||||
}
|
||||
@media (hover: none) {
|
||||
/* 觸控裝置一律顯示 ⋮ */
|
||||
.mira-app .mira-block-line .mira-menu-wrap {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
.mira-app .mira-menu-wrap:has(.mira-menu) { opacity: 1 !important; }
|
||||
|
||||
/* ── edit textarea ── */
|
||||
.mira-app .mira-edit-textarea {
|
||||
width: 100%;
|
||||
background: var(--mira-bg-0);
|
||||
border: 1px solid var(--mira-accent-line);
|
||||
border-radius: 8px;
|
||||
padding: 10px 12px;
|
||||
font-family: inherit;
|
||||
font-size: 14px;
|
||||
line-height: 1.7;
|
||||
color: var(--mira-text-1);
|
||||
resize: vertical;
|
||||
outline: none;
|
||||
}
|
||||
.mira-app .mira-edit-textarea:focus {
|
||||
border-color: var(--mira-accent);
|
||||
}
|
||||
.mira-app .mira-edit-textarea::placeholder {
|
||||
color: var(--mira-text-3);
|
||||
}
|
||||
.mira-app .mira-edit-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-top: 6px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
/* ── markdown toolbar ── */
|
||||
.mira-app .mira-md-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
padding: 6px 8px;
|
||||
background: var(--mira-bg-2);
|
||||
border: 1px solid var(--mira-line);
|
||||
border-bottom: none;
|
||||
border-top-left-radius: 8px;
|
||||
border-top-right-radius: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
/* compact 模式:給 PostComposer 的 actions 列 inline 用 */
|
||||
.mira-app .mira-md-toolbar.compact {
|
||||
padding: 0;
|
||||
background: transparent;
|
||||
border: none;
|
||||
gap: 2px;
|
||||
}
|
||||
.mira-app .mira-md-btn {
|
||||
background: transparent;
|
||||
border: none;
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
border-radius: 5px;
|
||||
color: var(--mira-text-2);
|
||||
cursor: pointer;
|
||||
font-size: 13px;
|
||||
font-family: inherit;
|
||||
transition: background 0.12s, color 0.12s;
|
||||
padding: 0;
|
||||
line-height: 1;
|
||||
}
|
||||
.mira-app .mira-md-btn:hover,
|
||||
.mira-app .mira-md-btn:active {
|
||||
background: var(--mira-bg-3);
|
||||
color: var(--mira-text-1);
|
||||
}
|
||||
.mira-app .mira-md-btn em {
|
||||
font-style: italic;
|
||||
font-family: serif;
|
||||
}
|
||||
.mira-app .mira-md-hint {
|
||||
margin-left: auto;
|
||||
font-size: 11px;
|
||||
color: var(--mira-text-3);
|
||||
font-family: var(--mira-font-en);
|
||||
}
|
||||
/* toolbar 之後的 textarea 接續成一塊 */
|
||||
.mira-app .mira-md-toolbar + .mira-edit-textarea {
|
||||
border-top-left-radius: 0;
|
||||
border-top-right-radius: 0;
|
||||
border-top: none;
|
||||
}
|
||||
|
||||
/* ── kbd 提示 ── */
|
||||
.mira-app .mira-kbd {
|
||||
font-size: 11px;
|
||||
color: var(--mira-text-3);
|
||||
font-family: var(--mira-font-en);
|
||||
}
|
||||
|
||||
/* ── messages ── */
|
||||
.mira-app .mira-msg-error {
|
||||
font-size: 12px;
|
||||
color: var(--mira-conflict);
|
||||
}
|
||||
.mira-app .mira-error {
|
||||
padding: 16px;
|
||||
color: var(--mira-conflict);
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
/* ── buttons ── */
|
||||
.mira-app .mira-btn-primary {
|
||||
background: var(--mira-accent);
|
||||
border: none;
|
||||
color: var(--mira-bg-0);
|
||||
font-size: 13px;
|
||||
padding: 8px 18px;
|
||||
border-radius: 999px;
|
||||
cursor: pointer;
|
||||
font-weight: 600;
|
||||
font-family: inherit;
|
||||
transition: opacity 0.12s, background 0.12s;
|
||||
}
|
||||
.mira-app .mira-btn-primary:hover {
|
||||
opacity: 0.9;
|
||||
}
|
||||
.mira-app .mira-btn-primary:disabled,
|
||||
.mira-app .mira-btn-primary.disabled {
|
||||
background: var(--mira-bg-3);
|
||||
color: var(--mira-text-3);
|
||||
cursor: not-allowed;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.mira-app .mira-btn-ghost {
|
||||
background: transparent;
|
||||
border: 1px solid var(--mira-line);
|
||||
color: var(--mira-text-2);
|
||||
font-size: 12px;
|
||||
padding: 6px 14px;
|
||||
border-radius: 999px;
|
||||
cursor: pointer;
|
||||
font-family: inherit;
|
||||
}
|
||||
.mira-app .mira-btn-ghost:hover {
|
||||
background: var(--mira-bg-2);
|
||||
color: var(--mira-text-1);
|
||||
}
|
||||
|
||||
/* ── Mira 思考中(AI reply pending)── */
|
||||
.mira-app .mira-thinking {
|
||||
opacity: 0.7;
|
||||
}
|
||||
.mira-app .mira-thinking-dots::after {
|
||||
content: '⋯';
|
||||
display: inline-block;
|
||||
animation: mira-think-dots 1.4s infinite;
|
||||
}
|
||||
@keyframes mira-think-dots {
|
||||
0%, 100% { opacity: 0.3; }
|
||||
50% { opacity: 1; }
|
||||
}
|
||||
|
||||
/* ── skeleton loader ── */
|
||||
.mira-app .mira-skel {
|
||||
height: 60px;
|
||||
background: linear-gradient(
|
||||
90deg,
|
||||
var(--mira-bg-1) 0%,
|
||||
var(--mira-bg-2) 50%,
|
||||
var(--mira-bg-1) 100%
|
||||
);
|
||||
background-size: 200% 100%;
|
||||
animation: mira-skel-shimmer 1.4s ease-in-out infinite;
|
||||
border-radius: 6px;
|
||||
}
|
||||
@keyframes mira-skel-shimmer {
|
||||
0% { background-position: 200% 0; }
|
||||
100% { background-position: -200% 0; }
|
||||
}
|
||||
|
||||
/* ── rel time ── */
|
||||
.mira-app .mira-rel-time {
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
/* ── Wiki detail (7B.3g 樹狀渲染) ── */
|
||||
/* .mira-md 已在 §190+ 定義整套 markdown 樣式(河道+wiki 共用),這裡只加 wiki 細節頁的「不破版」保護 */
|
||||
.mira-app .mira-wiki-detail {
|
||||
overflow-wrap: break-word;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
/* 防止長 cypher binding 字串 / URL 撐爆右邊界 */
|
||||
.mira-app .mira-wiki-detail .mira-md li,
|
||||
.mira-app .mira-wiki-detail .mira-md p {
|
||||
overflow-wrap: break-word;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
/* wiki h2/h3 加底線分隔,更像文章 */
|
||||
.mira-app .mira-wiki-detail .mira-md h2 {
|
||||
border-bottom: 1px solid var(--mira-line-soft);
|
||||
padding-bottom: 4px;
|
||||
}
|
||||
|
||||
/* ── Composer popup (P0 #5c 編輯器放大) ── */
|
||||
.mira-app .mira-composer-expand {
|
||||
font-size: 18px;
|
||||
padding: 0 8px;
|
||||
cursor: pointer;
|
||||
color: var(--mira-text-3);
|
||||
}
|
||||
.mira-app .mira-composer-expand:hover {
|
||||
color: var(--mira-text-1);
|
||||
}
|
||||
|
||||
/* backdrop 蓋全頁 + 居中 */
|
||||
.mira-composer-popup-backdrop {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
background: rgba(0, 0, 0, 0.6);
|
||||
z-index: 1000;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
/* popup card 大編輯區 */
|
||||
.mira-composer-popup {
|
||||
background: var(--mira-bg-1);
|
||||
border: 1px solid var(--mira-line);
|
||||
border-radius: var(--mira-radius-lg);
|
||||
width: min(800px, 100%);
|
||||
max-height: 90vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
font-family: var(--mira-font-zh);
|
||||
color: var(--mira-text-1);
|
||||
}
|
||||
|
||||
.mira-composer-popup-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 14px 16px;
|
||||
border-bottom: 1px solid var(--mira-line);
|
||||
}
|
||||
|
||||
.mira-composer-popup-title {
|
||||
font-weight: 600;
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
.mira-composer-popup-textarea {
|
||||
flex: 1;
|
||||
min-height: 320px;
|
||||
padding: 16px;
|
||||
background: transparent;
|
||||
color: var(--mira-text-1);
|
||||
border: none;
|
||||
outline: none;
|
||||
resize: none;
|
||||
font-family: inherit;
|
||||
font-size: 15px;
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.mira-composer-popup-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 12px 16px;
|
||||
border-top: 1px solid var(--mira-line);
|
||||
background: var(--mira-bg-0);
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
'use client';
|
||||
|
||||
// Mira 首頁(Profile / KM Hub)
|
||||
// SDD: polaris/mira/.agents/specs/mira-app/design.md §5.2
|
||||
// 這頁是 leo 的 KM 首頁,列出所有同層子頁的入口
|
||||
// 河道 / Wiki 是同層子頁,不是父子關係
|
||||
|
||||
import Link from 'next/link';
|
||||
import './mira.css';
|
||||
|
||||
type Entry = {
|
||||
href: string;
|
||||
emoji: string;
|
||||
title: string;
|
||||
desc: string;
|
||||
status?: 'live' | 'wip' | 'planned';
|
||||
};
|
||||
|
||||
const ENTRIES: Entry[] = [
|
||||
{
|
||||
href: '/mira/feed',
|
||||
emoji: '🌊',
|
||||
title: '河道',
|
||||
desc: '時間軸式貼文流,所有 source 進來的內容都在這',
|
||||
status: 'live',
|
||||
},
|
||||
{
|
||||
href: '/mira/wiki',
|
||||
emoji: '📚',
|
||||
title: 'Wiki',
|
||||
desc: 'leo 的個人觀點累積(Karpathy LLM Wiki 風格)',
|
||||
status: 'live',
|
||||
},
|
||||
{
|
||||
href: '/mira/plan',
|
||||
emoji: '📋',
|
||||
title: '計劃',
|
||||
desc: 'Task 列表 + 狀態切換 + workflow 觸發',
|
||||
status: 'planned',
|
||||
},
|
||||
{
|
||||
href: '/mira/dissent',
|
||||
emoji: '⚔️',
|
||||
title: '異見牆',
|
||||
desc: 'Triplet 列表(含 ai-idea / 矛盾標記)',
|
||||
status: 'planned',
|
||||
},
|
||||
];
|
||||
|
||||
export default function MiraHubPage() {
|
||||
return (
|
||||
<main className="mira-app">
|
||||
<div className="mira-content">
|
||||
<header style={{ padding: '32px 0 24px' }}>
|
||||
<h1 style={{ fontSize: 32, fontWeight: 700, color: '#fff', margin: 0 }}>
|
||||
🦔 Mira
|
||||
</h1>
|
||||
<p style={{ color: '#888', fontSize: 15, marginTop: 6 }}>
|
||||
leo 的個人 KM 系統
|
||||
</p>
|
||||
</header>
|
||||
|
||||
<div style={{ display: 'grid', gap: 12, paddingBottom: 40 }}>
|
||||
{ENTRIES.map((e) => (
|
||||
<EntryCard key={e.href} entry={e} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
function EntryCard({ entry }: { entry: Entry }) {
|
||||
const isClickable = entry.status === 'live';
|
||||
const card = (
|
||||
<div
|
||||
style={{
|
||||
padding: '18px 20px',
|
||||
background: '#1a1a1a',
|
||||
border: '1px solid #2a2a2a',
|
||||
borderRadius: 8,
|
||||
opacity: isClickable ? 1 : 0.5,
|
||||
cursor: isClickable ? 'pointer' : 'not-allowed',
|
||||
transition: 'border-color 0.15s',
|
||||
}}
|
||||
onMouseEnter={(e) => {
|
||||
if (isClickable) e.currentTarget.style.borderColor = '#444';
|
||||
}}
|
||||
onMouseLeave={(e) => {
|
||||
if (isClickable) e.currentTarget.style.borderColor = '#2a2a2a';
|
||||
}}
|
||||
>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 12, marginBottom: 6 }}>
|
||||
<span style={{ fontSize: 24 }}>{entry.emoji}</span>
|
||||
<span style={{ fontSize: 18, fontWeight: 600, color: '#fff' }}>
|
||||
{entry.title}
|
||||
</span>
|
||||
{entry.status === 'planned' && (
|
||||
<span
|
||||
style={{
|
||||
fontSize: 11,
|
||||
padding: '2px 8px',
|
||||
background: '#2a2a3a',
|
||||
color: '#aab',
|
||||
borderRadius: 3,
|
||||
}}
|
||||
>
|
||||
未實作
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<div style={{ color: '#888', fontSize: 14, marginLeft: 36 }}>{entry.desc}</div>
|
||||
</div>
|
||||
);
|
||||
return isClickable ? (
|
||||
<Link href={entry.href} style={{ textDecoration: 'none' }}>
|
||||
{card}
|
||||
</Link>
|
||||
) : (
|
||||
card
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,467 @@
|
||||
'use client';
|
||||
|
||||
export const runtime = 'edge';
|
||||
|
||||
// Mira Wiki 單篇頁
|
||||
// SDD: polaris/mira/.agents/specs/mira-app/design.md §5.2 + §3.5.12
|
||||
// 對應 task: 7C.2 + 7B.3g
|
||||
// 路由:/mira/wiki/[pageName]
|
||||
// 顯示:wiki-page parent → wiki-paragraph children (按 facet 分區) → triplet grandchildren
|
||||
// 7B.3g 升級:樹狀渲染 + 折疊 + triplet 跨 wiki 連結化
|
||||
|
||||
import { useEffect, useMemo, useState, use } from 'react';
|
||||
import Link from 'next/link';
|
||||
import { MarkdownView } from '../../_shared/markdown';
|
||||
import '../../mira.css';
|
||||
|
||||
const KBDB_BASE = 'https://kbdb.finally.click';
|
||||
const API_BASE = process.env.NEXT_PUBLIC_API_BASE ?? 'https://cypher.arcrun.dev';
|
||||
|
||||
type Block = {
|
||||
id: string;
|
||||
page_name: string | null;
|
||||
content: string;
|
||||
type: string;
|
||||
parent_id: string | null;
|
||||
tags_json: string | null;
|
||||
source: string | null;
|
||||
created_at: number;
|
||||
updated_at: number;
|
||||
};
|
||||
|
||||
type FacetGroup = {
|
||||
facet: string;
|
||||
paragraphs: Array<{
|
||||
block: Block;
|
||||
triplets: Block[];
|
||||
}>;
|
||||
};
|
||||
|
||||
export default function WikiPagePage({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ pageName: string }>;
|
||||
}) {
|
||||
const { pageName } = use(params);
|
||||
const decodedName = decodeURIComponent(pageName);
|
||||
|
||||
const [block, setBlock] = useState<Block | null>(null);
|
||||
const [paragraphs, setParagraphs] = useState<Block[]>([]);
|
||||
const [triplets, setTriplets] = useState<Block[]>([]);
|
||||
const [entitySet, setEntitySet] = useState<Set<string>>(new Set());
|
||||
// Backlinks:所有提到此 entity 的 raw note(V3 wiki_synthesis 在 wiki-page tags 寫 raw:XXX)
|
||||
// 對應 leo 2026-05-17 #2 反饋:「從這本書的條目應該反向連到那篇筆記去」
|
||||
const [backlinkRaws, setBacklinkRaws] = useState<Block[]>([]);
|
||||
const [collapsed, setCollapsed] = useState<Record<string, boolean>>({});
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
async function load() {
|
||||
try {
|
||||
const meRes = await fetch(`${API_BASE}/me`, { credentials: 'include' });
|
||||
if (!meRes.ok) throw new Error('未登入');
|
||||
const me = (await meRes.json()) as { api_key: string };
|
||||
const headers = { Authorization: `Bearer ${me.api_key}` };
|
||||
|
||||
// 1. 抓 wiki-page parent block by page_name
|
||||
const pageRes = await fetch(
|
||||
`${KBDB_BASE}/blocks?page_name=${encodeURIComponent(decodedName)}&limit=1`,
|
||||
{ headers },
|
||||
);
|
||||
if (!pageRes.ok) throw new Error(`KBDB ${pageRes.status}`);
|
||||
const pageData = await pageRes.json();
|
||||
const wikiPage: Block | undefined = pageData.blocks?.[0];
|
||||
if (cancelled) return;
|
||||
if (!wikiPage) {
|
||||
setError(`找不到 wiki page:${decodedName}`);
|
||||
return;
|
||||
}
|
||||
setBlock(wikiPage);
|
||||
|
||||
// 2. 平行撈所有 wiki-paragraph + triplet + wiki-page(跨 wiki 連結用),客戶端 filter by parent_id
|
||||
// KBDB 沒 parent_id server filter(兼 tag filter 還有 KI-3 bug),用 source+type 取再 client-side filter
|
||||
const [paraRes, tripRes, pageListRes] = await Promise.all([
|
||||
fetch(`${KBDB_BASE}/blocks?source=ai-canon-wiki&type=wiki-paragraph&limit=500`, { headers }),
|
||||
fetch(`${KBDB_BASE}/blocks?source=ai-canon-wiki&type=triplet&limit=1000`, { headers }),
|
||||
fetch(`${KBDB_BASE}/blocks?source=ai-canon-wiki&type=wiki-page&limit=500`, { headers }),
|
||||
]);
|
||||
if (!paraRes.ok || !tripRes.ok || !pageListRes.ok) {
|
||||
throw new Error('KBDB tree fetch failed');
|
||||
}
|
||||
const paraData = await paraRes.json();
|
||||
const tripData = await tripRes.json();
|
||||
const pageListData = await pageListRes.json();
|
||||
if (cancelled) return;
|
||||
|
||||
const allParas: Block[] = paraData.blocks ?? [];
|
||||
const allTrips: Block[] = tripData.blocks ?? [];
|
||||
const allPages: Block[] = pageListData.blocks ?? [];
|
||||
|
||||
// 該 wiki-page 的 paragraphs
|
||||
const myParas = allParas
|
||||
.filter((p) => p.parent_id === wikiPage.id)
|
||||
.sort((a, b) => a.created_at - b.created_at);
|
||||
setParagraphs(myParas);
|
||||
|
||||
// 該 wiki-page 範圍內所有 paragraph 的 triplets
|
||||
const paraIdSet = new Set(myParas.map((p) => p.id));
|
||||
const myTrips = allTrips.filter((t) => t.parent_id && paraIdSet.has(t.parent_id));
|
||||
setTriplets(myTrips);
|
||||
|
||||
// 跨 wiki 連結用:所有 wiki-page 的 entity 名稱(content 就是 entity)
|
||||
// 額外把 page_name 也加入(page_name=wiki-{entity})
|
||||
const eset = new Set<string>();
|
||||
for (const p of allPages) {
|
||||
if (p.content) eset.add(p.content.trim());
|
||||
if (p.page_name?.startsWith('wiki-')) {
|
||||
eset.add(p.page_name.slice(5).trim());
|
||||
}
|
||||
}
|
||||
setEntitySet(eset);
|
||||
|
||||
// Backlinks:找此 entity 的所有 wiki-page (可能多次寫入),提取 raw:XXX tag → fetch raw blocks
|
||||
if (wikiPage.type === 'wiki-page' && wikiPage.content) {
|
||||
const sameEntity = allPages.filter((p) => p.content?.trim() === wikiPage.content?.trim());
|
||||
const rawIds = new Set<string>();
|
||||
for (const wp of sameEntity) {
|
||||
try {
|
||||
const tags = JSON.parse(wp.tags_json || '[]') as string[];
|
||||
for (const t of tags) {
|
||||
if (typeof t === 'string' && t.startsWith('raw:')) {
|
||||
rawIds.add(t.slice(4));
|
||||
}
|
||||
}
|
||||
} catch { /* skip */ }
|
||||
}
|
||||
if (rawIds.size > 0) {
|
||||
// 一次撈 raw blocks,page_name 是 unique 一次 query 一個
|
||||
const rawBlocks: Block[] = [];
|
||||
await Promise.all(
|
||||
Array.from(rawIds).map(async (rawId) => {
|
||||
try {
|
||||
// KBDB GET /blocks/:id 直接 by id (走 list with block_id filter)
|
||||
const r = await fetch(`${KBDB_BASE}/blocks/${rawId}`, { headers });
|
||||
if (r.ok) {
|
||||
const data = await r.json();
|
||||
const b = data.blocks?.[0] ?? data;
|
||||
if (b?.id) rawBlocks.push(b as Block);
|
||||
}
|
||||
} catch { /* skip */ }
|
||||
}),
|
||||
);
|
||||
if (!cancelled) {
|
||||
setBacklinkRaws(rawBlocks.sort((a, b) => b.updated_at - a.updated_at));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e: any) {
|
||||
if (!cancelled) setError(e?.message ?? 'load failed');
|
||||
} finally {
|
||||
if (!cancelled) setLoading(false);
|
||||
}
|
||||
}
|
||||
load();
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [decodedName]);
|
||||
|
||||
// 按 facet 分區
|
||||
const facetGroups = useMemo<FacetGroup[]>(() => {
|
||||
const groups: Map<string, Array<{ block: Block; triplets: Block[] }>> = new Map();
|
||||
for (const p of paragraphs) {
|
||||
const facet = extractFacet(p.tags_json) ?? '未分類';
|
||||
const myTrips = triplets.filter((t) => t.parent_id === p.id);
|
||||
if (!groups.has(facet)) groups.set(facet, []);
|
||||
groups.get(facet)!.push({ block: p, triplets: myTrips });
|
||||
}
|
||||
return Array.from(groups.entries()).map(([facet, paragraphs]) => ({ facet, paragraphs }));
|
||||
}, [paragraphs, triplets]);
|
||||
|
||||
const isWikiPage = block?.type === 'wiki-page';
|
||||
// 標題:wiki-page 用 content(entity 名稱),其他(index-entry/schema/log/...)用 page_name 剝 prefix
|
||||
// 修 bug:原本一律用 block.content,但 index-entry 的 content 是整篇 markdown,會把整個 content render 成 h1
|
||||
const entity = isWikiPage
|
||||
? (block?.content?.trim() || decodedName.replace(/^wiki-/, ''))
|
||||
: decodedName.replace(/^(wiki|index)-/, '');
|
||||
|
||||
function toggleCollapse(key: string) {
|
||||
setCollapsed((c) => ({ ...c, [key]: !c[key] }));
|
||||
}
|
||||
|
||||
return (
|
||||
<main className="mira-app">
|
||||
<div className="mira-content mira-wiki-detail">
|
||||
<header style={{ padding: '24px 0 16px', borderBottom: '1px solid #2a2a2a' }}>
|
||||
<Link
|
||||
href="/mira/wiki"
|
||||
style={{ color: '#888', fontSize: 14, textDecoration: 'none' }}
|
||||
>
|
||||
← Wiki 索引
|
||||
</Link>
|
||||
<h1 style={{ fontSize: 28, fontWeight: 700, color: '#fff', margin: '8px 0 4px' }}>
|
||||
{entity}
|
||||
</h1>
|
||||
{block && (
|
||||
<div style={{ color: '#666', fontSize: 12 }}>
|
||||
{block.type} ・ updated {new Date(block.updated_at * 1000).toLocaleString('zh-TW')}
|
||||
</div>
|
||||
)}
|
||||
</header>
|
||||
|
||||
{loading && <div style={{ padding: 24, color: '#666' }}>載入中⋯</div>}
|
||||
{error && <div style={{ padding: 24, color: '#e66' }}>{error}</div>}
|
||||
|
||||
{block && !loading && !error && (
|
||||
<>
|
||||
{/* wiki-page tree view */}
|
||||
{isWikiPage && facetGroups.length > 0 && (
|
||||
<article style={{ padding: '8px 0 24px' }}>
|
||||
{facetGroups.map((group) => (
|
||||
<FacetSection
|
||||
key={group.facet}
|
||||
group={group}
|
||||
entitySet={entitySet}
|
||||
collapsed={collapsed}
|
||||
toggleCollapse={toggleCollapse}
|
||||
/>
|
||||
))}
|
||||
</article>
|
||||
)}
|
||||
|
||||
{/* wiki-page 但沒 children:fallback render content */}
|
||||
{isWikiPage && facetGroups.length === 0 && (
|
||||
<article style={{ padding: '8px 0 24px', color: '#888' }}>
|
||||
<em>尚無段落(wiki_synthesis 還沒跑出 children)</em>
|
||||
<MarkdownView text={block.content} />
|
||||
</article>
|
||||
)}
|
||||
|
||||
{/* 非 wiki-page(schema / index / log / index-entry 等):直接 render content */}
|
||||
{!isWikiPage && (
|
||||
<article style={{ padding: '20px 0' }}>
|
||||
<MarkdownView text={block.content} />
|
||||
</article>
|
||||
)}
|
||||
|
||||
{/* Backlinks:提到此 entity 的 raw notes */}
|
||||
{isWikiPage && backlinkRaws.length > 0 && (
|
||||
<section
|
||||
style={{
|
||||
margin: '24px 0 16px',
|
||||
padding: '12px 14px',
|
||||
borderLeft: '3px solid #4a3a2a',
|
||||
background: 'rgba(80, 60, 40, 0.08)',
|
||||
}}
|
||||
>
|
||||
<h3 style={{ margin: '0 0 8px', fontSize: 14, color: '#aab', fontWeight: 600 }}>
|
||||
📎 提到此 entity 的筆記 ({backlinkRaws.length})
|
||||
</h3>
|
||||
<ul style={{ margin: 0, paddingLeft: 18, fontSize: 13, lineHeight: 1.6 }}>
|
||||
{backlinkRaws.map((raw) => {
|
||||
const preview = (raw.content || '').replace(/\n/g, ' ').slice(0, 100);
|
||||
const href = `/mira/feed#page=${encodeURIComponent(raw.page_name || raw.id)}`;
|
||||
return (
|
||||
<li key={raw.id} style={{ marginBottom: 4 }}>
|
||||
<a
|
||||
href={href}
|
||||
style={{ color: '#9ab', textDecoration: 'none' }}
|
||||
title={raw.content || ''}
|
||||
>
|
||||
{preview}
|
||||
{(raw.content || '').length > 100 && '…'}
|
||||
</a>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
</section>
|
||||
)}
|
||||
|
||||
<footer
|
||||
style={{
|
||||
padding: '20px 0',
|
||||
borderTop: '1px solid #1f1f1f',
|
||||
color: '#555',
|
||||
fontSize: 12,
|
||||
}}
|
||||
>
|
||||
<div>id: <span style={{ fontFamily: 'monospace' }}>{block.id}</span></div>
|
||||
<div>type: {block.type}</div>
|
||||
{block.source && <div>source: {block.source}</div>}
|
||||
{block.parent_id && (
|
||||
<div>
|
||||
parent: <span style={{ fontFamily: 'monospace' }}>{block.parent_id}</span>
|
||||
</div>
|
||||
)}
|
||||
{paragraphs.length > 0 && (
|
||||
<div>
|
||||
{paragraphs.length} paragraph(s) ・ {triplets.length} triplet(s)
|
||||
</div>
|
||||
)}
|
||||
</footer>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
function FacetSection({
|
||||
group,
|
||||
entitySet,
|
||||
collapsed,
|
||||
toggleCollapse,
|
||||
}: {
|
||||
group: FacetGroup;
|
||||
entitySet: Set<string>;
|
||||
collapsed: Record<string, boolean>;
|
||||
toggleCollapse: (key: string) => void;
|
||||
}) {
|
||||
const key = `facet:${group.facet}`;
|
||||
const isCollapsed = collapsed[key] ?? false; // 預設展開(leo 看一篇 wiki 時要看內容)
|
||||
|
||||
return (
|
||||
<section style={{ margin: '16px 0', borderLeft: '3px solid #2a3a4a', paddingLeft: 14 }}>
|
||||
<button
|
||||
onClick={() => toggleCollapse(key)}
|
||||
style={{
|
||||
background: 'transparent',
|
||||
border: 'none',
|
||||
color: '#aab',
|
||||
fontSize: 16,
|
||||
fontWeight: 600,
|
||||
padding: '4px 0',
|
||||
cursor: 'pointer',
|
||||
textAlign: 'left',
|
||||
width: '100%',
|
||||
}}
|
||||
>
|
||||
{isCollapsed ? '▸' : '▾'} {group.facet}
|
||||
<span style={{ color: '#555', fontWeight: 400, fontSize: 13, marginLeft: 8 }}>
|
||||
({group.paragraphs.length})
|
||||
</span>
|
||||
</button>
|
||||
{!isCollapsed &&
|
||||
group.paragraphs.map((p) => (
|
||||
<ParagraphBlock
|
||||
key={p.block.id}
|
||||
block={p.block}
|
||||
triplets={p.triplets}
|
||||
entitySet={entitySet}
|
||||
collapsed={collapsed}
|
||||
toggleCollapse={toggleCollapse}
|
||||
/>
|
||||
))}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
function ParagraphBlock({
|
||||
block,
|
||||
triplets,
|
||||
entitySet,
|
||||
collapsed,
|
||||
toggleCollapse,
|
||||
}: {
|
||||
block: Block;
|
||||
triplets: Block[];
|
||||
entitySet: Set<string>;
|
||||
collapsed: Record<string, boolean>;
|
||||
toggleCollapse: (key: string) => void;
|
||||
}) {
|
||||
const tripKey = `trip:${block.id}`;
|
||||
const tripsCollapsed = collapsed[tripKey] ?? true; // triplets 預設折疊
|
||||
|
||||
return (
|
||||
<div style={{ margin: '12px 0 16px', paddingLeft: 4 }}>
|
||||
<div style={{ color: '#ddd', lineHeight: 1.7 }}>
|
||||
<MarkdownView text={block.content} />
|
||||
</div>
|
||||
{triplets.length > 0 && (
|
||||
<div style={{ marginTop: 8 }}>
|
||||
<button
|
||||
onClick={() => toggleCollapse(tripKey)}
|
||||
style={{
|
||||
background: 'transparent',
|
||||
border: 'none',
|
||||
color: '#666',
|
||||
fontSize: 12,
|
||||
padding: '2px 0',
|
||||
cursor: 'pointer',
|
||||
}}
|
||||
>
|
||||
{tripsCollapsed ? '▸' : '▾'} 關係 ({triplets.length})
|
||||
</button>
|
||||
{!tripsCollapsed && (
|
||||
<ul style={{ listStyle: 'none', padding: '4px 0 0 12px', margin: 0 }}>
|
||||
{triplets.map((t) => (
|
||||
<li
|
||||
key={t.id}
|
||||
style={{
|
||||
color: '#888',
|
||||
fontSize: 13,
|
||||
padding: '2px 0',
|
||||
fontFamily: 'monospace',
|
||||
}}
|
||||
>
|
||||
<TripletRender content={t.content} entitySet={entitySet} />
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** Render triplet "A >> 關係 >> B" with A/B linkified if they match an existing wiki entity */
|
||||
function TripletRender({
|
||||
content,
|
||||
entitySet,
|
||||
}: {
|
||||
content: string;
|
||||
entitySet: Set<string>;
|
||||
}) {
|
||||
// 切「>>」分 A / 關係 / B
|
||||
const parts = content.split('>>').map((s) => s.trim());
|
||||
if (parts.length !== 3) {
|
||||
return <>{content}</>;
|
||||
}
|
||||
const [a, rel, b] = parts;
|
||||
return (
|
||||
<>
|
||||
<EntityLink name={a} entitySet={entitySet} />{' '}
|
||||
<span style={{ color: '#666' }}>>> {rel} >></span>{' '}
|
||||
<EntityLink name={b} entitySet={entitySet} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function EntityLink({ name, entitySet }: { name: string; entitySet: Set<string> }) {
|
||||
if (entitySet.has(name)) {
|
||||
return (
|
||||
<Link
|
||||
href={`/mira/wiki/${encodeURIComponent(`wiki-${name}`)}`}
|
||||
style={{ color: '#88c0ff', textDecoration: 'none' }}
|
||||
>
|
||||
{name}
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
return <span style={{ color: '#ccc' }}>{name}</span>;
|
||||
}
|
||||
|
||||
function extractFacet(tags_json: string | null | undefined): string | null {
|
||||
if (!tags_json) return null;
|
||||
try {
|
||||
const tags = JSON.parse(tags_json) as string[];
|
||||
const facetTag = tags.find((t) => t.startsWith('facet:'));
|
||||
return facetTag ? facetTag.slice(6) : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,346 @@
|
||||
'use client';
|
||||
|
||||
// Mira Wiki 索引頁
|
||||
// SDD: polaris/mira/.agents/specs/mira-app/design.md §5.2 + §3.5.10
|
||||
// 對應 task: 7C.1
|
||||
// 階段 7-A 已建:mira-wiki-schema、mira-wiki-index(+4 children)、mira-wiki-log(+1 child)
|
||||
// 此頁列出這些 infra block 與既有 wiki-page,方便 leo 在瀏覽器確認 schema 寫得對不對
|
||||
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import Link from 'next/link';
|
||||
import '../mira.css';
|
||||
|
||||
const KBDB_BASE = 'https://kbdb.finally.click';
|
||||
const API_BASE = process.env.NEXT_PUBLIC_API_BASE ?? 'https://cypher.arcrun.dev';
|
||||
|
||||
type Block = {
|
||||
id: string;
|
||||
page_name: string;
|
||||
content: string;
|
||||
type: string;
|
||||
parent_id: string | null;
|
||||
tags_json: string | null;
|
||||
created_at: number;
|
||||
};
|
||||
|
||||
export default function WikiIndexPage() {
|
||||
const [schema, setSchema] = useState<Block | null>(null);
|
||||
const [indexChildren, setIndexChildren] = useState<Block[]>([]);
|
||||
const [logEntries, setLogEntries] = useState<Block[]>([]);
|
||||
const [otherWikiPages, setOtherWikiPages] = useState<Block[]>([]);
|
||||
const [indexEntries, setIndexEntries] = useState<Block[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
async function load() {
|
||||
try {
|
||||
// 先拿 ak_ partner key(同 page.tsx pattern)
|
||||
const meRes = await fetch(`${API_BASE}/me`, { credentials: 'include' });
|
||||
if (!meRes.ok) throw new Error('未登入');
|
||||
const me = (await meRes.json()) as { api_key: string };
|
||||
const headers = { Authorization: `Bearer ${me.api_key}` };
|
||||
|
||||
// 撈所有 type=wiki-page,再 client 端過濾 tags 含 'mira-wiki'
|
||||
// 原本 ?tag=mira-wiki 撞 KBDB worker D1 bug(malformed JSON),改 type filter
|
||||
// 待 KBDB 修 tag filter 後可改回(SDD 待開 kbdb-tag-filter-fix)
|
||||
const res = await fetch(
|
||||
`${KBDB_BASE}/blocks?type=wiki-page&limit=200`,
|
||||
{ headers },
|
||||
);
|
||||
if (!res.ok) throw new Error(`KBDB ${res.status}`);
|
||||
const data = await res.json();
|
||||
if (cancelled) return;
|
||||
const allWikiBlocks: Block[] = data.blocks ?? [];
|
||||
// Client 端過濾:只留 tags 含 'mira-wiki'
|
||||
const blocks: Block[] = allWikiBlocks.filter((b) => {
|
||||
if (!b.tags_json) return false;
|
||||
try {
|
||||
const tags = JSON.parse(b.tags_json) as string[];
|
||||
return tags.includes('mira-wiki');
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
const tagsOf = (b: Block): string[] => {
|
||||
if (!b.tags_json) return [];
|
||||
try {
|
||||
return JSON.parse(b.tags_json) as string[];
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
const hasSubtype = (b: Block, st: string) =>
|
||||
tagsOf(b).includes(`subtype:${st}`);
|
||||
const hasAnyInfraSubtype = (b: Block) =>
|
||||
['schema', 'index', 'index-child', 'log', 'log-child'].some((st) => hasSubtype(b, st));
|
||||
const hasMetaTag = (b: Block) =>
|
||||
tagsOf(b).some((t) => t === 'data-source-config' || t === 'source-skill');
|
||||
|
||||
setSchema(blocks.find((b) => hasSubtype(b, 'schema')) ?? null);
|
||||
setIndexChildren(
|
||||
blocks
|
||||
.filter((b) => hasSubtype(b, 'index-child'))
|
||||
.sort((a, b) => a.page_name.localeCompare(b.page_name)),
|
||||
);
|
||||
setLogEntries(
|
||||
blocks
|
||||
.filter((b) => hasSubtype(b, 'log-child'))
|
||||
.sort((a, b) => b.page_name.localeCompare(a.page_name)),
|
||||
);
|
||||
// 真正的 wiki-page paragraphs(排除 infra 跟 meta 配置)
|
||||
setOtherWikiPages(
|
||||
blocks
|
||||
.filter((b) => !hasAnyInfraSubtype(b) && !hasMetaTag(b))
|
||||
.sort((a, b) => (b.created_at ?? 0) - (a.created_at ?? 0)),
|
||||
);
|
||||
|
||||
// 平行撈 index-entry blocks(per-entity 摘要,CC navigation entry point)
|
||||
// 對應 design.md §3.5.12.4.1 / 7B.3f
|
||||
const idxRes = await fetch(
|
||||
`${KBDB_BASE}/blocks?type=index-entry&limit=200`,
|
||||
{ headers },
|
||||
);
|
||||
if (idxRes.ok) {
|
||||
const idxData = await idxRes.json();
|
||||
if (!cancelled) {
|
||||
const idxBlocks: Block[] = idxData.blocks ?? [];
|
||||
setIndexEntries(
|
||||
idxBlocks.sort((a, b) => (a.page_name ?? '').localeCompare(b.page_name ?? '')),
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (e: any) {
|
||||
if (!cancelled) setError(e?.message ?? 'load failed');
|
||||
} finally {
|
||||
if (!cancelled) setLoading(false);
|
||||
}
|
||||
}
|
||||
load();
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, []);
|
||||
|
||||
// Dedupe wiki-pages by entity(content)— 累積式設計每個 raw 各建一個 wiki-page,
|
||||
// 同 entity 多版只在 listing 顯示最新一張卡 + 版本數提示
|
||||
const dedupedWikiPages = useMemo(() => {
|
||||
const groups = new Map<string, { entity: string; latest: Block; versionCount: number }>();
|
||||
for (const p of otherWikiPages) {
|
||||
const entity = (p.content || '').trim() || p.page_name || '?';
|
||||
const existing = groups.get(entity);
|
||||
if (!existing) {
|
||||
groups.set(entity, { entity, latest: p, versionCount: 1 });
|
||||
} else {
|
||||
existing.versionCount++;
|
||||
if ((p.created_at ?? 0) > (existing.latest.created_at ?? 0)) {
|
||||
existing.latest = p;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Array.from(groups.values()).sort(
|
||||
(a, b) => (b.latest.created_at ?? 0) - (a.latest.created_at ?? 0),
|
||||
);
|
||||
}, [otherWikiPages]);
|
||||
|
||||
return (
|
||||
<main className="mira-app">
|
||||
<div className="mira-content">
|
||||
<header style={{ padding: '24px 0 16px', borderBottom: '1px solid #2a2a2a' }}>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 12, marginBottom: 4 }}>
|
||||
<Link
|
||||
href="/mira"
|
||||
style={{ color: '#888', fontSize: 14, textDecoration: 'none' }}
|
||||
>
|
||||
← Mira 首頁
|
||||
</Link>
|
||||
</div>
|
||||
<h1 style={{ fontSize: 28, fontWeight: 700, color: '#fff', margin: 0 }}>
|
||||
📚 Mira Wiki
|
||||
</h1>
|
||||
<p style={{ color: '#888', fontSize: 14, marginTop: 4 }}>
|
||||
leo 的個人觀點累積(Karpathy LLM Wiki 風格)
|
||||
</p>
|
||||
</header>
|
||||
|
||||
{loading && <div style={{ padding: 24, color: '#666' }}>載入中⋯</div>}
|
||||
{error && (
|
||||
<div style={{ padding: 24, color: '#e66' }}>讀取失敗:{error}</div>
|
||||
)}
|
||||
|
||||
{!loading && !error && (
|
||||
<>
|
||||
<Section title="📋 Schema(合成規則)">
|
||||
{schema ? (
|
||||
<WikiCardLink page_name={schema.page_name} title="mira-wiki-schema" excerpt="ingest 規則手冊:cypher binding、17 predicates、entity normalize⋯" />
|
||||
) : (
|
||||
<Empty>尚未建立 schema</Empty>
|
||||
)}
|
||||
</Section>
|
||||
|
||||
<Section title="🗂 Index(4 個分類)">
|
||||
{indexChildren.length > 0 ? (
|
||||
<div style={{ display: 'grid', gap: 8 }}>
|
||||
{indexChildren.map((b) => {
|
||||
const tags = b.tags_json ? (JSON.parse(b.tags_json) as string[]) : [];
|
||||
const key = tags.find((t) => t.startsWith('index-key:'))?.replace('index-key:', '') ?? '?';
|
||||
return (
|
||||
<WikiCardLink
|
||||
key={b.id}
|
||||
page_name={b.page_name}
|
||||
title={`${iconForKey(key)} ${key}`}
|
||||
excerpt={firstLineOf(b.content)}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
) : (
|
||||
<Empty>index children 尚未建立</Empty>
|
||||
)}
|
||||
</Section>
|
||||
|
||||
<Section title={`🧭 Index Entries(${indexEntries.length})— CC 看的 entity 摘要`}>
|
||||
{indexEntries.length > 0 ? (
|
||||
<div style={{ display: 'grid', gap: 8 }}>
|
||||
{indexEntries.map((b) => {
|
||||
const entity = (b.page_name ?? '').replace(/^index-/, '');
|
||||
const firstLine = firstLineOf(b.content)
|
||||
.replace(/^#+\s*/, '')
|
||||
.slice(0, 80);
|
||||
return (
|
||||
<WikiCardLink
|
||||
key={b.id}
|
||||
page_name={b.page_name ?? ''}
|
||||
title={entity}
|
||||
excerpt={firstLine || `index for ${entity}`}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
) : (
|
||||
<Empty>尚未有 index-entry(wiki_synthesis 跑完後自動建)</Empty>
|
||||
)}
|
||||
</Section>
|
||||
|
||||
<Section title="📜 Log(每月一筆)">
|
||||
{logEntries.length > 0 ? (
|
||||
<div style={{ display: 'grid', gap: 8 }}>
|
||||
{logEntries.map((b) => (
|
||||
<WikiCardLink
|
||||
key={b.id}
|
||||
page_name={b.page_name}
|
||||
title={b.page_name}
|
||||
excerpt={firstLineOf(b.content)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<Empty>尚未有 log</Empty>
|
||||
)}
|
||||
</Section>
|
||||
|
||||
<Section title={`📖 Wiki Pages(${dedupedWikiPages.length},原 ${otherWikiPages.length} 筆累積版本)`}>
|
||||
{dedupedWikiPages.length > 0 ? (
|
||||
<div style={{ display: 'grid', gap: 8 }}>
|
||||
{dedupedWikiPages.map((g) => (
|
||||
<WikiCardLink
|
||||
key={g.latest.id}
|
||||
page_name={g.latest.page_name}
|
||||
title={g.entity}
|
||||
excerpt={
|
||||
g.versionCount > 1
|
||||
? `${g.versionCount} 版累積 ・ 最新 ${new Date((g.latest.created_at ?? 0) * 1000).toLocaleString('zh-TW')}`
|
||||
: `建立 ${new Date((g.latest.created_at ?? 0) * 1000).toLocaleString('zh-TW')}`
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<Empty>尚未有 wiki page(待 7-B ai-canon-wiki workflow 跑出第一張)</Empty>
|
||||
)}
|
||||
</Section>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
function Section({ title, children }: { title: string; children: React.ReactNode }) {
|
||||
return (
|
||||
<section style={{ padding: '20px 0', borderBottom: '1px solid #1f1f1f' }}>
|
||||
<h2 style={{ fontSize: 16, fontWeight: 600, color: '#ddd', marginBottom: 12 }}>
|
||||
{title}
|
||||
</h2>
|
||||
{children}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
function Empty({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
<div style={{ color: '#555', fontStyle: 'italic', fontSize: 13 }}>{children}</div>
|
||||
);
|
||||
}
|
||||
|
||||
function WikiCardLink({
|
||||
page_name,
|
||||
title,
|
||||
excerpt,
|
||||
}: {
|
||||
page_name: string;
|
||||
title: string;
|
||||
excerpt: string;
|
||||
}) {
|
||||
return (
|
||||
<Link
|
||||
href={`/mira/wiki/${encodeURIComponent(page_name)}`}
|
||||
style={{
|
||||
display: 'block',
|
||||
padding: '12px 14px',
|
||||
background: '#1a1a1a',
|
||||
border: '1px solid #2a2a2a',
|
||||
borderRadius: 6,
|
||||
textDecoration: 'none',
|
||||
color: 'inherit',
|
||||
}}
|
||||
>
|
||||
<div style={{ color: '#ddd', fontWeight: 500, marginBottom: 4 }}>{title}</div>
|
||||
{excerpt && (
|
||||
<div
|
||||
style={{
|
||||
color: '#888',
|
||||
fontSize: 13,
|
||||
overflow: 'hidden',
|
||||
textOverflow: 'ellipsis',
|
||||
whiteSpace: 'nowrap',
|
||||
}}
|
||||
>
|
||||
{excerpt}
|
||||
</div>
|
||||
)}
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
|
||||
function iconForKey(key: string): string {
|
||||
return (
|
||||
{
|
||||
entities: '🧩',
|
||||
topics: '📂',
|
||||
sources: '🔗',
|
||||
stale: '⚠️',
|
||||
}[key] ?? '•'
|
||||
);
|
||||
}
|
||||
|
||||
function firstLineOf(content: string): string {
|
||||
if (!content) return '';
|
||||
const firstNonHeader = content
|
||||
.split('\n')
|
||||
.map((l) => l.trim())
|
||||
.find((l) => l && !l.startsWith('#') && !l.startsWith('>'));
|
||||
return firstNonHeader ?? '';
|
||||
}
|
||||
Reference in New Issue
Block a user