@sema-agent/settings-schema 24.0.0 → 25.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -8,6 +8,98 @@
8
8
 
9
9
  ## Unreleased
10
10
 
11
+ ## 25.0.0 — 2026-11-09 — major:写权限按字段抬权(读口只有一只 `writeRoleFor`,`domainWriteRole` 删;`projects` 的 `goal` / `contextItems` / `notes` 要 publisher)· 能力读数两态(`CapabilityReading` 删 `undeclared`,「读得出」要显式的 `capabilities` 对象,位交自有属性副本)
12
+
13
+ > 档位(按发版纪律):**major** —— 公开导出删除(`domainWriteRole`)· 闭集缩小(`CapabilityReading` 删一臂)· 写权限收紧(同一次写,`projects` 的内容字段 editor 由过变拒)。两项各自独立,放在一版里发:消费方升级时一起过一遍写口与心跳读口。
14
+
15
+ ### BREAKING ① 写权限读口
16
+
17
+ `domainWriteRole(domain)` 删,换成 `writeRoleFor(domain, changedFields)`:一次写要的角色是域的底(`DOMAIN_WRITE_ROLE` 的行)与被改字段各自角色(新表 `DOMAIN_FIELD_WRITE_ROLE`)的最高者,今天有逐字段行的域是 `projects`(`goal` / `contextItems` / `notes` = publisher,其余登记字段 = editor)。
18
+ 读 `domainWriteRole` 的代码(web-admin 的写口与权限图、server 的调用方信任)编译红,以 editor 身份改这三个字段的用户自此被拒。
19
+ 旧调用 `domainWriteRole(d)` 改成 `writeRoleFor(d, [])`(读数一格不变),判一次写改成 `writeRoleFor(d, changedWriteFields(d, 库里的文档, 要存的文档))`。
20
+
21
+ ### BREAKING ② 能力读数
22
+
23
+ `CapabilityReading` 删 `undeclared` 一臂,只有显式的 `capabilities` 对象才是读数:体是对象而没有 `capabilities` 键(`{}` / `{ ok: true }` / 位平铺 / 键的值是 `undefined`)读成 `{ kind: "unreadable", why: "capabilities-absent" }`,`declared.capabilities` 交自有属性的副本(包的隔离原型:不继承 `Object.prototype`)。
24
+ 按 `kind` 穷举的代码(`case "undeclared"`)编译红,把老 web-admin 的无键答复当「没宣告 ⇒ 不围栏」的部署自此保持围栏。
25
+ 删掉 `undeclared` 那一臂,`unreadable` 一律按「没有这一拍答复」处置(`why` 多一个词 `capabilities-absent`,与另两因同处置)。
26
+
27
+ ### 律(各一条)
28
+
29
+ **写权限**:一个事实一个读法 —— 谁能写这个域的这些字段,只问 `writeRoleFor`;「改了哪些字段」只问 `changedWriteFields`(同一张表对两份文档作差,整域 PUT / PATCH 之后的整文档 / 铸造 / 批量 / 导入 / 回滚都经它)。
30
+ 表在类型上穷举(登记形多一个键而没给角色 ⇒ 编译红,新字段不会悄悄落进底);「改了哪些字段」读的是将被存下的那份文档(两份都经 `parseDomain`,即写时校验用的那一只读法),校验器拒的 / 读不出的文档按全字段算(失败方向是抬权,一个出口),字段名不在表里 ⇒ `RangeError`(不静默落回底)。
31
+
32
+ **能力读数**:沉默从不放松围栏 —— 一拍心跳答复是能力读数,当且仅当它是对象、`capabilities` 是它的自有键、值过 `WebAdminCapabilities`。别的一律不是读数,引擎当没有这一拍答复;
33
+ 围栏只被中心的**显式声明对象**解除(`capabilities` 在、`servingLease` 不在 = 中心自己说租约关着或调用方走共享令牌)。
34
+
35
+ ### 读数变化(逐条)
36
+
37
+ 1. `writeRoleFor("projects", [字段])`:`goal` / `contextItems` / `notes` ⇒ `publisher`;`displayName` / `gitRemotes` / `defaultScopes` / `archivedAt` / `icon` / `color` / `registeredBy` / `registeredAt` 与空字段单 ⇒ `editor`(底);一笔里有一个内容字段 ⇒ 整笔 publisher。其余域的 `writeRoleFor(域, [])` 与旧 `domainWriteRole(域)` 逐域相同(钉)。
38
+ 2. `changedWriteFields("projects", before, after)`:新增 / 删除 / 值不同的表内字段,任一条目上有差即算,按表的次序各一次;新登记一条带内容 ⇒ 含内容字段(editor 登记时就不能埋条目);重发没改的字段、键序不同 ⇒ 没改;`before` 缺席传 `undefined`。
39
+ 两份文档都经 `parseDomain` 读:校验器剥掉的未声明键不算被写,`ownKeys` 陷阱藏起键的 Proxy 文档、隐藏键等,读到的就是校验器读到的那一份;校验器拒的 / 读不出的文档(不是对象 / 会抛的 getter 或陷阱 / 环 / 条目缺必填键或字段形坏 / 文档级判据不过 / 库里已不再过 schema 的旧文档)⇒ 全字段。没有逐字段行的域 ⇒ `[]`。
40
+ 3. `readCapabilityReading`:体是对象而键缺席(含键的值是 `undefined`、键只靠原型链可见)⇒ `unreadable` / `capabilities-absent`(此前 `undeclared`);显式 `capabilities: {}` ⇒ `declared` 无位(不变);`not-an-object` / `invalid-capabilities` 两因的答案不变。
41
+ 4. `declared.capabilities` 是新对象:原型是包的隔离原型(不继承 `Object.prototype`)、只含已设的已知位(未知位照剥)、位是自有数据属性 —— `Object.prototype.servingLease` 被污染成 `true` 时,空声明读出的位仍是 `undefined`(此前交的对象继承它,读成开位)。
42
+ 5. 文档句:`LEASE_STATES` 的 `none` = 最近一次可读声明没带 `servingLease`,`expired` 含「还没听到过任何声明的成员推定在围栏内、失联钟从起步算」;兼容门的说法收窄为「对带键的心跳路径成立」;读器头注不再有「读之前没有租约」一句。
43
+
44
+ ### 三问
45
+
46
+ **写权限**
47
+ - **谁需要**:用项目上下文注入的部署 —— `goal` / `notes` 进系统提示、`contextItems` 的 folder / file 条目进任务工作区与附件,与 `prompts` 同级;注入面上线之前,editor 不该能先埋条目。
48
+ - **谁受伤**:今天以 editor 改项目 `goal` / `contextItems` / `notes` 的用户(含登记项目时就带这三个字段的铸造)—— 升级后这类写要 publisher,被拒;只改名字、remotes、默认 scope、图标、颜色、归档的 editor 不受影响。
49
+ - **补偿**:身份索引字段留 editor(整域抬 publisher 会把改个名字也抬走,故不抬);要改内容的用户给 publisher 角色,或由 publisher 代写;权限图用 `writeRoleFor("projects", [])` 与 `writeRoleFor("projects", ["goal"])` 分别问「能不能进编辑页」与「能不能改目标」。
50
+
51
+ **能力读数**
52
+ - **谁需要**:用服务租约围栏成员的舰队 —— 一个只是「不是声明」的答复(网关或维护页答 `{}`、指错的基址、回滚前的 web-admin)不该解除围栏。
53
+ - **谁受伤**:心跳实际打到不带 `capabilities` 键的后端的成员(老 web-admin、另路由的活性基址、回滚版):从「读成没宣告 = 不围栏」变「不是读数 = 围栏保持」,到引擎的失联额度用完后拒新工作。现行能渲成员世代的 web-admin 发行版的心跳答复都带这个键。
54
+ - **补偿**:让心跳路径答到带键的 web-admin(升级它,或修正活性基址);不要围栏的成员去掉 fleet 世代;到点之前引擎逐拍计数并响亮告警(消费方的处置,见 §23)。
55
+
56
+ ### 导出面
57
+
58
+ - **删除**:`domainWriteRole`(主桶与 `./config-fns`)。读它的代码编译红,是应得的通知;替换见上。
59
+ - **新增**:`writeRoleFor` · `changedWriteFields` · `DOMAIN_FIELD_WRITE_ROLE`(值)· `DomainFieldWriteRoles`(类型),都在主桶与 `./config-fns`。
60
+ - **类型变**:`CapabilityReading` 删 `{ kind: "undeclared" }` 一臂,`unreadable.why` = `not-an-object` | `capabilities-absent` | `invalid-capabilities`。
61
+ - **读法变**:`readCapabilityReading`(见读数变化 3 / 4);签名不变。
62
+ - 值不变:`DOMAIN_WRITE_ROLE`、`DEFAULT_DOMAIN_WRITE_ROLE`、`LEASE_STATES`(四词)、`WebAdminCapabilities`、`HEARTBEAT_REPLY_CAPABILITIES_KEY`。
63
+
64
+ ### 各消费方
65
+
66
+ | 消费方 | 读点 | 动作 |
67
+ |---|---|---|
68
+ | server | 引擎侧唯一的能力读者(`capabilityReadingOf` 与按 `kind` 的穷举 switch;`AnnounceReplyFlaw` 取 `unreadable` 的 `why`)· 调用方信任里 `domainWriteRole("governance")` 两处 · 项目登记的写口(若有) | 提货后 `case "undeclared"` 编译红:删那一臂,`capabilities-absent` 与另两因同处置(推定围栏、逐拍计数);`domainWriteRole("governance")` ⇒ `writeRoleFor("governance", [])`(读数不变);项目登记的写口照读 `writeRoleFor("projects", changedWriteFields(...))`,不在本地抄角色 |
69
+ | web-admin | 写口的角色判(`effectiveDomainWriteRole` 与客户端权限图共用的那一只)· 项目页的内容控件 · 整域 PUT / PATCH / 批量 / 导入 / 回滚 / 铸造 / 认领各门 · 心跳答复的写者 | `domainWriteRole` 编译红:判一次写 = `writeRoleFor(域, changedWriteFields(域, 库里的文档, 要存的文档))`;权限图 = `writeRoleFor(域, [])` / `writeRoleFor(域, [字段])`;`governance` 的 admin 抬级照旧加在那一只函数外;心跳答复继续带 `capabilities` 键(不带键的答复现在读成没有读数) |
70
+ | cli | `cloudResources` 里四个资源域写角色的镜像 | **点名 cli**:零改动(不含 `projects`,读数不变) |
71
+ | client-core | 无直接调用 | **点名 client-core**:零改动 |
72
+ | sdk | 契约套件的一致性语料不含这两处读法 | 零代码改动;随同版契约套件对拍 |
73
+ | test | 黑盒判据 | 新格:editor 改项目 `goal` / `contextItems` / `notes`(PUT、PATCH、登记时带内容)⇒ 拒,改 `displayName` / 颜色 ⇒ 过,publisher 都过 · 心跳答 `{}` 的网关后面的成员 ⇒ 不因这一拍答复解围栏 |
74
+
75
+ ### 耐久数据面
76
+
77
+ 不配一次性迁移:存下来的 `projects` 文档一字不改,变的是写口对它的判;心跳答复是瞬时 wire,不落盘。
78
+
79
+ ### 已知限制
80
+
81
+ - **`defaultScopes` 与 `gitRemotes` 本版按身份索引字段留在 editor**:前者是会话默认记忆 scope 的种子、后者是 remote → 项目的找回阶梯的键;若消费方把它们当授权依据读,它们要在同一张表里补一行 —— 本版不在评审环里加这一臂,另案。
82
+ - **角色表答不了「不许改」**:`registeredBy` / `registeredAt` 由写口在登记时盖章,editor 经整域 PUT 能不能改写已登记的这两个值是写口自己的规则(抬它们的角色会让 editor 连登记都登不了)。
83
+ - **铸造 / 认领门是消费方的**:本包不包含这些端点;它们必须把「新条目带了哪些字段」经 `changedWriteFields` 交给 `writeRoleFor`,否则 editor 可经铸造带内容登记。
84
+ - **心跳答复无键的后端**:读成没有读数后围栏保持,是对「沉默不放松围栏」的有意收紧(见三问);这个读器无法区分「老 web-admin」与「指错基址的某个答 200 `{}` 的服务」,分不出,也不必分 —— 两者都不是声明。
85
+
86
+ ### 钉
87
+
88
+ `test/field-write-role-25.0.0.test.ts`(61 格:读口 —— 内容字段 ⇒ publisher、身份字段 / 空字段单 ⇒ editor、最高者、每个域 `writeRoleFor(域, [])` ≡ 底、字段名不在表里 ⇒ `RangeError`、`domainWriteRole` 退役 · 表 —— 键恰是登记形的全部键、内容字段恰三个、PATCH 能改的键都在表里、`Object.prototype` 污染不长出一行 ·
89
+ `changedWriteFields` —— 整域 PUT 带 `contextItems` 变动 ⇒ publisher、只改名字 / 颜色 ⇒ editor、重发 / 键序不同 ⇒ 空、删除与清空 ⇒ 内容变动、铸造带内容 ⇒ publisher、删整条 ⇒ 含它的内容字段、缺席文档、PATCH 经 `applyProjectPatch` 同一只、次序与去重 · 十四种校验器拒的文档 × 两侧 ⇒ 全字段 · 「一个读法」五格(`ownKeys` 列空的 Proxy 文档 / 条目、隐藏键、陷阱抛、`Map`:差 ≡ `parseDomain` 读到的那份的差)+ 授权读到被藏起的 `goal` + 未声明键不算被写 · 污染格 · 文档句)。
90
+ `test/capability-reading-25.0.0.test.ts`(13 格:体是对象键缺席的四种形 / 键值 `undefined` / 键只靠继承 ⇒ `capabilities-absent` · 显式空声明 ⇒ `declared` 无位 · 带位 / 未知位剥 · 不变的两因 · 位只认自有属性 · 副本在隔离原型上且与调用方对象脱钩 · 敌意输入不抛 · 类型面与穷举 switch 两词 · `src/fleet.ts` 里 `undeclared` 零命中 · 头注无「读之前没有租约」)。
91
+ 红先:基 v24.0.0 上读能力的 13 格 8 红(其余 5 格是不变的两因 / 正控 / 敌意输入),写权限一文件整体红(两只函数与表不存在,`projects` 的 `goal` 变动 editor 直接过)。
92
+ 随律翻面的老格逐格注明 25.0.0:`fleet-9.0.0`(7 格:`undeclared` 三格改 `capabilities-absent`、穷举 switch 与类型面、三条注释钉)· `fleet-8.2.0` · `fleet-readers-own-keys-14.7.0` · `read-answers-table-14.7.0` · 读 `domainWriteRole` 的四个文件改读 `writeRoleFor(域, [])`(`own-key-readers-14.7.0` / `plugins` / `redesign-0.6` / `prompts-domain-14.0.0`)。
93
+ 变异(22 条,杀 21):内容字段三者各改回 editor · 身份字段过抬 · 读口忽略底 · 未知字段落回底 · 校验器拒的文档答空单 · 差集漏删除的整条 · 只比存在不比值 · 表行与底借原型链(两处)· 文档不经 `parseDomain` 直读 · 旧 `domainWriteRole` 别名回来 · 旧理由句回来;读器:键缺席读成 `declared` · 交校验器的原对象 · 交寻常对象副本 · 缺席归 `invalid-capabilities` · 载体键用 `[[Get]]` 读 · `undeclared` 回到注释 · 头注回旧句 —— 每一条对应格都红。唯一存活的一条是等价变异:条目表那一键在校验结果上改用 `[[Get]]`(校验结果是新铸的寻常对象,这个键恒是它的自有键)。
94
+
95
+ **自 v24.0.0 起运行期代码有改动的公开导出(机器重算;上界 —— 可达 ≠ 一定变,不可达 ⇒ 一定不变;本版新增的导出不入表)**
96
+
97
+ ```text
98
+ readCapabilityReading [., ./fleet]
99
+ ```
100
+
101
+ 读数真变的是 `readCapabilityReading`(见读数变化 3 / 4);写权限一侧是删一个导出、加四个导出(新增不入表),既有导出的读数逐字不变。
102
+
11
103
  ## 24.0.0 — 2026-11-07 — major:收紧域的最后一个 `skills` 移出逐条丢弃集、读档 throw;wire 上的 skills 清单与域文档同一只判官;**条目是对象,一张值名单是一个值**(逐条丢弃只丢对象条目,`ATOMIC_SALVAGE` 退役)
12
104
 
13
105
  > 档位(按发版纪律):**major** —— 校验收紧(同一份文档在视图面读出的生效配置会变:`skills` 里一条坏条目由「丢那一条」变「整域读不进、读档 throw」;线上清单同读;
package/README.md CHANGED
@@ -47,6 +47,19 @@ therefore shows only `zod`. Node built-ins only (`node:crypto`, `node:fs`).
47
47
  > zod 3, nested inside every zod-4 host). The move to zod 4 did not change what any schema accepts or produces —
48
48
  > the conformance corpus reads byte-identically on both — only the wording of validation errors (see CHANGELOG 11.0.0).
49
49
 
50
+ ## 升级指引:24.0.x → 25.0.0(BREAKING:写权限读口只有一只 `writeRoleFor`,`projects` 的 `goal` / `contextItems` / `notes` 要 publisher,`domainWriteRole` 删 · 能力读数两态,`CapabilityReading` 删 `undeclared`)
51
+
52
+ 两处**不加性**的边(律、读数逐条、三问与各消费方改法见 CHANGELOG 25.0.0 与 `docs/CONSUMER-INTEGRATION.md` §23):
53
+
54
+ 1. **写权限按字段抬权**:`domainWriteRole(domain)` 删,换 `writeRoleFor(domain, changedFields)`(底 = `DOMAIN_WRITE_ROLE` 的行,逐字段角色表 = `DOMAIN_FIELD_WRITE_ROLE`,取最高者)。
55
+ `projects` 登记的 `goal` / `contextItems` / `notes` 是进系统提示与任务工作区的内容,改它们要 `publisher`;名字、remotes、默认 scope、图标、颜色、归档时刻仍是 `editor`。
56
+ 「这次写改了哪些字段」问 `changedWriteFields(domain, 库里的文档, 要存的文档)`(整域 PUT / PATCH 之后的整文档 / 铸造同一只;两份文档都经 `parseDomain` 读,校验器拒的 / 读不出的按全字段算)。
57
+ 旧调用 `domainWriteRole(d)` ⇒ `writeRoleFor(d, [])`(读数一格不变,只是现在要你写明「没有字段」)。
58
+ 2. **能力读数两态**:`CapabilityReading` 删 `undeclared`;体是对象而没有 `capabilities` 键(`{}` / `{ ok: true }` / 位平铺在体上)⇒ `{ kind: "unreadable", why: "capabilities-absent" }`,
59
+ 不再是「没宣告 = 不围栏」;显式的 `capabilities: {}` 仍是 `declared` 且无位。`declared.capabilities` 是自有属性的副本(包的隔离原型:不继承 `Object.prototype`)。读 `case "undeclared"` 的代码编译红:删掉那一臂,`unreadable` 一律按「没有这一拍答复」处置。
60
+
61
+ 出路:见 CHANGELOG 25.0.0 的三问;不配一次性迁移(存下来的文档一字不改)。
62
+
50
63
  ## 升级指引:23.0.x → 24.0.0(BREAKING:`skills` 移出逐条丢弃集、读档 throw · wire 上的 skills 清单与域文档同一只判官 · 一张值名单是一个值 · `ATOMIC_SALVAGE` 删除)
51
64
 
52
65
  三处**不加性**的边(律、三问、读数逐条与语料变化见 CHANGELOG 24.0.0):
@@ -459,7 +472,7 @@ settings 单元读不进的成员**不是缺席**(`loosen` 可丢且要响,`tigh
459
472
  - 代际 —— `generation` 是非负整数的**规范十进制串**(`"7"`,不是 `"07"`、不是数字型),判别器 `isCanonicalGeneration`、数值比较 `compareGeneration`;三处 wire 形共用这一条判据。
460
473
  - 服务租约 API 型 —— `ServingLeaseRequest`、`ServingLeaseResponse`(`granted { ttlMs }` / `denied { reason: superseded | retired }` / `unknown` 三词闭集,
461
474
  **`unknown` 不是 `denied` 的一种**,`denied` 只凭正面证据;读器按 `verdict` 键判,`denied` 的原因词读不出时仍是 `denied`,原因读成 `unknown_reason`)、`SERVING_LEASE_TTL_DEFAULT_MS` / `SERVING_LEASE_TTL_FLOOR_MS` / `SERVING_LEASE_DRIFT_MARGIN_MS`、读器 `readServingLeaseRequest` / `readServingLeaseResponse`;
462
- web-admin 能力位 `CenterCapabilities { servingLease?: true }` + `readCenterCapabilities`(9.0.0 起删,由 `readCapabilityReading` 取代,见 9.0.0 升级指引)—— 租约客户端只在位在场时启用,缺席 = web-admin 不支持租约(不续租、不围栏)。
475
+ web-admin 能力位 `CenterCapabilities { servingLease?: true }` + `readCenterCapabilities`(9.0.0 起删,由 `readCapabilityReading` 取代,见 9.0.0 升级指引;25.0.0 起该读器两态)—— 租约客户端只在 `declared` 且位在场时启用;位缺席于**声明对象里** = web-admin 不支持租约(不续租、不围栏),**没有声明**(答复不带 `capabilities` 键)不是「不支持」,是没有读数。
463
476
  - 排空口型 —— `DrainRequest`、`DrainReceipt`(`state: draining | already_draining`)、读器 `readDrainRequest` / `readDrainReceipt`。
464
477
  - `FLEET_GENERATION_ENV` —— 配置渲染器与引擎共用的 generation env 名常量(实例身份 `instanceId` 由引擎每进程自铸,没有 env 名);它同时进了 `RESERVED_WORKER_ENV`,`worker.env` / `secretEnv` 设不了它。
465
478
  - `clampServingLeaseTtlMs(n)` —— 配置的租约 TTL 的唯一夹取点(读不出 ⇒ 缺省 600 000;低于地板 ⇒ 60 000;无上限)。
@@ -491,7 +504,7 @@ settings 单元读不进的成员**不是缺席**(`loosen` 可丢且要响,`tigh
491
504
  `ENV_NAME`/`K8S_QUANTITY` boundaries, every domain's entry/config type.
492
505
  - **Pure config fns** (`config-fns.ts`): `buildEffective` (deterministic — `updatedAt` is a required param),
493
506
  `parseDomain`, `emptyEffective` (epoch-seeded), `statusRowsToPrune`, role helpers (`roleAtLeast`,
494
- `domainWriteRole`, …), `resolveActiveTiers`(0.9.0 档位组→引擎 `RunnerDeps.tiers` 组存 `models.tierGroups`+`models.activeTierGroup`,组切换=换表下发), and the pure data
507
+ `writeRoleFor` / `changedWriteFields` — the one write-role reader and the diff that feeds it, …), `resolveActiveTiers`(0.9.0 档位组→引擎 `RunnerDeps.tiers` 组存 `models.tierGroups`+`models.activeTierGroup`,组切换=换表下发), and the pure data
495
508
  shapes (`User`, `PublishedSnapshot`, …).
496
509
  - **Roster resolution** (`resolve-roster.ts`): `resolveEffectiveForWorker` → the per-worker wire payload.
497
510
  - **Ref integrity** (`cross-domain.ts`): `refIntegrityIssues` + `createSiblingResolver` (the pure half — fleet
@@ -883,6 +896,8 @@ settings 单元读不进的成员**不是缺席**(`loosen` 可丢且要响,`tigh
883
896
  config renderer and read by the engine as its own identity's scope (absent ⇒ `GLOBAL_SCOPE`); a reserved worker env name.
884
897
  **9.0.0** (BREAKING) replaces `readCenterCapabilities` with the three-state reader `readCapabilityReading(reply)` (`declared` |
885
898
  `undeclared` | `unreadable` — a malformed declaration is not an absent one) and types `EngineSignal`'s two config-version keys as numbers.
899
+ **25.0.0** (BREAKING) makes it two-state: `undeclared` is deleted — a reply without the `capabilities` key (or with `undefined` as its value) is not a reading (`unreadable`, `why: "capabilities-absent"`) —
900
+ and `declared.capabilities` is an own-property copy on the package's isolated prototype.
886
901
  - **Declared-but-unvalidated keys** (`PARSE_TRANSPARENT_KEYS`, 2.0.0): the ONE web-admin of keys this package
887
902
  carries verbatim WITHOUT checking their shape, each row naming who does check it (the engine's ingest side or
888
903
  a consumer's enforcement point). Today: `models[].compat` (1.10.0), `models[].headers` (6.4.0; the header-name
@@ -1 +1 @@
1
- 24.0.0
1
+ 25.0.0
@@ -50,15 +50,54 @@ export declare const USER_ROLES: readonly UserRole[];
50
50
  export declare function roleAtLeast(role: UserRole, min: UserRole): boolean;
51
51
  export declare function isRole(v: unknown): v is UserRole;
52
52
  /**
53
- * Minimum role to WRITE a domain. Default = `editor`; `skills` and `mcp` are raised to `publisher`
53
+ * The FLOOR of a domain write: the minimum role any write to the domain needs. Default = `editor`; `skills` and `mcp` are raised to `publisher`
54
54
  * because their content goes straight into the agent's system prompt / tool surface — one edit retargets
55
55
  * the prompt of every worker × scenario that loads it (the mcp/skills design note §3.3, decision §6 Q3 从严).
56
- * Looked up by the [domain] PUT route. Any domain absent here uses {@link DEFAULT_DOMAIN_WRITE_ROLE}.
56
+ * Any domain absent here uses {@link DEFAULT_DOMAIN_WRITE_ROLE}. Nobody reads this table directly: the one reader is
57
+ * {@link writeRoleFor}, which also looks at WHICH fields a write changes ({@link DOMAIN_FIELD_WRITE_ROLE}).
57
58
  */
58
59
  export declare const DEFAULT_DOMAIN_WRITE_ROLE: UserRole;
59
60
  export declare const DOMAIN_WRITE_ROLE: Partial<Record<DomainName, UserRole>>;
60
- /** The minimum role required to write `domain` (the raised gate for skills/mcp, else editor). */
61
- export declare function domainWriteRole(domain: DomainName): UserRole;
61
+ /**
62
+ * The per-field write roles of a domain whose document is a record of entries: ONE role for each field of an entry, exhaustive for the entry's
63
+ * shape (the table is `satisfies`-checked against the entry type, so a field added to the entry without a role is a compile error — a new field
64
+ * cannot default into the floor unseen). `entries` is the document key that holds the record (`projects` ⇒ `{ projects: { <projectId>: <registration> } }`).
65
+ */
66
+ export interface DomainFieldWriteRoles {
67
+ readonly entries: string;
68
+ readonly fields: Readonly<Record<string, UserRole>>;
69
+ }
70
+ /**
71
+ * The domains whose write role depends on WHICH fields a write changes. Same shape of use as {@link DOMAIN_WRITE_ROLE} — a package-owned table,
72
+ * one row per domain, an absent row means "the floor decides" — read only through {@link writeRoleFor}; the changed fields come from
73
+ * {@link changedWriteFields} (the one place that diffs two documents against this table).
74
+ */
75
+ export declare const DOMAIN_FIELD_WRITE_ROLE: Partial<Record<DomainName, DomainFieldWriteRoles>>;
76
+ /**
77
+ * The minimum role to make a write that changes exactly `changedFields` in `domain`: the HIGHEST of the domain's floor ({@link DOMAIN_WRITE_ROLE},
78
+ * else {@link DEFAULT_DOMAIN_WRITE_ROLE}) and the role of each changed field ({@link DOMAIN_FIELD_WRITE_ROLE}). `[]` = a write that changes no
79
+ * field that has a role of its own — the floor alone, which is also the answer to "may this role write anything in the domain at all" (a UI
80
+ * deciding whether to show a write affordance). The PUT, PATCH and mint doors of a domain all ask this ONE function, with the fields
81
+ * {@link changedWriteFields} reports for the document they are about to store. A field name the domain's table does not have — a typo, a
82
+ * field of another domain, any name for a domain with no field table — is a RangeError (the answer would otherwise be the floor, a quiet
83
+ * lowering): a caller's mistake is loud, never an `editor`.
84
+ */
85
+ export declare function writeRoleFor(domain: DomainName, changedFields: readonly string[]): UserRole;
86
+ /**
87
+ * Which fields a write changes: the fields of {@link DOMAIN_FIELD_WRITE_ROLE}`[domain]` whose value differs, in ANY entry, between the stored
88
+ * document `before` and the document about to be stored `after` — in the table's order, each once. This is the one place two documents are
89
+ * diffed against the table, whatever the door: a whole-domain PUT passes the stored and the submitted document; a PATCH passes the stored
90
+ * document and the document {@link applyProjectPatch} returns; a mint passes the stored document and the document with the new entry.
91
+ * Both documents are read through {@link parseDomain}, the reading a write is validated with, so the comparison is between the documents the
92
+ * store would receive: store what you authorized — the parse result, not a second reading of the raw body. A field is changed when it is added
93
+ * (absent → present), removed (present → absent) or its value differs; a new entry changes every field it carries, a removed one every field it
94
+ * carried; resending a field unchanged, or the keys in another order, changes nothing. `before` `undefined` = the domain has no document yet (the
95
+ * only spelling of "nothing stored"). A domain with no field table ⇒ `[]` (the floor alone decides). Fail-closed on the security axis, in ONE
96
+ * arm: a document the domain's schema refuses or cannot read — not an object, a getter or trap that throws, a bad entry, a stored document that
97
+ * no longer passes — or any step of the comparison that fails ⇒ EVERY field of the table, so the write needs the highest role the table names.
98
+ * Never throws.
99
+ */
100
+ export declare function changedWriteFields(domain: DomainName, before: unknown, after: unknown): readonly string[];
62
101
  /** A console user (no secret). */
63
102
  export interface User {
64
103
  username: string;
@@ -18,6 +18,7 @@
18
18
  import { z } from "zod";
19
19
  import { MODEL_ENTRY_REFUSAL_CODES, ModelRefusalsWire } from "./fleet.js";
20
20
  import { UNINSPECTABLE, dataDescriptor, emptyDocument, guardedSafeParse, inspect, isAccessorDescriptor, isolatedObject, ownEntriesOf, ownRow, ownValueOf } from "./own-key-read.js";
21
+ import { stableStringify } from "./hash.js";
21
22
  import { ownEnabledFlag } from "./catalog-manages.js";
22
23
  import { isJsonArray, isPlainJsonObject, jsonShapeOf } from "./plain-json-object.js";
23
24
  import { carriesUserinfo, secretScanForms } from "./secret-scan.js"; // package-private normalization (both scanners read it) + the userinfo judgement (not in the barrel)
@@ -162,10 +163,11 @@ export function isRole(v) {
162
163
  return typeof v === "string" && USER_ROLES.includes(v);
163
164
  }
164
165
  /**
165
- * Minimum role to WRITE a domain. Default = `editor`; `skills` and `mcp` are raised to `publisher`
166
+ * The FLOOR of a domain write: the minimum role any write to the domain needs. Default = `editor`; `skills` and `mcp` are raised to `publisher`
166
167
  * because their content goes straight into the agent's system prompt / tool surface — one edit retargets
167
168
  * the prompt of every worker × scenario that loads it (the mcp/skills design note §3.3, decision §6 Q3 从严).
168
- * Looked up by the [domain] PUT route. Any domain absent here uses {@link DEFAULT_DOMAIN_WRITE_ROLE}.
169
+ * Any domain absent here uses {@link DEFAULT_DOMAIN_WRITE_ROLE}. Nobody reads this table directly: the one reader is
170
+ * {@link writeRoleFor}, which also looks at WHICH fields a write changes ({@link DOMAIN_FIELD_WRITE_ROLE}).
169
171
  */
170
172
  export const DEFAULT_DOMAIN_WRITE_ROLE = "editor";
171
173
  export const DOMAIN_WRITE_ROLE = {
@@ -180,7 +182,7 @@ export const DOMAIN_WRITE_ROLE = {
180
182
  // systems drive CREDENTIAL minting/delivery/rotation (S2/S3) — the credential lifecycle is ≥ the skills tier.
181
183
  systems: "publisher",
182
184
  // access: DELETED in 0.6.0 (域整删,EXPERT-REDESIGN §9)。
183
- // governance (治理三件,0.6.0 从 runtime 拆出): editor(EXPERT-REDESIGN §5 domainWriteRole 同步;
185
+ // governance (治理三件,0.6.0 从 runtime 拆出): editor(与 EXPERT-REDESIGN §5 的写角色表同步;
184
186
  // default 即 editor,故不列条目;此注释即该裁定的落点)。
185
187
  // entitlement governs who-can-USE-what (models/skills/mcp/budget/runtime caps) per principal — a governance +
186
188
  // security surface (budget ceilings, bypass kill-switch) on par with systems. Same raised gate.
@@ -192,8 +194,10 @@ export const DOMAIN_WRITE_ROLE = {
192
194
  prompts: "publisher",
193
195
  // execution (0.8.0): editor — same档 as governance (治理旋钮同类;真安全边界在 service gate,
194
196
  // client-advisory 面不值 publisher 档)。default 即 editor,故不列条目;此注释即该裁定的落点。
195
- // projects (0.10.0, 142-S3): editor — 登记簿是身份索引不是注入面(无 prompt/凭据/可执行内容);
196
- // mint/claim 动作端点与编辑面同档(草案 §3 "该 scope editor+")。default 即 editor,故不列条目。
197
+ // projects (0.10.0): the floor is editor — the registry's identity fields (name, remotes, default scopes, icon, colour, archive time)
198
+ // are an index, an editor's job; default 即 editor,故不列条目。25.0.0: the registration's CONTENT fields (`goal`, `contextItems`, `notes`)
199
+ // are not an index — they ride into the system prompt and the task's workspace — and are raised field by field in
200
+ // {@link DOMAIN_FIELD_WRITE_ROLE}, not by raising the whole domain.
197
201
  // limits (0.19.0): editor —— 与它的前身 runtime 域(11.0.0 retired)同档,刻意不抬 publisher:本域是纯数值
198
202
  // 旋钮,无 prompt 注入面、无凭据、无可执行内容;真正的执法点在消费方的限额闸,发布闸(PUBLISH_MODE /
199
203
  // 审批流)才是"要不要多一道人"的属主。default 即 editor,故不列条目;此注释即该裁定的落点。
@@ -202,9 +206,105 @@ export const DOMAIN_WRITE_ROLE = {
202
206
  // Written out (not left to the default) because the default would be the WRONG answer here.
203
207
  a2a: "publisher",
204
208
  };
205
- /** The minimum role required to write `domain` (the raised gate for skills/mcp, else editor). */
206
- export function domainWriteRole(domain) {
207
- return ownRow(DOMAIN_WRITE_ROLE, domain) ?? DEFAULT_DOMAIN_WRITE_ROLE;
209
+ /**
210
+ * `projects`: a registration's identity fields are an index and stay with the floor (`editor`); its CONTENT fields are what the project hands
211
+ * to the agent — `goal` and `notes` ride into the system prompt, `contextItems` carries folder / file entries the task's workspace and
212
+ * attachments are built from — the same injection surface as `prompts`, so they need `publisher`. `registeredBy` / `registeredAt` are stamped
213
+ * by the write port on registration; whether a caller may rewrite them is that port's rule, not a role (raising them would also block an
214
+ * editor from registering a project at all).
215
+ */
216
+ const PROJECT_FIELD_WRITE_ROLE = {
217
+ displayName: "editor",
218
+ gitRemotes: "editor",
219
+ defaultScopes: "editor",
220
+ registeredBy: "editor",
221
+ registeredAt: "editor",
222
+ notes: "publisher",
223
+ goal: "publisher",
224
+ contextItems: "publisher",
225
+ archivedAt: "editor",
226
+ icon: "editor",
227
+ color: "editor",
228
+ };
229
+ /**
230
+ * The domains whose write role depends on WHICH fields a write changes. Same shape of use as {@link DOMAIN_WRITE_ROLE} — a package-owned table,
231
+ * one row per domain, an absent row means "the floor decides" — read only through {@link writeRoleFor}; the changed fields come from
232
+ * {@link changedWriteFields} (the one place that diffs two documents against this table).
233
+ */
234
+ export const DOMAIN_FIELD_WRITE_ROLE = {
235
+ projects: { entries: "projects", fields: PROJECT_FIELD_WRITE_ROLE },
236
+ };
237
+ /**
238
+ * The minimum role to make a write that changes exactly `changedFields` in `domain`: the HIGHEST of the domain's floor ({@link DOMAIN_WRITE_ROLE},
239
+ * else {@link DEFAULT_DOMAIN_WRITE_ROLE}) and the role of each changed field ({@link DOMAIN_FIELD_WRITE_ROLE}). `[]` = a write that changes no
240
+ * field that has a role of its own — the floor alone, which is also the answer to "may this role write anything in the domain at all" (a UI
241
+ * deciding whether to show a write affordance). The PUT, PATCH and mint doors of a domain all ask this ONE function, with the fields
242
+ * {@link changedWriteFields} reports for the document they are about to store. A field name the domain's table does not have — a typo, a
243
+ * field of another domain, any name for a domain with no field table — is a RangeError (the answer would otherwise be the floor, a quiet
244
+ * lowering): a caller's mistake is loud, never an `editor`.
245
+ */
246
+ export function writeRoleFor(domain, changedFields) {
247
+ let role = ownRow(DOMAIN_WRITE_ROLE, domain) ?? DEFAULT_DOMAIN_WRITE_ROLE;
248
+ const table = ownRow(DOMAIN_FIELD_WRITE_ROLE, domain);
249
+ for (const field of changedFields) {
250
+ const fieldRole = table === undefined ? undefined : ownRow(table.fields, field);
251
+ if (fieldRole === undefined) {
252
+ throw new RangeError(`writeRoleFor: ${JSON.stringify(String(field))} is not a field with a write role in domain "${domain}" (${table === undefined ? "the domain has no field table" : `its fields: ${Object.keys(table.fields).join(", ")}`})`);
253
+ }
254
+ if (ROLE_RANK[fieldRole] > ROLE_RANK[role])
255
+ role = fieldRole;
256
+ }
257
+ return role;
258
+ }
259
+ /**
260
+ * The entries of one domain document as the STORE would receive them: the document read through {@link parseDomain} — the reading a write is
261
+ * validated with — so what {@link changedWriteFields} compares and what is persisted are one document, not two readings of the caller's object
262
+ * (a Proxy that lists no keys but answers the validator's reads, an accessor, a key the validator strips). Anything `parseDomain` refuses or cannot
263
+ * read throws; the caller turns every throw into the fail-closed answer.
264
+ */
265
+ function writeEntriesOf(domain, table, document) {
266
+ const parsed = parseDomain(domain, document); // `undefined` = nothing stored yet = the domain's empty document
267
+ const carried = ownValueOf(parsed, table.entries);
268
+ if (!carried.ok || !isPlainJsonObject(carried.value))
269
+ throw new TypeError(`changedWriteFields: domain "${domain}" has no record of entries under "${table.entries}"`);
270
+ const entries = new Map();
271
+ for (const [id, entry] of Object.entries(carried.value)) {
272
+ if (!isPlainJsonObject(entry))
273
+ throw new TypeError(`changedWriteFields: an entry of domain "${domain}" is not an object`);
274
+ entries.set(id, entry);
275
+ }
276
+ return entries;
277
+ }
278
+ /** What one field of one entry holds, as a string two entries can be compared by: absent and present are different, and a value is compared by its stable JSON. */
279
+ function writeFieldImage(entry, field) {
280
+ return entry === undefined || !Object.hasOwn(entry, field) ? "-" : `=${stableStringify(entry[field])}`;
281
+ }
282
+ /**
283
+ * Which fields a write changes: the fields of {@link DOMAIN_FIELD_WRITE_ROLE}`[domain]` whose value differs, in ANY entry, between the stored
284
+ * document `before` and the document about to be stored `after` — in the table's order, each once. This is the one place two documents are
285
+ * diffed against the table, whatever the door: a whole-domain PUT passes the stored and the submitted document; a PATCH passes the stored
286
+ * document and the document {@link applyProjectPatch} returns; a mint passes the stored document and the document with the new entry.
287
+ * Both documents are read through {@link parseDomain}, the reading a write is validated with, so the comparison is between the documents the
288
+ * store would receive: store what you authorized — the parse result, not a second reading of the raw body. A field is changed when it is added
289
+ * (absent → present), removed (present → absent) or its value differs; a new entry changes every field it carries, a removed one every field it
290
+ * carried; resending a field unchanged, or the keys in another order, changes nothing. `before` `undefined` = the domain has no document yet (the
291
+ * only spelling of "nothing stored"). A domain with no field table ⇒ `[]` (the floor alone decides). Fail-closed on the security axis, in ONE
292
+ * arm: a document the domain's schema refuses or cannot read — not an object, a getter or trap that throws, a bad entry, a stored document that
293
+ * no longer passes — or any step of the comparison that fails ⇒ EVERY field of the table, so the write needs the highest role the table names.
294
+ * Never throws.
295
+ */
296
+ export function changedWriteFields(domain, before, after) {
297
+ const table = ownRow(DOMAIN_FIELD_WRITE_ROLE, domain);
298
+ if (table === undefined)
299
+ return [];
300
+ const fields = Object.keys(table.fields);
301
+ const changed = inspect(() => {
302
+ const was = writeEntriesOf(domain, table, before);
303
+ const now = writeEntriesOf(domain, table, after);
304
+ const ids = [...new Set([...was.keys(), ...now.keys()])];
305
+ return fields.filter((field) => ids.some((id) => writeFieldImage(was.get(id), field) !== writeFieldImage(now.get(id), field)));
306
+ });
307
+ return changed.ok ? changed.value : fields;
208
308
  }
209
309
  /** The empty/defaults effective config at version 0 — what publish mode serves before the first publish.
210
310
  * Seeds the epoch (`new Date(0)`) so it's deterministic (the wall-clock default was the original store.ts
package/dist/fleet.d.ts CHANGED
@@ -94,14 +94,15 @@ export declare function compareGeneration(a: string, b: string): -1 | 0 | 1;
94
94
  /**
95
95
  * The serving lease as the ENGINE holds it — a CLOSED set of four words, owned here (the engine's vocabulary, word for word;
96
96
  * a reader that switches on it exhaustively is told by the compiler when a word is added):
97
- * - `none` — the lease is not in effect: web-admin has declared no {@link WebAdminCapabilities}`.servingLease` ({@link readCapabilityReading}
98
- * says `undeclared` — an older web-admin — or `declared` without the bit). The engine behaves exactly as an engine without a lease —
99
- * no renewals, no fence. A reply that cannot be read (`unreadable`) is not a reading: it does not move the engine into or out of
100
- * `none` — it keeps the state it had.
97
+ * - `none` — the lease is not in effect: web-admin's most recent capability declaration ({@link readCapabilityReading} said `declared`) did
98
+ * not carry {@link WebAdminCapabilities}`.servingLease`. The engine behaves exactly as an engine without a lease — no renewals, no fence.
99
+ * A reply that is not a declaration (`unreadable`: an older web-admin that sends no `capabilities` key, a gateway answering `{}`, a body that
100
+ * cannot be read) is not a reading: it does not move the engine into or out of `none` — it keeps the state it had.
101
101
  * - `granted` — the engine holds a lease; `leaseUntil` says until when (epoch ms, the engine's own computation from the
102
102
  * granted `ttlMs`, see {@link ServingLeaseResponse}).
103
103
  * - `expired` — the lease is in effect but no grant is valid right now (web-admin is unreachable, answered `unknown`, or has
104
- * not granted one yet): the engine keeps serving until its own outage allowance runs out. Not a denial.
104
+ * not granted one yet; a fleet member that has not yet heard any declaration from web-admin is presumed to be inside the fence, its
105
+ * outage clock running from the engine's start): the engine keeps serving until its own outage allowance runs out. Not a denial.
105
106
  * - `denied` — web-admin denied this instance on positive evidence (the `denied` verdict): sticky; the engine is draining and
106
107
  * stops at its deadline.
107
108
  * Only a fleet member says it: an engine without a generation has no lease and carries no `leaseState` at all (there is no
@@ -694,19 +695,23 @@ export declare function readServingLeaseResponse(body: unknown): ServingLeaseRea
694
695
  * What web-admin says it can do: capability bits an engine reads before it starts using a web-admin-side endpoint.
695
696
  * - `servingLease` — web-admin answers serving-lease renewals ({@link ServingLeaseRequest} / {@link ServingLeaseResponse}).
696
697
  *
697
- * A bit is `true` or absent — one spelling for "not supported" (there is no `false`). An absent bit — in a declared object, or
698
- * because web-admin declares nothing at all (an older web-admin) — means web-admin does not support the lease, and the engine then
699
- * neither renews a lease nor is fenced by one: this is the compatibility gate that lets an executor ship ahead of web-admin
700
- * without pushing running engines into lease expiry. It is a gate, not a verdict — nothing in this shape says "web-admin refuses
701
- * leases". Read a heartbeat reply with {@link readCapabilityReading} and start the lease client only on a `declared` reading whose
702
- * `capabilities.servingLease === true`.
698
+ * A bit is `true` or absent — one spelling for "not supported" (there is no `false`). A bit absent from a DECLARED object means web-admin
699
+ * does not support it, and for `servingLease` the engine then neither renews a lease nor is fenced by one: that is web-admin's own word (the
700
+ * lease switched off there, or a caller under the shared token, below). Having NO declaration is a different fact and is not read as "not
701
+ * supported": a heartbeat reply that carries no `capabilities` key (an older web-admin, a gateway or maintenance page answering `{}`) is not
702
+ * a reading ({@link readCapabilityReading} says `unreadable`), and a fleet member that has heard no declaration is presumed to be inside the
703
+ * fence — silence never loosens it. So the compatibility gate this shape gives (an executor may ship ahead of web-admin) holds on the
704
+ * heartbeat path of a web-admin that answers with the key — every web-admin release that can render a fleet generation does; a path whose
705
+ * answer carries no key (a gateway, a differently routed live base, a rolled-back web-admin) leaves the member inside the presumed fence.
706
+ * It is a gate, not a verdict — nothing in this shape says "web-admin refuses leases". Read a heartbeat reply with
707
+ * {@link readCapabilityReading} and start the lease client only on a `declared` reading whose `capabilities.servingLease === true`.
703
708
  * Unknown bits are stripped (a newer web-admin's extra bits never break an older reader); a known bit whose value is not `true` breaks
704
- * the declaration — and a broken declaration is NOT an absent one: the reply reads as `unreadable`, which is not a reading (the engine
709
+ * the declaration — and a broken declaration is NOT an absent bit: the reply reads as `unreadable`, which is not a reading (the engine
705
710
  * keeps the state it had; see {@link readCapabilityReading}).
706
711
  * It rides in ONE place: the heartbeat's 2xx reply ({@link FLEET_PATHS}`.instances`), under {@link HEARTBEAT_REPLY_CAPABILITIES_KEY}.
707
712
  * Web-admin answers the bits per CALLER CREDENTIAL: under a per-worker token, by what web-admin supports; under the shared token
708
713
  * `servingLease` is always absent (the serving-lease endpoint takes per-worker tokens only, so announcing it there would only push
709
- * that caller into the unreachable arm).
714
+ * that caller into the unreachable arm) — an empty declaration, `{ capabilities: {} }`, not a reply without the key.
710
715
  */
711
716
  export declare const WebAdminCapabilities: z.ZodObject<{
712
717
  servingLease: z.ZodOptional<z.ZodLiteral<true>>;
@@ -717,34 +722,39 @@ export type WebAdminCapabilities = z.infer<typeof WebAdminCapabilities>;
717
722
  * Web-admin writes `{ …, [HEARTBEAT_REPLY_CAPABILITIES_KEY]: caps }`; the engine reads the whole reply with
718
723
  * `readCapabilityReading(reply)` — the key lookup lives in the reader, one carrier one reader — and only on a 2xx (a failed heartbeat
719
724
  * says nothing about the bits). Nested, not flat: the reply's own keys and the capability bits never share a namespace.
720
- * A reply without the key is an older web-admin — no capability said (`undeclared`). A reply with the key present with a value that
721
- * breaks the shape is NOT "without the key" — it is `unreadable`, and an unreadable reply says nothing: neither declared nor undeclared.
725
+ * A reply without the key is not a declaration — it reads `unreadable` (`capabilities-absent`): an older web-admin, a gateway answering `{}`,
726
+ * bits flat on the body and `undefined` as the key's value (what JSON cannot carry) all read this way, and the engine acts on it as on no reply at all.
727
+ * A reply with the key present with a value that breaks the shape reads `unreadable` too (`invalid-capabilities`). Only an object under this
728
+ * key that passes {@link WebAdminCapabilities} is a reading.
722
729
  */
723
730
  export declare const HEARTBEAT_REPLY_CAPABILITIES_KEY = "capabilities";
724
- /** What one heartbeat reply says about web-admin's capabilities — three readings of the reply, see {@link readCapabilityReading}. */
731
+ /**
732
+ * What one heartbeat reply says about web-admin's capabilities — two words, see {@link readCapabilityReading}: `declared` (an explicit
733
+ * declaration, the only reading) or `unreadable` (the reply is not a declaration; `why` says which way).
734
+ */
725
735
  export type CapabilityReading = {
726
736
  kind: "declared";
727
737
  capabilities: WebAdminCapabilities;
728
- } | {
729
- kind: "undeclared";
730
738
  } | {
731
739
  kind: "unreadable";
732
- why: "not-an-object" | "invalid-capabilities";
740
+ why: "not-an-object" | "capabilities-absent" | "invalid-capabilities";
733
741
  };
734
742
  /**
735
743
  * Engine side: what one heartbeat reply says about web-admin's capabilities. The input is the heartbeat's whole 2xx reply body
736
- * (the key lookup lives here — one carrier, one reader), the output one of three readings:
737
- * - `declared` — the key ({@link HEARTBEAT_REPLY_CAPABILITIES_KEY}) is present and its value passes {@link WebAdminCapabilities};
738
- * `capabilities` is the parsed object (unknown bits stripped, an absent bit stays absent).
739
- * - `undeclared` — the reply is an object and the key is absent: an older web-admin, which has said nothing about capabilities.
740
- * (`undefined` as the key's value is what JSON cannot carry; it reads as the key being absent.)
741
- * - `unreadable` — the reply is not an object (`why: "not-an-object"`), or the key is present but its value is not a
742
- * {@link WebAdminCapabilities} (`why: "invalid-capabilities"`; an accessor that throws reads the same way).
743
- * Only `declared` and `undeclared` are readings. `unreadable` is not a reading: on the fence axis a malformed declaration must not
744
- * read as "web-admin declared nothing", so the engine acts on it as on no reply at all — it keeps the state it last had (before
745
- * any reading: no lease) and leaves its clocks, the lease expiry and the outage allowance, as they were. Start the lease client only
746
- * on `declared` with `capabilities.servingLease === true`. Never throws; judged by the same one guarded body judgement as every
747
- * other reader here.
744
+ * (the key lookup lives here — one carrier, one reader), the output one of two words:
745
+ * - `declared` — the key ({@link HEARTBEAT_REPLY_CAPABILITIES_KEY}) is an own key of the reply and its value passes {@link WebAdminCapabilities}:
746
+ * web-admin made an explicit declaration. `capabilities` is a copy of it — the known bits that are set, as own properties of an object on the
747
+ * package's isolated prototype (unknown bits stripped, an absent bit stays absent and reads `undefined` even when `Object.prototype` is polluted with its name).
748
+ * `{ capabilities: {} }` is a declaration of no bits.
749
+ * - `unreadable` — anything else, and `why` says which way: the reply is not an object (`not-an-object`); the key is absent
750
+ * (`capabilities-absent` — an older web-admin, a body of `{}` or `{ ok: true }`, bits flat on the body, `undefined` as the key's value,
751
+ * a key that exists only on the prototype chain); the key is present but its value is not a {@link WebAdminCapabilities}
752
+ * (`invalid-capabilities`; a hidden key or an accessor that throws reads the same way).
753
+ * Only `declared` is a reading. A reply that is not a declaration says nothing about the fence — silence never loosens it: the engine acts
754
+ * on `unreadable` as on no reply at all. A fleet member that has heard no declaration is presumed to be inside the fence (its outage clock
755
+ * running from its own start); one that has heard a declaration keeps the state that declaration gave it, and leaves its clocks, the lease
756
+ * expiry and the outage allowance, as they were. Start the lease client only on `declared` with `capabilities.servingLease === true`.
757
+ * Never throws; judged by the same one guarded body judgement as every other reader here.
748
758
  */
749
759
  export declare function readCapabilityReading(reply: unknown): CapabilityReading;
750
760
  /**
package/dist/fleet.js CHANGED
@@ -21,7 +21,7 @@ import { z } from "zod";
21
21
  import { INTEGER } from "./integer.js";
22
22
  import { fnv1a64 } from "./hash.js";
23
23
  import { parseDeclared } from "./declared-capture.js";
24
- import { readDeclaredKey, ownValueOf } from "./own-key-read.js";
24
+ import { dataDescriptor, isolatedObject, readDeclaredKey, ownValueOf } from "./own-key-read.js";
25
25
  import { isPlainJsonObject } from "./plain-json-object.js";
26
26
  import { buildQuotedIssue } from "./quoted-issue.js";
27
27
  // ── Web-admin's fleet endpoints (paths, one spelling) ─────────────────────────────────────────────────────
@@ -123,14 +123,15 @@ const Generation = z.string().refine(isCanonicalGeneration, buildQuotedIssue `a
123
123
  /**
124
124
  * The serving lease as the ENGINE holds it — a CLOSED set of four words, owned here (the engine's vocabulary, word for word;
125
125
  * a reader that switches on it exhaustively is told by the compiler when a word is added):
126
- * - `none` — the lease is not in effect: web-admin has declared no {@link WebAdminCapabilities}`.servingLease` ({@link readCapabilityReading}
127
- * says `undeclared` — an older web-admin — or `declared` without the bit). The engine behaves exactly as an engine without a lease —
128
- * no renewals, no fence. A reply that cannot be read (`unreadable`) is not a reading: it does not move the engine into or out of
129
- * `none` — it keeps the state it had.
126
+ * - `none` — the lease is not in effect: web-admin's most recent capability declaration ({@link readCapabilityReading} said `declared`) did
127
+ * not carry {@link WebAdminCapabilities}`.servingLease`. The engine behaves exactly as an engine without a lease — no renewals, no fence.
128
+ * A reply that is not a declaration (`unreadable`: an older web-admin that sends no `capabilities` key, a gateway answering `{}`, a body that
129
+ * cannot be read) is not a reading: it does not move the engine into or out of `none` — it keeps the state it had.
130
130
  * - `granted` — the engine holds a lease; `leaseUntil` says until when (epoch ms, the engine's own computation from the
131
131
  * granted `ttlMs`, see {@link ServingLeaseResponse}).
132
132
  * - `expired` — the lease is in effect but no grant is valid right now (web-admin is unreachable, answered `unknown`, or has
133
- * not granted one yet): the engine keeps serving until its own outage allowance runs out. Not a denial.
133
+ * not granted one yet; a fleet member that has not yet heard any declaration from web-admin is presumed to be inside the fence, its
134
+ * outage clock running from the engine's start): the engine keeps serving until its own outage allowance runs out. Not a denial.
134
135
  * - `denied` — web-admin denied this instance on positive evidence (the `denied` verdict): sticky; the engine is draining and
135
136
  * stops at its deadline.
136
137
  * Only a fleet member says it: an engine without a generation has no lease and carries no `leaseState` at all (there is no
@@ -707,19 +708,23 @@ export function readServingLeaseResponse(body) {
707
708
  * What web-admin says it can do: capability bits an engine reads before it starts using a web-admin-side endpoint.
708
709
  * - `servingLease` — web-admin answers serving-lease renewals ({@link ServingLeaseRequest} / {@link ServingLeaseResponse}).
709
710
  *
710
- * A bit is `true` or absent — one spelling for "not supported" (there is no `false`). An absent bit — in a declared object, or
711
- * because web-admin declares nothing at all (an older web-admin) — means web-admin does not support the lease, and the engine then
712
- * neither renews a lease nor is fenced by one: this is the compatibility gate that lets an executor ship ahead of web-admin
713
- * without pushing running engines into lease expiry. It is a gate, not a verdict — nothing in this shape says "web-admin refuses
714
- * leases". Read a heartbeat reply with {@link readCapabilityReading} and start the lease client only on a `declared` reading whose
715
- * `capabilities.servingLease === true`.
711
+ * A bit is `true` or absent — one spelling for "not supported" (there is no `false`). A bit absent from a DECLARED object means web-admin
712
+ * does not support it, and for `servingLease` the engine then neither renews a lease nor is fenced by one: that is web-admin's own word (the
713
+ * lease switched off there, or a caller under the shared token, below). Having NO declaration is a different fact and is not read as "not
714
+ * supported": a heartbeat reply that carries no `capabilities` key (an older web-admin, a gateway or maintenance page answering `{}`) is not
715
+ * a reading ({@link readCapabilityReading} says `unreadable`), and a fleet member that has heard no declaration is presumed to be inside the
716
+ * fence — silence never loosens it. So the compatibility gate this shape gives (an executor may ship ahead of web-admin) holds on the
717
+ * heartbeat path of a web-admin that answers with the key — every web-admin release that can render a fleet generation does; a path whose
718
+ * answer carries no key (a gateway, a differently routed live base, a rolled-back web-admin) leaves the member inside the presumed fence.
719
+ * It is a gate, not a verdict — nothing in this shape says "web-admin refuses leases". Read a heartbeat reply with
720
+ * {@link readCapabilityReading} and start the lease client only on a `declared` reading whose `capabilities.servingLease === true`.
716
721
  * Unknown bits are stripped (a newer web-admin's extra bits never break an older reader); a known bit whose value is not `true` breaks
717
- * the declaration — and a broken declaration is NOT an absent one: the reply reads as `unreadable`, which is not a reading (the engine
722
+ * the declaration — and a broken declaration is NOT an absent bit: the reply reads as `unreadable`, which is not a reading (the engine
718
723
  * keeps the state it had; see {@link readCapabilityReading}).
719
724
  * It rides in ONE place: the heartbeat's 2xx reply ({@link FLEET_PATHS}`.instances`), under {@link HEARTBEAT_REPLY_CAPABILITIES_KEY}.
720
725
  * Web-admin answers the bits per CALLER CREDENTIAL: under a per-worker token, by what web-admin supports; under the shared token
721
726
  * `servingLease` is always absent (the serving-lease endpoint takes per-worker tokens only, so announcing it there would only push
722
- * that caller into the unreachable arm).
727
+ * that caller into the unreachable arm) — an empty declaration, `{ capabilities: {} }`, not a reply without the key.
723
728
  */
724
729
  export const WebAdminCapabilities = z.object({
725
730
  servingLease: z.literal(true).optional(),
@@ -729,26 +734,50 @@ export const WebAdminCapabilities = z.object({
729
734
  * Web-admin writes `{ …, [HEARTBEAT_REPLY_CAPABILITIES_KEY]: caps }`; the engine reads the whole reply with
730
735
  * `readCapabilityReading(reply)` — the key lookup lives in the reader, one carrier one reader — and only on a 2xx (a failed heartbeat
731
736
  * says nothing about the bits). Nested, not flat: the reply's own keys and the capability bits never share a namespace.
732
- * A reply without the key is an older web-admin — no capability said (`undeclared`). A reply with the key present with a value that
733
- * breaks the shape is NOT "without the key" — it is `unreadable`, and an unreadable reply says nothing: neither declared nor undeclared.
737
+ * A reply without the key is not a declaration — it reads `unreadable` (`capabilities-absent`): an older web-admin, a gateway answering `{}`,
738
+ * bits flat on the body and `undefined` as the key's value (what JSON cannot carry) all read this way, and the engine acts on it as on no reply at all.
739
+ * A reply with the key present with a value that breaks the shape reads `unreadable` too (`invalid-capabilities`). Only an object under this
740
+ * key that passes {@link WebAdminCapabilities} is a reading.
734
741
  */
735
742
  export const HEARTBEAT_REPLY_CAPABILITIES_KEY = "capabilities";
736
743
  /** The reply body as far as the capability carrier is concerned: the one key, optional, nothing else (the reply's other keys are stripped). */
737
744
  const CapabilitiesCarrier = z.object({ [HEARTBEAT_REPLY_CAPABILITIES_KEY]: WebAdminCapabilities.optional() });
745
+ /** The bits {@link WebAdminCapabilities} knows — read off its shape, so a bit added there is copied here without a second list. */
746
+ const CAPABILITY_BITS = Object.keys(WebAdminCapabilities.shape);
747
+ /**
748
+ * The declaration as the reader hands it out: a copy holding exactly the known bits that are set, as OWN data properties of an object on the
749
+ * package's isolated prototype (nothing is inherited from `Object.prototype`). A consumer's `capabilities.servingLease` can then only find a bit web-admin declared — an
750
+ * absent bit is `undefined` even when `Object.prototype` has been polluted with its name, and the copy is not the caller's object. A bit that cannot
751
+ * be read off the validated value (it was parsed from a snapshot, so this cannot happen) ⇒ `undefined`, which the reader answers as `unreadable`,
752
+ * never as a declaration of fewer bits.
753
+ */
754
+ function ownCapabilityBits(validated) {
755
+ const copy = isolatedObject();
756
+ for (const bit of CAPABILITY_BITS) {
757
+ const read = ownValueOf(validated, bit);
758
+ if (!read.ok)
759
+ return undefined;
760
+ if (read.value !== undefined)
761
+ Object.defineProperty(copy, bit, dataDescriptor(read.value));
762
+ }
763
+ return copy;
764
+ }
738
765
  /**
739
766
  * Engine side: what one heartbeat reply says about web-admin's capabilities. The input is the heartbeat's whole 2xx reply body
740
- * (the key lookup lives here — one carrier, one reader), the output one of three readings:
741
- * - `declared` — the key ({@link HEARTBEAT_REPLY_CAPABILITIES_KEY}) is present and its value passes {@link WebAdminCapabilities};
742
- * `capabilities` is the parsed object (unknown bits stripped, an absent bit stays absent).
743
- * - `undeclared` — the reply is an object and the key is absent: an older web-admin, which has said nothing about capabilities.
744
- * (`undefined` as the key's value is what JSON cannot carry; it reads as the key being absent.)
745
- * - `unreadable` — the reply is not an object (`why: "not-an-object"`), or the key is present but its value is not a
746
- * {@link WebAdminCapabilities} (`why: "invalid-capabilities"`; an accessor that throws reads the same way).
747
- * Only `declared` and `undeclared` are readings. `unreadable` is not a reading: on the fence axis a malformed declaration must not
748
- * read as "web-admin declared nothing", so the engine acts on it as on no reply at all — it keeps the state it last had (before
749
- * any reading: no lease) and leaves its clocks, the lease expiry and the outage allowance, as they were. Start the lease client only
750
- * on `declared` with `capabilities.servingLease === true`. Never throws; judged by the same one guarded body judgement as every
751
- * other reader here.
767
+ * (the key lookup lives here — one carrier, one reader), the output one of two words:
768
+ * - `declared` — the key ({@link HEARTBEAT_REPLY_CAPABILITIES_KEY}) is an own key of the reply and its value passes {@link WebAdminCapabilities}:
769
+ * web-admin made an explicit declaration. `capabilities` is a copy of it — the known bits that are set, as own properties of an object on the
770
+ * package's isolated prototype (unknown bits stripped, an absent bit stays absent and reads `undefined` even when `Object.prototype` is polluted with its name).
771
+ * `{ capabilities: {} }` is a declaration of no bits.
772
+ * - `unreadable` — anything else, and `why` says which way: the reply is not an object (`not-an-object`); the key is absent
773
+ * (`capabilities-absent` — an older web-admin, a body of `{}` or `{ ok: true }`, bits flat on the body, `undefined` as the key's value,
774
+ * a key that exists only on the prototype chain); the key is present but its value is not a {@link WebAdminCapabilities}
775
+ * (`invalid-capabilities`; a hidden key or an accessor that throws reads the same way).
776
+ * Only `declared` is a reading. A reply that is not a declaration says nothing about the fence — silence never loosens it: the engine acts
777
+ * on `unreadable` as on no reply at all. A fleet member that has heard no declaration is presumed to be inside the fence (its outage clock
778
+ * running from its own start); one that has heard a declaration keeps the state that declaration gave it, and leaves its clocks, the lease
779
+ * expiry and the outage allowance, as they were. Start the lease client only on `declared` with `capabilities.servingLease === true`.
780
+ * Never throws; judged by the same one guarded body judgement as every other reader here.
752
781
  */
753
782
  export function readCapabilityReading(reply) {
754
783
  const judged = judgeSignalBody(reply, WHOLE_BODY, CapabilitiesCarrier);
@@ -760,8 +789,12 @@ export function readCapabilityReading(reply) {
760
789
  case "read": {
761
790
  // the validated output is an ordinary object: an absent optional key must stay absent, not be read off a polluted `Object.prototype` — own key only (it was parsed from a snapshot, so it cannot be unreadable)
762
791
  const carried = ownValueOf(judged.value, HEARTBEAT_REPLY_CAPABILITIES_KEY);
763
- const capabilities = carried.ok ? carried.value : undefined;
764
- return capabilities === undefined ? { kind: "undeclared" } : { kind: "declared", capabilities };
792
+ if (!carried.ok)
793
+ return { kind: "unreadable", why: "invalid-capabilities" };
794
+ if (carried.value === undefined)
795
+ return { kind: "unreadable", why: "capabilities-absent" };
796
+ const capabilities = ownCapabilityBits(carried.value);
797
+ return capabilities === undefined ? { kind: "unreadable", why: "invalid-capabilities" } : { kind: "declared", capabilities };
765
798
  }
766
799
  default: {
767
800
  const unhandled = judged;
@@ -4,9 +4,9 @@
4
4
  > 每次全量重算并逐名比对 —— 加 / 删 / 改形一个导出而不重生成本档 ⇒ 红。导出面的每次变动因此以本档的 diff 出现在评审里。
5
5
  > 形:`value` = 运行期拿得到的值;`type` = 只在类型层;`value+type` = 同名的值与类型(zod schema 与它推出的类型)。
6
6
 
7
- 子路径 24 条(资产出口 `./package.json` / `./fleet-paths.json` 不是模块,不列),导出名合计 1517 个(同名在多条子路径上各计一次)。
7
+ 子路径 24 条(资产出口 `./package.json` / `./fleet-paths.json` 不是模块,不列),导出名合计 1523 个(同名在多条子路径上各计一次)。
8
8
 
9
- ## `.`(793)
9
+ ## `.`(796)
10
10
 
11
11
  - `A2aConfig` — value+type
12
12
  - `A2aPeerSpec` — value+type
@@ -106,6 +106,7 @@
106
106
  - `DISPATCH_STRATEGIES` — value
107
107
  - `DOMAINS` — value
108
108
  - `DOMAIN_ENTRY_SALVAGE` — value
109
+ - `DOMAIN_FIELD_WRITE_ROLE` — value
109
110
  - `DOMAIN_READ_FALLBACK` — value
110
111
  - `DOMAIN_SCHEMAS` — value
111
112
  - `DOMAIN_WRITE_ROLE` — value
@@ -130,6 +131,7 @@
130
131
  - `DispatchPolicy` — value+type
131
132
  - `DispatchStrategy` — type
132
133
  - `DomainConfig` — type
134
+ - `DomainFieldWriteRoles` — type
133
135
  - `DomainName` — type
134
136
  - `DrainPhase` — type
135
137
  - `DrainReceipt` — value+type
@@ -631,6 +633,7 @@
631
633
  - `buildRetiredEnvWire` — value
632
634
  - `canSwitchScope` — value
633
635
  - `catalogManagesModelPlane` — value
636
+ - `changedWriteFields` — value
634
637
  - `clampServingLeaseTtlMs` — value
635
638
  - `classifyHooksConfig` — value
636
639
  - `classifyTimeClaims` — value
@@ -647,7 +650,6 @@
647
650
  - `describeNotStringRecord` — value
648
651
  - `describeValueShape` — value
649
652
  - `deviceRelayFlaws` — value
650
- - `domainWriteRole` — value
651
653
  - `drainVerdict` — value
652
654
  - `effectiveScopeRole` — value
653
655
  - `emptyEffective` — value
@@ -800,6 +802,7 @@
800
802
  - `withheldNameToken` — value
801
803
  - `workerRouteKey` — value
802
804
  - `workersReferencingSecret` — value
805
+ - `writeRoleFor` — value
803
806
  - `wsUrlFlaws` — value
804
807
 
805
808
  ## `./types`(154)
@@ -1023,7 +1026,7 @@
1023
1026
  - `resolveEffectiveForWorker` — value
1024
1027
  - `rosterMarkerRoles` — value
1025
1028
 
1026
- ## `./config-fns`(54)
1029
+ ## `./config-fns`(57)
1027
1030
 
1028
1031
  - `ANY_INDEX` — value
1029
1032
  - `ApprovePublishResult` — type
@@ -1032,9 +1035,11 @@
1032
1035
  - `DEFAULT_DOMAIN_WRITE_ROLE` — value
1033
1036
  - `DISCLOSABLE_IDENTITY_RE` — value
1034
1037
  - `DOMAIN_ENTRY_SALVAGE` — value
1038
+ - `DOMAIN_FIELD_WRITE_ROLE` — value
1035
1039
  - `DOMAIN_READ_FALLBACK` — value
1036
1040
  - `DOMAIN_WRITE_ROLE` — value
1037
1041
  - `DROPPED_ENTRY_REASON_CODES` — value
1042
+ - `DomainFieldWriteRoles` — type
1038
1043
  - `DroppedEntry` — type
1039
1044
  - `DroppedEntryIdentity` — type
1040
1045
  - `DroppedEntryReasonCode` — type
@@ -1057,7 +1062,7 @@
1057
1062
  - `WarningProjection` — type
1058
1063
  - `WorkerLifecycleRecord` — type
1059
1064
  - `buildEffective` — value
1060
- - `domainWriteRole` — value
1065
+ - `changedWriteFields` — value
1061
1066
  - `emptyEffective` — value
1062
1067
  - `formatConfigPath` — value
1063
1068
  - `isDisclosableIdentity` — value
@@ -1079,6 +1084,7 @@
1079
1084
  - `sanitizeZodError` — value
1080
1085
  - `statusRowsToPrune` — value
1081
1086
  - `withheldNameToken` — value
1087
+ - `writeRoleFor` — value
1082
1088
 
1083
1089
  ## `./conformance`(70)
1084
1090
 
@@ -18,6 +18,7 @@
18
18
  > **22.0.0** 的逐条丢弃域里条目体内带未知键的条目整条丢(新词 `entry-unknown-key`;此前剥键照装)与 `salvageEntries` 必填的第三个参数 `domain` 在 §21。
19
19
  > **23.0.0** 的 `scenarios` / `plugins` 移出逐条丢弃集(条目缺席会放宽的域:坏形条目整域读不进,条目体内的未知键回到剥键 + 点名)在 §21 末「23.0.0 起」段。
20
20
  > **24.0.0** 的 `skills` 移出逐条丢弃集(读档 throw)、wire 上的 skills 清单与域文档同一只判官、「一张值名单是一个值」与 `ATOMIC_SALVAGE` 删除在 §22。
21
+ > **25.0.0** 的写权限读口(只有一只 `writeRoleFor`,逐字段角色表 `DOMAIN_FIELD_WRITE_ROLE`,`domainWriteRole` 删)与能力读数两态(`CapabilityReading` 删 `undeclared`)在 §23。
21
22
 
22
23
  ---
23
24
 
@@ -789,3 +790,35 @@ fleet 成员对中心公告的可达地址(`FLEET_ADVERTISE_ADDRESS`,中心往
789
790
  | sdk | 契约套件按发出的包字节跑一致性语料 | 零代码改动;语料读数变 4 条(`c34` `c36` `c37` `c87`),同版对拍 |
790
791
  | web-admin | 诊断口 `salvageEntries(DOMAIN_SCHEMAS.projects, raw, "projects")` · 视图面读 · 清单的写侧(`toSkillsManifest`) | 零改动;诊断口对 `gitRemotes` / `defaultScopes` 坏一个元素报整条登记(此前报元素) |
791
792
  | test | 黑盒判据 | 新格:skills 覆盖条目坏 ⇒ 整份候选被拒、出厂技能不回位 · 拒绝名单坏一个元素 ⇒ 不截短 · mcp `allowTools` 坏一个元素 ⇒ 那台服务器不挂载 |
793
+
794
+ ## 23. 写权限按字段抬权 · 能力读数两态(25.0.0 起)—— server、web-admin、cli、client-core、sdk、test 各自的读法
795
+
796
+ ### 23.1 写权限:读口只有一只 `writeRoleFor(domain, changedFields)`
797
+
798
+ - **读法**:一次写需要的角色 = 域的**底**(`DOMAIN_WRITE_ROLE` 的行,缺席 ⇒ `DEFAULT_DOMAIN_WRITE_ROLE` = editor)与**被改字段**各自角色(`DOMAIN_FIELD_WRITE_ROLE`)的最高者。`domainWriteRole(domain)` 删(零别名):
799
+ 读它的代码编译红,旧调用 `domainWriteRole(d)` 写成 `writeRoleFor(d, [])`(没有字段 = 只问底,读数一格不变——「某角色在这个域里到底能不能写点什么」就是这一问)。
800
+ - **今天有逐字段行的域只有 `projects`**(条目在文档的 `projects` 键下):`goal` / `contextItems`(folder / file / note 条目)/ `notes` = **publisher**(它们要进系统提示与任务工作区,与 `prompts` 同级的注入面);
801
+ `displayName` / `gitRemotes` / `defaultScopes` / `archivedAt` / `icon` / `color` / `registeredBy` / `registeredAt` = editor(登记簿的身份索引不整域抬)。表在类型上穷举:登记形多一个键而没给角色 ⇒ 编译红。
802
+ `registeredBy` / `registeredAt` 留 editor 是因为登记时由写口盖章(抬了,editor 就连登记都登不了);谁能改写已登记的这两个值是写口自己的规则,角色表答不了「不许改」。
803
+ - **「这次写改了哪些字段」只问 `changedWriteFields(domain, before, after)`**:表里的字段,在**任一条目**上从库里的文档 `before` 到要存的文档 `after` 值有差(新增、删除、值不同),按表的次序、各一次;整条登记新增 / 删除 = 它带的每个字段都算;重发没改的字段、键序不同 = 没改。
804
+ `before` 缺席(该域还没有文档)传 `undefined`(缺席的唯一写法)。**整域 PUT**传库里的文档与提交的文档;**PATCH** 传库里的文档与 `applyProjectPatch` 返回的整文档;**铸造 / 认领**传库里的文档与带上新条目的整文档;
805
+ **批量 / 导入 / 回滚**这类把整份文档换进来的门,传当前文档与要换进来的文档。两份文档都经 `parseDomain` 读(提交一份写时校验用的就是这一只读法),所以比的就是**将被存下的那份**——请存校验的结果,不要对原始请求体另读一遍;校验器剥掉的未声明键不算被写。**校验器拒的 / 读不出的文档**(不是对象、会抛的 getter / 陷阱、条目缺必填键或字段形坏、文档级判据不过,包括库里已经不再过 schema 的旧文档)⇒ 答**全字段**,于是需要表里最高的角色:失败方向是抬权(一个出口,不论卡在读哪一步)。
806
+ - **字段名不在这个域的表里**(拼错、别的域的字段、没有逐字段行的域收到任何字段名)⇒ `writeRoleFor` 抛 `RangeError`,不静默落回底。没有逐字段行的域,`changedWriteFields` 恒答 `[]`。
807
+ - 更早几节里写 `domainWriteRole(...)` 的地方(例如 §17 的 `domainWriteRole("a2a")`)一律读作 `writeRoleFor("a2a", [])`。
808
+
809
+ ### 23.2 能力读数:两态,只有显式的 `capabilities` 对象才是读数
810
+
811
+ - **`CapabilityReading` 删 `undeclared`**:`declared`(心跳 2xx 答复体里 `capabilities` 是自有键、值过 `WebAdminCapabilities`)或 `unreadable { why }`;`why` 三词:`not-an-object` · `capabilities-absent`(体是对象而键缺席:老 web-admin、网关或维护页答的 `{}`、位平铺在体上、键的值是 `undefined`、键只在原型链上)·
812
+ `invalid-capabilities`(键在场而形坏、隐藏键、会抛的 getter)。显式的 `capabilities: {}` 仍是 `declared`、无位。
813
+ - **沉默从不放松围栏**:不是声明的答复(`unreadable`)引擎当「没有这一拍答复」:没听到过声明的成员推定在围栏内(失联钟从自己起步算),听到过声明的成员保持那次声明给的状态、钟不动;只有 `declared` 且 `servingLease === true` 起租约客户端,
814
+ `declared` 不带位 = web-admin 自己说「租约关着 / 共享令牌」,才解除围栏。
815
+ - **`declared.capabilities` 是自有属性的副本(包的隔离原型:不继承 `Object.prototype`)**(只含已设的已知位,未知位照剥):`Object.prototype` 被污染出 `servingLease` 时,空声明读出的位仍是 `undefined`,位也不与调用方的对象共享。
816
+
817
+ | 消费方 | 读点 | 动作 |
818
+ |---|---|---|
819
+ | server | 引擎侧唯一的能力读者(`capabilityReadingOf` 与按 `kind` 的穷举 switch;`AnnounceReplyFlaw` 取 `unreadable` 的 `why`)· 调用方信任里 `domainWriteRole("governance")` 两处 · 项目登记的写口(若有) | 提货后 `case "undeclared"` 编译红:删那一臂,`capabilities-absent` 与另两因同处置(推定围栏、逐拍计数);`domainWriteRole("governance")` ⇒ `writeRoleFor("governance", [])`(读数不变);项目登记的写口照读这张表(`writeRoleFor("projects", changedWriteFields(...))`),不在本地抄角色 |
820
+ | web-admin | 写口的角色判(`effectiveDomainWriteRole` 与客户端权限图共用的那一只)· 项目页的内容控件 · 整域 PUT / PATCH / 批量 / 导入 / 回滚 / 铸造 / 认领各门 · 心跳答复的写者(恒带 `capabilities` 键) | `domainWriteRole` 编译红:判一次写 = `writeRoleFor(domain, changedWriteFields(domain, 库里的文档, 要存的文档))`;权限图问「能不能写这个域」= `writeRoleFor(domain, [])`,问「能不能改这个字段」= `writeRoleFor(domain, [字段])`;`governance` 的 admin 抬级是写口自己的一行,照旧在那一只函数外加;心跳答复继续带 `capabilities` 键(不带键的答复现在读成没有读数) |
821
+ | cli | `cloudResources` 里对四个资源域写角色的镜像(models / mcp / skills 与发布) | **点名 cli**:零改动(不含 `projects`,读数不变) |
822
+ | client-core | 无直接调用 | **点名 client-core**:零改动 |
823
+ | sdk | 契约套件的一致性语料不含这两处读法 | 零改动 |
824
+ | test | 黑盒判据 | 新格:editor 改项目 `goal` / `contextItems` / `notes`(PUT、PATCH、登记时带内容)⇒ 403,改 `displayName` / 颜色 ⇒ 过;publisher 都过 · 心跳答 `{}` 的网关后面的成员 ⇒ 不因这一拍答复解围栏 |
package/llms-full.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  <!--
2
2
  llms-full.txt — 自包含全文 · 消费方(使用者)视角 · @sema-agent/settings-schema
3
- 重写日期: 2026-11-07 | 包版本: 24.0.0
3
+ 重写日期: 2026-11-09 | 包版本: 25.0.0
4
4
  生成方式: 无生成脚本——按当前树 src/*.ts 导出面 + package.json + README/CHANGELOG 手写事实版。
5
5
  证据约定: 每条"它怎么工作"的断言附 (文件: 符号) 坐标,刻意不用行号(行号逐版腐烂;符号名由
6
6
  typecheck 与 test/package-surface.test.ts、test/docs-hygiene.test.ts 等常驻门钉住)。无证据推断显式标【推断】。
@@ -239,8 +239,10 @@ entitlement/execution/limits = `none`;`projects` = `salvage`,整域档位仍 `"t
239
239
  --- 24.0.0:条目是对象,一张值名单是一个值 —— 抢救只下钻对象集合,值名单 / 凭据引用整只判(`ATOMIC_SALVAGE` 删除);`skills` 判 `none` + 读档 `throw`;
240
240
  `readEffectiveWire` 上的 skills 清单不再是单列一臂,与域文档同一只读法、同两张表(缺席只有 `undefined`,重名同拒,清单顶层的未知键同样点名) ---
241
241
  - 角色助手:`UserRole`(viewer<editor<publisher<admin)、`ROLE_RANK`/`USER_ROLES`、`roleAtLeast`、`isRole`、
242
- `domainWriteRole(domain)`(默认 editor;skills/mcp/plugins/scenarios/systems/entitlement/prompts/a2a = publisher,
243
- 表在 `DOMAIN_WRITE_ROLE`)。
242
+ 写权限读口只有一只 `writeRoleFor(domain, changedFields)`(25.0.0 起取代 `domainWriteRole`;= 底与被改字段角色的最高者;`[]` = 只问底):
243
+ 底(默认 editor;skills/mcp/plugins/scenarios/systems/entitlement/prompts/a2a = publisher)在 `DOMAIN_WRITE_ROLE`,逐字段角色在 `DOMAIN_FIELD_WRITE_ROLE`
244
+ (今天只有 `projects`:`goal` / `contextItems` / `notes` = publisher,其余登记字段 editor;字段名不在表里 ⇒ RangeError);
245
+ 「这次写改了哪些字段」问 `changedWriteFields(domain, before, after)`(同一张表;两份文档都经 `parseDomain` 读,校验器拒的 / 读不出的按全字段算;(src/config-fns.ts: writeRoleFor, changedWriteFields, DOMAIN_FIELD_WRITE_ROLE))。
244
246
  - 纯数据类型:`User`、`UserAuth`、`PublishedSnapshot`、`PendingPublish`、`ApprovePublishResult`、
245
247
  `CasWriteResult`、`WorkerLifecycleRecord`;错误脱敏 `redactSecrets` / `sanitizeZodError`;
246
248
  `legacyGovernanceFromRuntime`;`statusRowsToPrune`(两 selector 都缺 → `[]`,防全删);`resolveActiveTiers`。
@@ -451,7 +453,7 @@ entitlement/execution/limits = `none`;`projects` = `salvage`,整域档位仍 `"t
451
453
  常量 `SERVING_LEASE_TTL_DEFAULT_MS`(600 000)/ `SERVING_LEASE_TTL_FLOOR_MS`(60 000)/ `SERVING_LEASE_DRIFT_MARGIN_MS`(派生自 `DEFAULT_HEARTBEAT_MS`),
452
454
  `generation` = 非负整数的规范十进制串(`"7"`,不许 `"07"` / 数字型;三处 wire 形同一条判据),判别器 `isCanonicalGeneration(value)`、数值比较 `compareGeneration(a, b)`(`"9"` < `"10"`;非规范入参抛 TypeError);
453
455
  读器 `readServingLeaseRequest` / `readServingLeaseResponse`;`denied` 只凭正面证据(web-admin 持久化的代际下限之下 ⇒ superseded),对象缺席 ⇒ `unknown`;`readServingLeaseResponse` 按 `verdict` 键判,返回 `ServingLeaseReading`(`denied` 的 reason 不在闭集 / 缺 ⇒ 仍是 denied,reason 读成 `SERVING_LEASE_UNKNOWN_REASON` = `"unknown_reason"`;判别词不在三词 ⇒ undefined);
454
- web-admin 能力位 `WebAdminCapabilities { servingLease?: true }` + 三态读器 `readCapabilityReading(reply): CapabilityReading`(9.0.0 起取代 `readCenterCapabilities`;吃心跳 2xx 的整只答复体,答 `declared { capabilities }` | `undeclared`(体是对象、键缺席 = 老 web-admin ⇒ 不续租、不围栏)| `unreadable { why: not-an-object | invalid-capabilities }`(不是读数:键在场而形坏 ≠ 没宣告,引擎保留上一次状态与钟);租约客户端只在 `declared` 且 `servingLease === true` 时启用);排空口型 `DrainRequest { actionId, scope?, worker, expectedGeneration?, instanceId?, deadlineAt, term? }`、
456
+ web-admin 能力位 `WebAdminCapabilities { servingLease?: true }` + 两态读器 `readCapabilityReading(reply): CapabilityReading`(9.0.0 起取代 `readCenterCapabilities`;吃心跳 2xx 的整只答复体,答 `declared { capabilities }`(`capabilities` 键是自有键且值过 schema;`capabilities` 是自有属性的副本,原型是包的隔离原型)| `unreadable { why: not-an-object | capabilities-absent | invalid-capabilities }`(不是读数:体不是对象 / 键缺席——老 web-admin、`{}`、位平铺——/ 键在场而形坏;沉默不放松围栏,引擎当没有这一拍答复);25.0.0 起没有 `undeclared`;租约客户端只在 `declared` 且 `servingLease === true` 时启用);排空口型 `DrainRequest { actionId, scope?, worker, expectedGeneration?, instanceId?, deadlineAt, term? }`、
455
457
  `DrainReceipt = EngineDraining + state ∈ DRAIN_RECEIPT_STATES(draining | already_draining)`,读器 `readDrainRequest` / `readDrainReceipt`;
456
458
  `clampServingLeaseTtlMs(n)`(配置 TTL 唯一夹取点:读不出 ⇒ 缺省,低于地板 ⇒ 地板,无上限;应答的 `ttlMs` 不夹);
457
459
  8.2.0(additive):`LEASE_STATES` = `["none", "granted", "expired", "denied"]` + zod `LeaseState`(引擎持有的租约四态闭集;只有 fleet 成员说它);
package/llms.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  <!--
2
2
  llms.txt — 消费方(使用者)视角索引 · @sema-agent/settings-schema
3
- 重写日期: 2026-11-07 | 包版本: 24.0.0
3
+ 重写日期: 2026-11-09 | 包版本: 25.0.0
4
4
  生成方式: 无生成脚本——按当前树的 src/*.ts 导出面 + package.json + README/CHANGELOG 手写事实版;
5
5
  每条断言附证据坐标(文件:符号),刻意不用行号(行号随每版腐烂,符号名由 typecheck/test 钉住)。
6
6
  刷新触发: package.json 版号变更(test/docs-hygiene.test.ts D 组钉「包版本:」与 package.json 相等、
@@ -159,7 +159,8 @@ llms.txt — 消费方(使用者)视角索引 · @sema-agent/settings-schema
159
159
  `isReadyForTraffic` / `isRoutable` 是它们的布尔形;没有信号(旧引擎)= `no-engine-signal`,不可路由;布尔对 `draining` / `drainingSince` 标 `@deprecated`、本包零读点、退役已登记;
160
160
  8.3.0 additive:env 名常量 `FLEET_SCOPE_ENV`(`"FLEET_SCOPE"`,成员所属租户 scope,渲染器写、引擎读;缺席 = 默认 scope `GLOBAL_SCOPE`;进保留 env 名表);
161
161
  14.7.0 additive:公告地址 env 名常量 `FLEET_ADVERTISE_ADDRESS_ENV`(`"FLEET_ADVERTISE_ADDRESS"`)+「后面要拼路径的基址」座位的禁用成分集 `PATH_BASE_URL_FORBIDDEN_PARTS`(`userinfo` / `query` / `fragment`)+ 判官 `pathBaseUrlFlaws(url)`(= `httpUrlFlaws` 配这一集;判展开之后的值;`webAdminSessionUrl` 也读它);
162
- 9.0.0 BREAKING:`readCenterCapabilities` 删,换三态读器 `readCapabilityReading(reply): CapabilityReading`(`declared` | `undeclared` | `unreadable`;键在场而形坏 ≠ 没宣告)、`EngineSignal.configTargetVersion` / `configAppliedVersion` 由串改数)、**scheduler-store 契约**(自唤醒
162
+ 25.0.0 BREAKING:写权限读口只有一只 `writeRoleFor(domain, changedFields)`(`domainWriteRole` 删;`projects` 的 `goal` / `contextItems` / `notes` 变动要 publisher,逐字段角色表 `DOMAIN_FIELD_WRITE_ROLE`、改了哪些字段问 `changedWriteFields`);`CapabilityReading` 删 `undeclared`(没有 `capabilities` 键的答复 = `unreadable` / `capabilities-absent`,不是读数);
163
+ 9.0.0 BREAKING:`readCenterCapabilities` 删,换读器 `readCapabilityReading(reply): CapabilityReading`(9.0.0 时三态,25.0.0 起 `declared` | `unreadable`;键在场而形坏 ≠ 没宣告)、`EngineSignal.configTargetVersion` / `configAppliedVersion` 由串改数)、**scheduler-store 契约**(自唤醒
163
164
  存储形 + node 绑定)、**auth / auth-bridge / scopes / wire** 契约(RFC 8628 设备流、RS256 JWKS 鉴权桥、
164
165
  多租户 scope)。(src/fleet.ts;src/scheduler-store*.ts;src/api/*.ts)
165
166
  - **web-admin 凭证文件契约**(6.1.0 起):`SEMA_WEB_ADMIN_TOKEN_FILE` 的内容是裸行(首行 = bearer,只收可打印 ASCII)或
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sema-agent/settings-schema",
3
- "version": "24.0.0",
3
+ "version": "25.0.0",
4
4
  "description": "Sema settings schema — pure config contract (zod domains + effective-config + roster resolution + ref-integrity + remoteExec) shared by sema-web-admin, sema-server, and the TOC desktop/CLI. One source of truth. (Renamed at 1.0.0 from @sema-agent/registry-core — name and docs only, no behavior change; note the range moves 0.19.0 -> 1.0.0, so a dependency must become ^1.0.0. The old names @sema-agent/registry-core <=0.19.0 and @sema-ai/registry-core remain published, frozen, for migration.)",
5
5
  "type": "module",
6
6
  "license": "BUSL-1.1",