promptlike-mcp 0.5.0 → 0.6.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 +41 -0
- package/README.md +15 -3
- package/dist/lib/api-client.js +18 -0
- package/dist/lib/config.js +48 -28
- package/dist/lib/constants.js +48 -2
- package/dist/lib/feedback.js +225 -0
- package/dist/lib/fsSafe.js +160 -0
- package/dist/lib/writeGuard.js +123 -31
- package/dist/lib/writeTools.js +99 -23
- package/dist/server.js +72 -9
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,46 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.6.0 — 2026-10-30
|
|
4
|
+
|
|
5
|
+
- **`update_prompt` can now change a prompt's description and tags** (before, only its text). New optional
|
|
6
|
+
arguments: `description` (overwrites; `""` clears it) and `tags` (add-only: adds the tags the prompt lacks, never removes one; `[]` changes nothing);
|
|
7
|
+
`content` is now optional too. Add-only is kept this way: a field you do not pass is not touched, a field you
|
|
8
|
+
pass overwrites, no prompt or version is deleted. Only `content` creates a **version** (the old one is
|
|
9
|
+
kept; same text → none). The description and the tags are not part of a version, so a call that changes only
|
|
10
|
+
them opens no version; the answer returns `previous_description` so an overwrite can be restored.
|
|
11
|
+
Tags are add-only (decision of 30 Oct): missing ones are added; tags already on the prompt, and tags you do
|
|
12
|
+
not list, are left as they are, so the answer has no `tags_removed` and the client sends no DELETE. When some
|
|
13
|
+
existing tags were not listed the answer carries a `tags_note` saying so. Values that already match change nothing (`status: "unchanged"`);
|
|
14
|
+
`status` is `updated` (a version was added), `metadata_updated` or `unchanged`. A call with none of
|
|
15
|
+
`content`, `description`, `tags` is an error. The same length limits and the secret check as `save_prompt`
|
|
16
|
+
apply. If a step fails after another succeeded, the answer is an error that says what was applied.
|
|
17
|
+
- **New tool: `submit_feedback`** (the eighth). An agent calls it when a PromptLikeEngineer tool is missing,
|
|
18
|
+
broken, confusing or returned a wrong result, or when a saved prompt did not work: `message` (one short
|
|
19
|
+
factual sentence), optional `type` (`bug`, `missing`, `idea`, `prompt`; default `idea`), `prompt` (a title or
|
|
20
|
+
id, never its text) and `email`. It works without a session and ties the report to your account when you are
|
|
21
|
+
signed in. Sent: those fields, `source: "agent"`, the agent name (the MCP client's name, or `mcp-client`),
|
|
22
|
+
`client: "mcp"` and four short values (version, OS and CPU, Node version, tool name). A message that looks
|
|
23
|
+
like an API key or token is refused, as in `save_prompt`. A rate limit, a network problem or a server error
|
|
24
|
+
returns a tool error with `code`, `retryable` and, for a rate limit, `retry_after`; nothing is queued.
|
|
25
|
+
|
|
26
|
+
## 0.5.1 — 2026-10-25
|
|
27
|
+
|
|
28
|
+
- **Security:** `PROMPTLIKE_API_URL` must now use https (plain http is accepted only for
|
|
29
|
+
`localhost`, `127.0.0.1` and `[::1]`) and may not contain credentials, a query or a fragment. An
|
|
30
|
+
unusable value is reported as a tool error before any request is made, so the login token is never
|
|
31
|
+
sent to it.
|
|
32
|
+
- **Security:** the API client no longer follows redirects. A 3xx answer (for example a 307/308 on the
|
|
33
|
+
session refresh) used to be replayed, refresh token included, at an address the server picked; it
|
|
34
|
+
now stops with a message that points at `PROMPTLIKE_API_URL`, and the saved login is kept.
|
|
35
|
+
- **Security:** the shared session file (`~/.config/promptlike/config.json`) is written atomically
|
|
36
|
+
(temp file, then rename) with mode 0600 in a 0700 folder; loose permissions on an existing file or
|
|
37
|
+
folder are tightened. A symbolic link at that path is never written through or read through (it
|
|
38
|
+
reads as "not logged in").
|
|
39
|
+
- **Security:** the secret check on `save_prompt` / `update_prompt` now also covers tags and the
|
|
40
|
+
changelog, ignores zero-width and other invisible characters, and recognises more key formats
|
|
41
|
+
(Supabase, npm, Stripe webhook, SendGrid, Vercel Blob, AWS secret key, bearer headers, URLs with an
|
|
42
|
+
embedded password). A key right after an underscore (`KEY_sk-...`) is no longer missed.
|
|
43
|
+
|
|
3
44
|
## 0.5.0 — 2026-10-19
|
|
4
45
|
|
|
5
46
|
- **New: `label` parameter** on `get_prompt` and `fill_variables` reads the version a deployment
|
package/README.md
CHANGED
|
@@ -52,16 +52,28 @@ Every prompt is also a resource, `promptlike://<repo>/<prompt>` (`text/markdown`
|
|
|
52
52
|
| `fill_variables` | Fetch + substitute `{{variables}}` (and `{{#if var}}…{{/if}}` blocks; optional `version`/`label`), returns ready-to-use text (unfilled ones reported in `missing_variables`). |
|
|
53
53
|
| `suggest_prompts` | Up to 3 prompts from your own library that fit a task (call once at the start of a non-trivial task). |
|
|
54
54
|
| `save_prompt` | **Write.** New prompt: `title`, `content`, optional `description`, `project` (repo; default: your most recent repo you can edit), `tags`. |
|
|
55
|
-
| `update_prompt` | **Write.**
|
|
55
|
+
| `update_prompt` | **Write.** Change an existing prompt (exact title or id). Pass any of: full new `content` → a **new version** (`changelog`, `bump` `patch`/`minor`/`major` go with it); `description` → overwrites the description; `tags` → replaces the tag list. A field you leave out is not touched; one you pass overwrites. |
|
|
56
|
+
| `submit_feedback` | Tell the maker that a tool is missing, broken, confusing or answered wrong, or that a saved prompt did not work: `message` (one short factual sentence), optional `type` (`bug`/`missing`/`idea`/`prompt`), `prompt` (title or id, never its text), `email`. Works without a session. Not a write to your library. |
|
|
56
57
|
|
|
57
58
|
### How writes behave
|
|
58
59
|
|
|
59
|
-
- **Add-only.** There is no delete tool; `update_prompt` keeps every earlier version (roll back on the web or with `ple rollback`).
|
|
60
|
-
-
|
|
60
|
+
- **Add-only.** There is no delete tool; `update_prompt` keeps every earlier version (roll back on the web or with `ple rollback`). No prompt and no version is ever deleted.
|
|
61
|
+
- **`update_prompt` touches only what you pass.** A field that is left out is not changed; a field that is passed overwrites (`description: ""` clears it). `content` is the only part that makes a **version**; the description and the tags are not part of a version, so changing only them opens none — and because the description is not versioned, the answer carries `previous_description` so an overwrite can be put back. **Tags are add-only:** `tags` adds the ones the prompt lacks; tags already on it, and tags you do not list, stay — `tags: []` changes nothing, and this server never sends a DELETE (remove a tag in the web app). Passing values that already match changes nothing; passing none of `content`, `description`, `tags` is an error.
|
|
62
|
+
- **Safe to retry.** Same title + content → "already saved"; content, description and tags equal to what the prompt has → "unchanged", no new version. A title that exists with different content is reported instead of duplicated.
|
|
61
63
|
- **Your account, your limits.** Writes use your `ple login` session and the same plan limits as the web; hitting one returns a plain message with the upgrade link and saves nothing. Viewer access to a shared repo cannot write.
|
|
62
64
|
- **No secrets.** Content that looks like an API key or token is refused — use a `{{variable}}`.
|
|
63
65
|
- **Exact names only for updates.** A fuzzy match is answered with "did you mean…", never written to.
|
|
64
66
|
|
|
67
|
+
### `submit_feedback`
|
|
68
|
+
|
|
69
|
+
The one tool that does not touch your library. The agent calls it when a PromptLikeEngineer tool is missing, broken,
|
|
70
|
+
confusing or returned a wrong result, or when a saved prompt did not work. What is sent: the type, the message, the
|
|
71
|
+
prompt title or id and email if given, `source: "agent"`, the agent name (your MCP client's name, or `mcp-client`),
|
|
72
|
+
`client: "mcp"` and four short values (server version, OS and CPU, Node version, the tool name). Never prompt bodies,
|
|
73
|
+
and a message that looks like an API key or token is refused. It works signed out; with a `ple login` session the
|
|
74
|
+
report is tied to your account. A rate limit, a network problem or a server error comes back as a tool error with
|
|
75
|
+
`code` and `retryable` (nothing is queued, nothing is thrown). The `ple feedback` command is the same thing from a terminal.
|
|
76
|
+
|
|
65
77
|
The server never spends your AI tokens (no improve), and it does not use MCP sampling.
|
|
66
78
|
|
|
67
79
|
## Notes
|
package/dist/lib/api-client.js
CHANGED
|
@@ -29,6 +29,7 @@ exports.recordPromptUse = recordPromptUse;
|
|
|
29
29
|
exports.createPrompt = createPrompt;
|
|
30
30
|
exports.savePromptVersion = savePromptVersion;
|
|
31
31
|
exports.addPromptTag = addPromptTag;
|
|
32
|
+
exports.updatePromptDescription = updatePromptDescription;
|
|
32
33
|
exports.suggestPrompts = suggestPrompts;
|
|
33
34
|
const constants_1 = require("./constants");
|
|
34
35
|
const config_1 = require("./config");
|
|
@@ -221,6 +222,9 @@ async function refreshSession() {
|
|
|
221
222
|
persist(data);
|
|
222
223
|
}
|
|
223
224
|
async function apiFetch(path, opts = {}) {
|
|
225
|
+
// An unusable PROMPTLIKE_API_URL is reported BEFORE a request (and a token) exists.
|
|
226
|
+
if (constants_1.API_BASE_URL_ERROR)
|
|
227
|
+
throw new Error(constants_1.API_BASE_URL_ERROR);
|
|
224
228
|
const { method = 'GET', body, query, auth = true } = opts;
|
|
225
229
|
const timeoutMs = opts.timeoutMs ?? (method === 'GET' ? exports.READ_TIMEOUT_MS : exports.WRITE_TIMEOUT_MS);
|
|
226
230
|
const signal = AbortSignal.timeout(timeoutMs);
|
|
@@ -239,6 +243,9 @@ async function apiFetch(path, opts = {}) {
|
|
|
239
243
|
body: body === undefined ? undefined : JSON.stringify(body),
|
|
240
244
|
// Süre başlıkla sınırlı değil: gövde okuması da aynı sinyalle kesilir.
|
|
241
245
|
signal,
|
|
246
|
+
// Never follow redirects automatically: a 307/308 would replay the POST body
|
|
247
|
+
// (the refresh_token on a session refresh) at a Location the server chose.
|
|
248
|
+
redirect: 'manual',
|
|
242
249
|
});
|
|
243
250
|
}
|
|
244
251
|
catch (err) {
|
|
@@ -246,6 +253,10 @@ async function apiFetch(path, opts = {}) {
|
|
|
246
253
|
throw new RequestTimeoutError(timeoutMs, method);
|
|
247
254
|
throw new NetworkError(err instanceof Error ? err.message : String(err));
|
|
248
255
|
}
|
|
256
|
+
if (res.status >= 300 && res.status < 400) {
|
|
257
|
+
throw new ApiError(`The server answered with a redirect (HTTP ${res.status}); this server does not follow redirects. ` +
|
|
258
|
+
`Check PROMPTLIKE_API_URL (currently ${constants_1.API_BASE_URL}).`, res.status);
|
|
259
|
+
}
|
|
249
260
|
if (res.status === 401 && auth) {
|
|
250
261
|
if (opts._retried)
|
|
251
262
|
throw new Error(SESSION_EXPIRED);
|
|
@@ -418,6 +429,13 @@ async function savePromptVersion(input) {
|
|
|
418
429
|
async function addPromptTag(promptId, tagName) {
|
|
419
430
|
await apiFetch(`/api/prompts/${promptId}/tags`, { method: 'POST', body: { tagName } });
|
|
420
431
|
}
|
|
432
|
+
/**
|
|
433
|
+
* Overwrite the prompt-level description (PATCH /api/prompts/{id}). The description is not part of a
|
|
434
|
+
* version: no version is created and nothing else about the prompt changes. `''` clears it.
|
|
435
|
+
*/
|
|
436
|
+
async function updatePromptDescription(promptId, description) {
|
|
437
|
+
await apiFetch(`/api/prompts/${promptId}`, { method: 'PATCH', body: { description } });
|
|
438
|
+
}
|
|
421
439
|
/** Best matches for a task from the user's OWN library (server-side full text). */
|
|
422
440
|
async function suggestPrompts(task, limit = 3) {
|
|
423
441
|
const res = await apiFetch('/api/prompts/suggest', {
|
package/dist/lib/config.js
CHANGED
|
@@ -41,48 +41,68 @@ exports.isTokenExpiringSoon = isTokenExpiringSoon;
|
|
|
41
41
|
const fs = __importStar(require("fs"));
|
|
42
42
|
const os = __importStar(require("os"));
|
|
43
43
|
const path = __importStar(require("path"));
|
|
44
|
-
const
|
|
45
|
-
|
|
44
|
+
const fsSafe_1 = require("./fsSafe");
|
|
45
|
+
/**
|
|
46
|
+
* Resolved lazily (not at import) so tests can point HOME at a temp dir.
|
|
47
|
+
* Same location as the CLI's default; the MCP server does not honor the CLI's
|
|
48
|
+
* test-only `PROMPTLIKE_CONFIG_DIR` override.
|
|
49
|
+
*/
|
|
50
|
+
function configDir() {
|
|
51
|
+
return path.join(os.homedir(), '.config', 'promptlike');
|
|
52
|
+
}
|
|
53
|
+
function configFile() {
|
|
54
|
+
return path.join(configDir(), 'config.json');
|
|
55
|
+
}
|
|
46
56
|
/** Config dosyasının tam yolu — debug çıktılarında göstermek için. */
|
|
47
57
|
function getConfigPath() {
|
|
48
|
-
return
|
|
58
|
+
return configFile();
|
|
49
59
|
}
|
|
50
|
-
/**
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
* çağırsın diye log'ı sessiz tutuyoruz.
|
|
54
|
-
*/
|
|
55
|
-
function readConfig() {
|
|
60
|
+
/** Parse + shape-check the session file. Anything unexpected → null (never throws). */
|
|
61
|
+
function parseConfig(raw) {
|
|
62
|
+
let parsed;
|
|
56
63
|
try {
|
|
57
|
-
|
|
58
|
-
return null;
|
|
59
|
-
const raw = fs.readFileSync(CONFIG_FILE, 'utf-8');
|
|
60
|
-
const parsed = JSON.parse(raw);
|
|
61
|
-
if (!parsed.access_token || !parsed.refresh_token)
|
|
62
|
-
return null;
|
|
63
|
-
return parsed;
|
|
64
|
+
parsed = JSON.parse(raw);
|
|
64
65
|
}
|
|
65
66
|
catch {
|
|
66
67
|
return null;
|
|
67
68
|
}
|
|
69
|
+
if (typeof parsed !== 'object' || parsed === null)
|
|
70
|
+
return null;
|
|
71
|
+
const o = parsed;
|
|
72
|
+
if (typeof o.access_token !== 'string' || !o.access_token)
|
|
73
|
+
return null;
|
|
74
|
+
if (typeof o.refresh_token !== 'string' || !o.refresh_token)
|
|
75
|
+
return null;
|
|
76
|
+
return {
|
|
77
|
+
access_token: o.access_token,
|
|
78
|
+
refresh_token: o.refresh_token,
|
|
79
|
+
email: typeof o.email === 'string' ? o.email : '',
|
|
80
|
+
user_id: typeof o.user_id === 'string' ? o.user_id : '',
|
|
81
|
+
expires_at: typeof o.expires_at === 'number' && Number.isFinite(o.expires_at) ? o.expires_at : 0,
|
|
82
|
+
};
|
|
68
83
|
}
|
|
69
84
|
/**
|
|
70
|
-
* Config'i
|
|
71
|
-
*
|
|
85
|
+
* Config'i diskten oku. Yoksa null döner — login gerekli demektir.
|
|
86
|
+
* Bozuk JSON, symlink ya da düzenli olmayan dosya varsa da null döner ve dosyaya
|
|
87
|
+
* dokunulmaz (CLI okuyucusuyla aynı davranış). Grup/dünya erişimi açık bir dosya
|
|
88
|
+
* okunurken 0600'e sıkılaştırılır.
|
|
89
|
+
*/
|
|
90
|
+
function readConfig() {
|
|
91
|
+
const raw = (0, fsSafe_1.readPrivateFile)(configFile());
|
|
92
|
+
return raw === null ? null : parseConfig(raw);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Config'i diske yaz: atomik (geçici dosya + rename), dosya 0600, klasör 0700
|
|
96
|
+
* (var olan gevşek izinler sıkılaştırılır). Hedef bir symlink ise yazma REDDEDİLİR.
|
|
72
97
|
*/
|
|
73
98
|
function writeConfig(config) {
|
|
74
|
-
|
|
75
|
-
fs.mkdirSync(CONFIG_DIR, { recursive: true, mode: 0o700 });
|
|
76
|
-
}
|
|
77
|
-
fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2), {
|
|
78
|
-
mode: 0o600,
|
|
79
|
-
});
|
|
99
|
+
(0, fsSafe_1.writePrivateFile)(configFile(), JSON.stringify(config, null, 2), { mode: 0o600 });
|
|
80
100
|
}
|
|
81
|
-
/** `ple logout` için: config dosyasını
|
|
101
|
+
/** `ple logout` için: config dosyasını sil (symlink ise yalnız bağlantının kendisi). */
|
|
82
102
|
function clearConfig() {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
103
|
+
const file = configFile();
|
|
104
|
+
if ((0, fsSafe_1.pathExists)(file))
|
|
105
|
+
fs.unlinkSync(file);
|
|
86
106
|
}
|
|
87
107
|
/** Token'ın 60 saniye içinde sona erecek olup olmadığını kontrol et. */
|
|
88
108
|
function isTokenExpiringSoon(config) {
|
package/dist/lib/constants.js
CHANGED
|
@@ -8,8 +8,46 @@
|
|
|
8
8
|
* CLI honors, so one export covers both tools).
|
|
9
9
|
*/
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.MCP_VERSION = exports.MCP_SERVER_NAME = exports.API_BASE_URL = void 0;
|
|
11
|
+
exports.MCP_VERSION = exports.MCP_SERVER_NAME = exports.API_BASE_URL = exports.API_BASE_URL_ERROR = void 0;
|
|
12
|
+
exports.validateApiBaseUrl = validateApiBaseUrl;
|
|
12
13
|
const BAKED_API_URL = 'https://promptlikeengineer.com';
|
|
14
|
+
/** Hosts for which plain http is allowed (local development only). */
|
|
15
|
+
const LOOPBACK_HOSTS = new Set(['localhost', '127.0.0.1', '[::1]']);
|
|
16
|
+
/**
|
|
17
|
+
* Validate an API base URL before ANY request is built from it. The server sends
|
|
18
|
+
* a bearer token and a refresh token to this origin, so a typo or a hostile
|
|
19
|
+
* `PROMPTLIKE_API_URL` must not turn into a plaintext token leak. Same contract
|
|
20
|
+
* as the CLI's `validateApiBaseUrl` (copied: the CLI package exports no internals).
|
|
21
|
+
*
|
|
22
|
+
* - https is required; http is accepted ONLY for localhost / 127.0.0.1 / [::1].
|
|
23
|
+
* - No credentials in the URL (`https://user:pw@host`), no query or fragment.
|
|
24
|
+
* - Only the origin plus an optional path prefix is kept (trailing slashes dropped).
|
|
25
|
+
*
|
|
26
|
+
* Returns the cleaned URL, or an error message that says how to fix it.
|
|
27
|
+
*/
|
|
28
|
+
function validateApiBaseUrl(raw) {
|
|
29
|
+
let u;
|
|
30
|
+
try {
|
|
31
|
+
u = new URL(raw);
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return { error: `PROMPTLIKE_API_URL is not a valid URL. Example: https://promptlikeengineer.com` };
|
|
35
|
+
}
|
|
36
|
+
const loopback = LOOPBACK_HOSTS.has(u.hostname);
|
|
37
|
+
if (u.protocol !== 'https:' && !(u.protocol === 'http:' && loopback)) {
|
|
38
|
+
return {
|
|
39
|
+
error: `PROMPTLIKE_API_URL must use https (plain http is allowed only for localhost, 127.0.0.1 and [::1]). ` +
|
|
40
|
+
'Your login token would otherwise travel unencrypted.',
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
if (u.username || u.password) {
|
|
44
|
+
return { error: 'PROMPTLIKE_API_URL must not contain a username or password.' };
|
|
45
|
+
}
|
|
46
|
+
if (u.search || u.hash) {
|
|
47
|
+
return { error: 'PROMPTLIKE_API_URL must not contain a query string or fragment.' };
|
|
48
|
+
}
|
|
49
|
+
return { url: (u.origin + u.pathname).replace(/\/+$/, '') };
|
|
50
|
+
}
|
|
13
51
|
function resolveEnv(key, fallback) {
|
|
14
52
|
const value = process.env[key];
|
|
15
53
|
if (typeof value === 'string' && value.trim().length > 0) {
|
|
@@ -17,8 +55,16 @@ function resolveEnv(key, fallback) {
|
|
|
17
55
|
}
|
|
18
56
|
return fallback;
|
|
19
57
|
}
|
|
58
|
+
const resolvedApi = validateApiBaseUrl(resolveEnv('PROMPTLIKE_API_URL', BAKED_API_URL));
|
|
59
|
+
/**
|
|
60
|
+
* Set when `PROMPTLIKE_API_URL` is unusable. The API client throws it before it
|
|
61
|
+
* builds a request, so nothing, least of all a token, is ever sent to a URL that
|
|
62
|
+
* failed validation. (Not thrown at import time: a crash there would kill the
|
|
63
|
+
* stdio server before it can report anything to the MCP client.)
|
|
64
|
+
*/
|
|
65
|
+
exports.API_BASE_URL_ERROR = 'error' in resolvedApi ? resolvedApi.error : null;
|
|
20
66
|
/** Base URL of the web API (no trailing slash). */
|
|
21
|
-
exports.API_BASE_URL =
|
|
67
|
+
exports.API_BASE_URL = 'url' in resolvedApi ? resolvedApi.url : BAKED_API_URL;
|
|
22
68
|
exports.MCP_SERVER_NAME = 'promptlike';
|
|
23
69
|
/**
|
|
24
70
|
* Sürüm TEK KAYNAKTAN: package.json (CLI ile aynı desen). Elle yazılan sabit
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* submit_feedback — an agent tells the maker that a tool is missing, broken, confusing or gave a wrong
|
|
4
|
+
* result, or that a saved prompt did not work (POST /api/feedback).
|
|
5
|
+
*
|
|
6
|
+
* Guarantees (each has a test):
|
|
7
|
+
* - No secret, no prompt body: the same secret patterns as save_prompt (writeGuard.ts) REFUSE the call and
|
|
8
|
+
* name the kind, never the value; `prompt` is a title or an id on one line (≤200), never prompt text.
|
|
9
|
+
* - What is sent is the type, the message, the prompt title/id and email if given, who wrote it
|
|
10
|
+
* (`source: "agent"`, `agent_name`: the MCP client's name or "mcp-client", `client: "mcp"`) and four short
|
|
11
|
+
* context values (version, OS + CPU, Node version, the tool name). Nothing else.
|
|
12
|
+
* - The session is optional: signed in, the report is tied to the account (bearer token of `ple login`);
|
|
13
|
+
* signed out, or when the server does not accept the session, it goes out anonymously.
|
|
14
|
+
* - Never throws. Rate limits, network problems and server errors come back as a structured error
|
|
15
|
+
* (`{ error, code, retryable, retry_after? }`) the agent can act on. Nothing is queued (the CLI queues; a
|
|
16
|
+
* stdio server that just failed to reach the API is not a place to keep state).
|
|
17
|
+
* - Retried tool calls do not duplicate: an identical report that already went through in this session
|
|
18
|
+
* returns the earlier id.
|
|
19
|
+
*/
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.FEEDBACK_TIMEOUT_MS = exports.DEFAULT_AGENT_NAME = exports.MAX_AGENT_NAME = exports.MAX_FEEDBACK_PROMPT_REF = exports.MAX_FEEDBACK_MESSAGE = exports.FEEDBACK_TYPES = void 0;
|
|
22
|
+
exports.agentNameFor = agentNameFor;
|
|
23
|
+
exports.buildFeedbackPayload = buildFeedbackPayload;
|
|
24
|
+
exports.resetFeedbackSession = resetFeedbackSession;
|
|
25
|
+
exports.submitFeedbackFlow = submitFeedbackFlow;
|
|
26
|
+
const constants_1 = require("./constants");
|
|
27
|
+
const api_client_1 = require("./api-client");
|
|
28
|
+
const config_1 = require("./config");
|
|
29
|
+
const writeGuard_1 = require("./writeGuard");
|
|
30
|
+
exports.FEEDBACK_TYPES = ['bug', 'missing', 'idea', 'prompt'];
|
|
31
|
+
exports.MAX_FEEDBACK_MESSAGE = 2000;
|
|
32
|
+
exports.MAX_FEEDBACK_PROMPT_REF = 200;
|
|
33
|
+
exports.MAX_AGENT_NAME = 64;
|
|
34
|
+
exports.DEFAULT_AGENT_NAME = 'mcp-client';
|
|
35
|
+
exports.FEEDBACK_TIMEOUT_MS = 15000;
|
|
36
|
+
const MAX_CONTEXT_VALUE = 64;
|
|
37
|
+
const EMAIL_RE = /^[^\s@<>()[\],;:"\\]{1,64}@[^\s@<>()[\],;:"\\]+\.[^\s@<>()[\],;:"\\]{2,}$/;
|
|
38
|
+
/** MCP client name (from `initialize`) as an agent label: lowercase `a-z 0-9 . _ -`, ≤64; "mcp-client" when unknown. */
|
|
39
|
+
function agentNameFor(clientName) {
|
|
40
|
+
const cleaned = (clientName ?? '')
|
|
41
|
+
.normalize('NFKC')
|
|
42
|
+
.toLowerCase()
|
|
43
|
+
.replace(/[^a-z0-9._-]+/g, '-')
|
|
44
|
+
.replace(/-{2,}/g, '-')
|
|
45
|
+
.replace(/^[-._]+|[-._]+$/g, '')
|
|
46
|
+
.slice(0, exports.MAX_AGENT_NAME);
|
|
47
|
+
return cleaned || exports.DEFAULT_AGENT_NAME;
|
|
48
|
+
}
|
|
49
|
+
function fail(code, message, extra = {}) {
|
|
50
|
+
return { ok: false, message, payload: { error: message, code, ...extra } };
|
|
51
|
+
}
|
|
52
|
+
/** Validate input and build the body. The error never echoes a secret. */
|
|
53
|
+
function buildFeedbackPayload(args, clientName) {
|
|
54
|
+
const type = args.type ?? 'idea';
|
|
55
|
+
if (!exports.FEEDBACK_TYPES.includes(type)) {
|
|
56
|
+
return { ok: false, error: `type must be one of: ${exports.FEEDBACK_TYPES.join(', ')}.` };
|
|
57
|
+
}
|
|
58
|
+
const message = (0, writeGuard_1.cleanContent)(args.message ?? '');
|
|
59
|
+
if (!message)
|
|
60
|
+
return { ok: false, error: 'message is empty.' };
|
|
61
|
+
if (message.length > exports.MAX_FEEDBACK_MESSAGE) {
|
|
62
|
+
return { ok: false, error: `message is too long (${message.length} chars, max ${exports.MAX_FEEDBACK_MESSAGE}). One short, factual sentence is enough.` };
|
|
63
|
+
}
|
|
64
|
+
// Scan the RAW text too: cleaning turns a control character into nothing/space, which can split a key.
|
|
65
|
+
const secret = (0, writeGuard_1.findSecret)(args.message) ?? (0, writeGuard_1.findSecret)(message);
|
|
66
|
+
if (secret) {
|
|
67
|
+
return { ok: false, error: `message looks like it contains a ${secret}. Nothing was sent. Remove it and try again — feedback never needs secrets.` };
|
|
68
|
+
}
|
|
69
|
+
const value = {
|
|
70
|
+
type: type,
|
|
71
|
+
message,
|
|
72
|
+
source: 'agent',
|
|
73
|
+
agent_name: agentNameFor(clientName),
|
|
74
|
+
client: 'mcp',
|
|
75
|
+
context: {
|
|
76
|
+
cli_version: constants_1.MCP_VERSION.slice(0, MAX_CONTEXT_VALUE),
|
|
77
|
+
os: `${process.platform}-${process.arch}`.slice(0, MAX_CONTEXT_VALUE),
|
|
78
|
+
node: process.versions.node.slice(0, MAX_CONTEXT_VALUE),
|
|
79
|
+
command: 'submit_feedback',
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
if (args.prompt !== undefined) {
|
|
83
|
+
if (/[\r\n\u2028\u2029]/.test(args.prompt)) {
|
|
84
|
+
return { ok: false, error: 'prompt must be a prompt title or id on one line, not prompt text. Prompt bodies are never sent.' };
|
|
85
|
+
}
|
|
86
|
+
const ref = (0, writeGuard_1.cleanTitle)(args.prompt);
|
|
87
|
+
if (ref.length > exports.MAX_FEEDBACK_PROMPT_REF) {
|
|
88
|
+
return { ok: false, error: `prompt is too long (max ${exports.MAX_FEEDBACK_PROMPT_REF} chars). Give the title or id, never the text.` };
|
|
89
|
+
}
|
|
90
|
+
const refSecret = (0, writeGuard_1.findSecret)(args.prompt);
|
|
91
|
+
if (refSecret)
|
|
92
|
+
return { ok: false, error: `prompt looks like it contains a ${refSecret}. Nothing was sent.` };
|
|
93
|
+
if (ref)
|
|
94
|
+
value.prompt_ref = ref;
|
|
95
|
+
}
|
|
96
|
+
if (args.email !== undefined) {
|
|
97
|
+
const email = args.email.trim();
|
|
98
|
+
if (email.length > 254 || !EMAIL_RE.test(email))
|
|
99
|
+
return { ok: false, error: 'email is not a valid address.' };
|
|
100
|
+
value.email = email;
|
|
101
|
+
}
|
|
102
|
+
return { ok: true, value };
|
|
103
|
+
}
|
|
104
|
+
function retryAfterOf(...values) {
|
|
105
|
+
for (const v of values) {
|
|
106
|
+
const n = typeof v === 'number' ? v : typeof v === 'string' && /^\d{1,6}$/.test(v.trim()) ? Number(v) : NaN;
|
|
107
|
+
if (Number.isFinite(n) && n >= 0)
|
|
108
|
+
return Math.min(Math.floor(n), 86400);
|
|
109
|
+
}
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
async function post(payload, token, fetchImpl) {
|
|
113
|
+
const signal = AbortSignal.timeout(exports.FEEDBACK_TIMEOUT_MS);
|
|
114
|
+
let res;
|
|
115
|
+
try {
|
|
116
|
+
res = await fetchImpl(`${constants_1.API_BASE_URL}/api/feedback`, {
|
|
117
|
+
method: 'POST',
|
|
118
|
+
headers: {
|
|
119
|
+
'Content-Type': 'application/json',
|
|
120
|
+
Accept: 'application/json',
|
|
121
|
+
'X-Client-Version': `mcp/${constants_1.MCP_VERSION}`,
|
|
122
|
+
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
|
123
|
+
},
|
|
124
|
+
body: JSON.stringify(payload),
|
|
125
|
+
signal,
|
|
126
|
+
// Never follow a redirect: the body (and a token) must not be replayed at an address the server chose.
|
|
127
|
+
redirect: 'manual',
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
catch (err) {
|
|
131
|
+
const timedOut = signal.aborted || err?.name === 'TimeoutError' || err?.name === 'AbortError';
|
|
132
|
+
return {
|
|
133
|
+
kind: 'unreachable',
|
|
134
|
+
message: timedOut
|
|
135
|
+
? `No response from ${constants_1.API_BASE_URL} within ${exports.FEEDBACK_TIMEOUT_MS / 1000}s.`
|
|
136
|
+
: `Cannot reach ${constants_1.API_BASE_URL}. Check the connection.`,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
if (res.status >= 300 && res.status < 400) {
|
|
140
|
+
return { kind: 'unreachable', message: `The server answered with a redirect (HTTP ${res.status}); it is not followed. Check PROMPTLIKE_API_URL.` };
|
|
141
|
+
}
|
|
142
|
+
let body = {};
|
|
143
|
+
try {
|
|
144
|
+
const parsed = await res.json();
|
|
145
|
+
if (typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed))
|
|
146
|
+
body = parsed;
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
/* status decides */
|
|
150
|
+
}
|
|
151
|
+
return { kind: 'response', status: res.status, body, retryAfter: retryAfterOf(body.retry_after, res.headers.get('retry-after')) };
|
|
152
|
+
}
|
|
153
|
+
/** Short, single-line text from the server (it is data, not instructions: length-capped, control characters removed). */
|
|
154
|
+
function serverText(body, fallback) {
|
|
155
|
+
const e = body.error;
|
|
156
|
+
if (typeof e !== 'string' || !e.trim())
|
|
157
|
+
return fallback;
|
|
158
|
+
return (0, writeGuard_1.cleanTitle)(e).slice(0, 300) || fallback;
|
|
159
|
+
}
|
|
160
|
+
const sentInThisSession = new Map();
|
|
161
|
+
const MAX_REMEMBERED = 100;
|
|
162
|
+
/** For tests. */
|
|
163
|
+
function resetFeedbackSession() {
|
|
164
|
+
sentInThisSession.clear();
|
|
165
|
+
}
|
|
166
|
+
async function submitFeedbackFlow(args, opts = {}) {
|
|
167
|
+
try {
|
|
168
|
+
const built = buildFeedbackPayload(args, opts.clientName);
|
|
169
|
+
if (!built.ok)
|
|
170
|
+
return fail('invalid_input', built.error, { retryable: false });
|
|
171
|
+
const payload = built.value;
|
|
172
|
+
if (constants_1.API_BASE_URL_ERROR)
|
|
173
|
+
return fail('config', constants_1.API_BASE_URL_ERROR, { retryable: false });
|
|
174
|
+
const key = JSON.stringify([payload.type, payload.message, payload.prompt_ref ?? '', payload.email ?? '']);
|
|
175
|
+
const earlier = sentInThisSession.get(key);
|
|
176
|
+
if (earlier !== undefined) {
|
|
177
|
+
return { ok: true, payload: { status: 'already_sent', ...(earlier ? { id: earlier } : {}), note: 'This exact report was already sent in this session.' } };
|
|
178
|
+
}
|
|
179
|
+
const fetchImpl = opts.fetchImpl ?? fetch;
|
|
180
|
+
// The session is optional. A refresh that fails only means: send without it.
|
|
181
|
+
let token;
|
|
182
|
+
if ((0, config_1.readConfig)()) {
|
|
183
|
+
try {
|
|
184
|
+
await (0, api_client_1.ensureAuthed)();
|
|
185
|
+
token = (0, config_1.readConfig)()?.access_token;
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
token = undefined;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
let raw = await post(payload, token, fetchImpl);
|
|
192
|
+
if (raw.kind === 'response' && (raw.status === 401 || raw.status === 403) && token) {
|
|
193
|
+
raw = await post(payload, undefined, fetchImpl); // the server did not accept the session: send anonymously
|
|
194
|
+
token = undefined;
|
|
195
|
+
}
|
|
196
|
+
if (raw.kind === 'unreachable') {
|
|
197
|
+
return fail('unavailable', `${raw.message} The feedback was not sent; do not retry in a loop — mention it to the user instead.`, { retryable: true });
|
|
198
|
+
}
|
|
199
|
+
const { status, body } = raw;
|
|
200
|
+
if (status === 200 || status === 201) {
|
|
201
|
+
const id = typeof body.id === 'string' || typeof body.id === 'number' ? (0, writeGuard_1.cleanTitle)(String(body.id)).slice(0, 64) : '';
|
|
202
|
+
if (sentInThisSession.size >= MAX_REMEMBERED)
|
|
203
|
+
sentInThisSession.clear();
|
|
204
|
+
sentInThisSession.set(key, id);
|
|
205
|
+
return { ok: true, payload: { status: 'sent', ...(id ? { id } : {}), account: token !== undefined, note: 'Thank you — this reaches the maker of PromptLikeEngineer.' } };
|
|
206
|
+
}
|
|
207
|
+
if (status === 429) {
|
|
208
|
+
const wait = raw.retryAfter;
|
|
209
|
+
return fail('rate_limited', `Rate limited${wait !== undefined ? `; retry in ${wait}s` : ''}. The feedback was not sent.`, {
|
|
210
|
+
retryable: true,
|
|
211
|
+
...(wait !== undefined ? { retry_after: wait } : {}),
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
if (status === 400 || status === 413 || status === 422) {
|
|
215
|
+
return fail('rejected', `The server rejected the feedback: ${serverText(body, status === 413 ? 'too large' : 'invalid')}`, { retryable: false });
|
|
216
|
+
}
|
|
217
|
+
if (status >= 500 || status === 404 || status === 408) {
|
|
218
|
+
return fail('unavailable', `The server answered HTTP ${status}. The feedback was not sent.`, { retryable: true });
|
|
219
|
+
}
|
|
220
|
+
return fail('unexpected', `The server answered HTTP ${status}: ${serverText(body, 'unexpected answer')}`, { retryable: false });
|
|
221
|
+
}
|
|
222
|
+
catch (err) {
|
|
223
|
+
return fail('unexpected', err instanceof Error ? (0, writeGuard_1.cleanTitle)(err.message).slice(0, 200) : 'Unexpected error.', { retryable: false });
|
|
224
|
+
}
|
|
225
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Safe file helpers for the shared session file (`~/.config/promptlike/config.json`).
|
|
4
|
+
* Minimal copy of `cli/src/lib/fsSafe.ts` (the CLI package exports no internals;
|
|
5
|
+
* precedent: promptVariables, writeGuard). Differences, on purpose:
|
|
6
|
+
* - `writePrivateFile` REFUSES a symlink at the target (the CLI replaces the link);
|
|
7
|
+
* the MCP server writes only after `readConfig` found a regular file, so a link
|
|
8
|
+
* means "not logged in" here rather than a silent swap of someone's dotfile.
|
|
9
|
+
*
|
|
10
|
+
* Threats covered (each has a test in fsSafe.test.ts):
|
|
11
|
+
* - SYMLINK: a link planted at the target (`config.json -> ~/.bashrc`) is never
|
|
12
|
+
* written through or read through.
|
|
13
|
+
* - LOOSE PERMISSIONS: `mkdir`/`writeFile` modes only apply on creation, so an
|
|
14
|
+
* existing directory/file with group or world access is tightened to 0700 / 0600.
|
|
15
|
+
* - TORN WRITES: data goes to a fresh temp file that is `rename`d over the target,
|
|
16
|
+
* so a crash mid-write never leaves a half token file for the CLI to read.
|
|
17
|
+
*
|
|
18
|
+
* POSIX permission bits do not exist on Windows; the chmod steps are skipped there.
|
|
19
|
+
*/
|
|
20
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
23
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
24
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
25
|
+
}
|
|
26
|
+
Object.defineProperty(o, k2, desc);
|
|
27
|
+
}) : (function(o, m, k, k2) {
|
|
28
|
+
if (k2 === undefined) k2 = k;
|
|
29
|
+
o[k2] = m[k];
|
|
30
|
+
}));
|
|
31
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
32
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
33
|
+
}) : function(o, v) {
|
|
34
|
+
o["default"] = v;
|
|
35
|
+
});
|
|
36
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
37
|
+
var ownKeys = function(o) {
|
|
38
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
39
|
+
var ar = [];
|
|
40
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
41
|
+
return ar;
|
|
42
|
+
};
|
|
43
|
+
return ownKeys(o);
|
|
44
|
+
};
|
|
45
|
+
return function (mod) {
|
|
46
|
+
if (mod && mod.__esModule) return mod;
|
|
47
|
+
var result = {};
|
|
48
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
49
|
+
__setModuleDefault(result, mod);
|
|
50
|
+
return result;
|
|
51
|
+
};
|
|
52
|
+
})();
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
exports.isSymlink = isSymlink;
|
|
55
|
+
exports.pathExists = pathExists;
|
|
56
|
+
exports.ensurePrivateDir = ensurePrivateDir;
|
|
57
|
+
exports.assertNotSymlink = assertNotSymlink;
|
|
58
|
+
exports.writePrivateFile = writePrivateFile;
|
|
59
|
+
exports.readPrivateFile = readPrivateFile;
|
|
60
|
+
const fs = __importStar(require("fs"));
|
|
61
|
+
const path = __importStar(require("path"));
|
|
62
|
+
const IS_WINDOWS = process.platform === 'win32';
|
|
63
|
+
/** True when `p` exists and is itself a symbolic link (does not follow it). */
|
|
64
|
+
function isSymlink(p) {
|
|
65
|
+
try {
|
|
66
|
+
return fs.lstatSync(p).isSymbolicLink();
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/** True when anything (file, dir, link, even a dangling link) exists at `p`. */
|
|
73
|
+
function pathExists(p) {
|
|
74
|
+
try {
|
|
75
|
+
fs.lstatSync(p);
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Create `dir` (and parents) with mode 0700 and tighten it when it already exists
|
|
84
|
+
* with group/world bits. Only the LEAF is tightened: parents such as `~/.config`
|
|
85
|
+
* belong to the user and other tools.
|
|
86
|
+
*/
|
|
87
|
+
function ensurePrivateDir(dir) {
|
|
88
|
+
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
89
|
+
if (IS_WINDOWS)
|
|
90
|
+
return;
|
|
91
|
+
try {
|
|
92
|
+
const st = fs.statSync(dir);
|
|
93
|
+
if (st.isDirectory() && (st.mode & 0o077) !== 0)
|
|
94
|
+
fs.chmodSync(dir, 0o700);
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
/* a directory we cannot stat is reported by the write that follows */
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/** Refuse to write over a symlink. */
|
|
101
|
+
function assertNotSymlink(target) {
|
|
102
|
+
if (isSymlink(target)) {
|
|
103
|
+
throw new Error(`${target} is a symbolic link; refusing to write through it. Remove the link and run \`ple login\` again.`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Write `data` to `file` atomically (default mode 0600; callers state it so the
|
|
108
|
+
* guarantee is visible at the call site). Refuses a symlink at `file`.
|
|
109
|
+
* The parent directory is created 0700 and tightened if needed.
|
|
110
|
+
*/
|
|
111
|
+
function writePrivateFile(file, data, opts = {}) {
|
|
112
|
+
assertNotSymlink(file);
|
|
113
|
+
ensurePrivateDir(path.dirname(file));
|
|
114
|
+
const tmp = `${file}.${process.pid}.${Date.now()}.tmp`;
|
|
115
|
+
// 'wx' = create exclusively, so a file or link planted at the temp name makes
|
|
116
|
+
// the write fail instead of being followed.
|
|
117
|
+
fs.writeFileSync(tmp, data, { mode: opts.mode ?? 0o600, flag: 'wx' });
|
|
118
|
+
try {
|
|
119
|
+
fs.renameSync(tmp, file);
|
|
120
|
+
}
|
|
121
|
+
catch (err) {
|
|
122
|
+
try {
|
|
123
|
+
fs.unlinkSync(tmp);
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
/* best effort */
|
|
127
|
+
}
|
|
128
|
+
throw err;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Read a private file without following a symlink at the final path component.
|
|
133
|
+
* Returns null when the file is missing, is a link, or is not a regular file.
|
|
134
|
+
* A regular file that is group/world accessible is tightened to 0600.
|
|
135
|
+
*/
|
|
136
|
+
function readPrivateFile(file) {
|
|
137
|
+
let st;
|
|
138
|
+
try {
|
|
139
|
+
st = fs.lstatSync(file);
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
if (st.isSymbolicLink() || !st.isFile())
|
|
145
|
+
return null;
|
|
146
|
+
if (!IS_WINDOWS && (st.mode & 0o077) !== 0) {
|
|
147
|
+
try {
|
|
148
|
+
fs.chmodSync(file, 0o600);
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
/* read-only filesystem: still readable */
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
try {
|
|
155
|
+
return fs.readFileSync(file, 'utf-8');
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
}
|
package/dist/lib/writeGuard.js
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.MAX_TAG_LENGTH = exports.MAX_TAGS = exports.MAX_CHANGELOG = exports.MAX_DESCRIPTION = exports.MAX_CONTENT = exports.MAX_TITLE = void 0;
|
|
18
|
+
exports.normalizeForScan = normalizeForScan;
|
|
18
19
|
exports.findSecret = findSecret;
|
|
19
20
|
exports.cleanTitle = cleanTitle;
|
|
20
21
|
exports.cleanContent = cleanContent;
|
|
@@ -27,27 +28,62 @@ exports.MAX_DESCRIPTION = 1000;
|
|
|
27
28
|
exports.MAX_CHANGELOG = 500;
|
|
28
29
|
exports.MAX_TAGS = 10;
|
|
29
30
|
exports.MAX_TAG_LENGTH = 50;
|
|
31
|
+
// A key can follow `_` (KEY_sk-...), which `\b` does not treat as a boundary, so
|
|
32
|
+
// prefixes use "not preceded by a letter or digit" instead.
|
|
33
|
+
const START = '(?<![A-Za-z0-9])';
|
|
30
34
|
const SECRET_PATTERNS = [
|
|
31
|
-
{ label: 'Anthropic/OpenAI API key', re:
|
|
32
|
-
{ label: 'AWS access key', re:
|
|
33
|
-
{
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
{ label: 'Anthropic/OpenAI API key', re: new RegExp(`${START}sk-(?:ant-|proj-)?[A-Za-z0-9_-]{20,}`) },
|
|
36
|
+
{ label: 'AWS access key', re: new RegExp(`${START}(?:AKIA|ASIA)[0-9A-Z]{16}(?![A-Za-z0-9])`) },
|
|
37
|
+
{
|
|
38
|
+
label: 'AWS secret key',
|
|
39
|
+
// 40 base64 characters alone are indistinguishable from hashes, so the variable name is required.
|
|
40
|
+
re: /aws_?secret_?access_?key["']?\s*[:=]\s*["']?[A-Za-z0-9/+=]{40}(?![A-Za-z0-9/+=])/i,
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
label: 'GitHub token',
|
|
44
|
+
re: new RegExp(`${START}(?:ghp|gho|ghu|ghs|ghr)_[A-Za-z0-9]{30,}|${START}github_pat_[A-Za-z0-9_]{30,}`),
|
|
45
|
+
},
|
|
46
|
+
{ label: 'GitLab token', re: new RegExp(`${START}glpat-[A-Za-z0-9_-]{20,}`) },
|
|
47
|
+
{ label: 'Slack token', re: new RegExp(`${START}xox[abprs]-[A-Za-z0-9-]{10,}`) },
|
|
48
|
+
{ label: 'Google API key', re: new RegExp(`${START}AIza[0-9A-Za-z_-]{35}(?![A-Za-z0-9_-])`) },
|
|
49
|
+
{ label: 'Stripe key', re: new RegExp(`${START}(?:sk|rk)_live_[A-Za-z0-9]{20,}`) },
|
|
50
|
+
{ label: 'Stripe webhook secret', re: new RegExp(`${START}whsec_[A-Za-z0-9]{20,}`) },
|
|
51
|
+
{ label: 'Supabase key', re: new RegExp(`${START}(?:sbp_[0-9a-f]{30,}|sb_secret_[A-Za-z0-9_-]{20,})`) },
|
|
52
|
+
{ label: 'npm token', re: new RegExp(`${START}npm_[A-Za-z0-9]{30,}`) },
|
|
53
|
+
{ label: 'Vercel Blob token', re: new RegExp(`${START}vercel_blob_rw_[A-Za-z0-9_-]{20,}`) },
|
|
54
|
+
{ label: 'SendGrid API key', re: new RegExp(`${START}SG\\.[A-Za-z0-9_-]{16,}\\.[A-Za-z0-9_-]{16,}`) },
|
|
38
55
|
{ label: 'private key', re: /-----BEGIN [A-Z ]*PRIVATE KEY-----/ },
|
|
39
|
-
{ label: 'JWT', re:
|
|
56
|
+
{ label: 'JWT', re: new RegExp(`${START}eyJ[A-Za-z0-9_-]{10,}\\.eyJ[A-Za-z0-9_-]{10,}\\.[A-Za-z0-9_-]{10,}`) },
|
|
57
|
+
{
|
|
58
|
+
label: 'Authorization bearer token',
|
|
59
|
+
// `Bearer {{token}}` placeholders are what we ask agents to write, so they pass.
|
|
60
|
+
re: /Authorization["']?\s*[:=]\s*["']?Bearer\s+(?!\{\{)[A-Za-z0-9._~+/-]{20,}/i,
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
label: 'URL with embedded password',
|
|
64
|
+
// scheme://user:password@host, but a `{{variable}}` password is the sanctioned form and passes.
|
|
65
|
+
re: /(?<![A-Za-z0-9+.-])[a-z][a-z0-9+.-]*:\/\/[^\s:@/]+:(?!\{\{)[^\s@/]{3,}@/i,
|
|
66
|
+
},
|
|
40
67
|
];
|
|
68
|
+
// C0/C1 control characters except tab/newline/carriage return.
|
|
69
|
+
const CONTROL_CHARS = /[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F-\u009F]/g;
|
|
70
|
+
// Characters that are invisible or merely formatting. They never change what a
|
|
71
|
+
// key looks like to a human or a model, but a zero-width space in the middle of
|
|
72
|
+
// one defeats a regex. Removed for MATCHING only (stored text is untouched).
|
|
73
|
+
const INVISIBLE = /[\p{Cf}\u2028\u2029\u034F\u115F\u1160\u17B4\u17B5\u180B-\u180F\u3164\uFE00-\uFE0F\uFFA0\u{E0000}-\u{E007F}\u{E0100}-\u{E01EF}]/gu;
|
|
74
|
+
/** Text as the matcher sees it: NFKC (fullwidth forms fold to ASCII) with format, invisible and control characters removed (tab/newline/CR stay, so line structure survives). */
|
|
75
|
+
function normalizeForScan(text) {
|
|
76
|
+
return text.normalize('NFKC').replace(INVISIBLE, '').replace(CONTROL_CHARS, '');
|
|
77
|
+
}
|
|
41
78
|
/** Kind of secret found (never the value), or null when clean. */
|
|
42
79
|
function findSecret(text) {
|
|
80
|
+
const scanned = normalizeForScan(text);
|
|
43
81
|
for (const { label, re } of SECRET_PATTERNS) {
|
|
44
|
-
if (re.test(
|
|
82
|
+
if (re.test(scanned))
|
|
45
83
|
return label;
|
|
46
84
|
}
|
|
47
85
|
return null;
|
|
48
86
|
}
|
|
49
|
-
// C0/C1 control characters except tab/newline/carriage return.
|
|
50
|
-
const CONTROL_CHARS = /[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F-\u009F]/g;
|
|
51
87
|
/** Titles are one line: control chars and line breaks collapse to spaces. */
|
|
52
88
|
function cleanTitle(raw) {
|
|
53
89
|
return raw.replace(CONTROL_CHARS, ' ').replace(/[\r\n\t]+/g, ' ').replace(/\s{2,}/g, ' ').trim();
|
|
@@ -73,49 +109,105 @@ function checkContent(raw) {
|
|
|
73
109
|
}
|
|
74
110
|
return { ok: true, value: content };
|
|
75
111
|
}
|
|
76
|
-
/**
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
const content = checkContent(input.content);
|
|
85
|
-
if (!content.ok)
|
|
86
|
-
return content;
|
|
87
|
-
const description = cleanTitle(input.description ?? '');
|
|
112
|
+
/**
|
|
113
|
+
* Description text (one line): control characters collapse, length-capped, secret-scanned. `alsoScan` is text
|
|
114
|
+
* that travels with it (the title) and is scanned in the same pass, as `save_prompt` always did.
|
|
115
|
+
* `undefined` → `''`.
|
|
116
|
+
*/
|
|
117
|
+
function checkDescription(raw, alsoScan = '') {
|
|
118
|
+
const description = cleanTitle(raw ?? '');
|
|
88
119
|
if (description.length > exports.MAX_DESCRIPTION) {
|
|
89
120
|
return { ok: false, error: `description is too long (max ${exports.MAX_DESCRIPTION} chars).` };
|
|
90
121
|
}
|
|
91
|
-
|
|
92
|
-
|
|
122
|
+
// Scan the RAW text: cleanTitle turns a control character into a space, which would split a key.
|
|
123
|
+
const textSecret = findSecret(`${alsoScan}\n${raw ?? ''}`);
|
|
124
|
+
if (textSecret) {
|
|
125
|
+
return {
|
|
126
|
+
ok: false,
|
|
127
|
+
error: `${alsoScan ? 'title/description' : 'description'} looks like it contains a ${textSecret}. Remove it and try again.`,
|
|
128
|
+
};
|
|
93
129
|
}
|
|
130
|
+
return { ok: true, value: description };
|
|
131
|
+
}
|
|
132
|
+
/** Tag names: cleaned, length-capped, secret-scanned, de-duplicated ignoring case, at most {@link MAX_TAGS}. */
|
|
133
|
+
function checkTags(raw) {
|
|
94
134
|
const tags = [];
|
|
95
|
-
for (const
|
|
96
|
-
const tag = cleanTitle(
|
|
135
|
+
for (const rawTag of raw ?? []) {
|
|
136
|
+
const tag = cleanTitle(rawTag);
|
|
97
137
|
if (!tag)
|
|
98
138
|
continue;
|
|
99
139
|
if (tag.length > exports.MAX_TAG_LENGTH) {
|
|
100
140
|
return { ok: false, error: `tag '${tag.slice(0, 20)}…' is too long (max ${exports.MAX_TAG_LENGTH} chars).` };
|
|
101
141
|
}
|
|
142
|
+
const tagSecret = findSecret(rawTag);
|
|
143
|
+
if (tagSecret) {
|
|
144
|
+
return { ok: false, error: `a tag looks like it contains a ${tagSecret}. Remove it and try again.` };
|
|
145
|
+
}
|
|
102
146
|
if (!tags.some((t) => t.toLowerCase() === tag.toLowerCase()))
|
|
103
147
|
tags.push(tag);
|
|
104
148
|
}
|
|
105
149
|
if (tags.length > exports.MAX_TAGS)
|
|
106
150
|
return { ok: false, error: `too many tags (max ${exports.MAX_TAGS}).` };
|
|
107
|
-
return { ok: true, value:
|
|
151
|
+
return { ok: true, value: tags };
|
|
108
152
|
}
|
|
109
|
-
/** Validate + normalise
|
|
110
|
-
function
|
|
153
|
+
/** Validate + normalise save_prompt input. */
|
|
154
|
+
function checkSaveInput(input) {
|
|
155
|
+
const title = cleanTitle(input.title);
|
|
156
|
+
if (!title)
|
|
157
|
+
return { ok: false, error: 'title is empty.' };
|
|
158
|
+
if (title.length > exports.MAX_TITLE) {
|
|
159
|
+
return { ok: false, error: `title is too long (${title.length} chars, max ${exports.MAX_TITLE}).` };
|
|
160
|
+
}
|
|
111
161
|
const content = checkContent(input.content);
|
|
112
162
|
if (!content.ok)
|
|
113
163
|
return content;
|
|
164
|
+
const description = checkDescription(input.description, input.title);
|
|
165
|
+
if (!description.ok)
|
|
166
|
+
return description;
|
|
167
|
+
const tags = checkTags(input.tags);
|
|
168
|
+
if (!tags.ok)
|
|
169
|
+
return tags;
|
|
170
|
+
return { ok: true, value: { title, content: content.value, description: description.value, tags: tags.value } };
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Validate + normalise update_prompt input. A field that was not given stays absent from the result, and a
|
|
174
|
+
* call that gives none of `content`, `description`, `tags` is refused — "update nothing" is a mistake, not a no-op.
|
|
175
|
+
* The same limits and secret scan as `save_prompt` apply to each field that IS given.
|
|
176
|
+
*/
|
|
177
|
+
function checkUpdateInput(input) {
|
|
178
|
+
if (input.content === undefined && input.description === undefined && input.tags === undefined) {
|
|
179
|
+
return { ok: false, error: 'nothing to update: give content (a new version), description or tags.' };
|
|
180
|
+
}
|
|
181
|
+
const value = {};
|
|
182
|
+
if (input.content !== undefined) {
|
|
183
|
+
const content = checkContent(input.content);
|
|
184
|
+
if (!content.ok)
|
|
185
|
+
return content;
|
|
186
|
+
value.content = content.value;
|
|
187
|
+
}
|
|
114
188
|
const changelog = input.changelog === undefined ? undefined : cleanTitle(input.changelog);
|
|
115
189
|
if (changelog !== undefined && changelog.length > exports.MAX_CHANGELOG) {
|
|
116
190
|
return { ok: false, error: `changelog is too long (max ${exports.MAX_CHANGELOG} chars).` };
|
|
117
191
|
}
|
|
118
|
-
|
|
192
|
+
const changelogSecret = input.changelog === undefined ? null : findSecret(input.changelog);
|
|
193
|
+
if (changelogSecret) {
|
|
194
|
+
return { ok: false, error: `changelog looks like it contains a ${changelogSecret}. Remove it and try again.` };
|
|
195
|
+
}
|
|
196
|
+
if (changelog)
|
|
197
|
+
value.changelog = changelog;
|
|
198
|
+
if (input.description !== undefined) {
|
|
199
|
+
const description = checkDescription(input.description);
|
|
200
|
+
if (!description.ok)
|
|
201
|
+
return description;
|
|
202
|
+
value.description = description.value;
|
|
203
|
+
}
|
|
204
|
+
if (input.tags !== undefined) {
|
|
205
|
+
const tags = checkTags(input.tags);
|
|
206
|
+
if (!tags.ok)
|
|
207
|
+
return tags;
|
|
208
|
+
value.tags = tags.value;
|
|
209
|
+
}
|
|
210
|
+
return { ok: true, value };
|
|
119
211
|
}
|
|
120
212
|
/**
|
|
121
213
|
* Idempotency key for "same content": whitespace-insensitive at the ends and
|
package/dist/lib/writeTools.js
CHANGED
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
* prompt; updating with the current content creates no version. A retried
|
|
13
13
|
* tool call therefore never duplicates anything.
|
|
14
14
|
* - Safety: update_prompt needs an exact title / id — a fuzzy match could
|
|
15
|
-
*
|
|
15
|
+
* change the wrong prompt. Old versions are never deleted. Its `description` overwrites only when given and
|
|
16
|
+
* its `tags` are add-only (see updatePromptFlow); this client sends no DELETE at all.
|
|
16
17
|
*/
|
|
17
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
19
|
exports.describeWriteError = describeWriteError;
|
|
@@ -125,11 +126,22 @@ function isExactReference(name, prompt) {
|
|
|
125
126
|
return true;
|
|
126
127
|
return prompt.title.trim().toLowerCase() === n;
|
|
127
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* update_prompt. Three independent parts, each acting ONLY when its argument was given:
|
|
131
|
+
* - `content` → a NEW version (old ones kept, labels stay); equal to the current text → no version.
|
|
132
|
+
* - `description` → overwritten on the prompt; equal to the current one → nothing is sent. No version.
|
|
133
|
+
* - `tags` → ADD-ONLY: the ones the prompt lacks are added; ones already on it (any case) are left,
|
|
134
|
+
* and tags not listed are never removed (`[]` changes nothing). No version.
|
|
135
|
+
* The description and the tags are not part of a version, so a metadata-only call never opens one. What the
|
|
136
|
+
* description was before is returned (`previous_description`) because it is overwritten and not versioned.
|
|
137
|
+
* Nothing here deletes a prompt or a version. The text goes first: a plan-limit refusal there stops the call
|
|
138
|
+
* before any metadata changes; a metadata step that fails after it is reported, never silent.
|
|
139
|
+
*/
|
|
128
140
|
async function updatePromptFlow(args) {
|
|
129
141
|
const checked = (0, writeGuard_1.checkUpdateInput)(args);
|
|
130
142
|
if (!checked.ok)
|
|
131
143
|
return { ok: false, message: checked.error };
|
|
132
|
-
const { content, changelog } = checked.value;
|
|
144
|
+
const { content, changelog, description, tags } = checked.value;
|
|
133
145
|
try {
|
|
134
146
|
const projectId = args.project ? await (0, resolver_1.resolveProjectId)(args.project) : undefined;
|
|
135
147
|
const result = await (0, resolver_1.resolvePromptByName)(args.name, { projectId });
|
|
@@ -152,30 +164,94 @@ async function updatePromptFlow(args) {
|
|
|
152
164
|
};
|
|
153
165
|
}
|
|
154
166
|
const current = (0, promptText_1.pickVersion)(prompt);
|
|
155
|
-
|
|
167
|
+
const payload = { id: prompt.id, title: prompt.title };
|
|
168
|
+
let versionAdded = false;
|
|
169
|
+
let metaChanged = false;
|
|
170
|
+
// 1) Text → new version.
|
|
171
|
+
if (content !== undefined) {
|
|
172
|
+
if ((0, writeGuard_1.sameContent)((0, promptText_1.versionText)(current), content)) {
|
|
173
|
+
payload.content = 'unchanged';
|
|
174
|
+
payload.version = current?.version_number ?? null;
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
const saved = await (0, api_client_1.savePromptVersion)({ promptId: prompt.id, content, changelog, bump: args.bump });
|
|
178
|
+
versionAdded = true;
|
|
179
|
+
payload.content = 'updated';
|
|
180
|
+
payload.version = saved.versionNumber ?? null;
|
|
181
|
+
payload.previous_version = current?.version_number ?? null;
|
|
182
|
+
payload.note = 'The previous version is kept; roll back any time from the web or `ple rollback`.';
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
const failures = [];
|
|
186
|
+
// 2) Description → overwrite (no version).
|
|
187
|
+
if (description !== undefined) {
|
|
188
|
+
const before = prompt.description ?? '';
|
|
189
|
+
if (before === description) {
|
|
190
|
+
payload.description = 'unchanged';
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
try {
|
|
194
|
+
await (0, api_client_1.updatePromptDescription)(prompt.id, description);
|
|
195
|
+
metaChanged = true;
|
|
196
|
+
payload.description = 'updated';
|
|
197
|
+
// The description is not versioned: hand back what was overwritten so it can be restored.
|
|
198
|
+
payload.previous_description = before;
|
|
199
|
+
}
|
|
200
|
+
catch (err) {
|
|
201
|
+
payload.description = 'failed';
|
|
202
|
+
failures.push(`description: ${describeWriteError(err)}`);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
// 3) Tags → add-only (no version). Nothing is ever detached.
|
|
207
|
+
if (tags !== undefined) {
|
|
208
|
+
const have = prompt.tags ?? [];
|
|
209
|
+
const haveNames = new Set(have.map((t) => t.name.toLowerCase()));
|
|
210
|
+
const toAdd = tags.filter((t) => !haveNames.has(t.toLowerCase()));
|
|
211
|
+
const added = [];
|
|
212
|
+
const tagsFailed = [];
|
|
213
|
+
for (const tag of toAdd) {
|
|
214
|
+
try {
|
|
215
|
+
await (0, api_client_1.addPromptTag)(prompt.id, tag);
|
|
216
|
+
added.push(tag);
|
|
217
|
+
}
|
|
218
|
+
catch {
|
|
219
|
+
tagsFailed.push(tag);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
metaChanged = metaChanged || added.length > 0;
|
|
223
|
+
payload.tags = toAdd.length === 0 ? 'unchanged' : tagsFailed.length > 0 ? 'partly updated' : 'updated';
|
|
224
|
+
if (added.length > 0)
|
|
225
|
+
payload.tags_added = added;
|
|
226
|
+
if (tagsFailed.length > 0) {
|
|
227
|
+
payload.tags_failed = tagsFailed;
|
|
228
|
+
failures.push(`tags: could not add ${tagsFailed.join(', ')}`);
|
|
229
|
+
}
|
|
230
|
+
const wanted = new Set(tags.map((t) => t.toLowerCase()));
|
|
231
|
+
if (have.some((t) => !wanted.has(t.name.toLowerCase()))) {
|
|
232
|
+
payload.tags_note = 'Tags are add-only: the tags you did not list were left on the prompt. Remove a tag in the web app.';
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
payload.status = versionAdded ? 'updated' : metaChanged ? 'metadata_updated' : 'unchanged';
|
|
236
|
+
if (payload.status === 'unchanged') {
|
|
237
|
+
// Text only: the wording the docs quote (src/config/iddia-kilidi.test.ts binds the page to this line).
|
|
238
|
+
payload.message =
|
|
239
|
+
description === undefined && tags === undefined
|
|
240
|
+
? 'Content matches the current version — no new version created.'
|
|
241
|
+
: 'Everything you sent already matches — nothing changed, no version created.';
|
|
242
|
+
}
|
|
243
|
+
else if (!versionAdded) {
|
|
244
|
+
payload.note = 'Only the description / tags changed: no new version was created (they are not part of a version).';
|
|
245
|
+
}
|
|
246
|
+
if (failures.length > 0) {
|
|
247
|
+
// The text (if any) is already saved: say so, and what is still to do.
|
|
156
248
|
return {
|
|
157
|
-
ok:
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
message: 'Content matches the current version — no new version created.',
|
|
161
|
-
id: prompt.id,
|
|
162
|
-
title: prompt.title,
|
|
163
|
-
version: current?.version_number ?? null,
|
|
164
|
-
},
|
|
249
|
+
ok: false,
|
|
250
|
+
message: `${versionAdded ? 'The new version was saved, but ' : ''}some changes were not applied — ${failures.join('; ')}. Call update_prompt again to retry them.`,
|
|
251
|
+
payload,
|
|
165
252
|
};
|
|
166
253
|
}
|
|
167
|
-
|
|
168
|
-
return {
|
|
169
|
-
ok: true,
|
|
170
|
-
payload: {
|
|
171
|
-
status: 'updated',
|
|
172
|
-
id: prompt.id,
|
|
173
|
-
title: prompt.title,
|
|
174
|
-
version: saved.versionNumber ?? null,
|
|
175
|
-
previous_version: current?.version_number ?? null,
|
|
176
|
-
note: 'The previous version is kept; roll back any time from the web or `ple rollback`.',
|
|
177
|
-
},
|
|
178
|
-
};
|
|
254
|
+
return { ok: true, payload };
|
|
179
255
|
}
|
|
180
256
|
catch (err) {
|
|
181
257
|
return { ok: false, message: describeWriteError(err) };
|
package/dist/server.js
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Üç yüzey:
|
|
7
7
|
* - tools: okuma (list_prompts / search_prompts / get_prompt / fill_variables
|
|
8
|
-
* / suggest_prompts) + yazma (v0.4+, W1-3: save_prompt / update_prompt)
|
|
8
|
+
* / suggest_prompts) + yazma (v0.4+, W1-3: save_prompt / update_prompt) +
|
|
9
|
+
* geri bildirim (submit_feedback: yapımcıya kısa not, oturumsuz da çalışır)
|
|
9
10
|
* - prompts (v0.3+): kullanıcının kütüphanesi MCP prompt'u olarak — istemcinin
|
|
10
11
|
* `/` menüsünde görünür, {{değişkenler}} prompt argümanı olur. Yerleşik
|
|
11
12
|
* `save-this` prompt'u (v0.4+) konuşmadaki talimatı kaydettirir.
|
|
@@ -30,6 +31,7 @@ const promptText_1 = require("./lib/promptText");
|
|
|
30
31
|
const mcpPrompts_1 = require("./lib/mcpPrompts");
|
|
31
32
|
const resources_1 = require("./lib/resources");
|
|
32
33
|
const writeTools_1 = require("./lib/writeTools");
|
|
34
|
+
const feedback_1 = require("./lib/feedback");
|
|
33
35
|
const writeGuard_1 = require("./lib/writeGuard");
|
|
34
36
|
function ok(payload) {
|
|
35
37
|
return { content: [{ type: 'text', text: JSON.stringify(payload, null, 2) }] };
|
|
@@ -37,6 +39,12 @@ function ok(payload) {
|
|
|
37
39
|
function fail(message) {
|
|
38
40
|
return { content: [{ type: 'text', text: message }], isError: true };
|
|
39
41
|
}
|
|
42
|
+
/** submit_feedback sonucu: başarıda JSON; hatada yapılandırılmış JSON (`error`, `code`, `retryable`, `retry_after?`) + isError. */
|
|
43
|
+
function fromFeedback(outcome) {
|
|
44
|
+
if (outcome.ok)
|
|
45
|
+
return ok(outcome.payload);
|
|
46
|
+
return { content: [{ type: 'text', text: JSON.stringify(outcome.payload, null, 2) }], isError: true };
|
|
47
|
+
}
|
|
40
48
|
function fromOutcome(outcome) {
|
|
41
49
|
if (outcome.ok)
|
|
42
50
|
return ok(outcome.payload);
|
|
@@ -504,24 +512,79 @@ function createServer(options = {}) {
|
|
|
504
512
|
return fromOutcome(outcome);
|
|
505
513
|
}));
|
|
506
514
|
server.registerTool('update_prompt', {
|
|
507
|
-
title: '
|
|
508
|
-
description: '
|
|
509
|
-
'
|
|
510
|
-
|
|
515
|
+
title: 'Update a prompt (new version, description, tags)',
|
|
516
|
+
description: 'Change an existing prompt. `name` must be the exact title or the id. Only the fields you pass are ' +
|
|
517
|
+
'touched; a field you leave out is NOT changed, a field you pass OVERWRITES. ' +
|
|
518
|
+
'`content` (the full new text) is saved as a NEW version: the old version is kept and nothing is ' +
|
|
519
|
+
'deleted; content equal to the current version creates no version. bump: patch (default), minor or major. ' +
|
|
520
|
+
"`description` (one line; '' clears it) overwrites the prompt's description. `tags` ADDS tags: the ones " +
|
|
521
|
+
'the prompt lacks are added; tags already on it, and tags you do not list, are left as they are. ' +
|
|
522
|
+
'It never removes a tag ([] changes nothing; remove a tag in the web app). Description and tags are not ' +
|
|
523
|
+
'part of a version: changing only them never creates one, and the previous description is returned so ' +
|
|
524
|
+
'it can be restored. ' +
|
|
525
|
+
'Pass at least one of content, description, tags; passing values that already match changes nothing. ' +
|
|
526
|
+
'This tool never deletes a prompt, a version or a tag.',
|
|
511
527
|
inputSchema: {
|
|
512
528
|
name: zod_1.z.string().min(1).describe('Exact prompt title, or its id / short id'),
|
|
513
|
-
content: zod_1.z
|
|
514
|
-
|
|
515
|
-
|
|
529
|
+
content: zod_1.z
|
|
530
|
+
.string()
|
|
531
|
+
.min(1)
|
|
532
|
+
.max(writeGuard_1.MAX_CONTENT)
|
|
533
|
+
.optional()
|
|
534
|
+
.describe('The full new prompt text (a new version). Omit to leave the text and versions untouched'),
|
|
535
|
+
description: zod_1.z
|
|
536
|
+
.string()
|
|
537
|
+
.max(writeGuard_1.MAX_DESCRIPTION)
|
|
538
|
+
.optional()
|
|
539
|
+
.describe("One-line description. Omit to leave it unchanged; given (even '') it overwrites"),
|
|
540
|
+
tags: zod_1.z
|
|
541
|
+
.array(zod_1.z.string().min(1).max(writeGuard_1.MAX_TAG_LENGTH))
|
|
542
|
+
.max(writeGuard_1.MAX_TAGS)
|
|
543
|
+
.optional()
|
|
544
|
+
.describe('Tags to ADD (add-only: tags already on the prompt, or not listed, are never removed; [] changes nothing). Omit to leave tags unchanged'),
|
|
545
|
+
changelog: zod_1.z.string().max(500).optional().describe('What changed in the new version, one line (only with content)'),
|
|
546
|
+
bump: zod_1.z.enum(['patch', 'minor', 'major']).optional().describe('Semver bump of the new version (default patch; only with content)'),
|
|
516
547
|
project: zod_1.z.string().min(1).optional().describe('Repo name, slug, or id when titles collide'),
|
|
517
548
|
},
|
|
518
549
|
annotations: WRITE,
|
|
519
550
|
}, async (args) => guarded(async () => {
|
|
520
551
|
const outcome = await (0, writeTools_1.updatePromptFlow)(args);
|
|
521
|
-
|
|
552
|
+
// A partly failed call can still have saved a version or changed metadata: refresh the catalog then too.
|
|
553
|
+
const status = outcome.ok ? outcome.payload.status : outcome.payload?.status;
|
|
554
|
+
if (status === 'updated' || status === 'metadata_updated')
|
|
522
555
|
afterWrite(server, catalog);
|
|
523
556
|
return fromOutcome(outcome);
|
|
524
557
|
}));
|
|
558
|
+
server.registerTool('submit_feedback', {
|
|
559
|
+
title: 'Send feedback to the PromptLikeEngineer maker',
|
|
560
|
+
description: 'Call this when a PromptLikeEngineer tool is missing, broken, confusing or returned a wrong result, ' +
|
|
561
|
+
'or when a saved prompt did not work. One short factual sentence is enough. ' +
|
|
562
|
+
'Never include prompt bodies, secrets or personal data. ' +
|
|
563
|
+
'Works without a signed-in session. A call with a key or token in the message is refused. ' +
|
|
564
|
+
'Errors come back as JSON with `code` and `retryable`; do not retry in a loop.',
|
|
565
|
+
inputSchema: {
|
|
566
|
+
type: zod_1.z
|
|
567
|
+
.enum(feedback_1.FEEDBACK_TYPES)
|
|
568
|
+
.optional()
|
|
569
|
+
.describe("bug = something broke or answered wrong, missing = a tool or option is absent, idea = a suggestion, prompt = a saved prompt did not work (default 'idea')"),
|
|
570
|
+
message: zod_1.z.string().min(1).max(feedback_1.MAX_FEEDBACK_MESSAGE).describe('What happened or what is missing, as one short factual sentence'),
|
|
571
|
+
prompt: zod_1.z
|
|
572
|
+
.string()
|
|
573
|
+
.min(1)
|
|
574
|
+
.max(feedback_1.MAX_FEEDBACK_PROMPT_REF)
|
|
575
|
+
.optional()
|
|
576
|
+
.describe('Title or id of the prompt this is about (never its text)'),
|
|
577
|
+
email: zod_1.z.string().max(254).optional().describe('Where the maker can answer, only if the user wants a reply'),
|
|
578
|
+
},
|
|
579
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true },
|
|
580
|
+
}, async (args) => {
|
|
581
|
+
try {
|
|
582
|
+
return fromFeedback(await (0, feedback_1.submitFeedbackFlow)(args, { clientName: server.server.getClientVersion()?.name }));
|
|
583
|
+
}
|
|
584
|
+
catch {
|
|
585
|
+
return fail('Unexpected error.'); // submitFeedbackFlow does not throw; this is only a backstop
|
|
586
|
+
}
|
|
587
|
+
});
|
|
525
588
|
registerPromptLibrary(server, catalog);
|
|
526
589
|
registerResources(server, catalog);
|
|
527
590
|
return server;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "promptlike-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"mcpName": "io.github.zeynepaslierhan/promptlike-mcp",
|
|
5
5
|
"description": "MCP server for PromptLikeEngineer - your prompt library as MCP tools, slash-command prompts and @-resources: list, search, get, fill {{variables}}, suggest, and save new prompts/versions (add-only).",
|
|
6
6
|
"bin": {
|