@stigmer/plugin-package 0.1.0-dev.20261017020314.g644422724c27
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 +194 -0
- package/README.md +72 -0
- package/client/archive.d.ts +27 -0
- package/client/archive.d.ts.map +1 -0
- package/client/archive.js +38 -0
- package/client/archive.js.map +1 -0
- package/client/builtin.d.ts +37 -0
- package/client/builtin.d.ts.map +1 -0
- package/client/builtin.js +49 -0
- package/client/builtin.js.map +1 -0
- package/client/ignore/defaults.d.ts +2 -0
- package/client/ignore/defaults.d.ts.map +1 -0
- package/client/ignore/defaults.js +140 -0
- package/client/ignore/defaults.js.map +1 -0
- package/client/ignore/match.d.ts +3 -0
- package/client/ignore/match.d.ts.map +1 -0
- package/client/ignore/match.js +166 -0
- package/client/ignore/match.js.map +1 -0
- package/client/ignore/matcher.d.ts +50 -0
- package/client/ignore/matcher.d.ts.map +1 -0
- package/client/ignore/matcher.js +116 -0
- package/client/ignore/matcher.js.map +1 -0
- package/client/ignore/pattern.d.ts +13 -0
- package/client/ignore/pattern.d.ts.map +1 -0
- package/client/ignore/pattern.js +119 -0
- package/client/ignore/pattern.js.map +1 -0
- package/client/prepare-eval.d.ts +62 -0
- package/client/prepare-eval.d.ts.map +1 -0
- package/client/prepare-eval.js +60 -0
- package/client/prepare-eval.js.map +1 -0
- package/client/prepare.d.ts +99 -0
- package/client/prepare.d.ts.map +1 -0
- package/client/prepare.js +89 -0
- package/client/prepare.js.map +1 -0
- package/client/presentation.d.ts +19 -0
- package/client/presentation.d.ts.map +1 -0
- package/client/presentation.js +44 -0
- package/client/presentation.js.map +1 -0
- package/client/refs.d.ts +76 -0
- package/client/refs.d.ts.map +1 -0
- package/client/refs.js +123 -0
- package/client/refs.js.map +1 -0
- package/client/release.d.ts +20 -0
- package/client/release.d.ts.map +1 -0
- package/client/release.js +28 -0
- package/client/release.js.map +1 -0
- package/client/reroot.d.ts +21 -0
- package/client/reroot.d.ts.map +1 -0
- package/client/reroot.js +37 -0
- package/client/reroot.js.map +1 -0
- package/client/select.d.ts +74 -0
- package/client/select.d.ts.map +1 -0
- package/client/select.js +121 -0
- package/client/select.js.map +1 -0
- package/client/vocabulary.d.ts +13 -0
- package/client/vocabulary.d.ts.map +1 -0
- package/client/vocabulary.js +17 -0
- package/client/vocabulary.js.map +1 -0
- package/client.d.ts +51 -0
- package/client.d.ts.map +1 -0
- package/client.js +51 -0
- package/client.js.map +1 -0
- package/detect.d.ts +83 -0
- package/detect.d.ts.map +1 -0
- package/detect.js +210 -0
- package/detect.js.map +1 -0
- package/dialects/claude.d.ts +34 -0
- package/dialects/claude.d.ts.map +1 -0
- package/dialects/claude.js +84 -0
- package/dialects/claude.js.map +1 -0
- package/dialects/codex.d.ts +20 -0
- package/dialects/codex.d.ts.map +1 -0
- package/dialects/codex.js +21 -0
- package/dialects/codex.js.map +1 -0
- package/dialects/cursor.d.ts +25 -0
- package/dialects/cursor.d.ts.map +1 -0
- package/dialects/cursor.js +66 -0
- package/dialects/cursor.js.map +1 -0
- package/dialects/manifest.d.ts +164 -0
- package/dialects/manifest.d.ts.map +1 -0
- package/dialects/manifest.js +256 -0
- package/dialects/manifest.js.map +1 -0
- package/dialects/open.d.ts +19 -0
- package/dialects/open.d.ts.map +1 -0
- package/dialects/open.js +49 -0
- package/dialects/open.js.map +1 -0
- package/documents.d.ts +58 -0
- package/documents.d.ts.map +1 -0
- package/documents.js +121 -0
- package/documents.js.map +1 -0
- package/evals/eval-dir.d.ts +59 -0
- package/evals/eval-dir.d.ts.map +1 -0
- package/evals/eval-dir.js +84 -0
- package/evals/eval-dir.js.map +1 -0
- package/evals/fields.d.ts +78 -0
- package/evals/fields.d.ts.map +1 -0
- package/evals/fields.js +156 -0
- package/evals/fields.js.map +1 -0
- package/evals/glob.d.ts +40 -0
- package/evals/glob.d.ts.map +1 -0
- package/evals/glob.js +146 -0
- package/evals/glob.js.map +1 -0
- package/evals/graders.d.ts +52 -0
- package/evals/graders.d.ts.map +1 -0
- package/evals/graders.js +279 -0
- package/evals/graders.js.map +1 -0
- package/evals/markdown.d.ts +24 -0
- package/evals/markdown.d.ts.map +1 -0
- package/evals/markdown.js +48 -0
- package/evals/markdown.js.map +1 -0
- package/evals/mocks.d.ts +50 -0
- package/evals/mocks.d.ts.map +1 -0
- package/evals/mocks.js +182 -0
- package/evals/mocks.js.map +1 -0
- package/evals/read-eval-suite.d.ts +110 -0
- package/evals/read-eval-suite.d.ts.map +1 -0
- package/evals/read-eval-suite.js +603 -0
- package/evals/read-eval-suite.js.map +1 -0
- package/evals/summary.d.ts +61 -0
- package/evals/summary.d.ts.map +1 -0
- package/evals/summary.js +69 -0
- package/evals/summary.js.map +1 -0
- package/evals/types.d.ts +203 -0
- package/evals/types.d.ts.map +1 -0
- package/evals/types.js +21 -0
- package/evals/types.js.map +1 -0
- package/files.d.ts +135 -0
- package/files.d.ts.map +1 -0
- package/files.js +209 -0
- package/files.js.map +1 -0
- package/frontmatter.d.ts +51 -0
- package/frontmatter.d.ts.map +1 -0
- package/frontmatter.js +61 -0
- package/frontmatter.js.map +1 -0
- package/index.d.ts +37 -0
- package/index.d.ts.map +1 -0
- package/index.js +33 -0
- package/index.js.map +1 -0
- package/marketplace/messages.d.ts +20 -0
- package/marketplace/messages.d.ts.map +1 -0
- package/marketplace/messages.js +49 -0
- package/marketplace/messages.js.map +1 -0
- package/marketplace/outcome.d.ts +70 -0
- package/marketplace/outcome.d.ts.map +1 -0
- package/marketplace/outcome.js +29 -0
- package/marketplace/outcome.js.map +1 -0
- package/marketplace/read-marketplace.d.ts +52 -0
- package/marketplace/read-marketplace.d.ts.map +1 -0
- package/marketplace/read-marketplace.js +351 -0
- package/marketplace/read-marketplace.js.map +1 -0
- package/messages.d.ts +55 -0
- package/messages.d.ts.map +1 -0
- package/messages.js +167 -0
- package/messages.js.map +1 -0
- package/normalise/hooks.d.ts +91 -0
- package/normalise/hooks.d.ts.map +1 -0
- package/normalise/hooks.js +437 -0
- package/normalise/hooks.js.map +1 -0
- package/normalise/ignored.d.ts +34 -0
- package/normalise/ignored.d.ts.map +1 -0
- package/normalise/ignored.js +78 -0
- package/normalise/ignored.js.map +1 -0
- package/normalise/mcp-servers.d.ts +50 -0
- package/normalise/mcp-servers.d.ts.map +1 -0
- package/normalise/mcp-servers.js +398 -0
- package/normalise/mcp-servers.js.map +1 -0
- package/normalise/settings.d.ts +32 -0
- package/normalise/settings.d.ts.map +1 -0
- package/normalise/settings.js +72 -0
- package/normalise/settings.js.map +1 -0
- package/normalise/skills.d.ts +39 -0
- package/normalise/skills.d.ts.map +1 -0
- package/normalise/skills.js +135 -0
- package/normalise/skills.js.map +1 -0
- package/normalise/stigmer-folder.d.ts +17 -0
- package/normalise/stigmer-folder.d.ts.map +1 -0
- package/normalise/stigmer-folder.js +19 -0
- package/normalise/stigmer-folder.js.map +1 -0
- package/normalise/sub-agents.d.ts +54 -0
- package/normalise/sub-agents.d.ts.map +1 -0
- package/normalise/sub-agents.js +219 -0
- package/normalise/sub-agents.js.map +1 -0
- package/normalise/variables.d.ts +31 -0
- package/normalise/variables.d.ts.map +1 -0
- package/normalise/variables.js +170 -0
- package/normalise/variables.js.map +1 -0
- package/outcome.d.ts +59 -0
- package/outcome.d.ts.map +1 -0
- package/outcome.js +32 -0
- package/outcome.js.map +1 -0
- package/package.json +47 -0
- package/placeholders.d.ts +65 -0
- package/placeholders.d.ts.map +1 -0
- package/placeholders.js +99 -0
- package/placeholders.js.map +1 -0
- package/presentation.d.ts +53 -0
- package/presentation.d.ts.map +1 -0
- package/presentation.js +156 -0
- package/presentation.js.map +1 -0
- package/read-plugin-package.d.ts +20 -0
- package/read-plugin-package.d.ts.map +1 -0
- package/read-plugin-package.js +73 -0
- package/read-plugin-package.js.map +1 -0
- package/src/client/archive.ts +44 -0
- package/src/client/builtin.ts +60 -0
- package/src/client/ignore/defaults.ts +155 -0
- package/src/client/ignore/match.ts +158 -0
- package/src/client/ignore/matcher.ts +156 -0
- package/src/client/ignore/pattern.ts +132 -0
- package/src/client/prepare-eval.ts +92 -0
- package/src/client/prepare.ts +160 -0
- package/src/client/presentation.ts +47 -0
- package/src/client/refs.ts +170 -0
- package/src/client/release.ts +29 -0
- package/src/client/reroot.ts +35 -0
- package/src/client/select.ts +161 -0
- package/src/client/vocabulary.ts +19 -0
- package/src/client.ts +102 -0
- package/src/detect.ts +245 -0
- package/src/dialects/claude.ts +102 -0
- package/src/dialects/codex.ts +26 -0
- package/src/dialects/cursor.ts +77 -0
- package/src/dialects/manifest.ts +316 -0
- package/src/dialects/open.ts +50 -0
- package/src/documents.ts +158 -0
- package/src/evals/eval-dir.ts +101 -0
- package/src/evals/fields.ts +184 -0
- package/src/evals/glob.ts +141 -0
- package/src/evals/graders.ts +293 -0
- package/src/evals/markdown.ts +56 -0
- package/src/evals/mocks.ts +202 -0
- package/src/evals/read-eval-suite.ts +713 -0
- package/src/evals/summary.ts +100 -0
- package/src/evals/types.ts +217 -0
- package/src/files.ts +235 -0
- package/src/frontmatter.ts +70 -0
- package/src/index.ts +129 -0
- package/src/marketplace/messages.ts +61 -0
- package/src/marketplace/outcome.ts +91 -0
- package/src/marketplace/read-marketplace.ts +388 -0
- package/src/messages.ts +248 -0
- package/src/normalise/hooks.ts +469 -0
- package/src/normalise/ignored.ts +79 -0
- package/src/normalise/mcp-servers.ts +423 -0
- package/src/normalise/settings.ts +81 -0
- package/src/normalise/skills.ts +145 -0
- package/src/normalise/stigmer-folder.ts +23 -0
- package/src/normalise/sub-agents.ts +231 -0
- package/src/normalise/variables.ts +181 -0
- package/src/outcome.ts +158 -0
- package/src/placeholders.ts +110 -0
- package/src/presentation.ts +170 -0
- package/src/read-plugin-package.ts +80 -0
- package/src/testing.ts +347 -0
- package/src/tool-names.ts +30 -0
- package/src/trim.ts +10 -0
- package/src/types.ts +214 -0
- package/testing.d.ts +127 -0
- package/testing.d.ts.map +1 -0
- package/testing.js +266 -0
- package/testing.js.map +1 -0
- package/tool-names.d.ts +21 -0
- package/tool-names.d.ts.map +1 -0
- package/tool-names.js +28 -0
- package/tool-names.js.map +1 -0
- package/trim.d.ts +7 -0
- package/trim.d.ts.map +1 -0
- package/trim.js +12 -0
- package/trim.js.map +1 -0
- package/types.d.ts +179 -0
- package/types.d.ts.map +1 -0
- package/types.js +19 -0
- package/types.js.map +1 -0
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sub-agent files (`agents/*.md`) into the shape `PluginAgent` takes.
|
|
3
|
+
*
|
|
4
|
+
* Cursor and Claude Code define this component; the open format does not,
|
|
5
|
+
* so `agents/` is read only when a vendor manifest is present (`detect.ts`
|
|
6
|
+
* decides) and recorded as ignored otherwise. Files come from the default
|
|
7
|
+
* `agents/` directory or, when any manifest declares `agents`, from the
|
|
8
|
+
* declared paths only (Claude's "replaces the default"), each of which may
|
|
9
|
+
* be one `.md` file or a directory of them.
|
|
10
|
+
*
|
|
11
|
+
* The body of the file is the sub-agent's prompt. A body under
|
|
12
|
+
* `SUB_AGENT_INSTRUCTIONS_MIN` characters is refused, because that is the
|
|
13
|
+
* floor every agent's instructions meet (the proto's
|
|
14
|
+
* `AgentSpec.instructions` `min_len`), and a plugin agent's instructions
|
|
15
|
+
* are an agent's prompt like any other. Frontmatter is optional (a bare
|
|
16
|
+
* prompt is named after its file, Claude's rule) but must parse when
|
|
17
|
+
* present: Claude degrades an unparseable header to a file-named agent with
|
|
18
|
+
* every field ignored, and a faithful install is better refused than
|
|
19
|
+
* quietly stripped.
|
|
20
|
+
*
|
|
21
|
+
* `model` is classified into an alias, never a model id (see `ModelHint`).
|
|
22
|
+
* Claude `skills:` names are matched against the plugin's own skills.
|
|
23
|
+
* Claude's two tool lists, `tools` ("only these") and `disallowedTools`
|
|
24
|
+
* ("never these"), are read as written: a comma-separated string split on
|
|
25
|
+
* commas outside parentheses (so `Agent(a, b)` stays one entry), or a YAML
|
|
26
|
+
* list of strings; entries trimmed, empty ones dropped. A list of another
|
|
27
|
+
* type is refused, because dropping it would widen an agent its author
|
|
28
|
+
* narrowed. Rewriting names to Stigmer's and checking them is the
|
|
29
|
+
* installer's, which knows the plugin's materialised servers. Every other
|
|
30
|
+
* frontmatter field (`effort`, `maxTurns`, `readonly`, `is_background`,
|
|
31
|
+
* `memory`, `isolation`, and the `hooks`, `mcpServers`, `permissionMode`
|
|
32
|
+
* and `initialPrompt` Claude Code itself ignores on a plugin's agents) is a
|
|
33
|
+
* warning, once per field per agent: they configure the IDE's loop, not the
|
|
34
|
+
* sub-agent's prompt.
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
import type { ManifestSet } from "../detect.js";
|
|
38
|
+
import { readText } from "../documents.js";
|
|
39
|
+
import { basename, comparePaths, joinPath, type PluginFileIndex } from "../files.js";
|
|
40
|
+
import { extractFrontmatter, parseFrontmatter } from "../frontmatter.js";
|
|
41
|
+
import type { Findings } from "../messages.js";
|
|
42
|
+
import type { ModelAlias, ModelHint, PluginSkill, PluginSubAgent } from "../types.js";
|
|
43
|
+
|
|
44
|
+
export const DEFAULT_AGENTS_DIR = "agents";
|
|
45
|
+
|
|
46
|
+
/** A plugin agent's instructions floor: the proto's `AgentSpec.instructions` `min_len`. */
|
|
47
|
+
export const SUB_AGENT_INSTRUCTIONS_MIN = 10;
|
|
48
|
+
|
|
49
|
+
const READ_FIELDS: ReadonlySet<string> = new Set(["name", "description", "model", "skills", "tools", "disallowedTools"]);
|
|
50
|
+
|
|
51
|
+
export function normaliseSubAgents(
|
|
52
|
+
index: PluginFileIndex,
|
|
53
|
+
set: ManifestSet,
|
|
54
|
+
skills: readonly PluginSkill[],
|
|
55
|
+
findings: Findings,
|
|
56
|
+
): readonly PluginSubAgent[] {
|
|
57
|
+
if (!set.readsAgents) return [];
|
|
58
|
+
const skillNames = new Set(skills.map((skill) => skill.name));
|
|
59
|
+
const agents: PluginSubAgent[] = [];
|
|
60
|
+
const seen = new Set<string>();
|
|
61
|
+
for (const path of discoverAgentFiles(index, set, findings)) {
|
|
62
|
+
const agent = readSubAgent(index, path, skillNames, findings);
|
|
63
|
+
if (agent === undefined) continue;
|
|
64
|
+
if (seen.has(agent.name)) {
|
|
65
|
+
findings.error("sub-agent-name-duplicate", { subject: agent.name, path });
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
seen.add(agent.name);
|
|
69
|
+
agents.push(agent);
|
|
70
|
+
}
|
|
71
|
+
return agents;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function discoverAgentFiles(index: PluginFileIndex, set: ManifestSet, findings: Findings): readonly string[] {
|
|
75
|
+
const files = new Set<string>();
|
|
76
|
+
const addMarkdownUnder = (dir: string): void => {
|
|
77
|
+
for (const name of index.childFiles(dir)) {
|
|
78
|
+
if (name.endsWith(".md")) files.add(joinPath(dir, name));
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const declared = set.manifests.flatMap((m) => m.agentPaths ?? []);
|
|
83
|
+
if (set.manifests.every((m) => m.agentPaths === undefined)) {
|
|
84
|
+
addMarkdownUnder(DEFAULT_AGENTS_DIR);
|
|
85
|
+
}
|
|
86
|
+
for (const { path, manifest } of declared) {
|
|
87
|
+
if (path !== "" && index.has(path) && path.endsWith(".md")) {
|
|
88
|
+
files.add(path);
|
|
89
|
+
} else if (index.isDirectory(path)) {
|
|
90
|
+
addMarkdownUnder(path);
|
|
91
|
+
} else {
|
|
92
|
+
findings.warn("path-missing", { path: manifest, subject: path === "" ? "." : `./${path}` });
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return [...files].sort(comparePaths);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function readSubAgent(
|
|
99
|
+
index: PluginFileIndex,
|
|
100
|
+
path: string,
|
|
101
|
+
skillNames: ReadonlySet<string>,
|
|
102
|
+
findings: Findings,
|
|
103
|
+
): PluginSubAgent | undefined {
|
|
104
|
+
const text = readText(index, path, "subAgent", findings);
|
|
105
|
+
if (text === undefined) return undefined;
|
|
106
|
+
|
|
107
|
+
const extracted = extractFrontmatter(text);
|
|
108
|
+
let fieldsMap: Readonly<Record<string, unknown>> = {};
|
|
109
|
+
let body = text;
|
|
110
|
+
if (extracted.ok) {
|
|
111
|
+
const parsed = parseFrontmatter(extracted.yaml);
|
|
112
|
+
if (!parsed.ok) {
|
|
113
|
+
findings.error("sub-agent-frontmatter-unreadable", { path, detail: parsed.detail });
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
fieldsMap = parsed.fields;
|
|
117
|
+
body = extracted.body;
|
|
118
|
+
} else if (extracted.reason === "unclosed") {
|
|
119
|
+
findings.error("sub-agent-frontmatter-unreadable", { path, detail: "the frontmatter is not closed (missing the closing '---')" });
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const stem = basename(path).replace(/\.md$/, "");
|
|
124
|
+
let name: string;
|
|
125
|
+
if (typeof fieldsMap["name"] === "string" && fieldsMap["name"] !== "") {
|
|
126
|
+
name = fieldsMap["name"];
|
|
127
|
+
} else {
|
|
128
|
+
name = stem;
|
|
129
|
+
findings.warn("sub-agent-name-defaulted", { path, subject: name });
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const instructions = body.trim();
|
|
133
|
+
if (instructions.length < SUB_AGENT_INSTRUCTIONS_MIN) {
|
|
134
|
+
findings.error("sub-agent-instructions-short", { path, subject: name, detail: String(SUB_AGENT_INSTRUCTIONS_MIN) });
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const description = fieldsMap["description"];
|
|
139
|
+
const requested = fieldsMap["skills"];
|
|
140
|
+
const matchedSkills: string[] = [];
|
|
141
|
+
if (Array.isArray(requested)) {
|
|
142
|
+
for (const skill of requested) {
|
|
143
|
+
if (typeof skill !== "string") continue;
|
|
144
|
+
if (skillNames.has(skill)) matchedSkills.push(skill);
|
|
145
|
+
else findings.warn("sub-agent-skill-unknown", { path, subject: name, detail: skill });
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
let modelHint: ModelHint | undefined;
|
|
150
|
+
const model = fieldsMap["model"];
|
|
151
|
+
if (typeof model === "string" && model.trim() !== "") {
|
|
152
|
+
modelHint = classifyModel(model);
|
|
153
|
+
if (modelHint.alias === "unknown") findings.warn("sub-agent-model-unknown", { path, subject: name, detail: model });
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
for (const field of Object.keys(fieldsMap)) {
|
|
157
|
+
if (!READ_FIELDS.has(field)) findings.warn("sub-agent-field-ignored", { path, subject: name, detail: field });
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const tools = readToolList(fieldsMap, "tools");
|
|
161
|
+
const disallowedTools = readToolList(fieldsMap, "disallowedTools");
|
|
162
|
+
for (const [field, list] of [["tools", tools], ["disallowedTools", disallowedTools]] as const) {
|
|
163
|
+
if (list === null) findings.error("sub-agent-tool-list-invalid", { path, subject: name, detail: field });
|
|
164
|
+
}
|
|
165
|
+
if (tools === null || disallowedTools === null) return undefined;
|
|
166
|
+
|
|
167
|
+
return {
|
|
168
|
+
name,
|
|
169
|
+
...(typeof description === "string" && description !== "" && { description }),
|
|
170
|
+
instructions,
|
|
171
|
+
skillNames: matchedSkills,
|
|
172
|
+
...(modelHint !== undefined && { modelHint }),
|
|
173
|
+
...(tools !== undefined && { tools }),
|
|
174
|
+
...(disallowedTools !== undefined && { disallowedTools }),
|
|
175
|
+
path,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** A tool list as written; `undefined` when absent (or YAML null), `null` when it is neither a string nor a list of strings. */
|
|
180
|
+
function readToolList(fieldsMap: Readonly<Record<string, unknown>>, field: string): readonly string[] | undefined | null {
|
|
181
|
+
const value = fieldsMap[field];
|
|
182
|
+
if (value === undefined || value === null) return undefined;
|
|
183
|
+
if (typeof value === "string") return splitToolList(value);
|
|
184
|
+
if (Array.isArray(value) && value.every((entry) => typeof entry === "string")) {
|
|
185
|
+
return value.map((entry: string) => entry.trim()).filter((entry) => entry !== "");
|
|
186
|
+
}
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** Split on commas outside parentheses: `Read, Agent(a, b)` is two entries. */
|
|
191
|
+
export function splitToolList(value: string): readonly string[] {
|
|
192
|
+
const entries: string[] = [];
|
|
193
|
+
let depth = 0;
|
|
194
|
+
let current = "";
|
|
195
|
+
for (const char of value) {
|
|
196
|
+
if (char === "(") depth++;
|
|
197
|
+
else if (char === ")" && depth > 0) depth--;
|
|
198
|
+
if (char === "," && depth === 0) {
|
|
199
|
+
entries.push(current);
|
|
200
|
+
current = "";
|
|
201
|
+
} else {
|
|
202
|
+
current += char;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
entries.push(current);
|
|
206
|
+
return entries.map((entry) => entry.trim()).filter((entry) => entry !== "");
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* A dialect's `model` value to an alias. Cursor writes `fast` and
|
|
211
|
+
* `inherit`; Claude writes `sonnet`, `opus`, `haiku`, `inherit` or a full
|
|
212
|
+
* model id, which contains one of those family names. Anything else
|
|
213
|
+
* (Cursor's `grok-4.6[effort=xhigh]`, a vendor id Stigmer does not serve)
|
|
214
|
+
* is `unknown` with the raw text kept for the installer's warning.
|
|
215
|
+
*/
|
|
216
|
+
export function classifyModel(raw: string): ModelHint {
|
|
217
|
+
const value = raw.trim().toLowerCase();
|
|
218
|
+
const alias: ModelAlias =
|
|
219
|
+
value === "inherit"
|
|
220
|
+
? "inherit"
|
|
221
|
+
: value === "fast"
|
|
222
|
+
? "fast"
|
|
223
|
+
: value.includes("haiku")
|
|
224
|
+
? "haiku"
|
|
225
|
+
: value.includes("sonnet")
|
|
226
|
+
? "sonnet"
|
|
227
|
+
: value.includes("opus")
|
|
228
|
+
? "opus"
|
|
229
|
+
: "unknown";
|
|
230
|
+
return { raw, alias };
|
|
231
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Variable declarations, from the dialects that have them, reconciled with
|
|
3
|
+
* the references the servers make.
|
|
4
|
+
*
|
|
5
|
+
* Cursor declares `variables` as a JSON Schema object with no sensitivity
|
|
6
|
+
* flag, so every Cursor variable is a secret on Stigmer (a token treated as
|
|
7
|
+
* plain text is the costly mistake; a region name treated as a secret is
|
|
8
|
+
* an inconvenience). Claude declares `userConfig` entries with `sensitive`
|
|
9
|
+
* and `required`, plus `default`, `options`, `multiple`, `min`, `max` and
|
|
10
|
+
* the `directory`, `file`, `number`, `boolean` types, none of which a
|
|
11
|
+
* Stigmer variable carries (values are strings supplied by the user, and a
|
|
12
|
+
* local path means nothing in the sandbox); each is warned once.
|
|
13
|
+
*
|
|
14
|
+
* Reconciliation is what makes an imported server start: the runner
|
|
15
|
+
* filters a stdio server's environment to its declared keys and resolves
|
|
16
|
+
* `${VAR}` in headers and arguments strictly, so a variable a server
|
|
17
|
+
* references but no manifest declares would never reach it. Such a variable
|
|
18
|
+
* is declared here as a required secret, with a warning naming the server.
|
|
19
|
+
* A declared variable no server and no hook references is warned too; it
|
|
20
|
+
* is not wrong, only useless. A name the runner fills itself
|
|
21
|
+
* (`PLATFORM_VARIABLES`) is declared as the platform's, optional and no
|
|
22
|
+
* secret, whatever a manifest says of it: no vault holds it, so a required
|
|
23
|
+
* declaration would refuse every run. A hook references a variable through
|
|
24
|
+
* Claude's `${user_config.KEY}` in an exec-form handler (`normalise/hooks.ts`).
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
import type { ManifestSet } from "../detect.js";
|
|
28
|
+
import { describeValue, fields, isJsonObject, isStringArray, type JsonObject } from "../documents.js";
|
|
29
|
+
import type { Findings } from "../messages.js";
|
|
30
|
+
import { PLATFORM_VARIABLES, VARIABLE_NAME_PATTERN } from "../placeholders.js";
|
|
31
|
+
import type { PluginVariable } from "../types.js";
|
|
32
|
+
import type { McpServersResult } from "./mcp-servers.js";
|
|
33
|
+
|
|
34
|
+
export function normaliseVariables(
|
|
35
|
+
set: ManifestSet,
|
|
36
|
+
servers: McpServersResult,
|
|
37
|
+
hookReferences: ReadonlySet<string>,
|
|
38
|
+
findings: Findings,
|
|
39
|
+
): readonly PluginVariable[] {
|
|
40
|
+
const declared = new Map<string, PluginVariable>();
|
|
41
|
+
const declaredIn = new Map<string, string>();
|
|
42
|
+
for (const manifest of set.manifests) {
|
|
43
|
+
const declaration = manifest.variables;
|
|
44
|
+
if (declaration === undefined) continue;
|
|
45
|
+
const variables =
|
|
46
|
+
declaration.dialect === "cursor"
|
|
47
|
+
? readCursorVariables(declaration.value, declaration.manifest, findings)
|
|
48
|
+
: readClaudeVariables(declaration.value, declaration.manifest, findings);
|
|
49
|
+
for (const variable of variables) {
|
|
50
|
+
// Two manifests declaring one name: the identity manifest's wins.
|
|
51
|
+
if (declared.has(variable.name)) continue;
|
|
52
|
+
declared.set(variable.name, variable);
|
|
53
|
+
declaredIn.set(variable.name, declaration.manifest);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const referencedBy = new Map<string, string>();
|
|
58
|
+
for (const server of servers.servers) {
|
|
59
|
+
for (const name of server.env) {
|
|
60
|
+
if (!referencedBy.has(name)) referencedBy.set(name, server.name);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// A refused server's references are unknown, so an "unreferenced"
|
|
65
|
+
// warning would be a consequence of the refusal, not advice.
|
|
66
|
+
if (servers.refused === 0) {
|
|
67
|
+
for (const [name, variable] of declared) {
|
|
68
|
+
if (!referencedBy.has(name) && !hookReferences.has(name)) {
|
|
69
|
+
findings.warn("variable-unreferenced", { subject: variable.name, path: declaredIn.get(name) });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const inferred: PluginVariable[] = [];
|
|
75
|
+
for (const [name, server] of [...referencedBy].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))) {
|
|
76
|
+
if (declared.has(name) || PLATFORM_VARIABLES.has(name)) continue;
|
|
77
|
+
findings.warn("variable-inferred", { subject: name, detail: server });
|
|
78
|
+
inferred.push({ name, isSecret: true, optional: false, declaredBy: "inferred" });
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const platform: PluginVariable[] = [...PLATFORM_VARIABLES]
|
|
82
|
+
.filter((name) => referencedBy.has(name) || hookReferences.has(name) || declared.has(name))
|
|
83
|
+
.map((name) => ({
|
|
84
|
+
name,
|
|
85
|
+
description: declared.get(name)?.description ?? "Filled by Stigmer when the server is called",
|
|
86
|
+
isSecret: false,
|
|
87
|
+
optional: true,
|
|
88
|
+
declaredBy: "platform",
|
|
89
|
+
}));
|
|
90
|
+
for (const variable of platform) declared.delete(variable.name);
|
|
91
|
+
|
|
92
|
+
return [...declared.values(), ...inferred, ...platform];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Cursor: `{ type: "object", properties: { NAME: { type, title, description } }, required: [NAME] }`.
|
|
97
|
+
*/
|
|
98
|
+
function readCursorVariables(value: unknown, manifest: string, findings: Findings): readonly PluginVariable[] {
|
|
99
|
+
if (!isJsonObject(value) || value["type"] !== "object") {
|
|
100
|
+
findings.error("manifest-field-type", { path: manifest, subject: "variables", detail: "a JSON Schema object with type 'object'" });
|
|
101
|
+
return [];
|
|
102
|
+
}
|
|
103
|
+
const properties = value["properties"] ?? {};
|
|
104
|
+
if (!isJsonObject(properties)) {
|
|
105
|
+
findings.error("manifest-field-type", { path: manifest, subject: "variables.properties", detail: "an object" });
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
const required = value["required"] ?? [];
|
|
109
|
+
if (!isStringArray(required)) {
|
|
110
|
+
findings.error("manifest-field-type", { path: manifest, subject: "variables.required", detail: "an array of strings" });
|
|
111
|
+
return [];
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const variables: PluginVariable[] = [];
|
|
115
|
+
for (const [name, schema] of fields(properties)) {
|
|
116
|
+
if (!VARIABLE_NAME_PATTERN.test(name)) {
|
|
117
|
+
findings.error("variable-name-invalid", { subject: name, path: manifest });
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
const property = isJsonObject(schema) ? schema : {};
|
|
121
|
+
const type = property["type"];
|
|
122
|
+
if (type !== undefined && type !== "string") {
|
|
123
|
+
findings.warn("variable-type-narrowed", { subject: name, path: manifest, detail: describeValue(type) });
|
|
124
|
+
}
|
|
125
|
+
if (property["default"] !== undefined) findings.warn("variable-default-dropped", { subject: name, path: manifest });
|
|
126
|
+
if (property["enum"] !== undefined) findings.warn("variable-option-dropped", { subject: name, path: manifest, detail: "enum" });
|
|
127
|
+
const description = describe(property);
|
|
128
|
+
variables.push({
|
|
129
|
+
name,
|
|
130
|
+
...(description !== undefined && { description }),
|
|
131
|
+
isSecret: true,
|
|
132
|
+
optional: !required.includes(name),
|
|
133
|
+
declaredBy: "cursor",
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
return variables;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Claude: `{ KEY: { type, title, description, sensitive, required, default, options, multiple, min, max } }`.
|
|
141
|
+
*/
|
|
142
|
+
function readClaudeVariables(value: unknown, manifest: string, findings: Findings): readonly PluginVariable[] {
|
|
143
|
+
if (!isJsonObject(value)) {
|
|
144
|
+
findings.error("manifest-field-type", { path: manifest, subject: "userConfig", detail: "an object" });
|
|
145
|
+
return [];
|
|
146
|
+
}
|
|
147
|
+
const variables: PluginVariable[] = [];
|
|
148
|
+
for (const [name, entry] of fields(value)) {
|
|
149
|
+
if (!VARIABLE_NAME_PATTERN.test(name)) {
|
|
150
|
+
findings.error("variable-name-invalid", { subject: name, path: manifest });
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
if (!isJsonObject(entry)) {
|
|
154
|
+
findings.error("manifest-field-type", { path: manifest, subject: `userConfig.${name}`, detail: "an object" });
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
const type = entry["type"];
|
|
158
|
+
if (type !== undefined && type !== "string") {
|
|
159
|
+
findings.warn("variable-type-narrowed", { subject: name, path: manifest, detail: describeValue(type) });
|
|
160
|
+
}
|
|
161
|
+
if (entry["default"] !== undefined) findings.warn("variable-default-dropped", { subject: name, path: manifest });
|
|
162
|
+
for (const option of ["options", "multiple", "min", "max"]) {
|
|
163
|
+
if (entry[option] !== undefined) findings.warn("variable-option-dropped", { subject: name, path: manifest, detail: option });
|
|
164
|
+
}
|
|
165
|
+
const description = describe(entry);
|
|
166
|
+
variables.push({
|
|
167
|
+
name,
|
|
168
|
+
...(description !== undefined && { description }),
|
|
169
|
+
isSecret: entry["sensitive"] === true,
|
|
170
|
+
optional: entry["required"] !== true,
|
|
171
|
+
declaredBy: "claude",
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
return variables;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** `title` and `description` joined, whichever are present. */
|
|
178
|
+
function describe(entry: JsonObject): string | undefined {
|
|
179
|
+
const parts = [entry["title"], entry["description"]].filter((part): part is string => typeof part === "string" && part !== "");
|
|
180
|
+
return parts.length === 0 ? undefined : parts.join(": ");
|
|
181
|
+
}
|
package/src/outcome.ts
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The outcome of reading a package and the closed vocabulary of findings.
|
|
3
|
+
*
|
|
4
|
+
* The shape is the server's `ConnectRunOutcome`: a discriminated union on
|
|
5
|
+
* `ok`, with a closed `kind` union behind the failure arm, so a consumer
|
|
6
|
+
* switches on kinds and the compiler closes the switch. An error refuses the
|
|
7
|
+
* package; a warning never does. Both are `PluginFinding`s with the same
|
|
8
|
+
* fields, so one renderer prints both.
|
|
9
|
+
*
|
|
10
|
+
* Two error postures meet here and the header of each module states which
|
|
11
|
+
* applies. Where the open format tells a client to skip a broken component
|
|
12
|
+
* and keep loading, Stigmer refuses the package: an installed agent that
|
|
13
|
+
* quietly lacks a server or a sub-agent is worse than a refused install.
|
|
14
|
+
* But the reader keeps scanning past a fatal finding so one run reports
|
|
15
|
+
* every problem and an author fixes them in one pass.
|
|
16
|
+
*
|
|
17
|
+
* Every kind has exactly one sentence, in `messages.ts`, and the adversarial
|
|
18
|
+
* suite has exactly one fixture per kind. Adding a kind means adding both.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import type { PluginPackage } from "./types.js";
|
|
22
|
+
|
|
23
|
+
export type PluginErrorKind =
|
|
24
|
+
// Manifests
|
|
25
|
+
| "no-manifest"
|
|
26
|
+
| "manifest-unreadable"
|
|
27
|
+
| "manifest-schema-missing"
|
|
28
|
+
| "manifest-schema-unsupported"
|
|
29
|
+
| "manifest-name-missing"
|
|
30
|
+
| "manifest-name-invalid"
|
|
31
|
+
| "manifest-name-conflict"
|
|
32
|
+
| "manifest-field-type"
|
|
33
|
+
// Paths
|
|
34
|
+
| "path-not-relative"
|
|
35
|
+
| "path-escapes-root"
|
|
36
|
+
| "path-glob-unsupported"
|
|
37
|
+
| "path-uncontained"
|
|
38
|
+
| "document-too-large"
|
|
39
|
+
// Skills
|
|
40
|
+
| "skill-frontmatter-missing"
|
|
41
|
+
| "skill-frontmatter-unclosed"
|
|
42
|
+
| "skill-frontmatter-unreadable"
|
|
43
|
+
| "skill-name-invalid"
|
|
44
|
+
| "skill-name-duplicate"
|
|
45
|
+
// MCP configuration files
|
|
46
|
+
| "mcp-config-unreadable"
|
|
47
|
+
| "mcp-config-shape"
|
|
48
|
+
| "mcp-config-schema-missing"
|
|
49
|
+
| "mcp-config-schema-unsupported"
|
|
50
|
+
| "mcp-config-field-unknown"
|
|
51
|
+
// MCP server entries
|
|
52
|
+
| "mcp-server-shape"
|
|
53
|
+
| "mcp-server-type-missing"
|
|
54
|
+
| "mcp-server-transport-unknown"
|
|
55
|
+
| "mcp-server-type-ambiguous"
|
|
56
|
+
| "mcp-server-type-unknown"
|
|
57
|
+
| "mcp-server-field-unknown"
|
|
58
|
+
| "mcp-server-field-type"
|
|
59
|
+
| "mcp-server-url-missing"
|
|
60
|
+
| "mcp-server-url-invalid"
|
|
61
|
+
| "mcp-server-url-variable"
|
|
62
|
+
| "mcp-server-command-missing"
|
|
63
|
+
| "mcp-server-command-invalid"
|
|
64
|
+
| "mcp-server-command-relative"
|
|
65
|
+
| "mcp-server-plugin-root-reference"
|
|
66
|
+
| "mcp-server-cwd-unsupported"
|
|
67
|
+
| "mcp-server-env-literal"
|
|
68
|
+
| "mcp-server-env-rename"
|
|
69
|
+
| "mcp-server-name-duplicate"
|
|
70
|
+
| "mcp-server-header-duplicate"
|
|
71
|
+
| "mcp-server-header-invalid"
|
|
72
|
+
// Sub-agents
|
|
73
|
+
| "sub-agent-frontmatter-unreadable"
|
|
74
|
+
| "sub-agent-instructions-short"
|
|
75
|
+
| "sub-agent-name-duplicate"
|
|
76
|
+
| "sub-agent-tool-list-invalid"
|
|
77
|
+
// Hooks
|
|
78
|
+
| "hooks-unreadable"
|
|
79
|
+
| "hooks-shape"
|
|
80
|
+
| "hook-command-missing"
|
|
81
|
+
| "hook-matcher-invalid"
|
|
82
|
+
| "hook-condition-invalid"
|
|
83
|
+
// Claude plugin settings
|
|
84
|
+
| "settings-unreadable"
|
|
85
|
+
// Variables
|
|
86
|
+
| "variable-name-invalid";
|
|
87
|
+
|
|
88
|
+
export type PluginWarningKind =
|
|
89
|
+
| "manifest-field-unknown"
|
|
90
|
+
| "manifest-extensions-invalid"
|
|
91
|
+
| "path-missing"
|
|
92
|
+
| "skill-name-defaulted"
|
|
93
|
+
| "skill-name-differs-from-directory"
|
|
94
|
+
| "skill-description-missing"
|
|
95
|
+
| "mcp-config-field-ignored"
|
|
96
|
+
| "mcp-server-sse-mapped"
|
|
97
|
+
| "mcp-server-field-ignored"
|
|
98
|
+
| "mcp-server-auth-ignored"
|
|
99
|
+
| "variable-inferred"
|
|
100
|
+
| "variable-unreferenced"
|
|
101
|
+
| "variable-default-dropped"
|
|
102
|
+
| "variable-type-narrowed"
|
|
103
|
+
| "variable-option-dropped"
|
|
104
|
+
| "sub-agent-name-defaulted"
|
|
105
|
+
| "sub-agent-skill-unknown"
|
|
106
|
+
| "sub-agent-model-unknown"
|
|
107
|
+
| "sub-agent-field-ignored"
|
|
108
|
+
| "hook-event-not-run"
|
|
109
|
+
| "hook-handler-not-run"
|
|
110
|
+
| "hook-field-ignored"
|
|
111
|
+
| "hooks-format-not-run"
|
|
112
|
+
| "skill-hooks-not-run"
|
|
113
|
+
| "hooks-not-read"
|
|
114
|
+
| "settings-agent-unknown"
|
|
115
|
+
| "settings-key-ignored"
|
|
116
|
+
| "stigmer-folder-ignored";
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* The warnings that name hooks Stigmer does not run, so a surface can list
|
|
120
|
+
* them beside the hooks that do run rather than among every other finding.
|
|
121
|
+
* `hook-field-ignored` is not one: its hook runs, with one field unread.
|
|
122
|
+
*/
|
|
123
|
+
export const HOOK_WARNING_KINDS: ReadonlySet<PluginWarningKind> = new Set<PluginWarningKind>([
|
|
124
|
+
"hook-event-not-run",
|
|
125
|
+
"hook-handler-not-run",
|
|
126
|
+
"hooks-format-not-run",
|
|
127
|
+
"skill-hooks-not-run",
|
|
128
|
+
"hooks-not-read",
|
|
129
|
+
]);
|
|
130
|
+
|
|
131
|
+
export type PluginFindingKind = PluginErrorKind | PluginWarningKind;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* One finding over any closed kind vocabulary. The plugin reader and the
|
|
135
|
+
* marketplace reader (`marketplace/`) each own a vocabulary and a sentence
|
|
136
|
+
* table; the shape of a finding, and the renderer that prints one, are
|
|
137
|
+
* shared through this type.
|
|
138
|
+
*/
|
|
139
|
+
export interface Finding<K extends string> {
|
|
140
|
+
readonly kind: K;
|
|
141
|
+
/** The file, or the declared path, the finding is about. */
|
|
142
|
+
readonly path?: string;
|
|
143
|
+
/** The skill, server, sub-agent, variable, entry or field the finding names. */
|
|
144
|
+
readonly subject?: string;
|
|
145
|
+
/** A second identifier the sentence needs (a field name, a parser's own message). */
|
|
146
|
+
readonly detail?: string;
|
|
147
|
+
/** The one sentence for this kind, from the vocabulary's `messages.ts`. */
|
|
148
|
+
readonly message: string;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export type PluginFinding = Finding<PluginFindingKind>;
|
|
152
|
+
|
|
153
|
+
/** What a reader needs to compose a finding: everything but the sentence. */
|
|
154
|
+
export type FindingContext = Pick<Finding<string>, "path" | "subject" | "detail">;
|
|
155
|
+
|
|
156
|
+
export type PluginReadOutcome =
|
|
157
|
+
| { readonly ok: true; readonly plugin: PluginPackage; readonly warnings: readonly PluginFinding[] }
|
|
158
|
+
| { readonly ok: false; readonly errors: readonly PluginFinding[]; readonly warnings: readonly PluginFinding[] };
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `${VAR}` vocabulary: what counts as a variable reference, what counts
|
|
3
|
+
* as a reference to the plugin's own files, and the Claude rewrite.
|
|
4
|
+
*
|
|
5
|
+
* `PLACEHOLDER_PATTERN` is the runner's own scanner, verbatim: the runner
|
|
6
|
+
* resolves `${VAR}` strictly in a server's headers and arguments and refuses
|
|
7
|
+
* to start a server with an unresolved one, so this is the definition of "a
|
|
8
|
+
* reference" in every dialect, including the open format whose text forbids
|
|
9
|
+
* expansion in headers. A plugin's `${API_KEY}` in a header means "the
|
|
10
|
+
* caller's API_KEY" on Stigmer whichever tool wrote it.
|
|
11
|
+
*
|
|
12
|
+
* Claude's `${user_config.KEY}` carries a dot the runner's scanner would
|
|
13
|
+
* never match, so it is rewritten to `${KEY}` before anything reads it; the
|
|
14
|
+
* rewrite is what makes a Claude plugin's server start, not a courtesy.
|
|
15
|
+
*
|
|
16
|
+
* The plugin-root placeholders are the one class the library refuses: the
|
|
17
|
+
* runner mounts nothing from a plugin, so a server that reaches for
|
|
18
|
+
* `${PLUGIN_ROOT}` (any dialect's spelling) can never find what it points
|
|
19
|
+
* at. The set is checked before the generic scan because `${PLUGIN_ROOT}`
|
|
20
|
+
* also matches the generic pattern.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/** The runner's `${VAR_NAME}` scanner (`shared/placeholder-resolver.ts`). */
|
|
24
|
+
export const PLACEHOLDER_PATTERN = /\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g;
|
|
25
|
+
|
|
26
|
+
/** A variable name the runner's scanner can reference. */
|
|
27
|
+
export const VARIABLE_NAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The names the runner fills itself for a server that references them: who
|
|
31
|
+
* is calling (a kind and a value), the conversation it calls from, and the
|
|
32
|
+
* Stigmer server's address. A plugin references them in a header or an
|
|
33
|
+
* argument; it never declares them, so each is declared here as an
|
|
34
|
+
* optional, non-secret variable the platform supplies. The address alone
|
|
35
|
+
* may also be saved by a person, and a saved one wins over the fill.
|
|
36
|
+
* The runner keeps the same names (`shared/platform-variables.ts`), and a
|
|
37
|
+
* runner test holds the two lists equal.
|
|
38
|
+
*/
|
|
39
|
+
export const PLATFORM_VARIABLES: ReadonlySet<string> = new Set([
|
|
40
|
+
"STIGMER_CALLER_IDENTITY_KIND",
|
|
41
|
+
"STIGMER_CALLER_IDENTITY_VALUE",
|
|
42
|
+
"STIGMER_SESSION_ID",
|
|
43
|
+
"STIGMER_SERVER_ADDRESS",
|
|
44
|
+
]);
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The platform variables the runner always fills, over anything a run
|
|
48
|
+
* planned: who is calling and the conversation. They are no requirement,
|
|
49
|
+
* so no vault value is read for them and no person is asked for them. The
|
|
50
|
+
* Stigmer server's address is the one platform variable a person may set:
|
|
51
|
+
* a value saved for it wins, and the runner fills it only when nothing is
|
|
52
|
+
* (stigmer/stigmer#1446), so it stays the optional key it is declared.
|
|
53
|
+
* The server's run planning and the console's reading of what a run needs
|
|
54
|
+
* both skip these names, from this one set.
|
|
55
|
+
*/
|
|
56
|
+
export const RUNNER_FILLED_VARIABLES: ReadonlySet<string> = new Set(
|
|
57
|
+
[...PLATFORM_VARIABLES].filter((name) => name !== "STIGMER_SERVER_ADDRESS"),
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
const USER_CONFIG_PATTERN = /\$\{user_config\.([A-Za-z_][A-Za-z0-9_]*)\}/g;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Every spelling of "the plugin's own directory" across the dialects:
|
|
64
|
+
* the open format's, Claude Code's (plus its project directory), Cursor's.
|
|
65
|
+
*/
|
|
66
|
+
export const PLUGIN_ROOT_PLACEHOLDERS: ReadonlySet<string> = new Set([
|
|
67
|
+
"${PLUGIN_ROOT}",
|
|
68
|
+
"${PLUGIN_DATA}",
|
|
69
|
+
"${CLAUDE_PLUGIN_ROOT}",
|
|
70
|
+
"${CLAUDE_PLUGIN_DATA}",
|
|
71
|
+
"${CLAUDE_PROJECT_DIR}",
|
|
72
|
+
"${CURSOR_PLUGIN_ROOT}",
|
|
73
|
+
]);
|
|
74
|
+
|
|
75
|
+
/** The reserved environment names the open format forbids a server's `env` to set. */
|
|
76
|
+
export const PLUGIN_ROOT_ENV_NAMES: ReadonlySet<string> = new Set(["PLUGIN_ROOT", "PLUGIN_DATA"]);
|
|
77
|
+
|
|
78
|
+
/** `${user_config.KEY}` -> `${KEY}`. */
|
|
79
|
+
export function rewriteUserConfig(value: string): string {
|
|
80
|
+
return value.replace(USER_CONFIG_PATTERN, (_match, key: string) => `\${${key}}`);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** The `KEY`s of every `${user_config.KEY}` in `value`, in order of appearance. */
|
|
84
|
+
export function userConfigReferences(value: string): readonly string[] {
|
|
85
|
+
return [...value.matchAll(USER_CONFIG_PATTERN)].map((match) => match[1]).filter((name): name is string => name !== undefined);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** The first plugin-root placeholder in `value`, or `undefined`. */
|
|
89
|
+
export function findPluginRootPlaceholder(value: string): string | undefined {
|
|
90
|
+
for (const placeholder of PLUGIN_ROOT_PLACEHOLDERS) {
|
|
91
|
+
if (value.includes(placeholder)) return placeholder;
|
|
92
|
+
}
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** The variable names referenced in `value`, in order of appearance, deduplicated. */
|
|
97
|
+
export function referencedVariables(value: string): readonly string[] {
|
|
98
|
+
const names: string[] = [];
|
|
99
|
+
for (const match of value.matchAll(PLACEHOLDER_PATTERN)) {
|
|
100
|
+
const name = match[1];
|
|
101
|
+
if (name !== undefined && !names.includes(name)) names.push(name);
|
|
102
|
+
}
|
|
103
|
+
return names;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** The variable name when `value` is exactly one placeholder and nothing else; otherwise `undefined`. */
|
|
107
|
+
export function singlePlaceholderName(value: string): string | undefined {
|
|
108
|
+
const match = /^\$\{([A-Za-z_][A-Za-z0-9_]*)\}$/.exec(value);
|
|
109
|
+
return match?.[1];
|
|
110
|
+
}
|