Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

docs(adr): record the skill package resource bounds as ADR 0303

vastsa79ab41aea64c
diff --git a/docs/adr/0303-skill-package-resource-limits.md b/docs/adr/0303-skill-package-resource-limits.md
new file mode 100644
index 000000000..013411c4a
--- /dev/null
+++ b/docs/adr/0303-skill-package-resource-limits.md
@@ -0,0 +1,89 @@
+# ADR 0303: A skill package carries resources far above the document cap
+
+- Status: Accepted for implementation
+- Date: 2026-09-22
+- Amends: ADR 0300 (the "bounded Skill package resources" of the configuration
+ sync baseline now have concrete values, separate from the document cap, and a
+ receiver bound that matches the packager)
+- Related: [03-runtime/22-config-sync](../spec/03-runtime/22-config-sync.md) ·
+ `crates/host-core/src/user_skills.rs` · ADR 0243 (the document cap the market
+ path enforces, unchanged)
+
+## Context
+
+A directory-shaped skill is a `SKILL.md` document plus sibling resources. One
+constant bounded both: `MAX_SKILL_BYTES` (128 KiB) was the document limit and,
+at the same time, the limit on one resource. The packager added a second pair —
+at most 64 resources, at most 512 KiB of resources per package — and the
+receiver kept a third copy of the per-resource number, refusing any resource
+above 128 KiB when a revision was read back.
+
+The document limit exists for a prompt-sized reason: a document can be handed to
+the model. A resource is not prompt content. It is data or a script that stays
+on disk and is read on demand, so sharing the document's constant with it made
+the package bound an accident of the document bound.
+
+The cost was not a graceful skip. `package_files` returns `Err` and the skills
+capture propagates it, so one oversized skill failed the whole capture and, with
+it, the sync of every domain. A real skill (a design-reference skill carrying
+3.7 MiB of CSV and JSON in 76 files, largest file 808 KiB) reproduced exactly
+that: config sync reported `SKILL_LIMIT_EXCEEDED: skill package is too large`
+and stopped. Raising the packager bound alone would have been worse than the
+failure it fixed — the revision would upload and then fail on the other device,
+where the receiver still enforced 128 KiB.
+
+## Decision
+
+The document bound and the package bounds are separate:
+
+- `MAX_SKILL_BYTES` (128 KiB) remains the cap on a skill document.
+- `MAX_SKILL_RESOURCE_BYTES` (2 MiB) is the new cap on one package resource.
+- `MAX_SKILL_PACKAGE_FILES` is 256 and `MAX_SKILL_PACKAGE_BYTES` is 16 MiB.
+
+Capture and apply both compare a resource against `MAX_SKILL_RESOURCE_BYTES`,
+and `read_remote_revision` uses that same constant, so an upload the packager
+accepted is always readable back. Capture compares a resource against its
+metadata length before reading it, so an oversized file is refused without being
+loaded into memory first. Package paths, symlinks, collisions, the document cap,
+and the resource-per-object transport are unchanged.
+
+## Consequences
+
+- A package may now be 32× larger than before (512 KiB → 16 MiB) and hold 4×
+ more files. Sync volume, capture memory, and the number of WebDAV objects per
+ revision grow with it; each resource is still one object, so no single request
+ exceeds the per-resource cap.
+- Resources share the existing 4096-object ceiling for one revision across all
+ domains; roughly sixteen maximum-size packages fill it, and the existing
+ `CONFIG_SYNC_LIMIT_EXCEEDED` error is what a user sees beyond that.
+- A bound is still all-or-nothing. `package_files` returns an error that the
+ skills capture propagates, so one resource above 2 MiB, more than 256
+ resources, or more than 16 MiB of resources in one package still fails the
+ capture, and with it the sync of every domain. This record moves the bound; it
+ does not make an oversized package skippable.
+- The descriptor list of a package travels in the entity payload, which keeps
+ its own 512 KiB bound. A package with 256 resource paths long enough to push
+ that payload over the bound is therefore refused at upload
+ (`CONFIG_SYNC_LIMIT_EXCEEDED: local entity is too large or unsupported`)
+ rather than at capture, which is a sharp edge of the wider file count.
+- No migration. The bounds are checked at capture and apply, never stored, so
+ existing packages and revisions keep working; only previously refused packages
+ start being accepted.
+- Prompt-facing behavior is unchanged: the editor counter, the market install
+ check, and their copy still describe a 128 KiB document, and ADR 0243 stands.
+- Known gaps are not addressed here. Junk directories (`__pycache__`, `.venv`,
+ `.git`) are still packaged and now consume the larger budget, and one symlink
+ anywhere in a package still fails the whole capture rather than being skipped.
+ A device running an older build still enforces 128 KiB per resource on read,
+ so a package accepted here is not readable by it.
+
+## Alternatives
+
+- **Raise the single shared constant.** Rejected: a 2 MiB `SKILL.md` is a prompt
+ problem, not a package problem, and the market path inlines sibling resources
+ into a document that must stay prompt-sized.
+- **Raise only the packager bounds.** Rejected: it splits the packager from the
+ receiver and converts a local refusal into a cross-device sync failure.
+- **Filter junk directories and skip symlinks instead of raising bounds.**
+ Rejected for this record: filtering changes which bytes a package carries, so
+ it is a packaging-semantics decision on its own, not a bound to widen.
diff --git a/docs/adr/README.md b/docs/adr/README.md
index 1bba2caf8..89609ddbc 100644
--- a/docs/adr/README.md
+++ b/docs/adr/README.md
@@ -331,6 +331,7 @@ Each ADR includes:
| 0300 | [Host-owned encrypted portable configuration sync](0300-host-owned-encrypted-portable-configuration-sync.md) | Accepted for implementation |
| 0301 | [Explicit append-only WebDAV compatibility mode](0301-explicit-append-only-webdav-compatibility-mode.md) | Accepted for implementation |
| 0302 | [A failed compaction keeps the recent window, and an oversized summary is chunked](0302-compaction-fallback-recent-window-and-chunked-summary.md) | Accepted for implementation (issue #827; amends ADR 0049 / ADR 0282) |
+| 0303 | [A skill package carries resources far above the document cap](0303-skill-package-resource-limits.md) | Accepted for implementation (amends ADR 0300) |
| turn-process-and-thinking-display | [Turn process and thinking presentation](turn-process-and-thinking-display.md) | Accepted |
| provider-display-order | [Provider display order](provider-display-order.md) | Accepted |
| registry-header-variable-spelling | [Remote header variables accept the registry's `{name}` spelling](registry-header-variable-spelling.md) | Proposed |
diff --git a/docs/spec/03-runtime/22-config-sync.md b/docs/spec/03-runtime/22-config-sync.md
index 8f85a12ae..566fd841f 100644
--- a/docs/spec/03-runtime/22-config-sync.md
+++ b/docs/spec/03-runtime/22-config-sync.md
@@ -43,8 +43,10 @@ repositories or arbitrary files. Imported instruction files are written only
after their scope is explicitly selected, mapped where required, and approved.
Directory-shaped skills carry bounded sibling resources as authenticated
objects. Package paths, symlinks, collisions, file counts, and total size are
-validated by Host before approved resources are written; scripts are stored as
-bytes and are never executed by import.
+validated by Host before approved resources are written: at most 256 resources
+per package, 2 MiB per resource, and 16 MiB per package, while the skill
+document itself stays capped at 128 KiB because it can reach a prompt. Scripts
+are stored as bytes and are never executed by import.
Project and workspace bindings are represented by opaque logical identifiers.
Host-core assigns a persistent logical identity to each registered standalone
diff --git a/docs/zh-CN/spec/03-runtime/22-config-sync.md b/docs/zh-CN/spec/03-runtime/22-config-sync.md
index 30af57b26..8a38269a6 100644
--- a/docs/zh-CN/spec/03-runtime/22-config-sync.md
+++ b/docs/zh-CN/spec/03-runtime/22-config-sync.md
@@ -23,7 +23,7 @@ Host-core 持有 vault key、WebDAV 传输、修订状态、合并基线、待
当前适配器集合覆盖应用偏好、用户所有的 providers、MCP 定义、用户 skills、全局 subagents、由应用管理的全局/项目指令与项目、插件安装意图、定时自动化任务以及可选的项目记忆。凭据默认需要明确选择。只有选中凭据类别时才会包含 provider API key 和 MCP 环境变量/headers;OAuth access/refresh token 与 cookies 永远不会导出。
指令适配器只读取固定的全局 `~/.pi/agent/AGENTS.md` 和每个已注册项目根目录的 `AGENTS.md`;不会扫描嵌套仓库或任意文件。导入的指令文件只有在明确选择其作用域、完成必要映射并获得审批后才会写入。
-目录形态的 skills 会将有界的同级资源作为已认证对象携带。Host 会校验 package path、symlink、冲突、文件数量和总大小后才写入已审批的资源;脚本按字节存储,导入时绝不执行。
+目录形态的 skills 会将有界的同级资源作为已认证对象携带。Host 会校验 package path、symlink、冲突、文件数量和总大小后才写入已审批的资源:每个 package 最多 256 个资源、单个资源 2 MiB、整个 package 16 MiB;技能文档本身仍保持 128 KiB 上限,因为它可能进入 prompt。脚本按字节存储,导入时绝不执行。
项目和 workspace 绑定使用不透明的逻辑标识符表示。Host-core 为每个已注册的独立项目分配持久逻辑身份;项目组根目录的身份由组身份和有序根位置派生。设备映射把接收的逻辑 ID 覆盖到本地文件夹,因此不同绝对路径不会产生重复实体。
传入的项目作用域可执行内容在本地文件夹映射和审批存在前保持暂存。加密的便携实体负载中不会写入本地路径。没有受支持适配器的插件数据会报告为不支持,而不会被声称为已同步。已审批的插件安装意图保存在 Host 所有的本地覆盖中;它不会拉取插件字节或权限授予。