Skip to content

feat(ui-plugins): add Offline Site Packer (offline-site-packer) - #244

Open
ppppp2005-p wants to merge 10 commits into
zai-org:mainfrom
ppppp2005-p:feat/offline-site-packer
Open

ppppp2005-p wants to merge 10 commits into
zai-org:mainfrom
ppppp2005-p:feat/offline-site-packer

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) / 涉及的插件名称:offline-site-packer (UI Plugin, new)

What / 改动内容

New community UI plugin Offline Site Packer / 网站离线打包: a built static site becomes an offline copy that works from file://, with offline full-text search and a link report.

Tools:

  • site_check: crawl only; writes nothing.
  • site_pack: writes <site>-offline/ and a .zip.
  • App-only: site_state, site_dirs.

How it works:

  • Crawl: BFS from index.html over a/area/iframe (pages) and link/script/img/source/video/audio (src, href, srcset, poster, data-src), inline style and <style>, and CSS url() / @import (CSS files are crawled too). Script bodies and comments are left untouched.
  • Link resolution:
    • Root-relative and relative paths; ?query is dropped and #hash kept.
    • dir/ resolves to dir/index.html; x resolves to x, then x.html, then x/index.html.
    • With baseUrl, absolute URLs on the same origin and path are treated as internal.
    • mailto / tel / javascript / data links are skipped. Paths escaping the site root are reported as broken.
  • Output:
    • Only used files are written (includeUnlinked adds the rest). <base href> is removed with a warning.
    • Orphan pages and unused files are listed, and fetch() / XHR in JS files triggers a warning.
    • A marker file means an existing output folder is replaced only if this plugin created it. The output must be outside the source.
  • Search:
    • A MiniSearch index (title boost 3, prefix, fuzzy 0.2) is written as _offline/search-index.js, together with the MiniSearch UMD build and a small vanilla widget (button, ⌘K / Ctrl+K and /, keyboard navigation, highlighted snippets, zh/en labels).
    • The widget is injected into every page with relative paths.

Panel:

  • Folder picker, output folder, public URL and options.
  • Check only / Pack buttons.
  • Stats: pages, assets, rewritten links, broken links, external links, size.
  • Broken links table, external links with page counts, orphans, unused files, warnings and a page list.

Network / API / side effects: none. No API keys. Writes the output folder, the zip and .offline-site-packer/last.json. No hooks.

Third-party: minisearch (MIT; also shipped inside the offline output), fflate (MIT), MCP SDK / ext-apps (MIT), zod (MIT).

Tests: the sample is a fictional "Lumen Lamp — Docs" site generated by samples/site/make-site.mjs. It has root-relative assets, pretty and extension-less URLs, CSS @import + url(), srcset and a same-site absolute URL. The planted problems are 1 broken link, 1 missing image, 3 external links + mailto, 1 orphan page and 1 unused image.

  • vitest:
    • resolveRef cases: pretty and extension-less URLs, hash, query, percent-encoding, baseUrl with a path, protocol-relative URLs, path escape, and skipped schemes.
    • A check-only run writes nothing.
    • The pack run:
      • Finds exactly the 7 linked pages, the expected broken and external links, the orphan and the unused file.
      • Produces relative links in nested pages, srcset, anchors and the baseUrl link, plus CSS @import / url().
      • Leaves out unused files.
      • Produces a search index loadable by MiniSearch.loadJSON that returns the right pages.
      • Writes a zip with the top folder and without the marker.
    • includeUnlinked and search: false; the fetch() warning; refusal to overwrite a folder the plugin did not create; output inside the source; a folder without index.html.
  • Chrome e2e (official AppBridge host):
    1. The user checks the site (2 broken links shown, nothing written), then packs it.
    2. The packed site is opened directly via file://. The @import'ed CSS colours apply, the srcset and background images load, and navigation across pretty URLs works.
    3. Ctrl+K → "colour temperature" → clicking the Scenes result opens the nested page.
    4. There are no script errors, and the panel has no console errors.
  • validate.py, build_dist.py, git diff --check and tsc pass.

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, installed from a local marketplace, site_check on lumen-site → panel → 2 broken links (page + image), 1 orphan page, 1 unused asset → site_pack: lumen-site-offline/ with offline full-text search (7 pages, 99 links rewritten) + zip; demo video in the comments; demo video in the comments)

@ppppp2005-p

Copy link
Copy Markdown
Author

ZCode desktop demo (ZCode 4.0.0, macOS arm64)

offline-site-packer-demo.mp4

Flow shown:

  1. Installed offline-site-packer from a local marketplace built from this PR's branch.
  2. Asked ZCode to check the lumen-site folder (a small static docs site) for broken links, missing images and orphan pages, then pack it into a version that opens offline with built-in search.
  3. The agent called site_check, which opened the side panel (site folder, output folder, optional live URL, search / zip / include-unlinked options, and stat cards). Issues found: a link from guide/pairing.html to /guide/firmware that doesn't exist, a missing /img/missing-diagram.png on guide/scenes/, the orphan page old/press-kit.html, an unused img/unused-draft.png, and 4 external links.
  4. site_pack wrote lumen-site-offline/ (7 pages, 15 assets, 99 links rewritten to relative paths, a ⌘K / Ctrl+K full-text search in _offline/) and lumen-site-offline.zip (0.11 MB). The agent asked about the two judgement calls: the site's live URL (to turn absolute self-links into local ones) and whether to include the orphan page. The last card shows the panel after packing.

演示流程:本地 marketplace 安装 → site_check 打开面板,列出 2 个坏链、1 个孤立页面、1 个未用图片 → site_pack 生成带站内搜索的离线版和 zip(7 页,改写 99 个链接)。

@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