chore: 初始化仓库,导入项目基线代码

Academy v0.8.3 完整代码基线:Go 后端(internal/cmd/cli/mcp-server/docreader)、
Vue 前端(frontend)、数据库迁移(migrations)、部署编排(docker/helm/deploy)与文档。
今日开发的培训推送管理改动随后单独提交。
This commit is contained in:
runny committed 2026-11-16 18:12:23 +08:00
commit 7ec21f35b0
5767 files changed
+1436788

No files matched your search

+92
View File
@@ -0,0 +1,92 @@
# Skills 示例
本目录包含 Agent Skills 功能的示例。
## 目录结构
```
skills/
├── README.md # 本文件
└── pdf-processing/ # PDF 处理技能示例
├── SKILL.md # 主文件(Level 2)
├── FORMS.md # 补充文档(Level 3)
└── scripts/ # 可执行脚本
├── analyze_form.py
└── extract_text.py
```
## 快速开始
### 运行 Demo
```bash
go run ./cmd/skills-demo/main.go
```
### 创建新 Skill
1. 在本目录创建新文件夹:
```bash
mkdir my-new-skill
```
2. 创建 `SKILL.md`:
```markdown
---
name: my-new-skill
description: Description of what this skill does and when to use it.
---
# My New Skill
Instructions for the agent...
```
3. 添加脚本(可选):
```bash
mkdir my-new-skill/scripts
# 添加你的脚本
```
## 详细文档
完整文档请参阅:[Agent Skills 文档](../../website-docs/03-features/22-skills-sandbox.md)
## 示例:pdf-processing
这是一个功能完整的示例技能,展示了:
- **SKILL.md**: 包含 YAML frontmatter 的主文件
- **FORMS.md**: 补充参考文档
- **scripts/**: 可在沙箱中执行的 Python 脚本
### 技能描述
```yaml
name: pdf-processing
description: Extract text and tables from PDF files, fill forms, merge documents.
```
### 包含的脚本
| 脚本 | 功能 |
|------|------|
| `analyze_form.py` | 分析 PDF 表单字段 |
| `extract_text.py` | 从 PDF 提取文本 |
### 使用示例
Agent 会根据用户请求自动调用:
```
用户: "分析一下这个 PDF 表单有哪些字段"
Agent:
1. 识别匹配 pdf-processing 技能
2. 调用 read_file(path="skill://pdf-processing/SKILL.md") 加载技能内容
3. 调用 shell_exec(skill_name="pdf-processing", command=...) 执行 analyze_form.py
4. 返回表单字段分析结果
```
+44
View File
@@ -0,0 +1,44 @@
# PDF Form Filling Guide
This guide covers how to fill PDF forms programmatically.
## Prerequisites
Install required packages:
```bash
pip install pypdf pdfrw
```
## Basic Form Filling
```python
from pypdf import PdfReader, PdfWriter
def fill_form(input_path, output_path, field_data):
reader = PdfReader(input_path)
writer = PdfWriter()
# Clone the original PDF
writer.clone_document_from_reader(reader)
# Fill form fields
for page in writer.pages:
writer.update_page_form_field_values(page, field_data)
# Save the filled PDF
with open(output_path, "wb") as f:
writer.write(f)
```
## Supported Field Types
- Text fields
- Checkboxes
- Radio buttons
- Dropdown lists
## Tips
1. Use `scripts/analyze_form.py` to discover available fields
2. Field names are case-sensitive
3. Always verify output after filling
+40
View File
@@ -0,0 +1,40 @@
---
name: pdf-processing
description: Extract text and tables from PDF files, fill forms, merge documents. Use when working with PDF files or when the user mentions PDFs, forms, or document extraction.
---
# PDF Processing
This skill provides utilities for working with PDF documents.
## Quick Start
Use pdfplumber to extract text from PDFs:
```python
import pdfplumber
with pdfplumber.open("document.pdf") as pdf:
text = pdf.pages[0].extract_text()
print(text)
```
## Available Operations
1. **Text Extraction**: Extract text content from PDF pages
2. **Table Extraction**: Extract tabular data from PDFs
3. **Form Filling**: Fill PDF forms with provided data
4. **Document Merging**: Combine multiple PDFs into one
## Advanced Features
**Form filling**: See [FORMS.md](FORMS.md) for complete guide
**Utility scripts**:
- Run `scripts/analyze_form.py` to extract form fields
- Run `scripts/extract_text.py` to extract text from a PDF
## Best Practices
1. Always validate PDF files before processing
2. Handle password-protected PDFs gracefully
3. Check for scanned PDFs that may require OCR
@@ -0,0 +1,46 @@
#!/usr/bin/env python3
"""
Analyze PDF form fields and output their structure.
Usage: python analyze_form.py <pdf_file>
"""
import sys
import json
def analyze_form(pdf_path):
"""Analyze form fields in a PDF file."""
# This is a mock implementation for testing
# In production, would use pypdf or pdfrw
print(f"Analyzing PDF: {pdf_path}")
print("=" * 50)
# Mock form fields for demonstration
fields = {
"name": {"type": "text", "required": True},
"email": {"type": "text", "required": True},
"date": {"type": "date", "required": False},
"agree_terms": {"type": "checkbox", "required": True},
"signature": {"type": "signature", "required": True}
}
print("\nDiscovered Form Fields:")
print("-" * 30)
for field_name, props in fields.items():
required_str = "[REQUIRED]" if props["required"] else "[optional]"
print(f" {field_name}: {props['type']} {required_str}")
print("\n" + "=" * 50)
print("Analysis complete.")
# Output JSON for programmatic use
return json.dumps(fields, indent=2)
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: python analyze_form.py <pdf_file>")
sys.exit(1)
result = analyze_form(sys.argv[1])
print("\nJSON Output:")
print(result)
@@ -0,0 +1,54 @@
#!/usr/bin/env python3
"""
Extract text from PDF files.
Usage: python extract_text.py <pdf_file> [--page N]
"""
import sys
def extract_text(pdf_path, page_num=None):
"""Extract text from a PDF file."""
# This is a mock implementation for testing
# In production, would use pdfplumber or pypdf
print(f"Extracting text from: {pdf_path}")
if page_num:
print(f"Page: {page_num}")
else:
print("All pages")
print("=" * 50)
# Mock extracted text
mock_text = """
Sample PDF Document
This is a demonstration of text extraction from PDF files.
Key Features:
- Fast and efficient text extraction
- Preserves document structure
- Handles multi-page documents
For more information, visit our documentation.
"""
print(mock_text)
print("=" * 50)
print("Extraction complete.")
return mock_text.strip()
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: python extract_text.py <pdf_file> [--page N]")
sys.exit(1)
pdf_path = sys.argv[1]
page_num = None
if len(sys.argv) > 3 and sys.argv[2] == "--page":
page_num = int(sys.argv[3])
extract_text(pdf_path, page_num)
Binary file not shown.
+67
View File
@@ -0,0 +1,67 @@
---
name: ui-builder
description: 当用户需要可视化界面时生成单文件 HTML 交互界面(学习进度看板、课程地图、练习题页、数据报表、操作指引页等),作为会话产物自动保存并可在沙箱面板中预览。触发词包括:做个看板、生成页面、可视化、练习页、报表、指引页。
---
# UI 构建(单文件 HTML 产物)
用户需要"看得见的界面"时,用本技能生成**一个自包含的 HTML 文件**写入产物目录。
文件会被自动收集为会话产物,并在前端沙箱面板中渲染(允许脚本,opaque origin)。
## 生成流程
1. **先取数,后生成。** 界面上的数据必须来自真实查询:
- 培训资料 → `search_knowledge`
- 表格/数据库 → `data_schema` + `data_analysis`(只读 SELECT)
- 学习/业务数据 → 已挂载的 MCP 工具(如 `get_student_progress`)
- 禁止编造数据;查不到的字段要标注"暂无数据"。
2. 生成一个 HTML 文件写入产物目录:优先使用环境变量
`ACADEMY_SKILL_OUTPUT_DIR`(未设置时用 `/workspace/output`)。
3. 文件名语义化并以 `.html` 结尾,例如 `progress-dashboard.html`、`quiz-fire-safety.html`。
4. 在回答末尾引用产物让前端渲染入口卡片:
`![界面预览](sandbox:progress-dashboard.html)`
## 硬性约束(运行环境是 opaque origin 沙箱 iframe)
- **单文件自包含**:所有 CSS/JS 内联;不得引用本地其它文件。
- **体量纪律**:整个文件控制在 250 行 / 30KB 以内;图表优先用内联 SVG 或纯 CSS
实现,仅当确有必要才引一个 ESM CDN 库;样式精炼不堆砌,信息密度优先。
(生成输出预算有限,体量超限会被截断导致文件损坏)
- **外部库仅限 ESM CDN**:`https://esm.sh/...`、`https://cdn.jsdelivr.net/...`,
用 `<script type="module">` + import 引入;库失败时界面必须仍可读。
- **数据内嵌**:查询结果写入
`<script id="embedded-data" type="application/json">{ ... }</script>`,
页面脚本从该节点读取;便于用户校对数据来源。
- **禁用浏览器存储**:不要读写 `localStorage`/`sessionStorage`
(宿主已注入内存垫片,但刷新即丢失,依赖它会坏)。
- **禁止**:向外部地址发请求、提交表单、要求凭证的调用、任何写操作。
- **响应式**:容器宽度 420px~1200px 都要可用;优先 flex/grid,避免固定宽度。
- **中文文案**,语言风格与企业培训场景一致;配色克制,状态色语义正确
(红=风险/未完成,绿=已完成)。
## 宿主桥接(wkui 协议,可选能力探测)
宿主页面若启用了桥接,iframe 内会有 `window.wkui`。用前必须探测:
```js
if (window.wkui && window.wkui.version >= 1) {
// 把一句话送进对话(例如"就按这个方案执行")
window.wkui.sendChat('请把研发部的明细展开');
// 只读数据请求(返回 Promise),kind 仅支持三种:
// session-artifacts / message-artifacts / artifact-text
const res = await window.wkui.requestData({ kind: 'session-artifacts' });
}
```
- `window.wkui` 不存在时界面必须完整可用(桥接是增强,不是依赖)。
- 按钮触发 `sendChat` 前给用户可见反馈(如按钮态变化)。
## 界面类型速查
| 类型 | 必备元素 |
|---|---|
| 学习进度看板 | 总完成率大数字、按课程/部门分组条形、逾期醒目提示 |
| 练习题页 | 题干+选项按钮、提交后逐题对错与解析、得分汇总 |
| 数据报表 | 表格+图表(可用内联 SVG 或 ESM CDN 图表库)、数据截止时间标注 |
| 操作指引 | 步骤条、图文区块、可折叠详情 |
@@ -0,0 +1,77 @@
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>学习进度看板(模板示例)</title>
<style>
/* 全部内联;配色克制;420~1200px 自适应 */
:root { --ok:#2e7d32; --warn:#c62828; --line:#e0e0e0; --muted:#757575; }
* { box-sizing: border-box; margin: 0; }
body { font: 14px/1.6 system-ui, "PingFang SC", "Microsoft YaHei", sans-serif; color:#212121; padding:16px; }
.head { display:flex; align-items:baseline; gap:12px; flex-wrap:wrap; }
.head h1 { font-size:18px; }
.head .meta { color:var(--muted); font-size:12px; }
.cards { display:grid; grid-template-columns:repeat(auto-fit,minmax(140px,1fr)); gap:12px; margin:16px 0; }
.card { border:1px solid var(--line); border-radius:8px; padding:12px; }
.card .num { font-size:26px; font-weight:700; }
.card .label { color:var(--muted); font-size:12px; }
.bar-row { display:grid; grid-template-columns: 9em 1fr 4em; gap:8px; align-items:center; padding:4px 0; }
.bar { height:10px; background:#eee; border-radius:5px; overflow:hidden; }
.bar > i { display:block; height:100%; background:#1976d2; }
.overdue { color:var(--warn); }
.done { color:var(--ok); }
button.wkui { border:1px solid var(--line); background:#fff; border-radius:6px; padding:6px 12px; cursor:pointer; }
button.wkui:active { background:#f5f5f5; }
@media (max-width:520px) { .bar-row { grid-template-columns: 7em 1fr 4em; } }
</style>
</head>
<body>
<div class="head">
<h1>我的学习进度</h1>
<span class="meta">数据截止:2026-11-09(来源:embedded-data)</span>
<button class="wkui" id="drill">展开研发部明细</button>
</div>
<div class="cards">
<div class="card"><div class="num">78%</div><div class="label">总完成率</div></div>
<div class="card"><div class="num done">12</div><div class="label">已完成课程</div></div>
<div class="card"><div class="num overdue">3</div><div class="label">逾期未完成</div></div>
</div>
<div id="bars"></div>
<!-- 数据快照:来自真实查询结果,禁止编造 -->
<script id="embedded-data" type="application/json">
{
"as_of": "2026-11-09",
"summary": { "total_rate": 0.78, "done": 12, "overdue": 3 },
"rows": [
{ "name": "入职必修", "rate": 1.0 },
{ "name": "安全合规", "rate": 0.6 },
{ "name": "岗位技能", "rate": 0.4 }
]
}
</script>
<script type="module">
const data = JSON.parse(document.getElementById('embedded-data').textContent);
const bars = document.getElementById('bars');
for (const row of data.rows) {
const el = document.createElement('div');
el.className = 'bar-row';
el.innerHTML = '<span>' + row.name + '</span>' +
'<span class="bar"><i style="width:' + Math.round(row.rate * 100) + '%"></i></span>' +
'<span>' + Math.round(row.rate * 100) + '%</span>';
bars.appendChild(el);
}
// 桥接为增强,不是依赖:不存在时按钮隐藏
const drill = document.getElementById('drill');
if (!(window.wkui && window.wkui.version >= 1)) {
drill.style.display = 'none';
} else {
drill.addEventListener('click', () => window.wkui.sendChat('展开研发部的培训明细'));
}
</script>
</body>
</html>