promptlike 0.13.2 → 0.15.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 +22 -0
- package/README.md +34 -6
- package/dist/commands/export.js +32 -4
- package/dist/commands/fork.js +111 -0
- package/dist/commands/importPle.js +3 -4
- package/dist/commands/rename.js +61 -0
- package/dist/commands/repo.js +43 -0
- package/dist/commands/save.js +10 -0
- package/dist/commands/suggest.js +3 -3
- package/dist/commands/sync.js +19 -1
- package/dist/help.js +1 -1
- package/dist/lib/agentExport.js +2 -2
- package/dist/lib/api-client.js +22 -3
- package/dist/lib/format.js +4 -14
- package/dist/lib/loopApi.js +27 -5
- package/dist/lib/obsidianExport.js +167 -0
- package/dist/lib/promptParts.js +16 -0
- package/dist/lib/promptResolver.js +6 -7
- package/dist/lib/repoRef.js +3 -4
- package/dist/lib/secretGuard.js +47 -9
- package/dist/lib/uuid.js +5 -0
- package/dist/program.js +45 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.15.0 — 2026-11-30
|
|
4
|
+
|
|
5
|
+
- **New: `ple export --format obsidian`** writes your prompts as linked Obsidian notes, so Obsidian's graph view draws your prompt
|
|
6
|
+
chains. `ple export --project <repo> --format obsidian --out <folder>` creates `<folder>/<repo>-obsidian/`: one note per prompt, the
|
|
7
|
+
prompts it suggests next as `[[links]]` under **Next**, and each context type it needs as a link to a `context/<type>` hub note,
|
|
8
|
+
plus one map note for the repo. Only the type and name of a context slot are written, never its hint or a value. Open the folder
|
|
9
|
+
in Obsidian or copy it into your vault; `--force` overwrites an earlier export (never through a symbolic link). `--zip` is refused
|
|
10
|
+
for this format.
|
|
11
|
+
|
|
12
|
+
## 0.14.0 — 2026-11-27
|
|
13
|
+
|
|
14
|
+
- **New: `ple fork <id|ple:user/repo/prompt> [--project <repo>] [--title <t>] [--json]`** copies a public prompt of someone else into a repo you own (the web's Fork button). The copy starts private and keeps its source and license. Forking twice is reported, not an error; your own prompts, private prompts, repos you do not own and a plan limit are refused with a plain message.
|
|
15
|
+
- **`ple save` refuses text that looks like a secret** (API key, token, private key), in the title, description or body, signed in or
|
|
16
|
+
out. Nothing is written; the error names the kind, never the value. Replace the value with a `{{variable}}`.
|
|
17
|
+
- **`ple sync` keeps such a prompt local** and names it by slug; the rest upload. Exit code 1 when anything was held back.
|
|
18
|
+
- **The secret check knows more shapes:** Supabase keys, npm tokens, SendGrid keys, Stripe webhook secrets, Vercel Blob tokens, an AWS secret key next to its variable name, an `Authorization: Bearer` header and a URL with a password in it. A key that follows `_` (as in `KEY_sk-…`) is caught too.
|
|
19
|
+
- **New: `ple rename <name> <new-title> [--project <repo>] [--json]`** changes a prompt's title. Its id, URL, versions, labels, stars, usage and tags stay. A title another prompt in the same repo already has stops the rename before anything is written.
|
|
20
|
+
- **New: `ple repo edit <repo> --description <text> [--json]`** overwrites a repo's one-line description (`""` clears it; owner or admin). Nothing else about the repo changes.
|
|
21
|
+
- **A read that times out is tried once more.** In a loop of `ple log --json` calls, some reads hung for the full 15 seconds while the next one answered at once. Writes are never repeated.
|
|
22
|
+
- **Exit code 2 (try again later) on a network error, a timeout, a rate limit or a server error**, for every command that reaches your account through the same request path: `ple improve`, `ple loop`, `ple move`, `ple untag`, a signed-in `ple save`, `ple import` (and `--check`), and the folder views of `ple list` and `ple export`. They used to exit 1 in those cases.
|
|
23
|
+
- **`ple export` no longer lists `{{else}}` as a variable.** It is the else branch of an `{{#if}}` block, not a name to fill.
|
|
24
|
+
|
|
3
25
|
## 0.13.2 — 2026-11-02
|
|
4
26
|
|
|
5
27
|
- **The hook note no longer invites fetching a prompt.** It now says a suggestion is not a go-ahead: name the prompt, ask the user, and
|
package/README.md
CHANGED
|
@@ -19,10 +19,10 @@ Prompts live as plain Markdown files in `~/.promptlike/prompts/` — greppable,
|
|
|
19
19
|
diffable, and yours. Your prompts stay on your machine until you ask it to
|
|
20
20
|
upload them.
|
|
21
21
|
|
|
22
|
-
**Signing in is the upgrade, not the door.**
|
|
23
|
-
[promptlikeengineer.com](https://promptlikeengineer.com) account
|
|
24
|
-
|
|
25
|
-
the
|
|
22
|
+
**Signing in is the upgrade, not the door.** Local version history works without
|
|
23
|
+
an account. A free [promptlikeengineer.com](https://promptlikeengineer.com) account
|
|
24
|
+
adds the web editor, sharing, and the same library in Claude Code and other MCP clients.
|
|
25
|
+
History in the account has diff and rollback too (Free holds up to 10 versions of each prompt; the 11th save asks you to upgrade).
|
|
26
26
|
Bring your local prompts up with one explicit command:
|
|
27
27
|
|
|
28
28
|
```bash
|
|
@@ -104,6 +104,9 @@ not repeat are carried over rather than wiped. Every save that changes the text
|
|
|
104
104
|
also adds a version to a local, append-only history (see
|
|
105
105
|
[Local version history](#local-version-history-signed-out)).
|
|
106
106
|
|
|
107
|
+
Text that looks like a secret (API key, token, private key) is refused, signed in or out: nothing is written and the
|
|
108
|
+
error names the kind, never the value. Use a `{{variable}}` instead.
|
|
109
|
+
|
|
107
110
|
### `ple save <title> --project <repo>` — straight into your account, safe to run again
|
|
108
111
|
|
|
109
112
|
Signed in, `--project` (a repo name, slug, id or short id) saves into that repo of your account instead
|
|
@@ -138,8 +141,9 @@ One-way (local → account) and it *copies*: your local files stay where they
|
|
|
138
141
|
are. Running it again is safe: every prompt is sent with a fingerprint of its
|
|
139
142
|
text, and text your account already has is skipped ("N already in your account —
|
|
140
143
|
skipped"). A prompt you edited since is a different text and is uploaded as a new
|
|
141
|
-
prompt — sync adds, it does not update. A prompt
|
|
142
|
-
|
|
144
|
+
prompt — sync adds, it does not update. A prompt that looks like it holds a secret
|
|
145
|
+
stays local: it is named by slug, the rest upload, and the exit code is 1. A prompt
|
|
146
|
+
imported from GitHub keeps its source (see [Import from GitHub](#import-from-github)). `--project <repo>` (a name,
|
|
143
147
|
slug, id or the short id `ple repo list` prints) uploads into that repo instead of
|
|
144
148
|
the default one, and a name that matches nothing stops the command before anything
|
|
145
149
|
is sent. `--dry-run` prints the list (and the repo name, which is only looked up
|
|
@@ -246,6 +250,7 @@ $ ple repo visibility team-prompts public # asks first; --yes in scripts
|
|
|
246
250
|
| `ple repo list [--json]` | Every repo you own or belong to: visibility, your role, prompt count. |
|
|
247
251
|
| `ple repo show <repo> [--json]` | One repo. `<repo>` = name, slug, id, or the 8-character id from `ple repo list`. |
|
|
248
252
|
| `ple repo visibility <repo> private\|public [--yes] [--json]` | Owner only. Going public asks for confirmation (a script must pass `--yes`); going private never asks. |
|
|
253
|
+
| `ple repo edit <repo> --description <text> [--json]` | Owner or admin. Overwrites the repo's one-line description (max 500 characters; `--description ""` clears it). Nothing else about the repo changes; `--json` returns `previous_description`. |
|
|
249
254
|
| `ple repo license <repo> CC-BY-4.0\|CC-BY-SA-4.0\|CC0-1.0\|MIT\|Apache-2.0\|none [--json]` | Owner only. Declares how the repo's prompts may be reused; shown on the public repo page. `none` clears it. A repo with no license is shown as "none declared", never as free to use. |
|
|
250
255
|
|
|
251
256
|
The server enforces the rules, not just the CLI: you must be signed in, Free
|
|
@@ -666,6 +671,29 @@ CLI 0.13.1+, signed in, editor access. Names ignore case. The prompt, its versio
|
|
|
666
671
|
version is made (tags are not part of a version). A name the prompt does not have is reported and exits 1. Deploy labels
|
|
667
672
|
are a different thing: `ple tag --remove`. The MCP tools cannot remove a tag, so an agent connected over MCP cannot either.
|
|
668
673
|
|
|
674
|
+
### `ple fork <source>` — copy a public prompt into your repo
|
|
675
|
+
|
|
676
|
+
```bash
|
|
677
|
+
ple fork ple:zeynepaslierhan/ortak-web/Code\ Review --project my-prompts
|
|
678
|
+
ple fork 3f2a9c1e-0000-0000-0000-000000000000 --title "Review (mine)" --json
|
|
679
|
+
```
|
|
680
|
+
|
|
681
|
+
Signed in only. `<source>` is the prompt's full id, or `ple:<user>/<repo>/<title or 8+ hex id characters>` (looked up on the
|
|
682
|
+
public pages; an ambiguous match lists the ids). The copy goes into a repo you **own**: `--project <repo>`, or your only
|
|
683
|
+
repo when you have just one. It starts **private** and keeps its source, the version it was read at and the repo's license
|
|
684
|
+
in its first version's changelog; the original is not touched. A prompt forks once per account: a second try prints your
|
|
685
|
+
existing copy and exits 0. Refused with a plain message: your own prompt, a prompt that is not public, a repo you do not
|
|
686
|
+
own, and a plan prompt limit (with the upgrade link). The same as the Fork button on the web.
|
|
687
|
+
|
|
688
|
+
### `ple rename <name> <new-title>` — change a prompt's title
|
|
689
|
+
|
|
690
|
+
```bash
|
|
691
|
+
ple rename "code review" "Code review (backend)"
|
|
692
|
+
ple rename "code review" "Code review v2" --project team-prompts --json
|
|
693
|
+
```
|
|
694
|
+
|
|
695
|
+
Only the title changes: the prompt keeps its id, the URL slug behind its public link, every version, labels, stars, usage and tags. A title another prompt in the same repo already has stops the rename; rename it back to undo. Needs an account.
|
|
696
|
+
|
|
669
697
|
### `ple move <name>` — to another repo, or into a folder
|
|
670
698
|
|
|
671
699
|
```bash
|
package/dist/commands/export.js
CHANGED
|
@@ -45,14 +45,16 @@ const folder_1 = require("../lib/folder");
|
|
|
45
45
|
const promptList_1 = require("../lib/promptList");
|
|
46
46
|
const fsSafe_1 = require("../lib/fsSafe");
|
|
47
47
|
const agentExport_1 = require("../lib/agentExport");
|
|
48
|
+
const obsidianExport_1 = require("../lib/obsidianExport");
|
|
48
49
|
/** Hard cap for a repo export — 10 pages × 100. */
|
|
49
50
|
const MAX_PAGES = 10;
|
|
50
51
|
const PAGE_SIZE = 100;
|
|
52
|
+
const EXPORT_FORMATS = [...agentExport_1.AGENT_EXPORT_FORMATS, 'obsidian'];
|
|
51
53
|
function parseFormat(value) {
|
|
52
54
|
const v = (value ?? '').trim().toLowerCase();
|
|
53
|
-
if (
|
|
55
|
+
if (EXPORT_FORMATS.includes(v))
|
|
54
56
|
return v;
|
|
55
|
-
throw new Error(`--format must be one of: ${
|
|
57
|
+
throw new Error(`--format must be one of: ${EXPORT_FORMATS.join(', ')}.`);
|
|
56
58
|
}
|
|
57
59
|
function fromRemote(p) {
|
|
58
60
|
const v = (0, promptResolver_1.fetchPromptContent)(p);
|
|
@@ -61,12 +63,12 @@ function fromRemote(p) {
|
|
|
61
63
|
: '';
|
|
62
64
|
if (!body.trim())
|
|
63
65
|
return null;
|
|
64
|
-
return { title: p.title, description: p.description ?? null, body, projectName: p.project_name ?? null };
|
|
66
|
+
return { id: p.id, title: p.title, description: p.description ?? null, body, projectName: p.project_name ?? null };
|
|
65
67
|
}
|
|
66
68
|
function fromLocal(p) {
|
|
67
69
|
if (!p.body.trim())
|
|
68
70
|
return null;
|
|
69
|
-
return { title: p.title, description: p.description || null, body: p.body.trim() };
|
|
71
|
+
return { id: p.slug, title: p.title, description: p.description || null, body: p.body.trim() };
|
|
70
72
|
}
|
|
71
73
|
async function collectRemoteRepo(projectId, folder) {
|
|
72
74
|
const out = [];
|
|
@@ -119,6 +121,22 @@ function writeSkill(skill, options) {
|
|
|
119
121
|
}
|
|
120
122
|
return folder;
|
|
121
123
|
}
|
|
124
|
+
/** obsidian: `<out>/<repo>-obsidian/` içine notlar (kasanın içine kopyalanır ya da kasa olarak açılır). */
|
|
125
|
+
function writeObsidian(name, files, options) {
|
|
126
|
+
const parent = path.resolve(options.out ?? '.');
|
|
127
|
+
fs.mkdirSync(parent, { recursive: true });
|
|
128
|
+
const folder = path.join(parent, `${(0, obsidianExport_1.noteName)(name, 'prompts')}-obsidian`);
|
|
129
|
+
assertInside(parent, folder);
|
|
130
|
+
ensureWritable(folder, options.force);
|
|
131
|
+
for (const f of files) {
|
|
132
|
+
const target = path.join(folder, ...f.path.split('/'));
|
|
133
|
+
assertInside(folder, target);
|
|
134
|
+
(0, fsSafe_1.assertNotSymlink)(target);
|
|
135
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
136
|
+
fs.writeFileSync(target, f.content, 'utf-8');
|
|
137
|
+
}
|
|
138
|
+
return folder;
|
|
139
|
+
}
|
|
122
140
|
function writeAgentsMd(text, options) {
|
|
123
141
|
if (!options.out) {
|
|
124
142
|
process.stdout.write(text);
|
|
@@ -202,6 +220,16 @@ async function exportCommand(name, options = {}) {
|
|
|
202
220
|
throw new Error('Give a prompt name, or --project <repo> to export a whole repo.');
|
|
203
221
|
}
|
|
204
222
|
}
|
|
223
|
+
if (format === 'obsidian') {
|
|
224
|
+
const name = repo ? repo.name : (single?.projectName ?? 'prompts');
|
|
225
|
+
const prompts = repo ? repo.prompts : single ? [single] : [];
|
|
226
|
+
if (prompts.length === 0) {
|
|
227
|
+
throw new Error(folder !== undefined ? `Nothing to export — no prompts with content in folder '${folder || '(root)'}'.` : 'Nothing to export — no prompts with content.');
|
|
228
|
+
}
|
|
229
|
+
const written = writeObsidian(name, (0, obsidianExport_1.buildObsidianVault)(name, prompts, exportedAt), options);
|
|
230
|
+
console.error(format_1.c.success(`✓ Exported ${prompts.length} prompt${prompts.length === 1 ? '' : 's'} as Obsidian notes → ${written}`));
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
205
233
|
let text = null;
|
|
206
234
|
let skill = null;
|
|
207
235
|
let count = 1;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* `ple fork <id|ple:user/repo/prompt> [--project <repo>] [--title <t>] [--json]` — copy a PUBLIC prompt of someone
|
|
4
|
+
* else into one of YOUR repos (the CLI side of the web's Fork button).
|
|
5
|
+
*
|
|
6
|
+
* The copy starts private and keeps its source (user, repo, prompt id, version read, license) in its first version's
|
|
7
|
+
* changelog. A prompt can be forked once per account: a second try points at the existing copy. Without `--project`
|
|
8
|
+
* the copy goes into your only repo; with several repos you must pick one (forks need a repo you OWN).
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.FORK_SOURCE_HELP = void 0;
|
|
12
|
+
exports.resolveForkSource = resolveForkSource;
|
|
13
|
+
exports.forkCommand = forkCommand;
|
|
14
|
+
const api_client_1 = require("../lib/api-client");
|
|
15
|
+
const format_1 = require("../lib/format");
|
|
16
|
+
const loopApi_1 = require("../lib/loopApi");
|
|
17
|
+
const pleSpec_1 = require("../lib/pleSpec");
|
|
18
|
+
const promptResolver_1 = require("../lib/promptResolver");
|
|
19
|
+
const publicApi_1 = require("../lib/publicApi");
|
|
20
|
+
const uuid_1 = require("../lib/uuid");
|
|
21
|
+
const importPle_1 = require("./importPle");
|
|
22
|
+
const local_1 = require("./local");
|
|
23
|
+
const MAX_TITLE = 200;
|
|
24
|
+
exports.FORK_SOURCE_HELP = 'Give the prompt as its full id, or as ple:<user>/<repo>/<prompt> (title or 8+ hex id characters).';
|
|
25
|
+
/** Source argument → the public prompt's full id (a ple: reference is looked up on the public pages). */
|
|
26
|
+
async function resolveForkSource(source) {
|
|
27
|
+
const value = source.trim();
|
|
28
|
+
if (uuid_1.UUID_RE.test(value))
|
|
29
|
+
return value.toLowerCase();
|
|
30
|
+
if (!(0, pleSpec_1.isPleSource)(value))
|
|
31
|
+
throw new Error(exports.FORK_SOURCE_HELP);
|
|
32
|
+
const spec = (0, pleSpec_1.parsePleSpec)(value);
|
|
33
|
+
if (!spec.prompt)
|
|
34
|
+
throw new Error(`Name the prompt too: ple:${spec.owner}/${spec.repo}/<title or id>. To copy a whole repo use: ple import ple:${spec.owner}/${spec.repo}`);
|
|
35
|
+
const where = `ple:${spec.owner}/${spec.repo}`;
|
|
36
|
+
const cards = await (0, publicApi_1.listPublicRepoPrompts)(spec.owner, spec.repo);
|
|
37
|
+
if (cards.length === 0)
|
|
38
|
+
throw new Error(`No public prompts found in ${where}. The repo and its prompts must both be public.`);
|
|
39
|
+
const rows = (0, importPle_1.pickByRef)(cards, spec.prompt);
|
|
40
|
+
if (rows.length === 0)
|
|
41
|
+
throw new Error(`No prompt matched '${(0, format_1.safeText)(spec.prompt)}' in ${where}.`);
|
|
42
|
+
if (rows.length > 1) {
|
|
43
|
+
const list = rows.map((k) => `${k.id.slice(0, 8)} ${(0, format_1.truncate)(k.title, 40)}`).join(', ');
|
|
44
|
+
throw new Error(`'${(0, format_1.safeText)(spec.prompt)}' matched ${rows.length} prompts in ${where} (${list}). Use the id.`);
|
|
45
|
+
}
|
|
46
|
+
return rows[0].id;
|
|
47
|
+
}
|
|
48
|
+
/** The repo the copy goes into: the named one, else your only owned repo. Forks need a repo you own. */
|
|
49
|
+
async function pickTarget(project) {
|
|
50
|
+
const repos = await (0, api_client_1.listProjectsDetailed)();
|
|
51
|
+
if (project !== undefined) {
|
|
52
|
+
const ref = await (0, promptResolver_1.resolveProject)(project);
|
|
53
|
+
const found = repos.find((r) => r.id === ref.id);
|
|
54
|
+
if (!found)
|
|
55
|
+
throw new Error(`No repo matched '${project}'. Run 'ple repo list' and use the repo's exact name, slug, or id.`);
|
|
56
|
+
if (found.role !== 'owner') {
|
|
57
|
+
throw new Error(`You have '${found.role}' access to '${found.name}' — a fork must go into a repo you own. Pick one of yours: ple repo list`);
|
|
58
|
+
}
|
|
59
|
+
return found;
|
|
60
|
+
}
|
|
61
|
+
const owned = repos.filter((r) => r.role === 'owner');
|
|
62
|
+
if (owned.length === 0)
|
|
63
|
+
throw new Error('You own no repo to fork into. Create one first: ple repo create <name>');
|
|
64
|
+
if (owned.length > 1) {
|
|
65
|
+
const names = owned.slice(0, 8).map((r) => r.name).join(', ');
|
|
66
|
+
throw new Error(`You own ${owned.length} repos (${names}). Say which one: ple fork <source> --project <repo>`);
|
|
67
|
+
}
|
|
68
|
+
return owned[0];
|
|
69
|
+
}
|
|
70
|
+
async function forkCommand(source, options = {}) {
|
|
71
|
+
const title = options.title?.replace(/\s+/g, ' ').trim();
|
|
72
|
+
if (options.title !== undefined && !title)
|
|
73
|
+
throw new Error('--title is empty.');
|
|
74
|
+
if (title && title.length > MAX_TITLE)
|
|
75
|
+
throw new Error(`--title is too long (${title.length} chars, max ${MAX_TITLE}).`);
|
|
76
|
+
if ((0, local_1.isSignedOut)()) {
|
|
77
|
+
throw new Error('Forking needs an account (the copy is saved into one of your repos). Sign in first: ple login');
|
|
78
|
+
}
|
|
79
|
+
const promptId = await resolveForkSource(source);
|
|
80
|
+
await (0, api_client_1.ensureAuthed)();
|
|
81
|
+
const target = await pickTarget(options.project);
|
|
82
|
+
try {
|
|
83
|
+
const res = await (0, loopApi_1.forkPrompt)(promptId, { targetProjectId: target.id, title });
|
|
84
|
+
if (options.json) {
|
|
85
|
+
console.log(JSON.stringify({ ok: true, forked: true, id: res.forkedPromptId, repo: target.name, repo_id: res.forkedProjectId, source_id: promptId }));
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
console.log(format_1.c.success(`✓ Forked into '${target.name}'`) + format_1.c.muted(` (${(0, format_1.shortId)(res.forkedPromptId)}, private)`));
|
|
89
|
+
console.log(format_1.c.muted(` Its source and license are in the first version's changelog. Open it: ple show ${(0, format_1.shortId)(res.forkedPromptId)}`));
|
|
90
|
+
}
|
|
91
|
+
catch (err) {
|
|
92
|
+
const e = err;
|
|
93
|
+
if (e?.code === 'ALREADY_FORKED') {
|
|
94
|
+
const existing = typeof e.details?.forkedPromptId === 'string' ? e.details.forkedPromptId : null;
|
|
95
|
+
if (options.json) {
|
|
96
|
+
console.log(JSON.stringify({ ok: true, forked: false, already_forked: true, id: existing, source_id: promptId }));
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
console.log(format_1.c.muted(`You already forked this prompt${existing ? ` — your copy is ${(0, format_1.shortId)(existing)}` : ''}. Nothing was copied.`));
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (e?.code === 'PROMPT_NOT_FOUND') {
|
|
103
|
+
throw new Error('That prompt was not found. Only prompts in a public repo that are themselves public can be forked.');
|
|
104
|
+
}
|
|
105
|
+
if (e?.code === 'CANNOT_FORK_OWN')
|
|
106
|
+
throw new Error('That is your own prompt — there is nothing to fork. Duplicate it with `ple save` instead.');
|
|
107
|
+
if (e?.code === 'NOTHING_TO_FORK')
|
|
108
|
+
throw new Error('That prompt has no saved content yet, so there is nothing to copy.');
|
|
109
|
+
throw err;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -63,6 +63,7 @@ const publicApi_1 = require("../lib/publicApi");
|
|
|
63
63
|
const scanners_1 = require("../lib/scanners");
|
|
64
64
|
const secretGuard_1 = require("../lib/secretGuard");
|
|
65
65
|
const titleMatch_1 = require("../lib/titleMatch");
|
|
66
|
+
const uuid_1 = require("../lib/uuid");
|
|
66
67
|
const local_1 = require("./local");
|
|
67
68
|
const LICENSE_NAMES = {
|
|
68
69
|
'CC-BY-4.0': 'CC BY 4.0',
|
|
@@ -71,14 +72,12 @@ const LICENSE_NAMES = {
|
|
|
71
72
|
MIT: 'MIT',
|
|
72
73
|
'Apache-2.0': 'Apache 2.0',
|
|
73
74
|
};
|
|
74
|
-
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
75
|
-
const SHORT_ID_RE = /^[0-9a-f]{8,}$/i;
|
|
76
75
|
/** The prompts a `<prompt>` argument names: an id (full or 8+ hex prefix), else exact title, else part of a title. */
|
|
77
76
|
function pickByRef(cards, ref) {
|
|
78
77
|
const r = ref.trim();
|
|
79
|
-
if (UUID_RE.test(r))
|
|
78
|
+
if (uuid_1.UUID_RE.test(r))
|
|
80
79
|
return cards.filter((k) => k.id.toLowerCase() === r.toLowerCase());
|
|
81
|
-
if (SHORT_ID_RE.test(r)) {
|
|
80
|
+
if (uuid_1.SHORT_ID_RE.test(r)) {
|
|
82
81
|
const byId = cards.filter((k) => k.id.toLowerCase().startsWith(r.toLowerCase()));
|
|
83
82
|
if (byId.length > 0)
|
|
84
83
|
return byId;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* `ple rename <name|id> <new title> [--project <repo>] [--json]` — change a prompt's title.
|
|
4
|
+
*
|
|
5
|
+
* Only the title changes: the prompt keeps its id (so `/p/<id>` still opens), the slug behind its public URL,
|
|
6
|
+
* every version, its deploy labels, stars, usage and tags. A title another prompt in the same repo already has
|
|
7
|
+
* stops the rename before anything is written (a title is how `ple save --project` finds a prompt).
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.cleanNewTitle = cleanNewTitle;
|
|
11
|
+
exports.renameCommand = renameCommand;
|
|
12
|
+
const api_client_1 = require("../lib/api-client");
|
|
13
|
+
const format_1 = require("../lib/format");
|
|
14
|
+
const loopApi_1 = require("../lib/loopApi");
|
|
15
|
+
const promptResolver_1 = require("../lib/promptResolver");
|
|
16
|
+
const secretGuard_1 = require("../lib/secretGuard");
|
|
17
|
+
const local_1 = require("./local");
|
|
18
|
+
const MAX_TITLE = 200;
|
|
19
|
+
/** One line: control characters and line breaks collapse to spaces, like the title `ple save` stores. */
|
|
20
|
+
function cleanNewTitle(raw) {
|
|
21
|
+
return raw.replace(/[\u0000-\u001f\u007f]+/g, ' ').replace(/\s{2,}/g, ' ').trim();
|
|
22
|
+
}
|
|
23
|
+
async function renameCommand(name, newTitle, options = {}) {
|
|
24
|
+
const title = cleanNewTitle(newTitle);
|
|
25
|
+
if (!title)
|
|
26
|
+
throw new Error('The new title is empty.');
|
|
27
|
+
if (title.length > MAX_TITLE)
|
|
28
|
+
throw new Error(`The new title is too long (${title.length} chars, max ${MAX_TITLE}).`);
|
|
29
|
+
const secret = (0, secretGuard_1.findSecret)(newTitle);
|
|
30
|
+
if (secret)
|
|
31
|
+
throw new Error(`Not renamed: the new title looks like it contains a ${secret}.`);
|
|
32
|
+
if ((0, local_1.isSignedOut)()) {
|
|
33
|
+
throw new Error('Renaming needs an account (it changes a saved prompt). Sign in first: ple login');
|
|
34
|
+
}
|
|
35
|
+
await (0, api_client_1.ensureAuthed)();
|
|
36
|
+
const projectId = options.project ? await (0, promptResolver_1.resolveProjectId)(options.project) : undefined;
|
|
37
|
+
const prompt = await (0, promptResolver_1.resolvePromptByName)(name, { projectId });
|
|
38
|
+
if (!prompt) {
|
|
39
|
+
process.exitCode = 1;
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (prompt.title === title) {
|
|
43
|
+
if (options.json)
|
|
44
|
+
console.log(JSON.stringify({ ok: true, changed: false, id: prompt.id, title }));
|
|
45
|
+
else
|
|
46
|
+
console.log(format_1.c.muted(`'${prompt.title}' already has that title. Nothing changed.`));
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const sameRepo = await (0, api_client_1.listPrompts)({ search: title, limit: 100, projectId: prompt.project_id ?? projectId });
|
|
50
|
+
const clash = sameRepo.find((p) => p.id !== prompt.id && p.title.trim().toLowerCase() === title.toLowerCase());
|
|
51
|
+
if (clash) {
|
|
52
|
+
throw new Error(`A prompt titled '${clash.title}' (${(0, format_1.shortId)(clash.id)}) already exists in this repo. Pick another title; nothing was changed.`);
|
|
53
|
+
}
|
|
54
|
+
await (0, loopApi_1.patchTitle)(prompt.id, title);
|
|
55
|
+
if (options.json) {
|
|
56
|
+
console.log(JSON.stringify({ ok: true, changed: true, id: prompt.id, title, previous_title: prompt.title }));
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
console.log(format_1.c.success(`✓ Renamed '${prompt.title}' to '${title}'`) + format_1.c.muted(` (${(0, format_1.shortId)(prompt.id)})`));
|
|
60
|
+
console.log(format_1.c.muted(` Its link, versions, labels and tags are unchanged. Undo: ple rename "${title}" "${prompt.title}"`));
|
|
61
|
+
}
|
package/dist/commands/repo.js
CHANGED
|
@@ -21,6 +21,7 @@ exports.repoCreateCommand = repoCreateCommand;
|
|
|
21
21
|
exports.repoListCommand = repoListCommand;
|
|
22
22
|
exports.repoShowCommand = repoShowCommand;
|
|
23
23
|
exports.repoVisibilityCommand = repoVisibilityCommand;
|
|
24
|
+
exports.repoEditCommand = repoEditCommand;
|
|
24
25
|
exports.parseLicense = parseLicense;
|
|
25
26
|
exports.repoLicenseCommand = repoLicenseCommand;
|
|
26
27
|
const api_client_1 = require("../lib/api-client");
|
|
@@ -28,6 +29,7 @@ const confirm_1 = require("../lib/confirm");
|
|
|
28
29
|
const format_1 = require("../lib/format");
|
|
29
30
|
const local_1 = require("./local");
|
|
30
31
|
const constants_1 = require("../lib/constants");
|
|
32
|
+
const secretGuard_1 = require("../lib/secretGuard");
|
|
31
33
|
const repoRef_1 = require("../lib/repoRef");
|
|
32
34
|
const SIGN_IN_FIRST = 'Repos live in your account. Sign in first: ple login';
|
|
33
35
|
function toRepoJson(r) {
|
|
@@ -175,6 +177,47 @@ async function repoVisibilityCommand(ref, value, options = {}, deps = {}) {
|
|
|
175
177
|
}
|
|
176
178
|
console.log(format_1.c.success(`✓ '${repo.name}' is now ${target}.`));
|
|
177
179
|
}
|
|
180
|
+
/**
|
|
181
|
+
* `ple repo edit <repo> --description <text>` — overwrite the repo's one-line description (`""` clears it).
|
|
182
|
+
* Nothing else about the repo moves. The server needs admin or owner.
|
|
183
|
+
*/
|
|
184
|
+
async function repoEditCommand(ref, options = {}) {
|
|
185
|
+
if (options.description === undefined) {
|
|
186
|
+
throw new Error('Nothing to change. Pass --description <text> (or --description "" to clear it).');
|
|
187
|
+
}
|
|
188
|
+
// Local checks first: no network, no session needed to learn the text is wrong.
|
|
189
|
+
const description = (0, repoRef_1.validateRepoDescription)(options.description) ?? '';
|
|
190
|
+
const secret = (0, secretGuard_1.findSecret)(options.description);
|
|
191
|
+
if (secret)
|
|
192
|
+
throw new Error(`Not changed: the description looks like it contains a ${secret}.`);
|
|
193
|
+
requireAccount();
|
|
194
|
+
await (0, api_client_1.ensureAuthed)();
|
|
195
|
+
const repo = (0, repoRef_1.resolveRepoRef)(ref, await (0, api_client_1.listProjectsDetailed)());
|
|
196
|
+
if (repo.role !== 'owner' && repo.role !== 'admin') {
|
|
197
|
+
throw new Error(`Only an owner or admin can change a repo's description (your role in '${repo.name}': ${repo.role}).`);
|
|
198
|
+
}
|
|
199
|
+
const before = repo.description ?? '';
|
|
200
|
+
if (before === description) {
|
|
201
|
+
if (options.json)
|
|
202
|
+
console.log(JSON.stringify({ ok: true, changed: false, repo: toRepoJson(repo) }, null, 2));
|
|
203
|
+
else
|
|
204
|
+
console.log(format_1.c.muted(`'${repo.name}' already has that description. Nothing changed.`));
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
try {
|
|
208
|
+
await (0, api_client_1.setProjectDescription)(repo.id, description);
|
|
209
|
+
}
|
|
210
|
+
catch (err) {
|
|
211
|
+
explainRepoError(err);
|
|
212
|
+
}
|
|
213
|
+
if (options.json) {
|
|
214
|
+
console.log(JSON.stringify({ ok: true, changed: true, previous_description: before || null, repo: toRepoJson({ ...repo, description: description || null }) }, null, 2));
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
console.log(format_1.c.success(description ? `✓ '${repo.name}' description updated.` : `✓ '${repo.name}' description cleared.`));
|
|
218
|
+
if (before)
|
|
219
|
+
console.log(format_1.c.muted(` Before: ${(0, format_1.truncate)(before, 120)}`));
|
|
220
|
+
}
|
|
178
221
|
// ---------------------------------------------------------------------------
|
|
179
222
|
/** Same list as the server (src/lib/repo-license.ts) and its database CHECK; the server stays the authority. */
|
|
180
223
|
exports.REPO_LICENSES = ['CC-BY-4.0', 'CC-BY-SA-4.0', 'CC0-1.0', 'MIT', 'Apache-2.0'];
|
package/dist/commands/save.js
CHANGED
|
@@ -57,6 +57,7 @@ const folder_1 = require("../lib/folder");
|
|
|
57
57
|
const accountSave_1 = require("../lib/accountSave");
|
|
58
58
|
const promptResolver_1 = require("../lib/promptResolver");
|
|
59
59
|
const libraryCache_1 = require("../lib/libraryCache");
|
|
60
|
+
const secretGuard_1 = require("../lib/secretGuard");
|
|
60
61
|
const local_1 = require("./local");
|
|
61
62
|
/**
|
|
62
63
|
* Same caps the web API enforces (title 200 / body 100K / description 1000).
|
|
@@ -127,6 +128,15 @@ async function saveCommand(title, options = {}) {
|
|
|
127
128
|
process.exitCode = 1;
|
|
128
129
|
return;
|
|
129
130
|
}
|
|
131
|
+
// Same patterns as `ple import` and `ple feedback`. Stops before anything is written, locally or to the account;
|
|
132
|
+
// only the kind is named, never the value.
|
|
133
|
+
const secret = (0, secretGuard_1.findSecret)([cleanTitle, options.description ?? '', body].join('\n'));
|
|
134
|
+
if (secret) {
|
|
135
|
+
console.error(format_1.c.error(`Not saved: this looks like it contains a ${secret}.`));
|
|
136
|
+
console.error(format_1.c.muted('Replace the value with a {{variable}} and save again.'));
|
|
137
|
+
process.exitCode = 1;
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
130
140
|
let folder;
|
|
131
141
|
if (options.folder !== undefined) {
|
|
132
142
|
const parsed = (0, folder_1.normalizeFolder)(options.folder);
|
package/dist/commands/suggest.js
CHANGED
|
@@ -73,6 +73,7 @@ const promptResolver_1 = require("../lib/promptResolver");
|
|
|
73
73
|
const rank_1 = require("../lib/rank");
|
|
74
74
|
const settings_1 = require("../lib/settings");
|
|
75
75
|
const tagFilter_1 = require("../lib/tagFilter");
|
|
76
|
+
const uuid_1 = require("../lib/uuid");
|
|
76
77
|
const local_1 = require("./local");
|
|
77
78
|
/** Entries that pass the filter. Pure; the ranker then runs on this subset only. */
|
|
78
79
|
function filterEntries(entries, filter) {
|
|
@@ -166,7 +167,6 @@ function noteLabel(raw) {
|
|
|
166
167
|
const chars = Array.from(clean);
|
|
167
168
|
return chars.length <= exports.NOTE_TITLE_MAX ? clean : chars.slice(0, exports.NOTE_TITLE_MAX - 1).join('').trimEnd() + '…';
|
|
168
169
|
}
|
|
169
|
-
const ACCOUNT_ID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
170
170
|
/** The only slugs that may appear inside a shell command in the note (lower-case ASCII, no shell syntax). */
|
|
171
171
|
const SAFE_SLUG_RE = /^[a-z0-9][a-z0-9._-]*$/;
|
|
172
172
|
/** True when `slug` can be placed in a shell command as-is. Old files may carry `$(…)`, quotes, spaces. */
|
|
@@ -192,7 +192,7 @@ function renderHookBlock(ranked, signedIn) {
|
|
|
192
192
|
const label = noteLabel(item.title || item.name);
|
|
193
193
|
const bits = [];
|
|
194
194
|
if (signedIn) {
|
|
195
|
-
if (
|
|
195
|
+
if (uuid_1.UUID_RE.test(item.id))
|
|
196
196
|
bits.push(`id ${item.id.toLowerCase()}`);
|
|
197
197
|
}
|
|
198
198
|
else if (isShellSafeSlug(item.name)) {
|
|
@@ -233,7 +233,7 @@ function renderHookBlock(ranked, signedIn) {
|
|
|
233
233
|
function getCommandFor(item) {
|
|
234
234
|
if (/^[\p{L}\p{N}][\p{L}\p{N} ._-]*$/u.test(item.name))
|
|
235
235
|
return `ple get "${item.name}"`;
|
|
236
|
-
if (
|
|
236
|
+
if (uuid_1.UUID_RE.test(item.id))
|
|
237
237
|
return `ple get ${item.id.toLowerCase()}`;
|
|
238
238
|
return null;
|
|
239
239
|
}
|
package/dist/commands/sync.js
CHANGED
|
@@ -20,6 +20,9 @@
|
|
|
20
20
|
* `--project <repo>` uploads into that repo (name, slug, id or short id — the same
|
|
21
21
|
* resolution as `ple import`); without it the prompts land in the default repo, or
|
|
22
22
|
* in the user's only repo when the plan cannot create another one.
|
|
23
|
+
*
|
|
24
|
+
* A prompt that looks like it holds a secret stays local: it is reported by slug and
|
|
25
|
+
* never sent. The store can hold one from before `ple save` refused them, or from a hand edit.
|
|
23
26
|
*/
|
|
24
27
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
25
28
|
if (k2 === undefined) k2 = k;
|
|
@@ -64,6 +67,7 @@ const githubImport_1 = require("../lib/githubImport");
|
|
|
64
67
|
const libraryCache_1 = require("../lib/libraryCache");
|
|
65
68
|
const promptResolver_1 = require("../lib/promptResolver");
|
|
66
69
|
const scanners_1 = require("../lib/scanners");
|
|
70
|
+
const secretGuard_1 = require("../lib/secretGuard");
|
|
67
71
|
/** The import endpoint caps one request at 50 records. */
|
|
68
72
|
const BATCH = 50;
|
|
69
73
|
/** The `--project` value as it would be typed again: quoted when a shell would split or expand it. */
|
|
@@ -88,9 +92,23 @@ function toImportable(p) {
|
|
|
88
92
|
};
|
|
89
93
|
}
|
|
90
94
|
async function syncCommand(options = {}) {
|
|
91
|
-
const
|
|
95
|
+
const withBody = store.list().filter((p) => p.body.trim());
|
|
96
|
+
const refused = withBody.flatMap((p) => {
|
|
97
|
+
const secret = (0, secretGuard_1.findSecret)([p.title, p.description ?? '', p.body, ...p.tags].join('\n'));
|
|
98
|
+
return secret ? [{ slug: p.slug, secret }] : [];
|
|
99
|
+
});
|
|
100
|
+
const local = withBody.filter((p) => !refused.some((r) => r.slug === p.slug));
|
|
92
101
|
/** What to run again: the same repo, not the default one. */
|
|
93
102
|
const again = `ple sync${options.project ? ` --project ${typed(options.project)}` : ''}`;
|
|
103
|
+
for (const r of refused) {
|
|
104
|
+
console.error(format_1.c.warn(`⚠ ${r.slug} not uploaded: it looks like it contains a ${r.secret}.`));
|
|
105
|
+
}
|
|
106
|
+
if (refused.length > 0) {
|
|
107
|
+
console.error(format_1.c.muted(' Replace the value with a {{variable}}, then sync again.'));
|
|
108
|
+
process.exitCode = 1;
|
|
109
|
+
if (local.length === 0)
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
94
112
|
if (local.length === 0) {
|
|
95
113
|
console.log(format_1.c.muted('Nothing to sync — the local store is empty.'));
|
|
96
114
|
console.log(format_1.c.muted(' ple save "code review" -m "Review this diff: {{diff}}"'));
|
package/dist/help.js
CHANGED
|
@@ -10,7 +10,7 @@ exports.COMMAND_GROUPS = void 0;
|
|
|
10
10
|
exports.formatRootHelp = formatRootHelp;
|
|
11
11
|
const commander_1 = require("commander");
|
|
12
12
|
exports.COMMAND_GROUPS = [
|
|
13
|
-
{ title: 'Prompts', commands: ['save', 'get', 'show', 'copy', 'list', 'search', 'log', 'diff', 'rollback', 'move', 'tag', 'untag', 'improve', 'loop'] },
|
|
13
|
+
{ title: 'Prompts', commands: ['save', 'get', 'show', 'copy', 'list', 'search', 'log', 'diff', 'rollback', 'move', 'rename', 'fork', 'tag', 'untag', 'improve', 'loop'] },
|
|
14
14
|
{ title: 'Repos', commands: ['repo', 'visibility'] },
|
|
15
15
|
{ title: 'Account', commands: ['login', 'logout', 'whoami'] },
|
|
16
16
|
{ title: 'Import / export / sync', commands: ['import', 'export', 'sync'] },
|
package/dist/lib/agentExport.js
CHANGED
|
@@ -79,10 +79,10 @@ function truncate(text, max) {
|
|
|
79
79
|
function yamlString(value) {
|
|
80
80
|
return `"${value.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`;
|
|
81
81
|
}
|
|
82
|
-
/** Metindeki benzersiz {{değişken}}
|
|
82
|
+
/** Metindeki benzersiz {{değişken}} adları; `{{else}}` koşul etiketidir, değişken sayılmaz. */
|
|
83
83
|
function listVariables(text) {
|
|
84
84
|
const seen = new Set();
|
|
85
|
-
for (const m of text.matchAll(/\{\{\s*([\p{L}\p{N}_.-]+)\s*\}\}/gu))
|
|
85
|
+
for (const m of text.matchAll(/\{\{\s*(?!else\s*\}\})([\p{L}\p{N}_.-]+)\s*\}\}/gu))
|
|
86
86
|
seen.add(m[1]);
|
|
87
87
|
return [...seen];
|
|
88
88
|
}
|
package/dist/lib/api-client.js
CHANGED
|
@@ -33,6 +33,7 @@ exports.listProjectsDetailed = listProjectsDetailed;
|
|
|
33
33
|
exports.createProject = createProject;
|
|
34
34
|
exports.setProjectVisibility = setProjectVisibility;
|
|
35
35
|
exports.setProjectLicense = setProjectLicense;
|
|
36
|
+
exports.setProjectDescription = setProjectDescription;
|
|
36
37
|
exports.setPromptVisibility = setPromptVisibility;
|
|
37
38
|
exports.getPromptById = getPromptById;
|
|
38
39
|
exports.getPromptHistory = getPromptHistory;
|
|
@@ -121,10 +122,13 @@ exports.DEFINITIVE_REFRESH_CODES = new Set([
|
|
|
121
122
|
]);
|
|
122
123
|
/** HTTP hatası; durum kodu ve sunucu kodu korunur (yenileme sınıflaması için). İleti değişmedi. */
|
|
123
124
|
class ApiError extends Error {
|
|
124
|
-
constructor(message, status, code
|
|
125
|
+
constructor(message, status, code,
|
|
126
|
+
/** Extra fields of the server's error body (e.g. the id of the copy an ALREADY_FORKED answer points to). */
|
|
127
|
+
details) {
|
|
125
128
|
super(message);
|
|
126
129
|
this.status = status;
|
|
127
130
|
this.code = code;
|
|
131
|
+
this.details = details;
|
|
128
132
|
this.name = 'ApiError';
|
|
129
133
|
}
|
|
130
134
|
}
|
|
@@ -310,8 +314,13 @@ async function apiFetch(path, opts = {}) {
|
|
|
310
314
|
});
|
|
311
315
|
}
|
|
312
316
|
catch (err) {
|
|
313
|
-
if (isTimeout(err, signal))
|
|
317
|
+
if (isTimeout(err, signal)) {
|
|
318
|
+
// `ple log --json` in a loop saw ~half of its reads hang for the full 15 s while the
|
|
319
|
+
// next one answered at once: a hung read is cheap to repeat, a write is not (it may have landed).
|
|
320
|
+
if (method === 'GET' && !opts._timeoutRetried)
|
|
321
|
+
return apiFetch(path, { ...opts, _timeoutRetried: true });
|
|
314
322
|
throw new RequestTimeoutError(timeoutMs, method);
|
|
323
|
+
}
|
|
315
324
|
throw new NetworkError(err instanceof Error ? err.message : String(err));
|
|
316
325
|
}
|
|
317
326
|
if (res.status >= 300 && res.status < 400) {
|
|
@@ -338,8 +347,11 @@ async function apiFetch(path, opts = {}) {
|
|
|
338
347
|
}
|
|
339
348
|
catch (err) {
|
|
340
349
|
// Başlıklar geldi, gövde yarıda kaldı ve süre doldu.
|
|
341
|
-
if (isTimeout(err, signal))
|
|
350
|
+
if (isTimeout(err, signal)) {
|
|
351
|
+
if (method === 'GET' && !opts._timeoutRetried)
|
|
352
|
+
return apiFetch(path, { ...opts, _timeoutRetried: true });
|
|
342
353
|
throw new RequestTimeoutError(timeoutMs, method);
|
|
354
|
+
}
|
|
343
355
|
throw err;
|
|
344
356
|
}
|
|
345
357
|
}
|
|
@@ -542,6 +554,13 @@ async function setProjectLicense(id, license) {
|
|
|
542
554
|
body: { license },
|
|
543
555
|
});
|
|
544
556
|
}
|
|
557
|
+
/** PATCH /api/projects/{id} — overwrite the description (`''` clears it); the server allows admin and owner. */
|
|
558
|
+
async function setProjectDescription(id, description) {
|
|
559
|
+
await apiFetch(`/api/projects/${encodeURIComponent(id)}`, {
|
|
560
|
+
method: 'PATCH',
|
|
561
|
+
body: { description },
|
|
562
|
+
});
|
|
563
|
+
}
|
|
545
564
|
/** PATCH /api/prompts/{id} — change one prompt's visibility (the server allows the owner only). */
|
|
546
565
|
async function setPromptVisibility(id, visibility) {
|
|
547
566
|
await apiFetch(`/api/prompts/${encodeURIComponent(id)}`, {
|
package/dist/lib/format.js
CHANGED
|
@@ -3,12 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.c = void 0;
|
|
6
|
+
exports.joinPromptParts = exports.c = void 0;
|
|
7
7
|
exports.timeAgo = timeAgo;
|
|
8
8
|
exports.shortId = shortId;
|
|
9
9
|
exports.truncate = truncate;
|
|
10
10
|
exports.formatTags = formatTags;
|
|
11
|
-
exports.joinPromptParts = joinPromptParts;
|
|
12
11
|
exports.safeText = safeText;
|
|
13
12
|
const chalk_1 = __importDefault(require("chalk"));
|
|
14
13
|
/**
|
|
@@ -87,18 +86,9 @@ function formatTags(names, max = 24) {
|
|
|
87
86
|
}
|
|
88
87
|
return `${shown.join(', ')} +${clean.length - shown.length}`;
|
|
89
88
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
* yalnız üç parça da boşken (gerçek legacy tek-alan kaydı) yedek olarak kullanılır. */
|
|
94
|
-
function joinPromptParts(parts) {
|
|
95
|
-
const segments = [parts.role_text, parts.description_text, parts.context_text]
|
|
96
|
-
.map((s) => (s || '').trim())
|
|
97
|
-
.filter(Boolean);
|
|
98
|
-
if (segments.length > 0)
|
|
99
|
-
return segments.join('\n\n---\n\n');
|
|
100
|
-
return parts.content && parts.content.trim() ? parts.content.trim() : '';
|
|
101
|
-
}
|
|
89
|
+
// Bağımlılıksız modülde durur: web testleri (src/lib/editor-body.test.ts) chalk kurulmadan içe aktarabilsin.
|
|
90
|
+
var promptParts_1 = require("./promptParts");
|
|
91
|
+
Object.defineProperty(exports, "joinPromptParts", { enumerable: true, get: function () { return promptParts_1.joinPromptParts; } });
|
|
102
92
|
/**
|
|
103
93
|
* Make server- or file-provided text safe to print on a terminal. A title such
|
|
104
94
|
* as "\u001b]0;pwned\u0007" or "\u001b[2J" would otherwise be interpreted by the
|
package/dist/lib/loopApi.js
CHANGED
|
@@ -17,12 +17,15 @@ exports.saveVersion = saveVersion;
|
|
|
17
17
|
exports.saveWinner = saveWinner;
|
|
18
18
|
exports.createPrompt = createPrompt;
|
|
19
19
|
exports.patchDescription = patchDescription;
|
|
20
|
+
exports.patchTitle = patchTitle;
|
|
20
21
|
exports.addTagByName = addTagByName;
|
|
21
22
|
exports.movePrompt = movePrompt;
|
|
23
|
+
exports.forkPrompt = forkPrompt;
|
|
22
24
|
exports.removePromptTag = removePromptTag;
|
|
23
25
|
const crypto_1 = require("crypto");
|
|
24
26
|
const constants_1 = require("./constants");
|
|
25
27
|
const config_1 = require("./config");
|
|
28
|
+
const api_client_1 = require("./api-client");
|
|
26
29
|
/**
|
|
27
30
|
* İstek zaman aşımları: sunucu takılırsa `ple loop` / `ple improve` sonsuza dek beklemesin.
|
|
28
31
|
* Varyant üretimi bir LLM çağrısı (genelde 10-40 sn), kayıt hafif bir yazma.
|
|
@@ -50,9 +53,9 @@ function isTimeout(err, signal) {
|
|
|
50
53
|
const name = err?.name;
|
|
51
54
|
return name === 'TimeoutError' || name === 'AbortError';
|
|
52
55
|
}
|
|
56
|
+
/** Typed so `exitCodeFor` sees a timeout (exit 2: try again), same as the api-client calls. */
|
|
53
57
|
function timeoutError(timeoutMs) {
|
|
54
|
-
return new
|
|
55
|
-
'The server may still be working on it; wait a moment, then try again.');
|
|
58
|
+
return new api_client_1.RequestTimeoutError(timeoutMs, 'POST', 'The server may still be working on it; wait a moment, then try again.');
|
|
56
59
|
}
|
|
57
60
|
const proForbidden = (serverError) => new Error(proMessage(serverError));
|
|
58
61
|
/**
|
|
@@ -84,7 +87,7 @@ async function bearerRequest(method, path, body, timeoutMs, forbidden) {
|
|
|
84
87
|
catch (err) {
|
|
85
88
|
if (isTimeout(err, signal))
|
|
86
89
|
throw timeoutError(timeoutMs);
|
|
87
|
-
throw new
|
|
90
|
+
throw new api_client_1.NetworkError(err instanceof Error ? err.message : String(err));
|
|
88
91
|
}
|
|
89
92
|
if (res.status >= 300 && res.status < 400) {
|
|
90
93
|
throw new Error(`The server answered with a redirect (HTTP ${res.status}); the CLI does not follow redirects. ` +
|
|
@@ -112,11 +115,11 @@ async function bearerRequest(method, path, body, timeoutMs, forbidden) {
|
|
|
112
115
|
}
|
|
113
116
|
if (res.status === 429) {
|
|
114
117
|
const retryAfter = res.headers.get('retry-after');
|
|
115
|
-
throw new
|
|
118
|
+
throw new api_client_1.ApiError(`Rate limited. Try again${retryAfter ? ` in ${retryAfter}s` : ' in a moment'}.`, 429);
|
|
116
119
|
}
|
|
117
120
|
if (!res.ok) {
|
|
118
121
|
// The message is unchanged; `code` / `status` let a caller act on a specific refusal (e.g. ask to confirm).
|
|
119
|
-
throw
|
|
122
|
+
throw new api_client_1.ApiError(parsed.error || `Request failed (${res.status}).`, res.status, parsed.code, parsed);
|
|
120
123
|
}
|
|
121
124
|
return parsed;
|
|
122
125
|
}
|
|
@@ -222,6 +225,13 @@ async function createPrompt(input) {
|
|
|
222
225
|
async function patchDescription(promptId, description) {
|
|
223
226
|
await bearerRequest('PATCH', `/api/prompts/${encodeURIComponent(promptId)}`, { description }, exports.SAVE_TIMEOUT_MS, metaForbidden);
|
|
224
227
|
}
|
|
228
|
+
/**
|
|
229
|
+
* PATCH /api/prompts/{id} — rename: only the title changes. The slug behind the public URL, every version,
|
|
230
|
+
* label and tag stay. The server does not check for a clashing title; `ple rename` does that first.
|
|
231
|
+
*/
|
|
232
|
+
async function patchTitle(promptId, title) {
|
|
233
|
+
await bearerRequest('PATCH', `/api/prompts/${encodeURIComponent(promptId)}`, { title }, exports.SAVE_TIMEOUT_MS, metaForbidden);
|
|
234
|
+
}
|
|
225
235
|
/** POST /api/prompts/{id}/tags — attach a tag by name (found or created in the prompt's repo); already attached is a no-op. */
|
|
226
236
|
async function addTagByName(promptId, tagName) {
|
|
227
237
|
await bearerRequest('POST', `/api/prompts/${encodeURIComponent(promptId)}/tags`, { tagName }, exports.SAVE_TIMEOUT_MS, metaForbidden);
|
|
@@ -240,6 +250,18 @@ async function movePrompt(promptId, input) {
|
|
|
240
250
|
}, exports.SAVE_TIMEOUT_MS, moveForbidden);
|
|
241
251
|
return res;
|
|
242
252
|
}
|
|
253
|
+
const forkForbidden = (serverError, body) => new Error(typeof body.upgradeUrl === 'string'
|
|
254
|
+
? `${serverError?.trim() || 'Prompt limit reached on your plan.'} Nothing was copied — upgrade at ${constants_1.API_BASE_URL}/pricing`
|
|
255
|
+
: serverError?.trim() || 'You are not allowed to fork into that repo.');
|
|
256
|
+
/**
|
|
257
|
+
* POST /api/prompts/{id}/fork — copy a PUBLIC prompt of someone else into one of YOUR repos. The copy starts private
|
|
258
|
+
* and records its source. Refusals keep the server `code`: PROMPT_NOT_FOUND (not public / gone), CANNOT_FORK_OWN,
|
|
259
|
+
* ALREADY_FORKED (409; `details.forkedPromptId` is the existing copy), NOTHING_TO_FORK; a plan limit is a 403.
|
|
260
|
+
*/
|
|
261
|
+
async function forkPrompt(promptId, input) {
|
|
262
|
+
const res = await bearerRequest('POST', `/api/prompts/${encodeURIComponent(promptId)}/fork`, { targetProjectId: input.targetProjectId, ...(input.title ? { title: input.title } : {}) }, exports.SAVE_TIMEOUT_MS, forkForbidden);
|
|
263
|
+
return { forkedPromptId: res.forkedPromptId, forkedProjectId: res.forkedProjectId };
|
|
264
|
+
}
|
|
243
265
|
const untagForbidden = (serverError) => new Error(serverError?.trim() || 'You need editor access to this repo to remove a tag.');
|
|
244
266
|
/** DELETE /api/prompts/{id}/tags/{tagId} — takes one tag off a prompt. The tag itself stays in the repo. */
|
|
245
267
|
async function removePromptTag(promptId, tagId) {
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readGraphLite = readGraphLite;
|
|
4
|
+
exports.noteName = noteName;
|
|
5
|
+
exports.buildObsidianVault = buildObsidianVault;
|
|
6
|
+
const OPEN = '<!-- ple-graph';
|
|
7
|
+
function cleanLine(v, max) {
|
|
8
|
+
if (typeof v !== 'string')
|
|
9
|
+
return null;
|
|
10
|
+
const s = v.replace(/[\u0000-\u001f\u007f]/g, ' ').replace(/\s+/g, ' ').trim();
|
|
11
|
+
return s ? s.slice(0, max) : null;
|
|
12
|
+
}
|
|
13
|
+
/** Çitli kod bloklarının (``` / ~~~) dışında kalan ilk kapalı bloğun aralığı. */
|
|
14
|
+
function findBlock(body) {
|
|
15
|
+
let inFence = false;
|
|
16
|
+
let offset = 0;
|
|
17
|
+
for (const line of body.split('\n')) {
|
|
18
|
+
if (/^\s*(```|~~~)/.test(line))
|
|
19
|
+
inFence = !inFence;
|
|
20
|
+
if (!inFence) {
|
|
21
|
+
const i = line.indexOf(OPEN);
|
|
22
|
+
if (i >= 0) {
|
|
23
|
+
const start = offset + i;
|
|
24
|
+
const close = body.indexOf('-->', start + OPEN.length);
|
|
25
|
+
if (close < 0)
|
|
26
|
+
return null; // kapanmamış: kullanıcının metni, dokunma
|
|
27
|
+
const json = body.slice(start + OPEN.length, close).trim();
|
|
28
|
+
return { start, end: close + 3, json };
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
offset += line.length + 1;
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
/** Gövdeden bloğu çıkarır ve okur. Blok yoksa ya da bozuksa `graph` null, gövde (blok varsa çıkarılmış) döner. */
|
|
36
|
+
function readGraphLite(body) {
|
|
37
|
+
const b = findBlock(body);
|
|
38
|
+
if (!b)
|
|
39
|
+
return { body, graph: null };
|
|
40
|
+
const stripped = (body.slice(0, b.start) + body.slice(b.end)).replace(/\n{3,}/g, '\n\n').trim();
|
|
41
|
+
let raw;
|
|
42
|
+
try {
|
|
43
|
+
raw = JSON.parse(b.json);
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return { body: stripped, graph: null };
|
|
47
|
+
}
|
|
48
|
+
if (!raw || typeof raw !== 'object' || raw.v !== 1)
|
|
49
|
+
return { body: stripped, graph: null };
|
|
50
|
+
const r = raw;
|
|
51
|
+
const needs = [];
|
|
52
|
+
for (const n of Array.isArray(r.needs) ? r.needs.slice(0, 12) : []) {
|
|
53
|
+
const name = cleanLine(n?.name, 64);
|
|
54
|
+
const type = cleanLine(n?.type, 48);
|
|
55
|
+
if (name)
|
|
56
|
+
needs.push({ name, type: type ?? name });
|
|
57
|
+
}
|
|
58
|
+
const next = [];
|
|
59
|
+
for (const e of Array.isArray(r.next) ? r.next.slice(0, 8) : []) {
|
|
60
|
+
const prompt = cleanLine(e?.prompt, 100);
|
|
61
|
+
const label = cleanLine(e?.label, 80);
|
|
62
|
+
if (prompt)
|
|
63
|
+
next.push(label ? { prompt, label } : { prompt });
|
|
64
|
+
}
|
|
65
|
+
return { body: stripped, graph: { needs, next } };
|
|
66
|
+
}
|
|
67
|
+
/** Obsidian dosya adı: wikilink'i bozan karakterler (`[]#^|`) ve yol ayırıcıları çıkar. */
|
|
68
|
+
function noteName(title, fallback = 'prompt') {
|
|
69
|
+
const s = title
|
|
70
|
+
.replace(/[\\/:*?"<>|#^[\]]/g, '-')
|
|
71
|
+
.replace(/\s+/g, ' ')
|
|
72
|
+
.replace(/^[.\s-]+|[.\s-]+$/g, '')
|
|
73
|
+
.slice(0, 100)
|
|
74
|
+
.trim();
|
|
75
|
+
return s || fallback;
|
|
76
|
+
}
|
|
77
|
+
function typeSlug(type) {
|
|
78
|
+
return noteName(type.toLowerCase().replace(/\s+/g, '-'), 'context');
|
|
79
|
+
}
|
|
80
|
+
function yamlString(v) {
|
|
81
|
+
return JSON.stringify(v); // JSON dizgesi geçerli YAML'dir
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Bir prompt kümesinden Obsidian notları üretir: prompt notları, `context/<tür>.md` merkezleri ve bir MOC.
|
|
85
|
+
* Kenar hedefi şunlarla eşleşir: tam id, 8+ haneli id öneki, başlık ya da başlığın slug'ı (büyük/küçük harf duyarsız).
|
|
86
|
+
*/
|
|
87
|
+
function buildObsidianVault(repoName, prompts, exportedAt) {
|
|
88
|
+
const used = new Set();
|
|
89
|
+
const notes = prompts.map((p) => {
|
|
90
|
+
let name = noteName(p.title);
|
|
91
|
+
let n = 2;
|
|
92
|
+
while (used.has(name.toLowerCase()))
|
|
93
|
+
name = `${noteName(p.title)} (${n++})`;
|
|
94
|
+
used.add(name.toLowerCase());
|
|
95
|
+
return { p, name, ...readGraphLite(p.body) };
|
|
96
|
+
});
|
|
97
|
+
const slug = (s) => s.toLowerCase().replace(/[^\p{L}\p{N}]+/gu, '-').replace(/^-+|-+$/g, '');
|
|
98
|
+
const resolve = (target) => {
|
|
99
|
+
const t = target.toLowerCase();
|
|
100
|
+
for (const x of notes) {
|
|
101
|
+
const id = (x.p.id ?? '').toLowerCase();
|
|
102
|
+
if (id && (id === t || (t.length >= 8 && id.startsWith(t))))
|
|
103
|
+
return x.name;
|
|
104
|
+
}
|
|
105
|
+
for (const x of notes)
|
|
106
|
+
if (x.p.title.toLowerCase() === t || slug(x.p.title) === slug(target))
|
|
107
|
+
return x.name;
|
|
108
|
+
return null;
|
|
109
|
+
};
|
|
110
|
+
const byType = new Map();
|
|
111
|
+
const files = [];
|
|
112
|
+
for (const x of notes) {
|
|
113
|
+
const g = x.graph;
|
|
114
|
+
const fm = [
|
|
115
|
+
'---',
|
|
116
|
+
'type: ple-prompt',
|
|
117
|
+
`title: ${yamlString(x.p.title)}`,
|
|
118
|
+
...(x.p.id ? [`ple_id: ${yamlString(x.p.id)}`] : []),
|
|
119
|
+
...(x.p.projectName ? [`project: ${yamlString(x.p.projectName)}`] : []),
|
|
120
|
+
...(x.p.version ? [`version: ${x.p.version}`] : []),
|
|
121
|
+
...(g && g.needs.length ? [`needs: [${g.needs.map((n) => yamlString(n.type)).join(', ')}]`] : []),
|
|
122
|
+
`exported_at: ${yamlString(exportedAt)}`,
|
|
123
|
+
'tags: [ple/prompt]',
|
|
124
|
+
'---',
|
|
125
|
+
];
|
|
126
|
+
const parts = [fm.join('\n'), `# ${x.p.title}`];
|
|
127
|
+
if (x.p.description)
|
|
128
|
+
parts.push(`> ${x.p.description.replace(/\n/g, ' ')}`);
|
|
129
|
+
parts.push(x.body);
|
|
130
|
+
if (g && g.next.length) {
|
|
131
|
+
const lines = g.next.map((e) => {
|
|
132
|
+
const hit = resolve(e.prompt);
|
|
133
|
+
const shown = e.label ? ` — ${e.label}` : '';
|
|
134
|
+
return hit ? `- [[${hit}]]${shown}` : `- \`${e.prompt}\` (not in this export)${shown}`;
|
|
135
|
+
});
|
|
136
|
+
parts.push(`## Next\n\n${lines.join('\n')}`);
|
|
137
|
+
}
|
|
138
|
+
if (g && g.needs.length) {
|
|
139
|
+
const lines = g.needs.map((nd) => {
|
|
140
|
+
const ts = typeSlug(nd.type);
|
|
141
|
+
const entry = byType.get(ts) ?? { type: nd.type, users: [] };
|
|
142
|
+
entry.users.push({ note: x.name, slot: nd.name });
|
|
143
|
+
byType.set(ts, entry);
|
|
144
|
+
return `- [[context/${ts}]] — \`{{${nd.name}}}\``;
|
|
145
|
+
});
|
|
146
|
+
parts.push(`## Needs\n\n${lines.join('\n')}`);
|
|
147
|
+
}
|
|
148
|
+
files.push({ path: `${x.name}.md`, content: parts.join('\n\n') + '\n' });
|
|
149
|
+
}
|
|
150
|
+
for (const [ts, e] of byType) {
|
|
151
|
+
const body = [
|
|
152
|
+
['---', 'type: ple-context-type', `context_type: ${yamlString(e.type)}`, 'tags: [ple/context]', '---'].join('\n'),
|
|
153
|
+
`# Context: ${e.type}`,
|
|
154
|
+
'Prompts that need this kind of context. Link your own notes here with ' +
|
|
155
|
+
`\`[[context/${ts}]]\` to connect them in the graph; PromptLikeEngineer never reads them.`,
|
|
156
|
+
e.users.map((u) => `- [[${u.note}]] — \`{{${u.slot}}}\``).join('\n'),
|
|
157
|
+
];
|
|
158
|
+
files.push({ path: `context/${ts}.md`, content: body.join('\n\n') + '\n' });
|
|
159
|
+
}
|
|
160
|
+
const moc = [
|
|
161
|
+
['---', 'type: ple-moc', `exported_at: ${yamlString(exportedAt)}`, 'tags: [ple/moc]', '---'].join('\n'),
|
|
162
|
+
`# ${repoName}`,
|
|
163
|
+
notes.map((x) => `- [[${x.name}]]`).join('\n'),
|
|
164
|
+
];
|
|
165
|
+
files.push({ path: `${noteName(repoName, 'prompts')} MOC.md`, content: moc.join('\n\n') + '\n' });
|
|
166
|
+
return files;
|
|
167
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Bağımlılıksız (chalk vb. yok): CLI dışından, alt paket bağımlılıkları kurulmadan da içe aktarılabilir.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.joinPromptParts = joinPromptParts;
|
|
5
|
+
/** Üç parçalı içeriği (role/description/context) tek metne birleştir.
|
|
6
|
+
* Yapısal parçalardan yeniden kurar ve BOŞ bölümleri atlar → yalnız-description
|
|
7
|
+
* bir prompt'ta başıboş `---` ayraçları çıkmaz (E2E bulgusu F2). Stored `content`
|
|
8
|
+
* yalnız üç parça da boşken (gerçek legacy tek-alan kaydı) yedek olarak kullanılır. */
|
|
9
|
+
function joinPromptParts(parts) {
|
|
10
|
+
const segments = [parts.role_text, parts.description_text, parts.context_text]
|
|
11
|
+
.map((s) => (s || '').trim())
|
|
12
|
+
.filter(Boolean);
|
|
13
|
+
if (segments.length > 0)
|
|
14
|
+
return segments.join('\n\n---\n\n');
|
|
15
|
+
return parts.content && parts.content.trim() ? parts.content.trim() : '';
|
|
16
|
+
}
|
|
@@ -8,8 +8,7 @@ exports.fetchPromptContent = fetchPromptContent;
|
|
|
8
8
|
const format_1 = require("./format");
|
|
9
9
|
const titleMatch_1 = require("./titleMatch");
|
|
10
10
|
const api_client_1 = require("./api-client");
|
|
11
|
-
const
|
|
12
|
-
const SHORT_ID_RE = /^[0-9a-f]{8,}$/i;
|
|
11
|
+
const uuid_1 = require("./uuid");
|
|
13
12
|
/** Server cap per page (GET /api/prompts maxLimit). */
|
|
14
13
|
const PAGE_LIMIT = 100;
|
|
15
14
|
/**
|
|
@@ -30,7 +29,7 @@ async function resolveProjectId(value) {
|
|
|
30
29
|
*/
|
|
31
30
|
async function resolveProject(value) {
|
|
32
31
|
const trimmed = value.trim();
|
|
33
|
-
if (UUID_RE.test(trimmed))
|
|
32
|
+
if (uuid_1.UUID_RE.test(trimmed))
|
|
34
33
|
return { id: trimmed };
|
|
35
34
|
const projects = await (0, api_client_1.listProjects)();
|
|
36
35
|
const lower = trimmed.toLowerCase();
|
|
@@ -39,7 +38,7 @@ async function resolveProject(value) {
|
|
|
39
38
|
return { id: matches[0].id, name: matches[0].name };
|
|
40
39
|
if (matches.length === 0) {
|
|
41
40
|
// Same short id `ple repo list` prints (8+ hex characters).
|
|
42
|
-
if (SHORT_ID_RE.test(trimmed)) {
|
|
41
|
+
if (uuid_1.SHORT_ID_RE.test(trimmed)) {
|
|
43
42
|
const byPrefix = projects.filter((p) => p.id.toLowerCase().startsWith(lower));
|
|
44
43
|
if (byPrefix.length === 1)
|
|
45
44
|
return { id: byPrefix[0].id, name: byPrefix[0].name };
|
|
@@ -85,7 +84,7 @@ async function lookupPromptByName(name, scope = {}) {
|
|
|
85
84
|
}
|
|
86
85
|
const projectId = scope.projectId;
|
|
87
86
|
// 1) Full UUID → detail endpoint. (Scope is advisory; verify it belongs.)
|
|
88
|
-
if (UUID_RE.test(trimmed)) {
|
|
87
|
+
if (uuid_1.UUID_RE.test(trimmed)) {
|
|
89
88
|
const found = await (0, api_client_1.getPromptById)(trimmed);
|
|
90
89
|
if (found) {
|
|
91
90
|
if (projectId && found.project_id && found.project_id !== projectId) {
|
|
@@ -97,7 +96,7 @@ async function lookupPromptByName(name, scope = {}) {
|
|
|
97
96
|
// Not found by id — fall through to a title search.
|
|
98
97
|
}
|
|
99
98
|
// 2) Short-id prefix (hex, 8+ chars, not a full UUID) → walk the pages.
|
|
100
|
-
if (!UUID_RE.test(trimmed) && SHORT_ID_RE.test(trimmed)) {
|
|
99
|
+
if (!uuid_1.UUID_RE.test(trimmed) && uuid_1.SHORT_ID_RE.test(trimmed)) {
|
|
101
100
|
const matches = await findByShortId(trimmed, projectId);
|
|
102
101
|
if (matches.length === 1)
|
|
103
102
|
return { kind: 'found', prompt: matches[0] };
|
|
@@ -113,7 +112,7 @@ async function lookupPromptByName(name, scope = {}) {
|
|
|
113
112
|
let titleMatches = results.filter((p) => (0, titleMatch_1.foldedIncludes)(p.title, trimmed));
|
|
114
113
|
// A hex-only name was just looked up page by page as a short id; a second walk over the same
|
|
115
114
|
// prompts would find no title that the first one did not.
|
|
116
|
-
const alreadyWalked = !UUID_RE.test(trimmed) && SHORT_ID_RE.test(trimmed);
|
|
115
|
+
const alreadyWalked = !uuid_1.UUID_RE.test(trimmed) && uuid_1.SHORT_ID_RE.test(trimmed);
|
|
117
116
|
if (titleMatches.length === 0 && !alreadyWalked) {
|
|
118
117
|
// The server's search is an ILIKE on title + description: it cannot see through Turkish letters or
|
|
119
118
|
// accents ("hat baslangici" never finds "Hat başlangıcı"), and a description that happens to contain
|
package/dist/lib/repoRef.js
CHANGED
|
@@ -12,10 +12,9 @@ exports.pickVisibility = pickVisibility;
|
|
|
12
12
|
exports.parseVisibility = parseVisibility;
|
|
13
13
|
exports.resolveRepoRef = resolveRepoRef;
|
|
14
14
|
const format_1 = require("./format");
|
|
15
|
+
const uuid_1 = require("./uuid");
|
|
15
16
|
exports.REPO_NAME_MAX = 100;
|
|
16
17
|
exports.REPO_DESCRIPTION_MAX = 500;
|
|
17
|
-
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
18
|
-
const SHORT_ID_RE = /^[0-9a-f]{8,}$/i;
|
|
19
18
|
const CONTROL_RE = /[\u0000-\u001f\u007f-\u009f]/;
|
|
20
19
|
/** Same transform the server applies to build the URL slug (`/api/projects`). */
|
|
21
20
|
function slugFromName(name) {
|
|
@@ -88,7 +87,7 @@ function resolveRepoRef(ref, repos) {
|
|
|
88
87
|
const value = ref.trim();
|
|
89
88
|
if (!value)
|
|
90
89
|
throw new Error('Give a repo name, slug or id. See: ple repo list');
|
|
91
|
-
if (UUID_RE.test(value)) {
|
|
90
|
+
if (uuid_1.UUID_RE.test(value)) {
|
|
92
91
|
const byId = repos.find((r) => r.id.toLowerCase() === value.toLowerCase());
|
|
93
92
|
if (byId)
|
|
94
93
|
return byId;
|
|
@@ -100,7 +99,7 @@ function resolveRepoRef(ref, repos) {
|
|
|
100
99
|
return byName[0];
|
|
101
100
|
if (byName.length > 1)
|
|
102
101
|
throw ambiguous(value, byName);
|
|
103
|
-
if (SHORT_ID_RE.test(value)) {
|
|
102
|
+
if (uuid_1.SHORT_ID_RE.test(value)) {
|
|
104
103
|
const byPrefix = repos.filter((r) => r.id.toLowerCase().startsWith(lower));
|
|
105
104
|
if (byPrefix.length === 1)
|
|
106
105
|
return byPrefix[0];
|
package/dist/lib/secretGuard.js
CHANGED
|
@@ -48,6 +48,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
48
48
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
49
49
|
exports.MAX_SCAN_FILE_BYTES = void 0;
|
|
50
50
|
exports.isDeniedFileName = isDeniedFileName;
|
|
51
|
+
exports.normalizeForScan = normalizeForScan;
|
|
51
52
|
exports.findSecret = findSecret;
|
|
52
53
|
const path = __importStar(require("path"));
|
|
53
54
|
/** Max size read from disk. Bigger files are skipped before reading. */
|
|
@@ -68,24 +69,61 @@ function isDeniedFileName(filePath) {
|
|
|
68
69
|
const base = path.basename(filePath);
|
|
69
70
|
return DENY_NAME_PATTERNS.some((re) => re.test(base));
|
|
70
71
|
}
|
|
72
|
+
// A key can follow `_` (KEY_sk-...), which `\b` does not treat as a boundary, so
|
|
73
|
+
// prefixes use "not preceded by a letter or digit" instead.
|
|
74
|
+
const START = '(?<![A-Za-z0-9])';
|
|
75
|
+
// Same list as the MCP write guard (mcp/src/lib/writeGuard.ts): keep the two in step.
|
|
71
76
|
const SECRET_PATTERNS = [
|
|
72
|
-
{ label: 'Anthropic/OpenAI API key', re:
|
|
73
|
-
{ label: 'AWS access key', re:
|
|
74
|
-
{
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
{ label: 'Anthropic/OpenAI API key', re: new RegExp(`${START}sk-(?:ant-|proj-)?[A-Za-z0-9_-]{20,}`) },
|
|
78
|
+
{ label: 'AWS access key', re: new RegExp(`${START}(?:AKIA|ASIA)[0-9A-Z]{16}(?![A-Za-z0-9])`) },
|
|
79
|
+
{
|
|
80
|
+
label: 'AWS secret key',
|
|
81
|
+
// 40 base64 characters alone are indistinguishable from hashes, so the variable name is required.
|
|
82
|
+
re: /aws_?secret_?access_?key["']?\s*[:=]\s*["']?[A-Za-z0-9/+=]{40}(?![A-Za-z0-9/+=])/i,
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
label: 'GitHub token',
|
|
86
|
+
re: new RegExp(`${START}(?:ghp|gho|ghu|ghs|ghr)_[A-Za-z0-9]{30,}|${START}github_pat_[A-Za-z0-9_]{30,}`),
|
|
87
|
+
},
|
|
88
|
+
{ label: 'GitLab token', re: new RegExp(`${START}glpat-[A-Za-z0-9_-]{20,}`) },
|
|
89
|
+
{ label: 'Slack token', re: new RegExp(`${START}xox[abprs]-[A-Za-z0-9-]{10,}`) },
|
|
90
|
+
{ label: 'Google API key', re: new RegExp(`${START}AIza[0-9A-Za-z_-]{35}(?![A-Za-z0-9_-])`) },
|
|
91
|
+
{ label: 'Stripe key', re: new RegExp(`${START}(?:sk|rk)_live_[A-Za-z0-9]{20,}`) },
|
|
92
|
+
{ label: 'Stripe webhook secret', re: new RegExp(`${START}whsec_[A-Za-z0-9]{20,}`) },
|
|
93
|
+
{ label: 'Supabase key', re: new RegExp(`${START}(?:sbp_[0-9a-f]{30,}|sb_secret_[A-Za-z0-9_-]{20,})`) },
|
|
94
|
+
{ label: 'npm token', re: new RegExp(`${START}npm_[A-Za-z0-9]{30,}`) },
|
|
95
|
+
{ label: 'Vercel Blob token', re: new RegExp(`${START}vercel_blob_rw_[A-Za-z0-9_-]{20,}`) },
|
|
96
|
+
{ label: 'SendGrid API key', re: new RegExp(`${START}SG\\.[A-Za-z0-9_-]{16,}\\.[A-Za-z0-9_-]{16,}`) },
|
|
79
97
|
{ label: 'private key', re: /-----BEGIN [A-Z ]*PRIVATE KEY-----/ },
|
|
80
|
-
{ label: 'JWT', re:
|
|
98
|
+
{ label: 'JWT', re: new RegExp(`${START}eyJ[A-Za-z0-9_-]{10,}\\.eyJ[A-Za-z0-9_-]{10,}\\.[A-Za-z0-9_-]{10,}`) },
|
|
99
|
+
{
|
|
100
|
+
label: 'Authorization bearer token',
|
|
101
|
+
// `Bearer {{token}}` placeholders are the sanctioned form, so they pass.
|
|
102
|
+
re: /Authorization["']?\s*[:=]\s*["']?Bearer\s+(?!\{\{)[A-Za-z0-9._~+/-]{20,}/i,
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
label: 'URL with embedded password',
|
|
106
|
+
// scheme://user:password@host, but a `{{variable}}` password is the sanctioned form and passes.
|
|
107
|
+
re: /(?<![A-Za-z0-9+.-])[a-z][a-z0-9+.-]*:\/\/[^\s:@/]+:(?!\{\{)[^\s@/]{3,}@/i,
|
|
108
|
+
},
|
|
81
109
|
];
|
|
110
|
+
// C0/C1 control characters except tab/newline/carriage return.
|
|
111
|
+
const CONTROL_CHARS = /[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F-\u009F]/g;
|
|
112
|
+
// Invisible or merely formatting characters never change what a key looks like to a human or a
|
|
113
|
+
// model, but a zero-width space in the middle of one defeats a regex. Removed for MATCHING only.
|
|
114
|
+
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;
|
|
115
|
+
/** Text as the matcher sees it: NFKC (fullwidth forms fold to ASCII), invisible and control characters removed. */
|
|
116
|
+
function normalizeForScan(text) {
|
|
117
|
+
return text.normalize('NFKC').replace(INVISIBLE, '').replace(CONTROL_CHARS, '');
|
|
118
|
+
}
|
|
82
119
|
/**
|
|
83
120
|
* Returns the *kind* of secret found (never the value), or null when clean.
|
|
84
121
|
* Callers print the label so the user knows which file to clean up.
|
|
85
122
|
*/
|
|
86
123
|
function findSecret(content) {
|
|
124
|
+
const scanned = normalizeForScan(content);
|
|
87
125
|
for (const { label, re } of SECRET_PATTERNS) {
|
|
88
|
-
if (re.test(
|
|
126
|
+
if (re.test(scanned))
|
|
89
127
|
return label;
|
|
90
128
|
}
|
|
91
129
|
return null;
|
package/dist/lib/uuid.js
ADDED
package/dist/program.js
CHANGED
|
@@ -33,6 +33,8 @@ const diff_1 = require("./commands/diff");
|
|
|
33
33
|
const rollback_1 = require("./commands/rollback");
|
|
34
34
|
const move_1 = require("./commands/move");
|
|
35
35
|
const untag_1 = require("./commands/untag");
|
|
36
|
+
const fork_1 = require("./commands/fork");
|
|
37
|
+
const rename_1 = require("./commands/rename");
|
|
36
38
|
const tag_1 = require("./commands/tag");
|
|
37
39
|
const suggest_1 = require("./commands/suggest");
|
|
38
40
|
const config_1 = require("./commands/config");
|
|
@@ -232,6 +234,40 @@ function buildProgram() {
|
|
|
232
234
|
'Exit codes: 0 moved · 1 fix it yourself (bad input, not found, not allowed, title taken, plan limit) ·',
|
|
233
235
|
'2 try again later (network, timeout, rate limit, server error)',
|
|
234
236
|
].join('\n'))).action(runWithErrorHandler((name, opts) => (0, move_1.moveCommand)(name, opts)));
|
|
237
|
+
scope(program
|
|
238
|
+
.command('fork <source>')
|
|
239
|
+
.description("Copy someone's public prompt into one of your repos")
|
|
240
|
+
.option('--title <title>', "Title of the copy (default: 'Fork of <title>')")
|
|
241
|
+
.option('--json', 'Print the outcome as one JSON line')
|
|
242
|
+
.addHelpText('after', [
|
|
243
|
+
'',
|
|
244
|
+
'Examples:',
|
|
245
|
+
' ple fork ple:zeynepaslierhan/ortak-web/Code Review --project my-prompts',
|
|
246
|
+
' ple fork 3f2a9c1e-0000-0000-0000-000000000000 --title "Review (mine)" --json',
|
|
247
|
+
'',
|
|
248
|
+
'<source> is the prompt\'s full id, or ple:<user>/<repo>/<title or id>. Only public prompts of other people',
|
|
249
|
+
'can be forked. The copy starts private and records its source and license in its first version. A',
|
|
250
|
+
'prompt can be forked once; trying again points at your copy. Counts against your plan\'s prompt limit.',
|
|
251
|
+
'',
|
|
252
|
+
'Exit codes: 0 forked (or already forked) · 1 fix it yourself (bad input, not found, not public, own prompt,',
|
|
253
|
+
'plan limit) · 2 try again later (network, timeout, rate limit, server error)',
|
|
254
|
+
].join('\n'))).action(runWithErrorHandler((source, opts) => (0, fork_1.forkCommand)(source, opts)));
|
|
255
|
+
scope(program
|
|
256
|
+
.command('rename <name> <new-title>')
|
|
257
|
+
.description("Change a prompt's title — its link, versions, labels and tags stay")
|
|
258
|
+
.option('--json', 'Print the outcome as one JSON line')
|
|
259
|
+
.addHelpText('after', [
|
|
260
|
+
'',
|
|
261
|
+
'Examples:',
|
|
262
|
+
' ple rename "code review" "Code review (backend)"',
|
|
263
|
+
' ple rename "code review" "Code review v2" --project team-prompts --json',
|
|
264
|
+
'',
|
|
265
|
+
'Only the title changes; the prompt keeps its id, the URL slug, every version, labels, stars, usage and',
|
|
266
|
+
'tags. A title another prompt in the same repo already has stops the rename. Undo: rename it back.',
|
|
267
|
+
'',
|
|
268
|
+
'Exit codes: 0 renamed · 1 fix it yourself (bad input, not found, not allowed, title taken) ·',
|
|
269
|
+
'2 try again later (network, timeout, rate limit, server error)',
|
|
270
|
+
].join('\n'))).action(runWithErrorHandler((name, newTitle, opts) => (0, rename_1.renameCommand)(name, newTitle, opts)));
|
|
235
271
|
scope(program
|
|
236
272
|
.command('rollback <name> <version>')
|
|
237
273
|
.description('Restore an old version as a new one — nothing is deleted (signed out: local history)')
|
|
@@ -274,6 +310,12 @@ function buildProgram() {
|
|
|
274
310
|
.option('-y, --yes', 'Confirm without asking (required when making a repo public in a script)')
|
|
275
311
|
.option('--json', 'Print the result as JSON')
|
|
276
312
|
.action(runWithErrorHandler((ref, value, opts) => (0, repo_1.repoVisibilityCommand)(ref, value, opts)));
|
|
313
|
+
repo.command('edit <repo>')
|
|
314
|
+
.description("Change a repo's description (owner or admin): --description <text>, \"\" clears it")
|
|
315
|
+
.option('-d, --description <text>', 'New description (max 500 characters); "" clears it')
|
|
316
|
+
.option('--json', 'Print the result as JSON')
|
|
317
|
+
.addHelpText('after', '\nExamples:\n ple repo edit team-prompts --description "Shared review prompts"\n ple repo edit team-prompts -d "" --json\n\nOnly the description changes: never the name, URL slug, visibility, license or prompts.')
|
|
318
|
+
.action(runWithErrorHandler(repo_1.repoEditCommand));
|
|
277
319
|
repo.command('license <repo> <value>')
|
|
278
320
|
.description('Declare the license of a repo\'s prompts (owner only): CC-BY-4.0 | CC-BY-SA-4.0 | CC0-1.0 | MIT | Apache-2.0 | none')
|
|
279
321
|
.option('--json', 'Print the result as JSON')
|
|
@@ -341,9 +383,9 @@ function buildProgram() {
|
|
|
341
383
|
.action(runWithErrorHandler((source, opts) => (0, import_1.importCommand)({ ...opts, source })));
|
|
342
384
|
scope(program
|
|
343
385
|
.command('export [name]')
|
|
344
|
-
.description('Export a prompt (or a whole repo with --project) as an AGENTS.md section
|
|
345
|
-
.requiredOption('--format <format>', 'agents-md | skill')
|
|
346
|
-
.option('-o, --out <path>', 'agents-md: file to write (default stdout) · skill: parent folder (default .)')
|
|
386
|
+
.description('Export a prompt (or a whole repo with --project) as an AGENTS.md section, an Agent Skill (SKILL.md) or linked Obsidian notes')
|
|
387
|
+
.requiredOption('--format <format>', 'agents-md | skill | obsidian')
|
|
388
|
+
.option('-o, --out <path>', 'agents-md: file to write (default stdout) · skill, obsidian: parent folder (default .)')
|
|
347
389
|
.option('--folder <path>', 'With --project: export only this folder of the repo (and what is under it)')
|
|
348
390
|
.option('--zip', 'skill: write <name>.zip (upload in Claude) instead of a folder')
|
|
349
391
|
.option('-f, --force', 'Overwrite an existing file or folder (never through a symbolic link)')).action(runWithErrorHandler(export_1.exportCommand));
|
package/package.json
CHANGED