@hasna/prompts 0.1.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 ADDED
@@ -0,0 +1,269 @@
1
+ # @hasna/prompts
2
+
3
+ Reusable prompt library for AI agents. Save prompts from any session, search them instantly, render templates, and reuse across agents via MCP, CLI, or SDK.
4
+
5
+ ```bash
6
+ bun install -g @hasna/prompts
7
+ ```
8
+
9
+ ---
10
+
11
+ ## Quick Start
12
+
13
+ ```bash
14
+ # Save a prompt
15
+ open-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
+ open-prompts use typescript-code-review
22
+
23
+ # Render a template
24
+ open-prompts render typescript-code-review --var code="$(cat myfile.ts)"
25
+
26
+ # Search
27
+ open-prompts search "code review"
28
+ ```
29
+
30
+ ---
31
+
32
+ ## MCP Server
33
+
34
+ Add to your Claude/agent config:
35
+
36
+ ```json
37
+ {
38
+ "mcpServers": {
39
+ "prompts": {
40
+ "command": "open-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
87
+
88
+ ```bash
89
+ open-prompts save <title> # Save a prompt (--body, --file, or stdin)
90
+ open-prompts use <id|slug> # Get body, increment counter
91
+ open-prompts get <id|slug> # Get details without incrementing
92
+ open-prompts list # List all prompts
93
+ open-prompts search <query> # Full-text search
94
+ open-prompts render <id> -v k=v # Render template with variables
95
+ open-prompts templates # List templates
96
+ open-prompts inspect <id> # Show template variables
97
+ open-prompts update <id> # Update fields
98
+ open-prompts delete <id> # Delete
99
+ open-prompts history <id> # Version history
100
+ open-prompts restore <id> <v> # Restore version
101
+ open-prompts collections # List collections
102
+ open-prompts move <id> <col> # Move to collection
103
+ open-prompts export # Export as JSON
104
+ open-prompts import <file> # Import from JSON
105
+ open-prompts stats # Usage statistics
106
+
107
+ # Global flags
108
+ open-prompts list --json # Machine-readable output
109
+ open-prompts list -c code # Filter by collection
110
+ open-prompts list -t review,ts # Filter by tags
111
+ ```
112
+
113
+ ---
114
+
115
+ ## Templates
116
+
117
+ Prompts with `{{variable}}` syntax are automatically detected as templates.
118
+
119
+ ```bash
120
+ # Save a template
121
+ open-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
+ open-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
+ open-prompts render pr-description \
133
+ --var diff="$(git diff main)" \
134
+ --var language=Go
135
+ ```
136
+
137
+ **Syntax:**
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
+ ---
182
+
183
+ ## REST API
184
+
185
+ ```bash
186
+ open-prompts-serve # starts on port 19430
187
+ ```
188
+
189
+ | Method | Endpoint | Description |
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
+ open-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
+ ---
252
+
253
+ ## Import from Claude Code Slash Commands
254
+
255
+ ```bash
256
+ # Export existing slash commands as prompts
257
+ for f in .claude/commands/*.md; do
258
+ name=$(basename "$f" .md)
259
+ open-prompts save "$name" --file "$f" --collection claude-commands --tags "slash-command"
260
+ done
261
+ ```
262
+
263
+ Or programmatically via SDK using `importFromClaudeCommands()`.
264
+
265
+ ---
266
+
267
+ ## License
268
+
269
+ Apache-2.0
@@ -0,0 +1,73 @@
1
+ # React + TypeScript + Vite
2
+
3
+ This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4
+
5
+ Currently, two official plugins are available:
6
+
7
+ - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Oxc](https://oxc.rs)
8
+ - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/)
9
+
10
+ ## React Compiler
11
+
12
+ The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
13
+
14
+ ## Expanding the ESLint configuration
15
+
16
+ If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
17
+
18
+ ```js
19
+ export default defineConfig([
20
+ globalIgnores(['dist']),
21
+ {
22
+ files: ['**/*.{ts,tsx}'],
23
+ extends: [
24
+ // Other configs...
25
+
26
+ // Remove tseslint.configs.recommended and replace with this
27
+ tseslint.configs.recommendedTypeChecked,
28
+ // Alternatively, use this for stricter rules
29
+ tseslint.configs.strictTypeChecked,
30
+ // Optionally, add this for stylistic rules
31
+ tseslint.configs.stylisticTypeChecked,
32
+
33
+ // Other configs...
34
+ ],
35
+ languageOptions: {
36
+ parserOptions: {
37
+ project: ['./tsconfig.node.json', './tsconfig.app.json'],
38
+ tsconfigRootDir: import.meta.dirname,
39
+ },
40
+ // other options...
41
+ },
42
+ },
43
+ ])
44
+ ```
45
+
46
+ You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
47
+
48
+ ```js
49
+ // eslint.config.js
50
+ import reactX from 'eslint-plugin-react-x'
51
+ import reactDom from 'eslint-plugin-react-dom'
52
+
53
+ export default defineConfig([
54
+ globalIgnores(['dist']),
55
+ {
56
+ files: ['**/*.{ts,tsx}'],
57
+ extends: [
58
+ // Other configs...
59
+ // Enable lint rules for React
60
+ reactX.configs['recommended-typescript'],
61
+ // Enable lint rules for React DOM
62
+ reactDom.configs.recommended,
63
+ ],
64
+ languageOptions: {
65
+ parserOptions: {
66
+ project: ['./tsconfig.node.json', './tsconfig.app.json'],
67
+ tsconfigRootDir: import.meta.dirname,
68
+ },
69
+ // other options...
70
+ },
71
+ },
72
+ ])
73
+ ```
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env bun
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.tsx"],"names":[],"mappings":""}