promptlike 0.10.1 → 0.12.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.
@@ -6,6 +6,7 @@
6
6
  * ple repo list
7
7
  * ple repo show <repo>
8
8
  * ple repo visibility <repo> private|public
9
+ * ple repo license <repo> <spdx|none>
9
10
  *
10
11
  * Everything is enforced on the SERVER (session, plan limit, name rules, slug
11
12
  * uniqueness, owner-only visibility); the checks here only give a faster, clearer
@@ -13,12 +14,15 @@
13
14
  * the web app.
14
15
  */
15
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.REPO_LICENSES = void 0;
16
18
  exports.toRepoJson = toRepoJson;
17
19
  exports.explainRepoError = explainRepoError;
18
20
  exports.repoCreateCommand = repoCreateCommand;
19
21
  exports.repoListCommand = repoListCommand;
20
22
  exports.repoShowCommand = repoShowCommand;
21
23
  exports.repoVisibilityCommand = repoVisibilityCommand;
24
+ exports.parseLicense = parseLicense;
25
+ exports.repoLicenseCommand = repoLicenseCommand;
22
26
  const api_client_1 = require("../lib/api-client");
23
27
  const confirm_1 = require("../lib/confirm");
24
28
  const format_1 = require("../lib/format");
@@ -33,6 +37,7 @@ function toRepoJson(r) {
33
37
  slug: r.slug ?? null,
34
38
  description: r.description,
35
39
  visibility: r.visibility,
40
+ license: r.license,
36
41
  role: r.role,
37
42
  prompt_count: r.prompt_count,
38
43
  member_count: r.member_count,
@@ -122,6 +127,7 @@ async function repoShowCommand(ref, options = {}) {
122
127
  row('id', repo.id);
123
128
  row('slug', repo.slug ?? '-');
124
129
  row('visibility', repo.visibility);
130
+ row('license', repo.license ?? 'none declared');
125
131
  row('your role', repo.role);
126
132
  row('prompts', String(repo.prompt_count));
127
133
  row('members', String(repo.member_count));
@@ -169,3 +175,46 @@ async function repoVisibilityCommand(ref, value, options = {}, deps = {}) {
169
175
  }
170
176
  console.log(format_1.c.success(`✓ '${repo.name}' is now ${target}.`));
171
177
  }
178
+ // ---------------------------------------------------------------------------
179
+ /** Same list as the server (src/lib/repo-license.ts) and its database CHECK; the server stays the authority. */
180
+ exports.REPO_LICENSES = ['CC-BY-4.0', 'CC-BY-SA-4.0', 'CC0-1.0', 'MIT', 'Apache-2.0'];
181
+ /** `cc by 4.0`-style spellings are not guessed: the SPDX id, any case, or `none`. Returns null for "clear it". */
182
+ function parseLicense(value) {
183
+ const v = value.trim();
184
+ if (/^(none|null|-|clear)$/i.test(v))
185
+ return null;
186
+ const hit = exports.REPO_LICENSES.find((l) => l.toLowerCase() === v.toLowerCase());
187
+ if (!hit)
188
+ throw new Error(`Unknown license '${v.slice(0, 40)}'. Use one of: ${exports.REPO_LICENSES.join(', ')} — or none to clear it.`);
189
+ return hit;
190
+ }
191
+ async function repoLicenseCommand(ref, value, options = {}) {
192
+ const target = parseLicense(value);
193
+ requireAccount();
194
+ await (0, api_client_1.ensureAuthed)();
195
+ const repo = (0, repoRef_1.resolveRepoRef)(ref, await (0, api_client_1.listProjectsDetailed)());
196
+ if (repo.role !== 'owner') {
197
+ throw new Error(`Only the owner can change a repo's license (your role in '${repo.name}': ${repo.role}).`);
198
+ }
199
+ if ((repo.license ?? null) === target) {
200
+ if (options.json)
201
+ console.log(JSON.stringify({ ok: true, changed: false, repo: toRepoJson(repo) }, null, 2));
202
+ else
203
+ console.log(format_1.c.muted(`'${repo.name}' already has ${target ?? 'no license declared'}. Nothing changed.`));
204
+ return;
205
+ }
206
+ try {
207
+ await (0, api_client_1.setProjectLicense)(repo.id, target);
208
+ }
209
+ catch (err) {
210
+ explainRepoError(err);
211
+ }
212
+ if (options.json) {
213
+ console.log(JSON.stringify({ ok: true, changed: true, repo: toRepoJson({ ...repo, license: target }) }, null, 2));
214
+ return;
215
+ }
216
+ console.log(format_1.c.success(target ? `✓ '${repo.name}' is now licensed ${target}.` : `✓ '${repo.name}' has no license declared now.`));
217
+ if (target && repo.visibility !== 'public') {
218
+ console.log(format_1.c.muted(` The repo is private; the license is shown once it is public: ple repo visibility ${repo.slug ?? (0, format_1.shortId)(repo.id)} public`));
219
+ }
220
+ }
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  /**
3
3
  * `ple save <title>` — write a prompt to the local store. **No account needed.**
4
+ * With `--project <repo>` and a session it saves INTO THE ACCOUNT instead, and is safe to run again
5
+ * (see lib/accountSave.ts: same title in the repo → no second prompt; new text → a new version;
6
+ * same text → "unchanged"). Without a session `--project` still saves locally, with a warning.
4
7
  *
5
8
  * This is the command that makes `npm i -g promptlike` worth something on its
6
9
  * own. Body comes from `-m/--message`, or from stdin when piped:
@@ -49,6 +52,11 @@ const store = __importStar(require("../lib/localStore"));
49
52
  const history = __importStar(require("../lib/localHistory"));
50
53
  const format_1 = require("../lib/format");
51
54
  const promptVariables_1 = require("../lib/promptVariables");
55
+ const api_client_1 = require("../lib/api-client");
56
+ const accountSave_1 = require("../lib/accountSave");
57
+ const promptResolver_1 = require("../lib/promptResolver");
58
+ const libraryCache_1 = require("../lib/libraryCache");
59
+ const local_1 = require("./local");
52
60
  /**
53
61
  * Same caps the web API enforces (title 200 / body 100K / description 1000).
54
62
  * The CLI mirrors them instead of letting `ple sync` discover the mismatch:
@@ -118,6 +126,22 @@ async function saveCommand(title, options = {}) {
118
126
  process.exitCode = 1;
119
127
  return;
120
128
  }
129
+ if (options.project !== undefined) {
130
+ const project = options.project.trim();
131
+ if (!project) {
132
+ console.error(format_1.c.error('--project is empty. Give a repo name, slug or id (see `ple repo list`).'));
133
+ process.exitCode = 1;
134
+ return;
135
+ }
136
+ if (!(0, local_1.isSignedOut)()) {
137
+ await saveIntoAccount(cleanTitle, body, project, options);
138
+ return;
139
+ }
140
+ // No session: do what `ple save` always did, but say that the account was NOT written —
141
+ // a silent local-only save would read as "it is in the repo".
142
+ console.error(format_1.c.warn(`⚠ --project needs an account: saved on this machine only, NOT in repo '${project}'.`));
143
+ console.error(format_1.c.muted(' Sign in with `ple login`, then run the same command again — it will not create a duplicate.'));
144
+ }
121
145
  const slug = store.slugFor(cleanTitle);
122
146
  const previous = store.read(slug);
123
147
  // Overwriting someone's prompt silently is the one unrecoverable thing this
@@ -151,3 +175,50 @@ async function saveCommand(title, options = {}) {
151
175
  console.log(format_1.c.muted(` use it: ple copy "${saved.slug}"`));
152
176
  }
153
177
  }
178
+ /** `--project` with a session: write to the account; the local store is not touched. */
179
+ async function saveIntoAccount(title, body, projectRef, options) {
180
+ const tags = (0, accountSave_1.cleanTags)(options.tag ?? []);
181
+ (0, accountSave_1.assertTagLengths)(tags);
182
+ const description = options.description === undefined ? undefined : options.description.trim();
183
+ await (0, api_client_1.ensureAuthed)();
184
+ // A wrong repo name stops here, before anything is sent.
185
+ const projectId = await (0, promptResolver_1.resolveProjectId)(projectRef);
186
+ const projectName = (await (0, api_client_1.listProjects)()).find((p) => p.id === projectId)?.name ?? projectRef;
187
+ const out = await (0, accountSave_1.saveToAccount)({ title, body, description, tags, projectId, projectName });
188
+ printAccountOutcome(out, title, projectName, projectRef);
189
+ if (out.status === 'created' || out.status === 'updated')
190
+ (0, libraryCache_1.startBackgroundRefresh)({ force: true });
191
+ }
192
+ function printAccountOutcome(out, title, repo, projectRef) {
193
+ const shown = (0, format_1.safeText)(title);
194
+ const repoName = (0, format_1.safeText)(repo);
195
+ if (out.status === 'ambiguous') {
196
+ console.error(format_1.c.error(`${out.candidates.length} prompts in '${repoName}' are titled "${shown}" and none has this text — not changing any of them.`));
197
+ for (const p of out.candidates.slice(0, 10))
198
+ console.error(format_1.c.muted(` ${(0, accountSave_1.candidateLine)(p)}`));
199
+ console.error(format_1.c.muted('Edit the one you mean with `ple improve <short id>` or on the web, or give this one a different title.'));
200
+ process.exitCode = 1;
201
+ return;
202
+ }
203
+ const id = out.id.slice(0, 8);
204
+ if (out.status === 'created') {
205
+ console.log(format_1.c.success(`✓ Saved to ${repoName}: ${shown}`) + format_1.c.muted(` (${id}${out.version ? `, v${out.version}` : ''})`));
206
+ }
207
+ else if (out.status === 'updated') {
208
+ const was = out.previousVersion ? ` (was v${out.previousVersion})` : '';
209
+ console.log(format_1.c.success(`✓ New version of "${shown}" in ${repoName}: v${out.version ?? '?'}${was}`) + format_1.c.muted(` (${id}) — earlier versions are kept`));
210
+ }
211
+ else {
212
+ console.log(`= Unchanged: "${shown}" in ${repoName} already has this text${out.version ? ` (v${out.version})` : ''} — no new version.` + format_1.c.muted(` (${id})`));
213
+ }
214
+ if (out.status !== 'created' && out.descriptionUpdated)
215
+ console.log(format_1.c.muted(' description updated (no new version)'));
216
+ if (out.tagsAdded.length > 0)
217
+ console.log(format_1.c.muted(` tags added: ${out.tagsAdded.map((t) => (0, format_1.safeText)(t)).join(', ')}`));
218
+ if (out.tagsFailed.length > 0) {
219
+ for (const f of out.tagsFailed)
220
+ console.error(format_1.c.warn(`⚠ tag '${(0, format_1.safeText)(f.tag)}' was not added: ${(0, format_1.safeText)(f.message)}`));
221
+ console.error(format_1.c.muted(` Run the same command again to retry them: ple save "${shown}" --project ${projectRef}`));
222
+ process.exitCode = 1;
223
+ }
224
+ }
@@ -39,6 +39,7 @@ const local_1 = require("./local");
39
39
  const format_1 = require("../lib/format");
40
40
  const promptSource_1 = require("../lib/promptSource");
41
41
  const store = __importStar(require("../lib/localStore"));
42
+ const feedbackHint_1 = require("../lib/feedbackHint");
42
43
  /** Local-only matches shown before "…and N more". */
43
44
  const LOCAL_ONLY_SHOWN = 10;
44
45
  /**
@@ -60,7 +61,8 @@ async function searchCommand(keyword) {
60
61
  return;
61
62
  }
62
63
  if ((0, local_1.isSignedOut)()) {
63
- (0, local_1.localSearch)(trimmed);
64
+ if (!(0, local_1.localSearch)(trimmed))
65
+ (0, feedbackHint_1.printFeedbackHint)();
64
66
  return;
65
67
  }
66
68
  await (0, api_client_1.ensureAuthed)();
@@ -71,6 +73,7 @@ async function searchCommand(keyword) {
71
73
  const onlyHere = (0, promptSource_1.localOnly)((0, promptSource_1.accountTitleSet)(rows, false).titles, store.search(trimmed));
72
74
  if (rows.length === 0 && onlyHere.length === 0) {
73
75
  console.log(format_1.c.muted(`No prompts matched '${trimmed}'.`));
76
+ (0, feedbackHint_1.printFeedbackHint)();
74
77
  return;
75
78
  }
76
79
  if (rows.length === 0) {
@@ -52,12 +52,13 @@ var __importStar = (this && this.__importStar) || (function () {
52
52
  })();
53
53
  Object.defineProperty(exports, "__esModule", { value: true });
54
54
  exports.NOTE_TITLE_MAX = exports.HOOK_BUDGET_MS = exports.HOOK_MIN_CHARS = void 0;
55
+ exports.filterEntries = filterEntries;
55
56
  exports.stripPasted = stripPasted;
56
57
  exports.hookShouldSkip = hookShouldSkip;
57
58
  exports.noteLabel = noteLabel;
58
59
  exports.isShellSafeSlug = isShellSafeSlug;
59
60
  exports.renderHookBlock = renderHookBlock;
60
- exports.useCommandFor = useCommandFor;
61
+ exports.getCommandFor = getCommandFor;
61
62
  exports.runHook = runHook;
62
63
  exports.refreshLibraryCache = refreshLibraryCache;
63
64
  exports.suggestCommand = suggestCommand;
@@ -66,8 +67,30 @@ const config_1 = require("../lib/config");
66
67
  const format_1 = require("../lib/format");
67
68
  const libraryCache_1 = require("../lib/libraryCache");
68
69
  const store = __importStar(require("../lib/localStore"));
70
+ const promptResolver_1 = require("../lib/promptResolver");
69
71
  const rank_1 = require("../lib/rank");
70
72
  const settings_1 = require("../lib/settings");
73
+ const tagFilter_1 = require("../lib/tagFilter");
74
+ const local_1 = require("./local");
75
+ /** Entries that pass the filter. Pure; the ranker then runs on this subset only. */
76
+ function filterEntries(entries, filter) {
77
+ const tags = filter.tags ?? [];
78
+ const repo = filter.repo;
79
+ return entries.filter((e) => {
80
+ if (tags.length > 0) {
81
+ const have = e.tags ?? [];
82
+ const ok = filter.ignoreCase ? (0, tagFilter_1.hasAllLocalTags)(have, tags) : tags.every((t) => have.includes(t));
83
+ if (!ok)
84
+ return false;
85
+ }
86
+ if (repo) {
87
+ if (e.repoId)
88
+ return e.repoId.toLowerCase() === repo.id.toLowerCase();
89
+ return repo.name !== undefined && e.repo === repo.name;
90
+ }
91
+ return true;
92
+ });
93
+ }
71
94
  /** Hook input must be at least this long to be worth matching. */
72
95
  exports.HOOK_MIN_CHARS = 20;
73
96
  /** Hard wall-clock budget for hook mode (Claude Code waits on us). */
@@ -194,7 +217,7 @@ function renderHookBlock(ranked, signedIn) {
194
217
  * or a slug (signed out): used as is only when it holds letters, digits, spaces, `.`, `_`, `-`
195
218
  * (safe inside double quotes); otherwise the prompt's id when it has one; otherwise no command.
196
219
  */
197
- function useCommandFor(item) {
220
+ function getCommandFor(item) {
198
221
  if (/^[\p{L}\p{N}][\p{L}\p{N} ._-]*$/u.test(item.name))
199
222
  return `ple get "${item.name}"`;
200
223
  if (ACCOUNT_ID_RE.test(item.id))
@@ -307,7 +330,17 @@ async function suggestCommand(words, options = {}) {
307
330
  entries = (0, libraryCache_1.readCache)(config.user_id)?.entries ?? [];
308
331
  }
309
332
  }
310
- const ranked = (0, rank_1.rankLibrary)(entries, text, limit);
333
+ const tags = (0, tagFilter_1.parseTagFilter)(options.tag);
334
+ if (!config)
335
+ (0, local_1.noteIgnoredProject)(options.project);
336
+ const repo = config && options.project ? await (0, promptResolver_1.resolveProject)(options.project) : undefined;
337
+ const pool = tags.length > 0 || repo ? filterEntries(entries, { tags, repo, ignoreCase: !config }) : entries;
338
+ if (pool.length === 0 && entries.length > 0 && !options.json) {
339
+ const what = [tags.length > 0 ? (0, tagFilter_1.describeTags)(tags) : '', repo ? `repo '${options.project}'` : ''].filter(Boolean).join(' in ');
340
+ console.log(format_1.c.muted(`No saved prompts matched ${what}.`));
341
+ return;
342
+ }
343
+ const ranked = (0, rank_1.rankLibrary)(pool, text, limit);
311
344
  if (options.json) {
312
345
  console.log(JSON.stringify(ranked.map(({ item, score }) => ({
313
346
  id: item.id,
@@ -329,6 +362,6 @@ async function suggestCommand(words, options = {}) {
329
362
  if (item.description)
330
363
  console.log(format_1.c.muted(` ${item.description}`));
331
364
  }
332
- const command = useCommandFor(ranked[0].item);
365
+ const command = getCommandFor(ranked[0].item);
333
366
  console.log(format_1.c.muted(command ? `\nUse one: ${command}` : '\nUse one: its name has characters a shell would act on, so find it with `ple list`.'));
334
367
  }
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+ /**
3
+ * `ple visibility` — make single prompts public or private.
4
+ *
5
+ * ple visibility <prompt> public|private [--project <repo>] [--yes] [--json]
6
+ * ple visibility --all --project <repo> public|private [--yes] [--json]
7
+ *
8
+ * A prompt page is public only when BOTH the repo and the prompt are public
9
+ * (`ple repo visibility` is the repo half). The server enforces who may change
10
+ * what (owner only); the checks here only give a faster, clearer message.
11
+ * Going private never asks; going public needs a yes (a person, or --yes).
12
+ */
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.visibilityCommand = visibilityCommand;
15
+ const api_client_1 = require("../lib/api-client");
16
+ const confirm_1 = require("../lib/confirm");
17
+ const format_1 = require("../lib/format");
18
+ const promptResolver_1 = require("../lib/promptResolver");
19
+ const repoRef_1 = require("../lib/repoRef");
20
+ const local_1 = require("./local");
21
+ const repo_1 = require("./repo");
22
+ const PAGE = 50;
23
+ const MAX_PAGES = 40;
24
+ function explain(err) {
25
+ if (err instanceof api_client_1.ApiError && err.status === 403)
26
+ throw new Error(`Only the owner can change a prompt's visibility. (${err.message})`);
27
+ return (0, repo_1.explainRepoError)(err);
28
+ }
29
+ async function allPromptsOf(projectId) {
30
+ const out = [];
31
+ for (let page = 1; page <= MAX_PAGES; page++) {
32
+ const batch = await (0, api_client_1.listPrompts)({ projectId, limit: PAGE, page });
33
+ out.push(...batch);
34
+ if (batch.length < PAGE)
35
+ break;
36
+ }
37
+ return out;
38
+ }
39
+ async function approvePublic(question, options, deps) {
40
+ if (options.yes)
41
+ return true;
42
+ const interactive = deps.isTTY ?? Boolean(process.stdin.isTTY && process.stdout.isTTY);
43
+ if (!interactive)
44
+ throw new Error('Making prompts public needs confirmation: re-run with --yes.');
45
+ const ok = await (deps.confirm ?? confirm_1.confirm)(question);
46
+ if (!ok)
47
+ console.log(format_1.c.muted('Cancelled — nothing changed.'));
48
+ return ok;
49
+ }
50
+ async function visibilityCommand(args = [], options = {}, deps = {}) {
51
+ const usage = 'Usage: ple visibility <prompt> public|private or ple visibility --all --project <repo> public|private';
52
+ const expected = options.all ? 1 : 2;
53
+ if (args.length !== expected)
54
+ throw new Error(usage);
55
+ const target = (0, repoRef_1.parseVisibility)(args[args.length - 1]);
56
+ if (options.all && !options.project)
57
+ throw new Error('--all needs --project <repo>. ' + usage);
58
+ if ((0, local_1.isSignedOut)())
59
+ throw new Error('Visibility lives in your account. Sign in first: ple login');
60
+ await (0, api_client_1.ensureAuthed)();
61
+ const repos = await (0, api_client_1.listProjectsDetailed)();
62
+ const repoOf = (projectId) => repos.find((r) => r.id === projectId);
63
+ if (options.all) {
64
+ const repo = (0, repoRef_1.resolveRepoRef)(options.project, repos);
65
+ const prompts = await allPromptsOf(repo.id);
66
+ const todo = prompts.filter((p) => (p.visibility ?? 'private') !== target);
67
+ if (todo.length === 0) {
68
+ if (options.json)
69
+ console.log(JSON.stringify({ ok: true, repo: repo.name, target, changed: 0, unchanged: prompts.length }, null, 2));
70
+ else
71
+ console.log(format_1.c.muted(`All ${prompts.length} prompt${prompts.length === 1 ? '' : 's'} in '${repo.name}' are already ${target}. Nothing changed.`));
72
+ return;
73
+ }
74
+ if (target === 'public') {
75
+ const ok = await approvePublic(`Make ${todo.length} prompt${todo.length === 1 ? '' : 's'} in '${repo.name}' public? Their text becomes readable by anyone once the repo is public too. [y/N] `, options, deps);
76
+ if (!ok)
77
+ return;
78
+ }
79
+ let changed = 0;
80
+ const failed = [];
81
+ for (const p of todo) {
82
+ try {
83
+ await (0, api_client_1.setPromptVisibility)(p.id, target);
84
+ changed++;
85
+ }
86
+ catch (err) {
87
+ failed.push({ id: p.id, title: p.title, error: err instanceof Error ? err.message : String(err) });
88
+ }
89
+ }
90
+ if (options.json) {
91
+ console.log(JSON.stringify({ ok: failed.length === 0, repo: repo.name, target, changed, unchanged: prompts.length - todo.length, failed }, null, 2));
92
+ }
93
+ else {
94
+ console.log(format_1.c.success(`✓ ${changed} prompt${changed === 1 ? '' : 's'} in '${repo.name}' ${changed === 1 ? 'is' : 'are'} now ${target}.`));
95
+ for (const f of failed)
96
+ console.log(format_1.c.warn(` ⚠ ${(0, format_1.shortId)(f.id)} ${f.title}: ${f.error}`));
97
+ if (target === 'public' && repo.visibility !== 'public') {
98
+ console.log(format_1.c.warn(` The repo is still private, so none of this is visible yet: ple repo visibility ${repo.slug ?? (0, format_1.shortId)(repo.id)} public`));
99
+ }
100
+ }
101
+ if (failed.length > 0)
102
+ process.exitCode = 1;
103
+ return;
104
+ }
105
+ const projectId = options.project ? await (0, promptResolver_1.resolveProjectId)(options.project) : undefined;
106
+ const prompt = await (0, promptResolver_1.resolvePromptByName)(args[0], { projectId });
107
+ if (!prompt) {
108
+ process.exitCode = 1;
109
+ return;
110
+ }
111
+ const repo = repoOf(prompt.project_id);
112
+ if ((prompt.visibility ?? 'private') === target) {
113
+ if (options.json)
114
+ console.log(JSON.stringify({ ok: true, changed: false, id: prompt.id, visibility: target }, null, 2));
115
+ else
116
+ console.log(format_1.c.muted(`'${prompt.title}' is already ${target}. Nothing changed.`));
117
+ return;
118
+ }
119
+ if (target === 'public') {
120
+ const ok = await approvePublic(`Make '${prompt.title}' public? Its text becomes readable by anyone once its repo is public too. [y/N] `, options, deps);
121
+ if (!ok)
122
+ return;
123
+ }
124
+ try {
125
+ await (0, api_client_1.setPromptVisibility)(prompt.id, target);
126
+ }
127
+ catch (err) {
128
+ explain(err);
129
+ }
130
+ if (options.json) {
131
+ console.log(JSON.stringify({ ok: true, changed: true, id: prompt.id, title: prompt.title, visibility: target, repo_visibility: repo?.visibility ?? null }, null, 2));
132
+ return;
133
+ }
134
+ console.log(format_1.c.success(`✓ '${prompt.title}' is now ${target}.`));
135
+ if (target === 'public' && repo && repo.visibility !== 'public') {
136
+ console.log(format_1.c.warn(` Its repo '${repo.name}' is private, so the page stays hidden: ple repo visibility ${repo.slug ?? (0, format_1.shortId)(repo.id)} public`));
137
+ }
138
+ }
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NOT_SIGNED_IN = void 0;
4
+ exports.describeTrialEnd = describeTrialEnd;
5
+ exports.renderWhoami = renderWhoami;
6
+ exports.whoamiJson = whoamiJson;
7
+ exports.whoamiCommand = whoamiCommand;
8
+ const api_client_1 = require("../lib/api-client");
9
+ const config_1 = require("../lib/config");
10
+ const format_1 = require("../lib/format");
11
+ const local_1 = require("./local");
12
+ exports.NOT_SIGNED_IN = 'Not signed in. Run `ple login`.';
13
+ const DAY_MS = 86400000;
14
+ /** "23 / 25", or "23 (no limit)" when the plan has none, or just "23" when the limit is not reported. */
15
+ function quota(used, limit, unlimited) {
16
+ if (used === null)
17
+ return limit === null ? unlimited : `? / ${limit}`;
18
+ return limit === null ? `${used} ${format_1.c.muted(`(${unlimited})`)}` : `${used} / ${limit}`;
19
+ }
20
+ /** "ends 2026-11-12 (in 13 days)" for a trial that is still running; "ended …" afterwards. */
21
+ function describeTrialEnd(iso, now = Date.now()) {
22
+ const end = Date.parse(iso);
23
+ const date = new Date(end).toISOString().slice(0, 10);
24
+ const days = Math.ceil((end - now) / DAY_MS);
25
+ if (days < 0)
26
+ return `ended ${date}`;
27
+ if (days === 0)
28
+ return `ends ${date} (today)`;
29
+ return `ends ${date} (in ${days} day${days === 1 ? '' : 's'})`;
30
+ }
31
+ /** Plain lines for a terminal. The session token is never part of this. */
32
+ function renderWhoami(email, limits, now = Date.now()) {
33
+ const { plan, usage } = limits;
34
+ const rows = [
35
+ ['Plan', plan.name],
36
+ ['Prompts', quota(usage.promptCount, plan.promptLimit, 'no limit')],
37
+ ['Repos', quota(usage.projectCount, plan.projectLimit, 'no limit')],
38
+ // The endpoint reports the per-prompt cap only, not how close each prompt is to it.
39
+ ['Versions', plan.versionLimitPerPrompt === null ? 'no limit' : `up to ${plan.versionLimitPerPrompt} per prompt`],
40
+ ];
41
+ if (plan.trialEndsAt)
42
+ rows.push(['Trial', describeTrialEnd(plan.trialEndsAt, now)]);
43
+ return [format_1.c.title(email || 'signed in'), ...rows.map(([k, v]) => `${format_1.c.label(k.padEnd(10))}${v}`)];
44
+ }
45
+ /** One JSON object for scripts. No token, no refresh token — only account facts. */
46
+ function whoamiJson(email, limits) {
47
+ const { plan, usage } = limits;
48
+ return {
49
+ signed_in: true,
50
+ email,
51
+ plan: { id: plan.id, name: plan.name, is_pro: plan.isPro },
52
+ usage: { prompts: usage.promptCount, repos: usage.projectCount },
53
+ limits: { prompts: plan.promptLimit, repos: plan.projectLimit, versions_per_prompt: plan.versionLimitPerPrompt },
54
+ trial_ends_at: plan.trialEndsAt,
55
+ };
56
+ }
57
+ /**
58
+ * `ple whoami` (alias `account`) — which account is this terminal signed in as, on which plan, and how much
59
+ * of it is used. Only your own account; the email is shown in full. Plan and counts come from
60
+ * GET /api/account/limits (the endpoint the web app's limit checks use). Signed out: one line, exit code 1.
61
+ */
62
+ async function whoamiCommand(options = {}) {
63
+ if ((0, local_1.isSignedOut)()) {
64
+ if (options.json)
65
+ console.log(JSON.stringify({ signed_in: false }));
66
+ else
67
+ console.error(exports.NOT_SIGNED_IN);
68
+ process.exitCode = 1;
69
+ return;
70
+ }
71
+ await (0, api_client_1.ensureAuthed)();
72
+ const limits = await (0, api_client_1.getAccountLimits)();
73
+ const email = (0, format_1.safeText)((0, config_1.readConfig)()?.email ?? '');
74
+ if (options.json) {
75
+ console.log(JSON.stringify(whoamiJson(email, limits)));
76
+ return;
77
+ }
78
+ for (const line of renderWhoami(email, limits))
79
+ console.log(line);
80
+ }
package/dist/help.js CHANGED
@@ -11,10 +11,10 @@ exports.formatRootHelp = formatRootHelp;
11
11
  const commander_1 = require("commander");
12
12
  exports.COMMAND_GROUPS = [
13
13
  { title: 'Prompts', commands: ['save', 'get', 'show', 'copy', 'list', 'search', 'log', 'diff', 'rollback', 'tag', 'improve', 'loop'] },
14
- { title: 'Repos', commands: ['repo'] },
15
- { title: 'Account', commands: ['login', 'logout'] },
14
+ { title: 'Repos', commands: ['repo', 'visibility'] },
15
+ { title: 'Account', commands: ['login', 'logout', 'whoami'] },
16
16
  { title: 'Import / export / sync', commands: ['import', 'export', 'sync'] },
17
- { title: 'Insights & settings', commands: ['stats', 'suggest', 'config'] },
17
+ { title: 'Insights & settings', commands: ['stats', 'suggest', 'config', 'feedback'] },
18
18
  ];
19
19
  const EXAMPLES = [
20
20
  'ple save "code review" -m "Review this diff: {{diff}}" # no account needed',
@@ -26,6 +26,8 @@ const EXIT_CODES = [
26
26
  '0 success',
27
27
  '1 fix it yourself: bad input, not signed in, not found, not allowed, plan limit',
28
28
  '2 try again later: no network, timeout, rate limit, server error',
29
+ ' (an unknown command also exits 2: a usage error, retrying will not help)',
30
+ ' (`ple feedback` has its own table, see `ple feedback --help`)',
29
31
  ];
30
32
  function formatRootHelp(cmd, helper) {
31
33
  // configureHelp() is inherited by subcommands; only the root gets the grouped layout.
package/dist/index.js CHANGED
@@ -6,13 +6,17 @@
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  const program_1 = require("./program");
8
8
  const updateCheck_1 = require("./lib/updateCheck");
9
+ const feedbackQueue_1 = require("./lib/feedbackQueue");
9
10
  (0, program_1.buildProgram)()
10
11
  .parseAsync(process.argv)
11
- .then(() => {
12
+ .then(async () => {
12
13
  // Once per run, after the command succeeded: at most one stderr line a day about a newer version, and a
13
14
  // detached background lookup when one is due. Never waits for the network, never throws, silent in
14
15
  // pipes, CI and when switched off (see lib/updateCheck.ts).
15
16
  (0, updateCheck_1.afterCommand)();
17
+ // Reports that `ple feedback` could not deliver are retried here, silently, within 2 seconds, at most every
18
+ // 15 minutes and never after the offline commands (see lib/feedbackQueue.ts). Never throws.
19
+ await (0, feedbackQueue_1.flushAfterCommand)();
16
20
  })
17
21
  .catch((err) => {
18
22
  // Commands handle their own errors; this only catches a bug in the wiring itself.