diff --git a/10-prd/behavior/rules-and-invariants.md b/10-prd/behavior/rules-and-invariants.md index 2b058ba..a224789 100644 --- a/10-prd/behavior/rules-and-invariants.md +++ b/10-prd/behavior/rules-and-invariants.md @@ -30,6 +30,10 @@ - violation impact: extensions could bypass durable product contracts. - linked claim(s): collect external information into reusable units; expose info-base information for retrieval and downstream use +## 自部署者可以从发布者仓库添加插件 + +部署者可通过发布者仓库发现并安装支持的插件。First-party 与社区插件使用相同的安装路径。用户决定各 Peer 的精确版本,并可在插件发布者提供的仓库中查看对应版本的说明。 + ## Resolver interpretation and storage retrieval remain distinct - rationale: resolver interpretation may combine hydrated block content with local relations, while storage only turns the block's opaque pointer into actual bytes. diff --git a/20-product-tdd/cross-unit-contracts.md b/20-product-tdd/cross-unit-contracts.md index 985f861..47c4534 100644 --- a/20-product-tdd/cross-unit-contracts.md +++ b/20-product-tdd/cross-unit-contracts.md @@ -27,15 +27,11 @@ Record durable data and behavior contracts that span more than one unit reposito ## Extension State Contract -[Extension 分发发布与 Peer 参与契约](extension-release-and-installation.md)拥有独立原生发布坐标、部署共享业务状态、Peer 精确安装选择,以及启用意图和实际运行的区别。插件拥有业务与数据兼容,各 Unit 分别拥有构建发布流程和宿主执行边界。 +[Extension 分发发布与 Peer 参与契约](extension-release-and-installation.md)拥有仓库发行的发现与读取、独立原生发布坐标、部署共享业务状态和 Peer 精确安装选择。插件拥有业务与数据兼容,各 Unit 分别拥有构建发布流程和宿主执行边界。 ## Extension Documentation Hosting Contract -- Author-built static documentation, exact native Release identity and historical scope compatibility, conditional whole-site - corrections, snapshot-origin isolation, and consumer discovery follow the - [Extension Documentation Hosting Contract](extension-documentation-hosting.md). -- Registry owns hosting and executable API details; authors own site content and structure. - Documentation does not become an installable Distribution or alter Host lifecycle authority. +[Extension 用户文档契约](extension-documentation-hosting.md)规定由发布者维护的仓库入口、发行版本链接和迁移期 Registry 文档的读取。 ## Twitter 归档信息与接入契约 diff --git a/20-product-tdd/extension-documentation-hosting.md b/20-product-tdd/extension-documentation-hosting.md index 02d403c..5dadf4f 100644 --- a/20-product-tdd/extension-documentation-hosting.md +++ b/20-product-tdd/extension-documentation-hosting.md @@ -1,5 +1,13 @@ # Extension Documentation Hosting +## 仓库用户文档 + +插件发布者维护其源码目录下的 `docs/user/`。源码目录由[仓库发行描述](extension-release-and-installation.md#从发布者仓库发现和安装)定位。App 打开所选发行 tag 对应提交中的该目录。目录缺失表示该发行未提供用户文档。 + +同一插件的通用说明由其维护者写入一个 producer 的 `docs/user/`,其他分发引用该原文,并补充各自的操作说明。First-party 现有的 Python 和 MF 共通说明由 `impl-py` 维护。面向当前读者的订正可发布到仓库默认分支,精确版本链接继续指向发行时的内容。 + +以下托管与更新规则适用于迁移期仍由 Registry 提供的文档。仓库发行使用上面的用户文档入口。 + ## Purpose And Ownership This contract defines how Extension authors, Registry, developer tooling, and consuming Hosts diff --git a/20-product-tdd/extension-release-and-installation.md b/20-product-tdd/extension-release-and-installation.md index ca2900e..89ef1cd 100644 --- a/20-product-tdd/extension-release-and-installation.md +++ b/20-product-tdd/extension-release-and-installation.md @@ -1,6 +1,6 @@ # Extension 分发发布与 Peer 参与契约 -Extension 发布者、Registry、开发工具和宿主共同消费本契约。Registry 拥有原生产物及发布生命周期的可执行协议;宿主拥有原生加载和运行生命周期;插件拥有业务、持久数据与协作兼容。本契约通过新版 Registry、宿主及数据库协议共同交付,不能将某一 Unit 的单独升级视为部署已经完成切换。 +Extension 的发布者通过自己的仓库交付发行。仓库的 Release 是该次公开发行的来源,部署保存各 Peer 的安装选择,宿主负责原生加载,插件负责业务和数据兼容。GitHub 是首个适用的代码托管平台。现有 Registry 发行按下文的迁移规则继续提供。 ## 插件身份与原生发布 @@ -10,17 +10,51 @@ Extension 发布者、Registry、开发工具和宿主共同消费本契约。Re 各 producer 只构建本仓维护的原生产物,原生依赖仍通过各自包工具消费。发布候选固定本分发的源码、元数据和产物身份;重试使用保存的原候选,不以当前分支的新构建覆盖同一个坐标。宿主 SDK 条件、Python Project/Version 和 MF manifest 等格式约束由相应 Unit 校验,不成为跨分发业务兼容声明。 -prepare、upload、publish 一次针对一个 Native Release。只有它自己的全部原生对象齐备时才可公开,检查与提交之间改变产物身份或关联必须重新验证。发布 Python 不等待 MF,发布 MF 不等待 Python。已发布的坐标及产物身份不可覆盖;相同请求可幂等重试,冲突需要新版本。文档不使缺少可执行产物的分发成为可安装版本。 +一次发布只交付一个 Native Release。生产者在全部原生对象就绪后公开 Release。公开后的坐标和产物固定,产物变更使用新版本。Python 与 MF 各自完成发布。 -共享参与协议中的 Distribution 是开放的非空字符串,不枚举语言、打包方式或现有宿主。各宿主报告自己支持的格式,并在实际加载边界校验;一个新宿主不需要修改共享数据库的格式白名单。Registry 只对自己能交付的产物提供安装能力。 +共享参与协议中的 Distribution 是开放的非空字符串。各宿主报告自己支持的格式,并在实际加载边界校验。仓库独立分发首先覆盖 `python` 和 `module_federation`。 Extension 不拥有独立共享数据表。资料使用 Block/Relation/Storage,共享配置与业务状态使用已有 Extension config/state;仅本机需要的草稿、队列和运行状态保存在本机。 +## 从发布者仓库发现和安装 + +所有发布者通过仓库 Topic `inkcre-extension` 参加同一个发现入口。App 也接受部署者直接提供的仓库地址。选定仓库后,从其公开 Releases 查找发行。Git tag 使用 `inkcre-ext////v`,给出插件逻辑名、原生分发和精确版本。同一仓库可发布多个插件和分发类型。App 选择版本时按逻辑名与分发筛选。 + +GitHub Release 正文含一个机器可读的 `inkcre-release` HTML 注释。发布工具从现有生产者元数据和实际构建生成 tag 与注释里的 JSON。宿主直接读取 Releases API 返回的正文。坐标和源码提交来自 tag,产物来自 Release 附件。 + +```text + +``` + +`source_path` 是源码的仓库相对目录,仓库根用 `.`。`host_sdk` 和 `host_sdk_version` 是原生包声明的 SDK 名称和兼容范围。MF 发行选择下表的一种形式。多文件使用 `manifest_url`,单脚本使用 `script`。同一发行坐标只有一种形式,新形式通过新版本发布。 + +| 分发 | 生产者发布内容 | 宿主读取 | +| --- | --- | --- | +| `python` | 该发行的原生 wheel,作为 Release 附件 | 从附件选取兼容的 wheel,按附件摘要核对下载,并用 wheel 的原生元数据校验插件身份、版本和入口 | +| `module_federation` 多文件 | Release 归档保存完整的 MF 资源树,同一资源树发布到该版本的静态地址 | 通过绝对 URL `manifest_url` 跨源读取 manifest,按需加载入口和其他资源 | +| `module_federation` 单脚本 | 自包含的经典 JS 脚本作为 Release 附件 | 按 `script.asset_name` 从该 Release 的附件中定位脚本,通过普通脚本加载并读取 `script.global_name` 对应的 MF 容器 | + +多文件发行的静态地址要为 manifest 和资源提供正确的内容类型与跨域响应。单脚本的 `asset_name` 是该 Release 中唯一匹配的 `.js` 附件名,`global_name` 是此脚本注册的 JavaScript 标识符,须在发布者、插件名和精确版本之间保持唯一。脚本通过 MF `get` 与 `init` 提供插件和共享依赖接口,其构建资源随这一份附件交付。两种形式都遵循同一 SDK 兼容检查。 + +每个发布者在自己的仓库控制发行。多文件发行可以使用发布者自己的静态站,也可以由发布工具安排从同一仓库提供文件。部署者可用 Release 归档自行镜像。单脚本由发布者的 Release 直接分发。宿主读取发布者声明的发行,安装无需向 InKCre 服务注册。 + +Web 发行的设置流程如需为同一 Extension 安装 Python 分发,默认读取该 Web 发行所属仓库。Python 分发由另一仓库发布时,Web Release 正文可使用 `python_repository` 指定 `https://github.com//`。设置从已选 Web Release 读取这个地址,查找逻辑名相同的公开 Python 发行。缺少匹配发行时报告仓库和插件名。来源仍为旧 Registry 的 Web 选择继续使用原设置路径。 + +用户选定来源后,安装选择保存可定位该仓库与精确发行的引用。恢复时直接使用该引用,已具备对应产物时可在本机恢复。精确版本无法取得时,向用户报告该版本的错误。浏览发现和检查更新按需触发。 + +### First-party 发布 + +`InKCre/impl-py` 和 `InKCre/impl-ts` 分别在现有仓库发布各自维护的 Python 与 MF 分发。两个仓库都使用 `inkcre-extension` Topic。插件仍以 `inkcre/` 表达共享业务身份,安装到各 Peer 的分发共用以此名字标识的插件条目。宿主沿用各自分发的版本和兼容范围。 + +以 Mail 为例,Python `0.4.0` 和 MF `0.4.4` 分别生成 `inkcre-ext/inkcre/mail/python/v0.4.0` 和 `inkcre-ext/inkcre/mail/module_federation/v0.4.4`。版本列表直接来自两个仓库的公开 Releases,普通 App 或 SDK 发行按 tag 前缀区分。 + ## 随签名应用交付的原生分发 `swift_bundled` 表示宿主签名应用携带的原生分发。producer manifest 定义 Extension Name、分发格式和精确版本,由模块资源与签名应用一起交付。宿主只运行实际携带的模块,不下载动态代码、不替换精确选择;需要其他版本时明确要求更新应用。其产物供应链是签名应用,不把不存在的 Registry 发布或原生热加载能力作为已完成事实。 -此分发仍有真实启停生命周期和 Peer 参与记录;应用关闭只停止实际运行,不撤回共享启用意图。未配置数据库时可离线使用扩展。首次加入与重连须区分:首次事务内创建缺失的参与,冲突则读已有值;加入或明确启用成功后,重连不重建已移除记录、不重放离线开关。用户在线明确启用可以重新创建本 Peer 的缺失参与;离线操作只改变本机运行并显示共享意图尚未更新。共享写入前复核参与选择和启用意图。Python/MF 原生产物继续按各自 Registry 发布流程交付。 +此分发仍有真实启停生命周期和 Peer 参与记录;应用关闭只停止实际运行,不撤回共享启用意图。未配置数据库时可离线使用扩展。首次加入与重连须区分:首次事务内创建缺失的参与,冲突则读已有值;加入或明确启用成功后,重连不重建已移除记录、不重放离线开关。用户在线明确启用可以重新创建本 Peer 的缺失参与;离线操作只改变本机运行并显示共享意图尚未更新。共享写入前复核参与选择和启用意图。 ## 部署共享状态与 Peer 参与 @@ -59,7 +93,9 @@ Extension 不拥有独立共享数据表。资料使用 Block/Relation/Stora ## 历史坐标与协议迁移 -Registry v2 提供独立原生分发读写。v1 只读取历史统一坐标,不将两个独立新版本拼成一个旧 Release;旧发布写入明确要求升级。历史原生产物、URL、摘要和来源可继续复用,但公开读取必须遵守对应原生发布的当前封禁与撤回状态。历史入口不能绕过新发布生命周期限制。 +Registry v2 继续提供独立原生发行。v1 只读取历史统一坐标,旧写入要求升级。Registry 提供的原有产物、URL 与文档继续遵守其撤回规则。 + +仓库直连发行由发布者和所用托管平台管理公开、撤回和文件可用性。现有精确选择在同一产物可经仓库来源恢复时迁移,内含旧静态地址的 MF 发行可继续使用旧入口,直到用户选择能从新来源运行的版本。旧入口在依赖它的安装完成过渡后退出。 迁移保留旧部署身份、配置和业务状态,以及可恢复的旧安装快照。旧启用成员转为各 Peer 的参与记录,保留原精确版本及意图。缺少原生格式证据时保留待解析的旧引用,旧全局配置 schema 仅留在快照,不能被赋予未知分发的来源;新版实际宿主识别并条件更新后,才填写有来源的 schema。不得猜测格式或自动改为最新版本。原版本不存在对应分发时明确待修复,不静默选另一个版本。没有记录的停用参与历史不能补造。 @@ -67,6 +103,6 @@ Registry v2 提供独立原生分发读写。v1 只读取历史统一坐标, ## 验收边界 -发布验收观察每种分发独立发布、缺少自身产物时保持不可公开、候选重试和提交身份一致,以及历史公开读取遵守封禁。部署验收包含精确旧版本迁移、未知分发延迟解析和非空业务 state 保留。 +以同一 first-party 插件的 Python 与 MF 为例,验证各发布者可独立交付,App 能从仓库发现或用仓库地址安装。安装和冷恢复应按记录的来源与精确版本取得产物,MF 验证实际界面和异步资源。迁移用已有 pin 验证原产物及业务数据可恢复。 完整运行验收从实际 Web 应用安装入口进入目标 Peer 的启用、运行、停用和刷新恢复。一个 Peer 升级不能改变另一个同种分发 Peer 的选择;睡眠恢复、离线待应用和 Python 环境更新后的新进程也属于验收。插件案例需覆盖已有内容读取与按需执行、设置 UI 的先行运行以及共享业务数据延续。仅构建、独立 import 或调用 MF 容器不能代替实际入口验收。 diff --git a/website/.vitepress/config.mts b/website/.vitepress/config.mts index eb32937..0d25cc1 100644 --- a/website/.vitepress/config.mts +++ b/website/.vitepress/config.mts @@ -123,6 +123,7 @@ export default defineConfig({ items: [ { text: 'Build on InKCre', link: '/developer/ecosystem/' }, { text: 'Build a Source Extension', link: '/developer/ecosystem/source-extension' }, + { text: 'Publish a Web Extension', link: '/developer/ecosystem/publish-web-extension' }, ], }, { diff --git a/website/content/en/developer/ecosystem/index.md b/website/content/en/developer/ecosystem/index.md index e1d4e0d..46e8ba9 100644 --- a/website/content/en/developer/ecosystem/index.md +++ b/website/content/en/developer/ecosystem/index.md @@ -11,6 +11,7 @@ to contribute it to the Core repository. Start with the boundary your integratio | Goal | Integration path | | -------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | | Collect from a service InKCre does not support yet | [Build a Source Extension](/developer/ecosystem/source-extension) | +| Ship a browser Extension from your own repository | [Publish a Web Extension](/developer/ecosystem/publish-web-extension) | | Use existing information from ChatGPT | [Connect the MCP Sink](/guide/sinks/chatgpt) | | Build a new runtime around the shared info-base | Read the [Peer architecture](/developer/architecture); this requires the admitted database protocol, not arbitrary SQL access | | Change InKCre's own runtime or product behavior | Follow [Contributing](/developer/contributing) | @@ -22,10 +23,9 @@ derives use-facing meaning from stored content and required context. A Sink expo another tool. An Extension packages one or more capabilities for a compatible Host; not every integration needs all three or a custom browser interface. -The Python path uses a native wheel, the `inkcre.core.extensions` entry point, and an exact Registry -Release. A Peer selects its own Distribution/version and records its enabled intent. An online Host -then activates the Extension best-effort; users do not maintain a second durable running flag. -Browser code is a separate distribution, not automatically produced by a Python wheel. +A Peer selects an exact Extension distribution and version and records whether it should be enabled. +Python uses a wheel with an `inkcre.core.extensions` entry point. Browser Extensions have their own +Module Federation builds and can publish either a manifest with separate assets or a single script. The Source tutorial targets **Core Host SDK 0.3.x**. Its Python programming interfaces currently import Core modules; they are not an independent, universally stable Source SDK. The Extension @@ -40,7 +40,7 @@ fixtures during development, with its own database and credentials. Package identity, Host compatibility, dependencies, and immutable releases are part of delivering a usable integration. Keep your own package, tests, release history, and user setup guide in your -repository. A public Registry requires a namespace and publishing authorization; a private -development preview does not grant those rights. +repository. You can publish a Web Extension through GitHub Releases using your repository token. If +you use a Registry for distribution, its operator grants namespace and publishing access. Continue with [Build a Source Extension](/developer/ecosystem/source-extension). diff --git a/website/content/en/developer/ecosystem/publish-web-extension.md b/website/content/en/developer/ecosystem/publish-web-extension.md new file mode 100644 index 0000000..82a1ade --- /dev/null +++ b/website/content/en/developer/ecosystem/publish-web-extension.md @@ -0,0 +1,103 @@ +--- +title: Publish a Web Extension +description: Package a Module Federation Extension and publish it from your GitHub repository. +--- + +# Publish a Web Extension + +The Web App installs Module Federation Extensions from your public GitHub repository. Each version +records its build and SDK requirements in one GitHub Release. Add the `inkcre-extension` repository +topic for discovery, and keep setup instructions in `docs/user/` beside the Extension's +`package.json`. Users can also install by entering the repository URL. + +## Choose a release format + +| Format | Use it when | What gets published | +| ---------- | ----------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `manifest` | The Extension has multiple assets or benefits from loading resources on demand. | A ZIP in the Release and a manifest at an exact, browser-readable static URL. The publishing tool serves the files from your repository using jsDelivr. | +| `script` | The Extension fits in one modest download, including styles and other build assets. | One classic JavaScript attachment in the Release. The Web App loads that attachment directly. | + +Choose one format per version. To switch formats, publish a new version. A publisher with its own +static origin can use the `manifest_url` path in the +[release contract](https://github.com/InKCre/docs/blob/main/20-product-tdd/extension-release-and-installation.md). + +## Build and publish + +Use the Extension's normal build to produce a directory containing `mf-manifest.json`, its remote +entry and the runtime files they reference. The +[Mail Vite configuration](https://github.com/InKCre/impl-ts/blob/main/extensions/mail/vite.config.ts) +shows a build with the root `.` exposure and shared Host SDK. Declare the identity and SDK range in +the same `package.json` used by the build: + +```json +{ + "name": "my-notes-extension", + "version": "0.1.0", + "inkcre": { + "name": "yourname/notes", + "module_federation": { "host_sdk_version": ">=0.4.2 <0.5.0" } + } +} +``` + +If setup installs the matching Python Distribution from another repository, set +`inkcre.module_federation.python_repository` to that repository's public GitHub URL. Publish a +compatible Python release before users run setup. When both Distributions live in your Web +repository, leave the field out. + +Save a workflow in `.github/workflows/publish-extension.yml`. The example uses npm for the build. +Keep the install and build commands you use in your own repository if they differ. + +```yaml +name: Publish Web Extension +on: workflow_dispatch +permissions: + contents: write +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + - uses: actions/setup-node@v7 + with: + node-version: 22 + cache: npm + - run: npm ci + - run: npm run build + - uses: InKCre/impl-ts/.github/actions/publish-extension@902535ee6ef39d642b9a6cb6892b98a29c59e952 + with: + package: package.json + artifact-directory: dist/web + format: manifest + token: ${{ github.token }} +``` + +Set `format: script` for the single-attachment route. The workflow uses your repository token to +publish to that same repository. The tool derives the version and Release tag from `package.json`, +binds the Release to the source commit, and uses that commit to locate `docs/user/`. Run the +workflow on the commit that you want to publish. + +## Check a build locally + +Run the publish tool in preparation mode to inspect the attachment and Release description without a +publishing token. Clone the tool once, check out the same ref used by the workflow, and install its +locked dependencies. + +```sh +git clone https://github.com/InKCre/impl-ts.git ../inkcre-publisher +git -C ../inkcre-publisher checkout 902535ee6ef39d642b9a6cb6892b98a29c59e952 +(cd ../inkcre-publisher/.github/actions/publish-extension && npm ci --ignore-scripts) +node ../inkcre-publisher/.github/actions/publish-extension/cli.mjs \ + --repository yourname/notes-extension --package package.json \ + --artifact-directory dist/web --format script --prepare-only --output /tmp/notes-release +``` + +Run the command from your Extension's checked-out repository. Use a fresh output directory and +change `--format` to `manifest` to inspect the ZIP and static tree instead. Script mode bundles the +Vite ESM remote and inlines its CSS, images, and fonts. The Web App downloads the whole attachment +before it starts the Extension. Choose `manifest` for large bundles or builds that require nested +remotes, CSS `@import`, or dynamic imports whose paths are only known at runtime. + +After publishing, open **Extensions → Browse GitHub repositories**, enter your repository URL and +choose the exact Web release. Install it, enable it, and reopen the app to verify that it loads the +same version.