promptlike 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.9.0 — 2026-10-19
4
+
5
+ - **New: conditional blocks in templates.** `{{#if var}}…{{else}}…{{/if}}` and
6
+ `{{#unless var}}…{{/unless}}` keep or drop text depending on a variable (set = a value
7
+ that is not empty, `false` or `0`; a variable you do not pass counts as not set). Text
8
+ only, nothing is executed; nesting is limited to 5 levels. Works in `ple get` and
9
+ `ple copy` with `--var`.
10
+ - **New: deployment labels.** `ple tag <name> <version> <label>` points a label
11
+ (`production`, `staging`, …) at a version; `--list` shows labels and recent moves,
12
+ `--remove <label>` deletes one. Every move is logged and the version history is never
13
+ touched. Needs an account and editor access.
14
+ - **New: `ple get --label <name>` and `ple copy --label <name>`** read the version a label
15
+ points at instead of the current one.
16
+
3
17
  ## 0.8.0 — 2026-10-17
4
18
 
5
19
  - **New: `ple repo`.** Create and manage repos from the terminal.
package/README.md CHANGED
@@ -20,7 +20,7 @@ diffable, and yours. Nothing leaves your machine until you ask it to.
20
20
 
21
21
  **Signing in is the upgrade, not the door.** A free
22
22
  [promptlikeengineer.com](https://promptlikeengineer.com) account adds version
23
- history with diff and rollback (Free holds up to 3 versions of each prompt; the 4th save asks you to upgrade),
23
+ history with diff and rollback (Free holds up to 10 versions of each prompt; the 11th save asks you to upgrade),
24
24
  the web editor, and the same library in Claude Code and other MCP clients.
25
25
  Bring your local prompts up with one explicit command:
26
26
 
@@ -239,6 +239,34 @@ $ ple get "code review" --var lang=python --copy
239
239
  Unfilled `{{variable}}` placeholders are left intact (not silently dropped) and
240
240
  reported on stderr.
241
241
 
242
+ **Conditional blocks.** `{{#if var}}…{{else}}…{{/if}}` and `{{#unless var}}…{{/unless}}`
243
+ keep or drop text depending on a variable. A variable counts as set when it has a
244
+ value that is not empty, `false` or `0`; a condition variable you do not pass is
245
+ treated as false. Text only — nothing is executed — and nesting is limited to 5
246
+ levels (an unbalanced or deeper template is left as plain text).
247
+
248
+ ```bash
249
+ $ ple get "pr review" --var strict=1 --var diff="$(git diff)"
250
+ # template: Review this diff.{{#if strict}} Flag every style nit.{{/if}}
251
+ ```
252
+
253
+ `--label <name>` reads the version a deployment label points at instead of the
254
+ current one (see `ple tag`). `ple copy` accepts the same `--var` and `--label`.
255
+
256
+ ### `ple tag <name> <version> <label>`
257
+
258
+ Point a deployment label (`production`, `staging`, any `a-z0-9._-` up to 32 chars)
259
+ at one version of a prompt. Needs an account (labels live on the server) and editor
260
+ access. Moving a label never touches the version history, and every move is logged
261
+ (who, when, from version, to version).
262
+
263
+ ```bash
264
+ ple tag "code review" 3 production # label v3 (moves it if it was elsewhere)
265
+ ple tag "code review" --list # labels + recent moves
266
+ ple tag "code review" --remove staging
267
+ ple get "code review" --label production
268
+ ```
269
+
242
270
  ### `ple improve <name> [--focus <hint>]`
243
271
 
244
272
  Loop Engineering, single round (**Pro**). The API generates 2-3 AI variants of
@@ -2,18 +2,22 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.copyCommand = copyCommand;
4
4
  const api_client_1 = require("../lib/api-client");
5
+ const tag_1 = require("./tag");
5
6
  const local_1 = require("./local");
6
7
  const promptResolver_1 = require("../lib/promptResolver");
7
8
  const clipboard_1 = require("../lib/clipboard");
8
9
  const format_1 = require("../lib/format");
10
+ const promptVariables_1 = require("../lib/promptVariables");
9
11
  /**
10
12
  * `ple copy <name>` — resolve a prompt by title (or short id) and copy its
11
13
  * content to the system clipboard.
12
14
  */
13
15
  async function copyCommand(name, options = {}) {
14
16
  if ((0, local_1.isSignedOut)()) {
17
+ if (options.label)
18
+ throw new Error("Deployment labels need an account (they live on the server). Run 'ple login' first.");
15
19
  (0, local_1.noteIgnoredProject)(options.project);
16
- await (0, local_1.localCopy)(name);
20
+ await (0, local_1.localCopy)(name, options.var ?? {});
17
21
  return;
18
22
  }
19
23
  await (0, api_client_1.ensureAuthed)();
@@ -23,18 +27,22 @@ async function copyCommand(name, options = {}) {
23
27
  process.exitCode = 1;
24
28
  return;
25
29
  }
26
- const version = (0, promptResolver_1.fetchPromptContent)(prompt);
30
+ const version = options.label
31
+ ? await (0, api_client_1.getLabeledVersion)(prompt.id, (0, tag_1.normalizeLabel)(options.label))
32
+ : (0, promptResolver_1.fetchPromptContent)(prompt);
27
33
  if (!version) {
28
34
  console.error(format_1.c.error(`'${prompt.title}' has no usable version.`));
29
35
  process.exitCode = 1;
30
36
  return;
31
37
  }
32
- const text = (0, format_1.joinPromptParts)(version);
33
- if (!text.trim()) {
38
+ const raw = (0, format_1.joinPromptParts)(version);
39
+ if (!raw.trim()) {
34
40
  console.error(format_1.c.error(`'${prompt.title}' has empty content.`));
35
41
  process.exitCode = 1;
36
42
  return;
37
43
  }
44
+ // Resolves {{#if}} blocks and fills --var values (plain unfilled {{vars}} stay as-is).
45
+ const text = (0, promptVariables_1.fillVariables)(raw, options.var ?? {});
38
46
  try {
39
47
  await (0, clipboard_1.copyToClipboard)(text);
40
48
  (0, api_client_1.recordPromptUse)(prompt.id); // Most Used verisi (REV-6) — fire-and-forget
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getCommand = getCommand;
4
4
  exports.collectVar = collectVar;
5
5
  const api_client_1 = require("../lib/api-client");
6
+ const tag_1 = require("./tag");
6
7
  const local_1 = require("./local");
7
8
  const promptResolver_1 = require("../lib/promptResolver");
8
9
  const clipboard_1 = require("../lib/clipboard");
@@ -22,6 +23,8 @@ const promptVariables_1 = require("../lib/promptVariables");
22
23
  */
23
24
  async function getCommand(name, options = {}) {
24
25
  if ((0, local_1.isSignedOut)()) {
26
+ if (options.label)
27
+ throw new Error("Deployment labels need an account (they live on the server). Run 'ple login' first.");
25
28
  (0, local_1.noteIgnoredProject)(options.project);
26
29
  await (0, local_1.localGet)(name, options.var ?? {}, options.copy === true);
27
30
  return;
@@ -33,7 +36,9 @@ async function getCommand(name, options = {}) {
33
36
  process.exitCode = 1;
34
37
  return;
35
38
  }
36
- const version = (0, promptResolver_1.fetchPromptContent)(prompt);
39
+ const version = options.label
40
+ ? await (0, api_client_1.getLabeledVersion)(prompt.id, (0, tag_1.normalizeLabel)(options.label))
41
+ : (0, promptResolver_1.fetchPromptContent)(prompt);
37
42
  if (!version) {
38
43
  console.error(format_1.c.error(`'${prompt.title}' has no usable version.`));
39
44
  process.exitCode = 1;
@@ -171,7 +171,7 @@ async function localGet(name, values, copy) {
171
171
  }
172
172
  }
173
173
  }
174
- async function localCopy(name) {
174
+ async function localCopy(name, values = {}) {
175
175
  const p = resolveOrExplain(name);
176
176
  if (!p)
177
177
  return;
@@ -180,9 +180,10 @@ async function localCopy(name) {
180
180
  process.exitCode = 1;
181
181
  return;
182
182
  }
183
+ const { text } = store.fillVariables(p.body, values);
183
184
  try {
184
- await (0, clipboard_1.copyToClipboard)(p.body);
185
- console.log(format_1.c.success(`✓ Copied: ${p.title}`) + format_1.c.muted(` (${p.slug}, ${p.body.length} chars)`));
185
+ await (0, clipboard_1.copyToClipboard)(text);
186
+ console.log(format_1.c.success(`✓ Copied: ${p.title}`) + format_1.c.muted(` (${p.slug}, ${text.length} chars)`));
186
187
  }
187
188
  catch {
188
189
  console.error(format_1.c.error('Could not access the clipboard.'));
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ /**
3
+ * `ple tag <name> <version> <label>` — point a deployment label (`production`, `staging`, …)
4
+ * at one version of a prompt. Moving a label keeps an audit trail (who/when/from → to); the version
5
+ * history itself never changes.
6
+ *
7
+ * ple tag "code review" 3 production # label v3 as production (moves it if it was elsewhere)
8
+ * ple tag "code review" --list # labels + recent moves
9
+ * ple tag "code review" --remove staging
10
+ *
11
+ * Then read it back with `ple get "code review" --label production`.
12
+ */
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.LABEL_RE = void 0;
15
+ exports.normalizeLabel = normalizeLabel;
16
+ exports.tagCommand = tagCommand;
17
+ const api_client_1 = require("../lib/api-client");
18
+ const format_1 = require("../lib/format");
19
+ const local_1 = require("./local");
20
+ const history_1 = require("./history");
21
+ /** Same rule as the server (a-z 0-9 . _ - ; 1-32 chars, starts alphanumeric). */
22
+ exports.LABEL_RE = /^[a-z0-9][a-z0-9._-]{0,31}$/;
23
+ function normalizeLabel(raw) {
24
+ const label = raw.trim().toLowerCase();
25
+ if (!exports.LABEL_RE.test(label)) {
26
+ throw new Error(`Invalid label '${raw}'. Use a-z, 0-9, '.', '_' or '-' (max 32 chars).`);
27
+ }
28
+ return label;
29
+ }
30
+ async function tagCommand(name, version, label, options = {}) {
31
+ if ((0, local_1.isSignedOut)()) {
32
+ throw new Error("Deployment labels need an account (they live on the server). Run 'ple login' first.");
33
+ }
34
+ const prompt = await (0, history_1.resolveForHistory)(name, options.project);
35
+ if (!prompt) {
36
+ process.exitCode = 1;
37
+ return;
38
+ }
39
+ if (options.list || (!version && !label && !options.remove)) {
40
+ const { labels, events } = await (0, api_client_1.listPromptLabels)(prompt.id);
41
+ if (labels.length === 0) {
42
+ console.log(format_1.c.muted(`No labels on '${prompt.title}'. Set one: ple tag "${prompt.title}" <version> production`));
43
+ }
44
+ for (const l of labels) {
45
+ console.log(`${l.label.padEnd(14)} → v${l.version_number} ${format_1.c.muted(new Date(l.set_at).toLocaleString())}`);
46
+ }
47
+ if (events.length > 0) {
48
+ console.log(format_1.c.muted('\nRecent moves:'));
49
+ for (const e of events.slice(0, 10)) {
50
+ const move = e.to_version_number == null
51
+ ? `removed from v${e.from_version_number ?? '?'}`
52
+ : e.from_version_number == null
53
+ ? `set to v${e.to_version_number}`
54
+ : `v${e.from_version_number} → v${e.to_version_number}`;
55
+ console.log(format_1.c.muted(` ${e.label}: ${move} (${new Date(e.created_at).toLocaleString()})`));
56
+ }
57
+ }
58
+ return;
59
+ }
60
+ if (options.remove) {
61
+ const target = normalizeLabel(options.remove);
62
+ const res = await (0, api_client_1.clearPromptLabel)(prompt.id, target);
63
+ console.log(res.changed
64
+ ? format_1.c.success(`✓ Removed label '${target}'`) + format_1.c.muted(` (was v${res.previous_version_number ?? '?'})`)
65
+ : format_1.c.muted(`Label '${target}' was not set — nothing to do.`));
66
+ return;
67
+ }
68
+ if (!version || !label) {
69
+ throw new Error('Usage: ple tag <name> <version> <label> (or --list / --remove <label>)');
70
+ }
71
+ const wanted = normalizeLabel(label);
72
+ const history = await (0, api_client_1.getPromptHistory)(prompt.id);
73
+ const target = (0, history_1.findVersion)(history.versions, version);
74
+ if (!target)
75
+ throw (0, history_1.versionNotFound)(version, history.versions);
76
+ const res = await (0, api_client_1.setPromptLabel)(prompt.id, wanted, target.id);
77
+ if (res.changed === false) {
78
+ console.log(format_1.c.muted(`'${wanted}' already points at v${target.version_number} — nothing to do.`));
79
+ return;
80
+ }
81
+ const moved = res.previous_version_number != null ? ` (moved from v${res.previous_version_number})` : '';
82
+ console.log(format_1.c.success(`✓ ${wanted} → v${target.version_number}`) + format_1.c.muted(`${moved} — ${history.title}`));
83
+ if (res.previous_version_number != null) {
84
+ console.log(format_1.c.muted(`Move it back with: ple tag "${history.title}" ${res.previous_version_number} ${wanted}`));
85
+ }
86
+ }
package/dist/help.js CHANGED
@@ -10,7 +10,7 @@ exports.COMMAND_GROUPS = void 0;
10
10
  exports.formatRootHelp = formatRootHelp;
11
11
  const commander_1 = require("commander");
12
12
  exports.COMMAND_GROUPS = [
13
- { title: 'Prompts', commands: ['save', 'get', 'show', 'copy', 'list', 'search', 'log', 'diff', 'rollback', 'improve', 'loop'] },
13
+ { title: 'Prompts', commands: ['save', 'get', 'show', 'copy', 'list', 'search', 'log', 'diff', 'rollback', 'tag', 'improve', 'loop'] },
14
14
  { title: 'Repos', commands: ['repo'] },
15
15
  { title: 'Account', commands: ['login', 'logout'] },
16
16
  { title: 'Import / export / sync', commands: ['import', 'export', 'sync'] },
@@ -34,6 +34,10 @@ exports.setProjectVisibility = setProjectVisibility;
34
34
  exports.getPromptById = getPromptById;
35
35
  exports.getPromptHistory = getPromptHistory;
36
36
  exports.rollbackPrompt = rollbackPrompt;
37
+ exports.listPromptLabels = listPromptLabels;
38
+ exports.setPromptLabel = setPromptLabel;
39
+ exports.clearPromptLabel = clearPromptLabel;
40
+ exports.getLabeledVersion = getLabeledVersion;
37
41
  exports.buildUseEventBody = buildUseEventBody;
38
42
  exports.recordPromptUse = recordPromptUse;
39
43
  exports.getUsageInsights = getUsageInsights;
@@ -534,6 +538,41 @@ async function rollbackPrompt(id, versionId) {
534
538
  body: { versionId },
535
539
  });
536
540
  }
541
+ /** GET /api/prompts/{id}/labels → current labels + the latest moves. */
542
+ async function listPromptLabels(id) {
543
+ const res = await apiFetch(`/api/prompts/${id}/labels`);
544
+ return { labels: res.labels ?? [], events: res.events ?? [] };
545
+ }
546
+ /** PUT /api/prompts/{id}/labels/{label} — point the label at a version (moving it leaves an audit event). */
547
+ async function setPromptLabel(id, label, versionId) {
548
+ return apiFetch(`/api/prompts/${id}/labels/${encodeURIComponent(label)}`, {
549
+ method: 'PUT',
550
+ body: { versionId },
551
+ });
552
+ }
553
+ /** DELETE /api/prompts/{id}/labels/{label}. */
554
+ async function clearPromptLabel(id, label) {
555
+ return apiFetch(`/api/prompts/${id}/labels/${encodeURIComponent(label)}`, { method: 'DELETE' });
556
+ }
557
+ /**
558
+ * GET /api/prompts/{id}?label=… → the version the label points at (content + number).
559
+ * Throws a readable error when the label does not exist.
560
+ */
561
+ async function getLabeledVersion(id, label) {
562
+ try {
563
+ const res = await apiFetch(`/api/prompts/${id}?label=${encodeURIComponent(label)}`);
564
+ const v = res.prompt?.labeled_version;
565
+ if (!v)
566
+ throw new Error(`Label '${label}' did not return a version.`);
567
+ return v;
568
+ }
569
+ catch (err) {
570
+ if (err instanceof ApiError && err.status === 404) {
571
+ throw new Error(`No label '${label}' on this prompt — see \`ple tag <name> --list\`.`);
572
+ }
573
+ throw err;
574
+ }
575
+ }
537
576
  /** Kullanım yüzeyleri — sunucudaki `USE_SURFACES` ile aynı küme (W1-1). */
538
577
  exports.USE_SURFACES = [
539
578
  'web', 'cli', 'mcp_tool', 'mcp_prompt', 'mcp_resource', 'extension', 'hook', 'repo', 'api', 'unknown',
@@ -76,6 +76,7 @@ const fs = __importStar(require("fs"));
76
76
  const os = __importStar(require("os"));
77
77
  const path = __importStar(require("path"));
78
78
  const fsSafe_1 = require("./fsSafe");
79
+ const promptTemplate_1 = require("./promptTemplate");
79
80
  /** Root of the local store. Overridable for tests and for people who relocate it. */
80
81
  function localRoot() {
81
82
  const override = process.env.PROMPTLIKE_HOME;
@@ -265,14 +266,6 @@ function search(query) {
265
266
  }
266
267
  /** Fill `{{variables}}`; report the ones left unfilled rather than shipping them. */
267
268
  function fillVariables(body, values) {
268
- const missing = new Set();
269
- const text = body.replace(/\{\{\s*([\w.-]+)\s*\}\}/g, (match, key) => {
270
- const value = values[key];
271
- if (value === undefined) {
272
- missing.add(key);
273
- return match;
274
- }
275
- return value;
276
- });
277
- return { text, missing: [...missing] };
269
+ const text = (0, promptTemplate_1.fillVariables)(body, values);
270
+ return { text, missing: (0, promptTemplate_1.extractVariables)(text) };
278
271
  }
@@ -0,0 +1,189 @@
1
+ "use strict";
2
+ /**
3
+ * Prompt şablon motoru - TEK KAYNAK (değişkenler + basit koşul).
4
+ *
5
+ * Bu dosya web (`src/lib/prompt-template.ts`), CLI (`cli/src/lib/promptTemplate.ts`)
6
+ * ve MCP (`mcp/src/lib/promptTemplate.ts`) içinde BAYT BAYT aynı durur; kayma
7
+ * `src/lib/prompt-template-drift.test.ts` ile yakalanır. Değiştirirsen üçünü de güncelle.
8
+ * Bağımlılıksız, saf fonksiyonlar. Kod ÇALIŞTIRMAZ: yalnız metin ağacı kurar ve yazdırır.
9
+ *
10
+ * Sözdizimi:
11
+ * {{ad}} değişken (boşluk tolere, Unicode ad)
12
+ * {{#if ad}} ... {{else}} ... {{/if}} ad doluysa ilk dal, değilse else dalı
13
+ * {{#unless ad}} ... {{/unless}} ad boş/yoksa
14
+ * Doluluk: değer verilmiş, kırpınca boş değil ve "false" / "0" değil (büyük/küçük harf farksız).
15
+ * Koşulda verilmeyen değişken = yanlış (sessizce); filler arayüzü bu adı yine de sorar.
16
+ * Sınırlar: iç içe en çok MAX_DEPTH. Dengesiz / fazla derin / sahipsiz {{else}} {{/if}} durumunda
17
+ * koşul etiketleri yorumlanmaz, metin olduğu gibi kalır (değişkenler yine doldurulur).
18
+ */
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.MAX_DEPTH = void 0;
21
+ exports.extractVariables = extractVariables;
22
+ exports.fillVariables = fillVariables;
23
+ exports.hasVariables = hasVariables;
24
+ exports.MAX_DEPTH = 5;
25
+ const NAME = '[\\p{L}\\p{N}_.-]+';
26
+ // 1: if|unless (açılış) 2: açılış adı 3: else 4: kapanış tipi 5: düz değişken adı
27
+ const TAG = new RegExp(`\\{\\{\\s*(?:#(if|unless)\\s+(${NAME})|(else)|\\/(if|unless)|(${NAME}))\\s*\\}\\}`, 'gu');
28
+ function tokenize(text) {
29
+ const tokens = [];
30
+ let cursor = 0;
31
+ for (const m of text.matchAll(TAG)) {
32
+ const start = m.index ?? 0;
33
+ const end = start + m[0].length;
34
+ const isControl = m[5] === undefined;
35
+ let from = start;
36
+ let to = end;
37
+ if (isControl) {
38
+ // Etiket kendi satırındaysa satırı (boşluk + satır sonu) tümden tüket.
39
+ // Yalnız boşluk karakterleri taranır (satır başına/sonuna kadar), O(1) amortize.
40
+ let ls = start;
41
+ while (ls > 0 && text[ls - 1] !== '\n' && /[ \t\r]/.test(text[ls - 1]))
42
+ ls--;
43
+ let le = end;
44
+ while (le < text.length && text[le] !== '\n' && /[ \t\r]/.test(text[le]))
45
+ le++;
46
+ const startsLine = ls === 0 || text[ls - 1] === '\n';
47
+ const endsLine = le === text.length || text[le] === '\n';
48
+ if (startsLine && endsLine) {
49
+ from = Math.max(ls, cursor);
50
+ to = Math.min(le + 1, text.length);
51
+ }
52
+ }
53
+ if (from > cursor)
54
+ tokens.push({ t: 'text', v: text.slice(cursor, from) });
55
+ cursor = to;
56
+ if (m[1])
57
+ tokens.push({ t: 'open', kind: m[1], name: m[2], raw: m[0] });
58
+ else if (m[3])
59
+ tokens.push({ t: 'else', raw: m[0] });
60
+ else if (m[4])
61
+ tokens.push({ t: 'close', kind: m[4], raw: m[0] });
62
+ else
63
+ tokens.push({ t: 'var', name: m[5], raw: m[0] });
64
+ }
65
+ if (cursor < text.length)
66
+ tokens.push({ t: 'text', v: text.slice(cursor) });
67
+ return tokens;
68
+ }
69
+ /** Dengeli ağaç kurar; hata olursa null (çağıran düz moda düşer). */
70
+ function parse(tokens) {
71
+ const root = [];
72
+ const stack = [];
73
+ const current = () => {
74
+ const top = stack[stack.length - 1];
75
+ return top ? (top.inElse ? top.node.no : top.node.yes) : root;
76
+ };
77
+ for (const tok of tokens) {
78
+ if (tok.t === 'text')
79
+ current().push(tok);
80
+ else if (tok.t === 'var')
81
+ current().push(tok);
82
+ else if (tok.t === 'open') {
83
+ if (stack.length >= exports.MAX_DEPTH)
84
+ return null;
85
+ const node = {
86
+ t: 'cond',
87
+ negate: tok.kind === 'unless',
88
+ name: tok.name,
89
+ yes: [],
90
+ no: [],
91
+ };
92
+ current().push(node);
93
+ stack.push({ kind: tok.kind, node, inElse: false });
94
+ }
95
+ else if (tok.t === 'else') {
96
+ const top = stack[stack.length - 1];
97
+ if (!top || top.inElse)
98
+ return null;
99
+ top.inElse = true;
100
+ }
101
+ else {
102
+ const top = stack.pop();
103
+ if (!top || top.kind !== tok.kind)
104
+ return null;
105
+ }
106
+ }
107
+ return stack.length === 0 ? root : null;
108
+ }
109
+ /** Düz mod: koşul etiketleri metin kalır, yalnız değişkenler var sayılır. */
110
+ function flatten(tokens) {
111
+ return tokens.map((tok) => {
112
+ if (tok.t === 'var')
113
+ return tok;
114
+ if (tok.t === 'text')
115
+ return tok;
116
+ return { t: 'text', v: tok.raw };
117
+ });
118
+ }
119
+ function isTruthy(values, name) {
120
+ if (!Object.prototype.hasOwnProperty.call(values, name))
121
+ return false;
122
+ const v = values[name];
123
+ if (typeof v !== 'string')
124
+ return false;
125
+ const s = v.trim().toLowerCase();
126
+ return s !== '' && s !== 'false' && s !== '0';
127
+ }
128
+ function build(text) {
129
+ const tokens = tokenize(text);
130
+ const tree = parse(tokens);
131
+ return tree ? { tree, balanced: true } : { tree: flatten(tokens), balanced: false };
132
+ }
133
+ function render(nodes, values) {
134
+ let out = '';
135
+ for (const n of nodes) {
136
+ if (n.t === 'text')
137
+ out += n.v;
138
+ else if (n.t === 'var') {
139
+ // Yalnız kendi anahtarları: {{constructor}} gibi adlar prototipten bir şey çekmesin.
140
+ const value = Object.prototype.hasOwnProperty.call(values, n.name)
141
+ ? values[n.name]
142
+ : undefined;
143
+ out += typeof value === 'string' && value !== '' ? value : n.raw;
144
+ }
145
+ else {
146
+ const on = isTruthy(values, n.name) !== n.negate;
147
+ out += render(on ? n.yes : n.no, values);
148
+ }
149
+ }
150
+ return out;
151
+ }
152
+ function collect(nodes, seen, result) {
153
+ const add = (name) => {
154
+ if (!seen.has(name)) {
155
+ seen.add(name);
156
+ result.push(name);
157
+ }
158
+ };
159
+ for (const n of nodes) {
160
+ if (n.t === 'var')
161
+ add(n.name);
162
+ else if (n.t === 'cond') {
163
+ add(n.name);
164
+ collect(n.yes, seen, result);
165
+ collect(n.no, seen, result);
166
+ }
167
+ }
168
+ }
169
+ /** Metindeki benzersiz değişken adları (koşul adları dahil), ilk görülme sırasıyla. */
170
+ function extractVariables(text) {
171
+ if (!text)
172
+ return [];
173
+ const result = [];
174
+ collect(build(text).tree, new Set(), result);
175
+ return result;
176
+ }
177
+ /**
178
+ * Koşulları çözer, `{{ad}}` yer tutucularını doldurur. Bulunmayan/boş değişken
179
+ * olduğu gibi kalır (sessizce silinmez); koşulda yanlış sayılır.
180
+ */
181
+ function fillVariables(text, values) {
182
+ if (!text)
183
+ return '';
184
+ return render(build(text).tree, values);
185
+ }
186
+ /** Metinde en az bir değişken ya da koşul var mı. */
187
+ function hasVariables(text) {
188
+ return extractVariables(text).length > 0;
189
+ }
@@ -1,44 +1,11 @@
1
1
  "use strict";
2
- /**
3
- * Prompt değişkenleri (`{{ad}}`) — CLI yerel kopyası.
4
- *
5
- * Web tarafındaki `src/lib/prompt-variables.ts` ile BİREBİR aynı mantık. CLI
6
- * ayrı bir npm paketi olduğu için web'den import edemiyor; bu yüzden küçük,
7
- * bağımlılıksız util burada tekrarlanıyor. Birini değiştirirken diğerini de
8
- * güncelle (ya da ileride shared/ altına taşıyıp sync-types ile senkronla).
9
- *
10
- * Syntax: `{{ad}}`, içeride whitespace tolere, Unicode adlar (Türkçe dahil).
11
- */
12
2
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.extractVariables = extractVariables;
14
- exports.fillVariables = fillVariables;
15
- const VARIABLE_PATTERN = /\{\{\s*([\p{L}\p{N}_.-]+)\s*\}\}/gu;
16
- /** Metindeki benzersiz değişken adları, ilk görülme sırasıyla. */
17
- function extractVariables(text) {
18
- if (!text)
19
- return [];
20
- const seen = new Set();
21
- const result = [];
22
- for (const match of text.matchAll(VARIABLE_PATTERN)) {
23
- const name = match[1];
24
- if (!seen.has(name)) {
25
- seen.add(name);
26
- result.push(name);
27
- }
28
- }
29
- return result;
30
- }
3
+ exports.hasVariables = exports.fillVariables = exports.extractVariables = void 0;
31
4
  /**
32
- * `{{ad}}` yer tutucularını doldurur. Bulunmayan/boş değer çıktıda `{{ad}}`
33
- * olarak kalır (sessizce silinmez).
5
+ * Prompt değişkenleri + koşullar — motor `promptTemplate.ts` içinde (web ile aynı dosya,
6
+ * kayma `src/lib/prompt-template-drift.test.ts` ile yakalanır).
34
7
  */
35
- function fillVariables(text, values) {
36
- if (!text)
37
- return '';
38
- return text.replace(VARIABLE_PATTERN, (whole, name) => {
39
- // Yalnız kendi anahtarları: {{constructor}} / {{toString}} gibi adlar
40
- // Object.prototype'tan fonksiyon çekip metne "function Object()…" basmasın.
41
- const value = Object.prototype.hasOwnProperty.call(values, name) ? values[name] : undefined;
42
- return typeof value === 'string' && value !== '' ? value : whole;
43
- });
44
- }
8
+ var promptTemplate_1 = require("./promptTemplate");
9
+ Object.defineProperty(exports, "extractVariables", { enumerable: true, get: function () { return promptTemplate_1.extractVariables; } });
10
+ Object.defineProperty(exports, "fillVariables", { enumerable: true, get: function () { return promptTemplate_1.fillVariables; } });
11
+ Object.defineProperty(exports, "hasVariables", { enumerable: true, get: function () { return promptTemplate_1.hasVariables; } });
package/dist/program.js CHANGED
@@ -28,6 +28,7 @@ const import_1 = require("./commands/import");
28
28
  const log_1 = require("./commands/log");
29
29
  const diff_1 = require("./commands/diff");
30
30
  const rollback_1 = require("./commands/rollback");
31
+ const tag_1 = require("./commands/tag");
31
32
  const suggest_1 = require("./commands/suggest");
32
33
  const config_1 = require("./commands/config");
33
34
  const repo_1 = require("./commands/repo");
@@ -71,13 +72,18 @@ function buildProgram() {
71
72
  .action(runWithErrorHandler(save_1.saveCommand));
72
73
  scope(program
73
74
  .command('get <name>')
74
- .description('Print a prompt raw to stdout; fill {{variables}} (agent/pipe friendly)')
75
+ .description('Print a prompt raw to stdout; fill {{variables}} and {{#if}} blocks (agent/pipe friendly)')
75
76
  .option('-v, --var <keyval>', 'Fill a variable — key=value (repeatable)', get_1.collectVar, {})
76
- .option('-c, --copy', 'Also copy the output to the clipboard'))
77
+ .option('-c, --copy', 'Also copy the output to the clipboard')
78
+ .option('-l, --label <name>', 'Read the version a deployment label points at (e.g. production)'))
77
79
  .addHelpText('after', '\nExample:\n ple get "code review" --var diff="$(git diff)" | claude')
78
80
  .action(runWithErrorHandler(get_1.getCommand));
79
81
  scope(program.command('show <name>').description('Show a prompt in the terminal')).action(runWithErrorHandler(show_1.showCommand));
80
- scope(program.command('copy <name>').description('Copy a prompt to the clipboard (by title or short id)')).action(runWithErrorHandler(copy_1.copyCommand));
82
+ scope(program
83
+ .command('copy <name>')
84
+ .description('Copy a prompt to the clipboard (by title or short id)')
85
+ .option('-v, --var <keyval>', 'Fill a variable / set an {{#if}} condition — key=value (repeatable)', get_1.collectVar, {})
86
+ .option('-l, --label <name>', 'Copy the version a deployment label points at (e.g. production)')).action(runWithErrorHandler(copy_1.copyCommand));
81
87
  scope(program
82
88
  .command('list')
83
89
  .description('List your prompts')
@@ -98,6 +104,12 @@ function buildProgram() {
98
104
  .command('diff <name> [a] [b]')
99
105
  .description('Diff two versions (default: previous ↔ current). Refs: 3, v3 or 1.0.2')
100
106
  .option('--no-color', 'Plain output (automatic when piped)')).action(runWithErrorHandler((name, a, b, opts) => (0, diff_1.diffCommand)(name, a, b, opts)));
107
+ scope(program
108
+ .command('tag <name> [version] [label]')
109
+ .description('Point a deployment label (production, staging…) at a version; every move is logged')
110
+ .option('--list', 'Show labels and recent moves')
111
+ .option('-r, --remove <label>', 'Remove a label')
112
+ .addHelpText('after', '\nExamples:\n ple tag "code review" 3 production\n ple tag "code review" --list\n ple get "code review" --label production')).action(runWithErrorHandler((name, version, label, opts) => (0, tag_1.tagCommand)(name, version, label, opts)));
101
113
  scope(program
102
114
  .command('rollback <name> <version>')
103
115
  .description('Restore an old version as a new one — nothing is deleted (signed out: local history)')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "promptlike",
3
- "version": "0.8.0",
3
+ "version": "0.9.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"