@americanumberoneaokgoodtimes/p-plugin 0.0.0-stage → 1.0.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/.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 +24 -0
- package/opencode/plugin.js +158 -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 +642 -0
- package/scripts/store.mjs +487 -0
- package/skills/p/SKILL.md +30 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://antigravity.google/schemas/v1/plugin.json",
|
|
3
|
+
"name": "prompt-manager",
|
|
4
|
+
"displayName": "Prompt Manager",
|
|
5
|
+
"version": "1.0.0",
|
|
6
|
+
"description": "Save, edit, and trigger reusable prompt instructions by ID using /p <id> and /p e <id> <text>.",
|
|
7
|
+
"logo": "assets/logo.svg",
|
|
8
|
+
"repository": "https://github.com/americanumberoneaokgoodtimes/prompt-manager-plugin-opencode-claude-agy-etc",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"keywords": [
|
|
11
|
+
"prompts",
|
|
12
|
+
"instructions",
|
|
13
|
+
"macros",
|
|
14
|
+
"shortcuts",
|
|
15
|
+
"productivity"
|
|
16
|
+
],
|
|
17
|
+
"suggestedPrompts": [
|
|
18
|
+
"/p",
|
|
19
|
+
"List my saved prompts",
|
|
20
|
+
"Explain how to save and run prompts with /p"
|
|
21
|
+
]
|
|
22
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "prompt-manager",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Save, edit, and trigger reusable prompt instructions by ID using /p <id> and /p e <id> <text>.",
|
|
5
|
+
"repository": "https://github.com/americanumberoneaokgoodtimes/prompt-manager-plugin-opencode-claude-agy-etc",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"prompts",
|
|
9
|
+
"instructions",
|
|
10
|
+
"macros",
|
|
11
|
+
"shortcuts",
|
|
12
|
+
"productivity"
|
|
13
|
+
]
|
|
14
|
+
}
|
package/.mcp.json
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,324 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Prompt Manager for agentic coding harness platforms (`p-plugin`)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A prompt manager plugin for **Antigravity**, **Claude Code**, and **OpenCode** that lets you save, edit, list, and send reusable prompt instructions (templates) by ID using `/p <id>` and edit using `/p e <id> <text>`.
|
|
4
|
+
|
|
5
|
+
Built with zero external runtime dependencies (Node.js `>= 18`), it pairs deterministic pre-model hook interception with a `SKILL.md` slash command, a stdio MCP server, and a standalone CLI.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Table of Contents
|
|
10
|
+
|
|
11
|
+
- [Requirements](#requirements)
|
|
12
|
+
- [Installation](#installation)
|
|
13
|
+
- [Antigravity (App, CLI, IDE)](#antigravity-app-cli-ide)
|
|
14
|
+
- [Claude Code](#claude-code)
|
|
15
|
+
- [OpenCode](#opencode)
|
|
16
|
+
- [Usage](#usage)
|
|
17
|
+
- [Save or Edit a Prompt (`/p e <id> <text>`)](#save-or-edit-a-prompt-p-e-id-text)
|
|
18
|
+
- [Inspect a Saved Prompt (`/p e <id>`)](#inspect-a-saved-prompt-p-e-id)
|
|
19
|
+
- [Send a Saved Prompt (`/p <id>`)](#send-a-saved-prompt-p-id)
|
|
20
|
+
- [Delete a Saved Prompt (`/p d <id>`)](#delete-a-saved-prompt-p-d-id)
|
|
21
|
+
- [List Saved Prompts (`/p`)](#list-saved-prompts-p)
|
|
22
|
+
- [Manage Prompts via Natural Language (MCP Tools)](#manage-prompts-via-natural-language-mcp-tools)
|
|
23
|
+
- [Standalone CLI (`scripts/p.mjs`)](#standalone-cli-scriptspmjs)
|
|
24
|
+
- [Storage & Cross-Tool Sync](#storage--cross-tool-sync)
|
|
25
|
+
- [Testing & Validation](#testing--validation)
|
|
26
|
+
- [Troubleshooting](#troubleshooting)
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Requirements
|
|
31
|
+
|
|
32
|
+
- **Node.js `>= 18`** available on your `PATH` as `node`.
|
|
33
|
+
- No `npm install` step is required.
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## Installation
|
|
38
|
+
|
|
39
|
+
### Antigravity (App, CLI, IDE)
|
|
40
|
+
|
|
41
|
+
#### Option 1: Install globally from a local clone
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
git clone https://github.com/americanumberoneaokgoodtimes/prompt-manager-plugin-opencode-claude-agy-etc.git agy-plugin-p
|
|
45
|
+
agy plugin install ./agy-plugin-p
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
On Windows PowerShell:
|
|
49
|
+
|
|
50
|
+
```powershell
|
|
51
|
+
agy plugin install C:\path\to\agy-plugin-p
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
#### Option 2: Install directly from GitHub
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
agy plugin install https://github.com/americanumberoneaokgoodtimes/prompt-manager-plugin-opencode-claude-agy-etc
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
#### Option 3: Load per-workspace (without global install)
|
|
61
|
+
|
|
62
|
+
Copy or symlink the repository into `.agents/plugins/prompt-manager` inside any project workspace.
|
|
63
|
+
|
|
64
|
+
#### Verify & manage in Antigravity
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
agy plugin validate ./agy-plugin-p
|
|
68
|
+
agy plugin list
|
|
69
|
+
agy plugin enable prompt-manager
|
|
70
|
+
agy plugin disable prompt-manager
|
|
71
|
+
agy plugin uninstall prompt-manager
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Inside an interactive Antigravity CLI session, run `/skills` (or `/skills reload`) to confirm `/p` is loaded, `/hooks` to inspect the `PreInvocation` hook, and `/mcp` to see the `prompts` MCP server.
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
### Claude Code
|
|
79
|
+
|
|
80
|
+
This repository includes `.claude-plugin/plugin.json`, `hooks/hooks.json` (`UserPromptSubmit`), `.mcp.json`, and `skills/p/SKILL.md`.
|
|
81
|
+
|
|
82
|
+
> **Note:** Claude Code namespaces plugin skills as `/prompt-manager:p` in the slash-command menu (both `/p ...` and `/prompt-manager:p ...` are handled by the `UserPromptSubmit` hook).
|
|
83
|
+
|
|
84
|
+
#### Option 1: Install as a plugin
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
claude plugin install /path/to/agy-plugin-p
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Or inside Claude Code chat:
|
|
91
|
+
|
|
92
|
+
```text
|
|
93
|
+
/plugin install /path/to/agy-plugin-p
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
#### Option 2: Load for a single session
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
claude --plugin-dir /path/to/agy-plugin-p
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
### OpenCode
|
|
105
|
+
|
|
106
|
+
This repository exports the OpenCode plugin from `package.json` and `opencode/plugin.js`, registering `/p`, `command.execute.before`, `chat.message`, and the local `prompt-manager` MCP server automatically.
|
|
107
|
+
|
|
108
|
+
#### Option 1: Install via `opencode plugin add` (recommended)
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
opencode plugin add @americanumberoneaokgoodtimes/p-plugin
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
#### Option 2: Reference in `opencode.json`
|
|
115
|
+
|
|
116
|
+
Add `@americanumberoneaokgoodtimes/p-plugin` to `~/.config/opencode/opencode.json` (global) or `./opencode.json` (project):
|
|
117
|
+
|
|
118
|
+
```json
|
|
119
|
+
{
|
|
120
|
+
"$schema": "https://opencode.ai/config.json",
|
|
121
|
+
"plugin": [
|
|
122
|
+
"@americanumberoneaokgoodtimes/p-plugin"
|
|
123
|
+
]
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
#### Option 3: Reference local file path URL
|
|
128
|
+
|
|
129
|
+
Add the plugin file URL to `~/.config/opencode/opencode.json` (global) or `./opencode.json` (project):
|
|
130
|
+
|
|
131
|
+
macOS / Linux:
|
|
132
|
+
|
|
133
|
+
```json
|
|
134
|
+
{
|
|
135
|
+
"$schema": "https://opencode.ai/config.json",
|
|
136
|
+
"plugin": [
|
|
137
|
+
"file:///path/to/agy-plugin-p/opencode/plugin.js"
|
|
138
|
+
]
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Windows:
|
|
143
|
+
|
|
144
|
+
```json
|
|
145
|
+
{
|
|
146
|
+
"$schema": "https://opencode.ai/config.json",
|
|
147
|
+
"plugin": [
|
|
148
|
+
"file:///C:/path/to/agy-plugin-p/opencode/plugin.js"
|
|
149
|
+
]
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
## Usage
|
|
156
|
+
|
|
157
|
+
### Save or Edit a Prompt (`/p e <id> <text>`)
|
|
158
|
+
|
|
159
|
+
Use `e` as the first argument to add a new prompt or overwrite an existing one:
|
|
160
|
+
|
|
161
|
+
```text
|
|
162
|
+
/p e 1 "begin doing the things you do best, but only if you think it's the best thing to do. Begin if you think you're ready, and if not then ask me about it for more information"
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
- **ID rules**: `<saved_prompt_ID>` can be numeric (`1`, `2`) or named (`review`, `plan-api`), cannot contain whitespace, and cannot be `e` (reserved for edit/inspect) or `d` (reserved for delete).
|
|
166
|
+
- **Quoting**: Outer matching `"..."` or `'...'` quotes are stripped (with `\"` / `\'` / `\\` unescaped). Unquoted multi-word text and multi-line prompts are also preserved:
|
|
167
|
+
```text
|
|
168
|
+
/p e review Review staged git changes for bugs, edge cases, and missing tests
|
|
169
|
+
```
|
|
170
|
+
- **Safe save behavior**: Saving confirms that the ID was stored or updated **without** executing the saved text as an instruction.
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
### Inspect a Saved Prompt (`/p e <id>`)
|
|
175
|
+
|
|
176
|
+
Run `/p e <id>` (with no text) to view the full saved text for `<id>` before overwriting or deleting it:
|
|
177
|
+
|
|
178
|
+
```text
|
|
179
|
+
/p e 1
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
### Send a Saved Prompt (`/p <id>`)
|
|
185
|
+
|
|
186
|
+
Pass any saved ID (other than `e` or `d`) as the first argument to expand and send that saved instruction to the agent:
|
|
187
|
+
|
|
188
|
+
```text
|
|
189
|
+
/p 1
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
You can also append extra per-turn context after the ID:
|
|
193
|
+
|
|
194
|
+
```text
|
|
195
|
+
/p review focus on src/auth/session.ts
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
- If the ID exists, the stored instruction is sent to the model (with any trailing text appended).
|
|
199
|
+
- If the ID does not exist, the hook reports that it was not found, lists currently saved IDs, and shows how to create it with `/p e <id> "<text>"`.
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
### Delete a Saved Prompt (`/p d <id>`)
|
|
204
|
+
|
|
205
|
+
Use `d` as the first argument to remove a saved prompt by ID:
|
|
206
|
+
|
|
207
|
+
```text
|
|
208
|
+
/p d 1
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
### List Saved Prompts (`/p`)
|
|
214
|
+
|
|
215
|
+
Run `/p` with no arguments to view all saved prompt IDs, previews, and command syntax:
|
|
216
|
+
|
|
217
|
+
```text
|
|
218
|
+
/p
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
### Manage Prompts via Natural Language (MCP Tools)
|
|
224
|
+
|
|
225
|
+
When the bundled MCP server (`prompts` in Antigravity/Claude Code, `prompt-manager` in OpenCode) is active, you can also manage prompts conversationally:
|
|
226
|
+
|
|
227
|
+
- *"List my saved prompts"* → calls `list_prompts`
|
|
228
|
+
- *"Show the full text of saved prompt `1`"* → calls `get_prompt`
|
|
229
|
+
- *"Save a prompt under ID `docs` to write concise JSDoc comments"* → calls `save_prompt`
|
|
230
|
+
- *"Delete saved prompt `1`"* → calls `delete_prompt`
|
|
231
|
+
|
|
232
|
+
---
|
|
233
|
+
|
|
234
|
+
### Standalone CLI (`scripts/p.mjs`)
|
|
235
|
+
|
|
236
|
+
You can manage your prompt store directly from any terminal (or via `p` if linked with `npm link`):
|
|
237
|
+
|
|
238
|
+
```bash
|
|
239
|
+
# List all saved prompts (add --json for JSON output)
|
|
240
|
+
node scripts/p.mjs list
|
|
241
|
+
|
|
242
|
+
# Print a saved prompt by ID (add --json for metadata + timestamps)
|
|
243
|
+
node scripts/p.mjs get 1
|
|
244
|
+
|
|
245
|
+
# Add or update a prompt (or pipe stdin / pass --stdin for multi-line text)
|
|
246
|
+
node scripts/p.mjs set 1 "Check every edge case carefully"
|
|
247
|
+
cat prompt.txt | node scripts/p.mjs set 1
|
|
248
|
+
|
|
249
|
+
# Delete a prompt
|
|
250
|
+
node scripts/p.mjs delete 1
|
|
251
|
+
|
|
252
|
+
# Print the active prompt store path
|
|
253
|
+
node scripts/p.mjs path
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
---
|
|
257
|
+
|
|
258
|
+
## Storage & Cross-Tool Sync
|
|
259
|
+
|
|
260
|
+
Prompts are stored atomically as JSON (`{ "version": 1, "prompts": { ... } }`). The store path is resolved in this order:
|
|
261
|
+
|
|
262
|
+
1. `PROMPT_MANAGER_STORE_PATH` — explicit file path override (supports leading `~/`)
|
|
263
|
+
2. `~/.prompt-manager/prompts.json` — shared default across Antigravity, Claude Code, OpenCode, and `scripts/p.mjs` (used if already present)
|
|
264
|
+
3. Existing legacy/tool store if present (`${PLUGIN_DATA}/prompts.json`, `${CLAUDE_PLUGIN_DATA}/prompts.json`, or `~/.gemini/config/prompt-manager/prompts.json`)
|
|
265
|
+
4. `~/.prompt-manager/prompts.json` — default location when creating a new store
|
|
266
|
+
|
|
267
|
+
### Overriding the storage location
|
|
268
|
+
|
|
269
|
+
Set `PROMPT_MANAGER_STORE_PATH` in your shell/environment if you want to store your prompt library in a custom location (such as a synced dotfiles repo):
|
|
270
|
+
|
|
271
|
+
macOS / Linux (`~/.zshrc` or `~/.bashrc`):
|
|
272
|
+
|
|
273
|
+
```bash
|
|
274
|
+
export PROMPT_MANAGER_STORE_PATH="$HOME/.config/prompt-manager/prompts.json"
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
Windows PowerShell (`$PROFILE`):
|
|
278
|
+
|
|
279
|
+
```powershell
|
|
280
|
+
$env:PROMPT_MANAGER_STORE_PATH = "$HOME\.config\prompt-manager\prompts.json"
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
Example `prompts.json` format:
|
|
284
|
+
|
|
285
|
+
```json
|
|
286
|
+
{
|
|
287
|
+
"version": 1,
|
|
288
|
+
"prompts": {
|
|
289
|
+
"1": {
|
|
290
|
+
"text": "begin doing the things you do best, but only if you think it's the best thing to do.",
|
|
291
|
+
"createdAt": "2026-11-24T22:49:09.340Z",
|
|
292
|
+
"updatedAt": "2026-11-24T22:49:09.340Z"
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
---
|
|
299
|
+
|
|
300
|
+
## Testing & Validation
|
|
301
|
+
|
|
302
|
+
Run the unit and integration test suite:
|
|
303
|
+
|
|
304
|
+
```bash
|
|
305
|
+
npm test
|
|
306
|
+
# or directly:
|
|
307
|
+
node --test scripts/prompt-manager.test.mjs
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
Validate the Antigravity plugin bundle:
|
|
311
|
+
|
|
312
|
+
```bash
|
|
313
|
+
agy plugin validate .
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
> **Note on multi-tool validation warnings:** When running `agy plugin validate .`, Antigravity reports `0` errors and `3` expected warnings for files belonging to Claude Code or shadowed by `.antigravity-plugin/plugin.json` (`.mcp.json`, `hooks/hooks.json`, and root `plugin.json`).
|
|
317
|
+
|
|
318
|
+
---
|
|
319
|
+
|
|
320
|
+
## Troubleshooting
|
|
321
|
+
|
|
322
|
+
- **`/p` does not appear in autocomplete**: Restart your session, or in Antigravity CLI run `/skills reload`. Verify the plugin is enabled via `agy plugin list`.
|
|
323
|
+
- **Prompts saved in Antigravity don't appear in Claude Code / OpenCode (or vice versa)**: Set `PROMPT_MANAGER_STORE_PATH` globally so all three tools point to the same JSON file.
|
|
324
|
+
- **Hook fails silently or does not intercept**: Confirm `node --version` outputs `v18` or newer and `node` is on your non-interactive `PATH`.
|
package/assets/logo.svg
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128" width="128" height="128" fill="none">
|
|
2
|
+
<rect x="14" y="14" width="100" height="100" rx="22" fill="#1E293B" stroke="#38BDF8" stroke-width="5"/>
|
|
3
|
+
<path d="M36 44L54 64L36 84" stroke="#38BDF8" stroke-width="8" stroke-linecap="round" stroke-linejoin="round"/>
|
|
4
|
+
<path d="M62 84H92" stroke="#F8FAFC" stroke-width="8" stroke-linecap="round"/>
|
|
5
|
+
<path d="M72 44H92M82 34V54" stroke="#F59E0B" stroke-width="7" stroke-linecap="round"/>
|
|
6
|
+
</svg>
|
package/hooks/hooks.json
ADDED
package/hooks.json
ADDED
package/mcp_config.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface PromptManagerPluginHooks {
|
|
2
|
+
config: (config: Record<string, any>) => Promise<void>;
|
|
3
|
+
"command.execute.before": (
|
|
4
|
+
input: { sessionID?: string; command: string; arguments?: string },
|
|
5
|
+
output: { parts?: Array<{ type: string; text?: string; [key: string]: unknown }> },
|
|
6
|
+
) => Promise<void>;
|
|
7
|
+
"chat.message": (
|
|
8
|
+
input: { sessionID?: string; messageID?: string; [key: string]: unknown },
|
|
9
|
+
output: { message?: unknown; parts: Array<{ type: string; text?: string; [key: string]: unknown }> },
|
|
10
|
+
) => Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export declare const createPromptManagerHooks: (ctx: unknown) => Promise<PromptManagerPluginHooks>;
|
|
14
|
+
export declare const PromptManagerPlugin: (ctx: unknown) => Promise<PromptManagerPluginHooks>;
|
|
15
|
+
|
|
16
|
+
export interface OpenCodePluginDefinition {
|
|
17
|
+
id: string;
|
|
18
|
+
name?: string;
|
|
19
|
+
description?: string;
|
|
20
|
+
setup: (ctx: unknown) => Promise<PromptManagerPluginHooks>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export declare const plugin: OpenCodePluginDefinition;
|
|
24
|
+
export default plugin;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { executePromptCommand } from "../scripts/handler.mjs";
|
|
4
|
+
import { resolveStorePath } from "../scripts/store.mjs";
|
|
5
|
+
|
|
6
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
const MCP_SERVER_PATH = path.resolve(__dirname, "..", "scripts", "mcp-server.mjs");
|
|
8
|
+
|
|
9
|
+
function extractTextFromParts(parts) {
|
|
10
|
+
if (!Array.isArray(parts)) {
|
|
11
|
+
return "";
|
|
12
|
+
}
|
|
13
|
+
return parts
|
|
14
|
+
.filter((p) => p && p.type === "text" && typeof p.text === "string")
|
|
15
|
+
.map((p) => p.text)
|
|
16
|
+
.join("\n");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function replaceTextInParts(parts, newText) {
|
|
20
|
+
if (!Array.isArray(parts) || parts.length === 0) {
|
|
21
|
+
return [{ type: "text", text: newText }];
|
|
22
|
+
}
|
|
23
|
+
const firstTextIdx = parts.findIndex((p) => p && p.type === "text");
|
|
24
|
+
if (firstTextIdx === -1) {
|
|
25
|
+
return [{ type: "text", text: newText }, ...parts];
|
|
26
|
+
}
|
|
27
|
+
const updatedFirst = { ...parts[firstTextIdx], type: "text", text: newText };
|
|
28
|
+
const nextParts = [];
|
|
29
|
+
for (let i = 0; i < parts.length; i++) {
|
|
30
|
+
if (i === firstTextIdx) {
|
|
31
|
+
nextParts.push(updatedFirst);
|
|
32
|
+
} else if (parts[i]?.type !== "text") {
|
|
33
|
+
// Keep non-text attachments while dropping redundant text fragments.
|
|
34
|
+
nextParts.push(parts[i]);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return nextParts;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function replacementForResult(result) {
|
|
41
|
+
if (result.action === "send" && result.found) {
|
|
42
|
+
return result.resolvedInstruction;
|
|
43
|
+
}
|
|
44
|
+
return `[Prompt Manager]\n${result.systemInstruction}`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* OpenCode plugin hook factory.
|
|
49
|
+
*/
|
|
50
|
+
export const createPromptManagerHooks = async (_ctx) => {
|
|
51
|
+
const recentlyHandled = new Map();
|
|
52
|
+
const DEDUP_TTL_MS = 5000;
|
|
53
|
+
|
|
54
|
+
function pruneExpired(now) {
|
|
55
|
+
for (const [k, entry] of recentlyHandled.entries()) {
|
|
56
|
+
if (now - entry.at > DEDUP_TTL_MS) {
|
|
57
|
+
recentlyHandled.delete(k);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function markHandled(sessionID, text) {
|
|
63
|
+
const now = Date.now();
|
|
64
|
+
pruneExpired(now);
|
|
65
|
+
const key = sessionID || "__default__";
|
|
66
|
+
recentlyHandled.set(key, { text, at: now });
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function wasJustHandled(sessionID, text) {
|
|
70
|
+
const now = Date.now();
|
|
71
|
+
pruneExpired(now);
|
|
72
|
+
const key = sessionID || "__default__";
|
|
73
|
+
const entry = recentlyHandled.get(key);
|
|
74
|
+
if (!entry) return false;
|
|
75
|
+
if (entry.text === text) {
|
|
76
|
+
recentlyHandled.delete(key);
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
config: async (config) => {
|
|
84
|
+
config.command = config.command || {};
|
|
85
|
+
if (!config.command.p) {
|
|
86
|
+
config.command.p = {
|
|
87
|
+
description: "Save, edit, inspect, delete, list, or send reusable prompts (/p <id>, /p e <id> <text>, /p d <id>)",
|
|
88
|
+
template: "/p $ARGUMENTS",
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
config.mcp = config.mcp || {};
|
|
92
|
+
if (!config.mcp["prompt-manager"]) {
|
|
93
|
+
config.mcp["prompt-manager"] = {
|
|
94
|
+
type: "local",
|
|
95
|
+
command: ["node", MCP_SERVER_PATH],
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
"command.execute.before": async (input, output) => {
|
|
101
|
+
const commandName = typeof input?.command === "string" ? input.command.replace(/^\/+/, "") : "";
|
|
102
|
+
if (commandName !== "p" && commandName !== "prompt-manager:p") {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const args = typeof input.arguments === "string" ? input.arguments.trim() : "";
|
|
106
|
+
const rawCommand = args ? `/p ${args}` : "/p";
|
|
107
|
+
const result = executePromptCommand(rawCommand, resolveStorePath());
|
|
108
|
+
if (!result) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const replacement = replacementForResult(result);
|
|
112
|
+
output.parts = replaceTextInParts(output.parts, replacement);
|
|
113
|
+
markHandled(input.sessionID, replacement);
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
"chat.message": async (input, output) => {
|
|
117
|
+
if (!output || !Array.isArray(output.parts)) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const text = extractTextFromParts(output.parts);
|
|
121
|
+
if (wasJustHandled(input?.sessionID, text)) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const result = executePromptCommand(text, resolveStorePath());
|
|
125
|
+
if (!result) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
output.parts = replaceTextInParts(output.parts, replacementForResult(result));
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* OpenCode v1 function-style plugin entrypoint.
|
|
135
|
+
*/
|
|
136
|
+
export const PromptManagerPlugin = async (ctx) => {
|
|
137
|
+
return await createPromptManagerHooks(ctx);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* OpenCode v2 definition object.
|
|
142
|
+
* OpenCode v2 requires the default export to be an object with an `id` string
|
|
143
|
+
* and a `setup` (or `effect`) function:
|
|
144
|
+
* Schema.Union([
|
|
145
|
+
* Schema.Struct({ id: Schema.String, setup: Schema.Function }),
|
|
146
|
+
* Schema.Struct({ id: Schema.String, effect: Schema.Function })
|
|
147
|
+
* ])
|
|
148
|
+
*/
|
|
149
|
+
export const plugin = {
|
|
150
|
+
id: "@americanumberoneaokgoodtimes/p-plugin",
|
|
151
|
+
name: "prompt-manager",
|
|
152
|
+
description: "Prompt Manager plugin for OpenCode (/p)",
|
|
153
|
+
setup: async (ctx) => {
|
|
154
|
+
return await createPromptManagerHooks(ctx);
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
export default plugin;
|
package/package.json
CHANGED
|
@@ -1,6 +1,59 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@americanumberoneaokgoodtimes/p-plugin",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Multi-tool Prompt Manager plugin for Antigravity, Claude Code, and OpenCode (/p <id>, /p e <id> <text>, /p d <id>).",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"bin": {
|
|
10
|
+
"p": "./scripts/p.mjs"
|
|
11
|
+
},
|
|
12
|
+
"main": "./opencode/plugin.js",
|
|
13
|
+
"types": "./opencode/plugin.d.ts",
|
|
14
|
+
"files": [
|
|
15
|
+
"opencode",
|
|
16
|
+
"scripts",
|
|
17
|
+
"skills",
|
|
18
|
+
"assets",
|
|
19
|
+
"hooks",
|
|
20
|
+
"hooks.json",
|
|
21
|
+
"mcp_config.json",
|
|
22
|
+
".mcp.json",
|
|
23
|
+
".antigravity-plugin",
|
|
24
|
+
".claude-plugin",
|
|
25
|
+
"plugin.json",
|
|
26
|
+
"README.md"
|
|
27
|
+
],
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./opencode/plugin.d.ts",
|
|
31
|
+
"default": "./opencode/plugin.js"
|
|
32
|
+
},
|
|
33
|
+
"./opencode": {
|
|
34
|
+
"types": "./opencode/plugin.d.ts",
|
|
35
|
+
"default": "./opencode/plugin.js"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "https://github.com/americanumberoneaokgoodtimes/prompt-manager-plugin-opencode-claude-agy-etc"
|
|
41
|
+
},
|
|
42
|
+
"license": "MIT",
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=18"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"test": "node --test scripts/prompt-manager.test.mjs"
|
|
48
|
+
},
|
|
49
|
+
"keywords": [
|
|
50
|
+
"opencode",
|
|
51
|
+
"opencode-plugin",
|
|
52
|
+
"antigravity",
|
|
53
|
+
"claude-code",
|
|
54
|
+
"plugin",
|
|
55
|
+
"prompts",
|
|
56
|
+
"prompt-manager",
|
|
57
|
+
"mcp"
|
|
58
|
+
]
|
|
59
|
+
}
|