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,178 @@
|
|
|
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 } 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
|
+
export function version(bin, args = ['--version'], env = {}) {
|
|
21
|
+
if (!which(bin)) return null;
|
|
22
|
+
const r = spawnSync(bin, args, { encoding: 'utf8', shell: useShell(bin), timeout: 20000, env: { ...allowedEnv(), ...env } });
|
|
23
|
+
const m = `${r.stdout}${r.stderr}`.match(/(\d+)\.(\d+)\.(\d+)/);
|
|
24
|
+
return m ? m[0] : 'unknown';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// A config dir from the environment counts only for the real home or inside --home:
|
|
28
|
+
// a run with --home must never write outside it, even when the variable is set.
|
|
29
|
+
export function envDir(home, name, fallback) {
|
|
30
|
+
const value = process.env[name];
|
|
31
|
+
if (!value || !path.isAbsolute(value)) return fallback;
|
|
32
|
+
const rel = path.relative(home, value);
|
|
33
|
+
const inside = !rel.startsWith('..') && !path.isAbsolute(rel);
|
|
34
|
+
return home === os.homedir() || inside ? value : fallback;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const configHome = (home) => envDir(home, 'XDG_CONFIG_HOME', path.join(home, '.config'));
|
|
38
|
+
|
|
39
|
+
// External tools read HOME, not --home, so a run with --home hands it down to every child.
|
|
40
|
+
export function isolate(home) {
|
|
41
|
+
if (home === os.homedir()) return;
|
|
42
|
+
const env = { XDG_CONFIG_HOME: configHome(home), COPILOT_HOME: envDir(home, 'COPILOT_HOME', path.join(home, '.copilot')) };
|
|
43
|
+
for (const name of ['XDG_CACHE_HOME', 'XDG_DATA_HOME', 'XDG_STATE_HOME']) {
|
|
44
|
+
if (!envDir(home, name, null)) delete process.env[name];
|
|
45
|
+
}
|
|
46
|
+
Object.assign(process.env, env, { HOME: home, USERPROFILE: home });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function detectAgents() {
|
|
50
|
+
const found = {};
|
|
51
|
+
const claude = version('claude');
|
|
52
|
+
if (claude) found.claude = claude;
|
|
53
|
+
const oc = version('opencode');
|
|
54
|
+
if (oc) found[oc.startsWith('1.') ? 'opencode-v1' : 'opencode-v2'] = oc;
|
|
55
|
+
const copilot = version('copilot');
|
|
56
|
+
if (copilot) found['copilot-cli'] = copilot;
|
|
57
|
+
const agy = version('agy');
|
|
58
|
+
if (agy) found.antigravity = agy;
|
|
59
|
+
const code = version('code');
|
|
60
|
+
if (code) found['vscode-copilot'] = code;
|
|
61
|
+
// The Cursor installer links both `agent` and `cursor-agent`; the second name is unambiguous.
|
|
62
|
+
const cursor = version('cursor-agent');
|
|
63
|
+
if (cursor) found.cursor = cursor;
|
|
64
|
+
return found;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function packageManager() {
|
|
68
|
+
if (isWin) return which('winget') ? 'winget' : which('scoop') ? 'scoop' : null;
|
|
69
|
+
return which('brew') ? 'brew' : null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// What each tool needs on PATH, and how to get it. Agent CLIs are never installed here.
|
|
73
|
+
export function prereqFor(tool, pm) {
|
|
74
|
+
const brew = (f) => (pm === 'brew' ? [['brew', 'install', f]] : null);
|
|
75
|
+
const winget = (id) => (pm === 'winget' ? [['winget', 'install', '--id', id, '-e', '--scope', 'user', '--accept-source-agreements', '--accept-package-agreements']] : null);
|
|
76
|
+
switch (tool) {
|
|
77
|
+
case 'rtk':
|
|
78
|
+
return { bin: 'rtk', install: brew('rtk') ?? winget('rtk-ai.rtk'), manual: 'https://github.com/rtk-ai/rtk#installation' };
|
|
79
|
+
case 'context-mode':
|
|
80
|
+
return { bin: 'context-mode', install: [['npm', 'install', '-g', npmSpec('context-mode')]] };
|
|
81
|
+
case 'serena':
|
|
82
|
+
return { bin: 'uvx', install: brew('uv') ?? winget('astral-sh.uv'), manual: 'https://docs.astral.sh/uv/getting-started/installation/' };
|
|
83
|
+
case 'playwright':
|
|
84
|
+
case 'playwright-extension':
|
|
85
|
+
case 'caveman':
|
|
86
|
+
case 'codeburn':
|
|
87
|
+
case 'autoskills':
|
|
88
|
+
case 'gsd':
|
|
89
|
+
return { bin: 'npx', install: null, manual: 'https://nodejs.org/' };
|
|
90
|
+
case 'gh':
|
|
91
|
+
return { bin: 'gh', install: brew('gh') ?? winget('GitHub.cli'), manual: 'https://cli.github.com/' };
|
|
92
|
+
case 'git':
|
|
93
|
+
case 'i-have-adhd':
|
|
94
|
+
return { bin: 'git', install: brew('git') ?? winget('Git.Git'), manual: 'https://git-scm.com/downloads' };
|
|
95
|
+
default:
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// One line for a missing git (team mode and the plugin installs need it); null when it is there.
|
|
101
|
+
export function gitHint(pm, present = which('git')) {
|
|
102
|
+
if (present) return null;
|
|
103
|
+
const g = prereqFor('git', pm);
|
|
104
|
+
return `! git not found. ${g.install ? `Install it: ${g.install.map((a) => a.join(' ')).join(' && ')}` : `Install it from ${g.manual}`}`;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Antigravity CLI and app, only when the user picked Antigravity. Only ids checked upstream (2026-11-03) run;
|
|
108
|
+
// the rest print the vendor link. Windows CLI: `Google.AntigravityCLI` has no documented scope, so install.ps1 stays manual.
|
|
109
|
+
export function antigravityPrereqs(pm, platform, home, app = true) {
|
|
110
|
+
const out = [];
|
|
111
|
+
const winApp = pm === 'winget' && platform === 'win32';
|
|
112
|
+
if (!which('agy')) {
|
|
113
|
+
out.push(platform === 'darwin' && pm === 'brew'
|
|
114
|
+
? { desc: 'install agy', run: [['brew', 'install', '--cask', 'antigravity-cli']] }
|
|
115
|
+
: { desc: `agy is missing: install it from https://antigravity.google/docs/getting-started`, run: [], manual: true });
|
|
116
|
+
}
|
|
117
|
+
if (!app) return out;
|
|
118
|
+
const appInstalled = platform === 'darwin'
|
|
119
|
+
? exists('/Applications/Antigravity.app') || exists(path.join(home, 'Applications', 'Antigravity.app'))
|
|
120
|
+
: winApp && quiet(['winget', 'list', '--id', 'Google.Antigravity', '-e']).ok;
|
|
121
|
+
if (!appInstalled) {
|
|
122
|
+
if (platform === 'darwin' && pm === 'brew') out.push({ desc: 'install the Antigravity app', run: [['brew', 'install', '--cask', 'antigravity']] });
|
|
123
|
+
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']] });
|
|
124
|
+
else out.push({ desc: 'The Antigravity app is optional: download it from https://antigravity.google/download', note: true });
|
|
125
|
+
}
|
|
126
|
+
return out;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Bun for Context Mode (JS/TS in ctx_execute). One route per OS; the undo is recorded only when this install ran.
|
|
130
|
+
// Linux and Windows: the pinned release zip is downloaded to a file, checked against the pinned SHA256 and only then extracted,
|
|
131
|
+
// 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.
|
|
132
|
+
const VERIFY = fileURLToPath(new URL('./verify-sha256.mjs', import.meta.url));
|
|
133
|
+
export function bunInstall(home, dir, platform, pm, arch = process.arch) {
|
|
134
|
+
const bunDir = path.join(home, '.bun');
|
|
135
|
+
if (platform === 'darwin') {
|
|
136
|
+
return pm === 'brew' ? { tool: 'bun', desc: 'install bun', run: [['brew', 'install', 'oven-sh/bun/bun']], undo: [['brew', 'uninstall', 'bun']], optional: true } : null;
|
|
137
|
+
}
|
|
138
|
+
const { version, sha256 } = bunPin();
|
|
139
|
+
const name = `bun-${platform === 'win32' ? 'windows' : 'linux'}-${arch === 'arm64' ? 'aarch64' : 'x64'}`;
|
|
140
|
+
if (!sha256[name.slice(4)]) return null;
|
|
141
|
+
const zip = path.join(dir, `${name}-${version}.zip`);
|
|
142
|
+
const download = [platform === 'win32' ? 'curl.exe' : 'curl', '-fsSL', '-o', zip, `https://github.com/oven-sh/bun/releases/download/bun-v${version}/${name}.zip`];
|
|
143
|
+
const verify = [process.execPath, VERIFY, zip, sha256[name.slice(4)]];
|
|
144
|
+
const rm = [process.execPath, '-e', 'require("fs").rmSync(process.argv[1], { recursive: true, force: true })', bunDir];
|
|
145
|
+
if (platform === 'win32') {
|
|
146
|
+
const bin = path.join(bunDir, 'bin');
|
|
147
|
+
const tmp = path.join(dir, `${name}-${version}`);
|
|
148
|
+
const q = (s) => s.replace(/'/g, "''"); // PowerShell single-quote escape for a profile path like O'Neil
|
|
149
|
+
const ps = (script) => ['powershell', '-NoProfile', '-NonInteractive', '-Command', script];
|
|
150
|
+
return {
|
|
151
|
+
tool: 'bun', desc: `install bun ${version}`, optional: true,
|
|
152
|
+
run: [download, verify, ps(`Expand-Archive -Force -LiteralPath '${q(zip)}' -DestinationPath '${q(tmp)}'; New-Item -ItemType Directory -Force '${q(bin)}' | Out-Null; Move-Item -Force '${q(path.join(tmp, name, 'bun.exe'))}' '${q(path.join(bin, 'bun.exe'))}'; Remove-Item -Recurse -Force '${q(tmp)}'; $p = [string][Environment]::GetEnvironmentVariable('Path', 'User'); if (($p -split ';') -notcontains '${q(bin)}') { [Environment]::SetEnvironmentVariable('Path', ($p.TrimEnd(';') + ';${q(bin)}'), 'User') }`)],
|
|
153
|
+
undo: [rm, ps(`$p = [string][Environment]::GetEnvironmentVariable('Path', 'User'); [Environment]::SetEnvironmentVariable('Path', (($p -split ';' | Where-Object { $_ -and $_ -ne '${q(bin)}' }) -join ';'), 'User')`)],
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
tool: 'bun', desc: `install bun ${version}`, optional: true,
|
|
158
|
+
run: [download, verify, ['mkdir', '-p', path.join(bunDir, 'bin')], ['unzip', '-q', '-j', '-o', zip, `${name}/bun`, '-d', path.join(bunDir, 'bin')]],
|
|
159
|
+
undo: [rm],
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export const bunPresent = (home) => Boolean(which('bun')) || fs.existsSync(path.join(home, '.bun', 'bin', isWin ? 'bun.exe' : 'bun'));
|
|
164
|
+
|
|
165
|
+
export function run(argv, { dryRun, log, env }) {
|
|
166
|
+
log(` $ ${argv.join(' ')}`);
|
|
167
|
+
if (dryRun) return true;
|
|
168
|
+
const r = spawnSync(argv[0], argv.slice(1), { stdio: 'inherit', shell: useShell(argv[0]), env: { ...allowedEnv(), ...env } });
|
|
169
|
+
return r.status === 0;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export function quiet(argv, timeout = 30000, env = {}) {
|
|
173
|
+
const r = spawnSync(argv[0], argv.slice(1), { encoding: 'utf8', shell: useShell(argv[0]), timeout, env: { ...allowedEnv(), ...env } });
|
|
174
|
+
return { ok: r.status === 0, out: `${r.stdout ?? ''}${r.stderr ?? ''}` };
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export const exists = (p) => fs.existsSync(p);
|
|
178
|
+
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
// Warp and Orca: detect the app, then plan the agent integrations for a user who already has it.
|
|
2
|
+
// The terminal apps themselves are never installed.
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { which, quiet } from './system.mjs';
|
|
6
|
+
import { hasProxy } from './network.mjs';
|
|
7
|
+
import { skillSource, skillsCli } from './pins.mjs';
|
|
8
|
+
|
|
9
|
+
export const TERMINALS = ['warp', 'orca'];
|
|
10
|
+
// Skills CLI agent ids; VS Code Copilot reads ~/.copilot/skills like Copilot CLI.
|
|
11
|
+
const ORCA_SKILL_AGENT = { claude: 'claude-code', 'opencode-v1': 'opencode', 'opencode-v2': 'opencode', 'copilot-cli': 'github-copilot', 'vscode-copilot': 'github-copilot', cursor: 'cursor', antigravity: 'antigravity-cli' };
|
|
12
|
+
// Orca's hooks POST status to 127.0.0.1; Windows curl sends loopback to the proxy unless NO_PROXY lists it.
|
|
13
|
+
const LOOPBACK = ['localhost', '127.0.0.1', '::1'];
|
|
14
|
+
const ORCA_TELEMETRY_ENV = ['DO_NOT_TRACK', 'ORCA_TELEMETRY_DISABLED'];
|
|
15
|
+
const ps = (script) => ['powershell', '-NoProfile', '-NonInteractive', '-Command', script];
|
|
16
|
+
|
|
17
|
+
// `platform` and `env` are parameters so tests can fake an OS without touching the machine.
|
|
18
|
+
export function detectTerminals(home, { platform = process.platform, env = process.env, system = true } = {}) {
|
|
19
|
+
const has = (...paths) => paths.some((p) => p && fs.existsSync(p));
|
|
20
|
+
const found = [];
|
|
21
|
+
// `system` is false for a run with --home: it looks only inside it, so a throwaway HOME behaves the same on every machine.
|
|
22
|
+
const apps = platform === 'darwin' ? [path.join(home, 'Applications'), ...(system ? ['/Applications'] : [])] : [];
|
|
23
|
+
const local = platform === 'win32' && system ? env.LOCALAPPDATA : null;
|
|
24
|
+
// PATH lookups are system-wide, so they follow `system` too. Linux `orca` is the GNOME screen reader: not a signal.
|
|
25
|
+
// Windows install folders under Programs: VERIFY.
|
|
26
|
+
const onPath = (bin) => system && which(bin);
|
|
27
|
+
if (has(...apps.map((d) => path.join(d, 'Warp.app')), local && path.join(local, 'Programs', 'Warp')) || onPath('warp-terminal')) found.push('warp');
|
|
28
|
+
if (has(...apps.map((d) => path.join(d, 'Orca.app')), local && path.join(local, 'Programs', 'Orca')) || (platform !== 'linux' && onPath('orca'))) found.push('orca');
|
|
29
|
+
return found;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// --terminal value to a list; "both" and "none" are shorthands.
|
|
33
|
+
export function parseTerminal(v) {
|
|
34
|
+
if (v === 'both') return [...TERMINALS];
|
|
35
|
+
if (v === 'none') return [];
|
|
36
|
+
if (TERMINALS.includes(v)) return [v];
|
|
37
|
+
throw new Error('--terminal takes warp, orca, both or none');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Commands only: OpenCode plugin entries go into the OpenCode adapter's own json edit, because two
|
|
41
|
+
// json actions on one file would each start from the unedited text.
|
|
42
|
+
// `system` is false for --home runs: Windows user env changes are real-machine only.
|
|
43
|
+
export function terminalCommands({ terminals, agents, network = {}, platform = process.platform, env = process.env, system = true, readEnv = readWindowsEnv }) {
|
|
44
|
+
const commands = [];
|
|
45
|
+
if (terminals.includes('warp') && agents.includes('claude')) {
|
|
46
|
+
commands.push({
|
|
47
|
+
tool: 'warp',
|
|
48
|
+
desc: 'Warp plugin for Claude Code (needs jq)',
|
|
49
|
+
run: [['claude', 'plugin', 'marketplace', 'add', 'warpdotdev/claude-code-warp'], ['claude', 'plugin', 'install', 'warp@claude-code-warp']],
|
|
50
|
+
undo: [['claude', 'plugin', 'uninstall', 'warp@claude-code-warp']],
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
if (terminals.includes('orca')) {
|
|
54
|
+
const as = [...new Set(agents.map((a) => ORCA_SKILL_AGENT[a]).filter(Boolean))];
|
|
55
|
+
if (as.length) {
|
|
56
|
+
commands.push({
|
|
57
|
+
tool: 'orca',
|
|
58
|
+
desc: 'Orca skill orca-cli',
|
|
59
|
+
run: [['npx', '-y', skillsCli(), 'add', skillSource('orca-cli'), '--skill', 'orca-cli', '-a', ...as, '-g', '-y']],
|
|
60
|
+
undo: [['npx', '-y', skillsCli(), 'remove', 'orca-cli', '-g', '-y']],
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
if (platform === 'win32' && system) commands.push(...orcaWindowsCommands({ network, env, readEnv }));
|
|
64
|
+
}
|
|
65
|
+
return commands;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// One Windows env value from the User or Machine scope (null when unset); plan time only, read-only.
|
|
69
|
+
function readWindowsEnv(scope, name) {
|
|
70
|
+
const r = quiet(ps(`[Console]::Out.Write([Environment]::GetEnvironmentVariable('${name}','${scope}'))`));
|
|
71
|
+
return r.ok && r.out.trim() ? r.out.trim() : null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function orcaWindowsCommands({ network, env, readEnv }) {
|
|
75
|
+
const commands = [];
|
|
76
|
+
if (network.telemetry === 'off') {
|
|
77
|
+
for (const name of ORCA_TELEMETRY_ENV) {
|
|
78
|
+
commands.push({
|
|
79
|
+
tool: 'orca',
|
|
80
|
+
desc: `Orca telemetry off: ${name}=1 in your Windows user env (restart Orca)`,
|
|
81
|
+
run: [ps(`[Environment]::SetEnvironmentVariable('${name}','1','User')`)],
|
|
82
|
+
undo: [ps(`[Environment]::SetEnvironmentVariable('${name}',$null,'User')`)],
|
|
83
|
+
// A value you already set is yours: never overwritten, never undone.
|
|
84
|
+
skipIfOutput: { cmd: ps(`if (-not ([Environment]::GetEnvironmentVariable('${name}','User') -or [Environment]::GetEnvironmentVariable('${name}','Machine'))) { exit 1 }`) },
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (hasProxy(env)) {
|
|
89
|
+
// Scopes decide, not this shell: a value set only in the current session is not persisted anywhere.
|
|
90
|
+
const user = readEnv('User', 'NO_PROXY');
|
|
91
|
+
const machine = readEnv('Machine', 'NO_PROXY');
|
|
92
|
+
const have = (user ?? machine ?? '').split(',').map((x) => x.trim());
|
|
93
|
+
const missing = LOOPBACK.filter((h) => !have.includes(h));
|
|
94
|
+
if (missing.length) {
|
|
95
|
+
const list = missing.map((h) => `'${h}'`).join(',');
|
|
96
|
+
const get = (scope) => `[Environment]::GetEnvironmentVariable('NO_PROXY','${scope}')`;
|
|
97
|
+
commands.push({
|
|
98
|
+
tool: 'orca',
|
|
99
|
+
desc: `NO_PROXY: add ${missing.join(', ')} to your Windows user env so Orca status hooks skip the proxy (restart Orca)`,
|
|
100
|
+
// A user value shadows the machine one, so without a user value the machine value is the starting point.
|
|
101
|
+
run: [ps(`$v=${get('User')}; if (-not $v) { $v=${get('Machine')} }; $l=@($v -split ',' | Where-Object { $_ }); foreach ($h in @(${list})) { if ($l -notcontains $h) { $l += $h } }; [Environment]::SetEnvironmentVariable('NO_PROXY', ($l -join ','), 'User')`)],
|
|
102
|
+
// Drops only our entries. With no user value before, the var was ours: remove it once nothing but the machine value is left.
|
|
103
|
+
undo: [ps(`$l=@(${get('User')} -split ',' | Where-Object { $_ -and @(${list}) -notcontains $_ }); ${user ? '' : `$l=@($l | Where-Object { @(${get('Machine')} -split ',') -notcontains $_ }); `}[Environment]::SetEnvironmentVariable('NO_PROXY', $(if ($l.Count) { $l -join ',' } else { $null }), 'User')`)],
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return commands;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Git Bash's bash.exe absolute path, found under the standard install folders; null off Windows or not found.
|
|
111
|
+
// MSYSTEM alone (a shell started from Git Bash) carries no path, so it is not a source here.
|
|
112
|
+
export function gitBashPath({ platform = process.platform, env = process.env } = {}) {
|
|
113
|
+
if (platform !== 'win32') return null;
|
|
114
|
+
const roots = [env.ProgramFiles, env['ProgramFiles(x86)'], env.LOCALAPPDATA && path.join(env.LOCALAPPDATA, 'Programs')];
|
|
115
|
+
for (const d of roots) {
|
|
116
|
+
if (!d) continue;
|
|
117
|
+
const p = path.join(d, 'Git', 'bin', 'bash.exe');
|
|
118
|
+
if (fs.existsSync(p)) return p;
|
|
119
|
+
}
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Git Bash on Windows: a shell started from it, or the standard install folders.
|
|
124
|
+
function gitBashPresent({ platform, env }) {
|
|
125
|
+
if (platform !== 'win32') return false;
|
|
126
|
+
return Boolean(env.MSYSTEM) || Boolean(gitBashPath({ platform, env }));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Which shell the agent will use on Windows, and what breaks without Git Bash. null off Windows.
|
|
130
|
+
export function shellNotice({ platform = process.platform, env = process.env } = {}) {
|
|
131
|
+
if (platform !== 'win32') return null;
|
|
132
|
+
if (gitBashPresent({ platform, env })) return { ok: true, text: 'Windows shell: Git Bash found. RTK and bash-style commands can run there.' };
|
|
133
|
+
return { ok: false, text: 'Windows shell: Git Bash not found, so agents fall back to PowerShell or cmd.exe. RTK rewrites and bash-style commands then fail or are skipped, output is not compressed (more tokens) and the rules\' POSIX examples do not apply. Fix: install Git for Windows (winget install Git.Git), then run --doctor.' };
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Marked ~/.bashrc block for Git Bash. Entries are appended at run time, so the user's own NO_PROXY is kept.
|
|
137
|
+
export function gitBashActions({ home, terminals, agents, platform = process.platform, env = process.env }) {
|
|
138
|
+
if (!gitBashPresent({ platform, env })) return [];
|
|
139
|
+
const lines = [];
|
|
140
|
+
if (agents.includes('cursor')) {
|
|
141
|
+
lines.push(
|
|
142
|
+
'# Cursor CLI hooks are denied under Git Bash unless MSYSTEM and SHELL are empty.',
|
|
143
|
+
"alias agent='MSYSTEM= SHELL= agent.cmd'",
|
|
144
|
+
"alias cursor-agent='MSYSTEM= SHELL= cursor-agent.cmd'",
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
if (terminals.includes('orca') && hasProxy(env)) {
|
|
148
|
+
lines.push(
|
|
149
|
+
'# Orca status hooks call 127.0.0.1 with curl: keep loopback off the proxy.',
|
|
150
|
+
`for h in ${LOOPBACK.join(' ')}; do`,
|
|
151
|
+
' case ",$NO_PROXY," in *",$h,"*) ;; *) NO_PROXY="${NO_PROXY:+$NO_PROXY,}$h" ;; esac',
|
|
152
|
+
' case ",$no_proxy," in *",$h,"*) ;; *) no_proxy="${no_proxy:+$no_proxy,}$h" ;; esac',
|
|
153
|
+
'done',
|
|
154
|
+
'export NO_PROXY no_proxy',
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
return lines.length ? [{ kind: 'block', toml: true, path: path.join(home, '.bashrc'), body: lines.join('\n') }] : [];
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Manual steps lean-agents cannot script: printed after install and by --doctor.
|
|
161
|
+
// `check` (when present) says whether a step is already done.
|
|
162
|
+
export function stillNeeded({ home, terminals, agents, platform = process.platform, env = process.env, exec = false, readEnv = readWindowsEnv }) {
|
|
163
|
+
const out = [];
|
|
164
|
+
if (agents.includes('cursor')) {
|
|
165
|
+
out.push({ text: 'Cursor: run `agent login` once (CLI) and sign in to the Cursor app; `agent mcp login <server>` for any MCP server that needs OAuth.' });
|
|
166
|
+
out.push({ text: 'Cursor: paste your global rules into Cursor Settings > Rules > User Rules (there is no file for them); --project writes team rules instead.' });
|
|
167
|
+
if (hasProxy(env)) out.push({ text: 'Cursor behind a proxy: export HTTP_PROXY, HTTPS_PROXY and NODE_USE_ENV_PROXY=1 in your shell profile (lean-agents never writes proxy values).' });
|
|
168
|
+
}
|
|
169
|
+
if (terminals.includes('orca')) {
|
|
170
|
+
if (platform === 'win32') {
|
|
171
|
+
out.push({ text: 'Orca: click "Install CLI & Skills" in Orca to put `orca` on PATH (%LOCALAPPDATA%\\Programs\\Orca\\resources\\bin).', check: exec ? () => Boolean(which('orca')) : undefined });
|
|
172
|
+
}
|
|
173
|
+
if (platform === 'win32' && hasProxy(env)) {
|
|
174
|
+
// Orca hands its own env to every terminal and Bun (OpenCode) reads proxy vars once, so a NO_PROXY added later needs an Orca restart.
|
|
175
|
+
out.push({
|
|
176
|
+
text: 'Orca behind a proxy: the Windows user NO_PROXY must list localhost, 127.0.0.1 and ::1, and Orca must be restarted after you change it (an Orca started earlier keeps the old value: status posts go to the proxy and fail with 403).',
|
|
177
|
+
check: exec ? () => LOOPBACK.every((h) => (readEnv('User', 'NO_PROXY') ?? readEnv('Machine', 'NO_PROXY') ?? '').split(',').map((x) => x.trim()).includes(h)) : undefined,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
// Mod+P is Ctrl+P on Windows; the rebind is the owner's report from the Windows work PC (#78).
|
|
181
|
+
if (platform === 'win32') out.push({ text: 'Orca: Ctrl+P opens Orca\'s worktree quick-open, so OpenCode never sees it. To keep Ctrl+P for OpenCode, put {"platforms":{"win32":{"worktree.quickOpen":["Ctrl+Shift+P"]}}} in ~/.orca/keybindings.json (lean-agents never edits that file).' });
|
|
182
|
+
out.push(
|
|
183
|
+
{ text: 'Orca: the first launch turns on agent status hooks, which write into ~/.claude/settings.json and ~/.cursor/hooks.json (Settings > Agents > Agent status hooks). --uninstall leaves them alone.', check: () => orcaHooksFound(home).length > 0 },
|
|
184
|
+
{ text: 'Orca: Settings > Agents > Agent permissions may start agents in Yolo mode; pick Manual if you expect approval prompts.' },
|
|
185
|
+
{ text: 'Orca: Settings > Session History > "Search inside sessions" indexes the full text of every agent chat on this machine; it is on by default.' },
|
|
186
|
+
{ text: 'Orca: restart Orca after env changes, then start a fresh agent tab (restored tabs keep the old env).' },
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
return out;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Orca hook entries found in other agents' configs, for --doctor.
|
|
193
|
+
const ORCA_HOOK = /[\\/]\.orca[\\/]agent-hooks|orca-agent-hook|ORCA_AGENT_HOOK/i;
|
|
194
|
+
export function orcaHooksFound(home) {
|
|
195
|
+
return [path.join(home, '.claude', 'settings.json'), path.join(home, '.cursor', 'hooks.json')].filter((f) => {
|
|
196
|
+
if (!fs.existsSync(f)) return false;
|
|
197
|
+
let text;
|
|
198
|
+
try { text = fs.readFileSync(f, 'utf8'); } catch { return false; }
|
|
199
|
+
// On Windows Orca writes the Cursor hook as a PowerShell -EncodedCommand (UTF-16LE base64).
|
|
200
|
+
const decoded = [...text.matchAll(/-EncodedCommand\s+([A-Za-z0-9+/=]+)/gi)].map((m) => Buffer.from(m[1], 'base64').toString('utf16le'));
|
|
201
|
+
return [text, ...decoded].some((t) => ORCA_HOOK.test(t));
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// True when an Orca opt-out is already set (Windows real home only). Reads process.env only: on Windows
|
|
206
|
+
// it carries the User and Machine vars from login, and spawning PowerShell here would touch USERPROFILE on a dry run.
|
|
207
|
+
export function orcaEnvSet({ platform = process.platform, system = true, env = process.env } = {}) {
|
|
208
|
+
if (platform !== 'win32' || !system) return false;
|
|
209
|
+
return ORCA_TELEMETRY_ENV.some((name) => Boolean(env[name]));
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// Printed with the all-off network preset; app settings stay the user's.
|
|
213
|
+
export function terminalPrivacyNotes(terminals, { orcaEnvSet = false } = {}) {
|
|
214
|
+
const notes = [];
|
|
215
|
+
if (terminals.includes('warp')) notes.push('Warp telemetry: set `[privacy] telemetry_enabled = false` in its settings.toml (the free plan may need it on for AI)');
|
|
216
|
+
if (terminals.includes('orca') && !orcaEnvSet) notes.push('Orca telemetry: set DO_NOT_TRACK=1 where Orca starts, or turn off Settings > Privacy > Share anonymous usage data');
|
|
217
|
+
return notes;
|
|
218
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Menus and progress for a real terminal, with @clack/prompts. lean.mjs keeps its readline prompter
|
|
2
|
+
// for every other case: clack hangs without a TTY or with a zero-width one, and Git Bash (mintty) has no raw mode.
|
|
3
|
+
export const canUseMenus = (input) => input.isTTY === true && typeof input.setRawMode === 'function' && process.stdout.isTTY === true && process.stdout.columns > 0;
|
|
4
|
+
|
|
5
|
+
export async function menuPrompter(input) {
|
|
6
|
+
const c = await import('@clack/prompts');
|
|
7
|
+
const io = { input, output: process.stdout };
|
|
8
|
+
const answer = (v) => {
|
|
9
|
+
if (c.isCancel(v)) { c.cancel('Cancelled.'); throw new Error('cancelled, nothing changed'); }
|
|
10
|
+
return v;
|
|
11
|
+
};
|
|
12
|
+
c.intro('lean-agents');
|
|
13
|
+
return {
|
|
14
|
+
menus: true,
|
|
15
|
+
// Yes/no questions keep their readline answers (y/n), so callers do not change.
|
|
16
|
+
ask: async (q, def) => {
|
|
17
|
+
if (def === 'y' || def === 'n') return answer(await c.confirm({ ...io, message: q, initialValue: def === 'y' })) ? 'y' : 'n';
|
|
18
|
+
return String(answer(await c.text({ ...io, message: q, placeholder: def, defaultValue: def }))).trim() || def;
|
|
19
|
+
},
|
|
20
|
+
select: async ({ message, options, def }) => answer(await c.select({ ...io, message, options, initialValue: def })),
|
|
21
|
+
multi: async ({ message, items, defaults }) => answer(await c.multiselect({ ...io, message, options: items, initialValues: defaults, required: false })),
|
|
22
|
+
close() { if (input !== process.stdin) input.destroy(); },
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Progress list and final summary. Without menus the engine prints its plain lines instead.
|
|
27
|
+
export async function menuProgress() {
|
|
28
|
+
const c = await import('@clack/prompts');
|
|
29
|
+
return {
|
|
30
|
+
step: (i, n, desc) => c.log.step(`[${i}/${n}] ${desc}`),
|
|
31
|
+
result: (ok, desc) => (ok ? c.log.success(desc) : c.log.error(`failed: ${desc}. Run the command above by hand, then --doctor.`)),
|
|
32
|
+
summary: (title, lines, ok) => { c.note(lines.join('\n'), title); c.outro(ok ? 'Done.' : 'Finished with errors.'); },
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Settings upstream does not document (VERIFY in docs/compatibility.md). lean-agents never guesses
|
|
2
|
+
// them: the user pastes their docs or IT notes, saved as-is for an agent to apply after review.
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { OWNED_MARK } from './fsops.mjs';
|
|
6
|
+
import { configHome } from './system.mjs';
|
|
7
|
+
import { redactUrl } from './network.mjs';
|
|
8
|
+
|
|
9
|
+
export const notesDir = (home) => path.join(home, '.config', 'lean-agents', 'notes');
|
|
10
|
+
|
|
11
|
+
// "kept": another agent or the user already set the tool up, so the question is skipped and no notes are added.
|
|
12
|
+
export function unverifiedItems(o, home, { platform = process.platform, env = process.env, stateFiles = [] } = {}) {
|
|
13
|
+
const ours = new Set(stateFiles.map((f) => f.path));
|
|
14
|
+
const foreign = (p) => fs.existsSync(p) && !ours.has(p);
|
|
15
|
+
const off = (c) => o.network[c] === 'off';
|
|
16
|
+
const win = platform === 'win32';
|
|
17
|
+
const items = [];
|
|
18
|
+
const add = (id, label, kept = false) => items.push({ id, label, kept });
|
|
19
|
+
if (o.agents.includes('antigravity') && (off('telemetry') || off('autoUpdate'))) add('antigravity', 'Antigravity telemetry and auto-update switches');
|
|
20
|
+
if (o.tools.includes('serena')) add('serena', 'Serena config (serena_config.yml)', fs.existsSync(path.join(home, '.serena', 'serena_config.yml')));
|
|
21
|
+
if (win && (env.HTTPS_PROXY || env.https_proxy || env.HTTP_PROXY || env.http_proxy)) add('winget-proxy', 'winget persistent proxy');
|
|
22
|
+
if (o.tools.includes('playwright') || win) add('download-hosts', 'download hosts (Playwright browsers, winget packages)');
|
|
23
|
+
if (off('telemetry')) {
|
|
24
|
+
if (o.tools.includes('dcp')) add('dcp', 'DCP telemetry', foreign(path.join(configHome(home), 'opencode', 'dcp.jsonc')));
|
|
25
|
+
if (o.tools.includes('gsd')) add('gsd', 'GSD telemetry', foreign(path.join(home, '.gsd', 'defaults.json')));
|
|
26
|
+
if (o.tools.includes('autoskills')) add('autoskills', 'AutoSkills telemetry');
|
|
27
|
+
}
|
|
28
|
+
return items;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Pasted notes may hold credentials in forms other than a URL.
|
|
32
|
+
export const redactNotes = (text) => redactUrl(text)
|
|
33
|
+
.replace(/(^|[\s=])[^\s:@/=]+:[^\s@/]+@/g, '$1***@')
|
|
34
|
+
.replace(/((?:password|passwd|pwd|token|secret)\s*[=:]\s*)\S+/gi, '$1***');
|
|
35
|
+
|
|
36
|
+
// The answer is one line of text, or an absolute or ~ path to a file with the docs.
|
|
37
|
+
export function notesFile(home, item, answer) {
|
|
38
|
+
const p = answer.replace(/^~(?=[/\\])/, home);
|
|
39
|
+
const fromFile = path.isAbsolute(p) && fs.existsSync(p) && fs.statSync(p).isFile();
|
|
40
|
+
const text = redactNotes(fromFile ? fs.readFileSync(p, 'utf8') : answer).trimEnd();
|
|
41
|
+
return {
|
|
42
|
+
kind: 'file',
|
|
43
|
+
path: path.join(notesDir(home), `${item.id}.md`),
|
|
44
|
+
content: `<!-- ${OWNED_MARK}: your notes, never applied automatically -->\n# ${item.label}\n\n`
|
|
45
|
+
+ 'Upstream does not document this setting (VERIFY in lean-agents docs/compatibility.md).\n'
|
|
46
|
+
+ 'Ask your agent to apply these notes, showing you each change first.\n\n'
|
|
47
|
+
+ `Source: ${fromFile ? p : 'pasted'}\n\n${text}\n`,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// --upgrade-agent opencode (#80 PR A): the --adopt inventory plus, per OpenCode 1.x item, what a move to 2.x would do with it.
|
|
2
|
+
// Read-only: only key names are printed, never env or header values. `home`, `fsx` and `binary` are passed in so tests never read the real machine.
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { parse } from 'jsonc-parser';
|
|
6
|
+
import { hasMark } from './fsops.mjs';
|
|
7
|
+
import { configHome } from './system.mjs';
|
|
8
|
+
import { configPath } from './adapters/opencode-v2.mjs';
|
|
9
|
+
|
|
10
|
+
const j = path.join;
|
|
11
|
+
|
|
12
|
+
// The translation table. `verified: false` rows are VERIFY (docs/compatibility.md): their items stay user-manual until proven.
|
|
13
|
+
export const TRANSLATIONS = [
|
|
14
|
+
{ key: 'agent', from: 'agent.<name>', to: 'agents.<name>', source: 'SPEC 0, real 2.2.5', verified: true },
|
|
15
|
+
{ key: 'plugin', from: 'plugin[] (npm spec)', to: 'plugins[]', source: 'SPEC 0, tests/real-opencode.sh', verified: true },
|
|
16
|
+
{ key: 'mcp', from: 'mcp.<name>', to: 'mcp.servers.<name>', source: 'SPEC 0, real 2.2.5 (tests/real-opencode.sh)', verified: true },
|
|
17
|
+
{ key: 'compaction.auto', from: 'compaction.auto', to: 'compaction.auto', source: 'SPEC 0', verified: true },
|
|
18
|
+
{ key: 'compaction.reserved', from: 'compaction.reserved', to: 'compaction.buffer', source: 'SPEC 0', verified: true },
|
|
19
|
+
{ key: 'autoupdate', from: 'autoupdate: false', to: 'update: "disable"', source: 'opencode.ai/docs/migrate-v1, 2026-11-12 (docs only)', verified: true },
|
|
20
|
+
{ key: 'autoupdate-true', from: 'autoupdate: true', to: 'update: "auto"', source: 'opencode.ai/docs/migrate-v1, 2026-11-12 (docs only)', verified: true },
|
|
21
|
+
{ key: 'disabled_providers', from: 'disabled_providers[]', to: 'policies: deny provider.use', source: 'real 2.1.4 accepts `policies` (tests/real-opencode.sh)', verified: true },
|
|
22
|
+
...['instructions', 'default_agent', 'model', 'share', 'shell'].map((k) => ({ key: k, from: k, to: k, source: 'real 2.2.5, #124b', verified: true })),
|
|
23
|
+
{ key: 'tui-plugin', from: 'tui.json(c) plugin[] (file://)', to: 'cli.json plugins[]', source: 'VERIFY: opencode.ai/docs/plugins says cli.json `plugins`, tui docs still say tui.json; no binary proof', verified: false },
|
|
24
|
+
{ key: 'keybinds', from: 'keybinds', to: '?', source: 'VERIFY: docs name no 2.x file for keybinds (tui.json vs cli.json)', verified: false },
|
|
25
|
+
{ key: 'dir', from: 'agent/ agents/ command/ commands/ folders', to: 'same folders', source: 'opencode.ai/docs/migrate-v1, 2026-11-12 (docs only)', verified: true },
|
|
26
|
+
{ key: 'skills', from: '~/.config/opencode/skills, ~/.agents/skills, ~/.claude/skills', to: 'same folders', source: 'opencode.ai/docs/skills, 2026-11-12 (docs only)', verified: true },
|
|
27
|
+
];
|
|
28
|
+
const row = (key) => TRANSLATIONS.find((t) => t.key === key);
|
|
29
|
+
|
|
30
|
+
// Keys with no verified 2.x equivalent, and so no row.
|
|
31
|
+
const MANUAL_KEYS = new Set(['provider', 'permission', 'experimental']);
|
|
32
|
+
const SAME = new Set(['instructions', 'default_agent', 'model', 'share', 'shell']);
|
|
33
|
+
const HANDLED = new Set(['$schema', 'mcp', 'plugin']); // mcp and plugin come from the adopt items
|
|
34
|
+
|
|
35
|
+
const readJson = (file, fsx) => { try { return parse(fsx.readFileSync(file, 'utf8'), [], { allowTrailingComma: true }) ?? null; } catch { return null; } };
|
|
36
|
+
|
|
37
|
+
const translate = (t, name, before = t.from.replace('<name>', name)) => ({ class: 'user-translatable', before, after: t.to.replace('<name>', name), reason: 'row in the translation table', source: t.source });
|
|
38
|
+
const verifyRow = (t, before) => ({ class: 'user-manual', before, after: null, reason: `${t.source}: no proven 2.x equivalent`, source: t.source });
|
|
39
|
+
const manual = (before, reason) => ({ class: 'user-manual', before, after: null, reason, source: null });
|
|
40
|
+
const managed = (before, after) => ({ class: 'managed', before, after, reason: 'lean-agents owns it; the 2.x adapter reinstalls it', source: 'adapters/opencode-v2.mjs' });
|
|
41
|
+
|
|
42
|
+
// Classify one adopt item of the OpenCode 1.x config (mcp, plugin, plugins/ file) or a skill.
|
|
43
|
+
function classifyItem(it, stopgaps) {
|
|
44
|
+
if (it.owner === 'managed') return managed(`${it.kind} ${it.name}`, it.kind === 'plugin' ? 'plugins[]' : it.kind === 'mcp' ? `mcp.servers.${it.name}` : it.file);
|
|
45
|
+
if (it.kind === 'mcp') return translate(row('mcp'), it.name);
|
|
46
|
+
if (it.kind === 'skill') { const t = row('skills'); return t.verified ? translate(t, it.name, `skill ${it.name}`) : verifyRow(t, `skill ${it.name}`); }
|
|
47
|
+
if (it.kind === 'plugin' && it.keyPath.length) {
|
|
48
|
+
const tui = /tui\.jsonc?$/.test(it.file);
|
|
49
|
+
const t = row(tui ? 'tui-plugin' : 'plugin');
|
|
50
|
+
const local = it.name.startsWith('file:');
|
|
51
|
+
if (!t.verified) return verifyRow(t, `${tui ? 'tui.json ' : ''}plugin ${it.name}`);
|
|
52
|
+
if (local) return manual(`plugin ${it.name}`, 'local plugin file: the 2.x plugin API is not proven for it');
|
|
53
|
+
return translate(t, it.name, `plugin ${it.name}`);
|
|
54
|
+
}
|
|
55
|
+
const sg = stopgaps.find((s) => s.file === it.file);
|
|
56
|
+
if (sg) return manual(`plugin ${it.name}`, `leftover stopgap: replace with ${sg.replaceWith}`);
|
|
57
|
+
return manual(`plugin ${it.name}`, 'JS/TS plugin uses 1.x API `api.command`; 2.x uses `api.keymap`');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Top-level keys of the 1.x config and the files in its agent/command folders, as new items (key names only).
|
|
61
|
+
function configItems(home, ocDir, fsx, rel) {
|
|
62
|
+
const out = [];
|
|
63
|
+
const file = configPath(ocDir);
|
|
64
|
+
const mk = (kind, name, f, keyPath, owner, upgrade) => out.push({ client: 'opencode', kind, name, file: rel(f), keyPath, launch: null, owner, status: [], pin: null, wanted: null, action: 'keep', upgrade });
|
|
65
|
+
const cfg = readJson(file, fsx);
|
|
66
|
+
for (const [k, v] of Object.entries(cfg && typeof cfg === 'object' ? cfg : {})) {
|
|
67
|
+
if (HANDLED.has(k)) continue;
|
|
68
|
+
const at = (name, u) => mk('config', name, file, [k], 'user', u);
|
|
69
|
+
if (k === 'agent') for (const n of Object.keys(v ?? {})) at(`agent.${n}`, translate(row('agent'), n));
|
|
70
|
+
else if (k === 'compaction') for (const s of Object.keys(v ?? {})) at(`compaction.${s}`, ['auto', 'reserved'].includes(s) ? translate(row(`compaction.${s}`), s) : manual(`compaction.${s}`, 'no verified 2.x key'));
|
|
71
|
+
else if (k === 'autoupdate') at(k, typeof v === 'boolean' ? translate(row(v ? 'autoupdate-true' : 'autoupdate'), k) : manual(k, 'no verified 2.x value (autoupdate "notify" is not in the table)'));
|
|
72
|
+
else if (k === 'disabled_providers') at(k, translate(row(k), k));
|
|
73
|
+
else if (SAME.has(k)) at(k, translate(row(k), k));
|
|
74
|
+
else if (k === 'keybinds') at(k, verifyRow(row(k), k));
|
|
75
|
+
else at(k, manual(k, MANUAL_KEYS.has(k) ? 'no verified 2.x key' : 'unknown 1.x key: no verified 2.x key'));
|
|
76
|
+
}
|
|
77
|
+
for (const d of ['agent', 'agents', 'command', 'commands']) {
|
|
78
|
+
let list = [];
|
|
79
|
+
try { list = fsx.readdirSync(j(ocDir, d), { withFileTypes: true }).filter((e) => e.isFile()); } catch { continue; }
|
|
80
|
+
for (const e of list) {
|
|
81
|
+
const f = j(ocDir, d, e.name);
|
|
82
|
+
let owned = false;
|
|
83
|
+
try { owned = hasMark(fsx.readFileSync(f, 'utf8')); } catch { /* unreadable: user */ }
|
|
84
|
+
mk('file', `${d}/${e.name}`, f, [], owned ? 'managed' : 'user', owned ? managed(`${d}/${e.name}`, 'rewritten by the 2.x adapter') : row('dir').verified ? { ...translate(row('dir'), d), before: `${d}/${e.name}`, after: `${d}/${e.name}` } : verifyRow(row('dir'), `${d}/${e.name}`));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Where the `opencode` binary came from, by its path. Unknown paths stay unknown.
|
|
91
|
+
export const installVia = (p) => (!p ? null : /node_modules|[\\/]\.nvm[\\/]|[\\/]npm[\\/]/.test(p) ? 'npm' : /[\\/]\.opencode[\\/]bin/.test(p) ? 'script' : /homebrew|Cellar|linuxbrew/i.test(p) ? 'brew' : /scoop/i.test(p) ? 'scoop' : 'unknown');
|
|
92
|
+
|
|
93
|
+
export function upgradeInventory(inv, { home, fsx = fs, binary = { path: null, version: null } }) {
|
|
94
|
+
const rel = (p) => (p && p.startsWith(home) ? `~${p.slice(home.length)}` : p);
|
|
95
|
+
const ocDir = j(configHome(home), 'opencode');
|
|
96
|
+
const items = inv.items.map((it) => {
|
|
97
|
+
if (!(it.client === 'opencode' || it.kind === 'skill')) return it;
|
|
98
|
+
return { ...it, upgrade: classifyItem(it, inv.stopgaps) };
|
|
99
|
+
});
|
|
100
|
+
items.push(...configItems(home, ocDir, fsx, rel));
|
|
101
|
+
const mine = items.filter((i) => i.upgrade);
|
|
102
|
+
const counts = { managed: 0, 'user-translatable': 0, 'user-manual': 0 };
|
|
103
|
+
for (const i of mine) counts[i.upgrade.class]++;
|
|
104
|
+
const plan = [
|
|
105
|
+
...(counts.managed ? [`reinstall ${counts.managed} managed items through the 2.x adapter`] : []),
|
|
106
|
+
...mine.filter((i) => i.upgrade.class === 'user-translatable').map((i) => `translate ${i.upgrade.before} -> ${i.upgrade.after}`),
|
|
107
|
+
...mine.filter((i) => i.upgrade.class === 'user-manual').map((i) => `manual ${i.upgrade.before}: ${i.upgrade.reason}`),
|
|
108
|
+
];
|
|
109
|
+
return {
|
|
110
|
+
...inv,
|
|
111
|
+
items,
|
|
112
|
+
upgrade: {
|
|
113
|
+
from: 'opencode-v1', to: 'opencode-v2',
|
|
114
|
+
binary: { path: rel(binary.path), version: binary.version, via: installVia(binary.path) },
|
|
115
|
+
layout: { configDir: rel(ocDir), dataDir: inv.opencode.dataDir, sessions: inv.opencode.sessions, major: inv.opencode.major },
|
|
116
|
+
backup: null, // PR B: the permanent session backup
|
|
117
|
+
counts, plan,
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function formatUpgrade(r) {
|
|
123
|
+
const u = r.upgrade;
|
|
124
|
+
const out = [`--upgrade-agent opencode (dry run: nothing is changed; apply is not in this release yet)`,
|
|
125
|
+
`OpenCode: ${u.binary.version ?? 'version unknown'} at ${u.binary.path ?? 'not on PATH'} (${u.binary.via ?? 'n/a'}), major ${u.layout.major ?? 'none'}, sessions ${u.layout.sessions ?? 'unknown'}`,
|
|
126
|
+
`${u.counts.managed} managed, ${u.counts['user-translatable']} translatable, ${u.counts['user-manual']} manual`];
|
|
127
|
+
for (const i of r.items.filter((x) => x.upgrade)) out.push(` ${i.upgrade.class.padEnd(16)} ${i.upgrade.before}${i.upgrade.after ? ` -> ${i.upgrade.after}` : ''}${i.upgrade.class === 'user-manual' ? ` (${i.upgrade.reason})` : ''}`);
|
|
128
|
+
out.push('Translation table:', ...TRANSLATIONS.map((t) => ` ${t.from} -> ${t.to} [${t.source}]`));
|
|
129
|
+
return out.join('\n');
|
|
130
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Refuses a git checkout whose HEAD is not the pinned commit: `node verify-commit.mjs <dir> <sha>`.
|
|
2
|
+
// A moved tag removes the checkout and exits 1. A script file, not `node -e`, so no shell can split its arguments.
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import { execFileSync } from 'node:child_process';
|
|
5
|
+
import { pathToFileURL } from 'node:url';
|
|
6
|
+
|
|
7
|
+
if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
|
|
8
|
+
const [dir, want] = process.argv.slice(2);
|
|
9
|
+
const got = execFileSync('git', ['-C', dir, 'rev-parse', 'HEAD'], { encoding: 'utf8' }).trim();
|
|
10
|
+
if (got !== want) {
|
|
11
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
12
|
+
console.error(`${dir}: tag moved, HEAD is ${got}, pinned ${want}. The checkout was removed.`);
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
console.log(`commit ok: ${dir}`);
|
|
16
|
+
}
|