leanprompt 0.0.1 → 0.1.0-dev.8
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/LICENSE +202 -0
- package/LICENSE-DOCS +396 -0
- package/NOTICE +11 -0
- package/README.md +86 -3
- package/cli/dist/detect.d.ts +23 -0
- package/cli/dist/detect.js +219 -0
- package/cli/dist/evalAudit.d.ts +32 -0
- package/cli/dist/evalAudit.js +161 -0
- package/cli/dist/facts.d.ts +14 -0
- package/cli/dist/facts.js +43 -0
- package/cli/dist/forms.d.ts +23 -0
- package/cli/dist/forms.js +199 -0
- package/cli/dist/frontmatter.d.ts +10 -0
- package/cli/dist/frontmatter.js +32 -0
- package/cli/dist/help.d.ts +27 -0
- package/cli/dist/help.js +118 -0
- package/cli/dist/init.d.ts +78 -0
- package/cli/dist/init.js +358 -0
- package/cli/dist/install.d.ts +20 -0
- package/cli/dist/install.js +225 -0
- package/cli/dist/isMain.d.ts +6 -0
- package/cli/dist/isMain.js +18 -0
- package/cli/dist/lesson.d.ts +16 -0
- package/cli/dist/lesson.js +205 -0
- package/cli/dist/lint/facts.d.ts +7 -0
- package/cli/dist/lint/facts.js +163 -0
- package/cli/dist/lint/numbers.d.ts +26 -0
- package/cli/dist/lint/numbers.js +163 -0
- package/cli/dist/lint/rules.d.ts +20 -0
- package/cli/dist/lint/rules.js +170 -0
- package/cli/dist/log/logger.d.ts +49 -0
- package/cli/dist/log/logger.js +148 -0
- package/cli/dist/log/record.d.ts +56 -0
- package/cli/dist/log/record.js +117 -0
- package/cli/dist/main.d.ts +6 -0
- package/cli/dist/main.js +67 -0
- package/cli/dist/profile.d.ts +93 -0
- package/cli/dist/profile.js +372 -0
- package/cli/dist/report/cost.d.ts +55 -0
- package/cli/dist/report/cost.js +151 -0
- package/cli/dist/report/html.d.ts +81 -0
- package/cli/dist/report/html.js +555 -0
- package/cli/dist/report/template.html +269 -0
- package/cli/dist/score/calibrate.d.ts +65 -0
- package/cli/dist/score/calibrate.js +213 -0
- package/cli/dist/score/measured.d.ts +66 -0
- package/cli/dist/score/measured.js +191 -0
- package/cli/dist/score/static.d.ts +112 -0
- package/cli/dist/score/static.js +172 -0
- package/cli/dist/score/write.d.ts +29 -0
- package/cli/dist/score/write.js +247 -0
- package/forms/AGENTS.block.md +25 -0
- package/forms/opencode/commands/leanprompt-audit.md +10 -0
- package/forms/opencode/commands/leanprompt.md +8 -0
- package/forms/skills/generation-economy/SKILL.md +89 -0
- package/forms/skills/generation-economy/rules/LP-GE-01.md +93 -0
- package/forms/skills/generation-economy/rules/LP-GE-02.md +82 -0
- package/forms/skills/generation-economy/rules/LP-GE-03.md +87 -0
- package/forms/skills/generation-economy/rules/LP-GE-04.md +118 -0
- package/forms/skills/generation-economy/rules/LP-GE-05.md +84 -0
- package/forms/skills/generation-economy/rules/LP-GE-06.md +76 -0
- package/forms/skills/generation-economy/rules/LP-GE-07.md +84 -0
- package/forms/skills/generation-economy/rules/LP-GE-08.md +71 -0
- package/forms/skills/generation-economy/rules/LP-GE-09.md +79 -0
- package/forms/skills/generation-economy/rules/LP-GE-10.md +104 -0
- package/forms/skills/leanprompt/SKILL.md +48 -0
- package/forms/skills/leanprompt/fix.md +15 -0
- package/forms/skills/leanprompt/init.md +30 -0
- package/forms/skills/llm-call-audit/SKILL.md +169 -0
- package/forms/skills/llm-call-audit/call-shapes.md +99 -0
- package/forms/skills/llm-call-audit/presenting.md +72 -0
- package/forms/skills/llm-call-audit/report-template.md +113 -0
- package/forms/skills/lmwarden/SKILL.md +97 -0
- package/forms/skills/lmwarden/rules/LP-LW-01.md +73 -0
- package/forms/skills/lmwarden/rules/LP-LW-02.md +78 -0
- package/forms/skills/lmwarden/rules/LP-LW-03.md +73 -0
- package/forms/skills/measure-loop/SKILL.md +155 -0
- package/forms/skills/measure-loop/templates/stable-head.template.ts +38 -0
- package/forms/skills/measure-loop/templates/stable_head_template.py +40 -0
- package/forms/skills/prefill-cache/SKILL.md +66 -0
- package/forms/skills/prefill-cache/rules/LP-PC-01.md +103 -0
- package/forms/skills/prefill-cache/rules/LP-PC-02.md +80 -0
- package/forms/skills/prefill-cache/rules/LP-PC-03.md +75 -0
- package/forms/skills/prefill-cache/rules/LP-PC-04.md +79 -0
- package/forms/skills/prefill-cache/rules/LP-PC-05.md +68 -0
- package/forms/skills/prefill-cache/rules/LP-PC-06.md +71 -0
- package/forms/skills/prefill-cache/rules/LP-PC-07.md +97 -0
- package/forms/skills/prefill-cache/rules/LP-PC-08.md +67 -0
- package/forms/skills/prefill-cache/rules/LP-PC-09.md +75 -0
- package/forms/skills/prefill-cache/rules/LP-PC-10.md +76 -0
- package/forms/skills/prefill-cache/rules/LP-PC-11.md +72 -0
- package/forms/skills/prefill-cache/rules/LP-PC-12.md +73 -0
- package/forms/skills/prompt-diet/SKILL.md +69 -0
- package/forms/skills/prompt-diet/rules/LP-PD-01.md +79 -0
- package/forms/skills/prompt-diet/rules/LP-PD-02.md +73 -0
- package/forms/skills/prompt-diet/rules/LP-PD-03.md +65 -0
- package/forms/skills/prompt-diet/rules/LP-PD-04.md +77 -0
- package/forms/skills/prompt-diet/rules/LP-PD-05.md +71 -0
- package/forms/skills/prompt-diet/rules/LP-PD-06.md +68 -0
- package/models/anthropic-thinking.md +38 -0
- package/models/openai-reasoning.md +35 -0
- package/models/qwen.md +34 -0
- package/package.json +31 -8
- package/providers/anthropic.md +83 -0
- package/providers/deepinfra.md +46 -0
- package/providers/gemini.md +61 -0
- package/providers/openai.md +73 -0
- package/providers/openrouter.md +66 -0
- package/providers/sglang.md +41 -0
- package/providers/vllm.md +52 -0
- package/runtimes/http-clients.md +20 -0
- package/skills/_template/RULE.md +31 -0
- package/skills/generation-economy/SKILL.md +88 -0
- package/skills/generation-economy/rules/LP-GE-01.md +92 -0
- package/skills/generation-economy/rules/LP-GE-02.md +81 -0
- package/skills/generation-economy/rules/LP-GE-03.md +86 -0
- package/skills/generation-economy/rules/LP-GE-04.md +117 -0
- package/skills/generation-economy/rules/LP-GE-05.md +83 -0
- package/skills/generation-economy/rules/LP-GE-06.md +75 -0
- package/skills/generation-economy/rules/LP-GE-07.md +83 -0
- package/skills/generation-economy/rules/LP-GE-08.md +70 -0
- package/skills/generation-economy/rules/LP-GE-09.md +78 -0
- package/skills/generation-economy/rules/LP-GE-10.md +103 -0
- package/skills/leanprompt/SKILL.md +47 -0
- package/skills/leanprompt/fix.md +14 -0
- package/skills/leanprompt/init.md +29 -0
- package/skills/llm-call-audit/SKILL.md +168 -0
- package/skills/llm-call-audit/call-shapes.md +98 -0
- package/skills/llm-call-audit/presenting.md +71 -0
- package/skills/llm-call-audit/report-template.md +112 -0
- package/skills/lmwarden/SKILL.md +96 -0
- package/skills/lmwarden/rules/LP-LW-01.md +72 -0
- package/skills/lmwarden/rules/LP-LW-02.md +77 -0
- package/skills/lmwarden/rules/LP-LW-03.md +72 -0
- package/skills/measure-loop/SKILL.md +154 -0
- package/skills/measure-loop/templates/stable-head.template.ts +38 -0
- package/skills/measure-loop/templates/stable_head_template.py +40 -0
- package/skills/prefill-cache/SKILL.md +65 -0
- package/skills/prefill-cache/rules/LP-PC-01.md +102 -0
- package/skills/prefill-cache/rules/LP-PC-02.md +79 -0
- package/skills/prefill-cache/rules/LP-PC-03.md +74 -0
- package/skills/prefill-cache/rules/LP-PC-04.md +78 -0
- package/skills/prefill-cache/rules/LP-PC-05.md +67 -0
- package/skills/prefill-cache/rules/LP-PC-06.md +70 -0
- package/skills/prefill-cache/rules/LP-PC-07.md +96 -0
- package/skills/prefill-cache/rules/LP-PC-08.md +66 -0
- package/skills/prefill-cache/rules/LP-PC-09.md +74 -0
- package/skills/prefill-cache/rules/LP-PC-10.md +75 -0
- package/skills/prefill-cache/rules/LP-PC-11.md +71 -0
- package/skills/prefill-cache/rules/LP-PC-12.md +72 -0
- package/skills/prompt-diet/SKILL.md +68 -0
- package/skills/prompt-diet/rules/LP-PD-01.md +78 -0
- package/skills/prompt-diet/rules/LP-PD-02.md +72 -0
- package/skills/prompt-diet/rules/LP-PD-03.md +64 -0
- package/skills/prompt-diet/rules/LP-PD-04.md +76 -0
- package/skills/prompt-diet/rules/LP-PD-05.md +70 -0
- package/skills/prompt-diet/rules/LP-PD-06.md +67 -0
package/cli/dist/init.js
ADDED
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
import { existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { dirname, join, relative, resolve, sep } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { BLOCK_BEGIN, BLOCK_END, isGenerated, listFiles } from "./forms.js";
|
|
6
|
+
export const ASSISTANTS = ["claude", "codex", "opencode", "cursor", "agents-md"];
|
|
7
|
+
/** Names people know the assistants by, for what the installer prints. */
|
|
8
|
+
export const ASSISTANT_NAMES = {
|
|
9
|
+
claude: "Claude Code",
|
|
10
|
+
codex: "Codex",
|
|
11
|
+
opencode: "OpenCode",
|
|
12
|
+
cursor: "Cursor",
|
|
13
|
+
"agents-md": "an AGENTS.md agent",
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Where each assistant reads skills for all of a user's projects, from its own documentation
|
|
17
|
+
* (checked 2026-11-26; the table with the sources is docs/assistant-paths.md):
|
|
18
|
+
* - Claude Code: ~/.claude/skills (https://code.claude.com/docs/en/skills)
|
|
19
|
+
* - Codex: ~/.agents/skills, plus ~/.codex/AGENTS.md (https://learn.chatgpt.com/docs/build-skills,
|
|
20
|
+
* https://learn.chatgpt.com/docs/agent-configuration/agents-md)
|
|
21
|
+
* - OpenCode: ~/.config/opencode/commands and ~/.config/opencode/AGENTS.md; skills are read from
|
|
22
|
+
* ~/.claude/skills and ~/.agents/skills too (https://opencode.ai/docs/skills/, /docs/commands/, /docs/rules/)
|
|
23
|
+
* - Cursor: ~/.cursor/skills, and it also reads ~/.claude/skills and ~/.agents/skills
|
|
24
|
+
* (https://cursor.com/docs/context/skills)
|
|
25
|
+
* - The AGENTS.md convention has no user-level location (https://agents.md/), so project only.
|
|
26
|
+
*/
|
|
27
|
+
export const NO_GLOBAL = {
|
|
28
|
+
"agents-md": "the AGENTS.md convention has no user-level location (https://agents.md/), so it installs per project only",
|
|
29
|
+
};
|
|
30
|
+
// cli/src and cli/dist are the same depth below the package root.
|
|
31
|
+
const PACKAGE_ROOT = fileURLToPath(new URL("../../", import.meta.url));
|
|
32
|
+
const FORMS = join(PACKAGE_ROOT, "forms");
|
|
33
|
+
function isDir(p) {
|
|
34
|
+
try {
|
|
35
|
+
return lstatSync(p).isDirectory();
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function isFile(p) {
|
|
42
|
+
try {
|
|
43
|
+
return lstatSync(p).isFile();
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/** Which assistants a project (or, with --global, the home directory) appears to use, and why. */
|
|
50
|
+
export function detect(base, global) {
|
|
51
|
+
const found = [];
|
|
52
|
+
const add = (assistant, why) => found.push({ assistant, why });
|
|
53
|
+
if (global) {
|
|
54
|
+
if (isDir(join(base, ".claude")))
|
|
55
|
+
add("claude", "found ~/.claude");
|
|
56
|
+
if (isDir(join(base, ".codex")))
|
|
57
|
+
add("codex", "found ~/.codex");
|
|
58
|
+
if (isDir(join(base, ".config", "opencode")))
|
|
59
|
+
add("opencode", "found ~/.config/opencode");
|
|
60
|
+
if (isDir(join(base, ".cursor")))
|
|
61
|
+
add("cursor", "found ~/.cursor");
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
if (isDir(join(base, ".claude")))
|
|
65
|
+
add("claude", "found .claude/");
|
|
66
|
+
if (isFile(join(base, "AGENTS.md"))) {
|
|
67
|
+
add("agents-md", "found AGENTS.md");
|
|
68
|
+
if (isDir(join(base, ".codex")))
|
|
69
|
+
add("codex", "found AGENTS.md and .codex/");
|
|
70
|
+
if (isDir(join(base, ".opencode")))
|
|
71
|
+
add("opencode", "found AGENTS.md and .opencode/");
|
|
72
|
+
}
|
|
73
|
+
if (isDir(join(base, ".cursor")))
|
|
74
|
+
add("cursor", "found .cursor/");
|
|
75
|
+
if (isDir(join(base, ".opencode")) && !found.some((f) => f.assistant === "opencode"))
|
|
76
|
+
add("opencode", "found .opencode/");
|
|
77
|
+
}
|
|
78
|
+
if (found.length === 0)
|
|
79
|
+
add("agents-md", "no assistant detected, using the AGENTS.md convention");
|
|
80
|
+
return found;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Insert or replace the marked block, leaving every byte outside the markers as it was.
|
|
84
|
+
* (forms.spliceBlock normalises line endings and trailing newlines, which is right for this
|
|
85
|
+
* repo's own AGENTS.md but would rewrite a user's file.) Returns null when the markers are
|
|
86
|
+
* damaged (a begin without a following end), so the caller can refuse to guess.
|
|
87
|
+
*/
|
|
88
|
+
export function spliceUserBlock(existing, block) {
|
|
89
|
+
const body = block.replace(/\n+$/, "");
|
|
90
|
+
if (existing === null)
|
|
91
|
+
return body + "\n";
|
|
92
|
+
const crlf = existing.includes("\r\n");
|
|
93
|
+
const b = crlf ? body.replace(/\n/g, "\r\n") : body;
|
|
94
|
+
const i = existing.indexOf(BLOCK_BEGIN);
|
|
95
|
+
if (i >= 0) {
|
|
96
|
+
const j = existing.indexOf(BLOCK_END, i);
|
|
97
|
+
if (j < 0)
|
|
98
|
+
return null;
|
|
99
|
+
return existing.slice(0, i) + b + existing.slice(j + BLOCK_END.length);
|
|
100
|
+
}
|
|
101
|
+
if (existing.indexOf(BLOCK_END) >= 0)
|
|
102
|
+
return null;
|
|
103
|
+
const nl = crlf ? "\r\n" : "\n";
|
|
104
|
+
const sep = existing === "" ? "" : existing.endsWith(nl + nl) ? "" : existing.endsWith("\n") ? nl : nl + nl;
|
|
105
|
+
return existing + sep + b + nl;
|
|
106
|
+
}
|
|
107
|
+
function readForm(sub) {
|
|
108
|
+
const root = join(FORMS, sub);
|
|
109
|
+
if (!existsSync(root))
|
|
110
|
+
throw new Error(`forms/${sub} is missing from the package; reinstall leanprompt`);
|
|
111
|
+
return listFiles(root).map((rel) => ({ rel, text: readFileSync(join(root, rel), "utf8") }));
|
|
112
|
+
}
|
|
113
|
+
/** True when a skills folder already holds leanprompt's skills (written by an earlier run). */
|
|
114
|
+
function hasOurSkills(root) {
|
|
115
|
+
return ["leanprompt", "llm-call-audit"].some((s) => {
|
|
116
|
+
const f = join(root, s, "SKILL.md");
|
|
117
|
+
return isFile(f) && isGenerated(readFileSync(f, "utf8"));
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
function targetsFor(assistant, base, global, plan, notes, skillsViaClaude) {
|
|
121
|
+
const put = (path, text) => plan.files.set(path, text);
|
|
122
|
+
// One shared skills form serves .claude/skills, .agents/skills and .cursor/skills.
|
|
123
|
+
const skills = (dir) => {
|
|
124
|
+
for (const f of readForm("skills"))
|
|
125
|
+
put(join(base, dir, f.rel), f.text);
|
|
126
|
+
};
|
|
127
|
+
const addAgentsMd = (path) => plan.agents.add(join(base, path));
|
|
128
|
+
// OpenCode and Cursor also read .claude/skills and .agents/skills (home or project alike), so a
|
|
129
|
+
// copy there, already installed or planned by this run, serves them; a second copy would show every skill twice.
|
|
130
|
+
const sharedSkills = () => {
|
|
131
|
+
const claudeSkills = join(base, ".claude", "skills");
|
|
132
|
+
const agentsSkills = join(base, ".agents", "skills");
|
|
133
|
+
return (hasOurSkills(claudeSkills) ||
|
|
134
|
+
hasOurSkills(agentsSkills) ||
|
|
135
|
+
[...plan.files.keys()].some((p) => p.startsWith(claudeSkills + sep) || p.startsWith(agentsSkills + sep)));
|
|
136
|
+
};
|
|
137
|
+
if (global && NO_GLOBAL[assistant]) {
|
|
138
|
+
notes.push(`${assistant}: ${NO_GLOBAL[assistant]}; skipped. Run in the project with --scope=project to install it there.`);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
switch (assistant) {
|
|
142
|
+
case "claude":
|
|
143
|
+
skills(join(".claude", "skills"));
|
|
144
|
+
break;
|
|
145
|
+
case "codex":
|
|
146
|
+
skills(join(".agents", "skills"));
|
|
147
|
+
addAgentsMd(global ? ".codex/AGENTS.md" : "AGENTS.md");
|
|
148
|
+
break;
|
|
149
|
+
case "agents-md":
|
|
150
|
+
// With claude detected, the block points at .claude/skills; a second copy would show every skill twice.
|
|
151
|
+
if (!skillsViaClaude)
|
|
152
|
+
skills(join(".agents", "skills"));
|
|
153
|
+
addAgentsMd("AGENTS.md");
|
|
154
|
+
break;
|
|
155
|
+
case "opencode": {
|
|
156
|
+
const cmdDir = global ? ".config/opencode/commands" : ".opencode/commands";
|
|
157
|
+
for (const f of readForm("opencode/commands"))
|
|
158
|
+
put(join(base, cmdDir, f.rel), f.text);
|
|
159
|
+
addAgentsMd(global ? ".config/opencode/AGENTS.md" : "AGENTS.md");
|
|
160
|
+
if (!sharedSkills())
|
|
161
|
+
skills(join(".agents", "skills"));
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
case "cursor":
|
|
165
|
+
if (!sharedSkills())
|
|
166
|
+
skills(join(".cursor", "skills"));
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/** realpath of the deepest ancestor of `path` that exists. */
|
|
171
|
+
function deepestRealParent(path) {
|
|
172
|
+
let p = dirname(path);
|
|
173
|
+
while (!existsSync(p) && dirname(p) !== p)
|
|
174
|
+
p = dirname(p);
|
|
175
|
+
return realpathSync(p);
|
|
176
|
+
}
|
|
177
|
+
/** The first symlinked directory between `base` and `path`'s parent (falls back to the parent). */
|
|
178
|
+
function firstSymlink(base, path) {
|
|
179
|
+
let cur = base;
|
|
180
|
+
for (const seg of relative(base, dirname(path)).split(sep).filter(Boolean)) {
|
|
181
|
+
cur = join(cur, seg);
|
|
182
|
+
if (isLink(cur))
|
|
183
|
+
return cur;
|
|
184
|
+
}
|
|
185
|
+
return dirname(path);
|
|
186
|
+
}
|
|
187
|
+
const inside = (child, parent) => child === parent || child.startsWith(parent.endsWith(sep) ? parent : parent + sep);
|
|
188
|
+
const emptyResult = () => ({ written: [], updated: [], skipped: [], skippedWhy: [], detected: [], notes: [] });
|
|
189
|
+
/**
|
|
190
|
+
* Write a plan under `base`, with every protection: a file is created, or replaced only when it carries
|
|
191
|
+
* leanprompt's stamp (or, for AGENTS.md, between leanprompt's own markers); never through a symlink that
|
|
192
|
+
* leaves the project; never anything that is not a regular file.
|
|
193
|
+
*/
|
|
194
|
+
function applyPlan(plan, base, global, dryRun, result) {
|
|
195
|
+
const skip = (path, reason) => {
|
|
196
|
+
result.skipped.push(path);
|
|
197
|
+
result.skippedWhy.push({ path, reason });
|
|
198
|
+
};
|
|
199
|
+
const realBase = realpathSync(base);
|
|
200
|
+
const apply = (path, content, stamped) => {
|
|
201
|
+
const exists = existsSync(path) || isLink(path);
|
|
202
|
+
if (exists) {
|
|
203
|
+
if (!isFile(path))
|
|
204
|
+
return skip(path, "exists and is not a regular file");
|
|
205
|
+
const current = readFileSync(path);
|
|
206
|
+
if (current.equals(Buffer.from(content)))
|
|
207
|
+
return skip(path, "already up to date");
|
|
208
|
+
if (!stamped && !isGenerated(current.toString("utf8")))
|
|
209
|
+
return skip(path, "exists and is not a leanprompt file");
|
|
210
|
+
}
|
|
211
|
+
const real = deepestRealParent(path);
|
|
212
|
+
if (!inside(real, realBase)) {
|
|
213
|
+
if (!global)
|
|
214
|
+
return skip(path, "parent directory is a symlink outside the project");
|
|
215
|
+
const link = firstSymlink(base, path);
|
|
216
|
+
result.notes.push(`via symlink ${link} → ${realpathSync(link)}: ${path}`);
|
|
217
|
+
}
|
|
218
|
+
try {
|
|
219
|
+
if (!dryRun) {
|
|
220
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
221
|
+
writeFileSync(path, content);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
catch (e) {
|
|
225
|
+
return skip(path, `cannot write: ${e.code ?? e.message}`);
|
|
226
|
+
}
|
|
227
|
+
(exists ? result.updated : result.written).push(path);
|
|
228
|
+
};
|
|
229
|
+
for (const [path, content] of plan.files)
|
|
230
|
+
apply(path, content, false);
|
|
231
|
+
const block = readFileSync(join(FORMS, "AGENTS.block.md"), "utf8");
|
|
232
|
+
for (const path of plan.agents) {
|
|
233
|
+
let existing = null;
|
|
234
|
+
if (existsSync(path) || isLink(path)) {
|
|
235
|
+
if (!isFile(path)) {
|
|
236
|
+
skip(path, "exists and is not a regular file");
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
existing = readFileSync(path, "utf8");
|
|
240
|
+
}
|
|
241
|
+
const next = spliceUserBlock(existing, block);
|
|
242
|
+
if (next === null) {
|
|
243
|
+
skip(path, "leanprompt markers are damaged (begin without end); fix or remove them and run again");
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
apply(path, next, true);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
export function init(o) {
|
|
250
|
+
const global = o.global === true;
|
|
251
|
+
const base = global ? resolve(o.home ?? homedir()) : resolve(o.dir);
|
|
252
|
+
const result = emptyResult();
|
|
253
|
+
const forced = o.assistants ?? (o.assistant ? [o.assistant] : undefined);
|
|
254
|
+
if (forced)
|
|
255
|
+
result.detected = forced.map((assistant) => ({ assistant, why: o.assistants ? "--providers" : "--assistant" }));
|
|
256
|
+
else {
|
|
257
|
+
result.detected = detect(base, global);
|
|
258
|
+
// Nothing in the home directory says which assistants are used: go by the project instead.
|
|
259
|
+
if (global && result.detected.length === 1 && result.detected[0].assistant === "agents-md" && !isFile(join(base, "AGENTS.md"))) {
|
|
260
|
+
const local = detect(resolve(o.dir), false);
|
|
261
|
+
if (!(local.length === 1 && local[0].why.startsWith("no assistant"))) {
|
|
262
|
+
result.detected = local.map((d) => ({ assistant: d.assistant, why: `${d.why} in this project` }));
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
// Auto-detect only: claude and an AGENTS.md reader share one copy, in .claude/skills (OpenCode reads it too).
|
|
267
|
+
// .agents/skills is for codex (detected or asked) or when claude is absent; --assistant agents-md forces it.
|
|
268
|
+
const skillsViaClaude = !forced && result.detected.some((d) => d.assistant === "claude");
|
|
269
|
+
if (skillsViaClaude) {
|
|
270
|
+
const d = result.detected.find((x) => x.assistant === "agents-md");
|
|
271
|
+
if (d)
|
|
272
|
+
d.why = `${d.why}; its block points at .claude/skills, so no second copy in .agents/skills`;
|
|
273
|
+
}
|
|
274
|
+
const plan = { files: new Map(), agents: new Set() };
|
|
275
|
+
for (const { assistant } of ASSISTANTS.map((a) => result.detected.find((d) => d.assistant === a)).filter((d) => d !== undefined)) {
|
|
276
|
+
targetsFor(assistant, base, global, plan, result.notes, skillsViaClaude);
|
|
277
|
+
}
|
|
278
|
+
applyPlan(plan, base, global, o.dryRun === true, result);
|
|
279
|
+
return result;
|
|
280
|
+
}
|
|
281
|
+
/** Where leanprompt may have installed before, per scope (paths relative to the project or home). */
|
|
282
|
+
const LOCATIONS = {
|
|
283
|
+
project: {
|
|
284
|
+
skills: [".claude/skills", ".agents/skills", ".cursor/skills", ".opencode/skills"],
|
|
285
|
+
commands: [".opencode/commands", ".opencode/command"],
|
|
286
|
+
agents: ["AGENTS.md"],
|
|
287
|
+
legacyRules: [".cursor/rules"],
|
|
288
|
+
},
|
|
289
|
+
global: {
|
|
290
|
+
skills: [".claude/skills", ".agents/skills", ".cursor/skills", ".config/opencode/skills"],
|
|
291
|
+
commands: [".config/opencode/commands"],
|
|
292
|
+
agents: [".codex/AGENTS.md", ".config/opencode/AGENTS.md"],
|
|
293
|
+
legacyRules: [],
|
|
294
|
+
},
|
|
295
|
+
};
|
|
296
|
+
/**
|
|
297
|
+
* Refresh what an earlier `install` wrote, in each scope where it is found: a skills folder holding
|
|
298
|
+
* leanprompt's stamped skills, an OpenCode commands folder with leanprompt's command, an AGENTS.md with
|
|
299
|
+
* leanprompt's block. Unstamped files are never touched; new files of the same form are added.
|
|
300
|
+
*/
|
|
301
|
+
export function update(o) {
|
|
302
|
+
const result = { ...emptyResult(), found: [] };
|
|
303
|
+
const seen = new Set();
|
|
304
|
+
for (const scope of o.scopes ?? ["project", "global"]) {
|
|
305
|
+
const base = scope === "global" ? resolve(o.home ?? homedir()) : resolve(o.dir);
|
|
306
|
+
if (!isDir(base))
|
|
307
|
+
continue;
|
|
308
|
+
const loc = LOCATIONS[scope];
|
|
309
|
+
const plan = { files: new Map(), agents: new Set() };
|
|
310
|
+
const found = (path) => {
|
|
311
|
+
if (seen.has(path))
|
|
312
|
+
return false;
|
|
313
|
+
seen.add(path);
|
|
314
|
+
result.found.push({ scope, path });
|
|
315
|
+
return true;
|
|
316
|
+
};
|
|
317
|
+
for (const rel of loc.skills) {
|
|
318
|
+
const root = join(base, rel);
|
|
319
|
+
if (!hasOurSkills(root) || !found(root))
|
|
320
|
+
continue;
|
|
321
|
+
for (const f of readForm("skills"))
|
|
322
|
+
plan.files.set(join(root, f.rel), f.text);
|
|
323
|
+
}
|
|
324
|
+
for (const rel of loc.commands) {
|
|
325
|
+
const root = join(base, rel);
|
|
326
|
+
const ours = ["leanprompt.md", "leanprompt-audit.md"].some((n) => isFile(join(root, n)) && isGenerated(readFileSync(join(root, n), "utf8")));
|
|
327
|
+
if (!ours || !found(root))
|
|
328
|
+
continue;
|
|
329
|
+
for (const f of readForm("opencode/commands"))
|
|
330
|
+
plan.files.set(join(root, f.rel), f.text);
|
|
331
|
+
}
|
|
332
|
+
for (const rel of loc.agents) {
|
|
333
|
+
const file = join(base, rel);
|
|
334
|
+
if (!isFile(file) || !readFileSync(file, "utf8").includes(BLOCK_BEGIN) || !found(file))
|
|
335
|
+
continue;
|
|
336
|
+
plan.agents.add(file);
|
|
337
|
+
}
|
|
338
|
+
for (const rel of loc.legacyRules) {
|
|
339
|
+
const root = join(base, rel);
|
|
340
|
+
if (!isDir(root))
|
|
341
|
+
continue;
|
|
342
|
+
const old = readdirSync(root).filter((n) => /^leanprompt-.*\.mdc$/.test(n) && isGenerated(readFileSync(join(root, n), "utf8")));
|
|
343
|
+
if (old.length > 0) {
|
|
344
|
+
result.notes.push(`${join(root)}: ${old.length} rule file${old.length === 1 ? "" : "s"} from an older leanprompt (leanprompt-*.mdc). Cursor now reads the skills instead; delete them when you like. They were left as they are.`);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
applyPlan(plan, base, scope === "global", o.dryRun === true, result);
|
|
348
|
+
}
|
|
349
|
+
return result;
|
|
350
|
+
}
|
|
351
|
+
function isLink(p) {
|
|
352
|
+
try {
|
|
353
|
+
return lstatSync(p).isSymbolicLink();
|
|
354
|
+
}
|
|
355
|
+
catch {
|
|
356
|
+
return false;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type Assistant, type Scope } from "./init.js";
|
|
2
|
+
/** Terminal access, injectable so the prompts can be tested. */
|
|
3
|
+
export interface Io {
|
|
4
|
+
/** True when both stdin and stdout are a terminal, so a question can be asked and answered. */
|
|
5
|
+
interactive: boolean;
|
|
6
|
+
ask(question: string): Promise<string>;
|
|
7
|
+
out(line: string): void;
|
|
8
|
+
err(line: string): void;
|
|
9
|
+
}
|
|
10
|
+
export declare function terminalIo(): Io;
|
|
11
|
+
/** How the user starts leanprompt in each assistant, from its own documentation (docs/assistant-paths.md). */
|
|
12
|
+
export declare function nextStep(a: Assistant, scope: Scope): string;
|
|
13
|
+
/**
|
|
14
|
+
* `leanprompt install` (and its alias `init`): detect the assistants, choose the scope, show the files,
|
|
15
|
+
* confirm, write, and say what to type next. Without a terminal and without `--yes` it shows the plan
|
|
16
|
+
* and exits 1 without writing.
|
|
17
|
+
*/
|
|
18
|
+
export declare function installCommand(args: string[], io?: Io, name?: "install" | "init"): Promise<number>;
|
|
19
|
+
/** `leanprompt update`: refresh what install wrote, in each scope where it is found. */
|
|
20
|
+
export declare function updateCommand(args: string[], io?: Io): Promise<number>;
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { homedir } from "node:os";
|
|
2
|
+
import { basename, relative, resolve, sep } from "node:path";
|
|
3
|
+
import { createInterface } from "node:readline";
|
|
4
|
+
import { parseArgs } from "node:util";
|
|
5
|
+
import { optionsFor } from "./help.js";
|
|
6
|
+
import { ASSISTANT_NAMES, ASSISTANTS, init, update } from "./init.js";
|
|
7
|
+
export function terminalIo() {
|
|
8
|
+
return {
|
|
9
|
+
interactive: process.stdin.isTTY === true && process.stdout.isTTY === true,
|
|
10
|
+
ask: (question) => new Promise((resolveAnswer) => {
|
|
11
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
12
|
+
rl.question(question, (a) => {
|
|
13
|
+
// Resolve before close(): closing emits "close" at once, which would answer "".
|
|
14
|
+
resolveAnswer(a.trim());
|
|
15
|
+
rl.close();
|
|
16
|
+
});
|
|
17
|
+
rl.on("close", () => resolveAnswer(""));
|
|
18
|
+
}),
|
|
19
|
+
out: (line) => process.stdout.write(line + "\n"),
|
|
20
|
+
err: (line) => process.stderr.write(line + "\n"),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/** How the user starts leanprompt in each assistant, from its own documentation (docs/assistant-paths.md). */
|
|
24
|
+
export function nextStep(a, scope) {
|
|
25
|
+
const where = scope === "global" ? "in any project" : "here";
|
|
26
|
+
switch (a) {
|
|
27
|
+
case "claude":
|
|
28
|
+
return `Next: open Claude Code ${where} and type /leanprompt audit`;
|
|
29
|
+
case "codex":
|
|
30
|
+
return `Next: open Codex ${where} and type $leanprompt audit (or pick it from /skills)`;
|
|
31
|
+
case "cursor":
|
|
32
|
+
return `Next: open Cursor ${where} and type /leanprompt audit in the Agent chat`;
|
|
33
|
+
case "opencode":
|
|
34
|
+
return `Next: open OpenCode ${where} and type /leanprompt audit`;
|
|
35
|
+
case "agents-md":
|
|
36
|
+
return `Next: open your assistant ${where} and ask it to use the leanprompt skill to audit this app's LLM calls`;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function parseProviders(raw) {
|
|
40
|
+
const names = raw
|
|
41
|
+
.split(",")
|
|
42
|
+
.map((s) => s.trim().toLowerCase())
|
|
43
|
+
.filter(Boolean);
|
|
44
|
+
if (names.length === 0)
|
|
45
|
+
return "--providers needs at least one name";
|
|
46
|
+
const bad = names.filter((n) => !ASSISTANTS.includes(n));
|
|
47
|
+
if (bad.length > 0)
|
|
48
|
+
return `unknown provider${bad.length > 1 ? "s" : ""} ${bad.map((b) => `"${b}"`).join(", ")}; use ${ASSISTANTS.join(", ")}`;
|
|
49
|
+
return [...new Set(names)];
|
|
50
|
+
}
|
|
51
|
+
const yes = (a) => /^(y|yes)$/i.test(a);
|
|
52
|
+
/**
|
|
53
|
+
* `leanprompt install` (and its alias `init`): detect the assistants, choose the scope, show the files,
|
|
54
|
+
* confirm, write, and say what to type next. Without a terminal and without `--yes` it shows the plan
|
|
55
|
+
* and exits 1 without writing.
|
|
56
|
+
*/
|
|
57
|
+
export async function installCommand(args, io = terminalIo(), name = "install") {
|
|
58
|
+
let values;
|
|
59
|
+
try {
|
|
60
|
+
values = parseArgs({ args, options: optionsFor(name), strict: true }).values;
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
io.err(`leanprompt: ${e.message}`);
|
|
64
|
+
return 2;
|
|
65
|
+
}
|
|
66
|
+
let assistants;
|
|
67
|
+
if (values.providers !== undefined && values.assistant !== undefined) {
|
|
68
|
+
io.err("leanprompt: give --providers or --assistant, not both");
|
|
69
|
+
return 2;
|
|
70
|
+
}
|
|
71
|
+
if (values.providers !== undefined) {
|
|
72
|
+
const p = parseProviders(values.providers);
|
|
73
|
+
if (typeof p === "string") {
|
|
74
|
+
io.err(`leanprompt: ${p}`);
|
|
75
|
+
return 2;
|
|
76
|
+
}
|
|
77
|
+
assistants = p;
|
|
78
|
+
}
|
|
79
|
+
if (values.assistant !== undefined) {
|
|
80
|
+
if (!ASSISTANTS.includes(values.assistant)) {
|
|
81
|
+
io.err(`leanprompt: unknown assistant "${values.assistant}"; use ${ASSISTANTS.join(", ")}`);
|
|
82
|
+
return 2;
|
|
83
|
+
}
|
|
84
|
+
assistants = [values.assistant];
|
|
85
|
+
}
|
|
86
|
+
if (values.scope !== undefined && values.scope !== "project" && values.scope !== "global") {
|
|
87
|
+
io.err(`leanprompt: --scope must be project or global, not "${values.scope}"`);
|
|
88
|
+
return 2;
|
|
89
|
+
}
|
|
90
|
+
if (values.global === true && values.scope === "project") {
|
|
91
|
+
io.err("leanprompt: --global and --scope=project disagree; give one");
|
|
92
|
+
return 2;
|
|
93
|
+
}
|
|
94
|
+
const dir = resolve(values.dir ?? ".");
|
|
95
|
+
const home = resolve(homedir());
|
|
96
|
+
const dry = values["dry-run"] === true;
|
|
97
|
+
let scope = values.global === true ? "global" : values.scope;
|
|
98
|
+
if (scope === undefined && io.interactive && !dry) {
|
|
99
|
+
io.out("Install for this project or for all your projects?");
|
|
100
|
+
io.out(` 1. this project (${dir})`);
|
|
101
|
+
io.out(" 2. all your projects (your home folder)");
|
|
102
|
+
const a = (await io.ask("Choose 1 or 2 [1]: ")).toLowerCase();
|
|
103
|
+
scope = a === "2" || a === "global" || a === "all" ? "global" : "project";
|
|
104
|
+
}
|
|
105
|
+
scope ??= "project";
|
|
106
|
+
const global = scope === "global";
|
|
107
|
+
const opts = { dir, home, global, ...(assistants ? { assistants } : {}) };
|
|
108
|
+
const plan = init({ ...opts, dryRun: true });
|
|
109
|
+
const base = global ? home : dir;
|
|
110
|
+
const show = (p) => (global ? "~/" : "") + relative(base, p).split(sep).join("/");
|
|
111
|
+
io.out("Found:");
|
|
112
|
+
for (const d of plan.detected)
|
|
113
|
+
io.out(` ${ASSISTANT_NAMES[d.assistant]} (${d.assistant}): ${d.why}`);
|
|
114
|
+
if (assistants === undefined)
|
|
115
|
+
io.out(` To choose instead: --providers=${ASSISTANTS.join(",")} (any of them)`);
|
|
116
|
+
io.out(`Scope: ${global ? "all your projects (~)" : `this project (${dir})`}`);
|
|
117
|
+
for (const n of plan.notes)
|
|
118
|
+
io.out(n);
|
|
119
|
+
const changes = plan.written.length + plan.updated.length;
|
|
120
|
+
printPlan(plan, show, io, dry);
|
|
121
|
+
if (dry) {
|
|
122
|
+
io.out("dry run: nothing was written");
|
|
123
|
+
return 0;
|
|
124
|
+
}
|
|
125
|
+
if (changes === 0) {
|
|
126
|
+
io.out("Nothing to write.");
|
|
127
|
+
printNext(plan, scope, io);
|
|
128
|
+
return 0;
|
|
129
|
+
}
|
|
130
|
+
if (values.yes !== true) {
|
|
131
|
+
if (!io.interactive) {
|
|
132
|
+
io.out("Nothing written: there is no terminal to confirm in. Run again with --yes to write these files.");
|
|
133
|
+
return 1;
|
|
134
|
+
}
|
|
135
|
+
const a = await io.ask(`Write these ${changes} file${changes === 1 ? "" : "s"}? [y/N] `);
|
|
136
|
+
if (!yes(a)) {
|
|
137
|
+
io.out("Nothing written.");
|
|
138
|
+
return 1;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const r = init({ ...opts, dryRun: false });
|
|
142
|
+
const failed = r.skippedWhy.filter((s) => s.reason.startsWith("cannot write"));
|
|
143
|
+
for (const s of failed)
|
|
144
|
+
io.err(` could not write ${show(s.path)}: ${s.reason}`);
|
|
145
|
+
io.out(`Wrote ${r.written.length} new file${r.written.length === 1 ? "" : "s"}, updated ${r.updated.length}.`);
|
|
146
|
+
io.out("Reload your assistant so it sees the new skills.");
|
|
147
|
+
printNext(r, scope, io);
|
|
148
|
+
return failed.length > 0 ? 1 : 0;
|
|
149
|
+
}
|
|
150
|
+
function printPlan(r, show, io, dry) {
|
|
151
|
+
if (r.written.length > 0) {
|
|
152
|
+
io.out(`${dry ? "Would write" : "Will write"} ${r.written.length} new file${r.written.length === 1 ? "" : "s"}:`);
|
|
153
|
+
for (const p of r.written)
|
|
154
|
+
io.out(` ${dry ? "would write" : "write"} ${show(p)}`);
|
|
155
|
+
}
|
|
156
|
+
if (r.updated.length > 0) {
|
|
157
|
+
io.out(`${dry ? "Would update" : "Will update"} ${r.updated.length} file${r.updated.length === 1 ? "" : "s"}:`);
|
|
158
|
+
for (const p of r.updated)
|
|
159
|
+
io.out(` ${dry ? "would update" : "update"} ${show(p)}${basename(p) === "AGENTS.md" ? " (only the leanprompt block)" : ""}`);
|
|
160
|
+
}
|
|
161
|
+
const skippedNew = r.skippedWhy.filter((s) => s.reason !== "already up to date");
|
|
162
|
+
for (const s of skippedNew)
|
|
163
|
+
io.out(` skip ${show(s.path)}: ${s.reason}`);
|
|
164
|
+
const same = r.skippedWhy.length - skippedNew.length;
|
|
165
|
+
if (same > 0)
|
|
166
|
+
io.out(` ${same} file${same === 1 ? "" : "s"} already up to date`);
|
|
167
|
+
}
|
|
168
|
+
function printNext(r, scope, io) {
|
|
169
|
+
const served = r.detected.map((d) => d.assistant).filter((a) => !(scope === "global" && a === "agents-md"));
|
|
170
|
+
// claude plus an AGENTS.md reader share the claude copy; the AGENTS.md line adds nothing for them.
|
|
171
|
+
const lines = served.filter((a) => !(a === "agents-md" && served.length > 1)).map((a) => nextStep(a, scope));
|
|
172
|
+
for (const l of lines)
|
|
173
|
+
io.out(l);
|
|
174
|
+
}
|
|
175
|
+
/** `leanprompt update`: refresh what install wrote, in each scope where it is found. */
|
|
176
|
+
export async function updateCommand(args, io = terminalIo()) {
|
|
177
|
+
let values;
|
|
178
|
+
try {
|
|
179
|
+
values = parseArgs({ args, options: optionsFor("update"), strict: true }).values;
|
|
180
|
+
}
|
|
181
|
+
catch (e) {
|
|
182
|
+
io.err(`leanprompt: ${e.message}`);
|
|
183
|
+
return 2;
|
|
184
|
+
}
|
|
185
|
+
if (values.scope !== undefined && values.scope !== "project" && values.scope !== "global") {
|
|
186
|
+
io.err(`leanprompt: --scope must be project or global, not "${values.scope}"`);
|
|
187
|
+
return 2;
|
|
188
|
+
}
|
|
189
|
+
const dir = resolve(values.dir ?? ".");
|
|
190
|
+
const home = resolve(homedir());
|
|
191
|
+
const dry = values["dry-run"] === true;
|
|
192
|
+
const scopes = values.scope ? [values.scope] : ["project", "global"];
|
|
193
|
+
const r = update({ dir, home, scopes, dryRun: dry });
|
|
194
|
+
const show = (p) => {
|
|
195
|
+
if (p === dir || p.startsWith(dir + sep))
|
|
196
|
+
return relative(dir, p).split(sep).join("/") || ".";
|
|
197
|
+
if (p === home || p.startsWith(home + sep))
|
|
198
|
+
return "~/" + relative(home, p).split(sep).join("/");
|
|
199
|
+
return p;
|
|
200
|
+
};
|
|
201
|
+
for (const n of r.notes)
|
|
202
|
+
io.out(n.split(dir + sep).join("").split(home + sep).join("~/"));
|
|
203
|
+
if (r.found.length === 0) {
|
|
204
|
+
io.out(`No leanprompt install found ${values.scope === "global" ? "in your home folder" : values.scope === "project" ? `in ${dir}` : `in ${dir} or your home folder`}. Run leanprompt install first.`);
|
|
205
|
+
return 0;
|
|
206
|
+
}
|
|
207
|
+
io.out("Found leanprompt in:");
|
|
208
|
+
for (const f of r.found)
|
|
209
|
+
io.out(` ${f.scope}: ${show(f.path)}`);
|
|
210
|
+
for (const p of r.written)
|
|
211
|
+
io.out(` ${dry ? "would add" : "added"} ${show(p)}`);
|
|
212
|
+
for (const p of r.updated)
|
|
213
|
+
io.out(` ${dry ? "would update" : "updated"} ${show(p)}`);
|
|
214
|
+
const left = r.skippedWhy.filter((s) => s.reason !== "already up to date");
|
|
215
|
+
for (const s of left)
|
|
216
|
+
io.out(` left ${show(s.path)}: ${s.reason}`);
|
|
217
|
+
const same = r.skippedWhy.length - left.length;
|
|
218
|
+
if (r.written.length + r.updated.length === 0)
|
|
219
|
+
io.out(`Already up to date (${same} file${same === 1 ? "" : "s"}).`);
|
|
220
|
+
else
|
|
221
|
+
io.out(`${dry ? "dry run: nothing was written. " : ""}${r.written.length} added, ${r.updated.length} updated, ${same} already up to date.`);
|
|
222
|
+
if (!dry && r.written.length + r.updated.length > 0)
|
|
223
|
+
io.out("Reload your assistant so it sees the new version.");
|
|
224
|
+
return r.skippedWhy.some((s) => s.reason.startsWith("cannot write")) ? 1 : 0;
|
|
225
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* True when the module at `metaUrl` (pass `import.meta.url`) is the script node was started with.
|
|
3
|
+
* Both sides are resolved through symlinks, so `npm link`, `node_modules/.bin` and a symlinked
|
|
4
|
+
* checkout all count as the entry point.
|
|
5
|
+
*/
|
|
6
|
+
export declare function isMain(metaUrl: string): boolean;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { realpathSync } from "node:fs";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
/**
|
|
4
|
+
* True when the module at `metaUrl` (pass `import.meta.url`) is the script node was started with.
|
|
5
|
+
* Both sides are resolved through symlinks, so `npm link`, `node_modules/.bin` and a symlinked
|
|
6
|
+
* checkout all count as the entry point.
|
|
7
|
+
*/
|
|
8
|
+
export function isMain(metaUrl) {
|
|
9
|
+
const entry = process.argv[1];
|
|
10
|
+
if (!entry)
|
|
11
|
+
return false;
|
|
12
|
+
try {
|
|
13
|
+
return realpathSync(entry) === realpathSync(fileURLToPath(metaUrl));
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const LESSON_FILE: string;
|
|
2
|
+
/**
|
|
3
|
+
* What must be removed before a lesson is shared: keys, emails, IP addresses, host names, links other than this
|
|
4
|
+
* repo's, and file paths. The repo URL, rule ids and E-row citations pass. A link is allowed only in the
|
|
5
|
+
* "Credit (optional): project and link" section, where the contributor puts it on purpose. Matches are masked
|
|
6
|
+
* to their first characters, so a key is never printed in full.
|
|
7
|
+
*/
|
|
8
|
+
export declare function scanLesson(text: string): {
|
|
9
|
+
blocked: string[];
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* `leanprompt lesson [--rule <id>] [--before <older score.json>] [--dir <project>]`.
|
|
13
|
+
* Writes a draft to `.leanprompt/lesson.md` for the user to edit, scans it, and prints a prefilled
|
|
14
|
+
* GitHub issue link once it is clean. An existing draft is checked, not overwritten. Sends nothing.
|
|
15
|
+
*/
|
|
16
|
+
export declare function lessonCommand(args: string[]): Promise<number>;
|