@hasna/prompts 0.3.8 → 0.3.10
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 +19 -238
- package/dist/cli/index.js +3478 -2923
- package/dist/index.js +3748 -3113
- package/dist/mcp/index.js +9734 -8451
- package/dist/server/index.js +3747 -3112
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -1,269 +1,50 @@
|
|
|
1
1
|
# @hasna/prompts
|
|
2
2
|
|
|
3
|
-
Reusable prompt library for AI agents
|
|
3
|
+
Reusable prompt library for AI agents — CLI + MCP server + REST API + web dashboard
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
```
|
|
5
|
+
[](https://www.npmjs.com/package/@hasna/prompts)
|
|
6
|
+
[](LICENSE)
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
## Quick Start
|
|
8
|
+
## Install
|
|
12
9
|
|
|
13
10
|
```bash
|
|
14
|
-
|
|
15
|
-
prompts save "TypeScript Code Review" \
|
|
16
|
-
--body "Review this TypeScript code for correctness, types, and style:\n\n{{code}}" \
|
|
17
|
-
--tags "code,review,typescript" \
|
|
18
|
-
--collection "code"
|
|
19
|
-
|
|
20
|
-
# Use it (prints body, increments counter)
|
|
21
|
-
prompts use typescript-code-review
|
|
22
|
-
|
|
23
|
-
# Render a template
|
|
24
|
-
prompts render typescript-code-review --var code="$(cat myfile.ts)"
|
|
25
|
-
|
|
26
|
-
# Search
|
|
27
|
-
prompts search "code review"
|
|
11
|
+
npm install -g @hasna/prompts
|
|
28
12
|
```
|
|
29
13
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
## MCP Server
|
|
33
|
-
|
|
34
|
-
Add to your Claude/agent config:
|
|
35
|
-
|
|
36
|
-
```json
|
|
37
|
-
{
|
|
38
|
-
"mcpServers": {
|
|
39
|
-
"prompts": {
|
|
40
|
-
"command": "prompts-mcp"
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
Then in any AI session:
|
|
47
|
-
|
|
48
|
-
```
|
|
49
|
-
Save this as a reusable prompt called "deploy-checklist"
|
|
50
|
-
→ prompts_save(title="Deploy Checklist", body="...", collection="devops")
|
|
51
|
-
|
|
52
|
-
Later, in any session:
|
|
53
|
-
→ prompts_use("deploy-checklist") // body + increments counter
|
|
54
|
-
→ prompts_render("deploy-checklist", { env: "production" })
|
|
55
|
-
→ prompts_search("deploy")
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
### Available MCP Tools
|
|
59
|
-
|
|
60
|
-
| Tool | Description |
|
|
61
|
-
|------|-------------|
|
|
62
|
-
| `prompts_save` | Create or update a prompt (upsert by slug) |
|
|
63
|
-
| `prompts_get` | Get by ID, slug, or partial ID |
|
|
64
|
-
| `prompts_list` | List with filters (collection, tags, is_template, source) |
|
|
65
|
-
| `prompts_use` | Get body + increment use counter |
|
|
66
|
-
| `prompts_delete` | Delete a prompt |
|
|
67
|
-
| `prompts_update` | Update fields |
|
|
68
|
-
| `prompts_search` | FTS5 full-text search (BM25 ranking) |
|
|
69
|
-
| `prompts_similar` | Find similar prompts by tag overlap |
|
|
70
|
-
| `prompts_render` | Fill `{{variables}}` in a template |
|
|
71
|
-
| `prompts_list_templates` | List templates only |
|
|
72
|
-
| `prompts_variables` | Inspect template variables |
|
|
73
|
-
| `prompts_validate_vars` | Check which vars are required/optional/extra |
|
|
74
|
-
| `prompts_collections` | List collections with counts |
|
|
75
|
-
| `prompts_move` | Move prompt to a different collection |
|
|
76
|
-
| `prompts_ensure_collection` | Create a collection |
|
|
77
|
-
| `prompts_history` | Version history |
|
|
78
|
-
| `prompts_restore` | Restore previous version |
|
|
79
|
-
| `prompts_export` | Export as JSON |
|
|
80
|
-
| `prompts_import` | Import from JSON array |
|
|
81
|
-
| `prompts_register_agent` | Register an agent for attribution |
|
|
82
|
-
| `prompts_stats` | Usage stats |
|
|
83
|
-
|
|
84
|
-
---
|
|
85
|
-
|
|
86
|
-
## CLI Reference
|
|
14
|
+
## CLI Usage
|
|
87
15
|
|
|
88
16
|
```bash
|
|
89
|
-
prompts
|
|
90
|
-
prompts use <id|slug> # Get body, increment counter
|
|
91
|
-
prompts get <id|slug> # Get details without incrementing
|
|
92
|
-
prompts list # List all prompts
|
|
93
|
-
prompts search <query> # Full-text search
|
|
94
|
-
prompts render <id> -v k=v # Render template with variables
|
|
95
|
-
prompts templates # List templates
|
|
96
|
-
prompts inspect <id> # Show template variables
|
|
97
|
-
prompts update <id> # Update fields
|
|
98
|
-
prompts delete <id> # Delete
|
|
99
|
-
prompts history <id> # Version history
|
|
100
|
-
prompts restore <id> <v> # Restore version
|
|
101
|
-
prompts collections # List collections
|
|
102
|
-
prompts move <id> <col> # Move to collection
|
|
103
|
-
prompts export # Export as JSON
|
|
104
|
-
prompts import <file> # Import from JSON
|
|
105
|
-
prompts stats # Usage statistics
|
|
106
|
-
|
|
107
|
-
# Global flags
|
|
108
|
-
prompts list --json # Machine-readable output
|
|
109
|
-
prompts list -c code # Filter by collection
|
|
110
|
-
prompts list -t review,ts # Filter by tags
|
|
17
|
+
prompts --help
|
|
111
18
|
```
|
|
112
19
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
## Templates
|
|
116
|
-
|
|
117
|
-
Prompts with `{{variable}}` syntax are automatically detected as templates.
|
|
20
|
+
## MCP Server
|
|
118
21
|
|
|
119
22
|
```bash
|
|
120
|
-
|
|
121
|
-
prompts save "PR Description" \
|
|
122
|
-
--body "Write a PR description for this {{language|TypeScript}} change:\n\n{{diff}}\n\nFocus on: {{focus|what changed and why}}"
|
|
123
|
-
|
|
124
|
-
# Inspect variables
|
|
125
|
-
prompts inspect pr-description
|
|
126
|
-
# Variables for pr-description:
|
|
127
|
-
# language optional (default: "TypeScript")
|
|
128
|
-
# diff required
|
|
129
|
-
# focus optional (default: "what changed and why")
|
|
130
|
-
|
|
131
|
-
# Render
|
|
132
|
-
prompts render pr-description \
|
|
133
|
-
--var diff="$(git diff main)" \
|
|
134
|
-
--var language=Go
|
|
23
|
+
prompts-mcp
|
|
135
24
|
```
|
|
136
25
|
|
|
137
|
-
|
|
138
|
-
- `{{name}}` — required variable
|
|
139
|
-
- `{{name|default value}}` — optional variable with default
|
|
140
|
-
|
|
141
|
-
---
|
|
142
|
-
|
|
143
|
-
## SDK
|
|
144
|
-
|
|
145
|
-
```typescript
|
|
146
|
-
import {
|
|
147
|
-
savePrompt, getPrompt, usePrompt, listPrompts,
|
|
148
|
-
searchPrompts, renderTemplate, extractVariables,
|
|
149
|
-
upsertPrompt, importFromJson, exportToJson
|
|
150
|
-
} from "@hasna/prompts"
|
|
151
|
-
|
|
152
|
-
// Save from a session
|
|
153
|
-
const { prompt } = await upsertPrompt({
|
|
154
|
-
title: "Summarize Issue",
|
|
155
|
-
body: "Summarize this GitHub issue in 3 bullets:\n\n{{issue_body}}",
|
|
156
|
-
collection: "github",
|
|
157
|
-
tags: ["github", "summary"],
|
|
158
|
-
source: "ai-session",
|
|
159
|
-
})
|
|
160
|
-
|
|
161
|
-
// Use it
|
|
162
|
-
const p = usePrompt("summarize-issue")
|
|
163
|
-
console.log(p.body)
|
|
164
|
-
|
|
165
|
-
// Render a template
|
|
166
|
-
const result = renderTemplate(p.body, { issue_body: "..." })
|
|
167
|
-
console.log(result.rendered)
|
|
168
|
-
console.log(result.missing_vars) // vars not provided
|
|
169
|
-
console.log(result.used_defaults) // vars that fell back to defaults
|
|
170
|
-
|
|
171
|
-
// Search
|
|
172
|
-
const results = searchPrompts("github issue", { collection: "github" })
|
|
173
|
-
|
|
174
|
-
// Import from Claude Code slash commands
|
|
175
|
-
import { importFromClaudeCommands } from "@hasna/prompts"
|
|
176
|
-
importFromClaudeCommands([
|
|
177
|
-
{ filename: "code-review.md", content: fs.readFileSync(".claude/commands/code-review.md", "utf-8") }
|
|
178
|
-
])
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
---
|
|
26
|
+
1 tools available.
|
|
182
27
|
|
|
183
28
|
## REST API
|
|
184
29
|
|
|
185
30
|
```bash
|
|
186
|
-
prompts-serve
|
|
31
|
+
prompts-serve
|
|
187
32
|
```
|
|
188
33
|
|
|
189
|
-
|
|
190
|
-
|--------|----------|-------------|
|
|
191
|
-
| GET | `/api/prompts` | List (supports `?collection=`, `?tags=`, `?templates=1`, `?limit=`) |
|
|
192
|
-
| POST | `/api/prompts` | Create/upsert |
|
|
193
|
-
| GET | `/api/prompts/:id` | Get by ID or slug |
|
|
194
|
-
| PUT | `/api/prompts/:id` | Update |
|
|
195
|
-
| DELETE | `/api/prompts/:id` | Delete |
|
|
196
|
-
| POST | `/api/prompts/:id/use` | Use (increment counter) |
|
|
197
|
-
| POST | `/api/prompts/:id/render` | Render template `{ vars: {...} }` |
|
|
198
|
-
| GET | `/api/prompts/:id/history` | Version history |
|
|
199
|
-
| POST | `/api/prompts/:id/restore` | Restore version `{ version: N }` |
|
|
200
|
-
| GET | `/api/prompts/:id/similar` | Similar prompts |
|
|
201
|
-
| GET | `/api/prompts/:id/variables` | Template variables |
|
|
202
|
-
| GET | `/api/search?q=` | Full-text search |
|
|
203
|
-
| GET | `/api/templates` | Templates only |
|
|
204
|
-
| GET | `/api/collections` | All collections |
|
|
205
|
-
| POST | `/api/collections` | Create collection |
|
|
206
|
-
| GET | `/api/stats` | Usage stats |
|
|
207
|
-
| GET | `/api/export` | Export JSON |
|
|
208
|
-
| POST | `/api/import` | Import JSON |
|
|
209
|
-
|
|
210
|
-
---
|
|
211
|
-
|
|
212
|
-
## Web Dashboard
|
|
213
|
-
|
|
214
|
-
```bash
|
|
215
|
-
prompts-serve # start API on :19430
|
|
216
|
-
# open dashboard/dist/index.html or run dashboard dev server
|
|
217
|
-
```
|
|
218
|
-
|
|
219
|
-
Features: browse/search prompts, view/edit body, template renderer with variable inputs, collection sidebar, version history, stats view, create modal.
|
|
220
|
-
|
|
221
|
-
---
|
|
222
|
-
|
|
223
|
-
## Data Model
|
|
224
|
-
|
|
225
|
-
Each prompt has:
|
|
226
|
-
|
|
227
|
-
| Field | Description |
|
|
228
|
-
|-------|-------------|
|
|
229
|
-
| `id` | Sequential ID: `PRMT-00001` |
|
|
230
|
-
| `slug` | Unique kebab-case slug (auto-generated from title) |
|
|
231
|
-
| `title` | Human display name |
|
|
232
|
-
| `body` | Prompt content |
|
|
233
|
-
| `collection` | Namespace (default: `default`) |
|
|
234
|
-
| `tags` | String array for filtering |
|
|
235
|
-
| `variables` | Detected `{{vars}}` with required/default info |
|
|
236
|
-
| `is_template` | Auto-set when body contains `{{}}` |
|
|
237
|
-
| `source` | `manual` \| `ai-session` \| `imported` |
|
|
238
|
-
| `use_count` | Times retrieved via `use` |
|
|
239
|
-
| `last_used_at` | Last use timestamp |
|
|
240
|
-
| `version` | Increments on every edit |
|
|
241
|
-
|
|
242
|
-
---
|
|
243
|
-
|
|
244
|
-
## Database Location
|
|
245
|
-
|
|
246
|
-
Priority order:
|
|
247
|
-
1. `PROMPTS_DB_PATH` env var
|
|
248
|
-
2. `PROMPTS_DB_SCOPE=project` — uses `.prompts/prompts.db` at git root
|
|
249
|
-
3. Global: `~/.prompts/prompts.db`
|
|
250
|
-
|
|
251
|
-
---
|
|
34
|
+
## Cloud Sync
|
|
252
35
|
|
|
253
|
-
|
|
36
|
+
This package supports cloud sync via `@hasna/cloud`:
|
|
254
37
|
|
|
255
38
|
```bash
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
prompts save "$name" --file "$f" --collection claude-commands --tags "slash-command"
|
|
260
|
-
done
|
|
39
|
+
cloud setup
|
|
40
|
+
cloud sync push --service prompts
|
|
41
|
+
cloud sync pull --service prompts
|
|
261
42
|
```
|
|
262
43
|
|
|
263
|
-
|
|
44
|
+
## Data Directory
|
|
264
45
|
|
|
265
|
-
|
|
46
|
+
Data is stored in `~/.hasna/prompts/`.
|
|
266
47
|
|
|
267
48
|
## License
|
|
268
49
|
|
|
269
|
-
Apache-2.0
|
|
50
|
+
Apache-2.0 -- see [LICENSE](LICENSE)
|