picocode-core 0.9.145 → 0.9.146
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/package.json +1 -1
- package/src/prompts.js +41 -0
package/package.json
CHANGED
package/src/prompts.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { mkdir, readFile, readdir, unlink, writeFile } from 'node:fs/promises'
|
|
2
|
+
import { join } from 'node:path'
|
|
3
|
+
import { picoHome } from './paths.js'
|
|
4
|
+
import { parseFrontmatter } from './skills.js'
|
|
5
|
+
|
|
6
|
+
export function globalPromptsDir() {
|
|
7
|
+
return join(picoHome(), 'prompts')
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function promptName(name) {
|
|
11
|
+
return String(name ?? '').trim().toLowerCase().replace(/[^a-z0-9_-]+/g, '-').replace(/^-+|-+$/g, '')
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const promptFile = (name) => join(globalPromptsDir(), `${promptName(name)}.md`)
|
|
15
|
+
|
|
16
|
+
export async function listPrompts() {
|
|
17
|
+
let files = []
|
|
18
|
+
try { files = await readdir(globalPromptsDir()) } catch { return [] }
|
|
19
|
+
return Promise.all(files.filter((file) => file.endsWith('.md')).sort().map(async (file) => {
|
|
20
|
+
const text = await readFile(join(globalPromptsDir(), file), 'utf-8')
|
|
21
|
+
const { meta, body } = parseFrontmatter(text)
|
|
22
|
+
return { name: file.slice(0, -3), description: meta.description || '', body: body.trim() }
|
|
23
|
+
}))
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function savePrompt({ previous, name, description, body }) {
|
|
27
|
+
const slug = promptName(name)
|
|
28
|
+
if (!slug || !String(body ?? '').trim()) throw new Error('prompt name and text are required')
|
|
29
|
+
await mkdir(globalPromptsDir(), { recursive: true })
|
|
30
|
+
const summary = String(description ?? '').trim().replace(/\s*\n\s*/g, ' ')
|
|
31
|
+
const text = `---\ndescription: ${summary}\n---\n\n${String(body).trim()}\n`
|
|
32
|
+
await writeFile(promptFile(slug), text)
|
|
33
|
+
const old = promptName(previous)
|
|
34
|
+
if (old && old !== slug) await unlink(promptFile(old)).catch(() => {})
|
|
35
|
+
return true
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export async function removePrompt(name) {
|
|
39
|
+
await unlink(promptFile(name))
|
|
40
|
+
return true
|
|
41
|
+
}
|