promptlike 0.6.3 → 0.7.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 +15 -0
- package/README.md +34 -3
- package/dist/commands/diff.js +4 -0
- package/dist/commands/history.js +0 -7
- package/dist/commands/local.js +1 -0
- package/dist/commands/localHistory.js +180 -0
- package/dist/commands/log.js +4 -0
- package/dist/commands/rollback.js +4 -0
- package/dist/commands/save.js +7 -2
- package/dist/commands/sync.js +4 -2
- package/dist/index.js +2 -2
- package/dist/lib/localHistory.js +156 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.7.0 — 2026-10-15
|
|
4
|
+
|
|
5
|
+
- **Local version history (no account needed):** `ple save` now keeps an
|
|
6
|
+
append-only history under `~/.promptlike/history/<name>/` (`v0001.md`, …). A
|
|
7
|
+
save adds a version only when the prompt text changed. Signed out, `ple log`,
|
|
8
|
+
`ple diff [a] [b]` and `ple rollback <name> <version>` work on it instead of
|
|
9
|
+
saying "local prompts keep no versions". Rollback adds the old text as a new
|
|
10
|
+
version ("Restored vX as a new version. Nothing was deleted."); the CLI never
|
|
11
|
+
overwrites or deletes a version and there is no limit. These commands make no
|
|
12
|
+
network requests (covered by a test). Signed in, the three commands are
|
|
13
|
+
unchanged and still use the account history. `ple sync` uploads each prompt's
|
|
14
|
+
current text only; the local history is not uploaded.
|
|
15
|
+
- **Docs:** README describes the local history; the claim that the local store
|
|
16
|
+
keeps no versions is removed.
|
|
17
|
+
|
|
3
18
|
## 0.6.3 — 2026-10-13
|
|
4
19
|
|
|
5
20
|
- **Package metadata:** `repository` and `bugs` now point to the public plugin repository
|
package/README.md
CHANGED
|
@@ -94,9 +94,10 @@ $ ple save "code review" -m "Review this diff: {{diff}}" -t review
|
|
|
94
94
|
$ pbpaste | ple save "bug triage" # or pipe it in
|
|
95
95
|
```
|
|
96
96
|
|
|
97
|
-
Saving over an existing prompt needs `--force
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
Saving over an existing prompt needs `--force`. Tags and the description you do
|
|
98
|
+
not repeat are carried over rather than wiped. Every save that changes the text
|
|
99
|
+
also adds a version to a local, append-only history (see
|
|
100
|
+
[Local version history](#local-version-history-signed-out)).
|
|
100
101
|
|
|
101
102
|
### `ple sync [--dry-run]`
|
|
102
103
|
|
|
@@ -309,6 +310,36 @@ ple rollback "code review" v2 # asks first; --yes for scripts
|
|
|
309
310
|
Rollback is non-destructive: the old version is copied forward as a new one,
|
|
310
311
|
nothing is deleted — so a rollback can itself be undone.
|
|
311
312
|
|
|
313
|
+
#### Local version history (signed out)
|
|
314
|
+
|
|
315
|
+
Without an account the same three commands work on a history kept on your
|
|
316
|
+
machine, in `~/.promptlike/history/<name>/v0001.md`, `v0002.md`, … (the same
|
|
317
|
+
Markdown format as your prompts, so you can read, grep and commit it).
|
|
318
|
+
|
|
319
|
+
```bash
|
|
320
|
+
ple save "code review" -m "Review this diff: {{diff}}" # v1
|
|
321
|
+
ple save "code review" -m "Review this diff, be strict" --force # v2
|
|
322
|
+
ple log "code review" # newest first, * = current
|
|
323
|
+
ple diff "code review" # previous ↔ current (same unified format)
|
|
324
|
+
ple diff "code review" 1 2 # any two: 1, v1 or #1
|
|
325
|
+
ple rollback "code review" v1 # asks first; --yes for scripts
|
|
326
|
+
# ✓ Restored v1 as a new version. Nothing was deleted.
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
- A save adds a version only when the prompt text changed. Title, description
|
|
330
|
+
and tags are stored with each version, but only a change to the text creates one.
|
|
331
|
+
- Append-only: version files are never overwritten or deleted by the CLI and
|
|
332
|
+
there is no limit on how many are kept. A rollback adds a new version, so it
|
|
333
|
+
can be undone with another rollback. Rollback restores the text; the current
|
|
334
|
+
title, description and tags stay.
|
|
335
|
+
- A prompt that existed before you updated has no history yet; the first
|
|
336
|
+
`ple save --force` over it records the text that was on disk as v1 first.
|
|
337
|
+
A file you edited by hand is recorded the same way before a rollback.
|
|
338
|
+
- No network access: these commands only read and write files under
|
|
339
|
+
`~/.promptlike` (`PROMPTLIKE_HOME` moves it). `--project` is ignored signed out.
|
|
340
|
+
- `ple sync` uploads the current text of each prompt. The version history is
|
|
341
|
+
not uploaded and stays local.
|
|
342
|
+
|
|
312
343
|
### `ple stats [--range 7|30|365] [--json]`
|
|
313
344
|
|
|
314
345
|
How your library is actually used — the same numbers as the web Insights
|
package/dist/commands/diff.js
CHANGED
|
@@ -11,11 +11,15 @@ exports.diffCommand = diffCommand;
|
|
|
11
11
|
const api_client_1 = require("../lib/api-client");
|
|
12
12
|
const format_1 = require("../lib/format");
|
|
13
13
|
const diff_1 = require("../lib/diff");
|
|
14
|
+
const localHistory_1 = require("./localHistory");
|
|
15
|
+
const local_1 = require("./local");
|
|
14
16
|
const history_1 = require("./history");
|
|
15
17
|
function label(title, v) {
|
|
16
18
|
return `${title} v${v.version_number} (${(0, history_1.semverOf)(v)})`;
|
|
17
19
|
}
|
|
18
20
|
async function diffCommand(name, a, b, options = {}) {
|
|
21
|
+
if ((0, local_1.isSignedOut)())
|
|
22
|
+
return (0, localHistory_1.localDiff)(name, a, b, options);
|
|
19
23
|
const prompt = await (0, history_1.resolveForHistory)(name, options.project);
|
|
20
24
|
if (!prompt) {
|
|
21
25
|
process.exitCode = 1;
|
package/dist/commands/history.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* Shared helpers for `ple log`, `ple diff`, `ple rollback` (W1-4).
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.HISTORY_NEEDS_ACCOUNT = void 0;
|
|
7
6
|
exports.semverOf = semverOf;
|
|
8
7
|
exports.sortNewestFirst = sortNewestFirst;
|
|
9
8
|
exports.findVersion = findVersion;
|
|
@@ -12,8 +11,6 @@ exports.resolveForHistory = resolveForHistory;
|
|
|
12
11
|
exports.versionNotFound = versionNotFound;
|
|
13
12
|
const api_client_1 = require("../lib/api-client");
|
|
14
13
|
const promptResolver_1 = require("../lib/promptResolver");
|
|
15
|
-
const local_1 = require("./local");
|
|
16
|
-
exports.HISTORY_NEEDS_ACCOUNT = 'Version history lives in your account — local prompts keep no versions. Run `ple login`, then `ple sync`.';
|
|
17
14
|
/** "1.2.3" from the semver columns, else release_tag, else "v<n>". */
|
|
18
15
|
function semverOf(v) {
|
|
19
16
|
if (v.major_version != null && v.minor_version != null && v.patch_version != null) {
|
|
@@ -48,10 +45,6 @@ function currentVersion(history) {
|
|
|
48
45
|
}
|
|
49
46
|
/** Signed-in guard + name/--project resolution. Returns null when unresolved (message already printed). */
|
|
50
47
|
async function resolveForHistory(name, project) {
|
|
51
|
-
if ((0, local_1.isSignedOut)()) {
|
|
52
|
-
(0, local_1.noteIgnoredProject)(project);
|
|
53
|
-
throw new Error(exports.HISTORY_NEEDS_ACCOUNT);
|
|
54
|
-
}
|
|
55
48
|
await (0, api_client_1.ensureAuthed)();
|
|
56
49
|
const projectId = project ? await (0, promptResolver_1.resolveProjectId)(project) : undefined;
|
|
57
50
|
const prompt = await (0, promptResolver_1.resolvePromptByName)(name, { projectId });
|
package/dist/commands/local.js
CHANGED
|
@@ -42,6 +42,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
42
42
|
exports.isSignedOut = isSignedOut;
|
|
43
43
|
exports.noteIgnoredProject = noteIgnoredProject;
|
|
44
44
|
exports.emptyHint = emptyHint;
|
|
45
|
+
exports.resolveOrExplain = resolveOrExplain;
|
|
45
46
|
exports.localList = localList;
|
|
46
47
|
exports.localShow = localShow;
|
|
47
48
|
exports.localGet = localGet;
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Signed-out `ple log` / `ple diff` / `ple rollback` — over the local,
|
|
4
|
+
* append-only history (lib/localHistory.ts). No network, ever.
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
23
|
+
var ownKeys = function(o) {
|
|
24
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
+
var ar = [];
|
|
26
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
return ownKeys(o);
|
|
30
|
+
};
|
|
31
|
+
return function (mod) {
|
|
32
|
+
if (mod && mod.__esModule) return mod;
|
|
33
|
+
var result = {};
|
|
34
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
+
__setModuleDefault(result, mod);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.localLog = localLog;
|
|
41
|
+
exports.localDiff = localDiff;
|
|
42
|
+
exports.localRollback = localRollback;
|
|
43
|
+
const readline = __importStar(require("readline"));
|
|
44
|
+
const store = __importStar(require("../lib/localStore"));
|
|
45
|
+
const history = __importStar(require("../lib/localHistory"));
|
|
46
|
+
const format_1 = require("../lib/format");
|
|
47
|
+
const diff_1 = require("../lib/diff");
|
|
48
|
+
const local_1 = require("./local");
|
|
49
|
+
function versionNotFound(ref, versions) {
|
|
50
|
+
const known = [...versions].reverse().slice(0, 8).map((v) => `v${v.version}`).join(', ');
|
|
51
|
+
return new Error(`No version '${ref}'. Known: ${known || 'none'}${versions.length > 8 ? ', …' : ''} — see \`ple log\`.`);
|
|
52
|
+
}
|
|
53
|
+
/** Tell the user when the file on disk was edited outside `ple` (not in history yet). */
|
|
54
|
+
function noteUnrecorded(p, latest) {
|
|
55
|
+
if (latest && latest.body.trim() !== p.body.trim()) {
|
|
56
|
+
console.error(format_1.c.muted(`(The file on disk differs from v${latest.version} — it was edited outside ple. ` +
|
|
57
|
+
`Run \`ple save "${p.slug}" --force\` or a rollback to record it.)`));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function localLog(name, options) {
|
|
61
|
+
(0, local_1.noteIgnoredProject)(options.project);
|
|
62
|
+
const p = (0, local_1.resolveOrExplain)(name);
|
|
63
|
+
if (!p)
|
|
64
|
+
return;
|
|
65
|
+
const all = history.listVersions(p.slug);
|
|
66
|
+
const limit = Math.max(1, Math.min(Number.parseInt(options.limit ?? '20', 10) || 20, 100));
|
|
67
|
+
const shown = [...all].reverse().slice(0, limit);
|
|
68
|
+
const currentNo = all.length > 0 ? all[all.length - 1].version : null;
|
|
69
|
+
if (options.json) {
|
|
70
|
+
console.log(JSON.stringify(shown.map((v) => ({
|
|
71
|
+
version: v.version,
|
|
72
|
+
created_at: v.saved,
|
|
73
|
+
note: v.note || null,
|
|
74
|
+
current: v.version === currentNo,
|
|
75
|
+
})), null, 2));
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
console.log(format_1.c.title(p.title) + format_1.c.muted(` ${all.length} version${all.length === 1 ? '' : 's'} (local)`));
|
|
79
|
+
if (shown.length === 0) {
|
|
80
|
+
console.log(format_1.c.muted(' No versions yet — the next `ple save` records one.'));
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
for (const v of shown) {
|
|
84
|
+
const mark = v.version === currentNo ? format_1.c.success('*') : ' ';
|
|
85
|
+
console.log(`${mark} ${format_1.c.accent(`v${v.version}`.padEnd(5))} ${format_1.c.muted((0, format_1.timeAgo)(v.saved).padEnd(8))} ` +
|
|
86
|
+
(0, format_1.truncate)(v.note.replace(/\s+/g, ' '), 60));
|
|
87
|
+
}
|
|
88
|
+
if (all.length > shown.length) {
|
|
89
|
+
console.log(format_1.c.muted(` … ${all.length - shown.length} older (use --limit)`));
|
|
90
|
+
}
|
|
91
|
+
noteUnrecorded(p, all.length > 0 ? all[all.length - 1] : null);
|
|
92
|
+
console.log(format_1.c.muted(`\nCompare: ple diff "${p.slug}" <a> <b> · Restore: ple rollback "${p.slug}" <version>`));
|
|
93
|
+
}
|
|
94
|
+
function localDiff(name, a, b, options) {
|
|
95
|
+
(0, local_1.noteIgnoredProject)(options.project);
|
|
96
|
+
const p = (0, local_1.resolveOrExplain)(name);
|
|
97
|
+
if (!p)
|
|
98
|
+
return;
|
|
99
|
+
const versions = history.listVersions(p.slug);
|
|
100
|
+
const current = versions[versions.length - 1];
|
|
101
|
+
if (!current)
|
|
102
|
+
throw new Error(`'${p.title}' has no versions yet — the next \`ple save\` records one.`);
|
|
103
|
+
let from;
|
|
104
|
+
let to;
|
|
105
|
+
const need = (ref) => history.findVersion(versions, ref) ?? (() => { throw versionNotFound(ref, versions); })();
|
|
106
|
+
if (a && b) {
|
|
107
|
+
from = need(a);
|
|
108
|
+
to = need(b);
|
|
109
|
+
}
|
|
110
|
+
else if (a) {
|
|
111
|
+
from = need(a);
|
|
112
|
+
to = current;
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
to = current;
|
|
116
|
+
const older = versions[versions.length - 2];
|
|
117
|
+
if (!older) {
|
|
118
|
+
console.log(format_1.c.muted(`'${p.title}' has a single version — nothing to compare yet.`));
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
from = older;
|
|
122
|
+
}
|
|
123
|
+
const useColor = options.color !== false && format_1.c.success.level > 0;
|
|
124
|
+
const lines = (0, diff_1.unifiedDiff)(from.body, to.body, {
|
|
125
|
+
fromLabel: `${p.title} v${from.version}`,
|
|
126
|
+
toLabel: `${p.title} v${to.version}`,
|
|
127
|
+
colors: useColor ? { header: format_1.c.title, hunk: format_1.c.accent, add: format_1.c.success, del: format_1.c.error } : undefined,
|
|
128
|
+
});
|
|
129
|
+
if (lines.length === 0) {
|
|
130
|
+
console.log(format_1.c.muted(`v${from.version} and v${to.version} have identical content.`));
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
for (const line of lines)
|
|
134
|
+
console.log(line);
|
|
135
|
+
}
|
|
136
|
+
function defaultConfirm(question) {
|
|
137
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
138
|
+
return new Promise((resolve) => {
|
|
139
|
+
rl.question(question, (answer) => {
|
|
140
|
+
rl.close();
|
|
141
|
+
resolve(/^y(es)?$/i.test(answer.trim()));
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
async function localRollback(name, ref, options, deps = {}) {
|
|
146
|
+
(0, local_1.noteIgnoredProject)(options.project);
|
|
147
|
+
const p = (0, local_1.resolveOrExplain)(name);
|
|
148
|
+
if (!p)
|
|
149
|
+
return;
|
|
150
|
+
// Anything edited outside ple is recorded first, so a rollback can never
|
|
151
|
+
// hide the text it replaces.
|
|
152
|
+
history.recordIfChanged(p.slug, { title: p.title, description: p.description, tags: p.tags, body: p.body }, { onDisk: null, note: 'Edited outside ple' });
|
|
153
|
+
const versions = history.listVersions(p.slug);
|
|
154
|
+
const target = history.findVersion(versions, ref);
|
|
155
|
+
if (!target)
|
|
156
|
+
throw versionNotFound(ref, versions);
|
|
157
|
+
const current = versions[versions.length - 1];
|
|
158
|
+
if (current && current.body.trim() === target.body.trim()) {
|
|
159
|
+
console.log(format_1.c.muted(`v${target.version} is already the current content — nothing to do.`));
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
if (!options.yes) {
|
|
163
|
+
const interactive = deps.isTTY ?? Boolean(process.stdin.isTTY && process.stdout.isTTY);
|
|
164
|
+
if (!interactive) {
|
|
165
|
+
throw new Error('Refusing to roll back without confirmation. Re-run with --yes.');
|
|
166
|
+
}
|
|
167
|
+
const ok = await (deps.confirm ?? defaultConfirm)(`Restore '${p.title}' to v${target.version}? This adds a new version; nothing is deleted. [y/N] `);
|
|
168
|
+
if (!ok) {
|
|
169
|
+
console.log(format_1.c.muted('Cancelled.'));
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
// Body is restored; the title, description and tags you have now are kept.
|
|
174
|
+
const saved = store.save({ slug: p.slug, title: p.title, description: p.description, tags: p.tags, body: target.body });
|
|
175
|
+
const created = history.recordIfChanged(p.slug, { title: saved.title, description: saved.description, tags: saved.tags, body: saved.body }, { onDisk: null, note: `Restored from v${target.version}` });
|
|
176
|
+
console.log(format_1.c.success(`✓ Restored v${target.version} as a new version. Nothing was deleted.`) + format_1.c.muted(` — ${p.title}`));
|
|
177
|
+
if (created)
|
|
178
|
+
console.log(format_1.c.muted(` now at v${created.version}`));
|
|
179
|
+
console.log(format_1.c.muted(`Undo with: ple rollback "${p.slug}" v${current.version}`));
|
|
180
|
+
}
|
package/dist/commands/log.js
CHANGED
|
@@ -9,8 +9,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.logCommand = logCommand;
|
|
10
10
|
const api_client_1 = require("../lib/api-client");
|
|
11
11
|
const format_1 = require("../lib/format");
|
|
12
|
+
const localHistory_1 = require("./localHistory");
|
|
13
|
+
const local_1 = require("./local");
|
|
12
14
|
const history_1 = require("./history");
|
|
13
15
|
async function logCommand(name, options = {}) {
|
|
16
|
+
if ((0, local_1.isSignedOut)())
|
|
17
|
+
return (0, localHistory_1.localLog)(name, options);
|
|
14
18
|
const prompt = await (0, history_1.resolveForHistory)(name, options.project);
|
|
15
19
|
if (!prompt) {
|
|
16
20
|
process.exitCode = 1;
|
|
@@ -44,6 +44,8 @@ exports.rollbackCommand = rollbackCommand;
|
|
|
44
44
|
const readline = __importStar(require("readline"));
|
|
45
45
|
const api_client_1 = require("../lib/api-client");
|
|
46
46
|
const format_1 = require("../lib/format");
|
|
47
|
+
const localHistory_1 = require("./localHistory");
|
|
48
|
+
const local_1 = require("./local");
|
|
47
49
|
const history_1 = require("./history");
|
|
48
50
|
function defaultConfirm(question) {
|
|
49
51
|
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
@@ -55,6 +57,8 @@ function defaultConfirm(question) {
|
|
|
55
57
|
});
|
|
56
58
|
}
|
|
57
59
|
async function rollbackCommand(name, ref, options = {}, deps = {}) {
|
|
60
|
+
if ((0, local_1.isSignedOut)())
|
|
61
|
+
return (0, localHistory_1.localRollback)(name, ref, options, deps);
|
|
58
62
|
const prompt = await (0, history_1.resolveForHistory)(name, options.project);
|
|
59
63
|
if (!prompt) {
|
|
60
64
|
process.exitCode = 1;
|
package/dist/commands/save.js
CHANGED
|
@@ -46,6 +46,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
46
46
|
exports.collectTag = collectTag;
|
|
47
47
|
exports.saveCommand = saveCommand;
|
|
48
48
|
const store = __importStar(require("../lib/localStore"));
|
|
49
|
+
const history = __importStar(require("../lib/localHistory"));
|
|
49
50
|
const format_1 = require("../lib/format");
|
|
50
51
|
const promptVariables_1 = require("../lib/promptVariables");
|
|
51
52
|
/**
|
|
@@ -120,7 +121,8 @@ async function saveCommand(title, options = {}) {
|
|
|
120
121
|
const slug = store.slugify(cleanTitle);
|
|
121
122
|
const previous = store.read(slug);
|
|
122
123
|
// Overwriting someone's prompt silently is the one unrecoverable thing this
|
|
123
|
-
// command could do — the
|
|
124
|
+
// command could do — the old text is kept in the local history
|
|
125
|
+
// (lib/localHistory.ts), but --force stays an explicit step. Farklı başlıklar
|
|
124
126
|
// aynı slug'a inebilir ("a/b" ve "a:b" → "ab"); mesaj bu yüzden mevcut
|
|
125
127
|
// kaydın GERÇEK başlığını söyler, kullanıcının hiç yazmadığı slug'ı değil.
|
|
126
128
|
if (previous && !options.force) {
|
|
@@ -131,12 +133,15 @@ async function saveCommand(title, options = {}) {
|
|
|
131
133
|
}
|
|
132
134
|
// On --force, fields the user did not re-specify are CARRIED OVER.
|
|
133
135
|
// Overwriting the body must not silently wipe tags and the description —
|
|
134
|
-
// the
|
|
136
|
+
// the prompt file itself is replaced (the old body survives in the history).
|
|
135
137
|
const tags = options.tag && options.tag.length > 0 ? options.tag : (previous?.tags ?? []);
|
|
136
138
|
const description = options.description?.trim() ?? previous?.description ?? '';
|
|
137
139
|
const saved = store.save({ slug, title: cleanTitle, description, tags, body });
|
|
140
|
+
const version = history.recordIfChanged(slug, { title: saved.title, description: saved.description, tags: saved.tags, body: saved.body }, { onDisk: previous ? { title: previous.title, description: previous.description, tags: previous.tags, body: previous.body } : null });
|
|
138
141
|
console.log(format_1.c.success(`✓ Saved: ${saved.title}`) + format_1.c.muted(` (${saved.slug})`));
|
|
139
142
|
console.log(format_1.c.muted(` ${store.filePath(saved.slug)}`));
|
|
143
|
+
if (version)
|
|
144
|
+
console.log(format_1.c.muted(` version: v${version.version} (history: ple log "${saved.slug}")`));
|
|
140
145
|
const vars = (0, promptVariables_1.extractVariables)(saved.body);
|
|
141
146
|
if (vars.length > 0) {
|
|
142
147
|
console.log(format_1.c.muted(` variables: ${vars.map((v) => `{{${v}}}`).join(', ')}`));
|
package/dist/commands/sync.js
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
* someone asks for it.
|
|
9
9
|
*
|
|
10
10
|
* One-way (local → account) on purpose. Pulling the account library down would
|
|
11
|
-
* need conflict rules the local store cannot express
|
|
12
|
-
* and a half-correct merge silently losing an edit is worse than no pull.
|
|
11
|
+
* need conflict rules the local store cannot express (the local history is
|
|
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
13
|
*/
|
|
14
14
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
15
15
|
if (k2 === undefined) k2 = k;
|
|
@@ -47,6 +47,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
47
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
48
|
exports.syncCommand = syncCommand;
|
|
49
49
|
const store = __importStar(require("../lib/localStore"));
|
|
50
|
+
const history = __importStar(require("../lib/localHistory"));
|
|
50
51
|
const api_client_1 = require("../lib/api-client");
|
|
51
52
|
const format_1 = require("../lib/format");
|
|
52
53
|
const libraryCache_1 = require("../lib/libraryCache");
|
|
@@ -131,4 +132,5 @@ async function syncCommand(options = {}) {
|
|
|
131
132
|
// would duplicate, so say so rather than letting someone find out.
|
|
132
133
|
console.log(format_1.c.muted(`\nLocal files kept in ${store.promptsDir()} (sync copies, it does not move).`));
|
|
133
134
|
console.log(format_1.c.muted('Re-running would upload them again — delete the local copies first if that is not what you want.'));
|
|
135
|
+
console.log(format_1.c.muted(`Only the current text of each prompt is uploaded; the local version history stays in ${history.historyRoot()}.`));
|
|
134
136
|
}
|
package/dist/index.js
CHANGED
|
@@ -137,7 +137,7 @@ program
|
|
|
137
137
|
.action(runWithErrorHandler((opts) => (0, import_1.importCommand)(opts)));
|
|
138
138
|
program
|
|
139
139
|
.command('log <name>')
|
|
140
|
-
.description('Version history of a prompt (* = current)')
|
|
140
|
+
.description('Version history of a prompt (* = current). Signed out: the local history')
|
|
141
141
|
.option('--project <repo>', 'Scope to one repo (name, slug, or id) when titles collide')
|
|
142
142
|
.option('-l, --limit <n>', 'Max versions to show (default 20)', '20')
|
|
143
143
|
.option('--json', 'Print as JSON')
|
|
@@ -169,7 +169,7 @@ configCmd
|
|
|
169
169
|
.action(runWithErrorHandler(config_1.configSetCommand));
|
|
170
170
|
program
|
|
171
171
|
.command('rollback <name> <version>')
|
|
172
|
-
.description('Restore an old version as a new one — nothing is deleted')
|
|
172
|
+
.description('Restore an old version as a new one — nothing is deleted (signed out: local history)')
|
|
173
173
|
.option('--project <repo>', 'Scope to one repo (name, slug, or id) when titles collide')
|
|
174
174
|
.option('-y, --yes', 'Skip the confirmation prompt')
|
|
175
175
|
.action(runWithErrorHandler((name, version, opts) => (0, rollback_1.rollbackCommand)(name, version, opts)));
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Local, append-only version history — `~/.promptlike/history/<slug>/v0001.md`.
|
|
4
|
+
*
|
|
5
|
+
* WHY: signed out, `ple save --force` used to overwrite a prompt for good. The
|
|
6
|
+
* account has versions; the local store now keeps its own, so `ple log`,
|
|
7
|
+
* `ple diff` and `ple rollback` work without an account.
|
|
8
|
+
*
|
|
9
|
+
* RULES (deliberate, and covered by tests):
|
|
10
|
+
* - Append-only. Files are created with the exclusive flag (`wx`), so nothing
|
|
11
|
+
* here ever overwrites or deletes a version. There is no limit and no pruning.
|
|
12
|
+
* - A new version is written only when the prompt BODY changed.
|
|
13
|
+
* - Rollback never rewrites history: the old body becomes a NEW version.
|
|
14
|
+
* - Nothing here touches the network.
|
|
15
|
+
*
|
|
16
|
+
* Each version file is the same Markdown+frontmatter shape as the prompt store
|
|
17
|
+
* (greppable, diffable), plus `version:`, `saved:` and an optional `note:`.
|
|
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.historyRoot = historyRoot;
|
|
54
|
+
exports.historyDir = historyDir;
|
|
55
|
+
exports.listVersions = listVersions;
|
|
56
|
+
exports.latestVersion = latestVersion;
|
|
57
|
+
exports.recordIfChanged = recordIfChanged;
|
|
58
|
+
exports.findVersion = findVersion;
|
|
59
|
+
const fs = __importStar(require("fs"));
|
|
60
|
+
const path = __importStar(require("path"));
|
|
61
|
+
const store = __importStar(require("./localStore"));
|
|
62
|
+
function historyRoot() {
|
|
63
|
+
return path.join(store.localRoot(), 'history');
|
|
64
|
+
}
|
|
65
|
+
function historyDir(slug) {
|
|
66
|
+
return path.join(historyRoot(), slug);
|
|
67
|
+
}
|
|
68
|
+
function versionFile(slug, n) {
|
|
69
|
+
return path.join(historyDir(slug), `v${String(n).padStart(4, '0')}.md`);
|
|
70
|
+
}
|
|
71
|
+
function oneLine(v) {
|
|
72
|
+
return v.replace(/\r?\n/g, ' ').trim();
|
|
73
|
+
}
|
|
74
|
+
function parseVersion(n, raw, slug) {
|
|
75
|
+
const p = store.parse(slug, raw);
|
|
76
|
+
const header = raw.startsWith('---') ? raw.slice(3, Math.max(raw.indexOf('\n---', 3), 3)) : '';
|
|
77
|
+
const note = header.match(/^note:[ \t]*(.*)$/m);
|
|
78
|
+
return {
|
|
79
|
+
version: n,
|
|
80
|
+
saved: p.updated,
|
|
81
|
+
note: note ? note[1].trim() : '',
|
|
82
|
+
title: p.title,
|
|
83
|
+
description: p.description,
|
|
84
|
+
tags: p.tags,
|
|
85
|
+
body: p.body,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/** All versions, oldest first. Unreadable files are skipped, never fatal. */
|
|
89
|
+
function listVersions(slug) {
|
|
90
|
+
const dir = historyDir(slug);
|
|
91
|
+
if (!fs.existsSync(dir))
|
|
92
|
+
return [];
|
|
93
|
+
const out = [];
|
|
94
|
+
for (const f of fs.readdirSync(dir)) {
|
|
95
|
+
const m = f.match(/^v(\d+)\.md$/);
|
|
96
|
+
if (!m)
|
|
97
|
+
continue;
|
|
98
|
+
try {
|
|
99
|
+
out.push(parseVersion(Number(m[1]), fs.readFileSync(path.join(dir, f), 'utf-8'), slug));
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
/* a damaged file must not hide the rest of the history */
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return out.sort((a, b) => a.version - b.version);
|
|
106
|
+
}
|
|
107
|
+
function latestVersion(slug) {
|
|
108
|
+
const all = listVersions(slug);
|
|
109
|
+
return all.length > 0 ? all[all.length - 1] : null;
|
|
110
|
+
}
|
|
111
|
+
/** Append one version. Never overwrites: on a number clash it takes the next one. */
|
|
112
|
+
function append(slug, snap, note) {
|
|
113
|
+
const dir = historyDir(slug);
|
|
114
|
+
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
115
|
+
const saved = new Date().toISOString();
|
|
116
|
+
const base = store.serialize({ slug, ...snap, created: saved, updated: saved });
|
|
117
|
+
const extra = [`version: __N__`, `saved: ${saved}`, ...(note ? [`note: ${oneLine(note)}`] : [])];
|
|
118
|
+
let n = (latestVersion(slug)?.version ?? 0) + 1;
|
|
119
|
+
for (;;) {
|
|
120
|
+
const text = base.replace(/^---\n/, `---\n${extra.join('\n').replace('__N__', String(n))}\n`);
|
|
121
|
+
try {
|
|
122
|
+
fs.writeFileSync(versionFile(slug, n), text, { flag: 'wx', mode: 0o600 });
|
|
123
|
+
return parseVersion(n, text, slug);
|
|
124
|
+
}
|
|
125
|
+
catch (err) {
|
|
126
|
+
if (err.code !== 'EEXIST')
|
|
127
|
+
throw err;
|
|
128
|
+
n++; // another process got there first — never overwrite
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
const same = (a, b) => a.trim() === b.trim();
|
|
133
|
+
/**
|
|
134
|
+
* Record `current` as a new version if its body differs from the newest one.
|
|
135
|
+
* First contact with a prompt that already exists on disk but has no history
|
|
136
|
+
* (saved before this feature) records what is on disk FIRST, so the text about
|
|
137
|
+
* to be overwritten is not lost. Returns the version written, or null.
|
|
138
|
+
*/
|
|
139
|
+
function recordIfChanged(slug, current, options = {}) {
|
|
140
|
+
let latest = latestVersion(slug);
|
|
141
|
+
if (!latest && options.onDisk && options.onDisk.body.trim()) {
|
|
142
|
+
latest = append(slug, options.onDisk, '');
|
|
143
|
+
}
|
|
144
|
+
if (latest && same(latest.body, current.body))
|
|
145
|
+
return null;
|
|
146
|
+
if (!current.body.trim())
|
|
147
|
+
return null;
|
|
148
|
+
return append(slug, current, options.note ?? '');
|
|
149
|
+
}
|
|
150
|
+
/** Resolve `3`, `v3` or `#3`. */
|
|
151
|
+
function findVersion(versions, ref) {
|
|
152
|
+
const m = ref.trim().toLowerCase().match(/^[v#]?(\d+)$/);
|
|
153
|
+
if (!m)
|
|
154
|
+
return null;
|
|
155
|
+
return versions.find((v) => v.version === Number(m[1])) ?? null;
|
|
156
|
+
}
|
package/package.json
CHANGED