promptlike 0.9.0 → 0.10.1
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 +112 -0
- package/README.md +241 -27
- package/dist/commands/config.js +13 -0
- package/dist/commands/copy.js +10 -3
- package/dist/commands/get.js +11 -2
- package/dist/commands/import.js +30 -128
- package/dist/commands/importCheck.js +304 -0
- package/dist/commands/importGithub.js +171 -0
- package/dist/commands/list.js +83 -17
- package/dist/commands/local.js +31 -9
- package/dist/commands/login.js +6 -5
- package/dist/commands/save.js +1 -1
- package/dist/commands/search.js +73 -7
- package/dist/commands/show.js +11 -3
- package/dist/commands/suggest.js +100 -10
- package/dist/commands/sync.js +57 -13
- package/dist/index.js +7 -0
- package/dist/lib/errors.js +4 -0
- package/dist/lib/format.js +28 -0
- package/dist/lib/frontmatter.js +86 -4
- package/dist/lib/github.js +208 -0
- package/dist/lib/githubCache.js +118 -0
- package/dist/lib/githubHttp.js +197 -0
- package/dist/lib/githubImport.js +238 -0
- package/dist/lib/githubSelect.js +148 -0
- package/dist/lib/githubSnapshot.js +67 -0
- package/dist/lib/githubSpec.js +78 -0
- package/dist/lib/importOrigins.js +36 -0
- package/dist/lib/importShared.js +179 -0
- package/dist/lib/licenses.js +243 -0
- package/dist/lib/localStore.js +80 -2
- package/dist/lib/loopApi.js +63 -11
- package/dist/lib/promptResolver.js +22 -9
- package/dist/lib/promptSource.js +123 -0
- package/dist/lib/rank.js +30 -13
- package/dist/lib/settings.js +24 -3
- package/dist/lib/tagFilter.js +40 -0
- package/dist/lib/updateCheck.js +296 -0
- package/dist/lib/upstreamCheck.js +71 -0
- package/dist/program.js +26 -7
- package/package.json +1 -1
package/dist/lib/loopApi.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Loop Engineering API calls — variant generation + winner save
|
|
3
|
+
* Loop Engineering API calls — variant generation + winner save — and the two
|
|
4
|
+
* generic bearer helpers other commands reuse (`bearerGet`, `saveVersion`).
|
|
4
5
|
*
|
|
5
6
|
* Kept separate from `api-client.ts` on purpose: these endpoints are
|
|
6
7
|
* Pro-gated and have their own 403 semantics ("upgrade to Pro"), which we
|
|
@@ -9,8 +10,10 @@
|
|
|
9
10
|
* first, so the token is fresh).
|
|
10
11
|
*/
|
|
11
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.SAVE_TIMEOUT_MS = exports.VARIANTS_TIMEOUT_MS = void 0;
|
|
13
|
+
exports.VersionLimitError = exports.GET_TIMEOUT_MS = exports.SAVE_TIMEOUT_MS = exports.VARIANTS_TIMEOUT_MS = void 0;
|
|
14
|
+
exports.bearerGet = bearerGet;
|
|
13
15
|
exports.requestVariants = requestVariants;
|
|
16
|
+
exports.saveVersion = saveVersion;
|
|
14
17
|
exports.saveWinner = saveWinner;
|
|
15
18
|
const constants_1 = require("./constants");
|
|
16
19
|
const config_1 = require("./config");
|
|
@@ -20,6 +23,8 @@ const config_1 = require("./config");
|
|
|
20
23
|
*/
|
|
21
24
|
exports.VARIANTS_TIMEOUT_MS = 120000;
|
|
22
25
|
exports.SAVE_TIMEOUT_MS = 30000;
|
|
26
|
+
/** Hafif okumalar (api-client.ts READ_TIMEOUT_MS ile aynı). */
|
|
27
|
+
exports.GET_TIMEOUT_MS = 15000;
|
|
23
28
|
const NOT_LOGGED_IN = 'Not logged in. Run `ple login` first.';
|
|
24
29
|
const SESSION_EXPIRED = 'Session expired. Log in again: `ple login`';
|
|
25
30
|
/** The Pro upsell suffix — appended to every 403 from the loop endpoints. */
|
|
@@ -43,12 +48,15 @@ function timeoutError(timeoutMs) {
|
|
|
43
48
|
return new Error(`No response from ${constants_1.API_BASE_URL} within ${Math.round(timeoutMs / 1000)}s. ` +
|
|
44
49
|
'The server may still be working on it; wait a moment, then try again.');
|
|
45
50
|
}
|
|
51
|
+
const proForbidden = (serverError) => new Error(proMessage(serverError));
|
|
46
52
|
/**
|
|
47
|
-
* Minimal bearer
|
|
48
|
-
* of `api-client.ts` (network / 401 / 403 / 429 /
|
|
49
|
-
* refresh-retry machinery — `ensureAuthed()` has
|
|
53
|
+
* Minimal bearer request used by the loop calls and the generic helpers below.
|
|
54
|
+
* Mirrors the error mapping of `api-client.ts` (network / 401 / 403 / 429 /
|
|
55
|
+
* error body) without the refresh-retry machinery — `ensureAuthed()` has
|
|
56
|
+
* already refreshed the token. Redirects are never followed: the bearer token
|
|
57
|
+
* must not be replayed at a Location the server chose.
|
|
50
58
|
*/
|
|
51
|
-
async function
|
|
59
|
+
async function bearerRequest(method, path, body, timeoutMs, forbidden) {
|
|
52
60
|
const config = (0, config_1.readConfig)();
|
|
53
61
|
if (!config)
|
|
54
62
|
throw new Error(NOT_LOGGED_IN);
|
|
@@ -56,14 +64,15 @@ async function bearerPost(path, body, timeoutMs) {
|
|
|
56
64
|
let res;
|
|
57
65
|
try {
|
|
58
66
|
res = await fetch(constants_1.API_BASE_URL + path, {
|
|
59
|
-
method
|
|
67
|
+
method,
|
|
60
68
|
headers: {
|
|
61
|
-
'Content-Type': 'application/json',
|
|
69
|
+
...(method === 'POST' ? { 'Content-Type': 'application/json' } : {}),
|
|
62
70
|
Authorization: `Bearer ${config.access_token}`,
|
|
63
71
|
},
|
|
64
|
-
body: JSON.stringify(body),
|
|
72
|
+
body: method === 'POST' ? JSON.stringify(body) : undefined,
|
|
65
73
|
// Süre başlıkla sınırlı değil: gövde okuması da aynı sinyalle kesilir.
|
|
66
74
|
signal,
|
|
75
|
+
redirect: 'manual',
|
|
67
76
|
});
|
|
68
77
|
}
|
|
69
78
|
catch (err) {
|
|
@@ -71,6 +80,10 @@ async function bearerPost(path, body, timeoutMs) {
|
|
|
71
80
|
throw timeoutError(timeoutMs);
|
|
72
81
|
throw new Error(`Cannot reach ${constants_1.API_BASE_URL}. Check your connection. (${err instanceof Error ? err.message : String(err)})`);
|
|
73
82
|
}
|
|
83
|
+
if (res.status >= 300 && res.status < 400) {
|
|
84
|
+
throw new Error(`The server answered with a redirect (HTTP ${res.status}); the CLI does not follow redirects. ` +
|
|
85
|
+
`Check PROMPTLIKE_API_URL (currently ${constants_1.API_BASE_URL}).`);
|
|
86
|
+
}
|
|
74
87
|
if (res.status === 401)
|
|
75
88
|
throw new Error(SESSION_EXPIRED);
|
|
76
89
|
let parsed = {};
|
|
@@ -83,9 +96,9 @@ async function bearerPost(path, body, timeoutMs) {
|
|
|
83
96
|
throw timeoutError(timeoutMs);
|
|
84
97
|
// Non-JSON body — fall through to the generic messages below.
|
|
85
98
|
}
|
|
86
|
-
// Pro gate → 403; tükenen AI token bütçesi → 402 (ApiErrors.insufficientTokens).
|
|
99
|
+
// Pro gate / plan limit → 403 (endpoint-specific); tükenen AI token bütçesi → 402 (ApiErrors.insufficientTokens).
|
|
87
100
|
if (res.status === 403)
|
|
88
|
-
throw
|
|
101
|
+
throw forbidden(parsed.error, parsed);
|
|
89
102
|
if (res.status === 402) {
|
|
90
103
|
// Satış anı, hata anı değil: MicroBoost adıyla ve fiyatıyla anılır.
|
|
91
104
|
const base = parsed.error?.trim() || "You've used this month's AI tokens";
|
|
@@ -100,6 +113,15 @@ async function bearerPost(path, body, timeoutMs) {
|
|
|
100
113
|
}
|
|
101
114
|
return parsed;
|
|
102
115
|
}
|
|
116
|
+
const bearerPost = (path, body, timeoutMs) => bearerRequest('POST', path, body, timeoutMs, proForbidden);
|
|
117
|
+
/**
|
|
118
|
+
* GET an API path with the stored bearer token and parse the JSON body.
|
|
119
|
+
* Same error mapping and timeout rules as the loop calls (callers run
|
|
120
|
+
* `ensureAuthed()` first).
|
|
121
|
+
*/
|
|
122
|
+
function bearerGet(path, timeoutMs = exports.GET_TIMEOUT_MS) {
|
|
123
|
+
return bearerRequest('GET', path, undefined, timeoutMs, (serverError) => new Error(serverError?.trim() || 'Not allowed.'));
|
|
124
|
+
}
|
|
103
125
|
/**
|
|
104
126
|
* POST /api/prompts/{id}/variants — ask the server to generate 2-3 AI
|
|
105
127
|
* variants of the prompt's current version.
|
|
@@ -117,6 +139,35 @@ async function requestVariants(promptId, opts = {}) {
|
|
|
117
139
|
const res = await bearerPost(`/api/prompts/${promptId}/variants`, body, exports.VARIANTS_TIMEOUT_MS);
|
|
118
140
|
return { variants: res.variants ?? [], tokensUsed: res.tokensUsed ?? 0 };
|
|
119
141
|
}
|
|
142
|
+
/** The plan's per-prompt version limit (Free) was hit — 403 with an upgrade link. */
|
|
143
|
+
class VersionLimitError extends Error {
|
|
144
|
+
constructor(message) {
|
|
145
|
+
super(message);
|
|
146
|
+
this.name = 'VersionLimitError';
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
exports.VersionLimitError = VersionLimitError;
|
|
150
|
+
const versionForbidden = (serverError, body) => typeof body.upgradeUrl === 'string'
|
|
151
|
+
? new VersionLimitError(`${serverError?.trim() || 'Version limit reached on this plan.'} — upgrade at ${constants_1.API_BASE_URL}/pricing`)
|
|
152
|
+
: new Error(serverError?.trim() || 'You are not allowed to save a new version of this prompt.');
|
|
153
|
+
/**
|
|
154
|
+
* Add a new version to an existing prompt through the save endpoint (update
|
|
155
|
+
* path — no `isNew`). Nothing is overwritten and no label moves: the server
|
|
156
|
+
* appends the version and the prompt's labels keep pointing where they did.
|
|
157
|
+
* `description` also updates the prompt-level description; leave it out to
|
|
158
|
+
* keep it.
|
|
159
|
+
*/
|
|
160
|
+
async function saveVersion(promptId, parts, changelog, source = 'cli', extra = {}) {
|
|
161
|
+
return bearerRequest('POST', '/api/prompts', {
|
|
162
|
+
id: promptId,
|
|
163
|
+
roleText: parts.roleText,
|
|
164
|
+
descriptionText: parts.descriptionText,
|
|
165
|
+
contextText: parts.contextText,
|
|
166
|
+
changelog,
|
|
167
|
+
source,
|
|
168
|
+
...(extra.description !== undefined ? { description: extra.description } : {}),
|
|
169
|
+
}, exports.SAVE_TIMEOUT_MS, versionForbidden);
|
|
170
|
+
}
|
|
120
171
|
/**
|
|
121
172
|
* Save the winning variant as a new version of the prompt via the existing
|
|
122
173
|
* save endpoint (update path — no `isNew`). Section mapping: the variant's
|
|
@@ -124,6 +175,7 @@ async function requestVariants(promptId, opts = {}) {
|
|
|
124
175
|
* as role / description / context respectively.
|
|
125
176
|
*/
|
|
126
177
|
async function saveWinner(promptId, variant, changelog) {
|
|
178
|
+
// 403 stays the Pro-gate message here: loop callers never meet the version limit's wording.
|
|
127
179
|
return bearerPost('/api/prompts', {
|
|
128
180
|
id: promptId,
|
|
129
181
|
roleText: variant.role || '',
|
|
@@ -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
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
+
}
|
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
|
-
*
|
|
17
|
-
*
|
|
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
|
-
/**
|
|
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"),
|
package/dist/lib/settings.js
CHANGED
|
@@ -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
|
-
*
|
|
10
|
-
*
|
|
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
|
+
}
|