promptlike 0.2.2 → 0.3.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.
@@ -9,9 +9,10 @@ const format_1 = require("../lib/format");
9
9
  * `ple copy <name>` — resolve a prompt by title (or short id) and copy its
10
10
  * content to the system clipboard.
11
11
  */
12
- async function copyCommand(name) {
12
+ async function copyCommand(name, options = {}) {
13
13
  await (0, api_client_1.ensureAuthed)();
14
- const prompt = await (0, promptResolver_1.resolvePromptByName)(name);
14
+ const projectId = options.project ? await (0, promptResolver_1.resolveProjectId)(options.project) : undefined;
15
+ const prompt = await (0, promptResolver_1.resolvePromptByName)(name, { projectId });
15
16
  if (!prompt) {
16
17
  process.exitCode = 1;
17
18
  return;
@@ -21,7 +21,8 @@ const promptVariables_1 = require("../lib/promptVariables");
21
21
  */
22
22
  async function getCommand(name, options = {}) {
23
23
  await (0, api_client_1.ensureAuthed)();
24
- const prompt = await (0, promptResolver_1.resolvePromptByName)(name);
24
+ const projectId = options.project ? await (0, promptResolver_1.resolveProjectId)(options.project) : undefined;
25
+ const prompt = await (0, promptResolver_1.resolvePromptByName)(name, { projectId });
25
26
  if (!prompt) {
26
27
  process.exitCode = 1;
27
28
  return;
@@ -37,7 +37,8 @@ function parsePick(raw, max) {
37
37
  */
38
38
  async function improveCommand(name, options = {}) {
39
39
  await (0, api_client_1.ensureAuthed)();
40
- const prompt = await (0, promptResolver_1.resolvePromptByName)(name);
40
+ const projectId = options.project ? await (0, promptResolver_1.resolveProjectId)(options.project) : undefined;
41
+ const prompt = await (0, promptResolver_1.resolvePromptByName)(name, { projectId });
41
42
  if (!prompt) {
42
43
  process.exitCode = 1;
43
44
  return;
@@ -32,7 +32,8 @@ function parseRounds(raw) {
32
32
  async function loopCommand(name, options = {}) {
33
33
  const rounds = parseRounds(options.rounds);
34
34
  await (0, api_client_1.ensureAuthed)();
35
- const prompt = await (0, promptResolver_1.resolvePromptByName)(name);
35
+ const projectId = options.project ? await (0, promptResolver_1.resolveProjectId)(options.project) : undefined;
36
+ const prompt = await (0, promptResolver_1.resolvePromptByName)(name, { projectId });
36
37
  if (!prompt) {
37
38
  process.exitCode = 1;
38
39
  return;
@@ -10,9 +10,10 @@ const format_1 = require("../lib/format");
10
10
  * Unlike `copy`, this doesn't touch the clipboard: it renders the three
11
11
  * sections (role / description / context) under readable headers.
12
12
  */
13
- async function showCommand(name) {
13
+ async function showCommand(name, options = {}) {
14
14
  await (0, api_client_1.ensureAuthed)();
15
- const prompt = await (0, promptResolver_1.resolvePromptByName)(name);
15
+ const projectId = options.project ? await (0, promptResolver_1.resolveProjectId)(options.project) : undefined;
16
+ const prompt = await (0, promptResolver_1.resolvePromptByName)(name, { projectId });
16
17
  if (!prompt) {
17
18
  process.exitCode = 1;
18
19
  return;
package/dist/index.js CHANGED
@@ -55,22 +55,26 @@ program
55
55
  program
56
56
  .command('copy <name>')
57
57
  .description('Copy a prompt to the clipboard (by title or short id)')
58
+ .option('--project <repo>', 'Scope to one repo (name, slug, or id) when titles collide')
58
59
  .action(runWithErrorHandler(copy_1.copyCommand));
59
60
  program
60
61
  .command('show <name>')
61
62
  .description('Show a prompt in the terminal')
63
+ .option('--project <repo>', 'Scope to one repo (name, slug, or id) when titles collide')
62
64
  .action(runWithErrorHandler(show_1.showCommand));
63
65
  program
64
66
  .command('get <name>')
65
67
  .description("Print a prompt raw to stdout; fill {{variables}} (agent/pipe friendly)")
66
68
  .option('-v, --var <keyval>', 'Fill a variable — key=value (repeatable)', get_1.collectVar, {})
67
69
  .option('-c, --copy', 'Also copy the output to the clipboard')
70
+ .option('--project <repo>', 'Scope to one repo (name, slug, or id) when titles collide')
68
71
  .action(runWithErrorHandler(get_1.getCommand));
69
72
  program
70
73
  .command('improve <name>')
71
74
  .option('-p, --pick <n>', 'Non-interactive: auto-pick variant N (1..3), 0 to cancel — for scripts/agents')
72
75
  .description('Generate AI variants of a prompt, pick a winner, save it as a new version (Pro)')
73
76
  .option('-f, --focus <hint>', "Steer the variants (e.g. 'shorter', 'more explicit output format')")
77
+ .option('--project <repo>', 'Scope to one repo (name, slug, or id) when titles collide')
74
78
  .action(runWithErrorHandler(improve_1.improveCommand));
75
79
  program
76
80
  .command('loop <name>')
@@ -79,6 +83,7 @@ program
79
83
  .option('-r, --rounds <n>', 'Number of improvement rounds', '1')
80
84
  .option('-f, --focus <hint>', 'Steer the variants')
81
85
  .option('-p, --pick <n>', 'Non-interactive: auto-pick variant N each round + auto-continue — for scripts/agents')
86
+ .option('--project <repo>', 'Scope to one repo (name, slug, or id) when titles collide')
82
87
  .action(runWithErrorHandler(loop_1.loopCommand));
83
88
  program
84
89
  .command('search <keyword>')
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.login = login;
18
18
  exports.ensureAuthed = ensureAuthed;
19
19
  exports.listPrompts = listPrompts;
20
+ exports.listProjects = listProjects;
20
21
  exports.getPromptById = getPromptById;
21
22
  exports.recordPromptUse = recordPromptUse;
22
23
  const constants_1 = require("./constants");
@@ -172,7 +173,7 @@ async function ensureAuthed() {
172
173
  await refreshSession();
173
174
  }
174
175
  }
175
- /** GET /api/prompts — list the user's prompts (optionally by tag / search). */
176
+ /** GET /api/prompts — list the user's prompts (optionally by tag / search / project). */
176
177
  async function listPrompts(params = {}) {
177
178
  const res = await apiFetch('/api/prompts', {
178
179
  query: {
@@ -180,10 +181,18 @@ async function listPrompts(params = {}) {
180
181
  search: params.search,
181
182
  limit: params.limit,
182
183
  page: params.page,
184
+ projectId: params.projectId,
183
185
  },
184
186
  });
185
187
  return res.prompts ?? [];
186
188
  }
189
+ /** GET /api/projects — list the user's accessible repos (for --project resolution). */
190
+ async function listProjects() {
191
+ const res = await apiFetch('/api/projects', {
192
+ query: { limit: 100 },
193
+ });
194
+ return res.projects ?? [];
195
+ }
187
196
  /** GET /api/prompts/{id} — full detail; returns null when not found (404). */
188
197
  async function getPromptById(id) {
189
198
  try {
@@ -1,11 +1,32 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveProjectId = resolveProjectId;
3
4
  exports.resolvePromptByName = resolvePromptByName;
4
5
  exports.fetchPromptContent = fetchPromptContent;
5
6
  const format_1 = require("./format");
6
7
  const api_client_1 = require("./api-client");
7
8
  const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
8
9
  const SHORT_ID_RE = /^[0-9a-f]{8,}$/i;
10
+ /**
11
+ * Resolve a `--project <value>` argument (UUID, exact name, or slug) to a
12
+ * project id. Throws a friendly error when it matches zero or multiple repos.
13
+ */
14
+ async function resolveProjectId(value) {
15
+ const trimmed = value.trim();
16
+ if (UUID_RE.test(trimmed))
17
+ return trimmed;
18
+ const projects = await (0, api_client_1.listProjects)();
19
+ const lower = trimmed.toLowerCase();
20
+ const matches = projects.filter((p) => p.name.toLowerCase() === lower || (p.slug ?? '').toLowerCase() === lower);
21
+ if (matches.length === 1)
22
+ return matches[0].id;
23
+ if (matches.length === 0) {
24
+ throw new Error(`No repo matched '${trimmed}'. Run 'ple list' or use the repo's exact name, slug, or id.`);
25
+ }
26
+ // Multiple repos share this name — ask for the id.
27
+ const hint = matches.map((p) => `${(0, format_1.shortId)(p.id)} ${p.name}`).join(', ');
28
+ throw new Error(`'${trimmed}' matched multiple repos (${hint}). Use the repo id.`);
29
+ }
9
30
  /**
10
31
  * Resolve a user-supplied `<name>` argument to a single prompt.
11
32
  * - Full UUID → direct detail lookup.
@@ -16,21 +37,27 @@ const SHORT_ID_RE = /^[0-9a-f]{8,}$/i;
16
37
  *
17
38
  * Throws on auth/network errors (the command wrapper catches them).
18
39
  */
19
- async function resolvePromptByName(name) {
40
+ async function resolvePromptByName(name, scope = {}) {
20
41
  const trimmed = name.trim();
21
42
  if (!trimmed) {
22
43
  throw new Error('Cannot resolve an empty name.');
23
44
  }
24
- // 1) Full UUID → detail endpoint.
45
+ const projectId = scope.projectId;
46
+ // 1) Full UUID → detail endpoint. (Scope is advisory; verify it belongs.)
25
47
  if (UUID_RE.test(trimmed)) {
26
48
  const found = await (0, api_client_1.getPromptById)(trimmed);
27
- if (found)
49
+ if (found) {
50
+ if (projectId && found.project_id && found.project_id !== projectId) {
51
+ console.error(format_1.c.error(`Prompt '${(0, format_1.shortId)(found.id)}' is not in the selected repo.`));
52
+ return null;
53
+ }
28
54
  return found;
55
+ }
29
56
  // Not found by id — fall through to a title search.
30
57
  }
31
58
  // 2) Short-id prefix (hex, 8+ chars, not a full UUID) → match a page.
32
59
  if (!UUID_RE.test(trimmed) && SHORT_ID_RE.test(trimmed)) {
33
- const page = await (0, api_client_1.listPrompts)({ limit: 100 });
60
+ const page = await (0, api_client_1.listPrompts)({ limit: 100, projectId });
34
61
  const lower = trimmed.toLowerCase();
35
62
  const matches = page.filter((p) => p.id.toLowerCase().startsWith(lower));
36
63
  if (matches.length === 1)
@@ -42,12 +69,13 @@ async function resolvePromptByName(name) {
42
69
  // No id match — fall through to a title search.
43
70
  }
44
71
  // 3) Title / description search.
45
- const results = await (0, api_client_1.listPrompts)({ search: trimmed, limit: 100 });
72
+ const results = await (0, api_client_1.listPrompts)({ search: trimmed, limit: 100, projectId });
46
73
  const lower = trimmed.toLowerCase();
47
74
  const titleMatches = results.filter((p) => p.title.toLowerCase().includes(lower));
48
75
  const pool = titleMatches.length > 0 ? titleMatches : results;
49
76
  if (pool.length === 0) {
50
- console.error(format_1.c.error(`No prompt matched '${trimmed}'.`));
77
+ const where = projectId ? ' in the selected repo' : '';
78
+ console.error(format_1.c.error(`No prompt matched '${trimmed}'${where}.`));
51
79
  return null;
52
80
  }
53
81
  if (pool.length === 1)
@@ -60,9 +88,11 @@ async function resolvePromptByName(name) {
60
88
  return null;
61
89
  }
62
90
  function printAmbiguous(query, rows) {
63
- console.error(format_1.c.warn(`'${query}' matched multiple prompts. Use a more specific name or short id:`));
91
+ console.error(format_1.c.warn(`'${query}' matched multiple prompts. Narrow with --project <repo>, or use a short id:`));
64
92
  for (const r of rows.slice(0, 10)) {
65
- console.error(` ${format_1.c.muted((0, format_1.shortId)(r.id))} ${r.title}`);
93
+ // Repo adını göster (F-analiz): aynı başlık iki repo'daysa hangisi belli olsun.
94
+ const repo = r.project_name ? format_1.c.muted(` (${r.project_name})`) : '';
95
+ console.error(` ${format_1.c.muted((0, format_1.shortId)(r.id))} ${r.title}${repo}`);
66
96
  }
67
97
  }
68
98
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "promptlike",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "Terminal access to your PromptLikeEngineer prompt library - search, read, and copy your saved prompts without leaving the shell.",
5
5
  "bin": {
6
6
  "ple": "dist/index.js"