promptlike 0.6.3 → 0.8.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.
@@ -69,6 +69,7 @@ const path = __importStar(require("path"));
69
69
  const format_1 = require("./format");
70
70
  const rank_1 = require("./rank");
71
71
  const settings_1 = require("./settings");
72
+ const fsSafe_1 = require("./fsSafe");
72
73
  exports.CACHE_TTL_MS = 10 * 60 * 1000;
73
74
  /** Background refreshes are at most one per minute (lock file mtime). */
74
75
  const REFRESH_LOCK_MS = 60 * 1000;
@@ -83,11 +84,9 @@ function cacheFile() {
83
84
  return path.join(cacheDir(), 'library.json');
84
85
  }
85
86
  function writePrivate(file, data) {
86
- fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
87
- // Write-then-rename: a hook reading mid-write never sees half a file.
88
- const tmp = `${file}.${process.pid}.tmp`;
89
- fs.writeFileSync(tmp, JSON.stringify(data), { mode: 0o600 });
90
- fs.renameSync(tmp, file);
87
+ // Atomic (temp + rename): a hook reading mid-write never sees half a file,
88
+ // and a symlink planted at `file` is replaced, never written through.
89
+ (0, fsSafe_1.writePrivateFile)(file, JSON.stringify(data));
91
90
  }
92
91
  /** Cached library for `userId`, or null (missing, corrupt, or another account's). */
93
92
  function readCache(userId) {
@@ -171,8 +170,8 @@ function startBackgroundRefresh(opts = {}) {
171
170
  }
172
171
  }
173
172
  try {
174
- fs.mkdirSync(cacheDir(), { recursive: true, mode: 0o700 });
175
- fs.writeFileSync(lock, String(now), { mode: 0o600 });
173
+ (0, fsSafe_1.ensurePrivateDir)(cacheDir());
174
+ (0, fsSafe_1.writePrivateFile)(lock, String(now));
176
175
  (opts.spawner ?? defaultSpawner)(process.execPath, [script, 'suggest', '--refresh-cache']);
177
176
  return true;
178
177
  }
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+ /**
3
+ * Local, append-only version history — `~/.promptlike/history/<slug>/v0001.md`.
4
+ *
5
+ * WHY: signed out, `ple save --force` used to overwrite a prompt for good. The
6
+ * account has versions; the local store now keeps its own, so `ple log`,
7
+ * `ple diff` and `ple rollback` work without an account.
8
+ *
9
+ * RULES (deliberate, and covered by tests):
10
+ * - Append-only. Files are created with the exclusive flag (`wx`), so nothing
11
+ * here ever overwrites or deletes a version. There is no limit and no pruning.
12
+ * - A new version is written only when the prompt BODY changed.
13
+ * - Rollback never rewrites history: the old body becomes a NEW version.
14
+ * - Nothing here touches the network.
15
+ *
16
+ * Each version file is the same Markdown+frontmatter shape as the prompt store
17
+ * (greppable, diffable), plus `version:`, `saved:` and an optional `note:`.
18
+ */
19
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
20
+ if (k2 === undefined) k2 = k;
21
+ var desc = Object.getOwnPropertyDescriptor(m, k);
22
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
23
+ desc = { enumerable: true, get: function() { return m[k]; } };
24
+ }
25
+ Object.defineProperty(o, k2, desc);
26
+ }) : (function(o, m, k, k2) {
27
+ if (k2 === undefined) k2 = k;
28
+ o[k2] = m[k];
29
+ }));
30
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
31
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
32
+ }) : function(o, v) {
33
+ o["default"] = v;
34
+ });
35
+ var __importStar = (this && this.__importStar) || (function () {
36
+ var ownKeys = function(o) {
37
+ ownKeys = Object.getOwnPropertyNames || function (o) {
38
+ var ar = [];
39
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
40
+ return ar;
41
+ };
42
+ return ownKeys(o);
43
+ };
44
+ return function (mod) {
45
+ if (mod && mod.__esModule) return mod;
46
+ var result = {};
47
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
48
+ __setModuleDefault(result, mod);
49
+ return result;
50
+ };
51
+ })();
52
+ Object.defineProperty(exports, "__esModule", { value: true });
53
+ exports.historyRoot = historyRoot;
54
+ exports.historyDir = historyDir;
55
+ exports.listVersions = listVersions;
56
+ exports.latestVersion = latestVersion;
57
+ exports.recordIfChanged = recordIfChanged;
58
+ exports.findVersion = findVersion;
59
+ const fs = __importStar(require("fs"));
60
+ const path = __importStar(require("path"));
61
+ const store = __importStar(require("./localStore"));
62
+ const fsSafe_1 = require("./fsSafe");
63
+ function historyRoot() {
64
+ return path.join(store.localRoot(), 'history');
65
+ }
66
+ function historyDir(slug) {
67
+ return path.join(historyRoot(), slug);
68
+ }
69
+ function versionFile(slug, n) {
70
+ return path.join(historyDir(slug), `v${String(n).padStart(4, '0')}.md`);
71
+ }
72
+ function oneLine(v) {
73
+ return v.replace(/\r?\n/g, ' ').trim();
74
+ }
75
+ function parseVersion(n, raw, slug) {
76
+ const p = store.parse(slug, raw);
77
+ const header = raw.startsWith('---') ? raw.slice(3, Math.max(raw.indexOf('\n---', 3), 3)) : '';
78
+ const note = header.match(/^note:[ \t]*(.*)$/m);
79
+ return {
80
+ version: n,
81
+ saved: p.updated,
82
+ note: note ? note[1].trim() : '',
83
+ title: p.title,
84
+ description: p.description,
85
+ tags: p.tags,
86
+ body: p.body,
87
+ };
88
+ }
89
+ /** All versions, oldest first. Unreadable files are skipped, never fatal. */
90
+ function listVersions(slug) {
91
+ const dir = historyDir(slug);
92
+ if (!fs.existsSync(dir))
93
+ return [];
94
+ const out = [];
95
+ for (const f of fs.readdirSync(dir)) {
96
+ const m = f.match(/^v(\d+)\.md$/);
97
+ if (!m)
98
+ continue;
99
+ try {
100
+ out.push(parseVersion(Number(m[1]), fs.readFileSync(path.join(dir, f), 'utf-8'), slug));
101
+ }
102
+ catch {
103
+ /* a damaged file must not hide the rest of the history */
104
+ }
105
+ }
106
+ return out.sort((a, b) => a.version - b.version);
107
+ }
108
+ function latestVersion(slug) {
109
+ const all = listVersions(slug);
110
+ return all.length > 0 ? all[all.length - 1] : null;
111
+ }
112
+ /** Append one version. Never overwrites: on a number clash it takes the next one. */
113
+ function append(slug, snap, note) {
114
+ const dir = historyDir(slug);
115
+ (0, fsSafe_1.ensurePrivateDir)(dir);
116
+ const saved = new Date().toISOString();
117
+ const base = store.serialize({ slug, ...snap, created: saved, updated: saved });
118
+ const extra = [`version: __N__`, `saved: ${saved}`, ...(note ? [`note: ${oneLine(note)}`] : [])];
119
+ let n = (latestVersion(slug)?.version ?? 0) + 1;
120
+ for (;;) {
121
+ const text = base.replace(/^---\n/, `---\n${extra.join('\n').replace('__N__', String(n))}\n`);
122
+ try {
123
+ (0, fsSafe_1.createPrivateFileExclusive)(versionFile(slug, n), text);
124
+ return parseVersion(n, text, slug);
125
+ }
126
+ catch (err) {
127
+ if (err.code !== 'EEXIST')
128
+ throw err;
129
+ n++; // another process got there first — never overwrite
130
+ }
131
+ }
132
+ }
133
+ const same = (a, b) => a.trim() === b.trim();
134
+ /**
135
+ * Record `current` as a new version if its body differs from the newest one.
136
+ * First contact with a prompt that already exists on disk but has no history
137
+ * (saved before this feature) records what is on disk FIRST, so the text about
138
+ * to be overwritten is not lost. Returns the version written, or null.
139
+ */
140
+ function recordIfChanged(slug, current, options = {}) {
141
+ let latest = latestVersion(slug);
142
+ if (!latest && options.onDisk && options.onDisk.body.trim()) {
143
+ latest = append(slug, options.onDisk, '');
144
+ }
145
+ if (latest && same(latest.body, current.body))
146
+ return null;
147
+ if (!current.body.trim())
148
+ return null;
149
+ return append(slug, current, options.note ?? '');
150
+ }
151
+ /** Resolve `3`, `v3` or `#3`. */
152
+ function findVersion(versions, ref) {
153
+ const m = ref.trim().toLowerCase().match(/^[v#]?(\d+)$/);
154
+ if (!m)
155
+ return null;
156
+ return versions.find((v) => v.version === Number(m[1])) ?? null;
157
+ }
@@ -75,6 +75,7 @@ exports.fillVariables = fillVariables;
75
75
  const fs = __importStar(require("fs"));
76
76
  const os = __importStar(require("os"));
77
77
  const path = __importStar(require("path"));
78
+ const fsSafe_1 = require("./fsSafe");
78
79
  /** Root of the local store. Overridable for tests and for people who relocate it. */
79
80
  function localRoot() {
80
81
  const override = process.env.PROMPTLIKE_HOME;
@@ -168,9 +169,7 @@ function parse(slug, raw) {
168
169
  };
169
170
  }
170
171
  function ensureDir() {
171
- const dir = promptsDir();
172
- if (!fs.existsSync(dir))
173
- fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
172
+ (0, fsSafe_1.ensurePrivateDir)(promptsDir());
174
173
  }
175
174
  function filePath(slug) {
176
175
  return path.join(promptsDir(), `${slug}.md`);
@@ -197,7 +196,8 @@ function save(p) {
197
196
  created: p.created || previous?.created || now,
198
197
  updated: now,
199
198
  };
200
- fs.writeFileSync(filePath(record.slug), serialize(record), { mode: 0o600 });
199
+ // Atomic + 0600; a symlink at the target is replaced, never written through.
200
+ (0, fsSafe_1.writePrivateFile)(filePath(record.slug), serialize(record));
201
201
  return record;
202
202
  }
203
203
  function read(slug) {
@@ -28,7 +28,17 @@ async function resolveProjectId(value) {
28
28
  if (matches.length === 1)
29
29
  return matches[0].id;
30
30
  if (matches.length === 0) {
31
- throw new Error(`No repo matched '${trimmed}'. Run 'ple list' or use the repo's exact name, slug, or id.`);
31
+ // Same short id `ple repo list` prints (8+ hex characters).
32
+ if (SHORT_ID_RE.test(trimmed)) {
33
+ const byPrefix = projects.filter((p) => p.id.toLowerCase().startsWith(lower));
34
+ if (byPrefix.length === 1)
35
+ return byPrefix[0].id;
36
+ if (byPrefix.length > 1) {
37
+ const hint = byPrefix.map((p) => `${(0, format_1.shortId)(p.id)} ${p.name}`).join(', ');
38
+ throw new Error(`'${trimmed}' matched multiple repos (${hint}). Use the full repo id.`);
39
+ }
40
+ }
41
+ throw new Error(`No repo matched '${trimmed}'. Run 'ple repo list' and use the repo's exact name, slug, or id.`);
32
42
  }
33
43
  // Multiple repos share this name — ask for the id.
34
44
  const hint = matches.map((p) => `${(0, format_1.shortId)(p.id)} ${p.name}`).join(', ');
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ /**
3
+ * Repo name validation and `<repo>` reference resolution for `ple repo ...`.
4
+ * Pure functions: no network, no disk — everything here is unit-tested.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.REPO_DESCRIPTION_MAX = exports.REPO_NAME_MAX = void 0;
8
+ exports.slugFromName = slugFromName;
9
+ exports.validateRepoName = validateRepoName;
10
+ exports.validateRepoDescription = validateRepoDescription;
11
+ exports.pickVisibility = pickVisibility;
12
+ exports.parseVisibility = parseVisibility;
13
+ exports.resolveRepoRef = resolveRepoRef;
14
+ const format_1 = require("./format");
15
+ exports.REPO_NAME_MAX = 100;
16
+ exports.REPO_DESCRIPTION_MAX = 500;
17
+ const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
18
+ const SHORT_ID_RE = /^[0-9a-f]{8,}$/i;
19
+ const CONTROL_RE = /[\u0000-\u001f\u007f-\u009f]/;
20
+ /** Same transform the server applies to build the URL slug (`/api/projects`). */
21
+ function slugFromName(name) {
22
+ return name
23
+ .trim()
24
+ .toLowerCase()
25
+ .replace(/[^a-z0-9\-._]+/g, '-')
26
+ .replace(/^[-._]+|[-._]+$/g, '')
27
+ .slice(0, 100)
28
+ .replace(/-+$/, '');
29
+ }
30
+ /**
31
+ * Validate a repo name the same way the server will, so a typo fails here with a
32
+ * fix instead of after a round trip. The server stays the authority (it re-checks
33
+ * everything; this is not a security boundary, only a courtesy).
34
+ *
35
+ * Returns the trimmed name, or throws an Error that says what to change.
36
+ */
37
+ function validateRepoName(raw) {
38
+ const name = raw.trim();
39
+ if (!name)
40
+ throw new Error('Repo name is empty. Example: ple repo create "my-prompts"');
41
+ if (name.length > exports.REPO_NAME_MAX) {
42
+ throw new Error(`Repo name is too long (${name.length} characters, max ${exports.REPO_NAME_MAX}).`);
43
+ }
44
+ if (CONTROL_RE.test(name)) {
45
+ throw new Error('Repo name contains control characters (line breaks, escape codes). Use plain text.');
46
+ }
47
+ if (!/[a-z0-9]/i.test(name)) {
48
+ throw new Error("Repo name needs at least one letter or digit (a-z, 0-9) — it becomes the repo's URL slug.");
49
+ }
50
+ return name;
51
+ }
52
+ function validateRepoDescription(raw) {
53
+ if (raw === undefined)
54
+ return undefined;
55
+ const d = raw.trim();
56
+ if (!d)
57
+ return undefined;
58
+ if (d.length > exports.REPO_DESCRIPTION_MAX) {
59
+ throw new Error(`Description is too long (${d.length} characters, max ${exports.REPO_DESCRIPTION_MAX}).`);
60
+ }
61
+ if (CONTROL_RE.test(d.replace(/\n/g, ' '))) {
62
+ throw new Error('Description contains control characters. Use plain text.');
63
+ }
64
+ return d;
65
+ }
66
+ /**
67
+ * `--private` / `--public` → visibility. Private is the default: a repo should
68
+ * only become public because someone said so.
69
+ */
70
+ function pickVisibility(opts) {
71
+ if (opts.private && opts.public) {
72
+ throw new Error('Choose one: --private or --public (not both).');
73
+ }
74
+ return opts.public ? 'public' : 'private';
75
+ }
76
+ function parseVisibility(value) {
77
+ const v = value.trim().toLowerCase();
78
+ if (v === 'private' || v === 'public')
79
+ return v;
80
+ throw new Error(`Visibility must be 'private' or 'public', got '${value}'.`);
81
+ }
82
+ /**
83
+ * Resolve a user-typed `<repo>` against the repos the account can see:
84
+ * full id, then exact name or slug (case-insensitive), then a short id prefix
85
+ * (8+ hex characters). Ambiguity is reported, never guessed.
86
+ */
87
+ function resolveRepoRef(ref, repos) {
88
+ const value = ref.trim();
89
+ if (!value)
90
+ throw new Error('Give a repo name, slug or id. See: ple repo list');
91
+ if (UUID_RE.test(value)) {
92
+ const byId = repos.find((r) => r.id.toLowerCase() === value.toLowerCase());
93
+ if (byId)
94
+ return byId;
95
+ throw notFound(value);
96
+ }
97
+ const lower = value.toLowerCase();
98
+ const byName = repos.filter((r) => r.name.toLowerCase() === lower || (r.slug ?? '').toLowerCase() === lower);
99
+ if (byName.length === 1)
100
+ return byName[0];
101
+ if (byName.length > 1)
102
+ throw ambiguous(value, byName);
103
+ if (SHORT_ID_RE.test(value)) {
104
+ const byPrefix = repos.filter((r) => r.id.toLowerCase().startsWith(lower));
105
+ if (byPrefix.length === 1)
106
+ return byPrefix[0];
107
+ if (byPrefix.length > 1)
108
+ throw ambiguous(value, byPrefix);
109
+ }
110
+ throw notFound(value);
111
+ }
112
+ function notFound(ref) {
113
+ return new Error(`No repo matched '${ref}'. List yours with: ple repo list`);
114
+ }
115
+ function ambiguous(ref, matches) {
116
+ const hint = matches.map((r) => `${(0, format_1.shortId)(r.id)} ${r.name}`).join(', ');
117
+ return new Error(`'${ref}' matched several repos (${hint}). Use the repo id.`);
118
+ }
@@ -52,6 +52,7 @@ exports.suggestEnabled = suggestEnabled;
52
52
  const fs = __importStar(require("fs"));
53
53
  const os = __importStar(require("os"));
54
54
  const path = __importStar(require("path"));
55
+ const fsSafe_1 = require("./fsSafe");
55
56
  exports.SETTING_KEYS = ['suggest'];
56
57
  /** Config dir (same as the session file). `PROMPTLIKE_CONFIG_DIR` overrides it for tests. */
57
58
  function configDir() {
@@ -76,8 +77,7 @@ function readSettings() {
76
77
  }
77
78
  }
78
79
  function writeSettings(next) {
79
- fs.mkdirSync(configDir(), { recursive: true, mode: 0o700 });
80
- fs.writeFileSync(settingsFile(), JSON.stringify(next, null, 2) + '\n', { mode: 0o600 });
80
+ (0, fsSafe_1.writePrivateFile)(settingsFile(), JSON.stringify(next, null, 2) + '\n');
81
81
  }
82
82
  /** Parse a user-typed on/off value. */
83
83
  function parseOnOff(value) {
@@ -0,0 +1,197 @@
1
+ "use strict";
2
+ /**
3
+ * Command table for `ple`: registers every command with `commander`. Each
4
+ * command's real logic lives under `src/commands/` — this file only does argument
5
+ * parsing, the grouped `--help`, and the global error wrapper (exit codes).
6
+ * Split from index.ts so tests can build the program without running it.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.runWithErrorHandler = runWithErrorHandler;
10
+ exports.buildProgram = buildProgram;
11
+ const commander_1 = require("commander");
12
+ const constants_1 = require("./lib/constants");
13
+ const format_1 = require("./lib/format");
14
+ const login_1 = require("./commands/login");
15
+ const logout_1 = require("./commands/logout");
16
+ const list_1 = require("./commands/list");
17
+ const copy_1 = require("./commands/copy");
18
+ const show_1 = require("./commands/show");
19
+ const search_1 = require("./commands/search");
20
+ const get_1 = require("./commands/get");
21
+ const improve_1 = require("./commands/improve");
22
+ const loop_1 = require("./commands/loop");
23
+ const save_1 = require("./commands/save");
24
+ const sync_1 = require("./commands/sync");
25
+ const export_1 = require("./commands/export");
26
+ const stats_1 = require("./commands/stats");
27
+ const import_1 = require("./commands/import");
28
+ const log_1 = require("./commands/log");
29
+ const diff_1 = require("./commands/diff");
30
+ const rollback_1 = require("./commands/rollback");
31
+ const suggest_1 = require("./commands/suggest");
32
+ const config_1 = require("./commands/config");
33
+ const repo_1 = require("./commands/repo");
34
+ const errors_1 = require("./lib/errors");
35
+ const help_1 = require("./help");
36
+ /**
37
+ * A single global try/catch — consistent error output and exit codes for every
38
+ * command: 1 = fix your input/login/plan, 2 = network/server problem, retry later.
39
+ * A command that already set `process.exitCode` keeps its own code.
40
+ */
41
+ function runWithErrorHandler(fn) {
42
+ return async (...args) => {
43
+ try {
44
+ await fn(...args);
45
+ }
46
+ catch (err) {
47
+ const message = err instanceof Error ? err.message : String(err);
48
+ console.error(format_1.c.error(`✗ ${message}`));
49
+ process.exit(process.exitCode || (0, errors_1.exitCodeFor)(err));
50
+ }
51
+ };
52
+ }
53
+ function buildProgram() {
54
+ const program = new commander_1.Command();
55
+ program
56
+ .name(constants_1.CLI_NAME)
57
+ .description('Your PromptLikeEngineer prompt library in the terminal — works offline, no account needed to start')
58
+ .version(constants_1.CLI_VERSION)
59
+ .configureHelp({ formatHelp: help_1.formatRootHelp })
60
+ .showSuggestionAfterError();
61
+ const scope = (cmd) => cmd.option('--project <repo>', 'Limit to one repo (name, slug or id) — use when titles collide');
62
+ // ---- prompts ------------------------------------------------------------
63
+ program
64
+ .command('save <title>')
65
+ .description('Save a prompt locally — no account needed')
66
+ .option('-m, --message <text>', 'Prompt body (or pipe it via stdin)')
67
+ .option('-d, --description <text>', 'Short description')
68
+ .option('-t, --tag <name>', 'Tag (repeatable)', save_1.collectTag, [])
69
+ .option('-f, --force', 'Overwrite an existing local prompt')
70
+ .addHelpText('after', '\nExamples:\n ple save "code review" -m "Review this diff: {{diff}}"\n pbpaste | ple save "bug triage" --tag triage')
71
+ .action(runWithErrorHandler(save_1.saveCommand));
72
+ scope(program
73
+ .command('get <name>')
74
+ .description('Print a prompt raw to stdout; fill {{variables}} (agent/pipe friendly)')
75
+ .option('-v, --var <keyval>', 'Fill a variable — key=value (repeatable)', get_1.collectVar, {})
76
+ .option('-c, --copy', 'Also copy the output to the clipboard'))
77
+ .addHelpText('after', '\nExample:\n ple get "code review" --var diff="$(git diff)" | claude')
78
+ .action(runWithErrorHandler(get_1.getCommand));
79
+ scope(program.command('show <name>').description('Show a prompt in the terminal')).action(runWithErrorHandler(show_1.showCommand));
80
+ scope(program.command('copy <name>').description('Copy a prompt to the clipboard (by title or short id)')).action(runWithErrorHandler(copy_1.copyCommand));
81
+ scope(program
82
+ .command('list')
83
+ .description('List your prompts')
84
+ .option('-t, --tag <name>', 'Filter by a specific tag')
85
+ .option('-l, --limit <n>', 'Max number of rows (default 30)', '30'))
86
+ .addHelpText('after', '\nExamples:\n ple list --tag debug\n ple list --project my-prompts')
87
+ .action(runWithErrorHandler(list_1.listCommand));
88
+ program
89
+ .command('search <keyword>')
90
+ .description('Search titles and descriptions (signed out: also local prompt bodies and tags)')
91
+ .action(runWithErrorHandler(search_1.searchCommand));
92
+ scope(program
93
+ .command('log <name>')
94
+ .description('Version history of a prompt (* = current). Signed out: the local history')
95
+ .option('-l, --limit <n>', 'Max versions to show (default 20)', '20')
96
+ .option('--json', 'Print as JSON')).action(runWithErrorHandler(log_1.logCommand));
97
+ scope(program
98
+ .command('diff <name> [a] [b]')
99
+ .description('Diff two versions (default: previous ↔ current). Refs: 3, v3 or 1.0.2')
100
+ .option('--no-color', 'Plain output (automatic when piped)')).action(runWithErrorHandler((name, a, b, opts) => (0, diff_1.diffCommand)(name, a, b, opts)));
101
+ scope(program
102
+ .command('rollback <name> <version>')
103
+ .description('Restore an old version as a new one — nothing is deleted (signed out: local history)')
104
+ .option('-y, --yes', 'Skip the confirmation prompt')).action(runWithErrorHandler((name, version, opts) => (0, rollback_1.rollbackCommand)(name, version, opts)));
105
+ scope(program
106
+ .command('improve <name>')
107
+ .option('-p, --pick <n>', 'Non-interactive: auto-pick variant N (1..3), 0 to cancel — for scripts/agents')
108
+ .description('Generate AI variants of a prompt, pick a winner, save it as a new version (Pro)')
109
+ .option('-f, --focus <hint>', "Steer the variants (e.g. 'shorter', 'more explicit output format')")).action(runWithErrorHandler(improve_1.improveCommand));
110
+ scope(program
111
+ .command('loop <name>')
112
+ .description('Multi-round improve — optionally test each variant with your own agent command (Pro)')
113
+ .option('-e, --exec <cmd>', 'Test each variant: prompt passed via PLE_PROMPT env + stdin; {} placeholder substituted')
114
+ .option('-r, --rounds <n>', 'Number of improvement rounds', '1')
115
+ .option('-f, --focus <hint>', 'Steer the variants')
116
+ .option('-p, --pick <n>', 'Non-interactive: auto-pick variant N each round + auto-continue — for scripts/agents')).action(runWithErrorHandler(loop_1.loopCommand));
117
+ // ---- repos --------------------------------------------------------------
118
+ const repo = program
119
+ .command('repo')
120
+ .description('Create and manage repos (collections of prompts) in your account')
121
+ .addHelpText('after', '\nExamples:\n ple repo create "team-prompts" --description "Shared review prompts"\n ple repo list\n ple repo visibility team-prompts public --yes\n\nRepos are private unless you say --public. Deleting a repo is only possible on the web.');
122
+ repo.command('create <name>')
123
+ .description('Create a repo (private by default)')
124
+ .option('--private', 'Only you and people you invite can see it (default)')
125
+ .option('--public', 'Anyone can read its public prompts')
126
+ .option('-d, --description <text>', 'Short description (max 500 characters)')
127
+ .option('--json', 'Print the result as JSON')
128
+ .action(runWithErrorHandler(repo_1.repoCreateCommand));
129
+ repo.command('list')
130
+ .description('List your repos with visibility, your role and prompt count')
131
+ .option('--json', 'Print as JSON')
132
+ .action(runWithErrorHandler(repo_1.repoListCommand));
133
+ repo.command('show <repo>')
134
+ .description('Show one repo (name, slug or id)')
135
+ .option('--json', 'Print as JSON')
136
+ .action(runWithErrorHandler(repo_1.repoShowCommand));
137
+ repo.command('visibility <repo> <value>')
138
+ .description('Make a repo private or public (owner only): value is private | public')
139
+ .option('-y, --yes', 'Confirm without asking (required when making a repo public in a script)')
140
+ .option('--json', 'Print the result as JSON')
141
+ .action(runWithErrorHandler((ref, value, opts) => (0, repo_1.repoVisibilityCommand)(ref, value, opts)));
142
+ // ---- account ------------------------------------------------------------
143
+ program
144
+ .command('login')
145
+ .description('Sign in with email + password; store the session under ~/.config/promptlike/')
146
+ .action(runWithErrorHandler(login_1.loginCommand));
147
+ program
148
+ .command('logout')
149
+ .description('Delete the local session file')
150
+ .action(runWithErrorHandler(logout_1.logoutCommand));
151
+ // ---- import / export / sync --------------------------------------------
152
+ program
153
+ .command('sync')
154
+ .description('Upload your local prompts to your account (one-way, explicit)')
155
+ .option('--dry-run', 'List what would be uploaded, change nothing')
156
+ .action(runWithErrorHandler(sync_1.syncCommand));
157
+ program
158
+ .command('import')
159
+ .description('Bring in prompts you already have: .claude/commands, SKILL.md, .cursor/commands, ~/.codex/prompts')
160
+ .option('--scan', 'Scan this repo and your home folder for agent prompt files')
161
+ .option('--dry-run', 'Only show what was found, import nothing')
162
+ .option('-a, --all', 'Import everything new without asking')
163
+ .option('--project <repo>', 'Import into this repo (signed in)')
164
+ .action(runWithErrorHandler((opts) => (0, import_1.importCommand)(opts)));
165
+ scope(program
166
+ .command('export [name]')
167
+ .description('Export a prompt (or a whole repo with --project) as an AGENTS.md section or an Agent Skill (SKILL.md)')
168
+ .requiredOption('--format <format>', 'agents-md | skill')
169
+ .option('-o, --out <path>', 'agents-md: file to write (default stdout) · skill: parent folder (default .)')
170
+ .option('--zip', 'skill: write <name>.zip (upload in Claude) instead of a folder')
171
+ .option('-f, --force', 'Overwrite an existing file or folder (never through a symbolic link)')).action(runWithErrorHandler(export_1.exportCommand));
172
+ // ---- insights & settings ------------------------------------------------
173
+ program
174
+ .command('stats')
175
+ .description('How your library is used — uses by surface, most used, gathering dust')
176
+ .option('-r, --range <days>', 'Window: 7, 30 or 365 (Free: 7)', '7')
177
+ .option('--json', 'Print the raw summary as JSON')
178
+ .action(runWithErrorHandler(stats_1.statsCommand));
179
+ program
180
+ .command('suggest [text...]')
181
+ .description('Which saved prompt fits this task? Local match — the text never leaves your machine')
182
+ .option('--json', 'Print matches as JSON')
183
+ .option('-l, --limit <n>', 'Max matches (default 3)', '3')
184
+ .option('--hook', 'Claude Code UserPromptSubmit mode: read hook JSON on stdin, print a short hint or nothing')
185
+ .option('--refresh-cache', 'Refresh the local library cache from your account and exit')
186
+ .action(runWithErrorHandler((text, opts) => (0, suggest_1.suggestCommand)(text ?? [], opts)));
187
+ const configCmd = program.command('config').description('CLI preferences (suggest on|off)');
188
+ configCmd
189
+ .command('get [key]')
190
+ .description('Show a setting (or all)')
191
+ .action(runWithErrorHandler(config_1.configGetCommand));
192
+ configCmd
193
+ .command('set <key> <value>')
194
+ .description('Change a setting, e.g. `ple config set suggest off`')
195
+ .action(runWithErrorHandler(config_1.configSetCommand));
196
+ return program;
197
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "promptlike",
3
- "version": "0.6.3",
3
+ "version": "0.8.0",
4
4
  "description": "Terminal access to your PromptLikeEngineer prompt library - search, read, and copy your saved prompts without leaving the shell.",
5
5
  "bin": {
6
6
  "ple": "dist/index.js"