@pluginfinity/core 0.2.0 → 0.3.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/config.js +15 -4
- package/env.js +94 -0
- package/hooks.js +6 -2
- package/index.d.ts +283 -11
- package/index.js +6 -3
- package/monitors.js +65 -0
- package/name.js +13 -0
- package/package.json +1 -1
- package/target.js +85 -9
- package/version.js +1 -1
package/config.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { Hooks } from "./hooks.js";
|
|
2
|
+
import { EnvConfig } from "./env.js";
|
|
2
3
|
import { McpServers } from "./mcp.js";
|
|
3
4
|
import { LspServers } from "./lsp.js";
|
|
5
|
+
import { KebabName } from "./name.js";
|
|
6
|
+
import { Monitors } from "./monitors.js";
|
|
4
7
|
import { Schema } from "effect";
|
|
5
8
|
|
|
6
9
|
//#region src/config.ts
|
|
@@ -10,7 +13,7 @@ import { Schema } from "effect";
|
|
|
10
13
|
*
|
|
11
14
|
* @public
|
|
12
15
|
*/
|
|
13
|
-
const PluginName =
|
|
16
|
+
const PluginName = KebabName;
|
|
14
17
|
/**
|
|
15
18
|
* How a `script` hook is invoked: through `bash`, which ignores the file
|
|
16
19
|
* mode, or directly, which needs the executable bit.
|
|
@@ -62,8 +65,12 @@ const BaseConfigFields = {
|
|
|
62
65
|
mcpServers: Schema.optionalKey(McpServers),
|
|
63
66
|
/** LSP servers in Claude Code's `.lsp.json` server shape. */
|
|
64
67
|
lspServers: Schema.optionalKey(LspServers),
|
|
68
|
+
/** Background monitors, keyed by name; Claude Code delivers each stdout line to the model. */
|
|
69
|
+
monitors: Schema.optionalKey(Monitors),
|
|
65
70
|
/** Extra files and directories (ending in `/`) shipped to every target. */
|
|
66
|
-
files: Schema.optionalKey(Schema.Array(ShippedPath))
|
|
71
|
+
files: Schema.optionalKey(Schema.Array(ShippedPath)),
|
|
72
|
+
/** Session variables the plugin keeps, resolved once at SessionStart; plugin-wide, with no per-target override. */
|
|
73
|
+
env: Schema.optionalKey(EnvConfig)
|
|
67
74
|
};
|
|
68
75
|
/**
|
|
69
76
|
* The names of the plugin-wide config fields.
|
|
@@ -79,16 +86,20 @@ const BASE_CONFIG_KEYS = Object.keys(BaseConfigFields);
|
|
|
79
86
|
* `hooks` is the target's own hooks schema, so each target admits the events
|
|
80
87
|
* it has: a hook under it replaces the base entries for that event on that
|
|
81
88
|
* target, and `[]` removes them. A server under `mcpServers` or `lspServers`
|
|
82
|
-
* replaces the base server of that name
|
|
89
|
+
* replaces the base server of that name, and a monitor under `monitors`
|
|
90
|
+
* replaces the base monitor of that name.
|
|
83
91
|
*
|
|
84
92
|
* @public
|
|
85
93
|
*/
|
|
86
94
|
const makeTargetSetting = (hooks) => Schema.Union([Schema.Literal(true), Schema.Struct({
|
|
87
95
|
/** The plugin's name on this host, when it differs from the base `name`. */
|
|
88
96
|
name: Schema.optionalKey(PluginName),
|
|
97
|
+
/** Extra files and directories (ending in `/`) shipped to this target only, on top of the base `files`. */
|
|
98
|
+
files: Schema.optionalKey(Schema.Array(ShippedPath)),
|
|
89
99
|
hooks: Schema.optionalKey(hooks),
|
|
90
100
|
mcpServers: Schema.optionalKey(McpServers),
|
|
91
|
-
lspServers: Schema.optionalKey(LspServers)
|
|
101
|
+
lspServers: Schema.optionalKey(LspServers),
|
|
102
|
+
monitors: Schema.optionalKey(Monitors)
|
|
92
103
|
})]);
|
|
93
104
|
|
|
94
105
|
//#endregion
|
package/env.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { PluginRelativePath } from "./hooks.js";
|
|
2
|
+
import { Schema } from "effect";
|
|
3
|
+
|
|
4
|
+
//#region src/env.ts
|
|
5
|
+
const RESERVED_NAME_LIST = [
|
|
6
|
+
"PATH",
|
|
7
|
+
"IFS",
|
|
8
|
+
"HOME",
|
|
9
|
+
"PWD",
|
|
10
|
+
"XDG_STATE_HOME",
|
|
11
|
+
"TMPDIR",
|
|
12
|
+
"SHELL",
|
|
13
|
+
"BASH_ENV",
|
|
14
|
+
"ENV",
|
|
15
|
+
"CDPATH",
|
|
16
|
+
"SHELLOPTS",
|
|
17
|
+
"BASHOPTS",
|
|
18
|
+
"PS4"
|
|
19
|
+
];
|
|
20
|
+
const RESERVED_NAMES = new Set(RESERVED_NAME_LIST);
|
|
21
|
+
const RESERVED_PREFIXES = [
|
|
22
|
+
"PLUGINFINITY_",
|
|
23
|
+
"_PF_",
|
|
24
|
+
"CLAUDE_",
|
|
25
|
+
"COPILOT_",
|
|
26
|
+
"LD_",
|
|
27
|
+
"DYLD_"
|
|
28
|
+
];
|
|
29
|
+
const RESERVED_MESSAGE = `is reserved: ${RESERVED_NAME_LIST.join(", ")} and names starting ${RESERVED_PREFIXES.join(", ")} belong to the env library, a host, the shell or the dynamic loader`;
|
|
30
|
+
const NAME_PATTERN = /^[A-Z_][A-Z0-9_]*$/;
|
|
31
|
+
const NAME_MESSAGE = "must be upper case letters, digits and _, not starting with a digit";
|
|
32
|
+
const isReserved = (name) => RESERVED_NAMES.has(name) || RESERVED_PREFIXES.some((prefix) => name.startsWith(prefix));
|
|
33
|
+
/**
|
|
34
|
+
* A session variable's name: upper case letters, digits and `_`, not starting
|
|
35
|
+
* with a digit.
|
|
36
|
+
*
|
|
37
|
+
* @remarks
|
|
38
|
+
* The env library, the hosts, the shell and the dynamic loader own some names:
|
|
39
|
+
* `PATH`, `IFS`, `HOME`, `PWD`, `XDG_STATE_HOME`, `TMPDIR`, `SHELL`,
|
|
40
|
+
* `BASH_ENV`, `ENV`, `CDPATH`, `SHELLOPTS`, `BASHOPTS` and `PS4`, and every name
|
|
41
|
+
* starting `PLUGINFINITY_`, `_PF_`, `CLAUDE_`, `COPILOT_`, `LD_` or `DYLD_`. A
|
|
42
|
+
* declared one would shadow them in every hook, so they are rejected.
|
|
43
|
+
*
|
|
44
|
+
* @public
|
|
45
|
+
*/
|
|
46
|
+
const EnvVarName = Schema.String.check(Schema.isPattern(NAME_PATTERN, { message: NAME_MESSAGE }), Schema.makeFilter((name) => isReserved(name) ? RESERVED_MESSAGE : void 0));
|
|
47
|
+
/**
|
|
48
|
+
* One declared session variable. Values are strings; `default` defaults to `""`
|
|
49
|
+
* and holds no newline or other control character but tab.
|
|
50
|
+
*
|
|
51
|
+
* @public
|
|
52
|
+
*/
|
|
53
|
+
const EnvVar = Schema.Struct({
|
|
54
|
+
/** The value when nothing else sets it, on one line with no control character but tab. Defaults to `""`. */
|
|
55
|
+
default: Schema.optionalKey(Schema.String.check(Schema.isPattern(/^[^\u0000-\u0008\u000a-\u001f\u007f]*$/, { message: "must be one line with no control character but tab: the session values file holds one NAME=value per line" }))),
|
|
56
|
+
/** What the variable holds, for readers of the config. */
|
|
57
|
+
description: Schema.optionalKey(Schema.String)
|
|
58
|
+
});
|
|
59
|
+
/**
|
|
60
|
+
* The session variables a plugin keeps, resolved once at SessionStart and
|
|
61
|
+
* read by its hooks, skill scripts and monitors.
|
|
62
|
+
*
|
|
63
|
+
* @remarks
|
|
64
|
+
* With `prefix` set, every declared name must start with `${prefix}_`. `setup`
|
|
65
|
+
* is a plugin-relative script whose `NAME=value` stdout lines rank above the
|
|
66
|
+
* defaults and below the project's `.env`. Record keys cannot repeat, so a
|
|
67
|
+
* name is declared once.
|
|
68
|
+
*
|
|
69
|
+
* @public
|
|
70
|
+
*/
|
|
71
|
+
const EnvConfig = Schema.Struct({
|
|
72
|
+
/** When set, every declared name starts with `${prefix}_`. */
|
|
73
|
+
prefix: Schema.optionalKey(Schema.String.check(Schema.isPattern(/^[A-Z_][A-Z0-9_]*$/, { message: "must be upper case letters, digits and _, not starting with a digit" }))),
|
|
74
|
+
/** The declared variables, keyed by name: each an {@link EnvVarName}. */
|
|
75
|
+
vars: Schema.Record(Schema.String, EnvVar),
|
|
76
|
+
/** A plugin-relative script that prints `NAME=value` lines at SessionStart. */
|
|
77
|
+
setup: Schema.optionalKey(PluginRelativePath)
|
|
78
|
+
}).check(Schema.makeFilter((env) => Object.keys(env.vars).flatMap((name) => {
|
|
79
|
+
const issue = !NAME_PATTERN.test(name) ? NAME_MESSAGE : isReserved(name) ? RESERVED_MESSAGE : void 0;
|
|
80
|
+
return issue === void 0 ? [] : [{
|
|
81
|
+
path: ["vars", name],
|
|
82
|
+
issue
|
|
83
|
+
}];
|
|
84
|
+
})), Schema.makeFilter((env) => {
|
|
85
|
+
const prefix = env.prefix;
|
|
86
|
+
if (prefix === void 0) return void 0;
|
|
87
|
+
return Object.keys(env.vars).filter((name) => !name.startsWith(`${prefix}_`)).map((name) => ({
|
|
88
|
+
path: ["vars", name],
|
|
89
|
+
issue: `must start with the prefix "${prefix}_"`
|
|
90
|
+
}));
|
|
91
|
+
}));
|
|
92
|
+
|
|
93
|
+
//#endregion
|
|
94
|
+
export { EnvConfig, EnvVar, EnvVarName };
|
package/hooks.js
CHANGED
|
@@ -58,6 +58,8 @@ const HookFallback = Schema.Literals(["fail", "omit"]);
|
|
|
58
58
|
/**
|
|
59
59
|
* A path relative to the plugin root: no leading slash, no backslash, no `..`
|
|
60
60
|
* segment.
|
|
61
|
+
*
|
|
62
|
+
* @public
|
|
61
63
|
*/
|
|
62
64
|
const PluginRelativePath = Schema.String.check(Schema.isPattern(/^(?![/\\])(?!(?:[\s\S]*\/)?\.\.(?:\/|$))[^\\\u0000-\u001f]+$/, { message: "must be a path relative to the plugin root, with no leading slash, backslash, control character or .. segment" }));
|
|
63
65
|
const PositiveInt = Schema.Int.check(Schema.isGreaterThan(0, { message: "must be a positive whole number of seconds" }));
|
|
@@ -67,7 +69,9 @@ const sharedHookFields = {
|
|
|
67
69
|
/** Seconds before the host gives up on the hook. */
|
|
68
70
|
timeout: Schema.optionalKey(PositiveInt),
|
|
69
71
|
/** What a target without this event does. Defaults to `"fail"`. */
|
|
70
|
-
fallback: Schema.optionalKey(HookFallback)
|
|
72
|
+
fallback: Schema.optionalKey(HookFallback),
|
|
73
|
+
/** Deny or block when the script fails before answering. Defaults to failing open. */
|
|
74
|
+
failClosed: Schema.optionalKey(Schema.Boolean)
|
|
71
75
|
};
|
|
72
76
|
/**
|
|
73
77
|
* A hook that runs a script the plugin ships. The build checks the script
|
|
@@ -121,4 +125,4 @@ const makeHooks = (events) => Schema.Struct(Object.fromEntries(events.map((event
|
|
|
121
125
|
const Hooks = makeHooks(CLAUDE_HOOK_EVENTS);
|
|
122
126
|
|
|
123
127
|
//#endregion
|
|
124
|
-
export { CLAUDE_HOOK_EVENTS, ClaudeHookEvent, CommandHook, HookEntries, HookEntry, HookFallback, Hooks, ScriptHook, makeHooks };
|
|
128
|
+
export { CLAUDE_HOOK_EVENTS, ClaudeHookEvent, CommandHook, HookEntries, HookEntry, HookFallback, Hooks, PluginRelativePath, ScriptHook, makeHooks };
|
package/index.d.ts
CHANGED
|
@@ -26,6 +26,13 @@ export type ClaudeHookEvent = typeof ClaudeHookEvent.Type;
|
|
|
26
26
|
* @public
|
|
27
27
|
*/
|
|
28
28
|
export declare const HookFallback: Schema.Literals<readonly ["fail", "omit"]>;
|
|
29
|
+
/**
|
|
30
|
+
* A path relative to the plugin root: no leading slash, no backslash, no `..`
|
|
31
|
+
* segment.
|
|
32
|
+
*
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
export declare const PluginRelativePath: Schema.String;
|
|
29
36
|
/**
|
|
30
37
|
* A hook that runs a script the plugin ships. The build checks the script
|
|
31
38
|
* exists and writes each host's command for it.
|
|
@@ -36,6 +43,7 @@ export declare const ScriptHook: Schema.Struct<{
|
|
|
36
43
|
readonly matcher: Schema.optionalKey<Schema.String>;
|
|
37
44
|
readonly timeout: Schema.optionalKey<Schema.Int>;
|
|
38
45
|
readonly fallback: Schema.optionalKey<Schema.Literals<readonly ["fail", "omit"]>>;
|
|
46
|
+
readonly failClosed: Schema.optionalKey<Schema.Boolean>;
|
|
39
47
|
readonly script: Schema.String;
|
|
40
48
|
readonly args: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
41
49
|
}>;
|
|
@@ -48,6 +56,7 @@ export declare const CommandHook: Schema.Struct<{
|
|
|
48
56
|
readonly matcher: Schema.optionalKey<Schema.String>;
|
|
49
57
|
readonly timeout: Schema.optionalKey<Schema.Int>;
|
|
50
58
|
readonly fallback: Schema.optionalKey<Schema.Literals<readonly ["fail", "omit"]>>;
|
|
59
|
+
readonly failClosed: Schema.optionalKey<Schema.Boolean>;
|
|
51
60
|
readonly command: Schema.String;
|
|
52
61
|
}>;
|
|
53
62
|
/**
|
|
@@ -60,12 +69,14 @@ export declare const HookEntry: Schema.Union<readonly [Schema.Struct<{
|
|
|
60
69
|
readonly matcher: Schema.optionalKey<Schema.String>;
|
|
61
70
|
readonly timeout: Schema.optionalKey<Schema.Int>;
|
|
62
71
|
readonly fallback: Schema.optionalKey<Schema.Literals<readonly ["fail", "omit"]>>;
|
|
72
|
+
readonly failClosed: Schema.optionalKey<Schema.Boolean>;
|
|
63
73
|
readonly script: Schema.String;
|
|
64
74
|
readonly args: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
65
75
|
}>, Schema.Struct<{
|
|
66
76
|
readonly matcher: Schema.optionalKey<Schema.String>;
|
|
67
77
|
readonly timeout: Schema.optionalKey<Schema.Int>;
|
|
68
78
|
readonly fallback: Schema.optionalKey<Schema.Literals<readonly ["fail", "omit"]>>;
|
|
79
|
+
readonly failClosed: Schema.optionalKey<Schema.Boolean>;
|
|
69
80
|
readonly command: Schema.String;
|
|
70
81
|
}>]>;
|
|
71
82
|
/**
|
|
@@ -84,12 +95,14 @@ export declare const HookEntries: Schema.$Array<Schema.Union<readonly [Schema.St
|
|
|
84
95
|
readonly matcher: Schema.optionalKey<Schema.String>;
|
|
85
96
|
readonly timeout: Schema.optionalKey<Schema.Int>;
|
|
86
97
|
readonly fallback: Schema.optionalKey<Schema.Literals<readonly ["fail", "omit"]>>;
|
|
98
|
+
readonly failClosed: Schema.optionalKey<Schema.Boolean>;
|
|
87
99
|
readonly script: Schema.String;
|
|
88
100
|
readonly args: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
89
101
|
}>, Schema.Struct<{
|
|
90
102
|
readonly matcher: Schema.optionalKey<Schema.String>;
|
|
91
103
|
readonly timeout: Schema.optionalKey<Schema.Int>;
|
|
92
104
|
readonly fallback: Schema.optionalKey<Schema.Literals<readonly ["fail", "omit"]>>;
|
|
105
|
+
readonly failClosed: Schema.optionalKey<Schema.Boolean>;
|
|
93
106
|
readonly command: Schema.String;
|
|
94
107
|
}>]>>;
|
|
95
108
|
/**
|
|
@@ -199,8 +212,28 @@ export declare const BaseConfigFields: {
|
|
|
199
212
|
readonly maxRestarts: Schema.optionalKey<Schema.Number>;
|
|
200
213
|
readonly diagnostics: Schema.optionalKey<Schema.Boolean>;
|
|
201
214
|
}>>>;
|
|
215
|
+
/** Background monitors, keyed by name; Claude Code delivers each stdout line to the model. */
|
|
216
|
+
readonly monitors: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Union<readonly [Schema.Struct<{
|
|
217
|
+
readonly description: Schema.String;
|
|
218
|
+
readonly when: Schema.optionalKey<Schema.Union<readonly [Schema.Literal<"always">, Schema.String]>>;
|
|
219
|
+
readonly script: Schema.String;
|
|
220
|
+
readonly args: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
221
|
+
}>, Schema.Struct<{
|
|
222
|
+
readonly description: Schema.String;
|
|
223
|
+
readonly when: Schema.optionalKey<Schema.Union<readonly [Schema.Literal<"always">, Schema.String]>>;
|
|
224
|
+
readonly command: Schema.String;
|
|
225
|
+
}>]>>>;
|
|
202
226
|
/** Extra files and directories (ending in `/`) shipped to every target. */
|
|
203
227
|
readonly files: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
228
|
+
/** Session variables the plugin keeps, resolved once at SessionStart; plugin-wide, with no per-target override. */
|
|
229
|
+
readonly env: Schema.optionalKey<Schema.Struct<{
|
|
230
|
+
readonly prefix: Schema.optionalKey<Schema.String>;
|
|
231
|
+
readonly vars: Schema.$Record<Schema.String, Schema.Struct<{
|
|
232
|
+
readonly default: Schema.optionalKey<Schema.String>;
|
|
233
|
+
readonly description: Schema.optionalKey<Schema.String>;
|
|
234
|
+
}>>;
|
|
235
|
+
readonly setup: Schema.optionalKey<Schema.String>;
|
|
236
|
+
}>>;
|
|
204
237
|
};
|
|
205
238
|
/**
|
|
206
239
|
* The names of the plugin-wide config fields.
|
|
@@ -216,13 +249,16 @@ export declare const BASE_CONFIG_KEYS: ReadonlyArray<string>;
|
|
|
216
249
|
* `hooks` is the target's own hooks schema, so each target admits the events
|
|
217
250
|
* it has: a hook under it replaces the base entries for that event on that
|
|
218
251
|
* target, and `[]` removes them. A server under `mcpServers` or `lspServers`
|
|
219
|
-
* replaces the base server of that name
|
|
252
|
+
* replaces the base server of that name, and a monitor under `monitors`
|
|
253
|
+
* replaces the base monitor of that name.
|
|
220
254
|
*
|
|
221
255
|
* @public
|
|
222
256
|
*/
|
|
223
257
|
export declare const makeTargetSetting: <H extends Schema.Top>(hooks: H) => Schema.Union<readonly [Schema.Literal<true>, Schema.Struct<{
|
|
224
258
|
/** The plugin's name on this host, when it differs from the base `name`. */
|
|
225
259
|
readonly name: Schema.optionalKey<Schema.String>;
|
|
260
|
+
/** Extra files and directories (ending in `/`) shipped to this target only, on top of the base `files`. */
|
|
261
|
+
readonly files: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
226
262
|
readonly hooks: Schema.optionalKey<H>;
|
|
227
263
|
readonly mcpServers: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Union<readonly [Schema.Struct<{
|
|
228
264
|
readonly type: Schema.optionalKey<Schema.Literal<"stdio">>;
|
|
@@ -249,8 +285,77 @@ export declare const makeTargetSetting: <H extends Schema.Top>(hooks: H) => Sche
|
|
|
249
285
|
readonly maxRestarts: Schema.optionalKey<Schema.Number>;
|
|
250
286
|
readonly diagnostics: Schema.optionalKey<Schema.Boolean>;
|
|
251
287
|
}>>>;
|
|
288
|
+
readonly monitors: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Union<readonly [Schema.Struct<{
|
|
289
|
+
readonly description: Schema.String;
|
|
290
|
+
readonly when: Schema.optionalKey<Schema.Union<readonly [Schema.Literal<"always">, Schema.String]>>;
|
|
291
|
+
readonly script: Schema.String;
|
|
292
|
+
readonly args: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
293
|
+
}>, Schema.Struct<{
|
|
294
|
+
readonly description: Schema.String;
|
|
295
|
+
readonly when: Schema.optionalKey<Schema.Union<readonly [Schema.Literal<"always">, Schema.String]>>;
|
|
296
|
+
readonly command: Schema.String;
|
|
297
|
+
}>]>>>;
|
|
252
298
|
}>]>;
|
|
253
299
|
//#endregion
|
|
300
|
+
//#region src/env.d.ts
|
|
301
|
+
/**
|
|
302
|
+
* A session variable's name: upper case letters, digits and `_`, not starting
|
|
303
|
+
* with a digit.
|
|
304
|
+
*
|
|
305
|
+
* @remarks
|
|
306
|
+
* The env library, the hosts, the shell and the dynamic loader own some names:
|
|
307
|
+
* `PATH`, `IFS`, `HOME`, `PWD`, `XDG_STATE_HOME`, `TMPDIR`, `SHELL`,
|
|
308
|
+
* `BASH_ENV`, `ENV`, `CDPATH`, `SHELLOPTS`, `BASHOPTS` and `PS4`, and every name
|
|
309
|
+
* starting `PLUGINFINITY_`, `_PF_`, `CLAUDE_`, `COPILOT_`, `LD_` or `DYLD_`. A
|
|
310
|
+
* declared one would shadow them in every hook, so they are rejected.
|
|
311
|
+
*
|
|
312
|
+
* @public
|
|
313
|
+
*/
|
|
314
|
+
export declare const EnvVarName: Schema.String;
|
|
315
|
+
/**
|
|
316
|
+
* One declared session variable. Values are strings; `default` defaults to `""`
|
|
317
|
+
* and holds no newline or other control character but tab.
|
|
318
|
+
*
|
|
319
|
+
* @public
|
|
320
|
+
*/
|
|
321
|
+
export declare const EnvVar: Schema.Struct<{
|
|
322
|
+
/** The value when nothing else sets it, on one line with no control character but tab. Defaults to `""`. */
|
|
323
|
+
readonly default: Schema.optionalKey<Schema.String>;
|
|
324
|
+
/** What the variable holds, for readers of the config. */
|
|
325
|
+
readonly description: Schema.optionalKey<Schema.String>;
|
|
326
|
+
}>;
|
|
327
|
+
/**
|
|
328
|
+
* The session variables a plugin keeps, resolved once at SessionStart and
|
|
329
|
+
* read by its hooks, skill scripts and monitors.
|
|
330
|
+
*
|
|
331
|
+
* @remarks
|
|
332
|
+
* With `prefix` set, every declared name must start with `${prefix}_`. `setup`
|
|
333
|
+
* is a plugin-relative script whose `NAME=value` stdout lines rank above the
|
|
334
|
+
* defaults and below the project's `.env`. Record keys cannot repeat, so a
|
|
335
|
+
* name is declared once.
|
|
336
|
+
*
|
|
337
|
+
* @public
|
|
338
|
+
*/
|
|
339
|
+
export declare const EnvConfig: Schema.Struct<{
|
|
340
|
+
/** When set, every declared name starts with `${prefix}_`. */
|
|
341
|
+
readonly prefix: Schema.optionalKey<Schema.String>;
|
|
342
|
+
/** The declared variables, keyed by name: each an {@link EnvVarName}. */
|
|
343
|
+
readonly vars: Schema.$Record<Schema.String, Schema.Struct<{
|
|
344
|
+
/** The value when nothing else sets it, on one line with no control character but tab. Defaults to `""`. */
|
|
345
|
+
readonly default: Schema.optionalKey<Schema.String>;
|
|
346
|
+
/** What the variable holds, for readers of the config. */
|
|
347
|
+
readonly description: Schema.optionalKey<Schema.String>;
|
|
348
|
+
}>>;
|
|
349
|
+
/** A plugin-relative script that prints `NAME=value` lines at SessionStart. */
|
|
350
|
+
readonly setup: Schema.optionalKey<Schema.String>;
|
|
351
|
+
}>;
|
|
352
|
+
/**
|
|
353
|
+
* The decoded `EnvConfig`.
|
|
354
|
+
*
|
|
355
|
+
* @public
|
|
356
|
+
*/
|
|
357
|
+
export type EnvConfig = typeof EnvConfig.Type;
|
|
358
|
+
//#endregion
|
|
254
359
|
//#region src/frontmatter.d.ts
|
|
255
360
|
/**
|
|
256
361
|
* A skill or agent name: kebab-case and at most 64 characters, the Agent
|
|
@@ -465,6 +570,94 @@ export declare const McpServers: Schema.$Record<Schema.String, Schema.Union<read
|
|
|
465
570
|
readonly headers: Schema.optionalKey<Schema.$Record<Schema.String, Schema.String>>;
|
|
466
571
|
}>]>>;
|
|
467
572
|
//#endregion
|
|
573
|
+
//#region src/monitors.d.ts
|
|
574
|
+
/**
|
|
575
|
+
* A monitor's name: kebab-case, the key it is written under.
|
|
576
|
+
*
|
|
577
|
+
* @public
|
|
578
|
+
*/
|
|
579
|
+
export declare const MonitorName: Schema.String;
|
|
580
|
+
/**
|
|
581
|
+
* When a monitor starts: `"always"` (the default) or the first time a named
|
|
582
|
+
* skill is invoked, as `on-skill-invoke:<skill>`.
|
|
583
|
+
*
|
|
584
|
+
* @remarks
|
|
585
|
+
* `<skill>` is the bare skill name, so the source is host-neutral: it holds no
|
|
586
|
+
* `:`. Claude Code matches the plugin-qualified name `<plugin>:<skill>`, and
|
|
587
|
+
* the build writes that form.
|
|
588
|
+
*
|
|
589
|
+
* @public
|
|
590
|
+
*/
|
|
591
|
+
export declare const MonitorWhen: Schema.Union<readonly [Schema.Literal<"always">, Schema.String]>;
|
|
592
|
+
/**
|
|
593
|
+
* A monitor that runs a script the plugin ships. Each line it prints to
|
|
594
|
+
* stdout is delivered to the model.
|
|
595
|
+
*
|
|
596
|
+
* @public
|
|
597
|
+
*/
|
|
598
|
+
export declare const ScriptMonitor: Schema.Struct<{
|
|
599
|
+
readonly description: Schema.String;
|
|
600
|
+
readonly when: Schema.optionalKey<Schema.Union<readonly [Schema.Literal<"always">, Schema.String]>>;
|
|
601
|
+
readonly script: Schema.String;
|
|
602
|
+
readonly args: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
603
|
+
}>;
|
|
604
|
+
/**
|
|
605
|
+
* A monitor given as a command string. `${PLUGIN_ROOT}` is its one placeholder.
|
|
606
|
+
*
|
|
607
|
+
* @public
|
|
608
|
+
*/
|
|
609
|
+
export declare const CommandMonitor: Schema.Struct<{
|
|
610
|
+
readonly description: Schema.String;
|
|
611
|
+
readonly when: Schema.optionalKey<Schema.Union<readonly [Schema.Literal<"always">, Schema.String]>>;
|
|
612
|
+
readonly command: Schema.String;
|
|
613
|
+
}>;
|
|
614
|
+
/**
|
|
615
|
+
* One monitor: exactly one of `script` or `command`. Decode strictly, or a
|
|
616
|
+
* mixed entry decodes as whichever member matches first.
|
|
617
|
+
*
|
|
618
|
+
* @public
|
|
619
|
+
*/
|
|
620
|
+
export declare const MonitorEntry: Schema.Union<readonly [Schema.Struct<{
|
|
621
|
+
readonly description: Schema.String;
|
|
622
|
+
readonly when: Schema.optionalKey<Schema.Union<readonly [Schema.Literal<"always">, Schema.String]>>;
|
|
623
|
+
readonly script: Schema.String;
|
|
624
|
+
readonly args: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
625
|
+
}>, Schema.Struct<{
|
|
626
|
+
readonly description: Schema.String;
|
|
627
|
+
readonly when: Schema.optionalKey<Schema.Union<readonly [Schema.Literal<"always">, Schema.String]>>;
|
|
628
|
+
readonly command: Schema.String;
|
|
629
|
+
}>]>;
|
|
630
|
+
/**
|
|
631
|
+
* The decoded `MonitorEntry`.
|
|
632
|
+
*
|
|
633
|
+
* @public
|
|
634
|
+
*/
|
|
635
|
+
export type MonitorEntry = typeof MonitorEntry.Type;
|
|
636
|
+
/**
|
|
637
|
+
* A plugin's monitors, keyed by name.
|
|
638
|
+
*
|
|
639
|
+
* @public
|
|
640
|
+
*/
|
|
641
|
+
export declare const Monitors: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.Struct<{
|
|
642
|
+
readonly description: Schema.String;
|
|
643
|
+
readonly when: Schema.optionalKey<Schema.Union<readonly [Schema.Literal<"always">, Schema.String]>>;
|
|
644
|
+
readonly script: Schema.String;
|
|
645
|
+
readonly args: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
646
|
+
}>, Schema.Struct<{
|
|
647
|
+
readonly description: Schema.String;
|
|
648
|
+
readonly when: Schema.optionalKey<Schema.Union<readonly [Schema.Literal<"always">, Schema.String]>>;
|
|
649
|
+
readonly command: Schema.String;
|
|
650
|
+
}>]>>;
|
|
651
|
+
//#endregion
|
|
652
|
+
//#region src/name.d.ts
|
|
653
|
+
/**
|
|
654
|
+
* A name every host accepts: kebab-case, lowercase letters and digits
|
|
655
|
+
* separated by single hyphens.
|
|
656
|
+
*
|
|
657
|
+
* @public
|
|
658
|
+
*/
|
|
659
|
+
export declare const KebabName: Schema.String;
|
|
660
|
+
//#endregion
|
|
468
661
|
//#region src/target.d.ts
|
|
469
662
|
/**
|
|
470
663
|
* The forms a field can be moved into when a host lacks it. The engine owns
|
|
@@ -494,21 +687,54 @@ export declare const HOOKS_FORMATS: readonly ["claude-hooks-json", "copilot-hook
|
|
|
494
687
|
/** @public */
|
|
495
688
|
export declare const HooksFormat: Schema.Literals<readonly ["claude-hooks-json", "copilot-hooks-v1"]>;
|
|
496
689
|
/**
|
|
497
|
-
* MCP config formats. The engine owns one encoder per format
|
|
690
|
+
* MCP config formats. The engine owns one encoder per format:
|
|
691
|
+
* `claude-mcp-servers` is the bare server map Claude Code reads under a
|
|
692
|
+
* manifest's `mcpServers` key, and `agent-plugins-mcp-1.0` is the Agent
|
|
693
|
+
* Plugins `mcp.json` envelope, `$schema` and an `mcpServers` map.
|
|
498
694
|
*
|
|
499
695
|
* @public
|
|
500
696
|
*/
|
|
501
|
-
export declare const MCP_FORMATS: readonly ["claude-mcp-
|
|
697
|
+
export declare const MCP_FORMATS: readonly ["claude-mcp-servers", "agent-plugins-mcp-1.0"];
|
|
502
698
|
/** @public */
|
|
503
|
-
export declare const McpFormat: Schema.Literals<readonly ["claude-mcp-
|
|
699
|
+
export declare const McpFormat: Schema.Literals<readonly ["claude-mcp-servers", "agent-plugins-mcp-1.0"]>;
|
|
504
700
|
/**
|
|
505
|
-
* LSP config formats. The engine owns one encoder per format
|
|
701
|
+
* LSP config formats. The engine owns one encoder per format:
|
|
702
|
+
* `claude-lsp-servers` is the bare server map Claude Code reads under a
|
|
703
|
+
* manifest's `lspServers` key, and `copilot-lsp-json` is Copilot's
|
|
704
|
+
* `{ "lspServers": … }` file.
|
|
506
705
|
*
|
|
507
706
|
* @public
|
|
508
707
|
*/
|
|
509
|
-
export declare const LSP_FORMATS: readonly ["claude-lsp-
|
|
708
|
+
export declare const LSP_FORMATS: readonly ["claude-lsp-servers", "copilot-lsp-json"];
|
|
510
709
|
/** @public */
|
|
511
|
-
export declare const LspFormat: Schema.Literals<readonly ["claude-lsp-
|
|
710
|
+
export declare const LspFormat: Schema.Literals<readonly ["claude-lsp-servers", "copilot-lsp-json"]>;
|
|
711
|
+
declare const InFile_base: Schema.Class<InFile, Schema.TaggedStruct<"file", {
|
|
712
|
+
readonly path: Schema.String;
|
|
713
|
+
}>, {}>;
|
|
714
|
+
/** Write a target's servers to a file of their own, at a plugin-relative path. @public */
|
|
715
|
+
export declare class InFile extends InFile_base {}
|
|
716
|
+
declare const InManifest_base: Schema.Class<InManifest, Schema.TaggedStruct<"manifest", {
|
|
717
|
+
readonly key: Schema.String;
|
|
718
|
+
readonly reserves: Schema.String;
|
|
719
|
+
}>, {}>;
|
|
720
|
+
/**
|
|
721
|
+
* Write a target's servers inline in its manifest, under a key the manifest's
|
|
722
|
+
* allowlist admits. `reserves` is the plugin-relative file the host also loads
|
|
723
|
+
* servers from by default, such as Claude Code's `.mcp.json`; no file may ship
|
|
724
|
+
* there, since the host would load it beside the inline servers.
|
|
725
|
+
*
|
|
726
|
+
* @public
|
|
727
|
+
*/
|
|
728
|
+
export declare class InManifest extends InManifest_base {}
|
|
729
|
+
/**
|
|
730
|
+
* Where a target writes its MCP or LSP servers: a file of their own, or inline
|
|
731
|
+
* in the manifest.
|
|
732
|
+
*
|
|
733
|
+
* @public
|
|
734
|
+
*/
|
|
735
|
+
export declare const ServerPlacement: Schema.Union<readonly [typeof InFile, typeof InManifest]>;
|
|
736
|
+
/** @public */
|
|
737
|
+
export type ServerPlacement = typeof ServerPlacement.Type;
|
|
512
738
|
declare const Keep_base: Schema.Class<Keep, Schema.TaggedStruct<"keep", {}>, {}>;
|
|
513
739
|
/** Write the field unchanged. @public */
|
|
514
740
|
export declare class Keep extends Keep_base {}
|
|
@@ -607,6 +833,18 @@ declare const Target_base: Schema.Class<Target, Schema.Struct<{
|
|
|
607
833
|
* or `unresolved` when the host has no such command.
|
|
608
834
|
*/
|
|
609
835
|
readonly invoke: Schema.Union<readonly [Schema.String, typeof Unresolved]>;
|
|
836
|
+
/**
|
|
837
|
+
* How a skill body names a skill's directory: `own` for the skill the body
|
|
838
|
+
* belongs to, `other` for a sibling, a template with `{skill}`, and `agent`
|
|
839
|
+
* for a sibling named from an agent body, which has no skill base
|
|
840
|
+
* directory. Where the host expands no path in bodies these are
|
|
841
|
+
* placeholders the model fills in, not paths.
|
|
842
|
+
*/
|
|
843
|
+
readonly dirSpelling: Schema.Struct<{
|
|
844
|
+
readonly own: Schema.String;
|
|
845
|
+
readonly other: Schema.String;
|
|
846
|
+
readonly agent: Schema.Union<readonly [Schema.String, typeof Unresolved]>;
|
|
847
|
+
}>;
|
|
610
848
|
}>;
|
|
611
849
|
readonly agents: Schema.Struct<{
|
|
612
850
|
readonly dir: Schema.String;
|
|
@@ -621,17 +859,47 @@ declare const Target_base: Schema.Class<Target, Schema.Struct<{
|
|
|
621
859
|
readonly format: Schema.Literals<readonly ["claude-hooks-json", "copilot-hooks-v1"]>;
|
|
622
860
|
readonly events: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, typeof Absent]>>;
|
|
623
861
|
readonly ownEvents: Schema.$Array<Schema.String>;
|
|
862
|
+
/**
|
|
863
|
+
* The Claude events whose matcher the host ignores. The build drops the
|
|
864
|
+
* host `matcher` key there and the hook library applies the matcher at
|
|
865
|
+
* run time instead.
|
|
866
|
+
*/
|
|
867
|
+
readonly matcherIgnored: Schema.$Array<Schema.String>;
|
|
868
|
+
/**
|
|
869
|
+
* The Claude events where the host honours each kind of hook output: the
|
|
870
|
+
* `context` a hook adds to the model's view and the `system_message` it
|
|
871
|
+
* shows the user. Mirrors `hook_supports` in the hook library, which a test
|
|
872
|
+
* pins; the build notes a script that emits output the host would ignore.
|
|
873
|
+
*/
|
|
874
|
+
readonly output: Schema.Struct<{
|
|
875
|
+
readonly context: Schema.$Array<Schema.String>;
|
|
876
|
+
readonly system_message: Schema.$Array<Schema.String>;
|
|
877
|
+
}>;
|
|
878
|
+
/**
|
|
879
|
+
* The Claude events from which the host passes values a hook exports to
|
|
880
|
+
* the model's shell (Claude Code's `CLAUDE_ENV_FILE`); empty when it has
|
|
881
|
+
* no such channel, and a skill script must source `env.sh` instead.
|
|
882
|
+
*/
|
|
883
|
+
readonly envShell: Schema.$Array<Schema.String>;
|
|
624
884
|
}>;
|
|
625
885
|
readonly mcp: Schema.Struct<{
|
|
626
|
-
readonly
|
|
627
|
-
readonly format: Schema.Literals<readonly ["claude-mcp-
|
|
886
|
+
readonly placement: Schema.Union<readonly [typeof InFile, typeof InManifest]>;
|
|
887
|
+
readonly format: Schema.Literals<readonly ["claude-mcp-servers", "agent-plugins-mcp-1.0"]>;
|
|
628
888
|
readonly schema: Schema.optionalKey<Schema.String>;
|
|
629
889
|
}>;
|
|
630
890
|
readonly lsp: Schema.Struct<{
|
|
631
|
-
readonly
|
|
632
|
-
readonly format: Schema.Literals<readonly ["claude-lsp-
|
|
891
|
+
readonly placement: Schema.Union<readonly [typeof InFile, typeof InManifest]>;
|
|
892
|
+
readonly format: Schema.Literals<readonly ["claude-lsp-servers", "copilot-lsp-json"]>;
|
|
633
893
|
readonly fields: Schema.$Record<Schema.String, Schema.Union<readonly [typeof Keep, typeof Rename, typeof Translate, typeof Degrade, typeof Drop, typeof Unresolved]>>;
|
|
634
894
|
}>;
|
|
895
|
+
/**
|
|
896
|
+
* Where the host reads background monitors and how it spells the plugin root
|
|
897
|
+
* in their commands, or `unresolved` when the host has no monitors.
|
|
898
|
+
*/
|
|
899
|
+
readonly monitors: Schema.Union<readonly [Schema.Struct<{
|
|
900
|
+
readonly path: Schema.String;
|
|
901
|
+
readonly root: Schema.String;
|
|
902
|
+
}>, typeof Unresolved]>;
|
|
635
903
|
readonly references: Schema.Struct<{
|
|
636
904
|
readonly style: Schema.Literals<readonly ["path", "prose"]>;
|
|
637
905
|
}>;
|
|
@@ -675,6 +943,10 @@ declare const Target_base: Schema.Class<Target, Schema.Struct<{
|
|
|
675
943
|
*/
|
|
676
944
|
export declare class Target extends Target_base {}
|
|
677
945
|
/** @public */
|
|
946
|
+
export declare const inFile: (path: string) => InFile;
|
|
947
|
+
/** @public */
|
|
948
|
+
export declare const inManifest: (key: string, reserves: string) => InManifest;
|
|
949
|
+
/** @public */
|
|
678
950
|
export declare const keep: Keep;
|
|
679
951
|
/** @public */
|
|
680
952
|
export declare const drop: Drop;
|
package/index.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { CLAUDE_HOOK_EVENTS, ClaudeHookEvent, CommandHook, HookEntries, HookEntry, HookFallback, Hooks, ScriptHook, makeHooks } from "./hooks.js";
|
|
1
|
+
import { CLAUDE_HOOK_EVENTS, ClaudeHookEvent, CommandHook, HookEntries, HookEntry, HookFallback, Hooks, PluginRelativePath, ScriptHook, makeHooks } from "./hooks.js";
|
|
2
|
+
import { EnvConfig, EnvVar, EnvVarName } from "./env.js";
|
|
2
3
|
import { McpServer, McpServers, RemoteMcpServer, ServerEnv, StdioMcpServer } from "./mcp.js";
|
|
3
4
|
import { LSP_FIELDS, LspServer, LspServers } from "./lsp.js";
|
|
5
|
+
import { KebabName } from "./name.js";
|
|
6
|
+
import { CommandMonitor, MonitorEntry, MonitorName, MonitorWhen, Monitors, ScriptMonitor } from "./monitors.js";
|
|
4
7
|
import { BASE_CONFIG_KEYS, BaseConfigFields, PluginName, ScriptInvoke, ShippedPath, makeTargetSetting } from "./config.js";
|
|
5
8
|
import { AGENT_FIELDS, AgentFrontmatter, ComponentName, ComponentTargets, SKILL_FIELDS, SkillFrontmatter } from "./frontmatter.js";
|
|
6
|
-
import { Absent, DEGRADE_FORMS, Degrade, Drop, EventMapping, FieldMapEntry, HOOKS_FORMATS, HooksFormat, Keep, LSP_FORMATS, LspFormat, MANIFEST_FORMATS, MCP_FORMATS, ManifestFormat, McpFormat, Rename, RootSpelling, Target, ToolMapping, Translate, TranslateTable, Unresolved, ValueMapping, absent, degrade, drop, keep, rename, translate, unresolved } from "./target.js";
|
|
9
|
+
import { Absent, DEGRADE_FORMS, Degrade, Drop, EventMapping, FieldMapEntry, HOOKS_FORMATS, HooksFormat, InFile, InManifest, Keep, LSP_FORMATS, LspFormat, MANIFEST_FORMATS, MCP_FORMATS, ManifestFormat, McpFormat, Rename, RootSpelling, ServerPlacement, Target, ToolMapping, Translate, TranslateTable, Unresolved, ValueMapping, absent, degrade, drop, inFile, inManifest, keep, rename, translate, unresolved } from "./target.js";
|
|
7
10
|
import { CORE_VERSION } from "./version.js";
|
|
8
11
|
|
|
9
|
-
export { AGENT_FIELDS, Absent, AgentFrontmatter, BASE_CONFIG_KEYS, BaseConfigFields, CLAUDE_HOOK_EVENTS, CORE_VERSION, ClaudeHookEvent, CommandHook, ComponentName, ComponentTargets, DEGRADE_FORMS, Degrade, Drop, EventMapping, FieldMapEntry, HOOKS_FORMATS, HookEntries, HookEntry, HookFallback, Hooks, HooksFormat, Keep, LSP_FIELDS, LSP_FORMATS, LspFormat, LspServer, LspServers, MANIFEST_FORMATS, MCP_FORMATS, ManifestFormat, McpFormat, McpServer, McpServers, PluginName, RemoteMcpServer, Rename, RootSpelling, SKILL_FIELDS, ScriptHook, ScriptInvoke, ServerEnv, ShippedPath, SkillFrontmatter, StdioMcpServer, Target, ToolMapping, Translate, TranslateTable, Unresolved, ValueMapping, absent, degrade, drop, keep, makeHooks, makeTargetSetting, rename, translate, unresolved };
|
|
12
|
+
export { AGENT_FIELDS, Absent, AgentFrontmatter, BASE_CONFIG_KEYS, BaseConfigFields, CLAUDE_HOOK_EVENTS, CORE_VERSION, ClaudeHookEvent, CommandHook, CommandMonitor, ComponentName, ComponentTargets, DEGRADE_FORMS, Degrade, Drop, EnvConfig, EnvVar, EnvVarName, EventMapping, FieldMapEntry, HOOKS_FORMATS, HookEntries, HookEntry, HookFallback, Hooks, HooksFormat, InFile, InManifest, KebabName, Keep, LSP_FIELDS, LSP_FORMATS, LspFormat, LspServer, LspServers, MANIFEST_FORMATS, MCP_FORMATS, ManifestFormat, McpFormat, McpServer, McpServers, MonitorEntry, MonitorName, MonitorWhen, Monitors, PluginName, PluginRelativePath, RemoteMcpServer, Rename, RootSpelling, SKILL_FIELDS, ScriptHook, ScriptInvoke, ScriptMonitor, ServerEnv, ServerPlacement, ShippedPath, SkillFrontmatter, StdioMcpServer, Target, ToolMapping, Translate, TranslateTable, Unresolved, ValueMapping, absent, degrade, drop, inFile, inManifest, keep, makeHooks, makeTargetSetting, rename, translate, unresolved };
|
package/monitors.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { PluginRelativePath } from "./hooks.js";
|
|
2
|
+
import { KebabName } from "./name.js";
|
|
3
|
+
import { Schema } from "effect";
|
|
4
|
+
|
|
5
|
+
//#region src/monitors.ts
|
|
6
|
+
/**
|
|
7
|
+
* A monitor's name: kebab-case, the key it is written under.
|
|
8
|
+
*
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
const MonitorName = KebabName;
|
|
12
|
+
/**
|
|
13
|
+
* When a monitor starts: `"always"` (the default) or the first time a named
|
|
14
|
+
* skill is invoked, as `on-skill-invoke:<skill>`.
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* `<skill>` is the bare skill name, so the source is host-neutral: it holds no
|
|
18
|
+
* `:`. Claude Code matches the plugin-qualified name `<plugin>:<skill>`, and
|
|
19
|
+
* the build writes that form.
|
|
20
|
+
*
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
const MonitorWhen = Schema.Union([Schema.Literal("always"), Schema.String.check(Schema.isPattern(/^on-skill-invoke:[^:]+$/, { message: "must be \"always\" or \"on-skill-invoke:<skill>\" with the bare skill name, no plugin prefix: the build qualifies it" }))]);
|
|
24
|
+
const sharedMonitorFields = {
|
|
25
|
+
/** What the monitor watches, shown by the host. */
|
|
26
|
+
description: Schema.String.check(Schema.isMinLength(1)),
|
|
27
|
+
/** When the monitor starts. Defaults to `"always"`. */
|
|
28
|
+
when: Schema.optionalKey(MonitorWhen)
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* A monitor that runs a script the plugin ships. Each line it prints to
|
|
32
|
+
* stdout is delivered to the model.
|
|
33
|
+
*
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
const ScriptMonitor = Schema.Struct({
|
|
37
|
+
script: PluginRelativePath,
|
|
38
|
+
args: Schema.optionalKey(Schema.Array(Schema.String)),
|
|
39
|
+
...sharedMonitorFields
|
|
40
|
+
});
|
|
41
|
+
/**
|
|
42
|
+
* A monitor given as a command string. `${PLUGIN_ROOT}` is its one placeholder.
|
|
43
|
+
*
|
|
44
|
+
* @public
|
|
45
|
+
*/
|
|
46
|
+
const CommandMonitor = Schema.Struct({
|
|
47
|
+
command: Schema.String.check(Schema.isMinLength(1)),
|
|
48
|
+
...sharedMonitorFields
|
|
49
|
+
});
|
|
50
|
+
/**
|
|
51
|
+
* One monitor: exactly one of `script` or `command`. Decode strictly, or a
|
|
52
|
+
* mixed entry decodes as whichever member matches first.
|
|
53
|
+
*
|
|
54
|
+
* @public
|
|
55
|
+
*/
|
|
56
|
+
const MonitorEntry = Schema.Union([ScriptMonitor, CommandMonitor]);
|
|
57
|
+
/**
|
|
58
|
+
* A plugin's monitors, keyed by name.
|
|
59
|
+
*
|
|
60
|
+
* @public
|
|
61
|
+
*/
|
|
62
|
+
const Monitors = Schema.Record(MonitorName, MonitorEntry);
|
|
63
|
+
|
|
64
|
+
//#endregion
|
|
65
|
+
export { CommandMonitor, MonitorEntry, MonitorName, MonitorWhen, Monitors, ScriptMonitor };
|
package/name.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
|
|
3
|
+
//#region src/name.ts
|
|
4
|
+
/**
|
|
5
|
+
* A name every host accepts: kebab-case, lowercase letters and digits
|
|
6
|
+
* separated by single hyphens.
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
const KebabName = Schema.String.check(Schema.isPattern(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, { message: "must be kebab-case: lowercase letters and digits separated by single hyphens" }));
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { KebabName };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pluginfinity/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The pluginfinity domain model: the host-neutral plugin source, the Target capability schema and the pluginfinity config shape. Platform-free.",
|
|
6
6
|
"keywords": [
|
package/target.js
CHANGED
|
@@ -27,22 +27,49 @@ const HOOKS_FORMATS = ["claude-hooks-json", "copilot-hooks-v1"];
|
|
|
27
27
|
/** @public */
|
|
28
28
|
const HooksFormat = Schema.Literals(HOOKS_FORMATS);
|
|
29
29
|
/**
|
|
30
|
-
* MCP config formats. The engine owns one encoder per format
|
|
30
|
+
* MCP config formats. The engine owns one encoder per format:
|
|
31
|
+
* `claude-mcp-servers` is the bare server map Claude Code reads under a
|
|
32
|
+
* manifest's `mcpServers` key, and `agent-plugins-mcp-1.0` is the Agent
|
|
33
|
+
* Plugins `mcp.json` envelope, `$schema` and an `mcpServers` map.
|
|
31
34
|
*
|
|
32
35
|
* @public
|
|
33
36
|
*/
|
|
34
|
-
const MCP_FORMATS = ["claude-mcp-
|
|
37
|
+
const MCP_FORMATS = ["claude-mcp-servers", "agent-plugins-mcp-1.0"];
|
|
35
38
|
/** @public */
|
|
36
39
|
const McpFormat = Schema.Literals(MCP_FORMATS);
|
|
37
40
|
/**
|
|
38
|
-
* LSP config formats. The engine owns one encoder per format
|
|
41
|
+
* LSP config formats. The engine owns one encoder per format:
|
|
42
|
+
* `claude-lsp-servers` is the bare server map Claude Code reads under a
|
|
43
|
+
* manifest's `lspServers` key, and `copilot-lsp-json` is Copilot's
|
|
44
|
+
* `{ "lspServers": … }` file.
|
|
39
45
|
*
|
|
40
46
|
* @public
|
|
41
47
|
*/
|
|
42
|
-
const LSP_FORMATS = ["claude-lsp-
|
|
48
|
+
const LSP_FORMATS = ["claude-lsp-servers", "copilot-lsp-json"];
|
|
43
49
|
/** @public */
|
|
44
50
|
const LspFormat = Schema.Literals(LSP_FORMATS);
|
|
45
51
|
const NonEmpty = Schema.String.check(Schema.isMinLength(1));
|
|
52
|
+
/** Write a target's servers to a file of their own, at a plugin-relative path. @public */
|
|
53
|
+
var InFile = class extends Schema.TaggedClass()("file", { path: NonEmpty }) {};
|
|
54
|
+
/**
|
|
55
|
+
* Write a target's servers inline in its manifest, under a key the manifest's
|
|
56
|
+
* allowlist admits. `reserves` is the plugin-relative file the host also loads
|
|
57
|
+
* servers from by default, such as Claude Code's `.mcp.json`; no file may ship
|
|
58
|
+
* there, since the host would load it beside the inline servers.
|
|
59
|
+
*
|
|
60
|
+
* @public
|
|
61
|
+
*/
|
|
62
|
+
var InManifest = class extends Schema.TaggedClass()("manifest", {
|
|
63
|
+
key: NonEmpty,
|
|
64
|
+
reserves: NonEmpty
|
|
65
|
+
}) {};
|
|
66
|
+
/**
|
|
67
|
+
* Where a target writes its MCP or LSP servers: a file of their own, or inline
|
|
68
|
+
* in the manifest.
|
|
69
|
+
*
|
|
70
|
+
* @public
|
|
71
|
+
*/
|
|
72
|
+
const ServerPlacement = Schema.Union([InFile, InManifest]);
|
|
46
73
|
/** Write the field unchanged. @public */
|
|
47
74
|
var Keep = class extends Schema.TaggedClass()("keep", {}) {};
|
|
48
75
|
/** Write the field under another name. @public */
|
|
@@ -158,7 +185,19 @@ var Target = class extends Schema.Class("Target")({
|
|
|
158
185
|
* How a user invokes a plugin skill: a template with `{plugin}` and `{skill}`,
|
|
159
186
|
* or `unresolved` when the host has no such command.
|
|
160
187
|
*/
|
|
161
|
-
invoke: Schema.Union([Schema.String, Unresolved])
|
|
188
|
+
invoke: Schema.Union([Schema.String, Unresolved]),
|
|
189
|
+
/**
|
|
190
|
+
* How a skill body names a skill's directory: `own` for the skill the body
|
|
191
|
+
* belongs to, `other` for a sibling, a template with `{skill}`, and `agent`
|
|
192
|
+
* for a sibling named from an agent body, which has no skill base
|
|
193
|
+
* directory. Where the host expands no path in bodies these are
|
|
194
|
+
* placeholders the model fills in, not paths.
|
|
195
|
+
*/
|
|
196
|
+
dirSpelling: Schema.Struct({
|
|
197
|
+
own: Schema.String,
|
|
198
|
+
other: Schema.String,
|
|
199
|
+
agent: RootSpelling
|
|
200
|
+
})
|
|
162
201
|
}),
|
|
163
202
|
agents: Schema.Struct({
|
|
164
203
|
dir: Schema.String,
|
|
@@ -172,18 +211,48 @@ var Target = class extends Schema.Class("Target")({
|
|
|
172
211
|
path: Schema.String,
|
|
173
212
|
format: HooksFormat,
|
|
174
213
|
events: Schema.Record(Schema.String, EventMapping),
|
|
175
|
-
ownEvents: Schema.Array(Schema.String)
|
|
214
|
+
ownEvents: Schema.Array(Schema.String),
|
|
215
|
+
/**
|
|
216
|
+
* The Claude events whose matcher the host ignores. The build drops the
|
|
217
|
+
* host `matcher` key there and the hook library applies the matcher at
|
|
218
|
+
* run time instead.
|
|
219
|
+
*/
|
|
220
|
+
matcherIgnored: Schema.Array(Schema.String),
|
|
221
|
+
/**
|
|
222
|
+
* The Claude events where the host honours each kind of hook output: the
|
|
223
|
+
* `context` a hook adds to the model's view and the `system_message` it
|
|
224
|
+
* shows the user. Mirrors `hook_supports` in the hook library, which a test
|
|
225
|
+
* pins; the build notes a script that emits output the host would ignore.
|
|
226
|
+
*/
|
|
227
|
+
output: Schema.Struct({
|
|
228
|
+
context: Schema.Array(Schema.String),
|
|
229
|
+
system_message: Schema.Array(Schema.String)
|
|
230
|
+
}),
|
|
231
|
+
/**
|
|
232
|
+
* The Claude events from which the host passes values a hook exports to
|
|
233
|
+
* the model's shell (Claude Code's `CLAUDE_ENV_FILE`); empty when it has
|
|
234
|
+
* no such channel, and a skill script must source `env.sh` instead.
|
|
235
|
+
*/
|
|
236
|
+
envShell: Schema.Array(Schema.String)
|
|
176
237
|
}),
|
|
177
238
|
mcp: Schema.Struct({
|
|
178
|
-
|
|
239
|
+
placement: ServerPlacement,
|
|
179
240
|
format: McpFormat,
|
|
180
241
|
schema: Schema.optionalKey(Schema.String)
|
|
181
242
|
}),
|
|
182
243
|
lsp: Schema.Struct({
|
|
183
|
-
|
|
244
|
+
placement: ServerPlacement,
|
|
184
245
|
format: LspFormat,
|
|
185
246
|
fields: FieldMap
|
|
186
247
|
}),
|
|
248
|
+
/**
|
|
249
|
+
* Where the host reads background monitors and how it spells the plugin root
|
|
250
|
+
* in their commands, or `unresolved` when the host has no monitors.
|
|
251
|
+
*/
|
|
252
|
+
monitors: Schema.Union([Schema.Struct({
|
|
253
|
+
path: Schema.String,
|
|
254
|
+
root: Schema.String
|
|
255
|
+
}), Unresolved]),
|
|
187
256
|
references: Schema.Struct({ style: Schema.Literals(["path", "prose"]) }),
|
|
188
257
|
tools: Schema.Struct({
|
|
189
258
|
names: Schema.Record(Schema.String, ToolMapping),
|
|
@@ -211,6 +280,13 @@ var Target = class extends Schema.Class("Target")({
|
|
|
211
280
|
efforts: Schema.Record(Schema.String, ValueMapping)
|
|
212
281
|
}) {};
|
|
213
282
|
/** @public */
|
|
283
|
+
const inFile = (path) => InFile.make({ path });
|
|
284
|
+
/** @public */
|
|
285
|
+
const inManifest = (key, reserves) => InManifest.make({
|
|
286
|
+
key,
|
|
287
|
+
reserves
|
|
288
|
+
});
|
|
289
|
+
/** @public */
|
|
214
290
|
const keep = Keep.make({});
|
|
215
291
|
/** @public */
|
|
216
292
|
const drop = Drop.make({});
|
|
@@ -229,4 +305,4 @@ const degrade = (form) => Degrade.make({ form });
|
|
|
229
305
|
const unresolved = (note) => Unresolved.make({ note });
|
|
230
306
|
|
|
231
307
|
//#endregion
|
|
232
|
-
export { Absent, DEGRADE_FORMS, Degrade, DegradeForm, Drop, EventMapping, FieldMapEntry, HOOKS_FORMATS, HooksFormat, Keep, LSP_FORMATS, LspFormat, MANIFEST_FORMATS, MCP_FORMATS, ManifestFormat, McpFormat, Rename, RootSpelling, Target, ToolMapping, Translate, TranslateTable, Unresolved, ValueMapping, absent, degrade, drop, keep, rename, translate, unresolved };
|
|
308
|
+
export { Absent, DEGRADE_FORMS, Degrade, DegradeForm, Drop, EventMapping, FieldMapEntry, HOOKS_FORMATS, HooksFormat, InFile, InManifest, Keep, LSP_FORMATS, LspFormat, MANIFEST_FORMATS, MCP_FORMATS, ManifestFormat, McpFormat, Rename, RootSpelling, ServerPlacement, Target, ToolMapping, Translate, TranslateTable, Unresolved, ValueMapping, absent, degrade, drop, inFile, inManifest, keep, rename, translate, unresolved };
|