feat(project): AI Agent 脚手架学习站(6 篇 22 章骨架 + 前言两章正文)
- 新增 VLoop 同构学习站:index/6 个篇章页/22 个章节页 + assets + tools(outline/build-nav/check-pages/gen-skeleton/SPEC) - 正文:第 1 章项目全景、第 2 章学习路线(按 2200 字/代码块/表格/提示框规范撰写) - 原面试题库迁至 interview/ 子目录,导航页拆成「学习站」与「题库」两个入口 - README 与 portal.data.js 同步
This commit is contained in:
102
project/ai-agent-scafford-go/tools/SPEC.md
Normal file
102
project/ai-agent-scafford-go/tools/SPEC.md
Normal file
@@ -0,0 +1,102 @@
|
||||
# 写作规范(本项目的 SPEC)
|
||||
|
||||
> 本文件是**写作规范**;章节与小节的**逐条清单**在 [`outline.json`](outline.json) 里,它是骨架的唯一数据源。
|
||||
> `tools/build-nav.js` 会用 outline.json 与页面里的 `<h3 id>` 双向核对,任何一边漂移都会直接报错并停止改写。
|
||||
|
||||
## 一、读者画像
|
||||
|
||||
读者是「会一门后端语言、想读懂一个真实 Agent 脚手架」的人,不是初学者,也没读过这套源码。
|
||||
所以每一节要同时满足两件事:**能落地到文件与函数**,**不需要先读别的章节才能看懂**。
|
||||
写成「面向同事的技术讲解」,不要写成 API 文档,也不要写成营销稿。
|
||||
|
||||
## 二、站点目录结构
|
||||
|
||||
```text
|
||||
ai-agent-scafford-go/
|
||||
├── index.html # 学习地图
|
||||
├── part-0.html … part-5.html # 六个篇章页
|
||||
├── NN-slug.html # 章节页(NN = 章号,从 01 起)
|
||||
├── assets/doc.css # 全站样式(勿改,除非要改主题)
|
||||
├── assets/doc.js # 交互:目录高亮、主题、代码复制、进度、搜索
|
||||
├── interview/ # 289 道面试题(独立页面,不参与本站校验)
|
||||
└── tools/
|
||||
├── outline.json # ★ 骨架唯一数据源:篇 / 章 / 小节
|
||||
├── build-nav.js # 生成顶栏、侧栏、篇页卡片、翻页、页脚、进度
|
||||
├── check-pages.js # 自检:结构 / 链接 / 锚点 / 目录树 / 内容量
|
||||
├── gen-skeleton.js # 一次性:按大纲生成页面外壳
|
||||
└── SPEC.md # 本文件
|
||||
```
|
||||
|
||||
## 三、三级页面与命名
|
||||
|
||||
- 学习地图 → 篇章页 → 章节页。**篇是一级导航**,直接摆在顶栏;**侧栏只列本篇章**(index 例外,列全 22 章)。
|
||||
- 章号 = 文件名前两位(`08-armory.html` 即第 8 章),必须从 01 连续。
|
||||
- 小节 id 一律 `sec-<章号>-<序号>`,序号从 1 连续;小节标题写作 `8.1 …`。
|
||||
|
||||
## 四、自动区块:不要手改
|
||||
|
||||
三类页面都有固定区块由 `tools/build-nav.js` 生成。写作时只改 `<article>` 里的正文,
|
||||
碰到下面这些区块一律跳过(脚本是幂等的,重跑会覆盖):
|
||||
|
||||
| 位置 | 占位 | 由谁生成 |
|
||||
| --- | --- | --- |
|
||||
| 顶栏 | `<nav class="partnav" id="partnav">` | build-nav |
|
||||
| 侧栏 | `<nav id="chapters">` | build-nav |
|
||||
| 页面 | `<p class="chapnav">` | build-nav |
|
||||
| 篇章页 | `<!-- AUTO:hero -->` … `<!-- /AUTO:hero -->` | build-nav |
|
||||
| 篇章页 | `<!-- AUTO:cards -->` … `<!-- /AUTO:cards -->` | build-nav |
|
||||
| 目录页 | `<!-- AUTO:kpis -->`、`<!-- AUTO:partcards -->` | build-nav |
|
||||
| 三类页 | `<!-- AUTO:prog -->` … `<!-- /AUTO:prog -->` | build-nav |
|
||||
| 三类页 | `<nav class="pager">`、`<p class="foot">` | build-nav |
|
||||
|
||||
## 五、每章的硬性要求(`check-pages.js` 严格模式逐条检查)
|
||||
|
||||
- 章标题 `<h2 id="chN"><span class="n">N</span>…</h2>`,文字与 `outline.json` **逐字一致**;
|
||||
- **至少 3 个小节**(`<h3 id="sec-N-x">`),标题与大纲一致;
|
||||
- **至少 2 个代码块**,且都带 `data-lang`(推荐再加 `data-name`);
|
||||
- **至少 1 个** `.box`(`note` / `tip` / `warn` / `danger` / `ok` / `case`);
|
||||
- **至少 1 个** `.tablewrap > table` 或 `.cards` 卡片组;
|
||||
- 正文(不含代码)**≥ 2200 字**;
|
||||
- 开头必须有 `.lead`,以「**这一章解决什么:**」起头;
|
||||
- 所有 `class="tbd"` 占位必须删干净。
|
||||
|
||||
## 六、内容纪律
|
||||
|
||||
1. **事实必须可核对**。讲实现给 `文件路径:行号`;讲行为给可复现命令与真实输出;讲配置给键名与默认值。
|
||||
本站的权威事实源只有三处:源码、`docs/项目完善报告.md`、`docs/something-to-be-implemented.md`。
|
||||
2. **先结论,再展开**。每节第一段就回答「它是什么 / 为什么这样设计」,不要从背景铺陈开始。
|
||||
3. **区分「设计如此」与「现状是坑」**。这个项目里有大量**有意为之的简化**(内存版 Registry、loop 与 parallel 复用同一段聚合逻辑、
|
||||
Skill 只出现在工具列表里)。写清楚哪些是取舍、哪些是缺陷,并给出判断依据。
|
||||
4. **不编造**。没有读过的代码不写;没跑通的命令不给输出;不确定的地方标「未验证」。
|
||||
5. **通俗**:术语首次出现给一句人话解释;每章结尾给一个「这一章记住三句话」的小结(用 `.box tip`)。
|
||||
|
||||
## 七、常用片段
|
||||
|
||||
```html
|
||||
<!-- 提示框 -->
|
||||
<div class="box warn">
|
||||
<span class="bt">小标题</span>
|
||||
<p>正文。</p>
|
||||
</div>
|
||||
|
||||
<!-- 代码 -->
|
||||
<pre data-lang="go" data-name="internal/app/bootstrap/bootstrap.go:49-53">代码…</pre>
|
||||
|
||||
<!-- 表格 -->
|
||||
<div class="tablewrap">
|
||||
<table>
|
||||
<thead><tr><th>列</th><th>列</th></tr></thead>
|
||||
<tbody><tr><td>…</td><td>…</td></tr></tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- 卡片组 -->
|
||||
<div class="cards">
|
||||
<div class="card"><h4>标题</h4><ul><li>要点</li></ul></div>
|
||||
</div>
|
||||
```
|
||||
|
||||
## 八、改大纲的正确姿势
|
||||
|
||||
先改 `outline.json` → 再改页面 `<h2>` / `<h3>` → 跑 `node tools/build-nav.js` → 跑 `node tools/check-pages.js`。
|
||||
反过来(只改页面不改大纲)会在核对阶段报错——这是有意设计的护栏。
|
||||
360
project/ai-agent-scafford-go/tools/build-nav.js
Normal file
360
project/ai-agent-scafford-go/tools/build-nav.js
Normal file
@@ -0,0 +1,360 @@
|
||||
#!/usr/bin/env node
|
||||
/* ==========================================================================
|
||||
VLoop 项目学习 · 页面骨架生成器
|
||||
用法:node tools/build-nav.js
|
||||
|
||||
本站分三级页面:
|
||||
目录页 index.html 学习地图 + 六个篇章入口卡片
|
||||
篇章页 part-N.html 一篇的导语 + 该篇的章节卡片(六个篇)
|
||||
章节页 NN-slug.html 一章正文(二十二章)
|
||||
|
||||
数据来源:
|
||||
tools/outline.json ← 篇 / 章 / 小节 的声明(骨架的唯一来源)
|
||||
各页面的 <h3 id> ← 只用来核对「页面是否与大纲一致」,不反向覆盖大纲
|
||||
|
||||
重写的占位区块:
|
||||
所有页面:<nav class="partnav"> 顶栏篇章导航(当前篇高亮)
|
||||
<nav id="chapters"> 侧栏目录树(按篇分组,当前章展开小节)
|
||||
篇章页: <!-- AUTO:hero --> 篇章导语(篇号 / 篇名 / 篇导语 / 章数小节数)
|
||||
<!-- AUTO:cards --> 该篇的章节卡片
|
||||
<!-- AUTO:prog --> 本篇已读进度条
|
||||
<p class="chapnav"> 「篇 N / 6」定位条
|
||||
<nav class="pager"> 上一篇 / 下一篇
|
||||
目录页: <!-- AUTO:kpis --> 篇 / 章 / 小节 / 代码 / 字数
|
||||
<!-- AUTO:partcards --> 六个篇章入口卡片
|
||||
<!-- AUTO:prog --> 总体已读进度条
|
||||
<nav class="pager"> 「开始阅读」
|
||||
页脚: <p class="foot"> 三种页面各自的页脚
|
||||
|
||||
写正文时只写 <article> 里的内容,骨架由本脚本统一生成;调整大纲先改 outline.json
|
||||
与页面标题,再执行本脚本。幂等、可重复运行。
|
||||
========================================================================== */
|
||||
"use strict";
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const ROOT = path.resolve(__dirname, "..");
|
||||
const PLAN = JSON.parse(fs.readFileSync(path.join(__dirname, "outline.json"), "utf8"));
|
||||
const S = PLAN.site;
|
||||
const TOTAL = PLAN.parts.reduce((n, p) => n + p.chapters.length, 0);
|
||||
const PART_PAGE = (no) => `part-${no}.html`;
|
||||
|
||||
const esc = (s) => String(s).replace(/&/g, "&").replace(/</g, "<")
|
||||
.replace(/>/g, ">").replace(/"/g, """);
|
||||
const stripTags = (s) => s.replace(/<[^>]+>/g, " ").replace(/\s+/g, " ").trim();
|
||||
const decode = (s) => s.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"')
|
||||
.replace(/'/g, "'").replace(/ /g, " ").replace(/&/g, "&");
|
||||
const plain = (s) => decode(stripTags(s));
|
||||
const shortPart = (name) => name.split("·")[0].trim();
|
||||
|
||||
/* ---------------------------- 1. 采集与核对 ---------------------------- */
|
||||
const chapters = [];
|
||||
const problems = [];
|
||||
|
||||
for (const part of PLAN.parts) {
|
||||
const pf = PART_PAGE(part.no);
|
||||
if (!fs.existsSync(path.join(ROOT, pf))) problems.push(`${pf}: 篇章页不存在`);
|
||||
|
||||
for (const c of part.chapters) {
|
||||
const file = c.file;
|
||||
if (!fs.existsSync(path.join(ROOT, file))) { problems.push(`${file}: 文件不存在`); continue; }
|
||||
const html = fs.readFileSync(path.join(ROOT, file), "utf8");
|
||||
const num = parseInt(file.slice(0, 2), 10);
|
||||
|
||||
const h2 = html.match(/<h2 id="([^"]+)">([\s\S]*?)<\/h2>/);
|
||||
if (!h2) { problems.push(`${file}: 找不到 <h2 id="...">章标题</h2>`); continue; }
|
||||
const title = plain(h2[2].replace(/<span class="n">\d+<\/span>/, ""));
|
||||
if (title !== c.title) {
|
||||
problems.push(`${file}: 章标题与 outline.json 不一致\n 页面:${title}\n 大纲:${c.title}`);
|
||||
}
|
||||
|
||||
/* 小节以页面 h3 为准,但必须与大纲逐条对齐(数量 + id + 标题) */
|
||||
const secs = [...html.matchAll(/<h3 id="([^"]+)">([\s\S]*?)<\/h3>/g)]
|
||||
.map((m) => ({ id: m[1], label: plain(m[2]) }));
|
||||
if (secs.length !== c.sections.length) {
|
||||
problems.push(`${file}: 小节数 ${secs.length} ≠ 大纲 ${c.sections.length}`);
|
||||
} else {
|
||||
c.sections.forEach((s, i) => {
|
||||
if (secs[i].id !== s.id) problems.push(`${file}: 第 ${i + 1} 个小节 id "${secs[i].id}" ≠ 大纲 "${s.id}"`);
|
||||
if (secs[i].label !== s.title) {
|
||||
problems.push(`${file}: 小节 "${s.id}" 标题与大纲不一致\n 页面:${secs[i].label}\n 大纲:${s.title}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const article = (html.match(/<article>([\s\S]*)<\/article>/) || [, ""])[1];
|
||||
/* 正文字数:排除代码块,也排除本脚本生成的导航(翻页 / 页脚 / 章位条) */
|
||||
const bodyText = article
|
||||
.replace(/<pre[\s\S]*?<\/pre>/g, " ")
|
||||
.replace(/<nav class="pager">[\s\S]*?<\/nav>/g, " ")
|
||||
.replace(/<p class="foot">[\s\S]*?<\/p>/g, " ")
|
||||
.replace(/<p class="chapnav">[\s\S]*?<\/p>/g, " ");
|
||||
|
||||
chapters.push({
|
||||
num, file, title, part, sections: secs,
|
||||
desc: plain((html.match(/<meta name="description" content="([^"]*)"/) || [, ""])[1]),
|
||||
level: c.level || "",
|
||||
pres: (html.match(/<pre[\s\S]*?<\/pre>/g) || []).length,
|
||||
chars: plain(bodyText).replace(/\s+/g, "").length,
|
||||
todo: (html.match(/class="tbd"/g) || []).length
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (problems.length) {
|
||||
console.error(`大纲与页面不一致(${problems.length} 处),已停止改写:`);
|
||||
problems.forEach((p) => console.error(" - " + p));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const parts = PLAN.parts.map((p) => ({
|
||||
...p,
|
||||
chapters: p.chapters.map((c) => chapters.find((x) => x.file === c.file)).filter(Boolean)
|
||||
}));
|
||||
|
||||
/* 章的 part 必须指回「富化后」的篇对象,否则 ctx.part.chapters 拿到的是大纲里的
|
||||
原始章节(没有 num / pres / chars),渲染出来章号会是 undefined。 */
|
||||
for (const p of parts) for (const ch of p.chapters) ch.part = p;
|
||||
|
||||
const totalSecs = chapters.reduce((n, c) => n + c.sections.length, 0);
|
||||
const totalPres = chapters.reduce((n, c) => n + c.pres, 0);
|
||||
const totalChars = chapters.reduce((n, c) => n + c.chars, 0);
|
||||
const totalTodo = chapters.reduce((n, c) => n + c.todo, 0);
|
||||
const allNums = chapters.map((c) => c.num).join(",");
|
||||
|
||||
/* ---------------------------- 2. 区块生成 ---------------------------- */
|
||||
function partnav(ctx) {
|
||||
const rows = [`<a class="home${ctx.kind === "index" ? " on" : ""}" href="index.html">学习地图</a>`,
|
||||
`<span class="pn-sep"></span>`];
|
||||
for (const p of parts) {
|
||||
const on = ctx.part && String(ctx.part.no) === String(p.no);
|
||||
rows.push(`<a href="${PART_PAGE(p.no)}"${on ? ' class="on"' : ""}>篇 ${p.no} ${esc(shortPart(p.name))}</a>`);
|
||||
}
|
||||
return `<nav class="partnav" id="partnav">${rows.join("")}</nav>`;
|
||||
}
|
||||
|
||||
function chapterRow(ch, ctx) {
|
||||
const isCur = ctx.kind === "chapter" && ch.num === ctx.chapter.num;
|
||||
if (!isCur) {
|
||||
return `<a class="toc-a" href="${ch.file}"><i class="cn">${ch.num}</i>${esc(ch.title)}</a>`;
|
||||
}
|
||||
const sub = ch.sections.length
|
||||
? `<div class="subnav current">${ch.sections
|
||||
.map((s) => `<a class="toc-a lv3" href="#${s.id}">${esc(s.label)}</a>`).join("")}</div>`
|
||||
: "";
|
||||
return `<span class="toc-a active" aria-current="page"><i class="cn">${ch.num}</i>${esc(ch.title)}</span>` + sub;
|
||||
}
|
||||
|
||||
function navTree(ctx) {
|
||||
/* 学习地图:全站目录,六个篇分组列出全部章节——它是唯一「看得见全貌」的地方 */
|
||||
if (ctx.kind === "index") {
|
||||
const rows = [];
|
||||
for (const p of parts) {
|
||||
rows.push(`<div class="toc-part"><a href="${PART_PAGE(p.no)}">篇 ${p.no} · ${esc(shortPart(p.name))}</a></div>`);
|
||||
for (const ch of p.chapters) rows.push(chapterRow(ch, ctx));
|
||||
}
|
||||
return `<nav id="chapters">${rows.join("")}</nav>`;
|
||||
}
|
||||
|
||||
/* 篇章页与章节页:侧栏只列本篇自己的章,顶部一条「本篇 / 全部篇章」的范围条 */
|
||||
const p = ctx.part;
|
||||
const rows = [
|
||||
`<div class="toc-scope">` +
|
||||
`<span class="ts-label">篇 ${p.no}</span><span class="ts-name">${esc(shortPart(p.name))}</span>` +
|
||||
`<a class="ts-all" href="index.html">全部篇章 →</a>` +
|
||||
`</div>`
|
||||
];
|
||||
for (const ch of p.chapters) rows.push(chapterRow(ch, ctx));
|
||||
return `<nav id="chapters">${rows.join("")}</nav>`;
|
||||
}
|
||||
|
||||
function chapnav(ctx) {
|
||||
if (ctx.kind === "part") {
|
||||
return ` <a href="index.html">${esc(S.name)}</a>\n` +
|
||||
` <span>·</span>\n` +
|
||||
` <span>篇 <b class="pos">${ctx.part.no}</b> / ${parts.length}</span>`;
|
||||
}
|
||||
const p = ctx.chapter.part;
|
||||
return ` <a href="index.html">${esc(S.name)}</a>\n` +
|
||||
` <span>·</span>\n` +
|
||||
` <a href="${PART_PAGE(p.no)}">篇 ${p.no} ${esc(shortPart(p.name))}</a>\n` +
|
||||
` <span>·</span>\n` +
|
||||
` <span>第 <b class="pos">${ctx.chapter.num}</b> / ${TOTAL} 章</span>`;
|
||||
}
|
||||
|
||||
function pagerLinks(prev, next, kPrev, kNext, doneText) {
|
||||
const a = (item, cls, k) => item
|
||||
? ` <a class="${cls}" href="${item.href}"><span class="k">${k}</span><span class="v">${item.label}</span></a>`
|
||||
: ` <a class="${cls} disabled"><span class="k">${k}</span><span class="v">${doneText}</span></a>`;
|
||||
return a(prev, "prev", kPrev) + "\n" + a(next, "next", kNext);
|
||||
}
|
||||
|
||||
function pager(ctx) {
|
||||
if (ctx.kind === "index") {
|
||||
const first = chapters[0];
|
||||
return ` <a class="next" href="${first.file}"><span class="k">开始阅读 →</span><span class="v">第 ${first.num} 章 · ${esc(first.title)}</span></a>`;
|
||||
}
|
||||
if (ctx.kind === "part") {
|
||||
const i = parts.indexOf(ctx.part);
|
||||
const mk = (p) => p && { href: PART_PAGE(p.no), label: `篇 ${p.no} · ${esc(shortPart(p.name))}` };
|
||||
return pagerLinks(mk(parts[i - 1]), mk(parts[i + 1]), "← 上一篇", "下一篇 →", "没有更多了");
|
||||
}
|
||||
const i = chapters.indexOf(ctx.chapter);
|
||||
const mk = (c) => c && { href: c.file, label: `第 ${c.num} 章 · ${esc(c.title)}` };
|
||||
return pagerLinks(mk(chapters[i - 1]), mk(chapters[i + 1]), "← 上一章", "下一章 →", "没有更多了");
|
||||
}
|
||||
|
||||
function foot(ctx) {
|
||||
if (ctx.kind === "index") {
|
||||
return ` ${esc(S.name)} · 共 ${parts.length} 篇 ${TOTAL} 章 ${totalSecs} 个小节` +
|
||||
`${totalTodo ? ` · 其中 ${totalTodo} 个小节待撰写` : ` · ${totalPres} 段代码`}<br>\n` +
|
||||
(S.repoUrl ? ` <a href="${esc(S.repoUrl)}">${esc(S.repo)}</a> · <a href="index.html">学习地图</a>`
|
||||
: ` ${esc(S.repo)} · <a href="index.html">学习地图</a>`);
|
||||
}
|
||||
if (ctx.kind === "part") {
|
||||
return ` ${esc(S.name)} · 篇 ${ctx.part.no} ${esc(ctx.part.name)}<br>\n` +
|
||||
` <a href="index.html">学习地图</a> · ${ctx.part.chapters.length} 章 · ` +
|
||||
`${ctx.part.chapters.reduce((n, c) => n + c.sections.length, 0)} 个小节`;
|
||||
}
|
||||
const c = ctx.chapter;
|
||||
return ` ${esc(S.name)} · 第 ${c.num} 章 ${esc(c.title)}<br>\n` +
|
||||
` <a href="index.html">学习地图</a> · <a href="${PART_PAGE(c.part.no)}">篇 ${c.part.no} ${esc(shortPart(c.part.name))}</a>` +
|
||||
` · <a href="22-cheatsheet.html">速查与自测</a>`;
|
||||
}
|
||||
|
||||
function kpis() {
|
||||
const wan = (totalChars / 10000).toFixed(1);
|
||||
return [
|
||||
`<div class="kpi"><b>${parts.length}</b><span>个篇章 · 递进式学习路径</span></div>`,
|
||||
`<div class="kpi"><b>${TOTAL}</b><span>章 · 从全景到速查</span></div>`,
|
||||
`<div class="kpi"><b>${totalSecs}</b><span>个小节骨架</span></div>`,
|
||||
`<div class="kpi"><b>${totalPres}</b><span>段可复制代码</span></div>`,
|
||||
`<div class="kpi"><b>${wan} 万</b><span>字正文</span></div>`
|
||||
].join("\n ");
|
||||
}
|
||||
|
||||
function partcards() {
|
||||
return parts.map((p) => {
|
||||
const nums = p.chapters.map((c) => c.num);
|
||||
const secs = p.chapters.reduce((n, c) => n + c.sections.length, 0);
|
||||
const lv = [...new Set(p.chapters.map((c) => c.level).filter(Boolean))].sort();
|
||||
return ` <div class="partcard" data-chapters="${nums.join(",")}">
|
||||
<div class="pc-head">
|
||||
<span class="pc-no">篇 ${p.no}</span>
|
||||
<a class="pc-name" href="${PART_PAGE(p.no)}">${esc(p.name)}</a>
|
||||
</div>
|
||||
<p class="pc-note">${esc(p.note || "")}</p>
|
||||
<div class="pc-meta">
|
||||
<span><b>${nums.length}</b> 章</span>
|
||||
<span><b>${secs}</b> 小节</span>
|
||||
${lv.length ? `<span>${lv.join(" / ")}</span>` : ""}
|
||||
<span data-partprog>已读 0 / ${nums.length}</span>
|
||||
</div>
|
||||
<a class="pc-go" href="${PART_PAGE(p.no)}">进入本篇 →</a>
|
||||
</div>`;
|
||||
}).join("\n");
|
||||
}
|
||||
|
||||
function cardsOf(part) {
|
||||
return part.chapters.map((ch) => {
|
||||
const search = [ch.title, ch.desc, ch.level, ch.sections.map((s) => s.label).join(" ")]
|
||||
.join(" ").toLowerCase();
|
||||
const secs = ch.sections.map((s) =>
|
||||
`<a href="${ch.file}#${s.id}">${esc(s.label)}</a>`).join("");
|
||||
return ` <div class="chapcard" data-search="${esc(search)}">
|
||||
<div class="cc-head">
|
||||
<input type="checkbox" data-ch="${ch.num}" aria-label="标记第 ${ch.num} 章已读">
|
||||
<span class="cc-no">${ch.num}</span>
|
||||
<a class="cc-title" href="${ch.file}">${esc(ch.title)}</a>
|
||||
${ch.level ? `<span class="cc-lv">${esc(ch.level)}</span>` : ""}
|
||||
<a class="cc-go" href="${ch.file}">进入 →</a>
|
||||
</div>
|
||||
<p class="cc-desc">${esc(ch.desc)}</p>
|
||||
<details class="cc-secs">
|
||||
<summary>${ch.sections.length} 个小节${ch.todo ? " · 待撰写" : ""} · 展开看知识点</summary>
|
||||
<div>${secs}</div>
|
||||
</details>
|
||||
</div>`;
|
||||
}).join("\n");
|
||||
}
|
||||
|
||||
function hero(part) {
|
||||
const nums = part.chapters.map((c) => c.num);
|
||||
const secs = part.chapters.reduce((n, c) => n + c.sections.length, 0);
|
||||
const lv = [...new Set(part.chapters.map((c) => c.level).filter(Boolean))].sort();
|
||||
return ` <!-- AUTO:hero -->
|
||||
<div class="modhero">
|
||||
<span class="mh-no">篇 ${part.no} / ${parts.length}</span>
|
||||
<h1>${esc(part.name)}</h1>
|
||||
<p class="mh-sub">${esc(part.note || "")}</p>
|
||||
<div class="mh-meta">
|
||||
<span>第 <b>${nums[0]}</b>–<b>${nums[nums.length - 1]}</b> 章</span>
|
||||
<span><b>${nums.length}</b> 章 · <b>${secs}</b> 个小节</span>
|
||||
${lv.length ? `<span>能力等级 <b>${lv.join(" / ")}</b></span>` : ""}
|
||||
</div>
|
||||
</div>
|
||||
<!-- /AUTO:hero -->`;
|
||||
}
|
||||
|
||||
function prog(nums) {
|
||||
return ` <!-- AUTO:prog -->
|
||||
<div class="progwrap" data-chapters="${nums}">
|
||||
<span>已读</span><div class="bar"><i></i></div><b>0%</b>
|
||||
</div>
|
||||
<!-- /AUTO:prog -->`;
|
||||
}
|
||||
|
||||
/* ---------------------------- 3. 写回 ---------------------------- */
|
||||
const Z = (re, gen, only) => ({ re, gen, only });
|
||||
|
||||
const zones = [
|
||||
Z(/<nav class="partnav"[^>]*>[\s\S]*?<\/nav>/, (ctx) => partnav(ctx)),
|
||||
Z(/<nav id="chapters">[\s\S]*?<\/nav>/, (ctx) => navTree(ctx)),
|
||||
Z(/<p class="chapnav">[\s\S]*?<\/p>/, (ctx) => `<p class="chapnav">\n${chapnav(ctx)}\n </p>`, "part|chapter"),
|
||||
Z(/<!-- AUTO:hero -->[\s\S]*?<!-- \/AUTO:hero -->/, (ctx) => hero(ctx.part), "part"),
|
||||
Z(/<!-- AUTO:kpis -->[\s\S]*?<!-- \/AUTO:kpis -->/, () => `<!-- AUTO:kpis -->\n ${kpis()}\n <!-- /AUTO:kpis -->`, "index"),
|
||||
Z(/<!-- AUTO:partcards -->[\s\S]*?<!-- \/AUTO:partcards -->/, () => `<!-- AUTO:partcards -->\n${partcards()}\n <!-- /AUTO:partcards -->`, "index"),
|
||||
Z(/<!-- AUTO:cards -->[\s\S]*?<!-- \/AUTO:cards -->/, (ctx) => `<!-- AUTO:cards -->\n${cardsOf(ctx.part)}\n <!-- /AUTO:cards -->`, "part"),
|
||||
Z(/<!-- AUTO:prog -->[\s\S]*?<!-- \/AUTO:prog -->/, (ctx) => prog(ctx.kind === "index"
|
||||
? allNums : ctx.part.chapters.map((c) => c.num).join(",")), "index|part"),
|
||||
Z(/<nav class="pager">[\s\S]*?<\/nav>/, (ctx) => `<nav class="pager">\n${pager(ctx)}\n </nav>`),
|
||||
Z(/<p class="foot">[\s\S]*?<\/p>/, (ctx) => `<p class="foot">\n${foot(ctx)}\n </p>`)
|
||||
];
|
||||
|
||||
const targets = [];
|
||||
if (fs.existsSync(path.join(ROOT, "index.html"))) {
|
||||
targets.push({ file: "index.html", ctx: { kind: "index" } });
|
||||
}
|
||||
for (const p of parts) {
|
||||
targets.push({ file: PART_PAGE(p.no), ctx: { kind: "part", part: p } });
|
||||
}
|
||||
for (const c of chapters) {
|
||||
targets.push({ file: c.file, ctx: { kind: "chapter", chapter: c, part: c.part } });
|
||||
}
|
||||
|
||||
for (const t of targets) {
|
||||
const p = path.join(ROOT, t.file);
|
||||
let html = fs.readFileSync(p, "utf8");
|
||||
for (const z of zones) {
|
||||
if (z.only && !z.only.split("|").includes(t.ctx.kind)) continue;
|
||||
if (!z.re.test(html)) {
|
||||
console.error(`${t.file}: 缺少占位区块 ${z.re}`);
|
||||
process.exit(1);
|
||||
}
|
||||
html = html.replace(z.re, z.gen(t.ctx));
|
||||
}
|
||||
fs.writeFileSync(p, html, "utf8");
|
||||
}
|
||||
|
||||
/* ---------------------------- 4. 报告 ---------------------------- */
|
||||
for (const p of parts) {
|
||||
const secs = p.chapters.reduce((n, c) => n + c.sections.length, 0);
|
||||
console.log(`${PART_PAGE(p.no).padEnd(12)} 篇 ${p.no} · ${String(p.chapters.length).padStart(2)} 章 · ` +
|
||||
`${String(secs).padStart(3)} 小节 · ${p.name}`);
|
||||
}
|
||||
console.log("");
|
||||
chapters.forEach((c) => console.log(
|
||||
`${c.file.padEnd(26)} 第 ${String(c.num).padStart(2)} 章 · ${String(c.sections.length).padStart(2)} 小节 · ` +
|
||||
`${String(c.pres).padStart(2)} 段代码 · ${String(c.chars).padStart(6)} 字 · ${c.title}`));
|
||||
console.log(`\n篇 ${parts.length} / 章 ${TOTAL} / 小节 ${totalSecs} / 代码 ${totalPres} 段 / ${(totalChars / 10000).toFixed(1)} 万字` +
|
||||
`${totalTodo ? `(待撰写 ${totalTodo} 个小节)` : ""},已同步 ${targets.length} 个页面。`);
|
||||
272
project/ai-agent-scafford-go/tools/check-pages.js
Normal file
272
project/ai-agent-scafford-go/tools/check-pages.js
Normal file
@@ -0,0 +1,272 @@
|
||||
#!/usr/bin/env node
|
||||
/* ==========================================================================
|
||||
VLoop 项目学习 · 页面自检
|
||||
用法:node tools/check-pages.js [--allow-empty]
|
||||
|
||||
--allow-empty(骨架期):内容量相关的要求(正文字数、代码块数量、提示框、
|
||||
表格/卡片、meta 描述长度)降级为提示,只强制结构与链接正确。
|
||||
内容补齐后去掉该参数,恢复为与其它站点一致的严格模式。
|
||||
|
||||
站点分三级页面,检查项按级别区分:
|
||||
所有页面:title / article / #chapters 侧栏 / partnav 顶栏篇章导航 /
|
||||
doc.css / doc.js / themeBtn / 站内链接不跑出本站
|
||||
目录页 index.html:AUTO:kpis / AUTO:partcards(6 张)/ AUTO:prog /
|
||||
「开始阅读」/ 目录页页脚
|
||||
篇章页 part-N.html:AUTO:hero / AUTO:cards(张数 = 本篇章数)/ AUTO:prog /
|
||||
「篇 N / 6」定位条 / 上一篇下一篇 / 篇章页页脚
|
||||
章节页 NN-*.html:h2 / 小节 id 前缀 / 章位条 / 上一章下一章 / 章节页页脚 /
|
||||
当前章 active / 侧栏小节数 = 正文 h3 数
|
||||
通用:标签配对、死链、锚点、目录树列全 22 章并按篇分组、
|
||||
顶栏篇章导航 6 个链接且当前篇高亮
|
||||
========================================================================== */
|
||||
"use strict";
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const ALLOW_EMPTY = process.argv.includes("--allow-empty");
|
||||
const root = path.resolve(__dirname, "..");
|
||||
|
||||
const problems = [];
|
||||
const info = [];
|
||||
const must = (c, m) => { if (!c) problems.push(m); };
|
||||
const soft = (m) => { if (ALLOW_EMPTY) info.push("○ " + m); else problems.push(m); };
|
||||
const read = (p) => fs.readFileSync(p, "utf8");
|
||||
const stripTags = (s) => s.replace(/<[^>]+>/g, "");
|
||||
const norm = (s) => s.replace(/\s+/g, "").length;
|
||||
|
||||
/* 正文字数:只看 <article> 内的手写内容——排除代码块,也排除 build-nav 生成的
|
||||
导航(翻页 / 页脚 / 章位条),否则生成出来的文字会把篇幅算进去。 */
|
||||
const bodyChars = (html) => {
|
||||
const art = (html.match(/<article>([\s\S]*)<\/article>/) || [, ""])[1]
|
||||
.replace(/<pre[\s\S]*?<\/pre>/g, " ")
|
||||
.replace(/<nav class="pager">[\s\S]*?<\/nav>/g, " ")
|
||||
.replace(/<p class="foot">[\s\S]*?<\/p>/g, " ")
|
||||
.replace(/<p class="chapnav">[\s\S]*?<\/p>/g, " ");
|
||||
return norm(stripTags(art));
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------ 页面清点 */
|
||||
const chapterFiles = fs.readdirSync(root).filter((f) => /^\d\d-.*\.html$/.test(f)).sort();
|
||||
const partFiles = fs.readdirSync(root).filter((f) => /^part-\d+\.html$/.test(f))
|
||||
.sort((a, b) => parseInt(a.slice(5), 10) - parseInt(b.slice(5), 10));
|
||||
const hasIndex = fs.existsSync(path.join(root, "index.html"));
|
||||
const pages = (hasIndex ? ["index.html"] : []).concat(partFiles, chapterFiles);
|
||||
|
||||
must(chapterFiles.length >= 5, "章节页数量异常:" + chapterFiles.length);
|
||||
must(partFiles.length >= 2, "篇章页数量异常:" + partFiles.length);
|
||||
|
||||
/* 大纲:用于核对「篇章页里的卡片张数 = 该篇章数」 */
|
||||
const outlineFile = path.join(__dirname, "outline.json");
|
||||
const PLAN = fs.existsSync(outlineFile) ? JSON.parse(read(outlineFile)) : null;
|
||||
must(!!PLAN, "tools/outline.json 不存在或解析失败");
|
||||
const partChapters = new Map(); // 'part-0.html' -> ['01-overview.html', ...]
|
||||
const chapterPart = new Map(); // '01-overview.html' -> ['01-overview.html', ...](本篇全部章)
|
||||
if (PLAN) {
|
||||
for (const p of PLAN.parts) {
|
||||
const files = p.chapters.map((c) => c.file);
|
||||
partChapters.set(`part-${p.no}.html`, files);
|
||||
for (const cf of files) chapterPart.set(cf, files);
|
||||
}
|
||||
must(PLAN.parts.length === partFiles.length,
|
||||
`outline.json 声明 ${PLAN.parts.length} 篇,磁盘上有 ${partFiles.length} 个篇章页`);
|
||||
}
|
||||
|
||||
/* id 索引,供锚点校验 */
|
||||
const idIndex = new Map();
|
||||
for (const f of pages) {
|
||||
const html = read(path.join(root, f));
|
||||
idIndex.set(f, new Set([...html.matchAll(/\sid="([^"]+)"/g)].map((m) => m[1])));
|
||||
}
|
||||
const partFileSet = new Set(partFiles);
|
||||
|
||||
for (const f of pages) {
|
||||
const html = read(path.join(root, f));
|
||||
const markup = html.replace(/<script[\s\S]*?<\/script>/g, "");
|
||||
const kind = f === "index.html" ? "index" : (partFileSet.has(f) ? "part" : "chapter");
|
||||
|
||||
must(/<title>[^<]+<\/title>/.test(html), `${f}: 缺少 title`);
|
||||
must(html.includes("<article>"), `${f}: 缺少 <article>`);
|
||||
must(html.includes('id="chapters"'), `${f}: 缺少侧栏 #chapters`);
|
||||
must(html.includes('href="assets/doc.css"'), `${f}: doc.css 路径不对`);
|
||||
must(html.includes('src="assets/doc.js"'), `${f}: doc.js 路径不对`);
|
||||
must(html.includes('id="themeBtn"'), `${f}: 缺少主题切换按钮`);
|
||||
must(!/href="\.\.\//.test(markup), `${f}: 站内链接不应跑出本资料目录`);
|
||||
|
||||
/* ---------------- 顶栏篇章导航 ---------------- */
|
||||
const pnav = markup.match(/<nav class="partnav"[^>]*>([\s\S]*?)<\/nav>/);
|
||||
must(!!pnav, `${f}: 缺少顶栏篇章导航 .partnav`);
|
||||
if (pnav) {
|
||||
const links = (pnav[1].match(/<a [^>]*href="part-\d+\.html"/g) || []).length;
|
||||
must(links === partFiles.length, `${f}: 顶栏篇章导航有 ${links} 个篇章链接 ≠ ${partFiles.length}`);
|
||||
must(/href="index\.html"/.test(pnav[1]), `${f}: 顶栏篇章导航缺少返回学习地图的入口`);
|
||||
const onCount = (pnav[1].match(/\bclass="[^"]*\bon\b[^"]*"/g) || []).length;
|
||||
must(onCount === 1, `${f}: 顶栏篇章导航应有且只有 1 个高亮项(当前为 ${onCount} 个)`);
|
||||
if (kind === "index") {
|
||||
must(/<a class="home on" href="index\.html"/.test(pnav[1]), "index.html: 顶栏「学习地图」未高亮");
|
||||
} else if (kind === "part") {
|
||||
const no = f.slice(5, -5);
|
||||
must(new RegExp(`<a href="part-${no}\\.html" class="on"`).test(pnav[1]),
|
||||
`${f}: 顶栏未把本篇(篇 ${no})标为高亮`);
|
||||
}
|
||||
}
|
||||
|
||||
/* 代码块结构(骨架期还没有代码块,data-lang 只在有时校验) */
|
||||
const pres = markup.match(/<pre[\s\S]*?<\/pre>/g) || [];
|
||||
pres.forEach((blk, i) => {
|
||||
must(/data-lang=/.test(blk), `${f}: 第 ${i + 1} 个 <pre> 未标注 data-lang`);
|
||||
const body = blk.replace(/^<pre[^>]*>/, "").replace(/<\/pre>$/, "");
|
||||
must(!/</.test(body), `${f}: 第 ${i + 1} 个 <pre> 内有未转义的 <`);
|
||||
});
|
||||
|
||||
/* 标签配对 */
|
||||
for (const t of ["div", "section", "article", "aside", "nav", "main", "details", "table", "ul", "ol", "li"]) {
|
||||
const o = (markup.match(new RegExp("<" + t + "(?=[\\s>])", "g")) || []).length;
|
||||
const c = (markup.match(new RegExp("</" + t + ">", "g")) || []).length;
|
||||
if (o !== c) problems.push(`${f}: <${t}> 开合不匹配 ${o}/${c}`);
|
||||
}
|
||||
|
||||
/* 链接与锚点 */
|
||||
for (const l of new Set([...markup.matchAll(/href="(?!https?:|mailto:|#)([^"]+)"/g)].map((m) => m[1]))) {
|
||||
const [file, hash] = l.split("#");
|
||||
const target = path.resolve(root, file || f);
|
||||
if (file && !fs.existsSync(target)) { problems.push(`${f}: 死链 ${l}`); continue; }
|
||||
const key = file ? path.basename(file) : f;
|
||||
if (hash && idIndex.has(key) && !idIndex.get(key).has(hash)) problems.push(`${f}: 锚点不存在 ${l}`);
|
||||
}
|
||||
for (const l of new Set([...markup.matchAll(/href="#([^"]+)"/g)].map((m) => m[1]))) {
|
||||
if (!idIndex.get(f).has(l)) problems.push(`${f}: 页内锚点不存在 #${l}`);
|
||||
}
|
||||
|
||||
/* ---------------- 按页面级别检查 ---------------- */
|
||||
if (kind === "index") {
|
||||
must(/<!-- AUTO:kpis -->/.test(html), "index.html: 缺少 AUTO:kpis 区块");
|
||||
must(/<!-- AUTO:partcards -->/.test(html), "index.html: 缺少 AUTO:partcards 区块");
|
||||
must(/<!-- AUTO:prog -->/.test(html), "index.html: 缺少 AUTO:prog 区块");
|
||||
const pc = (markup.match(/class="partcard"/g) || []).length;
|
||||
must(pc === partFiles.length, `index.html: 篇章入口卡片 ${pc} 张 ≠ ${partFiles.length}`);
|
||||
must(/data-partprog/.test(markup), "index.html: 篇章卡片缺少已读进度位 data-partprog");
|
||||
const pg = markup.match(/<nav class="pager">([\s\S]*?)<\/nav>/);
|
||||
must(!!pg && /开始阅读/.test(pg[1]), "index.html: .pager 缺少「开始阅读」入口");
|
||||
must(!!pg && !/上一章|下一章|上一篇|下一篇/.test(pg[1]), "index.html: .pager 误用了翻页导航");
|
||||
must(/class="foot">\s*AI Agent 脚手架项目学习 · 共 \d+ 篇/.test(html.replace(/\n/g, "")), "index.html: 页脚不是目录页页脚");
|
||||
must(/class="hero"/.test(markup), "index.html: 缺少 .hero 站点标题区");
|
||||
}
|
||||
|
||||
if (kind === "part") {
|
||||
const no = f.slice(5, -5);
|
||||
must(/<!-- AUTO:hero -->/.test(html), `${f}: 缺少 AUTO:hero 区块`);
|
||||
must(/<!-- AUTO:cards -->/.test(html), `${f}: 缺少 AUTO:cards 区块`);
|
||||
must(/<!-- AUTO:prog -->/.test(html), `${f}: 缺少 AUTO:prog 区块`);
|
||||
must(/class="modhero"/.test(markup), `${f}: 缺少篇章导语 .modhero`);
|
||||
must(/data-chapters="[\d,]+"/.test(markup), `${f}: 缺少进度条 data-chapters`);
|
||||
|
||||
const expect = partChapters.get(f) || [];
|
||||
const cards = [...markup.matchAll(/<div class="chapcard"[^>]*>([\s\S]*?)<details/g)]
|
||||
.map((m) => (m[1].match(/href="([^"]+)"/) || [, ""])[1]);
|
||||
must(cards.length === expect.length, `${f}: 章节卡片 ${cards.length} 张 ≠ 本篇 ${expect.length} 章`);
|
||||
for (const cf of expect) {
|
||||
must(cards.includes(cf), `${f}: 章节卡片缺少 ${cf}`);
|
||||
}
|
||||
|
||||
const cn = markup.match(/<p class="chapnav">([\s\S]*?)<\/p>/);
|
||||
must(!!cn && new RegExp(`篇 <b class="pos">${no}</b>`).test(cn[1]), `${f}: 定位条不是「篇 ${no} / N」`);
|
||||
const pg = markup.match(/<nav class="pager">([\s\S]*?)<\/nav>/);
|
||||
must(!!pg && /上一篇|下一篇/.test(pg[1]), `${f}: .pager 不是篇章页的上一篇/下一篇`);
|
||||
must(!!pg && !/开始阅读/.test(pg[1]), `${f}: .pager 误用了目录页的「开始阅读」`);
|
||||
must(new RegExp(`class="foot">\\s*AI Agent 脚手架项目学习 · 篇 ${no}`).test(html.replace(/\n/g, "")),
|
||||
`${f}: 页脚不是本篇页脚`);
|
||||
}
|
||||
|
||||
if (kind === "chapter") {
|
||||
const num = parseInt(f.slice(0, 2), 10);
|
||||
const h2 = html.match(/<h2 id="([^"]+)">([\s\S]*?)<\/h2>/);
|
||||
must(!!h2, `${f}: 缺少 h2 章节标题`);
|
||||
must(html.includes('class="chapnav"'), `${f}: 缺少章节定位条 .chapnav`);
|
||||
must(html.includes('class="pager"'), `${f}: 缺少上一/下一章 .pager`);
|
||||
must(html.includes('class="foot"'), `${f}: 缺少页脚 .foot`);
|
||||
must(html.includes('href="index.html"'), `${f}: 缺少返回学习地图链接`);
|
||||
must(/class="toc-a active"[^>]*aria-current="page"/.test(html), `${f}: 当前章未标记 active`);
|
||||
|
||||
const h3 = [...html.matchAll(/<h3 id="([^"]+)">([\s\S]*?)<\/h3>/g)];
|
||||
const h3any = (html.match(/<h3[ >]/g) || []).length;
|
||||
must(h3.length === h3any, `${f}: 有 h3 未补 id(${h3.length}/${h3any})`);
|
||||
must(h3.length >= 3, `${f}: 小节过少(${h3.length}),至少 3 个`);
|
||||
for (const m of h3) {
|
||||
if (!m[1].startsWith(`sec-${num}-`)) problems.push(`${f}: 小节 id "${m[1]}" 应以 sec-${num}- 开头`);
|
||||
}
|
||||
|
||||
const pager = markup.match(/<nav class="pager">([\s\S]*?)<\/nav>/);
|
||||
must(!!pager && /上一章|下一章/.test(pager[1]), `${f}: .pager 不是章节页的上一/下一章导航`);
|
||||
must(!!pager && !/开始阅读|上一篇|下一篇/.test(pager[1]), `${f}: .pager 用了别的页面的翻页样式`);
|
||||
must(new RegExp(`class="foot">\\s*AI Agent 脚手架项目学习 · 第 ${num} 章`).test(html.replace(/\n/g, "")),
|
||||
`${f}: 页脚不是本章标题`);
|
||||
|
||||
const sub = html.match(/<div class="subnav current">([\s\S]*?)<\/div>/);
|
||||
must(!!sub, `${f}: 侧栏缺少当前章小节`);
|
||||
if (sub) {
|
||||
const n = (sub[1].match(/class="toc-a lv3"/g) || []).length;
|
||||
must(n === h3.length, `${f}: 侧栏小节数 ${n} ≠ 正文 h3 数 ${h3.length}`);
|
||||
}
|
||||
|
||||
/* 内容量(骨架期降级为提示) */
|
||||
const desc = (html.match(/<meta name="description" content="([^"]*)"/) || [, ""])[1];
|
||||
if (desc.trim().length < 20) soft(`${f}: meta description 太短或缺失(${desc.length} 字)`);
|
||||
if (!/class="box /.test(html)) soft(`${f}: 没有任何 .box 提示框`);
|
||||
if (!/class="tablewrap"/.test(html) && !/class="cards"/.test(html)) {
|
||||
soft(`${f}: 既没有表格也没有卡片组`);
|
||||
}
|
||||
if (pres.length < 2) soft(`${f}: 代码块过少(${pres.length}),至少 2 个`);
|
||||
if (bodyChars(html) < 2200) soft(`${f}: 正文过短(约 ${bodyChars(html)} 字),内容需要补充`);
|
||||
|
||||
const tbd = (html.match(/class="tbd"/g) || []).length;
|
||||
if (tbd && tbd !== h3.length) {
|
||||
soft(`${f}: ${h3.length} 个小节里有 ${tbd} 个仍标记待补充`);
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------- 侧栏目录树 ----------------
|
||||
学习地图:按篇分组列全 22 章,是唯一能看到全貌的目录。
|
||||
篇章页 / 章节页:只列本篇的章(顶栏负责跨篇跳转),并带一条范围条。 */
|
||||
const nav = markup.match(/<nav id="chapters">([\s\S]*?)<\/nav>/);
|
||||
must(!!nav, `${f}: 缺少 #chapters 目录树`);
|
||||
if (nav) {
|
||||
const rows = (nav[1].match(/class="toc-a( active)?"/g) || []).length;
|
||||
if (kind === "index") {
|
||||
must(rows === chapterFiles.length, `${f}: 目录树章节数 ${rows} ≠ ${chapterFiles.length}`);
|
||||
const groups = (nav[1].match(/class="toc-part/g) || []).length;
|
||||
must(groups === partFiles.length, `${f}: 目录树「篇」分组 ${groups} ≠ ${partFiles.length}`);
|
||||
for (const cf of chapterFiles) {
|
||||
must(nav[1].includes(`href="${cf}"`), `${f}: 目录树缺少章节 ${cf}`);
|
||||
}
|
||||
must(!/class="subnav/.test(nav[1]), `${f}: 目录页不应展开任何章的小节`);
|
||||
must(!/class="toc-scope/.test(nav[1]), `${f}: 目录页不应有本篇范围条`);
|
||||
} else {
|
||||
const expect = kind === "part" ? (partChapters.get(f) || []) : (chapterPart.get(f) || []);
|
||||
must(rows === expect.length, `${f}: 侧栏只应列本篇 ${expect.length} 章,实际 ${rows}`);
|
||||
for (const cf of expect) {
|
||||
if (cf === f) continue;
|
||||
must(nav[1].includes(`href="${cf}"`), `${f}: 侧栏缺少本篇章节 ${cf}`);
|
||||
}
|
||||
for (const cf of chapterFiles) {
|
||||
if (cf === f || expect.includes(cf)) continue;
|
||||
must(!nav[1].includes(`href="${cf}"`), `${f}: 侧栏出现了其它篇的章节 ${cf}`);
|
||||
}
|
||||
must(/class="toc-scope"/.test(nav[1]), `${f}: 侧栏缺少本篇范围条 .toc-scope`);
|
||||
must(/href="index\.html"/.test(nav[1]), `${f}: 侧栏缺少「全部篇章」入口`);
|
||||
must(!/class="toc-part/.test(nav[1]), `${f}: 侧栏不应再按篇分组`);
|
||||
}
|
||||
}
|
||||
|
||||
info.push(`${f.padEnd(26)} ~${bodyChars(html)} 字 · 代码块 ${pres.length}`);
|
||||
}
|
||||
|
||||
info.sort((a, b) => a.replace(/^○ /, "").localeCompare(b.replace(/^○ /, "")));
|
||||
console.log(info.join("\n"));
|
||||
if (problems.length) {
|
||||
console.error(`\n✗ 发现 ${problems.length} 个问题:`);
|
||||
problems.slice(0, 60).forEach((x) => console.error(" - " + x));
|
||||
process.exit(1);
|
||||
}
|
||||
console.log(`\n✓ 结构与链接全部通过(目录页 + ${partFiles.length} 个篇章页 + ${chapterFiles.length} 章,共 ${pages.length} 个页面)` +
|
||||
(ALLOW_EMPTY ? "\n○ 当前为骨架期(--allow-empty):正文、代码块、提示框与表格尚未撰写,补齐内容后请去掉该参数重跑。"
|
||||
: "\n 严格模式:内容量与组件构成均已达标。"));
|
||||
214
project/ai-agent-scafford-go/tools/gen-skeleton.js
Normal file
214
project/ai-agent-scafford-go/tools/gen-skeleton.js
Normal file
@@ -0,0 +1,214 @@
|
||||
/* ==========================================================================
|
||||
AI Agent 脚手架项目学习 · 页面骨架生成器(一次性使用)
|
||||
依据 tools/outline.json 生成 index.html、part-N.html 与 NN-slug.html 三类页面。
|
||||
只写「页面外壳 + 标题 + 占位」,顶栏导航 / 侧栏目录 / 翻页 / 页脚 / 卡片 / 进度
|
||||
全部交给 tools/build-nav.js 填充——两侧的自动区块标记保持原样,不要手改。
|
||||
用法:node tools/gen-skeleton.js
|
||||
========================================================================== */
|
||||
"use strict";
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const ROOT = path.resolve(__dirname, "..");
|
||||
const PLAN = JSON.parse(fs.readFileSync(path.join(ROOT, "tools", "outline.json"), "utf8"));
|
||||
const S = PLAN.site;
|
||||
|
||||
const PAD = (n) => String(n).padStart(2, "0");
|
||||
const CHAPS = PLAN.parts.flatMap((p) => p.chapters);
|
||||
const TOTAL = CHAPS.length;
|
||||
|
||||
const esc = (s) => String(s).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
||||
const stripNo = (t) => t.replace(/^\d+(\.\d+)*\s*/, "");
|
||||
|
||||
function head(title, desc, keywords) {
|
||||
return `<!DOCTYPE html>
|
||||
<html lang="zh-CN" data-theme="light">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>${esc(title)}</title>
|
||||
<meta name="description" content="${esc(desc)}">
|
||||
<meta name="keywords" content="${esc(keywords)}">
|
||||
<link rel="stylesheet" href="assets/doc.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<header class="topbar">
|
||||
<div class="tb-in">
|
||||
<a class="brand" href="index.html"><span class="logo">${esc(S.logo)}</span><div>${esc(S.name)}<small>${esc(S.sub)}</small></div></a>
|
||||
<nav class="partnav" id="partnav"></nav>
|
||||
<div class="spacer"></div>
|
||||
<button class="btn" id="tocToggle">☰ 导航</button>
|
||||
<button class="btn" id="themeBtn" title="切换到深色主题">深色</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="layout" id="layout">
|
||||
<aside class="sidebar">
|
||||
<h2>章节目录</h2>
|
||||
<nav id="chapters"></nav>
|
||||
<div class="side-foot">
|
||||
<a class="btn" href="index.html">← 学习地图</a>
|
||||
<a class="btn" href="${CHAPS[CHAPS.length - 1].file}">速查与自测</a>
|
||||
</div>
|
||||
</aside>
|
||||
<div class="mask" id="mask"></div>
|
||||
|
||||
<main class="main-col">
|
||||
`;
|
||||
}
|
||||
|
||||
function tail() {
|
||||
return ` </main>
|
||||
</div>
|
||||
|
||||
<button id="toTop" title="回到顶部">↑</button>
|
||||
<script src="assets/doc.js"></script>
|
||||
<script src="../../assets/back.js" data-portal-back="project/ai-agent-scafford-go" data-portal-label="工程项目 › AI Agent 脚手架项目学习(Go 智能体框架)"></script>
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
}
|
||||
|
||||
/* ---------------------------- 章节页 ---------------------------- */
|
||||
function chapterPage(part, c, num) {
|
||||
const secs = c.sections
|
||||
.map(
|
||||
(s) => ` <h3 id="${s.id}">${esc(s.title)}</h3>
|
||||
|
||||
<p class="tbd">本节正文待撰写:${esc(stripNo(s.title))}。</p>
|
||||
`
|
||||
)
|
||||
.join("\n");
|
||||
|
||||
const leadTail = c.sections
|
||||
.slice(0, 3)
|
||||
.map((s) => stripNo(s.title))
|
||||
.join("、");
|
||||
|
||||
return (
|
||||
head(`第 ${num} 章 ${c.title} · ${S.name}`, c.desc, c.keywords) +
|
||||
` <article>
|
||||
<p class="chapnav"></p>
|
||||
|
||||
<h2 id="ch${num}"><span class="n">${num}</span>${esc(c.title)}</h2>
|
||||
|
||||
<div class="lead">
|
||||
<b>这一章解决什么:</b>${esc(c.desc)}
|
||||
读完这一章,你要能用自己的话讲清 ${c.sections.length} 个知识点${leadTail ? `,例如「${esc(leadTail)}」` : ""},
|
||||
并且能指回具体文件与函数。
|
||||
</div>
|
||||
|
||||
${secs}
|
||||
<nav class="pager"></nav>
|
||||
<p class="foot"></p>
|
||||
</article>
|
||||
` +
|
||||
tail()
|
||||
);
|
||||
}
|
||||
|
||||
/* ---------------------------- 篇章页 ---------------------------- */
|
||||
function partPage(p) {
|
||||
const first = CHAPS.indexOf(p.chapters[0]) + 1;
|
||||
const last = CHAPS.indexOf(p.chapters[p.chapters.length - 1]) + 1;
|
||||
const desc = `篇 ${p.no} ${p.name}:${p.note}`;
|
||||
return (
|
||||
head(`篇 ${p.no} ${p.name} · ${S.name}`, desc, p.chapters.map((c) => c.title).join(",")) +
|
||||
` <article>
|
||||
<p class="chapnav"></p>
|
||||
<!-- AUTO:hero -->
|
||||
<!-- /AUTO:hero -->
|
||||
|
||||
<div class="toolbar">
|
||||
<div class="search"><input id="q" type="search" placeholder="在本篇内搜索章节 / 小节(按 / 聚焦)"></div>
|
||||
<button class="btn" id="expandAll">展开全部小节</button>
|
||||
<button class="btn" id="resetBtn">清空进度</button>
|
||||
<button class="btn" id="printBtn">打印</button>
|
||||
<!-- AUTO:prog -->
|
||||
<!-- /AUTO:prog -->
|
||||
</div>
|
||||
|
||||
<div id="cards">
|
||||
<!-- AUTO:cards -->
|
||||
<!-- /AUTO:cards -->
|
||||
</div>
|
||||
|
||||
<p id="noHit" style="display:none">本篇没有匹配的章节,换个关键词试试。</p>
|
||||
|
||||
<nav class="pager"></nav>
|
||||
<p class="foot"></p>
|
||||
<p class="tbd">本篇覆盖第 ${first}–${last} 章;各章正文与代码段待撰写。</p>
|
||||
</article>
|
||||
` +
|
||||
tail()
|
||||
);
|
||||
}
|
||||
|
||||
/* ---------------------------- 学习地图 ---------------------------- */
|
||||
function indexPage() {
|
||||
const secs = CHAPS.reduce((n, c) => n + c.sections.length, 0);
|
||||
return (
|
||||
head(S.title, S.desc, "AI Agent,Go,Gin,ADK,MCP,脚手架,项目学习") +
|
||||
` <article>
|
||||
<div class="hero">
|
||||
<h1>${esc(S.name)}:<em>配置驱动的 Go 智能体脚手架</em></h1>
|
||||
<p>这套脚手架用三层配置(.env / application.yaml / agent YAML)驱动一条六节点装配链,把「模型 + 工具 + 工作流」
|
||||
拼成可对话的 Agent,并通过 Gin 暴露四个业务接口。本学习站按「全景 → 前置 → 源码拆解 → 缺陷与演进 → 场景与面试 → 速查」
|
||||
六篇 ${TOTAL} 章展开,每一条结论都指回具体文件与行号。</p>
|
||||
<div class="kpis" id="kpis">
|
||||
<!-- AUTO:kpis -->
|
||||
<!-- /AUTO:kpis -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="toolbar">
|
||||
<div class="search"><input id="q" type="search" placeholder="搜索章节 / 小节(按 / 聚焦)"></div>
|
||||
<button class="btn" id="expandAll">展开全部小节</button>
|
||||
<button class="btn" id="resetBtn">清空进度</button>
|
||||
<button class="btn" id="printBtn">打印</button>
|
||||
<!-- AUTO:prog -->
|
||||
<!-- /AUTO:prog -->
|
||||
</div>
|
||||
|
||||
<section class="block" id="map">
|
||||
<h2>学习地图</h2>
|
||||
<p class="sub">六个篇章,从「能跑能演示」到「抽象成方法论」;共 ${TOTAL} 章 ${secs} 个小节。建议先读篇 0 建立地图,再按篇 2 的顺序追源码。</p>
|
||||
<div class="partgrid" id="partgrid">
|
||||
<!-- AUTO:partcards -->
|
||||
<!-- /AUTO:partcards -->
|
||||
</div>
|
||||
<p id="noHit" style="display:none">没有匹配的篇章,换个关键词试试。</p>
|
||||
</section>
|
||||
|
||||
<nav class="pager"></nav>
|
||||
<p class="foot"></p>
|
||||
</article>
|
||||
` +
|
||||
tail()
|
||||
);
|
||||
}
|
||||
|
||||
/* ---------------------------- 写盘 ---------------------------- */
|
||||
const written = [];
|
||||
|
||||
fs.writeFileSync(path.join(ROOT, "index.html"), indexPage(), "utf8");
|
||||
written.push("index.html");
|
||||
|
||||
for (const p of PLAN.parts) {
|
||||
const file = `part-${p.no}.html`;
|
||||
fs.writeFileSync(path.join(ROOT, file), partPage(p), "utf8");
|
||||
written.push(file);
|
||||
}
|
||||
|
||||
for (const c of CHAPS) {
|
||||
const num = CHAPS.indexOf(c) + 1;
|
||||
const part = PLAN.parts.find((p) => p.chapters.includes(c));
|
||||
fs.writeFileSync(path.join(ROOT, c.file), chapterPage(part, c, num), "utf8");
|
||||
written.push(c.file);
|
||||
}
|
||||
|
||||
console.log(`已生成 ${written.length} 个页面:索引 1、篇章 ${PLAN.parts.length}、章节 ${TOTAL}。`);
|
||||
console.log(`小节合计 ${CHAPS.reduce((n, c) => n + c.sections.length, 0)} 个。`);
|
||||
console.log("下一步:node tools/build-nav.js && node tools/check-pages.js --allow-empty");
|
||||
377
project/ai-agent-scafford-go/tools/outline.json
Normal file
377
project/ai-agent-scafford-go/tools/outline.json
Normal file
@@ -0,0 +1,377 @@
|
||||
{
|
||||
"site": {
|
||||
"id": "ai-agent-scaffold-go",
|
||||
"logo": "AG",
|
||||
"name": "AI Agent 脚手架项目学习",
|
||||
"title": "AI Agent 脚手架项目学习 · Go 智能体框架源码拆解",
|
||||
"sub": "Go + Agent · 源码拆解 / 装配链 / 面试模拟",
|
||||
"desc": "围绕 ai-agent-scaffold-go 这套配置驱动的 Go AI Agent 脚手架的学习站:六个篇章、二十二章,从项目全景、前置知识、源码拆解,到缺陷清单、面试追问与故障场景还原。",
|
||||
"repo": "ai-agent-scaffold-go",
|
||||
"repoUrl": "",
|
||||
"themeKey": "ai-agent-scaffold-go:theme",
|
||||
"progressKey": "ai-agent-scaffold-go:progress"
|
||||
},
|
||||
|
||||
"levels": [
|
||||
{ "id": "L1", "name": "能跑能演示", "goal": "起服务、列出 Agent、建会话、发一条消息、看到流式输出" },
|
||||
{ "id": "L2", "name": "面试级理解", "goal": "讲清三层配置、责任链装配、工具调用循环、SSE 流与 MCP 发现" },
|
||||
{ "id": "L3", "name": "抗追问能力", "goal": "答得住重名工具、会话不持久、并发安全、无鉴权与超时取舍" },
|
||||
{ "id": "L4", "name": "可独立复刻", "goal": "关掉文档复刻核心链路:配置加载、Armory 装配、Agent 运行、HTTP 层" },
|
||||
{ "id": "L5", "name": "抽象成方法论", "goal": "上升为 Agent 脚手架通用框架:配置驱动、端口适配、编排与演进" }
|
||||
],
|
||||
|
||||
"parts": [
|
||||
{
|
||||
"no": "0",
|
||||
"name": "前言 · 先建立地图",
|
||||
"note": "先确认这个脚手架到底是什么、能演示什么、按什么节奏读,再决定读到多深。",
|
||||
"chapters": [
|
||||
{
|
||||
"file": "01-overview.html",
|
||||
"title": "项目全景:这个 Agent 脚手架是什么",
|
||||
"desc": "从一句定位、功能地图、技术栈与工程规模出发,交代一次对话的完整旅程、三层装配结构,以及这个项目有意保留的短板。",
|
||||
"keywords": "AI Agent,脚手架,Go,Gin,ADK,Eino,MCP,项目概览",
|
||||
"level": "L1",
|
||||
"sections": [
|
||||
{ "id": "sec-1-1", "title": "1.1 一句话定位:它解决什么问题" },
|
||||
{ "id": "sec-1-2", "title": "1.2 功能地图:能演示的五类能力" },
|
||||
{ "id": "sec-1-3", "title": "1.3 技术栈与工程规模:先看真实数字" },
|
||||
{ "id": "sec-1-4", "title": "1.4 一次对话的完整旅程" },
|
||||
{ "id": "sec-1-5", "title": "1.5 三层装配:配置、Armory、运行时" },
|
||||
{ "id": "sec-1-6", "title": "1.6 这个项目的边界:已知短板与刻意取舍" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "02-roadmap.html",
|
||||
"title": "学习路线:五级目标、阅读节奏与产出",
|
||||
"desc": "把项目学习拆成五级目标与三种节奏,给出每一级的达标标准、证明方式,以及学完之后应该拿得出的产出清单。",
|
||||
"keywords": "学习路线,项目学习,节奏表,成熟度,产出清单",
|
||||
"level": "L1",
|
||||
"sections": [
|
||||
{ "id": "sec-2-1", "title": "2.1 五级目标:从能跑能演示到方法论" },
|
||||
{ "id": "sec-2-2", "title": "2.2 每一级的达标标准与证明方式" },
|
||||
{ "id": "sec-2-3", "title": "2.3 三种节奏:半天、三天与一周" },
|
||||
{ "id": "sec-2-4", "title": "2.4 目录地图:先看哪几个文件" },
|
||||
{ "id": "sec-2-5", "title": "2.5 三份事实源:源码、完善报告、待实现清单" },
|
||||
{ "id": "sec-2-6", "title": "2.6 先把项目跑起来:最小启动路径" }
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"no": "1",
|
||||
"name": "知识学习 · 补齐前置",
|
||||
"note": "读源码之前先把会用到的语言、Web 与 Agent 协议基础补齐,避免边读边查。",
|
||||
"chapters": [
|
||||
{
|
||||
"file": "03-basics-go.html",
|
||||
"title": "Go 与 Web 基础:Gin、YAML、SSE 与泛型",
|
||||
"desc": "只讲这个项目真正用到的部分:Gin 的请求生命周期、结构体标签与 YAML 映射、依赖倒置、四个并发原语、SSE 与泛型。",
|
||||
"keywords": "Go,Gin,YAML,接口,并发,SSE,泛型",
|
||||
"level": "L1",
|
||||
"sections": [
|
||||
{ "id": "sec-3-1", "title": "3.1 一个 HTTP 请求在 Gin 里的生命周期" },
|
||||
{ "id": "sec-3-2", "title": "3.2 结构体标签与 YAML 映射" },
|
||||
{ "id": "sec-3-3", "title": "3.3 接口与依赖倒置:端口-适配器" },
|
||||
{ "id": "sec-3-4", "title": "3.4 四个并发原语:goroutine、channel、atomic、sync" },
|
||||
{ "id": "sec-3-5", "title": "3.5 SSE:服务端单向推送怎么工作" },
|
||||
{ "id": "sec-3-6", "title": "3.6 泛型:Handler 与响应信封里的类型参数" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "04-basics-agent.html",
|
||||
"title": "AI Agent 前置:模型协议、工具调用与 MCP",
|
||||
"desc": "把 Chat Completions、Function Calling、MCP、Skill 这四件事讲到能直接对上代码的程度,重点讲清一轮工具调用的闭环。",
|
||||
"keywords": "LLM,Chat Completions,Function Calling,MCP,JSON-RPC,Skill,流式",
|
||||
"level": "L1",
|
||||
"sections": [
|
||||
{ "id": "sec-4-1", "title": "4.1 Chat Completions 协议:消息角色与字段" },
|
||||
{ "id": "sec-4-2", "title": "4.2 工具调用闭环:模型说要用什么,谁来执行" },
|
||||
{ "id": "sec-4-3", "title": "4.3 MCP:一个标准化的工具协议" },
|
||||
{ "id": "sec-4-4", "title": "4.4 MCP 的 SSE 传输与 JSON-RPC 2.0" },
|
||||
{ "id": "sec-4-5", "title": "4.5 Skill:把长提示词拆成可复用目录" },
|
||||
{ "id": "sec-4-6", "title": "4.6 流式输出与增量拼接的两个难点" }
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"no": "2",
|
||||
"name": "项目拆解 · 追源码",
|
||||
"note": "本站主体:按「配置 → 装配 → 运行时 → 接口 → 前端 → 部署」的顺序把源码读完,每个模块都落到文件、函数与结构体。",
|
||||
"chapters": [
|
||||
{
|
||||
"file": "05-bootstrap.html",
|
||||
"title": "启动与装配:main → bootstrap → Gin",
|
||||
"desc": "从 main.go 的六个步骤到 bootstrap.Build 的手工装配清单,解释这个项目为什么没有 DI 容器,以及中间件与启动失败的排查顺序。",
|
||||
"keywords": "main,bootstrap,依赖注入,Gin,中间件,CORS",
|
||||
"level": "L2",
|
||||
"sections": [
|
||||
{ "id": "sec-5-1", "title": "5.1 main.go 的六个步骤" },
|
||||
{ "id": "sec-5-2", "title": "5.2 bootstrap.Build 的手工装配清单" },
|
||||
{ "id": "sec-5-3", "title": "5.3 为什么不用 DI 容器" },
|
||||
{ "id": "sec-5-4", "title": "5.4 路由、中间件与 CORS" },
|
||||
{ "id": "sec-5-5", "title": "5.5 启动失败的五个常见原因" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "06-config.html",
|
||||
"title": "配置体系:三层配置怎么生效",
|
||||
"desc": "讲清 .env、application.yaml、agent YAML 三层的优先级,${VAR:-default} 展开的实现细节,默认值注入与校验规则,以及配置层的已知缺口。",
|
||||
"keywords": "配置,dotenv,application.yaml,环境变量,校验,默认值",
|
||||
"level": "L2",
|
||||
"sections": [
|
||||
{ "id": "sec-6-1", "title": "6.1 三层优先级:.env、application.yaml、agent YAML" },
|
||||
{ "id": "sec-6-2", "title": "6.2 ${VAR:-default} 展开的实现细节" },
|
||||
{ "id": "sec-6-3", "title": "6.3 默认值注入与校验规则" },
|
||||
{ "id": "sec-6-4", "title": "6.4 为什么 application.yaml 不做变量替换" },
|
||||
{ "id": "sec-6-5", "title": "6.5 多文件 agent 表的合并逻辑" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "07-domain-ports.html",
|
||||
"title": "领域模型与端口:接口清单",
|
||||
"desc": "逐个过 model 包的结构体与 ports 包的九个接口,说明内存实现为什么够用、端口设计有哪些取舍,以及领域层为什么不含 HTTP。",
|
||||
"keywords": "领域模型,端口,ports,接口,内存实现,六边形",
|
||||
"level": "L2",
|
||||
"sections": [
|
||||
{ "id": "sec-7-1", "title": "7.1 model 包:配置结构与命令对象" },
|
||||
{ "id": "sec-7-2", "title": "7.2 ports 包:九个接口与各自职责" },
|
||||
{ "id": "sec-7-3", "title": "7.3 内存实现:Registry 与 SessionStore" },
|
||||
{ "id": "sec-7-4", "title": "7.4 端口设计的取舍:为什么 ModelAPI 是空接口" },
|
||||
{ "id": "sec-7-5", "title": "7.5 领域层为什么不含 HTTP 与数据库" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "08-armory.html",
|
||||
"title": "Armory 装配链:责任链把 YAML 变成 Agent",
|
||||
"desc": "拆解 Root → AiAPI → ChatModel → Agent → AgentWorkflow → Runner 六节点责任链,讲清 DynamicContext 的职责与一次装配的完整轨迹。",
|
||||
"keywords": "Armory,责任链,泛型,装配,DynamicContext,注册表",
|
||||
"level": "L2",
|
||||
"sections": [
|
||||
{ "id": "sec-8-1", "title": "8.1 责任链模式与泛型 Handler" },
|
||||
{ "id": "sec-8-2", "title": "8.2 六个节点的职责与顺序" },
|
||||
{ "id": "sec-8-3", "title": "8.3 DynamicContext:一次装配的上下文" },
|
||||
{ "id": "sec-8-4", "title": "8.4 从 YAML 表到注册表的完整轨迹" },
|
||||
{ "id": "sec-8-5", "title": "8.5 递归改循环:一条待实现的改造" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "09-workflow.html",
|
||||
"title": "工作流编排:sequential / parallel / loop",
|
||||
"desc": "讲清三种工作流的配置写法、顺序执行的变量作用域与 {output-key} 模板替换,并如实交代并行与循环目前的真实行为。",
|
||||
"keywords": "工作流,sequential,parallel,loop,模板替换,子 Agent",
|
||||
"level": "L2",
|
||||
"sections": [
|
||||
{ "id": "sec-9-1", "title": "9.1 三种工作流的 YAML 写法" },
|
||||
{ "id": "sec-9-2", "title": "9.2 顺序执行与 scope 变量传递" },
|
||||
{ "id": "sec-9-3", "title": "9.3 {output-key} 模板替换" },
|
||||
{ "id": "sec-9-4", "title": "9.4 并行与循环的真实现状" },
|
||||
{ "id": "sec-9-5", "title": "9.5 子 Agent 名称解析与装配顺序的坑" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "10-runtime.html",
|
||||
"title": "Agent 运行时:工具调用循环与流式",
|
||||
"desc": "拆 runLLM 的四步循环与 streamLLM 的 Done 语义,讲清 Runner 的会话、插件生命周期,以及会话 ID 生成方式的缺陷。",
|
||||
"keywords": "Agent运行时,工具调用循环,流式,Runner,插件,会话",
|
||||
"level": "L3",
|
||||
"sections": [
|
||||
{ "id": "sec-10-1", "title": "10.1 ADK 包在这里承担什么" },
|
||||
{ "id": "sec-10-2", "title": "10.2 runLLM:四步循环怎么收敛" },
|
||||
{ "id": "sec-10-3", "title": "10.3 streamLLM 与 Done 语义" },
|
||||
{ "id": "sec-10-4", "title": "10.4 Runner:会话、插件与生命周期" },
|
||||
{ "id": "sec-10-5", "title": "10.5 会话 ID 的生成方式与缺陷" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "11-model-client.html",
|
||||
"title": "模型层:OpenAI 兼容客户端",
|
||||
"desc": "从请求体构造、消息编码、工具 schema 的简化,到 SSE 增量解析与 tool_call 分片拼接,再到超时与错误处理的缺口。",
|
||||
"keywords": "OpenAI,chat completions,SSE,流式,tool_calls,超时",
|
||||
"level": "L3",
|
||||
"sections": [
|
||||
{ "id": "sec-11-1", "title": "11.1 请求体构造与消息编码" },
|
||||
{ "id": "sec-11-2", "title": "11.2 工具 schema 的简化:只有 query 参数" },
|
||||
{ "id": "sec-11-3", "title": "11.3 SSE 流解析与 tool_call 拼接" },
|
||||
{ "id": "sec-11-4", "title": "11.4 超时、错误处理与重试缺口" },
|
||||
{ "id": "sec-11-5", "title": "11.5 为什么叫 Eino 适配器却不是 Eino" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "12-mcp.html",
|
||||
"title": "MCP 工具:SSE 客户端与全局路由",
|
||||
"desc": "讲清 GET /sse 建连、endpoint 事件、JSON-RPC 请求-响应匹配与 tools/list 自动发现,并复现全局 router 下同名工具冲突的故障。",
|
||||
"keywords": "MCP,SSE,JSON-RPC,tools/list,工具路由,发现",
|
||||
"level": "L3",
|
||||
"sections": [
|
||||
{ "id": "sec-12-1", "title": "12.1 连接建立:GET /sse 与 endpoint 事件" },
|
||||
{ "id": "sec-12-2", "title": "12.2 JSON-RPC 请求-响应匹配" },
|
||||
{ "id": "sec-12-3", "title": "12.3 tools/list 自动发现与展开" },
|
||||
{ "id": "sec-12-4", "title": "12.4 全局 router 与同名工具的冲突" },
|
||||
{ "id": "sec-12-5", "title": "12.5 stdio 与 local:配置能写、运行不通" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "13-skills.html",
|
||||
"title": "Skill 机制:SKILL.md 扫描与命名",
|
||||
"desc": "讲清技能目录约定、front matter 解析、相对路径的四类候选解析与工具命名规则,并说明技能目前只出现在工具列表里这件事。",
|
||||
"keywords": "Skill,SKILL.md,front matter,路径解析,工具命名",
|
||||
"level": "L2",
|
||||
"sections": [
|
||||
{ "id": "sec-13-1", "title": "13.1 目录约定与 front matter" },
|
||||
{ "id": "sec-13-2", "title": "13.2 路径解析的四类候选" },
|
||||
{ "id": "sec-13-3", "title": "13.3 工具命名、清洗与冲突" },
|
||||
{ "id": "sec-13-4", "title": "13.4 技能在对话中的真实作用" },
|
||||
{ "id": "sec-13-5", "title": "13.5 与 MCP 工具的分工" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "14-http-api.html",
|
||||
"title": "HTTP 接口层:五个端点",
|
||||
"desc": "过一遍路由注册、统一响应信封与错误码、四个业务接口的请求响应、SSE 流式写法,以及这一层最要命的安全缺口。",
|
||||
"keywords": "HTTP,API,Gin,响应信封,错误码,SSE,鉴权",
|
||||
"level": "L2",
|
||||
"sections": [
|
||||
{ "id": "sec-14-1", "title": "14.1 路由注册与分组" },
|
||||
{ "id": "sec-14-2", "title": "14.2 统一响应信封与错误码" },
|
||||
{ "id": "sec-14-3", "title": "14.3 四个业务接口的请求与响应" },
|
||||
{ "id": "sec-14-4", "title": "14.4 SSE 流式接口的实现与局限" },
|
||||
{ "id": "sec-14-5", "title": "14.5 安全缺口:没有鉴权与租户隔离" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "15-frontend.html",
|
||||
"title": "前端:Next.js + draw.io 交互绘图",
|
||||
"desc": "从前端三栏布局与会话持久化,到画布上下文注入、XML 识别与后端交互时序,最后列出前端的已知问题。",
|
||||
"keywords": "前端,Next.js,draw.io,会话,localStorage,上下文注入",
|
||||
"level": "L2",
|
||||
"sections": [
|
||||
{ "id": "sec-15-1", "title": "15.1 三栏布局:历史、画布、对话" },
|
||||
{ "id": "sec-15-2", "title": "15.2 会话模型与 localStorage 持久化" },
|
||||
{ "id": "sec-15-3", "title": "15.3 画布上下文注入与 XML 识别" },
|
||||
{ "id": "sec-15-4", "title": "15.4 与后端的完整交互时序" },
|
||||
{ "id": "sec-15-5", "title": "15.5 前端的已知问题与改进点" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "16-infra-deploy.html",
|
||||
"title": "基础设施与部署",
|
||||
"desc": "交代 MySQL / Redis 适配器与未接线的现状、Compose 的端口与依赖、日志与探针,最后给一份从脚手架到服务的生产化清单。",
|
||||
"keywords": "MySQL,Redis,Docker Compose,日志,探针,部署",
|
||||
"level": "L2",
|
||||
"sections": [
|
||||
{ "id": "sec-16-1", "title": "16.1 MySQL / Redis 适配器与未接线现状" },
|
||||
{ "id": "sec-16-2", "title": "16.2 docker compose:端口与依赖" },
|
||||
{ "id": "sec-16-3", "title": "16.3 日志、探针与启动参数" },
|
||||
{ "id": "sec-16-4", "title": "16.4 生产化清单:从脚手架到服务" }
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"no": "3",
|
||||
"name": "缺陷与演进",
|
||||
"note": "把项目完善报告里的缺陷按级别读一遍,再给出可验收的改造顺序与扩展姿势。",
|
||||
"chapters": [
|
||||
{
|
||||
"file": "17-defects-p0.html",
|
||||
"title": "缺陷清单:P0 级问题逐条拆",
|
||||
"desc": "按装配期、运行期、安全三类拆开 P0 缺陷:重名 MCP 导致占位工具、会话不持久、并发安全、无鉴权与明文密钥,并给出复现步骤。",
|
||||
"keywords": "缺陷,P0,重名工具,并发安全,鉴权,复现",
|
||||
"level": "L3",
|
||||
"sections": [
|
||||
{ "id": "sec-17-1", "title": "17.1 缺陷分级方法与资料来源" },
|
||||
{ "id": "sec-17-2", "title": "17.2 装配期:重名 MCP 与占位工具" },
|
||||
{ "id": "sec-17-3", "title": "17.3 运行期:会话不持久与并发安全" },
|
||||
{ "id": "sec-17-4", "title": "17.4 安全:无鉴权、Key 明文与 CORS 全开" },
|
||||
{ "id": "sec-17-5", "title": "17.5 复现步骤与验证方式" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "18-defects-p1.html",
|
||||
"title": "P1 / P2 问题与工程化改造",
|
||||
"desc": "把 P1 的正确性与健壮性问题、P2 的可维护性与扩展性问题分层列出,给出改造顺序、收益判断与一份可验收修复方案的结构。",
|
||||
"keywords": "P1,P2,健壮性,可维护性,改造顺序,验收",
|
||||
"level": "L3",
|
||||
"sections": [
|
||||
{ "id": "sec-18-1", "title": "18.1 P1:正确性与健壮性" },
|
||||
{ "id": "sec-18-2", "title": "18.2 P2:可维护性与扩展性" },
|
||||
{ "id": "sec-18-3", "title": "18.3 建议的改造顺序与收益" },
|
||||
{ "id": "sec-18-4", "title": "18.4 怎么写一份可验收的修复方案" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "19-extension.html",
|
||||
"title": "扩展指南:加 Agent、工具与插件",
|
||||
"desc": "六种最常见的扩展动作:只改 YAML 加 Agent、接新 MCP 服务、写本地工具、写 RunnerPlugin、加工作流类型、加 HTTP 端点。",
|
||||
"keywords": "扩展,新增Agent,MCP,本地工具,插件,工作流,端点",
|
||||
"level": "L4",
|
||||
"sections": [
|
||||
{ "id": "sec-19-1", "title": "19.1 只改 YAML 加一个 Agent" },
|
||||
{ "id": "sec-19-2", "title": "19.2 接入一个新的 MCP 服务" },
|
||||
{ "id": "sec-19-3", "title": "19.3 写一个本地工具与路由" },
|
||||
{ "id": "sec-19-4", "title": "19.4 写一个 RunnerPlugin" },
|
||||
{ "id": "sec-19-5", "title": "19.5 新增一种工作流类型" },
|
||||
{ "id": "sec-19-6", "title": "19.6 新增一个 HTTP 端点" }
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"no": "4",
|
||||
"name": "场景还原 · 端到端",
|
||||
"note": "把前面读到的碎片串成三条链路,再逐个制造故障看系统怎么表现,最后练表达。",
|
||||
"chapters": [
|
||||
{
|
||||
"file": "20-flows.html",
|
||||
"title": "三条核心链路的端到端还原",
|
||||
"desc": "从 YAML 到可对话 Agent、一次带工具调用的对话、一段流式输出的字节流,三条链路逐跳走过,并给出三类故障现场。",
|
||||
"keywords": "端到端,链路,工具调用,流式,故障,排查",
|
||||
"level": "L3",
|
||||
"sections": [
|
||||
{ "id": "sec-20-1", "title": "20.1 链路一:YAML 到可对话 Agent" },
|
||||
{ "id": "sec-20-2", "title": "20.2 链路二:一次带工具调用的对话" },
|
||||
{ "id": "sec-20-3", "title": "20.3 链路三:流式输出的字节流" },
|
||||
{ "id": "sec-20-4", "title": "20.4 故障现场:启动失败、工具 404、流中断" },
|
||||
{ "id": "sec-20-5", "title": "20.5 用日志把链路串起来" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "21-interview.html",
|
||||
"title": "面试模拟:把项目讲出来",
|
||||
"desc": "30 秒与 3 分钟两个讲述版本、十五个高频追问、主动抛出深水区的技巧、与 LangChain / Dify 的横向对比,以及配套题库怎么用。",
|
||||
"keywords": "面试,项目讲述,追问,横向对比,题库",
|
||||
"level": "L3",
|
||||
"sections": [
|
||||
{ "id": "sec-21-1", "title": "21.1 30 秒版本与 3 分钟版本" },
|
||||
{ "id": "sec-21-2", "title": "21.2 高频追问十五问" },
|
||||
{ "id": "sec-21-3", "title": "21.3 追问引导:主动抛出深水区" },
|
||||
{ "id": "sec-21-4", "title": "21.4 横向对比:脚手架与 LangChain / Dify" },
|
||||
{ "id": "sec-21-5", "title": "21.5 配套题库:289 道题怎么用" }
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"no": "5",
|
||||
"name": "收尾 · 速查与自测",
|
||||
"note": "所有需要背下来的常量级事实集中在这里,配一份自测清单。",
|
||||
"chapters": [
|
||||
{
|
||||
"file": "22-cheatsheet.html",
|
||||
"title": "速查与自测",
|
||||
"desc": "接口、配置项、代码地图三张速查表,加一份二十题的自测清单,用来在面试前半小时快速过一遍。",
|
||||
"keywords": "速查,接口,配置,代码地图,自测",
|
||||
"level": "L4",
|
||||
"sections": [
|
||||
{ "id": "sec-22-1", "title": "22.1 接口速查:五个端点" },
|
||||
{ "id": "sec-22-2", "title": "22.2 配置项速查" },
|
||||
{ "id": "sec-22-3", "title": "22.3 代码地图:文件到职责" },
|
||||
{ "id": "sec-22-4", "title": "22.4 自测二十题" }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user