@r_masseater/masseater-utils 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@r_masseater/masseater-utils",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "The small shared libraries of masseater's repositories as subpaths of one package: a chip row for React, Claude Code plugin helpers, Effect entry points for Node.js and GitHub Actions, file import mapping, Node package readers, OTLP assertions for Vitest and Cloudflare Workers tracing.",
5
5
  "keywords": [
6
6
  "actions",
@@ -2,13 +2,15 @@
2
2
  name: read-hook-input
3
3
  description: >
4
4
  Use when a Claude Code plugin hook or script must read JSON it did not write, such as a hook
5
- payload on stdin or a settings file: parseJson to parse without throwing and isRecord to narrow
6
- the result to a plain object.
5
+ payload on stdin or a settings file: runHook, readHookInput, writeHookOutput and blockHook for a
6
+ hook written with Effect, and parseJson and isRecord for plain code.
7
7
  metadata:
8
8
  type: core
9
9
  library: "@r_masseater/masseater-utils"
10
10
  sources:
11
11
  - src/app/plugin-kit*
12
+ - src/features/run-main/model/hook-io.ts
13
+ - src/features/run-main/model/run-hook.ts
12
14
  - src/shared/lib/record.ts
13
15
  - README.md
14
16
  ---
@@ -25,6 +27,37 @@ bun add @r_masseater/masseater-utils
25
27
 
26
28
  Commit the `bun.lock` that `bun add` writes. Claude Code installs the dependencies of a plugin from its `package.json` and a text `bun.lock` when it caches the plugin.
27
29
 
30
+ ## Run a hook with Effect
31
+
32
+ ```sh
33
+ bun add @r_masseater/masseater-utils effect @effect/platform-node
34
+ ```
35
+
36
+ ```ts
37
+ import {
38
+ blockHook,
39
+ readHookInput,
40
+ runHook,
41
+ writeHookOutput,
42
+ } from "@r_masseater/masseater-utils/plugin-kit";
43
+ import { Effect, Schema } from "effect";
44
+
45
+ const Input = Schema.Struct({ tool_input: Schema.Struct({ command: Schema.String }) });
46
+ const Output = Schema.Struct({ systemMessage: Schema.String });
47
+
48
+ runHook("my-plugin")(
49
+ Effect.gen(function* guard() {
50
+ const input = yield* readHookInput(Input);
51
+ if (input.tool_input.command.startsWith("pnpm")) {
52
+ return yield* blockHook("Use vp instead of pnpm.");
53
+ }
54
+ yield* writeHookOutput(Output)({ systemMessage: "checked" });
55
+ }),
56
+ );
57
+ ```
58
+
59
+ `readHookInput` decodes the JSON on stdin with the schema and keeps only the fields the schema names. `writeHookOutput` encodes the value and writes it to stdout. `blockHook` ends the hook with exit code 2 and writes the reason to stderr, which Claude Code shows to the model. `runHook` provides the Node services and sends traces under the given service name, like `runMain`. List `effect` and `@effect/platform-node` in the plugin's `dependencies`, because they are optional peers of this package and Claude Code installs only what the plugin lists.
60
+
28
61
  ## Read a payload
29
62
 
30
63
  ```ts