Skip to content

Commit a209074

Browse files
docs(skills): owner_id in the session-token filter example, bound user id in the hook find example (#34125)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9JvBUHu5JZehUFbNWsJ7EFW)_ Fixes #33730 Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:两个已发布技能文档里的查询示例。filters.md 的会话令牌示例从 `owner` 改为平台的归属列 `owner_id`;data-hooks.md 的 `find` 示例先从钩子上下文取 `ctx.session?.userId` 绑定到 `uid`,取不到就提前返回,不再用未定义的变量。 - 为什么改:PR #33726 复审指出这两个示例照抄会出错:`owner` 列平台并不提供,`uid` 是个未定义变量。 - 风险与回滚:只改文档示例和一个 patch changeset,不动代码;回滚就是 revert 本 PR。 - 先看:`skills/objectstack-data/references/data-hooks.md` 第 298–300 行,`skills/objectstack-query/rules/filters.md` 第 166 与 176 行。 - 两分钟验证:`node scripts/check-skills-token-ratchet.mjs`,预期两个文件都在上限内(filters.md 2469/2473,data-hooks.md 10003/10011)。 - 需要你做的:无,席位落地。 ## What changes - `skills/objectstack-query/rules/filters.md`: the session-token example now filters `owner_id: '{current_user_id}'`. `owner_id` is the platform's provisioned ownership column (`packages/objectql/src/registry.ts:1643-1649`, auto-added and stamped to the acting user on insert by SecurityPlugin; the doc block at `registry.ts:1334-1338` names it the canonical reassignable owner). The tokens' own source uses the same example (`packages/spec/src/data/context-tokens.zod.ts:27`). The surrounding "Session tokens" paragraph still reads true and is unchanged. - `skills/objectstack-data/references/data-hooks.md`: the `find` example's unbound `uid` is now bound from the hook context before the read: `const uid = ctx.session?.userId;` then `if (!uid) return;`, and the `find` line itself is unchanged. The hook context names the caller's id `HookContext.session.userId` (`packages/spec/src/data/hook.zod.ts:1411-1412`: `session: z.object({ userId: z.string().optional(), …`), and the retired-roles prescription at `hook.zod.ts:1617` says "read `ctx.session.userId` / `ctx.session.isSystem`". Optional chaining because the same file teaches that `ctx.session` is absent on system writes; the example returns early when there is no id. - `.changeset/33730-skills-query-hook-examples.md`: `@objectstack/skills` patch. ## Tests Docs-only diff; no test file is touched and no forced test edit exists. No eval prompt is added: both edits correct an existing example and add no new teaching. Readings on origin/main `f81e4b6c` (before) and this head (after): | File | Lines | Bytes | Tokens / ceiling | |:--|:--|:--|:--| | `skills/objectstack-query/rules/filters.md` | 209 → 208 | 9892 → 9876 | 2473 → 2469 / 2473 | | `skills/objectstack-data/references/data-hooks.md` | 893 → 895 | 39960 → 40011 | 9990 → 10003 / 10011 | | Whole package, sum of all `SKILL.md` | 4596 → 4596 | — | — | | Whole shipped bundle (ratchet total) | — | — | 246787 → 246796 | No ratchet row moved. filters.md sat at zero headroom, so the 3 bytes of the `owner_id` rename are paid in place: the Parameterised-tokens bullet drops its third restatement of `{30_days_ago}` (the token keeps its homes at line 71 and in the code example at line 157 of the same file). Net, filters.md is 16 bytes smaller (9892 → 9876). data-hooks.md's two new lines fit its existing headroom; nothing was cut there. ## Acceptance notes - Authored by an isolated os-dev subagent pinned to the contract-review tier on this branch, because this thread is served below the tier `dispatch-gates --tier` mandates for `skills/**`; the thread did the push, gates and relay. The seat agreed this route before the claim. - The changeset body opens with the two declaration lines and carries no title line. - Review round 1 (contract review record 6900946687): the hook example now reads the id first and returns early without one. A security item is with the owner seat. ## Verification All local readings are on head `2d1bc82e` (the round-1 commit on top of `d057b5bc`, which is author commit `0c58bfe6` merged with origin/main `385ea1cc`; origin/main has not moved since). Build closure under `os-verify-lock`: `pnpm build` VERDICT command-exit 0 (13m14s), then the packages main moved and their consumers (`...@objectstack/objectql`, `...@objectstack/metadata-protocol`) rebuilt, VERDICT command-exit 0; the round-1 commit touches only a skills file. `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` derives the same 46 families on this head; all 46 plus `check:skill-docs` and `check:skill-examples` ran, every one exit 0. `--ran` reconciles: "46 derived famil(ies) accounted for — 46 run, 0 NOT-MEASURED (a DERIVED zero)". <details><summary>Gate run on 2d1bc82 (48 commands, exit codes captured before any pipe)</summary> ```text node scripts/check-adr-0087-registration.mjs --base origin/main :: exit 0 node scripts/check-adr-0087-registration.mjs --self-test :: exit 0 node scripts/check-changeset-no-major.mjs --base origin/main :: exit 0 node scripts/check-closing-keyword-parity.mjs :: exit 0 node scripts/check-closing-keyword-parity.mjs --self-test :: exit 0 node scripts/check-comment-mask-corpus.mjs :: exit 0 node scripts/check-doc-route-spelling.mjs --advisory :: exit 0 node scripts/check-doc-route-spelling.mjs --self-test :: exit 0 node scripts/check-dts-emitted.mjs --self-test :: exit 0 node scripts/check-empty-changeset.mjs --base origin/main :: exit 0 node scripts/check-empty-changeset.mjs --self-test :: exit 0 node scripts/check-skills-token-ratchet.mjs :: exit 0 node scripts/check-skills-token-ratchet.mjs --self-test :: exit 0 node scripts/ci/assert-turbo-remote-cache.mjs --self-test :: exit 0 node scripts/ci/plan-test-core-shards.mjs --self-test :: exit 0 node scripts/ci/prune-turbo-cache.mjs --self-test :: exit 0 node scripts/ci/snapshot-next.mjs --self-test :: exit 0 node scripts/pm/check-governed-queue-guard.mjs --self-test :: exit 0 node scripts/pm/release-rehearsal-clone.mjs --self-test :: exit 0 node scripts/release-pending-publish.mjs --self-test :: exit 0 pnpm --filter @objectstack/lint run check:doc-formula-expressions :: exit 0 pnpm --filter @objectstack/spec run check:skill-refs :: exit 0 pnpm check:agent-test-spelling :: exit 0 pnpm check:changeset-gate-self-tests :: exit 0 pnpm check:ci-filter-parity :: exit 0 pnpm check:closed-ceremony-text :: exit 0 pnpm check:corpus-claim-drift :: exit 0 pnpm check:cross-package-test-inputs :: exit 0 pnpm check:doc-authoring :: exit 0 pnpm check:driver-memory-census :: exit 0 pnpm check:dts-closure :: exit 0 pnpm check:dual-build-cjs-loads :: exit 0 pnpm check:gitlink-declared :: exit 0 pnpm check:lean-entry-closure :: exit 0 pnpm check:nul-bytes :: exit 0 pnpm check:pm-governed-merges :: exit 0 pnpm check:pm-skill-id-lint :: exit 0 pnpm check:published-files :: exit 0 pnpm check:refd-timer-probe :: exit 0 pnpm check:role-word :: exit 0 pnpm check:skill-compatibility :: exit 0 pnpm check:skill-frame-sync :: exit 0 pnpm check:skill-identifier-liveness :: exit 0 pnpm check:skill-links :: exit 0 pnpm check:sourcemap-no-sources-content :: exit 0 pnpm check:watch-hint-literal :: exit 0 pnpm --filter @objectstack/spec run check:skill-docs :: exit 0 pnpm --filter @objectstack/spec run check:skill-examples :: exit 0 ``` </details> CI families are not re-run locally; read the PR's check-runs. <!-- signed: domain:skills#2 · os-steve · session_01ADHkmPNsfEF3TsQJfFdSGv --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 965c835 commit a209074

3 files changed

Lines changed: 12 additions & 3 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+
Clause-②: no
6+
Metadata-protocol: none
7+
8+
The published query and hook skill examples now filter on the platform's `owner_id` column with `{current_user_id}`, and the hook `find` example reads the caller's id from `ctx.session?.userId` instead of an unbound variable.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ same DSL as the [objectstack-query](../../objectstack-query/SKILL.md) skill:
295295
await ctx.api.object('candidate').findOne({ where: { id: ctx.result.id } });
296296
await ctx.api.object('candidate').find({ where: { stage: 'hired' } });
297297
await ctx.api.object('invoice').count({ where: { amount: { $gte: 1000 } } });
298+
const uid = ctx.session?.userId;
299+
if (!uid) return;
298300
await ctx.api.object('task').find({ where: { $and: [{ done: false }, { owner_id: uid }] } });
299301
```
300302

‎skills/objectstack-query/rules/filters.md‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,7 @@ where: {
163163
period boundaries like `{current_month_start}`, `{last_quarter_end}`,
164164
`{next_year_start}` (and bare aliases like `{month_start}`).
165165
- **Parameterised tokens:** `{N_<unit>_ago}` / `{N_<unit>_from_now}` with
166-
units `minute|hour|day|week|month|year` — e.g. `{30_days_ago}`,
167-
`{2_weeks_from_now}`.
166+
units `minute|hour|day|week|month|year` — e.g. `{2_weeks_from_now}`.
168167
- **Both spellings parse:** `{today}` and `${today}` are the same token
169168
(`DATE_MACRO_WRAPPED_RE` is `/^\$?\{([a-zA-Z0-9_]+)\}$/`, and the context
170169
tokens share it).
@@ -174,7 +173,7 @@ where: {
174173
user's id and the active organization id.
175174

176175
```typescript
177-
where: { owner: '{current_user_id}', close_date: { $gte: '{current_year_start}' } }
176+
where: { owner_id: '{current_user_id}', close_date: { $gte: '{current_year_start}' } }
178177
```
179178

180179
**Scope:** tokens expand on **both** sides of the wire — client-side by

0 commit comments

Comments
 (0)