promptlike 0.2.1 → 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.
package/README.md CHANGED
@@ -350,7 +350,14 @@ HTTP, so there is no type-sync step for the CLI.
350
350
 
351
351
  Publishing is automated: pushing a `cli-v*` git tag runs the
352
352
  `.github/workflows/cli-publish.yml` workflow, which typechecks, tests, builds,
353
- and runs `npm publish --access public` (using the `NPM_TOKEN` repo secret).
353
+ and runs `npm publish --access public`.
354
+
355
+ Auth is **npm Trusted Publishing (OIDC)** — no token. npm verifies via OpenID
356
+ Connect that this exact repo + workflow is the package's configured trusted
357
+ publisher (npmjs.com/package/promptlike → Settings → Trusted Publisher:
358
+ `zeynepaslierhann` / `PromptLikeEngineer` / `cli-publish.yml`). The workflow
359
+ needs `permissions: id-token: write` and npm >= 11.5.1 (the runner upgrades npm
360
+ on Node 22), which the current workflow already sets.
354
361
 
355
362
  This CLI lives in a monorepo, so bump the version **without** letting `npm`
356
363
  create its own tag/commit, then push a `cli-v<version>` tag whose number
@@ -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;
@@ -30,6 +31,7 @@ async function copyCommand(name) {
30
31
  }
31
32
  try {
32
33
  await (0, clipboard_1.copyToClipboard)(text);
34
+ (0, api_client_1.recordPromptUse)(prompt.id); // Most Used verisi (REV-6) — fire-and-forget
33
35
  console.log(format_1.c.success(`✓ Copied: ${prompt.title}`) +
34
36
  format_1.c.muted(` (${(0, format_1.shortId)(prompt.id)}, ${text.length} chars)`));
35
37
  }
@@ -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;
@@ -47,6 +48,7 @@ async function getCommand(name, options = {}) {
47
48
  console.error(format_1.c.muted(` Fill with: --var ${remaining[0]}=...`));
48
49
  }
49
50
  // THE OUTPUT — raw, to stdout (agent-readable).
51
+ (0, api_client_1.recordPromptUse)(prompt.id); // Most Used verisi (REV-6) — fire-and-forget
50
52
  process.stdout.write(filled.endsWith('\n') ? filled : filled + '\n');
51
53
  if (options.copy) {
52
54
  try {
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.loopChangelog = loopChangelog;
4
+ exports.parsePick = parsePick;
4
5
  exports.improveCommand = improveCommand;
5
6
  const api_client_1 = require("../lib/api-client");
6
7
  const promptResolver_1 = require("../lib/promptResolver");
@@ -11,6 +12,18 @@ const loopUx_1 = require("../lib/loopUx");
11
12
  function loopChangelog(variant) {
12
13
  return `Loop(${variant.strategy}): ${variant.rationale}`.trim();
13
14
  }
15
+ /** Parse/validate `--pick` against the variant count. undefined = not passed
16
+ * (fall back to interactive). Throws on out-of-range. */
17
+ function parsePick(raw, max) {
18
+ if (raw === undefined)
19
+ return undefined;
20
+ const trimmed = raw.trim();
21
+ const n = Number.parseInt(trimmed, 10);
22
+ if (Number.isNaN(n) || String(n) !== trimmed || n < 0 || n > max) {
23
+ throw new Error(`Invalid --pick '${raw}' — expected 0 (cancel) or 1..${max}.`);
24
+ }
25
+ return n;
26
+ }
14
27
  /**
15
28
  * `ple improve <name> [--focus <hint>]` — single-round Loop Engineering.
16
29
  *
@@ -24,7 +37,8 @@ function loopChangelog(variant) {
24
37
  */
25
38
  async function improveCommand(name, options = {}) {
26
39
  await (0, api_client_1.ensureAuthed)();
27
- 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 });
28
42
  if (!prompt) {
29
43
  process.exitCode = 1;
30
44
  return;
@@ -41,7 +55,8 @@ async function improveCommand(name, options = {}) {
41
55
  (0, loopUx_1.renderVariants)(variants, baseline);
42
56
  console.log();
43
57
  console.log(format_1.c.muted(`${tokensUsed} AI tokens used.`));
44
- const pick = await (0, loopUx_1.selectVariant)(variants.length);
58
+ const override = parsePick(options.pick, variants.length);
59
+ const pick = override !== undefined ? override : await (0, loopUx_1.selectVariant)(variants.length);
45
60
  if (pick === 0) {
46
61
  console.log(format_1.c.muted('Cancelled — nothing saved.'));
47
62
  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;
@@ -60,7 +61,8 @@ async function loopCommand(name, options = {}) {
60
61
  }
61
62
  console.log();
62
63
  console.log(format_1.c.muted(`${tokensUsed} AI tokens used this round.`));
63
- const pick = await (0, loopUx_1.selectVariant)(variants.length);
64
+ const override = (0, improve_1.parsePick)(options.pick, variants.length);
65
+ const pick = override !== undefined ? override : await (0, loopUx_1.selectVariant)(variants.length);
64
66
  if (pick === 0) {
65
67
  console.log(format_1.c.muted('Cancelled — nothing saved this round.'));
66
68
  return;
@@ -73,7 +75,8 @@ async function loopCommand(name, options = {}) {
73
75
  // round generates from it. Track it locally for size comparisons.
74
76
  baseline = (0, loopUx_1.variantText)(winner);
75
77
  if (round < rounds) {
76
- const goOn = await (0, loopUx_1.confirmContinue)();
78
+ // --pick verildiyse non-interactive niyet → sonraki tura otomatik geç.
79
+ const goOn = override !== undefined ? true : await (0, loopUx_1.confirmContinue)();
77
80
  if (!goOn) {
78
81
  console.log(format_1.c.muted(`Stopped after round ${round}.`));
79
82
  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;
@@ -23,6 +24,7 @@ async function showCommand(name) {
23
24
  process.exitCode = 1;
24
25
  return;
25
26
  }
27
+ (0, api_client_1.recordPromptUse)(prompt.id); // Most Used verisi (REV-6) — fire-and-forget
26
28
  // Header
27
29
  console.log();
28
30
  console.log(format_1.c.title(prompt.title));
package/dist/index.js CHANGED
@@ -55,21 +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>')
74
+ .option('-p, --pick <n>', 'Non-interactive: auto-pick variant N (1..3), 0 to cancel — for scripts/agents')
71
75
  .description('Generate AI variants of a prompt, pick a winner, save it as a new version (Pro)')
72
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')
73
78
  .action(runWithErrorHandler(improve_1.improveCommand));
74
79
  program
75
80
  .command('loop <name>')
@@ -77,6 +82,8 @@ program
77
82
  .option('-e, --exec <cmd>', 'Test each variant: prompt passed via PLE_PROMPT env + stdin; {} placeholder substituted')
78
83
  .option('-r, --rounds <n>', 'Number of improvement rounds', '1')
79
84
  .option('-f, --focus <hint>', 'Steer the variants')
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')
80
87
  .action(runWithErrorHandler(loop_1.loopCommand));
81
88
  program
82
89
  .command('search <keyword>')
@@ -17,7 +17,9 @@ 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;
22
+ exports.recordPromptUse = recordPromptUse;
21
23
  const constants_1 = require("./constants");
22
24
  const config_1 = require("./config");
23
25
  const NOT_LOGGED_IN = 'Not logged in. Run `ple login` first.';
@@ -110,7 +112,12 @@ async function refreshSession() {
110
112
  /** Core request helper. See module doc for behavior. */
111
113
  async function apiFetch(path, opts = {}) {
112
114
  const { method = 'GET', body, query, auth = true } = opts;
113
- const headers = { 'Content-Type': 'application/json' };
115
+ const headers = {
116
+ 'Content-Type': 'application/json',
117
+ // REV-6: sunucu CLI surumunu bilsin — eski CLI + degismis API semasi
118
+ // sessizce kirilmasin (kontrat gozlemlenebilirligi / min-version zemini)
119
+ 'X-CLI-Version': constants_1.CLI_VERSION,
120
+ };
114
121
  if (auth) {
115
122
  headers['Authorization'] = `Bearer ${getAccessTokenOrThrow()}`;
116
123
  }
@@ -166,7 +173,7 @@ async function ensureAuthed() {
166
173
  await refreshSession();
167
174
  }
168
175
  }
169
- /** 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). */
170
177
  async function listPrompts(params = {}) {
171
178
  const res = await apiFetch('/api/prompts', {
172
179
  query: {
@@ -174,10 +181,18 @@ async function listPrompts(params = {}) {
174
181
  search: params.search,
175
182
  limit: params.limit,
176
183
  page: params.page,
184
+ projectId: params.projectId,
177
185
  },
178
186
  });
179
187
  return res.prompts ?? [];
180
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
+ }
181
196
  /** GET /api/prompts/{id} — full detail; returns null when not found (404). */
182
197
  async function getPromptById(id) {
183
198
  try {
@@ -190,3 +205,14 @@ async function getPromptById(id) {
190
205
  throw err;
191
206
  }
192
207
  }
208
+ /**
209
+ * Kullanım kaydı (REV-6) — `ple copy/get/show` sonrası fire-and-forget.
210
+ * Most Used + ⌘K sıralaması eskiden yalnız web kopyalarını sayıyordu; ana
211
+ * reuse yüzeyi terminal olduğundan metrik köreliyordu. Hata YUTULUR:
212
+ * telemetri asıl komutu asla kırmaz.
213
+ */
214
+ function recordPromptUse(promptId) {
215
+ apiFetch(`/api/prompts/${promptId}/use`, { method: 'POST' }).catch(() => {
216
+ /* sessiz — telemetri */
217
+ });
218
+ }
@@ -23,6 +23,6 @@ function resolveEnv(key, fallback) {
23
23
  /** Base URL of the web API the CLI calls (no trailing slash). */
24
24
  exports.API_BASE_URL = resolveEnv('PROMPTLIKE_API_URL', BAKED_API_URL).replace(/\/+$/, '');
25
25
  exports.CLI_NAME = 'ple';
26
- exports.CLI_VERSION = '0.2.0';
26
+ exports.CLI_VERSION = '0.2.2';
27
27
  /** Web app URL — shown to the user when their prompt list is empty. */
28
28
  exports.WEB_APP_URL = 'https://promptlikeengineer.com';
@@ -58,13 +58,15 @@ function truncate(str, max) {
58
58
  return str;
59
59
  return str.slice(0, max - 1) + '…';
60
60
  }
61
- /** Üç parçalı içeriği (role/description/context) tek metne birleştir. */
61
+ /** Üç parçalı içeriği (role/description/context) tek metne birleştir.
62
+ * Yapısal parçalardan yeniden kurar ve BOŞ bölümleri atlar → yalnız-description
63
+ * bir prompt'ta başıboş `---` ayraçları çıkmaz (E2E bulgusu F2). Stored `content`
64
+ * yalnız üç parça da boşken (gerçek legacy tek-alan kaydı) yedek olarak kullanılır. */
62
65
  function joinPromptParts(parts) {
63
- // Eski kayıtlarda content tek alanda — onu önce dene
64
- if (parts.content && parts.content.trim())
65
- return parts.content;
66
66
  const segments = [parts.role_text, parts.description_text, parts.context_text]
67
67
  .map((s) => (s || '').trim())
68
68
  .filter(Boolean);
69
- return segments.join('\n\n---\n\n');
69
+ if (segments.length > 0)
70
+ return segments.join('\n\n---\n\n');
71
+ return parts.content && parts.content.trim() ? parts.content.trim() : '';
70
72
  }
@@ -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.1",
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"