Repository navigation
Commit f4de1de
fix(spec): one rename rule for every unknown-key suggester (#35639)
<!-- claude-projects-attribution: {"github_login":"os-sales"} -->
_Requested by **Sales** · [project
thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4UuRTHmmdYhGsPrpf8EzYYxUk)_
Part of #35420 — the shared budget rule lands here; the retired-key half
(the card's last sentence) needs no code change under the standing
ruling, see Acceptance notes. The card is closed by hand after merge
with that reading.
Clause-②: no
Metadata-protocol: none
## 维护者速读
-
用户能看到什么变化:元数据作者在对象定义或种子数据里写错一个很短的键名时,报错不再附带一个毫不相干的"你是不是想写"建议;真正差一个字母或两个字母互换的笔误仍会被提示,其余入口不变。
- 为什么做:这是上一轮"短键名拼写建议收紧"的收尾,把同一条规则推到另外两个还在各自计算的报错入口,替编写元数据的作者(多数是
AI)解决被错误建议带偏的问题。
- 出错会怎样:最坏只是报错里的建议文字不准或缺失,任何键的接受与拒绝都不变,可以直接撤回。
- 要你做什么:无需你操作。卡片最后一句(退役旧键是否还附带拼写改名建议)按已有裁决处理:ADR-0087 2026-10-26
修订(#25767
D2=A)规定退役超过一个大版本的键按普通未知键拒绝、给出最接近的拼写并指向协议升级指南,现状正是如此,不改代码,也不另行请你裁定。
## What changes
One rename rule for every unknown-key suggester in `packages/spec`, in a
new leaf module `packages/spec/src/shared/rename-guess.ts` (imports
nothing; not re-exported from `shared/index.ts`, like `alias-probe.ts`):
- `renameBudget(key)` = `max(2, floor(len / 3))`, and
`suggestRename(key, knownKeys)` = the settled rule from the strict
refusal: above five characters the first `findClosestMatches` answer
inside the budget; at five or fewer only a candidate one edit away, an
adjacent swap counted as one; nothing for an empty key.
- `levenshteinDistance` and `findClosestMatches` moved into the leaf
with their docblocks verbatim and are re-exported from
`suggestions.zod.ts`, so the published names and import path are
unchanged (`check:api-surface` green; `export-origins/` regenerated for
the two moved origins). The leaf exists so `data/*.zod.ts` can share the
rule without a cycle through `suggestions.zod.ts` and without adding a
published export.
- Doors now calling it: `strictUnknownKeyError` (unchanged behaviour),
`ObjectSchema.create()` (its private `editDistance` + `suggestKey` copy
is deleted) `defineSeed` (its inline `max(2, floor(len / 3))` is
deleted) and the authoring-key lint `lintAuthoredRecordKeys` in
`data/authoring-key-lint.ts`, which `defineStack` and the CLI report
through (its flat `findClosestMatches(key, candidates, 3, 1)` is
replaced; the `hint?.to ?? (hint?.why ? undefined : …)` precedence is
unchanged). The leaf's header now names every unknown-key door; the
value-vocabulary suggesters (`error-map.zod.ts` enum hint,
`suggestFieldType`) stay on `findClosestMatches`' default on purpose.
- `field-value.zod.ts` and `default-value-shape.ts` held no code copy:
they read the rule through `strictObject` already. Their comments
restated the old budget and lookup and now name `suggestRename`.
- The `strictUnknownKeyError` docblock said its fallback matched
`suggestKey` in `object.zod.ts` (comment 7004171725); it now names
`suggestRename`, which both doors call, so the sentence is true by
construction.
- Nit: the header of
`packages/rest/src/rest-meta-packaged-action-permission-refusal.test.ts`
named the retired data route for the permission-set clone; it now names
`POST /api/v1/security/permission-sets/:name/clone`, the route the
regime table's refusal spells.
Observable change, suggestion text only: `ObjectSchema.create({ page: 1
})` no longer says "did you mean `name`", `defineSeed` no longer answers
a record key `kind` with `id`, and the authoring-key report no longer
answers `aria` with `areas` or an eight-character key three edits away
(`descrptn`) at all, while `dfltValue` → `defaultValue` (nine
characters, budget 3) is still answered. One-edit slips (`nmae`, `labl`,
`queeu`) are still answered. No key is accepted or refused differently.
## Tests
<details><summary>Pins, one per door, plus the rule and a class
guard</summary>
- `data/object.test.ts`: `page` gets no rename; `nmae` → `name`, `labl`
→ `label` still answered.
- `data/define-seed-record-keys.test.ts`: `kind` gets no rename; `queeu`
→ `queue` (adjacent swap) still answered.
- `data/field-value.test.ts`: `LocationValueSchema` `lon` gets no
rename; `lgn` → `lng` still answered.
- `data/default-value-shape.test.ts`: `checkLiteralDefaultValue` on a
location default, same pair.
- `data/authoring-key-lint.test.ts`: `aria` gets no rename; `lable` and
`lbael` → `label` still answered; `descrptn` (8 characters, 3 edits)
gets nothing while `dfltValue` (9 characters, 3 edits) → `defaultValue`.
- `shared/suggestions.test.ts`: `renameBudget`, `suggestRename` (short,
long, empty key), and a guard that no non-test source file under
`packages/spec/src` other than `rename-guess.ts` spells `Math.max(2,
Math.floor(` or hands `findClosestMatches` its own distance (a third
argument) in code (comment lines skipped).
- The strict door's own pins stay in `shared/strict-object.test.ts`
(unchanged).
</details>
<details><summary>Readings (head 945afc3)</summary>
- At 945afc3 (authoring-key-lint fold): `pnpm --filter
@objectstack/spec build && pnpm --filter @objectstack/spec
check:generated` → exit 0 (all 14 artifacts up to date); `pnpm --filter
@objectstack/spec typecheck` → exit 0; `vitest run src/shared/
src/data/authoring-key-lint.test.ts src/data/object.test.ts
src/data/define-seed-record-keys.test.ts src/data/field-value.test.ts
src/data/default-value-shape.test.ts` → 45 files, 1359 tests passed; the
lint's consumers `src/kernel/metadata-authoring-lint.test.ts
src/cron-typed-positions-retirement.test.ts src/stack.test.ts
src/kernel/functional-completeness.test.ts` → 4 files, 216 tests passed.
`dispatch-gates.mjs --commands` derives the same 96 commands and no full
spec suite; `--ran` → 93 run, 3 NOT MEASURED (shallow-clone fixture,
full-workspace dist), including `check:lean-entry-closure` exit 0 after
building objectql.
- Ablation at 945afc3: the call site reverted to
`findClosestMatches(key, candidates, 3, 1)[0]` (import held, then the
call replaced; both anchors x1 then x0, blob ebad5a5 to ad0aef4d):
`authoring-key-lint.test.ts` + `suggestions.test.ts` → 3 failed / 54
passed (the short-key and length-relative cases and the class guard red;
the one-edit slip control stays green). Restored: blob == HEAD ebad5a5,
`git diff HEAD` empty.
- At b8bdbfb (before the fold), the readings below.
- `pnpm --filter @objectstack/spec build && pnpm --filter
@objectstack/spec check:generated` → GEN_EXIT=0 (14 artifacts up to date
after the `export-origins/` regeneration).
- `pnpm --filter @objectstack/spec typecheck` → TC_EXIT=0.
- `pnpm --filter @objectstack/spec test` → Test Files 858 passed (858),
Tests 27414 passed, 1 todo; TEST_EXIT=0.
- Ablation (one, since every door reads one rule): `node
scripts/ablation-replace.mjs` on `rename-guess.ts`, anchor
`foldForScoring(candidate)) <= 1);` hit x1 then x0, blob 06f1011 to
9292b58e; the six harness files ran 8 failed / 367 passed (6 files red:
object, seed, field-value, default-value-shape, strict-object,
suggestions). Restored by the tool; working blob hash equal to the HEAD
blob 06f1011, `git diff HEAD` empty. Expected direction (red) observed.
</details>
## Acceptance notes
- **The retired-key half needs no change: the standing ruling covers
it.** Measured at the `/meta` write door (the real `PUT
/api/v1/meta/:type/:name` route handler of an in-process `RestServer`
over a real `ObjectStackProtocolImplementation` and `SchemaRegistry`,
built dists, head b8bdbfb): a form view body with `defaultSort` answers
`422 INVALID_METADATA` with "Unrecognized key(s) on this inline form
view: `defaultSort`. Did you mean `defaultSort` → `defaults`? Keys
retired before the previous protocol major are no longer prescribed here
— see the protocol upgrade guide…", and the `unrecognized_keys` entry in
`issues[]` names the upgrade guide too. The same probe with `aria`
answers with no guess (the short-key rule working at the door). The
ADR-0087 2026-10-26 amendment (#25767 D2 = A) rules that once a
retirement kit ages out "a removed key is refused as a strict unknown
key whose refusal names the protocol upgrade guide" (ADR-0087 status
line; the same words under D2), which is exactly the reading above. The
amendment is silent on the rename guess a strict unknown-key refusal
carries, so the guess stays the ordinary strict-refusal behaviour.
Keeping a rename guess off a retired key would mean the spec remembers
aged-out keys again, which that amendment chose not to do. The seat
routed this half to that ruling (no B or C option, nothing put to the
maintainer); the card is closed after merge citing this reading.
- The retired checklist item
`access-security.packaged-permission-set-lifecycle` was left unchanged:
its title already says "at the retired sys_permission_set data door" and
its `retiredReason` already names `POST
/api/v1/security/permission-sets/:name/clone`; its steps describe what
the item tested before it retired.
- Other copies of the budget, outside this diff's reach, reported to the
seat and not changed here: `packages/formula/src/validate.ts`
(`nearest`), `packages/lint/src/object-graph.ts`,
`packages/cli/src/utils/collect-docs.ts`. Prose that still describes the
pre-screen budget: `kernel/manifest.zod.ts` (the `hosts` alias comment
says the fallback would answer `hooks`; the short-key screen now refuses
that guess on its own, so the alias fills a gap rather than overruling a
wrong answer).
## Out of scope
Other copies of the rename budget, found by grep and not changed here.
None was measured at a public door, and no card is filed:
- `packages/formula/src/validate.ts:1497` (`nearest`): `max(2, floor(len
/ 3))` without the short-key screen.
- `packages/lint/src/object-graph.ts:809`: the same budget, without the
screen.
- `packages/cli/src/utils/collect-docs.ts:974`: the same budget, without
the screen.
## Verification
Read first, by risk:
1. `packages/spec/src/shared/rename-guess.ts` — `suggestRename` (the
moved rule; the empty-key guard moved into it).
2. `packages/spec/src/shared/suggestions.zod.ts` — the re-export line
and the `strictUnknownKeyError` call site.
3. `packages/spec/src/data/object.zod.ts` — `unknownKeyError` now calls
`suggestRename`.
Two-minute check: `pnpm --filter @objectstack/spec exec vitest run
src/data/object.test.ts src/data/define-seed-record-keys.test.ts` —
expect both files green, including the two new `a short unknown key gets
the shared rename rule` describes.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01L6bhgUZrkMKgGrXXe8zPGq
<!-- signed: repo:objectstack#1 · os-sales ·
session_01L6bhgUZrkMKgGrXXe8zPGq -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 5dd856f commit f4de1de
17 files changed
Lines changed: 439 additions & 205 deletions
File tree
- .changeset
- packages
- rest/src
- spec
- export-origins
- src
- data
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
178 | 178 | | |
179 | 179 | | |
180 | 180 | | |
181 | | - | |
| 181 | + | |
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
106 | | - | |
| 106 | + | |
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
113 | | - | |
| 113 | + | |
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
| 46 | + | |
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| |||
267 | 267 | | |
268 | 268 | | |
269 | 269 | | |
270 | | - | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
271 | 273 | | |
272 | 274 | | |
273 | 275 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
219 | 219 | | |
220 | 220 | | |
221 | 221 | | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
129 | 130 | | |
130 | 131 | | |
131 | 132 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
193 | 193 | | |
194 | 194 | | |
195 | 195 | | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
547 | 547 | | |
548 | 548 | | |
549 | 549 | | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
0 commit comments