@americanumberoneaokgoodtimes/p-plugin 0.0.0-stage → 1.0.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/.antigravity-plugin/plugin.json +22 -0
- package/.claude-plugin/plugin.json +14 -0
- package/.mcp.json +10 -0
- package/README.md +323 -2
- package/assets/logo.svg +6 -0
- package/hooks/hooks.json +16 -0
- package/hooks.json +11 -0
- package/mcp_config.json +10 -0
- package/opencode/plugin.d.ts +13 -0
- package/opencode/plugin.js +133 -0
- package/package.json +57 -4
- package/plugin.json +22 -0
- package/scripts/claude-hook.mjs +49 -0
- package/scripts/handler.mjs +197 -0
- package/scripts/mcp-server.mjs +206 -0
- package/scripts/p-hook.mjs +117 -0
- package/scripts/p.mjs +141 -0
- package/scripts/prompt-manager.test.mjs +624 -0
- package/scripts/store.mjs +487 -0
- package/skills/p/SKILL.md +30 -0
|
@@ -0,0 +1,487 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import crypto from "node:crypto";
|
|
5
|
+
|
|
6
|
+
const STORE_VERSION = 1;
|
|
7
|
+
const PROTOTYPE_KEYS = new Set(["__proto__", "constructor", "prototype"]);
|
|
8
|
+
const RESERVED_COMMAND_IDS = new Set(["e", "d"]);
|
|
9
|
+
const RESERVED_IDS = new Set([...PROTOTYPE_KEYS, ...RESERVED_COMMAND_IDS]);
|
|
10
|
+
|
|
11
|
+
function expandHomePath(filePath) {
|
|
12
|
+
if (filePath === "~") {
|
|
13
|
+
return os.homedir();
|
|
14
|
+
}
|
|
15
|
+
if (filePath.startsWith("~/") || filePath.startsWith("~\\")) {
|
|
16
|
+
return path.join(os.homedir(), filePath.slice(2));
|
|
17
|
+
}
|
|
18
|
+
return filePath;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Resolve the persistent JSON file path used to store saved prompts.
|
|
23
|
+
* Order of precedence:
|
|
24
|
+
* 1. PROMPT_MANAGER_STORE_PATH (explicit file override, supports leading ~/)
|
|
25
|
+
* 2. ~/.prompt-manager/prompts.json if it already exists (shared default)
|
|
26
|
+
* 3. Existing tool-specific store if present (PLUGIN_DATA, CLAUDE_PLUGIN_DATA, ~/.gemini/config/prompt-manager/prompts.json)
|
|
27
|
+
* 4. ~/.prompt-manager/prompts.json (default for new stores)
|
|
28
|
+
*/
|
|
29
|
+
export function resolveStorePath() {
|
|
30
|
+
const explicit = process.env.PROMPT_MANAGER_STORE_PATH?.trim();
|
|
31
|
+
if (explicit) {
|
|
32
|
+
return path.resolve(expandHomePath(explicit));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const sharedDefault = path.join(os.homedir(), ".prompt-manager", "prompts.json");
|
|
36
|
+
if (fs.existsSync(sharedDefault)) {
|
|
37
|
+
return sharedDefault;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const candidates = [
|
|
41
|
+
process.env.PLUGIN_DATA?.trim() && path.join(process.env.PLUGIN_DATA.trim(), "prompts.json"),
|
|
42
|
+
process.env.CLAUDE_PLUGIN_DATA?.trim() && path.join(process.env.CLAUDE_PLUGIN_DATA.trim(), "prompts.json"),
|
|
43
|
+
path.join(os.homedir(), ".gemini", "config", "prompt-manager", "prompts.json"),
|
|
44
|
+
].filter(Boolean);
|
|
45
|
+
|
|
46
|
+
for (const candidate of candidates) {
|
|
47
|
+
if (fs.existsSync(candidate)) {
|
|
48
|
+
return candidate;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return sharedDefault;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function emptyStore() {
|
|
56
|
+
return { version: STORE_VERSION, prompts: Object.create(null) };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Load the prompt store from disk, returning an empty store if missing.
|
|
61
|
+
*/
|
|
62
|
+
export function loadStore(storePath = resolveStorePath()) {
|
|
63
|
+
if (!fs.existsSync(storePath)) {
|
|
64
|
+
return emptyStore();
|
|
65
|
+
}
|
|
66
|
+
const raw = fs.readFileSync(storePath, "utf8");
|
|
67
|
+
if (!raw.trim()) {
|
|
68
|
+
return emptyStore();
|
|
69
|
+
}
|
|
70
|
+
let parsed;
|
|
71
|
+
try {
|
|
72
|
+
parsed = JSON.parse(raw);
|
|
73
|
+
} catch (err) {
|
|
74
|
+
throw new Error(`Failed to parse prompt store at ${storePath}: ${err?.message || err}`);
|
|
75
|
+
}
|
|
76
|
+
if (
|
|
77
|
+
!parsed ||
|
|
78
|
+
typeof parsed !== "object" ||
|
|
79
|
+
Array.isArray(parsed) ||
|
|
80
|
+
!parsed.prompts ||
|
|
81
|
+
typeof parsed.prompts !== "object" ||
|
|
82
|
+
Array.isArray(parsed.prompts)
|
|
83
|
+
) {
|
|
84
|
+
throw new Error(`Invalid prompt store format in ${storePath}`);
|
|
85
|
+
}
|
|
86
|
+
const prompts = Object.create(null);
|
|
87
|
+
for (const [id, entry] of Object.entries(parsed.prompts)) {
|
|
88
|
+
if (PROTOTYPE_KEYS.has(id)) continue;
|
|
89
|
+
if (typeof entry === "string") {
|
|
90
|
+
prompts[id] = { text: entry };
|
|
91
|
+
} else if (entry && typeof entry === "object" && typeof entry.text === "string") {
|
|
92
|
+
prompts[id] = {
|
|
93
|
+
text: entry.text,
|
|
94
|
+
...(typeof entry.createdAt === "string" && entry.createdAt ? { createdAt: entry.createdAt } : {}),
|
|
95
|
+
...(typeof entry.updatedAt === "string" && entry.updatedAt ? { updatedAt: entry.updatedAt } : {}),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
version: typeof parsed.version === "number" ? parsed.version : STORE_VERSION,
|
|
101
|
+
prompts,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Atomically persist the prompt store to disk, cleaning up temp files on error
|
|
107
|
+
* and handling transient Windows file-locking errors on rename.
|
|
108
|
+
*/
|
|
109
|
+
export function saveStore(store, storePath = resolveStorePath()) {
|
|
110
|
+
const dir = path.dirname(storePath);
|
|
111
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
112
|
+
const tmpPath = path.join(dir, `.prompts.${process.pid}.${crypto.randomBytes(4).toString("hex")}.tmp`);
|
|
113
|
+
const plainPrompts = Object.create(null);
|
|
114
|
+
for (const [id, entry] of Object.entries(store.prompts)) {
|
|
115
|
+
if (!PROTOTYPE_KEYS.has(id)) {
|
|
116
|
+
plainPrompts[id] = entry;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const payload =
|
|
120
|
+
JSON.stringify(
|
|
121
|
+
{
|
|
122
|
+
version: STORE_VERSION,
|
|
123
|
+
prompts: plainPrompts,
|
|
124
|
+
},
|
|
125
|
+
null,
|
|
126
|
+
2,
|
|
127
|
+
) + "\n";
|
|
128
|
+
|
|
129
|
+
try {
|
|
130
|
+
fs.writeFileSync(tmpPath, payload, "utf8");
|
|
131
|
+
const maxAttempts = process.platform === "win32" ? 4 : 1;
|
|
132
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
133
|
+
try {
|
|
134
|
+
fs.renameSync(tmpPath, storePath);
|
|
135
|
+
return;
|
|
136
|
+
} catch (err) {
|
|
137
|
+
const retryable = err && (err.code === "EPERM" || err.code === "EBUSY" || err.code === "EACCES");
|
|
138
|
+
if (!retryable || attempt === maxAttempts) {
|
|
139
|
+
throw err;
|
|
140
|
+
}
|
|
141
|
+
// Synchronous brief backoff for transient Windows AV/indexer locks.
|
|
142
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 25 * attempt);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
} finally {
|
|
146
|
+
if (fs.existsSync(tmpPath)) {
|
|
147
|
+
try {
|
|
148
|
+
fs.unlinkSync(tmpPath);
|
|
149
|
+
} catch {
|
|
150
|
+
// Ignore cleanup failure.
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Validate a prompt ID.
|
|
158
|
+
*/
|
|
159
|
+
export function validatePromptId(id) {
|
|
160
|
+
if (typeof id !== "string" || !id.trim()) {
|
|
161
|
+
throw new Error("Prompt ID must be a non-empty string.");
|
|
162
|
+
}
|
|
163
|
+
if (/\s/.test(id)) {
|
|
164
|
+
throw new Error("Prompt ID cannot contain whitespace.");
|
|
165
|
+
}
|
|
166
|
+
if (/[\x00-\x1f\x7f]/.test(id)) {
|
|
167
|
+
throw new Error("Prompt ID cannot contain control characters.");
|
|
168
|
+
}
|
|
169
|
+
if (id === "e") {
|
|
170
|
+
throw new Error("Prompt ID cannot be 'e' because 'e' is reserved for editing/adding prompts.");
|
|
171
|
+
}
|
|
172
|
+
if (id === "d") {
|
|
173
|
+
throw new Error("Prompt ID cannot be 'd' because 'd' is reserved for deleting prompts.");
|
|
174
|
+
}
|
|
175
|
+
if (RESERVED_IDS.has(id)) {
|
|
176
|
+
throw new Error(`Prompt ID '${id}' is reserved.`);
|
|
177
|
+
}
|
|
178
|
+
return id;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Get a saved prompt entry by ID, or null if not found.
|
|
183
|
+
*/
|
|
184
|
+
export function getPrompt(id, storePath = resolveStorePath()) {
|
|
185
|
+
if (typeof id !== "string" || !id || PROTOTYPE_KEYS.has(id)) {
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
const store = loadStore(storePath);
|
|
189
|
+
if (!Object.hasOwn(store.prompts, id)) {
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
return { id, ...store.prompts[id] };
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Add or update a saved prompt entry.
|
|
197
|
+
*/
|
|
198
|
+
export function setPrompt(id, text, storePath = resolveStorePath()) {
|
|
199
|
+
const validId = validatePromptId(id);
|
|
200
|
+
if (typeof text !== "string" || !text.trim()) {
|
|
201
|
+
throw new Error("Prompt text must be a non-empty string.");
|
|
202
|
+
}
|
|
203
|
+
const store = loadStore(storePath);
|
|
204
|
+
const now = new Date().toISOString();
|
|
205
|
+
const hasExisting = Object.hasOwn(store.prompts, validId);
|
|
206
|
+
const existing = hasExisting ? store.prompts[validId] : null;
|
|
207
|
+
const entry = {
|
|
208
|
+
text,
|
|
209
|
+
createdAt: existing?.createdAt ?? now,
|
|
210
|
+
updatedAt: now,
|
|
211
|
+
};
|
|
212
|
+
store.prompts[validId] = entry;
|
|
213
|
+
saveStore(store, storePath);
|
|
214
|
+
return {
|
|
215
|
+
id: validId,
|
|
216
|
+
...entry,
|
|
217
|
+
created: !hasExisting,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Delete a saved prompt entry by ID. Returns true if it existed.
|
|
223
|
+
*/
|
|
224
|
+
export function deletePrompt(id, storePath = resolveStorePath()) {
|
|
225
|
+
if (typeof id !== "string" || !id || PROTOTYPE_KEYS.has(id)) {
|
|
226
|
+
return false;
|
|
227
|
+
}
|
|
228
|
+
const store = loadStore(storePath);
|
|
229
|
+
if (!Object.hasOwn(store.prompts, id)) {
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
delete store.prompts[id];
|
|
233
|
+
saveStore(store, storePath);
|
|
234
|
+
return true;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Return all saved prompts sorted naturally by ID.
|
|
239
|
+
*/
|
|
240
|
+
export function listPrompts(storePath = resolveStorePath()) {
|
|
241
|
+
const store = loadStore(storePath);
|
|
242
|
+
return Object.entries(store.prompts)
|
|
243
|
+
.map(([id, entry]) => ({ id, ...entry }))
|
|
244
|
+
.sort((a, b) => a.id.localeCompare(b.id, undefined, { numeric: true, sensitivity: "base" }));
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Unwrap a single outer pair of matching "..." or '...' quotes when the opening
|
|
249
|
+
* quote closes unescaped at the very last character of the trimmed string.
|
|
250
|
+
*/
|
|
251
|
+
export function unwrapQuotes(raw) {
|
|
252
|
+
const trimmed = raw.trim();
|
|
253
|
+
if (trimmed.length < 2) {
|
|
254
|
+
return trimmed;
|
|
255
|
+
}
|
|
256
|
+
const quote = trimmed[0];
|
|
257
|
+
if ((quote !== '"' && quote !== "'") || trimmed[trimmed.length - 1] !== quote) {
|
|
258
|
+
return trimmed;
|
|
259
|
+
}
|
|
260
|
+
let out = "";
|
|
261
|
+
let escaped = false;
|
|
262
|
+
for (let i = 1; i < trimmed.length; i++) {
|
|
263
|
+
const ch = trimmed[i];
|
|
264
|
+
if (escaped) {
|
|
265
|
+
if (ch === quote || ch === "\\") {
|
|
266
|
+
out += ch;
|
|
267
|
+
} else {
|
|
268
|
+
out += "\\" + ch;
|
|
269
|
+
}
|
|
270
|
+
escaped = false;
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
if (ch === "\\") {
|
|
274
|
+
escaped = true;
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
if (ch === quote) {
|
|
278
|
+
if (i === trimmed.length - 1) {
|
|
279
|
+
return out;
|
|
280
|
+
}
|
|
281
|
+
// Unescaped quote appeared before the end, so this is not one wrapped string.
|
|
282
|
+
return trimmed;
|
|
283
|
+
}
|
|
284
|
+
out += ch;
|
|
285
|
+
}
|
|
286
|
+
// Closing quote was escaped (or dangling backslash), so keep original string.
|
|
287
|
+
return trimmed;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Consume the next whitespace-delimited (or quoted) token from text.
|
|
292
|
+
* Returns { token, rest } or null if empty.
|
|
293
|
+
*/
|
|
294
|
+
function consumeToken(input) {
|
|
295
|
+
const s = input.trimStart();
|
|
296
|
+
if (!s) {
|
|
297
|
+
return null;
|
|
298
|
+
}
|
|
299
|
+
const first = s[0];
|
|
300
|
+
if (first === '"' || first === "'") {
|
|
301
|
+
let token = "";
|
|
302
|
+
let escaped = false;
|
|
303
|
+
for (let i = 1; i < s.length; i++) {
|
|
304
|
+
const ch = s[i];
|
|
305
|
+
if (escaped) {
|
|
306
|
+
token += ch === first || ch === "\\" ? ch : "\\" + ch;
|
|
307
|
+
escaped = false;
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
if (ch === "\\") {
|
|
311
|
+
escaped = true;
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
if (ch === first) {
|
|
315
|
+
const after = s.slice(i + 1);
|
|
316
|
+
if (!after || /^\s/.test(after)) {
|
|
317
|
+
return { token, rest: after.replace(/^\s+/, "") };
|
|
318
|
+
}
|
|
319
|
+
break;
|
|
320
|
+
}
|
|
321
|
+
token += ch;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
const match = s.match(/^(\S+)(?:\s+([\s\S]*))?$/);
|
|
325
|
+
if (!match) {
|
|
326
|
+
return null;
|
|
327
|
+
}
|
|
328
|
+
return {
|
|
329
|
+
token: match[1],
|
|
330
|
+
rest: match[2] ?? "",
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Check whether the current script module was executed directly as the Node entrypoint,
|
|
336
|
+
* safely normalizing symlinks, relative paths, and Windows drive-letter casing.
|
|
337
|
+
*/
|
|
338
|
+
export function isDirectEntrypoint(importMetaUrl, argvPath = process.argv[1], fileURLToPathFn) {
|
|
339
|
+
if (!argvPath) {
|
|
340
|
+
return false;
|
|
341
|
+
}
|
|
342
|
+
try {
|
|
343
|
+
const modulePath = fs.realpathSync(fileURLToPathFn(importMetaUrl));
|
|
344
|
+
const entryPath = fs.realpathSync(path.resolve(argvPath));
|
|
345
|
+
if (process.platform === "win32") {
|
|
346
|
+
return modulePath.toLowerCase() === entryPath.toLowerCase();
|
|
347
|
+
}
|
|
348
|
+
return modulePath === entryPath;
|
|
349
|
+
} catch {
|
|
350
|
+
return false;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function validateSlashIdToken(token, allowLegacyCommandId = false) {
|
|
355
|
+
if (!token || !token.trim()) {
|
|
356
|
+
return { code: "INVALID_ID", message: "Prompt ID cannot be empty." };
|
|
357
|
+
}
|
|
358
|
+
if (/\s/.test(token)) {
|
|
359
|
+
return { code: "INVALID_ID", message: "Prompt ID cannot contain whitespace." };
|
|
360
|
+
}
|
|
361
|
+
if (/[\x00-\x1f\x7f]/.test(token)) {
|
|
362
|
+
return { code: "INVALID_ID", message: "Prompt ID cannot contain control characters." };
|
|
363
|
+
}
|
|
364
|
+
if (PROTOTYPE_KEYS.has(token) || (!allowLegacyCommandId && RESERVED_IDS.has(token))) {
|
|
365
|
+
let message = `Prompt ID '${token}' is reserved.`;
|
|
366
|
+
if (token === "e") {
|
|
367
|
+
message = "Prompt ID cannot be 'e' because 'e' is reserved for editing/adding prompts.";
|
|
368
|
+
} else if (token === "d") {
|
|
369
|
+
message = "Prompt ID cannot be 'd' because 'd' is reserved for deleting prompts.";
|
|
370
|
+
}
|
|
371
|
+
return { code: "RESERVED_ID", message };
|
|
372
|
+
}
|
|
373
|
+
return null;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* Parse a user slash command starting with /p (or /prompt-manager:p).
|
|
378
|
+
* Returns null if the input is not a /p command.
|
|
379
|
+
*/
|
|
380
|
+
export function parseSlashCommand(input) {
|
|
381
|
+
if (typeof input !== "string") {
|
|
382
|
+
return null;
|
|
383
|
+
}
|
|
384
|
+
const match = input.trimStart().match(/^\/(?:prompt-manager:)?p(?:\s+([\s\S]*))?$/);
|
|
385
|
+
if (!match) {
|
|
386
|
+
return null;
|
|
387
|
+
}
|
|
388
|
+
const body = (match[1] ?? "").trimStart();
|
|
389
|
+
if (!body) {
|
|
390
|
+
return { action: "list" };
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
const first = consumeToken(body);
|
|
394
|
+
if (!first) {
|
|
395
|
+
return { action: "list" };
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
if (first.token === "e") {
|
|
399
|
+
const idToken = consumeToken(first.rest);
|
|
400
|
+
if (!idToken) {
|
|
401
|
+
return {
|
|
402
|
+
action: "error",
|
|
403
|
+
code: "MISSING_ID",
|
|
404
|
+
message: "Missing prompt ID and text. Usage: /p e <saved_prompt_ID> <text>",
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
const idErr = validateSlashIdToken(idToken.token);
|
|
408
|
+
if (idErr) {
|
|
409
|
+
return {
|
|
410
|
+
action: "error",
|
|
411
|
+
code: idErr.code,
|
|
412
|
+
id: idToken.token,
|
|
413
|
+
message: idErr.message,
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
if (!idToken.rest || !idToken.rest.trim()) {
|
|
417
|
+
return {
|
|
418
|
+
action: "error",
|
|
419
|
+
code: "MISSING_TEXT",
|
|
420
|
+
id: idToken.token,
|
|
421
|
+
message: `Missing prompt text for ID '${idToken.token}'. Usage: /p e ${idToken.token} "<text>"`,
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
const text = unwrapQuotes(idToken.rest);
|
|
425
|
+
if (!text.trim()) {
|
|
426
|
+
return {
|
|
427
|
+
action: "error",
|
|
428
|
+
code: "EMPTY_TEXT",
|
|
429
|
+
id: idToken.token,
|
|
430
|
+
message: `Prompt text for ID '${idToken.token}' cannot be empty.`,
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
return {
|
|
434
|
+
action: "edit",
|
|
435
|
+
id: idToken.token,
|
|
436
|
+
text,
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
if (first.token === "d") {
|
|
441
|
+
const idToken = consumeToken(first.rest);
|
|
442
|
+
if (!idToken) {
|
|
443
|
+
return {
|
|
444
|
+
action: "error",
|
|
445
|
+
code: "MISSING_ID",
|
|
446
|
+
message: "Missing prompt ID. Usage: /p d <saved_prompt_ID>",
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
const idErr = validateSlashIdToken(idToken.token, true);
|
|
450
|
+
if (idErr) {
|
|
451
|
+
return {
|
|
452
|
+
action: "error",
|
|
453
|
+
code: idErr.code,
|
|
454
|
+
id: idToken.token,
|
|
455
|
+
message: idErr.message,
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
if (idToken.rest && idToken.rest.trim()) {
|
|
459
|
+
return {
|
|
460
|
+
action: "error",
|
|
461
|
+
code: "UNEXPECTED_ARGS",
|
|
462
|
+
id: idToken.token,
|
|
463
|
+
message: `Unexpected extra arguments after ID '${idToken.token}'. Usage: /p d ${idToken.token}`,
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
return {
|
|
467
|
+
action: "delete",
|
|
468
|
+
id: idToken.token,
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
const sendErr = validateSlashIdToken(first.token, true);
|
|
473
|
+
if (sendErr) {
|
|
474
|
+
return {
|
|
475
|
+
action: "error",
|
|
476
|
+
code: sendErr.code,
|
|
477
|
+
id: first.token,
|
|
478
|
+
message: sendErr.message,
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
return {
|
|
483
|
+
action: "send",
|
|
484
|
+
id: first.token,
|
|
485
|
+
extra: first.rest.trim(),
|
|
486
|
+
};
|
|
487
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: p
|
|
3
|
+
description: >-
|
|
4
|
+
Manage and send saved prompt instructions by ID via /p <id> and
|
|
5
|
+
/p e <id> <text>. Use only when explicitly invoked as /p.
|
|
6
|
+
disable-model-invocation: true
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Prompt Manager (`/p`)
|
|
10
|
+
|
|
11
|
+
This skill registers the `/p` slash command (namespaced as `/prompt-manager:p` in
|
|
12
|
+
Antigravity and Claude Code). A pre-turn hook (`PreInvocation` in Antigravity,
|
|
13
|
+
`UserPromptSubmit` in Claude Code, or `command.execute.before`/`chat.message` in
|
|
14
|
+
OpenCode) handles `/p` deterministically before model execution.
|
|
15
|
+
|
|
16
|
+
## Behavior
|
|
17
|
+
|
|
18
|
+
1. **If a hook message (`Prompt Manager ...`, `<prompt-manager-hook>`, or `[Prompt Manager]`) is already present in this turn:**
|
|
19
|
+
Follow that hook output directly:
|
|
20
|
+
- For `/p e <id> <text>` (save/edit), confirm the save briefly without executing `<text>`.
|
|
21
|
+
- For `/p <id>` (send), follow the injected resolved instruction directly.
|
|
22
|
+
- For `/p` (list), `/p e <id>` (inspect), `/p d <id>` (delete), or errors/missing IDs, report the hook message and stop.
|
|
23
|
+
|
|
24
|
+
2. **Fallback (only if no hook handled this turn):**
|
|
25
|
+
Use the bundled `prompts` MCP tools (`list_prompts`, `get_prompt`, `save_prompt`, `delete_prompt`):
|
|
26
|
+
- `/p` (no arguments): call `list_prompts` and display saved IDs, previews, and usage (`/p <id>`, `/p e <id> <text>`, `/p e <id>`, `/p d <id>`).
|
|
27
|
+
- `/p e <id> <text>`: call `save_prompt` with `id` and `text`, then confirm the save without executing `<text>`.
|
|
28
|
+
- `/p e <id>` (no `<text>`): call `get_prompt` for `id` to show the current saved text (if any) and edit/delete usage.
|
|
29
|
+
- `/p d <id>`: call `delete_prompt` for `id` and confirm deletion (or report not found).
|
|
30
|
+
- `/p <id>` (first argument is not `e` or `d`): call `get_prompt` for `id`. If found, follow the returned `text` as the user's instruction; if not found, list available IDs with `list_prompts` and show `/p e <id> "<text>"`.
|