@pluginfinity/engine 0.2.1 → 0.3.1
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/env-lib.generated.js +12 -0
- package/env.js +128 -0
- package/errors.js +25 -6
- package/hook-lib.generated.js +1 -1
- package/hook-lib.js +15 -8
- package/hook-output.js +68 -0
- package/hooks.js +105 -12
- package/index.d.ts +369 -13
- package/index.js +6 -3
- package/lib-files.js +39 -0
- package/log-lib.generated.js +9 -0
- package/logs.js +147 -0
- package/monitor-lib.generated.js +9 -0
- package/monitors.js +88 -0
- package/notes.js +8 -1
- package/operations.js +129 -23
- package/package.json +9 -9
- package/server-lib.generated.js +1 -1
- package/server-lib.js +3 -2
- package/skills.js +6 -2
- package/tokens.js +72 -6
- package/tool-map.js +35 -0
- package/version.js +1 -1
package/server-lib.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { LIB_DIR } from "./lib-files.js";
|
|
1
2
|
import { SERVER_LIB_FILES } from "./server-lib.generated.js";
|
|
2
3
|
|
|
3
4
|
//#region src/server-lib.ts
|
|
@@ -6,9 +7,9 @@ import { SERVER_LIB_FILES } from "./server-lib.generated.js";
|
|
|
6
7
|
*
|
|
7
8
|
* @public
|
|
8
9
|
*/
|
|
9
|
-
const SERVER_LIB_DIR =
|
|
10
|
+
const SERVER_LIB_DIR = LIB_DIR;
|
|
10
11
|
/**
|
|
11
|
-
* The server library, as one target's build writes it.
|
|
12
|
+
* The server library, as one target's build writes it. `log.sh` and `host.sh` come from `libFiles`.
|
|
12
13
|
*
|
|
13
14
|
* @public
|
|
14
15
|
*/
|
package/skills.js
CHANGED
|
@@ -100,7 +100,11 @@ const renderSkill = (target, id, skill, known, tokens) => Effect.gen(function* (
|
|
|
100
100
|
if (typeof description === "string" && description.length > 1024) problems.push(issue("description", `is ${description.length} characters on ${id}, over the ${SKILL_DESCRIPTION_MAX} limit; set a shorter targets.${id}.description`));
|
|
101
101
|
const body = mapHostBlocks(skill.body, id, known);
|
|
102
102
|
if ("problem" in body) return yield* Effect.fail(invalid(skill.path, [issue(`line ${body.problem.line + skill.bodyOffset}`, body.problem.message)]));
|
|
103
|
-
const
|
|
103
|
+
const own = {
|
|
104
|
+
...tokens,
|
|
105
|
+
skill: skill.name
|
|
106
|
+
};
|
|
107
|
+
const rendered = renderTokens(body.text, own);
|
|
104
108
|
if ("problems" in rendered) problems.push(...lineIssues(rendered.problems, body.lines, skill.bodyOffset));
|
|
105
109
|
const failures = problems.length > 0 ? [invalid(skill.path, problems, id)] : [];
|
|
106
110
|
const yaml = yield* frontmatterText({
|
|
@@ -131,7 +135,7 @@ const renderSkill = (target, id, skill, known, tokens) => Effect.gen(function* (
|
|
|
131
135
|
failures.push(invalid(absolute, [issue(`line ${processed.problem.line}`, processed.problem.message)]));
|
|
132
136
|
continue;
|
|
133
137
|
}
|
|
134
|
-
const tokened = renderTokens(processed.text,
|
|
138
|
+
const tokened = renderTokens(processed.text, own);
|
|
135
139
|
if ("problems" in tokened) {
|
|
136
140
|
failures.push(invalid(absolute, lineIssues(tokened.problems, processed.lines, 0), id));
|
|
137
141
|
continue;
|
package/tokens.js
CHANGED
|
@@ -6,10 +6,11 @@ const KINDS = /* @__PURE__ */ new Set([
|
|
|
6
6
|
"tool",
|
|
7
7
|
"agent",
|
|
8
8
|
"skill",
|
|
9
|
+
"skill_dir",
|
|
9
10
|
"plugin_root"
|
|
10
11
|
]);
|
|
11
|
-
/** The first word after `{{`: up to whitespace or a
|
|
12
|
-
const KIND = /^\s*([^\s{}]+)/;
|
|
12
|
+
/** The first word after `{{`: up to whitespace, a brace, a pipe or a backtick. */
|
|
13
|
+
const KIND = /^\s*([^\s{}`|]+)/;
|
|
13
14
|
const LINK = /(!?)\[([^[\]]*)\]\(\s*<?pluginfinity:\/\/([^\s<>()]*)>?\s*\)/g;
|
|
14
15
|
/** Every `pluginfinity://` occurrence, in any case. */
|
|
15
16
|
const SCHEMES = /pluginfinity:\/\//gi;
|
|
@@ -49,15 +50,43 @@ const tool = (name, raw, ctx) => {
|
|
|
49
50
|
/** Spell the inside of one `{{…}}` that opens with a known kind; `raw` is the whole token as written. */
|
|
50
51
|
const token = (inner, raw, ctx) => {
|
|
51
52
|
if (/[{}]/.test(inner)) return { problem: `malformed token ${raw}; write \\{{ for a literal {{` };
|
|
52
|
-
const
|
|
53
|
+
const bar = inner.indexOf("|");
|
|
54
|
+
const head = bar === -1 ? inner : inner.slice(0, bar);
|
|
55
|
+
const fallback = bar === -1 ? void 0 : inner.slice(bar + 1).trim();
|
|
56
|
+
const [kind = "", ...args] = head.trim().split(/\s+/).filter((part) => part.length > 0);
|
|
57
|
+
let code = false;
|
|
58
|
+
if (head.includes("`")) {
|
|
59
|
+
if (kind !== "tool") return { problem: `${raw}: only a tool token takes a backtick-wrapped name` };
|
|
60
|
+
const wrapped = /^\s*tool\s+`([^`\s]+)`\s*$/.exec(head);
|
|
61
|
+
if (wrapped === null) return { problem: `${raw}: wrap the tool name in exactly one pair of backticks, as {{tool \`Name\`}}` };
|
|
62
|
+
code = true;
|
|
63
|
+
args[0] = wrapped[1];
|
|
64
|
+
args.length = 1;
|
|
65
|
+
}
|
|
66
|
+
if (fallback !== void 0 && kind !== "tool") return { problem: `${raw}: only a tool token takes a | fallback` };
|
|
53
67
|
if (kind === "plugin_root") {
|
|
54
68
|
if (args.length > 0) return { problem: `${raw}: plugin_root takes no argument` };
|
|
55
69
|
return spelling(ctx.target.pluginRoot.body, raw);
|
|
56
70
|
}
|
|
57
71
|
const [name] = args;
|
|
72
|
+
if (kind === "skill_dir") {
|
|
73
|
+
if (args.length > 1) return { problem: `${raw} takes one skill_dir name` };
|
|
74
|
+
if (name === void 0 && ctx.skill === void 0) return { problem: `${raw}: an agent has no skill directory; name a skill, {{skill_dir <skill>}}` };
|
|
75
|
+
const skill = name ?? ctx.skill;
|
|
76
|
+
if (!ctx.skills.has(skill)) return { problem: `${raw}: this plugin has no skill "${skill}"` };
|
|
77
|
+
const spellings = ctx.target.skills.dirSpelling;
|
|
78
|
+
const chosen = ctx.skill === void 0 ? spellings.agent : skill === ctx.skill ? spellings.own : spellings.other;
|
|
79
|
+
const spelled = spelling(chosen, raw);
|
|
80
|
+
return "problem" in spelled ? spelled : { value: fill(spelled.value, { skill }) };
|
|
81
|
+
}
|
|
58
82
|
if (name === void 0) return { problem: `${raw} needs ${article(kind)} name` };
|
|
59
83
|
if (args.length > 1) return { problem: `${raw} takes one ${kind} name` };
|
|
60
|
-
if (kind === "tool")
|
|
84
|
+
if (kind === "tool") {
|
|
85
|
+
if (fallback === "") return { problem: `${raw}: the fallback after | is empty` };
|
|
86
|
+
const spelled = tool(name, raw, ctx);
|
|
87
|
+
if (fallback !== void 0 && "problem" in spelled) return { value: fallback };
|
|
88
|
+
return code && "value" in spelled ? { value: `\`${spelled.value}\`` } : spelled;
|
|
89
|
+
}
|
|
61
90
|
if (kind === "agent") {
|
|
62
91
|
if (!ctx.agents.has(name)) return { problem: `${raw}: this plugin has no agent "${name}"` };
|
|
63
92
|
return { value: fill(ctx.target.agents.id, {
|
|
@@ -189,8 +218,45 @@ const links = (line, ctx, problems) => {
|
|
|
189
218
|
* or report every one it cannot render.
|
|
190
219
|
*
|
|
191
220
|
* @remarks
|
|
192
|
-
* A token is
|
|
193
|
-
*
|
|
221
|
+
* A token is one of the following, with whitespace allowed inside the braces,
|
|
222
|
+
* on one line:
|
|
223
|
+
*
|
|
224
|
+
* ```text
|
|
225
|
+
* {{tool <name>}}
|
|
226
|
+
* {{tool <name> | <fallback>}}
|
|
227
|
+
* {{agent <name>}}
|
|
228
|
+
* {{skill <name>}}
|
|
229
|
+
* {{skill_dir}}
|
|
230
|
+
* {{skill_dir <name>}}
|
|
231
|
+
* {{plugin_root}}
|
|
232
|
+
* ```
|
|
233
|
+
*
|
|
234
|
+
* `{{skill_dir}}` is the directory of the skill whose body it is written in,
|
|
235
|
+
* and `{{skill_dir <name>}}` that of the named skill (naming the own skill is
|
|
236
|
+
* the own form). Claude spells them `${CLAUDE_SKILL_DIR}` and
|
|
237
|
+
* `${CLAUDE_PLUGIN_ROOT}/skills/<name>`, which it expands in skill bodies;
|
|
238
|
+
* Copilot expands nothing, so on Copilot the token is a placeholder the model
|
|
239
|
+
* resolves from the "Base directory for this skill" line the host puts above
|
|
240
|
+
* the body (`<skill base directory>`, and `<skill base directory>/../<name>`
|
|
241
|
+
* for a sibling), not a literal path. An agent has no skill directory, so the
|
|
242
|
+
* bare form there is a problem, as is a named skill on a target with no
|
|
243
|
+
* spelling for it from an agent (Copilot), an unknown skill or one the target
|
|
244
|
+
* does not build. It takes neither a `|` fallback nor backticks.
|
|
245
|
+
*
|
|
246
|
+
* A tool token may wrap its name in exactly one pair of backticks:
|
|
247
|
+
*
|
|
248
|
+
* ```text
|
|
249
|
+
* {{tool `Name`}}
|
|
250
|
+
* {{tool `Name` | <fallback>}}
|
|
251
|
+
* ```
|
|
252
|
+
*
|
|
253
|
+
* It then renders as a code span of the spelling where the tool spells, and as
|
|
254
|
+
* the fallback in plain text where it does not;
|
|
255
|
+
* unbalanced or doubled backticks, and backticks on any other kind, are
|
|
256
|
+
* problems. Only a tool token takes
|
|
257
|
+
* a `|` fallback: literal prose, trimmed, that replaces the token on a target
|
|
258
|
+
* where the tool has no spelling (and is discarded where it has one). It may
|
|
259
|
+
* not be empty or contain `{` or `}`.
|
|
194
260
|
* Tokens are replaced everywhere, fenced and inline code included; `\{{`
|
|
195
261
|
* before a token renders it literally, and before any other `{{` the
|
|
196
262
|
* backslash stays. A `{{` whose first word is not a kind is text, so
|
package/tool-map.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region src/tool-map.ts
|
|
2
|
+
const singleQuote = (value) => `'${value.replaceAll("'", `'\\''`)}'`;
|
|
3
|
+
/**
|
|
4
|
+
* The generated `tools.sh` the hook library sources to spell a Claude tool
|
|
5
|
+
* name the way the host spells it at run time.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* `plugin` is the plugin's Claude name: Claude Code namespaces a plugin's MCP
|
|
9
|
+
* tools with it, so a hook sees an own tool as
|
|
10
|
+
* `mcp__plugin_<plugin>_<server>__<tool>` on every host, and the run-time
|
|
11
|
+
* template's `{plugin}` is filled from it. Names the target leaves unresolved
|
|
12
|
+
* are omitted, which `hook_tool_name` reports as no spelling.
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
const renderToolMap = (target, plugin, servers, has) => {
|
|
17
|
+
const runtime = target.tools.runtime;
|
|
18
|
+
const pairs = Object.entries(runtime.names).flatMap(([name, spelled]) => typeof spelled === "string" ? [`${name}=${spelled}`] : []);
|
|
19
|
+
return [
|
|
20
|
+
"# Generated by pluginfinity. Do not edit.",
|
|
21
|
+
`_PF_TOOLS=${singleQuote(pairs.join("\n"))}`,
|
|
22
|
+
`_PF_TOOLS_PLUGIN=${singleQuote(plugin)}`,
|
|
23
|
+
`_PF_TOOLS_MCP=${singleQuote(runtime.mcp)}`,
|
|
24
|
+
`_PF_TOOLS_SERVERS=${singleQuote(servers.join(" "))}`,
|
|
25
|
+
`_PF_TOOLS_UNLISTED=${runtime.unlisted}`,
|
|
26
|
+
`_PF_HAS_SKILLS=${singleQuote(has.skills.join(" "))}`,
|
|
27
|
+
`_PF_HAS_AGENTS=${singleQuote(has.agents.join(" "))}`,
|
|
28
|
+
`_PF_HAS_MONITORS=${singleQuote(("path" in target.monitors ? has.monitors : []).join(" "))}`,
|
|
29
|
+
`_PF_HAS_SERVERS=${singleQuote(servers.join(" "))}`,
|
|
30
|
+
""
|
|
31
|
+
].join("\n");
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
export { renderToolMap };
|