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
package/dist/commands/sync.js
CHANGED
|
@@ -10,6 +10,16 @@
|
|
|
10
10
|
* One-way (local → account) on purpose. Pulling the account library down would
|
|
11
11
|
* need conflict rules the local store cannot express (the local history is
|
|
12
12
|
* a private, append-only log, not a mergeable one) and a half-correct merge silently losing an edit is worse than no pull.
|
|
13
|
+
*
|
|
14
|
+
* Re-running is safe: every prompt travels with the sha256 of its text, and the
|
|
15
|
+
* server skips text that is already in the account. A prompt edited since is a
|
|
16
|
+
* different text, so it is uploaded as a NEW prompt — sync copies, it never updates.
|
|
17
|
+
* A prompt that came from GitHub also carries where from (see lib/githubImport.ts),
|
|
18
|
+
* so `ple import --check` can follow it in the account.
|
|
19
|
+
*
|
|
20
|
+
* `--project <repo>` uploads into that repo (name, slug, id or short id — the same
|
|
21
|
+
* resolution as `ple import`); without it the prompts land in the default repo, or
|
|
22
|
+
* in the user's only repo when the plan cannot create another one.
|
|
13
23
|
*/
|
|
14
24
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
15
25
|
if (k2 === undefined) k2 = k;
|
|
@@ -50,11 +60,37 @@ const store = __importStar(require("../lib/localStore"));
|
|
|
50
60
|
const history = __importStar(require("../lib/localHistory"));
|
|
51
61
|
const api_client_1 = require("../lib/api-client");
|
|
52
62
|
const format_1 = require("../lib/format");
|
|
63
|
+
const githubImport_1 = require("../lib/githubImport");
|
|
53
64
|
const libraryCache_1 = require("../lib/libraryCache");
|
|
65
|
+
const promptResolver_1 = require("../lib/promptResolver");
|
|
66
|
+
const scanners_1 = require("../lib/scanners");
|
|
54
67
|
/** The import endpoint caps one request at 50 records. */
|
|
55
68
|
const BATCH = 50;
|
|
69
|
+
/** The `--project` value as it would be typed again: quoted when a shell would split or expand it. */
|
|
70
|
+
function typed(value) {
|
|
71
|
+
const v = (0, format_1.safeText)(value);
|
|
72
|
+
return /^[\w.@:/+-]+$/.test(v) ? v : `"${v.replace(/(["\\$`])/g, '\\$1')}"`;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Every prompt carries where it is from, so the server can tell what it already
|
|
76
|
+
* has: the sha256 of the text, and — for a GitHub import — the source and license.
|
|
77
|
+
*/
|
|
78
|
+
function toImportable(p) {
|
|
79
|
+
const sha256 = (0, scanners_1.hashBody)(p.body);
|
|
80
|
+
return {
|
|
81
|
+
title: p.title,
|
|
82
|
+
description: p.description,
|
|
83
|
+
content: p.body,
|
|
84
|
+
tags: p.tags,
|
|
85
|
+
origin: p.upstream
|
|
86
|
+
? (0, githubImport_1.originFromUpstream)(p.upstream, sha256)
|
|
87
|
+
: { tool: 'other', kind: 'prompt', path: `local:${p.slug}`, sha256 },
|
|
88
|
+
};
|
|
89
|
+
}
|
|
56
90
|
async function syncCommand(options = {}) {
|
|
57
91
|
const local = store.list().filter((p) => p.body.trim());
|
|
92
|
+
/** What to run again: the same repo, not the default one. */
|
|
93
|
+
const again = `ple sync${options.project ? ` --project ${typed(options.project)}` : ''}`;
|
|
58
94
|
if (local.length === 0) {
|
|
59
95
|
console.log(format_1.c.muted('Nothing to sync — the local store is empty.'));
|
|
60
96
|
console.log(format_1.c.muted(' ple save "code review" -m "Review this diff: {{diff}}"'));
|
|
@@ -64,17 +100,18 @@ async function syncCommand(options = {}) {
|
|
|
64
100
|
console.log(format_1.c.label(`${local.length} local prompt${local.length === 1 ? '' : 's'} would be uploaded:`));
|
|
65
101
|
for (const p of local)
|
|
66
102
|
console.log(format_1.c.muted(` ${p.slug} ${p.title}`));
|
|
67
|
-
|
|
103
|
+
// Offline on purpose: the repo is looked up (and a wrong name rejected) when you upload.
|
|
104
|
+
if (options.project)
|
|
105
|
+
console.log(format_1.c.muted(`→ repo ${(0, format_1.safeText)(options.project)} (checked when you upload)`));
|
|
106
|
+
console.log(format_1.c.muted(`\nRun \`${again}\` without --dry-run to upload.`));
|
|
68
107
|
return;
|
|
69
108
|
}
|
|
70
109
|
await (0, api_client_1.ensureAuthed)();
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
content: p.body,
|
|
75
|
-
tags: p.tags,
|
|
76
|
-
}));
|
|
110
|
+
// A wrong repo name stops here, before anything is uploaded.
|
|
111
|
+
const projectId = options.project ? await (0, promptResolver_1.resolveProjectId)(options.project) : undefined;
|
|
112
|
+
const payload = local.map(toImportable);
|
|
77
113
|
let imported = 0;
|
|
114
|
+
let skippedDuplicate = 0;
|
|
78
115
|
let failed = 0;
|
|
79
116
|
let skippedInvalid = 0;
|
|
80
117
|
let truncatedByQuota = 0;
|
|
@@ -86,8 +123,13 @@ async function syncCommand(options = {}) {
|
|
|
86
123
|
let abortMessage = null;
|
|
87
124
|
for (let i = 0; i < payload.length; i += BATCH) {
|
|
88
125
|
try {
|
|
89
|
-
const res = await (0, api_client_1.importPrompts)(payload.slice(i, i + BATCH)
|
|
126
|
+
const res = await (0, api_client_1.importPrompts)(payload.slice(i, i + BATCH), {
|
|
127
|
+
source: 'cli',
|
|
128
|
+
projectId,
|
|
129
|
+
fallbackToExistingProject: !projectId,
|
|
130
|
+
});
|
|
90
131
|
imported += res.imported;
|
|
132
|
+
skippedDuplicate += res.skippedDuplicate;
|
|
91
133
|
failed += res.failed;
|
|
92
134
|
skippedInvalid += res.skippedInvalid;
|
|
93
135
|
truncatedByQuota += res.truncatedByQuota;
|
|
@@ -107,6 +149,8 @@ async function syncCommand(options = {}) {
|
|
|
107
149
|
(0, libraryCache_1.startBackgroundRefresh)({ force: true });
|
|
108
150
|
const tagNote = serverCarriesTags && tagsApplied > 0 ? ` (+${tagsApplied} tag link${tagsApplied === 1 ? '' : 's'})` : '';
|
|
109
151
|
console.log(format_1.c.success(`✓ Uploaded ${imported} prompt${imported === 1 ? '' : 's'}${tagNote}`));
|
|
152
|
+
if (skippedDuplicate > 0)
|
|
153
|
+
console.log(format_1.c.muted(` ${skippedDuplicate} already in your account — skipped`));
|
|
110
154
|
// Each shortfall gets its own line with its own fix — "12 of 20 synced"
|
|
111
155
|
// with no reason is the kind of message that sends people to support.
|
|
112
156
|
if (abortMessage) {
|
|
@@ -114,13 +158,13 @@ async function syncCommand(options = {}) {
|
|
|
114
158
|
}
|
|
115
159
|
if (truncatedByQuota > 0) {
|
|
116
160
|
console.log(format_1.c.warn(`⚠ ${truncatedByQuota} not uploaded — plan prompt limit reached.`));
|
|
117
|
-
console.log(format_1.c.muted(
|
|
161
|
+
console.log(format_1.c.muted(` Upgrade for unlimited prompts, then run \`${again}\` again.`));
|
|
118
162
|
}
|
|
119
163
|
if (skippedInvalid > 0) {
|
|
120
164
|
console.log(format_1.c.warn(`⚠ ${skippedInvalid} skipped — missing a title or body.`));
|
|
121
165
|
}
|
|
122
166
|
if (failed > 0) {
|
|
123
|
-
console.log(format_1.c.warn(`⚠ ${failed} failed to import. Re-run \`
|
|
167
|
+
console.log(format_1.c.warn(`⚠ ${failed} failed to import. Re-run \`${again}\` to retry those.`));
|
|
124
168
|
}
|
|
125
169
|
// Tags travel since the server started answering with `tagsApplied`. An
|
|
126
170
|
// older deployment ignores the field silently — that is the one case where
|
|
@@ -128,9 +172,9 @@ async function syncCommand(options = {}) {
|
|
|
128
172
|
if (!serverCarriesTags && local.some((p) => p.tags.length > 0)) {
|
|
129
173
|
console.log(format_1.c.muted('Note: tags stayed local — this server does not carry them yet.'));
|
|
130
174
|
}
|
|
131
|
-
// Local files are NOT deleted: sync copies, it does not move.
|
|
132
|
-
//
|
|
175
|
+
// Local files are NOT deleted: sync copies, it does not move. Say what a
|
|
176
|
+
// re-run does, so nobody has to find out.
|
|
133
177
|
console.log(format_1.c.muted(`\nLocal files kept in ${store.promptsDir()} (sync copies, it does not move).`));
|
|
134
|
-
console.log(format_1.c.muted('Re-running
|
|
178
|
+
console.log(format_1.c.muted('Re-running is safe: text that is already in your account is skipped. A prompt you edited since is uploaded as a new prompt.'));
|
|
135
179
|
console.log(format_1.c.muted(`Only the current text of each prompt is uploaded; the local version history stays in ${history.historyRoot()}.`));
|
|
136
180
|
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* `ple tag <name> <version> <label>` — point a deployment label (`production`, `staging`, …)
|
|
4
|
+
* at one version of a prompt. Moving a label keeps an audit trail (who/when/from → to); the version
|
|
5
|
+
* history itself never changes.
|
|
6
|
+
*
|
|
7
|
+
* ple tag "code review" 3 production # label v3 as production (moves it if it was elsewhere)
|
|
8
|
+
* ple tag "code review" --list # labels + recent moves
|
|
9
|
+
* ple tag "code review" --remove staging
|
|
10
|
+
*
|
|
11
|
+
* Then read it back with `ple get "code review" --label production`.
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.LABEL_RE = void 0;
|
|
15
|
+
exports.normalizeLabel = normalizeLabel;
|
|
16
|
+
exports.tagCommand = tagCommand;
|
|
17
|
+
const api_client_1 = require("../lib/api-client");
|
|
18
|
+
const format_1 = require("../lib/format");
|
|
19
|
+
const local_1 = require("./local");
|
|
20
|
+
const history_1 = require("./history");
|
|
21
|
+
/** Same rule as the server (a-z 0-9 . _ - ; 1-32 chars, starts alphanumeric). */
|
|
22
|
+
exports.LABEL_RE = /^[a-z0-9][a-z0-9._-]{0,31}$/;
|
|
23
|
+
function normalizeLabel(raw) {
|
|
24
|
+
const label = raw.trim().toLowerCase();
|
|
25
|
+
if (!exports.LABEL_RE.test(label)) {
|
|
26
|
+
throw new Error(`Invalid label '${raw}'. Use a-z, 0-9, '.', '_' or '-' (max 32 chars).`);
|
|
27
|
+
}
|
|
28
|
+
return label;
|
|
29
|
+
}
|
|
30
|
+
async function tagCommand(name, version, label, options = {}) {
|
|
31
|
+
if ((0, local_1.isSignedOut)()) {
|
|
32
|
+
throw new Error("Deployment labels need an account (they live on the server). Run 'ple login' first.");
|
|
33
|
+
}
|
|
34
|
+
const prompt = await (0, history_1.resolveForHistory)(name, options.project);
|
|
35
|
+
if (!prompt) {
|
|
36
|
+
process.exitCode = 1;
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (options.list || (!version && !label && !options.remove)) {
|
|
40
|
+
const { labels, events } = await (0, api_client_1.listPromptLabels)(prompt.id);
|
|
41
|
+
if (labels.length === 0) {
|
|
42
|
+
console.log(format_1.c.muted(`No labels on '${prompt.title}'. Set one: ple tag "${prompt.title}" <version> production`));
|
|
43
|
+
}
|
|
44
|
+
for (const l of labels) {
|
|
45
|
+
console.log(`${l.label.padEnd(14)} → v${l.version_number} ${format_1.c.muted(new Date(l.set_at).toLocaleString())}`);
|
|
46
|
+
}
|
|
47
|
+
if (events.length > 0) {
|
|
48
|
+
console.log(format_1.c.muted('\nRecent moves:'));
|
|
49
|
+
for (const e of events.slice(0, 10)) {
|
|
50
|
+
const move = e.to_version_number == null
|
|
51
|
+
? `removed from v${e.from_version_number ?? '?'}`
|
|
52
|
+
: e.from_version_number == null
|
|
53
|
+
? `set to v${e.to_version_number}`
|
|
54
|
+
: `v${e.from_version_number} → v${e.to_version_number}`;
|
|
55
|
+
console.log(format_1.c.muted(` ${e.label}: ${move} (${new Date(e.created_at).toLocaleString()})`));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (options.remove) {
|
|
61
|
+
const target = normalizeLabel(options.remove);
|
|
62
|
+
const res = await (0, api_client_1.clearPromptLabel)(prompt.id, target);
|
|
63
|
+
console.log(res.changed
|
|
64
|
+
? format_1.c.success(`✓ Removed label '${target}'`) + format_1.c.muted(` (was v${res.previous_version_number ?? '?'})`)
|
|
65
|
+
: format_1.c.muted(`Label '${target}' was not set — nothing to do.`));
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (!version || !label) {
|
|
69
|
+
throw new Error('Usage: ple tag <name> <version> <label> (or --list / --remove <label>)');
|
|
70
|
+
}
|
|
71
|
+
const wanted = normalizeLabel(label);
|
|
72
|
+
const history = await (0, api_client_1.getPromptHistory)(prompt.id);
|
|
73
|
+
const target = (0, history_1.findVersion)(history.versions, version);
|
|
74
|
+
if (!target)
|
|
75
|
+
throw (0, history_1.versionNotFound)(version, history.versions);
|
|
76
|
+
const res = await (0, api_client_1.setPromptLabel)(prompt.id, wanted, target.id);
|
|
77
|
+
if (res.changed === false) {
|
|
78
|
+
console.log(format_1.c.muted(`'${wanted}' already points at v${target.version_number} — nothing to do.`));
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const moved = res.previous_version_number != null ? ` (moved from v${res.previous_version_number})` : '';
|
|
82
|
+
console.log(format_1.c.success(`✓ ${wanted} → v${target.version_number}`) + format_1.c.muted(`${moved} — ${history.title}`));
|
|
83
|
+
if (res.previous_version_number != null) {
|
|
84
|
+
console.log(format_1.c.muted(`Move it back with: ple tag "${history.title}" ${res.previous_version_number} ${wanted}`));
|
|
85
|
+
}
|
|
86
|
+
}
|
package/dist/help.js
CHANGED
|
@@ -10,7 +10,7 @@ exports.COMMAND_GROUPS = void 0;
|
|
|
10
10
|
exports.formatRootHelp = formatRootHelp;
|
|
11
11
|
const commander_1 = require("commander");
|
|
12
12
|
exports.COMMAND_GROUPS = [
|
|
13
|
-
{ title: 'Prompts', commands: ['save', 'get', 'show', 'copy', 'list', 'search', 'log', 'diff', 'rollback', 'improve', 'loop'] },
|
|
13
|
+
{ title: 'Prompts', commands: ['save', 'get', 'show', 'copy', 'list', 'search', 'log', 'diff', 'rollback', 'tag', 'improve', 'loop'] },
|
|
14
14
|
{ title: 'Repos', commands: ['repo'] },
|
|
15
15
|
{ title: 'Account', commands: ['login', 'logout'] },
|
|
16
16
|
{ title: 'Import / export / sync', commands: ['import', 'export', 'sync'] },
|
package/dist/index.js
CHANGED
|
@@ -5,8 +5,15 @@
|
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
const program_1 = require("./program");
|
|
8
|
+
const updateCheck_1 = require("./lib/updateCheck");
|
|
8
9
|
(0, program_1.buildProgram)()
|
|
9
10
|
.parseAsync(process.argv)
|
|
11
|
+
.then(() => {
|
|
12
|
+
// Once per run, after the command succeeded: at most one stderr line a day about a newer version, and a
|
|
13
|
+
// detached background lookup when one is due. Never waits for the network, never throws, silent in
|
|
14
|
+
// pipes, CI and when switched off (see lib/updateCheck.ts).
|
|
15
|
+
(0, updateCheck_1.afterCommand)();
|
|
16
|
+
})
|
|
10
17
|
.catch((err) => {
|
|
11
18
|
// Commands handle their own errors; this only catches a bug in the wiring itself.
|
|
12
19
|
console.error(`✗ ${err instanceof Error ? err.message : String(err)}`);
|
package/dist/lib/api-client.js
CHANGED
|
@@ -34,6 +34,10 @@ exports.setProjectVisibility = setProjectVisibility;
|
|
|
34
34
|
exports.getPromptById = getPromptById;
|
|
35
35
|
exports.getPromptHistory = getPromptHistory;
|
|
36
36
|
exports.rollbackPrompt = rollbackPrompt;
|
|
37
|
+
exports.listPromptLabels = listPromptLabels;
|
|
38
|
+
exports.setPromptLabel = setPromptLabel;
|
|
39
|
+
exports.clearPromptLabel = clearPromptLabel;
|
|
40
|
+
exports.getLabeledVersion = getLabeledVersion;
|
|
37
41
|
exports.buildUseEventBody = buildUseEventBody;
|
|
38
42
|
exports.recordPromptUse = recordPromptUse;
|
|
39
43
|
exports.getUsageInsights = getUsageInsights;
|
|
@@ -534,6 +538,41 @@ async function rollbackPrompt(id, versionId) {
|
|
|
534
538
|
body: { versionId },
|
|
535
539
|
});
|
|
536
540
|
}
|
|
541
|
+
/** GET /api/prompts/{id}/labels → current labels + the latest moves. */
|
|
542
|
+
async function listPromptLabels(id) {
|
|
543
|
+
const res = await apiFetch(`/api/prompts/${id}/labels`);
|
|
544
|
+
return { labels: res.labels ?? [], events: res.events ?? [] };
|
|
545
|
+
}
|
|
546
|
+
/** PUT /api/prompts/{id}/labels/{label} — point the label at a version (moving it leaves an audit event). */
|
|
547
|
+
async function setPromptLabel(id, label, versionId) {
|
|
548
|
+
return apiFetch(`/api/prompts/${id}/labels/${encodeURIComponent(label)}`, {
|
|
549
|
+
method: 'PUT',
|
|
550
|
+
body: { versionId },
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
/** DELETE /api/prompts/{id}/labels/{label}. */
|
|
554
|
+
async function clearPromptLabel(id, label) {
|
|
555
|
+
return apiFetch(`/api/prompts/${id}/labels/${encodeURIComponent(label)}`, { method: 'DELETE' });
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* GET /api/prompts/{id}?label=… → the version the label points at (content + number).
|
|
559
|
+
* Throws a readable error when the label does not exist.
|
|
560
|
+
*/
|
|
561
|
+
async function getLabeledVersion(id, label) {
|
|
562
|
+
try {
|
|
563
|
+
const res = await apiFetch(`/api/prompts/${id}?label=${encodeURIComponent(label)}`);
|
|
564
|
+
const v = res.prompt?.labeled_version;
|
|
565
|
+
if (!v)
|
|
566
|
+
throw new Error(`Label '${label}' did not return a version.`);
|
|
567
|
+
return v;
|
|
568
|
+
}
|
|
569
|
+
catch (err) {
|
|
570
|
+
if (err instanceof ApiError && err.status === 404) {
|
|
571
|
+
throw new Error(`No label '${label}' on this prompt — see \`ple tag <name> --list\`.`);
|
|
572
|
+
}
|
|
573
|
+
throw err;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
537
576
|
/** Kullanım yüzeyleri — sunucudaki `USE_SURFACES` ile aynı küme (W1-1). */
|
|
538
577
|
exports.USE_SURFACES = [
|
|
539
578
|
'web', 'cli', 'mcp_tool', 'mcp_prompt', 'mcp_resource', 'extension', 'hook', 'repo', 'api', 'unknown',
|
package/dist/lib/errors.js
CHANGED
|
@@ -8,9 +8,13 @@ exports.exitCodeFor = exitCodeFor;
|
|
|
8
8
|
* 2 not your fault / try again: no network, timeout, rate limit, server error (5xx)
|
|
9
9
|
*/
|
|
10
10
|
const api_client_1 = require("./api-client");
|
|
11
|
+
const github_1 = require("./github");
|
|
11
12
|
function exitCodeFor(err) {
|
|
12
13
|
if (err instanceof api_client_1.NetworkError || err instanceof api_client_1.RequestTimeoutError)
|
|
13
14
|
return 2;
|
|
15
|
+
// GitHub: no network, timeout, rate limit, 5xx → try again; not found, empty, too large → fix the input.
|
|
16
|
+
if (err instanceof github_1.GithubError)
|
|
17
|
+
return err.retryable ? 2 : 1;
|
|
14
18
|
if (err instanceof api_client_1.ApiError && (err.status >= 500 || err.status === 429))
|
|
15
19
|
return 2;
|
|
16
20
|
return 1;
|
package/dist/lib/format.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.c = void 0;
|
|
|
7
7
|
exports.timeAgo = timeAgo;
|
|
8
8
|
exports.shortId = shortId;
|
|
9
9
|
exports.truncate = truncate;
|
|
10
|
+
exports.formatTags = formatTags;
|
|
10
11
|
exports.joinPromptParts = joinPromptParts;
|
|
11
12
|
exports.safeText = safeText;
|
|
12
13
|
const chalk_1 = __importDefault(require("chalk"));
|
|
@@ -59,6 +60,33 @@ function truncate(str, max) {
|
|
|
59
60
|
return str;
|
|
60
61
|
return str.slice(0, max - 1) + '…';
|
|
61
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Tag names for one table cell: every name cleaned with {@link safeText} (tag names come from
|
|
65
|
+
* the server, and from other people in shared repos, and are not cleaned by the API client),
|
|
66
|
+
* joined with ", " and kept within `max` characters. Whole tags are kept where they fit and the
|
|
67
|
+
* rest is counted ("debug, review +2"); a first tag too long for the cell is truncated.
|
|
68
|
+
*/
|
|
69
|
+
function formatTags(names, max = 24) {
|
|
70
|
+
const clean = names.map((n) => safeText(n).trim()).filter(Boolean);
|
|
71
|
+
if (clean.length === 0)
|
|
72
|
+
return '';
|
|
73
|
+
const all = clean.join(', ');
|
|
74
|
+
if (all.length <= max)
|
|
75
|
+
return all;
|
|
76
|
+
const shown = [];
|
|
77
|
+
for (let i = 0; i < clean.length; i++) {
|
|
78
|
+
const candidate = [...shown, clean[i]].join(', ');
|
|
79
|
+
const rest = clean.length - (i + 1);
|
|
80
|
+
if ((rest > 0 ? `${candidate} +${rest}` : candidate).length > max)
|
|
81
|
+
break;
|
|
82
|
+
shown.push(clean[i]);
|
|
83
|
+
}
|
|
84
|
+
if (shown.length === 0) {
|
|
85
|
+
const suffix = clean.length > 1 ? ` +${clean.length - 1}` : '';
|
|
86
|
+
return truncate(clean[0], Math.max(1, max - suffix.length)) + suffix;
|
|
87
|
+
}
|
|
88
|
+
return `${shown.join(', ')} +${clean.length - shown.length}`;
|
|
89
|
+
}
|
|
62
90
|
/** Üç parçalı içeriği (role/description/context) tek metne birleştir.
|
|
63
91
|
* Yapısal parçalardan yeniden kurar ve BOŞ bölümleri atlar → yalnız-description
|
|
64
92
|
* bir prompt'ta başıboş `---` ayraçları çıkmaz (E2E bulgusu F2). Stored `content`
|
package/dist/lib/frontmatter.js
CHANGED
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Minimal YAML-frontmatter reader for agent files (commands, SKILL.md,
|
|
4
4
|
* `.prompt.md`). Not a YAML parser — agent frontmatter is flat `key: value`
|
|
5
|
-
* lines plus the occasional list (`tags: [a, b]` or `- item` lines),
|
|
6
|
-
*
|
|
5
|
+
* lines plus the occasional list (`tags: [a, b]` or `- item` lines), a block
|
|
6
|
+
* scalar (`description: >` / `|`) and a one-level map (`metadata:` + indented
|
|
7
|
+
* `author: x`), and a full YAML dependency is off-limits for this CLI
|
|
8
|
+
* (commander + chalk only).
|
|
7
9
|
*
|
|
8
10
|
* Anything it cannot understand stays a raw string; nothing throws.
|
|
9
11
|
*/
|
|
@@ -16,6 +18,43 @@ function unquote(v) {
|
|
|
16
18
|
}
|
|
17
19
|
return t;
|
|
18
20
|
}
|
|
21
|
+
/** `>`, `>-`, `|`, `|-` (also the `+` and indentation-digit variants). */
|
|
22
|
+
const BLOCK_SCALAR = /^([>|])[0-9+-]{0,2}$/;
|
|
23
|
+
const indentOf = (line) => line.length - line.trimStart().length;
|
|
24
|
+
/**
|
|
25
|
+
* Lines after `from` that belong to a block scalar: blank, or indented deeper
|
|
26
|
+
* than the key that opened it. Returns them and the index of the first line
|
|
27
|
+
* that does not belong.
|
|
28
|
+
*/
|
|
29
|
+
function collectBlock(lines, from, keyIndent) {
|
|
30
|
+
let next = from;
|
|
31
|
+
while (next < lines.length && (lines[next].trim() === '' || indentOf(lines[next]) > keyIndent))
|
|
32
|
+
next++;
|
|
33
|
+
return { raw: lines.slice(from, next), next };
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Block scalar text: the common indentation is dropped. `|` keeps the line
|
|
37
|
+
* breaks, `>` folds lines into single spaces (a blank line stays a line
|
|
38
|
+
* break). The result is trimmed.
|
|
39
|
+
*/
|
|
40
|
+
function blockText(raw, folded) {
|
|
41
|
+
const filled = raw.filter((l) => l.trim() !== '');
|
|
42
|
+
const strip = filled.length > 0 ? Math.min(...filled.map(indentOf)) : 0;
|
|
43
|
+
const lines = raw.map((l) => (l.trim() === '' ? '' : l.slice(strip).trimEnd()));
|
|
44
|
+
if (!folded)
|
|
45
|
+
return lines.join('\n').trim();
|
|
46
|
+
let out = '';
|
|
47
|
+
let gap = 0;
|
|
48
|
+
for (const l of lines) {
|
|
49
|
+
if (l === '') {
|
|
50
|
+
gap++;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
out = out === '' ? l : gap > 0 ? `${out}${'\n'.repeat(gap)}${l}` : `${out} ${l}`;
|
|
54
|
+
gap = 0;
|
|
55
|
+
}
|
|
56
|
+
return out.trim();
|
|
57
|
+
}
|
|
19
58
|
function parseFrontmatter(raw) {
|
|
20
59
|
const text = raw.replace(/^/, '').replace(/\r\n/g, '\n');
|
|
21
60
|
const empty = { fields: {}, lists: {}, body: text };
|
|
@@ -29,29 +68,72 @@ function parseFrontmatter(raw) {
|
|
|
29
68
|
const body = afterClose.replace(/^[^\n]*\n?/, ''); // rest of the closing line
|
|
30
69
|
const fields = {};
|
|
31
70
|
const lists = {};
|
|
71
|
+
const lines = header.split('\n');
|
|
32
72
|
let currentListKey = null;
|
|
33
|
-
|
|
73
|
+
// A `key:` with no value opens either a list (`- item`) or a one-level map
|
|
74
|
+
// (` child: value`); whichever child comes first decides.
|
|
75
|
+
let mapParent = null;
|
|
76
|
+
let mapIndent = -1;
|
|
77
|
+
for (let i = 0; i < lines.length; i++) {
|
|
78
|
+
const line = lines[i];
|
|
34
79
|
const item = line.match(/^\s+-\s+(.*)$/) ?? line.match(/^-\s+(.*)$/);
|
|
35
80
|
if (item && currentListKey) {
|
|
36
81
|
lists[currentListKey].push(unquote(item[1]));
|
|
37
82
|
fields[currentListKey] = lists[currentListKey].join(', ');
|
|
83
|
+
mapParent = null; // it is a list
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (mapParent !== null && line.trim() !== '' && /^[ \t]/.test(line)) {
|
|
87
|
+
const child = line.match(/^([ \t]+)([A-Za-z0-9_-]+):[ \t]*(.*)$/);
|
|
88
|
+
if (child) {
|
|
89
|
+
const indent = child[1].length;
|
|
90
|
+
if (mapIndent === -1)
|
|
91
|
+
mapIndent = indent;
|
|
92
|
+
// Only the first level: deeper structure is skipped, not guessed at.
|
|
93
|
+
if (indent === mapIndent) {
|
|
94
|
+
const name = `${mapParent}_${child[2].toLowerCase()}`;
|
|
95
|
+
delete fields[mapParent];
|
|
96
|
+
delete lists[mapParent];
|
|
97
|
+
currentListKey = null;
|
|
98
|
+
const value = child[3].trim();
|
|
99
|
+
const block = value.match(BLOCK_SCALAR);
|
|
100
|
+
if (block) {
|
|
101
|
+
const b = collectBlock(lines, i + 1, indent);
|
|
102
|
+
fields[name] = blockText(b.raw, block[1] === '>');
|
|
103
|
+
i = b.next - 1;
|
|
104
|
+
}
|
|
105
|
+
else if (value !== '') {
|
|
106
|
+
fields[name] = unquote(value);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
38
110
|
continue;
|
|
39
111
|
}
|
|
40
112
|
const kv = line.match(/^([A-Za-z0-9_-]+):[ \t]*(.*)$/);
|
|
41
113
|
if (!kv) {
|
|
42
114
|
currentListKey = null;
|
|
115
|
+
mapParent = null;
|
|
43
116
|
continue;
|
|
44
117
|
}
|
|
45
118
|
const key = kv[1].toLowerCase();
|
|
46
119
|
const value = kv[2].trim();
|
|
120
|
+
mapParent = null;
|
|
121
|
+
mapIndent = -1;
|
|
47
122
|
if (value === '') {
|
|
48
123
|
currentListKey = key;
|
|
124
|
+
mapParent = key;
|
|
49
125
|
lists[key] = [];
|
|
50
126
|
fields[key] = '';
|
|
51
127
|
continue;
|
|
52
128
|
}
|
|
53
129
|
currentListKey = null;
|
|
54
|
-
|
|
130
|
+
const block = value.match(BLOCK_SCALAR);
|
|
131
|
+
if (block) {
|
|
132
|
+
const b = collectBlock(lines, i + 1, 0);
|
|
133
|
+
fields[key] = blockText(b.raw, block[1] === '>');
|
|
134
|
+
i = b.next - 1;
|
|
135
|
+
}
|
|
136
|
+
else if (value.startsWith('[') && value.endsWith(']')) {
|
|
55
137
|
lists[key] = value
|
|
56
138
|
.slice(1, -1)
|
|
57
139
|
.split(',')
|