Skip to content

Commit b703678

Browse files
docs(skills): the registerHook example names the app's onEnable export, and the refusal-list teaching names its routes, the /data bound and its section (#38182)
<!-- claude-projects-attribution: {"github_login":"os-sales"} --> _Requested by **Sales** · [project thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4Uu5aGSp1oEmXTAmjuazY7oxd)_ Fixes #38161 Fixes #37642 Clause-②: no Metadata-protocol: none ## 维护者速读 - 是什么:照数据技能写钩子的开发者和 AI 会读到正确的注册位置:示例注释原来写「放在插件的 onEnable 里」,插件根本没有这个方法,照写的钩子永远不会注册;现在写明放在应用配置导出的 onEnable 里,插件则在启动方法里经服务拿引擎注册。拒绝清单一段还补了两点:数据接口会把返回消息截在 500 字,长清单的最后一行在那里会被截掉;哪些接口返回拒绝清单也点了名。动作技能页的「规则在那里」改成点名所指的章节。运行时行为不变。 - 为什么:属于「AI 照技能写出能跑的元数据」。照错误注释写的钩子不跑也不报错,是静默失效。 - 出错会怎样:只是技能文字,写错了是教错,可直接撤回;两个文件都在字数上限,新增靠删同文件里的重复说法来付,没有事实被删掉。 - 要你做的:座位审核和合同审核通过后,技能目录需你批准合并。 ## What changes - `skills/objectstack-data/references/data-hooks.md`, Registration Methods, method 2 (#38161): the comment `// in your plugin's onEnable()` named a method no kernel plugin has. It now reads `// in the app's onEnable export (objectstack.config.ts). A kernel plugin has no ctx.ql: from start(ctx), ctx.getService('objectql').registerHook(…)`, and the heading's "the plugin escape hatch" became "the `onEnable` escape hatch". - `packages/core/src/types.ts:155` `Plugin` has `init` / `start?` / `destroy?` and no `onEnable`; `PluginContext` (:16) has `getService` (:37) and no `ql`. - `packages/runtime/src/app-plugin.ts:1795-1834` resolves the bundle's `onEnable` and calls it with `hostContext = { ...ctx, ql, logger, drivers }`; `packages/spec/src/stack.zod.ts:1319` declares `onEnable` on the stack. - `packages/objectql/src/plugin.ts:932` registers the engine as service `objectql`; `engine.ts:715` is `registerHook`; `AppPlugin.start` itself reads `ctx.getService('objectql')` (`app-plugin.ts:1464`). - Same file, Declared refusals, the several-reasons bullet (#37642 N2, N5): "the HTTP doors answer `details.refusals`" became: `/data` cuts `userMessage` (a single sentence's too) at 500 characters, so a long list loses its closing line there; `/data` and `/actions` answer `details.refusals: [{ reason, message }]` uncut (MCP tools relay the lines as text). - Bound: `packages/types/src/data-error-classification.ts:55` `CLIENT_MESSAGE_MAX = 500`, applied to a declared `userMessage` by `mapDataError` → `withDeclaredUserMessage` → `boundedDeclaredUserMessage` (:568-703); the list stays whole (:609-620). `/actions` uses the unbounded `declaredUserMessage` (`thrown-http-error.ts:408`, via `actions-door-answer.ts:415-438`). - Routes: `/data` `withDeclaredRefusalLines` (`data-error-classification.ts:622`); `/actions` `action-dispatch.ts:957` → `thrown-http-error.ts:396-404`; MCP `packages/mcp/src/mcp-http-tools.ts:1474-1498` appends the lines as text. - `skills/objectstack-ui/rules/actions.md`, Refusing by code (#37642 N4): "(rules there)" named no place; it now ends "(Declared refusals)", the last segment of the same paragraph's pointer "objectstack-data → Lifecycle Hooks → Declared refusals". "closed by" became "then" to pay the byte. - `.changeset/38161-skills-hook-registration-refusal-pointers.md`: `@objectstack/skills` patch. **Paid by cuts in `data-hooks.md`** (each fact still in the file): the Error-handling row's "`onError` defaults to `'abort'` unconditionally" (the row keeps "Also aborts by default"); the repeated transition expression → "as above" (the code block above carries it); the `after*` bullet's "(`record` is that row's real state, not the bare payload)" (the section's bold lead says it); Gotcha 1's one-line `findOne` block → "re-query it by `ctx.result.id`, as the example below does" (the copy-paste example and Query shape carry the line); the copy-paste intro's "(a lookup FK that is **not** in the partial patch)" (Gotcha 1 says it); the `ctx.log` bullet's "two independent causes: (1) … (2)" scaffolding. **Skills readings** (lines / bytes, merge base 4f7aa88 → head): | | before | after | |:--|--:|--:| | `data-hooks.md` | 856 / 40477 | 851 / 40480 | | `actions.md` | 268 / 15670 | 268 / 15671 | | all `skills/**/SKILL.md`, lines | 4953 | 4953 | | whole `skills/` tree, bytes | 1224868 | 1224872 | Both files stay at their token ceilings (10120, 3918); no ceiling line changed. The `skills/**` edits were written by isolated sub-agents at the contract-review tier; `node scripts/pm/verify-review-tier.mjs` on their transcripts: `PASS — 4 assistant turn(s)` (actions.md) and `PASS — 54 assistant turn(s)` (data-hooks.md), every one served at CONTRACT_REVIEW_TIER. Not traced: whether the dispatcher's own `/data` twin (`packages/runtime/src/domains/data.ts`) carries the same cut and list, so the text names only `/data` and `/actions`. ## Tests <details><summary>gates (head 7eb3a71)</summary> Derived by `node scripts/pm/dispatch-gates.mjs --commands` (48 lines). Run locally, exit 0 (30): `check-skills-token-ratchet.mjs`, `check-adr-0087-registration.mjs`, `check-changeset-no-major.mjs`, `check-closing-keyword-parity.mjs`, `check-comment-mask-corpus.mjs`, `check-doc-route-spelling.mjs --advisory`, `check-empty-changeset.mjs`, `@objectstack/spec check:skill-refs`, `check:adr-anchors`, `check:agent-test-spelling`, `check:changeset-gate-self-tests`, `check:ci-filter-parity`, `check:closed-ceremony-text`, `check:corpus-claim-drift`, `check:cross-package-test-inputs`, `check:doc-authoring`, `check:driver-memory-census`, `check:gitlink-declared`, `check:nul-bytes`, `check:pm-expected-skips`, `check:pm-governed-merges`, `check:pm-skill-id-lint`, `check:published-files`, `check:refd-timer-probe`, `check:role-word`, `check:skill-compatibility`, `check:skill-frame-sync`, `check:skill-identifier-liveness`, `check:skill-links`, `check:watch-hint-literal`. NOT MEASURED locally, reason: they read built `dist/` and no package is built in this worktree (the diff touches no package source): `check:doc-formula-expressions`, `check:dts-closure`, `check:dual-build-cjs-loads`, `check:lean-entry-closure`, `check:sourcemap-no-sources-content`. Left to CI, as are the `--self-test` lines. </details> ## Acceptance notes - The 4xx `error` text on `/data` is cut at the same 500 characters (`data-error-classification.ts:1679`); not added, it did not fit the budget and the card asks for `userMessage`. - A throw that leaves the dispatcher's `dispatch()` exits through `errorResponseBase` (`packages/runtime/src/dispatcher-plugin.ts:711`), where no `refusals` handling was seen; that is why the page does not promise the list on the dispatcher's other routes. Read only, not filed. ## Verification Read first: `data-hooks.md` method 2 code block; the several-reasons bullet under Declared refusals; the last sentence of "Refusing by code" in `actions.md`. Two-minute check: `node scripts/check-skills-token-ratchet.mjs` prints `61 authored bundle file(s) within their ceilings`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01L6bhgWXNEKowao8Fvau3Bs <!-- signed: repo:objectstack#2 · os-sales · session_01L6bhgWXNEKowao8Fvau3Bs --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 3337425 commit b703678

3 files changed

Lines changed: 31 additions & 22 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@objectstack/skills': patch
3+
---
4+
5+
docs(skills): the `registerHook` example names the real seam, and the refusal-list teaching names its places
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
- `skills/objectstack-data/references/data-hooks.md`, Registration Methods, method 2: the example's comment said "in your plugin's onEnable()", a method no kernel plugin has, so a hook written there never registers. It now says the example runs in the app's `onEnable` export (`objectstack.config.ts`), where `ctx.ql` is the engine, and that a kernel plugin, which has no `ctx.ql`, registers from `start(ctx)` with `ctx.getService('objectql').registerHook(…)`.
11+
- Same file, Declared refusals: `/data` cuts `userMessage` at 500 characters (a single sentence's too), so a long reasons list loses its closing line there; `/data` and `/actions` answer `details.refusals` uncut, and MCP tools relay the lines as text. This replaces "the HTTP doors", since "door" on this page also means a hook registration path.
12+
- `skills/objectstack-ui/rules/actions.md`, Refusing by code: the reasons-list sentence ended "(rules there)", which named no place; it now names "Declared refusals", the hook section that carries the rules.
13+
14+
Both files stay at their token ceilings (10120 and 3918); the added words are paid by cutting restatements in the same file.

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

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ after an operation — see [Before vs After](#before-vs-after-hooks).
5858
| **Can modify** | `ctx.input` (mutable) | `ctx.result` (mutable) |
5959
| **Can abort** | Yes (throw error → rollback) | A sync after-hook's throw still rolls back the transaction (see error handling) |
6060
| **Transaction** | One transaction with the outer write: a refusal anywhere in it (a validation, a later hook, a driver constraint) rolls back the hook's `ctx.api` writes; no per-hook opt-out. Exits: a caller's open transaction decides; a hooked object off the default datasource, or a default driver with no transactions (Turso's remote transport), opens none, so those writes stay stored after a refusal; a hook registered in code (`registerHook`) opens none. A standalone MongoDB refuses every write of such a transaction (501 `NOT_IMPLEMENTED`); a single-node replica set is enough. On PostgreSQL and a MongoDB replica set a failed `ctx.api` statement refuses the outer write even when caught, logged (`onError: 'log'`) or retried (`25P02` / `251`); SQLite lets it through | **Within the transaction**. `async: true` on `afterInsert` / `afterUpdate` / `afterDelete`: starts once the outermost transaction commits, never if it rolls back (a failed commit included); on `afterFind`: starts as the read is dispatched; outside a transaction: starts at once |
61-
| **Error handling** | Aborts by default (`onError: 'abort'`) | **Also aborts by default** — `onError` defaults to `'abort'` unconditionally; set `onError: 'log'` on side-effect hooks |
61+
| **Error handling** | Aborts by default (`onError: 'abort'`) | **Also aborts by default**; set `onError: 'log'` on side-effect hooks |
6262

6363
---
6464

@@ -145,8 +145,7 @@ in neither). So:
145145
`record.done == true` works on an update that only sets `status`.
146146
- `record` describes the record's **state**, not the diff. `record.done == true`
147147
fires on every update of an already-done record, not only on the update that
148-
set it. **For the transition, compare against `previous`**:
149-
`previous.done != true && record.done == true`. `previous` is the stored
148+
set it. **For the transition, compare against `previous`**, as above. `previous` is the stored
150149
pre-write row, made total over the same declared fields, and it is the same
151150
binding a validation predicate reads.
152151
- **`previous` is `null` on insert** (`beforeInsert` / `afterInsert`), so
@@ -166,8 +165,7 @@ in neither). So:
166165
object) — the engine refuses the batch whole, before any write, when two rows'
167166
key sets differ (`MULTI_UPDATE_HOOK_KEY_DIVERGENCE`, status 400; ADR-0058
168167
Amendment II.3).
169-
- **`after*` hooks dispatch once per matched row too** (`record` is that row's
170-
real state, not the bare payload), so a transition condition on `afterUpdate` /
168+
- **`after*` hooks dispatch once per matched row too**, so a transition condition on `afterUpdate` /
171169
`afterDelete` means the same whether the write carried an id or a predicate.
172170
- **Guard optional values with `!= null`, never with `has(...)`.** A declared
173171
field holding `null` is *present*, so `has(record.spent)` is uniformly true and
@@ -343,11 +341,7 @@ The body's VM is **not** Node:
343341
On `afterUpdate`, both `ctx.result` and `ctx.input` carry only the fields this
344342
PATCH touched (`ctx.result` adds `id`). A field you did **not** write — a lookup FK, a status
345343
you want to branch on — is **absent**, not stale. To read the whole record,
346-
re-query it:
347-
348-
```js
349-
const full = await ctx.api.object('candidate').findOne({ where: { id: ctx.result.id } });
350-
```
344+
re-query it by `ctx.result.id`, as the example below does.
351345

352346
### ⚠️ Gotcha 2 — cross-object writes obey the *target's* sharing model
353347

@@ -367,8 +361,7 @@ write from a system-context automation.
367361

368362
### Copy-paste example — afterUpdate + cross-object update + re-query + capabilities
369363

370-
When a `candidate` is marked `hired`, look up its `position` (a lookup FK that
371-
is **not** in the partial patch) and flip that position to `filled`:
364+
When a `candidate` is marked `hired`, look up its `position` and flip that position to `filled`:
372365

373366
<!-- os:check -->
374367
```typescript
@@ -404,10 +397,9 @@ export default fillPositionOnHire;
404397
wrapped message names the hook; the usual causes are a missing capability, a
405398
`FORBIDDEN` cross-object write (gotcha 2), or a `ReferenceError` from a free
406399
identifier or an unavailable global (e.g. `console`).
407-
- **`ctx.log.*` produced no output** — two independent causes: (1) without the
408-
`log` capability the call **throws**; (2) **with** the
409-
capability it emits only when the runtime wired a logger into the hook context —
410-
otherwise it is a **silent no-op**. Treat `ctx.log` as best-effort diagnostics,
400+
- **`ctx.log.*` produced no output** — without the `log` capability the call
401+
**throws**; **with** it, it emits only when the runtime wired a logger into the
402+
hook context — otherwise it is a **silent no-op**. Treat `ctx.log` as best-effort diagnostics,
411403
never proof a hook ran; to observe an effect, assert on the data it writes.
412404

413405
---
@@ -723,14 +715,15 @@ export default defineStack({
723715
});
724716
```
725717

726-
**2. Programmatic — `ctx.ql.registerHook()`, the plugin escape hatch.** Pass
718+
**2. Programmatic — `ctx.ql.registerHook()`, the `onEnable` escape hatch.** Pass
727719
`packageId` so the hook can be unregistered cleanly. ⚠️ Hooks bound this way get
728720
**none** of the declarative `condition` / `retryPolicy` / `timeoutMs` / `onError` /
729721
`async` semantics — those apply only through `defineStack({ hooks })` or
730722
`ql.bindHooks([...])`.
731723

732724
```typescript
733-
// in your plugin's onEnable()
725+
// in the app's `onEnable` export (objectstack.config.ts). A kernel plugin has no
726+
// `ctx.ql`: from `start(ctx)`, `ctx.getService('objectql').registerHook(…)`.
734727
ctx.ql.registerHook('beforeInsert', async (hookCtx) => { /* ... */ },
735728
{ object: 'account', priority: 100, packageId: 'my-plugin' });
736729
```
@@ -812,8 +805,10 @@ export default defineHook({
812805
- For several reasons throw `reasons: [{ reason: 'on_loan', params: { due } }, …]`, not
813806
`reason`: one translated line each, filled from its own `params`. `userMessage` joins
814807
them by newlines and ends with the entry's `message`, filled from the throw's
815-
top-level `params` (else its holes are empty); the HTTP doors answer
816-
`details.refusals: [{ reason, message }]`, absent for a single `reason`.
808+
top-level `params` (else its holes are empty). `/data` cuts `userMessage` (a single
809+
sentence's too) at 500 characters, so a long list loses its closing line there.
810+
`/data` and `/actions` answer `details.refusals: [{ reason, message }]` uncut
811+
(MCP tools relay the lines as text), absent for a single `reason`.
817812
- Translated via `hooks.<hook>.refusals.<CODE>.message` (or
818813
`….<CODE>.reasons.<REASON>.message`); the thrown text and `status` are unused.
819814
- An undeclared code (or none), or a reason missing from a code's `reasons` (a listed

‎skills/objectstack-ui/rules/actions.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ throws and checks are a hook's (objectstack-data → Lifecycle Hooks → Declare
147147
sentence is answered as `userMessage`, translated at
148148
`objects.<object>._actions.<action>.refusals.<CODE>.message` (objectstack-i18n); the console's
149149
failure toast shows it unless the action sets `errorMessage`. For several reasons throw
150-
`reasons: [{ reason, params? }, …]`, not `reason`: `userMessage` is one line per reason, closed
151-
by the code's `message` (rules there).
150+
`reasons: [{ reason, params? }, …]`, not `reason`: `userMessage` is one line per reason, then
151+
the code's `message` (Declared refusals).
152152

153153
### Writing in the organization's language (`texts`)
154154

0 commit comments

Comments
 (0)