Skip to content

Commit da607a7

Browse files
committed
Merge remote-tracking branch 'origin/main' into claude/project-thread-3l8pov
2 parents 6112dbb + e997113 commit da607a7

9 files changed

Lines changed: 82 additions & 29 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@objectstack/spec': patch
3+
---
4+
5+
docs(spec): a hook's published `body` description says a hook body cannot send mail
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
The `body` key of `HookSchema` now states the rule its parse already holds: a `js` hook body granted `email.send` is refused, because a message cannot be taken back if the write that runs the hook rolls back, and mail on a record change goes through an action, a job or a flow. It also says a hook body may add a timeline entry (`activity.append`), which commits or rolls back with the write. The generated hook reference page carries the same sentence. No key, value or check changes; what a hook accepts is unchanged.
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

‎.claude/skills/pm-dispatch/references/filing-gate.md‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,29 @@
3939

4040
- p0:`main` 或合并队列红;发版阻塞卡只在发版窗内升 p0(⛔ 不打 `target:`),发版后回 p1。
4141
- p1:数据静默错或丢;安全边界;用户完不成核心任务且无绕行;发版所需的协议增项。
42-
- p2:有绕行的用户可见缺陷;普通协议增项;挡 p1 的流程或工具卡(靠 `pm:blocking` 排先,不升级)
42+
- p2:有绕行的用户可见缺陷;普通协议增项;挡他卡的流程或工具卡(`pm:blocking`,不沿链继承)。
4343
- p3(默认):评审 nit、尾巴、落地后的文档与技能跟进、其余流程改进;真实用户可撞 ⇒ p2。
44-
- 重点功能(清单住 `lanes/triage.md`)内用户或 agent 可达的缺陷上调一档;纯散文跟进不升。
4544
- 协议增项:修复改 spec 接受/声明面(含 ADR-0087 转换窗)或 `/meta` 读存删门的收答,宽窄皆算。
4645
- REST/数据门收窄亦算;措辞、文档、账本、CLI 旗、lint/verify 导出、门不变的服务行为不算。
46+
1. 次序:影响行 → 第 2 条降档 → 至多一次升档(第 7、8 条择一)→ 末判发版窗 p0。
47+
定级评论带一行:谁 · 哪门 · 多频 · 实测或读码。
48+
2. 降一档:仅最高权限或宿主开发者可触、经罕见配置或需非默认部署/驱动;不低于 p3。
49+
提权、跨租户、不可恢复丢失不降;⛔ 无「无现用者」第二档:客户少,现用不证明什么。
50+
3. 读码得出且写明机制的发现与实测者同按影响定级;⛔ 无证据上限。
51+
4. 安全边界:卡写得出「低权/外部者经步骤 X 读写或动作越出授权」才算,否则按普通缺陷。
52+
5. 核心任务:北极星「Features on the road」中清单项为 P0/P1 的行;表外不算。
53+
6. 绕行:同角色、同门、不改数据模型,且报错或文档点名;「找管理员」「改库」不算。
54+
7. 真实用户可撞:默认配置照出货文档/技能,错或卡住;带处方响亮拒绝不算(北极星第 4 条)。
55+
8. 重点功能(清单住 `lanes/triage.md`)升档:仅 agent 经该门得错答、假绿或卡死无处方。
56+
假绿 = 答 ok 而未发生或将被拒;升档永不至 p0。
57+
响亮拒绝、措辞、观感、宿主诊断不升,只在本行内排先。
58+
9. 清单断言缺陷(产品对、清单错)按 p2 修,不继承项档;发版窗内挡验收判定带 `pm:blocking`。
59+
项档继承只适用真实产品断;「平台测试清单反复变红,肯定要修啊」(维护者)。
4760
- 清单项三态 ①:项会 fail ⇒ 断,继承其 `priority`;⛔「有人在等」不是定级判据。
4861
- ② 项的标题/场景断言该能力而 steps 到不了那条路径 ⇒ 补步骤并继承该项档 ⛔ 不降 p3。
4962
- ③ 无项断言该能力 ⇒ 缺项补账本、北极星第 2 条 p3;②最常见,`area:*` 继承后成规模。
5063
- 假绿另有条款:绿线被读作「已核对」而实际没核对 ⇒ 一次人眼捕获即一次实测代价。
5164
- 「Instruments serve the fleet」的四种答案 ⛔ 不压成两条;假红的标准代价形态是席位顺从它。
52-
- 可达面定上界:`security` 标签不抬级;仅最高权限可达且无现用者至多 p3,可记录不修。
5365
- 北极星第 4 条只认出货面(`skills/**`、产品文档),⛔ 不含 `.claude/**` 内部协议。
5466
- 它认的是一句说错的话,⛔ 不是一句缺席的话;缺句按覆盖不足走北极星第 2 条。
5567

‎content/docs/references/data/hook.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const result = HookSchema.parse(data);
3333
| **object** | `string \| string[]` | ✅ | Target object(s) |
3434
| **events** | `Enum<'beforeFind' \| 'afterFind' \| 'beforeInsert' \| 'afterInsert' \| 'beforeUpdate' \| 'afterUpdate' \| 'beforeDelete' \| 'afterDelete'>[]` | ✅ | Lifecycle events |
3535
| **handler** | `string` | optional | Handler function name (string, post-build) or inline function (pre-build) — DEPRECATED, prefer `body` |
36-
| **body** | `{ language: 'expression'; source: string } \| { language: 'js'; source: string; capabilities?: Enum<'api.read' \| 'api.write' \| 'api.transaction' \| 'crypto.uuid' \| 'log' \| …>[]; timeoutMs?: integer; … }` | optional | Hook body — expression (L1) or sandboxed JS (L2) |
36+
| **body** | `{ language: 'expression'; source: string } \| { language: 'js'; source: string; capabilities?: Enum<'api.read' \| 'api.write' \| 'api.transaction' \| 'crypto.uuid' \| 'log' \| …>[]; timeoutMs?: integer; … }` | optional | Hook body — expression (L1) or sandboxed JS (L2). A hook body cannot send mail: a js body granted email.send is refused, because a message cannot be taken back if the write that runs the hook rolls back; send mail on a record change from an action, a job or a flow. A hook body may add a timeline entry (activity.append), which commits or rolls back with the write. |
3737
| **priority** | `number` | optional (default: `100`) | Execution priority |
3838
| **async** | `boolean` | optional (default: `false`) | Run specifically as fire-and-forget |
3939
| **condition** | `string \| { dialect: Enum<'cel' \| 'cron' \| 'template'>; source: string; ast?: any; meta?: object }` | optional | Predicate (CEL); hook runs only when TRUE. e.g. P`record.status == "closed" && record.amount != null && record.amount > 1000` |

‎docs/NORTH-STAR.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@
112112

113113
**Priority**:
114114
1. Security and data integrity always come first and do not wait for the road.
115-
2. The road broken, or a capability on the checklist broken ⇒ P0/P1; runs but goes wrong ⇒ P2; neither on the road nor on the checklist ⇒ p3 or not taken on. Grading reads "Features on the road": change that table to change priority, ⛔ never re-grade card by card.
116-
3. While a lane's queue still holds an open P0/P1, that lane dispatches no p2/p3 tooling card or contract-hygiene card; an instrument card that unblocks a product P0/P1 inherits its priority along the chain.
115+
2. The road broken, or a capability on the checklist broken ⇒ P0/P1; data silently wrong or lost ⇒ P1, subject to the grading rules' reach discount; any other run that goes wrong ⇒ P2; neither on the road nor on the checklist ⇒ p3 or not taken on. Grading reads "Features on the road": change that table to change priority, ⛔ never re-grade card by card — except for one re-grade pass when the grading rules themselves change, and none otherwise.
116+
3. While a lane's queue still holds an open P0/P1, that lane dispatches no p2/p3 tooling card or contract-hygiene card; a process or tooling card that blocks other work is P2 and carries `pm:blocking`; it does not inherit priority up the chain.
117117
4. Because AI writes it and AI uses it: the ontology must be writable by AI — what is wrong must be loudly refused with a prescription, never silently stored; and usable by people and agents — declared objects, actions and agent / tool / skill metadata are honoured at runtime, what the MCP surface exposes is what the application really can do, and an agent that oversteps is stopped by permissions and leaves a trace. The half people use has a standard too: an author who writes not one line of UI code gets a UI that looks as if a designer had handled it — one design system, one layout; looking wrong is as much a defect as failing to render, and is refused at the "see it" step. One wrong sentence in the documentation and skills written for AI is a product defect.
118118

119119
**Stage posture**: speed over compatibility. Few people use it: a retirement takes effect at once, with no transition window and no alias double-spelling; compatibility layers, migration windows and the like default to p3; keys declared but not honoured are retired in batches per release, not one card per key.

‎packages/cli/src/utils/extract-hook-body.ts‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,8 +509,10 @@ const CAPABILITY_PATTERNS: Array<{ rx: RegExp; cap: 'api.read' | 'api.write' | '
509509
// Match `ctx.api.object(...)` directly OR a local alias like
510510
// `const api = ctx.api;` then `api.object(...)`. We accept any
511511
// identifier (or chain) ending in `.object(...)` followed by a known
512-
// read/write method — over-inclusive but safe (false-positive caps
513-
// get rejected at the runtime by the sandbox if not actually granted).
512+
// read/write method — over-inclusive, and for these tokens harmless: an
513+
// over-inferred grant is one the body never exercises, and the sandbox
514+
// checks a grant only at a call. One token is the exception, see the door
515+
// patterns at the end of this list.
514516
{ rx: /\.object\s*\([^)]+\)\s*\.\s*(?:find|findOne|count|aggregate|get|list)\b/, cap: 'api.read' },
515517
{ rx: /\.object\s*\([^)]+\)\s*\.\s*(?:insert|update|upsert|delete|patch|remove|create)\b/, cap: 'api.write' },
516518
{ rx: /ctx\.crypto\.randomUUID\b/, cap: 'crypto.uuid' },
@@ -536,6 +538,17 @@ const CAPABILITY_PATTERNS: Array<{ rx: RegExp; cap: 'api.read' | 'api.write' | '
536538
// grants a token the body may not use, which the sandbox simply never checks.
537539
{ rx: /\.\s*title\s*\(\s*[^)\s]/, cap: 'api.read' },
538540
// The two platform doors: a call to the door is what its token grants.
541+
//
542+
// ⛔ An over-inferred `email.send` is NOT harmless on a hook. A hook body may
543+
// not be granted it (ruling 6843314411 on #32004: a message cannot be taken
544+
// back if the write that runs the hook rolls back), and the hook's parse
545+
// refuses a body that carries it, so the build fails on a handler whose
546+
// source merely spells `ctx.email.send` without calling it: a string, or a
547+
// branch that never runs (a comment does not count; the lowered source
548+
// carries none). That failure is the rule working: the remedy is
549+
// to take the spelling out of the hook handler, and mail on a record change
550+
// goes through an action, a job or a flow. An action or a job body is
551+
// granted the token as before.
539552
{ rx: /ctx\.email\.send\b/, cap: 'email.send' },
540553
{ rx: /ctx\.activity\.append\b/, cap: 'activity.append' },
541554
];

‎packages/spec/src/data/hook.zod.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,8 +530,20 @@ export const HookSchema = lazySchema(() => strictObject(
530530
*
531531
* Authoring convenience: `objectstack build` extracts inline TS handlers from
532532
* `*.hook.ts` files, AST-checks them, and emits the result here. See plan §6.
533+
*
534+
* A hook body cannot send mail (ruling 6843314411 on #32004): a message
535+
* cannot be taken back if the write that runs the hook rolls back, so a
536+
* `js` body granted `email.send` is refused at parse
537+
* (`refuseHookBodyMailGrant`). Mail on a record change goes through an
538+
* action, a job or a flow. A hook body may add a timeline entry
539+
* (`activity.append`); the entry commits or rolls back with the write.
533540
*/
534-
body: HookBodySchema.optional().describe('Hook body — expression (L1) or sandboxed JS (L2)'),
541+
body: HookBodySchema.optional().describe(
542+
'Hook body — expression (L1) or sandboxed JS (L2). A hook body cannot send mail: a js body granted ' +
543+
'email.send is refused, because a message cannot be taken back if the write that runs the hook rolls ' +
544+
'back; send mail on a record change from an action, a job or a flow. A hook body may add a timeline ' +
545+
'entry (activity.append), which commits or rolls back with the write.',
546+
),
535547

536548
/**
537549
* Execution Order

‎scripts/pm/check-skill-line-ratchet.mjs‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1504,7 +1504,15 @@ export const CEILINGS = new Map([
15041504
// the possible-data-leak reach exception left the exceptions line in place,
15051505
// so the measured delta is +1.
15061506
// Not a CROSS_FILE_MOVES destination. Landed count, headroom 0.
1507-
['.claude/skills/pm-dispatch/references/filing-gate.md', 67],
1507+
// 67 → 79 (#32997): an ordinary ruled raise under letter B (record
1508+
// 6184799323). The ruling of record is the maintainer's 2026-11-13 grading
1509+
// ruling quoted verbatim in the card body (「只是读代码得出的最高 p2。这个没必要吧,
1510+
// 我们的客户不多。」 and 「不需要限额,也不需要自动关。其他同意。」; triage audit
1511+
// 6846766675), which orders the nine adopted grading rules into 〈定级判据〉.
1512+
// Under the 120-byte line cap they take 14 lines; the old focus-raise and
1513+
// reach-cap lines fold into rules 8 and 2 and are deleted, so the measured
1514+
// delta is +12. Not a CROSS_FILE_MOVES destination. Landed count, headroom 0.
1515+
['.claude/skills/pm-dispatch/references/filing-gate.md', 79],
15081516
// The project layer above the seats (maintainer's word: ONE project form, the
15091517
// instruction line 「pm-dispatch <席位…>」 is the summon, seats are read from the
15101518
// seat posts' 🟢 line, takeover never waits for a walled account, mailbox PRs,

‎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)