promptlike 0.10.1 → 0.11.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,52 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.11.0 — 2026-10-30
4
+
5
+ - **New: `ple whoami` (alias `ple account`).** Shows the signed-in account: your email, the plan (Free / Pro /
6
+ Team), prompts and repos used against the plan limit (`prompts 23 / 25`), the version cap per prompt, and the
7
+ trial end when the server reports one. `--json` prints one line. Signed out it prints
8
+ `Not signed in. Run `ple login`.` and exits with code 1. It reads `GET /api/account/limits`; no token is ever
9
+ printed.
10
+ - **`ple suggest` no longer brings back unrelated prompts, and takes `--tag` and `--project`.** One generic word
11
+ in a title ("write") used to be enough for a 5-word task about something else (score 3.7-4.9). Now the longer
12
+ the task, the more of its words a prompt must match (1 word up to 4 task words, 2 up to 8, 3 up to 12), and a
13
+ match scoring under half of the best one is dropped. Short tasks and good matches are unchanged; the hook
14
+ output has the same shape. `--tag <name>` (repeatable, all must match, like `ple list`) and `--project <repo>`
15
+ narrow the library before ranking; signed out, `--project` is ignored with a note.
16
+ - **An unknown command is now a usage error.** `ple whoami-typo` (also `ple repo <x>`, `ple config <x>`) prints
17
+ `error: unknown command '...'`, the nearest command when there is one (`Did you mean list?`) and a pointer
18
+ to `ple --help` on stderr, and exits with code 2 (before: code 1, no pointer — the code scripts read as "your
19
+ login or input is wrong"). `ple` alone and `ple --help` are unchanged.
20
+ - **New: `ple save <title> --project <repo>` saves into your account, and running it again is safe.** The
21
+ title inside the repo is the identity: a new title creates the prompt, the same title with different text
22
+ adds a new version (earlier versions and labels stay), the same text prints "Unchanged" and sends nothing.
23
+ `-d` updates the description only when it differs (no new version), `-t` only adds tags. Two prompts with
24
+ the same title and no match for this text are listed and left alone (exit code 1). Signed out, `--project`
25
+ still saves locally and warns that the account was not written. Before this, `ple save` had no way to
26
+ reach the account, and `ple sync` after an edit uploaded the edited text as a second prompt.
27
+ - **Names are matched ignoring Turkish letters, accents and case.** `ple get "hat baslangici"` now finds
28
+ "Hat başlangıcı" and `ple get "is akisi"` finds "İş akışı özeti" (before: "No prompt matched", also for
29
+ "HAT BAŞLANGICI", because `I` and `ı`/`İ` did not fold). It works for `get`, `show`, `copy`, `log`, `diff`,
30
+ `rollback`, `improve` and `export`, in your account and in the local store, and a part of a title is
31
+ enough. An exact title still wins; several matches print the candidates and exit with code 1; no match
32
+ keeps the old error. `ple search` on this machine folds the same way.
33
+ - **New: `ple feedback "<message>"`.** Tell the maker what is missing, broken or confusing, from the
34
+ terminal or from an agent: `--type bug|missing|idea|prompt` (default `idea`), `--prompt <title|id>`,
35
+ `--email`, `--agent <name>`, `--json`. It never asks a question. Exit codes: `0` sent, `1` unexpected,
36
+ `2` usage or validation, `3` rate limited, `4` server or network problem (saved to a local queue).
37
+ What is sent: the type, the message, the prompt title or id and the email if you gave them, whether a
38
+ person or an agent wrote it, and the `ple` version, OS and CPU, Node version and the command name with
39
+ the flag names you used. Never a prompt body, a file, a path or a flag value. A message that looks like an
40
+ API key or token is refused. Signed in, the report is tied to your account; signed out it is anonymous.
41
+ - **Reports that cannot be delivered are kept and sent later.** They are saved to
42
+ `~/.promptlike/feedback/queue.json` (at most 50, mode `0600`) and sent silently after a later `ple` command
43
+ (2 second limit, at most every 15 minutes; not after `save`, `log`, `diff`, `rollback`, `suggest`,
44
+ `import`, and not after a failed command). `PLE_FEEDBACK_QUEUE=off` turns the sending off.
45
+ - **New (owner): `ple feedback list` and `ple feedback close <id> --commit <sha>`** read the feedback and
46
+ mark it `done` or `wontfix` with the commit that resolved it. They need a session on the owner account.
47
+ - **A pointer when nothing is found.** `ple search` with no result, and a failing `ple get`, print one
48
+ line on stderr: `Missing something? ple feedback --type missing "..."`. It never goes into the output you pipe.
49
+
3
50
  ## 0.10.1 — 2026-10-23
4
51
 
5
52
  - **Security: the Claude Code suggestion note is hardened.** The note the hook adds to Claude's
package/README.md CHANGED
@@ -104,6 +104,29 @@ not repeat are carried over rather than wiped. Every save that changes the text
104
104
  also adds a version to a local, append-only history (see
105
105
  [Local version history](#local-version-history-signed-out)).
106
106
 
107
+ ### `ple save <title> --project <repo>` — straight into your account, safe to run again
108
+
109
+ Signed in, `--project` (a repo name, slug, id or short id) saves into that repo of your account instead
110
+ of the local store, and the title inside the repo is the identity:
111
+
112
+ ```bash
113
+ $ ple save "code review" -m "Review this diff: {{diff}}" --project my-prompts
114
+ ✓ Saved to my-prompts: code review (3f2a1b9c, v1)
115
+ $ ple save "code review" -m "Review this diff: {{diff}}" --project my-prompts
116
+ = Unchanged: "code review" in my-prompts already has this text (v1) — no new version.
117
+ $ ple save "code review" -m "Review this diff, be strict: {{diff}}" --project my-prompts
118
+ ✓ New version of "code review" in my-prompts: v2 (was v1) — earlier versions are kept
119
+ ```
120
+
121
+ A new title creates the prompt; the same title with different text adds a new version (nothing is
122
+ overwritten, labels stay where they are); the same text sends nothing. `-d` changes the description only
123
+ when it differs (no new version); `-t` only ever adds tags. If two prompts in the repo share the title and
124
+ neither has this text, nothing is changed and both are listed (exit code 1). A wrong repo name stops before
125
+ anything is sent. Signed out, `--project` still saves locally and prints a warning that the account was
126
+ not written; run the same command after `ple login` and it will not duplicate anything. Unlike `ple sync`
127
+ (which uploads whatever text the local files hold, so an edited file becomes a second prompt), this
128
+ command updates the prompt you named.
129
+
107
130
  ### `ple sync [--dry-run] [--project <repo>]`
108
131
 
109
132
  Uploads local prompts into your signed-in account. **Explicit on purpose** —
@@ -138,6 +161,26 @@ Password: ********
138
161
  Removes the local session file. The session itself expires naturally on its
139
162
  own clock — this just clears the local copy.
140
163
 
164
+ ### `ple whoami [--json]` (alias `ple account`)
165
+
166
+ Which account is this terminal signed in as, and how much of the plan is used. It shows your own email in
167
+ full, the plan name (Free, Pro, Team), prompts and repos used against the plan limit, the version cap per
168
+ prompt, and — when the server reports one — the trial end. The session token is never printed.
169
+
170
+ ```bash
171
+ $ ple whoami
172
+ you@example.com
173
+ Plan Free
174
+ Prompts 23 / 25
175
+ Repos 1 / 1
176
+ Versions up to 10 per prompt
177
+ ```
178
+
179
+ `--json` prints one line (`signed_in`, `email`, `plan`, `usage`, `limits`, `trial_ends_at`). Signed out it
180
+ prints `Not signed in. Run `ple login`.` on stderr (`{"signed_in":false}` with `--json`) and exits `1`.
181
+ The data comes from `GET /api/account/limits`; that endpoint does not report a trial end or how many versions
182
+ each prompt has, so those two are shown only when it does.
183
+
141
184
  ### `ple list [--tag <name>]… [--limit <n>] [--project <repo>]`
142
185
 
143
186
  Lists every prompt your account has access to. The server scopes results to
@@ -285,6 +328,15 @@ used when your account has no match (see
285
328
  [Prompts only on this machine](#prompts-only-on-this-machine-signed-in)); the note
286
329
  about it goes to stderr as well.
287
330
 
331
+ **How a name is matched.** `get`, `show`, `copy` (and `log`, `diff`, `rollback`, `improve`, `export`) take a
332
+ title, a slug, a short id or just part of a title. Case, Turkish letters and accents do not matter:
333
+ `ple get "hat baslangici"` finds "Hat başlangıcı", `ple get "is akisi"` finds "İş akışı özeti". An exact
334
+ title always wins over longer titles that contain it. One match → the prompt. Several matches → a warning
335
+ with the candidates (name or short id on the left, repo on the right) on stderr, nothing on stdout, exit
336
+ code `1`; re-run with the exact name, a short id or `--project <repo>`. No match → the error, exit code
337
+ `1`, and the `ple feedback` pointer (`get`). Signed in, the account is searched first and the titles are
338
+ looked through when the server's own search finds none.
339
+
288
340
  **Conditional blocks.** `{{#if var}}…{{else}}…{{/if}}` and `{{#unless var}}…{{/unless}}`
289
341
  keep or drop text depending on a variable. A variable counts as set when it has a
290
342
  value that is not empty, `false` or `0`; a condition variable you do not pass is
@@ -596,7 +648,7 @@ Every `ple copy/get/show` records one use with `surface: cli`. A wrapper can
596
648
  attribute uses differently with `PLE_SURFACE` (e.g. `hook`) and
597
649
  `PLE_VIA=suggestion`; unknown values fall back to `cli`.
598
650
 
599
- ### `ple suggest "<task>" [--json] [--limit <n>] [--hook]`
651
+ ### `ple suggest "<task>" [--tag <name>]… [--project <repo>] [--json] [--limit <n>] [--hook]`
600
652
 
601
653
  Which of your saved prompts fits what you are about to do? Matching is
602
654
  **local**: a cached copy of your library (`~/.config/promptlike/cache/`,
@@ -614,7 +666,15 @@ Use one: ple get "Code Review"
614
666
 
615
667
  Ranking: title ×3, tag ×2, description ×1, the first 600 characters of the
616
668
  body ×0.5, weighted by how rare each word is in your library, plus a small
617
- bonus for prompts you use a lot. Weak single-word matches are not suggested.
669
+ bonus for prompts you use a lot. Weak single-word matches are not suggested: the
670
+ longer the task, the more of its words a prompt has to match (one word up to 4
671
+ task words, two up to 8, three up to 12), and a match scoring under half of the
672
+ best one is dropped. So one shared generic word like "write" no longer brings
673
+ back an unrelated prompt.
674
+
675
+ `--tag <name>` (repeat it to require several, as in `ple list`) and
676
+ `--project <repo>` (name, slug or id; needs `ple login`, ignored with a note
677
+ while signed out) narrow the library before ranking. `--hook` does not use them.
618
678
  Case, Turkish letters and accents are folded on both sides, so `kok neden` finds
619
679
  `kök neden` and `İngilizce` is the same word as `ingilizce` (ç ğ ı İ ö ş ü â î û
620
680
  and other Latin accents). This applies to the hook note as well.
@@ -630,6 +690,62 @@ the plugin option in Claude Code's `/config`. How many were shown is counted
630
690
  on this machine only (`ple stats`); the server only learns about a suggestion
631
691
  when one is actually used.
632
692
 
693
+ ### `ple feedback "<message>"` — tell the maker what is missing or broken
694
+
695
+ ```bash
696
+ ple feedback "ple search should also look inside prompt bodies" # an idea (the default type)
697
+ ple feedback --type bug --prompt "code review" "get printed the wrong version"
698
+ ple feedback --type missing --json "no way to rename a repo from the CLI"
699
+ ```
700
+
701
+ | Flag | Meaning |
702
+ |---|---|
703
+ | `--type bug\|missing\|idea\|prompt` | What kind of note (default `idea`) |
704
+ | `--prompt <title\|id>` | The prompt it is about: its **title or id**, never its text |
705
+ | `--email <address>` | Where to answer you (optional) |
706
+ | `--agent <name>` | Mark the report as written by an AI agent with this name |
707
+ | `--json` | One JSON line on stdout: `{"ok":true,"id":"…","exit_code":0,…}` — on failure `{"ok":false,"exit_code":2,"error":"…"}`, or `{"ok":false,"queued":true,"exit_code":4,…}` |
708
+
709
+ It never asks a question and never waits for input, so an agent can call it. A message is 1 to 2000 characters;
710
+ one that looks like an API key or token is **refused** (the kind is named, the value never echoed).
711
+
712
+ **What leaves your machine:** the type, your message, the prompt title or id and the email if you gave them,
713
+ whether a person or an AI agent wrote it, and four short values: the `ple` version, OS and CPU (`darwin-arm64`),
714
+ the Node version, and the command name with the **names** of the flags you used (`feedback --type --prompt`).
715
+ Never a prompt body, a file, a path or a flag value. Signed in, the report is tied to your account; signed out it is
716
+ anonymous. Who wrote it is decided from `--agent`, else from `PLE_AGENT=<name>`, `AI_AGENT`, `CLAUDECODE`,
717
+ `CLAUDE_CODE_ENTRYPOINT`, `CODEX_*` or `CURSOR_*` in the environment; otherwise a person (a piped stdin does not count).
718
+
719
+ **Exit codes** (this command only; the table at [Exit codes](#exit-codes) covers the rest):
720
+
721
+ | Code | Meaning |
722
+ |---|---|
723
+ | `0` | Sent |
724
+ | `1` | Something unexpected |
725
+ | `2` | Usage or validation error — nothing was sent (bad flag, empty or too long message, secret found, rejected by the server) |
726
+ | `3` | Rate limited — try again after the delay shown |
727
+ | `4` | Server or network problem — the report was saved to the local queue |
728
+
729
+ **Offline queue.** A report that could not be delivered is saved to `~/.promptlike/feedback/queue.json` (at most 50;
730
+ the oldest is dropped when it is full; mode `0600`). After any other `ple` command it is sent silently, with a
731
+ 2 second limit, at most once every 15 minutes, never after the offline commands (`save`, `log`, `diff`, `rollback`,
732
+ `suggest`, `import`) and never when the command failed. Turn it off with `PLE_FEEDBACK_QUEUE=off`.
733
+
734
+ **Pointer on a miss.** When `ple search` finds nothing, or `ple get` fails, one line goes to stderr:
735
+ `Missing something? ple feedback --type missing "..."` (never into the output you pipe).
736
+
737
+ **Owner commands** (need a session on the owner account; other accounts get a "not allowed" message):
738
+
739
+ ```bash
740
+ ple feedback list [--status new|triaged|done|wontfix] [--limit <n>] [--json]
741
+ ple feedback close <id> --commit <sha> [--status done|wontfix] [--json]
742
+ ```
743
+
744
+ `list` prints what the server returns (with `--json`: `{"ok":true,"exit_code":0,"items":[…]}` exactly as sent, e-mail
745
+ addresses included). `close` marks an item `done` (default) or `wontfix` and records the commit that resolved it
746
+ (`--commit` is required for `done`). They use `0` ok · `1` not signed in or not allowed · `2` bad input · `3` rate limit ·
747
+ `4` server or network problem (nothing is queued for these two).
748
+
633
749
  ### `ple config get [key]` · `ple config set <key> <value>`
634
750
 
635
751
  CLI preferences, stored in `~/.config/promptlike/settings.json` (separate from
@@ -686,7 +802,12 @@ Turn it off with `ple config set update-check off`, `PLE_UPDATE_CHECK=off` or
686
802
  | `1` | You can fix it | bad input, not signed in, not found, not allowed, plan limit, name already used |
687
803
  | `2` | Try again later | no network, timeout, rate limited, server error (5xx) |
688
804
 
689
- Scripts should treat any non-zero code as failure; `2` is the one worth retrying.
805
+ Scripts should treat any non-zero code as failure; `2` is the one worth retrying — except for a mistyped
806
+ command: `ple whoami-typo` prints `error: unknown command` with the nearest command and exits `2`, like a usage
807
+ error in `ple feedback`; retrying will not help.
808
+
809
+ `ple feedback` has its own table (`0` sent · `1` unexpected · `2` usage or validation · `3` rate limited · `4` queued for
810
+ later) — see [its section](#ple-feedback-message--tell-the-maker-what-is-missing-or-broken).
690
811
 
691
812
  ## Security notes
692
813
 
@@ -729,6 +850,7 @@ Scripts should treat any non-zero code as failure; `2` is the one worth retrying
729
850
  | `~/.config/promptlike/settings.json` | Preferences (`ple config`) | `0600` |
730
851
  | `~/.config/promptlike/cache/library.json` | Library snapshot for `ple suggest` (titles, descriptions, tags, first 600 chars) | `0600` |
731
852
  | `~/.config/promptlike/cache/update-check.json` | Latest `promptlike` version npm reported and when you were last told (see [Update notice](#update-notice)); safe to delete | `0600` where supported |
853
+ | `~/.promptlike/feedback/queue.json` | Reports `ple feedback` could not deliver (max 50), sent by a later command; see [`ple feedback`](#ple-feedback-message--tell-the-maker-what-is-missing-or-broken) | `0600` |
732
854
  | `~/.promptlike/cache/github/` | Answers from GitHub for `ple import github:…` (file lists, files, repo info); safe to delete | `0600` |
733
855
 
734
856
  Shape of the config file:
@@ -766,6 +888,8 @@ to configure.
766
888
  | `PLE_SUGGEST=off` | `ple suggest --hook` stays silent |
767
889
  | `PLE_UPDATE_CHECK=off` | No update notice, no cache read, no request to npm |
768
890
  | `NO_UPDATE_NOTIFIER=1` | Same (any value turns it off, even empty); a non-empty `CI` other than `false` / `0` does too |
891
+ | `PLE_FEEDBACK_QUEUE=off` | Reports that `ple feedback` could not deliver are not retried by later commands (they are still saved) |
892
+ | `PLE_AGENT=<name>` | `ple feedback` marks its reports as written by this agent (also read: `AI_AGENT`, `CLAUDECODE`, `CODEX_*`, `CURSOR_*`) |
769
893
  | `PLE_SURFACE`, `PLE_VIA` | How `copy/get/show` report a use (e.g. `hook`, `suggestion`) |
770
894
  | `PROMPTLIKE_HOME` | Local store location (default `~/.promptlike`) |
771
895
  | `PROMPTLIKE_CONFIG_DIR` | Session / settings / cache folder (default `~/.config/promptlike`) |
@@ -843,7 +967,8 @@ What this CLI does **not** do yet:
843
967
 
844
968
  ## Feedback
845
969
 
846
- Bug reports and feature requests: email
970
+ Bug reports and feature requests: run [`ple feedback "<message>"`](#ple-feedback-message--tell-the-maker-what-is-missing-or-broken)
971
+ (works from agents too), email
847
972
  [zeynepaslierhan@gmail.com](mailto:zeynepaslierhan@gmail.com) or open an issue on
848
973
  [github.com/zeynepaslierhann/promptlike-plugin](https://github.com/zeynepaslierhann/promptlike-plugin/issues).
849
974
  For a bug, include the command you ran, the error, your OS, and your Node version.
@@ -0,0 +1,351 @@
1
+ "use strict";
2
+ /**
3
+ * `ple feedback` — tell the maker what is missing, broken or confusing, from the terminal or from an agent.
4
+ *
5
+ * ple feedback [--type bug|missing|idea|prompt] [--prompt <title|id>] [--email <e>] [--agent <name>] [--json] "<message>"
6
+ * ple feedback list [--status new|triaged|done|wontfix] [--limit <n>] [--json] (owner)
7
+ * ple feedback close <id> --commit <sha> [--status done|wontfix] [--json] (owner)
8
+ *
9
+ * Built for scripts and agents: it never asks a question, never waits for input, and ends with a
10
+ * documented exit code. Exit codes (also in `--help` and the README):
11
+ * 0 sent (or, for list / close, done)
12
+ * 1 something unexpected (also: not signed in / not allowed, for the owner commands)
13
+ * 2 usage or validation error: nothing was sent
14
+ * 3 rate limited: try again after the printed delay
15
+ * 4 server or network problem: the report was saved to the local queue and is sent by a later `ple` command
16
+ *
17
+ * What leaves the machine: the type, the message, the prompt TITLE or id if you gave one, the email if you
18
+ * gave one, who wrote it (person or agent), and four short context values (see lib/feedbackInput.ts). Never a
19
+ * prompt body, a file, a path or an argument value. With a session the report is tied to your account; without
20
+ * one it is anonymous.
21
+ */
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.FEEDBACK_EXIT_CODES_HELP = exports.EXIT_QUEUED = exports.EXIT_RATE_LIMITED = exports.EXIT_USAGE = exports.EXIT_UNEXPECTED = exports.EXIT_SENT = void 0;
24
+ exports.feedbackCommand = feedbackCommand;
25
+ exports.feedbackListCommand = feedbackListCommand;
26
+ exports.feedbackCloseCommand = feedbackCloseCommand;
27
+ const api_client_1 = require("../lib/api-client");
28
+ const config_1 = require("../lib/config");
29
+ const constants_1 = require("../lib/constants");
30
+ const feedbackApi_1 = require("../lib/feedbackApi");
31
+ const feedbackInput_1 = require("../lib/feedbackInput");
32
+ const feedbackQueue_1 = require("../lib/feedbackQueue");
33
+ const feedbackSource_1 = require("../lib/feedbackSource");
34
+ const format_1 = require("../lib/format");
35
+ exports.EXIT_SENT = 0;
36
+ exports.EXIT_UNEXPECTED = 1;
37
+ exports.EXIT_USAGE = 2;
38
+ exports.EXIT_RATE_LIMITED = 3;
39
+ exports.EXIT_QUEUED = 4;
40
+ /** The documented table; `--help` and the tests print/compare it. */
41
+ exports.FEEDBACK_EXIT_CODES_HELP = [
42
+ '0 sent (list / close: done)',
43
+ '1 unexpected problem (list / close: also not signed in, or not allowed)',
44
+ '2 usage or validation error — nothing was sent',
45
+ '3 rate limited — try again after the delay shown',
46
+ '4 server or network problem — saved to the local queue, sent by a later `ple` command',
47
+ ];
48
+ // ---------------------------------------------------------------------------
49
+ // Output
50
+ // ---------------------------------------------------------------------------
51
+ function setExit(code) {
52
+ process.exitCode = code;
53
+ }
54
+ /** `--json`: one line on stdout, always, for every outcome. */
55
+ function emitJson(obj) {
56
+ console.log(JSON.stringify(obj));
57
+ }
58
+ function fail(json, code, error, extra = {}) {
59
+ setExit(code);
60
+ if (json)
61
+ emitJson({ ok: false, exit_code: code, error, ...extra });
62
+ else
63
+ console.error(format_1.c.error(`✗ ${error}`));
64
+ }
65
+ // ---------------------------------------------------------------------------
66
+ // ple feedback "<message>"
67
+ // ---------------------------------------------------------------------------
68
+ async function defaultToken() {
69
+ if ((0, config_1.configStatus)() !== 'valid')
70
+ return {};
71
+ try {
72
+ await (0, api_client_1.ensureAuthed)();
73
+ return { token: (0, config_1.readConfig)()?.access_token };
74
+ }
75
+ catch (err) {
76
+ // The server could not be reached to refresh the session: it cannot take the report either.
77
+ if (err instanceof api_client_1.NetworkError || err instanceof api_client_1.RequestTimeoutError)
78
+ return { unreachable: err.message };
79
+ return {}; // a dead session must not block a report: it goes out anonymously
80
+ }
81
+ }
82
+ async function feedbackCommand(messageParts, opts = {}, deps = {}) {
83
+ const json = opts.json === true;
84
+ try {
85
+ await submit(Array.isArray(messageParts) ? messageParts.join(' ') : String(messageParts ?? ''), opts, deps, json);
86
+ }
87
+ catch (err) {
88
+ fail(json, exports.EXIT_UNEXPECTED, `Unexpected error: ${(0, format_1.safeText)(err instanceof Error ? err.message : String(err)).slice(0, 200)}`);
89
+ }
90
+ }
91
+ async function submit(message, opts, deps, json) {
92
+ const env = deps.env ?? process.env;
93
+ let agentFlag;
94
+ if (opts.agent !== undefined) {
95
+ agentFlag = opts.agent;
96
+ if (!(0, feedbackInput_1.sanitizeAgentName)(agentFlag)) {
97
+ return fail(json, exports.EXIT_USAGE, '--agent needs a name made of letters, digits, ".", "_" or "-" (max 64).');
98
+ }
99
+ }
100
+ const checked = (0, feedbackInput_1.checkFeedbackFields)({ type: opts.type, message, prompt: opts.prompt, email: opts.email });
101
+ if (!checked.ok)
102
+ return fail(json, exports.EXIT_USAGE, checked.error);
103
+ const who = (0, feedbackSource_1.detectSource)(env, agentFlag);
104
+ const payload = {
105
+ type: checked.value.type,
106
+ message: checked.value.message,
107
+ ...(checked.value.prompt_ref ? { prompt_ref: checked.value.prompt_ref } : {}),
108
+ ...(checked.value.email ? { email: checked.value.email } : {}),
109
+ source: who.source,
110
+ ...(who.agent_name ? { agent_name: who.agent_name } : {}),
111
+ client: 'cli',
112
+ context: (0, feedbackInput_1.buildContext)({ cliVersion: constants_1.CLI_VERSION, commandName: 'feedback', flagNames: deps.flagNames }),
113
+ };
114
+ const auth = await (deps.token ?? defaultToken)();
115
+ const send = deps.send ?? ((p, o) => (0, feedbackApi_1.sendFeedback)(p, o));
116
+ let result;
117
+ let attachedAccount = Boolean(auth.token);
118
+ if (auth.unreachable) {
119
+ result = { kind: 'unavailable', message: auth.unreachable };
120
+ attachedAccount = false;
121
+ }
122
+ else {
123
+ result = await send(payload, { token: auth.token });
124
+ if (result.kind === 'auth' && auth.token) {
125
+ // The server did not accept the session: the report still matters, send it without one.
126
+ attachedAccount = false;
127
+ result = await send(payload, { token: undefined });
128
+ }
129
+ }
130
+ const base = { type: payload.type, source: payload.source, ...(payload.agent_name ? { agent_name: payload.agent_name } : {}) };
131
+ switch (result.kind) {
132
+ case 'sent':
133
+ setExit(exports.EXIT_SENT);
134
+ if (json)
135
+ emitJson({ ok: true, ...(result.id ? { id: result.id } : {}), exit_code: exports.EXIT_SENT, ...base, account: attachedAccount });
136
+ else {
137
+ console.log(format_1.c.success('✓ Feedback sent — thank you.') + (result.id ? format_1.c.muted(` (id ${result.id})`) : ''));
138
+ console.log(format_1.c.muted(attachedAccount ? ' Tied to your account.' : ' Sent anonymously (sign in with `ple login` to attach it to your account).'));
139
+ }
140
+ return;
141
+ case 'invalid':
142
+ return fail(json, exports.EXIT_USAGE, `The server rejected the report: ${result.message}`);
143
+ case 'config':
144
+ return fail(json, exports.EXIT_USAGE, result.message);
145
+ case 'rate_limited': {
146
+ const wait = result.retryAfter;
147
+ return fail(json, exports.EXIT_RATE_LIMITED, `Rate limited. Try again${wait !== undefined ? ` in ${wait}s` : ' in a moment'}.`, { retry_after: wait ?? null });
148
+ }
149
+ case 'unavailable':
150
+ return queueIt(payload, result.message, json, env, deps, base);
151
+ case 'auth':
152
+ return fail(json, exports.EXIT_UNEXPECTED, `The server refused the report (HTTP ${result.status}).`);
153
+ default:
154
+ return fail(json, exports.EXIT_UNEXPECTED, `Unexpected answer from the server (HTTP ${result.status}): ${result.message}`);
155
+ }
156
+ }
157
+ function queueIt(payload, reason, json, env, deps, base) {
158
+ let queued;
159
+ try {
160
+ queued = (deps.queue ?? ((p) => (0, feedbackQueue_1.enqueue)(p)))(payload);
161
+ }
162
+ catch (err) {
163
+ return fail(json, exports.EXIT_UNEXPECTED, `Could not reach the server (${reason}) and could not save the report locally either: ${(0, format_1.safeText)(err instanceof Error ? err.message : String(err)).slice(0, 160)}`);
164
+ }
165
+ const sendsLater = (0, feedbackQueue_1.queueEnabled)(env);
166
+ setExit(exports.EXIT_QUEUED);
167
+ const note = sendsLater
168
+ ? 'It will be sent by a later `ple` command.'
169
+ : 'Sending later is off (PLE_FEEDBACK_QUEUE=off); run `ple feedback` again when you are online.';
170
+ if (json) {
171
+ emitJson({
172
+ ok: false,
173
+ queued: true,
174
+ exit_code: exports.EXIT_QUEUED,
175
+ queue_size: queued.size,
176
+ ...(queued.droppedOldest ? { dropped_oldest: true } : {}),
177
+ send_later: sendsLater,
178
+ error: reason,
179
+ ...base,
180
+ });
181
+ return;
182
+ }
183
+ console.error(format_1.c.warn(`⚠ Could not deliver the report (${reason})`));
184
+ console.error(format_1.c.muted(` Saved to the local queue (${queued.size} waiting${queued.droppedOldest ? ', the oldest one was dropped' : ''}). ${note}`));
185
+ }
186
+ async function ownerAuth() {
187
+ if ((0, config_1.configStatus)() !== 'valid')
188
+ return { error: 'This command needs a session. Sign in first: ple login', code: exports.EXIT_UNEXPECTED };
189
+ try {
190
+ await (0, api_client_1.ensureAuthed)();
191
+ }
192
+ catch (err) {
193
+ const message = (0, format_1.safeText)(err instanceof Error ? err.message : String(err)).slice(0, 300);
194
+ const unreachable = err instanceof api_client_1.NetworkError || err instanceof api_client_1.RequestTimeoutError;
195
+ return { error: message, code: unreachable ? exports.EXIT_QUEUED : exports.EXIT_UNEXPECTED };
196
+ }
197
+ const token = (0, config_1.readConfig)()?.access_token;
198
+ return token ? { token } : { error: 'This command needs a session. Sign in first: ple login', code: exports.EXIT_UNEXPECTED };
199
+ }
200
+ /** The same status → exit code mapping for both owner commands. Returns null when the response is a success (2xx). */
201
+ function ownerFailure(out) {
202
+ if (out.kind === 'config')
203
+ return { code: exports.EXIT_USAGE, error: out.message };
204
+ if (out.kind === 'unreachable')
205
+ return { code: exports.EXIT_QUEUED, error: `${out.message} Nothing was changed.` };
206
+ const { status, body } = out;
207
+ if (status >= 200 && status < 300)
208
+ return null;
209
+ if (status === 401)
210
+ return { code: exports.EXIT_UNEXPECTED, error: 'The server did not accept your session. Sign in again: ple login' };
211
+ if (status === 403)
212
+ return { code: exports.EXIT_UNEXPECTED, error: 'Not allowed: reading and closing feedback is limited to the owner account.' };
213
+ if (status === 429) {
214
+ return {
215
+ code: exports.EXIT_RATE_LIMITED,
216
+ error: `Rate limited. Try again${out.retryAfter !== undefined ? ` in ${out.retryAfter}s` : ' in a moment'}.`,
217
+ extra: { retry_after: out.retryAfter ?? null },
218
+ };
219
+ }
220
+ if (status === 400 || status === 404 || status === 413 || status === 422) {
221
+ const details = (0, feedbackApi_1.serverDetails)(body);
222
+ const fallback = status === 404 ? 'No feedback with that id.' : 'The server rejected the request.';
223
+ return { code: exports.EXIT_USAGE, error: (0, feedbackApi_1.serverMessage)(body, fallback) + (details ? ` (${details})` : '') };
224
+ }
225
+ if (status >= 500 || status === 408)
226
+ return { code: exports.EXIT_QUEUED, error: `The server answered HTTP ${status}. Nothing was changed.` };
227
+ return { code: exports.EXIT_UNEXPECTED, error: (0, feedbackApi_1.serverMessage)(body, `The server answered HTTP ${status}.`) };
228
+ }
229
+ const MAX_LIST_LIMIT = 200;
230
+ async function feedbackListCommand(opts = {}, deps = {}) {
231
+ const json = opts.json === true;
232
+ try {
233
+ const status = opts.status === undefined ? undefined : opts.status.trim().toLowerCase();
234
+ if (status !== undefined && !feedbackApi_1.FEEDBACK_STATUSES.includes(status)) {
235
+ return fail(json, exports.EXIT_USAGE, `--status must be one of: ${feedbackApi_1.FEEDBACK_STATUSES.join(', ')}.`);
236
+ }
237
+ let limit = 50;
238
+ if (opts.limit !== undefined) {
239
+ if (!/^\d{1,4}$/.test(opts.limit.trim()) || Number(opts.limit) < 1 || Number(opts.limit) > MAX_LIST_LIMIT) {
240
+ return fail(json, exports.EXIT_USAGE, `--limit must be a whole number from 1 to ${MAX_LIST_LIMIT}.`);
241
+ }
242
+ limit = Number(opts.limit);
243
+ }
244
+ const auth = await (deps.auth ?? ownerAuth)();
245
+ if ('error' in auth)
246
+ return fail(json, auth.code, auth.error);
247
+ const out = await (0, feedbackApi_1.request)({
248
+ method: 'GET',
249
+ path: '/api/feedback',
250
+ query: { status, limit },
251
+ token: auth.token,
252
+ timeoutMs: feedbackApi_1.OWNER_TIMEOUT_MS,
253
+ fetchImpl: deps.fetchImpl,
254
+ });
255
+ const failure = ownerFailure(out);
256
+ if (failure)
257
+ return fail(json, failure.code, failure.error, failure.extra);
258
+ if (out.kind !== 'response' || !Array.isArray(out.body.items)) {
259
+ return fail(json, exports.EXIT_UNEXPECTED, 'The server sent an unexpected answer (no "items" list). Update the CLI: npm i -g promptlike@latest');
260
+ }
261
+ const items = out.body.items;
262
+ setExit(exports.EXIT_SENT);
263
+ if (json) {
264
+ // As the server sent it: it only ever returns this to the owner.
265
+ emitJson({ ok: true, exit_code: exports.EXIT_SENT, items });
266
+ return;
267
+ }
268
+ printList(items, status);
269
+ }
270
+ catch (err) {
271
+ fail(json, exports.EXIT_UNEXPECTED, `Unexpected error: ${(0, format_1.safeText)(err instanceof Error ? err.message : String(err)).slice(0, 200)}`);
272
+ }
273
+ }
274
+ /** A field from the server, as one safe line (it is other people's text). */
275
+ function field(item, key, max) {
276
+ const v = item[key];
277
+ return typeof v === 'string' || typeof v === 'number' ? (0, format_1.truncate)((0, feedbackInput_1.cleanLine)(String(v)), max) : '';
278
+ }
279
+ function printList(items, status) {
280
+ if (items.length === 0) {
281
+ console.log(format_1.c.muted(`No feedback${status ? ` with status '${status}'` : ''}.`));
282
+ return;
283
+ }
284
+ console.log(format_1.c.label('ID STATUS TYPE FROM AGE MESSAGE'));
285
+ for (const raw of items) {
286
+ if (typeof raw !== 'object' || raw === null)
287
+ continue;
288
+ const it = raw;
289
+ const created = field(it, 'created_at', 40);
290
+ const from = it.source === 'agent' ? field(it, 'agent_name', 8) || 'agent' : 'human';
291
+ const row = [
292
+ (0, format_1.shortId)(field(it, 'id', 64) || '?').padEnd(8),
293
+ field(it, 'status', 8).padEnd(8),
294
+ field(it, 'type', 7).padEnd(7),
295
+ from.padEnd(8),
296
+ (created ? (0, format_1.timeAgo)(created) : '').padEnd(10),
297
+ field(it, 'message', 70),
298
+ ].join(' ');
299
+ console.log(row);
300
+ const extra = [
301
+ field(it, 'prompt_ref', 60) && `prompt: ${field(it, 'prompt_ref', 60)}`,
302
+ field(it, 'email', 60) && `email: ${field(it, 'email', 60)}`,
303
+ field(it, 'resolution_commit', 40) && `commit: ${field(it, 'resolution_commit', 40)}`,
304
+ ].filter(Boolean);
305
+ if (extra.length > 0)
306
+ console.log(format_1.c.muted(` ${extra.join(' · ')}`));
307
+ }
308
+ console.log(format_1.c.muted(`\n${items.length} item${items.length === 1 ? '' : 's'}. Close one: ple feedback close <id> --commit <sha>`));
309
+ }
310
+ const ID_RE = /^[A-Za-z0-9_-]{1,64}$/;
311
+ const SHA_RE = /^[0-9a-f]{7,40}$/i;
312
+ async function feedbackCloseCommand(id, opts = {}, deps = {}) {
313
+ const json = opts.json === true;
314
+ try {
315
+ if (!ID_RE.test(id ?? ''))
316
+ return fail(json, exports.EXIT_USAGE, 'The id looks wrong: use the full id from `ple feedback list --json`.');
317
+ const status = (opts.status === undefined ? 'done' : opts.status.trim().toLowerCase());
318
+ if (status !== 'done' && status !== 'wontfix')
319
+ return fail(json, exports.EXIT_USAGE, '--status must be done or wontfix.');
320
+ const commit = opts.commit?.trim();
321
+ if (commit === undefined || commit === '') {
322
+ if (status === 'done')
323
+ return fail(json, exports.EXIT_USAGE, '--commit <sha> is required: name the commit that fixed it.');
324
+ }
325
+ else if (!SHA_RE.test(commit)) {
326
+ return fail(json, exports.EXIT_USAGE, '--commit must be a git commit hash (7 to 40 hex characters).');
327
+ }
328
+ const auth = await (deps.auth ?? ownerAuth)();
329
+ if ('error' in auth)
330
+ return fail(json, auth.code, auth.error);
331
+ const out = await (0, feedbackApi_1.request)({
332
+ method: 'PATCH',
333
+ path: `/api/feedback/${encodeURIComponent(id)}`,
334
+ body: { status, ...(commit ? { resolution_commit: commit.toLowerCase() } : {}) },
335
+ token: auth.token,
336
+ timeoutMs: feedbackApi_1.OWNER_TIMEOUT_MS,
337
+ fetchImpl: deps.fetchImpl,
338
+ });
339
+ const failure = ownerFailure(out);
340
+ if (failure)
341
+ return fail(json, failure.code, failure.error, failure.extra);
342
+ setExit(exports.EXIT_SENT);
343
+ if (json)
344
+ emitJson({ ok: true, exit_code: exports.EXIT_SENT, id, status, ...(commit ? { resolution_commit: commit.toLowerCase() } : {}) });
345
+ else
346
+ console.log(format_1.c.success(`✓ ${(0, format_1.shortId)(id)} → ${status}`) + (commit ? format_1.c.muted(` (commit ${commit.toLowerCase().slice(0, 12)})`) : ''));
347
+ }
348
+ catch (err) {
349
+ fail(json, exports.EXIT_UNEXPECTED, `Unexpected error: ${(0, format_1.safeText)(err instanceof Error ? err.message : String(err)).slice(0, 200)}`);
350
+ }
351
+ }
@@ -212,11 +212,12 @@ async function copyLocalPrompt(p, values = {}) {
212
212
  process.exitCode = 1;
213
213
  }
214
214
  }
215
+ /** Prints the matches; returns false when there were none (the caller adds the feedback pointer). */
215
216
  function localSearch(keyword) {
216
217
  const rows = store.search(keyword);
217
218
  if (rows.length === 0) {
218
219
  console.log(format_1.c.muted(`No local prompts matched '${keyword}'.`));
219
- return;
220
+ return false;
220
221
  }
221
222
  console.log(format_1.c.label(`${rows.length} result${rows.length === 1 ? '' : 's'}:`));
222
223
  console.log();
@@ -225,4 +226,5 @@ function localSearch(keyword) {
225
226
  if (p.description)
226
227
  console.log(format_1.c.muted(` ${(0, format_1.truncate)(p.description, 80)}`));
227
228
  }
229
+ return true;
228
230
  }
@@ -54,7 +54,7 @@ function versionNotFound(ref, versions) {
54
54
  function noteUnrecorded(p, latest) {
55
55
  if (latest && latest.body.trim() !== p.body.trim()) {
56
56
  console.error(format_1.c.muted(`(The file on disk differs from v${latest.version} — it was edited outside ple. ` +
57
- `Run \`ple save "${p.slug}" --force\` or a rollback to record it.)`));
57
+ `\`ple rollback "${p.slug}" v${latest.version}\` saves the edit as its own version first, then restores v${latest.version}.)`));
58
58
  }
59
59
  }
60
60
  function localLog(name, options) {