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
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { readFileSync, readdirSync, statSync, existsSync } from "node:fs";
|
|
2
|
+
import { posix, join } from "node:path";
|
|
3
|
+
import { parseDoc } from "./frontmatter.js";
|
|
4
|
+
export const SKILLS = ["leanprompt", "llm-call-audit", "prefill-cache", "generation-economy", "prompt-diet", "measure-loop", "lmwarden"];
|
|
5
|
+
export const BLOCK_BEGIN = "<!-- leanprompt:begin -->";
|
|
6
|
+
export const BLOCK_END = "<!-- leanprompt:end -->";
|
|
7
|
+
export const GENERATED_MARK = "<!-- leanprompt:generated";
|
|
8
|
+
export const generatedStamp = (version) => `${GENERATED_MARK} v${version}: written by npx leanprompt install; npx leanprompt update replaces local edits -->`;
|
|
9
|
+
const stamp = (text, version) => text.replace(/\n*$/, "\n") + generatedStamp(version) + "\n";
|
|
10
|
+
/** The stamp as a line comment, for the code templates (`//` for .ts, `#` for .py). */
|
|
11
|
+
export const codeStamp = (comment, version) => `${comment} leanprompt:generated v${version}: written by npx leanprompt install; npx leanprompt update replaces local edits`;
|
|
12
|
+
const stampCode = (text, comment, version) => text.replace(/\n*$/, "\n") + codeStamp(comment, version) + "\n";
|
|
13
|
+
/** True when a file's text carries any form of the generated stamp (markdown or code comment). */
|
|
14
|
+
export const isGenerated = (text) => text.includes(GENERATED_MARK) || /^(?:\/\/|#) leanprompt:generated v/m.test(text);
|
|
15
|
+
export const REPO = "https://github.com/Podwarden/leanprompt";
|
|
16
|
+
const PREAMBLE = `# AGENTS.md
|
|
17
|
+
|
|
18
|
+
This repo is leanprompt: skills that get more from every LLM call an app makes (cacheable
|
|
19
|
+
prompts, no dead weight, no wasted output, faster first tokens), plus a TypeScript CLI. Contributors:
|
|
20
|
+
|
|
21
|
+
- \`skills/\`, \`providers/\`, \`models/\`, \`runtimes/\`, \`docs/\` are the source of truth. Edit them, never \`forms/\`.
|
|
22
|
+
- \`npm run build:forms\` regenerates \`forms/\`, \`.claude-plugin/\` and the block below; CI runs
|
|
23
|
+
\`npm run build:forms -- --check\` and fails when they are stale.
|
|
24
|
+
- Provider facts (limits, prices, TTLs) live only in \`providers/\` and \`models/\`, and HTTP client
|
|
25
|
+
defaults in \`runtimes/\`, each with a \`checked:\` date and a \`source:\`. Every number in the docs links to its source.
|
|
26
|
+
- Commits carry a DCO sign-off (\`git commit -s\`).
|
|
27
|
+
|
|
28
|
+
The block below is generated. It is also what \`leanprompt install\` copies into other projects.
|
|
29
|
+
|
|
30
|
+
`;
|
|
31
|
+
const BLURB = {
|
|
32
|
+
leanprompt: "the entry point: `/leanprompt` lists the commands (init, audit, fix, measure, score, report, lesson)",
|
|
33
|
+
"llm-call-audit": "audit an app's LLM calls, rank the waste, write the report and findings",
|
|
34
|
+
"prefill-cache": "rules for prompts the provider's cache can reuse (LP-PC-*)",
|
|
35
|
+
"generation-economy": "rules for calls and output that are not wasted (LP-GE-*)",
|
|
36
|
+
"prompt-diet": "rules that cut dead weight from what each call sends (LP-PD-*)",
|
|
37
|
+
"measure-loop": "prove a fix with a before and after number; the score (CI test, logger)",
|
|
38
|
+
lmwarden: "rules for self-hosted vLLM, SGLang and LM Warden servers (LP-LW-*)",
|
|
39
|
+
};
|
|
40
|
+
const sorted = (xs) => [...xs].sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
|
|
41
|
+
const lf = (s) => s.replace(/\r\n?/g, "\n");
|
|
42
|
+
export function listFiles(dir, rel = "") {
|
|
43
|
+
const out = [];
|
|
44
|
+
for (const name of sorted(readdirSync(join(dir, rel)))) {
|
|
45
|
+
if (name === "__pycache__" || name.endsWith(".pyc"))
|
|
46
|
+
continue; // local interpreter cache, never source
|
|
47
|
+
const r = rel ? `${rel}/${name}` : name;
|
|
48
|
+
if (statSync(join(dir, r)).isDirectory())
|
|
49
|
+
out.push(...listFiles(dir, r));
|
|
50
|
+
else
|
|
51
|
+
out.push(r);
|
|
52
|
+
}
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
55
|
+
const LINK = /\]\(([^)\s]+)((?:\s+"[^"]*")?)\)/g;
|
|
56
|
+
/**
|
|
57
|
+
* Rewrite markdown links in `text`, which lives at repo path `fromFile`.
|
|
58
|
+
* mode "skills": links that stay inside skills/ remain relative; everything else becomes a GitHub URL.
|
|
59
|
+
* mode "flat": every local link becomes a GitHub URL (the file is installed outside the skills tree).
|
|
60
|
+
*/
|
|
61
|
+
export function rewriteLinks(text, fromFile, mode, root, version) {
|
|
62
|
+
return text.replace(LINK, (whole, target, title) => {
|
|
63
|
+
if (/^[a-z][a-z0-9+.-]*:/i.test(target) || target.startsWith("#") || target.startsWith("/"))
|
|
64
|
+
return whole;
|
|
65
|
+
const m = /^([^#?]*)([#?].*)?$/.exec(target);
|
|
66
|
+
const path = m[1];
|
|
67
|
+
const tail = m[2] ?? "";
|
|
68
|
+
const resolved = posix.normalize(posix.join(posix.dirname(fromFile), path));
|
|
69
|
+
if (resolved.startsWith(".."))
|
|
70
|
+
throw new Error(`${fromFile}: link ${target} leaves the repo`);
|
|
71
|
+
const abs = join(root, resolved);
|
|
72
|
+
if (!existsSync(abs))
|
|
73
|
+
throw new Error(`${fromFile}: link ${target} points at a missing file (${resolved})`);
|
|
74
|
+
if (mode === "skills" && resolved.startsWith("skills/"))
|
|
75
|
+
return whole;
|
|
76
|
+
const dir = statSync(abs).isDirectory();
|
|
77
|
+
const p = dir ? resolved.replace(/\/+$/, "") + "/" : resolved;
|
|
78
|
+
return `](${REPO}/${dir ? "tree" : "blob"}/v${version}/${p}${tail}${title})`;
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
function skillMeta(root, name) {
|
|
82
|
+
const raw = lf(readFileSync(join(root, "skills", name, "SKILL.md"), "utf8"));
|
|
83
|
+
const meta = parseDoc(raw).meta;
|
|
84
|
+
const description = typeof meta.description === "string" ? meta.description.trim() : "";
|
|
85
|
+
if (!description)
|
|
86
|
+
throw new Error(`skills/${name}/SKILL.md has no description`);
|
|
87
|
+
return { description };
|
|
88
|
+
}
|
|
89
|
+
export function agentsBlock() {
|
|
90
|
+
const lines = [
|
|
91
|
+
BLOCK_BEGIN,
|
|
92
|
+
"## leanprompt",
|
|
93
|
+
"",
|
|
94
|
+
"Skills that get more from every LLM call: cacheable prompts, no dead weight, no wasted output.",
|
|
95
|
+
"Load a skill only",
|
|
96
|
+
"when its task comes up, and a rule file only when the skill points at it.",
|
|
97
|
+
"",
|
|
98
|
+
"Skills live in `.claude/skills/<name>/`, `.agents/skills/<name>/` or `.cursor/skills/<name>/`:",
|
|
99
|
+
"",
|
|
100
|
+
...SKILLS.map((s) => `- \`${s}\`: ${BLURB[s]}`),
|
|
101
|
+
"",
|
|
102
|
+
"- Start with the `leanprompt` skill (`/leanprompt audit`, or `$leanprompt audit` in Codex), which routes to `llm-call-audit`.",
|
|
103
|
+
"- Rules are in `<skill>/rules/LP-*.md`. Each ends with `Verify`; run it before calling a fix done.",
|
|
104
|
+
"- Provider and model facts (limits, minimums, TTLs) are in the `providers/` and `models/`",
|
|
105
|
+
" pages linked from each rule, and HTTP client defaults in `runtimes/`, each with a `checked:`",
|
|
106
|
+
" date. Do not quote them from memory.",
|
|
107
|
+
"- Ask before editing code, installing a package, or running anything that sends billed requests.",
|
|
108
|
+
"- Keep meaning: a fix that changes what the model is asked or answers is not a fix.",
|
|
109
|
+
BLOCK_END,
|
|
110
|
+
];
|
|
111
|
+
return lines.join("\n") + "\n";
|
|
112
|
+
}
|
|
113
|
+
export function spliceBlock(existing, block) {
|
|
114
|
+
const b = block.replace(/\n+$/, "");
|
|
115
|
+
if (existing === null)
|
|
116
|
+
return PREAMBLE + b + "\n";
|
|
117
|
+
const text = lf(existing);
|
|
118
|
+
const i = text.indexOf(BLOCK_BEGIN);
|
|
119
|
+
const j = text.indexOf(BLOCK_END);
|
|
120
|
+
if (i < 0 || j < i)
|
|
121
|
+
return text.replace(/\n*$/, "\n\n") + b + "\n";
|
|
122
|
+
return text.slice(0, i) + b + text.slice(j + BLOCK_END.length);
|
|
123
|
+
}
|
|
124
|
+
function json(v) {
|
|
125
|
+
return JSON.stringify(v, null, 2) + "\n";
|
|
126
|
+
}
|
|
127
|
+
/** Everything generated from the source tree: repo-relative path -> content. */
|
|
128
|
+
export function buildForms(root) {
|
|
129
|
+
const out = new Map();
|
|
130
|
+
const pkg = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
|
|
131
|
+
const version = pkg.version;
|
|
132
|
+
for (const name of SKILLS) {
|
|
133
|
+
const base = join(root, "skills", name);
|
|
134
|
+
for (const f of listFiles(base)) {
|
|
135
|
+
let text = lf(readFileSync(join(base, f), "utf8"));
|
|
136
|
+
if (f.endsWith(".md"))
|
|
137
|
+
text = rewriteLinks(text, `skills/${name}/${f}`, "skills", root, version);
|
|
138
|
+
if (f.endsWith(".md"))
|
|
139
|
+
text = stamp(text, version);
|
|
140
|
+
else if (f.endsWith(".ts"))
|
|
141
|
+
text = stampCode(text, "//", version);
|
|
142
|
+
else if (f.endsWith(".py"))
|
|
143
|
+
text = stampCode(text, "#", version);
|
|
144
|
+
out.set(`forms/skills/${name}/${f}`, text);
|
|
145
|
+
}
|
|
146
|
+
skillMeta(root, name); // throws when a skill has no description
|
|
147
|
+
}
|
|
148
|
+
out.set("forms/opencode/commands/leanprompt.md", stamp([
|
|
149
|
+
"---",
|
|
150
|
+
"description: leanprompt commands for this app's LLM calls (init, audit, fix, measure, score, report, lesson)",
|
|
151
|
+
"---",
|
|
152
|
+
"",
|
|
153
|
+
"Load the `leanprompt` skill and follow its routing for this command: $ARGUMENTS",
|
|
154
|
+
"",
|
|
155
|
+
"With no command, show the skill's menu and suggest one next step. Do not edit code without asking.",
|
|
156
|
+
"",
|
|
157
|
+
].join("\n"), version));
|
|
158
|
+
out.set("forms/opencode/commands/leanprompt-audit.md", stamp([
|
|
159
|
+
"---",
|
|
160
|
+
"description: Audit this project's LLM calls with leanprompt and write leanprompt-report.md",
|
|
161
|
+
"---",
|
|
162
|
+
"",
|
|
163
|
+
"Load the `llm-call-audit` skill and run it on this project. Find every LLM call, check it",
|
|
164
|
+
"against the leanprompt rules, rank the findings by tokens lost, and write",
|
|
165
|
+
"`leanprompt-report.md` and `.leanprompt/findings.json`. Do not edit code without asking.",
|
|
166
|
+
"",
|
|
167
|
+
"Focus, if given: $ARGUMENTS",
|
|
168
|
+
"",
|
|
169
|
+
].join("\n"), version));
|
|
170
|
+
const block = agentsBlock();
|
|
171
|
+
out.set("forms/AGENTS.block.md", block);
|
|
172
|
+
const agentsPath = join(root, "AGENTS.md");
|
|
173
|
+
out.set("AGENTS.md", spliceBlock(existsSync(agentsPath) ? readFileSync(agentsPath, "utf8") : null, block));
|
|
174
|
+
out.set(".claude-plugin/plugin.json", json({
|
|
175
|
+
name: "leanprompt",
|
|
176
|
+
description: pkg.description,
|
|
177
|
+
version,
|
|
178
|
+
author: { name: "LM Warden Team" },
|
|
179
|
+
homepage: REPO,
|
|
180
|
+
repository: REPO,
|
|
181
|
+
license: "Apache-2.0 AND CC-BY-4.0",
|
|
182
|
+
}));
|
|
183
|
+
out.set(".claude-plugin/marketplace.json", json({
|
|
184
|
+
name: "leanprompt",
|
|
185
|
+
owner: { name: "LM Warden Team" },
|
|
186
|
+
metadata: { description: pkg.description },
|
|
187
|
+
plugins: [{ name: "leanprompt", source: "./", description: pkg.description }],
|
|
188
|
+
}));
|
|
189
|
+
return new Map([...out.entries()].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)));
|
|
190
|
+
}
|
|
191
|
+
/** Files under forms/ on disk that buildForms no longer produces. */
|
|
192
|
+
export function staleFiles(root, built) {
|
|
193
|
+
const dir = join(root, "forms");
|
|
194
|
+
if (!existsSync(dir))
|
|
195
|
+
return [];
|
|
196
|
+
return listFiles(dir)
|
|
197
|
+
.map((f) => `forms/${f}`)
|
|
198
|
+
.filter((f) => !built.has(f));
|
|
199
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface Section {
|
|
2
|
+
heading: string;
|
|
3
|
+
body: string;
|
|
4
|
+
}
|
|
5
|
+
export interface Doc {
|
|
6
|
+
meta: Record<string, unknown>;
|
|
7
|
+
sections: Section[];
|
|
8
|
+
}
|
|
9
|
+
/** Parse YAML frontmatter between leading `---` lines, then split the rest on level-2 headings. */
|
|
10
|
+
export declare function parseDoc(text: string): Doc;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { parse } from "yaml";
|
|
2
|
+
/** Parse YAML frontmatter between leading `---` lines, then split the rest on level-2 headings. */
|
|
3
|
+
export function parseDoc(text) {
|
|
4
|
+
const src = text.replace(/\r\n/g, "\n");
|
|
5
|
+
let meta = {};
|
|
6
|
+
let rest = src;
|
|
7
|
+
const m = /^---[ \t]*\n([\s\S]*?)\n---[ \t]*(?:\n|$)/.exec(src);
|
|
8
|
+
if (m) {
|
|
9
|
+
const parsed = parse(m[1]);
|
|
10
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed))
|
|
11
|
+
meta = parsed;
|
|
12
|
+
rest = src.slice(m[0].length);
|
|
13
|
+
}
|
|
14
|
+
const sections = [];
|
|
15
|
+
let cur = null;
|
|
16
|
+
let fence = false;
|
|
17
|
+
for (const line of rest.split("\n")) {
|
|
18
|
+
if (/^\s*(```|~~~)/.test(line))
|
|
19
|
+
fence = !fence;
|
|
20
|
+
const h = !fence ? /^##[ \t]+(.+?)[ \t]*$/.exec(line) : null;
|
|
21
|
+
if (h) {
|
|
22
|
+
if (cur)
|
|
23
|
+
sections.push({ heading: cur.heading, body: cur.lines.join("\n").trim() });
|
|
24
|
+
cur = { heading: h[1], lines: [] };
|
|
25
|
+
}
|
|
26
|
+
else if (cur)
|
|
27
|
+
cur.lines.push(line);
|
|
28
|
+
}
|
|
29
|
+
if (cur)
|
|
30
|
+
sections.push({ heading: cur.heading, body: cur.lines.join("\n").trim() });
|
|
31
|
+
return { meta, sections };
|
|
32
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One table of command specs. Every command builds its `parseArgs` options from it (`optionsFor`),
|
|
3
|
+
* and `--help` prints from it, so the help text cannot list a flag the parser rejects or miss one it accepts.
|
|
4
|
+
*/
|
|
5
|
+
export interface FlagSpec {
|
|
6
|
+
name: string;
|
|
7
|
+
type: "string" | "boolean";
|
|
8
|
+
/** Placeholder for the value, shown in help. */
|
|
9
|
+
arg?: string;
|
|
10
|
+
desc: string;
|
|
11
|
+
}
|
|
12
|
+
export interface CommandSpec {
|
|
13
|
+
name: string;
|
|
14
|
+
summary: string;
|
|
15
|
+
/** Positional arguments, shown in the usage line. */
|
|
16
|
+
positionals?: string;
|
|
17
|
+
flags: FlagSpec[];
|
|
18
|
+
}
|
|
19
|
+
export declare const SPECS: CommandSpec[];
|
|
20
|
+
export declare const spec: (name: string) => CommandSpec;
|
|
21
|
+
/** The `parseArgs` options object for a command. */
|
|
22
|
+
export declare function optionsFor(name: string): Record<string, {
|
|
23
|
+
type: "string" | "boolean";
|
|
24
|
+
}>;
|
|
25
|
+
export declare function usageLine(s: CommandSpec): string;
|
|
26
|
+
export declare function helpText(name: string): string;
|
|
27
|
+
export declare function overviewText(commandNames: string[]): string;
|
package/cli/dist/help.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { SKILLS } from "./forms.js";
|
|
2
|
+
const DIR = { name: "dir", type: "string", arg: "<project>", desc: "the project folder (default: the current directory)" };
|
|
3
|
+
const INSTALL_FLAGS = [
|
|
4
|
+
{ name: "providers", type: "string", arg: "<list>", desc: "install for these instead of detecting, comma-separated: claude, codex, opencode, cursor, agents-md" },
|
|
5
|
+
{ name: "scope", type: "string", arg: "project|global", desc: "this project, or all your projects (your home folder); asked when run in a terminal, else project" },
|
|
6
|
+
{ name: "yes", type: "boolean", desc: "write without asking; needed when there is no terminal to confirm in" },
|
|
7
|
+
{ name: "dry-run", type: "boolean", desc: "list what would be written or skipped; write nothing" },
|
|
8
|
+
{ name: "assistant", type: "string", arg: "<name>", desc: "one assistant, the older form of --providers" },
|
|
9
|
+
{ name: "global", type: "boolean", desc: "the older form of --scope=global" },
|
|
10
|
+
DIR,
|
|
11
|
+
];
|
|
12
|
+
export const SPECS = [
|
|
13
|
+
{
|
|
14
|
+
name: "install",
|
|
15
|
+
summary: "Install the skills for the coding assistants you use, in this project or for all your projects.",
|
|
16
|
+
flags: INSTALL_FLAGS,
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: "init",
|
|
20
|
+
summary: "Same as install (the older name, kept so existing links work).",
|
|
21
|
+
flags: INSTALL_FLAGS,
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: "update",
|
|
25
|
+
summary: "Refresh the files an earlier install wrote, wherever they are; never touches files it did not write.",
|
|
26
|
+
flags: [
|
|
27
|
+
{ name: "scope", type: "string", arg: "project|global", desc: "look only in this project or only in your home folder (default: both)" },
|
|
28
|
+
{ name: "dry-run", type: "boolean", desc: "list what would change; write nothing" },
|
|
29
|
+
DIR,
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: "score",
|
|
34
|
+
summary: "Write .leanprompt/score.json, measured from the usage log or static from the findings.",
|
|
35
|
+
flags: [
|
|
36
|
+
{ name: "measured", type: "string", arg: "[<usage.jsonl>]", desc: "score from the usage log (default .leanprompt/usage.jsonl; needs at least 50 calls)" },
|
|
37
|
+
{ name: "static", type: "string", arg: "[<findings.json>]", desc: "score from the audit's findings (default .leanprompt/findings.json)" },
|
|
38
|
+
{ name: "github", type: "boolean", desc: "also print a GitHub Actions annotation for each open finding in .leanprompt/findings.json" },
|
|
39
|
+
{ name: "fail-under", type: "string", arg: "<N>", desc: "exit 3 when the score is below N (default: never fail on the score)" },
|
|
40
|
+
DIR,
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: "calibrate",
|
|
45
|
+
summary: "Fit the static score's weights to this app from a trial run.",
|
|
46
|
+
flags: [
|
|
47
|
+
{ name: "findings", type: "string", arg: "<findings.json>", desc: "the findings file (default .leanprompt/findings.json)" },
|
|
48
|
+
{ name: "usage", type: "string", arg: "<usage.jsonl>", desc: "the usage log (default .leanprompt/usage.jsonl)" },
|
|
49
|
+
{ name: "synthetic", type: "boolean", desc: "the log comes from a synthetic run, not real traffic" },
|
|
50
|
+
{ name: "yes", type: "boolean", desc: "write .leanprompt/weights.json without asking" },
|
|
51
|
+
DIR,
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: "profile detect",
|
|
56
|
+
summary: "Read engine cache facts from LM Warden into leanprompt.yaml.",
|
|
57
|
+
flags: [
|
|
58
|
+
{ name: "lmwarden", type: "string", arg: "<url>", desc: "LM Warden base URL (required)" },
|
|
59
|
+
{ name: "token-env", type: "string", arg: "<VAR>", desc: "name of the environment variable holding the API key (default LMWARDEN_API_KEY)" },
|
|
60
|
+
{ name: "model", type: "string", arg: "<name>", desc: "the model, when the key can use several" },
|
|
61
|
+
],
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: "report",
|
|
65
|
+
summary: "Write the findings and the score to a local HTML page.",
|
|
66
|
+
flags: [
|
|
67
|
+
{ name: "html", type: "boolean", desc: "write the HTML page (required)" },
|
|
68
|
+
{ name: "out", type: "string", arg: "<file>", desc: "where to write it (default .leanprompt/report.html)" },
|
|
69
|
+
DIR,
|
|
70
|
+
],
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: "lesson",
|
|
74
|
+
summary: "Draft a lesson-learned issue on this machine; sends nothing.",
|
|
75
|
+
flags: [
|
|
76
|
+
{ name: "rule", type: "string", arg: "<id>", desc: "the rule the lesson is about, for example LP-PC-03 (needed unless you have a measured score)" },
|
|
77
|
+
{ name: "before", type: "string", arg: "<score.json>", desc: "an older score.json to compare against" },
|
|
78
|
+
DIR,
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: "eval-audit",
|
|
83
|
+
summary: "Score an audit's findings against a seeded example case.",
|
|
84
|
+
positionals: "<case-dir> <findings.json>",
|
|
85
|
+
flags: [{ name: "form", type: "string", arg: "before|after", desc: "which form of the case the findings describe (default before)" }],
|
|
86
|
+
},
|
|
87
|
+
];
|
|
88
|
+
export const spec = (name) => {
|
|
89
|
+
const s = SPECS.find((x) => x.name === name);
|
|
90
|
+
if (!s)
|
|
91
|
+
throw new Error(`no help for ${name}`);
|
|
92
|
+
return s;
|
|
93
|
+
};
|
|
94
|
+
/** The `parseArgs` options object for a command. */
|
|
95
|
+
export function optionsFor(name) {
|
|
96
|
+
return Object.fromEntries(spec(name).flags.map((f) => [f.name, { type: f.type }]));
|
|
97
|
+
}
|
|
98
|
+
const flagLabel = (f) => `--${f.name}${f.arg ? " " + f.arg : ""}`;
|
|
99
|
+
export function usageLine(s) {
|
|
100
|
+
const flags = s.flags.map((f) => `[${flagLabel(f)}]`).join(" ");
|
|
101
|
+
return `leanprompt ${s.name}${s.positionals ? " " + s.positionals : ""} ${flags}`;
|
|
102
|
+
}
|
|
103
|
+
export function helpText(name) {
|
|
104
|
+
const s = spec(name);
|
|
105
|
+
const labels = s.flags.map(flagLabel);
|
|
106
|
+
const w = Math.max(...labels.map((l) => l.length));
|
|
107
|
+
const lines = [s.summary, "", `usage: ${usageLine(s)}`, "", "options:"];
|
|
108
|
+
s.flags.forEach((f, i) => lines.push(` ${labels[i].padEnd(w)} ${f.desc}`));
|
|
109
|
+
lines.push(` ${"--help".padEnd(w)} show this text`);
|
|
110
|
+
return lines.join("\n") + "\n";
|
|
111
|
+
}
|
|
112
|
+
export function overviewText(commandNames) {
|
|
113
|
+
const rows = commandNames.map((c) => {
|
|
114
|
+
const s = SPECS.find((x) => x.name.split(" ")[0] === c);
|
|
115
|
+
return ` ${c.padEnd(11)}${s?.summary ?? ""}`;
|
|
116
|
+
});
|
|
117
|
+
return ["usage: leanprompt <command> [options]", "", "commands:", ...rows, "", `Skills that install writes: ${SKILLS.join(", ")}.`, "", "Run leanprompt <command> --help for a command's options.", "leanprompt --version prints the version.", ""].join("\n");
|
|
118
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export type Assistant = "claude" | "codex" | "opencode" | "cursor" | "agents-md";
|
|
2
|
+
export declare const ASSISTANTS: readonly Assistant[];
|
|
3
|
+
export type Scope = "project" | "global";
|
|
4
|
+
/** Names people know the assistants by, for what the installer prints. */
|
|
5
|
+
export declare const ASSISTANT_NAMES: Record<Assistant, string>;
|
|
6
|
+
/**
|
|
7
|
+
* Where each assistant reads skills for all of a user's projects, from its own documentation
|
|
8
|
+
* (checked 2026-11-26; the table with the sources is docs/assistant-paths.md):
|
|
9
|
+
* - Claude Code: ~/.claude/skills (https://code.claude.com/docs/en/skills)
|
|
10
|
+
* - Codex: ~/.agents/skills, plus ~/.codex/AGENTS.md (https://learn.chatgpt.com/docs/build-skills,
|
|
11
|
+
* https://learn.chatgpt.com/docs/agent-configuration/agents-md)
|
|
12
|
+
* - OpenCode: ~/.config/opencode/commands and ~/.config/opencode/AGENTS.md; skills are read from
|
|
13
|
+
* ~/.claude/skills and ~/.agents/skills too (https://opencode.ai/docs/skills/, /docs/commands/, /docs/rules/)
|
|
14
|
+
* - Cursor: ~/.cursor/skills, and it also reads ~/.claude/skills and ~/.agents/skills
|
|
15
|
+
* (https://cursor.com/docs/context/skills)
|
|
16
|
+
* - The AGENTS.md convention has no user-level location (https://agents.md/), so project only.
|
|
17
|
+
*/
|
|
18
|
+
export declare const NO_GLOBAL: Partial<Record<Assistant, string>>;
|
|
19
|
+
export interface InitOptions {
|
|
20
|
+
dir: string;
|
|
21
|
+
assistant?: Assistant;
|
|
22
|
+
/** Install for these assistants instead of detecting (`--providers`). */
|
|
23
|
+
assistants?: Assistant[];
|
|
24
|
+
global?: boolean;
|
|
25
|
+
/** Plan and report, write nothing. */
|
|
26
|
+
dryRun?: boolean;
|
|
27
|
+
/** Home directory for `--global`; defaults to the user's. */
|
|
28
|
+
home?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface InitResult {
|
|
31
|
+
/** Absolute paths of files that did not exist and were created. */
|
|
32
|
+
written: string[];
|
|
33
|
+
/** Absolute paths of leanprompt-owned files that differed and were replaced. */
|
|
34
|
+
updated: string[];
|
|
35
|
+
/** Absolute paths left alone (identical, or not ours to touch). */
|
|
36
|
+
skipped: string[];
|
|
37
|
+
skippedWhy: {
|
|
38
|
+
path: string;
|
|
39
|
+
reason: string;
|
|
40
|
+
}[];
|
|
41
|
+
detected: {
|
|
42
|
+
assistant: Assistant;
|
|
43
|
+
why: string;
|
|
44
|
+
}[];
|
|
45
|
+
notes: string[];
|
|
46
|
+
}
|
|
47
|
+
/** Which assistants a project (or, with --global, the home directory) appears to use, and why. */
|
|
48
|
+
export declare function detect(base: string, global: boolean): {
|
|
49
|
+
assistant: Assistant;
|
|
50
|
+
why: string;
|
|
51
|
+
}[];
|
|
52
|
+
/**
|
|
53
|
+
* Insert or replace the marked block, leaving every byte outside the markers as it was.
|
|
54
|
+
* (forms.spliceBlock normalises line endings and trailing newlines, which is right for this
|
|
55
|
+
* repo's own AGENTS.md but would rewrite a user's file.) Returns null when the markers are
|
|
56
|
+
* damaged (a begin without a following end), so the caller can refuse to guess.
|
|
57
|
+
*/
|
|
58
|
+
export declare function spliceUserBlock(existing: string | null, block: string): string | null;
|
|
59
|
+
export declare function init(o: InitOptions): InitResult;
|
|
60
|
+
export interface UpdateOptions {
|
|
61
|
+
dir: string;
|
|
62
|
+
home?: string;
|
|
63
|
+
scopes?: Scope[];
|
|
64
|
+
dryRun?: boolean;
|
|
65
|
+
}
|
|
66
|
+
export interface UpdateResult extends InitResult {
|
|
67
|
+
/** The install locations found, per scope (absolute paths). */
|
|
68
|
+
found: {
|
|
69
|
+
scope: Scope;
|
|
70
|
+
path: string;
|
|
71
|
+
}[];
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Refresh what an earlier `install` wrote, in each scope where it is found: a skills folder holding
|
|
75
|
+
* leanprompt's stamped skills, an OpenCode commands folder with leanprompt's command, an AGENTS.md with
|
|
76
|
+
* leanprompt's block. Unstamped files are never touched; new files of the same form are added.
|
|
77
|
+
*/
|
|
78
|
+
export declare function update(o: UpdateOptions): UpdateResult;
|