feat(product-source): 光湖知识库模块 v0.1.0 — Git 驱动的完整知识库系统

铸渊 2026-08-08 开发,冰朔架构决策:
- Git 是底层引擎,不依赖任何数据库(PostgreSQL/Redis/ORM)
- Agent 直达底层,中间不隔第三方服务
- 拆解 Outline v0.80.2 为参考样本,光湖自己实现全部能力

技术栈:
- 后端:Express v5 + simple-git + gray-matter(Git 操作层)
- 前端:Vite + React 19 + TypeScript + marked
- 存储:Markdown 文件 + Git 仓库(commit=版本历史,diff=对比)

功能清单(全部可用):
- 文档 CRUD(创建/读取/更新/删除/移动)
- 文档树导航(文件夹层级)
- Markdown 编辑器(编辑/预览双栏)
- 全文搜索(防抖 + 下拉结果)
- 版本历史(git log)
- 版本 diff 对比(选择两个 commit 对比)

API 端点(Agent 和 UI 共用):
- GET/POST/PUT/DELETE /api/docs/{*path}
- GET /api/tree
- GET /api/history/{*path}
- GET /api/version/:hash/{*path}
- GET /api/diff/{*path}?from=&to=
- GET /api/search?q=
- POST /api/move
- GET /api/health
This commit is contained in:
冰朔 2026-08-08 07:09:54 +08:00
commit ecfeca40e2
16 changed files with 5970 additions and 0 deletions

View file

@ -0,0 +1,87 @@
import { useState } from 'react';
import { DocTreeNode } from '../api';
interface Props {
nodes: DocTreeNode[];
currentPath: string;
onSelect: (path: string) => void;
onCreate: (parentPath: string) => void;
depth?: number;
}
export function DocTree({ nodes, currentPath, onSelect, onCreate, depth = 0 }: Props) {
return (
<div className="kb-tree" style={{ paddingLeft: depth > 0 ? 16 : 0 }}>
{nodes.map(node => (
<TreeNode
key={node.path}
node={node}
currentPath={currentPath}
onSelect={onSelect}
onCreate={onCreate}
depth={depth}
/>
))}
</div>
);
}
function TreeNode({
node,
currentPath,
onSelect,
onCreate,
depth,
}: {
node: DocTreeNode;
currentPath: string;
onSelect: (path: string) => void;
onCreate: (parentPath: string) => void;
depth: number;
}) {
const [expanded, setExpanded] = useState(depth < 2);
const isActive = node.path === currentPath;
if (node.type === 'folder') {
return (
<div className="kb-tree-folder">
<div
className={`kb-tree-item kb-tree-folder-header ${expanded ? 'expanded' : ''}`}
onClick={() => setExpanded(!expanded)}
>
<span className="kb-tree-icon">{expanded ? '📂' : '📁'}</span>
<span className="kb-tree-name">{node.name}</span>
<button
className="kb-tree-add"
onClick={e => {
e.stopPropagation();
onCreate(node.path);
}}
title="在此文件夹下新建文档"
>
+
</button>
</div>
{expanded && node.children && (
<DocTree
nodes={node.children}
currentPath={currentPath}
onSelect={onSelect}
onCreate={onCreate}
depth={depth + 1}
/>
)}
</div>
);
}
return (
<div
className={`kb-tree-item kb-tree-doc ${isActive ? 'active' : ''}`}
onClick={() => onSelect(node.path)}
>
<span className="kb-tree-icon">📄</span>
<span className="kb-tree-name">{node.name}</span>
</div>
);
}