@stigmer/coding-agent-plugin 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/README.md +150 -9
- package/index.js +2 -2
- package/package.json +2 -2
- package/plugin/.claude-plugin/marketplace.json +5 -2
- package/plugin/.claude-plugin/plugin.json +15 -4
- package/plugin/.codex-plugin/plugin.json +12 -5
- package/plugin/.cursor-plugin/marketplace.json +4 -2
- package/plugin/.cursor-plugin/plugin.json +7 -4
- package/plugin/README.md +52 -10
- package/plugin/hooks/codex-hooks.json +1 -0
- package/plugin/hooks/cursor-hooks.json +1 -0
- package/plugin/hooks/decide.mjs +230 -0
- package/plugin/hooks/guard.mjs +20 -0
- package/plugin/hooks/hooks.json +15 -0
- package/plugin/skills/stigmer/SKILL.md +244 -201
- package/plugin/skills/stigmer-build/SKILL.md +239 -0
- package/plugin/skills/stigmer-integrate/SKILL.md +227 -0
- package/plugin/skills/stigmer-operate/SKILL.md +239 -0
- package/plugin/skills/stigmer-run/SKILL.md +258 -0
- package/plugin/skills/stigmer-setup/SKILL.md +232 -0
- /package/plugin/{.claude-plugin/icon.png → assets/logo.png} +0 -0
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
// What the plugin's Claude Code guard (guard.mjs, a PreToolUse hook) decides
|
|
2
|
+
// about one tool call: ask the person first, or say nothing and let Claude
|
|
3
|
+
// Code's own permissions decide.
|
|
4
|
+
//
|
|
5
|
+
// It asks before an act that can't be undone, or that is the person's to
|
|
6
|
+
// give, even when they once chose "always allow" for the plugin's tools:
|
|
7
|
+
//
|
|
8
|
+
// - the plugin's own tool server's destructive tools (every tool marked
|
|
9
|
+
// destructiveHint in @stigmer/mcp-server), named the way Claude Code
|
|
10
|
+
// names a plugin's server's tools, mcp__plugin_<plugin>_<server>__<tool>;
|
|
11
|
+
// - answering a run's approval with allow or allow_all (a deny passes:
|
|
12
|
+
// refusing is always safe), by the tool or by `stigmer runs approve`;
|
|
13
|
+
// - a `stigmer` command whose --force skips the CLI's own confirmation or
|
|
14
|
+
// overwrites files. A plain `stigmer delete` passes: without a terminal
|
|
15
|
+
// the CLI's own question aborts it. `-f` is matched only on those
|
|
16
|
+
// commands, since it means --file on `apply` and --follow on `logs`.
|
|
17
|
+
//
|
|
18
|
+
// Both lists are held by tests against their sources (the tool server's
|
|
19
|
+
// roster, the CLI's command tree), so a new destructive tool or forced
|
|
20
|
+
// command can't ship unguarded. The reason is written for two readers: the
|
|
21
|
+
// person, who sees it in the prompt, and the agent, which reads it in the
|
|
22
|
+
// tool result when no one is there to answer (a `claude -p` run denies an
|
|
23
|
+
// `ask` and hands the agent the reason).
|
|
24
|
+
//
|
|
25
|
+
// Pure, and dependency-free: the plugin installs from GitHub with no
|
|
26
|
+
// node_modules.
|
|
27
|
+
|
|
28
|
+
/** The tool server's destructive tools, as the hook's matcher names them. */
|
|
29
|
+
export const DESTRUCTIVE_TOOLS = ["delete_agent", "delete_skill", "cancel_run"];
|
|
30
|
+
|
|
31
|
+
/** The tool that answers a run's approval. */
|
|
32
|
+
export const APPROVAL_TOOL = "submit_run_approval";
|
|
33
|
+
|
|
34
|
+
/** How Claude Code names this plugin's server's tools. */
|
|
35
|
+
export const TOOL_PREFIX = "mcp__plugin_stigmer_stigmer__";
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The CLI commands whose force flag skips a confirmation or overwrites,
|
|
39
|
+
* each with the flags that mean force on it.
|
|
40
|
+
*/
|
|
41
|
+
export const FORCE_COMMANDS = [
|
|
42
|
+
{ path: ["delete"], flags: ["-f", "--force"] },
|
|
43
|
+
{ path: ["provider-key", "delete"], flags: ["-f", "--force"] },
|
|
44
|
+
{ path: ["service-account", "delete"], flags: ["-f", "--force"] },
|
|
45
|
+
{ path: ["vault", "remove-secret"], flags: ["-f", "--force"] },
|
|
46
|
+
{ path: ["vault", "remove-connection"], flags: ["-f", "--force"] },
|
|
47
|
+
{ path: ["reset"], flags: ["--force"] },
|
|
48
|
+
{ path: ["example", "get"], flags: ["-f", "--force"] },
|
|
49
|
+
{ path: ["app-handover"], flags: ["-f", "--force"] },
|
|
50
|
+
];
|
|
51
|
+
|
|
52
|
+
/** The CLI command that answers a run's approval, and its flag naming the answer. */
|
|
53
|
+
export const APPROVE_COMMAND = { path: ["runs", "approve"], flag: "--action" };
|
|
54
|
+
|
|
55
|
+
/** Global options that take a value, so the value is never read as a command word. */
|
|
56
|
+
const VALUE_GLOBALS = new Set(["--org", "--api-key"]);
|
|
57
|
+
|
|
58
|
+
const AGENT_LINE = "If the person hasn't approved exactly this in the conversation, stop and ask them first.";
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The hook's answer to one PreToolUse input: an `ask` with its reason, or
|
|
62
|
+
* `null` to say nothing. Never throws.
|
|
63
|
+
*/
|
|
64
|
+
export function decide(input) {
|
|
65
|
+
try {
|
|
66
|
+
if (input === null || typeof input !== "object") return null;
|
|
67
|
+
const tool = typeof input.tool_name === "string" ? input.tool_name : "";
|
|
68
|
+
const args = input.tool_input !== null && typeof input.tool_input === "object" ? input.tool_input : {};
|
|
69
|
+
if (tool === "Bash") {
|
|
70
|
+
const command = typeof args.command === "string" ? args.command : "";
|
|
71
|
+
const reason = shellReason(command);
|
|
72
|
+
return reason === null ? null : ask(reason);
|
|
73
|
+
}
|
|
74
|
+
if (!tool.startsWith(TOOL_PREFIX)) return null;
|
|
75
|
+
const reason = toolReason(tool.slice(TOOL_PREFIX.length), args);
|
|
76
|
+
return reason === null ? null : ask(reason);
|
|
77
|
+
} catch {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function ask(reason) {
|
|
83
|
+
return {
|
|
84
|
+
hookSpecificOutput: {
|
|
85
|
+
hookEventName: "PreToolUse",
|
|
86
|
+
permissionDecision: "ask",
|
|
87
|
+
permissionDecisionReason: `${reason} ${AGENT_LINE}`,
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function text(value) {
|
|
93
|
+
return typeof value === "string" && value !== "" ? value : "?";
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function named(args) {
|
|
97
|
+
const org = typeof args.org === "string" && args.org !== "" ? `${args.org}/` : "";
|
|
98
|
+
return `${org}${text(args.slug)}`;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** The reason to ask before one of the tool server's tools, or null. */
|
|
102
|
+
function toolReason(name, args) {
|
|
103
|
+
switch (name) {
|
|
104
|
+
case "delete_agent":
|
|
105
|
+
return `Stigmer: this deletes the agent ${named(args)} and every version of it. It can't be undone.`;
|
|
106
|
+
case "delete_skill":
|
|
107
|
+
return `Stigmer: this deletes the skill ${named(args)} and every version of it. It can't be undone.`;
|
|
108
|
+
case "cancel_run":
|
|
109
|
+
return `Stigmer: this cancels run ${text(args.run_id)}: every unfinished turn of its conversation stops, and can't be resumed.`;
|
|
110
|
+
case APPROVAL_TOOL: {
|
|
111
|
+
const decision = args.decision;
|
|
112
|
+
if (decision !== "allow" && decision !== "allow_all") return null;
|
|
113
|
+
return `Stigmer: this answers run ${text(args.run_id)}'s approval with "${decision}", and the run then goes ahead. An approval is the person's to give.`;
|
|
114
|
+
}
|
|
115
|
+
default:
|
|
116
|
+
return DESTRUCTIVE_TOOLS.includes(name) ? `Stigmer: ${name} can't be undone.` : null;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** The reason to ask before a shell line, or null: the first `stigmer` command in it that needs asking. */
|
|
121
|
+
export function shellReason(line) {
|
|
122
|
+
for (const words of commands(line)) {
|
|
123
|
+
const at = words.findIndex(isStigmer);
|
|
124
|
+
if (at === -1) continue;
|
|
125
|
+
const rest = words.slice(at + 1);
|
|
126
|
+
const path = commandWords(rest);
|
|
127
|
+
const shown = words.slice(at).join(" ");
|
|
128
|
+
const forced = FORCE_COMMANDS.find((entry) => startsWith(path, entry.path));
|
|
129
|
+
if (forced !== undefined && rest.some((word) => isForceFlag(word, forced.flags))) {
|
|
130
|
+
return `Stigmer: \`${shown}\` skips the CLI's own question with --force, and what it deletes or overwrites can't be undone.`;
|
|
131
|
+
}
|
|
132
|
+
if (startsWith(path, APPROVE_COMMAND.path)) {
|
|
133
|
+
const answer = optionValue(rest, APPROVE_COMMAND.flag) ?? "allow";
|
|
134
|
+
if (answer !== "deny") {
|
|
135
|
+
return `Stigmer: \`${shown}\` answers a run's approval with "${answer}", and the run then goes ahead. An approval is the person's to give.`;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Whether a word runs the stigmer CLI: `stigmer`, a path to it, or the npm package. */
|
|
143
|
+
function isStigmer(word) {
|
|
144
|
+
const base = word.split("/").pop() ?? "";
|
|
145
|
+
return base === "stigmer" || base === "stigmer.exe" || /^@stigmer\/cli(@.*)?$/.test(word);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** The command words after `stigmer`: every word that is not a flag or a global flag's value. */
|
|
149
|
+
function commandWords(rest) {
|
|
150
|
+
const words = [];
|
|
151
|
+
for (let i = 0; i < rest.length; i += 1) {
|
|
152
|
+
const word = rest[i];
|
|
153
|
+
if (word === "--") break;
|
|
154
|
+
if (word.startsWith("-")) {
|
|
155
|
+
if (VALUE_GLOBALS.has(word)) i += 1;
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
words.push(word);
|
|
159
|
+
}
|
|
160
|
+
return words;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function startsWith(words, prefix) {
|
|
164
|
+
return prefix.every((word, i) => words[i] === word);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function isForceFlag(word, flags) {
|
|
168
|
+
if (flags.includes(word)) return true;
|
|
169
|
+
if (flags.includes("--force") && word.startsWith("--force=")) return word !== "--force=false";
|
|
170
|
+
// A cluster of short flags (`-yf`) carries -f too.
|
|
171
|
+
return flags.includes("-f") && /^-[A-Za-z]{2,}$/.test(word) && word.includes("f");
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function optionValue(words, flag) {
|
|
175
|
+
for (let i = 0; i < words.length; i += 1) {
|
|
176
|
+
if (words[i] === flag) return words[i + 1];
|
|
177
|
+
if (words[i].startsWith(`${flag}=`)) return words[i].slice(flag.length + 1);
|
|
178
|
+
}
|
|
179
|
+
return undefined;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* A shell line's simple commands, each as its words: split at `;`, `&`,
|
|
184
|
+
* `|`, `&&`, `||`, newlines and parentheses outside quotes, with quotes
|
|
185
|
+
* removed. Leading `VAR=value` assignments are dropped. Not a full shell
|
|
186
|
+
* parser: a line it misreads at worst asks once more than it needs to.
|
|
187
|
+
*/
|
|
188
|
+
export function commands(line) {
|
|
189
|
+
const out = [];
|
|
190
|
+
let words = [];
|
|
191
|
+
let word = "";
|
|
192
|
+
let inWord = false;
|
|
193
|
+
let quote = "";
|
|
194
|
+
const endWord = () => {
|
|
195
|
+
if (inWord) words.push(word);
|
|
196
|
+
word = "";
|
|
197
|
+
inWord = false;
|
|
198
|
+
};
|
|
199
|
+
const endCommand = () => {
|
|
200
|
+
endWord();
|
|
201
|
+
const start = words.findIndex((w) => !/^[A-Za-z_][A-Za-z0-9_]*=/.test(w));
|
|
202
|
+
if (start !== -1) out.push(words.slice(start));
|
|
203
|
+
words = [];
|
|
204
|
+
};
|
|
205
|
+
for (let i = 0; i < line.length; i += 1) {
|
|
206
|
+
const c = line[i];
|
|
207
|
+
if (quote !== "") {
|
|
208
|
+
if (c === quote) quote = "";
|
|
209
|
+
else if (c === "\\" && quote === '"' && i + 1 < line.length) word += line[++i];
|
|
210
|
+
else word += c;
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
if (c === "'" || c === '"') {
|
|
214
|
+
quote = c;
|
|
215
|
+
inWord = true;
|
|
216
|
+
} else if (c === "\\" && i + 1 < line.length) {
|
|
217
|
+
word += line[++i];
|
|
218
|
+
inWord = true;
|
|
219
|
+
} else if (c === " " || c === "\t") {
|
|
220
|
+
endWord();
|
|
221
|
+
} else if (c === ";" || c === "&" || c === "|" || c === "\n" || c === "(" || c === ")") {
|
|
222
|
+
endCommand();
|
|
223
|
+
} else {
|
|
224
|
+
word += c;
|
|
225
|
+
inWord = true;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
endCommand();
|
|
229
|
+
return out;
|
|
230
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Claude Code's PreToolUse hook for Stigmer's plugin: reads the call from
|
|
2
|
+
// stdin and prints decide()'s answer (decide.mjs). It fails open: on any
|
|
3
|
+
// error of its own it prints nothing and exits 0, never 2, which Claude Code
|
|
4
|
+
// would read as a block.
|
|
5
|
+
import { decide } from "./decide.mjs";
|
|
6
|
+
|
|
7
|
+
/* v8 ignore start -- @preserve: Claude Code's entry, which __tests__/guard.test.ts runs in a child process that this suite's coverage can't see */
|
|
8
|
+
let input = "";
|
|
9
|
+
process.stdin.setEncoding("utf8");
|
|
10
|
+
process.stdin.on("data", (chunk) => (input += chunk));
|
|
11
|
+
process.stdin.on("end", () => {
|
|
12
|
+
try {
|
|
13
|
+
const answer = decide(JSON.parse(input));
|
|
14
|
+
if (answer !== null) process.stdout.write(`${JSON.stringify(answer)}\n`);
|
|
15
|
+
} catch {
|
|
16
|
+
// Fail open: Claude Code's own permissions still decide.
|
|
17
|
+
}
|
|
18
|
+
process.exitCode = 0;
|
|
19
|
+
});
|
|
20
|
+
/* v8 ignore stop */
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"description": "Stigmer asks the person before an act that can't be undone or is theirs to give: deleting an agent or skill, cancelling a run, answering a run's approval, or a stigmer command forced past its own question.",
|
|
3
|
+
"hooks": {
|
|
4
|
+
"PreToolUse": [
|
|
5
|
+
{
|
|
6
|
+
"matcher": "^mcp__plugin_stigmer_stigmer__(delete_agent|delete_skill|cancel_run|submit_run_approval)$",
|
|
7
|
+
"hooks": [{ "type": "command", "command": "node", "args": ["${CLAUDE_PLUGIN_ROOT}/hooks/guard.mjs"] }]
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"matcher": "Bash",
|
|
11
|
+
"hooks": [{ "type": "command", "if": "Bash(stigmer *)", "command": "node", "args": ["${CLAUDE_PLUGIN_ROOT}/hooks/guard.mjs"] }]
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
}
|
|
15
|
+
}
|