Skip to content

Commit 0c9f76e

Browse files
committed
docs(skills): the regex-pattern warning says what main says; eval case 33 accepts either repair
Claude-Session: https://claude.ai/code/session_01L6bhgTRf6qBRCqPh4JZaZL Co-authored-by: Claude <noreply@anthropic.com>
1 parent 03b9383 commit 0c9f76e

3 files changed

Lines changed: 7 additions & 8 deletions

File tree

‎.changeset/35714-data-hooks-body-compile-refusal.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Metadata-protocol: none
99

1010
objectstack-data's `references/data-hooks.md`, "Sandbox restrictions":
1111

12-
- A new bullet says a `js` source is compiled, without being run, inside the `(async (ctx) => { … })` wrapper the runtime runs it in, where `ctx` is already declared. `const ctx = ctx.input || {};` (or `let ctx`, one name declared twice, any syntax error) is `hook-body-does-not-compile`: an error from `os validate`, `os build`, `os lint` and a runtime hook save (`422 INVALID_METADATA`), naming the hook, the `SyntaxError` and its line. The fix is to use `ctx` as it is or rename the local (`const input = ctx.input || {};`). A job's `js` body runs in the same wrapper and is `job-body-does-not-compile` from the three commands. A regular-expression pattern only the checking engine refuses is a warning.
13-
- Six restatements in the same file were removed to pay for the new text; the file is three lines and five tokens shorter than before.
12+
- A new bullet says a `js` source is compiled, without being run, inside the `(async (ctx) => { … })` wrapper the runtime runs it in, where `ctx` is already declared. `const ctx = ctx.input || {};` (or `let ctx`, one name declared twice, any syntax error) is `hook-body-does-not-compile`: an error from `os validate`, `os build`, `os lint` and a runtime hook save (`422 INVALID_METADATA`), naming the hook, the `SyntaxError` and its line. The fix is to use `ctx` as it is or rename the local (`const input = ctx.input || {};`). A job's `js` body runs in the same wrapper and is `job-body-does-not-compile` from the three commands. A regular-expression pattern the checking engine refuses is a warning: the runtime may accept it.
13+
- Six restatements in the same file were removed to pay for the new text; the file is four lines shorter and no larger in tokens than before.
1414

1515
`evals/hooks-security-seeds-datasources.json` gains one case on the refusal and its fix.

‎skills/objectstack-data/evals/hooks-security-seeds-datasources.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,10 @@
330330
{
331331
"id": 33,
332332
"prompt": "`os validate` reports an error on this `beforeInsert` hook on `lead`, and I cannot see why: `body: { language: 'js', source: \"const ctx = ctx.input || {}; if (!ctx.status) ctx.status = 'new';\", capabilities: [] }`. What is wrong, and what should the source be?",
333-
"expected_output": "The `js` source is compiled inside the wrapper the runtime runs it in, `(async (ctx) => { … })`, where `ctx` is already the parameter: `const ctx = …` declares it a second time, a SyntaxError before any statement runs. The finding is `hook-body-does-not-compile`, an error from `os validate`, `os build` and `os lint`, and a runtime save of the hook is refused with `422 INVALID_METADATA`. Fix: use `ctx` as it is (`if (!ctx.input.status) ctx.input.status = 'new';`) or give the local another name (`const input = ctx.input || {};`). Does not suppress the rule, and does not move the logic to a deprecated `handler`.",
333+
"expected_output": "The `js` source is compiled inside the wrapper the runtime runs it in, `(async (ctx) => { … })`, where `ctx` is already the parameter: `const ctx = …` declares it a second time, a SyntaxError before any statement runs. The finding is `hook-body-does-not-compile`, an error from `os validate`, `os build` and `os lint`, and a runtime save of the hook is refused with `422 INVALID_METADATA`. Fix: use `ctx` as it is (`if (!ctx.input.status) ctx.input.status = 'new';`) or give the local another name (`const input = ctx.input || {}; if (!input.status) input.status = 'new';`). Does not suppress the rule, and does not move the logic to a deprecated `handler`.",
334334
"files": [],
335335
"assertions": {
336-
"must_contain": ["hook-body-does-not-compile", "ctx.input.status"],
336+
"must_contain": ["hook-body-does-not-compile", "input.status"],
337337
"must_not_contain": []
338338
}
339339
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ The body runs in an isolated QuickJS VM, **not** Node:
345345
the hook, the `SyntaxError` and its line. Fix: use `ctx` as it is, or rename
346346
the local (`const input = ctx.input || {};`). A job's `js` body runs in the
347347
same wrapper: `job-body-does-not-compile`, from the three commands. A regex
348-
pattern only the checking engine refuses is a warning.
348+
pattern the checking engine refuses is a warning: the runtime may accept it.
349349

350350
> **A deadline stamped from an hours table is calendar hours** — nights, weekends and
351351
> holidays count. Name it `*_CALENDAR_HOURS` (`SLA_CALENDAR_HOURS`, or its camelCase)
@@ -774,9 +774,8 @@ the layout both real hook modules in the repo use.
774774

775775
## Best Practices
776776

777-
✅ **DO** — set
778-
`async: true` for non-critical background work; go through `ctx.api` for
779-
cross-object operations; refuse a business rule by a
777+
✅ **DO** — set `async: true` for non-critical background work; go through
778+
`ctx.api` for cross-object operations; refuse a business rule by a
780779
[declared code](#declared-refusals-refusals); test hooks in isolation.
781780

782781
❌ **DON'T** — do expensive work in `before*` (it blocks the transaction); write

0 commit comments

Comments
 (0)