promptlike 0.4.1 → 0.6.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/CHANGELOG.md +44 -0
- package/README.md +134 -2
- package/dist/commands/config.js +41 -0
- package/dist/commands/diff.js +59 -0
- package/dist/commands/export.js +196 -0
- package/dist/commands/history.js +63 -0
- package/dist/commands/import.js +250 -0
- package/dist/commands/list.js +4 -0
- package/dist/commands/log.js +48 -0
- package/dist/commands/rollback.js +88 -0
- package/dist/commands/stats.js +112 -0
- package/dist/commands/suggest.js +244 -0
- package/dist/commands/sync.js +4 -0
- package/dist/index.js +69 -0
- package/dist/lib/agentExport.js +378 -0
- package/dist/lib/api-client.js +91 -8
- package/dist/lib/constants.js +0 -1
- package/dist/lib/diff.js +149 -0
- package/dist/lib/frontmatter.js +67 -0
- package/dist/lib/libraryCache.js +222 -0
- package/dist/lib/promptVariables.js +4 -2
- package/dist/lib/rank.js +123 -0
- package/dist/lib/scanners/index.js +252 -0
- package/dist/lib/secretGuard.js +92 -0
- package/dist/lib/settings.js +105 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,49 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.6.0 — unreleased (2026-09-27)
|
|
4
|
+
|
|
5
|
+
Your library, where you already work.
|
|
6
|
+
|
|
7
|
+
- **New: `ple suggest "<task>"`** — which saved prompt fits this task?
|
|
8
|
+
Matching is local (a cached copy of your library, or `~/.promptlike` when
|
|
9
|
+
signed out); the text never leaves your machine. `--json`, `--limit`.
|
|
10
|
+
`--hook` is the Claude Code `UserPromptSubmit` mode used by the
|
|
11
|
+
promptlike plugin 0.3.0: silent for slash commands, short messages, weak
|
|
12
|
+
matches and repeats within a session; never waits on the network (a stale
|
|
13
|
+
cache refreshes in the background). Turn it off with
|
|
14
|
+
`ple config set suggest off` or `PLE_SUGGEST=off`.
|
|
15
|
+
- **New: `ple config get|set`** — CLI preferences (today: `suggest on|off`),
|
|
16
|
+
kept in `~/.config/promptlike/settings.json` so logging out does not reset them.
|
|
17
|
+
- **New: `ple import --scan`** — bring in the prompts you already keep for your
|
|
18
|
+
agents: `.claude/commands`, `.claude/skills/*/SKILL.md`, `.cursor/commands`,
|
|
19
|
+
`~/.codex/prompts`, `.github/prompts/*.prompt.md`, `AGENTS.md`, `CLAUDE.md`.
|
|
20
|
+
`--dry-run`, pick `1,3-5`, `--all`, `--project`. Re-running never imports
|
|
21
|
+
the same content twice; secrets (`.env*`, keys, files with live tokens) are
|
|
22
|
+
never read or uploaded.
|
|
23
|
+
- **New: `ple log` · `ple diff` · `ple rollback`** — the web's version history in
|
|
24
|
+
the terminal. Unified diff between any two versions (`3`, `v3` or `1.0.2`);
|
|
25
|
+
rollback is non-destructive (the old version is copied forward) and asks
|
|
26
|
+
first (`--yes` for scripts).
|
|
27
|
+
- **New: `ple stats`** — how your library is used: uses by surface (web / CLI /
|
|
28
|
+
agents), most used, not touched in 30 days (Free: 7-day view), plus how many
|
|
29
|
+
suggestions were shown on this machine and picked up.
|
|
30
|
+
- `copy` / `get` / `show` report the surface (`cli`) with each use;
|
|
31
|
+
`PLE_SURFACE` / `PLE_VIA` let a wrapper attribute uses (e.g. the hook).
|
|
32
|
+
- `ple list` / `ple sync` keep the suggestion cache fresh in the background.
|
|
33
|
+
- **Fixed:** `{{constructor}}`, `{{toString}}` and similar names no longer fill
|
|
34
|
+
from JavaScript built-ins when left empty.
|
|
35
|
+
|
|
36
|
+
`ple export` (AGENTS.md / Agent Skills) shipped in 0.5.0.
|
|
37
|
+
|
|
38
|
+
## 0.5.0 — 2026-09-27
|
|
39
|
+
|
|
40
|
+
- **New: `ple export`.** Turn a prompt, or a whole repo with `--project`, into
|
|
41
|
+
an AGENTS.md section or an Agent Skill (`SKILL.md`, the format Claude Code,
|
|
42
|
+
Claude and other skill-aware agents load). `--zip` writes the archive that
|
|
43
|
+
Claude's skill upload expects. Works signed out, from your local prompts.
|
|
44
|
+
Skill names and descriptions pass Anthropic's skill validator: kebab-case,
|
|
45
|
+
at most 64 characters, no reserved words, no angle brackets.
|
|
46
|
+
|
|
3
47
|
## 0.4.1 — 2026-08-15
|
|
4
48
|
|
|
5
49
|
Data-integrity fix — **update recommended for every 0.4.0 install.**
|
package/README.md
CHANGED
|
@@ -247,6 +247,122 @@ Debug Helper · 33cc44dd · 2w ago
|
|
|
247
247
|
Walk through systematic debugging steps for runtime errors.
|
|
248
248
|
```
|
|
249
249
|
|
|
250
|
+
### `ple export [name] --format agents-md|skill`
|
|
251
|
+
|
|
252
|
+
Export a prompt for coding agents — or a whole repo with `--project <repo>`
|
|
253
|
+
and no name. Signed out, it exports from the local store.
|
|
254
|
+
|
|
255
|
+
| Format | One prompt | Whole repo |
|
|
256
|
+
|---|---|---|
|
|
257
|
+
| `agents-md` | a `## Title` section on stdout (append it to your AGENTS.md) | a full AGENTS.md, one section per prompt |
|
|
258
|
+
| `skill` | `<name>/SKILL.md` ([Agent Skills](https://agentskills.io/specification) format) | one skill: `SKILL.md` index + `references/<prompt>.md` |
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
ple export "code review" --format agents-md >> AGENTS.md
|
|
262
|
+
ple export "code review" --format skill --out ~/.claude/skills # Claude Code picks it up
|
|
263
|
+
ple export --project backend --format skill --zip # upload the zip in Claude
|
|
264
|
+
ple export --project backend --format agents-md --out AGENTS.md
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
Skill names follow the spec: lowercase, digits and single hyphens, at most 64
|
|
268
|
+
characters. The words "claude" and "anthropic" are removed because Anthropic
|
|
269
|
+
rejects them in skill names. `{{variables}}` are listed under an **Inputs**
|
|
270
|
+
heading so the agent knows what to ask for. Existing files are never
|
|
271
|
+
overwritten without `--force`.
|
|
272
|
+
### `ple import --scan [--dry-run] [--all] [--project <repo>]`
|
|
273
|
+
|
|
274
|
+
Bring in the prompts you already keep for your agents — no copy-pasting.
|
|
275
|
+
Scans this repo and your home folder:
|
|
276
|
+
|
|
277
|
+
| Tool | Where |
|
|
278
|
+
|---|---|
|
|
279
|
+
| Claude Code | `.claude/commands/**/*.md`, `~/.claude/commands/**/*.md`, `.claude/skills/*/SKILL.md`, `~/.claude/skills/*/SKILL.md` |
|
|
280
|
+
| Cursor | `.cursor/commands/*.md`, `~/.cursor/commands/*.md` |
|
|
281
|
+
| Codex | `~/.codex/prompts/*.md` |
|
|
282
|
+
| Copilot | `.github/prompts/*.prompt.md` |
|
|
283
|
+
| Context | `AGENTS.md`, `CLAUDE.md` (repo root) |
|
|
284
|
+
|
|
285
|
+
```bash
|
|
286
|
+
ple import --scan --dry-run # what was found: tool, title, size, path
|
|
287
|
+
ple import --scan # pick: 1,3-5 / all / Enter to cancel
|
|
288
|
+
ple import --scan --all # everything new, no questions
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
- Frontmatter `description` / `tags` / `name` become the prompt's fields; the
|
|
292
|
+
body is what gets imported.
|
|
293
|
+
- Re-running is safe: the same content (sha256) is never imported twice.
|
|
294
|
+
- Signed out → your local store (`~/.promptlike`); signed in → your account.
|
|
295
|
+
- Never read: `.env*`, `*.key`, `*.pem`, `credentials*`, SSH keys, files over
|
|
296
|
+
64 KB. A file that looks like it contains a live token (`sk-…`, `AKIA…`,
|
|
297
|
+
`ghp_…`, private keys …) is skipped and named so you can clean it up.
|
|
298
|
+
|
|
299
|
+
### `ple log <name>` · `ple diff <name> [a] [b]` · `ple rollback <name> <version>`
|
|
300
|
+
|
|
301
|
+
The version history you have on the web, in the terminal (signed in).
|
|
302
|
+
|
|
303
|
+
```bash
|
|
304
|
+
ple log "code review" # v5 1.0.4 rollback 2h ago … (* = current)
|
|
305
|
+
ple diff "code review" # previous ↔ current, unified diff
|
|
306
|
+
ple diff "code review" 2 5 # any two: 3, v3 or 1.0.2
|
|
307
|
+
ple diff "code review" 2 | delta # plain when piped (or --no-color)
|
|
308
|
+
ple rollback "code review" v2 # asks first; --yes for scripts
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
Rollback is non-destructive: the old version is copied forward as a new one,
|
|
312
|
+
nothing is deleted — so a rollback can itself be undone.
|
|
313
|
+
|
|
314
|
+
### `ple stats [--range 7|30|365] [--json]`
|
|
315
|
+
|
|
316
|
+
How your library is actually used — the same numbers as the web Insights
|
|
317
|
+
page: uses in the window, where they came from (web / CLI / agents), the most
|
|
318
|
+
used prompts and the ones not touched in 30 days. Free shows a 7-day view;
|
|
319
|
+
asking for more says so instead of silently shrinking the window.
|
|
320
|
+
|
|
321
|
+
```bash
|
|
322
|
+
$ ple stats --range 30
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
Every `ple copy/get/show` records one use with `surface: cli`. A wrapper can
|
|
326
|
+
attribute uses differently with `PLE_SURFACE` (e.g. `hook`) and
|
|
327
|
+
`PLE_VIA=suggestion`; unknown values fall back to `cli`.
|
|
328
|
+
|
|
329
|
+
### `ple suggest "<task>" [--json] [--limit <n>] [--hook]`
|
|
330
|
+
|
|
331
|
+
Which of your saved prompts fits what you are about to do? Matching is
|
|
332
|
+
**local**: a cached copy of your library (`~/.config/promptlike/cache/`,
|
|
333
|
+
refreshed by `ple list` / `ple sync` and in the background every 10 minutes),
|
|
334
|
+
or `~/.promptlike` when you are signed out. The text you type never leaves
|
|
335
|
+
your machine.
|
|
336
|
+
|
|
337
|
+
```bash
|
|
338
|
+
$ ple suggest "review this pull request for security issues"
|
|
339
|
+
Code Review ai-os · used 12× · score 7.4
|
|
340
|
+
Review a diff for bugs, style and security
|
|
341
|
+
|
|
342
|
+
Use one: ple get "Code Review"
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
Ranking: title ×3, tag ×2, description ×1, the first 600 characters of the
|
|
346
|
+
body ×0.5, weighted by how rare each word is in your library, plus a small
|
|
347
|
+
bonus for prompts you use a lot. Weak single-word matches are not suggested.
|
|
348
|
+
|
|
349
|
+
`--hook` is what the Claude Code plugin runs on every message
|
|
350
|
+
(`UserPromptSubmit`). It reads the hook's JSON from stdin and prints one short
|
|
351
|
+
note — or nothing: slash commands, messages under 20 characters, weak
|
|
352
|
+
matches and prompts already suggested in the session stay silent. It never
|
|
353
|
+
waits on the network and gives up after 0.8 s.
|
|
354
|
+
|
|
355
|
+
Turn suggestions off with `ple config set suggest off`, `PLE_SUGGEST=off`, or
|
|
356
|
+
the plugin option in Claude Code's `/config`. How many were shown is counted
|
|
357
|
+
on this machine only (`ple stats`); the server only learns about a suggestion
|
|
358
|
+
when one is actually used.
|
|
359
|
+
|
|
360
|
+
### `ple config get [key]` · `ple config set <key> <value>`
|
|
361
|
+
|
|
362
|
+
CLI preferences, stored in `~/.config/promptlike/settings.json` (separate from
|
|
363
|
+
the session file, so logging out keeps them). Today there is one key:
|
|
364
|
+
`suggest` (`on` | `off`).
|
|
365
|
+
|
|
250
366
|
### `ple --help` / `ple <cmd> --help`
|
|
251
367
|
|
|
252
368
|
Standard `commander` help output for either the root command or any
|
|
@@ -259,6 +375,8 @@ sub-command.
|
|
|
259
375
|
| Path | Purpose | Permissions |
|
|
260
376
|
|---|---|---|
|
|
261
377
|
| `~/.config/promptlike/config.json` | Local session token storage | `0600` |
|
|
378
|
+
| `~/.config/promptlike/settings.json` | Preferences (`ple config`) | `0600` |
|
|
379
|
+
| `~/.config/promptlike/cache/library.json` | Library snapshot for `ple suggest` (titles, descriptions, tags, first 600 chars) | `0600` |
|
|
262
380
|
|
|
263
381
|
Shape of the config file:
|
|
264
382
|
|
|
@@ -289,6 +407,12 @@ ple list
|
|
|
289
407
|
That URL is the only backend detail the CLI knows — there is no Supabase key
|
|
290
408
|
to configure.
|
|
291
409
|
|
|
410
|
+
| Variable | Effect |
|
|
411
|
+
|---|---|
|
|
412
|
+
| `PLE_SUGGEST=off` | `ple suggest --hook` stays silent |
|
|
413
|
+
| `PLE_SURFACE`, `PLE_VIA` | How `copy/get/show` report a use (e.g. `hook`, `suggestion`) |
|
|
414
|
+
| `PROMPTLIKE_HOME` | Local store location (default `~/.promptlike`) |
|
|
415
|
+
|
|
292
416
|
---
|
|
293
417
|
|
|
294
418
|
## How it works
|
|
@@ -359,7 +483,13 @@ cli/
|
|
|
359
483
|
│ │ ├── list.ts # list with --tag / --limit
|
|
360
484
|
│ │ ├── copy.ts # resolve + fetch + clipboard
|
|
361
485
|
│ │ ├── show.ts # resolve + 3-part colored render
|
|
362
|
-
│ │
|
|
486
|
+
│ │ ├── search.ts # title + description search
|
|
487
|
+
│ │ ├── save.ts # write to local store, no account needed
|
|
488
|
+
│ │ ├── get.ts # resolve + fill {{vars}} + print/copy
|
|
489
|
+
│ │ ├── sync.ts # one-way upload: local store → account
|
|
490
|
+
│ │ ├── improve.ts # one-shot variants, pick a winner
|
|
491
|
+
│ │ ├── loop.ts # multi-round improve judged by --exec
|
|
492
|
+
│ │ └── local.ts # logged-out routing + local-store implementations
|
|
363
493
|
│ └── lib/
|
|
364
494
|
│ ├── constants.ts # API_BASE_URL + WEB_APP_URL
|
|
365
495
|
│ ├── config.ts # read/write ~/.config/promptlike/config.json
|
|
@@ -367,7 +497,9 @@ cli/
|
|
|
367
497
|
│ ├── clipboard.ts # spawn(pbcopy/xclip/clip) + Wayland fallback
|
|
368
498
|
│ ├── format.ts # chalk palette, timeAgo, truncate, joinPromptParts
|
|
369
499
|
│ ├── promptResolver.ts # name → prompt (id prefix or title search)
|
|
370
|
-
│
|
|
500
|
+
│ ├── promptVariables.ts # {{variable}} extract + fill
|
|
501
|
+
│ ├── localStore.ts # ~/.promptlike/prompts/ Markdown read/write
|
|
502
|
+
│ └── loopApi.ts / loopUx.ts # loop + improve variant generation & prompts
|
|
371
503
|
└── dist/ # tsc output, what gets published
|
|
372
504
|
```
|
|
373
505
|
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* `ple config get [key]` · `ple config set <key> <value>` — CLI preferences.
|
|
4
|
+
*
|
|
5
|
+
* Keys: `suggest` (on|off) — whether `ple suggest --hook` (the Claude Code
|
|
6
|
+
* plugin hook) may add a saved-prompt hint to your messages.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.configGetCommand = configGetCommand;
|
|
10
|
+
exports.configSetCommand = configSetCommand;
|
|
11
|
+
const format_1 = require("../lib/format");
|
|
12
|
+
const settings_1 = require("../lib/settings");
|
|
13
|
+
function assertKey(key) {
|
|
14
|
+
const k = key.trim().toLowerCase();
|
|
15
|
+
if (settings_1.SETTING_KEYS.includes(k))
|
|
16
|
+
return k;
|
|
17
|
+
throw new Error(`Unknown setting '${key}'. Available: ${settings_1.SETTING_KEYS.join(', ')}.`);
|
|
18
|
+
}
|
|
19
|
+
async function configGetCommand(key) {
|
|
20
|
+
const settings = (0, settings_1.readSettings)();
|
|
21
|
+
const keys = key ? [assertKey(key)] : [...settings_1.SETTING_KEYS];
|
|
22
|
+
for (const k of keys) {
|
|
23
|
+
if (k === 'suggest') {
|
|
24
|
+
const stored = settings.suggest ?? 'on';
|
|
25
|
+
const effective = (0, settings_1.suggestEnabled)() ? 'on' : 'off';
|
|
26
|
+
const note = stored !== effective ? format_1.c.muted(' (off via PLE_SUGGEST or the Claude Code plugin option)') : '';
|
|
27
|
+
console.log(`suggest ${effective}${note}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async function configSetCommand(key, value) {
|
|
32
|
+
const k = assertKey(key);
|
|
33
|
+
const settings = (0, settings_1.readSettings)();
|
|
34
|
+
if (k === 'suggest')
|
|
35
|
+
settings.suggest = (0, settings_1.parseOnOff)(value);
|
|
36
|
+
(0, settings_1.writeSettings)(settings);
|
|
37
|
+
console.log(format_1.c.success(`✓ ${k} = ${settings[k]}`));
|
|
38
|
+
if (k === 'suggest' && settings.suggest === 'off') {
|
|
39
|
+
console.log(format_1.c.muted(' The Claude Code hook stays silent now. Turn it back on: ple config set suggest on'));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* `ple diff <name> [a] [b]` — unified diff between two versions (W1-4).
|
|
4
|
+
*
|
|
5
|
+
* Defaults: no refs → previous ↔ current; one ref → that ↔ current.
|
|
6
|
+
* Refs: `3`, `v3` (version number) or `1.0.2` (semver). Colored on a TTY,
|
|
7
|
+
* plain when piped or with `--no-color` (chalk honours both).
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.diffCommand = diffCommand;
|
|
11
|
+
const api_client_1 = require("../lib/api-client");
|
|
12
|
+
const format_1 = require("../lib/format");
|
|
13
|
+
const diff_1 = require("../lib/diff");
|
|
14
|
+
const history_1 = require("./history");
|
|
15
|
+
function label(title, v) {
|
|
16
|
+
return `${title} v${v.version_number} (${(0, history_1.semverOf)(v)})`;
|
|
17
|
+
}
|
|
18
|
+
async function diffCommand(name, a, b, options = {}) {
|
|
19
|
+
const prompt = await (0, history_1.resolveForHistory)(name, options.project);
|
|
20
|
+
if (!prompt) {
|
|
21
|
+
process.exitCode = 1;
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const history = await (0, api_client_1.getPromptHistory)(prompt.id);
|
|
25
|
+
const current = (0, history_1.currentVersion)(history);
|
|
26
|
+
if (!current)
|
|
27
|
+
throw new Error(`'${history.title}' has no versions yet.`);
|
|
28
|
+
let to;
|
|
29
|
+
let from;
|
|
30
|
+
if (a && b) {
|
|
31
|
+
from = (0, history_1.findVersion)(history.versions, a) ?? (() => { throw (0, history_1.versionNotFound)(a, history.versions); })();
|
|
32
|
+
to = (0, history_1.findVersion)(history.versions, b) ?? (() => { throw (0, history_1.versionNotFound)(b, history.versions); })();
|
|
33
|
+
}
|
|
34
|
+
else if (a) {
|
|
35
|
+
from = (0, history_1.findVersion)(history.versions, a) ?? (() => { throw (0, history_1.versionNotFound)(a, history.versions); })();
|
|
36
|
+
to = current;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
to = current;
|
|
40
|
+
const older = (0, history_1.sortNewestFirst)(history.versions).find((v) => v.version_number < current.version_number);
|
|
41
|
+
if (!older) {
|
|
42
|
+
console.log(format_1.c.muted(`'${history.title}' has a single version — nothing to compare yet.`));
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
from = older;
|
|
46
|
+
}
|
|
47
|
+
const useColor = options.color !== false && format_1.c.success.level > 0;
|
|
48
|
+
const lines = (0, diff_1.unifiedDiff)((0, format_1.joinPromptParts)(from), (0, format_1.joinPromptParts)(to), {
|
|
49
|
+
fromLabel: label(history.title, from),
|
|
50
|
+
toLabel: label(history.title, to),
|
|
51
|
+
colors: useColor ? { header: format_1.c.title, hunk: format_1.c.accent, add: format_1.c.success, del: format_1.c.error } : undefined,
|
|
52
|
+
});
|
|
53
|
+
if (lines.length === 0) {
|
|
54
|
+
console.log(format_1.c.muted(`v${from.version_number} and v${to.version_number} have identical content.`));
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
for (const line of lines)
|
|
58
|
+
console.log(line);
|
|
59
|
+
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.exportCommand = exportCommand;
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
const api_client_1 = require("../lib/api-client");
|
|
40
|
+
const local_1 = require("./local");
|
|
41
|
+
const store = __importStar(require("../lib/localStore"));
|
|
42
|
+
const promptResolver_1 = require("../lib/promptResolver");
|
|
43
|
+
const format_1 = require("../lib/format");
|
|
44
|
+
const agentExport_1 = require("../lib/agentExport");
|
|
45
|
+
/** Hard cap for a repo export — 10 pages × 100. */
|
|
46
|
+
const MAX_PAGES = 10;
|
|
47
|
+
const PAGE_SIZE = 100;
|
|
48
|
+
function parseFormat(value) {
|
|
49
|
+
const v = (value ?? '').trim().toLowerCase();
|
|
50
|
+
if (agentExport_1.AGENT_EXPORT_FORMATS.includes(v))
|
|
51
|
+
return v;
|
|
52
|
+
throw new Error(`--format must be one of: ${agentExport_1.AGENT_EXPORT_FORMATS.join(', ')}.`);
|
|
53
|
+
}
|
|
54
|
+
function fromRemote(p) {
|
|
55
|
+
const v = (0, promptResolver_1.fetchPromptContent)(p);
|
|
56
|
+
const body = v
|
|
57
|
+
? (0, agentExport_1.composePromptMarkdown)({ role: v.role_text, context: v.context_text, description: v.description_text, content: v.content })
|
|
58
|
+
: '';
|
|
59
|
+
if (!body.trim())
|
|
60
|
+
return null;
|
|
61
|
+
return { title: p.title, description: p.description ?? null, body, projectName: p.project_name ?? null };
|
|
62
|
+
}
|
|
63
|
+
function fromLocal(p) {
|
|
64
|
+
if (!p.body.trim())
|
|
65
|
+
return null;
|
|
66
|
+
return { title: p.title, description: p.description || null, body: p.body.trim() };
|
|
67
|
+
}
|
|
68
|
+
async function collectRemoteRepo(projectId) {
|
|
69
|
+
const out = [];
|
|
70
|
+
for (let page = 1; page <= MAX_PAGES; page++) {
|
|
71
|
+
const rows = await (0, api_client_1.listPrompts)({ projectId, limit: PAGE_SIZE, page });
|
|
72
|
+
for (const r of rows) {
|
|
73
|
+
const e = fromRemote(r);
|
|
74
|
+
if (e)
|
|
75
|
+
out.push(e);
|
|
76
|
+
}
|
|
77
|
+
if (rows.length < PAGE_SIZE)
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
return out;
|
|
81
|
+
}
|
|
82
|
+
function ensureWritable(target, force) {
|
|
83
|
+
if (fs.existsSync(target) && !force) {
|
|
84
|
+
throw new Error(`${target} already exists. Re-run with --force to overwrite.`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function writeSkill(skill, options) {
|
|
88
|
+
const parent = path.resolve(options.out ?? '.');
|
|
89
|
+
fs.mkdirSync(parent, { recursive: true });
|
|
90
|
+
if (options.zip) {
|
|
91
|
+
const target = path.join(parent, `${skill.name}.zip`);
|
|
92
|
+
ensureWritable(target, options.force);
|
|
93
|
+
fs.writeFileSync(target, (0, agentExport_1.createZip)(skill.files));
|
|
94
|
+
return target;
|
|
95
|
+
}
|
|
96
|
+
const folder = path.join(parent, skill.name);
|
|
97
|
+
ensureWritable(folder, options.force);
|
|
98
|
+
for (const f of skill.files) {
|
|
99
|
+
const target = path.join(parent, ...f.path.split('/'));
|
|
100
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
101
|
+
fs.writeFileSync(target, f.content, 'utf-8');
|
|
102
|
+
}
|
|
103
|
+
return folder;
|
|
104
|
+
}
|
|
105
|
+
function writeAgentsMd(text, options) {
|
|
106
|
+
if (!options.out) {
|
|
107
|
+
process.stdout.write(text);
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
const target = path.resolve(options.out);
|
|
111
|
+
ensureWritable(target, options.force);
|
|
112
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
113
|
+
fs.writeFileSync(target, text, 'utf-8');
|
|
114
|
+
return target;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* `ple export [name] --format agents-md|skill` — one prompt, or a whole repo
|
|
118
|
+
* with `--project` and no name.
|
|
119
|
+
*
|
|
120
|
+
* ple export "code review" --format agents-md >> AGENTS.md
|
|
121
|
+
* ple export "code review" --format skill --out ~/.claude/skills
|
|
122
|
+
* ple export --project ai-os --format skill --zip # upload in Claude
|
|
123
|
+
*
|
|
124
|
+
* Signed out, it exports from the local store (no name → every local prompt).
|
|
125
|
+
*/
|
|
126
|
+
async function exportCommand(name, options = {}) {
|
|
127
|
+
const format = parseFormat(options.format);
|
|
128
|
+
if (options.zip && format !== 'skill')
|
|
129
|
+
throw new Error('--zip only applies to --format skill.');
|
|
130
|
+
const exportedAt = new Date().toISOString();
|
|
131
|
+
let single = null;
|
|
132
|
+
let repo = null;
|
|
133
|
+
if ((0, local_1.isSignedOut)()) {
|
|
134
|
+
if (options.project) {
|
|
135
|
+
console.error(format_1.c.muted(`(--project '${options.project}' is ignored while signed out — local prompts have no projects)`));
|
|
136
|
+
}
|
|
137
|
+
if (name) {
|
|
138
|
+
const hit = store.resolve(name);
|
|
139
|
+
if (hit === null || 'candidates' in hit) {
|
|
140
|
+
throw new Error(hit === null
|
|
141
|
+
? `No local prompt matched '${name}'.`
|
|
142
|
+
: `'${name}' matches ${hit.candidates.length} local prompts: ${hit.candidates.map((p) => p.slug).join(', ')}.`);
|
|
143
|
+
}
|
|
144
|
+
single = fromLocal(hit.prompt);
|
|
145
|
+
if (!single)
|
|
146
|
+
throw new Error(`'${hit.prompt.title}' has empty content.`);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
const prompts = store.list().map(fromLocal).filter((p) => p !== null);
|
|
150
|
+
repo = { name: 'prompts', prompts };
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
await (0, api_client_1.ensureAuthed)();
|
|
155
|
+
const projectId = options.project ? await (0, promptResolver_1.resolveProjectId)(options.project) : undefined;
|
|
156
|
+
if (name) {
|
|
157
|
+
const prompt = await (0, promptResolver_1.resolvePromptByName)(name, { projectId });
|
|
158
|
+
if (!prompt) {
|
|
159
|
+
process.exitCode = 1;
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
single = fromRemote(prompt);
|
|
163
|
+
if (!single)
|
|
164
|
+
throw new Error(`'${prompt.title}' has empty content.`);
|
|
165
|
+
}
|
|
166
|
+
else if (projectId) {
|
|
167
|
+
const prompts = await collectRemoteRepo(projectId);
|
|
168
|
+
repo = { name: prompts[0]?.projectName ?? options.project ?? 'prompts', prompts };
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
throw new Error('Give a prompt name, or --project <repo> to export a whole repo.');
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
let text = null;
|
|
175
|
+
let skill = null;
|
|
176
|
+
let count = 1;
|
|
177
|
+
if (single) {
|
|
178
|
+
if (format === 'agents-md')
|
|
179
|
+
text = (0, agentExport_1.buildAgentsMdSection)(single, exportedAt);
|
|
180
|
+
else
|
|
181
|
+
skill = (0, agentExport_1.buildPromptSkill)(single, exportedAt);
|
|
182
|
+
}
|
|
183
|
+
else if (repo) {
|
|
184
|
+
if (repo.prompts.length === 0)
|
|
185
|
+
throw new Error('Nothing to export — no prompts with content.');
|
|
186
|
+
count = repo.prompts.length;
|
|
187
|
+
if (format === 'agents-md')
|
|
188
|
+
text = (0, agentExport_1.buildAgentsMdDocument)(repo.name, null, repo.prompts, exportedAt);
|
|
189
|
+
else
|
|
190
|
+
skill = (0, agentExport_1.buildProjectSkill)(repo.name, null, repo.prompts, exportedAt);
|
|
191
|
+
}
|
|
192
|
+
const written = skill ? writeSkill(skill, options) : writeAgentsMd(text ?? '', options);
|
|
193
|
+
if (written) {
|
|
194
|
+
console.error(format_1.c.success(`✓ Exported ${count} prompt${count === 1 ? '' : 's'} → ${written}`));
|
|
195
|
+
}
|
|
196
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Shared helpers for `ple log`, `ple diff`, `ple rollback` (W1-4).
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.HISTORY_NEEDS_ACCOUNT = void 0;
|
|
7
|
+
exports.semverOf = semverOf;
|
|
8
|
+
exports.sortNewestFirst = sortNewestFirst;
|
|
9
|
+
exports.findVersion = findVersion;
|
|
10
|
+
exports.currentVersion = currentVersion;
|
|
11
|
+
exports.resolveForHistory = resolveForHistory;
|
|
12
|
+
exports.versionNotFound = versionNotFound;
|
|
13
|
+
const api_client_1 = require("../lib/api-client");
|
|
14
|
+
const promptResolver_1 = require("../lib/promptResolver");
|
|
15
|
+
const local_1 = require("./local");
|
|
16
|
+
exports.HISTORY_NEEDS_ACCOUNT = 'Version history lives in your account — local prompts keep no versions. Run `ple login`, then `ple sync`.';
|
|
17
|
+
/** "1.2.3" from the semver columns, else release_tag, else "v<n>". */
|
|
18
|
+
function semverOf(v) {
|
|
19
|
+
if (v.major_version != null && v.minor_version != null && v.patch_version != null) {
|
|
20
|
+
return `${v.major_version}.${v.minor_version}.${v.patch_version}`;
|
|
21
|
+
}
|
|
22
|
+
return v.release_tag || `v${v.version_number}`;
|
|
23
|
+
}
|
|
24
|
+
/** Newest first, by version_number (the API already orders; do not trust it blindly). */
|
|
25
|
+
function sortNewestFirst(versions) {
|
|
26
|
+
return [...versions].sort((a, b) => b.version_number - a.version_number);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Find a version by a user-typed ref: `3`, `v3`, `#3` (version number) or
|
|
30
|
+
* `1.0.2` (semver). Returns null when nothing matches.
|
|
31
|
+
*/
|
|
32
|
+
function findVersion(versions, ref) {
|
|
33
|
+
const r = ref.trim().toLowerCase();
|
|
34
|
+
const num = r.match(/^[v#]?(\d+)$/);
|
|
35
|
+
if (num) {
|
|
36
|
+
const n = Number(num[1]);
|
|
37
|
+
return versions.find((v) => v.version_number === n) ?? null;
|
|
38
|
+
}
|
|
39
|
+
const sem = r.replace(/^v/, '');
|
|
40
|
+
if (/^\d+\.\d+\.\d+$/.test(sem)) {
|
|
41
|
+
return versions.find((v) => semverOf(v) === sem) ?? null;
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
function currentVersion(history) {
|
|
46
|
+
const sorted = sortNewestFirst(history.versions);
|
|
47
|
+
return history.versions.find((v) => v.id === history.current_version_id) ?? sorted[0] ?? null;
|
|
48
|
+
}
|
|
49
|
+
/** Signed-in guard + name/--project resolution. Returns null when unresolved (message already printed). */
|
|
50
|
+
async function resolveForHistory(name, project) {
|
|
51
|
+
if ((0, local_1.isSignedOut)()) {
|
|
52
|
+
(0, local_1.noteIgnoredProject)(project);
|
|
53
|
+
throw new Error(exports.HISTORY_NEEDS_ACCOUNT);
|
|
54
|
+
}
|
|
55
|
+
await (0, api_client_1.ensureAuthed)();
|
|
56
|
+
const projectId = project ? await (0, promptResolver_1.resolveProjectId)(project) : undefined;
|
|
57
|
+
const prompt = await (0, promptResolver_1.resolvePromptByName)(name, { projectId });
|
|
58
|
+
return prompt ? { id: prompt.id, title: prompt.title } : null;
|
|
59
|
+
}
|
|
60
|
+
function versionNotFound(ref, versions) {
|
|
61
|
+
const known = sortNewestFirst(versions).slice(0, 8).map((v) => `v${v.version_number}`).join(', ');
|
|
62
|
+
return new Error(`No version '${ref}'. Known: ${known}${versions.length > 8 ? ', …' : ''} — see \`ple log\`.`);
|
|
63
|
+
}
|