Skip to content

IMBoy 打包契约与运维指南(Packaging Contract & Operator Guide) ​

版本:v1.2 | 最后更新:2026-11-06(一期交付增加 App 一对一 RTC;群通话独立关闭,见 §9.5) 任务:海外合规计划 F-09 — Packaging Contract and Operator Documentation 与 F-08 — Migration and Stored-Data Compatibility(兼容性 Runbook 见 §7);一期交付收敛主计划 Q11 同步(docs/design/2026-10-07-phase1-delivery-quality-plan.md) 受众:负责构建/发布 IMBoy 组合产物(Base-only / full-selected / overseas_baseline / agent_hub / phase1_delivery 等 profile)的运维与发布工程师 关联:scripts/generate_product_features.py(契约源)、scripts/verify_product_feature_artifacts.py(产物验证)、scripts/run_product_feature_matrix.sh(三仓矩阵,支持 phase1_delivery preset)、交付包清单。具体构建和验收记录保存在仓外,并绑定交付产物哈希。


1. 支持的 feature 全集 ​

Feature 全集的唯一权威源是代码:imboy_feature:feature_names()(src/lib/imboy_feature.erl),静态目录见 src/lib/imboy_policy_catalog.erl。构成:

类别feature裁剪性
Base 固定core不可裁剪(生成器 BASE_FEATURES = ("core",);disabled_base_features 必须为空)
可选加密域e2ee须在 manifest 显式选择;未选择时 compiled(e2ee)=false
插件管理(plugin-managed)channel、location、moment、channel_discover、channel_invitation、channel_order、group_vote、group_schedule、group_task 及插件注册表追加键可按 manifest 选择性编译/禁用
平台内建bot_webhook可禁用(overseas_baseline 默认关)
RTC 总域rtc后端保留运行时域语义;App 须在生成清单中选入,并读取运行时开关。一对一交付选入此键
RTC 子能力rtc_group依赖 rtc;须单独编入并运行时启用;phase1_delivery 交付锁保持关闭
平台内建project(GZAPP-02/G6,Workspace 项目协作面:project_handler/project_task_handler/project_member_handler/project_milestone_handler/project_channel_handler)可禁用;通用默认开启(full-selected 兼容)。物理裁剪仅 API handler 家族(logic/ds/repo 保留编译——admin 概览/资源计数仍引用);路由由 imboy_feature:route_feature/3 + compiled_routes/2 运行时过滤

依赖关系(如 channel_discover/channel_order 依赖 channel)由 imboy_policy_catalog:dependencies/1 与生成器 catalog 校验。

2. Immutable Base ​

  • core 是生成器的不变底座。e2ee 是可选 manifest 键;是否进入 compiled_features 以清单为准,运行时 policy 可进一步关闭已经编入的能力。
  • 契约真源与回归:scripts/generate_product_features.py 的 BASE_FEATURES、test/scripts/test_generate_product_features.py 与 test/lib/imboy_feature_compiled_tests.erl。

3. Manifest schema(v1) ​

json
{
  "schema_version": 1,
  "product_id": "imboy",
  "profile": "<profile 名>",
  "base_ref": "imboy-feature-inventory-v1",
  "selected_features": ["..."]
}

约束(generate_product_features.py:validate 强制):schema_version=1;product_id=imboy;base_ref 固定;disabled_base_features 必须为空(Base 不可禁);selected_features ⊆ 全集且已满足依赖闭包;compiled_features = selected_features ∪ {core}。生成器拒绝缺失依赖,不自动补选,并输出 manifest_hash(sha256)。

Tracked manifest 位置:config/product-feature-manifests/*.json(如 overseas_baseline.json、一期交付 phase1_delivery.json——selected = channel + moment + location + group_vote + group_schedule + group_task + enterprise_business + customer_service + rtc);config/product-feature-manifest.json 当前与 phase1_delivery.json 内容一致,均不选择 rtc_group。运行时镜像校验见 feature_composition_compat_tests:tracked_manifests_within_catalog_test_。

其它 full-selected 部署的 Git 外关闭示例——关 project(GZAPP-02/G6:不建地域 profile;当前 phase1 清单本身已不选择 project):

  1. 物理裁剪(编译期):在部署机用 Git 外 manifest 重跑生成器,产物同样落仓内路径但不回传 Git——
    bash
    # guangzhou.json = full-selected 清单去掉 "project",存放在部署机(不入仓)
    python3 imboy/scripts/generate_product_features.py --manifest /etc/imboy/guangzhou.json
    make -C imboy rel   # project_* 五 handler 经 ERLC_EXCLUDE 不进 beam
  2. 运行时开关(不重编译,双保险的第二道):sys.config 的 policy features 段把 project 置 false(逐机配置文件 Git 外,同 IMBOY_PG_* 约定)——imboy_feature:enabled/1 按 ?IMBOY_COMPILED_FEATURES andalso effective_features 双条件裁决,compiled_routes/2 同口径剔除路由。
  3. 数据兼容:关闭 project 只裁 API 面,project 表与存量数据保留(admin 只读面 adm_workspace_handler:project_* 不挂 feature 门,平台运营仍可查);重新启用走 §7.2。

4. 构建命令(单 manifest 复现) ​

生成器从 manifest 派生 11 个确定性产物(全部带 do not edit 头,--check 可校验陈旧):

端产物裁剪作用
后端imboy/include/generated/imboy_product_features.hrl?IMBOY_COMPILED_FEATURES 宏 + manifest hash
后端imboy/include/generated/imboy_product_features_erlc.mkIMBOY_FEATURE_ERLC_EXCLUDE:未选中 feature 的 beam 物理不编译(erlang.mk ERLC_EXCLUDE + BUILD-00R 装配钩子:rel-deps → app → prune → relx)
Flutterlib/app_core/feature_flags/generated_product_features.dart、lib/config/router/generated_product_feature_routes.dart、generated_channel_order_widget.dart编译集常量 + 路由树物理裁剪(未选中路由不进编译单元,AOT payload 无字符串残留)
Adminsrc/generated/productFeatures.ts、generatedFeatureComposition.tsx路由/菜单/chunk 编译集
Androidproduct-features.properties + debug/profile/release AndroidManifest.xml overlay权限/组件按需注入

一条命令流水线(先将 FEATURE_EVIDENCE_DIR 设置为三仓之外的绝对路径;等价 scripts/run_product_feature_matrix.sh <preset>):

bash
python3 imboy/scripts/generate_product_features.py --manifest <manifest.json>
make -C imboy rel                                   # 后端 release
(cd imboyapp && flutter pub get && flutter build apk --release)
(cd imboyadmin && bun run build)
python3 imboy/scripts/verify_product_feature_artifacts.py \
  --manifest <manifest.json> \
  --backend-beam "$(find imboy/_rel -path '*/ebin/imboy_feature.beam' | tail -1)" \
  --flutter-apk imboyapp/build/app/outputs/flutter-apk/app-release.apk \
  --admin-dist imboyadmin/dist \
  --output "$FEATURE_EVIDENCE_DIR/<preset>.json"

5. 输出证据(artifact 断言) ​

verify_product_feature_artifacts.py 三层物理断言(不是菜单级、是字节级):

  1. 后端 beam:release 内 imboy_feature.beam 的 compiled_features 契约 marker 与 manifest hash 一致;未选中 feature 的业务模块(agent_task_repo 类)beam 不得存在;
  2. Flutter APK:release libapp.so AOT payload 中不得残留被裁剪路由的 GoRoute name 字符串(marker 选自生成路由文件,避开核心页面硬编码路径);
  3. Admin dist:feature 专属动态 chunk 文件必须物理缺席。

证据 JSON 必须写入三仓之外的执行目录,不纳入 Git。矩阵脚本默认写入 ${XDG_STATE_HOME:-$HOME/.local/state}/imboy/feature-composition/<run-id>/,可用 FEATURE_EVIDENCE_DIR 指定仓外目录。报告含三仓 SHA 与产物哈希;矩阵铁律=先提交后跑,verify 记录 head/dirty/worktree hash,并拒绝仓内输出。历史报告由执行方在仓外保管,不能据此宣称当前候选通过。

6. 升级边界(Upgrade Limits) ​

  • Schema 超集,零 per-profile fork:priv/migrations/ 是唯一迁移目录(182 个迁移文件),所有 profile 共享同一迁移序列。禁用 feature 只关代码路径,不回滚、不删除任何表或数据。
  • 无 schema 降级路径:迁移只有 up;down 文件仅供开发清理,发布序列不含 downgrade。
  • 无 per-combination 迁移:新增 feature 的迁移照常追加到同一序列;旧产物升级到新 profile 不需要补历史行。
  • 生成物 --check 门防漂移:源码与 manifest 不同步时 CI/--check 即红。

7. Compatibility Runbook(F-08) ​

7.1 禁用一个已有数据的 feature ​

行为:路由/端点/UI/worker 消失(编译缺席或运行时门拒绝 ERR_FEATURE_DISABLED),库表与既有行原样保留(schema 超集,见 §6)。禁用动作本身不触发任何删除路径。已知读侧语义:feature 关闭后相关 API 返回 feature-disabled 错误或空集,不是数据丢失;举报工单/审核队列里的历史引用行保留(审核面见 moderation_policy surface 白名单)。

7.2 重新启用 ​

把 feature 加回 selected_features → 重新生成产物 → 发布。旧数据原样回读(表一直在、无数据迁移需要);feature 关闭期间产生的迁移照常已应用(超集序列),无需补迁。

7.3 降级(回到旧 profile/旧版本) ​

  • 产物级:允许回到裁剪更少/更多的 profile(同一 schema 序列),beam/APK/dist 按目标 manifest 重建即可;
  • Schema 级:不支持降级到更旧迁移版本——发布 runbook 必须先备份(imboy/scripts/backup_pg),回退版本=恢复备份+旧产物。

7.4 隐私/保留义务不随禁用停(Acceptance) ​

  • credential_retention_worker(T-02,验证码 PII 过期清理)恒挂 imboy_sup,不经任何 feature 门——契约测试 feature_composition_compat_tests:retention_duties_survive_feature_disable_test_;
  • 账号删除链(D-01~D-03 的 job/清扫/墓碑重放)同理为 Base 义务,不随 UI/feature 关闭而停;
  • "禁用代码不静默删数据"的可测面:schema_is_superset_no_profile_forks_test_(无 fork 目录)+ §7.1 行为定义。

7.5 兼容性测试矩阵 ​

层载体覆盖
静态契约(eunit,本批新增)test/lib/feature_composition_compat_tests.erl(6/6)schema 超集、manifest ⊆ 全集、运行时门语义、retention worker 恒跑
端点级feature_route_http_tests(矩阵脚本内 make eunit t=)base-only/full-selected 下可选路由 401/404 语义
产物级(三仓矩阵)run_product_feature_matrix.sh {base-only|full-selected|overseas_baseline|agent_hub|phase1_delivery}生成→构建→三层物理断言→证据 JSON(含三仓 SHA)
双 profile bootF-03 执行记录(9803/9804)运行时 effective_features/capability 全景

8. 已知保留的共享代码/Schema(Retained Shared Infrastructure) ​

组合裁剪裁的是业务模块与路由/UI 面,以下共享基础设施在任何 profile 恒在(它们不属于任何单一 feature,属 Base):

  • 消息/会话域:msg_* 表族与 C2C/C2G 管道(E2EE 与举报、审核、导出的载体);
  • 身份/合规域:user/user_device/user_setting/review_queue/report_ticket/user_deletion_job 等表与逻辑;
  • 平台库:imboy_policy/imboy_feature/imboy_profile_preset/moderation_policy/log_redact/elib_log 等横切模块;
  • 保留义务 worker:credential_retention_worker、删除清扫/墓碑重放链(§7.4);
  • 插件壳:feature 以插件注册表键存在(imboy_plugin_registry),壳与目录恒在,被裁的是键对应的业务实现模块。

区分口径(F-09 Acceptance):产物里找不到的是业务模块(如某 feature 专属 handler/logic/repo 的 beam),找不到≠删了数据;找到的共享基础设施不构成 feature 存在的声明——feature 是否启用只以 manifest + 运行时 policy 为准。

9. 一期交付 profile(phase1_delivery) ​

代码真源:src/lib/imboy_profile_preset.erl(profile_defaults/1、delivery_locked_features/1、fail_closed/1)。本节与代码不一致时以代码为准并回改本文。落地提交:1ac0c8ad(一期交付收敛主计划 Q02)。

9.1 白名单(运行时开启面) ​

phase1_delivery 是白名单语义 profile:运行时默认开启的特性键有 11 个——

键覆盖能力
coreCore IM(登录/会话、联系人、C2C/C2G、历史/离线/重连、多端、附件与消息治理)
channel频道底座:组织内部 General 群与公告频道(一期依赖保留)
appeal处置申诉链(R-04 operational baseline,治理保留)
enterprise_business企业组织/部门/成员/工作区/RBAC 与企业业务底座
customer_service人工客服(坐席队列/认领/转接/关闭/历史/附件/SSE/Widget)
rtc两个已登录 App 好友之间的一对一语音/视频;不包含访客/Web 坐席或群通话新增交付
moment朋友圈:发布、浏览、互动及内容可见性
location附近的人:定位授权、可见性与隐私控制
group_vote群投票及投票消息卡片
group_schedule群日程及日程消息卡片
group_task群作业、成员分配、提交及作业消息卡片

imboy_feature:feature_names() 全集中的其余键一律默认 false;且 fail_closed(phase1_delivery) = true——未在 preset 枚举的键(含未来新增 plugin 键)默认关闭。§9.2 列出的交付锁定键不能被 DB saved / 远端配置重新开启。

编译裁剪维度与运行时白名单是两回事:manifest config/product-feature-manifests/phase1_delivery.json 的 selected_features = [channel, moment, location, group_vote, group_schedule, group_task, enterprise_business, customer_service, rtc](core 是 Base;e2ee 未选入;appeal 是后端运行时域键并保留在白名单内)。依赖边 customer_service → enterprise_business 与 rtc_group → rtc 由 imboy_policy_catalog:dependencies/1 在生成期强制。

9.2 交付锁(delivery_locked_features) ​

一期交付 profile 下,运行时(DB saved / 远端配置)不得重新开启的特性键,合并链最后强制压 false(与 e2ee storage_mode 硬闸同一时机),保证"旧缓存或远端全开配置不能绕过关闭面"(AC03)。共 12 键:

  • 群通话及其余未交付能力:e2ee、rtc_group、live_room、bot_webhook、ai_assistant、agent_hub、mcp
  • 一期默认不承诺的运营域:wallet、channel_discover、channel_invitation、channel_order、project

OA 共享设施豁免(F08):bot_delivery outbox / worker / guard 不在锁内——enterprise_webhook(OA 对接)走独立门,Bot 产品关闭不影响合法企业事件投递。

9.3 capabilities 预设 ​

能力键值说明
storage_modearchived明文归档存储
e2ee_modedisabledE2EE 产品面关闭
message_searchtrue检索保持
message_exporttrue导出保持
audit_modefull全量审计
retention_policyrolling_days / 365 天与 enterprise 预设同档

E2EE OFF 语义边界(AC04):关闭的只是 E2EE 产品能力——TLS、企业托管加密(body_cipher / keyring)、访问控制、归档/检索/推送/保留合同全部保持;不自动解密、降级或迁移历史密文,有历史加密会话时显式拒绝不兼容写入。

9.4 构建入口 ​

bash
bash scripts/run_product_feature_matrix.sh phase1_delivery
# 单 manifest 复现:python3 scripts/generate_product_features.py \
#   --manifest config/product-feature-manifests/phase1_delivery.json

9.5 App 一对一 RTC 与群通话边界 ​

本次交付沿用 LiveKit SFU,只开放两个已登录 imboyapp 用户之间的 C2C 语音/视频。既有好友关系、信令黑名单校验和身份认证继续生效;访客、Web 坐席、C2S 会话及群通话不在新增交付范围。

两份默认/一期清单只新增 rtc,不选择 rtc_group。phase1_delivery 的 rtc 白名单默认值为 true,仍接受显式运行时 features.rtc=false;rtc_group 仍受交付锁约束。实际运行时 profile 从配置读取,打包 manifest 的 profile 字段不会替现场自动切换运行时配置,因此发布前须读取实际 effective profile/features,确认有无持久化关闭覆盖。

App 的 RTC 入口必须同时满足生成清单包含 rtc、服务端运行时 features.rtc=true。群入口另外要求 rtc_group 被编入并启用,且父级 rtc 开启。服务端 rtc_room_logic:join/4 在 kind=group 查询成员和签发令牌前复核两道门,关闭时复用 ERR_FEATURE_DISABLED(5190);未改变 kind 取值或新增错误号。其它 profile 的 RTC 总域继续沿用既有运行时语义;群子能力须显式选择。

无 BEAM 的新 checkout 由生成器 source_catalog() 读取 imboy_feature.erl 的 Phase2Domains,避免合法的 rtc 清单被误判为 unknown feature。新增 feature 与依赖仍从 Erlang 真源读取,不能手改任一端生成文件。三端须用同一 manifest 生成、构建并核对 hash/schema/compiled_features 后交付。

对应回归为 Python 生成器目录/依赖/清单测试,以及 imboy_feature_tests、imboy_feature_compiled_tests、imboy_profile_preset_tests、imboy_policy_tests、rtc_room_logic_tests、rtc_room_handler_tests。这些回归与真实 App 的双向音视频、权限、网络切换、挂断释放验证分别记录;生成器通过不代表媒体通话验收通过。

This delivery selects rtc for one-to-one calls between signed-in app friends. Group calls require the separate rtc_group feature, which remains excluded and delivery-locked. Existing friendship, blocklist and authentication rules still apply. Explicit runtime features.rtc=false remains effective; the manifest profile does not change the running server's profile. Generate all three products from the same manifest and verify the hash, schema and compiled features. Source and generator checks do not replace real-device call, lifecycle or cleanup acceptance.

IMBoy — 企业私有化即时通讯平台