promptlike 0.4.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +44 -0
- package/README.md +134 -2
- package/dist/commands/config.js +41 -0
- package/dist/commands/diff.js +59 -0
- package/dist/commands/export.js +196 -0
- package/dist/commands/history.js +63 -0
- package/dist/commands/import.js +250 -0
- package/dist/commands/list.js +4 -0
- package/dist/commands/log.js +48 -0
- package/dist/commands/rollback.js +88 -0
- package/dist/commands/stats.js +112 -0
- package/dist/commands/suggest.js +244 -0
- package/dist/commands/sync.js +4 -0
- package/dist/index.js +69 -0
- package/dist/lib/agentExport.js +378 -0
- package/dist/lib/api-client.js +91 -8
- package/dist/lib/constants.js +0 -1
- package/dist/lib/diff.js +149 -0
- package/dist/lib/frontmatter.js +67 -0
- package/dist/lib/libraryCache.js +222 -0
- package/dist/lib/promptVariables.js +4 -2
- package/dist/lib/rank.js +123 -0
- package/dist/lib/scanners/index.js +252 -0
- package/dist/lib/secretGuard.js +92 -0
- package/dist/lib/settings.js +105 -0
- package/package.json +1 -1
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* `ple suggest "<text>" [--json] [--limit 3] [--hook] [--refresh-cache]` (W1-5).
|
|
4
|
+
*
|
|
5
|
+
* Which saved prompt fits this task? Matching is LOCAL (cached library, or the
|
|
6
|
+
* local store when signed out) — the text never leaves the machine.
|
|
7
|
+
*
|
|
8
|
+
* `--hook` is the Claude Code `UserPromptSubmit` mode (plugin
|
|
9
|
+
* `scripts/suggest.sh`): reads the hook JSON from stdin, prints at most one
|
|
10
|
+
* short block that Claude Code adds to the model's context, and otherwise
|
|
11
|
+
* prints NOTHING. It is silent when:
|
|
12
|
+
* - suggestions are off (`PLE_SUGGEST=off`, plugin option, `ple config set suggest off`)
|
|
13
|
+
* - the message is a slash command or shorter than 20 characters
|
|
14
|
+
* - nothing scores above the noise gate
|
|
15
|
+
* - every match was already suggested in this session
|
|
16
|
+
* - anything at all goes wrong (the hook must never get in the way)
|
|
17
|
+
* It never waits on the network: a stale/missing cache triggers a detached
|
|
18
|
+
* background refresh and this run stays silent or uses the old snapshot.
|
|
19
|
+
*/
|
|
20
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
23
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
24
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
25
|
+
}
|
|
26
|
+
Object.defineProperty(o, k2, desc);
|
|
27
|
+
}) : (function(o, m, k, k2) {
|
|
28
|
+
if (k2 === undefined) k2 = k;
|
|
29
|
+
o[k2] = m[k];
|
|
30
|
+
}));
|
|
31
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
32
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
33
|
+
}) : function(o, v) {
|
|
34
|
+
o["default"] = v;
|
|
35
|
+
});
|
|
36
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
37
|
+
var ownKeys = function(o) {
|
|
38
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
39
|
+
var ar = [];
|
|
40
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
41
|
+
return ar;
|
|
42
|
+
};
|
|
43
|
+
return ownKeys(o);
|
|
44
|
+
};
|
|
45
|
+
return function (mod) {
|
|
46
|
+
if (mod && mod.__esModule) return mod;
|
|
47
|
+
var result = {};
|
|
48
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
49
|
+
__setModuleDefault(result, mod);
|
|
50
|
+
return result;
|
|
51
|
+
};
|
|
52
|
+
})();
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
exports.HOOK_BUDGET_MS = exports.HOOK_MIN_CHARS = void 0;
|
|
55
|
+
exports.stripPasted = stripPasted;
|
|
56
|
+
exports.hookShouldSkip = hookShouldSkip;
|
|
57
|
+
exports.renderHookBlock = renderHookBlock;
|
|
58
|
+
exports.runHook = runHook;
|
|
59
|
+
exports.refreshLibraryCache = refreshLibraryCache;
|
|
60
|
+
exports.suggestCommand = suggestCommand;
|
|
61
|
+
const api_client_1 = require("../lib/api-client");
|
|
62
|
+
const config_1 = require("../lib/config");
|
|
63
|
+
const format_1 = require("../lib/format");
|
|
64
|
+
const libraryCache_1 = require("../lib/libraryCache");
|
|
65
|
+
const store = __importStar(require("../lib/localStore"));
|
|
66
|
+
const rank_1 = require("../lib/rank");
|
|
67
|
+
const settings_1 = require("../lib/settings");
|
|
68
|
+
/** Hook input must be at least this long to be worth matching. */
|
|
69
|
+
exports.HOOK_MIN_CHARS = 20;
|
|
70
|
+
/** Hard wall-clock budget for hook mode (Claude Code waits on us). */
|
|
71
|
+
exports.HOOK_BUDGET_MS = 800;
|
|
72
|
+
/** Text considered from a message (pasted logs can be huge). */
|
|
73
|
+
const MAX_TASK_CHARS = 2000;
|
|
74
|
+
function parseLimit(raw) {
|
|
75
|
+
const n = Number.parseInt(raw ?? '3', 10);
|
|
76
|
+
return Number.isFinite(n) ? Math.max(1, Math.min(n, 10)) : 3;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Drop pasted blocks (`<pasted_content id=…>…</pasted_content id=…>`, see the
|
|
80
|
+
* Claude Code hooks docs) — a pasted stack trace says little about which of the
|
|
81
|
+
* user's prompts fits, and would drown the actual request.
|
|
82
|
+
*/
|
|
83
|
+
function stripPasted(text) {
|
|
84
|
+
return text.replace(/<pasted_content\b[^>]*>[\s\S]*?<\/pasted_content\b[^>]*>/g, ' ');
|
|
85
|
+
}
|
|
86
|
+
/** The hook's silence rules for the message itself. */
|
|
87
|
+
function hookShouldSkip(prompt) {
|
|
88
|
+
const t = prompt.trim();
|
|
89
|
+
return t.startsWith('/') || t.length < exports.HOOK_MIN_CHARS;
|
|
90
|
+
}
|
|
91
|
+
/** Library to match against, without touching the network. */
|
|
92
|
+
function localLibrary(now) {
|
|
93
|
+
const config = (0, config_1.readConfig)();
|
|
94
|
+
if (!config)
|
|
95
|
+
return { entries: (0, libraryCache_1.entriesFromLocal)(store.list()), signedIn: false, stale: false };
|
|
96
|
+
const cache = (0, libraryCache_1.readCache)(config.user_id);
|
|
97
|
+
if (!cache)
|
|
98
|
+
return { entries: [], signedIn: true, stale: true };
|
|
99
|
+
return { entries: cache.entries, signedIn: true, stale: !(0, libraryCache_1.isFresh)(cache, now) };
|
|
100
|
+
}
|
|
101
|
+
/** The ≤3-line block Claude Code injects into the model's context. */
|
|
102
|
+
function renderHookBlock(ranked, signedIn) {
|
|
103
|
+
const list = ranked
|
|
104
|
+
.map(({ item }) => `"${item.name}"${item.uses ? ` (used ${item.uses}×)` : ''}`)
|
|
105
|
+
.join(', ');
|
|
106
|
+
const how = signedIn
|
|
107
|
+
? 'fetch it with the promptlike get_prompt tool (name as quoted, via: "suggestion")'
|
|
108
|
+
: 'read it with `PLE_SURFACE=hook PLE_VIA=suggestion ple get "<name>"`';
|
|
109
|
+
return [
|
|
110
|
+
`PromptLikeEngineer: the user has saved prompts that may fit this request: ${list}.`,
|
|
111
|
+
`If one is clearly relevant, ${how} and follow it; otherwise ignore this note and do not mention it.`,
|
|
112
|
+
].join('\n');
|
|
113
|
+
}
|
|
114
|
+
function readStdin(budgetMs) {
|
|
115
|
+
if (process.stdin.isTTY)
|
|
116
|
+
return Promise.resolve('');
|
|
117
|
+
return new Promise((resolve) => {
|
|
118
|
+
let data = '';
|
|
119
|
+
const done = () => resolve(data);
|
|
120
|
+
const timer = setTimeout(done, budgetMs);
|
|
121
|
+
timer.unref();
|
|
122
|
+
process.stdin.setEncoding('utf-8');
|
|
123
|
+
process.stdin.on('data', (chunk) => {
|
|
124
|
+
if (data.length < 1000000)
|
|
125
|
+
data += chunk;
|
|
126
|
+
});
|
|
127
|
+
process.stdin.on('end', () => {
|
|
128
|
+
clearTimeout(timer);
|
|
129
|
+
done();
|
|
130
|
+
});
|
|
131
|
+
process.stdin.on('error', () => {
|
|
132
|
+
clearTimeout(timer);
|
|
133
|
+
done();
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
/** Hook mode. Every failure path is silent and exits 0. */
|
|
138
|
+
async function runHook(raw, now = Date.now()) {
|
|
139
|
+
if (!(0, settings_1.suggestEnabled)())
|
|
140
|
+
return '';
|
|
141
|
+
let input;
|
|
142
|
+
try {
|
|
143
|
+
input = JSON.parse(raw);
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
return '';
|
|
147
|
+
}
|
|
148
|
+
const prompt = typeof input.prompt === 'string' ? input.prompt : '';
|
|
149
|
+
const sessionId = typeof input.session_id === 'string' ? input.session_id : undefined;
|
|
150
|
+
if (hookShouldSkip(prompt))
|
|
151
|
+
return '';
|
|
152
|
+
const { entries, signedIn, stale } = localLibrary(now);
|
|
153
|
+
if (signedIn && stale)
|
|
154
|
+
(0, libraryCache_1.startBackgroundRefresh)({ now });
|
|
155
|
+
if (entries.length === 0)
|
|
156
|
+
return '';
|
|
157
|
+
const text = stripPasted(prompt).slice(0, MAX_TASK_CHARS);
|
|
158
|
+
const state = (0, libraryCache_1.readState)();
|
|
159
|
+
const already = (0, libraryCache_1.shownIn)(state, sessionId);
|
|
160
|
+
const fresh = (0, rank_1.rankLibrary)(entries, text, 3 + already.size).filter((r) => !already.has(r.item.id)).slice(0, 3);
|
|
161
|
+
if (fresh.length === 0)
|
|
162
|
+
return '';
|
|
163
|
+
(0, libraryCache_1.recordShown)(state, sessionId, fresh.map((r) => r.item.id), now);
|
|
164
|
+
return renderHookBlock(fresh, signedIn);
|
|
165
|
+
}
|
|
166
|
+
/** Refresh the account cache now (used by `--refresh-cache`, `ple list`, `ple sync`). */
|
|
167
|
+
async function refreshLibraryCache() {
|
|
168
|
+
const config = (0, config_1.readConfig)();
|
|
169
|
+
if (!config)
|
|
170
|
+
return 0;
|
|
171
|
+
await (0, api_client_1.ensureAuthed)();
|
|
172
|
+
const entries = await (0, libraryCache_1.fetchAccountEntries)((p) => (0, api_client_1.listPrompts)(p));
|
|
173
|
+
(0, libraryCache_1.writeCache)(config.user_id, entries);
|
|
174
|
+
return entries.length;
|
|
175
|
+
}
|
|
176
|
+
async function suggestCommand(words, options = {}) {
|
|
177
|
+
if (options.refreshCache) {
|
|
178
|
+
try {
|
|
179
|
+
await refreshLibraryCache();
|
|
180
|
+
}
|
|
181
|
+
catch {
|
|
182
|
+
process.exitCode = 1;
|
|
183
|
+
}
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
if (options.hook) {
|
|
187
|
+
const deadline = setTimeout(() => process.exit(0), exports.HOOK_BUDGET_MS);
|
|
188
|
+
deadline.unref();
|
|
189
|
+
try {
|
|
190
|
+
const out = await runHook(await readStdin(exports.HOOK_BUDGET_MS / 2));
|
|
191
|
+
if (out)
|
|
192
|
+
process.stdout.write(out + '\n');
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
// never surface an error into the user's session
|
|
196
|
+
}
|
|
197
|
+
process.exitCode = 0;
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
const text = words.join(' ').trim();
|
|
201
|
+
if (!text)
|
|
202
|
+
throw new Error('Describe the task: ple suggest "review this pull request"');
|
|
203
|
+
const limit = parseLimit(options.limit);
|
|
204
|
+
// Interactive: a missing/stale account cache is refreshed first (network is fine here).
|
|
205
|
+
const config = (0, config_1.readConfig)();
|
|
206
|
+
let entries;
|
|
207
|
+
if (!config) {
|
|
208
|
+
entries = (0, libraryCache_1.entriesFromLocal)(store.list());
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
const cache = (0, libraryCache_1.readCache)(config.user_id);
|
|
212
|
+
if (cache && (0, libraryCache_1.isFresh)(cache)) {
|
|
213
|
+
entries = cache.entries;
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
await refreshLibraryCache();
|
|
217
|
+
entries = (0, libraryCache_1.readCache)(config.user_id)?.entries ?? [];
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
const ranked = (0, rank_1.rankLibrary)(entries, text, limit);
|
|
221
|
+
if (options.json) {
|
|
222
|
+
console.log(JSON.stringify(ranked.map(({ item, score }) => ({
|
|
223
|
+
id: item.id,
|
|
224
|
+
name: item.name,
|
|
225
|
+
title: item.title,
|
|
226
|
+
repo: item.repo ?? null,
|
|
227
|
+
uses: item.uses ?? null,
|
|
228
|
+
score,
|
|
229
|
+
})), null, 2));
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
if (ranked.length === 0) {
|
|
233
|
+
console.log(format_1.c.muted('No saved prompt fits that task.'));
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
for (const { item, score } of ranked) {
|
|
237
|
+
const meta = [item.repo, item.uses ? `used ${item.uses}×` : '', `score ${score}`].filter(Boolean).join(' · ');
|
|
238
|
+
console.log(`${format_1.c.title(item.title)} ${format_1.c.muted(meta)}`);
|
|
239
|
+
if (item.description)
|
|
240
|
+
console.log(format_1.c.muted(` ${item.description}`));
|
|
241
|
+
}
|
|
242
|
+
const first = ranked[0].item.name;
|
|
243
|
+
console.log(format_1.c.muted(`\nUse one: ple get "${first}"`));
|
|
244
|
+
}
|
package/dist/commands/sync.js
CHANGED
|
@@ -49,6 +49,7 @@ exports.syncCommand = syncCommand;
|
|
|
49
49
|
const store = __importStar(require("../lib/localStore"));
|
|
50
50
|
const api_client_1 = require("../lib/api-client");
|
|
51
51
|
const format_1 = require("../lib/format");
|
|
52
|
+
const libraryCache_1 = require("../lib/libraryCache");
|
|
52
53
|
/** The import endpoint caps one request at 50 records. */
|
|
53
54
|
const BATCH = 50;
|
|
54
55
|
async function syncCommand(options = {}) {
|
|
@@ -100,6 +101,9 @@ async function syncCommand(options = {}) {
|
|
|
100
101
|
break;
|
|
101
102
|
}
|
|
102
103
|
}
|
|
104
|
+
// New prompts should be suggestible right away (W1-5 cache) — detached.
|
|
105
|
+
if (imported > 0)
|
|
106
|
+
(0, libraryCache_1.startBackgroundRefresh)({ force: true });
|
|
103
107
|
const tagNote = serverCarriesTags && tagsApplied > 0 ? ` (+${tagsApplied} tag link${tagsApplied === 1 ? '' : 's'})` : '';
|
|
104
108
|
console.log(format_1.c.success(`✓ Uploaded ${imported} prompt${imported === 1 ? '' : 's'}${tagNote}`));
|
|
105
109
|
// Each shortfall gets its own line with its own fix — "12 of 20 synced"
|
package/dist/index.js
CHANGED
|
@@ -22,6 +22,14 @@ const improve_1 = require("./commands/improve");
|
|
|
22
22
|
const loop_1 = require("./commands/loop");
|
|
23
23
|
const save_1 = require("./commands/save");
|
|
24
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 suggest_1 = require("./commands/suggest");
|
|
32
|
+
const config_1 = require("./commands/config");
|
|
25
33
|
/** A single global try/catch — consistent error output for every command. */
|
|
26
34
|
function runWithErrorHandler(fn) {
|
|
27
35
|
return async (...args) => {
|
|
@@ -100,8 +108,69 @@ program
|
|
|
100
108
|
.option('-p, --pick <n>', 'Non-interactive: auto-pick variant N each round + auto-continue — for scripts/agents')
|
|
101
109
|
.option('--project <repo>', 'Scope to one repo (name, slug, or id) when titles collide')
|
|
102
110
|
.action(runWithErrorHandler(loop_1.loopCommand));
|
|
111
|
+
program
|
|
112
|
+
.command('export [name]')
|
|
113
|
+
.description('Export a prompt (or a whole repo with --project) as an AGENTS.md section or an Agent Skill (SKILL.md)')
|
|
114
|
+
.requiredOption('--format <format>', 'agents-md | skill')
|
|
115
|
+
.option('--project <repo>', 'Repo to export (no name) or to scope the name to')
|
|
116
|
+
.option('-o, --out <path>', 'agents-md: file to write (default stdout) · skill: parent folder (default .)')
|
|
117
|
+
.option('--zip', 'skill: write <name>.zip (upload in Claude) instead of a folder')
|
|
118
|
+
.option('-f, --force', 'Overwrite an existing file or folder')
|
|
119
|
+
.action(runWithErrorHandler(export_1.exportCommand));
|
|
103
120
|
program
|
|
104
121
|
.command('search <keyword>')
|
|
105
122
|
.description('Search titles and descriptions (signed out: also local prompt bodies and tags)')
|
|
106
123
|
.action(runWithErrorHandler(search_1.searchCommand));
|
|
124
|
+
program
|
|
125
|
+
.command('stats')
|
|
126
|
+
.description('How your library is used — uses by surface, most used, gathering dust')
|
|
127
|
+
.option('-r, --range <days>', 'Window: 7, 30 or 365 (Free: 7)', '7')
|
|
128
|
+
.option('--json', 'Print the raw summary as JSON')
|
|
129
|
+
.action(runWithErrorHandler(stats_1.statsCommand));
|
|
130
|
+
program
|
|
131
|
+
.command('import')
|
|
132
|
+
.description('Bring in prompts you already have: .claude/commands, SKILL.md, .cursor/commands, ~/.codex/prompts')
|
|
133
|
+
.option('--scan', 'Scan this repo and your home folder for agent prompt files')
|
|
134
|
+
.option('--dry-run', 'Only show what was found, import nothing')
|
|
135
|
+
.option('-a, --all', 'Import everything new without asking')
|
|
136
|
+
.option('--project <repo>', 'Import into this repo (signed in)')
|
|
137
|
+
.action(runWithErrorHandler((opts) => (0, import_1.importCommand)(opts)));
|
|
138
|
+
program
|
|
139
|
+
.command('log <name>')
|
|
140
|
+
.description('Version history of a prompt (* = current)')
|
|
141
|
+
.option('--project <repo>', 'Scope to one repo (name, slug, or id) when titles collide')
|
|
142
|
+
.option('-l, --limit <n>', 'Max versions to show (default 20)', '20')
|
|
143
|
+
.option('--json', 'Print as JSON')
|
|
144
|
+
.action(runWithErrorHandler(log_1.logCommand));
|
|
145
|
+
program
|
|
146
|
+
.command('diff <name> [a] [b]')
|
|
147
|
+
.description('Diff two versions (default: previous ↔ current). Refs: 3, v3 or 1.0.2')
|
|
148
|
+
.option('--project <repo>', 'Scope to one repo (name, slug, or id) when titles collide')
|
|
149
|
+
.option('--no-color', 'Plain output (automatic when piped)')
|
|
150
|
+
.action(runWithErrorHandler((name, a, b, opts) => (0, diff_1.diffCommand)(name, a, b, opts)));
|
|
151
|
+
program
|
|
152
|
+
.command('suggest [text...]')
|
|
153
|
+
.description('Which saved prompt fits this task? Local match — the text never leaves your machine')
|
|
154
|
+
.option('--json', 'Print matches as JSON')
|
|
155
|
+
.option('-l, --limit <n>', 'Max matches (default 3)', '3')
|
|
156
|
+
.option('--hook', 'Claude Code UserPromptSubmit mode: read hook JSON on stdin, print a short hint or nothing')
|
|
157
|
+
.option('--refresh-cache', 'Refresh the local library cache from your account and exit')
|
|
158
|
+
.action(runWithErrorHandler((text, opts) => (0, suggest_1.suggestCommand)(text ?? [], opts)));
|
|
159
|
+
const configCmd = program
|
|
160
|
+
.command('config')
|
|
161
|
+
.description('CLI preferences (suggest on|off)');
|
|
162
|
+
configCmd
|
|
163
|
+
.command('get [key]')
|
|
164
|
+
.description('Show a setting (or all)')
|
|
165
|
+
.action(runWithErrorHandler(config_1.configGetCommand));
|
|
166
|
+
configCmd
|
|
167
|
+
.command('set <key> <value>')
|
|
168
|
+
.description('Change a setting, e.g. `ple config set suggest off`')
|
|
169
|
+
.action(runWithErrorHandler(config_1.configSetCommand));
|
|
170
|
+
program
|
|
171
|
+
.command('rollback <name> <version>')
|
|
172
|
+
.description('Restore an old version as a new one — nothing is deleted')
|
|
173
|
+
.option('--project <repo>', 'Scope to one repo (name, slug, or id) when titles collide')
|
|
174
|
+
.option('-y, --yes', 'Skip the confirmation prompt')
|
|
175
|
+
.action(runWithErrorHandler((name, version, opts) => (0, rollback_1.rollbackCommand)(name, version, opts)));
|
|
107
176
|
program.parseAsync(process.argv);
|