Skip to content

feat(ui-plugins): add Help Center Builder (help-center-builder) - #248

Open
ppppp2005-p wants to merge 11 commits into
zai-org:mainfrom
ppppp2005-p:feat/help-center-builder
Open

ppppp2005-p wants to merge 11 commits into
zai-org:mainfrom
ppppp2005-p:feat/help-center-builder

Conversation

@ppppp2005-p

Copy link
Copy Markdown

Plugin type (required) / 插件类型(必填)

  • UI Plugin / 是 UI 插件 — provides MCP Apps interactive pages / 提供 MCP Apps 交互页面
  • Standard plugin / 普通插件(非 UI)
  • Not applicable / 不适用

Affected plugin name(s) / 涉及的插件名称:help-center-builder (UI Plugin, new)

What / 改动内容

New community UI plugin Help Center Builder / 帮助中心制作: a folder of Markdown / HTML docs becomes a static help center with category navigation, breadcrumbs, a table of contents, related articles and offline full-text search (CJK too). Incremental builds rewrite only the affected pages and list them with the reason.

Tools:

  • hc_scan (read-only), hc_build.
  • App-only: hc_preview, hc_state.

How it works:

  • Parsing (src/docs.ts):
    • Front matter via yaml; Markdown via marked (GFM, tables wrapped).
    • Heading ids: Unicode-aware slugs, de-duplicated.
    • Title: front matter, else a leading # / ## / setext heading, else the file name (with a warning).
    • HTML inputs: <main> / <article> / <body>, minus nav, header, footer and the first h1; meta description and tags are read.
    • Sanitising strips script / iframe / object / embed, on*= and javascript: (author-content clean-up, reported as info).
    • Links are resolved relative to each file: doc, asset, anchor or external.
  • Model (src/site.ts):
    • Categories come from the first folder, a front matter category, or help-center.json, which also sets names, descriptions and order. Root files go to “General”; index.md is the category or home intro.
    • Articles are sorted by order, then title. Prev / next stay within the category.
    • Related articles: explicit related first, then scored by shared tags ×3, same category ×1 and title / heading word overlap ×0.5 (threshold 2, at most 5).
    • Templates: home (hero search plus cards), category, article (crumbs, sidebar, TOC, related, prev / next), search, 404 (absolute URLs from baseUrl, else /). Every other page uses relative URLs, so file:// and sub-paths work.
    • Also: sitemap and canonical links with baseUrl; English / Chinese UI strings, auto-detected; light / dark responsive CSS.
  • Search:
    • MiniSearch index built in Node with the same tokenize.js the browser loads (Latin words, plus CJK single characters and bigrams).
    • Written to search-index.js (window.HC_SEARCH) so it also works from file://. The MiniSearch UMD build (MIT) is copied into assets/.
    • Browser side: AND, falling back to OR; title / tags / headings boosts; prefix and fuzzy matching; highlighting; keyboard navigation; results page.
  • Incremental build:
    • Each page plan has dependency parts: article {content, nav, category, cats, related, prevnext, site, tpl}; category {list, intro, category, cats, site, tpl}; home {list, intro, cats, site, tpl}.
    • Parts are hashed and compared with .help-center/builds.json. A page is rewritten only when a part changed or the file is missing, and the changed parts are reported as reasons.
    • Assets, runtime files, search-index.js and the sitemap are hash-compared. Outputs of deleted docs are removed (only files recorded in the manifest).
    • The output folder may sit inside the docs folder (excluded from scanning); docs inside the output folder are rejected.
  • Checks: broken doc and asset links, missing anchors (ids and name= in raw HTML), links outside the docs folder, output conflicts (a.md + a.html → error, nothing written), missing or duplicate titles, empty articles, unknown related, drafts, empty configured categories.

Panel:

  • Docs folder picker, output folder, title; Build / Build changes / Full rebuild.
  • Summary banner.
  • “Pages rewritten this time” with reason chips; checks list.
  • Clickable site map, with a static preview iframe (CSS inlined, scripts removed, images inlined).

Network / API / side effects: none, and no API keys. Writes the output folder and .help-center/builds.json. No hooks. The generated site is fully self-contained.

Testing:

  • vitest (7 tests):
    • Parsing (front matter, ids, links, HTML clean-up, ## and setext titles, CJK slugs) and the tokenizer.
    • Full build of the fictional Harbor Bikes help center: 15 articles, 5 categories, 23 pages. Checked: crumbs, sidebar, prev / next, canonical, explicit related first, .md → .html, image copy, table wrap, TOC, sitemap (21 URLs), 404 base, and search ranking with the real MiniSearch.
    • Incremental builds:
      • No change → 0 pages.
      • Body edit → exactly 1 page (content) plus the search index.
      • Title change → exactly 7 pages with the right reasons.
      • New / removed article; missing file → 1 page; accent → all pages (site); full.
    • Broken link, anchor and asset; draft; conflict; out == docs rejected; out inside docs not rescanned.
    • Chinese site: zh-CN UI, Unicode paths, CJK search.
    • Real ripgrep docs (GUIDE / FAQ / README): titles from ## / setext headings; HTML name= anchors resolve; the 2 real broken CHANGELOG.md links are reported.
  • Chrome e2e:
    • Panel: build; site map plus preview; edit a title → “7 rewritten, 16 unchanged” with reason chips.
    • Built site over HTTP (nosniff): search dropdown, ArrowDown + Enter navigation, crumbs, TOC anchor, active sidebar item, next link, image loaded, search page, no horizontal scroll at 390 px, no console errors or failed requests (apart from favicon).
    • Chinese site opened from file://: “退款” finds and highlights the right article; related link works.

A ZCode Desktop demo recording is attached in the comments. / ZCode 桌面版演示录屏见评论。

Self-check / 自查清单

  • Plugin name is unique kebab-case; new external plugin directory is external_plugins/<name>/
  • Usage category is set (productivity)
  • Plugin type and affected names are declared above
  • version 0.1.0 in both plugin.json and marketplace.json
  • README.md (EN) and README_CN.md (中文) both provided and equivalent
  • description_i18n has both en and zh-CN
  • No secrets, machine-specific paths, or private dependencies
  • Model/API/network dependencies documented
  • python3 scripts/validate.py and python3 scripts/build_dist.py pass locally
  • Exercised in ZCode Desktop (ZCode 4.0.0, macOS arm64: installed from a local marketplace, asked it to scan help/harbor and build a static help center; the agent ran hc_scan (15 articles, 5 categories, 1 notice) → hc_build: 23 pages in help-center/, no broken links; demo video in the comments)

@ppppp2005-p

Copy link
Copy Markdown
Author

ZCode desktop demo (ZCode 4.0.0, macOS arm64)

help-center-builder-demo.mp4

Flow shown:

  1. Installed help-center-builder from a local marketplace built from this PR's branch.
  2. Asked ZCode to turn the help/harbor docs into a static help-center site: scan first, then build, and report the page count, issues and output folder.
  3. The agent called hc_scan: 15 articles in 5 categories (Getting started, Rentals & bookings, Billing & payments, Bikes & safety, Your account) and 1 notice: an onclick= attribute in account/contact-support.html is stripped because help articles don't run scripts.
  4. hc_build wrote help-center/: 23 pages (15 articles, 5 category pages, home, 404, sitemap and others) plus 6 assets, in 131 ms, with no broken links. The side panel shows the green build result, the list of rewritten pages (all marked 新页面) and the check section. The last card is the final state.

演示流程:本地 marketplace 安装 → hc_scan 扫描(15 篇文章、5 个分类、1 处提示)→ hc_build 生成 23 个页面的静态帮助中心,无坏链;面板显示构建结果和重写页面列表。

@panda920

Copy link
Copy Markdown
Collaborator

✅ Internal validation passed. A ZCode maintainer will review the change next; after acceptance, release checks run separately and this PR is closed automatically.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants