@r_masseater/plugin-kit 0.0.0 → 0.2.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/LICENSE +87 -0
- package/README.md +38 -1
- package/dist/index.d.mts +5691 -0
- package/dist/index.mjs +11974 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +44 -6
- package/skills/find-cache-folder/SKILL.md +36 -0
- package/skills/read-hook-input/SKILL.md +39 -0
package/package.json
CHANGED
|
@@ -1,15 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@r_masseater/plugin-kit",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Shared code for Claude Code plugin hooks and scripts: read untrusted JSON without throwing and find the plugin cache folder.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"claude-code",
|
|
7
|
+
"hooks",
|
|
8
|
+
"json",
|
|
9
|
+
"plugin",
|
|
10
|
+
"tanstack-intent"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://github.com/masseater/ecosystems/tree/main/libs/plugin-kit#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/masseater/ecosystems/issues"
|
|
15
|
+
},
|
|
5
16
|
"license": "MIT",
|
|
6
17
|
"repository": {
|
|
7
18
|
"type": "git",
|
|
8
19
|
"url": "git+https://github.com/masseater/ecosystems.git",
|
|
9
20
|
"directory": "libs/plugin-kit"
|
|
10
21
|
},
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
"
|
|
14
|
-
|
|
22
|
+
"files": [
|
|
23
|
+
"LICENSE",
|
|
24
|
+
"dist",
|
|
25
|
+
"skills/find-cache-folder",
|
|
26
|
+
"skills/read-hook-input"
|
|
27
|
+
],
|
|
28
|
+
"type": "module",
|
|
29
|
+
"sideEffects": false,
|
|
30
|
+
"imports": {
|
|
31
|
+
"#/*": "./src/*"
|
|
32
|
+
},
|
|
33
|
+
"exports": {
|
|
34
|
+
".": {
|
|
35
|
+
"types": "./dist/index.d.mts",
|
|
36
|
+
"default": "./dist/index.mjs"
|
|
37
|
+
},
|
|
38
|
+
"./package.json": "./package.json"
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public",
|
|
42
|
+
"provenance": true
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@effect/vitest": "4.1.5",
|
|
46
|
+
"effect": "4.1.5",
|
|
47
|
+
"vite-plus": "1.8.0"
|
|
48
|
+
},
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": ">=26.13.1"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {}
|
|
15
53
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: find-cache-folder
|
|
3
|
+
description: >
|
|
4
|
+
Use when a Claude Code plugin hook or script must keep downloaded or built files between runs,
|
|
5
|
+
such as a model, a binary or an installed tool: cacheRootOf gives the folder under
|
|
6
|
+
XDG_CACHE_HOME or ~/.cache.
|
|
7
|
+
metadata:
|
|
8
|
+
type: core
|
|
9
|
+
library: "@r_masseater/plugin-kit"
|
|
10
|
+
library_version: 0.2.0
|
|
11
|
+
sources:
|
|
12
|
+
- src/app/**
|
|
13
|
+
- README.md
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
# find-cache-folder
|
|
17
|
+
|
|
18
|
+
A plugin's own directory is replaced when the plugin updates, so files that are costly to fetch again belong in the user's cache folder. `cacheRootOf` gives that folder and keeps every plugin on the same rule.
|
|
19
|
+
|
|
20
|
+
## Setup
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
bun add @r_masseater/plugin-kit
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
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
|
+
|
|
28
|
+
## Find the folder
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { cacheRootOf } from "@r_masseater/plugin-kit";
|
|
32
|
+
|
|
33
|
+
const root = await cacheRootOf(["my-plugin", "runtime"]);
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
The folder is `$XDG_CACHE_HOME/my-plugin/runtime`, or `~/.cache/my-plugin/runtime` when `XDG_CACHE_HOME` is unset or empty. The function builds the path only and creates nothing. It rejects with `CacheRootError` when neither `XDG_CACHE_HOME` nor `HOME` (or `USERPROFILE` on Windows) is set. `cacheRootEffect` is the same lookup as an Effect: provide a `ConfigProvider` to test it with a fake environment.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: read-hook-input
|
|
3
|
+
description: >
|
|
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.
|
|
7
|
+
metadata:
|
|
8
|
+
type: core
|
|
9
|
+
library: "@r_masseater/plugin-kit"
|
|
10
|
+
library_version: 0.2.0
|
|
11
|
+
sources:
|
|
12
|
+
- src/app/**
|
|
13
|
+
- README.md
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
# read-hook-input
|
|
17
|
+
|
|
18
|
+
A hook payload comes from outside the hook, so its shape is not guaranteed. `parseJson` and `isRecord` read it without a cast and without a thrown error.
|
|
19
|
+
|
|
20
|
+
## Setup
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
bun add @r_masseater/plugin-kit
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
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
|
+
|
|
28
|
+
## Read a payload
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { isRecord, parseJson } from "@r_masseater/plugin-kit";
|
|
32
|
+
|
|
33
|
+
const parsed = parseJson(text);
|
|
34
|
+
if (parsed._tag === "Some" && isRecord(parsed.value)) {
|
|
35
|
+
console.log(parsed.value["tool_name"]);
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`parseJson` returns `{ _tag: "None" }` when the text is not JSON and never throws. `isRecord` is false for `null`, arrays and primitives, so check it before reading keys.
|