promptlike 0.5.0 → 0.6.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 +35 -0
- package/README.md +101 -0
- package/dist/commands/config.js +41 -0
- package/dist/commands/diff.js +59 -0
- package/dist/commands/history.js +63 -0
- package/dist/commands/import.js +250 -0
- package/dist/commands/list.js +4 -0
- package/dist/commands/log.js +48 -0
- package/dist/commands/rollback.js +88 -0
- package/dist/commands/stats.js +112 -0
- package/dist/commands/suggest.js +244 -0
- package/dist/commands/sync.js +4 -0
- package/dist/index.js +59 -0
- package/dist/lib/api-client.js +91 -8
- package/dist/lib/diff.js +149 -0
- package/dist/lib/frontmatter.js +67 -0
- package/dist/lib/libraryCache.js +222 -0
- package/dist/lib/promptVariables.js +4 -2
- package/dist/lib/rank.js +123 -0
- package/dist/lib/scanners/index.js +252 -0
- package/dist/lib/secretGuard.js +92 -0
- package/dist/lib/settings.js +105 -0
- package/package.json +1 -1
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Agent-file scanners for `ple import --scan` (W1-2 — strategy F15).
|
|
4
|
+
*
|
|
5
|
+
* Finds the reusable instructions a developer already keeps on disk, in the
|
|
6
|
+
* places each agent reads them from:
|
|
7
|
+
*
|
|
8
|
+
* Claude Code ./.claude/commands/**\/*.md ~/.claude/commands/**\/*.md
|
|
9
|
+
* ./.claude/skills/*\/SKILL.md ~/.claude/skills/*\/SKILL.md
|
|
10
|
+
* Cursor ./.cursor/commands/*.md ~/.cursor/commands/*.md
|
|
11
|
+
* Codex ~/.codex/prompts/*.md
|
|
12
|
+
* Copilot ./.github/prompts/*.prompt.md
|
|
13
|
+
* Context ./AGENTS.md ./CLAUDE.md
|
|
14
|
+
*
|
|
15
|
+
* Table-driven: one entry per location, so adding a tool is one line.
|
|
16
|
+
* Every path goes through the secret guard (name check before opening, size
|
|
17
|
+
* check before reading, content check after) — see ./secretGuard.ts.
|
|
18
|
+
* Pure I/O on the local disk; nothing leaves the machine here.
|
|
19
|
+
*/
|
|
20
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
23
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
24
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
25
|
+
}
|
|
26
|
+
Object.defineProperty(o, k2, desc);
|
|
27
|
+
}) : (function(o, m, k, k2) {
|
|
28
|
+
if (k2 === undefined) k2 = k;
|
|
29
|
+
o[k2] = m[k];
|
|
30
|
+
}));
|
|
31
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
32
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
33
|
+
}) : function(o, v) {
|
|
34
|
+
o["default"] = v;
|
|
35
|
+
});
|
|
36
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
37
|
+
var ownKeys = function(o) {
|
|
38
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
39
|
+
var ar = [];
|
|
40
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
41
|
+
return ar;
|
|
42
|
+
};
|
|
43
|
+
return ownKeys(o);
|
|
44
|
+
};
|
|
45
|
+
return function (mod) {
|
|
46
|
+
if (mod && mod.__esModule) return mod;
|
|
47
|
+
var result = {};
|
|
48
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
49
|
+
__setModuleDefault(result, mod);
|
|
50
|
+
return result;
|
|
51
|
+
};
|
|
52
|
+
})();
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
exports.SCAN_TARGETS = void 0;
|
|
55
|
+
exports.hashBody = hashBody;
|
|
56
|
+
exports.scanAgentFiles = scanAgentFiles;
|
|
57
|
+
const crypto = __importStar(require("crypto"));
|
|
58
|
+
const fs = __importStar(require("fs"));
|
|
59
|
+
const os = __importStar(require("os"));
|
|
60
|
+
const path = __importStar(require("path"));
|
|
61
|
+
const frontmatter_1 = require("../frontmatter");
|
|
62
|
+
const secretGuard_1 = require("../secretGuard");
|
|
63
|
+
exports.SCAN_TARGETS = [
|
|
64
|
+
{ tool: 'claude-code', kind: 'command', root: 'cwd', pattern: { type: 'dir-md', dir: '.claude/commands', recursive: true } },
|
|
65
|
+
{ tool: 'claude-code', kind: 'command', root: 'home', pattern: { type: 'dir-md', dir: '.claude/commands', recursive: true } },
|
|
66
|
+
{ tool: 'claude-code', kind: 'skill', root: 'cwd', pattern: { type: 'skill-dirs', dir: '.claude/skills' } },
|
|
67
|
+
{ tool: 'claude-code', kind: 'skill', root: 'home', pattern: { type: 'skill-dirs', dir: '.claude/skills' } },
|
|
68
|
+
{ tool: 'cursor', kind: 'command', root: 'cwd', pattern: { type: 'dir-md', dir: '.cursor/commands', recursive: false } },
|
|
69
|
+
{ tool: 'cursor', kind: 'command', root: 'home', pattern: { type: 'dir-md', dir: '.cursor/commands', recursive: false } },
|
|
70
|
+
{ tool: 'codex', kind: 'prompt', root: 'home', pattern: { type: 'dir-md', dir: '.codex/prompts', recursive: false } },
|
|
71
|
+
{ tool: 'copilot', kind: 'prompt', root: 'cwd', pattern: { type: 'dir-md', dir: '.github/prompts', recursive: false, suffix: '.prompt.md' } },
|
|
72
|
+
{ tool: 'agents-md', kind: 'context', root: 'cwd', pattern: { type: 'file', file: 'AGENTS.md' } },
|
|
73
|
+
{ tool: 'agents-md', kind: 'context', root: 'cwd', pattern: { type: 'file', file: 'CLAUDE.md' } },
|
|
74
|
+
];
|
|
75
|
+
/** Recursion + volume guards — a scan must stay a one-second operation. */
|
|
76
|
+
const MAX_DEPTH = 4;
|
|
77
|
+
const MAX_FILES = 500;
|
|
78
|
+
const MAX_TAGS = 10;
|
|
79
|
+
const MAX_TITLE = 200;
|
|
80
|
+
const MAX_DESCRIPTION = 1000;
|
|
81
|
+
const KNOWN_KEYS = new Set(['name', 'title', 'description', 'tags']);
|
|
82
|
+
/** Line-ending + surrounding-whitespace insensitive hash of a prompt body. */
|
|
83
|
+
function hashBody(body) {
|
|
84
|
+
const normalized = body.replace(/\r\n/g, '\n').trim();
|
|
85
|
+
return crypto.createHash('sha256').update(normalized, 'utf8').digest('hex');
|
|
86
|
+
}
|
|
87
|
+
function listMdFiles(dir, recursive, suffix, depth = 0) {
|
|
88
|
+
let entries;
|
|
89
|
+
try {
|
|
90
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
return [];
|
|
94
|
+
}
|
|
95
|
+
const out = [];
|
|
96
|
+
for (const e of entries.sort((a, b) => a.name.localeCompare(b.name))) {
|
|
97
|
+
const full = path.join(dir, e.name);
|
|
98
|
+
if (e.isDirectory()) {
|
|
99
|
+
if (recursive && depth < MAX_DEPTH && !e.name.startsWith('.')) {
|
|
100
|
+
out.push(...listMdFiles(full, recursive, suffix, depth + 1));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
else if ((e.isFile() || e.isSymbolicLink()) && e.name.toLowerCase().endsWith(suffix)) {
|
|
104
|
+
out.push(full);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return out;
|
|
108
|
+
}
|
|
109
|
+
function expand(target, base) {
|
|
110
|
+
const p = target.pattern;
|
|
111
|
+
if (p.type === 'file') {
|
|
112
|
+
const f = path.join(base, p.file);
|
|
113
|
+
return fs.existsSync(f) ? [f] : [];
|
|
114
|
+
}
|
|
115
|
+
if (p.type === 'skill-dirs') {
|
|
116
|
+
const dir = path.join(base, p.dir);
|
|
117
|
+
let entries;
|
|
118
|
+
try {
|
|
119
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
return [];
|
|
123
|
+
}
|
|
124
|
+
return entries
|
|
125
|
+
.filter((e) => e.isDirectory() || e.isSymbolicLink())
|
|
126
|
+
.map((e) => path.join(dir, e.name, 'SKILL.md'))
|
|
127
|
+
.filter((f) => fs.existsSync(f))
|
|
128
|
+
.sort();
|
|
129
|
+
}
|
|
130
|
+
return listMdFiles(path.join(base, p.dir), p.recursive, p.suffix ?? '.md');
|
|
131
|
+
}
|
|
132
|
+
function titleFor(target, file, base, fmName) {
|
|
133
|
+
if (fmName)
|
|
134
|
+
return fmName;
|
|
135
|
+
const p = target.pattern;
|
|
136
|
+
if (p.type === 'file')
|
|
137
|
+
return `${path.basename(file)} (${path.basename(base)})`;
|
|
138
|
+
if (p.type === 'skill-dirs')
|
|
139
|
+
return path.basename(path.dirname(file));
|
|
140
|
+
const rel = path.relative(path.join(base, p.dir), file).split(path.sep).join('/');
|
|
141
|
+
const suffix = p.suffix ?? '.md';
|
|
142
|
+
return rel.toLowerCase().endsWith(suffix) ? rel.slice(0, -suffix.length) : rel;
|
|
143
|
+
}
|
|
144
|
+
function displayPathFor(file, root, home, cwd) {
|
|
145
|
+
if (root === 'home')
|
|
146
|
+
return `~/${path.relative(home, file).split(path.sep).join('/')}`;
|
|
147
|
+
return path.relative(cwd, file).split(path.sep).join('/');
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Read one file through the guard. Returns the raw text, or a skip reason.
|
|
151
|
+
* Symlinks are followed only to a regular `.md` file that also passes the
|
|
152
|
+
* name + size checks, so a link cannot smuggle `~/.ssh/id_rsa` into a scan.
|
|
153
|
+
*/
|
|
154
|
+
function guardedRead(file) {
|
|
155
|
+
if ((0, secretGuard_1.isDeniedFileName)(file))
|
|
156
|
+
return { reason: 'sensitive file name — never read' };
|
|
157
|
+
let real;
|
|
158
|
+
try {
|
|
159
|
+
real = fs.realpathSync(file);
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
return { reason: 'unreadable' };
|
|
163
|
+
}
|
|
164
|
+
if ((0, secretGuard_1.isDeniedFileName)(real) || !real.toLowerCase().endsWith('.md')) {
|
|
165
|
+
return { reason: 'link to a non-markdown or sensitive file — never read' };
|
|
166
|
+
}
|
|
167
|
+
let stat;
|
|
168
|
+
try {
|
|
169
|
+
stat = fs.statSync(real);
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
return { reason: 'unreadable' };
|
|
173
|
+
}
|
|
174
|
+
if (!stat.isFile())
|
|
175
|
+
return { reason: 'not a regular file' };
|
|
176
|
+
if (stat.size > secretGuard_1.MAX_SCAN_FILE_BYTES) {
|
|
177
|
+
return { reason: `larger than ${secretGuard_1.MAX_SCAN_FILE_BYTES / 1024} KB — skipped` };
|
|
178
|
+
}
|
|
179
|
+
try {
|
|
180
|
+
return { text: fs.readFileSync(real, 'utf-8'), bytes: stat.size };
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
return { reason: 'unreadable' };
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
function scanAgentFiles(options = {}) {
|
|
187
|
+
const cwd = path.resolve(options.cwd ?? process.cwd());
|
|
188
|
+
const home = path.resolve(options.home ?? os.homedir());
|
|
189
|
+
const candidates = [];
|
|
190
|
+
const skipped = [];
|
|
191
|
+
const duplicates = [];
|
|
192
|
+
const seenFiles = new Set();
|
|
193
|
+
const seenHashes = new Set();
|
|
194
|
+
let fileCount = 0;
|
|
195
|
+
scan: for (const target of exports.SCAN_TARGETS) {
|
|
196
|
+
const base = target.root === 'home' ? home : cwd;
|
|
197
|
+
// When cwd IS home, project and home targets overlap — scan once.
|
|
198
|
+
for (const file of expand(target, base)) {
|
|
199
|
+
const key = path.resolve(file);
|
|
200
|
+
if (seenFiles.has(key))
|
|
201
|
+
continue;
|
|
202
|
+
seenFiles.add(key);
|
|
203
|
+
if (++fileCount > MAX_FILES) {
|
|
204
|
+
skipped.push({ displayPath: displayPathFor(file, target.root, home, cwd), reason: `scan capped at ${MAX_FILES} files` });
|
|
205
|
+
break scan;
|
|
206
|
+
}
|
|
207
|
+
const displayPath = displayPathFor(file, target.root, home, cwd);
|
|
208
|
+
const read = guardedRead(file);
|
|
209
|
+
if ('reason' in read) {
|
|
210
|
+
skipped.push({ displayPath, reason: read.reason });
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
const secret = (0, secretGuard_1.findSecret)(read.text);
|
|
214
|
+
if (secret) {
|
|
215
|
+
skipped.push({ displayPath, reason: `looks like it contains a ${secret} — remove it, then re-run` });
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
const fm = (0, frontmatter_1.parseFrontmatter)(read.text);
|
|
219
|
+
const body = fm.body.trim();
|
|
220
|
+
if (!body) {
|
|
221
|
+
skipped.push({ displayPath, reason: 'empty body' });
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
const fmTags = fm.lists.tags ?? (fm.fields.tags ? fm.fields.tags.split(',') : []);
|
|
225
|
+
const tags = [...new Set([...fmTags.map((t) => t.trim()).filter(Boolean), target.tool])].slice(0, MAX_TAGS);
|
|
226
|
+
const meta = {};
|
|
227
|
+
for (const [k, v] of Object.entries(fm.fields)) {
|
|
228
|
+
if (!KNOWN_KEYS.has(k) && v)
|
|
229
|
+
meta[k] = v;
|
|
230
|
+
}
|
|
231
|
+
const candidate = {
|
|
232
|
+
tool: target.tool,
|
|
233
|
+
kind: target.kind,
|
|
234
|
+
displayPath,
|
|
235
|
+
title: titleFor(target, file, base, fm.fields.name || fm.fields.title || '').slice(0, MAX_TITLE),
|
|
236
|
+
description: (fm.fields.description ?? '').slice(0, MAX_DESCRIPTION),
|
|
237
|
+
tags,
|
|
238
|
+
body,
|
|
239
|
+
meta,
|
|
240
|
+
bytes: read.bytes,
|
|
241
|
+
sha256: hashBody(body),
|
|
242
|
+
};
|
|
243
|
+
if (seenHashes.has(candidate.sha256)) {
|
|
244
|
+
duplicates.push(candidate);
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
seenHashes.add(candidate.sha256);
|
|
248
|
+
candidates.push(candidate);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return { candidates, skipped, duplicates };
|
|
252
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Secret guard for `ple import --scan` (W1-2).
|
|
4
|
+
*
|
|
5
|
+
* Two layers, both deliberately conservative:
|
|
6
|
+
* 1. NAME — files that are secrets by convention (`.env*`, `*.key`, `*.pem`,
|
|
7
|
+
* `credentials*`, SSH keys) are never even opened.
|
|
8
|
+
* 2. CONTENT — a file that *does* get read is dropped (and reported without
|
|
9
|
+
* echoing the match) when it contains something shaped like a live token.
|
|
10
|
+
*
|
|
11
|
+
* Importing uploads to the user's account, so a false positive (skip a file,
|
|
12
|
+
* say why) is always cheaper than a false negative (leak a key into a prompt
|
|
13
|
+
* that might one day be made public).
|
|
14
|
+
*/
|
|
15
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
18
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
19
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
20
|
+
}
|
|
21
|
+
Object.defineProperty(o, k2, desc);
|
|
22
|
+
}) : (function(o, m, k, k2) {
|
|
23
|
+
if (k2 === undefined) k2 = k;
|
|
24
|
+
o[k2] = m[k];
|
|
25
|
+
}));
|
|
26
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
27
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
28
|
+
}) : function(o, v) {
|
|
29
|
+
o["default"] = v;
|
|
30
|
+
});
|
|
31
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
32
|
+
var ownKeys = function(o) {
|
|
33
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
34
|
+
var ar = [];
|
|
35
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
36
|
+
return ar;
|
|
37
|
+
};
|
|
38
|
+
return ownKeys(o);
|
|
39
|
+
};
|
|
40
|
+
return function (mod) {
|
|
41
|
+
if (mod && mod.__esModule) return mod;
|
|
42
|
+
var result = {};
|
|
43
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
44
|
+
__setModuleDefault(result, mod);
|
|
45
|
+
return result;
|
|
46
|
+
};
|
|
47
|
+
})();
|
|
48
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
49
|
+
exports.MAX_SCAN_FILE_BYTES = void 0;
|
|
50
|
+
exports.isDeniedFileName = isDeniedFileName;
|
|
51
|
+
exports.findSecret = findSecret;
|
|
52
|
+
const path = __importStar(require("path"));
|
|
53
|
+
/** Max size read from disk. Bigger files are skipped before reading. */
|
|
54
|
+
exports.MAX_SCAN_FILE_BYTES = 64 * 1024;
|
|
55
|
+
const DENY_NAME_PATTERNS = [
|
|
56
|
+
/^\.env(\..*)?$/i,
|
|
57
|
+
/\.key$/i,
|
|
58
|
+
/\.pem$/i,
|
|
59
|
+
/\.p12$/i,
|
|
60
|
+
/\.pfx$/i,
|
|
61
|
+
/^credentials/i,
|
|
62
|
+
/^id_(rsa|dsa|ecdsa|ed25519)/i,
|
|
63
|
+
/^\.netrc$/i,
|
|
64
|
+
/^\.npmrc$/i,
|
|
65
|
+
];
|
|
66
|
+
/** True when a file must never be opened, judged by its name alone. */
|
|
67
|
+
function isDeniedFileName(filePath) {
|
|
68
|
+
const base = path.basename(filePath);
|
|
69
|
+
return DENY_NAME_PATTERNS.some((re) => re.test(base));
|
|
70
|
+
}
|
|
71
|
+
const SECRET_PATTERNS = [
|
|
72
|
+
{ label: 'Anthropic/OpenAI API key', re: /\bsk-(?:ant-|proj-)?[A-Za-z0-9_-]{20,}/ },
|
|
73
|
+
{ label: 'AWS access key', re: /\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/ },
|
|
74
|
+
{ label: 'GitHub token', re: /\b(?:ghp|gho|ghu|ghs|ghr)_[A-Za-z0-9]{30,}\b|\bgithub_pat_[A-Za-z0-9_]{30,}/ },
|
|
75
|
+
{ label: 'GitLab token', re: /\bglpat-[A-Za-z0-9_-]{20,}/ },
|
|
76
|
+
{ label: 'Slack token', re: /\bxox[abprs]-[A-Za-z0-9-]{10,}/ },
|
|
77
|
+
{ label: 'Google API key', re: /\bAIza[0-9A-Za-z_-]{35}\b/ },
|
|
78
|
+
{ label: 'Stripe key', re: /\b(?:sk|rk)_live_[A-Za-z0-9]{20,}/ },
|
|
79
|
+
{ label: 'private key', re: /-----BEGIN [A-Z ]*PRIVATE KEY-----/ },
|
|
80
|
+
{ label: 'JWT', re: /\beyJ[A-Za-z0-9_-]{10,}\.eyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}/ },
|
|
81
|
+
];
|
|
82
|
+
/**
|
|
83
|
+
* Returns the *kind* of secret found (never the value), or null when clean.
|
|
84
|
+
* Callers print the label so the user knows which file to clean up.
|
|
85
|
+
*/
|
|
86
|
+
function findSecret(content) {
|
|
87
|
+
for (const { label, re } of SECRET_PATTERNS) {
|
|
88
|
+
if (re.test(content))
|
|
89
|
+
return label;
|
|
90
|
+
}
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* User preferences for the CLI — `~/.config/promptlike/settings.json`.
|
|
4
|
+
*
|
|
5
|
+
* Deliberately NOT in config.json: that file holds the session and is
|
|
6
|
+
* rewritten on every token refresh and deleted on logout, which would silently
|
|
7
|
+
* reset a preference the user set once.
|
|
8
|
+
*
|
|
9
|
+
* Today there is one key: `suggest` (on/off) — the Claude Code hook and
|
|
10
|
+
* `ple suggest --hook` stay silent when it is off.
|
|
11
|
+
*/
|
|
12
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
15
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
16
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
17
|
+
}
|
|
18
|
+
Object.defineProperty(o, k2, desc);
|
|
19
|
+
}) : (function(o, m, k, k2) {
|
|
20
|
+
if (k2 === undefined) k2 = k;
|
|
21
|
+
o[k2] = m[k];
|
|
22
|
+
}));
|
|
23
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
24
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
25
|
+
}) : function(o, v) {
|
|
26
|
+
o["default"] = v;
|
|
27
|
+
});
|
|
28
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
29
|
+
var ownKeys = function(o) {
|
|
30
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
31
|
+
var ar = [];
|
|
32
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
33
|
+
return ar;
|
|
34
|
+
};
|
|
35
|
+
return ownKeys(o);
|
|
36
|
+
};
|
|
37
|
+
return function (mod) {
|
|
38
|
+
if (mod && mod.__esModule) return mod;
|
|
39
|
+
var result = {};
|
|
40
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
41
|
+
__setModuleDefault(result, mod);
|
|
42
|
+
return result;
|
|
43
|
+
};
|
|
44
|
+
})();
|
|
45
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
+
exports.SETTING_KEYS = void 0;
|
|
47
|
+
exports.configDir = configDir;
|
|
48
|
+
exports.readSettings = readSettings;
|
|
49
|
+
exports.writeSettings = writeSettings;
|
|
50
|
+
exports.parseOnOff = parseOnOff;
|
|
51
|
+
exports.suggestEnabled = suggestEnabled;
|
|
52
|
+
const fs = __importStar(require("fs"));
|
|
53
|
+
const os = __importStar(require("os"));
|
|
54
|
+
const path = __importStar(require("path"));
|
|
55
|
+
exports.SETTING_KEYS = ['suggest'];
|
|
56
|
+
/** Config dir (same as the session file). `PROMPTLIKE_CONFIG_DIR` overrides it for tests. */
|
|
57
|
+
function configDir() {
|
|
58
|
+
const override = process.env.PROMPTLIKE_CONFIG_DIR;
|
|
59
|
+
if (override && override.trim())
|
|
60
|
+
return override.trim();
|
|
61
|
+
return path.join(os.homedir(), '.config', 'promptlike');
|
|
62
|
+
}
|
|
63
|
+
function settingsFile() {
|
|
64
|
+
return path.join(configDir(), 'settings.json');
|
|
65
|
+
}
|
|
66
|
+
function readSettings() {
|
|
67
|
+
try {
|
|
68
|
+
const raw = JSON.parse(fs.readFileSync(settingsFile(), 'utf-8'));
|
|
69
|
+
const out = {};
|
|
70
|
+
if (raw.suggest === 'on' || raw.suggest === 'off')
|
|
71
|
+
out.suggest = raw.suggest;
|
|
72
|
+
return out;
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return {};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function writeSettings(next) {
|
|
79
|
+
fs.mkdirSync(configDir(), { recursive: true, mode: 0o700 });
|
|
80
|
+
fs.writeFileSync(settingsFile(), JSON.stringify(next, null, 2) + '\n', { mode: 0o600 });
|
|
81
|
+
}
|
|
82
|
+
/** Parse a user-typed on/off value. */
|
|
83
|
+
function parseOnOff(value) {
|
|
84
|
+
const v = value.trim().toLowerCase();
|
|
85
|
+
if (['on', 'true', '1', 'yes'].includes(v))
|
|
86
|
+
return 'on';
|
|
87
|
+
if (['off', 'false', '0', 'no'].includes(v))
|
|
88
|
+
return 'off';
|
|
89
|
+
throw new Error(`Expected on or off, got '${value}'.`);
|
|
90
|
+
}
|
|
91
|
+
const OFF_VALUES = new Set(['off', 'false', '0', 'no']);
|
|
92
|
+
/**
|
|
93
|
+
* Suggestions are on unless switched off in any of three places:
|
|
94
|
+
* `PLE_SUGGEST=off`, the Claude Code plugin option (exported to hooks as
|
|
95
|
+
* `CLAUDE_PLUGIN_OPTION_SUGGESTIONS`), or `ple config set suggest off`.
|
|
96
|
+
*/
|
|
97
|
+
function suggestEnabled(env = process.env, settings = readSettings()) {
|
|
98
|
+
const envValue = env.PLE_SUGGEST?.trim().toLowerCase();
|
|
99
|
+
if (envValue && OFF_VALUES.has(envValue))
|
|
100
|
+
return false;
|
|
101
|
+
const pluginValue = env.CLAUDE_PLUGIN_OPTION_SUGGESTIONS?.trim().toLowerCase();
|
|
102
|
+
if (pluginValue && OFF_VALUES.has(pluginValue))
|
|
103
|
+
return false;
|
|
104
|
+
return settings.suggest !== 'off';
|
|
105
|
+
}
|
package/package.json
CHANGED