promptlike 0.9.0 → 0.10.1
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 +112 -0
- package/README.md +241 -27
- package/dist/commands/config.js +13 -0
- package/dist/commands/copy.js +10 -3
- package/dist/commands/get.js +11 -2
- 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 +31 -9
- package/dist/commands/login.js +6 -5
- package/dist/commands/save.js +1 -1
- package/dist/commands/search.js +73 -7
- package/dist/commands/show.js +11 -3
- package/dist/commands/suggest.js +100 -10
- package/dist/commands/sync.js +57 -13
- package/dist/index.js +7 -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 +80 -2
- package/dist/lib/loopApi.js +63 -11
- package/dist/lib/promptResolver.js +22 -9
- package/dist/lib/promptSource.js +123 -0
- 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 +26 -7
- package/package.json +1 -1
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* `ple import github:owner/repo[/path][@ref]` — bring prompts and skills from a
|
|
4
|
+
* PUBLIC GitHub repo into PLE, pinned to the commit they were read at.
|
|
5
|
+
*
|
|
6
|
+
* ple import github:anthropics/skills --dry-run # what is there, and under which license
|
|
7
|
+
* ple import github:anthropics/skills/skills/pdf # pick (1,3-5 / all)
|
|
8
|
+
* ple import github:owner/repo@v1.2 --all # a tag, branch or commit; no questions
|
|
9
|
+
*
|
|
10
|
+
* Only files with an open license are copied (MIT, Apache-2.0, BSD, ISC, CC0,
|
|
11
|
+
* CC BY …, decided per file — see lib/licenses.ts); the rest are listed with a
|
|
12
|
+
* link and never copied. Every import keeps a link to its source and license:
|
|
13
|
+
* in the description, and as provenance (`upstream_*` lines locally, origin
|
|
14
|
+
* meta in the account) so `ple import --check` can follow upstream changes.
|
|
15
|
+
*
|
|
16
|
+
* Signed out → the local store. Signed in → the account. No GitHub token is
|
|
17
|
+
* used or read; see lib/github.ts for exactly what is sent.
|
|
18
|
+
*/
|
|
19
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
20
|
+
if (k2 === undefined) k2 = k;
|
|
21
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
22
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
23
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
24
|
+
}
|
|
25
|
+
Object.defineProperty(o, k2, desc);
|
|
26
|
+
}) : (function(o, m, k, k2) {
|
|
27
|
+
if (k2 === undefined) k2 = k;
|
|
28
|
+
o[k2] = m[k];
|
|
29
|
+
}));
|
|
30
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
31
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
32
|
+
}) : function(o, v) {
|
|
33
|
+
o["default"] = v;
|
|
34
|
+
});
|
|
35
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
36
|
+
var ownKeys = function(o) {
|
|
37
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
38
|
+
var ar = [];
|
|
39
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
40
|
+
return ar;
|
|
41
|
+
};
|
|
42
|
+
return ownKeys(o);
|
|
43
|
+
};
|
|
44
|
+
return function (mod) {
|
|
45
|
+
if (mod && mod.__esModule) return mod;
|
|
46
|
+
var result = {};
|
|
47
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
48
|
+
__setModuleDefault(result, mod);
|
|
49
|
+
return result;
|
|
50
|
+
};
|
|
51
|
+
})();
|
|
52
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
+
exports.importGithubCommand = importGithubCommand;
|
|
54
|
+
const history = __importStar(require("../lib/localHistory"));
|
|
55
|
+
const store = __importStar(require("../lib/localStore"));
|
|
56
|
+
const api_client_1 = require("../lib/api-client");
|
|
57
|
+
const format_1 = require("../lib/format");
|
|
58
|
+
const githubImport_1 = require("../lib/githubImport");
|
|
59
|
+
const githubSnapshot_1 = require("../lib/githubSnapshot");
|
|
60
|
+
const githubSpec_1 = require("../lib/githubSpec");
|
|
61
|
+
const importOrigins_1 = require("../lib/importOrigins");
|
|
62
|
+
const importShared_1 = require("../lib/importShared");
|
|
63
|
+
const licenses_1 = require("../lib/licenses");
|
|
64
|
+
const promptResolver_1 = require("../lib/promptResolver");
|
|
65
|
+
const scanners_1 = require("../lib/scanners");
|
|
66
|
+
const local_1 = require("./local");
|
|
67
|
+
/** What is already there: body hashes, and which GitHub files came in before (repo@ref:path). */
|
|
68
|
+
async function alreadyThere(signedOut) {
|
|
69
|
+
if (signedOut) {
|
|
70
|
+
const all = store.list();
|
|
71
|
+
return {
|
|
72
|
+
hashes: new Set(all.map((p) => (0, scanners_1.hashBody)(p.body))),
|
|
73
|
+
files: new Set(all.flatMap((p) => (p.upstream ? [(0, githubImport_1.trackedKey)(p.upstream.repo, p.upstream.ref, p.upstream.path)] : []))),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
// Best effort, like `--scan`: the server drops a duplicate hash itself.
|
|
77
|
+
try {
|
|
78
|
+
const state = await (0, importOrigins_1.fetchImportOrigins)();
|
|
79
|
+
const files = (state.origins ?? []).flatMap((o) => o.meta?.source === 'github' && o.meta.repo && o.meta.ref && o.meta.file ? [(0, githubImport_1.trackedKey)(o.meta.repo, o.meta.ref, o.meta.file)] : []);
|
|
80
|
+
return { hashes: state.knownHashes, files: new Set(files) };
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return { hashes: new Set(), files: new Set() };
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function printRow(index, item) {
|
|
87
|
+
const cand = item.candidate;
|
|
88
|
+
console.log(` ${format_1.c.accent(String(index + 1).padStart(3))} ${cand.pick.kind.padEnd(7)} ${(0, format_1.safeText)(item.verdict.spdx ?? '-').padEnd(12)} ` +
|
|
89
|
+
`${(0, format_1.truncate)(cand.title, 40).padEnd(40)} ${format_1.c.muted((0, importShared_1.formatSize)(cand.bytes).padStart(8))} ${format_1.c.muted((0, format_1.safeText)(cand.pick.path))}`);
|
|
90
|
+
const note = (text) => console.log(format_1.c.muted(` ${text}`));
|
|
91
|
+
if (cand.pick.extraFiles > 0) {
|
|
92
|
+
note(`(+${cand.pick.extraFiles} file${cand.pick.extraFiles === 1 ? '' : 's'} not imported — scripts/references stay on GitHub)`);
|
|
93
|
+
}
|
|
94
|
+
if (item.verdict.shareAlike)
|
|
95
|
+
note(licenses_1.SHARE_ALIKE_NOTE);
|
|
96
|
+
if (cand.variables.length > 0)
|
|
97
|
+
note(`variables: ${cand.variables.map((v) => `{{${(0, format_1.safeText)(v)}}}`).join(', ')}`);
|
|
98
|
+
for (const w of cand.warnings)
|
|
99
|
+
console.log(format_1.c.warn(` ⚠ ${w}`));
|
|
100
|
+
}
|
|
101
|
+
async function importGithubCommand(source, options = {}, deps = {}) {
|
|
102
|
+
const spec = (0, githubSpec_1.parseGithubSpec)(source);
|
|
103
|
+
const signedOut = (0, local_1.isSignedOut)();
|
|
104
|
+
if (!signedOut)
|
|
105
|
+
await (0, api_client_1.ensureAuthed)();
|
|
106
|
+
const destination = signedOut ? 'your local store' : 'your account';
|
|
107
|
+
const snap = await (0, githubSnapshot_1.loadSnapshot)(spec.owner, spec.repo, spec.ref);
|
|
108
|
+
const where = `github.com/${snap.repo}@${(0, format_1.safeText)(snap.ref)}`;
|
|
109
|
+
const { items, blocked, skipped } = await (0, githubImport_1.collectItems)(snap, spec);
|
|
110
|
+
if (items.length === 0 && blocked.length === 0 && skipped.length === 0) {
|
|
111
|
+
console.log(format_1.c.muted(`No prompt files found in ${where}${spec.path ? ` under '${(0, format_1.safeText)(spec.path)}'` : ''}.`));
|
|
112
|
+
console.log(format_1.c.muted('Looked for SKILL.md, *.prompt.md, .claude/commands, .cursor/commands, *.mdc, Fabric patterns, AGENTS.md and CLAUDE.md.'));
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const known = await alreadyThere(signedOut);
|
|
116
|
+
const fresh = items.filter((it) => !known.files.has((0, githubImport_1.trackedKey)(snap.repo, snap.ref, it.candidate.pick.path)) && !known.hashes.has(it.candidate.sha256));
|
|
117
|
+
const already = items.length - fresh.length;
|
|
118
|
+
console.log(format_1.c.title(`Found ${items.length} prompt file${items.length === 1 ? '' : 's'} in ${where} (${snap.commit.slice(0, 7)})`) +
|
|
119
|
+
format_1.c.muted(` → ${destination}`));
|
|
120
|
+
fresh.forEach((it, i) => printRow(i, it));
|
|
121
|
+
if (already > 0) {
|
|
122
|
+
console.log(format_1.c.muted(` … and ${already} already imported — skipped (upstream changes: ple import --check)`));
|
|
123
|
+
}
|
|
124
|
+
for (const b of blocked) {
|
|
125
|
+
const found = b.found ? ` (${(0, format_1.safeText)(b.found)} is not one of the accepted licenses)` : '';
|
|
126
|
+
console.log(format_1.c.warn(` ⚠ ${(0, format_1.safeText)(b.path)}: not imported — no open license found${found}`) + format_1.c.muted(` ${b.url}`));
|
|
127
|
+
}
|
|
128
|
+
for (const s of skipped) {
|
|
129
|
+
console.log(format_1.c.warn(` ⚠ ${(0, format_1.safeText)(s.path)}: ${s.reason}`));
|
|
130
|
+
}
|
|
131
|
+
console.log(format_1.c.muted('Check for upstream changes later: ple import --check'));
|
|
132
|
+
if (fresh.length === 0) {
|
|
133
|
+
console.log(format_1.c.success('\nNothing new to import.'));
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (options.dryRun) {
|
|
137
|
+
console.log(format_1.c.muted(`\nDry run — nothing imported. Run \`ple import ${(0, format_1.safeText)(source)}\` to pick, or add --all.`));
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const selected = await (0, importShared_1.chooseRows)(fresh, options.all, deps);
|
|
141
|
+
if (!selected)
|
|
142
|
+
return;
|
|
143
|
+
if (signedOut) {
|
|
144
|
+
const note = `Imported from github:${snap.repo}@${snap.commit.slice(0, 7)}`;
|
|
145
|
+
for (const it of selected) {
|
|
146
|
+
const cand = it.candidate;
|
|
147
|
+
const slug = (0, importShared_1.freeSlug)(cand.title);
|
|
148
|
+
const saved = store.save({
|
|
149
|
+
slug,
|
|
150
|
+
title: cand.title,
|
|
151
|
+
description: it.description,
|
|
152
|
+
tags: cand.tags,
|
|
153
|
+
body: cand.body,
|
|
154
|
+
upstream: (0, githubImport_1.buildUpstream)(snap, cand, it.verdict, it.url),
|
|
155
|
+
});
|
|
156
|
+
history.recordIfChanged(slug, { title: saved.title, description: saved.description, tags: saved.tags, body: saved.body }, { note });
|
|
157
|
+
}
|
|
158
|
+
console.log(format_1.c.success(`✓ Imported ${selected.length} prompt${selected.length === 1 ? '' : 's'} into ${store.promptsDir()}`));
|
|
159
|
+
console.log(format_1.c.muted('Sign in and run `ple sync` to carry them to your account (history, web, agents).'));
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const projectId = options.project ? await (0, promptResolver_1.resolveProjectId)(options.project) : undefined;
|
|
163
|
+
const payload = selected.map((it) => ({
|
|
164
|
+
title: it.candidate.title,
|
|
165
|
+
description: it.description,
|
|
166
|
+
content: it.candidate.body,
|
|
167
|
+
tags: it.candidate.tags,
|
|
168
|
+
origin: (0, githubImport_1.buildOrigin)(snap, it.candidate, it.verdict, it.url),
|
|
169
|
+
}));
|
|
170
|
+
await (0, importShared_1.uploadPrompts)(payload, { projectId, retryCommand: `ple import ${(0, format_1.safeText)(source)}` });
|
|
171
|
+
}
|
package/dist/commands/list.js
CHANGED
|
@@ -7,43 +7,109 @@ const promptResolver_1 = require("../lib/promptResolver");
|
|
|
7
7
|
const constants_1 = require("../lib/constants");
|
|
8
8
|
const format_1 = require("../lib/format");
|
|
9
9
|
const libraryCache_1 = require("../lib/libraryCache");
|
|
10
|
+
const promptSource_1 = require("../lib/promptSource");
|
|
11
|
+
const localStore_1 = require("../lib/localStore");
|
|
12
|
+
const tagFilter_1 = require("../lib/tagFilter");
|
|
13
|
+
/** The API returns at most 100 rows per page. */
|
|
14
|
+
const TAG_PAGE_SIZE = 100;
|
|
15
|
+
/** Multi-tag lookups read at most this many pages (10 × 100 prompts carrying the first tag). */
|
|
16
|
+
const MAX_TAG_PAGES = 10;
|
|
17
|
+
/** Width of the TAGS cell. It is the last column, so rows without tags carry no padding. */
|
|
18
|
+
const TAGS_WIDTH = 24;
|
|
10
19
|
/**
|
|
11
|
-
* `ple list [--tag X] [--limit N]` — list the user's prompts.
|
|
20
|
+
* `ple list [--tag X]… [--limit N]` — list the user's prompts.
|
|
12
21
|
*
|
|
13
|
-
* Tag filtering is done server-side (`?tag=`)
|
|
14
|
-
*
|
|
15
|
-
*
|
|
22
|
+
* Tag filtering is done server-side for ONE tag (`?tag=`). With several `--tag` flags the first
|
|
23
|
+
* tag goes to the server, the pages are read (≤10) and the other tags are checked here, so a
|
|
24
|
+
* prompt has to carry all of them; then the result is cut to `--limit`. The table shows
|
|
25
|
+
* id / title / updated / tags.
|
|
26
|
+
*
|
|
27
|
+
* Signed in, an unfiltered list ends with one muted line when prompts exist
|
|
28
|
+
* only on this machine (see {@link printLocalOnlyHint}) — they are not rows of
|
|
29
|
+
* the account table, and silence would read as data loss.
|
|
16
30
|
*/
|
|
17
31
|
async function listCommand(options) {
|
|
18
32
|
const limit = Math.max(1, Math.min(100, parseInt(options.limit ?? '30', 10) || 30));
|
|
33
|
+
const tags = (0, tagFilter_1.parseTagFilter)(options.tag);
|
|
19
34
|
// Signed out → the local store. The install has to be useful on its own.
|
|
20
35
|
if ((0, local_1.isSignedOut)()) {
|
|
21
36
|
(0, local_1.noteIgnoredProject)(options.project);
|
|
22
|
-
(0, local_1.localList)({
|
|
37
|
+
(0, local_1.localList)({ tags, limit });
|
|
23
38
|
return;
|
|
24
39
|
}
|
|
25
40
|
await (0, api_client_1.ensureAuthed)();
|
|
26
41
|
const projectId = options.project ? await (0, promptResolver_1.resolveProjectId)(options.project) : undefined;
|
|
27
|
-
const prompts = await (
|
|
42
|
+
const { rows: prompts, capped } = await fetchPrompts(tags, limit, projectId);
|
|
28
43
|
// Keep the suggestion cache (W1-5) in step with the account — detached,
|
|
29
44
|
// at most once a minute, never slows this command down.
|
|
30
45
|
(0, libraryCache_1.startBackgroundRefresh)();
|
|
31
46
|
if (prompts.length === 0) {
|
|
32
|
-
if (
|
|
33
|
-
console.log(format_1.c.muted(`No prompts matched
|
|
47
|
+
if (tags.length > 0) {
|
|
48
|
+
console.log(format_1.c.muted(`No prompts matched ${(0, tagFilter_1.describeTags)(tags)}${tags.length > 1 ? ' (all must match)' : ''}.`));
|
|
34
49
|
}
|
|
35
50
|
else {
|
|
36
51
|
console.log(format_1.c.muted(options.project ? `No prompts in '${options.project}' yet.` : `No prompts yet. Create one at ${constants_1.WEB_APP_URL}`));
|
|
37
52
|
}
|
|
38
|
-
return;
|
|
39
53
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
54
|
+
else {
|
|
55
|
+
console.log(format_1.c.label('ID TITLE UPDATED TAGS'));
|
|
56
|
+
console.log(format_1.c.label(`──────── ──────────────────────────────────────── ────────── ${'─'.repeat(TAGS_WIDTH)}`));
|
|
57
|
+
for (const p of prompts) {
|
|
58
|
+
const id = format_1.c.muted((0, format_1.shortId)(p.id));
|
|
59
|
+
const title = (0, format_1.truncate)(p.title, 40).padEnd(40);
|
|
60
|
+
const tagCell = (0, format_1.formatTags)((p.tags ?? []).map((t) => t.name), TAGS_WIDTH);
|
|
61
|
+
// UPDATED is padded only when a TAGS cell follows — no trailing spaces on untagged rows.
|
|
62
|
+
const ago = (0, format_1.timeAgo)(p.updated_at);
|
|
63
|
+
const updated = format_1.c.muted(tagCell ? ago.padEnd(10) : ago);
|
|
64
|
+
console.log(`${id} ${title} ${updated}${tagCell ? ` ${format_1.c.muted(tagCell)}` : ''}`);
|
|
65
|
+
}
|
|
66
|
+
console.log(format_1.c.muted(`\n${prompts.length} prompt${prompts.length === 1 ? '' : 's'} listed.`));
|
|
67
|
+
}
|
|
68
|
+
if (capped) {
|
|
69
|
+
console.error(format_1.c.muted(`Looked through the newest ${MAX_TAG_PAGES * TAG_PAGE_SIZE} prompts tagged '${tags[0]}' only — ` +
|
|
70
|
+
'add --project to narrow it down.'));
|
|
71
|
+
}
|
|
72
|
+
// A tag or repo filter asks a narrower question; the hint belongs to the plain "what do I have" list.
|
|
73
|
+
if (tags.length === 0 && !options.project)
|
|
74
|
+
printLocalOnlyHint(prompts, limit);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Account rows for the requested tags. One tag (or none) is a single request, as before. For
|
|
78
|
+
* several: the server filters by the first, and a page-by-page walk keeps the prompts that carry
|
|
79
|
+
* every tag until `limit` are found, the pages run out, or {@link MAX_TAG_PAGES} is reached.
|
|
80
|
+
*/
|
|
81
|
+
async function fetchPrompts(tags, limit, projectId) {
|
|
82
|
+
if (tags.length <= 1) {
|
|
83
|
+
return { rows: await (0, api_client_1.listPrompts)({ tag: tags[0], limit, projectId }), capped: false };
|
|
84
|
+
}
|
|
85
|
+
const rows = [];
|
|
86
|
+
for (let page = 1; page <= MAX_TAG_PAGES; page++) {
|
|
87
|
+
const batch = await (0, api_client_1.listPrompts)({ tag: tags[0], limit: TAG_PAGE_SIZE, page, projectId });
|
|
88
|
+
for (const p of batch)
|
|
89
|
+
if ((0, tagFilter_1.hasAllTags)(p.tags, tags))
|
|
90
|
+
rows.push(p);
|
|
91
|
+
if (rows.length >= limit)
|
|
92
|
+
return { rows: rows.slice(0, limit), capped: false };
|
|
93
|
+
if (batch.length < TAG_PAGE_SIZE)
|
|
94
|
+
return { rows, capped: false };
|
|
47
95
|
}
|
|
48
|
-
|
|
96
|
+
return { rows, capped: true };
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* "N prompts only on this machine" — local prompts whose titles the account does not have.
|
|
100
|
+
* Titles are compared against the whole account library from the suggestion cache when there
|
|
101
|
+
* is one (local read, no request), plus the rows just fetched. Without a cache and with a
|
|
102
|
+
* cut-off page the library is not known, so nothing is claimed (the background refresh that
|
|
103
|
+
* `list` just started makes the next run exact).
|
|
104
|
+
*/
|
|
105
|
+
function printLocalOnlyHint(fetched, limit) {
|
|
106
|
+
const { titles, complete } = (0, promptSource_1.accountTitleSet)(fetched, fetched.length < limit);
|
|
107
|
+
if (!complete)
|
|
108
|
+
return;
|
|
109
|
+
const only = (0, promptSource_1.localOnly)(titles);
|
|
110
|
+
if (only.length === 0)
|
|
111
|
+
return;
|
|
112
|
+
const n = only.length;
|
|
113
|
+
console.log(format_1.c.muted(`${n} local prompt${n === 1 ? '' : 's'} only on this machine, not in your account (${(0, localStore_1.promptsDir)()}) — ` +
|
|
114
|
+
`'ple sync' uploads ${n === 1 ? 'it' : 'them'}.`));
|
|
49
115
|
}
|
package/dist/commands/local.js
CHANGED
|
@@ -45,13 +45,17 @@ exports.emptyHint = emptyHint;
|
|
|
45
45
|
exports.resolveOrExplain = resolveOrExplain;
|
|
46
46
|
exports.localList = localList;
|
|
47
47
|
exports.localShow = localShow;
|
|
48
|
+
exports.showLocalPrompt = showLocalPrompt;
|
|
48
49
|
exports.localGet = localGet;
|
|
50
|
+
exports.getLocalPrompt = getLocalPrompt;
|
|
49
51
|
exports.localCopy = localCopy;
|
|
52
|
+
exports.copyLocalPrompt = copyLocalPrompt;
|
|
50
53
|
exports.localSearch = localSearch;
|
|
51
54
|
const store = __importStar(require("../lib/localStore"));
|
|
52
55
|
const config_1 = require("../lib/config");
|
|
53
56
|
const clipboard_1 = require("../lib/clipboard");
|
|
54
57
|
const format_1 = require("../lib/format");
|
|
58
|
+
const tagFilter_1 = require("../lib/tagFilter");
|
|
55
59
|
const promptVariables_1 = require("../lib/promptVariables");
|
|
56
60
|
/**
|
|
57
61
|
* Routing guard for the read commands: true → use the local store.
|
|
@@ -102,27 +106,33 @@ function resolveOrExplain(name) {
|
|
|
102
106
|
}
|
|
103
107
|
return hit.prompt;
|
|
104
108
|
}
|
|
109
|
+
/** Width of the TAGS cell in the list tables (the last column — untagged rows carry no padding). */
|
|
110
|
+
const TAGS_WIDTH = 24;
|
|
111
|
+
/** `tags`: every one has to be on a prompt ("all must match"), ignoring case. */
|
|
105
112
|
function localList(options) {
|
|
113
|
+
const wanted = options.tags ?? [];
|
|
106
114
|
let rows = store.list();
|
|
107
|
-
if (
|
|
108
|
-
|
|
109
|
-
rows = rows.filter((p) => p.tags.some((t) => t.toLowerCase() === tag));
|
|
115
|
+
if (wanted.length > 0) {
|
|
116
|
+
rows = rows.filter((p) => (0, tagFilter_1.hasAllLocalTags)(p.tags, wanted));
|
|
110
117
|
}
|
|
111
118
|
if (rows.length === 0) {
|
|
112
|
-
if (
|
|
113
|
-
console.log(format_1.c.muted(`No local prompts tagged '${
|
|
119
|
+
if (wanted.length > 0)
|
|
120
|
+
console.log(format_1.c.muted(`No local prompts tagged ${wanted.map((t) => `'${t}'`).join(' + ')}${wanted.length > 1 ? ' (all must match)' : ''}.`));
|
|
114
121
|
else
|
|
115
122
|
emptyHint();
|
|
116
123
|
return;
|
|
117
124
|
}
|
|
118
125
|
rows = rows.slice(0, options.limit);
|
|
119
|
-
console.log(format_1.c.label('NAME TITLE UPDATED'));
|
|
120
|
-
console.log(format_1.c.label(
|
|
126
|
+
console.log(format_1.c.label('NAME TITLE UPDATED TAGS'));
|
|
127
|
+
console.log(format_1.c.label(`──────────────────────── ──────────────────────────────────────── ────────── ${'─'.repeat(TAGS_WIDTH)}`));
|
|
121
128
|
for (const p of rows) {
|
|
122
129
|
const slug = format_1.c.muted((0, format_1.truncate)(p.slug, 24).padEnd(24));
|
|
123
130
|
const title = (0, format_1.truncate)(p.title, 40).padEnd(40);
|
|
124
|
-
const
|
|
125
|
-
|
|
131
|
+
const tagCell = (0, format_1.formatTags)(p.tags, TAGS_WIDTH);
|
|
132
|
+
// UPDATED is padded only when a TAGS cell follows — no trailing spaces on untagged rows.
|
|
133
|
+
const ago = p.updated ? (0, format_1.timeAgo)(p.updated) : '';
|
|
134
|
+
const updated = format_1.c.muted(tagCell ? ago.padEnd(10) : ago);
|
|
135
|
+
console.log(`${slug} ${title} ${updated}${tagCell ? ` ${format_1.c.muted(tagCell)}` : ''}`);
|
|
126
136
|
}
|
|
127
137
|
console.log(format_1.c.muted(`\n${rows.length} local prompt${rows.length === 1 ? '' : 's'} · stored in ${store.promptsDir()}`));
|
|
128
138
|
}
|
|
@@ -130,6 +140,10 @@ function localShow(name) {
|
|
|
130
140
|
const p = resolveOrExplain(name);
|
|
131
141
|
if (!p)
|
|
132
142
|
return;
|
|
143
|
+
showLocalPrompt(p);
|
|
144
|
+
}
|
|
145
|
+
/** Render one local prompt (shared by the signed-out `show` and the signed-in local fallback). */
|
|
146
|
+
function showLocalPrompt(p) {
|
|
133
147
|
console.log();
|
|
134
148
|
console.log(format_1.c.title(p.title));
|
|
135
149
|
const meta = [p.slug, p.updated ? `updated ${(0, format_1.timeAgo)(p.updated)}` : ''].filter(Boolean).join(' · ');
|
|
@@ -148,6 +162,10 @@ async function localGet(name, values, copy) {
|
|
|
148
162
|
const p = resolveOrExplain(name);
|
|
149
163
|
if (!p)
|
|
150
164
|
return;
|
|
165
|
+
await getLocalPrompt(p, values, copy);
|
|
166
|
+
}
|
|
167
|
+
/** Print one local prompt raw to stdout (shared by the signed-out `get` and the signed-in local fallback). */
|
|
168
|
+
async function getLocalPrompt(p, values, copy) {
|
|
151
169
|
if (!p.body.trim()) {
|
|
152
170
|
console.error(format_1.c.error(`'${p.title}' has empty content.`));
|
|
153
171
|
process.exitCode = 1;
|
|
@@ -175,6 +193,10 @@ async function localCopy(name, values = {}) {
|
|
|
175
193
|
const p = resolveOrExplain(name);
|
|
176
194
|
if (!p)
|
|
177
195
|
return;
|
|
196
|
+
await copyLocalPrompt(p, values);
|
|
197
|
+
}
|
|
198
|
+
/** Copy one local prompt to the clipboard (shared by the signed-out `copy` and the signed-in local fallback). */
|
|
199
|
+
async function copyLocalPrompt(p, values = {}) {
|
|
178
200
|
if (!p.body.trim()) {
|
|
179
201
|
console.error(format_1.c.error(`'${p.title}' has empty content.`));
|
|
180
202
|
process.exitCode = 1;
|
package/dist/commands/login.js
CHANGED
|
@@ -62,13 +62,14 @@ async function loginCommand() {
|
|
|
62
62
|
const config = await (0, api_client_1.login)(email, password);
|
|
63
63
|
console.log(format_1.c.success(`✓ Logged in as ${config.email}`));
|
|
64
64
|
console.log(format_1.c.muted("Next: run 'ple list' to see your prompts."));
|
|
65
|
-
//
|
|
66
|
-
// signed out
|
|
67
|
-
//
|
|
65
|
+
// Signed in, the commands read the ACCOUNT library first; prompts saved while
|
|
66
|
+
// signed out stay usable (get/show/copy fall back to them, list and search
|
|
67
|
+
// point to them). Say so once, and name the bridge: `ple sync`.
|
|
68
68
|
const localCount = store.list().length;
|
|
69
69
|
if (localCount > 0) {
|
|
70
|
-
console.log(format_1.c.muted(`${localCount} local prompt${localCount === 1 ? '' : 's'} on this machine
|
|
71
|
-
'
|
|
70
|
+
console.log(format_1.c.muted(`${localCount} local prompt${localCount === 1 ? '' : 's'} on this machine stay usable while signed in ` +
|
|
71
|
+
'(ple get/show/copy fall back to them; ple list and ple search point to them) — ' +
|
|
72
|
+
'to add them to your account: ple sync --dry-run'));
|
|
72
73
|
}
|
|
73
74
|
}
|
|
74
75
|
/** Read a single line with standard readline. */
|
package/dist/commands/save.js
CHANGED
|
@@ -118,7 +118,7 @@ async function saveCommand(title, options = {}) {
|
|
|
118
118
|
process.exitCode = 1;
|
|
119
119
|
return;
|
|
120
120
|
}
|
|
121
|
-
const slug = store.
|
|
121
|
+
const slug = store.slugFor(cleanTitle);
|
|
122
122
|
const previous = store.read(slug);
|
|
123
123
|
// Overwriting someone's prompt silently is the one unrecoverable thing this
|
|
124
124
|
// command could do — the old text is kept in the local history
|
package/dist/commands/search.js
CHANGED
|
@@ -1,15 +1,56 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
exports.searchCommand = searchCommand;
|
|
4
37
|
const api_client_1 = require("../lib/api-client");
|
|
5
38
|
const local_1 = require("./local");
|
|
6
39
|
const format_1 = require("../lib/format");
|
|
40
|
+
const promptSource_1 = require("../lib/promptSource");
|
|
41
|
+
const store = __importStar(require("../lib/localStore"));
|
|
42
|
+
/** Local-only matches shown before "…and N more". */
|
|
43
|
+
const LOCAL_ONLY_SHOWN = 10;
|
|
7
44
|
/**
|
|
8
45
|
* `ple search <keyword>` — search over title + description.
|
|
9
46
|
*
|
|
10
47
|
* Delegates to the web API's `/api/prompts?search=` (which escapes the input
|
|
11
48
|
* and searches title/description). Searching prompt version bodies would need
|
|
12
49
|
* a separate full-text index; matching titles/descriptions is fast and enough.
|
|
50
|
+
*
|
|
51
|
+
* Signed in, prompts that exist only on this machine are searched too (title,
|
|
52
|
+
* description, tags and body, like the signed-out search) and listed under their
|
|
53
|
+
* own heading, so a prompt saved before `ple login` does not seem to be gone.
|
|
13
54
|
*/
|
|
14
55
|
async function searchCommand(keyword) {
|
|
15
56
|
const trimmed = keyword.trim();
|
|
@@ -24,17 +65,42 @@ async function searchCommand(keyword) {
|
|
|
24
65
|
}
|
|
25
66
|
await (0, api_client_1.ensureAuthed)();
|
|
26
67
|
const rows = await (0, api_client_1.listPrompts)({ search: trimmed, limit: 30 });
|
|
27
|
-
|
|
68
|
+
// A local prompt that is already in the account is not "only here": compare against every title
|
|
69
|
+
// the account is known to have (the suggestion cache, when there is one), not just these results —
|
|
70
|
+
// the local search also reads bodies and tags, which the server's search does not.
|
|
71
|
+
const onlyHere = (0, promptSource_1.localOnly)((0, promptSource_1.accountTitleSet)(rows, false).titles, store.search(trimmed));
|
|
72
|
+
if (rows.length === 0 && onlyHere.length === 0) {
|
|
28
73
|
console.log(format_1.c.muted(`No prompts matched '${trimmed}'.`));
|
|
29
74
|
return;
|
|
30
75
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
76
|
+
if (rows.length === 0) {
|
|
77
|
+
console.log(format_1.c.muted(`No prompts in your account matched '${trimmed}'.`));
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
console.log(format_1.c.label(`${rows.length} result${rows.length === 1 ? '' : 's'}:`));
|
|
81
|
+
console.log();
|
|
82
|
+
for (const r of rows) {
|
|
83
|
+
console.log(`${format_1.c.title(r.title)} ${format_1.c.muted(`· ${(0, format_1.shortId)(r.id)} · ${(0, format_1.timeAgo)(r.updated_at)}`)}`);
|
|
84
|
+
if (r.description) {
|
|
85
|
+
console.log(` ${format_1.c.muted((0, format_1.truncate)(r.description, 80))}`);
|
|
86
|
+
}
|
|
37
87
|
}
|
|
38
88
|
}
|
|
89
|
+
if (onlyHere.length > 0)
|
|
90
|
+
printLocalOnly(onlyHere);
|
|
91
|
+
console.log();
|
|
92
|
+
}
|
|
93
|
+
function printLocalOnly(matches) {
|
|
39
94
|
console.log();
|
|
95
|
+
console.log(format_1.c.label('On this machine only:'));
|
|
96
|
+
for (const p of matches.slice(0, LOCAL_ONLY_SHOWN)) {
|
|
97
|
+
const updated = p.updated ? ` · ${(0, format_1.timeAgo)(p.updated)}` : '';
|
|
98
|
+
console.log(`${format_1.c.title((0, format_1.truncate)((0, format_1.safeText)(p.title), 60))} ${format_1.c.muted(`· ${(0, format_1.truncate)((0, format_1.safeText)(p.slug), 40)}${updated}`)}`);
|
|
99
|
+
if (p.description)
|
|
100
|
+
console.log(` ${format_1.c.muted((0, format_1.truncate)((0, format_1.safeText)(p.description), 80))}`);
|
|
101
|
+
}
|
|
102
|
+
if (matches.length > LOCAL_ONLY_SHOWN) {
|
|
103
|
+
console.log(format_1.c.muted(`…and ${matches.length - LOCAL_ONLY_SHOWN} more`));
|
|
104
|
+
}
|
|
105
|
+
console.log(format_1.c.muted(`Not in your account yet — 'ple sync' uploads ${matches.length === 1 ? 'it' : 'them'}.`));
|
|
40
106
|
}
|
package/dist/commands/show.js
CHANGED
|
@@ -4,12 +4,15 @@ exports.showCommand = showCommand;
|
|
|
4
4
|
const api_client_1 = require("../lib/api-client");
|
|
5
5
|
const local_1 = require("./local");
|
|
6
6
|
const promptResolver_1 = require("../lib/promptResolver");
|
|
7
|
+
const promptSource_1 = require("../lib/promptSource");
|
|
7
8
|
const format_1 = require("../lib/format");
|
|
8
9
|
/**
|
|
9
10
|
* `ple show <name>` — render a prompt's content to the terminal.
|
|
10
11
|
*
|
|
11
12
|
* Unlike `copy`, this doesn't touch the clipboard: it renders the three
|
|
12
|
-
* sections (role / description / context) under readable headers.
|
|
13
|
+
* sections (role / description / context) under readable headers. Signed in, a
|
|
14
|
+
* prompt that exists only on this machine is the fallback when the account has no
|
|
15
|
+
* match (one stderr line says so).
|
|
13
16
|
*/
|
|
14
17
|
async function showCommand(name, options = {}) {
|
|
15
18
|
if ((0, local_1.isSignedOut)()) {
|
|
@@ -19,11 +22,16 @@ async function showCommand(name, options = {}) {
|
|
|
19
22
|
}
|
|
20
23
|
await (0, api_client_1.ensureAuthed)();
|
|
21
24
|
const projectId = options.project ? await (0, promptResolver_1.resolveProjectId)(options.project) : undefined;
|
|
22
|
-
const
|
|
23
|
-
if (!
|
|
25
|
+
const found = await (0, promptSource_1.findPrompt)(name, { projectId });
|
|
26
|
+
if (!found) {
|
|
24
27
|
process.exitCode = 1;
|
|
25
28
|
return;
|
|
26
29
|
}
|
|
30
|
+
if (found.source === 'local') {
|
|
31
|
+
(0, local_1.showLocalPrompt)(found.prompt);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const prompt = found.prompt;
|
|
27
35
|
const version = (0, promptResolver_1.fetchPromptContent)(prompt);
|
|
28
36
|
if (!version) {
|
|
29
37
|
console.error(format_1.c.error(`'${prompt.title}' has no usable version.`));
|