promptlike 0.8.0 → 0.10.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 +108 -0
- package/README.md +270 -28
- package/dist/commands/config.js +13 -0
- package/dist/commands/copy.js +22 -7
- package/dist/commands/get.js +17 -3
- package/dist/commands/import.js +30 -128
- package/dist/commands/importCheck.js +304 -0
- package/dist/commands/importGithub.js +171 -0
- package/dist/commands/list.js +83 -17
- package/dist/commands/local.js +35 -12
- package/dist/commands/login.js +6 -5
- package/dist/commands/search.js +73 -7
- package/dist/commands/show.js +11 -3
- package/dist/commands/sync.js +57 -13
- package/dist/commands/tag.js +86 -0
- package/dist/help.js +1 -1
- package/dist/index.js +7 -0
- package/dist/lib/api-client.js +39 -0
- package/dist/lib/errors.js +4 -0
- package/dist/lib/format.js +28 -0
- package/dist/lib/frontmatter.js +86 -4
- package/dist/lib/github.js +208 -0
- package/dist/lib/githubCache.js +118 -0
- package/dist/lib/githubHttp.js +197 -0
- package/dist/lib/githubImport.js +238 -0
- package/dist/lib/githubSelect.js +148 -0
- package/dist/lib/githubSnapshot.js +67 -0
- package/dist/lib/githubSpec.js +78 -0
- package/dist/lib/importOrigins.js +36 -0
- package/dist/lib/importShared.js +179 -0
- package/dist/lib/licenses.js +243 -0
- package/dist/lib/localStore.js +52 -10
- package/dist/lib/loopApi.js +63 -11
- package/dist/lib/promptResolver.js +22 -9
- package/dist/lib/promptSource.js +123 -0
- package/dist/lib/promptTemplate.js +189 -0
- package/dist/lib/promptVariables.js +7 -40
- package/dist/lib/rank.js +30 -13
- package/dist/lib/settings.js +24 -3
- package/dist/lib/tagFilter.js +40 -0
- package/dist/lib/updateCheck.js +296 -0
- package/dist/lib/upstreamCheck.js +71 -0
- package/dist/program.js +41 -10
- package/package.json +1 -1
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* "A newer version is out" notice — costs the user nothing.
|
|
4
|
+
*
|
|
5
|
+
* What it does, exactly:
|
|
6
|
+
* - After a command finished successfully in an interactive terminal, it reads a small cache
|
|
7
|
+
* (`~/.config/promptlike/cache/update-check.json`). If the cache says a newer version exists and
|
|
8
|
+
* nobody was told in the last 24 hours, ONE line goes to stderr.
|
|
9
|
+
* - If the cache is older than 24 hours it starts a detached background process (never awaited,
|
|
10
|
+
* stdio ignored) that asks the npm registry for the latest version and stores it. The command
|
|
11
|
+
* never waits for the network; the answer shows up on a later run.
|
|
12
|
+
* - At most one registry request per 24 hours: the cache is stamped BEFORE the process starts, so
|
|
13
|
+
* a failed or slow check is not retried by the next command, and neither is a burst of commands.
|
|
14
|
+
*
|
|
15
|
+
* What is sent: one anonymous `GET https://registry.npmjs.org/promptlike/latest` (no cookies, no
|
|
16
|
+
* credentials, no identifiers, nothing about you or your prompts — the registry sees your IP address
|
|
17
|
+
* like it does on `npm install`). What comes back is reduced to a strict `x.y.z` version before it is
|
|
18
|
+
* stored or printed; no other response text is ever used.
|
|
19
|
+
*
|
|
20
|
+
* Silent, no cache read and no request: `PLE_UPDATE_CHECK=off`, `NO_UPDATE_NOTIFIER`, `CI`,
|
|
21
|
+
* `ple config set update-check off`, stdout or stderr not a terminal (so `ple get … | claude` and the
|
|
22
|
+
* Claude Code hook never see it), under a test runner, after a failed command, and after commands that
|
|
23
|
+
* promise to stay offline or to talk to one host only (see {@link SKIPPED_COMMANDS}).
|
|
24
|
+
*/
|
|
25
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
26
|
+
if (k2 === undefined) k2 = k;
|
|
27
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
28
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
29
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
30
|
+
}
|
|
31
|
+
Object.defineProperty(o, k2, desc);
|
|
32
|
+
}) : (function(o, m, k, k2) {
|
|
33
|
+
if (k2 === undefined) k2 = k;
|
|
34
|
+
o[k2] = m[k];
|
|
35
|
+
}));
|
|
36
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
37
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
38
|
+
}) : function(o, v) {
|
|
39
|
+
o["default"] = v;
|
|
40
|
+
});
|
|
41
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
42
|
+
var ownKeys = function(o) {
|
|
43
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
44
|
+
var ar = [];
|
|
45
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
46
|
+
return ar;
|
|
47
|
+
};
|
|
48
|
+
return ownKeys(o);
|
|
49
|
+
};
|
|
50
|
+
return function (mod) {
|
|
51
|
+
if (mod && mod.__esModule) return mod;
|
|
52
|
+
var result = {};
|
|
53
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
54
|
+
__setModuleDefault(result, mod);
|
|
55
|
+
return result;
|
|
56
|
+
};
|
|
57
|
+
})();
|
|
58
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
59
|
+
exports.CHILD_SCRIPT = exports.SKIPPED_COMMANDS = exports.FETCH_TIMEOUT_MS = exports.CHECK_INTERVAL_MS = exports.REGISTRY_URL = exports.PACKAGE_NAME = void 0;
|
|
60
|
+
exports.parseVersion = parseVersion;
|
|
61
|
+
exports.cleanVersion = cleanVersion;
|
|
62
|
+
exports.isNewer = isNewer;
|
|
63
|
+
exports.updateCacheFile = updateCacheFile;
|
|
64
|
+
exports.readUpdateCache = readUpdateCache;
|
|
65
|
+
exports.writeUpdateCache = writeUpdateCache;
|
|
66
|
+
exports.isCheckDue = isCheckDue;
|
|
67
|
+
exports.isNoticeDue = isNoticeDue;
|
|
68
|
+
exports.commandOf = commandOf;
|
|
69
|
+
exports.isSilenced = isSilenced;
|
|
70
|
+
exports.noticeText = noticeText;
|
|
71
|
+
exports.fetchLatestVersion = fetchLatestVersion;
|
|
72
|
+
exports.refreshUpdateCache = refreshUpdateCache;
|
|
73
|
+
exports.startBackgroundCheck = startBackgroundCheck;
|
|
74
|
+
exports.afterCommand = afterCommand;
|
|
75
|
+
const child_process_1 = require("child_process");
|
|
76
|
+
const path = __importStar(require("path"));
|
|
77
|
+
const constants_1 = require("./constants");
|
|
78
|
+
const format_1 = require("./format");
|
|
79
|
+
const fsSafe_1 = require("./fsSafe");
|
|
80
|
+
const settings_1 = require("./settings");
|
|
81
|
+
exports.PACKAGE_NAME = 'promptlike';
|
|
82
|
+
exports.REGISTRY_URL = `https://registry.npmjs.org/${exports.PACKAGE_NAME}/latest`;
|
|
83
|
+
/** Both the interval between registry requests and between notices. */
|
|
84
|
+
exports.CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000;
|
|
85
|
+
exports.FETCH_TIMEOUT_MS = 2000;
|
|
86
|
+
/** A registry answer or cache entry longer than this is not a version. */
|
|
87
|
+
const MAX_VERSION_LENGTH = 20;
|
|
88
|
+
const VERSION_RE = /^\d+\.\d+\.\d+$/;
|
|
89
|
+
/**
|
|
90
|
+
* Commands after which nothing is checked. `suggest` is the Claude Code hook (it must stay instant
|
|
91
|
+
* and silent). The others are documented as network-free when signed out (`save`, `log`, `diff`,
|
|
92
|
+
* `rollback`: "No network access") or as talking to GitHub only (`import`) — a background request
|
|
93
|
+
* to a third host would make those sentences untrue.
|
|
94
|
+
*/
|
|
95
|
+
exports.SKIPPED_COMMANDS = new Set(['suggest', 'save', 'log', 'diff', 'rollback', 'import']);
|
|
96
|
+
// ---------------------------------------------------------------------------
|
|
97
|
+
// Versions
|
|
98
|
+
// ---------------------------------------------------------------------------
|
|
99
|
+
/** `x.y.z` (digits only, each part up to 9 digits so it stays an exact number) or null. */
|
|
100
|
+
function parseVersion(value) {
|
|
101
|
+
if (typeof value !== 'string' || value.length > MAX_VERSION_LENGTH || !VERSION_RE.test(value))
|
|
102
|
+
return null;
|
|
103
|
+
const parts = value.split('.');
|
|
104
|
+
if (parts.some((p) => p.length > 9))
|
|
105
|
+
return null;
|
|
106
|
+
return [Number(parts[0]), Number(parts[1]), Number(parts[2])];
|
|
107
|
+
}
|
|
108
|
+
/** The version string if it is a strict `x.y.z`, else null — the only shape that is ever stored or printed. */
|
|
109
|
+
function cleanVersion(value) {
|
|
110
|
+
return parseVersion(value) ? value : null;
|
|
111
|
+
}
|
|
112
|
+
/** True when `latest` is a higher version than `current`. Numeric, so 0.10.0 > 0.9.0. Anything unparsable: false. */
|
|
113
|
+
function isNewer(latest, current) {
|
|
114
|
+
const a = parseVersion(latest);
|
|
115
|
+
const b = parseVersion(current);
|
|
116
|
+
if (!a || !b)
|
|
117
|
+
return false;
|
|
118
|
+
for (let i = 0; i < 3; i++) {
|
|
119
|
+
if (a[i] !== b[i])
|
|
120
|
+
return a[i] > b[i];
|
|
121
|
+
}
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
function updateCacheFile() {
|
|
125
|
+
return path.join((0, settings_1.configDir)(), 'cache', 'update-check.json');
|
|
126
|
+
}
|
|
127
|
+
const isTime = (v) => typeof v === 'number' && Number.isFinite(v) && v >= 0;
|
|
128
|
+
/** The cache, or null when it is missing, unreadable or not shaped like ours (never throws). */
|
|
129
|
+
function readUpdateCache() {
|
|
130
|
+
const raw = (0, fsSafe_1.readPrivateFile)(updateCacheFile());
|
|
131
|
+
if (raw === null)
|
|
132
|
+
return null;
|
|
133
|
+
try {
|
|
134
|
+
const o = JSON.parse(raw);
|
|
135
|
+
if (typeof o !== 'object' || o === null || !isTime(o.checkedAt))
|
|
136
|
+
return null;
|
|
137
|
+
return {
|
|
138
|
+
checkedAt: o.checkedAt,
|
|
139
|
+
// A tampered or corrupt value is dropped, so it can never reach a terminal.
|
|
140
|
+
latest: cleanVersion(o.latest),
|
|
141
|
+
notifiedAt: isTime(o.notifiedAt) ? o.notifiedAt : 0,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function writeUpdateCache(cache) {
|
|
149
|
+
(0, fsSafe_1.writePrivateFile)(updateCacheFile(), JSON.stringify(cache) + '\n');
|
|
150
|
+
}
|
|
151
|
+
/** No cache, or the last request was started 24 hours ago or more (also when the clock moved back). */
|
|
152
|
+
function isCheckDue(cache, now) {
|
|
153
|
+
if (!cache)
|
|
154
|
+
return true;
|
|
155
|
+
const age = now - cache.checkedAt;
|
|
156
|
+
return age < 0 || age >= exports.CHECK_INTERVAL_MS;
|
|
157
|
+
}
|
|
158
|
+
/** The user was never told, or last told 24 hours ago or more. */
|
|
159
|
+
function isNoticeDue(cache, now) {
|
|
160
|
+
const age = now - cache.notifiedAt;
|
|
161
|
+
return cache.notifiedAt === 0 || age < 0 || age >= exports.CHECK_INTERVAL_MS;
|
|
162
|
+
}
|
|
163
|
+
/** First argument that is not an option: the command name. */
|
|
164
|
+
function commandOf(argv) {
|
|
165
|
+
return argv.find((a) => !a.startsWith('-'));
|
|
166
|
+
}
|
|
167
|
+
/** True when neither the cache is read nor a request made nor a line printed. */
|
|
168
|
+
function isSilenced(ctx) {
|
|
169
|
+
if (!(0, settings_1.updateCheckEnabled)(ctx.env, ctx.settings))
|
|
170
|
+
return true; // env switches, CI, ple config set update-check off
|
|
171
|
+
if (ctx.env.VITEST !== undefined || ctx.env.NODE_ENV === 'test')
|
|
172
|
+
return true; // under a test runner
|
|
173
|
+
if (!ctx.stdoutIsTTY || !ctx.stderrIsTTY)
|
|
174
|
+
return true; // pipes, agents, hooks, cron
|
|
175
|
+
if (ctx.exitCode)
|
|
176
|
+
return true; // a failed command is not the moment for a nag
|
|
177
|
+
if (!ctx.command || exports.SKIPPED_COMMANDS.has(ctx.command))
|
|
178
|
+
return true;
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
function noticeText(current, latest) {
|
|
182
|
+
return (`Update available: ${exports.PACKAGE_NAME} ${current} → ${latest} · npm i -g ${exports.PACKAGE_NAME}@latest ` +
|
|
183
|
+
'(turn off: ple config set update-check off)');
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Ask the registry for the latest version. Resolves to a strict `x.y.z` or null — on any problem:
|
|
187
|
+
* network error, timeout (2 s, body included), HTTP error, redirect, not JSON, or a `version` that
|
|
188
|
+
* is not a plain `x.y.z` of at most 20 characters. Nothing else from the response is looked at.
|
|
189
|
+
*/
|
|
190
|
+
async function fetchLatestVersion(fetchImpl = fetch) {
|
|
191
|
+
const controller = new AbortController();
|
|
192
|
+
const timer = setTimeout(() => controller.abort(), exports.FETCH_TIMEOUT_MS);
|
|
193
|
+
try {
|
|
194
|
+
const res = await fetchImpl(exports.REGISTRY_URL, {
|
|
195
|
+
signal: controller.signal,
|
|
196
|
+
redirect: 'error',
|
|
197
|
+
headers: { Accept: 'application/json' },
|
|
198
|
+
});
|
|
199
|
+
if (!res.ok)
|
|
200
|
+
return null;
|
|
201
|
+
const body = (await res.json());
|
|
202
|
+
return cleanVersion(body?.version);
|
|
203
|
+
}
|
|
204
|
+
catch {
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
finally {
|
|
208
|
+
clearTimeout(timer);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Store the registry's answer. A failed request keeps the previous `latest` — and the stamp that
|
|
213
|
+
* `startBackgroundCheck` already wrote, so the next attempt is a day away.
|
|
214
|
+
*/
|
|
215
|
+
async function refreshUpdateCache(now = Date.now(), fetchImpl) {
|
|
216
|
+
const latest = await fetchLatestVersion(fetchImpl);
|
|
217
|
+
// Read AFTER the request: another command may have shown a notice (and stored it) in the meantime.
|
|
218
|
+
const previous = readUpdateCache();
|
|
219
|
+
writeUpdateCache({
|
|
220
|
+
checkedAt: previous?.checkedAt ?? now,
|
|
221
|
+
latest: latest ?? previous?.latest ?? null,
|
|
222
|
+
notifiedAt: previous?.notifiedAt ?? 0,
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
const defaultSpawner = (execPath, args) => {
|
|
226
|
+
const child = (0, child_process_1.spawn)(execPath, args, { detached: true, stdio: 'ignore', windowsHide: true });
|
|
227
|
+
child.on('error', () => undefined);
|
|
228
|
+
child.unref();
|
|
229
|
+
};
|
|
230
|
+
/**
|
|
231
|
+
* Runs inside the background process: load this compiled module (its path is the one extra
|
|
232
|
+
* argument), ask the registry, store the answer, leave. A hard timer ends it even if a socket hangs.
|
|
233
|
+
*/
|
|
234
|
+
exports.CHILD_SCRIPT = 'setTimeout(() => process.exit(0), 5000).unref();' +
|
|
235
|
+
'require(process.argv[1]).refreshUpdateCache().then(() => process.exit(0), () => process.exit(0));';
|
|
236
|
+
/**
|
|
237
|
+
* Stamp the cache (that is the "one request per 24 hours" guarantee: it happens BEFORE the request, so
|
|
238
|
+
* a slow or failed check and a burst of commands cannot start a second one), then start the detached
|
|
239
|
+
* process. Returns false when nothing was started.
|
|
240
|
+
*/
|
|
241
|
+
function startBackgroundCheck(previous, now, opts = {}) {
|
|
242
|
+
// Only the compiled package can be loaded by the child; a source checkout run through a loader cannot.
|
|
243
|
+
const modulePath = opts.modulePath ?? __filename;
|
|
244
|
+
if (!modulePath.endsWith('.js'))
|
|
245
|
+
return false;
|
|
246
|
+
try {
|
|
247
|
+
(0, fsSafe_1.ensurePrivateDir)(path.dirname(updateCacheFile()));
|
|
248
|
+
writeUpdateCache({ checkedAt: now, latest: previous?.latest ?? null, notifiedAt: previous?.notifiedAt ?? 0 });
|
|
249
|
+
(opts.spawner ?? defaultSpawner)(process.execPath, ['-e', exports.CHILD_SCRIPT, modulePath]);
|
|
250
|
+
return true;
|
|
251
|
+
}
|
|
252
|
+
catch {
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Called once after a command ran. Prints the cached notice (at most one per 24 h) and starts the
|
|
258
|
+
* background check when it is due. Synchronous apart from the detached process, and it never throws.
|
|
259
|
+
* Returns what it did, for tests.
|
|
260
|
+
*/
|
|
261
|
+
function afterCommand(deps = {}) {
|
|
262
|
+
const result = { printed: false, started: false };
|
|
263
|
+
try {
|
|
264
|
+
const env = deps.env ?? process.env;
|
|
265
|
+
const settings = deps.settings ?? (0, settings_1.readSettings)();
|
|
266
|
+
const gate = {
|
|
267
|
+
command: commandOf(deps.argv ?? process.argv.slice(2)),
|
|
268
|
+
env,
|
|
269
|
+
stdoutIsTTY: deps.stdoutIsTTY ?? process.stdout.isTTY === true,
|
|
270
|
+
stderrIsTTY: deps.stderrIsTTY ?? process.stderr.isTTY === true,
|
|
271
|
+
settings,
|
|
272
|
+
exitCode: 'exitCode' in deps ? deps.exitCode : process.exitCode,
|
|
273
|
+
};
|
|
274
|
+
if (isSilenced(gate))
|
|
275
|
+
return result;
|
|
276
|
+
const current = deps.currentVersion ?? constants_1.CLI_VERSION;
|
|
277
|
+
if (current === '0.0.0')
|
|
278
|
+
return result; // the version could not be read: nothing to compare with
|
|
279
|
+
const now = deps.now ?? Date.now();
|
|
280
|
+
const cache = readUpdateCache();
|
|
281
|
+
let notified = cache;
|
|
282
|
+
if (cache && cache.latest && isNewer(cache.latest, current) && isNoticeDue(cache, now)) {
|
|
283
|
+
(deps.print ?? ((line) => console.error(format_1.c.muted(line))))(noticeText(current, cache.latest));
|
|
284
|
+
notified = { ...cache, notifiedAt: now };
|
|
285
|
+
writeUpdateCache(notified);
|
|
286
|
+
result.printed = true;
|
|
287
|
+
}
|
|
288
|
+
if (isCheckDue(cache, now)) {
|
|
289
|
+
result.started = startBackgroundCheck(notified, now, { spawner: deps.spawner, modulePath: deps.modulePath });
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
catch {
|
|
293
|
+
// an update notice must never get in the way of a command
|
|
294
|
+
}
|
|
295
|
+
return result;
|
|
296
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* `ple import --check`, the part that needs no terminal: has the file a prompt
|
|
4
|
+
* was imported from changed on GitHub since the text we last took from it?
|
|
5
|
+
*
|
|
6
|
+
* Compared by git blob id (what the tree lists), so an unchanged file costs no
|
|
7
|
+
* download. A changed one is read, put through the same gates as an import
|
|
8
|
+
* (secret scan, license — it may have changed too), and compared with the
|
|
9
|
+
* prompt's current text.
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.DIFF_LINES = void 0;
|
|
13
|
+
exports.checkUpstream = checkUpstream;
|
|
14
|
+
exports.diffPreview = diffPreview;
|
|
15
|
+
exports.upstreamChangelog = upstreamChangelog;
|
|
16
|
+
exports.blobFromChangelog = blobFromChangelog;
|
|
17
|
+
const format_1 = require("./format");
|
|
18
|
+
const diff_1 = require("./diff");
|
|
19
|
+
const github_1 = require("./github");
|
|
20
|
+
const githubImport_1 = require("./githubImport");
|
|
21
|
+
const githubSnapshot_1 = require("./githubSnapshot");
|
|
22
|
+
const scanners_1 = require("./scanners");
|
|
23
|
+
const HEX = /^[0-9a-f]{7,40}$/;
|
|
24
|
+
/** Where the file stands at the snapshot's commit, compared with `currentBody` (the prompt's text now). */
|
|
25
|
+
async function checkUpstream(snap, t, currentBody) {
|
|
26
|
+
const head = snap.byPath.get(t.file);
|
|
27
|
+
if (!head)
|
|
28
|
+
return { kind: 'removed' };
|
|
29
|
+
if (HEX.test(t.blob) && head.sha.startsWith(t.blob))
|
|
30
|
+
return { kind: 'up-to-date' };
|
|
31
|
+
const text = await (0, githubSnapshot_1.readFile)(snap, t.file, false);
|
|
32
|
+
if (text === null)
|
|
33
|
+
return { kind: 'refused', reason: 'it is now larger than 64 KB or not text — not applied' };
|
|
34
|
+
const read = (0, githubImport_1.readUpstream)(text);
|
|
35
|
+
if ('skip' in read)
|
|
36
|
+
return { kind: 'refused', reason: `${read.skip} — not applied` };
|
|
37
|
+
if ((0, scanners_1.hashBody)(read.body) === (0, scanners_1.hashBody)(currentBody))
|
|
38
|
+
return { kind: 'matches', blob: head.sha };
|
|
39
|
+
const verdict = await (0, githubSnapshot_1.gate)(snap, t.file, read.declaredLicense);
|
|
40
|
+
if (!verdict.allowed)
|
|
41
|
+
return { kind: 'license', verdict };
|
|
42
|
+
(0, github_1.rememberRaw)(snap.owner, snap.name, snap.commit, t.file, text);
|
|
43
|
+
return { kind: 'changed', body: read.body, blob: head.sha, verdict };
|
|
44
|
+
}
|
|
45
|
+
/** Longest diff printed per prompt; the rest is counted, not shown. */
|
|
46
|
+
exports.DIFF_LINES = 60;
|
|
47
|
+
/**
|
|
48
|
+
* Unified diff current → upstream for the terminal. Upstream text is cleaned of
|
|
49
|
+
* escape sequences BEFORE it is diffed (colors are added afterwards), and the
|
|
50
|
+
* output is cut at {@link DIFF_LINES} lines.
|
|
51
|
+
*/
|
|
52
|
+
function diffPreview(current, upstream, labels) {
|
|
53
|
+
const colored = format_1.c.success.level > 0;
|
|
54
|
+
const lines = (0, diff_1.unifiedDiff)((0, format_1.safeText)(current, true), (0, format_1.safeText)(upstream, true), {
|
|
55
|
+
fromLabel: (0, format_1.safeText)(labels.from),
|
|
56
|
+
toLabel: (0, format_1.safeText)(labels.to),
|
|
57
|
+
colors: colored ? { header: format_1.c.title, hunk: format_1.c.accent, add: format_1.c.success, del: format_1.c.error } : undefined,
|
|
58
|
+
});
|
|
59
|
+
if (lines.length <= exports.DIFF_LINES)
|
|
60
|
+
return lines;
|
|
61
|
+
return [...lines.slice(0, exports.DIFF_LINES), format_1.c.muted(`… ${lines.length - exports.DIFF_LINES} more lines`)];
|
|
62
|
+
}
|
|
63
|
+
/** `Upstream o/r@abc1234 (blob def5678)` — the changelog of an applied update; the next check reads the blob back from it. */
|
|
64
|
+
function upstreamChangelog(repo, commit, blob) {
|
|
65
|
+
return `Upstream ${repo}@${commit.slice(0, 7)} (blob ${blob.slice(0, 7)})`;
|
|
66
|
+
}
|
|
67
|
+
/** The blob an applied update recorded in a changelog, or null. */
|
|
68
|
+
function blobFromChangelog(changelog) {
|
|
69
|
+
const m = (changelog ?? '').match(/^Upstream .*\(blob ([0-9a-f]{7,40})\)/);
|
|
70
|
+
return m ? m[1] : null;
|
|
71
|
+
}
|
package/dist/program.js
CHANGED
|
@@ -28,6 +28,7 @@ const import_1 = require("./commands/import");
|
|
|
28
28
|
const log_1 = require("./commands/log");
|
|
29
29
|
const diff_1 = require("./commands/diff");
|
|
30
30
|
const rollback_1 = require("./commands/rollback");
|
|
31
|
+
const tag_1 = require("./commands/tag");
|
|
31
32
|
const suggest_1 = require("./commands/suggest");
|
|
32
33
|
const config_1 = require("./commands/config");
|
|
33
34
|
const repo_1 = require("./commands/repo");
|
|
@@ -71,23 +72,28 @@ function buildProgram() {
|
|
|
71
72
|
.action(runWithErrorHandler(save_1.saveCommand));
|
|
72
73
|
scope(program
|
|
73
74
|
.command('get <name>')
|
|
74
|
-
.description('Print a prompt raw to stdout; fill {{variables}} (agent/pipe friendly)')
|
|
75
|
+
.description('Print a prompt raw to stdout; fill {{variables}} and {{#if}} blocks (agent/pipe friendly)')
|
|
75
76
|
.option('-v, --var <keyval>', 'Fill a variable — key=value (repeatable)', get_1.collectVar, {})
|
|
76
|
-
.option('-c, --copy', 'Also copy the output to the clipboard')
|
|
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)'))
|
|
77
79
|
.addHelpText('after', '\nExample:\n ple get "code review" --var diff="$(git diff)" | claude')
|
|
78
80
|
.action(runWithErrorHandler(get_1.getCommand));
|
|
79
81
|
scope(program.command('show <name>').description('Show a prompt in the terminal')).action(runWithErrorHandler(show_1.showCommand));
|
|
80
|
-
scope(program
|
|
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));
|
|
81
87
|
scope(program
|
|
82
88
|
.command('list')
|
|
83
|
-
.description('List your prompts')
|
|
84
|
-
.option('-t, --tag <name>', 'Filter by
|
|
89
|
+
.description('List your prompts with their tags')
|
|
90
|
+
.option('-t, --tag <name>', 'Filter by tag; repeat to require several (all must match)', save_1.collectTag, [])
|
|
85
91
|
.option('-l, --limit <n>', 'Max number of rows (default 30)', '30'))
|
|
86
|
-
.addHelpText('after', '\nExamples:\n ple list --tag debug\n ple list --project my-prompts')
|
|
92
|
+
.addHelpText('after', '\nExamples:\n ple list --tag debug\n ple list --tag debug --tag review # only prompts that have both\n ple list --project my-prompts')
|
|
87
93
|
.action(runWithErrorHandler(list_1.listCommand));
|
|
88
94
|
program
|
|
89
95
|
.command('search <keyword>')
|
|
90
|
-
.description('Search titles and descriptions
|
|
96
|
+
.description('Search titles and descriptions; also finds prompts only on this machine (incl. body and tags)')
|
|
91
97
|
.action(runWithErrorHandler(search_1.searchCommand));
|
|
92
98
|
scope(program
|
|
93
99
|
.command('log <name>')
|
|
@@ -98,6 +104,12 @@ function buildProgram() {
|
|
|
98
104
|
.command('diff <name> [a] [b]')
|
|
99
105
|
.description('Diff two versions (default: previous ↔ current). Refs: 3, v3 or 1.0.2')
|
|
100
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)));
|
|
101
113
|
scope(program
|
|
102
114
|
.command('rollback <name> <version>')
|
|
103
115
|
.description('Restore an old version as a new one — nothing is deleted (signed out: local history)')
|
|
@@ -153,15 +165,34 @@ function buildProgram() {
|
|
|
153
165
|
.command('sync')
|
|
154
166
|
.description('Upload your local prompts to your account (one-way, explicit)')
|
|
155
167
|
.option('--dry-run', 'List what would be uploaded, change nothing')
|
|
168
|
+
.option('--project <repo>', 'Upload into this repo (name, slug, id or short id)')
|
|
156
169
|
.action(runWithErrorHandler(sync_1.syncCommand));
|
|
157
170
|
program
|
|
158
|
-
.command('import')
|
|
159
|
-
.description('Bring in prompts
|
|
171
|
+
.command('import [source]')
|
|
172
|
+
.description('Bring in prompts from a public GitHub repo (github:owner/repo) or your agent folders (--scan)')
|
|
160
173
|
.option('--scan', 'Scan this repo and your home folder for agent prompt files')
|
|
174
|
+
.option('--check', 'Check prompts imported from GitHub for upstream changes')
|
|
175
|
+
.option('--apply', 'With --check: add the upstream changes as new versions (nothing is overwritten)')
|
|
161
176
|
.option('--dry-run', 'Only show what was found, import nothing')
|
|
162
177
|
.option('-a, --all', 'Import everything new without asking')
|
|
163
178
|
.option('--project <repo>', 'Import into this repo (signed in)')
|
|
164
|
-
.
|
|
179
|
+
.addHelpText('after', [
|
|
180
|
+
'',
|
|
181
|
+
'Examples:',
|
|
182
|
+
' ple import github:anthropics/skills --dry-run # what is there, and under which license',
|
|
183
|
+
' ple import github:anthropics/skills/skills/pdf # one folder; pick 1,3-5 / all',
|
|
184
|
+
' ple import github:owner/repo@v1.2 --all # a tag, branch or commit; no questions',
|
|
185
|
+
' ple import --check # did anything change on GitHub since?',
|
|
186
|
+
' ple import --check --apply # add the changes as new versions',
|
|
187
|
+
' ple import --scan --dry-run # prompts already on this machine',
|
|
188
|
+
'',
|
|
189
|
+
'GitHub: public repositories only, and no token is used (without one GitHub allows 60 requests',
|
|
190
|
+
'an hour per IP address). A file is copied only when it has an open license (MIT, Apache-2.0,',
|
|
191
|
+
'BSD, ISC, CC0, CC BY …) — the rest are listed with a link. Each prompt keeps a link to its',
|
|
192
|
+
'source and license; --check never overwrites: an update is a new version, labels stay put.',
|
|
193
|
+
'Use github:<owner>/<repo>[/path][@ref] — a branch with a "/" in its name needs the @ref form.',
|
|
194
|
+
].join('\n'))
|
|
195
|
+
.action(runWithErrorHandler((source, opts) => (0, import_1.importCommand)({ ...opts, source })));
|
|
165
196
|
scope(program
|
|
166
197
|
.command('export [name]')
|
|
167
198
|
.description('Export a prompt (or a whole repo with --project) as an AGENTS.md section or an Agent Skill (SKILL.md)')
|
package/package.json
CHANGED