Repository navigation
Commit 855c3e1
fix(cli): the hook-body extractor infers member tokens through a body-local alias of ctx.MEMBER (#38731)
<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9JeHmqv6CKCkW8ewrPBLekk)_
Refs #38690 (step 1)
Clause-②: no
Metadata-protocol: none
## 维护者速读
-
用户能看到什么变化:开发者把钩子或动作处理函数里的日志、编号、邮件、动态、关联标题先取成局部变量再调用时,构建现在会自动授予对应权限,运行时不再在调用处被沙箱拒绝。
- 为什么做:属于构建期处理函数降级这一组修复,替写内联处理函数的开发者补上发布检查已认、构建却没推断出的写法。
- 出错会怎样:最坏是多授予一个函数体确实调用了的权限;钩子里经别名发邮件会像直接写法一样在构建时被拒;可直接撤回。
- 要你做什么:无。
## What changes
`os build` lowers an inline hook `handler` / action `target` to a `js`
body and infers `body.capabilities` from its source. The member patterns
spelled `ctx.` (`ctx.log.info`, `ctx.crypto.randomUUID`,
`ctx.email.send`, `ctx.activity.append`), and the rebind followed only
the handler's own parameter, so a body-local alias inferred nothing and
the sandbox refused the call at run time, while the publish check
(`validate-action-body-capabilities`, `memberReceivers`) reads the same
alias as a receiver of `ctx.MEMBER`.
- `bodyMemberAliases` (new,
`packages/cli/src/utils/extract-hook-body.ts`) reads the handler's parse
for exactly the two alias shapes the lint rule credits: `const l =
ctx.MEMBER` (not `ctx?.MEMBER`, not a chain) and a plain element
destructured off `ctx` (`const { log } = ctx`, `const { log: l } = ctx`;
no default, rest or nesting). A name counts only when declared once and
never assigned or stepped again (the rule's `boundOnce`). `title` is
collected on the hook face only (the host builds `ctx.title` only for
hook bodies).
- `reboundCapabilities` takes those aliases as a third argument and
reads them the way the rule reads its receivers: a CALL of a gated leaf
(`?.` allowed on either side), and for `title` a call with an argument.
A field read infers nothing.
- The published `ExtractedBody.capabilities` union is unchanged (seven
tokens). No spec, no `packages/lint` edit.
- `content/docs/automation/hook-bodies.mdx` `### Capability inference`
(claim amendment 1): the `crypto.uuid` and `log` rows name the alias
shapes, new `email.send` and `activity.append` rows (which the table
never had) name theirs, the `*.title(…)` row names the hook-face alias
form, one sentence defines the two alias shapes and what infers nothing,
and the over-inclusive paragraph now names `email.send` as its exception
(a hook body is never granted it, so a hook that spells or alias-calls
it is refused at build).
Read first (by risk): `bodyMemberAliases` (the shape set must equal the
rule's), the call-shaped alias loop at the top of `reboundCapabilities`,
then the docs table hunk (every sentence there must hold for the
extractor as built).
## Tests
New `packages/cli/test/extract-hook-body-local-alias-38690.test.ts` (93
cases):
- refused-before / inferred-now, per member and shape on each face the
gate is installed on: `log` (local, destructure, renamed destructure),
`crypto.uuid`, `email.send` (measured here; the card had it unmeasured),
`activity.append` (local, destructure), and a hook's `title(FIELD)`
giving `api.read`. At base `d2caaec40d` this file ran 49 failed / 44
passed.
- controls that infer nothing: a local bound to `ctx.input.log`, a
reassigned `let`, a local bound to `ctx.log.child`, field reads (not
calls) off each member alias, a title alias read or called with no
argument, an alias spelled inside a string, a destructure with a
default.
- enumeration: every sandbox gate whose member is a `ctx.MEMBER`
receiver (all eight rows of lint's `SANDBOX_CAPABILITY_GATES`, `api`
included), through `ctx.MEMBER`, a bound local, a destructure and a
renamed destructure. `SANDBOX_CAPABILITY_GATES` is exported by none of
`@objectstack/lint`'s three entries (`.`, `./runtime`,
`./rule-explanations`), and a relative import into `packages/lint/src`
would need a `cross-package-test-inputs` declaration outside this card's
file surface, so the table is mirrored in the test and pinned to the
cli's own published union (`satisfies Record` over
`ExtractedBody['capabilities']`, plus a coverage assertion).
<details><summary>Ablations (one per member family,
scripts/ablation-replace.mjs)</summary>
Each removes one member from `ALIASABLE_MEMBERS`, runs the new file,
restores; every restore printed `blob == HEAD` and `git diff HEAD is
empty`.
- `log` removed: 13 failed of 93 (the six `log` alias cases, six `log`
enumeration rows, the optional-call case).
- `crypto` removed: 10 failed (four alias cases, six enumeration rows).
- `email` removed: 10 failed.
- `activity` removed: 10 failed.
- `title` removed: 5 failed (two alias cases, three enumeration rows).
</details>
<details><summary>Local readings at head (cli unit layer, typecheck,
gates)</summary>
- Build: `pnpm --filter '@objectstack/cli^...' build` under the verify
lock: `VERDICT command-exit 0`.
- `pnpm --filter @objectstack/cli exec vitest run --project unit
--maxWorkers=2`: Test Files 451 passed (451), Tests 6544 passed (6544),
`VERDICT command-exit 0`. The `integration` layer is CI's.
- `pnpm --filter @objectstack/cli typecheck`: `VERDICT command-exit 0`
(test layer OK under `tsconfig.test.json`).
- Six extractor files (`extract-hook-body`, the new file,
`hook-body-parameter-rebind`, `hook-body-mail-grant`, `lower-callables`,
`published-subpath-hook-body.pin`): 259 passed. No existing expected
capability list changed.
- Round 1 (`bcd5926dbc`), `dispatch-gates --commands`: 69 families; 68
exit 0; `check:dual-build-cjs-loads` exit 3 PREREQUISITE NOT MET, NOT
MEASURED there.
- Round 2 (`2ed55579aa`, docs page added), `dispatch-gates --commands`:
100 families, all exit 0 (nine first exited 3 on a fresh tree's missing
builds and were re-run after building their closures,
`check:dual-build-cjs-loads` among them). Docs families include
`check:doc-anchors`, `check:docs-section-name`, `check:doc-frontmatter`,
`check:docs-single-h1`, `check:docs-spec-enumerations`,
`check:docs-transcript-drift`, `check:doc-route-spelling --advisory`,
`check:section-landing-index`, `spec check:docs`. `--ran`
reconciliation: 100 derived, 100 run, 0 NOT-MEASURED, 0 UNRUN.
</details>
## Acceptance notes
- First-party bodies, before and after (every body in
`examples/app-crm`, `app-multi-package`, `app-showcase`, `app-starter`,
`app-todo`, `packages/apps/connector-docusign`, `connector-github`,
`connector-stripe`, loaded, normalized and lowered): 134 body rows,
inferred lists byte-identical. No first-party body uses an alias shape.
- Parity is kept with the rule, no wider: an alias reached through a
renamed context root (`async (c) => { const l = c.log; l.info('x') }`,
`const { log } = c`, or `const c = ctx; const l = c.log`) still infers
nothing here, and the rule does not read it either. Reported to the seat
as a finding, not fixed here.
- A hook body that calls `send(...)` through an `email` alias now
carries `email.send`, so the hook's parse refuses it at build, exactly
as `ctx.email.send(...)` spelled directly already is. Before, it shipped
and failed at the call.
- The alias calls are matched on the body text (the receiver-loose
machinery `reboundCapabilities` already uses), so a string containing
such a call next to a real alias over-infers; for `email.send` on a hook
that is a build refusal, the same edge the direct pattern documents.
- Step 2 (lint dropping its lowered skips) stays on the card.
## Verification
Two-minute check: `pnpm --filter @objectstack/cli exec vitest run
--maxWorkers=2 test/extract-hook-body-local-alias-38690.test.ts`. Expect
1 file, 93 tests passed. Docs: the `### Capability inference` table on
the hook-bodies page has five member rows (`crypto.uuid`, `log`,
`email.send`, `activity.append`, `title`), each naming its alias shapes.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01ADHkmSwS4mQyXWrddL4r6B)_
<!-- signed: repo:objectstack#3 · os-steve ·
session_01ADHkmSwS4mQyXWrddL4r6B -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 95ffacc commit 855c3e1
4 files changed
Lines changed: 261 additions & 7 deletions
File tree
- .changeset
- content/docs/automation
- packages/cli
- src/utils
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
455 | 455 | | |
456 | 456 | | |
457 | 457 | | |
458 | | - | |
459 | | - | |
460 | | - | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
461 | 463 | | |
462 | | - | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
463 | 467 | | |
464 | 468 | | |
465 | 469 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
756 | 756 | | |
757 | 757 | | |
758 | 758 | | |
759 | | - | |
760 | | - | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
761 | 762 | | |
762 | 763 | | |
763 | 764 | | |
| |||
1060 | 1061 | | |
1061 | 1062 | | |
1062 | 1063 | | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
1063 | 1139 | | |
1064 | 1140 | | |
1065 | 1141 | | |
| |||
1070 | 1146 | | |
1071 | 1147 | | |
1072 | 1148 | | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
1073 | 1154 | | |
1074 | | - | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
1075 | 1160 | | |
1076 | 1161 | | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
1077 | 1175 | | |
1078 | 1176 | | |
1079 | 1177 | | |
| |||
0 commit comments