promptlike 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +64 -0
- package/README.md +130 -9
- package/dist/commands/copy.js +12 -4
- package/dist/commands/export.js +14 -1
- package/dist/commands/get.js +6 -1
- package/dist/commands/list.js +5 -2
- package/dist/commands/local.js +4 -3
- package/dist/commands/logout.js +9 -4
- package/dist/commands/repo.js +171 -0
- package/dist/commands/show.js +4 -4
- package/dist/commands/tag.js +86 -0
- package/dist/help.js +65 -0
- package/dist/index.js +9 -171
- package/dist/lib/api-client.js +148 -5
- package/dist/lib/config.js +53 -30
- package/dist/lib/confirm.js +53 -0
- package/dist/lib/constants.js +47 -2
- package/dist/lib/errors.js +17 -0
- package/dist/lib/format.js +16 -0
- package/dist/lib/fsSafe.js +171 -0
- package/dist/lib/libraryCache.js +6 -7
- package/dist/lib/localHistory.js +3 -2
- package/dist/lib/localStore.js +7 -14
- package/dist/lib/promptResolver.js +11 -1
- package/dist/lib/promptTemplate.js +189 -0
- package/dist/lib/promptVariables.js +7 -40
- package/dist/lib/repoRef.js +118 -0
- package/dist/lib/settings.js +2 -2
- package/dist/program.js +209 -0
- package/package.json +1 -1
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Prompt şablon motoru - TEK KAYNAK (değişkenler + basit koşul).
|
|
4
|
+
*
|
|
5
|
+
* Bu dosya web (`src/lib/prompt-template.ts`), CLI (`cli/src/lib/promptTemplate.ts`)
|
|
6
|
+
* ve MCP (`mcp/src/lib/promptTemplate.ts`) içinde BAYT BAYT aynı durur; kayma
|
|
7
|
+
* `src/lib/prompt-template-drift.test.ts` ile yakalanır. Değiştirirsen üçünü de güncelle.
|
|
8
|
+
* Bağımlılıksız, saf fonksiyonlar. Kod ÇALIŞTIRMAZ: yalnız metin ağacı kurar ve yazdırır.
|
|
9
|
+
*
|
|
10
|
+
* Sözdizimi:
|
|
11
|
+
* {{ad}} değişken (boşluk tolere, Unicode ad)
|
|
12
|
+
* {{#if ad}} ... {{else}} ... {{/if}} ad doluysa ilk dal, değilse else dalı
|
|
13
|
+
* {{#unless ad}} ... {{/unless}} ad boş/yoksa
|
|
14
|
+
* Doluluk: değer verilmiş, kırpınca boş değil ve "false" / "0" değil (büyük/küçük harf farksız).
|
|
15
|
+
* Koşulda verilmeyen değişken = yanlış (sessizce); filler arayüzü bu adı yine de sorar.
|
|
16
|
+
* Sınırlar: iç içe en çok MAX_DEPTH. Dengesiz / fazla derin / sahipsiz {{else}} {{/if}} durumunda
|
|
17
|
+
* koşul etiketleri yorumlanmaz, metin olduğu gibi kalır (değişkenler yine doldurulur).
|
|
18
|
+
*/
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.MAX_DEPTH = void 0;
|
|
21
|
+
exports.extractVariables = extractVariables;
|
|
22
|
+
exports.fillVariables = fillVariables;
|
|
23
|
+
exports.hasVariables = hasVariables;
|
|
24
|
+
exports.MAX_DEPTH = 5;
|
|
25
|
+
const NAME = '[\\p{L}\\p{N}_.-]+';
|
|
26
|
+
// 1: if|unless (açılış) 2: açılış adı 3: else 4: kapanış tipi 5: düz değişken adı
|
|
27
|
+
const TAG = new RegExp(`\\{\\{\\s*(?:#(if|unless)\\s+(${NAME})|(else)|\\/(if|unless)|(${NAME}))\\s*\\}\\}`, 'gu');
|
|
28
|
+
function tokenize(text) {
|
|
29
|
+
const tokens = [];
|
|
30
|
+
let cursor = 0;
|
|
31
|
+
for (const m of text.matchAll(TAG)) {
|
|
32
|
+
const start = m.index ?? 0;
|
|
33
|
+
const end = start + m[0].length;
|
|
34
|
+
const isControl = m[5] === undefined;
|
|
35
|
+
let from = start;
|
|
36
|
+
let to = end;
|
|
37
|
+
if (isControl) {
|
|
38
|
+
// Etiket kendi satırındaysa satırı (boşluk + satır sonu) tümden tüket.
|
|
39
|
+
// Yalnız boşluk karakterleri taranır (satır başına/sonuna kadar), O(1) amortize.
|
|
40
|
+
let ls = start;
|
|
41
|
+
while (ls > 0 && text[ls - 1] !== '\n' && /[ \t\r]/.test(text[ls - 1]))
|
|
42
|
+
ls--;
|
|
43
|
+
let le = end;
|
|
44
|
+
while (le < text.length && text[le] !== '\n' && /[ \t\r]/.test(text[le]))
|
|
45
|
+
le++;
|
|
46
|
+
const startsLine = ls === 0 || text[ls - 1] === '\n';
|
|
47
|
+
const endsLine = le === text.length || text[le] === '\n';
|
|
48
|
+
if (startsLine && endsLine) {
|
|
49
|
+
from = Math.max(ls, cursor);
|
|
50
|
+
to = Math.min(le + 1, text.length);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (from > cursor)
|
|
54
|
+
tokens.push({ t: 'text', v: text.slice(cursor, from) });
|
|
55
|
+
cursor = to;
|
|
56
|
+
if (m[1])
|
|
57
|
+
tokens.push({ t: 'open', kind: m[1], name: m[2], raw: m[0] });
|
|
58
|
+
else if (m[3])
|
|
59
|
+
tokens.push({ t: 'else', raw: m[0] });
|
|
60
|
+
else if (m[4])
|
|
61
|
+
tokens.push({ t: 'close', kind: m[4], raw: m[0] });
|
|
62
|
+
else
|
|
63
|
+
tokens.push({ t: 'var', name: m[5], raw: m[0] });
|
|
64
|
+
}
|
|
65
|
+
if (cursor < text.length)
|
|
66
|
+
tokens.push({ t: 'text', v: text.slice(cursor) });
|
|
67
|
+
return tokens;
|
|
68
|
+
}
|
|
69
|
+
/** Dengeli ağaç kurar; hata olursa null (çağıran düz moda düşer). */
|
|
70
|
+
function parse(tokens) {
|
|
71
|
+
const root = [];
|
|
72
|
+
const stack = [];
|
|
73
|
+
const current = () => {
|
|
74
|
+
const top = stack[stack.length - 1];
|
|
75
|
+
return top ? (top.inElse ? top.node.no : top.node.yes) : root;
|
|
76
|
+
};
|
|
77
|
+
for (const tok of tokens) {
|
|
78
|
+
if (tok.t === 'text')
|
|
79
|
+
current().push(tok);
|
|
80
|
+
else if (tok.t === 'var')
|
|
81
|
+
current().push(tok);
|
|
82
|
+
else if (tok.t === 'open') {
|
|
83
|
+
if (stack.length >= exports.MAX_DEPTH)
|
|
84
|
+
return null;
|
|
85
|
+
const node = {
|
|
86
|
+
t: 'cond',
|
|
87
|
+
negate: tok.kind === 'unless',
|
|
88
|
+
name: tok.name,
|
|
89
|
+
yes: [],
|
|
90
|
+
no: [],
|
|
91
|
+
};
|
|
92
|
+
current().push(node);
|
|
93
|
+
stack.push({ kind: tok.kind, node, inElse: false });
|
|
94
|
+
}
|
|
95
|
+
else if (tok.t === 'else') {
|
|
96
|
+
const top = stack[stack.length - 1];
|
|
97
|
+
if (!top || top.inElse)
|
|
98
|
+
return null;
|
|
99
|
+
top.inElse = true;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
const top = stack.pop();
|
|
103
|
+
if (!top || top.kind !== tok.kind)
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return stack.length === 0 ? root : null;
|
|
108
|
+
}
|
|
109
|
+
/** Düz mod: koşul etiketleri metin kalır, yalnız değişkenler var sayılır. */
|
|
110
|
+
function flatten(tokens) {
|
|
111
|
+
return tokens.map((tok) => {
|
|
112
|
+
if (tok.t === 'var')
|
|
113
|
+
return tok;
|
|
114
|
+
if (tok.t === 'text')
|
|
115
|
+
return tok;
|
|
116
|
+
return { t: 'text', v: tok.raw };
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
function isTruthy(values, name) {
|
|
120
|
+
if (!Object.prototype.hasOwnProperty.call(values, name))
|
|
121
|
+
return false;
|
|
122
|
+
const v = values[name];
|
|
123
|
+
if (typeof v !== 'string')
|
|
124
|
+
return false;
|
|
125
|
+
const s = v.trim().toLowerCase();
|
|
126
|
+
return s !== '' && s !== 'false' && s !== '0';
|
|
127
|
+
}
|
|
128
|
+
function build(text) {
|
|
129
|
+
const tokens = tokenize(text);
|
|
130
|
+
const tree = parse(tokens);
|
|
131
|
+
return tree ? { tree, balanced: true } : { tree: flatten(tokens), balanced: false };
|
|
132
|
+
}
|
|
133
|
+
function render(nodes, values) {
|
|
134
|
+
let out = '';
|
|
135
|
+
for (const n of nodes) {
|
|
136
|
+
if (n.t === 'text')
|
|
137
|
+
out += n.v;
|
|
138
|
+
else if (n.t === 'var') {
|
|
139
|
+
// Yalnız kendi anahtarları: {{constructor}} gibi adlar prototipten bir şey çekmesin.
|
|
140
|
+
const value = Object.prototype.hasOwnProperty.call(values, n.name)
|
|
141
|
+
? values[n.name]
|
|
142
|
+
: undefined;
|
|
143
|
+
out += typeof value === 'string' && value !== '' ? value : n.raw;
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
const on = isTruthy(values, n.name) !== n.negate;
|
|
147
|
+
out += render(on ? n.yes : n.no, values);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return out;
|
|
151
|
+
}
|
|
152
|
+
function collect(nodes, seen, result) {
|
|
153
|
+
const add = (name) => {
|
|
154
|
+
if (!seen.has(name)) {
|
|
155
|
+
seen.add(name);
|
|
156
|
+
result.push(name);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
for (const n of nodes) {
|
|
160
|
+
if (n.t === 'var')
|
|
161
|
+
add(n.name);
|
|
162
|
+
else if (n.t === 'cond') {
|
|
163
|
+
add(n.name);
|
|
164
|
+
collect(n.yes, seen, result);
|
|
165
|
+
collect(n.no, seen, result);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/** Metindeki benzersiz değişken adları (koşul adları dahil), ilk görülme sırasıyla. */
|
|
170
|
+
function extractVariables(text) {
|
|
171
|
+
if (!text)
|
|
172
|
+
return [];
|
|
173
|
+
const result = [];
|
|
174
|
+
collect(build(text).tree, new Set(), result);
|
|
175
|
+
return result;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Koşulları çözer, `{{ad}}` yer tutucularını doldurur. Bulunmayan/boş değişken
|
|
179
|
+
* olduğu gibi kalır (sessizce silinmez); koşulda yanlış sayılır.
|
|
180
|
+
*/
|
|
181
|
+
function fillVariables(text, values) {
|
|
182
|
+
if (!text)
|
|
183
|
+
return '';
|
|
184
|
+
return render(build(text).tree, values);
|
|
185
|
+
}
|
|
186
|
+
/** Metinde en az bir değişken ya da koşul var mı. */
|
|
187
|
+
function hasVariables(text) {
|
|
188
|
+
return extractVariables(text).length > 0;
|
|
189
|
+
}
|
|
@@ -1,44 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Prompt değişkenleri (`{{ad}}`) — CLI yerel kopyası.
|
|
4
|
-
*
|
|
5
|
-
* Web tarafındaki `src/lib/prompt-variables.ts` ile BİREBİR aynı mantık. CLI
|
|
6
|
-
* ayrı bir npm paketi olduğu için web'den import edemiyor; bu yüzden küçük,
|
|
7
|
-
* bağımlılıksız util burada tekrarlanıyor. Birini değiştirirken diğerini de
|
|
8
|
-
* güncelle (ya da ileride shared/ altına taşıyıp sync-types ile senkronla).
|
|
9
|
-
*
|
|
10
|
-
* Syntax: `{{ad}}`, içeride whitespace tolere, Unicode adlar (Türkçe dahil).
|
|
11
|
-
*/
|
|
12
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.extractVariables =
|
|
14
|
-
exports.fillVariables = fillVariables;
|
|
15
|
-
const VARIABLE_PATTERN = /\{\{\s*([\p{L}\p{N}_.-]+)\s*\}\}/gu;
|
|
16
|
-
/** Metindeki benzersiz değişken adları, ilk görülme sırasıyla. */
|
|
17
|
-
function extractVariables(text) {
|
|
18
|
-
if (!text)
|
|
19
|
-
return [];
|
|
20
|
-
const seen = new Set();
|
|
21
|
-
const result = [];
|
|
22
|
-
for (const match of text.matchAll(VARIABLE_PATTERN)) {
|
|
23
|
-
const name = match[1];
|
|
24
|
-
if (!seen.has(name)) {
|
|
25
|
-
seen.add(name);
|
|
26
|
-
result.push(name);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
return result;
|
|
30
|
-
}
|
|
3
|
+
exports.hasVariables = exports.fillVariables = exports.extractVariables = void 0;
|
|
31
4
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
5
|
+
* Prompt değişkenleri + koşullar — motor `promptTemplate.ts` içinde (web ile aynı dosya,
|
|
6
|
+
* kayma `src/lib/prompt-template-drift.test.ts` ile yakalanır).
|
|
34
7
|
*/
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
// Yalnız kendi anahtarları: {{constructor}} / {{toString}} gibi adlar
|
|
40
|
-
// Object.prototype'tan fonksiyon çekip metne "function Object()…" basmasın.
|
|
41
|
-
const value = Object.prototype.hasOwnProperty.call(values, name) ? values[name] : undefined;
|
|
42
|
-
return typeof value === 'string' && value !== '' ? value : whole;
|
|
43
|
-
});
|
|
44
|
-
}
|
|
8
|
+
var promptTemplate_1 = require("./promptTemplate");
|
|
9
|
+
Object.defineProperty(exports, "extractVariables", { enumerable: true, get: function () { return promptTemplate_1.extractVariables; } });
|
|
10
|
+
Object.defineProperty(exports, "fillVariables", { enumerable: true, get: function () { return promptTemplate_1.fillVariables; } });
|
|
11
|
+
Object.defineProperty(exports, "hasVariables", { enumerable: true, get: function () { return promptTemplate_1.hasVariables; } });
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Repo name validation and `<repo>` reference resolution for `ple repo ...`.
|
|
4
|
+
* Pure functions: no network, no disk — everything here is unit-tested.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.REPO_DESCRIPTION_MAX = exports.REPO_NAME_MAX = void 0;
|
|
8
|
+
exports.slugFromName = slugFromName;
|
|
9
|
+
exports.validateRepoName = validateRepoName;
|
|
10
|
+
exports.validateRepoDescription = validateRepoDescription;
|
|
11
|
+
exports.pickVisibility = pickVisibility;
|
|
12
|
+
exports.parseVisibility = parseVisibility;
|
|
13
|
+
exports.resolveRepoRef = resolveRepoRef;
|
|
14
|
+
const format_1 = require("./format");
|
|
15
|
+
exports.REPO_NAME_MAX = 100;
|
|
16
|
+
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
|
+
const CONTROL_RE = /[\u0000-\u001f\u007f-\u009f]/;
|
|
20
|
+
/** Same transform the server applies to build the URL slug (`/api/projects`). */
|
|
21
|
+
function slugFromName(name) {
|
|
22
|
+
return name
|
|
23
|
+
.trim()
|
|
24
|
+
.toLowerCase()
|
|
25
|
+
.replace(/[^a-z0-9\-._]+/g, '-')
|
|
26
|
+
.replace(/^[-._]+|[-._]+$/g, '')
|
|
27
|
+
.slice(0, 100)
|
|
28
|
+
.replace(/-+$/, '');
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Validate a repo name the same way the server will, so a typo fails here with a
|
|
32
|
+
* fix instead of after a round trip. The server stays the authority (it re-checks
|
|
33
|
+
* everything; this is not a security boundary, only a courtesy).
|
|
34
|
+
*
|
|
35
|
+
* Returns the trimmed name, or throws an Error that says what to change.
|
|
36
|
+
*/
|
|
37
|
+
function validateRepoName(raw) {
|
|
38
|
+
const name = raw.trim();
|
|
39
|
+
if (!name)
|
|
40
|
+
throw new Error('Repo name is empty. Example: ple repo create "my-prompts"');
|
|
41
|
+
if (name.length > exports.REPO_NAME_MAX) {
|
|
42
|
+
throw new Error(`Repo name is too long (${name.length} characters, max ${exports.REPO_NAME_MAX}).`);
|
|
43
|
+
}
|
|
44
|
+
if (CONTROL_RE.test(name)) {
|
|
45
|
+
throw new Error('Repo name contains control characters (line breaks, escape codes). Use plain text.');
|
|
46
|
+
}
|
|
47
|
+
if (!/[a-z0-9]/i.test(name)) {
|
|
48
|
+
throw new Error("Repo name needs at least one letter or digit (a-z, 0-9) — it becomes the repo's URL slug.");
|
|
49
|
+
}
|
|
50
|
+
return name;
|
|
51
|
+
}
|
|
52
|
+
function validateRepoDescription(raw) {
|
|
53
|
+
if (raw === undefined)
|
|
54
|
+
return undefined;
|
|
55
|
+
const d = raw.trim();
|
|
56
|
+
if (!d)
|
|
57
|
+
return undefined;
|
|
58
|
+
if (d.length > exports.REPO_DESCRIPTION_MAX) {
|
|
59
|
+
throw new Error(`Description is too long (${d.length} characters, max ${exports.REPO_DESCRIPTION_MAX}).`);
|
|
60
|
+
}
|
|
61
|
+
if (CONTROL_RE.test(d.replace(/\n/g, ' '))) {
|
|
62
|
+
throw new Error('Description contains control characters. Use plain text.');
|
|
63
|
+
}
|
|
64
|
+
return d;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* `--private` / `--public` → visibility. Private is the default: a repo should
|
|
68
|
+
* only become public because someone said so.
|
|
69
|
+
*/
|
|
70
|
+
function pickVisibility(opts) {
|
|
71
|
+
if (opts.private && opts.public) {
|
|
72
|
+
throw new Error('Choose one: --private or --public (not both).');
|
|
73
|
+
}
|
|
74
|
+
return opts.public ? 'public' : 'private';
|
|
75
|
+
}
|
|
76
|
+
function parseVisibility(value) {
|
|
77
|
+
const v = value.trim().toLowerCase();
|
|
78
|
+
if (v === 'private' || v === 'public')
|
|
79
|
+
return v;
|
|
80
|
+
throw new Error(`Visibility must be 'private' or 'public', got '${value}'.`);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Resolve a user-typed `<repo>` against the repos the account can see:
|
|
84
|
+
* full id, then exact name or slug (case-insensitive), then a short id prefix
|
|
85
|
+
* (8+ hex characters). Ambiguity is reported, never guessed.
|
|
86
|
+
*/
|
|
87
|
+
function resolveRepoRef(ref, repos) {
|
|
88
|
+
const value = ref.trim();
|
|
89
|
+
if (!value)
|
|
90
|
+
throw new Error('Give a repo name, slug or id. See: ple repo list');
|
|
91
|
+
if (UUID_RE.test(value)) {
|
|
92
|
+
const byId = repos.find((r) => r.id.toLowerCase() === value.toLowerCase());
|
|
93
|
+
if (byId)
|
|
94
|
+
return byId;
|
|
95
|
+
throw notFound(value);
|
|
96
|
+
}
|
|
97
|
+
const lower = value.toLowerCase();
|
|
98
|
+
const byName = repos.filter((r) => r.name.toLowerCase() === lower || (r.slug ?? '').toLowerCase() === lower);
|
|
99
|
+
if (byName.length === 1)
|
|
100
|
+
return byName[0];
|
|
101
|
+
if (byName.length > 1)
|
|
102
|
+
throw ambiguous(value, byName);
|
|
103
|
+
if (SHORT_ID_RE.test(value)) {
|
|
104
|
+
const byPrefix = repos.filter((r) => r.id.toLowerCase().startsWith(lower));
|
|
105
|
+
if (byPrefix.length === 1)
|
|
106
|
+
return byPrefix[0];
|
|
107
|
+
if (byPrefix.length > 1)
|
|
108
|
+
throw ambiguous(value, byPrefix);
|
|
109
|
+
}
|
|
110
|
+
throw notFound(value);
|
|
111
|
+
}
|
|
112
|
+
function notFound(ref) {
|
|
113
|
+
return new Error(`No repo matched '${ref}'. List yours with: ple repo list`);
|
|
114
|
+
}
|
|
115
|
+
function ambiguous(ref, matches) {
|
|
116
|
+
const hint = matches.map((r) => `${(0, format_1.shortId)(r.id)} ${r.name}`).join(', ');
|
|
117
|
+
return new Error(`'${ref}' matched several repos (${hint}). Use the repo id.`);
|
|
118
|
+
}
|
package/dist/lib/settings.js
CHANGED
|
@@ -52,6 +52,7 @@ exports.suggestEnabled = suggestEnabled;
|
|
|
52
52
|
const fs = __importStar(require("fs"));
|
|
53
53
|
const os = __importStar(require("os"));
|
|
54
54
|
const path = __importStar(require("path"));
|
|
55
|
+
const fsSafe_1 = require("./fsSafe");
|
|
55
56
|
exports.SETTING_KEYS = ['suggest'];
|
|
56
57
|
/** Config dir (same as the session file). `PROMPTLIKE_CONFIG_DIR` overrides it for tests. */
|
|
57
58
|
function configDir() {
|
|
@@ -76,8 +77,7 @@ function readSettings() {
|
|
|
76
77
|
}
|
|
77
78
|
}
|
|
78
79
|
function writeSettings(next) {
|
|
79
|
-
|
|
80
|
-
fs.writeFileSync(settingsFile(), JSON.stringify(next, null, 2) + '\n', { mode: 0o600 });
|
|
80
|
+
(0, fsSafe_1.writePrivateFile)(settingsFile(), JSON.stringify(next, null, 2) + '\n');
|
|
81
81
|
}
|
|
82
82
|
/** Parse a user-typed on/off value. */
|
|
83
83
|
function parseOnOff(value) {
|
package/dist/program.js
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Command table for `ple`: registers every command with `commander`. Each
|
|
4
|
+
* command's real logic lives under `src/commands/` — this file only does argument
|
|
5
|
+
* parsing, the grouped `--help`, and the global error wrapper (exit codes).
|
|
6
|
+
* Split from index.ts so tests can build the program without running it.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.runWithErrorHandler = runWithErrorHandler;
|
|
10
|
+
exports.buildProgram = buildProgram;
|
|
11
|
+
const commander_1 = require("commander");
|
|
12
|
+
const constants_1 = require("./lib/constants");
|
|
13
|
+
const format_1 = require("./lib/format");
|
|
14
|
+
const login_1 = require("./commands/login");
|
|
15
|
+
const logout_1 = require("./commands/logout");
|
|
16
|
+
const list_1 = require("./commands/list");
|
|
17
|
+
const copy_1 = require("./commands/copy");
|
|
18
|
+
const show_1 = require("./commands/show");
|
|
19
|
+
const search_1 = require("./commands/search");
|
|
20
|
+
const get_1 = require("./commands/get");
|
|
21
|
+
const improve_1 = require("./commands/improve");
|
|
22
|
+
const loop_1 = require("./commands/loop");
|
|
23
|
+
const save_1 = require("./commands/save");
|
|
24
|
+
const sync_1 = require("./commands/sync");
|
|
25
|
+
const export_1 = require("./commands/export");
|
|
26
|
+
const stats_1 = require("./commands/stats");
|
|
27
|
+
const import_1 = require("./commands/import");
|
|
28
|
+
const log_1 = require("./commands/log");
|
|
29
|
+
const diff_1 = require("./commands/diff");
|
|
30
|
+
const rollback_1 = require("./commands/rollback");
|
|
31
|
+
const tag_1 = require("./commands/tag");
|
|
32
|
+
const suggest_1 = require("./commands/suggest");
|
|
33
|
+
const config_1 = require("./commands/config");
|
|
34
|
+
const repo_1 = require("./commands/repo");
|
|
35
|
+
const errors_1 = require("./lib/errors");
|
|
36
|
+
const help_1 = require("./help");
|
|
37
|
+
/**
|
|
38
|
+
* A single global try/catch — consistent error output and exit codes for every
|
|
39
|
+
* command: 1 = fix your input/login/plan, 2 = network/server problem, retry later.
|
|
40
|
+
* A command that already set `process.exitCode` keeps its own code.
|
|
41
|
+
*/
|
|
42
|
+
function runWithErrorHandler(fn) {
|
|
43
|
+
return async (...args) => {
|
|
44
|
+
try {
|
|
45
|
+
await fn(...args);
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
49
|
+
console.error(format_1.c.error(`✗ ${message}`));
|
|
50
|
+
process.exit(process.exitCode || (0, errors_1.exitCodeFor)(err));
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function buildProgram() {
|
|
55
|
+
const program = new commander_1.Command();
|
|
56
|
+
program
|
|
57
|
+
.name(constants_1.CLI_NAME)
|
|
58
|
+
.description('Your PromptLikeEngineer prompt library in the terminal — works offline, no account needed to start')
|
|
59
|
+
.version(constants_1.CLI_VERSION)
|
|
60
|
+
.configureHelp({ formatHelp: help_1.formatRootHelp })
|
|
61
|
+
.showSuggestionAfterError();
|
|
62
|
+
const scope = (cmd) => cmd.option('--project <repo>', 'Limit to one repo (name, slug or id) — use when titles collide');
|
|
63
|
+
// ---- prompts ------------------------------------------------------------
|
|
64
|
+
program
|
|
65
|
+
.command('save <title>')
|
|
66
|
+
.description('Save a prompt locally — no account needed')
|
|
67
|
+
.option('-m, --message <text>', 'Prompt body (or pipe it via stdin)')
|
|
68
|
+
.option('-d, --description <text>', 'Short description')
|
|
69
|
+
.option('-t, --tag <name>', 'Tag (repeatable)', save_1.collectTag, [])
|
|
70
|
+
.option('-f, --force', 'Overwrite an existing local prompt')
|
|
71
|
+
.addHelpText('after', '\nExamples:\n ple save "code review" -m "Review this diff: {{diff}}"\n pbpaste | ple save "bug triage" --tag triage')
|
|
72
|
+
.action(runWithErrorHandler(save_1.saveCommand));
|
|
73
|
+
scope(program
|
|
74
|
+
.command('get <name>')
|
|
75
|
+
.description('Print a prompt raw to stdout; fill {{variables}} and {{#if}} blocks (agent/pipe friendly)')
|
|
76
|
+
.option('-v, --var <keyval>', 'Fill a variable — key=value (repeatable)', get_1.collectVar, {})
|
|
77
|
+
.option('-c, --copy', 'Also copy the output to the clipboard')
|
|
78
|
+
.option('-l, --label <name>', 'Read the version a deployment label points at (e.g. production)'))
|
|
79
|
+
.addHelpText('after', '\nExample:\n ple get "code review" --var diff="$(git diff)" | claude')
|
|
80
|
+
.action(runWithErrorHandler(get_1.getCommand));
|
|
81
|
+
scope(program.command('show <name>').description('Show a prompt in the terminal')).action(runWithErrorHandler(show_1.showCommand));
|
|
82
|
+
scope(program
|
|
83
|
+
.command('copy <name>')
|
|
84
|
+
.description('Copy a prompt to the clipboard (by title or short id)')
|
|
85
|
+
.option('-v, --var <keyval>', 'Fill a variable / set an {{#if}} condition — key=value (repeatable)', get_1.collectVar, {})
|
|
86
|
+
.option('-l, --label <name>', 'Copy the version a deployment label points at (e.g. production)')).action(runWithErrorHandler(copy_1.copyCommand));
|
|
87
|
+
scope(program
|
|
88
|
+
.command('list')
|
|
89
|
+
.description('List your prompts')
|
|
90
|
+
.option('-t, --tag <name>', 'Filter by a specific tag')
|
|
91
|
+
.option('-l, --limit <n>', 'Max number of rows (default 30)', '30'))
|
|
92
|
+
.addHelpText('after', '\nExamples:\n ple list --tag debug\n ple list --project my-prompts')
|
|
93
|
+
.action(runWithErrorHandler(list_1.listCommand));
|
|
94
|
+
program
|
|
95
|
+
.command('search <keyword>')
|
|
96
|
+
.description('Search titles and descriptions (signed out: also local prompt bodies and tags)')
|
|
97
|
+
.action(runWithErrorHandler(search_1.searchCommand));
|
|
98
|
+
scope(program
|
|
99
|
+
.command('log <name>')
|
|
100
|
+
.description('Version history of a prompt (* = current). Signed out: the local history')
|
|
101
|
+
.option('-l, --limit <n>', 'Max versions to show (default 20)', '20')
|
|
102
|
+
.option('--json', 'Print as JSON')).action(runWithErrorHandler(log_1.logCommand));
|
|
103
|
+
scope(program
|
|
104
|
+
.command('diff <name> [a] [b]')
|
|
105
|
+
.description('Diff two versions (default: previous ↔ current). Refs: 3, v3 or 1.0.2')
|
|
106
|
+
.option('--no-color', 'Plain output (automatic when piped)')).action(runWithErrorHandler((name, a, b, opts) => (0, diff_1.diffCommand)(name, a, b, opts)));
|
|
107
|
+
scope(program
|
|
108
|
+
.command('tag <name> [version] [label]')
|
|
109
|
+
.description('Point a deployment label (production, staging…) at a version; every move is logged')
|
|
110
|
+
.option('--list', 'Show labels and recent moves')
|
|
111
|
+
.option('-r, --remove <label>', 'Remove a label')
|
|
112
|
+
.addHelpText('after', '\nExamples:\n ple tag "code review" 3 production\n ple tag "code review" --list\n ple get "code review" --label production')).action(runWithErrorHandler((name, version, label, opts) => (0, tag_1.tagCommand)(name, version, label, opts)));
|
|
113
|
+
scope(program
|
|
114
|
+
.command('rollback <name> <version>')
|
|
115
|
+
.description('Restore an old version as a new one — nothing is deleted (signed out: local history)')
|
|
116
|
+
.option('-y, --yes', 'Skip the confirmation prompt')).action(runWithErrorHandler((name, version, opts) => (0, rollback_1.rollbackCommand)(name, version, opts)));
|
|
117
|
+
scope(program
|
|
118
|
+
.command('improve <name>')
|
|
119
|
+
.option('-p, --pick <n>', 'Non-interactive: auto-pick variant N (1..3), 0 to cancel — for scripts/agents')
|
|
120
|
+
.description('Generate AI variants of a prompt, pick a winner, save it as a new version (Pro)')
|
|
121
|
+
.option('-f, --focus <hint>', "Steer the variants (e.g. 'shorter', 'more explicit output format')")).action(runWithErrorHandler(improve_1.improveCommand));
|
|
122
|
+
scope(program
|
|
123
|
+
.command('loop <name>')
|
|
124
|
+
.description('Multi-round improve — optionally test each variant with your own agent command (Pro)')
|
|
125
|
+
.option('-e, --exec <cmd>', 'Test each variant: prompt passed via PLE_PROMPT env + stdin; {} placeholder substituted')
|
|
126
|
+
.option('-r, --rounds <n>', 'Number of improvement rounds', '1')
|
|
127
|
+
.option('-f, --focus <hint>', 'Steer the variants')
|
|
128
|
+
.option('-p, --pick <n>', 'Non-interactive: auto-pick variant N each round + auto-continue — for scripts/agents')).action(runWithErrorHandler(loop_1.loopCommand));
|
|
129
|
+
// ---- repos --------------------------------------------------------------
|
|
130
|
+
const repo = program
|
|
131
|
+
.command('repo')
|
|
132
|
+
.description('Create and manage repos (collections of prompts) in your account')
|
|
133
|
+
.addHelpText('after', '\nExamples:\n ple repo create "team-prompts" --description "Shared review prompts"\n ple repo list\n ple repo visibility team-prompts public --yes\n\nRepos are private unless you say --public. Deleting a repo is only possible on the web.');
|
|
134
|
+
repo.command('create <name>')
|
|
135
|
+
.description('Create a repo (private by default)')
|
|
136
|
+
.option('--private', 'Only you and people you invite can see it (default)')
|
|
137
|
+
.option('--public', 'Anyone can read its public prompts')
|
|
138
|
+
.option('-d, --description <text>', 'Short description (max 500 characters)')
|
|
139
|
+
.option('--json', 'Print the result as JSON')
|
|
140
|
+
.action(runWithErrorHandler(repo_1.repoCreateCommand));
|
|
141
|
+
repo.command('list')
|
|
142
|
+
.description('List your repos with visibility, your role and prompt count')
|
|
143
|
+
.option('--json', 'Print as JSON')
|
|
144
|
+
.action(runWithErrorHandler(repo_1.repoListCommand));
|
|
145
|
+
repo.command('show <repo>')
|
|
146
|
+
.description('Show one repo (name, slug or id)')
|
|
147
|
+
.option('--json', 'Print as JSON')
|
|
148
|
+
.action(runWithErrorHandler(repo_1.repoShowCommand));
|
|
149
|
+
repo.command('visibility <repo> <value>')
|
|
150
|
+
.description('Make a repo private or public (owner only): value is private | public')
|
|
151
|
+
.option('-y, --yes', 'Confirm without asking (required when making a repo public in a script)')
|
|
152
|
+
.option('--json', 'Print the result as JSON')
|
|
153
|
+
.action(runWithErrorHandler((ref, value, opts) => (0, repo_1.repoVisibilityCommand)(ref, value, opts)));
|
|
154
|
+
// ---- account ------------------------------------------------------------
|
|
155
|
+
program
|
|
156
|
+
.command('login')
|
|
157
|
+
.description('Sign in with email + password; store the session under ~/.config/promptlike/')
|
|
158
|
+
.action(runWithErrorHandler(login_1.loginCommand));
|
|
159
|
+
program
|
|
160
|
+
.command('logout')
|
|
161
|
+
.description('Delete the local session file')
|
|
162
|
+
.action(runWithErrorHandler(logout_1.logoutCommand));
|
|
163
|
+
// ---- import / export / sync --------------------------------------------
|
|
164
|
+
program
|
|
165
|
+
.command('sync')
|
|
166
|
+
.description('Upload your local prompts to your account (one-way, explicit)')
|
|
167
|
+
.option('--dry-run', 'List what would be uploaded, change nothing')
|
|
168
|
+
.action(runWithErrorHandler(sync_1.syncCommand));
|
|
169
|
+
program
|
|
170
|
+
.command('import')
|
|
171
|
+
.description('Bring in prompts you already have: .claude/commands, SKILL.md, .cursor/commands, ~/.codex/prompts')
|
|
172
|
+
.option('--scan', 'Scan this repo and your home folder for agent prompt files')
|
|
173
|
+
.option('--dry-run', 'Only show what was found, import nothing')
|
|
174
|
+
.option('-a, --all', 'Import everything new without asking')
|
|
175
|
+
.option('--project <repo>', 'Import into this repo (signed in)')
|
|
176
|
+
.action(runWithErrorHandler((opts) => (0, import_1.importCommand)(opts)));
|
|
177
|
+
scope(program
|
|
178
|
+
.command('export [name]')
|
|
179
|
+
.description('Export a prompt (or a whole repo with --project) as an AGENTS.md section or an Agent Skill (SKILL.md)')
|
|
180
|
+
.requiredOption('--format <format>', 'agents-md | skill')
|
|
181
|
+
.option('-o, --out <path>', 'agents-md: file to write (default stdout) · skill: parent folder (default .)')
|
|
182
|
+
.option('--zip', 'skill: write <name>.zip (upload in Claude) instead of a folder')
|
|
183
|
+
.option('-f, --force', 'Overwrite an existing file or folder (never through a symbolic link)')).action(runWithErrorHandler(export_1.exportCommand));
|
|
184
|
+
// ---- insights & settings ------------------------------------------------
|
|
185
|
+
program
|
|
186
|
+
.command('stats')
|
|
187
|
+
.description('How your library is used — uses by surface, most used, gathering dust')
|
|
188
|
+
.option('-r, --range <days>', 'Window: 7, 30 or 365 (Free: 7)', '7')
|
|
189
|
+
.option('--json', 'Print the raw summary as JSON')
|
|
190
|
+
.action(runWithErrorHandler(stats_1.statsCommand));
|
|
191
|
+
program
|
|
192
|
+
.command('suggest [text...]')
|
|
193
|
+
.description('Which saved prompt fits this task? Local match — the text never leaves your machine')
|
|
194
|
+
.option('--json', 'Print matches as JSON')
|
|
195
|
+
.option('-l, --limit <n>', 'Max matches (default 3)', '3')
|
|
196
|
+
.option('--hook', 'Claude Code UserPromptSubmit mode: read hook JSON on stdin, print a short hint or nothing')
|
|
197
|
+
.option('--refresh-cache', 'Refresh the local library cache from your account and exit')
|
|
198
|
+
.action(runWithErrorHandler((text, opts) => (0, suggest_1.suggestCommand)(text ?? [], opts)));
|
|
199
|
+
const configCmd = program.command('config').description('CLI preferences (suggest on|off)');
|
|
200
|
+
configCmd
|
|
201
|
+
.command('get [key]')
|
|
202
|
+
.description('Show a setting (or all)')
|
|
203
|
+
.action(runWithErrorHandler(config_1.configGetCommand));
|
|
204
|
+
configCmd
|
|
205
|
+
.command('set <key> <value>')
|
|
206
|
+
.description('Change a setting, e.g. `ple config set suggest off`')
|
|
207
|
+
.action(runWithErrorHandler(config_1.configSetCommand));
|
|
208
|
+
return program;
|
|
209
|
+
}
|
package/package.json
CHANGED