promptlike 0.7.0 → 0.9.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 CHANGED
@@ -1,5 +1,69 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.9.0 — 2026-10-19
4
+
5
+ - **New: conditional blocks in templates.** `{{#if var}}…{{else}}…{{/if}}` and
6
+ `{{#unless var}}…{{/unless}}` keep or drop text depending on a variable (set = a value
7
+ that is not empty, `false` or `0`; a variable you do not pass counts as not set). Text
8
+ only, nothing is executed; nesting is limited to 5 levels. Works in `ple get` and
9
+ `ple copy` with `--var`.
10
+ - **New: deployment labels.** `ple tag <name> <version> <label>` points a label
11
+ (`production`, `staging`, …) at a version; `--list` shows labels and recent moves,
12
+ `--remove <label>` deletes one. Every move is logged and the version history is never
13
+ touched. Needs an account and editor access.
14
+ - **New: `ple get --label <name>` and `ple copy --label <name>`** read the version a label
15
+ points at instead of the current one.
16
+
17
+ ## 0.8.0 — 2026-10-17
18
+
19
+ - **New: `ple repo`.** Create and manage repos from the terminal.
20
+ `ple repo create <name> [--private|--public] [-d <text>]` (private unless you
21
+ say `--public`), `ple repo list` (visibility, your role, prompt count),
22
+ `ple repo show <repo>`, `ple repo visibility <repo> private|public` (owner
23
+ only; making a repo public asks first, `--yes` in scripts). `<repo>` is a name,
24
+ slug, id or the 8-character id that `ple repo list` prints. All four take
25
+ `--json` (stable shape, see the README). There is no delete command: deleting a
26
+ repo cannot be undone, so it stays on the web. The server enforces the plan's
27
+ repo limit (Free: 1), the name rules, slug uniqueness and owner-only visibility;
28
+ the CLI only checks first so mistakes fail faster.
29
+ - **New: `ple list --project <repo>`** (the README listed it as missing). The short
30
+ repo id from `ple repo list` now also works for every `--project` option.
31
+ - **`ple --help` is grouped** (Prompts, Repos, Account, Import / export / sync,
32
+ Insights & settings) with examples and the exit codes. Every old command and
33
+ option still works unchanged.
34
+ - **Exit codes are consistent:** 0 success; 1 you can fix it (bad input, not
35
+ signed in, not found, not allowed, plan limit, conflict); 2 try again later (no
36
+ network, timeout, rate limit, server error). Before, every failure exited 1.
37
+ A script that tested for exactly `1` should test for non-zero.
38
+ - **Security: the API URL must be https.** `PROMPTLIKE_API_URL` now has to be https
39
+ (plain http only for localhost / 127.0.0.1 / [::1]), without a username, password,
40
+ query or fragment. A bad value stops the command before any request, so the
41
+ token and your password can never be sent to an insecure or mistyped address.
42
+ - **Security: no redirects.** The CLI no longer follows HTTP redirects (a redirect
43
+ could replay your login or token at another address); it stops with a message.
44
+ - **Security: session and local files.** The session file is written atomically,
45
+ `0600` in a `0700` folder; a looser existing file or folder is tightened. A
46
+ symbolic link at `config.json`, a prompt file, a history file or an export target
47
+ is never written through (the link is replaced or the export refused); a link at
48
+ `config.json` is not trusted as a session. `ple logout` now also removes a corrupt
49
+ or unreadable session file instead of reporting "Not logged in" and leaving it.
50
+ Settings, the suggestion cache and `~/.promptlike` files get the same treatment.
51
+ - **Security: `ple export`** refuses to write through a symbolic link (even with
52
+ `--force`) and treats a dangling link as existing; skill files must stay inside the
53
+ chosen folder.
54
+ - **Security: server text on your terminal.** Titles, descriptions and repo names
55
+ from the server (including shared repos) have terminal escape sequences and
56
+ control characters removed before they are printed; `ple show` does the same for
57
+ the body. `ple get` and `ple copy` still output the prompt byte for byte.
58
+ - **Security: responses are checked.** A sign-in response without proper tokens is
59
+ rejected before anything is written to disk; repo rows from the server are
60
+ validated and fall back to the most restrictive reading (private, viewer). A
61
+ `Retry-After` header is only echoed when it is a plain number.
62
+ - No environment variable can hold the token: the only place a session lives is
63
+ `config.json`. Tokens are never printed or put on a command line.
64
+ - **Docs:** README documents `ple repo`, the `--json` shapes, exit codes and the
65
+ security behavior above.
66
+
3
67
  ## 0.7.0 — 2026-10-15
4
68
 
5
69
  - **Local version history (no account needed):** `ple save` now keeps an
package/README.md CHANGED
@@ -20,7 +20,7 @@ diffable, and yours. Nothing leaves your machine until you ask it to.
20
20
 
21
21
  **Signing in is the upgrade, not the door.** A free
22
22
  [promptlikeengineer.com](https://promptlikeengineer.com) account adds version
23
- history with diff and rollback (Free holds up to 3 versions of each prompt; the 4th save asks you to upgrade),
23
+ history with diff and rollback (Free holds up to 10 versions of each prompt; the 11th save asks you to upgrade),
24
24
  the web editor, and the same library in Claude Code and other MCP clients.
25
25
  Bring your local prompts up with one explicit command:
26
26
 
@@ -37,11 +37,13 @@ ple sync # one-way, local → account; local files are kept
37
37
  1. [Install](#install)
38
38
  2. [Quick start](#quick-start)
39
39
  3. [Commands](#commands)
40
- 4. [Configuration](#configuration)
41
- 5. [How it works](#how-it-works)
42
- 6. [Troubleshooting](#troubleshooting)
43
- 7. [Feedback](#feedback)
44
- 8. [License](#license)
40
+ 4. [Exit codes](#exit-codes)
41
+ 5. [Security notes](#security-notes)
42
+ 6. [Configuration](#configuration)
43
+ 7. [How it works](#how-it-works)
44
+ 8. [Troubleshooting](#troubleshooting)
45
+ 9. [Feedback](#feedback)
46
+ 10. [License](#license)
45
47
 
46
48
  ---
47
49
 
@@ -126,7 +128,7 @@ Password: ********
126
128
  Removes the local session file. The session itself expires naturally on its
127
129
  own clock — this just clears the local copy.
128
130
 
129
- ### `ple list [--tag <name>] [--limit <n>]`
131
+ ### `ple list [--tag <name>] [--limit <n>] [--project <repo>]`
130
132
 
131
133
  Lists every prompt your account has access to. The server scopes results to
132
134
  you automatically.
@@ -140,8 +142,58 @@ ID TITLE UPDATED
140
142
 
141
143
  $ ple list --tag debug # filter by tag (server-side)
142
144
  $ ple list --limit 50 # default 30, max 100
145
+ $ ple list --project my-prompts # only one repo (name, slug or id)
143
146
  ```
144
147
 
148
+ ### `ple repo` — create and manage repos
149
+
150
+ A repo is a collection of prompts in your account. Needs an account
151
+ (`ple login`); signed out, the commands say so.
152
+
153
+ ```bash
154
+ $ ple repo create "team-prompts" --description "Shared review prompts"
155
+ ✓ Created private repo 'team-prompts' (team-prompts, 1a2b3c4d)
156
+ Private: only you and people you invite can see it.
157
+ Next: ple import --scan --project 1a2b3c4d (or ple sync, then move prompts on the web)
158
+
159
+ $ ple repo list
160
+ ID NAME VISIBILITY ROLE PROMPTS UPDATED
161
+ ──────── ────────────────────────────── ────────── ────── ─────── ──────────
162
+ 1a2b3c4d team-prompts private owner 0 now
163
+ 9f8e7d6c Open prompts public owner 12 3d ago
164
+
165
+ $ ple repo show team-prompts
166
+ $ ple repo visibility team-prompts public # asks first; --yes in scripts
167
+ ✓ 'team-prompts' is now public.
168
+ ```
169
+
170
+ | Command | What it does |
171
+ |---|---|
172
+ | `ple repo create <name> [--private\|--public] [-d <text>] [--json]` | Creates a repo. **Private unless you pass `--public`.** Name: 1–100 characters, plain text, at least one letter or digit (it becomes the URL slug). Description: up to 500 characters. |
173
+ | `ple repo list [--json]` | Every repo you own or belong to: visibility, your role, prompt count. |
174
+ | `ple repo show <repo> [--json]` | One repo. `<repo>` = name, slug, id, or the 8-character id from `ple repo list`. |
175
+ | `ple repo visibility <repo> private\|public [--yes] [--json]` | Owner only. Going public asks for confirmation (a script must pass `--yes`); going private never asks. |
176
+
177
+ The server enforces the rules, not just the CLI: you must be signed in, Free
178
+ includes 1 repo (hitting the limit says so and links the pricing page), names and URL slugs must be valid and unique among your repos
179
+ (a clash says "pick a different name"), and only the owner can change a repo's
180
+ visibility. Private repos are available on every plan. A repo you do not own or
181
+ belong to is reported as "not found". There is **no delete command**: deleting
182
+ a repo cannot be undone, so it is only possible on the web.
183
+
184
+ `--json` prints one stable object and nothing else:
185
+
186
+ ```json
187
+ { "ok": true, "repo": { "id": "…", "name": "team-prompts", "slug": "team-prompts",
188
+ "description": null, "visibility": "private", "role": "owner",
189
+ "prompt_count": 0, "member_count": 1,
190
+ "created_at": "2026-10-17T09:00:00Z", "updated_at": "2026-10-17T09:00:00Z" } }
191
+ ```
192
+
193
+ `list` prints `{ "repos": [ … ] }` with the same repo objects; `show` prints
194
+ `{ "repo": { … } }`; `visibility` prints `{ "ok": true, "changed": true|false, "repo": { … } }`.
195
+ Keys are only ever added, never renamed or removed, within 0.x minor releases.
196
+
145
197
  ### `ple copy <name>`
146
198
 
147
199
  Looks up a prompt by title substring (case-insensitive) or short ID, joins
@@ -187,6 +239,34 @@ $ ple get "code review" --var lang=python --copy
187
239
  Unfilled `{{variable}}` placeholders are left intact (not silently dropped) and
188
240
  reported on stderr.
189
241
 
242
+ **Conditional blocks.** `{{#if var}}…{{else}}…{{/if}}` and `{{#unless var}}…{{/unless}}`
243
+ keep or drop text depending on a variable. A variable counts as set when it has a
244
+ value that is not empty, `false` or `0`; a condition variable you do not pass is
245
+ treated as false. Text only — nothing is executed — and nesting is limited to 5
246
+ levels (an unbalanced or deeper template is left as plain text).
247
+
248
+ ```bash
249
+ $ ple get "pr review" --var strict=1 --var diff="$(git diff)"
250
+ # template: Review this diff.{{#if strict}} Flag every style nit.{{/if}}
251
+ ```
252
+
253
+ `--label <name>` reads the version a deployment label points at instead of the
254
+ current one (see `ple tag`). `ple copy` accepts the same `--var` and `--label`.
255
+
256
+ ### `ple tag <name> <version> <label>`
257
+
258
+ Point a deployment label (`production`, `staging`, any `a-z0-9._-` up to 32 chars)
259
+ at one version of a prompt. Needs an account (labels live on the server) and editor
260
+ access. Moving a label never touches the version history, and every move is logged
261
+ (who, when, from version, to version).
262
+
263
+ ```bash
264
+ ple tag "code review" 3 production # label v3 (moves it if it was elsewhere)
265
+ ple tag "code review" --list # labels + recent moves
266
+ ple tag "code review" --remove staging
267
+ ple get "code review" --label production
268
+ ```
269
+
190
270
  ### `ple improve <name> [--focus <hint>]`
191
271
 
192
272
  Loop Engineering, single round (**Pro**). The API generates 2-3 AI variants of
@@ -399,6 +479,38 @@ sub-command.
399
479
 
400
480
  ---
401
481
 
482
+ ## Exit codes
483
+
484
+ | Code | Meaning | Examples |
485
+ |---|---|---|
486
+ | `0` | Success | |
487
+ | `1` | You can fix it | bad input, not signed in, not found, not allowed, plan limit, name already used |
488
+ | `2` | Try again later | no network, timeout, rate limited, server error (5xx) |
489
+
490
+ Scripts should treat any non-zero code as failure; `2` is the one worth retrying.
491
+
492
+ ## Security notes
493
+
494
+ - **Where your session lives:** `~/.config/promptlike/config.json`, mode `0600`
495
+ inside a `0700` folder (a looser existing file or folder is tightened). It is
496
+ written atomically and never through a symbolic link. There is no environment
497
+ variable for the token, the token is never printed or passed on a command line,
498
+ and `ple logout` deletes the file (also when it is corrupt).
499
+ - **HTTPS only.** `PROMPTLIKE_API_URL` must be https (plain http only for
500
+ `localhost`, `127.0.0.1`, `[::1]`), without credentials, query or fragment. An
501
+ invalid value stops the command before anything is sent. Redirects are never
502
+ followed. Requests time out (15 s reads, 30 s writes) and are never retried
503
+ automatically.
504
+ - **Files:** `ple export` refuses to overwrite without `--force` and never writes
505
+ through a symbolic link; local prompts, history and cache are `0600`.
506
+ - **Terminal safety:** titles and descriptions that come from the server have
507
+ escape sequences and control characters removed before they are printed.
508
+ - **No shell:** `ple copy` runs the clipboard tool directly and sends the text on
509
+ its standard input. The one deliberate exception is `ple loop --exec`, which runs
510
+ *your own* command through your shell (see the note there).
511
+
512
+ ---
513
+
402
514
  ## Configuration
403
515
 
404
516
  | Path | Purpose | Permissions |
@@ -426,7 +538,8 @@ you to run `ple login`.
426
538
  ### Optional environment variables
427
539
 
428
540
  The CLI ships with the production API URL baked in. You can point it at a
429
- different deployment (e.g. a local dev server) for testing:
541
+ different deployment (e.g. a local dev server) for testing. The URL must be
542
+ https, except for `localhost` / `127.0.0.1` / `[::1]`:
430
543
 
431
544
  ```bash
432
545
  export PROMPTLIKE_API_URL="http://localhost:3000"
@@ -441,6 +554,8 @@ to configure.
441
554
  | `PLE_SUGGEST=off` | `ple suggest --hook` stays silent |
442
555
  | `PLE_SURFACE`, `PLE_VIA` | How `copy/get/show` report a use (e.g. `hook`, `suggestion`) |
443
556
  | `PROMPTLIKE_HOME` | Local store location (default `~/.promptlike`) |
557
+ | `PROMPTLIKE_CONFIG_DIR` | Session / settings / cache folder (default `~/.config/promptlike`) |
558
+ | `PROMPTLIKE_API_URL` | API address (https only, see above) |
444
559
 
445
560
  ---
446
561
 
@@ -461,6 +576,7 @@ to configure.
461
576
  │ POST /api/auth/cli/login │
462
577
  │ GET /api/prompts?tag&search&limit │
463
578
  │ GET /api/prompts/{id} │
579
+ │ GET/POST /api/projects (repos) │
464
580
  │ rate limiting · validation · RLS │
465
581
  └──────────────────────────────────────┘
466
582
  ```
@@ -491,6 +607,11 @@ to configure.
491
607
  | `'X' matched multiple prompts.` | Substring matched several rows | Use a more specific name or the short ID |
492
608
  | `Rate limited. Try again in Ns.` | Too many requests in a short window | Wait the suggested seconds and retry |
493
609
  | `Cannot reach <url>. Check your connection.` | Network / wrong `PROMPTLIKE_API_URL` | Check connectivity or unset the override |
610
+ | `PROMPTLIKE_API_URL must use https …` | The override is plain http (or not a URL) | Use an https address, or unset it; http works only for localhost |
611
+ | `Your plan's repo limit is reached …` | Free includes 1 repo | Use your existing repo (`ple repo list`) or upgrade |
612
+ | `You already have a repo with that name …` | The name's URL slug is taken | Pick a different name |
613
+ | `Only the owner can change a repo's visibility` | You are an admin/editor/viewer there | Ask the owner |
614
+ | `Making '…' public needs confirmation` | Non-interactive run | Re-run with `--yes` |
494
615
 
495
616
  ---
496
617
 
@@ -500,7 +621,7 @@ What this CLI does **not** do yet:
500
621
 
501
622
  - Delete prompts (`ple save` creates and updates; deleting is done on the web)
502
623
  - `ple search` over version body (`content`); needs a server-side full-text index
503
- - `--project <name>` filter on `ple list`
624
+ - Delete a repo (`ple repo` creates, lists, shows and changes visibility; deleting is done on the web)
504
625
  - Interactive picker (think `fzf`-style)
505
626
  - Configurable color theme
506
627
 
@@ -2,18 +2,22 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.copyCommand = copyCommand;
4
4
  const api_client_1 = require("../lib/api-client");
5
+ const tag_1 = require("./tag");
5
6
  const local_1 = require("./local");
6
7
  const promptResolver_1 = require("../lib/promptResolver");
7
8
  const clipboard_1 = require("../lib/clipboard");
8
9
  const format_1 = require("../lib/format");
10
+ const promptVariables_1 = require("../lib/promptVariables");
9
11
  /**
10
12
  * `ple copy <name>` — resolve a prompt by title (or short id) and copy its
11
13
  * content to the system clipboard.
12
14
  */
13
15
  async function copyCommand(name, options = {}) {
14
16
  if ((0, local_1.isSignedOut)()) {
17
+ if (options.label)
18
+ throw new Error("Deployment labels need an account (they live on the server). Run 'ple login' first.");
15
19
  (0, local_1.noteIgnoredProject)(options.project);
16
- await (0, local_1.localCopy)(name);
20
+ await (0, local_1.localCopy)(name, options.var ?? {});
17
21
  return;
18
22
  }
19
23
  await (0, api_client_1.ensureAuthed)();
@@ -23,18 +27,22 @@ async function copyCommand(name, options = {}) {
23
27
  process.exitCode = 1;
24
28
  return;
25
29
  }
26
- const version = (0, promptResolver_1.fetchPromptContent)(prompt);
30
+ const version = options.label
31
+ ? await (0, api_client_1.getLabeledVersion)(prompt.id, (0, tag_1.normalizeLabel)(options.label))
32
+ : (0, promptResolver_1.fetchPromptContent)(prompt);
27
33
  if (!version) {
28
34
  console.error(format_1.c.error(`'${prompt.title}' has no usable version.`));
29
35
  process.exitCode = 1;
30
36
  return;
31
37
  }
32
- const text = (0, format_1.joinPromptParts)(version);
33
- if (!text.trim()) {
38
+ const raw = (0, format_1.joinPromptParts)(version);
39
+ if (!raw.trim()) {
34
40
  console.error(format_1.c.error(`'${prompt.title}' has empty content.`));
35
41
  process.exitCode = 1;
36
42
  return;
37
43
  }
44
+ // Resolves {{#if}} blocks and fills --var values (plain unfilled {{vars}} stay as-is).
45
+ const text = (0, promptVariables_1.fillVariables)(raw, options.var ?? {});
38
46
  try {
39
47
  await (0, clipboard_1.copyToClipboard)(text);
40
48
  (0, api_client_1.recordPromptUse)(prompt.id); // Most Used verisi (REV-6) — fire-and-forget
@@ -41,6 +41,7 @@ const local_1 = require("./local");
41
41
  const store = __importStar(require("../lib/localStore"));
42
42
  const promptResolver_1 = require("../lib/promptResolver");
43
43
  const format_1 = require("../lib/format");
44
+ const fsSafe_1 = require("../lib/fsSafe");
44
45
  const agentExport_1 = require("../lib/agentExport");
45
46
  /** Hard cap for a repo export — 10 pages × 100. */
46
47
  const MAX_PAGES = 10;
@@ -80,9 +81,19 @@ async function collectRemoteRepo(projectId) {
80
81
  return out;
81
82
  }
82
83
  function ensureWritable(target, force) {
83
- if (fs.existsSync(target) && !force) {
84
+ // lstat-based: a dangling symlink counts as "exists" (existsSync said no and
85
+ // the write then created the link's target), and a link is never written through.
86
+ if ((0, fsSafe_1.pathExists)(target) && !force) {
84
87
  throw new Error(`${target} already exists. Re-run with --force to overwrite.`);
85
88
  }
89
+ (0, fsSafe_1.assertNotSymlink)(target);
90
+ }
91
+ /** Every file of an export must land inside the chosen folder (no `..`, no absolute paths). */
92
+ function assertInside(parent, target) {
93
+ const rel = path.relative(parent, target);
94
+ if (rel === '' || rel.startsWith('..') || path.isAbsolute(rel)) {
95
+ throw new Error(`Refusing to write outside ${parent}: ${target}`);
96
+ }
86
97
  }
87
98
  function writeSkill(skill, options) {
88
99
  const parent = path.resolve(options.out ?? '.');
@@ -97,6 +108,8 @@ function writeSkill(skill, options) {
97
108
  ensureWritable(folder, options.force);
98
109
  for (const f of skill.files) {
99
110
  const target = path.join(parent, ...f.path.split('/'));
111
+ assertInside(parent, target);
112
+ (0, fsSafe_1.assertNotSymlink)(target);
100
113
  fs.mkdirSync(path.dirname(target), { recursive: true });
101
114
  fs.writeFileSync(target, f.content, 'utf-8');
102
115
  }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getCommand = getCommand;
4
4
  exports.collectVar = collectVar;
5
5
  const api_client_1 = require("../lib/api-client");
6
+ const tag_1 = require("./tag");
6
7
  const local_1 = require("./local");
7
8
  const promptResolver_1 = require("../lib/promptResolver");
8
9
  const clipboard_1 = require("../lib/clipboard");
@@ -22,6 +23,8 @@ const promptVariables_1 = require("../lib/promptVariables");
22
23
  */
23
24
  async function getCommand(name, options = {}) {
24
25
  if ((0, local_1.isSignedOut)()) {
26
+ if (options.label)
27
+ throw new Error("Deployment labels need an account (they live on the server). Run 'ple login' first.");
25
28
  (0, local_1.noteIgnoredProject)(options.project);
26
29
  await (0, local_1.localGet)(name, options.var ?? {}, options.copy === true);
27
30
  return;
@@ -33,7 +36,9 @@ async function getCommand(name, options = {}) {
33
36
  process.exitCode = 1;
34
37
  return;
35
38
  }
36
- const version = (0, promptResolver_1.fetchPromptContent)(prompt);
39
+ const version = options.label
40
+ ? await (0, api_client_1.getLabeledVersion)(prompt.id, (0, tag_1.normalizeLabel)(options.label))
41
+ : (0, promptResolver_1.fetchPromptContent)(prompt);
37
42
  if (!version) {
38
43
  console.error(format_1.c.error(`'${prompt.title}' has no usable version.`));
39
44
  process.exitCode = 1;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.listCommand = listCommand;
4
4
  const api_client_1 = require("../lib/api-client");
5
5
  const local_1 = require("./local");
6
+ const promptResolver_1 = require("../lib/promptResolver");
6
7
  const constants_1 = require("../lib/constants");
7
8
  const format_1 = require("../lib/format");
8
9
  const libraryCache_1 = require("../lib/libraryCache");
@@ -17,11 +18,13 @@ async function listCommand(options) {
17
18
  const limit = Math.max(1, Math.min(100, parseInt(options.limit ?? '30', 10) || 30));
18
19
  // Signed out → the local store. The install has to be useful on its own.
19
20
  if ((0, local_1.isSignedOut)()) {
21
+ (0, local_1.noteIgnoredProject)(options.project);
20
22
  (0, local_1.localList)({ tag: options.tag, limit });
21
23
  return;
22
24
  }
23
25
  await (0, api_client_1.ensureAuthed)();
24
- const prompts = await (0, api_client_1.listPrompts)({ tag: options.tag, limit });
26
+ const projectId = options.project ? await (0, promptResolver_1.resolveProjectId)(options.project) : undefined;
27
+ const prompts = await (0, api_client_1.listPrompts)({ tag: options.tag, limit, projectId });
25
28
  // Keep the suggestion cache (W1-5) in step with the account — detached,
26
29
  // at most once a minute, never slows this command down.
27
30
  (0, libraryCache_1.startBackgroundRefresh)();
@@ -30,7 +33,7 @@ async function listCommand(options) {
30
33
  console.log(format_1.c.muted(`No prompts matched tag '${options.tag}'.`));
31
34
  }
32
35
  else {
33
- console.log(format_1.c.muted(`No prompts yet. Create one at ${constants_1.WEB_APP_URL}`));
36
+ console.log(format_1.c.muted(options.project ? `No prompts in '${options.project}' yet.` : `No prompts yet. Create one at ${constants_1.WEB_APP_URL}`));
34
37
  }
35
38
  return;
36
39
  }
@@ -171,7 +171,7 @@ async function localGet(name, values, copy) {
171
171
  }
172
172
  }
173
173
  }
174
- async function localCopy(name) {
174
+ async function localCopy(name, values = {}) {
175
175
  const p = resolveOrExplain(name);
176
176
  if (!p)
177
177
  return;
@@ -180,9 +180,10 @@ async function localCopy(name) {
180
180
  process.exitCode = 1;
181
181
  return;
182
182
  }
183
+ const { text } = store.fillVariables(p.body, values);
183
184
  try {
184
- await (0, clipboard_1.copyToClipboard)(p.body);
185
- console.log(format_1.c.success(`✓ Copied: ${p.title}`) + format_1.c.muted(` (${p.slug}, ${p.body.length} chars)`));
185
+ await (0, clipboard_1.copyToClipboard)(text);
186
+ console.log(format_1.c.success(`✓ Copied: ${p.title}`) + format_1.c.muted(` (${p.slug}, ${text.length} chars)`));
186
187
  }
187
188
  catch {
188
189
  console.error(format_1.c.error('Could not access the clipboard.'));
@@ -4,15 +4,20 @@ exports.logoutCommand = logoutCommand;
4
4
  const config_1 = require("../lib/config");
5
5
  const format_1 = require("../lib/format");
6
6
  /**
7
- * `ple logout` — delete the local config file. No server call is made (the
7
+ * `ple logout` — delete the local session file. No server call is made (the
8
8
  * session expires naturally); this only clears local state.
9
+ *
10
+ * A corrupt or unreadable session file is deleted too: logout is the documented
11
+ * fix for that state, so it must not answer "Not logged in" and leave the file.
9
12
  */
10
13
  async function logoutCommand() {
11
- const existing = (0, config_1.readConfig)();
12
- if (!existing) {
14
+ if ((0, config_1.configStatus)() === 'absent') {
13
15
  console.log(format_1.c.muted('Not logged in.'));
14
16
  return;
15
17
  }
18
+ const existing = (0, config_1.readConfig)();
16
19
  (0, config_1.clearConfig)();
17
- console.log(format_1.c.success(`✓ Logged out (${existing.email}).`));
20
+ console.log(existing
21
+ ? format_1.c.success(`✓ Logged out (${existing.email}).`)
22
+ : format_1.c.success('✓ Removed the unreadable session file. You are logged out.'));
18
23
  }
@@ -0,0 +1,171 @@
1
+ "use strict";
2
+ /**
3
+ * `ple repo ...` — repos (projects) of your account.
4
+ *
5
+ * ple repo create <name> [--private|--public] [--description <text>]
6
+ * ple repo list
7
+ * ple repo show <repo>
8
+ * ple repo visibility <repo> private|public
9
+ *
10
+ * Everything is enforced on the SERVER (session, plan limit, name rules, slug
11
+ * uniqueness, owner-only visibility); the checks here only give a faster, clearer
12
+ * message. There is deliberately no `delete`: it cannot be undone, so it stays in
13
+ * the web app.
14
+ */
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.toRepoJson = toRepoJson;
17
+ exports.explainRepoError = explainRepoError;
18
+ exports.repoCreateCommand = repoCreateCommand;
19
+ exports.repoListCommand = repoListCommand;
20
+ exports.repoShowCommand = repoShowCommand;
21
+ exports.repoVisibilityCommand = repoVisibilityCommand;
22
+ const api_client_1 = require("../lib/api-client");
23
+ const confirm_1 = require("../lib/confirm");
24
+ const format_1 = require("../lib/format");
25
+ const local_1 = require("./local");
26
+ const constants_1 = require("../lib/constants");
27
+ const repoRef_1 = require("../lib/repoRef");
28
+ const SIGN_IN_FIRST = 'Repos live in your account. Sign in first: ple login';
29
+ function toRepoJson(r) {
30
+ return {
31
+ id: r.id,
32
+ name: r.name,
33
+ slug: r.slug ?? null,
34
+ description: r.description,
35
+ visibility: r.visibility,
36
+ role: r.role,
37
+ prompt_count: r.prompt_count,
38
+ member_count: r.member_count,
39
+ created_at: r.created_at,
40
+ updated_at: r.updated_at,
41
+ };
42
+ }
43
+ function requireAccount() {
44
+ if ((0, local_1.isSignedOut)())
45
+ throw new Error(SIGN_IN_FIRST);
46
+ }
47
+ /** Turn the server's refusals into "what happened + what to do". */
48
+ function explainRepoError(err) {
49
+ if (err instanceof api_client_1.ApiError) {
50
+ if (err.status === 403 && err.code === 'LIMIT_EXCEEDED') {
51
+ throw new Error(`Your plan's repo limit is reached (Free includes 1 repo). Upgrade at ${constants_1.WEB_APP_URL}/pricing, or use the repo you already have: ple repo list`);
52
+ }
53
+ if (err.status === 403) {
54
+ throw new Error(err.message);
55
+ }
56
+ if (err.status === 409) {
57
+ throw new Error('You already have a repo with that name or URL slug. Pick a different name (see: ple repo list).');
58
+ }
59
+ if (err.status === 404) {
60
+ throw new Error('Repo not found, or you have no access to it. See: ple repo list');
61
+ }
62
+ }
63
+ throw err;
64
+ }
65
+ async function repoCreateCommand(name, options = {}) {
66
+ // Local checks first: no network, no session needed to learn the name is wrong.
67
+ const cleanName = (0, repoRef_1.validateRepoName)(name);
68
+ const description = (0, repoRef_1.validateRepoDescription)(options.description);
69
+ const visibility = (0, repoRef_1.pickVisibility)(options);
70
+ requireAccount();
71
+ await (0, api_client_1.ensureAuthed)();
72
+ let repo;
73
+ try {
74
+ repo = await (0, api_client_1.createProject)({ name: cleanName, description, visibility });
75
+ }
76
+ catch (err) {
77
+ explainRepoError(err);
78
+ }
79
+ if (options.json) {
80
+ console.log(JSON.stringify({ ok: true, repo: toRepoJson(repo) }, null, 2));
81
+ return;
82
+ }
83
+ console.log(format_1.c.success(`✓ Created ${visibility} repo '${repo.name}'`) + format_1.c.muted(` (${repo.slug ?? (0, repoRef_1.slugFromName)(repo.name)}, ${(0, format_1.shortId)(repo.id)})`));
84
+ if (visibility === 'public') {
85
+ console.log(format_1.c.warn(' Public: anyone can read its public prompts. Make it private again: ple repo visibility ' + (0, format_1.shortId)(repo.id) + ' private'));
86
+ }
87
+ else {
88
+ console.log(format_1.c.muted(' Private: only you and people you invite can see it.'));
89
+ }
90
+ console.log(format_1.c.muted(` Next: ple import --scan --project ${(0, format_1.shortId)(repo.id)} (or ple sync, then move prompts on the web)`));
91
+ }
92
+ async function repoListCommand(options = {}) {
93
+ requireAccount();
94
+ await (0, api_client_1.ensureAuthed)();
95
+ const repos = await (0, api_client_1.listProjectsDetailed)();
96
+ if (options.json) {
97
+ console.log(JSON.stringify({ repos: repos.map(toRepoJson) }, null, 2));
98
+ return;
99
+ }
100
+ if (repos.length === 0) {
101
+ console.log(format_1.c.muted('No repos yet. Create one: ple repo create "my-prompts"'));
102
+ return;
103
+ }
104
+ console.log(format_1.c.label('ID NAME VISIBILITY ROLE PROMPTS UPDATED'));
105
+ console.log(format_1.c.label('──────── ────────────────────────────── ────────── ────── ─────── ──────────'));
106
+ for (const r of repos) {
107
+ const vis = r.visibility === 'public' ? format_1.c.warn('public ') : format_1.c.muted('private ');
108
+ console.log(`${format_1.c.muted((0, format_1.shortId)(r.id))} ${(0, format_1.truncate)(r.name, 30).padEnd(30)} ${vis} ${r.role.padEnd(6)} ${String(r.prompt_count).padStart(7)} ${format_1.c.muted(r.updated_at ? (0, format_1.timeAgo)(r.updated_at) : '-')}`);
109
+ }
110
+ console.log(format_1.c.muted(`\n${repos.length} repo${repos.length === 1 ? '' : 's'} listed.`));
111
+ }
112
+ async function repoShowCommand(ref, options = {}) {
113
+ requireAccount();
114
+ await (0, api_client_1.ensureAuthed)();
115
+ const repo = (0, repoRef_1.resolveRepoRef)(ref, await (0, api_client_1.listProjectsDetailed)());
116
+ if (options.json) {
117
+ console.log(JSON.stringify({ repo: toRepoJson(repo) }, null, 2));
118
+ return;
119
+ }
120
+ console.log(format_1.c.title(repo.name));
121
+ const row = (k, v) => console.log(`${format_1.c.label(k.padEnd(12))}${v}`);
122
+ row('id', repo.id);
123
+ row('slug', repo.slug ?? '-');
124
+ row('visibility', repo.visibility);
125
+ row('your role', repo.role);
126
+ row('prompts', String(repo.prompt_count));
127
+ row('members', String(repo.member_count));
128
+ row('updated', repo.updated_at ? (0, format_1.timeAgo)(repo.updated_at) : '-');
129
+ if (repo.description)
130
+ row('description', repo.description);
131
+ }
132
+ async function repoVisibilityCommand(ref, value, options = {}, deps = {}) {
133
+ const target = (0, repoRef_1.parseVisibility)(value);
134
+ requireAccount();
135
+ await (0, api_client_1.ensureAuthed)();
136
+ const repo = (0, repoRef_1.resolveRepoRef)(ref, await (0, api_client_1.listProjectsDetailed)());
137
+ if (repo.role !== 'owner') {
138
+ throw new Error(`Only the owner can change a repo's visibility (your role in '${repo.name}': ${repo.role}).`);
139
+ }
140
+ if (repo.visibility === target) {
141
+ if (options.json)
142
+ console.log(JSON.stringify({ ok: true, changed: false, repo: toRepoJson(repo) }, null, 2));
143
+ else
144
+ console.log(format_1.c.muted(`'${repo.name}' is already ${target}. Nothing changed.`));
145
+ return;
146
+ }
147
+ // Making a repo public is the one step here that exposes data. It needs a
148
+ // person to say yes (or a script to say --yes); going private never asks.
149
+ if (target === 'public' && !options.yes) {
150
+ const interactive = deps.isTTY ?? Boolean(process.stdin.isTTY && process.stdout.isTTY);
151
+ if (!interactive) {
152
+ throw new Error(`Making '${repo.name}' public needs confirmation: re-run with --yes.`);
153
+ }
154
+ const ok = await (deps.confirm ?? confirm_1.confirm)(`Make '${repo.name}' public? Its public prompts become readable by anyone. [y/N] `);
155
+ if (!ok) {
156
+ console.log(format_1.c.muted('Cancelled — nothing changed.'));
157
+ return;
158
+ }
159
+ }
160
+ try {
161
+ await (0, api_client_1.setProjectVisibility)(repo.id, target);
162
+ }
163
+ catch (err) {
164
+ explainRepoError(err);
165
+ }
166
+ if (options.json) {
167
+ console.log(JSON.stringify({ ok: true, changed: true, repo: toRepoJson({ ...repo, visibility: target }) }, null, 2));
168
+ return;
169
+ }
170
+ console.log(format_1.c.success(`✓ '${repo.name}' is now ${target}.`));
171
+ }