lean-agents 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +407 -0
- package/LICENSE +21 -0
- package/README.es.md +560 -0
- package/README.md +559 -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 +189 -0
- package/core/mcp.json +38 -0
- package/core/pins.json +39 -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 +30 -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/behavior-diff.sh +47 -0
- package/scripts/bump-pins.mjs +115 -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/ci-timing.mjs +61 -0
- package/scripts/copilot-context-mode.mjs +33 -0
- package/scripts/labels.sh +56 -0
- package/scripts/lean.mjs +1319 -0
- package/scripts/lib/adapters/antigravity.mjs +83 -0
- package/scripts/lib/adapters/claude.mjs +127 -0
- package/scripts/lib/adapters/copilot-cli.mjs +82 -0
- package/scripts/lib/adapters/cursor.mjs +60 -0
- package/scripts/lib/adapters/opencode-v1.mjs +79 -0
- package/scripts/lib/adapters/opencode-v2.mjs +216 -0
- package/scripts/lib/adapters/vscode-copilot.mjs +56 -0
- package/scripts/lib/adhd.mjs +28 -0
- package/scripts/lib/adopt.mjs +619 -0
- package/scripts/lib/agent-lifecycle.mjs +280 -0
- package/scripts/lib/backup-stamp.mjs +25 -0
- package/scripts/lib/copilot-usage.mjs +49 -0
- package/scripts/lib/doctor.mjs +279 -0
- package/scripts/lib/feedback.mjs +48 -0
- package/scripts/lib/fsops.mjs +319 -0
- package/scripts/lib/gsd.mjs +42 -0
- package/scripts/lib/inventory.mjs +196 -0
- package/scripts/lib/lean-update.mjs +30 -0
- package/scripts/lib/logins.mjs +28 -0
- package/scripts/lib/migrate.mjs +407 -0
- package/scripts/lib/network.mjs +119 -0
- package/scripts/lib/node-runtime.mjs +85 -0
- package/scripts/lib/opencode-backup.mjs +204 -0
- package/scripts/lib/opencode-upgrade.mjs +441 -0
- package/scripts/lib/opencode1.mjs +203 -0
- package/scripts/lib/parallel.mjs +270 -0
- package/scripts/lib/pins-diff.mjs +33 -0
- package/scripts/lib/pins.mjs +52 -0
- package/scripts/lib/plugin-health.mjs +191 -0
- package/scripts/lib/prereqs.mjs +203 -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/shell-path.mjs +22 -0
- package/scripts/lib/summary-data.mjs +30 -0
- package/scripts/lib/summary-html.mjs +159 -0
- package/scripts/lib/system.mjs +269 -0
- package/scripts/lib/terminals.mjs +316 -0
- package/scripts/lib/ui.mjs +34 -0
- package/scripts/lib/unverified.mjs +49 -0
- package/scripts/lib/update-plan.mjs +60 -0
- package/scripts/lib/upgrade.mjs +231 -0
- package/scripts/lib/verify-commit.mjs +16 -0
- package/scripts/lib/verify-prompt.mjs +46 -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 +66 -0
- package/scripts/release.mjs +71 -0
- package/scripts/verify-pins.mjs +36 -0
- package/scripts/version-watch.mjs +124 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
// The finish-step summary page (#181): one self-contained HTML file, inline CSS and JS, no network and no external reference.
|
|
2
|
+
// Pure: renders the buildSummary() model; lean.mjs writes it as an owned file and asks before opening it.
|
|
3
|
+
import { redactText } from './redact.mjs';
|
|
4
|
+
import { verifyPrompt } from './verify-prompt.mjs';
|
|
5
|
+
import { feedbackAllowed } from './feedback.mjs';
|
|
6
|
+
|
|
7
|
+
const MAX_ITEMS = 5;
|
|
8
|
+
const RUN = 'npx -y lean-agents@latest';
|
|
9
|
+
const ISSUE_URL = /^https:\/\/github\.com\/[\w.-]+\/[\w.-]+\/issues\/\d+$/;
|
|
10
|
+
|
|
11
|
+
const TEXT = {
|
|
12
|
+
en: {
|
|
13
|
+
title: 'lean-agents install',
|
|
14
|
+
action: 'Action needed',
|
|
15
|
+
login: 'Log in to each tool:',
|
|
16
|
+
state: { ok: 'done', needed: 'needed', unknown: 'not checked' },
|
|
17
|
+
fileOn: 'Then paste this prompt into your agent. It checks the install, fixes what fits the plan after your yes, and files an issue only after your yes.',
|
|
18
|
+
fileOff: 'Then paste this prompt into your agent. It checks the install and fixes what fits the plan after your yes. Nothing is filed.',
|
|
19
|
+
copy: 'Copy prompt', copied: 'Copied', show: 'Show prompt',
|
|
20
|
+
summary: 'Summary',
|
|
21
|
+
installed: (n) => `Installed: ${n} items`,
|
|
22
|
+
kept: 'Kept', updated: 'Updated', skipped: 'Skipped', errors: 'Errors', filed: 'Filed issues', none: 'none',
|
|
23
|
+
more: (n) => `+${n} more`,
|
|
24
|
+
doctorOk: 'Doctor: all checks ok',
|
|
25
|
+
doctorBad: (n) => `Doctor: ${n} to fix`,
|
|
26
|
+
next: 'Next steps',
|
|
27
|
+
steps: ['Restart your agents.', 'Log in to each tool above.', 'Paste the prompt.'],
|
|
28
|
+
how: 'How to use',
|
|
29
|
+
howIntro: `Your agent now has shared rules, cheap subagents and your tools. Run with \`${RUN}\`:`,
|
|
30
|
+
cmds: [['--doctor', 'check the install'], ['--summary', 'rebuild this page'], ['--update', 'update pinned tools'], ['--uninstall', 'undo everything']],
|
|
31
|
+
updates: 'Updates',
|
|
32
|
+
updatesText: 'Auto-update is off for every pinned tool, so versions stay the ones CI tested. A daily CI run checks newer versions and each release lists the changes. Update when you want with `--update`.',
|
|
33
|
+
},
|
|
34
|
+
es: {
|
|
35
|
+
title: 'Instalación de lean-agents',
|
|
36
|
+
action: 'Acción necesaria',
|
|
37
|
+
login: 'Inicia sesión en cada herramienta:',
|
|
38
|
+
state: { ok: 'hecho', needed: 'falta', unknown: 'sin comprobar' },
|
|
39
|
+
fileOn: 'Luego pega este prompt en tu agente. Revisa la instalación, arregla lo que cabe en el plan si dices sí, y crea un issue solo si dices sí.',
|
|
40
|
+
fileOff: 'Luego pega este prompt en tu agente. Revisa la instalación y arregla lo que cabe en el plan si dices sí. No crea nada.',
|
|
41
|
+
copy: 'Copiar prompt', copied: 'Copiado', show: 'Ver prompt',
|
|
42
|
+
summary: 'Resumen',
|
|
43
|
+
installed: (n) => `Instalado: ${n} elementos`,
|
|
44
|
+
kept: 'Conservado', updated: 'Actualizado', skipped: 'Omitido', errors: 'Errores', filed: 'Issues creados', none: 'nada',
|
|
45
|
+
more: (n) => `+${n} más`,
|
|
46
|
+
doctorOk: 'Doctor: todo ok',
|
|
47
|
+
doctorBad: (n) => `Doctor: ${n} por arreglar`,
|
|
48
|
+
next: 'Próximos pasos',
|
|
49
|
+
steps: ['Reinicia tus agentes.', 'Inicia sesión en cada herramienta.', 'Pega el prompt.'],
|
|
50
|
+
how: 'Cómo usarlo',
|
|
51
|
+
howIntro: `Tu agente ya tiene reglas compartidas, subagentes baratos y tus herramientas. Ejecuta con \`${RUN}\`:`,
|
|
52
|
+
cmds: [['--doctor', 'revisa la instalación'], ['--summary', 'rehace esta página'], ['--update', 'actualiza lo fijado'], ['--uninstall', 'deshace todo']],
|
|
53
|
+
updates: 'Actualizaciones',
|
|
54
|
+
updatesText: 'La actualización automática está apagada en cada herramienta fijada, así las versiones son las que probó CI. Un CI diario revisa versiones nuevas y cada release lista los cambios. Actualiza cuando quieras con `--update`.',
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const CSS = `:root{color-scheme:light dark;--bg:#fff;--fg:#1a1a1a;--muted:#555;--line:#c9c9c9;--code:#f1f1f1;--red-bg:#fdecea;--red-line:#b3261e;--red-fg:#7a1510;--btn:#0b57d0;--btn-fg:#fff}
|
|
59
|
+
@media(prefers-color-scheme:dark){:root{--bg:#161616;--fg:#eee;--muted:#b0b0b0;--line:#444;--code:#262626;--red-bg:#3a1512;--red-line:#f2b8b5;--red-fg:#ffdad6;--btn:#a8c7fa;--btn-fg:#062e6f}}
|
|
60
|
+
body{margin:0;padding:1rem;background:var(--bg);color:var(--fg);font:16px/1.5 system-ui,sans-serif}
|
|
61
|
+
main{max-width:46rem;margin:0 auto}
|
|
62
|
+
h1{font-size:1.4rem}h2{font-size:1.15rem;margin:0 0 .5rem}
|
|
63
|
+
section{border:1px solid var(--line);border-radius:8px;padding:.75rem 1rem;margin:1rem 0}
|
|
64
|
+
section.action{background:var(--red-bg);border:2px solid var(--red-line);color:var(--red-fg)}
|
|
65
|
+
code,pre{background:var(--code);color:var(--fg);border-radius:4px;font:.9em ui-monospace,monospace}
|
|
66
|
+
code{padding:.1em .3em}pre{padding:.75rem;overflow-x:auto;white-space:pre-wrap}
|
|
67
|
+
ul{padding-left:1.25rem;margin:.25rem 0}
|
|
68
|
+
button{min-height:2.75rem;padding:0 1rem;border:0;border-radius:6px;background:var(--btn);color:var(--btn-fg);font:inherit;cursor:pointer}
|
|
69
|
+
button:focus-visible,summary:focus-visible,a:focus-visible{outline:3px solid var(--fg);outline-offset:2px}
|
|
70
|
+
.state{font-weight:600}`;
|
|
71
|
+
|
|
72
|
+
// The copy button: the Clipboard API on a secure page, a selection copy on file://.
|
|
73
|
+
const JS = `(function(){var b=document.getElementById('copy'),p=document.getElementById('prompt'),s=document.getElementById('copied');
|
|
74
|
+
if(!b||!p)return;b.addEventListener('click',function(){var t=p.textContent;
|
|
75
|
+
function done(){s.textContent=b.getAttribute('data-done')}
|
|
76
|
+
if(navigator.clipboard&&navigator.clipboard.writeText){navigator.clipboard.writeText(t).then(done,fallback)}else{fallback()}
|
|
77
|
+
function fallback(){var r=document.createRange();r.selectNodeContents(p);var g=window.getSelection();g.removeAllRanges();g.addRange(r);try{if(document.execCommand('copy'))done()}catch(e){}}})})();`;
|
|
78
|
+
|
|
79
|
+
const esc = (v) => String(v).replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[c]);
|
|
80
|
+
// `code` spans in the strings above become <code>.
|
|
81
|
+
const md = (s) => esc(s).replace(/`([^`]+)`/g, '<code>$1</code>');
|
|
82
|
+
|
|
83
|
+
// `model` is buildSummary()'s result; `filed` is state.filedIssues; `network` decides whether the prompt may file issues.
|
|
84
|
+
export function renderSummary({ model, filed = [], network, home, env } = {}) {
|
|
85
|
+
const lang = TEXT[model.lang] ? model.lang : 'en';
|
|
86
|
+
const x = TEXT[lang];
|
|
87
|
+
const t = (v) => esc(redactText(v, { home, env }));
|
|
88
|
+
const allowFile = feedbackAllowed(network);
|
|
89
|
+
const prompt = redactText(verifyPrompt({ lang, network }), { home, env });
|
|
90
|
+
const { summary } = model;
|
|
91
|
+
const list = (items) => {
|
|
92
|
+
if (!items.length) return x.none;
|
|
93
|
+
const shown = items.slice(0, MAX_ITEMS).map(t).join(', ');
|
|
94
|
+
return items.length > MAX_ITEMS ? `${shown} ${x.more(items.length - MAX_ITEMS)}` : shown;
|
|
95
|
+
};
|
|
96
|
+
const rows = [`<li>${esc(x.installed(summary.installed.length))}</li>`];
|
|
97
|
+
for (const k of ['kept', 'updated', 'skipped']) rows.push(`<li>${esc(x[k])}: ${list(summary[k])}</li>`);
|
|
98
|
+
if (summary.errors.length) rows.push(`<li>${esc(x.errors)}: ${list(summary.errors)}</li>`);
|
|
99
|
+
const d = summary.doctor;
|
|
100
|
+
rows.push(`<li>${esc(d.ok ? x.doctorOk : x.doctorBad(d.problems.length))}</li>`);
|
|
101
|
+
for (const p of d.problems.slice(0, MAX_ITEMS)) rows.push(`<li><code>${t(p.item)}</code>: ${t(p.status)} ${t(p.detail)}</li>`);
|
|
102
|
+
const links = filed.filter((f) => ISSUE_URL.test(f.url));
|
|
103
|
+
if (links.length) rows.push(`<li>${esc(x.filed)}: ${links.map((f) => `<a href="${esc(f.url)}">${t(f.item)}</a>`).join(', ')}</li>`);
|
|
104
|
+
const logins = model.action.logins
|
|
105
|
+
.map((l) => `<li><code>${t(l.command)}</code> (${t(l.tool)}) <span class="state">${esc(x.state[l.state] ?? x.state.unknown)}</span></li>`)
|
|
106
|
+
.join('');
|
|
107
|
+
return `<!doctype html>
|
|
108
|
+
<!-- managed by lean-agents: rewritten by --summary, removed by --uninstall -->
|
|
109
|
+
<html lang="${lang}">
|
|
110
|
+
<head>
|
|
111
|
+
<meta charset="utf-8">
|
|
112
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
113
|
+
<meta name="color-scheme" content="light dark">
|
|
114
|
+
<title>${esc(x.title)}</title>
|
|
115
|
+
<style>${CSS}</style>
|
|
116
|
+
</head>
|
|
117
|
+
<body>
|
|
118
|
+
<main>
|
|
119
|
+
<h1>${esc(x.title)} ${t(model.version)}</h1>
|
|
120
|
+
<section class="action" aria-labelledby="h-action">
|
|
121
|
+
<h2 id="h-action">${esc(x.action)}</h2>
|
|
122
|
+
<p>${esc(x.login)}</p>
|
|
123
|
+
<ul>${logins}</ul>
|
|
124
|
+
<p>${esc(allowFile ? x.fileOn : x.fileOff)}</p>
|
|
125
|
+
<p><button type="button" id="copy" data-done="${esc(x.copied)}">${esc(x.copy)}</button> <span id="copied" role="status" aria-live="polite"></span></p>
|
|
126
|
+
<details><summary>${esc(x.show)}</summary><pre id="prompt">${esc(prompt)}</pre></details>
|
|
127
|
+
</section>
|
|
128
|
+
<section aria-labelledby="h-summary">
|
|
129
|
+
<h2 id="h-summary">${esc(x.summary)}</h2>
|
|
130
|
+
<ul>${rows.join('')}</ul>
|
|
131
|
+
</section>
|
|
132
|
+
<section aria-labelledby="h-next">
|
|
133
|
+
<h2 id="h-next">${esc(x.next)}</h2>
|
|
134
|
+
<ol>${x.steps.map((s) => `<li>${esc(s)}</li>`).join('')}</ol>
|
|
135
|
+
</section>
|
|
136
|
+
<section aria-labelledby="h-how">
|
|
137
|
+
<h2 id="h-how">${esc(x.how)}</h2>
|
|
138
|
+
<p>${md(x.howIntro)}</p>
|
|
139
|
+
<ul>${x.cmds.map(([c, d]) => `<li><code>${esc(c)}</code> ${esc(d)}</li>`).join('')}</ul>
|
|
140
|
+
</section>
|
|
141
|
+
<section aria-labelledby="h-updates">
|
|
142
|
+
<h2 id="h-updates">${esc(x.updates)}</h2>
|
|
143
|
+
<p>${md(x.updatesText)}</p>
|
|
144
|
+
</section>
|
|
145
|
+
</main>
|
|
146
|
+
<script>${JS}</script>
|
|
147
|
+
</body>
|
|
148
|
+
</html>
|
|
149
|
+
`;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Opening the page is a question, never a default: not under CI, --no-open, --yes or --json, and not without a terminal.
|
|
153
|
+
export const canOffer = ({ noOpen, yes, json, env = process.env, tty }) => !noOpen && !yes && !json && !env.CI && !!tty;
|
|
154
|
+
|
|
155
|
+
export function openArgv(platform, file) {
|
|
156
|
+
if (platform === 'darwin') return ['open', file];
|
|
157
|
+
if (platform === 'win32') return ['cmd', '/c', 'start', '', file];
|
|
158
|
+
return ['xdg-open', file];
|
|
159
|
+
}
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
// Detection of agents and prerequisites, and running external commands.
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
import { npmSpec, bunPin, rtkPin } from './pins.mjs';
|
|
8
|
+
import { allowedEnv } from './network.mjs';
|
|
9
|
+
|
|
10
|
+
const isWin = process.platform === 'win32';
|
|
11
|
+
|
|
12
|
+
export function which(bin) {
|
|
13
|
+
const r = spawnSync(isWin ? 'where' : 'command', isWin ? [bin] : ['-v', bin], { shell: !isWin, encoding: 'utf8' });
|
|
14
|
+
return r.status === 0 ? r.stdout.trim().split(/\r?\n/)[0] : null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Windows .cmd shims (npm, npx) need a shell; real .exe files must not get one, or paths with spaces split.
|
|
18
|
+
const useShell = (bin) => isWin && !/\.exe$/i.test(bin) && !/\.exe$/i.test(which(bin) ?? '');
|
|
19
|
+
|
|
20
|
+
// The version string as the binary prints it, pre-release tag included (2.0.1-beta): what an undo must reinstall.
|
|
21
|
+
export function versionFull(bin, args = ['--version'], env = {}) {
|
|
22
|
+
if (!path.isAbsolute(bin) && !which(bin)) return null;
|
|
23
|
+
const r = spawnSync(bin, args, { encoding: 'utf8', shell: useShell(bin), timeout: 20000, env: { ...allowedEnv(), ...env } });
|
|
24
|
+
const m = `${r.stdout}${r.stderr}`.match(/\d+\.\d+\.\d+(?:-[0-9A-Za-z][0-9A-Za-z.-]*)?/);
|
|
25
|
+
return m ? m[0] : 'unknown';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const version = (bin, args, env) => versionFull(bin, args, env)?.replace(/-.*/, '') ?? null;
|
|
29
|
+
|
|
30
|
+
// A config dir from the environment counts only for the real home or inside --home:
|
|
31
|
+
// a run with --home must never write outside it, even when the variable is set.
|
|
32
|
+
export function envDir(home, name, fallback) {
|
|
33
|
+
const value = process.env[name];
|
|
34
|
+
if (!value || !path.isAbsolute(value)) return fallback;
|
|
35
|
+
const rel = path.relative(home, value);
|
|
36
|
+
const inside = !rel.startsWith('..') && !path.isAbsolute(rel);
|
|
37
|
+
return home === os.homedir() || inside ? value : fallback;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const configHome = (home) => envDir(home, 'XDG_CONFIG_HOME', path.join(home, '.config'));
|
|
41
|
+
|
|
42
|
+
// External tools read HOME, not --home, so a run with --home hands it down to every child.
|
|
43
|
+
export function isolate(home) {
|
|
44
|
+
if (home === os.homedir()) return;
|
|
45
|
+
const env = { XDG_CONFIG_HOME: configHome(home), COPILOT_HOME: envDir(home, 'COPILOT_HOME', path.join(home, '.copilot')) };
|
|
46
|
+
for (const name of ['XDG_CACHE_HOME', 'XDG_DATA_HOME', 'XDG_STATE_HOME']) {
|
|
47
|
+
if (!envDir(home, name, null)) delete process.env[name];
|
|
48
|
+
}
|
|
49
|
+
Object.assign(process.env, env, { HOME: home, USERPROFILE: home });
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Where `agy` lives when it is not on PATH. install.sh: $HOME/.local/bin (--dir changes it, unknowable here);
|
|
53
|
+
// install.ps1: %LOCALAPPDATA%\agy\bin; ~/.gemini/bin/agy.exe was seen on Windows in #211 (who writes it: VERIFY).
|
|
54
|
+
export function agyCandidates(home, platform = process.platform, env = process.env) {
|
|
55
|
+
if (platform !== 'win32') return [path.posix.join(home, '.local', 'bin', 'agy')];
|
|
56
|
+
return [env.LOCALAPPDATA && path.win32.join(env.LOCALAPPDATA, 'agy', 'bin', 'agy.exe'), path.win32.join(home, '.gemini', 'bin', 'agy.exe')].filter(Boolean);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// PATH first, then the candidates above. Returns a command that can be spawned, or null.
|
|
60
|
+
export function findAgy(home, platform = process.platform, env = process.env) {
|
|
61
|
+
return which('agy') ? 'agy' : agyCandidates(home, platform, env).find(exists) ?? null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Antigravity IDE folders and the VS Code extension, by existence only (#216): nothing is read or written.
|
|
65
|
+
// The extension folder name is lowercase on disk (`google.google-antigravity-<version>`); Windows and Linux paths are VERIFY.
|
|
66
|
+
export function antigravityFootprint(home, fsx = fs) {
|
|
67
|
+
const found = [];
|
|
68
|
+
for (const d of ['antigravity-ide', 'antigravity-cli', 'antigravity']) {
|
|
69
|
+
const p = path.join(home, '.gemini', d);
|
|
70
|
+
if (fsx.existsSync(p)) found.push({ name: d === 'antigravity' ? 'antigravity (legacy)' : d, file: p });
|
|
71
|
+
}
|
|
72
|
+
const ext = path.join(home, '.vscode', 'extensions');
|
|
73
|
+
let names = [];
|
|
74
|
+
try { names = fsx.readdirSync(ext); } catch { /* no VS Code extensions folder */ }
|
|
75
|
+
for (const n of names.filter((x) => x.toLowerCase().startsWith('google.google-antigravity'))) found.push({ name: 'vscode extension Google.google-antigravity', file: path.join(ext, n) });
|
|
76
|
+
return found;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export const agyVersion = (home) => { const a = findAgy(home); return a && version(a); };
|
|
80
|
+
|
|
81
|
+
export function detectAgents() {
|
|
82
|
+
const found = {};
|
|
83
|
+
const claude = version('claude');
|
|
84
|
+
if (claude) found.claude = claude;
|
|
85
|
+
const oc = version('opencode');
|
|
86
|
+
if (oc) found[oc.startsWith('1.') ? 'opencode-v1' : 'opencode-v2'] = oc;
|
|
87
|
+
const copilot = version('copilot');
|
|
88
|
+
if (copilot) found['copilot-cli'] = copilot;
|
|
89
|
+
const agy = agyVersion(os.homedir());
|
|
90
|
+
if (agy) found.antigravity = agy;
|
|
91
|
+
const code = version('code');
|
|
92
|
+
if (code) found['vscode-copilot'] = code;
|
|
93
|
+
// The Cursor installer links both `agent` and `cursor-agent`; the second name is unambiguous.
|
|
94
|
+
const cursor = version('cursor-agent');
|
|
95
|
+
if (cursor) found.cursor = cursor;
|
|
96
|
+
return found;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function packageManager() {
|
|
100
|
+
if (isWin) return which('winget') ? 'winget' : which('scoop') ? 'scoop' : null;
|
|
101
|
+
return which('brew') ? 'brew' : null;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// What each tool needs on PATH, and how to get it. Agent CLIs are never installed here.
|
|
105
|
+
export function prereqFor(tool, pm) {
|
|
106
|
+
const brew = (f) => (pm === 'brew' ? [['brew', 'install', f]] : null);
|
|
107
|
+
const winget = (id) => (pm === 'winget' ? [['winget', 'install', '--id', id, '-e', '--scope', 'user', '--accept-source-agreements', '--accept-package-agreements']] : null);
|
|
108
|
+
switch (tool) {
|
|
109
|
+
case 'rtk':
|
|
110
|
+
return { bin: 'rtk', install: brew('rtk') ?? winget('rtk-ai.rtk'), manual: 'https://github.com/rtk-ai/rtk#installation' };
|
|
111
|
+
case 'context-mode':
|
|
112
|
+
return { bin: 'context-mode', install: [['npm', 'install', '-g', npmSpec('context-mode')]] };
|
|
113
|
+
case 'serena':
|
|
114
|
+
return { bin: 'uvx', install: brew('uv') ?? winget('astral-sh.uv'), manual: 'https://docs.astral.sh/uv/getting-started/installation/' };
|
|
115
|
+
case 'playwright':
|
|
116
|
+
case 'playwright-extension':
|
|
117
|
+
case 'caveman':
|
|
118
|
+
case 'codeburn':
|
|
119
|
+
case 'autoskills':
|
|
120
|
+
case 'gsd':
|
|
121
|
+
return { bin: 'npx', install: null, manual: 'https://nodejs.org/' };
|
|
122
|
+
case 'gh':
|
|
123
|
+
return { bin: 'gh', install: brew('gh') ?? winget('GitHub.cli'), manual: 'https://cli.github.com/' };
|
|
124
|
+
case 'git':
|
|
125
|
+
case 'i-have-adhd':
|
|
126
|
+
return { bin: 'git', install: brew('git') ?? winget('Git.Git'), manual: 'https://git-scm.com/downloads' };
|
|
127
|
+
default:
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// One line for a missing git (team mode and the plugin installs need it); null when it is there.
|
|
133
|
+
export function gitHint(pm, present = which('git')) {
|
|
134
|
+
if (present) return null;
|
|
135
|
+
const g = prereqFor('git', pm);
|
|
136
|
+
return `! git not found. ${g.install ? `Install it: ${g.install.map((a) => a.join(' ')).join(' && ')}` : `Install it from ${g.manual}`}`;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Antigravity CLI and app, only when the user picked Antigravity. Only ids checked upstream (2026-11-03) run;
|
|
140
|
+
// the rest print the vendor link. Windows CLI: `Google.AntigravityCLI` has no documented scope, so install.ps1 stays manual.
|
|
141
|
+
// #147: Homebrew installs whatever version the cask has today; it cannot install an older one or a cask from a URL.
|
|
142
|
+
export const BREW_AGY_LIMIT = 'Homebrew cannot pin or verify this cask: you get its current version, unpinned by lean-agents. VERIFY';
|
|
143
|
+
|
|
144
|
+
export function antigravityPrereqs(pm, platform, home, app = true) {
|
|
145
|
+
const out = [];
|
|
146
|
+
const winApp = pm === 'winget' && platform === 'win32';
|
|
147
|
+
if (!findAgy(home, platform)) {
|
|
148
|
+
out.push(platform === 'darwin' && pm === 'brew'
|
|
149
|
+
? { desc: `install agy (${BREW_AGY_LIMIT})`, run: [['brew', 'install', '--cask', 'antigravity-cli']] }
|
|
150
|
+
: { desc: `agy is missing: install it from https://antigravity.google/docs/getting-started`, run: [], manual: true });
|
|
151
|
+
}
|
|
152
|
+
if (!app) return out;
|
|
153
|
+
const appInstalled = platform === 'darwin'
|
|
154
|
+
? exists('/Applications/Antigravity.app') || exists(path.join(home, 'Applications', 'Antigravity.app'))
|
|
155
|
+
: winApp && quiet(['winget', 'list', '--id', 'Google.Antigravity', '-e']).ok;
|
|
156
|
+
if (!appInstalled) {
|
|
157
|
+
if (platform === 'darwin' && pm === 'brew') out.push({ desc: 'install the Antigravity app', run: [['brew', 'install', '--cask', 'antigravity']] });
|
|
158
|
+
else if (winApp) out.push({ desc: 'install the Antigravity app', run: [['winget', 'install', '--id', 'Google.Antigravity', '-e', '--scope', 'user', '--accept-source-agreements', '--accept-package-agreements']] });
|
|
159
|
+
else out.push({ desc: 'The Antigravity app is optional: download it from https://antigravity.google/download', note: true });
|
|
160
|
+
}
|
|
161
|
+
return out;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Bun for Context Mode (JS/TS in ctx_execute). One route per OS; the undo is recorded only when this install ran.
|
|
165
|
+
// Linux and Windows: the pinned release zip is downloaded to a file, checked against the pinned SHA256 and only then extracted,
|
|
166
|
+
// so no upstream installer script runs. Linux: no shell profile edit (the engine finds ~/.bun/bin itself). Windows: ~\.bun\bin goes on the user PATH.
|
|
167
|
+
const VERIFY = fileURLToPath(new URL('./verify-sha256.mjs', import.meta.url));
|
|
168
|
+
const psQ = (s) => s.replace(/'/g, "''"); // PowerShell single-quote escape for a profile path like O'Neil
|
|
169
|
+
const psRun = (script) => ['powershell', '-NoProfile', '-NonInteractive', '-Command', script];
|
|
170
|
+
const psAddPath = (bin) => `$p = [string][Environment]::GetEnvironmentVariable('Path', 'User'); if (($p -split ';').TrimEnd('\\') -notcontains '${psQ(bin)}'.TrimEnd('\\')) { [Environment]::SetEnvironmentVariable('Path', ($p.TrimEnd(';') + ';${psQ(bin)}'), 'User') }`;
|
|
171
|
+
const psRemovePath = (bin) => `$p = [string][Environment]::GetEnvironmentVariable('Path', 'User'); [Environment]::SetEnvironmentVariable('Path', (($p -split ';' | Where-Object { $_ -and $_.TrimEnd('\\') -ne '${psQ(bin)}'.TrimEnd('\\') }) -join ';'), 'User')`;
|
|
172
|
+
|
|
173
|
+
export function bunPathCommand(home) {
|
|
174
|
+
const bin = path.join(home, '.bun', 'bin');
|
|
175
|
+
return {
|
|
176
|
+
// tool bun-path, not bun: a moved Bun pin must not undo and re-record this PATH entry.
|
|
177
|
+
tool: 'bun-path', desc: 'put ~\\.bun\\bin on your user PATH (open a new terminal)', optional: true,
|
|
178
|
+
run: [psRun(psAddPath(bin))],
|
|
179
|
+
undo: [psRun(psRemovePath(bin))],
|
|
180
|
+
// Already in the saved user PATH (only this shell is stale): skip, so --uninstall never removes an entry the user made.
|
|
181
|
+
skipIfOutput: { cmd: psRun(`if (([string][Environment]::GetEnvironmentVariable('Path', 'User') -split ';').TrimEnd('\\') -contains '${psQ(bin)}'.TrimEnd('\\')) { exit 0 } else { exit 1 }`) },
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export function bunInstall(home, dir, platform, pm, arch = process.arch) {
|
|
186
|
+
const bunDir = path.join(home, '.bun');
|
|
187
|
+
if (platform === 'darwin') {
|
|
188
|
+
return pm === 'brew' ? { tool: 'bun', desc: 'install bun', run: [['brew', 'install', 'oven-sh/bun/bun']], undo: [['brew', 'uninstall', 'bun']], optional: true } : null;
|
|
189
|
+
}
|
|
190
|
+
const { version, sha256 } = bunPin();
|
|
191
|
+
const name = `bun-${platform === 'win32' ? 'windows' : 'linux'}-${arch === 'arm64' ? 'aarch64' : 'x64'}`;
|
|
192
|
+
if (!sha256[name.slice(4)]) return null;
|
|
193
|
+
const zip = path.join(dir, `${name}-${version}.zip`);
|
|
194
|
+
const download = [platform === 'win32' ? 'curl.exe' : 'curl', '-fsSL', '-o', zip, `https://github.com/oven-sh/bun/releases/download/bun-v${version}/${name}.zip`];
|
|
195
|
+
const verify = [process.execPath, VERIFY, zip, sha256[name.slice(4)]];
|
|
196
|
+
// Undo removes only the binary this install put there, then the dirs it made if they are empty: ~/.bun may hold the user's cache or global packages.
|
|
197
|
+
const exe = platform === 'win32' ? 'bun.exe' : 'bun';
|
|
198
|
+
const rm = [process.execPath, '-e', `const fs = require("fs"), p = require("path"), d = p.join(require("os").homedir(), ".bun"), b = p.join(d, "bin"); if (p.resolve(process.argv[1]) !== d) { console.error("refusing to remove under " + process.argv[1] + ": not the Bun dir lean-agents installed"); process.exit(1); } try { fs.unlinkSync(p.join(b, "${exe}")); } catch {} for (const x of [b, d]) try { fs.rmdirSync(x); } catch {}`, bunDir];
|
|
199
|
+
if (platform === 'win32') {
|
|
200
|
+
const bin = path.join(bunDir, 'bin');
|
|
201
|
+
const tmp = path.join(dir, `${name}-${version}`);
|
|
202
|
+
return {
|
|
203
|
+
tool: 'bun', desc: `install bun ${version}`, optional: true,
|
|
204
|
+
run: [download, verify, psRun(`Expand-Archive -Force -LiteralPath '${psQ(zip)}' -DestinationPath '${psQ(tmp)}'; New-Item -ItemType Directory -Force '${psQ(bin)}' | Out-Null; Move-Item -Force '${psQ(path.join(tmp, name, 'bun.exe'))}' '${psQ(path.join(bin, 'bun.exe'))}'; Remove-Item -Recurse -Force '${psQ(tmp)}'; ${psAddPath(bin)}`)],
|
|
205
|
+
undo: [rm, psRun(psRemovePath(bin))],
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
return {
|
|
209
|
+
tool: 'bun', desc: `install bun ${version}`, optional: true,
|
|
210
|
+
run: [download, verify, ['mkdir', '-p', path.join(bunDir, 'bin')], ['unzip', '-q', '-j', '-o', zip, `${name}/bun`, '-d', path.join(bunDir, 'bin')]],
|
|
211
|
+
undo: [rm],
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export function rtkInstall(home, dir, platform, arch = process.arch) {
|
|
216
|
+
if (platform !== 'linux') return null;
|
|
217
|
+
const P = path.posix; // Linux steps, even when planned (tests) on Windows
|
|
218
|
+
const { version, sha256 } = rtkPin();
|
|
219
|
+
const aarch = arch === 'arm64' || arch === 'aarch64' ? 'aarch64' : (arch === 'x64' || arch === 'x86_64' ? 'x64' : null);
|
|
220
|
+
if (!aarch) return null;
|
|
221
|
+
const hash = sha256?.[`linux-${aarch}`];
|
|
222
|
+
if (!hash) return null;
|
|
223
|
+
const triple = `${aarch === 'aarch64' ? 'aarch64' : 'x86_64'}-unknown-linux-musl`;
|
|
224
|
+
const tarball = P.join(dir, `rtk-${triple}-${version}.tar.gz`);
|
|
225
|
+
const download = ['curl', '-fsSL', '--create-dirs', '-o', tarball, `https://github.com/rtk-ai/rtk/releases/download/${version}/rtk-${triple}.tar.gz`];
|
|
226
|
+
const verify = [process.execPath, VERIFY, tarball, hash];
|
|
227
|
+
const binDir = P.join(home, '.local', 'bin');
|
|
228
|
+
const bin = P.join(binDir, 'rtk');
|
|
229
|
+
const rm = [process.execPath, '-e', 'require("fs").rmSync(process.argv[1], { force: true })', bin]; // only the binary: ~/.local/bin holds other tools
|
|
230
|
+
return {
|
|
231
|
+
tool: 'rtk', desc: `install rtk ${version}`, optional: true,
|
|
232
|
+
run: [download, verify, ['mkdir', '-p', binDir], ['tar', '-xzf', tarball, '-C', binDir, 'rtk']],
|
|
233
|
+
undo: [rm],
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export const bunPresent = (home) => Boolean(which('bun')) || fs.existsSync(path.join(home, '.bun', 'bin', isWin ? 'bun.exe' : 'bun'));
|
|
238
|
+
|
|
239
|
+
// Node < 24.20 on Windows can abort on exit after the skills CLI finished (nodejs/node#56645); its "Done!" is the proof.
|
|
240
|
+
export const exitCrashAfterDone = (argv, status, out) => status !== 0 && argv.some((a) => /^skills@/.test(a)) && /Done!/.test(out) && /UV_HANDLE_CLOSING/.test(out);
|
|
241
|
+
|
|
242
|
+
// `codes` collects the exit status; `json` sends the child's stdout to stderr so stdout stays one JSON object.
|
|
243
|
+
export function run(argv, { dryRun, log, env, json, codes }) {
|
|
244
|
+
log(` $ ${argv.join(' ')}`);
|
|
245
|
+
if (dryRun) return true;
|
|
246
|
+
const isSkills = argv.some((a) => /^skills@/.test(a));
|
|
247
|
+
const r = isSkills
|
|
248
|
+
? spawnSync(argv[0], argv.slice(1), { stdio: ['inherit', 'pipe', 'pipe'], encoding: 'utf8', shell: useShell(argv[0]), env: { ...allowedEnv(), ...env } })
|
|
249
|
+
: spawnSync(argv[0], argv.slice(1), { stdio: json ? ['inherit', 2, 2] : 'inherit', shell: useShell(argv[0]), env: { ...allowedEnv(), ...env } });
|
|
250
|
+
if (isSkills) {
|
|
251
|
+
(json ? process.stderr : process.stdout).write(r.stdout ?? '');
|
|
252
|
+
process.stderr.write(r.stderr ?? '');
|
|
253
|
+
}
|
|
254
|
+
codes?.push(r.status ?? -1);
|
|
255
|
+
if (exitCrashAfterDone(argv, r.status, `${r.stdout ?? ''}${r.stderr ?? ''}`)) {
|
|
256
|
+
log(' (the skills CLI finished, then Node crashed on exit: nodejs/node#56645, fixed in Node 24.20; counted as done)');
|
|
257
|
+
return true;
|
|
258
|
+
}
|
|
259
|
+
return r.status === 0;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export function quiet(argv, timeout = 30000, env = {}) {
|
|
263
|
+
const r = spawnSync(argv[0], argv.slice(1), { encoding: 'utf8', shell: useShell(argv[0]), timeout, env: { ...allowedEnv(), ...env } });
|
|
264
|
+
// `failed`: the command did not finish (timeout, signal, not runnable), so a non-zero status says nothing about its answer.
|
|
265
|
+
return { ok: r.status === 0, failed: Boolean(r.error || r.signal), out: `${r.stdout ?? ''}${r.stderr ?? ''}` };
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
export const exists = (p) => Array.isArray(p) ? p.some(x => fs.existsSync(x)) : fs.existsSync(p);
|
|
269
|
+
|