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.
Files changed (41) hide show
  1. package/CHANGELOG.md +112 -0
  2. package/README.md +241 -27
  3. package/dist/commands/config.js +13 -0
  4. package/dist/commands/copy.js +10 -3
  5. package/dist/commands/get.js +11 -2
  6. package/dist/commands/import.js +30 -128
  7. package/dist/commands/importCheck.js +304 -0
  8. package/dist/commands/importGithub.js +171 -0
  9. package/dist/commands/list.js +83 -17
  10. package/dist/commands/local.js +31 -9
  11. package/dist/commands/login.js +6 -5
  12. package/dist/commands/save.js +1 -1
  13. package/dist/commands/search.js +73 -7
  14. package/dist/commands/show.js +11 -3
  15. package/dist/commands/suggest.js +100 -10
  16. package/dist/commands/sync.js +57 -13
  17. package/dist/index.js +7 -0
  18. package/dist/lib/errors.js +4 -0
  19. package/dist/lib/format.js +28 -0
  20. package/dist/lib/frontmatter.js +86 -4
  21. package/dist/lib/github.js +208 -0
  22. package/dist/lib/githubCache.js +118 -0
  23. package/dist/lib/githubHttp.js +197 -0
  24. package/dist/lib/githubImport.js +238 -0
  25. package/dist/lib/githubSelect.js +148 -0
  26. package/dist/lib/githubSnapshot.js +67 -0
  27. package/dist/lib/githubSpec.js +78 -0
  28. package/dist/lib/importOrigins.js +36 -0
  29. package/dist/lib/importShared.js +179 -0
  30. package/dist/lib/licenses.js +243 -0
  31. package/dist/lib/localStore.js +80 -2
  32. package/dist/lib/loopApi.js +63 -11
  33. package/dist/lib/promptResolver.js +22 -9
  34. package/dist/lib/promptSource.js +123 -0
  35. package/dist/lib/rank.js +30 -13
  36. package/dist/lib/settings.js +24 -3
  37. package/dist/lib/tagFilter.js +40 -0
  38. package/dist/lib/updateCheck.js +296 -0
  39. package/dist/lib/upstreamCheck.js +71 -0
  40. package/dist/program.js +26 -7
  41. package/package.json +1 -1
@@ -1,8 +1,12 @@
1
1
  "use strict";
2
2
  /**
3
- * `ple import --scan` — bring the prompts you already keep on disk into PLE
4
- * (W1-2 — strategy F15, "activation = investment").
3
+ * `ple import` — bring prompts you already have into PLE.
5
4
  *
5
+ * ple import --scan # your agent folders (W1-2 — strategy F15, "activation = investment")
6
+ * ple import github:owner/repo # a public GitHub repo, per-file license gate (importGithub.ts)
7
+ * ple import --check [--apply] # follow upstream changes of what came from GitHub (importCheck.ts)
8
+ *
9
+ * `--scan`:
6
10
  * ple import --scan --dry-run # preview: tool, path, title, size, status
7
11
  * ple import --scan # preview + pick (1,3-5 / all)
8
12
  * ple import --scan --all # no questions (scripts, agents)
@@ -49,72 +53,18 @@ var __importStar = (this && this.__importStar) || (function () {
49
53
  };
50
54
  })();
51
55
  Object.defineProperty(exports, "__esModule", { value: true });
52
- exports.parseSelection = parseSelection;
56
+ exports.parseSelection = void 0;
53
57
  exports.importCommand = importCommand;
54
- const readline = __importStar(require("readline"));
55
58
  const store = __importStar(require("../lib/localStore"));
56
59
  const api_client_1 = require("../lib/api-client");
57
60
  const promptResolver_1 = require("../lib/promptResolver");
58
61
  const scanners_1 = require("../lib/scanners");
62
+ const importShared_1 = require("../lib/importShared");
63
+ Object.defineProperty(exports, "parseSelection", { enumerable: true, get: function () { return importShared_1.parseSelection; } });
59
64
  const local_1 = require("./local");
60
65
  const format_1 = require("../lib/format");
61
- const constants_1 = require("../lib/constants");
62
- /** The import endpoint caps one request at 50 records. */
63
- const BATCH = 50;
64
- /**
65
- * Parse a pick like `1,3-5`, `all`, or empty (cancel). Returns 0-based
66
- * indices, `null` for cancel; throws on anything out of range or malformed.
67
- */
68
- function parseSelection(input, count) {
69
- const v = input.trim().toLowerCase();
70
- if (v === '' || v === 'q' || v === 'n' || v === 'none')
71
- return null;
72
- if (v === 'a' || v === 'all' || v === '*')
73
- return Array.from({ length: count }, (_, i) => i);
74
- const picked = new Set();
75
- for (const part of v.split(/[\s,]+/).filter(Boolean)) {
76
- const range = part.match(/^(\d+)-(\d+)$/);
77
- const single = part.match(/^(\d+)$/);
78
- if (range) {
79
- const a = Number(range[1]);
80
- const b = Number(range[2]);
81
- if (a < 1 || b > count || a > b)
82
- throw new Error(`'${part}' is out of range (1-${count}).`);
83
- for (let i = a; i <= b; i++)
84
- picked.add(i - 1);
85
- }
86
- else if (single) {
87
- const n = Number(single[1]);
88
- if (n < 1 || n > count)
89
- throw new Error(`'${part}' is out of range (1-${count}).`);
90
- picked.add(n - 1);
91
- }
92
- else {
93
- throw new Error(`Could not read '${part}'. Use numbers like 1,3-5 or 'all'.`);
94
- }
95
- }
96
- return [...picked].sort((x, y) => x - y);
97
- }
98
- function formatSize(bytes) {
99
- return bytes < 1024 ? `${bytes} B` : `${(bytes / 1024).toFixed(1)} KB`;
100
- }
101
- function defaultAsk(question) {
102
- const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
103
- return new Promise((resolve) => {
104
- rl.question(question, (answer) => {
105
- rl.close();
106
- resolve(answer);
107
- });
108
- });
109
- }
110
- /** Local slug that does not overwrite a different existing prompt. */
111
- function freeSlug(title) {
112
- const base = store.slugify(title.replace(/[/\\:]+/g, '-'));
113
- let slug = base;
114
- for (let n = 2; store.exists(slug); n++)
115
- slug = `${base}-${n}`;
116
- return slug;
117
- }
66
+ const importGithub_1 = require("./importGithub");
67
+ const importCheck_1 = require("./importCheck");
118
68
  function toImportable(cand) {
119
69
  return {
120
70
  title: cand.title,
@@ -131,8 +81,20 @@ function toImportable(cand) {
131
81
  };
132
82
  }
133
83
  async function importCommand(options = {}, deps = {}) {
84
+ const modes = [options.source ? 'a GitHub source' : '', options.scan ? '--scan' : '', options.check ? '--check' : ''].filter(Boolean);
85
+ if (modes.length > 1) {
86
+ throw new Error(`Choose one: ${modes.join(' and ')} cannot be combined. Use a GitHub source, --scan, or --check.`);
87
+ }
88
+ if (options.apply && !options.check) {
89
+ throw new Error('--apply only works together with --check.');
90
+ }
91
+ if (options.source)
92
+ return (0, importGithub_1.importGithubCommand)(options.source, options, deps);
93
+ if (options.check)
94
+ return (0, importCheck_1.importCheckCommand)({ apply: options.apply, dryRun: options.dryRun });
134
95
  if (!options.scan) {
135
- throw new Error('Nothing to import. Use `ple import --scan` to find prompts in your agent folders.');
96
+ throw new Error('Nothing to import. Use `ple import --scan` to find prompts in your agent folders, ' +
97
+ '`ple import github:<owner>/<repo>` to bring in a public GitHub repo, or `ple import --check` to look for upstream changes.');
136
98
  }
137
99
  const signedOut = (0, local_1.isSignedOut)();
138
100
  const destination = signedOut ? 'your local store' : 'your account';
@@ -157,7 +119,7 @@ async function importCommand(options = {}, deps = {}) {
157
119
  format_1.c.muted(` → ${destination}`));
158
120
  fresh.forEach((cand, i) => {
159
121
  console.log(` ${format_1.c.accent(String(i + 1).padStart(3))} ${cand.tool.padEnd(11)} ${cand.kind.padEnd(7)} ` +
160
- `${(0, format_1.truncate)(cand.title, 40).padEnd(40)} ${format_1.c.muted(formatSize(cand.bytes).padStart(8))} ${format_1.c.muted(cand.displayPath)}`);
122
+ `${(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(cand.displayPath)}`);
161
123
  });
162
124
  if (already > 0) {
163
125
  console.log(format_1.c.muted(` … and ${already} already imported (same content) — skipped`));
@@ -176,77 +138,17 @@ async function importCommand(options = {}, deps = {}) {
176
138
  console.log(format_1.c.muted(`\nDry run — nothing imported. Run \`ple import --scan\` to pick, or add --all.`));
177
139
  return;
178
140
  }
179
- let selected;
180
- if (options.all) {
181
- selected = fresh;
182
- }
183
- else {
184
- const interactive = deps.isTTY ?? Boolean(process.stdin.isTTY && process.stdout.isTTY);
185
- if (!interactive) {
186
- console.log(format_1.c.muted(`\nNot a terminal — re-run with --all to import these ${fresh.length}, or --dry-run to only look.`));
187
- return;
188
- }
189
- const answer = await (deps.ask ?? defaultAsk)(`\nImport which? [all | 1,3-5 | Enter to cancel]: `);
190
- const picked = parseSelection(answer, fresh.length);
191
- if (!picked || picked.length === 0) {
192
- console.log(format_1.c.muted('Cancelled — nothing imported.'));
193
- return;
194
- }
195
- selected = picked.map((i) => fresh[i]);
196
- }
141
+ const selected = await (0, importShared_1.chooseRows)(fresh, options.all, deps);
142
+ if (!selected)
143
+ return;
197
144
  if (signedOut) {
198
145
  for (const cand of selected) {
199
- store.save({ slug: freeSlug(cand.title), title: cand.title, description: cand.description, tags: cand.tags, body: cand.body });
146
+ store.save({ slug: (0, importShared_1.freeSlug)(cand.title), title: cand.title, description: cand.description, tags: cand.tags, body: cand.body });
200
147
  }
201
148
  console.log(format_1.c.success(`✓ Imported ${selected.length} prompt${selected.length === 1 ? '' : 's'} into ${store.promptsDir()}`));
202
149
  console.log(format_1.c.muted('Sign in and run `ple sync` to carry them to your account (history, web, agents).'));
203
150
  return;
204
151
  }
205
152
  const projectId = options.project ? await (0, promptResolver_1.resolveProjectId)(options.project) : undefined;
206
- // Say the plan limit out loud BEFORE uploading, not after a partial result.
207
- const headroom = await (0, api_client_1.getAccountHeadroom)();
208
- if (headroom.promptsRemaining !== null && selected.length > headroom.promptsRemaining) {
209
- console.log(format_1.c.warn(`Your plan has room for ${headroom.promptsRemaining} more prompt${headroom.promptsRemaining === 1 ? '' : 's'}; ` +
210
- `the first ${headroom.promptsRemaining} of ${selected.length} will be imported.`));
211
- }
212
- const payload = selected.map(toImportable);
213
- let imported = 0;
214
- let skippedDuplicate = 0;
215
- let truncatedByQuota = 0;
216
- let failed = 0;
217
- let abortMessage = null;
218
- for (let i = 0; i < payload.length; i += BATCH) {
219
- try {
220
- const res = await (0, api_client_1.importPrompts)(payload.slice(i, i + BATCH), {
221
- source: 'import',
222
- projectId,
223
- fallbackToExistingProject: !projectId,
224
- });
225
- imported += res.imported;
226
- skippedDuplicate += res.skippedDuplicate;
227
- truncatedByQuota += res.truncatedByQuota;
228
- failed += res.failed + res.skippedInvalid;
229
- }
230
- catch (err) {
231
- abortMessage = err instanceof Error ? err.message : String(err);
232
- truncatedByQuota += payload.length - i;
233
- break;
234
- }
235
- }
236
- console.log(format_1.c.success(`✓ Imported ${imported} prompt${imported === 1 ? '' : 's'} into your account`));
237
- if (skippedDuplicate > 0)
238
- console.log(format_1.c.muted(` ${skippedDuplicate} already there — skipped`));
239
- if (abortMessage)
240
- console.log(format_1.c.warn(`⚠ Stopped early: ${abortMessage}`));
241
- if (truncatedByQuota > 0) {
242
- console.log(format_1.c.warn(`⚠ ${truncatedByQuota} not imported — plan prompt limit reached.`));
243
- // Deneme vaadi YOK: deneme web'de bayrakla (NEXT_PUBLIC_PRO_TRIAL_DAYS) açılır
244
- // kapanır; CLI bayrağı bilemez, kapalıyken "14-day trial" yanlış söz olurdu.
245
- console.log(format_1.c.muted(` Upgrade to Pro to bring the rest: ${constants_1.WEB_APP_URL}/pricing`));
246
- console.log(format_1.c.muted(' Then run `ple import --scan` again — what already came in is skipped.'));
247
- }
248
- if (failed > 0)
249
- console.log(format_1.c.warn(`⚠ ${failed} failed. Re-run \`ple import --scan\` to retry those.`));
250
- if (imported > 0)
251
- console.log(format_1.c.muted(`Open them at ${constants_1.WEB_APP_URL}/dashboard or \`ple list\`.`));
153
+ await (0, importShared_1.uploadPrompts)(selected.map(toImportable), { projectId, retryCommand: 'ple import --scan' });
252
154
  }
@@ -0,0 +1,304 @@
1
+ "use strict";
2
+ /**
3
+ * `ple import --check [--apply]` — has anything changed on GitHub since you
4
+ * imported a prompt from there?
5
+ *
6
+ * ple import --check # compare, show a diff per changed prompt, change nothing
7
+ * ple import --check --apply # add each upstream text as a NEW version
8
+ *
9
+ * Never overwrites: an update is a new version (local: a new entry in the local
10
+ * history; account: a new version of the prompt) and the previous text stays in
11
+ * the history. Labels are never moved — `production` keeps pointing where it did
12
+ * until you say otherwise with `ple tag`. A changed file goes through the same
13
+ * gates as an import first, so a license that turned non-open is reported, not applied.
14
+ *
15
+ * Signed out it follows the local prompts that carry `upstream_*` lines; signed
16
+ * in, the account's imports (GET /api/prompts/import?include=origins).
17
+ */
18
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
19
+ if (k2 === undefined) k2 = k;
20
+ var desc = Object.getOwnPropertyDescriptor(m, k);
21
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
22
+ desc = { enumerable: true, get: function() { return m[k]; } };
23
+ }
24
+ Object.defineProperty(o, k2, desc);
25
+ }) : (function(o, m, k, k2) {
26
+ if (k2 === undefined) k2 = k;
27
+ o[k2] = m[k];
28
+ }));
29
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
30
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
31
+ }) : function(o, v) {
32
+ o["default"] = v;
33
+ });
34
+ var __importStar = (this && this.__importStar) || (function () {
35
+ var ownKeys = function(o) {
36
+ ownKeys = Object.getOwnPropertyNames || function (o) {
37
+ var ar = [];
38
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
39
+ return ar;
40
+ };
41
+ return ownKeys(o);
42
+ };
43
+ return function (mod) {
44
+ if (mod && mod.__esModule) return mod;
45
+ var result = {};
46
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
47
+ __setModuleDefault(result, mod);
48
+ return result;
49
+ };
50
+ })();
51
+ Object.defineProperty(exports, "__esModule", { value: true });
52
+ exports.importCheckCommand = importCheckCommand;
53
+ const history = __importStar(require("../lib/localHistory"));
54
+ const store = __importStar(require("../lib/localStore"));
55
+ const api_client_1 = require("../lib/api-client");
56
+ const format_1 = require("../lib/format");
57
+ const github_1 = require("../lib/github");
58
+ const githubImport_1 = require("../lib/githubImport");
59
+ const githubSnapshot_1 = require("../lib/githubSnapshot");
60
+ const importOrigins_1 = require("../lib/importOrigins");
61
+ const loopApi_1 = require("../lib/loopApi");
62
+ const upstreamCheck_1 = require("../lib/upstreamCheck");
63
+ const history_1 = require("./history");
64
+ const local_1 = require("./local");
65
+ const NEXT_STEP_NOTE = 'Run `ple import --check --apply` to add these as new versions. Nothing is overwritten — the current version stays in the history.';
66
+ const LABELS_NOTE = 'labels unchanged — move production with `ple tag` when ready';
67
+ // ---------------------------------------------------------------------------
68
+ // Local prompts
69
+ // ---------------------------------------------------------------------------
70
+ function localTargets() {
71
+ return store
72
+ .list()
73
+ .filter((p) => p.upstream !== undefined)
74
+ .map((p) => {
75
+ const snapshotOf = (q) => ({ title: q.title, description: q.description, tags: q.tags, body: q.body });
76
+ return {
77
+ tracked: { title: p.title, repo: p.upstream.repo, ref: p.upstream.ref, file: p.upstream.path, blob: p.upstream.blob },
78
+ current: p.body,
79
+ async apply(change, snap) {
80
+ // Re-read: anything edited since the list was taken must not be lost.
81
+ const now = store.read(p.slug) ?? p;
82
+ // A text edited outside ple is recorded first, so the update never hides it.
83
+ history.recordIfChanged(p.slug, snapshotOf(now), { onDisk: null, note: 'Edited outside ple' });
84
+ const up = now.upstream ?? p.upstream;
85
+ const attribution = (0, githubImport_1.attributionLine)(snap.repo, snap.commit, up.path, change.verdict);
86
+ const saved = store.save({
87
+ slug: p.slug,
88
+ title: now.title,
89
+ description: (0, githubImport_1.refreshAttribution)(now.description, attribution) ?? now.description,
90
+ tags: now.tags,
91
+ body: change.body,
92
+ upstream: {
93
+ ...up,
94
+ commit: snap.commit,
95
+ blob: change.blob,
96
+ license: change.verdict.spdx ?? up.license,
97
+ licenseUrl: change.verdict.licenseUrl,
98
+ copyright: change.verdict.copyright,
99
+ url: (0, github_1.blobUrl)(snap.repo, snap.commit, up.path),
100
+ },
101
+ });
102
+ const v = history.recordIfChanged(p.slug, snapshotOf(saved), { note: `Upstream ${snap.repo}@${snap.commit.slice(0, 7)}` });
103
+ return v ? `saved as local version v${v.version}` : 'saved';
104
+ },
105
+ advance(blob, snap) {
106
+ const now = store.read(p.slug);
107
+ if (!now?.upstream)
108
+ return;
109
+ store.save({
110
+ slug: p.slug,
111
+ title: now.title,
112
+ description: now.description,
113
+ tags: now.tags,
114
+ body: now.body,
115
+ upstream: { ...now.upstream, commit: snap.commit, blob, url: (0, github_1.blobUrl)(snap.repo, snap.commit, now.upstream.path) },
116
+ });
117
+ },
118
+ };
119
+ });
120
+ }
121
+ // ---------------------------------------------------------------------------
122
+ // Account prompts
123
+ // ---------------------------------------------------------------------------
124
+ const isNotFound = (err) => (err instanceof api_client_1.ApiError && err.status === 404) || (err instanceof Error && /not found/i.test(err.message));
125
+ async function accountTargets() {
126
+ await (0, api_client_1.ensureAuthed)();
127
+ const state = await (0, importOrigins_1.fetchImportOrigins)();
128
+ if (state.origins === null) {
129
+ throw new Error('The server did not list your imports (it may be an older version), so there is nothing to check yet.');
130
+ }
131
+ const rows = state.origins.filter((o) => o.meta?.source === 'github' && o.meta.repo && o.meta.ref && o.meta.file && o.meta.blob);
132
+ const built = await (0, githubImport_1.mapLimit)(rows, 3, async (row) => {
133
+ const meta = row.meta;
134
+ if (!meta)
135
+ return null;
136
+ let hist;
137
+ try {
138
+ hist = await (0, api_client_1.getPromptHistory)(row.promptId);
139
+ }
140
+ catch (err) {
141
+ if (isNotFound(err))
142
+ return null; // deleted since
143
+ throw err;
144
+ }
145
+ const now = (0, history_1.currentVersion)(hist);
146
+ // The newest update we added says which blob it took; else the one the import took.
147
+ const applied = (0, history_1.sortNewestFirst)(hist.versions).map((v) => (0, upstreamCheck_1.blobFromChangelog)(v.changelog)).find((b) => b !== null);
148
+ return {
149
+ tracked: { title: hist.title, repo: meta.repo, ref: meta.ref, file: meta.file, blob: applied ?? meta.blob },
150
+ current: now?.context_text ?? '',
151
+ async apply(change, snap) {
152
+ // The other parts stay exactly as they are; only the text and our own attribution line change.
153
+ const prompt = await (0, api_client_1.getPromptById)(row.promptId);
154
+ const base = prompt?.current_version ?? now;
155
+ const attribution = (0, githubImport_1.attributionLine)(snap.repo, snap.commit, meta.file, change.verdict);
156
+ const partDescription = base?.description_text ?? '';
157
+ const description = prompt?.description ? (0, githubImport_1.refreshAttribution)(prompt.description, attribution) : null;
158
+ const res = await (0, loopApi_1.saveVersion)(row.promptId, {
159
+ roleText: base?.role_text ?? '',
160
+ descriptionText: (0, githubImport_1.refreshAttribution)(partDescription, attribution) ?? partDescription,
161
+ contextText: change.body,
162
+ }, (0, upstreamCheck_1.upstreamChangelog)(snap.repo, snap.commit, change.blob), 'import', description !== null ? { description } : {});
163
+ return res.versionNumber ? `added as v${res.versionNumber}` : 'added as a new version';
164
+ },
165
+ };
166
+ });
167
+ return { targets: built.filter((t) => t !== null), gone: built.filter((t) => t === null).length };
168
+ }
169
+ // ---------------------------------------------------------------------------
170
+ // The command
171
+ // ---------------------------------------------------------------------------
172
+ function markOf(outcome) {
173
+ switch (outcome.kind) {
174
+ case 'up-to-date':
175
+ return format_1.c.success('✓');
176
+ case 'changed':
177
+ return format_1.c.warn('↑');
178
+ case 'matches':
179
+ case 'removed':
180
+ return format_1.c.muted('•');
181
+ default:
182
+ return format_1.c.warn('⚠');
183
+ }
184
+ }
185
+ function outcomeText(outcome) {
186
+ switch (outcome.kind) {
187
+ case 'up-to-date':
188
+ return format_1.c.success('up to date');
189
+ case 'removed':
190
+ return format_1.c.muted('removed upstream — kept here');
191
+ case 'matches':
192
+ return format_1.c.muted('already matches upstream');
193
+ case 'changed':
194
+ return format_1.c.warn('changed upstream');
195
+ case 'license':
196
+ return format_1.c.warn(`license changed to ${(0, format_1.safeText)(outcome.verdict.spdx ?? 'terms that are not open')} — not applied`);
197
+ case 'refused':
198
+ return format_1.c.warn((0, format_1.safeText)(outcome.reason));
199
+ }
200
+ }
201
+ async function importCheckCommand(options = {}) {
202
+ if (options.apply && options.dryRun) {
203
+ throw new Error('--dry-run and --apply cannot be combined: --check only looks until you add --apply.');
204
+ }
205
+ const signedOut = (0, local_1.isSignedOut)();
206
+ const found = signedOut ? { targets: localTargets(), gone: 0 } : await accountTargets();
207
+ const targets = found.targets;
208
+ if (!signedOut) {
209
+ const localOnly = store.list().filter((p) => p.upstream).length;
210
+ if (localOnly > 0 && targets.length === 0) {
211
+ console.log(format_1.c.muted(`${localOnly} prompt${localOnly === 1 ? '' : 's'} imported from GitHub ${localOnly === 1 ? 'is' : 'are'} only in your local store — run \`ple sync\` to carry ${localOnly === 1 ? 'it' : 'them'} to your account.`));
212
+ }
213
+ }
214
+ if (found.gone > 0) {
215
+ console.log(format_1.c.muted(`${found.gone} imported prompt${found.gone === 1 ? ' is' : 's are'} no longer in your account — skipped.`));
216
+ }
217
+ if (targets.length === 0) {
218
+ console.log(format_1.c.muted('No prompts imported from GitHub yet. Try: ple import github:anthropics/skills --dry-run'));
219
+ return;
220
+ }
221
+ // One snapshot (≤ 3 counted API calls) per repo and ref, however many prompts came from it.
222
+ const groups = new Map();
223
+ for (const t of targets) {
224
+ const key = `${t.tracked.repo.toLowerCase()}@${t.tracked.ref}`;
225
+ groups.set(key, [...(groups.get(key) ?? []), t]);
226
+ }
227
+ let changed = 0;
228
+ let removed = 0;
229
+ let applied = 0;
230
+ let limited = 0;
231
+ let problems = 0;
232
+ console.log(format_1.c.label(`Checking ${targets.length} prompt${targets.length === 1 ? '' : 's'} imported from GitHub…`));
233
+ for (const group of groups.values()) {
234
+ const [owner, name] = group[0].tracked.repo.split('/');
235
+ const ref = group[0].tracked.ref;
236
+ const label = `github.com/${(0, format_1.safeText)(group[0].tracked.repo)}@${(0, format_1.safeText)(ref)}`;
237
+ let snap;
238
+ try {
239
+ if (!owner || !name || !github_1.OWNER_RE.test(owner) || !github_1.REPO_RE.test(name))
240
+ throw new github_1.GithubError('The saved source is not a GitHub repository.');
241
+ snap = await (0, githubSnapshot_1.loadSnapshot)(owner, name, ref);
242
+ }
243
+ catch (err) {
244
+ // One repo that is gone must not hide the others; limits and network errors stop the run.
245
+ if (err instanceof github_1.GithubError && !err.retryable) {
246
+ console.log(`\n${format_1.c.title(label)}`);
247
+ console.log(format_1.c.warn(` ⚠ ${err.message}`));
248
+ problems += group.length;
249
+ continue;
250
+ }
251
+ throw err;
252
+ }
253
+ console.log(`\n${format_1.c.title(label)} ${format_1.c.muted(`(${snap.commit.slice(0, 7)})`)}`);
254
+ const outcomes = await (0, githubImport_1.mapLimit)(group, 3, (t) => (0, upstreamCheck_1.checkUpstream)(snap, t.tracked, t.current));
255
+ for (let i = 0; i < group.length; i++) {
256
+ const target = group[i];
257
+ const outcome = outcomes[i];
258
+ const title = (0, format_1.safeText)(target.tracked.title);
259
+ console.log(` ${markOf(outcome)} ${title} — ${outcomeText(outcome)}${outcome.kind === 'changed' ? format_1.c.muted(` ${(0, format_1.safeText)(target.tracked.file)}`) : ''}`);
260
+ if (outcome.kind === 'removed')
261
+ removed++;
262
+ if (outcome.kind === 'license' || outcome.kind === 'refused')
263
+ problems++;
264
+ if (outcome.kind === 'matches')
265
+ target.advance?.(outcome.blob, snap); // the text is already theirs; move the pointer silently
266
+ if (outcome.kind !== 'changed')
267
+ continue;
268
+ changed++;
269
+ for (const line of (0, upstreamCheck_1.diffPreview)(target.current, outcome.body, { from: `${title} (current)`, to: `upstream ${snap.commit.slice(0, 7)}` })) {
270
+ console.log(` ${line}`);
271
+ }
272
+ if (!options.apply)
273
+ continue;
274
+ try {
275
+ console.log(format_1.c.success(` ✓ ${await target.apply(outcome, snap)}`));
276
+ applied++;
277
+ }
278
+ catch (err) {
279
+ if (err instanceof loopApi_1.VersionLimitError) {
280
+ limited++;
281
+ console.log(format_1.c.warn(` ⚠ not applied: ${(0, format_1.safeText)(err.message)}`));
282
+ }
283
+ else {
284
+ problems++;
285
+ console.log(format_1.c.warn(` ⚠ not applied: ${err instanceof Error ? (0, format_1.safeText)(err.message) : 'unknown error'}`));
286
+ }
287
+ }
288
+ }
289
+ }
290
+ console.log('');
291
+ if (changed === 0) {
292
+ console.log(format_1.c.success(problems === 0 && removed === 0 ? 'Everything is up to date.' : 'Nothing to apply.'));
293
+ return;
294
+ }
295
+ if (!options.apply) {
296
+ console.log(format_1.c.muted(NEXT_STEP_NOTE));
297
+ return;
298
+ }
299
+ console.log(format_1.c.success(`✓ Added ${applied} new version${applied === 1 ? '' : 's'}`) + (signedOut ? '' : format_1.c.muted(` — ${LABELS_NOTE}`)));
300
+ if (limited > 0)
301
+ console.log(format_1.c.warn(`⚠ ${limited} not applied — the plan's version limit is reached.`));
302
+ if (problems > 0 || limited > 0)
303
+ process.exitCode = 1;
304
+ }