Skip to content

Commit b440ffb

Browse files
docs(skills): name the ctx.email.send and ctx.activity.append body doors in the data-hooks reference (#33078)
<!-- claude-projects-attribution: {"github_login":"os-tesla"} --> _Requested by **Tesla** · [project thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6Jao4mxVDvLfhyeEEmRuW5tvnb)_ Fixes #33033 Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:`objectstack-data` 技能的 `data-hooks.md` 现在点名 #32966 发布的两个脚本体入口:沙箱 `ctx` 表加 `ctx.email` / `ctx.activity` 两行,「Capabilities — the complete list」加 `email.send` / `activity.append` 两行,并把过时的「exactly five」改为「exactly seven」(`HookBodyCapability` 在 main 上是七个值)。 - 为什么改:按原文写钩子的 agent 找不到这两个入口,还可能在钩子体里发邮件——这在解析时就被拒(裁决 #32004 6843314411)。规则只陈述一次:钩子体不能持有 `email.send`(解析与绑定时拒收),记录变更时的邮件走 action、job 或 flow;`activity.append` 随运行脚本体的那次写入一起提交或回滚;`type` 只能用应用自己的值(平台类型 403 拒收),且不得在 `ctx.api.transaction` 内调用(409)。另把「async 钩子用于发邮件」改为「发通知」,免得与新规则矛盾。 - 风险与回滚:只改已发布技能文字,无代码改动;token 10007 / 10011(同文件删复述付账,不抬上限)。回滚即 revert。 - 先看:`skills/objectstack-data/references/data-hooks.md` 第 355–356 行(`ctx` 表两行)、第 426–436 行(能力表两行 + seven),第 197 行(async 用途)。 - 两分钟验证:`node scripts/check-skills-token-ratchet.mjs | grep data-hooks`,预期 `10007 / 10011` 且退出 0。 - 需要你做的:本 PR 触及 `skills/**`(Tier H)。契约复审在现 head 已 PASS(r1 评论 6849613993,r2 增量 6849985798,Head-sha `dc05d1b0a91dd4c9d89f6fe6b558114e54f03818`),请以 os-zhuang 批准。⛔ 18.4.0 合并冻结中(#32908 6848983225):本 PR 带 changeset,批准后请勿入队,席位在解冻后落地。 - 席位意见:同意落地。两个钩子体入口、解析/绑定两处拒收、两个入参 schema 逐一对过;r1 的两个 should-fix(activity.append 的 type 与事务内调用会被拒;async 段落仍教「发邮件」)已在 r2 修掉;余两个 nit 作为接受的偏差。 ## What changes - **`ctx` table:** `ctx.email` (`{ send }`, gated by `email.send`, not in a hook body) and `ctx.activity` (`{ append }`, gated by `activity.append`). - **Capabilities — the complete list:** "exactly five" → "exactly seven" (it was stale: `HookBodyCapability` on `main` b232220 lists `api.read`, `api.write`, `api.transaction`, `crypto.uuid`, `log`, `email.send`, `activity.append`), plus two rows: - `email.send`: `ctx.email.send({ to, subject, text })`, mail via the mail service with sender, user and organization stamped (`BodyMailSendInputSchema`); not in a hook body, refused at parse and at bind, because a message cannot be taken back if the hook's write rolls back; mail on a record change goes through an action, a job or a flow. - `activity.append`: `ctx.activity.append({ object, recordId, type, summary })`, one record-timeline entry with actor and origin stamped (`BodyActivityAppendInputSchema`); commits or rolls back with the write that runs the body. `type` is the app's own, never a `SYS_ACTIVITY_PLATFORM_TYPES` value (403 `PERMISSION_DENIED`, aborting the write under `onError: 'abort'`), and the call is never made inside `ctx.api.transaction` (409 `RESOURCE_CONFLICT`). - **`async` section:** "Sending emails/notifications" → "Sending notifications", so no line sends an author to mail from a hook. - **Truth sources read on `main` b232220:** `packages/spec/src/data/hook-body-doors.zod.ts` (both input schemas and their descriptions), `packages/spec/src/data/hook-body.zod.ts` (`HookBodyCapability` JSDoc), `packages/spec/src/data/hook.zod.ts` `refuseHookBodyMailGrant` (parse-side refusal; its block comment names the bind-side refusal in `hookBodyRunnerFactory`), `content/docs/automation/hook-bodies.mdx` rows for both doors, `content/docs/kernel/runtime-services/email-service.mdx`. The skill text claims nothing those do not say; the required input keys named are the schema's required keys (`text` stands for "`text` or `html`"). - **Budget paid by same-file restatement cuts, no ratchet raise:** - the `body` vs `handler` table's "Ships as" row and the paragraph after the table ("Because a `body` is pure metadata …") — both restate the Shape/Status rows and the section intro; - the Hook Context API callout's tail "including the `where` query shape and the `update({ id, … })` pattern" — the linked section already titles both; - the "What Are Hooks?" four-bullet list, which restates the Before vs After table (now linked) and the `ctx` table; - the Cross-Object API paragraph's second link to the sandbox section and its "additionally require `api.read` / `api.write`" sentence — the callout at the top of the same `## Hook Context API` section links the sandbox section, and the capability table states the tokens. ## Tests Teaching text only; no tested behaviour changed, so no ablation. ## Acceptance notes - Readings (published `skills/**`): `skills/objectstack-data/references/data-hooks.md` lines 953 → 943, tokens 9987 → 10007 (ceiling 10011) at head dc05d1b. - No out-of-scope findings. ## Verification <details><summary>Gates: CI on dc05d1b 44 check-runs, 28 success, 16 skipped, 0 failed; local derived list at e7336ef, skill-text gates re-run on dc05d1b</summary> - Derivation: `node scripts/pm/dispatch-gates.mjs --commands` (45 commands) plus `pnpm check:changeset-fixed` (roster under `.changeset`, flagged by the derivation). `@objectstack/lint...` built first for `check:doc-formula-expressions`. - `main` b232220 merged before opening: no-op. Skill-text gates re-run on e7336ef, each exit 0: `check-skills-token-ratchet` (10007 / 10011), spec `check:skill-refs`, spec `check:skill-docs`, `check:skill-identifier-liveness`, `check:skill-links`. - Re-run on dc05d1b, 16 commands, each exit 0 (token ratchet 10007 / 10011, spec `check:skill-refs` / `check:skill-docs`, skill identifier liveness, skill links, doc authoring, changeset gates, closing-keyword parity, …). - NOT MEASURED locally (exit 3, prerequisite: whole-workspace dists): `check:dual-build-cjs-loads`, `check:lean-entry-closure`. The diff is one markdown file and a changeset, which cannot move built dists; CI's `Build Core` ran both on dc05d1b: success. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01L9qibzqxVnBg8FjZXM1fQu)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01L9qibzqxVnBg8FjZXM1fQu <!-- signed: domain:skills#2 · os-tesla · session_01L9qibvXzthnUYrxzphgFgW --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 2c98485 commit b440ffb

2 files changed

Lines changed: 17 additions & 19 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@objectstack/skills': patch
3+
---
4+
5+
The data-hooks reference names the two body doors, `ctx.email.send` (`email.send`) and `ctx.activity.append` (`activity.append`), in its sandbox `ctx` table and capability list. A hook body cannot send mail; mail on a record change goes through an action, a job or a flow. An activity entry's `type` is the app's own value, never a platform type, and the call stays outside `ctx.api.transaction`.
6+
7+
Clause-②: no
8+
Metadata-protocol: none

‎skills/objectstack-data/references/data-hooks.md‎

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@ inline `handler`), the `HookContext` API, registration, and the canonical patter
2020
### What Are Hooks?
2121

2222
Hooks are **event handlers** that execute during the ObjectQL data access lifecycle.
23-
They intercept operations at specific points (before/after) and can:
24-
25-
- **Read** the operation context (user, session, input data)
26-
- **Modify** input parameters or operation results
27-
- **Validate** data and throw errors to abort operations
28-
- **Trigger** side effects (notifications, integrations, logging)
23+
They intercept operations at specific points (before/after) — see [Before vs After](#before-vs-after-hooks).
2924

3025
### Hook Lifecycle Events
3126

@@ -199,7 +194,7 @@ async: true
199194
```
200195

201196
**When to use async: true:**
202-
- Sending emails/notifications
197+
- Sending notifications
203198
- Non-critical side effects
204199

205200
**When to use async: false:**
@@ -316,14 +311,9 @@ executes — or as the deprecated inline **`handler`**.
316311
|:--|:--|:--|
317312
| Shape | `body: { language, source, capabilities }` (pure metadata) | `handler: async (ctx) => { … }` |
318313
| Runs in | An isolated **QuickJS VM** (edge-safe, capability-gated) | The host process (**full Node**) |
319-
| Ships as | Plain JSON inside the build artifact — travels everywhere | Lowered at build to a string ref + a sibling `.mjs` runtime module |
320314
| Status | **Preferred for new code** | **Deprecated** (`HookSchema`: *"prefer `body`"*) |
321315
| Both present? | Runtime uses **`body`** and ignores `handler` | — |
322316

323-
Because a `body` is pure metadata, it is what AI-authored hooks, Studio-authored
324-
hooks, and any `objectstack build` artifact carry. The rest of this section is
325-
the contract for that sandbox.
326-
327317
### The `body` shape
328318

329319
```jsonc
@@ -362,6 +352,8 @@ The sandbox is handed a **JSON snapshot** of these (built by
362352
| `ctx.api` | object | Cross-object CRUD. Gated by `api.read` / `api.write` — see below. |
363353
| `ctx.log` | `{ debug, info, warn, error }` | Gated by `log`. Call **`ctx.log.info(msg, data?)`** — `ctx.log` is an **object, not** callable as `ctx.log(msg)`. Emission is **best-effort** (see Troubleshooting). |
364354
| `ctx.crypto` | `{ randomUUID }` | Gated by `crypto.uuid`. |
355+
| `ctx.email` | `{ send }` | Gated by `email.send`; not in a hook body. |
356+
| `ctx.activity` | `{ append }` | Gated by `activity.append`. |
365357
| `ctx.notice` | `(message) => void` | **Tell the saver what this save set in motion** — answered as the create/update `notice`, shown on the save toast. No capability; insert/update only; last call wins. [`rules/lifecycle.md` § Save Notice](../rules/lifecycle.md#save-notice). |
366358
| `ctx.title` | `(field?) => Promise<string \| null>` | **Name the record, not its id.** `ctx.title()` resolves this object's `nameField`, a **formula** included (no extra read); `ctx.title('account_id')` resolves a lookup's title (needs `api.read`). `null` when there is no title, never the id. **Per door:** `body` has it; a deprecated `handler` gets it at runtime, undeclared on `HookContext` (TS2339 when annotated) — use `body`; `ql.registerHook` and a bare `ObjectQL` `bindHooks` lack it. |
367359

@@ -431,7 +423,7 @@ single-record form is `update({ id, ...fieldsToChange })` — e.g.
431423
A body may only touch a `ctx` API it declared in `capabilities`. Calling an
432424
undeclared one **throws inside the VM** — `capability '<token>' not granted to
433425
hook '<name>' …` — which surfaces as a hook error (see Troubleshooting). The full
434-
set of legal tokens (`HookBodyCapability`) is exactly five:
426+
set of legal tokens (`HookBodyCapability`) is exactly seven:
435427

436428
| Token | Unlocks |
437429
|:--|:--|
@@ -440,6 +432,8 @@ set of legal tokens (`HookBodyCapability`) is exactly five:
440432
| `api.transaction` | `ctx.api.transaction(async () => { … })` — runs the callback's `ctx.api` ops in **one driver transaction** (commit on return, rollback on throw). Pair it with `api.write`. |
441433
| `crypto.uuid` | `ctx.crypto.randomUUID()` |
442434
| `log` | `ctx.log.debug` / `info` / `warn` / `error(msg, data?)` |
435+
| `email.send` | `ctx.email.send({ to, subject, text })` — mail via the mail service; sender, user and organization are stamped (`BodyMailSendInputSchema`). **Not in a hook body** (refused at parse and at bind): a message cannot be taken back if the hook's write rolls back. Mail on a record change goes through an action, a job or a flow. |
436+
| `activity.append` | `ctx.activity.append({ object, recordId, type, summary })` — one record-timeline entry; actor and origin are stamped (`BodyActivityAppendInputSchema`). `type` is the app's own, never a `SYS_ACTIVITY_PLATFORM_TYPES` value (403 `PERMISSION_DENIED`, aborting the write under `onError: 'abort'`); never inside `ctx.api.transaction` (409 `RESOURCE_CONFLICT`). Commits or rolls back with the write that runs the body. |
443437

444438
There is **no `http.fetch` capability** by design — outbound calls go through
445439
[Connector recipes](../../objectstack-automation/references/integration-recipes.md)
@@ -559,8 +553,7 @@ Register it like any hook — add it to `defineStack({ hooks: [fillPositionOnHir
559553
> `handler`** context (full Node; `handler` is deprecated). A metadata-native **`body`** sees a
560554
> capability-gated *subset* of it inside an isolated VM — see
561555
> [Sandboxed Hook Bodies](#sandboxed-hook-bodies-body--what-the-sandbox-ctx-can-call)
562-
> for exactly what is and isn't available there, including the `where` query
563-
> shape and the `update({ id, … })` pattern.
556+
> for exactly what is and isn't available there.
564557
565558
The engine's `HookContext` provides:
566559

@@ -727,10 +720,7 @@ ctx.previous: {
727720
### Cross-Object API
728721

729722
Access other objects within the same transaction. `ctx.api.object(name)` is the
730-
same repository in both forms; the canonical query key is **`where`** (see
731-
[Sandboxed Hook Bodies](#sandboxed-hook-bodies-body--what-the-sandbox-ctx-can-call)
732-
for the full method + capability contract). In a sandboxed `body` these calls
733-
additionally require the `api.read` / `api.write` capabilities.
723+
same repository in both forms; the canonical query key is **`where`**.
734724

735725
---
736726

0 commit comments

Comments
 (0)