promptlike 0.8.0 → 0.10.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.
Files changed (44) hide show
  1. package/CHANGELOG.md +108 -0
  2. package/README.md +270 -28
  3. package/dist/commands/config.js +13 -0
  4. package/dist/commands/copy.js +22 -7
  5. package/dist/commands/get.js +17 -3
  6. package/dist/commands/import.js +30 -128
  7. package/dist/commands/importCheck.js +304 -0
  8. package/dist/commands/importGithub.js +171 -0
  9. package/dist/commands/list.js +83 -17
  10. package/dist/commands/local.js +35 -12
  11. package/dist/commands/login.js +6 -5
  12. package/dist/commands/search.js +73 -7
  13. package/dist/commands/show.js +11 -3
  14. package/dist/commands/sync.js +57 -13
  15. package/dist/commands/tag.js +86 -0
  16. package/dist/help.js +1 -1
  17. package/dist/index.js +7 -0
  18. package/dist/lib/api-client.js +39 -0
  19. package/dist/lib/errors.js +4 -0
  20. package/dist/lib/format.js +28 -0
  21. package/dist/lib/frontmatter.js +86 -4
  22. package/dist/lib/github.js +208 -0
  23. package/dist/lib/githubCache.js +118 -0
  24. package/dist/lib/githubHttp.js +197 -0
  25. package/dist/lib/githubImport.js +238 -0
  26. package/dist/lib/githubSelect.js +148 -0
  27. package/dist/lib/githubSnapshot.js +67 -0
  28. package/dist/lib/githubSpec.js +78 -0
  29. package/dist/lib/importOrigins.js +36 -0
  30. package/dist/lib/importShared.js +179 -0
  31. package/dist/lib/licenses.js +243 -0
  32. package/dist/lib/localStore.js +52 -10
  33. package/dist/lib/loopApi.js +63 -11
  34. package/dist/lib/promptResolver.js +22 -9
  35. package/dist/lib/promptSource.js +123 -0
  36. package/dist/lib/promptTemplate.js +189 -0
  37. package/dist/lib/promptVariables.js +7 -40
  38. package/dist/lib/rank.js +30 -13
  39. package/dist/lib/settings.js +24 -3
  40. package/dist/lib/tagFilter.js +40 -0
  41. package/dist/lib/updateCheck.js +296 -0
  42. package/dist/lib/upstreamCheck.js +71 -0
  43. package/dist/program.js +41 -10
  44. package/package.json +1 -1
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolveProjectId = resolveProjectId;
4
4
  exports.resolvePromptByName = resolvePromptByName;
5
+ exports.lookupPromptByName = lookupPromptByName;
5
6
  exports.fetchPromptContent = fetchPromptContent;
6
7
  const format_1 = require("./format");
7
8
  const api_client_1 = require("./api-client");
@@ -56,6 +57,19 @@ async function resolveProjectId(value) {
56
57
  * Throws on auth/network errors (the command wrapper catches them).
57
58
  */
58
59
  async function resolvePromptByName(name, scope = {}) {
60
+ const result = await lookupPromptByName(name, scope);
61
+ if (result.kind === 'found')
62
+ return result.prompt;
63
+ if (result.kind === 'not_found')
64
+ console.error(format_1.c.error(result.message));
65
+ return null;
66
+ }
67
+ /**
68
+ * Same lookup as {@link resolvePromptByName}, except that "no match at all" is returned
69
+ * instead of printed. `get` / `show` / `copy` use it so a signed-in user's prompt that only
70
+ * lives on this machine is not announced as "not found" before the local store is tried.
71
+ */
72
+ async function lookupPromptByName(name, scope = {}) {
59
73
  const trimmed = name.trim();
60
74
  if (!trimmed) {
61
75
  throw new Error('Cannot resolve an empty name.');
@@ -67,9 +81,9 @@ async function resolvePromptByName(name, scope = {}) {
67
81
  if (found) {
68
82
  if (projectId && found.project_id && found.project_id !== projectId) {
69
83
  console.error(format_1.c.error(`Prompt '${(0, format_1.shortId)(found.id)}' is not in the selected repo.`));
70
- return null;
84
+ return { kind: 'reported' };
71
85
  }
72
- return found;
86
+ return { kind: 'found', prompt: found };
73
87
  }
74
88
  // Not found by id — fall through to a title search.
75
89
  }
@@ -77,10 +91,10 @@ async function resolvePromptByName(name, scope = {}) {
77
91
  if (!UUID_RE.test(trimmed) && SHORT_ID_RE.test(trimmed)) {
78
92
  const matches = await findByShortId(trimmed, projectId);
79
93
  if (matches.length === 1)
80
- return matches[0];
94
+ return { kind: 'found', prompt: matches[0] };
81
95
  if (matches.length > 1) {
82
96
  printAmbiguous(trimmed, matches);
83
- return null;
97
+ return { kind: 'reported' };
84
98
  }
85
99
  // No id match — fall through to a title search.
86
100
  }
@@ -91,17 +105,16 @@ async function resolvePromptByName(name, scope = {}) {
91
105
  const pool = titleMatches.length > 0 ? titleMatches : results;
92
106
  if (pool.length === 0) {
93
107
  const where = projectId ? ' in the selected repo' : '';
94
- console.error(format_1.c.error(`No prompt matched '${trimmed}'${where}.`));
95
- return null;
108
+ return { kind: 'not_found', message: `No prompt matched '${trimmed}'${where}.` };
96
109
  }
97
110
  if (pool.length === 1)
98
- return pool[0];
111
+ return { kind: 'found', prompt: pool[0] };
99
112
  // Disambiguate on an exact (case-insensitive) title match if unique.
100
113
  const exact = pool.filter((p) => p.title.toLowerCase() === lower);
101
114
  if (exact.length === 1)
102
- return exact[0];
115
+ return { kind: 'found', prompt: exact[0] };
103
116
  printAmbiguous(trimmed, pool);
104
- return null;
117
+ return { kind: 'reported' };
105
118
  }
106
119
  /**
107
120
  * Walks GET /api/prompts page by page (updated_at desc, stable id tie-break) and returns the
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ /**
3
+ * Where does a prompt live: the account, this machine, or both?
4
+ *
5
+ * Signed in, the read commands used to look at the account only, so a prompt saved
6
+ * while signed out (or imported) was invisible until `ple sync` — the single hint
7
+ * came at `ple login`. This module is the bridge, and it stays one-directional and
8
+ * honest about it:
9
+ * - `findPrompt` get / show / copy: the account first; when it has NO match, the local
10
+ * store, with a one-line stderr note that says it is local.
11
+ * - `accountTitleSet` the titles the account is known to have, from local data only (the
12
+ * suggestion cache + the rows a command just fetched) — no extra request.
13
+ * - `localOnly` local prompts whose titles are not in that set (`list`, `search`).
14
+ *
15
+ * Nothing here uploads or changes anything.
16
+ */
17
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ var desc = Object.getOwnPropertyDescriptor(m, k);
20
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
21
+ desc = { enumerable: true, get: function() { return m[k]; } };
22
+ }
23
+ Object.defineProperty(o, k2, desc);
24
+ }) : (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ o[k2] = m[k];
27
+ }));
28
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
29
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
30
+ }) : function(o, v) {
31
+ o["default"] = v;
32
+ });
33
+ var __importStar = (this && this.__importStar) || (function () {
34
+ var ownKeys = function(o) {
35
+ ownKeys = Object.getOwnPropertyNames || function (o) {
36
+ var ar = [];
37
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
38
+ return ar;
39
+ };
40
+ return ownKeys(o);
41
+ };
42
+ return function (mod) {
43
+ if (mod && mod.__esModule) return mod;
44
+ var result = {};
45
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
46
+ __setModuleDefault(result, mod);
47
+ return result;
48
+ };
49
+ })();
50
+ Object.defineProperty(exports, "__esModule", { value: true });
51
+ exports.normalizeTitle = normalizeTitle;
52
+ exports.findPrompt = findPrompt;
53
+ exports.accountTitleSet = accountTitleSet;
54
+ exports.localOnly = localOnly;
55
+ const config_1 = require("./config");
56
+ const format_1 = require("./format");
57
+ const libraryCache_1 = require("./libraryCache");
58
+ const store = __importStar(require("./localStore"));
59
+ const promptResolver_1 = require("./promptResolver");
60
+ /** Title as people compare it: Unicode-compatible, trimmed, single spaces, case-insensitive. */
61
+ function normalizeTitle(title) {
62
+ return title.normalize('NFKC').trim().replace(/\s+/g, ' ').toLowerCase();
63
+ }
64
+ function localOnlyNote(p) {
65
+ return `Note: '${(0, format_1.truncate)((0, format_1.safeText)(p.title), 60)}' is only on this machine, not in your account — 'ple sync' uploads it.`;
66
+ }
67
+ /**
68
+ * Signed-in lookup for `get` / `show` / `copy`.
69
+ *
70
+ * The account always wins. Only when it has no match at all (an ambiguous match is NOT "no
71
+ * match" — that is reported as before) and the request is not scoped to a repo or a label does
72
+ * the local store get a turn. A network or auth failure is never answered from disk: a stale
73
+ * local copy must not stand in for the account's version.
74
+ *
75
+ * Returns null when the caller should stop; the reason is already printed.
76
+ */
77
+ async function findPrompt(name, opts = {}) {
78
+ const lookup = await (0, promptResolver_1.lookupPromptByName)(name, { projectId: opts.projectId });
79
+ if (lookup.kind === 'found')
80
+ return { source: 'account', prompt: lookup.prompt };
81
+ if (lookup.kind === 'reported')
82
+ return null;
83
+ if (!opts.projectId && !opts.label) {
84
+ const hit = store.resolve(name);
85
+ if (hit && 'prompt' in hit) {
86
+ console.error(format_1.c.muted(localOnlyNote(hit.prompt)));
87
+ return { source: 'local', prompt: hit.prompt };
88
+ }
89
+ if (hit) {
90
+ console.error(format_1.c.error(lookup.message));
91
+ console.error(format_1.c.error(`'${(0, format_1.truncate)((0, format_1.safeText)(name.trim()), 60)}' matches ${hit.candidates.length} prompts that are only on this machine:`));
92
+ for (const p of hit.candidates) {
93
+ console.error(format_1.c.muted(` ${(0, format_1.truncate)((0, format_1.safeText)(p.slug), 40)} ${(0, format_1.truncate)((0, format_1.safeText)(p.title), 60)}`));
94
+ }
95
+ console.error(format_1.c.muted('Re-run with the exact name on the left.'));
96
+ return null;
97
+ }
98
+ }
99
+ console.error(format_1.c.error(lookup.message));
100
+ return null;
101
+ }
102
+ /**
103
+ * Titles of the account's prompts, from local data only (no request): the suggestion cache
104
+ * (the whole library, up to 500 prompts — `ple list` / `sync` / `suggest` keep it fresh) plus
105
+ * `fetched`, the rows the calling command just got. The union matters right after `ple sync`,
106
+ * when the cache is still the snapshot from before the upload.
107
+ *
108
+ * `fetchedIsLibrary`: the rows are the whole library (an unfiltered, uncut `ple list`), which
109
+ * makes the set complete even without a cache.
110
+ */
111
+ function accountTitleSet(fetched, fetchedIsLibrary) {
112
+ const titles = new Set(fetched.map((p) => normalizeTitle(p.title)));
113
+ const config = (0, config_1.readConfig)();
114
+ const cache = config ? (0, libraryCache_1.readCache)(config.user_id) : null;
115
+ if (cache)
116
+ for (const entry of cache.entries)
117
+ titles.add(normalizeTitle(entry.title));
118
+ return { titles, complete: cache !== null || fetchedIsLibrary };
119
+ }
120
+ /** Local prompts `ple sync` would upload (non-empty body) whose titles are not in `known`. */
121
+ function localOnly(known, candidates = store.list()) {
122
+ return candidates.filter((p) => p.body.trim() && !known.has(normalizeTitle(p.title)));
123
+ }
@@ -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/lib/rank.js CHANGED
@@ -13,38 +13,55 @@
13
13
  *
14
14
  * Noise gate (a wrong nudge costs more than a missed one): a prompt qualifies
15
15
  * only with a title or tag hit, or with at least two distinct terms matched.
16
- * Tokenisation and stop words match the server's `src/lib/suggest.ts` so the
17
- * CLI hook and MCP `suggest_prompts` agree on what a "term" is.
16
+ * Case, Turkish letters and accents are folded away on both sides ("kök neden" =
17
+ * "kok neden", "İngilizce" = "ingilizce"). Folding, stop words and tokenisation are
18
+ * the SAME code as the server's `src/lib/suggest.ts` (MCP `suggest_prompts`): the
19
+ * block between the fold-text markers below is kept byte-identical, and a test in
20
+ * src/lib/suggest.test.ts fails when the two copies drift.
18
21
  */
19
22
  Object.defineProperty(exports, "__esModule", { value: true });
20
23
  exports.MIN_SCORE = exports.BODY_HEAD = exports.MAX_TERMS = void 0;
24
+ exports.foldText = foldText;
21
25
  exports.tokenize = tokenize;
22
26
  exports.taskTerms = taskTerms;
23
27
  exports.rankLibrary = rankLibrary;
28
+ // <fold-text:begin> — copy of the same block in src/lib/suggest.ts (byte-identical; src/lib/suggest.test.ts locks it)
29
+ /**
30
+ * Case-, accent- and Turkish-insensitive form of a text: lower case, NFKD, combining marks
31
+ * (U+0300–U+036F) dropped, then dotless ı → i. ç ğ ı İ ö ş ü â î û and other Latin accents
32
+ * all fold to their base letter. Applied to the task terms AND to every field.
33
+ */
34
+ function foldText(input) {
35
+ return input
36
+ .toLocaleLowerCase('en-US')
37
+ .normalize('NFKD')
38
+ .replace(/[\u0300-\u036f]/g, '')
39
+ .normalize('NFC') // put non-Latin scripts (kana + dakuten, …) back together, as NFKC did
40
+ .replace(/ı/g, 'i');
41
+ }
24
42
  const STOPWORDS = new Set([
25
43
  'the', 'and', 'for', 'with', 'this', 'that', 'from', 'into', 'your', 'you', 'are', 'can', 'please',
26
44
  'make', 'let', 'use', 'using', 'want', 'need', 'how', 'what', 'why', 'when', 'will', 'should', 'would',
27
45
  'bir', 'bu', 've', 'ile', 'için', 'icin', 'şu', 'su', 'gibi', 'daha', 'çok', 'cok', 'olan', 'yap', 'lütfen', 'lutfen',
28
- ]);
46
+ ].map(foldText));
29
47
  exports.MAX_TERMS = 12;
30
- /** Body characters considered — the head of a prompt says what it is for. */
31
- exports.BODY_HEAD = 600;
32
- /** Minimum score to be suggested at all. */
33
- exports.MIN_SCORE = 2;
34
- const WEIGHTS = { title: 3, tag: 2, description: 1, body: 0.5 };
35
- /** Split text into lower-case word tokens (letters/digits, any script). */
48
+ /** Split text into folded word tokens (letters/digits, any script). */
36
49
  function tokenize(text) {
37
- return text
38
- .toLocaleLowerCase('en-US')
39
- .normalize('NFKC')
50
+ return foldText(text)
40
51
  .split(/[^\p{L}\p{N}]+/u)
41
52
  .filter(Boolean);
42
53
  }
43
- /** Task text → distinct search terms (≥3 chars, no stop words, max 12). */
54
+ /** Task text → distinct, folded search terms (≥3 chars, no stop words, max 12). */
44
55
  function taskTerms(task) {
45
56
  const words = tokenize(task).filter((w) => w.length >= 3 && !STOPWORDS.has(w));
46
57
  return [...new Set(words)].slice(0, exports.MAX_TERMS);
47
58
  }
59
+ // <fold-text:end>
60
+ /** Body characters considered — the head of a prompt says what it is for. */
61
+ exports.BODY_HEAD = 600;
62
+ /** Minimum score to be suggested at all. */
63
+ exports.MIN_SCORE = 2;
64
+ const WEIGHTS = { title: 3, tag: 2, description: 1, body: 0.5 };
48
65
  /**
49
66
  * A term hits a field token when one is a prefix of the other and the
50
67
  * shorter side has ≥4 chars ("review" ~ "reviews", "refactor" ~ "refactoring"),
@@ -6,8 +6,9 @@
6
6
  * rewritten on every token refresh and deleted on logout, which would silently
7
7
  * reset a preference the user set once.
8
8
  *
9
- * Today there is one key: `suggest` (on/off) — the Claude Code hook and
10
- * `ple suggest --hook` stay silent when it is off.
9
+ * Two keys, both on/off: `suggest` — the Claude Code hook and `ple suggest --hook`
10
+ * stay silent when it is off; `update-check` — the once-a-day "new version" notice
11
+ * (see updateCheck.ts) is never shown and never fetched when it is off.
11
12
  */
12
13
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
13
14
  if (k2 === undefined) k2 = k;
@@ -49,11 +50,12 @@ exports.readSettings = readSettings;
49
50
  exports.writeSettings = writeSettings;
50
51
  exports.parseOnOff = parseOnOff;
51
52
  exports.suggestEnabled = suggestEnabled;
53
+ exports.updateCheckEnabled = updateCheckEnabled;
52
54
  const fs = __importStar(require("fs"));
53
55
  const os = __importStar(require("os"));
54
56
  const path = __importStar(require("path"));
55
57
  const fsSafe_1 = require("./fsSafe");
56
- exports.SETTING_KEYS = ['suggest'];
58
+ exports.SETTING_KEYS = ['suggest', 'update-check'];
57
59
  /** Config dir (same as the session file). `PROMPTLIKE_CONFIG_DIR` overrides it for tests. */
58
60
  function configDir() {
59
61
  const override = process.env.PROMPTLIKE_CONFIG_DIR;
@@ -70,6 +72,9 @@ function readSettings() {
70
72
  const out = {};
71
73
  if (raw.suggest === 'on' || raw.suggest === 'off')
72
74
  out.suggest = raw.suggest;
75
+ const check = raw['update-check'];
76
+ if (check === 'on' || check === 'off')
77
+ out['update-check'] = check;
73
78
  return out;
74
79
  }
75
80
  catch {
@@ -103,3 +108,19 @@ function suggestEnabled(env = process.env, settings = readSettings()) {
103
108
  return false;
104
109
  return settings.suggest !== 'off';
105
110
  }
111
+ /**
112
+ * The update notice is on unless switched off in any of four places: `PLE_UPDATE_CHECK=off`,
113
+ * `NO_UPDATE_NOTIFIER` (the common opt-out for CLI notifiers; any value, even empty), a `CI`
114
+ * environment (a value other than empty, `false` or `0`), or `ple config set update-check off`.
115
+ */
116
+ function updateCheckEnabled(env = process.env, settings = readSettings()) {
117
+ const envValue = env.PLE_UPDATE_CHECK?.trim().toLowerCase();
118
+ if (envValue && OFF_VALUES.has(envValue))
119
+ return false;
120
+ if (env.NO_UPDATE_NOTIFIER !== undefined)
121
+ return false;
122
+ const ci = env.CI?.trim().toLowerCase();
123
+ if (ci && ci !== 'false' && ci !== '0')
124
+ return false;
125
+ return settings['update-check'] !== 'off';
126
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ /**
3
+ * Multi-tag filtering for `ple list --tag a --tag b` ("all must match").
4
+ *
5
+ * The server filters by ONE tag (`GET /api/prompts?tag=`), so the account list asks for the first
6
+ * tag and checks the rest here. Tag names are stored trimmed and with their case kept (nothing
7
+ * lower-cases them on save), and the server matches them exactly — the account check is exact
8
+ * too, so the first tag and the others follow one rule and the order of the flags does not matter.
9
+ * The local store has always matched tags ignoring case; that stays.
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.parseTagFilter = parseTagFilter;
13
+ exports.hasAllTags = hasAllTags;
14
+ exports.hasAllLocalTags = hasAllLocalTags;
15
+ exports.describeTags = describeTags;
16
+ /** Requested tags: trimmed, empty ones dropped, exact duplicates removed. Accepts one string or a list. */
17
+ function parseTagFilter(input) {
18
+ const list = input === undefined ? [] : typeof input === 'string' ? [input] : input;
19
+ const out = [];
20
+ for (const raw of list) {
21
+ const name = raw.trim();
22
+ if (name && !out.includes(name))
23
+ out.push(name);
24
+ }
25
+ return out;
26
+ }
27
+ /** Account prompt: does it carry every requested tag (exact, as stored)? */
28
+ function hasAllTags(tags, wanted) {
29
+ const have = new Set((tags ?? []).map((t) => t.name));
30
+ return wanted.every((name) => have.has(name));
31
+ }
32
+ /** Local prompt: does it carry every requested tag, ignoring case? */
33
+ function hasAllLocalTags(tags, wanted) {
34
+ const have = new Set(tags.map((t) => t.toLowerCase()));
35
+ return wanted.every((name) => have.has(name.toLowerCase()));
36
+ }
37
+ /** "tag 'a'" / "tags 'a' + 'b'" — for messages. */
38
+ function describeTags(wanted) {
39
+ return `${wanted.length === 1 ? 'tag' : 'tags'} ${wanted.map((t) => `'${t}'`).join(' + ')}`;
40
+ }