lean-agents 0.0.0-stage → 0.8.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/LICENSE +21 -0
- package/README.es.md +454 -0
- package/README.md +453 -2
- package/core/AGENTS.es.md +60 -0
- package/core/AGENTS.md +60 -0
- package/core/README.md +8 -0
- package/core/agents/debug.md +14 -0
- package/core/agents/explore.md +13 -0
- package/core/agents/planner.md +14 -0
- package/core/agents/research.md +13 -0
- package/core/agents/review.md +13 -0
- package/core/copilot-usage-tui.js +186 -0
- package/core/mcp.json +38 -0
- package/core/pins.json +30 -0
- package/core/tiers.json +4 -0
- package/node_modules/@clack/core/LICENSE +9 -0
- package/node_modules/@clack/core/README.md +22 -0
- package/node_modules/@clack/core/dist/index.d.mts +503 -0
- package/node_modules/@clack/core/dist/index.mjs +1003 -0
- package/node_modules/@clack/core/package.json +63 -0
- package/node_modules/@clack/prompts/LICENSE +9 -0
- package/node_modules/@clack/prompts/README.md +396 -0
- package/node_modules/@clack/prompts/dist/index.d.mts +949 -0
- package/node_modules/@clack/prompts/dist/index.mjs +1423 -0
- package/node_modules/@clack/prompts/package.json +67 -0
- package/node_modules/fast-string-truncated-width/dist/index.d.ts +4 -0
- package/node_modules/fast-string-truncated-width/dist/index.js +111 -0
- package/node_modules/fast-string-truncated-width/dist/types.d.ts +19 -0
- package/node_modules/fast-string-truncated-width/dist/types.js +2 -0
- package/node_modules/fast-string-truncated-width/dist/utils.d.ts +4 -0
- package/node_modules/fast-string-truncated-width/dist/utils.js +20 -0
- package/node_modules/fast-string-truncated-width/license +21 -0
- package/node_modules/fast-string-truncated-width/package.json +35 -0
- package/node_modules/fast-string-truncated-width/readme.md +59 -0
- package/node_modules/fast-string-width/dist/index.d.ts +4 -0
- package/node_modules/fast-string-width/dist/index.js +14 -0
- package/node_modules/fast-string-width/license +21 -0
- package/node_modules/fast-string-width/package.json +34 -0
- package/node_modules/fast-string-width/readme.md +42 -0
- package/node_modules/fast-wrap-ansi/LICENSE +23 -0
- package/node_modules/fast-wrap-ansi/README.md +26 -0
- package/node_modules/fast-wrap-ansi/lib/main.d.ts +6 -0
- package/node_modules/fast-wrap-ansi/lib/main.js +218 -0
- package/node_modules/fast-wrap-ansi/package.json +51 -0
- package/node_modules/jsonc-parser/CHANGELOG.md +76 -0
- package/node_modules/jsonc-parser/LICENSE.md +21 -0
- package/node_modules/jsonc-parser/README.md +364 -0
- package/node_modules/jsonc-parser/SECURITY.md +41 -0
- package/node_modules/jsonc-parser/lib/esm/impl/edit.js +185 -0
- package/node_modules/jsonc-parser/lib/esm/impl/format.js +261 -0
- package/node_modules/jsonc-parser/lib/esm/impl/parser.js +659 -0
- package/node_modules/jsonc-parser/lib/esm/impl/scanner.js +443 -0
- package/node_modules/jsonc-parser/lib/esm/impl/string-intern.js +29 -0
- package/node_modules/jsonc-parser/lib/esm/main.d.ts +351 -0
- package/node_modules/jsonc-parser/lib/esm/main.js +178 -0
- package/node_modules/jsonc-parser/lib/umd/impl/edit.js +201 -0
- package/node_modules/jsonc-parser/lib/umd/impl/format.js +275 -0
- package/node_modules/jsonc-parser/lib/umd/impl/parser.js +682 -0
- package/node_modules/jsonc-parser/lib/umd/impl/scanner.js +456 -0
- package/node_modules/jsonc-parser/lib/umd/impl/string-intern.js +42 -0
- package/node_modules/jsonc-parser/lib/umd/main.d.ts +351 -0
- package/node_modules/jsonc-parser/lib/umd/main.js +194 -0
- package/node_modules/jsonc-parser/package.json +37 -0
- package/node_modules/sisteransi/license +21 -0
- package/node_modules/sisteransi/package.json +34 -0
- package/node_modules/sisteransi/readme.md +113 -0
- package/node_modules/sisteransi/src/index.js +58 -0
- package/node_modules/sisteransi/src/sisteransi.d.ts +35 -0
- package/package.json +29 -4
- package/profiles/README.md +10 -0
- package/profiles/anthropic-api/gsd-defaults.json +26 -0
- package/profiles/anthropic-api.json +18 -0
- package/profiles/antigravity.json +12 -0
- package/profiles/claude-subscription/gsd-defaults.json +26 -0
- package/profiles/claude-subscription.json +17 -0
- package/profiles/github-copilot/gsd-defaults.json +26 -0
- package/profiles/github-copilot.json +17 -0
- package/profiles/openai-api/gsd-defaults.json +26 -0
- package/profiles/openai-api.json +17 -0
- package/profiles/opencode-go/gsd-defaults.json +26 -0
- package/profiles/opencode-go.json +17 -0
- package/profiles/vertex-gemini/gsd-defaults.json +26 -0
- package/profiles/vertex-gemini.json +18 -0
- package/scripts/adhd-skill.mjs +12 -0
- package/scripts/bump-pins.mjs +104 -0
- package/scripts/check-private.sh +52 -0
- package/scripts/check-readme.mjs +131 -0
- package/scripts/ci-download.sh +20 -0
- package/scripts/ci-install-opencode-v2.sh +6 -0
- package/scripts/ci-latest-report.mjs +38 -0
- package/scripts/copilot-context-mode.mjs +33 -0
- package/scripts/labels.sh +55 -0
- package/scripts/lean.mjs +700 -0
- package/scripts/lib/adapters/antigravity.mjs +72 -0
- package/scripts/lib/adapters/claude.mjs +122 -0
- package/scripts/lib/adapters/copilot-cli.mjs +81 -0
- package/scripts/lib/adapters/cursor.mjs +60 -0
- package/scripts/lib/adapters/opencode-v1.mjs +86 -0
- package/scripts/lib/adapters/opencode-v2.mjs +168 -0
- package/scripts/lib/adapters/vscode-copilot.mjs +56 -0
- package/scripts/lib/adhd.mjs +28 -0
- package/scripts/lib/adopt.mjs +474 -0
- package/scripts/lib/agent-lifecycle.mjs +163 -0
- package/scripts/lib/copilot-usage.mjs +49 -0
- package/scripts/lib/doctor.mjs +207 -0
- package/scripts/lib/feedback.mjs +30 -0
- package/scripts/lib/fsops.mjs +291 -0
- package/scripts/lib/gsd.mjs +42 -0
- package/scripts/lib/inventory.mjs +195 -0
- package/scripts/lib/lean-update.mjs +30 -0
- package/scripts/lib/migrate.mjs +407 -0
- package/scripts/lib/network.mjs +79 -0
- package/scripts/lib/node-runtime.mjs +85 -0
- package/scripts/lib/parallel.mjs +265 -0
- package/scripts/lib/pins.mjs +47 -0
- package/scripts/lib/project.mjs +38 -0
- package/scripts/lib/redact.mjs +30 -0
- package/scripts/lib/render.mjs +101 -0
- package/scripts/lib/system.mjs +178 -0
- package/scripts/lib/terminals.mjs +218 -0
- package/scripts/lib/ui.mjs +34 -0
- package/scripts/lib/unverified.mjs +49 -0
- package/scripts/lib/upgrade.mjs +130 -0
- package/scripts/lib/verify-commit.mjs +16 -0
- package/scripts/lib/verify-sha256.mjs +20 -0
- package/scripts/lint-workflows.mjs +25 -0
- package/scripts/models-refresh.mjs +58 -0
- package/scripts/parallel.mjs +59 -0
- package/scripts/pins-latest.mjs +43 -0
- package/scripts/release.mjs +46 -0
- package/scripts/verify-pins.mjs +36 -0
- package/scripts/version-watch.mjs +118 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Refuses a download whose SHA256 differs from the pinned one: `node verify-sha256.mjs <file> <hex>`.
|
|
2
|
+
// A mismatch deletes the file and exits 1, so the install command chain stops before extracting it.
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import crypto from 'node:crypto';
|
|
5
|
+
import { pathToFileURL } from 'node:url';
|
|
6
|
+
|
|
7
|
+
export function sha256(file) {
|
|
8
|
+
return crypto.createHash('sha256').update(fs.readFileSync(file)).digest('hex');
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
|
|
12
|
+
const [file, want] = process.argv.slice(2);
|
|
13
|
+
const got = sha256(file);
|
|
14
|
+
if (got !== want.toLowerCase()) {
|
|
15
|
+
fs.rmSync(file, { force: true });
|
|
16
|
+
console.error(`SHA256 mismatch for ${file}: got ${got}, pinned ${want}. Nothing was installed.`);
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
console.log(`SHA256 ok: ${file}`);
|
|
20
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Fails on a download piped straight into a shell in a workflow or composite action (#75):
|
|
2
|
+
// `curl ... | bash`, `wget ... | sh`, `irm ... | iex`. Download to a file, check its SHA256, then run it (scripts/ci-download.sh).
|
|
3
|
+
// node scripts/lint-workflows.mjs [files...] (default: .github/workflows and .github/actions)
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { pathToFileURL } from 'node:url';
|
|
7
|
+
|
|
8
|
+
const PIPE = /\b(curl|wget|irm|iwr|Invoke-RestMethod|Invoke-WebRequest)\b[^\n]*\|\s*(sudo\s+)?(bash|sh|zsh|iex|Invoke-Expression)\b/i;
|
|
9
|
+
|
|
10
|
+
export function findPipes(text) {
|
|
11
|
+
return text.split('\n').map((l, i) => [i + 1, l]).filter(([, l]) => !l.trim().startsWith('#') && PIPE.test(l)).map(([n, l]) => `${n}: ${l.trim()}`);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function listFiles(dir) {
|
|
15
|
+
if (!fs.existsSync(dir)) return [];
|
|
16
|
+
return fs.readdirSync(dir, { withFileTypes: true, recursive: true }).filter((e) => e.isFile() && /\.ya?ml$/.test(e.name)).map((e) => path.join(e.parentPath, e.name));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (process.argv[1] && pathToFileURL(process.argv[1]).href === import.meta.url) {
|
|
20
|
+
const files = process.argv.length > 2 ? process.argv.slice(2) : [...listFiles('.github/workflows'), ...listFiles('.github/actions')];
|
|
21
|
+
let bad = 0;
|
|
22
|
+
for (const f of files) for (const hit of findPipes(fs.readFileSync(f, 'utf8'))) { console.log(`::error file=${f}::download piped into a shell, line ${hit}`); bad++; }
|
|
23
|
+
console.log(bad ? `${bad} piped download(s)` : 'no piped downloads');
|
|
24
|
+
process.exit(bad ? 1 : 0);
|
|
25
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Compares the model IDs in profiles/ with the public models.dev catalog.
|
|
3
|
+
// Prints a Markdown report. --check exits 1 when a profile uses an ID the catalog lacks.
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
|
|
8
|
+
const ROOT = fileURLToPath(new URL('..', import.meta.url));
|
|
9
|
+
const CATALOG = 'https://models.dev/api.json';
|
|
10
|
+
|
|
11
|
+
// Unknown outputs on either side count as the same, so a catalog gap never hides an upgrade.
|
|
12
|
+
const outputs = (m) => (m.modalities?.output ? JSON.stringify([...m.modalities.output].sort()) : null);
|
|
13
|
+
const sameOutputs = (a, b) => !outputs(a) || !outputs(b) || outputs(a) === outputs(b);
|
|
14
|
+
|
|
15
|
+
// profiles: [{ name, tiers }]. IDs without a provider prefix are aliases and are skipped.
|
|
16
|
+
export function diffModels(profiles, catalog) {
|
|
17
|
+
const missing = [];
|
|
18
|
+
const newer = [];
|
|
19
|
+
for (const { name, tiers } of profiles) {
|
|
20
|
+
const used = new Set(Object.values(tiers).map((t) => t.model));
|
|
21
|
+
for (const { model } of Object.values(tiers)) {
|
|
22
|
+
if (!model.includes('/')) continue;
|
|
23
|
+
const [provider, id] = model.split(/\/(.*)/);
|
|
24
|
+
const models = catalog[provider]?.models ?? {};
|
|
25
|
+
const current = models[id];
|
|
26
|
+
if (!current) {
|
|
27
|
+
missing.push({ profile: name, model });
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
const latest = Object.values(models)
|
|
31
|
+
// A model the profile already uses, or one with other outputs (an image model in a text family), is not an upgrade.
|
|
32
|
+
.filter((m) => m.family === current.family && m.release_date > current.release_date)
|
|
33
|
+
.filter((m) => !used.has(`${provider}/${m.id}`) && sameOutputs(m, current))
|
|
34
|
+
.sort((a, b) => b.release_date.localeCompare(a.release_date))[0];
|
|
35
|
+
if (latest) newer.push({ profile: name, model, latest: `${provider}/${latest.id}` });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return { missing, newer };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function report({ missing, newer }) {
|
|
42
|
+
const lines = ['## Model IDs not in models.dev', ''];
|
|
43
|
+
lines.push(...(missing.length ? missing.map((m) => `- \`${m.profile}\`: \`${m.model}\``) : ['None.']));
|
|
44
|
+
lines.push('', '## Newer models in the same family', '');
|
|
45
|
+
lines.push(...(newer.length ? newer.map((m) => `- \`${m.profile}\`: \`${m.model}\`, newer: \`${m.latest}\``) : ['None.']));
|
|
46
|
+
lines.push('', `Source: ${CATALOG}. Check price and training terms before changing a profile.`);
|
|
47
|
+
return lines.join('\n');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
|
51
|
+
const dir = path.join(ROOT, 'profiles');
|
|
52
|
+
const profiles = fs.readdirSync(dir).filter((f) => f.endsWith('.json')).map((f) => JSON.parse(fs.readFileSync(path.join(dir, f), 'utf8')));
|
|
53
|
+
const res = await fetch(CATALOG);
|
|
54
|
+
if (!res.ok) throw new Error(`${CATALOG}: HTTP ${res.status}`);
|
|
55
|
+
const diff = diffModels(profiles, await res.json());
|
|
56
|
+
console.log(report(diff));
|
|
57
|
+
if (process.argv.includes('--check') && diff.missing.length) process.exitCode = 1;
|
|
58
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Parallel agent sessions helper: start <task.md>…, status, merge <task> --yes, clean.
|
|
3
|
+
// Run it inside the repo whose work you want to split (or pass --repo <dir>).
|
|
4
|
+
import { start, status, merge, clean } from './lib/parallel.mjs';
|
|
5
|
+
|
|
6
|
+
const VALUE_FLAGS = ['repo', 'base', 'agent', 'tier', 'profile', 'model', 'cmd'];
|
|
7
|
+
|
|
8
|
+
function parse(argv) {
|
|
9
|
+
const opts = {};
|
|
10
|
+
const rest = [];
|
|
11
|
+
for (let i = 0; i < argv.length; i++) {
|
|
12
|
+
const m = argv[i].match(/^--(\w+)$/);
|
|
13
|
+
if (!m) rest.push(argv[i]);
|
|
14
|
+
else if (VALUE_FLAGS.includes(m[1])) opts[m[1]] = argv[++i];
|
|
15
|
+
else opts[m[1]] = true;
|
|
16
|
+
}
|
|
17
|
+
return { opts, rest };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const USAGE = `usage: parallel.mjs <command> [options]
|
|
21
|
+
start <task.md>… [--agent auto|orca|claude|opencode|print|custom] [--tier cheap|balanced|strong]
|
|
22
|
+
[--profile <name>] [--model <id>] [--base <branch>] [--cmd <program>]
|
|
23
|
+
status
|
|
24
|
+
merge <task> --yes merge one finished worker (start order), rebase the rest
|
|
25
|
+
clean remove merged worktrees and branches
|
|
26
|
+
--repo <dir> repository to work in (default: current directory)`;
|
|
27
|
+
|
|
28
|
+
const { opts, rest } = parse(process.argv.slice(2));
|
|
29
|
+
const [cmd, ...args] = rest;
|
|
30
|
+
const cwd = opts.repo ?? process.cwd();
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
if (cmd === 'start' && args.length) {
|
|
34
|
+
for (const w of start(cwd, args, opts)) {
|
|
35
|
+
console.log(`${w.name}: ${w.agent}, tier ${w.tier}${w.model ? ` (${w.model})` : ''}, branch ${w.branch}, ${w.dir}`);
|
|
36
|
+
if (w.command) console.log(` run in a new terminal: ${w.command}`);
|
|
37
|
+
}
|
|
38
|
+
} else if (cmd === 'status') {
|
|
39
|
+
const rows = status(cwd);
|
|
40
|
+
if (!rows.length) console.log('no workers');
|
|
41
|
+
for (const w of rows) {
|
|
42
|
+
console.log(`${w.name}\t${w.merged ? 'merged' : w.status}\t${w.agent}\t${w.tier}\t${w.branch}`);
|
|
43
|
+
if (w.tail && !w.merged) console.log(w.tail.replace(/^/gm, ' '));
|
|
44
|
+
}
|
|
45
|
+
} else if (cmd === 'merge' && args.length === 1) {
|
|
46
|
+
if (!opts.yes) { console.log(`dry run: would merge ${args[0]}; ask the user, then add --yes`); process.exit(0); }
|
|
47
|
+
const rebased = merge(cwd, args[0]);
|
|
48
|
+
console.log(`merged ${args[0]}${rebased.length ? `; rebased ${rebased.join(', ')}; rerun their checks` : ''}`);
|
|
49
|
+
} else if (cmd === 'clean') {
|
|
50
|
+
const r = clean(cwd);
|
|
51
|
+
console.log(`removed: ${r.removed.join(', ') || 'none'}${r.kept.length ? `; kept (not merged): ${r.kept.join(', ')}` : ''}`);
|
|
52
|
+
} else {
|
|
53
|
+
console.log(USAGE);
|
|
54
|
+
process.exit(cmd ? 1 : 0);
|
|
55
|
+
}
|
|
56
|
+
} catch (e) {
|
|
57
|
+
console.error(`error: ${e.message}`);
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Rewrites core/pins.json in the current checkout to the newest upstream versions, so the daily CI run tests `latest`.
|
|
3
|
+
// Only the runner's copy changes; nothing is committed. Pins never move backwards. Deliberately no 14-day quarantine: the point is to see a brand-new release break before anyone bumps to it.
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
6
|
+
import { isNewer, latestVersion, tagSha } from './version-watch.mjs';
|
|
7
|
+
|
|
8
|
+
const FILE = fileURLToPath(new URL('../core/pins.json', import.meta.url));
|
|
9
|
+
|
|
10
|
+
// Returns the pins that moved as [{ key, from, to }] and edits `pins` in place.
|
|
11
|
+
export async function bump(pins, get) {
|
|
12
|
+
const moved = [];
|
|
13
|
+
for (const [key, p] of Object.entries(pins)) {
|
|
14
|
+
let next = null;
|
|
15
|
+
if (p.kind === 'download') continue; // Bun: the sha256 map is copied by hand from SHASUMS256.txt
|
|
16
|
+
try {
|
|
17
|
+
next = await latestVersion(p, get);
|
|
18
|
+
if (next && isNewer(p.version, next)) {
|
|
19
|
+
const sha = p.sha ? await tagSha(p.source, next, get) : null;
|
|
20
|
+
const integrity = p.integrity ? (await get(`https://registry.npmjs.org/${p.source.replace('/', '%2F')}/${next}`)).dist.integrity : null;
|
|
21
|
+
moved.push({ key, from: p.version, to: next }); p.version = next;
|
|
22
|
+
if (sha) p.sha = sha;
|
|
23
|
+
if (integrity) p.integrity = integrity;
|
|
24
|
+
}
|
|
25
|
+
} catch (e) { console.log(`! ${key}: ${e.message}`); }
|
|
26
|
+
}
|
|
27
|
+
return moved;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
31
|
+
const { GITHUB_TOKEN } = process.env;
|
|
32
|
+
const get = async (url) => {
|
|
33
|
+
const r = await fetch(url, { headers: { accept: 'application/json', ...(url.includes('api.github.com') && GITHUB_TOKEN ? { authorization: `Bearer ${GITHUB_TOKEN}` } : {}) } });
|
|
34
|
+
if (!r.ok) throw new Error(`${url}: ${r.status}`);
|
|
35
|
+
return r.json();
|
|
36
|
+
};
|
|
37
|
+
const file = JSON.parse(fs.readFileSync(FILE, 'utf8'));
|
|
38
|
+
const moved = await bump(file.pins, get);
|
|
39
|
+
fs.writeFileSync(FILE, `${JSON.stringify(file, null, 2)}\n`);
|
|
40
|
+
const lines = moved.length ? moved.map((m) => `- ${m.key}: ${m.from} -> ${m.to}`) : ['- no pin has a newer version'];
|
|
41
|
+
console.log(lines.join('\n'));
|
|
42
|
+
if (process.env.GITHUB_STEP_SUMMARY) fs.appendFileSync(process.env.GITHUB_STEP_SUMMARY, `### Latest versions under test\n${lines.join('\n')}\n`);
|
|
43
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Builds dist/notes.md, the source archives, the npm tarball and SHA256SUMS for a release. Used by release.yml and CI.
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { execFileSync } from 'node:child_process';
|
|
6
|
+
import crypto from 'node:crypto';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
8
|
+
|
|
9
|
+
const ROOT = fileURLToPath(new URL('..', import.meta.url));
|
|
10
|
+
|
|
11
|
+
export function releaseNotes(changelog, version) {
|
|
12
|
+
const lines = changelog.split('\n');
|
|
13
|
+
const start = lines.findIndex((l) => l.startsWith(`## [${version}]`));
|
|
14
|
+
if (start < 0) return '';
|
|
15
|
+
const rest = lines.slice(start + 1);
|
|
16
|
+
const end = rest.findIndex((l) => l.startsWith('## ['));
|
|
17
|
+
return rest.slice(0, end < 0 ? undefined : end).join('\n').trim();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Needs `npm ci --omit=dev` first: the tarball bundles node_modules.
|
|
21
|
+
export function packDist(dist, version) {
|
|
22
|
+
const name = `lean-agents-${version}`;
|
|
23
|
+
execFileSync('npm', ['pack', '--pack-destination', dist, '--silent'], { cwd: ROOT });
|
|
24
|
+
for (const f of ['install.sh', 'install.ps1']) fs.copyFileSync(path.join(ROOT, f), path.join(dist, f));
|
|
25
|
+
const files = [`${name}.tgz`, `${name}.tar.gz`, `${name}.zip`, 'install.sh', 'install.ps1'];
|
|
26
|
+
const sums = files.map((f) => `${crypto.createHash('sha256').update(fs.readFileSync(path.join(dist, f))).digest('hex')} ${f}\n`);
|
|
27
|
+
fs.writeFileSync(path.join(dist, 'SHA256SUMS'), sums.join(''));
|
|
28
|
+
return files;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
|
32
|
+
const version = process.argv[2];
|
|
33
|
+
const current = JSON.parse(fs.readFileSync(path.join(ROOT, 'package.json'), 'utf8')).version;
|
|
34
|
+
if (version !== current) throw new Error(`version ${version} does not match package.json ${current}`);
|
|
35
|
+
const notes = releaseNotes(fs.readFileSync(path.join(ROOT, 'CHANGELOG.md'), 'utf8'), version);
|
|
36
|
+
if (!notes) throw new Error(`CHANGELOG.md has no notes for ${version}`);
|
|
37
|
+
const dist = path.join(ROOT, 'dist');
|
|
38
|
+
fs.mkdirSync(dist, { recursive: true });
|
|
39
|
+
fs.writeFileSync(path.join(dist, 'notes.md'), `${notes}\n`);
|
|
40
|
+
const name = `lean-agents-${version}`;
|
|
41
|
+
for (const ext of ['tar.gz', 'zip']) {
|
|
42
|
+
execFileSync('git', ['archive', '--format', ext, '--prefix', `${name}/`, '-o', path.join(dist, `${name}.${ext}`), 'HEAD'], { cwd: ROOT });
|
|
43
|
+
}
|
|
44
|
+
const packed = packDist(dist, version);
|
|
45
|
+
console.log(`dist: notes.md, SHA256SUMS, ${packed.join(', ')}`);
|
|
46
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Checks core/pins.json against the real upstream: npm `dist.integrity` and the commit a tag points at.
|
|
2
|
+
// A mismatch means the registry or the tag changed after the pin was recorded (a republish or a moved tag).
|
|
3
|
+
// node scripts/verify-pins.mjs (GITHUB_TOKEN raises the GitHub API rate limit)
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
6
|
+
import { tagSha } from './version-watch.mjs';
|
|
7
|
+
|
|
8
|
+
const FILE = fileURLToPath(new URL('../core/pins.json', import.meta.url));
|
|
9
|
+
|
|
10
|
+
// Returns one message per pin whose recorded integrity or sha differs from upstream.
|
|
11
|
+
export async function verify(pins, get) {
|
|
12
|
+
const bad = [];
|
|
13
|
+
for (const [key, p] of Object.entries(pins)) {
|
|
14
|
+
try {
|
|
15
|
+
if (p.integrity) {
|
|
16
|
+
const meta = await get(`https://registry.npmjs.org/${p.source.replace('/', '%2F')}/${p.version}`);
|
|
17
|
+
if (meta.dist.integrity !== p.integrity) bad.push(`${key}: integrity ${meta.dist.integrity} != pinned ${p.integrity}`);
|
|
18
|
+
if (meta.engines?.node !== p.node) bad.push(`${key}: engines.node ${meta.engines?.node} != pinned ${p.node}`);
|
|
19
|
+
}
|
|
20
|
+
if (p.sha) {
|
|
21
|
+
const got = await tagSha(p.source, p.version, get);
|
|
22
|
+
if (got !== p.sha) bad.push(`${key}: ${p.version} is ${got}, pinned ${p.sha}`);
|
|
23
|
+
}
|
|
24
|
+
} catch (e) { bad.push(`${key}: ${e.message}`); }
|
|
25
|
+
}
|
|
26
|
+
return bad;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
|
|
30
|
+
const headers = { 'User-Agent': 'lean-agents', ...(process.env.GITHUB_TOKEN ? { Authorization: `Bearer ${process.env.GITHUB_TOKEN}` } : {}) };
|
|
31
|
+
const get = async (url) => { const r = await fetch(url, { headers }); if (!r.ok) throw new Error(`${url}: HTTP ${r.status}`); return r.json(); };
|
|
32
|
+
const bad = await verify(JSON.parse(fs.readFileSync(FILE, 'utf8')).pins, get);
|
|
33
|
+
for (const m of bad) console.log(`! ${m}`);
|
|
34
|
+
console.log(bad.length ? `${bad.length} pin(s) do not match upstream` : 'every pin matches upstream');
|
|
35
|
+
process.exit(bad.length ? 1 : 0);
|
|
36
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Daily check of core/pins.json against npm and GitHub tags. Opens one `version-watch` issue per item with a newer
|
|
3
|
+
// version, or comments on the open one. Read-only for the repo: it never changes a pin.
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
6
|
+
|
|
7
|
+
const ROOT = fileURLToPath(new URL('..', import.meta.url));
|
|
8
|
+
const LABEL = 'version-watch';
|
|
9
|
+
const STABLE = /^v?\d+\.\d+\.\d+$/;
|
|
10
|
+
const mark = (v) => `<!-- version-watch:${v} -->`;
|
|
11
|
+
const parts = (v) => v.replace(/^v/, '').split('.').map(Number);
|
|
12
|
+
|
|
13
|
+
// True when `next` is a higher stable x.y.z than `current`.
|
|
14
|
+
export function isNewer(current, next) {
|
|
15
|
+
if (!STABLE.test(next)) return false;
|
|
16
|
+
const [a, b] = [parts(current), parts(next)];
|
|
17
|
+
for (let i = 0; i < 3; i++) if (a[i] !== b[i]) return b[i] > a[i];
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function notesUrl(p, version) {
|
|
22
|
+
return p.kind === 'npm' ? `https://www.npmjs.com/package/${p.source}/v/${version}` : `https://github.com/${p.source}/releases/tag/${version}`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function render(key, p, version) {
|
|
26
|
+
return [
|
|
27
|
+
`Confirmed to work: \`${p.version}\` (verified ${p.verified}).`,
|
|
28
|
+
`New upstream version: \`${version}\`.`,
|
|
29
|
+
`Release notes: ${notesUrl(p, version)}`,
|
|
30
|
+
'Do not bump to a version published in the last 14 days.',
|
|
31
|
+
...(p.note ? [`Note: ${p.note}`] : []),
|
|
32
|
+
`Run before bumping: the \`${p.ci}\` job (or its \`tests/real-*.sh\` script in a sandbox HOME).`,
|
|
33
|
+
'This watch never changes pins. To bump, follow "Tool versions" in `skills/update-models/SKILL.md` and edit `core/pins.json` after the owner approves.',
|
|
34
|
+
mark(version),
|
|
35
|
+
].join('\n\n');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// pins: core/pins.json "pins"; latest: { key: version|null }; issues: every version-watch issue, open or closed:
|
|
39
|
+
// [{ number, title, state, body, comments: [string] }]. A closed issue still counts as "already reported".
|
|
40
|
+
export function plan(pins, latest, issues) {
|
|
41
|
+
const actions = [];
|
|
42
|
+
for (const [key, p] of Object.entries(pins)) {
|
|
43
|
+
const version = latest[key];
|
|
44
|
+
if (!version || !isNewer(p.version, version)) continue;
|
|
45
|
+
const title = `Update available: ${key}`;
|
|
46
|
+
const same = issues.filter((i) => i.title === title);
|
|
47
|
+
if (same.some((i) => [i.body, ...i.comments].some((t) => t?.includes(mark(version))))) continue;
|
|
48
|
+
const issue = same.find((i) => i.state === 'open');
|
|
49
|
+
const body = render(key, p, version);
|
|
50
|
+
if (!issue) actions.push({ type: 'create', key, title, body });
|
|
51
|
+
else actions.push({ type: 'comment', key, number: issue.number, body });
|
|
52
|
+
}
|
|
53
|
+
return actions;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export async function latestVersion(p, get) {
|
|
57
|
+
if (p.kind === 'npm') return (await get(`https://registry.npmjs.org/${p.source.replace('/', '%2F')}/latest`)).version;
|
|
58
|
+
// shortcut: first 100 tags only, enough for repos that tag per release; page if a repo outgrows that.
|
|
59
|
+
const tags = (await get(`https://api.github.com/repos/${p.source}/tags?per_page=100`)).map((t) => t.name).filter((n) => STABLE.test(n));
|
|
60
|
+
return tags.reduce((best, n) => (!best || isNewer(best, n) ? n : best), null);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Commit SHA a GitHub tag points at (annotated tags are dereferenced).
|
|
64
|
+
export async function tagSha(source, tag, get) {
|
|
65
|
+
const ref = (await get(`https://api.github.com/repos/${source}/git/ref/tags/${tag}`)).object;
|
|
66
|
+
return ref.type === 'tag' ? (await get(`https://api.github.com/repos/${source}/git/tags/${ref.sha}`)).object.sha : ref.sha;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// api: { list(), comments(number), create(title, body), comment(number, body) }
|
|
70
|
+
export async function run({ pins, get, api, log = console.log }) {
|
|
71
|
+
const latest = {};
|
|
72
|
+
for (const [key, p] of Object.entries(pins)) {
|
|
73
|
+
try { latest[key] = await latestVersion(p, get); } catch (e) { log(`! ${key}: ${e.message}`); }
|
|
74
|
+
}
|
|
75
|
+
const issues = await api.list();
|
|
76
|
+
for (const i of issues) i.comments = await api.comments(i.number);
|
|
77
|
+
const actions = plan(pins, latest, issues);
|
|
78
|
+
for (const a of actions) {
|
|
79
|
+
if (a.type === 'create') await api.create(a.title, a.body);
|
|
80
|
+
else await api.comment(a.number, a.body);
|
|
81
|
+
log(`${a.type}: ${a.key}`);
|
|
82
|
+
}
|
|
83
|
+
if (!actions.length) log('nothing new');
|
|
84
|
+
return actions;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function githubApi(repo, token) {
|
|
88
|
+
const call = async (method, url, body) => {
|
|
89
|
+
const r = await fetch(`https://api.github.com/repos/${repo}${url}`, {
|
|
90
|
+
method,
|
|
91
|
+
headers: { authorization: `Bearer ${token}`, accept: 'application/vnd.github+json', 'content-type': 'application/json' },
|
|
92
|
+
body: body && JSON.stringify(body),
|
|
93
|
+
});
|
|
94
|
+
if (!r.ok && !(method === 'POST' && url === '/labels' && r.status === 422)) throw new Error(`${method} ${url}: ${r.status}`);
|
|
95
|
+
return r.status === 204 ? null : r.json();
|
|
96
|
+
};
|
|
97
|
+
return {
|
|
98
|
+
async list() {
|
|
99
|
+
await call('POST', '/labels', { name: LABEL, color: 'ededed' });
|
|
100
|
+
return call('GET', `/issues?labels=${LABEL}&state=all&per_page=100`);
|
|
101
|
+
},
|
|
102
|
+
async comments(number) { return (await call('GET', `/issues/${number}/comments?per_page=100`)).map((c) => c.body); },
|
|
103
|
+
create: (title, body) => call('POST', '/issues', { title, body, labels: [LABEL, 'type: update'] }),
|
|
104
|
+
comment: (number, body) => call('POST', `/issues/${number}/comments`, { body }),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
109
|
+
const { GITHUB_TOKEN, GITHUB_REPOSITORY } = process.env;
|
|
110
|
+
if (!GITHUB_TOKEN || !GITHUB_REPOSITORY) { console.error('needs GITHUB_TOKEN and GITHUB_REPOSITORY'); process.exit(1); }
|
|
111
|
+
const pins = JSON.parse(fs.readFileSync(`${ROOT}core/pins.json`, 'utf8')).pins;
|
|
112
|
+
const get = async (url) => {
|
|
113
|
+
const r = await fetch(url, { headers: { accept: 'application/json', authorization: url.includes('api.github.com') ? `Bearer ${GITHUB_TOKEN}` : '' } });
|
|
114
|
+
if (!r.ok) throw new Error(`${url}: ${r.status}`);
|
|
115
|
+
return r.json();
|
|
116
|
+
};
|
|
117
|
+
await run({ pins, get, api: githubApi(GITHUB_REPOSITORY, GITHUB_TOKEN) });
|
|
118
|
+
}
|